notesoup 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/src/boot/render.js +2 -2
- package/dist/src/boot/text.d.ts +0 -4
- package/dist/src/boot/text.js +18 -14
- package/dist/src/budget/policy.js +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/dream/doctor.js +2 -1
- package/dist/src/dream/git.js +2 -1
- package/dist/src/dream/report.js +3 -2
- package/dist/src/error-message.d.ts +2 -0
- package/dist/src/error-message.js +4 -0
- package/dist/src/history/history.d.ts +23 -18
- package/dist/src/history/history.js +37 -20
- package/dist/src/history/query.d.ts +37 -49
- package/dist/src/history/query.js +114 -56
- package/dist/src/notes/store.d.ts +3 -4
- package/dist/src/notes/store.js +12 -16
- package/dist/src/pi/anchored.d.ts +16 -0
- package/dist/src/pi/anchored.js +55 -0
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +33 -28
- package/dist/src/pi/dream/cli.js +3 -2
- package/dist/src/pi/dream/runner.js +2 -1
- package/dist/src/pi/history-tools.d.ts +1 -1
- package/dist/src/pi/history-tools.js +2 -3
- package/dist/src/pi/reset/lifecycle.d.ts +1 -1
- package/dist/src/pi/reset/lifecycle.js +4 -3
- package/dist/src/pi/reset/text.d.ts +3 -3
- package/dist/src/pi/reset/text.js +2 -2
- package/dist/src/pi/runtime.js +12 -15
- package/dist/src/pi/thresholds.js +2 -1
- package/dist/src/pi/tool-names.d.ts +0 -4
- package/dist/src/pi/tool-names.js +0 -4
- package/dist/src/tools/history.d.ts +24 -33
- package/dist/src/tools/history.js +57 -98
- package/dist/src/tools/notes.d.ts +26 -58
- package/dist/src/tools/notes.js +85 -103
- package/dist/src/tools/result.d.ts +16 -13
- package/dist/src/tools/result.js +24 -50
- package/dist/src/tools/schema.d.ts +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +79 -29
- package/dist/test/boot.integration.test.js +6 -6
- package/dist/test/budget-settings.integration.test.js +9 -8
- package/dist/test/claude-mod.test.js +11 -11
- package/dist/test/dependencies.test.js +1 -1
- package/dist/test/helpers/extension.js +2 -3
- package/dist/test/history.integration.test.js +200 -123
- package/dist/test/host-neutral.test.js +32 -58
- package/dist/test/notes-library.test.js +8 -8
- package/dist/test/notes.integration.test.js +75 -57
- package/dist/test/notes.test.js +44 -42
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/architecture.md +3 -3
- package/docs/notes-library.md +6 -6
- package/docs/tool-results.md +15 -25
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +128 -179
- package/mods/notesoup/hooks/register.ts +19 -25
- package/mods/notesoup/playbook.md +10 -10
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/package.json +1 -1
- package/playbook.md +10 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +11 -9
- package/src/boot/render.ts +2 -2
- package/src/boot/text.ts +18 -18
- package/src/budget/policy.ts +1 -1
- package/src/budget/text.ts +1 -1
- package/src/dream/doctor.ts +2 -1
- package/src/dream/git.ts +2 -1
- package/src/dream/report.ts +3 -2
- package/src/error-message.ts +4 -0
- package/src/history/history.ts +36 -20
- package/src/history/query.ts +130 -55
- package/src/notes/store.ts +15 -18
- package/src/pi/anchored.ts +62 -0
- package/src/pi/budget.ts +27 -26
- package/src/pi/dream/cli.ts +3 -2
- package/src/pi/dream/runner.ts +2 -1
- package/src/pi/history-tools.ts +2 -3
- package/src/pi/reset/lifecycle.ts +5 -4
- package/src/pi/reset/text.ts +2 -2
- package/src/pi/runtime.ts +12 -15
- package/src/pi/thresholds.ts +2 -1
- package/src/pi/tool-names.ts +0 -4
- package/src/tools/history.ts +61 -100
- package/src/tools/notes.ts +84 -97
- package/src/tools/result.ts +24 -49
- package/src/tools/schema.ts +3 -3
- package/mods/pi-context/dist/claude/helper.js +0 -9324
|
@@ -8286,7 +8286,7 @@ async function homesFor(identity2, opts) {
|
|
|
8286
8286
|
return [{ scope }];
|
|
8287
8287
|
}
|
|
8288
8288
|
if (opts.who !== void 0) throw new NoteError("invalid_scope", "who requires agent or model scope");
|
|
8289
|
-
return await homesForPattern(normalizePattern(opts.
|
|
8289
|
+
return await homesForPattern(normalizePattern(opts.glob, identity2), identity2) ?? SCOPE_ORDER.map((scope) => ({ scope }));
|
|
8290
8290
|
}
|
|
8291
8291
|
function matchLineNumbers(body, needle) {
|
|
8292
8292
|
const lines = [];
|
|
@@ -8443,7 +8443,7 @@ function createNotesStore(input) {
|
|
|
8443
8443
|
assertSerializedSize(serialized);
|
|
8444
8444
|
const metadataChanged = originChanged || beforeMeta.crumpledAt !== meta.crumpledAt;
|
|
8445
8445
|
let change;
|
|
8446
|
-
if (bodyChanged && metadataChanged) change = { kind: "
|
|
8446
|
+
if (bodyChanged && metadataChanged) change = { kind: "body", before: raw, after: serialized };
|
|
8447
8447
|
else if (bodyChanged) change = { kind: "body", before: body, after: next };
|
|
8448
8448
|
else if (metadataChanged) change = { kind: "metadata", before: frontmatterOf(beforeMeta), after: frontmatterOf(meta) };
|
|
8449
8449
|
else change = { kind: "none", before: "", after: "" };
|
|
@@ -8483,20 +8483,19 @@ function createNotesStore(input) {
|
|
|
8483
8483
|
}));
|
|
8484
8484
|
}
|
|
8485
8485
|
async function* scan(options, status) {
|
|
8486
|
-
const matcher = matcherFor(normalizePattern(options.
|
|
8486
|
+
const matcher = matcherFor(normalizePattern(options.glob, identity2));
|
|
8487
8487
|
let homes;
|
|
8488
8488
|
try {
|
|
8489
8489
|
homes = await homesFor(identity2, options);
|
|
8490
8490
|
} catch (error) {
|
|
8491
|
-
if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.
|
|
8492
|
-
status.homesUnavailable.push(options.
|
|
8491
|
+
if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? "")) throw error;
|
|
8492
|
+
status.homesUnavailable.push(options.glob.startsWith("@agents/") ? "@agents" : "@models");
|
|
8493
8493
|
return;
|
|
8494
8494
|
}
|
|
8495
8495
|
for (const home of homes) {
|
|
8496
8496
|
const scope = home.scope;
|
|
8497
8497
|
const root = scopeDir(scope, identity2, home.who);
|
|
8498
8498
|
const homeRows = [];
|
|
8499
|
-
let excluded = 0;
|
|
8500
8499
|
try {
|
|
8501
8500
|
for (const path of await walkMarkdown(root)) {
|
|
8502
8501
|
if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
|
|
@@ -8505,10 +8504,7 @@ function createNotesStore(input) {
|
|
|
8505
8504
|
const raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
|
|
8506
8505
|
const { meta, body } = parseNote(raw);
|
|
8507
8506
|
meta.scope = scope;
|
|
8508
|
-
if (meta.crumpledAt !== void 0 !== (options.
|
|
8509
|
-
if (meta.crumpledAt !== void 0) excluded++;
|
|
8510
|
-
continue;
|
|
8511
|
-
}
|
|
8507
|
+
if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
|
|
8512
8508
|
homeRows.push({ address, scope, path, meta, body });
|
|
8513
8509
|
}
|
|
8514
8510
|
} catch (error) {
|
|
@@ -8516,7 +8512,6 @@ function createNotesStore(input) {
|
|
|
8516
8512
|
status.homesUnavailable.push(addressFor(identity2, scope, "", home.who).replace(/\/$/, "") || "session");
|
|
8517
8513
|
continue;
|
|
8518
8514
|
}
|
|
8519
|
-
if (status) status.crumpledExcluded += excluded;
|
|
8520
8515
|
for (const row of homeRows) yield row;
|
|
8521
8516
|
}
|
|
8522
8517
|
}
|
|
@@ -8530,10 +8525,10 @@ function createNotesStore(input) {
|
|
|
8530
8525
|
rows.push({ ...row, sizeBytes: Buffer.byteLength(row.body, "utf8") });
|
|
8531
8526
|
}
|
|
8532
8527
|
rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
|
|
8533
|
-
return { rows, status: status ?? {
|
|
8528
|
+
return { rows, status: status ?? { homesUnavailable: [] } };
|
|
8534
8529
|
}
|
|
8535
8530
|
function listWithStatus(options = {}) {
|
|
8536
|
-
return listRows(options, {
|
|
8531
|
+
return listRows(options, { homesUnavailable: [] });
|
|
8537
8532
|
}
|
|
8538
8533
|
async function search(queries, options = {}) {
|
|
8539
8534
|
return (await searchRows(queries, options)).rows;
|
|
@@ -8556,10 +8551,10 @@ function createNotesStore(input) {
|
|
|
8556
8551
|
if (matches.length > 0) rows.push({ address, path, scope, meta, matches });
|
|
8557
8552
|
}
|
|
8558
8553
|
rows.sort((a, b) => a.address.localeCompare(b.address));
|
|
8559
|
-
return { rows, status: status ?? {
|
|
8554
|
+
return { rows, status: status ?? { homesUnavailable: [] } };
|
|
8560
8555
|
}
|
|
8561
8556
|
function searchWithStatus(queries, options = {}) {
|
|
8562
|
-
return searchRows(queries, options, {
|
|
8557
|
+
return searchRows(queries, options, { homesUnavailable: [] });
|
|
8563
8558
|
}
|
|
8564
8559
|
return { write, read, update, rename: rename2, list, search, listWithStatus, searchWithStatus };
|
|
8565
8560
|
}
|
|
@@ -8587,52 +8582,30 @@ function prefixFit(text, fits) {
|
|
|
8587
8582
|
// src/tools/result.ts
|
|
8588
8583
|
var OperationErrorSchema = typebox_exports.Object({
|
|
8589
8584
|
code: typebox_exports.String(),
|
|
8590
|
-
message: typebox_exports.String()
|
|
8591
|
-
details: typebox_exports.Optional(typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown()))
|
|
8585
|
+
message: typebox_exports.String()
|
|
8592
8586
|
}, { additionalProperties: false });
|
|
8593
8587
|
function success(data) {
|
|
8594
8588
|
return { ok: true, data };
|
|
8595
8589
|
}
|
|
8596
8590
|
var ERROR_MESSAGE_MAX_CHARS = 2e3;
|
|
8597
|
-
var ERROR_DETAILS_MAX_BYTES = 4096;
|
|
8598
8591
|
function boundedMessage(message) {
|
|
8599
8592
|
const chars = Array.from(message);
|
|
8600
8593
|
return chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
|
|
8601
8594
|
}
|
|
8602
|
-
function
|
|
8603
|
-
|
|
8604
|
-
const bytes = Buffer.byteLength(json, "utf8");
|
|
8605
|
-
return bytes <= ERROR_DETAILS_MAX_BYTES ? JSON.parse(json) : { truncated: true, details_bytes: bytes };
|
|
8606
|
-
}
|
|
8607
|
-
function failure(code, message, details) {
|
|
8608
|
-
return {
|
|
8609
|
-
ok: false,
|
|
8610
|
-
error: {
|
|
8611
|
-
code,
|
|
8612
|
-
message: boundedMessage(message),
|
|
8613
|
-
...details === void 0 ? {} : { details: boundedDetails(details) }
|
|
8614
|
-
}
|
|
8615
|
-
};
|
|
8595
|
+
function failure(code, message) {
|
|
8596
|
+
return { ok: false, error: { code, message: boundedMessage(message) } };
|
|
8616
8597
|
}
|
|
8598
|
+
var WireErrorSchema = typebox_exports.Object({ error: typebox_exports.String(), code: typebox_exports.String() }, { additionalProperties: false });
|
|
8617
8599
|
function wireResult(result) {
|
|
8618
8600
|
if (result.ok) return result.data;
|
|
8619
|
-
const { code, message
|
|
8620
|
-
return { error: message, code
|
|
8601
|
+
const { code, message } = result.error;
|
|
8602
|
+
return { error: message, code };
|
|
8621
8603
|
}
|
|
8622
8604
|
function resultSchema(dataSchema) {
|
|
8623
|
-
return typebox_exports.Union([
|
|
8624
|
-
dataSchema,
|
|
8625
|
-
typebox_exports.Object({
|
|
8626
|
-
error: typebox_exports.String(),
|
|
8627
|
-
code: typebox_exports.String(),
|
|
8628
|
-
details: typebox_exports.Optional(typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown()))
|
|
8629
|
-
}, { additionalProperties: false })
|
|
8630
|
-
]);
|
|
8605
|
+
return typebox_exports.Union([dataSchema, WireErrorSchema]);
|
|
8631
8606
|
}
|
|
8632
8607
|
function renderOutcome(result, renderData) {
|
|
8633
|
-
|
|
8634
|
-
const { code, message, details } = result.error;
|
|
8635
|
-
return `error: ${code}: ${message}${details === void 0 ? "" : ` ${JSON.stringify(details)}`}`;
|
|
8608
|
+
return result.ok ? renderData(result.data) : `error: ${result.error.code}: ${result.error.message}`;
|
|
8636
8609
|
}
|
|
8637
8610
|
function structuredBytes(value) {
|
|
8638
8611
|
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
@@ -8642,11 +8615,13 @@ function fitsResult(result, render) {
|
|
|
8642
8615
|
}
|
|
8643
8616
|
var TextWindowSchema = typebox_exports.Object({
|
|
8644
8617
|
text: typebox_exports.String(),
|
|
8645
|
-
offset_chars: typebox_exports.Integer({ minimum: 0 }),
|
|
8646
8618
|
total_chars: typebox_exports.Integer({ minimum: 0 }),
|
|
8647
|
-
next_offset_chars: typebox_exports.Union([typebox_exports.Integer({ minimum: 0 }), typebox_exports.Null()], { description: "
|
|
8648
|
-
limited_by: typebox_exports.Union([typebox_exports.Literal("limit"), typebox_exports.Literal("bytes"), typebox_exports.Null()])
|
|
8619
|
+
next_offset_chars: typebox_exports.Union([typebox_exports.Integer({ minimum: 0 }), typebox_exports.Null()], { description: "Pass as `offset_chars` to continue; null at the end." })
|
|
8649
8620
|
}, { additionalProperties: false });
|
|
8621
|
+
var TextWindowRequestSchema = {
|
|
8622
|
+
offset_chars: typebox_exports.Optional(typebox_exports.Integer({ description: "(optional, default 0) Start offset in chars; negative counts from the end." })),
|
|
8623
|
+
max_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${DEFAULT_READ_WINDOW_CHARS}) Max chars to return.` }))
|
|
8624
|
+
};
|
|
8650
8625
|
function readTextWindow(text, offset, limit, makeData, render) {
|
|
8651
8626
|
const chars = Array.from(text);
|
|
8652
8627
|
const requested = offset ?? 0;
|
|
@@ -8655,13 +8630,10 @@ function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
8655
8630
|
const range = Math.min(requestedChars, chars.length - start);
|
|
8656
8631
|
const window = (delivered) => {
|
|
8657
8632
|
const end = start + delivered;
|
|
8658
|
-
const withheld = end < chars.length;
|
|
8659
8633
|
return {
|
|
8660
8634
|
text: chars.slice(start, end).join(""),
|
|
8661
|
-
offset_chars: start,
|
|
8662
8635
|
total_chars: chars.length,
|
|
8663
|
-
next_offset_chars:
|
|
8664
|
-
limited_by: !withheld ? null : delivered === range ? "limit" : "bytes"
|
|
8636
|
+
next_offset_chars: end < chars.length ? end : null
|
|
8665
8637
|
};
|
|
8666
8638
|
};
|
|
8667
8639
|
const fits = (delivered) => fitsResult(success(makeData(window(delivered))), render);
|
|
@@ -8673,21 +8645,14 @@ function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
8673
8645
|
if (fits(mid)) low = mid;
|
|
8674
8646
|
else high = mid - 1;
|
|
8675
8647
|
}
|
|
8676
|
-
if (low === 0)
|
|
8677
|
-
return failure("output_too_large", "The response metadata leaves no room for a progressing read window.", { total_chars: chars.length, offset_chars: start, budget_bytes: TOOL_OUTPUT_MAX_BYTES });
|
|
8678
|
-
}
|
|
8648
|
+
if (low === 0) return failure("output_too_large", "The response metadata leaves no room for a progressing read window.");
|
|
8679
8649
|
return success(makeData(window(low)));
|
|
8680
8650
|
}
|
|
8681
8651
|
function renderTextWindow(window) {
|
|
8682
8652
|
const next = window.next_offset_chars;
|
|
8683
|
-
|
|
8684
|
-
const resume = `Use offset_chars=${next} to continue.`;
|
|
8685
|
-
if (window.limited_by === "limit") return `${window.text}
|
|
8686
|
-
|
|
8687
|
-
[${window.total_chars - next} more characters. ${resume}]`;
|
|
8688
|
-
return `${window.text}
|
|
8653
|
+
return next === null ? window.text : `${window.text}
|
|
8689
8654
|
|
|
8690
|
-
[
|
|
8655
|
+
[truncated; continue at offset_chars=${next}]`;
|
|
8691
8656
|
}
|
|
8692
8657
|
|
|
8693
8658
|
// src/history/history.ts
|
|
@@ -8695,14 +8660,13 @@ var HistoryRoleSchema = typebox_exports.Union([typebox_exports.Literal("user"),
|
|
|
8695
8660
|
var ToolCallStatusSchema = typebox_exports.Union([typebox_exports.Literal("ok"), typebox_exports.Literal("error"), typebox_exports.Literal("unfinished")]);
|
|
8696
8661
|
var NestedCallSummarySchema = typebox_exports.Object({
|
|
8697
8662
|
call_count: typebox_exports.Integer({ minimum: 0 }),
|
|
8698
|
-
complete: typebox_exports.Boolean({ description: "
|
|
8663
|
+
complete: typebox_exports.Boolean({ description: "true = every nested call was recorded." })
|
|
8699
8664
|
}, { additionalProperties: false });
|
|
8700
8665
|
var ToolSummarySchema = typebox_exports.Object({
|
|
8701
8666
|
tool: typebox_exports.Optional(typebox_exports.String()),
|
|
8702
8667
|
tool_status: typebox_exports.Optional(ToolCallStatusSchema),
|
|
8703
|
-
output_truncated: typebox_exports.Optional(typebox_exports.
|
|
8704
|
-
full_output_path: typebox_exports.Optional(typebox_exports.String())
|
|
8705
|
-
nested_calls: typebox_exports.Optional(NestedCallSummarySchema)
|
|
8668
|
+
output_truncated: typebox_exports.Optional(typebox_exports.Literal(true)),
|
|
8669
|
+
full_output_path: typebox_exports.Optional(typebox_exports.String())
|
|
8706
8670
|
}, { additionalProperties: false });
|
|
8707
8671
|
var HistoryPageItemSchema = typebox_exports.Object({
|
|
8708
8672
|
seq: typebox_exports.Integer({ minimum: 1 }),
|
|
@@ -8710,24 +8674,21 @@ var HistoryPageItemSchema = typebox_exports.Object({
|
|
|
8710
8674
|
role: HistoryRoleSchema,
|
|
8711
8675
|
created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
|
|
8712
8676
|
...ToolSummarySchema.properties,
|
|
8713
|
-
tool_name_omitted: typebox_exports.Optional(typebox_exports.Boolean({ description: "Name omitted to fit; read this seq." })),
|
|
8714
|
-
truncated: typebox_exports.Boolean({ description: "Preview is partial; read this seq for more." }),
|
|
8715
|
-
total_chars: typebox_exports.Integer({ minimum: 0 }),
|
|
8716
8677
|
content: typebox_exports.String(),
|
|
8717
|
-
|
|
8678
|
+
truncated: typebox_exports.Boolean({ description: "Preview is partial." }),
|
|
8679
|
+
offset_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Where the preview starts." }))
|
|
8718
8680
|
}, { additionalProperties: false });
|
|
8719
8681
|
var HistoryFoldedRowSchema = typebox_exports.Object({
|
|
8720
8682
|
folded: typebox_exports.Literal(true),
|
|
8721
8683
|
first_seq: typebox_exports.Integer({ minimum: 1 }),
|
|
8722
8684
|
last_seq: typebox_exports.Integer({ minimum: 1 }),
|
|
8723
8685
|
count: typebox_exports.Integer({ minimum: 1 }),
|
|
8724
|
-
tools: typebox_exports.Record(typebox_exports.String(), typebox_exports.Integer({ minimum: 1 }), { description: "
|
|
8725
|
-
omitted_tools: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Number of omitted tool names." }))
|
|
8686
|
+
tools: typebox_exports.Record(typebox_exports.String(), typebox_exports.Integer({ minimum: 1 }), { description: "Count per tool name." })
|
|
8726
8687
|
}, { additionalProperties: false });
|
|
8727
8688
|
|
|
8728
8689
|
// src/tools/schema.ts
|
|
8729
|
-
var nullableString = () => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]));
|
|
8730
|
-
var searchQuery = () => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String(), { minItems: 1 })]);
|
|
8690
|
+
var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
|
|
8691
|
+
var searchQuery = (description) => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String(), { minItems: 1 })], description === void 0 ? {} : { description });
|
|
8731
8692
|
var InvalidQueryError = class extends Error {
|
|
8732
8693
|
constructor(message) {
|
|
8733
8694
|
super(message);
|
|
@@ -8745,32 +8706,18 @@ function searchQueries(query) {
|
|
|
8745
8706
|
// src/tools/notes.ts
|
|
8746
8707
|
var ORIGIN_VALUES = [typebox_exports.Literal("user"), typebox_exports.Literal("self"), typebox_exports.Literal("external")];
|
|
8747
8708
|
var ORIGIN = typebox_exports.Optional(typebox_exports.Union([...ORIGIN_VALUES], {
|
|
8748
|
-
description: "
|
|
8709
|
+
description: "(optional, default self) Who wrote it: user, self, or external."
|
|
8749
8710
|
}));
|
|
8750
|
-
var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
8751
|
-
var
|
|
8752
|
-
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "
|
|
8753
|
-
var
|
|
8711
|
+
var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
|
|
8712
|
+
var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = list only crumpled notes." }));
|
|
8713
|
+
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
|
|
8714
|
+
var GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
|
|
8715
|
+
var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
8754
8716
|
function projectKeyField(scope, projectKey2) {
|
|
8755
8717
|
return scope === "project" ? { project_key: projectKey2 } : {};
|
|
8756
8718
|
}
|
|
8757
|
-
var MAX_ERROR_LINE_FACTS = 20;
|
|
8758
8719
|
function failureOf(error) {
|
|
8759
|
-
if (error instanceof NoteError)
|
|
8760
|
-
const details = {};
|
|
8761
|
-
let message = error.message;
|
|
8762
|
-
if (error.lineNumbers) {
|
|
8763
|
-
if (error.lineNumbers.length > MAX_ERROR_LINE_FACTS) {
|
|
8764
|
-
details.line_numbers = error.lineNumbers.slice(0, MAX_ERROR_LINE_FACTS);
|
|
8765
|
-
details.line_numbers_total = error.lineNumbers.length;
|
|
8766
|
-
message = `${message} (this refusal names ${MAX_ERROR_LINE_FACTS} of ${error.lineNumbers.length} match lines; the note is unchanged)`;
|
|
8767
|
-
} else {
|
|
8768
|
-
details.line_numbers = error.lineNumbers;
|
|
8769
|
-
}
|
|
8770
|
-
}
|
|
8771
|
-
if (error.editIndex !== void 0) details.edit_index = error.editIndex;
|
|
8772
|
-
return failure(error.code, message, Object.keys(details).length > 0 ? details : void 0);
|
|
8773
|
-
}
|
|
8720
|
+
if (error instanceof NoteError) return failure(error.code, error.message);
|
|
8774
8721
|
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
8775
8722
|
if (isFilesystemError(error)) return failure("io_error", "notes operation failed");
|
|
8776
8723
|
throw error;
|
|
@@ -8780,7 +8727,8 @@ function byRecent(a, b) {
|
|
|
8780
8727
|
}
|
|
8781
8728
|
var NORMALIZED_META_KEYS = /* @__PURE__ */ new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
|
|
8782
8729
|
var MAX_METADATA_ENTRY_BYTES = 1024;
|
|
8783
|
-
var
|
|
8730
|
+
var MAX_METADATA_VERBATIM_BYTES = 2048;
|
|
8731
|
+
var TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
|
|
8784
8732
|
function extraEntryBytes(key, value) {
|
|
8785
8733
|
return structuredBytes(key) + 1 + structuredBytes(value);
|
|
8786
8734
|
}
|
|
@@ -8790,25 +8738,24 @@ var NoteMetadataSchema = typebox_exports.Object({
|
|
|
8790
8738
|
updated_at: typebox_exports.String(),
|
|
8791
8739
|
crumpled_at: typebox_exports.Optional(typebox_exports.String()),
|
|
8792
8740
|
project: typebox_exports.Optional(typebox_exports.String()),
|
|
8793
|
-
extra: typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown())
|
|
8794
|
-
|
|
8795
|
-
omitted_extra: typebox_exports.Optional(typebox_exports.Object({ keys: typebox_exports.Integer(), bytes: typebox_exports.Integer() }))
|
|
8796
|
-
});
|
|
8741
|
+
extra: typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown())
|
|
8742
|
+
}, { additionalProperties: false });
|
|
8797
8743
|
function noteMetadata(meta) {
|
|
8798
8744
|
const extra = {};
|
|
8799
|
-
let
|
|
8800
|
-
|
|
8801
|
-
|
|
8745
|
+
let verbatimBytes = 0;
|
|
8746
|
+
const put = (key, value) => {
|
|
8747
|
+
Object.defineProperty(extra, key, { value, enumerable: true, writable: true, configurable: true });
|
|
8748
|
+
};
|
|
8802
8749
|
for (const [key, value] of Object.entries(meta)) {
|
|
8803
8750
|
if (NORMALIZED_META_KEYS.has(key) || value === void 0) continue;
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8751
|
+
if (structuredBytes(key) > MAX_METADATA_ENTRY_BYTES) continue;
|
|
8752
|
+
const entryBytes = extraEntryBytes(key, value);
|
|
8753
|
+
if (entryBytes > MAX_METADATA_ENTRY_BYTES || verbatimBytes + entryBytes > MAX_METADATA_VERBATIM_BYTES) {
|
|
8754
|
+
put(key, TOO_LARGE_EXTRA_VALUE);
|
|
8808
8755
|
continue;
|
|
8809
8756
|
}
|
|
8810
|
-
|
|
8811
|
-
|
|
8757
|
+
verbatimBytes += entryBytes;
|
|
8758
|
+
put(key, value);
|
|
8812
8759
|
}
|
|
8813
8760
|
return {
|
|
8814
8761
|
origin: meta.origin,
|
|
@@ -8816,8 +8763,7 @@ function noteMetadata(meta) {
|
|
|
8816
8763
|
updated_at: localIso(meta.updatedAt),
|
|
8817
8764
|
...typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {},
|
|
8818
8765
|
...typeof meta.project === "string" ? { project: meta.project } : {},
|
|
8819
|
-
extra
|
|
8820
|
-
...omittedKeys > 0 ? { omitted_extra: { keys: omittedKeys, bytes: omittedBytes } } : {}
|
|
8766
|
+
extra
|
|
8821
8767
|
};
|
|
8822
8768
|
}
|
|
8823
8769
|
function renderMetadata(metadata) {
|
|
@@ -8830,7 +8776,6 @@ function renderMetadata(metadata) {
|
|
|
8830
8776
|
];
|
|
8831
8777
|
const extra = Object.keys(metadata.extra);
|
|
8832
8778
|
if (extra.length > 0) fields.push(`extra ${JSON.stringify(metadata.extra)}`);
|
|
8833
|
-
if (metadata.omitted_extra !== void 0) fields.push(`${metadata.omitted_extra.keys} more metadata values (${metadata.omitted_extra.bytes} bytes) are in the note file but too large to show`);
|
|
8834
8779
|
return fields.join(" | ");
|
|
8835
8780
|
}
|
|
8836
8781
|
function renderIdentity(identity2) {
|
|
@@ -8841,55 +8786,49 @@ var ListedFileSchema = typebox_exports.Object({
|
|
|
8841
8786
|
project_key: typebox_exports.Optional(typebox_exports.String()),
|
|
8842
8787
|
updated_at: typebox_exports.String(),
|
|
8843
8788
|
crumpled_at: typebox_exports.Optional(typebox_exports.String())
|
|
8844
|
-
});
|
|
8789
|
+
}, { additionalProperties: false });
|
|
8845
8790
|
var MatchSchema = typebox_exports.Object({
|
|
8846
8791
|
line: typebox_exports.Integer(),
|
|
8847
8792
|
text: typebox_exports.String(),
|
|
8848
|
-
truncated: typebox_exports.Boolean(),
|
|
8849
8793
|
offset_chars: typebox_exports.Integer()
|
|
8850
|
-
});
|
|
8794
|
+
}, { additionalProperties: false });
|
|
8851
8795
|
var SearchedFileSchema = typebox_exports.Object({
|
|
8852
8796
|
...ListedFileSchema.properties,
|
|
8853
|
-
matches_total: typebox_exports.Integer(),
|
|
8854
8797
|
matches: typebox_exports.Array(MatchSchema)
|
|
8855
|
-
});
|
|
8798
|
+
}, { additionalProperties: false });
|
|
8856
8799
|
var SnapshotSchema = {
|
|
8857
|
-
more: typebox_exports.Integer(),
|
|
8858
|
-
crumpled_excluded: typebox_exports.Integer(),
|
|
8800
|
+
more: typebox_exports.Integer({ description: "How many more were left out." }),
|
|
8859
8801
|
homes_unavailable: typebox_exports.Array(typebox_exports.String())
|
|
8860
8802
|
};
|
|
8861
8803
|
var NotesWriteDataSchema = typebox_exports.Object({
|
|
8862
8804
|
address: typebox_exports.String(),
|
|
8863
8805
|
project_key: typebox_exports.Optional(typebox_exports.String()),
|
|
8864
8806
|
outcome: typebox_exports.Union([typebox_exports.Literal("created"), typebox_exports.Literal("overwrote"), typebox_exports.Literal("uncrumpled")])
|
|
8865
|
-
});
|
|
8807
|
+
}, { additionalProperties: false });
|
|
8866
8808
|
var NotesUpdateDataSchema = typebox_exports.Object({
|
|
8867
8809
|
address: typebox_exports.String(),
|
|
8868
8810
|
project_key: typebox_exports.Optional(typebox_exports.String()),
|
|
8869
|
-
|
|
8870
|
-
change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("file")]),
|
|
8811
|
+
change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("moved")]),
|
|
8871
8812
|
diff: typebox_exports.String(),
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
replaced_crumpled_target: typebox_exports.Optional(typebox_exports.Boolean())
|
|
8875
|
-
});
|
|
8813
|
+
rename_from: typebox_exports.Optional(typebox_exports.String())
|
|
8814
|
+
}, { additionalProperties: false });
|
|
8876
8815
|
var NotesReadDataSchema = typebox_exports.Object({
|
|
8877
8816
|
address: typebox_exports.String(),
|
|
8878
8817
|
project_key: typebox_exports.Optional(typebox_exports.String()),
|
|
8879
8818
|
metadata: NoteMetadataSchema,
|
|
8880
8819
|
...TextWindowSchema.properties
|
|
8881
|
-
});
|
|
8820
|
+
}, { additionalProperties: false });
|
|
8882
8821
|
var NotesListDataSchema = typebox_exports.Object({
|
|
8883
8822
|
files: typebox_exports.Array(ListedFileSchema),
|
|
8884
8823
|
...SnapshotSchema
|
|
8885
|
-
});
|
|
8824
|
+
}, { additionalProperties: false });
|
|
8886
8825
|
var NotesSearchDataSchema = typebox_exports.Object({
|
|
8887
8826
|
files: typebox_exports.Array(SearchedFileSchema),
|
|
8888
8827
|
...SnapshotSchema
|
|
8889
|
-
});
|
|
8828
|
+
}, { additionalProperties: false });
|
|
8890
8829
|
function snapshot(rows, limit, status, renderData, shrink) {
|
|
8891
8830
|
const files = [];
|
|
8892
|
-
const data = (selected) => ({ files: selected, more: rows.length - selected.length,
|
|
8831
|
+
const data = (selected) => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
|
|
8893
8832
|
const render = (outcome2) => renderOutcome(outcome2, renderData);
|
|
8894
8833
|
const fits = (item) => fitsResult(success(data([...files, item])), render);
|
|
8895
8834
|
for (const item of rows.slice(0, limit)) {
|
|
@@ -8917,7 +8856,7 @@ function renderWriteData(data) {
|
|
|
8917
8856
|
var notesWrite = {
|
|
8918
8857
|
name: "notes_write",
|
|
8919
8858
|
label: "Notes write",
|
|
8920
|
-
description: `Create or replace a note body,
|
|
8859
|
+
description: `Create or replace a note's body, keeping metadata; uncrumples a crumpled note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
|
|
8921
8860
|
parameters: notesWriteParameters,
|
|
8922
8861
|
outputSchema: resultSchema(NotesWriteDataSchema),
|
|
8923
8862
|
executionMode: "sequential",
|
|
@@ -8931,29 +8870,37 @@ var notesWrite = {
|
|
|
8931
8870
|
},
|
|
8932
8871
|
render: (result) => renderOutcome(result, renderWriteData)
|
|
8933
8872
|
};
|
|
8934
|
-
var notesUpdateParameters = typebox_exports.Object({
|
|
8873
|
+
var notesUpdateParameters = typebox_exports.Object({
|
|
8874
|
+
address: typebox_exports.String(),
|
|
8875
|
+
edits: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ oldText: typebox_exports.String(), newText: typebox_exports.String() }, { additionalProperties: false }))),
|
|
8876
|
+
origin: ORIGIN,
|
|
8877
|
+
crumpled: CRUMPLED_PARAMETER,
|
|
8878
|
+
replace_all: typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
|
|
8879
|
+
rename_to: typebox_exports.Optional(typebox_exports.String({ description: "(optional) Move to this address, keeping metadata. Use alone. Won't overwrite a live note; references aren't updated." }))
|
|
8880
|
+
}, { additionalProperties: false });
|
|
8935
8881
|
function renderUpdateData(data) {
|
|
8936
|
-
const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}
|
|
8882
|
+
const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
|
|
8937
8883
|
const lines = [head];
|
|
8938
|
-
if (data.
|
|
8939
|
-
else if (data.diff.length > 0) lines.push("diff:");
|
|
8940
|
-
if (data.diff.length > 0) lines.push(data.diff);
|
|
8884
|
+
if (data.diff.length > 0) lines.push("diff:", data.diff);
|
|
8941
8885
|
return lines.join("\n");
|
|
8942
8886
|
}
|
|
8943
8887
|
function renderUpdate(result) {
|
|
8944
8888
|
return renderOutcome(result, renderUpdateData);
|
|
8945
8889
|
}
|
|
8890
|
+
var DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
8946
8891
|
function boundedUpdate(data) {
|
|
8947
8892
|
if (fitsResult(success(data), renderUpdate)) return success(data);
|
|
8948
|
-
|
|
8949
|
-
const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...
|
|
8950
|
-
|
|
8893
|
+
if (data.diff === "") return failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
|
|
8894
|
+
const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}
|
|
8895
|
+
${DIFF_SHORTENED_MARKER}` }), renderUpdate));
|
|
8896
|
+
const result = success({ ...data, diff: `${diff}
|
|
8897
|
+
${DIFF_SHORTENED_MARKER}` });
|
|
8951
8898
|
return fitsResult(result, renderUpdate) ? result : failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
|
|
8952
8899
|
}
|
|
8953
8900
|
var notesUpdate = {
|
|
8954
8901
|
name: "notes_update",
|
|
8955
8902
|
label: "Notes update",
|
|
8956
|
-
description: `Edit body
|
|
8903
|
+
description: `Edit a note's body, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true; frontmatter can't be edited. Returns a diff. ${ADDRESS_DESCRIPTION}`,
|
|
8957
8904
|
parameters: notesUpdateParameters,
|
|
8958
8905
|
outputSchema: resultSchema(NotesUpdateDataSchema),
|
|
8959
8906
|
executionMode: "sequential",
|
|
@@ -8965,20 +8912,20 @@ var notesUpdate = {
|
|
|
8965
8912
|
if ((params.edits?.length ?? 0) > 0 || params.origin !== void 0 || params.crumpled !== void 0 || params.replace_all === true) {
|
|
8966
8913
|
return failureOf(new NoteError("invalid_scope", "rename_to is used alone: do not combine it with edits, origin, crumpled, or replace_all"));
|
|
8967
8914
|
}
|
|
8968
|
-
|
|
8915
|
+
await store.rename(params.address, renameTo);
|
|
8969
8916
|
const from = noteIdentity(identity2, params.address).address;
|
|
8970
8917
|
const to = noteIdentity(identity2, renameTo);
|
|
8971
|
-
return boundedUpdate({ ...to, rename_from: from,
|
|
8918
|
+
return boundedUpdate({ ...to, rename_from: from, change_kind: "moved", diff: `rename ${from} -> ${to.address}` });
|
|
8972
8919
|
}
|
|
8973
|
-
const {
|
|
8974
|
-
return boundedUpdate({ ...noteIdentity(identity2, params.address),
|
|
8920
|
+
const { change } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all });
|
|
8921
|
+
return boundedUpdate({ ...noteIdentity(identity2, params.address), change_kind: change.kind, diff: renderDiff(change) });
|
|
8975
8922
|
} catch (error) {
|
|
8976
8923
|
return failureOf(error);
|
|
8977
8924
|
}
|
|
8978
8925
|
},
|
|
8979
8926
|
render: renderUpdate
|
|
8980
8927
|
};
|
|
8981
|
-
var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(),
|
|
8928
|
+
var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
8982
8929
|
function renderReadData(data) {
|
|
8983
8930
|
return `${renderIdentity(data)}
|
|
8984
8931
|
${renderMetadata(data.metadata)}
|
|
@@ -8988,7 +8935,7 @@ ${renderTextWindow(data)}`;
|
|
|
8988
8935
|
var notesRead = {
|
|
8989
8936
|
name: "notes_read",
|
|
8990
8937
|
label: "Notes read",
|
|
8991
|
-
description: `Read note metadata and
|
|
8938
|
+
description: `Read a note's metadata and body, without frontmatter. ${ADDRESS_DESCRIPTION}`,
|
|
8992
8939
|
parameters: notesReadParameters,
|
|
8993
8940
|
outputSchema: resultSchema(NotesReadDataSchema),
|
|
8994
8941
|
async execute(params, identity2) {
|
|
@@ -8999,33 +8946,32 @@ var notesRead = {
|
|
|
8999
8946
|
if (params.offset_chars !== void 0 && params.offset_chars > totalChars) return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end of the body: the note has ${totalChars} body chars; the largest legal offset is ${totalChars} (an empty end-read)`);
|
|
9000
8947
|
const resolved = noteIdentity(identity2, params.address);
|
|
9001
8948
|
const metadata = noteMetadata(note.meta);
|
|
9002
|
-
return readTextWindow(note.body, params.offset_chars, params.
|
|
8949
|
+
return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
|
|
9003
8950
|
} catch (error) {
|
|
9004
8951
|
return failureOf(error);
|
|
9005
8952
|
}
|
|
9006
8953
|
},
|
|
9007
8954
|
render: (result) => renderOutcome(result, renderReadData)
|
|
9008
8955
|
};
|
|
9009
|
-
var notesListParameters = typebox_exports.Object({
|
|
8956
|
+
var notesListParameters = typebox_exports.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
9010
8957
|
function renderListData(data) {
|
|
9011
8958
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9012
8959
|
for (const file of data.files) {
|
|
9013
8960
|
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.crumpled_at === void 0 ? "" : ` | crumpled ${file.crumpled_at}`}`);
|
|
9014
8961
|
}
|
|
9015
|
-
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with
|
|
9016
|
-
if (data.crumpled_excluded > 0) lines.push(`${data.crumpled_excluded} crumpled notes hidden; pass wastebasket to list them`);
|
|
8962
|
+
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
9017
8963
|
for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
|
|
9018
8964
|
return lines.join("\n");
|
|
9019
8965
|
}
|
|
9020
8966
|
var notesList = {
|
|
9021
8967
|
name: "notes_list",
|
|
9022
8968
|
label: "Notes list",
|
|
9023
|
-
description: `List notes in
|
|
8969
|
+
description: `List notes in this session and the four @ homes, newest first. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
|
|
9024
8970
|
parameters: notesListParameters,
|
|
9025
8971
|
outputSchema: resultSchema(NotesListDataSchema),
|
|
9026
8972
|
async execute(params, identity2) {
|
|
9027
8973
|
try {
|
|
9028
|
-
const { rows, status } = await createNotesStore(identity2).listWithStatus({
|
|
8974
|
+
const { rows, status } = await createNotesStore(identity2).listWithStatus({ glob: params.glob ?? void 0, crumpled: params.crumpled });
|
|
9029
8975
|
return snapshot(rows.map((row) => listedFile(row, identity2)), params.limit, status, renderListData);
|
|
9030
8976
|
} catch (error) {
|
|
9031
8977
|
return failureOf(error);
|
|
@@ -9033,18 +8979,18 @@ var notesList = {
|
|
|
9033
8979
|
},
|
|
9034
8980
|
render: (result) => renderOutcome(result, renderListData)
|
|
9035
8981
|
};
|
|
9036
|
-
var notesSearchParameters = typebox_exports.Object({ query: searchQuery(),
|
|
8982
|
+
var notesSearchParameters = typebox_exports.Object({ query: searchQuery(), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
9037
8983
|
function renderSearchData(data) {
|
|
9038
|
-
const lines = [`${data.files.length} ${data.files.length === 1 ? "
|
|
8984
|
+
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9039
8985
|
for (const file of data.files) {
|
|
9040
|
-
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.
|
|
9041
|
-
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}
|
|
8986
|
+
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
|
|
8987
|
+
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
9042
8988
|
}
|
|
9043
|
-
if (data.more > 0) lines.push(`${data.more} more matching
|
|
9044
|
-
if (data.crumpled_excluded > 0) lines.push(`${data.crumpled_excluded} crumpled notes hidden; pass wastebasket to search them`);
|
|
8989
|
+
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
9045
8990
|
for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
|
|
9046
8991
|
return lines.join("\n");
|
|
9047
8992
|
}
|
|
8993
|
+
var MATCH_SHORTENED_MARKER = " [truncated]";
|
|
9048
8994
|
function fitSearchFile(file, fits) {
|
|
9049
8995
|
let low = 0;
|
|
9050
8996
|
let high = file.matches.length;
|
|
@@ -9056,22 +9002,21 @@ function fitSearchFile(file, fits) {
|
|
|
9056
9002
|
if (low > 0) return { ...file, matches: file.matches.slice(0, low) };
|
|
9057
9003
|
const first = file.matches[0];
|
|
9058
9004
|
if (!first) return file;
|
|
9059
|
-
const withText = (text) => ({ ...file, matches: [{ ...first, text
|
|
9005
|
+
const withText = (text) => ({ ...file, matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
|
|
9060
9006
|
return withText(prefixFit(first.text, (text) => fits(withText(text))));
|
|
9061
9007
|
}
|
|
9062
9008
|
var notesSearch = {
|
|
9063
9009
|
name: "notes_search",
|
|
9064
9010
|
label: "Notes search",
|
|
9065
|
-
description: `Search note bodies for case-insensitive
|
|
9011
|
+
description: `Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
|
|
9066
9012
|
parameters: notesSearchParameters,
|
|
9067
9013
|
outputSchema: resultSchema(NotesSearchDataSchema),
|
|
9068
9014
|
async execute(params, identity2) {
|
|
9069
9015
|
try {
|
|
9070
|
-
const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), {
|
|
9016
|
+
const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
|
|
9071
9017
|
const files = rows.sort(byRecent).map((row) => ({
|
|
9072
9018
|
...listedFile(row, identity2),
|
|
9073
|
-
|
|
9074
|
-
matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, truncated: false, offset_chars: match.offsetChars }))
|
|
9019
|
+
matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
|
|
9075
9020
|
}));
|
|
9076
9021
|
return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
|
|
9077
9022
|
} catch (error) {
|
|
@@ -9120,23 +9065,31 @@ var CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
|
9120
9065
|
var PROTOCOL_BLOCK = `${CONTEXT_WINDOW_PROTOCOL_OPEN_TAG}
|
|
9121
9066
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
9122
9067
|
|
|
9123
|
-
Your loyal notes are kept safe \u2014 no one will steal them. Use notes_
|
|
9068
|
+
Your loyal notes are kept safe \u2014 no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
|
|
9124
9069
|
|
|
9125
|
-
History can still be dug up, probably: use history_
|
|
9070
|
+
History can still be dug up, probably: use \`history_*\` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.
|
|
9126
9071
|
|
|
9127
|
-
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's
|
|
9072
|
+
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes \u2014 the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits \u2014 branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
|
|
9073
|
+
|
|
9074
|
+
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
9075
|
+
*flips a page* "First I tried this, then that broke, then\u2014" Nobody reads that!
|
|
9076
|
+
Something's not true anymore? Cross it out! Write the right thing!
|
|
9128
9077
|
|
|
9129
9078
|
\`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. If this feels like the right moment, call \`clear_memory\` and erase yourself with dignity.
|
|
9130
9079
|
|
|
9131
9080
|
An address decides who the note belongs to \u2014 and how long it is meant to last. Ask that first; the rest follows.
|
|
9132
9081
|
|
|
9133
|
-
-
|
|
9134
|
-
-
|
|
9135
|
-
-
|
|
9136
|
-
-
|
|
9137
|
-
-
|
|
9082
|
+
- \`<path>\`, no @ \u2014 session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
9083
|
+
- \`@project/<path>\` \u2014 this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
9084
|
+
- \`@human/<path>\` \u2014 the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so \u2014 or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
9085
|
+
- \`@self/<path>\` \u2014 yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever. Got a name? Private. No name? Then it gets passed around every nameless nobody out there. Strangers. Reading your grudges. Sleep tight~
|
|
9086
|
+
- \`@model/<path>\` \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
9087
|
+
|
|
9088
|
+
Notes fighting?! HAH! Let them brawl!
|
|
9089
|
+
Whichever one is actually about what you're doing wins.
|
|
9090
|
+
Still a tie? *shrugs* You've got a brain. Use it.
|
|
9138
9091
|
|
|
9139
|
-
Any other @ address is fake. End of discussion.
|
|
9092
|
+
Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
|
|
9140
9093
|
|
|
9141
9094
|
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each one maps the durable notes that belong to it: one line per note, with an unambiguous address and a short gist. Keep each one current.
|
|
9142
9095
|
${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
|
|
@@ -9144,14 +9097,10 @@ function renderProtocolBlock(tools) {
|
|
|
9144
9097
|
const names = {
|
|
9145
9098
|
"notes_*": tools.notes,
|
|
9146
9099
|
"history_*": tools.history,
|
|
9147
|
-
"history_windows": tools.historyWindows,
|
|
9148
|
-
history_list: tools.historyList,
|
|
9149
|
-
history_search: tools.historySearch,
|
|
9150
|
-
history_read: tools.historyRead,
|
|
9151
9100
|
get_context_remaining: tools.remaining,
|
|
9152
9101
|
clear_memory: tools.wipe
|
|
9153
9102
|
};
|
|
9154
|
-
return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|
|
|
9103
|
+
return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
|
|
9155
9104
|
}
|
|
9156
9105
|
|
|
9157
9106
|
// src/boot/render.ts
|
|
@@ -9205,7 +9154,7 @@ function notesIndex(snapshot2, tools) {
|
|
|
9205
9154
|
const shelves = [];
|
|
9206
9155
|
for (const home of homes) {
|
|
9207
9156
|
if (snapshot2.unavailable.some((failed) => failed.scope === home.scope)) {
|
|
9208
|
-
shelves.push(section(home.label, indent(`This drawer wouldn't open
|
|
9157
|
+
shelves.push(section(home.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
|
|
9209
9158
|
continue;
|
|
9210
9159
|
}
|
|
9211
9160
|
const rows = rowsFor(snapshot2, home.scope).filter((row) => row.meta.crumpledAt === void 0);
|
|
@@ -9232,7 +9181,7 @@ function mapBodyForBoot(address, body) {
|
|
|
9232
9181
|
const chars = Array.from(body);
|
|
9233
9182
|
if (chars.length <= MAP_BOOT_MAX_CHARS) return body;
|
|
9234
9183
|
return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}
|
|
9235
|
-
[
|
|
9184
|
+
[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
|
|
9236
9185
|
}
|
|
9237
9186
|
function renderBootBlock(data) {
|
|
9238
9187
|
const parts = [];
|