@oathe/oathe 0.2.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +3 -4
- package/README.md +15 -45
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +401 -59
- package/docs/PRIVACY.md +13 -5
- package/notch/Oathe Notch.app/Contents/Info.plist +13 -0
- package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
- package/notch/Oathe Notch.app/Contents/_CodeSignature/CodeResources +115 -0
- package/notch/README.md +88 -0
- package/package.json +13 -4
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +36 -0
- package/plugin/.mcp.json +1 -4
- package/plugin/commands/verify.md +18 -0
- package/plugin/hooks/frame-note.mjs +5 -3
- package/plugin/hooks/heartbeat.mjs +21 -25
- package/plugin/hooks/lib.mjs +96 -33
- package/plugin/hooks/render-board.mjs +47 -7
- package/src/activation.mjs +126 -0
- package/src/atif.mjs +4 -13
- package/src/blocks.mjs +113 -8
- package/src/board-render.mjs +55 -29
- package/src/config.mjs +100 -15
- package/src/context.mjs +4 -8
- package/src/doctor.mjs +96 -15
- package/src/fence.mjs +85 -0
- package/src/fslock.mjs +51 -0
- package/src/harnesses/catalog.mjs +180 -0
- package/src/harnesses/claude.mjs +196 -0
- package/src/harnesses/codex.mjs +188 -0
- package/src/harnesses/cursor.mjs +234 -0
- package/src/harnesses/dialects.mjs +52 -0
- package/src/harnesses/harness.mjs +203 -0
- package/src/harnesses/surfaces.mjs +71 -0
- package/src/home.mjs +107 -0
- package/src/init.mjs +101 -21
- package/src/launch-env.mjs +1 -51
- package/src/launch.mjs +36 -105
- package/src/manifest.mjs +7 -3
- package/src/mcp/connection.mjs +218 -0
- package/src/mcp/oathe-tools.mjs +380 -141
- package/src/notch.mjs +160 -0
- package/src/pager.mjs +178 -0
- package/src/paths.mjs +13 -1
- package/src/plans.mjs +10 -2
- package/src/registry.mjs +110 -0
- package/src/runtime/discharge.mjs +1 -1
- package/src/runtime/provider.mjs +10 -7
- package/src/runtime/simple-cage.mjs +18 -9
- package/src/runtime/sql-acceptance-lane.mjs +1 -1
- package/src/session-host.mjs +8 -6
- package/src/sessions.mjs +168 -0
- package/src/setup.mjs +494 -0
- package/src/speaker.mjs +65 -0
- package/src/statements.mjs +113 -0
- package/src/substrate.mjs +44 -0
- package/src/successor.mjs +1 -1
- package/src/traces.mjs +8 -8
- package/src/uninstall.mjs +10 -2
- package/src/verifier.mjs +135 -47
- package/src/verify-dispatch.mjs +169 -0
- package/src/welcome.mjs +32 -0
- package/src/wire.mjs +64 -0
- package/src/workspace-resolver.mjs +178 -0
- package/src/workspace.mjs +16 -5
- package/vendor/ddl/001_core.sql +1 -1
- package/vendor/ddl/004_delegation.sql +1 -1
- package/vendor/ddl/006_dependency.sql +1 -1
- package/vendor/ddl/008_effect_receipt.sql +1 -1
- package/vendor/ddl/009_verified_edge.sql +1 -1
- package/vendor/ddl/011_confirm.sql +2 -2
- package/vendor/ddl/manifest.json +8 -8
- package/assets/handoff-splash.png +0 -0
- package/src/harness.mjs +0 -271
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// oathe — the Cursor adapter (IDE and CLI share ~/.cursor). Wiring is installer-written owned
|
|
2
|
+
// entries: an object path in ~/.cursor/mcp.json and owned ARRAY elements among the user's own
|
|
3
|
+
// hooks in ~/.cursor/hooks.json — both documented user-editable and hot-reloaded, verified
|
|
4
|
+
// after every write, backed up once, manifest-recorded, byte-reversible.
|
|
5
|
+
// Schema source: .harness-docs/cursor/{mcp,hooks}.md (pinned 2026-08-28).
|
|
6
|
+
//
|
|
7
|
+
// Cursor quirks the facts encode: hook payloads carry `workspace_roots[]` (not `cwd`) and the
|
|
8
|
+
// sessionStart reply is snake_case fire-and-forget; hook scripts see CURSOR_PROJECT_DIR (with
|
|
9
|
+
// a CLAUDE_PROJECT_DIR compatibility alias) but MCP servers get NO documented project-dir env
|
|
10
|
+
// var — the resolution ladder's roots/cwd steps carry them; a machine can hold ~/.cursor with
|
|
11
|
+
// no CLI on PATH (the IDE alone), so detection keys on the config home; user hooks run from
|
|
12
|
+
// ~/.cursor and GUI apps read no shell rc, so every command is an ABSOLUTE path.
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
|
|
17
|
+
import { Harness, HarnessOnboardError } from './harness.mjs';
|
|
18
|
+
import { workspaceRootsDialect } from './dialects.mjs';
|
|
19
|
+
import { JsonArrayEntries, JsonEntries } from '../blocks.mjs';
|
|
20
|
+
import { sha256Hex } from '../manifest.mjs';
|
|
21
|
+
|
|
22
|
+
const HOOK_EVENTS = Object.freeze([
|
|
23
|
+
{ event: 'sessionStart', script: 'render-board' },
|
|
24
|
+
{ event: 'stop', script: 'heartbeat' },
|
|
25
|
+
{ event: 'preCompact', script: 'frame-note' },
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
export class CursorHarness extends Harness {
|
|
29
|
+
static harnessName = 'cursor';
|
|
30
|
+
static displayName = 'Cursor';
|
|
31
|
+
static covers = 'CLI/Desktop App';
|
|
32
|
+
static bin = 'cursor-agent';
|
|
33
|
+
// The installer ships both names (verified 2026-08-29); either on PATH is the CLI.
|
|
34
|
+
static cliBins = Object.freeze(['cursor-agent', 'cursor']);
|
|
35
|
+
static clientNames = Object.freeze(['cursor']);
|
|
36
|
+
static contextFiles = Object.freeze(['AGENTS.md']);
|
|
37
|
+
static projectDirEnvVar = 'CURSOR_PROJECT_DIR';
|
|
38
|
+
// Wiring is our own JSON writes into ~/.cursor — no CLI needed; the IDE alone reads them.
|
|
39
|
+
static wiring = Object.freeze({ needsCli: false });
|
|
40
|
+
static hooks = Object.freeze({ dialect: workspaceRootsDialect });
|
|
41
|
+
// The missing primitive, restored (founder ruling 2026-08-30: all harnesses on the same
|
|
42
|
+
// primitives, each with its own adapter): cursor launches its interactive CLI agent.
|
|
43
|
+
static launch = Object.freeze({ splash: true, bin: 'cursor-agent' });
|
|
44
|
+
// The IDE's spawned children live inside Cursor.app (helper bundles); the CLI is cliBins.
|
|
45
|
+
static surfaces = Object.freeze({
|
|
46
|
+
ownsExec: (exec) => exec.includes(`${path.sep}Cursor.app${path.sep}`)
|
|
47
|
+
|| CursorHarness.cliBins.includes(path.basename(exec)),
|
|
48
|
+
name: () => 'cursor',
|
|
49
|
+
});
|
|
50
|
+
// cursor/cli-installation.md:10 (pinned 2026-08-29).
|
|
51
|
+
static install = Object.freeze({ installer: 'curl https://cursor.com/install -fsS | bash', bin: 'cursor-agent', versionArgs: ['--version'] });
|
|
52
|
+
// Headless: `agent -p --output-format json` → {type:"result", result} (cursor/cli-output-format.md);
|
|
53
|
+
// CI auth CURSOR_API_KEY (cursor/cli-authentication.md:24-37, cli-github-actions.md:17). A fresh
|
|
54
|
+
// project dir is untrusted — the CLI refuses to run there without --trust (observed live 2026-08-29).
|
|
55
|
+
static headless = Object.freeze({
|
|
56
|
+
auth: ['CURSOR_API_KEY'],
|
|
57
|
+
command: (prompt, model = null) => ['cursor-agent', ['-p', prompt, '--trust', '--output-format', 'json', ...(model ? ['--model', model] : [])]],
|
|
58
|
+
extract: (stdout) => CursorHarness.extractJsonResult(stdout),
|
|
59
|
+
});
|
|
60
|
+
static traces = null; // Cursor keeps no session store we read; its hook payload carries transcript_path: null
|
|
61
|
+
static docs = Object.freeze([
|
|
62
|
+
'cursor/mcp', 'cursor/mcp-install-links', 'cursor/hooks', 'cursor/plugins', 'cursor/plugins-reference',
|
|
63
|
+
'cursor/third-party-hooks', 'cursor/rules', 'cursor/cli-mcp', 'cursor/cli-configuration', 'cursor/cli-overview',
|
|
64
|
+
'cursor/cli-installation', 'cursor/cli-using', 'cursor/cli-headless', 'cursor/cli-authentication',
|
|
65
|
+
'cursor/cli-parameters', 'cursor/cli-output-format', 'cursor/cli-slash-commands', 'cursor/cli-permissions',
|
|
66
|
+
'cursor/cli-github-actions', 'cursor/cli-shell-mode',
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/** The IDE alone leaves no bin on PATH — the config home is the install evidence. */
|
|
70
|
+
static installedFrom(presence) {
|
|
71
|
+
return presence.configHome !== null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
constructor(o) {
|
|
75
|
+
super({ ...o, name: 'cursor' });
|
|
76
|
+
this.entries = new JsonEntries();
|
|
77
|
+
this.arrays = new JsonArrayEntries();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
get mcpConfigPath() {
|
|
83
|
+
return path.join(this.configHome, 'mcp.json');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get hooksConfigPath() {
|
|
87
|
+
return path.join(this.configHome, 'hooks.json');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The absolute oathe address: the bin resolved on PATH, else <node> <packageRoot>/bin/oathe.mjs
|
|
92
|
+
* (npm shims ride `#!/usr/bin/env node`, and a GUI-launched Cursor may not carry node's dir
|
|
93
|
+
* on PATH — the fallback names the runtime explicitly).
|
|
94
|
+
* @returns {{command: string, args: string[], hookPrefix: string}}
|
|
95
|
+
*/
|
|
96
|
+
#oatheAddress() {
|
|
97
|
+
for (const dir of this.envPath.split(':').filter(Boolean)) {
|
|
98
|
+
const candidate = path.join(dir, 'oathe');
|
|
99
|
+
try {
|
|
100
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
101
|
+
return { command: candidate, args: [], hookPrefix: candidate };
|
|
102
|
+
} catch { /* keep looking */ }
|
|
103
|
+
}
|
|
104
|
+
const binPath = path.join(this.paths.packageRoot, 'bin/oathe.mjs');
|
|
105
|
+
return { command: process.execPath, args: [binPath], hookPrefix: `${process.execPath} ${binPath}` };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#hookEntries(hookPrefix) {
|
|
109
|
+
return HOOK_EVENTS.map(({ event, script }) => {
|
|
110
|
+
const command = `${hookPrefix} hook ${script}`;
|
|
111
|
+
return {
|
|
112
|
+
path: ['hooks', event],
|
|
113
|
+
element: { command },
|
|
114
|
+
owns: (el) => el?.command === command,
|
|
115
|
+
match: command,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#readJson(file) {
|
|
121
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#applyOwned({ file, before, apply, verify, refuseDetail }) {
|
|
125
|
+
const { content, changed } = apply(before);
|
|
126
|
+
if (changed) {
|
|
127
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
128
|
+
fs.writeFileSync(file, content);
|
|
129
|
+
}
|
|
130
|
+
const now = this.#readJson(file);
|
|
131
|
+
if (now === null || !verify(now)) {
|
|
132
|
+
throw new HarnessOnboardError('CURSOR_VERIFICATION_FAILED',
|
|
133
|
+
`verification failed: ${file} does not carry ${refuseDetail} after the write — refusing `
|
|
134
|
+
+ 'to record an install that cannot be proven');
|
|
135
|
+
}
|
|
136
|
+
return changed;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** What init writes — from the same address and entries onboard() writes. */
|
|
140
|
+
describe() {
|
|
141
|
+
const address = this.#oatheAddress();
|
|
142
|
+
return [
|
|
143
|
+
`${this.mcpConfigPath}: mcpServers.oathe → ${[address.command, ...address.args, 'mcp'].join(' ')}`,
|
|
144
|
+
`${this.hooksConfigPath}: ${HOOK_EVENTS.map((h) => h.event).join(', ')} → ${address.hookPrefix} hook <script>`,
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
onboard({ manifest, version }) {
|
|
149
|
+
const address = this.#oatheAddress();
|
|
150
|
+
const mcpValue = { command: address.command, args: [...address.args, 'mcp'] };
|
|
151
|
+
const hookEntries = this.#hookEntries(address.hookPrefix);
|
|
152
|
+
const hooksAbsentBefore = !fs.existsSync(this.hooksConfigPath);
|
|
153
|
+
// Version ownership is decided ONCE (the file we created carries our version key) and then
|
|
154
|
+
// carried forward — a re-run must upsert the SAME row identity, never mint a sibling.
|
|
155
|
+
const ownsVersion = hooksAbsentBefore
|
|
156
|
+
|| (manifest.rows.find((r) => r.harness === this.name && r.file === this.hooksConfigPath
|
|
157
|
+
&& r.kind === 'json-array')?.detail?.owns_version ?? false);
|
|
158
|
+
|
|
159
|
+
manifest.backupOnce(this.mcpConfigPath);
|
|
160
|
+
const mcpBefore = fs.existsSync(this.mcpConfigPath) ? fs.readFileSync(this.mcpConfigPath, 'utf8') : '';
|
|
161
|
+
const mcpChanged = this.#applyOwned({
|
|
162
|
+
file: this.mcpConfigPath,
|
|
163
|
+
before: mcpBefore,
|
|
164
|
+
apply: (text) => this.entries.apply(text, [{ path: ['mcpServers', 'oathe'], value: mcpValue }]),
|
|
165
|
+
verify: (doc) => doc?.mcpServers?.oathe?.command === mcpValue.command,
|
|
166
|
+
refuseDetail: 'the mcpServers.oathe entry',
|
|
167
|
+
});
|
|
168
|
+
manifest.upsert({
|
|
169
|
+
harness: this.name,
|
|
170
|
+
file: this.mcpConfigPath,
|
|
171
|
+
kind: 'json-path',
|
|
172
|
+
detail: { paths: [['mcpServers', 'oathe']] },
|
|
173
|
+
blockVersion: version,
|
|
174
|
+
sha256: sha256Hex(JSON.stringify([{ path: ['mcpServers', 'oathe'], value: mcpValue }])),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
manifest.backupOnce(this.hooksConfigPath);
|
|
178
|
+
const hooksBefore = hooksAbsentBefore ? '' : fs.readFileSync(this.hooksConfigPath, 'utf8');
|
|
179
|
+
const hooksChanged = this.#applyOwned({
|
|
180
|
+
file: this.hooksConfigPath,
|
|
181
|
+
before: hooksBefore,
|
|
182
|
+
apply: (text) => {
|
|
183
|
+
let out = this.arrays.apply(text, hookEntries);
|
|
184
|
+
// A file we created carries the schema version; a user's own file keeps their value.
|
|
185
|
+
if (hooksAbsentBefore) out = this.entries.apply(out.content, [{ path: ['version'], value: 1 }]);
|
|
186
|
+
return out;
|
|
187
|
+
},
|
|
188
|
+
verify: (doc) => hookEntries.every((e) => (doc?.hooks?.[e.path[1]] ?? []).some((el) => el?.command === e.match)),
|
|
189
|
+
refuseDetail: 'the three owned oathe hook entries',
|
|
190
|
+
});
|
|
191
|
+
manifest.upsert({
|
|
192
|
+
harness: this.name,
|
|
193
|
+
file: this.hooksConfigPath,
|
|
194
|
+
kind: 'json-array',
|
|
195
|
+
detail: {
|
|
196
|
+
entries: hookEntries.map((e) => ({ path: e.path, match: e.match })),
|
|
197
|
+
owns_version: ownsVersion,
|
|
198
|
+
},
|
|
199
|
+
blockVersion: version,
|
|
200
|
+
sha256: sha256Hex(JSON.stringify(hookEntries.map((e) => e.match))),
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return [
|
|
204
|
+
{ action: 'cursor-mcp-entry', file: this.mcpConfigPath, changed: mcpChanged },
|
|
205
|
+
{ action: 'cursor-hooks-entries', file: this.hooksConfigPath, changed: hooksChanged },
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
offboard({ manifest }) {
|
|
210
|
+
const rows = manifest.removeWhere((r) => r.harness === this.name);
|
|
211
|
+
const actions = [];
|
|
212
|
+
for (const row of rows) {
|
|
213
|
+
if (!fs.existsSync(row.file)) {
|
|
214
|
+
actions.push({ action: 'cursor-target-absent', file: row.file });
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const before = fs.readFileSync(row.file, 'utf8');
|
|
218
|
+
let result;
|
|
219
|
+
if (row.kind === 'json-path') {
|
|
220
|
+
result = this.entries.remove(before, row.detail?.paths ?? []);
|
|
221
|
+
} else {
|
|
222
|
+
const entries = (row.detail?.entries ?? []).map((e) => ({
|
|
223
|
+
path: e.path,
|
|
224
|
+
owns: (el) => el?.command === e.match,
|
|
225
|
+
}));
|
|
226
|
+
result = this.arrays.remove(before, entries);
|
|
227
|
+
if (row.detail?.owns_version) result = this.entries.remove(result.content, [['version']]);
|
|
228
|
+
}
|
|
229
|
+
if (result.changed) fs.writeFileSync(row.file, result.content);
|
|
230
|
+
actions.push({ action: `cursor-removed-${row.kind}`, file: row.file, changed: result.changed });
|
|
231
|
+
}
|
|
232
|
+
return actions;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// oathe — hook payload dialects. Two wire shapes exist across the supported harnesses: the
|
|
2
|
+
// cwd shape (Claude Code and Codex: `cwd` + camelCase SessionStart output envelope) and the
|
|
3
|
+
// workspace-roots shape (Cursor: `workspace_roots[]` + snake_case fire-and-forget output).
|
|
4
|
+
// Each dialect owns its sniff, its normalization, and its output format — pinned by the
|
|
5
|
+
// fixtures in tests/fixtures/hooks/ against the .harness-docs snapshot.
|
|
6
|
+
|
|
7
|
+
/** @typedef {{cwd: string|null, sessionId: string|null, transcriptPath: string|null}} HookSession */
|
|
8
|
+
|
|
9
|
+
export const cwdDialect = Object.freeze({
|
|
10
|
+
name: 'cwd',
|
|
11
|
+
matches(input) {
|
|
12
|
+
return typeof input?.cwd === 'string';
|
|
13
|
+
},
|
|
14
|
+
/** @returns {HookSession} */
|
|
15
|
+
normalizePayload(input) {
|
|
16
|
+
return {
|
|
17
|
+
cwd: input.cwd ?? null,
|
|
18
|
+
sessionId: input.session_id ?? null,
|
|
19
|
+
transcriptPath: input.transcript_path ?? null,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
formatSessionStart({ context, message }) {
|
|
23
|
+
// R-QUIET: a null message is SILENCE — the key is omitted, or the harness renders "null".
|
|
24
|
+
return `${JSON.stringify({
|
|
25
|
+
hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: context },
|
|
26
|
+
...(message ? { systemMessage: message } : {}),
|
|
27
|
+
})}\n`;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const workspaceRootsDialect = Object.freeze({
|
|
32
|
+
name: 'workspace-roots',
|
|
33
|
+
matches(input) {
|
|
34
|
+
return Array.isArray(input?.workspace_roots);
|
|
35
|
+
},
|
|
36
|
+
/** @returns {HookSession} first root scopes the board — multiroot workspaces carry several */
|
|
37
|
+
normalizePayload(input) {
|
|
38
|
+
return {
|
|
39
|
+
cwd: input.workspace_roots[0] ?? null,
|
|
40
|
+
sessionId: input.session_id ?? input.conversation_id ?? null,
|
|
41
|
+
transcriptPath: input.transcript_path ?? null,
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
// Fire-and-forget: no user-visible message channel exists in this dialect, so `message`
|
|
45
|
+
// rides nowhere — context is the whole payload.
|
|
46
|
+
formatSessionStart({ context }) {
|
|
47
|
+
return `${JSON.stringify({ additional_context: context })}\n`;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** Sniff order: the more specific roots shape first — a cwd field is the common fallback. */
|
|
52
|
+
export const DIALECTS = Object.freeze([workspaceRootsDialect, cwdDialect]);
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// oathe — the harness base class. One base holds what every harness shares (detection inputs,
|
|
2
|
+
// exec seam, config-home convention); each subclass owns EVERYTHING harness-specific as a named
|
|
3
|
+
// member — identity, wiring, context files, project-dir env var, hook dialect, engine surface —
|
|
4
|
+
// so no `if (name === 'x')` exists anywhere outside src/harnesses/. The catalog
|
|
5
|
+
// (./catalog.mjs) is the one registry over the subclasses.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
|
|
11
|
+
import { globalFenceBody, writeFence } from '../fence.mjs';
|
|
12
|
+
|
|
13
|
+
export class HarnessOnboardError extends Error {
|
|
14
|
+
constructor(code, message, details = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'HarnessOnboardError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.details = details;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const defaultExec = {
|
|
23
|
+
run(cmd, args) {
|
|
24
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
25
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? '', stderr: r.stderr ?? '' };
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class Harness {
|
|
30
|
+
// ------------------------------------------------------------ identity facts
|
|
31
|
+
/** The CLI on PATH (null: no CLI — a GUI-only or hosted surface). */
|
|
32
|
+
static bin = null;
|
|
33
|
+
/** MCP clientInfo.name values that mean this harness (catalog.harnessForClient). */
|
|
34
|
+
static clientNames = Object.freeze([]);
|
|
35
|
+
/** Context files a project folder carries for this harness (the fence targets). */
|
|
36
|
+
static contextFiles = Object.freeze([]);
|
|
37
|
+
/** The env var this harness sets to name the project dir for hooks/servers, or null. */
|
|
38
|
+
static projectDirEnvVar = null;
|
|
39
|
+
/** Manual steps for a detect-only surface (wiring null), or null. */
|
|
40
|
+
static note = null;
|
|
41
|
+
/** The surfaces this wiring serves, as the init row states them (e.g. 'CLI/Desktop App'); null for detect-only. */
|
|
42
|
+
static covers = null;
|
|
43
|
+
|
|
44
|
+
// ------------------------------------------------------------ capabilities (frozen or null)
|
|
45
|
+
/** {needsCli} — the install writes this harness's config through its CLI (true) or our own files. */
|
|
46
|
+
static wiring = null;
|
|
47
|
+
/** {dialect} — the hook payload/reply dialect this harness speaks. */
|
|
48
|
+
static hooks = null;
|
|
49
|
+
/** {splash, bin} — `oathe <name>` launches it in the cage; splash: print the board to
|
|
50
|
+
* scrollback first; bin: the adapter's OWN interactive binary (never assumed from the
|
|
51
|
+
* harness name — the same primitive, each harness's unique adapter). */
|
|
52
|
+
static launch = null;
|
|
53
|
+
/** {store, newest, projector, ownsPath} — the session-record store the verifier and doctor read. */
|
|
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. */
|
|
59
|
+
static surfaces = null;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {{name?: string, home: string, envPath?: string, paths: object,
|
|
63
|
+
* exec?: {run: (cmd: string, args: string[]) => {status: number, stdout: string, stderr: string}}}} o
|
|
64
|
+
*/
|
|
65
|
+
constructor({ name, home, envPath = process.env.PATH ?? '', paths, exec = defaultExec }) {
|
|
66
|
+
this.name = name ?? this.constructor.harnessName;
|
|
67
|
+
this.home = home;
|
|
68
|
+
this.envPath = envPath;
|
|
69
|
+
this.paths = paths;
|
|
70
|
+
this.exec = exec;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The config-home convention (~/.<name>) — the ONE place it is spelled. */
|
|
74
|
+
static configHomeFor(home, name = this.harnessName) {
|
|
75
|
+
return path.join(home, `.${name}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* R-BOARD-SCOPE: is `dir` a SYNTHETIC workspace — a directory this harness stages for a
|
|
80
|
+
* session that has no real project folder (ChatGPT desktop's per-conversation cwd), so no
|
|
81
|
+
* board of its own? Base: no harness stages such directories. An adapter that does names
|
|
82
|
+
* them here; the resolver derives the fact once and every surface threads it.
|
|
83
|
+
* @param {{dir: string, home: string}} _o
|
|
84
|
+
*/
|
|
85
|
+
static isSyntheticWorkspaceDir(_o) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The harness's GLOBAL instructions files, relative to its config home, in the harness's
|
|
91
|
+
* OWN precedence order (the first that exists is the one it reads; the last is the default
|
|
92
|
+
* to create); [] = the harness has none. A harness whose sessions can open with no project
|
|
93
|
+
* folder (Codex: ChatGPT desktop) declares them, and `oathe init` puts the managed block
|
|
94
|
+
* where the harness will actually read it — the standing rule those sessions would
|
|
95
|
+
* otherwise never see, since a staging dir never carries a fence.
|
|
96
|
+
*/
|
|
97
|
+
static globalContextFiles = Object.freeze([]);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The harness-docs snapshot pages this adapter's facts derive from, as `<harness>/<slug>`
|
|
101
|
+
* keys of DOC_SOURCES (scripts/pull-harness-docs.mjs). The docs-drift lane re-pulls those
|
|
102
|
+
* pages and, when one changes, names THIS adapter as the thing to re-verify. Every adapter
|
|
103
|
+
* declares at least one; the contract suite refuses orphan pins in either direction.
|
|
104
|
+
*/
|
|
105
|
+
static docs = Object.freeze([]);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* How a fresh Linux runner gets this harness's REAL CLI — the install-contract lane installs
|
|
109
|
+
* it and proves `oathe init` against it: `{ npm, bin, versionArgs }` for an npm package,
|
|
110
|
+
* `{ 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).
|
|
112
|
+
*/
|
|
113
|
+
static install = null;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The harness's one-shot (headless) run — what the live-behaviour lane drives to make a
|
|
117
|
+
* REAL session fire our hooks and leave a transcript: `{ auth, command, extract }` — the env
|
|
118
|
+
* vars its non-interactive mode authenticates with (pinned from the docs snapshot), the
|
|
119
|
+
* argv for a prompt, and the extraction of the model's text from stdout; null for none.
|
|
120
|
+
*/
|
|
121
|
+
static headless = null;
|
|
122
|
+
|
|
123
|
+
/** `--output-format json` on Claude Code and Cursor wraps the text in {result}. */
|
|
124
|
+
static extractJsonResult(stdout) {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(stdout).result ?? '';
|
|
127
|
+
} catch {
|
|
128
|
+
throw new Error('--output-format json did not return JSON');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Install the global fence when the adapter declares where it is read — through THE fence
|
|
134
|
+
* writer, recorded as a plain fence row (owner 'global') so `oathe uninstall` strips it
|
|
135
|
+
* exactly like a folder fence. Idempotent.
|
|
136
|
+
* @returns {Array<{action: string, file: string, changed: boolean}>}
|
|
137
|
+
*/
|
|
138
|
+
installGlobalFence({ manifest, version }) {
|
|
139
|
+
const files = this.constructor.globalContextFiles;
|
|
140
|
+
if (files.length === 0) return [];
|
|
141
|
+
const candidates = files.map((file) => path.join(this.configHome, file));
|
|
142
|
+
const target = candidates.find((file) => fs.existsSync(file)) ?? candidates.at(-1);
|
|
143
|
+
const { changed } = writeFence({
|
|
144
|
+
manifest, file: target, version, body: globalFenceBody(), scope: 'user', harness: 'global',
|
|
145
|
+
});
|
|
146
|
+
return [{ action: 'global-fence', file: target, changed }];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The plugin version this harness has CACHED for itself, or null when it keeps no
|
|
151
|
+
* version-keyed copy. A fact the doctor prints beside the package version — the code that
|
|
152
|
+
* runs is always the `oathe` bin on PATH; the cache holds manifests only.
|
|
153
|
+
* @returns {string|null}
|
|
154
|
+
*/
|
|
155
|
+
installedPluginVersion() {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The harness's config home (e.g. ~/.claude). */
|
|
160
|
+
get configHome() {
|
|
161
|
+
return this.constructor.configHomeFor(this.home, this.name);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The CLI names that count as this harness's CLI on PATH (subclasses may accept aliases). */
|
|
165
|
+
static get cliBins() {
|
|
166
|
+
return this.bin ? [this.bin] : [];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The adapter's OWN rule for "installed", over structured presence. Base: CLI and config home. */
|
|
170
|
+
static installedFrom(presence) {
|
|
171
|
+
return presence.cli && presence.configHome !== null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
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
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* STRUCTURED detection: what is actually here — the app (GUI surfaces; null when the
|
|
182
|
+
* question does not apply), the CLI, the config home — and the adapter's own verdict on
|
|
183
|
+
* "installed" over those facts. Consumers pick the fact their capability needs (a headless
|
|
184
|
+
* 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}}
|
|
186
|
+
*/
|
|
187
|
+
detect() {
|
|
188
|
+
const cli = this.constructor.cliBins.some((bin) => this.binOnPath(bin));
|
|
189
|
+
const configHome = fs.existsSync(this.configHome) ? this.configHome : null;
|
|
190
|
+
const presence = { app: null, cli, configHome };
|
|
191
|
+
return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** What init will write for this harness, one line per file — from the SAME data onboard() writes. */
|
|
195
|
+
describe() {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @returns {Array<{name: string, installed: boolean, evidence: object}>} */
|
|
201
|
+
export function census(harnesses) {
|
|
202
|
+
return harnesses.map((h) => h.detect());
|
|
203
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// oathe — detect-only surfaces: places oathe can be USED but not WIRED by an installer. They are
|
|
2
|
+
// adapters like any other — same hierarchy, same structured detection, same docs pins — with
|
|
3
|
+
// `wiring: null` and a NOTE of manual steps instead of writes: detection plus honest
|
|
4
|
+
// instructions is the whole contract. (Cowork is a mode of the Claude Desktop app, running in a
|
|
5
|
+
// cloud sandbox; ChatGPT web has no local wiring at all — its desktop app rides the codex host.)
|
|
6
|
+
// Notes are dated: they describe the surfaces as pinned in .harness-docs.
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { Harness } from './harness.mjs';
|
|
12
|
+
|
|
13
|
+
export class CoworkSurface extends Harness {
|
|
14
|
+
static harnessName = 'cowork';
|
|
15
|
+
static displayName = 'Claude Cowork';
|
|
16
|
+
static clientNames = Object.freeze([]);
|
|
17
|
+
// The Claude Desktop app hosts Cowork (a mode beside Chat); its manual steps are dated
|
|
18
|
+
// against these pages, so the docs-drift lane names this surface when one changes.
|
|
19
|
+
static docs = Object.freeze([
|
|
20
|
+
'cowork/overview', 'cowork/projects', 'cowork/plugins', 'cowork/extensions', 'cowork/architecture',
|
|
21
|
+
'cowork/surfaces', 'cowork/use-plugins', 'claude-desktop/connect-local-servers',
|
|
22
|
+
]);
|
|
23
|
+
static note = [
|
|
24
|
+
'Claude desktop detected. Cowork sessions run in a cloud sandbox with a Linux-VM shell:',
|
|
25
|
+
'an attached folder\'s fence (AGENTS.md/CLAUDE.md) reaches them, but the local board —',
|
|
26
|
+
'MCP server, CLI, Postgres — does not (canary-confirmed 2026-08-28). Nothing to wire',
|
|
27
|
+
'today; a remote board surface is the tracked path.',
|
|
28
|
+
].join('\n');
|
|
29
|
+
|
|
30
|
+
constructor({ home, platform = process.platform, envPath = '', paths = null, exec } = {}) {
|
|
31
|
+
super({ name: 'cowork', home, envPath, paths, exec });
|
|
32
|
+
this.platform = platform;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static installedFrom(presence) {
|
|
36
|
+
return presence.app === true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
detect() {
|
|
40
|
+
const appSupport = path.join(this.home, 'Library/Application Support/Claude');
|
|
41
|
+
const app = this.platform === 'darwin' && (fs.existsSync('/Applications/Claude.app') || fs.existsSync(appSupport));
|
|
42
|
+
const presence = { app, cli: false, configHome: app ? appSupport : null };
|
|
43
|
+
return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class ChatGptWebSurface extends Harness {
|
|
48
|
+
static harnessName = 'chatgpt-web';
|
|
49
|
+
static displayName = 'ChatGPT web';
|
|
50
|
+
static clientNames = Object.freeze([]);
|
|
51
|
+
static docs = Object.freeze([]); // no local wiring, no page we depend on
|
|
52
|
+
static note = [
|
|
53
|
+
'ChatGPT web has no local wiring — remote MCP only. The ChatGPT desktop app shares the',
|
|
54
|
+
'codex host wiring above; from the web, use the oathe CLI verbs in a terminal against',
|
|
55
|
+
'the same board.',
|
|
56
|
+
].join('\n');
|
|
57
|
+
|
|
58
|
+
constructor({ home, platform = process.platform, envPath = '', paths = null, exec } = {}) {
|
|
59
|
+
super({ name: 'chatgpt-web', home, envPath, paths, exec });
|
|
60
|
+
this.platform = platform;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static installedFrom() {
|
|
64
|
+
return false; // nothing local marks ChatGPT web; listed for honesty, never auto-detected
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
detect() {
|
|
68
|
+
const presence = { app: null, cli: false, configHome: null };
|
|
69
|
+
return { name: this.name, presence, installed: false };
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/home.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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.
|
|
6
|
+
//
|
|
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.
|
|
11
|
+
|
|
12
|
+
import { VERIFICATION_PREFIX, verifiedTaskId } from './plans.mjs';
|
|
13
|
+
|
|
14
|
+
/** The workspace token of a homeless claim — a real ref is always `ws-<12hex>`, never this. */
|
|
15
|
+
export const HOMELESS = 'none';
|
|
16
|
+
|
|
17
|
+
const CONTRACT_VERSION = 'v1';
|
|
18
|
+
const GRAMMAR = /^workspace:([^;]+);contract:([^/]+)\/(.+)@v1$/;
|
|
19
|
+
|
|
20
|
+
export class HomeError extends Error {
|
|
21
|
+
constructor(code, message, details = {}) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'HomeError';
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.details = details;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A claim's contract reference: the workspace it is homed on (null = homeless) + the contract. */
|
|
30
|
+
export class ContractRef {
|
|
31
|
+
/** @param {{workspace: string|null, orgId: string, taskId: string}} o */
|
|
32
|
+
constructor({ workspace, orgId, taskId }) {
|
|
33
|
+
this.workspace = workspace ?? null;
|
|
34
|
+
this.orgId = orgId;
|
|
35
|
+
this.taskId = taskId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @param {string} text @returns {ContractRef} @throws {HomeError} OATHE_CONTRACT_REF_MALFORMED */
|
|
39
|
+
static parse(text) {
|
|
40
|
+
const match = GRAMMAR.exec(String(text));
|
|
41
|
+
if (!match) {
|
|
42
|
+
throw new HomeError('OATHE_CONTRACT_REF_MALFORMED',
|
|
43
|
+
`contract_ref '${text}' does not follow workspace:<ws|${HOMELESS}>;contract:<org>/<task>@${CONTRACT_VERSION}`,
|
|
44
|
+
{ text });
|
|
45
|
+
}
|
|
46
|
+
const [, workspace, orgId, taskId] = match;
|
|
47
|
+
return new ContractRef({ workspace: workspace === HOMELESS ? null : workspace, orgId, taskId });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get isHomeless() {
|
|
51
|
+
return this.workspace === null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
toString() {
|
|
55
|
+
return `workspace:${this.workspace ?? HOMELESS};contract:${this.orgId}/${this.taskId}@${CONTRACT_VERSION}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
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.
|
|
62
|
+
*/
|
|
63
|
+
export class HomeBoard {
|
|
64
|
+
/** @param {{client: {query: Function}, orgId: string}} o */
|
|
65
|
+
constructor({ client, orgId }) {
|
|
66
|
+
this.client = client;
|
|
67
|
+
this.orgId = orgId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The task whose ledger decides `taskId`'s home: itself, or its parent for a verification task. */
|
|
71
|
+
static anchorTaskId(taskId) {
|
|
72
|
+
return verifiedTaskId(taskId) ?? taskId;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The LIKE pattern every homeless claim matches — the sentinel, spelled once. */
|
|
76
|
+
static get homelessPattern() {
|
|
77
|
+
return `workspace:${HOMELESS};%`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
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.
|
|
84
|
+
*/
|
|
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;
|
|
106
|
+
}
|
|
107
|
+
}
|