notesoup 0.45.2 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +5 -5
- package/dist/src/budget/text.d.ts +4 -4
- package/dist/src/budget/text.js +3 -3
- package/dist/src/dsh/index.js +1 -1
- package/dist/src/dsh/tools.js +2 -2
- package/dist/src/history/query.js +18 -23
- package/dist/src/notes/store.js +4 -0
- package/dist/src/pi/reset/artifacts.d.ts +5 -3
- package/dist/src/pi/reset/artifacts.js +7 -9
- package/dist/src/pi/reset/lifecycle.js +1 -1
- package/dist/src/pi/runtime.js +17 -13
- package/dist/src/tools/history.js +1 -1
- package/dist/src/tools/notes.d.ts +3 -3
- package/dist/src/tools/notes.js +2 -2
- package/dist/src/tools/schema.d.ts +1 -7
- package/dist/src/tools/schema.js +6 -14
- package/dist/test/agent-loop.test.js +37 -37
- package/dist/test/boot.integration.test.js +11 -11
- package/dist/test/claude-mod.test.js +8 -8
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh-cli.test.js +1 -1
- package/dist/test/dsh.test.js +7 -7
- package/dist/test/history.integration.test.js +8 -3
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/notes.integration.test.js +22 -1
- package/dist/test/notes.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +19 -14
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +3 -3
- package/docs/dsh.md +3 -3
- package/docs/notes-library.md +1 -1
- package/docs/reset-lifecycle.md +7 -7
- package/docs/tool-results.md +2 -2
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +16 -13
- package/mods/notesoup/hooks/register.ts +10 -9
- package/mods/notesoup/skills/memory/SKILL.md +1 -1
- package/package.json +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/text.ts +5 -5
- package/src/budget/text.ts +3 -3
- package/src/dsh/index.ts +1 -1
- package/src/dsh/tools.ts +2 -2
- package/src/history/query.ts +16 -20
- package/src/notes/store.ts +4 -0
- package/src/pi/reset/artifacts.ts +8 -8
- package/src/pi/reset/lifecycle.ts +1 -1
- package/src/pi/runtime.ts +16 -13
- package/src/tools/history.ts +1 -1
- package/src/tools/notes.ts +2 -2
- package/src/tools/schema.ts +5 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# notesoup
|
|
2
2
|
|
|
3
|
-
Your agent's memory gets wiped when the context fills. notesoup makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, `/
|
|
3
|
+
Your agent's memory gets wiped when the context fills. notesoup makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, `/fresh-window` to force a fresh window, `/notesoup` to toggle.
|
|
4
4
|
|
|
5
5
|
The architecture — durable context windows, model-authored notes, searchable history — is the one OpenAI prototyped in Codex's `context_management` experiment and switched off ten days later, because it was welded to their backend. notesoup is the same architecture running entirely on your machine, built only on [Pi](https://github.com/earendil-works/pi)'s public extension APIs. No backend, no subscription gate, no server that can 404 at the worst possible moment. It can't be switched off from far away, because there is no far away.
|
|
6
6
|
|
|
@@ -28,7 +28,7 @@ pi -e npm:notesoup
|
|
|
28
28
|
|
|
29
29
|
## What you get
|
|
30
30
|
|
|
31
|
-
- **Durable context windows.** `/
|
|
31
|
+
- **Durable context windows.** `/fresh-window` (alias `/neuralyze`) clears and stops; `/fresh-window Continue reviewing the implementation` clears and continues. The model can also request a window itself with `neuralyze`, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
|
|
32
32
|
- **A boot block at every window head.** Static once-per-window content (cache-stable) with the window identity, the recent-notes index, and a short protocol teaching the model how to recover: notes for its own bookkeeping, history tools for everything before the reset.
|
|
33
33
|
- **`get_context_remaining`** — the live countdown to the close-out line, so the agent can see the cliff before it drives off it.
|
|
34
34
|
- **Eight history/notes tools**, flattened from the original Codex actions:
|
package/dist/src/boot/text.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ export declare const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_proto
|
|
|
10
10
|
* The one sentence that tells the model how to end its window voluntarily. A host with no
|
|
11
11
|
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
12
12
|
*/
|
|
13
|
-
export declare const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `
|
|
13
|
+
export declare const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `neuralyze` and erase yourself with dignity.";
|
|
14
14
|
/** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
|
|
15
|
-
export declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/
|
|
15
|
+
export declare const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
|
|
16
16
|
/** Logical tool names are supplied by the composing host, not discovered here. */
|
|
17
17
|
export type BootToolNames = Readonly<{
|
|
18
18
|
notes: string;
|
|
@@ -31,6 +31,6 @@ export declare const DEFAULT_BOOT_TOOL_NAMES: {
|
|
|
31
31
|
readonly notesList: "notes_list";
|
|
32
32
|
readonly history: "history_*";
|
|
33
33
|
readonly remaining: "get_context_remaining";
|
|
34
|
-
readonly wipe: "
|
|
34
|
+
readonly wipe: "neuralyze";
|
|
35
35
|
};
|
|
36
36
|
export declare function renderProtocolBlock(tools: BootToolNames): string;
|
package/dist/src/boot/text.js
CHANGED
|
@@ -10,9 +10,9 @@ export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
|
10
10
|
* The one sentence that tells the model how to end its window voluntarily. A host with no
|
|
11
11
|
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
12
12
|
*/
|
|
13
|
-
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `
|
|
13
|
+
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `neuralyze` and erase yourself with dignity.";
|
|
14
14
|
/** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
|
|
15
|
-
export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/
|
|
15
|
+
export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
|
|
16
16
|
/**
|
|
17
17
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
18
18
|
* notesoup's tool names. It lives once per window in the persisted boot block;
|
|
@@ -58,7 +58,7 @@ export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
|
58
58
|
notesList: "notes_list",
|
|
59
59
|
history: "history_*",
|
|
60
60
|
remaining: "get_context_remaining",
|
|
61
|
-
wipe: "
|
|
61
|
+
wipe: "neuralyze",
|
|
62
62
|
};
|
|
63
63
|
export function renderProtocolBlock(tools) {
|
|
64
64
|
const names = {
|
|
@@ -66,12 +66,12 @@ export function renderProtocolBlock(tools) {
|
|
|
66
66
|
notes_list: tools.notesList,
|
|
67
67
|
"history_*": tools.history,
|
|
68
68
|
get_context_remaining: tools.remaining,
|
|
69
|
-
|
|
69
|
+
neuralyze: tools.wipe,
|
|
70
70
|
};
|
|
71
71
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
72
72
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
73
73
|
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
74
74
|
? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
|
|
75
75
|
: PROTOCOL_BLOCK;
|
|
76
|
-
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|
|
|
76
|
+
return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)neuralyze/g, (name) => names[name]);
|
|
77
77
|
}
|
|
@@ -9,11 +9,11 @@ export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea
|
|
|
9
9
|
* instruction differs — Pi can reset the model itself, Claude can only end the turn.
|
|
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
|
-
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 `
|
|
13
|
-
/** Pi-only nudge: pi's
|
|
14
|
-
export declare const LAST_WORD_HINT = "If you want, pass `
|
|
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 `neuralyze` to reset now instead of being cut off mid-task.";
|
|
13
|
+
/** Pi-only nudge: pi's neuralyze persists a parting line; the dsh tool has no such parameter. */
|
|
14
|
+
export declare const LAST_WORD_HINT = "If you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
15
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 `
|
|
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 `neuralyze` to reset now instead of being cut off mid-task.\nIf you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.\n</context_window_guidance>";
|
|
17
17
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
18
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.";
|
|
19
19
|
/**
|
package/dist/src/budget/text.js
CHANGED
|
@@ -9,9 +9,9 @@ export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Defini
|
|
|
9
9
|
* instruction differs — Pi can reset the model itself, Claude can only end the turn.
|
|
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
|
-
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`
|
|
13
|
-
/** Pi-only nudge: pi's
|
|
14
|
-
export const LAST_WORD_HINT = "If you want, pass `
|
|
12
|
+
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`neuralyze\` to reset now instead of being cut off mid-task.`;
|
|
13
|
+
/** Pi-only nudge: pi's neuralyze persists a parting line; the dsh tool has no such parameter. */
|
|
14
|
+
export const LAST_WORD_HINT = "If you want, pass `neuralyze` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
15
15
|
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
|
|
16
16
|
export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
|
|
17
17
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
package/dist/src/dsh/index.js
CHANGED
|
@@ -33,7 +33,7 @@ export function apply(ctx) {
|
|
|
33
33
|
const state = engine.windows.get(agent.session);
|
|
34
34
|
const phase = budget.remaining <= budget.warning ? "warning" : budget.remaining <= budget.reminder ? "reminder" : undefined;
|
|
35
35
|
if (phase && !(phase === "warning" ? state.warned : state.reminded || state.warned)) {
|
|
36
|
-
const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "
|
|
36
|
+
const text = phase === "warning" ? WARNING_PROMPT : tokenBudgetGuidance(budget.countdown, "neuralyze");
|
|
37
37
|
agent.steer(createUserMessage({ content: [{ type: "text", text }], source: { kind: "notesoup-budget", windowId: state.snapshot.windowId, phase } }));
|
|
38
38
|
if (phase === "warning")
|
|
39
39
|
state.warned = true;
|
package/dist/src/dsh/tools.js
CHANGED
|
@@ -63,7 +63,7 @@ export function registerTools(ctx, engine) {
|
|
|
63
63
|
if (!exec.agent)
|
|
64
64
|
return;
|
|
65
65
|
const state = engine.windows.get(exec.agent.session);
|
|
66
|
-
if (exec.name === "
|
|
66
|
+
if (exec.name === "neuralyze" && !result.isError && result.value.window_id === state.snapshot.windowId) {
|
|
67
67
|
if (!exec.parent)
|
|
68
68
|
state.pendingReset = true;
|
|
69
69
|
else {
|
|
@@ -85,7 +85,7 @@ export function registerTools(ctx, engine) {
|
|
|
85
85
|
register(ctx, historyRead, async (agent) => [await historyProjection(ctx, agent.session.id)]);
|
|
86
86
|
register(ctx, historyWindows, async (agent) => [await historyProjection(ctx, agent.session.id), agent.session.id]);
|
|
87
87
|
ctx.tools.register(defineTool({
|
|
88
|
-
name: "
|
|
88
|
+
name: "neuralyze",
|
|
89
89
|
description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history stay on disk.",
|
|
90
90
|
parameters: {},
|
|
91
91
|
output: { schema: { type: "object", properties: { window_id: { type: "string", required: true }, reset_requested: { type: "boolean", required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: `notesoup: reset requested for ${value.window_id}; finish this tool batch, then recover from your notes.` }] },
|
|
@@ -130,26 +130,15 @@ function pageData(projection, params, vis, selected, maxChars, folds) {
|
|
|
130
130
|
}
|
|
131
131
|
return { items: rows, ...cursors };
|
|
132
132
|
}
|
|
133
|
-
/** Filter, then keep only literal matches when a query is present.
|
|
133
|
+
/** Filter, then keep only literal matches when a normalized query is present. */
|
|
134
134
|
function selectionCandidates(projection, params) {
|
|
135
|
-
|
|
136
|
-
if (params.query
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
catch (error) {
|
|
141
|
-
if (error instanceof InvalidQueryError)
|
|
142
|
-
return failure("invalid_query", error.message);
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const events = filteredItems(projection, params, queries === undefined);
|
|
147
|
-
if (queries === undefined)
|
|
148
|
-
return success(events.map((event) => ({ event })));
|
|
149
|
-
const needles = queries;
|
|
150
|
-
return success(events
|
|
135
|
+
const events = filteredItems(projection, params, params.query === undefined);
|
|
136
|
+
if (params.query === undefined)
|
|
137
|
+
return events.map((event) => ({ event }));
|
|
138
|
+
const needles = params.query;
|
|
139
|
+
return events
|
|
151
140
|
.map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), needles) }))
|
|
152
|
-
.filter((candidate) => candidate.matchOffset >= 0)
|
|
141
|
+
.filter((candidate) => candidate.matchOffset >= 0);
|
|
153
142
|
}
|
|
154
143
|
/**
|
|
155
144
|
* Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
|
|
@@ -159,11 +148,17 @@ export function selectPage(projection, params, fits, maxChars) {
|
|
|
159
148
|
const bounds = resolveTimeBounds(params);
|
|
160
149
|
if (!bounds.ok)
|
|
161
150
|
return bounds;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
let queries;
|
|
152
|
+
try {
|
|
153
|
+
queries = searchQueries(params.query);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (error instanceof InvalidQueryError)
|
|
157
|
+
return failure("invalid_query", error.message);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
const scoped = { ...params, ...bounds.data, query: queries.length ? queries : undefined };
|
|
161
|
+
const vis = selectionCandidates(projection, scoped);
|
|
167
162
|
// Take the limit from the end `from` names, so a budget for one row keeps the most important one.
|
|
168
163
|
// At least one: `slice(-0)` would otherwise return the whole selection.
|
|
169
164
|
const limit = Math.max(1, scoped.limit ?? 20);
|
package/dist/src/notes/store.js
CHANGED
|
@@ -461,6 +461,10 @@ export function createNotesStore(input) {
|
|
|
461
461
|
const rows = [];
|
|
462
462
|
for await (const note of scan(stableOptions, status)) {
|
|
463
463
|
const { address, path, scope, meta, body } = note;
|
|
464
|
+
if (stableQueries.length === 0) {
|
|
465
|
+
rows.push({ address, path, scope, meta, matches: [] });
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
464
468
|
// Offsets address the note body alone: no frontmatter length is predicted, so an
|
|
465
469
|
// access-counter rewrite cannot move a match out from under the caller.
|
|
466
470
|
let baseChars = 0;
|
|
@@ -5,9 +5,11 @@ export type ResetTailState = {
|
|
|
5
5
|
readonly boot: boolean;
|
|
6
6
|
readonly continuation: boolean;
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
export declare const MAX_LAST_WORD_CHARS =
|
|
10
|
-
/**
|
|
8
|
+
/** A sticky note, not a letter: over this, neuralyze refuses instead of truncating. */
|
|
9
|
+
export declare const MAX_LAST_WORD_CHARS = 250;
|
|
10
|
+
/** How the next window finds the note. */
|
|
11
|
+
export declare const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
|
|
12
|
+
/** Trim a parting line; blank input leaves no last word. Length is checked by the caller. */
|
|
11
13
|
export declare function sanitizeLastWord(raw: string | undefined): string | undefined;
|
|
12
14
|
/** Match the hidden continuation entry that carries the one reset message. */
|
|
13
15
|
export declare function isWindowContinuationEntry(entry: SessionEntry): boolean;
|
|
@@ -3,15 +3,13 @@ import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE,
|
|
|
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
|
-
/**
|
|
7
|
-
export const MAX_LAST_WORD_CHARS =
|
|
8
|
-
/**
|
|
6
|
+
/** A sticky note, not a letter: over this, neuralyze refuses instead of truncating. */
|
|
7
|
+
export const MAX_LAST_WORD_CHARS = 250;
|
|
8
|
+
/** How the next window finds the note. */
|
|
9
|
+
export const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
|
|
10
|
+
/** Trim a parting line; blank input leaves no last word. Length is checked by the caller. */
|
|
9
11
|
export function sanitizeLastWord(raw) {
|
|
10
|
-
|
|
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;
|
|
12
|
+
return raw?.trim() || undefined;
|
|
15
13
|
}
|
|
16
14
|
/** Match the hidden continuation entry that carries the one reset message. */
|
|
17
15
|
export function isWindowContinuationEntry(entry) {
|
|
@@ -40,7 +38,7 @@ export async function buildResetDrafts(ctx, notifyIncompleteNotes, isCurrent = (
|
|
|
40
38
|
{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId } },
|
|
41
39
|
{ type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
|
|
42
40
|
{ type: "custom_message", customType: CONTINUATION_TYPE, content: CONTINUATION, display: false },
|
|
43
|
-
...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: lastWord
|
|
41
|
+
...(lastWord ? [{ type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
|
|
44
42
|
...(prompt ? [{ type: "custom_message", customType: RESET_PROMPT_TYPE, content: prompt, display: true }] : []),
|
|
45
43
|
];
|
|
46
44
|
}
|
|
@@ -256,7 +256,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
256
256
|
const markerExists = currentReset(ctx) !== undefined;
|
|
257
257
|
if (options.isEnabled() || markerExists) {
|
|
258
258
|
if (event.reason === "manual") {
|
|
259
|
-
ctx.ui.notify("🥣 /compact is off while notesoup is on · use /
|
|
259
|
+
ctx.ui.notify("🥣 /compact is off while notesoup is on · use /fresh-window", "warning");
|
|
260
260
|
}
|
|
261
261
|
return { cancel: true };
|
|
262
262
|
}
|
package/dist/src/pi/runtime.js
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 } from "./window.js";
|
|
8
8
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
9
|
-
import { buildResetDrafts, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
9
|
+
import { buildResetDrafts, MAX_LAST_WORD_CHARS, 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 } from "./boot.js";
|
|
@@ -132,7 +132,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
132
132
|
catch (error) {
|
|
133
133
|
if (missingBootNotice !== windowId) {
|
|
134
134
|
missingBootNotice = windowId;
|
|
135
|
-
ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /
|
|
135
|
+
ctx.ui.notify("🥣 Request cancelled · this memory window is broken, run /fresh-window", "error");
|
|
136
136
|
}
|
|
137
137
|
ctx.abort();
|
|
138
138
|
const safeHead = getCurrentSystemMessage(event.messages);
|
|
@@ -166,8 +166,8 @@ export function registerContext(pi, settingsManager) {
|
|
|
166
166
|
cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
167
167
|
},
|
|
168
168
|
});
|
|
169
|
-
const
|
|
170
|
-
description: "
|
|
169
|
+
const neuralyzeCommand = {
|
|
170
|
+
description: "Flush memory to notes and continue in a fresh window; optional prompt runs there",
|
|
171
171
|
handler: async (args, cmdCtx) => {
|
|
172
172
|
if (!enabled) {
|
|
173
173
|
cmdCtx.ui.notify("🥣 notesoup is off · run /notesoup on first", "error");
|
|
@@ -185,7 +185,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
185
185
|
const prompt = args.trim() || undefined;
|
|
186
186
|
const armed = resets.closeOut(requestedWindowId, "manual", prompt);
|
|
187
187
|
if (armed === "already-pending") {
|
|
188
|
-
cmdCtx.ui.notify("🥣
|
|
188
|
+
cmdCtx.ui.notify("🥣 Neuralyze already queued · the first prompt is kept", "info");
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
cmdCtx.ui.notify(prompt
|
|
@@ -196,21 +196,25 @@ export function registerContext(pi, settingsManager) {
|
|
|
196
196
|
}
|
|
197
197
|
catch (error) {
|
|
198
198
|
resets.clear();
|
|
199
|
-
cmdCtx.ui.notify(`🥣 Couldn't start
|
|
199
|
+
cmdCtx.ui.notify(`🥣 Couldn't start /fresh-window: ${errorMessage(error)}`, "error");
|
|
200
200
|
}
|
|
201
201
|
},
|
|
202
202
|
};
|
|
203
|
-
pi.registerCommand("
|
|
204
|
-
pi.registerCommand("
|
|
203
|
+
pi.registerCommand("neuralyze", neuralyzeCommand);
|
|
204
|
+
pi.registerCommand("fresh-window", neuralyzeCommand);
|
|
205
205
|
pi.registerTool(defineTool({
|
|
206
|
-
name: "
|
|
207
|
-
label: "
|
|
208
|
-
description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to
|
|
209
|
-
parameters: Type.Object({ last_word: Type.Optional(Type.String({ description:
|
|
206
|
+
name: "neuralyze",
|
|
207
|
+
label: "Neuralyze",
|
|
208
|
+
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.",
|
|
209
|
+
parameters: Type.Object({ last_word: Type.Optional(Type.String({ maxLength: MAX_LAST_WORD_CHARS, description: `A tiny sticky note, at most ${MAX_LAST_WORD_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
|
|
210
210
|
async execute(_id, params, _signal, _update, ctx) {
|
|
211
211
|
if (!enabled)
|
|
212
212
|
return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
213
|
-
|
|
213
|
+
const lastWord = sanitizeLastWord(params.last_word);
|
|
214
|
+
const length = lastWord ? Array.from(lastWord).length : 0;
|
|
215
|
+
if (length > MAX_LAST_WORD_CHARS)
|
|
216
|
+
return output({ error: `last_word is ${length} characters; the sticky note holds ${MAX_LAST_WORD_CHARS}. Shorten it and call again.` });
|
|
217
|
+
return output({ status: resets.request(currentWindowId(ctx), lastWord) }, undefined, true);
|
|
214
218
|
},
|
|
215
219
|
}));
|
|
216
220
|
const resets = registerResetLifecycle(pi, {
|
|
@@ -134,7 +134,7 @@ function renderWindows(data) {
|
|
|
134
134
|
}
|
|
135
135
|
/* ------------------------------------------------------------------ history_list */
|
|
136
136
|
export const historyListParameters = Type.Object({
|
|
137
|
-
query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Searches every role, tool arguments and output included; returns only hits.")),
|
|
137
|
+
query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Empty text/list means no search filter; empty entries are ignored. Searches every role, tool arguments and output included; returns only hits.")),
|
|
138
138
|
roles: historyRoles(),
|
|
139
139
|
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
|
|
140
140
|
after_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq above this." })),
|
|
@@ -228,7 +228,7 @@ export declare const notesList: {
|
|
|
228
228
|
readonly render: (result: Outcome<NotesListData>) => string;
|
|
229
229
|
};
|
|
230
230
|
export declare const notesSearchParameters: Type.TObject<{
|
|
231
|
-
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]
|
|
231
|
+
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
232
232
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
233
233
|
limit: Type.TOptional<Type.TInteger>;
|
|
234
234
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
@@ -239,9 +239,9 @@ export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
|
239
239
|
export declare const notesSearch: {
|
|
240
240
|
readonly name: "notes_search";
|
|
241
241
|
readonly label: "Notes search";
|
|
242
|
-
readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
242
|
+
readonly description: "Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
243
243
|
readonly parameters: Type.TObject<{
|
|
244
|
-
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]
|
|
244
|
+
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
245
245
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
246
246
|
limit: Type.TOptional<Type.TInteger>;
|
|
247
247
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -306,7 +306,7 @@ export const notesList = {
|
|
|
306
306
|
},
|
|
307
307
|
render: (result) => renderOutcome(result, renderListData),
|
|
308
308
|
};
|
|
309
|
-
export const notesSearchParameters = Type.Object({ query: searchQuery(), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
309
|
+
export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
310
310
|
function renderSearchData(data) {
|
|
311
311
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
312
312
|
for (const file of data.files) {
|
|
@@ -343,7 +343,7 @@ function fitSearchFile(file, fits) {
|
|
|
343
343
|
}
|
|
344
344
|
export const notesSearch = {
|
|
345
345
|
name: "notes_search", label: "Notes search",
|
|
346
|
-
description: `Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
|
|
346
|
+
description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
|
|
347
347
|
parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
|
|
348
348
|
async execute(params, identity) {
|
|
349
349
|
try {
|
|
@@ -7,11 +7,5 @@ export declare const searchQuery: (description?: string) => Type.TUnion<[Type.TS
|
|
|
7
7
|
export declare class InvalidQueryError extends Error {
|
|
8
8
|
constructor(message: string);
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Normalize a search `query` parameter into the literal needles to match.
|
|
12
|
-
* A bare string is a one-element list, so single-query behavior is unchanged.
|
|
13
|
-
* An empty list, a non-string element, or an empty string is refused rather than silently
|
|
14
|
-
* searching for nothing: those are argument errors, not empty result sets. An empty string
|
|
15
|
-
* matches every line and every item, so it can never be what the caller meant.
|
|
16
|
-
*/
|
|
10
|
+
/** Missing/empty queries disable filtering; empty list entries are ignored, not OR wildcards. */
|
|
17
11
|
export declare function searchQueries(query: unknown): string[];
|
package/dist/src/tools/schema.js
CHANGED
|
@@ -3,7 +3,7 @@ import { HistoryRoleSchema } from "../history/history.js";
|
|
|
3
3
|
export const nullableString = (description) => Type.Optional(Type.Union([Type.String(), Type.Null()], description === undefined ? {} : { description }));
|
|
4
4
|
export const historyRoles = () => Type.Optional(Type.Array(HistoryRoleSchema, { minItems: 1, description: "(optional) Only these roles: user, assistant, tool, context. Omit to see the conversation with tool and context runs folded." }));
|
|
5
5
|
/** Search query parameter: one literal, or several literals combined with OR. */
|
|
6
|
-
export const searchQuery = (description) => Type.Union([Type.String(), Type.Array(Type.String()
|
|
6
|
+
export const searchQuery = (description = "(optional) Literal text, or texts combined with OR. Empty text or list means no search filter.") => Type.Union([Type.String(), Type.Array(Type.String())], { description });
|
|
7
7
|
/** Expected search-query refusal, distinct from any other Error an operation may raise. */
|
|
8
8
|
export class InvalidQueryError extends Error {
|
|
9
9
|
constructor(message) {
|
|
@@ -11,20 +11,12 @@ export class InvalidQueryError extends Error {
|
|
|
11
11
|
this.name = "InvalidQueryError";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Normalize a search `query` parameter into the literal needles to match.
|
|
16
|
-
* A bare string is a one-element list, so single-query behavior is unchanged.
|
|
17
|
-
* An empty list, a non-string element, or an empty string is refused rather than silently
|
|
18
|
-
* searching for nothing: those are argument errors, not empty result sets. An empty string
|
|
19
|
-
* matches every line and every item, so it can never be what the caller meant.
|
|
20
|
-
*/
|
|
14
|
+
/** Missing/empty queries disable filtering; empty list entries are ignored, not OR wildcards. */
|
|
21
15
|
export function searchQueries(query) {
|
|
22
|
-
const candidates = typeof query === "string" ? [query] : query;
|
|
23
|
-
if (!Array.isArray(candidates)
|
|
24
|
-
throw new InvalidQueryError("`query` must be a string or a
|
|
16
|
+
const candidates = query === undefined ? [] : typeof query === "string" ? [query] : query;
|
|
17
|
+
if (!Array.isArray(candidates))
|
|
18
|
+
throw new InvalidQueryError("`query` must be a string or a list of strings.");
|
|
25
19
|
if (!candidates.every((candidate) => typeof candidate === "string"))
|
|
26
20
|
throw new InvalidQueryError("Every item in the `query` list must be a string.");
|
|
27
|
-
|
|
28
|
-
throw new InvalidQueryError("`query` can't be an empty string; it would match everything.");
|
|
29
|
-
return candidates;
|
|
21
|
+
return candidates.filter((candidate) => candidate !== "");
|
|
30
22
|
}
|