notesoup 0.59.2 → 0.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -17
- package/dist/plugins/claude/src/helper.js +1 -2
- 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/dream/git.js +12 -13
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- 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/project-namespace.js +39 -73
- package/dist/src/notes/store.d.ts +2 -4
- package/dist/src/notes/store.js +1 -2
- package/dist/src/sqlite-lock.d.ts +2 -0
- package/dist/src/sqlite-lock.js +17 -0
- package/dist/src/tools/dream.d.ts +2 -4
- package/dist/src/tools/dream.js +15 -16
- 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 +5 -6
- package/dist/test/claude-mod.test.js +6 -7
- 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/dream-tools.test.js +42 -14
- package/dist/test/dsh.test.js +2 -2
- package/dist/test/history-corpus.test.js +21 -36
- 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 +33 -42
- package/dist/test/notes.test.js +12 -14
- package/dist/test/project-namespace.test.js +36 -91
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +8 -9
- package/docs/notes-library.md +9 -3
- package/docs/skills.md +2 -6
- package/docs/tool-results.md +12 -6
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +212 -211
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +1 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +211 -210
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/dream/git.ts +11 -11
- package/src/history/history.ts +11 -16
- package/src/history/query.ts +67 -99
- package/src/index.ts +1 -1
- package/src/notes/address.ts +2 -2
- package/src/notes/project-namespace.ts +37 -59
- package/src/notes/store.ts +3 -6
- package/src/sqlite-lock.ts +14 -0
- package/src/tools/dream.ts +15 -14
- package/src/tools/history.ts +60 -29
- package/src/tools/notes.ts +39 -54
- package/src/tools/schema.ts +0 -1
- package/dist/src/dream/lock.d.ts +0 -14
- package/dist/src/dream/lock.js +0 -29
- package/src/dream/lock.ts +0 -28
|
@@ -7972,6 +7972,7 @@ var HistoryFoldedRowSchema = typebox_exports.Object({
|
|
|
7972
7972
|
var HistoryPageItemSchema = typebox_exports.Object({
|
|
7973
7973
|
session: typebox_exports.Optional(typebox_exports.String()),
|
|
7974
7974
|
folded_before: typebox_exports.Optional(HistoryFoldedRowSchema),
|
|
7975
|
+
context: typebox_exports.Optional(typebox_exports.Literal(true, { description: "A neighbor of a search hit, not a hit in this page." })),
|
|
7975
7976
|
seq: typebox_exports.Integer({ minimum: 1 }),
|
|
7976
7977
|
role: HistoryRoleSchema,
|
|
7977
7978
|
created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
|
|
@@ -8001,20 +8002,17 @@ function visibleItem(event, maxChars, matchOffset) {
|
|
|
8001
8002
|
function allItems(projection) {
|
|
8002
8003
|
return projection.windows.flatMap((current) => current.items);
|
|
8003
8004
|
}
|
|
8004
|
-
function
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
const at = Date.parse(event.createdAt);
|
|
8010
|
-
return !Number.isNaN(at) && (params.sinceMs === void 0 || at >= params.sinceMs) && (params.untilMs === void 0 || at < params.untilMs);
|
|
8005
|
+
function compareBound(event, bound) {
|
|
8006
|
+
return "seq" in bound ? event.seq - bound.seq : Date.parse(event.createdAt ?? "") - bound.at;
|
|
8007
|
+
}
|
|
8008
|
+
function matchesFilter(event, { after, before, roles }) {
|
|
8009
|
+
return (!after || compareBound(event, after) > 0) && (!before || compareBound(event, before) < 0) && (!roles || roles.includes(event.role));
|
|
8011
8010
|
}
|
|
8012
8011
|
function filteredItems(projection, params) {
|
|
8013
|
-
return allItems(projection).filter((
|
|
8012
|
+
return allItems(projection).filter((event) => matchesFilter(event, params)).sort((a, b) => a.seq - b.seq);
|
|
8014
8013
|
}
|
|
8015
8014
|
|
|
8016
8015
|
// src/tools/schema.ts
|
|
8017
|
-
var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
|
|
8018
8016
|
var historyRoles = () => typebox_exports.Optional(typebox_exports.Array(HistoryRoleSchema, { minItems: 1, description: "Only these voices: user, assistant, tool, context. Without roles or query, tool and context runs fold into one line." }));
|
|
8019
8017
|
function paramProblem(schema, params) {
|
|
8020
8018
|
const first = Errors2(schema, params).find((error) => error.keyword !== "boolean");
|
|
@@ -8122,8 +8120,8 @@ function globToRegExp(pattern) {
|
|
|
8122
8120
|
return new RegExp(`${source}$`);
|
|
8123
8121
|
}
|
|
8124
8122
|
function assertGlobPattern(value) {
|
|
8125
|
-
if (value === void 0
|
|
8126
|
-
if (typeof value !== "string") throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
|
|
8123
|
+
if (value === void 0) return void 0;
|
|
8124
|
+
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.`);
|
|
8127
8125
|
if (value.includes("\0") || value.includes("\\")) throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
|
|
8128
8126
|
return value;
|
|
8129
8127
|
}
|
|
@@ -8397,8 +8395,25 @@ var MAX_NOTE_PATH_BYTES = 512;
|
|
|
8397
8395
|
|
|
8398
8396
|
// src/notes/project-namespace.ts
|
|
8399
8397
|
import { randomUUID } from "node:crypto";
|
|
8400
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync,
|
|
8398
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8401
8399
|
import { basename, dirname, join as join2, resolve as resolve2, sep } from "node:path";
|
|
8400
|
+
|
|
8401
|
+
// src/sqlite-lock.ts
|
|
8402
|
+
function trySqliteLock(path, waitMs) {
|
|
8403
|
+
const sqlite = process.getBuiltinModule?.("node:sqlite");
|
|
8404
|
+
if (!sqlite?.DatabaseSync) throw new Error("Notesoup locks require built-in node:sqlite (Node 22.13+).");
|
|
8405
|
+
const db = new sqlite.DatabaseSync(path);
|
|
8406
|
+
try {
|
|
8407
|
+
db.exec(`PRAGMA busy_timeout = ${waitMs}; BEGIN IMMEDIATE`);
|
|
8408
|
+
} catch (error) {
|
|
8409
|
+
db.close();
|
|
8410
|
+
if (error instanceof Error && "errcode" in error && error.errcode === 5) return void 0;
|
|
8411
|
+
throw error;
|
|
8412
|
+
}
|
|
8413
|
+
return () => db.close();
|
|
8414
|
+
}
|
|
8415
|
+
|
|
8416
|
+
// src/notes/project-namespace.ts
|
|
8402
8417
|
function errno(error) {
|
|
8403
8418
|
return typeof error === "object" && error !== null ? error.code : void 0;
|
|
8404
8419
|
}
|
|
@@ -8511,67 +8526,42 @@ function updateMarker(namespace, marker) {
|
|
|
8511
8526
|
}
|
|
8512
8527
|
return { ...namespace, ...marker };
|
|
8513
8528
|
}
|
|
8514
|
-
|
|
8515
|
-
|
|
8516
|
-
|
|
8517
|
-
for (; ; ) {
|
|
8518
|
-
const result = attempt();
|
|
8519
|
-
if (result !== void 0) return result;
|
|
8520
|
-
const remaining = deadline - performance.now();
|
|
8521
|
-
if (remaining <= 0) throw new Error(`Timed out waiting for project claim at ${path}`);
|
|
8522
|
-
Atomics.wait(claimSleep, 0, 0, Math.min(10, remaining));
|
|
8523
|
-
}
|
|
8529
|
+
function checkoutMarker(cwd) {
|
|
8530
|
+
const path = canonicalRoot(cwd);
|
|
8531
|
+
return { id: originRemote(path) ?? path, path };
|
|
8524
8532
|
}
|
|
8525
8533
|
function resolveProjectNamespace(cwd, home) {
|
|
8526
|
-
|
|
8527
|
-
const
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
throw error;
|
|
8535
|
-
}
|
|
8536
|
-
});
|
|
8534
|
+
const expected = checkoutMarker(cwd);
|
|
8535
|
+
const current = projectNamespaces(home).find((candidate) => candidate.id === expected.id);
|
|
8536
|
+
if (current?.path === expected.path) return current;
|
|
8537
|
+
const root = projectRoot(home);
|
|
8538
|
+
mkdirSync(root, { recursive: true });
|
|
8539
|
+
const lockPath = join2(home, ".project-claim.sqlite");
|
|
8540
|
+
const release = trySqliteLock(lockPath, 5e3);
|
|
8541
|
+
if (!release) throw new Error(`Timed out waiting for project claim at ${lockPath}`);
|
|
8537
8542
|
try {
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
return found;
|
|
8558
|
-
}
|
|
8559
|
-
const base = slugify(basename(root));
|
|
8560
|
-
const taken = new Set(readdirSync(markerRoot));
|
|
8561
|
-
for (let suffix = 0; ; suffix++) {
|
|
8562
|
-
const name = suffix === 0 ? base : `${base}-${suffix}`;
|
|
8563
|
-
if (taken.has(name)) continue;
|
|
8564
|
-
const dir = join2(markerRoot, name);
|
|
8565
|
-
try {
|
|
8566
|
-
mkdirSync(dir);
|
|
8567
|
-
} catch (error) {
|
|
8568
|
-
if (errno(error) !== "EEXIST") throw error;
|
|
8569
|
-
let winner = awaitClaim(join2(dir, ".project"), () => readMarker(dir));
|
|
8570
|
-
if (winner.id !== id2 && !(remote && winner.id === root)) continue;
|
|
8571
|
-
if (winner.id !== id2 || winner.path !== root) winner = updateMarker(winner, { id: id2, path: root });
|
|
8572
|
-
return winner;
|
|
8543
|
+
const marker = checkoutMarker(cwd);
|
|
8544
|
+
const { id: id2, path } = marker;
|
|
8545
|
+
const namespaces = projectNamespaces(home);
|
|
8546
|
+
const found = namespaces.find((candidate) => candidate.id === id2) ?? namespaces.find((candidate) => candidate.id === path);
|
|
8547
|
+
if (found) return found.id === id2 && found.path === path ? found : updateMarker(found, marker);
|
|
8548
|
+
const base = slugify(basename(path));
|
|
8549
|
+
for (let suffix = 0; ; suffix++) {
|
|
8550
|
+
const name = suffix === 0 ? base : `${base}-${suffix}`;
|
|
8551
|
+
const dir = join2(root, name);
|
|
8552
|
+
if (lstatSync(dir, { throwIfNoEntry: false })) continue;
|
|
8553
|
+
const staged = mkdtempSync(join2(home, ".project-pending-"));
|
|
8554
|
+
try {
|
|
8555
|
+
writeFileSync(join2(staged, ".project"), JSON.stringify(marker));
|
|
8556
|
+
renameSync(staged, dir);
|
|
8557
|
+
} catch (error) {
|
|
8558
|
+
rmSync(staged, { recursive: true, force: true });
|
|
8559
|
+
throw error;
|
|
8560
|
+
}
|
|
8561
|
+
return { name, dir, ...marker };
|
|
8573
8562
|
}
|
|
8574
|
-
|
|
8563
|
+
} finally {
|
|
8564
|
+
release();
|
|
8575
8565
|
}
|
|
8576
8566
|
}
|
|
8577
8567
|
function gitRoot(cwd) {
|
|
@@ -8977,8 +8967,7 @@ function createNotesStore(input) {
|
|
|
8977
8967
|
}));
|
|
8978
8968
|
}
|
|
8979
8969
|
async function* scan(options, status) {
|
|
8980
|
-
const
|
|
8981
|
-
const pattern = glob === "@default" ? void 0 : glob;
|
|
8970
|
+
const pattern = assertGlobPattern(options.glob);
|
|
8982
8971
|
const normalized = normalizePattern(pattern, identity2);
|
|
8983
8972
|
const matcher = normalized === void 0 ? void 0 : globToRegExp(normalized);
|
|
8984
8973
|
const namespaces = await namespacesForPattern(pattern, identity2, status);
|
|
@@ -9188,7 +9177,7 @@ function withWarnings(text, data) {
|
|
|
9188
9177
|
var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
|
|
9189
9178
|
var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "Only the crumpled balls." }));
|
|
9190
9179
|
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many pages at most." }));
|
|
9191
|
-
var GLOB_PARAMETER =
|
|
9180
|
+
var GLOB_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf \xB7 `MAP.md` that page in every notebook \xB7 `**` everything \xB7 `@sessions/*/**` every session." }));
|
|
9192
9181
|
var CWD_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
9193
9182
|
var ADDRESS_PARAMETER = typebox_exports.String({ description: "Which drawer the page sits in. `plan.md` \u2014 this session's desk, cleared when it ends. `@project/` this project's shelf \xB7 `@human/` your human's file \xB7 `@self/` your own notebook \xB7 `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` \u2014 someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
|
|
9194
9183
|
function failureOf(error) {
|
|
@@ -9278,11 +9267,6 @@ var MatchSchema = typebox_exports.Object({
|
|
|
9278
9267
|
text: typebox_exports.String(),
|
|
9279
9268
|
offset_chars: typebox_exports.Integer()
|
|
9280
9269
|
}, { additionalProperties: false });
|
|
9281
|
-
var SearchedFileSchema = typebox_exports.Object({
|
|
9282
|
-
...ListedFileSchema.properties,
|
|
9283
|
-
matches: typebox_exports.Array(MatchSchema),
|
|
9284
|
-
more_matches: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1 }))
|
|
9285
|
-
}, { additionalProperties: false });
|
|
9286
9270
|
var SnapshotSchema = {
|
|
9287
9271
|
more: typebox_exports.Integer({ description: "How many more were left out." }),
|
|
9288
9272
|
namespaces_unavailable: typebox_exports.Array(typebox_exports.String(), { description: "Unreadable notebooks or notes." })
|
|
@@ -9307,11 +9291,11 @@ var NotesReadDataSchema = typebox_exports.Object({
|
|
|
9307
9291
|
...TextWindowSchema.properties
|
|
9308
9292
|
}, { additionalProperties: false });
|
|
9309
9293
|
var NotesListDataSchema = typebox_exports.Object({
|
|
9310
|
-
files: typebox_exports.Array(
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9294
|
+
files: typebox_exports.Array(typebox_exports.Object({
|
|
9295
|
+
...ListedFileSchema.properties,
|
|
9296
|
+
matches: typebox_exports.Optional(typebox_exports.Array(MatchSchema)),
|
|
9297
|
+
more_matches: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1 }))
|
|
9298
|
+
}, { additionalProperties: false })),
|
|
9315
9299
|
...SnapshotSchema
|
|
9316
9300
|
}, { additionalProperties: false });
|
|
9317
9301
|
function snapshot(rows, limit, status, renderData, shrink) {
|
|
@@ -9427,41 +9411,24 @@ var notesRead = {
|
|
|
9427
9411
|
},
|
|
9428
9412
|
render: (result) => renderOutcome(result, renderReadData)
|
|
9429
9413
|
};
|
|
9430
|
-
var notesListParameters = typebox_exports.Object({
|
|
9414
|
+
var notesListParameters = typebox_exports.Object({
|
|
9415
|
+
glob: GLOB_PARAMETER,
|
|
9416
|
+
query: typebox_exports.Optional(searchQuery()),
|
|
9417
|
+
max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many hit lines per note at most; requires a query." })),
|
|
9418
|
+
crumpled: CRUMPLED_LIST_PARAMETER,
|
|
9419
|
+
limit: FILE_LIMIT_PARAMETER,
|
|
9420
|
+
cwd: CWD_PARAMETER
|
|
9421
|
+
}, { additionalProperties: false });
|
|
9431
9422
|
function renderListData(data) {
|
|
9432
9423
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9433
9424
|
for (const file of data.files) {
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
return lines.join("\n");
|
|
9440
|
-
}
|
|
9441
|
-
var notesList = {
|
|
9442
|
-
name: "notes_list",
|
|
9443
|
-
label: "Notes list",
|
|
9444
|
-
description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile \u2014 narrow `glob`.",
|
|
9445
|
-
parameters: notesListParameters,
|
|
9446
|
-
outputSchema: resultSchema(NotesListDataSchema),
|
|
9447
|
-
async execute(params, context2) {
|
|
9448
|
-
try {
|
|
9449
|
-
const identity2 = notesIdentityForCall(context2, params.cwd);
|
|
9450
|
-
const { rows, status } = await createNotesStore(identity2).listWithStatus({ glob: params.glob ?? void 0, crumpled: params.crumpled });
|
|
9451
|
-
return snapshot(rows.map((row) => listedFile(row, identity2)), params.limit, status, renderListData);
|
|
9452
|
-
} catch (error) {
|
|
9453
|
-
return failureOf(error);
|
|
9454
|
-
}
|
|
9455
|
-
},
|
|
9456
|
-
render: (result) => renderOutcome(result, renderListData)
|
|
9457
|
-
};
|
|
9458
|
-
var notesSearchParameters = typebox_exports.Object({ query: typebox_exports.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many hit lines per page at most." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
9459
|
-
function renderSearchData(data) {
|
|
9460
|
-
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9461
|
-
for (const file of data.files) {
|
|
9462
|
-
lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
9425
|
+
const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
|
|
9426
|
+
if (file.last_accessed !== void 0) fields.push(`accessed ${file.last_accessed}`);
|
|
9427
|
+
if (file.crumpled_at !== void 0) fields.push(`crumpled ${file.crumpled_at}`);
|
|
9428
|
+
if (file.matches) fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
9429
|
+
lines.push(fields.join(" | "));
|
|
9463
9430
|
lines.push(...file.warnings.map((warning) => ` ${warning}`));
|
|
9464
|
-
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
9431
|
+
for (const match of file.matches ?? []) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
9465
9432
|
}
|
|
9466
9433
|
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
9467
9434
|
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
@@ -9485,26 +9452,34 @@ function fitSearchFile(file, fits) {
|
|
|
9485
9452
|
const withText = (text) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
|
|
9486
9453
|
return withText(prefixFit(first.text, (text) => fits(withText(text))));
|
|
9487
9454
|
}
|
|
9488
|
-
var
|
|
9489
|
-
name: "
|
|
9490
|
-
label: "Notes
|
|
9491
|
-
description: "
|
|
9492
|
-
parameters:
|
|
9493
|
-
outputSchema: resultSchema(
|
|
9455
|
+
var notesList = {
|
|
9456
|
+
name: "notes_list",
|
|
9457
|
+
label: "Notes list",
|
|
9458
|
+
description: "List or search notes, newest pages on top. A query matches literal text (ignoring case) and returns hit lines and read offsets. One pass; `more` counts pages left on the pile \u2014 narrow `glob`.",
|
|
9459
|
+
parameters: notesListParameters,
|
|
9460
|
+
outputSchema: resultSchema(NotesListDataSchema),
|
|
9494
9461
|
async execute(params, context2) {
|
|
9495
9462
|
try {
|
|
9463
|
+
const queries = searchQueries(params.query);
|
|
9464
|
+
const { glob, crumpled, limit } = params;
|
|
9465
|
+
if (!queries.length && params.max_matches_per_file !== void 0) return failure("invalid_params", "`max_matches_per_file` requires a non-empty `query`.");
|
|
9496
9466
|
const identity2 = notesIdentityForCall(context2, params.cwd);
|
|
9497
|
-
const
|
|
9467
|
+
const store = createNotesStore(identity2);
|
|
9468
|
+
if (!queries.length) {
|
|
9469
|
+
const { rows: rows2, status: status2 } = await store.listWithStatus({ glob, crumpled });
|
|
9470
|
+
return snapshot(rows2.map((row) => listedFile(row, identity2)), limit, status2, renderListData);
|
|
9471
|
+
}
|
|
9472
|
+
const { rows, status } = await store.searchWithStatus(queries, { glob, crumpled });
|
|
9498
9473
|
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => keepMatches({
|
|
9499
9474
|
...listedFile(row, identity2),
|
|
9500
9475
|
matches: row.matches.map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
|
|
9501
9476
|
}, params.max_matches_per_file));
|
|
9502
|
-
return snapshot(files,
|
|
9477
|
+
return snapshot(files, limit, status, renderListData, fitSearchFile);
|
|
9503
9478
|
} catch (error) {
|
|
9504
9479
|
return failureOf(error);
|
|
9505
9480
|
}
|
|
9506
9481
|
},
|
|
9507
|
-
render: (result) => renderOutcome(result,
|
|
9482
|
+
render: (result) => renderOutcome(result, renderListData)
|
|
9508
9483
|
};
|
|
9509
9484
|
|
|
9510
9485
|
// src/history/query.ts
|
|
@@ -9516,23 +9491,6 @@ function markMultiPage(page) {
|
|
|
9516
9491
|
multiPages.add(page);
|
|
9517
9492
|
return page;
|
|
9518
9493
|
}
|
|
9519
|
-
var ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
|
|
9520
|
-
function timeBound(name, value) {
|
|
9521
|
-
if (value === void 0) return success(void 0);
|
|
9522
|
-
const match = ISO_8601.exec(value);
|
|
9523
|
-
const at = match === null ? void 0 : Date.parse(match[1] === void 0 ? `${value}Z` : value);
|
|
9524
|
-
return at === void 0 || Number.isNaN(at) ? failure("invalid_time", `\`${name}\` isn't an ISO 8601 time: "${value}".`) : success(at);
|
|
9525
|
-
}
|
|
9526
|
-
function resolveTimeBounds(params) {
|
|
9527
|
-
const since = timeBound("since", params.since);
|
|
9528
|
-
if (!since.ok) return since;
|
|
9529
|
-
const until = timeBound("until", params.until);
|
|
9530
|
-
if (!until.ok) return until;
|
|
9531
|
-
if (since.data !== void 0 && until.data !== void 0 && since.data >= until.data) {
|
|
9532
|
-
return failure("invalid_time", "`since` must be earlier than `until`.");
|
|
9533
|
-
}
|
|
9534
|
-
return success({ ...since.data === void 0 ? {} : { sinceMs: since.data }, ...until.data === void 0 ? {} : { untilMs: until.data } });
|
|
9535
|
-
}
|
|
9536
9494
|
var HistoryPageSchema = typebox_exports.Object({
|
|
9537
9495
|
notice: typebox_exports.Optional(typebox_exports.String()),
|
|
9538
9496
|
items: typebox_exports.Array(HistoryPageItemSchema),
|
|
@@ -9565,22 +9523,29 @@ function foldedRun(events, session) {
|
|
|
9565
9523
|
const tools = Object.fromEntries(entries);
|
|
9566
9524
|
return { ...session === void 0 ? {} : { session }, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools };
|
|
9567
9525
|
}
|
|
9526
|
+
var visible = (event) => event.role !== "user" && event.role !== "assistant" || eventDocument(event) !== "";
|
|
9527
|
+
function* queryHits(projection, params, session) {
|
|
9528
|
+
const { query, context: context2 } = params;
|
|
9529
|
+
const events = filteredItems(projection, context2 ? {} : params).filter(visible);
|
|
9530
|
+
for (const [index, event] of events.entries()) {
|
|
9531
|
+
if (context2 && !matchesFilter(event, params)) continue;
|
|
9532
|
+
const matchOffset = earliestMatchOffsetChars(eventDocument(event), query);
|
|
9533
|
+
if (matchOffset >= 0) yield { event, session, matchOffset, neighbors: context2 ? { events, index } : void 0 };
|
|
9534
|
+
}
|
|
9535
|
+
}
|
|
9568
9536
|
function prepareSelection(projection, params) {
|
|
9569
|
-
const
|
|
9537
|
+
const { query, roles, session } = params;
|
|
9538
|
+
if (query) return { candidates: [...queryHits(projection, params, session)] };
|
|
9570
9539
|
const candidates = [];
|
|
9571
9540
|
let run = [];
|
|
9572
|
-
for (const event of filteredItems(projection, params)) {
|
|
9573
|
-
if (
|
|
9574
|
-
|
|
9575
|
-
|
|
9541
|
+
for (const event of filteredItems(projection, params).filter(visible)) {
|
|
9542
|
+
if (!roles && (event.role === "tool" || event.role === "context")) run.push(event);
|
|
9543
|
+
else {
|
|
9544
|
+
candidates.push({ event, session, before: foldedRun(run, session) });
|
|
9545
|
+
run = [];
|
|
9576
9546
|
}
|
|
9577
|
-
if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
|
|
9578
|
-
const matchOffset = params.query === void 0 ? void 0 : earliestMatchOffsetChars(eventDocument(event), params.query);
|
|
9579
|
-
if (matchOffset !== void 0 && matchOffset < 0) continue;
|
|
9580
|
-
candidates.push({ event, ...params.session === void 0 ? {} : { session: params.session }, matchOffset, before: foldedRun(run, params.session) });
|
|
9581
|
-
run = [];
|
|
9582
9547
|
}
|
|
9583
|
-
return { candidates,
|
|
9548
|
+
return { candidates, tail: foldedRun(run, session) };
|
|
9584
9549
|
}
|
|
9585
9550
|
function pageData(prepared, start, end, maxChars, preview) {
|
|
9586
9551
|
const { candidates, tail } = prepared;
|
|
@@ -9593,38 +9558,51 @@ function pageData(prepared, start, end, maxChars, preview) {
|
|
|
9593
9558
|
const page = {
|
|
9594
9559
|
items,
|
|
9595
9560
|
...end === candidates.length && tail ? { folded_after: tail } : {},
|
|
9596
|
-
has_older: start > 0 && start < end || !!prepared.discarded && prepared.
|
|
9597
|
-
has_newer: end < candidates.length && start < end || !!prepared.discarded && prepared.
|
|
9561
|
+
has_older: start > 0 && start < end || !!prepared.discarded && !prepared.forward,
|
|
9562
|
+
has_newer: end < candidates.length && start < end || !!prepared.discarded && !!prepared.forward
|
|
9598
9563
|
};
|
|
9599
9564
|
return prepared.multi ? markMultiPage(page) : page;
|
|
9600
9565
|
}
|
|
9601
|
-
function resolveSelection(params) {
|
|
9602
|
-
const bounds = resolveTimeBounds(params);
|
|
9603
|
-
if (!bounds.ok) return bounds;
|
|
9604
|
-
try {
|
|
9605
|
-
const queries = searchQueries(params.query);
|
|
9606
|
-
return success({ ...params, ...bounds.data, query: queries.length ? queries : void 0 });
|
|
9607
|
-
} catch (error) {
|
|
9608
|
-
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
9609
|
-
throw error;
|
|
9610
|
-
}
|
|
9611
|
-
}
|
|
9612
9566
|
function selectPage(projection, params, fits, maxChars) {
|
|
9613
|
-
|
|
9614
|
-
if (!scoped.ok) return scoped;
|
|
9615
|
-
return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
|
|
9616
|
-
}
|
|
9617
|
-
function corpusSelection(params) {
|
|
9618
|
-
if (params.before_seq !== void 0 || params.after_seq !== void 0) return failure("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
9619
|
-
return resolveSelection(params);
|
|
9567
|
+
return selectPrepared(prepareSelection(projection, params), params, fits, maxChars);
|
|
9620
9568
|
}
|
|
9621
9569
|
function sessionRepresentative(projection, scoped) {
|
|
9622
|
-
const events = filteredItems(projection, scoped).filter(
|
|
9570
|
+
const events = filteredItems(projection, scoped).filter(visible);
|
|
9623
9571
|
if (scoped.roles) return events.at(-1);
|
|
9624
9572
|
return events.find((event) => event.role === "user") ?? events.filter((event) => event.role === "assistant").at(-1) ?? events.at(-1);
|
|
9625
9573
|
}
|
|
9626
|
-
|
|
9627
|
-
|
|
9574
|
+
function eventTime(timestamp) {
|
|
9575
|
+
const at = Date.parse(timestamp ?? "");
|
|
9576
|
+
return Number.isNaN(at) ? -Infinity : at;
|
|
9577
|
+
}
|
|
9578
|
+
var compareCorpus = (a, b) => eventTime(a.event.createdAt) - eventTime(b.event.createdAt) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq;
|
|
9579
|
+
function addContext(page, hits, radius, fits, maxChars) {
|
|
9580
|
+
const key = (session, seq) => `${session ?? ""}\0${seq}`;
|
|
9581
|
+
const seen = new Set(page.items.map((item) => key(item.session, item.seq)));
|
|
9582
|
+
const compare = (a, b) => (isMultiPage(page) ? eventTime(a.created_at) - eventTime(b.created_at) || a.session.localeCompare(b.session) : 0) || a.seq - b.seq;
|
|
9583
|
+
for (let distance = 1; distance <= radius; distance++) {
|
|
9584
|
+
let found = false;
|
|
9585
|
+
for (const { neighbors, session } of hits) {
|
|
9586
|
+
if (!neighbors) continue;
|
|
9587
|
+
for (const index of [neighbors.index - distance, neighbors.index + distance]) {
|
|
9588
|
+
const event = neighbors.events[index];
|
|
9589
|
+
if (!event) continue;
|
|
9590
|
+
found = true;
|
|
9591
|
+
const id2 = key(session, event.seq);
|
|
9592
|
+
if (seen.has(id2)) continue;
|
|
9593
|
+
const item = { ...visibleItem(event, maxChars), ...session === void 0 ? {} : { session }, context: true };
|
|
9594
|
+
const previous = page.items;
|
|
9595
|
+
page.items = [...previous, item].sort(compare);
|
|
9596
|
+
if (!fits(page)) {
|
|
9597
|
+
page.items = previous;
|
|
9598
|
+
return;
|
|
9599
|
+
}
|
|
9600
|
+
seen.add(id2);
|
|
9601
|
+
}
|
|
9602
|
+
}
|
|
9603
|
+
if (!found) return;
|
|
9604
|
+
}
|
|
9605
|
+
}
|
|
9628
9606
|
var CorpusCollector = class {
|
|
9629
9607
|
constructor(scoped) {
|
|
9630
9608
|
this.scoped = scoped;
|
|
@@ -9643,7 +9621,7 @@ var CorpusCollector = class {
|
|
|
9643
9621
|
}
|
|
9644
9622
|
if (this.candidates.length === this.limit) {
|
|
9645
9623
|
this.discarded = true;
|
|
9646
|
-
if (this.scoped.
|
|
9624
|
+
if (this.scoped.after) {
|
|
9647
9625
|
if (low === this.limit) return;
|
|
9648
9626
|
this.candidates.pop();
|
|
9649
9627
|
} else {
|
|
@@ -9663,22 +9641,16 @@ var CorpusCollector = class {
|
|
|
9663
9641
|
/** Returns whether this session contributes an overview representative. */
|
|
9664
9642
|
add(session, projection) {
|
|
9665
9643
|
if (this.scoped.query === void 0) return this.addRepresentative(session, sessionRepresentative(projection, this.scoped));
|
|
9666
|
-
for (const
|
|
9667
|
-
const document = eventDocument(event);
|
|
9668
|
-
if ((event.role === "user" || event.role === "assistant") && document === "") continue;
|
|
9669
|
-
const matchOffset = earliestMatchOffsetChars(document, this.scoped.query);
|
|
9670
|
-
if (matchOffset >= 0) this.admit({ session, event, matchOffset });
|
|
9671
|
-
}
|
|
9644
|
+
for (const hit of queryHits(projection, this.scoped, session)) this.admit(hit);
|
|
9672
9645
|
return true;
|
|
9673
9646
|
}
|
|
9674
9647
|
page(fits, maxChars, unvisited = false) {
|
|
9675
|
-
return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited,
|
|
9648
|
+
return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited, forward: !!this.scoped.after }, this.scoped, fits, maxChars);
|
|
9676
9649
|
}
|
|
9677
9650
|
};
|
|
9678
9651
|
function selectPrepared(prepared, scoped, fits, maxChars) {
|
|
9679
9652
|
const { candidates } = prepared;
|
|
9680
|
-
const
|
|
9681
|
-
const newest = from === "newest";
|
|
9653
|
+
const newest = scoped.after === void 0;
|
|
9682
9654
|
let start = newest ? candidates.length : 0;
|
|
9683
9655
|
let end = start;
|
|
9684
9656
|
const limit = Math.max(1, scoped.limit ?? 20);
|
|
@@ -9700,6 +9672,7 @@ function selectPrepared(prepared, scoped, fits, maxChars) {
|
|
|
9700
9672
|
}
|
|
9701
9673
|
const page = pageData(prepared, start, end, maxChars);
|
|
9702
9674
|
if (!fits(page)) return { ok: false, pageTooLarge: { count: page.items.length, multi: prepared.multi === true } };
|
|
9675
|
+
if (scoped.context) addContext(page, candidates.slice(start, end), scoped.context, fits, maxChars);
|
|
9703
9676
|
return success(page);
|
|
9704
9677
|
}
|
|
9705
9678
|
|
|
@@ -9790,7 +9763,7 @@ function toolHeader(item) {
|
|
|
9790
9763
|
}
|
|
9791
9764
|
function renderPageItem(item) {
|
|
9792
9765
|
const tool = toolHeader(item);
|
|
9793
|
-
const lines =
|
|
9766
|
+
const lines = [header(item) + (item.context ? " | search context" : ""), ...tool ? [tool] : []];
|
|
9794
9767
|
if (item.truncated) lines.push(`[truncated; from offset ${item.offset_chars ?? 0}]`);
|
|
9795
9768
|
lines.push(item.content);
|
|
9796
9769
|
return lines.join("\n");
|
|
@@ -9799,7 +9772,7 @@ function renderFoldedRow(row) {
|
|
|
9799
9772
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
9800
9773
|
const identity2 = row.session === void 0 ? {} : { session: row.session };
|
|
9801
9774
|
const expand = `
|
|
9802
|
-
\u2192 expand: ${JSON.stringify({ ...identity2,
|
|
9775
|
+
\u2192 expand: ${JSON.stringify({ ...identity2, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] })}`;
|
|
9803
9776
|
return `${row.session === void 0 ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
9804
9777
|
}
|
|
9805
9778
|
function renderPage(page) {
|
|
@@ -9809,13 +9782,14 @@ function renderPage(page) {
|
|
|
9809
9782
|
const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
|
|
9810
9783
|
return (page.notice ?? "") + body + (directions ? `
|
|
9811
9784
|
|
|
9812
|
-
\u2192 more ${directions} results: narrow with
|
|
9785
|
+
\u2192 more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
|
|
9813
9786
|
}
|
|
9814
|
-
const
|
|
9815
|
-
const
|
|
9787
|
+
const hits = page.items.filter((item) => !item.context);
|
|
9788
|
+
const first = hits[0];
|
|
9789
|
+
const last = hits.at(-1);
|
|
9816
9790
|
const cursors = [
|
|
9817
|
-
page.has_older ? `\u2192 older: ${JSON.stringify({
|
|
9818
|
-
page.has_newer ? `\u2192 newer: ${JSON.stringify({
|
|
9791
|
+
page.has_older ? `\u2192 older: ${JSON.stringify({ session: first.session, before: first.seq })}` : "",
|
|
9792
|
+
page.has_newer ? `\u2192 newer: ${JSON.stringify({ session: last.session, after: last.seq })}` : ""
|
|
9819
9793
|
].filter((line) => line !== "");
|
|
9820
9794
|
return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}
|
|
9821
9795
|
|
|
@@ -9823,28 +9797,54 @@ ${cursors.join(" | ")}`);
|
|
|
9823
9797
|
}
|
|
9824
9798
|
function renderRead(data) {
|
|
9825
9799
|
const tool = toolHeader(data);
|
|
9826
|
-
const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...data.session === void 0 ? {} : { session: data.session },
|
|
9800
|
+
const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...data.session === void 0 ? {} : { session: data.session }, after: Math.max(0, data.seq - 10), before: data.seq + 10 })})`;
|
|
9827
9801
|
return (data.notice ?? "") + [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
9828
9802
|
}
|
|
9829
9803
|
var plainText = (text) => text;
|
|
9830
9804
|
function pageOutcome(result) {
|
|
9831
9805
|
if (!("pageTooLarge" in result)) return result;
|
|
9832
9806
|
const { count, multi } = result.pageTooLarge;
|
|
9833
|
-
const narrow = multi ? "narrow the session pattern, query, roles or `
|
|
9807
|
+
const narrow = multi ? "narrow the session pattern, query, roles or time bounds (`after`/`before`), or read one session/seq with `history_read`" : "narrow with `after`/`before`, pass `roles` to skip folding, or `history_read` one seq";
|
|
9834
9808
|
return failure("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
9835
9809
|
}
|
|
9810
|
+
var boundParameter = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Number()], { description: `${description} Use a seq (number or digits) or ISO 8601 time (UTC without offset); wildcards take only times.` }));
|
|
9836
9811
|
var historyListParameters = typebox_exports.Object({
|
|
9837
9812
|
session: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
|
|
9838
|
-
query: typebox_exports.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
9839
9813
|
roles: historyRoles(),
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
|
|
9814
|
+
query: typebox_exports.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
9815
|
+
after: boundParameter("Start strictly after this bound, paging forward; 0 starts at the oldest event."),
|
|
9816
|
+
before: boundParameter("Stop strictly before this bound; without `after`, take the newest eligible events."),
|
|
9817
|
+
context: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events on each side of a hit in its own session; requires a query." })),
|
|
9818
|
+
limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
|
|
9846
9819
|
max_chars_per_item: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." }))
|
|
9847
9820
|
}, { additionalProperties: false });
|
|
9821
|
+
var ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
9822
|
+
function parseBound(name, value) {
|
|
9823
|
+
if (value === void 0) return success(void 0);
|
|
9824
|
+
if (typeof value === "number" || /^\d+$/.test(value)) {
|
|
9825
|
+
const seq = Number(value);
|
|
9826
|
+
if (Number.isSafeInteger(seq) && seq >= 0) return success({ seq });
|
|
9827
|
+
} else if (typeof value === "string") {
|
|
9828
|
+
const match = ISO_8601.exec(value);
|
|
9829
|
+
const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
|
|
9830
|
+
if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10))) return success({ at });
|
|
9831
|
+
}
|
|
9832
|
+
return failure("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
|
|
9833
|
+
}
|
|
9834
|
+
function parseSelection(params) {
|
|
9835
|
+
const after = parseBound("after", params.after);
|
|
9836
|
+
if (!after.ok) return after;
|
|
9837
|
+
const before = parseBound("before", params.before);
|
|
9838
|
+
if (!before.ok) return before;
|
|
9839
|
+
try {
|
|
9840
|
+
const query = searchQueries(params.query);
|
|
9841
|
+
if (!query.length && params.context !== void 0) return failure("invalid_params", "`context` requires a non-empty `query`.");
|
|
9842
|
+
return success({ after: after.data, before: before.data, query: query.length ? query : void 0, roles: params.roles, context: params.context, limit: params.limit });
|
|
9843
|
+
} catch (error) {
|
|
9844
|
+
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
9845
|
+
throw error;
|
|
9846
|
+
}
|
|
9847
|
+
}
|
|
9848
9848
|
var historyList = {
|
|
9849
9849
|
name: "history_list",
|
|
9850
9850
|
label: "History list items",
|
|
@@ -9852,32 +9852,34 @@ var historyList = {
|
|
|
9852
9852
|
parameters: historyListParameters,
|
|
9853
9853
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
9854
9854
|
async execute(params, context2, wrapText = plainText) {
|
|
9855
|
+
const selection = parseSelection(params);
|
|
9856
|
+
if (!selection.ok) return selection;
|
|
9857
|
+
const scoped = selection.data;
|
|
9855
9858
|
const fits = (page) => fitsResult(success(page), (result2) => wrapText(renderOutcome(result2, renderPage)));
|
|
9856
9859
|
const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
|
|
9857
|
-
if (params.session === void 0) return pageOutcome(selectPage(await currentHistory(context2),
|
|
9860
|
+
if (params.session === void 0) return pageOutcome(selectPage(await currentHistory(context2), scoped, fits, maxChars));
|
|
9858
9861
|
const selector = parseSessionSelector(params.session);
|
|
9859
9862
|
if (!selector.ok) return selector;
|
|
9860
9863
|
const corpus = "corpus" in context2 ? context2.corpus : void 0;
|
|
9861
9864
|
if (selector.data.wildcard) {
|
|
9862
|
-
const
|
|
9863
|
-
if (
|
|
9865
|
+
const { after, before, query, roles } = scoped;
|
|
9866
|
+
if (after && "seq" in after || before && "seq" in before) return failure("invalid_bounds", "Wildcard history requires times, not seqs, for `after` and `before`.");
|
|
9864
9867
|
if (corpus === void 0) return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
9865
9868
|
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
const
|
|
9869
|
-
const collector = new CorpusCollector(scoped.data);
|
|
9869
|
+
if (!query) sessions.sort((a, b) => (after ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
9870
|
+
const representative = !query && !roles && !after && !before;
|
|
9871
|
+
const collector = new CorpusCollector(scoped);
|
|
9870
9872
|
let qualifying = 0;
|
|
9871
9873
|
const notices = [];
|
|
9872
9874
|
let unvisited = false;
|
|
9873
9875
|
for (const [index, session] of sessions.entries()) {
|
|
9874
|
-
const result3 = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session,
|
|
9876
|
+
const result3 = representative ? await loadHistoryRepresentative(session) : await loadHistorySession(session, query);
|
|
9875
9877
|
if (!result3.ok || !result3.data) continue;
|
|
9876
9878
|
const added = "projection" in result3.data ? collector.add(sessionIdentity(session), result3.data.projection) : collector.addRepresentative(sessionIdentity(session), result3.data.event);
|
|
9877
9879
|
if (!added) continue;
|
|
9878
9880
|
qualifying++;
|
|
9879
9881
|
if (result3.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result3.data.notice}`);
|
|
9880
|
-
if (!
|
|
9882
|
+
if (!query && qualifying >= Math.min(500, Math.max(1, params.limit ?? 20))) {
|
|
9881
9883
|
unvisited = index + 1 < sessions.length;
|
|
9882
9884
|
break;
|
|
9883
9885
|
}
|
|
@@ -9891,7 +9893,7 @@ var historyList = {
|
|
|
9891
9893
|
const loaded = await loadHistorySession(target.data);
|
|
9892
9894
|
if (!loaded.ok) return loaded;
|
|
9893
9895
|
const notice = loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice };
|
|
9894
|
-
const result = pageOutcome(selectPage(loaded.data.projection, { ...
|
|
9896
|
+
const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
|
|
9895
9897
|
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
9896
9898
|
},
|
|
9897
9899
|
render: (result) => renderOutcome(result, renderPage)
|
|
@@ -11581,8 +11583,7 @@ var OPERATIONS = {
|
|
|
11581
11583
|
notes_write: boundOperation(notesWrite),
|
|
11582
11584
|
notes_update: boundOperation(notesUpdate),
|
|
11583
11585
|
notes_read: boundOperation(notesRead),
|
|
11584
|
-
notes_list: boundOperation(notesList)
|
|
11585
|
-
notes_search: boundOperation(notesSearch)
|
|
11586
|
+
notes_list: boundOperation(notesList)
|
|
11586
11587
|
};
|
|
11587
11588
|
var HISTORY_OPERATIONS = {
|
|
11588
11589
|
history_list: boundOperation(historyList),
|