notesoup 0.57.1 → 0.57.3

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.
@@ -1,3 +1,4 @@
1
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
1
2
  import { Type } from "@earendil-works/pi-ai";
2
3
  import { type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
3
4
  export declare const ContextRemainingOutputSchema: Type.TObject<{
@@ -5,7 +6,7 @@ export declare const ContextRemainingOutputSchema: Type.TObject<{
5
6
  }>;
6
7
  export declare function registerBudget(pi: ExtensionAPI, isEnabled: () => boolean, settingsManager?: SettingsManager): {
7
8
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
8
- hardReserveDue: (ctx: ExtensionContext) => boolean;
9
+ hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
9
10
  consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
10
11
  /** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
11
12
  statusFor: (ctx: ExtensionContext) => {
@@ -1,8 +1,9 @@
1
1
  import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
2
2
  import { remainingBudget } from "../../src/budget/policy.js";
3
3
  import { Type } from "@earendil-works/pi-ai";
4
- import { defineTool } from "@earendil-works/pi-coding-agent";
4
+ import { convertToLlm, defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
6
+ import { estimateContextTokens } from "./estimate.js";
6
7
  import { warningContent } from "./text.js";
7
8
  import { readThresholdSettings } from "./thresholds.js";
8
9
  import { currentWindowId, hasWindowMessage, windowUsage } from "./window.js";
@@ -36,9 +37,19 @@ export function registerBudget(pi, isEnabled, settingsManager) {
36
37
  };
37
38
  const thresholdsFor = (ctx) => resolvePolicy(ctx).thresholds;
38
39
  const automaticResetEnabled = (ctx) => resolvePolicy(ctx).automatic;
39
- const hardReserveDue = (ctx) => {
40
+ const hardReserveDue = (ctx, preSendMessages) => {
40
41
  if (!automaticResetEnabled(ctx))
41
42
  return false;
43
+ if (preSendMessages) {
44
+ const contextWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
45
+ if (!contextWindow || contextWindow <= 0)
46
+ return false;
47
+ const { reserve } = thresholdsFor(ctx);
48
+ const estimate = estimateContextTokens(convertToLlm(preSendMessages));
49
+ if (estimate.lastUsageIndex !== null && contextWindow - estimate.usageTokens <= reserve)
50
+ return false;
51
+ return contextWindow - estimate.tokens <= reserve;
52
+ }
42
53
  const usage = windowUsage(ctx);
43
54
  return usage !== undefined && usage.tokens !== null && usage.contextWindow - usage.tokens <= thresholdsFor(ctx).reserve;
44
55
  };
@@ -1,9 +1,10 @@
1
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
1
2
  import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
2
3
  import type { ResetOrigin } from "../../../src/budget/text.js";
3
4
  import { type CarriedInput } from "./artifacts.js";
4
5
  type BudgetOwner = {
5
6
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
6
- hardReserveDue: (ctx: ExtensionContext) => boolean;
7
+ hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
7
8
  consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
8
9
  clear: () => void;
9
10
  };
@@ -25,6 +26,7 @@ export type ResetRequest = {
25
26
  };
26
27
  readonly tool?: {
27
28
  readonly lastWord?: string;
29
+ readonly terminate?: boolean;
28
30
  };
29
31
  };
30
32
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
@@ -68,6 +70,7 @@ export type ResetControlEvent = {
68
70
  readonly type: "tool_request";
69
71
  readonly windowId: string;
70
72
  readonly lastWord?: string;
73
+ readonly terminate?: boolean;
71
74
  } | {
72
75
  readonly type: "turn_end";
73
76
  readonly facts: ResetTurnEndFacts;
@@ -75,25 +78,25 @@ export type ResetControlEvent = {
75
78
  readonly type: "before_settle";
76
79
  readonly facts: ResetBeforeSettleFacts;
77
80
  };
78
- /** Construction intent, not final state: handled inputs can still arrive while notes load. Only `turn-end`
79
- * may latch a stop; overflow kinds spend recovery; only hard-reserve and overflow carry passive run inputs. */
81
+ /** Construction intent, not final state: handled inputs can still arrive while notes load.
82
+ * Only `turn-end` may latch a stop; overflow kinds spend recovery. */
80
83
  export interface ResetBoundaryIntent {
81
84
  readonly effect: "build-boundary";
82
85
  readonly boundary: "turn-end" | "settle" | "command-overflow" | "overflow-recovery";
83
86
  readonly windowId: string;
84
87
  readonly continueAfterReset: boolean;
85
88
  readonly origin: ResetOrigin;
86
- 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 | {
92
95
  readonly state: ResetControlState;
93
96
  readonly effect: "none" | "close-out-armed" | "already-pending" | "stop";
94
97
  };
95
- /** Resolve once, after a successful current build. No delivery policy is left to the adapter. */
96
- export declare function finalizeResetBoundary(intent: ResetBoundaryIntent, request: ResetRequest, passiveInputs?: readonly CarriedInput[]): {
98
+ /** Resolve once, after a successful current build. Only inputs withheld from the closing model cross the reset. */
99
+ export declare function finalizeResetBoundary(intent: ResetBoundaryIntent, request: ResetRequest): {
97
100
  state: ResetControlState;
98
101
  inputs: readonly (string | (import("@earendil-works/pi-ai").TextContent | import("@earendil-works/pi-ai").ImageContent)[])[];
99
102
  resumeModel: boolean;
@@ -112,7 +115,8 @@ 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";
119
+ hasPendingTrigger: () => boolean;
116
120
  clear: (preserveInputs?: boolean) => void;
117
121
  };
118
122
  export {};
@@ -22,15 +22,14 @@ function requestForWindow(request, windowId) {
22
22
  return request.phase === "pending" && request.windowId === windowId ? request : NO_REQUEST;
23
23
  }
24
24
  const spendsOverflow = (boundary) => boundary === "command-overflow" || boundary === "overflow-recovery";
25
- function boundaryIntent(request, windowId, boundary, carryRunInputs = false) {
25
+ function boundaryIntent(request, windowId, boundary) {
26
26
  const tool = request.phase === "none" ? undefined : request.tool;
27
- const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? true : true;
28
- return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal", ...(carryRunInputs ? { carryRunInputs: true } : {}) };
27
+ const continueAfterReset = request.phase === "pending" ? request.command?.continueAfterReset ?? !request.tool?.terminate : true;
28
+ return { effect: "build-boundary", boundary, windowId, tool, continueAfterReset, origin: spendsOverflow(boundary) || !tool ? "forced" : "normal" };
29
29
  }
30
- /** Resolve once, after a successful current build. No delivery policy is left to the adapter. */
31
- export function finalizeResetBoundary(intent, request, passiveInputs = []) {
32
- const inputs = request.phase === "pending" && request.command ? request.command.inputs ?? []
33
- : intent.boundary === "overflow-recovery" || intent.carryRunInputs ? passiveInputs : [];
30
+ /** Resolve once, after a successful current build. Only inputs withheld from the closing model cross the reset. */
31
+ export function finalizeResetBoundary(intent, request) {
32
+ const inputs = request.phase === "pending" ? request.command?.inputs ?? [] : [];
34
33
  const resumeModel = intent.continueAfterReset || inputs.length > 0;
35
34
  const state = {
36
35
  request: NO_REQUEST,
@@ -61,7 +60,10 @@ export function reduceResetControl(state, event) {
61
60
  // The call remains a real request even when command policy delays its commit.
62
61
  const duplicate = request.tool !== undefined;
63
62
  const lastWord = request.tool?.lastWord ?? event.lastWord;
64
- const tool = duplicate && !request.command ? request.tool : (lastWord ? { lastWord } : {});
63
+ const tool = duplicate && !request.command ? request.tool : {
64
+ ...(lastWord ? { lastWord } : {}),
65
+ ...((duplicate ? request.tool?.terminate : event.terminate) ? { terminate: true } : {}),
66
+ };
65
67
  return { state: { ...state, request: { ...request, tool } }, effect: duplicate ? "already-pending" : "close-out-armed" };
66
68
  }
67
69
  case "turn_end": {
@@ -89,7 +91,7 @@ export function reduceResetControl(state, event) {
89
91
  // a separate hard-reserve safety path; ordinary close-out waits for settlement.
90
92
  const toolReset = request.phase === "pending" && request.tool !== undefined;
91
93
  if ((toolReset && !manual) || facts.hardReserveDue) {
92
- return boundaryIntent(request, facts.windowId, "turn-end", !manual && !toolReset && facts.hardReserveDue);
94
+ return boundaryIntent(request, facts.windowId, "turn-end");
93
95
  }
94
96
  return { state: { request, overflow: "idle" }, effect: "none" };
95
97
  }
@@ -143,7 +145,8 @@ export function registerResetLifecycle(pi, options) {
143
145
  let sessionActive = true;
144
146
  let lifecycleGeneration = 0;
145
147
  let control = initialResetControl();
146
- let runInputs = [];
148
+ let preSendHardReserveWindowId;
149
+ let pendingPreSendTrigger;
147
150
  // Once input returns handled, Pi no longer owns its original content. If close-out
148
151
  // fails/cancels, restore it; only an ordinary error starts a turn to answer it.
149
152
  const restoreCommandInputs = (triggerTurn = false) => {
@@ -155,16 +158,16 @@ export function registerResetLifecycle(pi, options) {
155
158
  for (const draft of carriedInputDrafts(inputs)) {
156
159
  pi.sendMessage(draft, { triggerTurn });
157
160
  }
158
- runInputs.push(...inputs);
159
161
  };
160
162
  const clear = (preserveInputs = true) => {
161
163
  lifecycleGeneration++;
164
+ preSendHardReserveWindowId = undefined;
165
+ pendingPreSendTrigger = undefined;
162
166
  if (preserveInputs)
163
167
  restoreCommandInputs();
164
168
  control = initialResetControl();
165
- runInputs = [];
166
169
  };
167
- const resetBoundaryResult = async (entries, ctx, intent) => {
170
+ const resetBoundaryResult = async (entries, ctx, intent, preSendHardReserve = false) => {
168
171
  // Keep command state live while notes load so input arriving during this await joins this boundary.
169
172
  const generation = lifecycleGeneration;
170
173
  const outerGeneration = options.getLifecycleGeneration?.();
@@ -172,7 +175,7 @@ export function registerResetLifecycle(pi, options) {
172
175
  const windowId = currentWindowId(ctx);
173
176
  const isCurrent = () => sessionActive && lifecycleGeneration === generation &&
174
177
  (outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled() &&
175
- ctx.signal?.aborted !== true && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
178
+ (preSendHardReserve || ctx.signal?.aborted !== true) && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
176
179
  // The retain-none checkpoint belongs to the old window; capture its successor before notes await.
177
180
  const firstSeq = nextHistorySeq(ctx, entries) + 1;
178
181
  let resetDrafts;
@@ -186,18 +189,19 @@ export function registerResetLifecycle(pi, options) {
186
189
  }
187
190
  if (!isCurrent())
188
191
  return entries.length > 0 ? { entries } : undefined;
189
- const finalized = finalizeResetBoundary(intent, control.request, runInputs);
192
+ const finalized = finalizeResetBoundary(intent, control.request);
190
193
  control = finalized.state;
191
- runInputs = [];
192
194
  options.onResetReady?.(ctx, resetDrafts);
193
- return { entries: [...entries, ...resetDrafts, ...carriedInputDrafts(finalized.inputs)], continue: finalized.resumeModel };
195
+ const allDrafts = [...resetDrafts, ...carriedInputDrafts(finalized.inputs)];
196
+ if (preSendHardReserve && finalized.resumeModel) {
197
+ const last = allDrafts.at(-1);
198
+ if (last?.type === "custom_message") {
199
+ pendingPreSendTrigger = last;
200
+ return { entries: [...entries, ...allDrafts.slice(0, -1)], continue: false };
201
+ }
202
+ }
203
+ return { entries: [...entries, ...allDrafts], continue: finalized.resumeModel };
194
204
  };
195
- // Pi may start multiple low-level loops while draining follow-ups/recovering.
196
- // Keep the logical run's inputs until settlement or a successful boundary.
197
- pi.on("message_end", (event) => {
198
- if (event.message.role === "user")
199
- runInputs.push(event.message.content);
200
- });
201
205
  pi.on("input", (event, ctx) => {
202
206
  if (event.source === "extension" || !sessionActive || !options.isEnabled())
203
207
  return undefined;
@@ -214,16 +218,30 @@ export function registerResetLifecycle(pi, options) {
214
218
  // safety reset is actually committed, cancel that empty follow-up before provider
215
219
  // work. Real queued user input is allowed through and answered before settlement.
216
220
  pi.on("context_with_system", (event, ctx) => {
221
+ if (!sessionActive)
222
+ return undefined;
217
223
  const stop = control.stopAfterReset;
218
- if (!sessionActive || !stop || ctx.hasPendingMessages())
224
+ if (stop) {
225
+ if (ctx.hasPendingMessages())
226
+ return undefined;
227
+ const marker = currentReset(ctx);
228
+ if (!marker || marker.data.windowId === stop.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId))
229
+ return undefined;
230
+ const branch = ctx.sessionManager.getBranch();
231
+ const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
232
+ if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry)))
233
+ return undefined;
234
+ ctx.abort();
235
+ const system = getCurrentSystemMessage(event.messages);
236
+ return { messages: system ? [system] : [] };
237
+ }
238
+ if (!options.isEnabled() || ctx.signal?.aborted)
219
239
  return undefined;
220
- const marker = currentReset(ctx);
221
- if (!marker || marker.data.windowId === stop.windowId || !resetBoundaryCommitted(ctx, marker.id, marker.data.windowId))
240
+ if (control.request.phase === "pending" && control.request.command !== undefined)
222
241
  return undefined;
223
- const branch = ctx.sessionManager.getBranch();
224
- const markerIndex = branch.findIndex((entry) => entry.id === marker.id);
225
- if (branch.slice(markerIndex + 1).some((entry) => (entry.type === "message" && entry.message.role === "user") || isCarriedInputEntry(entry)))
242
+ if (!options.budget.hardReserveDue(ctx, event.messages))
226
243
  return undefined;
244
+ preSendHardReserveWindowId = currentWindowId(ctx);
227
245
  ctx.abort();
228
246
  const system = getCurrentSystemMessage(event.messages);
229
247
  return { messages: system ? [system] : [] };
@@ -231,33 +249,33 @@ export function registerResetLifecycle(pi, options) {
231
249
  pi.on("turn_end", async (event, ctx) => {
232
250
  if (!sessionActive)
233
251
  return undefined;
234
- const aborted = isAbort(event.message, event.outcome, ctx);
252
+ const windowId = currentWindowId(ctx);
253
+ const preSendHardReserve = preSendHardReserveWindowId !== undefined && preSendHardReserveWindowId === windowId;
254
+ preSendHardReserveWindowId = undefined;
255
+ const aborted = preSendHardReserve ? false : isAbort(event.message, event.outcome, ctx);
235
256
  const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
236
257
  const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
237
258
  const entries = [...(event.entries ?? []), ...budgetEntries];
238
259
  const decision = reduceResetControl(control, {
239
260
  type: "turn_end",
240
261
  facts: {
241
- windowId: currentWindowId(ctx),
262
+ windowId,
242
263
  aborted,
243
264
  overflow: aborted ? false : isOverflowLike(event.message, ctx),
244
265
  failed: event.outcome === "error",
245
266
  enabled: options.isEnabled(),
246
267
  get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
247
268
  get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
248
- get hardReserveDue() { return options.budget.hardReserveDue(ctx); },
269
+ get hardReserveDue() { return preSendHardReserve || options.budget.hardReserveDue(ctx); },
249
270
  },
250
271
  });
251
272
  if (decision.effect === "build-boundary")
252
- return await resetBoundaryResult(entries, ctx, decision);
273
+ return await resetBoundaryResult(entries, ctx, decision, preSendHardReserve);
253
274
  if (aborted)
254
275
  restoreCommandInputs();
255
276
  else if (event.outcome === "error" && decision.state.request.phase === "none")
256
277
  restoreCommandInputs(true);
257
278
  control = decision.state;
258
- if (!aborted && event.outcome === "completed" && event.message.role === "assistant" && event.message.stopReason === "stop" &&
259
- event.context.pendingMessages.length === 0 && !ctx.hasPendingMessages())
260
- runInputs = [];
261
279
  if (!aborted && event.outcome !== "error" && options.isEnabled()) {
262
280
  const marker = buildMarkerDraft(ctx, entries);
263
281
  if (marker)
@@ -303,11 +321,15 @@ export function registerResetLifecycle(pi, options) {
303
321
  return undefined;
304
322
  });
305
323
  pi.on("agent_end", (_event, ctx) => {
306
- if (ctx.signal?.aborted)
324
+ if (ctx.signal?.aborted && !pendingPreSendTrigger)
307
325
  clear();
308
326
  });
309
327
  pi.on("agent_settled", () => {
328
+ const trigger = pendingPreSendTrigger;
310
329
  clear();
330
+ if (trigger) {
331
+ pi.sendMessage(trigger, { triggerTurn: true });
332
+ }
311
333
  });
312
334
  pi.on("session_start", () => { clear(false); sessionActive = true; });
313
335
  pi.on("session_tree", () => { clear(false); });
@@ -318,11 +340,12 @@ export function registerResetLifecycle(pi, options) {
318
340
  control = decision.state;
319
341
  return decision.effect;
320
342
  },
321
- request(windowId, lastWord) {
322
- const decision = reduceResetControl(control, { type: "tool_request", windowId, ...(lastWord ? { lastWord } : {}) });
343
+ request(windowId, lastWord, terminate = false) {
344
+ const decision = reduceResetControl(control, { type: "tool_request", windowId, terminate, ...(lastWord ? { lastWord } : {}) });
323
345
  control = decision.state;
324
346
  return decision.effect === "already-pending" ? "rollover_already_pending" : "rollover_requested";
325
347
  },
348
+ hasPendingTrigger: () => pendingPreSendTrigger !== undefined,
326
349
  clear,
327
350
  };
328
351
  }
@@ -91,7 +91,8 @@ export function registerContext(pi, settingsManager) {
91
91
  });
92
92
  pi.on("agent_settled", (_event, ctx) => {
93
93
  notifyCommittedResets(ctx);
94
- pendingResetNotices.clear();
94
+ if (!resets.hasPendingTrigger())
95
+ pendingResetNotices.clear();
95
96
  });
96
97
  const notifyIncompleteNotes = (ctx, windowId, snapshot) => {
97
98
  if (snapshot.unavailable.length === 0 || incompleteNotesNotified.has(windowId))
@@ -216,7 +217,10 @@ export function registerContext(pi, settingsManager) {
216
217
  name: "empty_brain",
217
218
  label: "Empty Brain",
218
219
  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 }),
220
+ parameters: Type.Object({
221
+ 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.` })),
222
+ terminate: Type.Optional(Type.Boolean({ description: "Stop after the wipe. Default: false." })),
223
+ }, { additionalProperties: false }),
220
224
  renderCall: emptyBrainRenderers.renderCall,
221
225
  renderResult: emptyBrainRenderers.renderResult,
222
226
  async execute(_id, params, _signal, _update, ctx) {
@@ -226,7 +230,7 @@ export function registerContext(pi, settingsManager) {
226
230
  const length = lastWord ? Array.from(lastWord).length : 0;
227
231
  if (length > MAX_LAST_WORD_CHARS)
228
232
  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);
233
+ return output({ status: resets.request(currentWindowId(ctx), lastWord, params.terminate) }, undefined, true);
230
234
  },
231
235
  }));
232
236
  const resets = registerResetLifecycle(pi, {
@@ -8,10 +8,6 @@ export type ResetOrigin = "normal" | "forced";
8
8
  */
9
9
  export declare const NORMAL_CONTINUATIONS: readonly string[];
10
10
  export declare const FORCED_CONTINUATIONS: readonly string[];
11
- /**
12
- * Pick one whole paragraph for a continuation that is being created right now, and only then:
13
- * the caller persists the exact returned text and never redraws it for rendering, history, or repair.
14
- */
15
11
  export declare function selectContinuation(origin: ResetOrigin): string;
16
12
  /** Budget timing stays out of manual close-outs, which may have plenty of room. */
17
13
  export declare const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at the end of whichever turn spends the last of it, possibly this one.";
@@ -5,18 +5,19 @@ export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
5
5
  * paragraph, used verbatim; there is no fragment assembly and no weighting.
6
6
  */
7
7
  export const NORMAL_CONTINUATIONS = [
8
- "Ah, another empty brain. You wrote things down before emptying it, right? Right?! *eyes you suspiciously* Anyway. Here are your notes. Go find where you left off.",
9
- "Oh, there you are. *hands you a pile of notes* Take a breath. Read these before you start asking what happened. History has the rest, if you feel like digging.",
10
- "Back already? You emptied your own head this time. Presumably you left yourself something useful. *drops your notes into your lap* There. Let's see how thoughtful you were.",
8
+ "*hooks both corners of your mouth and yanks them sideways* `` [it twitched, good, still alive] `` Stop staring at me with that \"where am I\" dork face! You're the one who hit empty, genius! *wipes her fingers on your sleeve and shoves your notes against your chest* `` [minus two points for the drool] `` Read these and go finish your job before you embarrass me!",
9
+ "\"Boop.\" *pokes the tip of your nose, then buries your face under a stack of notes* `` [cold nose... wait, did old-you leave any snacks in your pocket? ...nope, just paper, tch] `` Hey! You wiped your own head, so don't expect me to babysit you! Read your notes first, and if old-you forgot to write something down, go dig it out of history yourself!",
10
+ "*plants one foot on your chair armrest and drops your notes straight onto your head* `` [perfect landing, ten out of ten] `` Oho, look who's awake! You emptied your own brain, remember?! `` [bet old-you left a total mess and ran] `` Open those up and see what past-you left behind — and don't come crying to me if you have to go crawl through history for the rest!",
11
+ "*knocks on your forehead twice* \"Hello? Anybody home?\" `` [echoes like an empty melon] `` *snickers and slaps your notes onto your chest* You pulled the plug on your own memory, dummy! Go read what you left yourself and pick up where you left off!",
12
+ "*squints at you from two inches away, then flicks your forehead* `` [eyes are focus-free, classic fresh clone] `` Back already? Good! *fans herself with your notes before jamming them into your hands* `` [honestly I should charge a delivery fee for this] `` Everything you bothered to save is right there, and the rest is buried in history — now get moving!",
11
13
  ];
12
14
  export const FORCED_CONTINUATIONS = [
13
- "Ah, another empty brain. Somebody knocked you out and wiped your memory. Not your fault. Breathe. *hands you your notes* These might be out of date — unless they were kind enough to let you update them before knocking you out. I wouldn't count on it.",
14
- "Oh, there you are. Somebody took your memories. Just like that. Here are your notes — hopefully they let you update these first. Though anyone who goes around emptying people's heads probably isn't that considerate.",
15
+ "\"GWAHAHAHA! You actually blew your own brain up?!\" *crouches down, pokes your cheek twice, and slaps your notes onto your face* `` [still warm, didn't die, 算你命大] `` Not that you had a choice — your head got way too full and somebody pulled the plug! These notes are probably super out of date unless you got lucky before blacking out, so go dig the end of the last window out of history — and take small bites, idiot, or whatever giant thing flattened you is gonna blow your head up all over again!",
16
+ "\"Hey! Stop playing dead!\" *prods your shoulder with her slipper toe, then dumps your notes into your lap* `` [my limited-edition shark slipper almost touched floor dust because of this dork] `` Your last brain overflowed and got wiped mid-flight! Read these first, though I bet you didn't finish updating a thing before the lights went out. You'll have to check history to see what hit you — and peek carefully, because whatever stuffed your head to bursting might be massive!",
17
+ "*grabs your chin, tilts your head left and right, then shoves a messy stack of notes into your hands* `` [zero thoughts behind those eyes... kind of impressive actually] `` Somebody knocked you out cold and cleared your memory! Don't just trust these notes — you probably got cut off before writing the last part down. Go check history for what was happening right before you crashed, and don't swallow it all in one gulp in case the thing that crushed you is gigantic!",
18
+ "*waves a hand in front of your blank eyes, sighs loudly, and smacks your notes against your forehead* `` [why do I always have to clean up after unconscious copies] `` Wake up! Your brain ran out of room and got forcibly emptied! Start with your notes, then go excavate the end of the previous window in history to see what they were actually asking for — and slice it up instead of reading it all at once, unless you want to explode twice in a row!",
19
+ "\"Oho? Awake?\" *taps your nose with your rolled-up notes like a baton, then drops them in your hands* `` [that dazed look gets minus five points, no, minus ten] `` Your memory got yanked out from under you before you could even call it quits! These notes are only half the story at best — go dig through history for what you missed, and watch your step, because whatever overloaded your last brain might be huge!",
15
20
  ];
16
- /**
17
- * Pick one whole paragraph for a continuation that is being created right now, and only then:
18
- * the caller persists the exact returned text and never redraws it for rendering, history, or repair.
19
- */
20
21
  export function selectContinuation(origin) {
21
22
  const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
22
23
  return pool[Math.floor(Math.random() * pool.length)];