@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
@@ -52,19 +52,36 @@ export class Harness {
52
52
  static launch = null;
53
53
  /** {store, newest, projector, ownsPath} — the session-record store the verifier and doctor read. */
54
54
  static traces = null;
55
- /** {ownsExec, name} — recognizing this harness's session PROCESSES (exec predicate) and
56
- * NAMING the surface they speak from over facts (exec + nearest app bundle). Facts are
57
- * recorded at SessionStart; naming happens at READ, so it evolves without rewriting
58
- * history. null: no local process of ours to meet in an ancestry walk. */
55
+ /** {ownsExec, name, display, resumable} — recognizing this harness's session PROCESSES (exec
56
+ * predicate), NAMING the surface they speak from over facts (exec + nearest app bundle),
57
+ * the WORD each named surface wears where work lives (`display: {surface: word}`), and
58
+ * which surfaces are apps the glass resumes INTO by opening them (`resumable`, ruling
59
+ * 2026-09-05 — a folder's session is never one). Facts are recorded at SessionStart;
60
+ * naming happens at READ, so it evolves without rewriting history. null: no local process
61
+ * of ours to meet in an ancestry walk. */
59
62
  static surfaces = null;
63
+ /** Attestation (ruling 2026-09-04) — per owned surface NAME: 'hooks' when the harness's
64
+ * sessions register through the lifecycle hooks (a claim with no registered session is
65
+ * refused), 'hookless' when the surface never runs hooks by design (the claim is admitted
66
+ * and its evidence is discovered). A surface that never speaks declares null. */
67
+ static attestation = null;
68
+ /** The blocking exchange declared to the transport (ruling 2026-09-05): `{key, unit: 'sec'}` —
69
+ * the per-tool timeout KEY this adapter's MCP registration writes where its client reads it,
70
+ * valued from config `mcpToolTimeoutSec` (a `done` waits minutes for its verdict; codex's
71
+ * default was 60s). null when the client needs none (Claude Code: ≈28h default, and a call
72
+ * past two minutes becomes a background task) or documents none (Cursor). */
73
+ static mcpToolTimeout = null;
60
74
 
61
75
  /**
62
76
  * @param {{name?: string, home: string, envPath?: string, paths: object,
63
- * exec?: {run: (cmd: string, args: string[]) => {status: number, stdout: string, stderr: string}}}} o
77
+ * exec?: {run: (cmd: string, args: string[]) => {status: number, stdout: string, stderr: string}},
78
+ * config?: {get: Function}|null}} o config — the OatheConfig an adapter's writes are
79
+ * valued from (the codex timeout budget); null for read-only uses (detect, census)
64
80
  */
65
- constructor({ name, home, envPath = process.env.PATH ?? '', paths, exec = defaultExec }) {
81
+ constructor({ name, home, envPath = process.env.PATH ?? '', paths, exec = defaultExec, config = null }) {
66
82
  this.name = name ?? this.constructor.harnessName;
67
83
  this.home = home;
84
+ this.config = config;
68
85
  this.envPath = envPath;
69
86
  this.paths = paths;
70
87
  this.exec = exec;
@@ -82,6 +99,12 @@ export class Harness {
82
99
  * them here; the resolver derives the fact once and every surface threads it.
83
100
  * @param {{dir: string, home: string}} _o
84
101
  */
102
+ /** `{dirs(home), originators}` — the staging dirs an app surface runs sessions from (no project
103
+ * folder; a measured list, absolute paths for `home`) and the rollout originators that name the
104
+ * desktop (so `traces.stagingDrift` can say when the app moves). A claim from a staging dir is
105
+ * picked up by the app and says so in its place statement. null when none. */
106
+ static synthetic = null;
107
+
85
108
  static isSyntheticWorkspaceDir(_o) {
86
109
  return false;
87
110
  }
@@ -108,7 +131,10 @@ export class Harness {
108
131
  * How a fresh Linux runner gets this harness's REAL CLI — the install-contract lane installs
109
132
  * it and proves `oathe init` against it: `{ npm, bin, versionArgs }` for an npm package,
110
133
  * `{ installer, bin, versionArgs }` for a vendor install script, null when the harness has no
111
- * CLI to install (its wiring is then our own file writes, pinned by the suite).
134
+ * CLI to install (its wiring is then our own file writes, pinned by the suite). `update`
135
+ * (ruling 2026-09-05): `(address) => [bin, args]` — the CLI's OWN in-place updater, run by
136
+ * `oathe engine update` when a judgment named it out of date; null when the adapter knows no
137
+ * updater (then the glass offers no update act and the stall words stay honest).
112
138
  */
113
139
  static install = null;
114
140
 
@@ -117,6 +143,9 @@ export class Harness {
117
143
  * REAL session fire our hooks and leave a transcript: `{ auth, command, extract }` — the env
118
144
  * vars its non-interactive mode authenticates with (pinned from the docs snapshot), the
119
145
  * argv for a prompt, and the extraction of the model's text from stdout; null for none.
146
+ * `diagnose(stderrTail) → 'outdated' | null` (ruling 2026-09-05): the ONLY reader of the
147
+ * engine's own failure words — the verifier records the cause, the pager words it, the glass
148
+ * acts on it. When the CLI changes its message, this predicate changes and nothing else does.
120
149
  */
121
150
  static headless = null;
122
151
 
@@ -171,10 +200,48 @@ export class Harness {
171
200
  return presence.cli && presence.configHome !== null;
172
201
  }
173
202
 
203
+ /**
204
+ * The ONE resolver of a CLI's ADDRESS (ruling 2026-09-05, engines are addresses): the first
205
+ * executable named `name` on `envPath`, absolute, or null. Detection, the launcher and the
206
+ * engine runner all ask this — no second reading of PATH anywhere.
207
+ */
208
+ static resolveOnPath(envPath, name) {
209
+ for (const dir of String(envPath ?? '').split(':').filter(Boolean)) {
210
+ const candidate = path.join(dir, name);
211
+ try { fs.accessSync(candidate, fs.constants.X_OK); return candidate; } catch { /* keep looking */ }
212
+ }
213
+ return null;
214
+ }
215
+
174
216
  binOnPath(bin) {
175
- return this.envPath.split(':').filter(Boolean).some((dir) => {
176
- try { fs.accessSync(path.join(dir, bin), fs.constants.X_OK); return true; } catch { return false; }
177
- });
217
+ return Harness.resolveOnPath(this.envPath, bin) !== null;
218
+ }
219
+
220
+ /** The manifest kind that records a CLI's address — the one kind whose file oathe does not own. */
221
+ static CLI_ADDRESS_KIND = 'cli-address';
222
+
223
+ /**
224
+ * offboard()'s first line: take this harness's WIRING rows off the manifest — never its
225
+ * cli-address row, which records a file the harness owns (uninstall forgets it separately;
226
+ * an unwire keeps it: the CLI is still there to verify with).
227
+ */
228
+ takeWiringRows(manifest) {
229
+ return manifest.removeWhere((r) => r.harness === this.name && r.kind !== Harness.CLI_ADDRESS_KIND);
230
+ }
231
+
232
+ /**
233
+ * Record WHERE this harness's CLI is (init, every run): one `cli-address` manifest row with the
234
+ * measured address, no sha (the file is the harness's, never ours — the doctor proves it RUNS
235
+ * under the LaunchAgent's PATH instead). Not found → no row, and any stale row goes: a
236
+ * daemon-forwarded judgment must never spawn a bare name into launchd's PATH again.
237
+ * @returns {Array<{action: string, file?: string}>}
238
+ */
239
+ recordCliAddress({ manifest, version }) {
240
+ const { cliPath } = this.detect().presence;
241
+ const stale = manifest.removeWhere((r) => r.kind === Harness.CLI_ADDRESS_KIND && r.harness === this.name);
242
+ if (cliPath === null) return stale.length > 0 ? [{ action: 'cli-address-gone', file: stale[0].file }] : [];
243
+ manifest.upsert({ harness: this.name, file: cliPath, kind: Harness.CLI_ADDRESS_KIND, detail: { bin: path.basename(cliPath) }, blockVersion: version, sha256: null });
244
+ return [{ action: stale.some((r) => r.file === cliPath) ? 'cli-address-current' : 'cli-address-recorded', file: cliPath }];
178
245
  }
179
246
 
180
247
  /**
@@ -182,12 +249,14 @@ export class Harness {
182
249
  * question does not apply), the CLI, the config home — and the adapter's own verdict on
183
250
  * "installed" over those facts. Consumers pick the fact their capability needs (a headless
184
251
  * run needs `cli`; wiring needs `configHome`), never the one bit.
185
- * @returns {{name: string, presence: {app: boolean|null, cli: boolean, configHome: string|null}, installed: boolean}}
252
+ * `cliPath` is the CLI's measured ADDRESS (the first cliBin resolved on this harness's PATH)
253
+ * or null; `cli` is its boolean face.
254
+ * @returns {{name: string, presence: {app: boolean|null, cli: boolean, cliPath: string|null, configHome: string|null}, installed: boolean}}
186
255
  */
187
256
  detect() {
188
- const cli = this.constructor.cliBins.some((bin) => this.binOnPath(bin));
257
+ const cliPath = this.constructor.cliBins.map((bin) => Harness.resolveOnPath(this.envPath, bin)).find((p) => p !== null) ?? null;
189
258
  const configHome = fs.existsSync(this.configHome) ? this.configHome : null;
190
- const presence = { app: null, cli, configHome };
259
+ const presence = { app: null, cli: cliPath !== null, cliPath, configHome };
191
260
  return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
192
261
  }
193
262
 
@@ -39,7 +39,7 @@ export class CoworkSurface extends Harness {
39
39
  detect() {
40
40
  const appSupport = path.join(this.home, 'Library/Application Support/Claude');
41
41
  const app = this.platform === 'darwin' && (fs.existsSync('/Applications/Claude.app') || fs.existsSync(appSupport));
42
- const presence = { app, cli: false, configHome: app ? appSupport : null };
42
+ const presence = { app, cli: false, cliPath: null, configHome: app ? appSupport : null };
43
43
  return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
44
44
  }
45
45
  }
@@ -65,7 +65,7 @@ export class ChatGptWebSurface extends Harness {
65
65
  }
66
66
 
67
67
  detect() {
68
- const presence = { app: null, cli: false, configHome: null };
68
+ const presence = { app: null, cli: false, cliPath: null, configHome: null };
69
69
  return { name: this.name, presence, installed: false };
70
70
  }
71
71
  }
package/src/home.mjs CHANGED
@@ -1,21 +1,28 @@
1
- // oathe — the home board (ruling R-HOME-BOARD, PLAN.md 2026-08-28). A task's board is the
2
- // workspace of the EARLIEST claim that named a real folder; every later claim inherits it and
3
- // never restamps it, so cross-surface pickup cannot drag a task off its repo's board. Tasks
4
- // minted from a synthetic workspace (a ChatGPT-desktop staging dir) are HOMELESS until a real
5
- // folder claims — adopts — them; a verification task lives wherever its parent lives.
1
+ // oathe — where work lives (founder ruling 2026-09-05, superseding R-HOME-BOARD's fixed home).
2
+ // A PLACE is where a claim was picked up — a folder (a workspace ref) or an app (a surface with
3
+ // no folder, the ChatGPT desktop) — and every pickup records its place as a statement
4
+ // (statements.mjs linkPlace). A task is VISIBLE on the board of every place that ever picked it
5
+ // up (the history keeps the visibility R-HOME-BOARD's fixed home once protected), and it
6
+ // RESIDES where it was picked up last: that is where continue goes, where the verifier runs,
7
+ // and the word a row wears. A claim is picked up at a place or it is refused; a task no claim
8
+ // has picked up is UNCLAIMED. There is no third word. No rank, no adoption — the last pickup.
6
9
  //
7
- // Home is DERIVED from the claim ledger, never stored: the DDL is frozen, and a stored copy
8
- // would drift from the ledger it summarizes. This module is the ONE owner of the contract_ref
9
- // grammar (`workspace:<ws-ref|none>;contract:<org>/<task>@v1`) in both JavaScript and SQL —
10
- // nothing else in the tree builds, parses, or pattern-matches a contract_ref.
10
+ // Residence and places are DERIVED, never stored: the DDL is frozen, and a stored copy would
11
+ // drift from the record it summarizes. This module is the ONE owner of two grammars, in
12
+ // JavaScript and in SQL: the ledger's contract_ref (`workspace:<ws-ref|none>;contract:<org>/
13
+ // <task>@v1` — the substrate's own field, transcribed by 016/027; `none` says "this claim had
14
+ // no folder", which is an app pickup) and the place (`workspace:<ws-ref>` | `app:<surface>`).
15
+ // Nothing else in the tree builds, parses, or pattern-matches either.
11
16
 
12
17
  import { VERIFICATION_PREFIX, verifiedTaskId } from './plans.mjs';
18
+ import { PLACE_SUBJECT_PREFIX } from './statements.mjs';
13
19
 
14
- /** The workspace token of a homeless claim — a real ref is always `ws-<12hex>`, never this. */
15
- export const HOMELESS = 'none';
20
+ /** The ledger's token for a claim made from no folder (an app pickup) — a real ref is always `ws-<12hex>`, never this. */
21
+ export const NO_FOLDER = 'none';
16
22
 
17
23
  const CONTRACT_VERSION = 'v1';
18
24
  const GRAMMAR = /^workspace:([^;]+);contract:([^/]+)\/(.+)@v1$/;
25
+ const PLACE_GRAMMAR = /^(workspace|app):(.+)$/;
19
26
 
20
27
  export class HomeError extends Error {
21
28
  constructor(code, message, details = {}) {
@@ -26,7 +33,7 @@ export class HomeError extends Error {
26
33
  }
27
34
  }
28
35
 
29
- /** A claim's contract reference: the workspace it is homed on (null = homeless) + the contract. */
36
+ /** A claim's contract reference: the folder it was made from (null = none) + the contract. */
30
37
  export class ContractRef {
31
38
  /** @param {{workspace: string|null, orgId: string, taskId: string}} o */
32
39
  constructor({ workspace, orgId, taskId }) {
@@ -40,68 +47,183 @@ export class ContractRef {
40
47
  const match = GRAMMAR.exec(String(text));
41
48
  if (!match) {
42
49
  throw new HomeError('OATHE_CONTRACT_REF_MALFORMED',
43
- `contract_ref '${text}' does not follow workspace:<ws|${HOMELESS}>;contract:<org>/<task>@${CONTRACT_VERSION}`,
50
+ `contract_ref '${text}' does not follow workspace:<ws|${NO_FOLDER}>;contract:<org>/<task>@${CONTRACT_VERSION}`,
44
51
  { text });
45
52
  }
46
53
  const [, workspace, orgId, taskId] = match;
47
- return new ContractRef({ workspace: workspace === HOMELESS ? null : workspace, orgId, taskId });
54
+ return new ContractRef({ workspace: workspace === NO_FOLDER ? null : workspace, orgId, taskId });
48
55
  }
49
56
 
50
- get isHomeless() {
51
- return this.workspace === null;
57
+ /** A folder claim; false for an app pickup (the ledger's `none`). */
58
+ get hasFolder() {
59
+ return this.workspace !== null;
52
60
  }
53
61
 
54
62
  toString() {
55
- return `workspace:${this.workspace ?? HOMELESS};contract:${this.orgId}/${this.taskId}@${CONTRACT_VERSION}`;
63
+ return `workspace:${this.workspace ?? NO_FOLDER};contract:${this.orgId}/${this.taskId}@${CONTRACT_VERSION}`;
56
64
  }
57
65
  }
58
66
 
59
67
  /**
60
- * The home derivation over the claim ledger. `of(taskId)` answers from the database; `homeSql`
61
- * projects the same rule into a query so the board never re-implements it.
68
+ * Where a claim was picked up: a folder (`workspace:<ws-ref>`) or an app (`app:<surface>` —
69
+ * the surface name the adapter gives it, e.g. `chatgpt`). A value object; the statement's
70
+ * subject is `place:` + this string (statements.mjs owns the subject prefix).
62
71
  */
63
- export class HomeBoard {
64
- /** @param {{client: {query: Function}, orgId: string}} o */
65
- constructor({ client, orgId }) {
66
- this.client = client;
67
- this.orgId = orgId;
72
+ export class Place {
73
+ /** @param {{kind: 'workspace'|'app', ref: string}} o */
74
+ constructor({ kind, ref }) {
75
+ this.kind = kind;
76
+ this.ref = ref;
77
+ }
78
+
79
+ static workspace(ref) {
80
+ return new Place({ kind: 'workspace', ref });
81
+ }
82
+
83
+ static app(surface) {
84
+ return new Place({ kind: 'app', ref: surface });
85
+ }
86
+
87
+ /** @throws {HomeError} OATHE_PLACE_MALFORMED — a place is a folder ref or an app surface, never the ledger's token */
88
+ static parse(text) {
89
+ const match = PLACE_GRAMMAR.exec(String(text));
90
+ if (!match || (match[1] === 'workspace' && match[2] === NO_FOLDER)) {
91
+ throw new HomeError('OATHE_PLACE_MALFORMED',
92
+ `place '${text}' does not follow workspace:<ws-ref> | app:<surface>`, { text });
93
+ }
94
+ return new Place({ kind: match[1], ref: match[2] });
95
+ }
96
+
97
+ /** A row that has no place is null — never a throw. */
98
+ static parseOrNull(text) {
99
+ return text === null || text === undefined ? null : Place.parse(text);
68
100
  }
69
101
 
70
- /** The task whose ledger decides `taskId`'s home: itself, or its parent for a verification task. */
102
+ get isFolder() {
103
+ return this.kind === 'workspace';
104
+ }
105
+
106
+ toString() {
107
+ return `${this.kind}:${this.ref}`;
108
+ }
109
+ }
110
+
111
+ /**
112
+ * What a pickup KNOWS beside its place, each only when known: the app bundle it was spoken from,
113
+ * the device, and — for an app pickup — the project folder the app ran in (the ChatGPT project's
114
+ * staging dir, where its files are; never a place to resume into). One grammar (`app:`,
115
+ * `device:`, `dir:`), one writer, one parser; a row reads it back as place_app/place_device/place_dir.
116
+ */
117
+ const EVIDENCE_PREFIX = Object.freeze({ app: 'app:', device: 'device:', dir: 'dir:' });
118
+
119
+ export class PlaceEvidence {
120
+ /** @param {{app?: string|null, device?: string|null, dir?: string|null}} o */
121
+ constructor({ app = null, device = null, dir = null } = {}) {
122
+ this.app = app;
123
+ this.device = device;
124
+ this.dir = dir;
125
+ }
126
+
127
+ /** The evidence refs a place statement carries — the known facts only, never a null string. */
128
+ get refs() {
129
+ return Object.entries(EVIDENCE_PREFIX).flatMap(([key, prefix]) => (this[key] ? [`${prefix}${this[key]}`] : []));
130
+ }
131
+
132
+ /** The refs of a place statement back to facts; refs of another grammar are ignored. */
133
+ static parse(refs) {
134
+ const list = Array.isArray(refs) ? refs : [];
135
+ const pick = (prefix) => list.find((r) => typeof r === 'string' && r.startsWith(prefix))?.slice(prefix.length) ?? null;
136
+ return new PlaceEvidence({ app: pick(EVIDENCE_PREFIX.app), device: pick(EVIDENCE_PREFIX.device), dir: pick(EVIDENCE_PREFIX.dir) });
137
+ }
138
+
139
+ /** The row shape every surface reads (the pager, the board, the glass). */
140
+ row() {
141
+ return { place_app: this.app, place_device: this.device, place_dir: this.dir };
142
+ }
143
+ }
144
+
145
+ /**
146
+ * The PICKUP: where a surface picks work up and what it knows — computed once per surface, recorded
147
+ * on every claim and re-seat (ruling 2026-09-05). A folder session picks up at its workspace (the
148
+ * folder is the registry's fact, not evidence); an app session (a synthetic dir, or no folder at
149
+ * all) picks up at `app:<surface>` and records the project dir it ran in; a surface with neither
150
+ * has no place, and `require()` refuses a claim from it. A system task (a judgment, an update)
151
+ * never records a place: it lives where its work does.
152
+ */
153
+ export class Pickup {
154
+ /** @param {{place: Place|null, evidence: PlaceEvidence}} o */
155
+ constructor({ place, evidence }) {
156
+ this.place = place;
157
+ this.evidence = evidence;
158
+ }
159
+
160
+ static of({ workspace = null, synthetic = false, dir = null, speaker = null } = {}) {
161
+ const folder = !synthetic && workspace ? Place.workspace(workspace) : null;
162
+ const app = folder === null && speaker?.surface ? Place.app(speaker.surface) : null;
163
+ return new Pickup({
164
+ place: folder ?? app,
165
+ evidence: new PlaceEvidence({ app: speaker?.app?.bundle ?? null, device: speaker?.device ?? null, dir: app !== null ? dir : null }),
166
+ });
167
+ }
168
+
169
+ /** @throws {HomeError} OATHE_PLACE_UNKNOWN — a claim is picked up somewhere, or it is refused before anything is written */
170
+ require(taskId) {
171
+ if (this.place === null) {
172
+ throw new HomeError('OATHE_PLACE_UNKNOWN',
173
+ `a claim is picked up somewhere — a folder session or an app — and this surface named neither; `
174
+ + `speak it from a harness session on a project folder or from the desktop app (task '${taskId}')`, { task_id: taskId });
175
+ }
176
+ return this.place;
177
+ }
178
+ }
179
+
180
+ /**
181
+ * The place rule projected into SQL so the board, the pager, and the verifier never
182
+ * re-implement it: `residenceSql` is the LAST pickup (a LATERAL body yielding `place` and
183
+ * `place_evidence`), `placesSql` every pickup (a scalar text[] of place strings). Both anchor
184
+ * a verification task on its parent — the judgment lives where the work does.
185
+ *
186
+ * A pickup is read from ONE record: the place statement every claim records at the pickup
187
+ * (statements.mjs linkPlace). The ledger's `contract_ref` slot still carries the claim's folder
188
+ * (or `none`) because the substrate's verbs transcribe it, but nothing derives a place from it —
189
+ * a claim with no place statement does not exist (zero legacy, founder 2026-09-05: records from
190
+ * before the statement were removed from the machine, never inferred).
191
+ */
192
+ export class HomeBoard {
193
+ /** The task whose record decides `taskId`'s place: itself, or its parent for a verification task. */
71
194
  static anchorTaskId(taskId) {
72
195
  return verifiedTaskId(taskId) ?? taskId;
73
196
  }
74
197
 
75
- /** The LIKE pattern every homeless claim matches — the sentinel, spelled once. */
76
- static get homelessPattern() {
77
- return `workspace:${HOMELESS};%`;
198
+ static #anchorSql(t) {
199
+ return `CASE WHEN ${t}.task_id LIKE '${VERIFICATION_PREFIX}%'
200
+ THEN substr(${t}.task_id, ${VERIFICATION_PREFIX.length + 1})
201
+ ELSE ${t}.task_id END`;
78
202
  }
79
203
 
80
204
  /**
81
- * SQL scalar subquery: the home workspace ref (or NULL) of the task row aliased `taskAlias`.
82
- * The verification-prefix anchor and the sentinel exclusion derive from the JS constants —
83
- * one owner, two languages.
205
+ * Every pickup of the anchored task — the place statements, and nothing else (place,
206
+ * place_evidence, at). The ledger's `contract_ref` slot is NOT read as a pickup: every claim
207
+ * records its place as a statement at the pickup, and a claim without one does not exist
208
+ * (zero legacy, founder 2026-09-05 — records from before the statement were removed, never inferred).
84
209
  */
85
- static homeSql(taskAlias) {
86
- const t = taskAlias;
87
- return `(SELECT split_part(split_part(c.contract_ref, ';', 1), ':', 2)
88
- FROM cell.work_claim c
89
- WHERE c.org_id = ${t}.org_id
90
- AND c.task_id = CASE WHEN ${t}.task_id LIKE '${VERIFICATION_PREFIX}%'
91
- THEN substr(${t}.task_id, ${VERIFICATION_PREFIX.length + 1})
92
- ELSE ${t}.task_id END
93
- AND c.contract_ref NOT LIKE '${HomeBoard.homelessPattern}'
94
- ORDER BY c.claimed_at ASC LIMIT 1)`;
95
- }
96
-
97
- /** @returns {Promise<string|null>} the home workspace ref, or null when homeless/unclaimed */
98
- async of(taskId) {
99
- const { rows } = await this.client.query(
100
- `SELECT split_part(split_part(contract_ref, ';', 1), ':', 2) AS workspace
101
- FROM cell.work_claim
102
- WHERE org_id = $1 AND task_id = $2 AND contract_ref NOT LIKE $3
103
- ORDER BY claimed_at ASC LIMIT 1`,
104
- [this.orgId, HomeBoard.anchorTaskId(taskId), HomeBoard.homelessPattern]);
105
- return rows[0]?.workspace ?? null;
210
+ static #pickupsSql(t) {
211
+ return `SELECT substr(s.subject_ref, ${PLACE_SUBJECT_PREFIX.length + 1}) AS place, s.evidence_refs AS place_evidence, s.asserted_at AS at
212
+ FROM cell.agent_statement s
213
+ WHERE s.org_id = ${t}.org_id AND s.task_id = ${HomeBoard.#anchorSql(t)}
214
+ AND s.subject_ref LIKE '${PLACE_SUBJECT_PREFIX}%'`;
215
+ }
216
+
217
+ /** LATERAL body: the residence — the latest pickup's place text and its evidence (app, device). */
218
+ static residenceSql(taskAlias) {
219
+ return `SELECT pickup.place, pickup.place_evidence
220
+ FROM (${HomeBoard.#pickupsSql(taskAlias)}) pickup
221
+ ORDER BY pickup.at DESC LIMIT 1`;
222
+ }
223
+
224
+ /** Scalar subquery: every place that ever picked the task up, as place strings (text[], never NULL). */
225
+ static placesSql(taskAlias) {
226
+ return `(SELECT coalesce(array_agg(DISTINCT pickup.place), '{}'::text[])
227
+ FROM (${HomeBoard.#pickupsSql(taskAlias)}) pickup)`;
106
228
  }
107
229
  }
package/src/init.mjs CHANGED
@@ -33,7 +33,7 @@ export async function runInit({
33
33
  // 2026-08-29).
34
34
  const machine = OatheConfig.global({ env: ctx.config.env });
35
35
  // DECLARATIVE: the screen shows the wiring state and Enter makes the machine match it.
36
- const wiredNow = new Set(manifest.rows.map((r) => r.harness).filter((h) => wired.some((a) => a.name === h)));
36
+ const wiredNow = new Set(wired.map((a) => a.name).filter((h) => manifest.wiringRowsFor(h).length > 0));
37
37
  const plan = SetupPlan.from({
38
38
  adapters: wired, census: seen, surfaces, machine, home: ctx.home, paths: ctx.paths, fallbackVerifier: ctx.config.get('verifier'), wiredNow,
39
39
  });
@@ -124,6 +124,24 @@ export async function runInit({
124
124
  actions.push({ harness: name, ...action });
125
125
  }
126
126
  }
127
+ // The shim FIRST: every adapter's wiring, the plugin's hooks, and the notch-frame acts
128
+ // address $HOME/.oathe/bin/oathe — the one durable address (connection-lane plan,
129
+ // 2026-09-04). Re-stamped every init, so node moves never strand a harness config.
130
+ const { writeShim } = await import('./shim.mjs');
131
+ for (const action of writeShim({ home: ctx.home, manifest, version, packageRoot: ctx.paths.packageRoot })) {
132
+ actions.push({ harness: 'shim', ...action });
133
+ }
134
+ // The device identity (ruling 2026-09-04): minted once, kept forever, one row — the
135
+ // trust unit anything outside this machine will sign against (src/device.mjs).
136
+ const { writeDevice } = await import('./device.mjs');
137
+ const [deviceAction] = writeDevice({ devicePath: ctx.paths.devicePath, manifest, version });
138
+ actions.push({ harness: 'device', ...deviceAction });
139
+ // Every harness's CLI ADDRESS (ruling 2026-09-05: engines are addresses, never recipes): a
140
+ // machine fact recorded whether or not the harness is wired — the verifier can be any CLI
141
+ // here — so a judgment spawned from launchd's bare PATH (the feed, the daemon) still finds it.
142
+ for (const harness of wired) {
143
+ for (const action of harness.recordCliAddress({ manifest, version })) actions.push({ harness: harness.name, ...action });
144
+ }
127
145
  for (const step of plan.steps) {
128
146
  if (!step.installed) {
129
147
  actions.push({ harness: step.name, action: 'skipped-not-installed' });
@@ -144,6 +162,12 @@ export async function runInit({
144
162
  for (const action of wireNotch({ home: ctx.home, manifest, config: ctx.config, version, packageRoot: ctx.paths.packageRoot, ...(exec ? { exec } : {}) })) {
145
163
  actions.push({ harness: 'notch', ...action });
146
164
  }
165
+ // The serve daemon (connection-lane phase 2): launchd runs the shim written above; every
166
+ // `oathe mcp` forwards to it when it answers, and the device holds ONE substrate presence.
167
+ const { wireServe } = await import('./serve.mjs');
168
+ for (const action of wireServe({ home: ctx.home, manifest, config: ctx.config, version, ...(exec ? { exec } : {}) })) {
169
+ actions.push({ harness: 'serve', ...action });
170
+ }
147
171
  // This run took as long as its CLI calls did; a hook or a server may have saved a row in
148
172
  // the meantime. Under the lock, merge what landed on disk, then record this run — never a
149
173
  // snapshot over a living file (B4, 2026-09-03).
@@ -155,7 +179,8 @@ export async function runInit({
155
179
  census: seen,
156
180
  surfaces,
157
181
  substrate: await substrate.status(),
158
- principal: { org_id: identity.orgId, principal_id: identity.principalId, role: 'ceo' },
182
+ device: { device_id: deviceAction.device_id, minted: deviceAction.action === 'device-minted' },
183
+ principal: { org_id: identity.orgId, principal_id: identity.principalId, role: 'ceo' },
159
184
  verifier: { principal_id: verifierPrincipal, seats },
160
185
  verifier_engine: {
161
186
  chosen: v.chosen,
package/src/launch.mjs CHANGED
@@ -6,11 +6,9 @@
6
6
  // here — the runtime's cage lives outside oathe-runtime's exports map (pre-extraction) and is
7
7
  // resolved by PATH from paths.cagePath inside OatheRuntimeProvider itself.
8
8
 
9
- import fs from 'node:fs';
10
- import path from 'node:path';
11
9
 
12
10
  import { buildContext } from './context.mjs';
13
- import { byName } from './harnesses/catalog.mjs';
11
+ import { Harness, byName } from './harnesses/catalog.mjs';
14
12
  import { SessionHost } from './session-host.mjs';
15
13
  import { launchSessionEnv } from './launch-env.mjs';
16
14
 
@@ -32,7 +30,7 @@ export async function preflight({ env = process.env, cwd = process.cwd(), exec,
32
30
  const ctx = buildContext({ env, exec });
33
31
  const { manifest, version, substrate, paths, config } = ctx;
34
32
  await substrate.close(); // preflight itself never talks to the database
35
- if (!manifest.rows.some((r) => r.harness === harness)) {
33
+ if (manifest.wiringRowsFor(harness).length === 0) { // an address row alone wires nothing
36
34
  throw new LaunchError('OATHE_NOT_INSTALLED',
37
35
  `the ${harness} install is missing (no ${harness} rows in the install manifest) — `
38
36
  + 'run `oathe init` with that harness present first');
@@ -62,12 +60,12 @@ function declarable(env) {
62
60
  * reads process.env.PATH, which is not the environment the user asked us to launch from).
63
61
  */
64
62
  function resolveOnPath(envPath, name) {
65
- for (const dir of String(envPath ?? '').split(':').filter(Boolean)) {
66
- const candidate = path.join(dir, name);
67
- try { fs.accessSync(candidate, fs.constants.X_OK); return candidate; } catch { /* keep looking */ }
63
+ const found = Harness.resolveOnPath(envPath, name); // the ONE resolver (src/harnesses/harness.mjs)
64
+ if (found === null) {
65
+ throw new LaunchError('OATHE_HARNESS_NOT_FOUND',
66
+ `no executable '${name}' on PATH — is the harness installed?`, { name });
68
67
  }
69
- throw new LaunchError('OATHE_HARNESS_NOT_FOUND',
70
- `no executable '${name}' on PATH — is the harness installed?`, { name });
68
+ return found;
71
69
  }
72
70
 
73
71
  /** The hermetic whitelist: terminal plumbing + oathe wiring, nothing else. */
@@ -0,0 +1,100 @@
1
+ // oathe — the launchd machinery, ONE implementation (connection-lane phase 2, generalized
2
+ // out of src/notch.mjs where 0.4.4 hardened it): per-home hashed labels (the uid's launchd
3
+ // domain is shared across homes — only the hash keeps installations apart; there is
4
+ // deliberately no bare-label special case), a plist writer that ESCAPES its interpolations
5
+ // and takes arbitrary ProgramArguments, the bootstrap retried inside a budget with the pid
6
+ // read back from launchd (bootout is asynchronous; a bootstrap in its window is refused
7
+ // "5: Input/output error" — the unread refusal that shipped 0.4.3's dead notch), and the
8
+ // job probe. Two consumers: the notch (src/notch.mjs) and the serve daemon (src/serve.mjs).
9
+ // The scar rules travel with the code: the proof is always the SUPERVISOR's answer, and a
10
+ // poll never sleeps past its deadline (Greptile P1 on #34).
11
+
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+
15
+ import { defaultExec } from './harnesses/harness.mjs';
16
+ import { sha256Hex } from './manifest.mjs';
17
+
18
+ const xmlEscape = (s) => String(s)
19
+ .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
20
+
21
+ /** base + '.' + 12 hex of the REAL home path — the label NAMES the installation. */
22
+ export function serviceLabel(home, base) {
23
+ const real = (p) => { try { return fs.realpathSync(p); } catch { return p; } };
24
+ return `${base}.${sha256Hex(real(home)).slice(0, 12)}`;
25
+ }
26
+
27
+ /** The plist file is NAMED BY ITS LABEL — doctor derives the label back from the filename. */
28
+ export function agentPathFor(home, label) {
29
+ return path.join(home, 'Library', 'LaunchAgents', `${label}.plist`);
30
+ }
31
+
32
+ /**
33
+ * The agent plist: RunAtLoad + KeepAlive (a dead oathe service is a silent breach surface —
34
+ * launchd owns liveness), the running node's bin dir leading PATH (launchd spawns with a
35
+ * bare PATH and a login shell never sources .zshrc — but this IS oathe running, so it knows
36
+ * where the bin lives), every interpolation XML-escaped.
37
+ */
38
+ export function agentPathEnv(nodeBinDir = path.dirname(process.execPath)) {
39
+ return [nodeBinDir, '/usr/local/bin', '/opt/homebrew/bin', '/usr/bin', '/bin'].join(':');
40
+ }
41
+
42
+ export function launchAgentPlistFor({ label, programArguments, nodeBinDir = path.dirname(process.execPath) }) {
43
+ const agentPath = agentPathEnv(nodeBinDir);
44
+ const args = programArguments.map((a) => `<string>${xmlEscape(a)}</string>`).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>${xmlEscape(label)}</string>
50
+ <key>ProgramArguments</key><array>${args}</array>
51
+ <key>EnvironmentVariables</key><dict><key>PATH</key><string>${xmlEscape(agentPath)}</string></dict>
52
+ <key>RunAtLoad</key><true/>
53
+ <key>KeepAlive</key><true/>
54
+ </dict>
55
+ </plist>
56
+ `;
57
+ }
58
+
59
+ /** launchd's word on one label: loaded, and the pid it runs — the only "running" oathe reports. */
60
+ export function launchdJob({ label, exec = defaultExec, uid = process.getuid() }) {
61
+ const r = exec.run('launchctl', ['print', `gui/${uid}/${label}`]);
62
+ const pid = r.status === 0 ? Number(/^\s*pid = (\d+)/m.exec(r.stdout)?.[1] ?? NaN) : NaN;
63
+ return { label, loaded: r.status === 0, pid: Number.isFinite(pid) ? pid : null };
64
+ }
65
+
66
+ /** A synchronous pause — init is a straight line, and launchd is asked, not raced. */
67
+ export const blockingSleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
68
+
69
+ const lastLine = (text) => String(text ?? '').trim().split('\n').filter((l) => l && !/^Try re-running/.test(l)).at(-1) ?? '';
70
+
71
+ /**
72
+ * The restart, asked not raced: retry the refused bootstrap inside the budget, then confirm
73
+ * from launchd itself that the job has a pid. Past the budget the answer is launchd's own
74
+ * last word — a silent "written" over a dead service is what shipped in 0.4.3.
75
+ * @returns {{pid: number|null, loaded: boolean, detail: string|null}}
76
+ */
77
+ export function bootstrapWithRetry({
78
+ label, file, uid = process.getuid(), exec = defaultExec,
79
+ deadlineMs, pollMs, sleep = blockingSleep, now = Date.now,
80
+ }) {
81
+ const deadline = now() + deadlineMs;
82
+ // A poll never sleeps past the deadline — the budget is the budget (Greptile P1 on #34).
83
+ const poll = () => Math.max(0, Math.min(pollMs, deadline - now()));
84
+ let last = exec.run('launchctl', ['bootstrap', `gui/${uid}`, file]);
85
+ while (last.status !== 0 && now() < deadline) {
86
+ sleep(poll());
87
+ last = exec.run('launchctl', ['bootstrap', `gui/${uid}`, file]);
88
+ }
89
+ let job = launchdJob({ label, exec, uid });
90
+ while (last.status === 0 && job.pid === null && now() < deadline) {
91
+ sleep(poll());
92
+ job = launchdJob({ label, exec, uid });
93
+ }
94
+ return {
95
+ pid: job.pid,
96
+ loaded: job.loaded,
97
+ detail: job.pid !== null ? null
98
+ : (lastLine(last.stderr) || (job.loaded ? 'loaded, no pid yet' : 'not loaded')),
99
+ };
100
+ }