@oathe/oathe 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/NOTICE +3 -4
  2. package/README.md +14 -45
  3. package/assets/oathe-hero.svg +92 -0
  4. package/bin/oathe.mjs +397 -59
  5. package/docs/PRIVACY.md +13 -5
  6. package/notch/Oathe Notch.app/Contents/Info.plist +13 -0
  7. package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
  8. package/notch/Oathe Notch.app/Contents/_CodeSignature/CodeResources +115 -0
  9. package/notch/README.md +88 -0
  10. package/package.json +13 -4
  11. package/plugin/.claude-plugin/plugin.json +1 -1
  12. package/plugin/.cursor-plugin/plugin.json +36 -0
  13. package/plugin/.mcp.json +1 -4
  14. package/plugin/commands/verify.md +18 -0
  15. package/plugin/hooks/frame-note.mjs +5 -3
  16. package/plugin/hooks/heartbeat.mjs +21 -25
  17. package/plugin/hooks/lib.mjs +96 -33
  18. package/plugin/hooks/render-board.mjs +47 -7
  19. package/src/activation.mjs +126 -0
  20. package/src/atif.mjs +4 -13
  21. package/src/blocks.mjs +113 -8
  22. package/src/board-render.mjs +55 -29
  23. package/src/config.mjs +100 -15
  24. package/src/context.mjs +4 -8
  25. package/src/doctor.mjs +96 -15
  26. package/src/fence.mjs +85 -0
  27. package/src/fslock.mjs +51 -0
  28. package/src/harnesses/catalog.mjs +180 -0
  29. package/src/harnesses/claude.mjs +196 -0
  30. package/src/harnesses/codex.mjs +188 -0
  31. package/src/harnesses/cursor.mjs +234 -0
  32. package/src/harnesses/dialects.mjs +52 -0
  33. package/src/harnesses/harness.mjs +203 -0
  34. package/src/harnesses/surfaces.mjs +71 -0
  35. package/src/home.mjs +107 -0
  36. package/src/init.mjs +101 -21
  37. package/src/launch-env.mjs +1 -51
  38. package/src/launch.mjs +37 -106
  39. package/src/manifest.mjs +7 -3
  40. package/src/mcp/connection.mjs +218 -0
  41. package/src/mcp/oathe-tools.mjs +380 -140
  42. package/src/notch.mjs +154 -0
  43. package/src/pager.mjs +178 -0
  44. package/src/paths.mjs +13 -1
  45. package/src/plans.mjs +10 -2
  46. package/src/registry.mjs +110 -0
  47. package/src/runtime/discharge.mjs +1 -1
  48. package/src/runtime/provider.mjs +10 -6
  49. package/src/runtime/simple-cage.mjs +32 -12
  50. package/src/runtime/sql-acceptance-lane.mjs +1 -1
  51. package/src/session-host.mjs +8 -6
  52. package/src/sessions.mjs +168 -0
  53. package/src/setup.mjs +494 -0
  54. package/src/speaker.mjs +65 -0
  55. package/src/statements.mjs +113 -0
  56. package/src/substrate.mjs +44 -0
  57. package/src/successor.mjs +3 -2
  58. package/src/traces.mjs +8 -8
  59. package/src/uninstall.mjs +10 -2
  60. package/src/verifier.mjs +135 -47
  61. package/src/verify-dispatch.mjs +169 -0
  62. package/src/welcome.mjs +32 -0
  63. package/src/wire.mjs +64 -0
  64. package/src/workspace-resolver.mjs +178 -0
  65. package/src/workspace.mjs +16 -5
  66. package/vendor/ddl/001_core.sql +1 -1
  67. package/vendor/ddl/004_delegation.sql +1 -1
  68. package/vendor/ddl/006_dependency.sql +1 -1
  69. package/vendor/ddl/008_effect_receipt.sql +1 -1
  70. package/vendor/ddl/009_verified_edge.sql +1 -1
  71. package/vendor/ddl/011_confirm.sql +2 -2
  72. package/vendor/ddl/manifest.json +8 -8
  73. package/assets/claude-splash.png +0 -0
  74. package/assets/resume-splash.png +0 -0
  75. package/src/harness.mjs +0 -271
@@ -0,0 +1,115 @@
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>files</key>
6
+ <dict/>
7
+ <key>files2</key>
8
+ <dict/>
9
+ <key>rules</key>
10
+ <dict>
11
+ <key>^Resources/</key>
12
+ <true/>
13
+ <key>^Resources/.*\.lproj/</key>
14
+ <dict>
15
+ <key>optional</key>
16
+ <true/>
17
+ <key>weight</key>
18
+ <real>1000</real>
19
+ </dict>
20
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
21
+ <dict>
22
+ <key>omit</key>
23
+ <true/>
24
+ <key>weight</key>
25
+ <real>1100</real>
26
+ </dict>
27
+ <key>^Resources/Base\.lproj/</key>
28
+ <dict>
29
+ <key>weight</key>
30
+ <real>1010</real>
31
+ </dict>
32
+ <key>^version.plist$</key>
33
+ <true/>
34
+ </dict>
35
+ <key>rules2</key>
36
+ <dict>
37
+ <key>.*\.dSYM($|/)</key>
38
+ <dict>
39
+ <key>weight</key>
40
+ <real>11</real>
41
+ </dict>
42
+ <key>^(.*/)?\.DS_Store$</key>
43
+ <dict>
44
+ <key>omit</key>
45
+ <true/>
46
+ <key>weight</key>
47
+ <real>2000</real>
48
+ </dict>
49
+ <key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
50
+ <dict>
51
+ <key>nested</key>
52
+ <true/>
53
+ <key>weight</key>
54
+ <real>10</real>
55
+ </dict>
56
+ <key>^.*</key>
57
+ <true/>
58
+ <key>^Info\.plist$</key>
59
+ <dict>
60
+ <key>omit</key>
61
+ <true/>
62
+ <key>weight</key>
63
+ <real>20</real>
64
+ </dict>
65
+ <key>^PkgInfo$</key>
66
+ <dict>
67
+ <key>omit</key>
68
+ <true/>
69
+ <key>weight</key>
70
+ <real>20</real>
71
+ </dict>
72
+ <key>^Resources/</key>
73
+ <dict>
74
+ <key>weight</key>
75
+ <real>20</real>
76
+ </dict>
77
+ <key>^Resources/.*\.lproj/</key>
78
+ <dict>
79
+ <key>optional</key>
80
+ <true/>
81
+ <key>weight</key>
82
+ <real>1000</real>
83
+ </dict>
84
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
85
+ <dict>
86
+ <key>omit</key>
87
+ <true/>
88
+ <key>weight</key>
89
+ <real>1100</real>
90
+ </dict>
91
+ <key>^Resources/Base\.lproj/</key>
92
+ <dict>
93
+ <key>weight</key>
94
+ <real>1010</real>
95
+ </dict>
96
+ <key>^[^/]+$</key>
97
+ <dict>
98
+ <key>nested</key>
99
+ <true/>
100
+ <key>weight</key>
101
+ <real>10</real>
102
+ </dict>
103
+ <key>^embedded\.provisionprofile$</key>
104
+ <dict>
105
+ <key>weight</key>
106
+ <real>20</real>
107
+ </dict>
108
+ <key>^version\.plist$</key>
109
+ <dict>
110
+ <key>weight</key>
111
+ <real>20</real>
112
+ </dict>
113
+ </dict>
114
+ </dict>
115
+ </plist>
@@ -0,0 +1,88 @@
1
+ # Oathe Notch
2
+
3
+ The quiet glass. A macOS island that shows your durable work — and otherwise you
4
+ shouldn't know it's there.
5
+
6
+ Three states, nothing else:
7
+
8
+ - **rest** — literally nothing: dissolved into the MacBook's camera housing, or a
9
+ small sliver on external displays. Hover peeks a lock and how many tasks you hold.
10
+ - **event** — one pushed line, only when something happened (`🔒 1 unclaimed task
11
+ expiring`). Amber persists until seen; receipts show once and fade.
12
+ - **open** — click: work in motion. One row per live claim — task, the surface
13
+ speaking on it, the age of its last word. A row expands to its last progress and
14
+ home, with one act: `continue ↗` (copies `continue <task>`, opens the folder).
15
+ The sheet is Liquid Glass on macOS 26, the island's own black before that.
16
+
17
+ Drag it anywhere; it snaps to the nearest edge of any display and remembers its seat
18
+ (side docks lie vertical). Right-click: Reset Position, Start at Login, Quit.
19
+
20
+ ## Architecture
21
+
22
+ The package computes, the notch renders. This app contains **zero business logic**.
23
+
24
+ ```
25
+ speech acts (claim · statement · done · yield · pickup · verify)
26
+ │ one pg_notify per successful write ("the wire")
27
+ ▼
28
+ Postgres (oathe's local substrate)
29
+ ▲ LISTEN
30
+ │
31
+ `oathe notch --serve` ← the feed: recomputes a frame per event + heartbeat
32
+ │ ndjson frames on stdout {push, breaches, motion, idle, sections, receipt?}
33
+ ▼
34
+ OatheNotch.app ← this repo: supervises the feed child, renders frames
35
+ ```
36
+
37
+ One file per concern:
38
+
39
+ | File | Owns |
40
+ |---|---|
41
+ | `OatheNotchApp.swift` | bootstrap; launchd owns the process, the app owns its feed child |
42
+ | `Feed.swift` | frame decoding + feed supervision (restart with backoff; failures are typed amber lines, never silence) |
43
+ | `NotchModel.swift` | the state machine (motion-free) |
44
+ | `NotchView.swift` | the glass (geometry hugs content) |
45
+ | `NotchPanel.swift` | the window: seat, pointer arming, drag + snap — the only frame owner |
46
+ | `DockAnchor.swift` | where the island lives; persists; `clear()` goes home |
47
+ | `Theme.swift` | every token, named once — read its taxonomy header before adding a constant |
48
+
49
+ ## The two scars (read before touching motion)
50
+
51
+ 1. **The freeze** — never animate window frames from state changes; overlapping
52
+ animator groups wedge the panel. Content animates; the window holds still.
53
+ 2. **The oscillation** — hover must never change window geometry; a frame that flees
54
+ the pointer flickers forever and can't be clicked.
55
+
56
+ ## Install
57
+
58
+ The notch ships with `@oathe/oathe` — the npm tarball carries the built app (prepack
59
+ builds it), and on macOS `oathe init` writes + bootstraps its LaunchAgent for everyone;
60
+ `oathe uninstall` boots it out and removes exactly what init recorded. No opt-in, no
61
+ extra step. `oathe config notchApp <path> --global` overrides the packaged app (a source
62
+ checkout that hasn't run `./make-app.sh` gets an honest `notch-binary-missing` row).
63
+
64
+ ## Build from source
65
+
66
+ ```sh
67
+ ./make-app.sh # swift build + assemble "Oathe Notch.app" (ad-hoc signed)
68
+ oathe init # re-seats the LaunchAgent on the fresh build
69
+ ```
70
+
71
+ Requires macOS 14+, Swift toolchain, and [oathe](https://github.com/oathe-ai/oathe)
72
+ with its local substrate (`oathe init`).
73
+
74
+ ## Platforms
75
+
76
+ macOS 14+ only, Apple Silicon and Intel (the shipped app is a universal binary). The
77
+ glass is native AppKit; everything beneath it is platform-neutral — `oathe notch
78
+ --serve` streams plain ndjson frames, so a Windows or Linux notch is a renderer plus
79
+ its own startup wiring, no substrate or wire changes. On other platforms `oathe init`
80
+ wires nothing and says nothing: there is nothing for the user to do.
81
+
82
+ ## License
83
+
84
+ Apache-2.0, as the rest of the oathe repository.
85
+
86
+ ## License
87
+
88
+ TBD — follows the oathe project's licensing decision.
package/package.json CHANGED
@@ -1,20 +1,28 @@
1
1
  {
2
2
  "name": "@oathe/oathe",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Auto save and verified completion for AI coding agents \u2014 a durable local task board that outlives any one session. D0 preview.",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=22"
7
+ "node": ">=22.5.0"
8
8
  },
9
9
  "bin": {
10
10
  "oathe": "bin/oathe.mjs"
11
11
  },
12
12
  "scripts": {
13
- "test": "node --test tests/*.test.mjs",
13
+ "test": "npm run test:unit && npm run test:heavy",
14
+ "test:unit": "node --test tests/activation.test.mjs tests/atif.test.mjs tests/blocks.test.mjs tests/board-render.test.mjs tests/config.test.mjs tests/cursor-harness.test.mjs tests/discharge.test.mjs tests/fslock.test.mjs tests/harness-contract.test.mjs tests/harness-docs.test.mjs tests/harness-docs-drift.test.mjs tests/harness.test.mjs tests/home.test.mjs tests/horizon-census.test.mjs tests/manifest.test.mjs tests/mcp-connection.test.mjs tests/notch.test.mjs tests/packaging.test.mjs tests/paths.test.mjs tests/registry.test.mjs tests/runtime-provider.test.mjs tests/sessions.test.mjs tests/setup.test.mjs tests/speaker.test.mjs tests/successor.test.mjs tests/traces.test.mjs tests/ux-contract.test.mjs tests/verify-dispatch.test.mjs tests/welcome.test.mjs tests/workspace-resolver.test.mjs tests/workspace.test.mjs",
15
+ "test:heavy": "node --test --test-concurrency=2 tests/amend.test.mjs tests/cli.test.mjs tests/harness-install-contract.test.mjs tests/harness-live-contract.test.mjs tests/init.test.mjs tests/integration.test.mjs tests/launch.test.mjs tests/oathe-tools.test.mjs tests/pager.test.mjs tests/plugin.test.mjs tests/session-host.test.mjs tests/simple-cage.test.mjs tests/sql-acceptance-lane.test.mjs tests/substrate.test.mjs tests/vendor-scripts.test.mjs tests/verifier.test.mjs",
16
+ "lint": "npx -y eslint@10.9.1 .",
17
+ "pack:dry-run": "npm pack --dry-run --ignore-scripts",
18
+ "prepack": "node scripts/pack-notch.mjs",
14
19
  "link-runtime": "node scripts/link-runtime.mjs",
15
20
  "vendor-ddl": "node scripts/vendor-ddl.mjs",
21
+ "live-contract": "node scripts/harness-live-contract.mjs",
22
+ "install-contract": "node scripts/harness-install-contract.mjs",
23
+ "harness-docs-drift": "node scripts/harness-docs-drift.mjs",
24
+ "harness-docs-lock": "node scripts/harness-docs-drift.mjs --lock",
16
25
  "marker-scan": "node scripts/marker-scan.mjs",
17
- "pack:dry-run": "npm pack --dry-run --ignore-scripts",
18
26
  "ci:policy": "node scripts/ci/check-workflows.mjs"
19
27
  },
20
28
  "license": "Apache-2.0",
@@ -33,6 +41,7 @@
33
41
  "src/",
34
42
  "plugin/",
35
43
  "vendor/",
44
+ "notch/Oathe Notch.app",
36
45
  "docs/PRIVACY.md",
37
46
  "LICENSE",
38
47
  "NOTICE",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oathe",
3
3
  "displayName": "Oathe",
4
- "version": "0.2.2",
4
+ "version": "0.3.1",
5
5
  "description": "Claims are speech acts: your session opens on this folder's board, records progress as statements, and yields what it cannot finish. Horizons move only by deliberate acts \u2014 never by session liveness.",
6
6
  "author": {
7
7
  "name": "Oathe"
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "oathe",
3
+ "version": "0.3.1",
4
+ "description": "Claims are speech acts: your session opens on this folder's board, records progress as statements, and yields what it cannot finish. Horizons move only by deliberate acts \u2014 never by session liveness.",
5
+ "author": {
6
+ "name": "Oathe"
7
+ },
8
+ "license": "Apache-2.0",
9
+ "mcpServers": {
10
+ "oathe": {
11
+ "command": "oathe",
12
+ "args": [
13
+ "mcp"
14
+ ]
15
+ }
16
+ },
17
+ "hooks": {
18
+ "hooks": {
19
+ "sessionStart": [
20
+ {
21
+ "command": "oathe hook render-board"
22
+ }
23
+ ],
24
+ "stop": [
25
+ {
26
+ "command": "oathe hook heartbeat"
27
+ }
28
+ ],
29
+ "preCompact": [
30
+ {
31
+ "command": "oathe hook frame-note"
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ }
package/plugin/.mcp.json CHANGED
@@ -4,10 +4,7 @@
4
4
  "command": "oathe",
5
5
  "args": [
6
6
  "mcp"
7
- ],
8
- "env": {
9
- "OATHE_WORKSPACE_DIR": "${CLAUDE_PROJECT_DIR}"
10
- }
7
+ ]
11
8
  }
12
9
  }
13
10
  }
@@ -0,0 +1,18 @@
1
+ ---
2
+ description: Verify a task's asserted completion — optionally on a specific engine (claude | codex | cursor)
3
+ argument-hint: <task-id> [engine]
4
+ ---
5
+
6
+ Run verification for the named task with the `oathe_verify` MCP tool.
7
+
8
+ Arguments: `$ARGUMENTS` — the first word is the task id; the optional second word is the
9
+ engine to judge with (`claude`, `codex`, or `cursor` — any harness CLI present on this
10
+ machine can verify). Passing an engine is how you retry a STALLED verification on a
11
+ different engine after an outage (e.g. a usage limit): the failed run already released its
12
+ claim and recorded the failure, so the retry claims cleanly.
13
+
14
+ Call `oathe_verify` with `{task_id, engine?}`. It returns immediately — verification runs
15
+ in a detached background process. Report to the user exactly what the response says: the
16
+ verdict lands on the board; a rejection reopens the task with the reason recorded on the
17
+ verify-task's completion statement; the engine log path is in the response. Do not wait or
18
+ poll unless the user asks.
@@ -4,11 +4,13 @@
4
4
  import crypto from 'node:crypto';
5
5
  import { failSoft } from './lib.mjs';
6
6
 
7
- await failSoft(async ({ substrate, workspace, identity }) => {
7
+ // Custody is the PRINCIPAL's, not the folder's (R-HOME-BOARD): every claim this principal
8
+ // actively holds gets the note, wherever the task is homed.
9
+ await failSoft(async ({ substrate, identity }) => {
8
10
  const { rows } = await substrate.query(
9
11
  `SELECT work_claim_id, task_id FROM cell.work_claim
10
- WHERE org_id = $1 AND principal_id = $2 AND state = 'active' AND contract_ref LIKE $3`,
11
- [identity.orgId, identity.principalId, `workspace:${workspace};%`]);
12
+ WHERE org_id = $1 AND principal_id = $2 AND state = 'active'`,
13
+ [identity.orgId, identity.principalId]);
12
14
  for (const claim of rows) {
13
15
  await substrate.query(
14
16
  `INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
@@ -4,11 +4,15 @@
4
4
  // ownership_valid_until: session liveness is not an organizational act (R1, correction
5
5
  // packet 2026-08-26); the horizon is set at claim time by the substrate's claim verb.
6
6
 
7
- import crypto from 'node:crypto';
8
- import { failSoft } from './lib.mjs';
9
- import { projectorFor, claimIntervals } from '../../src/atif.mjs';
7
+ import { linkTrace } from '../../src/statements.mjs';
8
+ import { failSoft, ensureSessionRegistered } from './lib.mjs';
9
+ import { claimIntervals } from '../../src/atif.mjs';
10
+ import { projectorFor } from '../../src/harnesses/catalog.mjs';
10
11
 
11
- await failSoft(async ({ substrate, workspace, identity, config, session }) => {
12
+ await failSoft(async ({ substrate, identity, session, paths, workspace }) => {
13
+ // The session's liveness signal — independent of trace linkage (a planning-only session
14
+ // still converges) and fail-soft on its own.
15
+ await ensureSessionRegistered({ session, paths, workspace });
12
16
  if (!session?.transcriptPath) return; // no identity handed to this hook — nothing to link
13
17
  // R3 (§5): evidence is claim-specific and interval-specific. The session's own structured
14
18
  // trace names the tasks it ACTED on (the projector's claim_events); only those claims get
@@ -16,7 +20,7 @@ await failSoft(async ({ substrate, workspace, identity, config, session }) => {
16
20
  // a planning-only session leaves no claim evidence.
17
21
  let touched;
18
22
  try {
19
- const trajectory = projectorFor(session.transcriptPath).project(session.transcriptPath);
23
+ const trajectory = (await projectorFor(session.transcriptPath)).project(session.transcriptPath);
20
24
  touched = new Set(claimIntervals(trajectory).map((i) => i.task_id));
21
25
  } catch {
22
26
  return; // fail-soft: an unreadable or unprojectable trace attributes nothing
@@ -25,25 +29,17 @@ await failSoft(async ({ substrate, workspace, identity, config, session }) => {
25
29
  // Linkage covers ASSERTED claims too: a claim taken and completed inside a single turn has
26
30
  // never seen a heartbeat while active — the turn-end hook is its only chance to leave the
27
31
  // trace evidence the verifier will demand. (Settled claims are closed; nothing to link.)
28
- const { rows } = await substrate.query(
29
- `SELECT work_claim_id, task_id FROM cell.work_claim
30
- WHERE org_id = $1 AND principal_id = $2 AND settled_at IS NULL
31
- AND state IN ('active', 'completion_asserted') AND contract_ref LIKE $3
32
- AND task_id = ANY($4)`,
33
- [identity.orgId, identity.principalId, `workspace:${workspace};%`, [...touched]]);
34
- for (const claim of rows) {
35
- await substrate.query(
36
- `INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
37
- execution_actor, claim_principal, statement_type, subject_ref, proposition,
38
- evidence_refs, epistemic_status, asserted_at)
39
- SELECT $1, $2, $3, $4, $5, $6, 'progress', $7, $8, $9::jsonb, 'observed', now()
40
- WHERE NOT EXISTS (
41
- SELECT 1 FROM cell.agent_statement
42
- WHERE org_id = $2 AND work_claim_id = $4 AND subject_ref = $7)`,
43
- [crypto.randomUUID(), identity.orgId, claim.task_id, claim.work_claim_id,
44
- `session:${session.sessionId}`, identity.principalId, `trace:${session.sessionId}`,
45
- `${session.harness} session ${session.sessionId} worked this claim — transcript at `
46
- + `${session.transcriptPath} (fan-out derived at read time)`,
47
- JSON.stringify([session.transcriptPath])]);
32
+ // Custody is the PRINCIPAL's, not the folder's (R-HOME-BOARD): a claim homed on another
33
+ // board is still this principal's, and the trace's own touched-set is what scopes linkage.
34
+ // The write wrapper already linked every claim SPOKEN through the tools (linkTrace at
35
+ // the act — the SPEAKER primitive); this turn-end sweep covers claims the transcript
36
+ // proves were WORKED without a substrate write this turn. Same writer, idempotent.
37
+ for (const taskId of touched) {
38
+ await linkTrace({
39
+ client: substrate,
40
+ identity,
41
+ taskId,
42
+ session: { sessionId: session.sessionId, transcriptPath: session.transcriptPath, harness: session.harness },
43
+ });
48
44
  }
49
45
  });
@@ -3,37 +3,68 @@
3
3
  //
4
4
  // A hook must NEVER break a session: every entry point runs through failSoft, which turns any
5
5
  // substrate absence into a quiet note (SessionStart) or silence (Stop/PreCompact) and exit 0.
6
+ // Payloads arrive in each harness's own dialect (Claude/Codex: `cwd`; Cursor:
7
+ // `workspace_roots[]`) — the catalog's dialect sniff normalizes them, and the reply speaks the
8
+ // same dialect back. A session with no resolvable workspace exits silently: there is no board
9
+ // to speak about, and hooks are the one sanctioned fail-soft surface.
10
+
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
6
13
 
7
14
  import { Substrate } from '../../src/substrate.mjs';
8
- import { buildPaths } from '../../src/paths.mjs';
9
- import { workspaceRef } from '../../src/workspace.mjs';
15
+ import { buildPaths, homeOf } from '../../src/paths.mjs';
10
16
  import { OatheConfig } from '../../src/config.mjs';
11
- import { harnessForTracePath } from '../../src/traces.mjs';
12
- import { launchedHarness } from '../../src/launch-env.mjs';
13
17
 
14
- /** The hook's JSON input on stdin (Claude and Codex both deliver {cwd, hook_event_name, …}). */
18
+ import { dialectFor, ownerOfTracePath } from '../../src/harnesses/catalog.mjs';
19
+ import { cwdDialect } from '../../src/harnesses/dialects.mjs';
20
+ import { WorkspaceResolver } from '../../src/workspace-resolver.mjs';
21
+
22
+ /** The hook's JSON input on stdin, whichever dialect the harness speaks. */
15
23
  export async function readHookInput() {
16
24
  let raw = '';
17
25
  for await (const chunk of process.stdin) raw += chunk;
18
- try { return JSON.parse(raw); } catch { return {}; }
26
+ const input = (() => { try { return JSON.parse(raw); } catch { return {}; } })();
27
+ // Drift monitors: with OATHE_HOOK_CAPTURE_DIR set, the RAW payload is written before any
28
+ // normalization — the live lane compares what the harness actually sends against the pinned
29
+ // fixtures. Off by default; a capture failure never costs the session (fail-soft surface).
30
+ const captureDir = process.env.OATHE_HOOK_CAPTURE_DIR;
31
+ if (captureDir) {
32
+ try {
33
+ fs.mkdirSync(captureDir, { recursive: true });
34
+ fs.writeFileSync(path.join(captureDir, `${input.hook_event_name ?? 'unknown'}-${Date.now()}.json`), raw);
35
+ } catch (e) {
36
+ process.stderr.write(`oathe hook: capture ${String(e?.message || e)}\n`);
37
+ }
38
+ }
39
+ return input;
19
40
  }
20
41
 
21
- export function buildHookContext(input, env = process.env) {
42
+ export async function buildHookContext(input, env = process.env) {
22
43
  const paths = buildPaths(env);
23
- const cwd = input.cwd || process.cwd();
44
+ const dialect = dialectFor(input) ?? cwdDialect;
45
+ const normalized = dialect.normalizePayload(input ?? {});
46
+ // A payload naming a directory is described outright; one without falls to the resolution
47
+ // ladder (env vars, guarded cwd). Either way the facts (ref, synthetic) come from the one
48
+ // describer. An unresolvable session throws OATHE_WORKSPACE_UNRESOLVED — failSoft exits silently.
49
+ const home = homeOf(env);
50
+ const place = normalized.cwd
51
+ ? WorkspaceResolver.describe({ dir: normalized.cwd, home })
52
+ : await new WorkspaceResolver({ env, home }).resolve();
53
+ const cwd = place.dir;
24
54
  const config = new OatheConfig({ env, cwd });
25
- // The session identity both harnesses hand every hook — the trace linkage rides on it.
26
- const session = input.session_id
55
+ // The session identity the harness hands every hook — the trace linkage rides on it.
56
+ const session = normalized.sessionId
27
57
  ? {
28
- sessionId: input.session_id,
29
- transcriptPath: input.transcript_path ?? null,
30
- harness: harnessForTracePath(input.transcript_path ?? ''),
58
+ sessionId: normalized.sessionId,
59
+ transcriptPath: normalized.transcriptPath,
60
+ harness: ownerOfTracePath(normalized.transcriptPath ?? ''),
31
61
  }
32
62
  : null;
33
63
  return {
34
64
  session,
35
65
  substrate: new Substrate({ database: config.get('db'), paths, env, config }),
36
- workspace: workspaceRef(cwd),
66
+ workspace: place.ref,
67
+ synthetic: place.synthetic, // R-BOARD-SCOPE: a staging dir serves the full board
37
68
  identity: {
38
69
  orgId: config.get('org'),
39
70
  principalId: config.get('principal') || env.USER || 'operator',
@@ -41,41 +72,73 @@ export function buildHookContext(input, env = process.env) {
41
72
  },
42
73
  config,
43
74
  cwd,
75
+ dialect,
76
+ paths,
77
+ env,
44
78
  };
45
79
  }
46
80
 
47
81
  /**
48
- * The SessionStart hook's JSON frame: `context` reaches the MODEL as additional context,
49
- * `message` is the line the USER sees when the session loads — the visible confirmation that
50
- * oathe is watching this folder.
82
+ * The SessionStart reply in the session's own dialect: `context` reaches the MODEL, `message`
83
+ * is the user-visible line (dialects without a message channel carry context only).
84
+ */
85
+ export function emitSessionStart({ context, message, dialect = cwdDialect }) {
86
+ process.stdout.write(dialect.formatSessionStart({ context, message }));
87
+ }
88
+
89
+ /**
90
+ * The session's liveness signal — SessionStart and the heartbeat both speak it, so a living
91
+ * session is never invisible (a pre-feature or resumed session converges at its next turn).
92
+ * The ps walk rides the facts thunk: paid only when the registry actually (re)registers.
93
+ * Fail-soft on its own: a broken registry costs the facts, never the session.
51
94
  */
52
- export function emitSessionStart({ context, message }) {
53
- process.stdout.write(`${JSON.stringify({
54
- hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: context },
55
- systemMessage: message,
56
- })}\n`);
95
+ export async function ensureSessionRegistered({ session, paths, workspace = undefined }) {
96
+ try {
97
+ if (!session?.sessionId) return;
98
+ const { SessionRegistry, processAncestry, nearestAppBundle } = await import('../../src/sessions.mjs');
99
+ const { ownedAncestorIndex } = await import('../../src/harnesses/catalog.mjs');
100
+ // The row describes THE HARNESS PROCESS, not whatever interposer spawned the hook
101
+ // (cursor-agent runs hooks through a short-lived /bin/zsh — registering the shell's pid
102
+ // would sweep the session the moment the shell exits). Walk up to the nearest
103
+ // adapter-owned ancestor; a chain with none (fixtures, bare runners) keeps the ppid.
104
+ const walk = processAncestry({ pid: process.ppid });
105
+ const owned = ownedAncestorIndex(walk);
106
+ const ancestry = owned <= 0 ? walk : walk.slice(owned);
107
+ await new SessionRegistry({ sessionsPath: paths.sessionsPath }).ensure({
108
+ sessionId: session.sessionId,
109
+ pid: ancestry[0]?.pid ?? process.ppid,
110
+ facts: () => ({
111
+ ancestry,
112
+ app: nearestAppBundle(ancestry),
113
+ transcriptPath: session.transcriptPath ?? undefined,
114
+ workspace,
115
+ }),
116
+ });
117
+ } catch (e) {
118
+ process.stderr.write(`oathe hook: sessions ${String(e?.message || e)}\n`);
119
+ }
57
120
  }
58
121
 
59
122
  /**
60
- * Run `fn`; on any failure print `quietNote` (when given) as a visible session-load line and
61
- * exit 0 regardless. The board being unavailable is information for the session, never an
62
- * error that blocks it.
123
+ * Run `fn`; on failure print `quietNote` (when given) as a visible session-load line and exit 0
124
+ * regardless. The board being unavailable is information for the session, never an error that
125
+ * blocks it — and a session with no resolvable workspace has no board to mention at all.
63
126
  */
64
127
  export async function failSoft(fn, { quietNote = null } = {}) {
65
- // The opt-in gate: the plugin reaches every session on the machine, but only a session the
66
- // oathe launcher started carries the marker. Everything else is a silent noop — no output,
67
- // no substrate contact — because that session never asked to be on the board.
68
- if (!launchedHarness()) process.exit(0);
69
128
  let substrate = null;
129
+ let dialect = cwdDialect;
70
130
  try {
71
131
  const input = await readHookInput();
72
- const ctx = buildHookContext(input);
132
+ dialect = dialectFor(input) ?? cwdDialect;
133
+ const ctx = await buildHookContext(input);
73
134
  substrate = ctx.substrate;
74
135
  await fn(ctx, input);
75
136
  } catch (e) {
76
- const detail = String(e?.message || e);
77
- if (quietNote) emitSessionStart({ context: quietNote, message: `${quietNote} (${detail.slice(0, 120)})` });
78
- process.stderr.write(`oathe hook: ${detail}\n`);
137
+ if (e?.code !== 'OATHE_WORKSPACE_UNRESOLVED') {
138
+ const detail = String(e?.message || e);
139
+ if (quietNote) emitSessionStart({ context: quietNote, message: `${quietNote} (${detail.slice(0, 120)})`, dialect });
140
+ process.stderr.write(`oathe hook: ${detail}\n`);
141
+ }
79
142
  } finally {
80
143
  if (substrate) await substrate.close().catch(() => {});
81
144
  }
@@ -1,11 +1,51 @@
1
- // SessionStart — the board, delivered twice over: the full list as additional context for the
2
- // MODEL, and one visible line for the USER. The rendering itself lives in src/board-render.mjs,
3
- // shared with the launcher (which prints the same board into scrollback before the TUI starts).
1
+ // SessionStart — activation + the board. Opening a session on a folder ACTIVATES its
2
+ // workspace (central registry row + the context-file fences, through the ONE writer in
3
+ // src/activation.mjs, disclosed in the render) and then delivers the board twice over: the
4
+ // full list as additional context for the MODEL, one visible line for the USER — each in the
5
+ // session's own dialect. Activation failing must never cost the session its board: the
6
+ // failure is reported on stderr and the render proceeds (hooks are the sanctioned fail-soft).
4
7
 
5
- import { failSoft, emitSessionStart } from './lib.mjs';
8
+ import { failSoft, emitSessionStart, ensureSessionRegistered } from './lib.mjs';
6
9
  import { renderBoard } from '../../src/board-render.mjs';
10
+ import { WorkspaceRegistry } from '../../src/registry.mjs';
7
11
 
8
- await failSoft(async ({ substrate, workspace, identity, config }) => {
9
- const { context, message } = await renderBoard({ client: substrate, identity, workspace, config });
10
- emitSessionStart({ context, message });
12
+ await failSoft(async ({ substrate, workspace, synthetic, identity, config, cwd, dialect, paths, env, session }) => {
13
+ const registry = new WorkspaceRegistry({ registryPath: paths.registryPath });
14
+ let disclosed = null;
15
+ try {
16
+ const [{ activateWorkspace }, { InstallManifest }, { packageVersion }] = await Promise.all([
17
+ import('../../src/activation.mjs'), import('../../src/manifest.mjs'), import('../../src/context.mjs'),
18
+ ]);
19
+ const manifest = InstallManifest.load({ manifestPath: paths.manifestPath, backupsDir: paths.backupsDir });
20
+ const out = await activateWorkspace({
21
+ cwd, env, manifest, registry, config, version: packageVersion(paths), source: 'hook:session-start',
22
+ });
23
+ // Disclose only when something was actually written — an unchanged fence needs no line,
24
+ // and autoActivate=false registers quietly (the user's own explicit choice).
25
+ disclosed = out.actions.some((a) => a.changed) ? out.disclosed : null;
26
+ } catch (e) {
27
+ process.stderr.write(`oathe hook: activation ${String(e?.message || e)}\n`);
28
+ }
29
+ // Session liveness: the hook's ppid IS the harness process — the shared convergence
30
+ // signal registers its facts so the notch can meet the living process behind a claim.
31
+ await ensureSessionRegistered({ session, paths, workspace });
32
+ // R-PAGER: the breach digest is computed apart from the board, and a failure there is
33
+ // reported on stderr while the board still renders — the digest is a courtesy, the board
34
+ // is the session's contract.
35
+ let breaches = [];
36
+ try {
37
+ const { Pager } = await import('../../src/pager.mjs');
38
+ breaches = await new Pager({ client: substrate, identity, config, registry }).breaches();
39
+ } catch (e) {
40
+ process.stderr.write(`oathe hook: pager ${String(e?.message || e)}\n`);
41
+ }
42
+ const { context, message } = await renderBoard({ client: substrate, identity, workspace, config, synthetic, breaches });
43
+ // R-QUIET: the board message is breaches-or-silence; a real write's disclosure still speaks
44
+ // (a receipt, printed once) even when the board itself has nothing to push.
45
+ const visible = [message, disclosed].filter(Boolean).join('\n') || null;
46
+ emitSessionStart({
47
+ context: disclosed ? `${context}\n\n_${disclosed}_` : context,
48
+ message: visible,
49
+ dialect,
50
+ });
11
51
  }, { quietNote: 'Oathe board unavailable — substrate not initialized; run `oathe init`' });