@oathe/oathe 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +3 -4
- package/README.md +15 -45
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +397 -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 +154 -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/speaker.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// oathe — the SPEAKER primitive (founder ruling 2026-08-30): every speech act is spoken by
|
|
2
|
+
// someone, and the writer resolves WHO from its own process ancestry — never from the
|
|
3
|
+
// model's word, never from a client's self-declared name when the process tree says more
|
|
4
|
+
// (ChatGPT-embedded codex is 'chatgpt', not 'codex'). One resolution, one shape:
|
|
5
|
+
//
|
|
6
|
+
// { surface: string|null — which glass is speaking, named by the adapters
|
|
7
|
+
// app: {bundle,pid}|null — the focusable app above the speaker (the switch target)
|
|
8
|
+
// session: {sessionId, transcriptPath|null, harness}|null — the registered harness
|
|
9
|
+
// session this process speaks FOR, found by the parent chain in the device's
|
|
10
|
+
// session registry (~/.oathe/sessions.json) }
|
|
11
|
+
//
|
|
12
|
+
// Each field is observed truth or null: a bare terminal has no session; a desktop surface
|
|
13
|
+
// with no hooks has surface + app but no session. Observation gaps (ps failing, no registry
|
|
14
|
+
// file) resolve to nulls; a MALFORMED registry refuses typed through load() — a broken
|
|
15
|
+
// invariant is never smoothed over (no fail-soft outside hooks).
|
|
16
|
+
//
|
|
17
|
+
// The two homes this primitive spans (cloud posture, founder ruling): the substrate keeps
|
|
18
|
+
// the PORTABLE fact (which session spoke — written by linkTrace at the act); this device's
|
|
19
|
+
// sessions.json keeps the DEVICE fact (which process embodies it now).
|
|
20
|
+
|
|
21
|
+
import { processAncestry, nearestAppBundle, SessionRegistry } from './sessions.mjs';
|
|
22
|
+
import { surfaceForSession, harnessForClient, ownerOfTracePath, ownedAncestorIndex, HARNESS_CLASSES } from './harnesses/catalog.mjs';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {{pid?: number, sessionsPath: string, clientName?: string|null,
|
|
26
|
+
* exec?: object, platform?: string}} o — exec/platform are test seams for the walk
|
|
27
|
+
* @returns {{surface: string|null, app: {bundle: string, pid: number}|null,
|
|
28
|
+
* session: {sessionId: string, transcriptPath: string|null, harness: string}|null}}
|
|
29
|
+
*/
|
|
30
|
+
export function resolveSpeaker({ pid = process.pid, sessionsPath, clientName = null, exec, platform } = {}) {
|
|
31
|
+
const walk = processAncestry({
|
|
32
|
+
pid,
|
|
33
|
+
...(exec !== undefined && { exec }),
|
|
34
|
+
...(platform !== undefined && { platform }),
|
|
35
|
+
});
|
|
36
|
+
const hit = sessionsPath ? new SessionRegistry({ sessionsPath }).byAncestry(walk) : null;
|
|
37
|
+
if (hit) {
|
|
38
|
+
const { row } = hit;
|
|
39
|
+
const ownedRow = ownedAncestorIndex(row.ancestry ?? []);
|
|
40
|
+
const harnessExec = (ownedRow === -1 ? row.ancestry?.[0]?.exec : row.ancestry[ownedRow].exec) ?? '';
|
|
41
|
+
return {
|
|
42
|
+
surface: surfaceForSession({ ancestry: row.ancestry ?? [], app: row.app ?? null, transcriptPath: row.transcript_path ?? null })
|
|
43
|
+
?? harnessForClient(clientName),
|
|
44
|
+
app: row.app ?? nearestAppBundle(walk),
|
|
45
|
+
session: {
|
|
46
|
+
sessionId: hit.sessionId,
|
|
47
|
+
transcriptPath: row.transcript_path ?? null,
|
|
48
|
+
// The adapter that owns the session: its trace store first, else its own process.
|
|
49
|
+
harness: ownerOfTracePath(row.transcript_path ?? '')
|
|
50
|
+
?? HARNESS_CLASSES.find((C) => C.surfaces?.ownsExec(harnessExec))?.harnessName
|
|
51
|
+
?? harnessForClient(clientName),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// No registered session — name what the chain itself shows, sliced at the nearest
|
|
56
|
+
// adapter-owned ancestor (the harness above us); the client's word is the last fallback.
|
|
57
|
+
const owned = ownedAncestorIndex(walk);
|
|
58
|
+
const ancestry = owned === -1 ? walk : walk.slice(owned);
|
|
59
|
+
const app = nearestAppBundle(ancestry);
|
|
60
|
+
return {
|
|
61
|
+
surface: (owned === -1 ? null : surfaceForSession({ ancestry, app })) ?? harnessForClient(clientName),
|
|
62
|
+
app,
|
|
63
|
+
session: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// oathe — the statement vocabulary shared across the tree. Two facts live here and nowhere
|
|
2
|
+
// else: the subject_ref grammar of a TRACE-LINKAGE statement ('trace:<session_id>', written by
|
|
3
|
+
// the heartbeat hook, read by the verifier and the CLI), and the SQL that finds a claim's
|
|
4
|
+
// latest PROGRESS statement in the holder's own words — trace links excluded, because a
|
|
5
|
+
// heartbeat is custody evidence, not a word from the holder (the board and the pager both
|
|
6
|
+
// read "last word" through this one fragment).
|
|
7
|
+
|
|
8
|
+
export const TRACE_SUBJECT_PREFIX = 'trace:';
|
|
9
|
+
|
|
10
|
+
/** The subject_ref of the statement linking a session transcript to a claim. */
|
|
11
|
+
export function traceSubjectRef(sessionId) {
|
|
12
|
+
return `${TRACE_SUBJECT_PREFIX}${sessionId}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** SQL predicate on a subject_ref column: is this a trace-linkage statement? */
|
|
16
|
+
export function isTraceSubjectSql(column) {
|
|
17
|
+
return `${column} LIKE '${TRACE_SUBJECT_PREFIX}%'`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* THE trace-link writer — attribution rides the speech act (SPEAKER primitive, founder
|
|
22
|
+
* ruling 2026-08-30). Links `session` to the principal's open claim on `taskId`:
|
|
23
|
+
* one link per claim × session, idempotent by (work_claim_id, subject_ref), so the write
|
|
24
|
+
* wrapper stamps it at the act and the turn-end heartbeat's sweep is a no-op for it.
|
|
25
|
+
* A session with no transcript store (cursor) attributes with empty evidence — honestly.
|
|
26
|
+
* No open claim of this principal on the task → nothing to link, {linked: false}.
|
|
27
|
+
* Failures THROW — attribution is part of the act, not a courtesy (retries are idempotent).
|
|
28
|
+
* @param {{client: {query: Function}, identity: {orgId: string, principalId: string},
|
|
29
|
+
* taskId: string, session: {sessionId: string, transcriptPath: string|null, harness: string|null}}} o
|
|
30
|
+
* @returns {Promise<{linked: boolean}>}
|
|
31
|
+
*/
|
|
32
|
+
export async function linkTrace({ client, identity, taskId, session }) {
|
|
33
|
+
const { rows } = await client.query(
|
|
34
|
+
`SELECT work_claim_id FROM cell.work_claim
|
|
35
|
+
WHERE org_id = $1 AND principal_id = $2 AND task_id = $3 AND settled_at IS NULL
|
|
36
|
+
AND state IN ('active', 'completion_asserted')
|
|
37
|
+
ORDER BY claimed_at DESC LIMIT 1`,
|
|
38
|
+
[identity.orgId, identity.principalId, taskId]);
|
|
39
|
+
if (rows.length === 0) return { linked: false };
|
|
40
|
+
const { randomUUID } = await import('node:crypto');
|
|
41
|
+
const transcript = session.transcriptPath ?? null;
|
|
42
|
+
await client.query(
|
|
43
|
+
`INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
|
|
44
|
+
execution_actor, claim_principal, statement_type, subject_ref, proposition,
|
|
45
|
+
evidence_refs, epistemic_status, asserted_at)
|
|
46
|
+
SELECT $1, $2, $3, $4, $5, $6, 'progress', $7, $8, $9::jsonb, 'observed', now()
|
|
47
|
+
WHERE NOT EXISTS (
|
|
48
|
+
SELECT 1 FROM cell.agent_statement
|
|
49
|
+
WHERE org_id = $2 AND work_claim_id = $4 AND subject_ref = $7)`,
|
|
50
|
+
[randomUUID(), identity.orgId, taskId, rows[0].work_claim_id,
|
|
51
|
+
`session:${session.sessionId}`, identity.principalId, traceSubjectRef(session.sessionId),
|
|
52
|
+
`${session.harness ?? 'unknown'} session ${session.sessionId} worked this claim`
|
|
53
|
+
+ (transcript ? ` — transcript at ${transcript} (fan-out derived at read time)` : ' — no transcript store (this surface keeps none)'),
|
|
54
|
+
JSON.stringify(transcript ? [transcript] : [])]);
|
|
55
|
+
return { linked: true };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The latest non-trace progress statement of one claim, as a LATERAL body:
|
|
60
|
+
* `LEFT JOIN LATERAL (${latestProgressSql({ task: 't', claim: 'w' })}) p ON true` yields
|
|
61
|
+
* p.proposition / p.asserted_at (NULL when the holder has said nothing yet).
|
|
62
|
+
* @param {{task: string, claim: string}} aliases the cell.task and cell.work_claim aliases in scope
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* The verdict's own words for `task` — the latest completion statement of its verify: twin
|
|
66
|
+
* ("rejected: <reason>" / "accepted: <reason>"). THE owning read for the rejection reason:
|
|
67
|
+
* the pager's breach detail, the tools' attention lines, and the reclaim bundle all consume
|
|
68
|
+
* this one fragment (`task` is a cell.task alias).
|
|
69
|
+
*/
|
|
70
|
+
/** Engine-failure evidence shape: 'engine-failure:<engine>' — a verify child that lost its
|
|
71
|
+
* engine records this on the verify task before releasing its claim. */
|
|
72
|
+
export function engineFailureRef(engine) {
|
|
73
|
+
return `engine-failure:${engine}`;
|
|
74
|
+
}
|
|
75
|
+
export function isEngineFailureSql(column) {
|
|
76
|
+
return `EXISTS (SELECT 1 FROM jsonb_array_elements_text(${column}) er WHERE er LIKE 'engine-failure:%')`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** R-AMEND: the amendment trail's subject shape — 'amend:<task_id>', owned here alone. */
|
|
80
|
+
export const AMEND_SUBJECT_PREFIX = 'amend:';
|
|
81
|
+
export function amendSubjectRef(taskId) {
|
|
82
|
+
return `${AMEND_SUBJECT_PREFIX}${taskId}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function latestVerdictSql({ task }) {
|
|
86
|
+
return `SELECT s.proposition AS verdict, s.asserted_at AS verdict_at
|
|
87
|
+
FROM cell.agent_statement s
|
|
88
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = 'verify:' || ${task}.task_id
|
|
89
|
+
AND s.statement_type = 'completion'
|
|
90
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The latest trace-link statement's transcript path for `task` — the durable record of
|
|
95
|
+
* WHICH SURFACE last worked the claim (the heartbeat writes one per claim × session,
|
|
96
|
+
* transcript path as evidence_refs[0]; ownerOfTracePath maps it to a harness).
|
|
97
|
+
*/
|
|
98
|
+
export function latestTracePathSql({ task }) {
|
|
99
|
+
return `SELECT s.evidence_refs->>0 AS trace_path,
|
|
100
|
+
substr(s.subject_ref, ${TRACE_SUBJECT_PREFIX.length + 1}) AS trace_session_id
|
|
101
|
+
FROM cell.agent_statement s
|
|
102
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = ${task}.task_id
|
|
103
|
+
AND ${isTraceSubjectSql('s.subject_ref')}
|
|
104
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function latestProgressSql({ task, claim }) {
|
|
108
|
+
return `SELECT s.proposition, s.asserted_at FROM cell.agent_statement s
|
|
109
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = ${task}.task_id
|
|
110
|
+
AND s.work_claim_id = ${claim}.work_claim_id
|
|
111
|
+
AND s.statement_type = 'progress' AND NOT (${isTraceSubjectSql('s.subject_ref')})
|
|
112
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
113
|
+
}
|
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) {
|