@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/launch.mjs
CHANGED
|
@@ -10,13 +10,9 @@ import fs from 'node:fs';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
|
|
12
12
|
import { buildContext } from './context.mjs';
|
|
13
|
-
import {
|
|
14
|
-
import { census } from './harness.mjs';
|
|
15
|
-
import { FencedBlock, FENCE_STYLES } from './blocks.mjs';
|
|
16
|
-
import { sha256Hex } from './manifest.mjs';
|
|
17
|
-
import { workspaceRef } from './workspace.mjs';
|
|
13
|
+
import { byName } from './harnesses/catalog.mjs';
|
|
18
14
|
import { SessionHost } from './session-host.mjs';
|
|
19
|
-
import { launchSessionEnv
|
|
15
|
+
import { launchSessionEnv } from './launch-env.mjs';
|
|
20
16
|
|
|
21
17
|
export class LaunchError extends Error {
|
|
22
18
|
constructor(code, message, details = {}) {
|
|
@@ -27,59 +23,27 @@ export class LaunchError extends Error {
|
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
/** The managed section: an H2 inside HTML-comment fences — the estate-convention hybrid. */
|
|
31
|
-
function fenceBody(workspace) {
|
|
32
|
-
return [
|
|
33
|
-
'## Oathe',
|
|
34
|
-
'',
|
|
35
|
-
`This folder has an Oathe board (workspace \`${workspace}\`). Claims are speech acts:`,
|
|
36
|
-
'claim before you build, record progress as statements, yield what you cannot finish —',
|
|
37
|
-
'via the `oathe_*` MCP tools. The board renders at SessionStart; `continue <task>`',
|
|
38
|
-
'picks work back up.',
|
|
39
|
-
].join('\n');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
26
|
/**
|
|
43
|
-
* Ensure the cwd's
|
|
44
|
-
*
|
|
45
|
-
* when absent — recorded as a project-scope manifest row either way.
|
|
27
|
+
* Ensure the cwd's context files carry the managed Oathe section (through the ONE activation
|
|
28
|
+
* writer — src/activation.mjs), and that the global install exists.
|
|
46
29
|
*/
|
|
47
|
-
export async function preflight({ env = process.env, cwd = process.cwd(), exec, harness
|
|
30
|
+
export async function preflight({ env = process.env, cwd = process.cwd(), exec, harness } = {}) {
|
|
31
|
+
byName(harness); // the harness to launch is named by the caller — unknown or missing is the catalog's typed refusal
|
|
48
32
|
const ctx = buildContext({ env, exec });
|
|
49
|
-
const { manifest,
|
|
33
|
+
const { manifest, version, substrate, paths, config } = ctx;
|
|
50
34
|
await substrate.close(); // preflight itself never talks to the database
|
|
51
35
|
if (!manifest.rows.some((r) => r.harness === harness)) {
|
|
52
36
|
throw new LaunchError('OATHE_NOT_INSTALLED',
|
|
53
37
|
`the ${harness} install is missing (no ${harness} rows in the install manifest) — `
|
|
54
38
|
+ 'run `oathe init` with that harness present first');
|
|
55
39
|
}
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
const actions = [];
|
|
64
|
-
for (const target of targets) {
|
|
65
|
-
const file = path.join(cwd, target.file);
|
|
66
|
-
manifest.backupOnce(file);
|
|
67
|
-
const before = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
68
|
-
const { content, changed } = block.apply(before, { version, body: fenceBody(workspace) });
|
|
69
|
-
if (changed) fs.writeFileSync(file, content);
|
|
70
|
-
manifest.upsert({
|
|
71
|
-
harness: 'project',
|
|
72
|
-
file,
|
|
73
|
-
kind: 'fence',
|
|
74
|
-
scope: 'project',
|
|
75
|
-
detail: { style: 'html' },
|
|
76
|
-
blockVersion: version,
|
|
77
|
-
sha256: sha256Hex(block.read(content).blockText),
|
|
78
|
-
});
|
|
79
|
-
actions.push({ action: target.action, file, changed });
|
|
80
|
-
}
|
|
81
|
-
manifest.save();
|
|
82
|
-
return { workspace, actions };
|
|
40
|
+
const { activateWorkspace } = await import('./activation.mjs');
|
|
41
|
+
const { WorkspaceRegistry } = await import('./registry.mjs');
|
|
42
|
+
const registry = new WorkspaceRegistry({ registryPath: paths.registryPath });
|
|
43
|
+
const { workspace, synthetic, actions } = await activateWorkspace({
|
|
44
|
+
cwd, env, manifest, registry, config, version, source: 'launcher:preflight', harness,
|
|
45
|
+
});
|
|
46
|
+
return { workspace, synthetic, actions };
|
|
83
47
|
}
|
|
84
48
|
|
|
85
49
|
/** POSIX-name keys only — what the cage can declare; the rest cannot ride an `env -i` word. */
|
|
@@ -118,7 +82,7 @@ function curatedEnv(env, { hermetic, extra }) {
|
|
|
118
82
|
|
|
119
83
|
/**
|
|
120
84
|
* ONE launcher, both harnesses — same cage, same session host, same pre-flight; only the
|
|
121
|
-
* binary differs. (
|
|
85
|
+
* binary differs. (An earlier plan deferred `oathe codex` on the premise that Codex lacked
|
|
122
86
|
* Stop/PreCompact; the docs pass proved both exist, so the premise — and the wait — died.)
|
|
123
87
|
*
|
|
124
88
|
* @param {{harness: 'claude'|'codex', env?: object, cwd?: string, args?: string[],
|
|
@@ -129,22 +93,25 @@ export async function runHarness({
|
|
|
129
93
|
harness, env = process.env, cwd = process.cwd(), args = [], hermetic = false, exec,
|
|
130
94
|
observeIntervalMs = 60_000, out = process.stdout, stdin = process.stdin, pauseMs = 3000,
|
|
131
95
|
} = {}) {
|
|
132
|
-
const { workspace } = await preflight({ env, cwd, exec, harness });
|
|
96
|
+
const { workspace, synthetic } = await preflight({ env, cwd, exec, harness });
|
|
133
97
|
const ctx = buildContext({ env, exec, cwd });
|
|
134
98
|
const { paths, substrate, identity, config } = ctx;
|
|
135
99
|
|
|
136
100
|
// First launch in a folder: the verifier is CHOSEN, on the record, before any claim binds it.
|
|
137
101
|
await ensureVerifierChoice({ config, harness, stdin, out });
|
|
138
102
|
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
if (harness === 'codex') {
|
|
103
|
+
// The splash is the adapter's own quirk (codex buries hook output in its ctrl+T transcript
|
|
104
|
+
// overlay, unrendered; Claude Code shows the systemMessage banner inside its own TUI).
|
|
105
|
+
if (byName(harness).launch?.splash) {
|
|
143
106
|
let openWork = false;
|
|
144
107
|
try {
|
|
145
|
-
const { renderBoard, renderSplash } = await
|
|
146
|
-
|
|
147
|
-
|
|
108
|
+
const [{ renderBoard, renderSplash }, { Pager }, { WorkspaceRegistry }] = await Promise.all([
|
|
109
|
+
import('./board-render.mjs'), import('./pager.mjs'), import('./registry.mjs'),
|
|
110
|
+
]);
|
|
111
|
+
const registry = new WorkspaceRegistry({ registryPath: paths.registryPath });
|
|
112
|
+
const breaches = await new Pager({ client: substrate, identity, config, registry }).breaches();
|
|
113
|
+
const seen = await renderBoard({ client: substrate, identity, workspace, config, synthetic, breaches });
|
|
114
|
+
out.write(renderSplash({ message: seen.message, sections: seen.sections, workspace: seen.lens, breaches }));
|
|
148
115
|
openWork = Object.values(seen.sections).some((rows) => rows.length > 0);
|
|
149
116
|
} catch (e) {
|
|
150
117
|
out.write(`Oathe board unavailable (${String(e?.message || e).slice(0, 120)})\n`);
|
|
@@ -157,14 +124,10 @@ export async function runHarness({
|
|
|
157
124
|
|
|
158
125
|
const unit = `oathe-${Date.now().toString(36)}-${process.pid}`;
|
|
159
126
|
const extra = launchSessionEnv({ config, identity, cwd, harness });
|
|
160
|
-
// The env block above dies at Codex's MCP spawn boundary; the marker file is the
|
|
161
|
-
// harness-agnostic copy of the same wiring, retired in the finally below.
|
|
162
|
-
const marker = writeSessionMarker({
|
|
163
|
-
oatheHome: paths.oatheHome, workspace, harness, cwd, wiring: extra });
|
|
164
127
|
const cage = spawnCaged({
|
|
165
128
|
unit,
|
|
166
129
|
env: curatedEnv(env, { hermetic, extra }),
|
|
167
|
-
cmd: resolveOnPath(env.PATH, harness),
|
|
130
|
+
cmd: resolveOnPath(env.PATH, byName(harness).launch?.bin ?? harness), // the adapter names its own binary
|
|
168
131
|
args,
|
|
169
132
|
cwd,
|
|
170
133
|
stdio: 'inherit', // an interactive daily driver owns the terminal
|
|
@@ -173,7 +136,6 @@ export async function runHarness({
|
|
|
173
136
|
const host = new SessionHost({
|
|
174
137
|
client: substrate,
|
|
175
138
|
identity,
|
|
176
|
-
workspace,
|
|
177
139
|
liveness: () => (cage.alive ? cage.alive() : cage.enumerate().length > 0),
|
|
178
140
|
observeIntervalMs,
|
|
179
141
|
});
|
|
@@ -186,7 +148,6 @@ export async function runHarness({
|
|
|
186
148
|
if (exitCode === 0) await host.stop({ exitCode });
|
|
187
149
|
else await host.stopSilently(); // a non-zero exit was not a clean goodbye — leave the absence
|
|
188
150
|
} finally {
|
|
189
|
-
clearSessionMarker(marker);
|
|
190
151
|
await substrate.close();
|
|
191
152
|
}
|
|
192
153
|
const teardown = await cage.teardownProvenEmpty();
|
|
@@ -194,40 +155,18 @@ export async function runHarness({
|
|
|
194
155
|
}
|
|
195
156
|
|
|
196
157
|
/**
|
|
197
|
-
* The
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* default is ANNOUNCED, never silently assumed.
|
|
158
|
+
* The verifier is chosen ONCE, at `oathe init` (machine-wide, per-folder override via
|
|
159
|
+
* `oathe config verifier <engine>`). Launch never prompts: an explicit choice passes
|
|
160
|
+
* silently; a still-default value is ANNOUNCED on stderr — never silently assumed.
|
|
201
161
|
* @returns {Promise<{chosen: string, prompted: boolean}>}
|
|
202
162
|
*/
|
|
203
|
-
export function ensureVerifierChoice({ config,
|
|
204
|
-
const
|
|
205
|
-
if (config.source('verifier')
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
`);
|
|
209
|
-
return Promise.resolve({ chosen: current, prompted: false });
|
|
163
|
+
export function ensureVerifierChoice({ config, err = process.stderr } = {}) {
|
|
164
|
+
const chosen = config.get('verifier');
|
|
165
|
+
if (config.source('verifier') === 'default') {
|
|
166
|
+
err?.write?.(`verifier: ${chosen} (default — \`oathe init\` records the machine choice; `
|
|
167
|
+
+ 'override per folder with `oathe config verifier <engine>`)\n');
|
|
210
168
|
}
|
|
211
|
-
|
|
212
|
-
out.write(`
|
|
213
|
-
Who verifies this folder's work? ${menu} (Enter = ${current})
|
|
214
|
-
> `);
|
|
215
|
-
return new Promise((resolve) => {
|
|
216
|
-
const onAnswer = (data) => {
|
|
217
|
-
stdin.removeListener('data', onAnswer);
|
|
218
|
-
stdin.pause?.();
|
|
219
|
-
const raw = String(data).trim();
|
|
220
|
-
const byIndex = VERIFIER_ENGINES[Number(raw) - 1];
|
|
221
|
-
const chosen = byIndex ?? (VERIFIER_ENGINES.includes(raw) ? raw : current);
|
|
222
|
-
config.set('verifier', chosen, { scope: 'workspace' });
|
|
223
|
-
out.write(` verifier: ${chosen} (recorded in ${config.workspacePath})
|
|
224
|
-
|
|
225
|
-
`);
|
|
226
|
-
resolve({ chosen, prompted: true });
|
|
227
|
-
};
|
|
228
|
-
stdin.on('data', onAnswer);
|
|
229
|
-
stdin.resume?.();
|
|
230
|
-
});
|
|
169
|
+
return Promise.resolve({ chosen, prompted: false });
|
|
231
170
|
}
|
|
232
171
|
|
|
233
172
|
/**
|
|
@@ -254,11 +193,3 @@ export function waitForLaunch({ harness, pauseMs, stdin, out }) {
|
|
|
254
193
|
stdin.resume?.();
|
|
255
194
|
});
|
|
256
195
|
}
|
|
257
|
-
|
|
258
|
-
export function runClaude(o = {}) {
|
|
259
|
-
return runHarness({ ...o, harness: 'claude' });
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function runCodex(o = {}) {
|
|
263
|
-
return runHarness({ ...o, harness: 'codex' });
|
|
264
|
-
}
|
package/src/manifest.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import crypto from 'node:crypto';
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
|
|
9
|
+
import { atomicWriteJson } from './fslock.mjs';
|
|
10
|
+
|
|
9
11
|
export function sha256Hex(text) {
|
|
10
12
|
return crypto.createHash('sha256').update(text).digest('hex');
|
|
11
13
|
}
|
|
@@ -35,9 +37,11 @@ export class InstallManifest {
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
save() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
// Atomic (temp-then-rename): concurrent hooks and servers read this file; a torn manifest
|
|
41
|
+
// would break doctor/uninstall. Serializing whole load→mutate→save cycles is the caller's
|
|
42
|
+
// job (withFileLock), because a lock inside save() alone cannot prevent lost updates.
|
|
43
|
+
atomicWriteJson(this.manifestPath,
|
|
44
|
+
{ format: MANIFEST_FORMAT, saved_at: this.clock(), rows: this.rows, backups: this.backups });
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
/** One row per (harness, file, kind, detail identity); a re-run replaces its own row. */
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// oathe — the MCP connection: the ndjson JSON-RPC loop, server-initiated requests
|
|
2
|
+
// (roots/list, id-correlated), and the LAZY tool context. Startup is crash-proof by
|
|
3
|
+
// construction: nothing beyond the transport is built until the first tools/call, so a
|
|
4
|
+
// poisoned environment (an unexpanded ${...} template, an empty allowlisted env) can never
|
|
5
|
+
// kill the server before it answers initialize — it surfaces per call, typed, through the
|
|
6
|
+
// resolution ladder instead.
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import readline from 'node:readline';
|
|
10
|
+
|
|
11
|
+
import { dispatch, lazyTools } from './oathe-tools.mjs';
|
|
12
|
+
import { OatheConfig } from '../config.mjs';
|
|
13
|
+
import { WorkspaceResolver } from '../workspace-resolver.mjs';
|
|
14
|
+
import { harnessForClient } from '../harnesses/catalog.mjs';
|
|
15
|
+
import { resolveSpeaker } from '../speaker.mjs';
|
|
16
|
+
import { homeOf } from '../paths.mjs';
|
|
17
|
+
|
|
18
|
+
export class McpConnection {
|
|
19
|
+
/**
|
|
20
|
+
* @param {{env?: NodeJS.ProcessEnv, input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream,
|
|
21
|
+
* err?: NodeJS.WritableStream, toolContextFactory?: (o: {resolution: object, client: object}) =>
|
|
22
|
+
* Promise<{tools: object, close: () => Promise<void>}>, cwd?: () => string, home?: string}} o
|
|
23
|
+
*/
|
|
24
|
+
constructor({
|
|
25
|
+
env = process.env, input = process.stdin, output = process.stdout, err = process.stderr,
|
|
26
|
+
toolContextFactory = null, cwd = () => process.cwd(), home = homeOf(env),
|
|
27
|
+
} = {}) {
|
|
28
|
+
this.env = env;
|
|
29
|
+
this.input = input;
|
|
30
|
+
this.output = output;
|
|
31
|
+
this.err = err;
|
|
32
|
+
this.factory = toolContextFactory ?? defaultToolContextFactory({ env });
|
|
33
|
+
this.cwd = cwd;
|
|
34
|
+
this.home = home;
|
|
35
|
+
this.client = { capabilities: {}, info: null };
|
|
36
|
+
this.pending = new Map();
|
|
37
|
+
this.requestSeq = 0;
|
|
38
|
+
this.resolver = null;
|
|
39
|
+
this.contextPromise = null;
|
|
40
|
+
this.currentContext = null;
|
|
41
|
+
this.served = lazyTools(() => this.#context());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
start() {
|
|
45
|
+
const rl = readline.createInterface({ input: this.input });
|
|
46
|
+
rl.on('line', async (line) => {
|
|
47
|
+
const s = line.trim();
|
|
48
|
+
if (!s) return;
|
|
49
|
+
let msg;
|
|
50
|
+
try { msg = JSON.parse(s); } catch { return; }
|
|
51
|
+
await this.#onMessage(msg);
|
|
52
|
+
});
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A server→client request; the response routes back by id. */
|
|
57
|
+
request(method, params = {}) {
|
|
58
|
+
const id = `srv-${++this.requestSeq}`;
|
|
59
|
+
const promise = new Promise((resolve, reject) => this.pending.set(id, { resolve, reject }));
|
|
60
|
+
this.#write({ jsonrpc: '2.0', id, method, params });
|
|
61
|
+
return promise;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async #onMessage(msg) {
|
|
65
|
+
// A response to one of OUR requests: no method, an id we issued.
|
|
66
|
+
if (msg.method === undefined && msg.id !== undefined && this.pending.has(msg.id)) {
|
|
67
|
+
const entry = this.pending.get(msg.id);
|
|
68
|
+
this.pending.delete(msg.id);
|
|
69
|
+
if (msg.error) entry.reject(new Error(`${msg.error.code}: ${msg.error.message}`));
|
|
70
|
+
else entry.resolve(msg.result);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (msg.method === 'initialize') {
|
|
74
|
+
this.client = {
|
|
75
|
+
capabilities: msg.params?.capabilities ?? {},
|
|
76
|
+
info: msg.params?.clientInfo ?? null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (msg.method === 'notifications/roots/list_changed') {
|
|
80
|
+
await this.#invalidate();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const out = await dispatch(msg, { tools: this.served });
|
|
84
|
+
if (out) this.#write(out);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#write(obj) {
|
|
88
|
+
this.output.write(`${JSON.stringify(obj)}\n`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The one lazily-built context per resolution — rebuilt when the roots change OR when a
|
|
93
|
+
* config layer file's clock moves (two stats per call): `oathe config verifier cursor`
|
|
94
|
+
* must reach a server that has been alive for months, not wait for its restart. The
|
|
95
|
+
* founder hit this live — a ChatGPT session's claims kept the verifier its startup
|
|
96
|
+
* snapshot recorded.
|
|
97
|
+
*/
|
|
98
|
+
async #context() {
|
|
99
|
+
if (this.contextPromise) {
|
|
100
|
+
const cached = await this.contextPromise.catch(() => null);
|
|
101
|
+
if (cached && this.#configStamp(cached.resolution?.root ?? null) !== cached.configStamp) {
|
|
102
|
+
await this.#invalidate();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (!this.contextPromise) {
|
|
106
|
+
this.contextPromise = this.#buildContext();
|
|
107
|
+
this.contextPromise.catch(() => { this.contextPromise = null; });
|
|
108
|
+
}
|
|
109
|
+
return this.contextPromise;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The config layers' clocks, as one comparable string; an absent file is its own state. */
|
|
113
|
+
#configStamp(root) {
|
|
114
|
+
return OatheConfig.filesFor({ env: this.env, cwd: root })
|
|
115
|
+
.map((f) => { try { return `${f}:${fs.statSync(f).mtimeMs}`; } catch { return `${f}:absent`; } })
|
|
116
|
+
.join('|');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async #buildContext() {
|
|
120
|
+
if (!this.resolver) {
|
|
121
|
+
// rootsTimeoutMs flows from config; the global layer is read HERE, lazily, so a broken
|
|
122
|
+
// config file surfaces as this call's typed error, never a startup crash.
|
|
123
|
+
const { OatheConfig } = await import('../config.mjs');
|
|
124
|
+
const timeoutMs = OatheConfig.global({ env: this.env }).get('rootsTimeoutMs');
|
|
125
|
+
const rootsProvider = this.client.capabilities?.roots
|
|
126
|
+
? async () => (await this.request('roots/list'))?.roots ?? []
|
|
127
|
+
: null;
|
|
128
|
+
this.resolver = new WorkspaceResolver({
|
|
129
|
+
env: this.env, cwd: this.cwd, rootsProvider, timeoutMs, home: this.home,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const resolution = await this.resolver.resolve();
|
|
133
|
+
if (resolution.diagnostics.length > 0) {
|
|
134
|
+
this.err.write(`oathe mcp: workspace resolved via ${resolution.source}; `
|
|
135
|
+
+ `${resolution.diagnostics.join('; ')}\n`);
|
|
136
|
+
}
|
|
137
|
+
// The stamp is taken BEFORE the factory reads the files: a write racing the build can
|
|
138
|
+
// only cause one extra rebuild next call, never a missed change.
|
|
139
|
+
const configStamp = this.#configStamp(resolution.root ?? null);
|
|
140
|
+
const context = await this.factory({ resolution, client: this.client });
|
|
141
|
+
this.currentContext = context;
|
|
142
|
+
return { resolution, tools: context.tools, context, configStamp };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async #invalidate() {
|
|
146
|
+
const stale = this.currentContext;
|
|
147
|
+
this.currentContext = null;
|
|
148
|
+
this.contextPromise = null;
|
|
149
|
+
this.resolver?.invalidate();
|
|
150
|
+
if (stale) await stale.close?.().catch?.(() => {});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The production context: config from the resolved root, real substrate, and the ONE
|
|
155
|
+
* activation seam (src/activation.mjs) — the resolution's `synthetic` fact rides into both
|
|
156
|
+
* the tools (board scope) and the seam (no registration, no fences). */
|
|
157
|
+
export function defaultToolContextFactory({ env }) {
|
|
158
|
+
let speaker = null; // observed once per server process — our own ancestry never changes
|
|
159
|
+
return async ({ resolution, client }) => {
|
|
160
|
+
const [
|
|
161
|
+
{ Substrate }, { buildPaths }, { OatheConfig }, { WorkspaceRegistry }, { InstallManifest },
|
|
162
|
+
{ packageVersion }, { ActivationSeam }, tools,
|
|
163
|
+
] = await Promise.all([
|
|
164
|
+
import('../substrate.mjs'), import('../paths.mjs'), import('../config.mjs'), import('../registry.mjs'),
|
|
165
|
+
import('../manifest.mjs'), import('../context.mjs'), import('../activation.mjs'), import('./oathe-tools.mjs'),
|
|
166
|
+
]);
|
|
167
|
+
const paths = buildPaths(env);
|
|
168
|
+
const config = new OatheConfig({ env, cwd: resolution.root });
|
|
169
|
+
const substrate = new Substrate({ database: config.get('db'), paths, env, config });
|
|
170
|
+
const identity = {
|
|
171
|
+
orgId: config.get('org'),
|
|
172
|
+
principalId: config.get('principal') || env.USER || 'operator',
|
|
173
|
+
department: config.get('department'),
|
|
174
|
+
};
|
|
175
|
+
const activation = new ActivationSeam({
|
|
176
|
+
cwd: resolution.dir,
|
|
177
|
+
env,
|
|
178
|
+
registry: new WorkspaceRegistry({ registryPath: paths.registryPath }),
|
|
179
|
+
manifest: InstallManifest.load({ manifestPath: paths.manifestPath, backupsDir: paths.backupsDir }),
|
|
180
|
+
config,
|
|
181
|
+
version: packageVersion(paths),
|
|
182
|
+
synthetic: resolution.synthetic,
|
|
183
|
+
harness: harnessForClient(client?.info?.name),
|
|
184
|
+
sourceFor: (tool) => `mcp:${tool}`,
|
|
185
|
+
});
|
|
186
|
+
let successorPromise = null;
|
|
187
|
+
const served = tools.createOatheTools({
|
|
188
|
+
client: substrate,
|
|
189
|
+
identity,
|
|
190
|
+
config,
|
|
191
|
+
workspace: resolution.ref,
|
|
192
|
+
synthetic: resolution.synthetic,
|
|
193
|
+
activation,
|
|
194
|
+
// The SPEAKER primitive — resolved ONCE from our own ancestry + the device session
|
|
195
|
+
// registry (the walk outranks the client's self-declared name); required plumbing.
|
|
196
|
+
speaker: (speaker ??= resolveSpeaker({ clientName: client?.info?.name, sessionsPath: paths.sessionsPath })),
|
|
197
|
+
|
|
198
|
+
// Verification over MCP DISPATCHES — the engine never runs inside the server (a run is
|
|
199
|
+
// minutes; the server must keep answering). ONE seam, every surface (verifierSeam).
|
|
200
|
+
verifier: (await import('../verify-dispatch.mjs')).verifierSeam({
|
|
201
|
+
orgId: identity.orgId,
|
|
202
|
+
query: (sql, params) => substrate.query(sql, params),
|
|
203
|
+
paths,
|
|
204
|
+
cwd: resolution.dir,
|
|
205
|
+
}),
|
|
206
|
+
successor: async (o) => {
|
|
207
|
+
if (!successorPromise) {
|
|
208
|
+
successorPromise = import('../runtime/provider.mjs')
|
|
209
|
+
.then(({ resolveRuntimeProvider }) => resolveRuntimeProvider({ config, paths })
|
|
210
|
+
.successor({ substrate, identity, paths }));
|
|
211
|
+
successorPromise.catch(() => { successorPromise = null; }); // a failed build must not poison retries
|
|
212
|
+
}
|
|
213
|
+
return (await successorPromise).pickup(o);
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return { tools: served, close: () => substrate.close() };
|
|
217
|
+
};
|
|
218
|
+
}
|