notesoup 0.45.0 → 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.
Files changed (72) hide show
  1. package/dist/src/boot/text.d.ts +7 -0
  2. package/dist/src/boot/text.js +7 -0
  3. package/dist/src/budget/text.d.ts +4 -2
  4. package/dist/src/budget/text.js +4 -2
  5. package/dist/src/claude/helper.js +3 -8
  6. package/dist/src/dsh/engine.d.ts +6 -0
  7. package/dist/src/dsh/engine.js +34 -1
  8. package/dist/src/dsh/index.js +1 -1
  9. package/dist/src/dsh/tools.d.ts +1 -1
  10. package/dist/src/dsh/tools.js +2 -2
  11. package/dist/src/dsh/window.d.ts +1 -1
  12. package/dist/src/dsh/window.js +4 -6
  13. package/dist/src/notes/index.d.ts +4 -2
  14. package/dist/src/notes/index.js +4 -1
  15. package/dist/src/notes/paths.d.ts +0 -1
  16. package/dist/src/notes/paths.js +0 -1
  17. package/dist/src/pi/boot.d.ts +0 -5
  18. package/dist/src/pi/boot.js +4 -30
  19. package/dist/src/pi/budget.js +3 -3
  20. package/dist/src/pi/entries.d.ts +1 -0
  21. package/dist/src/pi/entries.js +1 -0
  22. package/dist/src/pi/notes/adapter.d.ts +1 -1
  23. package/dist/src/pi/notes/adapter.js +1 -1
  24. package/dist/src/pi/reset/artifacts.d.ts +6 -2
  25. package/dist/src/pi/reset/artifacts.js +14 -3
  26. package/dist/src/pi/reset/lifecycle.d.ts +6 -2
  27. package/dist/src/pi/reset/lifecycle.js +28 -18
  28. package/dist/src/pi/runtime.js +33 -8
  29. package/dist/src/pi/tool-result.d.ts +9 -0
  30. package/dist/src/pi/tool-result.js +4 -0
  31. package/dist/src/tools/notes.d.ts +1 -1
  32. package/dist/src/tools/notes.js +1 -1
  33. package/dist/src/tools/output.d.ts +1 -14
  34. package/dist/src/tools/output.js +1 -9
  35. package/dist/test/dependencies.test.js +53 -17
  36. package/dist/test/dsh.test.js +1 -1
  37. package/dist/test/helpers/dependency-graph.d.ts +3 -3
  38. package/dist/test/helpers/dependency-graph.js +64 -14
  39. package/dist/test/helpers/extension.js +2 -2
  40. package/dist/test/host-neutral.test.js +5 -0
  41. package/dist/test/notes.integration.test.js +4 -4
  42. package/dist/test/notes.test.js +1 -1
  43. package/dist/test/reset-lifecycle.test.js +47 -3
  44. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  45. package/mods/notesoup/dist/claude/helper.js +166 -166
  46. package/package.json +1 -1
  47. package/src/boot/text.ts +8 -0
  48. package/src/budget/text.ts +5 -2
  49. package/src/claude/helper.ts +3 -10
  50. package/src/dsh/engine.ts +27 -1
  51. package/src/dsh/index.ts +1 -1
  52. package/src/dsh/tools.ts +2 -3
  53. package/src/dsh/window.ts +4 -6
  54. package/src/notes/index.ts +4 -2
  55. package/src/notes/paths.ts +0 -1
  56. package/src/pi/boot.ts +4 -33
  57. package/src/pi/budget.ts +3 -3
  58. package/src/pi/entries.ts +1 -0
  59. package/src/pi/notes/adapter.ts +1 -2
  60. package/src/pi/notes/tools.ts +1 -1
  61. package/src/pi/reset/artifacts.ts +15 -2
  62. package/src/pi/reset/lifecycle.ts +34 -21
  63. package/src/pi/runtime.ts +36 -8
  64. package/src/pi/tool-result.ts +5 -0
  65. package/src/tools/notes.ts +1 -1
  66. package/src/tools/output.ts +1 -10
  67. package/dist/src/dsh/preflight.d.ts +0 -8
  68. package/dist/src/dsh/preflight.js +0 -35
  69. package/dist/src/pi/tool-names.d.ts +0 -7
  70. package/dist/src/pi/tool-names.js +0 -7
  71. package/src/dsh/preflight.ts +0 -29
  72. package/src/pi/tool-names.ts +0 -9
@@ -26,4 +26,11 @@ export type BootToolNames = Readonly<{
26
26
  */
27
27
  wipeSentence?: string;
28
28
  }>;
29
+ export declare const DEFAULT_BOOT_TOOL_NAMES: {
30
+ readonly notes: "notes_*";
31
+ readonly notesList: "notes_list";
32
+ readonly history: "history_*";
33
+ readonly remaining: "get_context_remaining";
34
+ readonly wipe: "clear_memory";
35
+ };
29
36
  export declare function renderProtocolBlock(tools: BootToolNames): string;
@@ -53,6 +53,13 @@ Any other @ address is fake. End of discussion. @ addresses are not file paths:
53
53
 
54
54
  \`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each may carry a short Cheatsheet of rules that always apply (about 5 lines); the rest is the note index, with addresses and gists for lookup. Keep each one current.
55
55
  ${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
56
+ export const DEFAULT_BOOT_TOOL_NAMES = {
57
+ notes: "notes_*",
58
+ notesList: "notes_list",
59
+ history: "history_*",
60
+ remaining: "get_context_remaining",
61
+ wipe: "clear_memory",
62
+ };
56
63
  export function renderProtocolBlock(tools) {
57
64
  const names = {
58
65
  "notes_*": tools.notes,
@@ -10,8 +10,10 @@ export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea
10
10
  */
11
11
  export declare const WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
12
12
  export declare const WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.";
13
- /** The shared hidden checkpoint text: one manual/budget-triggered request, both hosts. */
14
- export declare const WARNING_CONTENT = "<context_window_guidance>\nThis context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.\n</context_window_guidance>";
13
+ /** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
14
+ export declare const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
15
+ /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
16
+ export declare const WARNING_CONTENT = "<context_window_guidance>\nThis context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, call `clear_memory` to reset now instead of being cut off mid-task.\nIf you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.\n</context_window_guidance>";
15
17
  /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
16
18
  export declare const CLAUDE_WARNING_PROMPT = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, end your turn; the reset runs after it.";
17
19
  /**
@@ -10,8 +10,10 @@ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Defini
10
10
  */
11
11
  export const WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
12
12
  export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
13
- /** The shared hidden checkpoint text: one manual/budget-triggered request, both hosts. */
14
- export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${GUIDANCE_CLOSE_TAG}`;
13
+ /** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
14
+ export const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
15
+ /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
16
+ export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
15
17
  /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
16
18
  export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
17
19
  /**
@@ -7,15 +7,14 @@ import { renderBootBlock } from "../boot/render.js";
7
7
  import { CLAUDE_WIPE_SENTENCE } from "../boot/text.js";
8
8
  import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../budget/text.js";
9
9
  import { resolveClaudeLimits } from "./thresholds.js";
10
- import { resolveProjectHome } from "../notes/project-home.js";
11
- import { snapshotNotesIdentity } from "../notes/identity.js";
10
+ import { projectKey, snapshotNotesIdentity } from "../notes/index.js";
12
11
  const MAX_REQUEST_BYTES = 512 * 1024;
13
12
  const MAX_RESPONSE_BYTES = 1024 * 1024;
14
13
  const TOOL_NAMES = ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"];
15
14
  function identity(input) {
16
15
  if (!input || typeof input !== "object" || typeof input.cwd !== "string")
17
16
  throw new Error("invalid identity");
18
- return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: resolveProjectHome(input.cwd, input.home).name, agent: input.agent, model: input.model });
17
+ return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
19
18
  }
20
19
  /** The first schema violation, named by parameter so the model can fix that one field. */
21
20
  function paramProblem(schema, params) {
@@ -42,13 +41,9 @@ function boundOperation(operation, ...rest) {
42
41
  },
43
42
  };
44
43
  }
45
- /** Claude has no diff renderer, so an update receipt names the change kind instead of a diff. */
46
- function claudeDiff(change) {
47
- return change.kind === "none" ? "" : `note ${change.kind}`;
48
- }
49
44
  const OPERATIONS = {
50
45
  notes_write: boundOperation(notesWrite),
51
- notes_update: boundOperation(notesUpdate, claudeDiff),
46
+ notes_update: boundOperation(notesUpdate),
52
47
  notes_read: boundOperation(notesRead),
53
48
  notes_list: boundOperation(notesList),
54
49
  notes_search: boundOperation(notesSearch),
@@ -20,3 +20,9 @@ export declare class NotesoupCompactionEngine extends CompactionEngine {
20
20
  private transaction;
21
21
  }
22
22
  export default NotesoupCompactionEngine;
23
+ export declare class PreflightError extends Error {
24
+ readonly code: string;
25
+ constructor(code: string, message: string);
26
+ }
27
+ /** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
28
+ export declare function preflight(ctx: Context): NotesoupCompactionEngine;
@@ -4,7 +4,6 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
4
4
  import { appendPluginRecord } from "@deepseek-ai/dsh-session";
5
5
  import { measureBudget } from "./budget.js";
6
6
  import { checkpointText, Windows, WINDOW_RECORD } from "./window.js";
7
- import { preflight } from "./preflight.js";
8
7
  function resolveConfig(config) {
9
8
  const resolved = { ...config, auto: config.auto ?? true, thresholdRatio: config.thresholdRatio ?? 0.8, headroomTokens: config.headroomTokens ?? 65536 };
10
9
  if (typeof resolved.auto !== "boolean" || !Number.isFinite(resolved.thresholdRatio) || resolved.thresholdRatio <= 0 || resolved.thresholdRatio > 1 || !Number.isSafeInteger(resolved.headroomTokens) || resolved.headroomTokens < 0 || (resolved.reminderMarginTokens !== undefined && (!Number.isSafeInteger(resolved.reminderMarginTokens) || resolved.reminderMarginTokens <= 0)))
@@ -191,3 +190,37 @@ export class NotesoupCompactionEngine extends CompactionEngine {
191
190
  }
192
191
  }
193
192
  export default NotesoupCompactionEngine;
193
+ export class PreflightError extends Error {
194
+ code;
195
+ constructor(code, message) {
196
+ super(`notesoup: ${message}`);
197
+ this.code = code;
198
+ }
199
+ }
200
+ /** Probe capabilities and the public loader/registry, not preview-version strings or private hooks. */
201
+ export function preflight(ctx) {
202
+ for (const [service, method] of [["systemPrompt", "section"], ["tools", "register"], ["sessionQuery", "readSession"], ["tokenMeter", "measure"], ["llm", "resolveModelInfo"]]) {
203
+ const mounted = ctx.get(service);
204
+ if (typeof mounted?.[method] !== "function")
205
+ throw new PreflightError("CAPABILITY", `${service}.${method} is unavailable; enable that service in the profile before using notesoup.`);
206
+ }
207
+ const engine = ctx.get("compaction");
208
+ if (!(engine instanceof NotesoupCompactionEngine))
209
+ throw new PreflightError("ENGINE", "ctx.compaction must be NotesoupCompactionEngine; disable compaction-basic and enable the notesoup-engine row, then restart dsh.");
210
+ const loader = ctx.get("loader");
211
+ if (loader) {
212
+ if (typeof loader.entries !== "function")
213
+ throw new PreflightError("CAPABILITY", "loader.entries is unavailable; this profile cannot be checked for two engines.");
214
+ for (const entry of loader.entries()) {
215
+ if ((entry.options.id === "compaction-basic" || /(?:^|\/)dsh-compaction-basic$/.test(entry.options.name)) && !entry.disabled)
216
+ throw new PreflightError("DOUBLE_ENGINE", "compaction-basic is enabled; set disabled: true on that profile row and restart dsh.");
217
+ }
218
+ }
219
+ for (const [callback, runtime] of ctx.registry.entries()) {
220
+ if (callback.name === "BasicCompactionEngine" && runtime.fibers.length > 0)
221
+ throw new PreflightError("DOUBLE_ENGINE", "a BasicCompactionEngine fiber is mounted; remove it before starting notesoup.");
222
+ }
223
+ if (!engine.automaticListenerPresent)
224
+ throw new PreflightError("AUTO_LISTENER", "the automatic reset listener is missing; reload notesoup-engine before sending another request.");
225
+ return engine;
226
+ }
@@ -2,7 +2,7 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
2
2
  import { CONTINUATION, WARNING_PROMPT, tokenBudgetGuidance } from "../budget/text.js";
3
3
  import { measureBudget } from "./budget.js";
4
4
  import { BOOT_SECTION, restoreWarnings } from "./window.js";
5
- import { preflight } from "./preflight.js";
5
+ import { preflight } from "./engine.js";
6
6
  import { registerTools } from "./tools.js";
7
7
  export const name = "notesoup-dsh";
8
8
  export const inject = ["tools", "sessions", "systemPrompt", "llm", "tokenMeter", "sessionQuery", "compaction"];
@@ -1,3 +1,3 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
- import type { NotesoupCompactionEngine } from "./engine.js";
2
+ import { type NotesoupCompactionEngine } from "./engine.js";
3
3
  export declare function registerTools(ctx: Context, engine: NotesoupCompactionEngine): void;
@@ -7,7 +7,7 @@ import { success } from "../tools/result.js";
7
7
  import { historyProjection } from "./history.js";
8
8
  import { notesIdentity } from "./window.js";
9
9
  import { measureBudget } from "./budget.js";
10
- import { preflight } from "./preflight.js";
10
+ import { preflight } from "./engine.js";
11
11
  /** dsh enforces a small schema subset; TypeBox remains the full validator at execution. */
12
12
  function hostSchema(schema) {
13
13
  const value = JSON.parse(JSON.stringify(schema));
@@ -77,7 +77,7 @@ export function registerTools(ctx, engine) {
77
77
  });
78
78
  const identity = (agent) => notesIdentity(agent, engine.config);
79
79
  register(ctx, notesWrite, (agent) => [identity(agent)]);
80
- register(ctx, notesUpdate, (agent) => [identity(agent), (change) => change.kind === "none" ? "" : `note ${change.kind}`]);
80
+ register(ctx, notesUpdate, (agent) => [identity(agent)]);
81
81
  register(ctx, notesRead, (agent) => [identity(agent)]);
82
82
  register(ctx, notesList, (agent) => [identity(agent)]);
83
83
  register(ctx, notesSearch, (agent) => [identity(agent)]);
@@ -1,6 +1,6 @@
1
1
  import type { Agent } from "@deepseek-ai/dsh-agent";
2
2
  import { type Session, type SessionEvent } from "@deepseek-ai/dsh-session";
3
- import { type NotesIdentity } from "../notes/identity.js";
3
+ import { type NotesIdentity } from "../notes/index.js";
4
4
  export declare const WINDOW_RECORD = "plugin:notesoup/window";
5
5
  export declare const BOOT_SECTION = "notesoup:boot";
6
6
  export type WindowSnapshot = Readonly<{
@@ -5,17 +5,15 @@ import { join } from "node:path";
5
5
  import { createHash } from "node:crypto";
6
6
  import { loadNotesSnapshot } from "../boot/snapshot.js";
7
7
  import { renderBootBlock } from "../boot/render.js";
8
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
8
9
  import { CONTINUATION } from "../budget/text.js";
9
10
  import { contentText } from "../history/history.js";
10
- import { slugify } from "../notes/paths.js";
11
- import { resolveProjectHome } from "../notes/project-home.js";
12
- import { snapshotNotesIdentity } from "../notes/identity.js";
11
+ import { projectKey, slugify, snapshotNotesIdentity } from "../notes/index.js";
13
12
  export const WINDOW_RECORD = "plugin:notesoup/window";
14
13
  export const BOOT_SECTION = "notesoup:boot";
15
14
  const BOOT_OPEN = "<notesoup-boot>\n";
16
15
  const BOOT_CLOSE = "\n</notesoup-boot>";
17
16
  const CHECKPOINT_END = "\n\n<notesoup-continuation>\n";
18
- const TOOLS = { notes: "notes_*", notesList: "notes_list", history: "history_*", remaining: "get_context_remaining", wipe: "clear_memory" };
19
17
  export function restoreWarnings(state, events) {
20
18
  state.warned = false;
21
19
  state.reminded = false;
@@ -81,7 +79,7 @@ export function notesIdentity(agent, config) {
81
79
  return snapshotNotesIdentity({
82
80
  home,
83
81
  sessionId: agent.session.id,
84
- projectKey: resolveProjectHome(agent.session.header.cwd ?? process.cwd(), home).name,
82
+ projectKey: projectKey(agent.session.header.cwd ?? process.cwd(), home),
85
83
  agent: slugify(config.agentName ?? "dsh"),
86
84
  model: slugify(agent.session.requestHeader()?.config.model ?? agent.options.model ?? "unknown"),
87
85
  });
@@ -118,7 +116,7 @@ export class Windows {
118
116
  const notes = await loadNotesSnapshot(identity, openedAt);
119
117
  const previous = this.states.get(agent.session)?.snapshot;
120
118
  const firstWindowId = previous?.boot.match(/^First context window id: (.+)$/m)?.[1] ?? windowId(agent.session.id, 0);
121
- const boot = BOOT_OPEN + renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId, currentWindowId: windowId(agent.session.id, window), ...(window ? { previousWindowId: previous?.windowId ?? windowId(agent.session.id, window - 1) } : {}), notes, tools: TOOLS }) + BOOT_CLOSE;
119
+ const boot = BOOT_OPEN + renderBootBlock({ agentName: identity.agent, modelName: identity.model, firstWindowId, currentWindowId: windowId(agent.session.id, window), ...(window ? { previousWindowId: previous?.windowId ?? windowId(agent.session.id, window - 1) } : {}), notes, tools: DEFAULT_BOOT_TOOL_NAMES }) + BOOT_CLOSE;
122
120
  return Object.freeze({ version: 1, window, windowId: windowId(agent.session.id, window), openedAt, boot, notesDigest: digest(boot) });
123
121
  }
124
122
  }
@@ -1,5 +1,7 @@
1
1
  export { createNotesStore, noteIdentity } from "./store.js";
2
2
  export { NoteError, type NoteErrorCode } from "./errors.js";
3
- export { projectKey, slugify } from "./paths.js";
4
- export type { NotesIdentity } from "./identity.js";
3
+ export { projectKey } from "./project-home.js";
4
+ export { slugify } from "./paths.js";
5
+ export { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
6
+ export { isFilesystemError } from "./fs-error.js";
5
7
  export type { EditOperation, EditOptions, NoteChange, NoteEditResult, NoteMatch, NoteMeta, NoteQueryResult, NoteQueryStatus, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NoteWriteResult, NotesQuery, NotesStore, Origin, Scope, WriteOptions, } from "./store.js";
@@ -1,3 +1,6 @@
1
1
  export { createNotesStore, noteIdentity } from "./store.js";
2
2
  export { NoteError } from "./errors.js";
3
- export { projectKey, slugify } from "./paths.js";
3
+ export { projectKey } from "./project-home.js";
4
+ export { slugify } from "./paths.js";
5
+ export { snapshotNotesIdentity } from "./identity.js";
6
+ export { isFilesystemError } from "./fs-error.js";
@@ -1,4 +1,3 @@
1
- export { projectKey } from "./project-home.js";
2
1
  import type { NotesIdentity } from "./identity.js";
3
2
  export type Scope = "session" | "project" | "human" | "agent" | "model";
4
3
  /** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
@@ -1,6 +1,5 @@
1
1
  import { readdir } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
- export { projectKey } from "./project-home.js";
4
3
  import { NoteError, shown } from "./errors.js";
5
4
  /** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
6
5
  export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -17,8 +17,3 @@ export type BootMessage = {
17
17
  export declare function buildBootMessage(ctx: ExtensionContext, windowId: string, previousId: string | undefined, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean): Promise<BootMessage>;
18
18
  /** Persist one hidden boot message without triggering a model turn. */
19
19
  export declare function sendBoot(pi: ExtensionAPI, boot: BootMessage): void;
20
- /**
21
- * Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
22
- * boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
23
- */
24
- export declare function ensureBoot(pi: ExtensionAPI, ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean): Promise<void>;
@@ -1,11 +1,10 @@
1
- import { PI_TOOL_NAMES } from "./tool-names.js";
1
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
2
2
  import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
3
3
  import { loadNotesSnapshot, unavailableNotesSnapshot } from "../boot/snapshot.js";
4
- import { isFilesystemError } from "../notes/fs-error.js";
4
+ import { isFilesystemError } from "../notes/index.js";
5
5
  import { BOOT_TYPE } from "./entries.js";
6
6
  import { renderBootBlock } from "../boot/render.js";
7
- import { currentReset, currentWindowId, isWindowBoot, rootWindowId } from "./window.js";
8
- import { repairResetTail } from "./reset/artifacts.js";
7
+ import { rootWindowId } from "./window.js";
9
8
  /**
10
9
  * Acquire one notes snapshot and build the boot custom message for a window. All identity
11
10
  * fields are captured synchronously before the first filesystem await.
@@ -28,7 +27,7 @@ export async function buildBootMessage(ctx, windowId, previousId, notifyIncomple
28
27
  notifyIncompleteNotes?.(ctx, windowId, notes);
29
28
  return {
30
29
  customType: BOOT_TYPE,
31
- content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: PI_TOOL_NAMES }),
30
+ content: renderBootBlock({ agentName, modelName, firstWindowId: rootWindowId(sessionId), currentWindowId: windowId, previousWindowId: previousId, notes, tools: DEFAULT_BOOT_TOOL_NAMES }),
32
31
  display: false,
33
32
  details: { windowId },
34
33
  };
@@ -37,28 +36,3 @@ export async function buildBootMessage(ctx, windowId, previousId, notifyIncomple
37
36
  export function sendBoot(pi, boot) {
38
37
  pi.sendMessage({ customType: boot.customType, content: boot.content, display: boot.display, details: boot.details }, { triggerTurn: false });
39
38
  }
40
- /**
41
- * Boot entry point for `session_start` / `session_tree`. Ordinary startup ensures one root
42
- * boot; a reset marker instead asks reset-artifact repair to complete its persisted tail.
43
- */
44
- export async function ensureBoot(pi, ctx, notifyIncompleteNotes, isCurrent = () => true) {
45
- const sessionId = ctx.sessionManager.getSessionId();
46
- const reset = currentReset(ctx);
47
- const windowId = reset?.data.windowId ?? rootWindowId(sessionId);
48
- const stillCurrent = () => isCurrent() &&
49
- ctx.signal?.aborted !== true &&
50
- ctx.sessionManager.getSessionId() === sessionId &&
51
- currentWindowId(ctx) === windowId;
52
- if (reset) {
53
- await repairResetTail(pi, ctx, reset, notifyIncompleteNotes, stillCurrent);
54
- return;
55
- }
56
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
57
- return;
58
- const boot = await buildBootMessage(ctx, windowId, undefined, notifyIncompleteNotes, stillCurrent);
59
- if (!stillCurrent())
60
- return;
61
- if (ctx.sessionManager.buildSessionProjection().messages.some((message) => isWindowBoot(message, windowId)))
62
- return;
63
- sendBoot(pi, boot);
64
- }
@@ -1,4 +1,4 @@
1
- import { PI_TOOL_NAMES } from "./tool-names.js";
1
+ import { DEFAULT_BOOT_TOOL_NAMES } from "../boot/text.js";
2
2
  import { remainingBudget } from "../budget/policy.js";
3
3
  import { Type } from "@earendil-works/pi-ai";
4
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
@@ -8,7 +8,7 @@ import { readThresholdSettings } from "./thresholds.js";
8
8
  import { currentWindowId, hasWindowMessage, isWindowMarker, rootWindowId, windowUsage } from "./window.js";
9
9
  import { tokenBudgetGuidance } from "../budget/text.js";
10
10
  import { arrangeAnchoredReminders } from "./anchored.js";
11
- import { output } from "../tools/output.js";
11
+ import { output } from "./tool-result.js";
12
12
  /** Remaining tokens in the provider's active window, or null without a usable estimate. */
13
13
  function remainingTokens(ctx) {
14
14
  const usage = windowUsage(ctx);
@@ -154,7 +154,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
154
154
  if (pendingGuidance?.windowId !== windowId) {
155
155
  if (remaining > reminder)
156
156
  return result();
157
- pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, PI_TOOL_NAMES.wipe) };
157
+ pendingGuidance = { windowId, content: tokenBudgetGuidance(remainingBudget(remaining, warning) ?? 0, DEFAULT_BOOT_TOOL_NAMES.wipe) };
158
158
  }
159
159
  return result({ customType: GUIDANCE_TYPE, content: pendingGuidance.content });
160
160
  });
@@ -5,3 +5,4 @@ export declare const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
5
  export declare const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
6
  export declare const CONTINUATION_TYPE = "notesoup/continuation";
7
7
  export declare const RESET_PROMPT_TYPE = "notesoup/reset-prompt";
8
+ export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
@@ -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,5 +1,5 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { NotesIdentity } from "../../notes/identity.js";
2
+ import { type NotesIdentity } from "../../notes/index.js";
3
3
  /** Pi's default notes root; environment access stays on the host side of the library boundary. */
4
4
  export declare function notesRoot(): string;
5
5
  /** Translate the current Pi runtime into a fresh, explicit identity snapshot. */
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { join, resolve } from "node:path";
3
- import { projectKey, slugify } from "../../notes/paths.js";
3
+ import { projectKey, slugify } from "../../notes/index.js";
4
4
  /** Pi's default notes root; environment access stays on the host side of the library boundary. */
5
5
  export function notesRoot() {
6
6
  const override = process.env.PI_NOTES_HOME;
@@ -5,13 +5,17 @@ export type ResetTailState = {
5
5
  readonly boot: boolean;
6
6
  readonly continuation: boolean;
7
7
  };
8
+ /** Cap for the parting line: one visible line, not an essay. */
9
+ export declare const MAX_LAST_WORD_CHARS = 500;
10
+ /** Trim and cap a parting line; blank input leaves no last word. */
11
+ export declare function sanitizeLastWord(raw: string | undefined): string | undefined;
8
12
  /** Match the hidden continuation entry that carries the one reset message. */
9
13
  export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
10
14
  /**
11
15
  * The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
12
- * continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
16
+ * continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
13
17
  */
14
- export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string): Promise<SessionBoundaryDraft[]>;
18
+ export declare function buildResetDrafts(ctx: ExtensionContext, notifyIncompleteNotes?: IncompleteNotesNotifier, isCurrent?: () => boolean, prompt?: string, lastWord?: string): Promise<SessionBoundaryDraft[]>;
15
19
  /**
16
20
  * Inspect the persisted tail of a reset marker. It reports which reset messages are present
17
21
  * only while the tail stays repairable: metadata may follow the marker, but real conversation,
@@ -1,8 +1,18 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { BOOT_TYPE, CONTINUATION_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
2
+ import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE, RESET_PROMPT_TYPE } from "../entries.js";
3
3
  import { CONTINUATION } from "../../budget/text.js";
4
4
  import { currentWindowId, isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, previousWindowId } from "../window.js";
5
5
  import { buildBootMessage, sendBoot } from "../boot.js";
6
+ /** Cap for the parting line: one visible line, not an essay. */
7
+ export const MAX_LAST_WORD_CHARS = 500;
8
+ /** Trim and cap a parting line; blank input leaves no last word. */
9
+ export function sanitizeLastWord(raw) {
10
+ const trimmed = raw?.trim();
11
+ if (!trimmed)
12
+ return undefined;
13
+ const chars = Array.from(trimmed);
14
+ return chars.length > MAX_LAST_WORD_CHARS ? `${chars.slice(0, MAX_LAST_WORD_CHARS).join("")}…` : trimmed;
15
+ }
6
16
  /** Match the hidden continuation entry that carries the one reset message. */
7
17
  export function isWindowContinuationEntry(entry) {
8
18
  return entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE;
@@ -13,9 +23,9 @@ function sendContinuation(pi) {
13
23
  }
14
24
  /**
15
25
  * The closed, ordered reset shape: retain-none native checkpoint, marker, matching boot,
16
- * continuation, then an optional command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
26
+ * continuation, then an optional parting line and command prompt. The boot snapshot is acquired asynchronously after capturing this identity.
17
27
  */
18
- export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt) {
28
+ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = () => true, prompt, lastWord) {
19
29
  const sessionId = ctx.sessionManager.getSessionId();
20
30
  const previousId = currentWindowId(ctx);
21
31
  const sessionPrefix = sessionId.slice(0, 8);
@@ -30,6 +40,7 @@ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = (
30
40
  { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
31
41
  { type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
32
42
  { type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
43
+ ...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: lastWord, display: true }] : []),
33
44
  ...(prompt ? [{ type: "custom_message", customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
34
45
  ];
35
46
  }
@@ -8,7 +8,7 @@ type BudgetOwner = {
8
8
  type ResetOptions = {
9
9
  isEnabled: () => boolean;
10
10
  budget: BudgetOwner;
11
- buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
11
+ buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, prompt?: string, lastWord?: string) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
12
12
  getLifecycleGeneration?: () => number;
13
13
  onResetReady?: (ctx: ExtensionContext, drafts: readonly SessionBoundaryDraft[]) => void;
14
14
  };
@@ -24,10 +24,12 @@ export type ResetRequest = {
24
24
  readonly windowId: string;
25
25
  readonly source: ResetRequestSource;
26
26
  readonly prompt?: string;
27
+ readonly lastWord?: string;
27
28
  } | {
28
29
  readonly phase: "tool-requested";
29
30
  readonly windowId: string;
30
31
  readonly source: ToolResetRequestSource;
32
+ readonly lastWord?: string;
31
33
  };
32
34
  export type ResetOverflowPhase = "idle" | "pending" | "pending-spent" | "spent";
33
35
  export interface ResetControlState {
@@ -63,6 +65,7 @@ export type ResetControlEvent = {
63
65
  } | {
64
66
  readonly type: "tool_request";
65
67
  readonly windowId: string;
68
+ readonly lastWord?: string;
66
69
  } | {
67
70
  readonly type: "turn_end";
68
71
  readonly facts: ResetTurnEndFacts;
@@ -81,6 +84,7 @@ export interface ResetControlResult {
81
84
  readonly state: ResetControlState;
82
85
  readonly effect: ResetControlEffect;
83
86
  readonly prompt?: string;
87
+ readonly lastWord?: string;
84
88
  }
85
89
  /** Pure reset-control transitions: request phases own close-out, tool commit, and fallback. */
86
90
  export declare function reduceResetControl(state: ResetControlState, event: ResetControlEvent): ResetControlResult;
@@ -95,7 +99,7 @@ export declare function reduceResetControl(state: ResetControlState, event: Rese
95
99
  */
96
100
  export declare function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions): {
97
101
  closeOut(windowId: string, source: ResetRequestSource, prompt?: string): ResetControlEffect;
98
- request(windowId: string): "rollover_already_pending" | "rollover_requested";
102
+ request(windowId: string, lastWord?: string): "rollover_already_pending" | "rollover_requested";
99
103
  clear: () => void;
100
104
  };
101
105
  export {};