- web board (Backlog / In progress / Review / Done) with drag-and-drop and buttons; moveTask starts an agent on In progress, stops on Backlog/Done - routine proposals go straight to apply; request_approval/ask_pm only for architectural stoppers (RULES.md, MCP hints, template pushed to Gitea) - Stop hook keeps the agent going (decision: block, max 2 in a row, sessions.auto_nudges reset by a human answer) instead of pinging the PM - review: ready-for-review message with Accept (acceptTask → done, session stopped) in Telegram and web; a text reply goes back to the agent - mock-claude honours Stop-hook block; 6 new e2e tests (48 total, green) - OpenSpec: pep-7 archived (task-autonomy, web-workspace board) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
import { mkdirSync, writeFileSync } from "node:fs";
|
|
import { peppaHome, peppaRoot } from "@peppa/shared";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const hookBin = () => `${peppaRoot(resolve(dirname(fileURLToPath(import.meta.url)), "../../.."))}/packages/runner/bin/peppa-hook`;
|
|
/** Blocking hooks wait for the PM this long before falling back to the terminal. */
|
|
export const HOOK_WAIT_SEC = Number(process.env.PEPPA_HOOK_WAIT_SEC ?? 540);
|
|
|
|
/** Stop-hook "keep going" nudges in a row before the PM is called. */
|
|
export const MAX_AUTO_NUDGES = 2;
|
|
|
|
export const RUNS_DIR = join(peppaHome(), "runs");
|
|
|
|
/**
|
|
* Claude settings for one session run, passed with --settings. Hooks live here rather
|
|
* than in each project repo, so they are versioned with Peppa and only fire for
|
|
* sessions Peppa launched.
|
|
*/
|
|
export function runDir(sessionId: number, generation: number): string {
|
|
const dir = join(RUNS_DIR, `s${sessionId}-g${generation}`);
|
|
mkdirSync(dir, { recursive: true });
|
|
return dir;
|
|
}
|
|
|
|
/** Writes the shared Peppa rules for --append-system-prompt-file. */
|
|
export function writeRunRules(sessionId: number, generation: number, text: string): string {
|
|
const path = join(runDir(sessionId, generation), "rules.md");
|
|
writeFileSync(path, text);
|
|
return path;
|
|
}
|
|
|
|
export function writeRunSettings(sessionId: number, generation: number): string {
|
|
const hook = (event: string, timeout = 30) => ({ type: "command", command: `${hookBin()} ${event}`, timeout });
|
|
const settings = {
|
|
hooks: {
|
|
SessionStart: [{ hooks: [hook("session-start")] }],
|
|
UserPromptSubmit: [{ hooks: [hook("prompt")] }],
|
|
PermissionRequest: [{ hooks: [hook("permission-request", HOOK_WAIT_SEC + 30)] }],
|
|
PreToolUse: [{ matcher: "AskUserQuestion", hooks: [hook("ask-question", HOOK_WAIT_SEC + 30)] }],
|
|
Notification: [{ hooks: [hook("notification")] }],
|
|
Stop: [{ hooks: [hook("stop")] }],
|
|
StopFailure: [{ hooks: [hook("stop-failure")] }],
|
|
SessionEnd: [{ hooks: [hook("session-end")] }],
|
|
},
|
|
};
|
|
const path = join(runDir(sessionId, generation), "settings.json");
|
|
writeFileSync(path, JSON.stringify(settings, null, 2));
|
|
return path;
|
|
}
|