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/dist/src/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export { renderBootBlock } from "./boot/render.js";
|
|
|
19
19
|
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
20
20
|
// Operations: the schemas and typed outcomes a host registers as its own tools, over a
|
|
21
21
|
// host-supplied notes tool context or decoded history projection/lazy corpus context.
|
|
22
|
-
export { notesList, notesRead,
|
|
22
|
+
export { notesList, notesRead, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
23
23
|
export { notesIdentityForCall, notesToolContext } from "./tools/notes-context.js";
|
|
24
24
|
export { historyList, historyRead } from "./tools/history.js";
|
|
25
25
|
export { projectHistory } from "./history/history.js";
|
|
@@ -44,10 +44,10 @@ export function globToRegExp(pattern) {
|
|
|
44
44
|
}
|
|
45
45
|
/** Glob patterns are not virtual paths (`*` is legal), so they get their own guard. */
|
|
46
46
|
export function assertGlobPattern(value) {
|
|
47
|
-
if (value === undefined
|
|
47
|
+
if (value === undefined)
|
|
48
48
|
return undefined;
|
|
49
|
-
if (typeof value !== "string")
|
|
50
|
-
throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
|
|
49
|
+
if (typeof value !== "string" || !value)
|
|
50
|
+
throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a non-empty string; omit it for the current notebooks.`);
|
|
51
51
|
if (value.includes("\0") || value.includes("\\"))
|
|
52
52
|
throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
|
|
53
53
|
return value;
|
|
@@ -38,11 +38,9 @@ export type EditOptions = NotePolicyFields & {
|
|
|
38
38
|
replaceAll?: boolean;
|
|
39
39
|
renameTo?: string;
|
|
40
40
|
};
|
|
41
|
-
/**
|
|
42
|
-
* A pattern without `@` or `/` matches filenames at any depth; relative paths with `/` match the current session.
|
|
43
|
-
*/
|
|
41
|
+
/** Omit glob for current notebooks. A pattern without `@` or `/` matches filenames at any depth. */
|
|
44
42
|
export type NotesQuery = {
|
|
45
|
-
glob?: string
|
|
43
|
+
glob?: string;
|
|
46
44
|
crumpled?: boolean;
|
|
47
45
|
};
|
|
48
46
|
/** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
|
package/dist/src/notes/store.js
CHANGED
|
@@ -471,8 +471,7 @@ export function createNotesStore(input) {
|
|
|
471
471
|
}));
|
|
472
472
|
}
|
|
473
473
|
async function* scan(options, status) {
|
|
474
|
-
const
|
|
475
|
-
const pattern = glob === "@default" ? undefined : glob;
|
|
474
|
+
const pattern = assertGlobPattern(options.glob);
|
|
476
475
|
const normalized = normalizePattern(pattern, identity);
|
|
477
476
|
const matcher = normalized === undefined ? undefined : globToRegExp(normalized);
|
|
478
477
|
const namespaces = await namespacesForPattern(pattern, identity, status);
|
|
@@ -27,13 +27,11 @@ type HistoryReadData = Static<typeof HistoryReadDataSchema>;
|
|
|
27
27
|
export type HistoryTextWrapper = (text: string) => string;
|
|
28
28
|
export declare const historyListParameters: Type.TObject<{
|
|
29
29
|
session: Type.TOptional<Type.TString>;
|
|
30
|
-
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
31
30
|
roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
from: Type.TOptional<Type.TUnion<[Type.TLiteral<"newest">, Type.TLiteral<"oldest">]>>;
|
|
31
|
+
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
32
|
+
after: Type.TOptional<Type.TUnion<[Type.TString, Type.TNumber]>>;
|
|
33
|
+
before: Type.TOptional<Type.TUnion<[Type.TString, Type.TNumber]>>;
|
|
34
|
+
context: Type.TOptional<Type.TInteger>;
|
|
37
35
|
limit: Type.TOptional<Type.TInteger>;
|
|
38
36
|
max_chars_per_item: Type.TOptional<Type.TInteger>;
|
|
39
37
|
}>;
|
|
@@ -4,7 +4,8 @@ import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from
|
|
|
4
4
|
import { failure, success } from "../result.js";
|
|
5
5
|
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema, TextWindowSchema } 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 } from "../history/query.js";
|
|
8
9
|
import { currentHistory, loadHistoryRepresentative, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity } from "../history/corpus.js";
|
|
9
10
|
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema } from "../history/history.js";
|
|
10
11
|
/** One read: identity, tool summary and a flat document slice. */
|
|
@@ -35,7 +36,7 @@ function toolHeader(item) {
|
|
|
35
36
|
}
|
|
36
37
|
function renderPageItem(item) {
|
|
37
38
|
const tool = toolHeader(item);
|
|
38
|
-
const lines =
|
|
39
|
+
const lines = [header(item) + (item.context ? " | search context" : ""), ...(tool ? [tool] : [])];
|
|
39
40
|
if (item.truncated)
|
|
40
41
|
lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
|
|
41
42
|
lines.push(item.content);
|
|
@@ -44,7 +45,7 @@ function renderPageItem(item) {
|
|
|
44
45
|
function renderFoldedRow(row) {
|
|
45
46
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
46
47
|
const identity = row.session === undefined ? {} : { session: row.session };
|
|
47
|
-
const expand = `\n\t→ expand: ${JSON.stringify({ ...identity,
|
|
48
|
+
const expand = `\n\t→ expand: ${JSON.stringify({ ...identity, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] })}`;
|
|
48
49
|
return `${row.session === undefined ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
49
50
|
}
|
|
50
51
|
function renderPage(page) {
|
|
@@ -54,19 +55,20 @@ function renderPage(page) {
|
|
|
54
55
|
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");
|
|
55
56
|
if (isMultiPage(page)) {
|
|
56
57
|
const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
|
|
57
|
-
return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with
|
|
58
|
+
return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
|
|
58
59
|
}
|
|
59
|
-
const
|
|
60
|
-
const
|
|
60
|
+
const hits = page.items.filter(item => !item.context);
|
|
61
|
+
const first = hits[0];
|
|
62
|
+
const last = hits.at(-1);
|
|
61
63
|
const cursors = [
|
|
62
|
-
page.has_older ? `→ older: ${JSON.stringify({
|
|
63
|
-
page.has_newer ? `→ newer: ${JSON.stringify({
|
|
64
|
+
page.has_older ? `→ older: ${JSON.stringify({ session: first.session, before: first.seq })}` : "",
|
|
65
|
+
page.has_newer ? `→ newer: ${JSON.stringify({ session: last.session, after: last.seq })}` : "",
|
|
64
66
|
].filter((line) => line !== "");
|
|
65
67
|
return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`);
|
|
66
68
|
}
|
|
67
69
|
function renderRead(data) {
|
|
68
70
|
const tool = toolHeader(data);
|
|
69
|
-
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }),
|
|
71
|
+
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }), after: Math.max(0, data.seq - 10), before: data.seq + 10 })})`;
|
|
70
72
|
return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
71
73
|
}
|
|
72
74
|
const plainText = (text) => text;
|
|
@@ -75,22 +77,57 @@ function pageOutcome(result) {
|
|
|
75
77
|
if (!("pageTooLarge" in result))
|
|
76
78
|
return result;
|
|
77
79
|
const { count, multi } = result.pageTooLarge;
|
|
78
|
-
const narrow = multi ? "narrow the session pattern, query, roles or `
|
|
80
|
+
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";
|
|
79
81
|
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}.`);
|
|
80
82
|
}
|
|
81
83
|
/* ------------------------------------------------------------------ history_list */
|
|
84
|
+
const boundParameter = (description) => 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.` }));
|
|
82
85
|
export const historyListParameters = Type.Object({
|
|
83
86
|
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." })),
|
|
84
|
-
query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
85
87
|
roles: historyRoles(),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
|
|
88
|
+
query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
89
|
+
after: boundParameter("Start strictly after this bound, paging forward; 0 starts at the oldest event."),
|
|
90
|
+
before: boundParameter("Stop strictly before this bound; without `after`, take the newest eligible events."),
|
|
91
|
+
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." })),
|
|
92
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
|
|
92
93
|
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." })),
|
|
93
94
|
}, { additionalProperties: false });
|
|
95
|
+
const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
96
|
+
function parseBound(name, value) {
|
|
97
|
+
if (value === undefined)
|
|
98
|
+
return success(undefined);
|
|
99
|
+
if (typeof value === "number" || /^\d+$/.test(value)) {
|
|
100
|
+
const seq = Number(value);
|
|
101
|
+
if (Number.isSafeInteger(seq) && seq >= 0)
|
|
102
|
+
return success({ seq });
|
|
103
|
+
}
|
|
104
|
+
else if (typeof value === "string") {
|
|
105
|
+
const match = ISO_8601.exec(value);
|
|
106
|
+
const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
|
|
107
|
+
if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10)))
|
|
108
|
+
return success({ at });
|
|
109
|
+
}
|
|
110
|
+
return failure("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
|
|
111
|
+
}
|
|
112
|
+
function parseSelection(params) {
|
|
113
|
+
const after = parseBound("after", params.after);
|
|
114
|
+
if (!after.ok)
|
|
115
|
+
return after;
|
|
116
|
+
const before = parseBound("before", params.before);
|
|
117
|
+
if (!before.ok)
|
|
118
|
+
return before;
|
|
119
|
+
try {
|
|
120
|
+
const query = searchQueries(params.query);
|
|
121
|
+
if (!query.length && params.context !== undefined)
|
|
122
|
+
return failure("invalid_params", "`context` requires a non-empty `query`.");
|
|
123
|
+
return success({ after: after.data, before: before.data, query: query.length ? query : undefined, roles: params.roles, context: params.context, limit: params.limit });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error instanceof InvalidQueryError)
|
|
127
|
+
return failure("invalid_query", error.message);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
94
131
|
export const historyList = {
|
|
95
132
|
name: "history_list",
|
|
96
133
|
label: "History list items",
|
|
@@ -98,32 +135,35 @@ export const historyList = {
|
|
|
98
135
|
parameters: historyListParameters,
|
|
99
136
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
100
137
|
async execute(params, context, wrapText = plainText) {
|
|
138
|
+
const selection = parseSelection(params);
|
|
139
|
+
if (!selection.ok)
|
|
140
|
+
return selection;
|
|
141
|
+
const scoped = selection.data;
|
|
101
142
|
// Charge wrapped rendering, identities, notices and recipes, not only event previews.
|
|
102
143
|
const fits = (page) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
|
|
103
144
|
const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
|
|
104
145
|
if (params.session === undefined)
|
|
105
|
-
return pageOutcome(selectPage(await currentHistory(context),
|
|
146
|
+
return pageOutcome(selectPage(await currentHistory(context), scoped, fits, maxChars));
|
|
106
147
|
const selector = parseSessionSelector(params.session);
|
|
107
148
|
if (!selector.ok)
|
|
108
149
|
return selector;
|
|
109
150
|
const corpus = "corpus" in context ? context.corpus : undefined;
|
|
110
151
|
if (selector.data.wildcard) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
return
|
|
152
|
+
const { after, before, query, roles } = scoped;
|
|
153
|
+
if ((after && "seq" in after) || (before && "seq" in before))
|
|
154
|
+
return failure("invalid_bounds", "Wildcard history requires times, not seqs, for `after` and `before`.");
|
|
114
155
|
if (corpus === undefined)
|
|
115
156
|
return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
116
157
|
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const collector = new CorpusCollector(scoped.data);
|
|
158
|
+
if (!query)
|
|
159
|
+
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);
|
|
122
162
|
let qualifying = 0;
|
|
123
163
|
const notices = [];
|
|
124
164
|
let unvisited = false;
|
|
125
165
|
for (const [index, session] of sessions.entries()) {
|
|
126
|
-
const result = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session,
|
|
166
|
+
const result = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, query);
|
|
127
167
|
if (!result.ok || !result.data)
|
|
128
168
|
continue;
|
|
129
169
|
const added = "projection" in result.data ? collector.add(sessionIdentity(session), result.data.projection) : collector.addRepresentative(sessionIdentity(session), result.data.event);
|
|
@@ -132,7 +172,7 @@ export const historyList = {
|
|
|
132
172
|
qualifying++;
|
|
133
173
|
if (result.data.notice)
|
|
134
174
|
notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
|
|
135
|
-
if (!
|
|
175
|
+
if (!query && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
|
|
136
176
|
unvisited = index + 1 < sessions.length;
|
|
137
177
|
break;
|
|
138
178
|
}
|
|
@@ -148,7 +188,7 @@ export const historyList = {
|
|
|
148
188
|
if (!loaded.ok)
|
|
149
189
|
return loaded;
|
|
150
190
|
const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
|
|
151
|
-
const result = pageOutcome(selectPage(loaded.data.projection, { ...
|
|
191
|
+
const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
|
|
152
192
|
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
153
193
|
},
|
|
154
194
|
render: (result) => renderOutcome(result, renderPage),
|
|
@@ -117,31 +117,11 @@ export declare const NotesListDataSchema: Type.TObject<{
|
|
|
117
117
|
more: Type.TInteger;
|
|
118
118
|
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
119
119
|
files: Type.TArray<Type.TObject<{
|
|
120
|
-
|
|
121
|
-
crumpled_at: Type.TOptional<Type.TString>;
|
|
122
|
-
warnings: Type.TArray<Type.TString>;
|
|
123
|
-
pinned: Type.TBoolean;
|
|
124
|
-
budget: Type.TInteger;
|
|
125
|
-
readonly: Type.TBoolean;
|
|
126
|
-
project_root: Type.TOptional<Type.TString>;
|
|
127
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
128
|
-
name: Type.TString;
|
|
129
|
-
path: Type.TString;
|
|
130
|
-
}>>>;
|
|
131
|
-
address: Type.TString;
|
|
132
|
-
project_key: Type.TOptional<Type.TString>;
|
|
133
|
-
}>>;
|
|
134
|
-
}>;
|
|
135
|
-
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
136
|
-
export declare const NotesSearchDataSchema: Type.TObject<{
|
|
137
|
-
more: Type.TInteger;
|
|
138
|
-
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
139
|
-
files: Type.TArray<Type.TObject<{
|
|
140
|
-
matches: Type.TArray<Type.TObject<{
|
|
120
|
+
matches: Type.TOptional<Type.TArray<Type.TObject<{
|
|
141
121
|
line: Type.TInteger;
|
|
142
122
|
text: Type.TString;
|
|
143
123
|
offset_chars: Type.TInteger;
|
|
144
|
-
}
|
|
124
|
+
}>>>;
|
|
145
125
|
more_matches: Type.TOptional<Type.TInteger>;
|
|
146
126
|
updated_at: Type.TString;
|
|
147
127
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
@@ -158,7 +138,8 @@ export declare const NotesSearchDataSchema: Type.TObject<{
|
|
|
158
138
|
project_key: Type.TOptional<Type.TString>;
|
|
159
139
|
}>>;
|
|
160
140
|
}>;
|
|
161
|
-
export type
|
|
141
|
+
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
142
|
+
type ListedFile = Static<typeof ListedFileSchema>;
|
|
162
143
|
type Snapshot<T> = Omit<NotesListData, "files"> & {
|
|
163
144
|
files: T[];
|
|
164
145
|
};
|
|
@@ -169,7 +150,7 @@ export declare function snapshot<T extends {
|
|
|
169
150
|
export declare function listedFile(row: Pick<NoteRow, "address" | "meta"> & {
|
|
170
151
|
body?: string;
|
|
171
152
|
warnings?: string[];
|
|
172
|
-
}, identity: NotesIdentity):
|
|
153
|
+
}, identity: NotesIdentity): ListedFile;
|
|
173
154
|
export declare const notesWriteParameters: Type.TObject<{
|
|
174
155
|
cwd: Type.TOptional<Type.TString>;
|
|
175
156
|
pinned: Type.TOptional<Type.TBoolean>;
|
|
@@ -316,80 +297,39 @@ export declare const notesRead: {
|
|
|
316
297
|
readonly render: (result: Outcome<NotesReadData>) => string;
|
|
317
298
|
};
|
|
318
299
|
export declare const notesListParameters: Type.TObject<{
|
|
319
|
-
glob: Type.TOptional<Type.
|
|
320
|
-
|
|
300
|
+
glob: Type.TOptional<Type.TString>;
|
|
301
|
+
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
302
|
+
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
321
303
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
304
|
+
limit: Type.TOptional<Type.TInteger>;
|
|
322
305
|
cwd: Type.TOptional<Type.TString>;
|
|
323
306
|
}>;
|
|
324
307
|
export declare function renderListData(data: Snapshot<NotesListData["files"][number] & {
|
|
325
308
|
last_accessed?: string;
|
|
326
309
|
}>): string;
|
|
310
|
+
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
311
|
+
export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
327
312
|
export declare const notesList: {
|
|
328
313
|
readonly name: "notes_list";
|
|
329
314
|
readonly label: "Notes list";
|
|
330
|
-
readonly description: "
|
|
331
|
-
readonly parameters: Type.TObject<{
|
|
332
|
-
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
333
|
-
limit: Type.TOptional<Type.TInteger>;
|
|
334
|
-
crumpled: Type.TOptional<Type.TBoolean>;
|
|
335
|
-
cwd: Type.TOptional<Type.TString>;
|
|
336
|
-
}>;
|
|
337
|
-
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
338
|
-
more: Type.TInteger;
|
|
339
|
-
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
340
|
-
files: Type.TArray<Type.TObject<{
|
|
341
|
-
updated_at: Type.TString;
|
|
342
|
-
crumpled_at: Type.TOptional<Type.TString>;
|
|
343
|
-
warnings: Type.TArray<Type.TString>;
|
|
344
|
-
pinned: Type.TBoolean;
|
|
345
|
-
budget: Type.TInteger;
|
|
346
|
-
readonly: Type.TBoolean;
|
|
347
|
-
project_root: Type.TOptional<Type.TString>;
|
|
348
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
349
|
-
name: Type.TString;
|
|
350
|
-
path: Type.TString;
|
|
351
|
-
}>>>;
|
|
352
|
-
address: Type.TString;
|
|
353
|
-
project_key: Type.TOptional<Type.TString>;
|
|
354
|
-
}>>;
|
|
355
|
-
}>, Type.TObject<{
|
|
356
|
-
error: Type.TString;
|
|
357
|
-
code: Type.TString;
|
|
358
|
-
}>]>;
|
|
359
|
-
readonly execute: (params: Static<typeof notesListParameters>, context: NotesToolContext) => Promise<Outcome<NotesListData>>;
|
|
360
|
-
readonly render: (result: Outcome<NotesListData>) => string;
|
|
361
|
-
};
|
|
362
|
-
export declare const notesSearchParameters: Type.TObject<{
|
|
363
|
-
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
364
|
-
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
365
|
-
limit: Type.TOptional<Type.TInteger>;
|
|
366
|
-
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
367
|
-
crumpled: Type.TOptional<Type.TBoolean>;
|
|
368
|
-
cwd: Type.TOptional<Type.TString>;
|
|
369
|
-
}>;
|
|
370
|
-
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
371
|
-
export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
372
|
-
export declare const notesSearch: {
|
|
373
|
-
readonly name: "notes_search";
|
|
374
|
-
readonly label: "Notes search";
|
|
375
|
-
readonly 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`.";
|
|
315
|
+
readonly 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`.";
|
|
376
316
|
readonly parameters: Type.TObject<{
|
|
317
|
+
glob: Type.TOptional<Type.TString>;
|
|
377
318
|
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
378
|
-
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
379
|
-
limit: Type.TOptional<Type.TInteger>;
|
|
380
319
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
381
320
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
321
|
+
limit: Type.TOptional<Type.TInteger>;
|
|
382
322
|
cwd: Type.TOptional<Type.TString>;
|
|
383
323
|
}>;
|
|
384
324
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
385
325
|
more: Type.TInteger;
|
|
386
326
|
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
387
327
|
files: Type.TArray<Type.TObject<{
|
|
388
|
-
matches: Type.TArray<Type.TObject<{
|
|
328
|
+
matches: Type.TOptional<Type.TArray<Type.TObject<{
|
|
389
329
|
line: Type.TInteger;
|
|
390
330
|
text: Type.TString;
|
|
391
331
|
offset_chars: Type.TInteger;
|
|
392
|
-
}
|
|
332
|
+
}>>>;
|
|
393
333
|
more_matches: Type.TOptional<Type.TInteger>;
|
|
394
334
|
updated_at: Type.TString;
|
|
395
335
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
@@ -409,7 +349,7 @@ export declare const notesSearch: {
|
|
|
409
349
|
error: Type.TString;
|
|
410
350
|
code: Type.TString;
|
|
411
351
|
}>]>;
|
|
412
|
-
readonly execute: (params: Static<typeof
|
|
413
|
-
readonly render: (result: Outcome<
|
|
352
|
+
readonly execute: (params: Static<typeof notesListParameters>, context: NotesToolContext) => Promise<Outcome<NotesListData>>;
|
|
353
|
+
readonly render: (result: Outcome<NotesListData>) => string;
|
|
414
354
|
};
|
|
415
355
|
export {};
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -9,7 +9,7 @@ import { TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
|
9
9
|
import { failure, success } from "../result.js";
|
|
10
10
|
import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
|
|
11
11
|
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
12
|
-
import {
|
|
12
|
+
import { searchQuery } from "./schema.js";
|
|
13
13
|
import { notesIdentityForCall } from "./notes-context.js";
|
|
14
14
|
const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
|
|
15
15
|
const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
@@ -36,7 +36,7 @@ function withWarnings(text, data) {
|
|
|
36
36
|
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." }));
|
|
37
37
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
|
|
38
38
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
|
|
39
|
-
const GLOB_PARAMETER =
|
|
39
|
+
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." }));
|
|
40
40
|
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
41
41
|
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." });
|
|
42
42
|
/**
|
|
@@ -148,10 +148,6 @@ const MatchSchema = Type.Object({
|
|
|
148
148
|
text: Type.String(),
|
|
149
149
|
offset_chars: Type.Integer(),
|
|
150
150
|
}, { additionalProperties: false });
|
|
151
|
-
const SearchedFileSchema = Type.Object({
|
|
152
|
-
...ListedFileSchema.properties,
|
|
153
|
-
matches: Type.Array(MatchSchema), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
154
|
-
}, { additionalProperties: false });
|
|
155
151
|
export const SnapshotSchema = {
|
|
156
152
|
more: Type.Integer({ description: "How many more were left out." }),
|
|
157
153
|
namespaces_unavailable: Type.Array(Type.String(), { description: "Unreadable notebooks or notes." }),
|
|
@@ -176,11 +172,10 @@ export const NotesReadDataSchema = Type.Object({
|
|
|
176
172
|
...TextWindowSchema.properties,
|
|
177
173
|
}, { additionalProperties: false });
|
|
178
174
|
export const NotesListDataSchema = Type.Object({
|
|
179
|
-
files: Type.Array(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
files: Type.Array(SearchedFileSchema),
|
|
175
|
+
files: Type.Array(Type.Object({
|
|
176
|
+
...ListedFileSchema.properties,
|
|
177
|
+
matches: Type.Optional(Type.Array(MatchSchema)), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
178
|
+
}, { additionalProperties: false })),
|
|
184
179
|
...SnapshotSchema,
|
|
185
180
|
}, { additionalProperties: false });
|
|
186
181
|
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
@@ -296,42 +291,27 @@ export const notesRead = {
|
|
|
296
291
|
},
|
|
297
292
|
render: (result) => renderOutcome(result, renderReadData),
|
|
298
293
|
};
|
|
299
|
-
export const notesListParameters = Type.Object({
|
|
294
|
+
export const notesListParameters = Type.Object({
|
|
295
|
+
glob: GLOB_PARAMETER,
|
|
296
|
+
query: Type.Optional(searchQuery()),
|
|
297
|
+
max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "How many hit lines per note at most; requires a query." })),
|
|
298
|
+
crumpled: CRUMPLED_LIST_PARAMETER,
|
|
299
|
+
limit: FILE_LIMIT_PARAMETER,
|
|
300
|
+
cwd: CWD_PARAMETER,
|
|
301
|
+
}, { additionalProperties: false });
|
|
300
302
|
export function renderListData(data) {
|
|
301
303
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
302
304
|
for (const file of data.files) {
|
|
303
|
-
|
|
305
|
+
const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
|
|
306
|
+
if (file.last_accessed !== undefined)
|
|
307
|
+
fields.push(`accessed ${file.last_accessed}`);
|
|
308
|
+
if (file.crumpled_at !== undefined)
|
|
309
|
+
fields.push(`crumpled ${file.crumpled_at}`);
|
|
310
|
+
if (file.matches)
|
|
311
|
+
fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
312
|
+
lines.push(fields.join(" | "));
|
|
304
313
|
lines.push(...file.warnings.map(warning => ` ${warning}`));
|
|
305
|
-
|
|
306
|
-
if (data.more > 0)
|
|
307
|
-
lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
308
|
-
for (const namespace of data.namespaces_unavailable)
|
|
309
|
-
lines.push(`${namespace} could not be read`);
|
|
310
|
-
return lines.join("\n");
|
|
311
|
-
}
|
|
312
|
-
export const notesList = {
|
|
313
|
-
name: "notes_list", label: "Notes list",
|
|
314
|
-
description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile — narrow `glob`.",
|
|
315
|
-
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
316
|
-
async execute(params, context) {
|
|
317
|
-
try {
|
|
318
|
-
const identity = notesIdentityForCall(context, params.cwd);
|
|
319
|
-
const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
320
|
-
return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
|
|
321
|
-
}
|
|
322
|
-
catch (error) {
|
|
323
|
-
return failureOf(error);
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
render: (result) => renderOutcome(result, renderListData),
|
|
327
|
-
};
|
|
328
|
-
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 });
|
|
329
|
-
function renderSearchData(data) {
|
|
330
|
-
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
331
|
-
for (const file of data.files) {
|
|
332
|
-
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` : ""}`);
|
|
333
|
-
lines.push(...file.warnings.map(warning => ` ${warning}`));
|
|
334
|
-
for (const match of file.matches)
|
|
314
|
+
for (const match of file.matches ?? [])
|
|
335
315
|
lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
336
316
|
}
|
|
337
317
|
if (data.more > 0)
|
|
@@ -363,23 +343,32 @@ function fitSearchFile(file, fits) {
|
|
|
363
343
|
const withText = (text) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
|
|
364
344
|
return withText(prefixFit(first.text, text => fits(withText(text))));
|
|
365
345
|
}
|
|
366
|
-
export const
|
|
367
|
-
name: "
|
|
368
|
-
description: "
|
|
369
|
-
parameters:
|
|
346
|
+
export const notesList = {
|
|
347
|
+
name: "notes_list", label: "Notes list",
|
|
348
|
+
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`.",
|
|
349
|
+
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
370
350
|
async execute(params, context) {
|
|
371
351
|
try {
|
|
352
|
+
const queries = searchQueries(params.query);
|
|
353
|
+
const { glob, crumpled, limit } = params;
|
|
354
|
+
if (!queries.length && params.max_matches_per_file !== undefined)
|
|
355
|
+
return failure("invalid_params", "`max_matches_per_file` requires a non-empty `query`.");
|
|
372
356
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
373
|
-
const
|
|
357
|
+
const store = createNotesStore(identity);
|
|
358
|
+
if (!queries.length) {
|
|
359
|
+
const { rows, status } = await store.listWithStatus({ glob, crumpled });
|
|
360
|
+
return snapshot(rows.map(row => listedFile(row, identity)), limit, status, renderListData);
|
|
361
|
+
}
|
|
362
|
+
const { rows, status } = await store.searchWithStatus(queries, { glob, crumpled });
|
|
374
363
|
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => keepMatches({
|
|
375
364
|
...listedFile(row, identity),
|
|
376
365
|
matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
|
|
377
366
|
}, params.max_matches_per_file));
|
|
378
|
-
return snapshot(files,
|
|
367
|
+
return snapshot(files, limit, status, renderListData, fitSearchFile);
|
|
379
368
|
}
|
|
380
369
|
catch (error) {
|
|
381
370
|
return failureOf(error);
|
|
382
371
|
}
|
|
383
372
|
},
|
|
384
|
-
render: (result) => renderOutcome(result,
|
|
373
|
+
render: (result) => renderOutcome(result, renderListData),
|
|
385
374
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Type, type TSchema } from "typebox";
|
|
2
|
-
export declare const nullableString: (description?: string) => Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
3
2
|
export declare const historyRoles: () => Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
|
|
4
3
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|
|
5
4
|
export declare function paramProblem(schema: TSchema, params: unknown): string;
|
package/dist/src/tools/schema.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { Errors } from "typebox/value";
|
|
3
3
|
import { HistoryRoleSchema } from "../history/history.js";
|
|
4
|
-
export const nullableString = (description) => 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
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|
|
7
6
|
export function paramProblem(schema, params) {
|