notesoup 0.41.0 → 0.42.0
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/dist/src/boot/text.d.ts +12 -0
- package/dist/src/boot/text.js +14 -2
- package/dist/src/budget/text.d.ts +12 -0
- package/dist/src/budget/text.js +12 -0
- package/dist/src/claude/helper.js +23 -2
- package/dist/src/claude/thresholds.d.ts +39 -0
- package/dist/src/claude/thresholds.js +149 -0
- package/dist/src/dream/doctor.js +1 -1
- package/dist/src/dream/jail.js +10 -10
- package/dist/src/history/history.js +1 -1
- package/dist/src/history/query.js +6 -6
- package/dist/src/notes/address.d.ts +1 -1
- package/dist/src/notes/address.js +12 -12
- package/dist/src/notes/store.js +16 -12
- package/dist/src/pi/reset/text.d.ts +2 -3
- package/dist/src/pi/reset/text.js +5 -4
- package/dist/src/pi/runtime.js +1 -1
- package/dist/src/pi/tool-result.js +2 -2
- package/dist/src/settings.d.ts +8 -0
- package/dist/src/settings.js +6 -1
- package/dist/src/tools/history.js +12 -12
- package/dist/src/tools/notes.d.ts +3 -3
- package/dist/src/tools/notes.js +12 -11
- package/dist/src/tools/output.d.ts +2 -0
- package/dist/src/tools/output.js +2 -0
- package/dist/src/tools/result.js +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/claude-mod.test.js +206 -16
- package/dist/test/dream.test.js +3 -3
- package/dist/test/history.integration.test.js +7 -8
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/notes-library.test.js +1 -1
- package/dist/test/notes.integration.test.js +4 -4
- package/dist/test/notes.test.js +16 -16
- package/docs/claude-code-mod.md +10 -2
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +200 -41
- package/mods/notesoup/hooks/register.ts +193 -27
- package/mods/pi-context/dist/claude/helper.js +9324 -0
- package/package.json +1 -1
- package/src/boot/text.ts +20 -2
- package/src/budget/text.ts +17 -0
- package/src/claude/helper.ts +20 -3
- package/src/claude/thresholds.ts +170 -0
- package/src/dream/doctor.ts +1 -1
- package/src/dream/jail.ts +10 -10
- package/src/history/history.ts +1 -1
- package/src/history/query.ts +6 -6
- package/src/notes/address.ts +12 -12
- package/src/notes/store.ts +17 -12
- package/src/pi/reset/text.ts +6 -7
- package/src/pi/runtime.ts +1 -1
- package/src/pi/tool-result.ts +2 -2
- package/src/settings.ts +18 -2
- package/src/tools/history.ts +12 -12
- package/src/tools/notes.ts +14 -12
- package/src/tools/output.ts +2 -0
- package/src/tools/result.ts +2 -2
- package/src/tools/schema.ts +3 -3
package/dist/src/notes/store.js
CHANGED
|
@@ -195,12 +195,16 @@ async function atomicWrite(path, content) {
|
|
|
195
195
|
function assertWritablePath(vpath) {
|
|
196
196
|
const bytes = Buffer.byteLength(vpath, "utf8");
|
|
197
197
|
if (bytes > MAX_NOTE_PATH_BYTES)
|
|
198
|
-
throw new NoteError("too_large", `
|
|
198
|
+
throw new NoteError("too_large", `Path too long: ${bytes} bytes; the limit is ${MAX_NOTE_PATH_BYTES}.`);
|
|
199
|
+
}
|
|
200
|
+
/** Rounded up, so a note just over the limit never reads as exactly at it. */
|
|
201
|
+
function megabytes(bytes) {
|
|
202
|
+
return `${Math.ceil(bytes / 10_000) / 100} MB`;
|
|
199
203
|
}
|
|
200
204
|
function assertSerializedSize(content) {
|
|
201
205
|
const bytes = Buffer.byteLength(content, "utf8");
|
|
202
206
|
if (bytes > MAX_NOTE_BYTES)
|
|
203
|
-
throw new NoteError("too_large", `note
|
|
207
|
+
throw new NoteError("too_large", `This note would be ${megabytes(bytes)}, over the ${megabytes(MAX_NOTE_BYTES)} limit per note; split it into several notes.`);
|
|
204
208
|
}
|
|
205
209
|
/** Frontmatter block only (the body separator stripped), for metadata-only change inputs. */
|
|
206
210
|
function frontmatterOf(meta) {
|
|
@@ -214,7 +218,7 @@ function assertWritableHome(scope, who, identity) {
|
|
|
214
218
|
if (who === current)
|
|
215
219
|
return;
|
|
216
220
|
const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
|
|
217
|
-
throw new NoteError("invalid_scope", `${home} is
|
|
221
|
+
throw new NoteError("invalid_scope", `${home} is someone else's home; you can write to this session, @project/, @human/, @self/, or @model/.`);
|
|
218
222
|
}
|
|
219
223
|
/** Normalize parsed metadata exactly as a read does, including its access mutation. */
|
|
220
224
|
function accessedMeta(meta, scope, now) {
|
|
@@ -282,13 +286,13 @@ export function createNotesStore(input) {
|
|
|
282
286
|
const scope = destination.scope;
|
|
283
287
|
assertWritableHome(scope, destination.who, identity);
|
|
284
288
|
if (operations.length === 0 && stableOptions.origin === undefined && stableOptions.crumpled === undefined) {
|
|
285
|
-
throw new NoteError("nothing_to_do", "
|
|
289
|
+
throw new NoteError("nothing_to_do", "Nothing to change: pass edits, origin, crumpled, or rename_to.");
|
|
286
290
|
}
|
|
287
291
|
const path = physicalPath(scope, destination.path, identity, destination.who);
|
|
288
292
|
return withPathQueue(path, async () => {
|
|
289
293
|
const raw = await readFileIfExists(path);
|
|
290
294
|
if (raw === undefined)
|
|
291
|
-
throw new NoteError("not_found",
|
|
295
|
+
throw new NoteError("not_found", `No note at ${noteIdentity(identity, address).address}.`);
|
|
292
296
|
const { meta, body } = parseNote(raw);
|
|
293
297
|
meta.scope = scope;
|
|
294
298
|
const beforeMeta = { ...meta };
|
|
@@ -298,14 +302,14 @@ export function createNotesStore(input) {
|
|
|
298
302
|
const oldText = operation?.oldText;
|
|
299
303
|
const newText = operation?.newText;
|
|
300
304
|
if (typeof oldText !== "string" || oldText.length === 0)
|
|
301
|
-
throw new NoteError("no_match", `
|
|
305
|
+
throw new NoteError("no_match", `edits[${index}].oldText is empty.`, { editIndex: index });
|
|
302
306
|
if (typeof newText !== "string")
|
|
303
|
-
throw new NoteError("no_match", `
|
|
307
|
+
throw new NoteError("no_match", `edits[${index}].newText must be a string.`, { editIndex: index });
|
|
304
308
|
const lines = matchLineNumbers(next, oldText);
|
|
305
309
|
if (lines.length === 0)
|
|
306
|
-
throw new NoteError("no_match", `
|
|
310
|
+
throw new NoteError("no_match", `edits[${index}].oldText isn't in the note${index > 0 ? " (after the earlier edits)" : ""}. Nothing was saved.`, { editIndex: index });
|
|
307
311
|
if (lines.length > 1 && !stableOptions.replaceAll) {
|
|
308
|
-
throw new NoteError("ambiguous_edit", `
|
|
312
|
+
throw new NoteError("ambiguous_edit", `edits[${index}].oldText appears ${lines.length} times (${anchorLines(lines)}); add surrounding text to pick one, or set replace_all. Nothing was saved.`, { lineNumbers: lines, editIndex: index });
|
|
309
313
|
}
|
|
310
314
|
if (oldText !== newText)
|
|
311
315
|
applied++;
|
|
@@ -361,15 +365,15 @@ export function createNotesStore(input) {
|
|
|
361
365
|
const fromPath = physicalPath(fromScope, from.path, identity, from.who);
|
|
362
366
|
const toPath = physicalPath(toScope, to.path, identity, to.who);
|
|
363
367
|
if (resolve(fromPath) === resolve(toPath))
|
|
364
|
-
throw new NoteError("nothing_to_do", "rename_to
|
|
368
|
+
throw new NoteError("nothing_to_do", "rename_to points at the note itself.");
|
|
365
369
|
const [first, second] = [fromPath, toPath].sort();
|
|
366
370
|
return withPathQueue(first, () => withPathQueue(second, async () => {
|
|
367
371
|
const raw = await readFileIfExists(fromPath);
|
|
368
372
|
if (raw === undefined)
|
|
369
|
-
throw new NoteError("not_found",
|
|
373
|
+
throw new NoteError("not_found", `No note at ${noteIdentity(identity, fromAddress).address}.`);
|
|
370
374
|
const targetRaw = await readFileIfExists(toPath);
|
|
371
375
|
if (targetRaw !== undefined && parseNote(targetRaw).meta.crumpledAt === undefined) {
|
|
372
|
-
throw new NoteError("already_exists",
|
|
376
|
+
throw new NoteError("already_exists", `${noteIdentity(identity, toAddress).address} already holds a note; crumple it first or pick another address.`);
|
|
373
377
|
}
|
|
374
378
|
const { meta, body } = parseNote(raw);
|
|
375
379
|
meta.scope = toScope;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
|
|
3
|
-
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.";
|
|
1
|
+
import { CLAUDE_WARNING_PROMPT, CONTINUATION, WARNING_BODY, WARNING_PROMPT } from "../../budget/text.js";
|
|
4
2
|
/** Shared hidden checkpoint text for manual and budget-triggered requests. */
|
|
5
3
|
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>";
|
|
4
|
+
export { CLAUDE_WARNING_PROMPT, CONTINUATION, WARNING_BODY, WARNING_PROMPT };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/** The single reset message: the only reset prose persisted, carried by the continuation entry. */
|
|
3
|
-
export const CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
|
|
4
|
-
export 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.";
|
|
1
|
+
import { CLAUDE_WARNING_PROMPT, CONTINUATION, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WARNING_PROMPT } from "../../budget/text.js";
|
|
5
2
|
/** Shared hidden checkpoint text for manual and budget-triggered requests. */
|
|
6
3
|
export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${GUIDANCE_CLOSE_TAG}`;
|
|
4
|
+
// The reset prose lives beside the guidance text in the host-neutral budget domain, so the
|
|
5
|
+
// Claude mod can show the same words without depending on any Pi module. Re-exported here
|
|
6
|
+
// for the Pi-side importers that already reach for this module.
|
|
7
|
+
export { CLAUDE_WARNING_PROMPT, CONTINUATION, WARNING_BODY, WARNING_PROMPT };
|
package/dist/src/pi/runtime.js
CHANGED
|
@@ -182,7 +182,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
182
182
|
parameters: Type.Object({}, { additionalProperties: false }),
|
|
183
183
|
async execute(_id, _params, _signal, _update, ctx) {
|
|
184
184
|
if (!enabled)
|
|
185
|
-
return output({ error: "notesoup is off
|
|
185
|
+
return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
|
|
186
186
|
return output({ status: resets.request(currentWindowId(ctx)) }, undefined, true);
|
|
187
187
|
},
|
|
188
188
|
}));
|
|
@@ -10,8 +10,8 @@ export function piOperationResult(render, outcome) {
|
|
|
10
10
|
details: undefined,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See
|
|
14
|
-
export const HISTORY_NAMESPACE = { name: "history", description: "What happened in this session, read-only. See
|
|
13
|
+
export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
|
|
14
|
+
export const HISTORY_NAMESPACE = { name: "history", description: "What happened in this session, read-only. See the memory skill." };
|
|
15
15
|
/** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
|
|
16
16
|
export function registerOperation(pi, operation, run, namespace) {
|
|
17
17
|
pi.registerTool(defineTool({
|
package/dist/src/settings.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export declare const NOTESOUP_SETTINGS_KEY = "notesoup";
|
|
2
2
|
/** Nested under "notesoup": the default dreamer model pattern, overridden by CLI --dreamer. */
|
|
3
3
|
export declare const NOTESOUP_DREAMER_KEY = "dreamer";
|
|
4
|
+
/**
|
|
5
|
+
* The one notesoup settings shape both hosts read. `reminderMarginTokens` is Pi's early
|
|
6
|
+
* reminder margin; `resetMarginTokens` and `warningRunwayTokens` are the Claude mod's
|
|
7
|
+
* margins against Claude's own auto-compact point (see src/claude/thresholds.ts). A host
|
|
8
|
+
* ignores the keys it does not use; every value is validated where it is consumed.
|
|
9
|
+
*/
|
|
4
10
|
export type NotesoupSettings = {
|
|
5
11
|
reminderMarginTokens?: unknown;
|
|
12
|
+
resetMarginTokens?: unknown;
|
|
13
|
+
warningRunwayTokens?: unknown;
|
|
6
14
|
dreamer?: unknown;
|
|
7
15
|
};
|
|
8
16
|
/** Merge the global and project "notesoup" objects per key; project wins, mirroring Pi's deep merge. */
|
package/dist/src/settings.js
CHANGED
|
@@ -14,5 +14,10 @@ function notesoupSettings(settings) {
|
|
|
14
14
|
/** Merge the global and project "notesoup" objects per key; project wins, mirroring Pi's deep merge. */
|
|
15
15
|
export function mergeNotesoupSettings(globalSettings, projectSettings) {
|
|
16
16
|
const merged = { ...notesoupSettings(globalSettings), ...notesoupSettings(projectSettings) };
|
|
17
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
reminderMarginTokens: merged.reminderMarginTokens,
|
|
19
|
+
resetMarginTokens: merged.resetMarginTokens,
|
|
20
|
+
warningRunwayTokens: merged.warningRunwayTokens,
|
|
21
|
+
dreamer: merged.dreamer,
|
|
22
|
+
};
|
|
18
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Host-neutral history operations: one bounded payload for text and structured results. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import { HISTORY_PREVIEW_CHARS } from "./output.js";
|
|
3
|
+
import { HISTORY_PREVIEW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
4
4
|
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
5
5
|
import { historyRoles, searchQuery } from "./schema.js";
|
|
6
6
|
import { HistoryPageSchema, selectPage } from "../history/query.js";
|
|
@@ -59,7 +59,7 @@ function renderFoldedRow(row) {
|
|
|
59
59
|
function renderPage(page) {
|
|
60
60
|
// An empty selection has no anchors either, so it would otherwise render as nothing at all.
|
|
61
61
|
if (page.items.length === 0)
|
|
62
|
-
return "
|
|
62
|
+
return "No events match these filters.";
|
|
63
63
|
const body = page.items.map((item) => (isFoldedRow(item) ? renderFoldedRow(item) : renderPageItem(item))).join("\n\n");
|
|
64
64
|
const cursors = [
|
|
65
65
|
page.page_older === null ? "" : `→ older: ${JSON.stringify(page.page_older)}`,
|
|
@@ -82,7 +82,7 @@ function pageFits(page) {
|
|
|
82
82
|
const MAX_REPORTED_WINDOWS = 5;
|
|
83
83
|
/** At most `MAX_REPORTED_WINDOWS` known ids, appended to an unknown_window_id message. */
|
|
84
84
|
function knownWindowSuffix(known) {
|
|
85
|
-
return known.length === 0 ? "" : `;
|
|
85
|
+
return known.length === 0 ? "" : `; its windows: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
|
|
86
86
|
}
|
|
87
87
|
export const PREVIOUS_WINDOW = "@previous";
|
|
88
88
|
/** Resolve "@previous" against oldest-first windows; every other value passes through. */
|
|
@@ -93,13 +93,13 @@ function resolveWindowId(projection, windowId) {
|
|
|
93
93
|
if (previous !== undefined)
|
|
94
94
|
return { ok: true, window_id: previous.windowId };
|
|
95
95
|
const known = projection.windows.map((current) => current.windowId);
|
|
96
|
-
return { ok: false, outcome: failure("unknown_window_id", `
|
|
96
|
+
return { ok: false, outcome: failure("unknown_window_id", `"${PREVIOUS_WINDOW}" has nothing to point at: this session has no window before the current one${knownWindowSuffix(known)}.`) };
|
|
97
97
|
}
|
|
98
98
|
function badWindowId(projection, params) {
|
|
99
99
|
const badWindow = unknownWindowId(projection, params);
|
|
100
100
|
if (!badWindow)
|
|
101
101
|
return undefined;
|
|
102
|
-
return failure("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}
|
|
102
|
+
return failure("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}.`);
|
|
103
103
|
}
|
|
104
104
|
/* ------------------------------------------------------------------ history_windows */
|
|
105
105
|
export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
|
|
@@ -125,14 +125,14 @@ export const historyWindows = {
|
|
|
125
125
|
data.windows.push(row);
|
|
126
126
|
data.more--;
|
|
127
127
|
}
|
|
128
|
-
return fits(data) ? success(data) : failure("output_too_large",
|
|
128
|
+
return fits(data) ? success(data) : failure("output_too_large", `The session id alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry.`);
|
|
129
129
|
},
|
|
130
130
|
render: (result) => renderOutcome(result, renderWindows),
|
|
131
131
|
};
|
|
132
132
|
function renderWindows(data) {
|
|
133
133
|
const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}`)];
|
|
134
134
|
if (data.more > 0)
|
|
135
|
-
lines.push(`${data.more} more windows not shown; \`history_list\` also
|
|
135
|
+
lines.push(`${data.more} more windows not shown; every \`history_list\` event also names its window.`);
|
|
136
136
|
return lines.join("\n");
|
|
137
137
|
}
|
|
138
138
|
/* ------------------------------------------------------------------ history_list */
|
|
@@ -179,22 +179,22 @@ export const historyRead = {
|
|
|
179
179
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
180
180
|
// consumed by a pairing. Only the last two can mention what is at the address.
|
|
181
181
|
if (item === undefined && params.seq > projection.highestSeq) {
|
|
182
|
-
return failure("unknown_seq", `
|
|
182
|
+
return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
183
183
|
}
|
|
184
184
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
185
|
-
return failure("not_on_branch", `
|
|
185
|
+
return failure("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
|
|
186
186
|
}
|
|
187
187
|
if (item === undefined) {
|
|
188
188
|
const callSeq = projection.pairedResults.get(params.seq);
|
|
189
189
|
if (callSeq !== undefined) {
|
|
190
|
-
return failure("not_an_event", `
|
|
190
|
+
return failure("not_an_event", `Seq ${params.seq} is a tool result, shown together with its call; read seq ${callSeq} instead.`);
|
|
191
191
|
}
|
|
192
|
-
return failure("unknown_seq", `
|
|
192
|
+
return failure("unknown_seq", `Seq ${params.seq} holds nothing to read.`);
|
|
193
193
|
}
|
|
194
194
|
const document = eventDocument(item);
|
|
195
195
|
const totalChars = Array.from(document).length;
|
|
196
196
|
if (typeof params.offset_chars === "number" && params.offset_chars > totalChars) {
|
|
197
|
-
return failure("invalid_offset", `
|
|
197
|
+
return failure("invalid_offset", `This event ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
198
198
|
}
|
|
199
199
|
return readTextWindow(document, params.offset_chars, params.max_chars, (window) => ({
|
|
200
200
|
seq: item.seq,
|
|
@@ -80,7 +80,7 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
80
80
|
export declare const notesWrite: {
|
|
81
81
|
readonly name: "notes_write";
|
|
82
82
|
readonly label: "Notes write";
|
|
83
|
-
readonly description: "Create or replace a note
|
|
83
|
+
readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
84
84
|
readonly parameters: Type.TObject<{
|
|
85
85
|
address: Type.TString;
|
|
86
86
|
content: Type.TString;
|
|
@@ -115,7 +115,7 @@ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
|
115
115
|
export declare const notesUpdate: {
|
|
116
116
|
readonly name: "notes_update";
|
|
117
117
|
readonly label: "Notes update";
|
|
118
|
-
readonly description: "Edit a note
|
|
118
|
+
readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
119
119
|
readonly parameters: Type.TObject<{
|
|
120
120
|
address: Type.TString;
|
|
121
121
|
edits: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -149,7 +149,7 @@ export declare const notesReadParameters: Type.TObject<{
|
|
|
149
149
|
export declare const notesRead: {
|
|
150
150
|
readonly name: "notes_read";
|
|
151
151
|
readonly label: "Notes read";
|
|
152
|
-
readonly description: "Read a note
|
|
152
|
+
readonly description: "Read a note. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
153
153
|
readonly parameters: Type.TObject<{
|
|
154
154
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
155
155
|
max_chars: Type.TOptional<Type.TInteger>;
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Type } from "typebox";
|
|
|
2
2
|
import { localIso } from "../notes/frontmatter.js";
|
|
3
3
|
import { isFilesystemError } from "../notes/fs-error.js";
|
|
4
4
|
import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
|
|
5
|
-
import { prefixFit } from "./output.js";
|
|
5
|
+
import { prefixFit, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
6
6
|
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
7
7
|
import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
|
|
8
8
|
const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
|
|
@@ -164,11 +164,11 @@ function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
164
164
|
files.push(reduced);
|
|
165
165
|
}
|
|
166
166
|
if (files.length === 0)
|
|
167
|
-
return failure("output_too_large",
|
|
167
|
+
return failure("output_too_large", `\`${item.address}\` won't fit on the list (${TOOL_OUTPUT_LIMIT} per call); narrow \`glob\` to leave it out.`);
|
|
168
168
|
break;
|
|
169
169
|
}
|
|
170
170
|
const outcome = success(data(files));
|
|
171
|
-
return fitsResult(outcome, render) ? outcome : failure("output_too_large",
|
|
171
|
+
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
|
|
172
172
|
}
|
|
173
173
|
function listedFile(row, identity) {
|
|
174
174
|
return { address: row.address, ...projectKeyField(row.scope, identity.projectKey), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
@@ -179,7 +179,7 @@ function renderWriteData(data) {
|
|
|
179
179
|
}
|
|
180
180
|
export const notesWrite = {
|
|
181
181
|
name: "notes_write", label: "Notes write",
|
|
182
|
-
description: `Create or replace a note
|
|
182
|
+
description: `Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
|
|
183
183
|
parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
|
|
184
184
|
async execute(params, identity) {
|
|
185
185
|
try {
|
|
@@ -214,19 +214,20 @@ function renderUpdate(result) {
|
|
|
214
214
|
}
|
|
215
215
|
/** A shortened diff still says so in the receipt's own text, on both surfaces. */
|
|
216
216
|
export const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
217
|
+
const RECEIPT_TOO_LONG = `Saved, but the receipt is too long to hand back (${TOOL_OUTPUT_LIMIT} per call). Check the note with \`notes_read\`.`;
|
|
217
218
|
/** Bound a mutation receipt on both surfaces; a huge diff is cut to the longest fitting prefix and marked. */
|
|
218
219
|
function boundedUpdate(data) {
|
|
219
220
|
if (fitsResult(success(data), renderUpdate))
|
|
220
221
|
return success(data);
|
|
221
222
|
if (data.diff === "")
|
|
222
|
-
return failure("output_too_large",
|
|
223
|
+
return failure("output_too_large", RECEIPT_TOO_LONG);
|
|
223
224
|
const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}\n${DIFF_SHORTENED_MARKER}` }), renderUpdate));
|
|
224
225
|
const result = success({ ...data, diff: `${diff}\n${DIFF_SHORTENED_MARKER}` });
|
|
225
|
-
return fitsResult(result, renderUpdate) ? result : failure("output_too_large",
|
|
226
|
+
return fitsResult(result, renderUpdate) ? result : failure("output_too_large", RECEIPT_TOO_LONG);
|
|
226
227
|
}
|
|
227
228
|
export const notesUpdate = {
|
|
228
229
|
name: "notes_update", label: "Notes update",
|
|
229
|
-
description: `Edit a note
|
|
230
|
+
description: `Edit a note, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
|
|
230
231
|
parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
|
|
231
232
|
async execute(params, identity, renderDiff) {
|
|
232
233
|
try {
|
|
@@ -257,17 +258,17 @@ function renderReadData(data) {
|
|
|
257
258
|
}
|
|
258
259
|
export const notesRead = {
|
|
259
260
|
name: "notes_read", label: "Notes read",
|
|
260
|
-
description: `Read a note
|
|
261
|
+
description: `Read a note. ${ADDRESS_DESCRIPTION}`,
|
|
261
262
|
parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
|
|
262
263
|
async execute(params, identity) {
|
|
263
264
|
try {
|
|
264
265
|
const note = await createNotesStore(identity).read(params.address);
|
|
266
|
+
const resolved = noteIdentity(identity, params.address);
|
|
265
267
|
if (!note)
|
|
266
|
-
return failure("not_found",
|
|
268
|
+
return failure("not_found", `No note at ${resolved.address}.`);
|
|
267
269
|
const totalChars = Array.from(note.body).length;
|
|
268
270
|
if (params.offset_chars !== undefined && params.offset_chars > totalChars)
|
|
269
|
-
return failure("invalid_offset", `
|
|
270
|
-
const resolved = noteIdentity(identity, params.address);
|
|
271
|
+
return failure("invalid_offset", `This note ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
271
272
|
const metadata = noteMetadata(note.meta);
|
|
272
273
|
return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
|
|
273
274
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** Budget primitives. Notes/history use result.ts; reset/budget tools retain output(). */
|
|
2
2
|
export { earliestMatchOffsetChars } from "../text-match.js";
|
|
3
3
|
export declare const TOOL_OUTPUT_MAX_BYTES: number;
|
|
4
|
+
/** The per-call limit as the model reads it in refusals. */
|
|
5
|
+
export declare const TOOL_OUTPUT_LIMIT = "32 KB";
|
|
4
6
|
export declare const DEFAULT_READ_WINDOW_CHARS = 12000;
|
|
5
7
|
export declare const MAX_READ_WINDOW_CHARS = 50000;
|
|
6
8
|
export declare const HISTORY_PREVIEW_CHARS = 1200;
|
package/dist/src/tools/output.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** Budget primitives. Notes/history use result.ts; reset/budget tools retain output(). */
|
|
2
2
|
export { earliestMatchOffsetChars } from "../text-match.js";
|
|
3
3
|
export const TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
|
|
4
|
+
/** The per-call limit as the model reads it in refusals. */
|
|
5
|
+
export const TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
|
|
4
6
|
export const DEFAULT_READ_WINDOW_CHARS = 12000;
|
|
5
7
|
export const MAX_READ_WINDOW_CHARS = 50000;
|
|
6
8
|
export const HISTORY_PREVIEW_CHARS = 1200;
|
package/dist/src/tools/result.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Internal outcomes, compact wire results, and bounded read windows. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import { DEFAULT_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_MAX_BYTES, withinTextBudget } from "./output.js";
|
|
3
|
+
import { DEFAULT_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT, TOOL_OUTPUT_MAX_BYTES, withinTextBudget } from "./output.js";
|
|
4
4
|
/** The one refusal shape: `code` is a stable internal identifier, `message` the bounded reading. */
|
|
5
5
|
export const OperationErrorSchema = Type.Object({
|
|
6
6
|
code: Type.String(),
|
|
@@ -94,7 +94,7 @@ export function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
94
94
|
high = mid - 1;
|
|
95
95
|
}
|
|
96
96
|
if (low === 0)
|
|
97
|
-
return failure("output_too_large",
|
|
97
|
+
return failure("output_too_large", `Its header alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry; no room left for the text.`);
|
|
98
98
|
return success(makeData(window(low)));
|
|
99
99
|
}
|
|
100
100
|
/** The continuation line never becomes part of `window.text`, and a complete window has none. */
|
package/dist/src/tools/schema.js
CHANGED
|
@@ -22,10 +22,10 @@ export class InvalidQueryError extends Error {
|
|
|
22
22
|
export function searchQueries(query) {
|
|
23
23
|
const candidates = typeof query === "string" ? [query] : query;
|
|
24
24
|
if (!Array.isArray(candidates) || candidates.length === 0)
|
|
25
|
-
throw new InvalidQueryError("query must be a string or a non-empty
|
|
25
|
+
throw new InvalidQueryError("`query` must be a string or a non-empty list of strings.");
|
|
26
26
|
if (!candidates.every((candidate) => typeof candidate === "string"))
|
|
27
|
-
throw new InvalidQueryError("query
|
|
27
|
+
throw new InvalidQueryError("Every item in the `query` list must be a string.");
|
|
28
28
|
if (candidates.some((candidate) => candidate === ""))
|
|
29
|
-
throw new InvalidQueryError("query
|
|
29
|
+
throw new InvalidQueryError("`query` can't be an empty string; it would match everything.");
|
|
30
30
|
return candidates;
|
|
31
31
|
}
|