@oathe/oathe 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/NOTICE +3 -4
  2. package/README.md +15 -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 +36 -105
  39. package/src/manifest.mjs +7 -3
  40. package/src/mcp/connection.mjs +218 -0
  41. package/src/mcp/oathe-tools.mjs +380 -141
  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 -7
  49. package/src/runtime/simple-cage.mjs +18 -9
  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 +1 -1
  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/handoff-splash.png +0 -0
  74. package/src/harness.mjs +0 -271
package/bin/oathe.mjs CHANGED
@@ -1,27 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
  // oathe — the subcommand router. Deliberate divergence from the monorepo's env-only bins:
3
- // oathe is a USER tool, so it speaks argv (node:util parseArgs); it keeps the estate's
3
+ // oathe is a USER tool, so it speaks argv (node:util parseArgs); it keeps the runtime's
4
4
  // machine-parseable summary line (`oathe: <verb> <status>`) as the last line of every run.
5
5
 
6
6
  import { parseArgs } from 'node:util';
7
7
 
8
- const VERBS = ['init', 'claude', 'codex', 'claim', 'ls', 'note', 'done', 'verify', 'trace', 'yield', 'config', 'doctor', 'uninstall', 'status', 'hook', 'mcp'];
8
+ import { isTraceSubjectSql } from '../src/statements.mjs';
9
+ import { byName, launchable, projectorFor, verifierCapable } from '../src/harnesses/catalog.mjs';
10
+
11
+ const VERBS = ['init', ...launchable(), 'claim', 'ls', 'note', 'amend', 'done', 'verify', 'trace', 'notch', 'yield', 'config', 'doctor', 'uninstall', 'status', 'version', 'hook', 'mcp'];
9
12
 
10
13
  const USAGE = `usage: oathe <verb> [args]
11
14
 
12
15
  verbs:
13
- init onboard installed harnesses + bring up the local cell substrate
14
- claude [--hermetic] [args…] launch interactive Claude Code inside the cage, board attached
15
- codex [--hermetic] [args…] launch interactive Codex inside the cage, board attached
16
+ init [--harness a,b] [--yes] bring up the local cell substrate + wire the harnesses you pick
17
+ ${launchable().map((name) => ` ${name.padEnd(6)} [--hermetic] [args…] launch interactive ${byName(name).displayName} inside the cage, board attached`).join('\n')}
16
18
  claim <task-id> [objective] claim a task (minting it when new — objective required then)
17
19
  ls [--all] this workspace's board (--all: every workspace)
18
20
  note <task-id> <text> [ref] record a progress statement against your active claim
21
+ amend <task> "<objective>" "<why>" change what done means, on the record (active claim only)
19
22
  done <task-id> <what> [ref] assert completion (a completion statement + the substrate's terminal)
20
- verify [task] [--all] [--engine claude|codex] run the verification lane (non-author seat settles)
23
+ verify [task] [--all] [--engine ${verifierCapable().join('|')}] run the verification lane (non-author seat settles)
21
24
  trace <task-id> [--out dir] export the claim's linked session traces as ATIF trajectories
25
+ notch [--welcome] the whole machine's board + breach digest, pure JSON (only shows); --welcome replays the one-time welcome on the glass
22
26
  yield <task-id> <note> yield: the task goes back on the board, unowned
23
- doctor verify every managed surface against the install manifest
27
+ doctor [--surface] verify every managed surface (--surface: the resolution report only)
24
28
  status the substrate half of doctor
29
+ version the package version (upgrade: npm i -g @oathe/oathe@latest && oathe init)
25
30
  config <key> [value] [--global] read or write a config key (workspace scope by default)
26
31
  uninstall [--purge-db] remove exactly what init recorded (the database stays put)
27
32
  hook <name> · mcp internal: the plugin's hook/server entry points (bin-addressed)
@@ -38,60 +43,102 @@ function fail(verb, e) {
38
43
  process.exit(1);
39
44
  }
40
45
 
46
+ // An unknown flag refuses loudly with the verb's usable flags, derived from the same options
47
+ // the verb parses with — never a raw parse error (fresh-user-trial ruling, 2026-08-29).
48
+ function parseFlags(verb, spec) {
49
+ try {
50
+ return parseArgs(spec);
51
+ } catch (e) {
52
+ if (e?.code !== 'ERR_PARSE_ARGS_UNKNOWN_OPTION') throw e;
53
+ const flags = Object.entries(spec.options ?? {})
54
+ .map(([name, opt]) => `--${name}${opt.type === 'string' ? ' <value>' : ''}`).join(', ');
55
+ const flag = /'(--?[^']*)'/.exec(e.message)?.[1] ?? 'flag';
56
+ const err = new Error(`unknown option '${flag}' refused — ${verb} takes: ${flags || 'no flags'}`);
57
+ err.code = 'OATHE_UNKNOWN_FLAG';
58
+ throw err;
59
+ }
60
+ }
61
+
41
62
  async function toolsForCwd(env = process.env) {
42
- const [{ buildContext }, { createOatheTools }, { workspaceRef }] = await Promise.all([
43
- import('../src/context.mjs'), import('../src/mcp/oathe-tools.mjs'), import('../src/workspace.mjs'),
63
+ const [{ buildContext }, { createOatheTools }, { WorkspaceResolver }, { WorkspaceRegistry }, { ActivationSeam }, { homeOf }, { resolveSpeaker }, { verifierSeam }] = await Promise.all([
64
+ import('../src/context.mjs'), import('../src/mcp/oathe-tools.mjs'), import('../src/workspace-resolver.mjs'),
65
+ import('../src/registry.mjs'), import('../src/activation.mjs'), import('../src/paths.mjs'),
66
+ import('../src/speaker.mjs'), import('../src/verify-dispatch.mjs'),
44
67
  ]);
45
68
  const ctx = buildContext({ env });
69
+ // The terminal IS the workspace: its facts (ref, synthetic) come from the one describer, and
70
+ // every verb registers it centrally through the one seam — claim activates (fences included).
71
+ const cwd = process.cwd();
72
+ const place = WorkspaceResolver.describe({ dir: cwd, home: homeOf(env) });
46
73
  return {
47
74
  ctx,
48
75
  tools: createOatheTools({
49
76
  client: ctx.substrate,
50
77
  identity: ctx.identity,
51
78
  config: ctx.config,
52
- workspace: workspaceRef(process.cwd()),
79
+ workspace: place.ref,
80
+ synthetic: place.synthetic,
81
+ // A CLI verb run from inside a harness session's shell speaks FOR that session — the
82
+ // ancestry reaches the registered harness pid; a bare terminal resolves to nulls.
83
+ speaker: resolveSpeaker({ sessionsPath: ctx.paths.sessionsPath }),
84
+ // ONE verifier seam, every surface: done's auto-dispatch works from the CLI too.
85
+ verifier: verifierSeam({
86
+ orgId: ctx.identity.orgId,
87
+ query: (sql, params) => ctx.substrate.query(sql, params),
88
+ paths: ctx.paths,
89
+ cwd,
90
+ }),
91
+ activation: new ActivationSeam({
92
+ cwd,
93
+ env,
94
+ registry: new WorkspaceRegistry({ registryPath: ctx.paths.registryPath }),
95
+ manifest: ctx.manifest,
96
+ config: ctx.config,
97
+ version: ctx.version,
98
+ synthetic: place.synthetic,
99
+ sourceFor: (tool) => `cli:${tool.replace(/^oathe_/, '')}`,
100
+ }),
53
101
  }),
54
102
  };
55
103
  }
56
104
 
57
105
  const handlers = {
58
- async init() {
106
+ async init(argv) {
107
+ const { values } = parseFlags('init', {
108
+ args: argv,
109
+ options: { harness: { type: 'string' }, yes: { type: 'boolean', default: false } },
110
+ allowPositionals: false,
111
+ });
59
112
  const { runInit } = await import('../src/init.mjs');
60
- const result = await runInit({});
61
- const tty = process.stdout.isTTY === true;
62
- const B = tty ? '\x1b[1m' : '';
63
- const D = tty ? '\x1b[2m' : '';
64
- const G = tty ? '\x1b[32m' : '';
65
- const R = tty ? '\x1b[0m' : '';
66
- const ok = `${G}✓${R}`;
67
- const s = result.substrate;
68
- const lines = ['', ` ${B}⚡ Oathe is up${R}`, ''];
69
- lines.push(` ${ok} ${B}substrate${R} ${D}db up · ${s.ddl_applied}/${s.ddl_expected} schema applied · verification lane ready${R}`);
70
- if (!s.yield_cause_registered) {
71
- lines.push(` ${B}! yield cause MISSING${R} — run \`oathe doctor\` before claiming work`);
113
+ const result = await runInit({
114
+ harnessFilter: values.harness ? values.harness.split(',').map((s) => s.trim()).filter(Boolean) : null,
115
+ assumeYes: values.yes === true,
116
+ });
117
+ process.stdout.write('oathe init — done\n');
118
+ for (const step of result.steps) {
119
+ // Paths were disclosed on the screen before Enter; `oathe doctor` is the audit (ruling 2026-08-29).
120
+ const detail = step.outcome === 'wired' ? 'wired'
121
+ : step.outcome === 'unwired' ? 'unwired'
122
+ : `skipped — ${step.reason}`;
123
+ process.stdout.write(` ${step.displayName.padEnd(13)} ${detail}\n`);
72
124
  }
73
- for (const c of result.census) {
74
- const wired = result.actions.filter((a) => a.harness === c.name).length;
75
- lines.push(c.installed
76
- ? ` ${ok} ${B}${c.name.padEnd(9)}${R} ${D}onboarded (${wired} surface${wired === 1 ? '' : 's'} wired, reversible)${R}`
77
- : ` ${D}– ${c.name.padEnd(9)} not installed — skipped${R}`);
125
+ process.stdout.write(` verifier ${result.verifier_engine.chosen}\n`);
126
+ const s = result.substrate;
127
+ process.stdout.write(` substrate: db up, ddl ${s.ddl_applied}/${s.ddl_expected} applied `
128
+ + `(source: ${s.ddl_source}), yield cause ${s.yield_cause_registered ? 'registered' : 'MISSING'}\n`);
129
+ process.stdout.write(` principal: ${result.principal.principal_id} (${result.principal.role})\n`);
130
+ // The surface note lives here, once: the screen showed only the row.
131
+ for (const surface of result.surfaces.filter((x) => x.detected)) {
132
+ process.stdout.write(`\n${surface.displayName} — detected; nothing to wire:\n${surface.steps.split('\n').map((l) => ` ${l}`).join('\n')}\n`);
78
133
  }
79
- lines.push(` ${ok} ${B}you${R} ${D}${result.principal.principal_id}${R}`);
80
- lines.push('');
81
- lines.push(` Next: ${B}oathe claude${R} ${D}(or codex)${R} in any project — the board rides every session.`);
82
- lines.push(` Claim before you build: ${B}oathe claim <task> "what done means"${R}`);
83
- lines.push('');
84
- process.stdout.write(`${lines.join('\n')}\n`);
134
+ // The moment after init (live polish #7): what to do next, coloured only on a TTY.
135
+ const tty = process.stdout.isTTY === true;
136
+ const [B, D, R] = tty ? ['\x1b[1m', '\x1b[2m', '\x1b[0m'] : ['', '', ''];
137
+ const [first, ...rest] = launchable();
138
+ process.stdout.write(`\n Next: ${B}oathe ${first}${R} ${D}(or ${rest.join(', ')})${R} in any project — the board rides every session.\n`);
85
139
  summary('init', 'ok');
86
140
  },
87
141
 
88
- async claude(argv) {
89
- return launchHarness('claude', argv);
90
- },
91
-
92
- async codex(argv) {
93
- return launchHarness('codex', argv);
94
- },
95
142
 
96
143
  async hook(argv) {
97
144
  const scripts = {
@@ -123,7 +170,7 @@ const handlers = {
123
170
  },
124
171
 
125
172
  async ls(argv) {
126
- const { values } = parseArgs({
173
+ const { values } = parseFlags('ls', {
127
174
  args: argv, options: { all: { type: 'boolean', default: false } }, allowPositionals: true,
128
175
  });
129
176
  const { ctx, tools } = await toolsForCwd();
@@ -142,6 +189,19 @@ const handlers = {
142
189
  }
143
190
  },
144
191
 
192
+ async amend(argv) {
193
+ const [taskId, objective, why] = argv;
194
+ if (!taskId || !objective || !why) throw new Error('usage: oathe amend <task-id> "<new objective>" "<why>"');
195
+ const { ctx, tools } = await toolsForCwd();
196
+ try {
197
+ const out = await tools.oathe_amend({ task_id: taskId, objective, why });
198
+ process.stdout.write(`amended to v${out.version} — ${out.note}\n`);
199
+ summary('amend', 'ok');
200
+ } finally {
201
+ await ctx.substrate.close();
202
+ }
203
+ },
204
+
145
205
  async note(argv) {
146
206
  const [taskId, proposition, evidenceRef] = argv;
147
207
  if (!taskId || !proposition) throw new Error('usage: oathe note <task-id> <text> [evidence-ref]');
@@ -162,22 +222,48 @@ const handlers = {
162
222
  try {
163
223
  const out = await tools.oathe_done({ task_id: taskId, proposition, evidence_ref: evidenceRef });
164
224
  process.stdout.write(`done: ${out.task_id} — ${out.note}\n`);
165
- summary('done', 'ok');
225
+ // The blocked verdict, for the human (ruling 2026-08-31: locally, done owes its answer).
226
+ const v = out.verification;
227
+ if (v?.verdict) {
228
+ process.stdout.write(`verdict: ${v.verdict} — ${v.reason}\n`);
229
+ if (v.your_options) process.stdout.write(`next: ${v.your_options}\n`);
230
+ } else if (v?.failed) {
231
+ process.stdout.write(`verification failed: ${v.reason}\n`);
232
+ }
233
+ summary('done', v?.verdict === 'rejected' || v?.failed ? 'attention' : 'ok');
166
234
  } finally {
167
235
  await ctx.substrate.close();
168
236
  }
169
237
  },
170
238
 
171
239
  async verify(argv) {
172
- const { values, positionals } = parseArgs({
240
+ const { values, positionals } = parseFlags('verify', {
173
241
  args: argv,
174
- options: { all: { type: 'boolean', default: false }, engine: { type: 'string' } },
242
+ options: { all: { type: 'boolean', default: false }, engine: { type: 'string' }, detach: { type: 'boolean', default: false } },
175
243
  allowPositionals: true,
176
244
  });
177
245
  const [{ buildContext }, { Verifier }, { workspaceRef }] = await Promise.all([
178
246
  import('../src/context.mjs'), import('../src/verifier.mjs'), import('../src/workspace.mjs'),
179
247
  ]);
180
248
  const ctx = buildContext({});
249
+ // --detach: the judgment survives its terminal — one dispatcher, same as MCP and the
250
+ // glass; closing the window can never orphan a verify claim again.
251
+ if (values.detach === true) {
252
+ if (!positionals[0]) throw new Error('usage: oathe verify --detach <task-id>');
253
+ const { dispatchVerification } = await import('../src/verify-dispatch.mjs');
254
+ try {
255
+ const out = await dispatchVerification({
256
+ taskId: positionals[0], engine: values.engine ?? null, orgId: ctx.identity.orgId,
257
+ query: (sql, params) => ctx.substrate.query(sql, params),
258
+ paths: ctx.paths, cwd: process.cwd(), env: process.env,
259
+ });
260
+ process.stdout.write(`dispatched — the verdict lands on the glass. Log: ${out.log}\n`);
261
+ summary('verify', 'ok');
262
+ } finally {
263
+ await ctx.substrate.close();
264
+ }
265
+ return;
266
+ }
181
267
  const verifier = new Verifier({
182
268
  substrate: ctx.substrate, paths: ctx.paths, config: ctx.config,
183
269
  workspace: workspaceRef(process.cwd()),
@@ -201,13 +287,13 @@ const handlers = {
201
287
  },
202
288
 
203
289
  async trace(argv) {
204
- const { values, positionals } = parseArgs({
290
+ const { values, positionals } = parseFlags('trace', {
205
291
  args: argv, options: { out: { type: 'string' } }, allowPositionals: true,
206
292
  });
207
293
  const [taskId] = positionals;
208
294
  if (!taskId) throw new Error('usage: oathe trace <task-id> [--out <dir>]');
209
- const [{ buildContext }, { projectorFor }, { workspaceRef }, fs, path] = await Promise.all([
210
- import('../src/context.mjs'), import('../src/atif.mjs'), import('../src/workspace.mjs'),
295
+ const [{ buildContext }, { workspaceRef }, fs, path] = await Promise.all([
296
+ import('../src/context.mjs'), import('../src/workspace.mjs'),
211
297
  import('node:fs'), import('node:path'),
212
298
  ]);
213
299
  const ctx = buildContext({});
@@ -220,7 +306,7 @@ const handlers = {
220
306
  const claim = claims[0];
221
307
  const { rows: traceRows } = await ctx.substrate.query(
222
308
  `SELECT evidence_refs FROM cell.agent_statement
223
- WHERE org_id = $1 AND work_claim_id = $2 AND subject_ref LIKE 'trace:%'`,
309
+ WHERE org_id = $1 AND work_claim_id = $2 AND ${isTraceSubjectSql('subject_ref')}`,
224
310
  [ctx.identity.orgId, claim.work_claim_id]);
225
311
  const { rows: verdicts } = await ctx.substrate.query(
226
312
  `SELECT result, verifier_principal, verification_id FROM cell.verification
@@ -228,8 +314,9 @@ const handlers = {
228
314
  [ctx.identity.orgId, taskId]);
229
315
  const files = traceRows.flatMap((r) => r.evidence_refs);
230
316
  if (files.length === 0) throw new Error(`'${taskId}' has no linked traces — nothing to export`);
231
- const trajectories = files.map((file) => {
232
- const trajectory = projectorFor(file).project(file);
317
+ const trajectories = [];
318
+ for (const file of files) {
319
+ const trajectory = (await projectorFor(file)).project(file);
233
320
  Object.assign(trajectory.extra.oathe, {
234
321
  org_id: ctx.identity.orgId,
235
322
  task_id: taskId,
@@ -238,8 +325,8 @@ const handlers = {
238
325
  workspace: workspaceRef(process.cwd()),
239
326
  ...(verdicts[0] ? { verdict: verdicts[0] } : {}),
240
327
  });
241
- return trajectory;
242
- });
328
+ trajectories.push(trajectory);
329
+ }
243
330
  if (values.out) {
244
331
  fs.mkdirSync(values.out, { recursive: true });
245
332
  for (const [at, trajectory] of trajectories.entries()) {
@@ -257,6 +344,221 @@ const handlers = {
257
344
  }
258
345
  },
259
346
 
347
+ // The notch feed: machine board + breach digest, pure JSON on stdout (trailer on stderr,
348
+ // the trace precedent). Workspace-less by construction — buildContext({cwd: null}) is the
349
+ // global bootstrap — and seamless: no activation, no registry write; it only SHOWS
350
+ // (R-PAGER kinship: resurfacing is fact-paged; this verb is the facts, not a dashboard).
351
+ // One flag: --serve LISTENs on the wire and streams one ndjson frame per speech act
352
+ // (receipts ride the frame that caused them), plus a heartbeat frame as drift guard;
353
+ // it exits when the supervisor (the notch app) closes stdin.
354
+ async notch(argv) {
355
+ const { values } = parseFlags('notch', {
356
+ args: argv, options: { serve: { type: 'boolean', default: false }, welcome: { type: 'boolean', default: false } }, allowPositionals: false,
357
+ });
358
+ if (values.welcome && values.serve) {
359
+ const err = new Error('--welcome with --serve refused — the feed consumes the welcome; the flag plants it for a live feed to play');
360
+ err.code = 'OATHE_NOTCH_WELCOME_SERVE';
361
+ throw err;
362
+ }
363
+ const [{ buildContext }, { renderBoard }, { Pager }, { WorkspaceRegistry }, { WIRE_CHANNEL, noticeFor, emit }, { plantWelcome, consumeWelcome }] = await Promise.all([
364
+ import('../src/context.mjs'), import('../src/board-render.mjs'),
365
+ import('../src/pager.mjs'), import('../src/registry.mjs'), import('../src/wire.mjs'),
366
+ import('../src/welcome.mjs'),
367
+ ]);
368
+ const ctx = buildContext({ cwd: null });
369
+ if (values.welcome) {
370
+ // The demo/replay lever: plant the one-shot marker, nudge the wire. Same path as the
371
+ // real first run — a live feed consumes it on its very next frame; with no feed up,
372
+ // the marker waits for the next serve start. emit is fail-soft by the wire's ruling.
373
+ plantWelcome({ paths: ctx.paths, by: 'cli' });
374
+ try {
375
+ await emit(ctx.substrate, { kind: 'welcome' });
376
+ } finally {
377
+ await ctx.substrate.close().catch(() => {});
378
+ }
379
+ process.stdout.write('welcome queued — a live glass plays it now; otherwise on its next start\n');
380
+ process.stderr.write('oathe: notch ok\n');
381
+ return;
382
+ }
383
+ const registry = new WorkspaceRegistry({ registryPath: ctx.paths.registryPath });
384
+ // MOTION (founder ruling, 2026-08-30): a row on the glass means a LIVE session — a claim
385
+ // whose last word is younger than notchMotionMinutes, or one the wire just heard (serve
386
+ // mode overlays `heard`, ephemeral by design). Idle-held work is `oathe ls`'s business.
387
+ const { ownerOfTracePath, surfaceForSession, launchable: launchableNames } = await import('../src/harnesses/catalog.mjs');
388
+ const { SessionRegistry, pidAlive } = await import('../src/sessions.mjs');
389
+ const sessionsReg = new SessionRegistry({ sessionsPath: ctx.paths.sessionsPath });
390
+ // A broken sessions file costs the frame its session refs, never the frame.
391
+ const loadSessions = () => {
392
+ try { return sessionsReg.load().sessions; } catch (e) {
393
+ process.stderr.write(`oathe notch: sessions ${String(e?.message || e).slice(0, 120)}\n`);
394
+ return {};
395
+ }
396
+ };
397
+ const launchables = launchableNames();
398
+ const defaultAgent = ctx.config.get('defaultAgent');
399
+ const TERMINAL_FALLBACK = '/System/Applications/Utilities/Terminal.app'; // the system terminal — an OS fact
400
+ const shellQuote = (s) => `'${String(s).replaceAll("'", "'\\''")}'`;
401
+ const heard = new Map(); // task → {at, via}: what the wire heard, ephemeral by design
402
+ const motionWindowMs = ctx.config.get('notchMotionMinutes') * 60_000;
403
+ const moving = (r) => (heard.get(r.task_id)?.at ?? 0) > Date.now() - motionWindowMs
404
+ || (r.last_word_at && Date.parse(r.last_word_at) > Date.now() - motionWindowMs);
405
+ // Continue is a RESUMPTION, never a shrug (founder ruling 2026-08-30): activate the
406
+ // living app; else spawn the agent at the task's home in a terminal; else open the
407
+ // desktop app; else the clipboard is the act. The package decides — the glass executes.
408
+ const resumeFor = (base, ref) => {
409
+ if (ref?.alive && ref.app_pid !== null && ref.app_pid !== undefined) {
410
+ // The bundle rides along: macOS may deny a background app's activate (cooperative
411
+ // activation) — opening the bundle is the permission-free fallback that still switches.
412
+ return { kind: 'activate', app_pid: ref.app_pid, bundle: ref.bundle ?? null };
413
+ }
414
+ const surface = ref?.surface ?? base.surface;
415
+ const agent = launchables.includes(surface) ? surface
416
+ : (launchables.includes(defaultAgent) ? defaultAgent : null);
417
+ if (agent && typeof base.home_path === 'string' && base.home_path.startsWith('/')) {
418
+ return {
419
+ kind: 'spawn-terminal',
420
+ command: `oathe ${agent} ${shellQuote(`continue ${base.task_id}`)}`,
421
+ cwd: base.home_path,
422
+ terminal_bundle: ref?.bundle ?? TERMINAL_FALLBACK,
423
+ };
424
+ }
425
+ if (ref?.bundle) return { kind: 'open-app', bundle: ref.bundle };
426
+ return { kind: 'copy-only' };
427
+ };
428
+ const glassRow = (r, sess) => {
429
+ const row = (r.trace_session_id && sess[r.trace_session_id]) || null;
430
+ const h = heard.get(r.task_id);
431
+ // The durable registry row outranks the wire's ephemeral word; either way the ref
432
+ // carries surface + the focusable app, so a HOMELESS task heard from a living app
433
+ // (ChatGPT's embedded codex — no hooks, no registry row) still resolves to a switch.
434
+ const ref = row !== null ? {
435
+ surface: surfaceForSession({ ancestry: row.ancestry, app: row.app, transcriptPath: row.transcript_path }),
436
+ app_pid: row.app?.pid ?? null,
437
+ bundle: row.app?.bundle ?? null,
438
+ alive: pidAlive(row.pid),
439
+ } : (h?.app ? {
440
+ surface: h.via ?? null,
441
+ app_pid: h.app.pid ?? null,
442
+ bundle: h.app.bundle ?? null,
443
+ alive: h.app.pid !== null && h.app.pid !== undefined && pidAlive(h.app.pid),
444
+ } : null);
445
+ const base = {
446
+ task_id: r.task_id, holder: r.principal_id, state: r.state,
447
+ last_word_at: r.last_word_at, last_progress: r.last_progress,
448
+ home_path: registry.rootOf(r.home) ?? r.home ?? 'homeless',
449
+ // The surface speaking on the claim: the wire's live word wins; the durable fallback
450
+ // is the latest trace-link statement's transcript, mapped by its owning store.
451
+ surface: heard.get(r.task_id)?.via ?? (r.trace_path ? ownerOfTracePath(r.trace_path) : null),
452
+ };
453
+ return { ...base, session: ref, resume: resumeFor(base, ref) };
454
+ };
455
+ // A breach row carries the ONE act that can change its truth (ruling 2026-08-31):
456
+ // never-judged (overdue) → dispatch the judgment, DETACHED (closing the window can't
457
+ // orphan it); engine-failed (stalled) → retry, same dispatcher; judged-rejected
458
+ // (reopened) and gone-quiet → CONTINUE into the work (the reclaim bundle carries the
459
+ // verdict — re-judging a judged assertion is the one act that can never help).
460
+ // Home is the ONE resolver's answer; a homeless judgment runs from the operator's home.
461
+ const { homeOf } = await import('../src/paths.mjs');
462
+ const glassBreach = (b) => {
463
+ const home = typeof b.home === 'string' && b.home.startsWith('/') ? b.home : null;
464
+ let act = { kind: 'copy-only' };
465
+ if (b.kind === 'overdue' || b.kind === 'stalled') {
466
+ act = { kind: 'spawn-terminal', command: `oathe verify --detach ${shellQuote(b.task_id)}`, cwd: home ?? homeOf(), terminal_bundle: TERMINAL_FALLBACK };
467
+ } else if (home !== null && launchables.includes(defaultAgent)) {
468
+ act = { kind: 'spawn-terminal', command: `oathe ${defaultAgent} ${shellQuote(`continue ${b.task_id}`)}`, cwd: home, terminal_bundle: TERMINAL_FALLBACK };
469
+ }
470
+ return { ...b, act };
471
+ };
472
+ const frame = async () => {
473
+ const breaches = (await new Pager({ client: ctx.substrate, identity: ctx.identity, config: ctx.config, registry }).breaches())
474
+ .map(glassBreach);
475
+ const { message, sections } = await renderBoard({
476
+ client: ctx.substrate, identity: ctx.identity, workspace: null, config: ctx.config, all: true, breaches,
477
+ });
478
+ const sess = loadSessions();
479
+ return {
480
+ push: message,
481
+ breaches,
482
+ // motion = anyone's active claim with a recent word (or heard live on the wire);
483
+ // idle = YOUR held claims gone quiet — the sheet shows them after motion, aged.
484
+ motion: [...sections.mine, ...sections.held].filter(moving).map((r) => glassRow(r, sess)),
485
+ idle: sections.mine.filter((r) => !moving(r)).map((r) => glassRow(r, sess)),
486
+ sections,
487
+ workspace: null,
488
+ };
489
+ };
490
+ if (!values.serve) {
491
+ try {
492
+ process.stdout.write(`${JSON.stringify(await frame())}\n`);
493
+ process.stderr.write('oathe: notch ok\n');
494
+ } finally {
495
+ await ctx.substrate.close();
496
+ }
497
+ return;
498
+ }
499
+ const { default: pg } = await import('pg');
500
+ const write = (f) => process.stdout.write(`${JSON.stringify(f)}\n`);
501
+ // The one-shot welcome rides the next frame after a SUCCESSFUL build — consume-on-emit,
502
+ // never on failure, so a broken frame cannot eat the shot (and a KeepAlive restart
503
+ // cannot replay it: the marker is gone the moment it is spoken).
504
+ const serveFrame = async () => {
505
+ const f = await frame();
506
+ const welcome = consumeWelcome({ paths: ctx.paths });
507
+ if (welcome) f.welcome = welcome;
508
+ return f;
509
+ };
510
+ const listener = new pg.Client(ctx.substrate.connectionConfig());
511
+ await listener.connect();
512
+ await listener.query(`LISTEN ${WIRE_CHANNEL}`);
513
+ let beat = null;
514
+ let closing = false;
515
+ // The trailer tells the truth (fail loud): only a clean stdin-close is ok; a lost
516
+ // wire or dead substrate exits nonzero so the supervisor's restart means something.
517
+ const shutdown = async (status = 'ok', code = 0) => {
518
+ if (closing) return;
519
+ closing = true;
520
+ if (beat) clearInterval(beat);
521
+ await listener.end().catch(() => {});
522
+ await ctx.substrate.close().catch(() => {});
523
+ process.stderr.write(`oathe: notch ${status}\n`);
524
+ process.exit(code);
525
+ };
526
+ // A TRANSIENT substrate failure (a Postgres restart, a locked table) must never kill
527
+ // the feed — the error is a typed stderr note and the next event/heartbeat retries.
528
+ // A DEAD CONNECTION is fatal-but-clean: exit nonzero; the app's backoff restart is
529
+ // the recovery. (An unguarded rejection here used to kill the process with no
530
+ // trailer at all — the review's SERVE-CRASH finding.)
531
+ const guarded = (label, fn) => async (...args) => {
532
+ try {
533
+ await fn(...args);
534
+ } catch (e) {
535
+ process.stderr.write(`oathe notch: ${label} failed (${String(e?.message || e).slice(0, 160)}) — serving continues\n`);
536
+ }
537
+ };
538
+ listener.on('notification', guarded('wire frame', async (msg) => {
539
+ let ev = null;
540
+ try { ev = JSON.parse(msg.payload); } catch { /* a foreign payload nudges, it does not speak */ }
541
+ if (ev?.task_id) heard.set(ev.task_id, { at: Date.now(), via: ev.via ?? null, app: ev.app ?? null }); // the wire IS liveness
542
+ const f = await serveFrame();
543
+ // The event's own notice rides the frame it caused — the glass PULSES its tone and
544
+ // keeps the words for the sheet (never expanding the bar; founder ruling 2026-08-31).
545
+ const notice = ev?.task_id ? noticeFor(ev.kind, ev.task_id, ev.via) : null;
546
+ if (notice) f.notice = notice;
547
+ write(f);
548
+ }));
549
+ listener.on('error', (e) => {
550
+ process.stderr.write(`oathe notch: wire lost (${String(e?.message || e).slice(0, 120)})\n`);
551
+ shutdown('error', 1);
552
+ });
553
+ beat = setInterval(guarded('heartbeat frame', async () => write(await serveFrame())), ctx.config.get('notchHeartbeatSeconds') * 1000);
554
+ write(await serveFrame());
555
+ process.stdin.resume();
556
+ process.stdin.on('end', shutdown);
557
+ process.stdin.on('close', shutdown);
558
+ process.on('SIGTERM', shutdown);
559
+ process.on('SIGINT', shutdown);
560
+ },
561
+
260
562
  async yield(argv) {
261
563
  const [taskId, note] = argv;
262
564
  if (!taskId || !note) throw new Error('usage: oathe yield <task-id> <note>');
@@ -271,26 +573,60 @@ const handlers = {
271
573
  },
272
574
 
273
575
  async config(argv) {
274
- const { values, positionals } = parseArgs({
576
+ const { values, positionals } = parseFlags('config', {
275
577
  args: argv, options: { global: { type: 'boolean', default: false } }, allowPositionals: true,
276
578
  });
277
579
  const [key, raw] = positionals;
278
580
  if (!key) throw new Error('usage: oathe config <key> [value] [--global]');
279
- const { OatheConfig, CONFIG_KEYS } = await import('../src/config.mjs');
581
+ const { OatheConfig } = await import('../src/config.mjs');
280
582
  const cfg = new OatheConfig({});
281
583
  if (raw === undefined) {
282
584
  process.stdout.write(`${key} = ${JSON.stringify(cfg.get(key)).replaceAll('"', '')}\n`);
283
585
  } else {
284
- const value = /^\d+$/.test(raw) ? Number(raw) : raw;
586
+ // Each key's OWN coercion (booleans, numbers, null) — set() still validates typed.
587
+ const value = OatheConfig.coerce(key, raw);
285
588
  const out = cfg.set(key, value, { scope: values.global ? 'global' : 'workspace' });
286
589
  process.stdout.write(`${key} = ${raw} (${out.file})\n`);
287
590
  }
288
591
  summary('config', 'ok');
289
592
  },
290
593
 
291
- async doctor() {
594
+ async version() {
595
+ const [{ buildPaths }, { packageVersion }] = await Promise.all([import('../src/paths.mjs'), import('../src/context.mjs')]);
596
+ process.stdout.write(`${packageVersion(buildPaths(process.env))}\n`);
597
+ summary('version', 'ok');
598
+ },
599
+
600
+ async doctor(argv) {
601
+ const { values } = parseFlags('doctor', {
602
+ args: argv, options: { surface: { type: 'boolean', default: false } }, allowPositionals: false,
603
+ });
604
+ if (values.surface) {
605
+ // The per-surface resolution report: no substrate contact — this must answer on ANY
606
+ // machine, from ANY harness's spawn environment, exactly as the MCP server would see it.
607
+ const { runSurfaceReport } = await import('../src/doctor.mjs');
608
+ const report = await runSurfaceReport({});
609
+ for (const [name, value] of Object.entries(report.env_slice)) {
610
+ process.stdout.write(` env ${name.padEnd(22)} ${value === null ? '(unset)' : value}\n`);
611
+ }
612
+ process.stdout.write(` cwd ${process.cwd()}\n`);
613
+ if (report.resolved) {
614
+ const r = report.resolution;
615
+ process.stdout.write(`workspace: ${r.ref} via ${r.source}\n dir ${r.dir}\n root ${r.root}\n`);
616
+ for (const d of r.diagnostics) process.stdout.write(` note ${d}\n`);
617
+ process.stdout.write(`registry: ${report.registered === null ? 'unreadable'
618
+ : report.registered ? 'registered' : 'not yet registered (first use registers it)'}\n`);
619
+ } else {
620
+ process.stdout.write(`workspace: UNRESOLVED\n${report.refusal}\n`);
621
+ }
622
+ summary('doctor', report.resolved ? 'ok' : 'attention');
623
+ if (!report.resolved) process.exit(1);
624
+ return;
625
+ }
292
626
  const { runDoctor } = await import('../src/doctor.mjs');
293
627
  const result = await runDoctor({});
628
+ const caches = Object.entries(result.version.plugin).map(([name, v]) => `${name} ${v ?? 'none'}`).join('; ');
629
+ process.stdout.write(`version: ${result.version.package} (plugin cache: ${caches})\n`);
294
630
  const s = result.substrate;
295
631
  process.stdout.write(`substrate: ${s.reachable ? 'reachable' : 'UNREACHABLE'}, `
296
632
  + `db ${s.database_exists ? 'present' : 'ABSENT'}, ddl ${s.ddl_applied}/${s.ddl_expected}, `
@@ -336,7 +672,7 @@ const handlers = {
336
672
  },
337
673
 
338
674
  async uninstall(argv) {
339
- const { values } = parseArgs({
675
+ const { values } = parseFlags('uninstall', {
340
676
  args: argv, options: { 'purge-db': { type: 'boolean', default: false } }, allowPositionals: true,
341
677
  });
342
678
  const { runUninstall } = await import('../src/uninstall.mjs');
@@ -383,7 +719,9 @@ if (!verb || !VERBS.includes(verb)) {
383
719
  process.exit(2);
384
720
  }
385
721
  try {
386
- await handlers[verb](rest);
722
+ // Launch verbs come from the catalog (every adapter with a `launch` capability), not a handler each.
723
+ const handler = launchable().includes(verb) ? (argv) => launchHarness(verb, argv) : handlers[verb];
724
+ await handler(rest);
387
725
  } catch (e) {
388
726
  fail(verb, e);
389
727
  }
package/docs/PRIVACY.md CHANGED
@@ -12,13 +12,21 @@ Oathe does not crawl arbitrary files. It reads exactly these declared surfaces:
12
12
  (`plugin/hooks/heartbeat.mjs`), and `oathe verify` / `oathe trace` read the transcript
13
13
  files linked to a claim. Codex thread indexes are read through `node:sqlite` where the
14
14
  Node version provides it.
15
- - **Harness configuration it manages**: `~/.claude/settings.json` (two owned keys) and
16
- `~/.codex/config.toml` (via the codex CLI), plus the project's `CLAUDE.md`/`AGENTS.md`
17
- fenced sections.
18
- - **Its own state**: the install manifest, backups, and artifact store under `~/.oathe/`,
19
- and the workspace config (`.oathe.json`).
15
+ - **Harness configuration it manages**: `~/.claude/settings.json` (two owned keys),
16
+ `~/.codex/config.toml` (via the codex CLI), and `~/.cursor/mcp.json` + `~/.cursor/hooks.json`
17
+ (owned entries), plus the project's `CLAUDE.md`/`AGENTS.md` fenced sections.
18
+ - **Its own state**: the install manifest, backups, artifact store, and the workspace
19
+ registry (`workspaces.json` — folder path, git identity, when each harness last opened it)
20
+ under `~/.oathe/`, and the workspace config (`.oathe.json`).
20
21
  - **Git metadata** of the working directory (root, origin) to derive the workspace identity.
21
22
 
23
+ One write behavior to know about: **opening a session in a folder activates it** — the
24
+ SessionStart hook (or your first `oathe_claim` there) records the folder in the local
25
+ registry and pins the board's fenced section into that folder's `CLAUDE.md`/`AGENTS.md`,
26
+ disclosing the write in the session banner. `oathe config autoActivate false --global`
27
+ turns the file writes off (registration stays); `oathe uninstall` removes every recorded
28
+ write. Everything stays on your machine.
29
+
22
30
  ## Stores (locally, in YOUR Postgres)
23
31
 
24
32
  Task ids, objectives, claims, statements, verdicts, and transcript file **paths**.
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleIdentifier</key><string>ai.oathe.notch</string>
6
+ <key>CFBundleName</key><string>Oathe Notch</string>
7
+ <key>CFBundleExecutable</key><string>OatheNotch</string>
8
+ <key>CFBundlePackageType</key><string>APPL</string>
9
+ <key>CFBundleShortVersionString</key><string>0.1.0</string>
10
+ <key>LSMinimumSystemVersion</key><string>14.0</string>
11
+ <key>LSUIElement</key><true/>
12
+ </dict>
13
+ </plist>