@oathe/oathe 0.2.3 → 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.
- package/NOTICE +3 -4
- package/README.md +15 -45
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +397 -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 +154 -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
package/src/context.mjs
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
// a scratch database without monkey-patching anything.
|
|
4
4
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import os from 'node:os';
|
|
7
6
|
import path from 'node:path';
|
|
8
7
|
|
|
9
|
-
import { buildPaths } from './paths.mjs';
|
|
8
|
+
import { buildPaths, homeOf } from './paths.mjs';
|
|
10
9
|
import { OatheConfig } from './config.mjs';
|
|
11
10
|
import { InstallManifest } from './manifest.mjs';
|
|
12
|
-
import {
|
|
11
|
+
import { buildAll } from './harnesses/catalog.mjs';
|
|
13
12
|
import { Substrate } from './substrate.mjs';
|
|
14
13
|
|
|
15
14
|
export function packageVersion(paths) {
|
|
@@ -18,13 +17,10 @@ export function packageVersion(paths) {
|
|
|
18
17
|
|
|
19
18
|
export function buildContext({ env = process.env, exec, cwd = process.cwd() } = {}) {
|
|
20
19
|
const paths = buildPaths(env);
|
|
21
|
-
const home = env
|
|
20
|
+
const home = homeOf(env);
|
|
22
21
|
const config = new OatheConfig({ env, cwd });
|
|
23
22
|
const manifest = InstallManifest.load({ manifestPath: paths.manifestPath, backupsDir: paths.backupsDir });
|
|
24
|
-
const harnesses =
|
|
25
|
-
new ClaudeHarness({ home, envPath: env.PATH, paths, exec }),
|
|
26
|
-
new CodexHarness({ home, envPath: env.PATH, paths, exec }),
|
|
27
|
-
];
|
|
23
|
+
const harnesses = buildAll({ home, envPath: env.PATH, paths, exec }); // the ONE roster; consumers filter by capability
|
|
28
24
|
const substrate = new Substrate({ database: config.get('db'), paths, env, config });
|
|
29
25
|
const identity = {
|
|
30
26
|
orgId: config.get('org'),
|
package/src/doctor.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
|
|
8
|
-
import { buildContext } from './context.mjs';
|
|
8
|
+
import { buildContext, packageVersion } from './context.mjs';
|
|
9
9
|
import { FencedBlock, FENCE_STYLES, JsonEntries } from './blocks.mjs';
|
|
10
10
|
import { sha256Hex } from './manifest.mjs';
|
|
11
11
|
|
|
@@ -35,13 +35,95 @@ function verifyCliRow(row) {
|
|
|
35
35
|
return fs.readFileSync(row.file, 'utf8').includes(row.detail?.proof) ? 'ok' : 'removed';
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
function verifyJsonArrayRow(row) {
|
|
39
|
+
if (!fs.existsSync(row.file)) return 'file-missing';
|
|
40
|
+
let doc;
|
|
41
|
+
try { doc = JSON.parse(fs.readFileSync(row.file, 'utf8')); } catch { return 'user-edited'; }
|
|
42
|
+
const present = (entry) => {
|
|
43
|
+
let node = doc;
|
|
44
|
+
for (const key of entry.path) {
|
|
45
|
+
if (node === null || typeof node !== 'object' || !(key in node)) return false;
|
|
46
|
+
node = node[key];
|
|
47
|
+
}
|
|
48
|
+
return Array.isArray(node) && node.some((el) => el?.command === entry.match);
|
|
49
|
+
};
|
|
50
|
+
return (row.detail?.entries ?? []).every(present) ? 'ok' : 'removed';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The trace-layer refusals that mean "this runtime cannot read the store" — not a format change. */
|
|
54
|
+
const RUNTIME_BOUND_CODES = new Set(['TRACE_CODEX_SQLITE_UNSUPPORTED']);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The trace-contract status for a failed projection: a runtime bound (node:sqlite missing on
|
|
58
|
+
* Node < 22.5 — the store never got to read the record) is RUNTIME; anything else is format
|
|
59
|
+
* DRIFT. Both stay loud; the drift lanes need them told apart.
|
|
60
|
+
*/
|
|
61
|
+
export function traceStatusOf(error) {
|
|
62
|
+
return RUNTIME_BOUND_CODES.has(error?.code) ? 'RUNTIME' : 'DRIFT';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A LaunchAgent is a whole-file write: present and byte-identical to what init recorded, or
|
|
66
|
+
// user-edited; gone is gone. (The notch ships with the package — every darwin manifest
|
|
67
|
+
// carries this row now.)
|
|
68
|
+
function verifyLaunchAgentRow(row) {
|
|
69
|
+
if (!fs.existsSync(row.file)) return 'file-missing';
|
|
70
|
+
return sha256Hex(fs.readFileSync(row.file, 'utf8')) === row.sha256 ? 'ok' : 'user-edited';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The materialized notch copy: the row's detail names the binary inside the key dir; ok
|
|
74
|
+
// means those exact bytes. A replaced binary under the same key is a drift the same way an
|
|
75
|
+
// edited plist is — materialization promises immutability per key.
|
|
76
|
+
function verifyNotchAppRow(row) {
|
|
77
|
+
const binary = row.detail?.binary;
|
|
78
|
+
if (!binary || !fs.existsSync(binary)) return 'file-missing';
|
|
79
|
+
return sha256Hex(fs.readFileSync(binary)) === row.sha256 ? 'ok' : 'user-edited';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const VERIFIERS = {
|
|
83
|
+
'json-path': verifyJsonRow, fence: verifyFenceRow, 'cli-managed': verifyCliRow, 'json-array': verifyJsonArrayRow,
|
|
84
|
+
'launch-agent': verifyLaunchAgentRow, 'notch-app': verifyNotchAppRow,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The per-surface resolution report (`oathe doctor --surface`): what the ladder received,
|
|
89
|
+
* which rung won, and whether the workspace is registered — no substrate contact, so it
|
|
90
|
+
* answers even on a machine whose database is down. This is the empirical probe the unknown
|
|
91
|
+
* surfaces (Cowork, ChatGPT desktop) get pointed at.
|
|
92
|
+
* @returns {Promise<{resolved: boolean, resolution: object|null, refusal: string|null,
|
|
93
|
+
* registered: boolean|null, env_slice: object}>}
|
|
94
|
+
*/
|
|
95
|
+
export async function runSurfaceReport({ env = process.env, cwd = () => process.cwd() } = {}) {
|
|
96
|
+
const { WorkspaceResolver } = await import('./workspace-resolver.mjs');
|
|
97
|
+
const { projectDirEnvVars } = await import('./harnesses/catalog.mjs');
|
|
98
|
+
const { WorkspaceRegistry } = await import('./registry.mjs');
|
|
99
|
+
const { buildPaths } = await import('./paths.mjs');
|
|
100
|
+
const paths = buildPaths(env);
|
|
101
|
+
const envSlice = Object.fromEntries(
|
|
102
|
+
['OATHE_WORKSPACE_DIR', ...projectDirEnvVars().map(([, envVar]) => envVar), 'OATHE_LAUNCHED_HARNESS']
|
|
103
|
+
.map((name) => [name, env[name] ?? null]));
|
|
104
|
+
try {
|
|
105
|
+
const resolution = await new WorkspaceResolver({ env, cwd }).resolve();
|
|
106
|
+
let registered = null;
|
|
107
|
+
try {
|
|
108
|
+
registered = new WorkspaceRegistry({ registryPath: paths.registryPath }).get(resolution.ref) !== null;
|
|
109
|
+
} catch { registered = null; }
|
|
110
|
+
return { resolved: true, resolution, refusal: null, registered, env_slice: envSlice };
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return { resolved: false, resolution: null, refusal: String(e?.message || e), registered: null, env_slice: envSlice };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
39
115
|
|
|
40
116
|
/** @returns {Promise<{rows: object[], substrate: object, plugin: {resolves: boolean, detail: string|null}}>} */
|
|
41
117
|
export async function runDoctor({ env = process.env } = {}) {
|
|
42
118
|
const ctx = buildContext({ env });
|
|
43
|
-
const { manifest, substrate, paths } = ctx;
|
|
119
|
+
const { manifest, substrate, paths, harnesses } = ctx;
|
|
44
120
|
try {
|
|
121
|
+
// Version FACTS, not a check: the code that runs is the bin on PATH (this package); what
|
|
122
|
+
// each harness has cached is its own manifests-only copy. Upgrade = reinstall + `oathe init`.
|
|
123
|
+
const version = {
|
|
124
|
+
package: packageVersion(paths),
|
|
125
|
+
plugin: Object.fromEntries(harnesses.filter((h) => h.constructor.wiring !== null).map((h) => [h.name, h.installedPluginVersion()])),
|
|
126
|
+
};
|
|
45
127
|
const rows = manifest.rows.map((row) => ({
|
|
46
128
|
harness: row.harness,
|
|
47
129
|
file: row.file,
|
|
@@ -50,29 +132,28 @@ export async function runDoctor({ env = process.env } = {}) {
|
|
|
50
132
|
status: (VERIFIERS[row.kind] ?? (() => 'unknown-kind'))(row),
|
|
51
133
|
}));
|
|
52
134
|
// The trace-contract monitor: both vendors disclaim transcript-schema stability, so the
|
|
53
|
-
// doctor validates the NEWEST live record in each store against docs/traces.md and
|
|
135
|
+
// doctor validates the NEWEST live record in each engine's store against docs/traces.md and
|
|
54
136
|
// reports DRIFT loudly. An absent store is a distinct, visible status — never a silent skip.
|
|
55
|
-
|
|
56
|
-
const {
|
|
137
|
+
// Store, newest-record lookup, and projector are each engine adapter's own facts.
|
|
138
|
+
const { byName, traceStores } = await import('./harnesses/catalog.mjs');
|
|
139
|
+
const { AtifValidator } = await import('./atif.mjs');
|
|
57
140
|
const home = ctx.home;
|
|
58
141
|
const traces = {};
|
|
59
|
-
for (const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const newest = name === 'claude' ? store.newestTranscript() : store.newestRollout();
|
|
142
|
+
for (const name of traceStores()) {
|
|
143
|
+
const { traces: capability } = byName(name);
|
|
144
|
+
const store = await capability.store({ home });
|
|
145
|
+
const newest = capability.newest(store);
|
|
64
146
|
if (!newest) {
|
|
65
147
|
traces[name] = { status: 'store-absent', newest: null, detail: 'no session records found' };
|
|
66
148
|
continue;
|
|
67
149
|
}
|
|
68
150
|
// Full projection + validation — the deepest read the verifier itself performs.
|
|
69
151
|
try {
|
|
70
|
-
const projector =
|
|
71
|
-
? new ClaudeAtifProjector({ store }) : new CodexAtifProjector({ store });
|
|
152
|
+
const projector = await capability.projector({ store });
|
|
72
153
|
new AtifValidator().assert(projector.project(newest), { file: newest });
|
|
73
154
|
traces[name] = { status: 'ok', newest, detail: null };
|
|
74
155
|
} catch (e) {
|
|
75
|
-
traces[name] = { status:
|
|
156
|
+
traces[name] = { status: traceStatusOf(e), newest, detail: String(e?.message || e) };
|
|
76
157
|
}
|
|
77
158
|
}
|
|
78
159
|
|
|
@@ -101,7 +182,7 @@ export async function runDoctor({ env = process.env } = {}) {
|
|
|
101
182
|
capabilities: null, error: String(e?.message || e), probe: null };
|
|
102
183
|
}
|
|
103
184
|
|
|
104
|
-
return { rows, substrate: await substrate.status(), plugin, traces, runtime };
|
|
185
|
+
return { version, rows, substrate: await substrate.status(), plugin, traces, runtime };
|
|
105
186
|
} finally {
|
|
106
187
|
await substrate.close();
|
|
107
188
|
}
|
package/src/fence.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// oathe — the managed fence, owned once: the two bodies (a folder's, and the GLOBAL one an
|
|
2
|
+
// adapter's instructions file carries for sessions that open with no folder at all) and THE
|
|
3
|
+
// write that puts a block into a file — backup once, apply, manifest row. activateWorkspace
|
|
4
|
+
// (folder fences) and Harness.installGlobalFence (`oathe init`) both write through here, so
|
|
5
|
+
// the bytes on disk and the manifest rows that make them reversible can never drift apart.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
|
|
9
|
+
import { FencedBlock, FENCE_STYLES } from './blocks.mjs';
|
|
10
|
+
import { sha256Hex } from './manifest.mjs';
|
|
11
|
+
|
|
12
|
+
/** The rule, in one sentence, everywhere it is spoken (fences, the board render). */
|
|
13
|
+
export const SPEECH_ACT_RULE = 'Claims are speech acts: claim before you build, record progress as statements, '
|
|
14
|
+
+ 'yield what you cannot finish — via the `oathe_*` MCP tools.';
|
|
15
|
+
|
|
16
|
+
/** The folder fence: an H2 inside HTML-comment fences (the `>>> <<<` shell-profile convention,
|
|
17
|
+
* in a form Markdown renders as nothing). Surface-neutral by design: hooks may not fire on every harness, so the fence promises
|
|
18
|
+
* only what every surface delivers. (Byte-stable: every activated folder carries it.) */
|
|
19
|
+
export function fenceBody(workspace) {
|
|
20
|
+
return [
|
|
21
|
+
'## Oathe',
|
|
22
|
+
'',
|
|
23
|
+
`This folder has an Oathe board (workspace \`${workspace}\`). Claims are speech acts:`,
|
|
24
|
+
'claim before you build, record progress as statements, yield what you cannot finish —',
|
|
25
|
+
'via the `oathe_*` MCP tools. Where your session opens on this folder, the board loads',
|
|
26
|
+
'with it; `continue <task>` picks work back up.',
|
|
27
|
+
].join('\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The GLOBAL fence (R-BOARD-SCOPE follow-up): an adapter's global instructions file is read
|
|
32
|
+
* by every one of its sessions — including those that open on a staging directory with no
|
|
33
|
+
* project folder (ChatGPT desktop), where no folder fence can exist. It must be true in a
|
|
34
|
+
* folder session too, so it describes both cases and names no workspace.
|
|
35
|
+
*/
|
|
36
|
+
export function globalFenceBody() {
|
|
37
|
+
return [
|
|
38
|
+
'## Oathe',
|
|
39
|
+
'',
|
|
40
|
+
wrap(`Every session on this machine has an Oathe board. ${SPEECH_ACT_RULE} Where a session opens `
|
|
41
|
+
+ 'on a project folder, that folder\'s board loads with it. A session with no project folder '
|
|
42
|
+
+ '(ChatGPT desktop runs from a staging directory) sees the machine-wide board, and a task '
|
|
43
|
+
+ 'claimed there is homeless until a real folder claims it — which adopts it onto that '
|
|
44
|
+
+ 'folder\'s board. `continue <task>` picks work back up.'),
|
|
45
|
+
].join('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Word-wrap one paragraph to `width` columns — the fence files are read by people too. */
|
|
49
|
+
function wrap(paragraph, width = 90) {
|
|
50
|
+
const lines = [];
|
|
51
|
+
let line = '';
|
|
52
|
+
for (const word of paragraph.split(' ')) {
|
|
53
|
+
if (line !== '' && `${line} ${word}`.length > width) { lines.push(line); line = word; }
|
|
54
|
+
else line = line === '' ? word : `${line} ${word}`;
|
|
55
|
+
}
|
|
56
|
+
if (line !== '') lines.push(line);
|
|
57
|
+
return lines.join('\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* THE fence write: put the managed block into `file` and record it. Idempotent — an unchanged
|
|
62
|
+
* block writes nothing; the manifest row is keyed so a re-run replaces its own.
|
|
63
|
+
* @param {{manifest: object, file: string, version: string, body: string, scope: 'project'|'user',
|
|
64
|
+
* harness?: string}} o harness — the row's owner label ('project' for folder fences,
|
|
65
|
+
* 'global' for an adapter's instructions file; never an adapter name, so an adapter's
|
|
66
|
+
* offboard cannot drop the row without stripping the block)
|
|
67
|
+
* @returns {{file: string, changed: boolean}}
|
|
68
|
+
*/
|
|
69
|
+
export function writeFence({ manifest, file, version, body, scope, harness = 'project' }) {
|
|
70
|
+
const block = new FencedBlock({ style: FENCE_STYLES.html });
|
|
71
|
+
manifest.backupOnce(file);
|
|
72
|
+
const before = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
73
|
+
const { content, changed } = block.apply(before, { version, body });
|
|
74
|
+
if (changed) fs.writeFileSync(file, content);
|
|
75
|
+
manifest.upsert({
|
|
76
|
+
harness,
|
|
77
|
+
file,
|
|
78
|
+
kind: 'fence',
|
|
79
|
+
scope,
|
|
80
|
+
detail: { style: 'html' },
|
|
81
|
+
blockVersion: version,
|
|
82
|
+
sha256: sha256Hex(block.read(content).blockText),
|
|
83
|
+
});
|
|
84
|
+
return { file, changed };
|
|
85
|
+
}
|
package/src/fslock.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// oathe — shared-file concurrency: atomic JSON writes plus a bounded advisory lock. Many
|
|
2
|
+
// sessions' hooks and MCP servers write ~/.oathe files at once; a reader must never see a torn
|
|
3
|
+
// file, and a hook must never deadlock a session on somebody else's lock. Rename is the only
|
|
4
|
+
// publish; the lock is a lockdir spin (mkdir is atomic on POSIX) that gives up after the bound
|
|
5
|
+
// and proceeds — every caller's mutation is idempotent by contract, so a lost race self-heals.
|
|
6
|
+
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
/** Write `doc` as pretty JSON + trailing newline via temp-then-rename in the same directory. */
|
|
12
|
+
export function atomicWriteJson(file, doc) {
|
|
13
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
14
|
+
const tmp = path.join(path.dirname(file), `.${path.basename(file)}.tmp-${process.pid}-${crypto.randomBytes(4).toString('hex')}`);
|
|
15
|
+
fs.writeFileSync(tmp, `${JSON.stringify(doc, null, 2)}\n`);
|
|
16
|
+
fs.renameSync(tmp, file);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Run `fn` under an advisory lockdir beside `file`. A lockdir older than `staleMs` is broken
|
|
21
|
+
* (its holder died); a live foreign lock is waited on for at most `timeoutMs`, then `fn` runs
|
|
22
|
+
* lock-free rather than blocking the caller.
|
|
23
|
+
*/
|
|
24
|
+
export async function withFileLock(file, fn, { timeoutMs = 2000, staleMs = 10_000 } = {}) {
|
|
25
|
+
const lockDir = `${file}.lock`;
|
|
26
|
+
fs.mkdirSync(path.dirname(lockDir), { recursive: true });
|
|
27
|
+
const deadline = Date.now() + timeoutMs;
|
|
28
|
+
let acquired = false;
|
|
29
|
+
for (;;) {
|
|
30
|
+
try {
|
|
31
|
+
fs.mkdirSync(lockDir);
|
|
32
|
+
acquired = true;
|
|
33
|
+
break;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e.code !== 'EEXIST') throw e;
|
|
36
|
+
try {
|
|
37
|
+
if (Date.now() - fs.statSync(lockDir).mtimeMs > staleMs) {
|
|
38
|
+
fs.rmdirSync(lockDir);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
} catch { /* the holder released between stat and rmdir — retry */ }
|
|
42
|
+
if (Date.now() >= deadline) break;
|
|
43
|
+
await new Promise((resolve) => { setTimeout(resolve, 25); });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return await fn();
|
|
48
|
+
} finally {
|
|
49
|
+
if (acquired) fs.rmSync(lockDir, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// oathe — the harness catalog: the ONE registry over every adapter, and the sweeps that answer
|
|
2
|
+
// every "which harness can…?" BY CAPABILITY. Nothing else in the tree keys on a harness name or
|
|
3
|
+
// a flag: the verifier asks verifierCapable(), the doctor asks traceStores(), the launcher asks
|
|
4
|
+
// launchable(), init asks wireable() and verifiers(census). Adding a harness means adding an
|
|
5
|
+
// adapter file and one entry HERE — the contract suite's golden capability table is the spec.
|
|
6
|
+
|
|
7
|
+
import { Harness, HarnessOnboardError, census } from './harness.mjs';
|
|
8
|
+
import { DIALECTS } from './dialects.mjs';
|
|
9
|
+
import { TraceContractError } from '../traces.mjs';
|
|
10
|
+
import { ClaudeHarness } from './claude.mjs';
|
|
11
|
+
import { CodexHarness } from './codex.mjs';
|
|
12
|
+
import { CursorHarness } from './cursor.mjs';
|
|
13
|
+
import { ChatGptWebSurface, CoworkSurface } from './surfaces.mjs';
|
|
14
|
+
|
|
15
|
+
export { Harness, HarnessOnboardError, census, ClaudeHarness, CodexHarness, CursorHarness, CoworkSurface, ChatGptWebSurface };
|
|
16
|
+
|
|
17
|
+
/** Every surface oathe knows — wired harnesses and detect-only surfaces, one hierarchy. */
|
|
18
|
+
export const HARNESS_CLASSES = Object.freeze([ClaudeHarness, CodexHarness, CursorHarness, CoworkSurface, ChatGptWebSurface]);
|
|
19
|
+
|
|
20
|
+
/** @returns {typeof Harness} */
|
|
21
|
+
export function byName(name) {
|
|
22
|
+
const found = HARNESS_CLASSES.find((C) => C.harnessName === name);
|
|
23
|
+
if (!found) {
|
|
24
|
+
throw new Error(`no harness '${name}' — known harnesses: ${HARNESS_CLASSES.map((C) => C.harnessName).join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
return found;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const names = (predicate) => HARNESS_CLASSES.filter(predicate).map((C) => C.harnessName);
|
|
30
|
+
|
|
31
|
+
/** The harnesses an installer can wire (the wiring capability). */
|
|
32
|
+
export function wireable() {
|
|
33
|
+
return names((C) => C.wiring !== null);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The harnesses `oathe <name>` can launch inside the cage (the launch capability). */
|
|
37
|
+
export function launchable() {
|
|
38
|
+
return names((C) => C.launch !== null);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The harnesses that can judge completed work — every one with a headless run. Validates config. */
|
|
42
|
+
export function verifierCapable() {
|
|
43
|
+
return names((C) => C.headless !== null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The verifier candidates on THIS machine: headless-capable AND the CLI is actually present. */
|
|
47
|
+
export function verifiers(seen) {
|
|
48
|
+
const present = new Map(seen.map((d) => [d.name, d]));
|
|
49
|
+
return verifierCapable().filter((name) => present.get(name)?.presence?.cli === true);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The harnesses with a session-record store the verifier and doctor read (the traces capability). */
|
|
53
|
+
export function traceStores() {
|
|
54
|
+
return names((C) => C.traces !== null);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The harnesses with a REAL CLI the install-contract lane can install and prove against. */
|
|
58
|
+
export function installable() {
|
|
59
|
+
return names((C) => C.install !== null);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The harnesses with a headless run the live-behaviour lane can drive. */
|
|
63
|
+
export function liveTestable() {
|
|
64
|
+
return names((C) => C.headless !== null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The golden capability table — harness → which capabilities it possesses. The contract suite
|
|
69
|
+
* pins it row for row: a supported harness has every touchpoint mapped, and a row change is a
|
|
70
|
+
* reviewed change (PLAN.md R-HARNESS-TOUCHPOINTS).
|
|
71
|
+
*/
|
|
72
|
+
export function capabilityTable() {
|
|
73
|
+
return Object.fromEntries(HARNESS_CLASSES.map((C) => [C.harnessName, {
|
|
74
|
+
wiring: C.wiring !== null,
|
|
75
|
+
hooks: C.hooks !== null,
|
|
76
|
+
launch: C.launch !== null,
|
|
77
|
+
headless: C.headless !== null,
|
|
78
|
+
traces: C.traces !== null,
|
|
79
|
+
surfaces: C.surfaces !== null,
|
|
80
|
+
contextFiles: C.contextFiles.length > 0,
|
|
81
|
+
globalContextFiles: C.globalContextFiles.length > 0,
|
|
82
|
+
synthetic: C.isSyntheticWorkspaceDir !== Harness.isSyntheticWorkspaceDir,
|
|
83
|
+
install: C.install !== null,
|
|
84
|
+
docs: C.docs.length > 0,
|
|
85
|
+
}]));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** [name, envVar] pairs for every adapter that documents a project-dir env var. */
|
|
89
|
+
export function projectDirEnvVars() {
|
|
90
|
+
return HARNESS_CLASSES.filter((C) => C.projectDirEnvVar !== null)
|
|
91
|
+
.map((C) => [C.harnessName, C.projectDirEnvVar]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** R-BOARD-SCOPE: does ANY adapter stage `dir` as a synthetic workspace? Asked once, by the resolver. */
|
|
95
|
+
export function isSyntheticWorkspace({ dir, home }) {
|
|
96
|
+
return HARNESS_CLASSES.some((C) => C.isSyntheticWorkspaceDir({ dir, home }));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Drift: the adapters and surfaces whose facts derive from the snapshot page `key`. */
|
|
100
|
+
export function docsDependents(key) {
|
|
101
|
+
return names((C) => C.docs.includes(key));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The hook dialect whose sniff accepts `input`, or null — shapes, not harness identity. */
|
|
105
|
+
export function dialectFor(input) {
|
|
106
|
+
return DIALECTS.find((d) => d.matches(input)) ?? null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The harness an MCP client is, from its declared clientNames — or null. */
|
|
110
|
+
export function harnessForClient(clientName) {
|
|
111
|
+
const name = String(clientName ?? '').toLowerCase();
|
|
112
|
+
if (name === '') return null;
|
|
113
|
+
return HARNESS_CLASSES.find((C) => C.clientNames.some((c) => name.includes(c)))?.harnessName ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Which store owns a session record — each store's own predicate; null when nobody's. */
|
|
117
|
+
export function ownerOfTracePath(file) {
|
|
118
|
+
return HARNESS_CLASSES.find((C) => C.traces?.ownsPath(file))?.harnessName ?? null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The NEAREST adapter-owned process in an ancestry chain — the harness the chain speaks
|
|
123
|
+
* for. Harnesses interpose helpers between themselves and their children (cursor-agent
|
|
124
|
+
* runs hooks through a /bin/zsh; MCP servers are node), so ownership is never decided by
|
|
125
|
+
* the chain's head alone. -1 when nobody in the chain is a harness. ONE implementation:
|
|
126
|
+
* surface naming, speaker resolution, and hook registration all ask here.
|
|
127
|
+
*/
|
|
128
|
+
export function ownedAncestorIndex(ancestry) {
|
|
129
|
+
return ancestry.findIndex((a) => HARNESS_CLASSES.some((C) => C.surfaces?.ownsExec(a?.exec ?? '')));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* NAME the surface a registered session speaks from — facts in, name out, at read time
|
|
134
|
+
* (the sessions file stores facts only, so naming evolves without rewriting history).
|
|
135
|
+
* Ownership: the trace store that owns the transcript wins (environment-independent);
|
|
136
|
+
* else the adapter owning the NEAREST harness process in the chain. Nobody's process is
|
|
137
|
+
* null — never a guess.
|
|
138
|
+
*/
|
|
139
|
+
export function surfaceForSession({ ancestry = [], app = null, transcriptPath = null }) {
|
|
140
|
+
const idx = ownedAncestorIndex(ancestry);
|
|
141
|
+
const exec = (idx === -1 ? ancestry[0]?.exec : ancestry[idx].exec) ?? '';
|
|
142
|
+
const owner = ownerOfTracePath(transcriptPath ?? '')
|
|
143
|
+
?? (idx === -1 ? null : HARNESS_CLASSES.find((C) => C.surfaces?.ownsExec(exec))?.harnessName) ?? null;
|
|
144
|
+
if (owner === null) return null;
|
|
145
|
+
const { surfaces } = byName(owner);
|
|
146
|
+
return surfaces === null ? owner : surfaces.name({ exec, appBundle: app?.bundle ?? null });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The ATIF projector for a session record, from the store that owns it — or a typed refusal:
|
|
151
|
+
* a file no store owns is not evidence, never "probably Claude".
|
|
152
|
+
*/
|
|
153
|
+
export async function projectorFor(file, { home } = {}) {
|
|
154
|
+
const owner = ownerOfTracePath(file);
|
|
155
|
+
if (owner === null) {
|
|
156
|
+
throw new TraceContractError('TRACE_OWNER_UNKNOWN',
|
|
157
|
+
`no trace store owns '${file}' — known stores: ${traceStores().join(', ')}`, { file });
|
|
158
|
+
}
|
|
159
|
+
const { traces } = byName(owner);
|
|
160
|
+
const store = await traces.store({ home });
|
|
161
|
+
return traces.projector({ store });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Instantiate every adapter whose wiring exists — the init/uninstall roster. */
|
|
165
|
+
export function buildWireable({ home, envPath, paths, exec }) {
|
|
166
|
+
return HARNESS_CLASSES.filter((C) => C.wiring !== null).map((C) => new C({ home, envPath, paths, exec }));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Instantiate every adapter — detection sweeps (the picker census) see them all. */
|
|
170
|
+
export function buildAll({ home, envPath, paths, exec }) {
|
|
171
|
+
return HARNESS_CLASSES.map((C) => new C({ home, envPath, paths, exec }));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The detect-only surfaces as the picker prints them: detected + the manual steps. */
|
|
175
|
+
export function detectOnlySurfaces({ home, platform = process.platform }) {
|
|
176
|
+
return HARNESS_CLASSES.filter((C) => C.wiring === null).map((C) => {
|
|
177
|
+
const surface = new C({ home, platform });
|
|
178
|
+
return { name: C.harnessName, displayName: C.displayName, detected: surface.detect().installed, steps: C.note };
|
|
179
|
+
});
|
|
180
|
+
}
|