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.
Files changed (139) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +23 -0
  3. package/README.md +152 -2
  4. package/README.zh-CN.md +152 -0
  5. package/bin/proofdeck.js +191 -0
  6. package/board/LICENSE +201 -0
  7. package/board/README.md +473 -0
  8. package/board/README.zh-CN.md +424 -0
  9. package/board/dist/_chk.db-shm +0 -0
  10. package/board/dist/_chk.db-wal +0 -0
  11. package/board/dist/adapters.d.ts +40 -0
  12. package/board/dist/adapters.d.ts.map +1 -0
  13. package/board/dist/adapters.js +124 -0
  14. package/board/dist/adapters.js.map +1 -0
  15. package/board/dist/board.d.ts +628 -0
  16. package/board/dist/board.d.ts.map +1 -0
  17. package/board/dist/board.js +2767 -0
  18. package/board/dist/board.js.map +1 -0
  19. package/board/dist/cli.d.ts +3 -0
  20. package/board/dist/cli.d.ts.map +1 -0
  21. package/board/dist/cli.js +1663 -0
  22. package/board/dist/cli.js.map +1 -0
  23. package/board/dist/config.d.ts +57 -0
  24. package/board/dist/config.d.ts.map +1 -0
  25. package/board/dist/config.js +99 -0
  26. package/board/dist/config.js.map +1 -0
  27. package/board/dist/db.d.ts +9 -0
  28. package/board/dist/db.d.ts.map +1 -0
  29. package/board/dist/db.js +506 -0
  30. package/board/dist/db.js.map +1 -0
  31. package/board/dist/git.d.ts +35 -0
  32. package/board/dist/git.d.ts.map +1 -0
  33. package/board/dist/git.js +147 -0
  34. package/board/dist/git.js.map +1 -0
  35. package/board/dist/index.d.ts +18 -0
  36. package/board/dist/index.d.ts.map +1 -0
  37. package/board/dist/index.js +13 -0
  38. package/board/dist/index.js.map +1 -0
  39. package/board/dist/mcp-config.d.ts +26 -0
  40. package/board/dist/mcp-config.d.ts.map +1 -0
  41. package/board/dist/mcp-config.js +88 -0
  42. package/board/dist/mcp-config.js.map +1 -0
  43. package/board/dist/mcp.d.ts +3 -0
  44. package/board/dist/mcp.d.ts.map +1 -0
  45. package/board/dist/mcp.js +949 -0
  46. package/board/dist/mcp.js.map +1 -0
  47. package/board/dist/quickstart.d.ts +75 -0
  48. package/board/dist/quickstart.d.ts.map +1 -0
  49. package/board/dist/quickstart.js +156 -0
  50. package/board/dist/quickstart.js.map +1 -0
  51. package/board/dist/serve.d.ts +10 -0
  52. package/board/dist/serve.d.ts.map +1 -0
  53. package/board/dist/serve.js +445 -0
  54. package/board/dist/serve.js.map +1 -0
  55. package/board/dist/signing.d.ts +18 -0
  56. package/board/dist/signing.d.ts.map +1 -0
  57. package/board/dist/signing.js +26 -0
  58. package/board/dist/signing.js.map +1 -0
  59. package/board/dist/sync.d.ts +49 -0
  60. package/board/dist/sync.d.ts.map +1 -0
  61. package/board/dist/sync.js +158 -0
  62. package/board/dist/sync.js.map +1 -0
  63. package/board/dist/types.d.ts +359 -0
  64. package/board/dist/types.d.ts.map +1 -0
  65. package/board/dist/types.js +20 -0
  66. package/board/dist/types.js.map +1 -0
  67. package/board/docs/adr/0001-shared-worktree-collision.md +102 -0
  68. package/board/docs/adr/0001-shared-worktree-collision.zh-CN.md +90 -0
  69. package/board/docs/attribution.md +123 -0
  70. package/board/docs/attribution.zh-CN.md +104 -0
  71. package/board/docs/development-workflow.md +81 -0
  72. package/board/docs/development-workflow.zh-CN.md +75 -0
  73. package/board/docs/diagrams/banner.png +0 -0
  74. package/board/docs/diagrams/banner.svg +1 -0
  75. package/board/docs/diagrams/before-after.png +0 -0
  76. package/board/docs/diagrams/before-after.svg +1 -0
  77. package/board/docs/diagrams/governance-chain.png +0 -0
  78. package/board/docs/diagrams/governance-chain.svg +1 -0
  79. package/board/docs/diagrams/value-flow.png +0 -0
  80. package/board/docs/diagrams/value-flow.svg +1 -0
  81. package/board/docs/entry-point.md +81 -0
  82. package/board/docs/entry-point.zh-CN.md +65 -0
  83. package/board/docs/kanban.png +0 -0
  84. package/board/docs/octoryn-mark.png +0 -0
  85. package/board/docs/registry-metadata.md +34 -0
  86. package/board/docs/registry-metadata.zh-CN.md +30 -0
  87. package/board/package.json +87 -0
  88. package/config.example.json +72 -0
  89. package/daemon.js +1148 -0
  90. package/docs/assets/demo.gif +0 -0
  91. package/docs/assets/logo-512.png +0 -0
  92. package/docs/assets/logo.svg +31 -0
  93. package/docs/assets/social-preview.png +0 -0
  94. package/docs/demo-run.mjs +61 -0
  95. package/docs/render-demo.py +94 -0
  96. package/docs/render-logo.py +101 -0
  97. package/docs/task-book.md +58 -0
  98. package/e2e/verify-acceptance.mjs +150 -0
  99. package/e2e/verify-antifraud.mjs +128 -0
  100. package/e2e/verify-caps.mjs +46 -0
  101. package/e2e/verify-checkpoint.mjs +208 -0
  102. package/e2e/verify-firstclass.mjs +110 -0
  103. package/e2e/verify-judge.mjs +52 -0
  104. package/e2e/verify-lease.mjs +95 -0
  105. package/e2e/verify-replay.mjs +92 -0
  106. package/e2e/verify-resilience.mjs +323 -0
  107. package/e2e/verify-review.mjs +86 -0
  108. package/e2e/verify-scheduling.mjs +110 -0
  109. package/e2e/verify-schema-evolution.mjs +107 -0
  110. package/e2e/verify-sla-digest.mjs +105 -0
  111. package/guard.js +97 -0
  112. package/lib/adapters/codex.js +206 -0
  113. package/lib/billing-convert.js +57 -0
  114. package/lib/board.js +46 -0
  115. package/lib/caps.js +35 -0
  116. package/lib/checkpoint.js +130 -0
  117. package/lib/gating.js +218 -0
  118. package/lib/guard-core.mjs +108 -0
  119. package/lib/http.js +161 -0
  120. package/lib/judge.js +89 -0
  121. package/lib/lease.js +93 -0
  122. package/lib/notify.js +56 -0
  123. package/lib/platform.js +120 -0
  124. package/lib/replay.js +68 -0
  125. package/lib/review.js +40 -0
  126. package/lib/runner.js +152 -0
  127. package/lib/schedule.js +59 -0
  128. package/lib/sla.js +42 -0
  129. package/lib/spans.js +36 -0
  130. package/lib/starve.js +43 -0
  131. package/lib/store.js +109 -0
  132. package/lib/supply.js +101 -0
  133. package/lib/usage.js +103 -0
  134. package/lib/verify.js +223 -0
  135. package/lib/watchdog-core.mjs +68 -0
  136. package/lib/watchdog-worker.mjs +75 -0
  137. package/package.json +55 -4
  138. package/scripts/run-daemon.sh +18 -0
  139. package/scripts/run-e2e.mjs +39 -0
Binary file
Binary file
@@ -0,0 +1,31 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
2
+ <!-- ProofDeck logo: a deck card stamped with a proof seal, chained. -->
3
+ <defs>
4
+ <linearGradient id="cardbg" x1="0" y1="0" x2="1" y2="1">
5
+ <stop offset="0" stop-color="#1c2b2e"/>
6
+ <stop offset="1" stop-color="#172224"/>
7
+ </linearGradient>
8
+ </defs>
9
+
10
+ <!-- hash-chain dots leading into the card -->
11
+ <g fill="#a6d0b9" opacity="0.55">
12
+ <circle cx="70" cy="430" r="10"/>
13
+ <circle cx="108" cy="456" r="7"/>
14
+ <circle cx="142" cy="474" r="4.5"/>
15
+ </g>
16
+
17
+ <!-- the deck card, slightly stamped over -->
18
+ <g transform="rotate(-8 256 256)">
19
+ <rect x="96" y="96" width="320" height="320" rx="48" fill="url(#cardbg)" stroke="#e9c779" stroke-width="10"/>
20
+ <!-- proof seal: ring + check -->
21
+ <circle cx="256" cy="240" r="92" fill="none" stroke="#e9c779" stroke-width="12"/>
22
+ <circle cx="256" cy="240" r="74" fill="none" stroke="#a6d0b9" stroke-width="4" opacity="0.5"/>
23
+ <path d="M 214 244 L 246 276 L 306 204" fill="none" stroke="#a6d0b9" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/>
24
+ <!-- card footer rule: the "evidence line" -->
25
+ <line x1="170" y1="368" x2="342" y2="368" stroke="#e9c779" stroke-width="8" stroke-linecap="round" opacity="0.85"/>
26
+ <line x1="196" y1="388" x2="316" y2="388" stroke="#e9c779" stroke-width="5" stroke-linecap="round" opacity="0.45"/>
27
+ </g>
28
+
29
+ <!-- stamp notch: the deck was here -->
30
+ <circle cx="418" cy="118" r="9" fill="#e9c779" opacity="0.9"/>
31
+ </svg>
Binary file
@@ -0,0 +1,61 @@
1
+ // Demo: a "fake done" gets caught by the real verification engine.
2
+ // This is NOT a mock — it calls lib/verify.js evaluateAcceptance with the same
3
+ // fail-closed check types the daemon runs before accepting a done claim.
4
+ //
5
+ // Output is a plain-text terminal transcript (no ANSI), so render-demo.mjs can
6
+ // turn an actual run into the demo GIF honestly.
7
+ import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
8
+ import { tmpdir } from "node:os";
9
+ import { join, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { pathToFileURL } from "node:url";
12
+
13
+ const root = dirname(fileURLToPath(import.meta.url));
14
+ const { evaluateAcceptance } = await import(pathToFileURL(join(root, "..", "lib", "verify.js")).href);
15
+
16
+ const work = mkdtempSync(join(tmpdir(), "proofdeck-demo-"));
17
+ const line = (s) => console.log(s);
18
+
19
+ try {
20
+ // The agent "finished" the task and wrote its report — but only 1 item, not 3.
21
+ mkdirSync(join(work, "out"), { recursive: true });
22
+ writeFileSync(join(work, "out", "report.json"), JSON.stringify({ count: 1, note: "everything done!" }));
23
+
24
+ line("$ proofdeck task claim fix-pagination # agent starts working");
25
+ line("$ ... agent edits files, runs tests, writes out/report.json");
26
+ line("$ proofdeck task done fix-pagination # agent claims DONE");
27
+ line("");
28
+
29
+ const acceptance = {
30
+ baseDir: work,
31
+ checks: [
32
+ { type: "countAtLeast", path: "out/report.json", jsonPath: "count", min: 3 },
33
+ { type: "fileExists", path: "out/notes.md" },
34
+ ],
35
+ };
36
+
37
+ line(" acceptance gate — fail-closed:");
38
+ for (const c of acceptance.checks) line(` · ${c.type} ${c.path}${c.jsonPath ? " ." + c.jsonPath : ""}${c.min != null ? " >= " + c.min : ""}`);
39
+ line("");
40
+ line(" verify V1 running...");
41
+
42
+ const v = evaluateAcceptance({ acceptance });
43
+ for (const r of v.checks) {
44
+ line(` ${r.pass ? "PASS" : "FAIL"} ${r.type} ${r.target ?? ""} ${r.evidence ?? ""}`);
45
+ }
46
+ line("");
47
+
48
+ if (!v.pass) {
49
+ line(" done REJECTED — no evidence, no completion.");
50
+ line(" => task returns to open for redispatch (retry/breaker applies).");
51
+ line(" => a verify event is appended to the sha256 hash chain.");
52
+ line(" => upstream UI shows: \"agent said done; ProofDeck demanded proof.\"");
53
+ line("");
54
+ line(` demo workspace: ${work}`);
55
+ } else {
56
+ line(" PASS — done accepted (this demo expects FAIL; something changed!)");
57
+ }
58
+ } finally {
59
+ // Keep the demo output stable; workspace is a throwaway — delete it.
60
+ try { rmSync(work, { recursive: true, force: true }); } catch { }
61
+ }
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env python3
2
+ """Render demo-transcript.txt (an ACTUAL run of docs/demo-run.mjs) into demo.gif.
3
+
4
+ Honesty: every line comes verbatim from a real invocation of lib/verify.js —
5
+ this script only styles the text; it never invents output.
6
+ """
7
+ from PIL import Image, ImageDraw, ImageFont
8
+ import sys, os
9
+
10
+ TRANSCRIPT = "D:/AgentHub/tmp/demo-transcript.txt"
11
+ OUT = os.path.join(os.path.dirname(__file__), "assets", "demo.gif")
12
+
13
+ W, H = 1000, 620
14
+ PAD = 28
15
+ LINE_H = 25
16
+ BG = (16, 26, 27)
17
+ BAR = (25, 37, 40)
18
+ INK = (237, 240, 223)
19
+ DIM = (140, 158, 152)
20
+ MINT = (166, 208, 185)
21
+ RED = (255, 107, 107)
22
+ GOLD = (233, 199, 121)
23
+ ORANGE = (255, 159, 67)
24
+
25
+ def font(size=16, prefer=("C:/Windows/Fonts/consola.ttf", "C:/Windows/Fonts/cour.ttf", "C:/Windows/Fonts/msyh.ttc")):
26
+ for f in prefer:
27
+ if os.path.exists(f):
28
+ return ImageFont.truetype(f, size)
29
+ return ImageFont.load_default()
30
+
31
+ f_body = font(16)
32
+ f_cjk = font(15, ("C:/Windows/Fonts/msyh.ttc",)) # engine evidence strings are Chinese
33
+ f_bar = font(13)
34
+ f_foot = font(12)
35
+
36
+ lines = open(TRANSCRIPT, encoding="utf-8").read().splitlines()
37
+ # Strip volatile temp paths to keep the demo readable and stable.
38
+ lines = [l.replace("D:\\OPENCO~1\\", "D:\\tmp\\").replace("D:\\AgentHub\\tmp\\", "D:\\tmp\\") for l in lines]
39
+
40
+ def color_of(text: str):
41
+ t = text.strip()
42
+ if t.startswith("$"):
43
+ return MINT
44
+ if "FAIL" in t:
45
+ return RED
46
+ if "REJECTED" in t:
47
+ return ORANGE
48
+ if t.startswith("acceptance gate"):
49
+ return GOLD
50
+ if t.startswith("·") or t.startswith("verify V1"):
51
+ return DIM
52
+ if t.startswith("=>"):
53
+ return DIM
54
+ return INK
55
+
56
+ def frame(shown: int, final: bool) -> Image.Image:
57
+ im = Image.new("RGB", (W, H), BG)
58
+ d = ImageDraw.Draw(im)
59
+ # Title bar
60
+ d.rectangle([0, 0, W, 38], fill=BAR)
61
+ d.ellipse([16, 13, 26, 23], fill=(255, 95, 86))
62
+ d.ellipse([32, 13, 42, 23], fill=(255, 189, 46))
63
+ d.ellipse([48, 13, 58, 23], fill=(39, 201, 63))
64
+ d.text((72, 11), "proofdeck — acceptance gate (actual run of lib/verify.js)", font=f_bar, fill=DIM)
65
+ y = 62
66
+ for i in range(0, shown):
67
+ col = color_of(lines[i])
68
+ use = f_cjk if any(ord(ch) > 127 for ch in lines[i]) else f_body
69
+ d.text((PAD, y), lines[i], font=use, fill=col)
70
+ y += LINE_H
71
+ if final:
72
+ # highlight the REJECTED block
73
+ for i, l in enumerate(lines):
74
+ if "done REJECTED" in l:
75
+ yy = 62 + i * LINE_H - 4
76
+ d.rectangle([PAD - 10, yy, W - PAD, yy + LINE_H * 3 + 6], outline=RED, width=2)
77
+ d.text((PAD, H - 22), "text rendered from a real invocation — no fabricated output", font=f_foot, fill=DIM)
78
+ return im
79
+
80
+ frames = []
81
+ durations = []
82
+ # Progressive reveal: a few lines per frame for the fast part, slower at the verdict.
83
+ for shown in range(1, len(lines) + 1):
84
+ is_verdict = any("REJECTED" in lines[i] for i in range(max(0, shown - 3), shown))
85
+ frames.append(frame(shown, final=(shown == len(lines))))
86
+ durations.append(120 if not is_verdict else 420)
87
+ # Hold the last frame
88
+ for _ in range(4):
89
+ frames.append(frame(len(lines), final=True))
90
+ durations.append(900)
91
+
92
+ os.makedirs(os.path.dirname(OUT), exist_ok=True)
93
+ frames[0].save(OUT, save_all=True, append_images=frames[1:], duration=durations, loop=0, optimize=False)
94
+ print(f"wrote {OUT} ({len(frames)} frames, {sum(durations)/1000:.1f}s)")
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env python3
2
+ """Render ProofDeck logo/social-preview PNGs (supersampled for crisp edges)."""
3
+ from PIL import Image, ImageDraw, ImageFont
4
+ import os
5
+
6
+ HERE = os.path.dirname(__file__)
7
+ ASSETS = os.path.join(HERE, "assets")
8
+ os.makedirs(ASSETS, exist_ok=True)
9
+
10
+ GOLD = (233, 199, 121)
11
+ MINT = (166, 208, 185)
12
+ CARD = (28, 43, 46)
13
+ CARD2 = (23, 34, 36)
14
+ BG = (16, 26, 27)
15
+ INK = (237, 240, 223)
16
+ DIM = (140, 158, 152)
17
+
18
+ def font(size, bold=True):
19
+ paths = (["C:/Windows/Fonts/segoeuib.ttf", "C:/Windows/Fonts/arialbd.ttf"] if bold
20
+ else ["C:/Windows/Fonts/segoeui.ttf", "C:/Windows/Fonts/arial.ttf"])
21
+ for p in paths:
22
+ if os.path.exists(p):
23
+ return ImageFont.truetype(p, size)
24
+ return ImageFont.load_default()
25
+
26
+ def rounded_card(d, cx, cy, size, rot_anti=False):
27
+ """Draw the deck card (rotate applied on a square canvas via supersample coords)."""
28
+ # we draw axis-aligned here; rotation handled by drawing the whole logo rotated
29
+ half = size // 2
30
+ d.rounded_rectangle([cx - half, cy - half, cx + half, cy + half], radius=int(size * 0.15),
31
+ fill=CARD, outline=GOLD, width=10)
32
+
33
+ def seal(d, cx, cy, r):
34
+ d.ellipse([cx - r, cy - r, cx + r, cy + r], outline=GOLD, width=12)
35
+ r2 = r - 14
36
+ d.ellipse([cx - r2, cy - r2, cx + r2, cy + r2], outline=MINT, width=4)
37
+ # checkmark
38
+ pts = [(cx - r * 0.48, cy + r * 0.02), (cx - r * 0.12, cy + r * 0.42), (cx + r * 0.56, cy - r * 0.38)]
39
+ d.line(pts, fill=MINT, width=18, joint="curve")
40
+ for p in pts:
41
+ d.ellipse([p[0] - 9, p[1] - 9, p[0] + 9, p[1] + 9], fill=MINT)
42
+
43
+ def chain_dots(d, pts):
44
+ for (x, y, r, o) in pts:
45
+ c = MINT if o == 255 else (MINT[0], MINT[1], MINT[2])
46
+ d.ellipse([x - r, y - r, x + r, y + r], fill=(int(MINT[0] * o / 255), int(MINT[1] * o / 255), int(MINT[2] * o / 255)))
47
+
48
+ def draw_logo_square(scale=2, size_px=512):
49
+ S = size_px * scale
50
+ im = Image.new("RGBA", (S, S), (0, 0, 0, 0))
51
+ d = ImageDraw.Draw(im)
52
+ # rotate the whole emblem by drawing on a larger transparent canvas then rotating
53
+ emblem = Image.new("RGBA", (S, S), (0, 0, 0, 0))
54
+ ed = ImageDraw.Draw(emblem)
55
+ card_size = int(S * 0.62)
56
+ rounded_card(ed, S // 2, S // 2, card_size)
57
+ seal(ed, S // 2, int(S * 0.47), int(S * 0.18))
58
+ # evidence lines
59
+ ed.rounded_rectangle([int(S * 0.33), int(S * 0.72), int(S * 0.67), int(S * 0.745)],
60
+ radius=int(S * 0.012), fill=GOLD)
61
+ ed.rounded_rectangle([int(S * 0.38), int(S * 0.76), int(S * 0.62), int(S * 0.782)],
62
+ radius=int(S * 0.008), fill=(GOLD[0], GOLD[1], GOLD[2], 115))
63
+ # chain dots
64
+ chain_dots(ed, [(int(S * 0.14), int(S * 0.84), int(S * 0.02), 140),
65
+ (int(S * 0.21), int(S * 0.89), int(S * 0.014), 110),
66
+ (int(S * 0.27), int(S * 0.925), int(S * 0.009), 90)])
67
+ emblem = emblem.rotate(-8, resample=Image.BICUBIC, expand=False)
68
+ im.alpha_composite(emblem)
69
+ # gold notch
70
+ d.ellipse([int(S * 0.815), int(S * 0.2), int(S * 0.855), int(S * 0.24)], fill=GOLD)
71
+ return im.resize((size_px, size_px), Image.LANCZOS)
72
+
73
+ # 1) logo-512.png
74
+ logo = draw_logo_square(scale=2, size_px=512)
75
+ logo.save(os.path.join(ASSETS, "logo-512.png"))
76
+
77
+ # 2) social preview 1280x640
78
+ SPW, SPH = 1280, 640
79
+ S = 2
80
+ sp = Image.new("RGBA", (SPW * S, SPH * S), BG)
81
+ d = ImageDraw.Draw(sp)
82
+ # subtle vignette bands
83
+ for i, a in enumerate((18, 10)):
84
+ d.rounded_rectangle([40 * S + i * 22 * S, 40 * S + i * 22 * S, SPW * S - 40 * S - i * 22 * S, SPH * S - 40 * S - i * 22 * S],
85
+ radius=30 * S, outline=(GOLD[0], GOLD[1], GOLD[2], 0) if False else (46, 66, 68), width=3 * S)
86
+ logo_sq = draw_logo_square(scale=2, size_px=int(SPH * S * 0.78))
87
+ # paste logo at left
88
+ lx, ly = int(SPW * S * 0.06), int((SPH * S - logo_sq.height) // 2)
89
+ sp.alpha_composite(logo_sq, (lx, ly))
90
+ # wordmark
91
+ tx = lx + logo_sq.width + int(SPW * S * 0.055)
92
+ f_title = font(int(SPH * S * 0.17))
93
+ f_tag = font(int(SPH * S * 0.062), bold=False)
94
+ f_url = font(int(SPH * S * 0.042), bold=False)
95
+ d.text((tx, int(SPH * S * 0.24)), "ProofDeck", font=f_title, fill=INK)
96
+ d.text((tx + int(S * 6), int(SPH * S * 0.46)), "Agents claim done.", font=f_tag, fill=INK)
97
+ d.text((tx + int(S * 6), int(SPH * S * 0.545)), "ProofDeck demands proof.", font=f_tag, fill=MINT)
98
+ d.text((tx + int(S * 6), int(SPH * S * 0.72)), "github.com/kumu314/proofdeck", font=f_url, fill=DIM)
99
+ sp = sp.resize((SPW, SPH), Image.LANCZOS).convert("RGB")
100
+ sp.save(os.path.join(ASSETS, "social-preview.png"))
101
+ print("wrote", os.path.join(ASSETS, "logo-512.png"), "and", os.path.join(ASSETS, "social-preview.png"))
@@ -0,0 +1,58 @@
1
+ # Task books — how ProofDeck reads your tasks
2
+
3
+ A ProofDeck task has two halves:
4
+
5
+ 1. **The card** on the board — title + a **pointer** to the task book file.
6
+ 2. **The task book file** (under `briefs/`) — the actual instruction text plus a
7
+ ```bridge fence carrying the dispatch metadata.
8
+
9
+ Why a file? The gating layer evaluates the book's content (risk words, sandbox
10
+ requests, auto flags) before dispatch, and the file is what gets archived with
11
+ the run for audit. Inline descriptions are treated as pointers only.
12
+
13
+ ## Format
14
+
15
+ ```markdown
16
+ <instruction text for the agent>
17
+
18
+ ```bridge
19
+ { "auto": "yes", "risk": "low", "impact": "low" }
20
+ ```
21
+ ```
22
+
23
+ The fence fields:
24
+
25
+ | Field | Meaning |
26
+ |---|---|
27
+ | `auto` | `"yes"` → the gate may dispatch automatically (risk words still apply) |
28
+ | `risk` | `low` / `medium` / `high` / `critical` — must be in `gating.autoRisk` for auto dispatch |
29
+ | `impact` | metadata; `high`/`critical` hits `gating.blockImpact` |
30
+ | `agent` | optional — pin the task to a specific face (otherwise first enabled face / autoAssign) |
31
+ | `priority` | optional — `P0`…`P3` lane priority |
32
+ | `acceptance` | optional — inline acceptance override (otherwise the card's `acceptance` column is used) |
33
+ | `sandbox` | optional — override the face sandbox for this task (`danger` requires approval) |
34
+
35
+ ## Lifecycle
36
+
37
+ 1. `proofdeck init` scaffolds `briefs/` with a starter task book.
38
+ 2. Write the book, then put the pointer on a card:
39
+ `description: "任务书:D:/path/to/briefs/my-task.md"`
40
+ 3. Dispatch it: `proofdeck assign my-task codex` — or just leave it open;
41
+ `autoAssign` (default on) queues auto-flagged books automatically.
42
+ 4. The gate runs: risk words → auto/ask/soft; the face executes; the verify
43
+ engine checks acceptance; the verdict lands in the hash chain.
44
+
45
+ ## Gotchas (dogfood-tested)
46
+
47
+ - **No fence → parked.** A book without a ```bridge fence is parked with
48
+ "未找到可读的任务书文件" — the gate refuses to guess your intent.
49
+ - **Relative `workdir` dies twice.** Face workdirs are resolved against the
50
+ daemon BASE at load; the agent's own `-C` resolves again inside the workdir —
51
+ use absolute paths (init normalizes them for you).
52
+ - **Codex faces need API-key mode for custom providers.** ChatGPT-account auth
53
+ only serves OpenAI models. Give a face its own `CODEX_HOME` with
54
+ `preferred_auth_method = "apikey"` + a DeepSeek/magpie provider to mix
55
+ account-quota and API-quota faces on one machine.
56
+ - **Windows sandbox blocks shell writes by default.** For tasks that must run
57
+ shell commands, set the face `sandbox` accordingly (`workspace-write` allows
58
+ workspace writes; anything broader is gated).
@@ -0,0 +1,150 @@
1
+ // e2e: acceptance verification V1 (验证层 Part B) — pure checks + full fail-path
2
+ // integration against a TEST board and a temp store. Never touches the real board.
3
+ import { mkdtempSync, writeFileSync, mkdirSync, readFileSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { pathToFileURL, fileURLToPath } from "node:url";
7
+
8
+ const V = await import(new URL("../lib/verify.js", import.meta.url).href);
9
+ const { Store } = await import(new URL("../lib/store.js", import.meta.url).href);
10
+ const boardCh = await import(new URL("../lib/board.js", import.meta.url).href);
11
+
12
+ let pass = 0, fail = 0;
13
+ const ok = (name, cond, detail = "") => {
14
+ if (cond) { pass++; console.log(`PASS ${name}${detail ? " — " + detail : ""}`); }
15
+ else { fail++; console.log(`FAIL ${name}${detail ? " — " + detail : ""}`); }
16
+ };
17
+
18
+ const dir = mkdtempSync(join(tmpdir(), "bridge-verify-"));
19
+ const boardDir = join(dir, "board");
20
+ const storeDir = mkdtempSync(join(tmpdir(), "bridge-vstore-"));
21
+ const store = new Store(join(storeDir, "state.json"));
22
+ await boardCh.init(fileURLToPath(new URL("../board", import.meta.url)));
23
+ const cfg = { dir: boardDir, identity: "bridge" };
24
+
25
+ // ---------- P1: parseBridgeBlock ----------
26
+ {
27
+ const d1 = '正文\n```bridge\n{ "priority": "P1", "retry": {"max": 1}, "acceptance": { "checks": [] } }\n```\n尾部';
28
+ const b1 = V.parseBridgeBlock(d1);
29
+ ok("P1a valid block parsed", b1?.priority === "P1" && b1?.retry?.max === 1);
30
+ ok("P1b no block → null", V.parseBridgeBlock("没有围栏") === null && V.parseBridgeBlock(null) === null);
31
+ ok("P1c malformed JSON → null", V.parseBridgeBlock("```bridge\n{oops}\n```") === null);
32
+ ok("P1d array payload → null", V.parseBridgeBlock("```bridge\n[1,2]\n```") === null);
33
+ }
34
+
35
+ // ---------- P2: evaluateAcceptance ----------
36
+ {
37
+ const root = join(dir, "work");
38
+ mkdirSync(root, { recursive: true });
39
+ writeFileSync(join(root, "out.md"), "## 第1首\n内容\n## 第2首\n内容\n");
40
+ writeFileSync(join(root, "ledger.json"), JSON.stringify({ items: [{ a: 1 }, { a: 2 }, { a: 3 }], total: 7 }));
41
+ writeFileSync(join(root, "empty.txt"), "");
42
+
43
+ ok("P2a null acceptance → null", V.evaluateAcceptance({ acceptance: null }) === null);
44
+ ok("P2b empty checks → null", V.evaluateAcceptance({ acceptance: { checks: [] } }) === null);
45
+ ok("P2c mode human → null (V3 待建)", V.evaluateAcceptance({ acceptance: { mode: "human", checks: [{ type: "fileExists", path: "out.md" }] } }) === null);
46
+
47
+ const allPass = V.evaluateAcceptance({
48
+ acceptance: { baseDir: root, checks: [
49
+ { type: "fileExists", path: "out.md" },
50
+ { type: "countAtLeast", path: "ledger.json", jsonPath: "$.items", min: 3 },
51
+ { type: "countAtLeast", path: "ledger.json", jsonPath: "$.total", min: 7 },
52
+ { type: "countOccurrences", path: "out.md", text: "## 第", minCount: 2 },
53
+ ] },
54
+ });
55
+ ok("P2d all-pass aggregate", allPass?.pass === true && allPass.checks.length === 4, JSON.stringify(allPass?.checks?.map(c => c.pass)));
56
+
57
+ const short = V.evaluateAcceptance({
58
+ acceptance: { baseDir: root, checks: [
59
+ { type: "countAtLeast", path: "ledger.json", jsonPath: "$.items", min: 20 },
60
+ { type: "fileExists", path: "missing.md" },
61
+ { type: "countOccurrences", path: "out.md", text: "## 第", minCount: 9 },
62
+ ] },
63
+ });
64
+ ok("P2e work-level fails detected", short?.pass === false && short.checks.filter((c) => !c.pass).length === 3 && short.checks.every((c) => c.invalid !== true),
65
+ JSON.stringify(short.checks.filter(c => !c.pass).map(c => c.evidence)));
66
+
67
+ const invalid = V.evaluateAcceptance({
68
+ acceptance: { baseDir: root, checks: [
69
+ { type: "fileExsits", path: "out.md" },
70
+ { type: "countOccurrences", path: "out.md" },
71
+ { type: "countAtLeast", path: "ledger.json", jsonPath: "$.nope.deep", min: 1 },
72
+ ] },
73
+ });
74
+ ok("P2f spec errors flagged invalid, path-miss is work-level",
75
+ invalid?.pass === false && invalid.checks[0].invalid === true && invalid.checks[1].invalid === true && invalid.checks[2].invalid !== true,
76
+ JSON.stringify(invalid.checks.map(c => ({ p: c.pass, inv: !!c.invalid }))));
77
+
78
+ ok("P2g empty file fails fileExists (minBytes default 1)",
79
+ V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [{ type: "fileExists", path: "empty.txt" }] } }).pass === false);
80
+ ok("P2h absolute path works", V.evaluateAcceptance({ acceptance: { checks: [{ type: "fileExists", path: join(root, "out.md").replaceAll("\\", "/") }] } }).pass === true);
81
+ }
82
+
83
+ // ---------- P3: full fail-path integration on a TEST board ----------
84
+ {
85
+ await boardCh.withBoard(cfg, (b) => {
86
+ b.defineTask("zcode", "e2e-verify-1", { title: "verify e2e", description: "测试任务" });
87
+ });
88
+
89
+ const v = { pass: false, checks: [
90
+ { type: "countAtLeast", target: "out.md $.items", pass: false, evidence: "got 12 < 20" },
91
+ { type: "fileExists", target: "missing.md", pass: false, evidence: "不存在" },
92
+ ] };
93
+
94
+ // 第一次:未用尽 → retry-scheduled + 回 open + note/message
95
+ let res;
96
+ await boardCh.withBoard(cfg, (b) => {
97
+ res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
98
+ });
99
+ ok("P3a first verify-fail schedules retry", res.outcome === "retry-scheduled" && res.attempts === 1, JSON.stringify(res));
100
+ ok("P3b retries ledger written", store.s.retries["e2e-verify-1"]?.n === 1 && store.s.retries["e2e-verify-1"]?.why === "verify-fail");
101
+ await boardCh.withBoard(cfg, (b) => {
102
+ const t = b.getTask("e2e-verify-1");
103
+ ok("P3c task back to open", t?.status === "open", t?.status);
104
+ const evs = b.timeline(200);
105
+ const note = evs.filter((e) => e.kind === "note" && String(e.summary).includes("[[verify]]")).pop();
106
+ ok("P3d structured verify FAIL note on chain", !!note && String(note.summary).includes("verdict=FAIL") && String(note.summary).includes("checks=0/2"), String(note?.summary).slice(0, 80));
107
+ const msgs = b.inbox("zcode", true);
108
+ ok("P3e creator notified", msgs.some((m) => (m.body ?? "").includes("未通过验收") || JSON.stringify(m).includes("未通过验收")));
109
+ });
110
+
111
+ // 第二、三次:attempts 递增到用尽 → blocked + verification 熔断
112
+ await boardCh.withBoard(cfg, (b) => {
113
+ res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
114
+ });
115
+ ok("P3f-pre second retry scheduled (max=2 → 还允许最后一试)", res.outcome === "retry-scheduled" && res.attempts === 2, JSON.stringify(res));
116
+ await boardCh.withBoard(cfg, (b) => {
117
+ res = V.applyVerifyFail({ b, io: boardCh, store, ID: "bridge", owner: "kemu", key: "e2e-verify-1", agent: "trae", task: { createdBy: "zcode" }, v, maxAttempts: 2, baseMs: 60000, maxDelayMs: 240000, holdBase: 300000, holdMax: 7200000, now: Date.now() });
118
+ });
119
+ ok("P3f exhaustion → blocked + face latched", res.outcome === "exhausted" && res.streak === 1, JSON.stringify(res));
120
+ ok("P3g verification latch recorded", store.supplyGet("trae")?.category === "verification");
121
+ ok("P3h retries ledger cleared", store.s.retries["e2e-verify-1"] === undefined);
122
+ await boardCh.withBoard(cfg, (b) => {
123
+ ok("P3i task blocked", b.getTask("e2e-verify-1")?.status === "blocked");
124
+ ok("P3j chain intact", b.verifyChain().brokenAtSeq === null);
125
+ });
126
+
127
+ // PASS 路径
128
+ const vp = { pass: true, checks: [{ type: "fileExists", target: "out.md", pass: true, evidence: "12B" }] };
129
+ await boardCh.withBoard(cfg, (b) => V.applyVerifyPass({ b, io: boardCh, ID: "bridge", key: "e2e-verify-1", v: vp }));
130
+ await boardCh.withBoard(cfg, (b) => {
131
+ const evs = b.timeline(300);
132
+ const note = evs.filter((e) => e.kind === "note" && String(e.summary).includes("[[verify]]")).pop();
133
+ ok("P3k structured PASS note", !!note && String(note.summary).includes("verdict=PASS") && String(note.summary).includes("checks=1/1"));
134
+ ok("P3l chain still intact", b.verifyChain().brokenAtSeq === null);
135
+ });
136
+ }
137
+
138
+ // ---------- P4: formatVerifyNote ----------
139
+ {
140
+ const n = V.formatVerifyNote({ key: "k1", verdict: "FAIL", checks: [
141
+ { type: "fileExists", target: "a.md", pass: false, evidence: "不存在" },
142
+ { type: "fileExists", target: "b.md", pass: true, evidence: "1B" },
143
+ ], by: "bridge" });
144
+ ok("P4a note format stable", n.startsWith("[[verify]] key=k1 verdict=FAIL level=V1 by=bridge checks=1/2") && n.includes("· FAIL fileExists a.md"), n.slice(0, 100));
145
+ }
146
+
147
+ rmSync(dir, { recursive: true, force: true });
148
+ rmSync(storeDir, { recursive: true, force: true });
149
+ console.log(`\n${pass} PASS, ${fail} FAIL`);
150
+ process.exit(fail ? 1 : 0);
@@ -0,0 +1,128 @@
1
+ // e2e: 防刷分检查(2026-10-07)—— countMatches / referencesExist 两类组合一致性检查。
2
+ // SpecBench 教训:声明式检查可被针对性刷穿;组合检查迫使刷单必须整条链一起伪造。
3
+ // 纯检查测试 + 一次 board 集成,不碰现网。
4
+ import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+
9
+ const V = await import(new URL("../lib/verify.js", import.meta.url).href);
10
+
11
+ let pass = 0, fail = 0;
12
+ const ok = (name, cond, detail = "") => {
13
+ if (cond) { pass++; console.log(`PASS ${name}${detail ? " — " + detail : ""}`); }
14
+ else { fail++; console.log(`FAIL ${name}${detail ? " — " + detail : ""}`); }
15
+ };
16
+
17
+ const dir = mkdtempSync(join(tmpdir(), "bridge-antifraud-"));
18
+ const root = join(dir, "work");
19
+ mkdirSync(join(root, "out"), { recursive: true });
20
+ mkdirSync(join(root, "assets"), { recursive: true });
21
+
22
+ // 工件:产物 + 台账 + 引用资源
23
+ writeFileSync(join(root, "out", "ledger.json"), JSON.stringify({ items: [{ id: 1 }, { id: 2 }, { id: 3 }], rendered: 3 }));
24
+ writeFileSync(join(root, "out", "manifest.json"), JSON.stringify({ count: 3 }));
25
+ writeFileSync(join(root, "out", "refs.json"), JSON.stringify({ files: ["assets/a.png", "assets/b.png"] }));
26
+ writeFileSync(join(root, "out", "badrefs.json"), JSON.stringify({ files: ["assets/a.png", "assets/ghost.png"] }));
27
+ writeFileSync(join(root, "out", "norefs.json"), JSON.stringify({ files: [] }));
28
+ writeFileSync(join(root, "assets", "a.png"), "fake-image-a");
29
+ writeFileSync(join(root, "assets", "b.png"), "fake-image-b");
30
+
31
+ try {
32
+ // ---- countMatches ----
33
+ {
34
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
35
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count", min: 3 },
36
+ ] } });
37
+ ok("M1a 数量一致且达标 → PASS", r?.pass === true, JSON.stringify(r?.checks?.[0]));
38
+ }
39
+ {
40
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
41
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count" },
42
+ ] } });
43
+ ok("M1b 一致但缺 min(默认1)此处 3≥1 → PASS", r?.pass === true);
44
+ }
45
+ {
46
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
47
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/ledger.json", withJsonPath: "$.rendered", min: 3 },
48
+ ] } });
49
+ // items=3 vs rendered=3 → 相等 → pass(同文件自比也合法)
50
+ ok("M1c 同文件两路径相等 → PASS", r?.pass === true);
51
+ }
52
+ {
53
+ // 刷分模拟:产物说 3,台账只给了 2 —— 不一致必须 FAIL
54
+ writeFileSync(join(root, "out", "liar.json"), JSON.stringify({ count: 2 }));
55
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
56
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/liar.json", withJsonPath: "$.count", min: 3 },
57
+ ] } });
58
+ ok("M2a 数量不一致 → FAIL(work 类)", r?.pass === false && r.checks[0].invalid !== true, r?.checks?.[0]?.evidence);
59
+ }
60
+ {
61
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
62
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.nonexistent", withPath: "out/manifest.json", withJsonPath: "$.count" },
63
+ ] } });
64
+ ok("M2b 路径未命中 → FAIL(work 类,取值不可计数)", r?.pass === false && r.checks[0].invalid !== true);
65
+ }
66
+ {
67
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
68
+ { type: "countMatches", path: "out/ledger.json", withPath: "out/manifest.json" },
69
+ ] } });
70
+ ok("M3a 缺 jsonPath → spec 类 invalid", r?.pass === false && r.checks[0].invalid === true);
71
+ }
72
+ {
73
+ // 相等但为 0:没有 min 时默认 1,防"两边都是空的也算过"
74
+ writeFileSync(join(root, "out", "zero.json"), JSON.stringify({ a: 0 }));
75
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
76
+ { type: "countMatches", path: "out/zero.json", jsonPath: "$.a", withPath: "out/zero.json", withJsonPath: "$.a" },
77
+ ] } });
78
+ ok("M3b 相等但为 0 → FAIL(默认 min 1)", r?.pass === false, r?.checks?.[0]?.evidence);
79
+ }
80
+
81
+ // ---- referencesExist ----
82
+ {
83
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
84
+ { type: "referencesExist", path: "out/refs.json", jsonPath: "$.files" },
85
+ ] } });
86
+ ok("R1a 引用全部存在 → PASS", r?.pass === true, JSON.stringify(r?.checks?.[0]?.evidence));
87
+ }
88
+ {
89
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
90
+ { type: "referencesExist", path: "out/badrefs.json", jsonPath: "$.files" },
91
+ ] } });
92
+ ok("R2a 幽灵引用 → FAIL(work 类,证据点名缺失项)", r?.pass === false && String(r.checks[0].evidence).includes("ghost.png"), r?.checks?.[0]?.evidence);
93
+ }
94
+ {
95
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
96
+ { type: "referencesExist", path: "out/norefs.json", jsonPath: "$.files" },
97
+ ] } });
98
+ ok("R2b 引用列表为空 → FAIL(fail-closed)", r?.pass === false && r.checks[0].invalid !== true);
99
+ }
100
+ {
101
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
102
+ { type: "referencesExist", path: "out/refs.json", jsonPath: "$.files", baseDir: root },
103
+ ] } });
104
+ ok("R3a 显式 baseDir 相对解析 → PASS", r?.pass === true);
105
+ }
106
+ {
107
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
108
+ { type: "referencesExist", path: "out/refs.json" },
109
+ ] } });
110
+ ok("R3b 缺 jsonPath → spec 类 invalid", r?.pass === false && r.checks[0].invalid === true);
111
+ }
112
+
113
+ // ---- 混合:防刷分检查与三类既有检查同场 ----
114
+ {
115
+ const r = V.evaluateAcceptance({ acceptance: { baseDir: root, checks: [
116
+ { type: "fileExists", path: "out/ledger.json" },
117
+ { type: "countAtLeast", path: "out/ledger.json", jsonPath: "$.items", min: 3 },
118
+ { type: "countMatches", path: "out/ledger.json", jsonPath: "$.items", withPath: "out/manifest.json", withJsonPath: "$.count" },
119
+ { type: "referencesExist", path: "out/refs.json", jsonPath: "$.files" },
120
+ ] } });
121
+ ok("X1 四类检查同场全过 → aggregate PASS", r?.pass === true && r.checks.length === 4);
122
+ }
123
+
124
+ console.log(`\n${pass} passed, ${fail} failed`);
125
+ if (fail > 0) process.exit(1);
126
+ } finally {
127
+ try { rmSync(dir, { recursive: true, force: true }); } catch { }
128
+ }