// mock-team (PEP-183): stands in for `claude -p` as the specialist matcher. The scenario file // (MOCK_TEAM_SCENARIO, JSON): { "rules": [{ "match": "безопасн", "agent": "Страж ИБ", "reason": "…" }], "fail": false, "slowMs": 0 }. // The first rule whose regexp matches the story's title ("Задача: …") wins; none → agent null. // Every call is appended to .log.jsonl. import { appendFileSync, existsSync, readFileSync } from "node:fs"; interface Scenario { rules?: Array<{ match: string; agent: string | null; reason?: string }>; fail?: boolean; /** Answer after this many ms (a slow model). */ slowMs?: number; } const file = process.env.MOCK_TEAM_SCENARIO; const sc: Scenario = file && existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {}; const prompt = readFileSync(0, "utf8"); const title = /^Задача: (.*)$/m.exec(prompt)?.[1] ?? ""; if (file) appendFileSync(`${file}.log.jsonl`, JSON.stringify({ args: process.argv.slice(2), title, prompt }) + "\n"); if (!process.argv.includes("-p")) { console.error("mock-team: expected -p (non-interactive print mode)"); process.exit(2); } if (sc.slowMs) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, sc.slowMs); if (sc.fail) { console.error("mock-team: API Error: 529 overloaded"); process.exit(1); } const rule = sc.rules?.find((r) => new RegExp(r.match, "i").test(title)); const answer = { agent: rule?.agent ?? null, reason: rule?.reason ?? "mock: никто не подходит" }; process.stdout.write(JSON.stringify({ type: "result", subtype: "success", is_error: false, num_turns: 1, result: JSON.stringify(answer), session_id: "mock-team" }) + "\n");