notesoup 0.45.2 → 0.46.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 +2 -2
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +5 -5
- package/dist/src/budget/text.d.ts +4 -4
- package/dist/src/budget/text.js +3 -3
- package/dist/src/dsh/index.js +1 -1
- package/dist/src/dsh/tools.js +2 -2
- package/dist/src/pi/reset/artifacts.d.ts +5 -3
- package/dist/src/pi/reset/artifacts.js +7 -9
- package/dist/src/pi/reset/lifecycle.js +1 -1
- package/dist/src/pi/runtime.js +17 -13
- package/dist/test/agent-loop.test.js +37 -37
- package/dist/test/boot.integration.test.js +11 -11
- package/dist/test/claude-mod.test.js +8 -8
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh-cli.test.js +1 -1
- package/dist/test/dsh.test.js +7 -7
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/notes.integration.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +19 -14
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +3 -3
- package/docs/dsh.md +3 -3
- package/docs/reset-lifecycle.md +7 -7
- package/docs/tool-results.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +6 -6
- package/mods/notesoup/hooks/register.ts +10 -9
- package/mods/notesoup/skills/memory/SKILL.md +1 -1
- package/package.json +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/text.ts +5 -5
- package/src/budget/text.ts +3 -3
- package/src/dsh/index.ts +1 -1
- package/src/dsh/tools.ts +2 -2
- package/src/pi/reset/artifacts.ts +8 -8
- package/src/pi/reset/lifecycle.ts +1 -1
- package/src/pi/runtime.ts +16 -13
|
@@ -19,7 +19,7 @@ test("custom reset marker removes old provider context while history remains sea
|
|
|
19
19
|
const oldUserId = appendText(sessionManager, "user", "OLD-UNIQUE-TRANSCRIPT needle");
|
|
20
20
|
appendText(sessionManager, "assistant", "I will use a tool");
|
|
21
21
|
const toolResultId = appendText(sessionManager, "toolResult", "tool result safely recorded");
|
|
22
|
-
await call(captured, "
|
|
22
|
+
await call(captured, "neuralyze", {}, ctx);
|
|
23
23
|
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
24
24
|
assert.equal(boundary.continue, true);
|
|
25
25
|
const branch = sessionManager.getBranch();
|
|
@@ -80,7 +80,7 @@ test("the root boot and reset boot carry durable window identity", async () => {
|
|
|
80
80
|
assert.match(rootText, /decisions\.md · (?:just now|\d+s ago)/, "boot note metadata carries a relative update time");
|
|
81
81
|
assert.ok(rootText.includes(CONTEXT_WINDOW_PROTOCOL_OPEN_TAG));
|
|
82
82
|
// Reset: the marker and boot are committed together at the turn boundary.
|
|
83
|
-
await call(captured, "
|
|
83
|
+
await call(captured, "neuralyze", {}, ctx);
|
|
84
84
|
assert.equal(noticesOf(ctx).length, 0, "requesting a reset does not announce success");
|
|
85
85
|
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
86
86
|
assert.equal(boundary.continue, true);
|
|
@@ -201,22 +201,22 @@ test("off preserves an existing marker window and still cancels native compactio
|
|
|
201
201
|
const windows = resultData(await call(captured, "history_windows", {}, ctx));
|
|
202
202
|
assert.equal(windows.windows.at(-1)?.window_id, windowId);
|
|
203
203
|
});
|
|
204
|
-
test("
|
|
204
|
+
test("neuralyze uses one turn boundary and never calls ctx.compact", async () => {
|
|
205
205
|
const sessionManager = manager();
|
|
206
206
|
const captured = makeExtension(sessionManager);
|
|
207
207
|
const ctx = context(sessionManager, () => assert.fail("ctx.compact must not be used"));
|
|
208
208
|
appendText(sessionManager, "user", "enough history for the boundary test");
|
|
209
|
-
const result = resultJson(await call(captured, "
|
|
209
|
+
const result = resultJson(await call(captured, "neuralyze", {}, ctx));
|
|
210
210
|
assert.ok(result.status);
|
|
211
211
|
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
212
212
|
assert.equal(boundary.continue, true);
|
|
213
213
|
assert.equal(sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).length, 1);
|
|
214
214
|
assert.equal(sessionManager.getBranch().filter((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE && entry.details && typeof entry.details === "object" && "windowId" in entry.details).length, 1);
|
|
215
215
|
});
|
|
216
|
-
test("/
|
|
216
|
+
test("/neuralyze waits out non-agent busy work before starting its single-turn request", async () => {
|
|
217
217
|
const sessionManager = manager();
|
|
218
218
|
const captured = makeExtension(sessionManager);
|
|
219
|
-
const cmd = captured.commands.get("
|
|
219
|
+
const cmd = captured.commands.get("neuralyze");
|
|
220
220
|
assert.ok(cmd);
|
|
221
221
|
let waits = 0;
|
|
222
222
|
const notices = [];
|
|
@@ -231,7 +231,7 @@ test("/clear-memory waits out non-agent busy work before starting its single-tur
|
|
|
231
231
|
assert.equal(captured.sent[0]?.options?.triggerTurn, true);
|
|
232
232
|
assert.equal(notices.filter((message) => message.includes("notes first, then it stops")).length, 1);
|
|
233
233
|
});
|
|
234
|
-
test("notesoup command toggles future work, /
|
|
234
|
+
test("notesoup command toggles future work, /neuralyze schedules a turn-end reset, and /compact remains disabled", async () => {
|
|
235
235
|
const sessionManager = manager();
|
|
236
236
|
appendText(sessionManager, "user", "hello");
|
|
237
237
|
const captured = makeExtension(sessionManager);
|
|
@@ -246,11 +246,11 @@ test("notesoup command toggles future work, /clear-memory schedules a turn-end r
|
|
|
246
246
|
assert.equal(sentOf(captured, GUIDANCE_TYPE).length, 0, "no guidance persisted while off");
|
|
247
247
|
await runHandlers(captured, "session_start", { reason: "startup" }, low);
|
|
248
248
|
assert.equal(captured.sent.length, 1, "no new boot block is persisted while off");
|
|
249
|
-
const offResult = resultJson(await call(captured, "
|
|
250
|
-
assert.match(offResult.error ?? "", /off/, "
|
|
249
|
+
const offResult = resultJson(await call(captured, "neuralyze", {}, low));
|
|
250
|
+
assert.match(offResult.error ?? "", /off/, "neuralyze refuses while off");
|
|
251
251
|
notices = await runCommand(captured, "notesoup", "on", low);
|
|
252
252
|
assert.match(notices[0]?.message ?? "", /on/);
|
|
253
|
-
notices = await runCommand(captured, "
|
|
253
|
+
notices = await runCommand(captured, "neuralyze", "", low);
|
|
254
254
|
assert.equal(notices.length, 1, "the command acknowledges the reset request");
|
|
255
255
|
assert.match(notices[0]?.message ?? "", /notes first, then it stops/);
|
|
256
256
|
assert.equal(captured.sent.length, 2, "the command persists one hidden warning after the startup boot");
|
|
@@ -272,7 +272,7 @@ test("committed reset confirmation survives later work while repair refuses that
|
|
|
272
272
|
const sessionManager = manager();
|
|
273
273
|
const captured = makeExtension(sessionManager);
|
|
274
274
|
const ctx = context(sessionManager);
|
|
275
|
-
await call(captured, "
|
|
275
|
+
await call(captured, "neuralyze", {}, ctx);
|
|
276
276
|
await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
277
277
|
const marker = sessionManager.getBranch().find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
278
278
|
assert.ok(marker && marker.type === "custom");
|
|
@@ -193,13 +193,13 @@ test("Claude helper resolves limits across the boundary and never throws on nons
|
|
|
193
193
|
assert.ok(nonsense.result.warn > 0 && nonsense.result.warn < 100);
|
|
194
194
|
});
|
|
195
195
|
test("Claude's wipe sentence replaces only that sentence in the shared protocol block", () => {
|
|
196
|
-
const piTools = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "
|
|
196
|
+
const piTools = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "neuralyze" };
|
|
197
197
|
const pi = renderProtocolBlock(piTools);
|
|
198
198
|
assert.ok(pi.includes(PROTOCOL_WIPE_SENTENCE), "Pi keeps the default sentence, byte for byte");
|
|
199
199
|
const claude = renderProtocolBlock({ ...piTools, wipeSentence: CLAUDE_WIPE_SENTENCE });
|
|
200
200
|
assert.equal(claude, pi.replace(PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE), "only that sentence changes");
|
|
201
201
|
assert.equal(claude.includes("erase yourself with dignity"), false);
|
|
202
|
-
assert.ok(claude.includes("end your turn and ask the human to run `/
|
|
202
|
+
assert.ok(claude.includes("end your turn and ask the human to run `/fresh-window`."));
|
|
203
203
|
});
|
|
204
204
|
test("Claude Mod helper runs from a standalone copied plugin directory", () => {
|
|
205
205
|
const fixture = mkdtempSync(join(tmpdir(), "claude-mod-install-"));
|
|
@@ -419,7 +419,7 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
|
|
|
419
419
|
await invoke("turn.complete");
|
|
420
420
|
assert.equal(attempts, 0, "headless sessions skip the unsupported capability from startup");
|
|
421
421
|
assert.deepEqual(notifications, ["🥣 Clear-memory is off in headless (-p / SDK) sessions"]);
|
|
422
|
-
const manual = await invoke("command.run", { command: "
|
|
422
|
+
const manual = await invoke("command.run", { command: "neuralyze" });
|
|
423
423
|
assert.match(manual.text, /off in headless/);
|
|
424
424
|
assert.equal(notifications.length, 1);
|
|
425
425
|
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
@@ -479,7 +479,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
479
479
|
};
|
|
480
480
|
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
481
481
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
482
|
-
const command = await invoke("command.run", { command: "
|
|
482
|
+
const command = await invoke("command.run", { command: "neuralyze" });
|
|
483
483
|
assert.match(command.text, /Clearing memory/);
|
|
484
484
|
await Promise.resolve();
|
|
485
485
|
assert.equal(compactions, 0, "command.run must not call compact under its held turn");
|
|
@@ -497,7 +497,7 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
497
497
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
498
498
|
assert.deepEqual(await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] })), { blocks: [] }, "reload does not duplicate the already-retained boot");
|
|
499
499
|
await invoke("turn.start");
|
|
500
|
-
await invoke("command.run", { command: "
|
|
500
|
+
await invoke("command.run", { command: "neuralyze" });
|
|
501
501
|
await invoke("turn.complete");
|
|
502
502
|
assert.equal(prompts.length, 1, "a busy manual request reuses the current turn instead of submitting another");
|
|
503
503
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:2/);
|
|
@@ -568,7 +568,7 @@ test("Claude Mod stops the automatic reset and the manual command under DISABLE_
|
|
|
568
568
|
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
569
569
|
assert.equal(notifications.length, 1, "one startup line");
|
|
570
570
|
assert.match(notifications[0], /DISABLE_COMPACT/);
|
|
571
|
-
const manual = await invoke("command.run", { command: "
|
|
571
|
+
const manual = await invoke("command.run", { command: "neuralyze" });
|
|
572
572
|
assert.match(manual.text, /DISABLE_COMPACT/);
|
|
573
573
|
assert.equal(timers.length, 0, "no close-out turn is queued");
|
|
574
574
|
await invoke("turn.start");
|
|
@@ -676,7 +676,7 @@ async function retainedFixture(t) {
|
|
|
676
676
|
const { host } = fakeEngine(home);
|
|
677
677
|
const boot = await dispatch({ op: "boot", identity: { ...identity, home, cwd: home, sessionId: "hook-session" }, window: 2, tools: {
|
|
678
678
|
notes: "mcp__notesoup__notes_*", notesList: "mcp__notesoup__notes_list",
|
|
679
|
-
history: "unavailable", remaining: "unavailable", wipe: "/
|
|
679
|
+
history: "unavailable", remaining: "unavailable", wipe: "/fresh-window",
|
|
680
680
|
} });
|
|
681
681
|
host.session.messages = async () => [{ role: "user", text: `# notesoup:boot\n${boot}` }];
|
|
682
682
|
const handlers = new Map();
|
|
@@ -694,7 +694,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
694
694
|
host.session.usage = async () => ({ context: { tokens: 142_424, window: 200_000 } });
|
|
695
695
|
assert.equal((await context()).blocks[0]?.name, "notesoup:warning", "the old window has already warned");
|
|
696
696
|
await invoke("turn.start");
|
|
697
|
-
await invoke("command.run", { command: "
|
|
697
|
+
await invoke("command.run", { command: "neuralyze" });
|
|
698
698
|
const ended = { sentinel: action };
|
|
699
699
|
assert.equal(await invoke("session.end", { reason: action === "clear" ? "clear" : "resume", sessionId: "hook-session" }, ended), ended);
|
|
700
700
|
host.session.id = async () => `after-${action}`;
|
|
@@ -155,8 +155,8 @@ test("configured extension source and moved dream CLI are executable current ent
|
|
|
155
155
|
registerTool(tool) { tools.push(tool); },
|
|
156
156
|
registerCommand(name) { commands.push(name); },
|
|
157
157
|
});
|
|
158
|
-
assert.deepEqual(tools.map((tool) => tool.name).sort(), ["
|
|
159
|
-
assert.deepEqual(commands.sort(), ["
|
|
158
|
+
assert.deepEqual(tools.map((tool) => tool.name).sort(), ["get_context_remaining", "history_list", "history_read", "history_windows", "neuralyze", "notes_list", "notes_read", "notes_search", "notes_update", "notes_write"]);
|
|
159
|
+
assert.deepEqual(commands.sort(), ["fresh-window", "neuralyze", "notesoup"]);
|
|
160
160
|
const help = execFileSync(process.execPath, [resolve(root, manifest.bin.dream), "--help"], { cwd: root, encoding: "utf8" });
|
|
161
161
|
assert.ok(help.startsWith("dream doctor [--notes-home <dir>]"));
|
|
162
162
|
assert.ok(help.includes("Default playbook: <installed package root>/playbook.md"));
|
|
@@ -28,7 +28,7 @@ test("dsh profile loads our rows and a second process restores the on-disk windo
|
|
|
28
28
|
await writeFile(join(profile, "cordis.patch.yml"), patch + "\n- id: session-title-llm\n disabled: true\n");
|
|
29
29
|
const env = { ...process.env, DSH_HOME: home, DEEPSEEK_API_KEY: "mock-key", DEEPSEEK_BASE_URL: mock.url, DSH_TOOLS_MODE: "native" };
|
|
30
30
|
const cli = resolve(repository, "node_modules/@deepseek-ai/dsh/lib/bin.js");
|
|
31
|
-
mock.script.push({ tool: "
|
|
31
|
+
mock.script.push({ tool: "neuralyze", input: {} }, { text: "after reset" });
|
|
32
32
|
const first = await exec(process.execPath, [cli, "--profile", "notesoup-test", "old conversation"], { cwd: directory, env, timeout: 20000 });
|
|
33
33
|
assert.equal(mock.requests.length, 2, first.stderr);
|
|
34
34
|
assert.equal(mock.requests[1].messages.length, 1);
|
package/dist/test/dsh.test.js
CHANGED
|
@@ -27,7 +27,7 @@ function code(expected) { return (error) => error?.code === expected; }
|
|
|
27
27
|
test("dsh boot freezes across note writes, rotates before the next wire request, and keeps raw history", async (t) => {
|
|
28
28
|
const { ctx, engine, create, mock } = await dshFixture(t);
|
|
29
29
|
const agent = await create();
|
|
30
|
-
mock.script.push({ tool: "notes_write", input: { address: "handoff", content: "recover me {{literal}}" } }, { tool: "
|
|
30
|
+
mock.script.push({ tool: "notes_write", input: { address: "handoff", content: "recover me {{literal}}" } }, { tool: "neuralyze", input: {} }, { text: "resumed" });
|
|
31
31
|
await run(agent, "old secret conversation");
|
|
32
32
|
assert.equal(mock.requests.length, 3);
|
|
33
33
|
assert.equal(system(mock.requests[0]), system(mock.requests[1]));
|
|
@@ -59,7 +59,7 @@ test("dsh boot freezes across note writes, rotates before the next wire request,
|
|
|
59
59
|
test("dsh reload adopts persisted bytes before first assembly; missing records reconstruct from checkpoints and root system", async (t) => {
|
|
60
60
|
const { engine, create, mock } = await dshFixture(t);
|
|
61
61
|
const agent = await create();
|
|
62
|
-
mock.script.push({ tool: "
|
|
62
|
+
mock.script.push({ tool: "neuralyze", input: {} }, { text: "after" });
|
|
63
63
|
await run(agent, "before");
|
|
64
64
|
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
65
65
|
await createNotesStore(notesIdentity(agent, engine.config)).write("@self/later", "not in the frozen boot");
|
|
@@ -195,7 +195,7 @@ test("dsh budget follows configured host reserve, close-out tool runs across ste
|
|
|
195
195
|
assert.equal(budget?.warning, 76384);
|
|
196
196
|
assert.equal(budget?.reminder, 84576);
|
|
197
197
|
assert.equal(budget?.countdown, Math.max(0, 123616 - budget.used));
|
|
198
|
-
mock.script.push({ tool: "notes_write", input: { address: "handoff", content: "checkpoint", }, inputTokens: 125000 }, { tool: "
|
|
198
|
+
mock.script.push({ tool: "notes_write", input: { address: "handoff", content: "checkpoint", }, inputTokens: 125000 }, { tool: "neuralyze", input: {} }, { text: "fresh" });
|
|
199
199
|
await run(agent, "continue");
|
|
200
200
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 1);
|
|
201
201
|
assert.equal(agent.session.snapshotEvents().filter((event) => event.type === "user/message" && event.data.source.kind === "notesoup-budget" && event.data.source.phase === "warning").length, 1);
|
|
@@ -207,7 +207,7 @@ test("dsh budget follows configured host reserve, close-out tool runs across ste
|
|
|
207
207
|
test("dsh explicit resets survive auto:false; shared tool reads and expected errors keep their codes", async (t) => {
|
|
208
208
|
const { ctx, engine, create, mock } = await dshFixture(t, { auto: false });
|
|
209
209
|
const agent = await create();
|
|
210
|
-
mock.script.push({ tool: "
|
|
210
|
+
mock.script.push({ tool: "neuralyze", input: {} }, { text: "fresh" });
|
|
211
211
|
await run(agent, "keep raw history");
|
|
212
212
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 1);
|
|
213
213
|
assert.equal(engine.automaticListenerPresent, true);
|
|
@@ -263,11 +263,11 @@ test("dsh explicit resets survive auto:false; shared tool reads and expected err
|
|
|
263
263
|
if (refused.isError)
|
|
264
264
|
assert.equal(refused.error.info?.code, "invalid_scope");
|
|
265
265
|
const snapshot = engine.windows.get(agent.session).snapshot;
|
|
266
|
-
const sharedBoot = renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId: `dsh:${agent.session.id}:0`, currentWindowId: snapshot.windowId, previousWindowId: `dsh:${agent.session.id}:0`, notes: await loadNotesSnapshot(identity, snapshot.openedAt), tools: { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "
|
|
266
|
+
const sharedBoot = renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId: `dsh:${agent.session.id}:0`, currentWindowId: snapshot.windowId, previousWindowId: `dsh:${agent.session.id}:0`, notes: await loadNotesSnapshot(identity, snapshot.openedAt), tools: { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "neuralyze" } });
|
|
267
267
|
// The shared protocol, including the MAP cheatsheet, is used verbatim inside host framing.
|
|
268
268
|
assert.ok(snapshot.boot.includes(sharedBoot.split("YOUR NOTES")[0]));
|
|
269
|
-
const blocked = ctx.on("tools/post-execute", async (exec, _result, next) => exec.name === "
|
|
270
|
-
mock.script.push({ tool: "
|
|
269
|
+
const blocked = ctx.on("tools/post-execute", async (exec, _result, next) => exec.name === "neuralyze" ? { kind: "block", feedback: [{ type: "text", text: "blocked" }] } : next());
|
|
270
|
+
mock.script.push({ tool: "neuralyze", input: {} }, { text: "request refused" });
|
|
271
271
|
await run(agent, "refused clear");
|
|
272
272
|
assert.equal(engine.windows.get(agent.session).snapshot.window, 1);
|
|
273
273
|
blocked();
|
|
@@ -50,7 +50,7 @@ test("shared boot uses only explicit identity, loader, captured time and logical
|
|
|
50
50
|
assert.equal(renderBootBlock(block), rendered);
|
|
51
51
|
assert.ok(rendered.includes("😀\n checkpoint.md · 1m ago"), "a feed entry is the note's own first line over its locator");
|
|
52
52
|
assert.ok(rendered.includes("Try `memo_list` again"));
|
|
53
|
-
assert.equal(/notes_\*|notes_list|history_\*|history_list|history_read|get_context_remaining|
|
|
53
|
+
assert.equal(/notes_\*|notes_list|history_\*|history_list|history_read|get_context_remaining|neuralyze/.test(rendered), false);
|
|
54
54
|
});
|
|
55
55
|
test("the shared result module bounds both surfaces and resumes by offset", () => {
|
|
56
56
|
const text = `${"a".repeat(120)}😀${"b".repeat(30)}`;
|
|
@@ -278,7 +278,7 @@ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer"
|
|
|
278
278
|
const ctx = context(session);
|
|
279
279
|
await call(captured, "notes_write", { address: "MAP.md", content: "M".repeat(MAP_BOOT_MAX_CHARS + 10) }, ctx);
|
|
280
280
|
const rendered = await explicitBoot(ctx, "pcw:test:root", undefined);
|
|
281
|
-
for (const tool of ["notes_*", "history_*", "get_context_remaining", "
|
|
281
|
+
for (const tool of ["notes_*", "history_*", "get_context_remaining", "neuralyze"]) {
|
|
282
282
|
assert.ok(rendered.includes(`\`${tool}\``), `${tool} is bound in the protocol`);
|
|
283
283
|
}
|
|
284
284
|
assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
|
|
@@ -9,7 +9,7 @@ import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESE
|
|
|
9
9
|
import { MANUAL_WIPE_TYPE } from "../src/pi/entries.js";
|
|
10
10
|
import { toolContext } from "./helpers/extension.js";
|
|
11
11
|
import { WARNING_CONTENT } from "../src/budget/text.js";
|
|
12
|
-
import { MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../src/pi/reset/artifacts.js";
|
|
12
|
+
import { LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../src/pi/reset/artifacts.js";
|
|
13
13
|
import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../src/pi/reset/lifecycle.js";
|
|
14
14
|
const previousNotesHome = process.env.PI_NOTES_HOME;
|
|
15
15
|
const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
|
|
@@ -154,8 +154,8 @@ function fakeBoundaryEvent(entries = [], message) {
|
|
|
154
154
|
test("public reset boundary drafts one marker, one boot, and one continuation after a tool batch", async () => {
|
|
155
155
|
const h = harness();
|
|
156
156
|
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
157
|
-
const first = await h.callTool("
|
|
158
|
-
const second = await h.callTool("
|
|
157
|
+
const first = await h.callTool("neuralyze");
|
|
158
|
+
const second = await h.callTool("neuralyze");
|
|
159
159
|
assert.ok(first.content.length > 0 && second.content.length > 0, "both tool calls return normally");
|
|
160
160
|
const toolBatch = [{ type: "custom_message", customType: "foreign/tool-batch", content: "tool finished", display: false }];
|
|
161
161
|
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent(toolBatch)));
|
|
@@ -179,9 +179,9 @@ test("public reset boundary drafts one marker, one boot, and one continuation af
|
|
|
179
179
|
assert.deepEqual(branch.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).map((entry) => entry.type === "custom" ? entry.data : undefined), [{ windowId }]);
|
|
180
180
|
assert.equal(branch.filter((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE).length, 1);
|
|
181
181
|
});
|
|
182
|
-
test("manual /
|
|
182
|
+
test("manual /neuralyze spans tool turns and commits the stop at settlement", async () => {
|
|
183
183
|
const h = harness();
|
|
184
|
-
await h.runCommand("
|
|
184
|
+
await h.runCommand("neuralyze");
|
|
185
185
|
assert.ok(h.sent.some((message) => message.customType === MANUAL_WIPE_TYPE && message.triggerTurn === true), "the idle close-out warning starts a turn");
|
|
186
186
|
const toolCallMessage = {
|
|
187
187
|
role: "assistant",
|
|
@@ -204,7 +204,7 @@ test("manual /clear-memory spans tool turns and commits the stop at settlement",
|
|
|
204
204
|
});
|
|
205
205
|
test("off stops future automatic/manual reset requests while an existing marker remains authoritative", async () => {
|
|
206
206
|
const h = harness();
|
|
207
|
-
await h.callTool("
|
|
207
|
+
await h.callTool("neuralyze");
|
|
208
208
|
const first = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
209
209
|
assert.ok(first.entries.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE));
|
|
210
210
|
appendDrafts(h.sessionManager, first.entries);
|
|
@@ -221,8 +221,8 @@ test("off stops future automatic/manual reset requests while an existing marker
|
|
|
221
221
|
const afterOff = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
222
222
|
assert.equal(afterOff.entries.length, 0, "off does not create another reset");
|
|
223
223
|
await h.runCommand("notesoup", "on");
|
|
224
|
-
await h.runCommand("
|
|
225
|
-
assert.equal(h.sent.length, 1, "/
|
|
224
|
+
await h.runCommand("neuralyze");
|
|
225
|
+
assert.equal(h.sent.length, 1, "/neuralyze sends one hidden close-out warning and starts a normal turn");
|
|
226
226
|
assert.equal(h.sent[0]?.triggerTurn, true);
|
|
227
227
|
assert.equal(h.sent[0]?.customType, MANUAL_WIPE_TYPE);
|
|
228
228
|
const warning = h.sessionManager.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE);
|
|
@@ -604,25 +604,30 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
604
604
|
CONTINUATION_TYPE,
|
|
605
605
|
], "the persisted reset shape remains marker -> boot -> continuation");
|
|
606
606
|
});
|
|
607
|
-
test("a
|
|
607
|
+
test("a neuralyze last word lands as a visible entry after the continuation", async () => {
|
|
608
608
|
const h = harness();
|
|
609
609
|
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
610
|
-
await h.callTool("
|
|
610
|
+
await h.callTool("neuralyze", { last_word: "feed the ants" });
|
|
611
611
|
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
612
612
|
const lastWords = boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE);
|
|
613
613
|
assert.equal(lastWords.length, 1, "the boundary persists exactly one parting line");
|
|
614
|
-
assert.deepEqual(lastWords[0], { type: "custom_message", customType: RESET_LAST_WORD_TYPE, content:
|
|
614
|
+
assert.deepEqual(lastWords[0], { type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}feed the ants`, display: true });
|
|
615
615
|
const continuationIndex = boundary.entries.findIndex((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
616
616
|
assert.ok(boundary.entries.indexOf(lastWords[0]) > continuationIndex, "the parting line follows the continuation");
|
|
617
617
|
});
|
|
618
|
-
test("
|
|
618
|
+
test("neuralyze trims the last word, refuses an oversized one, and a blank persists no entry", async () => {
|
|
619
619
|
assert.equal(sanitizeLastWord(" hi "), "hi");
|
|
620
620
|
assert.equal(sanitizeLastWord(" "), undefined);
|
|
621
621
|
assert.equal(sanitizeLastWord(undefined), undefined);
|
|
622
|
-
|
|
622
|
+
const over = harness();
|
|
623
|
+
over.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
624
|
+
const refused = await over.callTool("neuralyze", { last_word: "x".repeat(MAX_LAST_WORD_CHARS + 1) });
|
|
625
|
+
assert.match(JSON.stringify(refused), /error/, "an oversized note is refused, not truncated");
|
|
626
|
+
const untouched = resultEntries(await over.emit("turn_end", fakeBoundaryEvent()));
|
|
627
|
+
assert.equal(untouched.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a refused call requests no reset");
|
|
623
628
|
const h = harness();
|
|
624
629
|
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
625
|
-
await h.callTool("
|
|
630
|
+
await h.callTool("neuralyze", { last_word: " " });
|
|
626
631
|
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
627
632
|
assert.equal(boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a blank last word persists no entry");
|
|
628
633
|
});
|
package/docs/architecture.md
CHANGED
|
@@ -39,11 +39,11 @@ For the native dsh reset transaction, prompt ordering, capability checks and lim
|
|
|
39
39
|
|
|
40
40
|
A new reset is a native empty-summary compaction checkpoint configured to retain none, followed by one `notesoup/reset-marker` custom entry with `{ windowId: string }`, a hidden `notesoup/boot` whose `details.windowId` matches, and a hidden continuation. The checkpoint is the canonical-history cut; the marker is the durable logical window identity. Raw session entries remain available to history tools. Legacy marker-only branches keep a narrow projection fallback. `pi/window.ts` owns marker/checkpoint validation, active-branch scan, root/current IDs, and per-window message lookup; `pi/history.ts` consumes those native identity primitives while decoding entries; shared `history/history.ts` only receives decoded, addressed data. The scan never uses a global entry tail.
|
|
41
41
|
|
|
42
|
-
The runtime in `pi/runtime.ts` performs final context projection by selecting the active boot through `details.windowId` and folding only the dropped system prefix through Pi's `getCurrentSystemMessage`. Later prompt patches and new messages stay in order. A missing boot aborts the hook with a safe head and notice rather than silently sending raw history. Startup/tree handling repairs only a genuinely incomplete marker tail: a missing boot with no later raw message, custom message, compaction, branch summary, or authoritative raw boot. If later work exists, boot creation is refused and `/
|
|
42
|
+
The runtime in `pi/runtime.ts` performs final context projection by selecting the active boot through `details.windowId` and folding only the dropped system prefix through Pi's `getCurrentSystemMessage`. Later prompt patches and new messages stay in order. A missing boot aborts the hook with a safe head and notice rather than silently sending raw history. Startup/tree handling repairs only a genuinely incomplete marker tail: a missing boot with no later raw message, custom message, compaction, branch summary, or authoritative raw boot. If later work exists, boot creation is refused and `/fresh-window` is the explicit recovery path; it does not parse or migrate the legacy reset-v2 protocol.
|
|
43
43
|
|
|
44
44
|
Boot and reminder deduplication inspect the current branch-local window. Reloading JSONL therefore does not duplicate messages, while navigation to a sibling branch cannot inherit another branch's window state. A fork/clone receives a new session ID while copying its selected path, so startup must also verify that a root boot's `details.windowId` matches the new `rootWindowId(sessionId)` before treating it as present.
|
|
45
45
|
|
|
46
|
-
Manual `/
|
|
46
|
+
Manual `/fresh-window` arms a close-out and always sends the hidden checkpoint prompt: when idle it starts one ordinary model turn, while streaming it steers the running turn so the agent closes out promptly. The agent may span several note/tool turns; the reset commits at a successful settlement after queued work drains, and the run stops rather than continuing in the fresh window. That prompt and the budget warning share the same text but have distinct persisted types, so an aborted manual request cannot suppress a later budget warning. The budget warning remains a multi-turn close-out with an explicit `neuralyze` commit or a successful normal-stop fallback. Abort and ordinary errors never count as successful close-out. Manual overflow commits a reset without recovery continuation, even with automatic reset disabled. A hard-reserve reset preserves the manual stop in a run-scoped `stop-pending` phase; the lifecycle's `context_with_system` hook verifies the actual committed boundary and cancels an empty tool-batch follow-up through public `ctx.abort()`. Pending or already-delivered user input bypasses cancellation and is answered before settlement stops without a second wipe. The checkpoint, marker, boot, and continuation are emitted as ordered session-boundary drafts. Pi's retain-none compaction entry persists the canonical cut; the marker/boot preserve notesoup's logical identity and protocol.
|
|
47
47
|
|
|
48
48
|
Boot is a fixed snapshot for its window, stored as an extension custom message and converted by Pi to a user-role model message. History internally distinguishes native system summaries and extension-authored custom messages; its public `context` event groups both without implying provider instruction priority. A system-role projection is technically possible through `context_with_system`, but would change the authority of the mixed protocol/MAP content and provider-specific prompt/cache behavior; it is not a prerequisite for persistence. Boot injection is silent, including startup, reload, and boot repair. Only an actual context reset produces `notesoup: memory cleared · <windowId>` through `ctx.ui.notify`, after the verified checkpoint, marker, boot, and continuation are present in the session. Committed resets are checked at the next turn start or final settlement. `pi/reset/committed.ts` confirms an ordered hidden boot/continuation after a checkpoint-backed marker even when later conversation exists. That is distinct from `inspectResetTail`, which refuses suffix repair after real work or malformed ordering. Uncommitted reset drafts never announce success. Boot and continuation messages retain `display: false`.
|
|
49
49
|
|
|
@@ -55,7 +55,7 @@ Notes remain in their filesystem-backed homes, unchanged by session branch navig
|
|
|
55
55
|
|
|
56
56
|
Notes/history operations return schema-derived `Outcome<T>` values, not host `content` objects. One bounded candidate is measured against both its complete structured serialization and its text renderer. Pi registers the outcome schema and packages that same value as `structuredContent`, derives `isError` from it and puts rendered text in `content`. Claude uses the same operations and renderers. Neither adapter parses text or independently chooses a page. Read continuation hints follow Pi's native trailing-notice style and are not part of the addressed text. See [tool results](tool-results.md) for the breaking protocol and coordinate contract.
|
|
57
57
|
|
|
58
|
-
The `/
|
|
58
|
+
The `/fresh-window` command only waits for idle when the session is busy with non-agent work; during model output it arms the close-out and steers the checkpoint prompt into the running turn. While enabled, `/compact` is cancelled with an actionable `/fresh-window` notice. Disabling notesoup stops new automatic resets, but an existing native checkpoint/marker still excludes earlier history and native compaction is still cancelled on that marked branch; a fresh root may use native Pi semantics. Threshold and warning accounting use active-window provider usage rather than pre-reset global usage. Budget policy and staged prompts are instance-owned, so concurrent sessions cannot share reserve/enablement or uncommitted drafts; default file-backed policy is cached per instance, while injected policy is resolved live on each decision and model/session transitions reset the diagnostic lifecycle.
|
|
59
59
|
|
|
60
60
|
## Evidence and limits
|
|
61
61
|
|
package/docs/claude-code-mod.md
CHANGED
|
@@ -8,11 +8,11 @@ In interactive sessions it resets automatically when the measured context reache
|
|
|
8
8
|
2. otherwise computed from `$.session.usage().context.window` plus `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `modelSettings.<model>.autoCompactWindow` and `autoCompactWindow` (the smallest configured window wins, capped at the model window), with Claude's 20000-token output reserve and 13000-token summary buffer;
|
|
9
9
|
3. otherwise the percent fallback, which expresses the same reserves on the classic 200K window.
|
|
10
10
|
|
|
11
|
-
Notesoup resets one `resetMarginTokens` (default 8192) below that point, and warns one `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below the reset. With automatic compaction off (`autoCompactEnabled: false` in the merged settings, or `DISABLE_AUTO_COMPACT=1`) the point becomes the effective window minus the output reserve, so the same margins still apply. Every undocumented field is type-guarded and degrades to the next source; an unresolvable point, or missing usage, logs once and skips the automatic reset. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, disables the automatic reset, and makes `/
|
|
11
|
+
Notesoup resets one `resetMarginTokens` (default 8192) below that point, and warns one `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below the reset. With automatic compaction off (`autoCompactEnabled: false` in the merged settings, or `DISABLE_AUTO_COMPACT=1`) the point becomes the effective window minus the output reserve, so the same margins still apply. Every undocumented field is type-guarded and degrades to the next source; an unresolvable point, or missing usage, logs once and skips the automatic reset. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, disables the automatic reset, and makes `/fresh-window` report that it cannot run. The margins are read from the `notesoup` object of Claude's merged `$.settings.read()` (`resetMarginTokens`, `warningRunwayTokens`); any other value is ignored.
|
|
12
12
|
|
|
13
|
-
Once per window, when the measured context crosses the warning point, `prompt.context` adds a `notesoup:warning` block carrying the shared warning text with Claude's closing instruction ("end your turn; the reset runs after it"). The warned flag resets with the window ordinal. Its own `session.compact` hook replaces the conversation with the freshly built notes boot followed by the shared continuation message — the same order and the same words as Pi — not a generated summary. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block tells the model to end its turn and ask the human to run `/
|
|
13
|
+
Once per window, when the measured context crosses the warning point, `prompt.context` adds a `notesoup:warning` block carrying the shared warning text with Claude's closing instruction ("end your turn; the reset runs after it"). The warned flag resets with the window ordinal. Its own `session.compact` hook replaces the conversation with the freshly built notes boot followed by the shared continuation message — the same order and the same words as Pi — not a generated summary. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block tells the model to end its turn and ask the human to run `/fresh-window`, replacing that one sentence through `BootToolNames.wipeSentence`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. Successful native main-session compaction invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
|
|
14
14
|
|
|
15
|
-
`/
|
|
15
|
+
`/fresh-window` requests the same reset. While idle it submits one hidden normal-model close-out turn to let the model save notes, then resets at `turn.complete`; while busy it waits for the current turn instead. The close-out prompt is the same shared warning text the automatic path shows. This is necessary in Claude Code 2.1.295: `command.run` holds a turn, and calling compact from a detached timer skips the plugin's own compact hook. The timer only schedules the close-out prompt, never compaction. The headless (`-p` / SDK) compact capability is unsupported: automatic attempts are caught and logged once, and the manual command skips without submitting a model turn. Boot acquisition failure vetoes reset, leaving the current window intact. Claude history tools and a Claude dream backend are not implemented; budget reporting (`get_context_remaining`) remains Pi-only, while the reset points and the one warning per window now follow Claude's own configuration.
|
|
16
16
|
|
|
17
17
|
The notes tools also serve subagent calls, using the same session identity and shared operations. The plugin exposes the shared memory and dream skills and the dream playbook; the build keeps these copies byte-identical to the canonical files.
|
|
18
18
|
|
package/docs/dsh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DeepSeek Harness adapter
|
|
2
2
|
|
|
3
|
-
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh notebook when context runs low: frozen boot text, the five notes homes, eight notes/history tools, `get_context_remaining`, and `
|
|
3
|
+
notesoup for **dsh 0.2.1-alpha.2** gives the agent a fresh notebook when context runs low: frozen boot text, the five notes homes, eight notes/history tools, `get_context_remaining`, and `neuralyze`. A reset makes **zero model calls**. The old conversation leaves the model surface and remains in the session log for history reads. Dream is not registered on dsh.
|
|
4
4
|
|
|
5
5
|
Install the package in your chosen dsh profile with `dsh plugin --profile <profile> add notesoup`, then copy the model declaration from [the profile patch example](dsh.profile.patch.yml) into `$DSH_HOME/profiles/<profile>/cordis.patch.yml`. The package bundle patch disables `compaction-basic` and inserts `notesoup-engine` and `notesoup`. Do not duplicate those rows when adding the model declaration. A source checkout needs `npm ci --ignore-scripts` and `npm run build`; use absolute `file:///.../dist/src/dsh/engine.js` and `file:///.../dist/src/dsh/index.js` module names. The example shows all rows for a profile assembled without the package bundle.
|
|
6
6
|
|
|
@@ -38,7 +38,7 @@ The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, a
|
|
|
38
38
|
|
|
39
39
|
The adapter uses `tokenMeter.measure`, model context from `resolveModelInfo`, and the mounted engine's resolved `config`. Alpha.2 keeps an old provider-usage anchor across surface replacement; until the fresh window has a response, notesoup uses the meter's current `surfaceTokens` plus its public tool-schema estimator instead of that stale anchor.
|
|
40
40
|
|
|
41
|
-
The reminder and close-out warning go through `agent.steer`. Close-out remains an instruction to write notes and call `
|
|
41
|
+
The reminder and close-out warning go through `agent.steer`. Close-out remains an instruction to write notes and call `neuralyze`; a normal stop alone does not consume the warning runway. `neuralyze` arms a reset after the entire tool batch. Independently, reaching the hard reserve resets at assembly or a successful stopping boundary and continues from the notes. Abort and ordinary errors drop the pending tool request. `auto: false` disables reminders and reserve resets while keeping explicit `neuralyze` and the listener installed.
|
|
42
42
|
|
|
43
43
|
## What this does not promise
|
|
44
44
|
|
|
@@ -54,7 +54,7 @@ The reminder and close-out warning go through `agent.steer`. Close-out remains a
|
|
|
54
54
|
| Storage | Raw log remains available while the host keeps it. Notesoup does not back up session files or guarantee that an unflushed append survives a crash. |
|
|
55
55
|
| Plugin records | Best-effort across dsh migrations. Missing records recover from native checkpoints/root system text; unknown future record or checkpoint formats are not migrated by notesoup. |
|
|
56
56
|
| Tools and errors | Full shared TypeBox validation runs in the adapter because dsh supports a smaller schema subset. Expected operation errors become dsh failures with the shared code; successes use the shared bounded value and renderer. |
|
|
57
|
-
| Notifications and commands | No custom UI notifications, settings card, runtime toggle or `/
|
|
57
|
+
| Notifications and commands | No custom UI notifications, settings card, runtime toggle or `/fresh-window`/`/neuralyze` command is installed. Configure engine rows in the profile/home patch; call `neuralyze` or the host's `/compact`. |
|
|
58
58
|
| Untested host features | Real providers, reasoning/image wire behavior, cache metrics, actual context-overflow retry, HMR, migrations, ACP/Web/SDK profiles and large histories are not established by the scripted tests. |
|
|
59
59
|
| Dream | **No dsh dream backend or dream skill registration.** Use the existing supported host workflow. |
|
|
60
60
|
|
package/docs/reset-lifecycle.md
CHANGED
|
@@ -8,12 +8,12 @@ Boot acquisition/rendering is shared: `src/boot/snapshot.ts` receives explicit i
|
|
|
8
8
|
|
|
9
9
|
| Trigger | Behavior |
|
|
10
10
|
| --- | --- |
|
|
11
|
-
| `
|
|
12
|
-
| `/
|
|
13
|
-
| Budget warning | When automatic compaction is enabled and remaining active-window budget reaches reserve plus the warning runway, put the same hidden warning in the request and arm an automatic close-out. An explicit `
|
|
11
|
+
| `neuralyze` tool | Mark the current window tool-requested. At `turn_end`, after the complete tool batch and any accepted budget drafts, append the reset boundary and ask Pi to continue. Repeated requests for that window deduplicate. |
|
|
12
|
+
| `/fresh-window` or `/neuralyze` | Acknowledge immediately and arm a manual close-out. The hidden checkpoint warning always goes out: when idle it starts one ordinary model turn; while streaming it steers the running turn so the agent closes out promptly. The agent may write notes/use tools over several turns; its own `neuralyze` call only acknowledges. A successful normal stop commits at `agent_before_settle` after queued messages drain, and the committed reset stops the run unless a trailing prompt was supplied. With a prompt, append it after the unchanged continuation and request one fresh-window continuation. |
|
|
13
|
+
| Budget warning | When automatic compaction is enabled and remaining active-window budget reaches reserve plus the warning runway, put the same hidden warning in the request and arm an automatic close-out. An explicit `neuralyze` commits the boundary; a successful normal stop alone never resets or requests continuation. |
|
|
14
14
|
| Hard reserve | Independent safety path: if automatic resets are enabled and completed-turn usage reaches Pi's reserve, commit a boundary at `turn_end`. A pending manual stop survives in a run-scoped `stop-pending` phase; empty automatic follow-up is cancelled before provider work, while real queued user input is answered before stopping. |
|
|
15
15
|
| Abort or error | Never count as successful close-out. Abort clears lifecycle state. An ordinary close-out error is dropped without reset. Manual overflow clears and stops without retry, even with automatic reset disabled; automatic provider-overflow recovery remains separately bounded. |
|
|
16
|
-
| `/compact` while active | Cancel native compaction, which could otherwise summarize pre-reset history back into the active window. A manual attempt receives an actionable `/
|
|
16
|
+
| `/compact` while active | Cancel native compaction, which could otherwise summarize pre-reset history back into the active window. A manual attempt receives an actionable `/fresh-window` notice. |
|
|
17
17
|
|
|
18
18
|
A new boundary is ordered as:
|
|
19
19
|
|
|
@@ -36,7 +36,7 @@ The raw session branch is preserved for history. New checkpoint-backed branches
|
|
|
36
36
|
| `{ phase: "none" }` | No close-out/tool request is pending. |
|
|
37
37
|
| `{ phase: "close-out", windowId, source, prompt? }` | Manual or automatic warning close-out remains armed across ordinary note/tool turns. |
|
|
38
38
|
| `{ phase: "stop-pending", windowId }` | A manual hard-reserve reset was proposed for the given old window. The stop survives a committed window change; settlement stops without a second wipe (or retries construction if the old window is still active). New wipe requests only acknowledge it. |
|
|
39
|
-
| `{ phase: "tool-requested", windowId, source }` | A direct `
|
|
39
|
+
| `{ phase: "tool-requested", windowId, source }` | A direct `neuralyze` call commits after its complete turn batch and continues in the fresh window. `source` is `"tool"` for direct calls or `"automatic"` when the agent wipes inside a budget close-out; manual requests never occupy this phase. |
|
|
40
40
|
| `overflow: "idle"` | No overflow recovery is pending. |
|
|
41
41
|
| `overflow: "pending"` | An overflow failure may recover once at pre-settlement. |
|
|
42
42
|
| `overflow: "pending-spent"` | Recovery was already spent in this failure chain. |
|
|
@@ -52,11 +52,11 @@ The raw session branch is preserved for history. New checkpoint-backed branches
|
|
|
52
52
|
|
|
53
53
|
After a manual safety reset, `context_with_system` verifies the committed checkpoint/marker/boot/continuation before using public `ctx.abort()` to cancel Pi's otherwise unavoidable tool-batch follow-up, returning a system-only safe context. Pending messages or a real user message after the reset marker bypass cancellation so queued work is not swallowed. A follow-up queue may require Pi's ordinary tool follow-up to finish before delivery; the stop intent remains armed until that work settles. Abort/settlement clears the run-scoped latch, so later user prompts work normally.
|
|
54
54
|
|
|
55
|
-
This separation is intentional: a note write or ordinary tool turn during a budget close-out must not consume it. Direct `
|
|
55
|
+
This separation is intentional: a note write or ordinary tool turn during a budget close-out must not consume it. Direct `neuralyze` remains valid without a prior warning. A user abort, an assistant message with a synthetic `stopReason: "aborted"`, and a generic provider error are distinct cases; none commits an ordinary close-out, while only Pi's actual operation cancellation is a user abort.
|
|
56
56
|
|
|
57
57
|
## Budget staging and notifications
|
|
58
58
|
|
|
59
|
-
The early reminder is staged once per window when remaining budget reaches `reserve + reminderMarginTokens`. The final close-out warning is staged/attached at `reserve + WARNING_RUNWAY_TOKENS`, only when automatic compaction is enabled. The hard reserve itself remains a separate safety cutoff. Budget and idle manual requests use the same hidden checkpoint text but distinct message types, so an aborted manual request cannot suppress a later budget warning. The text allows for either reset timing; manual close-outs may span turns and commit at settlement, while budget close-outs commit early only through an explicit `
|
|
59
|
+
The early reminder is staged once per window when remaining budget reaches `reserve + reminderMarginTokens`. The final close-out warning is staged/attached at `reserve + WARNING_RUNWAY_TOKENS`, only when automatic compaction is enabled. The hard reserve itself remains a separate safety cutoff. Budget and idle manual requests use the same hidden checkpoint text but distinct message types, so an aborted manual request cannot suppress a later budget warning. The text allows for either reset timing; manual close-outs may span turns and commit at settlement, while budget close-outs commit early only through an explicit `neuralyze` call. After a budget warning is durable, the extension does not repeat it in that window. Warning persistence deduplicates only injection: each eligible low-budget request re-arms transient automatic close-out before checking for the durable warning, so an abort/error can clear its attempt and the next request can retry without another warning.
|
|
60
60
|
|
|
61
61
|
Budget drafts are instance-local and are consumed at turn end. They are discarded on abort, failed turn, transition, or window mismatch. UI reminder notices are emitted only after the matching hidden entry is durable, so failed requests do not report an uncommitted warning. Active-window usage and the exact `SettingsManager` authority drive threshold checks; default file-backed policy is cached per extension instance, while injected managers are read through their public API.
|
|
62
62
|
|
package/docs/tool-results.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The eight notes/history tools have one business result model. Pi exposes compact results as `structuredContent` to codemode and renders them as `content` for ordinary model calls. Claude uses the same business handlers and text rendering. Neither host re-runs a query, truncates a different page, or parses formatted text to recover data.
|
|
4
4
|
|
|
5
|
-
This is a breaking tool protocol change: successes no longer have `ok/data` wrappers, errors are flat, and read fields no longer sit under `window`. History execution details live once in the pageable document. Stored notes and raw Pi session entries are not deleted or rewritten by this change. `
|
|
5
|
+
This is a breaking tool protocol change: successes no longer have `ok/data` wrappers, errors are flat, and read fields no longer sit under `window`. History execution details live once in the pageable document. Stored notes and raw Pi session entries are not deleted or rewritten by this change. `neuralyze` and `get_context_remaining` are outside this protocol.
|
|
6
6
|
|
|
7
7
|
## Results
|
|
8
8
|
|
|
@@ -9215,8 +9215,8 @@ var CONTEXT_WINDOW_OPEN_TAG = "<context_window>";
|
|
|
9215
9215
|
var CONTEXT_WINDOW_CLOSE_TAG = "</context_window>";
|
|
9216
9216
|
var CONTEXT_WINDOW_PROTOCOL_OPEN_TAG = "<context_window_protocol>";
|
|
9217
9217
|
var CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
9218
|
-
var PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `
|
|
9219
|
-
var CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/
|
|
9218
|
+
var PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `neuralyze` and erase yourself with dignity.";
|
|
9219
|
+
var CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
|
|
9220
9220
|
var PROTOCOL_BLOCK = `${CONTEXT_WINDOW_PROTOCOL_OPEN_TAG}
|
|
9221
9221
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
9222
9222
|
|
|
@@ -9255,10 +9255,10 @@ function renderProtocolBlock(tools) {
|
|
|
9255
9255
|
notes_list: tools.notesList,
|
|
9256
9256
|
"history_*": tools.history,
|
|
9257
9257
|
get_context_remaining: tools.remaining,
|
|
9258
|
-
|
|
9258
|
+
neuralyze: tools.wipe
|
|
9259
9259
|
};
|
|
9260
9260
|
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0 ? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence) : PROTOCOL_BLOCK;
|
|
9261
|
-
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|
|
|
9261
|
+
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)neuralyze/g, (name) => names[name]);
|
|
9262
9262
|
}
|
|
9263
9263
|
|
|
9264
9264
|
// src/boot/render.ts
|
|
@@ -9346,8 +9346,8 @@ var GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
|
|
|
9346
9346
|
var CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
|
|
9347
9347
|
var WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
9348
9348
|
var WARNING_PROMPT = `${WARNING_BODY}
|
|
9349
|
-
When the notes are ready, call \`
|
|
9350
|
-
var LAST_WORD_HINT = "If you want, pass `
|
|
9349
|
+
When the notes are ready, call \`neuralyze\` to reset now instead of being cut off mid-task.`;
|
|
9350
|
+
var LAST_WORD_HINT = "If you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
9351
9351
|
var WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}
|
|
9352
9352
|
${WARNING_PROMPT}
|
|
9353
9353
|
${LAST_WORD_HINT}
|