@oathe/oathe 0.3.2 → 0.4.3

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.
Files changed (57) hide show
  1. package/README.md +42 -12
  2. package/assets/oathe-hero.png +0 -0
  3. package/bin/node-floor.mjs +16 -0
  4. package/bin/oathe.mjs +96 -136
  5. package/docs/PRIVACY.md +7 -6
  6. package/notch/Oathe Notch.app/Contents/Info.plist +1 -1
  7. package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
  8. package/notch/README.md +33 -18
  9. package/package.json +9 -5
  10. package/plugin/.claude-plugin/plugin.json +2 -2
  11. package/plugin/.cursor-plugin/plugin.json +2 -2
  12. package/plugin/commands/verify.md +6 -5
  13. package/plugin/hooks/heartbeat.mjs +14 -5
  14. package/plugin/hooks/hooks.json +1 -1
  15. package/plugin/hooks/lib.mjs +7 -5
  16. package/plugin/hooks/render-board.mjs +3 -3
  17. package/plugin/skills/oathe-work/SKILL.md +4 -1
  18. package/src/activation.mjs +3 -0
  19. package/src/atif.mjs +182 -348
  20. package/src/board-render.mjs +46 -42
  21. package/src/breach-digest.mjs +183 -0
  22. package/src/config.mjs +15 -3
  23. package/src/context.mjs +1 -1
  24. package/src/doctor.mjs +30 -8
  25. package/src/evidence.mjs +153 -0
  26. package/src/harnesses/catalog.mjs +12 -1
  27. package/src/harnesses/claude-roster.mjs +49 -0
  28. package/src/harnesses/claude-transcript.mjs +174 -0
  29. package/src/harnesses/claude.mjs +35 -2
  30. package/src/harnesses/codex-rollout.mjs +610 -0
  31. package/src/harnesses/codex-roster.mjs +88 -0
  32. package/src/harnesses/codex.mjs +72 -2
  33. package/src/harnesses/cursor.mjs +10 -8
  34. package/src/harnesses/fidelity.mjs +123 -0
  35. package/src/init.mjs +5 -1
  36. package/src/launch-env.mjs +5 -5
  37. package/src/launch.mjs +5 -6
  38. package/src/manifest.mjs +35 -0
  39. package/src/mcp/connection.mjs +9 -7
  40. package/src/mcp/oathe-tools.mjs +135 -75
  41. package/src/node-floor.mjs +44 -0
  42. package/src/notch-frame.mjs +152 -0
  43. package/src/oathe-annotator.mjs +113 -0
  44. package/src/pager.mjs +75 -37
  45. package/src/runtime/provider.mjs +2 -2
  46. package/src/session-host.mjs +1 -1
  47. package/src/sessions.mjs +8 -1
  48. package/src/speaker.mjs +54 -26
  49. package/src/statements.mjs +120 -2
  50. package/src/substrate.mjs +3 -3
  51. package/src/successor.mjs +2 -3
  52. package/src/trace-census.mjs +96 -0
  53. package/src/traces.mjs +98 -6
  54. package/src/uninstall.mjs +4 -1
  55. package/src/update.mjs +86 -0
  56. package/src/verifier.mjs +37 -19
  57. package/assets/oathe-hero.svg +0 -92
@@ -7,29 +7,37 @@
7
7
  // this operator's to answer for), status PULLS (`oathe ls`), and the restored-state banner
8
8
  // rides the actual pickup (oathe_pickup), never ambient session start. The model's context
9
9
  // channel still carries the full board; only the human channel keeps quiet.
10
+ //
11
+ // The breaches arrive as the BreachDigest (src/breach-digest.mjs): the push line, the rows
12
+ // under the budget, the count beyond it. This module words them and computes nothing —
13
+ // UX rules 17 and 18.
10
14
 
11
15
  import { createOatheTools } from './mcp/oathe-tools.mjs';
12
16
  import { SPEECH_ACT_RULE } from './fence.mjs';
13
-
14
-
17
+ import { BreachDigest, clip, rowLine, pullPointer } from './breach-digest.mjs';
15
18
 
16
19
  /** The board's scope, spoken once: the folder lens, or the whole machine (R-BOARD-SCOPE). */
17
20
  export const MACHINE_SCOPE_LABEL = 'all workspaces';
18
21
 
22
+ const nothingBreached = () => new BreachDigest({ breaches: [] });
23
+
19
24
  /**
20
25
  * @param {{client: {query: Function}, identity: object, workspace: string|null, config?: object,
21
- * synthetic?: boolean, all?: boolean, breaches?: object[]}} o synthetic — the session
22
- * sits on a harness staging dir (R-BOARD-SCOPE): the tools serve the full board and the
23
- * render says so. all — an honest machine lens (the notch feed): the folder filter is
24
- * dropped without borrowing synthetic's staging-dir semantics. breaches — the Pager's
25
- * digest (R-PAGER), rendered machine-wide below the board.
26
+ * synthetic?: boolean, all?: boolean, digest?: BreachDigest|null}} o synthetic — the
27
+ * session sits on a harness staging dir (R-BOARD-SCOPE): the tools serve the full board
28
+ * and the render says so. all — an honest machine lens (the notch feed): the folder
29
+ * filter is dropped without borrowing synthetic's staging-dir semantics. digest — the
30
+ * Pager's digest (R-PAGER), machine-wide, rendered below the board; null (the hook's
31
+ * fail-soft path) renders the board alone and stays silent.
26
32
  * @returns {Promise<{context: string, message: string|null, sections: object, lens: string|null}>}
27
33
  * context = the full board (model / scrollback); message = the one visible push line
28
- * (breaches only — null is silence); lens = the workspace the board was scoped to,
34
+ * (the digest's — null is silence); lens = the workspace the board was scoped to,
29
35
  * null for the whole machine
30
36
  */
31
- export async function renderBoard({ client, identity, workspace, config, synthetic = false, all = false, breaches = [] }) {
32
- const tools = createOatheTools({ client, identity, workspace, config, synthetic });
37
+ export async function renderBoard({ client, identity, workspace, config, synthetic = false, all = false, digest = null }) {
38
+ digest ??= nothingBreached();
39
+ // A read-only composition: the digest arrives from the caller, so the tools read no breach.
40
+ const tools = createOatheTools({ client, identity, workspace, config, synthetic, attention: false });
33
41
  const { sections, workspace: lens } = await tools.oathe_board({ all });
34
42
  const { mine, open, asserted, held } = sections;
35
43
  const total = mine.length + open.length + asserted.length + held.length;
@@ -42,11 +50,14 @@ export async function renderBoard({ client, identity, workspace, config, synthet
42
50
  if (total === 0) {
43
51
  lines.push(`_No open tasks ${where}._`);
44
52
  }
53
+ // UX rule 21: a root's spawned work is one counts line under it, never child bullets.
54
+ const spawned = (r) => (r.children ? [` ↳ ${r.children.line}`] : []);
45
55
  if (mine.length > 0) {
46
56
  lines.push('**Yours (still claimed by you — completion not asserted; say `continue <task>` to pick one up):**');
47
57
  for (const r of mine) {
48
58
  lines.push(`- [${r.task_id}] ${r.objective} — lease until ${r.lease_until}`);
49
59
  if (r.last_progress) lines.push(` ↳ last recorded progress${r.last_progress_at ? ` (${r.last_progress_at})` : ''}: ${r.last_progress}`);
60
+ lines.push(...spawned(r));
50
61
  }
51
62
  lines.push('');
52
63
  }
@@ -54,43 +65,31 @@ export async function renderBoard({ client, identity, workspace, config, synthet
54
65
  lines.push('**Open (claimable):**');
55
66
  for (const r of open) {
56
67
  const note = r.state === 'reopened' ? ' (came back incomplete — actionable again)' : (r.state ? ` (${r.state})` : '');
57
- lines.push(`- [${r.task_id}] ${r.objective}${note}`);
68
+ lines.push(`- [${r.task_id}] ${r.objective}${note}`, ...spawned(r));
58
69
  }
59
70
  lines.push('');
60
71
  }
61
72
  if (asserted.length > 0) {
62
73
  lines.push('**Asserted (completion claimed — awaiting a non-author verdict; `oathe verify` runs it):**');
63
- for (const r of asserted) lines.push(`- [${r.task_id}] ${r.objective}`);
74
+ for (const r of asserted) lines.push(`- [${r.task_id}] ${r.objective}`, ...spawned(r));
64
75
  lines.push('');
65
76
  }
66
77
  if (held.length > 0) {
67
78
  lines.push('**Held:**');
68
- for (const r of held) lines.push(`- [${r.task_id}] ${r.objective} (${r.principal_id})`);
79
+ for (const r of held) lines.push(`- [${r.task_id}] ${r.objective} (${r.principal_id})`, ...spawned(r));
69
80
  }
70
- if (breaches.length > 0) {
81
+ if (digest.total > 0) {
71
82
  // R-PAGER: promises breached ANYWHERE on this machine — the one place a folder lens does
72
83
  // not apply, because a breach elsewhere is still this operator's to answer for.
73
84
  lines.push('', `## Breached promises (${MACHINE_SCOPE_LABEL})`, '');
74
- for (const b of breaches) lines.push(`- [${b.task_id}] ${b.objective} — ${b.detail} (home: ${b.home})`);
85
+ for (const b of digest.rows) lines.push(`- [${b.task_id}] ${b.objective} — ${b.kind_word}: ${rowLine(b)} (home: ${b.home})`);
86
+ const more = pullPointer('context', digest.more);
87
+ if (more) lines.push(`_${more}_`);
75
88
  }
76
-
77
- // R-QUIET: breaches-or-silence. Wording is the founder's bar (2026-08-31): PERSON
78
- // words, not board words — what needs you, in two buckets. "to fix" = a verdict came
79
- // back or the verifier itself failed (a person acts); "to verify" = asserted and never
80
- // judged (the system drains these itself; the count is the queue, not a chore). Composed
81
- // HERE and only here; the hook message and the notch bar render this string verbatim.
82
- let message = null;
83
- if (breaches.length > 0) {
84
- const byKind = {};
85
- for (const b of breaches) byKind[b.kind] = (byKind[b.kind] ?? 0) + 1;
86
- const fix = (byKind.reopened ?? 0) + (byKind.stalled ?? 0);
87
- const parts = [];
88
- if (fix > 0) parts.push(`${fix} to fix`);
89
- if (byKind.overdue) parts.push(`${byKind.overdue} to verify`);
90
- if (byKind.quiet) parts.push(`${byKind.quiet} gone quiet`);
91
- message = parts.join(' · ');
92
- }
93
- return { context: lines.join('\n'), message, sections, lens };
89
+ // R-QUIET: breaches-or-silence. The visible line is the digest's push — PERSON words, the
90
+ // count by bucket, composed once (BreachDigest.push); the hook message and the notch bar
91
+ // render it verbatim.
92
+ return { context: lines.join('\n'), message: digest.push, sections, lens };
94
93
  }
95
94
 
96
95
  const BOLD = '\x1b[1m';
@@ -102,23 +101,27 @@ const OBJECTIVE_WIDTH = 48;
102
101
  * The board as an ANSI terminal splash — the launcher's human-facing render. No markdown:
103
102
  * bold ids, aligned columns, dim detail. An empty board is just the state line.
104
103
  */
105
- export function renderSplash({ message, sections, workspace, breaches = [] }) {
104
+ export function renderSplash({ digest = null, sections, workspace }) {
105
+ digest ??= nothingBreached();
106
106
  const { mine, open, asserted, held } = sections;
107
- const all = [...mine, ...open, ...asserted, ...held, ...breaches];
107
+ const all = [...mine, ...open, ...asserted, ...held, ...digest.rows];
108
108
  const scope = `${DIM}${workspace ?? MACHINE_SCOPE_LABEL}${RESET}`;
109
- // R-QUIET: a silent message leaves just the scope line — the board below speaks for itself.
110
- const out = ['', message ? ` ${message} ${scope}` : ` ${scope}`, ''];
109
+ // R-QUIET: a silent push leaves just the scope line — the board below speaks for itself.
110
+ const out = ['', digest.push ? ` ${digest.push} ${scope}` : ` ${scope}`, ''];
111
111
  if (all.length === 0) return `${out.join('\n')}\n`;
112
112
 
113
113
  const idWidth = Math.max(...all.map((r) => r.task_id.length));
114
- const clip = (text) => (text.length > OBJECTIVE_WIDTH ? `${text.slice(0, OBJECTIVE_WIDTH - 1)}…` : text);
115
114
  const row = (r, detail) => ` ${BOLD}${r.task_id.padEnd(idWidth)}${RESET} `
116
- + `${clip(r.objective).padEnd(OBJECTIVE_WIDTH)} ${DIM}${detail}${RESET}`;
115
+ + `${clip(r.objective, OBJECTIVE_WIDTH).padEnd(OBJECTIVE_WIDTH)} ${DIM}${detail}${RESET}`;
117
116
 
118
- const section = (header, rows, detailFor) => {
117
+ const section = (header, rows, detailFor, tail = null) => {
119
118
  if (rows.length === 0) return;
120
119
  out.push(` ${BOLD}${DIM}${header}${RESET}`);
121
- for (const r of rows) out.push(row(r, detailFor(r)));
120
+ for (const r of rows) {
121
+ out.push(row(r, detailFor(r)));
122
+ if (r.children) out.push(` ${DIM}↳ ${r.children.line}${RESET}`); // UX rule 21: one counts line
123
+ }
124
+ if (tail) out.push(` ${DIM}${tail}${RESET}`);
122
125
  out.push('');
123
126
  };
124
127
  section('YOURS (completion not asserted)', mine, (r) => (r.last_progress
@@ -127,6 +130,7 @@ export function renderSplash({ message, sections, workspace, breaches = [] }) {
127
130
  section('OPEN', open, (r) => (r.state === 'reopened' ? 'back — incomplete, actionable' : (r.state ?? 'unclaimed')));
128
131
  section('ASSERTED', asserted, () => 'awaiting verdict');
129
132
  section('HELD', held, (r) => r.principal_id);
130
- section(`BREACHED PROMISES (${MACHINE_SCOPE_LABEL})`, breaches, (b) => `${b.detail} · ${b.home}`);
133
+ section(`BREACHED PROMISES (${MACHINE_SCOPE_LABEL})`, digest.rows,
134
+ (b) => `${b.kind_word}: ${rowLine(b)} · ${b.home}`, pullPointer('splash', digest.more));
131
135
  return `${out.join('\n')}\n`;
132
136
  }
@@ -0,0 +1,183 @@
1
+ // oathe — the BreachDigest: the ONE budget over the pager's facts.
2
+ //
3
+ // The pager (src/pager.mjs) reads conditions and hands over whole rows; every surface that
4
+ // shows a breach — SessionStart context, the launch splash, tool attention, `oathe ls`, the
5
+ // glass — reads THIS digest and words it, never computing its own. R-PAGER + ruling 2
6
+ // (2026-09-01): one row per task, or per sibling group — children spawned under one claim
7
+ // are one row under the group's sharpest breach, and a child never has its own row while
8
+ // its parent is in view. UX rule 18: a digest is a budget, not a wall — sharpest first,
9
+ // DIGEST_ROW_CAP rows, then one `+N more` that names the pull; a rendered detail is clipped
10
+ // by its renderer, the data stays whole. Pure and synchronous: facts in, a budget out.
11
+ //
12
+ // Every word about a kind lives in KINDS — its person word (`rejected`), its push bucket
13
+ // (`to fix`), its one act (`continue ↗`) — and the kinds' order IS the sharpness order.
14
+ // Nothing about a kind is spelled twice: the glass reads the words off the frame, the
15
+ // renderers read them off the rows.
16
+
17
+ /** The resumption's word — a breach that continues into the work, and every working claim. */
18
+ export const CONTINUE_ACT = 'continue ↗';
19
+ export const KINDS = Object.freeze({
20
+ reopened: Object.freeze({ word: 'rejected', bucket: 'fix', act: CONTINUE_ACT }),
21
+ stalled: Object.freeze({ word: 'verify failed', bucket: 'fix', act: 'retry ↗' }),
22
+ overdue: Object.freeze({ word: 'never verified', bucket: 'verify', act: 'verify ↗' }),
23
+ quiet: Object.freeze({ word: 'quiet', bucket: 'quiet', act: CONTINUE_ACT }),
24
+ });
25
+ /** The push buckets, in the order the one ambient line speaks them. */
26
+ export const BUCKET_WORDS = Object.freeze({ fix: 'to fix', verify: 'to verify', quiet: 'gone quiet' });
27
+ /** The kinds in sharpness order: a verdict that came back first, an unjudged assertion last. */
28
+ export const BREACH_KINDS = Object.freeze(Object.keys(KINDS));
29
+ /** Rows a surface shows before `+N more` — the glass sheet (Theme.swift rowCap) is sized for eight. */
30
+ export const DIGEST_ROW_CAP = 8;
31
+ /** A rendered detail's width; the whole text rides the row for the card and oathe_board. */
32
+ export const DETAIL_CLIP = 160;
33
+
34
+ // The pull each channel points at when the budget is exceeded — worded once, placed by the
35
+ // renderer. The glass gets the number, never a sentence (its `+N more` row is its own).
36
+ const PULL = Object.freeze({
37
+ context: 'oathe_board lists every breach on this board; `oathe ls` every one on this machine',
38
+ splash: 'oathe ls',
39
+ attention: 'oathe_board lists every breach on this board',
40
+ });
41
+
42
+ export class DigestError extends Error {
43
+ constructor(code, message) {
44
+ super(message);
45
+ this.name = 'DigestError';
46
+ this.code = code;
47
+ }
48
+ }
49
+
50
+ /** The one order every breach list is in: kind rank, then the breach's own clock, then id. */
51
+ export function breachOrder(a, b) {
52
+ return (BREACH_KINDS.indexOf(a.kind) - BREACH_KINDS.indexOf(b.kind))
53
+ || String(a.at ?? '').localeCompare(String(b.at ?? ''))
54
+ || String(a.task_id).localeCompare(String(b.task_id));
55
+ }
56
+
57
+ export function clip(text, width) {
58
+ return text.length > width ? `${text.slice(0, width - 1)}…` : text;
59
+ }
60
+
61
+ export function clipDetail(text) {
62
+ return clip(text, DETAIL_CLIP);
63
+ }
64
+
65
+ /** A row's one-line form for a text surface: a single is its detail, clipped; a group its spawn count. */
66
+ export function rowLine(row) {
67
+ return row.group ? `${row.group.n} spawned` : clipDetail(row.detail);
68
+ }
69
+
70
+ export function pullPointer(channel, more) {
71
+ const pull = PULL[channel];
72
+ if (!pull) {
73
+ throw new DigestError('OATHE_DIGEST_CHANNEL_UNKNOWN',
74
+ `no pull wording for channel '${channel}' (known: ${Object.keys(PULL).join(', ')})`);
75
+ }
76
+ return more > 0 ? `+${more} more — ${pull}` : null;
77
+ }
78
+
79
+ /** `19 rejected · 1 verify failed` — kinds in sharpness order, zero counts omitted. */
80
+ function countWords(byKind) {
81
+ return BREACH_KINDS.filter((kind) => byKind[kind]).map((kind) => `${byKind[kind]} ${KINDS[kind].word}`).join(' · ');
82
+ }
83
+
84
+ function pushLine(counts) {
85
+ const byBucket = {};
86
+ for (const kind of BREACH_KINDS) byBucket[KINDS[kind].bucket] = (byBucket[KINDS[kind].bucket] ?? 0) + counts[kind];
87
+ const parts = Object.keys(BUCKET_WORDS).filter((bucket) => byBucket[bucket] > 0)
88
+ .map((bucket) => `${byBucket[bucket]} ${BUCKET_WORDS[bucket]}`);
89
+ return parts.length > 0 ? parts.join(' · ') : null;
90
+ }
91
+
92
+ function single(breach) {
93
+ return { ...breach, kind_word: KINDS[breach.kind].word, group: null };
94
+ }
95
+
96
+ /**
97
+ * One row for a parent and the children spawned under it. `own` is the parent's own breach
98
+ * when it has one (its facts lead the row); otherwise the row is synthesized from what the
99
+ * children know of their parent. The row's kind is the sharpest among all members; its
100
+ * clock is the oldest member of that kind, which is what a person reads as the age.
101
+ */
102
+ function groupRow(own, children) {
103
+ const members = [...(own ? [own] : []), ...children].sort(breachOrder);
104
+ const sortedChildren = [...children].sort(breachOrder);
105
+ const byKind = {};
106
+ for (const child of children) byKind[child.kind] = (byKind[child.kind] ?? 0) + 1;
107
+ const shown = sortedChildren.slice(0, DIGEST_ROW_CAP);
108
+ const more = children.length - shown.length;
109
+ const lead = own ?? members[0];
110
+ const detail = [
111
+ ...(own ? [own.detail] : []),
112
+ ...shown.map((child) => `${child.task_id} · ${KINDS[child.kind].word} · ${child.detail}`),
113
+ ...(more > 0 ? [`+${more} more`] : []),
114
+ ].join('\n');
115
+ return {
116
+ kind: members[0].kind,
117
+ kind_word: [...(own ? [KINDS[own.kind].word] : []), countWords(byKind)].join(' · '),
118
+ task_id: own ? own.task_id : children[0].parent,
119
+ objective: own ? own.objective : children[0].parent_objective,
120
+ home: lead.home,
121
+ home_ref: lead.home_ref,
122
+ detail,
123
+ at: members[0].at,
124
+ group: { n: children.length, by_kind: byKind, children: shown.map((child) => child.task_id), more },
125
+ };
126
+ }
127
+
128
+ /** Rows in breach order, and each breach's row (a single is its own; a child's is its parent's). */
129
+ function groupSiblings(breaches) {
130
+ const childrenOf = new Map();
131
+ for (const breach of breaches) {
132
+ if (!breach.parent) continue;
133
+ if (!childrenOf.has(breach.parent)) childrenOf.set(breach.parent, []);
134
+ childrenOf.get(breach.parent).push(breach);
135
+ }
136
+ const rowOf = new Map();
137
+ const place = (row, members) => { for (const member of members) rowOf.set(member, row); return row; };
138
+ const rows = [];
139
+ for (const breach of breaches) {
140
+ if (breach.parent) continue;
141
+ const children = childrenOf.get(breach.task_id) ?? [];
142
+ childrenOf.delete(breach.task_id);
143
+ rows.push(children.length > 0 ? place(groupRow(breach, children), [breach, ...children]) : place(single(breach), [breach]));
144
+ }
145
+ for (const children of childrenOf.values()) rows.push(place(groupRow(null, children), children));
146
+ return { rows: rows.sort(breachOrder), rowOf };
147
+ }
148
+
149
+ export class BreachDigest {
150
+ #breaches;
151
+ #rowOf;
152
+
153
+ /** @param {{breaches: object[]}} o the pager's rows, whole */
154
+ constructor({ breaches }) {
155
+ for (const breach of breaches) {
156
+ if (!(breach.kind in KINDS)) {
157
+ throw new DigestError('OATHE_DIGEST_KIND_UNKNOWN',
158
+ `breach '${breach.task_id}' has kind '${breach.kind}' — the digest knows ${BREACH_KINDS.join(', ')}`);
159
+ }
160
+ }
161
+ this.#breaches = breaches;
162
+ this.counts = Object.fromEntries(BREACH_KINDS.map((kind) => [kind, 0]));
163
+ for (const breach of breaches) this.counts[breach.kind] += 1;
164
+ this.total = breaches.length;
165
+ this.push = pushLine(this.counts);
166
+ const { rows, rowOf } = groupSiblings(breaches);
167
+ this.#rowOf = rowOf;
168
+ this.groups = rows;
169
+ this.rows = rows.slice(0, DIGEST_ROW_CAP);
170
+ this.more = rows.length - this.rows.length;
171
+ }
172
+
173
+ /** This board's digest — the facts homed on `homeRef`; `null` is the whole machine (this). */
174
+ scoped(homeRef) {
175
+ if (homeRef === null) return this;
176
+ return new BreachDigest({ breaches: this.#breaches.filter((breach) => breach.home_ref === homeRef) });
177
+ }
178
+
179
+ /** The digest over the rows `keep` accepts — a group is kept or dropped whole. */
180
+ filter(keep) {
181
+ return new BreachDigest({ breaches: this.#breaches.filter((breach) => keep(this.#rowOf.get(breach))) });
182
+ }
183
+ }
package/src/config.mjs CHANGED
@@ -20,10 +20,18 @@ export class ConfigError extends Error {
20
20
 
21
21
  const ENGINES = verifierCapable();
22
22
 
23
+ /** The OS user — the principal's one default, named here and nowhere else (D0-PREVIEW:
24
+ * "principal from OATHE_PRINCIPAL or the OS user"). os.userInfo() refuses in a container
25
+ * whose uid has no passwd entry; USER is the next truth and 'operator' the last word — the
26
+ * fallback three consumers each hardcoded before 2026-09-03, now in this one place. */
27
+ function osUser() {
28
+ try { return os.userInfo().username; } catch { return process.env.USER || 'operator'; }
29
+ }
30
+
23
31
  /** Every key: default, env var, validator. Adding a tunable means adding a row HERE. */
24
32
  const KEYS = Object.freeze({
25
33
  org: { default: 'oathe', env: 'OATHE_ORG', check: nonEmptyString },
26
- principal: { default: null, env: 'OATHE_PRINCIPAL', check: nullOrString },
34
+ principal: { default: osUser(), env: 'OATHE_PRINCIPAL', check: nonEmptyString },
27
35
  department: { default: 'operator', env: 'OATHE_DEPARTMENT', check: nonEmptyString },
28
36
  db: { default: 'oathe_local', env: 'OATHE_DB', check: nonEmptyString },
29
37
  // Standard-first: honor libpq's PGHOST when set; otherwise the platform's conventional
@@ -43,6 +51,10 @@ const KEYS = Object.freeze({
43
51
  defaultAgent: { default: null, env: 'OATHE_DEFAULT_AGENT', check: nullOrOneOf(launchable()) },
44
52
  verifierPrincipal: { default: 'oathe-verifier', env: 'OATHE_VERIFIER_PRINCIPAL', check: nonEmptyString },
45
53
  verifierEvidenceBudget: { default: 24000, env: 'OATHE_VERIFIER_EVIDENCE_BUDGET', check: positiveInt },
54
+ // The trace census sweep window (doctor and the trace-census lane share these): how many
55
+ // days back and at most how many records per engine — the cost knobs for busy stores.
56
+ traceCensusDays: { default: 3, env: 'OATHE_TRACE_CENSUS_DAYS', check: positiveInt },
57
+ traceCensusMaxFiles: { default: 40, env: 'OATHE_TRACE_CENSUS_MAX_FILES', check: positiveInt },
46
58
  runtimeProvider: { default: 'auto', env: 'OATHE_RUNTIME_PROVIDER', check: oneOf(['auto', 'oathe', 'standalone']) },
47
59
  // Activation (registry row + context-file fences) on first use in a workspace: the off
48
60
  // switch for machines that want register-only sessions.
@@ -53,8 +65,8 @@ const KEYS = Object.freeze({
53
65
  // R-PAGER: an active claim with no non-trace progress statement inside this many hours is
54
66
  // a breached promise (paged at session start). Lifecycle facts like a lapsed lease are not.
55
67
  pagerQuietHours: { default: 24, env: 'OATHE_PAGER_QUIET_HOURS', check: positiveInt },
56
- // The notch app: the machine opts in by naming its binary — init then owns the
57
- // LaunchAgent (src/notch.mjs). D1 packaging will default this to a bundled binary.
68
+ // The notch app: null is the app the package carries (notch/Oathe Notch.app, built at
69
+ // prepack); a path overrides it for development. init owns the LaunchAgent (src/notch.mjs).
58
70
  notchApp: { default: null, env: 'OATHE_NOTCH_APP', check: nullOrString },
59
71
  // What "in motion" means on the glass: a claim whose last word (statement, or the claim
60
72
  // itself) is younger than this earns a row; idle-held work stays in `oathe ls`.
package/src/context.mjs CHANGED
@@ -24,7 +24,7 @@ export function buildContext({ env = process.env, exec, cwd = process.cwd() } =
24
24
  const substrate = new Substrate({ database: config.get('db'), paths, env, config });
25
25
  const identity = {
26
26
  orgId: config.get('org'),
27
- principalId: config.get('principal') || env.USER || 'operator',
27
+ principalId: config.get('principal'),
28
28
  department: config.get('department'),
29
29
  };
30
30
  return { paths, home, manifest, harnesses, substrate, identity, config, version: packageVersion(paths), env };
package/src/doctor.mjs CHANGED
@@ -54,9 +54,10 @@ function verifyJsonArrayRow(row) {
54
54
  const RUNTIME_BOUND_CODES = new Set(['TRACE_CODEX_SQLITE_UNSUPPORTED']);
55
55
 
56
56
  /**
57
- * The trace-contract status for a failed projection: a runtime bound (node:sqlite missing on
58
- * Node < 22.5 — the store never got to read the record) is RUNTIME; anything else is format
59
- * DRIFT. Both stay loud; the drift lanes need them told apart.
57
+ * The trace-contract status for a failed projection: a runtime bound (node:sqlite is
58
+ * unflagged only from Node 22.13.0 / 23.4.0 — below that the store never got to read the
59
+ * record) is RUNTIME; anything else is format DRIFT. Both stay loud; the drift lanes need
60
+ * them told apart.
60
61
  */
61
62
  export function traceStatusOf(error) {
62
63
  return RUNTIME_BOUND_CODES.has(error?.code) ? 'RUNTIME' : 'DRIFT';
@@ -136,7 +137,7 @@ export async function runDoctor({ env = process.env } = {}) {
136
137
  // reports DRIFT loudly. An absent store is a distinct, visible status — never a silent skip.
137
138
  // Store, newest-record lookup, and projector are each engine adapter's own facts.
138
139
  const { byName, traceStores } = await import('./harnesses/catalog.mjs');
139
- const { AtifValidator } = await import('./atif.mjs');
140
+ const { projectAnnotated } = await import('./oathe-annotator.mjs');
140
141
  const home = ctx.home;
141
142
  const traces = {};
142
143
  for (const name of traceStores()) {
@@ -147,11 +148,32 @@ export async function runDoctor({ env = process.env } = {}) {
147
148
  traces[name] = { status: 'store-absent', newest: null, detail: 'no session records found' };
148
149
  continue;
149
150
  }
150
- // Full projection + validation — the deepest read the verifier itself performs.
151
+ // The full read the verifier itself performs (converter, validated; then the annotator)
152
+ // — then the census sweep over the recent window: an undeclared row type or a fidelity
153
+ // failure is DRIFT the day it appears on this machine, not the day a verify mis-judges.
151
154
  try {
152
- const projector = await capability.projector({ store });
153
- new AtifValidator().assert(projector.project(newest), { file: newest });
154
- traces[name] = { status: 'ok', newest, detail: null };
155
+ await projectAnnotated(newest, { home });
156
+ const { censusOf, fidelityOf } = await import('./trace-census.mjs');
157
+ const files = capability.recent(store, {
158
+ days: ctx.config.get('traceCensusDays'), maxFiles: ctx.config.get('traceCensusMaxFiles'),
159
+ });
160
+ const census = censusOf({ store, roster: capability.roster, kindOf: capability.kindOf, files });
161
+ const fidelity = await fidelityOf({
162
+ store, project: (file) => projectAnnotated(file, { home }), fidelity: capability.fidelity, files, traceStatus: traceStatusOf,
163
+ });
164
+ const failures = [
165
+ ...census.undeclared.map((u) => `undeclared ${u.channel}.${u.type} ×${u.count} (first: ${u.example})`),
166
+ ...fidelity.projectionErrors.filter((p) => p.status === 'DRIFT').map((p) => `${p.file}: ${p.detail}`),
167
+ ...fidelity.probes.flatMap((p) => p.failed.map((f) => `${p.probe}: ${f.file}: ${f.detail}`)),
168
+ ];
169
+ const runtime = fidelity.projectionErrors.find((p) => p.status === 'RUNTIME');
170
+ traces[name] = {
171
+ status: runtime ? 'RUNTIME' : failures.length > 0 ? 'DRIFT' : 'ok',
172
+ newest,
173
+ census: { swept: census.swept, undeclared: census.undeclared.length,
174
+ fidelity_failures: fidelity.probes.reduce((n, p) => n + p.failed.length, 0) },
175
+ detail: runtime ? runtime.detail : failures[0] ?? null,
176
+ };
155
177
  } catch (e) {
156
178
  traces[name] = { status: traceStatusOf(e), newest, detail: String(e?.message || e) };
157
179
  }
@@ -0,0 +1,153 @@
1
+ // oathe — the evidence renderer: ONE budget-true rendering of a trajectory for a judge's
2
+ // eyes. Every emitted character is accounted — header, elision lines, subagent headers, the
3
+ // join newlines — so `render(t, {budget}).length <= budget` is a hard invariant, not a hope.
4
+ // Truncation is TAIL-PRIORITIZED (the most recent steps survive whole) and ANNOUNCED — an
5
+ // elision the reader cannot see is evidence silently lost.
6
+
7
+ import { AtifError } from './atif.mjs';
8
+
9
+ // Design constants, not tunables — no consumer has a story for turning them (founder
10
+ // ruling 2026-09-01: no speculative config).
11
+ const CLIP = { message: 300, args: 140, result: 200, user: 200 };
12
+ const SUBAGENT_BUDGET_SHARE = 0.3;
13
+
14
+ function clip(text, max) {
15
+ const flat = String(text).replaceAll('\n', ' ⏎ ');
16
+ return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat;
17
+ }
18
+
19
+ /** Hard cap for whole strings (multi-line allowed) — the last resort, still announced by '…'. */
20
+ function clipTo(text, max) {
21
+ if (text.length <= max) return text;
22
+ return max <= 1 ? '…'.slice(0, max) : `${text.slice(0, max - 1)}…`;
23
+ }
24
+
25
+ function plural(n, word) {
26
+ return `${n} ${word}${n === 1 ? '' : 's'}`;
27
+ }
28
+
29
+ /**
30
+ * One step → its aligned lines: SAID (the claims), CLAIM (speech acts), DID (actions), GOT
31
+ * (outcomes) — and FROM (a message another agent sent this one: a delegated brief, a child's
32
+ * answer), which is never SAID.
33
+ */
34
+ function stepLines(step) {
35
+ const lines = [];
36
+ const inbound = step.extra?.record?.inbound;
37
+ if (inbound) {
38
+ // Codex names an author and a message type; Claude a kind and, for a notification, the task.
39
+ const ref = step.observation?.results?.[0]?.subagent_trajectory_ref?.[0]?.trajectory_id;
40
+ const text = step.observation?.results?.[0]?.content ?? step.message;
41
+ const detail = inbound.message_type ?? inbound.task_id;
42
+ return [`FROM ${inbound.author ?? inbound.kind}${detail ? ` (${detail})` : ''}${ref ? ` → subagent ${ref}` : ''}: ${clip(text, CLIP.user)}`];
43
+ }
44
+ if (step.source === 'user') return [`USER: ${clip(step.message, CLIP.user)}`];
45
+ if (step.source === 'system') return [`SYSTEM: ${clip(step.message, CLIP.user)}`];
46
+ if (step.message) lines.push(`SAID: ${clip(step.message, CLIP.message)}`);
47
+ for (const event of step.extra?.oathe?.claim_events ?? []) {
48
+ lines.push(`CLAIM(${event.verb}${event.task_id ? ` ${event.task_id}` : ''})`);
49
+ }
50
+ for (const call of step.tool_calls ?? []) {
51
+ lines.push(`DID: ${call.function_name}(${clip(JSON.stringify(call.arguments), CLIP.args)})`);
52
+ }
53
+ for (const result of step.observation?.results ?? []) {
54
+ const exit = result.extra?.oathe?.observed?.exit_code;
55
+ lines.push(`GOT${exit !== undefined ? ` [exit ${exit}]` : ''}: ${clip(result.content, CLIP.result)}`);
56
+ }
57
+ return lines;
58
+ }
59
+
60
+ export class EvidenceRenderer {
61
+ /** @returns {string} guaranteed `length <= budget` (a violation is an accounting bug and throws) */
62
+ render(trajectory, { budget }) {
63
+ const subagents = trajectory.subagent_trajectories ?? [];
64
+ const joins = subagents.length; // '\n' between the main section and each child section
65
+ const usable = Math.max(0, budget - joins);
66
+ const mainBudget = subagents.length > 0 ? Math.floor(usable * (1 - SUBAGENT_BUDGET_SHARE)) : usable;
67
+ const childAllocation = subagents.length > 0 ? Math.floor((usable - mainBudget) / subagents.length) : 0;
68
+
69
+ const parts = [this.#section(trajectory, mainBudget)];
70
+ for (const child of subagents) parts.push(this.#childSection(child, childAllocation));
71
+ const out = parts.join('\n');
72
+ if (out.length > budget) {
73
+ throw new AtifError('ATIF_EVIDENCE_BUDGET_EXCEEDED',
74
+ `rendered ${out.length} chars against a ${budget} budget — the renderer's accounting broke`,
75
+ { rendered: out.length, budget });
76
+ }
77
+ return out;
78
+ }
79
+
80
+ #childSection(child, allocation) {
81
+ const meta = child.extra?.record?.subagent_meta;
82
+ const label = meta?.agentType ?? meta?.agent_nickname;
83
+ const head = `SUBAGENT ${child.trajectory_id}${label ? ` (${label})` : ''}`;
84
+ if (head.length + 1 >= allocation) return clipTo(head, allocation);
85
+ return `${head}\n${this.render(child, { budget: allocation - head.length - 1 })}`;
86
+ }
87
+
88
+ /** The header + step body of ONE trajectory, within exactly sectionBudget characters. */
89
+ #section(trajectory, sectionBudget) {
90
+ // Record facts are the converter's (extra.record); the slice marker is the annotator's.
91
+ const record = trajectory.extra?.record ?? {};
92
+ const oathe = trajectory.extra?.oathe ?? {};
93
+ const headerLines = [
94
+ `TRACE ${trajectory.session_id} (${trajectory.agent?.name}`
95
+ + `${record.session_title ? ` — "${record.session_title}"` : ''})`,
96
+ ...(record.files_touched?.length ? [`files touched: ${record.files_touched.join(', ')}`] : []),
97
+ ];
98
+ // What the converter could not place is announced, never hidden: rows outside the roster,
99
+ // items that completed no call.
100
+ for (const [key, noun] of [['unrecognized_rows', 'unrecognized row'], ['uncorrelated_items', 'uncorrelated item']]) {
101
+ if (!record[key]) continue;
102
+ const total = Object.values(record[key]).reduce((a, b) => a + b, 0);
103
+ headerLines.push(`[${plural(total, noun)}: ${Object.keys(record[key]).sort().join(', ')}]`);
104
+ }
105
+ if (oathe.sliced) {
106
+ headerLines.push(`[evidence sliced to task ${oathe.sliced.task_id}`
107
+ + `${oathe.sliced.subagents_elided > 0 ? `; ${plural(oathe.sliced.subagents_elided, 'sibling subagent')} elided` : ''}]`);
108
+ }
109
+ // Inherited context (a forked child's copy of its parent's turns) is not this agent's
110
+ // work: elided from the record it is judged on, and announced.
111
+ const copied = (trajectory.steps ?? []).filter((s) => s.is_copied_context === true).length;
112
+ if (copied > 0) headerLines.push(`[${plural(copied, 'copied-context step')} elided]`);
113
+ const header = headerLines.join('\n');
114
+ if (header.length >= sectionBudget) return clipTo(header, sectionBudget);
115
+
116
+ const steps = (trajectory.steps ?? []).filter((s) => s.is_copied_context !== true);
117
+ const blocks = steps.map((step) => stepLines(step).map((l) => ` ${l}`).join('\n'));
118
+ const stepBudget = sectionBudget - header.length;
119
+
120
+ // First pass: everything fits whole → no elision machinery at all.
121
+ const totalCost = blocks.reduce((n, b) => n + b.length + 1, 0);
122
+ if (totalCost <= stepBudget) return [header, ...blocks].join('\n');
123
+
124
+ // Elision pass: reserve room for the announcement (an upper bound — computed over ALL
125
+ // steps, so the real line, over fewer, always fits), then keep whole blocks tail-first.
126
+ const elisionFor = (elided) => {
127
+ const toolCalls = elided.reduce((n, s) => n + (s.tool_calls?.length ?? 0), 0);
128
+ const claims = elided.reduce((n, s) => n + (s.extra?.oathe?.claim_events?.length ?? 0), 0);
129
+ return ` [${plural(elided.length, 'earlier step')} elided: `
130
+ + `${plural(toolCalls, 'tool call')}, ${plural(claims, 'claim')}]`;
131
+ };
132
+ const reserve = elisionFor(steps).length + 1;
133
+ const kept = [];
134
+ let spent = 0;
135
+ for (let at = blocks.length - 1; at >= 0; at -= 1) {
136
+ const cost = blocks[at].length + 1;
137
+ if (spent + cost > stepBudget - reserve) break;
138
+ kept.unshift(at);
139
+ spent += cost;
140
+ }
141
+ const elisionLine = elisionFor(steps.slice(0, kept[0] ?? steps.length));
142
+ const body = [clipTo(elisionLine, Math.max(0, stepBudget - spent - 1)), ...kept.map((at) => blocks[at])];
143
+ return [header, ...body].join('\n');
144
+ }
145
+ }
146
+
147
+ /**
148
+ * The deterministic human/engine-facing rendering of a trajectory — the thin functional edge
149
+ * over EvidenceRenderer (the one budget-true implementation).
150
+ */
151
+ export function renderEvidenceView(trajectory, { budget }) {
152
+ return new EvidenceRenderer().render(trajectory, { budget });
153
+ }
@@ -120,7 +120,7 @@ export function ownerOfTracePath(file) {
120
120
 
121
121
  /**
122
122
  * The NEAREST adapter-owned process in an ancestry chain — the harness the chain speaks
123
- * for. Harnesses interpose helpers between themselves and their children (cursor-agent
123
+ * for. Harnesses interpose helpers between themselves and their children (Cursor's agent CLI
124
124
  * runs hooks through a /bin/zsh; MCP servers are node), so ownership is never decided by
125
125
  * the chain's head alone. -1 when nobody in the chain is a harness. ONE implementation:
126
126
  * surface naming, speaker resolution, and hook registration all ask here.
@@ -161,6 +161,17 @@ export async function projectorFor(file, { home } = {}) {
161
161
  return traces.projector({ store });
162
162
  }
163
163
 
164
+ /**
165
+ * The file a session's rows actually live in, asked of the store that owns the reported
166
+ * path — each store knows how its harness rotates ids and where it keeps writing (see the
167
+ * stores' transcriptFor). A path no store owns, or none at all, is returned as reported.
168
+ */
169
+ export function transcriptFor({ sessionId, reportedPath, home } = {}) {
170
+ const owner = ownerOfTracePath(reportedPath ?? '');
171
+ if (owner === null) return reportedPath ?? null;
172
+ return byName(owner).traces.store({ home }).transcriptFor({ sessionId, reportedPath });
173
+ }
174
+
164
175
  /** Instantiate every adapter whose wiring exists — the init/uninstall roster. */
165
176
  export function buildWireable({ home, envPath, paths, exec }) {
166
177
  return HARNESS_CLASSES.filter((C) => C.wiring !== null).map((C) => new C({ home, envPath, paths, exec }));