- infra: Bugsink 2.6.3 in docker (infra/bugsink, scripts/bugsink-up.sh), database bugsink in Peppa's Postgres, Traefik route bugsink.telecom.quest - packages/bugsink: REST API client + custom-webhook payload parsing - incidents (migration 0011): incident_settings, error_sources, incidents; ingest from webhook POST /api/hooks/bugsink/<secret> and a 2-minute poll in the watchdog - incident policy per project: notify / backlog (default) / start / ask (Telegram buttons) / triage (claude -p with the owner's token, falls back to ask) - daily task cap, environments, ignore pattern; manual "fixed" until PEP-57; REGRESSED returns the task to the backlog - web «Ошибки» section, bot buttons, MCP tools for agents and the PM, help, RULES.md - testkit: mock-bugsink, mock-triage, incidents.test.ts (one test per scenario, plus a live run against the real Bugsink with PEPPA_LIVE_BUGSINK=1) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
2.2 KiB
TypeScript
45 lines
2.2 KiB
TypeScript
// mock-triage (PEP-58): stands in for `claude -p --output-format json` as the incident
|
||
// triager. Reads the prompt on stdin, answers with the CLI's JSON envelope whose `result`
|
||
// is the decision line. Behaviour comes from MOCK_TRIAGE_SCENARIO (a JSON file):
|
||
// { "rules": [{ "match": "PaymentError", "action": "start", "confidence": 0.9, "reason": "…" }],
|
||
// "default": { "action": "ask", "confidence": 0.3, "reason": "…" },
|
||
// "fail": false, "hang": false }
|
||
// Every call is appended to <scenario>.log.jsonl (args, whether the PM prompt and token came through).
|
||
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
||
|
||
interface Rule {
|
||
match: string;
|
||
action: string;
|
||
confidence?: number;
|
||
reason?: string;
|
||
}
|
||
interface Scenario {
|
||
rules?: Rule[];
|
||
default?: Omit<Rule, "match">;
|
||
fail?: boolean;
|
||
hang?: boolean;
|
||
}
|
||
|
||
const file = process.env.MOCK_TRIAGE_SCENARIO;
|
||
const sc: Scenario = file && existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
||
const prompt = readFileSync(0, "utf8");
|
||
const pmRules = /Правила PM:\n([\s\S]*?)\n\nПроект:/.exec(prompt)?.[1] ?? "";
|
||
const title = /^Ошибка: (.*)$/m.exec(prompt)?.[1] ?? "";
|
||
if (file) {
|
||
appendFileSync(`${file}.log.jsonl`, JSON.stringify({ args: process.argv.slice(2), title, pmRules, token: process.env.CLAUDE_CODE_OAUTH_TOKEN ? "set" : null, cwd: process.cwd() }) + "\n");
|
||
}
|
||
if (!process.argv.includes("-p")) {
|
||
console.error("mock-triage: expected -p (non-interactive print mode)");
|
||
process.exit(2);
|
||
}
|
||
if (sc.hang) await new Promise(() => setInterval(() => {}, 1000)); // never answers
|
||
if (sc.fail) {
|
||
console.error("mock-triage: API Error: 529 overloaded");
|
||
process.exit(1);
|
||
}
|
||
const rule = sc.rules?.find((r) => new RegExp(r.match, "i").test(title)) ?? { match: "", ...(sc.default ?? { action: "ask", confidence: 0.2, reason: "правила PM не покрывают этот случай" }) };
|
||
const decision = { action: rule.action, confidence: rule.confidence ?? 0.9, reason: rule.reason ?? `mock: правило «${rule.match}»` };
|
||
process.stdout.write(
|
||
JSON.stringify({ type: "result", subtype: "success", is_error: false, num_turns: 1, result: JSON.stringify(decision), session_id: "mock-triage" }) + "\n",
|
||
);
|