@oathe/oathe 0.0.1 → 0.2.0
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/LICENSE +202 -21
- package/NOTICE +7 -0
- package/README.md +99 -12
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +376 -0
- package/docs/PRIVACY.md +45 -0
- package/package.json +32 -23
- package/plugin/.claude-plugin/plugin.json +10 -0
- package/plugin/.mcp.json +13 -0
- package/plugin/hooks/frame-note.mjs +24 -0
- package/plugin/hooks/heartbeat.mjs +49 -0
- package/plugin/hooks/hooks.json +39 -0
- package/plugin/hooks/lib.mjs +83 -0
- package/plugin/hooks/render-board.mjs +11 -0
- package/plugin/skills/oathe-work/SKILL.md +33 -0
- package/src/atif.mjs +633 -0
- package/src/blocks.mjs +192 -0
- package/src/board-render.mjs +106 -0
- package/src/config.mjs +169 -0
- package/src/context.mjs +35 -0
- package/src/doctor.mjs +108 -0
- package/src/harness.mjs +271 -0
- package/src/init.mjs +92 -0
- package/src/launch-env.mjs +25 -0
- package/src/launch.mjs +259 -0
- package/src/manifest.mjs +89 -0
- package/src/mcp/oathe-tools.mjs +517 -0
- package/src/paths.mjs +49 -0
- package/src/plans.mjs +50 -0
- package/src/runtime/discharge.mjs +57 -0
- package/src/runtime/provider.mjs +154 -0
- package/src/runtime/simple-cage.mjs +67 -0
- package/src/runtime/sql-acceptance-lane.mjs +89 -0
- package/src/session-host.mjs +81 -0
- package/src/substrate.mjs +337 -0
- package/src/successor.mjs +31 -0
- package/src/traces.mjs +242 -0
- package/src/uninstall.mjs +45 -0
- package/src/verifier.mjs +322 -0
- package/src/workspace.mjs +47 -0
- package/vendor/ddl/001_core.sql +312 -0
- package/vendor/ddl/002_claim.sql +438 -0
- package/vendor/ddl/003_verification.sql +480 -0
- package/vendor/ddl/004_delegation.sql +397 -0
- package/vendor/ddl/005_escalation.sql +303 -0
- package/vendor/ddl/006_dependency.sql +384 -0
- package/vendor/ddl/007_assignment.sql +502 -0
- package/vendor/ddl/008_effect_receipt.sql +290 -0
- package/vendor/ddl/009_verified_edge.sql +452 -0
- package/vendor/ddl/010_parent_child_verification.sql +320 -0
- package/vendor/ddl/011_confirm.sql +288 -0
- package/vendor/ddl/012_evaluator_lane.sql +444 -0
- package/vendor/ddl/013_claim_terminal.sql +279 -0
- package/vendor/ddl/014_claim_settlement.sql +327 -0
- package/vendor/ddl/015_claim_yield.sql +213 -0
- package/vendor/ddl/016_reopened_reclaim.sql +285 -0
- package/vendor/ddl/017_claim_yield_causes.sql +357 -0
- package/vendor/ddl/018_receiptless_unknown.sql +249 -0
- package/vendor/ddl/019_verification_contract_freeze.sql +335 -0
- package/vendor/ddl/020_context_compilation.sql +105 -0
- package/vendor/ddl/021_execution_attempt_closure.sql +95 -0
- package/vendor/ddl/022_verification_clause.sql +106 -0
- package/vendor/ddl/023_executor_role.sql +66 -0
- package/vendor/ddl/024_executor_role_hardening.sql +439 -0
- package/vendor/ddl/025_running_attempt_uniqueness.sql +102 -0
- package/vendor/ddl/026_acceptance_authority.sql +230 -0
- package/vendor/ddl/027_ownership_return.sql +836 -0
- package/vendor/ddl/028_attempt_bind_ownership.sql +173 -0
- package/vendor/ddl/manifest.json +183 -0
- package/index.js +0 -33
package/src/harness.mjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// oathe — the harness layer. One base class holds what every harness shares (detection inputs,
|
|
2
|
+
// manifest access, exec seam); each subclass owns the ONE way its harness is onboarded:
|
|
3
|
+
// Claude via owned JSON paths in ~/.claude/settings.json, Codex via its sanctioned CLIs with
|
|
4
|
+
// post-verification (its config stanzas are Codex-managed bookkeeping — writing them by hand
|
|
5
|
+
// is how two managers end up owning one file).
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
|
|
11
|
+
import { JsonEntries } from './blocks.mjs';
|
|
12
|
+
import { sha256Hex } from './manifest.mjs';
|
|
13
|
+
|
|
14
|
+
export class HarnessOnboardError extends Error {
|
|
15
|
+
constructor(code, message, details = {}) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'HarnessOnboardError';
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.details = details;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const defaultExec = {
|
|
24
|
+
run(cmd, args) {
|
|
25
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
26
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? '', stderr: r.stderr ?? '' };
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class Harness {
|
|
31
|
+
/**
|
|
32
|
+
* @param {{name: string, home: string, envPath?: string, paths: object,
|
|
33
|
+
* exec?: {run: (cmd: string, args: string[]) => {status: number, stdout: string, stderr: string}}}} o
|
|
34
|
+
*/
|
|
35
|
+
constructor({ name, home, envPath = process.env.PATH ?? '', paths, exec = defaultExec }) {
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.home = home;
|
|
38
|
+
this.envPath = envPath;
|
|
39
|
+
this.paths = paths;
|
|
40
|
+
this.exec = exec;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The harness's config home (e.g. ~/.claude) — subclasses name theirs. */
|
|
44
|
+
get configHome() {
|
|
45
|
+
return path.join(this.home, `.${this.name}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
binOnPath(bin) {
|
|
49
|
+
return this.envPath.split(':').filter(Boolean).some((dir) => {
|
|
50
|
+
try { fs.accessSync(path.join(dir, bin), fs.constants.X_OK); return true; } catch { return false; }
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @returns {{name: string, installed: boolean, evidence: object}} */
|
|
55
|
+
detect() {
|
|
56
|
+
const binFound = this.binOnPath(this.name);
|
|
57
|
+
const homeFound = fs.existsSync(this.configHome);
|
|
58
|
+
return {
|
|
59
|
+
name: this.name,
|
|
60
|
+
installed: binFound && homeFound,
|
|
61
|
+
evidence: { bin_on_path: binFound, config_home: homeFound ? this.configHome : null },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class ClaudeHarness extends Harness {
|
|
67
|
+
constructor(o) {
|
|
68
|
+
super({ ...o, name: 'claude' });
|
|
69
|
+
this.entries = new JsonEntries();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get settingsPath() {
|
|
73
|
+
return path.join(this.configHome, 'settings.json');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The exact keys oathe owns in settings.json — the whole Claude install. */
|
|
77
|
+
#ownedEntries() {
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
// "directory" is what the INSTALLED CLI's settings schema accepts (verified empirically
|
|
81
|
+
// on 2.1.241: the pre-existing custom-plugins entry validates, a "local" entry is
|
|
82
|
+
// rejected with "Invalid input" and the whole file is skipped). The docs say "local";
|
|
83
|
+
// the binary outranks the docs.
|
|
84
|
+
path: ['extraKnownMarketplaces', 'oathe'],
|
|
85
|
+
value: { source: { source: 'directory', path: this.paths.packageRoot } },
|
|
86
|
+
},
|
|
87
|
+
{ path: ['enabledPlugins', 'oathe@oathe'], value: true },
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get registryDir() {
|
|
92
|
+
return path.join(this.configHome, 'plugins');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get installedFile() {
|
|
96
|
+
return path.join(this.registryDir, 'installed_plugins.json');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#readRegistry(file) {
|
|
100
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#installedVersion() {
|
|
104
|
+
return this.#readRegistry(this.installedFile)?.plugins?.['oathe@oathe']?.[0]?.version ?? null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#marketplaceKnown() {
|
|
108
|
+
return this.#readRegistry(path.join(this.registryDir, 'known_marketplaces.json'))?.oathe !== undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#cli(args) {
|
|
112
|
+
const result = this.exec.run('claude', args);
|
|
113
|
+
if (result.status !== 0) {
|
|
114
|
+
throw new HarnessOnboardError('CLAUDE_CLI_FAILED',
|
|
115
|
+
`claude ${args.join(' ')} exited ${result.status}: ${result.stderr.trim()}`, { args });
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onboard({ manifest, version }) {
|
|
121
|
+
const entries = this.#ownedEntries();
|
|
122
|
+
const before = fs.existsSync(this.settingsPath) ? fs.readFileSync(this.settingsPath, 'utf8') : '';
|
|
123
|
+
manifest.backupOnce(this.settingsPath);
|
|
124
|
+
const { content, changed } = this.entries.apply(before, entries);
|
|
125
|
+
if (changed) {
|
|
126
|
+
fs.mkdirSync(path.dirname(this.settingsPath), { recursive: true });
|
|
127
|
+
fs.writeFileSync(this.settingsPath, content);
|
|
128
|
+
}
|
|
129
|
+
manifest.upsert({
|
|
130
|
+
harness: this.name,
|
|
131
|
+
file: this.settingsPath,
|
|
132
|
+
kind: 'json-path',
|
|
133
|
+
detail: { paths: entries.map((e) => e.path) },
|
|
134
|
+
blockVersion: version,
|
|
135
|
+
sha256: sha256Hex(JSON.stringify(entries)),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// MATERIALIZE via the CLI. The settings entries above are the declarative pin, but the CLI's
|
|
139
|
+
// own registry (installed_plugins.json) is what sessions load from — and the install is a
|
|
140
|
+
// CACHED COPY keyed by version, so a version change must evict the stale copy.
|
|
141
|
+
const installed = this.#installedVersion();
|
|
142
|
+
let materialized = false;
|
|
143
|
+
if (installed !== version) {
|
|
144
|
+
if (!this.#marketplaceKnown()) this.#cli(['plugin', 'marketplace', 'add', this.paths.packageRoot]);
|
|
145
|
+
if (installed !== null) this.#cli(['plugin', 'uninstall', 'oathe@oathe']);
|
|
146
|
+
this.#cli(['plugin', 'install', 'oathe@oathe']);
|
|
147
|
+
if (this.#installedVersion() !== version) {
|
|
148
|
+
throw new HarnessOnboardError('CLAUDE_VERIFICATION_FAILED',
|
|
149
|
+
'verification failed: `claude plugin install oathe@oathe` reported success but '
|
|
150
|
+
+ `${this.installedFile} does not record version ${version} — refusing to record an `
|
|
151
|
+
+ 'install that cannot be proven');
|
|
152
|
+
}
|
|
153
|
+
materialized = true;
|
|
154
|
+
}
|
|
155
|
+
manifest.upsert({
|
|
156
|
+
harness: this.name,
|
|
157
|
+
file: this.installedFile,
|
|
158
|
+
kind: 'cli-managed',
|
|
159
|
+
detail: {
|
|
160
|
+
id: 'plugin-install',
|
|
161
|
+
proof: 'oathe@oathe',
|
|
162
|
+
undo: [['plugin', 'uninstall', 'oathe@oathe'], ['plugin', 'marketplace', 'remove', 'oathe']],
|
|
163
|
+
},
|
|
164
|
+
blockVersion: version,
|
|
165
|
+
sha256: sha256Hex('oathe@oathe'),
|
|
166
|
+
});
|
|
167
|
+
return [
|
|
168
|
+
{ action: 'settings-owned-paths', file: this.settingsPath, changed },
|
|
169
|
+
{ action: materialized ? 'plugin-installed' : 'plugin-already-current', file: this.installedFile },
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
offboard({ manifest }) {
|
|
174
|
+
const rows = manifest.removeWhere((r) => r.harness === this.name);
|
|
175
|
+
const actions = [];
|
|
176
|
+
for (const row of rows.filter((r) => r.kind === 'cli-managed')) {
|
|
177
|
+
for (const undo of row.detail?.undo ?? []) {
|
|
178
|
+
const result = this.exec.run('claude', undo);
|
|
179
|
+
actions.push({ action: `claude-undo-${undo.join('-')}`, status: result.status });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!fs.existsSync(this.settingsPath)) return [...actions, { action: 'settings-absent' }];
|
|
183
|
+
const before = fs.readFileSync(this.settingsPath, 'utf8');
|
|
184
|
+
const ownedPaths = rows.flatMap((r) => r.detail?.paths ?? []);
|
|
185
|
+
const { content, changed } = this.entries.remove(before, ownedPaths);
|
|
186
|
+
if (changed) fs.writeFileSync(this.settingsPath, content);
|
|
187
|
+
return [...actions, { action: 'settings-owned-paths-removed', file: this.settingsPath, changed }];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export class CodexHarness extends Harness {
|
|
192
|
+
constructor(o) {
|
|
193
|
+
super({ ...o, name: 'codex' });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get configPath() {
|
|
197
|
+
return path.join(this.configHome, 'config.toml');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The sanctioned registrations, each with the CLI that makes it, the config.toml stanza that
|
|
202
|
+
* proves it landed, and the CLI that undoes it.
|
|
203
|
+
*/
|
|
204
|
+
#registrations() {
|
|
205
|
+
return [
|
|
206
|
+
{
|
|
207
|
+
id: 'marketplace',
|
|
208
|
+
add: ['plugin', 'marketplace', 'add', this.paths.packageRoot],
|
|
209
|
+
proof: '[marketplaces.oathe]',
|
|
210
|
+
undo: ['plugin', 'marketplace', 'remove', 'oathe'],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 'plugin',
|
|
214
|
+
add: ['plugin', 'add', 'oathe@oathe'],
|
|
215
|
+
proof: '[plugins."oathe@oathe"]',
|
|
216
|
+
undo: ['plugin', 'remove', 'oathe@oathe'],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: 'mcp-server',
|
|
220
|
+
add: ['mcp', 'add', 'oathe', '--', 'oathe', 'mcp'],
|
|
221
|
+
proof: '[mcp_servers.oathe]',
|
|
222
|
+
undo: ['mcp', 'remove', 'oathe'],
|
|
223
|
+
},
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
onboard({ manifest, version }) {
|
|
228
|
+
manifest.backupOnce(this.configPath);
|
|
229
|
+
for (const reg of this.#registrations()) {
|
|
230
|
+
const result = this.exec.run('codex', reg.add);
|
|
231
|
+
if (result.status !== 0) {
|
|
232
|
+
throw new HarnessOnboardError('CODEX_CLI_FAILED',
|
|
233
|
+
`codex ${reg.add.join(' ')} exited ${result.status}: ${result.stderr.trim()}`, { reg: reg.id });
|
|
234
|
+
}
|
|
235
|
+
const config = fs.existsSync(this.configPath) ? fs.readFileSync(this.configPath, 'utf8') : '';
|
|
236
|
+
if (!config.includes(reg.proof)) {
|
|
237
|
+
throw new HarnessOnboardError('CODEX_VERIFICATION_FAILED',
|
|
238
|
+
`verification failed: codex ${reg.add.join(' ')} reported success but ${this.configPath} `
|
|
239
|
+
+ `carries no ${reg.proof} stanza — refusing to record an install that cannot be proven`,
|
|
240
|
+
{ reg: reg.id });
|
|
241
|
+
}
|
|
242
|
+
manifest.upsert({
|
|
243
|
+
harness: this.name,
|
|
244
|
+
file: this.configPath,
|
|
245
|
+
kind: 'cli-managed',
|
|
246
|
+
detail: { id: reg.id, proof: reg.proof, undo: reg.undo },
|
|
247
|
+
blockVersion: version,
|
|
248
|
+
sha256: sha256Hex(reg.proof),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return this.#registrations().map((r) => ({ action: `codex-${r.id}` }));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
offboard({ manifest }) {
|
|
255
|
+
const rows = manifest.removeWhere((r) => r.harness === this.name);
|
|
256
|
+
const actions = [];
|
|
257
|
+
// Undo in reverse install order, so the plugin is gone before its marketplace is.
|
|
258
|
+
for (const row of rows.reverse()) {
|
|
259
|
+
const undo = row.detail?.undo;
|
|
260
|
+
if (!undo) continue;
|
|
261
|
+
const result = this.exec.run('codex', undo);
|
|
262
|
+
actions.push({ action: `codex-undo-${row.detail.id}`, status: result.status });
|
|
263
|
+
}
|
|
264
|
+
return actions;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** @returns {Array<{name: string, installed: boolean, evidence: object}>} */
|
|
269
|
+
export function census(harnesses) {
|
|
270
|
+
return harnesses.map((h) => h.detect());
|
|
271
|
+
}
|
package/src/init.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// oathe init — census → substrate → per-harness onboarding → manifest. The order is the
|
|
2
|
+
// promise: nothing is onboarded onto a world whose substrate could not come up, and nothing
|
|
3
|
+
// is recorded that was not verified.
|
|
4
|
+
|
|
5
|
+
import { buildContext } from './context.mjs';
|
|
6
|
+
import { census } from './harness.mjs';
|
|
7
|
+
import { standardPlan } from './plans.mjs';
|
|
8
|
+
|
|
9
|
+
export class OatheInitError extends Error {
|
|
10
|
+
constructor(code, message, details = {}) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'OatheInitError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {Promise<{census: object[], substrate: object, principal: object, actions: object[]}>}
|
|
20
|
+
*/
|
|
21
|
+
export async function runInit({ env = process.env, exec } = {}) {
|
|
22
|
+
const ctx = buildContext({ env, exec });
|
|
23
|
+
const { manifest, harnesses, substrate, identity, version } = ctx;
|
|
24
|
+
try {
|
|
25
|
+
const seen = census(harnesses);
|
|
26
|
+
|
|
27
|
+
const detect = await substrate.detect();
|
|
28
|
+
if (!detect.reachable) {
|
|
29
|
+
throw new OatheInitError('OATHE_SUBSTRATE_UNREACHABLE',
|
|
30
|
+
'Postgres is not reachable, so there is no substrate to onboard onto. Install and start '
|
|
31
|
+
+ 'it first ('
|
|
32
|
+
+ (process.platform === 'darwin'
|
|
33
|
+
? 'macOS: `brew install postgresql@17 && brew services start postgresql@17`'
|
|
34
|
+
: 'Debian/Ubuntu: `apt install postgresql && service postgresql start`')
|
|
35
|
+
+ ', or point PGHOST/OATHE_PG_HOST at your server), '
|
|
36
|
+
+ `then re-run \`oathe init\`. Detail: ${detect.detail}`,
|
|
37
|
+
{ detail: detect.detail });
|
|
38
|
+
}
|
|
39
|
+
// Same preflight block as detect(): a missing DDL source is caught here too, before any
|
|
40
|
+
// database is created — never a half-onboarded world.
|
|
41
|
+
substrate.assertDdlSource();
|
|
42
|
+
await substrate.ensureDatabase();
|
|
43
|
+
await substrate.applyDdl();
|
|
44
|
+
await substrate.seed({
|
|
45
|
+
orgId: identity.orgId, principalId: identity.principalId, department: identity.department,
|
|
46
|
+
});
|
|
47
|
+
await substrate.registerYieldCause();
|
|
48
|
+
|
|
49
|
+
// The verification lane: a non-author verifier principal (FC010) and the acceptance-seat
|
|
50
|
+
// roster, registered through the substrate's own governed verb. Seat order matters — the
|
|
51
|
+
// producer picks the first NON-AUTHOR seat, so the verifier leads and the operator backs
|
|
52
|
+
// it up (for settling the verification tasks the verifier itself authors).
|
|
53
|
+
const verifierPrincipal = ctx.config.get('verifierPrincipal');
|
|
54
|
+
await substrate.seedVerifier({
|
|
55
|
+
orgId: identity.orgId,
|
|
56
|
+
verifierPrincipal,
|
|
57
|
+
operatorPrincipal: identity.principalId,
|
|
58
|
+
department: 'verification',
|
|
59
|
+
});
|
|
60
|
+
const seats = [verifierPrincipal, identity.principalId];
|
|
61
|
+
await substrate.registerAcceptanceAuthority({
|
|
62
|
+
orgId: identity.orgId,
|
|
63
|
+
seats,
|
|
64
|
+
clauseSpecs: standardPlan().clause_spec,
|
|
65
|
+
checkerRefs: { 'checker://acceptance_package': 'verification-clause' },
|
|
66
|
+
registeredBy: 'oathe-init',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const actions = [];
|
|
70
|
+
for (const harness of harnesses) {
|
|
71
|
+
const detection = seen.find((s) => s.name === harness.name);
|
|
72
|
+
if (!detection.installed) {
|
|
73
|
+
actions.push({ harness: harness.name, action: 'skipped-not-installed' });
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const action of harness.onboard({ manifest, version })) {
|
|
77
|
+
actions.push({ harness: harness.name, ...action });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
manifest.save();
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
census: seen,
|
|
84
|
+
substrate: await substrate.status(),
|
|
85
|
+
principal: { org_id: identity.orgId, principal_id: identity.principalId, role: 'ceo' },
|
|
86
|
+
verifier: { principal_id: verifierPrincipal, seats },
|
|
87
|
+
actions,
|
|
88
|
+
};
|
|
89
|
+
} finally {
|
|
90
|
+
await substrate.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// oathe — the launched-session contract. The plugin installs at USER scope, so its hooks and
|
|
2
|
+
// MCP server reach every session on the machine; only a session started by `oathe <harness>`
|
|
3
|
+
// has opted into the board. The launcher stamps that opt-in into the caged child's environment,
|
|
4
|
+
// and everything plugin-side asks ONE predicate before touching the substrate. Named once here:
|
|
5
|
+
// the launcher writes the block, the hooks and the server read it.
|
|
6
|
+
|
|
7
|
+
export const LAUNCHED_HARNESS_ENV = 'OATHE_LAUNCHED_HARNESS';
|
|
8
|
+
|
|
9
|
+
/** The harness ('claude' | 'codex') that launched this session, or null when unlaunched. */
|
|
10
|
+
export function launchedHarness(env = process.env) {
|
|
11
|
+
const value = String(env[LAUNCHED_HARNESS_ENV] ?? '').trim();
|
|
12
|
+
return value === '' ? null : value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The env block the launcher hands the caged child — the oathe wiring plus the opt-in marker. */
|
|
16
|
+
export function launchSessionEnv({ config, identity, cwd, harness }) {
|
|
17
|
+
return {
|
|
18
|
+
OATHE_DB: config.get('db'),
|
|
19
|
+
OATHE_ORG: identity.orgId,
|
|
20
|
+
OATHE_PRINCIPAL: identity.principalId,
|
|
21
|
+
OATHE_DEPARTMENT: identity.department,
|
|
22
|
+
OATHE_WORKSPACE_DIR: cwd,
|
|
23
|
+
[LAUNCHED_HARNESS_ENV]: harness,
|
|
24
|
+
};
|
|
25
|
+
}
|
package/src/launch.mjs
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// oathe claude — pre-flight the project surfaces, then launch the interactive harness INSIDE
|
|
2
|
+
// the cage (spawnCaged: replaced environment, stamped fence, proven-empty teardown) with the
|
|
3
|
+
// session host observing cage liveness (never touching claim horizons — R1).
|
|
4
|
+
//
|
|
5
|
+
// The cage is reached through the runtime seam (resolveRuntimeProvider), not by a path import
|
|
6
|
+
// here — the runtime's cage lives outside oathe-runtime's exports map (pre-extraction) and is
|
|
7
|
+
// resolved by PATH from paths.cagePath inside OatheRuntimeProvider itself.
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
import { buildContext } from './context.mjs';
|
|
13
|
+
import { VERIFIER_ENGINES } from './config.mjs';
|
|
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';
|
|
18
|
+
import { SessionHost } from './session-host.mjs';
|
|
19
|
+
import { launchSessionEnv } from './launch-env.mjs';
|
|
20
|
+
|
|
21
|
+
export class LaunchError extends Error {
|
|
22
|
+
constructor(code, message, details = {}) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'LaunchError';
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.details = details;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
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
|
+
/**
|
|
43
|
+
* Ensure the cwd's CLAUDE.md (and AGENTS.md when Codex is installed) carries the managed Oathe
|
|
44
|
+
* section, and that the global install exists. Creates a minimal file holding only the fence
|
|
45
|
+
* when absent — recorded as a project-scope manifest row either way.
|
|
46
|
+
*/
|
|
47
|
+
export async function preflight({ env = process.env, cwd = process.cwd(), exec, harness = 'claude' } = {}) {
|
|
48
|
+
const ctx = buildContext({ env, exec });
|
|
49
|
+
const { manifest, harnesses, version, substrate } = ctx;
|
|
50
|
+
await substrate.close(); // preflight itself never talks to the database
|
|
51
|
+
if (!manifest.rows.some((r) => r.harness === harness)) {
|
|
52
|
+
throw new LaunchError('OATHE_NOT_INSTALLED',
|
|
53
|
+
`the ${harness} install is missing (no ${harness} rows in the install manifest) — `
|
|
54
|
+
+ 'run `oathe init` with that harness present first');
|
|
55
|
+
}
|
|
56
|
+
const seen = census(harnesses);
|
|
57
|
+
const workspace = workspaceRef(cwd);
|
|
58
|
+
const block = new FencedBlock({ style: FENCE_STYLES.html });
|
|
59
|
+
const targets = [{ file: 'CLAUDE.md', action: 'claude-md-fence' }];
|
|
60
|
+
if (seen.find((s) => s.name === 'codex')?.installed) {
|
|
61
|
+
targets.push({ file: 'AGENTS.md', action: 'agents-md-fence' });
|
|
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 };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** POSIX-name keys only — what the cage can declare; the rest cannot ride an `env -i` word. */
|
|
86
|
+
function declarable(env) {
|
|
87
|
+
const out = {};
|
|
88
|
+
for (const [k, v] of Object.entries(env)) {
|
|
89
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) && v !== undefined && v !== null && !String(v).includes('\0')) {
|
|
90
|
+
out[k] = String(v);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resolve `name` against the LAUNCH env's PATH (not the supervisor's — the cage's own resolver
|
|
98
|
+
* reads process.env.PATH, which is not the environment the user asked us to launch from).
|
|
99
|
+
*/
|
|
100
|
+
function resolveOnPath(envPath, name) {
|
|
101
|
+
for (const dir of String(envPath ?? '').split(':').filter(Boolean)) {
|
|
102
|
+
const candidate = path.join(dir, name);
|
|
103
|
+
try { fs.accessSync(candidate, fs.constants.X_OK); return candidate; } catch { /* keep looking */ }
|
|
104
|
+
}
|
|
105
|
+
throw new LaunchError('OATHE_HARNESS_NOT_FOUND',
|
|
106
|
+
`no executable '${name}' on PATH — is the harness installed?`, { name });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The hermetic whitelist: terminal plumbing + oathe wiring, nothing else. */
|
|
110
|
+
const HERMETIC_KEYS = ['PATH', 'HOME', 'TERM', 'USER', 'LANG', 'LC_ALL', 'SHELL', 'TMPDIR', 'COLORTERM'];
|
|
111
|
+
|
|
112
|
+
function curatedEnv(env, { hermetic, extra }) {
|
|
113
|
+
if (!hermetic) return { ...declarable(env), ...extra };
|
|
114
|
+
const out = {};
|
|
115
|
+
for (const key of HERMETIC_KEYS) if (env[key] !== undefined) out[key] = String(env[key]);
|
|
116
|
+
return { ...out, ...extra };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* ONE launcher, both harnesses — same cage, same session host, same pre-flight; only the
|
|
121
|
+
* binary differs. (The plan parked `oathe codex` in W2 on the premise that Codex lacked
|
|
122
|
+
* Stop/PreCompact; the docs pass proved both exist, so the premise — and the wait — died.)
|
|
123
|
+
*
|
|
124
|
+
* @param {{harness: 'claude'|'codex', env?: object, cwd?: string, args?: string[],
|
|
125
|
+
* hermetic?: boolean, exec?: object, observeIntervalMs?: number}} o
|
|
126
|
+
* @returns {Promise<{exitCode: number, teardown: object, workspace: string}>}
|
|
127
|
+
*/
|
|
128
|
+
export async function runHarness({
|
|
129
|
+
harness, env = process.env, cwd = process.cwd(), args = [], hermetic = false, exec,
|
|
130
|
+
observeIntervalMs = 60_000, out = process.stdout, stdin = process.stdin, pauseMs = 3000,
|
|
131
|
+
} = {}) {
|
|
132
|
+
const { workspace } = await preflight({ env, cwd, exec, harness });
|
|
133
|
+
const ctx = buildContext({ env, exec, cwd });
|
|
134
|
+
const { paths, substrate, identity, config } = ctx;
|
|
135
|
+
|
|
136
|
+
// First launch in a folder: the verifier is CHOSEN, on the record, before any claim binds it.
|
|
137
|
+
await ensureVerifierChoice({ config, harness, stdin, out });
|
|
138
|
+
|
|
139
|
+
// CODEX ONLY: the ANSI splash into terminal scrollback before the TUI starts, with a short
|
|
140
|
+
// readable pause. Codex buries hook output in its ctrl+T transcript overlay, unrendered;
|
|
141
|
+
// Claude Code shows the systemMessage banner inside its own TUI, so it launches clean.
|
|
142
|
+
if (harness === 'codex') {
|
|
143
|
+
let openWork = false;
|
|
144
|
+
try {
|
|
145
|
+
const { renderBoard, renderSplash } = await import('./board-render.mjs');
|
|
146
|
+
const seen = await renderBoard({ client: substrate, identity, workspace });
|
|
147
|
+
out.write(renderSplash({ message: seen.message, sections: seen.sections, workspace }));
|
|
148
|
+
openWork = Object.values(seen.sections).some((rows) => rows.length > 0);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
out.write(`Oathe board unavailable (${String(e?.message || e).slice(0, 120)})\n`);
|
|
151
|
+
}
|
|
152
|
+
if (openWork) await waitForLaunch({ harness, pauseMs, stdin, out });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const { resolveRuntimeProvider } = await import('./runtime/provider.mjs');
|
|
156
|
+
const { spawnCaged } = await resolveRuntimeProvider({ config, paths }).cage();
|
|
157
|
+
|
|
158
|
+
const unit = `oathe-${Date.now().toString(36)}-${process.pid}`;
|
|
159
|
+
const extra = launchSessionEnv({ config, identity, cwd, harness });
|
|
160
|
+
const cage = spawnCaged({
|
|
161
|
+
unit,
|
|
162
|
+
env: curatedEnv(env, { hermetic, extra }),
|
|
163
|
+
cmd: resolveOnPath(env.PATH, harness),
|
|
164
|
+
args,
|
|
165
|
+
cwd,
|
|
166
|
+
stdio: 'inherit', // an interactive daily driver owns the terminal
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const host = new SessionHost({
|
|
170
|
+
client: substrate,
|
|
171
|
+
identity,
|
|
172
|
+
workspace,
|
|
173
|
+
liveness: () => cage.enumerate().length > 0,
|
|
174
|
+
observeIntervalMs,
|
|
175
|
+
});
|
|
176
|
+
host.start();
|
|
177
|
+
|
|
178
|
+
const exitCode = await new Promise((resolve) => {
|
|
179
|
+
cage.child.on('exit', (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
if (exitCode === 0) await host.stop({ exitCode });
|
|
183
|
+
else await host.stopSilently(); // a non-zero exit was not a clean goodbye — leave the absence
|
|
184
|
+
} finally {
|
|
185
|
+
await substrate.close();
|
|
186
|
+
}
|
|
187
|
+
const teardown = await cage.teardownProvenEmpty();
|
|
188
|
+
return { exitCode, teardown, workspace };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The one-time verifier choice for a workspace. If the engine was never EXPLICITLY chosen
|
|
193
|
+
* (config source is 'default'), a TTY launch asks once and records the answer in the
|
|
194
|
+
* workspace file — silence would assign a judge the founder never picked. Off-TTY the
|
|
195
|
+
* default is ANNOUNCED, never silently assumed.
|
|
196
|
+
* @returns {Promise<{chosen: string, prompted: boolean}>}
|
|
197
|
+
*/
|
|
198
|
+
export function ensureVerifierChoice({ config, harness, stdin, out, err = process.stderr }) {
|
|
199
|
+
const current = config.get('verifier');
|
|
200
|
+
if (config.source('verifier') !== 'default') return Promise.resolve({ chosen: current, prompted: false });
|
|
201
|
+
if (stdin?.isTTY !== true || out?.isTTY !== true) {
|
|
202
|
+
err?.write?.(`verifier: ${current} (default — choose one with \`oathe config verifier <engine>\`)
|
|
203
|
+
`);
|
|
204
|
+
return Promise.resolve({ chosen: current, prompted: false });
|
|
205
|
+
}
|
|
206
|
+
const menu = VERIFIER_ENGINES.map((engine, at) => `[${at + 1}] ${engine}`).join(' ');
|
|
207
|
+
out.write(`
|
|
208
|
+
Who verifies this folder's work? ${menu} (Enter = ${current})
|
|
209
|
+
> `);
|
|
210
|
+
return new Promise((resolve) => {
|
|
211
|
+
const onAnswer = (data) => {
|
|
212
|
+
stdin.removeListener('data', onAnswer);
|
|
213
|
+
stdin.pause?.();
|
|
214
|
+
const raw = String(data).trim();
|
|
215
|
+
const byIndex = VERIFIER_ENGINES[Number(raw) - 1];
|
|
216
|
+
const chosen = byIndex ?? (VERIFIER_ENGINES.includes(raw) ? raw : current);
|
|
217
|
+
config.set('verifier', chosen, { scope: 'workspace' });
|
|
218
|
+
out.write(` verifier: ${chosen} (recorded in ${config.workspacePath})
|
|
219
|
+
|
|
220
|
+
`);
|
|
221
|
+
resolve({ chosen, prompted: true });
|
|
222
|
+
};
|
|
223
|
+
stdin.on('data', onAnswer);
|
|
224
|
+
stdin.resume?.();
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The readable-moment gate: give the splash `pauseMs` on screen, let Enter cut it short.
|
|
230
|
+
* TTY-only on BOTH ends — scripts, pipes, and tests never wait. The stdin listener is removed
|
|
231
|
+
* and the stream paused before the harness inherits it.
|
|
232
|
+
*/
|
|
233
|
+
export function waitForLaunch({ harness, pauseMs, stdin, out }) {
|
|
234
|
+
if (stdin?.isTTY !== true || out?.isTTY !== true) return Promise.resolve();
|
|
235
|
+
out.write(` \x1b[2mstarting ${harness} in ${Math.round(pauseMs / 1000)}s — Enter to go now\x1b[0m\n`);
|
|
236
|
+
return new Promise((resolve) => {
|
|
237
|
+
let timer = null;
|
|
238
|
+
const finish = () => {
|
|
239
|
+
stdin.removeListener('data', finish);
|
|
240
|
+
if (timer) clearTimeout(timer);
|
|
241
|
+
stdin.pause();
|
|
242
|
+
resolve();
|
|
243
|
+
};
|
|
244
|
+
// The timer stays ref'd on purpose: this promise is awaited before the harness spawns,
|
|
245
|
+
// so the countdown must hold the event loop open even when stdin contributes no handle
|
|
246
|
+
// (an unref'd timer here let the loop drain mid-wait and cancel the gate).
|
|
247
|
+
timer = setTimeout(finish, pauseMs);
|
|
248
|
+
stdin.on('data', finish);
|
|
249
|
+
stdin.resume?.();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function runClaude(o = {}) {
|
|
254
|
+
return runHarness({ ...o, harness: 'claude' });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function runCodex(o = {}) {
|
|
258
|
+
return runHarness({ ...o, harness: 'codex' });
|
|
259
|
+
}
|