notesoup 0.52.5 → 0.52.7
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/dist/plugins/claude/src/helper.js +34 -7
- package/dist/plugins/claude/src/history.d.ts +7 -2
- package/dist/plugins/claude/src/history.js +53 -22
- package/dist/plugins/claude/src/text.d.ts +5 -0
- package/dist/plugins/claude/src/text.js +12 -0
- package/dist/src/history/history.js +12 -11
- package/dist/src/notes/store.d.ts +2 -0
- package/dist/src/notes/store.js +2 -2
- package/dist/src/tools/dream.d.ts +2 -0
- package/dist/src/tools/history.d.ts +5 -3
- package/dist/src/tools/history.js +9 -11
- package/dist/src/tools/notes.d.ts +7 -0
- package/dist/src/tools/notes.js +8 -3
- package/dist/test/claude-history.test.js +135 -3
- package/dist/test/dream-skill.test.js +5 -0
- package/dist/test/dream-tools.test.js +15 -0
- package/dist/test/history.integration.test.js +26 -1
- package/dist/test/notes-library.test.js +1 -1
- package/dist/test/notes.test.js +1 -1
- package/dist/test/pi-render.test.js +2 -2
- package/docs/claude-code-mod.md +6 -2
- package/docs/tool-results.md +2 -2
- package/package.json +1 -1
- package/playbook.md +24 -13
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +105 -44
- package/plugins/claude/playbook.md +24 -13
- package/plugins/claude/skills/dream/SKILL.md +8 -0
- package/plugins/claude/src/helper.ts +34 -9
- package/plugins/claude/src/history.ts +54 -22
- package/plugins/claude/src/text.ts +13 -0
- package/plugins/paseo/OVERVIEW.md +6 -2
- package/plugins/paseo/client/brain-empty-card.tsx +3 -1
- package/plugins/paseo/client/brain-empty-transformer.ts +7 -14
- package/plugins/paseo/client/notes-op-transformer.ts +10 -18
- package/plugins/paseo/client/tool-result.ts +31 -0
- package/plugins/paseo/test/brain-empty.test.ts +24 -1
- package/plugins/paseo/test/fixtures/claude-tool-calls.ts +86 -0
- package/plugins/paseo/test/notes-op.test.ts +39 -1
- package/skills/dream/SKILL.md +8 -0
- package/src/history/history.ts +12 -10
- package/src/notes/store.ts +4 -3
- package/src/tools/history.ts +14 -13
- package/src/tools/notes.ts +8 -3
|
@@ -8569,10 +8569,10 @@ function createNotesStore(input) {
|
|
|
8569
8569
|
if (raw === void 0) return void 0;
|
|
8570
8570
|
const now = Date.now();
|
|
8571
8571
|
const parsed = parseNote(raw, now);
|
|
8572
|
-
if (identity2.dreaming !== void 0 || (scope === "project" || scope === "session") && destination.who !== void 0) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
|
|
8572
|
+
if (identity2.dreaming !== void 0 || (scope === "project" || scope === "session") && destination.who !== void 0) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope, accessedBefore: parsed.meta.lastAccessed };
|
|
8573
8573
|
const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
|
|
8574
8574
|
await atomicWrite(path, serializeNote(meta, parsed.body));
|
|
8575
|
-
return { meta, body: parsed.body, resolvedScope: scope };
|
|
8575
|
+
return { meta, body: parsed.body, resolvedScope: scope, accessedBefore: parsed.meta.lastAccessed };
|
|
8576
8576
|
});
|
|
8577
8577
|
}
|
|
8578
8578
|
async function update(address, edits, options = {}) {
|
|
@@ -8900,28 +8900,28 @@ function toolEvent(item, result) {
|
|
|
8900
8900
|
};
|
|
8901
8901
|
}
|
|
8902
8902
|
function projectHistory(rawWindows, highestSeq, branchSeqs) {
|
|
8903
|
-
const raw = rawWindows.flatMap((current) => current.items);
|
|
8903
|
+
const raw = rawWindows.flatMap((current) => current.items).sort((a, b) => a.seq - b.seq);
|
|
8904
8904
|
const resultsById = /* @__PURE__ */ new Map();
|
|
8905
8905
|
for (const item of raw) {
|
|
8906
8906
|
if (item.role === "tool" && item.toolCallId && !resultsById.has(item.toolCallId)) resultsById.set(item.toolCallId, item);
|
|
8907
8907
|
}
|
|
8908
8908
|
const pairedResults = /* @__PURE__ */ new Map();
|
|
8909
|
-
const
|
|
8909
|
+
for (const item of raw) {
|
|
8910
|
+
const result = item.role === "tool_call" && item.toolCallId ? resultsById.get(item.toolCallId) : void 0;
|
|
8911
|
+
if (result && result.seq > item.seq && !pairedResults.has(result.seq)) {
|
|
8912
|
+
pairedResults.set(result.seq, item.seq);
|
|
8913
|
+
}
|
|
8914
|
+
}
|
|
8910
8915
|
const windows = rawWindows.map((current) => ({
|
|
8911
8916
|
windowId: current.windowId,
|
|
8912
8917
|
...current.createdAt ? { createdAt: current.createdAt } : {},
|
|
8913
8918
|
items: current.items.flatMap((item) => {
|
|
8914
|
-
if (
|
|
8915
|
-
if (item.role === "tool_call") {
|
|
8919
|
+
if (pairedResults.has(item.seq)) return [];
|
|
8920
|
+
if (item.role === "tool_call" || item.role === "tool") {
|
|
8916
8921
|
const result = item.toolCallId ? resultsById.get(item.toolCallId) : void 0;
|
|
8917
|
-
const paired = result && result.seq
|
|
8918
|
-
if (paired) {
|
|
8919
|
-
consumed.add(paired.seq);
|
|
8920
|
-
pairedResults.set(paired.seq, item.seq);
|
|
8921
|
-
}
|
|
8922
|
+
const paired = result && pairedResults.get(result.seq) === item.seq ? result : void 0;
|
|
8922
8923
|
return [toolEvent(item, paired)];
|
|
8923
8924
|
}
|
|
8924
|
-
if (item.role === "tool") return [toolEvent(item)];
|
|
8925
8925
|
return [{ seq: item.seq, windowId: item.windowId, role: item.role === "system" || item.role === "developer" ? "context" : item.role, text: item.text, createdAt: item.createdAt }];
|
|
8926
8926
|
})
|
|
8927
8927
|
}));
|
|
@@ -9053,6 +9053,7 @@ var NoteMetadataSchema = typebox_exports.Object({
|
|
|
9053
9053
|
origin: typebox_exports.Union([...ORIGIN_VALUES]),
|
|
9054
9054
|
created_at: typebox_exports.String(),
|
|
9055
9055
|
updated_at: typebox_exports.String(),
|
|
9056
|
+
last_accessed: typebox_exports.String(),
|
|
9056
9057
|
crumpled_at: typebox_exports.Optional(typebox_exports.String()),
|
|
9057
9058
|
project: typebox_exports.Optional(typebox_exports.String()),
|
|
9058
9059
|
extra: typebox_exports.Record(typebox_exports.String(), typebox_exports.Unknown())
|
|
@@ -9078,6 +9079,7 @@ function noteMetadata(meta) {
|
|
|
9078
9079
|
origin: meta.origin,
|
|
9079
9080
|
created_at: localIso(meta.createdAt),
|
|
9080
9081
|
updated_at: localIso(meta.updatedAt),
|
|
9082
|
+
last_accessed: localIso(meta.lastAccessed),
|
|
9081
9083
|
...typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {},
|
|
9082
9084
|
...typeof meta.project === "string" ? { project: meta.project } : {},
|
|
9083
9085
|
extra
|
|
@@ -9088,6 +9090,7 @@ function renderMetadata(metadata) {
|
|
|
9088
9090
|
`origin ${metadata.origin}`,
|
|
9089
9091
|
`created ${metadata.created_at}`,
|
|
9090
9092
|
`updated ${metadata.updated_at}`,
|
|
9093
|
+
`accessed ${metadata.last_accessed}`,
|
|
9091
9094
|
...metadata.crumpled_at === void 0 ? [] : [`crumpled ${metadata.crumpled_at}`],
|
|
9092
9095
|
...metadata.project === void 0 ? [] : [`project ${metadata.project}`]
|
|
9093
9096
|
];
|
|
@@ -9111,6 +9114,7 @@ var ListedFileSchema = typebox_exports.Object({
|
|
|
9111
9114
|
project_key: typebox_exports.Optional(typebox_exports.String()),
|
|
9112
9115
|
...ProjectReceiptSchema,
|
|
9113
9116
|
updated_at: typebox_exports.String(),
|
|
9117
|
+
last_accessed: typebox_exports.String(),
|
|
9114
9118
|
crumpled_at: typebox_exports.Optional(typebox_exports.String())
|
|
9115
9119
|
}, { additionalProperties: false });
|
|
9116
9120
|
var MatchSchema = typebox_exports.Object({
|
|
@@ -9174,7 +9178,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
9174
9178
|
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
|
|
9175
9179
|
}
|
|
9176
9180
|
function listedFile(row, identity2) {
|
|
9177
|
-
return { ...noteIdentity(identity2, row.address), updated_at: localIso(row.meta.updatedAt), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
|
|
9181
|
+
return { ...noteIdentity(identity2, row.address), updated_at: localIso(row.meta.updatedAt), last_accessed: localIso(row.meta.lastAccessed), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
|
|
9178
9182
|
}
|
|
9179
9183
|
var notesWriteParameters = typebox_exports.Object({ address: typebox_exports.String(), content: typebox_exports.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
9180
9184
|
function renderWriteData(data) {
|
|
@@ -9267,7 +9271,7 @@ var notesRead = {
|
|
|
9267
9271
|
if (!note) return failure("not_found", `No note at ${resolved.address}.`);
|
|
9268
9272
|
const totalChars = Array.from(note.body).length;
|
|
9269
9273
|
if (params.offset_chars !== void 0 && params.offset_chars > totalChars) return failure("invalid_offset", `This note ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
9270
|
-
const metadata = noteMetadata(note.meta);
|
|
9274
|
+
const metadata = noteMetadata({ ...note.meta, lastAccessed: note.accessedBefore });
|
|
9271
9275
|
return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
|
|
9272
9276
|
} catch (error) {
|
|
9273
9277
|
return failureOf(error);
|
|
@@ -9279,7 +9283,7 @@ var notesListParameters = typebox_exports.Object({ glob: GLOB_PARAMETER, limit:
|
|
|
9279
9283
|
function renderListData(data) {
|
|
9280
9284
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
9281
9285
|
for (const file of data.files) {
|
|
9282
|
-
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.crumpled_at === void 0 ? "" : ` | crumpled ${file.crumpled_at}`}`);
|
|
9286
|
+
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | accessed ${file.last_accessed}${file.crumpled_at === void 0 ? "" : ` | crumpled ${file.crumpled_at}`}`);
|
|
9283
9287
|
}
|
|
9284
9288
|
if (data.more > 0) lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
9285
9289
|
for (const home of data.homes_unavailable) lines.push(`${home} could not be read`);
|
|
@@ -9537,9 +9541,7 @@ function renderRead(data) {
|
|
|
9537
9541
|
const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...afterSeq >= 1 ? { after_seq: afterSeq } : {}, before_seq: data.seq + 10 })})`;
|
|
9538
9542
|
return [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
9539
9543
|
}
|
|
9540
|
-
|
|
9541
|
-
return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
|
|
9542
|
-
}
|
|
9544
|
+
var plainText = (text) => text;
|
|
9543
9545
|
var MAX_REPORTED_WINDOWS = 5;
|
|
9544
9546
|
function knownWindowSuffix(known) {
|
|
9545
9547
|
return known.length === 0 ? "" : `; its windows: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
|
|
@@ -9564,9 +9566,9 @@ var historyWindows = {
|
|
|
9564
9566
|
description: "List this session's context windows, oldest first, with seq ranges.",
|
|
9565
9567
|
parameters: historyWindowsParameters,
|
|
9566
9568
|
outputSchema: resultSchema(HistoryWindowsDataSchema),
|
|
9567
|
-
async execute(_params, projection, sessionId) {
|
|
9569
|
+
async execute(_params, projection, sessionId, wrapText = plainText) {
|
|
9568
9570
|
const data = { session_id: sessionId, windows: [], more: projection.windows.length };
|
|
9569
|
-
const fits = (candidate) => fitsResult(success(candidate), (result) => renderOutcome(result, renderWindows));
|
|
9571
|
+
const fits = (candidate) => fitsResult(success(candidate), (result) => wrapText(renderOutcome(result, renderWindows)));
|
|
9570
9572
|
for (const window of projection.windows) {
|
|
9571
9573
|
let first = null;
|
|
9572
9574
|
let last = null;
|
|
@@ -9606,13 +9608,14 @@ var historyList = {
|
|
|
9606
9608
|
description: "Browse or search this session's events, a page at a time. Read one in full with `history_read`.",
|
|
9607
9609
|
parameters: historyListParameters,
|
|
9608
9610
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
9609
|
-
async execute(params, projection) {
|
|
9611
|
+
async execute(params, projection, wrapText = plainText) {
|
|
9610
9612
|
const resolved = resolveWindowId(projection, params.window_id);
|
|
9611
9613
|
if (!resolved.ok) return resolved.outcome;
|
|
9612
9614
|
const scoped = { ...params, window_id: resolved.window_id };
|
|
9613
9615
|
const badWindow = badWindowId(projection, scoped);
|
|
9614
9616
|
if (badWindow) return badWindow;
|
|
9615
|
-
|
|
9617
|
+
const fits = (page) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
|
|
9618
|
+
return selectPage(projection, scoped, fits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
|
|
9616
9619
|
},
|
|
9617
9620
|
render: (result) => renderOutcome(result, renderPage)
|
|
9618
9621
|
};
|
|
@@ -9623,7 +9626,7 @@ var historyRead = {
|
|
|
9623
9626
|
description: "Read one event in full: tool arguments, output, and nested calls.",
|
|
9624
9627
|
parameters: historyReadParameters,
|
|
9625
9628
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
9626
|
-
async execute(params, projection) {
|
|
9629
|
+
async execute(params, projection, wrapText = plainText) {
|
|
9627
9630
|
const item = allItems(projection).find((event) => event.seq === params.seq);
|
|
9628
9631
|
if (item === void 0 && params.seq > projection.highestSeq) {
|
|
9629
9632
|
return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
@@ -9656,7 +9659,7 @@ var historyRead = {
|
|
|
9656
9659
|
...nestedCallSummary(item),
|
|
9657
9660
|
...window
|
|
9658
9661
|
}),
|
|
9659
|
-
(result) => renderOutcome(result, renderRead)
|
|
9662
|
+
(result) => wrapText(renderOutcome(result, renderRead))
|
|
9660
9663
|
);
|
|
9661
9664
|
},
|
|
9662
9665
|
render: (result) => renderOutcome(result, renderRead)
|
|
@@ -9779,26 +9782,32 @@ function claudeHistoryFromJsonl(text, source) {
|
|
|
9779
9782
|
nextSeq += items.length;
|
|
9780
9783
|
nodes.set(uuid, { first: version, latest: version, items });
|
|
9781
9784
|
}
|
|
9782
|
-
|
|
9785
|
+
const missingAncestors = /* @__PURE__ */ new Set();
|
|
9786
|
+
function positionOf(version) {
|
|
9783
9787
|
const chain = [], calculating = /* @__PURE__ */ new Set();
|
|
9784
9788
|
let cursor = version;
|
|
9785
|
-
|
|
9789
|
+
let before = { ordinal: 0 };
|
|
9790
|
+
while (cursor.position === void 0) {
|
|
9786
9791
|
cursor.ancestor ??= cursor.ancestorUuid === void 0 ? void 0 : nodes.get(cursor.ancestorUuid)?.first;
|
|
9787
9792
|
if (calculating.has(cursor)) throw new Error("cyclic Claude transcript ancestry");
|
|
9788
|
-
if (cursor.ancestorUuid !== void 0 && cursor.ancestor === void 0) throw new Error(`missing Claude transcript ancestor: ${cursor.ancestorUuid}`);
|
|
9789
9793
|
calculating.add(cursor);
|
|
9790
9794
|
chain.push(cursor);
|
|
9795
|
+
if (cursor.ancestorUuid !== void 0 && cursor.ancestor === void 0) {
|
|
9796
|
+
missingAncestors.add(cursor.ancestorUuid);
|
|
9797
|
+
before = { unknownAncestor: cursor.ancestorUuid };
|
|
9798
|
+
break;
|
|
9799
|
+
}
|
|
9791
9800
|
if (cursor.ancestor === void 0) break;
|
|
9792
9801
|
cursor = cursor.ancestor;
|
|
9793
9802
|
}
|
|
9794
|
-
|
|
9795
|
-
for (const
|
|
9796
|
-
const retained =
|
|
9797
|
-
const marked = bootOrdinal(
|
|
9798
|
-
|
|
9799
|
-
before =
|
|
9803
|
+
before = cursor.position ?? before;
|
|
9804
|
+
for (const current2 of chain.reverse()) {
|
|
9805
|
+
const retained = current2.row.isCompactSummary === true || current2.ancestor !== void 0 && boundary(current2.ancestor.row);
|
|
9806
|
+
const marked = bootOrdinal(current2.row, retained);
|
|
9807
|
+
current2.position = marked !== void 0 ? { ordinal: "ordinal" in before ? Math.max(before.ordinal, marked) : marked } : "ordinal" in before ? { ordinal: before.ordinal + (boundary(current2.row) ? 1 : 0) } : before;
|
|
9808
|
+
before = current2.position;
|
|
9800
9809
|
}
|
|
9801
|
-
return version.
|
|
9810
|
+
return version.position;
|
|
9802
9811
|
}
|
|
9803
9812
|
if (!source.headUuid) throw new Error("Claude history has no confirmed active head yet; wait for a main-session append after startup/resume");
|
|
9804
9813
|
if (!nodes.has(source.headUuid)) throw new Error("Claude history active head is not persisted yet; retry after the transcript write");
|
|
@@ -9817,7 +9826,10 @@ function claudeHistoryFromJsonl(text, source) {
|
|
|
9817
9826
|
visiting.add(key);
|
|
9818
9827
|
stack.push({ ...step, exit: true });
|
|
9819
9828
|
const node = nodes.get(uuid);
|
|
9820
|
-
if (!node)
|
|
9829
|
+
if (!node) {
|
|
9830
|
+
missingAncestors.add(uuid);
|
|
9831
|
+
continue;
|
|
9832
|
+
}
|
|
9821
9833
|
selected.add(uuid);
|
|
9822
9834
|
const row = (historical ? node.first : node.latest).row;
|
|
9823
9835
|
const ancestor = parent(row);
|
|
@@ -9839,20 +9851,35 @@ function claudeHistoryFromJsonl(text, source) {
|
|
|
9839
9851
|
}
|
|
9840
9852
|
}
|
|
9841
9853
|
}
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
const
|
|
9854
|
+
const current = positionOf(nodes.get(source.headUuid).latest);
|
|
9855
|
+
const windowId = (position) => `claude:${source.sessionId}:${"ordinal" in position ? position.ordinal : `unknown:${position.unknownAncestor}`}`;
|
|
9856
|
+
const windowsById = /* @__PURE__ */ new Map();
|
|
9845
9857
|
const branchSeqs = /* @__PURE__ */ new Set();
|
|
9858
|
+
let maxOrdinal = "ordinal" in current ? current.ordinal : 0;
|
|
9846
9859
|
for (const [uuid, node] of nodes) {
|
|
9847
9860
|
if (!selected.has(uuid)) continue;
|
|
9848
|
-
const
|
|
9861
|
+
const position = positionOf(node.first);
|
|
9862
|
+
if ("ordinal" in position) maxOrdinal = Math.max(maxOrdinal, position.ordinal);
|
|
9863
|
+
const id = windowId(position);
|
|
9864
|
+
let window = windowsById.get(id);
|
|
9865
|
+
if (!window) {
|
|
9866
|
+
window = { windowId: id, ..."ordinal" in position ? { ordinal: position.ordinal } : {}, items: [] };
|
|
9867
|
+
windowsById.set(id, window);
|
|
9868
|
+
}
|
|
9849
9869
|
window.createdAt ??= node.items[0]?.createdAt;
|
|
9850
9870
|
for (const item of node.items) {
|
|
9851
9871
|
branchSeqs.add(item.seq);
|
|
9852
|
-
window.items.push({ ...item, windowId:
|
|
9872
|
+
window.items.push({ ...item, windowId: id });
|
|
9873
|
+
}
|
|
9874
|
+
}
|
|
9875
|
+
if (missingAncestors.size === 0) {
|
|
9876
|
+
for (let ordinal = 0; ordinal <= maxOrdinal; ordinal++) {
|
|
9877
|
+
const id = windowId({ ordinal });
|
|
9878
|
+
if (!windowsById.has(id)) windowsById.set(id, { windowId: id, ordinal, items: [] });
|
|
9853
9879
|
}
|
|
9854
9880
|
}
|
|
9855
|
-
|
|
9881
|
+
const windows = [...windowsById.values()].sort((a, b) => a.ordinal === void 0 ? b.ordinal === void 0 ? 0 : 1 : b.ordinal === void 0 ? -1 : a.ordinal - b.ordinal);
|
|
9882
|
+
return { ...projectHistory(windows, nextSeq - 1, branchSeqs), missingAncestors: [...missingAncestors], currentWindowOrdinal: "ordinal" in current ? current.ordinal : void 0 };
|
|
9856
9883
|
}
|
|
9857
9884
|
async function readClaudeHistory(source) {
|
|
9858
9885
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string") throw new Error("Claude history transcript_path is unavailable");
|
|
@@ -10098,6 +10125,18 @@ var COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
|
|
|
10098
10125
|
// plugins/claude/src/text.ts
|
|
10099
10126
|
var CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
|
|
10100
10127
|
var CLAUDE_WARNING_PROMPT = warningNotice();
|
|
10128
|
+
var CLAUDE_HISTORY_UNKNOWN_WINDOW = "Claude history cannot determine the current window ordinal across a missing ancestor; restore the ancestry or use a retained notesoup boot to re-anchor it.";
|
|
10129
|
+
var CLAUDE_HISTORY_UNKNOWN_PREVIOUS = 'Cannot resolve "@previous": the immediately preceding window is not confirmed across the ancestry gap. Use an explicit window id from history_windows.';
|
|
10130
|
+
function claudeHistoryUnconfirmedSeq(seq) {
|
|
10131
|
+
return `Seq ${seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`;
|
|
10132
|
+
}
|
|
10133
|
+
function claudeHistoryGapNotice(missing) {
|
|
10134
|
+
if (missing.length === 0) return "";
|
|
10135
|
+
const evidence = missing.slice(0, 5).map((uuid) => JSON.stringify(uuid.length > 160 ? `${uuid.slice(0, 160)}\u2026` : uuid)).join(", ");
|
|
10136
|
+
return `Claude history is incomplete: missing ancestor UUID(s): ${evidence}${missing.length > 5 ? `; ${missing.length - 5} more` : ""}. Only confirmed selected ancestry is returned; disconnected prefixes and unrelated branches are excluded. Window IDs containing :unknown: have unconfirmed ordinal/ownership and may span native compactions; they are listed separately after numbered windows, not placed in a chronological order. A later retained boot can re-anchor window numbering, but cannot fill the history gap.
|
|
10137
|
+
|
|
10138
|
+
`;
|
|
10139
|
+
}
|
|
10101
10140
|
|
|
10102
10141
|
// src/budget/constants.ts
|
|
10103
10142
|
var WARNING_RUNWAY_TOKENS = 16384;
|
|
@@ -10245,7 +10284,6 @@ function boundOperation(operation) {
|
|
|
10245
10284
|
description: operation.description,
|
|
10246
10285
|
parameters: operation.parameters,
|
|
10247
10286
|
async call(params, ...context) {
|
|
10248
|
-
if (!Check2(operation.parameters, params)) throw new Error(`invalid ${operation.name} parameters: ${paramProblem(operation.parameters, params)}`);
|
|
10249
10287
|
const outcome = await operation.execute(params, ...context);
|
|
10250
10288
|
return { text: operation.render(outcome), ok: outcome.ok };
|
|
10251
10289
|
}
|
|
@@ -10281,17 +10319,40 @@ async function dispatch(request) {
|
|
|
10281
10319
|
if (value.op === "limits") return resolveClaudeLimits(value.facts);
|
|
10282
10320
|
if (value.op === "tool") {
|
|
10283
10321
|
if (typeof value.tool !== "string" || !Object.hasOwn(OPERATIONS, value.tool) && !Object.hasOwn(HISTORY_OPERATIONS, value.tool)) throw new Error("unknown tool");
|
|
10322
|
+
const operation = Object.hasOwn(OPERATIONS, value.tool) ? OPERATIONS[value.tool] : HISTORY_OPERATIONS[value.tool];
|
|
10323
|
+
if (!Check2(operation.parameters, value.params)) throw new Error(`invalid ${value.tool} parameters: ${paramProblem(operation.parameters, value.params)}`);
|
|
10284
10324
|
const id = identity(value.identity);
|
|
10285
10325
|
if (Object.hasOwn(HISTORY_OPERATIONS, value.tool)) {
|
|
10326
|
+
const tool = value.tool;
|
|
10286
10327
|
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
10287
|
-
|
|
10328
|
+
const notice = claudeHistoryGapNotice(projection.missingAncestors);
|
|
10329
|
+
const wrapText = (text) => notice + text;
|
|
10330
|
+
let params = value.params;
|
|
10331
|
+
if (projection.missingAncestors.length > 0) {
|
|
10332
|
+
if (params.window_id === "@previous") {
|
|
10333
|
+
const previous = projection.currentWindowOrdinal === void 0 ? void 0 : `claude:${id.sessionId}:${projection.currentWindowOrdinal - 1}`;
|
|
10334
|
+
if (!projection.windows.some((window) => window.windowId === previous)) {
|
|
10335
|
+
return { ok: false, text: wrapText(CLAUDE_HISTORY_UNKNOWN_PREVIOUS) };
|
|
10336
|
+
}
|
|
10337
|
+
params = { ...params, window_id: previous };
|
|
10338
|
+
}
|
|
10339
|
+
if (value.tool === "history_read") {
|
|
10340
|
+
const { seq } = params;
|
|
10341
|
+
if (seq <= projection.highestSeq && !projection.branchSeqs.has(seq)) {
|
|
10342
|
+
return { ok: false, text: wrapText(claudeHistoryUnconfirmedSeq(seq)) };
|
|
10343
|
+
}
|
|
10344
|
+
}
|
|
10345
|
+
}
|
|
10346
|
+
const result = tool === "history_windows" ? await HISTORY_OPERATIONS[tool].call(params, projection, id.sessionId, wrapText) : await HISTORY_OPERATIONS[tool].call(params, projection, wrapText);
|
|
10347
|
+
return { ...result, text: wrapText(result.text) };
|
|
10288
10348
|
}
|
|
10289
10349
|
return OPERATIONS[value.tool].call(value.params, id);
|
|
10290
10350
|
}
|
|
10291
10351
|
if (value.op === "history_state") {
|
|
10292
10352
|
const id = identity(value.identity);
|
|
10293
10353
|
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
10294
|
-
|
|
10354
|
+
if (projection.currentWindowOrdinal === void 0) throw new Error(CLAUDE_HISTORY_UNKNOWN_WINDOW);
|
|
10355
|
+
return { window: projection.currentWindowOrdinal };
|
|
10295
10356
|
}
|
|
10296
10357
|
if (value.op === "boot") {
|
|
10297
10358
|
const id = identity(value.identity);
|
|
@@ -4,31 +4,42 @@ I am reviewing my notes: keeping what is useful, connecting what belongs togethe
|
|
|
4
4
|
|
|
5
5
|
## Scope
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
A project dream draws from that project's material, project notes, and session notes identified as belonging to the project; it organizes only that project's notes. A store-wide dream may inspect across homes, but authorship and write permissions still apply. Unknown ownership is a coverage gap to report, not a reason to guess or repair ownership.
|
|
7
|
+
A dream covers one project: its `@project` notes and the session notes born in it. `@human`, `@self`, and `@model` are not part of a dream unless the human asks for them or the dream runs from inside the notes home itself. Do not broaden that scope while exploring; if a boundary is unclear, ask before crossing it. Unknown ownership is a coverage gap to report, not a reason to guess or repair ownership.
|
|
10
8
|
|
|
11
9
|
The homes serve different readers:
|
|
12
10
|
|
|
13
|
-
- Session notes (`<path>`, no `@`) are a trip's working record. Read them as sources
|
|
11
|
+
- Session notes (`<path>`, no `@`) are a trip's working record. Read them as sources; do not rewrite them. Only the wastebasket rule below may remove another session's notes.
|
|
14
12
|
- `@project` notes hold knowledge for whoever next works on that project.
|
|
15
13
|
- `@human` notes hold the human's cross-project preferences and standing rules. Do not turn project facts or your own conclusions into rules in the human's voice.
|
|
16
14
|
- `@self` notes belong to their author: private if the author has a name, one shared notebook for everyone nameless. Other named authors' notes are read-only unless the human authorizes revision.
|
|
17
15
|
- `@model` notes describe the substrate's behavior. Other models' notes are read-only unless the human authorizes revision.
|
|
18
16
|
|
|
17
|
+
## What a durable note holds
|
|
18
|
+
|
|
19
|
+
Durable notes hold decisions, constraints, and lessons that stay true after the current work ends. They are not diaries: commit hashes, test counts, dates, and the story of how something was reached belong to git and history. A session finding is worth promoting only when it meets this bar.
|
|
20
|
+
|
|
19
21
|
## Review and consolidate
|
|
20
22
|
|
|
21
|
-
1. **Leave stable notes alone.** Change a note to incorporate new evidence,
|
|
22
|
-
2. **Verify only what the proposed change depends on.** Before correcting or promoting a conclusion, check the relevant evidence as needed. Do not revalidate every stable note or turn dream into a source-code audit. An unavailable referent is unverified, not proof that it is dead
|
|
23
|
-
3. **
|
|
24
|
-
4. **
|
|
25
|
-
5. **
|
|
26
|
-
6. **
|
|
27
|
-
7. **Keep
|
|
28
|
-
8. **
|
|
23
|
+
1. **Leave stable notes alone.** Change a note to incorporate new evidence, fix a verified error, retire a stale claim, merge a genuine duplicate, trim diary content, or split an oversized file, not merely to shorten or rephrase it. No change is a valid outcome.
|
|
24
|
+
2. **Verify only what the proposed change depends on.** Before correcting, retiring, or promoting a conclusion, check the relevant evidence as needed. Do not revalidate every stable note or turn dream into a source-code audit. An unavailable referent is unverified, not proof that it is dead.
|
|
25
|
+
3. **Retire what is no longer true.** When evidence shows a durable note is stale, correct it in place; if nothing true remains, crumple it. Remove or fix its MAP line either way. A note's last access is a hint, not evidence: long-unread notes are candidates to check, not to crumple on sight. A read reports the access before itself, so reviewing a note does not make it look fresh.
|
|
26
|
+
4. **Merge only genuine duplicates.** Merge two notes only when they share a topic and kind (checkpoint, design, log). First carry every fact, condition, and exception unique to the absorbed note into the survivor, then crumple the absorbed note. Otherwise keep both and record any unresolved conflict.
|
|
27
|
+
5. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper home, move it there, preserving its metadata, and update both homes' maps. Do it, don't propose it. Propose only when the destination home itself is unclear.
|
|
28
|
+
6. **Preserve meaning and provenance.** Keep facts, conditions, exceptions, uncertainty, authorship, and sources. When promoting a finding, cite its source. Do not relabel agent-authored material as human-authored. If its destination or authority is unclear, propose the promotion instead.
|
|
29
|
+
7. **Keep notes manageable.** Aim below about 200 lines / 8KB per note. Split oversized notes by topic with one-line cross-links.
|
|
30
|
+
8. **Keep maps useful.** Each writable home's MAP.md may include a Cheatsheet of rules that apply in every window; keep it short, about 5 lines. The rest stays the note index: durable notes' addresses and short gists, for lookup. Preserve standing rules, add promoted notes, and drop entries that no longer hold. Maps follow the same size budget.
|
|
31
|
+
|
|
32
|
+
## Deleting
|
|
33
|
+
|
|
34
|
+
Never physically delete a live note; crumple it first. Two cases allow deleting a crumpled note:
|
|
35
|
+
|
|
36
|
+
- **Your own session's notes** may be deleted once crumpled.
|
|
37
|
+
- **The wastebasket:** any note within the dream's reach that was crumpled more than 7 days ago may be deleted, whatever its home or session. Judge by its crumpled date; if none is readable, keep it and report it.
|
|
38
|
+
|
|
39
|
+
Where notes cannot be deleted, list the doomed addresses in the report instead of blanking them.
|
|
29
40
|
|
|
30
41
|
## Report
|
|
31
42
|
|
|
32
|
-
Give a concise report grouped by home: what you inspected, changed, promoted, deleted, and left unresolved. Mention coverage gaps and partial failures. If no notes changed, say so. Distinguish actual note changes from execution or audit artifacts; do not claim success for an incomplete run.
|
|
43
|
+
Give a concise report grouped by home: what you inspected, changed, retired, promoted, deleted, and left unresolved. Mention coverage gaps and partial failures. If no notes changed, say so. Distinguish actual note changes from execution or audit artifacts; do not claim success for an incomplete run.
|
|
33
44
|
|
|
34
45
|
Put skill ideas and unresolved questions in the final message as proposals for the human, not new skill files.
|
|
@@ -10,3 +10,11 @@ Read `../../playbook.md` completely, resolving the path from this skill's direct
|
|
|
10
10
|
Dream in this agent's current session. Do not start another agent or model unless the human asks.
|
|
11
11
|
|
|
12
12
|
Work within the supplied readable and writable scope. If the scope or permission to write has not been established, ask rather than inventing it or setting up execution machinery yourself.
|
|
13
|
+
|
|
14
|
+
## Tools
|
|
15
|
+
|
|
16
|
+
Use `dream_begin`, `dream_forget`, and `dream_end` for the dream lifecycle. If any are missing from the current tool list, search for them before proceeding. If they remain unavailable, report that limitation rather than inventing a replacement backend.
|
|
17
|
+
|
|
18
|
+
- Every dream starts with `dream_begin`, before reading or editing any notes.
|
|
19
|
+
- Use `notes_*` to read and organize notes within the established scope. `dream_forget` permanently deletes a crumpled note when the playbook permits it; never delete a live note.
|
|
20
|
+
- `dream_end` closes the open dream. Close it when finished, and report any partial failures.
|
|
@@ -3,14 +3,13 @@ import { pathToFileURL } from "node:url";
|
|
|
3
3
|
import type { Static, TSchema } from "typebox";
|
|
4
4
|
import { Check, Errors } from "typebox/value";
|
|
5
5
|
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
|
|
6
|
-
import { historyList, historyRead, historyWindows } from "../../../src/tools/history.js";
|
|
6
|
+
import { historyList, historyRead, historyWindows, type HistoryTextWrapper } from "../../../src/tools/history.js";
|
|
7
7
|
import { readClaudeHistory, type ClaudeHistorySource } from "./history.js";
|
|
8
|
-
import type { HistoryProjection } from "../../../src/history/history.js";
|
|
9
8
|
import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
|
|
10
9
|
import { renderBootBlock } from "../../../src/boot/render.js";
|
|
11
10
|
import type { BootToolNames } from "../../../src/boot/text.js";
|
|
12
11
|
import { selectContinuation } from "../../../src/budget/text.js";
|
|
13
|
-
import { CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
12
|
+
import { claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_HISTORY_UNKNOWN_PREVIOUS, CLAUDE_HISTORY_UNKNOWN_WINDOW, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
14
13
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
15
14
|
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../../../src/notes/index.js";
|
|
16
15
|
import type { Operation } from "../../../src/tools/result.js";
|
|
@@ -41,7 +40,7 @@ function paramProblem(schema: TSchema, params: unknown): string {
|
|
|
41
40
|
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
/** Bind
|
|
43
|
+
/** Bind shared execution/rendering to a host context; dispatch validates parameters before calling. */
|
|
45
44
|
function boundOperation<TParams extends TSchema, TData, TContext extends readonly unknown[]>(
|
|
46
45
|
operation: Operation<TParams, TData, TContext>,
|
|
47
46
|
): BoundOperation<TContext> {
|
|
@@ -49,8 +48,6 @@ function boundOperation<TParams extends TSchema, TData, TContext extends readonl
|
|
|
49
48
|
description: operation.description,
|
|
50
49
|
parameters: operation.parameters,
|
|
51
50
|
async call(params, ...context) {
|
|
52
|
-
// Refuse before the operation can act: a rejected shape never reaches a write.
|
|
53
|
-
if (!Check(operation.parameters, params)) throw new Error(`invalid ${operation.name} parameters: ${paramProblem(operation.parameters, params)}`);
|
|
54
51
|
// The same business outcome and the same renderer as the Pi tool; only the envelope differs.
|
|
55
52
|
const outcome = await operation.execute(params as Static<TParams>, ...context);
|
|
56
53
|
return { text: operation.render(outcome), ok: outcome.ok };
|
|
@@ -66,7 +63,7 @@ const OPERATIONS: Record<string, BoundOperation<[NotesIdentity]>> = {
|
|
|
66
63
|
notes_search: boundOperation(notesSearch),
|
|
67
64
|
};
|
|
68
65
|
|
|
69
|
-
const HISTORY_OPERATIONS
|
|
66
|
+
const HISTORY_OPERATIONS = {
|
|
70
67
|
history_list: boundOperation(historyList),
|
|
71
68
|
history_read: boundOperation(historyRead),
|
|
72
69
|
history_windows: boundOperation(historyWindows),
|
|
@@ -95,17 +92,45 @@ export async function dispatch(request: unknown): Promise<unknown> {
|
|
|
95
92
|
if (value.op === "limits") return resolveClaudeLimits(value.facts);
|
|
96
93
|
if (value.op === "tool") {
|
|
97
94
|
if (typeof value.tool !== "string" || (!Object.hasOwn(OPERATIONS, value.tool) && !Object.hasOwn(HISTORY_OPERATIONS, value.tool))) throw new Error("unknown tool");
|
|
95
|
+
const operation = Object.hasOwn(OPERATIONS, value.tool) ? OPERATIONS[value.tool]! : HISTORY_OPERATIONS[value.tool as keyof typeof HISTORY_OPERATIONS];
|
|
96
|
+
// Refuse before any operation can act: a rejected shape never reaches a write.
|
|
97
|
+
if (!Check(operation.parameters, value.params)) throw new Error(`invalid ${value.tool} parameters: ${paramProblem(operation.parameters, value.params)}`);
|
|
98
98
|
const id = identity(value.identity as ClaudeIdentityInput);
|
|
99
99
|
if (Object.hasOwn(HISTORY_OPERATIONS, value.tool)) {
|
|
100
|
+
const tool = value.tool as keyof typeof HISTORY_OPERATIONS;
|
|
100
101
|
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
101
|
-
|
|
102
|
+
const notice = claudeHistoryGapNotice(projection.missingAncestors);
|
|
103
|
+
const wrapText: HistoryTextWrapper = (text) => notice + text;
|
|
104
|
+
let params = value.params;
|
|
105
|
+
if (projection.missingAncestors.length > 0) {
|
|
106
|
+
// An unknown segment is not evidence for the window before the current
|
|
107
|
+
// one. Resolve the exact ordinal, never array adjacency across a gap.
|
|
108
|
+
if ((params as { window_id?: string }).window_id === "@previous") {
|
|
109
|
+
const previous = projection.currentWindowOrdinal === undefined ? undefined : `claude:${id.sessionId}:${projection.currentWindowOrdinal - 1}`;
|
|
110
|
+
if (!projection.windows.some((window) => window.windowId === previous)) {
|
|
111
|
+
return { ok: false, text: wrapText(CLAUDE_HISTORY_UNKNOWN_PREVIOUS) };
|
|
112
|
+
}
|
|
113
|
+
params = { ...params as object, window_id: previous };
|
|
114
|
+
}
|
|
115
|
+
if (value.tool === "history_read") {
|
|
116
|
+
const { seq } = params as { seq: number };
|
|
117
|
+
if (seq <= projection.highestSeq && !projection.branchSeqs.has(seq)) {
|
|
118
|
+
return { ok: false, text: wrapText(claudeHistoryUnconfirmedSeq(seq)) };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const result = tool === "history_windows"
|
|
123
|
+
? await HISTORY_OPERATIONS[tool].call(params, projection, id.sessionId, wrapText)
|
|
124
|
+
: await HISTORY_OPERATIONS[tool].call(params, projection, wrapText);
|
|
125
|
+
return { ...result, text: wrapText(result.text) };
|
|
102
126
|
}
|
|
103
127
|
return OPERATIONS[value.tool]!.call(value.params, id);
|
|
104
128
|
}
|
|
105
129
|
if (value.op === "history_state") {
|
|
106
130
|
const id = identity(value.identity as ClaudeIdentityInput);
|
|
107
131
|
const projection = await readClaudeHistory(historySource(value.history, id.sessionId));
|
|
108
|
-
|
|
132
|
+
if (projection.currentWindowOrdinal === undefined) throw new Error(CLAUDE_HISTORY_UNKNOWN_WINDOW);
|
|
133
|
+
return { window: projection.currentWindowOrdinal };
|
|
109
134
|
}
|
|
110
135
|
if (value.op === "boot") {
|
|
111
136
|
const id = identity(value.identity as ClaudeIdentityInput);
|