notesoup 0.59.0 → 0.59.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.
@@ -15,12 +15,12 @@ import { notesIdentityForCall, type NotesToolContext } from "./notes-context.js"
15
15
 
16
16
  const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")] as const;
17
17
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
18
- description: "(optional) Who wrote it: user, self, or external. Omit to keep the existing origin; new notes default to self.",
18
+ description: "Whose handwriting: user, self, or external. Leave it out to keep what's there.",
19
19
  }));
20
20
  const POLICY_PARAMETERS = {
21
- pinned: Type.Optional(Type.Boolean({ description: "Inject the full body at boot. At most 5 live pins per notebook; root CHEATSHEET.md/MAP.md default true, all others false. Explicit false overrides the default." })),
22
- budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "Body budget in Unicode code points (default 4096; root CHEATSHEET.md and MAP.md default 2048). Over budget warns but saves; boot does not truncate." })),
23
- readonly: Type.Optional(Type.Boolean({ description: "Soft lock, not a security boundary. true locks changes; explicitly pass false to unlock, including in the same call as edits or overwrite." })),
21
+ pinned: Type.Optional(Type.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET and MAP included." })),
22
+ budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "How much paper the page gets. Writing past it still saves, with a warning. A page over budget gets boiled down: stale lines out, repeats merged, the rest said shorter. More paper is for a page already boiled down that still needs the room." })),
23
+ readonly: Type.Optional(Type.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off — same call is fine." })),
24
24
  };
25
25
  const PolicySchema = {
26
26
  pinned: Type.Boolean(), budget: Type.Integer(), readonly: Type.Boolean(),
@@ -36,13 +36,12 @@ function withWarnings(text: string, data: { warnings: string[] }): string {
36
36
  return [text, ...data.warnings].join("\n");
37
37
  }
38
38
 
39
- const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
40
- const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
41
- const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
42
- const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current notebooks.");
43
- const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "(optional) Select the current project for this call. A relative path resolves against the host session cwd; the path must be an existing directory." }));
44
- const QUERY_NAMESPACES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions.";
45
- const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
39
+ const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
40
+ const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
41
+ const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
42
+ const GLOB_PARAMETER = nullableString("Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf · `MAP.md` that page in every notebook · `**` everything · `@sessions/*/**` every session.");
43
+ const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
44
+ const ADDRESS_PARAMETER = Type.String({ description: "Which drawer the page sits in. `plan.md` — this session's desk, cleared when it ends. `@project/` this project's shelf · `@human/` your human's file · `@self/` your own notebook · `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` — someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
46
45
 
47
46
  /**
48
47
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
@@ -158,7 +157,7 @@ const MatchSchema = Type.Object({
158
157
 
159
158
  const SearchedFileSchema = Type.Object({
160
159
  ...ListedFileSchema.properties,
161
- matches: Type.Array(MatchSchema),
160
+ matches: Type.Array(MatchSchema), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
162
161
  }, { additionalProperties: false });
163
162
 
164
163
  export const SnapshotSchema = {
@@ -238,7 +237,7 @@ export function listedFile(row: Pick<NoteRow, "address" | "meta"> & { body?: str
238
237
  return { ...noteIdentity(identity, row.address), ...policy, warnings: row.warnings ?? (row.body === undefined ? [] : noteBudgetWarnings(row.body, policy)), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
239
238
  }
240
239
 
241
- export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
240
+ export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "The whole page." }), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
242
241
 
243
242
  function renderWriteData(data: NotesWriteData): string {
244
243
  return withWarnings(`${data.outcome} ${renderIdentity(data)} | ${renderPolicy(data)}`, data);
@@ -246,7 +245,7 @@ function renderWriteData(data: NotesWriteData): string {
246
245
 
247
246
  export const notesWrite = {
248
247
  name: "notes_write", label: "Notes write",
249
- description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
248
+ description: "Take a fresh page and write it — or rip out the old one and write it again. Title it for what's inside and when you'll reach for it.",
250
249
  parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
251
250
  async execute(params: Static<typeof notesWriteParameters>, context: NotesToolContext): Promise<Outcome<NotesWriteData>> {
252
251
  try {
@@ -259,13 +258,13 @@ export const notesWrite = {
259
258
  } as const;
260
259
 
261
260
  export const notesUpdateParameters = Type.Object({
262
- address: Type.String(),
263
- edits: Type.Optional(Type.Array(Type.Object({ oldText: Type.String(), newText: Type.String() }, { additionalProperties: false }))),
261
+ address: ADDRESS_PARAMETER,
262
+ edits: Type.Optional(Type.Array(Type.Object({ oldText: Type.String({ description: "The passage as it stands on the page." }), newText: Type.String({ description: "What goes in its place." }) }, { additionalProperties: false }), { description: "Pen strokes, in order. Each `oldText` is the exact passage — same case, found once — and `newText` is what goes in its place." })),
264
263
  origin: ORIGIN,
265
264
  ...POLICY_PARAMETERS,
266
265
  crumpled: CRUMPLED_PARAMETER,
267
- replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
268
- rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, optionally with edits or metadata changes. Won't overwrite a live note; references aren't updated." })),
266
+ replace_all: Type.Optional(Type.Boolean({ description: "Strike every copy of `oldText`, not just one." })),
267
+ rename_to: Type.Optional(Type.String({ description: "Move the page to another address. Never lands on top of a live page; nothing pointing at it follows." })),
269
268
  cwd: CWD_PARAMETER,
270
269
  }, { additionalProperties: false });
271
270
 
@@ -278,7 +277,7 @@ function renderUpdateData(data: NotesUpdateData): string {
278
277
 
279
278
  export const notesUpdate = {
280
279
  name: "notes_update", label: "Notes update",
281
- description: `Change part of a note's body, policy (pinned/budget/readonly), origin, crumpled state, or address. A readonly note requires explicit readonly:false before any change, or in the same call. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
280
+ description: "Work on a page you already have: cross out and rewrite lines, move it, pin it, lock it, give it more paper, crumple it. Keep every page true to now: wrong, stale, or no-longer-mattering lines get rewritten or struck where they stand. The page stays one page.",
282
281
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
283
282
  async execute(params: Static<typeof notesUpdateParameters>, context: NotesToolContext, onChange?: (change: NoteChange) => void): Promise<Outcome<NotesUpdateData>> {
284
283
  try {
@@ -296,7 +295,7 @@ export const notesUpdate = {
296
295
  render: (result: Outcome<NotesUpdateData>): string => renderOutcome(result, renderUpdateData),
297
296
  } as const;
298
297
 
299
- export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
298
+ export const notesReadParameters = Type.Object({ address: ADDRESS_PARAMETER, ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
300
299
 
301
300
  function renderReadData(data: NotesReadData): string {
302
301
  return withWarnings(`${renderIdentity(data)}\n${renderMetadata(data.metadata)}`, data) + `\n\n${renderTextWindow(data)}`;
@@ -304,7 +303,7 @@ function renderReadData(data: NotesReadData): string {
304
303
 
305
304
  export const notesRead = {
306
305
  name: "notes_read", label: "Notes read",
307
- description: `Read a note. ${ADDRESS_DESCRIPTION}`,
306
+ description: "Read a page. Long ones come a stretch at a time; follow `next_offset_chars`.",
308
307
  parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
309
308
  async execute(params: Static<typeof notesReadParameters>, context: NotesToolContext): Promise<Outcome<NotesReadData>> {
310
309
  try {
@@ -337,7 +336,7 @@ export function renderListData(data: Snapshot<NotesListData["files"][number] & {
337
336
 
338
337
  export const notesList = {
339
338
  name: "notes_list", label: "Notes list",
340
- description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
339
+ description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile — narrow `glob`.",
341
340
  parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
342
341
  async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
343
342
  try {
@@ -349,12 +348,12 @@ export const notesList = {
349
348
  render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
350
349
  } as const;
351
350
 
352
- 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, cwd: CWD_PARAMETER }, { additionalProperties: false });
351
+ 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: "How many hit lines per page at most." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
353
352
 
354
353
  function renderSearchData(data: NotesSearchData): string {
355
354
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
356
355
  for (const file of data.files) {
357
- lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
356
+ lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
358
357
  lines.push(...file.warnings.map(warning => ` ${warning}`));
359
358
  for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
360
359
  }
@@ -364,6 +363,10 @@ function renderSearchData(data: NotesSearchData): string {
364
363
  }
365
364
 
366
365
  type SearchFile = NotesSearchData["files"][number];
366
+ function keepMatches(file: SearchFile, count = file.matches.length): SearchFile {
367
+ const more = (file.more_matches ?? 0) + Math.max(0, file.matches.length - count);
368
+ return { ...file, matches: file.matches.slice(0, count), ...(more ? { more_matches: more } : {}) };
369
+ }
367
370
 
368
371
  /** A shortened match line still ends with a marker, so its own text says it was cut. */
369
372
  export const MATCH_SHORTENED_MARKER = " [truncated]";
@@ -374,28 +377,27 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
374
377
  let high = file.matches.length;
375
378
  while (low < high) {
376
379
  const mid = Math.ceil((low + high) / 2);
377
- if (fits({ ...file, matches: file.matches.slice(0, mid) })) low = mid;
380
+ if (fits(keepMatches(file, mid))) low = mid;
378
381
  else high = mid - 1;
379
382
  }
380
- if (low > 0) return { ...file, matches: file.matches.slice(0, low) };
381
- const first = file.matches[0];
382
- if (!first) return file;
383
- const withText = (text: string): SearchFile => ({ ...file, matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
383
+ if (low > 0 || file.matches.length === 0) return keepMatches(file, low);
384
+ const first = file.matches[0]!;
385
+ const withText = (text: string): SearchFile => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
384
386
  return withText(prefixFit(first.text, text => fits(withText(text))));
385
387
  }
386
388
 
387
389
  export const notesSearch = {
388
390
  name: "notes_search", label: "Notes search",
389
- 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. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
391
+ description: "Run a finger down every page for some text, case doesn't matter. Returns the lines it hits and where they sit; no query just lists the pages. One pass; `more` counts pages left on the pile — narrow `glob`.",
390
392
  parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
391
393
  async execute(params: Static<typeof notesSearchParameters>, context: NotesToolContext): Promise<Outcome<NotesSearchData>> {
392
394
  try {
393
395
  const identity = notesIdentityForCall(context, params.cwd);
394
396
  const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
395
- const files: NotesSearchData["files"] = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => ({
397
+ const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => keepMatches({
396
398
  ...listedFile(row, identity),
397
- matches: row.matches.slice(0, params.max_matches_per_file).map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
398
- }));
399
+ matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
400
+ }, params.max_matches_per_file));
399
401
  return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
400
402
  } catch (error) { return failureOf(error); }
401
403
  },
@@ -50,8 +50,8 @@ export type TextWindow = Static<typeof TextWindowSchema>;
50
50
  * because `readTextWindow` already owns the defaults.
51
51
  */
52
52
  export const TextWindowRequestSchema = {
53
- offset_chars: Type.Optional(Type.Integer({ description: "(optional, default 0) Start offset in chars; negative counts from the end." })),
54
- max_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${DEFAULT_READ_WINDOW_CHARS}) Max chars to return.` })),
53
+ offset_chars: Type.Optional(Type.Integer({ description: "Where on the page to start reading; negative counts from the end." })),
54
+ max_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much to read at once." })),
55
55
  };
56
56
 
57
57
  /**
@@ -2,7 +2,7 @@ import { Type, type TSchema } from "typebox";
2
2
  import { Errors } from "typebox/value";
3
3
  import { HistoryRoleSchema } from "../history/history.js";
4
4
  export const nullableString = (description?: string) => Type.Optional(Type.Union([Type.String(), Type.Null()], description === undefined ? {} : { description }));
5
- 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
+ export const historyRoles = () => Type.Optional(Type.Array(HistoryRoleSchema, { minItems: 1, description: "Only these voices: user, assistant, tool, context. Without roles or query, tool and context runs fold into one line." }));
6
6
 
7
7
  /** First parameter violation; skip false subschemas so additionalProperties can name the field. */
8
8
  export function paramProblem(schema: TSchema, params: unknown): string {
@@ -14,4 +14,4 @@ export function paramProblem(schema: TSchema, params: unknown): string {
14
14
  }
15
15
 
16
16
  /** Search query parameter: one literal, or several literals combined with OR. */
17
- 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 });
17
+ export const searchQuery = (description = "Text to look for, or a list (any match). Leave it out to just list the pages.") => Type.Union([Type.String(), Type.Array(Type.String())], { description });