@oathe/oathe 0.2.3 → 0.3.2

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 +401 -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 +160 -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
@@ -1,6 +1,6 @@
1
1
  // oathe — the session host: liveness OBSERVATION for an interactive session's cage.
2
2
  //
3
- // R1 (correction packet 2026-08-26): the host never touches ownership_valid_until — session
3
+ // R1 (ruling, 2026-08-26): the host never touches ownership_valid_until — session
4
4
  // and process liveness are not organizational acts, and a claim's horizon is set once by the
5
5
  // substrate's claim verb. Each tick asks the injected liveness probe (the cage's enumerate(),
6
6
  // kernel-read); a dead cage stops the loop and touches NOTHING — R10: an absence is an
@@ -14,12 +14,11 @@ import crypto from 'node:crypto';
14
14
  export class SessionHost {
15
15
  /**
16
16
  * @param {{client: {query: Function}, identity: {orgId: string, principalId: string},
17
- * workspace: string, liveness: () => boolean, observeIntervalMs?: number}} o
17
+ * liveness: () => boolean, observeIntervalMs?: number}} o
18
18
  */
19
- constructor({ client, identity, workspace, liveness, observeIntervalMs = 60_000 }) {
19
+ constructor({ client, identity, liveness, observeIntervalMs = 60_000 }) {
20
20
  this.client = client;
21
21
  this.identity = identity;
22
- this.workspace = workspace;
23
22
  this.liveness = liveness;
24
23
  this.observeIntervalMs = observeIntervalMs;
25
24
  this.running = false;
@@ -61,10 +60,13 @@ export class SessionHost {
61
60
  async stop({ exitCode }) {
62
61
  this.#halt();
63
62
  await this.tickInFlight;
63
+ // Custody is the PRINCIPAL's, not the folder's (R-HOME-BOARD): a claim homed elsewhere is
64
+ // still this session's to speak for. Known over-breadth: two concurrent sessions of the
65
+ // same principal both speak on each other's exits — an honest duplicate beats a lost note.
64
66
  const { rows } = await this.client.query(
65
67
  `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
+ WHERE org_id = $1 AND principal_id = $2 AND state = 'active'`,
69
+ [this.identity.orgId, this.identity.principalId]);
68
70
  for (const claim of rows) {
69
71
  await this.client.query(
70
72
  `INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
@@ -0,0 +1,168 @@
1
+ // oathe — the session liveness registry (~/.oathe/sessions.json): which LIVING process
2
+ // speaks for each harness session on THIS device. Written by hooks (SessionStart and the
3
+ // heartbeat both speak ensure() — the one convergence verb), read by the notch feed. FACTS
4
+ // ONLY —
5
+ // pids, exec paths, the nearest focusable app bundle; surface NAMES are resolved at read
6
+ // time by the harness adapters, so naming evolves without rewriting history.
7
+ //
8
+ // Liveness is device-local by ruling (2026-08-30): pids mean nothing off-device, so when
9
+ // the substrate moves to the cloud this file stays beside the processes it describes.
10
+ // It cleans itself: register() sweeps dead rows in the same mutation, and every reader
11
+ // checks pid-aliveness — no cron, no migration, no dead-process ledger.
12
+
13
+ import fs from 'node:fs';
14
+
15
+ import { atomicWriteJson, withFileLock } from './fslock.mjs';
16
+ import { defaultExec } from './harnesses/harness.mjs';
17
+
18
+ const SESSIONS_FORMAT = 1;
19
+ const ANCESTRY_DEPTH_CAP = 32; // loop guard for a corrupt ps snapshot — a bound, not a tunable
20
+
21
+ export class SessionRegistryError extends Error {
22
+ constructor(code, message, details = {}) {
23
+ super(message);
24
+ this.name = 'SessionRegistryError';
25
+ this.code = code;
26
+ this.details = details;
27
+ }
28
+ }
29
+
30
+ export function pidAlive(pid) {
31
+ try {
32
+ process.kill(pid, 0);
33
+ return true;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * The process ancestry of `pid` to pid 1 — ONE `ps` snapshot walked in memory. A darwin
41
+ * fact (`comm=` is the full exec path there; elsewhere it truncates): other platforms get
42
+ * `[]`, and so does any ps failure — the walk is fail-soft, a session without ancestry
43
+ * still registers and its pid-aliveness still serves.
44
+ * @returns {Array<{pid: number, exec: string}>} ancestry[0] is `pid` itself
45
+ */
46
+ export function processAncestry({ pid, exec = defaultExec, platform = process.platform }) {
47
+ if (platform !== 'darwin') return [];
48
+ const out = exec.run('ps', ['-axo', 'pid=,ppid=,comm=']);
49
+ if (out.status !== 0) return [];
50
+ const table = new Map();
51
+ for (const line of out.stdout.split('\n')) {
52
+ const m = line.match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
53
+ if (m) table.set(Number(m[1]), { ppid: Number(m[2]), exec: m[3] });
54
+ }
55
+ const chain = [];
56
+ let cursor = pid;
57
+ for (let depth = 0; depth < ANCESTRY_DEPTH_CAP; depth += 1) {
58
+ const row = table.get(cursor);
59
+ if (!row) break;
60
+ chain.push({ pid: cursor, exec: row.exec });
61
+ if (cursor === 1 || row.ppid === 0) break;
62
+ cursor = row.ppid;
63
+ }
64
+ return chain;
65
+ }
66
+
67
+ /**
68
+ * The nearest FOCUSABLE app process in an ancestry: exec inside `<bundle>.app/Contents/MacOS/`
69
+ * where the bundle itself is not nested inside another bundle — a helper's own `.app` is
70
+ * skipped for its host (Cursor Helper → Cursor.app). null: nothing focusable (a daemon).
71
+ * @returns {{bundle: string, pid: number}|null}
72
+ */
73
+ export function nearestAppBundle(ancestry) {
74
+ for (const { pid, exec } of ancestry) {
75
+ const m = exec.match(/^(.*\.app)\/Contents\/MacOS\/[^/]+$/);
76
+ if (m && !m[1].slice(0, -4).includes('.app/')) return { bundle: m[1], pid };
77
+ }
78
+ return null;
79
+ }
80
+
81
+ export class SessionRegistry {
82
+ /** @param {{sessionsPath: string, clock?: () => string, isAlive?: (pid: number) => boolean}} o */
83
+ constructor({ sessionsPath, clock = () => new Date().toISOString(), isAlive = pidAlive }) {
84
+ this.sessionsPath = sessionsPath;
85
+ this.clock = clock;
86
+ this.isAlive = isAlive;
87
+ }
88
+
89
+ /** @returns {{format: number, saved_at?: string, sessions: object}} */
90
+ load() {
91
+ if (!fs.existsSync(this.sessionsPath)) return { format: SESSIONS_FORMAT, sessions: {} };
92
+ try {
93
+ return JSON.parse(fs.readFileSync(this.sessionsPath, 'utf8'));
94
+ } catch (e) {
95
+ throw new SessionRegistryError('OATHE_SESSIONS_MALFORMED',
96
+ `${this.sessionsPath} is not valid JSON: ${e.message}`, { file: this.sessionsPath });
97
+ }
98
+ }
99
+
100
+ /**
101
+ * The ONE convergence verb — "this session is alive right now", from whichever hook
102
+ * fires. Unknown row → full register (the facts thunk pays for its one ps walk, and the
103
+ * same mutation sweeps every row whose pid has died — the file cleans itself). Known row
104
+ * in a NEW body (a resumed harness: same session, different pid) → re-register: process
105
+ * facts refresh, registered_at survives (first-seen is the session's birthday), and a
106
+ * fact this observer cannot know survives from the old row. Known row, same pid → a
107
+ * cheap beat: last_seen_at only, the thunk never runs.
108
+ *
109
+ * A registry with a single write moment is not a registry: a session that outlives a
110
+ * deploy, or whose file was wiped, must become visible again at its next signal.
111
+ * @param {{sessionId: string, pid: number,
112
+ * facts: () => {ancestry?: Array, app?: object|null, transcriptPath?: string, workspace?: string}}} o
113
+ */
114
+ async ensure({ sessionId, pid, facts }) {
115
+ return this.#mutate((doc, now) => {
116
+ const existing = doc.sessions[sessionId];
117
+ if (existing && existing.pid === pid) {
118
+ existing.last_seen_at = now;
119
+ return existing;
120
+ }
121
+ for (const [sid, row] of Object.entries(doc.sessions)) {
122
+ if (!this.isAlive(row.pid)) delete doc.sessions[sid];
123
+ }
124
+ const { ancestry = [], app = null, transcriptPath, workspace } = facts() ?? {};
125
+ const next = {
126
+ pid, ancestry, app,
127
+ transcript_path: transcriptPath ?? existing?.transcript_path ?? null,
128
+ workspace: workspace ?? existing?.workspace ?? null,
129
+ registered_at: existing?.registered_at ?? now,
130
+ last_seen_at: now,
131
+ };
132
+ doc.sessions[sessionId] = next;
133
+ return next;
134
+ });
135
+ }
136
+
137
+ /** @returns {object|null} */
138
+ get(sessionId) {
139
+ return this.load().sessions[sessionId] ?? null;
140
+ }
141
+
142
+ /**
143
+ * The writer's self-identification: which registered session's pid appears in MY OWN
144
+ * ancestry (nearest ancestor wins — the harness process is the speaker's parent chain).
145
+ * An unknown chain is null, never a guess; a malformed file refuses typed via load().
146
+ * @returns {{sessionId: string, row: object}|null}
147
+ */
148
+ byAncestry(ancestry) {
149
+ const { sessions } = this.load();
150
+ for (const { pid } of ancestry) {
151
+ for (const [sessionId, row] of Object.entries(sessions)) {
152
+ if (row.pid === pid) return { sessionId, row };
153
+ }
154
+ }
155
+ return null;
156
+ }
157
+
158
+ // One clock read per mutation: row timestamps and saved_at describe the same instant.
159
+ async #mutate(fn) {
160
+ return withFileLock(this.sessionsPath, () => {
161
+ const doc = this.load();
162
+ const now = this.clock();
163
+ const result = fn(doc, now);
164
+ atomicWriteJson(this.sessionsPath, { format: SESSIONS_FORMAT, saved_at: now, sessions: doc.sessions });
165
+ return result;
166
+ });
167
+ }
168
+ }