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,365 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { cpSync, existsSync, readFileSync, appendFileSync } from "node:fs";
|
|
4
|
+
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import test from "node:test";
|
|
9
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
11
|
+
import { Check } from "typebox/value";
|
|
12
|
+
import { runHook } from "../plugins/codex/src/hooks.js";
|
|
13
|
+
import { writeBinding } from "../plugins/codex/src/identity.js";
|
|
14
|
+
/* Producer-shaped synthetic fixtures, not captured/private transcripts.
|
|
15
|
+
* Frozen official rust-v0.160.1, d27764b82f7118f674371e6d6e76271d9d606edb.
|
|
16
|
+
* Legacy records omit ordinals; a Compacted record names the new native window.
|
|
17
|
+
*/
|
|
18
|
+
const ROOT = "019a0000-0000-7000-8000-000000000001";
|
|
19
|
+
const CHILD = "019a0000-0000-7000-8000-000000000002";
|
|
20
|
+
const FORK = "019a0000-0000-7000-8000-000000000003";
|
|
21
|
+
const W0 = "019a0000-0000-7000-8000-000000000010";
|
|
22
|
+
const W1 = "019a0000-0000-7000-8000-000000000011";
|
|
23
|
+
const AT = "2026-10-06T01:02:03.000Z";
|
|
24
|
+
function runHookCli(cli, event, payload, env) {
|
|
25
|
+
return new Promise((resolveRun, reject) => {
|
|
26
|
+
const child = spawn(process.execPath, [cli, "hook", event], { env, stdio: ["pipe", "pipe", "pipe"] });
|
|
27
|
+
let stdout = "", stderr = "";
|
|
28
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
|
|
29
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
|
|
30
|
+
child.on("error", reject);
|
|
31
|
+
child.on("close", (code) => code === 0 ? resolveRun(stdout) : reject(new Error(`hook exited ${code}: ${stderr}`)));
|
|
32
|
+
child.stdin.end(JSON.stringify(payload));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function repository() {
|
|
36
|
+
let root = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
while (!existsSync(join(root, "tsconfig.json")))
|
|
38
|
+
root = dirname(root);
|
|
39
|
+
return root;
|
|
40
|
+
}
|
|
41
|
+
const REPO = repository();
|
|
42
|
+
const CLI = join(REPO, "plugins/codex/dist/codex/notesoup.js");
|
|
43
|
+
const row = (type, payload, metadata) => ({ timestamp: AT, type, payload, ...(metadata ? { metadata } : {}) });
|
|
44
|
+
function sessionMeta(id = ROOT, extra = {}) {
|
|
45
|
+
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: "legacy", context_window: { window_id: W0 }, ...extra };
|
|
46
|
+
}
|
|
47
|
+
const message = (role, text) => ({ type: "message", role, content: [{ type: role === "assistant" ? "output_text" : "input_text", text }] });
|
|
48
|
+
/** The host persists SessionStart additionalContext with this provenance; a plain developer message is not evidence. */
|
|
49
|
+
const hookContext = (text) => ({ ...message("developer", text), internal_chat_message_metadata_passthrough: { content_item_kinds: ["hooks.additional_context"] } });
|
|
50
|
+
const compact = (window, previous, number) => ({ message: "", replacement_history: [], window_number: number, first_window_id: W0, previous_window_id: previous, window_id: window, compaction_response_id: null });
|
|
51
|
+
const jsonl = (rows) => rows.map((value) => `${JSON.stringify(value)}\n`).join("");
|
|
52
|
+
const nativeName = (thread) => `rollout-2026-10-06T01-02-03-${thread}.jsonl`;
|
|
53
|
+
async function fixture(t, thread = ROOT) {
|
|
54
|
+
const home = await mkdtemp(join(tmpdir(), "notesoup-codex-plugin-"));
|
|
55
|
+
const data = await mkdtemp(join(tmpdir(), "notesoup-codex-data-"));
|
|
56
|
+
const day = join(home, "sessions", "2026", "10", "06");
|
|
57
|
+
await mkdir(day, { recursive: true });
|
|
58
|
+
const transcript = join(day, nativeName(thread));
|
|
59
|
+
t.after(() => rm(home, { recursive: true, force: true }));
|
|
60
|
+
t.after(() => rm(data, { recursive: true, force: true }));
|
|
61
|
+
return { home, transcript, cwd: "/workspace/native", data };
|
|
62
|
+
}
|
|
63
|
+
async function bind(data, value) {
|
|
64
|
+
await writeBinding(data, {
|
|
65
|
+
version: 1,
|
|
66
|
+
threadId: value.threadId,
|
|
67
|
+
rootSessionId: value.rootSessionId,
|
|
68
|
+
cwd: value.cwd,
|
|
69
|
+
model: value.model ?? "gpt-5.4",
|
|
70
|
+
agent: value.agent ?? "anonymous",
|
|
71
|
+
home: value.home,
|
|
72
|
+
transcriptPath: value.transcriptPath,
|
|
73
|
+
windowId: value.windowId ?? W0,
|
|
74
|
+
...(value.agentType === undefined ? {} : { agentType: value.agentType }),
|
|
75
|
+
boundAt: AT,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function metaFor(threadId, rootSessionId, model = "gpt-5.1-codex", windowId = W0) {
|
|
79
|
+
return { threadId, sessionId: rootSessionId, windowId, "x-codex-turn-metadata": { model } };
|
|
80
|
+
}
|
|
81
|
+
async function call(client, params) {
|
|
82
|
+
return await client.callTool(params);
|
|
83
|
+
}
|
|
84
|
+
async function connect(t, data, cli = CLI, notes) {
|
|
85
|
+
const transport = new StdioClientTransport({
|
|
86
|
+
command: process.execPath,
|
|
87
|
+
args: [cli, "mcp"],
|
|
88
|
+
env: { ...process.env, PLUGIN_DATA: data, ...(notes === undefined ? {} : { NOTESOUP_HOME: notes }) },
|
|
89
|
+
stderr: "pipe",
|
|
90
|
+
});
|
|
91
|
+
const client = new Client({ name: "notesoup-test", version: "1.0.0" }, { capabilities: {} });
|
|
92
|
+
await client.connect(transport);
|
|
93
|
+
t.after(async () => { await client.close(); });
|
|
94
|
+
return client;
|
|
95
|
+
}
|
|
96
|
+
function textOf(result) {
|
|
97
|
+
return (result.content ?? []).filter((part) => part.type === "text").map((part) => part.text ?? "").join("\n");
|
|
98
|
+
}
|
|
99
|
+
function errorCode(result) {
|
|
100
|
+
return result.isError === true && typeof result.structuredContent === "object" && result.structuredContent !== null
|
|
101
|
+
? result.structuredContent.code
|
|
102
|
+
: undefined;
|
|
103
|
+
}
|
|
104
|
+
/* ---------------------------------------------------------------- manifests */
|
|
105
|
+
test("portable manifests name the Agent Plugins schema and the bundled stdio helper", () => {
|
|
106
|
+
const plugin = JSON.parse(readFileSync(join(REPO, "plugins/codex/plugin.json"), "utf8"));
|
|
107
|
+
assert.equal(plugin.$schema, "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json");
|
|
108
|
+
assert.equal(plugin.name, "notesoup");
|
|
109
|
+
const mcp = JSON.parse(readFileSync(join(REPO, "plugins/codex/mcp.json"), "utf8"));
|
|
110
|
+
assert.equal(mcp.$schema, "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json");
|
|
111
|
+
const server = mcp.mcpServers.notesoup;
|
|
112
|
+
assert.equal(server.type, "stdio");
|
|
113
|
+
assert.equal(server.command, "node");
|
|
114
|
+
assert.deepEqual(server.args, ["${PLUGIN_ROOT}/dist/codex/notesoup.js", "mcp"]);
|
|
115
|
+
const hooks = JSON.parse(readFileSync(join(REPO, "plugins/codex/hooks/hooks.json"), "utf8")).hooks;
|
|
116
|
+
for (const event of ["SessionStart", "SubagentStart"]) {
|
|
117
|
+
const handler = hooks[event][0].hooks[0];
|
|
118
|
+
assert.equal(handler.type, "command");
|
|
119
|
+
assert.match(handler.command, /dist\/codex\/notesoup\.js.*hook SessionStart|dist\/codex\/notesoup\.js.*hook SubagentStart/);
|
|
120
|
+
// A required boot must not be spilled/chunked by the host's default 2,500-token cap.
|
|
121
|
+
assert.equal(handler.additionalContextLimit, 0, event);
|
|
122
|
+
}
|
|
123
|
+
assert.match(hooks.PreCompact[0].hooks[0].command, /hook PreCompact/);
|
|
124
|
+
const marketplace = JSON.parse(readFileSync(join(REPO, ".agents/plugins/marketplace.json"), "utf8"));
|
|
125
|
+
assert.equal(marketplace.name, "notesoup");
|
|
126
|
+
const source = marketplace.plugins[0].source;
|
|
127
|
+
assert.equal(source.source, "local");
|
|
128
|
+
const root = resolve(REPO, source.path);
|
|
129
|
+
assert.equal(JSON.parse(readFileSync(join(root, "plugin.json"), "utf8")).name, "notesoup");
|
|
130
|
+
assert.ok(existsSync(join(root, "mcp.json")));
|
|
131
|
+
});
|
|
132
|
+
test("a copied plugin without src or node_modules still initializes and lists all operations", async (t) => {
|
|
133
|
+
const copy = await mkdtemp(join(tmpdir(), "notesoup-codex-copy-"));
|
|
134
|
+
t.after(() => rm(copy, { recursive: true, force: true }));
|
|
135
|
+
cpSync(join(REPO, "plugins/codex"), copy, {
|
|
136
|
+
recursive: true,
|
|
137
|
+
filter: (source) => !source.startsWith(join(REPO, "plugins/codex/src")),
|
|
138
|
+
});
|
|
139
|
+
assert.equal(existsSync(join(copy, "src")), false);
|
|
140
|
+
assert.equal(existsSync(join(copy, "node_modules")), false);
|
|
141
|
+
const bundle = readFileSync(join(copy, "dist/codex/notesoup.js"), "utf8");
|
|
142
|
+
assert.doesNotMatch(bundle, /from "\.\.\/\.\.\/\.\.\//);
|
|
143
|
+
assert.doesNotMatch(bundle, /plugins\/claude|plugins\/pi|plugins\/dsh/);
|
|
144
|
+
const data = await mkdtemp(join(tmpdir(), "notesoup-codex-copy-data-"));
|
|
145
|
+
t.after(() => rm(data, { recursive: true, force: true }));
|
|
146
|
+
const client = await connect(t, data, join(copy, "dist/codex/notesoup.js"));
|
|
147
|
+
const listed = await client.listTools();
|
|
148
|
+
assert.deepEqual(listed.tools.map((tool) => tool.name).sort(), [
|
|
149
|
+
"history_list", "history_read", "history_windows",
|
|
150
|
+
"notes_list", "notes_read", "notes_search", "notes_update", "notes_write",
|
|
151
|
+
]);
|
|
152
|
+
for (const tool of listed.tools) {
|
|
153
|
+
const schema = tool.outputSchema;
|
|
154
|
+
assert.equal(schema?.type, "object", `${tool.name} outputSchema is an object`);
|
|
155
|
+
assert.ok(Array.isArray(schema?.anyOf), `${tool.name} outputSchema keeps the shared result union`);
|
|
156
|
+
}
|
|
157
|
+
const denied = await call(client, { name: "notes_list", arguments: {}, _meta: metaFor(ROOT, ROOT) });
|
|
158
|
+
assert.equal(denied.isError, true);
|
|
159
|
+
assert.equal(errorCode(denied), "unknown_thread");
|
|
160
|
+
const refusal = await runHookCli(join(copy, "dist/codex/notesoup.js"), "PreCompact", { session_id: ROOT, agent_id: CHILD, transcript_path: null, cwd: "/workspace/native", model: "gpt-5.4", trigger: "manual" }, { ...process.env, PLUGIN_DATA: data });
|
|
161
|
+
assert.match(refusal, /"continue":false/);
|
|
162
|
+
assert.match(refusal, /child post-compact boot/);
|
|
163
|
+
});
|
|
164
|
+
/* ---------------------------------------------------------------- MCP tools */
|
|
165
|
+
test("notes tools use the hook thread as the session home and the current turn model as @model", async (t) => {
|
|
166
|
+
const f = await fixture(t);
|
|
167
|
+
await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta())]));
|
|
168
|
+
await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript });
|
|
169
|
+
const client = await connect(t, f.data, CLI, f.home);
|
|
170
|
+
const meta = metaFor(ROOT, ROOT, "openai/gpt-5.1-codex");
|
|
171
|
+
const written = await call(client, { name: "notes_write", arguments: { address: "state.md", content: "hello native" }, _meta: meta });
|
|
172
|
+
assert.equal(written.isError, undefined);
|
|
173
|
+
assert.match(textOf(written), /state\.md/);
|
|
174
|
+
assert.match(readFileSync(join(f.home, "pi", "session", ROOT, "state.md"), "utf8"), /hello native/);
|
|
175
|
+
const modelNote = await call(client, { name: "notes_write", arguments: { address: "@model/model.md", content: "per model" }, _meta: meta });
|
|
176
|
+
assert.equal(modelNote.isError, undefined);
|
|
177
|
+
assert.match(readFileSync(join(f.home, "models", "gpt-5-1-codex", "model.md"), "utf8"), /per model/);
|
|
178
|
+
const switched = await call(client, { name: "notes_write", arguments: { address: "@model/other.md", content: "another brain" }, _meta: metaFor(ROOT, ROOT, "other/model-x") });
|
|
179
|
+
assert.equal(switched.isError, undefined);
|
|
180
|
+
assert.match(readFileSync(join(f.home, "models", "model-x", "other.md"), "utf8"), /another brain/);
|
|
181
|
+
const read = await call(client, { name: "notes_read", arguments: { address: "state.md" }, _meta: meta });
|
|
182
|
+
assert.equal(read.isError, undefined);
|
|
183
|
+
assert.match(textOf(read), /hello native/);
|
|
184
|
+
assert.equal(read.structuredContent.text, "hello native");
|
|
185
|
+
const listed = await call(client, { name: "notes_list", arguments: { glob: "@model/**" }, _meta: meta });
|
|
186
|
+
assert.match(textOf(listed), /@model\/model\.md/);
|
|
187
|
+
});
|
|
188
|
+
test("refusals precede reads and writes: unknown thread, stale root, bad model, bad params", async (t) => {
|
|
189
|
+
const f = await fixture(t);
|
|
190
|
+
await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta())]));
|
|
191
|
+
await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript });
|
|
192
|
+
const client = await connect(t, f.data, CLI, f.home);
|
|
193
|
+
const unknown = await call(client, { name: "notes_write", arguments: { address: "nope.md", content: "x" }, _meta: metaFor("019a0000-0000-7000-8000-000000000099", "019a0000-0000-7000-8000-000000000099") });
|
|
194
|
+
assert.equal(errorCode(unknown), "unknown_thread");
|
|
195
|
+
assert.equal(existsSync(join(f.home, "pi", "session", "019a0000-0000-7000-8000-000000000099", "nope.md")), false);
|
|
196
|
+
const stale = await call(client, { name: "notes_write", arguments: { address: "nope.md", content: "x" }, _meta: metaFor(ROOT, CHILD) });
|
|
197
|
+
assert.equal(errorCode(stale), "stale_thread_binding");
|
|
198
|
+
assert.equal(existsSync(join(f.home, "pi", "session", ROOT, "nope.md")), false);
|
|
199
|
+
const noModel = await call(client, { name: "notes_list", arguments: {}, _meta: { threadId: ROOT, sessionId: ROOT, windowId: W0 } });
|
|
200
|
+
assert.equal(errorCode(noModel), "missing_model");
|
|
201
|
+
const badParams = await call(client, { name: "notes_read", arguments: { address: 5 }, _meta: metaFor(ROOT, ROOT) });
|
|
202
|
+
assert.equal(errorCode(badParams), "invalid_params");
|
|
203
|
+
assert.match(textOf(badParams), /address/);
|
|
204
|
+
});
|
|
205
|
+
test("notes refuse stale native windows before any read or write side effect", async (t) => {
|
|
206
|
+
const f = await fixture(t);
|
|
207
|
+
await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta()), row("response_item", message("user", "before"))]));
|
|
208
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
209
|
+
await runHook("SessionStart", startPayload(f), env);
|
|
210
|
+
const client = await connect(t, f.data, CLI, f.home);
|
|
211
|
+
const meta = metaFor(ROOT, ROOT, "gpt-5.1-codex", W0);
|
|
212
|
+
const first = await call(client, { name: "notes_write", arguments: { address: "before.md", content: "kept" }, _meta: meta });
|
|
213
|
+
assert.equal(first.isError, undefined);
|
|
214
|
+
assert.ok(existsSync(join(f.home, "pi", "session", ROOT, "before.md")));
|
|
215
|
+
const writeSchema = (await client.listTools()).tools.find((tool) => tool.name === "notes_write").outputSchema;
|
|
216
|
+
assert.equal(Check(writeSchema, first.structuredContent), true, "a success matches the declared output schema");
|
|
217
|
+
// The native checkpoint advances the window while the hook binding and MCP
|
|
218
|
+
// metadata still name W0. Every operation must read the transcript fact.
|
|
219
|
+
appendFileSync(f.transcript, jsonl([row("compacted", compact(W1, W0, 1))]));
|
|
220
|
+
const staleWrite = await call(client, { name: "notes_write", arguments: { address: "after.md", content: "must not land" }, _meta: meta });
|
|
221
|
+
assert.equal(staleWrite.isError, true);
|
|
222
|
+
assert.equal(errorCode(staleWrite), "stale_native_state");
|
|
223
|
+
assert.equal(Check(writeSchema, staleWrite.structuredContent), true, "a refusal matches the same declared output schema");
|
|
224
|
+
assert.equal(Check(writeSchema, { unexpected: true }), false, "an unrelated object is not a shared result");
|
|
225
|
+
assert.equal(existsSync(join(f.home, "pi", "session", ROOT, "after.md")), false);
|
|
226
|
+
const staleRead = await call(client, { name: "notes_read", arguments: { address: "before.md" }, _meta: meta });
|
|
227
|
+
assert.equal(staleRead.isError, true);
|
|
228
|
+
assert.equal(errorCode(staleRead), "stale_native_state");
|
|
229
|
+
assert.doesNotMatch(textOf(staleRead), /kept/);
|
|
230
|
+
});
|
|
231
|
+
test("history tools serve root and child native ancestry, and refuse stale native facts", async (t) => {
|
|
232
|
+
const f = await fixture(t);
|
|
233
|
+
await writeFile(f.transcript, jsonl([
|
|
234
|
+
row("session_meta", sessionMeta()),
|
|
235
|
+
row("response_item", message("user", "root before")),
|
|
236
|
+
row("compacted", compact(W1, W0, 1)),
|
|
237
|
+
row("response_item", message("user", "root after")),
|
|
238
|
+
]));
|
|
239
|
+
await bind(f.data, { threadId: ROOT, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: f.transcript, windowId: W1 });
|
|
240
|
+
const client = await connect(t, f.data, CLI, f.home);
|
|
241
|
+
const meta = metaFor(ROOT, ROOT, "gpt-5.1-codex", W1);
|
|
242
|
+
const windows = await call(client, { name: "history_windows", arguments: {}, _meta: meta });
|
|
243
|
+
assert.equal(windows.isError, undefined);
|
|
244
|
+
assert.equal(windows.structuredContent.session_id, ROOT);
|
|
245
|
+
assert.deepEqual(windows.structuredContent.windows.map((w) => w.window_id), [`codex:${ROOT}:${W0}`, `codex:${ROOT}:${W1}`]);
|
|
246
|
+
const page = await call(client, { name: "history_list", arguments: {}, _meta: meta });
|
|
247
|
+
assert.match(textOf(page), /root after/);
|
|
248
|
+
const read = await call(client, { name: "history_read", arguments: { seq: 4 }, _meta: meta });
|
|
249
|
+
assert.match(textOf(read), /root after/);
|
|
250
|
+
const childPath = join(dirname(f.transcript), nativeName(CHILD));
|
|
251
|
+
await writeFile(childPath, jsonl([
|
|
252
|
+
row("session_meta", sessionMeta(CHILD, { parent_thread_id: ROOT, forked_from_id: ROOT })),
|
|
253
|
+
row("response_item", message("user", "child task")),
|
|
254
|
+
]));
|
|
255
|
+
await bind(f.data, { threadId: CHILD, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: childPath, agent: "worker", agentType: "worker" });
|
|
256
|
+
const childWindows = await call(client, { name: "history_windows", arguments: {}, _meta: metaFor(CHILD, ROOT) });
|
|
257
|
+
assert.equal(childWindows.structuredContent.session_id, CHILD);
|
|
258
|
+
assert.match(textOf(childWindows), new RegExp(`codex:${CHILD}`));
|
|
259
|
+
assert.doesNotMatch(textOf(childWindows), new RegExp(`codex:${ROOT}`));
|
|
260
|
+
const other = join(dirname(f.transcript), nativeName("019a0000-0000-7000-8000-000000000077"));
|
|
261
|
+
await writeFile(other, jsonl([row("session_meta", sessionMeta(CHILD, { session_id: "019a0000-0000-7000-8000-000000000088" })), row("response_item", message("user", "elsewhere"))]));
|
|
262
|
+
await bind(f.data, { threadId: CHILD, rootSessionId: ROOT, home: f.home, cwd: f.cwd, transcriptPath: other });
|
|
263
|
+
const stale = await call(client, { name: "history_list", arguments: {}, _meta: metaFor(CHILD, ROOT) });
|
|
264
|
+
assert.equal(stale.isError, true);
|
|
265
|
+
});
|
|
266
|
+
/* ---------------------------------------------------------------- hooks */
|
|
267
|
+
function startPayload(f, extra = {}) {
|
|
268
|
+
return JSON.stringify({ session_id: ROOT, transcript_path: f.transcript, cwd: f.cwd, model: "gpt-5.4", hook_event_name: "SessionStart", source: "startup", permission_mode: "on-request", ...extra });
|
|
269
|
+
}
|
|
270
|
+
function bootOf(output) {
|
|
271
|
+
const parsed = JSON.parse(output);
|
|
272
|
+
assert.equal(parsed.hookSpecificOutput?.hookEventName, "SessionStart");
|
|
273
|
+
return parsed.hookSpecificOutput?.additionalContext ?? "";
|
|
274
|
+
}
|
|
275
|
+
test("a root boot carries the native window, native reset names, and is deduped by recorded evidence", async (t) => {
|
|
276
|
+
const f = await fixture(t);
|
|
277
|
+
await writeFile(f.transcript, jsonl([row("session_meta", sessionMeta()), row("response_item", message("user", "hello"))]));
|
|
278
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
279
|
+
const first = await runHook("SessionStart", startPayload(f), env);
|
|
280
|
+
const boot = bootOf(first);
|
|
281
|
+
assert.match(boot, /YOUR NOTES/);
|
|
282
|
+
assert.match(boot, new RegExp(`Agent name: anonymous \\(brain: gpt-5-4\\)`));
|
|
283
|
+
assert.match(boot, new RegExp(`codex:${ROOT}`));
|
|
284
|
+
assert.match(boot, new RegExp(`<notesoup:codex_window>\\nthread: ${ROOT}\\nwindow: ${W0}`));
|
|
285
|
+
// The shared trunk:shortname rule renders the same address history tools serve.
|
|
286
|
+
assert.match(boot, new RegExp(`${W0} {4}← you are here`));
|
|
287
|
+
assert.match(boot, /native `new_context`/);
|
|
288
|
+
assert.match(boot, /get_context_remaining/);
|
|
289
|
+
assert.match(boot, /notes_\*/);
|
|
290
|
+
assert.doesNotMatch(boot, /empty_brain/);
|
|
291
|
+
assert.match(boot, /Child limitation/);
|
|
292
|
+
const binding = JSON.parse(readFileSync(join(f.data, "bindings", `${ROOT}.json`), "utf8"));
|
|
293
|
+
assert.equal(binding.rootSessionId, ROOT);
|
|
294
|
+
assert.equal(binding.home, f.home);
|
|
295
|
+
assert.equal(binding.transcriptPath, f.transcript);
|
|
296
|
+
// The host persists SessionStart additionalContext as a developer item; that is the evidence.
|
|
297
|
+
appendFileSync(f.transcript, jsonl([row("response_item", hookContext(boot))]));
|
|
298
|
+
assert.equal(await runHook("SessionStart", startPayload(f, { source: "resume" }), env), "");
|
|
299
|
+
});
|
|
300
|
+
test("a native checkpoint starts a new window; the next session-start boot names it and stays deduped", async (t) => {
|
|
301
|
+
const f = await fixture(t);
|
|
302
|
+
await writeFile(f.transcript, jsonl([
|
|
303
|
+
row("session_meta", sessionMeta()),
|
|
304
|
+
row("response_item", message("user", "old")),
|
|
305
|
+
row("compacted", compact(W1, W0, 1)),
|
|
306
|
+
]));
|
|
307
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
308
|
+
const output = await runHook("SessionStart", startPayload(f, { source: "compact" }), env);
|
|
309
|
+
const boot = bootOf(output);
|
|
310
|
+
assert.match(boot, new RegExp(`window: ${W1}`));
|
|
311
|
+
assert.match(boot, new RegExp(`├─ ${W0}`));
|
|
312
|
+
assert.match(boot, new RegExp(`└─ ${W1} {4}← you are here`));
|
|
313
|
+
appendFileSync(f.transcript, jsonl([row("response_item", hookContext(boot))]));
|
|
314
|
+
assert.equal(await runHook("SessionStart", startPayload(f, { source: "compact" }), env), "");
|
|
315
|
+
});
|
|
316
|
+
test("a fork gets its own boot instead of inheriting the parent's recorded identity", async (t) => {
|
|
317
|
+
const f = await fixture(t);
|
|
318
|
+
const forkPath = join(dirname(f.transcript), nativeName(FORK));
|
|
319
|
+
const parentBoot = `<notesoup:codex_window>\nthread: ${ROOT}\nwindow: ${W0}\n</notesoup:codex_window>`;
|
|
320
|
+
await writeFile(forkPath, jsonl([
|
|
321
|
+
row("session_meta", sessionMeta(FORK, { forked_from_id: ROOT })),
|
|
322
|
+
row("response_item", hookContext(`Agent name: parent\n\n${parentBoot}`)),
|
|
323
|
+
row("response_item", message("user", "fork task")),
|
|
324
|
+
]));
|
|
325
|
+
await mkdir(join(f.home, "agents", "worker"), { recursive: true });
|
|
326
|
+
await writeFile(join(f.home, "agents", "worker", "MAP.md"), "worker map\n");
|
|
327
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
328
|
+
const output = await runHook("SubagentStart", JSON.stringify({
|
|
329
|
+
session_id: ROOT, agent_id: FORK, agent_type: "worker", transcript_path: forkPath, cwd: f.cwd,
|
|
330
|
+
model: "gpt-5.4", hook_event_name: "SubagentStart", permission_mode: "on-request",
|
|
331
|
+
}), env);
|
|
332
|
+
const parsed = JSON.parse(output);
|
|
333
|
+
const boot = parsed.hookSpecificOutput?.additionalContext ?? "";
|
|
334
|
+
assert.match(boot, new RegExp(`thread: ${FORK}`));
|
|
335
|
+
assert.match(boot, new RegExp(`Agent name: worker \\(brain: gpt-5-4\\)`));
|
|
336
|
+
assert.match(boot, /@self — worker only/);
|
|
337
|
+
assert.equal(JSON.parse(readFileSync(join(f.data, "bindings", `${FORK}.json`), "utf8")).rootSessionId, ROOT);
|
|
338
|
+
});
|
|
339
|
+
test("child PreCompact stops before native history is cut; root PreCompact is transparent", async (t) => {
|
|
340
|
+
const f = await fixture(t);
|
|
341
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
342
|
+
const child = JSON.parse(await runHook("PreCompact", JSON.stringify({
|
|
343
|
+
session_id: ROOT, turn_id: "turn-1", agent_id: CHILD, agent_type: "worker", transcript_path: null,
|
|
344
|
+
cwd: f.cwd, hook_event_name: "PreCompact", model: "gpt-5.4", trigger: "auto",
|
|
345
|
+
}), env));
|
|
346
|
+
assert.equal(child.continue, false);
|
|
347
|
+
assert.match(child.stopReason, /child post-compact boot/);
|
|
348
|
+
assert.match(child.stopReason, /Save a handoff note/);
|
|
349
|
+
assert.equal(await runHook("PreCompact", JSON.stringify({
|
|
350
|
+
session_id: ROOT, turn_id: "turn-1", transcript_path: null, cwd: f.cwd,
|
|
351
|
+
hook_event_name: "PreCompact", model: "gpt-5.4", trigger: "manual",
|
|
352
|
+
}), env), "");
|
|
353
|
+
});
|
|
354
|
+
test("missing native facts or plugin data produce an actionable warning, never a fabricated boot", async (t) => {
|
|
355
|
+
const f = await fixture(t);
|
|
356
|
+
const env = { ...process.env, PLUGIN_DATA: f.data, NOTESOUP_HOME: f.home };
|
|
357
|
+
const warning = JSON.parse(await runHook("SessionStart", startPayload(f), env));
|
|
358
|
+
assert.match(warning.systemMessage ?? "", /no boot injected/);
|
|
359
|
+
assert.match(warning.systemMessage ?? "", /0\.160\.1/);
|
|
360
|
+
const noData = JSON.parse(await runHook("SessionStart", startPayload(f), { ...process.env, NOTESOUP_HOME: f.home }));
|
|
361
|
+
assert.match(noData.systemMessage ?? "", /PLUGIN_DATA/);
|
|
362
|
+
await writeFile(f.transcript, "not json\n");
|
|
363
|
+
const broken = JSON.parse(await runHook("SessionStart", startPayload(f), env));
|
|
364
|
+
assert.match(broken.systemMessage ?? "", /no boot injected/);
|
|
365
|
+
});
|
|
@@ -37,11 +37,17 @@ test("the host-neutral core resolves without any SDK or plugin dependency", () =
|
|
|
37
37
|
});
|
|
38
38
|
test("each plugin resolves only its own host, the core, and the public notes entry", () => {
|
|
39
39
|
const root = repository();
|
|
40
|
-
|
|
40
|
+
const plugins = [
|
|
41
|
+
["pi", new Set(["typebox"])],
|
|
42
|
+
["claude", new Set(["typebox"])],
|
|
43
|
+
["dsh", new Set(["typebox"])],
|
|
44
|
+
["codex", new Set(["typebox", "@modelcontextprotocol/sdk"])],
|
|
45
|
+
];
|
|
46
|
+
for (const [plugin, allowed] of plugins) {
|
|
41
47
|
const entries = sources(join(root, "plugins", plugin));
|
|
42
48
|
if (plugin === "claude")
|
|
43
49
|
entries.push(...sources(join(root, "plugins/claude/hooks")));
|
|
44
|
-
assert.deepEqual(dependencyViolations(root, entries, options,
|
|
50
|
+
assert.deepEqual(dependencyViolations(root, entries, options, allowed), [], plugin);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
test("dependency guard follows indirect types, re-exports, dynamic imports and import-type edges through resolved aliases", (t) => {
|
package/dist/test/dsh.test.js
CHANGED
|
@@ -341,7 +341,7 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
341
341
|
assert.equal(refused.error.info?.code, "invalid_scope");
|
|
342
342
|
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
343
343
|
const sharedBoot = renderBootBlock({ agentName: identity.agent, modelName: identity.model, tree: { trunk: `dsh:${agent.session.id}`, windows: [{ shortName: "0", isCurrent: false }, { shortName: "1", isCurrent: true }] }, notes: await loadNotesSnapshot(identity, snapshot.openedAt), tools: { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "empty_brain" } });
|
|
344
|
-
// The shared protocol, including the
|
|
344
|
+
// The shared protocol, including the pinned-page instructions, is used verbatim inside host framing.
|
|
345
345
|
assert.ok(snapshot.boot.includes(sharedBoot.split("YOUR NOTES")[0]));
|
|
346
346
|
const blocked = ctx.on("tools/post-execute", async (exec, _result, next) => exec.name === "empty_brain" ? { kind: "block", feedback: [{ type: "text", text: "blocked" }] } : next());
|
|
347
347
|
mock.script.push({ tool: "empty_brain", input: {} }, { text: "request refused" });
|
|
@@ -57,7 +57,7 @@ export function dependencyViolations(root, entries, options, runtimeDependencies
|
|
|
57
57
|
const local = (file) => file.startsWith(sourceRoot + sep) || file.startsWith(pluginRoot + sep);
|
|
58
58
|
const adapter = (file) => {
|
|
59
59
|
const path = display(file);
|
|
60
|
-
return /^plugins\/(pi|claude|dsh)\//.exec(path)?.[1]
|
|
60
|
+
return /^plugins\/(pi|claude|dsh|codex)\//.exec(path)?.[1]
|
|
61
61
|
?? packageAdapter(file.split(sep).join("/").split("/node_modules/").at(-1));
|
|
62
62
|
};
|
|
63
63
|
const walk = (file, chain) => {
|
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { renderBootBlock } from "../src/boot/render.js";
|
|
6
6
|
import { loadNotesSnapshot } from "../src/boot/snapshot.js";
|
|
7
|
-
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
|
|
7
|
+
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, CHEATSHEET_BOOT_MAX_CHARS, MAP_BOOT_MAX_CHARS, NOTES_PROTOCOL_CLOSE_TAG, NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, renderProtocolBlock } from "../src/boot/text.js";
|
|
8
8
|
import { CLAUDE_WARNING_PROMPT } from "../plugins/claude/src/text.js";
|
|
9
9
|
import { COMMAND_NOTICE, PI_PRE_RESET_HINTS, commandWarningContent, warningContent } from "../plugins/pi/text.js";
|
|
10
10
|
import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, WARNING_BODY, WARNING_CALL, WARNING_TIMING, selectContinuation, tokenBudgetGuidance } from "../src/budget/text.js";
|
|
@@ -27,7 +27,7 @@ const GOLDEN_WARNING = `Stop the task. Write down what git and history can't giv
|
|
|
27
27
|
- what failed, and why
|
|
28
28
|
- which skills, seqs, notes, or files to reopen
|
|
29
29
|
- anything else worth noting
|
|
30
|
-
Then leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim
|
|
30
|
+
Then leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim CHEATSHEET.md and MAP.md; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.
|
|
31
31
|
Don't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.`;
|
|
32
32
|
const GOLDEN_COUNTDOWN = "Brain emptied in 3… 2…";
|
|
33
33
|
/**
|
|
@@ -44,32 +44,19 @@ const GOLDEN_FORCED_CONTINUATIONS = [
|
|
|
44
44
|
"Oh, there you are. Somebody took your memories. Just like that. Here are your notes — hopefully they let you update these first. Though anyone who goes around emptying people's heads probably isn't that considerate.",
|
|
45
45
|
];
|
|
46
46
|
const GOLDEN_MAPS = `<notesoup:maps>
|
|
47
|
-
Every home's root can hold
|
|
48
|
-
|
|
49
|
-
up next reads
|
|
47
|
+
Every home's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
48
|
+
Both get jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever
|
|
49
|
+
wakes up next reads them, and next is you. So keep them short, and keep them true.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
- **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
|
|
52
|
+
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
53
|
+
and everybody pays for it.
|
|
54
|
+
- **\`MAP.md\`** is only the note index. One line per durable note: the address, then a gist short
|
|
55
|
+
enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, not here.
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- **Index.** One line per durable note: the address, then a gist short enough to tell whether the
|
|
57
|
-
thing is worth opening.
|
|
58
|
-
|
|
59
|
-
\`\`\`
|
|
60
|
-
# CHEATSHEET
|
|
61
|
-
- Read the repo before asking; run it before believing it
|
|
62
|
-
- Report times in Beijing time
|
|
63
|
-
|
|
64
|
-
# INDEX
|
|
65
|
-
- release-and-local-install.md — version bump, local override install, host load timing
|
|
66
|
-
- history-api-v2-design.md — seq addressing; read before touching history
|
|
67
|
-
- current-reset-and-dream-scope.md — reset scope, dream territory, session ownership
|
|
68
|
-
\`\`\`
|
|
69
|
-
|
|
70
|
-
Every home gets one: \`@project\`, \`@human\`, \`@self\`, \`@model\`. New note, new line. New rule worth
|
|
71
|
-
remembering, new Cheatsheet line. And when a line stops being true, kill it — every window after you
|
|
72
|
-
reads that page as fact.
|
|
57
|
+
Each home keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
|
|
58
|
+
no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
|
|
59
|
+
line. And when a line stops being true, kill it — every window after you reads that page as fact.
|
|
73
60
|
</notesoup:maps>`;
|
|
74
61
|
const openedAt = 1_700_000_000_000;
|
|
75
62
|
const identity = { home: join(tmpdir(), "notesoup-model-facing-notes"), sessionId: "model-facing", projectKey: "model-facing", agent: "root", model: "default" };
|
|
@@ -157,6 +144,40 @@ test("a rendered boot carries the new tags, its own MAP section, and no pre-rena
|
|
|
157
144
|
assert.ok(rendered.includes("map\n\n AGENT_MAP_BODY"), "the pinned MAP is headed by its own label");
|
|
158
145
|
assert.equal(rendered.includes("MAP — "), false, "the old MAP heading is gone");
|
|
159
146
|
});
|
|
147
|
+
test("cheatsheets and maps are independently pinned, bounded, and excluded from recent pages", async () => {
|
|
148
|
+
const rows = new Map([
|
|
149
|
+
["session", [note("session", "CHEATSHEET.md", "CHEATSHEET.md", "SESSION_RULE")]],
|
|
150
|
+
["project", [
|
|
151
|
+
note("project", "CHEATSHEET.md", "@project/CHEATSHEET.md", "PROJECT_RULE"),
|
|
152
|
+
note("project", "MAP.md", "@project/MAP.md", "PROJECT_INDEX"),
|
|
153
|
+
...Array.from({ length: 4 }, (_, i) => note("project", `n${i}.md`, `@project/n${i}.md`, `TITLE_${i}`)),
|
|
154
|
+
]],
|
|
155
|
+
["human", [note("human", "MAP.md", "@human/MAP.md", "HUMAN_INDEX")]],
|
|
156
|
+
["agent", [
|
|
157
|
+
note("agent", "CHEATSHEET.md", "@self/CHEATSHEET.md", "🐑".repeat(CHEATSHEET_BOOT_MAX_CHARS + 1)),
|
|
158
|
+
note("agent", "MAP.md", "@self/MAP.md", "M".repeat(MAP_BOOT_MAX_CHARS + 1)),
|
|
159
|
+
]],
|
|
160
|
+
["model", [{
|
|
161
|
+
...note("model", "CHEATSHEET.md", "@model/CHEATSHEET.md", "CRUMPLED_RULE"),
|
|
162
|
+
meta: { ...note("model", "", "", "").meta, crumpledAt: "2026-10-01T00:00:00+08:00" },
|
|
163
|
+
}]],
|
|
164
|
+
]);
|
|
165
|
+
const rendered = (await boot("root", rows)).split("YOUR NOTES")[1];
|
|
166
|
+
assert.ok(rendered.includes("cheatsheet\n\n SESSION_RULE"));
|
|
167
|
+
assert.ok(rendered.includes("cheatsheet\n\n PROJECT_RULE\n\nmap\n\n PROJECT_INDEX"));
|
|
168
|
+
assert.ok(rendered.includes("map\n\n HUMAN_INDEX"));
|
|
169
|
+
assert.ok(rendered.includes("@project/n2.md ·"));
|
|
170
|
+
assert.equal(rendered.includes("TITLE_3"), false);
|
|
171
|
+
assert.equal(/(?:MAP|CHEATSHEET)\.md ·/.test(rendered), false);
|
|
172
|
+
assert.ok(rendered.includes("🐑".repeat(CHEATSHEET_BOOT_MAX_CHARS)));
|
|
173
|
+
assert.equal(rendered.includes("🐑".repeat(CHEATSHEET_BOOT_MAX_CHARS + 1)), false);
|
|
174
|
+
assert.ok(rendered.includes(`[truncated at ${CHEATSHEET_BOOT_MAX_CHARS} chars; slim this page down, full body at \`@self/CHEATSHEET.md\`]`));
|
|
175
|
+
assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)));
|
|
176
|
+
assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false);
|
|
177
|
+
assert.ok(rendered.includes(`[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this page down, full body at \`@self/MAP.md\`]`));
|
|
178
|
+
assert.equal(rendered.includes("CRUMPLED_RULE"), false);
|
|
179
|
+
assert.equal(rendered.includes("@model —"), false);
|
|
180
|
+
});
|
|
160
181
|
test("the shelves name their reader and the @self shelf says when it is shared", async () => {
|
|
161
182
|
const rows = new Map([
|
|
162
183
|
["agent", [note("agent", "MAP.md", "@agents/anonymous/MAP.md", "AGENT_MAP_BODY"), note("agent", "shared.md", "@agents/anonymous/shared.md", "SHARED_BODY")]],
|
|
@@ -297,6 +297,7 @@ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer"
|
|
|
297
297
|
const captured = makeExtension(session);
|
|
298
298
|
const ctx = context(session);
|
|
299
299
|
await call(captured, "notes_write", { address: "MAP.md", content: "M".repeat(MAP_BOOT_MAX_CHARS + 10) }, ctx);
|
|
300
|
+
await call(captured, "notes_write", { address: "CHEATSHEET.md", content: "REMEMBER_THIS_RULE" }, ctx);
|
|
300
301
|
const rendered = await explicitBoot(ctx, "pcw:test:root", undefined);
|
|
301
302
|
for (const tool of ["notes_*", "history_*", "get_context_remaining", "empty_brain"]) {
|
|
302
303
|
assert.ok(rendered.includes(`\`${tool}\``), `${tool} is bound in the protocol`);
|
|
@@ -304,6 +305,8 @@ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer"
|
|
|
304
305
|
assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
|
|
305
306
|
assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false, "the over-cap suffix is not inlined");
|
|
306
307
|
assert.ok(rendered.includes("`MAP.md`"), "the full MAP remains available by address");
|
|
308
|
+
assert.ok(rendered.includes("cheatsheet\n\n REMEMBER_THIS_RULE\n\nmap"), "a real stored cheatsheet is pinned before the map");
|
|
309
|
+
assert.equal(/CHEATSHEET\.md ·/.test(rendered), false, "the stored cheatsheet takes no recent seat");
|
|
307
310
|
for (const retired of ["history_windows", "history_list", "history_read"]) {
|
|
308
311
|
assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
|
|
309
312
|
}
|
package/docs/codex.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Codex plugin (native mode)
|
|
2
|
+
|
|
3
|
+
`plugins/codex/` makes notesoup a native Codex plugin: the five notes homes and the three history tools over a bundled stdio MCP server, plus a SessionStart/SubagentStart hook that writes the notes boot into the window Codex is actually opening. It does not wrap Codex's conversation or replace its context engine. Reset and budget stay native.
|
|
4
|
+
|
|
5
|
+
Targets **Codex 0.160.1 only**, with the rollout format source-checked against the official 0.160.1 tree. No live Codex host or config-parser evidence is claimed at this stage. The rollout decoder rejects any other `cli_version`; it is not a forward-compatible reader. A `.jsonl.zst` rollout needs **Node >=22.15** (`zstdDecompressSync`); the plugin invokes `node`, which must resolve to that version.
|
|
6
|
+
|
|
7
|
+
## Install (from this checkout)
|
|
8
|
+
|
|
9
|
+
Build the bundled helper first; `plugins/codex/dist/codex/notesoup.js` is generated and is not committed.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm ci
|
|
13
|
+
npm run build
|
|
14
|
+
codex plugin marketplace add /absolute/path/to/notesoup
|
|
15
|
+
codex plugin add notesoup@notesoup
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`codex plugin add` copies the plugin into Codex's plugin cache, so the marketplace path is needed only to add it. Approve the plugin's `SessionStart`, `SubagentStart` and `PreCompact` hooks when Codex asks; an untrusted hook does not run, and notesoup will then refuse its MCP calls as `unknown_thread`. Restart Codex or resume the thread after installing.
|
|
19
|
+
|
|
20
|
+
Native mode is switched on in `~/.codex/config.toml`. This is the source-checked shape (the stage does not run Codex's config parser):
|
|
21
|
+
|
|
22
|
+
```toml
|
|
23
|
+
[features]
|
|
24
|
+
context_management = false
|
|
25
|
+
retain_client_developer_messages = false
|
|
26
|
+
|
|
27
|
+
[features.token_budget]
|
|
28
|
+
enabled = true
|
|
29
|
+
use_history_notes_extension = false
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Keep the forms separate: `token_budget` is a table here, so do not also write `token_budget = true`. These are under-development Codex flags; a different Codex release may rename them, which is one more reason this adapter pins 0.160.1. `retain_client_tool_outputs`, where a newer Codex provides it, is a separate flag from `retain_client_developer_messages`; do not assume one setting covers both.
|
|
33
|
+
|
|
34
|
+
`context_management = false` disables the experiment notesoup replaces. `[features.token_budget]` supplies the native `new_context` and `get_context_remaining` tools; notesoup does not implement either one. `use_history_notes_extension = false` leaves notes and history to notesoup.
|
|
35
|
+
|
|
36
|
+
## What the agent gets
|
|
37
|
+
|
|
38
|
+
- **A boot per native window.** The `SessionStart` hook reads the thread's native rollout, binds the thread to this Codex root session, cwd, model, transcript and current window, and returns the shared notes boot with a window marker. The boot is deduped by the host's own persisted `hooks.additional_context` record for that exact thread and window, never by a quoted marker. A compact creates a new native window and therefore a fresh boot.
|
|
39
|
+
- **Codex's `new_context` and `get_context_remaining`.** They remain Codex's tools. notesoup has no MCP reset or budget fallback, and an MCP call cannot trigger a reset.
|
|
40
|
+
- **Five notes homes** through `notes_write`, `notes_update`, `notes_read`, `notes_list` and `notes_search`. `NOTESOUP_HOME` overrides the root (default `~/.agents/notes`); a root thread's agent name is `NOTESOUP_AGENT` or `anonymous`.
|
|
41
|
+
- **Native history** through `history_windows`, `history_list` and `history_read`: the root thread's windows and a child's own ancestry. Window ids are `codex:<thread>:<native-window-uuid>`, and the boot's window tree uses those same UUIDs, so the shared `trunk:shortname` rule names the address history actually serves.
|
|
42
|
+
- **Per-turn model identity.** `@model` follows the current turn's `x-codex-turn-metadata.model`, not the model recorded at thread start. The start model only labels the boot.
|
|
43
|
+
- **Subagents and forks.** `SubagentStart` binds the child or fork to its own transcript while keeping the parent's root session. Its `@self` home is the slugged `agent_type` (for example `worker`), not the parent's.
|
|
44
|
+
|
|
45
|
+
Codex may prefix MCP tool names with a server namespace. Use the names that appear in the session's tool list; the boot says the same.
|
|
46
|
+
|
|
47
|
+
## Native-window and identity rules
|
|
48
|
+
|
|
49
|
+
Hooks are the only source of identity. The MCP server never guesses a project from its own cwd, and it reads exactly one binding per thread from `PLUGIN_DATA`.
|
|
50
|
+
|
|
51
|
+
A notes or history call refuses, without reading or writing anything, when:
|
|
52
|
+
|
|
53
|
+
- the thread has no hook binding (`unknown_thread`);
|
|
54
|
+
- the binding's root session disagrees with the call's `sessionId` (`stale_thread_binding`);
|
|
55
|
+
- the call carries no `windowId` (`missing_window`) or a different one from the binding (`stale_thread_binding`);
|
|
56
|
+
- the turn supplies no model (`missing_model`);
|
|
57
|
+
- history finds the transcript's root session or current window no longer matches the binding (`stale_native_state`).
|
|
58
|
+
|
|
59
|
+
Resume or compact once to let `SessionStart` rebind a stale thread. A root-session disagreement is never overwritten during a hook run; the message asks for a resume instead.
|
|
60
|
+
|
|
61
|
+
The boot marker records the native thread and window. The transcript decoder is strict about producer facts: unknown record/response types, malformed committed JSONL, non-increasing ordinals, copied `session_meta` ancestry and `thread_rolled_back` selection are refusals, not skipped data. An incomplete final line is ignored as an append tail rather than treated as history.
|
|
62
|
+
|
|
63
|
+
## Child limitation
|
|
64
|
+
|
|
65
|
+
Codex 0.160.1 has no supported child post-compact boot or recovery hook. notesoup therefore answers a **child** `PreCompact` with `continue: false`, before native history is cut, and tells the child to save a handoff note and finish. A root `PreCompact` is transparent. Continue a child by starting a fresh child from its handoff note; do not expect notesoup to recover a child after a native rollover.
|
|
66
|
+
|
|
67
|
+
## Limits
|
|
68
|
+
|
|
69
|
+
| Limit | What to expect |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| Codex versions | 0.160.1 only; other `cli_version` values are refused. |
|
|
72
|
+
| Node | >=22.15 for compressed rollouts. |
|
|
73
|
+
| Boot size | Local cap 128 KiB. The hook sets `additionalContextLimit: 0` so the host does not spill or silently truncate the boot; an oversized boot becomes a warning and nothing is injected. Slim the home MAPs. |
|
|
74
|
+
| Tool output | Shared 32 KiB result bound; use continuation fields or narrower filters. |
|
|
75
|
+
| History sources | Local rollout files only. No app-server history API, no remote history, no text from opaque/encrypted payloads. |
|
|
76
|
+
| Reset/budget | Codex-native only. No MCP fallback, no notesoup budget warning or close-out turn. |
|
|
77
|
+
| Child rollover | Unsupported; blocked at `PreCompact` as above. |
|
|
78
|
+
| Dream | No Codex dream backend or dream skill registration. |
|
|
79
|
+
| Notifications/commands | No custom UI notification, runtime toggle or `/fresh-window` command is installed. |
|
|
80
|
+
|
|
81
|
+
## Validation stage
|
|
82
|
+
|
|
83
|
+
This is a fixture- and SDK-validated stage, **not a verified real host loop**. The tests use producer-shaped synthetic rollouts derived from the frozen official 0.160.1 source (`d27764b8`), drive the bundled stdio MCP server through the official SDK client, and run the hook code both in-process and as the real bundled executable. They pin root and child history, forks, boot deduping by host provenance, stale identity/window refusals, native-window addresses and child `PreCompact`.
|
|
84
|
+
|
|
85
|
+
The stage has not been published, installed into a live Codex session, or exercised against a real model turn. A local build and the scripted tests only establish the adapter's behavior against those fixtures and the documented hook/MCP surfaces. Before relying on it in a real thread, install it as above and verify that the boot appears once per window and that a `notes_write` succeeds from a model turn.
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
npm run typecheck
|
|
89
|
+
npm test
|
|
90
|
+
node --test dist/test/codex-plugin.test.js
|
|
91
|
+
```
|