995b39a122
- Move prompt construction logic from action-side to server-side (webhook handler and trigger page) - Include issue/comment body in USER PROMPT only if @pullfrog was tagged (checked server-side using containsTriggerPhrase) - Add repoInstructions as separate REPO-LEVEL INSTRUCTIONS section in FULL prompt - Macro-expand repoInstructions server-side before sending to action - Trigger page never includes body (manual triggers) - Remove redundant customInstructions field (now combined into prompt server-side) files changed: - action/external.ts: add repoInstructions to WriteablePayload, remove customInstructions - action/utils/payload.ts: add repoInstructions to JsonPayload schema, remove customInstructions - action/utils/repoSettings.ts: add repoInstructions to RepoSettings interface - action/utils/instructions.ts: use payload.prompt directly, add repo section to full prompt, add repo field to ResolvedInstructions - utils/webhooks/handleWebhook.ts: check @pullfrog tag and include body if tagged, macro-expand repoInstructions - app/trigger/[owner]/[repo]/[number]/page.tsx: macro-expand repoInstructions (never include body)
88 lines
2.0 KiB
TypeScript
88 lines
2.0 KiB
TypeScript
import type { AgentName, BashPermission, ToolPermission } from "../external.ts";
|
|
import type { RepoContext } from "./github.ts";
|
|
|
|
export interface Mode {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
prompt: string;
|
|
}
|
|
|
|
export interface RepoSettings {
|
|
defaultAgent: AgentName | null;
|
|
modes: Mode[];
|
|
repoInstructions: string;
|
|
web: ToolPermission;
|
|
search: ToolPermission;
|
|
write: ToolPermission;
|
|
bash: BashPermission;
|
|
}
|
|
|
|
/**
|
|
* Fetch repository settings from the Pullfrog API
|
|
* Returns defaults if repo doesn't exist or fetch fails
|
|
*/
|
|
export async function fetchRepoSettings(params: {
|
|
token: string;
|
|
repoContext: RepoContext;
|
|
}): Promise<RepoSettings> {
|
|
const apiUrl = process.env.API_URL || "https://pullfrog.com";
|
|
const timeoutMs = 30000;
|
|
const controller = new AbortController();
|
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
|
|
try {
|
|
const response = await fetch(
|
|
`${apiUrl}/api/repo/${params.repoContext.owner}/${params.repoContext.name}/settings`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
Authorization: `Bearer ${params.token}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
signal: controller.signal,
|
|
}
|
|
);
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
if (!response.ok) {
|
|
return {
|
|
defaultAgent: null,
|
|
modes: [],
|
|
repoInstructions: "",
|
|
web: "enabled",
|
|
search: "enabled",
|
|
write: "enabled",
|
|
bash: "restricted",
|
|
};
|
|
}
|
|
|
|
const settings = (await response.json()) as RepoSettings | null;
|
|
if (settings === null) {
|
|
return {
|
|
defaultAgent: null,
|
|
modes: [],
|
|
repoInstructions: "",
|
|
web: "enabled",
|
|
search: "enabled",
|
|
write: "enabled",
|
|
bash: "restricted",
|
|
};
|
|
}
|
|
|
|
return settings;
|
|
} catch {
|
|
clearTimeout(timeoutId);
|
|
return {
|
|
defaultAgent: null,
|
|
modes: [],
|
|
repoInstructions: "",
|
|
web: "enabled",
|
|
search: "enabled",
|
|
write: "enabled",
|
|
bash: "restricted",
|
|
};
|
|
}
|
|
}
|