@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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// oathe — the harness base class. One base holds what every harness shares (detection inputs,
|
|
2
|
+
// exec seam, config-home convention); each subclass owns EVERYTHING harness-specific as a named
|
|
3
|
+
// member — identity, wiring, context files, project-dir env var, hook dialect, engine surface —
|
|
4
|
+
// so no `if (name === 'x')` exists anywhere outside src/harnesses/. The catalog
|
|
5
|
+
// (./catalog.mjs) is the one registry over the subclasses.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
|
|
11
|
+
import { globalFenceBody, writeFence } from '../fence.mjs';
|
|
12
|
+
|
|
13
|
+
export class HarnessOnboardError extends Error {
|
|
14
|
+
constructor(code, message, details = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'HarnessOnboardError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.details = details;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const defaultExec = {
|
|
23
|
+
run(cmd, args) {
|
|
24
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8' });
|
|
25
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? '', stderr: r.stderr ?? '' };
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class Harness {
|
|
30
|
+
// ------------------------------------------------------------ identity facts
|
|
31
|
+
/** The CLI on PATH (null: no CLI — a GUI-only or hosted surface). */
|
|
32
|
+
static bin = null;
|
|
33
|
+
/** MCP clientInfo.name values that mean this harness (catalog.harnessForClient). */
|
|
34
|
+
static clientNames = Object.freeze([]);
|
|
35
|
+
/** Context files a project folder carries for this harness (the fence targets). */
|
|
36
|
+
static contextFiles = Object.freeze([]);
|
|
37
|
+
/** The env var this harness sets to name the project dir for hooks/servers, or null. */
|
|
38
|
+
static projectDirEnvVar = null;
|
|
39
|
+
/** Manual steps for a detect-only surface (wiring null), or null. */
|
|
40
|
+
static note = null;
|
|
41
|
+
/** The surfaces this wiring serves, as the init row states them (e.g. 'CLI/Desktop App'); null for detect-only. */
|
|
42
|
+
static covers = null;
|
|
43
|
+
|
|
44
|
+
// ------------------------------------------------------------ capabilities (frozen or null)
|
|
45
|
+
/** {needsCli} — the install writes this harness's config through its CLI (true) or our own files. */
|
|
46
|
+
static wiring = null;
|
|
47
|
+
/** {dialect} — the hook payload/reply dialect this harness speaks. */
|
|
48
|
+
static hooks = null;
|
|
49
|
+
/** {splash, bin} — `oathe <name>` launches it in the cage; splash: print the board to
|
|
50
|
+
* scrollback first; bin: the adapter's OWN interactive binary (never assumed from the
|
|
51
|
+
* harness name — the same primitive, each harness's unique adapter). */
|
|
52
|
+
static launch = null;
|
|
53
|
+
/** {store, newest, projector, ownsPath} — the session-record store the verifier and doctor read. */
|
|
54
|
+
static traces = null;
|
|
55
|
+
/** {ownsExec, name} — recognizing this harness's session PROCESSES (exec predicate) and
|
|
56
|
+
* NAMING the surface they speak from over facts (exec + nearest app bundle). Facts are
|
|
57
|
+
* recorded at SessionStart; naming happens at READ, so it evolves without rewriting
|
|
58
|
+
* history. null: no local process of ours to meet in an ancestry walk. */
|
|
59
|
+
static surfaces = null;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {{name?: string, home: string, envPath?: string, paths: object,
|
|
63
|
+
* exec?: {run: (cmd: string, args: string[]) => {status: number, stdout: string, stderr: string}}}} o
|
|
64
|
+
*/
|
|
65
|
+
constructor({ name, home, envPath = process.env.PATH ?? '', paths, exec = defaultExec }) {
|
|
66
|
+
this.name = name ?? this.constructor.harnessName;
|
|
67
|
+
this.home = home;
|
|
68
|
+
this.envPath = envPath;
|
|
69
|
+
this.paths = paths;
|
|
70
|
+
this.exec = exec;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The config-home convention (~/.<name>) — the ONE place it is spelled. */
|
|
74
|
+
static configHomeFor(home, name = this.harnessName) {
|
|
75
|
+
return path.join(home, `.${name}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* R-BOARD-SCOPE: is `dir` a SYNTHETIC workspace — a directory this harness stages for a
|
|
80
|
+
* session that has no real project folder (ChatGPT desktop's per-conversation cwd), so no
|
|
81
|
+
* board of its own? Base: no harness stages such directories. An adapter that does names
|
|
82
|
+
* them here; the resolver derives the fact once and every surface threads it.
|
|
83
|
+
* @param {{dir: string, home: string}} _o
|
|
84
|
+
*/
|
|
85
|
+
static isSyntheticWorkspaceDir(_o) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The harness's GLOBAL instructions files, relative to its config home, in the harness's
|
|
91
|
+
* OWN precedence order (the first that exists is the one it reads; the last is the default
|
|
92
|
+
* to create); [] = the harness has none. A harness whose sessions can open with no project
|
|
93
|
+
* folder (Codex: ChatGPT desktop) declares them, and `oathe init` puts the managed block
|
|
94
|
+
* where the harness will actually read it — the standing rule those sessions would
|
|
95
|
+
* otherwise never see, since a staging dir never carries a fence.
|
|
96
|
+
*/
|
|
97
|
+
static globalContextFiles = Object.freeze([]);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The harness-docs snapshot pages this adapter's facts derive from, as `<harness>/<slug>`
|
|
101
|
+
* keys of DOC_SOURCES (scripts/pull-harness-docs.mjs). The docs-drift lane re-pulls those
|
|
102
|
+
* pages and, when one changes, names THIS adapter as the thing to re-verify. Every adapter
|
|
103
|
+
* declares at least one; the contract suite refuses orphan pins in either direction.
|
|
104
|
+
*/
|
|
105
|
+
static docs = Object.freeze([]);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* How a fresh Linux runner gets this harness's REAL CLI — the install-contract lane installs
|
|
109
|
+
* it and proves `oathe init` against it: `{ npm, bin, versionArgs }` for an npm package,
|
|
110
|
+
* `{ installer, bin, versionArgs }` for a vendor install script, null when the harness has no
|
|
111
|
+
* CLI to install (its wiring is then our own file writes, pinned by the suite).
|
|
112
|
+
*/
|
|
113
|
+
static install = null;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The harness's one-shot (headless) run — what the live-behaviour lane drives to make a
|
|
117
|
+
* REAL session fire our hooks and leave a transcript: `{ auth, command, extract }` — the env
|
|
118
|
+
* vars its non-interactive mode authenticates with (pinned from the docs snapshot), the
|
|
119
|
+
* argv for a prompt, and the extraction of the model's text from stdout; null for none.
|
|
120
|
+
*/
|
|
121
|
+
static headless = null;
|
|
122
|
+
|
|
123
|
+
/** `--output-format json` on Claude Code and Cursor wraps the text in {result}. */
|
|
124
|
+
static extractJsonResult(stdout) {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(stdout).result ?? '';
|
|
127
|
+
} catch {
|
|
128
|
+
throw new Error('--output-format json did not return JSON');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Install the global fence when the adapter declares where it is read — through THE fence
|
|
134
|
+
* writer, recorded as a plain fence row (owner 'global') so `oathe uninstall` strips it
|
|
135
|
+
* exactly like a folder fence. Idempotent.
|
|
136
|
+
* @returns {Array<{action: string, file: string, changed: boolean}>}
|
|
137
|
+
*/
|
|
138
|
+
installGlobalFence({ manifest, version }) {
|
|
139
|
+
const files = this.constructor.globalContextFiles;
|
|
140
|
+
if (files.length === 0) return [];
|
|
141
|
+
const candidates = files.map((file) => path.join(this.configHome, file));
|
|
142
|
+
const target = candidates.find((file) => fs.existsSync(file)) ?? candidates.at(-1);
|
|
143
|
+
const { changed } = writeFence({
|
|
144
|
+
manifest, file: target, version, body: globalFenceBody(), scope: 'user', harness: 'global',
|
|
145
|
+
});
|
|
146
|
+
return [{ action: 'global-fence', file: target, changed }];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The plugin version this harness has CACHED for itself, or null when it keeps no
|
|
151
|
+
* version-keyed copy. A fact the doctor prints beside the package version — the code that
|
|
152
|
+
* runs is always the `oathe` bin on PATH; the cache holds manifests only.
|
|
153
|
+
* @returns {string|null}
|
|
154
|
+
*/
|
|
155
|
+
installedPluginVersion() {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The harness's config home (e.g. ~/.claude). */
|
|
160
|
+
get configHome() {
|
|
161
|
+
return this.constructor.configHomeFor(this.home, this.name);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The CLI names that count as this harness's CLI on PATH (subclasses may accept aliases). */
|
|
165
|
+
static get cliBins() {
|
|
166
|
+
return this.bin ? [this.bin] : [];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The adapter's OWN rule for "installed", over structured presence. Base: CLI and config home. */
|
|
170
|
+
static installedFrom(presence) {
|
|
171
|
+
return presence.cli && presence.configHome !== null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
binOnPath(bin) {
|
|
175
|
+
return this.envPath.split(':').filter(Boolean).some((dir) => {
|
|
176
|
+
try { fs.accessSync(path.join(dir, bin), fs.constants.X_OK); return true; } catch { return false; }
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* STRUCTURED detection: what is actually here — the app (GUI surfaces; null when the
|
|
182
|
+
* question does not apply), the CLI, the config home — and the adapter's own verdict on
|
|
183
|
+
* "installed" over those facts. Consumers pick the fact their capability needs (a headless
|
|
184
|
+
* run needs `cli`; wiring needs `configHome`), never the one bit.
|
|
185
|
+
* @returns {{name: string, presence: {app: boolean|null, cli: boolean, configHome: string|null}, installed: boolean}}
|
|
186
|
+
*/
|
|
187
|
+
detect() {
|
|
188
|
+
const cli = this.constructor.cliBins.some((bin) => this.binOnPath(bin));
|
|
189
|
+
const configHome = fs.existsSync(this.configHome) ? this.configHome : null;
|
|
190
|
+
const presence = { app: null, cli, configHome };
|
|
191
|
+
return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** What init will write for this harness, one line per file — from the SAME data onboard() writes. */
|
|
195
|
+
describe() {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @returns {Array<{name: string, installed: boolean, evidence: object}>} */
|
|
201
|
+
export function census(harnesses) {
|
|
202
|
+
return harnesses.map((h) => h.detect());
|
|
203
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// oathe — detect-only surfaces: places oathe can be USED but not WIRED by an installer. They are
|
|
2
|
+
// adapters like any other — same hierarchy, same structured detection, same docs pins — with
|
|
3
|
+
// `wiring: null` and a NOTE of manual steps instead of writes: detection plus honest
|
|
4
|
+
// instructions is the whole contract. (Cowork is a mode of the Claude Desktop app, running in a
|
|
5
|
+
// cloud sandbox; ChatGPT web has no local wiring at all — its desktop app rides the codex host.)
|
|
6
|
+
// Notes are dated: they describe the surfaces as pinned in .harness-docs.
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { Harness } from './harness.mjs';
|
|
12
|
+
|
|
13
|
+
export class CoworkSurface extends Harness {
|
|
14
|
+
static harnessName = 'cowork';
|
|
15
|
+
static displayName = 'Claude Cowork';
|
|
16
|
+
static clientNames = Object.freeze([]);
|
|
17
|
+
// The Claude Desktop app hosts Cowork (a mode beside Chat); its manual steps are dated
|
|
18
|
+
// against these pages, so the docs-drift lane names this surface when one changes.
|
|
19
|
+
static docs = Object.freeze([
|
|
20
|
+
'cowork/overview', 'cowork/projects', 'cowork/plugins', 'cowork/extensions', 'cowork/architecture',
|
|
21
|
+
'cowork/surfaces', 'cowork/use-plugins', 'claude-desktop/connect-local-servers',
|
|
22
|
+
]);
|
|
23
|
+
static note = [
|
|
24
|
+
'Claude desktop detected. Cowork sessions run in a cloud sandbox with a Linux-VM shell:',
|
|
25
|
+
'an attached folder\'s fence (AGENTS.md/CLAUDE.md) reaches them, but the local board —',
|
|
26
|
+
'MCP server, CLI, Postgres — does not (canary-confirmed 2026-08-28). Nothing to wire',
|
|
27
|
+
'today; a remote board surface is the tracked path.',
|
|
28
|
+
].join('\n');
|
|
29
|
+
|
|
30
|
+
constructor({ home, platform = process.platform, envPath = '', paths = null, exec } = {}) {
|
|
31
|
+
super({ name: 'cowork', home, envPath, paths, exec });
|
|
32
|
+
this.platform = platform;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static installedFrom(presence) {
|
|
36
|
+
return presence.app === true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
detect() {
|
|
40
|
+
const appSupport = path.join(this.home, 'Library/Application Support/Claude');
|
|
41
|
+
const app = this.platform === 'darwin' && (fs.existsSync('/Applications/Claude.app') || fs.existsSync(appSupport));
|
|
42
|
+
const presence = { app, cli: false, configHome: app ? appSupport : null };
|
|
43
|
+
return { name: this.name, presence, installed: this.constructor.installedFrom(presence) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class ChatGptWebSurface extends Harness {
|
|
48
|
+
static harnessName = 'chatgpt-web';
|
|
49
|
+
static displayName = 'ChatGPT web';
|
|
50
|
+
static clientNames = Object.freeze([]);
|
|
51
|
+
static docs = Object.freeze([]); // no local wiring, no page we depend on
|
|
52
|
+
static note = [
|
|
53
|
+
'ChatGPT web has no local wiring — remote MCP only. The ChatGPT desktop app shares the',
|
|
54
|
+
'codex host wiring above; from the web, use the oathe CLI verbs in a terminal against',
|
|
55
|
+
'the same board.',
|
|
56
|
+
].join('\n');
|
|
57
|
+
|
|
58
|
+
constructor({ home, platform = process.platform, envPath = '', paths = null, exec } = {}) {
|
|
59
|
+
super({ name: 'chatgpt-web', home, envPath, paths, exec });
|
|
60
|
+
this.platform = platform;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static installedFrom() {
|
|
64
|
+
return false; // nothing local marks ChatGPT web; listed for honesty, never auto-detected
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
detect() {
|
|
68
|
+
const presence = { app: null, cli: false, configHome: null };
|
|
69
|
+
return { name: this.name, presence, installed: false };
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/home.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// oathe — the home board (ruling R-HOME-BOARD, PLAN.md 2026-08-28). A task's board is the
|
|
2
|
+
// workspace of the EARLIEST claim that named a real folder; every later claim inherits it and
|
|
3
|
+
// never restamps it, so cross-surface pickup cannot drag a task off its repo's board. Tasks
|
|
4
|
+
// minted from a synthetic workspace (a ChatGPT-desktop staging dir) are HOMELESS until a real
|
|
5
|
+
// folder claims — adopts — them; a verification task lives wherever its parent lives.
|
|
6
|
+
//
|
|
7
|
+
// Home is DERIVED from the claim ledger, never stored: the DDL is frozen, and a stored copy
|
|
8
|
+
// would drift from the ledger it summarizes. This module is the ONE owner of the contract_ref
|
|
9
|
+
// grammar (`workspace:<ws-ref|none>;contract:<org>/<task>@v1`) in both JavaScript and SQL —
|
|
10
|
+
// nothing else in the tree builds, parses, or pattern-matches a contract_ref.
|
|
11
|
+
|
|
12
|
+
import { VERIFICATION_PREFIX, verifiedTaskId } from './plans.mjs';
|
|
13
|
+
|
|
14
|
+
/** The workspace token of a homeless claim — a real ref is always `ws-<12hex>`, never this. */
|
|
15
|
+
export const HOMELESS = 'none';
|
|
16
|
+
|
|
17
|
+
const CONTRACT_VERSION = 'v1';
|
|
18
|
+
const GRAMMAR = /^workspace:([^;]+);contract:([^/]+)\/(.+)@v1$/;
|
|
19
|
+
|
|
20
|
+
export class HomeError extends Error {
|
|
21
|
+
constructor(code, message, details = {}) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'HomeError';
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.details = details;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A claim's contract reference: the workspace it is homed on (null = homeless) + the contract. */
|
|
30
|
+
export class ContractRef {
|
|
31
|
+
/** @param {{workspace: string|null, orgId: string, taskId: string}} o */
|
|
32
|
+
constructor({ workspace, orgId, taskId }) {
|
|
33
|
+
this.workspace = workspace ?? null;
|
|
34
|
+
this.orgId = orgId;
|
|
35
|
+
this.taskId = taskId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @param {string} text @returns {ContractRef} @throws {HomeError} OATHE_CONTRACT_REF_MALFORMED */
|
|
39
|
+
static parse(text) {
|
|
40
|
+
const match = GRAMMAR.exec(String(text));
|
|
41
|
+
if (!match) {
|
|
42
|
+
throw new HomeError('OATHE_CONTRACT_REF_MALFORMED',
|
|
43
|
+
`contract_ref '${text}' does not follow workspace:<ws|${HOMELESS}>;contract:<org>/<task>@${CONTRACT_VERSION}`,
|
|
44
|
+
{ text });
|
|
45
|
+
}
|
|
46
|
+
const [, workspace, orgId, taskId] = match;
|
|
47
|
+
return new ContractRef({ workspace: workspace === HOMELESS ? null : workspace, orgId, taskId });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get isHomeless() {
|
|
51
|
+
return this.workspace === null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
toString() {
|
|
55
|
+
return `workspace:${this.workspace ?? HOMELESS};contract:${this.orgId}/${this.taskId}@${CONTRACT_VERSION}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The home derivation over the claim ledger. `of(taskId)` answers from the database; `homeSql`
|
|
61
|
+
* projects the same rule into a query so the board never re-implements it.
|
|
62
|
+
*/
|
|
63
|
+
export class HomeBoard {
|
|
64
|
+
/** @param {{client: {query: Function}, orgId: string}} o */
|
|
65
|
+
constructor({ client, orgId }) {
|
|
66
|
+
this.client = client;
|
|
67
|
+
this.orgId = orgId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The task whose ledger decides `taskId`'s home: itself, or its parent for a verification task. */
|
|
71
|
+
static anchorTaskId(taskId) {
|
|
72
|
+
return verifiedTaskId(taskId) ?? taskId;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The LIKE pattern every homeless claim matches — the sentinel, spelled once. */
|
|
76
|
+
static get homelessPattern() {
|
|
77
|
+
return `workspace:${HOMELESS};%`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* SQL scalar subquery: the home workspace ref (or NULL) of the task row aliased `taskAlias`.
|
|
82
|
+
* The verification-prefix anchor and the sentinel exclusion derive from the JS constants —
|
|
83
|
+
* one owner, two languages.
|
|
84
|
+
*/
|
|
85
|
+
static homeSql(taskAlias) {
|
|
86
|
+
const t = taskAlias;
|
|
87
|
+
return `(SELECT split_part(split_part(c.contract_ref, ';', 1), ':', 2)
|
|
88
|
+
FROM cell.work_claim c
|
|
89
|
+
WHERE c.org_id = ${t}.org_id
|
|
90
|
+
AND c.task_id = CASE WHEN ${t}.task_id LIKE '${VERIFICATION_PREFIX}%'
|
|
91
|
+
THEN substr(${t}.task_id, ${VERIFICATION_PREFIX.length + 1})
|
|
92
|
+
ELSE ${t}.task_id END
|
|
93
|
+
AND c.contract_ref NOT LIKE '${HomeBoard.homelessPattern}'
|
|
94
|
+
ORDER BY c.claimed_at ASC LIMIT 1)`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @returns {Promise<string|null>} the home workspace ref, or null when homeless/unclaimed */
|
|
98
|
+
async of(taskId) {
|
|
99
|
+
const { rows } = await this.client.query(
|
|
100
|
+
`SELECT split_part(split_part(contract_ref, ';', 1), ':', 2) AS workspace
|
|
101
|
+
FROM cell.work_claim
|
|
102
|
+
WHERE org_id = $1 AND task_id = $2 AND contract_ref NOT LIKE $3
|
|
103
|
+
ORDER BY claimed_at ASC LIMIT 1`,
|
|
104
|
+
[this.orgId, HomeBoard.anchorTaskId(taskId), HomeBoard.homelessPattern]);
|
|
105
|
+
return rows[0]?.workspace ?? null;
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/init.mjs
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
|
-
// oathe init — census → substrate →
|
|
2
|
-
//
|
|
3
|
-
// is
|
|
1
|
+
// oathe init — census → plan → (substrate reachable?) → ask everything → do everything → summary.
|
|
2
|
+
// The order is the promise: the questions come from the census and each adapter's own
|
|
3
|
+
// description of its writes (src/setup.mjs); nothing is asked of a world whose substrate cannot
|
|
4
|
+
// come up; nothing is written before the last answer; nothing is recorded that was not
|
|
5
|
+
// verified. On a TTY the plan is a conversation; with --yes or off-TTY the plan's defaults are
|
|
6
|
+
// applied and ANNOUNCED — never a silent assumption, never a hang.
|
|
4
7
|
|
|
5
8
|
import { buildContext } from './context.mjs';
|
|
6
|
-
import { census } from './
|
|
9
|
+
import { census, detectOnlySurfaces } from './harnesses/catalog.mjs';
|
|
10
|
+
import { OatheConfig } from './config.mjs';
|
|
7
11
|
import { standardPlan } from './plans.mjs';
|
|
12
|
+
import { OatheInitError, SetupPlan, SetupPrompter } from './setup.mjs';
|
|
8
13
|
|
|
9
|
-
export
|
|
10
|
-
constructor(code, message, details = {}) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = 'OatheInitError';
|
|
13
|
-
this.code = code;
|
|
14
|
-
this.details = details;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
14
|
+
export { OatheInitError };
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
|
-
* @returns {Promise<{census: object[],
|
|
17
|
+
* @returns {Promise<{plan: SetupPlan, census: object[], surfaces: object[], substrate: object,
|
|
18
|
+
* principal: object, verifier: object, verifier_engine: object, wired: string[],
|
|
19
|
+
* actions: object[], steps: object[]}>}
|
|
20
20
|
*/
|
|
21
|
-
export async function runInit({
|
|
21
|
+
export async function runInit({
|
|
22
|
+
env = process.env, exec, stdin = process.stdin, out = process.stdout, err = process.stderr,
|
|
23
|
+
harnessFilter = null, assumeYes = false,
|
|
24
|
+
} = {}) {
|
|
22
25
|
const ctx = buildContext({ env, exec });
|
|
23
26
|
const { manifest, harnesses, substrate, identity, version } = ctx;
|
|
24
27
|
try {
|
|
25
|
-
const
|
|
28
|
+
const wired = harnesses.filter((h) => h.constructor.wiring !== null);
|
|
29
|
+
const seen = census(wired); // what an installer can wire
|
|
30
|
+
const surfaces = detectOnlySurfaces({ home: ctx.home });
|
|
31
|
+
// The verifier is a MACHINE-WIDE choice: only the global layer decides whether it was made.
|
|
32
|
+
// A per-folder .oathe.json in the cwd init runs from must not silence the question (it did,
|
|
33
|
+
// 2026-08-29).
|
|
34
|
+
const machine = OatheConfig.global({ env: ctx.config.env });
|
|
35
|
+
// DECLARATIVE: the screen shows the wiring state and Enter makes the machine match it.
|
|
36
|
+
const wiredNow = new Set(manifest.rows.map((r) => r.harness).filter((h) => wired.some((a) => a.name === h)));
|
|
37
|
+
const plan = SetupPlan.from({
|
|
38
|
+
adapters: wired, census: seen, surfaces, machine, home: ctx.home, paths: ctx.paths, fallbackVerifier: ctx.config.get('verifier'), wiredNow,
|
|
39
|
+
});
|
|
40
|
+
if (harnessFilter) plan.narrow(harnessFilter);
|
|
26
41
|
|
|
42
|
+
// The substrate is checked BEFORE any question: nobody answers a setup that cannot come up.
|
|
27
43
|
const detect = await substrate.detect();
|
|
28
44
|
if (!detect.reachable) {
|
|
29
45
|
throw new OatheInitError('OATHE_SUBSTRATE_UNREACHABLE',
|
|
@@ -39,7 +55,27 @@ export async function runInit({ env = process.env, exec } = {}) {
|
|
|
39
55
|
// Same preflight block as detect(): a missing DDL source is caught here too, before any
|
|
40
56
|
// database is created — never a half-onboarded world.
|
|
41
57
|
substrate.assertDdlSource();
|
|
42
|
-
|
|
58
|
+
|
|
59
|
+
// Ask everything…
|
|
60
|
+
if (assumeYes) plan.applyDefaults('assume-yes');
|
|
61
|
+
else if (SetupPrompter.isInteractive({ stdin, out })) await new SetupPrompter({ stdin, out }).ask(plan);
|
|
62
|
+
else plan.applyDefaults('no-tty');
|
|
63
|
+
if (plan.defaultsReason !== null) {
|
|
64
|
+
const label = { 'assume-yes': '--yes', 'no-tty': 'no TTY' }[plan.defaultsReason] ?? plan.defaultsReason;
|
|
65
|
+
const stream = assumeYes ? out : err; // --yes was asked for: stdout; a pipe hears it on stderr
|
|
66
|
+
stream?.write?.(`init: ${label} — applying defaults: ${plan.announceLines().join('; ')}\n`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// …then do everything.
|
|
70
|
+
const db = await substrate.ensureDatabase();
|
|
71
|
+
// A database made for the FIRST time plants the one-shot welcome — the glass plays it
|
|
72
|
+
// on its next frame. Planted here, not with the actions: a failed later step must not
|
|
73
|
+
// cost the eventual successful init its welcome.
|
|
74
|
+
let welcomePlanted = null;
|
|
75
|
+
if (db.created) {
|
|
76
|
+
const { plantWelcome } = await import('./welcome.mjs');
|
|
77
|
+
welcomePlanted = plantWelcome({ paths: ctx.paths });
|
|
78
|
+
}
|
|
43
79
|
await substrate.applyDdl();
|
|
44
80
|
await substrate.seed({
|
|
45
81
|
orgId: identity.orgId, principalId: identity.principalId, department: identity.department,
|
|
@@ -66,25 +102,69 @@ export async function runInit({ env = process.env, exec } = {}) {
|
|
|
66
102
|
registeredBy: 'oathe-init',
|
|
67
103
|
});
|
|
68
104
|
|
|
105
|
+
const v = plan.verifier;
|
|
106
|
+
// Record when there was no machine-wide choice, or the screen changed it — re-running init IS the switch.
|
|
107
|
+
const record = v.alreadyChosen === null || v.chosen !== v.alreadyChosen.value;
|
|
108
|
+
if (record) ctx.config.set('verifier', v.chosen, { scope: 'global' });
|
|
109
|
+
const a = plan.agent;
|
|
110
|
+
if (a.chosen !== null && (a.alreadyChosen === null || a.chosen !== a.alreadyChosen.value)) {
|
|
111
|
+
ctx.config.set('defaultAgent', a.chosen, { scope: 'global' });
|
|
112
|
+
}
|
|
113
|
+
|
|
69
114
|
const actions = [];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
if (welcomePlanted) actions.push({ harness: 'notch', action: 'welcome-planted', file: welcomePlanted.file });
|
|
116
|
+
// The screen's unchecks first: unwire exactly those harnesses through their own offboard.
|
|
117
|
+
// (The codex global fence rides uninstall, not a per-harness unwire.)
|
|
118
|
+
for (const name of plan.toUnwire) {
|
|
119
|
+
const harness = wired.find((h) => h.name === name);
|
|
120
|
+
const files = new Set(manifest.rows.filter((r) => r.harness === name).map((r) => r.file));
|
|
121
|
+
for (const action of harness.offboard({ manifest })) actions.push({ harness: name, ...action });
|
|
122
|
+
const { sweepCreatedResidue } = await import('./blocks.mjs');
|
|
123
|
+
for (const action of sweepCreatedResidue({ backups: manifest.backups.filter((b) => files.has(b.file)) })) {
|
|
124
|
+
actions.push({ harness: name, ...action });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const step of plan.steps) {
|
|
128
|
+
if (!step.installed) {
|
|
129
|
+
actions.push({ harness: step.name, action: 'skipped-not-installed' });
|
|
74
130
|
continue;
|
|
75
131
|
}
|
|
76
|
-
|
|
132
|
+
if (step.selected !== true) {
|
|
133
|
+
actions.push({ harness: step.name, action: plan.toUnwire.includes(step.name) ? 'unwired' : 'skipped-not-selected' });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const harness = wired.find((h) => h.name === step.name);
|
|
137
|
+
for (const action of [...harness.onboard({ manifest, version }), ...harness.installGlobalFence({ manifest, version })]) {
|
|
77
138
|
actions.push({ harness: harness.name, ...action });
|
|
78
139
|
}
|
|
79
140
|
}
|
|
141
|
+
// The notch (the quiet glass): shipped with the package for everyone — the packaged
|
|
142
|
+
// app is the default, notchApp the override, a missing build a stated fact.
|
|
143
|
+
const { wireNotch } = await import('./notch.mjs');
|
|
144
|
+
for (const action of wireNotch({ home: ctx.home, manifest, config: ctx.config, version, packageRoot: ctx.paths.packageRoot, ...(exec ? { exec } : {}) })) {
|
|
145
|
+
actions.push({ harness: 'notch', ...action });
|
|
146
|
+
}
|
|
80
147
|
manifest.save();
|
|
81
148
|
|
|
82
149
|
return {
|
|
150
|
+
plan,
|
|
83
151
|
census: seen,
|
|
152
|
+
surfaces,
|
|
84
153
|
substrate: await substrate.status(),
|
|
85
154
|
principal: { org_id: identity.orgId, principal_id: identity.principalId, role: 'ceo' },
|
|
86
155
|
verifier: { principal_id: verifierPrincipal, seats },
|
|
156
|
+
verifier_engine: {
|
|
157
|
+
chosen: v.chosen,
|
|
158
|
+
candidates: v.candidates,
|
|
159
|
+
asked: v.asked,
|
|
160
|
+
recorded: record,
|
|
161
|
+
reason: v.alreadyChosen
|
|
162
|
+
? `already chosen machine-wide (${v.alreadyChosen.file}); switch with \`oathe config verifier <name> --global\``
|
|
163
|
+
: null,
|
|
164
|
+
},
|
|
165
|
+
wired: plan.wired,
|
|
87
166
|
actions,
|
|
167
|
+
steps: plan.outcomes(actions),
|
|
88
168
|
};
|
|
89
169
|
} finally {
|
|
90
170
|
await substrate.close();
|
package/src/launch-env.mjs
CHANGED
|
@@ -4,59 +4,9 @@
|
|
|
4
4
|
// and everything plugin-side asks ONE predicate before touching the substrate. Named once here:
|
|
5
5
|
// the launcher writes the block, the hooks and the server read it.
|
|
6
6
|
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
|
|
10
7
|
export const LAUNCHED_HARNESS_ENV = 'OATHE_LAUNCHED_HARNESS';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
// children (Claude Code). Codex builds MCP child environments from its own config, so the
|
|
14
|
-
// marker dies at that boundary — the SESSION MARKER FILE is the harness-agnostic transport:
|
|
15
|
-
// the launcher writes <oatheHome>/launched/<workspace>.<pid>.json while it supervises, the
|
|
16
|
-
// gate honors any marker for its workspace whose supervisor is still alive, and teardown
|
|
17
|
-
// (or the supervisor dying) retires it. Stale markers fail the liveness probe and are inert.
|
|
18
|
-
|
|
19
|
-
export function sessionMarkerPath(oatheHome, workspace, pid = process.pid) {
|
|
20
|
-
return path.join(oatheHome, 'launched', `${workspace}.${pid}.json`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** @returns {string} the marker file path (hand it to clearSessionMarker at teardown).
|
|
24
|
-
* `wiring` is the launchSessionEnv block: harnesses that strip the environment on the way
|
|
25
|
-
* to their MCP children (Codex) get it back from here, identity included. */
|
|
26
|
-
export function writeSessionMarker({ oatheHome, workspace, harness, cwd, wiring = {}, pid = process.pid }) {
|
|
27
|
-
const file = sessionMarkerPath(oatheHome, workspace, pid);
|
|
28
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
29
|
-
fs.writeFileSync(file, `${JSON.stringify({
|
|
30
|
-
harness, supervisor_pid: pid, cwd, wiring, started_at: new Date().toISOString(),
|
|
31
|
-
})}\n`);
|
|
32
|
-
return file;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function clearSessionMarker(file) {
|
|
36
|
-
fs.rmSync(file, { force: true });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** The full LIVE launch marker for this workspace ({harness, wiring, …}), or null.
|
|
40
|
-
* Dead and unreadable markers are retired on sight. */
|
|
41
|
-
export function liveSessionMarker({ oatheHome, workspace }) {
|
|
42
|
-
const dir = path.join(oatheHome, 'launched');
|
|
43
|
-
let names;
|
|
44
|
-
try { names = fs.readdirSync(dir); } catch { return null; }
|
|
45
|
-
for (const name of names) {
|
|
46
|
-
if (!name.startsWith(`${workspace}.`) || !name.endsWith('.json')) continue;
|
|
47
|
-
const file = path.join(dir, name);
|
|
48
|
-
try {
|
|
49
|
-
const marker = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
50
|
-
process.kill(marker.supervisor_pid, 0); // throws when the supervisor is gone
|
|
51
|
-
return marker;
|
|
52
|
-
} catch {
|
|
53
|
-
fs.rmSync(file, { force: true }); // stale or unreadable: retire it
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** The harness ('claude' | 'codex') that launched this session, or null when unlaunched. */
|
|
9
|
+
/** The name of the launch-capable harness (catalog `launchable()`) that launched this session, or null when unlaunched. */
|
|
60
10
|
export function launchedHarness(env = process.env) {
|
|
61
11
|
const value = String(env[LAUNCHED_HARNESS_ENV] ?? '').trim();
|
|
62
12
|
return value === '' ? null : value;
|