notesoup 0.52.6 → 0.53.0
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/claude/src/helper.js +34 -7
- package/dist/plugins/claude/src/history.d.ts +7 -2
- package/dist/plugins/claude/src/history.js +53 -22
- package/dist/plugins/claude/src/text.d.ts +5 -0
- package/dist/plugins/claude/src/text.js +12 -0
- 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 +11 -10
- package/dist/src/boot/text.d.ts +4 -5
- package/dist/src/boot/text.js +14 -28
- package/dist/src/budget/text.d.ts +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/history/history.js +12 -11
- package/dist/src/tools/history.d.ts +5 -3
- package/dist/src/tools/history.js +9 -11
- package/dist/test/claude-history.test.js +135 -3
- 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/history.integration.test.js +26 -1
- package/dist/test/model-facing-text.test.js +41 -26
- package/dist/test/notes.integration.test.js +3 -0
- package/docs/claude-code-mod.md +6 -2
- package/docs/codex.md +91 -0
- package/docs/dsh.md +1 -1
- package/docs/reset-lifecycle.md +1 -1
- package/docs/tool-results.md +2 -2
- 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 +120 -74
- 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/claude/src/helper.ts +34 -9
- package/plugins/claude/src/history.ts +54 -22
- package/plugins/claude/src/text.ts +13 -0
- package/plugins/codex/README.md +43 -0
- package/plugins/codex/dist/codex/notesoup.js +27800 -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/plugins/paseo/OVERVIEW.md +6 -2
- package/plugins/paseo/client/brain-empty-card.tsx +3 -1
- package/plugins/paseo/client/brain-empty-transformer.ts +7 -14
- package/plugins/paseo/client/notes-op-transformer.ts +10 -18
- package/plugins/paseo/client/tool-result.ts +31 -0
- package/plugins/paseo/test/brain-empty.test.ts +24 -1
- package/plugins/paseo/test/fixtures/claude-tool-calls.ts +86 -0
- package/plugins/paseo/test/notes-op.test.ts +39 -1
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +11 -9
- package/src/boot/text.ts +16 -30
- package/src/budget/text.ts +1 -1
- package/src/history/history.ts +12 -10
- package/src/tools/history.ts +14 -13
|
@@ -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) => {
|
|
@@ -93,6 +93,20 @@ test("every history operation declares a result schema its own payload satisfies
|
|
|
93
93
|
const refusal = await call(captured, "history_read", { seq: 999 }, ctx);
|
|
94
94
|
assert.equal(Check(historyRead.outputSchema, refusal.structuredContent), true, "a refusal satisfies the same result schema");
|
|
95
95
|
});
|
|
96
|
+
test("pairing uses append seq rather than the presentation order of unnumbered segments", async () => {
|
|
97
|
+
const projection = projectHistory([
|
|
98
|
+
{ windowId: "unknown-a", items: [
|
|
99
|
+
{ seq: 1, windowId: "unknown-a", role: "system", text: "notice" },
|
|
100
|
+
{ seq: 3, windowId: "unknown-a", role: "tool", toolCallId: "t", text: "output" },
|
|
101
|
+
] },
|
|
102
|
+
{ windowId: "unknown-b", items: [{ seq: 2, windowId: "unknown-b", role: "tool_call", toolCallId: "t", toolName: "bash", text: "" }] },
|
|
103
|
+
], 3, new Set([1, 2, 3]));
|
|
104
|
+
assert.deepEqual(projection.windows.map((window) => window.windowId), ["unknown-a", "unknown-b"], "pairing must not invent segment chronology");
|
|
105
|
+
assert.deepEqual(projection.windows.flatMap((window) => window.items).filter((event) => event.role === "tool").map((event) => [event.seq, event.text]), [[2, "output"]]);
|
|
106
|
+
const alias = await historyRead.execute({ seq: 3 }, projection);
|
|
107
|
+
assert.ok(!alias.ok);
|
|
108
|
+
assert.equal(alias.error.code, "not_an_event");
|
|
109
|
+
});
|
|
96
110
|
test("seq is stable across branch changes, abandoned entries stay unreadable, and a paired result seq is refused precisely", async () => {
|
|
97
111
|
const session = manager();
|
|
98
112
|
const captured = makeExtension(session);
|
|
@@ -647,7 +661,7 @@ test("history_read paginates one document with an accurate limit and a bounded b
|
|
|
647
661
|
assert.equal(past.code, "invalid_offset");
|
|
648
662
|
assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
|
|
649
663
|
});
|
|
650
|
-
test("history windows expose stable ranges and
|
|
664
|
+
test("history windows expose stable ranges and include host decoration in the complete budget", async () => {
|
|
651
665
|
const session = manager();
|
|
652
666
|
const captured = makeExtension(session);
|
|
653
667
|
const ctx = context(session);
|
|
@@ -656,6 +670,17 @@ test("history windows expose stable ranges and session identity", async () => {
|
|
|
656
670
|
assert.equal(windows.session_id, session.getSessionId());
|
|
657
671
|
assert.equal(windows.windows.length, 1);
|
|
658
672
|
assert.deepEqual(windows.windows[0], { window_id: windows.windows[0].window_id, created_at: null, first_seq: 1, last_seq: 1 });
|
|
673
|
+
const projection = projectHistory([0, 1, 2].map((index) => ({ windowId: `w${index}-${"x".repeat(200)}`, items: [] })), 0, new Set());
|
|
674
|
+
const notice = `${"n".repeat(TOOL_OUTPUT_MAX_BYTES - 400)}\n`;
|
|
675
|
+
const wrapText = (text) => notice + text;
|
|
676
|
+
const bounded = await historyWindows.execute({}, projection, "session-x", wrapText);
|
|
677
|
+
assert.ok(bounded.ok);
|
|
678
|
+
assert.equal(bounded.data.windows.length, 1);
|
|
679
|
+
assert.equal(bounded.data.more, 2);
|
|
680
|
+
const text = wrapText(historyWindows.render(bounded));
|
|
681
|
+
assert.ok(Buffer.byteLength(text, "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
682
|
+
assert.ok(text.startsWith(notice), "decoration is measured, never clipped at delivery");
|
|
683
|
+
assert.match(text, /2 more windows not shown/);
|
|
659
684
|
});
|
|
660
685
|
test("historyDocument is one deterministic projection of the facts, with no UI header or continuation suffix", async () => {
|
|
661
686
|
const windowId = "w1";
|
|
@@ -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, 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,34 @@ 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", [note("agent", "CHEATSHEET.md", "@self/CHEATSHEET.md", "🐑".repeat(MAP_BOOT_MAX_CHARS + 1))]],
|
|
157
|
+
["model", [{
|
|
158
|
+
...note("model", "CHEATSHEET.md", "@model/CHEATSHEET.md", "CRUMPLED_RULE"),
|
|
159
|
+
meta: { ...note("model", "", "", "").meta, crumpledAt: "2026-10-01T00:00:00+08:00" },
|
|
160
|
+
}]],
|
|
161
|
+
]);
|
|
162
|
+
const rendered = (await boot("root", rows)).split("YOUR NOTES")[1];
|
|
163
|
+
assert.ok(rendered.includes("cheatsheet\n\n SESSION_RULE"));
|
|
164
|
+
assert.ok(rendered.includes("cheatsheet\n\n PROJECT_RULE\n\nmap\n\n PROJECT_INDEX"));
|
|
165
|
+
assert.ok(rendered.includes("map\n\n HUMAN_INDEX"));
|
|
166
|
+
assert.ok(rendered.includes("@project/n2.md ·"));
|
|
167
|
+
assert.equal(rendered.includes("TITLE_3"), false);
|
|
168
|
+
assert.equal(/(?:MAP|CHEATSHEET)\.md ·/.test(rendered), false);
|
|
169
|
+
assert.ok(rendered.includes("🐑".repeat(MAP_BOOT_MAX_CHARS)));
|
|
170
|
+
assert.equal(rendered.includes("🐑".repeat(MAP_BOOT_MAX_CHARS + 1)), false);
|
|
171
|
+
assert.ok(rendered.includes("full body at `@self/CHEATSHEET.md`"));
|
|
172
|
+
assert.equal(rendered.includes("CRUMPLED_RULE"), false);
|
|
173
|
+
assert.equal(rendered.includes("@model —"), false);
|
|
174
|
+
});
|
|
160
175
|
test("the shelves name their reader and the @self shelf says when it is shared", async () => {
|
|
161
176
|
const rows = new Map([
|
|
162
177
|
["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/claude-code-mod.md
CHANGED
|
@@ -24,9 +24,13 @@ The notes tools also serve subagent calls, using the same session identity and s
|
|
|
24
24
|
|
|
25
25
|
The active head comes from the main loop's successful `session.append` result UUID, including attachments and notices. On startup/resume, before such an append, the public API supplies no authoritative selected leaf: history explicitly refuses instead of assuming the last file row or `last-prompt.leafUuid` is current. The append result means the engine kept a row, but its disk write may lag; a head missing on disk is a retryable refusal, not permission to switch branches. Session end clears the binding; a new classic start rebinds it.
|
|
26
26
|
|
|
27
|
-
Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. List pages skip empty user/assistant envelopes even with explicit roles, so tool-only and thinking-only rows do not crowd out dialogue; direct reads preserve those addresses and explicitly say when no visible text was recorded. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed. Record types other than user, assistant, system and attachment are ignored, including future metadata, without allocating addresses or exposing payloads. If the selected branch requires a skipped record as an ancestor,
|
|
27
|
+
Seqs are allocated over first-occurrence persisted append order, before active-branch filtering: one address per logical message/attachment/notice and additional addresses for each tool use/result. Repeated UUID records do not allocate again. List pages skip empty user/assistant envelopes even with explicit roles, so tool-only and thinking-only rows do not crowd out dialogue; direct reads preserve those addresses and explicitly say when no visible text was recorded. Results pair by `tool_use_id`; pending calls remain unfinished, and a paired result's seq redirects to its call. Only text blocks and recorded attachment renderings become visible text; thinking and raw, unrendered attachment payloads are never exposed. Record types other than user, assistant, system and attachment are ignored, including future metadata, without allocating addresses or exposing payloads. If the selected branch requires a skipped record as an ancestor, that UUID is an ancestry gap, not a visible metadata event. Invalid supported message/block schemas, conflicting duplicates, session/sidechain mismatches, cycles and malformed committed JSONL lines still refuse explicitly. An incomplete final unterminated write is tolerated. Valid forward parent references are resolved after reading the snapshot, without reallocating addresses.
|
|
28
28
|
|
|
29
|
-
The selected tree follows the latest native `parentUuid` links. Compact boundaries also join their `logicalParentUuid` and recorded preserved segments through original ancestry, retaining old events instead of presenting only retained inference context. Auxiliary preservation UUIDs that were never persisted are skipped. Windows use `claude:<sessionId>:<ordinal>`, matching the current boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. A fork preserves the copied boot's ordinal but uses its own session id for public window ids. Copied prompt-context boot blocks are rebuilt with a fresh notes snapshot and the current session identity; historical boot messages in the transcript remain unchanged. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window.
|
|
29
|
+
The selected tree follows the latest native `parentUuid` links. Compact boundaries also join their `logicalParentUuid` and recorded preserved segments through original ancestry, retaining old events instead of presenting only retained inference context. Auxiliary preservation UUIDs that were never persisted are skipped. Windows use `claude:<sessionId>:<ordinal>`, matching the current boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. A fork preserves the copied boot's ordinal but uses its own session id for public window ids. Copied prompt-context boot blocks are rebuilt with a fresh notes snapshot and the current session identity; historical boot messages in the transcript remain unchanged. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window.
|
|
30
|
+
|
|
31
|
+
A missing required ancestor stops only that traversal edge. Confirmed selected suffixes and explicitly linked compaction history remain queryable; append order never joins a disconnected prefix or selects a sibling. All three history tools prepend a bounded Claude-specific incomplete-history notice, including missing UUID evidence, even for empty selections or query errors. The same pure text wrapper is supplied to shared selection/read budget checks and final delivery, so the complete text including the notice fits 32 KiB without clipping event text or continuation footers afterward. The notice is outside event documents, search matches and read offsets; the shared query schemas are unchanged. Previously allocated seqs remain unchanged if the missing record later appears: its first occurrence takes the next append address, and a fresh projection removes the gap notice when ancestry is complete.
|
|
32
|
+
|
|
33
|
+
Without a path back to a root or retained boot, window ordinals are unknown. Those events use `claude:<sessionId>:unknown:<missingUuid>` as an explicitly unnumbered segment (possibly spanning native compactions), not an invented ordinal. A subsequent complete retained boot re-anchors its own and later window ordinals without filling the history gap. Incomplete projections list only evidenced windows/segments, not empty placeholders for unseen ordinals. Confirmed numbered windows are sorted by ordinal (including when forward references put newer-window rows on disk first). Unknown segments are listed separately after the numbered windows; that placement does not assert chronological order for them. Shared tool pairing scans stable append seq order before regrouping events for display, so it does not depend on window/segment presentation order. `@previous` requires the exact preceding numbered window to be evidenced when history is incomplete, rather than choosing an adjacent unknown segment. The helper's reset-facing `history_state` returns the head's independently resolved ordinal, never `windows.length - 1`; if it is unknown, it explicitly refuses rather than supplying a guessed number. Existing reset-hook refusal handling leaves its prior state intact.
|
|
30
34
|
|
|
31
35
|
## Validation
|
|
32
36
|
|