proofdeck 0.0.0-stage → 0.1.0

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 (134) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +23 -0
  3. package/README.md +97 -2
  4. package/README.zh-CN.md +89 -0
  5. package/bin/proofdeck.js +126 -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 +71 -0
  89. package/daemon.js +1112 -0
  90. package/docs/assets/demo.gif +0 -0
  91. package/docs/demo-run.mjs +61 -0
  92. package/docs/render-demo.py +94 -0
  93. package/e2e/verify-acceptance.mjs +150 -0
  94. package/e2e/verify-antifraud.mjs +128 -0
  95. package/e2e/verify-caps.mjs +46 -0
  96. package/e2e/verify-checkpoint.mjs +208 -0
  97. package/e2e/verify-firstclass.mjs +110 -0
  98. package/e2e/verify-judge.mjs +52 -0
  99. package/e2e/verify-lease.mjs +95 -0
  100. package/e2e/verify-replay.mjs +92 -0
  101. package/e2e/verify-resilience.mjs +323 -0
  102. package/e2e/verify-review.mjs +86 -0
  103. package/e2e/verify-scheduling.mjs +110 -0
  104. package/e2e/verify-schema-evolution.mjs +107 -0
  105. package/e2e/verify-sla-digest.mjs +105 -0
  106. package/guard.js +97 -0
  107. package/lib/adapters/codex.js +206 -0
  108. package/lib/billing-convert.js +57 -0
  109. package/lib/board.js +46 -0
  110. package/lib/caps.js +35 -0
  111. package/lib/checkpoint.js +130 -0
  112. package/lib/gating.js +218 -0
  113. package/lib/guard-core.mjs +108 -0
  114. package/lib/http.js +161 -0
  115. package/lib/judge.js +89 -0
  116. package/lib/lease.js +93 -0
  117. package/lib/notify.js +56 -0
  118. package/lib/platform.js +120 -0
  119. package/lib/replay.js +68 -0
  120. package/lib/review.js +40 -0
  121. package/lib/runner.js +152 -0
  122. package/lib/schedule.js +59 -0
  123. package/lib/sla.js +42 -0
  124. package/lib/spans.js +36 -0
  125. package/lib/starve.js +43 -0
  126. package/lib/store.js +109 -0
  127. package/lib/supply.js +101 -0
  128. package/lib/usage.js +103 -0
  129. package/lib/verify.js +223 -0
  130. package/lib/watchdog-core.mjs +68 -0
  131. package/lib/watchdog-worker.mjs +75 -0
  132. package/package.json +55 -4
  133. package/scripts/run-daemon.sh +18 -0
  134. package/scripts/run-e2e.mjs +39 -0
@@ -0,0 +1,506 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { createRequire } from "node:module";
4
+ // Dual SQLite backend (2026-10-24): prefer Node's built-in node:sqlite (zero native
5
+ // deps, ABI-independent — survives Node upgrades like the 10-24 v26 swap that broke
6
+ // better-sqlite3's ABI-137 build), fall back to better-sqlite3 for runtimes older
7
+ // than ~22.13 where node:sqlite is absent/flagged. Force legacy with
8
+ // OCTOBOARD_BACKEND=better-sqlite3 (rollback lever). better-sqlite3 is loaded
9
+ // LAZILY (only when the legacy branch actually runs) so a fresh install on a
10
+ // modern Node needs no native module at all. The probes use createRequire
11
+ // (NOT top-level await) so this file stays a synchronous ESM graph and CJS
12
+ // consumers can still require() the dist build.
13
+ let NodeSqliteDb = null;
14
+ try {
15
+ NodeSqliteDb = createRequire(import.meta.url)("node:sqlite").DatabaseSync ?? null;
16
+ }
17
+ catch { /* runtime without node:sqlite — legacy path below */ }
18
+ function loadLegacyDatabase() {
19
+ try {
20
+ return createRequire(import.meta.url)("better-sqlite3");
21
+ }
22
+ catch {
23
+ throw new Error("node:sqlite unavailable (need Node >=22.13) and better-sqlite3 not installed — run: npm install better-sqlite3");
24
+ }
25
+ }
26
+ // node:sqlite 缺 better-sqlite3 的三个面,直接补在 DatabaseSync 实例上(返回原对象):
27
+ // pragma(name) —— 带返回行的 PRAGMA 查询(migrate 的 table_info 靠它读列);
28
+ // transaction() —— 含 better-sqlite3 的嵌套语义:外层 BEGIN/COMMIT、内层 SAVEPOINT/RELEASE
29
+ // (assign() 里套 message() 就是嵌套事务,平铺 BEGIN 会断写路径);
30
+ // inTransaction —— 事务内标志。所有 SQL 语句均为静态字面量。
31
+ function adaptNodeSqlite(raw) {
32
+ let txDepth = 0;
33
+ raw.pragma = (name) => raw.prepare("PRAGMA " + name).all();
34
+ Object.defineProperty(raw, "inTransaction", { get: () => txDepth > 0 });
35
+ const withTx = (fn, args, begin) => {
36
+ const outer = txDepth === 0;
37
+ if (outer)
38
+ begin();
39
+ else
40
+ raw.exec("SAVEPOINT sp");
41
+ txDepth++;
42
+ try {
43
+ const out = fn(...args);
44
+ txDepth--;
45
+ if (outer)
46
+ raw.exec("COMMIT");
47
+ else
48
+ raw.exec("RELEASE SAVEPOINT sp");
49
+ return out;
50
+ }
51
+ catch (e) {
52
+ txDepth--;
53
+ try {
54
+ if (outer)
55
+ raw.exec("ROLLBACK");
56
+ else
57
+ raw.exec("ROLLBACK TO SAVEPOINT sp; RELEASE SAVEPOINT sp");
58
+ }
59
+ catch { /* connection-level failure: surface the original error */ }
60
+ throw e;
61
+ }
62
+ };
63
+ raw.transaction = (fn) => {
64
+ // better-sqlite3 形态:transaction 返回「可调用对象」(默认 BEGIN),
65
+ // .deferred/.immediate/.exclusive 挂在函数上——board 的 _wrapTransactions 按此形态包门铃。
66
+ const main = (...args) => withTx(fn, args, () => raw.exec("BEGIN"));
67
+ main.deferred = (...args) => withTx(fn, args, () => raw.exec("BEGIN DEFERRED"));
68
+ main.immediate = (...args) => withTx(fn, args, () => raw.exec("BEGIN IMMEDIATE"));
69
+ main.exclusive = (...args) => withTx(fn, args, () => raw.exec("BEGIN EXCLUSIVE"));
70
+ return main;
71
+ };
72
+ return raw;
73
+ }
74
+ // SQLite does NOT apply busy_timeout to the journal_mode switch: that pragma needs
75
+ // an exclusive lock and throws `database is locked` immediately if another agent
76
+ // holds a write txn or a hot -wal needs recovery. Retry in-process for the budget a
77
+ // busy handler would have given, then rethrow so a genuinely stuck board stays loud.
78
+ const WAL_SWITCH_RETRY_MS = 5000;
79
+ const WAL_SWITCH_RETRY_STEP_MS = 200;
80
+ const WAL_SWITCH_SLEEP = new Int32Array(new SharedArrayBuffer(4));
81
+ /**
82
+ * Open (creating if needed) the SQLite database that backs a blackboard and
83
+ * apply the schema. The schema is idempotent (`IF NOT EXISTS`), so opening an
84
+ * existing board is safe. WAL mode lets multiple agents read while one writes —
85
+ * the common case when several CLIs share one board.
86
+ */
87
+ export function openDb(dbPath) {
88
+ mkdirSync(dirname(dbPath), { recursive: true });
89
+ let db = null;
90
+ if (process.env.OCTOBOARD_BACKEND !== "better-sqlite3" && NodeSqliteDb) {
91
+ try { db = adaptNodeSqlite(new NodeSqliteDb(dbPath)); } catch { db = null; }
92
+ }
93
+ if (!db)
94
+ db = new (loadLegacyDatabase())(dbPath); // legacy better-sqlite3 (needs matching ABI build)
95
+ {
96
+ const deadline = Date.now() + WAL_SWITCH_RETRY_MS;
97
+ for (;;) {
98
+ try {
99
+ db.pragma("journal_mode = WAL");
100
+ break;
101
+ } catch (err) {
102
+ if (Date.now() >= deadline) throw err;
103
+ Atomics.wait(WAL_SWITCH_SLEEP, 0, 0, WAL_SWITCH_RETRY_STEP_MS);
104
+ }
105
+ }
106
+ }
107
+ // Durability to match the tamper-evident audit-log promise: FULL fsyncs each
108
+ // commit so the most recent timeline entries + head anchor survive OS crash /
109
+ // power loss, not just an app crash (WAL's default NORMAL would risk them).
110
+ db.pragma("synchronous = FULL");
111
+ db.pragma("foreign_keys = ON");
112
+ db.pragma("busy_timeout = 5000"); // applies to the writes below, not to the WAL switch above
113
+ applySchema(db);
114
+ migrate(db);
115
+ db.exec(INDEXES); // after migrate: indexes may reference newly-added columns
116
+ return db;
117
+ }
118
+ function applySchema(db) {
119
+ db.exec(SCHEMA);
120
+ }
121
+ /**
122
+ * Additive, in-place migration for boards created by an earlier version. Only
123
+ * ever ADDS nullable columns and new tables — never drops or rewrites — so
124
+ * upgrading an existing `.octoboard/board.db` is safe and lossless.
125
+ */
126
+ function migrate(db) {
127
+ const columns = (table) => new Set(db.pragma(`table_info(${table})`).map((c) => c.name));
128
+ const ensure = (table, column, decl) => {
129
+ if (!columns(table).has(column)) {
130
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${decl}`);
131
+ }
132
+ };
133
+ // agents: provider-independent identity fields
134
+ ensure("agents", "provider", "TEXT");
135
+ ensure("agents", "model", "TEXT");
136
+ ensure("agents", "cli", "TEXT");
137
+ ensure("agents", "version", "TEXT");
138
+ // sessions: reshaped for first-class attribution (old boards had a stub,
139
+ // never-written table using agent_id/ended_at; add the new columns beside it)
140
+ ensure("sessions", "agent_name", "TEXT");
141
+ ensure("sessions", "finished_at", "TEXT");
142
+ ensure("sessions", "machine", "TEXT");
143
+ ensure("sessions", "working_directory", "TEXT");
144
+ ensure("sessions", "git_branch", "TEXT");
145
+ ensure("sessions", "repository", "TEXT");
146
+ ensure("sessions", "public_key", "TEXT");
147
+ ensure("sessions", "last_heartbeat", "TEXT");
148
+ // session linkage on writes
149
+ ensure("timeline", "session_id", "TEXT");
150
+ ensure("files_changed", "session_id", "TEXT");
151
+ // decisions: evidence & relations
152
+ ensure("decisions", "session_id", "TEXT");
153
+ ensure("decisions", "evidence", "TEXT");
154
+ ensure("decisions", "related_commits", "TEXT");
155
+ ensure("decisions", "related_tasks", "TEXT");
156
+ // handoffs: richer context
157
+ ensure("handoffs", "from_session", "TEXT");
158
+ ensure("handoffs", "to_session", "TEXT");
159
+ ensure("handoffs", "context", "TEXT");
160
+ ensure("handoffs", "related_files", "TEXT");
161
+ ensure("handoffs", "open_questions", "TEXT");
162
+ // tasks: kanban fields
163
+ ensure("tasks", "number", "INTEGER");
164
+ ensure("tasks", "description", "TEXT");
165
+ ensure("tasks", "project", "TEXT");
166
+ ensure("tasks", "impact", "TEXT");
167
+ ensure("tasks", "risk_level", "TEXT");
168
+ ensure("tasks", "progress", "INTEGER NOT NULL DEFAULT 0");
169
+ // tasks: first-class acceptance spec (JSON) for the verification layer;
170
+ // nullable, so tasks defined before this migration simply read back as null
171
+ ensure("tasks", "acceptance", "TEXT");
172
+ // --- four-layer partition: board -> project -> task -> trace ---------------
173
+ // Purely additive: the `projects` table itself is created by SCHEMA above
174
+ // (CREATE TABLE IF NOT EXISTS), so pre-existing boards only need the new
175
+ // nullable columns. Nothing is renamed or dropped; old readers that never
176
+ // mention these columns keep working unchanged.
177
+ ensure("tasks", "stream", "TEXT");
178
+ // projects.streams: the controlled stream vocabulary (JSON string array) that
179
+ // `defineTask` enforces. Additive + nullable; boards predating this migration
180
+ // simply read back NULL, which means "no vocabulary declared -> no rejection".
181
+ ensure("projects", "streams", "TEXT");
182
+ ensure("sessions", "project", "TEXT");
183
+ ensure("sessions", "task_key", "TEXT");
184
+ ensure("messages", "project", "TEXT");
185
+ ensure("decisions", "project", "TEXT");
186
+ ensure("risks", "project", "TEXT");
187
+ ensure("handoffs", "project", "TEXT");
188
+ ensure("evidence", "project", "TEXT");
189
+ ensure("files_changed", "project", "TEXT");
190
+ ensure("risks", "task_key", "TEXT");
191
+ // timeline: the 7th trace table. Added in step 2 because §3.2 requires
192
+ // `note --project/--task`, and `note` writes ONLY to timeline — without these
193
+ // two columns a project-scoped note has nowhere to record its owner.
194
+ // Nullable, purely additive: old readers never mention them.
195
+ ensure("timeline", "project", "TEXT");
196
+ ensure("timeline", "task_key", "TEXT");
197
+ // risks: the close path (who resolved it, and when). Nullable, so risks
198
+ // registered before this migration simply read back as "unresolved".
199
+ ensure("risks", "resolved_at", "TEXT");
200
+ ensure("risks", "resolved_by", "TEXT");
201
+ ensure("evidence", "sha256", "TEXT");
202
+ // evidence ledger (2026-10-10): `evidence` doubles as the project
203
+ // "sedimentation register" -- each entry may be scoped to a task and tagged
204
+ // with a kind (memory/skill/hook/lesson/playbook). Purely additive; rows
205
+ // written before this migration simply read back null for both columns.
206
+ ensure("evidence", "task_key", "TEXT");
207
+ ensure("evidence", "kind", "TEXT");
208
+ // Backfill stable, unique numbers for tasks created before numbering existed,
209
+ // in creation order (rowid is unique, so no two tasks collide).
210
+ db.exec(`UPDATE tasks SET number = (SELECT COUNT(*) FROM tasks t2 WHERE t2.rowid <= tasks.rowid)
211
+ WHERE number IS NULL`);
212
+ // Drop indexes that turned out redundant/low-value (present on boards created
213
+ // by earlier versions): the implicit index on the UNIQUE seq column, and the
214
+ // low-selectivity actor_type index.
215
+ db.exec("DROP INDEX IF EXISTS idx_timeline_seq");
216
+ db.exec("DROP INDEX IF EXISTS idx_attr_type");
217
+ }
218
+ /**
219
+ * The board schema. Mirrors the domain model in `types.ts`. `timeline` is the
220
+ * append-only hash chain every other write also records into.
221
+ */
222
+ const SCHEMA = `
223
+ CREATE TABLE IF NOT EXISTS meta (
224
+ key TEXT PRIMARY KEY,
225
+ value TEXT NOT NULL
226
+ );
227
+
228
+ CREATE TABLE IF NOT EXISTS agents (
229
+ id TEXT PRIMARY KEY,
230
+ name TEXT NOT NULL UNIQUE,
231
+ kind TEXT,
232
+ provider TEXT,
233
+ model TEXT,
234
+ cli TEXT,
235
+ version TEXT,
236
+ created_at TEXT NOT NULL,
237
+ last_seen TEXT NOT NULL
238
+ );
239
+
240
+ CREATE TABLE IF NOT EXISTS sessions (
241
+ id TEXT PRIMARY KEY,
242
+ agent_name TEXT NOT NULL,
243
+ label TEXT,
244
+ machine TEXT,
245
+ working_directory TEXT,
246
+ git_branch TEXT,
247
+ repository TEXT,
248
+ public_key TEXT,
249
+ last_heartbeat TEXT,
250
+ started_at TEXT NOT NULL,
251
+ finished_at TEXT,
252
+ project TEXT,
253
+ task_key TEXT
254
+ );
255
+
256
+ CREATE TABLE IF NOT EXISTS redactions (
257
+ seq INTEGER PRIMARY KEY,
258
+ reason TEXT,
259
+ actor TEXT,
260
+ created_at TEXT NOT NULL
261
+ );
262
+
263
+ -- Each agent's active session, kept in the DB (not a JSON file) so start/stop
264
+ -- are transactional and cannot race between concurrent CLI processes.
265
+ CREATE TABLE IF NOT EXISTS current_sessions (
266
+ agent TEXT PRIMARY KEY,
267
+ session_id TEXT NOT NULL
268
+ );
269
+
270
+ CREATE TABLE IF NOT EXISTS signatures (
271
+ id TEXT PRIMARY KEY,
272
+ session_id TEXT NOT NULL,
273
+ head_seq INTEGER NOT NULL,
274
+ head_hash TEXT NOT NULL,
275
+ signature TEXT NOT NULL,
276
+ public_key TEXT NOT NULL,
277
+ created_at TEXT NOT NULL
278
+ );
279
+
280
+ -- Projects: a first-class partition above tasks (board -> project -> task -> trace).
281
+ -- "key" is the stable English slug and the ONLY anchor tasks/traces reference;
282
+ -- "name" is the human-readable (Chinese) display name. "created_by" records the
283
+ -- project's author, which the four-layer design requires to be traceable.
284
+ -- "streams" is the project's controlled stream vocabulary (JSON array of strings);
285
+ -- NULL/empty means "no vocabulary declared" and tasks may carry any stream.
286
+ -- Additive: new table, so boards created before this migration are untouched.
287
+ CREATE TABLE IF NOT EXISTS projects (
288
+ id TEXT PRIMARY KEY,
289
+ key TEXT NOT NULL UNIQUE,
290
+ name TEXT NOT NULL,
291
+ description TEXT,
292
+ status TEXT NOT NULL DEFAULT 'active',
293
+ streams TEXT,
294
+ created_by TEXT NOT NULL,
295
+ created_at TEXT NOT NULL,
296
+ updated_at TEXT NOT NULL
297
+ );
298
+
299
+ CREATE TABLE IF NOT EXISTS tasks (
300
+ id TEXT PRIMARY KEY,
301
+ key TEXT NOT NULL UNIQUE,
302
+ number INTEGER,
303
+ title TEXT,
304
+ description TEXT,
305
+ status TEXT NOT NULL DEFAULT 'open',
306
+ project TEXT,
307
+ stream TEXT,
308
+ impact TEXT,
309
+ risk_level TEXT,
310
+ progress INTEGER NOT NULL DEFAULT 0,
311
+ created_by TEXT,
312
+ claimed_by TEXT,
313
+ claimed_at TEXT,
314
+ released_at TEXT,
315
+ created_at TEXT NOT NULL,
316
+ updated_at TEXT NOT NULL
317
+ );
318
+
319
+ -- Agents assigned to a task (many-to-many). Assigning is how "notify Claude to
320
+ -- look at task #145" is recorded — it also drops a message in the assignee's
321
+ -- inbox. The board records the assignment; it never launches the agent.
322
+ CREATE TABLE IF NOT EXISTS task_assignees (
323
+ task_key TEXT NOT NULL,
324
+ agent TEXT NOT NULL,
325
+ assigned_by TEXT,
326
+ assigned_at TEXT NOT NULL,
327
+ PRIMARY KEY (task_key, agent)
328
+ );
329
+
330
+ CREATE TABLE IF NOT EXISTS messages (
331
+ id TEXT PRIMARY KEY,
332
+ from_agent TEXT NOT NULL,
333
+ to_agent TEXT,
334
+ body TEXT NOT NULL,
335
+ created_at TEXT NOT NULL,
336
+ read_at TEXT,
337
+ project TEXT
338
+ );
339
+
340
+ -- Per-agent ack ledger. messages.read_at is one column on the message row, so it
341
+ -- can only record "someone has seen this" — and for a broadcast (to_agent IS
342
+ -- NULL) a single agent's read would hide the message from every other agent.
343
+ -- Reads are therefore keyed by (message, agent). messages.read_at is still
344
+ -- stamped on first read as the legacy global "seen by anyone" flag.
345
+ CREATE TABLE IF NOT EXISTS message_reads (
346
+ message_id TEXT NOT NULL,
347
+ agent TEXT NOT NULL,
348
+ read_at TEXT NOT NULL,
349
+ PRIMARY KEY (message_id, agent)
350
+ );
351
+
352
+ CREATE TABLE IF NOT EXISTS decisions (
353
+ id TEXT PRIMARY KEY,
354
+ agent_id TEXT NOT NULL,
355
+ session_id TEXT,
356
+ title TEXT NOT NULL,
357
+ rationale TEXT,
358
+ evidence TEXT,
359
+ related_commits TEXT,
360
+ related_tasks TEXT,
361
+ created_at TEXT NOT NULL,
362
+ project TEXT
363
+ );
364
+
365
+ CREATE TABLE IF NOT EXISTS evidence (
366
+ id TEXT PRIMARY KEY,
367
+ agent_id TEXT NOT NULL,
368
+ ref TEXT NOT NULL,
369
+ note TEXT,
370
+ target TEXT,
371
+ sha256 TEXT,
372
+ created_at TEXT NOT NULL,
373
+ project TEXT,
374
+ task_key TEXT,
375
+ kind TEXT
376
+ );
377
+
378
+ CREATE TABLE IF NOT EXISTS files_changed (
379
+ id TEXT PRIMARY KEY,
380
+ agent_id TEXT NOT NULL,
381
+ session_id TEXT,
382
+ path TEXT NOT NULL,
383
+ change TEXT NOT NULL,
384
+ task_key TEXT,
385
+ created_at TEXT NOT NULL,
386
+ project TEXT
387
+ );
388
+
389
+ CREATE TABLE IF NOT EXISTS risks (
390
+ id TEXT PRIMARY KEY,
391
+ agent_id TEXT NOT NULL,
392
+ title TEXT NOT NULL,
393
+ severity TEXT NOT NULL DEFAULT 'medium',
394
+ status TEXT NOT NULL DEFAULT 'open',
395
+ task_key TEXT,
396
+ created_at TEXT NOT NULL,
397
+ project TEXT
398
+ );
399
+
400
+ CREATE TABLE IF NOT EXISTS handoffs (
401
+ id TEXT PRIMARY KEY,
402
+ from_agent TEXT NOT NULL,
403
+ to_agent TEXT NOT NULL,
404
+ from_session TEXT,
405
+ to_session TEXT,
406
+ summary TEXT NOT NULL,
407
+ context TEXT,
408
+ related_files TEXT,
409
+ open_questions TEXT,
410
+ task_key TEXT,
411
+ created_at TEXT NOT NULL,
412
+ accepted_at TEXT,
413
+ project TEXT
414
+ );
415
+
416
+ CREATE TABLE IF NOT EXISTS attributions (
417
+ id TEXT PRIMARY KEY,
418
+ commit_sha TEXT NOT NULL,
419
+ file TEXT,
420
+ hunk TEXT,
421
+ actor_type TEXT NOT NULL,
422
+ actor TEXT NOT NULL,
423
+ provider TEXT,
424
+ model TEXT,
425
+ cli TEXT,
426
+ session_id TEXT,
427
+ created_at TEXT NOT NULL
428
+ );
429
+
430
+ CREATE TABLE IF NOT EXISTS reviews (
431
+ id TEXT PRIMARY KEY,
432
+ commit_sha TEXT NOT NULL,
433
+ reviewer_type TEXT NOT NULL,
434
+ reviewer TEXT NOT NULL,
435
+ session_id TEXT,
436
+ outcome TEXT NOT NULL,
437
+ note TEXT,
438
+ created_at TEXT NOT NULL
439
+ );
440
+
441
+ CREATE TABLE IF NOT EXISTS timeline (
442
+ id TEXT PRIMARY KEY,
443
+ seq INTEGER NOT NULL UNIQUE,
444
+ at TEXT NOT NULL,
445
+ actor TEXT NOT NULL,
446
+ session_id TEXT,
447
+ kind TEXT NOT NULL,
448
+ ref_table TEXT,
449
+ ref_id TEXT,
450
+ summary TEXT NOT NULL,
451
+ payload TEXT,
452
+ prev_hash TEXT NOT NULL,
453
+ hash TEXT NOT NULL
454
+ );
455
+
456
+ -- Enforce append-only at the database layer, for EVERY connection (not just the
457
+ -- board's code): the timeline can be INSERTed into, never UPDATEd or DELETEd.
458
+ -- This turns "append-only by convention" into "append-only by default" — a
459
+ -- casual sqlite3 edit or a buggy write is refused. A determined attacker with
460
+ -- DB access can still DROP these triggers, but then the hash chain + head anchor
461
+ -- detect the tamper (belt and braces). No legitimate code path updates/deletes
462
+ -- timeline rows (redaction uses an overlay; prune never touches the timeline).
463
+ CREATE TRIGGER IF NOT EXISTS timeline_no_update BEFORE UPDATE ON timeline
464
+ BEGIN SELECT RAISE(ABORT, 'timeline is append-only: rows cannot be modified'); END;
465
+ CREATE TRIGGER IF NOT EXISTS timeline_no_delete BEFORE DELETE ON timeline
466
+ BEGIN SELECT RAISE(ABORT, 'timeline is append-only: rows cannot be deleted'); END;
467
+
468
+ `;
469
+ /**
470
+ * Indexes, applied after migration so they may safely reference columns added
471
+ * to pre-existing tables during an upgrade.
472
+ */
473
+ const INDEXES = `
474
+ -- NB: timeline.seq is INTEGER UNIQUE, which already creates an implicit index —
475
+ -- so no explicit idx_timeline_seq (it would be a redundant duplicate B-tree).
476
+ -- actor_type is too low-selectivity (2-3 values) for an index to help.
477
+ CREATE INDEX IF NOT EXISTS idx_messages_to ON messages(to_agent, read_at);
478
+ CREATE INDEX IF NOT EXISTS idx_files_task ON files_changed(task_key);
479
+ CREATE INDEX IF NOT EXISTS idx_files_session ON files_changed(session_id);
480
+ CREATE INDEX IF NOT EXISTS idx_files_path ON files_changed(path);
481
+ CREATE INDEX IF NOT EXISTS idx_timeline_session ON timeline(session_id);
482
+ CREATE INDEX IF NOT EXISTS idx_risks_status ON risks(status);
483
+ CREATE INDEX IF NOT EXISTS idx_attr_commit ON attributions(commit_sha);
484
+ CREATE INDEX IF NOT EXISTS idx_attr_file ON attributions(file);
485
+ CREATE INDEX IF NOT EXISTS idx_attr_actor ON attributions(actor);
486
+ CREATE INDEX IF NOT EXISTS idx_reviews_commit ON reviews(commit_sha);
487
+ CREATE INDEX IF NOT EXISTS idx_sessions_active ON sessions(finished_at, last_heartbeat);
488
+ CREATE INDEX IF NOT EXISTS idx_assignees_task ON task_assignees(task_key);
489
+ CREATE INDEX IF NOT EXISTS idx_risks_task ON risks(task_key);
490
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_tasks_number ON tasks(number);
491
+ -- four-layer partition: filter tasks by project/stream, and join traces by project.
492
+ -- projects.key is UNIQUE so it already has an implicit index (no duplicate B-tree).
493
+ CREATE INDEX IF NOT EXISTS idx_tasks_project ON tasks(project);
494
+ CREATE INDEX IF NOT EXISTS idx_tasks_stream ON tasks(stream);
495
+ CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project);
496
+ CREATE INDEX IF NOT EXISTS idx_decisions_project ON decisions(project);
497
+ CREATE INDEX IF NOT EXISTS idx_risks_project ON risks(project);
498
+ CREATE INDEX IF NOT EXISTS idx_handoffs_project ON handoffs(project);
499
+ CREATE INDEX IF NOT EXISTS idx_evidence_project ON evidence(project);
500
+ -- evidence ledger (2026-10-10): filter the register by task / kind.
501
+ CREATE INDEX IF NOT EXISTS idx_evidence_task ON evidence(task_key);
502
+ CREATE INDEX IF NOT EXISTS idx_evidence_kind ON evidence(kind);
503
+ CREATE INDEX IF NOT EXISTS idx_files_project ON files_changed(project);
504
+ CREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project);
505
+ `;
506
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc;IACnC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAChC,6EAA6E;IAC7E,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IAE7C,uBAAuB;IACvB,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACrC,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,4BAA4B,CAAC,CAAC;IAC1D,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrC,8EAA8E;IAC9E,gEAAgE;IAChE,EAAE,CAAC,IAAI,CACL;0BACsB,CACvB,CAAC;IAEF,8EAA8E;IAC9E,6EAA6E;IAC7E,oCAAoC;IACpC,EAAE,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACjD,EAAE,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Md,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;CAkBf,CAAC"}
@@ -0,0 +1,35 @@
1
+ export declare function isRepo(cwd?: string): boolean;
2
+ export declare function repoRoot(cwd?: string): string | undefined;
3
+ export declare function currentBranch(cwd?: string): string | undefined;
4
+ export declare function remoteUrl(cwd?: string): string | undefined;
5
+ /** Resolve any revision (HEAD, a tag, short sha) to a full commit sha. */
6
+ export declare function resolveRev(rev: string, cwd?: string): string | undefined;
7
+ /**
8
+ * List commit shas in a revision range (e.g. `main..HEAD`), newest first.
9
+ * `--end-of-options` blocks flag injection via a dashed range.
10
+ */
11
+ export declare function revList(range: string, cwd?: string): string[];
12
+ export interface CommitInfo {
13
+ sha: string;
14
+ author: string;
15
+ authorEmail: string;
16
+ date: string;
17
+ subject: string;
18
+ }
19
+ export declare function commitInfo(rev: string, cwd?: string): CommitInfo | undefined;
20
+ /** Files touched by a commit (paths relative to the repo root). */
21
+ export declare function filesInCommit(rev: string, cwd?: string): string[];
22
+ /** Distinct Git authors that have touched a file (from `git log`). */
23
+ export declare function fileAuthors(file: string, cwd?: string): string[];
24
+ /** Resolve which commit last modified a specific line — `git blame -L`. */
25
+ export declare function blameLine(file: string, line: number, cwd?: string): {
26
+ sha: string;
27
+ author: string;
28
+ } | undefined;
29
+ /**
30
+ * Append attribution as a Git note under `refs/notes/blackboard`. Notes are
31
+ * additive: they never alter the commit or its sha. Returns true on success.
32
+ */
33
+ export declare function writeNote(rev: string, note: string, cwd?: string): boolean;
34
+ export declare function readNote(rev: string, cwd?: string): string | undefined;
35
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AA0BA,wBAAgB,MAAM,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAE3D;AAED,wBAAgB,QAAQ,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAExE;AAED,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED,wBAAgB,SAAS,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAEzE;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CACxB,GA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