@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,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
|
+
}
|