notesoup 0.59.1 → 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 +3 -4
- 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/claude.d.ts +3 -1
- package/dist/src/history/claude.js +40 -4
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- package/dist/src/history/prefilter.d.ts +1 -1
- package/dist/src/history/prefilter.js +14 -9
- 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 +27 -6
- package/dist/test/claude-mod.test.js +19 -8
- 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-prefilter.test.js +5 -0
- 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 +5 -3
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +9 -10
- 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 +214 -173
- package/plugins/claude/hooks/register.ts +8 -6
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +3 -4
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +176 -160
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/paseo/README.md +16 -0
- package/plugins/paseo/client/brain-empty-card.tsx +5 -3
- package/plugins/paseo/client/markdown-core.tsx +189 -0
- package/plugins/paseo/client/markdown.tsx +38 -135
- package/plugins/paseo/client/notes-op-card.tsx +15 -12
- package/plugins/paseo/client/paper-card.tsx +1 -3
- package/plugins/paseo/client/sticky-card.tsx +2 -1
- package/plugins/paseo/client/typography.ts +24 -0
- package/plugins/paseo/test/markdown-core.test.ts +75 -0
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/history/claude.ts +31 -4
- package/src/history/history.ts +11 -16
- package/src/history/prefilter.ts +13 -9
- 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/history.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from
|
|
|
4
4
|
import { failure, success, type Outcome } from "../result.js";
|
|
5
5
|
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema, TextWindowSchema, type Operation } from "./result.js";
|
|
6
6
|
import { historyRoles, searchQuery } from "./schema.js";
|
|
7
|
-
import {
|
|
7
|
+
import { InvalidQueryError, searchQueries } from "../text-match.js";
|
|
8
|
+
import { HistoryPageSchema, CorpusCollector, isMultiPage, markMultiPage, selectPage, type HistoryPage, type HistoryPageResult, type HistorySelection } from "../history/query.js";
|
|
8
9
|
import { currentHistory, loadHistoryRepresentative, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity, type HistoryContext } from "../history/corpus.js";
|
|
9
|
-
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, type HistoryFoldedRow, type HistoryPageItem } from "../history/history.js";
|
|
10
|
+
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, type HistoryBound, type HistoryFoldedRow, type HistoryPageItem } from "../history/history.js";
|
|
10
11
|
|
|
11
12
|
/** One read: identity, tool summary and a flat document slice. */
|
|
12
13
|
const HistoryReadDataSchema = Type.Object({
|
|
@@ -39,7 +40,7 @@ function toolHeader(item: { role: string; tool?: string; tool_status?: string; o
|
|
|
39
40
|
|
|
40
41
|
function renderPageItem(item: HistoryPageItem): string {
|
|
41
42
|
const tool = toolHeader(item);
|
|
42
|
-
const lines =
|
|
43
|
+
const lines = [header(item) + (item.context ? " | search context" : ""), ...(tool ? [tool] : [])];
|
|
43
44
|
if (item.truncated) lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
|
|
44
45
|
lines.push(item.content);
|
|
45
46
|
return lines.join("\n");
|
|
@@ -48,7 +49,7 @@ function renderPageItem(item: HistoryPageItem): string {
|
|
|
48
49
|
function renderFoldedRow(row: HistoryFoldedRow): string {
|
|
49
50
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
50
51
|
const identity = row.session === undefined ? {} : { session: row.session };
|
|
51
|
-
const expand = `\n\t→ expand: ${JSON.stringify({ ...identity,
|
|
52
|
+
const expand = `\n\t→ expand: ${JSON.stringify({ ...identity, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] })}`;
|
|
52
53
|
return `${row.session === undefined ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -58,21 +59,21 @@ function renderPage(page: HistoryPage): string {
|
|
|
58
59
|
const body = [...page.items.flatMap((item) => [...(item.folded_before ? [renderFoldedRow(item.folded_before)] : []), renderPageItem(item)]), ...(page.folded_after ? [renderFoldedRow(page.folded_after)] : [])].join("\n\n");
|
|
59
60
|
if (isMultiPage(page)) {
|
|
60
61
|
const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
|
|
61
|
-
return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with
|
|
62
|
+
return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
|
|
62
63
|
}
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const hits = page.items.filter(item => !item.context);
|
|
65
|
+
const first = hits[0]!;
|
|
66
|
+
const last = hits.at(-1)!;
|
|
66
67
|
const cursors = [
|
|
67
|
-
page.has_older ? `→ older: ${JSON.stringify({
|
|
68
|
-
page.has_newer ? `→ newer: ${JSON.stringify({
|
|
68
|
+
page.has_older ? `→ older: ${JSON.stringify({ session: first.session, before: first.seq })}` : "",
|
|
69
|
+
page.has_newer ? `→ newer: ${JSON.stringify({ session: last.session, after: last.seq })}` : "",
|
|
69
70
|
].filter((line) => line !== "");
|
|
70
71
|
return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
function renderRead(data: HistoryReadData): string {
|
|
74
75
|
const tool = toolHeader(data);
|
|
75
|
-
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }),
|
|
76
|
+
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }), after: Math.max(0, data.seq - 10), before: data.seq + 10 })})`;
|
|
76
77
|
return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -86,25 +87,53 @@ const plainText: HistoryTextWrapper = (text) => text;
|
|
|
86
87
|
function pageOutcome(result: HistoryPageResult): Outcome<HistoryPage> {
|
|
87
88
|
if (!("pageTooLarge" in result)) return result;
|
|
88
89
|
const { count, multi } = result.pageTooLarge;
|
|
89
|
-
const narrow = multi ? "narrow the session pattern, query, roles or `
|
|
90
|
+
const narrow = multi ? "narrow the session pattern, query, roles or time bounds (`after`/`before`), or read one session/seq with `history_read`" : "narrow with `after`/`before`, pass `roles` to skip folding, or `history_read` one seq";
|
|
90
91
|
return failure("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/* ------------------------------------------------------------------ history_list */
|
|
94
95
|
|
|
96
|
+
const boundParameter = (description: string) => Type.Optional(Type.Union([Type.String(), Type.Number()], { description: `${description} Use a seq (number or digits) or ISO 8601 time (UTC without offset); wildcards take only times.` }));
|
|
95
97
|
export const historyListParameters = Type.Object({
|
|
96
98
|
session: Type.Optional(Type.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
|
|
97
|
-
query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
98
99
|
roles: historyRoles(),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
|
|
100
|
+
query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
101
|
+
after: boundParameter("Start strictly after this bound, paging forward; 0 starts at the oldest event."),
|
|
102
|
+
before: boundParameter("Stop strictly before this bound; without `after`, take the newest eligible events."),
|
|
103
|
+
context: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events on each side of a hit in its own session; requires a query." })),
|
|
104
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
|
|
105
105
|
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." })),
|
|
106
106
|
}, { additionalProperties: false });
|
|
107
107
|
|
|
108
|
+
const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
109
|
+
function parseBound(name: "after" | "before", value?: number | string): Outcome<HistoryBound | undefined> {
|
|
110
|
+
if (value === undefined) return success(undefined);
|
|
111
|
+
if (typeof value === "number" || /^\d+$/.test(value)) {
|
|
112
|
+
const seq = Number(value);
|
|
113
|
+
if (Number.isSafeInteger(seq) && seq >= 0) return success({ seq });
|
|
114
|
+
} else if (typeof value === "string") {
|
|
115
|
+
const match = ISO_8601.exec(value);
|
|
116
|
+
const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
|
|
117
|
+
if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10))) return success({ at });
|
|
118
|
+
}
|
|
119
|
+
return failure("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function parseSelection(params: Static<typeof historyListParameters>): Outcome<HistorySelection> {
|
|
123
|
+
const after = parseBound("after", params.after);
|
|
124
|
+
if (!after.ok) return after;
|
|
125
|
+
const before = parseBound("before", params.before);
|
|
126
|
+
if (!before.ok) return before;
|
|
127
|
+
try {
|
|
128
|
+
const query = searchQueries(params.query);
|
|
129
|
+
if (!query.length && params.context !== undefined) return failure("invalid_params", "`context` requires a non-empty `query`.");
|
|
130
|
+
return success({ after: after.data, before: before.data, query: query.length ? query : undefined, roles: params.roles, context: params.context, limit: params.limit });
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
108
137
|
export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryContext, HistoryTextWrapper?]> = {
|
|
109
138
|
name: "history_list",
|
|
110
139
|
label: "History list items",
|
|
@@ -112,33 +141,35 @@ export const historyList: Operation<typeof historyListParameters, HistoryPage, [
|
|
|
112
141
|
parameters: historyListParameters,
|
|
113
142
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
114
143
|
async execute(params, context, wrapText = plainText) {
|
|
144
|
+
const selection = parseSelection(params);
|
|
145
|
+
if (!selection.ok) return selection;
|
|
146
|
+
const scoped = selection.data;
|
|
115
147
|
// Charge wrapped rendering, identities, notices and recipes, not only event previews.
|
|
116
148
|
const fits = (page: HistoryPage) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
|
|
117
149
|
const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
|
|
118
|
-
if (params.session === undefined) return pageOutcome(selectPage(await currentHistory(context),
|
|
150
|
+
if (params.session === undefined) return pageOutcome(selectPage(await currentHistory(context), scoped, fits, maxChars));
|
|
119
151
|
const selector = parseSessionSelector(params.session);
|
|
120
152
|
if (!selector.ok) return selector;
|
|
121
153
|
const corpus = "corpus" in context ? context.corpus : undefined;
|
|
122
154
|
if (selector.data.wildcard) {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
155
|
+
const { after, before, query, roles } = scoped;
|
|
156
|
+
if ((after && "seq" in after) || (before && "seq" in before)) return failure("invalid_bounds", "Wildcard history requires times, not seqs, for `after` and `before`.");
|
|
125
157
|
if (corpus === undefined) return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
126
158
|
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
const collector = new CorpusCollector(scoped.data);
|
|
159
|
+
if (!query) sessions.sort((a, b) => (after ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
160
|
+
const representative = !query && !roles && !after && !before;
|
|
161
|
+
const collector = new CorpusCollector(scoped);
|
|
131
162
|
let qualifying = 0;
|
|
132
163
|
const notices: string[] = [];
|
|
133
164
|
let unvisited = false;
|
|
134
165
|
for (const [index, session] of sessions.entries()) {
|
|
135
|
-
const result = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session,
|
|
166
|
+
const result = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, query);
|
|
136
167
|
if (!result.ok || !result.data) continue;
|
|
137
168
|
const added = "projection" in result.data ? collector.add(sessionIdentity(session), result.data.projection) : collector.addRepresentative(sessionIdentity(session), result.data.event);
|
|
138
169
|
if (!added) continue;
|
|
139
170
|
qualifying++;
|
|
140
171
|
if (result.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
|
|
141
|
-
if (!
|
|
172
|
+
if (!query && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
|
|
142
173
|
unvisited = index + 1 < sessions.length;
|
|
143
174
|
break;
|
|
144
175
|
}
|
|
@@ -152,7 +183,7 @@ export const historyList: Operation<typeof historyListParameters, HistoryPage, [
|
|
|
152
183
|
const loaded = await loadHistorySession(target.data);
|
|
153
184
|
if (!loaded.ok) return loaded;
|
|
154
185
|
const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
|
|
155
|
-
const result = pageOutcome(selectPage(loaded.data.projection, { ...
|
|
186
|
+
const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
|
|
156
187
|
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
157
188
|
},
|
|
158
189
|
render: (result) => renderOutcome(result, renderPage),
|
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. */
|