@oathe/oathe 0.2.2 → 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.
Files changed (75) hide show
  1. package/NOTICE +3 -4
  2. package/README.md +14 -45
  3. package/assets/oathe-hero.svg +92 -0
  4. package/bin/oathe.mjs +397 -59
  5. package/docs/PRIVACY.md +13 -5
  6. package/notch/Oathe Notch.app/Contents/Info.plist +13 -0
  7. package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
  8. package/notch/Oathe Notch.app/Contents/_CodeSignature/CodeResources +115 -0
  9. package/notch/README.md +88 -0
  10. package/package.json +13 -4
  11. package/plugin/.claude-plugin/plugin.json +1 -1
  12. package/plugin/.cursor-plugin/plugin.json +36 -0
  13. package/plugin/.mcp.json +1 -4
  14. package/plugin/commands/verify.md +18 -0
  15. package/plugin/hooks/frame-note.mjs +5 -3
  16. package/plugin/hooks/heartbeat.mjs +21 -25
  17. package/plugin/hooks/lib.mjs +96 -33
  18. package/plugin/hooks/render-board.mjs +47 -7
  19. package/src/activation.mjs +126 -0
  20. package/src/atif.mjs +4 -13
  21. package/src/blocks.mjs +113 -8
  22. package/src/board-render.mjs +55 -29
  23. package/src/config.mjs +100 -15
  24. package/src/context.mjs +4 -8
  25. package/src/doctor.mjs +96 -15
  26. package/src/fence.mjs +85 -0
  27. package/src/fslock.mjs +51 -0
  28. package/src/harnesses/catalog.mjs +180 -0
  29. package/src/harnesses/claude.mjs +196 -0
  30. package/src/harnesses/codex.mjs +188 -0
  31. package/src/harnesses/cursor.mjs +234 -0
  32. package/src/harnesses/dialects.mjs +52 -0
  33. package/src/harnesses/harness.mjs +203 -0
  34. package/src/harnesses/surfaces.mjs +71 -0
  35. package/src/home.mjs +107 -0
  36. package/src/init.mjs +101 -21
  37. package/src/launch-env.mjs +1 -51
  38. package/src/launch.mjs +37 -106
  39. package/src/manifest.mjs +7 -3
  40. package/src/mcp/connection.mjs +218 -0
  41. package/src/mcp/oathe-tools.mjs +380 -140
  42. package/src/notch.mjs +154 -0
  43. package/src/pager.mjs +178 -0
  44. package/src/paths.mjs +13 -1
  45. package/src/plans.mjs +10 -2
  46. package/src/registry.mjs +110 -0
  47. package/src/runtime/discharge.mjs +1 -1
  48. package/src/runtime/provider.mjs +10 -6
  49. package/src/runtime/simple-cage.mjs +32 -12
  50. package/src/runtime/sql-acceptance-lane.mjs +1 -1
  51. package/src/session-host.mjs +8 -6
  52. package/src/sessions.mjs +168 -0
  53. package/src/setup.mjs +494 -0
  54. package/src/speaker.mjs +65 -0
  55. package/src/statements.mjs +113 -0
  56. package/src/substrate.mjs +44 -0
  57. package/src/successor.mjs +3 -2
  58. package/src/traces.mjs +8 -8
  59. package/src/uninstall.mjs +10 -2
  60. package/src/verifier.mjs +135 -47
  61. package/src/verify-dispatch.mjs +169 -0
  62. package/src/welcome.mjs +32 -0
  63. package/src/wire.mjs +64 -0
  64. package/src/workspace-resolver.mjs +178 -0
  65. package/src/workspace.mjs +16 -5
  66. package/vendor/ddl/001_core.sql +1 -1
  67. package/vendor/ddl/004_delegation.sql +1 -1
  68. package/vendor/ddl/006_dependency.sql +1 -1
  69. package/vendor/ddl/008_effect_receipt.sql +1 -1
  70. package/vendor/ddl/009_verified_edge.sql +1 -1
  71. package/vendor/ddl/011_confirm.sql +2 -2
  72. package/vendor/ddl/manifest.json +8 -8
  73. package/assets/claude-splash.png +0 -0
  74. package/assets/resume-splash.png +0 -0
  75. package/src/harness.mjs +0 -271
package/src/notch.mjs ADDED
@@ -0,0 +1,154 @@
1
+ // oathe — the notch lifecycle (darwin): always-on as part of init, gone with uninstall,
2
+ // and SHIPPED WITH THE PACKAGE for everyone (founder rulings, 2026-08-30). The packaged
3
+ // app (notch/Oathe Notch.app, built at pack time) is the SOURCE; what launchd runs is a
4
+ // MATERIALIZED copy under the oathe home, keyed by version + binary content. The package
5
+ // tree is mutable — npm replaces it on upgrade, and replacing a signed binary under a
6
+ // running process gets it killed by the kernel — so the agent never points there: a new
7
+ // binary materializes a NEW key, the agent is re-stamped and restarted, and the old key is
8
+ // pruned only after launchd is off it. `oathe config notchApp <path> --global` overrides
9
+ // the source; init writes the LaunchAgent as a manifest-owned file and bootstraps it NOW;
10
+ // uninstall boots it out and removes exactly what was recorded; a source checkout without
11
+ // the built app gets a fact row naming what is missing.
12
+
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+
16
+ import { defaultExec } from './harnesses/harness.mjs';
17
+ import { sha256Hex } from './manifest.mjs';
18
+
19
+ export const NOTCH_LABEL = 'ai.oathe.notch';
20
+
21
+ /** The launchd label NAMES the installation, and installations are per-home — EVERY home,
22
+ * the real one included, gets a home-hashed label. There is deliberately no bare-label
23
+ * special case: "am I the default home" cannot be judged from inside an environment
24
+ * (os.homedir() follows $HOME, so a sandboxed child believes its sandbox is home — the
25
+ * self-reference that let a full-suite run kill the founder's live island through the
26
+ * shared fixed label, 2026-08-31, twice). The uid's launchd domain is shared across
27
+ * homes; only the hash keeps installations apart. */
28
+ export function notchLabel(home) {
29
+ const real = (p) => { try { return fs.realpathSync(p); } catch { return p; } };
30
+ return `${NOTCH_LABEL}.${sha256Hex(real(home)).slice(0, 12)}`;
31
+ }
32
+
33
+ export function launchAgentPath(home) {
34
+ return path.join(home, 'Library', 'LaunchAgents', `${notchLabel(home)}.plist`);
35
+ }
36
+
37
+ export function launchAgentPlist(appPath, { label = NOTCH_LABEL, nodeBinDir = path.dirname(process.execPath) } = {}) {
38
+ // launchd spawns with a bare PATH and a login shell never sources .zshrc — but init IS
39
+ // oathe running, so it knows exactly where the bin lives: the running node's own bin dir
40
+ // (the global npm bin) leads the agent's PATH. The app resolves `oathe` from this, no
41
+ // shell guessing. KeepAlive: the notch is a viewer with no side effects — a dead viewer
42
+ // is a silent breach surface, so launchd owns its liveness (crash, kill, or a replaced
43
+ // binary all end in a restart, never in quiet absence).
44
+ const agentPath = [nodeBinDir, '/usr/local/bin', '/opt/homebrew/bin', '/usr/bin', '/bin'].join(':');
45
+ return `<?xml version="1.0" encoding="UTF-8"?>
46
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
47
+ <plist version="1.0">
48
+ <dict>
49
+ <key>Label</key><string>${label}</string>
50
+ <key>ProgramArguments</key><array><string>${appPath}</string></array>
51
+ <key>EnvironmentVariables</key><dict><key>PATH</key><string>${agentPath}</string></dict>
52
+ <key>RunAtLoad</key><true/>
53
+ <key>KeepAlive</key><true/>
54
+ </dict>
55
+ </plist>
56
+ `;
57
+ }
58
+
59
+ /** The app the npm package ships — built by prepack, the SOURCE every machine materializes from. */
60
+ export function packagedNotchApp(packageRoot) {
61
+ return path.join(packageRoot, 'notch', 'Oathe Notch.app', 'Contents', 'MacOS', 'OatheNotch');
62
+ }
63
+
64
+ /** ~/.oathe/notch — every materialized key lives under here and nowhere else. */
65
+ export function materializedNotchRoot(home) {
66
+ return path.join(home, '.oathe', 'notch');
67
+ }
68
+
69
+ /**
70
+ * Copy the whole app bundle to `~/.oathe/notch/<version>-<sha12>/Oathe Notch.app`.
71
+ * Content-keyed: identical bytes land on the identical key (idempotent, no churn); changed
72
+ * bytes land on a FRESH key (a running copy is never overwritten in place). Materializing
73
+ * never deletes prior keys — pruning is wireNotch's job, after launchd has moved.
74
+ * @returns {{dir: string, binary: string, sha256: string}}
75
+ */
76
+ export function materializeNotchApp({ home, appBinary, version }) {
77
+ const sha = sha256Hex(fs.readFileSync(appBinary));
78
+ const dir = path.join(materializedNotchRoot(home), `${version}-${sha.slice(0, 12)}`);
79
+ // Only a real bundle (…/<Name>.app/Contents/MacOS/<bin>) is copied as one; a bare binary
80
+ // (`notchApp` pointed at a plain executable) materializes as just the file — walking three
81
+ // levels up from an arbitrary path would copy an unrelated ancestor into itself.
82
+ const bundleSource = path.dirname(path.dirname(path.dirname(appBinary)));
83
+ const isBundle = bundleSource.endsWith('.app')
84
+ && path.basename(path.dirname(appBinary)) === 'MacOS'
85
+ && path.basename(path.dirname(path.dirname(appBinary))) === 'Contents';
86
+ const binary = isBundle
87
+ ? path.join(dir, path.basename(bundleSource), 'Contents', 'MacOS', path.basename(appBinary))
88
+ : path.join(dir, path.basename(appBinary));
89
+ if (!fs.existsSync(binary)) {
90
+ fs.mkdirSync(dir, { recursive: true });
91
+ if (isBundle) fs.cpSync(bundleSource, path.join(dir, path.basename(bundleSource)), { recursive: true });
92
+ else fs.cpSync(appBinary, binary);
93
+ }
94
+ return { dir, binary, sha256: sha };
95
+ }
96
+
97
+ /** @returns {object[]} action rows for the init report; [] only off-darwin */
98
+ export function wireNotch({ home, manifest, config, version, exec = defaultExec, uid = process.getuid(), packageRoot }) {
99
+ if (process.platform !== 'darwin') return [];
100
+ const source = config.get('notchApp') ?? packagedNotchApp(packageRoot);
101
+ if (!fs.existsSync(source)) return [{ action: 'notch-binary-missing', file: source }];
102
+
103
+ const app = materializeNotchApp({ home, appBinary: source, version });
104
+ const label = notchLabel(home);
105
+ const file = launchAgentPath(home);
106
+ const content = launchAgentPlist(app.binary, { label });
107
+ fs.mkdirSync(path.dirname(file), { recursive: true });
108
+ fs.writeFileSync(file, content);
109
+
110
+ // Replaced wholesale on every wire: the manifest rows say what exists NOW (upsert keys on
111
+ // detail, so a moved app path would otherwise accumulate rows instead of replacing them).
112
+ // A replaced agent under a DIFFERENT name (a legacy bare label, a moved home) is booted
113
+ // out and removed here — otherwise the old job lingers loaded beside the new one.
114
+ for (const row of manifest.removeWhere((r) => r.kind === 'launch-agent' || r.kind === 'notch-app')) {
115
+ if (row.kind === 'launch-agent' && row.file !== file) {
116
+ exec.run('launchctl', ['bootout', `gui/${uid}/${path.basename(row.file, '.plist')}`]);
117
+ if (fs.existsSync(row.file)) fs.rmSync(row.file);
118
+ }
119
+ }
120
+ manifest.upsert({
121
+ harness: 'notch', file, kind: 'launch-agent', scope: 'user',
122
+ detail: { app: app.binary }, blockVersion: version, sha256: sha256Hex(content),
123
+ });
124
+ manifest.upsert({
125
+ harness: 'notch', file: app.dir, kind: 'notch-app', scope: 'user',
126
+ detail: { binary: app.binary }, blockVersion: version, sha256: app.sha256,
127
+ });
128
+
129
+ // A re-run is the restart: bootout is allowed to fail (not loaded), bootstrap must land.
130
+ // Prune stale keys BETWEEN the two — launchd is off the old copy, the new one not yet up.
131
+ exec.run('launchctl', ['bootout', `gui/${uid}/${label}`]);
132
+ for (const key of fs.readdirSync(materializedNotchRoot(home))) {
133
+ const stale = path.join(materializedNotchRoot(home), key);
134
+ if (stale !== app.dir) fs.rmSync(stale, { recursive: true, force: true });
135
+ }
136
+ exec.run('launchctl', ['bootstrap', `gui/${uid}`, file]);
137
+ return [{ action: 'launch-agent-written', file }];
138
+ }
139
+
140
+ /** @returns {object[]} action rows for the uninstall report */
141
+ export function unwireNotch({ manifest, exec = defaultExec, uid = process.getuid() }) {
142
+ const actions = [];
143
+ for (const row of manifest.removeWhere((r) => r.kind === 'launch-agent')) {
144
+ // The label rides the recorded file name — unwire boots out exactly what wire named.
145
+ exec.run('launchctl', ['bootout', `gui/${uid}/${path.basename(row.file, '.plist')}`]);
146
+ if (fs.existsSync(row.file)) fs.rmSync(row.file);
147
+ actions.push({ action: 'launch-agent-removed', file: row.file });
148
+ }
149
+ for (const row of manifest.removeWhere((r) => r.kind === 'notch-app')) {
150
+ if (fs.existsSync(row.file)) fs.rmSync(row.file, { recursive: true, force: true });
151
+ actions.push({ action: 'notch-app-removed', file: row.file });
152
+ }
153
+ return actions;
154
+ }
package/src/pager.mjs ADDED
@@ -0,0 +1,178 @@
1
+ // oathe — the breach pager (R-PAGER): the session-start digest of promises BREACHED anywhere
2
+ // on this machine. Condition-based and stateless — three org-wide reads over facts the
3
+ // substrate already holds, no cursor, no read-state, no auto-yield; a breach repeats every
4
+ // session until its condition clears, because the condition is the fact.
5
+ //
6
+ // overdue a completion asserted and still unverified past its verify_by
7
+ // (cell.unverified_past_verify_by — the R2 clock leg, at the injected instant)
8
+ // reopened a rejection nobody reclaimed: origin `reopened`, and the task's latest claim
9
+ // predates its latest rejected verification (016's next claimant never came)
10
+ // quiet an active claim whose holder has said nothing (no non-trace progress statement)
11
+ // for longer than pagerQuietHours — the claim itself counts as the first word
12
+ //
13
+ // A lapsed lease is lifecycle, not a breach. A task appears once, under its sharpest breach.
14
+ // Homes render as folders through the registry (raw ref when unregistered, `homeless` for
15
+ // a synthetic mint). The board renderers own the voice; this module owns the facts.
16
+
17
+ import { HomeBoard } from './home.mjs';
18
+ import { VERIFICATION_PREFIX } from './plans.mjs';
19
+ import { isEngineFailureSql, latestVerdictSql, latestProgressSql } from './statements.mjs';
20
+
21
+ export const BREACH_KINDS = Object.freeze(['overdue', 'reopened', 'quiet']);
22
+ export const HOMELESS_LABEL = 'homeless';
23
+ const STAMP = "'YYYY-MM-DD HH24:MI'";
24
+
25
+ export class Pager {
26
+ /**
27
+ * @param {{client: {query: Function}, identity: {orgId: string}, config: {get: Function},
28
+ * registry?: {get: Function}|null, clock?: () => Date}} o
29
+ * clock — the instant the digest reasons about; injected so a breach can be asserted at a
30
+ * stated time (a pager reading now() cannot be tested without waiting).
31
+ */
32
+ constructor({ client, identity, config, registry = null, clock = () => new Date() }) {
33
+ this.client = client;
34
+ this.orgId = identity.orgId;
35
+ this.quietHours = config.get('pagerQuietHours');
36
+ this.registry = registry;
37
+ this.clock = clock;
38
+ }
39
+
40
+ /**
41
+ * @returns {Promise<Array<{kind: 'overdue'|'reopened'|'quiet', task_id: string, objective: string,
42
+ * home: string, detail: string, at: string}>>} kind-ordered, oldest first within a kind;
43
+ * `at` is the breach's own clock (UTC) — ages render from it, never from the sentence
44
+ */
45
+ async breaches() {
46
+ const asOf = this.clock().toISOString();
47
+ const overdue = await this.#overdue(asOf);
48
+ const reopened = await this.#reopened();
49
+ const stalled = await this.#stalled();
50
+ const quiet = await this.#quiet(asOf);
51
+ // A rejected-and-unreclaimed task is also "asserted past verify_by" — but the verdict
52
+ // landed; what is breached is the reclaim. One line per task, the sharper fact wins —
53
+ // and the SHARPEST kinds lead the list (ruling 2026-08-31): rejected and stalled work
54
+ // needs a person; never-verified drains itself now that done dispatches its own
55
+ // judgment. Every consumer (digest, splash, glass) inherits this one order.
56
+ const reopenedIds = new Set(reopened.map((r) => r.task_id));
57
+ const stalledIds = new Set(stalled.map((r) => r.task_id));
58
+ return [...reopened, ...stalled,
59
+ ...overdue.filter((r) => !reopenedIds.has(r.task_id) && !stalledIds.has(r.task_id)),
60
+ ...quiet]
61
+ .map(({ kind, task_id, objective, home, detail, at }) => ({ kind, task_id, objective, home: this.#homeLabel(home), detail, at }));
62
+ }
63
+
64
+ #homeLabel(ref) {
65
+ if (ref === null || ref === undefined) return HOMELESS_LABEL;
66
+ return this.registry?.rootOf(ref) ?? ref;
67
+ }
68
+
69
+ // Verification tasks never page on their own: their overdue IS the parent's overdue line.
70
+ async #overdue(asOf) {
71
+ // "Overdue" means exactly: an assertion NOBODY HAS JUDGED. A task whose latest claim
72
+ // already received a verdict is a closed question — re-paging it as overdue invited
73
+ // re-judgment of the same rejected assertion forever (the founder's live loop,
74
+ // 2026-08-31). The substrate function stays the raw clock; this leg owns the meaning.
75
+ const { rows } = await this.client.query(
76
+ `SELECT 'overdue' AS kind, o.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
77
+ 'verification overdue since ' || to_char(o.verify_by, ${STAMP}) AS detail,
78
+ to_char(o.verify_by AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at
79
+ FROM cell.unverified_past_verify_by($2::timestamptz) o
80
+ JOIN cell.task t ON t.org_id = o.org_id AND t.task_id = o.task_id
81
+ WHERE o.org_id = $1 AND t.task_id NOT LIKE '${VERIFICATION_PREFIX}%'
82
+ AND NOT EXISTS (
83
+ SELECT 1 FROM cell.verification v
84
+ WHERE v.org_id = o.org_id AND v.task_id = o.task_id
85
+ AND v.recorded_at > (SELECT max(c.claimed_at) FROM cell.work_claim c
86
+ WHERE c.org_id = o.org_id AND c.task_id = o.task_id))
87
+ ORDER BY o.verify_by, o.task_id`,
88
+ [this.orgId, asOf]);
89
+ return rows;
90
+ }
91
+
92
+ async #reopened() {
93
+ // Pages while nobody is REDOING the work: no active claim, and no fresh assertion
94
+ // since the last rejection. A reclaim silences it only while it stays active — a
95
+ // reclaim-then-yield returns here (it used to flip to "overdue" and offer re-judgment
96
+ // of the already-rejected assertion). The verdict rides WHOLE: the reason is one
97
+ // sentence by the verdict contract; clipping is the renderer's business, not the data's.
98
+ const { rows } = await this.client.query(
99
+ `SELECT 'reopened' AS kind, t.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
100
+ coalesce(v.verdict || ' — ', '') || 'nobody has reclaimed it (last held by ' || w.principal_id || ')' AS detail,
101
+ to_char(r.last_rejected AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at
102
+ FROM cell.task t
103
+ JOIN LATERAL (
104
+ SELECT max(v2.recorded_at) AS last_rejected FROM cell.verification v2
105
+ WHERE v2.org_id = t.org_id AND v2.task_id = t.task_id AND v2.result = 'rejected'
106
+ ) r ON r.last_rejected IS NOT NULL
107
+ -- …and the rejection is the LAST WORD: a later acceptance is redemption —
108
+ -- a settled task must never page as rejected again (caught on the founder's
109
+ -- own glass: verified-and-settled rows still reading "rejected · continue").
110
+ AND NOT EXISTS (
111
+ SELECT 1 FROM cell.verification va
112
+ WHERE va.org_id = t.org_id AND va.task_id = t.task_id
113
+ AND va.result <> 'rejected' AND va.recorded_at > r.last_rejected)
114
+ JOIN LATERAL (
115
+ SELECT c.principal_id, c.claimed_at FROM cell.work_claim c
116
+ WHERE c.org_id = t.org_id AND c.task_id = t.task_id
117
+ ORDER BY c.claimed_at DESC LIMIT 1
118
+ ) w ON true
119
+ LEFT JOIN LATERAL (${latestVerdictSql({ task: 't' })}) v ON true
120
+ WHERE t.org_id = $1 AND t.origin = 'reopened'
121
+ AND NOT EXISTS (
122
+ SELECT 1 FROM cell.work_claim c2
123
+ WHERE c2.org_id = t.org_id AND c2.task_id = t.task_id AND c2.settled_at IS NULL
124
+ AND (c2.state = 'active'
125
+ OR (c2.state = 'completion_asserted' AND c2.claimed_at > r.last_rejected)))
126
+ ORDER BY w.claimed_at, t.task_id`,
127
+ [this.orgId]);
128
+ return rows;
129
+ }
130
+
131
+ // A verification whose engine died before a verdict (the run recorded the failure and
132
+ // RELEASED its claim — ruling 2026-08-30): the promise is stalled on an engine, and the
133
+ // page names the retry gesture on another one.
134
+ async #stalled() {
135
+ const { rows } = await this.client.query(
136
+ `SELECT 'stalled' AS kind, substring(t.task_id from 8) AS task_id, p.objective,
137
+ ${HomeBoard.homeSql('p')} AS home,
138
+ 'verification stalled — ' || left(s.proposition, 120)
139
+ || '; retry: /oathe:verify ' || substring(t.task_id from 8) || ' <another engine>' AS detail,
140
+ to_char(s.asserted_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at
141
+ FROM cell.task t
142
+ JOIN cell.task p ON p.org_id = t.org_id AND p.task_id = substring(t.task_id from 8)
143
+ JOIN LATERAL (
144
+ SELECT st.proposition, st.asserted_at FROM cell.agent_statement st
145
+ WHERE st.org_id = t.org_id AND st.task_id = t.task_id
146
+ AND ${isEngineFailureSql('st.evidence_refs')}
147
+ ORDER BY st.asserted_at DESC LIMIT 1
148
+ ) s ON true
149
+ WHERE t.org_id = $1 AND t.task_id LIKE 'verify:%'
150
+ AND NOT EXISTS (SELECT 1 FROM cell.work_claim c
151
+ WHERE c.org_id = t.org_id AND c.task_id = t.task_id
152
+ AND (c.state = 'active' OR c.settled_at IS NOT NULL))
153
+ AND s.asserted_at > coalesce((SELECT max(c2.claimed_at) FROM cell.work_claim c2
154
+ WHERE c2.org_id = t.org_id AND c2.task_id = t.task_id
155
+ AND c2.settled_at IS NOT NULL), 'epoch')
156
+ ORDER BY s.asserted_at`,
157
+ [this.orgId]);
158
+ return rows;
159
+ }
160
+
161
+ async #quiet(asOf) {
162
+ const { rows } = await this.client.query(
163
+ `SELECT 'quiet' AS kind, t.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
164
+ w.principal_id || ' holds it, quiet for '
165
+ || floor(extract(epoch FROM ($2::timestamptz - last.at)) / 3600)::int || 'h (last word '
166
+ || to_char(last.at, ${STAMP}) || ')' AS detail,
167
+ to_char(last.at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at
168
+ FROM cell.work_claim w
169
+ JOIN cell.task t USING (org_id, task_id)
170
+ LEFT JOIN LATERAL (${latestProgressSql({ task: 't', claim: 'w' })}) p ON true
171
+ CROSS JOIN LATERAL (SELECT coalesce(p.asserted_at, w.claimed_at) AS at) last
172
+ WHERE w.org_id = $1 AND w.state = 'active' AND w.settled_at IS NULL
173
+ AND last.at < $2::timestamptz - make_interval(hours => $3)
174
+ ORDER BY last.at, t.task_id`,
175
+ [this.orgId, asOf, this.quietHours]);
176
+ return rows;
177
+ }
178
+ }
package/src/paths.mjs CHANGED
@@ -10,11 +10,17 @@ import os from 'node:os';
10
10
  import { fileURLToPath } from 'node:url';
11
11
 
12
12
 
13
+ /** The user's home as the session sees it — env first (sandboxes and hooks rebind it), then the OS. */
14
+ export function homeOf(env = process.env) {
15
+ return env.HOME || os.homedir();
16
+ }
17
+
13
18
  /**
14
19
  * @param {NodeJS.ProcessEnv} env
15
20
  * @returns {{monorepo: string|null, ddlDir: string|null, ddlSource: ('OATHE_DDL_DIR'|'vendor'|'monorepo'|null),
16
21
  * cagePath: string|null, oatheHome: string,
17
- * manifestPath: string, backupsDir: string, artifactDir: string, workRoot: string,
22
+ * manifestPath: string, registryPath: string, sessionsPath: string, welcomePath: string,
23
+ * backupsDir: string, artifactDir: string, workRoot: string,
18
24
  * packageRoot: string, pluginDir: string, mcpServerPath: string}}
19
25
  */
20
26
  export function buildPaths(env = process.env) {
@@ -39,7 +45,13 @@ export function buildPaths(env = process.env) {
39
45
  cagePath: monorepo ? path.join(monorepo, 'packages/oathe-runtime/falsifiers/acp-probe/acp-cage.mjs') : null,
40
46
  oatheHome,
41
47
  manifestPath: path.join(oatheHome, 'install-manifest.json'),
48
+ registryPath: path.join(oatheHome, 'workspaces.json'),
49
+ sessionsPath: path.join(oatheHome, 'sessions.json'),
50
+ // The one-shot welcome marker sits at the home root: ~/.oathe/notch/ is pruned to the
51
+ // current materialized key by wireNotch, which would eat a marker planted there.
52
+ welcomePath: path.join(oatheHome, 'welcome-pending.json'),
42
53
  backupsDir: path.join(oatheHome, 'backups'),
54
+ logsDir: path.join(oatheHome, 'logs'),
43
55
  artifactDir: path.join(oatheHome, 'artifacts'),
44
56
  workRoot: path.join(oatheHome, 'work'),
45
57
  packageRoot,
package/src/plans.mjs CHANGED
@@ -35,12 +35,20 @@ export function standardPlan({ verifierEngine = null } = {}) {
35
35
  };
36
36
  }
37
37
 
38
+ /** The one owner of the verification-task naming: `verify:<task>`. */
39
+ export const VERIFICATION_PREFIX = 'verify:';
40
+
38
41
  export function verificationTaskId(taskId) {
39
- return `verify:${taskId}`;
42
+ return `${VERIFICATION_PREFIX}${taskId}`;
40
43
  }
41
44
 
42
45
  export function isVerificationTask(taskId) {
43
- return taskId.startsWith('verify:');
46
+ return taskId.startsWith(VERIFICATION_PREFIX);
47
+ }
48
+
49
+ /** The task a verification task judges, or null for a non-verification id. */
50
+ export function verifiedTaskId(taskId) {
51
+ return isVerificationTask(taskId) ? taskId.slice(VERIFICATION_PREFIX.length) : null;
44
52
  }
45
53
 
46
54
  export function verificationObjective(taskId) {
@@ -0,0 +1,110 @@
1
+ // oathe — the central workspace registry (~/.oathe/workspaces.json): the one machine-wide
2
+ // record of which folders carry a board. Hooks, the MCP server, CLI verbs, and launchers all
3
+ // upsert it on use; the init picker and doctor read it. Every mutation is load → mutate →
4
+ // atomic-write inside the shared bounded lock, and every mutation is idempotent — a lost race
5
+ // self-heals on the next session.
6
+
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ import { atomicWriteJson, withFileLock } from './fslock.mjs';
11
+ import { workspaceIdentity, workspaceRef, workspaceRoot } from './workspace.mjs';
12
+
13
+ const REGISTRY_FORMAT = 1;
14
+
15
+ export class RegistryError extends Error {
16
+ constructor(code, message, details = {}) {
17
+ super(message);
18
+ this.name = 'RegistryError';
19
+ this.code = code;
20
+ this.details = details;
21
+ }
22
+ }
23
+
24
+ export class WorkspaceRegistry {
25
+ /** @param {{registryPath: string, clock?: () => string}} o */
26
+ constructor({ registryPath, clock = () => new Date().toISOString() }) {
27
+ this.registryPath = registryPath;
28
+ this.clock = clock;
29
+ }
30
+
31
+ /** @returns {{format: number, saved_at?: string, workspaces: object}} */
32
+ load() {
33
+ if (!fs.existsSync(this.registryPath)) return { format: REGISTRY_FORMAT, workspaces: {} };
34
+ try {
35
+ return JSON.parse(fs.readFileSync(this.registryPath, 'utf8'));
36
+ } catch (e) {
37
+ throw new RegistryError('OATHE_REGISTRY_MALFORMED',
38
+ `${this.registryPath} is not valid JSON: ${e.message}`, { file: this.registryPath });
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Upsert the workspace containing `cwd`. First writer owns registered_at/registered_by;
44
+ * every writer refreshes last_seen_at, harnesses_seen, and workspace_config.
45
+ * @param {{cwd: string, source: string, harness?: string|null}} o
46
+ * @returns {Promise<object>} the row, with its `ref`
47
+ */
48
+ async register({ cwd, source, harness = null }) {
49
+ const root = workspaceRoot(cwd);
50
+ const ref = workspaceRef(cwd);
51
+ const identity = workspaceIdentity(cwd);
52
+ const row = await this.#mutate((doc, now) => {
53
+ const existing = doc.workspaces[ref];
54
+ const next = existing ?? {
55
+ root,
56
+ identity,
57
+ registered_at: now,
58
+ registered_by: source,
59
+ harnesses_seen: {},
60
+ fences: {},
61
+ };
62
+ next.last_seen_at = now;
63
+ if (harness) next.harnesses_seen = { ...next.harnesses_seen, [harness]: now };
64
+ next.workspace_config = fs.existsSync(path.join(root, '.oathe.json'));
65
+ doc.workspaces[ref] = next;
66
+ return next;
67
+ });
68
+ return { ref, ...row };
69
+ }
70
+
71
+ /** Stamp the fence version written into `file` on the workspace row. */
72
+ async recordFence(ref, file, version) {
73
+ return this.#mutate((doc) => {
74
+ const row = doc.workspaces[ref];
75
+ if (!row) {
76
+ throw new RegistryError('OATHE_REGISTRY_WORKSPACE_UNKNOWN',
77
+ `no registered workspace ${ref} to record a fence on`, { ref, file });
78
+ }
79
+ row.fences = { ...row.fences, [file]: version };
80
+ return row;
81
+ });
82
+ }
83
+
84
+ /** @returns {object|null} */
85
+ /** THE home resolver — a ws-ref's root path, or null. Every surface that needs a task's
86
+ * folder (glass rows, breach acts, the verifier's cwd) asks HERE; nobody re-derives it. */
87
+ rootOf(ref) {
88
+ return this.get(ref)?.root ?? null;
89
+ }
90
+
91
+ get(ref) {
92
+ return this.load().workspaces[ref] ?? null;
93
+ }
94
+
95
+ /** @returns {object[]} every row, each carrying its ref */
96
+ list() {
97
+ return Object.entries(this.load().workspaces).map(([ref, row]) => ({ ref, ...row }));
98
+ }
99
+
100
+ // One clock read per mutation: the row timestamps and saved_at describe the same instant.
101
+ async #mutate(fn) {
102
+ return withFileLock(this.registryPath, () => {
103
+ const doc = this.load();
104
+ const now = this.clock();
105
+ const result = fn(doc, now);
106
+ atomicWriteJson(this.registryPath, { format: REGISTRY_FORMAT, saved_at: now, workspaces: doc.workspaces });
107
+ return result;
108
+ });
109
+ }
110
+ }
@@ -1,4 +1,4 @@
1
- // oathe — deterministic clause discharge, owned by the package (the Stage 1 plan: "we already
1
+ // oathe — deterministic clause discharge, owned by the package (the design ruling: "we already
2
2
  // own STANDARD_CLAUSE_CONDITIONS; the discharge logic is ~50 lines against the DDL's
3
3
  // contract"). Shared by BOTH providers: the standalone lane calls dischargeClause directly;
4
4
  // the oathe provider composes applyRecordedVerdict over the upstream base checker. Three
@@ -1,5 +1,5 @@
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
1
+ // oathe — the runtime seam (ruling: ONE seam, never a fork). Two providers serve the
2
+ // same capability surface: OatheRuntimeProvider binds the runtime monorepo (the richer
3
3
  // semantics), StandaloneRuntimeProvider is what the public package runs on a clean machine —
4
4
  // every capability an honest implementation or a TYPED, LOUD degradation, never silent.
5
5
  // Selection is explicit config (`runtimeProvider: auto|oathe|standalone`); auto = oathe
@@ -43,7 +43,7 @@ export class OatheRuntimeProvider {
43
43
  }
44
44
 
45
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
46
+ * failing to resolve (e.g. a forgotten `npm run link-runtime` on a monorepo machine) is turned
47
47
  * into a typed, loud fact here instead of leaking out of acceptanceRuntime()/successor().
48
48
  * @returns {{ok: boolean, error?: string}} */
49
49
  probe() {
@@ -76,7 +76,7 @@ export class OatheRuntimeProvider {
76
76
  return { spawnCaged };
77
77
  }
78
78
 
79
- /** THIN WRAPPER (Stage 1 ruling, 2026-08-26): no composition logic lives here. The runtime
79
+ /** THIN WRAPPER (ruling, 2026-08-26): no composition logic lives here. The runtime
80
80
  * package owns the whole acceptance build — including the recorded-verdict checker wiring
81
81
  * that previously lived in this method — and lands as `oathe-runtime/seam` exporting
82
82
  * `buildAcceptanceRuntime({ pool }) → { SETTLE, laneFor(seatPrincipal) }`. */
@@ -131,8 +131,12 @@ export class StandaloneRuntimeProvider {
131
131
  pickup: async () => {
132
132
  throw new RuntimeError('OATHE_PICKUP_UNAVAILABLE',
133
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' });
134
+ + 'machine (runtime provider: standalone) — pickup cannot pretend; this is a preview limitation. Claim the task '
135
+ + 'instead (oathe_claim): a reclaim of rejected work returns the recovery bundle — '
136
+ + 'the rejection reason, the prior interval\'s statements, and its trace refs — and '
137
+ + 'the board (oathe_board) carries the objective and progress. On a machine with the '
138
+ + 'runtime checkout, set OATHE_MONOREPO and run `npm run link-runtime` to restore '
139
+ + 'pickup.');
136
140
  },
137
141
  close: async () => {},
138
142
  };
@@ -1,5 +1,5 @@
1
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
2
+ // contract the launcher consumes (documented in docs/PRODUCT.md and the design ruling; no
3
3
  // upstream code was read). The contract: synchronous spawnCaged({unit, env, cmd, args, cwd,
4
4
  // stdio}) → {child, enumerate(), teardownProvenEmpty()}; the child environment is REPLACED
5
5
  // (never merged) and the cage itself stamps OATHE_EXECUTION_ATTEMPT_ID; the child leads a
@@ -24,15 +24,30 @@ export function spawnCaged({ unit, env, cmd, args, cwd, stdio, graceMs = DEFAULT
24
24
  });
25
25
  const pgid = child.pid;
26
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' });
27
+ /** Liveness of the group as a kernel signal probe — kill(-pgid, 0) costs nanoseconds and
28
+ * spawns nothing. True while ANY member (stopped and zombie included) exists. This is the
29
+ * hot-path check: a full `ps -A` here made every poll a whole-system process-table scan,
30
+ * and concurrent cages contending on that scan wedged macOS's proc subsystem (measured:
31
+ * `ps` latency >45s while the test suite ran — the suite was DDoSing itself). */
32
+ const alive = () => {
33
+ try { process.kill(-pgid, 0); return true; } catch { return false; }
34
+ };
35
+
36
+ /** Kernel read of the group — member pids, [] once the scope is empty. Full-table scan:
37
+ * COLD PATH ONLY (the final proof and its failure detail), never inside a poll loop.
38
+ * By default every member counts, zombies included — matching what the alive() probe
39
+ * sees. `runnableOnly` drops zombies: an unreaped exit record can never execute again,
40
+ * but stopped (T) members still count because a SIGCONT would resume them. */
41
+ const enumerate = ({ runnableOnly = false } = {}) => {
42
+ const ps = spawnSync('ps', ['-A', '-o', 'pid=,pgid=,stat='], { encoding: 'utf8' });
30
43
  if (ps.status !== 0) {
31
44
  throw new Error(`SimpleCage cannot enumerate: ps exited ${ps.status}: ${ps.stderr}`);
32
45
  }
33
46
  return ps.stdout.split('\n')
34
- .map((line) => line.trim().split(/\s+/).map(Number))
35
- .filter(([pid, group]) => Number.isInteger(pid) && group === pgid)
47
+ .map((line) => line.trim().split(/\s+/))
48
+ .map(([pid, group, stat]) => [Number(pid), Number(group), stat ?? ''])
49
+ .filter(([pid, group, stat]) => Number.isInteger(pid) && group === pgid
50
+ && !(runnableOnly && stat.startsWith('Z')))
36
51
  .map(([pid]) => pid);
37
52
  };
38
53
 
@@ -41,20 +56,25 @@ export function spawnCaged({ unit, env, cmd, args, cwd, stdio, graceMs = DEFAULT
41
56
  };
42
57
 
43
58
  const drainUntil = async (deadline) => {
44
- while (Date.now() < deadline && enumerate().length > 0) await sleep(POLL_MS);
59
+ while (Date.now() < deadline && alive()) await sleep(POLL_MS);
45
60
  };
46
61
 
47
- /** SIGTERM → grace → SIGKILL, then RE-ENUMERATE: the emptiness is proof, not assumption. */
62
+ /** SIGTERM → grace → SIGKILL, then RE-ENUMERATE: the emptiness is proof, not assumption.
63
+ * Polling rides the signal probe; the one authoritative ps scan is the closing proof.
64
+ * The proof counts what can still EXECUTE: a KILLed leader lingers as a zombie until its
65
+ * parent reaps it (arbitrarily late on a loaded machine — the probe and the drain both
66
+ * see it), and calling that exit record a survivor fails teardowns that in fact emptied
67
+ * the scope. */
48
68
  const teardownProvenEmpty = async () => {
49
- if (enumerate().length > 0) {
69
+ if (alive()) {
50
70
  signalGroup('SIGTERM');
51
71
  await drainUntil(Date.now() + graceMs);
52
- if (enumerate().length > 0) {
72
+ if (alive()) {
53
73
  signalGroup('SIGKILL');
54
74
  await drainUntil(Date.now() + graceMs);
55
75
  }
56
76
  }
57
- const survivors = enumerate();
77
+ const survivors = enumerate({ runnableOnly: true });
58
78
  return {
59
79
  empty: survivors.length === 0,
60
80
  detail: survivors.length === 0
@@ -63,5 +83,5 @@ export function spawnCaged({ unit, env, cmd, args, cwd, stdio, graceMs = DEFAULT
63
83
  };
64
84
  };
65
85
 
66
- return { child, enumerate, teardownProvenEmpty };
86
+ return { child, alive, enumerate, teardownProvenEmpty };
67
87
  }
@@ -1,5 +1,5 @@
1
1
  // oathe — SqlAcceptanceLane: the standalone provider's settlement path. The documented
2
- // SQL-equivalent of the estate lane: our own deterministic clause discharge, then
2
+ // SQL-equivalent of the runtime's lane: our own deterministic clause discharge, then
3
3
  // INSERT cell.verification + cell.settle_work_claim in ONE transaction (now() =
4
4
  // transaction_timestamp keeps FC113/FC114 by equality). The substrate's triggers remain the
5
5
  // enforcement — this lane is a caller, not an authority: it never writes settled_at itself