@oathe/oathe 0.4.3 → 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.
- package/.claude-plugin/marketplace.json +18 -2
- package/README.md +4 -1
- package/bin/oathe.mjs +206 -34
- package/docs/PRIVACY.md +26 -4
- package/notch/Oathe Notch.app/Contents/Info.plist +1 -1
- package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
- package/notch/README.md +4 -3
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +21 -3
- package/plugin/.cursor-plugin/plugin.json +2 -2
- package/plugin/hooks/hooks.json +4 -4
- package/plugin/hooks/lib.mjs +9 -0
- package/plugin/hooks/render-board.mjs +4 -2
- package/src/blocks.mjs +10 -1
- package/src/board-render.mjs +7 -4
- package/src/breach-digest.mjs +75 -10
- package/src/config.mjs +24 -0
- package/src/context.mjs +1 -1
- package/src/device.mjs +106 -0
- package/src/doctor.mjs +110 -9
- package/src/engine-update.mjs +170 -0
- package/src/evidence-discovery.mjs +170 -0
- package/src/fence.mjs +3 -3
- package/src/harnesses/catalog.mjs +46 -4
- package/src/harnesses/claude.mjs +56 -4
- package/src/harnesses/codex-rollout.mjs +110 -21
- package/src/harnesses/codex.mjs +107 -20
- package/src/harnesses/cursor.mjs +31 -18
- package/src/harnesses/harness.mjs +82 -13
- package/src/harnesses/surfaces.mjs +2 -2
- package/src/home.mjs +174 -52
- package/src/init.mjs +27 -2
- package/src/launch.mjs +7 -9
- package/src/launchd.mjs +100 -0
- package/src/manifest.mjs +48 -6
- package/src/mcp/connection.mjs +73 -7
- package/src/mcp/daemon.mjs +123 -0
- package/src/mcp/forwarder.mjs +99 -0
- package/src/mcp/oathe-tools.mjs +392 -145
- package/src/notch-frame.mjs +118 -42
- package/src/notch.mjs +44 -41
- package/src/oathe-annotator.mjs +10 -10
- package/src/pager.mjs +144 -40
- package/src/paths.mjs +1 -0
- package/src/plans.mjs +44 -5
- package/src/registry.mjs +10 -2
- package/src/serve.mjs +82 -0
- package/src/session-host.mjs +1 -1
- package/src/sessions.mjs +39 -8
- package/src/shim.mjs +110 -0
- package/src/speaker.mjs +24 -5
- package/src/statements.mjs +116 -2
- package/src/traces.mjs +61 -19
- package/src/uninstall.mjs +20 -3
- package/src/update.mjs +48 -4
- package/src/verifier.mjs +215 -105
- package/src/verify-dispatch.mjs +86 -32
- package/src/wire.mjs +7 -1
- package/plugin/.mcp.json +0 -10
package/src/mcp/oathe-tools.mjs
CHANGED
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
import { pathToFileURL } from 'node:url';
|
|
14
14
|
import crypto from 'node:crypto';
|
|
15
15
|
|
|
16
|
-
import { standardPlan, verificationTaskId, verificationObjective,
|
|
17
|
-
import { verifierCapable } from '../harnesses/catalog.mjs';
|
|
18
|
-
import { ContractRef, HomeBoard } from '../home.mjs';
|
|
16
|
+
import { standardPlan, verificationTaskId, verificationObjective, systemTaskOf, VERIFICATION_PREFIX } from '../plans.mjs';
|
|
17
|
+
import { verifierCapable, attestationFor, harnessForClient } from '../harnesses/catalog.mjs';
|
|
18
|
+
import { ContractRef, HomeBoard, Pickup, Place, PlaceEvidence } from '../home.mjs';
|
|
19
19
|
import {
|
|
20
|
-
amendSubjectRef, isTraceSubjectSql, latestVerdictSql, latestProgressSql, latestTracePathSql,
|
|
21
|
-
|
|
20
|
+
amendSubjectRef, attributionWhy, holdSql, isTraceSubjectSql, latestVerdictSql, latestProgressSql, latestTracePathSql, linkPlace,
|
|
21
|
+
linkTrace, rejectedIntervalSql,
|
|
22
|
+
spawnParentSql, spawnParentFor, linkSpawn, taskTraceLinksSql,
|
|
22
23
|
} from '../statements.mjs';
|
|
23
24
|
import { Pager } from '../pager.mjs';
|
|
24
25
|
import { KINDS, clipDetail, pullPointer } from '../breach-digest.mjs';
|
|
@@ -174,11 +175,14 @@ export function makeToolDefs() {
|
|
|
174
175
|
* activation — the central-registry seam (src/activation.mjs ActivationSeam): every
|
|
175
176
|
* successful call registers the workspace; oathe_claim activates through the ONE writer.
|
|
176
177
|
* oathe_claim (write intent) activates it, and the claim result discloses what happened.
|
|
177
|
-
* synthetic — the session sits on a synthetic workspace (R-BOARD-SCOPE):
|
|
178
|
-
*
|
|
178
|
+
* synthetic — the session sits on a synthetic workspace (R-BOARD-SCOPE): it serves the full
|
|
179
|
+
* board, and its claims are picked up by the app the speaker was measured under (R-PLACE).
|
|
179
180
|
*/
|
|
180
181
|
export function createOatheTools({
|
|
181
182
|
client, identity, workspace, executionActor, successor, config, verifier, activation, synthetic = false,
|
|
183
|
+
// The directory this surface speaks from (the resolver's `dir`): an app pickup records it as
|
|
184
|
+
// evidence — the ChatGPT project folder its files live in (ruling 2026-09-05).
|
|
185
|
+
dir = null,
|
|
182
186
|
// The SPEAKER primitive (founder ruling 2026-08-30): who is speaking — {surface, app,
|
|
183
187
|
// session} resolved from the writer's own ancestry (src/speaker.mjs). REQUIRED wherever
|
|
184
188
|
// it is consumed: a serving surface (one with the activation seam, whose writes ride the
|
|
@@ -190,59 +194,202 @@ export function createOatheTools({
|
|
|
190
194
|
attention = true,
|
|
191
195
|
}) {
|
|
192
196
|
const { orgId, principalId, department } = identity;
|
|
193
|
-
|
|
197
|
+
// WHERE this surface picks work up (ruling 2026-09-05): a folder session's workspace, else
|
|
198
|
+
// the app the speaker was measured under (the ChatGPT desktop — no folder, the app IS the
|
|
199
|
+
// place); a surface with neither records no place. One answer for the ledger's workspace
|
|
200
|
+
// slot, the claim's receipt, and the place statement every act writes.
|
|
201
|
+
// The PICKUP (src/home.mjs): where this surface picks work up and what it knows — one value,
|
|
202
|
+
// computed once. A work task's claim requires a place (refused before anything is written);
|
|
203
|
+
// a SYSTEM task (a judgment, an update) needs none and records none — it lives where its work does.
|
|
204
|
+
const pickup = Pickup.of({ workspace, synthetic, dir, speaker });
|
|
205
|
+
const placeFor = (taskId) => (systemTaskOf(taskId) !== null ? null : pickup.require(taskId));
|
|
206
|
+
/** A pickup records its place on the interval it began — the claim and the re-seat, nowhere else. */
|
|
207
|
+
async function recordPlace(taskId, workClaimId) {
|
|
208
|
+
const place = placeFor(taskId);
|
|
209
|
+
if (place !== null) await linkPlace({ client, identity, taskId, place, evidence: pickup.evidence, workClaimId });
|
|
210
|
+
return place;
|
|
211
|
+
}
|
|
194
212
|
// The breaches are the pager's conditions read per call — stateless: a line repeats while
|
|
195
213
|
// its condition holds and vanishes when it clears — under the ONE digest (src/breach-
|
|
196
214
|
// digest.mjs): scoped to this board (a synthetic surface sees the machine), grouped,
|
|
197
215
|
// ordered, budgeted. Attention words the fix bucket for the model's response channel —
|
|
198
216
|
// rejected and verify-failed work, the one thing a session can act on now — so a background
|
|
199
217
|
// rejection reaches it at its next act; the SessionStart hook covers new sessions.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
218
|
+
// Every tunable comes from config (src/config.mjs is the ONE place a default is named) —
|
|
219
|
+
// the tools never shadow one with a literal.
|
|
220
|
+
if (!config) {
|
|
221
|
+
throw new OatheToolError('OATHE_TOOLS_NEED_CONFIG',
|
|
222
|
+
'the tools read every tunable (lease, verify_by, the verifier principal, the pager thresholds) from config — pass an OatheConfig');
|
|
203
223
|
}
|
|
204
224
|
const pager = attention ? new Pager({ client, identity, config }) : null;
|
|
205
225
|
const breachesFor = async (machine) => (await pager.digest()).scoped(machine ? null : workspace);
|
|
206
226
|
const attentionLines = async () => {
|
|
207
|
-
|
|
227
|
+
// A judgment in flight is not a breach to act on — a model acting on it would only be
|
|
228
|
+
// refused (OATHE_VERIFY_IN_FLIGHT); attention leaves it to the glass, where it reads verifying.
|
|
229
|
+
const fix = (await breachesFor(synthetic)).filter((row) => KINDS[row.kind].bucket === 'fix' && !row.busy);
|
|
208
230
|
const lines = fix.rows.map((row) => (row.group
|
|
209
231
|
? `spawned under '${row.task_id}': ${row.kind_word} — the children and their verdicts are in `
|
|
210
232
|
+ 'oathe_board.breaches; reclaim each (oathe_claim <child>), retry a failed verify with /oathe:verify <child>'
|
|
211
233
|
: `${row.kind_word}: '${row.task_id}' — ${clipDetail(row.detail)}`
|
|
212
|
-
+ (row.kind === 'reopened' ? ' —
|
|
234
|
+
+ (row.kind === 'reopened' ? ' — your next act on it resumes it with the bundle (or oathe_claim)' : '')));
|
|
213
235
|
const more = pullPointer('attention', fix.more);
|
|
214
236
|
return more ? [...lines, more] : lines;
|
|
215
237
|
};
|
|
216
|
-
const leaseHours = config
|
|
217
|
-
const verifyByHours = config
|
|
238
|
+
const leaseHours = config.get('leaseHours');
|
|
239
|
+
const verifyByHours = config.get('verifyByHours');
|
|
218
240
|
const actor = executionActor
|
|
219
241
|
?? (process.env.OATHE_EXECUTION_ATTEMPT_ID
|
|
220
242
|
? `attempt:${process.env.OATHE_EXECUTION_ATTEMPT_ID}`
|
|
221
243
|
: 'oathe-operator');
|
|
222
244
|
|
|
223
|
-
|
|
245
|
+
/**
|
|
246
|
+
* The verifier engine, named on the record at claim (founder direction 2026-08-25): the
|
|
247
|
+
* statement is the RECORD of what was assigned; at verify, current config wins over it
|
|
248
|
+
* (ruling 2026-09-04, verifier.mjs) so a judgment never wedges on an engine the operator
|
|
249
|
+
* has since replaced. No fallback literal: config names the verifier or the claim refuses.
|
|
250
|
+
*/
|
|
251
|
+
async function bindVerifier(taskId, workClaimId) {
|
|
252
|
+
const verifier = config.get('verifier');
|
|
253
|
+
await client.query(
|
|
254
|
+
`INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
|
|
255
|
+
execution_actor, claim_principal, statement_type, subject_ref, proposition,
|
|
256
|
+
evidence_refs, epistemic_status, asserted_at)
|
|
257
|
+
VALUES ($1, $2, $3, $4, $5, $6, 'observation', $7, $8, $9::jsonb, 'observed', now())`,
|
|
258
|
+
[crypto.randomUUID(), orgId, taskId, workClaimId, actor, principalId,
|
|
259
|
+
`verifier:${verifier}`,
|
|
260
|
+
`verification of this claim is assigned to the ${verifier} engine (bound at claim time)`,
|
|
261
|
+
JSON.stringify([`config:verifier=${verifier}`])]);
|
|
262
|
+
return verifier;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The task's LAST ENDED interval while nobody holds it — 016's own choice of "the interval
|
|
267
|
+
* being resumed" — with whether THAT interval was judged rejected (rejectedIntervalSql:
|
|
268
|
+
* the verification row's statement link, never a clock). Null while a live owner holds
|
|
269
|
+
* the task, or nothing ever ended.
|
|
270
|
+
*/
|
|
271
|
+
async function lastEndedInterval(taskId) {
|
|
272
|
+
const { rows } = await client.query(
|
|
273
|
+
`SELECT w.work_claim_id, w.principal_id, t.origin, ${rejectedIntervalSql({ claim: 'w' })} AS rejected
|
|
274
|
+
FROM cell.work_claim w JOIN cell.task t USING (org_id, task_id)
|
|
275
|
+
WHERE w.org_id = $1 AND w.task_id = $2 AND w.ownership_ended_at IS NOT NULL
|
|
276
|
+
AND NOT EXISTS (SELECT 1 FROM cell.work_claim a
|
|
277
|
+
WHERE a.org_id = w.org_id AND a.task_id = w.task_id AND a.state = 'active')
|
|
278
|
+
ORDER BY w.ownership_ended_at DESC, w.claimed_at DESC, w.work_claim_id LIMIT 1`,
|
|
279
|
+
[orgId, taskId]);
|
|
280
|
+
return rows[0] ?? null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The recovery bundle a reclaim of rejected work carries: what was missed and where the
|
|
285
|
+
* work stood when verification began. Null unless the task's LATEST verdict is a
|
|
286
|
+
* rejection — an acceptance is never "what was missed" (the `accepted: …` reason, 2026-09-04).
|
|
287
|
+
*/
|
|
288
|
+
async function rejectionBundle(taskId) {
|
|
289
|
+
const { rows: verdictRows } = await client.query(
|
|
290
|
+
`SELECT v.verdict FROM cell.task t
|
|
291
|
+
LEFT JOIN LATERAL (${latestVerdictSql({ task: 't' })}) v ON true
|
|
292
|
+
WHERE t.org_id = $1 AND t.task_id = $2`, [orgId, taskId]);
|
|
293
|
+
const verdict = verdictRows[0]?.verdict ?? null;
|
|
294
|
+
if (verdict === null || !verdict.startsWith('rejected')) return null; // the verdict contract's own word (verifier.mjs VERDICTS)
|
|
295
|
+
const { rows: vtask } = await client.query(
|
|
296
|
+
`SELECT created_at FROM cell.task WHERE org_id = $1 AND task_id = '${VERIFICATION_PREFIX}' || $2`, [orgId, taskId]);
|
|
297
|
+
// The holder's own words: progress and completions — never an observation (the verifier
|
|
298
|
+
// binding, the place, a spawn) and never a trace link.
|
|
299
|
+
const { rows: priorWords } = await client.query(
|
|
300
|
+
`SELECT proposition FROM cell.agent_statement s
|
|
301
|
+
WHERE s.org_id = $1 AND s.task_id = $2 AND s.statement_type IN ('progress', 'completion')
|
|
302
|
+
AND NOT ${isTraceSubjectSql('s.subject_ref')}
|
|
303
|
+
ORDER BY s.asserted_at DESC LIMIT 3`, [orgId, taskId]);
|
|
304
|
+
// The task's trace links — the same read the verifier judges from (taskTraceLinksSql),
|
|
305
|
+
// shaped here to a couple of pointers.
|
|
306
|
+
const { rows: traceRows } = await client.query(taskTraceLinksSql(), [orgId, taskId]);
|
|
307
|
+
return {
|
|
308
|
+
reason: verdict,
|
|
309
|
+
verification_started_at: vtask[0]?.created_at ?? null,
|
|
310
|
+
last_statements: priorWords.map((r) => r.proposition),
|
|
311
|
+
trace_refs: [...new Set(traceRows.flatMap((r) => (Array.isArray(r.evidence_refs) ? r.evidence_refs : [])))].slice(0, 2),
|
|
312
|
+
your_options: REJECTION_FORK,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* R8's second half as ONE act: seat the prior interval's principal through the evaluator
|
|
318
|
+
* lane's verb (016 — a transcription: nothing here chooses who; the lease is the task's
|
|
319
|
+
* own verify_by, never the config hours), bind the verifier on the record, and read the
|
|
320
|
+
* seated row back. Only the prior holder may be seated (ruling 2026-09-04): reopened work
|
|
321
|
+
* returns to its last holder; anyone else is told no, and who — never a seat under
|
|
322
|
+
* another's name.
|
|
323
|
+
*/
|
|
324
|
+
async function reseat(taskId, prior) {
|
|
325
|
+
if (prior.principal_id !== principalId) {
|
|
326
|
+
throw new OatheToolError('OATHE_RECLAIM_FOREIGN',
|
|
327
|
+
`'${taskId}' is reopened work that returns to its last holder, ${prior.principal_id} (R8) — `
|
|
328
|
+
+ 'it is not yours to resume; take it by delegation or ask them to yield it',
|
|
329
|
+
{ task_id: taskId, owner: prior.principal_id });
|
|
330
|
+
}
|
|
331
|
+
const workClaimId = crypto.randomUUID();
|
|
332
|
+
const { rows: reclaimed } = await client.query(
|
|
333
|
+
'SELECT cell.reclaim_reopened_task($1, $2, $3, now(), $4) AS seated',
|
|
334
|
+
[orgId, taskId, workClaimId, crypto.randomUUID()]);
|
|
335
|
+
if (reclaimed[0].seated !== true) {
|
|
336
|
+
throw new OatheToolError('OATHE_RECLAIM_REFUSED',
|
|
337
|
+
`'${taskId}' is reopened but could not be resumed (a live owner already holds it)`, { task_id: taskId });
|
|
338
|
+
}
|
|
339
|
+
// The reclaim verb TRANSCRIBES the prior interval's ref and stamps the task's verify_by
|
|
340
|
+
// as the lease — report the row, not our guess.
|
|
341
|
+
const { rows: seated } = await client.query(
|
|
342
|
+
`SELECT contract_ref, to_char(ownership_valid_until AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS lease_until
|
|
343
|
+
FROM cell.work_claim WHERE work_claim_id = $1`, [workClaimId]);
|
|
344
|
+
const verifier = await bindVerifier(taskId, workClaimId);
|
|
345
|
+
await recordPlace(taskId, workClaimId); // a re-seat is a pickup: it says where the work lives now
|
|
346
|
+
return {
|
|
347
|
+
work_claim_id: workClaimId, contract_ref: seated[0].contract_ref, lease: `until ${seated[0].lease_until}`,
|
|
348
|
+
verifier, rejection: await rejectionBundle(taskId),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The prior holder's act on rejected work RESUMES it (ruling 2026-09-04: the verdict hands
|
|
354
|
+
* the work back; the act is the principal speaking). Null while a live owner holds the
|
|
355
|
+
* task, or when its last ended interval is not the rejected one — a yield is a deliberate
|
|
356
|
+
* stop, and nothing but an explicit claim follows it.
|
|
357
|
+
*/
|
|
358
|
+
async function resumeIfRejected(taskId) {
|
|
359
|
+
const prior = await lastEndedInterval(taskId);
|
|
360
|
+
if (!prior?.rejected || prior.origin !== 'reopened') return null;
|
|
361
|
+
return reseat(taskId, prior);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The claim an act speaks against: the live one, else the one a rejection handed back. */
|
|
365
|
+
async function hold(taskId) {
|
|
224
366
|
const { rows } = await client.query(
|
|
225
367
|
`SELECT work_claim_id FROM cell.work_claim
|
|
226
368
|
WHERE org_id = $1 AND task_id = $2 AND state = 'active' LIMIT 1`,
|
|
227
369
|
[orgId, taskId]);
|
|
228
|
-
if (rows.length
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
370
|
+
if (rows.length > 0) return { workClaimId: rows[0].work_claim_id, seat: null };
|
|
371
|
+
const seat = await resumeIfRejected(taskId);
|
|
372
|
+
if (seat) return { workClaimId: seat.work_claim_id, seat };
|
|
373
|
+
throw new OatheToolError('OATHE_NO_ACTIVE_CLAIM',
|
|
374
|
+
`no active claim on '${taskId}' — nothing to speak against`, { task_id: taskId });
|
|
233
375
|
}
|
|
234
376
|
|
|
377
|
+
/** What a response says when the act reclaimed first: the reclaim is on the record, and so is the verdict it answers. */
|
|
378
|
+
const seatFields = (seat) => (seat ? { reclaimed: true, lease: seat.lease, rejection: seat.rejection } : {});
|
|
379
|
+
|
|
235
380
|
let toolMap = {
|
|
236
381
|
async oathe_claim({ task_id, objective }) {
|
|
237
382
|
const { rows: existing } = await client.query(
|
|
238
383
|
'SELECT origin FROM cell.task WHERE org_id = $1 AND task_id = $2', [orgId, task_id]);
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
384
|
+
// The ledger's own field records THIS claim's folder (or `none` for an app pickup) — the
|
|
385
|
+
// place statement recorded at the pickup is the read, and the last pickup is where the
|
|
386
|
+
// work resides (ruling 2026-09-05: no inheritance, no adoption, no rank). A surface that
|
|
387
|
+
// names no place is refused here, before anything is written.
|
|
388
|
+
const place = placeFor(task_id);
|
|
389
|
+
// The ledger slot: a folder pickup's ref; `none` for an app pickup; a system task carries the
|
|
390
|
+
// seat's own workspace (null from a synthetic dir — never a minted id).
|
|
391
|
+
const slot = place === null ? workspace : (place.isFolder ? place.ref : null);
|
|
392
|
+
let contractRef = String(new ContractRef({ workspace: slot, orgId, taskId: task_id }));
|
|
246
393
|
let rejection = null; // the recovery bundle, set on a reclaim of rejected work
|
|
247
394
|
if (existing.length === 0) {
|
|
248
395
|
if (!objective) {
|
|
@@ -258,74 +405,43 @@ export function createOatheTools({
|
|
|
258
405
|
ON CONFLICT DO NOTHING`,
|
|
259
406
|
[orgId, task_id, department, objective, verifyByHours]);
|
|
260
407
|
}
|
|
261
|
-
|
|
408
|
+
let workClaimId = crypto.randomUUID();
|
|
409
|
+
let lease = `${leaseHours} hours`;
|
|
410
|
+
let verifier;
|
|
262
411
|
if (existing[0]?.origin === 'reopened') {
|
|
263
412
|
// R8's second half: reopened work is RESUMED, not re-claimed — the evaluator lane's
|
|
264
|
-
// verb seats the prior interval's principal (the one who answers for this work next)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (reclaimed[0].seated !== true) {
|
|
413
|
+
// verb seats the prior interval's principal (the one who answers for this work next),
|
|
414
|
+
// and only that principal may ask for it.
|
|
415
|
+
const prior = await lastEndedInterval(task_id);
|
|
416
|
+
if (prior === null) {
|
|
269
417
|
throw new OatheToolError('OATHE_RECLAIM_REFUSED',
|
|
270
418
|
`'${task_id}' is reopened but could not be resumed (a live owner already holds it)`,
|
|
271
419
|
{ task_id });
|
|
272
420
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
'SELECT contract_ref FROM cell.work_claim WHERE work_claim_id = $1', [workClaimId]);
|
|
276
|
-
contractRef = seated[0].contract_ref;
|
|
277
|
-
// The recovery bundle: what was missed and where the work stood when verification began.
|
|
278
|
-
const { rows: verdictRows } = await client.query(
|
|
279
|
-
`SELECT v.verdict, v.verdict_at FROM cell.task t
|
|
280
|
-
LEFT JOIN LATERAL (${latestVerdictSql({ task: 't' })}) v ON true
|
|
281
|
-
WHERE t.org_id = $1 AND t.task_id = $2`, [orgId, task_id]);
|
|
282
|
-
const { rows: vtask } = await client.query(
|
|
283
|
-
"SELECT created_at FROM cell.task WHERE org_id = $1 AND task_id = 'verify:' || $2", [orgId, task_id]);
|
|
284
|
-
const { rows: priorWords } = await client.query(
|
|
285
|
-
`SELECT proposition FROM cell.agent_statement s
|
|
286
|
-
WHERE s.org_id = $1 AND s.task_id = $2 AND NOT ${isTraceSubjectSql('s.subject_ref')}
|
|
287
|
-
ORDER BY s.asserted_at DESC LIMIT 3`, [orgId, task_id]);
|
|
288
|
-
const { rows: traceRows } = await client.query(
|
|
289
|
-
`SELECT DISTINCT evidence_refs FROM cell.agent_statement s
|
|
290
|
-
WHERE s.org_id = $1 AND s.task_id = $2 AND ${isTraceSubjectSql('s.subject_ref')}
|
|
291
|
-
ORDER BY evidence_refs LIMIT 2`, [orgId, task_id]);
|
|
292
|
-
rejection = {
|
|
293
|
-
reason: verdictRows[0]?.verdict ?? null,
|
|
294
|
-
verification_started_at: vtask[0]?.created_at ?? null,
|
|
295
|
-
last_statements: priorWords.map((r) => r.proposition),
|
|
296
|
-
trace_refs: traceRows.flatMap((r) => (Array.isArray(r.evidence_refs) ? r.evidence_refs : [])),
|
|
297
|
-
your_options: REJECTION_FORK,
|
|
298
|
-
};
|
|
421
|
+
const seat = await reseat(task_id, prior);
|
|
422
|
+
({ work_claim_id: workClaimId, contract_ref: contractRef, lease, verifier, rejection } = seat);
|
|
299
423
|
} else {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
424
|
+
try {
|
|
425
|
+
await client.query(
|
|
426
|
+
`SELECT cell.claim_work($1, $2, $3, NULL, NULL, $4, $5, 'exclusive',
|
|
427
|
+
now() + make_interval(hours => $6), $7, now(), $8)`,
|
|
428
|
+
[orgId, task_id, workClaimId, principalId, department, leaseHours, contractRef, crypto.randomUUID()]);
|
|
429
|
+
} catch (e) {
|
|
430
|
+
// The substrate's own typed vocabulary (FC003 WORK_ALREADY_CLAIMED, 002_claim.sql) —
|
|
431
|
+
// surfaced as a typed refusal, never a raw pg error a caller sniffs words from.
|
|
432
|
+
if (/^WORK_ALREADY_CLAIMED:/.test(String(e?.message ?? ''))) {
|
|
433
|
+
throw new OatheToolError('OATHE_WORK_ALREADY_CLAIMED', String(e.message), { task_id });
|
|
434
|
+
}
|
|
435
|
+
throw e;
|
|
436
|
+
}
|
|
437
|
+
verifier = await bindVerifier(task_id, workClaimId);
|
|
438
|
+
await recordPlace(task_id, workClaimId);
|
|
304
439
|
}
|
|
305
|
-
// Verifier assignment happens AT CLAIM (founder direction 2026-08-25): the engine that
|
|
306
|
-
// will judge this work is named before the work starts, from config, on the record.
|
|
307
|
-
// No fallback literal: config names the verifier or the claim refuses — never a judge
|
|
308
|
-
// nobody chose.
|
|
309
|
-
const verifier = config.get('verifier');
|
|
310
|
-
await client.query(
|
|
311
|
-
`INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
|
|
312
|
-
execution_actor, claim_principal, statement_type, subject_ref, proposition,
|
|
313
|
-
evidence_refs, epistemic_status, asserted_at)
|
|
314
|
-
VALUES ($1, $2, $3, $4, $5, $6, 'observation', $7, $8, $9::jsonb, 'observed', now())`,
|
|
315
|
-
[crypto.randomUUID(), orgId, task_id, workClaimId, actor, principalId,
|
|
316
|
-
`verifier:${verifier}`,
|
|
317
|
-
`verification of this claim is assigned to the ${verifier} engine (bound at claim time)`,
|
|
318
|
-
JSON.stringify([`config:verifier=${verifier}`])]);
|
|
319
440
|
const effective = ContractRef.parse(contractRef);
|
|
441
|
+
const where = place === null ? 'a judgment lives where its work does' : `it lives at ${place}`;
|
|
320
442
|
const note = existing.length === 0
|
|
321
|
-
?
|
|
322
|
-
|
|
323
|
-
: "task minted at claim — plan_status is honestly 'unknown'; a real cell pages you at verify_by")
|
|
324
|
-
: adopted
|
|
325
|
-
? `existing homeless task claimed and ADOPTED onto this folder's board (${effective.workspace})`
|
|
326
|
-
: effective.isHomeless
|
|
327
|
-
? 'existing homeless task claimed — still homeless (a synthetic surface never adopts)'
|
|
328
|
-
: 'existing task claimed';
|
|
443
|
+
? `task minted at claim — ${where}; plan_status is honestly 'unknown'; a real cell pages you at verify_by`
|
|
444
|
+
: `existing task picked up — ${where}`;
|
|
329
445
|
return {
|
|
330
446
|
claimed: true,
|
|
331
447
|
task_id,
|
|
@@ -333,7 +449,8 @@ export function createOatheTools({
|
|
|
333
449
|
work_claim_id: workClaimId,
|
|
334
450
|
contract_ref: contractRef,
|
|
335
451
|
home: effective.workspace,
|
|
336
|
-
|
|
452
|
+
place: place === null ? null : String(place),
|
|
453
|
+
lease,
|
|
337
454
|
verifier,
|
|
338
455
|
note,
|
|
339
456
|
};
|
|
@@ -343,24 +460,26 @@ export function createOatheTools({
|
|
|
343
460
|
// R-BOARD-SCOPE: scope is a per-surface fact. A synthetic workspace has no folder to
|
|
344
461
|
// lens through, so it serves the full board whatever the caller asked.
|
|
345
462
|
const full = all || synthetic;
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
const
|
|
463
|
+
// Where work lives (ruling 2026-09-05, src/home.mjs): a folder's board = every task some
|
|
464
|
+
// claim picked up HERE (any interval — visibility is history) + every UNCLAIMED task (no
|
|
465
|
+
// claim yet: open work anyone may pick up, visible everywhere). Each row carries its
|
|
466
|
+
// RESIDENCE (the last pickup) and every place.
|
|
467
|
+
const filter = full ? '' : 'AND ($2 = ANY(latest.places) OR cardinality(latest.places) = 0)';
|
|
468
|
+
const params = full ? [orgId] : [orgId, String(Place.workspace(workspace))];
|
|
351
469
|
// ONE row per task: the latest claim in view wins (a task reclaimed after a yield is one
|
|
352
470
|
// task, not a history lesson — statements carry the history).
|
|
353
|
-
const { rows } = await client.query(
|
|
354
|
-
`SELECT task_id, objective, origin, state, principal_id, contract_ref,
|
|
471
|
+
const { rows: raw } = await client.query(
|
|
472
|
+
`SELECT task_id, objective, origin, state, principal_id, contract_ref, place, place_evidence, places, settled_at,
|
|
355
473
|
lease_until, last_progress, last_progress_at, last_word_at, trace_path, trace_session_id, rejected_after,
|
|
356
|
-
parent, parent_objective FROM (
|
|
474
|
+
verifying, parent, parent_objective FROM (
|
|
357
475
|
SELECT DISTINCT ON (t.task_id)
|
|
358
476
|
t.task_id, t.objective, t.created_at, t.origin, w.state, w.principal_id, w.contract_ref,
|
|
359
477
|
sp.parent_task_id AS parent, sp.parent_objective,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
478
|
+
-- THIS interval judged rejected (Leg A: the statement link, never a clock),
|
|
479
|
+
-- and whether a judge holds it right now (UX rule 22: one spelling with the pager).
|
|
480
|
+
${rejectedIntervalSql({ claim: 'w' })} AS rejected_after,
|
|
481
|
+
(j.claimed_at IS NOT NULL) AS verifying,
|
|
482
|
+
res.place, res.place_evidence, ${HomeBoard.placesSql('t')} AS places,
|
|
364
483
|
w.settled_at,
|
|
365
484
|
to_char(w.ownership_valid_until AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI\"Z\"') AS lease_until,
|
|
366
485
|
p.proposition AS last_progress,
|
|
@@ -372,13 +491,17 @@ export function createOatheTools({
|
|
|
372
491
|
LEFT JOIN LATERAL (${latestProgressSql({ task: 't', claim: 'w' })}) p ON true
|
|
373
492
|
LEFT JOIN LATERAL (${latestTracePathSql({ task: 't' })}) tr ON true
|
|
374
493
|
LEFT JOIN LATERAL (${spawnParentSql({ task: 't' })}) sp ON true
|
|
494
|
+
LEFT JOIN LATERAL (${holdSql({ kind: 'verify', orgId: 't.org_id', subject: 't.task_id', asOf: 'now()' })}) j ON true
|
|
495
|
+
LEFT JOIN LATERAL (${HomeBoard.residenceSql('t')}) res ON true
|
|
375
496
|
WHERE t.org_id = $1
|
|
376
497
|
ORDER BY t.task_id, w.claimed_at DESC NULLS LAST
|
|
377
498
|
) latest WHERE true ${filter} ORDER BY created_at DESC`,
|
|
378
499
|
params);
|
|
500
|
+
// The residence's evidence back to facts: the app it was spoken from, the device.
|
|
501
|
+
const rows = raw.map(({ place_evidence, ...row }) => ({ ...row, ...PlaceEvidence.parse(place_evidence).row() }));
|
|
379
502
|
// Lineage (UX rule 21): a child never surfaces top-level while its parent is in view —
|
|
380
503
|
// it is counted on the parent's row. A child whose parent is off the board (settled,
|
|
381
|
-
// or
|
|
504
|
+
// or residing elsewhere) stands on its own.
|
|
382
505
|
const inView = new Set(rows.filter((r) => !r.settled_at).map((r) => r.task_id));
|
|
383
506
|
const childrenOf = new Map();
|
|
384
507
|
for (const row of rows) {
|
|
@@ -403,7 +526,7 @@ export function createOatheTools({
|
|
|
403
526
|
},
|
|
404
527
|
|
|
405
528
|
async oathe_statement({ task_id, proposition, evidence_ref }) {
|
|
406
|
-
const workClaimId = await
|
|
529
|
+
const { workClaimId, seat } = await hold(task_id);
|
|
407
530
|
const statementId = crypto.randomUUID();
|
|
408
531
|
await client.query(
|
|
409
532
|
`INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
|
|
@@ -412,8 +535,12 @@ export function createOatheTools({
|
|
|
412
535
|
VALUES ($1, $2, $3, $4, $5, $6, 'progress', $7, $8, $9::jsonb, 'observed', now())`,
|
|
413
536
|
[statementId, orgId, task_id, workClaimId, actor, principalId,
|
|
414
537
|
`task:${task_id}`, proposition, JSON.stringify([evidence_ref ?? 'note:session'])]);
|
|
538
|
+
// task_id + work_claim_id ride the response on purpose: the harness serializes tool
|
|
539
|
+
// results into its transcript, so every statement self-fingerprints the claim it
|
|
540
|
+
// speaks to — a session picked up mid-claim is still discoverable by its UUID.
|
|
415
541
|
return {
|
|
416
|
-
recorded: true, statement_id: statementId,
|
|
542
|
+
recorded: true, statement_id: statementId, task_id, work_claim_id: workClaimId,
|
|
543
|
+
...seatFields(seat),
|
|
417
544
|
note: 'a statement, not truth — nothing settled',
|
|
418
545
|
};
|
|
419
546
|
},
|
|
@@ -427,12 +554,14 @@ export function createOatheTools({
|
|
|
427
554
|
`yield refused — '${task_id}' cannot go back on the board without its cause: pass note `
|
|
428
555
|
+ '(why you are stopping, for whoever picks it up)', { task_id });
|
|
429
556
|
}
|
|
430
|
-
|
|
557
|
+
// Dropping rejected work is a speech act too: the reclaim lands, then the yield — both on record.
|
|
558
|
+
const { workClaimId, seat } = await hold(task_id);
|
|
431
559
|
await client.query(
|
|
432
560
|
'SELECT cell.oathe_yield_operator($1::uuid, $2, now(), $3::uuid)',
|
|
433
561
|
[workClaimId, note, crypto.randomUUID()]);
|
|
434
562
|
return {
|
|
435
563
|
yielded: true, task_id, work_claim_id: workClaimId,
|
|
564
|
+
...seatFields(seat),
|
|
436
565
|
note: 'the obligation is back on the board, unowned',
|
|
437
566
|
};
|
|
438
567
|
},
|
|
@@ -448,9 +577,9 @@ export function createOatheTools({
|
|
|
448
577
|
if (!why || !String(why).trim()) {
|
|
449
578
|
throw new OatheToolError('OATHE_AMEND_WHY_REQUIRED', 'an amendment records WHY the definition moved', { task_id });
|
|
450
579
|
}
|
|
451
|
-
if (
|
|
580
|
+
if (systemTaskOf(task_id) !== null) {
|
|
452
581
|
throw new OatheToolError('OATHE_AMEND_VERIFY_TASK',
|
|
453
|
-
`'${task_id}' is a
|
|
582
|
+
`'${task_id}' is a system task (${systemTaskOf(task_id).kind}) — its objective is generated (src/plans.mjs), never amended`, { task_id });
|
|
454
583
|
}
|
|
455
584
|
const { rows: authority } = await client.query(
|
|
456
585
|
'SELECT seats FROM cell.acceptance_authority WHERE org_id = $1', [orgId]);
|
|
@@ -462,10 +591,13 @@ export function createOatheTools({
|
|
|
462
591
|
throw new OatheToolError('OATHE_AMEND_UNAUTHORIZED',
|
|
463
592
|
`'${principalId}' is not in the seats roster [${authority[0].seats.join(', ')}] — an amendment is signed by the acceptance seat`, { task_id });
|
|
464
593
|
}
|
|
465
|
-
if (principalId ===
|
|
594
|
+
if (principalId === config.get('verifierPrincipal')) {
|
|
466
595
|
throw new OatheToolError('OATHE_AMEND_UNAUTHORIZED',
|
|
467
596
|
`'${principalId}' is the verifier — the judge must not move the bar it judges`, { task_id });
|
|
468
597
|
}
|
|
598
|
+
// The fork's descope arm: rejected work is RESUMED first (the act), then amended while
|
|
599
|
+
// ACTIVE — R-AMEND holds, and both acts are on the record in that order.
|
|
600
|
+
const seat = await resumeIfRejected(task_id);
|
|
469
601
|
return inTransaction(client, async (tx) => {
|
|
470
602
|
const { rows: locked } = await tx.query(
|
|
471
603
|
`SELECT work_claim_id FROM cell.work_claim
|
|
@@ -495,6 +627,8 @@ export function createOatheTools({
|
|
|
495
627
|
return {
|
|
496
628
|
amended: true,
|
|
497
629
|
task_id,
|
|
630
|
+
work_claim_id: locked[0].work_claim_id,
|
|
631
|
+
...seatFields(seat),
|
|
498
632
|
version,
|
|
499
633
|
note: `the definition of done moved to v${version}; the original definition stays on record in the amendment trail — verification judges the version in force at assertion and SEES the trail`,
|
|
500
634
|
};
|
|
@@ -505,7 +639,7 @@ export function createOatheTools({
|
|
|
505
639
|
// ONE transaction, claim row locked FIRST (the same discipline as oathe_amend): the
|
|
506
640
|
// amend-vs-done race is decided by the lock, "the version in force at assertion" is
|
|
507
641
|
// exact, and a completion statement never lands without its terminal.
|
|
508
|
-
const workClaimId = await
|
|
642
|
+
const { workClaimId, seat } = await hold(task_id);
|
|
509
643
|
const statementId = crypto.randomUUID();
|
|
510
644
|
await inTransaction(client, async (tx) => {
|
|
511
645
|
const { rows: lockRows } = await tx.query(
|
|
@@ -547,14 +681,19 @@ export function createOatheTools({
|
|
|
547
681
|
// carrying the engine assigned at claim time. A verification task does not mint a
|
|
548
682
|
// verifier for ITSELF — that regress ends at the deterministic bar.
|
|
549
683
|
let verificationTask = null;
|
|
550
|
-
if (
|
|
684
|
+
if (systemTaskOf(task_id) === null) { // a system task (a judgment, an update) settles at the deterministic bar — it mints no judge of its own
|
|
551
685
|
const { rows: engineRows } = await client.query(
|
|
552
686
|
`SELECT subject_ref FROM cell.agent_statement
|
|
553
687
|
WHERE org_id = $1 AND work_claim_id = $2 AND subject_ref LIKE 'verifier:%'
|
|
554
688
|
ORDER BY asserted_at DESC LIMIT 1`,
|
|
555
689
|
[orgId, workClaimId]);
|
|
556
|
-
|
|
557
|
-
|
|
690
|
+
// Every claim binds its verifier at the pickup (bindVerifier, on claim and reseat) — a
|
|
691
|
+
// claim without the binding is not one the tools made; refuse, never fall back.
|
|
692
|
+
if (engineRows.length === 0) {
|
|
693
|
+
throw new OatheToolError('OATHE_VERIFIER_UNBOUND',
|
|
694
|
+
`'${task_id}' carries no verifier binding on its claim — not a claim this oathe made; claim it again through oathe_claim`, { task_id, work_claim_id: workClaimId });
|
|
695
|
+
}
|
|
696
|
+
const engine = engineRows[0].subject_ref.slice('verifier:'.length);
|
|
558
697
|
verificationTask = verificationTaskId(task_id);
|
|
559
698
|
await client.query(
|
|
560
699
|
`INSERT INTO cell.task (org_id, task_id, department, objective, origin, verification_plan,
|
|
@@ -568,23 +707,26 @@ export function createOatheTools({
|
|
|
568
707
|
|
|
569
708
|
return {
|
|
570
709
|
done: true, task_id, work_claim_id: workClaimId, statement_id: statementId,
|
|
710
|
+
...seatFields(seat),
|
|
571
711
|
verification_task: verificationTask,
|
|
572
712
|
note: verificationTask
|
|
573
713
|
? `completion ASSERTED, not settled. Verification task '${verificationTask}' is on the `
|
|
574
714
|
+ 'board. A DIFFERENT principal must verify (FC010 — you cannot verify your own work, '
|
|
575
|
-
+ 'including via your own sub-agents)
|
|
715
|
+
+ 'including via your own sub-agents). Locally this call WAITS for the verdict and returns it '
|
|
716
|
+
+ '(progress ticks ride the call; Claude Code moves a call past two minutes to a background task '
|
|
717
|
+
+ 'and delivers the verdict as its notification). Otherwise run `oathe verify` from any terminal, or leave '
|
|
576
718
|
+ 'it for another session to claim.'
|
|
577
719
|
: 'completion ASSERTED, not settled — the deterministic acceptance bar settles verification tasks',
|
|
578
720
|
};
|
|
579
721
|
},
|
|
580
722
|
|
|
581
|
-
async oathe_verify({ task_id, engine }) {
|
|
723
|
+
async oathe_verify({ task_id, engine }, { progress } = {}) {
|
|
582
724
|
if (!verifier) {
|
|
583
725
|
throw new OatheToolError('OATHE_VERIFY_UNAVAILABLE',
|
|
584
726
|
'the verification lane is not wired into this server — run `oathe verify` from a '
|
|
585
727
|
+ 'terminal instead; verification cannot pretend', { task_id });
|
|
586
728
|
}
|
|
587
|
-
return verifier({ taskId: task_id, engine });
|
|
729
|
+
return verifier({ taskId: task_id, engine, ...(progress && { progress }) });
|
|
588
730
|
},
|
|
589
731
|
|
|
590
732
|
async oathe_pickup({ task_id }) {
|
|
@@ -593,34 +735,41 @@ export function createOatheTools({
|
|
|
593
735
|
WHERE org_id = $1 AND task_id = $2 ORDER BY claimed_at DESC LIMIT 1`,
|
|
594
736
|
[orgId, task_id]);
|
|
595
737
|
const latest = rows[0];
|
|
596
|
-
|
|
597
|
-
|
|
738
|
+
// Rejected work is resumed by the pickup itself (the act); anything else not active is
|
|
739
|
+
// a refusal that coaches the recovery a session actually needs mid-conversation.
|
|
740
|
+
const seat = latest && latest.state !== 'active' ? await resumeIfRejected(task_id) : null;
|
|
741
|
+
if (!seat && (!latest || latest.state !== 'active')) {
|
|
598
742
|
const hint = latest
|
|
599
743
|
? `the latest claim on '${task_id}' is ${latest.state} — claim it again (oathe_claim), `
|
|
600
744
|
+ 'then oathe_pickup follows the task\'s history'
|
|
601
745
|
: `no claim exists on '${task_id}' — nothing to pick up`;
|
|
602
746
|
throw new OatheToolError('OATHE_NO_ACTIVE_CLAIM', hint, { task_id, state: latest?.state ?? null });
|
|
603
747
|
}
|
|
748
|
+
const workClaimId = seat?.work_claim_id ?? latest.work_claim_id;
|
|
604
749
|
if (!successor) {
|
|
750
|
+
// The reclaim STANDS whatever the seam lacks: its seat rides the refusal's details.
|
|
605
751
|
throw new OatheToolError('OATHE_PICKUP_UNAVAILABLE',
|
|
606
752
|
'pickup is not wired into this tools server — the successor sequence is unavailable in '
|
|
607
|
-
+ 'this session (a preview limitation of sessions without the runtime seam).
|
|
608
|
-
+
|
|
609
|
-
|
|
753
|
+
+ 'this session (a preview limitation of sessions without the runtime seam). '
|
|
754
|
+
+ (seat
|
|
755
|
+
? 'The rejected work is reclaimed and held; the recovery bundle — the rejection reason, '
|
|
756
|
+
+ 'the prior interval\'s statements, and its trace refs — rides this refusal\'s details, and the '
|
|
757
|
+
: 'Claim the task instead (oathe_claim): a reclaim of rejected work returns the recovery bundle — '
|
|
758
|
+
+ 'the rejection reason, the prior interval\'s statements, and its trace refs — and the ')
|
|
610
759
|
+ 'board (oathe_board) carries the objective and progress; pickup cannot pretend',
|
|
611
|
-
{ task_id });
|
|
760
|
+
{ task_id, work_claim_id: workClaimId, ...seatFields(seat) });
|
|
612
761
|
}
|
|
613
|
-
const frame = await successor({ task_id, work_claim_id:
|
|
762
|
+
const frame = await successor({ task_id, work_claim_id: workClaimId });
|
|
614
763
|
// R-QUIET: the restored-state banner rides the pickup — the one moment it is news.
|
|
615
|
-
return { ...frame, receipt: restoredReceipt(task_id) };
|
|
764
|
+
return { ...frame, ...seatFields(seat), receipt: restoredReceipt(task_id) };
|
|
616
765
|
},
|
|
617
766
|
};
|
|
618
767
|
|
|
619
768
|
// Attention rides EVERY response, activation or not: the act succeeded — a failing
|
|
620
769
|
// attention read is reported beside it (attention_error), never converted into a tool error.
|
|
621
770
|
if (pager) {
|
|
622
|
-
toolMap = Object.fromEntries(Object.entries(toolMap).map(([name, fn]) => [name, async (args) => {
|
|
623
|
-
const out = await fn(args);
|
|
771
|
+
toolMap = Object.fromEntries(Object.entries(toolMap).map(([name, fn]) => [name, async (args, ctx = {}) => {
|
|
772
|
+
const out = await fn(args, ctx);
|
|
624
773
|
try {
|
|
625
774
|
const lines = await attentionLines();
|
|
626
775
|
if (lines.length > 0) out.attention = lines;
|
|
@@ -643,18 +792,70 @@ export function createOatheTools({
|
|
|
643
792
|
// Every successful WRITE carries its speaker: the durable trace-link lands WITH the act
|
|
644
793
|
// (linkTrace — a failure throws typed; retries are idempotent), the wire nudges the glass,
|
|
645
794
|
// and the result discloses who spoke. Reads stamp and emit nothing.
|
|
646
|
-
|
|
795
|
+
/**
|
|
796
|
+
* THE GATE (founder ruling 2026-09-04): a claim needs a session behind it. Refused, typed,
|
|
797
|
+
* with the fix the model can act on — never disclosed and deferred to a stall at done. The
|
|
798
|
+
* one exception is a surface that runs no hooks by design (the adapter declares it, the
|
|
799
|
+
* measured process names it): admitted, and the act says how its evidence will be found.
|
|
800
|
+
* Claim-only: an admitted claim's later acts link when they can and never refuse here.
|
|
801
|
+
*/
|
|
802
|
+
const gate = () => {
|
|
803
|
+
if (speaker.session) return null;
|
|
804
|
+
if (speaker.pid === null) {
|
|
805
|
+
throw new OatheToolError('OATHE_SPEAKER_UNKNOWN',
|
|
806
|
+
'a claim is a session\'s speech act, and nothing here could be measured (the connection named '
|
|
807
|
+
+ 'no process to walk) — speak it from a harness session through the oathe MCP tools (`oathe_claim`)');
|
|
808
|
+
}
|
|
809
|
+
const label = harnessForClient(speaker.client ?? null);
|
|
810
|
+
if (speaker.walked === false) {
|
|
811
|
+
// A platform with no process walk (off darwin): the client's label stands in — a stated
|
|
812
|
+
// D0 limitation, disclosed on the act — or nothing at all, refused.
|
|
813
|
+
if (label) return attributionWhy({ surface: speaker.surface, walked: false });
|
|
814
|
+
throw new OatheToolError('OATHE_SPEAKER_UNKNOWN',
|
|
815
|
+
'a claim is a session\'s speech act — the process ancestry could not be walked and the client '
|
|
816
|
+
+ 'named no harness; speak it from a harness session through the oathe MCP tools (`oathe_claim`)');
|
|
817
|
+
}
|
|
818
|
+
const owner = attestationFor(speaker.surface);
|
|
819
|
+
if (!owner) {
|
|
820
|
+
throw new OatheToolError('OATHE_SPEAKER_UNKNOWN',
|
|
821
|
+
'a claim is a session\'s speech act — speak it from a harness session through the oathe MCP tools '
|
|
822
|
+
+ '(`oathe_claim`), not from a bare shell');
|
|
823
|
+
}
|
|
824
|
+
if (label && label !== owner.harness) {
|
|
825
|
+
throw new OatheToolError('OATHE_SPEAKER_MISMATCH',
|
|
826
|
+
`the client calls itself ${speaker.client} (${label}) but the process belongs to ${speaker.surface} `
|
|
827
|
+
+ `(${owner.harness}) — refusing to attribute the claim`, { client: speaker.client, surface: speaker.surface });
|
|
828
|
+
}
|
|
829
|
+
if (owner.attestation === 'hooks') {
|
|
830
|
+
throw new OatheToolError('OATHE_SESSION_UNREGISTERED',
|
|
831
|
+
`this ${speaker.surface} session is not registered — its SessionStart hook did not run (a session `
|
|
832
|
+
+ 'resumed before `oathe init`, or the plugin hooks are not wired). Run `oathe init` and start a new '
|
|
833
|
+
+ 'session, then claim again', { surface: speaker.surface });
|
|
834
|
+
}
|
|
835
|
+
return attributionWhy({ surface: speaker.surface, walked: true }); // hookless by design: admitted, disclosed
|
|
836
|
+
};
|
|
837
|
+
// `ctx` is the transport's per-call context: `progress(message)` when the client asked for
|
|
838
|
+
// progress on this request (connection.mjs) — the blocking done and verify hand it to the seam.
|
|
839
|
+
return Object.fromEntries(Object.entries(toolMap).map(([name, fn]) => [name, async (args, ctx = {}) => {
|
|
840
|
+
const admittedWhy = name === 'oathe_claim' ? gate() : null;
|
|
647
841
|
// Lineage is decided BEFORE a claim lands (a refused parent leaves nothing behind) and
|
|
648
842
|
// recorded right after it, on the parent's claim — the `spawn:<child>` observation.
|
|
649
843
|
const spawn = name === 'oathe_claim'
|
|
650
844
|
? await spawnParentFor({ client, identity, session: speaker.session, taskId: args.task_id, parent: args.parent })
|
|
651
845
|
: null;
|
|
652
|
-
const out = await fn(args);
|
|
846
|
+
const out = await fn(args, ctx);
|
|
653
847
|
if (WIRE_KINDS[name]) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
848
|
+
// Attribution rides the act (SPEAKER primitive): the session's transcript as evidence — a
|
|
849
|
+
// link that waits, or one that cannot exist on an admitted session-less surface, is
|
|
850
|
+
// disclosed, never assumed, never silent. (The PLACE is the pickup's fact, recorded by
|
|
851
|
+
// the claim and the re-seat themselves — ruling 2026-09-05.)
|
|
852
|
+
const attribute = async () => {
|
|
853
|
+
const link = speaker.session
|
|
854
|
+
? await linkTrace({ client, identity, taskId: args.task_id, session: speaker.session })
|
|
855
|
+
: { linked: false, why: admittedWhy ?? attributionWhy({ surface: speaker.surface, walked: speaker.walked !== false }) };
|
|
856
|
+
if (link.why) out.trace_link = link;
|
|
857
|
+
};
|
|
858
|
+
if (args?.task_id && LINKABLE.has(name)) await attribute();
|
|
658
859
|
if (name === 'oathe_claim') {
|
|
659
860
|
if (spawn) {
|
|
660
861
|
await linkSpawn({
|
|
@@ -671,7 +872,7 @@ export function createOatheTools({
|
|
|
671
872
|
// whatever happens — a seam failure is disclosed, and the pager pages the miss.
|
|
672
873
|
if (name === 'oathe_done' && verifier) {
|
|
673
874
|
try {
|
|
674
|
-
const outcome = await verifier({ taskId: args.task_id });
|
|
875
|
+
const outcome = await verifier({ taskId: args.task_id, ...(ctx.progress && { progress: ctx.progress }) });
|
|
675
876
|
out.verification = outcome?.verdict === 'rejected'
|
|
676
877
|
? { ...outcome, your_options: REJECTION_FORK }
|
|
677
878
|
: outcome;
|
|
@@ -679,10 +880,26 @@ export function createOatheTools({
|
|
|
679
880
|
out.verification = { failed: true, reason: `${e?.code ? `[${e.code}] ` : ''}${String(e?.message ?? e).slice(0, 200)}` };
|
|
680
881
|
}
|
|
681
882
|
}
|
|
883
|
+
// The verdict's own answer (founder ruling 2026-09-04): a rejection returned in THIS
|
|
884
|
+
// exchange hands the work back to its asserter before the next token — the principal
|
|
885
|
+
// spoke (the done), the substrate answered, and the re-seat completes that act (R-PAGER:
|
|
886
|
+
// nothing moves until a principal has spoken; here one just did). The fact is read off
|
|
887
|
+
// the substrate, never off the seam's word. A verify by anyone else reseats nobody — the
|
|
888
|
+
// breach shows for the owner, whose next act resumes it.
|
|
889
|
+
const verdict = name === 'oathe_done' ? out.verification?.verdict : name === 'oathe_verify' ? out.verdict : null;
|
|
890
|
+
if (verdict === 'rejected') {
|
|
891
|
+
const prior = await lastEndedInterval(args.task_id);
|
|
892
|
+
if (prior?.rejected && prior.origin === 'reopened' && prior.principal_id === principalId) {
|
|
893
|
+
const seat = await reseat(args.task_id, prior);
|
|
894
|
+
Object.assign(out, seatFields(seat), { judged_claim_id: prior.work_claim_id, work_claim_id: seat.work_claim_id });
|
|
895
|
+
if (LINKABLE.has(name)) await attribute(); // the NEW seat carries the session's link in the same act
|
|
896
|
+
}
|
|
897
|
+
}
|
|
682
898
|
out.spoken_from = {
|
|
683
899
|
surface: speaker.surface,
|
|
684
900
|
app: speaker.app?.bundle ?? null,
|
|
685
901
|
session: speaker.session?.sessionId ?? null,
|
|
902
|
+
device: speaker.device ?? null, // the trust unit outside this machine (ruling 2026-09-04)
|
|
686
903
|
};
|
|
687
904
|
await emit(client, { kind: WIRE_KINDS[name], task_id: args?.task_id, via: speaker.surface, app: speaker.app });
|
|
688
905
|
}
|
|
@@ -694,17 +911,21 @@ export function createOatheTools({
|
|
|
694
911
|
|
|
695
912
|
/**
|
|
696
913
|
* The board's ONE classification of an unsettled row: [bucket, row]. The discriminator is a
|
|
697
|
-
* REJECTION
|
|
698
|
-
* one, origin='reopened' is stale history
|
|
699
|
-
* no-verdict engine failure must not read
|
|
914
|
+
* REJECTION OVER the latest claim (rejectedIntervalSql — this interval's own verdict): with
|
|
915
|
+
* one, the task is back on the board (R8); without one, origin='reopened' is stale history
|
|
916
|
+
* and the truth is asserted-awaiting-verification (a no-verdict engine failure must not read
|
|
917
|
+
* as reopened — live, 2026-08-30). An asserted row names the judgment it awaits: `verifying`
|
|
918
|
+
* while a judge holds it, `awaiting` until one does — the keys of JUDGMENT (breach-digest),
|
|
919
|
+
* whose words every surface renders (UX rule 22).
|
|
700
920
|
*/
|
|
701
921
|
function classify(row, principalId) {
|
|
702
922
|
if (row.state === 'active') return [row.principal_id === principalId ? 'mine' : 'held', row];
|
|
703
|
-
if (row.state === 'completion_asserted' && !row.rejected_after) return ['asserted', row];
|
|
923
|
+
if (row.state === 'completion_asserted' && !row.rejected_after) return ['asserted', judged(row)];
|
|
704
924
|
if (row.origin === 'reopened') return ['open', { ...row, state: 'reopened' }]; // R8: back on the board
|
|
705
|
-
if (row.state === 'completion_asserted') return ['asserted', row];
|
|
925
|
+
if (row.state === 'completion_asserted') return ['asserted', judged(row)];
|
|
706
926
|
return ['open', row];
|
|
707
927
|
}
|
|
928
|
+
const judged = (row) => ({ ...row, judgment: row.verifying ? 'verifying' : 'awaiting' });
|
|
708
929
|
|
|
709
930
|
/** A spawned child's one word on its parent's row, in the order the line speaks them. */
|
|
710
931
|
const CHILD_WORDS = ['active', 'asserted', 'reopened', 'open', 'settled'];
|
|
@@ -749,14 +970,14 @@ const okText = (obj) => ({ content: [{ type: 'text', text: JSON.stringify(obj) }
|
|
|
749
970
|
const errText = (obj) => ({ content: [{ type: 'text', text: JSON.stringify(obj) }], isError: true });
|
|
750
971
|
|
|
751
972
|
/** One tools/call: a throwing tool becomes a TYPED tool error — never a bland success. */
|
|
752
|
-
export async function handleToolCall(params, tools) {
|
|
973
|
+
export async function handleToolCall(params, tools, ctx = {}) {
|
|
753
974
|
const name = params?.name;
|
|
754
975
|
const fn = tools[name];
|
|
755
976
|
if (typeof fn !== 'function') {
|
|
756
977
|
return errText({ status: 'ERROR', error_type: 'unknown_tool', reason: `no such oathe tool '${name}'` });
|
|
757
978
|
}
|
|
758
979
|
try {
|
|
759
|
-
return okText(await fn(params?.arguments || {}));
|
|
980
|
+
return okText(await fn(params?.arguments || {}, ctx));
|
|
760
981
|
} catch (e) {
|
|
761
982
|
return errText({
|
|
762
983
|
status: 'ERROR',
|
|
@@ -777,15 +998,15 @@ export async function handleToolCall(params, tools) {
|
|
|
777
998
|
*/
|
|
778
999
|
export function lazyTools(loader, { names = makeToolDefs().map((t) => t.name) } = {}) {
|
|
779
1000
|
// No memo here: deduplication (and invalidation) is the LOADER's job — one cache, one owner.
|
|
780
|
-
return Object.fromEntries(names.map((name) => [name, async (args) => {
|
|
1001
|
+
return Object.fromEntries(names.map((name) => [name, async (args, ctx = {}) => {
|
|
781
1002
|
const context = await loader();
|
|
782
|
-
return context.tools[name](args);
|
|
1003
|
+
return context.tools[name](args, ctx);
|
|
783
1004
|
}]));
|
|
784
1005
|
}
|
|
785
1006
|
|
|
786
1007
|
/** The pure JSON-RPC dispatcher — a response object, or null for a notification. `version`
|
|
787
1008
|
* is the package version the server names at initialize (the connection reads it once). */
|
|
788
|
-
export async function dispatch(msg, { tools, version }) {
|
|
1009
|
+
export async function dispatch(msg, { tools, version, progress = null }) {
|
|
789
1010
|
const { id, method, params } = msg || {};
|
|
790
1011
|
const isNotification = id === undefined || id === null;
|
|
791
1012
|
if (method === 'notifications/initialized' || method === 'initialized') return null;
|
|
@@ -800,7 +1021,7 @@ export async function dispatch(msg, { tools, version }) {
|
|
|
800
1021
|
case 'tools/list':
|
|
801
1022
|
return { tools: makeToolDefs() };
|
|
802
1023
|
case 'tools/call':
|
|
803
|
-
return handleToolCall(params, tools);
|
|
1024
|
+
return handleToolCall(params, tools, progress ? { progress } : {});
|
|
804
1025
|
case 'ping':
|
|
805
1026
|
return {};
|
|
806
1027
|
default:
|
|
@@ -815,16 +1036,42 @@ export async function dispatch(msg, { tools, version }) {
|
|
|
815
1036
|
}
|
|
816
1037
|
|
|
817
1038
|
/**
|
|
818
|
-
* Start the server over stdio
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
1039
|
+
* Start the server over stdio — as a FORWARDER when the device daemon answers on its socket
|
|
1040
|
+
* (connection-lane phase 2: one substrate owner per device; this process stays the harness's
|
|
1041
|
+
* per-session child, whose pid the daemon measures the speaker from), standalone otherwise.
|
|
1042
|
+
* The mode is a MEASURED fact — one connect attempt inside a config budget, never config,
|
|
1043
|
+
* never a hang. Startup stays crash-proof: a broken config or socket surface falls back to
|
|
1044
|
+
* the standalone server (reported on stderr), and nothing beyond the transport is built
|
|
1045
|
+
* before the first tools/call.
|
|
822
1046
|
*/
|
|
823
1047
|
export async function main(env = process.env) {
|
|
1048
|
+
if (await forwardIfServed(env)) return;
|
|
824
1049
|
const { McpConnection } = await import('./connection.mjs');
|
|
825
1050
|
new McpConnection({ env }).start();
|
|
826
1051
|
}
|
|
827
1052
|
|
|
1053
|
+
async function forwardIfServed(env) {
|
|
1054
|
+
try {
|
|
1055
|
+
const [{ connectDaemon, McpForwarder }, { serveSocketPath }, { OatheConfig }, { buildPaths }] = await Promise.all([
|
|
1056
|
+
import('./forwarder.mjs'), import('../serve.mjs'), import('../config.mjs'), import('../paths.mjs'),
|
|
1057
|
+
]);
|
|
1058
|
+
const config = OatheConfig.global({ env });
|
|
1059
|
+
const socket = await connectDaemon({
|
|
1060
|
+
socketPath: serveSocketPath(buildPaths(env), config),
|
|
1061
|
+
timeoutMs: config.get('serveConnectMs'),
|
|
1062
|
+
});
|
|
1063
|
+
if (!socket) return false;
|
|
1064
|
+
new McpForwarder({
|
|
1065
|
+
socket, input: process.stdin, output: process.stdout,
|
|
1066
|
+
env, cwd: process.cwd(), pid: process.pid,
|
|
1067
|
+
}).start();
|
|
1068
|
+
return true;
|
|
1069
|
+
} catch (e) {
|
|
1070
|
+
process.stderr.write(`oathe mcp: forwarding unavailable (${String(e?.message || e).slice(0, 160)}) — serving standalone\n`);
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
828
1075
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
829
1076
|
main();
|
|
830
1077
|
}
|