notesoup 0.59.1 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -17
- package/dist/plugins/claude/src/helper.js +3 -4
- package/dist/plugins/codex/src/mcp.js +1 -2
- package/dist/plugins/dsh/tools.js +1 -2
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +2 -3
- package/dist/src/history/claude.d.ts +3 -1
- package/dist/src/history/claude.js +40 -4
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- package/dist/src/history/prefilter.d.ts +1 -1
- package/dist/src/history/prefilter.js +14 -9
- package/dist/src/history/query.d.ts +3 -14
- package/dist/src/history/query.js +73 -85
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/address.js +3 -3
- package/dist/src/notes/store.d.ts +2 -4
- package/dist/src/notes/store.js +1 -2
- package/dist/src/tools/history.d.ts +4 -6
- package/dist/src/tools/history.js +69 -29
- package/dist/src/tools/notes.d.ts +18 -78
- package/dist/src/tools/notes.js +39 -50
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/claude-history.test.js +27 -6
- package/dist/test/claude-mod.test.js +19 -8
- package/dist/test/codex-history.test.js +1 -1
- package/dist/test/codex-plugin.test.js +1 -2
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh.test.js +2 -2
- package/dist/test/history-corpus.test.js +21 -36
- package/dist/test/history-prefilter.test.js +5 -0
- package/dist/test/history-summary-cache.test.js +3 -3
- package/dist/test/history.integration.test.js +53 -106
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/note-policy.test.js +5 -5
- package/dist/test/notes-cwd.test.js +5 -5
- package/dist/test/notes-query-namespaces.test.js +2 -6
- package/dist/test/notes.integration.test.js +30 -35
- package/dist/test/notes.test.js +12 -14
- package/dist/test/project-namespace.test.js +3 -3
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +5 -3
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +9 -10
- package/docs/notes-library.md +3 -3
- package/docs/tool-results.md +12 -6
- package/package.json +1 -1
- package/plugins/claude/dist/claude/helper.js +214 -173
- package/plugins/claude/hooks/register.ts +8 -6
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +3 -4
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +176 -160
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/paseo/README.md +16 -0
- package/plugins/paseo/client/brain-empty-card.tsx +5 -3
- package/plugins/paseo/client/markdown-core.tsx +189 -0
- package/plugins/paseo/client/markdown.tsx +38 -135
- package/plugins/paseo/client/notes-op-card.tsx +15 -12
- package/plugins/paseo/client/paper-card.tsx +1 -3
- package/plugins/paseo/client/sticky-card.tsx +2 -1
- package/plugins/paseo/client/typography.ts +24 -0
- package/plugins/paseo/test/markdown-core.test.ts +75 -0
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/history/claude.ts +31 -4
- package/src/history/history.ts +11 -16
- package/src/history/prefilter.ts +13 -9
- package/src/history/query.ts +67 -99
- package/src/index.ts +1 -1
- package/src/notes/address.ts +2 -2
- package/src/notes/store.ts +3 -6
- package/src/tools/history.ts +60 -29
- package/src/tools/notes.ts +39 -54
- package/src/tools/schema.ts +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
|
|
7
|
+
// Exercise the actual renderer with RN host primitives, not a native layout emulator.
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const opened: string[] = [];
|
|
10
|
+
const source = readFileSync(new URL("../client/markdown-core.tsx", import.meta.url), "utf8");
|
|
11
|
+
const { outputText } = ts.transpileModule(source, {
|
|
12
|
+
compilerOptions: { jsx: ts.JsxEmit.ReactJSX, module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
|
13
|
+
});
|
|
14
|
+
const compiled = { exports: {} as any };
|
|
15
|
+
new Function("require", "module", "exports", outputText)(
|
|
16
|
+
(id: string) => id === "react-native"
|
|
17
|
+
? { Text: "Text", View: "View", ScrollView: "ScrollView", Linking: { openURL: (url: string) => { opened.push(url); return Promise.resolve(); } } }
|
|
18
|
+
: require(id),
|
|
19
|
+
compiled, compiled.exports,
|
|
20
|
+
);
|
|
21
|
+
const { renderBlocks, renderInlines } = compiled.exports;
|
|
22
|
+
const { lexer, Lexer } = require("marked");
|
|
23
|
+
const styles = new Proxy({}, { get: () => ({}) });
|
|
24
|
+
function elements(node: any): any[] {
|
|
25
|
+
if (Array.isArray(node)) return node.flatMap(elements);
|
|
26
|
+
if (!node || typeof node !== "object") return [];
|
|
27
|
+
return [node, ...elements(node.props?.children)];
|
|
28
|
+
}
|
|
29
|
+
function text(node: any): string {
|
|
30
|
+
if (Array.isArray(node)) return node.map(text).join("");
|
|
31
|
+
if (node == null) return "";
|
|
32
|
+
return typeof node === "object" ? text(node.props?.children) : String(node);
|
|
33
|
+
}
|
|
34
|
+
const render = (markdown: string, openLinks?: boolean) => renderBlocks(lexer(markdown), styles, "test", undefined, openLinks);
|
|
35
|
+
|
|
36
|
+
test("inline nesting, entities, br and empty-alt images render cleanly", () => {
|
|
37
|
+
const result = renderInlines(Lexer.lexInline("**bold *nested*** — A `a < b & c`<br>"), styles, "inline");
|
|
38
|
+
assert.equal(text(result), "bold nested — A a < b & c\n[image]");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("ordered starts, tight and loose task markers survive without duplicate checkboxes", () => {
|
|
42
|
+
assert.match(text(render("3. third\n4. fourth")), /3\.third4\.fourth/);
|
|
43
|
+
const tight = text(render("- [x] done\n- [ ] pending\n - child"));
|
|
44
|
+
assert.match(tight, /☑done/);
|
|
45
|
+
assert.match(tight, /☐pending/);
|
|
46
|
+
assert.match(tight, /•child/);
|
|
47
|
+
const loose = text(render("- [x] first\n\n- [ ] second"));
|
|
48
|
+
assert.equal(loose, "☑first☐second");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("safe links open only when enabled and block unsafe schemes", () => {
|
|
52
|
+
opened.length = 0;
|
|
53
|
+
const disabled = elements(render("[ok](https://example.com?a=1&b=2)", false)).find(n => typeof n.props?.onPress === "function");
|
|
54
|
+
assert.equal(disabled, undefined);
|
|
55
|
+
const inlineDefault = elements(renderInlines(Lexer.lexInline("[peek](https://example.com)"), styles, "peek")).find(n => typeof n.props?.onPress === "function");
|
|
56
|
+
assert.equal(inlineDefault, undefined);
|
|
57
|
+
|
|
58
|
+
const active = elements(render("[ok](https://example.com?a=1&b=2) [bad](javascript:alert(1)) [mail](mailto:hi@example.com)"));
|
|
59
|
+
const handlers = active.filter(n => typeof n.props?.onPress === "function");
|
|
60
|
+
assert.equal(handlers.length, 2);
|
|
61
|
+
handlers.forEach(n => n.props.onPress());
|
|
62
|
+
assert.deepEqual(opened, ["https://example.com?a=1&b=2", "mailto:hi@example.com"]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("tables size by visible CJK/link text and stay horizontally scrollable", () => {
|
|
66
|
+
const md = "# Heading\n\n| [详情](https://very-long.example.com/path/to/doc) | 状态说明 |\n| :--- | ---: |\n| x<br>y | 值 |\n\n```\n&\n```";
|
|
67
|
+
const nodes = elements(render(md));
|
|
68
|
+
assert.equal(nodes.filter(n => n.type === "ScrollView" && n.props.horizontal).length, 2);
|
|
69
|
+
assert.ok(nodes.filter(n => n.type === "Text" && n.props.selectable !== undefined).every(n => n.props.selectable));
|
|
70
|
+
const headerCells = nodes.filter(n => Array.isArray(n.props.style) && n.props.style.some((s: any) => typeof s?.width === "number")).slice(0, 2);
|
|
71
|
+
const [linkColWidth, cjkColWidth] = headerCells.map(n => n.props.style.find((s: any) => typeof s?.width === "number").width);
|
|
72
|
+
assert.ok(linkColWidth < 80, `expected visible link text width, got ${linkColWidth}`);
|
|
73
|
+
assert.ok(cjkColWidth > 64, `expected CJK header width above ASCII floor, got ${cjkColWidth}`);
|
|
74
|
+
assert.ok(nodes.some(n => n.type === "Text" && text(n) === "&"));
|
|
75
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateDiffString, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { notesWrite, notesUpdate, notesRead, notesList
|
|
2
|
+
import { notesWrite, notesUpdate, notesRead, notesList } from "../../../src/tools/notes.js";
|
|
3
3
|
import { abandonDream, dreamBegin, dreamEnd, dreamForget, dreamingIdentity, type DreamState } from "../../../src/tools/dream.js";
|
|
4
4
|
import { notesIdentityFromPi } from "./adapter.js";
|
|
5
5
|
import { notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../render.js";
|
|
@@ -11,7 +11,7 @@ function renderDiff(change: NoteChange): string {
|
|
|
11
11
|
return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** Register the
|
|
14
|
+
/** Register the shared note operations and the three hidden dream tools; an open dream widens the note identity. */
|
|
15
15
|
export function registerNotesTools(pi: ExtensionAPI) {
|
|
16
16
|
// One pending or open dream per session: shutdown releases ownership without the end commit.
|
|
17
17
|
const dreams = new Map<string, DreamState>();
|
|
@@ -35,7 +35,6 @@ export function registerNotesTools(pi: ExtensionAPI) {
|
|
|
35
35
|
}, NOTES_NAMESPACE, notesUpdateRenderers);
|
|
36
36
|
registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
|
|
37
37
|
registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
38
|
-
registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
39
38
|
registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
40
39
|
registerOperation(pi, dreamForget, (params, ctx) => dreamForget.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
41
40
|
registerOperation(pi, dreamEnd, (params, ctx) => dreamEnd.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -38,15 +38,15 @@ Keep notes focused on what is true now; if a piece of past context still matters
|
|
|
38
38
|
|
|
39
39
|
## Finding things again
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
In `notes_list`, omit `glob` for this session and the current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions.
|
|
42
42
|
|
|
43
|
-
- **A note**:
|
|
44
|
-
- **Something that happened**: `history_list`
|
|
45
|
-
- **An earlier window**: use its seq range from the boot window tree with `history_list`'s `
|
|
43
|
+
- **A note**: add `glob` to narrow where `notes_list` looks, and `query` if you remember a phrase. Then use `notes_read` with the address and, for a match, its `offset_chars`.
|
|
44
|
+
- **Something that happened**: `history_list` browses or searches this session's events. Add `context: 1` with a `query` to include neighboring events. Use `history_read` with the seq for the whole event.
|
|
45
|
+
- **An earlier window**: use its seq range from the boot window tree with `history_list`'s exclusive `after` / `before` bounds, or search for a remembered phrase. With `after` you page forward; otherwise you page back from the newest eligible end.
|
|
46
46
|
- **Another session**: pass `session: "<id-or-prefix>"` or `"pi:<id>"`, `"claude:<id>"`, `"codex:<id>"`, `"dsh:<id>"`. An unqualified selector checks this harness first. If ambiguous, use a longer ID or a harness prefix; never pick a candidate blindly.
|
|
47
|
-
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard
|
|
47
|
+
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard takes ISO 8601 times only in `after` / `before` and cannot use `history_read`. Hits cover every role unless `roles` narrows them. Results are chronological and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
|
|
48
48
|
|
|
49
|
-
- **Recent sessions, no remembered phrase**: `history_list({ session: "*" })` returns one representative event per session, preferring its first visible user prompt, up to `limit` (default 20). Sessions are chosen newest-modified first (
|
|
49
|
+
- **Recent sessions, no remembered phrase**: `history_list({ session: "*" })` returns one representative event per session, preferring its first visible user prompt, up to `limit` (default 20). Sessions are chosen newest-modified first (oldest-modified first with `after`), then results are sorted chronologically. Empty queries also browse. Role/time filters apply before choosing representatives; with `roles`, the latest matching event represents each session. No paging cursors.
|
|
50
50
|
|
|
51
51
|
Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. A single unreadable or unsupported local transcript refuses explicitly; wildcards skip individual sessions that cannot load. An empty result is not proof the remembered event never happened.
|
|
52
52
|
|
package/src/history/claude.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/** Claude's persisted main transcript -> the shared history projection. No inference-context API. */
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
3
4
|
import { isDeepStrictEqual } from "node:util";
|
|
4
5
|
import { contentText, projectHistory, type DecodedHistoryItem, type DecodedHistoryWindow, type HistoryProjection } from "./history.js";
|
|
5
6
|
|
|
7
|
+
class UnpersistedClaudeHead extends Error {
|
|
8
|
+
constructor() { super("Claude history active head is not persisted yet; retry after the transcript write"); }
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
type Row = Record<string, unknown>;
|
|
7
12
|
type WindowPosition = { ordinal: number } | { unknownAncestor: string };
|
|
8
13
|
type Version = { row: Row; ancestorUuid?: string; ancestor?: Version; position?: WindowPosition };
|
|
@@ -180,7 +185,7 @@ function claudeHistoryFromRows(rows: Row[], source: Omit<ClaudeHistorySource, "t
|
|
|
180
185
|
return version.position!;
|
|
181
186
|
}
|
|
182
187
|
if (!source.headUuid) throw new Error("Claude history has no confirmed active head yet; wait for a main-session append after startup/resume");
|
|
183
|
-
if (!nodes.has(source.headUuid)) throw new
|
|
188
|
+
if (!nodes.has(source.headUuid)) throw new UnpersistedClaudeHead();
|
|
184
189
|
|
|
185
190
|
// The inference tree uses the latest rewritten parents. At a compact boundary the logical
|
|
186
191
|
// parent and preserved segments use ORIGINAL ancestry: the old context is still history.
|
|
@@ -299,7 +304,29 @@ export function offlineClaudeHistoryFromJsonl(text: string, sessionId: string):
|
|
|
299
304
|
return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
|
|
300
305
|
}
|
|
301
306
|
|
|
302
|
-
export async function readClaudeHistory(source: ClaudeHistorySource): Promise<ClaudeHistoryProjection> {
|
|
307
|
+
export async function readClaudeHistory(source: ClaudeHistorySource, { waitForHead = false } = {}): Promise<ClaudeHistoryProjection> {
|
|
303
308
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string") throw new Error("Claude history transcript_path is unavailable");
|
|
304
|
-
|
|
309
|
+
const snapshot = { ...source };
|
|
310
|
+
const read = async () => claudeHistoryFromJsonl(await readFile(snapshot.transcriptPath, "utf8"), snapshot);
|
|
311
|
+
if (!waitForHead || !snapshot.headUuid) return read();
|
|
312
|
+
const revision = async () => {
|
|
313
|
+
const { dev, ino, size, mtimeNs, ctimeNs } = await stat(snapshot.transcriptPath, { bigint: true });
|
|
314
|
+
return `${dev}:${ino}:${size}:${mtimeNs}:${ctimeNs}`;
|
|
315
|
+
};
|
|
316
|
+
let seen = await revision();
|
|
317
|
+
try { return await read(); }
|
|
318
|
+
catch (error) {
|
|
319
|
+
if (!(error instanceof UnpersistedClaudeHead)) throw error;
|
|
320
|
+
// A kept append can reach the tool before its disk write. Only retry that same
|
|
321
|
+
// head, and only reparse on file changes. Never fall back to an offline leaf.
|
|
322
|
+
for (const delay of [50, 100, 200, 300, 350]) {
|
|
323
|
+
await sleep(delay);
|
|
324
|
+
const current = await revision();
|
|
325
|
+
if (current === seen) continue;
|
|
326
|
+
seen = current;
|
|
327
|
+
try { return await read(); }
|
|
328
|
+
catch (retry) { if (!(retry instanceof UnpersistedClaudeHead)) throw retry; }
|
|
329
|
+
}
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
305
332
|
}
|
package/src/history/history.ts
CHANGED
|
@@ -46,7 +46,8 @@ export type HistoryWindow = { windowId: string; createdAt?: string; items: Histo
|
|
|
46
46
|
/** Paired result seqs stay on the branch but redirect readers to the call's event. */
|
|
47
47
|
export type HistoryProjection = { windows: HistoryWindow[]; highestSeq: number; branchSeqs: Set<number>; pairedResults: Map<number, number> };
|
|
48
48
|
/** The filters one selection applies before paging: roles, seq bounds, and parsed epoch-ms time bounds. */
|
|
49
|
-
export type
|
|
49
|
+
export type HistoryBound = { seq: number } | { at: number };
|
|
50
|
+
export type HistoryFilter = { roles?: HistoryRole[]; after?: HistoryBound; before?: HistoryBound };
|
|
50
51
|
|
|
51
52
|
/** Native entries after the adapter allocates seqs and selects the active branch. */
|
|
52
53
|
export type DecodedHistoryItem = {
|
|
@@ -221,6 +222,7 @@ export type HistoryFoldedRow = Static<typeof HistoryFoldedRowSchema>;
|
|
|
221
222
|
export const HistoryPageItemSchema = Type.Object({
|
|
222
223
|
session: Type.Optional(Type.String()),
|
|
223
224
|
folded_before: Type.Optional(HistoryFoldedRowSchema),
|
|
225
|
+
context: Type.Optional(Type.Literal(true, { description: "A neighbor of a search hit, not a hit in this page." })),
|
|
224
226
|
seq: Type.Integer({ minimum: 1 }),
|
|
225
227
|
role: HistoryRoleSchema,
|
|
226
228
|
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
@@ -260,23 +262,16 @@ export function allItems(projection: HistoryProjection): HistoryEvent[] {
|
|
|
260
262
|
return projection.windows.flatMap((current) => current.items);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (params.before_seq !== undefined && event.seq >= params.before_seq) return false;
|
|
271
|
-
if (params.sinceMs === undefined && params.untilMs === undefined) return true;
|
|
272
|
-
if (event.createdAt === undefined) return false;
|
|
273
|
-
const at = Date.parse(event.createdAt);
|
|
274
|
-
return !Number.isNaN(at) && (params.sinceMs === undefined || at >= params.sinceMs) && (params.untilMs === undefined || at < params.untilMs);
|
|
265
|
+
function compareBound(event: HistoryEvent, bound: HistoryBound): number {
|
|
266
|
+
return "seq" in bound ? event.seq - bound.seq : Date.parse(event.createdAt ?? "") - bound.at;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function matchesFilter(event: HistoryEvent, { after, before, roles }: HistoryFilter): boolean {
|
|
270
|
+
return (!after || compareBound(event, after) > 0) && (!before || compareBound(event, before) < 0)
|
|
271
|
+
&& (!roles || roles.includes(event.role));
|
|
275
272
|
}
|
|
276
273
|
|
|
277
274
|
/** Ordered events inside the requested seq/time range and optional roles, before folding. */
|
|
278
275
|
export function filteredItems(projection: HistoryProjection, params: HistoryFilter): HistoryEvent[] {
|
|
279
|
-
return allItems(projection)
|
|
280
|
-
.filter((item) => inSelection(item, params) && (!params.roles || params.roles.includes(item.role)))
|
|
281
|
-
.sort((a, b) => a.seq - b.seq);
|
|
276
|
+
return allItems(projection).filter(event => matchesFilter(event, params)).sort((a, b) => a.seq - b.seq);
|
|
282
277
|
}
|
package/src/history/prefilter.ts
CHANGED
|
@@ -13,7 +13,7 @@ const PRESENTATION = `Codex unknown arguments not recorded output nested calls c
|
|
|
13
13
|
FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
|
|
14
14
|
the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
|
|
15
15
|
const HISTORY_BASE = '"history_base"';
|
|
16
|
-
export type HistoryPrefilter = (chunks: AsyncIterable<Uint8Array>, codex?: boolean) => Promise<boolean>;
|
|
16
|
+
export type HistoryPrefilter = (chunks: AsyncIterable<Uint8Array>, codex?: boolean, stopOnHit?: boolean) => Promise<boolean>;
|
|
17
17
|
|
|
18
18
|
/** Compile literal Unicode case matching once, then keep only per-file token bits and a bounded tail. */
|
|
19
19
|
export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefilter {
|
|
@@ -27,7 +27,7 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
|
|
|
27
27
|
}));
|
|
28
28
|
// No safe tokens (or generated text alone) cannot prove a miss.
|
|
29
29
|
const fallback = !alternatives.length || alternatives.some((tokens) => tokens.length === 0);
|
|
30
|
-
return async (chunks, codex = false) => {
|
|
30
|
+
return async (chunks, codex = false, stopOnHit = false) => {
|
|
31
31
|
const decoder = new StringDecoder("utf8");
|
|
32
32
|
const seen = alternatives.map((tokens) => tokens.map(() => false));
|
|
33
33
|
let rawTail = "", normalizedTail = "", pending = "", possible = fallback;
|
|
@@ -55,7 +55,10 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
|
|
|
55
55
|
rawTail = raw.slice(-overlap);
|
|
56
56
|
normalizedTail = normalized.slice(-overlap);
|
|
57
57
|
};
|
|
58
|
-
for await (const chunk of chunks)
|
|
58
|
+
for await (const chunk of chunks) {
|
|
59
|
+
if (!possible) scan(decoder.write(chunk));
|
|
60
|
+
if (possible && stopOnHit) return true;
|
|
61
|
+
}
|
|
59
62
|
if (!possible) scan(decoder.end(), true);
|
|
60
63
|
return possible;
|
|
61
64
|
};
|
|
@@ -63,12 +66,13 @@ export function createHistoryPrefilter(queries: readonly string[]): HistoryPrefi
|
|
|
63
66
|
|
|
64
67
|
/** The byte budget comes from the strict Codex reader; Pi/Claude have no such native limit. */
|
|
65
68
|
export async function historyFileMayMatch(path: string, prefilter: HistoryPrefilter, codex = false, maxBytes = codex ? CODEX_TRANSCRIPT_MAX_BYTES : Infinity): Promise<boolean> {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
// Plain Pi/Claude files will be read and validated by the strict decoder on a possible
|
|
70
|
+
// hit. Don't drain a potentially huge file just to read it from the beginning again.
|
|
71
|
+
if (!codex) return prefilter(createReadStream(path), false, true);
|
|
72
|
+
const info = await stat(path);
|
|
73
|
+
if (!info.isFile() || info.size > maxBytes) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
|
|
74
|
+
// Native Codex compression is zstd; scan through EOF to enforce the decoded size limit.
|
|
75
|
+
const compressed = path.endsWith(".jsonl.zst");
|
|
72
76
|
if (compressed && typeof zlib.createZstdDecompress !== "function") throw new Error("Compressed Codex rollouts require Node >=22.15 (createZstdDecompress)");
|
|
73
77
|
const input = createReadStream(path);
|
|
74
78
|
const consume = async (chunks: AsyncIterable<Buffer>) => {
|
package/src/history/query.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
|
-
import {
|
|
4
|
-
import { earliestMatchOffsetChars,
|
|
5
|
-
import { eventDocument, filteredItems, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS, type HistoryEvent, type HistoryFilter, type HistoryFoldedRow, type HistoryPageItem, type HistoryProjection } from "./history.js";
|
|
3
|
+
import { success, type Outcome } from "../result.js";
|
|
4
|
+
import { earliestMatchOffsetChars, prefixFit } from "../text-match.js";
|
|
5
|
+
import { eventDocument, filteredItems, matchesFilter, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS, type HistoryEvent, type HistoryFilter, type HistoryFoldedRow, type HistoryPageItem, type HistoryProjection } from "./history.js";
|
|
6
6
|
|
|
7
|
-
type Candidate = { event: HistoryEvent; session?: string; matchOffset?: number; preview?: HistoryPageItem; before?: HistoryFoldedRow };
|
|
8
|
-
type PreparedSelection = { candidates: Candidate[]; tail?: HistoryFoldedRow;
|
|
7
|
+
type Candidate = { event: HistoryEvent; session?: string; matchOffset?: number; preview?: HistoryPageItem; before?: HistoryFoldedRow; neighbors?: { events: HistoryEvent[]; index: number } };
|
|
8
|
+
type PreparedSelection = { candidates: Candidate[]; tail?: HistoryFoldedRow; multi?: boolean; discarded?: boolean; forward?: boolean };
|
|
9
9
|
const multiPages = new WeakSet<HistoryPage>();
|
|
10
10
|
export function isMultiPage(page: HistoryPage): boolean { return multiPages.has(page); }
|
|
11
11
|
export function markMultiPage(page: HistoryPage): HistoryPage {
|
|
@@ -13,46 +13,7 @@ export function markMultiPage(page: HistoryPage): HistoryPage {
|
|
|
13
13
|
return page;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
export type HistoryOrder = "newest" | "oldest";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* What one list call selects. `before_seq`/`after_seq` choose a seq range and `since`/`until` a time
|
|
21
|
-
* range; `from` chooses the end `limit` counts from; a `query` keeps only matching events, across
|
|
22
|
-
* every role, with no folded rows.
|
|
23
|
-
*/
|
|
24
|
-
export type HistorySelection = HistoryFilter & {
|
|
25
|
-
session?: string;
|
|
26
|
-
from?: HistoryOrder;
|
|
27
|
-
limit?: number;
|
|
28
|
-
query?: string | string[];
|
|
29
|
-
since?: string;
|
|
30
|
-
until?: string;
|
|
31
|
-
max_chars_per_item?: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/** ISO 8601 date or date-time; the offset is optional (group 1) and a missing one is read as UTC. */
|
|
35
|
-
const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
|
|
36
|
-
|
|
37
|
-
/** Epoch ms for one optional time param, or a refusal naming it. */
|
|
38
|
-
function timeBound(name: "since" | "until", value: string | undefined): Outcome<number | undefined> {
|
|
39
|
-
if (value === undefined) return success(undefined);
|
|
40
|
-
const match = ISO_8601.exec(value);
|
|
41
|
-
const at = match === null ? undefined : Date.parse(match[1] === undefined ? `${value}Z` : value);
|
|
42
|
-
return at === undefined || Number.isNaN(at) ? failure("invalid_time", `\`${name}\` isn't an ISO 8601 time: "${value}".`) : success(at);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Parse `since`/`until`; a malformed or inverted pair refuses here. */
|
|
46
|
-
function resolveTimeBounds(params: HistorySelection): Outcome<{ sinceMs?: number; untilMs?: number }> {
|
|
47
|
-
const since = timeBound("since", params.since);
|
|
48
|
-
if (!since.ok) return since;
|
|
49
|
-
const until = timeBound("until", params.until);
|
|
50
|
-
if (!until.ok) return until;
|
|
51
|
-
if (since.data !== undefined && until.data !== undefined && since.data >= until.data) {
|
|
52
|
-
return failure("invalid_time", "`since` must be earlier than `until`.");
|
|
53
|
-
}
|
|
54
|
-
return success({ ...(since.data === undefined ? {} : { sinceMs: since.data }), ...(until.data === undefined ? {} : { untilMs: until.data }) });
|
|
55
|
-
}
|
|
16
|
+
export type HistorySelection = HistoryFilter & { session?: string; limit?: number; query?: string[]; context?: number };
|
|
56
17
|
|
|
57
18
|
export const HistoryPageSchema = Type.Object({
|
|
58
19
|
notice: Type.Optional(Type.String()),
|
|
@@ -97,24 +58,32 @@ function foldedRun(events: HistoryEvent[], session?: string): HistoryFoldedRow |
|
|
|
97
58
|
return { ...(session === undefined ? {} : { session }), first_seq: events[0]!.seq, last_seq: events.at(-1)!.seq, count: events.length, tools };
|
|
98
59
|
}
|
|
99
60
|
|
|
100
|
-
|
|
61
|
+
// Tool/thinking-only envelopes are not dialogue, even with explicit roles.
|
|
62
|
+
const visible = (event: HistoryEvent) => (event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "";
|
|
63
|
+
|
|
64
|
+
function* queryHits(projection: HistoryProjection, params: HistorySelection, session?: string): Generator<Candidate> {
|
|
65
|
+
const { query, context } = params;
|
|
66
|
+
const events = filteredItems(projection, context ? {} : params).filter(visible);
|
|
67
|
+
for (const [index, event] of events.entries()) {
|
|
68
|
+
if (context && !matchesFilter(event, params)) continue;
|
|
69
|
+
const matchOffset = earliestMatchOffsetChars(eventDocument(event), query!);
|
|
70
|
+
if (matchOffset >= 0) yield { event, session, matchOffset, neighbors: context ? { events, index } : undefined };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
101
74
|
function prepareSelection(projection: HistoryProjection, params: HistorySelection): PreparedSelection {
|
|
102
|
-
const
|
|
75
|
+
const { query, roles, session } = params;
|
|
76
|
+
if (query) return { candidates: [...queryHits(projection, params, session)] };
|
|
103
77
|
const candidates: Candidate[] = [];
|
|
104
78
|
let run: HistoryEvent[] = [];
|
|
105
|
-
for (const event of filteredItems(projection, params)) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
79
|
+
for (const event of filteredItems(projection, params).filter(visible)) {
|
|
80
|
+
if (!roles && (event.role === "tool" || event.role === "context")) run.push(event);
|
|
81
|
+
else {
|
|
82
|
+
candidates.push({ event, session, before: foldedRun(run, session) });
|
|
83
|
+
run = [];
|
|
109
84
|
}
|
|
110
|
-
// Tool/thinking-only envelopes are not dialogue, even with explicit roles.
|
|
111
|
-
if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
|
|
112
|
-
const matchOffset = params.query === undefined ? undefined : earliestMatchOffsetChars(eventDocument(event), params.query as string[]);
|
|
113
|
-
if (matchOffset !== undefined && matchOffset < 0) continue;
|
|
114
|
-
candidates.push({ event, ...(params.session === undefined ? {} : { session: params.session }), matchOffset, before: foldedRun(run, params.session) });
|
|
115
|
-
run = [];
|
|
116
85
|
}
|
|
117
|
-
return { candidates,
|
|
86
|
+
return { candidates, tail: foldedRun(run, session) };
|
|
118
87
|
}
|
|
119
88
|
|
|
120
89
|
/** Assemble only the admitted interval. Edge folds belong only to a page reaching that edge. */
|
|
@@ -129,52 +98,56 @@ function pageData(prepared: PreparedSelection, start: number, end: number, maxCh
|
|
|
129
98
|
const page = {
|
|
130
99
|
items,
|
|
131
100
|
...(end === candidates.length && tail ? { folded_after: tail } : {}),
|
|
132
|
-
has_older: (start > 0 && start < end) || (!!prepared.discarded && prepared.
|
|
133
|
-
has_newer: (end < candidates.length && start < end) || (!!prepared.discarded && prepared.
|
|
101
|
+
has_older: (start > 0 && start < end) || (!!prepared.discarded && !prepared.forward),
|
|
102
|
+
has_newer: (end < candidates.length && start < end) || (!!prepared.discarded && !!prepared.forward),
|
|
134
103
|
};
|
|
135
104
|
return prepared.multi ? markMultiPage(page) : page;
|
|
136
105
|
}
|
|
137
106
|
|
|
138
|
-
/**
|
|
139
|
-
* Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
|
|
140
|
-
* Grow the page in selection order; shorten the first preview only when no full row fits.
|
|
141
|
-
*/
|
|
142
|
-
function resolveSelection(params: HistorySelection): Outcome<HistorySelection> {
|
|
143
|
-
const bounds = resolveTimeBounds(params);
|
|
144
|
-
if (!bounds.ok) return bounds;
|
|
145
|
-
try {
|
|
146
|
-
const queries = searchQueries(params.query);
|
|
147
|
-
return success({ ...params, ...bounds.data, query: queries.length ? queries : undefined });
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
150
|
-
throw error;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
107
|
export function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): HistoryPageResult {
|
|
155
|
-
|
|
156
|
-
if (!scoped.ok) return scoped;
|
|
157
|
-
return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Validate before corpus discovery or I/O: per-session seqs cannot bound a multi-session search. */
|
|
161
|
-
export function corpusSelection(params: HistorySelection): Outcome<HistorySelection> {
|
|
162
|
-
if (params.before_seq !== undefined || params.after_seq !== undefined) return failure("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
163
|
-
return resolveSelection(params);
|
|
108
|
+
return selectPrepared(prepareSelection(projection, params), params, fits, maxChars);
|
|
164
109
|
}
|
|
165
110
|
|
|
166
111
|
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
167
112
|
export function sessionRepresentative(projection: HistoryProjection, scoped: HistorySelection): HistoryEvent | undefined {
|
|
168
|
-
const events = filteredItems(projection, scoped).filter(
|
|
169
|
-
(event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "");
|
|
113
|
+
const events = filteredItems(projection, scoped).filter(visible);
|
|
170
114
|
if (scoped.roles) return events.at(-1);
|
|
171
115
|
return events.find((event) => event.role === "user")
|
|
172
116
|
?? events.filter((event) => event.role === "assistant").at(-1)
|
|
173
117
|
?? events.at(-1);
|
|
174
118
|
}
|
|
175
119
|
|
|
176
|
-
|
|
177
|
-
const
|
|
120
|
+
function eventTime(timestamp?: string | null): number {
|
|
121
|
+
const at = Date.parse(timestamp ?? "");
|
|
122
|
+
return Number.isNaN(at) ? -Infinity : at;
|
|
123
|
+
}
|
|
124
|
+
const compareCorpus = (a: Candidate, b: Candidate) => eventTime(a.event.createdAt) - eventTime(b.event.createdAt) || a.session!.localeCompare(b.session!) || a.event.seq - b.event.seq;
|
|
125
|
+
|
|
126
|
+
/** Fill the remaining budget nearest first. Shared session/seq keys merge overlapping windows. */
|
|
127
|
+
function addContext(page: HistoryPage, hits: Candidate[], radius: number, fits: (page: HistoryPage) => boolean, maxChars: number): void {
|
|
128
|
+
const key = (session: string | undefined, seq: number) => `${session ?? ""}\0${seq}`;
|
|
129
|
+
const seen = new Set(page.items.map(item => key(item.session, item.seq)));
|
|
130
|
+
const compare = (a: HistoryPageItem, b: HistoryPageItem) => (isMultiPage(page) ? eventTime(a.created_at) - eventTime(b.created_at) || a.session!.localeCompare(b.session!) : 0) || a.seq - b.seq;
|
|
131
|
+
for (let distance = 1; distance <= radius; distance++) {
|
|
132
|
+
let found = false;
|
|
133
|
+
for (const { neighbors, session } of hits) {
|
|
134
|
+
if (!neighbors) continue;
|
|
135
|
+
for (const index of [neighbors.index - distance, neighbors.index + distance]) {
|
|
136
|
+
const event = neighbors.events[index];
|
|
137
|
+
if (!event) continue;
|
|
138
|
+
found = true;
|
|
139
|
+
const id = key(session, event.seq);
|
|
140
|
+
if (seen.has(id)) continue;
|
|
141
|
+
const item: HistoryPageItem = { ...visibleItem(event, maxChars), ...(session === undefined ? {} : { session }), context: true };
|
|
142
|
+
const previous = page.items;
|
|
143
|
+
page.items = [...previous, item].sort(compare);
|
|
144
|
+
if (!fits(page)) { page.items = previous; return; }
|
|
145
|
+
seen.add(id);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!found) return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
178
151
|
|
|
179
152
|
/** Keep only the requested end of the globally ordered selection while sessions are released. */
|
|
180
153
|
export class CorpusCollector {
|
|
@@ -195,7 +168,7 @@ export class CorpusCollector {
|
|
|
195
168
|
}
|
|
196
169
|
if (this.candidates.length === this.limit) {
|
|
197
170
|
this.discarded = true;
|
|
198
|
-
if (this.scoped.
|
|
171
|
+
if (this.scoped.after) {
|
|
199
172
|
if (low === this.limit) return;
|
|
200
173
|
this.candidates.pop();
|
|
201
174
|
} else {
|
|
@@ -217,25 +190,19 @@ export class CorpusCollector {
|
|
|
217
190
|
/** Returns whether this session contributes an overview representative. */
|
|
218
191
|
add(session: string, projection: HistoryProjection): boolean {
|
|
219
192
|
if (this.scoped.query === undefined) return this.addRepresentative(session, sessionRepresentative(projection, this.scoped));
|
|
220
|
-
for (const
|
|
221
|
-
const document = eventDocument(event);
|
|
222
|
-
if ((event.role === "user" || event.role === "assistant") && document === "") continue;
|
|
223
|
-
const matchOffset = earliestMatchOffsetChars(document, this.scoped.query as string[]);
|
|
224
|
-
if (matchOffset >= 0) this.admit({ session, event, matchOffset });
|
|
225
|
-
}
|
|
193
|
+
for (const hit of queryHits(projection, this.scoped, session)) this.admit(hit);
|
|
226
194
|
return true;
|
|
227
195
|
}
|
|
228
196
|
|
|
229
197
|
page(fits: (page: HistoryPage) => boolean, maxChars: number, unvisited = false): HistoryPageResult {
|
|
230
|
-
return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited,
|
|
198
|
+
return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited, forward: !!this.scoped.after }, this.scoped, fits, maxChars);
|
|
231
199
|
}
|
|
232
200
|
}
|
|
233
201
|
|
|
234
202
|
function selectPrepared(prepared: PreparedSelection, scoped: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): HistoryPageResult {
|
|
235
203
|
const { candidates } = prepared;
|
|
236
204
|
// Grow a contiguous interval from the requested end; even a byte-limited newest page stays ascending.
|
|
237
|
-
const
|
|
238
|
-
const newest = from === "newest";
|
|
205
|
+
const newest = scoped.after === undefined;
|
|
239
206
|
let start = newest ? candidates.length : 0;
|
|
240
207
|
let end = start;
|
|
241
208
|
const limit = Math.max(1, scoped.limit ?? 20);
|
|
@@ -257,5 +224,6 @@ function selectPrepared(prepared: PreparedSelection, scoped: HistorySelection, f
|
|
|
257
224
|
}
|
|
258
225
|
const page = pageData(prepared, start, end, maxChars);
|
|
259
226
|
if (!fits(page)) return { ok: false, pageTooLarge: { count: page.items.length, multi: prepared.multi === true } };
|
|
227
|
+
if (scoped.context) addContext(page, candidates.slice(start, end), scoped.context, fits, maxChars);
|
|
260
228
|
return success(page);
|
|
261
229
|
}
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ export type { BootToolNames } from "./boot/text.js";
|
|
|
42
42
|
|
|
43
43
|
// Operations: the schemas and typed outcomes a host registers as its own tools, over a
|
|
44
44
|
// host-supplied notes tool context or decoded history projection/lazy corpus context.
|
|
45
|
-
export { notesList, notesRead,
|
|
45
|
+
export { notesList, notesRead, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
46
46
|
export { notesIdentityForCall, notesToolContext, type NotesToolContext } from "./tools/notes-context.js";
|
|
47
47
|
export { historyList, historyRead } from "./tools/history.js";
|
|
48
48
|
export { projectHistory } from "./history/history.js";
|
package/src/notes/address.ts
CHANGED
|
@@ -48,8 +48,8 @@ export function globToRegExp(pattern: string): RegExp {
|
|
|
48
48
|
|
|
49
49
|
/** Glob patterns are not virtual paths (`*` is legal), so they get their own guard. */
|
|
50
50
|
export function assertGlobPattern(value: unknown): string | undefined {
|
|
51
|
-
if (value === undefined
|
|
52
|
-
if (typeof value !== "string") throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
|
|
51
|
+
if (value === undefined) return undefined;
|
|
52
|
+
if (typeof value !== "string" || !value) throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a non-empty string; omit it for the current notebooks.`);
|
|
53
53
|
if (value.includes("\0") || value.includes("\\")) throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
|
|
54
54
|
return value;
|
|
55
55
|
}
|
package/src/notes/store.ts
CHANGED
|
@@ -29,10 +29,8 @@ export type NoteSearchRow = { address: string; scope: Scope; path: string; meta:
|
|
|
29
29
|
export type EditOperation = { oldText: string; newText: string };
|
|
30
30
|
export type WriteOptions = NotePolicyFields & { origin?: Origin };
|
|
31
31
|
export type EditOptions = NotePolicyFields & { origin?: Origin; crumpled?: boolean; replaceAll?: boolean; renameTo?: string };
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
export type NotesQuery = { glob?: string | null; crumpled?: boolean };
|
|
32
|
+
/** Omit glob for current notebooks. A pattern without `@` or `/` matches filenames at any depth. */
|
|
33
|
+
export type NotesQuery = { glob?: string; crumpled?: boolean };
|
|
36
34
|
/** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
|
|
37
35
|
export type NoteReadResult = { meta: NoteMeta; body: string; resolvedScope: Scope };
|
|
38
36
|
export type NoteWriteResult = { meta: NoteMeta; warnings: string[]; outcome: "created" | "overwrote" | "uncrumpled" };
|
|
@@ -480,8 +478,7 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
|
|
|
480
478
|
}
|
|
481
479
|
|
|
482
480
|
async function* scan(options: NotesQuery, status?: NoteQueryStatus): AsyncGenerator<Omit<NoteRow, "sizeBytes">> {
|
|
483
|
-
const
|
|
484
|
-
const pattern = glob === "@default" ? undefined : glob;
|
|
481
|
+
const pattern = assertGlobPattern(options.glob);
|
|
485
482
|
const normalized = normalizePattern(pattern, identity);
|
|
486
483
|
const matcher = normalized === undefined ? undefined : globToRegExp(normalized);
|
|
487
484
|
const namespaces = await namespacesForPattern(pattern, identity, status);
|