notesoup 0.57.1 → 0.57.2

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.
@@ -25,6 +25,7 @@ export type ResetRequest = {
25
25
  };
26
26
  readonly tool?: {
27
27
  readonly lastWord?: string;
28
+ readonly terminate?: boolean;
28
29
  };
29
30
  };
30
31
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
@@ -68,6 +69,7 @@ export type ResetControlEvent = {
68
69
  readonly type: "tool_request";
69
70
  readonly windowId: string;
70
71
  readonly lastWord?: string;
72
+ readonly terminate?: boolean;
71
73
  } | {
72
74
  readonly type: "turn_end";
73
75
  readonly facts: ResetTurnEndFacts;
@@ -86,6 +88,7 @@ export interface ResetBoundaryIntent {
86
88
  readonly carryRunInputs?: boolean;
87
89
  readonly tool?: {
88
90
  readonly lastWord?: string;
91
+ readonly terminate?: boolean;
89
92
  };
90
93
  }
91
94
  export type ResetControlResult = ResetBoundaryIntent | {
@@ -112,7 +115,7 @@ export declare function reduceResetControl(state: ResetControlState, event: Rese
112
115
  */
113
116
  export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
114
117
  command(windowId: string, continueAfterReset: boolean, input?: CarriedInput): "none" | "stop" | "close-out-armed" | "already-pending";
115
- request(windowId: string, lastWord?: string): "rollover_already_pending" | "rollover_requested";
118
+ request(windowId: string, lastWord?: string, terminate?: boolean): "rollover_already_pending" | "rollover_requested";
116
119
  clear: (preserveInputs?: boolean) => void;
117
120
  };
118
121
  export {};
@@ -24,7 +24,7 @@ function requestForWindow(request, windowId) {
24
24
  const spendsOverflow = (boundary) => boundary === "command-overflow" || boundary === "overflow-recovery";
25
25
  function boundaryIntent(request, windowId, boundary, carryRunInputs = false) {
26
26
  const tool = request.phase === "none" ? undefined : request.tool;
27
- const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? true : true;
27
+ const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? !request.tool?.terminate : true;
28
28
  return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal", ...(carryRunInputs ? { carryRunInputs: true } : {}) };
29
29
  }
30
30
  /** Resolve once, after a successful current build. No delivery policy is left to the adapter. */
@@ -61,7 +61,10 @@ export function reduceResetControl(state, event) {
61
61
  // The call remains a real request even when command policy delays its commit.
62
62
  const duplicate = request.tool !== undefined;
63
63
  const lastWord = request.tool?.lastWord ?? event.lastWord;
64
- const tool = duplicate && !request.command ? request.tool : (lastWord ? { lastWord } : {});
64
+ const tool = duplicate && !request.command ? request.tool : {
65
+ ...(lastWord ? { lastWord } : {}),
66
+ ...((duplicate ? request.tool?.terminate : event.terminate) ? { terminate: true } : {}),
67
+ };
65
68
  return { state: { ...state, request: { ...request, tool } }, effect: duplicate ? "already-pending" : "close-out-armed" };
66
69
  }
67
70
  case "turn_end": {
@@ -318,8 +321,8 @@ export function registerResetLifecycle(pi, options) {
318
321
  control = decision.state;
319
322
  return decision.effect;
320
323
  },
321
- request(windowId, lastWord) {
322
- const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
324
+ request(windowId, lastWord, terminate = false) {
325
+ const decision = reduceResetControl(control, { type: "tool_request", windowId, terminate, ...(lastWord ? { lastWord } : {}) });
323
326
  control = decision.state;
324
327
  return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
325
328
  },
@@ -216,7 +216,10 @@ export function registerContext(pi, settingsManager) {
216
216
  name: "empty_brain",
217
217
  label: "Empty Brain",
218
218
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
219
- parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
219
+ parameters: Type.Object({
220
+ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })),
221
+ terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
222
+ }, { additionalProperties: false }),
220
223
  renderCall: emptyBrainRenderers.renderCall,
221
224
  renderResult: emptyBrainRenderers.renderResult,
222
225
  async execute(_id, params, _signal, _update, ctx) {
@@ -226,7 +229,7 @@ export function registerContext(pi, settingsManager) {
226
229
  const length = lastWord ? Array.from(lastWord).length : 0;
227
230
  if (length > MAX_LAST_WORD_CHARS)
228
231
  return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
229
- return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
232
+ return output({ status: resets.request(currentWindowId(ctx), lastWord, params.terminate) }, undefined, true);
230
233
  },
231
234
  }));
232
235
  const resets = registerResetLifecycle(pi, {
@@ -6,7 +6,7 @@ import test from "node:test";
6
6
  import { createAssistantMessageEventStream, getCurrentSystemMessage } from "@earendil-works/pi-ai";
7
7
  import { createAgentSession, createCodemodeExtension, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
8
8
  import notesoup, { createNotesoup } from "../plugins/pi/extension.js";
9
- import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
9
+ import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
10
10
  import { historyFromSession } from "../plugins/pi/history.js";
11
11
  import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
12
12
  import { assertBootHistory } from "./helpers/extension.js";
@@ -550,6 +550,35 @@ test("real AgentSession: explicit tiny-session wipe ignores keepRecentTokens and
550
550
  fixture.close();
551
551
  }
552
552
  });
553
+ test("real AgentSession: terminate wipes and stops, including a mixed tool batch, without closing the session", async () => {
554
+ for (const mixedBatch of [false, true]) {
555
+ let fixture;
556
+ fixture = await openFixture({
557
+ compactionEnabled: false,
558
+ script: (request) => request === 1
559
+ ? assistant(fixture, [
560
+ { type: "toolCall", id: "wipe-stop", name: "empty_brain", arguments: { terminate: true, last_word: "saved for later" } },
561
+ ...(mixedBatch ? [{ type: "toolCall", id: "remaining", name: "get_context_remaining", arguments: {} }] : []),
562
+ ], "toolUse")
563
+ : assistant(fixture, [{ type: "text", text: "answering new input" }]),
564
+ });
565
+ try {
566
+ await fixture.session.prompt("TERMINATE_OLD_CONTEXT");
567
+ await fixture.session.waitForIdle();
568
+ assert.equal(fixture.requests.length, 1, "no automatic provider request after wiping");
569
+ assert.equal(resetMarkers(fixture).length, 1);
570
+ assert.ok(fixture.sessionManager.getBranch().some((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE));
571
+ await fixture.session.prompt("A new task");
572
+ await fixture.session.waitForIdle();
573
+ assert.equal(fixture.requests.length, 2, "new user input still runs");
574
+ assertFreshRequest(fixture, 1, "TERMINATE_OLD_CONTEXT");
575
+ assert.ok(text(fixture.requests[1]).includes("saved for later"));
576
+ }
577
+ finally {
578
+ fixture.close();
579
+ }
580
+ }
581
+ });
553
582
  test("real AgentSession: a model-requested reset does not carry its original text-and-image prompt", async () => {
554
583
  let fixture;
555
584
  const input = "IMAGE_RESET_UNANSWERED: describe this image";
@@ -168,6 +168,20 @@ function fakeBoundaryEvent(entries = [], message) {
168
168
  toolResultEntryIds: [],
169
169
  };
170
170
  }
171
+ test("tool continuation defaults to true, preserves the first request, and yields to command policy", () => {
172
+ const windowId = "pcw:test:window";
173
+ for (const terminate of [undefined, false, true]) {
174
+ const requested = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, terminate }).state;
175
+ const duplicate = reduceResetControl(requested, { type: "tool_request", windowId, terminate: !terminate }).state;
176
+ const intent = boundaryIntent(reduceResetControl(duplicate, { type: "turn_end", facts: turnEndFacts() }));
177
+ assert.equal(finalizeResetBoundary(intent, duplicate.request).resumeModel, !terminate);
178
+ const commanded = reduceResetControl(requested, { type: "command", windowId, continueAfterReset: false }).state;
179
+ const commandIntent = boundaryIntent(reduceResetControl(commanded, { type: "before_settle", facts: beforeSettleFacts() }));
180
+ assert.equal(finalizeResetBoundary(commandIntent, commanded.request).resumeModel, false);
181
+ const withInput = reduceResetControl(commanded, { type: "input", windowId, input: "new task" }).state;
182
+ assert.equal(finalizeResetBoundary(commandIntent, withInput.request).resumeModel, true);
183
+ }
184
+ });
171
185
  test("public reset boundary drafts one marker, one boot, and one continuation after a tool batch", async () => {
172
186
  const h = harness();
173
187
  h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
@@ -8,7 +8,7 @@ Pi reset control lives in `plugins/pi/reset/lifecycle.ts`: the pure `reduceReset
8
8
 
9
9
  | Trigger | Behavior |
10
10
  | --- | --- |
11
- | `empty_brain` tool | Record the actual call and optional last word. Without command policy, reset after the whole tool batch at `turn_end` and continue. Under command policy, wait for settlement. |
11
+ | `empty_brain` tool | Record the actual call and optional last word. Without command policy, reset after the whole tool batch at `turn_end` and continue unless `terminate: true` (default: false). Termination stops automatic continuation, not the session or new user input. Under command policy, wait for settlement. |
12
12
  | `/empty <text>` or `/fresh-window <text>` | Send a hidden close-out warning (trigger when idle, steer when busy), with the argument verbatim as context for notes, then reset and stop unless separate human input arrives during emptying. |
13
13
  | Bare `/empty` or `/fresh-window` | Close out, reset, and stop, unless more human input arrives while close-out is pending. |
14
14
  | Human input during command close-out | Intercept public `input` events except source `extension`, return `handled`, and keep the original text/images in command state for the reset boundary. Do not steer the input into the closing model; use `/empty <text>` for close-out context. |
@@ -46,7 +46,7 @@ Raw session history remains available. The retain-none checkpoint excludes old c
46
46
  | Request | Meaning |
47
47
  | --- | --- |
48
48
  | `none` | No command or tool request. |
49
- | `pending` | Current `windowId`, optional `tool: { lastWord? }`, and optional `command: { continueAfterReset, inputs? }`. Command inputs retain their original text/images. Separate human input during close-out is intercepted and carried, never steered. Duplicate commands retain the first policy/text; tool calls do not overwrite command policy. |
49
+ | `pending` | Current `windowId`, optional `tool: { lastWord?, terminate? }`, and optional `command: { continueAfterReset, inputs? }`. Command inputs retain their original text/images. Separate human input during close-out is intercepted and carried, never steered. Duplicate commands retain the first policy/text; tool calls do not overwrite command policy. |
50
50
 
51
51
  `stopAfterReset` is separate from the request. It retains the safety boundary's intent after construction, while `request` becomes `none`. Settlement waits for queued work; if the window changed, it stops without a second wipe. If the window did not change, the boundary never committed, so settlement retries the retained intent with its stop policy and tool origin intact. A successful settle retry consumes the latch.
52
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.57.1",
3
+ "version": "0.57.2",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.57.1",
3
+ "version": "0.57.2",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"
@@ -38,7 +38,7 @@ export type ResetRequest =
38
38
  | { readonly phase: "none" }
39
39
  | { readonly phase: "pending"; readonly windowId: string;
40
40
  readonly command?: { readonly continueAfterReset: boolean; readonly inputs?: readonly CarriedInput[] };
41
- readonly tool?: { readonly lastWord?: string } };
41
+ readonly tool?: { readonly lastWord?: string; readonly terminate?: boolean } };
42
42
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
43
43
 
44
44
  export interface ResetControlState {
@@ -79,7 +79,7 @@ export interface ResetBeforeSettleFacts {
79
79
  export type ResetControlEvent =
80
80
  | { readonly type: "command"; readonly windowId: string; readonly continueAfterReset: boolean; readonly input?: CarriedInput }
81
81
  | { readonly type: "input"; readonly windowId: string; readonly input: CarriedInput }
82
- | { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string }
82
+ | { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string; readonly terminate?: boolean }
83
83
  | { readonly type: "turn_end"; readonly facts: ResetTurnEndFacts }
84
84
  | { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts };
85
85
 
@@ -92,7 +92,7 @@ export interface ResetBoundaryIntent {
92
92
  readonly continueAfterReset: boolean;
93
93
  readonly origin: ResetOrigin;
94
94
  readonly carryRunInputs?: boolean;
95
- readonly tool?: { readonly lastWord?: string };
95
+ readonly tool?: { readonly lastWord?: string; readonly terminate?: boolean };
96
96
  }
97
97
 
98
98
  export type ResetControlResult = ResetBoundaryIntent |
@@ -106,7 +106,7 @@ const spendsOverflow = (boundary: ResetBoundaryIntent["boundary"]) => boundary =
106
106
 
107
107
  function boundaryIntent(request: ResetRequest, windowId: string, boundary: ResetBoundaryIntent["boundary"], carryRunInputs = false): ResetBoundaryIntent {
108
108
  const tool = request.phase === "none" ? undefined : request.tool;
109
- const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? true : true;
109
+ const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? !request.tool?.terminate : true;
110
110
  return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal", ...(carryRunInputs ? { carryRunInputs: true } : {}) };
111
111
  }
112
112
 
@@ -145,7 +145,10 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
145
145
  // The call remains a real request even when command policy delays its commit.
146
146
  const duplicate = request.tool !== undefined;
147
147
  const lastWord = request.tool?.lastWord ?? event.lastWord;
148
- const tool = duplicate && !request.command ? request.tool : (lastWord ? { lastWord } : {});
148
+ const tool = duplicate && !request.command ? request.tool : {
149
+ ...(lastWord ? { lastWord } : {}),
150
+ ...((duplicate ? request.tool?.terminate : event.terminate) ? { terminate: true } : {}),
151
+ };
149
152
  return { state: { ...state, request: { ...request, tool } }, effect: duplicate ? "already-pending" : "close-out-armed" };
150
153
  }
151
154
  case "turn_end": {
@@ -377,8 +380,8 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
377
380
  control = decision.state;
378
381
  return decision.effect;
379
382
  },
380
- request(windowId: string, lastWord?: string) {
381
- const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
383
+ request(windowId: string, lastWord?: string, terminate = false) {
384
+ const decision = reduceResetControl(control, { type: "tool_request", windowId, terminate, ...(lastWord ? { lastWord } : {}) });
382
385
  control = decision.state;
383
386
  return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
384
387
  },
@@ -211,7 +211,10 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
211
211
  name: "empty_brain",
212
212
  label: "Empty Brain",
213
213
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
214
- parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
214
+ parameters: Type.Object({
215
+ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })),
216
+ terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
217
+ }, { additionalProperties: false }),
215
218
  renderCall: emptyBrainRenderers.renderCall,
216
219
  renderResult: emptyBrainRenderers.renderResult,
217
220
  async execute(_id, params, _signal, _update, ctx) {
@@ -219,7 +222,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
219
222
  const lastWord = sanitizeLastWord(params.last_word);
220
223
  const length = lastWord ? Array.from(lastWord).length : 0;
221
224
  if (length > MAX_LAST_WORD_CHARS) return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
222
- return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
225
+ return output({ status: resets.request(currentWindowId(ctx), lastWord, params.terminate) }, undefined, true);
223
226
  },
224
227
  }));
225
228