@oathe/oathe 0.0.1 → 0.2.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/.claude-plugin/marketplace.json +14 -0
- package/LICENSE +202 -21
- package/NOTICE +7 -0
- package/README.md +104 -12
- package/assets/oathe-hero.svg +92 -0
- package/bin/oathe.mjs +376 -0
- package/docs/PRIVACY.md +45 -0
- package/package.json +33 -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/blocks.mjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// oathe — the managed-write engines. Every byte oathe puts in a user file goes through one of
|
|
2
|
+
// these two classes, so "replace own block only, never touch outside" is a property of the type,
|
|
3
|
+
// not a discipline each call site re-implements.
|
|
4
|
+
//
|
|
5
|
+
// Two styles exist because the surfaces do: fenced TEXT for files with comments (CLAUDE.md,
|
|
6
|
+
// AGENTS.md, config.toml — the estate's zprofile `>>> <<<` precedent), and owned KEY PATHS for
|
|
7
|
+
// JSON files, where ownership is recorded in the install manifest rather than as in-file marker
|
|
8
|
+
// keys (Claude Code validates settings.json and warns on unknown keys, so the file stays clean
|
|
9
|
+
// and the manifest carries the version + sha).
|
|
10
|
+
|
|
11
|
+
const FENCE_NAME = 'oathe';
|
|
12
|
+
|
|
13
|
+
export const FENCE_STYLES = Object.freeze({
|
|
14
|
+
hash: { open: (v) => `# >>> ${FENCE_NAME} v${v} >>>`, close: `# <<< ${FENCE_NAME} <<<` },
|
|
15
|
+
html: { open: (v) => `<!-- >>> ${FENCE_NAME} v${v} >>> -->`, close: `<!-- <<< ${FENCE_NAME} <<< -->` },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The opening marker split around its version slot, so locate matches ANY version. NUL is
|
|
20
|
+
* the sentinel because it is the one character no rendered marker can contain.
|
|
21
|
+
*/
|
|
22
|
+
function openMarkerPattern(style) {
|
|
23
|
+
const probe = style.open('\u0000');
|
|
24
|
+
const [before, after] = probe.split('\u0000');
|
|
25
|
+
return { before, after };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class DuplicateFenceError extends Error {
|
|
29
|
+
constructor(count) {
|
|
30
|
+
super(`duplicate oathe fences: found ${count} managed blocks in one file; refusing to edit `
|
|
31
|
+
+ 'rather than guess which one is ours — remove the extras by hand or run `oathe doctor`');
|
|
32
|
+
this.name = 'DuplicateFenceError';
|
|
33
|
+
this.code = 'OATHE_DUPLICATE_FENCE';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class FencedBlock {
|
|
38
|
+
/** @param {{style: {open: (v:string)=>string, close: string}}} o */
|
|
39
|
+
constructor({ style }) {
|
|
40
|
+
this.style = style;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The complete block text (no trailing newline) — also what the manifest hashes. */
|
|
44
|
+
render(version, body) {
|
|
45
|
+
return `${this.style.open(version)}\n${body}\n${this.style.close}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Every managed block in `content`, located by scanning lines for the open/close markers.
|
|
50
|
+
* @returns {{start: number, end: number, version: string, body: string}[]} index ranges cover
|
|
51
|
+
* the block text exactly (no surrounding newlines).
|
|
52
|
+
*/
|
|
53
|
+
#locate(content) {
|
|
54
|
+
const { before, after } = openMarkerPattern(this.style);
|
|
55
|
+
const found = [];
|
|
56
|
+
let from = 0;
|
|
57
|
+
for (;;) {
|
|
58
|
+
const start = content.indexOf(before, from);
|
|
59
|
+
if (start === -1) break;
|
|
60
|
+
const openEnd = content.indexOf('\n', start);
|
|
61
|
+
if (openEnd === -1) break;
|
|
62
|
+
const openLine = content.slice(start, openEnd);
|
|
63
|
+
if (!openLine.endsWith(after)) { from = start + before.length; continue; }
|
|
64
|
+
const version = openLine.slice(before.length, openLine.length - after.length);
|
|
65
|
+
const closeAt = content.indexOf(this.style.close, openEnd);
|
|
66
|
+
if (closeAt === -1) break;
|
|
67
|
+
const end = closeAt + this.style.close.length;
|
|
68
|
+
found.push({ start, end, version, body: content.slice(openEnd + 1, closeAt - 1) });
|
|
69
|
+
from = end;
|
|
70
|
+
}
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#single(content) {
|
|
75
|
+
const found = this.#locate(content);
|
|
76
|
+
if (found.length > 1) throw new DuplicateFenceError(found.length);
|
|
77
|
+
return found[0] ?? null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @returns {{present: boolean, version: string|null, body: string|null, blockText: string|null}} */
|
|
81
|
+
read(content) {
|
|
82
|
+
const block = this.#single(content);
|
|
83
|
+
if (!block) return { present: false, version: null, body: null, blockText: null };
|
|
84
|
+
return {
|
|
85
|
+
present: true,
|
|
86
|
+
version: block.version,
|
|
87
|
+
body: block.body,
|
|
88
|
+
blockText: content.slice(block.start, block.end),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create or replace THE managed block. Content outside the fence is preserved byte-for-byte.
|
|
94
|
+
* @returns {{content: string, changed: boolean}}
|
|
95
|
+
*/
|
|
96
|
+
apply(content, { version, body }) {
|
|
97
|
+
const rendered = this.render(version, body);
|
|
98
|
+
const existing = this.#single(content);
|
|
99
|
+
if (existing) {
|
|
100
|
+
const next = content.slice(0, existing.start) + rendered + content.slice(existing.end);
|
|
101
|
+
return { content: next, changed: next !== content };
|
|
102
|
+
}
|
|
103
|
+
if (content === '') return { content: `${rendered}\n`, changed: true };
|
|
104
|
+
const sep = content.endsWith('\n') ? '\n' : '\n\n';
|
|
105
|
+
return { content: `${content}${sep}${rendered}\n`, changed: true };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Delete the managed block and the separating blank line `apply` introduced. Idempotent. */
|
|
109
|
+
remove(content) {
|
|
110
|
+
const existing = this.#single(content);
|
|
111
|
+
if (!existing) return { content, changed: false };
|
|
112
|
+
let head = content.slice(0, existing.start);
|
|
113
|
+
let tail = content.slice(existing.end);
|
|
114
|
+
if (tail.startsWith('\n')) tail = tail.slice(1);
|
|
115
|
+
if (head.endsWith('\n\n')) head = head.slice(0, -1);
|
|
116
|
+
return { content: head + tail, changed: true };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class JsonEntries {
|
|
121
|
+
#parse(text) {
|
|
122
|
+
if (text.trim() === '') return {};
|
|
123
|
+
try {
|
|
124
|
+
return JSON.parse(text);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
throw new Error(`the target file is not valid JSON, so oathe refuses to rewrite it: ${e.message}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#stringify(doc) {
|
|
131
|
+
return `${JSON.stringify(doc, null, 2)}\n`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @returns {*} the value at `path`, or undefined */
|
|
135
|
+
read(text, path) {
|
|
136
|
+
let node = this.#parse(text);
|
|
137
|
+
for (const key of path) {
|
|
138
|
+
if (node === null || typeof node !== 'object' || !(key in node)) return undefined;
|
|
139
|
+
node = node[key];
|
|
140
|
+
}
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set every {path, value} entry, creating intermediate objects. Keys oathe does not own are
|
|
146
|
+
* untouched (the whole document is re-serialized, but no other key's VALUE changes).
|
|
147
|
+
* @returns {{content: string, changed: boolean}}
|
|
148
|
+
*/
|
|
149
|
+
apply(text, entries) {
|
|
150
|
+
const doc = this.#parse(text);
|
|
151
|
+
for (const { path, value } of entries) {
|
|
152
|
+
let node = doc;
|
|
153
|
+
for (const key of path.slice(0, -1)) {
|
|
154
|
+
if (node[key] === null || typeof node[key] !== 'object') node[key] = {};
|
|
155
|
+
node = node[key];
|
|
156
|
+
}
|
|
157
|
+
node[path.at(-1)] = value;
|
|
158
|
+
}
|
|
159
|
+
const content = this.#stringify(doc);
|
|
160
|
+
return { content, changed: content !== text };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Delete the owned paths; a parent object emptied by the deletion is pruned (it existed for
|
|
165
|
+
* our key), while a parent still holding someone else's keys stays.
|
|
166
|
+
* @returns {{content: string, changed: boolean}}
|
|
167
|
+
*/
|
|
168
|
+
remove(text, paths) {
|
|
169
|
+
const doc = this.#parse(text);
|
|
170
|
+
for (const path of paths) {
|
|
171
|
+
const parents = [];
|
|
172
|
+
let node = doc;
|
|
173
|
+
let missing = false;
|
|
174
|
+
for (const key of path.slice(0, -1)) {
|
|
175
|
+
if (node === null || typeof node !== 'object' || !(key in node)) { missing = true; break; }
|
|
176
|
+
parents.push({ node, key });
|
|
177
|
+
node = node[key];
|
|
178
|
+
}
|
|
179
|
+
if (missing || node === null || typeof node !== 'object') continue;
|
|
180
|
+
delete node[path.at(-1)];
|
|
181
|
+
for (let i = parents.length - 1; i >= 0; i -= 1) {
|
|
182
|
+
const { node: parent, key } = parents[i];
|
|
183
|
+
const child = parent[key];
|
|
184
|
+
if (child !== null && typeof child === 'object' && Object.keys(child).length === 0) {
|
|
185
|
+
delete parent[key];
|
|
186
|
+
} else break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const content = this.#stringify(doc);
|
|
190
|
+
return { content, changed: content !== text };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// oathe — the ONE board renderer. Two consumers, one voice: the SessionStart hook (context
|
|
2
|
+
// for the model + the visible line) and the launcher (printed into terminal scrollback before
|
|
3
|
+
// the harness TUI starts, because TUIs bury hook output in transcript overlays).
|
|
4
|
+
//
|
|
5
|
+
// Three states, three voices: RECOVERY (tasks of yours survived across sessions — the moment
|
|
6
|
+
// oathe visibly earned its keep, so the celebration and the star ask ride here, and ONLY
|
|
7
|
+
// here); open-but-not-yours (the lock summary); and a clean folder (the beer — silence would
|
|
8
|
+
// be indistinguishable from oathe not running).
|
|
9
|
+
|
|
10
|
+
import { createOatheTools } from './mcp/oathe-tools.mjs';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {{client: {query: Function}, identity: object, workspace: string}} o
|
|
16
|
+
* @returns {Promise<{context: string, message: string}>} context = the full board (model /
|
|
17
|
+
* scrollback); message = the one visible state line
|
|
18
|
+
*/
|
|
19
|
+
export async function renderBoard({ client, identity, workspace, config }) {
|
|
20
|
+
const starUrl = config?.get('starUrl') ?? 'https://github.com/oathe-ai/oathe';
|
|
21
|
+
const starAsk = `⭐ Support open-source infra: ${starUrl}`;
|
|
22
|
+
const tools = createOatheTools({ client, identity, workspace, config });
|
|
23
|
+
const { sections } = await tools.oathe_board({});
|
|
24
|
+
const { mine, open, asserted, held } = sections;
|
|
25
|
+
const total = mine.length + open.length + asserted.length + held.length;
|
|
26
|
+
|
|
27
|
+
const lines = [`## Oathe board (${workspace})`, ''];
|
|
28
|
+
if (total === 0) {
|
|
29
|
+
lines.push('_No open tasks in this workspace. Claim before you build: `oathe_claim`._');
|
|
30
|
+
}
|
|
31
|
+
if (mine.length > 0) {
|
|
32
|
+
lines.push('**Yours (still claimed by you — completion not asserted; say `continue <task>` to pick one up):**');
|
|
33
|
+
for (const r of mine) {
|
|
34
|
+
lines.push(`- [${r.task_id}] ${r.objective} — lease until ${r.lease_until}`);
|
|
35
|
+
if (r.last_progress) lines.push(` ↳ last recorded progress${r.last_progress_at ? ` (${r.last_progress_at})` : ''}: ${r.last_progress}`);
|
|
36
|
+
}
|
|
37
|
+
lines.push('');
|
|
38
|
+
}
|
|
39
|
+
if (open.length > 0) {
|
|
40
|
+
lines.push('**Open (claimable):**');
|
|
41
|
+
for (const r of open) {
|
|
42
|
+
const note = r.state === 'reopened' ? ' (came back incomplete — actionable again)' : (r.state ? ` (${r.state})` : '');
|
|
43
|
+
lines.push(`- [${r.task_id}] ${r.objective}${note}`);
|
|
44
|
+
}
|
|
45
|
+
lines.push('');
|
|
46
|
+
}
|
|
47
|
+
if (asserted.length > 0) {
|
|
48
|
+
lines.push('**Asserted (completion claimed — awaiting a non-author verdict; `oathe verify` runs it):**');
|
|
49
|
+
for (const r of asserted) lines.push(`- [${r.task_id}] ${r.objective}`);
|
|
50
|
+
lines.push('');
|
|
51
|
+
}
|
|
52
|
+
if (held.length > 0) {
|
|
53
|
+
lines.push('**Held:**');
|
|
54
|
+
for (const r of held) lines.push(`- [${r.task_id}] ${r.objective} (${r.principal_id})`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let message;
|
|
58
|
+
if (mine.length > 0) {
|
|
59
|
+
const n = mine.length === 1 ? '1 task' : `${mine.length} tasks`;
|
|
60
|
+
message = `🎉 Oathe just saved your session state — ${n} still yours! ${starAsk}`;
|
|
61
|
+
} else if (total > 0) {
|
|
62
|
+
const parts = [];
|
|
63
|
+
parts.push(open.length === 1 ? '1 open task' : `${open.length} open tasks`);
|
|
64
|
+
if (asserted.length > 0) parts.push(`${asserted.length} asserted`);
|
|
65
|
+
if (held.length > 0) parts.push(`${held.length} held`);
|
|
66
|
+
message = `🔒 Oathe: ${parts.join(' · ')}`;
|
|
67
|
+
} else {
|
|
68
|
+
message = '🍺 No open tasks in this folder — Oathe is keeping track.';
|
|
69
|
+
}
|
|
70
|
+
return { context: lines.join('\n'), message, sections };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const BOLD = '\x1b[1m';
|
|
74
|
+
const DIM = '\x1b[2m';
|
|
75
|
+
const RESET = '\x1b[0m';
|
|
76
|
+
const OBJECTIVE_WIDTH = 48;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The board as an ANSI terminal splash — the launcher's human-facing render. No markdown:
|
|
80
|
+
* bold ids, aligned columns, dim detail. An empty board is just the state line.
|
|
81
|
+
*/
|
|
82
|
+
export function renderSplash({ message, sections, workspace }) {
|
|
83
|
+
const { mine, open, asserted, held } = sections;
|
|
84
|
+
const all = [...mine, ...open, ...asserted, ...held];
|
|
85
|
+
const out = ['', ` ${message} ${DIM}${workspace}${RESET}`, ''];
|
|
86
|
+
if (all.length === 0) return `${out.join('\n')}\n`;
|
|
87
|
+
|
|
88
|
+
const idWidth = Math.max(...all.map((r) => r.task_id.length));
|
|
89
|
+
const clip = (text) => (text.length > OBJECTIVE_WIDTH ? `${text.slice(0, OBJECTIVE_WIDTH - 1)}…` : text);
|
|
90
|
+
const row = (r, detail) => ` ${BOLD}${r.task_id.padEnd(idWidth)}${RESET} `
|
|
91
|
+
+ `${clip(r.objective).padEnd(OBJECTIVE_WIDTH)} ${DIM}${detail}${RESET}`;
|
|
92
|
+
|
|
93
|
+
const section = (header, rows, detailFor) => {
|
|
94
|
+
if (rows.length === 0) return;
|
|
95
|
+
out.push(` ${BOLD}${DIM}${header}${RESET}`);
|
|
96
|
+
for (const r of rows) out.push(row(r, detailFor(r)));
|
|
97
|
+
out.push('');
|
|
98
|
+
};
|
|
99
|
+
section('YOURS (completion not asserted)', mine, (r) => (r.last_progress
|
|
100
|
+
? `last: ${r.last_progress.slice(0, 26)}`
|
|
101
|
+
: `lease until ${r.lease_until}`));
|
|
102
|
+
section('OPEN', open, (r) => (r.state === 'reopened' ? 'back — incomplete, actionable' : (r.state ?? 'unclaimed')));
|
|
103
|
+
section('ASSERTED', asserted, () => 'awaiting verdict');
|
|
104
|
+
section('HELD', held, (r) => r.principal_id);
|
|
105
|
+
return `${out.join('\n')}\n`;
|
|
106
|
+
}
|
package/src/config.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// oathe — the ONE place every tunable is named (founder ruling: never hardcode). Layered:
|
|
2
|
+
// DEFAULTS → global file (<OATHE_HOME>/config.json) → workspace file (<workspace-root>/.oathe.json)
|
|
3
|
+
// → environment. Unknown keys and invalid values refuse loudly at LOAD, not at first use —
|
|
4
|
+
// a config file nobody validates is a config file that silently defers.
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export class ConfigError extends Error {
|
|
11
|
+
constructor(code, message, details = {}) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'ConfigError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ENGINES = ['claude', 'codex'];
|
|
20
|
+
|
|
21
|
+
/** Every key: default, env var, validator. Adding a tunable means adding a row HERE. */
|
|
22
|
+
const KEYS = Object.freeze({
|
|
23
|
+
org: { default: 'oathe', env: 'OATHE_ORG', check: nonEmptyString },
|
|
24
|
+
principal: { default: null, env: 'OATHE_PRINCIPAL', check: nullOrString },
|
|
25
|
+
department: { default: 'operator', env: 'OATHE_DEPARTMENT', check: nonEmptyString },
|
|
26
|
+
db: { default: 'oathe_local', env: 'OATHE_DB', check: nonEmptyString },
|
|
27
|
+
// Standard-first: honor libpq's PGHOST when set; otherwise the platform's conventional
|
|
28
|
+
// socket directory (Homebrew macOS: /tmp; Debian/Ubuntu: /var/run/postgresql). A '/tmp'
|
|
29
|
+
// default alone was a macOS assumption that broke every fresh Linux machine.
|
|
30
|
+
pgHost: {
|
|
31
|
+
default: process.env.PGHOST
|
|
32
|
+
|| (process.platform === 'darwin' ? '/tmp' : '/var/run/postgresql'),
|
|
33
|
+
env: 'OATHE_PG_HOST', check: nonEmptyString,
|
|
34
|
+
},
|
|
35
|
+
pgPort: { default: 5432, env: 'OATHE_PG_PORT', check: positiveInt },
|
|
36
|
+
leaseHours: { default: 4, env: 'OATHE_LEASE_HOURS', check: positiveInt },
|
|
37
|
+
verifyByHours: { default: 24, env: 'OATHE_VERIFY_BY_HOURS', check: positiveInt },
|
|
38
|
+
verifier: { default: 'claude', env: 'OATHE_VERIFIER', check: oneOf(ENGINES) },
|
|
39
|
+
verifierPrincipal: { default: 'oathe-verifier', env: 'OATHE_VERIFIER_PRINCIPAL', check: nonEmptyString },
|
|
40
|
+
verifierEvidenceBudget: { default: 24000, env: 'OATHE_VERIFIER_EVIDENCE_BUDGET', check: positiveInt },
|
|
41
|
+
runtimeProvider: { default: 'auto', env: 'OATHE_RUNTIME_PROVIDER', check: oneOf(['auto', 'oathe', 'standalone']) },
|
|
42
|
+
starUrl: {
|
|
43
|
+
default: 'https://github.com/oathe-ai/oathe', env: 'OATHE_STAR_URL', check: httpsUrl,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function nonEmptyString(v) {
|
|
48
|
+
return typeof v === 'string' && v.trim() !== '';
|
|
49
|
+
}
|
|
50
|
+
function nullOrString(v) {
|
|
51
|
+
return v === null || nonEmptyString(v);
|
|
52
|
+
}
|
|
53
|
+
function positiveInt(v) {
|
|
54
|
+
return Number.isInteger(v) && v > 0;
|
|
55
|
+
}
|
|
56
|
+
function oneOf(allowed) {
|
|
57
|
+
const check = (v) => allowed.includes(v);
|
|
58
|
+
check.expected = allowed.join('|');
|
|
59
|
+
return check;
|
|
60
|
+
}
|
|
61
|
+
function httpsUrl(v) {
|
|
62
|
+
return typeof v === 'string' && v.startsWith('https://');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Walk up from `dir` to the workspace root (the dir holding .git), else `dir` itself. */
|
|
66
|
+
function workspaceRoot(dir) {
|
|
67
|
+
let current = dir;
|
|
68
|
+
for (;;) {
|
|
69
|
+
if (fs.existsSync(path.join(current, '.git'))) return current;
|
|
70
|
+
const parent = path.dirname(current);
|
|
71
|
+
if (parent === current) return dir;
|
|
72
|
+
current = parent;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const CONFIG_KEYS = Object.freeze(Object.keys(KEYS));
|
|
77
|
+
export const VERIFIER_ENGINES = Object.freeze([...ENGINES]);
|
|
78
|
+
|
|
79
|
+
export class OatheConfig {
|
|
80
|
+
/** @param {{env?: NodeJS.ProcessEnv, cwd?: string}} o */
|
|
81
|
+
constructor({ env = process.env, cwd = process.cwd() } = {}) {
|
|
82
|
+
this.env = env;
|
|
83
|
+
this.globalPath = path.join(env.OATHE_HOME || path.join(env.HOME || os.homedir(), '.oathe'), 'config.json');
|
|
84
|
+
this.workspacePath = path.join(workspaceRoot(cwd), '.oathe.json');
|
|
85
|
+
this.values = { ...Object.fromEntries(Object.entries(KEYS).map(([k, spec]) => [k, spec.default])) };
|
|
86
|
+
this.sources = Object.fromEntries(Object.keys(KEYS).map((k) => [k, 'default']));
|
|
87
|
+
for (const [file, layer] of [[this.globalPath, 'global'], [this.workspacePath, 'workspace']]) {
|
|
88
|
+
const loaded = this.#loadFile(file);
|
|
89
|
+
Object.assign(this.values, loaded);
|
|
90
|
+
for (const key of Object.keys(loaded)) this.sources[key] = layer;
|
|
91
|
+
}
|
|
92
|
+
for (const [key, spec] of Object.entries(KEYS)) {
|
|
93
|
+
if (spec.env && env[spec.env] !== undefined) {
|
|
94
|
+
const raw = env[spec.env];
|
|
95
|
+
const value = typeof spec.default === 'number' ? Number(raw) : raw;
|
|
96
|
+
this.#checkValue(key, value, `env ${spec.env}`);
|
|
97
|
+
this.values[key] = value;
|
|
98
|
+
this.sources[key] = 'env';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Where a key's value came from: 'default' | 'global' | 'workspace' | 'env'. */
|
|
104
|
+
source(key) {
|
|
105
|
+
if (!(key in KEYS)) {
|
|
106
|
+
throw new ConfigError('OATHE_CONFIG_KEY_UNKNOWN',
|
|
107
|
+
`unknown config key '${key}' — known keys: ${CONFIG_KEYS.join(', ')}`, { key });
|
|
108
|
+
}
|
|
109
|
+
return this.sources[key];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#loadFile(file) {
|
|
113
|
+
if (!fs.existsSync(file)) return {};
|
|
114
|
+
let doc;
|
|
115
|
+
try {
|
|
116
|
+
doc = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
117
|
+
} catch (e) {
|
|
118
|
+
throw new ConfigError('OATHE_CONFIG_FILE_MALFORMED',
|
|
119
|
+
`${file} is not valid JSON: ${e.message}`, { file });
|
|
120
|
+
}
|
|
121
|
+
for (const [key, value] of Object.entries(doc)) {
|
|
122
|
+
if (!(key in KEYS)) {
|
|
123
|
+
throw new ConfigError('OATHE_CONFIG_KEY_UNKNOWN',
|
|
124
|
+
`${file} sets unknown key '${key}' — known keys: ${CONFIG_KEYS.join(', ')}`, { file, key });
|
|
125
|
+
}
|
|
126
|
+
this.#checkValue(key, value, file);
|
|
127
|
+
}
|
|
128
|
+
return doc;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#checkValue(key, value, source) {
|
|
132
|
+
const spec = KEYS[key];
|
|
133
|
+
if (!spec.check(value)) {
|
|
134
|
+
throw new ConfigError('OATHE_CONFIG_VALUE_INVALID',
|
|
135
|
+
`${source}: '${key}' = ${JSON.stringify(value)} is invalid`
|
|
136
|
+
+ `${spec.check.expected ? ` (expected ${spec.check.expected})` : ''}`, { key, value, source });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get(key) {
|
|
141
|
+
if (!(key in KEYS)) {
|
|
142
|
+
throw new ConfigError('OATHE_CONFIG_KEY_UNKNOWN',
|
|
143
|
+
`unknown config key '${key}' — known keys: ${CONFIG_KEYS.join(', ')}`, { key });
|
|
144
|
+
}
|
|
145
|
+
return this.values[key];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Write one key to the chosen scope file and apply it live. */
|
|
149
|
+
set(key, value, { scope }) {
|
|
150
|
+
if (!(key in KEYS)) {
|
|
151
|
+
throw new ConfigError('OATHE_CONFIG_KEY_UNKNOWN',
|
|
152
|
+
`unknown config key '${key}' — known keys: ${CONFIG_KEYS.join(', ')}`, { key });
|
|
153
|
+
}
|
|
154
|
+
this.#checkValue(key, value, `set(${scope})`);
|
|
155
|
+
const file = scope === 'global' ? this.globalPath
|
|
156
|
+
: scope === 'workspace' ? this.workspacePath
|
|
157
|
+
: (() => {
|
|
158
|
+
throw new ConfigError('OATHE_CONFIG_SCOPE_UNKNOWN',
|
|
159
|
+
`unknown scope '${scope}' — use 'global' or 'workspace'`, { scope });
|
|
160
|
+
})();
|
|
161
|
+
const doc = this.#loadFile(file);
|
|
162
|
+
doc[key] = value;
|
|
163
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
164
|
+
fs.writeFileSync(file, `${JSON.stringify(doc, null, 2)}\n`);
|
|
165
|
+
this.values[key] = value;
|
|
166
|
+
this.sources[key] = scope;
|
|
167
|
+
return { file, key, value };
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/context.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// oathe — the composition seam every verb starts from: paths, manifest, harnesses, substrate,
|
|
2
|
+
// identity, version. Built from env + an injectable exec so tests run in a sandbox HOME against
|
|
3
|
+
// a scratch database without monkey-patching anything.
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { buildPaths } from './paths.mjs';
|
|
10
|
+
import { OatheConfig } from './config.mjs';
|
|
11
|
+
import { InstallManifest } from './manifest.mjs';
|
|
12
|
+
import { ClaudeHarness, CodexHarness } from './harness.mjs';
|
|
13
|
+
import { Substrate } from './substrate.mjs';
|
|
14
|
+
|
|
15
|
+
export function packageVersion(paths) {
|
|
16
|
+
return JSON.parse(fs.readFileSync(path.join(paths.packageRoot, 'package.json'), 'utf8')).version;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function buildContext({ env = process.env, exec, cwd = process.cwd() } = {}) {
|
|
20
|
+
const paths = buildPaths(env);
|
|
21
|
+
const home = env.HOME || os.homedir();
|
|
22
|
+
const config = new OatheConfig({ env, cwd });
|
|
23
|
+
const manifest = InstallManifest.load({ manifestPath: paths.manifestPath, backupsDir: paths.backupsDir });
|
|
24
|
+
const harnesses = [
|
|
25
|
+
new ClaudeHarness({ home, envPath: env.PATH, paths, exec }),
|
|
26
|
+
new CodexHarness({ home, envPath: env.PATH, paths, exec }),
|
|
27
|
+
];
|
|
28
|
+
const substrate = new Substrate({ database: config.get('db'), paths, env, config });
|
|
29
|
+
const identity = {
|
|
30
|
+
orgId: config.get('org'),
|
|
31
|
+
principalId: config.get('principal') || env.USER || 'operator',
|
|
32
|
+
department: config.get('department'),
|
|
33
|
+
};
|
|
34
|
+
return { paths, home, manifest, harnesses, substrate, identity, config, version: packageVersion(paths), env };
|
|
35
|
+
}
|
package/src/doctor.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// oathe doctor — verify every manifest row against the world as it is NOW. A user edit inside
|
|
2
|
+
// an owned surface is REPORTED, never overwritten: the manifest records what oathe wrote, the
|
|
3
|
+
// doctor says whether it still stands, and the user's hand outranks ours.
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
import { buildContext } from './context.mjs';
|
|
9
|
+
import { FencedBlock, FENCE_STYLES, JsonEntries } from './blocks.mjs';
|
|
10
|
+
import { sha256Hex } from './manifest.mjs';
|
|
11
|
+
|
|
12
|
+
function verifyJsonRow(row) {
|
|
13
|
+
if (!fs.existsSync(row.file)) return 'file-missing';
|
|
14
|
+
const text = fs.readFileSync(row.file, 'utf8');
|
|
15
|
+
const engine = new JsonEntries();
|
|
16
|
+
const entries = [];
|
|
17
|
+
for (const p of row.detail?.paths ?? []) {
|
|
18
|
+
const value = engine.read(text, p);
|
|
19
|
+
if (value === undefined) return 'removed';
|
|
20
|
+
entries.push({ path: p, value });
|
|
21
|
+
}
|
|
22
|
+
return sha256Hex(JSON.stringify(entries)) === row.sha256 ? 'ok' : 'user-edited';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function verifyFenceRow(row) {
|
|
26
|
+
if (!fs.existsSync(row.file)) return 'file-missing';
|
|
27
|
+
const block = new FencedBlock({ style: FENCE_STYLES[row.detail?.style ?? 'hash'] });
|
|
28
|
+
const seen = block.read(fs.readFileSync(row.file, 'utf8'));
|
|
29
|
+
if (!seen.present) return 'removed';
|
|
30
|
+
return sha256Hex(seen.blockText) === row.sha256 ? 'ok' : 'user-edited';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function verifyCliRow(row) {
|
|
34
|
+
if (!fs.existsSync(row.file)) return 'file-missing';
|
|
35
|
+
return fs.readFileSync(row.file, 'utf8').includes(row.detail?.proof) ? 'ok' : 'removed';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const VERIFIERS = { 'json-path': verifyJsonRow, fence: verifyFenceRow, 'cli-managed': verifyCliRow };
|
|
39
|
+
|
|
40
|
+
/** @returns {Promise<{rows: object[], substrate: object, plugin: {resolves: boolean, detail: string|null}}>} */
|
|
41
|
+
export async function runDoctor({ env = process.env } = {}) {
|
|
42
|
+
const ctx = buildContext({ env });
|
|
43
|
+
const { manifest, substrate, paths } = ctx;
|
|
44
|
+
try {
|
|
45
|
+
const rows = manifest.rows.map((row) => ({
|
|
46
|
+
harness: row.harness,
|
|
47
|
+
file: row.file,
|
|
48
|
+
kind: row.kind,
|
|
49
|
+
block_version: row.block_version,
|
|
50
|
+
status: (VERIFIERS[row.kind] ?? (() => 'unknown-kind'))(row),
|
|
51
|
+
}));
|
|
52
|
+
// The trace-contract monitor: both vendors disclaim transcript-schema stability, so the
|
|
53
|
+
// doctor validates the NEWEST live record in each store against docs/traces.md and
|
|
54
|
+
// reports DRIFT loudly. An absent store is a distinct, visible status — never a silent skip.
|
|
55
|
+
const { ClaudeTraceStore, CodexTraceStore } = await import('./traces.mjs');
|
|
56
|
+
const { ClaudeAtifProjector, CodexAtifProjector, AtifValidator } = await import('./atif.mjs');
|
|
57
|
+
const home = ctx.home;
|
|
58
|
+
const traces = {};
|
|
59
|
+
for (const [name, store] of Object.entries({
|
|
60
|
+
claude: new ClaudeTraceStore({ home }),
|
|
61
|
+
codex: new CodexTraceStore({ home }),
|
|
62
|
+
})) {
|
|
63
|
+
const newest = name === 'claude' ? store.newestTranscript() : store.newestRollout();
|
|
64
|
+
if (!newest) {
|
|
65
|
+
traces[name] = { status: 'store-absent', newest: null, detail: 'no session records found' };
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// Full projection + validation — the deepest read the verifier itself performs.
|
|
69
|
+
try {
|
|
70
|
+
const projector = name === 'claude'
|
|
71
|
+
? new ClaudeAtifProjector({ store }) : new CodexAtifProjector({ store });
|
|
72
|
+
new AtifValidator().assert(projector.project(newest), { file: newest });
|
|
73
|
+
traces[name] = { status: 'ok', newest, detail: null };
|
|
74
|
+
} catch (e) {
|
|
75
|
+
traces[name] = { status: 'DRIFT', newest, detail: String(e?.message || e) };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let plugin;
|
|
80
|
+
try {
|
|
81
|
+
const manifestDoc = JSON.parse(
|
|
82
|
+
fs.readFileSync(path.join(paths.pluginDir, '.claude-plugin/plugin.json'), 'utf8'));
|
|
83
|
+
plugin = manifestDoc.name === 'oathe'
|
|
84
|
+
? { resolves: true, detail: null }
|
|
85
|
+
: { resolves: false, detail: `plugin.json names '${manifestDoc.name}', not 'oathe'` };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
plugin = { resolves: false, detail: String(e?.message || e) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let runtime;
|
|
91
|
+
try {
|
|
92
|
+
const { resolveRuntimeProvider } = await import('./runtime/provider.mjs');
|
|
93
|
+
const provider = resolveRuntimeProvider({ config: ctx.config, paths });
|
|
94
|
+
// The resolvability probe (Finding 1): an oathe selection whose cage path exists on disk
|
|
95
|
+
// says nothing about whether `npm run link-runtime` was ever run — doctor must surface the
|
|
96
|
+
// SAME probe acceptanceRuntime()/successor() gate on, never report HEALTHY over it.
|
|
97
|
+
runtime = { provider: provider.name, requested: ctx.config.get('runtimeProvider'),
|
|
98
|
+
capabilities: provider.capabilities(), error: null, probe: provider.probe() };
|
|
99
|
+
} catch (e) {
|
|
100
|
+
runtime = { provider: null, requested: ctx.config.get('runtimeProvider'),
|
|
101
|
+
capabilities: null, error: String(e?.message || e), probe: null };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { rows, substrate: await substrate.status(), plugin, traces, runtime };
|
|
105
|
+
} finally {
|
|
106
|
+
await substrate.close();
|
|
107
|
+
}
|
|
108
|
+
}
|