@oathe/oathe 0.0.1 → 0.2.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.
Files changed (71) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/LICENSE +202 -21
  3. package/NOTICE +7 -0
  4. package/README.md +104 -12
  5. package/assets/oathe-hero.svg +92 -0
  6. package/bin/oathe.mjs +376 -0
  7. package/docs/PRIVACY.md +45 -0
  8. package/package.json +33 -23
  9. package/plugin/.claude-plugin/plugin.json +10 -0
  10. package/plugin/.mcp.json +13 -0
  11. package/plugin/hooks/frame-note.mjs +24 -0
  12. package/plugin/hooks/heartbeat.mjs +49 -0
  13. package/plugin/hooks/hooks.json +39 -0
  14. package/plugin/hooks/lib.mjs +83 -0
  15. package/plugin/hooks/render-board.mjs +11 -0
  16. package/plugin/skills/oathe-work/SKILL.md +33 -0
  17. package/src/atif.mjs +633 -0
  18. package/src/blocks.mjs +192 -0
  19. package/src/board-render.mjs +106 -0
  20. package/src/config.mjs +169 -0
  21. package/src/context.mjs +35 -0
  22. package/src/doctor.mjs +108 -0
  23. package/src/harness.mjs +271 -0
  24. package/src/init.mjs +92 -0
  25. package/src/launch-env.mjs +25 -0
  26. package/src/launch.mjs +259 -0
  27. package/src/manifest.mjs +89 -0
  28. package/src/mcp/oathe-tools.mjs +517 -0
  29. package/src/paths.mjs +49 -0
  30. package/src/plans.mjs +50 -0
  31. package/src/runtime/discharge.mjs +57 -0
  32. package/src/runtime/provider.mjs +154 -0
  33. package/src/runtime/simple-cage.mjs +67 -0
  34. package/src/runtime/sql-acceptance-lane.mjs +89 -0
  35. package/src/session-host.mjs +81 -0
  36. package/src/substrate.mjs +337 -0
  37. package/src/successor.mjs +31 -0
  38. package/src/traces.mjs +242 -0
  39. package/src/uninstall.mjs +45 -0
  40. package/src/verifier.mjs +322 -0
  41. package/src/workspace.mjs +47 -0
  42. package/vendor/ddl/001_core.sql +312 -0
  43. package/vendor/ddl/002_claim.sql +438 -0
  44. package/vendor/ddl/003_verification.sql +480 -0
  45. package/vendor/ddl/004_delegation.sql +397 -0
  46. package/vendor/ddl/005_escalation.sql +303 -0
  47. package/vendor/ddl/006_dependency.sql +384 -0
  48. package/vendor/ddl/007_assignment.sql +502 -0
  49. package/vendor/ddl/008_effect_receipt.sql +290 -0
  50. package/vendor/ddl/009_verified_edge.sql +452 -0
  51. package/vendor/ddl/010_parent_child_verification.sql +320 -0
  52. package/vendor/ddl/011_confirm.sql +288 -0
  53. package/vendor/ddl/012_evaluator_lane.sql +444 -0
  54. package/vendor/ddl/013_claim_terminal.sql +279 -0
  55. package/vendor/ddl/014_claim_settlement.sql +327 -0
  56. package/vendor/ddl/015_claim_yield.sql +213 -0
  57. package/vendor/ddl/016_reopened_reclaim.sql +285 -0
  58. package/vendor/ddl/017_claim_yield_causes.sql +357 -0
  59. package/vendor/ddl/018_receiptless_unknown.sql +249 -0
  60. package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
  61. package/vendor/ddl/020_context_compilation.sql +105 -0
  62. package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
  63. package/vendor/ddl/022_verification_clause.sql +106 -0
  64. package/vendor/ddl/023_executor_role.sql +66 -0
  65. package/vendor/ddl/024_executor_role_hardening.sql +439 -0
  66. package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
  67. package/vendor/ddl/026_acceptance_authority.sql +230 -0
  68. package/vendor/ddl/027_ownership_return.sql +836 -0
  69. package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
  70. package/vendor/ddl/manifest.json +183 -0
  71. package/index.js +0 -33
package/src/plans.mjs ADDED
@@ -0,0 +1,50 @@
1
+ // oathe — the policy-standard verification plan (the G2-b "policy supplies a standard plan
2
+ // for routine work types" binder, the one ruled way a solo user's claim ever settles without
3
+ // ceremony). Named ONCE here; bound by oathe_done before the completion terminal (FC161
4
+ // permits amendment only under an ACTIVE claim), and stamped `bound_by` so the ledger shows
5
+ // WHO set the bar (G2-b: "stamped — visibly, in the ledger").
6
+ //
7
+ // The clause conditions are DETERMINISTIC (the acceptance lane's own vocabulary — no model,
8
+ // no network): a completion-typed statement, at least one addressable evidence ref, and a
9
+ // non-blank trace ref. The judgment about the WORK is the verifier agent's, recorded as
10
+ // evidence; this bar checks presence and provenance — checker shallowness is a published
11
+ // bound of the design, stated here on purpose.
12
+
13
+ export const ACCEPTANCE_CLAUSE_KEY = 'acceptance_package';
14
+ export const PLAN_POLICY_VERSION = 1;
15
+
16
+ export const STANDARD_CLAUSE_CONDITIONS = Object.freeze([
17
+ { kind: 'statement_kind', expected: 'completion' },
18
+ { kind: 'evidence_present', min: 1 },
19
+ { kind: 'trace_ref_present' },
20
+ ]);
21
+
22
+ /**
23
+ * @param {{verifierEngine?: string|null}} o engine stamped on VERIFICATION tasks so any
24
+ * session (or `oathe verify`) knows which harness the founder assigned.
25
+ */
26
+ export function standardPlan({ verifierEngine = null } = {}) {
27
+ return {
28
+ plan_status: 'declared',
29
+ clauses: [ACCEPTANCE_CLAUSE_KEY],
30
+ clause_spec: {
31
+ [ACCEPTANCE_CLAUSE_KEY]: { conditions: STANDARD_CLAUSE_CONDITIONS.map((c) => ({ ...c })) },
32
+ },
33
+ bound_by: `policy:oathe-standard@${PLAN_POLICY_VERSION}`,
34
+ ...(verifierEngine ? { verifier_engine: verifierEngine } : {}),
35
+ };
36
+ }
37
+
38
+ export function verificationTaskId(taskId) {
39
+ return `verify:${taskId}`;
40
+ }
41
+
42
+ export function isVerificationTask(taskId) {
43
+ return taskId.startsWith('verify:');
44
+ }
45
+
46
+ export function verificationObjective(taskId) {
47
+ return `Render a verdict on '${taskId}': does the recorded evidence — the completion `
48
+ + 'statement and the linked session traces — support that the objective was met? '
49
+ + 'A non-author principal claims this, analyzes the traces, and records the verdict.';
50
+ }
@@ -0,0 +1,57 @@
1
+ // oathe — deterministic clause discharge, owned by the package (the Stage 1 plan: "we already
2
+ // own STANDARD_CLAUSE_CONDITIONS; the discharge logic is ~50 lines against the DDL's
3
+ // contract"). Shared by BOTH providers: the standalone lane calls dischargeClause directly;
4
+ // the oathe provider composes applyRecordedVerdict over the upstream base checker. Three
5
+ // verdicts only — accepted, rejected, blocked — and everything unknown fails TOWARD blocked.
6
+
7
+ export const RECORDED_VERDICT_CHECKER = 'oathe-verdict';
8
+
9
+ /** The recorded-verdict rule (bound at claim, discharged here) — only for its own checker. */
10
+ export function applyRecordedVerdict(conditions, clause) {
11
+ if (clause.checker !== RECORDED_VERDICT_CHECKER) return conditions;
12
+ if (conditions.verdict !== 'accepted') return conditions;
13
+ const recorded = clause.oathe_recorded_verdict;
14
+ if (recorded === 'accepted') return conditions;
15
+ if (recorded === 'rejected') {
16
+ return { verdict: 'rejected',
17
+ reason: 'the assigned verifier engine rejected the completion against its traces',
18
+ checks: conditions.checks, evidence: conditions.evidence };
19
+ }
20
+ return { verdict: 'blocked',
21
+ reason: `recorded verdict '${recorded}' is not a verdict`,
22
+ checks: conditions.checks, evidence: conditions.evidence };
23
+ }
24
+
25
+ const CONDITION_CHECKS = {
26
+ statement_kind: (statement, cond) =>
27
+ (statement.kind ?? statement.statement_type) === cond.expected,
28
+ evidence_present: (statement, cond) =>
29
+ Array.isArray(statement.evidence_refs) && statement.evidence_refs.length >= cond.min,
30
+ trace_ref_present: (statement) =>
31
+ typeof statement.trace_ref === 'string' && statement.trace_ref.trim() !== '',
32
+ };
33
+
34
+ /** @returns {{verdict: 'accepted'|'rejected'|'blocked', reason?: string, checks: object[], evidence: string[]}} */
35
+ export function dischargeClause({ statement, clause, spec }) {
36
+ const evidence = Array.isArray(statement.evidence_refs) ? statement.evidence_refs : [];
37
+ if (!spec) {
38
+ return { verdict: 'blocked',
39
+ reason: `no clause_spec for '${clause.clause_key}' — a lane with no bar blocks rather than accepting`,
40
+ checks: [], evidence };
41
+ }
42
+ const checks = [];
43
+ for (const cond of spec.conditions) {
44
+ const check = CONDITION_CHECKS[cond.kind];
45
+ if (!check) {
46
+ return { verdict: 'blocked',
47
+ reason: `unknown condition kind '${cond.kind}' — the discharge never guesses`,
48
+ checks, evidence };
49
+ }
50
+ checks.push({ kind: cond.kind, pass: check(statement, cond) === true });
51
+ }
52
+ const failed = checks.filter((c) => !c.pass).map((c) => c.kind);
53
+ const conditions = failed.length === 0
54
+ ? { verdict: 'accepted', checks, evidence }
55
+ : { verdict: 'rejected', reason: `conditions failed: ${failed.join(', ')}`, checks, evidence };
56
+ return applyRecordedVerdict(conditions, clause);
57
+ }
@@ -0,0 +1,154 @@
1
+ // oathe — the runtime seam (Stage 1 ruling: ONE seam, never a fork). Two providers serve the
2
+ // same capability surface: OatheRuntimeProvider binds the estate monorepo (the richer
3
+ // semantics), StandaloneRuntimeProvider is what the public package runs on a clean machine —
4
+ // every capability an honest implementation or a TYPED, LOUD degradation, never silent.
5
+ // Selection is explicit config (`runtimeProvider: auto|oathe|standalone`); auto = oathe
6
+ // exactly when the sanctioned cage address resolves on disk.
7
+
8
+ import fs from 'node:fs';
9
+ import { pathToFileURL } from 'node:url';
10
+ import { createRequire } from 'node:module';
11
+
12
+ import { standardPlan } from '../plans.mjs';
13
+
14
+ export class RuntimeError extends Error {
15
+ constructor(code, message, details = {}) {
16
+ super(message);
17
+ this.name = 'RuntimeError';
18
+ this.code = code;
19
+ this.details = details;
20
+ }
21
+ }
22
+
23
+ /** The default resolvability probe: does `oathe-runtime` actually resolve from THIS module's
24
+ * location, independent of whether the monorepo checkout (and thus the cage path) is present?
25
+ * A monorepo file being present says nothing about whether `npm run link-runtime` was ever run. */
26
+ function defaultResolve(specifier) {
27
+ return createRequire(import.meta.url).resolve(specifier);
28
+ }
29
+
30
+ export class OatheRuntimeProvider {
31
+ name = 'oathe';
32
+
33
+ #resolve;
34
+ #probeResult;
35
+
36
+ constructor({ paths, resolve = defaultResolve }) {
37
+ this.paths = paths;
38
+ this.#resolve = resolve;
39
+ }
40
+
41
+ capabilities() {
42
+ return { cage: 'acp-cage', settlement: 'oathe-acceptance-lane', pickup: 'thin-path' };
43
+ }
44
+
45
+ /** Computed ONCE per instance and cached — a raw ERR_MODULE_NOT_FOUND from oathe-runtime
46
+ * failing to resolve (e.g. a forgotten `npm run link-runtime` on an estate machine) is turned
47
+ * into a typed, loud fact here instead of leaking out of acceptanceRuntime()/successor().
48
+ * @returns {{ok: boolean, error?: string}} */
49
+ probe() {
50
+ if (this.#probeResult === undefined) {
51
+ try {
52
+ this.#resolve('oathe-runtime/seam');
53
+ this.#probeResult = { ok: true };
54
+ } catch (e) {
55
+ this.#probeResult = { ok: false, error: String(e?.message || e) };
56
+ }
57
+ }
58
+ return this.#probeResult;
59
+ }
60
+
61
+ #assertResolves() {
62
+ const result = this.probe();
63
+ if (!result.ok) {
64
+ throw new RuntimeError('OATHE_RUNTIME_UNLINKED',
65
+ 'the oathe runtime does not resolve from this checkout — run `npm run link-runtime` '
66
+ + `(the monorepo is at ${this.paths.monorepo}, but node_modules/oathe-runtime is missing)`,
67
+ { monorepo: this.paths.monorepo });
68
+ }
69
+ }
70
+
71
+ /** The one sanctioned path import — the cage lives outside oathe-runtime's exports map.
72
+ * Stays path-based (no probe): the cage address is resolved off paths.cagePath directly,
73
+ * never through oathe-runtime's package resolution. */
74
+ async cage() {
75
+ const { spawnCaged } = await import(pathToFileURL(this.paths.cagePath).href);
76
+ return { spawnCaged };
77
+ }
78
+
79
+ /** THIN WRAPPER (Stage 1 ruling, 2026-08-26): no composition logic lives here. The runtime
80
+ * package owns the whole acceptance build — including the recorded-verdict checker wiring
81
+ * that previously lived in this method — and lands as `oathe-runtime/seam` exporting
82
+ * `buildAcceptanceRuntime({ pool }) → { SETTLE, laneFor(seatPrincipal) }`. */
83
+ async acceptanceRuntime({ pool }) {
84
+ this.#assertResolves();
85
+ const seam = await import('oathe-runtime/seam');
86
+ return seam.buildAcceptanceRuntime({ pool });
87
+ }
88
+
89
+ /** The thin-path pickup, served only where the oathe runtime resolves. */
90
+ async successor({ substrate, identity, paths }) {
91
+ this.#assertResolves();
92
+ const { buildSuccessor } = await import('../successor.mjs');
93
+ return buildSuccessor({ substrate, identity, paths });
94
+ }
95
+ }
96
+
97
+ export class StandaloneRuntimeProvider {
98
+ name = 'standalone';
99
+
100
+ capabilities() {
101
+ return { cage: 'simple-cage', settlement: 'sql-acceptance-lane', pickup: 'unavailable' };
102
+ }
103
+
104
+ /** The standalone package never depends on oathe-runtime — always resolvable by definition. */
105
+ probe() {
106
+ return { ok: true };
107
+ }
108
+
109
+ async cage() {
110
+ const { spawnCaged } = await import('./simple-cage.mjs');
111
+ return { spawnCaged };
112
+ }
113
+
114
+ /** The standalone package's own settlement path — the SQL-equivalent lane, lazily imported
115
+ * to keep this module from cycling with sql-acceptance-lane.mjs (which imports RuntimeError
116
+ * from here). */
117
+ async acceptanceRuntime({ pool, orgId }) {
118
+ const { SqlAcceptanceLane, SETTLE } = await import('./sql-acceptance-lane.mjs');
119
+ const specs = standardPlan().clause_spec;
120
+ return {
121
+ SETTLE,
122
+ laneFor: (seatPrincipal) => new SqlAcceptanceLane({ pool, orgId, seatPrincipal, specs }),
123
+ };
124
+ }
125
+
126
+ /** Pickup degrades TYPED and LOUD: same {pickup, close} shape, the refusal inside pickup().
127
+ * Takes no args — the typed refusal never touches substrate/identity/paths, so there is
128
+ * nothing here to accept. */
129
+ async successor() {
130
+ return {
131
+ pickup: async () => {
132
+ throw new RuntimeError('OATHE_PICKUP_UNAVAILABLE',
133
+ 'the successor sequence needs the oathe runtime, which does not resolve on this '
134
+ + 'machine (runtime provider: standalone) — pickup cannot pretend; this is a preview '
135
+ + 'limitation', { provider: 'standalone' });
136
+ },
137
+ close: async () => {},
138
+ };
139
+ }
140
+ }
141
+
142
+ /** @returns {OatheRuntimeProvider | StandaloneRuntimeProvider} */
143
+ export function resolveRuntimeProvider({ config, paths }) {
144
+ const requested = config.get('runtimeProvider');
145
+ const runtimeResolves = paths.cagePath !== null && fs.existsSync(paths.cagePath);
146
+ if (requested === 'oathe' && !runtimeResolves) {
147
+ throw new RuntimeError('OATHE_RUNTIME_UNAVAILABLE',
148
+ `runtimeProvider 'oathe' is requested but the monorepo does not resolve `
149
+ + `(no cage at ${paths.cagePath}) — set runtimeProvider to 'standalone' or 'auto', `
150
+ + 'or point OATHE_MONOREPO at a checkout', { cagePath: paths.cagePath, monorepo: paths.monorepo });
151
+ }
152
+ const name = requested === 'auto' ? (runtimeResolves ? 'oathe' : 'standalone') : requested;
153
+ return name === 'oathe' ? new OatheRuntimeProvider({ paths }) : new StandaloneRuntimeProvider();
154
+ }
@@ -0,0 +1,67 @@
1
+ // oathe — SimpleCage: the standalone provider's cage, a CLEAN-ROOM implementation of the
2
+ // contract the launcher consumes (documented in docs/PRODUCT.md and the Stage 1 plan; no
3
+ // upstream code was read). The contract: synchronous spawnCaged({unit, env, cmd, args, cwd,
4
+ // stdio}) → {child, enumerate(), teardownProvenEmpty()}; the child environment is REPLACED
5
+ // (never merged) and the cage itself stamps OATHE_EXECUTION_ATTEMPT_ID; the child leads a
6
+ // fresh process group (setsid) so enumerate() is a kernel read of the whole scope and
7
+ // teardown is SIGTERM → grace → SIGKILL with the emptiness RE-OBSERVED, never assumed.
8
+
9
+ import { spawn, spawnSync } from 'node:child_process';
10
+ import crypto from 'node:crypto';
11
+
12
+ const DEFAULT_GRACE_MS = 2000;
13
+ const POLL_MS = 100;
14
+
15
+ function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }
16
+
17
+ export function spawnCaged({ unit, env, cmd, args, cwd, stdio, graceMs = DEFAULT_GRACE_MS }) {
18
+ const attemptId = `${unit}-${crypto.randomUUID()}`;
19
+ const child = spawn(cmd, args, {
20
+ cwd,
21
+ stdio,
22
+ detached: true, // setsid: the child leads a NEW process group, enumerable and killable as one
23
+ env: { ...env, OATHE_EXECUTION_ATTEMPT_ID: attemptId }, // REPLACED env + the cage's own stamp
24
+ });
25
+ const pgid = child.pid;
26
+
27
+ /** Kernel read of the group — live pids (stopped counts as live), [] once the scope is empty. */
28
+ const enumerate = () => {
29
+ const ps = spawnSync('ps', ['-A', '-o', 'pid=,pgid='], { encoding: 'utf8' });
30
+ if (ps.status !== 0) {
31
+ throw new Error(`SimpleCage cannot enumerate: ps exited ${ps.status}: ${ps.stderr}`);
32
+ }
33
+ return ps.stdout.split('\n')
34
+ .map((line) => line.trim().split(/\s+/).map(Number))
35
+ .filter(([pid, group]) => Number.isInteger(pid) && group === pgid)
36
+ .map(([pid]) => pid);
37
+ };
38
+
39
+ const signalGroup = (sig) => {
40
+ try { process.kill(-pgid, sig); } catch (e) { if (e.code !== 'ESRCH') throw e; }
41
+ };
42
+
43
+ const drainUntil = async (deadline) => {
44
+ while (Date.now() < deadline && enumerate().length > 0) await sleep(POLL_MS);
45
+ };
46
+
47
+ /** SIGTERM → grace → SIGKILL, then RE-ENUMERATE: the emptiness is proof, not assumption. */
48
+ const teardownProvenEmpty = async () => {
49
+ if (enumerate().length > 0) {
50
+ signalGroup('SIGTERM');
51
+ await drainUntil(Date.now() + graceMs);
52
+ if (enumerate().length > 0) {
53
+ signalGroup('SIGKILL');
54
+ await drainUntil(Date.now() + graceMs);
55
+ }
56
+ }
57
+ const survivors = enumerate();
58
+ return {
59
+ empty: survivors.length === 0,
60
+ detail: survivors.length === 0
61
+ ? `process group ${pgid} re-enumerated empty`
62
+ : `live pids remain in group ${pgid}: ${survivors.join(', ')}`,
63
+ };
64
+ };
65
+
66
+ return { child, enumerate, teardownProvenEmpty };
67
+ }
@@ -0,0 +1,89 @@
1
+ // oathe — SqlAcceptanceLane: the standalone provider's settlement path. The documented
2
+ // SQL-equivalent of the estate lane: our own deterministic clause discharge, then
3
+ // INSERT cell.verification + cell.settle_work_claim in ONE transaction (now() =
4
+ // transaction_timestamp keeps FC113/FC114 by equality). The substrate's triggers remain the
5
+ // enforcement — this lane is a caller, not an authority: it never writes settled_at itself
6
+ // (FC110), never edits a frozen plan (FC160), and blocks whenever the law is not plainly met.
7
+ // cell.verification_clause (the optional clause object) is deliberately not written.
8
+
9
+ import crypto from 'node:crypto';
10
+
11
+ import { dischargeClause } from './discharge.mjs';
12
+ import { RuntimeError } from './provider.mjs';
13
+
14
+ export const SETTLE = Object.freeze({ CLAIM: 'claim' });
15
+
16
+ export class SqlAcceptanceLane {
17
+ constructor({ pool, orgId, seatPrincipal, specs }) {
18
+ this.pool = pool;
19
+ this.orgId = orgId;
20
+ this.seatPrincipal = seatPrincipal;
21
+ this.specs = specs;
22
+ }
23
+
24
+ /** The seat law (026): registered roster, and never the author or executor (pre-FC010). */
25
+ async #seatBlocked(clause) {
26
+ const { rows } = await this.pool.query(
27
+ 'SELECT seats FROM cell.acceptance_authority WHERE org_id = $1', [this.orgId]);
28
+ if (rows.length === 0) {
29
+ return `no acceptance authority is registered for org '${this.orgId}' — an absent row is not lawful`;
30
+ }
31
+ if (!rows[0].seats.includes(this.seatPrincipal)) {
32
+ return `'${this.seatPrincipal}' is not in the registered seats roster [${rows[0].seats.join(', ')}]`;
33
+ }
34
+ if (this.seatPrincipal === clause.author_principal
35
+ || this.seatPrincipal === clause.executor_principal) {
36
+ return `'${this.seatPrincipal}' authored or executed the statement under evaluation — `
37
+ + 'verification is non-author only (FC010)';
38
+ }
39
+ return null;
40
+ }
41
+
42
+ async verify({ agent_statement, task_id, clause }, { settle }) {
43
+ const blockedBySeat = await this.#seatBlocked(clause);
44
+ if (blockedBySeat) {
45
+ return { settled: false, verification: { verdict: 'blocked', reason: blockedBySeat } };
46
+ }
47
+ const outcome = dischargeClause({
48
+ statement: agent_statement, clause, spec: this.specs[clause.clause_key] });
49
+ if (outcome.verdict === 'blocked') {
50
+ return { settled: false, verification: { verdict: 'blocked', reason: outcome.reason } };
51
+ }
52
+
53
+ const client = await this.pool.connect();
54
+ const verificationId = crypto.randomUUID();
55
+ try {
56
+ await client.query('BEGIN');
57
+ await client.query(
58
+ `INSERT INTO cell.verification
59
+ (verification_id, org_id, task_id, statement_id, source, result,
60
+ verifier_principal, verifier_type, verification_plan_ref, checks,
61
+ evidence_refs, trace_ref, privacy_class, transfer_scope, state_version, recorded_at)
62
+ VALUES ($1, $2, $3, $4, 'acceptance_package', $5, $6, 'seat', $7,
63
+ $8::jsonb, $9::jsonb, $10, $11, $12, NULL, now())`,
64
+ [verificationId, this.orgId, task_id, agent_statement.statement_ref,
65
+ outcome.verdict === 'accepted' ? 'verified' : 'rejected',
66
+ this.seatPrincipal, clause.clause_key,
67
+ JSON.stringify(outcome.checks), JSON.stringify(clause.evidence_refs),
68
+ clause.trace_ref, clause.privacy_class, clause.transfer_scope]);
69
+ let settled = false;
70
+ if (outcome.verdict === 'accepted' && settle === SETTLE.CLAIM) {
71
+ const { rows } = await client.query(
72
+ 'SELECT cell.settle_work_claim($1, now()) AS settled',
73
+ [agent_statement.work_claim_id]);
74
+ settled = rows[0].settled === true;
75
+ }
76
+ await client.query('COMMIT');
77
+ return { settled,
78
+ verification: { verdict: outcome.verdict, reason: outcome.reason ?? null,
79
+ verification_id: verificationId } };
80
+ } catch (e) {
81
+ await client.query('ROLLBACK').catch(() => {});
82
+ throw new RuntimeError('OATHE_SETTLEMENT_REFUSED',
83
+ `the substrate refused the settlement: ${String(e?.message || e)}`,
84
+ { sqlstate: e?.code ?? null, task_id });
85
+ } finally {
86
+ client.release();
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,81 @@
1
+ // oathe — the session host: liveness OBSERVATION for an interactive session's cage.
2
+ //
3
+ // R1 (correction packet 2026-08-26): the host never touches ownership_valid_until — session
4
+ // and process liveness are not organizational acts, and a claim's horizon is set once by the
5
+ // substrate's claim verb. Each tick asks the injected liveness probe (the cage's enumerate(),
6
+ // kernel-read); a dead cage stops the loop and touches NOTHING — R10: an absence is an
7
+ // absence. No statement is fabricated for a death nobody witnessed. Only a CLEAN exit
8
+ // speaks: stop({exitCode}) records the exit statement, because the exit was actually observed.
9
+
10
+ import crypto from 'node:crypto';
11
+
12
+
13
+
14
+ export class SessionHost {
15
+ /**
16
+ * @param {{client: {query: Function}, identity: {orgId: string, principalId: string},
17
+ * workspace: string, liveness: () => boolean, observeIntervalMs?: number}} o
18
+ */
19
+ constructor({ client, identity, workspace, liveness, observeIntervalMs = 60_000 }) {
20
+ this.client = client;
21
+ this.identity = identity;
22
+ this.workspace = workspace;
23
+ this.liveness = liveness;
24
+ this.observeIntervalMs = observeIntervalMs;
25
+ this.running = false;
26
+ this.timer = null;
27
+ this.tickInFlight = Promise.resolve();
28
+ }
29
+
30
+ start() {
31
+ if (this.running) return;
32
+ this.running = true;
33
+ this.timer = setInterval(() => { this.tickInFlight = this.#tick(); }, this.observeIntervalMs);
34
+ this.timer.unref?.();
35
+ }
36
+
37
+ async #tick() {
38
+ let alive;
39
+ try {
40
+ alive = this.liveness() === true;
41
+ } catch {
42
+ alive = false; // "I cannot tell" is not "it is alive"
43
+ }
44
+ if (!alive) this.#halt();
45
+ // A live cage needs nothing from us: observation is not an organizational act (R1).
46
+ }
47
+
48
+ #halt() {
49
+ if (this.timer) clearInterval(this.timer);
50
+ this.timer = null;
51
+ this.running = false;
52
+ }
53
+
54
+ /** Stop without a word — the killed-cage path and test teardown. */
55
+ async stopSilently() {
56
+ this.#halt();
57
+ await this.tickInFlight;
58
+ }
59
+
60
+ /** The observed clean exit: stop renewing AND say so on every claim this session held. */
61
+ async stop({ exitCode }) {
62
+ this.#halt();
63
+ await this.tickInFlight;
64
+ const { rows } = await this.client.query(
65
+ `SELECT work_claim_id, task_id FROM cell.work_claim
66
+ WHERE org_id = $1 AND principal_id = $2 AND state = 'active' AND contract_ref LIKE $3`,
67
+ [this.identity.orgId, this.identity.principalId, `workspace:${this.workspace};%`]);
68
+ for (const claim of rows) {
69
+ await this.client.query(
70
+ `INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
71
+ execution_actor, claim_principal, statement_type, subject_ref, proposition,
72
+ evidence_refs, epistemic_status, asserted_at)
73
+ VALUES ($1, $2, $3, $4, 'oathe-session-host', $5, 'progress', $6,
74
+ $7, '["session:exit"]'::jsonb, 'observed', now())`,
75
+ [crypto.randomUUID(), this.identity.orgId, claim.task_id, claim.work_claim_id,
76
+ this.identity.principalId, `task:${claim.task_id}`,
77
+ `session ended (exit ${exitCode}) with this claim still held — the lease will expire `
78
+ + 'unless the work is picked up or yielded']);
79
+ }
80
+ }
81
+ }