notesoup 0.53.2 → 0.54.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/README.md +6 -4
- package/dist/plugins/claude/src/helper.d.ts +2 -1
- package/dist/plugins/claude/src/helper.js +21 -24
- package/dist/plugins/claude/src/history.d.ts +3 -14
- package/dist/plugins/claude/src/history.js +2 -298
- package/dist/plugins/claude/src/text.d.ts +0 -1
- package/dist/plugins/claude/src/text.js +0 -1
- package/dist/plugins/codex/src/history.d.ts +3 -8
- package/dist/plugins/codex/src/history.js +2 -238
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +9 -8
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/codex/src/transcript.d.ts +3 -39
- package/dist/plugins/codex/src/transcript.js +2 -313
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/history.d.ts +3 -0
- package/dist/plugins/dsh/history.js +15 -0
- package/dist/plugins/dsh/tools.js +12 -12
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +9 -5
- package/dist/plugins/pi/history.d.ts +2 -3
- package/dist/plugins/pi/history.js +4 -147
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/runtime.js +2 -2
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +9 -11
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +5 -3
- package/dist/src/boot/text.js +18 -10
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/history/claude.d.ts +16 -0
- package/dist/src/history/claude.js +336 -0
- package/dist/src/history/codex-transcript.d.ts +39 -0
- package/dist/src/history/codex-transcript.js +315 -0
- package/dist/src/history/codex.d.ts +8 -0
- package/dist/src/history/codex.js +238 -0
- package/dist/src/history/corpus.d.ts +35 -0
- package/dist/src/history/corpus.js +54 -0
- package/dist/src/history/history.d.ts +4 -8
- package/dist/src/history/history.js +3 -11
- package/dist/src/history/local.d.ts +17 -0
- package/dist/src/history/local.js +101 -0
- package/dist/src/history/pi.d.ts +36 -0
- package/dist/src/history/pi.js +202 -0
- package/dist/src/history/query.d.ts +15 -5
- package/dist/src/history/query.js +42 -13
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.js +6 -4
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/history.d.ts +7 -19
- package/dist/src/tools/history.js +80 -93
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/boot.integration.test.js +2 -3
- package/dist/test/claude-history.test.js +47 -34
- package/dist/test/claude-mod.test.js +96 -50
- package/dist/test/codex-history.test.js +4 -10
- package/dist/test/codex-plugin.test.js +50 -12
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +73 -6
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +88 -19
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -1
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/helpers/history-corpus.d.ts +7 -0
- package/dist/test/helpers/history-corpus.js +26 -0
- package/dist/test/history-corpus.test.js +307 -0
- package/dist/test/history.integration.test.js +40 -48
- package/dist/test/host-neutral.test.js +20 -33
- package/dist/test/model-facing-text.test.js +14 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +73 -24
- package/dist/test/notes.test.js +51 -21
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/docs/architecture.md +19 -12
- package/docs/claude-code-mod.md +7 -5
- package/docs/codex.md +6 -6
- package/docs/dsh.md +9 -9
- package/docs/history-sessions.md +52 -0
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +14 -8
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +2164 -1341
- package/plugins/claude/hooks/register.ts +19 -11
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +9 -7
- package/plugins/claude/src/helper.ts +22 -25
- package/plugins/claude/src/history.ts +3 -257
- package/plugins/claude/src/text.ts +0 -1
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +1582 -969
- package/plugins/codex/src/history.ts +3 -193
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +9 -8
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/codex/src/transcript.ts +3 -275
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/history.ts +17 -0
- package/plugins/dsh/tools.ts +12 -12
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +159 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/history-tools.ts +11 -5
- package/plugins/pi/history.ts +8 -157
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/runtime.ts +2 -2
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +9 -7
- package/src/boot/render.ts +10 -13
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +18 -10
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/history/claude.ts +286 -0
- package/src/history/codex-transcript.ts +276 -0
- package/src/history/codex.ts +193 -0
- package/src/history/corpus.ts +69 -0
- package/src/history/history.ts +5 -12
- package/src/history/local.ts +93 -0
- package/src/history/pi.ts +199 -0
- package/src/history/query.ts +45 -15
- package/src/index.ts +8 -5
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/history.ts +71 -101
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
package/src/tools/history.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/** Host-neutral history operations: one bounded payload for text and structured results. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
|
-
import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS
|
|
4
|
-
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema, type Operation
|
|
3
|
+
import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS } from "./output.js";
|
|
4
|
+
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema, type Operation } from "./result.js";
|
|
5
5
|
import { historyRoles, searchQuery } from "./schema.js";
|
|
6
|
-
import { HistoryPageSchema, selectPage, type HistoryPage } from "../history/query.js";
|
|
7
|
-
import {
|
|
6
|
+
import { HistoryPageSchema, corpusSelection, selectCorpusPage, selectPage, type HistoryPage } from "../history/query.js";
|
|
7
|
+
import { currentHistory, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity, type HistoryContext } from "../history/corpus.js";
|
|
8
|
+
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, type HistoryFoldedRow, type HistoryPageItem } from "../history/history.js";
|
|
8
9
|
|
|
9
10
|
/** One read: identity, tool summary and a flat document slice. */
|
|
10
11
|
const HistoryReadDataSchema = Type.Object({
|
|
12
|
+
session: Type.Optional(Type.String()),
|
|
13
|
+
notice: Type.Optional(Type.String()),
|
|
11
14
|
seq: Type.Integer({ minimum: 1 }),
|
|
12
|
-
window_id: Type.String(),
|
|
13
15
|
role: HistoryRoleSchema,
|
|
14
16
|
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
15
17
|
...ToolSummarySchema.properties,
|
|
@@ -18,22 +20,10 @@ const HistoryReadDataSchema = Type.Object({
|
|
|
18
20
|
}, { additionalProperties: false });
|
|
19
21
|
type HistoryReadData = Static<typeof HistoryReadDataSchema>;
|
|
20
22
|
|
|
21
|
-
const HistoryWindowsDataSchema = Type.Object({
|
|
22
|
-
session_id: Type.String(),
|
|
23
|
-
windows: Type.Array(Type.Object({
|
|
24
|
-
window_id: Type.String(),
|
|
25
|
-
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
26
|
-
first_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
27
|
-
last_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
28
|
-
}, { additionalProperties: false })),
|
|
29
|
-
more: Type.Integer({ minimum: 0, description: "How many more were left out." }),
|
|
30
|
-
}, { additionalProperties: false });
|
|
31
|
-
type HistoryWindowsData = Static<typeof HistoryWindowsDataSchema>;
|
|
32
|
-
|
|
33
23
|
/* ------------------------------------------------------------------ rendering */
|
|
34
24
|
|
|
35
|
-
function header(item: {
|
|
36
|
-
return `
|
|
25
|
+
function header(item: { session?: string; seq: number; role: string }): string {
|
|
26
|
+
return `${item.session === undefined ? "" : `session ${item.session} | `}seq ${item.seq} | ${item.role}`;
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
function toolHeader(item: { role: string; tool?: string; tool_status?: string; output_truncated?: true; full_output_path?: string; nested_calls?: { call_count: number; complete: boolean } }): string | undefined {
|
|
@@ -56,26 +46,27 @@ function renderPageItem(item: HistoryPageItem): string {
|
|
|
56
46
|
|
|
57
47
|
function renderFoldedRow(row: HistoryFoldedRow): string {
|
|
58
48
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
59
|
-
const
|
|
60
|
-
|
|
49
|
+
const identity = row.session === undefined ? {} : { session: row.session };
|
|
50
|
+
const expand = `\n\t→ expand: ${JSON.stringify({ ...identity, after_seq: row.first_seq - 1, before_seq: row.last_seq + 1, from: "oldest", roles: ["tool", "context"] })}`;
|
|
51
|
+
return `${row.session === undefined ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
61
52
|
}
|
|
62
53
|
|
|
63
54
|
function renderPage(page: HistoryPage): string {
|
|
64
55
|
// An empty selection has no anchors either, so it would otherwise render as nothing at all.
|
|
65
|
-
if (page.items.length === 0) return "No events match these filters
|
|
56
|
+
if (page.items.length === 0) return `${page.notice ?? ""}No events match these filters.`;
|
|
66
57
|
const body = page.items.map((item) => ("folded" in item ? renderFoldedRow(item) : renderPageItem(item))).join("\n\n");
|
|
67
58
|
const cursors = [
|
|
68
59
|
page.page_older === null ? "" : `→ older: ${JSON.stringify(page.page_older)}`,
|
|
69
60
|
page.page_newer === null ? "" : `→ newer: ${JSON.stringify(page.page_newer)}`,
|
|
70
61
|
].filter((line) => line !== "");
|
|
71
|
-
return cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}
|
|
62
|
+
return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`);
|
|
72
63
|
}
|
|
73
64
|
|
|
74
65
|
function renderRead(data: HistoryReadData): string {
|
|
75
66
|
const tool = toolHeader(data);
|
|
76
67
|
const afterSeq = data.seq - 10;
|
|
77
|
-
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
|
|
78
|
-
return [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
68
|
+
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(data.session === undefined ? {} : { session: data.session }), ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
|
|
69
|
+
return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
/* ------------------------------------------------------------------ shared bounding */
|
|
@@ -84,70 +75,12 @@ function renderRead(data: HistoryReadData): string {
|
|
|
84
75
|
export type HistoryTextWrapper = (text: string) => string;
|
|
85
76
|
const plainText: HistoryTextWrapper = (text) => text;
|
|
86
77
|
|
|
87
|
-
// Sample known ids in the refusal message itself, never as a second listing.
|
|
88
|
-
const MAX_REPORTED_WINDOWS = 5;
|
|
89
|
-
|
|
90
|
-
/** At most `MAX_REPORTED_WINDOWS` known ids, appended to an unknown_window_id message. */
|
|
91
|
-
function knownWindowSuffix(known: string[]): string {
|
|
92
|
-
return known.length === 0 ? "" : `; its windows: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const PREVIOUS_WINDOW = "@previous";
|
|
96
|
-
|
|
97
|
-
/** Resolve "@previous" against oldest-first windows; every other value passes through. */
|
|
98
|
-
function resolveWindowId(projection: HistoryProjection, windowId: string | undefined): { ok: true; window_id: string | undefined } | { ok: false; outcome: Outcome<never> } {
|
|
99
|
-
if (windowId !== PREVIOUS_WINDOW) return { ok: true, window_id: windowId };
|
|
100
|
-
const previous = projection.windows.at(-2);
|
|
101
|
-
if (previous !== undefined) return { ok: true, window_id: previous.windowId };
|
|
102
|
-
const known = projection.windows.map((current) => current.windowId);
|
|
103
|
-
return { ok: false, outcome: failure("unknown_window_id", `"${PREVIOUS_WINDOW}" has nothing to point at: this session has no window before the current one${knownWindowSuffix(known)}.`) };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function badWindowId(projection: HistoryProjection, params: HistoryFilter): Outcome<never> | undefined {
|
|
107
|
-
const badWindow = unknownWindowId(projection, params);
|
|
108
|
-
if (!badWindow) return undefined;
|
|
109
|
-
return failure("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}.`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/* ------------------------------------------------------------------ history_windows */
|
|
113
|
-
|
|
114
|
-
export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
|
|
115
|
-
|
|
116
|
-
export const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string, HistoryTextWrapper?]> = {
|
|
117
|
-
name: "history_windows",
|
|
118
|
-
label: "History list windows",
|
|
119
|
-
description: "List this session's context windows, oldest first, with seq ranges.",
|
|
120
|
-
parameters: historyWindowsParameters,
|
|
121
|
-
outputSchema: resultSchema(HistoryWindowsDataSchema),
|
|
122
|
-
async execute(_params, projection, sessionId, wrapText = plainText) {
|
|
123
|
-
const data: HistoryWindowsData = { session_id: sessionId, windows: [], more: projection.windows.length };
|
|
124
|
-
const fits = (candidate: HistoryWindowsData) => fitsResult(success(candidate), (result) => wrapText(renderOutcome(result, renderWindows)));
|
|
125
|
-
for (const window of projection.windows) {
|
|
126
|
-
let first: number | null = null;
|
|
127
|
-
let last: number | null = null;
|
|
128
|
-
for (const event of window.items) {
|
|
129
|
-
first = first === null ? event.seq : Math.min(first, event.seq);
|
|
130
|
-
last = last === null ? event.seq : Math.max(last, event.seq);
|
|
131
|
-
}
|
|
132
|
-
const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last };
|
|
133
|
-
if (!fits({ ...data, windows: [...data.windows, row], more: data.more - 1 })) break;
|
|
134
|
-
data.windows.push(row);
|
|
135
|
-
data.more--;
|
|
136
|
-
}
|
|
137
|
-
return fits(data) ? success(data) : failure("output_too_large", `The session id alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry.`);
|
|
138
|
-
},
|
|
139
|
-
render: (result) => renderOutcome(result, renderWindows),
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
function renderWindows(data: HistoryWindowsData): string {
|
|
143
|
-
const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}`)];
|
|
144
|
-
if (data.more > 0) lines.push(`${data.more} more windows not shown; every \`history_list\` event also names its window.`);
|
|
145
|
-
return lines.join("\n");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
78
|
/* ------------------------------------------------------------------ history_list */
|
|
149
79
|
|
|
80
|
+
const sessionParameter = Type.Optional(Type.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions (query required); history_read needs one session." }));
|
|
81
|
+
|
|
150
82
|
export const historyListParameters = Type.Object({
|
|
83
|
+
session: sessionParameter,
|
|
151
84
|
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.")),
|
|
152
85
|
roles: historyRoles(),
|
|
153
86
|
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
|
|
@@ -155,41 +88,77 @@ export const historyListParameters = Type.Object({
|
|
|
155
88
|
since: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events at or after it. UTC if no offset." })),
|
|
156
89
|
until: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events before it. UTC if no offset." })),
|
|
157
90
|
from: Type.Optional(Type.Union([Type.Literal("newest"), Type.Literal("oldest")], { description: "(optional, default newest) Which end `limit` counts from: newest or oldest. Results stay oldest first." })),
|
|
158
|
-
window_id: Type.Optional(Type.String({ minLength: 1, description: `(optional) Only this context window. From \`history_windows\` or any event; \`${PREVIOUS_WINDOW}\` is the one before this.` })),
|
|
159
91
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "(optional, default 20) Max events per page; folded rows don't count." })),
|
|
160
92
|
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` })),
|
|
161
93
|
}, { additionalProperties: false });
|
|
162
94
|
|
|
163
|
-
export const historyList: Operation<typeof historyListParameters, HistoryPage, [
|
|
95
|
+
export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryContext, HistoryTextWrapper?]> = {
|
|
164
96
|
name: "history_list",
|
|
165
97
|
label: "History list items",
|
|
166
|
-
description: "Browse or search
|
|
98
|
+
description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * with query to search across local harnesses. Read one in full with `history_read`.",
|
|
167
99
|
parameters: historyListParameters,
|
|
168
100
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
169
|
-
async execute(params,
|
|
170
|
-
|
|
171
|
-
if (!resolved.ok) return resolved.outcome;
|
|
172
|
-
const scoped = { ...params, window_id: resolved.window_id };
|
|
173
|
-
const badWindow = badWindowId(projection, scoped);
|
|
174
|
-
if (badWindow) return badWindow;
|
|
175
|
-
// Charge wrapped rendering and cursors, not only event previews.
|
|
101
|
+
async execute(params, context, wrapText = plainText) {
|
|
102
|
+
// Charge wrapped rendering, identities, notices and recipes, not only event previews.
|
|
176
103
|
const fits = (page: HistoryPage) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
|
|
177
|
-
|
|
104
|
+
const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
|
|
105
|
+
if (params.session === undefined) return selectPage(await currentHistory(context), params, fits, maxChars);
|
|
106
|
+
const selector = parseSessionSelector(params.session);
|
|
107
|
+
if (!selector.ok) return selector;
|
|
108
|
+
const corpus = "corpus" in context ? context.corpus : undefined;
|
|
109
|
+
if (selector.data.wildcard) {
|
|
110
|
+
const scoped = corpusSelection(params);
|
|
111
|
+
if (!scoped.ok) return scoped;
|
|
112
|
+
if (corpus === undefined) return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
113
|
+
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
114
|
+
const loaded = [];
|
|
115
|
+
const notices: string[] = [];
|
|
116
|
+
for (const session of sessions) {
|
|
117
|
+
const result = await loadHistorySession(session);
|
|
118
|
+
if (!result.ok) return result;
|
|
119
|
+
loaded.push({ session: sessionIdentity(session), projection: result.data.projection });
|
|
120
|
+
if (result.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
|
|
121
|
+
}
|
|
122
|
+
const notice = notices.length ? { notice: notices.join("") } : {};
|
|
123
|
+
const result = selectCorpusPage(loaded, scoped.data, (page) => fits({ ...page, ...notice }), maxChars);
|
|
124
|
+
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
125
|
+
}
|
|
126
|
+
const target = await resolveSession(corpus, selector.data);
|
|
127
|
+
if (!target.ok) return target;
|
|
128
|
+
const loaded = await loadHistorySession(target.data);
|
|
129
|
+
if (!loaded.ok) return loaded;
|
|
130
|
+
const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
|
|
131
|
+
const result = selectPage(loaded.data.projection, { ...params, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars);
|
|
132
|
+
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
178
133
|
},
|
|
179
134
|
render: (result) => renderOutcome(result, renderPage),
|
|
180
135
|
};
|
|
181
136
|
|
|
182
137
|
/* ------------------------------------------------------------------ history_read */
|
|
183
138
|
|
|
184
|
-
export const historyReadParameters = Type.Object({ seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
139
|
+
export const historyReadParameters = Type.Object({ session: sessionParameter, seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`. Pass its session too when present." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
185
140
|
|
|
186
|
-
export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [
|
|
141
|
+
export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryContext, HistoryTextWrapper?]> = {
|
|
187
142
|
name: "history_read",
|
|
188
143
|
label: "History read item",
|
|
189
144
|
description: "Read one event in full: tool arguments, output, and nested calls.",
|
|
190
145
|
parameters: historyReadParameters,
|
|
191
146
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
192
|
-
async execute(params,
|
|
147
|
+
async execute(params, context, wrapText = plainText) {
|
|
148
|
+
let projection;
|
|
149
|
+
let identity: { session?: string; notice?: string } = {};
|
|
150
|
+
if (params.session === undefined) projection = await currentHistory(context);
|
|
151
|
+
else {
|
|
152
|
+
const selector = parseSessionSelector(params.session);
|
|
153
|
+
if (!selector.ok) return selector;
|
|
154
|
+
if (selector.data.wildcard) return failure("invalid_session", "`history_read` reads one session; pass a specific `session` ID, not a wildcard.");
|
|
155
|
+
const target = await resolveSession("corpus" in context ? context.corpus : undefined, selector.data);
|
|
156
|
+
if (!target.ok) return target;
|
|
157
|
+
const loaded = await loadHistorySession(target.data);
|
|
158
|
+
if (!loaded.ok) return loaded;
|
|
159
|
+
projection = loaded.data.projection;
|
|
160
|
+
identity = { session: sessionIdentity(target.data), ...(loaded.data.notice === undefined ? {} : { notice: loaded.data.notice }) };
|
|
161
|
+
}
|
|
193
162
|
const item = allItems(projection).find((event) => event.seq === params.seq);
|
|
194
163
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
195
164
|
// consumed by a pairing. Only the last two can mention what is at the address.
|
|
@@ -197,6 +166,7 @@ export const historyRead: Operation<typeof historyReadParameters, HistoryReadDat
|
|
|
197
166
|
return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
198
167
|
}
|
|
199
168
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
169
|
+
if (identity.notice) return failure("unconfirmed_seq", `Seq ${params.seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`);
|
|
200
170
|
return failure("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
|
|
201
171
|
}
|
|
202
172
|
if (item === undefined) {
|
|
@@ -216,8 +186,8 @@ export const historyRead: Operation<typeof historyReadParameters, HistoryReadDat
|
|
|
216
186
|
params.offset_chars,
|
|
217
187
|
params.max_chars,
|
|
218
188
|
(window) => ({
|
|
189
|
+
...identity,
|
|
219
190
|
seq: item.seq,
|
|
220
|
-
window_id: item.windowId,
|
|
221
191
|
role: item.role,
|
|
222
192
|
created_at: item.createdAt ?? null,
|
|
223
193
|
...toolSummary(item),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { NoteError } from "../notes/errors.js";
|
|
4
|
+
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../notes/index.js";
|
|
5
|
+
|
|
6
|
+
/** Host-supplied facts for one notes tool registration; overrides never mutate this context. */
|
|
7
|
+
export type NotesToolContext = Readonly<{
|
|
8
|
+
identity: NotesIdentity;
|
|
9
|
+
cwd: string;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
/** Capture the host's base cwd alongside its default identity. */
|
|
13
|
+
export function notesToolContext(identity: NotesIdentity, cwd: string): NotesToolContext {
|
|
14
|
+
if (typeof cwd !== "string" || cwd.length === 0) throw new TypeError("notes tool cwd must be a non-empty string");
|
|
15
|
+
return Object.freeze({ identity: snapshotNotesIdentity(identity), cwd: resolve(cwd) });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Resolve the current-project override once, before any address, receipt, or ownership decision. */
|
|
19
|
+
export function notesIdentityForCall(context: NotesToolContext, cwd?: string): NotesIdentity {
|
|
20
|
+
if (cwd === undefined) return context.identity;
|
|
21
|
+
const resolved = resolve(context.cwd, cwd);
|
|
22
|
+
let directory = false;
|
|
23
|
+
try { directory = statSync(resolved).isDirectory(); } catch { /* Report one typed refusal below. */ }
|
|
24
|
+
if (!directory) throw new NoteError("invalid_cwd", `cwd is not an existing directory: ${JSON.stringify(cwd)} (resolved to ${resolved}).`);
|
|
25
|
+
return snapshotNotesIdentity({
|
|
26
|
+
...context.identity,
|
|
27
|
+
projectKey: projectKey(resolved, context.identity.home),
|
|
28
|
+
});
|
|
29
|
+
}
|
package/src/tools/notes.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { createNotesStore, NoteError, noteIdentity, type NoteChange, type NoteMe
|
|
|
6
6
|
import { prefixFit, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
7
7
|
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema, type Outcome } from "./result.js";
|
|
8
8
|
import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
|
|
9
|
+
import { notesIdentityForCall, type NotesToolContext } from "./notes-context.js";
|
|
9
10
|
|
|
10
11
|
const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")] as const;
|
|
11
12
|
const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
@@ -14,9 +15,10 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
|
14
15
|
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
|
|
15
16
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
|
|
16
17
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
|
|
17
|
-
const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current
|
|
18
|
-
const
|
|
19
|
-
const
|
|
18
|
+
const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current notebooks.");
|
|
19
|
+
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "(optional) Select the current project for this call. A relative path resolves against the host session cwd; the path must be an existing directory." }));
|
|
20
|
+
const QUERY_NAMESPACES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions.";
|
|
21
|
+
const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
@@ -103,15 +105,21 @@ function renderIdentity(identity: { address: string; project_key?: string; proje
|
|
|
103
105
|
return text;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
/** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
|
|
109
|
+
export const ProjectReceiptSchema = {
|
|
107
110
|
project_root: Type.Optional(Type.String()),
|
|
108
111
|
project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
|
|
109
112
|
};
|
|
110
113
|
|
|
111
|
-
|
|
114
|
+
/** One note identity, shared by every receipt: read/list/search rows and all mutations alike. */
|
|
115
|
+
export const NoteIdentitySchema = {
|
|
112
116
|
address: Type.String(),
|
|
113
117
|
project_key: Type.Optional(Type.String()),
|
|
114
118
|
...ProjectReceiptSchema,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const ListedFileSchema = Type.Object({
|
|
122
|
+
...NoteIdentitySchema,
|
|
115
123
|
updated_at: Type.String(),
|
|
116
124
|
last_accessed: Type.String(),
|
|
117
125
|
crumpled_at: Type.Optional(Type.String()),
|
|
@@ -130,19 +138,17 @@ const SearchedFileSchema = Type.Object({
|
|
|
130
138
|
|
|
131
139
|
const SnapshotSchema = {
|
|
132
140
|
more: Type.Integer({ description: "How many more were left out." }),
|
|
133
|
-
|
|
141
|
+
namespaces_unavailable: Type.Array(Type.String()),
|
|
134
142
|
};
|
|
135
143
|
|
|
136
144
|
export const NotesWriteDataSchema = Type.Object({
|
|
137
|
-
|
|
138
|
-
project_key: Type.Optional(Type.String()),
|
|
145
|
+
...NoteIdentitySchema,
|
|
139
146
|
outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
|
|
140
147
|
}, { additionalProperties: false });
|
|
141
148
|
export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
|
|
142
149
|
|
|
143
150
|
export const NotesUpdateDataSchema = Type.Object({
|
|
144
|
-
|
|
145
|
-
project_key: Type.Optional(Type.String()),
|
|
151
|
+
...NoteIdentitySchema,
|
|
146
152
|
change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
|
|
147
153
|
diff: Type.String(),
|
|
148
154
|
rename_from: Type.Optional(Type.String()),
|
|
@@ -150,9 +156,7 @@ export const NotesUpdateDataSchema = Type.Object({
|
|
|
150
156
|
export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
|
|
151
157
|
|
|
152
158
|
export const NotesReadDataSchema = Type.Object({
|
|
153
|
-
|
|
154
|
-
project_key: Type.Optional(Type.String()),
|
|
155
|
-
...ProjectReceiptSchema,
|
|
159
|
+
...NoteIdentitySchema,
|
|
156
160
|
metadata: NoteMetadataSchema,
|
|
157
161
|
...TextWindowSchema.properties,
|
|
158
162
|
}, { additionalProperties: false });
|
|
@@ -181,7 +185,7 @@ export function snapshot<T extends { address: string }>(
|
|
|
181
185
|
shrink?: (item: T, fits: (candidate: T) => boolean) => T,
|
|
182
186
|
): Outcome<Snapshot<T>> {
|
|
183
187
|
const files: T[] = [];
|
|
184
|
-
const data = (selected: T[]): Snapshot<T> => ({ files: selected, more: rows.length - selected.length,
|
|
188
|
+
const data = (selected: T[]): Snapshot<T> => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
|
|
185
189
|
const render = (outcome: Outcome<Snapshot<T>>) => renderOutcome(outcome, renderData);
|
|
186
190
|
const fits = (item: T) => fitsResult(success(data([...files, item])), render);
|
|
187
191
|
for (const item of rows.slice(0, limit)) {
|
|
@@ -197,14 +201,14 @@ export function snapshot<T extends { address: string }>(
|
|
|
197
201
|
break;
|
|
198
202
|
}
|
|
199
203
|
const outcome = success(data(files));
|
|
200
|
-
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable
|
|
204
|
+
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.`);
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
export function listedFile(row: Pick<NoteRow, "address" | "meta">, identity: NotesIdentity): NotesListData["files"][number] {
|
|
204
208
|
return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), last_accessed: localIso(row.meta.lastAccessed), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
205
209
|
}
|
|
206
210
|
|
|
207
|
-
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
211
|
+
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
208
212
|
|
|
209
213
|
function renderWriteData(data: NotesWriteData): string {
|
|
210
214
|
return `${data.outcome} ${renderIdentity(data)}`;
|
|
@@ -214,8 +218,9 @@ export const notesWrite = {
|
|
|
214
218
|
name: "notes_write", label: "Notes write",
|
|
215
219
|
description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
|
|
216
220
|
parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
|
|
217
|
-
async execute(params: Static<typeof notesWriteParameters>,
|
|
221
|
+
async execute(params: Static<typeof notesWriteParameters>, context: NotesToolContext): Promise<Outcome<NotesWriteData>> {
|
|
218
222
|
try {
|
|
223
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
219
224
|
const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin });
|
|
220
225
|
return success({ ...noteIdentity(identity, params.address), outcome });
|
|
221
226
|
} catch (error) { return failureOf(error); }
|
|
@@ -230,6 +235,7 @@ export const notesUpdateParameters = Type.Object({
|
|
|
230
235
|
crumpled: CRUMPLED_PARAMETER,
|
|
231
236
|
replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
|
|
232
237
|
rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, optionally with edits or metadata changes. Won't overwrite a live note; references aren't updated." })),
|
|
238
|
+
cwd: CWD_PARAMETER,
|
|
233
239
|
}, { additionalProperties: false });
|
|
234
240
|
|
|
235
241
|
function renderUpdateData(data: NotesUpdateData): string {
|
|
@@ -261,10 +267,11 @@ function boundedUpdate(data: NotesUpdateData): Outcome<NotesUpdateData> {
|
|
|
261
267
|
|
|
262
268
|
export const notesUpdate = {
|
|
263
269
|
name: "notes_update", label: "Notes update",
|
|
264
|
-
description: `Change part of a note's body, its origin or crumpled state, or its address. When
|
|
270
|
+
description: `Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
|
|
265
271
|
parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
|
|
266
|
-
async execute(params: Static<typeof notesUpdateParameters>,
|
|
272
|
+
async execute(params: Static<typeof notesUpdateParameters>, context: NotesToolContext, renderDiff: (change: NoteChange) => string = (change) => change.kind === "none" ? "" : `note ${change.kind}`): Promise<Outcome<NotesUpdateData>> {
|
|
267
273
|
try {
|
|
274
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
268
275
|
const store = createNotesStore(identity);
|
|
269
276
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
270
277
|
const renameTo = params.rename_to === "" ? undefined : params.rename_to;
|
|
@@ -278,7 +285,7 @@ export const notesUpdate = {
|
|
|
278
285
|
render: renderUpdate,
|
|
279
286
|
} as const;
|
|
280
287
|
|
|
281
|
-
export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
288
|
+
export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
282
289
|
|
|
283
290
|
function renderReadData(data: NotesReadData): string {
|
|
284
291
|
return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
|
|
@@ -288,8 +295,9 @@ export const notesRead = {
|
|
|
288
295
|
name: "notes_read", label: "Notes read",
|
|
289
296
|
description: `Read a note. ${ADDRESS_DESCRIPTION}`,
|
|
290
297
|
parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
|
|
291
|
-
async execute(params: Static<typeof notesReadParameters>,
|
|
298
|
+
async execute(params: Static<typeof notesReadParameters>, context: NotesToolContext): Promise<Outcome<NotesReadData>> {
|
|
292
299
|
try {
|
|
300
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
293
301
|
const note = await createNotesStore(identity).read(params.address);
|
|
294
302
|
const resolved = noteIdentity(identity, params.address);
|
|
295
303
|
if (!note) return failure("not_found", `No note at ${resolved.address}.`);
|
|
@@ -303,7 +311,7 @@ export const notesRead = {
|
|
|
303
311
|
render: (result: Outcome<NotesReadData>): string => renderOutcome(result, renderReadData),
|
|
304
312
|
} as const;
|
|
305
313
|
|
|
306
|
-
export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
314
|
+
export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
307
315
|
|
|
308
316
|
export function renderListData(data: NotesListData): string {
|
|
309
317
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
@@ -311,16 +319,17 @@ export function renderListData(data: NotesListData): string {
|
|
|
311
319
|
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | accessed ${file.last_accessed}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
|
|
312
320
|
}
|
|
313
321
|
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
314
|
-
for (const
|
|
322
|
+
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
315
323
|
return lines.join("\n");
|
|
316
324
|
}
|
|
317
325
|
|
|
318
326
|
export const notesList = {
|
|
319
327
|
name: "notes_list", label: "Notes list",
|
|
320
|
-
description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${
|
|
328
|
+
description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
|
|
321
329
|
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
322
|
-
async execute(params: Static<typeof notesListParameters>,
|
|
330
|
+
async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
|
|
323
331
|
try {
|
|
332
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
324
333
|
const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
325
334
|
return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
|
|
326
335
|
} catch (error) { return failureOf(error); }
|
|
@@ -328,7 +337,7 @@ export const notesList = {
|
|
|
328
337
|
render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
|
|
329
338
|
} as const;
|
|
330
339
|
|
|
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 });
|
|
340
|
+
export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
332
341
|
|
|
333
342
|
function renderSearchData(data: NotesSearchData): string {
|
|
334
343
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
@@ -337,7 +346,7 @@ function renderSearchData(data: NotesSearchData): string {
|
|
|
337
346
|
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
338
347
|
}
|
|
339
348
|
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
340
|
-
for (const
|
|
349
|
+
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
341
350
|
return lines.join("\n");
|
|
342
351
|
}
|
|
343
352
|
|
|
@@ -364,10 +373,11 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
|
|
|
364
373
|
|
|
365
374
|
export const notesSearch = {
|
|
366
375
|
name: "notes_search", label: "Notes search",
|
|
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. ${
|
|
376
|
+
description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
|
|
368
377
|
parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
|
|
369
|
-
async execute(params: Static<typeof notesSearchParameters>,
|
|
378
|
+
async execute(params: Static<typeof notesSearchParameters>, context: NotesToolContext): Promise<Outcome<NotesSearchData>> {
|
|
370
379
|
try {
|
|
380
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
371
381
|
const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
372
382
|
const files: NotesSearchData["files"] = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => ({
|
|
373
383
|
...listedFile(row, identity),
|