@oathe/oathe 0.4.4 → 0.4.6

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 (59) hide show
  1. package/.claude-plugin/marketplace.json +18 -2
  2. package/README.md +6 -3
  3. package/bin/oathe.mjs +199 -35
  4. package/docs/PRIVACY.md +26 -4
  5. package/notch/Oathe Notch.app/Contents/Info.plist +1 -1
  6. package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
  7. package/notch/README.md +4 -3
  8. package/package.json +5 -4
  9. package/plugin/.claude-plugin/plugin.json +21 -3
  10. package/plugin/.cursor-plugin/plugin.json +2 -2
  11. package/plugin/hooks/hooks.json +4 -4
  12. package/plugin/hooks/lib.mjs +9 -0
  13. package/plugin/hooks/render-board.mjs +4 -2
  14. package/src/blocks.mjs +10 -1
  15. package/src/board-render.mjs +7 -4
  16. package/src/breach-digest.mjs +75 -10
  17. package/src/config.mjs +18 -0
  18. package/src/context.mjs +1 -1
  19. package/src/device.mjs +106 -0
  20. package/src/doctor.mjs +101 -6
  21. package/src/engine-update.mjs +170 -0
  22. package/src/evidence-discovery.mjs +170 -0
  23. package/src/fence.mjs +3 -3
  24. package/src/harnesses/catalog.mjs +46 -4
  25. package/src/harnesses/claude.mjs +56 -4
  26. package/src/harnesses/codex-rollout.mjs +110 -21
  27. package/src/harnesses/codex.mjs +106 -19
  28. package/src/harnesses/cursor.mjs +31 -18
  29. package/src/harnesses/harness.mjs +82 -13
  30. package/src/harnesses/surfaces.mjs +2 -2
  31. package/src/home.mjs +174 -52
  32. package/src/init.mjs +27 -2
  33. package/src/launch.mjs +7 -9
  34. package/src/launchd.mjs +100 -0
  35. package/src/manifest.mjs +48 -6
  36. package/src/mcp/connection.mjs +73 -7
  37. package/src/mcp/daemon.mjs +123 -0
  38. package/src/mcp/forwarder.mjs +99 -0
  39. package/src/mcp/oathe-tools.mjs +392 -145
  40. package/src/notch-frame.mjs +118 -42
  41. package/src/notch.mjs +34 -68
  42. package/src/oathe-annotator.mjs +10 -10
  43. package/src/pager.mjs +144 -40
  44. package/src/paths.mjs +1 -0
  45. package/src/plans.mjs +44 -5
  46. package/src/registry.mjs +10 -2
  47. package/src/serve.mjs +82 -0
  48. package/src/session-host.mjs +1 -1
  49. package/src/sessions.mjs +39 -8
  50. package/src/shim.mjs +110 -0
  51. package/src/speaker.mjs +24 -5
  52. package/src/statements.mjs +116 -2
  53. package/src/traces.mjs +61 -19
  54. package/src/uninstall.mjs +20 -3
  55. package/src/update.mjs +35 -7
  56. package/src/verifier.mjs +215 -105
  57. package/src/verify-dispatch.mjs +86 -32
  58. package/src/wire.mjs +7 -1
  59. package/plugin/.mcp.json +0 -10
package/src/pager.mjs CHANGED
@@ -14,34 +14,55 @@
14
14
  //
15
15
  // A lapsed lease is lifecycle, not a breach. A task appears once, under its sharpest breach;
16
16
  // the kinds, their sharpness order (BREACH_KINDS) and the ONE comparator (breachOrder) live
17
- // with the digest (src/breach-digest.mjs) and are re-exported here beside the facts. Homes
18
- // render as folders through the registry (raw ref when unregistered, `homeless` for a
19
- // synthetic mint) and the raw ref rides beside the label. The data is whole — a verdict or
17
+ // with the digest (src/breach-digest.mjs) and are re-exported here beside the facts. Where a
18
+ // breach lives renders as its residence: a folder through the registry (raw ref when
19
+ // unregistered), an app by its display word; the raw place rides beside the label. The data is whole — a verdict or
20
20
  // an engine's words are never clipped here; clipping is the renderer's business. This
21
21
  // module owns the facts, not the voice; `digest()` hands them to the one budget.
22
22
 
23
- import { HomeBoard } from './home.mjs';
24
- import { VERIFICATION_PREFIX } from './plans.mjs';
25
- import { isEngineFailureSql, isVerifyStallSql, latestVerdictSql, latestProgressSql, spawnParentSql } from './statements.mjs';
26
- import { verifierCapable } from './harnesses/catalog.mjs';
23
+ import { HomeBoard, HomeError, Place, PlaceEvidence } from './home.mjs';
24
+ import { SYSTEM_TASKS, isSystemTaskSql } from './plans.mjs';
25
+ import { IN_FLIGHT } from './breach-digest.mjs';
26
+ import {
27
+ holdSql, isUpdateFailureSql, isVerifyStallSql, latestVerdictSql, parseEngineFailure, latestProgressSql, rejectedIntervalSql,
28
+ spawnParentSql,
29
+ } from './statements.mjs';
30
+ import { displayFor, verifierCapable } from './harnesses/catalog.mjs';
27
31
  import { BreachDigest, breachOrder } from './breach-digest.mjs';
28
32
 
29
33
  export { BREACH_KINDS, breachOrder } from './breach-digest.mjs';
30
- export const HOMELESS_LABEL = 'homeless';
31
34
  const STAMP = "'YYYY-MM-DD HH24:MI'";
32
35
 
33
36
  /**
34
- * A stall's detail: the verify child's own failure words, whole, then the retry gesture — on
35
- * another engine only when an engine (not the record) died, named concretely from the catalog.
36
- * The failed engine is read from the stall statement's fixed opening (`engine <name> failed…`,
37
- * src/verifier.mjs) — the one place that wording is minted. The kind word ("verify failed")
38
- * rides beside every rendering of this detail, so the detail does not repeat it; the retry
39
- * leads, so a renderer's clip only ever shortens the engine's words, never the act.
37
+ * A stall's detail: the verify child's own failure words, whole, behind the retry gesture.
38
+ * Config wins at every verify (ruling 2026-09-04), so the gesture is decided by ONE question:
39
+ * would a plain retry hit the same dead engine? Only when the engine that died IS the
40
+ * configured verifier — then the act is the config change, naming a concrete other engine
41
+ * from the catalog, and the retry after it. Any other stall (a record that would fail every
42
+ * engine alike, or a death on an override engine the config no longer points at) is a plain
43
+ * retry. The failed engine is read from the stall statement's fixed opening
44
+ * (`engine <name> failed…`, src/verifier.mjs) — the one place that wording is minted. The
45
+ * kind word ("verify failed") rides beside every rendering of this detail, so the detail does
46
+ * not repeat it; the gesture leads, so a renderer's clip only ever shortens the engine's words.
40
47
  */
41
- function stallDetail({ task_id, proposition, engine_stage }) {
42
- const failed = engine_stage ? /^engine (\S+) failed/.exec(proposition)?.[1] ?? null : null;
43
- const other = engine_stage ? verifierCapable().find((engine) => engine !== failed) ?? null : null;
44
- return `retry: /oathe:verify ${task_id}${other ? ` ${other}` : ''} — ${proposition}`;
48
+ function stallDetail({ task_id, proposition, engine, cause, update_failure, verifier }) {
49
+ // The cause (ruling 2026-09-05) names the honest gesture: an out-of-date engine is UPDATED (the
50
+ // glass's update ↗ runs it; the last failed update rides beside, so a click that did not help
51
+ // says why); an unreachable one is re-addressed by oathe init. Neither is "another verifier".
52
+ if (cause === 'outdated') {
53
+ const name = displayFor(engine) ?? engine;
54
+ return `${name} is out of date — update it and the judgment re-runs: oathe engine update ${engine}`
55
+ + `${update_failure ? ` — last update failed: ${update_failure}` : ''} — ${proposition}`;
56
+ }
57
+ if (cause === 'missing') {
58
+ return `${displayFor(engine) ?? engine} is not reachable from this process — run oathe init to record its address, `
59
+ + `then /oathe:verify ${task_id} — ${proposition}`;
60
+ }
61
+ if (engine !== null && engine === verifier) {
62
+ const other = verifierCapable().find((e) => e !== engine);
63
+ return `set another verifier: oathe config verifier ${other}, then /oathe:verify ${task_id} — ${proposition}`;
64
+ }
65
+ return `retry: /oathe:verify ${task_id} — ${proposition}`;
45
66
  }
46
67
 
47
68
  export class Pager {
@@ -55,6 +76,7 @@ export class Pager {
55
76
  this.client = client;
56
77
  this.orgId = identity.orgId;
57
78
  this.quietHours = config.get('pagerQuietHours');
79
+ this.verifier = config.get('verifier'); // the engine a plain retry would run — the stall gesture's one question
58
80
  this.registry = registry;
59
81
  this.clock = clock;
60
82
  }
@@ -62,9 +84,12 @@ export class Pager {
62
84
  /**
63
85
  * @returns {Promise<Array<{kind: 'reopened'|'stalled'|'overdue'|'quiet', task_id: string,
64
86
  * objective: string, home: string, home_ref: string|null, detail: string,
65
- * at: string}>>} in breachOrder; `at` is the breach's own clock (UTC) —
66
- * ages render from it, never from the sentence; `home_ref` is the raw ref a digest
67
- * scopes on, `home` the folder a person reads
87
+ * at: string, busy: boolean}>>} in breachOrder; `at` is the breach's own
88
+ * clock (UTC) — ages render from it, never from the sentence; `busy` says a system
89
+ * claim is held for this row right now — the judge's `verify:`, or the machine's
90
+ * `update:<engine>` on a stall that names that engine out of date — with `busy_word`/
91
+ * `busy_detail` from IN_FLIGHT (then `at` is that hold's start); `engine`/`cause` ride
92
+ * a stall; `home_ref` is the raw ref a digest scopes on, `home` the folder a person reads
68
93
  */
69
94
  async breaches() {
70
95
  const asOf = this.clock().toISOString();
@@ -72,26 +97,85 @@ export class Pager {
72
97
  const reopened = await this.#reopened();
73
98
  const stalled = await this.#stalled();
74
99
  const quiet = await this.#quiet(asOf);
100
+ const flight = await this.inFlight(asOf);
75
101
  // A rejected-and-unreclaimed or stalled task is also "asserted past verify_by" — but the
76
102
  // verdict (or the attempt at one) landed; what is breached is the reclaim or the retry.
77
103
  // One row per task, the sharper fact wins; the order is breachOrder's, nowhere else's.
78
104
  const judged = new Set([...reopened, ...stalled].map((r) => r.task_id));
79
105
  return [...reopened, ...stalled, ...overdue.filter((r) => !judged.has(r.task_id)), ...quiet]
80
- .map(({ kind, task_id, objective, home, detail, at, parent, parent_objective }) => ({
81
- kind, task_id, objective, home: this.#homeLabel(home), home_ref: home ?? null, detail, at,
82
- parent: parent ?? null, parent_objective: parent_objective ?? null,
83
- }))
106
+ .map(({ kind, task_id, objective, place, place_evidence, places, detail, at, parent, parent_objective, engine = null, cause = null }) => {
107
+ // Busy is a state ON the breach, never a fifth kind (rulings 2026-09-04/05): a system
108
+ // claim is held for this row — a judge on verify:<task>, or the machine on update:<engine>
109
+ // when the stall names that engine out of date — so the row keeps its kind (the overdue
110
+ // leg stays suppressed, no "never verified" twin), wears IN_FLIGHT's word, and its clock
111
+ // becomes the hold's start. The stale failure it wore is the digest's to drop.
112
+ const judge = flight.verify.get(task_id);
113
+ const updating = kind === 'stalled' && cause === 'outdated' ? flight.update.get(engine) : undefined;
114
+ const name = displayFor(engine) ?? engine;
115
+ const hold = judge !== undefined ? { at: judge, word: IN_FLIGHT.verify.word, detail: IN_FLIGHT.verify.detail }
116
+ : updating !== undefined ? { at: updating, word: IN_FLIGHT.update.word(name), detail: IN_FLIGHT.update.detail(name) }
117
+ : null;
118
+ // Where it lives (ruling 2026-09-05): the residence (last pickup) wears the word; every
119
+ // place that ever picked it up scopes it (BreachDigest.scoped).
120
+ const residence = Place.parseOrNull(place ?? null);
121
+ return {
122
+ kind, task_id, objective, detail,
123
+ home: this.#homeLabel(residence), home_ref: residence?.isFolder ? residence.ref : null,
124
+ place: residence ? String(residence) : null, places: places ?? [], ...PlaceEvidence.parse(place_evidence).row(),
125
+ at: hold?.at ?? at, busy: hold !== null, busy_word: hold?.word ?? null, busy_detail: hold?.detail ?? null,
126
+ engine, cause,
127
+ parent: parent ?? null, parent_objective: parent_objective ?? null,
128
+ };
129
+ })
84
130
  .sort(breachOrder);
85
131
  }
86
132
 
133
+ /** The residence and every place, as the four legs select them — one spelling of the columns. */
134
+ static #placeColumns(taskAlias) {
135
+ return `res.place, res.place_evidence, ${HomeBoard.placesSql(taskAlias)} AS places`;
136
+ }
137
+
138
+ static #placeJoin(taskAlias) {
139
+ return `LEFT JOIN LATERAL (${HomeBoard.residenceSql(taskAlias)}) res ON true`;
140
+ }
141
+
142
+ /**
143
+ * The system claims IN FLIGHT at `asOf` — the ONE map (UX rule 22): `verify` — a judge holding
144
+ * `verify:<task>` inside its lease (task → start), so the task's breach is busy and the board's
145
+ * `verifying` judgment is the same fact through the same SQL (holdSql); `update` — the machine
146
+ * holding `update:<engine>` (engine → start), so every stall naming that engine out of date is
147
+ * busy "updating". An active claim past its lease is a holder that died without releasing —
148
+ * not a running one; the underlying breach shows again, with its own clock.
149
+ * @returns {Promise<{verify: Map<string, string>, update: Map<string, string>}>} starts in UTC
150
+ */
151
+ async inFlight(asOf) {
152
+ const held = async (kind, subjectSql, where) => new Map((await this.client.query(
153
+ `SELECT ${subjectSql} AS subject, to_char(j.claimed_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at
154
+ FROM cell.task t
155
+ JOIN LATERAL (${holdSql({ kind, orgId: 't.org_id', subject: subjectSql, asOf: '$2::timestamptz' })}) j ON true
156
+ WHERE t.org_id = $1 AND ${where}`,
157
+ [this.orgId, asOf])).rows.map((r) => [r.subject, r.at]));
158
+ return {
159
+ verify: await held('verify', 't.task_id', `NOT ${isSystemTaskSql('t.task_id')}`),
160
+ update: await held('update', `substr(t.task_id, ${SYSTEM_TASKS.update.length + 1})`, `t.task_id LIKE '${SYSTEM_TASKS.update}%'`),
161
+ };
162
+ }
163
+
164
+
87
165
  /** The one budget over the facts — every surface that shows a breach renders this. */
88
166
  async digest() {
89
167
  return new BreachDigest({ breaches: await this.breaches() });
90
168
  }
91
169
 
92
- #homeLabel(ref) {
93
- if (ref === null || ref === undefined) return HOMELESS_LABEL;
94
- return this.registry?.rootOf(ref) ?? ref;
170
+ /** The word a place wears: a folder through the registry (else its raw ref), an app by the
171
+ * adapter's display word (else the surface). A breach is a claim's, and every claim has a
172
+ * place — a residence-less breach is a broken record, said loudly, never a third word. */
173
+ #homeLabel(residence) {
174
+ if (residence === null) {
175
+ throw new HomeError('OATHE_PLACE_UNKNOWN', 'a breached claim has no recorded place — the record is broken (every pickup records one)');
176
+ }
177
+ if (residence.isFolder) return this.registry?.rootOf(residence.ref) ?? residence.ref;
178
+ return displayFor(residence.ref) ?? residence.ref;
95
179
  }
96
180
 
97
181
  // Verification tasks never page on their own: their overdue IS the parent's overdue line.
@@ -101,14 +185,15 @@ export class Pager {
101
185
  // re-judgment of the same rejected assertion forever (the founder's live loop,
102
186
  // 2026-08-31). The substrate function stays the raw clock; this leg owns the meaning.
103
187
  const { rows } = await this.client.query(
104
- `SELECT 'overdue' AS kind, o.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
188
+ `SELECT 'overdue' AS kind, o.task_id, t.objective, ${Pager.#placeColumns('t')},
105
189
  'verification overdue since ' || to_char(o.verify_by, ${STAMP}) AS detail,
106
190
  to_char(o.verify_by AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at,
107
191
  sp.parent_task_id AS parent, sp.parent_objective
108
192
  FROM cell.unverified_past_verify_by($2::timestamptz) o
109
193
  JOIN cell.task t ON t.org_id = o.org_id AND t.task_id = o.task_id
110
194
  LEFT JOIN LATERAL (${spawnParentSql({ task: 't' })}) sp ON true
111
- WHERE o.org_id = $1 AND t.task_id NOT LIKE '${VERIFICATION_PREFIX}%'
195
+ ${Pager.#placeJoin('t')}
196
+ WHERE o.org_id = $1 AND NOT ${isSystemTaskSql('t.task_id')}
112
197
  AND NOT EXISTS (
113
198
  SELECT 1 FROM cell.verification v
114
199
  WHERE v.org_id = o.org_id AND v.task_id = o.task_id
@@ -120,18 +205,20 @@ export class Pager {
120
205
  }
121
206
 
122
207
  async #reopened() {
123
- // Pages while nobody is REDOING the work: no active claim, and no fresh assertion
124
- // since the last rejection. A reclaim silences it only while it stays active — a
125
- // reclaim-then-yield returns here, never to "overdue" (the rejected assertion is not
208
+ // Pages while nobody is REDOING the work: no active claim, and no unjudged assertion
209
+ // standing (an asserted interval the rejection was NOT over — rejectedIntervalSql, the
210
+ // interval-exact fact, never a clock). A reclaim silences it only while it stays active —
211
+ // a reclaim-then-yield returns here, never to "overdue" (the rejected assertion is not
126
212
  // owed a second judgment). The verdict rides WHOLE: the reason is one
127
213
  // sentence by the verdict contract; clipping is the renderer's business, not the data's.
128
214
  const { rows } = await this.client.query(
129
- `SELECT 'reopened' AS kind, t.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
215
+ `SELECT 'reopened' AS kind, t.task_id, t.objective, ${Pager.#placeColumns('t')},
130
216
  coalesce(v.verdict || ' — ', '') || 'nobody has reclaimed it (last held by ' || w.principal_id || ')' AS detail,
131
217
  to_char(r.last_rejected AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at,
132
218
  sp.parent_task_id AS parent, sp.parent_objective
133
219
  FROM cell.task t
134
220
  LEFT JOIN LATERAL (${spawnParentSql({ task: 't' })}) sp ON true
221
+ ${Pager.#placeJoin('t')}
135
222
  JOIN LATERAL (
136
223
  SELECT max(v2.recorded_at) AS last_rejected FROM cell.verification v2
137
224
  WHERE v2.org_id = t.org_id AND v2.task_id = t.task_id AND v2.result = 'rejected'
@@ -154,7 +241,7 @@ export class Pager {
154
241
  SELECT 1 FROM cell.work_claim c2
155
242
  WHERE c2.org_id = t.org_id AND c2.task_id = t.task_id AND c2.settled_at IS NULL
156
243
  AND (c2.state = 'active'
157
- OR (c2.state = 'completion_asserted' AND c2.claimed_at > r.last_rejected)))
244
+ OR (c2.state = 'completion_asserted' AND NOT ${rejectedIntervalSql({ claim: 'c2' })})))
158
245
  ORDER BY w.claimed_at, t.task_id`,
159
246
  [this.orgId]);
160
247
  return rows;
@@ -168,35 +255,51 @@ export class Pager {
168
255
  async #stalled() {
169
256
  const { rows } = await this.client.query(
170
257
  `SELECT 'stalled' AS kind, substring(t.task_id from 8) AS task_id, p.objective,
171
- ${HomeBoard.homeSql('p')} AS home, s.proposition, s.engine_stage,
258
+ ${Pager.#placeColumns('p')}, s.proposition, s.failure_ref, uf.update_failure,
172
259
  to_char(s.asserted_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI"Z"') AS at,
173
260
  sp.parent_task_id AS parent, sp.parent_objective
174
261
  FROM cell.task t
175
262
  JOIN cell.task p ON p.org_id = t.org_id AND p.task_id = substring(t.task_id from 8)
176
263
  LEFT JOIN LATERAL (${spawnParentSql({ task: 'p' })}) sp ON true
264
+ ${Pager.#placeJoin('p')}
177
265
  JOIN LATERAL (
178
266
  SELECT st.proposition, st.asserted_at,
179
- ${isEngineFailureSql('st.evidence_refs')} AS engine_stage
267
+ (SELECT er FROM jsonb_array_elements_text(st.evidence_refs) er WHERE er LIKE 'engine-failure:%' LIMIT 1) AS failure_ref
180
268
  FROM cell.agent_statement st
181
269
  WHERE st.org_id = t.org_id AND st.task_id = t.task_id
182
270
  AND ${isVerifyStallSql('st.evidence_refs')}
183
271
  ORDER BY st.asserted_at DESC LIMIT 1
184
272
  ) s ON true
273
+ -- The last FAILED update of the engine the stall names (its update:<engine> task's
274
+ -- statement) — a person who clicked update ↗ sees why it did not help.
275
+ LEFT JOIN LATERAL (
276
+ SELECT u.proposition AS update_failure
277
+ FROM cell.agent_statement u
278
+ WHERE u.org_id = t.org_id AND u.task_id = '${SYSTEM_TASKS.update}' || split_part(s.failure_ref, ':', 2)
279
+ AND ${isUpdateFailureSql('u.evidence_refs')}
280
+ ORDER BY u.asserted_at DESC LIMIT 1
281
+ ) uf ON true
185
282
  WHERE t.org_id = $1 AND t.task_id LIKE 'verify:%'
283
+ -- A settled verify claim closes the stall. An ACTIVE one does not hide it: that is a
284
+ -- retry in flight, rendered busy (breaches()) — hiding it here let the overdue leg
285
+ -- re-surface the task as "never verified" mid-retry (live 2026-09-04).
186
286
  AND NOT EXISTS (SELECT 1 FROM cell.work_claim c
187
287
  WHERE c.org_id = t.org_id AND c.task_id = t.task_id
188
- AND (c.state = 'active' OR c.settled_at IS NOT NULL))
288
+ AND c.settled_at IS NOT NULL)
189
289
  AND s.asserted_at > coalesce((SELECT max(c2.claimed_at) FROM cell.work_claim c2
190
290
  WHERE c2.org_id = t.org_id AND c2.task_id = t.task_id
191
291
  AND c2.settled_at IS NOT NULL), 'epoch')
192
292
  ORDER BY s.asserted_at`,
193
293
  [this.orgId]);
194
- return rows.map(({ proposition, engine_stage, ...row }) => ({ ...row, detail: stallDetail({ ...row, proposition, engine_stage }) }));
294
+ return rows.map(({ proposition, failure_ref, update_failure, ...row }) => {
295
+ const { engine, cause } = parseEngineFailure(failure_ref) ?? { engine: null, cause: null };
296
+ return { ...row, engine, cause, update_failure: update_failure ?? null, detail: stallDetail({ ...row, proposition, engine, cause, update_failure, verifier: this.verifier }) };
297
+ });
195
298
  }
196
299
 
197
300
  async #quiet(asOf) {
198
301
  const { rows } = await this.client.query(
199
- `SELECT 'quiet' AS kind, t.task_id, t.objective, ${HomeBoard.homeSql('t')} AS home,
302
+ `SELECT 'quiet' AS kind, t.task_id, t.objective, ${Pager.#placeColumns('t')},
200
303
  w.principal_id || ' holds it, quiet for '
201
304
  || floor(extract(epoch FROM ($2::timestamptz - last.at)) / 3600)::int || 'h (last word '
202
305
  || to_char(last.at, ${STAMP}) || ')' AS detail,
@@ -205,6 +308,7 @@ export class Pager {
205
308
  FROM cell.work_claim w
206
309
  JOIN cell.task t USING (org_id, task_id)
207
310
  LEFT JOIN LATERAL (${spawnParentSql({ task: 't' })}) sp ON true
311
+ ${Pager.#placeJoin('t')}
208
312
  LEFT JOIN LATERAL (${latestProgressSql({ task: 't', claim: 'w' })}) p ON true
209
313
  CROSS JOIN LATERAL (SELECT coalesce(p.asserted_at, w.claimed_at) AS at) last
210
314
  WHERE w.org_id = $1 AND w.state = 'active' AND w.settled_at IS NULL
package/src/paths.mjs CHANGED
@@ -47,6 +47,7 @@ export function buildPaths(env = process.env) {
47
47
  manifestPath: path.join(oatheHome, 'install-manifest.json'),
48
48
  registryPath: path.join(oatheHome, 'workspaces.json'),
49
49
  sessionsPath: path.join(oatheHome, 'sessions.json'),
50
+ devicePath: path.join(oatheHome, 'device.json'),
50
51
  // The one-shot welcome marker sits at the home root: ~/.oathe/notch/ is pruned to the
51
52
  // current materialized key by wireNotch, which would eat a marker planted there.
52
53
  welcomePath: path.join(oatheHome, 'welcome-pending.json'),
package/src/plans.mjs CHANGED
@@ -35,20 +35,59 @@ 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:';
38
+ /**
39
+ * The machine's OWN tasks (ruling 2026-09-05): one grammar, `<kind>:<subject>` — the judgment
40
+ * of a task (`verify:<task>`) and the update of an engine (`update:<harness>`). A system task is
41
+ * a claim like any other (that is how every surface reads "verifying"/"updating" off one fact)
42
+ * but never a WORK row: boards and pagers ask `systemTaskOf`, and no prefix literal lives
43
+ * outside this table.
44
+ */
45
+ export const SYSTEM_TASKS = Object.freeze({ verify: 'verify:', update: 'update:' });
46
+
47
+ export function systemTaskId(kind, subject) {
48
+ const prefix = SYSTEM_TASKS[kind];
49
+ if (!prefix) throw new Error(`no system task kind '${kind}' — kinds: ${Object.keys(SYSTEM_TASKS).join(', ')}`);
50
+ return `${prefix}${subject}`;
51
+ }
52
+
53
+ /** @returns {{kind: string, subject: string}|null} */
54
+ export function systemTaskOf(taskId) {
55
+ for (const [kind, prefix] of Object.entries(SYSTEM_TASKS)) {
56
+ if (taskId.startsWith(prefix)) return { kind, subject: taskId.slice(prefix.length) };
57
+ }
58
+ return null;
59
+ }
60
+
61
+ /** SQL: is `column` a system task of any kind — the one exclusion every work-row query applies. */
62
+ export function isSystemTaskSql(column) {
63
+ return `(${Object.values(SYSTEM_TASKS).map((p) => `${column} LIKE '${p}%'`).join(' OR ')})`;
64
+ }
65
+
66
+ /** The verification kind's helpers — thin calls on the grammar. */
67
+ export const VERIFICATION_PREFIX = SYSTEM_TASKS.verify;
40
68
 
41
69
  export function verificationTaskId(taskId) {
42
- return `${VERIFICATION_PREFIX}${taskId}`;
70
+ return systemTaskId('verify', taskId);
43
71
  }
44
72
 
45
73
  export function isVerificationTask(taskId) {
46
- return taskId.startsWith(VERIFICATION_PREFIX);
74
+ return systemTaskOf(taskId)?.kind === 'verify';
47
75
  }
48
76
 
49
77
  /** The task a verification task judges, or null for a non-verification id. */
50
78
  export function verifiedTaskId(taskId) {
51
- return isVerificationTask(taskId) ? taskId.slice(VERIFICATION_PREFIX.length) : null;
79
+ const system = systemTaskOf(taskId);
80
+ return system?.kind === 'verify' ? system.subject : null;
81
+ }
82
+
83
+ /** The update kind's helpers. */
84
+ export function updateTaskId(harness) {
85
+ return systemTaskId('update', harness);
86
+ }
87
+
88
+ export function updateObjective(harness, address) {
89
+ return `Update the '${harness}' CLI in place at ${address} — the engine a judgment named as out of date; `
90
+ + 'the machine claims this, runs the CLI\'s own updater, records the version before and after, and re-verifies.';
52
91
  }
53
92
 
54
93
  export function verificationObjective(taskId) {
package/src/registry.mjs CHANGED
@@ -10,7 +10,7 @@ import path from 'node:path';
10
10
  import { atomicWriteJson, withFileLock } from './fslock.mjs';
11
11
  import { workspaceIdentity, workspaceRef, workspaceRoot } from './workspace.mjs';
12
12
 
13
- const REGISTRY_FORMAT = 1;
13
+ export const REGISTRY_FORMAT = 1;
14
14
 
15
15
  export class RegistryError extends Error {
16
16
  constructor(code, message, details = {}) {
@@ -31,12 +31,20 @@ export class WorkspaceRegistry {
31
31
  /** @returns {{format: number, saved_at?: string, workspaces: object}} */
32
32
  load() {
33
33
  if (!fs.existsSync(this.registryPath)) return { format: REGISTRY_FORMAT, workspaces: {} };
34
+ let doc;
34
35
  try {
35
- return JSON.parse(fs.readFileSync(this.registryPath, 'utf8'));
36
+ doc = JSON.parse(fs.readFileSync(this.registryPath, 'utf8'));
36
37
  } catch (e) {
37
38
  throw new RegistryError('OATHE_REGISTRY_MALFORMED',
38
39
  `${this.registryPath} is not valid JSON: ${e.message}`, { file: this.registryPath });
39
40
  }
41
+ // The format is the gate (zero legacy, 2026-09-05): another oathe's file is refused by name.
42
+ if (doc?.format !== REGISTRY_FORMAT || typeof doc.workspaces !== 'object' || doc.workspaces === null) {
43
+ throw new RegistryError('OATHE_REGISTRY_FORMAT',
44
+ `${this.registryPath} is format ${JSON.stringify(doc?.format)}; this oathe reads format ${REGISTRY_FORMAT} — move it aside and run oathe init (folders re-register on use)`,
45
+ { file: this.registryPath, found: doc?.format, expected: REGISTRY_FORMAT });
46
+ }
47
+ return doc;
40
48
  }
41
49
 
42
50
  /**
package/src/serve.mjs ADDED
@@ -0,0 +1,82 @@
1
+ // oathe — the serve daemon's install lifecycle (connection-lane phase 2): the second
2
+ // consumer of the ONE launchd machinery (src/launchd.mjs). launchd runs THE SHIM
3
+ // (`~/.oathe/bin/oathe serve`) — the durable address is the program, so a node or package
4
+ // move re-stamps one file and the daemon follows on its KeepAlive restart; the daemon
5
+ // itself (src/mcp/daemon.mjs) owns the socket. Wire on init after the shim lands, unwire on
6
+ // uninstall beside the notch; each service owns exactly its own manifest rows.
7
+
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ import { defaultExec } from './harnesses/harness.mjs';
12
+ import { sha256Hex } from './manifest.mjs';
13
+ import {
14
+ serviceLabel, agentPathFor, launchAgentPlistFor, launchdJob, bootstrapWithRetry, blockingSleep,
15
+ } from './launchd.mjs';
16
+ import { shimPath } from './shim.mjs';
17
+
18
+ export const SERVE_LABEL = 'ai.oathe.serve';
19
+
20
+ export function serveLabel(home) {
21
+ return serviceLabel(home, SERVE_LABEL);
22
+ }
23
+
24
+ /** The daemon's address: the config key wins; the default lives under the oathe home. */
25
+ export function serveSocketPath(paths, config) {
26
+ return config.get('serveSocket') ?? path.join(paths.oatheHome, 'serve.sock');
27
+ }
28
+
29
+ /** launchd's word on this home's daemon. */
30
+ export function serveStatus({ home, exec = defaultExec, uid = process.getuid() }) {
31
+ return launchdJob({ label: serveLabel(home), exec, uid });
32
+ }
33
+
34
+ /** @returns {object[]} action rows for the init report; [] only off-darwin */
35
+ export function wireServe({ home, manifest, config, version, exec = defaultExec, uid = process.getuid(), sleep = blockingSleep }) {
36
+ if (process.platform !== 'darwin') return [];
37
+ const shim = shimPath(home);
38
+ if (!fs.existsSync(shim)) return [{ action: 'serve-shim-missing', file: shim }];
39
+
40
+ const label = serveLabel(home);
41
+ const file = agentPathFor(home, label);
42
+ const content = launchAgentPlistFor({ label, programArguments: [shim, 'serve'] });
43
+ fs.mkdirSync(path.dirname(file), { recursive: true });
44
+ fs.writeFileSync(file, content);
45
+
46
+ // Replaced wholesale on every wire, scoped to THIS service's rows (the notch's are
47
+ // another owner's); a replaced agent under a different name is booted out and removed.
48
+ for (const row of manifest.removeWhere((r) => r.harness === 'serve' && r.kind === 'launch-agent')) {
49
+ if (row.file !== file) {
50
+ exec.run('launchctl', ['bootout', `gui/${uid}/${path.basename(row.file, '.plist')}`]); // result unread: a replaced label that is not loaded answers 'Could not find service' — nothing to do either way
51
+ if (fs.existsSync(row.file)) fs.rmSync(row.file);
52
+ }
53
+ }
54
+ manifest.upsert({
55
+ harness: 'serve', file, kind: 'launch-agent', scope: 'user',
56
+ detail: { program: shim }, blockVersion: version, sha256: sha256Hex(content),
57
+ });
58
+
59
+ // A re-run is the restart: bootout may fail (not loaded); whether the OLD job is gone is
60
+ // asked by retrying bootstrap until launchd takes the new one (the 0.4.4 lesson).
61
+ exec.run('launchctl', ['bootout', `gui/${uid}/${label}`]); // result unread: a first install has no job to boot out; the bootstrapWithRetry below reads launchd's answer
62
+ const took = bootstrapWithRetry({
63
+ label, file, uid, exec, sleep,
64
+ deadlineMs: config.get('serveRestartSeconds') * 1000,
65
+ pollMs: config.get('serveRestartPollMs'),
66
+ });
67
+ const outcome = took.pid !== null
68
+ ? { action: 'serve-running', pid: took.pid, label }
69
+ : { action: 'serve-not-running', file, label, detail: took.detail };
70
+ return [{ action: 'serve-agent-written', file }, outcome];
71
+ }
72
+
73
+ /** @returns {object[]} action rows for the uninstall report — the SERVE rows only. */
74
+ export function unwireServe({ manifest, exec = defaultExec, uid = process.getuid() }) {
75
+ const actions = [];
76
+ for (const row of manifest.removeWhere((r) => r.harness === 'serve' && r.kind === 'launch-agent')) {
77
+ exec.run('launchctl', ['bootout', `gui/${uid}/${path.basename(row.file, '.plist')}`]); // result unread: an agent already gone answers 'Could not find service'; the removal below is what uninstall promises
78
+ if (fs.existsSync(row.file)) fs.rmSync(row.file);
79
+ actions.push({ action: 'serve-agent-removed', file: row.file });
80
+ }
81
+ return actions;
82
+ }
@@ -60,7 +60,7 @@ export class SessionHost {
60
60
  async stop({ exitCode }) {
61
61
  this.#halt();
62
62
  await this.tickInFlight;
63
- // Custody is the PRINCIPAL's, not the folder's (R-HOME-BOARD): a claim homed elsewhere is
63
+ // Custody is the PRINCIPAL's, not the folder's (R-PLACE, 2026-09-05): a claim residing elsewhere is
64
64
  // still this session's to speak for. Known over-breadth: two concurrent sessions of the
65
65
  // same principal both speak on each other's exits — an honest duplicate beats a lost note.
66
66
  const { rows } = await this.client.query(
package/src/sessions.mjs CHANGED
@@ -11,11 +11,12 @@
11
11
  // checks pid-aliveness — no cron, no migration, no dead-process ledger.
12
12
 
13
13
  import fs from 'node:fs';
14
+ import path from 'node:path';
14
15
 
15
16
  import { atomicWriteJson, withFileLock } from './fslock.mjs';
16
17
  import { defaultExec } from './harnesses/harness.mjs';
17
18
 
18
- const SESSIONS_FORMAT = 1;
19
+ export const SESSIONS_FORMAT = 1;
19
20
  const ANCESTRY_DEPTH_CAP = 32; // loop guard for a corrupt ps snapshot — a bound, not a tunable
20
21
 
21
22
  export class SessionRegistryError extends Error {
@@ -36,14 +37,36 @@ export function pidAlive(pid) {
36
37
  }
37
38
  }
38
39
 
40
+ /** The linux walk: /proc/<pid>/status carries PPid, /proc/<pid>/exe the full executable path
41
+ * (its Name line stands in when exe cannot be read — a kernel thread, a vanished process). */
42
+ function procAncestry(pid, root) {
43
+ const chain = [];
44
+ let cursor = pid;
45
+ for (let depth = 0; depth < ANCESTRY_DEPTH_CAP; depth += 1) {
46
+ let status;
47
+ try { status = fs.readFileSync(path.join(root, String(cursor), 'status'), 'utf8'); } catch { break; }
48
+ const ppid = Number(/^PPid:\s*(\d+)/m.exec(status)?.[1] ?? NaN);
49
+ let exec;
50
+ try { exec = fs.readlinkSync(path.join(root, String(cursor), 'exe')); } catch { exec = /^Name:\s*(.*)$/m.exec(status)?.[1]?.trim() ?? ''; }
51
+ chain.push({ pid: cursor, exec });
52
+ if (cursor === 1 || !Number.isInteger(ppid) || ppid === 0) break;
53
+ cursor = ppid;
54
+ }
55
+ return chain;
56
+ }
57
+
39
58
  /**
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.
59
+ * The process ancestry of `pid` to pid 1 — measured, never asserted. Darwin: ONE `ps`
60
+ * snapshot walked in memory (`comm=` is the full exec path there). Linux: /proc walked
61
+ * (PPid + exe). Any other platform, and any ps failure, yields `[]` — the walk is fail-soft,
62
+ * a session without ancestry still registers and its pid-aliveness still serves; the claim
63
+ * gate treats an unwalked speaker as the client's word (ruling 2026-09-04).
64
+ * @param {{pid: number, exec?: object, platform?: string, procRoot?: string}} o — exec and
65
+ * procRoot are test seams (the ps runner; the /proc directory)
44
66
  * @returns {Array<{pid: number, exec: string}>} ancestry[0] is `pid` itself
45
67
  */
46
- export function processAncestry({ pid, exec = defaultExec, platform = process.platform }) {
68
+ export function processAncestry({ pid, exec = defaultExec, platform = process.platform, procRoot = '/proc' }) {
69
+ if (platform === 'linux') return procAncestry(pid, procRoot);
47
70
  if (platform !== 'darwin') return [];
48
71
  const out = exec.run('ps', ['-axo', 'pid=,ppid=,comm=']);
49
72
  if (out.status !== 0) return [];
@@ -89,12 +112,20 @@ export class SessionRegistry {
89
112
  /** @returns {{format: number, saved_at?: string, sessions: object}} */
90
113
  load() {
91
114
  if (!fs.existsSync(this.sessionsPath)) return { format: SESSIONS_FORMAT, sessions: {} };
115
+ let doc;
92
116
  try {
93
- return JSON.parse(fs.readFileSync(this.sessionsPath, 'utf8'));
117
+ doc = JSON.parse(fs.readFileSync(this.sessionsPath, 'utf8'));
94
118
  } catch (e) {
95
119
  throw new SessionRegistryError('OATHE_SESSIONS_MALFORMED',
96
120
  `${this.sessionsPath} is not valid JSON: ${e.message}`, { file: this.sessionsPath });
97
121
  }
122
+ // The format is the gate (zero legacy, 2026-09-05): another oathe's file is refused by name.
123
+ if (doc?.format !== SESSIONS_FORMAT || typeof doc.sessions !== 'object' || doc.sessions === null) {
124
+ throw new SessionRegistryError('OATHE_SESSIONS_FORMAT',
125
+ `${this.sessionsPath} is format ${JSON.stringify(doc?.format)}; this oathe reads format ${SESSIONS_FORMAT} — move it aside (sessions re-register on their next hook)`,
126
+ { file: this.sessionsPath, found: doc?.format, expected: SESSIONS_FORMAT });
127
+ }
128
+ return doc;
98
129
  }
99
130
 
100
131
  /**
@@ -153,7 +184,7 @@ export class SessionRegistry {
153
184
  let best = null;
154
185
  for (const [sessionId, row] of Object.entries(sessions)) {
155
186
  if (row.pid !== pid) continue;
156
- if (!best || String(row.last_seen_at ?? '') > String(best.row.last_seen_at ?? '')) {
187
+ if (!best || String(row.last_seen_at) > String(best.row.last_seen_at)) { // every row is written with last_seen_at
157
188
  best = { sessionId, row };
158
189
  }
159
190
  }