notesoup 0.46.0 → 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/dist/src/history/query.js +18 -23
- package/dist/src/notes/store.js +4 -0
- 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/history.integration.test.js +8 -3
- package/dist/test/notes.integration.test.js +21 -0
- package/dist/test/notes.test.js +1 -1
- package/docs/notes-library.md +1 -1
- package/docs/tool-results.md +1 -1
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +10 -7
- package/package.json +1 -1
- package/src/history/query.ts +16 -20
- package/src/notes/store.ts +4 -0
- package/src/tools/history.ts +1 -1
- package/src/tools/notes.ts +2 -2
- package/src/tools/schema.ts +5 -12
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -60,7 +60,7 @@ test("history_list exposes bounded paging, `from` and a literal query, while not
|
|
|
60
60
|
for (const retired of [{ before: 5 }, { after: 5 }, { order: "oldest" }, { limit_chars: 10 }]) {
|
|
61
61
|
assert.equal(Check(listSchema, retired), false, `${Object.keys(retired)[0]} is refused as an unknown parameter`);
|
|
62
62
|
}
|
|
63
|
-
assert.equal(Check(listSchema, { query: "" }), true, "an empty literal is
|
|
63
|
+
assert.equal(Check(listSchema, { query: "" }), true, "an empty literal is equivalent to an omitted query");
|
|
64
64
|
for (const invalid of [{ roles: ["tool_call"] }, { roles: ["system"] }, { tool_name: "bash" }, { roles: [] }]) {
|
|
65
65
|
assert.equal(Check(listSchema, invalid), false, JSON.stringify(invalid));
|
|
66
66
|
}
|
|
@@ -462,7 +462,7 @@ test("compaction summary becomes context and is folded in the default list", asy
|
|
|
462
462
|
const contextItems = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
|
|
463
463
|
assert.deepEqual(contextItems.items.map((item) => [item.role, item.content]), [["context", "summary needle"]]);
|
|
464
464
|
});
|
|
465
|
-
test("a query covers every role, carries match offsets and
|
|
465
|
+
test("a query covers every role, carries match offsets and treats empty queries as omitted", async () => {
|
|
466
466
|
const session = manager();
|
|
467
467
|
const captured = makeExtension(session);
|
|
468
468
|
const ctx = context(session);
|
|
@@ -483,7 +483,12 @@ test("a query covers every role, carries match offsets and refuses an empty lite
|
|
|
483
483
|
const absent = await call(captured, "history_list", { query: "absent" }, ctx);
|
|
484
484
|
assert.deepEqual(page(absent).items, []);
|
|
485
485
|
assert.notEqual(rendered(absent).trim(), "", "an empty page says so instead of rendering nothing");
|
|
486
|
-
|
|
486
|
+
for (const query of ["", [], ["", ""]]) {
|
|
487
|
+
assert.deepEqual(page(await call(captured, "history_list", { query }, ctx)), page(await call(captured, "history_list", {}, ctx)), "empty queries preserve conversation folding");
|
|
488
|
+
const filters = { roles: ["context"], after_seq: 1, before_seq: 3 };
|
|
489
|
+
assert.deepEqual(page(await call(captured, "history_list", { ...filters, query }, ctx)), page(await call(captured, "history_list", filters, ctx)), "other filters still apply");
|
|
490
|
+
}
|
|
491
|
+
assert.deepEqual(page(await call(captured, "history_list", { query: ["", "needle"] }, ctx)), all, "empty entries do not turn OR into match-all");
|
|
487
492
|
});
|
|
488
493
|
test("page_older and page_newer round-trip a session with no duplicates and no gaps", async () => {
|
|
489
494
|
const session = manager();
|
|
@@ -44,6 +44,27 @@ test("notes_list and notes_search are recent-first snapshots with narrowing hint
|
|
|
44
44
|
assert.deepEqual(narrowed.files.map((file) => file.address), ["@project/design.md"]);
|
|
45
45
|
assert.equal(narrowed.more, 0);
|
|
46
46
|
});
|
|
47
|
+
test("empty notes queries list scoped notes without fabricated matches", async () => {
|
|
48
|
+
const session = manager();
|
|
49
|
+
const captured = makeExtension(session);
|
|
50
|
+
const ctx = context(session);
|
|
51
|
+
for (const [address, content] of [["empty-query/blank.md", ""], ["empty-query/hit.md", "needle"], ["outside.md", "needle"]]) {
|
|
52
|
+
await call(captured, "notes_write", { address, content }, ctx);
|
|
53
|
+
}
|
|
54
|
+
await call(captured, "notes_write", { address: "empty-query/hidden.md", content: "needle" }, ctx);
|
|
55
|
+
await call(captured, "notes_update", { address: "empty-query/hidden.md", crumpled: true }, ctx);
|
|
56
|
+
for (const crumpled of [false, true]) {
|
|
57
|
+
const filters = { glob: "empty-query/**", crumpled, limit: 1 };
|
|
58
|
+
const listed = resultData(await call(captured, "notes_list", filters, ctx));
|
|
59
|
+
const expected = { ...listed, files: listed.files.map(file => ({ ...file, matches: [] })) };
|
|
60
|
+
for (const query of [undefined, "", [], ["", ""]]) {
|
|
61
|
+
assert.deepEqual(resultData(await call(captured, "notes_search", { ...filters, query }, ctx)), expected);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const filters = { glob: "empty-query/**" };
|
|
65
|
+
assert.deepEqual(resultData(await call(captured, "notes_search", { ...filters, query: ["", "needle"] }, ctx)), resultData(await call(captured, "notes_search", { ...filters, query: "needle" }, ctx)));
|
|
66
|
+
assert.equal(resultError(await call(captured, "notes_search", { query: [42] }, ctx)).code, "invalid_query");
|
|
67
|
+
});
|
|
47
68
|
test("notes_list reports omitted files when the wire budget truncates the snapshot", async () => {
|
|
48
69
|
const session = manager();
|
|
49
70
|
const captured = makeExtension(session);
|
package/dist/test/notes.test.js
CHANGED
|
@@ -421,7 +421,7 @@ test("list and search merge scopes and carry addresses; the path jail rejects es
|
|
|
421
421
|
assert.equal(resultError(await call(captured, tool, { address: path, content: "x", edits: [{ oldText: "a", newText: "b" }] }, ctx)).code, "invalid_address");
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
|
-
assert.
|
|
424
|
+
assert.deepEqual(resultData(await call(captured, "notes_search", { query: "" }, ctx)), resultData(await call(captured, "notes_search", {}, ctx)));
|
|
425
425
|
assert.equal(resultError(await call(captured, "notes_read", { address: "one.md", offset_chars: 99999 }, ctx)).code, "invalid_offset");
|
|
426
426
|
assert.equal(resultError(await call(captured, "notes_list", { glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
|
|
427
427
|
assert.equal(resultError(await call(captured, "notes_search", { query: "needle", glob: "bad\\glob" }, ctx)).code, "invalid_pattern");
|
package/docs/notes-library.md
CHANGED
|
@@ -37,7 +37,7 @@ const matches = await notes.search(["library"]);
|
|
|
37
37
|
- `update(address, edits?, { origin?, crumpled?, replaceAll? }?)` returns `Promise<{ meta, applied, resolvedScope, change }>`. Edits affect the body; metadata-only changes need no edits, but must supply `origin` or `crumpled`. `crumpled: true` records `crumpledAt` (keeping the original time if already set); `crumpled: false` removes it; omitted leaves it unchanged. Crumpling and smoothing never change `updatedAt`, which tracks body or origin changes only. Each replacement uses the evolving body in array order; the complete batch is written atomically only after every edit succeeds. `change` is a typed `{ kind, before, after }`: `kind` is `body`, `metadata`, or `none` with empty strings when neither body, origin, nor `crumpledAt` changed. A body change that also rewrites frontmatter is still `body`, and its diff inputs then span the whole serialized file. It is not a rendered diff.
|
|
38
38
|
- `rename(fromAddress, toAddress)` returns `Promise<{ meta, replacedCrumpledTarget }>`. The note moves with every metadata key preserved (`updatedAt` is bumped); a live note at the target refuses with `already_exists`, a crumpled target is replaced, and renaming onto the same resolved path is `nothing_to_do`.
|
|
39
39
|
- `list({ glob?, scope?, who?, crumpled? }?)` returns `Promise<NoteRow[]>`, sorted by update time descending with address tie-breaking. Rows contain address, scope, virtual path, metadata, body, and body byte size. `scope` narrows the five-home view; `who` names a concrete agent/model home. By default crumpled notes are excluded; `crumpled: true` returns only crumpled notes instead.
|
|
40
|
-
- `search(queries: string[], { glob?, scope?, who?, crumpled? }?)` returns `Promise<NoteSearchRow[]>`, sorted by address, with the same crumpled-note rule as `list`.
|
|
40
|
+
- `search(queries: string[], { glob?, scope?, who?, crumpled? }?)` returns `Promise<NoteSearchRow[]>`, sorted by address, with the same crumpled-note rule as `list`. An empty queries array disables filtering and returns scoped notes with empty `matches`. Otherwise matching is case-insensitive literal OR over body lines; matches contain one-based `line`, `text`, and `offsetChars` into the body, excluding frontmatter. Neither listing nor search increments access metadata.
|
|
41
41
|
|
|
42
42
|
`list` and `search` share the `NotesQuery` type. A merged query uses `{ glob?, crumpled? }`; a single-home query adds `scope`. Only `scope: "agent" | "model"` accepts `who`. TypeScript rejects combinations such as `{ scope: "project", who: "root" }`, and JavaScript callers receive a runtime refusal.
|
|
43
43
|
|
package/docs/tool-results.md
CHANGED
|
@@ -61,7 +61,7 @@ Pi's nested records contain child ID, name, optional arguments, status, timing a
|
|
|
61
61
|
|
|
62
62
|
One selection determines the structured result and its text. Both complete representations must fit the 32 KiB output budget, including metadata, cursor and rendered notice. A programmatic caller does not receive an unbounded hidden payload beside a truncated textual one.
|
|
63
63
|
|
|
64
|
-
History pages carry `page_older` and `page_newer`, the exact params to merge into the next call; `from` picks which end of a bounded range `limit` counts from, `since`/`until` narrow that range by event `created_at`, and only a call without roles or query folds tool/context runs. Notes listings/search are snapshots with a `more` count and can be narrowed by `glob`; they are not falsely advertised as paginated. `history_windows` is a snapshot too: its `more` counts the windows the budget left out and there is no window cursor, because `history_list` rows also expose `window_id`. A read can stop anywhere in the event document, including inside serialized arguments; concatenate its verbatim text slices before parsing any arguments. There is no separately truncated arguments object.
|
|
64
|
+
History pages carry `page_older` and `page_newer`, the exact params to merge into the next call; `from` picks which end of a bounded range `limit` counts from, `since`/`until` narrow that range by event `created_at`, and only a call without roles or a non-empty query folds tool/context runs. Omitted queries, empty strings and empty lists all disable search filtering; empty entries in a query list are ignored. Without a query, notes search returns scoped notes with empty `matches`, not every body line. Notes listings/search are snapshots with a `more` count and can be narrowed by `glob`; they are not falsely advertised as paginated. `history_windows` is a snapshot too: its `more` counts the windows the budget left out and there is no window cursor, because `history_list` rows also expose `window_id`. A read can stop anywhere in the event document, including inside serialized arguments; concatenate its verbatim text slices before parsing any arguments. There is no separately truncated arguments object.
|
|
65
65
|
|
|
66
66
|
A note read reports unrecognized frontmatter under `metadata.extra`; a value too large to carry, or past the verbatim budget, is named in place as `[omitted: too large]` under its key rather than delivered in part, and the value itself stays in the note file. A rename receipt uses `address` for the destination and `rename_from` for the source; it has no duplicate `rename_to` field.
|
|
67
67
|
|
|
@@ -8704,6 +8704,10 @@ function createNotesStore(input) {
|
|
|
8704
8704
|
const rows = [];
|
|
8705
8705
|
for await (const note of scan(stableOptions, status)) {
|
|
8706
8706
|
const { address, path, scope, meta, body } = note;
|
|
8707
|
+
if (stableQueries.length === 0) {
|
|
8708
|
+
rows.push({ address, path, scope, meta, matches: [] });
|
|
8709
|
+
continue;
|
|
8710
|
+
}
|
|
8707
8711
|
let baseChars = 0;
|
|
8708
8712
|
const matches = [];
|
|
8709
8713
|
for (const [index, line] of body.split("\n").entries()) {
|
|
@@ -8843,7 +8847,7 @@ var HistoryFoldedRowSchema = typebox_exports.Object({
|
|
|
8843
8847
|
|
|
8844
8848
|
// src/tools/schema.ts
|
|
8845
8849
|
var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
|
|
8846
|
-
var searchQuery = (description) => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String()
|
|
8850
|
+
var searchQuery = (description = "(optional) Literal text, or texts combined with OR. Empty text or list means no search filter.") => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String())], { description });
|
|
8847
8851
|
var InvalidQueryError = class extends Error {
|
|
8848
8852
|
constructor(message) {
|
|
8849
8853
|
super(message);
|
|
@@ -8851,11 +8855,10 @@ var InvalidQueryError = class extends Error {
|
|
|
8851
8855
|
}
|
|
8852
8856
|
};
|
|
8853
8857
|
function searchQueries(query) {
|
|
8854
|
-
const candidates = typeof query === "string" ? [query] : query;
|
|
8855
|
-
if (!Array.isArray(candidates)
|
|
8858
|
+
const candidates = query === void 0 ? [] : typeof query === "string" ? [query] : query;
|
|
8859
|
+
if (!Array.isArray(candidates)) throw new InvalidQueryError("`query` must be a string or a list of strings.");
|
|
8856
8860
|
if (!candidates.every((candidate) => typeof candidate === "string")) throw new InvalidQueryError("Every item in the `query` list must be a string.");
|
|
8857
|
-
|
|
8858
|
-
return candidates;
|
|
8861
|
+
return candidates.filter((candidate) => candidate !== "");
|
|
8859
8862
|
}
|
|
8860
8863
|
|
|
8861
8864
|
// src/tools/notes.ts
|
|
@@ -9136,7 +9139,7 @@ var notesList = {
|
|
|
9136
9139
|
},
|
|
9137
9140
|
render: (result) => renderOutcome(result, renderListData)
|
|
9138
9141
|
};
|
|
9139
|
-
var notesSearchParameters = typebox_exports.Object({ query: searchQuery(), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
9142
|
+
var notesSearchParameters = typebox_exports.Object({ query: typebox_exports.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
9140
9143
|
function renderSearchData(data) {
|
|
9141
9144
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9142
9145
|
for (const file of data.files) {
|
|
@@ -9165,7 +9168,7 @@ function fitSearchFile(file, fits) {
|
|
|
9165
9168
|
var notesSearch = {
|
|
9166
9169
|
name: "notes_search",
|
|
9167
9170
|
label: "Notes search",
|
|
9168
|
-
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}`,
|
|
9171
|
+
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}`,
|
|
9169
9172
|
parameters: notesSearchParameters,
|
|
9170
9173
|
outputSchema: resultSchema(NotesSearchDataSchema),
|
|
9171
9174
|
async execute(params, identity2) {
|
package/package.json
CHANGED
package/src/history/query.ts
CHANGED
|
@@ -155,23 +155,14 @@ function pageData(projection: HistoryProjection, params: HistorySelection, vis:
|
|
|
155
155
|
return { items: rows, ...cursors };
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
/** Filter, then keep only literal matches when a query is present.
|
|
159
|
-
function selectionCandidates(projection: HistoryProjection, params: HistorySelection):
|
|
160
|
-
|
|
161
|
-
if (params.query
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} catch (error) {
|
|
165
|
-
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const events = filteredItems(projection, params, queries === undefined);
|
|
170
|
-
if (queries === undefined) return success(events.map((event) => ({ event })));
|
|
171
|
-
const needles = queries;
|
|
172
|
-
return success(events
|
|
158
|
+
/** Filter, then keep only literal matches when a normalized query is present. */
|
|
159
|
+
function selectionCandidates(projection: HistoryProjection, params: HistorySelection): Candidate[] {
|
|
160
|
+
const events = filteredItems(projection, params, params.query === undefined);
|
|
161
|
+
if (params.query === undefined) return events.map((event) => ({ event }));
|
|
162
|
+
const needles = params.query as string[];
|
|
163
|
+
return events
|
|
173
164
|
.map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), needles) }))
|
|
174
|
-
.filter((candidate) => candidate.matchOffset >= 0)
|
|
165
|
+
.filter((candidate) => candidate.matchOffset >= 0);
|
|
175
166
|
}
|
|
176
167
|
|
|
177
168
|
/**
|
|
@@ -181,10 +172,15 @@ function selectionCandidates(projection: HistoryProjection, params: HistorySelec
|
|
|
181
172
|
export function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): Outcome<HistoryPage> {
|
|
182
173
|
const bounds = resolveTimeBounds(params);
|
|
183
174
|
if (!bounds.ok) return bounds;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
let queries: string[];
|
|
176
|
+
try {
|
|
177
|
+
queries = searchQueries(params.query);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
const scoped = { ...params, ...bounds.data, query: queries.length ? queries : undefined };
|
|
183
|
+
const vis = selectionCandidates(projection, scoped);
|
|
188
184
|
// Take the limit from the end `from` names, so a budget for one row keeps the most important one.
|
|
189
185
|
// At least one: `slice(-0)` would otherwise return the whole selection.
|
|
190
186
|
const limit = Math.max(1, scoped.limit ?? 20);
|
package/src/notes/store.ts
CHANGED
|
@@ -475,6 +475,10 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
|
|
|
475
475
|
const rows: NoteSearchRow[] = [];
|
|
476
476
|
for await (const note of scan(stableOptions, status)) {
|
|
477
477
|
const { address, path, scope, meta, body } = note;
|
|
478
|
+
if (stableQueries.length === 0) {
|
|
479
|
+
rows.push({ address, path, scope, meta, matches: [] });
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
478
482
|
// Offsets address the note body alone: no frontmatter length is predicted, so an
|
|
479
483
|
// access-counter rewrite cannot move a match out from under the caller.
|
|
480
484
|
let baseChars = 0;
|
package/src/tools/history.ts
CHANGED
|
@@ -149,7 +149,7 @@ function renderWindows(data: HistoryWindowsData): string {
|
|
|
149
149
|
/* ------------------------------------------------------------------ history_list */
|
|
150
150
|
|
|
151
151
|
export const historyListParameters = Type.Object({
|
|
152
|
-
query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Searches every role, tool arguments and output included; returns only hits.")),
|
|
152
|
+
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.")),
|
|
153
153
|
roles: historyRoles(),
|
|
154
154
|
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
|
|
155
155
|
after_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq above this." })),
|
package/src/tools/notes.ts
CHANGED
|
@@ -328,7 +328,7 @@ export const notesList = {
|
|
|
328
328
|
render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
|
|
329
329
|
} as const;
|
|
330
330
|
|
|
331
|
-
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 });
|
|
331
|
+
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 });
|
|
332
332
|
|
|
333
333
|
function renderSearchData(data: NotesSearchData): string {
|
|
334
334
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
@@ -364,7 +364,7 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
|
|
|
364
364
|
|
|
365
365
|
export const notesSearch = {
|
|
366
366
|
name: "notes_search", label: "Notes search",
|
|
367
|
-
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}`,
|
|
367
|
+
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}`,
|
|
368
368
|
parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
|
|
369
369
|
async execute(params: Static<typeof notesSearchParameters>, identity: NotesIdentity): Promise<Outcome<NotesSearchData>> {
|
|
370
370
|
try {
|
package/src/tools/schema.ts
CHANGED
|
@@ -4,7 +4,7 @@ export const nullableString = (description?: string) => Type.Optional(Type.Union
|
|
|
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
|
|
|
6
6
|
/** Search query parameter: one literal, or several literals combined with OR. */
|
|
7
|
-
export const searchQuery = (description
|
|
7
|
+
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 });
|
|
8
8
|
|
|
9
9
|
/** Expected search-query refusal, distinct from any other Error an operation may raise. */
|
|
10
10
|
export class InvalidQueryError extends Error {
|
|
@@ -14,17 +14,10 @@ export class InvalidQueryError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Normalize a search `query` parameter into the literal needles to match.
|
|
19
|
-
* A bare string is a one-element list, so single-query behavior is unchanged.
|
|
20
|
-
* An empty list, a non-string element, or an empty string is refused rather than silently
|
|
21
|
-
* searching for nothing: those are argument errors, not empty result sets. An empty string
|
|
22
|
-
* matches every line and every item, so it can never be what the caller meant.
|
|
23
|
-
*/
|
|
17
|
+
/** Missing/empty queries disable filtering; empty list entries are ignored, not OR wildcards. */
|
|
24
18
|
export function searchQueries(query: unknown): string[] {
|
|
25
|
-
const candidates = typeof query === "string" ? [query] : query;
|
|
26
|
-
if (!Array.isArray(candidates)
|
|
19
|
+
const candidates = query === undefined ? [] : typeof query === "string" ? [query] : query;
|
|
20
|
+
if (!Array.isArray(candidates)) throw new InvalidQueryError("`query` must be a string or a list of strings.");
|
|
27
21
|
if (!candidates.every((candidate) => typeof candidate === "string")) throw new InvalidQueryError("Every item in the `query` list must be a string.");
|
|
28
|
-
|
|
29
|
-
return candidates as string[];
|
|
22
|
+
return candidates.filter((candidate) => candidate !== "") as string[];
|
|
30
23
|
}
|