@oathe/oathe 0.4.4 → 0.4.5

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 (59) hide show
  1. package/.claude-plugin/marketplace.json +18 -2
  2. package/README.md +4 -1
  3. package/bin/oathe.mjs +199 -35
  4. package/docs/PRIVACY.md +26 -4
  5. package/notch/Oathe Notch.app/Contents/Info.plist +1 -1
  6. package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
  7. package/notch/README.md +4 -3
  8. package/package.json +3 -3
  9. package/plugin/.claude-plugin/plugin.json +21 -3
  10. package/plugin/.cursor-plugin/plugin.json +2 -2
  11. package/plugin/hooks/hooks.json +4 -4
  12. package/plugin/hooks/lib.mjs +9 -0
  13. package/plugin/hooks/render-board.mjs +4 -2
  14. package/src/blocks.mjs +10 -1
  15. package/src/board-render.mjs +7 -4
  16. package/src/breach-digest.mjs +75 -10
  17. package/src/config.mjs +18 -0
  18. package/src/context.mjs +1 -1
  19. package/src/device.mjs +106 -0
  20. package/src/doctor.mjs +101 -6
  21. package/src/engine-update.mjs +170 -0
  22. package/src/evidence-discovery.mjs +170 -0
  23. package/src/fence.mjs +3 -3
  24. package/src/harnesses/catalog.mjs +46 -4
  25. package/src/harnesses/claude.mjs +56 -4
  26. package/src/harnesses/codex-rollout.mjs +110 -21
  27. package/src/harnesses/codex.mjs +106 -19
  28. package/src/harnesses/cursor.mjs +31 -18
  29. package/src/harnesses/harness.mjs +82 -13
  30. package/src/harnesses/surfaces.mjs +2 -2
  31. package/src/home.mjs +174 -52
  32. package/src/init.mjs +27 -2
  33. package/src/launch.mjs +7 -9
  34. package/src/launchd.mjs +100 -0
  35. package/src/manifest.mjs +48 -6
  36. package/src/mcp/connection.mjs +73 -7
  37. package/src/mcp/daemon.mjs +123 -0
  38. package/src/mcp/forwarder.mjs +99 -0
  39. package/src/mcp/oathe-tools.mjs +392 -145
  40. package/src/notch-frame.mjs +118 -42
  41. package/src/notch.mjs +34 -68
  42. package/src/oathe-annotator.mjs +10 -10
  43. package/src/pager.mjs +144 -40
  44. package/src/paths.mjs +1 -0
  45. package/src/plans.mjs +44 -5
  46. package/src/registry.mjs +10 -2
  47. package/src/serve.mjs +82 -0
  48. package/src/session-host.mjs +1 -1
  49. package/src/sessions.mjs +39 -8
  50. package/src/shim.mjs +110 -0
  51. package/src/speaker.mjs +24 -5
  52. package/src/statements.mjs +116 -2
  53. package/src/traces.mjs +61 -19
  54. package/src/uninstall.mjs +20 -3
  55. package/src/update.mjs +35 -7
  56. package/src/verifier.mjs +215 -105
  57. package/src/verify-dispatch.mjs +86 -32
  58. package/src/wire.mjs +7 -1
  59. package/plugin/.mcp.json +0 -10
package/src/verifier.mjs CHANGED
@@ -22,20 +22,20 @@
22
22
  // PROVENANCE; the judgment quality is the engine's, and the linked traces exist precisely so
23
23
  // that judgment stays auditable.
24
24
 
25
- import { isTraceSubjectSql, TRACE_SUBJECT_PREFIX } from './statements.mjs';
25
+ import fs from 'node:fs';
26
+ import { EvidenceDiscovery } from './evidence-discovery.mjs';
26
27
  import { createRequire } from 'node:module';
27
28
  import { spawn } from 'node:child_process';
28
29
  import { amendSubjectRef, engineFailureRef, evidenceFailureRef } from './statements.mjs';
29
30
  import { emit as wireEmit } from './wire.mjs';
30
31
  import { WorkspaceRegistry } from './registry.mjs';
31
32
  import { homeOf } from './paths.mjs';
32
- import { HomeBoard } from './home.mjs';
33
+ import { HomeBoard, Place, PlaceEvidence } from './home.mjs';
33
34
 
34
35
  import { createOatheTools } from './mcp/oathe-tools.mjs';
35
36
  import { renderEvidenceView, sliceForTask } from './atif.mjs';
36
- import { transcriptFor } from './harnesses/catalog.mjs';
37
- import { projectAnnotated } from './oathe-annotator.mjs';
38
- import { verificationTaskId, isVerificationTask, ACCEPTANCE_CLAUSE_KEY } from './plans.mjs';
37
+ import { verificationTaskId, isVerificationTask, verifiedTaskId, ACCEPTANCE_CLAUSE_KEY } from './plans.mjs';
38
+ import { InstallManifest } from './manifest.mjs';
39
39
  import { RECORDED_VERDICT_CHECKER } from './runtime/discharge.mjs';
40
40
 
41
41
  const require = createRequire(import.meta.url);
@@ -57,8 +57,14 @@ export class Verifier {
57
57
  * config: import('./config.mjs').OatheConfig, operatorPrincipal: string,
58
58
  * engineRunner?: ({engine, prompt}) => Promise<{verdict: string, reason: string}>}} o
59
59
  */
60
- constructor({ substrate, paths, workspace, config, operatorPrincipal, engineRunner, provider = null, homePathFor = null, env = process.env }) {
60
+ constructor({ substrate, paths, workspace, config, operatorPrincipal, engineRunner, provider = null, homePathFor = null, env = process.env, discovery = null, addressFor = null }) {
61
61
  this.env = env; // the store home follows the RUN's env — a rebound HOME (cage, sandbox) must read the store the hooks wrote
62
+ // The engine's ADDRESS (ruling 2026-09-05): the manifest row init measured — a judgment
63
+ // dispatched from launchd's bare PATH (the feed, the daemon) spawns it by address, never by
64
+ // a bare name. Injectable; defaults to the install manifest under paths.
65
+ this.addressFor = addressFor
66
+ ?? ((engine) => InstallManifest.load({ manifestPath: paths.manifestPath, backupsDir: paths.backupsDir }).cliAddressFor(engine));
67
+ this.discovery = discovery; // the evidence rail — injectable like engineRunner, defaulted at first gather
62
68
  this.substrate = substrate;
63
69
  this.paths = paths;
64
70
  this.workspace = workspace;
@@ -67,8 +73,9 @@ export class Verifier {
67
73
  this.verifierPrincipal = config.get('verifierPrincipal');
68
74
  this.engineRunner = engineRunner ?? defaultEngineRunner;
69
75
  // The ONE home resolver (registry rootOf), injectable for tests. The engine judges
70
- // FROM the task's own folder — its tools are the evidence reader (ruling 2026-08-31);
71
- // a homeless task judges from the operator's home, never the caller's accidental cwd.
76
+ // FROM the folder the work resides in — its tools are the evidence reader (ruling
77
+ // 2026-08-31); work residing in an app judges from the operator's home, never the caller's
78
+ // accidental cwd.
72
79
  this.homePathFor = homePathFor
73
80
  ?? ((homeRef) => new WorkspaceRegistry({ registryPath: paths.registryPath }).rootOf(homeRef));
74
81
  this.orgId = config.get('org');
@@ -84,33 +91,31 @@ export class Verifier {
84
91
  config,
85
92
  });
86
93
  this.pool = null;
87
- this.runtime = null;
94
+ this.runtime_ = null;
88
95
  }
89
96
 
90
- async #runtime() {
91
- if (this.runtime) return this.runtime;
97
+ /** The acceptance runtime ({SETTLE, laneFor}) through the provider seam — opened once, closed with close(). */
98
+ async runtime() {
99
+ if (this.runtime_) return this.runtime_;
92
100
  const provider = this.provider
93
101
  ?? (await import('./runtime/provider.mjs')).resolveRuntimeProvider({
94
102
  config: this.config, paths: this.paths });
95
103
  const pg = require('pg');
96
104
  this.pool = new pg.Pool(this.substrate.connectionConfig());
97
- this.runtime = await provider.acceptanceRuntime({ pool: this.pool, orgId: this.orgId });
98
- return this.runtime;
105
+ this.runtime_ = await provider.acceptanceRuntime({ pool: this.pool, orgId: this.orgId });
106
+ return this.runtime_;
99
107
  }
100
108
 
101
109
  /** The latest completion statement for a task — the assertion under judgment. */
102
110
  async #completionStatement(taskId) {
111
+ return completionStatementOf({ substrate: this.substrate, orgId: this.orgId, taskId });
112
+ }
113
+
114
+ /** A task's bound verification plan (the standard plan `oathe_done` binds). */
115
+ async planOf(taskId) {
103
116
  const { rows } = await this.substrate.query(
104
- `SELECT statement_id, work_claim_id, claim_principal, execution_actor, evidence_refs, proposition
105
- FROM cell.agent_statement
106
- WHERE org_id = $1 AND task_id = $2 AND statement_type = 'completion'
107
- ORDER BY asserted_at DESC LIMIT 1`,
108
- [this.orgId, taskId]);
109
- if (rows.length === 0) {
110
- throw new VerifierError('OATHE_NO_COMPLETION',
111
- `'${taskId}' has no completion statement — nothing was asserted, nothing to verify`, { taskId });
112
- }
113
- return rows[0];
117
+ 'SELECT verification_plan FROM cell.task WHERE org_id = $1 AND task_id = $2', [this.orgId, taskId]);
118
+ return rows[0]?.verification_plan ?? null;
114
119
  }
115
120
 
116
121
  /**
@@ -118,27 +123,17 @@ export class Verifier {
118
123
  * validated. Contract/projection failures REFUSE loudly (TraceContractError/AtifError):
119
124
  * never less evidence than the claim recorded.
120
125
  */
121
- async #traceEvidence(workClaimId) {
122
- const { rows } = await this.substrate.query(
123
- `SELECT subject_ref, evidence_refs FROM cell.agent_statement
124
- WHERE org_id = $1 AND work_claim_id = $2 AND ${isTraceSubjectSql('subject_ref')}`,
125
- [this.orgId, workClaimId]);
126
- const traces = [];
127
- for (const row of rows) {
128
- // The file the session's rows LIVE in: a link spoken from a resumed session names the
129
- // transcript the harness reported and never wrote — the store resolves it from the rows
130
- // that carry the session id (transcriptFor); a file nothing carries stays as recorded
131
- // and refuses below, loudly.
132
- const sessionId = row.subject_ref.slice(TRACE_SUBJECT_PREFIX.length);
133
- for (const ref of row.evidence_refs) {
134
- const file = transcriptFor({ sessionId, reportedPath: ref, home: homeOf(this.env) });
135
- traces.push({ path: file, trajectory: await projectAnnotated(file, { home: homeOf(this.env) }) });
136
- }
137
- }
138
- return traces;
126
+ async #traceEvidence(taskId) {
127
+ // Evidence is the TASK's record, spanning claims, gathered by the evidence rail: the
128
+ // recorded trace links ∪ fingerprint discovery, performance-confirmed and deterministic
129
+ // (src/evidence-discovery.mjs). A re-claim judged blind to its prior interval and a
130
+ // traceless surface judged on an empty record were both false rejections, live 2026-09-04.
131
+ this.discovery ??= new EvidenceDiscovery({
132
+ client: this.substrate, orgId: this.orgId, home: homeOf(this.env) });
133
+ return this.discovery.read({ taskId });
139
134
  }
140
135
 
141
- #prompt({ taskRow, completion, traces, taskId, amendments = [] }) {
136
+ #prompt({ taskRow, completion, traces, taskId, amendments = [], cwd }) {
142
137
  const budget = this.config.get('verifierEvidenceBudget');
143
138
  const perTrace = Math.max(1, Math.floor(budget / Math.max(1, traces.length)));
144
139
  return [
@@ -148,13 +143,20 @@ export class Verifier {
148
143
  'actually took; GOT lines are what actually came back; FROM lines are messages other agents sent',
149
144
  'this one (a delegated brief, a subagent\'s answer) — never this agent\'s own claims. Judge',
150
145
  'claims against actions and outcomes — be strict: absence of evidence is absence.',
151
- 'You are running in the task\'s workspace — check asserted artifacts against the files on disk.',
146
+ `You are running in ${cwd} — the task's folder — check asserted artifacts against the files on disk.`,
152
147
  '',
153
148
  `TASK: ${taskId}`,
154
149
  `OBJECTIVE: ${taskRow.objective}`,
155
150
  `VERIFICATION PLAN: ${JSON.stringify(taskRow.verification_plan)}`,
156
151
  `COMPLETION ASSERTION: ${completion.proposition}`,
157
152
  `ASSERTED EVIDENCE: ${JSON.stringify(completion.evidence_refs)}`,
153
+ // The assertion is the done act itself, from the substrate — told "absence is absence"
154
+ // without this, an engine read a done missing from the trace (the call in flight on a
155
+ // code-mode surface) as "never completed" and rejected honest work (2026-09-04).
156
+ 'The COMPLETION ASSERTION above IS the done act under judgment, recorded by the substrate. It may',
157
+ 'not appear in the traces below: it is the call in flight on some surfaces, or was spoken from',
158
+ 'elsewhere. Never treat its absence from a trace as absence of completion — judge the DID/GOT',
159
+ 'against the objective.',
158
160
  ...(amendments.length === 0 ? [] : [
159
161
  '',
160
162
  `AMENDMENT TRAIL (${amendments.length} — the definition of done MOVED, with sign-off;`,
@@ -176,7 +178,7 @@ export class Verifier {
176
178
  */
177
179
  async verify({ taskId, engine: engineOverride }) {
178
180
  const verificationTask = isVerificationTask(taskId) ? taskId : verificationTaskId(taskId);
179
- const originalTask = verificationTask.slice('verify:'.length);
181
+ const originalTask = verifiedTaskId(verificationTask);
180
182
 
181
183
  const { rows: vtaskRows } = await this.substrate.query(
182
184
  'SELECT objective, verification_plan FROM cell.task WHERE org_id = $1 AND task_id = $2',
@@ -186,11 +188,19 @@ export class Verifier {
186
188
  `no verification task '${verificationTask}' on the board — has '${originalTask}' been `
187
189
  + 'asserted done (oathe done) at all?', { taskId });
188
190
  }
189
- const engine = engineOverride ?? vtaskRows[0].verification_plan?.verifier_engine
190
- ?? this.config.get('verifier');
191
+ // Current config beats the claim-time binding (founder ruling 2026-09-04): an unsettled
192
+ // verification must never stay wedged on an engine that failed — a dead CLI, a usage
193
+ // limit — when the operator has since changed the verifier. The plan's frozen
194
+ // verifier_engine stays the RECORD of what was assigned at claim; an explicit --engine
195
+ // still wins as a deliberate per-run choice.
196
+ const engine = engineOverride ?? this.config.get('verifier'); // config names the verifier or refuses — the plan's verifier_engine is the RECORD of the claim-time assignment, never a fallback
191
197
 
192
198
  // 1. Claim the review — the verifier principal takes visible responsibility for it.
193
199
  const vclaim = await this.tools.oathe_claim({ task_id: verificationTask });
200
+ // The judgment announces its START on the wire (ruling 2026-09-04): the glass turns the
201
+ // row `verifying` the moment the claim lands, whichever surface dispatched it — the
202
+ // verifier's own tools carry no activation, so this nudge is hand-rolled like the verdict's.
203
+ await wireEmit(this.substrate, { kind: 'verify_started', task_id: originalTask });
194
204
 
195
205
  // 2-3. EVERYTHING between the claim and a durable verdict runs under the release
196
206
  // guard (ruling 2026-08-31: ANY exit before a verdict fails loud and frees the claim —
@@ -205,13 +215,34 @@ export class Verifier {
205
215
  try {
206
216
  completion = await this.#completionStatement(originalTask);
207
217
  ({ rows: taskRows } = await this.substrate.query(
208
- `SELECT objective, verification_plan, ${HomeBoard.homeSql('t')} AS home
209
- FROM cell.task t WHERE org_id = $1 AND task_id = $2`,
218
+ `SELECT t.objective, t.verification_plan, res.place, res.place_evidence
219
+ FROM cell.task t LEFT JOIN LATERAL (${HomeBoard.residenceSql('t')}) res ON true
220
+ WHERE t.org_id = $1 AND t.task_id = $2`,
210
221
  [this.orgId, originalTask]));
211
- // The engine judges FROM the task's workspace — its own tools read the evidence on
212
- // disk. One resolver (registry rootOf); a homeless task judges from the operator's home.
213
- const taskHome = this.homePathFor(taskRows[0]?.home) ?? homeOf();
214
- traces = await this.#traceEvidence(completion.work_claim_id);
222
+ // The engine judges FROM where the work RESIDES (ruling 2026-09-05: the last pickup) —
223
+ // its own tools read the evidence on disk. One resolver (registry rootOf) for a folder; an
224
+ // app residence judges from the project folder the pickup recorded (its files are there),
225
+ // else the operator's home — and the prompt says which, the only place that is spoken.
226
+ const residence = Place.parseOrNull(taskRows[0]?.place ?? null);
227
+ const projectDir = PlaceEvidence.parse(taskRows[0]?.place_evidence).dir;
228
+ const taskHome = (residence?.isFolder ? this.homePathFor(residence.ref) : (projectDir && fs.existsSync(projectDir) ? projectDir : null)) ?? homeOf();
229
+ const evidence = await this.#traceEvidence(originalTask);
230
+ traces = evidence.traces;
231
+ // An empty record never reaches the engine: judged on nothing, one engine rejected and
232
+ // the next accepted the same claim (live 2026-09-04) — a verdict lottery. A store-less
233
+ // surface's empty-evidence link IS attribution and still judges; no link and no
234
+ // discovery hit is a stall in the evidence lane, not a coin flip. What the scan could
235
+ // not read is said in the stall, by name — an unrelated unreadable file never stalls a
236
+ // task on its own, and never goes unmentioned either.
237
+ if (traces.length === 0 && !(await this.discovery.hasAttribution(originalTask))) {
238
+ const unread = evidence.unreadable.length === 0 ? ''
239
+ : `; ${evidence.unreadable.length} store file(s) the scan could not read: `
240
+ + evidence.unreadable.map((u) => `${u.path} (${u.code})`).join(', ');
241
+ throw new VerifierError('OATHE_EVIDENCE_EMPTY',
242
+ `no session evidence reachable for '${originalTask}' — the record holds no trace links and `
243
+ + `discovery found no transcript performing it${unread}; fix attribution (or land the work) and re-verify`,
244
+ { taskId: originalTask, unreadable: evidence.unreadable });
245
+ }
215
246
  // R-AMEND: the amendment trail is part of the record — the engine judges the CURRENT
216
247
  // objective and SEES every move of the bar (a late amendment is visible evidence).
217
248
  const { rows: amendments } = await this.substrate.query(
@@ -222,8 +253,9 @@ export class Verifier {
222
253
  engineLaunched = true;
223
254
  raw = await this.engineRunner({
224
255
  engine,
256
+ address: this.addressFor(engine),
225
257
  cwd: taskHome,
226
- prompt: this.#prompt({ taskRow: taskRows[0], completion, traces, taskId: originalTask, amendments }),
258
+ prompt: this.#prompt({ taskRow: taskRows[0], completion, traces, taskId: originalTask, amendments, cwd: taskHome }),
227
259
  });
228
260
  if (!raw || !VERDICTS.includes(raw.verdict) || typeof raw.reason !== 'string' || raw.reason.trim() === '') {
229
261
  throw new VerifierError('OATHE_VERDICT_MALFORMED',
@@ -234,10 +266,16 @@ export class Verifier {
234
266
  // One guard, two honest stalls (the 2026-08-31 pileup): an unreadable record fails
235
267
  // every engine alike, so only an engine-stage death may advise trying another one.
236
268
  const msg = String(e?.message ?? e).slice(0, 400);
269
+ // The cause (ruling 2026-09-05) rides the ref — `missing` (no address runs), or what the
270
+ // adapter's diagnose read off the engine's own words (`outdated`), or none — and names
271
+ // the honest gesture; the pager and the glass act on the same word.
272
+ const cause = e?.code === 'OATHE_ENGINE_MISSING' ? 'missing' : (e?.details?.cause ?? null);
273
+ const gesture = {
274
+ outdated: `engine ${engine} is out of date — update it and the judgment re-runs: oathe engine update ${engine}`,
275
+ missing: `engine ${engine} is not reachable — run oathe init to record its address, then oathe verify ${originalTask}`,
276
+ }[cause] ?? `engine ${engine} died — released for retry: set another verifier (oathe config verifier <engine>) or oathe verify ${originalTask} --engine <engine>`;
237
277
  const stall = engineLaunched
238
- ? { proposition: `engine ${engine} failed before a verdict: ${msg}`,
239
- ref: engineFailureRef(engine),
240
- note: `engine ${engine} died — released for retry: oathe verify ${originalTask} --engine <another>` }
278
+ ? { proposition: `engine ${engine} failed before a verdict: ${msg}`, ref: engineFailureRef(engine, cause), note: gesture }
241
279
  : { proposition: `gathering evidence failed before the ${engine} engine launched: ${msg}`,
242
280
  ref: evidenceFailureRef(e?.code),
243
281
  note: `the record could not be read — fix the cause and retry: oathe verify ${originalTask}` };
@@ -264,37 +302,16 @@ export class Verifier {
264
302
  });
265
303
 
266
304
  // 5. Settle the ORIGINAL claim — deterministic lane, verifier seat, FC010-clean.
267
- const { SETTLE, laneFor } = await this.#runtime();
305
+ const runtime = await this.runtime();
268
306
  const tracePath = traces[0]?.path ?? `statement:${done.statement_id}`;
269
- const lane = laneFor(this.verifierPrincipal);
270
- const statementFor = (stmt) => ({
271
- statement_ref: stmt.statement_id,
272
- work_claim_id: stmt.work_claim_id,
273
- evidence_refs: stmt.evidence_refs,
274
- trace_ref: tracePath,
275
- kind: 'completion',
276
- statement_type: 'completion',
277
- });
278
- const clauseFor = (task, plan, stmt, extra = {}) => ({
279
- org_id: this.orgId,
280
- task_id: task,
281
- clause_key: ACCEPTANCE_CLAUSE_KEY,
282
- verification_plan: plan,
283
- author_principal: stmt.claim_principal,
284
- executor_principal: stmt.execution_actor,
285
- seat_principal: null,
286
- evidence_refs: [verdictRef],
287
- trace_ref: tracePath,
288
- privacy_class: 'org_internal',
289
- transfer_scope: 'org_internal',
290
- ...extra,
291
- });
292
- const outcome = await lane.verify({
293
- agent_statement: statementFor(completion),
307
+ const outcome = await runtime.laneFor(this.verifierPrincipal).verify({
308
+ agent_statement: laneStatement(completion, tracePath),
294
309
  task_id: originalTask,
295
- clause: clauseFor(originalTask, taskRows[0].verification_plan, completion,
296
- { checker: RECORDED_VERDICT_CHECKER, oathe_recorded_verdict: raw.verdict }),
297
- }, { settle: SETTLE.CLAIM });
310
+ clause: settleClause({
311
+ orgId: this.orgId, taskId: originalTask, plan: taskRows[0].verification_plan, stmt: completion, evidenceRefs: [verdictRef], tracePath,
312
+ extra: { checker: RECORDED_VERDICT_CHECKER, oathe_recorded_verdict: raw.verdict },
313
+ }),
314
+ }, { settle: runtime.SETTLE.CLAIM });
298
315
 
299
316
  let settledNow = outcome.settled === true;
300
317
  if (!settledNow) {
@@ -320,19 +337,10 @@ export class Verifier {
320
337
  await wireEmit(this.substrate, { kind: raw.verdict === 'rejected' ? 'rejected' : 'settled', task_id: originalTask });
321
338
 
322
339
  // 7. The review itself settles under the OPERATOR seat (non-author of the verdict statement).
323
- const verdictStatement = await this.#completionStatement(verificationTask);
324
- const operatorLane = laneFor(this.operatorPrincipal);
325
- const reviewOutcome = await operatorLane.verify({
326
- agent_statement: statementFor(verdictStatement),
327
- task_id: verificationTask,
328
- clause: clauseFor(verificationTask, vtaskRows[0].verification_plan, verdictStatement,
329
- { checker: 'verification-clause' }),
330
- }, { settle: SETTLE.CLAIM });
331
- if (!reviewOutcome.settled) {
332
- throw new VerifierError('OATHE_REVIEW_UNSETTLED',
333
- `the verification task's own settlement failed: ${JSON.stringify(reviewOutcome.verification)}`,
334
- { reviewOutcome });
335
- }
340
+ await settleReview({
341
+ runtime, seat: this.operatorPrincipal, orgId: this.orgId, taskId: verificationTask,
342
+ plan: vtaskRows[0].verification_plan, stmt: await this.#completionStatement(verificationTask), evidenceRefs: [verdictRef], tracePath,
343
+ });
336
344
 
337
345
  return {
338
346
  task_id: originalTask,
@@ -361,8 +369,100 @@ export class Verifier {
361
369
  }
362
370
  }
363
371
 
364
- /** The real engine runner: one headless run, strict JSON out. Refusals are typed and loud. */
365
- export async function defaultEngineRunner({ engine, prompt, env = process.env, model = null, cwd = undefined }) {
372
+ /**
373
+ * Every JSON object in `text` that carries a "verdict" key, as raw slices — found by walking
374
+ * balanced braces (string-aware), not by a brace-free regex: an engine's reason may quote
375
+ * braces (`{parent,surface}` did, live 2026-09-05) and a real verdict must never read as none.
376
+ */
377
+ export function verdictObjects(text) {
378
+ const out = [];
379
+ for (let i = text.indexOf('{'); i !== -1; i = text.indexOf('{', i + 1)) {
380
+ let depth = 0; let inString = false; let end = -1;
381
+ for (let j = i; j < text.length; j += 1) {
382
+ const c = text[j];
383
+ if (inString) { if (c === '\\') j += 1; else if (c === '"') inString = false; continue; }
384
+ if (c === '"') inString = true;
385
+ else if (c === '{') depth += 1;
386
+ else if (c === '}') { depth -= 1; if (depth === 0) { end = j; break; } }
387
+ }
388
+ if (end === -1) continue;
389
+ const slice = text.slice(i, end + 1);
390
+ if (/"verdict"\s*:/.test(slice)) out.push(slice); // inner objects are visited too — the last (innermost-last) wins
391
+ }
392
+ return out;
393
+ }
394
+
395
+ /** The latest completion statement for a task — the assertion a seat settles. */
396
+ export async function completionStatementOf({ substrate, orgId, taskId }) {
397
+ const { rows } = await substrate.query(
398
+ `SELECT statement_id, work_claim_id, claim_principal, execution_actor, evidence_refs, proposition
399
+ FROM cell.agent_statement
400
+ WHERE org_id = $1 AND task_id = $2 AND statement_type = 'completion'
401
+ ORDER BY asserted_at DESC LIMIT 1`,
402
+ [orgId, taskId]);
403
+ if (rows.length === 0) {
404
+ throw new VerifierError('OATHE_NO_COMPLETION',
405
+ `'${taskId}' has no completion statement — nothing was asserted, nothing to verify`, { taskId });
406
+ }
407
+ return rows[0];
408
+ }
409
+
410
+ /** The lane's view of a completion statement — the shape the acceptance lane's verify reads. */
411
+ export function laneStatement(stmt, tracePath) {
412
+ return {
413
+ statement_ref: stmt.statement_id,
414
+ work_claim_id: stmt.work_claim_id,
415
+ evidence_refs: stmt.evidence_refs,
416
+ trace_ref: tracePath,
417
+ kind: 'completion',
418
+ statement_type: 'completion',
419
+ };
420
+ }
421
+
422
+ /** The clause a seat settles under: the task's bound plan, the statement's author and executor, the refs, a checker. */
423
+ export function settleClause({ orgId, taskId, plan, stmt, evidenceRefs, tracePath, extra = {} }) {
424
+ return {
425
+ org_id: orgId,
426
+ task_id: taskId,
427
+ clause_key: ACCEPTANCE_CLAUSE_KEY,
428
+ verification_plan: plan,
429
+ author_principal: stmt.claim_principal,
430
+ executor_principal: stmt.execution_actor,
431
+ seat_principal: null,
432
+ evidence_refs: evidenceRefs,
433
+ trace_ref: tracePath,
434
+ privacy_class: 'org_internal',
435
+ transfer_scope: 'org_internal',
436
+ ...extra,
437
+ };
438
+ }
439
+
440
+ /**
441
+ * The deterministic review a SYSTEM task closes with (a judgment's verify: task, an engine's
442
+ * update: task): its completion settles under `seat` — a non-author — at the standard bar
443
+ * (checker verification-clause: a completion, evidence present, a trace ref; no model). One
444
+ * implementation; throws OATHE_REVIEW_UNSETTLED when the lane refuses.
445
+ */
446
+ export async function settleReview({ runtime, seat, orgId, taskId, plan, stmt, evidenceRefs, tracePath }) {
447
+ const outcome = await runtime.laneFor(seat).verify({
448
+ agent_statement: laneStatement(stmt, tracePath),
449
+ task_id: taskId,
450
+ clause: settleClause({ orgId, taskId, plan, stmt, evidenceRefs, tracePath, extra: { checker: 'verification-clause' } }),
451
+ }, { settle: runtime.SETTLE.CLAIM });
452
+ if (!outcome.settled) {
453
+ throw new VerifierError('OATHE_REVIEW_UNSETTLED',
454
+ `the verification task's own settlement failed: ${JSON.stringify(outcome.verification)}`, { reviewOutcome: outcome, taskId });
455
+ }
456
+ return outcome;
457
+ }
458
+
459
+ /**
460
+ * The real engine runner: one headless run, strict JSON out. Refusals are typed and loud.
461
+ * `address` (ruling 2026-09-05) is the CLI's recorded address — the one thing spawn is handed;
462
+ * never a bare name, never a PATH guess, so a launchd-spawned judgment either runs the engine
463
+ * init measured or refuses by name.
464
+ */
465
+ export async function defaultEngineRunner({ engine, prompt, env = process.env, model = null, cwd = undefined, address = null }) {
366
466
  // The command line and output shape are each engine adapter's own facts (src/harnesses/).
367
467
  const { byName, verifierCapable } = await import('./harnesses/catalog.mjs');
368
468
  const known = verifierCapable();
@@ -372,6 +472,14 @@ export async function defaultEngineRunner({ engine, prompt, env = process.env, m
372
472
  }
373
473
  const adapter = byName(engine);
374
474
  const command = adapter.headless.command(prompt, model);
475
+ // The address is REQUIRED (zero legacy, 2026-09-05): init records one for every CLI it finds;
476
+ // a judgment never guesses a PATH — a machine without the row refuses by name.
477
+ if (typeof address !== 'string' || address === '') {
478
+ throw new VerifierError('OATHE_ENGINE_MISSING',
479
+ `the '${engine}' CLI: no address was recorded for it — run oathe init to record where it is`, { engine, address: null });
480
+ }
481
+ const bin = address;
482
+ command[0] = bin;
375
483
  // async spawn — a minutes-long engine run must never halt the event loop (spawnSync froze the
376
484
  // whole MCP server, ping included, before the dispatcher existed; the sync bin path gains the
377
485
  // same hygiene for free).
@@ -401,12 +509,14 @@ export async function defaultEngineRunner({ engine, prompt, env = process.env, m
401
509
  });
402
510
  if (run.error) {
403
511
  throw new VerifierError('OATHE_ENGINE_MISSING',
404
- `the '${engine}' CLI is not installed or not on PATH — verification needs a real engine `
405
- + `(${String(run.error.message).slice(0, 120)})`, { engine });
512
+ `the '${engine}' CLI at ${bin} did not run (${String(run.error.message).slice(0, 120)}) — `
513
+ + 'run oathe init to record where it is now', { engine, address: bin });
406
514
  }
407
515
  if (run.status !== 0) {
516
+ const tail = String(run.stderr ?? '').trim().slice(-300);
408
517
  throw new VerifierError('OATHE_ENGINE_FAILED',
409
- `${engine} exited ${run.status}; stderr tail: ${String(run.stderr ?? '').trim().slice(-300)}`, { engine, status: run.status });
518
+ `${engine} exited ${run.status}; stderr tail: ${tail}`,
519
+ { engine, status: run.status, cause: adapter.headless.diagnose(tail) }); // the adapter alone reads the engine's words
410
520
  }
411
521
  let text;
412
522
  try {
@@ -414,8 +524,8 @@ export async function defaultEngineRunner({ engine, prompt, env = process.env, m
414
524
  } catch (e) {
415
525
  throw new VerifierError('OATHE_ENGINE_OUTPUT_MALFORMED', e.message, { engine });
416
526
  }
417
- const match = String(text).match(/\{[^{}]*"verdict"[^{}]*\}/g);
418
- if (!match) {
527
+ const match = verdictObjects(String(text));
528
+ if (match.length === 0) {
419
529
  throw new VerifierError('OATHE_VERDICT_MALFORMED',
420
530
  `no JSON verdict found in ${engine} output: ${String(text).slice(-300)}`, { engine });
421
531
  }