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.
Files changed (53) hide show
  1. package/README.md +5 -2
  2. package/dist/src/boot/render.js +2 -2
  3. package/dist/src/boot/text.d.ts +0 -4
  4. package/dist/src/boot/text.js +9 -13
  5. package/dist/src/history/history.d.ts +23 -18
  6. package/dist/src/history/history.js +37 -20
  7. package/dist/src/history/query.d.ts +37 -49
  8. package/dist/src/history/query.js +114 -56
  9. package/dist/src/notes/store.d.ts +3 -4
  10. package/dist/src/notes/store.js +12 -16
  11. package/dist/src/pi/history-tools.d.ts +1 -1
  12. package/dist/src/pi/history-tools.js +2 -3
  13. package/dist/src/pi/runtime.js +1 -1
  14. package/dist/src/pi/tool-names.d.ts +0 -4
  15. package/dist/src/pi/tool-names.js +0 -4
  16. package/dist/src/tools/history.d.ts +24 -33
  17. package/dist/src/tools/history.js +57 -98
  18. package/dist/src/tools/notes.d.ts +26 -58
  19. package/dist/src/tools/notes.js +85 -103
  20. package/dist/src/tools/result.d.ts +16 -13
  21. package/dist/src/tools/result.js +24 -50
  22. package/dist/src/tools/schema.d.ts +2 -2
  23. package/dist/src/tools/schema.js +3 -3
  24. package/dist/test/agent-loop.test.js +1 -1
  25. package/dist/test/boot.integration.test.js +1 -1
  26. package/dist/test/claude-mod.test.js +4 -4
  27. package/dist/test/dependencies.test.js +1 -1
  28. package/dist/test/helpers/extension.js +2 -3
  29. package/dist/test/history.integration.test.js +200 -123
  30. package/dist/test/host-neutral.test.js +32 -58
  31. package/dist/test/notes-library.test.js +8 -8
  32. package/dist/test/notes.integration.test.js +75 -57
  33. package/dist/test/notes.test.js +44 -42
  34. package/docs/architecture.md +3 -3
  35. package/docs/notes-library.md +6 -6
  36. package/docs/tool-results.md +15 -25
  37. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  38. package/mods/notesoup/dist/claude/helper.js +119 -178
  39. package/mods/notesoup/hooks/register.ts +1 -2
  40. package/package.json +1 -1
  41. package/skills/memory/SKILL.md +6 -6
  42. package/src/boot/render.ts +2 -2
  43. package/src/boot/text.ts +9 -17
  44. package/src/history/history.ts +36 -20
  45. package/src/history/query.ts +130 -55
  46. package/src/notes/store.ts +15 -18
  47. package/src/pi/history-tools.ts +2 -3
  48. package/src/pi/runtime.ts +1 -1
  49. package/src/pi/tool-names.ts +0 -4
  50. package/src/tools/history.ts +61 -100
  51. package/src/tools/notes.ts +84 -97
  52. package/src/tools/result.ts +24 -49
  53. package/src/tools/schema.ts +3 -3
@@ -1,17 +1,52 @@
1
- /** Stable-anchor paging and folding. The operation supplies the full-response budget check. */
1
+ /** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
2
2
  import { Type } from "typebox";
3
3
  import { failure, success } from "../tools/result.js";
4
- import { prefixFit } from "../tools/output.js";
5
- import { allItems, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS } from "./history.js";
4
+ import { earliestMatchOffsetChars, prefixFit } from "../tools/output.js";
5
+ import { InvalidQueryError, searchQueries } from "../tools/schema.js";
6
+ import { allItems, eventDocument, filteredItems, inSelection, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS } from "./history.js";
7
+ /** ISO 8601 date or date-time; the offset is optional (group 1) and a missing one is read as UTC. */
8
+ const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
9
+ /** Epoch ms for one ISO 8601 value, with a missing offset read as UTC. */
10
+ function isoUtcMs(value) {
11
+ const match = ISO_8601.exec(value);
12
+ if (match === null)
13
+ return undefined;
14
+ const at = Date.parse(match[1] === undefined ? `${value}Z` : value);
15
+ return Number.isNaN(at) ? undefined : at;
16
+ }
17
+ /** Epoch ms for one optional time param, or a refusal naming it. */
18
+ function timeBound(name, value) {
19
+ if (value === undefined)
20
+ return success(undefined);
21
+ const at = isoUtcMs(value);
22
+ return at === undefined ? failure("invalid_time", `${name} is not an ISO 8601 timestamp: "${value}"`) : success(at);
23
+ }
24
+ /** Parse `since`/`until`; a malformed or inverted pair refuses here. */
25
+ function resolveTimeBounds(params) {
26
+ const since = timeBound("since", params.since);
27
+ if (!since.ok)
28
+ return since;
29
+ const until = timeBound("until", params.until);
30
+ if (!until.ok)
31
+ return until;
32
+ if (since.data !== undefined && until.data !== undefined && since.data >= until.data) {
33
+ return failure("invalid_time", "since must be earlier than until");
34
+ }
35
+ return success({ ...(since.data === undefined ? {} : { sinceMs: since.data }), ...(until.data === undefined ? {} : { untilMs: until.data }) });
36
+ }
37
+ /** The params to merge into the previous call to continue toward older events. */
38
+ export const HistoryOlderSchema = Type.Object({
39
+ before_seq: Type.Integer({ minimum: 1 }),
40
+ }, { additionalProperties: false });
41
+ /** The params to merge into the previous call to continue toward newer events. */
42
+ export const HistoryNewerSchema = Type.Object({
43
+ after_seq: Type.Integer({ minimum: 1 }),
44
+ from: Type.Literal("oldest"),
45
+ }, { additionalProperties: false });
6
46
  export const HistoryPageSchema = Type.Object({
7
47
  items: Type.Array(Type.Union([HistoryPageItemSchema, HistoryFoldedRowSchema])),
8
- older_before: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()], { description: "Pass as before to page older." }),
9
- newer_after: Type.Union([Type.Integer({ minimum: 1 }), Type.Null()], { description: "Pass as after to page newer." }),
10
- }, { additionalProperties: false });
11
- /** Search never returns conversation folds. */
12
- export const HistorySearchPageSchema = Type.Object({
13
- ...HistoryPageSchema.properties,
14
- items: Type.Array(HistoryPageItemSchema),
48
+ page_older: Type.Union([HistoryOlderSchema, Type.Null()], { description: "Params for the next page; null at the end." }),
49
+ page_newer: Type.Union([HistoryNewerSchema, Type.Null()], { description: "Params for the next page; null at the end." }),
15
50
  }, { additionalProperties: false });
16
51
  /** Shorten preview text first; omit an oversized tool name rather than invent a partial name. */
17
52
  function truncateHistoryItem(item, fits) {
@@ -28,16 +63,14 @@ function truncateHistoryItem(item, fits) {
28
63
  if (item.tool === undefined)
29
64
  return withContent;
30
65
  const { tool: _dropped, ...withoutName } = item;
31
- const named = { ...withoutName, tool_name_omitted: true };
32
- if (fits(named))
33
- return named;
34
- return shrinkContent(named);
66
+ return fits(withoutName) ? withoutName : shrinkContent(withoutName);
35
67
  }
36
68
  function isFoldableEvent(event) {
37
69
  return event.role === "tool" || event.role === "context";
38
70
  }
39
- export function isConversationView(params) {
40
- return !params.roles;
71
+ /** Only a call without roles or query folds tool/context runs. */
72
+ function foldsRuns(params) {
73
+ return !params.roles && params.query === undefined;
41
74
  }
42
75
  /** Folded counts stay exact even when some distinct tool names must be omitted. */
43
76
  function foldedRuns(events) {
@@ -54,37 +87,32 @@ function foldedRuns(events) {
54
87
  const entries = [...counts].filter(([name]) => name.length <= MAX_FOLD_TOOL_NAME_CHARS).slice(0, MAX_FOLD_TOOL_NAMES);
55
88
  // fromEntries preserves __proto__ as an ordinary key without mutating the prototype.
56
89
  const tools = Object.fromEntries(entries);
57
- const omitted = counts.size - entries.length;
58
- return [{ folded: true, first_seq: sorted[0].seq, last_seq: sorted.at(-1).seq, count: sorted.length, tools, ...(omitted > 0 ? { omitted_tools: omitted } : {}) }];
90
+ return [{ folded: true, first_seq: sorted[0].seq, last_seq: sorted.at(-1).seq, count: sorted.length, tools }];
59
91
  }
60
- function pageAnchors(vis, selected, before, after) {
92
+ /** A cursor exists only when the same selection still has a visible event past that end. */
93
+ function pageCursors(vis, selected, beforeSeq, afterSeq) {
61
94
  if (selected.length === 0)
62
- return { older_before: null, newer_after: null };
63
- const lower = after ?? 0;
64
- const upper = before ?? Number.POSITIVE_INFINITY;
95
+ return { page_older: null, page_newer: null };
96
+ const lower = afterSeq ?? 0;
97
+ const upper = beforeSeq ?? Number.POSITIVE_INFINITY;
65
98
  // Selected events are in seq order.
66
99
  const first = selected[0].seq;
67
100
  const last = selected.at(-1).seq;
68
101
  return {
69
- older_before: vis.some((event) => event.seq > lower && event.seq < first && event.seq < upper) ? first : null,
70
- newer_after: vis.some((event) => event.seq > last && event.seq < upper && event.seq > lower) ? last : null,
102
+ page_older: vis.some((event) => event.seq > lower && event.seq < first) ? { before_seq: first } : null,
103
+ page_newer: vis.some((event) => event.seq > last && event.seq < upper) ? { after_seq: last, from: "oldest" } : null,
71
104
  };
72
105
  }
73
- function foldRows(projection, params, selected, anchors) {
74
- const lower = params.after ?? 0;
75
- const upper = params.before ?? Number.POSITIVE_INFINITY;
106
+ function foldRows(projection, params, selected, cursors) {
76
107
  if (selected.length === 0) {
77
108
  // Even a range with no conversation can contain tool/context events.
78
- const hidden = allItems(projection).filter((event) => (typeof params.window_id !== "string" || params.window_id === event.windowId) && event.seq > lower && event.seq < upper && isFoldableEvent(event));
79
- return foldedRuns(hidden);
109
+ return foldedRuns(allItems(projection).filter((event) => inSelection(event, params) && isFoldableEvent(event)));
80
110
  }
81
- const windowEvents = allItems(projection)
82
- .filter((event) => (typeof params.window_id !== "string" || params.window_id === event.windowId) && event.seq > lower && event.seq < upper)
83
- .sort((a, b) => a.seq - b.seq);
111
+ const windowEvents = allItems(projection).filter((event) => inSelection(event, params)).sort((a, b) => a.seq - b.seq);
84
112
  const folded = [];
85
113
  const firstSeq = selected[0].seq;
86
114
  const lastSeq = selected.at(-1).seq;
87
- if (anchors.older_before === null)
115
+ if (cursors.page_older === null)
88
116
  folded.push(...foldedRuns(windowEvents.filter((event) => event.seq < firstSeq && isFoldableEvent(event))));
89
117
  // pageData already ordered selected by seq.
90
118
  for (let i = 0; i + 1 < selected.length; i++) {
@@ -92,52 +120,82 @@ function foldRows(projection, params, selected, anchors) {
92
120
  const right = selected[i + 1].seq;
93
121
  folded.push(...foldedRuns(windowEvents.filter((event) => event.seq > left && event.seq < right && isFoldableEvent(event))));
94
122
  }
95
- if (anchors.newer_after === null)
123
+ if (cursors.page_newer === null)
96
124
  folded.push(...foldedRuns(windowEvents.filter((event) => event.seq > lastSeq && isFoldableEvent(event))));
97
125
  return folded;
98
126
  }
99
127
  function pageData(projection, params, vis, selected, maxChars, folds) {
100
128
  const orderedSelected = [...selected].sort((a, b) => a.event.seq - b.event.seq);
101
129
  const selectedEvents = orderedSelected.map((candidate) => candidate.event);
102
- const anchors = pageAnchors(vis, selectedEvents, params.before, params.after);
130
+ const cursors = pageCursors(vis, selectedEvents, params.before_seq, params.after_seq);
103
131
  const visible = orderedSelected.map((candidate) => candidate.preview ?? visibleItem(candidate.event, maxChars, candidate.matchOffset));
104
132
  let rows = visible;
105
133
  if (folds) {
106
- const folded = foldRows(projection, params, selectedEvents, anchors);
134
+ const folded = foldRows(projection, params, selectedEvents, cursors);
107
135
  rows = [...visible, ...folded].sort((a, b) => ("folded" in a ? a.first_seq : a.seq) - ("folded" in b ? b.first_seq : b.seq));
108
136
  }
109
- return { items: rows, ...anchors };
137
+ return { items: rows, ...cursors };
138
+ }
139
+ /** Filter, then keep only literal matches when a query is present. Query shape errors refuse here. */
140
+ function selectionCandidates(projection, params) {
141
+ let queries;
142
+ if (params.query !== undefined) {
143
+ try {
144
+ queries = searchQueries(params.query);
145
+ }
146
+ catch (error) {
147
+ if (error instanceof InvalidQueryError)
148
+ return failure("invalid_query", error.message);
149
+ throw error;
150
+ }
151
+ }
152
+ const events = filteredItems(projection, params, queries === undefined);
153
+ if (queries === undefined)
154
+ return success(events.map((event) => ({ event })));
155
+ const needles = queries;
156
+ return success(events
157
+ .map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), needles) }))
158
+ .filter((candidate) => candidate.matchOffset >= 0));
110
159
  }
111
- function orderedCandidates(vis, before, after, limit) {
160
+ /**
161
+ * Take the limit from the end `from` names, starting there so a budget for one row keeps the most
162
+ * important row. The selection is already filtered to its range; `from` never states a direction.
163
+ */
164
+ function orderedCandidates(vis, params, limit) {
112
165
  const ascending = [...vis].sort((a, b) => a.event.seq - b.event.seq);
113
- if (before !== undefined && after !== undefined)
114
- return ascending.filter((candidate) => candidate.event.seq > after && candidate.event.seq < before).slice(0, limit);
115
- if (after !== undefined)
116
- return ascending.filter((candidate) => candidate.event.seq > after).slice(0, limit);
117
- if (before !== undefined)
118
- return ascending.filter((candidate) => candidate.event.seq < before).reverse().slice(0, limit);
119
- return ascending.slice(-limit).reverse();
166
+ const selected = params.from === "oldest" ? ascending.slice(0, limit) : ascending.slice(-limit);
167
+ return params.from === "oldest" ? selected : selected.reverse();
120
168
  }
121
- /** Grow the page in query order; shorten the first preview only when no full row fits. */
122
- export function selectPage(projection, params, vis, folds, fits, maxChars) {
123
- const before = params.before;
124
- const after = params.after;
125
- const limit = params.limit ?? 20;
126
- const candidates = orderedCandidates(vis, before, after, limit);
169
+ /**
170
+ * Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
171
+ * Grow the page in selection order; shorten the first preview only when no full row fits.
172
+ */
173
+ export function selectPage(projection, params, fits, maxChars) {
174
+ const bounds = resolveTimeBounds(params);
175
+ if (!bounds.ok)
176
+ return bounds;
177
+ const scoped = { ...params, ...bounds.data };
178
+ const candidates = selectionCandidates(projection, scoped);
179
+ if (!candidates.ok)
180
+ return candidates;
181
+ const vis = candidates.data;
182
+ const limit = scoped.limit ?? 20;
183
+ const folds = foldsRuns(scoped);
184
+ const ordered = orderedCandidates(vis, scoped, limit);
127
185
  const allVisible = vis.map((candidate) => candidate.event).sort((a, b) => a.seq - b.seq);
128
186
  const kept = [];
129
- for (const candidate of candidates) {
130
- if (fits(pageData(projection, params, allVisible, [...kept, candidate], maxChars, folds))) {
187
+ for (const candidate of ordered) {
188
+ if (fits(pageData(projection, scoped, allVisible, [...kept, candidate], maxChars, folds))) {
131
189
  kept.push(candidate);
132
190
  continue;
133
191
  }
134
192
  if (kept.length === 0)
135
- kept.push({ ...candidate, preview: truncateHistoryItem(visibleItem(candidate.event, maxChars, candidate.matchOffset), (preview) => fits(pageData(projection, params, allVisible, [{ ...candidate, preview }], maxChars, folds))) });
193
+ kept.push({ ...candidate, preview: truncateHistoryItem(visibleItem(candidate.event, maxChars, candidate.matchOffset), (preview) => fits(pageData(projection, scoped, allVisible, [{ ...candidate, preview }], maxChars, folds))) });
136
194
  break;
137
195
  }
138
- const page = pageData(projection, params, allVisible, kept, maxChars, folds);
196
+ const page = pageData(projection, scoped, allVisible, kept, maxChars, folds);
139
197
  if (!fits(page)) {
140
- return failure("page_too_large", `${page.items.length} history rows and their fold summary do not fit one response even at their smallest; narrow the range with before/after or read one seq`, { rows: page.items.length });
198
+ return failure("page_too_large", `${page.items.length} history rows and their fold summary do not fit one response even at their smallest; narrow with before_seq/after_seq or since/until, or read one seq`);
141
199
  }
142
200
  return success(page);
143
201
  }
@@ -44,8 +44,8 @@ export type NotesQuery = ({
44
44
  scope: "agent" | "model";
45
45
  who?: string;
46
46
  }) & {
47
- pattern?: string;
48
- wastebasket?: boolean;
47
+ glob?: string;
48
+ crumpled?: boolean;
49
49
  };
50
50
  /** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
51
51
  export type NoteReadResult = {
@@ -62,7 +62,7 @@ export type NoteChange = {
62
62
  before: "";
63
63
  after: "";
64
64
  } | {
65
- kind: "body" | "metadata" | "file";
65
+ kind: "body" | "metadata";
66
66
  before: string;
67
67
  after: string;
68
68
  };
@@ -77,7 +77,6 @@ export type NoteRenameResult = {
77
77
  replacedCrumpledTarget: boolean;
78
78
  };
79
79
  export type NoteQueryStatus = {
80
- crumpledExcluded: number;
81
80
  homesUnavailable: string[];
82
81
  };
83
82
  export type NoteQueryResult<T> = {
@@ -139,7 +139,7 @@ async function homesFor(identity, opts) {
139
139
  }
140
140
  if (opts.who !== undefined)
141
141
  throw new NoteError("invalid_scope", "who requires agent or model scope");
142
- return await homesForPattern(normalizePattern(opts.pattern, identity), identity) ?? SCOPE_ORDER.map((scope) => ({ scope }));
142
+ return await homesForPattern(normalizePattern(opts.glob, identity), identity) ?? SCOPE_ORDER.map((scope) => ({ scope }));
143
143
  }
144
144
  /**
145
145
  * Line numbers (1-based) of every occurrence of `needle` in `body`. The scan walks forward
@@ -331,8 +331,10 @@ export function createNotesStore(input) {
331
331
  assertSerializedSize(serialized);
332
332
  const metadataChanged = originChanged || beforeMeta.crumpledAt !== meta.crumpledAt;
333
333
  let change;
334
+ // A body edit that also rewrites frontmatter is still a body change; its diff inputs span the
335
+ // whole serialized file, so the frontmatter part stays visible in the diff.
334
336
  if (bodyChanged && metadataChanged)
335
- change = { kind: "file", before: raw, after: serialized };
337
+ change = { kind: "body", before: raw, after: serialized };
336
338
  else if (bodyChanged)
337
339
  change = { kind: "body", before: body, after: next };
338
340
  else if (metadataChanged)
@@ -385,22 +387,21 @@ export function createNotesStore(input) {
385
387
  }));
386
388
  }
387
389
  async function* scan(options, status) {
388
- const matcher = matcherFor(normalizePattern(options.pattern, identity));
390
+ const matcher = matcherFor(normalizePattern(options.glob, identity));
389
391
  let homes;
390
392
  try {
391
393
  homes = await homesFor(identity, options);
392
394
  }
393
395
  catch (error) {
394
- if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.pattern ?? ""))
396
+ if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? ""))
395
397
  throw error;
396
- status.homesUnavailable.push(options.pattern.startsWith("@agents/") ? "@agents" : "@models");
398
+ status.homesUnavailable.push(options.glob.startsWith("@agents/") ? "@agents" : "@models");
397
399
  return;
398
400
  }
399
401
  for (const home of homes) {
400
402
  const scope = home.scope;
401
403
  const root = scopeDir(scope, identity, home.who);
402
404
  const homeRows = [];
403
- let excluded = 0;
404
405
  try {
405
406
  for (const path of await walkMarkdown(root)) {
406
407
  if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who)))
@@ -410,11 +411,8 @@ export function createNotesStore(input) {
410
411
  const raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
411
412
  const { meta, body } = parseNote(raw);
412
413
  meta.scope = scope;
413
- if ((meta.crumpledAt !== undefined) !== (options.wastebasket === true)) {
414
- if (meta.crumpledAt !== undefined)
415
- excluded++;
414
+ if ((meta.crumpledAt !== undefined) !== (options.crumpled === true))
416
415
  continue;
417
- }
418
416
  homeRows.push({ address, scope, path, meta, body });
419
417
  }
420
418
  }
@@ -424,8 +422,6 @@ export function createNotesStore(input) {
424
422
  status.homesUnavailable.push(addressFor(identity, scope, "", home.who).replace(/\/$/, "") || "session");
425
423
  continue;
426
424
  }
427
- if (status)
428
- status.crumpledExcluded += excluded;
429
425
  for (const row of homeRows)
430
426
  yield row;
431
427
  }
@@ -440,10 +436,10 @@ export function createNotesStore(input) {
440
436
  rows.push({ ...row, sizeBytes: Buffer.byteLength(row.body, "utf8") });
441
437
  }
442
438
  rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
443
- return { rows, status: status ?? { crumpledExcluded: 0, homesUnavailable: [] } };
439
+ return { rows, status: status ?? { homesUnavailable: [] } };
444
440
  }
445
441
  function listWithStatus(options = {}) {
446
- return listRows(options, { crumpledExcluded: 0, homesUnavailable: [] });
442
+ return listRows(options, { homesUnavailable: [] });
447
443
  }
448
444
  async function search(queries, options = {}) {
449
445
  return (await searchRows(queries, options)).rows;
@@ -469,10 +465,10 @@ export function createNotesStore(input) {
469
465
  rows.push({ address, path, scope, meta, matches });
470
466
  }
471
467
  rows.sort((a, b) => a.address.localeCompare(b.address));
472
- return { rows, status: status ?? { crumpledExcluded: 0, homesUnavailable: [] } };
468
+ return { rows, status: status ?? { homesUnavailable: [] } };
473
469
  }
474
470
  function searchWithStatus(queries, options = {}) {
475
- return searchRows(queries, options, { crumpledExcluded: 0, homesUnavailable: [] });
471
+ return searchRows(queries, options, { homesUnavailable: [] });
476
472
  }
477
473
  return { write, read, update, rename, list, search, listWithStatus, searchWithStatus };
478
474
  }
@@ -1,3 +1,3 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- /** Register the four shared history operations; the adapter allocates addresses and supplies them. */
2
+ /** Register the three shared history operations; the adapter allocates addresses and supplies them. */
3
3
  export declare function registerHistoryTools(pi: ExtensionAPI): void;
@@ -1,10 +1,9 @@
1
- import { historyWindows, historyList, historyRead, historySearch } from "../tools/history.js";
1
+ import { historyWindows, historyList, historyRead } from "../tools/history.js";
2
2
  import { historyFromSession } from "./history.js";
3
3
  import { HISTORY_NAMESPACE, registerOperation } from "./tool-result.js";
4
- /** Register the four shared history operations; the adapter allocates addresses and supplies them. */
4
+ /** Register the three shared history operations; the adapter allocates addresses and supplies them. */
5
5
  export function registerHistoryTools(pi) {
6
6
  registerOperation(pi, historyWindows, (params, ctx) => historyWindows.execute(params, historyFromSession(ctx), ctx.sessionManager.getSessionId()), HISTORY_NAMESPACE);
7
7
  registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE);
8
8
  registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE);
9
- registerOperation(pi, historySearch, (params, ctx) => historySearch.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE);
10
9
  }
@@ -58,7 +58,7 @@ export function registerContext(pi, settingsManager) {
58
58
  return;
59
59
  incompleteNotesNotified.add(windowId);
60
60
  const homes = snapshot.unavailable.map((home) => home.label).join(", ");
61
- ctx.ui.notify(`notesoup: notes index incomplete for ${homes}; notes_list can retry after recovery.`, "warning");
61
+ ctx.ui.notify(`notesoup: notes index incomplete for ${homes}; \`notes_list\` can retry after recovery.`, "warning");
62
62
  };
63
63
  const budget = registerBudget(pi, () => enabled, settingsManager, (windowId) => resets.closeOut(windowId, "automatic"));
64
64
  pi.on("session_start", async (_event, ctx) => {
@@ -2,10 +2,6 @@ export declare const PI_TOOL_NAMES: {
2
2
  readonly notes: "notes_*";
3
3
  readonly notesList: "notes_list";
4
4
  readonly history: "history_*";
5
- readonly historyWindows: "history_windows";
6
- readonly historyList: "history_list";
7
- readonly historySearch: "history_search";
8
- readonly historyRead: "history_read";
9
5
  readonly remaining: "get_context_remaining";
10
6
  readonly wipe: "clear_memory";
11
7
  };
@@ -2,10 +2,6 @@ export const PI_TOOL_NAMES = {
2
2
  notes: "notes_*",
3
3
  notesList: "notes_list",
4
4
  history: "history_*",
5
- historyWindows: "history_windows",
6
- historyList: "history_list",
7
- historySearch: "history_search",
8
- historyRead: "history_read",
9
5
  remaining: "get_context_remaining",
10
6
  wipe: "clear_memory",
11
7
  };
@@ -3,65 +3,56 @@ import { Type, type Static } from "typebox";
3
3
  import { type Operation } from "./result.js";
4
4
  import { type HistoryPage } from "../history/query.js";
5
5
  import { type HistoryProjection } from "../history/history.js";
6
- declare const HistoryWindowsDataSchema: Type.TObject<{
7
- session_id: Type.TString;
8
- windows: Type.TArray<Type.TObject<{
9
- window_id: Type.TString;
10
- created_at: Type.TUnion<[Type.TString, Type.TNull]>;
11
- first_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
12
- last_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
13
- item_count: Type.TInteger;
14
- }>>;
15
- more: Type.TInteger;
16
- }>;
17
- type HistoryWindowsData = Static<typeof HistoryWindowsDataSchema>;
18
6
  /** One read: identity, tool summary and a flat document slice. */
19
7
  declare const HistoryReadDataSchema: Type.TObject<{
20
8
  text: Type.TString;
21
- offset_chars: Type.TInteger;
22
9
  total_chars: Type.TInteger;
23
10
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
24
- limited_by: Type.TUnion<[Type.TLiteral<"limit">, Type.TLiteral<"bytes">, Type.TNull]>;
25
- tool: Type.TOptional<Type.TString>;
26
- tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
27
- output_truncated: Type.TOptional<Type.TBoolean>;
28
- full_output_path: Type.TOptional<Type.TString>;
29
11
  nested_calls: Type.TOptional<Type.TObject<{
30
12
  call_count: Type.TInteger;
31
13
  complete: Type.TBoolean;
32
14
  }>>;
15
+ tool: Type.TOptional<Type.TString>;
16
+ tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
17
+ output_truncated: Type.TOptional<Type.TLiteral<true>>;
18
+ full_output_path: Type.TOptional<Type.TString>;
33
19
  seq: Type.TInteger;
34
20
  window_id: Type.TString;
35
21
  role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
36
22
  created_at: Type.TUnion<[Type.TString, Type.TNull]>;
37
23
  }>;
38
24
  type HistoryReadData = Static<typeof HistoryReadDataSchema>;
25
+ declare const HistoryWindowsDataSchema: Type.TObject<{
26
+ session_id: Type.TString;
27
+ windows: Type.TArray<Type.TObject<{
28
+ window_id: Type.TString;
29
+ created_at: Type.TUnion<[Type.TString, Type.TNull]>;
30
+ first_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
31
+ last_seq: Type.TUnion<[Type.TInteger, Type.TNull]>;
32
+ }>>;
33
+ more: Type.TInteger;
34
+ }>;
35
+ type HistoryWindowsData = Static<typeof HistoryWindowsDataSchema>;
39
36
  export declare const PREVIOUS_WINDOW = "@previous";
40
37
  export declare const historyWindowsParameters: Type.TObject<{}>;
41
38
  export declare const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string]>;
42
39
  export declare const historyListParameters: Type.TObject<{
43
- limit: Type.TOptional<Type.TInteger>;
40
+ query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
44
41
  roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
45
- before: Type.TOptional<Type.TInteger>;
46
- after: Type.TOptional<Type.TInteger>;
42
+ before_seq: Type.TOptional<Type.TInteger>;
43
+ after_seq: Type.TOptional<Type.TInteger>;
44
+ since: Type.TOptional<Type.TString>;
45
+ until: Type.TOptional<Type.TString>;
46
+ from: Type.TOptional<Type.TUnion<[Type.TLiteral<"newest">, Type.TLiteral<"oldest">]>>;
47
47
  window_id: Type.TOptional<Type.TString>;
48
+ limit: Type.TOptional<Type.TInteger>;
48
49
  max_chars_per_item: Type.TOptional<Type.TInteger>;
49
50
  }>;
50
51
  export declare const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection]>;
51
52
  export declare const historyReadParameters: Type.TObject<{
52
- seq: Type.TInteger;
53
53
  offset_chars: Type.TOptional<Type.TInteger>;
54
- limit_chars: Type.TOptional<Type.TInteger>;
54
+ max_chars: Type.TOptional<Type.TInteger>;
55
+ seq: Type.TInteger;
55
56
  }>;
56
57
  export declare const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection]>;
57
- export declare const historySearchParameters: Type.TObject<{
58
- query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
59
- limit: Type.TOptional<Type.TInteger>;
60
- roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
61
- before: Type.TOptional<Type.TInteger>;
62
- after: Type.TOptional<Type.TInteger>;
63
- window_id: Type.TOptional<Type.TString>;
64
- max_chars_per_item: Type.TOptional<Type.TInteger>;
65
- }>;
66
- export declare const historySearch: Operation<typeof historySearchParameters, HistoryPage, [HistoryProjection]>;
67
58
  export {};