notesoup 0.47.1 → 0.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/boot/render.d.ts +14 -7
- package/dist/src/boot/render.js +29 -16
- package/dist/src/boot/text.d.ts +25 -4
- package/dist/src/boot/text.js +60 -13
- package/dist/src/budget/constants.d.ts +2 -4
- package/dist/src/budget/constants.js +2 -4
- package/dist/src/budget/policy.d.ts +2 -2
- package/dist/src/budget/policy.js +3 -3
- package/dist/src/budget/text.d.ts +29 -9
- package/dist/src/budget/text.js +51 -10
- package/dist/src/claude/helper.d.ts +2 -3
- package/dist/src/claude/helper.js +45 -11
- package/dist/src/claude/history.d.ts +9 -0
- package/dist/src/claude/history.js +271 -0
- package/dist/src/dsh/budget.js +1 -1
- package/dist/src/dsh/engine.d.ts +2 -1
- package/dist/src/dsh/engine.js +18 -9
- package/dist/src/dsh/index.js +9 -4
- package/dist/src/dsh/tools.js +1 -1
- package/dist/src/dsh/window.d.ts +2 -1
- package/dist/src/dsh/window.js +14 -8
- package/dist/src/history/query.js +59 -81
- package/dist/src/notes/address.d.ts +5 -0
- package/dist/src/notes/address.js +20 -21
- package/dist/src/notes/store.js +12 -19
- package/dist/src/pi/boot.d.ts +1 -1
- package/dist/src/pi/boot.js +28 -5
- package/dist/src/pi/budget.d.ts +1 -3
- package/dist/src/pi/budget.js +20 -61
- package/dist/src/pi/entries.d.ts +0 -1
- package/dist/src/pi/entries.js +0 -1
- package/dist/src/pi/history.d.ts +3 -0
- package/dist/src/pi/history.js +4 -0
- package/dist/src/pi/reset/artifacts.d.ts +7 -2
- package/dist/src/pi/reset/artifacts.js +16 -14
- package/dist/src/pi/reset/lifecycle.d.ts +21 -25
- package/dist/src/pi/reset/lifecycle.js +48 -72
- package/dist/src/pi/runtime.js +9 -8
- package/dist/src/pi/window.d.ts +12 -6
- package/dist/src/pi/window.js +7 -0
- package/dist/test/agent-loop.test.js +53 -30
- package/dist/test/boot.integration.test.js +123 -12
- package/dist/test/budget-settings.integration.test.js +10 -6
- package/dist/test/claude-history.test.d.ts +1 -0
- package/dist/test/claude-history.test.js +184 -0
- package/dist/test/claude-mod.test.js +236 -42
- package/dist/test/dsh.test.js +80 -3
- package/dist/test/helpers/extension.d.ts +3 -0
- package/dist/test/helpers/extension.js +33 -5
- package/dist/test/history.integration.test.js +66 -0
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/model-facing-text.test.d.ts +1 -0
- package/dist/test/model-facing-text.test.js +181 -0
- package/dist/test/notes.integration.test.js +16 -18
- package/dist/test/reset-lifecycle.test.js +201 -46
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +15 -3
- package/docs/dsh.md +2 -2
- package/docs/reset-lifecycle.md +32 -20
- package/docs/skills.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +836 -92
- package/mods/notesoup/hooks/register.ts +140 -38
- package/package.json +1 -1
- package/src/boot/render.ts +41 -23
- package/src/boot/text.ts +69 -13
- package/src/budget/constants.ts +2 -4
- package/src/budget/policy.ts +3 -3
- package/src/budget/text.ts +61 -10
- package/src/claude/helper.ts +53 -22
- package/src/claude/history.ts +228 -0
- package/src/dsh/budget.ts +1 -1
- package/src/dsh/engine.ts +16 -9
- package/src/dsh/index.ts +8 -3
- package/src/dsh/tools.ts +1 -1
- package/src/dsh/window.ts +15 -9
- package/src/history/query.ts +57 -82
- package/src/notes/address.ts +19 -16
- package/src/notes/store.ts +9 -14
- package/src/pi/boot.ts +27 -5
- package/src/pi/budget.ts +20 -58
- package/src/pi/entries.ts +0 -1
- package/src/pi/history.ts +7 -2
- package/src/pi/reset/artifacts.ts +17 -14
- package/src/pi/reset/lifecycle.ts +56 -79
- package/src/pi/runtime.ts +9 -8
- package/src/pi/window.ts +11 -1
|
@@ -7,9 +7,10 @@ import { SessionManager as Manager } from "@earendil-works/pi-coding-agent";
|
|
|
7
7
|
import notesoup from "../src/pi/extension.js";
|
|
8
8
|
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
9
9
|
import { MANUAL_WIPE_TYPE } from "../src/pi/entries.js";
|
|
10
|
-
import { toolContext } from "./helpers/extension.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { assertBootHistory, toolContext } from "./helpers/extension.js";
|
|
11
|
+
import { COUNTDOWN_LINE, FORCED_CONTINUATIONS, LAST_WORD_HINT, NORMAL_CONTINUATIONS, WARNING_CALL_PROMPTED, warningContent } from "../src/budget/text.js";
|
|
12
|
+
import { historyFromSession, nextHistorySeq } from "../src/pi/history.js";
|
|
13
|
+
import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../src/pi/reset/artifacts.js";
|
|
13
14
|
import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../src/pi/reset/lifecycle.js";
|
|
14
15
|
const previousNotesHome = process.env.PI_NOTES_HOME;
|
|
15
16
|
const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
|
|
@@ -176,7 +177,7 @@ test("public reset boundary drafts one marker, one boot, and one continuation af
|
|
|
176
177
|
assert.equal(boundary.entries[4]?.type, "custom_message", "the continuation closes the ordered reset shape");
|
|
177
178
|
appendDrafts(h.sessionManager, boundary.entries);
|
|
178
179
|
const branch = h.sessionManager.getBranch();
|
|
179
|
-
assert.deepEqual(branch.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).map((entry) => entry.type === "custom" ? entry.data : undefined), [{ windowId }]);
|
|
180
|
+
assert.deepEqual(branch.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).map((entry) => entry.type === "custom" ? entry.data : undefined), [{ windowId, origin: "normal" }], "the boundary records the model's own call");
|
|
180
181
|
assert.equal(branch.filter((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE).length, 1);
|
|
181
182
|
});
|
|
182
183
|
test("manual /empty-brain spans tool turns and commits the stop at settlement", async () => {
|
|
@@ -227,10 +228,40 @@ test("off stops future automatic/manual reset requests while an existing marker
|
|
|
227
228
|
assert.equal(h.sent[0]?.customType, MANUAL_WIPE_TYPE);
|
|
228
229
|
const warning = h.sessionManager.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE);
|
|
229
230
|
assert.ok(warning && warning.type === "custom_message");
|
|
230
|
-
assert.equal(warning.content,
|
|
231
|
+
assert.equal(warning.content, warningContent());
|
|
231
232
|
const markers = h.sessionManager.getBranch().filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
232
233
|
assert.equal(markers.length, 1, "manual command waits for an agent boundary; it does not persist an immediate reset");
|
|
233
234
|
});
|
|
235
|
+
test("manual /empty-brain with a prompt shows the human's command line in the close-out", async () => {
|
|
236
|
+
const h = harness();
|
|
237
|
+
// Assert on values, not on the warning's wording: the command line must survive verbatim
|
|
238
|
+
// and must precede the closing instruction, so the prompt cannot read as this window's task.
|
|
239
|
+
await h.runCommand("empty-brain", "Continue reviewing the implementation");
|
|
240
|
+
const warning = h.sessionManager.getBranch().find((entry) => entry.type === "custom_message" && entry.customType === MANUAL_WIPE_TYPE);
|
|
241
|
+
assert.ok(warning?.type === "custom_message", "the close-out warning is persisted");
|
|
242
|
+
const content = String(warning.content);
|
|
243
|
+
const promptLine = "/empty-brain Continue reviewing the implementation";
|
|
244
|
+
const promptIndex = content.indexOf(promptLine);
|
|
245
|
+
assert.ok(promptIndex >= 0, "the human's raw command line reaches the closing model");
|
|
246
|
+
const closingIndex = content.indexOf(WARNING_CALL_PROMPTED);
|
|
247
|
+
assert.ok(closingIndex > promptIndex, "the closing instruction follows the prompt, so the order stays prompt then act");
|
|
248
|
+
assert.ok(content.indexOf(COUNTDOWN_LINE) > content.indexOf(LAST_WORD_HINT), "the countdown follows the Pi-only last-word hint");
|
|
249
|
+
assert.equal(content.split(COUNTDOWN_LINE).length - 1, 1, "the notice carries the countdown once");
|
|
250
|
+
// The prompt was a note-to-self for the closing window: it never becomes the next window's task.
|
|
251
|
+
const settle = resultEntries(await h.emit("agent_before_settle", {
|
|
252
|
+
type: "agent_before_settle",
|
|
253
|
+
entries: [],
|
|
254
|
+
outcome: "completed",
|
|
255
|
+
context: { contextEntries: [], contextMessages: [], llmMessages: [], pendingMessages: [], canContinue: true },
|
|
256
|
+
}));
|
|
257
|
+
assert.equal(settle.continue, true, "a prompted close-out continues in the fresh window");
|
|
258
|
+
assert.deepEqual(settle.entries.map((entry) => entry.type === "compaction" ? "native-compaction" : entry.customType), [
|
|
259
|
+
"native-compaction",
|
|
260
|
+
RESET_MARKER_TYPE,
|
|
261
|
+
BOOT_TYPE,
|
|
262
|
+
CONTINUATION_TYPE,
|
|
263
|
+
], "the reset tail is one boot, one continuation, and no persisted prompt");
|
|
264
|
+
});
|
|
234
265
|
test("reset construction failure preserves incoming and budget drafts without continuation", async () => {
|
|
235
266
|
const sessionManager = Manager.inMemory("/private/tmp/notesoup-reset-failure-test");
|
|
236
267
|
const handlers = new Map();
|
|
@@ -259,9 +290,9 @@ test("reset construction failure preserves incoming and budget drafts without co
|
|
|
259
290
|
consumeTurnEnd: () => [budgetDraft],
|
|
260
291
|
clear: () => { },
|
|
261
292
|
},
|
|
262
|
-
buildReset: (
|
|
293
|
+
buildReset: () => { throw new Error("synthetic reset construction failure"); },
|
|
263
294
|
});
|
|
264
|
-
lifecycle.
|
|
295
|
+
lifecycle.command(`pcw:${sessionManager.getSessionId().slice(0, 8)}:root`, true);
|
|
265
296
|
const incoming = { type: "custom_message", customType: "foreign/boundary", content: "foreign draft", display: false };
|
|
266
297
|
const results = [];
|
|
267
298
|
for (const handler of handlers.get("turn_end") ?? [])
|
|
@@ -273,7 +304,44 @@ test("reset construction failure preserves incoming and budget drafts without co
|
|
|
273
304
|
assert.equal(result.continue, false, "a failed reset does not request continuation");
|
|
274
305
|
assert.equal(notices.at(-1)?.type, "warning");
|
|
275
306
|
assert.match(notices.at(-1)?.message ?? "", /Brain still full/);
|
|
276
|
-
assert.match(notices.at(-1)?.message ?? "", /
|
|
307
|
+
assert.match(notices.at(-1)?.message ?? "", /synthetic reset construction failure/);
|
|
308
|
+
assert.doesNotMatch(notices.at(-1)?.message ?? "", /prompt not sent/);
|
|
309
|
+
});
|
|
310
|
+
test("reset seq is captured before asynchronous construction and counts only consuming drafts", async () => {
|
|
311
|
+
const h = harness();
|
|
312
|
+
const handlers = new Map();
|
|
313
|
+
const api = { on(name, handler) { handlers.set(name, handler); } };
|
|
314
|
+
const ctx = { sessionManager: h.sessionManager, model: undefined, hasPendingMessages: () => false, ui: { notify() { } } };
|
|
315
|
+
const targetId = h.sessionManager.appendMessage({ role: "user", content: "recorded", timestamp: Date.now() });
|
|
316
|
+
const budgetDraft = { type: "custom_message", customType: GUIDANCE_TYPE, content: "pending budget", display: false };
|
|
317
|
+
const incoming = [
|
|
318
|
+
{ type: "custom", customType: "foreign/metadata" },
|
|
319
|
+
{ type: "context_edit", targetId, replacement: null },
|
|
320
|
+
{ type: "custom_message", customType: "foreign/message", content: "pending", display: false },
|
|
321
|
+
{ type: "compaction", summary: "pending checkpoint", firstKeptEntryId: null },
|
|
322
|
+
];
|
|
323
|
+
const before = historyFromSession(ctx).highestSeq;
|
|
324
|
+
let capturedSeq;
|
|
325
|
+
let release;
|
|
326
|
+
const pending = new Promise((resolve) => { release = resolve; });
|
|
327
|
+
const lifecycle = registerResetLifecycle(api, {
|
|
328
|
+
isEnabled: () => true,
|
|
329
|
+
budget: { automaticResetEnabled: () => true, hardReserveDue: () => false, consumeTurnEnd: () => [budgetDraft], clear() { } },
|
|
330
|
+
async buildReset(_ctx, _isCurrent, _lastWord, firstSeq) {
|
|
331
|
+
capturedSeq = firstSeq;
|
|
332
|
+
await pending;
|
|
333
|
+
return [];
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
lifecycle.request(`pcw:${h.sessionManager.getSessionId().slice(0, 8)}:root`);
|
|
337
|
+
const result = handlers.get("turn_end")(fakeBoundaryEvent(incoming), ctx);
|
|
338
|
+
assert.equal(capturedSeq, before + 5, "three consuming pending drafts, the old checkpoint and the next slot");
|
|
339
|
+
h.sessionManager.appendCustomMessageEntry("foreign/during-await", "later", false);
|
|
340
|
+
release();
|
|
341
|
+
await result;
|
|
342
|
+
assert.equal(capturedSeq, before + 5, "snapshot latency must not recalculate the window's first seq");
|
|
343
|
+
appendDrafts(h.sessionManager, [...incoming, budgetDraft]);
|
|
344
|
+
assert.equal(nextHistorySeq(ctx), historyFromSession(ctx).highestSeq + 1);
|
|
277
345
|
});
|
|
278
346
|
test("a stale async reset is discarded after a lifecycle switch without staging a notice", async () => {
|
|
279
347
|
const sessionManager = Manager.inMemory("/private/tmp/notesoup-stale-reset-test");
|
|
@@ -372,50 +440,65 @@ test("a queued success clears an overflow failure before settle recovery can res
|
|
|
372
440
|
assert.equal(await beforeSettle(settled, ctx), undefined, "the successful queued turn clears the stale recovery");
|
|
373
441
|
assert.equal(resetCount, 0);
|
|
374
442
|
});
|
|
375
|
-
test("reset-control:
|
|
443
|
+
test("reset-control: command policy deduplicates, spans turns, and retains a real tool request", () => {
|
|
376
444
|
const windowId = "pcw:test:window";
|
|
377
|
-
const first = reduceResetControl(initialResetControl(), { type: "
|
|
445
|
+
const first = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false });
|
|
378
446
|
assert.equal(first.effect, "close-out-armed");
|
|
379
|
-
assert.deepEqual(first.state.request, { phase: "
|
|
380
|
-
const duplicate = reduceResetControl(first.state, { type: "
|
|
447
|
+
assert.deepEqual(first.state.request, { phase: "pending", windowId, command: { continueAfterReset: false } });
|
|
448
|
+
const duplicate = reduceResetControl(first.state, { type: "command", windowId, continueAfterReset: false });
|
|
381
449
|
assert.equal(duplicate.effect, "already-pending");
|
|
382
450
|
const noteTurn = reduceResetControl(first.state, { type: "turn_end", facts: turnEndFacts() });
|
|
383
451
|
assert.equal(noteTurn.effect, "none");
|
|
384
452
|
assert.deepEqual(noteTurn.state.request, first.state.request, "note/tool turns do not consume close-out");
|
|
385
453
|
const tool = reduceResetControl(noteTurn.state, { type: "tool_request", windowId });
|
|
386
|
-
assert.equal(tool.effect, "
|
|
387
|
-
assert.deepEqual(tool.state.request, { phase: "
|
|
454
|
+
assert.equal(tool.effect, "close-out-armed", "the first tool call is recorded without changing settlement policy");
|
|
455
|
+
assert.deepEqual(tool.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
|
|
388
456
|
const commit = reduceResetControl(tool.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
389
457
|
assert.equal(commit.effect, "commit-boundary-stop", "a manual close-out commits at settlement and stops");
|
|
390
458
|
assert.deepEqual(commit.state, initialResetControl());
|
|
391
459
|
});
|
|
392
|
-
test("reset-control:
|
|
460
|
+
test("reset-control: command settlement policy preserves a pending tool request", () => {
|
|
393
461
|
const windowId = "pcw:test:window";
|
|
394
462
|
const tool = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
|
|
395
|
-
const manual = reduceResetControl(tool.state, { type: "
|
|
463
|
+
const manual = reduceResetControl(tool.state, { type: "command", windowId, continueAfterReset: false });
|
|
396
464
|
assert.equal(manual.effect, "close-out-armed", "the user's stop intent outranks the pending rollover");
|
|
397
|
-
assert.deepEqual(manual.state.request, { phase: "
|
|
465
|
+
assert.deepEqual(manual.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} });
|
|
398
466
|
assert.equal(reduceResetControl(manual.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none", "the converted request no longer commits at turn end");
|
|
399
467
|
assert.equal(reduceResetControl(manual.state, { type: "before_settle", facts: beforeSettleFacts() }).effect, "commit-boundary-stop");
|
|
400
|
-
const automatic = reduceResetControl(tool.state, { type: "close_out", windowId, source: "automatic" });
|
|
401
|
-
assert.equal(automatic.effect, "already-pending", "an automatic close-out must not displace a pending tool commit");
|
|
402
468
|
});
|
|
403
|
-
test("reset-control:
|
|
469
|
+
test("reset-control: duplicate commands preserve policy and both call orders retain the tool's last word", () => {
|
|
404
470
|
const windowId = "pcw:test:window";
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
assert.
|
|
471
|
+
const command = { type: "command", windowId, continueAfterReset: true };
|
|
472
|
+
const call = { type: "tool_request", windowId, lastWord: "pick up here" };
|
|
473
|
+
const first = reduceResetControl(initialResetControl(), command);
|
|
474
|
+
const duplicate = reduceResetControl(first.state, { ...command, continueAfterReset: false });
|
|
475
|
+
assert.equal(duplicate.effect, "already-pending");
|
|
476
|
+
assert.deepEqual(duplicate.state, first.state);
|
|
477
|
+
const commandThenTool = reduceResetControl(first.state, call);
|
|
478
|
+
const toolThenCommand = reduceResetControl(reduceResetControl(initialResetControl(), call).state, command);
|
|
479
|
+
assert.deepEqual(commandThenTool.state, toolThenCommand.state);
|
|
480
|
+
const repeated = reduceResetControl(commandThenTool.state, { ...call, lastWord: "do not replace" });
|
|
481
|
+
assert.equal(repeated.effect, "already-pending");
|
|
482
|
+
assert.deepEqual(repeated.state, commandThenTool.state);
|
|
483
|
+
assert.equal(reduceResetControl(repeated.state, { type: "turn_end", facts: turnEndFacts() }).effect, "none");
|
|
484
|
+
const commit = reduceResetControl(repeated.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
485
|
+
assert.equal(commit.effect, "commit-boundary");
|
|
486
|
+
assert.equal(commit.lastWord, "pick up here");
|
|
487
|
+
});
|
|
488
|
+
test("reset-control: a tool request needs no prior budget warning", () => {
|
|
489
|
+
const windowId = "pcw:test:window";
|
|
490
|
+
const requested = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
|
|
491
|
+
assert.equal(requested.effect, "close-out-armed");
|
|
492
|
+
assert.deepEqual(requested.state.request, { phase: "pending", windowId, tool: {} });
|
|
493
|
+
assert.equal(reduceResetControl(requested.state, { type: "turn_end", facts: turnEndFacts() }).effect, "commit-boundary");
|
|
411
494
|
});
|
|
412
495
|
test("reset-control: fallback is normal-stop only; hard reserve remains safety", () => {
|
|
413
496
|
const windowId = "pcw:test:window";
|
|
414
|
-
const manual = reduceResetControl(initialResetControl(), { type: "
|
|
497
|
+
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
415
498
|
const fallback = reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() });
|
|
416
499
|
assert.equal(fallback.effect, "commit-boundary-stop", "manual close-out stops after the reset is committed");
|
|
417
500
|
assert.deepEqual(fallback.state, initialResetControl());
|
|
418
|
-
const automatic =
|
|
501
|
+
const automatic = initialResetControl();
|
|
419
502
|
const normalStop = reduceResetControl(automatic, { type: "before_settle", facts: beforeSettleFacts() });
|
|
420
503
|
assert.equal(normalStop.effect, "none", "ignoring a budget warning and answering normally must not wipe memory");
|
|
421
504
|
assert.deepEqual(normalStop.state, initialResetControl());
|
|
@@ -433,13 +516,13 @@ test("reset-control: fallback is normal-stop only; hard reserve remains safety",
|
|
|
433
516
|
});
|
|
434
517
|
test("reset-control: manual stop survives a hard-reserve reset across windows without a second wipe", () => {
|
|
435
518
|
const windowId = "pcw:test:window";
|
|
436
|
-
const manual = reduceResetControl(initialResetControl(), { type: "
|
|
519
|
+
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
437
520
|
const safety = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
|
|
438
521
|
assert.equal(safety.effect, "commit-boundary-stop");
|
|
439
522
|
assert.deepEqual(safety.state.request, { phase: "stop-pending", windowId });
|
|
440
523
|
const freshWindowId = "pcw:test:fresh";
|
|
441
524
|
assert.equal(reduceResetControl(safety.state, { type: "tool_request", windowId: freshWindowId }).effect, "already-pending");
|
|
442
|
-
assert.equal(reduceResetControl(safety.state, { type: "
|
|
525
|
+
assert.equal(reduceResetControl(safety.state, { type: "command", windowId: freshWindowId, continueAfterReset: false }).effect, "already-pending");
|
|
443
526
|
const queued = reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts({ windowId: freshWindowId, queued: true }) });
|
|
444
527
|
assert.deepEqual(queued.state, safety.state);
|
|
445
528
|
const freshTurn = reduceResetControl(queued.state, { type: "turn_end", facts: turnEndFacts({ windowId: freshWindowId, hardReserveDue: true }) });
|
|
@@ -452,7 +535,7 @@ test("reset-control: manual stop survives a hard-reserve reset across windows wi
|
|
|
452
535
|
});
|
|
453
536
|
test("reset-control: manual overflow keeps stop intent while queued work supersedes the failure", () => {
|
|
454
537
|
const windowId = "pcw:test:window";
|
|
455
|
-
const manual = reduceResetControl(initialResetControl(), { type: "
|
|
538
|
+
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
456
539
|
const overflow = reduceResetControl(manual, { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true, queued: true, automaticResetEnabled: false }) });
|
|
457
540
|
assert.deepEqual(overflow.state.request, manual.request);
|
|
458
541
|
const deferred = reduceResetControl(overflow.state, { type: "before_settle", facts: beforeSettleFacts({ failed: true, queued: true, automaticResetEnabled: false }) });
|
|
@@ -465,7 +548,7 @@ test("reset-control: manual overflow keeps stop intent while queued work superse
|
|
|
465
548
|
});
|
|
466
549
|
test("reset-control: abort and lifecycle transitions clear every pending phase", () => {
|
|
467
550
|
const windowId = "pcw:test:window";
|
|
468
|
-
const pending = reduceResetControl(initialResetControl(), { type: "
|
|
551
|
+
const pending = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
469
552
|
const aborted = reduceResetControl(pending, { type: "turn_end", facts: turnEndFacts({ aborted: true }) });
|
|
470
553
|
assert.equal(aborted.effect, "none");
|
|
471
554
|
assert.deepEqual(aborted.state, initialResetControl());
|
|
@@ -545,13 +628,14 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
545
628
|
},
|
|
546
629
|
};
|
|
547
630
|
const ctx = {
|
|
631
|
+
cwd: "/private/tmp",
|
|
632
|
+
isProjectTrusted: () => true,
|
|
548
633
|
sessionManager,
|
|
549
634
|
model: undefined,
|
|
550
635
|
signal: undefined,
|
|
551
636
|
hasPendingMessages: () => false,
|
|
552
637
|
ui: { notify() { } },
|
|
553
638
|
};
|
|
554
|
-
const windowId = "pcw:ordering:test";
|
|
555
639
|
const budgetDraft = { type: "custom_message", customType: GUIDANCE_TYPE, content: "budget draft", display: false };
|
|
556
640
|
const lifecycle = registerResetLifecycle(api, {
|
|
557
641
|
isEnabled: () => true,
|
|
@@ -561,12 +645,7 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
561
645
|
consumeTurnEnd: () => [budgetDraft],
|
|
562
646
|
clear: () => { },
|
|
563
647
|
},
|
|
564
|
-
buildReset: () =>
|
|
565
|
-
{ type: "compaction", summary: "", firstKeptEntryId: null },
|
|
566
|
-
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
|
|
567
|
-
{ type: "custom_message", customType: BOOT_TYPE, content: "boot", display: false, details: { windowId } },
|
|
568
|
-
{ type: "custom_message", customType: CONTINUATION_TYPE, content: "continuation", display: false },
|
|
569
|
-
],
|
|
648
|
+
buildReset: (ctx, isCurrent, lastWord, firstSeq, origin) => buildResetDrafts(ctx, undefined, isCurrent, lastWord, firstSeq, origin),
|
|
570
649
|
});
|
|
571
650
|
lifecycle.request(`pcw:${sessionManager.getSessionId().slice(0, 8)}:root`);
|
|
572
651
|
const incoming = { type: "custom_message", customType: "foreign/boundary", content: "incoming", display: false };
|
|
@@ -598,6 +677,12 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
598
677
|
assert.ok(checkpoint?.type === "compaction");
|
|
599
678
|
assert.equal(checkpoint.summary, "");
|
|
600
679
|
assert.equal(checkpoint.firstKeptEntryId, checkpoint.id, "Pi materializes null as retain-none");
|
|
680
|
+
const projection = historyFromSession(ctx);
|
|
681
|
+
const boot = branch.find((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE);
|
|
682
|
+
assert.ok(boot?.type === "custom_message");
|
|
683
|
+
assertBootHistory(String(boot.content), projection);
|
|
684
|
+
assert.equal(projection.windows[0].items.at(-1).seq, projection.windows[1].items[0].seq - 1, "the old window includes its checkpoint slot");
|
|
685
|
+
assert.equal(nextHistorySeq(ctx), projection.highestSeq + 1);
|
|
601
686
|
assert.deepEqual(customTypes(branch.slice(markerIndex)), [
|
|
602
687
|
RESET_MARKER_TYPE,
|
|
603
688
|
BOOT_TYPE,
|
|
@@ -635,19 +720,89 @@ test("reset-control: a tool request carries its last word to the turn-end commit
|
|
|
635
720
|
const windowId = "pcw:test:window";
|
|
636
721
|
const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
|
637
722
|
assert.equal(armed.effect, "close-out-armed");
|
|
638
|
-
assert.deepEqual(armed.state.request, { phase: "
|
|
723
|
+
assert.deepEqual(armed.state.request, { phase: "pending", windowId, tool: { lastWord: "the shoes were loyal" } });
|
|
639
724
|
const commit = reduceResetControl(armed.state, { type: "turn_end", facts: turnEndFacts() });
|
|
640
725
|
assert.equal(commit.effect, "commit-boundary");
|
|
641
726
|
assert.equal(commit.lastWord, "the shoes were loyal");
|
|
642
727
|
});
|
|
643
|
-
test("reset-control: a
|
|
728
|
+
test("reset-control: a call and a command keep their facts in either order", () => {
|
|
729
|
+
const windowId = "pcw:test:window";
|
|
730
|
+
// The call first, then the command: the conversion must not erase the call it outranks.
|
|
731
|
+
const toolFirst = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
|
732
|
+
const converted = reduceResetControl(toolFirst.state, { type: "command", windowId, continueAfterReset: false });
|
|
733
|
+
assert.equal(converted.effect, "close-out-armed");
|
|
734
|
+
assert.deepEqual(converted.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "the shoes were loyal" } });
|
|
735
|
+
const stop = reduceResetControl(converted.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
736
|
+
assert.equal(stop.effect, "commit-boundary-stop");
|
|
737
|
+
assert.equal(stop.origin, "normal", "a command arriving after a model wipe does not rewrite it as forced");
|
|
738
|
+
assert.equal(stop.lastWord, "the shoes were loyal", "the call's parting line survives the conversion");
|
|
739
|
+
// The command first, then the call: the acknowledgement records the call and keeps stopping.
|
|
740
|
+
const commandFirst = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false });
|
|
741
|
+
const acknowledged = reduceResetControl(commandFirst.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
|
|
742
|
+
assert.equal(acknowledged.effect, "close-out-armed");
|
|
743
|
+
assert.deepEqual(acknowledged.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
|
|
744
|
+
const settled = reduceResetControl(acknowledged.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
745
|
+
assert.equal(settled.effect, "commit-boundary-stop");
|
|
746
|
+
assert.equal(settled.origin, "normal", "the command-first order records the same origin");
|
|
747
|
+
assert.equal(settled.lastWord, "tell them I was funny");
|
|
748
|
+
});
|
|
749
|
+
test("reset-control: the origin is the empty_brain call, independent of command policy", () => {
|
|
750
|
+
const windowId = "pcw:test:window";
|
|
751
|
+
const tool = reduceResetControl(initialResetControl(), { type: "tool_request", windowId });
|
|
752
|
+
assert.equal(reduceResetControl(tool.state, { type: "turn_end", facts: turnEndFacts() }).origin, "normal", "the model's own call is a normal reset");
|
|
753
|
+
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state;
|
|
754
|
+
assert.equal(reduceResetControl(manual, { type: "before_settle", facts: beforeSettleFacts() }).origin, "forced", "a command close-out with no call is a system reset");
|
|
755
|
+
const acknowledged = reduceResetControl(manual, { type: "tool_request", windowId }).state;
|
|
756
|
+
assert.equal(reduceResetControl(acknowledged, { type: "before_settle", facts: beforeSettleFacts() }).origin, "normal", "a manual close-out the model actually wipes is normal but still stops");
|
|
757
|
+
assert.equal(reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) }).origin, "forced", "the hard cutoff happens without a call");
|
|
758
|
+
const safety = reduceResetControl(acknowledged, { type: "turn_end", facts: turnEndFacts({ hardReserveDue: true }) });
|
|
759
|
+
assert.equal(safety.origin, "normal", "an acknowledged call survives the hard cutoff it was armed against");
|
|
760
|
+
assert.deepEqual(safety.state.request, { phase: "stop-pending", windowId, tool: {} }, "the recorded call survives into the run-scoped stop latch");
|
|
761
|
+
assert.equal(reduceResetControl(safety.state, { type: "before_settle", facts: beforeSettleFacts() }).origin, "normal", "a retried safety construction keeps the recorded origin");
|
|
762
|
+
const overflow = reduceResetControl(initialResetControl(), { type: "turn_end", facts: turnEndFacts({ overflow: true, failed: true }) }).state;
|
|
763
|
+
assert.equal(reduceResetControl(overflow, { type: "before_settle", facts: beforeSettleFacts() }).origin, "forced", "overflow recovery has no call behind it");
|
|
764
|
+
});
|
|
765
|
+
test("a committed reset records its origin and draws that pool exactly once", async () => {
|
|
766
|
+
const random = Math.random;
|
|
767
|
+
Math.random = () => 0;
|
|
768
|
+
try {
|
|
769
|
+
const asked = harness();
|
|
770
|
+
await asked.callTool("empty_brain");
|
|
771
|
+
const askedBoundary = resultEntries(await asked.emit("turn_end", fakeBoundaryEvent()));
|
|
772
|
+
const askedMarker = askedBoundary.entries.find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
773
|
+
assert.ok(askedMarker?.type === "custom");
|
|
774
|
+
assert.deepEqual(Object.keys(askedMarker.data), ["windowId", "origin"]);
|
|
775
|
+
assert.equal(askedMarker.data.origin, "normal");
|
|
776
|
+
const askedLine = askedBoundary.entries.find((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
777
|
+
assert.ok(askedLine?.type === "custom_message");
|
|
778
|
+
assert.equal(askedLine.content, NORMAL_CONTINUATIONS[0]);
|
|
779
|
+
const commanded = harness();
|
|
780
|
+
await commanded.runCommand("empty-brain");
|
|
781
|
+
const commandedBoundary = resultEntries(await commanded.emit("agent_before_settle", {
|
|
782
|
+
type: "agent_before_settle",
|
|
783
|
+
entries: [],
|
|
784
|
+
outcome: "completed",
|
|
785
|
+
context: { contextEntries: [], contextMessages: [], llmMessages: [], pendingMessages: [], canContinue: true },
|
|
786
|
+
}));
|
|
787
|
+
const commandedMarker = commandedBoundary.entries.find((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE);
|
|
788
|
+
assert.ok(commandedMarker?.type === "custom");
|
|
789
|
+
assert.equal(commandedMarker.data.origin, "forced", "the human's command is a system reset, not a model call");
|
|
790
|
+
const commandedLine = commandedBoundary.entries.find((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
791
|
+
assert.ok(commandedLine?.type === "custom_message");
|
|
792
|
+
assert.equal(commandedLine.content, FORCED_CONTINUATIONS[0]);
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
Math.random = random;
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
test("reset-control: a command retains tool calls with or without a last word and still stops at settlement", () => {
|
|
644
799
|
const windowId = "pcw:test:window";
|
|
645
|
-
const manual = reduceResetControl(initialResetControl(), { type: "
|
|
800
|
+
const manual = reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false });
|
|
646
801
|
const ack = reduceResetControl(manual.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
|
|
647
|
-
assert.equal(ack.effect, "
|
|
648
|
-
assert.deepEqual(ack.state.request, { phase: "
|
|
649
|
-
const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "
|
|
650
|
-
assert.deepEqual(silentAck.state.request, { phase: "
|
|
802
|
+
assert.equal(ack.effect, "close-out-armed", "the tool request is recorded independently of command policy");
|
|
803
|
+
assert.deepEqual(ack.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: { lastWord: "tell them I was funny" } });
|
|
804
|
+
const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "command", windowId, continueAfterReset: false }).state, { type: "tool_request", windowId });
|
|
805
|
+
assert.deepEqual(silentAck.state.request, { phase: "pending", windowId, command: { continueAfterReset: false }, tool: {} }, "a call with no last word is still a real tool request");
|
|
651
806
|
const commit = reduceResetControl(ack.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
652
807
|
assert.equal(commit.effect, "commit-boundary-stop");
|
|
653
808
|
assert.equal(commit.lastWord, "tell them I was funny");
|
package/docs/architecture.md
CHANGED
|
@@ -37,15 +37,15 @@ For the native dsh reset transaction, prompt ordering, capability checks and lim
|
|
|
37
37
|
|
|
38
38
|
`pi/reset/lifecycle.ts` is the sole `turn_end` composer: it accepts incoming drafts, drains budget-owned guidance/warning drafts, and appends a reset boundary for an explicit tool request or the hard-reserve safety path. Manual and budget close-outs stay armed across note/tool turns and commit from `agent_before_settle` after a successful stop with queued work drained; a manual close-out stops the run while a budget close-out continues in the fresh window. Repeated requests for the same window deduplicate. See [reset lifecycle](reset-lifecycle.md).
|
|
39
39
|
|
|
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.
|
|
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, origin: "normal" | "forced" }`, 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
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 `/fresh-window`
|
|
46
|
+
Manual `/fresh-window` stores command settlement policy and sends a hidden warning: idle commands start a model turn, running commands steer it. Tool requests are recorded independently and retained under that policy. A bare command settles and stops; a command with text settles and continues, with its text supplied only to the closing window. Budget warnings create no reset state: only an explicit tool request, hard reserve or bounded overflow recovery triggers a reset. Abort and ordinary errors do not count as successful settlement. Hard reserve preserves a bare command's stop in a run-scoped latch; `context_with_system` cancels only an empty tool-batch follow-up after confirming the committed boundary. Queued user input is answered before stopping. See [reset lifecycle](reset-lifecycle.md) for the state and recovery rules.
|
|
47
47
|
|
|
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
|
|
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 a brain-cleared notice 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
|
|
|
50
50
|
The Pi history adapter decodes the selected raw session branch on demand without a cache. It allocates stable seq values from the session's append-order entry list, then selects current-branch-only visibility, so navigation cannot expose a sibling's history. Shared history pairs and queries those decoded events; it neither traverses SessionReader nor reconstructs inference messages. The public stream combines each tool call with its result at the call seq; paired result slots are not public event addresses, and unpaired results retain their own seq. Summaries and injected messages project as `context`. List pages chronologically with seq anchors and an explicit `from`. Tool executions retain structured call/result facts and any native nested-call metadata. A deterministic event document supplies both query-match positions and read windows. Nested calls have no independent seq and never imply that unrecorded child outputs are available.
|
|
51
51
|
|
package/docs/claude-code-mod.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Claude Code Mod
|
|
2
2
|
|
|
3
|
-
The package also ships `mods/notesoup`, an early-access Claude Code Mod that registers
|
|
3
|
+
The package also ships `mods/notesoup`, an early-access Claude Code Mod that registers five notes tools as `mcp__notesoup__notes_*` and three history tools as `mcp__notesoup__history_*` and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `mods/notesoup/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
|
|
4
4
|
|
|
5
5
|
In interactive sessions it resets automatically when the measured context reaches notesoup's reset point, checking after `session.measure` and `turn.complete` and waiting for a running turn to complete. That point is derived from Claude's own auto-compact threshold instead of a fixed percent, in `src/claude/thresholds.ts`, and reaches the sandboxed hooks module through the helper's `limits` operation:
|
|
6
6
|
|
|
@@ -10,10 +10,22 @@ In interactive sessions it resets automatically when the measured context reache
|
|
|
10
10
|
|
|
11
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
|
|
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 answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected paragraph from the shared forced-reset pool, selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while `/compact` and precompute are vetoed with a one-line notice. `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`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
|
|
14
14
|
|
|
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.
|
|
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. A Claude dream backend is 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
|
|
|
19
|
+
## Persisted history
|
|
20
|
+
|
|
21
|
+
`history_list`, `history_read` and `history_windows` use the same schemas, literal search (`history_list.query`), paging, folding, pairing and text rendering as Pi. They read only the current main session's persisted JSONL, via the documented `classic.SessionStart.transcript_path`; no path is guessed and `$.session.messages()` is not treated as full history. The classic binding survives typed `session.start`, which fires later. Without that path, history calls refuse and the boot says history is unavailable. Subagent history calls refuse rather than silently exposing the main transcript.
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
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. 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. Known bookkeeping metadata is deliberately ignored; unknown message/block schemas and malformed committed JSONL lines refuse explicitly. An incomplete final unterminated write is tolerated. Valid forward parent references are resolved after reading the snapshot, without reallocating addresses.
|
|
26
|
+
|
|
27
|
+
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 boot: native compact boundaries advance the ordinal, and retained notesoup boot markers name that same ordinal rather than advancing it again. Preserved duplicate rows keep their original window; new children of their rewritten versions inherit the new window. `@previous` resolves through this oldest-first window list. A missing required ancestor is an explicit refusal.
|
|
28
|
+
|
|
29
|
+
## Validation
|
|
30
|
+
|
|
19
31
|
`npm run typecheck` includes the mod against the vendored Claude Code 2.1.295 contract. `npm test` also typechecks it and runs `claude plugin validate mods/notesoup --strict`, skipping validation with a clear message only if `claude` is not installed. Scanner regression tests deliberately reintroduce each of the three forbidden call shapes and require the gate to fail. From a built checkout, check the real load with `claude --plugin-dir mods/notesoup -p "ok"`; a model/API failure after load is separate from a hooks-module refusal. The package build and `npm pack --dry-run` include the manifests, hooks module, helper, skills, and playbook.
|
package/docs/dsh.md
CHANGED
|
@@ -18,7 +18,7 @@ The boot is a `systemPrompt.section` at order **2450**, with `interpolate: false
|
|
|
18
18
|
|
|
19
19
|
## Reset and budget
|
|
20
20
|
|
|
21
|
-
The engine owns the compaction transaction, rather than inheriting a summarizer. It validates the complete balanced surface span at positions **1..last**, acquires `compaction/start`, loads and mints the new notebook, writes `compaction/summary` and the replacement checkpoint synchronously, closes with `compaction/end`, then appends the window record. Node **0** stays host-owned. Nothing from the old conversation is retained on the surface. The checkpoint contains only the frozen boot and
|
|
21
|
+
The engine owns the compaction transaction, rather than inheriting a summarizer. It validates the complete balanced surface span at positions **1..last**, acquires `compaction/start`, loads and mints the new notebook, writes `compaction/summary` and the replacement checkpoint synchronously, closes with `compaction/end`, then appends the window record. Node **0** stays host-owned. Nothing from the old conversation is retained on the surface. The checkpoint contains only the frozen boot and a complete handoff paragraph, randomly selected once at reset creation. A model reset call selects the normal pool; other resets select the forced pool. The checkpoint and steered copy reuse the same paragraph. A one-message span can reset even when its replacement is larger.
|
|
22
22
|
|
|
23
23
|
Cancellation or a snapshot/checkpoint failure before replacement restores the old notebook. If replacement has already landed, it is authoritative even if closing or flushing fails; rolling back then would send stale boot text. An unmatched close keeps the durable lock until reload. A lost window record is recoverable from the checkpoint. Manual `compactNow` uses host maintenance and flushes through `ctx.sessions.flush`; the host `/compact` command, when installed, therefore uses this reset engine too.
|
|
24
24
|
|
|
@@ -34,7 +34,7 @@ warning = reserve + 16384
|
|
|
34
34
|
reminder = reserve + reminderMarginTokens
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining`
|
|
37
|
+
The defaults are `auto: true`, `thresholdRatio: 0.8`, `headroomTokens: 65536`, and `reminderMarginTokens: 24576`. For the example's **200000/8192/0.7/32768**, resetAt is **140000**, reserve **60000**, warning **76384** remaining, and reminder **84576** remaining. `get_context_remaining` and the numeric reminder report room to resetAt: physical remaining minus reserve, clamped at zero. The warning runway is included. Missing model capacity returns null. A profile with no positive reset budget fails with `BUDGET_CONFIG` and the numbers to fix. No independent percentage cutoff is added by notesoup.
|
|
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
|
|