notesoup 0.45.1 → 0.45.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.45.1",
3
+ "version": "0.45.2",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -15,8 +15,11 @@ export const WARNING_BODY =
15
15
 
16
16
  export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
17
17
 
18
- /** The shared hidden checkpoint text: one manual/budget-triggered request, both hosts. */
19
- export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${GUIDANCE_CLOSE_TAG}`;
18
+ /** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
19
+ export const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
20
+
21
+ /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
22
+ export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
20
23
 
21
24
  /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
22
25
  export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
package/src/pi/entries.ts CHANGED
@@ -5,3 +5,4 @@ export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
5
  export const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
6
  export const CONTINUATION_TYPE = "notesoup/continuation";
7
7
  export const RESET_PROMPT_TYPE = "notesoup/reset-prompt";
8
+ export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
@@ -1,12 +1,23 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
3
- import { BOOT_TYPE, CONTINUATION_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
3
+ import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
4
4
  import { CONTINUATION } from "../../budget/text.js";
5
5
  import { currentWindowId, isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, previousWindowId, type WindowMarker } from "../window.js";
6
6
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "../boot.js";
7
7
 
8
8
  export type ResetTailState = { readonly boot: boolean; readonly continuation: boolean };
9
9
 
10
+ /** Cap for the parting line: one visible line, not an essay. */
11
+ export const MAX_LAST_WORD_CHARS = 500;
12
+
13
+ /** Trim and cap a parting line; blank input leaves no last word. */
14
+ export function sanitizeLastWord(raw: string | undefined): string | undefined {
15
+ const trimmed = raw?.trim();
16
+ if (!trimmed) return undefined;
17
+ const chars = Array.from(trimmed);
18
+ return chars.length > MAX_LAST_WORD_CHARS ? `${chars.slice(0, MAX_LAST_WORD_CHARS).join("")}…` : trimmed;
19
+ }
20
+
10
21
  /** Match the hidden continuation entry that carries the one reset message. */
11
22
  export function isWindowContinuationEntry(entry: SessionEntry): boolean {
12
23
  return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
@@ -22,13 +33,14 @@ function sendContinuation(pi: ExtensionAPI): void {
22
33
 
23
34
  /**
24
35
  * The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
25
- * continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
36
+ * continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
26
37
  */
27
38
  export async function buildResetDrafts(
28
39
  ctx: ExtensionContext,
29
40
  notifyIncompleteNotes?: IncompleteNotesNotifier,
30
41
  isCurrent: () => boolean = () => true,
31
42
  prompt?: string,
43
+ lastWord?: string,
32
44
  ): Promise<SessionBoundaryDraft[]> {
33
45
  const sessionId = ctx.sessionManager.getSessionId();
34
46
  const previousId = currentWindowId(ctx);
@@ -46,6 +58,7 @@ export async function buildResetDrafts(
46
58
  { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
47
59
  { type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
48
60
  { type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
61
+ ...(lastWord ? [{ type: "custom_message" as const, customType: RESET_LAST_WORD_TYPE, content: lastWord, display: true }] : []),
49
62
  ...(prompt ? [{ type: "custom_message" as const, customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
50
63
  ];
51
64
  }
@@ -15,7 +15,7 @@ type BudgetOwner = {
15
15
  type ResetOptions = {
16
16
  isEnabled: () => boolean;
17
17
  budget: BudgetOwner;
18
- buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
18
+ buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string, lastWord?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
19
19
  getLifecycleGeneration?: () => number;
20
20
  onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
21
21
  };
@@ -37,8 +37,8 @@ export type ResetRequest =
37
37
  // The safety reset may change windows before Pi finishes its tool-batch continuation.
38
38
  // This run-scoped stop intent survives that change; windowId is the pre-reset window.
39
39
  | { readonly phase: "stop-pending"; readonly windowId: string }
40
- | { readonly phase: "close-out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string }
41
- | { readonly phase: "tool-requested"; readonly windowId: string; readonly source: ToolResetRequestSource };
40
+ | { readonly phase: "close-out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string; readonly lastWord?: string }
41
+ | { readonly phase: "tool-requested"; readonly windowId: string; readonly source: ToolResetRequestSource; readonly lastWord?: string };
42
42
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
43
43
 
44
44
  export interface ResetControlState {
@@ -76,7 +76,7 @@ export interface ResetBeforeSettleFacts {
76
76
 
77
77
  export type ResetControlEvent =
78
78
  | { readonly type: "close_out"; readonly windowId: string; readonly source: ResetRequestSource; readonly prompt?: string }
79
- | { readonly type: "tool_request"; readonly windowId: string }
79
+ | { readonly type: "tool_request"; readonly windowId: string; readonly lastWord?: string }
80
80
  | { readonly type: "turn_end"; readonly facts: ResetTurnEndFacts }
81
81
  | { readonly type: "before_settle"; readonly facts: ResetBeforeSettleFacts }
82
82
  | { readonly type: "settled" }
@@ -96,16 +96,23 @@ export interface ResetControlResult {
96
96
  readonly state: ResetControlState;
97
97
  readonly effect: ResetControlEffect;
98
98
  readonly prompt?: string;
99
+ readonly lastWord?: string;
99
100
  }
100
101
 
101
102
  function requestForWindow(request: ResetRequest, windowId: string): ResetRequest {
102
103
  return request.phase === "stop-pending" || (request.phase !== "none" && request.windowId === windowId) ? request : NO_REQUEST;
103
104
  }
104
105
 
105
- function manualCommit(prompt?: string): ResetControlResult {
106
+ function manualCommit(prompt?: string, lastWord?: string): ResetControlResult {
107
+ const parting = lastWord ? { lastWord } : {};
106
108
  return prompt
107
- ? { state: initialResetControl(), effect: "commit-boundary", prompt }
108
- : { state: initialResetControl(), effect: "commit-boundary-stop" };
109
+ ? { state: initialResetControl(), effect: "commit-boundary", prompt, ...parting }
110
+ : { state: initialResetControl(), effect: "commit-boundary-stop", ...parting };
111
+ }
112
+
113
+ /** The parting line rides either committing phase; other phases never carry one. */
114
+ function requestLastWord(request: ResetRequest): string | undefined {
115
+ return request.phase === "close-out" || request.phase === "tool-requested" ? request.lastWord : undefined;
109
116
  }
110
117
 
111
118
  /** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
@@ -134,15 +141,20 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
134
141
  if (request.phase === "tool-requested" && request.windowId === event.windowId) {
135
142
  return { state, effect: "already-pending" };
136
143
  }
144
+ const parting = event.lastWord ? { lastWord: event.lastWord } : {};
137
145
  // A manual close-out must settle so the stop actually lands; the agent's own wipe
138
146
  // call during one is only an acknowledgement, never a conversion to a turn-end
139
147
  // commit that pi's tool-batch continuation can overrun. A budget close-out still
140
148
  // upgrades: context pressure cannot wait for settlement.
141
149
  if (request.phase === "close-out" && request.windowId === event.windowId) {
142
- if (request.source === "manual") return { state, effect: "already-pending" };
143
- return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "automatic" } }, effect: "close-out-armed" };
150
+ // The acknowledging call still contributes its last word; the manual commit keeps the wheel.
151
+ if (request.source === "manual") {
152
+ const lastWord = request.lastWord ?? event.lastWord;
153
+ return { state: { ...state, request: { ...request, ...(lastWord ? { lastWord } : {}) } }, effect: "already-pending" };
154
+ }
155
+ return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "automatic", ...parting } }, effect: "close-out-armed" };
144
156
  }
145
- return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool" } }, effect: "close-out-armed" };
157
+ return { state: { ...state, request: { phase: "tool-requested", windowId: event.windowId, source: "tool", ...parting } }, effect: "close-out-armed" };
146
158
  }
147
159
  case "turn_end": {
148
160
  const facts = event.facts;
@@ -165,9 +177,10 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
165
177
  // A direct tool request commits after the whole tool batch. The budget cutoff is
166
178
  // a separate hard-reserve safety path; ordinary close-out waits for settlement.
167
179
  if (request.phase === "tool-requested" || facts.hardReserveDue) {
168
- if (manual && request.prompt) return manualCommit(request.prompt);
169
- if (manual) return { state: { request: { phase: "stop-pending", windowId: facts.windowId }, overflow: "idle" }, effect: "commit-boundary-stop" };
170
- return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary" };
180
+ const lastWord = requestLastWord(request);
181
+ if (manual && request.prompt) return manualCommit(request.prompt, lastWord);
182
+ if (manual) return { state: { request: { phase: "stop-pending", windowId: facts.windowId }, overflow: "idle" }, effect: "commit-boundary-stop", ...(lastWord ? { lastWord } : {}) };
183
+ return { state: { request: NO_REQUEST, overflow: "idle" }, effect: "commit-boundary", ...(lastWord ? { lastWord } : {}) };
171
184
  }
172
185
  return { state: { request, overflow: "idle" }, effect: "none" };
173
186
  }
@@ -189,7 +202,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
189
202
  }
190
203
  // An explicit manual wipe is not an automatic recovery/retry. It must still
191
204
  // clear on overflow, including when automatic reset is disabled.
192
- if (manual && facts.enabled) return manualCommit(request.prompt);
205
+ if (manual && facts.enabled) return manualCommit(request.prompt, requestLastWord(request));
193
206
  const spent = state.overflow === "pending-spent";
194
207
  if (!facts.enabled || !facts.automaticResetEnabled) {
195
208
  return { state: { request: facts.failed ? NO_REQUEST : request, overflow: spent ? "spent" : "idle" }, effect: "none" };
@@ -200,7 +213,7 @@ export function reduceResetControl(state: ResetControlState, event: ResetControl
200
213
  return { state: { ...state, request: NO_REQUEST }, effect: "none" };
201
214
  }
202
215
  if (facts.queued) return { state: { ...state, request }, effect: "none" };
203
- return manualCommit(request.prompt);
216
+ return manualCommit(request.prompt, requestLastWord(request));
204
217
  }
205
218
  case "settled":
206
219
  return { state: initialResetControl(), effect: "none" };
@@ -225,7 +238,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
225
238
  let control = initialResetControl();
226
239
 
227
240
  const clear = () => { control = reduceResetControl(control, { type: "clear" }).state; };
228
- const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, continueAfterReset: boolean, prompt?: string) => {
241
+ const resetBoundaryResult = async (entries: SessionBoundaryDraft[], ctx: ExtensionContext, continueAfterReset: boolean, prompt?: string, lastWord?: string) => {
229
242
  const generation = lifecycleGeneration;
230
243
  const outerGeneration = options.getLifecycleGeneration?.();
231
244
  const sessionId = ctx.sessionManager.getSessionId();
@@ -235,7 +248,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
235
248
  ctx.signal?.aborted !== true && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
236
249
  let resetDrafts: SessionBoundaryDraft[];
237
250
  try {
238
- resetDrafts = await options.buildReset(ctx, isCurrent, prompt);
251
+ resetDrafts = await options.buildReset(ctx, isCurrent, prompt, lastWord);
239
252
  } catch (error) {
240
253
  if (isCurrent()) ctx.ui.notify(`🥣 Couldn't clear memory: ${errorMessage(error)}${prompt ? " · your prompt was not sent" : ""}`, "warning");
241
254
  return entries.length > 0 ? { entries } : undefined;
@@ -281,7 +294,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
281
294
  },
282
295
  });
283
296
  control = decision.state;
284
- if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt);
297
+ if (decision.effect === "commit-boundary" || decision.effect === "commit-boundary-stop") return await resetBoundaryResult(entries, ctx, decision.effect === "commit-boundary", decision.prompt, decision.lastWord);
285
298
  return entries.length > 0 ? { entries } : undefined;
286
299
  });
287
300
 
@@ -301,7 +314,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
301
314
  control = decision.state;
302
315
  if (decision.effect === "stop") return { entries: event.entries, continue: false };
303
316
  if (decision.effect !== "commit-boundary" && decision.effect !== "commit-boundary-stop" && decision.effect !== "recover-overflow") return undefined;
304
- return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt);
317
+ return await resetBoundaryResult(event.entries, ctx, decision.effect !== "commit-boundary-stop", decision.prompt, decision.lastWord);
305
318
  });
306
319
 
307
320
  pi.on("session_before_compact", (event, ctx) => {
@@ -333,8 +346,8 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
333
346
  control = decision.state;
334
347
  return decision.effect;
335
348
  },
336
- request(windowId: string) {
337
- const decision = reduceResetControl(control, { type: "tool_request", windowId });
349
+ request(windowId: string, lastWord?: string) {
350
+ const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
338
351
  control = decision.state;
339
352
  return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
340
353
  },
package/src/pi/runtime.ts CHANGED
@@ -6,7 +6,7 @@ import { registerBudget } from "./budget.js";
6
6
  import { output } from "./tool-result.js";
7
7
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
8
8
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
- import { buildResetDrafts, repairResetTail } from "./reset/artifacts.js";
9
+ import { buildResetDrafts, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
10
10
  import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
11
11
  import { WARNING_CONTENT } from "../budget/text.js";
12
12
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
@@ -201,17 +201,17 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
201
201
  pi.registerTool(defineTool({
202
202
  name: "clear_memory",
203
203
  label: "Clear memory",
204
- description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive.",
205
- parameters: Type.Object({}, { additionalProperties: false }),
206
- async execute(_id, _params, _signal, _update, ctx) {
204
+ description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to leave one short visible line where this window closes.",
205
+ parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: "A parting line shown where this window closes; the next window can read it too." })) }, { additionalProperties: false }),
206
+ async execute(_id, params, _signal, _update, ctx) {
207
207
  if (!enabled) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
208
- return output({ status: resets.request(currentWindowId(ctx)) }, undefined, true);
208
+ return output({ status: resets.request(currentWindowId(ctx), sanitizeLastWord(params.last_word)) }, undefined, true);
209
209
  },
210
210
  }));
211
211
 
212
212
  const resets = registerResetLifecycle(pi, {
213
213
  isEnabled: () => enabled,
214
- buildReset: (ctx, isCurrent, prompt) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt),
214
+ buildReset: (ctx, isCurrent, prompt, lastWord) => buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent, prompt, lastWord),
215
215
  getLifecycleGeneration: () => lifecycleGeneration,
216
216
  onResetReady: (_ctx, drafts) => {
217
217
  const boot = drafts.find((draft) => draft.type === "custom_message" && draft.customType === BOOT_TYPE);