@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.
- package/README.md +42 -12
- package/assets/oathe-hero.png +0 -0
- package/bin/node-floor.mjs +16 -0
- package/bin/oathe.mjs +96 -136
- package/docs/PRIVACY.md +7 -6
- package/notch/Oathe Notch.app/Contents/Info.plist +1 -1
- package/notch/Oathe Notch.app/Contents/MacOS/OatheNotch +0 -0
- package/notch/README.md +33 -18
- package/package.json +9 -5
- package/plugin/.claude-plugin/plugin.json +2 -2
- package/plugin/.cursor-plugin/plugin.json +2 -2
- package/plugin/commands/verify.md +6 -5
- package/plugin/hooks/heartbeat.mjs +14 -5
- package/plugin/hooks/hooks.json +1 -1
- package/plugin/hooks/lib.mjs +7 -5
- package/plugin/hooks/render-board.mjs +3 -3
- package/plugin/skills/oathe-work/SKILL.md +4 -1
- package/src/activation.mjs +3 -0
- package/src/atif.mjs +182 -348
- package/src/board-render.mjs +46 -42
- package/src/breach-digest.mjs +183 -0
- package/src/config.mjs +15 -3
- package/src/context.mjs +1 -1
- package/src/doctor.mjs +30 -8
- package/src/evidence.mjs +153 -0
- package/src/harnesses/catalog.mjs +12 -1
- package/src/harnesses/claude-roster.mjs +49 -0
- package/src/harnesses/claude-transcript.mjs +174 -0
- package/src/harnesses/claude.mjs +35 -2
- package/src/harnesses/codex-rollout.mjs +610 -0
- package/src/harnesses/codex-roster.mjs +88 -0
- package/src/harnesses/codex.mjs +72 -2
- package/src/harnesses/cursor.mjs +10 -8
- package/src/harnesses/fidelity.mjs +123 -0
- package/src/init.mjs +5 -1
- package/src/launch-env.mjs +5 -5
- package/src/launch.mjs +5 -6
- package/src/manifest.mjs +35 -0
- package/src/mcp/connection.mjs +9 -7
- package/src/mcp/oathe-tools.mjs +135 -75
- package/src/node-floor.mjs +44 -0
- package/src/notch-frame.mjs +152 -0
- package/src/oathe-annotator.mjs +113 -0
- package/src/pager.mjs +75 -37
- package/src/runtime/provider.mjs +2 -2
- package/src/session-host.mjs +1 -1
- package/src/sessions.mjs +8 -1
- package/src/speaker.mjs +54 -26
- package/src/statements.mjs +120 -2
- package/src/substrate.mjs +3 -3
- package/src/successor.mjs +2 -3
- package/src/trace-census.mjs +96 -0
- package/src/traces.mjs +98 -6
- package/src/uninstall.mjs +4 -1
- package/src/update.mjs +86 -0
- package/src/verifier.mjs +37 -19
- package/assets/oathe-hero.svg +0 -92
package/src/atif.mjs
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
// oathe — ATIF projection: both
|
|
2
|
-
// Agent Trajectory Interchange Format (v1.7)
|
|
3
|
-
//
|
|
4
|
-
// (docs/atif-oathe.md).
|
|
1
|
+
// oathe — ATIF projection: the raw traces of both trace stores (Claude Code, Codex), derived at read time into Harbor's
|
|
2
|
+
// Agent Trajectory Interchange Format (v1.7). A projector is a CONVERTER: its output is pure
|
|
3
|
+
// ATIF — what a Harbor converter could also emit — with the raw-record facts ATIF has no field
|
|
4
|
+
// for under the converter's one namespace, `extra.record` (docs/atif-oathe.md). oathe's
|
|
5
|
+
// claims-vs-actions layer is the annotator's (src/oathe-annotator.mjs, `extra.oathe`), applied
|
|
6
|
+
// over any valid trajectory. Raw stores stay ground truth; a projector never emits an invalid
|
|
5
7
|
// trajectory (finalize() validates); anything unmappable is a typed refusal, never a silent
|
|
6
8
|
// drop. The reference models forbid unknown fields outside `extra` — so does our validator.
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
import { makeToolDefs } from './mcp/oathe-tools.mjs';
|
|
10
|
-
|
|
10
|
+
/** What the converters emit — what the reference converters emit (Harbor codex.py, claude_code.py). */
|
|
11
11
|
export const ATIF_SCHEMA_VERSION = 'ATIF-v1.7';
|
|
12
|
-
export const OATHE_CONVENTION_VERSION = 1;
|
|
13
12
|
|
|
14
|
-
/** Accepted
|
|
13
|
+
/** Accepted inbound: the reference models' Literal v1.0..v1.8 (v1.8 added audio content parts). */
|
|
15
14
|
const KNOWN_SCHEMA_VERSIONS = Object.freeze(
|
|
16
|
-
Array.from({ length:
|
|
15
|
+
Array.from({ length: 9 }, (_, i) => `ATIF-v1.${i}`),
|
|
17
16
|
);
|
|
18
17
|
|
|
19
|
-
/** The oathe speech-act verbs — derived from the server's own tool defs, never retyped. */
|
|
20
|
-
const OATHE_VERBS = Object.freeze(makeToolDefs().map((t) => t.name));
|
|
21
|
-
|
|
22
|
-
const EXIT_CODE_PATTERN = /[Ee]xit code:?\s+(\d+)/;
|
|
23
|
-
|
|
24
18
|
export class AtifError extends Error {
|
|
25
19
|
constructor(code, message, details = {}) {
|
|
26
20
|
super(message);
|
|
@@ -33,7 +27,7 @@ export class AtifError extends Error {
|
|
|
33
27
|
// --------------------------------------------------------------------------- shared assembly
|
|
34
28
|
|
|
35
29
|
/** Text of a content part list (Claude tool_result content may itself be a part array). */
|
|
36
|
-
function textOf(content) {
|
|
30
|
+
export function textOf(content) {
|
|
37
31
|
if (typeof content === 'string') return content;
|
|
38
32
|
if (!Array.isArray(content)) return content == null ? '' : JSON.stringify(content);
|
|
39
33
|
return content
|
|
@@ -42,42 +36,38 @@ function textOf(content) {
|
|
|
42
36
|
.join('\n');
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
/** The conservative observed-facts parse: only what the output text actually states. */
|
|
46
|
-
function observedFacts(resultText) {
|
|
47
|
-
const match = String(resultText).match(EXIT_CODE_PATTERN);
|
|
48
|
-
return match ? { exit_code: Number(match[1]) } : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** oathe verb name for a tool call, when the call IS an oathe speech act (MCP-prefixed). */
|
|
52
|
-
function oatheVerbFor(functionName) {
|
|
53
|
-
return OATHE_VERBS.find((verb) => functionName === verb || functionName.endsWith(`__${verb}`)) ?? null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
39
|
/**
|
|
57
40
|
* The projector family's shared trajectory assembly. Subclasses implement `map(rows, file)`
|
|
58
41
|
* by driving the step/observation helpers; the base owns numbering, metrics accumulation,
|
|
59
|
-
* the
|
|
42
|
+
* the record namespace, and validation-before-return.
|
|
60
43
|
*/
|
|
61
44
|
export class AtifProjector {
|
|
62
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @param {{store: object, copiedIds?: Set<string>|null}} o copiedIds — the row ids a PARENT
|
|
47
|
+
* already holds: a forked child begins with the parent's rows under the same ids, and a
|
|
48
|
+
* step built entirely from them is context it inherited, not work it did
|
|
49
|
+
* (is_copied_context — the RFC excludes such steps from SFT).
|
|
50
|
+
*/
|
|
51
|
+
constructor({ store, copiedIds = null }) {
|
|
63
52
|
if (!store) throw new AtifError('ATIF_STORE_REQUIRED', 'a projector needs its trace store');
|
|
64
53
|
this.store = store;
|
|
65
54
|
this.harness = store.harness; // the store was named by its adapter; the projector labels ATIF with the same name
|
|
55
|
+
this.copiedIds = copiedIds;
|
|
66
56
|
}
|
|
67
57
|
|
|
68
58
|
/** @returns {object} a VALID ATIF trajectory (validator-asserted) */
|
|
69
59
|
project(file) {
|
|
70
60
|
this.steps = [];
|
|
71
61
|
this.agentInfo = { name: this.harness, version: null, model_name: null };
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
source_path: file,
|
|
76
|
-
};
|
|
62
|
+
this.sessionId = null;
|
|
63
|
+
// Raw-record facts ATIF has no field for — the converter's one namespace (extra.record).
|
|
64
|
+
this.record = { source_path: file };
|
|
77
65
|
this.subagents = [];
|
|
66
|
+
this.rowsOf = new Map(); // step → the ids of the raw rows that built it
|
|
67
|
+
this.ownerOf = new WeakMap(); // observation result → the step it sits on
|
|
78
68
|
this.map(this.store.entries(file), file);
|
|
79
69
|
if (this.steps.length === 0) {
|
|
80
|
-
throw new AtifError('
|
|
70
|
+
throw new AtifError('ATIF_NO_STEPS',
|
|
81
71
|
`${file}: no mappable steps — a trajectory with nothing in it is not evidence`, { file });
|
|
82
72
|
}
|
|
83
73
|
return this.#finalize(file);
|
|
@@ -90,6 +80,13 @@ export class AtifProjector {
|
|
|
90
80
|
return this.steps.at(-1);
|
|
91
81
|
}
|
|
92
82
|
|
|
83
|
+
/** A raw row (by its id) landed on `step` — what decides whether the step was inherited. */
|
|
84
|
+
landed(step, rowId) {
|
|
85
|
+
if (!step || rowId === undefined || rowId === null) return;
|
|
86
|
+
if (!this.rowsOf.has(step)) this.rowsOf.set(step, new Set());
|
|
87
|
+
this.rowsOf.get(step).add(rowId);
|
|
88
|
+
}
|
|
89
|
+
|
|
93
90
|
/** The open agent step to attach observations/content to — or null. */
|
|
94
91
|
currentAgentStep() {
|
|
95
92
|
const last = this.steps.at(-1);
|
|
@@ -106,41 +103,72 @@ export class AtifProjector {
|
|
|
106
103
|
+ 'internally consistent and the projection will not paper over it', { file, callId });
|
|
107
104
|
}
|
|
108
105
|
owner.observation ??= { results: [] };
|
|
109
|
-
const
|
|
110
|
-
const result = { source_call_id: callId, content: text };
|
|
111
|
-
const observed = observedFacts(text);
|
|
112
|
-
if (observed) result.extra = { oathe: { observed } };
|
|
106
|
+
const result = { source_call_id: callId, content: textOf(content) };
|
|
113
107
|
owner.observation.results.push(result);
|
|
108
|
+
this.ownerOf.set(result, owner);
|
|
114
109
|
return result;
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
/** A tool_call object with the oathe extras (files touched, speech-act marking). */
|
|
118
112
|
buildToolCall({ id, name, args }) {
|
|
119
|
-
|
|
120
|
-
if (typeof call.arguments?.file_path === 'string') {
|
|
121
|
-
call.extra = { oathe: { files: [call.arguments.file_path] } };
|
|
122
|
-
}
|
|
123
|
-
return call;
|
|
113
|
+
return { tool_call_id: id, function_name: name, arguments: args ?? {} };
|
|
124
114
|
}
|
|
125
115
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
addSubagent(trajectory) {
|
|
117
|
+
this.subagents.push(trajectory);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The ref to a delegated child sits on the observation result of the call that delegated
|
|
122
|
+
* (the reference converters' placement — Harbor qwen_code.py): found on the step owning
|
|
123
|
+
* `callId`, or created there without content when the call never got an output row.
|
|
124
|
+
* Refuses when nobody owns the call — a ref pointing from nowhere is not evidence.
|
|
125
|
+
*/
|
|
126
|
+
attachRef(callId, ref, { file }) {
|
|
127
|
+
const owner = [...this.steps].reverse()
|
|
128
|
+
.find((s) => s.tool_calls?.some((c) => c.tool_call_id === callId));
|
|
129
|
+
if (!owner) {
|
|
130
|
+
throw new AtifError('ATIF_UNMAPPABLE',
|
|
131
|
+
`${file}: subagent ref for call '${callId}' has no owning tool call`, { file, callId });
|
|
132
|
+
}
|
|
133
|
+
owner.observation ??= { results: [] };
|
|
134
|
+
let result = owner.observation.results.find((r) => r.source_call_id === callId);
|
|
135
|
+
if (!result) {
|
|
136
|
+
result = { source_call_id: callId };
|
|
137
|
+
owner.observation.results.push(result);
|
|
136
138
|
}
|
|
139
|
+
result.subagent_trajectory_ref = [...(result.subagent_trajectory_ref ?? []), ref];
|
|
140
|
+
return result;
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
/** Accumulate per-turn token deltas onto a step — never overwrite what a turn already cost. */
|
|
144
|
+
addMetrics(step, { prompt_tokens = 0, completion_tokens = 0, cached_tokens = 0 }) {
|
|
145
|
+
const prior = step.metrics ?? { prompt_tokens: 0, completion_tokens: 0, cached_tokens: 0 };
|
|
146
|
+
step.metrics = {
|
|
147
|
+
...prior,
|
|
148
|
+
prompt_tokens: prior.prompt_tokens + prompt_tokens,
|
|
149
|
+
completion_tokens: prior.completion_tokens + completion_tokens,
|
|
150
|
+
cached_tokens: prior.cached_tokens + cached_tokens,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A row type outside the harness's declared roster: quarantine VISIBLY — counted here,
|
|
156
|
+
* announced in the evidence view, DRIFT in the census lane. Additions tolerate visibly;
|
|
157
|
+
* only missing EXPECTED shapes refuse (founder ruling 2026-08-31).
|
|
158
|
+
*/
|
|
159
|
+
noteUnrecognized(key) {
|
|
160
|
+
this.record.unrecognized_rows ??= {};
|
|
161
|
+
this.record.unrecognized_rows[key] = (this.record.unrecognized_rows[key] ?? 0) + 1;
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
#finalize(file) {
|
|
165
|
+
if (this.copiedIds) {
|
|
166
|
+
// Inherited context: a step every one of whose rows the parent already holds.
|
|
167
|
+
for (const step of this.steps) {
|
|
168
|
+
const rows = this.rowsOf.get(step);
|
|
169
|
+
if (rows && rows.size > 0 && [...rows].every((id) => this.copiedIds.has(id))) step.is_copied_context = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
144
172
|
const totals = { total_prompt_tokens: 0, total_completion_tokens: 0, total_cached_tokens: 0, total_steps: this.steps.length };
|
|
145
173
|
for (const step of this.steps) {
|
|
146
174
|
if (!step.metrics) continue;
|
|
@@ -148,13 +176,21 @@ export class AtifProjector {
|
|
|
148
176
|
totals.total_completion_tokens += step.metrics.completion_tokens ?? 0;
|
|
149
177
|
totals.total_cached_tokens += step.metrics.cached_tokens ?? 0;
|
|
150
178
|
}
|
|
179
|
+
// A run that delegates is not under-counted (the reference converters' fold — Harbor
|
|
180
|
+
// qwen_code.py): each child's totals already hold its own children's, so the direct
|
|
181
|
+
// children's totals fold into the root's. total_steps stays this trajectory's own.
|
|
182
|
+
for (const child of this.subagents) {
|
|
183
|
+
totals.total_prompt_tokens += child.final_metrics?.total_prompt_tokens ?? 0;
|
|
184
|
+
totals.total_completion_tokens += child.final_metrics?.total_completion_tokens ?? 0;
|
|
185
|
+
totals.total_cached_tokens += child.final_metrics?.total_cached_tokens ?? 0;
|
|
186
|
+
}
|
|
151
187
|
const trajectory = {
|
|
152
188
|
schema_version: ATIF_SCHEMA_VERSION,
|
|
153
|
-
session_id: this.
|
|
189
|
+
session_id: this.sessionId,
|
|
154
190
|
agent: this.agentInfo,
|
|
155
191
|
steps: this.steps,
|
|
156
192
|
final_metrics: totals,
|
|
157
|
-
extra: {
|
|
193
|
+
extra: { record: this.record },
|
|
158
194
|
...(this.subagents.length > 0 ? { subagent_trajectories: this.subagents } : {}),
|
|
159
195
|
};
|
|
160
196
|
new AtifValidator().assert(trajectory, { file });
|
|
@@ -164,211 +200,13 @@ export class AtifProjector {
|
|
|
164
200
|
|
|
165
201
|
// --------------------------------------------------------------------------- Claude
|
|
166
202
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
'queue-operation', 'file-history-snapshot', 'ai-title',
|
|
170
|
-
]);
|
|
171
|
-
|
|
172
|
-
export class ClaudeAtifProjector extends AtifProjector {
|
|
173
|
-
map(rows, file) {
|
|
174
|
-
let lastMessageId = null;
|
|
175
|
-
this.turnBroken = false;
|
|
176
|
-
const filesTouched = new Set();
|
|
177
|
-
for (const row of rows) {
|
|
178
|
-
if (row.type === 'ai-title') {
|
|
179
|
-
this.oatheRoot.session_title = row.aiTitle;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (row.type === 'file-history-snapshot') {
|
|
183
|
-
for (const touched of Object.keys(row.snapshot?.trackedFileBackups ?? {})) filesTouched.add(touched);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (CLAUDE_NOISE_TYPES.has(row.type)) continue;
|
|
187
|
-
if (row.sessionId && !this.oatheRoot.session_id) this.oatheRoot.session_id = row.sessionId;
|
|
188
|
-
if (row.version && !this.agentInfo.version) this.agentInfo.version = row.version;
|
|
189
|
-
|
|
190
|
-
if (row.type === 'assistant') {
|
|
191
|
-
this.#mapAssistant(row, lastMessageId);
|
|
192
|
-
lastMessageId = row.message?.id ?? null;
|
|
193
|
-
} else if (row.type === 'user') {
|
|
194
|
-
this.#mapUser(row, file);
|
|
195
|
-
} else if (row.type === 'system') {
|
|
196
|
-
this.pushStep({ source: 'system', message: textOf(row.message?.content ?? row.content ?? '') });
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (filesTouched.size > 0) this.oatheRoot.files_touched = [...filesTouched];
|
|
200
|
-
|
|
201
|
-
for (const sub of this.store.subagentsFor(file)) {
|
|
202
|
-
const child = new ClaudeAtifProjector({ store: this.store }).project(sub.path);
|
|
203
|
-
child.trajectory_id = sub.agent_id;
|
|
204
|
-
if (sub.meta) child.extra.oathe.subagent_meta = sub.meta;
|
|
205
|
-
this.addSubagent(child);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
#mapAssistant(row, lastMessageId) {
|
|
210
|
-
const parts = Array.isArray(row.message?.content) ? row.message.content : [];
|
|
211
|
-
const texts = parts.filter((p) => p.type === 'text').map((p) => p.text);
|
|
212
|
-
const thinking = parts.filter((p) => p.type === 'thinking').map((p) => p.thinking);
|
|
213
|
-
const calls = parts.filter((p) => p.type === 'tool_use')
|
|
214
|
-
.map((p) => this.buildToolCall({ id: p.id, name: p.name, args: p.input }));
|
|
215
|
-
if (row.message?.model && !this.agentInfo.model_name) this.agentInfo.model_name = row.message.model;
|
|
216
|
-
|
|
217
|
-
// Consecutive assistant rows are one TURN (streamed content blocks): merge into the open
|
|
218
|
-
// agent step — but any intervening user row (a tool result included) ENDS the turn.
|
|
219
|
-
// Usage repeats per API response id, so it is added once per message id.
|
|
220
|
-
let step = this.turnBroken ? null : this.currentAgentStep();
|
|
221
|
-
this.turnBroken = false;
|
|
222
|
-
if (!step) {
|
|
223
|
-
step = this.pushStep({ source: 'agent', message: '' });
|
|
224
|
-
if (row.timestamp) step.timestamp = row.timestamp;
|
|
225
|
-
}
|
|
226
|
-
if (texts.length > 0) step.message = [step.message, ...texts].filter((t) => t !== '').join('\n');
|
|
227
|
-
if (thinking.length > 0) {
|
|
228
|
-
step.reasoning_content = [step.reasoning_content, ...thinking].filter(Boolean).join('\n');
|
|
229
|
-
}
|
|
230
|
-
if (calls.length > 0) step.tool_calls = [...(step.tool_calls ?? []), ...calls];
|
|
231
|
-
|
|
232
|
-
const usage = row.message?.usage;
|
|
233
|
-
const messageId = row.message?.id ?? null;
|
|
234
|
-
// Dedupe usage only when an API response id actually REPEATS — absent ids never match.
|
|
235
|
-
if (usage && (messageId === null || messageId !== lastMessageId)) {
|
|
236
|
-
const cached = usage.cache_read_input_tokens ?? 0;
|
|
237
|
-
const creation = usage.cache_creation_input_tokens ?? 0;
|
|
238
|
-
const prior = step.metrics ?? { prompt_tokens: 0, completion_tokens: 0, cached_tokens: 0 };
|
|
239
|
-
step.metrics = {
|
|
240
|
-
prompt_tokens: prior.prompt_tokens + (usage.input_tokens ?? 0) + cached + creation,
|
|
241
|
-
completion_tokens: prior.completion_tokens + (usage.output_tokens ?? 0),
|
|
242
|
-
cached_tokens: prior.cached_tokens + cached,
|
|
243
|
-
...(creation > 0 ? { extra: { cache_creation_input_tokens: creation } } : {}),
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
this.markClaimEvents(step);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
#mapUser(row, file) {
|
|
250
|
-
this.turnBroken = true;
|
|
251
|
-
const content = row.message?.content;
|
|
252
|
-
if (Array.isArray(content)) {
|
|
253
|
-
const results = content.filter((p) => p.type === 'tool_result');
|
|
254
|
-
const texts = content.filter((p) => p.type === 'text').map((p) => p.text);
|
|
255
|
-
for (const result of results) this.attachResult(result.tool_use_id, result.content, { file });
|
|
256
|
-
if (texts.length > 0) this.pushStep({ source: 'user', message: texts.join('\n') });
|
|
257
|
-
} else {
|
|
258
|
-
this.pushStep({ source: 'user', message: textOf(content) });
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
203
|
+
// ClaudeAtifProjector lives in src/harnesses/claude-transcript.mjs — Claude format knowledge is
|
|
204
|
+
// the adapter's (R-HARNESS-TOUCHPOINTS); this module stays harness-agnostic assembly.
|
|
262
205
|
|
|
263
206
|
// --------------------------------------------------------------------------- Codex
|
|
264
207
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const head = rows[0];
|
|
268
|
-
if (head?.type !== 'session_meta') {
|
|
269
|
-
throw new AtifError('ATIF_UNMAPPABLE',
|
|
270
|
-
`${file}: first rollout line is '${head?.type}', expected session_meta`, { file });
|
|
271
|
-
}
|
|
272
|
-
const meta = head.payload ?? {};
|
|
273
|
-
this.oatheRoot.session_id = meta.id ?? meta.session_id;
|
|
274
|
-
this.agentInfo.version = meta.cli_version ?? null;
|
|
275
|
-
const modelName = meta.model ?? meta.model_provider;
|
|
276
|
-
if (!modelName) {
|
|
277
|
-
throw new AtifError('ATIF_UNMAPPABLE',
|
|
278
|
-
`${file}: session_meta names neither model nor model_provider — the agent identity `
|
|
279
|
-
+ 'cannot be stated without being invented', { file });
|
|
280
|
-
}
|
|
281
|
-
this.agentInfo.model_name = modelName;
|
|
282
|
-
|
|
283
|
-
for (const row of rows.slice(1)) {
|
|
284
|
-
if (row.type === 'response_item') this.#mapResponseItem(row.payload ?? {}, file);
|
|
285
|
-
else if (row.type === 'event_msg' && row.payload?.type === 'token_count') {
|
|
286
|
-
const step = this.currentAgentStep() ?? this.steps.at(-1);
|
|
287
|
-
if (step && step.source === 'agent') {
|
|
288
|
-
step.metrics = {
|
|
289
|
-
prompt_tokens: row.payload.input_tokens ?? 0,
|
|
290
|
-
completion_tokens: row.payload.output_tokens ?? 0,
|
|
291
|
-
cached_tokens: row.payload.cached_tokens ?? 0,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
for (const child of this.#children()) this.addSubagent(child);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
#children() {
|
|
301
|
-
const projected = [];
|
|
302
|
-
let children = [];
|
|
303
|
-
try {
|
|
304
|
-
children = this.store.childThreads(this.oatheRoot.session_id);
|
|
305
|
-
} catch (e) {
|
|
306
|
-
if (e instanceof TraceContractError && e.code === 'TRACE_CODEX_STATE_ABSENT') return projected;
|
|
307
|
-
throw e;
|
|
308
|
-
}
|
|
309
|
-
for (const child of children) {
|
|
310
|
-
if (!child.rollout_path) {
|
|
311
|
-
throw new AtifError('ATIF_UNMAPPABLE',
|
|
312
|
-
`codex child thread ${child.thread_id} has no rollout path — a fan-out member cannot `
|
|
313
|
-
+ 'be silently dropped from the evidence', { child });
|
|
314
|
-
}
|
|
315
|
-
const projectedChild = new CodexAtifProjector({ store: this.store }).project(child.rollout_path);
|
|
316
|
-
projectedChild.trajectory_id = child.thread_id;
|
|
317
|
-
projected.push(projectedChild);
|
|
318
|
-
}
|
|
319
|
-
return projected;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
#agentStep() {
|
|
323
|
-
return this.currentAgentStep() ?? this.pushStep({ source: 'agent', message: '' });
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
#mapResponseItem(payload, file) {
|
|
327
|
-
switch (payload.type) {
|
|
328
|
-
case 'message':
|
|
329
|
-
case 'agent_message': {
|
|
330
|
-
const text = textOf(payload.content);
|
|
331
|
-
if (payload.role === 'user') {
|
|
332
|
-
this.pushStep({ source: 'user', message: text });
|
|
333
|
-
} else {
|
|
334
|
-
const step = this.#agentStep();
|
|
335
|
-
step.message = [step.message, text].filter((t) => t !== '').join('\n');
|
|
336
|
-
}
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
case 'reasoning': {
|
|
340
|
-
const step = this.#agentStep();
|
|
341
|
-
const text = textOf(payload.content ?? payload.summary);
|
|
342
|
-
if (text) step.reasoning_content = [step.reasoning_content, text].filter(Boolean).join('\n');
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
case 'function_call':
|
|
346
|
-
case 'local_shell_call':
|
|
347
|
-
case 'custom_tool_call': {
|
|
348
|
-
const step = this.#agentStep();
|
|
349
|
-
let args = payload.arguments ?? payload.action ?? {};
|
|
350
|
-
if (typeof args === 'string') {
|
|
351
|
-
try {
|
|
352
|
-
args = JSON.parse(args);
|
|
353
|
-
} catch {
|
|
354
|
-
throw new AtifError('ATIF_UNMAPPABLE',
|
|
355
|
-
`${file}: tool call '${payload.call_id}' carries arguments that are not JSON`, { file });
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
step.tool_calls = [...(step.tool_calls ?? []),
|
|
359
|
-
this.buildToolCall({ id: payload.call_id, name: payload.name ?? payload.type, args })];
|
|
360
|
-
this.markClaimEvents(step);
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case 'function_call_output':
|
|
364
|
-
case 'custom_tool_call_output':
|
|
365
|
-
this.attachResult(payload.call_id, payload.output ?? payload.content, { file });
|
|
366
|
-
break;
|
|
367
|
-
default:
|
|
368
|
-
break; // compaction/additional_tools/… — context machinery, not evidence steps
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
208
|
+
// CodexAtifProjector lives in src/harnesses/codex-rollout.mjs — codex format knowledge is
|
|
209
|
+
// the adapter's (R-HARNESS-TOUCHPOINTS); this module stays harness-agnostic assembly.
|
|
372
210
|
|
|
373
211
|
// --------------------------------------------------------------------------- factory
|
|
374
212
|
|
|
@@ -379,9 +217,9 @@ export class CodexAtifProjector extends AtifProjector {
|
|
|
379
217
|
const FOCUS_CLOSERS = new Set(['oathe_done', 'oathe_yield']);
|
|
380
218
|
|
|
381
219
|
/**
|
|
382
|
-
* Claim-focused intervals of
|
|
220
|
+
* Claim-focused intervals of an ANNOTATED trajectory (ruling R3 §5.4): a session becomes
|
|
383
221
|
* attributable to a task only from the step where it ACTS on that task through an oathe
|
|
384
|
-
* speech act (claim, pickup, statement, done, yield — the
|
|
222
|
+
* speech act (claim, pickup, statement, done, yield — the annotator's claim_events), and
|
|
385
223
|
* stops being attributable when the act names a different task (a switch), when done/yield
|
|
386
224
|
* closes the work, or when the session ends. Steps before the first act — planning, board
|
|
387
225
|
* reading, repository discussion — belong to no interval and are context, not evidence.
|
|
@@ -409,99 +247,66 @@ export function claimIntervals(trajectory) {
|
|
|
409
247
|
}
|
|
410
248
|
|
|
411
249
|
/**
|
|
412
|
-
* The trajectory reduced to
|
|
413
|
-
*
|
|
414
|
-
* (a pre-interval trace, or CLI-only work
|
|
415
|
-
*
|
|
250
|
+
* The trajectory reduced to what is attributable to ONE task — what a verifier may treat as
|
|
251
|
+
* that task's execution evidence. Steps: interval-scoped; no interval for the task means the
|
|
252
|
+
* WHOLE step record stays (a pre-interval trace, or CLI-only work — slicing to nothing would
|
|
253
|
+
* fabricate absence). Children: partitioned by their OWN claim intervals — a child naming
|
|
254
|
+
* the task is kept (recursively sliced), a child positively naming only OTHER tasks is never
|
|
255
|
+
* this task's evidence (the 22-sibling dilution, 2026-08-31), and a child naming nothing is
|
|
256
|
+
* kept only while no sibling positively names the task. A slice that changed anything
|
|
257
|
+
* renumbers step_ids (validator-safe) and announces itself in extra.oathe.sliced; an
|
|
258
|
+
* untouched trajectory is returned as-is, unmarked.
|
|
416
259
|
*/
|
|
417
260
|
export function sliceForTask(trajectory, taskId) {
|
|
418
261
|
const mine = claimIntervals(trajectory).filter((i) => i.task_id === taskId);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
262
|
+
const children = trajectory.subagent_trajectories ?? [];
|
|
263
|
+
let keptChildren = children;
|
|
264
|
+
if (children.length > 0) {
|
|
265
|
+
const judged = children.map((child) => {
|
|
266
|
+
const tasks = new Set(claimIntervals(child).map((i) => i.task_id));
|
|
267
|
+
return { child, names: tasks.has(taskId), othersOnly: tasks.size > 0 && !tasks.has(taskId) };
|
|
268
|
+
});
|
|
269
|
+
const anyNames = judged.some((j) => j.names);
|
|
270
|
+
keptChildren = judged
|
|
271
|
+
.filter((j) => j.names || (!j.othersOnly && !anyNames))
|
|
272
|
+
.map((j) => (j.names ? sliceForTask(j.child, taskId) : j.child));
|
|
423
273
|
}
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
// --------------------------------------------------------------------------- evidence view
|
|
428
|
-
|
|
429
|
-
const CLIP = { message: 300, args: 140, result: 200, user: 200 };
|
|
430
|
-
const SUBAGENT_BUDGET_SHARE = 0.3;
|
|
431
|
-
|
|
432
|
-
function clip(text, max) {
|
|
433
|
-
const flat = String(text).replaceAll('\n', ' ⏎ ');
|
|
434
|
-
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
435
|
-
}
|
|
274
|
+
if (mine.length === 0 && keptChildren.length === children.length) return trajectory;
|
|
436
275
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (step.source === 'user') return [`USER: ${clip(step.message, CLIP.user)}`];
|
|
441
|
-
if (step.source === 'system') return [`SYSTEM: ${clip(step.message, CLIP.user)}`];
|
|
442
|
-
if (step.message) lines.push(`SAID: ${clip(step.message, CLIP.message)}`);
|
|
443
|
-
for (const event of step.extra?.oathe?.claim_events ?? []) {
|
|
444
|
-
lines.push(`CLAIM(${event.verb}${event.task_id ? ` ${event.task_id}` : ''})`);
|
|
445
|
-
}
|
|
446
|
-
for (const call of step.tool_calls ?? []) {
|
|
447
|
-
lines.push(`DID: ${call.function_name}(${clip(JSON.stringify(call.arguments), CLIP.args)})`);
|
|
276
|
+
const keepIndex = new Set();
|
|
277
|
+
for (const { start_index, end_index } of mine) {
|
|
278
|
+
for (let i = start_index; i <= end_index; i++) keepIndex.add(i);
|
|
448
279
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
280
|
+
const keptIndices = mine.length > 0
|
|
281
|
+
? trajectory.steps.map((_, i) => i).filter((i) => keepIndex.has(i))
|
|
282
|
+
: trajectory.steps.map((_, i) => i);
|
|
283
|
+
const sliced = {
|
|
284
|
+
...trajectory,
|
|
285
|
+
steps: keptIndices.map((i, at) => ({ ...trajectory.steps[i], step_id: at + 1 })),
|
|
286
|
+
extra: {
|
|
287
|
+
...(trajectory.extra ?? {}),
|
|
288
|
+
oathe: {
|
|
289
|
+
...(trajectory.extra?.oathe ?? {}),
|
|
290
|
+
sliced: {
|
|
291
|
+
task_id: taskId,
|
|
292
|
+
original_step_ids: keptIndices.map((i) => trajectory.steps[i].step_id ?? i + 1),
|
|
293
|
+
subagents_elided: children.length - keptChildren.length,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
if (children.length > 0) {
|
|
299
|
+
if (keptChildren.length > 0) sliced.subagent_trajectories = keptChildren;
|
|
300
|
+
else delete sliced.subagent_trajectories;
|
|
452
301
|
}
|
|
453
|
-
return
|
|
302
|
+
return sliced;
|
|
454
303
|
}
|
|
455
304
|
|
|
456
|
-
|
|
457
|
-
return `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
458
|
-
}
|
|
305
|
+
// --------------------------------------------------------------------------- evidence view
|
|
459
306
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
* survive whole) and ANNOUNCED — an elision the reader cannot see is evidence silently lost.
|
|
464
|
-
*/
|
|
465
|
-
export function renderEvidenceView(trajectory, { budget }) {
|
|
466
|
-
const oathe = trajectory.extra?.oathe ?? {};
|
|
467
|
-
const header = [
|
|
468
|
-
`TRACE ${trajectory.session_id} (${oathe.harness ?? trajectory.agent?.name}`
|
|
469
|
-
+ `${oathe.session_title ? ` — "${oathe.session_title}"` : ''})`,
|
|
470
|
-
...(oathe.files_touched?.length ? [`files touched: ${oathe.files_touched.join(', ')}`] : []),
|
|
471
|
-
];
|
|
472
|
-
const subagents = trajectory.subagent_trajectories ?? [];
|
|
473
|
-
const mainBudget = subagents.length > 0 ? Math.floor(budget * (1 - SUBAGENT_BUDGET_SHARE)) : budget;
|
|
474
|
-
|
|
475
|
-
const blocks = trajectory.steps.map((step) => stepLines(step).map((l) => ` ${l}`).join('\n'));
|
|
476
|
-
const kept = [];
|
|
477
|
-
let spent = 0;
|
|
478
|
-
for (let at = blocks.length - 1; at >= 0; at -= 1) {
|
|
479
|
-
if (spent + blocks[at].length > mainBudget && kept.length > 0) break;
|
|
480
|
-
kept.unshift(at);
|
|
481
|
-
spent += blocks[at].length;
|
|
482
|
-
if (spent > mainBudget) break;
|
|
483
|
-
}
|
|
484
|
-
const elidedSteps = trajectory.steps.slice(0, kept[0] ?? 0);
|
|
485
|
-
const body = [];
|
|
486
|
-
if (elidedSteps.length > 0) {
|
|
487
|
-
const toolCalls = elidedSteps.reduce((n, s) => n + (s.tool_calls?.length ?? 0), 0);
|
|
488
|
-
const claims = elidedSteps.reduce((n, s) => n + (s.extra?.oathe?.claim_events?.length ?? 0), 0);
|
|
489
|
-
body.push(` [${plural(elidedSteps.length, 'earlier step')} elided: `
|
|
490
|
-
+ `${plural(toolCalls, 'tool call')}, ${plural(claims, 'claim')}]`);
|
|
491
|
-
}
|
|
492
|
-
for (const at of kept) body.push(blocks[at]);
|
|
493
|
-
|
|
494
|
-
const out = [...header, ...body];
|
|
495
|
-
if (subagents.length > 0) {
|
|
496
|
-
const each = Math.floor((budget * SUBAGENT_BUDGET_SHARE) / subagents.length);
|
|
497
|
-
for (const child of subagents) {
|
|
498
|
-
const meta = child.extra?.oathe?.subagent_meta;
|
|
499
|
-
out.push(`SUBAGENT ${child.trajectory_id}${meta?.agentType ? ` (${meta.agentType})` : ''}`);
|
|
500
|
-
out.push(renderEvidenceView(child, { budget: each }));
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return out.join('\n');
|
|
504
|
-
}
|
|
307
|
+
// The rendering lives in src/evidence.mjs (EvidenceRenderer — the one budget-true
|
|
308
|
+
// implementation); the export stays here for its consumers' stable import path.
|
|
309
|
+
export { renderEvidenceView } from './evidence.mjs';
|
|
505
310
|
|
|
506
311
|
// --------------------------------------------------------------------------- validator
|
|
507
312
|
|
|
@@ -516,6 +321,9 @@ const KNOWN_FIELDS = Object.freeze({
|
|
|
516
321
|
tool_call: ['tool_call_id', 'function_name', 'arguments', 'extra'],
|
|
517
322
|
observation: ['results', 'extra'],
|
|
518
323
|
observation_result: ['source_call_id', 'content', 'subagent_trajectory_ref', 'extra'],
|
|
324
|
+
// The reference SubagentTrajectoryRef: resolvable by trajectory_id (embedded) or
|
|
325
|
+
// trajectory_path (external); session_id is informational, never a key; extra forbidden.
|
|
326
|
+
subagent_trajectory_ref: ['trajectory_id', 'trajectory_path', 'session_id', 'extra'],
|
|
519
327
|
metrics: ['prompt_tokens', 'completion_tokens', 'cached_tokens', 'cost_usd',
|
|
520
328
|
'prompt_token_ids', 'completion_token_ids', 'logprobs', 'extra'],
|
|
521
329
|
final_metrics: ['total_prompt_tokens', 'total_completion_tokens', 'total_cached_tokens',
|
|
@@ -567,7 +375,10 @@ export class AtifValidator {
|
|
|
567
375
|
this.#knownFields(t.agent, 'agent', `${where}.agent`);
|
|
568
376
|
if (!t.agent.name) this.#fail(`${where}.agent: name required`);
|
|
569
377
|
if (!Array.isArray(t.steps) || t.steps.length === 0) this.#fail(`${where}: steps must be a non-empty array`);
|
|
570
|
-
|
|
378
|
+
// The ids a ref can resolve against — the embedded children's — are known before the steps
|
|
379
|
+
// are read, so a dangling trajectory_id is refused where it sits.
|
|
380
|
+
const embedded = new Set((t.subagent_trajectories ?? []).map((child) => child?.trajectory_id).filter(Boolean));
|
|
381
|
+
t.steps.forEach((step, at) => this.#step(step, at, `${where}.steps[${at}]`, embedded));
|
|
571
382
|
if (t.final_metrics) this.#knownFields(t.final_metrics, 'final_metrics', `${where}.final_metrics`);
|
|
572
383
|
if (t.subagent_trajectories !== undefined) {
|
|
573
384
|
const ids = new Set();
|
|
@@ -584,7 +395,7 @@ export class AtifValidator {
|
|
|
584
395
|
}
|
|
585
396
|
}
|
|
586
397
|
|
|
587
|
-
#step(step, at, where) {
|
|
398
|
+
#step(step, at, where, embedded) {
|
|
588
399
|
this.#knownFields(step, 'step', where);
|
|
589
400
|
if (step.step_id !== at + 1) {
|
|
590
401
|
this.#fail(`${where}: step_id ${step.step_id} breaks the sequential-from-1 rule (expected ${at + 1})`);
|
|
@@ -617,8 +428,31 @@ export class AtifValidator {
|
|
|
617
428
|
this.#fail(`${where}.observation.results[${ri}]: source_call_id '${result.source_call_id}' `
|
|
618
429
|
+ 'matches no tool call on its step');
|
|
619
430
|
}
|
|
431
|
+
if (result.subagent_trajectory_ref !== undefined && result.subagent_trajectory_ref !== null) {
|
|
432
|
+
this.#refs(result.subagent_trajectory_ref, `${where}.observation.results[${ri}].subagent_trajectory_ref`, embedded);
|
|
433
|
+
}
|
|
620
434
|
}
|
|
621
435
|
}
|
|
622
436
|
if (step.metrics !== undefined) this.#knownFields(step.metrics, 'metrics', `${where}.metrics`);
|
|
623
437
|
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* A result's subagent refs (RFC 0001, v1.7): an ARRAY of SubagentTrajectoryRef — each
|
|
441
|
+
* resolvable by trajectory_id (which must name an embedded child — the RFC's resolution
|
|
442
|
+
* rule, held here though the reference model checks only the one-of) or by
|
|
443
|
+
* trajectory_path (an external file, taken on trust); session_id rides informationally.
|
|
444
|
+
*/
|
|
445
|
+
#refs(refs, where, embedded) {
|
|
446
|
+
if (!Array.isArray(refs)) this.#fail(`${where}: subagent_trajectory_ref must be an array of refs`);
|
|
447
|
+
for (const [at, ref] of refs.entries()) {
|
|
448
|
+
if (ref === null || typeof ref !== 'object') this.#fail(`${where}[${at}]: not an object`);
|
|
449
|
+
this.#knownFields(ref, 'subagent_trajectory_ref', `${where}[${at}]`);
|
|
450
|
+
if (!ref.trajectory_id && !ref.trajectory_path) {
|
|
451
|
+
this.#fail(`${where}[${at}]: a ref must be resolvable — set trajectory_id (embedded) or trajectory_path (external); session_id alone is not a key`);
|
|
452
|
+
}
|
|
453
|
+
if (ref.trajectory_id && !embedded.has(ref.trajectory_id)) {
|
|
454
|
+
this.#fail(`${where}[${at}]: trajectory_id '${ref.trajectory_id}' names no embedded subagent trajectory`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
624
458
|
}
|