pi-stereo-view 0.1.18 → 0.1.19

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.19 - 2026-11-19
6
+
7
+ ### Changed
8
+
9
+ - Split view uses much less CPU while an agent works: the panels are drawn as one full-width block instead of being merged cell by cell, and only history near each panel's viewport is rendered on every frame.
10
+ - Split view's per-frame work no longer grows with session length: content classification, tool grouping and timestamp checks reuse their results for history that did not change.
11
+
5
12
  ## 0.1.18 - 2026-11-09
6
13
 
7
14
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-stereo-view",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "type": "module",
5
5
  "description": "Keep Pi conversation separate from tool output and agent activity.",
6
6
  "license": "MIT",
@@ -52,10 +52,12 @@
52
52
  "@earendil-works/pi-tui": "*"
53
53
  },
54
54
  "devDependencies": {
55
- "@earendil-works/pi-coding-agent": "1.1.0",
56
- "@earendil-works/pi-tui": "1.1.0",
55
+ "@earendil-works/pi-ai": "1.5.2",
56
+ "@earendil-works/pi-coding-agent": "1.5.2",
57
+ "@earendil-works/pi-tui": "1.5.2",
57
58
  "@types/node": "^24.0.4",
58
59
  "pi-coding-agent-test": "0.1.3",
60
+ "typebox": "1.3.27",
59
61
  "typescript": "5.9.3",
60
62
  "vitest": "4.1.11"
61
63
  },
package/src/content.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Container, Markdown, Text, stripTerminalSequences, type Component } from "@earendil-works/pi-tui";
2
2
  import { searchText, type SearchEntry } from "./search.ts";
3
3
  import { NestedCalls } from "./nested-calls.ts";
4
+ import { sameValues } from "./render-cache.ts";
4
5
 
5
6
  export type Pane = "activity" | "chat";
6
7
  export type ContentKind = "dialogue" | "system" | "thinking" | "tool" | "shell";
@@ -49,6 +50,11 @@ export interface ContentEntry {
49
50
  /** Live execution metadata exists only on calls, never on linked output. */
50
51
  tool?(): ToolSummary;
51
52
  }
53
+ /** A call's status from Pi's result fields, which Pi updates in place without invalidating the call. */
54
+ export function callStatus(call: Component): ToolSummary["status"] {
55
+ const { result, isPartial } = call as NativeContent;
56
+ return !result || isPartial !== false ? "running" : result.isError ? "error" : "success";
57
+ }
52
58
 
53
59
  const nameOf = (component: Component): string => component.constructor.name;
54
60
  const contentText = (content: unknown): string => typeof content === "string" ? content :
@@ -91,7 +97,31 @@ function forEachRun(source: NativeAssistant, visit: (kind: ContentKind) => void)
91
97
  }
92
98
  }
93
99
  }
94
- const runsEnd = Symbol("runs");
100
+ /** One non-spacer native history child, its spacing and the entries projected from it. */
101
+ interface Classified {
102
+ component: Component;
103
+ spacing: Component[];
104
+ entries: ContentEntry[];
105
+ /** Native identities that ownership depends on; Pi sets them at construction. */
106
+ toolCallId: unknown;
107
+ parentId: unknown;
108
+ custom: unknown;
109
+ /** Assistant inputs: Pi replaces the content array whenever it rebuilds the message's blocks. */
110
+ content?: Component[];
111
+ contentLength?: number;
112
+ message?: unknown;
113
+ /** Linked panel inputs: its resolved owner and the panel parts shown as nested calls. */
114
+ parent?: { id: string; owner?: NativeContent; parts?: Component[] };
115
+ }
116
+
117
+ const parentOf = (component: NativeContent): unknown => component.entry?.data?.parentToolCallId ?? component.message?.details?.parentToolCallId;
118
+
119
+ /** The previous entry for the same native block, when every field that renders or searches it is equal. */
120
+ function reuse(entry: ContentEntry, previous: readonly ContentEntry[]): ContentEntry {
121
+ const match = previous.find(candidate => candidate.source === entry.source && candidate.component === entry.component);
122
+ return match && match.owner === entry.owner && match.kind === entry.kind && match.compact === entry.compact &&
123
+ sameValues(match.spacing, entry.spacing) ? match : entry;
124
+ }
95
125
 
96
126
  /** Read supported native execution identities; unrecognized content is system information. */
97
127
  const nativeKinds: Record<string, { kind: ContentKind; accepts(content: NativeContent): boolean }> = {
@@ -139,11 +169,17 @@ function nativePanelParts(source: NativeContent): Component[] | undefined {
139
169
  }
140
170
  /** Shared semantic index for painting and search, independent of wording, severity and lifecycle. */
141
171
  export class NativeContentIndex {
142
- private signature: unknown[] = [];
143
172
  private content: ContentEntry[] = [];
173
+ /** History children, source parts and per-block classification from the last verification. */
174
+ private history: Component[] = [];
175
+ private head: Component[] = [];
176
+ private headEntries: ContentEntry[] = [];
177
+ private blocks: Classified[] = [];
178
+ private readonly owners = new Map<string, NativeContent>();
144
179
  private panes: Partial<Record<Pane, ContentEntry[]>> = {};
145
180
  private readonly expandedPanels = new WeakMap<Component, Component>();
146
181
  private readonly views = new WeakMap<NativeAssistant, Partial<Record<Pane, Container>>>();
182
+ private readonly diagnostics = new WeakMap<NativeAssistant, Component[]>();
147
183
 
148
184
  private pass?: { active: boolean; verified?: { children: Component[]; length: number; last?: Component; parts: number; revision: number } };
149
185
 
@@ -185,29 +221,6 @@ export class NativeContentIndex {
185
221
  return group.map(candidate => stripTerminalSequences(candidate.search(width).text)).filter(Boolean).join("\n\n");
186
222
  }
187
223
 
188
- /** Visit every native identity that classification depends on, in a fixed order. */
189
- private visitSignature(history: Container, visit: (value: unknown) => boolean): boolean {
190
- if (!visit(this.nested.revision)) return false;
191
- for (const component of this.source.children) if (!visit(component)) return false;
192
- for (const component of history.children) if (!visit(component)) return false;
193
- for (const component of history.children) {
194
- const metadata = component as NativeContent;
195
- if (!visit(metadata.toolCallId) || !visit(metadata.entry?.data?.parentToolCallId) ||
196
- !visit(metadata.message?.details?.parentToolCallId) || !visit(metadata.customComponent)) return false;
197
- if (metadata.entry?.data?.parentToolCallId || metadata.message?.details?.parentToolCallId)
198
- for (const part of nativePanelParts(metadata) ?? []) if (!visit(part)) return false;
199
- const native = assistant(component);
200
- if (native) {
201
- // Streaming replaces the message on every delta; only its block layout affects routing.
202
- let changed = false;
203
- forEachRun(native, kind => { if (!changed && !visit(kind)) changed = true; });
204
- if (changed || !visit(runsEnd)) return false;
205
- for (const child of native.contentContainer.children) if (!visit(child)) return false;
206
- }
207
- }
208
- return true;
209
- }
210
-
211
224
  private refresh(): void {
212
225
  const history = this.source.children[2] as Container;
213
226
  if (!Array.isArray(history?.children)) throw new Error("Pi's history document is not supported");
@@ -220,52 +233,73 @@ export class NativeContentIndex {
220
233
  if (pass) pass.verified = { children, length: children.length, last: children.at(-1), parts: this.source.children.length, revision: this.nested.revision };
221
234
  }
222
235
 
236
+ /** Whether a classified block still has the native inputs its entries were built from. */
237
+ private unchanged(block: Classified): boolean {
238
+ const component = block.component as NativeAssistant & NativeContent;
239
+ if (component.toolCallId !== block.toolCallId || parentOf(component) !== block.parentId || component.customComponent !== block.custom) return false;
240
+ if (block.content) {
241
+ const children = component.contentContainer?.children;
242
+ if (component.contentIsStale === true || children !== block.content || children.length !== block.contentLength ||
243
+ component.lastMessage !== block.message) return false;
244
+ }
245
+ if (block.parent) {
246
+ const owner = this.owners.get(block.parent.id);
247
+ if (owner !== block.parent.owner) return false;
248
+ const parts = owner?.toolCallId && this.nested.entries(owner.toolCallId).length ? nativePanelParts(component) : undefined;
249
+ if (parts ? !sameValues(block.parent.parts, parts) : block.parent.parts) return false;
250
+ }
251
+ return true;
252
+ }
253
+
254
+ /**
255
+ * Reclassify only blocks whose native inputs changed: new or moved children, rebuilt assistant content,
256
+ * and parented panels whose owner or parts changed. Unchanged blocks keep their entry objects, and the
257
+ * content array keeps its identity while no entry changed, so streaming does not rebuild the index.
258
+ */
223
259
  private verify(history: Container): void {
224
- const makeSignature = (): unknown[] => {
225
- const values: unknown[] = [];
226
- this.visitSignature(history, value => { values.push(value); return true; });
227
- return values;
228
- };
229
- // Compare in place: this runs several times per frame over the whole history.
230
- let position = 0;
231
- const previous = this.signature;
232
- if (this.visitSignature(history, value => value === previous[position++]) && position === previous.length) return;
233
- const owners = new Map<string, NativeContent>();
234
- for (const component of history.children) {
260
+ const children = history.children;
261
+ const head = this.source.children;
262
+ let same = 0;
263
+ const limit = Math.min(children.length, this.history.length);
264
+ while (same < limit && children[same] === this.history[same]) same++;
265
+ const structural = same !== children.length || same !== this.history.length;
266
+ if (!structural && sameValues(this.head, head) && this.blocks.every(block => this.unchanged(block))) return;
267
+ this.owners.clear();
268
+ for (const component of children) {
235
269
  const adapter = nativeKinds[nameOf(component)];
236
270
  const native = component as NativeContent;
237
271
  if (adapter?.kind === "tool" && adapter.accepts(native) && typeof native.toolCallId === "string") {
238
- owners.set(native.toolCallId, native);
272
+ this.owners.set(native.toolCallId, native);
239
273
  }
240
274
  }
241
- const entries = this.source.children.slice(0, 2).map(component => this.entry(component, "system", [], false));
275
+ // Blocks of the unchanged prefix keep their positions; later children may have moved.
276
+ let previous: Map<Component, Classified> | undefined;
277
+ const find = (component: Component, index: number): Classified | undefined => {
278
+ if (this.blocks[index]?.component === component) return this.blocks[index];
279
+ previous ??= new Map(this.blocks.map(block => [block.component, block]));
280
+ return previous.get(component);
281
+ };
282
+ const blocks: Classified[] = [];
283
+ const entries = head.slice(0, 2).map(component => reuse(this.entry(component, "system", [], false), this.headEntries));
284
+ this.headEntries = entries.slice();
242
285
  let spacing: Component[] = [];
243
- for (const component of history.children) {
286
+ for (let position = 0; position < children.length; position++) {
287
+ const component = children[position];
244
288
  if (nameOf(component) === "Spacer") {
245
289
  spacing.push(component);
246
290
  continue;
247
291
  }
248
- const native = assistant(component);
249
- if (native) entries.push(...this.assistantEntries(native, spacing));
250
- else {
251
- const adapter = nativeKinds[nameOf(component)];
252
- const native = component as NativeContent;
253
- const kind = adapter?.accepts(native) ? adapter.kind : "system";
254
- const parentId = native.entry?.data?.parentToolCallId ?? native.message?.details?.parentToolCallId;
255
- const owner = kind === "system" && typeof parentId === "string" ? owners.get(parentId) : undefined;
256
- if (owner && this.expandedPanels.get(component) !== owner) {
257
- native.setExpanded?.(true);
258
- this.expandedPanels.set(component, owner);
259
- } else if (!owner) this.expandedPanels.delete(component);
260
- const parts = owner && this.nested.entries(owner.toolCallId!).length ? nativePanelParts(native) : undefined;
261
- if (parts) for (const part of parts) {
262
- const adapter = nativeKinds[nameOf(part)];
263
- const partKind = adapter?.accepts(part as NativeContent) ? adapter.kind : "system";
264
- entries.push(this.entry(part, partKind, [], true, owner));
265
- } else entries.push(this.entry(component, kind, spacing, true, owner));
266
- }
292
+ const old = find(component, blocks.length);
293
+ // Spacing before a block in the unchanged prefix lies in that prefix too.
294
+ const sameSpacing = old !== undefined && (position < same || sameValues(old.spacing, spacing));
295
+ const block = old && sameSpacing && this.unchanged(old) ? old : this.classify(component, sameSpacing ? old!.spacing : spacing, old);
296
+ blocks.push(block);
297
+ for (const entry of block.entries) entries.push(entry);
267
298
  spacing = [];
268
299
  }
300
+ this.blocks = blocks;
301
+ this.history = children.slice();
302
+ this.head = head.slice();
269
303
  // Project late execution output beside its owner, never reorder native history.
270
304
  const linked = new Map<Component, ContentEntry[]>();
271
305
  for (const entry of entries) {
@@ -274,18 +308,51 @@ export class NativeContentIndex {
274
308
  group.push(entry);
275
309
  linked.set(entry.owner, group);
276
310
  }
277
- this.content = entries.flatMap(entry => entry.owner === entry.source
278
- ? [entry, ...(linked.get(entry.source) ?? [])] : []);
279
- this.signature = makeSignature();
311
+ const content = linked.size ? entries.flatMap(entry => entry.owner === entry.source
312
+ ? [entry, ...(linked.get(entry.source) ?? [])] : []) : entries;
313
+ if (sameValues(this.content, content)) return;
314
+ this.content = content;
280
315
  this.panes = {};
281
316
  }
282
317
 
318
+ /** Build the entries of one native history block, keeping previous entry objects that did not change. */
319
+ private classify(component: Component, spacing: Component[], old: Classified | undefined): Classified {
320
+ const native = component as NativeContent;
321
+ const block: Classified = { component, spacing, entries: [], toolCallId: native.toolCallId, parentId: parentOf(native), custom: native.customComponent };
322
+ const message = assistant(component);
323
+ if (message) {
324
+ block.entries = this.assistantEntries(message, spacing);
325
+ block.content = message.contentContainer.children;
326
+ block.contentLength = block.content.length;
327
+ block.message = message.lastMessage;
328
+ } else {
329
+ const adapter = nativeKinds[nameOf(component)];
330
+ const content = component as NativeContent;
331
+ const kind = adapter?.accepts(content) ? adapter.kind : "system";
332
+ const parentId = block.parentId;
333
+ const owner = kind === "system" && typeof parentId === "string" ? this.owners.get(parentId) : undefined;
334
+ if (owner && this.expandedPanels.get(component) !== owner) {
335
+ content.setExpanded?.(true);
336
+ this.expandedPanels.set(component, owner);
337
+ } else if (!owner) this.expandedPanels.delete(component);
338
+ const parts = owner && this.nested.entries(owner.toolCallId!).length ? nativePanelParts(content) : undefined;
339
+ if (kind === "system" && typeof parentId === "string") block.parent = { id: parentId, owner, parts };
340
+ if (parts) for (const part of parts) {
341
+ const adapter = nativeKinds[nameOf(part)];
342
+ const partKind = adapter?.accepts(part as NativeContent) ? adapter.kind : "system";
343
+ block.entries.push(this.entry(part, partKind, [], true, owner));
344
+ } else block.entries.push(this.entry(component, kind, spacing, true, owner));
345
+ }
346
+ if (old) block.entries = block.entries.map(entry => reuse(entry, old.entries));
347
+ return block;
348
+ }
349
+
283
350
  private entry(source: Component, kind: ContentKind, spacing: Component[], compact: boolean, owner?: NativeContent): ContentEntry {
284
351
  const tool = kind === "tool" ? (): ToolSummary => {
285
352
  const native = source as NativeContent;
286
353
  return {
287
354
  name: native.toolName!, args: native.args,
288
- status: !native.result || native.isPartial !== false ? "running" : native.result.isError ? "error" : "success",
355
+ status: callStatus(native),
289
356
  };
290
357
  } : undefined;
291
358
  return { source, owner: owner ?? source, component: source, kind: owner ? "tool" : kind, spacing, compact, tool, search: width => {
@@ -343,6 +410,8 @@ export class NativeContentIndex {
343
410
  padding = [];
344
411
  }
345
412
  if (slot < runs.length) throw new Error("Pi's assistant content layout is not supported");
413
+ // Entries outlive one classification; search reads the current diagnostics.
414
+ this.diagnostics.set(source, diagnostics);
346
415
  const views = this.views.get(source) ?? {};
347
416
  this.views.set(source, views);
348
417
  const result: ContentEntry[] = [];
@@ -371,7 +440,7 @@ export class NativeContentIndex {
371
440
  .map(block => kind === "text" ? block.text ?? "" : block.thinking ?? "").join("\n\n");
372
441
  return {
373
442
  label: pane === "activity" ? "Thinking" : "Assistant",
374
- text: [saved, ...(pane === "chat" ? diagnostics.map(child => searchText(child.render(width).join("\n"))) : [])].filter(Boolean).join("\n\n"),
443
+ text: [saved, ...(pane === "chat" ? (this.diagnostics.get(source) ?? []).map(child => searchText(child.render(width).join("\n"))) : [])].filter(Boolean).join("\n\n"),
375
444
  reveal: pane === "activity" ? () => source.setHideThinkingBlock(false) : undefined,
376
445
  };
377
446
  },
package/src/layout.ts CHANGED
@@ -10,6 +10,8 @@ import { NestedCalls } from "./nested-calls.ts";
10
10
  import type { Preferences } from "./preferences.ts";
11
11
  import type { TranscriptTimestamps } from "./timestamps.ts";
12
12
  import { PANEL_SEARCH_ROWS, PanelSearch, PanelSearchShortcut, type SearchHit } from "./search.ts";
13
+ import { SplitSurface } from "./surface.ts";
14
+ import { sameValues } from "./render-cache.ts";
13
15
 
14
16
  type NativeTui = TUI & {
15
17
  layoutRoot?: Container;
@@ -21,6 +23,23 @@ const MIN_ACTIVITY = 40;
21
23
  const MIN_ROWS = 4;
22
24
  const TOOLBAR_BUTTON_WIDTH = 6;
23
25
 
26
+ /**
27
+ * A control that renders again only when one of its inputs changes. Every spinner frame lays out
28
+ * all toolbar and panel controls; restyling unchanged labels would cost more than the panels themselves.
29
+ */
30
+ function memoized(inputs: (width: number) => unknown[], render: (width: number) => string[]): Component {
31
+ let last: { inputs: unknown[]; lines: string[] } | undefined;
32
+ return {
33
+ render: width => {
34
+ const current = inputs(width);
35
+ if (last && sameValues(last.inputs, current)) return last.lines;
36
+ last = { inputs: current, lines: render(width) };
37
+ return last.lines;
38
+ },
39
+ invalidate: () => { last = undefined; },
40
+ };
41
+ }
42
+
24
43
  class PanelScrollView extends ScrollView {
25
44
  constructor(component: Component, options: ScrollViewOptions, private readonly interact: () => void, active: () => boolean) {
26
45
  super(component, options);
@@ -111,7 +130,9 @@ class ButtonStack extends VStack {
111
130
  flush();
112
131
  }
113
132
  }
114
- return super.render(width);
133
+ // Pi and the split surface lay out these rows themselves and read render only for the height.
134
+ // Rendering the rows here would composite every button into a full-width row on every frame.
135
+ return Array<string>(this.children.length).fill("");
115
136
  }
116
137
  }
117
138
  class TranscriptColumns extends HStack {
@@ -137,11 +158,17 @@ class TranscriptRows extends VStack {
137
158
  class TranscriptRoot extends VStack {
138
159
  private readonly owned: Component[];
139
160
 
140
- constructor(children: StackChild[]) {
161
+ constructor(children: StackChild[], private readonly unhandled: (event: TuiMouseEvent) => void) {
141
162
  super(children);
142
163
  this.owned = [...this.children];
143
164
  }
144
165
 
166
+ override handleMouse(event: TuiMouseEvent): ReturnType<Container["handleMouse"]> {
167
+ // Pi offers the root only events no component handled, such as pointer moves outside the split panels.
168
+ this.unhandled(event);
169
+ return undefined;
170
+ }
171
+
145
172
  unchanged(): boolean {
146
173
  return this.children.length === this.owned.length && this.children.every((child, index) => child === this.owned[index]);
147
174
  }
@@ -194,6 +221,7 @@ export class TranscriptLayout {
194
221
  private activity?: ScrollView;
195
222
  private chat?: ScrollView;
196
223
  private documents?: Record<Pane, NativeDocument>;
224
+ private surface?: SplitSurface;
197
225
  private disposeDocuments?: () => void;
198
226
  private activePane: Pane = "chat";
199
227
  private readonly searchShortcut = new PanelSearchShortcut();
@@ -225,12 +253,10 @@ export class TranscriptLayout {
225
253
  ) {}
226
254
 
227
255
  private button(label: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
228
- const button = new MouseRegion({
229
- render: width => new Text(this.theme().style((this.preferences.buttonStyle === "icons" ? "[ " + label() + " ]" : "[" + label() + "]").padEnd(width), {
256
+ const button = new MouseRegion(memoized(width => [width, this.theme(), this.preferences.buttonStyle, label(), enabled(), background?.()],
257
+ width => new Text(this.theme().style((this.preferences.buttonStyle === "icons" ? "[ " + label() + " ]" : "[" + label() + "]").padEnd(width), {
230
258
  fg: enabled() ? "accent" : "dim", bg: background?.(),
231
- }), 0, 0).render(width),
232
- invalidate() {},
233
- }, event => {
259
+ }), 0, 0).render(width)), event => {
234
260
  if (event.button !== "left") return;
235
261
  if (event.type === "press") return { capture: true };
236
262
  if (event.type === "click" && enabled() && event.x >= 0 && event.x < event.width && event.y === 0) {
@@ -342,6 +368,11 @@ export class TranscriptLayout {
342
368
  this.activity = new PanelScrollView(activityDocument, scrollOptions, () => this.activate("activity"),
343
369
  () => this.searchPane() === "activity");
344
370
  this.chat = new PanelScrollView(chatDocument, scrollOptions, () => this.activate("chat"), () => this.searchPane() === "chat");
371
+ // Each document renders only the history near its panel's viewport from the previous layout.
372
+ for (const [document, view] of [[activityDocument, this.activity], [chatDocument, this.chat]] as const) {
373
+ document.setViewport(() => view.viewportHeight ?
374
+ { top: view.scrollTop, height: view.viewportHeight, following: view.isFollowingEnd } : undefined, () => this.host?.requestRender());
375
+ }
345
376
  let historyHeight = 0;
346
377
  let chatHeader: Component;
347
378
  let activityHeader: Component;
@@ -439,25 +470,25 @@ export class TranscriptLayout {
439
470
  ]);
440
471
  const pane = (title: string, target: Pane, view: ScrollView): Component => {
441
472
  const hue = target === "chat" ? rgbColor(104, 158, 115) : rgbColor(107, 152, 190);
473
+ let colors: { inputs: unknown[]; palette: { fill: Color; text: Color; border: Color } } | undefined;
474
+ // Mixed colors keep their identity while the theme is unchanged, so memoized controls can compare them.
442
475
  const palette = () => {
443
476
  const theme = this.theme();
444
- return {
477
+ const inputs = [theme, theme.colors.customMessageBg, theme.colors.text, theme.colors.border];
478
+ if (!colors || !sameValues(colors.inputs, inputs)) colors = { inputs, palette: {
445
479
  fill: mixColors(theme.colors.customMessageBg, hue, 0.15, "srgb"),
446
480
  text: mixColors(theme.colors.text, hue, 0.25),
447
481
  border: mixColors(theme.colors.border, hue, 0.3),
448
- };
449
- };
450
- const line: Component = {
451
- render: width => [this.theme().style("─".repeat(width), { fg: palette().border })],
452
- invalidate() {},
482
+ } };
483
+ return colors.palette;
453
484
  };
485
+ const line = memoized(width => [width, this.theme(), palette()],
486
+ width => [this.theme().style("─".repeat(width), { fg: palette().border })]);
454
487
  const label = new ButtonStack([
455
- { component: new MouseRegion({
456
- render: width => new Text(this.theme().style(truncateToWidth(width < title.length + 3 ? title : " " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
488
+ { component: new MouseRegion(memoized(width => [width, this.theme(), palette(), this.searchPane() === target],
489
+ width => new Text(this.theme().style(truncateToWidth(width < title.length + 3 ? title : " " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
457
490
  fg: this.searchPane() === target ? "accent" : palette().text, bg: palette().fill,
458
- }), 0, 0).render(width),
459
- invalidate() {},
460
- }, event => {
491
+ }), 0, 0).render(width)), event => {
461
492
  if (event.button === "left" && (event.type === "press" || event.type === "click")) {
462
493
  this.activate(target);
463
494
  return { handled: true, render: true };
@@ -486,10 +517,8 @@ export class TranscriptLayout {
486
517
  ] : [
487
518
  { index: 1, icon: 6 },
488
519
  { index: 2, icon: 5 },
489
- ], title.length, {
490
- render: width => [this.theme().style(" ".repeat(width), { bg: palette().fill })],
491
- invalidate() {},
492
- });
520
+ ], title.length, memoized(width => [width, this.theme(), palette()],
521
+ width => [this.theme().style(" ".repeat(width), { bg: palette().fill })]));
493
522
  headers.push(label);
494
523
  const header = new VStack([
495
524
  { component: line, basis: 1, shrink: 0, visible: () =>
@@ -507,12 +536,10 @@ export class TranscriptLayout {
507
536
  };
508
537
  const activityPane = pane("Activity", "activity", this.activity);
509
538
  const chatPane = pane("Conversation", "chat", this.chat);
510
- const divider = (axis: "columns" | "rows"): Component => new MouseRegion({
511
- render: width => axis === "columns" ?
539
+ const divider = (axis: "columns" | "rows"): Component => new MouseRegion(memoized(width => [width, host.terminal.rows, this.theme()],
540
+ width => axis === "columns" ?
512
541
  Array.from({ length: host.terminal.rows }, () => this.theme().fg("dim", "║")) :
513
- [this.theme().fg("dim", "═".repeat(width))],
514
- invalidate() {},
515
- }, event => {
542
+ [this.theme().fg("dim", "═".repeat(width))]), event => {
516
543
  if (event.button !== "left" && event.type !== "release") return;
517
544
  const position = axis === "columns" ? event.screenX : event.screenY;
518
545
  if (event.type === "press") {
@@ -564,32 +591,42 @@ export class TranscriptLayout {
564
591
  }
565
592
  };
566
593
  this.rebuild();
594
+ const surface = new SplitSurface(host, {
595
+ model: () => {
596
+ const zoom = this.preferences.zoom;
597
+ if (zoom) return { component: zoom === "chat" ? chatPane : activityPane, fill: false, minSize: MIN_ROWS };
598
+ return this.preferences.layout === "columns" ? { component: columns, fill: true, minSize: 1 } : { component: rows, fill: false, minSize: 1 };
599
+ },
600
+ height: () => historyHeight,
601
+ active: () => {
602
+ const pane = this.searchPane();
603
+ return pane === "chat" ? this.chat : pane === "activity" ? this.activity : undefined;
604
+ },
605
+ });
606
+ surface.setModels([columns, rows, activityPane, chatPane]);
607
+ this.surface = surface;
567
608
  const mounted = new TranscriptRoot([
568
609
  { component: toolbar, basis: "auto", shrink: 0, visible: () => {
569
610
  // Root visibility is evaluated once at the start of each native layout pass.
570
611
  pass = undefined;
571
612
  this.timestamps.beginFrame();
572
- activityDocument.beginFrame();
573
- chatDocument.beginFrame();
613
+ index.beginFrame();
614
+ activityDocument.beginFrame(true);
615
+ chatDocument.beginFrame(true);
574
616
  return true;
575
617
  } },
576
618
  { component: {
577
619
  render: width => [this.theme().style("─".repeat(width), { fg: this.theme().colors.border })],
578
620
  invalidate() {},
579
621
  }, basis: 1, shrink: 0, visible: viewport => !shown(viewport) },
580
- { component: columns, basis: 0, grow: 1, minSize: 1,
581
- visible: viewport => shown(viewport) && !this.preferences.zoom && this.preferences.layout === "columns" },
582
- { component: rows, basis: "auto", minSize: 1,
583
- visible: viewport => shown(viewport) && !this.preferences.zoom && this.preferences.layout === "rows" },
584
- { component: activityPane, basis: "auto", minSize: MIN_ROWS,
585
- visible: viewport => shown(viewport) && this.preferences.zoom === "activity" },
586
- { component: chatPane, basis: "auto", minSize: MIN_ROWS,
587
- visible: viewport => shown(viewport) && this.preferences.zoom === "chat" },
622
+ // The split paints as one full-width row block; the proxy gives Pi's keyboard scrolling the active panel.
623
+ { component: surface, basis: "auto", minSize: 1, visible: viewport => shown(viewport) },
624
+ { component: surface.proxy, basis: 0, shrink: 0, visible: viewport => shown(viewport) },
588
625
  { component: transcript, basis: 0, grow: 1, minSize: 1, visible: viewport => !shown(viewport) },
589
626
  ...(projectedDock ? [{ component: projectedDock, basis: "auto" as const, shrink: 0, minSize: 1,
590
627
  visible: () => projectSurface }] : []),
591
628
  { component: dock, basis: "auto", shrink: 0, minSize: 1, visible: () => !projectSurface },
592
- ]);
629
+ ], event => surface.unhandled(event));
593
630
  this.mounted = mounted;
594
631
  host.setLayoutRoot(mounted);
595
632
  host.requestRender();
@@ -846,6 +883,8 @@ export class TranscriptLayout {
846
883
  this.searchShortcut.dispose();
847
884
  this.disposeDocuments?.();
848
885
  this.disposeDocuments = undefined;
886
+ this.surface?.dispose();
887
+ this.surface = undefined;
849
888
  const host = this.host;
850
889
  this.activity?.setScrollbar("hidden");
851
890
  this.chat?.setScrollbar("hidden");