@oathe/oathe 0.2.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +3 -4
- package/README.md +15 -45
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +401 -59
- package/docs/PRIVACY.md +13 -5
- package/notch/Oathe Notch.app/Contents/Info.plist +13 -0
- package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
- package/notch/Oathe Notch.app/Contents/_CodeSignature/CodeResources +115 -0
- package/notch/README.md +88 -0
- package/package.json +13 -4
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +36 -0
- package/plugin/.mcp.json +1 -4
- package/plugin/commands/verify.md +18 -0
- package/plugin/hooks/frame-note.mjs +5 -3
- package/plugin/hooks/heartbeat.mjs +21 -25
- package/plugin/hooks/lib.mjs +96 -33
- package/plugin/hooks/render-board.mjs +47 -7
- package/src/activation.mjs +126 -0
- package/src/atif.mjs +4 -13
- package/src/blocks.mjs +113 -8
- package/src/board-render.mjs +55 -29
- package/src/config.mjs +100 -15
- package/src/context.mjs +4 -8
- package/src/doctor.mjs +96 -15
- package/src/fence.mjs +85 -0
- package/src/fslock.mjs +51 -0
- package/src/harnesses/catalog.mjs +180 -0
- package/src/harnesses/claude.mjs +196 -0
- package/src/harnesses/codex.mjs +188 -0
- package/src/harnesses/cursor.mjs +234 -0
- package/src/harnesses/dialects.mjs +52 -0
- package/src/harnesses/harness.mjs +203 -0
- package/src/harnesses/surfaces.mjs +71 -0
- package/src/home.mjs +107 -0
- package/src/init.mjs +101 -21
- package/src/launch-env.mjs +1 -51
- package/src/launch.mjs +36 -105
- package/src/manifest.mjs +7 -3
- package/src/mcp/connection.mjs +218 -0
- package/src/mcp/oathe-tools.mjs +380 -141
- package/src/notch.mjs +160 -0
- package/src/pager.mjs +178 -0
- package/src/paths.mjs +13 -1
- package/src/plans.mjs +10 -2
- package/src/registry.mjs +110 -0
- package/src/runtime/discharge.mjs +1 -1
- package/src/runtime/provider.mjs +10 -7
- package/src/runtime/simple-cage.mjs +18 -9
- package/src/runtime/sql-acceptance-lane.mjs +1 -1
- package/src/session-host.mjs +8 -6
- package/src/sessions.mjs +168 -0
- package/src/setup.mjs +494 -0
- package/src/speaker.mjs +65 -0
- package/src/statements.mjs +113 -0
- package/src/substrate.mjs +44 -0
- package/src/successor.mjs +1 -1
- package/src/traces.mjs +8 -8
- package/src/uninstall.mjs +10 -2
- package/src/verifier.mjs +135 -47
- package/src/verify-dispatch.mjs +169 -0
- package/src/welcome.mjs +32 -0
- package/src/wire.mjs +64 -0
- package/src/workspace-resolver.mjs +178 -0
- package/src/workspace.mjs +16 -5
- package/vendor/ddl/001_core.sql +1 -1
- package/vendor/ddl/004_delegation.sql +1 -1
- package/vendor/ddl/006_dependency.sql +1 -1
- package/vendor/ddl/008_effect_receipt.sql +1 -1
- package/vendor/ddl/009_verified_edge.sql +1 -1
- package/vendor/ddl/011_confirm.sql +2 -2
- package/vendor/ddl/manifest.json +8 -8
- package/assets/handoff-splash.png +0 -0
- package/src/harness.mjs +0 -271
package/src/substrate.mjs
CHANGED
|
@@ -97,16 +97,60 @@ export class Substrate {
|
|
|
97
97
|
async #cellClient() {
|
|
98
98
|
if (!this.client) {
|
|
99
99
|
this.client = new pg.Client(this.connectionConfig());
|
|
100
|
+
// An idle-connection drop without a listener is an UNCAUGHT 'error' event — it used
|
|
101
|
+
// to kill whole processes (the review's SERVE-CRASH finding). The death becomes a
|
|
102
|
+
// fact: noted once, and every later query refuses typed instead of exploding.
|
|
103
|
+
this.client.on('error', (e) => {
|
|
104
|
+
this.connectionLost = String(e?.message || e);
|
|
105
|
+
process.stderr.write(`oathe substrate: connection lost (${this.connectionLost.slice(0, 120)})\n`);
|
|
106
|
+
});
|
|
100
107
|
await this.client.connect();
|
|
101
108
|
}
|
|
109
|
+
if (this.connectionLost) {
|
|
110
|
+
const err = new Error(`the substrate connection was lost (${this.connectionLost}) — reconnect or restart the process`);
|
|
111
|
+
err.code = 'OATHE_SUBSTRATE_LOST';
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
102
114
|
return this.client;
|
|
103
115
|
}
|
|
104
116
|
|
|
117
|
+
// The transaction gate: BEGIN..COMMIT spans hold it, every outside query waits at it.
|
|
118
|
+
// One shared connection + concurrent MCP tool calls used to interleave an acknowledged
|
|
119
|
+
// write into an open transaction (swallowed by its ROLLBACK) — the review's sharpest
|
|
120
|
+
// finding. The gate makes that impossible; a transaction's own queries ride `tx`.
|
|
121
|
+
#txnGate = Promise.resolve();
|
|
122
|
+
|
|
105
123
|
async query(sql, params) {
|
|
124
|
+
await this.#txnGate;
|
|
106
125
|
const client = await this.#cellClient();
|
|
107
126
|
return client.query(sql, params);
|
|
108
127
|
}
|
|
109
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Run `fn(tx)` inside BEGIN..COMMIT (ROLLBACK on throw) with the gate held for the whole
|
|
131
|
+
* span. `tx.query` is the only lawful way to speak inside the transaction.
|
|
132
|
+
*/
|
|
133
|
+
async withTransaction(fn) {
|
|
134
|
+
const prev = this.#txnGate;
|
|
135
|
+
let release;
|
|
136
|
+
this.#txnGate = new Promise((r) => { release = r; });
|
|
137
|
+
await prev;
|
|
138
|
+
try {
|
|
139
|
+
const client = await this.#cellClient();
|
|
140
|
+
await client.query('BEGIN');
|
|
141
|
+
try {
|
|
142
|
+
const out = await fn({ query: (sql, params) => client.query(sql, params) });
|
|
143
|
+
await client.query('COMMIT');
|
|
144
|
+
return out;
|
|
145
|
+
} catch (e) {
|
|
146
|
+
await client.query('ROLLBACK').catch(() => {});
|
|
147
|
+
throw e;
|
|
148
|
+
}
|
|
149
|
+
} finally {
|
|
150
|
+
release();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
110
154
|
/** @returns {Promise<{reachable: boolean, detail: string|null}>} */
|
|
111
155
|
async detect() {
|
|
112
156
|
let admin;
|
package/src/successor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// oathe — the successor sequence seam (pickup is what "continue task-x" means; the founder
|
|
2
2
|
// ruling: resuming is what launching means, and picking up happens here).
|
|
3
3
|
//
|
|
4
|
-
// THIN WRAPPER (
|
|
4
|
+
// THIN WRAPPER (ruling, 2026-08-26): no execution logic lives in this tree. The real
|
|
5
5
|
// three-call sequence — buildProductionDeps → readPriorAttemptStep → reallocateStep, with the
|
|
6
6
|
// RECOMPILE-vs-RESUME decision inside allocate() — ships with the `oathe-runtime` package and
|
|
7
7
|
// lands behind `oathe-runtime/seam`, which must export
|
package/src/traces.mjs
CHANGED
|
@@ -9,11 +9,6 @@ import os from 'node:os';
|
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import zlib from 'node:zlib';
|
|
11
11
|
|
|
12
|
-
/** Which harness a trace path belongs to — the codex store dir is the discriminator. */
|
|
13
|
-
export function harnessForTracePath(file) {
|
|
14
|
-
return String(file).includes(`${path.sep}.codex${path.sep}`) ? 'codex' : 'claude';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
12
|
export class TraceContractError extends Error {
|
|
18
13
|
constructor(code, message, details = {}) {
|
|
19
14
|
super(message);
|
|
@@ -26,7 +21,12 @@ export class TraceContractError extends Error {
|
|
|
26
21
|
/** Shared machinery: newline-delimited JSON with optional zstd compression. */
|
|
27
22
|
export class TraceStore {
|
|
28
23
|
/** @param {{home?: string}} o home = the user home the store hangs off (default os.homedir()) */
|
|
29
|
-
constructor({ home } = {}) {
|
|
24
|
+
constructor({ home, harness } = {}) {
|
|
25
|
+
if (!harness) {
|
|
26
|
+
throw new TraceContractError('TRACE_STORE_HARNESS_REQUIRED',
|
|
27
|
+
'a trace store is built by its harness adapter, which names it — no store spells its own harness');
|
|
28
|
+
}
|
|
29
|
+
this.harness = harness;
|
|
30
30
|
this.home = home || os.homedir();
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -119,7 +119,7 @@ export class ClaudeTraceStore extends TraceStore {
|
|
|
119
119
|
`${file}: message entries carry no sessionId — the transcript contract drifted`, { file });
|
|
120
120
|
}
|
|
121
121
|
return {
|
|
122
|
-
harness:
|
|
122
|
+
harness: this.harness,
|
|
123
123
|
session_id: identity.sessionId,
|
|
124
124
|
cwd: messages.find((r) => r.cwd)?.cwd ?? null,
|
|
125
125
|
title: rows.find((r) => r.type === 'ai-title')?.aiTitle ?? null,
|
|
@@ -201,7 +201,7 @@ export class CodexTraceStore extends TraceStore {
|
|
|
201
201
|
`${file}: session_meta carries neither id nor session_id`, { file });
|
|
202
202
|
}
|
|
203
203
|
return {
|
|
204
|
-
harness:
|
|
204
|
+
harness: this.harness,
|
|
205
205
|
session_id: meta.id ?? meta.session_id,
|
|
206
206
|
cwd: meta.cwd ?? null,
|
|
207
207
|
source: meta.source ?? null,
|
package/src/uninstall.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
|
|
7
7
|
import { buildContext } from './context.mjs';
|
|
8
|
-
import { FencedBlock, FENCE_STYLES } from './blocks.mjs';
|
|
8
|
+
import { FencedBlock, FENCE_STYLES, sweepCreatedResidue } from './blocks.mjs';
|
|
9
9
|
|
|
10
10
|
/** @returns {Promise<{actions: object[], database_dropped: boolean}>} */
|
|
11
11
|
export async function runUninstall({ env = process.env, exec, purgeDb = false } = {}) {
|
|
@@ -19,7 +19,8 @@ export async function runUninstall({ env = process.env, exec, purgeDb = false }
|
|
|
19
19
|
actions.push({ harness: harness.name, ...action });
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
//
|
|
22
|
+
// Every fence: the folder ones (CLAUDE.md/AGENTS.md written by activation) and the global
|
|
23
|
+
// one in an adapter's instructions file (written by init) — one row shape, one removal.
|
|
23
24
|
for (const row of manifest.removeWhere((r) => r.kind === 'fence')) {
|
|
24
25
|
if (!fs.existsSync(row.file)) continue;
|
|
25
26
|
const block = new FencedBlock({ style: FENCE_STYLES[row.detail?.style ?? 'hash'] });
|
|
@@ -30,6 +31,13 @@ export async function runUninstall({ env = process.env, exec, purgeDb = false }
|
|
|
30
31
|
else fs.writeFileSync(row.file, content);
|
|
31
32
|
actions.push({ action: 'fence-removed', file: row.file });
|
|
32
33
|
}
|
|
34
|
+
// Files init CREATED (absent before) and that hold nothing of substance now are removed —
|
|
35
|
+
// the fence rule above, applied to every managed-write engine. A file the user or the
|
|
36
|
+
// harness wrote anything else into stays, minus our entries.
|
|
37
|
+
actions.push(...sweepCreatedResidue({ backups: manifest.backups }));
|
|
38
|
+
// The notch LaunchAgent: booted out and removed exactly as recorded (src/notch.mjs).
|
|
39
|
+
const { unwireNotch } = await import('./notch.mjs');
|
|
40
|
+
actions.push(...unwireNotch({ manifest, ...(exec ? { exec } : {}) }));
|
|
33
41
|
manifest.save();
|
|
34
42
|
|
|
35
43
|
let databaseDropped = false;
|
package/src/verifier.mjs
CHANGED
|
@@ -22,13 +22,18 @@
|
|
|
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
|
|
26
|
-
import path from 'node:path';
|
|
25
|
+
import { isTraceSubjectSql } from './statements.mjs';
|
|
27
26
|
import { createRequire } from 'node:module';
|
|
28
|
-
import {
|
|
27
|
+
import { spawn } from 'node:child_process';
|
|
28
|
+
import { amendSubjectRef, engineFailureRef } from './statements.mjs';
|
|
29
|
+
import { emit as wireEmit } from './wire.mjs';
|
|
30
|
+
import { WorkspaceRegistry } from './registry.mjs';
|
|
31
|
+
import { homeOf } from './paths.mjs';
|
|
32
|
+
import { HomeBoard } from './home.mjs';
|
|
29
33
|
|
|
30
34
|
import { createOatheTools } from './mcp/oathe-tools.mjs';
|
|
31
|
-
import {
|
|
35
|
+
import { renderEvidenceView, sliceForTask } from './atif.mjs';
|
|
36
|
+
import { projectorFor } from './harnesses/catalog.mjs';
|
|
32
37
|
import { verificationTaskId, isVerificationTask, ACCEPTANCE_CLAUSE_KEY } from './plans.mjs';
|
|
33
38
|
import { RECORDED_VERDICT_CHECKER } from './runtime/discharge.mjs';
|
|
34
39
|
|
|
@@ -51,7 +56,7 @@ export class Verifier {
|
|
|
51
56
|
* config: import('./config.mjs').OatheConfig, operatorPrincipal: string,
|
|
52
57
|
* engineRunner?: ({engine, prompt}) => Promise<{verdict: string, reason: string}>}} o
|
|
53
58
|
*/
|
|
54
|
-
constructor({ substrate, paths, workspace, config, operatorPrincipal, engineRunner, provider = null }) {
|
|
59
|
+
constructor({ substrate, paths, workspace, config, operatorPrincipal, engineRunner, provider = null, homePathFor = null }) {
|
|
55
60
|
this.substrate = substrate;
|
|
56
61
|
this.paths = paths;
|
|
57
62
|
this.workspace = workspace;
|
|
@@ -59,6 +64,11 @@ export class Verifier {
|
|
|
59
64
|
this.operatorPrincipal = operatorPrincipal;
|
|
60
65
|
this.verifierPrincipal = config.get('verifierPrincipal');
|
|
61
66
|
this.engineRunner = engineRunner ?? defaultEngineRunner;
|
|
67
|
+
// The ONE home resolver (registry rootOf), injectable for tests. The engine judges
|
|
68
|
+
// FROM the task's own folder — its tools are the evidence reader (ruling 2026-08-31);
|
|
69
|
+
// a homeless task judges from the operator's home, never the caller's accidental cwd.
|
|
70
|
+
this.homePathFor = homePathFor
|
|
71
|
+
?? ((homeRef) => new WorkspaceRegistry({ registryPath: paths.registryPath }).rootOf(homeRef));
|
|
62
72
|
this.orgId = config.get('org');
|
|
63
73
|
this.provider = provider;
|
|
64
74
|
this.tools = createOatheTools({
|
|
@@ -109,18 +119,18 @@ export class Verifier {
|
|
|
109
119
|
async #traceEvidence(workClaimId) {
|
|
110
120
|
const { rows } = await this.substrate.query(
|
|
111
121
|
`SELECT subject_ref, evidence_refs FROM cell.agent_statement
|
|
112
|
-
WHERE org_id = $1 AND work_claim_id = $2 AND subject_ref
|
|
122
|
+
WHERE org_id = $1 AND work_claim_id = $2 AND ${isTraceSubjectSql('subject_ref')}`,
|
|
113
123
|
[this.orgId, workClaimId]);
|
|
114
124
|
const traces = [];
|
|
115
125
|
for (const row of rows) {
|
|
116
126
|
for (const file of row.evidence_refs) {
|
|
117
|
-
traces.push({ path: file, trajectory: projectorFor(file).project(file) });
|
|
127
|
+
traces.push({ path: file, trajectory: (await projectorFor(file)).project(file) });
|
|
118
128
|
}
|
|
119
129
|
}
|
|
120
130
|
return traces;
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
#prompt({ taskRow, completion, traces, taskId }) {
|
|
133
|
+
#prompt({ taskRow, completion, traces, taskId, amendments = [] }) {
|
|
124
134
|
const budget = this.config.get('verifierEvidenceBudget');
|
|
125
135
|
const perTrace = Math.max(1, Math.floor(budget / Math.max(1, traces.length)));
|
|
126
136
|
return [
|
|
@@ -129,12 +139,19 @@ export class Verifier {
|
|
|
129
139
|
'own claims; CLAIM lines are its on-the-record speech acts; DID lines are the actions it',
|
|
130
140
|
'actually took; GOT lines are what actually came back. Judge claims against actions and',
|
|
131
141
|
'outcomes — be strict: absence of evidence is absence.',
|
|
142
|
+
'You are running in the task\'s workspace — check asserted artifacts against the files on disk.',
|
|
132
143
|
'',
|
|
133
144
|
`TASK: ${taskId}`,
|
|
134
145
|
`OBJECTIVE: ${taskRow.objective}`,
|
|
135
146
|
`VERIFICATION PLAN: ${JSON.stringify(taskRow.verification_plan)}`,
|
|
136
147
|
`COMPLETION ASSERTION: ${completion.proposition}`,
|
|
137
148
|
`ASSERTED EVIDENCE: ${JSON.stringify(completion.evidence_refs)}`,
|
|
149
|
+
...(amendments.length === 0 ? [] : [
|
|
150
|
+
'',
|
|
151
|
+
`AMENDMENT TRAIL (${amendments.length} — the definition of done MOVED, with sign-off;`,
|
|
152
|
+
'judge the CURRENT objective above; a late or convenient move is itself evidence to weigh):',
|
|
153
|
+
...amendments.map((a) => `- [${new Date(a.asserted_at).toISOString()}] ${a.proposition}`),
|
|
154
|
+
]),
|
|
138
155
|
'',
|
|
139
156
|
`SESSION TRACES (${traces.length}, sliced to this task's claim intervals where recorded):`,
|
|
140
157
|
...traces.map(({ trajectory }) => renderEvidenceView(sliceForTask(trajectory, taskId), { budget: perTrace })),
|
|
@@ -166,22 +183,58 @@ export class Verifier {
|
|
|
166
183
|
// 1. Claim the review — the verifier principal takes visible responsibility for it.
|
|
167
184
|
const vclaim = await this.tools.oathe_claim({ task_id: verificationTask });
|
|
168
185
|
|
|
169
|
-
// 2.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
// 2-3. EVERYTHING between the claim and a durable verdict runs under the release
|
|
187
|
+
// guard (ruling 2026-08-31: ANY exit before a verdict fails loud and frees the claim
|
|
188
|
+
// — an unreadable trace once killed a run OUTSIDE the old engine-only guard and left
|
|
189
|
+
// the twin wedged behind its lease, caught live). Evidence-gathering and the engine
|
|
190
|
+
// fail the same way: durable statement, yield, verify_failed on the wire.
|
|
191
|
+
let raw;
|
|
192
|
+
let completion;
|
|
193
|
+
let taskRows;
|
|
194
|
+
let traces;
|
|
195
|
+
try {
|
|
196
|
+
completion = await this.#completionStatement(originalTask);
|
|
197
|
+
({ rows: taskRows } = await this.substrate.query(
|
|
198
|
+
`SELECT objective, verification_plan, ${HomeBoard.homeSql('t')} AS home
|
|
199
|
+
FROM cell.task t WHERE org_id = $1 AND task_id = $2`,
|
|
200
|
+
[this.orgId, originalTask]));
|
|
201
|
+
// The engine judges FROM the task's workspace — its own tools read the evidence on
|
|
202
|
+
// disk. One resolver (registry rootOf); a homeless task judges from the operator's home.
|
|
203
|
+
const taskHome = this.homePathFor(taskRows[0]?.home) ?? homeOf();
|
|
204
|
+
traces = await this.#traceEvidence(completion.work_claim_id);
|
|
205
|
+
// R-AMEND: the amendment trail is part of the record — the engine judges the CURRENT
|
|
206
|
+
// objective and SEES every move of the bar (a late amendment is visible evidence).
|
|
207
|
+
const { rows: amendments } = await this.substrate.query(
|
|
208
|
+
`SELECT proposition, asserted_at FROM cell.agent_statement
|
|
209
|
+
WHERE org_id = $1 AND task_id = $2 AND subject_ref = $3
|
|
210
|
+
ORDER BY asserted_at`,
|
|
211
|
+
[this.orgId, originalTask, amendSubjectRef(originalTask)]);
|
|
212
|
+
raw = await this.engineRunner({
|
|
213
|
+
engine,
|
|
214
|
+
cwd: taskHome,
|
|
215
|
+
prompt: this.#prompt({ taskRow: taskRows[0], completion, traces, taskId: originalTask, amendments }),
|
|
216
|
+
});
|
|
217
|
+
if (!raw || !VERDICTS.includes(raw.verdict) || typeof raw.reason !== 'string' || raw.reason.trim() === '') {
|
|
218
|
+
throw new VerifierError('OATHE_VERDICT_MALFORMED',
|
|
219
|
+
`the ${engine} engine returned ${JSON.stringify(raw)} — a verdict is exactly `
|
|
220
|
+
+ `{verdict: ${VERDICTS.join('|')}, reason} and the lane never guesses`, { raw, engine });
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
try {
|
|
224
|
+
await this.tools.oathe_statement({
|
|
225
|
+
task_id: verificationTask,
|
|
226
|
+
proposition: `engine ${engine} failed before a verdict: ${String(e?.message ?? e).slice(0, 400)}`,
|
|
227
|
+
evidence_ref: engineFailureRef(engine),
|
|
228
|
+
});
|
|
229
|
+
await this.tools.oathe_yield({
|
|
230
|
+
task_id: verificationTask,
|
|
231
|
+
note: `engine ${engine} died — released for retry: oathe verify ${originalTask} --engine <another>`,
|
|
232
|
+
});
|
|
233
|
+
} catch { /* best-effort release — the primary failure must surface either way */ }
|
|
234
|
+
// The glass hears the failure too (fail-soft inside emit): named by the ORIGINAL
|
|
235
|
+
// task — the row a person is looking at — so retry is one act, not archaeology.
|
|
236
|
+
await wireEmit(this.substrate, { kind: 'verify_failed', task_id: originalTask, via: engine });
|
|
237
|
+
throw e;
|
|
185
238
|
}
|
|
186
239
|
|
|
187
240
|
// 4. The verdict becomes durable: the verification task's completion statement.
|
|
@@ -225,16 +278,28 @@ export class Verifier {
|
|
|
225
278
|
{ checker: RECORDED_VERDICT_CHECKER, oathe_recorded_verdict: raw.verdict }),
|
|
226
279
|
}, { settle: SETTLE.CLAIM });
|
|
227
280
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
281
|
+
let settledNow = outcome.settled === true;
|
|
282
|
+
if (!settledNow) {
|
|
283
|
+
// `settle_work_claim` answers false for an ALREADY-settled claim (idempotency) exactly as it
|
|
284
|
+
// does for a refused one. A prior run killed after its settle must read as recovery — the
|
|
285
|
+
// claim row knows (a re-run otherwise wedged forever, burning an engine run per retry).
|
|
286
|
+
const { rows: settledRows } = await this.substrate.query(
|
|
287
|
+
'SELECT settled_at FROM cell.work_claim WHERE work_claim_id = $1', [completion.work_claim_id]);
|
|
288
|
+
settledNow = settledRows[0]?.settled_at != null;
|
|
289
|
+
if (!settledNow && (outcome.verification?.verdict === 'blocked' || raw.verdict === 'accepted')) {
|
|
290
|
+
throw new VerifierError('OATHE_SETTLEMENT_BLOCKED',
|
|
291
|
+
`the acceptance lane did not settle an ACCEPTED verdict: ${JSON.stringify(outcome.verification)}`,
|
|
292
|
+
{ outcome });
|
|
293
|
+
}
|
|
232
294
|
}
|
|
233
295
|
|
|
234
296
|
// 6. R8: a rejection reopens the work, through the evaluator lane's own verb.
|
|
235
297
|
if (raw.verdict === 'rejected') {
|
|
236
298
|
await this.substrate.query('SELECT cell.reopen_rejected_task($1, $2)', [this.orgId, originalTask]);
|
|
237
299
|
}
|
|
300
|
+
// The wire hears the verdict the moment it lands (fail-soft inside emit — the settlement
|
|
301
|
+
// stands whatever the wire does; the notch otherwise catches up on its heartbeat).
|
|
302
|
+
await wireEmit(this.substrate, { kind: raw.verdict === 'rejected' ? 'rejected' : 'settled', task_id: originalTask });
|
|
238
303
|
|
|
239
304
|
// 7. The review itself settles under the OPERATOR seat (non-author of the verdict statement).
|
|
240
305
|
const verdictStatement = await this.#completionStatement(verificationTask);
|
|
@@ -257,7 +322,7 @@ export class Verifier {
|
|
|
257
322
|
engine,
|
|
258
323
|
verdict: raw.verdict,
|
|
259
324
|
reason: raw.reason,
|
|
260
|
-
settled:
|
|
325
|
+
settled: settledNow,
|
|
261
326
|
reopened: raw.verdict === 'rejected',
|
|
262
327
|
verdict_ref: verdictRef,
|
|
263
328
|
verification_claim: vclaim.work_claim_id,
|
|
@@ -279,17 +344,43 @@ export class Verifier {
|
|
|
279
344
|
}
|
|
280
345
|
|
|
281
346
|
/** The real engine runner: one headless run, strict JSON out. Refusals are typed and loud. */
|
|
282
|
-
export async function defaultEngineRunner({ engine, prompt, env = process.env, model = null }) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const command = commands[engine];
|
|
288
|
-
if (!command) {
|
|
347
|
+
export async function defaultEngineRunner({ engine, prompt, env = process.env, model = null, cwd = undefined }) {
|
|
348
|
+
// The command line and output shape are each engine adapter's own facts (src/harnesses/).
|
|
349
|
+
const { byName, verifierCapable } = await import('./harnesses/catalog.mjs');
|
|
350
|
+
const known = verifierCapable();
|
|
351
|
+
if (!known.includes(engine)) {
|
|
289
352
|
throw new VerifierError('OATHE_ENGINE_UNKNOWN',
|
|
290
|
-
`no engine '${engine}' — known engines: ${
|
|
353
|
+
`no engine '${engine}' — known engines: ${known.join(', ')}`, { engine });
|
|
291
354
|
}
|
|
292
|
-
const
|
|
355
|
+
const adapter = byName(engine);
|
|
356
|
+
const command = adapter.headless.command(prompt, model);
|
|
357
|
+
// async spawn — a minutes-long engine run must never halt the event loop (spawnSync froze the
|
|
358
|
+
// whole MCP server, ping included, before the dispatcher existed; the sync bin path gains the
|
|
359
|
+
// same hygiene for free).
|
|
360
|
+
const run = await new Promise((resolve) => {
|
|
361
|
+
// stdin 'ignore': the engine gets immediate EOF (codex exec drains stdin before answering;
|
|
362
|
+
// spawnSync closed it implicitly — an open default pipe hung two live runs, 2026-08-30).
|
|
363
|
+
const child = spawn(command[0], command[1], { env, cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
364
|
+
let stdout = '';
|
|
365
|
+
let stderr = '';
|
|
366
|
+
let settled = false;
|
|
367
|
+
// Resolve on EXIT (with a short drain grace), not only on 'close': an engine's backgrounded
|
|
368
|
+
// helper can inherit the stdio pipes, and then 'close' never fires — a detached verify sat
|
|
369
|
+
// at 0% CPU for 20 minutes after codex finished (live, 2026-08-30). Destroying the streams
|
|
370
|
+
// releases the inherited-pipe fds so the loop is never pinned either.
|
|
371
|
+
const finish = (result) => {
|
|
372
|
+
if (settled) return;
|
|
373
|
+
settled = true;
|
|
374
|
+
child.stdout.destroy();
|
|
375
|
+
child.stderr.destroy();
|
|
376
|
+
resolve(result);
|
|
377
|
+
};
|
|
378
|
+
child.stdout.on('data', (d) => { if (stdout.length < 32 * 1024 * 1024) stdout += d; });
|
|
379
|
+
child.stderr.on('data', (d) => { if (stderr.length < 1024 * 1024) stderr += d; });
|
|
380
|
+
child.on('error', (error) => finish({ error, status: null, stdout, stderr }));
|
|
381
|
+
child.on('close', (status) => finish({ status, stdout, stderr }));
|
|
382
|
+
child.on('exit', (status) => { setTimeout(() => finish({ status, stdout, stderr }), 500).unref(); });
|
|
383
|
+
});
|
|
293
384
|
if (run.error) {
|
|
294
385
|
throw new VerifierError('OATHE_ENGINE_MISSING',
|
|
295
386
|
`the '${engine}' CLI is not installed or not on PATH — verification needs a real engine `
|
|
@@ -297,16 +388,13 @@ export async function defaultEngineRunner({ engine, prompt, env = process.env, m
|
|
|
297
388
|
}
|
|
298
389
|
if (run.status !== 0) {
|
|
299
390
|
throw new VerifierError('OATHE_ENGINE_FAILED',
|
|
300
|
-
`${engine} exited ${run.status}: ${String(run.stderr ?? '').slice(
|
|
391
|
+
`${engine} exited ${run.status}; stderr tail: ${String(run.stderr ?? '').trim().slice(-300)}`, { engine, status: run.status });
|
|
301
392
|
}
|
|
302
|
-
let text
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
throw new VerifierError('OATHE_ENGINE_OUTPUT_MALFORMED',
|
|
308
|
-
'claude --output-format json did not return JSON', { engine });
|
|
309
|
-
}
|
|
393
|
+
let text;
|
|
394
|
+
try {
|
|
395
|
+
text = adapter.headless.extract(run.stdout);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
throw new VerifierError('OATHE_ENGINE_OUTPUT_MALFORMED', e.message, { engine });
|
|
310
398
|
}
|
|
311
399
|
const match = String(text).match(/\{[^{}]*"verdict"[^{}]*\}/g);
|
|
312
400
|
if (!match) {
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// oathe — the verification dispatcher. `oathe_verify` over MCP never runs the engine in the
|
|
2
|
+
// server: it launches the existing `oathe verify` bin verb as a DETACHED process (its own
|
|
3
|
+
// group, unref'd — it survives the session; a deliberate, documented exception to the cage's
|
|
4
|
+
// containment) and answers immediately with the durable addresses. Concurrency stays the
|
|
5
|
+
// substrate's: the child claims `verify:<task>` before its engine runs, so a concurrent loser
|
|
6
|
+
// exits on FC003 pre-engine. The only pre-spawn read exists so a live in-flight review is a
|
|
7
|
+
// TYPED refusal naming the holder — never a lying {started: true}. No auto-heal: an expired
|
|
8
|
+
// lease names the manual fix (`oathe yield`) and stops.
|
|
9
|
+
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
13
|
+
|
|
14
|
+
import { isVerificationTask, verificationTaskId } from './plans.mjs';
|
|
15
|
+
import { isEngineFailureSql } from './statements.mjs';
|
|
16
|
+
import { pidAlive } from './sessions.mjs';
|
|
17
|
+
|
|
18
|
+
export class VerifyDispatchError extends Error {
|
|
19
|
+
constructor(code, message, details = {}) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'VerifyDispatchError';
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.details = details;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The env the child gets: the caller's, minus the judged session's provenance stamps —
|
|
28
|
+
* otherwise the verifier's own statements carry the attempt id of the very execution under
|
|
29
|
+
* judgment. */
|
|
30
|
+
function scrubbedEnv(env) {
|
|
31
|
+
const child = { ...env };
|
|
32
|
+
delete child.OATHE_EXECUTION_ATTEMPT_ID;
|
|
33
|
+
delete child.OATHE_LAUNCHED_HARNESS;
|
|
34
|
+
return child;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {{taskId: string, engine?: string, orgId: string,
|
|
39
|
+
* query: (sql: string, params: unknown[]) => Promise<{rows: object[]}>,
|
|
40
|
+
* paths: {packageRoot: string, logsDir: string}, cwd: string, env: object,
|
|
41
|
+
* spawn?: typeof nodeSpawn, clock?: () => Date}} o
|
|
42
|
+
* @returns {Promise<{started: true, task_id: string, verification_task: string, engine: string|null,
|
|
43
|
+
* pid: number, log: string, note: string}>}
|
|
44
|
+
*/
|
|
45
|
+
export async function dispatchVerification({
|
|
46
|
+
taskId, engine = null, orgId, query, paths, cwd, env, spawn = nodeSpawn, clock = () => new Date(),
|
|
47
|
+
}) {
|
|
48
|
+
const verificationTask = isVerificationTask(taskId) ? taskId : verificationTaskId(taskId);
|
|
49
|
+
const originalTask = verificationTask.slice('verify:'.length);
|
|
50
|
+
|
|
51
|
+
const { rows } = await query(
|
|
52
|
+
`SELECT principal_id, state, ownership_valid_until
|
|
53
|
+
FROM cell.work_claim WHERE org_id = $1 AND task_id = $2
|
|
54
|
+
ORDER BY claimed_at DESC LIMIT 1`, [orgId, verificationTask]);
|
|
55
|
+
const latest = rows[0];
|
|
56
|
+
if (latest?.state === 'active') {
|
|
57
|
+
const until = latest.ownership_valid_until ? new Date(latest.ownership_valid_until) : null;
|
|
58
|
+
const expired = until !== null && until < clock();
|
|
59
|
+
throw new VerifyDispatchError('OATHE_VERIFY_IN_FLIGHT',
|
|
60
|
+
expired
|
|
61
|
+
? `a verification of '${originalTask}' is still claimed by ${latest.principal_id} but its `
|
|
62
|
+
+ `lease expired ${until.toISOString()} — likely a dead run; \`oathe yield ${verificationTask}\` `
|
|
63
|
+
+ 'releases it, then dispatch again'
|
|
64
|
+
: `a verification of '${originalTask}' is already running — claimed by ${latest.principal_id}`
|
|
65
|
+
+ `${until ? ` until ${until.toISOString()}` : ''}; its verdict lands on the board`,
|
|
66
|
+
{ verification_task: verificationTask, holder: latest.principal_id, expired });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fs.mkdirSync(paths.logsDir, { recursive: true });
|
|
70
|
+
const log = path.join(paths.logsDir, `verify-${originalTask.replace(/[^A-Za-z0-9._-]+/g, '-')}.log`);
|
|
71
|
+
const logFd = fs.openSync(log, 'w'); // one log per task, overwritten per run — no retention machinery
|
|
72
|
+
let child;
|
|
73
|
+
try {
|
|
74
|
+
child = spawn(process.execPath,
|
|
75
|
+
[path.join(paths.packageRoot, 'bin/oathe.mjs'), 'verify', originalTask, ...(engine ? ['--engine', engine] : [])],
|
|
76
|
+
{ detached: true, cwd, env: scrubbedEnv(env), stdio: ['ignore', logFd, logFd] });
|
|
77
|
+
} finally {
|
|
78
|
+
fs.closeSync(logFd); // the child holds its own copy; the long-lived server must not leak one per dispatch
|
|
79
|
+
}
|
|
80
|
+
child.unref();
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
started: true,
|
|
84
|
+
task_id: originalTask,
|
|
85
|
+
verification_task: verificationTask,
|
|
86
|
+
engine,
|
|
87
|
+
pid: child.pid,
|
|
88
|
+
log,
|
|
89
|
+
note: `verification of '${originalTask}' started in the background as ${verificationTask} — `
|
|
90
|
+
+ 'when it leaves the board the claim settled; a rejection reopens the task with the reason '
|
|
91
|
+
+ `recorded on ${verificationTask}'s completion statement. Engine log: ${log}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* AWAIT a dispatched judgment's outcome from the substrate — the blocking half of the
|
|
97
|
+
* local rule. The engine still runs in its own detached process; this only reads. The
|
|
98
|
+
* wait is bounded by the CHILD'S OWN LIFE, never an arbitrary budget: verdict recorded →
|
|
99
|
+
* the answer; failure statement recorded → the failure; child dead with neither (one
|
|
100
|
+
* last read closes the exit race) → a typed failed outcome naming the retry.
|
|
101
|
+
* @returns {Promise<{verdict: 'accepted'|'rejected', reason: string}
|
|
102
|
+
* |{failed: true, reason: string}>}
|
|
103
|
+
*/
|
|
104
|
+
export async function awaitVerdict({
|
|
105
|
+
taskId, pid, orgId, query, since,
|
|
106
|
+
pollMs = 1000, isAlive = pidAlive, sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
107
|
+
}) {
|
|
108
|
+
const verificationTask = isVerificationTask(taskId) ? taskId : verificationTaskId(taskId);
|
|
109
|
+
const originalTask = verificationTask.slice('verify:'.length);
|
|
110
|
+
let lastChance = false;
|
|
111
|
+
for (;;) {
|
|
112
|
+
const { rows } = await query(
|
|
113
|
+
`SELECT v.result, s.proposition
|
|
114
|
+
FROM cell.verification v
|
|
115
|
+
LEFT JOIN LATERAL (
|
|
116
|
+
SELECT st.proposition FROM cell.agent_statement st
|
|
117
|
+
WHERE st.org_id = v.org_id AND st.task_id = $3 AND st.statement_type = 'completion'
|
|
118
|
+
ORDER BY st.asserted_at DESC LIMIT 1) s ON true
|
|
119
|
+
WHERE v.org_id = $1 AND v.task_id = $2 AND v.recorded_at > $4
|
|
120
|
+
ORDER BY v.recorded_at DESC LIMIT 1`,
|
|
121
|
+
[orgId, originalTask, verificationTask, since]);
|
|
122
|
+
if (rows[0]) {
|
|
123
|
+
return {
|
|
124
|
+
verdict: rows[0].result === 'rejected' ? 'rejected' : 'accepted',
|
|
125
|
+
// The verdict statement reads "accepted: <reason>" / "rejected: <reason>" — hand back the reason.
|
|
126
|
+
reason: String(rows[0].proposition ?? '').replace(/^(accepted|rejected):\s*/, '') || rows[0].result,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// The failure is only REPORTABLE once the dead run has RELEASED its claim — returning
|
|
130
|
+
// on the statement alone raced the child's yield and handed the caller a twin still
|
|
131
|
+
// holding the lock (a retry dispatched in that beat read IN_FLIGHT — caught live).
|
|
132
|
+
const { rows: twin } = await query(
|
|
133
|
+
`SELECT state FROM cell.work_claim WHERE org_id = $1 AND task_id = $2
|
|
134
|
+
ORDER BY claimed_at DESC LIMIT 1`, [orgId, verificationTask]);
|
|
135
|
+
if (twin[0] && twin[0].state !== 'active') {
|
|
136
|
+
const { rows: fail } = await query(
|
|
137
|
+
`SELECT proposition FROM cell.agent_statement
|
|
138
|
+
WHERE org_id = $1 AND task_id = $2 AND asserted_at > $3
|
|
139
|
+
AND ${isEngineFailureSql('evidence_refs')}
|
|
140
|
+
ORDER BY asserted_at DESC LIMIT 1`,
|
|
141
|
+
[orgId, verificationTask, since]);
|
|
142
|
+
if (fail[0]) return { failed: true, reason: fail[0].proposition };
|
|
143
|
+
}
|
|
144
|
+
if (lastChance) {
|
|
145
|
+
return {
|
|
146
|
+
failed: true,
|
|
147
|
+
reason: `the verifier (pid ${pid}) died without recording a verdict — retry: oathe verify ${originalTask}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (!isAlive(pid)) { lastChance = true; continue; } // one final read closes the wrote-then-exited race
|
|
151
|
+
await sleep(pollMs);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* THE verifier seam — how a serving tool surface runs a verification, and WHERE topology
|
|
157
|
+
* decides the blocking rule (founder ruling 2026-08-31: the trust boundary is the blocking
|
|
158
|
+
* boundary). A LOCAL substrate owes the answer in-call — dispatch the detached child, then
|
|
159
|
+
* await its verdict; when the substrate is REMOTE (the cloud), this seam is the one place
|
|
160
|
+
* that flips to dispatch-and-return. Never an engine inside the server either way.
|
|
161
|
+
*/
|
|
162
|
+
export function verifierSeam({ orgId, query, paths, cwd, env = process.env }) {
|
|
163
|
+
return async ({ taskId, engine = null }) => {
|
|
164
|
+
const since = new Date().toISOString();
|
|
165
|
+
const out = await dispatchVerification({ taskId, engine, orgId, query, paths, cwd, env });
|
|
166
|
+
const outcome = await awaitVerdict({ taskId, pid: out.pid, orgId, query, since });
|
|
167
|
+
return { ...outcome, log: out.log };
|
|
168
|
+
};
|
|
169
|
+
}
|
package/src/welcome.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// oathe — the one-time welcome. Init plants the marker when it CREATES the database;
|
|
2
|
+
// the serve feed consumes it after a successful frame build and rides the lines on that
|
|
3
|
+
// frame. Consume-on-emit is a ruling: the glass has no ack channel (its stdin to the feed
|
|
4
|
+
// is write-never), so a play lost to a dying app is accepted one-shot loss — the
|
|
5
|
+
// alternative, replay-on-every-KeepAlive-restart, would lie louder. `oathe notch
|
|
6
|
+
// --welcome` is the free replay. Presence is the fact: consume never parses the marker,
|
|
7
|
+
// so a corrupt file has no failure mode.
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
/** The founder copy, verbatim (2026-08-31) — product code, not a tunable. */
|
|
13
|
+
export const WELCOME_LINES = Object.freeze([
|
|
14
|
+
'welcome to oathe',
|
|
15
|
+
"I'll list your session statuses here.",
|
|
16
|
+
'you can click to expand in the future.',
|
|
17
|
+
"let's build something great today",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
/** Plant the pending marker. Idempotent — planting over a pending marker is still one welcome. */
|
|
21
|
+
export function plantWelcome({ paths, by = 'init' }) {
|
|
22
|
+
fs.mkdirSync(path.dirname(paths.welcomePath), { recursive: true });
|
|
23
|
+
fs.writeFileSync(paths.welcomePath, `${JSON.stringify({ planted_at: new Date().toISOString(), by })}\n`);
|
|
24
|
+
return { file: paths.welcomePath };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Take the one shot: the lines if a marker was pending (clearing it), else null. */
|
|
28
|
+
export function consumeWelcome({ paths }) {
|
|
29
|
+
if (!fs.existsSync(paths.welcomePath)) return null;
|
|
30
|
+
fs.rmSync(paths.welcomePath, { force: true });
|
|
31
|
+
return { lines: [...WELCOME_LINES] };
|
|
32
|
+
}
|