@linxiraos/pi-tui 1.4.3 → 1.4.6

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 (117) hide show
  1. package/CHANGELOG.md +29 -23
  2. package/THIRD-PARTY-NOTICES.txt +14 -0
  3. package/dist/types/app-keybindings.d.ts +5 -0
  4. package/dist/types/chrome/context-map.d.ts +15 -0
  5. package/dist/types/chrome/context-presentation.d.ts +48 -0
  6. package/dist/types/chrome/context-view-model.d.ts +77 -0
  7. package/dist/types/components/image.d.ts +20 -0
  8. package/dist/types/components/loader.d.ts +1 -1
  9. package/dist/types/native/blobs.d.ts +9 -0
  10. package/dist/types/overlays/advisor-config.d.ts +6 -0
  11. package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
  12. package/dist/types/overlays/ask-dialog.d.ts +12 -3
  13. package/dist/types/overlays/btw-history-panel.d.ts +16 -2
  14. package/dist/types/overlays/btw-history.d.ts +7 -0
  15. package/dist/types/overlays/btw-panel.d.ts +2 -0
  16. package/dist/types/overlays/context-viewer-format.d.ts +42 -0
  17. package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
  18. package/dist/types/overlays/context-viewer.d.ts +25 -0
  19. package/dist/types/overlays/hook-input.d.ts +1 -0
  20. package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
  21. package/dist/types/overlays/pause-screen.d.ts +13 -3
  22. package/dist/types/overlays/running-subagent-badge.d.ts +7 -1
  23. package/dist/types/prompt/macos-spelling.d.ts +2 -2
  24. package/dist/types/render/hyperlink.d.ts +15 -2
  25. package/dist/types/render/output-pane.d.ts +1 -1
  26. package/dist/types/render/render-utils.d.ts +7 -1
  27. package/dist/types/status-line/component.d.ts +2 -2
  28. package/dist/types/status-line/context-usage.d.ts +15 -30
  29. package/dist/types/terminal-capabilities.d.ts +7 -0
  30. package/dist/types/theme/symbols.d.ts +1 -1
  31. package/dist/types/tools/ask.d.ts +4 -0
  32. package/dist/types/tools/edit.d.ts +3 -1
  33. package/dist/types/tools/fetch.d.ts +1 -0
  34. package/dist/types/tools/github.d.ts +3 -0
  35. package/dist/types/tools/grouped-file-output.d.ts +2 -0
  36. package/dist/types/tools/mcp.d.ts +3 -3
  37. package/dist/types/tools/read.d.ts +3 -0
  38. package/dist/types/tools/wait.d.ts +16 -2
  39. package/dist/types/tui.d.ts +2 -0
  40. package/dist/types/vim.d.ts +39 -0
  41. package/package.json +9 -9
  42. package/src/app-keybindings.d.ts +5 -0
  43. package/src/app-keybindings.ts +5 -0
  44. package/src/chat/bash-execution.ts +7 -1
  45. package/src/chat/read-tool-group.ts +1 -2
  46. package/src/chat/skill-message.ts +2 -6
  47. package/src/chrome/context-map.ts +62 -0
  48. package/src/chrome/context-presentation.ts +26 -0
  49. package/src/chrome/context-view-model.ts +73 -0
  50. package/src/chrome/transcript-container.ts +89 -59
  51. package/src/components/editor.ts +455 -13
  52. package/src/components/image.d.ts +20 -0
  53. package/src/components/image.ts +83 -18
  54. package/src/components/loader.d.ts +1 -1
  55. package/src/components/loader.ts +1 -1
  56. package/src/components/markdown.ts +109 -7
  57. package/src/hotkeys-markdown.ts +1 -0
  58. package/src/native/blobs.d.ts +9 -0
  59. package/src/native/blobs.ts +3 -2
  60. package/src/overlays/advisor-config.ts +9 -2
  61. package/src/overlays/agent-hub-projection.d.ts +3 -1
  62. package/src/overlays/agent-hub-projection.ts +6 -5
  63. package/src/overlays/agent-hub.ts +51 -42
  64. package/src/overlays/ask-dialog.ts +125 -35
  65. package/src/overlays/btw-history-panel.ts +124 -12
  66. package/src/overlays/btw-history.ts +11 -0
  67. package/src/overlays/btw-panel.ts +8 -4
  68. package/src/overlays/context-viewer-format.ts +145 -0
  69. package/src/overlays/context-viewer-overview.ts +381 -0
  70. package/src/overlays/context-viewer.ts +728 -0
  71. package/src/overlays/hook-input.ts +2 -0
  72. package/src/overlays/mcp-add-wizard.ts +5 -0
  73. package/src/overlays/pause-screen.ts +166 -33
  74. package/src/overlays/running-subagent-badge.ts +12 -1
  75. package/src/overlays/settings-defs.ts +1 -0
  76. package/src/overlays/usage-dashboard.ts +15 -2
  77. package/src/prompt/macos-spelling.ts +24 -15
  78. package/src/render/hyperlink.d.ts +15 -2
  79. package/src/render/hyperlink.ts +41 -18
  80. package/src/render/output-pane.d.ts +1 -1
  81. package/src/render/output-pane.ts +60 -17
  82. package/src/render/render-utils.d.ts +7 -1
  83. package/src/render/render-utils.ts +11 -2
  84. package/src/setup/scenes/sign-in.ts +6 -0
  85. package/src/status-line/component.ts +6 -4
  86. package/src/status-line/context-usage.ts +56 -582
  87. package/src/terminal-capabilities.d.ts +7 -0
  88. package/src/terminal-capabilities.ts +10 -0
  89. package/src/theme/symbols.d.ts +1 -1
  90. package/src/theme/symbols.ts +16 -0
  91. package/src/tools/ask.d.ts +4 -0
  92. package/src/tools/ask.ts +4 -0
  93. package/src/tools/ast-grep.ts +3 -2
  94. package/src/tools/bash.ts +5 -23
  95. package/src/tools/edit.d.ts +3 -1
  96. package/src/tools/edit.ts +8 -4
  97. package/src/tools/fetch.d.ts +1 -0
  98. package/src/tools/fetch.ts +1 -0
  99. package/src/tools/find.ts +3 -10
  100. package/src/tools/github.d.ts +3 -0
  101. package/src/tools/github.ts +23 -3
  102. package/src/tools/glob.ts +4 -3
  103. package/src/tools/grep.ts +3 -4
  104. package/src/tools/grouped-file-output.d.ts +2 -0
  105. package/src/tools/grouped-file-output.ts +8 -2
  106. package/src/tools/mcp.d.ts +3 -3
  107. package/src/tools/mcp.ts +27 -9
  108. package/src/tools/native-view.ts +2 -2
  109. package/src/tools/read.d.ts +3 -0
  110. package/src/tools/read.ts +3 -1
  111. package/src/tools/vibe.ts +14 -3
  112. package/src/tools/wait.d.ts +16 -2
  113. package/src/tools/wait.ts +16 -2
  114. package/src/tui.d.ts +2 -0
  115. package/src/tui.ts +59 -19
  116. package/src/vim.d.ts +39 -0
  117. package/src/vim.ts +313 -22
package/src/tools/read.ts CHANGED
@@ -62,7 +62,9 @@ export interface ReadToolDetails {
62
62
  * screenshots, URL reads and other images not backed by a file. Display-only.
63
63
  */
64
64
  mediaPath?: string;
65
- suffixResolution?: { from: string; to: string };
65
+ suffixResolution?: { from: string; to: string; raw?: boolean };
66
+ /** Raw source output keeps descriptive diagnostics in details, not in the body. */
67
+ raw?: boolean;
66
68
  url?: string;
67
69
  finalUrl?: string;
68
70
  contentType?: string;
package/src/tools/vibe.ts CHANGED
@@ -206,6 +206,7 @@ function tvScreen(
206
206
  screen: VibeScreenSnapshot,
207
207
  options: RenderResultOptions,
208
208
  settledStatus?: "completed" | "failed" | "cancelled",
209
+ nowMs = Date.now(),
209
210
  ): string[] {
210
211
  const live = screen.state === "running" || screen.state === "starting";
211
212
  const spinnerFrame = live ? options.spinnerFrame : undefined;
@@ -223,7 +224,7 @@ function tvScreen(
223
224
  const turnsLabel = `${screen.turns}t${screen.queued > 0 ? `+${screen.queued}q` : ""}`;
224
225
  headParts.push(uiTheme.fg("muted", turnsLabel));
225
226
  if (screen.turnStartedAt !== undefined) {
226
- headParts.push(uiTheme.fg("dim", formatDuration(Date.now() - screen.turnStartedAt)));
227
+ headParts.push(uiTheme.fg("dim", formatDuration(nowMs - screen.turnStartedAt)));
227
228
  }
228
229
  if (screen.model) headParts.push(uiTheme.fg("muted", frameText(screen.model, 40)));
229
230
 
@@ -603,6 +604,8 @@ export function createVibeToolRenderer(op: VibeOp) {
603
604
  }
604
605
  const waiting = details.wait?.waiting === true;
605
606
  const settledById = new Map(details.wait?.settled.map(entry => [entry.id, entry.status] as const) ?? []);
607
+ const snapshotTime = Date.now();
608
+ const wallOptions = options.isPartial ? options : { ...options, spinnerFrame: undefined };
606
609
  return linesComponent(() => {
607
610
  const running = screens.filter(screen => screen.state === "running" || screen.state === "starting").length;
608
611
  const meta: string[] = [];
@@ -619,7 +622,7 @@ export function createVibeToolRenderer(op: VibeOp) {
619
622
  const header = renderStatusLine(
620
623
  {
621
624
  icon: details.wait?.timedOut ? "warning" : running > 0 ? "info" : "done",
622
- spinnerFrame: running > 0 ? options.spinnerFrame : undefined,
625
+ spinnerFrame: running > 0 ? wallOptions.spinnerFrame : undefined,
623
626
  title,
624
627
  meta,
625
628
  },
@@ -627,7 +630,15 @@ export function createVibeToolRenderer(op: VibeOp) {
627
630
  );
628
631
  const lines = [header];
629
632
  for (const screen of screens) {
630
- lines.push(...tvScreen(uiTheme, screen, options, settledById.get(screen.id)));
633
+ lines.push(
634
+ ...tvScreen(
635
+ uiTheme,
636
+ screen,
637
+ wallOptions,
638
+ settledById.get(screen.id),
639
+ options.isPartial ? Date.now() : snapshotTime,
640
+ ),
641
+ );
631
642
  }
632
643
  return lines;
633
644
  });
@@ -10,8 +10,8 @@ import type { NativeToolView, ToolRenderResult } from "./renderer";
10
10
  /** Whether a wait snapshot contains only running jobs and no cancellations. */
11
11
  export declare function isWaitingPollDetails(details: unknown): boolean;
12
12
  /** Coordination details retained by wait and background job operations. */
13
- export type CoordinationOp = "send" | "wait" | "jobs" | "cancel";
14
- /** Background-job row surfaced by `wait`/`cancel`/`jobs` results. */
13
+ export type CoordinationOp = "send" | "wait" | "cancel";
14
+ /** Background-job row surfaced by `wait`/`cancel` results and `proc://` listings. */
15
15
  export interface JobSnapshot {
16
16
  id: string;
17
17
  type: "bash" | "task" | "eval";
@@ -32,6 +32,14 @@ export interface JobSnapshot {
32
32
  completionPercent?: number;
33
33
  /** The task agent's latest stage in its own words; see `AgentProgress.stage`. */
34
34
  stage?: string;
35
+ /** Running task only: assistant requests so far; see `AgentProgress.requests`. */
36
+ requests?: number;
37
+ /** Running task only: cumulative cost in USD; see `AgentProgress.cost`. */
38
+ cost?: number;
39
+ /** Running task only: latest per-turn context size; see `AgentProgress.contextTokens`. */
40
+ contextTokens?: number;
41
+ /** Running task only: the model's context window; see `AgentProgress.contextWindow`. */
42
+ contextWindow?: number;
35
43
  /** The job's live widget, while one is being drawn; frozen at its last state once the job settles. */
36
44
  widget?: JobWidgetView;
37
45
  resultText?: string;
@@ -47,6 +55,12 @@ export interface JobSnapshot {
47
55
  * on collision, else the job id itself. See {@link AsyncJob.agentId}.
48
56
  */
49
57
  agentUrlId?: string;
58
+ /**
59
+ * Whether this job's turn published `<agentUrlId>.md`. False where the job
60
+ * body reported that it wrote none, so `agent://` still holds an earlier
61
+ * turn's output; undefined where the body does not report it.
62
+ */
63
+ agentOutputPublished?: boolean;
50
64
  }
51
65
  /** Outcome of cancelling one background job. */
52
66
  export type CancelStatus = "cancelled" | "not_found" | "already_completed";
package/src/tools/wait.ts CHANGED
@@ -43,9 +43,9 @@ export function isWaitingPollDetails(details: unknown): boolean {
43
43
  return d.jobs.every(job => job?.status === "running");
44
44
  }
45
45
  /** Coordination details retained by wait and background job operations. */
46
- export type CoordinationOp = "send" | "wait" | "jobs" | "cancel";
46
+ export type CoordinationOp = "send" | "wait" | "cancel";
47
47
 
48
- /** Background-job row surfaced by `wait`/`cancel`/`jobs` results. */
48
+ /** Background-job row surfaced by `wait`/`cancel` results and `proc://` listings. */
49
49
  export interface JobSnapshot {
50
50
  id: string;
51
51
  type: "bash" | "task" | "eval";
@@ -66,6 +66,14 @@ export interface JobSnapshot {
66
66
  completionPercent?: number;
67
67
  /** The task agent's latest stage in its own words; see `AgentProgress.stage`. */
68
68
  stage?: string;
69
+ /** Running task only: assistant requests so far; see `AgentProgress.requests`. */
70
+ requests?: number;
71
+ /** Running task only: cumulative cost in USD; see `AgentProgress.cost`. */
72
+ cost?: number;
73
+ /** Running task only: latest per-turn context size; see `AgentProgress.contextTokens`. */
74
+ contextTokens?: number;
75
+ /** Running task only: the model's context window; see `AgentProgress.contextWindow`. */
76
+ contextWindow?: number;
69
77
  /** The job's live widget, while one is being drawn; frozen at its last state once the job settles. */
70
78
  widget?: JobWidgetView;
71
79
  resultText?: string;
@@ -81,6 +89,12 @@ export interface JobSnapshot {
81
89
  * on collision, else the job id itself. See {@link AsyncJob.agentId}.
82
90
  */
83
91
  agentUrlId?: string;
92
+ /**
93
+ * Whether this job's turn published `<agentUrlId>.md`. False where the job
94
+ * body reported that it wrote none, so `agent://` still holds an earlier
95
+ * turn's output; undefined where the body does not report it.
96
+ */
97
+ agentOutputPublished?: boolean;
84
98
  }
85
99
 
86
100
  /** Outcome of cancelling one background job. */
package/src/tui.d.ts CHANGED
@@ -363,6 +363,8 @@ export declare class TUI extends Container {
363
363
  * observers (live stream publisher, session recorder) coexist.
364
364
  */
365
365
  addPaintListener(listener: PaintListener): () => void;
366
+ /** Observe actual ANSI frame writes, including transient resize paints; returns the unsubscribe. */
367
+ addFrameWriteListener(listener: (data: string) => void): () => void;
366
368
  /** Install the product-owned bounded frame provider. */
367
369
  setFrameProvider(provider: TerminalFrameProvider | undefined): void;
368
370
  get fullRedraws(): number;
package/src/tui.ts CHANGED
@@ -48,6 +48,7 @@ import {
48
48
  shouldEnableSynchronizedOutputByDefault,
49
49
  synchronizedOutputUserOverride,
50
50
  TERMINAL,
51
+ withDirectPlacementLift,
51
52
  } from "./terminal-capabilities";
52
53
  import { onTerminalBackgroundFallbackChange } from "./theme/theme";
53
54
  import { compositeLineAt } from "./render/composite";
@@ -943,6 +944,7 @@ export class TUI extends Container {
943
944
  /** True from the end of start() until stop(): the terminal modes start listeners enable are live. */
944
945
  #started = false;
945
946
  #paintListeners = new Set<PaintListener>();
947
+ #frameWriteListeners = new Set<(data: string) => void>();
946
948
 
947
949
  /** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
948
950
  onDebug?: () => void;
@@ -1159,6 +1161,14 @@ export class TUI extends Container {
1159
1161
  };
1160
1162
  }
1161
1163
 
1164
+ /** Observe actual ANSI frame writes, including transient resize paints; returns the unsubscribe. */
1165
+ addFrameWriteListener(listener: (data: string) => void): () => void {
1166
+ this.#frameWriteListeners.add(listener);
1167
+ return () => {
1168
+ this.#frameWriteListeners.delete(listener);
1169
+ };
1170
+ }
1171
+
1162
1172
  /** Install the product-owned bounded frame provider. */
1163
1173
  setFrameProvider(provider: TerminalFrameProvider | undefined): void {
1164
1174
  this.#frameProvider = provider;
@@ -3391,29 +3401,40 @@ export class TUI extends Container {
3391
3401
 
3392
3402
  /**
3393
3403
  * Clip direct placements to the visible source slice: Kitty tracks a live
3394
- * placement owner, while SIXEL crops the encoded raster (iTerm2 images are
3395
- * not cropped). SIXEL and iTerm2 have no delete command and composite over
3396
- * existing pixels, so erase the visible rows they paint above `screenRow`
3397
- * before repainting.
3404
+ * placement owner, while SIXEL crops the encoded raster. An iTerm2 image
3405
+ * or a Kitty transmit-and-display image cannot be cropped, so a block
3406
+ * clipped at the top is omitted rather than painted over following text.
3407
+ * SIXEL and iTerm2 have no delete command and composite over existing
3408
+ * pixels, so erase the visible rows they paint above the line before repainting.
3409
+ *
3410
+ * `frameRow` is the line's row within the frame it was rendered in, so at
3411
+ * most that many rows above it belong to its image block. A viewport whose
3412
+ * top clips a block sits below history rows on screen; bounding the lift by
3413
+ * the physical row instead would erase and paint over those history rows
3414
+ * just before they scroll into native scrollback.
3398
3415
  */
3399
3416
  #imageLineSequence(
3400
3417
  line: string,
3401
- screenRow: number,
3418
+ frameRow: number,
3402
3419
  placements: Map<number, LiveImagePlacement> | undefined,
3403
3420
  placementRow: number,
3404
3421
  ): string {
3405
- if (screenRow < 0) return line;
3422
+ if (frameRow < 0) return line;
3406
3423
  const parsed = parseKittyDirectPlacementLine(line);
3407
3424
  if (!parsed) {
3408
3425
  const requestedLift = directPlacementLift(line);
3409
- const lift = Math.min(requestedLift, screenRow);
3426
+ const lift = Math.min(requestedLift, frameRow);
3410
3427
  if (requestedLift > lift) {
3411
3428
  const cellHeight = getCellDimensions().heightPx;
3412
3429
  const cropPixels = Math.round((requestedLift - lift) * cellHeight);
3413
- const maxHeightPixels = Math.floor((screenRow + 1) * cellHeight);
3414
- line = line.replace(/\x1bP[0-9;]*q[\s\S]*?\x1b\\/g, sequence =>
3430
+ const maxHeightPixels = Math.floor((frameRow + 1) * cellHeight);
3431
+ const clipped = line.replace(/\x1bP[0-9;]*q[\s\S]*?\x1b\\/g, sequence =>
3415
3432
  this.#cropSixel(sequence, cropPixels, maxHeightPixels),
3416
3433
  );
3434
+ // Re-anchoring an uncropped OSC/APC image would paint its hidden
3435
+ // rows below the reserved slice, over the following text.
3436
+ if (clipped === line) return "";
3437
+ line = withDirectPlacementLift(clipped, lift);
3417
3438
  }
3418
3439
  return lift > 0 ? `\x1b[${lift}A${`${ERASE_LINE}\x1b[B`.repeat(lift)}${line}` : line;
3419
3440
  }
@@ -3428,7 +3449,7 @@ export class TUI extends Container {
3428
3449
  placementId,
3429
3450
  columns: parsed.columns,
3430
3451
  rows: parsed.rows,
3431
- screenRow,
3452
+ screenRow: frameRow,
3432
3453
  imageHeightPx: this.#imageBudget.getPlacementGeometry(parsed.imageId)?.heightPx ?? 0,
3433
3454
  })
3434
3455
  );
@@ -3501,6 +3522,16 @@ export class TUI extends Container {
3501
3522
  }
3502
3523
  }
3503
3524
 
3525
+ #notifyFrameWrite(data: string): void {
3526
+ for (const listener of this.#frameWriteListeners) {
3527
+ try {
3528
+ listener(data);
3529
+ } catch (err) {
3530
+ logger.error("TUI frame write listener failed", { err });
3531
+ }
3532
+ }
3533
+ }
3534
+
3504
3535
  #renderProviderFrame(mainWidth: number, rawWidth: number, height: number): void {
3505
3536
  const provider = this.#frameProvider;
3506
3537
  if (!provider || mainWidth <= 0 || height <= 0) return;
@@ -3825,9 +3856,9 @@ export class TUI extends Container {
3825
3856
  buffer += `\x1b[${newTop + index + 1};1H${this.#lineRewriteSequence(
3826
3857
  current,
3827
3858
  width,
3828
- newTop + index,
3859
+ index,
3829
3860
  this.#osc66SpacerGlyphWidth(prepared.lines, index),
3830
- { imagePlacements: this.#screenImagePlacements },
3861
+ { imagePlacements: this.#screenImagePlacements, imageRow: newTop + index },
3831
3862
  )}`;
3832
3863
  }
3833
3864
  if (this.#providerWindow.length > rows && newTop + rows < height) {
@@ -3870,15 +3901,18 @@ export class TUI extends Container {
3870
3901
  }
3871
3902
  for (let index = 0; index < rows; index++) {
3872
3903
  if (screenRow > startTop) buffer += "\n";
3904
+ // Replay-split rows continue the history ledger written above them;
3905
+ // the provider's own rows reach no higher than its viewport top.
3906
+ const moved = index < replayViewportRows;
3873
3907
  append(
3874
3908
  this.#lineRewriteSequence(
3875
3909
  prepared.rows[index]!,
3876
3910
  width,
3877
- Math.min(screenRow, height - 1),
3911
+ moved ? Math.min(screenRow, height - 1) : index,
3878
3912
  this.#osc66SpacerGlyphWidth(prepared.lines, index),
3879
3913
  {
3880
3914
  blankRow: compactReplay,
3881
- imagePlacements: index < replayViewportRows ? undefined : this.#screenImagePlacements,
3915
+ imagePlacements: moved ? undefined : this.#screenImagePlacements,
3882
3916
  imageRow: newTop + index,
3883
3917
  },
3884
3918
  ),
@@ -3915,6 +3949,7 @@ export class TUI extends Container {
3915
3949
  this.terminal.write(this.#rebuildNoticeSequence(width, height));
3916
3950
  }
3917
3951
  this.terminal.write(buffer);
3952
+ this.#notifyFrameWrite(buffer);
3918
3953
  this.#debugPaint = {
3919
3954
  lines: prepared.lines,
3920
3955
  windowTop: this.#debugNextWindowTop,
@@ -4512,10 +4547,15 @@ export class TUI extends Container {
4512
4547
  );
4513
4548
  }
4514
4549
 
4550
+ /**
4551
+ * Terminal bytes that rewrite one row. `frameRow` is the row's index within
4552
+ * the frame it belongs to (see {@link #imageLineSequence}); `imageRow`, the
4553
+ * physical row keying live Kitty placements, defaults to it.
4554
+ */
4515
4555
  #lineRewriteSequence(
4516
4556
  line: PreparedLine,
4517
4557
  width: number,
4518
- screenRow = -1,
4558
+ frameRow = -1,
4519
4559
  spacerGlyphWidth = -1,
4520
4560
  options?: { blankRow?: boolean; imagePlacements?: Map<number, LiveImagePlacement>; imageRow?: number },
4521
4561
  ): string {
@@ -4536,7 +4576,7 @@ export class TUI extends Container {
4536
4576
  } else if (line.isImage) {
4537
4577
  rewrite =
4538
4578
  ERASE_LINE +
4539
- this.#imageLineSequence(line.line, screenRow, options?.imagePlacements, options?.imageRow ?? screenRow);
4579
+ this.#imageLineSequence(line.line, frameRow, options?.imagePlacements, options?.imageRow ?? frameRow);
4540
4580
  } else {
4541
4581
  const terminalLine = this.#terminalLine(line);
4542
4582
  if (options?.blankRow) {
@@ -4728,9 +4768,9 @@ export class TUI extends Container {
4728
4768
  } else if (hideCursor) {
4729
4769
  cursorBuffer = "\x1b[?25l";
4730
4770
  }
4731
- this.terminal.write(
4732
- `${this.#paintBeginSequence}${prelude}${full ? "\x1b[H" : ""}${rowsBuffer}${cursorBuffer}${this.#paintEndSequence}`,
4733
- );
4771
+ const frame = `${this.#paintBeginSequence}${prelude}${full ? "\x1b[H" : ""}${rowsBuffer}${cursorBuffer}${this.#paintEndSequence}`;
4772
+ this.terminal.write(frame);
4773
+ this.#notifyFrameWrite(frame);
4734
4774
  this.#debugPaint = {
4735
4775
  lines: prepared.lines,
4736
4776
  windowTop: 0,
package/src/vim.d.ts CHANGED
@@ -64,13 +64,43 @@ export type VimCommand = {
64
64
  fromLine: number;
65
65
  toLine: number;
66
66
  out: boolean;
67
+ } | {
68
+ kind: "retype";
69
+ record: VimInsertRecord;
70
+ times: number;
71
+ newline: boolean;
72
+ overwrite: boolean;
67
73
  };
74
+ /** What an Insert/Replace session typed, relative to where it started; `.` replays it. */
75
+ export interface VimInsertRecord {
76
+ /** Graphemes removed before the session's start cursor (Backspace past the insert point). */
77
+ deleteBefore: number;
78
+ /** Graphemes removed after it (forward delete). */
79
+ deleteAfter: number;
80
+ text: string;
81
+ }
68
82
  /** Start offset of the grapheme after `col`, clamped to `text.length`. */
69
83
  export declare function nextGraphemeStart(text: string, col: number): number;
70
84
  /** Start offset of the grapheme before `col`, clamped to 0. */
71
85
  export declare function prevGraphemeStart(text: string, col: number): number;
72
86
  /** Offset of the final grapheme — where a Normal-mode cursor rests on a non-empty line. */
73
87
  export declare function lastGraphemeStart(text: string): number;
88
+ export declare function countGraphemes(text: string): number;
89
+ /** Offset `count` graphemes forward or backward from `offset`, clamped to the text. */
90
+ export declare function stepGraphemes(text: string, offset: number, count: number, forward: boolean): number;
91
+ /**
92
+ * What a session turned `before` into, anchored at its start `cursor`: the prefix match stops at the
93
+ * cursor and the suffix match never crosses it, so typing `aa` before an existing `a` records `aa`
94
+ * at the cursor rather than after the old one. Comparisons are whole graphemes, so a shared high
95
+ * surrogate cannot split an emoji into the replayed text.
96
+ */
97
+ export declare function diffInsertSession(before: string, cursor: number, after: string): VimInsertRecord;
98
+ /** Buffer flattened to one string plus the cursor's offset in it, so scans can cross lines. */
99
+ export declare function flatten(buf: VimBuffer): {
100
+ text: string;
101
+ cursor: number;
102
+ };
103
+ export declare function offsetToPos(lines: readonly string[], offset: number): VimPosition;
74
104
  export declare class VimState {
75
105
  #private;
76
106
  mode: VimMode;
@@ -94,6 +124,15 @@ export declare class VimState {
94
124
  * through to its regular handling (and, for Escape in Normal mode, to the app's interrupt).
95
125
  */
96
126
  handleKey(key: string, buf: VimBuffer): VimCommand[] | null;
127
+ /**
128
+ * Attach what an Insert/Replace session typed to the change that opened it. After an arrow key
129
+ * split the session, Vim's redo becomes a plain insert of the text typed since.
130
+ */
131
+ recordInsert(record: VimInsertRecord, afterArrow: boolean): void;
132
+ /** Commit a staged change when the editor confirms text changed. */
133
+ commitChange(): void;
134
+ /** Discard a staged change when the command was a no-op (e.g. `J` on the last line). */
135
+ discardChange(): void;
97
136
  }
98
137
  /**
99
138
  * Normalized, end-exclusive span covered by a Visual selection.