notesoup 0.52.6 → 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.
@@ -1,21 +1,17 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
2
  import { BRAIN_EMPTY_KIND, BRAIN_EMPTY_TOOL, type BrainEmpty } from "../shared/brain-empty.ts";
3
+ import { isRecord, notesoupToolName, resultError, resultText } from "./tool-result.ts";
3
4
 
4
5
  type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
5
6
  type Source = Parameters<Transformer["transform"]>[0];
6
7
  type ToolCallItem = Extract<Source["item"], { type: "tool_call" }>;
7
8
 
8
- function isRecord(value: unknown): value is Record<string, unknown> {
9
- return typeof value === "object" && value !== null;
10
- }
11
-
12
- /** empty_brain answers in a plain JSON text block; there is no structured payload. */
9
+ /** Pi answers in JSON text; Claude normally returns a plain acknowledgement. */
13
10
  function resultJson(output: unknown): Record<string, unknown> | undefined {
14
- if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
15
- const part = output.content.filter(isRecord).find((block) => block.type === "text" && typeof block.text === "string");
16
- if (!part) return undefined;
11
+ const text = resultText(output);
12
+ if (text === undefined) return undefined;
17
13
  try {
18
- const parsed: unknown = JSON.parse(part.text as string);
14
+ const parsed: unknown = JSON.parse(text);
19
15
  return isRecord(parsed) ? parsed : undefined;
20
16
  } catch {
21
17
  return undefined;
@@ -27,10 +23,7 @@ function brainEmptyData(item: ToolCallItem): BrainEmpty | undefined {
27
23
  if (item.status === "running") return { status: "running" };
28
24
  const wire = resultJson(item.detail.output);
29
25
  if (wire && typeof wire.error === "string") return { status: item.status === "failed" ? "failed" : "completed", error: wire.error };
30
- if (item.status === "failed") {
31
- const hostError = isRecord(item.error) && typeof item.error.message === "string" ? item.error.message : undefined;
32
- return { status: "failed", error: hostError ?? "failed" };
33
- }
26
+ if (item.status === "failed") return { status: "failed", error: resultError(item.detail.output, item.error) };
34
27
  if (wire && typeof wire.status === "string") return { status: "completed", outcome: wire.status };
35
28
  return { status: "completed" };
36
29
  }
@@ -39,7 +32,7 @@ export const brainEmptyTransformer = {
39
32
  id: "brain-empty-source",
40
33
  query: { itemType: "tool_call" },
41
34
  transform: ({ item }: Pick<Source, "item">) => {
42
- if (item.type !== "tool_call" || item.name !== BRAIN_EMPTY_TOOL) return undefined;
35
+ if (item.type !== "tool_call" || notesoupToolName(item.name) !== BRAIN_EMPTY_TOOL) return undefined;
43
36
  const data = brainEmptyData(item);
44
37
  return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: BRAIN_EMPTY_KIND, version: 1, data }] };
45
38
  },
@@ -8,6 +8,7 @@ import {
8
8
  type NotesOp,
9
9
  type NotesOpTool,
10
10
  } from "../shared/notes-op.ts";
11
+ import { isRecord, notesoupToolName, resultError, resultText } from "./tool-result.ts";
11
12
 
12
13
  type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
13
14
  type Source = Parameters<Transformer["transform"]>[0];
@@ -19,10 +20,6 @@ const OP_BY_TOOL: Record<NotesOpTool, NotesOp["op"]> = {
19
20
  notes_update: "update",
20
21
  };
21
22
 
22
- function isRecord(value: unknown): value is Record<string, unknown> {
23
- return typeof value === "object" && value !== null;
24
- }
25
-
26
23
  function clip(text: string, maxChars: number): { text: string; truncated: boolean } {
27
24
  const chars = Array.from(text);
28
25
  return chars.length <= maxChars
@@ -30,13 +27,6 @@ function clip(text: string, maxChars: number): { text: string; truncated: boolea
30
27
  : { text: chars.slice(0, maxChars).join(""), truncated: true };
31
28
  }
32
29
 
33
- /** Prefer the structured payload; fall back to the rendered text blocks. */
34
- function resultText(output: unknown): string | undefined {
35
- if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
36
- const parts = output.content.filter(isRecord).filter((block) => block.type === "text" && typeof block.text === "string");
37
- return parts.length > 0 ? parts.map((block) => block.text as string).join("\n") : undefined;
38
- }
39
-
40
30
  function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesOp | undefined {
41
31
  const address = isRecord(input) && typeof input.address === "string" ? input.address : undefined;
42
32
  if (!address) return undefined;
@@ -45,9 +35,9 @@ function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesO
45
35
  return { op, address, status, ...(crumpled ? { crumpled } : {}) };
46
36
  }
47
37
 
48
- function notesOpData(item: ToolCallItem): NotesOp | undefined {
49
- const op = OP_BY_TOOL[item.name as NotesOpTool];
50
- if (!op || item.detail.type !== "unknown") return undefined;
38
+ function notesOpData(item: ToolCallItem, tool: NotesOpTool): NotesOp | undefined {
39
+ const op = OP_BY_TOOL[tool];
40
+ if (item.detail.type !== "unknown") return undefined;
51
41
  const { input, output } = item.detail;
52
42
  const data = baseData(item, op, input);
53
43
  if (!data) return undefined;
@@ -55,9 +45,9 @@ function notesOpData(item: ToolCallItem): NotesOp | undefined {
55
45
 
56
46
  const wire = isRecord(output) && isRecord(output.structuredContent) ? output.structuredContent : undefined;
57
47
  if (wire && typeof wire.error === "string") return { ...data, error: wire.error };
58
- if (data.status === "failed" && !wire) return { ...data, error: resultText(output) ?? "failed" };
48
+ if (data.status === "failed") return { ...data, error: resultError(output, item.error) };
59
49
  if (!wire) {
60
- // History replay reconstructs results without the structured payload; parse the rendered text.
50
+ // Pi history and Claude carry rendered text, not the structured Notesoup payload.
61
51
  const text = resultText(output);
62
52
  if (text === undefined) return data;
63
53
  if (op === "read") {
@@ -111,8 +101,10 @@ export const notesOpTransformer = {
111
101
  id: "notes-op-source",
112
102
  query: { itemType: "tool_call" },
113
103
  transform: ({ item }: Pick<Source, "item">) => {
114
- if (item.type !== "tool_call" || !NOTES_OP_TOOLS.includes(item.name as NotesOpTool)) return undefined;
115
- const data = notesOpData(item);
104
+ if (item.type !== "tool_call") return undefined;
105
+ const tool = notesoupToolName(item.name) as NotesOpTool;
106
+ if (!NOTES_OP_TOOLS.includes(tool)) return undefined;
107
+ const data = notesOpData(item, tool);
116
108
  return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: NOTES_OP_KIND, version: 1, data }] };
117
109
  },
118
110
  } satisfies Transformer;
@@ -0,0 +1,31 @@
1
+ // Paseo's Pi and Claude adapters use different tool-result envelopes.
2
+ export function isRecord(value: unknown): value is Record<string, unknown> {
3
+ return typeof value === "object" && value !== null;
4
+ }
5
+
6
+ /** Strip only Notesoup's exact MCP server prefix, never another server's. */
7
+ export function notesoupToolName(name: string): string {
8
+ const prefix = "mcp__notesoup__";
9
+ return name.startsWith(prefix) ? name.slice(prefix.length) : name;
10
+ }
11
+
12
+ function textContent(content: unknown): string | undefined {
13
+ if (typeof content === "string") return content;
14
+ if (!Array.isArray(content)) return undefined;
15
+ const parts = content.filter(isRecord).filter((block) => block.type === "text" && typeof block.text === "string");
16
+ return parts.length > 0 ? parts.map((block) => block.text as string).join("\n") : undefined;
17
+ }
18
+
19
+ /** Pi live/history: content blocks. Claude: buildToolOutput's output field. */
20
+ export function resultText(output: unknown): string | undefined {
21
+ if (!isRecord(output)) return undefined;
22
+ return textContent(output.content) ?? (typeof output.output === "string" ? output.output : undefined);
23
+ }
24
+
25
+ /** Claude failures have no output; handleToolResult preserves the raw block in error. */
26
+ export function resultError(output: unknown, error: unknown): string {
27
+ return resultText(output)
28
+ ?? (typeof error === "string" ? error : undefined)
29
+ ?? (isRecord(error) ? textContent(error.content) ?? (typeof error.message === "string" ? error.message : undefined) : undefined)
30
+ ?? "failed";
31
+ }
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { brainEmptyTransformer } from "../client/brain-empty-transformer.ts";
4
4
  import { brainEmptySchema } from "../shared/brain-empty.ts";
5
+ import { claudeEmptyCompleted, claudeEmptyFailed } from "./fixtures/claude-tool-calls.ts";
5
6
 
6
7
  function toolCall(overrides: Record<string, unknown>) {
7
8
  return {
@@ -45,7 +46,29 @@ test("a failed transport call without a payload still fails", () => {
45
46
  assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "failed", error: "boom" });
46
47
  });
47
48
 
49
+ test("Claude's plain acknowledgement completes the call without inventing a Pi rollover outcome", () => {
50
+ const result = transform(claudeEmptyCompleted);
51
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "completed" });
52
+ });
53
+
54
+ test("Claude empty_brain running and failed calls use the adapter's null output and raw error", () => {
55
+ const running = transform({ ...claudeEmptyCompleted, status: "running", detail: { ...claudeEmptyCompleted.detail, output: null } });
56
+ assert.deepEqual(brainEmptySchema.parse(running!.items[0]!.data), { status: "running" });
57
+ assert.deepEqual(brainEmptySchema.parse(transform(claudeEmptyFailed)!.items[0]!.data), {
58
+ status: "failed", error: "notesoup: only the main agent can empty this brain",
59
+ });
60
+ const blocks = transform({ ...claudeEmptyFailed, error: { ...claudeEmptyFailed.error, content: [{ type: "text", text: "notesoup: last_word must be a string" }] } });
61
+ assert.deepEqual(brainEmptySchema.parse(blocks!.items[0]!.data), { status: "failed", error: "notesoup: last_word must be a string" });
62
+ });
63
+
64
+ test("Pi failed calls still surface text-block errors when no JSON receipt exists", () => {
65
+ const result = transform({ status: "failed", detail: { type: "unknown", input: {}, output: { content: [{ type: "text", text: "io failed" }] } } });
66
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "failed", error: "io failed" });
67
+ });
68
+
48
69
  test("other tools and non-tool items stay untouched", () => {
49
- assert.equal(brainEmptyTransformer.transform({ item: toolCall({ name: "notes_read" }) as never }), undefined);
70
+ for (const name of ["notes_read", "mcp__other__empty_brain", "mcp__notesoup_extra__empty_brain", "mcp__notesoup__empty_brain_extra", "mcp__notesoup__mcp__notesoup__empty_brain"]) {
71
+ assert.equal(transform({ name }), undefined, name);
72
+ }
50
73
  assert.equal(brainEmptyTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
51
74
  });
@@ -0,0 +1,86 @@
1
+ // Source-derived timeline fixtures, not a live UI capture.
2
+ // Paseo packages/server/src/server/agent/providers/claude/agent.ts:
3
+ // handleToolUseStart -> { input, output: null }; handleToolResult/buildToolOutput
4
+ // -> { output: text } on success, null output + raw tool_result in error on failure.
5
+ // tool-call-mapper.ts / tool-call-detail-parser.ts keep Notesoup calls as "unknown".
6
+ // Receipt strings follow src/tools/notes.ts and plugins/claude/hooks/register.ts.
7
+
8
+ export const claudeReadCompleted = {
9
+ type: "tool_call",
10
+ callId: "toolu_notes_read",
11
+ name: "mcp__notesoup__notes_read",
12
+ status: "completed",
13
+ error: null,
14
+ detail: {
15
+ type: "unknown",
16
+ input: { address: "@self/foo.md" },
17
+ output: { output: "@self/foo.md\norigin self | created 2026-10-17T10:00:00+08:00 | updated 2026-10-17T10:00:00+08:00 | accessed 2026-10-17T10:00:00+08:00\n\nbody line one\nbody line two" },
18
+ },
19
+ } as const;
20
+
21
+ export const claudeWriteCompleted = {
22
+ type: "tool_call",
23
+ callId: "toolu_notes_write",
24
+ name: "mcp__notesoup__notes_write",
25
+ status: "completed",
26
+ error: null,
27
+ detail: {
28
+ type: "unknown",
29
+ input: { address: "a.md", content: "the new body" },
30
+ output: { output: "overwrote a.md (project pi-context)" },
31
+ },
32
+ } as const;
33
+
34
+ export const claudeUpdateCompleted = {
35
+ type: "tool_call",
36
+ callId: "toolu_notes_update",
37
+ name: "mcp__notesoup__notes_update",
38
+ status: "completed",
39
+ error: null,
40
+ detail: {
41
+ type: "unknown",
42
+ input: { address: "a.md", edits: [{ oldText: "old", newText: "new" }] },
43
+ output: { output: "updated a.md (project pi-context)\ndiff:\n- 1 - old\n+ 1 + new" },
44
+ },
45
+ } as const;
46
+
47
+ export const claudeReadFailed = {
48
+ type: "tool_call",
49
+ callId: "toolu_notes_read",
50
+ name: "mcp__notesoup__notes_read",
51
+ status: "failed",
52
+ error: {
53
+ type: "tool_result",
54
+ tool_use_id: "toolu_notes_read",
55
+ is_error: true,
56
+ content: [{ type: "text", text: "No note at @self/foo.md." }],
57
+ },
58
+ detail: { type: "unknown", input: { address: "@self/foo.md" }, output: null },
59
+ } as const;
60
+
61
+ export const claudeEmptyCompleted = {
62
+ type: "tool_call",
63
+ callId: "toolu_empty_brain",
64
+ name: "mcp__notesoup__empty_brain",
65
+ status: "completed",
66
+ error: null,
67
+ detail: {
68
+ type: "unknown",
69
+ input: { last_word: "bye" },
70
+ output: { output: "Brain will be emptied after this turn. End your turn now; do not call more tools or explain things to the human before the reset." },
71
+ },
72
+ } as const;
73
+
74
+ export const claudeEmptyFailed = {
75
+ type: "tool_call",
76
+ callId: "toolu_empty_brain",
77
+ name: "mcp__notesoup__empty_brain",
78
+ status: "failed",
79
+ error: {
80
+ type: "tool_result",
81
+ tool_use_id: "toolu_empty_brain",
82
+ is_error: true,
83
+ content: "notesoup: only the main agent can empty this brain",
84
+ },
85
+ detail: { type: "unknown", input: {}, output: null },
86
+ } as const;
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { notesOpTransformer } from "../client/notes-op-transformer.ts";
4
4
  import { DIFF_MAX_CHARS, PREVIEW_MAX_CHARS, READ_TEXT_MAX_CHARS, notesOpSchema } from "../shared/notes-op.ts";
5
+ import { claudeReadCompleted, claudeReadFailed, claudeUpdateCompleted, claudeWriteCompleted } from "./fixtures/claude-tool-calls.ts";
5
6
 
6
7
  function toolCall(overrides: Record<string, unknown>) {
7
8
  return {
@@ -118,12 +119,49 @@ test("history replay has no structured payload: the rendered text is parsed inst
118
119
  });
119
120
 
120
121
  test("non-notes tools, unknown shapes and missing addresses stay untouched", () => {
121
- assert.equal(notesOpTransformer.transform({ item: toolCall({ name: "bash" }) as never }), undefined);
122
+ for (const name of ["bash", "mcp__other__notes_read", "mcp__notesoup_extra__notes_write", "mcp__notesoup__notes_list", "mcp__notesoup__mcp__notesoup__notes_read"]) {
123
+ assert.equal(transform({ name }), undefined, name);
124
+ }
122
125
  assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "plain_text", text: "hi" } }) as never }), undefined);
123
126
  assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "unknown", input: {}, output: {} } }) as never }), undefined);
124
127
  assert.equal(notesOpTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
125
128
  });
126
129
 
130
+ test("Claude completed calls use the adapter's output text for read, write preview and update diff", () => {
131
+ const read = notesOpSchema.parse(transform(claudeReadCompleted)!.items[0]!.data);
132
+ assert.deepEqual(read, { op: "read", address: "@self/foo.md", status: "completed", text: "body line one\nbody line two" });
133
+ assert.deepEqual(notesOpSchema.parse(transform(claudeWriteCompleted)!.items[0]!.data), {
134
+ op: "write", address: "a.md", status: "completed", outcome: "overwrote", preview: "the new body",
135
+ });
136
+ assert.deepEqual(notesOpSchema.parse(transform(claudeUpdateCompleted)!.items[0]!.data), {
137
+ op: "update", address: "a.md", status: "completed", changeKind: "body", diff: "- 1 - old\n+ 1 + new",
138
+ });
139
+ });
140
+
141
+ test("Claude running calls render from input with null output", () => {
142
+ for (const [op, call] of [["read", claudeReadCompleted], ["write", claudeWriteCompleted], ["update", claudeUpdateCompleted]] as const) {
143
+ const running = transform({ ...call, status: "running", detail: { ...call.detail, output: null } });
144
+ assert.deepEqual(notesOpSchema.parse(running!.items[0]!.data), { op, address: call.detail.input.address, status: "running" });
145
+ }
146
+ });
147
+
148
+ test("Claude failures keep raw error content and transport messages instead of parsing them as notes", () => {
149
+ assert.deepEqual(notesOpSchema.parse(transform(claudeReadFailed)!.items[0]!.data), {
150
+ op: "read", address: "@self/foo.md", status: "failed", error: "No note at @self/foo.md.",
151
+ });
152
+ const write = transform({
153
+ ...claudeWriteCompleted, status: "failed",
154
+ detail: { ...claudeWriteCompleted.detail, output: null },
155
+ error: { type: "tool_result", tool_use_id: claudeWriteCompleted.callId, is_error: true, content: "Disk full" },
156
+ });
157
+ assert.deepEqual(notesOpSchema.parse(write!.items[0]!.data), { op: "write", address: "a.md", status: "failed", error: "Disk full" });
158
+ const update = transform({
159
+ ...claudeUpdateCompleted, status: "failed", error: { message: "MCP connection closed" },
160
+ detail: { ...claudeUpdateCompleted.detail, output: null },
161
+ });
162
+ assert.deepEqual(notesOpSchema.parse(update!.items[0]!.data), { op: "update", address: "a.md", status: "failed", error: "MCP connection closed" });
163
+ });
164
+
127
165
  function result_items(result: { items: Array<{ data: unknown }> } | undefined) {
128
166
  return result!.items.map((item) => item.data);
129
167
  }
@@ -146,28 +146,30 @@ function toolEvent(item: DecodedHistoryItem, result?: DecodedHistoryItem): Histo
146
146
 
147
147
  /** Pair results into call events; consumed result seqs are not alternate read addresses. */
148
148
  export function projectHistory(rawWindows: DecodedHistoryWindow[], highestSeq: number, branchSeqs: Set<number>): HistoryProjection {
149
- const raw = rawWindows.flatMap((current) => current.items);
149
+ // Pair in durable address order, not window presentation order. Unnumbered
150
+ // segments need not have a provable chronological order relative to each other.
151
+ const raw = rawWindows.flatMap((current) => current.items).sort((a, b) => a.seq - b.seq);
150
152
  const resultsById = new Map<string, DecodedHistoryItem>();
151
153
  for (const item of raw) {
152
154
  if (item.role === "tool" && item.toolCallId && !resultsById.has(item.toolCallId)) resultsById.set(item.toolCallId, item);
153
155
  }
154
156
  const pairedResults = new Map<number, number>();
155
- const consumed = new Set<number>();
157
+ for (const item of raw) {
158
+ const result = item.role === "tool_call" && item.toolCallId ? resultsById.get(item.toolCallId) : undefined;
159
+ if (result && result.seq > item.seq && !pairedResults.has(result.seq)) {
160
+ pairedResults.set(result.seq, item.seq);
161
+ }
162
+ }
156
163
  const windows: HistoryWindow[] = rawWindows.map((current) => ({
157
164
  windowId: current.windowId,
158
165
  ...(current.createdAt ? { createdAt: current.createdAt } : {}),
159
166
  items: current.items.flatMap((item): HistoryEvent[] => {
160
- if (consumed.has(item.seq)) return [];
161
- if (item.role === "tool_call") {
167
+ if (pairedResults.has(item.seq)) return [];
168
+ if (item.role === "tool_call" || item.role === "tool") {
162
169
  const result = item.toolCallId ? resultsById.get(item.toolCallId) : undefined;
163
- const paired = result && result.seq > item.seq && !consumed.has(result.seq) ? result : undefined;
164
- if (paired) {
165
- consumed.add(paired.seq);
166
- pairedResults.set(paired.seq, item.seq);
167
- }
170
+ const paired = result && pairedResults.get(result.seq) === item.seq ? result : undefined;
168
171
  return [toolEvent(item, paired)];
169
172
  }
170
- if (item.role === "tool") return [toolEvent(item)];
171
173
  return [{ seq: item.seq, windowId: item.windowId, role: item.role === "system" || item.role === "developer" ? "context" : item.role, text: item.text, createdAt: item.createdAt }];
172
174
  }),
173
175
  }));
@@ -80,10 +80,9 @@ function renderRead(data: HistoryReadData): string {
80
80
 
81
81
  /* ------------------------------------------------------------------ shared bounding */
82
82
 
83
- /** Include rendering and cursors in the budget, not just row contents. */
84
- function pageFits(page: HistoryPage): boolean {
85
- return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
86
- }
83
+ /** Pure host decoration, measured during selection and applied unchanged by the caller at delivery. */
84
+ export type HistoryTextWrapper = (text: string) => string;
85
+ const plainText: HistoryTextWrapper = (text) => text;
87
86
 
88
87
  // Sample known ids in the refusal message itself, never as a second listing.
89
88
  const MAX_REPORTED_WINDOWS = 5;
@@ -114,15 +113,15 @@ function badWindowId(projection: HistoryProjection, params: HistoryFilter): Outc
114
113
 
115
114
  export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
116
115
 
117
- export const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string]> = {
116
+ export const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string, HistoryTextWrapper?]> = {
118
117
  name: "history_windows",
119
118
  label: "History list windows",
120
119
  description: "List this session's context windows, oldest first, with seq ranges.",
121
120
  parameters: historyWindowsParameters,
122
121
  outputSchema: resultSchema(HistoryWindowsDataSchema),
123
- async execute(_params, projection, sessionId) {
122
+ async execute(_params, projection, sessionId, wrapText = plainText) {
124
123
  const data: HistoryWindowsData = { session_id: sessionId, windows: [], more: projection.windows.length };
125
- const fits = (candidate: HistoryWindowsData) => fitsResult(success(candidate), (result) => renderOutcome(result, renderWindows));
124
+ const fits = (candidate: HistoryWindowsData) => fitsResult(success(candidate), (result) => wrapText(renderOutcome(result, renderWindows)));
126
125
  for (const window of projection.windows) {
127
126
  let first: number | null = null;
128
127
  let last: number | null = null;
@@ -161,19 +160,21 @@ export const historyListParameters = Type.Object({
161
160
  max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` })),
162
161
  }, { additionalProperties: false });
163
162
 
164
- export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection]> = {
163
+ export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection, HistoryTextWrapper?]> = {
165
164
  name: "history_list",
166
165
  label: "History list items",
167
166
  description: "Browse or search this session's events, a page at a time. Read one in full with `history_read`.",
168
167
  parameters: historyListParameters,
169
168
  outputSchema: resultSchema(HistoryPageSchema),
170
- async execute(params, projection) {
169
+ async execute(params, projection, wrapText = plainText) {
171
170
  const resolved = resolveWindowId(projection, params.window_id);
172
171
  if (!resolved.ok) return resolved.outcome;
173
172
  const scoped = { ...params, window_id: resolved.window_id };
174
173
  const badWindow = badWindowId(projection, scoped);
175
174
  if (badWindow) return badWindow;
176
- return selectPage(projection, scoped, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
175
+ // Charge wrapped rendering and cursors, not only event previews.
176
+ const fits = (page: HistoryPage) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
177
+ return selectPage(projection, scoped, fits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
177
178
  },
178
179
  render: (result) => renderOutcome(result, renderPage),
179
180
  };
@@ -182,13 +183,13 @@ export const historyList: Operation<typeof historyListParameters, HistoryPage, [
182
183
 
183
184
  export const historyReadParameters = Type.Object({ seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
184
185
 
185
- export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection]> = {
186
+ export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection, HistoryTextWrapper?]> = {
186
187
  name: "history_read",
187
188
  label: "History read item",
188
189
  description: "Read one event in full: tool arguments, output, and nested calls.",
189
190
  parameters: historyReadParameters,
190
191
  outputSchema: resultSchema(HistoryReadDataSchema),
191
- async execute(params, projection) {
192
+ async execute(params, projection, wrapText = plainText) {
192
193
  const item = allItems(projection).find((event) => event.seq === params.seq);
193
194
  // Address checks run in one order: past the end of the file, off this branch, then
194
195
  // consumed by a pairing. Only the last two can mention what is at the address.
@@ -223,7 +224,7 @@ export const historyRead: Operation<typeof historyReadParameters, HistoryReadDat
223
224
  ...nestedCallSummary(item),
224
225
  ...window,
225
226
  }),
226
- (result) => renderOutcome(result, renderRead),
227
+ (result) => wrapText(renderOutcome(result, renderRead)),
227
228
  );
228
229
  },
229
230
  render: (result) => renderOutcome(result, renderRead),