proofdeck 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +23 -0
- package/README.md +152 -2
- package/README.zh-CN.md +152 -0
- package/bin/proofdeck.js +191 -0
- package/board/LICENSE +201 -0
- package/board/README.md +473 -0
- package/board/README.zh-CN.md +424 -0
- package/board/dist/_chk.db-shm +0 -0
- package/board/dist/_chk.db-wal +0 -0
- package/board/dist/adapters.d.ts +40 -0
- package/board/dist/adapters.d.ts.map +1 -0
- package/board/dist/adapters.js +124 -0
- package/board/dist/adapters.js.map +1 -0
- package/board/dist/board.d.ts +628 -0
- package/board/dist/board.d.ts.map +1 -0
- package/board/dist/board.js +2767 -0
- package/board/dist/board.js.map +1 -0
- package/board/dist/cli.d.ts +3 -0
- package/board/dist/cli.d.ts.map +1 -0
- package/board/dist/cli.js +1663 -0
- package/board/dist/cli.js.map +1 -0
- package/board/dist/config.d.ts +57 -0
- package/board/dist/config.d.ts.map +1 -0
- package/board/dist/config.js +99 -0
- package/board/dist/config.js.map +1 -0
- package/board/dist/db.d.ts +9 -0
- package/board/dist/db.d.ts.map +1 -0
- package/board/dist/db.js +506 -0
- package/board/dist/db.js.map +1 -0
- package/board/dist/git.d.ts +35 -0
- package/board/dist/git.d.ts.map +1 -0
- package/board/dist/git.js +147 -0
- package/board/dist/git.js.map +1 -0
- package/board/dist/index.d.ts +18 -0
- package/board/dist/index.d.ts.map +1 -0
- package/board/dist/index.js +13 -0
- package/board/dist/index.js.map +1 -0
- package/board/dist/mcp-config.d.ts +26 -0
- package/board/dist/mcp-config.d.ts.map +1 -0
- package/board/dist/mcp-config.js +88 -0
- package/board/dist/mcp-config.js.map +1 -0
- package/board/dist/mcp.d.ts +3 -0
- package/board/dist/mcp.d.ts.map +1 -0
- package/board/dist/mcp.js +949 -0
- package/board/dist/mcp.js.map +1 -0
- package/board/dist/quickstart.d.ts +75 -0
- package/board/dist/quickstart.d.ts.map +1 -0
- package/board/dist/quickstart.js +156 -0
- package/board/dist/quickstart.js.map +1 -0
- package/board/dist/serve.d.ts +10 -0
- package/board/dist/serve.d.ts.map +1 -0
- package/board/dist/serve.js +445 -0
- package/board/dist/serve.js.map +1 -0
- package/board/dist/signing.d.ts +18 -0
- package/board/dist/signing.d.ts.map +1 -0
- package/board/dist/signing.js +26 -0
- package/board/dist/signing.js.map +1 -0
- package/board/dist/sync.d.ts +49 -0
- package/board/dist/sync.d.ts.map +1 -0
- package/board/dist/sync.js +158 -0
- package/board/dist/sync.js.map +1 -0
- package/board/dist/types.d.ts +359 -0
- package/board/dist/types.d.ts.map +1 -0
- package/board/dist/types.js +20 -0
- package/board/dist/types.js.map +1 -0
- package/board/docs/adr/0001-shared-worktree-collision.md +102 -0
- package/board/docs/adr/0001-shared-worktree-collision.zh-CN.md +90 -0
- package/board/docs/attribution.md +123 -0
- package/board/docs/attribution.zh-CN.md +104 -0
- package/board/docs/development-workflow.md +81 -0
- package/board/docs/development-workflow.zh-CN.md +75 -0
- package/board/docs/diagrams/banner.png +0 -0
- package/board/docs/diagrams/banner.svg +1 -0
- package/board/docs/diagrams/before-after.png +0 -0
- package/board/docs/diagrams/before-after.svg +1 -0
- package/board/docs/diagrams/governance-chain.png +0 -0
- package/board/docs/diagrams/governance-chain.svg +1 -0
- package/board/docs/diagrams/value-flow.png +0 -0
- package/board/docs/diagrams/value-flow.svg +1 -0
- package/board/docs/entry-point.md +81 -0
- package/board/docs/entry-point.zh-CN.md +65 -0
- package/board/docs/kanban.png +0 -0
- package/board/docs/octoryn-mark.png +0 -0
- package/board/docs/registry-metadata.md +34 -0
- package/board/docs/registry-metadata.zh-CN.md +30 -0
- package/board/package.json +87 -0
- package/config.example.json +72 -0
- package/daemon.js +1148 -0
- package/docs/assets/demo.gif +0 -0
- package/docs/assets/logo-512.png +0 -0
- package/docs/assets/logo.svg +31 -0
- package/docs/assets/social-preview.png +0 -0
- package/docs/demo-run.mjs +61 -0
- package/docs/render-demo.py +94 -0
- package/docs/render-logo.py +101 -0
- package/docs/task-book.md +58 -0
- package/e2e/verify-acceptance.mjs +150 -0
- package/e2e/verify-antifraud.mjs +128 -0
- package/e2e/verify-caps.mjs +46 -0
- package/e2e/verify-checkpoint.mjs +208 -0
- package/e2e/verify-firstclass.mjs +110 -0
- package/e2e/verify-judge.mjs +52 -0
- package/e2e/verify-lease.mjs +95 -0
- package/e2e/verify-replay.mjs +92 -0
- package/e2e/verify-resilience.mjs +323 -0
- package/e2e/verify-review.mjs +86 -0
- package/e2e/verify-scheduling.mjs +110 -0
- package/e2e/verify-schema-evolution.mjs +107 -0
- package/e2e/verify-sla-digest.mjs +105 -0
- package/guard.js +97 -0
- package/lib/adapters/codex.js +206 -0
- package/lib/billing-convert.js +57 -0
- package/lib/board.js +46 -0
- package/lib/caps.js +35 -0
- package/lib/checkpoint.js +130 -0
- package/lib/gating.js +218 -0
- package/lib/guard-core.mjs +108 -0
- package/lib/http.js +161 -0
- package/lib/judge.js +89 -0
- package/lib/lease.js +93 -0
- package/lib/notify.js +56 -0
- package/lib/platform.js +120 -0
- package/lib/replay.js +68 -0
- package/lib/review.js +40 -0
- package/lib/runner.js +152 -0
- package/lib/schedule.js +59 -0
- package/lib/sla.js +42 -0
- package/lib/spans.js +36 -0
- package/lib/starve.js +43 -0
- package/lib/store.js +109 -0
- package/lib/supply.js +101 -0
- package/lib/usage.js +103 -0
- package/lib/verify.js +223 -0
- package/lib/watchdog-core.mjs +68 -0
- package/lib/watchdog-worker.mjs +75 -0
- package/package.json +55 -4
- package/scripts/run-daemon.sh +18 -0
- package/scripts/run-e2e.mjs +39 -0
package/lib/verify.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Acceptance verification V1 (the verification engine).
|
|
2
|
+
// Tasks declare acceptance and scheduling metadata in a ```bridge fenced block
|
|
3
|
+
// inside their description; the bridge judges it before the done transition —
|
|
4
|
+
// a claim by the executing agent does not count. FAIL rejects done: the task
|
|
5
|
+
// returns to open for automatic redispatch, and a face that keeps failing gets
|
|
6
|
+
// circuit-broken.
|
|
7
|
+
//
|
|
8
|
+
// Acceptance also exists as a first-class column on the board (see board/),
|
|
9
|
+
// which is preferred when present; the fenced block remains the
|
|
10
|
+
// backwards-compatible surface for boards without the column.
|
|
11
|
+
//
|
|
12
|
+
// 围栏格式(任务书正文任意位置,取第一个块):
|
|
13
|
+
// ```bridge
|
|
14
|
+
// { "priority": "P1", "retry": {"max": 2},
|
|
15
|
+
// "acceptance": { "baseDir": "/abs/path/to/repo", "checks": [ ... ] } }
|
|
16
|
+
// ```
|
|
17
|
+
// 检查类型(fail-closed:未知类型记 FAIL,不许静默放行;相对路径按 baseDir 解析,
|
|
18
|
+
// baseDir 缺省为本次运行的 workdir):
|
|
19
|
+
// fileExists {path, minBytes?} 文件存在且 ≥ minBytes(默认 1 字节)
|
|
20
|
+
// countAtLeast {path, jsonPath, min} JSON 取值是数组→长度、数字→值,须 ≥ min
|
|
21
|
+
// countOccurrences{path, text, minCount?} 文本中字面量子串出现次数 ≥ minCount(默认 1)
|
|
22
|
+
// —— 刻意不做正则:模式来自任务书文本,动态正则既不可控(ReDoS)又是注入面;
|
|
23
|
+
// V1 只需要「数结构标记出现几次」这种朴素能力。
|
|
24
|
+
// 防刷分检查(2026-10-07,SpecBench 教训:声明式检查可被针对性刷穿,差距随规模每
|
|
25
|
+
// 十倍增 27-28pp;组合一致性迫使刷单必须整条链一起伪造):
|
|
26
|
+
// countMatches {path, jsonPath, withPath, withJsonPath, min?}
|
|
27
|
+
// 两份 JSON 取值(数组→长度、数字→值)必须相等且 ≥ min(默认 1)
|
|
28
|
+
// referencesExist {path, jsonPath, baseDir?}
|
|
29
|
+
// JSON 取值须为字符串数组,每个引用按 baseDir(缺省检查根)解析后
|
|
30
|
+
// 必须真实存在为文件;列表为空也记 FAIL(fail-closed)
|
|
31
|
+
// 记录:结构化 note「[[verify]] key=… verdict=… level=V1 by=… checks=n/m」+ 逐项证据。
|
|
32
|
+
import { readFileSync, statSync } from "node:fs";
|
|
33
|
+
import { join } from "node:path";
|
|
34
|
+
import { retryDecision } from "./schedule.js";
|
|
35
|
+
import { left } from "./supply.js";
|
|
36
|
+
|
|
37
|
+
const cap = (s, n = 200) => (typeof s === "string" && s.length > n ? s.slice(0, n) + "…" : s);
|
|
38
|
+
|
|
39
|
+
export function parseBridgeBlock(description) {
|
|
40
|
+
if (!description || typeof description !== "string") return null;
|
|
41
|
+
const m = description.match(/```bridge\s*\n([\s\S]*?)```/);
|
|
42
|
+
if (!m) return null;
|
|
43
|
+
try {
|
|
44
|
+
const j = JSON.parse(m[1]);
|
|
45
|
+
return j && typeof j === "object" && !Array.isArray(j) ? j : null;
|
|
46
|
+
} catch { return null; }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function walkJsonPath(obj, path) {
|
|
50
|
+
if (typeof path !== "string" || !path.trim()) return undefined;
|
|
51
|
+
const parts = path.replace(/^\$\.?/, "").split(".").filter(Boolean);
|
|
52
|
+
let cur = obj;
|
|
53
|
+
for (const part of parts) {
|
|
54
|
+
if (cur == null) return undefined;
|
|
55
|
+
const m = part.match(/^([^[\]]*)((?:\[\d+\])*)$/);
|
|
56
|
+
if (m?.[1]) cur = cur[m[1]];
|
|
57
|
+
for (const idx of (m?.[2]?.match(/\d+/g) ?? [])) cur = cur?.[Number(idx)];
|
|
58
|
+
}
|
|
59
|
+
return cur;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 字面量子串计数(非重叠),计数封顶 10 万防病态输入。
|
|
63
|
+
function countLiteral(hay, needle) {
|
|
64
|
+
let n = 0, i = 0;
|
|
65
|
+
while (n < 100000) {
|
|
66
|
+
const j = hay.indexOf(needle, i);
|
|
67
|
+
if (j === -1) break;
|
|
68
|
+
n++;
|
|
69
|
+
i = j + needle.length;
|
|
70
|
+
}
|
|
71
|
+
return n;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const PASS = (type, target, evidence) => ({ type, target, pass: true, evidence });
|
|
75
|
+
// invalid=true = 验收标准本身写错(未知类型/缺字段),不是工件不合格——调用方据此
|
|
76
|
+
// 区分处置:spec 类不罚面、不烧重试,打回任务作者修正后 requeue。
|
|
77
|
+
const FAIL = (type, target, evidence, invalid = false) => ({ type, target, pass: false, evidence, invalid });
|
|
78
|
+
|
|
79
|
+
const resolvePath = (p, root) =>
|
|
80
|
+
(typeof p === "string" && p && (p.includes(":") || p.startsWith("/") || p.startsWith("\\"))) ? p : (p ? join(root, p) : null);
|
|
81
|
+
|
|
82
|
+
// JSON 取值→计数(数组→长度、数字→值),其余视为不可计数。
|
|
83
|
+
function readCount(p, jsonPath) {
|
|
84
|
+
const j = JSON.parse(readFileSync(p, "utf8"));
|
|
85
|
+
const v = walkJsonPath(j, jsonPath);
|
|
86
|
+
const n = Array.isArray(v) ? v.length : (typeof v === "number" ? v : NaN);
|
|
87
|
+
if (!Number.isFinite(n)) throw Object.assign(new Error(`值不可计数(${v === undefined ? "路径未命中" : typeof v})`), { spec: true });
|
|
88
|
+
return n;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function runCheck(c, root) {
|
|
92
|
+
const type = c?.type ?? "unknown";
|
|
93
|
+
const target = c?.path ?? c?.jsonPath ?? "?";
|
|
94
|
+
try {
|
|
95
|
+
if (type === "fileExists") {
|
|
96
|
+
const p = resolvePath(c.path, root);
|
|
97
|
+
if (!p) return FAIL(type, target, "缺 path", true);
|
|
98
|
+
const st = statSync(p);
|
|
99
|
+
if (!st.isFile()) return FAIL(type, p, "不是文件");
|
|
100
|
+
const min = Number(c.minBytes ?? 1);
|
|
101
|
+
return st.size >= min ? PASS(type, p, `${st.size}B`) : FAIL(type, p, `${st.size}B < minBytes ${min}`);
|
|
102
|
+
}
|
|
103
|
+
if (type === "countAtLeast") {
|
|
104
|
+
const p = resolvePath(c.path, root);
|
|
105
|
+
if (!p) return FAIL(type, target, "缺 path", true);
|
|
106
|
+
const j = JSON.parse(readFileSync(p, "utf8"));
|
|
107
|
+
const v = walkJsonPath(j, c.jsonPath);
|
|
108
|
+
const n = Array.isArray(v) ? v.length : (typeof v === "number" ? v : NaN);
|
|
109
|
+
if (!Number.isFinite(n)) return FAIL(type, `${p} ${c.jsonPath ?? ""}`, `值不是数组或数字(${v === undefined ? "路径未命中" : typeof v})`);
|
|
110
|
+
const min = Number(c.min);
|
|
111
|
+
return n >= min ? PASS(type, `${p} ${c.jsonPath ?? ""}`, `${n} ≥ ${min}`) : FAIL(type, `${p} ${c.jsonPath ?? ""}`, `got ${n} < ${min}`);
|
|
112
|
+
}
|
|
113
|
+
if (type === "countOccurrences") {
|
|
114
|
+
const p = resolvePath(c.path, root);
|
|
115
|
+
if (!p) return FAIL(type, target, "缺 path", true);
|
|
116
|
+
const needle = c.text;
|
|
117
|
+
if (typeof needle !== "string" || !needle) return FAIL(type, target, "缺 text(要计数的是字面量子串)", true);
|
|
118
|
+
const hay = readFileSync(p, "utf8");
|
|
119
|
+
const count = countLiteral(hay, needle);
|
|
120
|
+
const min = Number(c.minCount ?? 1);
|
|
121
|
+
return count >= min
|
|
122
|
+
? PASS(type, `${p} 「${cap(needle, 40)}」`, `${count} ≥ ${min}`)
|
|
123
|
+
: FAIL(type, `${p} 「${cap(needle, 40)}」`, `出现 ${count} < ${min}`);
|
|
124
|
+
}
|
|
125
|
+
if (type === "countMatches") {
|
|
126
|
+
const p1 = resolvePath(c.path, root);
|
|
127
|
+
const p2 = resolvePath(c.withPath, root);
|
|
128
|
+
if (!p1 || !p2) return FAIL(type, target, "缺 path 或 withPath", true);
|
|
129
|
+
if (!c.jsonPath || !c.withJsonPath) return FAIL(type, target, "缺 jsonPath / withJsonPath", true);
|
|
130
|
+
const n1 = readCount(p1, c.jsonPath);
|
|
131
|
+
const n2 = readCount(p2, c.withJsonPath);
|
|
132
|
+
const min = Number(c.min ?? 1);
|
|
133
|
+
if (n1 !== n2) return FAIL(type, `${p1} ↔ ${p2}`, `不一致:${n1} ≠ ${n2}`);
|
|
134
|
+
return n1 >= min
|
|
135
|
+
? PASS(type, `${p1} ↔ ${p2}`, `${n1} = ${n2} ≥ ${min}`)
|
|
136
|
+
: FAIL(type, `${p1} ↔ ${p2}`, `相等但 ${n1} < min ${min}`);
|
|
137
|
+
}
|
|
138
|
+
if (type === "referencesExist") {
|
|
139
|
+
const p = resolvePath(c.path, root);
|
|
140
|
+
if (!p) return FAIL(type, target, "缺 path", true);
|
|
141
|
+
if (!c.jsonPath) return FAIL(type, target, "缺 jsonPath(指向引用列表的路径)", true);
|
|
142
|
+
const j = JSON.parse(readFileSync(p, "utf8"));
|
|
143
|
+
const v = walkJsonPath(j, c.jsonPath);
|
|
144
|
+
const refs = Array.isArray(v) ? v : [v];
|
|
145
|
+
if (!refs.length || refs.some((r) => typeof r !== "string" || !r.trim())) {
|
|
146
|
+
return FAIL(type, `${p} ${c.jsonPath}`, `引用列表为空或含非字符串项(共 ${refs.length} 项)`);
|
|
147
|
+
}
|
|
148
|
+
const refBase = resolvePath(c.baseDir, root) ?? root;
|
|
149
|
+
const missing = [];
|
|
150
|
+
for (const r of refs) {
|
|
151
|
+
const rp = resolvePath(r, refBase);
|
|
152
|
+
try {
|
|
153
|
+
if (!statSync(rp).isFile()) missing.push(r);
|
|
154
|
+
} catch {
|
|
155
|
+
missing.push(r);
|
|
156
|
+
}
|
|
157
|
+
if (missing.length >= 3) break;
|
|
158
|
+
}
|
|
159
|
+
return missing.length === 0
|
|
160
|
+
? PASS(type, `${p} ${c.jsonPath}`, `${refs.length} 个引用全部存在`)
|
|
161
|
+
: FAIL(type, `${p} ${c.jsonPath}`, `${refs.length} 个引用中存在缺失(示例:${missing.map((m) => cap(m, 60)).join(", ")}${refs.length - missing.length > 3 ? " …" : ""})`);
|
|
162
|
+
}
|
|
163
|
+
return FAIL(type, target, `未知检查类型「${type}」(fail-closed)`, true);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
return FAIL(type, String(target), e.code === "ENOENT" ? "不存在" : cap(e.message, 160));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 返回 null = 无可执行的 V1 检查(无 acceptance / 空 checks / mode=human(V3 队列未建,
|
|
170
|
+
// 本阶段按 legacy 放行,调用方记日志));否则 {pass, checks, mode}。
|
|
171
|
+
export function evaluateAcceptance({ acceptance, baseDir } = {}) {
|
|
172
|
+
if (!acceptance || typeof acceptance !== "object") return null;
|
|
173
|
+
if (acceptance.mode === "human") return null;
|
|
174
|
+
const checks = Array.isArray(acceptance.checks) ? acceptance.checks : [];
|
|
175
|
+
if (!checks.length) return null;
|
|
176
|
+
const root = acceptance.baseDir ?? baseDir ?? process.cwd();
|
|
177
|
+
const results = checks.map((c) => runCheck(c, root));
|
|
178
|
+
return { pass: results.every((r) => r.pass), checks: results, mode: acceptance.mode ?? "auto" };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function formatVerifyNote({ key, verdict, checks = [], by = "bridge" }) {
|
|
182
|
+
const passed = checks.filter((c) => c.pass).length;
|
|
183
|
+
const head = `[[verify]] key=${key} verdict=${verdict} level=V1 by=${by} checks=${passed}/${checks.length}`;
|
|
184
|
+
if (verdict === "PASS") return head;
|
|
185
|
+
return [head, ...checks.filter((c) => !c.pass).map((c) => `· FAIL ${c.type} ${cap(c.target, 120)} — ${cap(c.evidence, 200)}`)].join("\n");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const failingLines = (v) => v.checks.filter((c) => !c.pass).map((c) => `· ${c.type} ${cap(c.target, 120)} — ${cap(c.evidence, 200)}`).join("\n") || "(无逐项证据)";
|
|
189
|
+
|
|
190
|
+
export function applyVerifyPass({ b, io, ID, key, v }) {
|
|
191
|
+
io.note(b, ID, formatVerifyNote({ key, verdict: "PASS", checks: v.checks, by: ID }));
|
|
192
|
+
// 结构化裁决落链(kind=verify);旧 dist 无 verify API 时 io.verify 为 undefined,可选调用跳过。
|
|
193
|
+
io.verify?.(b, ID, key, "pass", { level: "V1", summary: `verify PASS ${key} (V1)`, checks: v.checks });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 验收未通过的完整处置(在 execute() 的写板回调内调用,io = lib/board.js)。
|
|
197
|
+
// 与调度层共用重试台账:未用尽 → 回 open + 退避重派;用尽 → 落 blocked + 该面按
|
|
198
|
+
// 「verification」类熔断(复用供应熔断机器,到期自动放探针)。
|
|
199
|
+
export function applyVerifyFail({ b, io, store, ID, owner, key, agent, task, v, maxAttempts, baseMs, maxDelayMs, holdBase, holdMax, now }) {
|
|
200
|
+
const attempts = store.s.retries?.[key]?.n ?? 0;
|
|
201
|
+
const d = retryDecision({ why: "验收未通过(V1)", attempts, maxAttempts, baseMs, maxDelayMs });
|
|
202
|
+
const creator = task?.createdBy ?? owner;
|
|
203
|
+
const note = formatVerifyNote({ key, verdict: "FAIL", checks: v.checks, by: ID });
|
|
204
|
+
io.verify?.(b, ID, key, "fail", { level: "V1", summary: `verify FAIL ${key} (V1)`, checks: v.checks });
|
|
205
|
+
if (d.retry) {
|
|
206
|
+
(store.s.retries ??= {})[key] = { n: d.attempt, dueAt: now + d.delayMs, agent, why: "verify-fail", lastAt: now };
|
|
207
|
+
io.setStatus(b, ID, key, "open");
|
|
208
|
+
io.note(b, ID, `[${ID}→${agent}] ${note}\n· 不接受 done,任务回 open;${left(d.delayMs)} 后自动重派(第 ${d.attempt}/${maxAttempts} 次)`);
|
|
209
|
+
io.message(b, ID, creator, `[${ID}] 任务 ${key} 执行完成但未通过验收(V1):\n${failingLines(v)}\n已回 open,将于 ${left(d.delayMs)} 后自动重派(第 ${d.attempt}/${maxAttempts} 次)。`);
|
|
210
|
+
return { outcome: "retry-scheduled", attempts: d.attempt, delayMs: d.delayMs };
|
|
211
|
+
}
|
|
212
|
+
const streak0 = store.supplyGet(agent)?.streak ?? 0;
|
|
213
|
+
const latch = store.supplyLatch(agent, {
|
|
214
|
+
category: "verification", label: "连续验收不通过", key, to: creator, runDir: null,
|
|
215
|
+
evidence: failingLines(v), evidenceFile: "verify:v1",
|
|
216
|
+
holdMs: Math.min(holdBase * 2 ** streak0, holdMax),
|
|
217
|
+
});
|
|
218
|
+
delete store.s.retries?.[key];
|
|
219
|
+
io.setStatus(b, ID, key, "blocked");
|
|
220
|
+
io.note(b, ID, `[${ID}→${agent}] ${note}\n· 自动重派用尽(${maxAttempts} 次)仍不过验收 → 落 blocked;${agent} 面按「验收不通过」熔断 ${left(latch.holdMs)}(第 ${latch.streak} 次),到期自动放探针。`);
|
|
221
|
+
io.message(b, ID, creator, `[${ID}] 任务 ${key} 重派 ${maxAttempts} 次仍未通过验收,已落 blocked,需要你处置:放宽或修正验收标准后 requeue,或人工检查工件。证据:\n${failingLines(v)}`);
|
|
222
|
+
return { outcome: "exhausted", streak: latch.streak, holdMs: latch.holdMs };
|
|
223
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// watchdog-core — 冻结自愈看门狗的决策核(纯函数 + 注入时钟,可单测;I/O 留给 watchdog-worker.mjs)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么要有这颗核(2026-10-06,接 10-02 缺口④ 与 10-05 误杀事故):
|
|
4
|
+
// 原来只有一条判据「主线程心跳静默 > staleMs 且连续两振」,而静默有两种成因,读数完全同形:
|
|
5
|
+
// (a) 事件循环真冻结(10-02 形状,必须杀);
|
|
6
|
+
// (b) 整机被挂起(睡眠/休眠)后唤醒,唤醒瞬间 CPU 饥饿,主线程只是还没被调度到(10-05 形状,
|
|
7
|
+
// 杀错的就是健在的守护:实测它 36.989433s 后自己答了 /ps)。
|
|
8
|
+
// 单靠静默时长分不开,所以加两道独立闸:
|
|
9
|
+
// 闸一(自测节拍):worker 自己也在被挂起之列。若自己这一拍比 checkMs 晚了 staleMs 以上,
|
|
10
|
+
// 说明「整进程」被挂起过,此刻的静默读数不可解释 → 清零、不做任何 I/O、不杀。
|
|
11
|
+
// 闸二(端口旁证):两振成立后先问一次控制口,且给**远大于 guard 探针**的预算(饥饿中的守护
|
|
12
|
+
// 会慢答,冻结的事件循环永远不答)。有答 / 探针期间心跳恢复 → 弃权。
|
|
13
|
+
// 保留:闸二里「整段预算无一字应答」和「拒连」仍判杀——这正是 10-02 缺口①要治的那个形状,不能让
|
|
14
|
+
// 「超时一律弃权」把冻结自愈能力退回 0(那件事交给分钟级的 guard 反而做不了:guard 必须秒级退出)。
|
|
15
|
+
export function createWatchdog({ now, staleMs, graceMs, checkMs, probe, kill, log = () => {} }) {
|
|
16
|
+
const startedAt = now();
|
|
17
|
+
let lastMsg = startedAt;
|
|
18
|
+
let lastTick = startedAt;
|
|
19
|
+
let streak = 0;
|
|
20
|
+
let busy = false;
|
|
21
|
+
let fired = false; // 只开火一次(2026-10-06 W1b 实测:不置闸的话,杀完之后每一拍都会再杀一次)
|
|
22
|
+
|
|
23
|
+
const onHeartbeat = () => { lastMsg = now(); streak = 0; };
|
|
24
|
+
|
|
25
|
+
async function tick() {
|
|
26
|
+
const t = now();
|
|
27
|
+
const tickGap = t - lastTick;
|
|
28
|
+
lastTick = t;
|
|
29
|
+
if (busy) return "probing-busy";
|
|
30
|
+
if (fired) return "already-fired";
|
|
31
|
+
if (t - startedAt < graceMs) return "grace";
|
|
32
|
+
|
|
33
|
+
if (tickGap - checkMs > staleMs) {
|
|
34
|
+
streak = 0; lastMsg = t;
|
|
35
|
+
log(`watchdog: 自身节拍迟到 ${Math.round(tickGap / 1000)}s(checkMs=${checkMs})— 整进程被挂起过,静默读数不可解释,计数清零且不查端口`);
|
|
36
|
+
return "suspend-reset";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const silence = t - lastMsg;
|
|
40
|
+
if (silence <= staleMs) { streak = 0; return "healthy"; }
|
|
41
|
+
streak += 1;
|
|
42
|
+
if (streak < 2) {
|
|
43
|
+
log(`watchdog: main heartbeat silent ${Math.round(silence / 1000)}s (strike 1) — waiting one more check`);
|
|
44
|
+
return "strike1";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
busy = true;
|
|
48
|
+
let outcome;
|
|
49
|
+
try { outcome = await probe(); } catch (e) { outcome = "probe-error"; log(`watchdog: 探针抛错 ${e.message}`); }
|
|
50
|
+
busy = false;
|
|
51
|
+
lastTick = now();
|
|
52
|
+
|
|
53
|
+
const resumed = now() - lastMsg <= staleMs;
|
|
54
|
+
if (outcome === "answered" || resumed) {
|
|
55
|
+
streak = 0; lastMsg = now();
|
|
56
|
+
log(`watchdog: 静默 ${Math.round(silence / 1000)}s 但控制口 ${outcome === "answered" ? "有应答" : "心跳已恢复"} — 主循环只是慢,不是冻结,弃权`);
|
|
57
|
+
return outcome === "answered" ? "answered-stand-down" : "heartbeat-resumed-stand-down";
|
|
58
|
+
}
|
|
59
|
+
if (outcome === "probe-error") { streak = 0; return "abstain-probe-error"; }
|
|
60
|
+
|
|
61
|
+
log(`watchdog: 主线程静默 ${Math.round(silence / 1000)}s 两振成立、自身节拍正常、控制口整段预算判为 ${outcome} — SIGKILL 自杀重启`);
|
|
62
|
+
fired = true;
|
|
63
|
+
kill();
|
|
64
|
+
return outcome === "refused" ? "kill-refused" : "kill-unanswered";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { onHeartbeat, tick, snapshot: () => ({ streak, silence: now() - lastMsg, tickGap: now() - lastTick }) };
|
|
68
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Freeze self-rescue watchdog worker(2026-10-02 事故缺口④;2026-10-06 补 10-05 误杀的两道闸)。
|
|
2
|
+
// 决策逻辑全在 lib/watchdog-core.mjs(纯函数、注入时钟、可单测);这颗线程只做 I/O:
|
|
3
|
+
// 收心跳、按拍调用 decide、探控制口、必要时 SIGKILL 自己进程让 run_daemon.bat 重启。
|
|
4
|
+
// 铁律不变:看门狗自己的 bug 绝不能杀健在的守护——每一步单独兜住,判据不足就弃权。
|
|
5
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
6
|
+
import { appendFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { killTree } from "./platform.js";
|
|
9
|
+
import { createWatchdog } from "./watchdog-core.mjs";
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
pid,
|
|
13
|
+
staleMs,
|
|
14
|
+
graceMs,
|
|
15
|
+
checkMs,
|
|
16
|
+
logFile,
|
|
17
|
+
port = null,
|
|
18
|
+
tokenPath = null,
|
|
19
|
+
probeBudgetMs = 120000, // 必须远大于 guard.js 的 3500ms:10-05 实测健在但饥饿的守护答 /ps 用了 36.989433s,取 3 倍余量
|
|
20
|
+
probeAttemptMs = 8000,
|
|
21
|
+
} = workerData;
|
|
22
|
+
|
|
23
|
+
const wlog = (m) => {
|
|
24
|
+
try { mkdirSync(dirname(logFile), { recursive: true }); appendFileSync(logFile, `[${new Date().toISOString()}] ${m}\n`); } catch { /* never fail on logging */ }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 端口旁证:任何 HTTP 应答(哪怕 401)都证明事件循环在服务 → answered;
|
|
28
|
+
// 拒连(内核 RST,没人监听)→ refused;连得上但整段预算一个字没回 → timeout。
|
|
29
|
+
async function probePort() {
|
|
30
|
+
if (!port) { wlog("watchdog: 未配置控制口,无法旁证 — 保守按 answered 弃权"); return "answered"; }
|
|
31
|
+
let token = "";
|
|
32
|
+
try { token = tokenPath && existsSync(tokenPath) ? readFileSync(tokenPath, "utf8").trim() : ""; } catch { /* 空 token 仍能给 401,足以证明在服务 */ }
|
|
33
|
+
const deadline = Date.now() + probeBudgetMs;
|
|
34
|
+
while (Date.now() < deadline) {
|
|
35
|
+
try {
|
|
36
|
+
await fetch(`http://127.0.0.1:${port}/ps?token=${encodeURIComponent(token)}`, { signal: AbortSignal.timeout(Math.max(500, probeAttemptMs)) });
|
|
37
|
+
return "answered";
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if ((e?.cause?.code ?? e?.code) === "ECONNREFUSED") return "refused";
|
|
40
|
+
// TimeoutError 等:可能是慢,继续给预算,不作数
|
|
41
|
+
}
|
|
42
|
+
const left = deadline - Date.now();
|
|
43
|
+
if (left <= 0) break;
|
|
44
|
+
await new Promise((r) => setTimeout(r, Math.min(2000, left)));
|
|
45
|
+
}
|
|
46
|
+
return "timeout";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const doKill = () => {
|
|
50
|
+
try {
|
|
51
|
+
process.kill(pid, "SIGKILL");
|
|
52
|
+
} catch (e) {
|
|
53
|
+
wlog(`watchdog: SIGKILL failed (${e.message}) — falling back to platform killTree`);
|
|
54
|
+
killTree(pid, { log: wlog });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const wd = createWatchdog({
|
|
59
|
+
now: () => Date.now(),
|
|
60
|
+
staleMs, graceMs, checkMs,
|
|
61
|
+
probe: probePort,
|
|
62
|
+
kill: doKill,
|
|
63
|
+
log: wlog,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (parentPort) parentPort.on("message", () => { try { wd.onHeartbeat(); } catch { /* never act on a watchdog bug */ } });
|
|
67
|
+
|
|
68
|
+
let running = false;
|
|
69
|
+
const timer = setInterval(() => {
|
|
70
|
+
if (running) return;
|
|
71
|
+
running = true;
|
|
72
|
+
wd.tick()
|
|
73
|
+
.catch((e) => wlog(`watchdog tick failed: ${e.message}`))
|
|
74
|
+
.finally(() => { running = false; });
|
|
75
|
+
}, checkMs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proofdeck",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Verification-first task board and orchestrator for coding-agent fleets. Agents claim done; ProofDeck demands proof.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/board.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node scripts/run-e2e.mjs"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"proofdeck": "bin/proofdeck.js"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.5.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
19
|
+
"commander": "^15.0.0",
|
|
20
|
+
"zod": "^4.4.3"
|
|
21
|
+
},
|
|
22
|
+
"optionalDependencies": {
|
|
23
|
+
"better-sqlite3": "^12.11.1"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib",
|
|
27
|
+
"board",
|
|
28
|
+
"e2e",
|
|
29
|
+
"bin",
|
|
30
|
+
"docs",
|
|
31
|
+
"daemon.js",
|
|
32
|
+
"guard.js",
|
|
33
|
+
"scripts",
|
|
34
|
+
"config.example.json",
|
|
35
|
+
"README.md",
|
|
36
|
+
"README.zh-CN.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"NOTICE"
|
|
39
|
+
],
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/kumu314/proofdeck.git"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"ai-agents",
|
|
46
|
+
"coding-agents",
|
|
47
|
+
"orchestration",
|
|
48
|
+
"verification",
|
|
49
|
+
"acceptance-criteria",
|
|
50
|
+
"task-board",
|
|
51
|
+
"blackboard",
|
|
52
|
+
"multi-agent",
|
|
53
|
+
"mcp",
|
|
54
|
+
"claude-code",
|
|
55
|
+
"codex"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# ProofDeck POSIX launcher — mirrors run_daemon.bat on Windows:
|
|
3
|
+
# - restart loop (10s) so a crashed daemon comes back
|
|
4
|
+
# - rc=3 = lost the control-port single-instance race → self-exit (the
|
|
5
|
+
# winner is running; without this every losing loop would retry forever)
|
|
6
|
+
# - rc=0 = clean exit → self-exit
|
|
7
|
+
# - STOP file stops the loop
|
|
8
|
+
# Refuses to run without a daemon.config.json (fresh clone / CI: no-op).
|
|
9
|
+
DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
10
|
+
cd "$DIR" || exit 1
|
|
11
|
+
[ -f "$DIR/daemon.config.json" ] || exit 0
|
|
12
|
+
while :; do
|
|
13
|
+
node "$DIR/daemon.js" "$DIR/daemon.config.json"
|
|
14
|
+
rc=$?
|
|
15
|
+
if [ "$rc" -eq 3 ] || [ "$rc" -eq 0 ]; then exit 0; fi
|
|
16
|
+
[ -f "$DIR/STOP" ] && exit 0
|
|
17
|
+
sleep 10
|
|
18
|
+
done
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Cross-platform e2e suite runner (CI + local).
|
|
2
|
+
// Usage: node scripts/run-e2e.mjs [pattern]
|
|
3
|
+
// Runs every e2e/verify-*.mjs against a temp board; exits non-zero on any failure.
|
|
4
|
+
// Backend lever: OCTOBOARD_BACKEND=better-sqlite3 exercises the legacy backend.
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { readdirSync } from "node:fs";
|
|
7
|
+
import { join, dirname } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const pattern = process.argv[2] ?? "";
|
|
12
|
+
const tests = readdirSync(join(root, "e2e"))
|
|
13
|
+
.filter((f) => f.startsWith("verify-") && f.endsWith(".mjs"))
|
|
14
|
+
.filter((f) => f.includes(pattern));
|
|
15
|
+
|
|
16
|
+
console.log(`proofdeck e2e — ${tests.length} suites, backend=${process.env.OCTOBOARD_BACKEND || "native(node:sqlite)"}, node=${process.version}, platform=${process.platform}`);
|
|
17
|
+
let green = 0;
|
|
18
|
+
const red = [];
|
|
19
|
+
for (const t of tests) {
|
|
20
|
+
const r = spawnSync(process.execPath, [join(root, "e2e", t)], {
|
|
21
|
+
encoding: "utf8",
|
|
22
|
+
timeout: 240000,
|
|
23
|
+
cwd: root,
|
|
24
|
+
env: { ...process.env },
|
|
25
|
+
});
|
|
26
|
+
const out = (r.stdout || "") + (r.stderr || "");
|
|
27
|
+
// only lines that START with FAIL are failures — PASS detail text may contain the word
|
|
28
|
+
const realFails = out.split(/\r?\n/).filter((l) => l.startsWith("FAIL ")).length;
|
|
29
|
+
const ok = r.status === 0 && realFails === 0;
|
|
30
|
+
const last = out.trim().split(/\r?\n/).filter(Boolean).pop() ?? "(no output)";
|
|
31
|
+
if (ok) green++;
|
|
32
|
+
else red.push(t);
|
|
33
|
+
console.log(`${ok ? "GREEN" : "RED "} ${t} rc=${r.status} fails=${realFails} :: ${last.slice(0, 90)}`);
|
|
34
|
+
if (!ok && out) {
|
|
35
|
+
for (const l of out.split(/\r?\n/).filter((l) => l.startsWith("FAIL "))) console.log(" " + l.trim().slice(0, 140));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
console.log(`\n=== ${green}/${tests.length} GREEN ===`);
|
|
39
|
+
process.exit(red.length ? 1 : 0);
|