notesoup 0.59.2 → 0.60.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/README.md +3 -17
- package/dist/plugins/claude/src/helper.js +1 -2
- package/dist/plugins/codex/src/mcp.js +1 -2
- package/dist/plugins/dsh/tools.js +1 -2
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +2 -3
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- package/dist/src/history/query.d.ts +3 -14
- package/dist/src/history/query.js +73 -85
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/address.js +3 -3
- package/dist/src/notes/store.d.ts +2 -4
- package/dist/src/notes/store.js +1 -2
- package/dist/src/tools/history.d.ts +4 -6
- package/dist/src/tools/history.js +69 -29
- package/dist/src/tools/notes.d.ts +18 -78
- package/dist/src/tools/notes.js +39 -50
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/claude-history.test.js +5 -6
- package/dist/test/claude-mod.test.js +6 -7
- package/dist/test/codex-history.test.js +1 -1
- package/dist/test/codex-plugin.test.js +1 -2
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh.test.js +2 -2
- package/dist/test/history-corpus.test.js +21 -36
- package/dist/test/history-summary-cache.test.js +3 -3
- package/dist/test/history.integration.test.js +53 -106
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/note-policy.test.js +5 -5
- package/dist/test/notes-cwd.test.js +5 -5
- package/dist/test/notes-query-namespaces.test.js +2 -6
- package/dist/test/notes.integration.test.js +30 -35
- package/dist/test/notes.test.js +12 -14
- package/dist/test/project-namespace.test.js +3 -3
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +8 -9
- package/docs/notes-library.md +3 -3
- package/docs/tool-results.md +12 -6
- package/package.json +1 -1
- package/plugins/claude/dist/claude/helper.js +162 -153
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +1 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +161 -152
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/history/history.ts +11 -16
- package/src/history/query.ts +67 -99
- package/src/index.ts +1 -1
- package/src/notes/address.ts +2 -2
- package/src/notes/store.ts +3 -6
- package/src/tools/history.ts +60 -29
- package/src/tools/notes.ts +39 -54
- package/src/tools/schema.ts +0 -1
package/src/tools/notes.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
|
10
10
|
import { failure, success, type Outcome } from "../result.js";
|
|
11
11
|
import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
|
|
12
12
|
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
13
|
-
import {
|
|
13
|
+
import { searchQuery } from "./schema.js";
|
|
14
14
|
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;
|
|
@@ -39,7 +39,7 @@ function withWarnings(text: string, data: { warnings: string[] }): string {
|
|
|
39
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
40
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
|
|
41
41
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
|
|
42
|
-
const GLOB_PARAMETER =
|
|
42
|
+
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "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
43
|
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
44
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." });
|
|
45
45
|
|
|
@@ -155,11 +155,6 @@ const MatchSchema = Type.Object({
|
|
|
155
155
|
offset_chars: Type.Integer(),
|
|
156
156
|
}, { additionalProperties: false });
|
|
157
157
|
|
|
158
|
-
const SearchedFileSchema = Type.Object({
|
|
159
|
-
...ListedFileSchema.properties,
|
|
160
|
-
matches: Type.Array(MatchSchema), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
161
|
-
}, { additionalProperties: false });
|
|
162
|
-
|
|
163
158
|
export const SnapshotSchema = {
|
|
164
159
|
more: Type.Integer({ description: "How many more were left out." }),
|
|
165
160
|
namespaces_unavailable: Type.Array(Type.String(), { description: "Unreadable notebooks or notes." }),
|
|
@@ -191,16 +186,15 @@ export const NotesReadDataSchema = Type.Object({
|
|
|
191
186
|
export type NotesReadData = Static<typeof NotesReadDataSchema>;
|
|
192
187
|
|
|
193
188
|
export const NotesListDataSchema = Type.Object({
|
|
194
|
-
files: Type.Array(
|
|
189
|
+
files: Type.Array(Type.Object({
|
|
190
|
+
...ListedFileSchema.properties,
|
|
191
|
+
matches: Type.Optional(Type.Array(MatchSchema)), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
192
|
+
}, { additionalProperties: false })),
|
|
195
193
|
...SnapshotSchema,
|
|
196
194
|
}, { additionalProperties: false });
|
|
197
195
|
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
files: Type.Array(SearchedFileSchema),
|
|
201
|
-
...SnapshotSchema,
|
|
202
|
-
}, { additionalProperties: false });
|
|
203
|
-
export type NotesSearchData = Static<typeof NotesSearchDataSchema>;
|
|
196
|
+
type ListedFile = Static<typeof ListedFileSchema>;
|
|
197
|
+
type SearchFile = ListedFile & { matches: Static<typeof MatchSchema>[]; more_matches?: number };
|
|
204
198
|
|
|
205
199
|
type Snapshot<T> = Omit<NotesListData, "files"> & { files: T[] };
|
|
206
200
|
|
|
@@ -232,7 +226,7 @@ export function snapshot<T extends { address: string }>(
|
|
|
232
226
|
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable notebooks is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer notebooks.`);
|
|
233
227
|
}
|
|
234
228
|
|
|
235
|
-
export function listedFile(row: Pick<NoteRow, "address" | "meta"> & { body?: string; warnings?: string[] }, identity: NotesIdentity):
|
|
229
|
+
export function listedFile(row: Pick<NoteRow, "address" | "meta"> & { body?: string; warnings?: string[] }, identity: NotesIdentity): ListedFile {
|
|
236
230
|
const policy = policyAt(row.meta, row.address);
|
|
237
231
|
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 }) };
|
|
238
232
|
}
|
|
@@ -321,48 +315,31 @@ export const notesRead = {
|
|
|
321
315
|
render: (result: Outcome<NotesReadData>): string => renderOutcome(result, renderReadData),
|
|
322
316
|
} as const;
|
|
323
317
|
|
|
324
|
-
export const notesListParameters = Type.Object({
|
|
318
|
+
export const notesListParameters = Type.Object({
|
|
319
|
+
glob: GLOB_PARAMETER,
|
|
320
|
+
query: Type.Optional(searchQuery()),
|
|
321
|
+
max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "How many hit lines per note at most; requires a query." })),
|
|
322
|
+
crumpled: CRUMPLED_LIST_PARAMETER,
|
|
323
|
+
limit: FILE_LIMIT_PARAMETER,
|
|
324
|
+
cwd: CWD_PARAMETER,
|
|
325
|
+
}, { additionalProperties: false });
|
|
325
326
|
|
|
326
327
|
export function renderListData(data: Snapshot<NotesListData["files"][number] & { last_accessed?: string }>): string {
|
|
327
328
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
328
329
|
for (const file of data.files) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return lines.join("\n");
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export const notesList = {
|
|
338
|
-
name: "notes_list", label: "Notes list",
|
|
339
|
-
description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile — narrow `glob`.",
|
|
340
|
-
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
341
|
-
async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
|
|
342
|
-
try {
|
|
343
|
-
const identity = notesIdentityForCall(context, params.cwd);
|
|
344
|
-
const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
345
|
-
return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
|
|
346
|
-
} catch (error) { return failureOf(error); }
|
|
347
|
-
},
|
|
348
|
-
render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
|
|
349
|
-
} as const;
|
|
350
|
-
|
|
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 });
|
|
352
|
-
|
|
353
|
-
function renderSearchData(data: NotesSearchData): string {
|
|
354
|
-
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
355
|
-
for (const file of data.files) {
|
|
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` : ""}`);
|
|
330
|
+
const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
|
|
331
|
+
if (file.last_accessed !== undefined) fields.push(`accessed ${file.last_accessed}`);
|
|
332
|
+
if (file.crumpled_at !== undefined) fields.push(`crumpled ${file.crumpled_at}`);
|
|
333
|
+
if (file.matches) fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
334
|
+
lines.push(fields.join(" | "));
|
|
357
335
|
lines.push(...file.warnings.map(warning => ` ${warning}`));
|
|
358
|
-
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
336
|
+
for (const match of file.matches ?? []) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
359
337
|
}
|
|
360
338
|
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
361
339
|
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
362
340
|
return lines.join("\n");
|
|
363
341
|
}
|
|
364
342
|
|
|
365
|
-
type SearchFile = NotesSearchData["files"][number];
|
|
366
343
|
function keepMatches(file: SearchFile, count = file.matches.length): SearchFile {
|
|
367
344
|
const more = (file.more_matches ?? 0) + Math.max(0, file.matches.length - count);
|
|
368
345
|
return { ...file, matches: file.matches.slice(0, count), ...(more ? { more_matches: more } : {}) };
|
|
@@ -386,20 +363,28 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
|
|
|
386
363
|
return withText(prefixFit(first.text, text => fits(withText(text))));
|
|
387
364
|
}
|
|
388
365
|
|
|
389
|
-
export const
|
|
390
|
-
name: "
|
|
391
|
-
description: "
|
|
392
|
-
parameters:
|
|
393
|
-
async execute(params: Static<typeof
|
|
366
|
+
export const notesList = {
|
|
367
|
+
name: "notes_list", label: "Notes list",
|
|
368
|
+
description: "List or search notes, newest pages on top. A query matches literal text (ignoring case) and returns hit lines and read offsets. One pass; `more` counts pages left on the pile — narrow `glob`.",
|
|
369
|
+
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
370
|
+
async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
|
|
394
371
|
try {
|
|
372
|
+
const queries = searchQueries(params.query);
|
|
373
|
+
const { glob, crumpled, limit } = params;
|
|
374
|
+
if (!queries.length && params.max_matches_per_file !== undefined) return failure("invalid_params", "`max_matches_per_file` requires a non-empty `query`.");
|
|
395
375
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
396
|
-
const
|
|
376
|
+
const store = createNotesStore(identity);
|
|
377
|
+
if (!queries.length) {
|
|
378
|
+
const { rows, status } = await store.listWithStatus({ glob, crumpled });
|
|
379
|
+
return snapshot(rows.map(row => listedFile(row, identity)), limit, status, renderListData);
|
|
380
|
+
}
|
|
381
|
+
const { rows, status } = await store.searchWithStatus(queries, { glob, crumpled });
|
|
397
382
|
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => keepMatches({
|
|
398
383
|
...listedFile(row, identity),
|
|
399
384
|
matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
|
|
400
385
|
}, params.max_matches_per_file));
|
|
401
|
-
return snapshot(files,
|
|
386
|
+
return snapshot(files, limit, status, renderListData, fitSearchFile);
|
|
402
387
|
} catch (error) { return failureOf(error); }
|
|
403
388
|
},
|
|
404
|
-
render: (result: Outcome<
|
|
389
|
+
render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
|
|
405
390
|
} as const;
|
package/src/tools/schema.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type, type TSchema } from "typebox";
|
|
2
2
|
import { Errors } from "typebox/value";
|
|
3
3
|
import { HistoryRoleSchema } from "../history/history.js";
|
|
4
|
-
export const nullableString = (description?: string) => Type.Optional(Type.Union([Type.String(), Type.Null()], description === undefined ? {} : { description }));
|
|
5
4
|
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
5
|
|
|
7
6
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|