notesoup 0.52.7 → 0.53.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/README.md +3 -1
- package/dist/plugins/codex/src/cli.d.ts +2 -0
- package/dist/plugins/codex/src/cli.js +25 -0
- package/dist/plugins/codex/src/history.d.ts +8 -0
- package/dist/plugins/codex/src/history.js +238 -0
- package/dist/plugins/codex/src/hooks.d.ts +9 -0
- package/dist/plugins/codex/src/hooks.js +196 -0
- package/dist/plugins/codex/src/identity.d.ts +35 -0
- package/dist/plugins/codex/src/identity.js +134 -0
- package/dist/plugins/codex/src/mcp.d.ts +7 -0
- package/dist/plugins/codex/src/mcp.js +159 -0
- package/dist/plugins/codex/src/state.d.ts +23 -0
- package/dist/plugins/codex/src/state.js +92 -0
- package/dist/plugins/codex/src/text.d.ts +14 -0
- package/dist/plugins/codex/src/text.js +25 -0
- package/dist/plugins/codex/src/transcript.d.ts +39 -0
- package/dist/plugins/codex/src/transcript.js +313 -0
- package/dist/src/boot/render.js +13 -12
- package/dist/src/boot/text.d.ts +5 -5
- package/dist/src/boot/text.js +15 -28
- package/dist/src/budget/text.d.ts +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/test/codex-history.test.d.ts +1 -0
- package/dist/test/codex-history.test.js +330 -0
- package/dist/test/codex-plugin.test.d.ts +1 -0
- package/dist/test/codex-plugin.test.js +365 -0
- package/dist/test/dependencies.test.js +8 -2
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/helpers/dependency-graph.js +1 -1
- package/dist/test/model-facing-text.test.js +47 -26
- package/dist/test/notes.integration.test.js +3 -0
- package/docs/codex.md +91 -0
- package/docs/dsh.md +1 -1
- package/docs/reset-lifecycle.md +1 -1
- package/package.json +6 -3
- package/playbook.md +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +27 -37
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/memory/SKILL.md +1 -1
- package/plugins/codex/README.md +43 -0
- package/plugins/codex/dist/codex/notesoup.js +27801 -0
- package/plugins/codex/hooks/hooks.json +41 -0
- package/plugins/codex/mcp.json +10 -0
- package/plugins/codex/plugin.json +6 -0
- package/plugins/codex/src/cli.ts +26 -0
- package/plugins/codex/src/history.ts +193 -0
- package/plugins/codex/src/hooks.ts +190 -0
- package/plugins/codex/src/identity.ts +147 -0
- package/plugins/codex/src/mcp.ts +171 -0
- package/plugins/codex/src/state.ts +102 -0
- package/plugins/codex/src/text.ts +31 -0
- package/plugins/codex/src/transcript.ts +275 -0
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +13 -11
- package/src/boot/text.ts +17 -30
- package/src/budget/text.ts +1 -1
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, writeFile, appendFile, mkdir, readFile, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { zstdCompressSync } from "node:zlib";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { readCodexHistory } from "../plugins/codex/src/history.js";
|
|
8
|
+
import { readCodexTranscriptState } from "../plugins/codex/src/transcript.js";
|
|
9
|
+
import { allItems, eventDocument } from "../src/history/history.js";
|
|
10
|
+
import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
|
|
11
|
+
/* Producer-shaped synthetic fixtures, not captured/private transcripts.
|
|
12
|
+
* Frozen official rust-v0.160.1, d27764b82f7118f674371e6d6e76271d9d606edb:
|
|
13
|
+
* - history/src/{lib.rs,rollout_payload.rs}: flattened JSONL envelope, top-level
|
|
14
|
+
* metadata, raw replacement_history + aligned replacement_history_metadata.
|
|
15
|
+
* - protocol/src/{protocol.rs,models.rs,items.rs,mcp.rs}: exact case/field shapes;
|
|
16
|
+
* item_completed's TurnItem is PascalCase; McpToolCall fields are camelCase;
|
|
17
|
+
* legacy MCP Result uses {Ok:{...}}/{Err:string}, not flattened MCP fields.
|
|
18
|
+
* - rollout/src/{ordinal.rs,policy.rs,compression.rs}: legacy omits ordinals,
|
|
19
|
+
* paginated uses native (possibly gapped) ordinals, .jsonl.zst decoded offsets.
|
|
20
|
+
* - thread-store/src/local/{rollout_lineage.rs,revert_thread.rs}: history_base
|
|
21
|
+
* is an exclusive physical rollout-ID + ordinal + decoded byte coordinate;
|
|
22
|
+
* replacement filename has stable thread ID and distinct _rollout-id suffix.
|
|
23
|
+
* - core/src/agent/control_tests.rs: paginated full-history children COPY only
|
|
24
|
+
* inference context and mark subagent_history_start_ordinal, not history_base.
|
|
25
|
+
*/
|
|
26
|
+
const ROOT = "019a0000-0000-7000-8000-000000000001";
|
|
27
|
+
const CHILD = "019a0000-0000-7000-8000-000000000002";
|
|
28
|
+
const FORK = "019a0000-0000-7000-8000-000000000003";
|
|
29
|
+
const REVERT = "019a0000-0000-7000-8000-000000000004";
|
|
30
|
+
const W0 = "019a0000-0000-7000-8000-000000000010";
|
|
31
|
+
const W1 = "019a0000-0000-7000-8000-000000000011";
|
|
32
|
+
const W2 = "019a0000-0000-7000-8000-000000000012";
|
|
33
|
+
const WC = "019a0000-0000-7000-8000-000000000013";
|
|
34
|
+
const AT = "2026-10-06T01:02:03.000Z";
|
|
35
|
+
const row = (type, payload, ordinal, metadata) => ({ timestamp: AT, ...(ordinal === undefined ? {} : { ordinal }), type, payload, ...(metadata ? { metadata } : {}) });
|
|
36
|
+
function meta(id = ROOT, extra = {}) {
|
|
37
|
+
return { session_id: ROOT, id, timestamp: AT, cwd: "/workspace/native", originator: "codex_cli_rs", cli_version: "0.160.1", source: "cli", model_provider: "openai", base_instructions: { text: "base" }, history_mode: "paginated", context_window: { window_id: W0 }, ...extra };
|
|
38
|
+
}
|
|
39
|
+
function settings(model) {
|
|
40
|
+
return { model, model_provider_id: "openai", approval_policy: "on-request", approvals_reviewer: "user", permission_profile: { type: "managed", file_system: { type: "restricted", entries: [] }, network: "restricted" }, cwd: "/workspace/native", collaboration_mode: { mode: "default", settings: { model, reasoning_effort: null, developer_instructions: null } }, disabled_plugin_ids: [] };
|
|
41
|
+
}
|
|
42
|
+
function turnContext(model) {
|
|
43
|
+
return { turn_id: "turn-1", cwd: "/workspace/native", approval_policy: "on-request", sandbox_policy: { type: "read-only" }, model, summary: "auto" };
|
|
44
|
+
}
|
|
45
|
+
const message = (role, text, id = `msg-${role}`) => ({ type: "message", id, role, content: [{ type: role === "assistant" ? "output_text" : "input_text", text }] });
|
|
46
|
+
const completed = (item, thread = ROOT) => ({ type: "item_completed", thread_id: thread, turn_id: "turn-1", item, started_at_ms: 1791248523000, completed_at_ms: 1791248524000 });
|
|
47
|
+
const command = (id, extra = {}) => ({ type: "CommandExecution", id, command: ["bash", "-lc", "printf output"], cwd: "file:///workspace/native", parsed_cmd: [], source: "agent", status: "failed", stdout: "partial", stderr: "error", aggregated_output: "partial\nerror", exit_code: 2, duration: { secs: 0, nanos: 1000000 }, formatted_output: "partial\nerror", ...extra });
|
|
48
|
+
function compact(window, previous, number, replacement = []) {
|
|
49
|
+
return { message: "", replacement_history: replacement, replacement_history_metadata: replacement.map(() => ({ client_authored: false })), window_number: number, first_window_id: W0, previous_window_id: previous, window_id: window, compaction_response_id: null, latest_token_usage_record: null };
|
|
50
|
+
}
|
|
51
|
+
const jsonl = (rows) => rows.map((r) => JSON.stringify(r) + "\n").join("");
|
|
52
|
+
const nativeName = (thread, rollout) => `rollout-2026-10-06T01-02-03-${thread}${rollout ? `_${rollout}` : ""}.jsonl`;
|
|
53
|
+
async function fixture(t) {
|
|
54
|
+
const home = await mkdtemp(join(tmpdir(), "notesoup-codex-history-test-"));
|
|
55
|
+
t.after(() => rm(home, { recursive: true, force: true }));
|
|
56
|
+
const day = join(home, "sessions", "2026", "10", "06");
|
|
57
|
+
await mkdir(day, { recursive: true });
|
|
58
|
+
return { home, day, path: join(day, nativeName(ROOT)) };
|
|
59
|
+
}
|
|
60
|
+
test("root: raw messages, top-level envelope metadata, native tool pairing and no display duplicates", async (t) => {
|
|
61
|
+
const f = await fixture(t);
|
|
62
|
+
await writeFile(f.path, jsonl([
|
|
63
|
+
row("session_meta", meta(), 0),
|
|
64
|
+
row("turn_context", turnContext("gpt-5.4"), 1),
|
|
65
|
+
row("response_item", message("system", "system context"), 2),
|
|
66
|
+
row("response_item", message("developer", "developer context"), 3, { client_authored: true, user_input_order: 1 }),
|
|
67
|
+
row("response_item", message("user", "please run this"), 4),
|
|
68
|
+
row("event_msg", completed({ type: "UserMessage", id: "user-ui", content: [{ type: "text", text: "please run this", text_elements: [] }] }), 5),
|
|
69
|
+
row("response_item", { type: "function_call", name: "exec_command", arguments: '{"cmd":"printf output"}', call_id: "cmd-1" }, 6),
|
|
70
|
+
row("event_msg", completed(command("cmd-1")), 7),
|
|
71
|
+
row("response_item", { type: "function_call_output", call_id: "cmd-1", output: "partial\nerror" }, 8),
|
|
72
|
+
row("response_item", message("assistant", "finished", "a1"), 9),
|
|
73
|
+
row("event_msg", completed({ type: "AgentMessage", id: "a1", content: [{ type: "Text", text: "finished" }], phase: "final_answer" }), 10),
|
|
74
|
+
]));
|
|
75
|
+
const before = await readFile(f.path), info = await stat(f.path);
|
|
76
|
+
const result = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
77
|
+
assert.equal(result.threadId, ROOT);
|
|
78
|
+
assert.equal(result.rootSessionId, ROOT);
|
|
79
|
+
assert.equal(result.model, "gpt-5.4");
|
|
80
|
+
assert.equal(result.currentWindowId, W0);
|
|
81
|
+
assert.equal(result.currentWindowNumber, 0);
|
|
82
|
+
assert.equal(result.firstWindowId, W0);
|
|
83
|
+
assert.equal(result.previousWindowId, undefined);
|
|
84
|
+
const { projection } = result, items = allItems(projection);
|
|
85
|
+
assert.deepEqual(items.map((i) => i.seq), [3, 4, 5, 7, 10]);
|
|
86
|
+
assert.deepEqual(items.map((i) => i.role), ["context", "context", "user", "tool", "assistant"]);
|
|
87
|
+
const tool = await historyRead.execute({ seq: 7 }, projection);
|
|
88
|
+
assert.ok(tool.ok);
|
|
89
|
+
assert.equal(tool.data.tool, "exec_command");
|
|
90
|
+
assert.equal(tool.data.tool_status, "error");
|
|
91
|
+
assert.match(historyRead.render(tool), /printf output/);
|
|
92
|
+
assert.match(historyRead.render(tool), /partial\nerror/);
|
|
93
|
+
assert.equal(tool.data.output_truncated, undefined);
|
|
94
|
+
assert.equal(tool.data.nested_calls, undefined);
|
|
95
|
+
const paired = await historyRead.execute({ seq: 9 }, projection);
|
|
96
|
+
assert.equal(paired.ok, false);
|
|
97
|
+
assert.match(historyRead.render(paired), /read seq 7 instead/);
|
|
98
|
+
const omitted = await historyRead.execute({ seq: 6 }, projection);
|
|
99
|
+
assert.match(historyRead.render(omitted), /holds nothing/);
|
|
100
|
+
const page = await historyList.execute({ query: "printf output" }, projection);
|
|
101
|
+
assert.ok(page.ok);
|
|
102
|
+
assert.equal(page.data.items.length, 1);
|
|
103
|
+
assert.match(historyList.render(page), /seq 7/);
|
|
104
|
+
assert.deepEqual(await readFile(f.path), before);
|
|
105
|
+
assert.equal((await stat(f.path)).mtimeMs, info.mtimeMs);
|
|
106
|
+
});
|
|
107
|
+
test("two native checkpoints retain old raw history; replacement_history is not new dialogue", async (t) => {
|
|
108
|
+
const f = await fixture(t);
|
|
109
|
+
const prefix = [row("session_meta", meta(), 0), row("response_item", message("user", "old raw text"), 1), row("response_item", message("assistant", "old answer"), 2)];
|
|
110
|
+
await writeFile(f.path, jsonl(prefix));
|
|
111
|
+
const first = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
112
|
+
await appendFile(f.path, jsonl([
|
|
113
|
+
row("compacted", compact(W1, W0, 1, [message("user", "COPIED CHECKPOINT TEXT")]), 3),
|
|
114
|
+
row("event_msg", completed({ type: "ContextCompaction", id: "ui-compact" }), 4),
|
|
115
|
+
row("response_item", message("user", "middle text"), 5),
|
|
116
|
+
row("compacted", compact(W2, W1, 2), 6),
|
|
117
|
+
row("response_item", message("assistant", "current text"), 7),
|
|
118
|
+
]));
|
|
119
|
+
const second = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
120
|
+
assert.equal(second.currentWindowId, W2);
|
|
121
|
+
assert.equal(second.currentWindowNumber, 2);
|
|
122
|
+
assert.equal(second.previousWindowId, W1);
|
|
123
|
+
assert.equal(second.firstWindowId, W0);
|
|
124
|
+
assert.deepEqual(allItems(second.projection).filter((i) => i.seq <= 3), allItems(first.projection));
|
|
125
|
+
assert.doesNotMatch(allItems(second.projection).map(eventDocument).join("\n"), /COPIED CHECKPOINT TEXT/);
|
|
126
|
+
const windows = await historyWindows.execute({}, second.projection, second.threadId);
|
|
127
|
+
assert.ok(windows.ok);
|
|
128
|
+
assert.equal(windows.data.session_id, ROOT);
|
|
129
|
+
assert.deepEqual(windows.data.windows.map((w) => [w.window_id, w.first_seq, w.last_seq]), [
|
|
130
|
+
[`codex:${ROOT}:${W0}`, 2, 3], [`codex:${ROOT}:${W1}`, 4, 6], [`codex:${ROOT}:${W2}`, 7, 8],
|
|
131
|
+
]);
|
|
132
|
+
const previous = await historyList.execute({ window_id: "@previous", roles: ["user"] }, second.projection);
|
|
133
|
+
assert.match(historyList.render(previous), /middle text/);
|
|
134
|
+
const old = await historyRead.execute({ seq: 2 }, second.projection);
|
|
135
|
+
assert.match(historyRead.render(old), /old raw text/);
|
|
136
|
+
const { projection: _projection, ...facts } = second;
|
|
137
|
+
assert.deepEqual(await readCodexTranscriptState({ transcriptPath: f.path, threadId: ROOT }), facts);
|
|
138
|
+
assert.deepEqual(await readCodexHistory({ transcriptPath: f.path, threadId: ROOT }), second);
|
|
139
|
+
});
|
|
140
|
+
test("legacy source coordinates stay append-stable including a pending call and incomplete/valid JSON append tails", async (t) => {
|
|
141
|
+
const f = await fixture(t);
|
|
142
|
+
const head = jsonl([
|
|
143
|
+
row("session_meta", meta(ROOT, { history_mode: "legacy" })),
|
|
144
|
+
row("response_item", { type: "function_call", call_id: "pending", name: "lookup", arguments: '{"q":"needle"}' }),
|
|
145
|
+
]);
|
|
146
|
+
await writeFile(f.path, head + '{"timestamp":');
|
|
147
|
+
const source = { transcriptPath: f.path, threadId: ROOT };
|
|
148
|
+
const pending = await readCodexHistory(source);
|
|
149
|
+
assert.equal(allItems(pending.projection)[0]?.execution?.status, "unfinished");
|
|
150
|
+
const result = row("response_item", { type: "function_call_output", call_id: "pending", output: [{ type: "input_text", text: "answer" }, { type: "input_image", image_url: "data:omitted" }] });
|
|
151
|
+
await writeFile(f.path, head + JSON.stringify(result));
|
|
152
|
+
assert.deepEqual(await readCodexHistory(source), pending); // JSON without delimiter is not committed
|
|
153
|
+
await appendFile(f.path, "\n");
|
|
154
|
+
const complete = await readCodexHistory(source);
|
|
155
|
+
assert.equal(allItems(complete.projection)[0]?.seq, 2);
|
|
156
|
+
assert.equal(allItems(complete.projection)[0]?.execution?.status, "ok");
|
|
157
|
+
assert.match(eventDocument(allItems(complete.projection)[0]), /answer\n\[Codex image content omitted\]/);
|
|
158
|
+
await appendFile(f.path, jsonl([row("response_item", message("assistant", "later"))]));
|
|
159
|
+
assert.deepEqual(allItems((await readCodexHistory(source)).projection).slice(0, 1), allItems(complete.projection));
|
|
160
|
+
});
|
|
161
|
+
test("paginated native ordinal gaps never become mutable display ranks", async (t) => {
|
|
162
|
+
const f = await fixture(t);
|
|
163
|
+
await writeFile(f.path, jsonl([row("session_meta", meta(), 0), row("response_item", message("user", "one"), 20), row("response_item", message("assistant", "two"), 49)]));
|
|
164
|
+
const result = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
165
|
+
assert.deepEqual(allItems(result.projection).map((i) => i.seq), [21, 50]);
|
|
166
|
+
await appendFile(f.path, jsonl([row("response_item", message("user", "three"), 100)]));
|
|
167
|
+
const appended = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
168
|
+
assert.deepEqual(allItems(appended.projection).slice(0, 2), allItems(result.projection));
|
|
169
|
+
assert.equal(appended.projection.highestSeq, 101);
|
|
170
|
+
});
|
|
171
|
+
test("fork + reverted physical lineage resolves only bounded ancestry, including archived zstd", async (t) => {
|
|
172
|
+
const f = await fixture(t);
|
|
173
|
+
const ancestor = jsonl([row("session_meta", meta(), 0), row("response_item", message("user", "父前缀 🦈"), 1), row("response_item", message("assistant", "kept answer"), 2)]);
|
|
174
|
+
const archived = join(f.home, "archived_sessions");
|
|
175
|
+
await mkdir(archived);
|
|
176
|
+
await writeFile(join(archived, nativeName(ROOT) + ".zst"), zstdCompressSync(Buffer.from(ancestor + jsonl([row("response_item", message("assistant", "EXCLUDED ROOT SUFFIX"), 3)]))));
|
|
177
|
+
const base = { thread_id: ROOT, end_ordinal_exclusive: 3, end_byte_offset: Buffer.byteLength(ancestor) };
|
|
178
|
+
const forkPath = join(f.day, nativeName(FORK));
|
|
179
|
+
const forkPrefix = jsonl([
|
|
180
|
+
row("session_meta", meta(FORK, { forked_from_id: ROOT, forked_from_ordinal_exclusive: 3, history_base: base, context_window: { window_id: WC } }), 3),
|
|
181
|
+
row("response_item", message("user", "fork-local kept"), 4),
|
|
182
|
+
]);
|
|
183
|
+
await writeFile(forkPath, forkPrefix + jsonl([row("response_item", message("assistant", "EXCLUDED FORK SUFFIX"), 5)]));
|
|
184
|
+
// Same thread ID, NEW physical rollout ID, cutoff addresses the prior file.
|
|
185
|
+
const replacementPath = join(f.day, nativeName(FORK, REVERT));
|
|
186
|
+
await writeFile(replacementPath, jsonl([
|
|
187
|
+
row("session_meta", meta(FORK, { forked_from_id: ROOT, forked_from_ordinal_exclusive: 3, history_base: { thread_id: FORK, end_ordinal_exclusive: 5, end_byte_offset: Buffer.byteLength(forkPrefix) }, context_window: { window_id: WC } }), 5),
|
|
188
|
+
row("response_item", message("assistant", "new branch"), 6),
|
|
189
|
+
]));
|
|
190
|
+
await writeFile(join(f.day, nativeName(CHILD)), "THIS SIBLING MUST NEVER BE PARSED\n");
|
|
191
|
+
const result = await readCodexHistory({ transcriptPath: replacementPath, threadId: FORK });
|
|
192
|
+
const text = allItems(result.projection).map(eventDocument).join("\n");
|
|
193
|
+
assert.match(text, /父前缀 🦈/);
|
|
194
|
+
assert.match(text, /fork-local kept/);
|
|
195
|
+
assert.match(text, /new branch/);
|
|
196
|
+
assert.doesNotMatch(text, /EXCLUDED|SIBLING/);
|
|
197
|
+
assert.deepEqual(allItems(result.projection).map((i) => i.seq), [2, 3, 5, 7]);
|
|
198
|
+
assert.equal(result.currentWindowId, WC);
|
|
199
|
+
assert.equal(result.threadId, FORK);
|
|
200
|
+
assert.ok(result.projection.windows.every((w) => w.windowId.startsWith(`codex:${FORK}:`)));
|
|
201
|
+
});
|
|
202
|
+
test("child root session_id isn't thread identity; copied inference prefix isn't child dialogue", async (t) => {
|
|
203
|
+
const f = await fixture(t), path = join(f.day, nativeName(CHILD));
|
|
204
|
+
await writeFile(path, jsonl([
|
|
205
|
+
row("session_meta", meta(CHILD, { parent_thread_id: ROOT, forked_from_id: ROOT, source: { subagent: { thread_spawn: { parent_thread_id: ROOT, depth: 1, agent_path: "/root/worker", agent_nickname: "worker", agent_role: "default" } } }, subagent_history_start_ordinal: 3, context_window: { window_id: WC } }), 0),
|
|
206
|
+
row("response_item", message("user", "INHERITED MODEL CONTEXT"), 1, { inherited_user_message: true }),
|
|
207
|
+
row("response_item", message("developer", "INHERITED DEVELOPER"), 2),
|
|
208
|
+
row("event_msg", { type: "thread_settings_applied", thread_id: CHILD, thread_settings: settings("child-model") }, 3),
|
|
209
|
+
row("response_item", message("user", "child task"), 4),
|
|
210
|
+
]));
|
|
211
|
+
const result = await readCodexHistory({ transcriptPath: path, threadId: CHILD });
|
|
212
|
+
assert.equal(result.rootSessionId, ROOT);
|
|
213
|
+
assert.equal(result.threadId, CHILD);
|
|
214
|
+
const windows = await historyWindows.execute({}, result.projection, result.threadId);
|
|
215
|
+
assert.ok(windows.ok);
|
|
216
|
+
assert.equal(windows.data.session_id, CHILD);
|
|
217
|
+
assert.equal(result.model, "child-model");
|
|
218
|
+
assert.equal(result.currentWindowId, WC);
|
|
219
|
+
assert.doesNotMatch(allItems(result.projection).map(eventDocument).join("\n"), /INHERITED/);
|
|
220
|
+
assert.equal(allItems(result.projection).at(-1)?.seq, 5);
|
|
221
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: ROOT }), /not requested threadId.*session_id is root-scoped/);
|
|
222
|
+
});
|
|
223
|
+
test("custom calls, MCP error envelopes, standalone terminal facts and opaque omissions", async (t) => {
|
|
224
|
+
const f = await fixture(t);
|
|
225
|
+
await writeFile(f.path, jsonl([
|
|
226
|
+
row("session_meta", meta(ROOT, { history_mode: "legacy" })),
|
|
227
|
+
row("response_item", { type: "custom_tool_call", call_id: "patch", name: "apply_patch", input: "*** Begin Patch\n*** End Patch" }),
|
|
228
|
+
row("response_item", { type: "custom_tool_call_output", call_id: "patch", output: "patched" }),
|
|
229
|
+
row("response_item", { type: "function_call", call_id: "mcp-1", name: "mcp__repo__read", arguments: '{"path":"nope"}' }),
|
|
230
|
+
row("event_msg", { type: "mcp_tool_call_end", call_id: "mcp-1", invocation: { server: "repo", tool: "read", arguments: { path: "nope" } }, duration: { secs: 0, nanos: 1 }, result: { Ok: { content: [{ type: "text", text: "not found" }], isError: true } } }),
|
|
231
|
+
row("response_item", { type: "function_call_output", call_id: "mcp-1", output: "not found" }),
|
|
232
|
+
row("event_msg", completed(command("user-shell", { source: "user_shell" }))),
|
|
233
|
+
row("response_item", { type: "reasoning", summary: [{ type: "summary_text", text: "recorded summary" }], encrypted_content: "SECRET OPAQUE BYTES" }),
|
|
234
|
+
row("response_item", { type: "function_call", call_id: "bad-json", name: "bad", arguments: "{broken" }),
|
|
235
|
+
]));
|
|
236
|
+
const { projection } = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
237
|
+
const items = allItems(projection);
|
|
238
|
+
assert.equal(items[0]?.execution?.arguments?.input, "*** Begin Patch\n*** End Patch");
|
|
239
|
+
assert.equal(items[1]?.execution?.status, "error");
|
|
240
|
+
assert.equal(items[2]?.execution?.name, "terminal");
|
|
241
|
+
assert.equal(items[2]?.execution?.status, "error");
|
|
242
|
+
assert.match(eventDocument(items[2]), /partial\nerror/);
|
|
243
|
+
assert.match(eventDocument(items[3]), /recorded summary/);
|
|
244
|
+
assert.doesNotMatch(items.map(eventDocument).join("\n"), /SECRET OPAQUE BYTES/);
|
|
245
|
+
assert.equal(items.at(-1)?.execution?.arguments?.raw_arguments, "{broken");
|
|
246
|
+
});
|
|
247
|
+
test("native lifecycle and hook-runtime persisted output use wire spellings and shared raw identities", async (t) => {
|
|
248
|
+
const f = await fixture(t);
|
|
249
|
+
// From protocol.rs EventMsg serde renames and hook_runtime.rs record_pending_input:
|
|
250
|
+
// raw FunctionCallOutput(id/name, no call_id) -> ItemCompleted(FunctionCallOutput).
|
|
251
|
+
// HookStarted/HookCompleted themselves are transient in rollout/src/policy.rs.
|
|
252
|
+
await writeFile(f.path, jsonl([
|
|
253
|
+
row("session_meta", meta(), 0),
|
|
254
|
+
row("event_msg", { type: "thread_settings_applied", thread_id: ROOT, thread_settings: settings("current-settings-model") }, 1),
|
|
255
|
+
row("event_msg", { type: "task_started", turn_id: "turn-1", model_context_window: 272000, collaboration_mode_kind: "default" }, 2),
|
|
256
|
+
row("response_item", { ...message("developer", "hook additional context", "hook-context"), internal_chat_message_metadata_passthrough: { content_item_kinds: ["hooks.additional_context"] } }, 3),
|
|
257
|
+
row("response_item", { type: "function_call_output", id: "hook-result", name: "hook_tool", output: "hook output only once" }, 4),
|
|
258
|
+
row("event_msg", completed({ type: "FunctionCallOutput", id: "hook-result", name: "hook_tool", output: "hook output only once" }), 5),
|
|
259
|
+
row("response_item", { type: "function_call", call_id: "mcp-native", name: "mcp__repo__read", arguments: '{"path":"x"}' }, 6),
|
|
260
|
+
row("response_item", { type: "function_call_output", call_id: "mcp-native", output: "MCP wire error only once" }, 7),
|
|
261
|
+
row("event_msg", completed({ type: "McpToolCall", id: "mcp-native", server: "repo", tool: "read", arguments: { path: "x" }, status: "failed", result: { content: [{ type: "text", text: "MCP wire error only once" }], isError: true }, error: { message: "failure" } }), 8),
|
|
262
|
+
row("response_item", message("assistant", "final answer only once"), 9),
|
|
263
|
+
row("event_msg", { type: "task_complete", turn_id: "turn-1", last_agent_message: "final answer only once" }, 10),
|
|
264
|
+
row("turn_context", turnContext("frozen-companion-model"), 11),
|
|
265
|
+
]));
|
|
266
|
+
const result = await readCodexHistory({ transcriptPath: f.path, threadId: ROOT });
|
|
267
|
+
assert.equal(result.model, "current-settings-model");
|
|
268
|
+
const items = allItems(result.projection), text = items.map(eventDocument).join("\n");
|
|
269
|
+
assert.match(text, /Codex task_started/);
|
|
270
|
+
assert.match(text, /Codex task_complete/);
|
|
271
|
+
assert.equal(text.match(/hook output only once/g)?.length, 1);
|
|
272
|
+
assert.equal(text.match(/MCP wire error only once/g)?.length, 1);
|
|
273
|
+
assert.equal(text.match(/final answer only once/g)?.length, 1);
|
|
274
|
+
assert.equal(items.find((i) => i.seq === 7)?.execution?.status, "error");
|
|
275
|
+
assert.equal(items.find((i) => i.seq === 5)?.execution?.name, "hook_tool");
|
|
276
|
+
});
|
|
277
|
+
test("header-only native facts exist before any compaction, but absent facts are never fabricated", async (t) => {
|
|
278
|
+
const f = await fixture(t), source = { transcriptPath: f.path, threadId: ROOT };
|
|
279
|
+
await writeFile(f.path, jsonl([row("session_meta", meta(), 0)]));
|
|
280
|
+
assert.equal((await readCodexTranscriptState(source)).currentWindowId, W0);
|
|
281
|
+
assert.equal((await readCodexHistory(source)).projection.windows.length, 1);
|
|
282
|
+
await writeFile(f.path, jsonl([row("session_meta", meta(ROOT, { context_window: null }), 0)]));
|
|
283
|
+
const facts = await readCodexTranscriptState(source);
|
|
284
|
+
assert.equal(facts.currentWindowId, undefined);
|
|
285
|
+
assert.equal(facts.currentWindowNumber, undefined);
|
|
286
|
+
assert.equal(facts.firstWindowId, undefined);
|
|
287
|
+
assert.equal((await readCodexHistory(source)).projection.windows.length, 0);
|
|
288
|
+
await appendFile(f.path, jsonl([row("response_item", message("user", "unaddressable"), 1)]));
|
|
289
|
+
await assert.rejects(readCodexHistory(source), /native window identity missing/);
|
|
290
|
+
});
|
|
291
|
+
test("committed malformed, unsupported, unsafe and unproved native shapes refuse explicitly", async (t) => {
|
|
292
|
+
const f = await fixture(t), source = { transcriptPath: f.path, threadId: ROOT };
|
|
293
|
+
await assert.rejects(readCodexHistory(source), /ENOENT/);
|
|
294
|
+
const head = row("session_meta", meta(), 0);
|
|
295
|
+
for (const [rows, expected] of [
|
|
296
|
+
[[row("session_meta", meta(ROOT, { cli_version: "0.161.0" }), 0)], /Unsupported Codex producer/],
|
|
297
|
+
[[head, row("future_record", {}, 1)], /Unsupported Codex rollout record/],
|
|
298
|
+
[[head, row("response_item", { type: "future_item" }, 1)], /Unsupported Codex response/],
|
|
299
|
+
[[head, row("response_item", message("user", "x"))], /paginated record ordinal/],
|
|
300
|
+
[[head, row("response_item", message("user", "x"), 0)], /non-increasing/],
|
|
301
|
+
[[head, row("response_item", message("user", "x"), Number.MAX_SAFE_INTEGER + 1)], /unsafe/],
|
|
302
|
+
[[head, row("response_item", { item: message("user", "wrong envelope") }, 1)], /response_item.type/],
|
|
303
|
+
[[head, row("compacted", { ...compact(W1, W0, 1), replacement_history_metadata: [{}] }, 1)], /metadata alignment/],
|
|
304
|
+
[[head, row("event_msg", { type: "thread_rolled_back", num_turns: 1 }, 1)], /thread_rolled_back/],
|
|
305
|
+
[[head, row("session_meta", meta(CHILD), 1)], /copied session_meta ancestry/],
|
|
306
|
+
]) {
|
|
307
|
+
await writeFile(f.path, jsonl(rows));
|
|
308
|
+
await assert.rejects(readCodexHistory(source), expected);
|
|
309
|
+
}
|
|
310
|
+
await writeFile(f.path, jsonl([head]) + "{broken}\n");
|
|
311
|
+
await assert.rejects(readCodexHistory(source), /Malformed committed.*line 2/);
|
|
312
|
+
});
|
|
313
|
+
test("missing or mismatched ancestry and unsafe cutoff pairs never fall back to concatenation", async (t) => {
|
|
314
|
+
const f = await fixture(t), path = join(f.day, nativeName(CHILD));
|
|
315
|
+
const ancestor = jsonl([row("session_meta", meta(), 0), row("response_item", message("user", "kept"), 1)]);
|
|
316
|
+
const base = { thread_id: ROOT, end_ordinal_exclusive: 2, end_byte_offset: Buffer.byteLength(ancestor) };
|
|
317
|
+
const writeChild = async (history_base, extra = {}) => writeFile(path, jsonl([row("session_meta", meta(CHILD, { history_base, forked_from_id: ROOT, ...extra }), history_base.end_ordinal_exclusive)]));
|
|
318
|
+
await writeChild(base);
|
|
319
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: CHILD }), /no local source file/);
|
|
320
|
+
await writeFile(f.path, ancestor);
|
|
321
|
+
await writeChild({ ...base, end_byte_offset: base.end_byte_offset - 1 });
|
|
322
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: CHILD }), /complete decoded JSONL boundary/);
|
|
323
|
+
await writeChild({ ...base, end_ordinal_exclusive: 3 });
|
|
324
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: CHILD }), /ordinal cutoff is beyond the proved prefix/);
|
|
325
|
+
await writeChild(base, { forked_from_ordinal_exclusive: 1 });
|
|
326
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: CHILD }), /exceeds the logical fork cutoff/);
|
|
327
|
+
await writeChild(base);
|
|
328
|
+
await writeFile(f.path, jsonl([row("session_meta", meta(FORK), 0), row("response_item", message("user", "kept"), 1)]));
|
|
329
|
+
await assert.rejects(readCodexHistory({ transcriptPath: path, threadId: CHILD }), /identity mismatch/);
|
|
330
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|