@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
package/src/setup.mjs
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
// oathe init as DATA. A SetupPlan is everything the machine owner is asked and everything init
|
|
2
|
+
// will do: one step per wiring adapter, each step's "what yes writes" taken from the adapter's
|
|
3
|
+
// own describe() (the same data its onboard() writes — the prompt cannot promise what the
|
|
4
|
+
// write does not do), the verifier candidates from the census (headless-capable AND the CLI is
|
|
5
|
+
// here), the detect-only surfaces as explanations. A SetupPrompter renders the plan on a TTY:
|
|
6
|
+
// one explained yes/no per installed harness, the verifier by NAME, Enter = default, an
|
|
7
|
+
// unrecognized answer refused and re-asked. --yes and no-TTY apply the plan's defaults to the
|
|
8
|
+
// SAME plan and announce them. Nothing in this file writes anything. The rules every line here
|
|
9
|
+
// follows are docs/UX.md; tests/setup.test.mjs holds them.
|
|
10
|
+
|
|
11
|
+
import { launchable, verifiers } from './harnesses/catalog.mjs';
|
|
12
|
+
|
|
13
|
+
export class OatheInitError extends Error {
|
|
14
|
+
constructor(code, message, details = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'OatheInitError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.details = details;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `~` for the home prefix — every path a person reads in a prompt or a summary. */
|
|
23
|
+
export function tilde(text, home) {
|
|
24
|
+
return home ? String(text).split(home).join('~') : String(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Why a step was skipped, as a sentence for people — never the token. */
|
|
28
|
+
const SKIP_REASONS = Object.freeze({
|
|
29
|
+
'not-installed': 'not installed',
|
|
30
|
+
'not-wired': 'not wired',
|
|
31
|
+
'harness-filter': 'not named by --harness',
|
|
32
|
+
answered: 'you said no',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export class SetupStep {
|
|
36
|
+
constructor({ name, displayName, covers, wired = false, presence, installed, writes, configHome, cliBins }) {
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.displayName = displayName;
|
|
39
|
+
this.covers = covers;
|
|
40
|
+
this.wired = wired;
|
|
41
|
+
this.presence = presence;
|
|
42
|
+
this.installed = installed;
|
|
43
|
+
this.writes = writes;
|
|
44
|
+
this.configHome = configHome;
|
|
45
|
+
this.cliBins = cliBins;
|
|
46
|
+
/** null = unanswered; a harness that is not here is never a question. */
|
|
47
|
+
this.selected = installed ? null : false;
|
|
48
|
+
this.reason = installed ? null : 'not-installed';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
decide(selected, reason) {
|
|
52
|
+
this.selected = selected;
|
|
53
|
+
this.reason = reason;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Presence as facts: what was found — or, when nothing was, what was looked for. */
|
|
57
|
+
presenceLine(home) {
|
|
58
|
+
const found = [];
|
|
59
|
+
if (this.presence.app === true) found.push('app installed');
|
|
60
|
+
if (this.presence.cli) found.push('CLI on PATH');
|
|
61
|
+
if (this.presence.configHome) found.push(`config at ${tilde(this.presence.configHome, home)}`);
|
|
62
|
+
if (this.installed) {
|
|
63
|
+
const noCli = !this.presence.cli && this.cliBins.length > 0 ? ` (no ${this.cliBins.join('/')} on PATH)` : '';
|
|
64
|
+
return `found: ${found.join(', ')}${noCli}`;
|
|
65
|
+
}
|
|
66
|
+
const lookedFor = [];
|
|
67
|
+
if (this.cliBins.length > 0) lookedFor.push(`no ${this.cliBins.join('/')} on PATH`);
|
|
68
|
+
lookedFor.push(`no ${tilde(this.configHome, home)}`);
|
|
69
|
+
return `not found (${lookedFor.join(', ')})`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class SetupPlan {
|
|
74
|
+
constructor({ home, fresh = true, configPath, manifestPath, steps, verifier, agent, surfaces }) {
|
|
75
|
+
this.home = home;
|
|
76
|
+
/** No wiring exists yet — the screen defaults everything detected ON; else it shows the state. */
|
|
77
|
+
this.fresh = fresh;
|
|
78
|
+
this.configPath = configPath;
|
|
79
|
+
this.manifestPath = manifestPath;
|
|
80
|
+
this.steps = steps;
|
|
81
|
+
this.verifier = verifier;
|
|
82
|
+
this.agent = agent;
|
|
83
|
+
this.surfaces = surfaces;
|
|
84
|
+
/** Set when defaults were applied instead of answers: 'assume-yes' | 'no-tty' | … */
|
|
85
|
+
this.defaultsReason = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {{adapters: object[], census: object[], surfaces: object[], machine: import('./config.mjs').OatheConfig,
|
|
90
|
+
* home: string, paths: {manifestPath: string}, fallbackVerifier: string}} o — `machine` is the GLOBAL config layer: the
|
|
91
|
+
* verifier is a machine-wide choice, and only that layer says whether it was made.
|
|
92
|
+
*/
|
|
93
|
+
static from({ adapters, census, surfaces, machine, home, paths, fallbackVerifier, wiredNow = new Set() }) {
|
|
94
|
+
const steps = adapters.map((adapter) => {
|
|
95
|
+
const seen = census.find((c) => c.name === adapter.name);
|
|
96
|
+
return new SetupStep({
|
|
97
|
+
name: adapter.name,
|
|
98
|
+
displayName: adapter.constructor.displayName,
|
|
99
|
+
covers: adapter.constructor.covers,
|
|
100
|
+
wired: wiredNow.has(adapter.name),
|
|
101
|
+
presence: seen.presence,
|
|
102
|
+
installed: seen.installed,
|
|
103
|
+
writes: adapter.describe(),
|
|
104
|
+
configHome: adapter.configHome,
|
|
105
|
+
cliBins: adapter.constructor.cliBins,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
const candidates = verifiers(census);
|
|
109
|
+
const alreadyChosen = machine.source('verifier') !== 'default'
|
|
110
|
+
? { value: machine.get('verifier'), file: machine.globalPath }
|
|
111
|
+
: null;
|
|
112
|
+
const fresh = wiredNow.size === 0;
|
|
113
|
+
const verifier = {
|
|
114
|
+
candidates,
|
|
115
|
+
default: candidates[0] ?? fallbackVerifier,
|
|
116
|
+
alreadyChosen,
|
|
117
|
+
chosen: alreadyChosen?.value ?? null,
|
|
118
|
+
asked: false,
|
|
119
|
+
};
|
|
120
|
+
// The default agent (who picks your work back up — the notch's continue): the same
|
|
121
|
+
// question shape as the verifier, asked ABOVE it (founder ruling 2026-08-30).
|
|
122
|
+
const agentCandidates = launchable().filter((n) => census.find((c) => c.name === n)?.installed);
|
|
123
|
+
const agentChosen = machine.source('defaultAgent') !== 'default'
|
|
124
|
+
? { value: machine.get('defaultAgent'), file: machine.globalPath }
|
|
125
|
+
: null;
|
|
126
|
+
const agent = {
|
|
127
|
+
candidates: agentCandidates,
|
|
128
|
+
default: agentCandidates[0] ?? null,
|
|
129
|
+
alreadyChosen: agentChosen,
|
|
130
|
+
chosen: agentChosen?.value ?? null,
|
|
131
|
+
asked: false,
|
|
132
|
+
};
|
|
133
|
+
return new SetupPlan({
|
|
134
|
+
home,
|
|
135
|
+
fresh,
|
|
136
|
+
configPath: machine.globalPath,
|
|
137
|
+
manifestPath: paths.manifestPath,
|
|
138
|
+
steps,
|
|
139
|
+
verifier,
|
|
140
|
+
agent,
|
|
141
|
+
surfaces: surfaces.filter((s) => s.detected)
|
|
142
|
+
.map((s) => ({ name: s.name, displayName: s.displayName, detected: true, note: s.steps })),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
step(name) {
|
|
147
|
+
return this.steps.find((s) => s.name === name);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** --harness a,b: exactly the named — an unknown name or one not on this machine is a refusal. */
|
|
151
|
+
narrow(names) {
|
|
152
|
+
const wireable = this.steps.map((s) => s.name);
|
|
153
|
+
const unknown = names.filter((n) => !wireable.includes(n));
|
|
154
|
+
if (unknown.length > 0) {
|
|
155
|
+
throw new OatheInitError('OATHE_INIT_HARNESS_UNKNOWN',
|
|
156
|
+
`--harness names ${unknown.join(', ')} — init wires: ${wireable.join(', ')}`, { unknown });
|
|
157
|
+
}
|
|
158
|
+
const absent = names.filter((n) => !this.step(n).installed);
|
|
159
|
+
if (absent.length > 0) {
|
|
160
|
+
throw new OatheInitError('OATHE_INIT_HARNESS_ABSENT',
|
|
161
|
+
`--harness names ${absent.map((n) => `${n}, which is ${this.step(n).presenceLine(this.home)}`).join('; ')}`
|
|
162
|
+
+ ' — nothing to wire; install it first or drop it from --harness', { absent });
|
|
163
|
+
}
|
|
164
|
+
for (const step of this.steps.filter((s) => s.installed)) step.decide(names.includes(step.name), 'harness-filter');
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Answer every open question with its default — the CURRENT state (a fresh machine: all on). Never unwires. */
|
|
169
|
+
applyDefaults(reason) {
|
|
170
|
+
for (const step of this.steps) {
|
|
171
|
+
if (!step.installed || step.selected !== null) continue;
|
|
172
|
+
if (this.fresh || step.wired) step.decide(true, reason);
|
|
173
|
+
else step.decide(false, 'not-wired');
|
|
174
|
+
}
|
|
175
|
+
if (this.verifier.chosen === null) this.verifier.chosen = this.verifier.default;
|
|
176
|
+
if (this.agent.chosen === null) this.agent.chosen = this.agent.default;
|
|
177
|
+
this.defaultsReason = reason;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get wired() {
|
|
182
|
+
return this.steps.filter((s) => s.selected === true).map((s) => s.name);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The wired harnesses the SCREEN unchecked — the only path that unwires (--yes/--harness never do). */
|
|
186
|
+
get toUnwire() {
|
|
187
|
+
return this.steps.filter((s) => s.wired && s.selected === false && s.reason === 'answered').map((s) => s.name);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
get answered() {
|
|
191
|
+
return this.steps.every((s) => s.selected !== null) && this.verifier.chosen !== null
|
|
192
|
+
&& (this.agent.chosen !== null || this.agent.candidates.length === 0);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** What was applied, one clause each — the line --yes and no-TTY print. */
|
|
196
|
+
announceLines() {
|
|
197
|
+
const lines = [];
|
|
198
|
+
if (this.wired.length > 0) lines.push(`wire: ${this.wired.join(', ')}`);
|
|
199
|
+
const skipped = new Map();
|
|
200
|
+
for (const s of this.steps.filter((x) => x.selected === false)) {
|
|
201
|
+
const why = SKIP_REASONS[s.reason] ?? s.reason;
|
|
202
|
+
skipped.set(why, [...(skipped.get(why) ?? []), s.name]);
|
|
203
|
+
}
|
|
204
|
+
for (const [why, names] of skipped) lines.push(`skip: ${names.join(', ')} (${why})`);
|
|
205
|
+
if (this.agent.chosen !== null) {
|
|
206
|
+
lines.push(`default agent: ${this.agent.chosen}${this.agent.alreadyChosen ? ' (already chosen machine-wide)' : ''}`);
|
|
207
|
+
}
|
|
208
|
+
lines.push(`verifier: ${this.verifier.chosen}${this.verifier.alreadyChosen ? ' (already chosen machine-wide)' : ''}`);
|
|
209
|
+
return lines;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The plan plus what landed: one row per step, files under ~, reasons as sentences. */
|
|
213
|
+
outcomes(actions) {
|
|
214
|
+
return this.steps.map((step) => {
|
|
215
|
+
const mine = actions.filter((a) => a.harness === step.name && !/^skipped/.test(a.action));
|
|
216
|
+
const files = [...new Set(mine.filter((a) => a.file).map((a) => tilde(a.file, this.home)))];
|
|
217
|
+
const landed = files.length > 0 ? files : mine.map((a) => a.action);
|
|
218
|
+
if (step.selected === true) return { name: step.name, displayName: step.displayName, outcome: 'wired', reason: null, landed };
|
|
219
|
+
if (this.toUnwire.includes(step.name)) return { name: step.name, displayName: step.displayName, outcome: 'unwired', reason: null, landed };
|
|
220
|
+
return { name: step.name, displayName: step.displayName, outcome: 'skipped', reason: SKIP_REASONS[step.reason] ?? step.reason, landed: [] };
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ------------------------------------------------------------------ the one-screen checklist
|
|
226
|
+
// Raw-mode keys, plain ANSI, no TUI dependency. Every detected harness is a pre-selected row;
|
|
227
|
+
// ↑↓ move, space toggles, the verifier is a radio row (← →), Enter installs the selection —
|
|
228
|
+
// one keypress for the common case (docs/UX.md rule 1). Nothing here writes anything.
|
|
229
|
+
|
|
230
|
+
const ANSI = Object.freeze({
|
|
231
|
+
dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m', hide: '\x1b[?25l', show: '\x1b[?25h',
|
|
232
|
+
up: (n) => `\x1b[${n}A`, clear: '\x1b[J',
|
|
233
|
+
});
|
|
234
|
+
const LEGEND = '↑↓ move · space toggle · enter install';
|
|
235
|
+
const OPENING = 'oathe init — reversible (oathe uninstall)';
|
|
236
|
+
|
|
237
|
+
const KEY_NAMES = Object.freeze({
|
|
238
|
+
'\x1b[A': 'up', '\x1bOA': 'up', k: 'up',
|
|
239
|
+
'\x1b[B': 'down', '\x1bOB': 'down', j: 'down',
|
|
240
|
+
'\x1b[C': 'right', '\x1bOC': 'right', l: 'right',
|
|
241
|
+
'\x1b[D': 'left', '\x1bOD': 'left', h: 'left',
|
|
242
|
+
' ': 'toggle', '\r': 'enter', '\n': 'enter',
|
|
243
|
+
'\x03': 'abort', q: 'abort', '\x1b': 'abort',
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
/** Raw bytes → key names; a chunk may carry several keys (a paste, a piped line); unknown bytes do nothing (rule 5). */
|
|
247
|
+
export function decodeKeys(chunk) {
|
|
248
|
+
const text = String(chunk);
|
|
249
|
+
const keys = [];
|
|
250
|
+
for (let at = 0; at < text.length;) {
|
|
251
|
+
if (text[at] === '\x1b' && (text[at + 1] === '[' || text[at + 1] === 'O') && at + 2 < text.length) {
|
|
252
|
+
const name = KEY_NAMES[text.slice(at, at + 3)];
|
|
253
|
+
if (name) keys.push(name);
|
|
254
|
+
at += 3;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const name = KEY_NAMES[text[at]];
|
|
258
|
+
if (name) keys.push(name);
|
|
259
|
+
at += 1;
|
|
260
|
+
}
|
|
261
|
+
return keys;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
class SetupScreen {
|
|
265
|
+
constructor(plan, { columns }) {
|
|
266
|
+
this.plan = plan;
|
|
267
|
+
this.columns = columns;
|
|
268
|
+
this.t = (x) => tilde(x, plan.home);
|
|
269
|
+
// The live picks: only steps the plan has not already decided (installed and unanswered).
|
|
270
|
+
this.picks = new Map(plan.steps.filter((s) => s.installed && s.selected === null).map((s) => [s.name, plan.fresh || s.wired]));
|
|
271
|
+
const v = plan.verifier;
|
|
272
|
+
this.radio = v.candidates.length > 1; // a recorded choice PRESETS the radio — re-running init is how you change it
|
|
273
|
+
this.verifierAt = Math.max(0, v.candidates.indexOf(
|
|
274
|
+
v.alreadyChosen !== null && v.candidates.includes(v.alreadyChosen.value) ? v.alreadyChosen.value : v.default));
|
|
275
|
+
const a = plan.agent;
|
|
276
|
+
this.agentRadio = a.candidates.length > 1;
|
|
277
|
+
this.agentAt = Math.max(0, a.candidates.indexOf(
|
|
278
|
+
a.alreadyChosen !== null && a.candidates.includes(a.alreadyChosen.value) ? a.alreadyChosen.value : a.default));
|
|
279
|
+
// The rows the cursor can reach: toggleable steps, then the agent, then the verifier
|
|
280
|
+
// (the agent question sits ABOVE the verifier — founder ruling 2026-08-30).
|
|
281
|
+
this.movable = [
|
|
282
|
+
...plan.steps.filter((s) => this.picks.has(s.name)).map((s) => ({ kind: 'step', step: s })),
|
|
283
|
+
...(this.agentRadio ? [{ kind: 'agent' }] : []),
|
|
284
|
+
...(this.radio ? [{ kind: 'verifier' }] : []),
|
|
285
|
+
];
|
|
286
|
+
this.cursor = 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
get current() {
|
|
290
|
+
return this.movable[this.cursor] ?? null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
move(delta) {
|
|
294
|
+
if (this.movable.length > 0) this.cursor = (this.cursor + delta + this.movable.length) % this.movable.length;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
toggle() {
|
|
298
|
+
const row = this.current;
|
|
299
|
+
if (!row) return;
|
|
300
|
+
if (row.kind === 'step') this.picks.set(row.step.name, !this.picks.get(row.step.name));
|
|
301
|
+
else this.cycle(1);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
cycle(delta) {
|
|
305
|
+
if (this.current?.kind === 'agent') {
|
|
306
|
+
const n = this.plan.agent.candidates.length;
|
|
307
|
+
this.agentAt = (this.agentAt + delta + n) % n;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (this.current?.kind !== 'verifier') return;
|
|
311
|
+
const n = this.plan.verifier.candidates.length;
|
|
312
|
+
this.verifierAt = (this.verifierAt + delta + n) % n;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
#stepRow(step) {
|
|
316
|
+
const label = step.displayName.padEnd(12);
|
|
317
|
+
if (!step.installed) return { text: ` ${label} ${step.presenceLine(this.plan.home)}`, fixed: true, step };
|
|
318
|
+
const covers = `(${step.covers})`;
|
|
319
|
+
if (this.picks.has(step.name)) {
|
|
320
|
+
return { text: `[${this.picks.get(step.name) ? 'x' : ' '}] ${label} ${covers}`, fixed: false, step };
|
|
321
|
+
}
|
|
322
|
+
const why = step.selected === true ? '(--harness)' : (SKIP_REASONS[step.reason] ?? step.reason);
|
|
323
|
+
return { text: `[${step.selected === true ? 'x' : ' '}] ${label} ${covers} ${why}`, fixed: true, step };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#agentRow() {
|
|
327
|
+
const a = this.plan.agent;
|
|
328
|
+
const label = 'default agent'.padEnd(12);
|
|
329
|
+
if (a.candidates.length === 0) return null; // no launchable agent installed — not a question
|
|
330
|
+
if (a.candidates.length === 1) {
|
|
331
|
+
return { text: ` ${label} ${a.candidates[0]}`, fixed: true };
|
|
332
|
+
}
|
|
333
|
+
const radio = a.candidates.map((c, i) => `(${i === this.agentAt ? '•' : ' '}) ${c}`).join(' ');
|
|
334
|
+
return {
|
|
335
|
+
text: ` ${label} ${radio}`,
|
|
336
|
+
fixed: false,
|
|
337
|
+
kind: 'agent',
|
|
338
|
+
hint: '← → choose · who picks your work back up (the notch\'s continue opens this agent)',
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#verifierRow() {
|
|
343
|
+
const v = this.plan.verifier;
|
|
344
|
+
const label = 'verifier'.padEnd(12);
|
|
345
|
+
if (v.candidates.length <= 1) {
|
|
346
|
+
return { text: ` ${label} ${v.candidates[0] ?? v.default}`, fixed: true };
|
|
347
|
+
}
|
|
348
|
+
const radio = v.candidates.map((c, i) => `(${i === this.verifierAt ? '•' : ' '}) ${c}`).join(' ');
|
|
349
|
+
return {
|
|
350
|
+
text: ` ${label} ${radio}`,
|
|
351
|
+
fixed: false,
|
|
352
|
+
kind: 'verifier',
|
|
353
|
+
hint: '← → choose · judges finished work in a fresh headless run under a non-author seat; tip: the one you use less',
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
rows() {
|
|
358
|
+
return [
|
|
359
|
+
...this.plan.steps.map((s) => this.#stepRow(s)),
|
|
360
|
+
...this.plan.surfaces.map((s) => ({ text: ` ${s.displayName.padEnd(12)} detected — nothing to wire`, fixed: true })),
|
|
361
|
+
...(this.#agentRow() ? [this.#agentRow()] : []),
|
|
362
|
+
this.#verifierRow(),
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#fit(text) {
|
|
367
|
+
return text.length >= this.columns ? `${text.slice(0, this.columns - 2)}…` : text;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** The live screen: opening, legend, rows with the cursor, the highlighted row's full writes. */
|
|
371
|
+
render() {
|
|
372
|
+
const cur = this.current;
|
|
373
|
+
const lines = [OPENING, ` ${ANSI.dim}${LEGEND}${ANSI.reset}`, ''];
|
|
374
|
+
for (const row of this.rows()) {
|
|
375
|
+
const here = cur !== null
|
|
376
|
+
&& ((cur.kind === 'step' && row.step === cur.step) || (row.kind !== undefined && row.kind === cur.kind));
|
|
377
|
+
const body = this.#fit(row.text);
|
|
378
|
+
lines.push(here ? `${ANSI.bold}› ${body}${ANSI.reset}` : row.fixed ? `${ANSI.dim} ${body}${ANSI.reset}` : ` ${body}`);
|
|
379
|
+
}
|
|
380
|
+
lines.push('');
|
|
381
|
+
if (cur?.kind === 'step') for (const w of cur.step.writes) lines.push(` ${ANSI.dim}${this.#fit(this.t(w))}${ANSI.reset}`);
|
|
382
|
+
if (cur?.kind === 'verifier') lines.push(` ${ANSI.dim}${this.#fit(this.rows().at(-1).hint)}${ANSI.reset}`);
|
|
383
|
+
return lines;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** What stays in scrollback once the choice is made: the rows, plain, no legend. */
|
|
387
|
+
final() {
|
|
388
|
+
return [OPENING, '', ...this.rows().map((row) => (row.fixed
|
|
389
|
+
? `${ANSI.dim} ${this.#fit(row.text)}${ANSI.reset}`
|
|
390
|
+
: ` ${this.#fit(row.text)}`)), ''];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Apply the picks to the plan. */
|
|
394
|
+
commit() {
|
|
395
|
+
for (const [name, on] of this.picks) this.plan.step(name).decide(on, 'answered');
|
|
396
|
+
const v = this.plan.verifier;
|
|
397
|
+
if (this.radio) {
|
|
398
|
+
v.chosen = v.candidates[this.verifierAt];
|
|
399
|
+
v.asked = true;
|
|
400
|
+
} else {
|
|
401
|
+
v.chosen = v.alreadyChosen?.value ?? v.candidates[0] ?? v.default;
|
|
402
|
+
}
|
|
403
|
+
const a = this.plan.agent;
|
|
404
|
+
if (this.agentRadio) {
|
|
405
|
+
a.chosen = a.candidates[this.agentAt];
|
|
406
|
+
a.asked = true;
|
|
407
|
+
} else {
|
|
408
|
+
a.chosen = a.alreadyChosen?.value ?? a.candidates[0] ?? a.default;
|
|
409
|
+
}
|
|
410
|
+
return this.plan;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** The one-screen setup over a SetupPlan on a TTY. */
|
|
415
|
+
export class SetupPrompter {
|
|
416
|
+
constructor({ stdin, out }) {
|
|
417
|
+
this.stdin = stdin;
|
|
418
|
+
this.out = out;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
static isInteractive({ stdin, out }) {
|
|
422
|
+
return stdin?.isTTY === true && out?.isTTY === true;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Show the screen, take keys until Enter, return the answered plan; Esc/q/ctrl-c and EOF are typed refusals. */
|
|
426
|
+
ask(plan) {
|
|
427
|
+
const screen = new SetupScreen(plan, { columns: this.out.columns || 100 });
|
|
428
|
+
let drawn = 0;
|
|
429
|
+
const columns = this.out.columns || 100;
|
|
430
|
+
const fit = (line) => {
|
|
431
|
+
const plain = line.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '');
|
|
432
|
+
if (plain.length <= columns) return line;
|
|
433
|
+
// Clamp by VISIBLE length: a wrapped line occupies two rows while the redraw counts one.
|
|
434
|
+
let visible = 0;
|
|
435
|
+
let out = '';
|
|
436
|
+
for (let at = 0; at < line.length && visible < columns - 1;) {
|
|
437
|
+
const esc = /^\x1b\[[0-9;?]*[A-Za-z]/.exec(line.slice(at));
|
|
438
|
+
if (esc) { out += esc[0]; at += esc[0].length; continue; }
|
|
439
|
+
out += line[at]; at += 1; visible += 1;
|
|
440
|
+
}
|
|
441
|
+
return `${out}…${line.includes(ANSI.reset) ? ANSI.reset : ''}`;
|
|
442
|
+
};
|
|
443
|
+
const draw = (lines) => {
|
|
444
|
+
this.out.write(`${drawn > 0 ? ANSI.up(drawn) + ANSI.clear : ''}${lines.map(fit).join('\n')}\n`);
|
|
445
|
+
drawn = lines.length;
|
|
446
|
+
};
|
|
447
|
+
return new Promise((resolve, reject) => {
|
|
448
|
+
const stop = () => {
|
|
449
|
+
this.stdin.removeListener('data', onData);
|
|
450
|
+
this.stdin.removeListener('end', onEnd);
|
|
451
|
+
this.stdin.removeListener('close', onEnd);
|
|
452
|
+
this.stdin.setRawMode?.(false);
|
|
453
|
+
this.stdin.pause?.();
|
|
454
|
+
this.out.write(ANSI.show);
|
|
455
|
+
};
|
|
456
|
+
const finish = () => {
|
|
457
|
+
draw(screen.final());
|
|
458
|
+
stop();
|
|
459
|
+
resolve(screen.commit());
|
|
460
|
+
};
|
|
461
|
+
const refuse = (code, message) => {
|
|
462
|
+
draw(screen.final());
|
|
463
|
+
stop();
|
|
464
|
+
reject(new OatheInitError(code, message));
|
|
465
|
+
};
|
|
466
|
+
const onData = (chunk) => {
|
|
467
|
+
for (const key of decodeKeys(chunk)) {
|
|
468
|
+
if (key === 'enter') return finish();
|
|
469
|
+
if (key === 'abort') {
|
|
470
|
+
return refuse('OATHE_INIT_ABORTED',
|
|
471
|
+
'setup aborted at the keyboard — nothing was written; run `oathe init` again, or `oathe init --yes` for the defaults');
|
|
472
|
+
}
|
|
473
|
+
if (key === 'up') screen.move(-1);
|
|
474
|
+
else if (key === 'down') screen.move(1);
|
|
475
|
+
else if (key === 'toggle') screen.toggle();
|
|
476
|
+
else if (key === 'right') screen.cycle(1);
|
|
477
|
+
else if (key === 'left') screen.cycle(-1);
|
|
478
|
+
}
|
|
479
|
+
draw(screen.render());
|
|
480
|
+
return undefined;
|
|
481
|
+
};
|
|
482
|
+
const onEnd = () => refuse('OATHE_INIT_INPUT_CLOSED',
|
|
483
|
+
'stdin closed before Enter — nothing was written; run `oathe init` on a terminal, or `oathe init --yes` for a '
|
|
484
|
+
+ 'non-interactive setup (it announces the defaults it applies)');
|
|
485
|
+
this.stdin.setRawMode?.(true);
|
|
486
|
+
this.stdin.on('data', onData);
|
|
487
|
+
this.stdin.on('end', onEnd);
|
|
488
|
+
this.stdin.on('close', onEnd);
|
|
489
|
+
this.stdin.resume?.();
|
|
490
|
+
this.out.write(ANSI.hide);
|
|
491
|
+
draw(screen.render());
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
package/src/speaker.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// oathe — the SPEAKER primitive (founder ruling 2026-08-30): every speech act is spoken by
|
|
2
|
+
// someone, and the writer resolves WHO from its own process ancestry — never from the
|
|
3
|
+
// model's word, never from a client's self-declared name when the process tree says more
|
|
4
|
+
// (ChatGPT-embedded codex is 'chatgpt', not 'codex'). One resolution, one shape:
|
|
5
|
+
//
|
|
6
|
+
// { surface: string|null — which glass is speaking, named by the adapters
|
|
7
|
+
// app: {bundle,pid}|null — the focusable app above the speaker (the switch target)
|
|
8
|
+
// session: {sessionId, transcriptPath|null, harness}|null — the registered harness
|
|
9
|
+
// session this process speaks FOR, found by the parent chain in the device's
|
|
10
|
+
// session registry (~/.oathe/sessions.json) }
|
|
11
|
+
//
|
|
12
|
+
// Each field is observed truth or null: a bare terminal has no session; a desktop surface
|
|
13
|
+
// with no hooks has surface + app but no session. Observation gaps (ps failing, no registry
|
|
14
|
+
// file) resolve to nulls; a MALFORMED registry refuses typed through load() — a broken
|
|
15
|
+
// invariant is never smoothed over (no fail-soft outside hooks).
|
|
16
|
+
//
|
|
17
|
+
// The two homes this primitive spans (cloud posture, founder ruling): the substrate keeps
|
|
18
|
+
// the PORTABLE fact (which session spoke — written by linkTrace at the act); this device's
|
|
19
|
+
// sessions.json keeps the DEVICE fact (which process embodies it now).
|
|
20
|
+
|
|
21
|
+
import { processAncestry, nearestAppBundle, SessionRegistry } from './sessions.mjs';
|
|
22
|
+
import { surfaceForSession, harnessForClient, ownerOfTracePath, ownedAncestorIndex, HARNESS_CLASSES } from './harnesses/catalog.mjs';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {{pid?: number, sessionsPath: string, clientName?: string|null,
|
|
26
|
+
* exec?: object, platform?: string}} o — exec/platform are test seams for the walk
|
|
27
|
+
* @returns {{surface: string|null, app: {bundle: string, pid: number}|null,
|
|
28
|
+
* session: {sessionId: string, transcriptPath: string|null, harness: string}|null}}
|
|
29
|
+
*/
|
|
30
|
+
export function resolveSpeaker({ pid = process.pid, sessionsPath, clientName = null, exec, platform } = {}) {
|
|
31
|
+
const walk = processAncestry({
|
|
32
|
+
pid,
|
|
33
|
+
...(exec !== undefined && { exec }),
|
|
34
|
+
...(platform !== undefined && { platform }),
|
|
35
|
+
});
|
|
36
|
+
const hit = sessionsPath ? new SessionRegistry({ sessionsPath }).byAncestry(walk) : null;
|
|
37
|
+
if (hit) {
|
|
38
|
+
const { row } = hit;
|
|
39
|
+
const ownedRow = ownedAncestorIndex(row.ancestry ?? []);
|
|
40
|
+
const harnessExec = (ownedRow === -1 ? row.ancestry?.[0]?.exec : row.ancestry[ownedRow].exec) ?? '';
|
|
41
|
+
return {
|
|
42
|
+
surface: surfaceForSession({ ancestry: row.ancestry ?? [], app: row.app ?? null, transcriptPath: row.transcript_path ?? null })
|
|
43
|
+
?? harnessForClient(clientName),
|
|
44
|
+
app: row.app ?? nearestAppBundle(walk),
|
|
45
|
+
session: {
|
|
46
|
+
sessionId: hit.sessionId,
|
|
47
|
+
transcriptPath: row.transcript_path ?? null,
|
|
48
|
+
// The adapter that owns the session: its trace store first, else its own process.
|
|
49
|
+
harness: ownerOfTracePath(row.transcript_path ?? '')
|
|
50
|
+
?? HARNESS_CLASSES.find((C) => C.surfaces?.ownsExec(harnessExec))?.harnessName
|
|
51
|
+
?? harnessForClient(clientName),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// No registered session — name what the chain itself shows, sliced at the nearest
|
|
56
|
+
// adapter-owned ancestor (the harness above us); the client's word is the last fallback.
|
|
57
|
+
const owned = ownedAncestorIndex(walk);
|
|
58
|
+
const ancestry = owned === -1 ? walk : walk.slice(owned);
|
|
59
|
+
const app = nearestAppBundle(ancestry);
|
|
60
|
+
return {
|
|
61
|
+
surface: (owned === -1 ? null : surfaceForSession({ ancestry, app })) ?? harnessForClient(clientName),
|
|
62
|
+
app,
|
|
63
|
+
session: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// oathe — the statement vocabulary shared across the tree. Two facts live here and nowhere
|
|
2
|
+
// else: the subject_ref grammar of a TRACE-LINKAGE statement ('trace:<session_id>', written by
|
|
3
|
+
// the heartbeat hook, read by the verifier and the CLI), and the SQL that finds a claim's
|
|
4
|
+
// latest PROGRESS statement in the holder's own words — trace links excluded, because a
|
|
5
|
+
// heartbeat is custody evidence, not a word from the holder (the board and the pager both
|
|
6
|
+
// read "last word" through this one fragment).
|
|
7
|
+
|
|
8
|
+
export const TRACE_SUBJECT_PREFIX = 'trace:';
|
|
9
|
+
|
|
10
|
+
/** The subject_ref of the statement linking a session transcript to a claim. */
|
|
11
|
+
export function traceSubjectRef(sessionId) {
|
|
12
|
+
return `${TRACE_SUBJECT_PREFIX}${sessionId}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** SQL predicate on a subject_ref column: is this a trace-linkage statement? */
|
|
16
|
+
export function isTraceSubjectSql(column) {
|
|
17
|
+
return `${column} LIKE '${TRACE_SUBJECT_PREFIX}%'`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* THE trace-link writer — attribution rides the speech act (SPEAKER primitive, founder
|
|
22
|
+
* ruling 2026-08-30). Links `session` to the principal's open claim on `taskId`:
|
|
23
|
+
* one link per claim × session, idempotent by (work_claim_id, subject_ref), so the write
|
|
24
|
+
* wrapper stamps it at the act and the turn-end heartbeat's sweep is a no-op for it.
|
|
25
|
+
* A session with no transcript store (cursor) attributes with empty evidence — honestly.
|
|
26
|
+
* No open claim of this principal on the task → nothing to link, {linked: false}.
|
|
27
|
+
* Failures THROW — attribution is part of the act, not a courtesy (retries are idempotent).
|
|
28
|
+
* @param {{client: {query: Function}, identity: {orgId: string, principalId: string},
|
|
29
|
+
* taskId: string, session: {sessionId: string, transcriptPath: string|null, harness: string|null}}} o
|
|
30
|
+
* @returns {Promise<{linked: boolean}>}
|
|
31
|
+
*/
|
|
32
|
+
export async function linkTrace({ client, identity, taskId, session }) {
|
|
33
|
+
const { rows } = await client.query(
|
|
34
|
+
`SELECT work_claim_id FROM cell.work_claim
|
|
35
|
+
WHERE org_id = $1 AND principal_id = $2 AND task_id = $3 AND settled_at IS NULL
|
|
36
|
+
AND state IN ('active', 'completion_asserted')
|
|
37
|
+
ORDER BY claimed_at DESC LIMIT 1`,
|
|
38
|
+
[identity.orgId, identity.principalId, taskId]);
|
|
39
|
+
if (rows.length === 0) return { linked: false };
|
|
40
|
+
const { randomUUID } = await import('node:crypto');
|
|
41
|
+
const transcript = session.transcriptPath ?? null;
|
|
42
|
+
await client.query(
|
|
43
|
+
`INSERT INTO cell.agent_statement (statement_id, org_id, task_id, work_claim_id,
|
|
44
|
+
execution_actor, claim_principal, statement_type, subject_ref, proposition,
|
|
45
|
+
evidence_refs, epistemic_status, asserted_at)
|
|
46
|
+
SELECT $1, $2, $3, $4, $5, $6, 'progress', $7, $8, $9::jsonb, 'observed', now()
|
|
47
|
+
WHERE NOT EXISTS (
|
|
48
|
+
SELECT 1 FROM cell.agent_statement
|
|
49
|
+
WHERE org_id = $2 AND work_claim_id = $4 AND subject_ref = $7)`,
|
|
50
|
+
[randomUUID(), identity.orgId, taskId, rows[0].work_claim_id,
|
|
51
|
+
`session:${session.sessionId}`, identity.principalId, traceSubjectRef(session.sessionId),
|
|
52
|
+
`${session.harness ?? 'unknown'} session ${session.sessionId} worked this claim`
|
|
53
|
+
+ (transcript ? ` — transcript at ${transcript} (fan-out derived at read time)` : ' — no transcript store (this surface keeps none)'),
|
|
54
|
+
JSON.stringify(transcript ? [transcript] : [])]);
|
|
55
|
+
return { linked: true };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The latest non-trace progress statement of one claim, as a LATERAL body:
|
|
60
|
+
* `LEFT JOIN LATERAL (${latestProgressSql({ task: 't', claim: 'w' })}) p ON true` yields
|
|
61
|
+
* p.proposition / p.asserted_at (NULL when the holder has said nothing yet).
|
|
62
|
+
* @param {{task: string, claim: string}} aliases the cell.task and cell.work_claim aliases in scope
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* The verdict's own words for `task` — the latest completion statement of its verify: twin
|
|
66
|
+
* ("rejected: <reason>" / "accepted: <reason>"). THE owning read for the rejection reason:
|
|
67
|
+
* the pager's breach detail, the tools' attention lines, and the reclaim bundle all consume
|
|
68
|
+
* this one fragment (`task` is a cell.task alias).
|
|
69
|
+
*/
|
|
70
|
+
/** Engine-failure evidence shape: 'engine-failure:<engine>' — a verify child that lost its
|
|
71
|
+
* engine records this on the verify task before releasing its claim. */
|
|
72
|
+
export function engineFailureRef(engine) {
|
|
73
|
+
return `engine-failure:${engine}`;
|
|
74
|
+
}
|
|
75
|
+
export function isEngineFailureSql(column) {
|
|
76
|
+
return `EXISTS (SELECT 1 FROM jsonb_array_elements_text(${column}) er WHERE er LIKE 'engine-failure:%')`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** R-AMEND: the amendment trail's subject shape — 'amend:<task_id>', owned here alone. */
|
|
80
|
+
export const AMEND_SUBJECT_PREFIX = 'amend:';
|
|
81
|
+
export function amendSubjectRef(taskId) {
|
|
82
|
+
return `${AMEND_SUBJECT_PREFIX}${taskId}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function latestVerdictSql({ task }) {
|
|
86
|
+
return `SELECT s.proposition AS verdict, s.asserted_at AS verdict_at
|
|
87
|
+
FROM cell.agent_statement s
|
|
88
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = 'verify:' || ${task}.task_id
|
|
89
|
+
AND s.statement_type = 'completion'
|
|
90
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The latest trace-link statement's transcript path for `task` — the durable record of
|
|
95
|
+
* WHICH SURFACE last worked the claim (the heartbeat writes one per claim × session,
|
|
96
|
+
* transcript path as evidence_refs[0]; ownerOfTracePath maps it to a harness).
|
|
97
|
+
*/
|
|
98
|
+
export function latestTracePathSql({ task }) {
|
|
99
|
+
return `SELECT s.evidence_refs->>0 AS trace_path,
|
|
100
|
+
substr(s.subject_ref, ${TRACE_SUBJECT_PREFIX.length + 1}) AS trace_session_id
|
|
101
|
+
FROM cell.agent_statement s
|
|
102
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = ${task}.task_id
|
|
103
|
+
AND ${isTraceSubjectSql('s.subject_ref')}
|
|
104
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function latestProgressSql({ task, claim }) {
|
|
108
|
+
return `SELECT s.proposition, s.asserted_at FROM cell.agent_statement s
|
|
109
|
+
WHERE s.org_id = ${task}.org_id AND s.task_id = ${task}.task_id
|
|
110
|
+
AND s.work_claim_id = ${claim}.work_claim_id
|
|
111
|
+
AND s.statement_type = 'progress' AND NOT (${isTraceSubjectSql('s.subject_ref')})
|
|
112
|
+
ORDER BY s.asserted_at DESC LIMIT 1`;
|
|
113
|
+
}
|