notesoup 0.39.0 → 0.40.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 +5 -2
- package/dist/src/boot/render.js +2 -2
- package/dist/src/boot/text.d.ts +0 -4
- package/dist/src/boot/text.js +9 -13
- package/dist/src/history/history.d.ts +23 -18
- package/dist/src/history/history.js +37 -20
- package/dist/src/history/query.d.ts +37 -49
- package/dist/src/history/query.js +114 -56
- package/dist/src/notes/store.d.ts +3 -4
- package/dist/src/notes/store.js +12 -16
- package/dist/src/pi/history-tools.d.ts +1 -1
- package/dist/src/pi/history-tools.js +2 -3
- package/dist/src/pi/runtime.js +1 -1
- package/dist/src/pi/tool-names.d.ts +0 -4
- package/dist/src/pi/tool-names.js +0 -4
- package/dist/src/tools/history.d.ts +24 -33
- package/dist/src/tools/history.js +57 -98
- package/dist/src/tools/notes.d.ts +26 -58
- package/dist/src/tools/notes.js +85 -103
- package/dist/src/tools/result.d.ts +16 -13
- package/dist/src/tools/result.js +24 -50
- package/dist/src/tools/schema.d.ts +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +1 -1
- package/dist/test/boot.integration.test.js +1 -1
- package/dist/test/claude-mod.test.js +4 -4
- package/dist/test/dependencies.test.js +1 -1
- package/dist/test/helpers/extension.js +2 -3
- package/dist/test/history.integration.test.js +200 -123
- package/dist/test/host-neutral.test.js +32 -58
- package/dist/test/notes-library.test.js +8 -8
- package/dist/test/notes.integration.test.js +75 -57
- package/dist/test/notes.test.js +44 -42
- package/docs/architecture.md +3 -3
- package/docs/notes-library.md +6 -6
- package/docs/tool-results.md +15 -25
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +119 -178
- package/mods/notesoup/hooks/register.ts +1 -2
- package/package.json +1 -1
- package/skills/memory/SKILL.md +6 -6
- package/src/boot/render.ts +2 -2
- package/src/boot/text.ts +9 -17
- package/src/history/history.ts +36 -20
- package/src/history/query.ts +130 -55
- package/src/notes/store.ts +15 -18
- package/src/pi/history-tools.ts +2 -3
- package/src/pi/runtime.ts +1 -1
- package/src/pi/tool-names.ts +0 -4
- package/src/tools/history.ts +61 -100
- package/src/tools/notes.ts +84 -97
- package/src/tools/result.ts +24 -49
- package/src/tools/schema.ts +3 -3
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
/** Host-neutral history operations: one bounded payload for text and structured results. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import {
|
|
4
|
-
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowSchema } from "./result.js";
|
|
5
|
-
import { historyRoles,
|
|
6
|
-
import { HistoryPageSchema,
|
|
7
|
-
import { allItems, eventDocument,
|
|
8
|
-
const HistoryWindowsDataSchema = Type.Object({
|
|
9
|
-
session_id: Type.String(),
|
|
10
|
-
windows: Type.Array(Type.Object({
|
|
11
|
-
window_id: Type.String(),
|
|
12
|
-
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
13
|
-
first_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
14
|
-
last_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
15
|
-
item_count: Type.Integer({ minimum: 0 }),
|
|
16
|
-
}, { additionalProperties: false }), { description: "Oldest first." }),
|
|
17
|
-
more: Type.Integer({ minimum: 0, description: "Omitted windows; history_list also supplies window ids." }),
|
|
18
|
-
}, { additionalProperties: false });
|
|
3
|
+
import { HISTORY_PREVIEW_CHARS } from "./output.js";
|
|
4
|
+
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
5
|
+
import { historyRoles, searchQuery } from "./schema.js";
|
|
6
|
+
import { HistoryPageSchema, selectPage } from "../history/query.js";
|
|
7
|
+
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, unknownWindowId } from "../history/history.js";
|
|
19
8
|
/** One read: identity, tool summary and a flat document slice. */
|
|
20
9
|
const HistoryReadDataSchema = Type.Object({
|
|
21
10
|
seq: Type.Integer({ minimum: 1 }),
|
|
@@ -23,8 +12,19 @@ const HistoryReadDataSchema = Type.Object({
|
|
|
23
12
|
role: HistoryRoleSchema,
|
|
24
13
|
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
25
14
|
...ToolSummarySchema.properties,
|
|
15
|
+
nested_calls: Type.Optional(NestedCallSummarySchema),
|
|
26
16
|
...TextWindowSchema.properties,
|
|
27
17
|
}, { additionalProperties: false });
|
|
18
|
+
const HistoryWindowsDataSchema = Type.Object({
|
|
19
|
+
session_id: Type.String(),
|
|
20
|
+
windows: Type.Array(Type.Object({
|
|
21
|
+
window_id: Type.String(),
|
|
22
|
+
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
23
|
+
first_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
24
|
+
last_seq: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()]),
|
|
25
|
+
}, { additionalProperties: false })),
|
|
26
|
+
more: Type.Integer({ minimum: 0, description: "How many more were left out." }),
|
|
27
|
+
}, { additionalProperties: false });
|
|
28
28
|
/* ------------------------------------------------------------------ rendering */
|
|
29
29
|
function header(item) {
|
|
30
30
|
return `seq ${item.seq} | window ${item.window_id} | ${item.role}`;
|
|
@@ -32,7 +32,7 @@ function header(item) {
|
|
|
32
32
|
function toolHeader(item) {
|
|
33
33
|
if (item.role !== "tool")
|
|
34
34
|
return undefined;
|
|
35
|
-
const parts = [
|
|
35
|
+
const parts = [`tool ${item.tool}`, `status ${item.tool_status}`];
|
|
36
36
|
if (item.output_truncated)
|
|
37
37
|
parts.push(`output truncated${item.full_output_path ? `, full text at ${item.full_output_path}` : ""}`);
|
|
38
38
|
if (item.nested_calls) {
|
|
@@ -44,7 +44,7 @@ function renderPageItem(item) {
|
|
|
44
44
|
const tool = toolHeader(item);
|
|
45
45
|
const lines = tool === undefined ? [header(item)] : [header(item), tool];
|
|
46
46
|
if (item.truncated)
|
|
47
|
-
lines.push(`[
|
|
47
|
+
lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
|
|
48
48
|
lines.push(item.content);
|
|
49
49
|
return lines.join("\n");
|
|
50
50
|
}
|
|
@@ -53,9 +53,8 @@ function isFoldedRow(item) {
|
|
|
53
53
|
}
|
|
54
54
|
function renderFoldedRow(row) {
|
|
55
55
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${omitted}${expand}`;
|
|
56
|
+
const expand = `\n\t→ expand: {"after_seq":${row.first_seq - 1},"before_seq":${row.last_seq + 1},"from":"oldest","roles":["tool","context"]}`;
|
|
57
|
+
return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
59
58
|
}
|
|
60
59
|
function renderPage(page) {
|
|
61
60
|
// An empty selection has no anchors either, so it would otherwise render as nothing at all.
|
|
@@ -63,14 +62,15 @@ function renderPage(page) {
|
|
|
63
62
|
return "no events match this selection";
|
|
64
63
|
const body = page.items.map((item) => (isFoldedRow(item) ? renderFoldedRow(item) : renderPageItem(item))).join("\n\n");
|
|
65
64
|
const cursors = [
|
|
66
|
-
page.
|
|
67
|
-
page.
|
|
65
|
+
page.page_older === null ? "" : `→ older: ${JSON.stringify(page.page_older)}`,
|
|
66
|
+
page.page_newer === null ? "" : `→ newer: ${JSON.stringify(page.page_newer)}`,
|
|
68
67
|
].filter((line) => line !== "");
|
|
69
68
|
return cursors.length === 0 ? body : `${body}\n\n${cursors.join(" | ")}`;
|
|
70
69
|
}
|
|
71
70
|
function renderRead(data) {
|
|
72
71
|
const tool = toolHeader(data);
|
|
73
|
-
const
|
|
72
|
+
const afterSeq = data.seq - 10;
|
|
73
|
+
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
|
|
74
74
|
return [header(data), ...(tool ? [tool] : []), neighborhood, "", renderTextWindow(data)].join("\n");
|
|
75
75
|
}
|
|
76
76
|
/* ------------------------------------------------------------------ shared bounding */
|
|
@@ -78,8 +78,12 @@ function renderRead(data) {
|
|
|
78
78
|
function pageFits(page) {
|
|
79
79
|
return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
|
|
80
80
|
}
|
|
81
|
-
// Sample known ids
|
|
82
|
-
const MAX_REPORTED_WINDOWS =
|
|
81
|
+
// Sample known ids in the refusal message itself, never as a second listing.
|
|
82
|
+
const MAX_REPORTED_WINDOWS = 5;
|
|
83
|
+
/** At most `MAX_REPORTED_WINDOWS` known ids, appended to an unknown_window_id message. */
|
|
84
|
+
function knownWindowSuffix(known) {
|
|
85
|
+
return known.length === 0 ? "" : `; known: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
|
|
86
|
+
}
|
|
83
87
|
export const PREVIOUS_WINDOW = "@previous";
|
|
84
88
|
/** Resolve "@previous" against oldest-first windows; every other value passes through. */
|
|
85
89
|
function resolveWindowId(projection, windowId) {
|
|
@@ -89,25 +93,20 @@ function resolveWindowId(projection, windowId) {
|
|
|
89
93
|
if (previous !== undefined)
|
|
90
94
|
return { ok: true, window_id: previous.windowId };
|
|
91
95
|
const known = projection.windows.map((current) => current.windowId);
|
|
92
|
-
return { ok: false, outcome: failure("unknown_window_id", `unknown window_id "${PREVIOUS_WINDOW}": this session has no window before the current one
|
|
96
|
+
return { ok: false, outcome: failure("unknown_window_id", `unknown window_id "${PREVIOUS_WINDOW}": this session has no window before the current one${knownWindowSuffix(known)}`) };
|
|
93
97
|
}
|
|
94
98
|
function badWindowId(projection, params) {
|
|
95
99
|
const badWindow = unknownWindowId(projection, params);
|
|
96
100
|
if (!badWindow)
|
|
97
101
|
return undefined;
|
|
98
|
-
|
|
99
|
-
return failure("unknown_window_id", badWindow.message, {
|
|
100
|
-
window_id: params.window_id,
|
|
101
|
-
known_windows: known.slice(0, MAX_REPORTED_WINDOWS),
|
|
102
|
-
...(known.length > MAX_REPORTED_WINDOWS ? { known_windows_omitted: known.length - MAX_REPORTED_WINDOWS } : {}),
|
|
103
|
-
});
|
|
102
|
+
return failure("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}`);
|
|
104
103
|
}
|
|
105
104
|
/* ------------------------------------------------------------------ history_windows */
|
|
106
105
|
export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
|
|
107
106
|
export const historyWindows = {
|
|
108
107
|
name: "history_windows",
|
|
109
108
|
label: "History list windows",
|
|
110
|
-
description: "List session
|
|
109
|
+
description: "List this session's context windows, oldest first, with seq ranges.",
|
|
111
110
|
parameters: historyWindowsParameters,
|
|
112
111
|
outputSchema: resultSchema(HistoryWindowsDataSchema),
|
|
113
112
|
async execute(_params, projection, sessionId) {
|
|
@@ -120,35 +119,39 @@ export const historyWindows = {
|
|
|
120
119
|
first = first === null ? event.seq : Math.min(first, event.seq);
|
|
121
120
|
last = last === null ? event.seq : Math.max(last, event.seq);
|
|
122
121
|
}
|
|
123
|
-
const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last
|
|
122
|
+
const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last };
|
|
124
123
|
if (!fits({ ...data, windows: [...data.windows, row], more: data.more - 1 }))
|
|
125
124
|
break;
|
|
126
125
|
data.windows.push(row);
|
|
127
126
|
data.more--;
|
|
128
127
|
}
|
|
129
|
-
return fits(data) ? success(data) : failure("output_too_large", "The session identity does not fit one history_windows response.");
|
|
128
|
+
return fits(data) ? success(data) : failure("output_too_large", "The session identity does not fit one `history_windows` response.");
|
|
130
129
|
},
|
|
131
130
|
render: (result) => renderOutcome(result, renderWindows),
|
|
132
131
|
};
|
|
133
132
|
function renderWindows(data) {
|
|
134
|
-
const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}
|
|
133
|
+
const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}`)];
|
|
135
134
|
if (data.more > 0)
|
|
136
|
-
lines.push(`${data.more} more windows not shown; history_list also reports window ids on events`);
|
|
135
|
+
lines.push(`${data.more} more windows not shown; \`history_list\` also reports window ids on events`);
|
|
137
136
|
return lines.join("\n");
|
|
138
137
|
}
|
|
139
138
|
/* ------------------------------------------------------------------ history_list */
|
|
140
139
|
export const historyListParameters = Type.Object({
|
|
141
|
-
|
|
140
|
+
query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Searches every role, tool arguments and output included; returns only hits.")),
|
|
142
141
|
roles: historyRoles(),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
|
|
143
|
+
after_seq: Type.Optional(Type.Integer({ minimum: 1, description: "(optional) Only events with seq above this." })),
|
|
144
|
+
since: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events at or after it. UTC if no offset." })),
|
|
145
|
+
until: Type.Optional(Type.String({ minLength: 1, description: "(optional) ISO 8601 time; only events before it. UTC if no offset." })),
|
|
146
|
+
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." })),
|
|
147
|
+
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.` })),
|
|
148
|
+
limit: Type.Optional(Type.Integer({ description: "(optional, default 20) Max events per page; folded rows don't count." })),
|
|
149
|
+
max_chars_per_item: Type.Optional(Type.Integer({ description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` })),
|
|
147
150
|
}, { additionalProperties: false });
|
|
148
151
|
export const historyList = {
|
|
149
152
|
name: "history_list",
|
|
150
153
|
label: "History list items",
|
|
151
|
-
description: "
|
|
154
|
+
description: "Browse or search this session's events, a page at a time. Read one in full with `history_read`.",
|
|
152
155
|
parameters: historyListParameters,
|
|
153
156
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
154
157
|
async execute(params, projection) {
|
|
@@ -159,21 +162,16 @@ export const historyList = {
|
|
|
159
162
|
const badWindow = badWindowId(projection, scoped);
|
|
160
163
|
if (badWindow)
|
|
161
164
|
return badWindow;
|
|
162
|
-
|
|
163
|
-
return selectPage(projection, scoped, items.map((event) => ({ event })), isConversationView(scoped), pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
|
|
165
|
+
return selectPage(projection, scoped, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
|
|
164
166
|
},
|
|
165
167
|
render: (result) => renderOutcome(result, renderPage),
|
|
166
168
|
};
|
|
167
169
|
/* ------------------------------------------------------------------ history_read */
|
|
168
|
-
export const historyReadParameters = Type.Object({
|
|
169
|
-
seq: Type.Integer({ minimum: 1, description: "Event address from history_list/search." }),
|
|
170
|
-
offset_chars: Type.Optional(Type.Integer({ description: "Code-point offset (default 0); negative counts from EOF." })),
|
|
171
|
-
limit_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `Max code points (default ${DEFAULT_READ_WINDOW_CHARS}); also bounded by output bytes.` })),
|
|
172
|
-
}, { additionalProperties: false });
|
|
170
|
+
export const historyReadParameters = Type.Object({ seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
173
171
|
export const historyRead = {
|
|
174
172
|
name: "history_read",
|
|
175
173
|
label: "History read item",
|
|
176
|
-
description: "Read
|
|
174
|
+
description: "Read one event in full: tool arguments, output, and nested calls.",
|
|
177
175
|
parameters: historyReadParameters,
|
|
178
176
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
179
177
|
async execute(params, projection) {
|
|
@@ -181,71 +179,32 @@ export const historyRead = {
|
|
|
181
179
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
182
180
|
// consumed by a pairing. Only the last two can mention what is at the address.
|
|
183
181
|
if (item === undefined && params.seq > projection.highestSeq) {
|
|
184
|
-
return failure("unknown_seq", `unknown seq ${params.seq}: this session's items run 1..${projection.highestSeq}
|
|
182
|
+
return failure("unknown_seq", `unknown seq ${params.seq}: this session's items run 1..${projection.highestSeq}`);
|
|
185
183
|
}
|
|
186
184
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
187
|
-
return failure("not_on_branch", `seq ${params.seq} is on another branch and is not readable here
|
|
185
|
+
return failure("not_on_branch", `seq ${params.seq} is on another branch and is not readable here`);
|
|
188
186
|
}
|
|
189
187
|
if (item === undefined) {
|
|
190
188
|
const callSeq = projection.pairedResults.get(params.seq);
|
|
191
189
|
if (callSeq !== undefined) {
|
|
192
|
-
return failure("not_an_event", `seq ${params.seq} is a tool result already shown inside the call at seq ${callSeq}; read that seq instead
|
|
190
|
+
return failure("not_an_event", `seq ${params.seq} is a tool result already shown inside the call at seq ${callSeq}; read that seq instead`);
|
|
193
191
|
}
|
|
194
|
-
return failure("unknown_seq", `seq ${params.seq} is on this branch but carries no readable event
|
|
192
|
+
return failure("unknown_seq", `seq ${params.seq} is on this branch but carries no readable event`);
|
|
195
193
|
}
|
|
196
194
|
const document = eventDocument(item);
|
|
197
195
|
const totalChars = Array.from(document).length;
|
|
198
196
|
if (typeof params.offset_chars === "number" && params.offset_chars > totalChars) {
|
|
199
|
-
return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end: the item has ${totalChars} chars; the largest legal offset is ${totalChars} (an empty end-read)
|
|
197
|
+
return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end: the item has ${totalChars} chars; the largest legal offset is ${totalChars} (an empty end-read)`);
|
|
200
198
|
}
|
|
201
|
-
return readTextWindow(document, params.offset_chars, params.
|
|
199
|
+
return readTextWindow(document, params.offset_chars, params.max_chars, (window) => ({
|
|
202
200
|
seq: item.seq,
|
|
203
201
|
window_id: item.windowId,
|
|
204
202
|
role: item.role,
|
|
205
203
|
created_at: item.createdAt ?? null,
|
|
206
204
|
...toolSummary(item),
|
|
205
|
+
...nestedCallSummary(item),
|
|
207
206
|
...window,
|
|
208
207
|
}), (result) => renderOutcome(result, renderRead));
|
|
209
208
|
},
|
|
210
209
|
render: (result) => renderOutcome(result, renderRead),
|
|
211
210
|
};
|
|
212
|
-
/* ------------------------------------------------------------------ history_search */
|
|
213
|
-
export const historySearchParameters = Type.Object({
|
|
214
|
-
query: searchQuery(),
|
|
215
|
-
limit: Type.Optional(Type.Integer({ description: "Optional. Maximum matching items returned." })),
|
|
216
|
-
roles: historyRoles(),
|
|
217
|
-
before: Type.Optional(Type.Integer({ description: "Optional. Upper bound: only events with seq strictly below this. Together with after, selects the events strictly between the two." })),
|
|
218
|
-
after: Type.Optional(Type.Integer({ description: "Optional. Lower bound: only events with seq strictly above this. Together with before, selects the events strictly between the two." })),
|
|
219
|
-
window_id: Type.Optional(Type.String({ minLength: 1, description: `Optional. Limit to one context window. Values come from history_windows or any event; "${PREVIOUS_WINDOW}" names the window before the current one.` })),
|
|
220
|
-
max_chars_per_item: Type.Optional(Type.Integer({ description: `Optional. Maximum preview characters per item (default ${HISTORY_PREVIEW_CHARS}); use history_read for full content.` })),
|
|
221
|
-
}, { additionalProperties: false });
|
|
222
|
-
export const historySearch = {
|
|
223
|
-
name: "history_search",
|
|
224
|
-
label: "History search",
|
|
225
|
-
description: "Search session events for case-insensitive literal queries (OR), including tool arguments/output and nested calls. Defaults to all roles; no folded rows. Read a hit with its seq and offset_chars. before/after are strict bounds; the footer prints the exact calls to page older or newer.",
|
|
226
|
-
parameters: historySearchParameters,
|
|
227
|
-
outputSchema: resultSchema(HistorySearchPageSchema),
|
|
228
|
-
async execute(params, projection) {
|
|
229
|
-
const resolved = resolveWindowId(projection, params.window_id);
|
|
230
|
-
if (!resolved.ok)
|
|
231
|
-
return resolved.outcome;
|
|
232
|
-
const scoped = { ...params, window_id: resolved.window_id };
|
|
233
|
-
const badWindow = badWindowId(projection, scoped);
|
|
234
|
-
if (badWindow)
|
|
235
|
-
return badWindow;
|
|
236
|
-
let queries;
|
|
237
|
-
try {
|
|
238
|
-
queries = searchQueries(scoped.query);
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
if (error instanceof InvalidQueryError)
|
|
242
|
-
return failure("invalid_query", error.message);
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
const matches = filteredItems(projection, scoped, "search")
|
|
246
|
-
.map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), queries) }))
|
|
247
|
-
.filter((candidate) => candidate.matchOffset >= 0);
|
|
248
|
-
return selectPage(projection, scoped, matches, false, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
|
|
249
|
-
},
|
|
250
|
-
render: (result) => renderOutcome(result, renderPage),
|
|
251
|
-
};
|
|
@@ -2,8 +2,10 @@ import type { NotesIdentity } from "../notes/identity.js";
|
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
3
|
import { type NoteChange } from "../notes/index.js";
|
|
4
4
|
import { type Outcome } from "./result.js";
|
|
5
|
-
/** One unrecognized entry, and
|
|
5
|
+
/** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
|
|
6
6
|
export declare const MAX_METADATA_ENTRY_BYTES = 1024;
|
|
7
|
+
/** An extra value that cannot be carried is named in place, never silently dropped. */
|
|
8
|
+
export declare const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
|
|
7
9
|
export declare const NoteMetadataSchema: Type.TObject<{
|
|
8
10
|
origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
|
|
9
11
|
created_at: Type.TString;
|
|
@@ -11,11 +13,6 @@ export declare const NoteMetadataSchema: Type.TObject<{
|
|
|
11
13
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
12
14
|
project: Type.TOptional<Type.TString>;
|
|
13
15
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
14
|
-
/** Values left in the file but too large to show, summarized so the summary cannot grow. */
|
|
15
|
-
omitted_extra: Type.TOptional<Type.TObject<{
|
|
16
|
-
keys: Type.TInteger;
|
|
17
|
-
bytes: Type.TInteger;
|
|
18
|
-
}>>;
|
|
19
16
|
}>;
|
|
20
17
|
export type NoteMetadata = Static<typeof NoteMetadataSchema>;
|
|
21
18
|
export declare const NotesWriteDataSchema: Type.TObject<{
|
|
@@ -27,20 +24,15 @@ export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
|
|
|
27
24
|
export declare const NotesUpdateDataSchema: Type.TObject<{
|
|
28
25
|
address: Type.TString;
|
|
29
26
|
project_key: Type.TOptional<Type.TString>;
|
|
30
|
-
|
|
31
|
-
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"file">]>;
|
|
27
|
+
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
32
28
|
diff: Type.TString;
|
|
33
|
-
diff_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
34
29
|
rename_from: Type.TOptional<Type.TString>;
|
|
35
|
-
replaced_crumpled_target: Type.TOptional<Type.TBoolean>;
|
|
36
30
|
}>;
|
|
37
31
|
export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
|
|
38
32
|
export declare const NotesReadDataSchema: Type.TObject<{
|
|
39
33
|
text: Type.TString;
|
|
40
|
-
offset_chars: Type.TInteger;
|
|
41
34
|
total_chars: Type.TInteger;
|
|
42
35
|
next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
43
|
-
limited_by: Type.TUnion<[Type.TLiteral<"limit">, Type.TLiteral<"bytes">, Type.TNull]>;
|
|
44
36
|
address: Type.TString;
|
|
45
37
|
project_key: Type.TOptional<Type.TString>;
|
|
46
38
|
metadata: Type.TObject<{
|
|
@@ -50,17 +42,11 @@ export declare const NotesReadDataSchema: Type.TObject<{
|
|
|
50
42
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
51
43
|
project: Type.TOptional<Type.TString>;
|
|
52
44
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
53
|
-
/** Values left in the file but too large to show, summarized so the summary cannot grow. */
|
|
54
|
-
omitted_extra: Type.TOptional<Type.TObject<{
|
|
55
|
-
keys: Type.TInteger;
|
|
56
|
-
bytes: Type.TInteger;
|
|
57
|
-
}>>;
|
|
58
45
|
}>;
|
|
59
46
|
}>;
|
|
60
47
|
export type NotesReadData = Static<typeof NotesReadDataSchema>;
|
|
61
48
|
export declare const NotesListDataSchema: Type.TObject<{
|
|
62
49
|
more: Type.TInteger;
|
|
63
|
-
crumpled_excluded: Type.TInteger;
|
|
64
50
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
65
51
|
files: Type.TArray<Type.TObject<{
|
|
66
52
|
address: Type.TString;
|
|
@@ -72,14 +58,11 @@ export declare const NotesListDataSchema: Type.TObject<{
|
|
|
72
58
|
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
73
59
|
export declare const NotesSearchDataSchema: Type.TObject<{
|
|
74
60
|
more: Type.TInteger;
|
|
75
|
-
crumpled_excluded: Type.TInteger;
|
|
76
61
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
77
62
|
files: Type.TArray<Type.TObject<{
|
|
78
|
-
matches_total: Type.TInteger;
|
|
79
63
|
matches: Type.TArray<Type.TObject<{
|
|
80
64
|
line: Type.TInteger;
|
|
81
65
|
text: Type.TString;
|
|
82
|
-
truncated: Type.TBoolean;
|
|
83
66
|
offset_chars: Type.TInteger;
|
|
84
67
|
}>>;
|
|
85
68
|
address: Type.TString;
|
|
@@ -97,7 +80,7 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
97
80
|
export declare const notesWrite: {
|
|
98
81
|
readonly name: "notes_write";
|
|
99
82
|
readonly label: "Notes write";
|
|
100
|
-
readonly description: "Create or replace a note body,
|
|
83
|
+
readonly description: "Create or replace a note's body, keeping metadata; uncrumples a crumpled note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
101
84
|
readonly parameters: Type.TObject<{
|
|
102
85
|
address: Type.TString;
|
|
103
86
|
content: Type.TString;
|
|
@@ -110,7 +93,6 @@ export declare const notesWrite: {
|
|
|
110
93
|
}>, Type.TObject<{
|
|
111
94
|
error: Type.TString;
|
|
112
95
|
code: Type.TString;
|
|
113
|
-
details: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
114
96
|
}>]>;
|
|
115
97
|
readonly executionMode: "sequential";
|
|
116
98
|
readonly execute: (params: Static<typeof notesWriteParameters>, identity: NotesIdentity) => Promise<Outcome<NotesWriteData>>;
|
|
@@ -128,10 +110,12 @@ export declare const notesUpdateParameters: Type.TObject<{
|
|
|
128
110
|
rename_to: Type.TOptional<Type.TString>;
|
|
129
111
|
}>;
|
|
130
112
|
declare function renderUpdate(result: Outcome<NotesUpdateData>): string;
|
|
113
|
+
/** A shortened diff still says so in the receipt's own text, on both surfaces. */
|
|
114
|
+
export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
131
115
|
export declare const notesUpdate: {
|
|
132
116
|
readonly name: "notes_update";
|
|
133
117
|
readonly label: "Notes update";
|
|
134
|
-
readonly description: "Edit body
|
|
118
|
+
readonly description: "Edit a note's body, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true; frontmatter can't be edited. Returns a diff. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
135
119
|
readonly parameters: Type.TObject<{
|
|
136
120
|
address: Type.TString;
|
|
137
121
|
edits: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -146,41 +130,35 @@ export declare const notesUpdate: {
|
|
|
146
130
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
147
131
|
address: Type.TString;
|
|
148
132
|
project_key: Type.TOptional<Type.TString>;
|
|
149
|
-
|
|
150
|
-
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"file">]>;
|
|
133
|
+
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
151
134
|
diff: Type.TString;
|
|
152
|
-
diff_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
153
135
|
rename_from: Type.TOptional<Type.TString>;
|
|
154
|
-
replaced_crumpled_target: Type.TOptional<Type.TBoolean>;
|
|
155
136
|
}>, Type.TObject<{
|
|
156
137
|
error: Type.TString;
|
|
157
138
|
code: Type.TString;
|
|
158
|
-
details: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
159
139
|
}>]>;
|
|
160
140
|
readonly executionMode: "sequential";
|
|
161
141
|
readonly execute: (params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string) => Promise<Outcome<NotesUpdateData>>;
|
|
162
142
|
readonly render: typeof renderUpdate;
|
|
163
143
|
};
|
|
164
144
|
export declare const notesReadParameters: Type.TObject<{
|
|
165
|
-
address: Type.TString;
|
|
166
145
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
167
|
-
|
|
146
|
+
max_chars: Type.TOptional<Type.TInteger>;
|
|
147
|
+
address: Type.TString;
|
|
168
148
|
}>;
|
|
169
149
|
export declare const notesRead: {
|
|
170
150
|
readonly name: "notes_read";
|
|
171
151
|
readonly label: "Notes read";
|
|
172
|
-
readonly description: "Read note metadata and
|
|
152
|
+
readonly description: "Read a note's metadata and body, without frontmatter. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
173
153
|
readonly parameters: Type.TObject<{
|
|
174
|
-
address: Type.TString;
|
|
175
154
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
176
|
-
|
|
155
|
+
max_chars: Type.TOptional<Type.TInteger>;
|
|
156
|
+
address: Type.TString;
|
|
177
157
|
}>;
|
|
178
158
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
179
159
|
text: Type.TString;
|
|
180
|
-
offset_chars: Type.TInteger;
|
|
181
160
|
total_chars: Type.TInteger;
|
|
182
161
|
next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
183
|
-
limited_by: Type.TUnion<[Type.TLiteral<"limit">, Type.TLiteral<"bytes">, Type.TNull]>;
|
|
184
162
|
address: Type.TString;
|
|
185
163
|
project_key: Type.TOptional<Type.TString>;
|
|
186
164
|
metadata: Type.TObject<{
|
|
@@ -190,37 +168,30 @@ export declare const notesRead: {
|
|
|
190
168
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
191
169
|
project: Type.TOptional<Type.TString>;
|
|
192
170
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
193
|
-
/** Values left in the file but too large to show, summarized so the summary cannot grow. */
|
|
194
|
-
omitted_extra: Type.TOptional<Type.TObject<{
|
|
195
|
-
keys: Type.TInteger;
|
|
196
|
-
bytes: Type.TInteger;
|
|
197
|
-
}>>;
|
|
198
171
|
}>;
|
|
199
172
|
}>, Type.TObject<{
|
|
200
173
|
error: Type.TString;
|
|
201
174
|
code: Type.TString;
|
|
202
|
-
details: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
203
175
|
}>]>;
|
|
204
176
|
readonly execute: (params: Static<typeof notesReadParameters>, identity: NotesIdentity) => Promise<Outcome<NotesReadData>>;
|
|
205
177
|
readonly render: (result: Outcome<NotesReadData>) => string;
|
|
206
178
|
};
|
|
207
179
|
export declare const notesListParameters: Type.TObject<{
|
|
208
|
-
|
|
180
|
+
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
209
181
|
limit: Type.TOptional<Type.TInteger>;
|
|
210
|
-
|
|
182
|
+
crumpled: Type.TOptional<Type.TBoolean>;
|
|
211
183
|
}>;
|
|
212
184
|
export declare const notesList: {
|
|
213
185
|
readonly name: "notes_list";
|
|
214
186
|
readonly label: "Notes list";
|
|
215
|
-
readonly description: "List notes in
|
|
187
|
+
readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
216
188
|
readonly parameters: Type.TObject<{
|
|
217
|
-
|
|
189
|
+
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
218
190
|
limit: Type.TOptional<Type.TInteger>;
|
|
219
|
-
|
|
191
|
+
crumpled: Type.TOptional<Type.TBoolean>;
|
|
220
192
|
}>;
|
|
221
193
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
222
194
|
more: Type.TInteger;
|
|
223
|
-
crumpled_excluded: Type.TInteger;
|
|
224
195
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
225
196
|
files: Type.TArray<Type.TObject<{
|
|
226
197
|
address: Type.TString;
|
|
@@ -231,39 +202,37 @@ export declare const notesList: {
|
|
|
231
202
|
}>, Type.TObject<{
|
|
232
203
|
error: Type.TString;
|
|
233
204
|
code: Type.TString;
|
|
234
|
-
details: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
235
205
|
}>]>;
|
|
236
206
|
readonly execute: (params: Static<typeof notesListParameters>, identity: NotesIdentity) => Promise<Outcome<NotesListData>>;
|
|
237
207
|
readonly render: (result: Outcome<NotesListData>) => string;
|
|
238
208
|
};
|
|
239
209
|
export declare const notesSearchParameters: Type.TObject<{
|
|
240
210
|
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
241
|
-
|
|
211
|
+
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
242
212
|
limit: Type.TOptional<Type.TInteger>;
|
|
243
213
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
244
|
-
|
|
214
|
+
crumpled: Type.TOptional<Type.TBoolean>;
|
|
245
215
|
}>;
|
|
216
|
+
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
217
|
+
export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
246
218
|
export declare const notesSearch: {
|
|
247
219
|
readonly name: "notes_search";
|
|
248
220
|
readonly label: "Notes search";
|
|
249
|
-
readonly description: "Search note bodies for case-insensitive
|
|
221
|
+
readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
250
222
|
readonly parameters: Type.TObject<{
|
|
251
223
|
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
252
|
-
|
|
224
|
+
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
253
225
|
limit: Type.TOptional<Type.TInteger>;
|
|
254
226
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
255
|
-
|
|
227
|
+
crumpled: Type.TOptional<Type.TBoolean>;
|
|
256
228
|
}>;
|
|
257
229
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
258
230
|
more: Type.TInteger;
|
|
259
|
-
crumpled_excluded: Type.TInteger;
|
|
260
231
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
261
232
|
files: Type.TArray<Type.TObject<{
|
|
262
|
-
matches_total: Type.TInteger;
|
|
263
233
|
matches: Type.TArray<Type.TObject<{
|
|
264
234
|
line: Type.TInteger;
|
|
265
235
|
text: Type.TString;
|
|
266
|
-
truncated: Type.TBoolean;
|
|
267
236
|
offset_chars: Type.TInteger;
|
|
268
237
|
}>>;
|
|
269
238
|
address: Type.TString;
|
|
@@ -274,7 +243,6 @@ export declare const notesSearch: {
|
|
|
274
243
|
}>, Type.TObject<{
|
|
275
244
|
error: Type.TString;
|
|
276
245
|
code: Type.TString;
|
|
277
|
-
details: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
278
246
|
}>]>;
|
|
279
247
|
readonly execute: (params: Static<typeof notesSearchParameters>, identity: NotesIdentity) => Promise<Outcome<NotesSearchData>>;
|
|
280
248
|
readonly render: (result: Outcome<NotesSearchData>) => string;
|