pi-posthorse 0.10.32 → 0.10.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-posthorse",
3
- "version": "0.10.32",
3
+ "version": "0.10.34",
4
4
  "type": "module",
5
5
  "description": "Posthorse: fresh context, same journey. No-summary context rollover for Pi, with sparse budget reminders, handoffs, notes, and history.",
6
6
  "keywords": [
@@ -72,9 +72,9 @@
72
72
  "@earendil-works/pi-tui": "1.5.2",
73
73
  "@types/node": "24.19.1",
74
74
  "oxc-parser": "0.157.0",
75
- "oxfmt": "0.76.0",
76
- "oxlint": "1.91.0",
77
- "oxlint-tsgolint": "7.0.2005",
75
+ "oxfmt": "0.79.0",
76
+ "oxlint": "1.94.0",
77
+ "tsrs": "7.1.0-beta.tsrs2",
78
78
  "typebox": "1.3.27",
79
79
  "typescript": "7.0.2",
80
80
  "yaml": "2.9.1"
@@ -58,14 +58,17 @@ export function registerContextTools(
58
58
  description:
59
59
  "Optionally request a deliberate clean context reset once the current foreground tools succeed; retains no prior messages, unlike automatic rollover. Not required after a notes reminder. Background work continues. Earlier conversation stays recoverable through history. Put continuation state in handoff, or save fuller state in notes first.",
60
60
  promptSnippet: "optionally request a clean context reset with an optional handoff",
61
- parameters: Type.Object({
62
- handoff: Type.Optional(
63
- Type.String({
64
- description: "What the fresh window needs to continue, as readable prose",
65
- maxLength: MAX_HANDOFF_CHARS,
66
- }),
67
- ),
68
- }),
61
+ parameters: Type.Object(
62
+ {
63
+ handoff: Type.Optional(
64
+ Type.String({
65
+ description: "What the fresh window needs to continue, as readable prose",
66
+ maxLength: MAX_HANDOFF_CHARS,
67
+ }),
68
+ ),
69
+ },
70
+ { additionalProperties: false },
71
+ ),
69
72
  async execute(...[id, { handoff }, , , ctx]) {
70
73
  const trimmed = handoff?.trim();
71
74
  const limit = freshPayloadChars(policy(ctx), activeToolTokens());
@@ -8,7 +8,7 @@ import {
8
8
  import { textResult, type TextResult } from "./ui/display.ts";
9
9
  import { excerpt, shortKey, sourceTag } from "./message-text.ts";
10
10
  import { cursorFor as cursorAt } from "./history-cursor.ts";
11
- import type { HistoryMatches, HistoryParams } from "./history-search.ts";
11
+ import { MAX_SEARCH_LIMIT, type HistoryMatches, type HistoryParams } from "./history-search.ts";
12
12
  import type { PageAccess } from "./paging.ts";
13
13
 
14
14
  type Continuation<Position> =
@@ -114,22 +114,22 @@ export function searchPage(
114
114
  function readOffsets(
115
115
  item: WindowedEntry,
116
116
  params: HistoryParams,
117
- ): { readonly offset: number; readonly imageOffset: number } {
117
+ shownId: string,
118
+ ): { readonly offset: number; readonly imageOffset: number } | string {
118
119
  const offset = params.offset ?? 0;
119
120
  const imageOffset = params.imageOffset ?? (offset === 0 ? 0 : item.images.length);
120
- const id = params.id ?? "";
121
+ const restart =
122
+ item.images.length > 0
123
+ ? "Restart with offset 0 and imageOffset 0."
124
+ : "Restart with offset 0.";
121
125
  if (imageOffset > item.images.length) {
122
- throw new Error(
123
- `Image offset ${imageOffset} is past the end of history entry "${id}" (${item.images.length} images).`,
124
- );
126
+ return `Image offset ${imageOffset} is past the end of history entry "${shownId}" (${item.images.length} images). ${restart}`;
125
127
  }
126
128
  if (
127
129
  offset > item.text.length ||
128
130
  (offset === item.text.length && imageOffset === item.images.length)
129
131
  ) {
130
- throw new Error(
131
- `Offset ${offset} is past the end of history entry "${id}" (${item.text.length} chars).`,
132
- );
132
+ return `Offset ${offset} is past the end of history entry "${shownId}" (${item.text.length} chars). ${restart}`;
133
133
  }
134
134
  return { offset, imageOffset };
135
135
  }
@@ -143,7 +143,11 @@ export function historyReadPage(
143
143
  source = "",
144
144
  ): TextResult {
145
145
  const shownId = shownEntryId(item, params.id, source);
146
- const { offset, imageOffset } = readOffsets(item, params);
146
+ const offsets = readOffsets(item, params, shownId);
147
+ if (typeof offsets === "string") {
148
+ return access.pages.deliver(access.host, {}, () => textResult(offsets));
149
+ }
150
+ const { offset, imageOffset } = offsets;
147
151
  const firstImage = imageOffset < item.images.length ? 1 : 0;
148
152
  return access.pages.deliver(access.host, { imageCount: firstImage }, (chars) => {
149
153
  const imageEnd = Math.min(
@@ -166,8 +170,12 @@ export function historyReadPage(
166
170
  continuation.kind === "more"
167
171
  ? `\nMore remains; call history read with id "${shownId}" and offset ${continuation.next.offset}${item.images.length > 0 ? ` and imageOffset ${continuation.next.imageOffset}` : ""}.`
168
172
  : "";
173
+ const limitHint =
174
+ (params.limit ?? 0) > MAX_SEARCH_LIMIT
175
+ ? "\n[Omit limit for history read. It sets the search result count, not the read page size.]"
176
+ : "";
169
177
  const header = `${item.entry.timestamp ?? ""}${sourceTag(source)} [window ${item.windowId}] [${shownId}] [chars ${offset}-${end} of ${item.text.length}] `;
170
- return textResult(`${header}${item.text.slice(offset, end)}${more}`, images, {
178
+ return textResult(`${header}${item.text.slice(offset, end)}${more}${limitHint}`, images, {
171
179
  kind: "history-read",
172
180
  headerLength: header.length,
173
181
  offset,
@@ -19,41 +19,54 @@ import {
19
19
  sessionWindowEntries,
20
20
  } from "./session-files.ts";
21
21
 
22
- export const historyParameters = Type.Object({
23
- op: Type.Enum(["search", "read"], {
24
- type: "string",
25
- description: "Operation to perform",
26
- }),
27
- query: Type.Optional(Type.String({ description: "Case-insensitive text to find (search)" })),
28
- id: Type.Optional(Type.String({ description: "Entry id exactly as search printed it (read)" })),
29
- all: Type.Optional(
30
- Type.Boolean({
31
- description: "Also search this project's other sessions and subagent runs",
32
- }),
33
- ),
34
- limit: Type.Optional(
35
- Type.Integer({
36
- description: "Maximum search results per page (default 10, max 50)",
37
- minimum: 1,
38
- maximum: 50,
39
- }),
40
- ),
41
- cursor: Type.Optional(
42
- Type.String({
43
- description: "Continuation from the previous search page; keep query and all unchanged",
44
- maxLength: 512,
45
- }),
46
- ),
47
- offset: Type.Optional(
48
- Type.Integer({ description: "Character offset for read (default 0)", minimum: 0 }),
49
- ),
50
- imageOffset: Type.Optional(
51
- Type.Integer({
52
- description: "First image to return (read); use the value from the continuation",
53
- minimum: 0,
22
+ const DEFAULT_SEARCH_LIMIT = 10;
23
+ export const MAX_SEARCH_LIMIT = 50;
24
+
25
+ export const historyParameters = Type.Object(
26
+ {
27
+ op: Type.Enum(["search", "read"], {
28
+ type: "string",
29
+ description: "Operation to perform",
54
30
  }),
55
- ),
56
- });
31
+ query: Type.Optional(
32
+ Type.String({ description: "Case-insensitive text to find (search)" }),
33
+ ),
34
+ id: Type.Optional(
35
+ Type.String({ description: "Entry id exactly as search printed it (read)" }),
36
+ ),
37
+ all: Type.Optional(
38
+ Type.Boolean({
39
+ description: "Also search this project's other sessions and subagent runs",
40
+ }),
41
+ ),
42
+ limit: Type.Optional(
43
+ Type.Integer({
44
+ description: `Search only: maximum results per page (1–${MAX_SEARCH_LIMIT}, default ${DEFAULT_SEARCH_LIMIT}). Omit for read; use its returned offset and imageOffset, if shown.`,
45
+ minimum: 1,
46
+ }),
47
+ ),
48
+ cursor: Type.Optional(
49
+ Type.String({
50
+ description:
51
+ "Continuation from the previous search page; keep query and all unchanged",
52
+ maxLength: 512,
53
+ }),
54
+ ),
55
+ offset: Type.Optional(
56
+ Type.Integer({
57
+ description: "Read only: character offset from the previous page (default 0)",
58
+ minimum: 0,
59
+ }),
60
+ ),
61
+ imageOffset: Type.Optional(
62
+ Type.Integer({
63
+ description: "First image to return (read); use the value from the continuation",
64
+ minimum: 0,
65
+ }),
66
+ ),
67
+ },
68
+ { additionalProperties: false },
69
+ );
57
70
  export type HistoryParams = Immutable<Static<typeof historyParameters>>;
58
71
  export type HistorySource = {
59
72
  readonly dir: string;
@@ -316,8 +329,11 @@ export async function historyMatches(
316
329
  signal: AbortSignal | undefined,
317
330
  fail: (message: string) => never,
318
331
  ): Promise<HistoryMatches> {
332
+ const limit = params.limit ?? DEFAULT_SEARCH_LIMIT;
333
+ if (limit > MAX_SEARCH_LIMIT) {
334
+ fail(`History search limit must be between 1 and ${MAX_SEARCH_LIMIT} results per page.`);
335
+ }
319
336
  const query = requireValue(params.query, "query", params.op).toLowerCase();
320
- const limit = params.limit ?? 10;
321
337
  const key = shortKey(JSON.stringify([query, params.all === true]));
322
338
  let cursor: HistoryCursor | undefined;
323
339
  try {
package/src/history.ts CHANGED
@@ -81,7 +81,7 @@ export function registerHistory(
81
81
  label: "History",
82
82
  ...toolCards("history"),
83
83
  description:
84
- "Search or read earlier session entries, including previous context windows. search skips entries still in your active context and lists original content before recovery echoes, newest first; all=true also searches this project's other sessions and subagent runs. read takes an entry id exactly as search printed it and pages text and images.",
84
+ "Search or read earlier session entries, including previous context windows. search skips entries still in your active context and lists original content before recovery echoes, newest first; all=true also searches this project's other sessions and subagent runs. search pages with cursor; limit is a search result count only. read takes an entry id exactly as search printed it. Omit limit and continue with the returned offset and imageOffset, if shown.",
85
85
  promptSnippet: "recover earlier conversation that left the active context window",
86
86
  promptGuidelines: [
87
87
  "Use history search first, then history read with the entry id exactly as printed",
package/src/notes.ts CHANGED
@@ -116,7 +116,11 @@ async function readNote(
116
116
  const text = readFileSync(path, "utf8");
117
117
  const offset = params.offset ?? 0;
118
118
  if (offset > 0 && offset >= text.length) {
119
- throw new Error(`Offset ${offset} is past the end of ${relative} (${text.length} chars).`);
119
+ return pages.deliver(access.host(), {}, () =>
120
+ textResult(
121
+ `Offset ${offset} is past the end of ${relative} (${text.length} chars). Restart with offset 0.`,
122
+ ),
123
+ );
120
124
  }
121
125
  const header =
122
126
  target.kind === "own"
@@ -288,34 +292,37 @@ function withoutEmptyScope(params: NotesParams): NotesParams {
288
292
  const { scope, ...unscoped } = params;
289
293
  return presentText(scope) === undefined ? unscoped : params;
290
294
  }
291
- const notesParameters = Type.Object({
292
- op: Type.Enum(["list", "read", "write", "append", "search"], {
293
- type: "string",
294
- description: "Operation to perform",
295
- }),
296
- path: Type.Optional(
297
- Type.String({
298
- description:
299
- "Note or folder path relative to the notes directory (read also accepts a path in this session's notes directory)",
300
- }),
301
- ),
302
- scope: Type.Optional(
303
- Type.String({
304
- description:
305
- "Absolute scope selector from list/search; only for read/list/search. Omit for current notes and project-wide discovery.",
306
- }),
307
- ),
308
- content: Type.Optional(
309
- Type.String({ description: "Full file content (write) or text to add (append)" }),
310
- ),
311
- query: Type.Optional(Type.String({ description: "Substring to find in notes (search)" })),
312
- offset: Type.Optional(
313
- Type.Integer({
314
- description: "Character offset for list/read/search (default 0)",
315
- minimum: 0,
295
+ const notesParameters = Type.Object(
296
+ {
297
+ op: Type.Enum(["list", "read", "write", "append", "search"], {
298
+ type: "string",
299
+ description: "Operation to perform",
316
300
  }),
317
- ),
318
- });
301
+ path: Type.Optional(
302
+ Type.String({
303
+ description:
304
+ "Note or folder path relative to the notes directory (read also accepts a path in this session's notes directory)",
305
+ }),
306
+ ),
307
+ scope: Type.Optional(
308
+ Type.String({
309
+ description:
310
+ "Absolute scope selector from list/search; only for read/list/search. Omit for current notes and project-wide discovery.",
311
+ }),
312
+ ),
313
+ content: Type.Optional(
314
+ Type.String({ description: "Full file content (write) or text to add (append)" }),
315
+ ),
316
+ query: Type.Optional(Type.String({ description: "Substring to find in notes (search)" })),
317
+ offset: Type.Optional(
318
+ Type.Integer({
319
+ description: "Character offset for list/read/search (default 0)",
320
+ minimum: 0,
321
+ }),
322
+ ),
323
+ },
324
+ { additionalProperties: false },
325
+ );
319
326
  export type NotesParams = Immutable<Static<typeof notesParameters>>;
320
327
  export function registerNotes(
321
328
  pi: ExtensionAPI,
package/src/paging.ts CHANGED
@@ -112,7 +112,9 @@ export class PageReservations {
112
112
  const footer = (end: number) =>
113
113
  `\n[chars ${offset}-${end}${more === true ? "; more matches follow" : ` of ${text.length}`}; continue with offset ${end}]`;
114
114
  if (offset > 0 && offset >= text.length) {
115
- this.error(ctx, "Offset is past the end; restart with offset 0.");
115
+ return textResult(
116
+ `Offset ${offset} is at or past the end (${text.length} chars); no more entries. Restart with offset 0.`,
117
+ );
116
118
  }
117
119
  const range = notesRange(rows, {
118
120
  offset,
package/src/ui/cards.ts CHANGED
@@ -29,13 +29,6 @@ const titles: Readonly<Record<ToolName, string>> = {
29
29
  new_context: "New context",
30
30
  };
31
31
 
32
- interface CallState {
33
- readonly isError: boolean;
34
- readonly isPartial: boolean;
35
- readonly executionStarted: boolean;
36
- readonly expanded: boolean;
37
- }
38
-
39
32
  function callTarget(name: ToolName, args: Readonly<Record<string, unknown>>): string {
40
33
  if (args.op === "search") {
41
34
  return ` · “${argument(args.query, "query")}”`;
@@ -46,16 +39,6 @@ function callTarget(name: ToolName, args: Readonly<Record<string, unknown>>): st
46
39
  return name === "history" && args.op === "read" ? ` · ${argument(args.id, "id")}` : "";
47
40
  }
48
41
 
49
- function callStatus(state: CallState): string {
50
- if (state.isError) {
51
- return " · error";
52
- }
53
- if (!state.isPartial) {
54
- return "";
55
- }
56
- return state.executionStarted ? " · running" : " · preparing";
57
- }
58
-
59
42
  function callDetails(name: ToolName, args: Readonly<Record<string, unknown>>): string {
60
43
  const scope =
61
44
  name === "history" && args.op === "search"
@@ -75,11 +58,51 @@ function callDetails(name: ToolName, args: Readonly<Record<string, unknown>>): s
75
58
  return [scope, ...offsets].filter((part) => part.length > 0).join(" · ");
76
59
  }
77
60
 
61
+ class CallHeader implements Component {
62
+ private heading = "";
63
+ private details = "";
64
+ private expanded = false;
65
+ private cached: { readonly width: number; readonly lines: string[] } | undefined;
66
+
67
+ update(heading: string, details: string, expanded: boolean): void {
68
+ if (this.heading === heading && this.details === details && this.expanded === expanded) {
69
+ return;
70
+ }
71
+ this.heading = heading;
72
+ this.details = details;
73
+ this.expanded = expanded;
74
+ this.invalidate();
75
+ }
76
+
77
+ invalidate(): void {
78
+ this.cached = undefined;
79
+ }
80
+
81
+ render(width: number): string[] {
82
+ if (this.cached?.width === width) {
83
+ return this.cached.lines;
84
+ }
85
+ const lines = this.expanded
86
+ ? [
87
+ ...new Text(this.heading, 0, 0).render(width),
88
+ ...(this.details.length > 0 ? new Text(this.details, 0, 0).render(width) : []),
89
+ ]
90
+ : [truncateToWidth(this.heading.replace(/\s+/g, " "), width)];
91
+ this.cached = { width, lines };
92
+ return lines;
93
+ }
94
+ }
95
+
96
+ interface CallContext {
97
+ readonly expanded: boolean;
98
+ readonly lastComponent: Component | undefined;
99
+ }
100
+
78
101
  function callComponent(
79
102
  name: ToolName,
80
103
  args: Readonly<Record<string, unknown>>,
81
104
  theme: Theme,
82
- state: CallState,
105
+ context: CallContext,
83
106
  ): Component {
84
107
  let action = "";
85
108
  if (name === "notes" || name === "history") {
@@ -87,28 +110,15 @@ function callComponent(
87
110
  } else if (name === "new_context") {
88
111
  action = " · request";
89
112
  }
90
- let marker = "▸";
91
- if (state.isPartial) {
92
- marker = "…";
93
- } else if (state.expanded) {
94
- marker = "▾";
95
- }
96
- const label = `${marker} ${titles[name]}${action}${callStatus(state)}${callTarget(name, args)}`;
97
- return {
98
- invalidate() {
99
- // Stateless layout is recomputed with the current width on every render.
100
- },
101
- render(width) {
102
- const heading = theme.fg(state.isError ? "error" : "toolTitle", theme.bold(label));
103
- if (!state.expanded) {
104
- return [truncateToWidth(heading.replace(/\s+/g, " "), width)];
105
- }
106
- return [
107
- ...new Text(heading, 0, 0).render(width),
108
- ...textBlock(callDetails(name, args), theme, "muted").render(width),
109
- ];
110
- },
111
- };
113
+ const marker = context.expanded ? "▾" : "▸";
114
+ const label = `${marker} ${titles[name]}${action}${callTarget(name, args)}`;
115
+ const heading = theme.fg("toolTitle", theme.bold(label));
116
+ const detailsText = callDetails(name, args);
117
+ const details = detailsText.length > 0 ? theme.fg("muted", clean(detailsText)) : "";
118
+ const component =
119
+ context.lastComponent instanceof CallHeader ? context.lastComponent : new CallHeader();
120
+ component.update(heading, details, context.expanded);
121
+ return component;
112
122
  }
113
123
 
114
124
  interface ResultFacts {
@@ -121,7 +131,7 @@ interface ResultFacts {
121
131
  readonly expanded: boolean;
122
132
  readonly imageCount: number;
123
133
  readonly showImages: boolean;
124
- readonly expandKey: string;
134
+ readonly expandHint: string;
125
135
  }
126
136
 
127
137
  function submittedText(facts: ResultFacts): string {
@@ -315,7 +325,7 @@ function collapsedView(
315
325
  ...summaryRows,
316
326
  ...shown,
317
327
  ...attachments,
318
- ...(hidden ? [hint(theme, width, facts.expandKey)] : []),
328
+ ...(hidden ? [hint(theme, width, facts.expandHint)] : []),
319
329
  ];
320
330
  };
321
331
  }
@@ -349,7 +359,7 @@ export function toolCards(name: ToolName): Pick<ToolDefinition, "renderCall" | "
349
359
  expanded,
350
360
  imageCount: result.content.filter((part) => part.type === "image").length,
351
361
  showImages: context.showImages,
352
- expandKey: context.keyText("app.tools.expand"),
362
+ expandHint: context.keyHint("app.tools.expand", "to expand"),
353
363
  },
354
364
  theme,
355
365
  );
package/src/ui/text.ts CHANGED
@@ -78,9 +78,11 @@ export function leadingRows(
78
78
  };
79
79
  }
80
80
 
81
- export function hint(theme: Theme, width: number, key: string): string {
82
- return truncateToWidth(
83
- theme.fg("dim", key.length > 0 ? `… ${key} to expand` : "… details hidden"),
84
- width,
85
- );
81
+ export function hint(theme: Theme, width: number, keyHint: string): string {
82
+ const plain = stripTerminalSequences(keyHint).trim();
83
+ const text =
84
+ plain.length === 0 || plain === "to expand"
85
+ ? theme.fg("dim", "… details hidden")
86
+ : `${theme.fg("dim", "… ")}${keyHint}`;
87
+ return truncateToWidth(text, width);
86
88
  }
package/ui.ts CHANGED
@@ -17,16 +17,25 @@ interface ExpansionState {
17
17
  expanded: boolean;
18
18
  }
19
19
 
20
+ function localExpansion(
21
+ states: WeakMap<object, ExpansionState>,
22
+ message: object,
23
+ globalExpanded: boolean,
24
+ ): ExpansionState {
25
+ let state = states.get(message);
26
+ if (state === undefined || state.global !== globalExpanded) {
27
+ state = { global: globalExpanded, expanded: globalExpanded };
28
+ states.set(message, state);
29
+ }
30
+ return state;
31
+ }
32
+
20
33
  /** Each saved message owns its click state; global expansion resets that local choice. */
21
34
  export function registerPosthorseMessages(pi: ExtensionAPI): void {
22
35
  const states = new WeakMap<object, ExpansionState>();
23
36
  const renderer: MessageRenderer = (message, options, theme) => {
24
- let state = states.get(message);
25
- if (state === undefined || state.global !== options.expanded) {
26
- state = { global: options.expanded, expanded: options.expanded };
27
- states.set(message, state);
28
- }
29
- const view = state;
37
+ const nativeToggle = "compactView" in options && options.compactView !== undefined;
38
+ const view = nativeToggle ? undefined : localExpansion(states, message, options.expanded);
30
39
  const window = message.customType === LEGACY_WINDOW_TYPE;
31
40
  const raw = textOf(message.content);
32
41
  const handoffLabel = "\n\nHandoff from the previous window:\n";
@@ -36,46 +45,61 @@ export function registerPosthorseMessages(pi: ExtensionAPI): void {
36
45
  : raw;
37
46
  const previewRows = window ? 2 : 3;
38
47
  const previewText = leadingRows(preview, theme, "toolOutput", previewRows);
39
- const expandKey = options.keyText("app.tools.expand");
48
+ const expandHint = options.keyHint("app.tools.expand", "to expand");
40
49
  let fullText: Text | undefined;
50
+ let cached: { readonly width: number; readonly lines: string[] } | undefined;
41
51
  const historyText = textBlock("Earlier conversation remains in history.", theme, "muted");
52
+ const messageLines = (inner: number, expanded: boolean): string[] => {
53
+ const title = `${expanded ? "▾" : "▸"} ${window ? "Context window started" : "Checkpoint reminder"}`;
54
+ const heading = truncateToWidth(
55
+ theme.fg(window ? "customMessageLabel" : "warning", theme.bold(clean(title))),
56
+ inner,
57
+ );
58
+ const body = expanded
59
+ ? (fullText ??= textBlock(raw, theme)).render(inner)
60
+ : [
61
+ ...(window ? historyText.render(inner).slice(0, 2) : []),
62
+ ...previewText(inner).slice(0, previewRows),
63
+ hint(theme, inner, expandHint),
64
+ ];
65
+ return [heading, ...body];
66
+ };
42
67
  const content: Component = {
43
68
  invalidate() {
44
- // Pi calls the renderer again on invalidation, so cached rows never outlive a theme.
69
+ fullText = undefined;
70
+ cached = undefined;
45
71
  },
46
72
  render(width) {
73
+ if (cached?.width === width) {
74
+ return cached.lines;
75
+ }
47
76
  const padding = Math.min(
48
77
  options.outputPad,
49
78
  Math.max(0, Math.floor((width - 1) / 2)),
50
79
  );
51
80
  const inner = Math.max(1, width - padding * 2);
52
- const title = `${view.expanded ? "▾" : "▸"} ${window ? "Context window started" : "Checkpoint reminder"}`;
53
- const heading = truncateToWidth(
54
- theme.fg(window ? "customMessageLabel" : "warning", theme.bold(clean(title))),
55
- inner,
56
- );
57
- const body = view.expanded
58
- ? (fullText ??= textBlock(raw, theme)).render(inner)
59
- : [
60
- ...(window ? historyText.render(inner).slice(0, 2) : []),
61
- ...previewText(inner).slice(0, previewRows),
62
- hint(theme, inner, expandKey),
63
- ];
81
+ const rows = messageLines(inner, view?.expanded ?? options.expanded);
64
82
  const box = new Box(padding, 1, (line) => theme.bg("customMessageBg", line));
65
83
  box.addChild({
66
- render: () => [heading, ...body],
84
+ render: () => rows,
67
85
  invalidate() {
68
86
  // The parent rebuilds this stateless box for every render.
69
87
  },
70
88
  });
71
- return box.render(width);
89
+ const lines = box.render(width);
90
+ cached = { width, lines };
91
+ return lines;
72
92
  },
73
93
  };
94
+ if (view === undefined) {
95
+ return content;
96
+ }
74
97
  return new MouseRegion(content, (event) => {
75
98
  if (event.type !== "click" || event.button !== "left") {
76
99
  return;
77
100
  }
78
101
  view.expanded = !view.expanded;
102
+ content.invalidate();
79
103
  return { handled: true };
80
104
  });
81
105
  };