notesoup 0.54.2 → 0.55.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.
Files changed (70) hide show
  1. package/dist/plugins/pi/budget.js +1 -1
  2. package/dist/plugins/pi/marker.d.ts +1 -1
  3. package/dist/plugins/pi/marker.js +11 -7
  4. package/dist/plugins/pi/notes/tools.js +5 -1
  5. package/dist/plugins/pi/render.d.ts +4 -1
  6. package/dist/plugins/pi/render.js +3 -7
  7. package/dist/plugins/pi/runtime.js +5 -5
  8. package/dist/plugins/pi/tool-result.d.ts +4 -2
  9. package/dist/plugins/pi/tool-result.js +5 -4
  10. package/dist/src/history/claude.d.ts +1 -1
  11. package/dist/src/history/claude.js +11 -6
  12. package/dist/src/history/codex-transcript.d.ts +2 -0
  13. package/dist/src/history/codex-transcript.js +3 -2
  14. package/dist/src/history/corpus.d.ts +2 -1
  15. package/dist/src/history/corpus.js +5 -2
  16. package/dist/src/history/history.d.ts +1 -1
  17. package/dist/src/history/history.js +1 -1
  18. package/dist/src/history/local.d.ts +2 -6
  19. package/dist/src/history/local.js +34 -2
  20. package/dist/src/history/query.d.ts +4 -2
  21. package/dist/src/history/query.js +17 -8
  22. package/dist/src/tools/history.js +17 -13
  23. package/dist/src/tools/notes.d.ts +2 -7
  24. package/dist/src/tools/notes.js +5 -26
  25. package/dist/test/boot.integration.test.js +24 -0
  26. package/dist/test/budget-settings.integration.test.js +2 -2
  27. package/dist/test/claude-history.test.js +4 -6
  28. package/dist/test/codex-history.test.js +3 -2
  29. package/dist/test/dependencies.test.js +3 -4
  30. package/dist/test/dream-tools.test.js +3 -3
  31. package/dist/test/history-corpus.test.js +238 -14
  32. package/dist/test/history.integration.test.js +9 -9
  33. package/dist/test/host-neutral.test.js +7 -9
  34. package/dist/test/marker.test.js +34 -27
  35. package/dist/test/notes.integration.test.js +8 -10
  36. package/dist/test/notes.test.js +9 -7
  37. package/dist/test/pi-render.test.js +7 -7
  38. package/dist/test/project-namespace.test.js +4 -4
  39. package/docs/claude-code-mod.md +1 -1
  40. package/docs/history-sessions.md +9 -7
  41. package/docs/skills.md +1 -1
  42. package/docs/tool-results.md +3 -3
  43. package/package.json +1 -1
  44. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  45. package/plugins/claude/dist/claude/helper.js +68 -47
  46. package/plugins/claude/skills/memory/SKILL.md +4 -2
  47. package/plugins/codex/dist/codex/notesoup.js +68 -47
  48. package/plugins/paseo/OVERVIEW.md +2 -2
  49. package/plugins/paseo/client/brain-empty-card.tsx +1 -1
  50. package/plugins/paseo/client/notes-op-card.tsx +1 -1
  51. package/plugins/paseo/client/notes-op-transformer.ts +16 -1
  52. package/plugins/paseo/client/paper-palette.ts +18 -18
  53. package/plugins/paseo/test/fixtures/claude-tool-calls.ts +1 -1
  54. package/plugins/paseo/test/notes-op.test.ts +4 -4
  55. package/plugins/paseo/test/paper-palette.test.ts +3 -3
  56. package/plugins/pi/budget.ts +1 -1
  57. package/plugins/pi/marker.ts +11 -6
  58. package/plugins/pi/notes/tools.ts +5 -1
  59. package/plugins/pi/render.ts +7 -8
  60. package/plugins/pi/runtime.ts +4 -3
  61. package/plugins/pi/tool-result.ts +10 -9
  62. package/skills/memory/SKILL.md +4 -2
  63. package/src/history/claude.ts +9 -4
  64. package/src/history/codex-transcript.ts +3 -2
  65. package/src/history/corpus.ts +9 -3
  66. package/src/history/history.ts +1 -1
  67. package/src/history/local.ts +36 -4
  68. package/src/history/query.ts +17 -6
  69. package/src/tools/history.ts +13 -12
  70. package/src/tools/notes.ts +5 -27
@@ -9189,7 +9189,6 @@ var NotesWriteDataSchema = typebox_exports.Object({
9189
9189
  var NotesUpdateDataSchema = typebox_exports.Object({
9190
9190
  ...NoteIdentitySchema,
9191
9191
  change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("moved")]),
9192
- diff: typebox_exports.String(),
9193
9192
  rename_from: typebox_exports.Optional(typebox_exports.String())
9194
9193
  }, { additionalProperties: false });
9195
9194
  var NotesReadDataSchema = typebox_exports.Object({
@@ -9260,24 +9259,7 @@ var notesUpdateParameters = typebox_exports.Object({
9260
9259
  cwd: CWD_PARAMETER
9261
9260
  }, { additionalProperties: false });
9262
9261
  function renderUpdateData(data) {
9263
- const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
9264
- const lines = [head];
9265
- if (data.diff.length > 0) lines.push("diff:", data.diff);
9266
- return lines.join("\n");
9267
- }
9268
- function renderUpdate(result) {
9269
- return renderOutcome(result, renderUpdateData);
9270
- }
9271
- var DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
9272
- var RECEIPT_TOO_LONG = `Saved, but the receipt is too long to hand back (${TOOL_OUTPUT_LIMIT} per call). Check the note with \`notes_read\`.`;
9273
- function boundedUpdate(data) {
9274
- if (fitsResult(success(data), renderUpdate)) return success(data);
9275
- if (data.diff === "") return failure("output_too_large", RECEIPT_TOO_LONG);
9276
- const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}
9277
- ${DIFF_SHORTENED_MARKER}` }), renderUpdate));
9278
- const result = success({ ...data, diff: `${diff}
9279
- ${DIFF_SHORTENED_MARKER}` });
9280
- return fitsResult(result, renderUpdate) ? result : failure("output_too_large", RECEIPT_TOO_LONG);
9262
+ return data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
9281
9263
  }
9282
9264
  var notesUpdate = {
9283
9265
  name: "notes_update",
@@ -9286,21 +9268,21 @@ var notesUpdate = {
9286
9268
  parameters: notesUpdateParameters,
9287
9269
  outputSchema: resultSchema(NotesUpdateDataSchema),
9288
9270
  executionMode: "sequential",
9289
- async execute(params, context2, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
9271
+ async execute(params, context2, onChange) {
9290
9272
  try {
9291
9273
  const identity2 = notesIdentityForCall(context2, params.cwd);
9292
9274
  const store = createNotesStore(identity2);
9293
9275
  const renameTo = params.rename_to === "" ? void 0 : params.rename_to;
9294
9276
  const { change, moved } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
9277
+ onChange?.(change);
9295
9278
  const from = noteIdentity(identity2, params.address).address;
9296
9279
  const to = noteIdentity(identity2, renameTo ?? params.address);
9297
- const diff = renderDiff(change);
9298
- return boundedUpdate({ ...to, ...moved ? { rename_from: from } : {}, change_kind: moved ? "moved" : change.kind, diff: moved ? [`rename ${from} -> ${to.address}`, diff].filter(Boolean).join("\n") : diff });
9280
+ return success({ ...to, ...moved ? { rename_from: from } : {}, change_kind: moved ? "moved" : change.kind });
9299
9281
  } catch (error) {
9300
9282
  return failureOf(error);
9301
9283
  }
9302
9284
  },
9303
- render: renderUpdate
9285
+ render: (result) => renderOutcome(result, renderUpdateData)
9304
9286
  };
9305
9287
  var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
9306
9288
  function renderReadData(data) {
@@ -9514,14 +9496,20 @@ function selectPage(projection, params, fits, maxChars) {
9514
9496
  return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
9515
9497
  }
9516
9498
  function corpusSelection(params) {
9517
- const scoped = resolveSelection(params);
9518
- if (!scoped.ok) return scoped;
9519
- if (scoped.data.query === void 0) return failure("missing_query", "Wildcard session search requires a non-empty `query`.");
9520
9499
  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.");
9521
- return scoped;
9500
+ return resolveSelection(params);
9501
+ }
9502
+ function sessionRepresentative(projection, scoped) {
9503
+ const events = filteredItems(projection, scoped, false).filter((event) => event.role !== "user" && event.role !== "assistant" || eventDocument(event) !== "");
9504
+ if (scoped.roles) return events.at(-1);
9505
+ return events.find((event) => event.role === "user") ?? events.filter((event) => event.role === "assistant").at(-1) ?? events.at(-1);
9522
9506
  }
9523
9507
  function selectCorpusPage(sessions, scoped, fits, maxChars) {
9524
- const candidates = sessions.flatMap(({ session, projection }) => prepareSelection(projection, { ...scoped, session }).candidates);
9508
+ const candidates = sessions.flatMap(({ session, projection }) => {
9509
+ if (scoped.query !== void 0) return prepareSelection(projection, { ...scoped, session }).candidates;
9510
+ const event = sessionRepresentative(projection, scoped);
9511
+ return event === void 0 ? [] : [{ session, event }];
9512
+ });
9525
9513
  const time = (event) => event.createdAt === void 0 || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
9526
9514
  candidates.sort((a, b) => time(a.event) - time(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq);
9527
9515
  return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
@@ -9591,9 +9579,11 @@ async function resolveSession(corpus, selector) {
9591
9579
  if (matches.length > 1) return failure("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
9592
9580
  return success(matches[0]);
9593
9581
  }
9594
- async function loadHistorySession(session) {
9582
+ async function loadHistorySession(session, queries) {
9595
9583
  try {
9596
- return success(await session.load());
9584
+ const data = await session.load(queries);
9585
+ if (data === void 0 && !queries?.length) throw new Error("Session returned no history");
9586
+ return success(data);
9597
9587
  } catch (error) {
9598
9588
  return failure("history_unavailable", `Cannot read session ${sessionIdentity(session)}: ${error instanceof Error ? error.message : String(error)}`);
9599
9589
  }
@@ -9657,7 +9647,7 @@ function renderRead(data) {
9657
9647
  return (data.notice ?? "") + [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
9658
9648
  }
9659
9649
  var plainText = (text) => text;
9660
- var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions (query required); history_read needs one session." }));
9650
+ var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
9661
9651
  var historyListParameters = typebox_exports.Object({
9662
9652
  session: sessionParameter,
9663
9653
  query: typebox_exports.Optional(searchQuery("(optional) Text, or a list of texts (any match). Empty text/list means no search filter; empty entries are ignored. Searches every role, tool arguments and output included; returns only hits.")),
@@ -9673,7 +9663,7 @@ var historyListParameters = typebox_exports.Object({
9673
9663
  var historyList = {
9674
9664
  name: "history_list",
9675
9665
  label: "History list items",
9676
- description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * with query to search across local harnesses. Read one in full with `history_read`.",
9666
+ description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * to browse recent sessions across local harnesses (add query to search). Read one in full with `history_read`.",
9677
9667
  parameters: historyListParameters,
9678
9668
  outputSchema: resultSchema(HistoryPageSchema),
9679
9669
  async execute(params, context2, wrapText = plainText) {
@@ -9688,13 +9678,17 @@ var historyList = {
9688
9678
  if (!scoped.ok) return scoped;
9689
9679
  if (corpus === void 0) return failure("unknown_session", "This host supplied no cross-session history corpus.");
9690
9680
  const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
9681
+ const queries = Array.isArray(scoped.data.query) ? scoped.data.query : void 0;
9682
+ if (!queries) sessions.sort((a, b) => (scoped.data.from === "oldest" ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
9691
9683
  const loaded2 = [];
9692
9684
  const notices = [];
9693
9685
  for (const session of sessions) {
9694
- const result3 = await loadHistorySession(session);
9695
- if (!result3.ok) return result3;
9686
+ const result3 = await loadHistorySession(session, queries);
9687
+ if (!result3.ok || !result3.data) continue;
9688
+ if (!queries && !sessionRepresentative(result3.data.projection, scoped.data)) continue;
9696
9689
  loaded2.push({ session: sessionIdentity(session), projection: result3.data.projection });
9697
9690
  if (result3.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result3.data.notice}`);
9691
+ if (!queries && loaded2.length >= Math.max(1, params.limit ?? 20)) break;
9698
9692
  }
9699
9693
  const notice2 = notices.length ? { notice: notices.join("") } : {};
9700
9694
  const result2 = selectCorpusPage(loaded2, scoped.data, (page) => fits({ ...page, ...notice2 }), maxChars);
@@ -9732,19 +9726,16 @@ var historyRead = {
9732
9726
  projection = loaded.data.projection;
9733
9727
  identity2 = { session: sessionIdentity(target.data), ...loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice } };
9734
9728
  }
9735
- const item = allItems(projection).find((event) => event.seq === params.seq);
9736
- if (item === void 0 && params.seq > projection.highestSeq) {
9729
+ if (params.seq > projection.highestSeq) {
9737
9730
  return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
9738
9731
  }
9739
9732
  if (!projection.branchSeqs.has(params.seq)) {
9740
9733
  if (identity2.notice) return failure("unconfirmed_seq", `Seq ${params.seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`);
9741
9734
  return failure("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
9742
9735
  }
9736
+ const targetSeq = projection.pairedResults.get(params.seq) ?? params.seq;
9737
+ const item = allItems(projection).find((event) => event.seq === targetSeq);
9743
9738
  if (item === void 0) {
9744
- const callSeq = projection.pairedResults.get(params.seq);
9745
- if (callSeq !== void 0) {
9746
- return failure("not_an_event", `Seq ${params.seq} is a tool result, shown together with its call; read seq ${callSeq} instead.`);
9747
- }
9748
9739
  return failure("unknown_seq", `Seq ${params.seq} holds nothing to read.`);
9749
9740
  }
9750
9741
  const document = eventDocument(item);
@@ -10159,7 +10150,10 @@ function claudeHistoryFromJsonl(text, source) {
10159
10150
  function offlineClaudeHead(text) {
10160
10151
  const latest = /* @__PURE__ */ new Map();
10161
10152
  for (const row of rowsOf(text)) {
10162
- if (MESSAGE_TYPES.has(row.type)) latest.set(requiredString(row.uuid, "uuid"), row);
10153
+ if (!MESSAGE_TYPES.has(row.type)) continue;
10154
+ const uuid = requiredString(row.uuid, "uuid");
10155
+ latest.delete(uuid);
10156
+ latest.set(uuid, row);
10163
10157
  }
10164
10158
  const ancestors = /* @__PURE__ */ new Set();
10165
10159
  for (const row of latest.values()) {
@@ -10182,8 +10176,10 @@ function offlineClaudeHead(text) {
10182
10176
  }
10183
10177
  }
10184
10178
  const leaves = [...latest.keys()].filter((uuid) => !ancestors.has(uuid));
10185
- if (leaves.length !== 1) throw new Error(`Offline Claude transcript has ${leaves.length} possible heads; no confirmed unique leaf (refusing to guess a selected branch)`);
10186
- return leaves[0];
10179
+ if (leaves.length === 0) throw new Error("Offline Claude transcript has 0 possible heads");
10180
+ const nonAttachments = leaves.filter((uuid) => latest.get(uuid).type !== "attachment");
10181
+ const candidates = nonAttachments.length ? nonAttachments : leaves;
10182
+ return candidates.at(-1);
10187
10183
  }
10188
10184
  async function readClaudeHistory(source) {
10189
10185
  if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string") throw new Error("Claude history transcript_path is unavailable");
@@ -10333,7 +10329,7 @@ async function referencedPath(home, rolloutId) {
10333
10329
  if (matches.length !== 1) throw new Error(`Unavailable Codex lineage: rollout ${rolloutId} has ${matches.length ? "ambiguous native files" : "no local source file"}`);
10334
10330
  return matches[0];
10335
10331
  }
10336
- async function decodedBytes(path, remaining) {
10332
+ async function readCodexTranscriptBytes(path, remaining = MAX_BYTES) {
10337
10333
  const info = await stat(path);
10338
10334
  if (!info.isFile() || info.size > remaining) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
10339
10335
  const bytes = await readFile3(path);
@@ -10352,7 +10348,7 @@ async function readCodexTranscript(source) {
10352
10348
  while (true) {
10353
10349
  if (segments.length >= MAX_SEGMENTS || seen.has(path)) throw new Error("Unavailable Codex lineage: cycle or ancestry depth limit exceeded");
10354
10350
  seen.add(path);
10355
- const bytes = await decodedBytes(path, remaining);
10351
+ const bytes = await readCodexTranscriptBytes(path, remaining);
10356
10352
  remaining -= bytes.length;
10357
10353
  const segment = segmentFromBytes(bytes, cutoff);
10358
10354
  if (segments.length === 0 && segment.meta.id !== source.threadId) throw new Error(`Codex transcript belongs to thread ${String(segment.meta.id)}, not requested threadId ${source.threadId} (session_id is root-scoped)`);
@@ -10653,6 +10649,29 @@ async function filesAt(root, depth) {
10653
10649
  }
10654
10650
  return paths;
10655
10651
  }
10652
+ var PRESENTATION = `Codex unknown arguments not recorded output nested calls complete incomplete terminal ms image audio items null
10653
+ copied subagent inference prefix omitted child-local history starts at native ordinal copied model context
10654
+ does not prove original parent event addresses compaction boundary replacement_history is an inference checkpoint
10655
+ not new conversation events opaque content omitted not recovered plaintext MCP completion without a recorded raw call
10656
+ FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
10657
+ the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
10658
+ function escapeRegExp(value) {
10659
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10660
+ }
10661
+ function mayMatch(text, queries, codex) {
10662
+ if (codex && text.includes('"history_base"')) return true;
10663
+ const unescaped = text.includes("\\u") ? text.replace(/\\+u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16))) : text;
10664
+ return queries.some((query) => {
10665
+ const tokens = query.match(/[\p{L}\p{N}_-]+/gu);
10666
+ return tokens === null || tokens.every((token) => {
10667
+ const parts = /^\d+ms$/iu.test(token) ? [token.slice(0, -2), "ms"] : [token];
10668
+ return parts.every((part) => {
10669
+ const literal = new RegExp(escapeRegExp(part), "iu");
10670
+ return literal.test(unescaped) || unescaped !== text && literal.test(text) || literal.test(PRESENTATION);
10671
+ });
10672
+ });
10673
+ });
10674
+ }
10656
10675
  async function localSessions(harness, root) {
10657
10676
  const paths = await filesAt(root, harness === "codex" ? 3 : 1);
10658
10677
  const sessions = [];
@@ -10671,9 +10690,11 @@ async function localSessions(harness, root) {
10671
10690
  harness,
10672
10691
  id: id2,
10673
10692
  modifiedAt,
10674
- async load() {
10693
+ async load(queries) {
10694
+ if (harness === "codex" && !queries?.length) return { projection: (await readCodexHistory({ threadId: id2, transcriptPath: path })).projection };
10695
+ const text = harness === "codex" ? (await readCodexTranscriptBytes(path)).toString("utf8") : await readFile4(path, "utf8");
10696
+ if (queries?.length && !mayMatch(text, queries, harness === "codex")) return void 0;
10675
10697
  if (harness === "codex") return { projection: (await readCodexHistory({ threadId: id2, transcriptPath: path })).projection };
10676
- const text = await readFile4(path, "utf8");
10677
10698
  if (harness === "pi") return { projection: piHistoryFromJsonl(text, id2) };
10678
10699
  const projection = claudeHistoryFromJsonl(text, { sessionId: id2, headUuid: offlineClaudeHead(text) });
10679
10700
  const missing = projection.missingAncestors;
@@ -44,9 +44,11 @@ For list/search, omit `glob` or use the collection alias `@default` for this ses
44
44
  - **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
45
45
  - **An earlier window**: use its seq range from the boot window tree with `history_list`'s `before_seq` / `after_seq` bounds, or search for a remembered phrase.
46
46
  - **Another session**: pass `session: "<id-or-prefix>"` or `"pi:<id>"`, `"claude:<id>"`, `"codex:<id>"`, `"dsh:<id>"`. An unqualified selector checks this harness first. If ambiguous, use a longer ID or a harness prefix; never pick a candidate blindly.
47
- - **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard requires a non-empty query; it cannot use `before_seq`/`after_seq` or `history_read`. Results cover every role unless `roles` narrows them, are chronological, and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
47
+ - **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard cannot use `before_seq`/`after_seq` or `history_read`. Query results cover every role unless `roles` narrows them, are chronological, and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
48
48
 
49
- Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. An unreadable or unsupported local transcript refuses explicitly; do not treat that as proof the remembered event never happened.
49
+ - **Recent sessions, no remembered phrase**: `history_list({ session: "*" })` returns one representative event per session, preferring its first visible user prompt, up to `limit` (default 20). Sessions are chosen newest-modified first (`from: "oldest"` reverses that), then results are sorted chronologically. Empty queries also browse. Role/time filters apply before choosing representatives; with `roles`, the latest matching event represents each session. No paging cursors.
50
+
51
+ Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. A single unreadable or unsupported local transcript refuses explicitly; wildcards skip individual sessions that cannot load. An empty result is not proof the remembered event never happened.
50
52
 
51
53
  ## Saving recovery state
52
54
 
@@ -26164,7 +26164,6 @@ var NotesWriteDataSchema = typebox_exports.Object({
26164
26164
  var NotesUpdateDataSchema = typebox_exports.Object({
26165
26165
  ...NoteIdentitySchema,
26166
26166
  change_kind: typebox_exports.Union([typebox_exports.Literal("none"), typebox_exports.Literal("body"), typebox_exports.Literal("metadata"), typebox_exports.Literal("moved")]),
26167
- diff: typebox_exports.String(),
26168
26167
  rename_from: typebox_exports.Optional(typebox_exports.String())
26169
26168
  }, { additionalProperties: false });
26170
26169
  var NotesReadDataSchema = typebox_exports.Object({
@@ -26235,24 +26234,7 @@ var notesUpdateParameters = typebox_exports.Object({
26235
26234
  cwd: CWD_PARAMETER
26236
26235
  }, { additionalProperties: false });
26237
26236
  function renderUpdateData(data) {
26238
- const head = data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
26239
- const lines = [head];
26240
- if (data.diff.length > 0) lines.push("diff:", data.diff);
26241
- return lines.join("\n");
26242
- }
26243
- function renderUpdate(result) {
26244
- return renderOutcome(result, renderUpdateData);
26245
- }
26246
- var DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
26247
- var RECEIPT_TOO_LONG = `Saved, but the receipt is too long to hand back (${TOOL_OUTPUT_LIMIT} per call). Check the note with \`notes_read\`.`;
26248
- function boundedUpdate(data) {
26249
- if (fitsResult(success(data), renderUpdate)) return success(data);
26250
- if (data.diff === "") return failure2("output_too_large", RECEIPT_TOO_LONG);
26251
- const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}
26252
- ${DIFF_SHORTENED_MARKER}` }), renderUpdate));
26253
- const result = success({ ...data, diff: `${diff}
26254
- ${DIFF_SHORTENED_MARKER}` });
26255
- return fitsResult(result, renderUpdate) ? result : failure2("output_too_large", RECEIPT_TOO_LONG);
26237
+ return data.rename_from === void 0 ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}` : `moved ${data.rename_from} -> ${data.address}`;
26256
26238
  }
26257
26239
  var notesUpdate = {
26258
26240
  name: "notes_update",
@@ -26261,21 +26243,21 @@ var notesUpdate = {
26261
26243
  parameters: notesUpdateParameters,
26262
26244
  outputSchema: resultSchema(NotesUpdateDataSchema),
26263
26245
  executionMode: "sequential",
26264
- async execute(params, context2, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
26246
+ async execute(params, context2, onChange) {
26265
26247
  try {
26266
26248
  const identity = notesIdentityForCall(context2, params.cwd);
26267
26249
  const store = createNotesStore(identity);
26268
26250
  const renameTo = params.rename_to === "" ? void 0 : params.rename_to;
26269
26251
  const { change, moved } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
26252
+ onChange?.(change);
26270
26253
  const from = noteIdentity(identity, params.address).address;
26271
26254
  const to = noteIdentity(identity, renameTo ?? params.address);
26272
- const diff = renderDiff(change);
26273
- return boundedUpdate({ ...to, ...moved ? { rename_from: from } : {}, change_kind: moved ? "moved" : change.kind, diff: moved ? [`rename ${from} -> ${to.address}`, diff].filter(Boolean).join("\n") : diff });
26255
+ return success({ ...to, ...moved ? { rename_from: from } : {}, change_kind: moved ? "moved" : change.kind });
26274
26256
  } catch (error2) {
26275
26257
  return failureOf(error2);
26276
26258
  }
26277
26259
  },
26278
- render: renderUpdate
26260
+ render: (result) => renderOutcome(result, renderUpdateData)
26279
26261
  };
26280
26262
  var notesReadParameters = typebox_exports.Object({ address: typebox_exports.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
26281
26263
  function renderReadData(data) {
@@ -26489,14 +26471,20 @@ function selectPage(projection, params, fits, maxChars) {
26489
26471
  return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
26490
26472
  }
26491
26473
  function corpusSelection(params) {
26492
- const scoped = resolveSelection(params);
26493
- if (!scoped.ok) return scoped;
26494
- if (scoped.data.query === void 0) return failure2("missing_query", "Wildcard session search requires a non-empty `query`.");
26495
26474
  if (params.before_seq !== void 0 || params.after_seq !== void 0) return failure2("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
26496
- return scoped;
26475
+ return resolveSelection(params);
26476
+ }
26477
+ function sessionRepresentative(projection, scoped) {
26478
+ const events = filteredItems(projection, scoped, false).filter((event) => event.role !== "user" && event.role !== "assistant" || eventDocument(event) !== "");
26479
+ if (scoped.roles) return events.at(-1);
26480
+ return events.find((event) => event.role === "user") ?? events.filter((event) => event.role === "assistant").at(-1) ?? events.at(-1);
26497
26481
  }
26498
26482
  function selectCorpusPage(sessions, scoped, fits, maxChars) {
26499
- const candidates = sessions.flatMap(({ session, projection }) => prepareSelection(projection, { ...scoped, session }).candidates);
26483
+ const candidates = sessions.flatMap(({ session, projection }) => {
26484
+ if (scoped.query !== void 0) return prepareSelection(projection, { ...scoped, session }).candidates;
26485
+ const event = sessionRepresentative(projection, scoped);
26486
+ return event === void 0 ? [] : [{ session, event }];
26487
+ });
26500
26488
  const time3 = (event) => event.createdAt === void 0 || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
26501
26489
  candidates.sort((a, b) => time3(a.event) - time3(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq);
26502
26490
  return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
@@ -26566,9 +26554,11 @@ async function resolveSession(corpus, selector) {
26566
26554
  if (matches.length > 1) return failure2("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
26567
26555
  return success(matches[0]);
26568
26556
  }
26569
- async function loadHistorySession(session) {
26557
+ async function loadHistorySession(session, queries) {
26570
26558
  try {
26571
- return success(await session.load());
26559
+ const data = await session.load(queries);
26560
+ if (data === void 0 && !queries?.length) throw new Error("Session returned no history");
26561
+ return success(data);
26572
26562
  } catch (error2) {
26573
26563
  return failure2("history_unavailable", `Cannot read session ${sessionIdentity(session)}: ${error2 instanceof Error ? error2.message : String(error2)}`);
26574
26564
  }
@@ -26632,7 +26622,7 @@ function renderRead(data) {
26632
26622
  return (data.notice ?? "") + [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
26633
26623
  }
26634
26624
  var plainText = (text2) => text2;
26635
- var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions (query required); history_read needs one session." }));
26625
+ var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
26636
26626
  var historyListParameters = typebox_exports.Object({
26637
26627
  session: sessionParameter,
26638
26628
  query: typebox_exports.Optional(searchQuery("(optional) Text, or a list of texts (any match). Empty text/list means no search filter; empty entries are ignored. Searches every role, tool arguments and output included; returns only hits.")),
@@ -26648,7 +26638,7 @@ var historyListParameters = typebox_exports.Object({
26648
26638
  var historyList = {
26649
26639
  name: "history_list",
26650
26640
  label: "History list items",
26651
- description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * with query to search across local harnesses. Read one in full with `history_read`.",
26641
+ description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * to browse recent sessions across local harnesses (add query to search). Read one in full with `history_read`.",
26652
26642
  parameters: historyListParameters,
26653
26643
  outputSchema: resultSchema(HistoryPageSchema),
26654
26644
  async execute(params, context2, wrapText = plainText) {
@@ -26663,13 +26653,17 @@ var historyList = {
26663
26653
  if (!scoped.ok) return scoped;
26664
26654
  if (corpus === void 0) return failure2("unknown_session", "This host supplied no cross-session history corpus.");
26665
26655
  const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
26656
+ const queries = Array.isArray(scoped.data.query) ? scoped.data.query : void 0;
26657
+ if (!queries) sessions.sort((a, b) => (scoped.data.from === "oldest" ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
26666
26658
  const loaded2 = [];
26667
26659
  const notices = [];
26668
26660
  for (const session of sessions) {
26669
- const result3 = await loadHistorySession(session);
26670
- if (!result3.ok) return result3;
26661
+ const result3 = await loadHistorySession(session, queries);
26662
+ if (!result3.ok || !result3.data) continue;
26663
+ if (!queries && !sessionRepresentative(result3.data.projection, scoped.data)) continue;
26671
26664
  loaded2.push({ session: sessionIdentity(session), projection: result3.data.projection });
26672
26665
  if (result3.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result3.data.notice}`);
26666
+ if (!queries && loaded2.length >= Math.max(1, params.limit ?? 20)) break;
26673
26667
  }
26674
26668
  const notice2 = notices.length ? { notice: notices.join("") } : {};
26675
26669
  const result2 = selectCorpusPage(loaded2, scoped.data, (page) => fits({ ...page, ...notice2 }), maxChars);
@@ -26707,19 +26701,16 @@ var historyRead = {
26707
26701
  projection = loaded.data.projection;
26708
26702
  identity = { session: sessionIdentity(target.data), ...loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice } };
26709
26703
  }
26710
- const item = allItems(projection).find((event) => event.seq === params.seq);
26711
- if (item === void 0 && params.seq > projection.highestSeq) {
26704
+ if (params.seq > projection.highestSeq) {
26712
26705
  return failure2("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
26713
26706
  }
26714
26707
  if (!projection.branchSeqs.has(params.seq)) {
26715
26708
  if (identity.notice) return failure2("unconfirmed_seq", `Seq ${params.seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`);
26716
26709
  return failure2("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
26717
26710
  }
26711
+ const targetSeq = projection.pairedResults.get(params.seq) ?? params.seq;
26712
+ const item = allItems(projection).find((event) => event.seq === targetSeq);
26718
26713
  if (item === void 0) {
26719
- const callSeq = projection.pairedResults.get(params.seq);
26720
- if (callSeq !== void 0) {
26721
- return failure2("not_an_event", `Seq ${params.seq} is a tool result, shown together with its call; read seq ${callSeq} instead.`);
26722
- }
26723
26714
  return failure2("unknown_seq", `Seq ${params.seq} holds nothing to read.`);
26724
26715
  }
26725
26716
  const document = eventDocument(item);
@@ -27008,7 +26999,7 @@ async function referencedPath(home, rolloutId) {
27008
26999
  if (matches.length !== 1) throw new Error(`Unavailable Codex lineage: rollout ${rolloutId} has ${matches.length ? "ambiguous native files" : "no local source file"}`);
27009
27000
  return matches[0];
27010
27001
  }
27011
- async function decodedBytes(path, remaining) {
27002
+ async function readCodexTranscriptBytes(path, remaining = MAX_BYTES) {
27012
27003
  const info = await stat(path);
27013
27004
  if (!info.isFile() || info.size > remaining) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
27014
27005
  const bytes = await readFile3(path);
@@ -27027,7 +27018,7 @@ async function readCodexTranscript(source) {
27027
27018
  while (true) {
27028
27019
  if (segments.length >= MAX_SEGMENTS || seen.has(path)) throw new Error("Unavailable Codex lineage: cycle or ancestry depth limit exceeded");
27029
27020
  seen.add(path);
27030
- const bytes = await decodedBytes(path, remaining);
27021
+ const bytes = await readCodexTranscriptBytes(path, remaining);
27031
27022
  remaining -= bytes.length;
27032
27023
  const segment = segmentFromBytes(bytes, cutoff);
27033
27024
  if (segments.length === 0 && segment.meta.id !== source.threadId) throw new Error(`Codex transcript belongs to thread ${String(segment.meta.id)}, not requested threadId ${source.threadId} (session_id is root-scoped)`);
@@ -27689,7 +27680,10 @@ function claudeHistoryFromJsonl(text2, source) {
27689
27680
  function offlineClaudeHead(text2) {
27690
27681
  const latest = /* @__PURE__ */ new Map();
27691
27682
  for (const row of rowsOf(text2)) {
27692
- if (MESSAGE_TYPES.has(row.type)) latest.set(requiredString(row.uuid, "uuid"), row);
27683
+ if (!MESSAGE_TYPES.has(row.type)) continue;
27684
+ const uuid2 = requiredString(row.uuid, "uuid");
27685
+ latest.delete(uuid2);
27686
+ latest.set(uuid2, row);
27693
27687
  }
27694
27688
  const ancestors = /* @__PURE__ */ new Set();
27695
27689
  for (const row of latest.values()) {
@@ -27712,8 +27706,10 @@ function offlineClaudeHead(text2) {
27712
27706
  }
27713
27707
  }
27714
27708
  const leaves = [...latest.keys()].filter((uuid2) => !ancestors.has(uuid2));
27715
- if (leaves.length !== 1) throw new Error(`Offline Claude transcript has ${leaves.length} possible heads; no confirmed unique leaf (refusing to guess a selected branch)`);
27716
- return leaves[0];
27709
+ if (leaves.length === 0) throw new Error("Offline Claude transcript has 0 possible heads");
27710
+ const nonAttachments = leaves.filter((uuid2) => latest.get(uuid2).type !== "attachment");
27711
+ const candidates = nonAttachments.length ? nonAttachments : leaves;
27712
+ return candidates.at(-1);
27717
27713
  }
27718
27714
 
27719
27715
  // src/history/local.ts
@@ -27742,6 +27738,29 @@ async function filesAt(root, depth) {
27742
27738
  }
27743
27739
  return paths;
27744
27740
  }
27741
+ var PRESENTATION = `Codex unknown arguments not recorded output nested calls complete incomplete terminal ms image audio items null
27742
+ copied subagent inference prefix omitted child-local history starts at native ordinal copied model context
27743
+ does not prove original parent event addresses compaction boundary replacement_history is an inference checkpoint
27744
+ not new conversation events opaque content omitted not recovered plaintext MCP completion without a recorded raw call
27745
+ FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
27746
+ the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
27747
+ function escapeRegExp(value) {
27748
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27749
+ }
27750
+ function mayMatch(text2, queries, codex) {
27751
+ if (codex && text2.includes('"history_base"')) return true;
27752
+ const unescaped = text2.includes("\\u") ? text2.replace(/\\+u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16))) : text2;
27753
+ return queries.some((query) => {
27754
+ const tokens = query.match(/[\p{L}\p{N}_-]+/gu);
27755
+ return tokens === null || tokens.every((token) => {
27756
+ const parts = /^\d+ms$/iu.test(token) ? [token.slice(0, -2), "ms"] : [token];
27757
+ return parts.every((part) => {
27758
+ const literal2 = new RegExp(escapeRegExp(part), "iu");
27759
+ return literal2.test(unescaped) || unescaped !== text2 && literal2.test(text2) || literal2.test(PRESENTATION);
27760
+ });
27761
+ });
27762
+ });
27763
+ }
27745
27764
  async function localSessions(harness, root) {
27746
27765
  const paths = await filesAt(root, harness === "codex" ? 3 : 1);
27747
27766
  const sessions = [];
@@ -27760,9 +27779,11 @@ async function localSessions(harness, root) {
27760
27779
  harness,
27761
27780
  id: id2,
27762
27781
  modifiedAt,
27763
- async load() {
27782
+ async load(queries) {
27783
+ if (harness === "codex" && !queries?.length) return { projection: (await readCodexHistory({ threadId: id2, transcriptPath: path })).projection };
27784
+ const text2 = harness === "codex" ? (await readCodexTranscriptBytes(path)).toString("utf8") : await readFile4(path, "utf8");
27785
+ if (queries?.length && !mayMatch(text2, queries, harness === "codex")) return void 0;
27764
27786
  if (harness === "codex") return { projection: (await readCodexHistory({ threadId: id2, transcriptPath: path })).projection };
27765
- const text2 = await readFile4(path, "utf8");
27766
27787
  if (harness === "pi") return { projection: piHistoryFromJsonl(text2, id2) };
27767
27788
  const projection = claudeHistoryFromJsonl(text2, { sessionId: id2, headUuid: offlineClaudeHead(text2) });
27768
27789
  const missing = projection.missingAncestors;
@@ -4,9 +4,9 @@ Displays notesoup last-word messages already present in Paseo’s timeline as ex
4
4
 
5
5
  This client-only plugin transforms existing timeline rows in place: last-word custom messages become sticky cards, and notes_read/notes_write/notes_update tool calls become paper cards with the address, state, and a content or diff preview. It accepts the bare Pi tool names and Claude's exact `mcp__notesoup__` prefix; same-named tools from other MCP servers are unchanged. It does not read session files or append messages. Other timeline items are unchanged.
6
6
 
7
- Notes cards start collapsed; update cards also show the sentence just added. The whole header row expands and collapses the body. Long content scrolls inside a bounded panel. Read text and diffs come from the existing tool-result text; writes come from the call's content argument. Live and history use the same projection without a persisted copy. Each displayed body/diff is capped at 32,000 UTF-16 units, retaining the beginning and end with a visible omission line; collapsed previews are capped at 1,000 units before layout. Expanding does not fetch more content; original tool results and notes are unchanged. Diff lines of the same color share a text run rather than one component per line.
7
+ Notes cards start collapsed; update cards also show the sentence just added. The whole header row expands and collapses the body. Long content scrolls inside a bounded panel. Read text comes from the existing tool-result text, update diffs come from Pi's `details.diff` (falling back to legacy diff text or `input.edits` on MCP hosts), and writes come from the call's content argument. Live and history use the same projection without a persisted copy. Each displayed body/diff is capped at 32,000 UTF-16 units, retaining the beginning and end with a visible omission line; collapsed previews are capped at 1,000 units before layout. Expanding does not fetch more content; original tool results and notes are unchanged. Diff lines of the same color share a text run rather than one component per line.
8
8
 
9
- Notes cards use the same rendered-text parser for Pi live events and replayed history; Claude supplies that text under the adapter's `output` field. Write previews come from the call arguments. The UI does not depend on Pi's live-only `structuredContent`. Failed calls also read the adapter's error content (string or text blocks) or transport message when no result is available.
9
+ Notes cards use the same projection for Pi live events and replayed history; Claude supplies its receipt text under the adapter's `output` field and its edits under `input.edits`. The UI does not depend on Pi's live-only `structuredContent`. Failed calls also read the adapter's error content (string or text blocks) or transport message when no result is available.
10
10
 
11
11
  `empty_brain` (including `mcp__notesoup__empty_brain`) becomes a divider for running, completed and failed calls. Pi's JSON rollover outcomes are preserved. Claude's plain acknowledgement only completes the tool call; it does not invent a Pi outcome or assert that the deferred reset has committed.
12
12
 
@@ -6,7 +6,7 @@ function label(data: BrainEmpty): string {
6
6
  if (data.status === "running") return "✂ emptying brain …";
7
7
  if (data.error !== undefined) return "✂ brain refused to empty";
8
8
  if (data.outcome === "rollover_already_pending") return "✂ already emptying";
9
- if (data.outcome === "rollover_requested") return "✂ reset requested";
9
+ if (data.outcome === "rollover_requested") return "✂ brain emptied";
10
10
  // A completed tool call (including Claude's acknowledgement) does not prove a reset committed.
11
11
  return "✂ empty_brain completed";
12
12
  }
@@ -12,7 +12,7 @@ const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "reading", write
12
12
 
13
13
  /** First added line of an update diff, without its line-number prefix: the sentence the agent just wrote down. */
14
14
  function addedLine(diff: string): string | undefined {
15
- return /^\+.*/m.exec(diff)?.[0].replace(/^\+\s*\d+\s+\+\s?/, "");
15
+ return /^\+.*/m.exec(diff)?.[0].replace(/^\+(?:\s*\d+\s+\+|\s*\d+)?\s?/, "");
16
16
  }
17
17
 
18
18
  function DiffBody({ diff, paper }: { diff: string; paper: PaperPalette }) {
@@ -18,6 +18,17 @@ const OP_BY_TOOL: Record<NotesOpTool, NotesOp["op"]> = {
18
18
  notes_update: "update",
19
19
  };
20
20
 
21
+ function editsDiff(input: unknown): string | undefined {
22
+ if (!isRecord(input) || !Array.isArray(input.edits)) return undefined;
23
+ const lines: string[] = [];
24
+ for (const edit of input.edits) {
25
+ if (!isRecord(edit) || typeof edit.oldText !== "string" || typeof edit.newText !== "string" || edit.oldText === edit.newText) continue;
26
+ for (const line of edit.oldText.split("\n")) lines.push(`- ${line}`);
27
+ for (const line of edit.newText.split("\n")) lines.push(`+ ${line}`);
28
+ }
29
+ return lines.length > 0 ? lines.join("\n") : undefined;
30
+ }
31
+
21
32
  function notesOpData(item: ToolCallItem, tool: NotesOpTool): NotesOp | undefined {
22
33
  const op = OP_BY_TOOL[tool];
23
34
  if (item.detail.type !== "unknown") return undefined;
@@ -38,11 +49,15 @@ function notesOpData(item: ToolCallItem, tool: NotesOpTool): NotesOp | undefined
38
49
  const text = resultText(output);
39
50
  if (text === undefined) return data;
40
51
  if (op === "read") return { ...data, text: outputPreview(text.split("\n").slice(2).join("\n").replace(/^\n/, "")) };
52
+ const detailsDiff = isRecord(output) && isRecord(output.details) && typeof output.details.diff === "string" && output.details.diff.length > 0
53
+ ? output.details.diff
54
+ : undefined;
41
55
  const diffStart = text.indexOf("\ndiff:\n");
56
+ const rawDiff = detailsDiff ?? (diffStart >= 0 ? text.slice(diffStart + 7) : text.startsWith("unchanged ") ? undefined : editsDiff(input));
42
57
  return {
43
58
  ...data,
44
59
  ...(text.startsWith("moved ") && isRecord(input) && typeof input.rename_to === "string" ? { renamedFrom: data.address, address: input.rename_to } : {}),
45
- ...(diffStart >= 0 ? { diff: outputPreview(text.slice(diffStart + 7)) } : {}),
60
+ ...(rawDiff !== undefined ? { diff: outputPreview(rawDiff) } : {}),
46
61
  };
47
62
  }
48
63