@oh-my-pi/pi-tui 18.7.0 → 18.8.0

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 (79) hide show
  1. package/CHANGELOG.md +21 -52
  2. package/dist/types/apps/debug/log-viewer.d.ts +4 -0
  3. package/dist/types/apps/debug/raw-sse-buffer.d.ts +2 -0
  4. package/dist/types/chat/fence-figure.d.ts +42 -0
  5. package/dist/types/chat/svg-figure.d.ts +1 -1
  6. package/dist/types/chat/tool-execution.d.ts +2 -0
  7. package/dist/types/components/editor.d.ts +8 -3
  8. package/dist/types/components/markdown.d.ts +11 -6
  9. package/dist/types/fuzzy.d.ts +17 -3
  10. package/dist/types/native/backend.d.ts +2 -1
  11. package/dist/types/native/blobs.d.ts +4 -2
  12. package/dist/types/native/encode.d.ts +3 -4
  13. package/dist/types/overlays/agent-transcript-viewer.d.ts +8 -1
  14. package/dist/types/overlays/history-search.d.ts +10 -0
  15. package/dist/types/overlays/model-browser.d.ts +6 -0
  16. package/dist/types/prompt/custom-editor.d.ts +7 -4
  17. package/dist/types/prompt/interactive-context-helpers.d.ts +2 -1
  18. package/dist/types/tools/renderer.d.ts +22 -0
  19. package/dist/types/tools/streaming-output.d.ts +11 -1
  20. package/dist/types/tools/write.d.ts +8 -1
  21. package/package.json +9 -9
  22. package/src/apps/debug/log-viewer.ts +188 -72
  23. package/src/apps/debug/raw-sse-buffer.ts +8 -0
  24. package/src/apps/debug/raw-sse.ts +39 -5
  25. package/src/apps/git/diff-pane.ts +26 -5
  26. package/src/autocomplete.ts +59 -33
  27. package/src/chat/assistant-message.ts +30 -18
  28. package/src/chat/fence-figure.ts +80 -0
  29. package/src/chat/svg-figure.ts +2 -4
  30. package/src/chat/tool-execution.ts +53 -4
  31. package/src/components/editor.ts +16 -3
  32. package/src/components/markdown.ts +80 -307
  33. package/src/fuzzy.ts +59 -14
  34. package/src/native/backend.ts +170 -15
  35. package/src/native/blobs.ts +4 -2
  36. package/src/native/encode.ts +58 -31
  37. package/src/overlays/agent-hub-projection.ts +70 -2
  38. package/src/overlays/agent-hub.ts +3 -2
  39. package/src/overlays/agent-transcript-viewer.ts +64 -13
  40. package/src/overlays/agents-hub.ts +14 -7
  41. package/src/overlays/copy-selector.ts +30 -8
  42. package/src/overlays/extensions/state-manager.ts +52 -12
  43. package/src/overlays/history-search.ts +100 -7
  44. package/src/overlays/jobs-panel.ts +30 -2
  45. package/src/overlays/model-browser.ts +107 -21
  46. package/src/overlays/model-hub.ts +34 -7
  47. package/src/overlays/oauth-selector.ts +41 -26
  48. package/src/overlays/plan-review-overlay.ts +142 -64
  49. package/src/overlays/rewind-selector.ts +86 -17
  50. package/src/overlays/session-selector.ts +24 -4
  51. package/src/overlays/settings-selector.ts +21 -6
  52. package/src/overlays/tree-selector.ts +20 -4
  53. package/src/overlays/usage-dashboard.ts +12 -15
  54. package/src/prompt/attachment-chips.ts +2 -1
  55. package/src/prompt/composer-attachments.ts +6 -4
  56. package/src/prompt/custom-editor.ts +48 -19
  57. package/src/prompt/interactive-context-helpers.ts +27 -18
  58. package/src/prompt/macos-spelling.ts +7 -0
  59. package/src/prompt/magic-keywords.ts +11 -2
  60. package/src/prompt/word-completion.ts +38 -5
  61. package/src/setup/scenes/splash.ts +109 -45
  62. package/src/status-line/component.ts +220 -64
  63. package/src/status-line/segments.ts +5 -2
  64. package/src/terminal.ts +3 -2
  65. package/src/tools/ast-edit.ts +59 -35
  66. package/src/tools/ast-grep.ts +35 -16
  67. package/src/tools/default-renderer.ts +35 -19
  68. package/src/tools/eval-format/index.ts +28 -2
  69. package/src/tools/eval-format/javascript.ts +7 -5
  70. package/src/tools/eval.ts +164 -78
  71. package/src/tools/grep.ts +81 -48
  72. package/src/tools/lsp.ts +81 -59
  73. package/src/tools/mcp.ts +98 -68
  74. package/src/tools/renderer.ts +27 -0
  75. package/src/tools/streaming-output.ts +120 -48
  76. package/src/tools/task.ts +111 -54
  77. package/src/tools/todo.ts +115 -29
  78. package/src/tools/wait.ts +34 -24
  79. package/src/tools/write.ts +77 -39
@@ -51,8 +51,10 @@ import type {
51
51
  ComposerFactsSource,
52
52
  EffectiveStatusLineSettings,
53
53
  SegmentView,
54
+ SeparatorDef,
54
55
  StatusLineSegmentId,
55
56
  StatusLineSegmentOptions,
57
+ StatusLineSeparatorStyle,
56
58
  StatusLineSettings,
57
59
  } from "./types";
58
60
 
@@ -214,12 +216,51 @@ function reportMatchesExactIdentity(report: UsageReport, identity: OAuthAccountI
214
216
  // Context-usage memo
215
217
  // ═══════════════════════════════════════════════════════════════════════════
216
218
 
219
+ /**
220
+ * Serialized length of tool-call arguments, memoized per arguments object.
221
+ * Streaming providers may grow the same object in place (at any depth), so
222
+ * each entry keeps a shape check — key/element counts plus string and number
223
+ * lengths over the whole tree — and is recomputed when it differs, without
224
+ * re-serializing the whole (possibly multi-KB edit/write) payload on every
225
+ * status-line rebuild.
226
+ */
227
+ const toolArgumentsLengthCache = new WeakMap<object, { check: number; length: number }>();
228
+
229
+ /** Past this depth the check stops descending; JSON.stringify rejects real cycles anyway. */
230
+ const SHAPE_CHECK_MAX_DEPTH = 32;
231
+
232
+ function toolArgumentsShapeCheck(value: unknown, depth = 0): number {
233
+ if (typeof value === "string") return value.length + 1;
234
+ if (typeof value === "number" || typeof value === "bigint") return String(value).length + 1;
235
+ if (value === null || typeof value !== "object" || depth >= SHAPE_CHECK_MAX_DEPTH) return 1;
236
+ let check = 1;
237
+ for (const child of Object.values(value)) check += 1 + toolArgumentsShapeCheck(child, depth + 1);
238
+ return check;
239
+ }
240
+
241
+ function toolArgumentsLength(args: unknown): number {
242
+ if (typeof args === "string") return args.length;
243
+ if (args === null || typeof args !== "object") return String(args).length;
244
+ const check = toolArgumentsShapeCheck(args);
245
+ const cached = toolArgumentsLengthCache.get(args);
246
+ if (cached !== undefined && cached.check === check) return cached.length;
247
+ let length: number;
248
+ try {
249
+ length =
250
+ JSON.stringify(args, (_key, value) => (typeof value === "bigint" ? value.toString() : value))?.length ?? 0;
251
+ } catch {
252
+ length = String(args).length;
253
+ }
254
+ toolArgumentsLengthCache.set(args, { check, length });
255
+ return length;
256
+ }
257
+
217
258
  /**
218
259
  * Cheap structural fingerprint of a message's tokenizable content. O(blocks) —
219
- * only reads string `.length` and primitives, never copies or serializes.
220
- * Detects in-place growth of the streaming tail (and other in-place mutations)
221
- * so the cached `getContextUsage()` result is recomputed when — and only when —
222
- * the numbers it depends on change.
260
+ * only reads string `.length`, primitives, and memoized tool-argument sizes;
261
+ * never copies. Detects growth of the streaming tail (in-place text appends,
262
+ * freshly parsed tool arguments) so the cached `getContextUsage()` result is
263
+ * recomputed when — and only when — the numbers it depends on change.
223
264
  */
224
265
  function messageFingerprint(msg: AgentMessage): string {
225
266
  const role = (msg as { role?: string }).role ?? "";
@@ -301,15 +342,7 @@ function messageFingerprint(msg: AgentMessage): string {
301
342
  redactedLen += b.data.length;
302
343
  } else if (b.type === "toolCall") {
303
344
  if (typeof b.name === "string") textLen += b.name.length;
304
- if (b.arguments !== undefined) {
305
- try {
306
- textLen += JSON.stringify(b.arguments, (_key, value) =>
307
- typeof value === "bigint" ? value.toString() : value,
308
- ).length;
309
- } catch {
310
- textLen += String(b.arguments).length;
311
- }
312
- }
345
+ if (b.arguments !== undefined) textLen += toolArgumentsLength(b.arguments);
313
346
  }
314
347
  }
315
348
  }
@@ -421,6 +454,25 @@ interface CachedStatusLine {
421
454
  externalInputs: StatusLineExternalInputs;
422
455
  }
423
456
 
457
+ /** Dot separator of the plain (borderless) layouts; carries no caps. */
458
+ const PLAIN_SEPARATOR: SeparatorDef = { left: "·", right: "·" };
459
+
460
+ /** A separator style's glyphs and cell widths: theme-pure, so measured once per theme. */
461
+ interface SeparatorMetrics {
462
+ themeRef: unknown;
463
+ themeEpoch: number;
464
+ style: StatusLineSeparatorStyle;
465
+ def: SeparatorDef;
466
+ leftSepWidth: number;
467
+ rightSepWidth: number;
468
+ /** Left group's closing cap (`endCaps.right`); 0 without caps. */
469
+ leftCapWidth: number;
470
+ /** Right group's opening cap (`endCaps.left`); 0 without caps. */
471
+ rightCapWidth: number;
472
+ /** Band layout's flush-left soft cap; 0 without caps. */
473
+ bandCapWidth: number;
474
+ }
475
+
424
476
  interface ActiveRepoCache {
425
477
  projectDir: string;
426
478
  activeRepo: ActiveRepoContext | null;
@@ -580,10 +632,21 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
580
632
  };
581
633
  #statusLineInputRevision = 0;
582
634
  #statusLineClockTick = 0;
635
+ /**
636
+ * Earliest wall-clock ms at which a TTL-throttled VCS cache the render path
637
+ * served goes stale (git/jj status, watcher-less branch poll, repository
638
+ * re-probe, PR activity refresh); `Infinity` when none can. The first frame
639
+ * past it expires the render memo so the getters refetch — instead of a
640
+ * fixed polling tick that rebuilt the whole bar every second.
641
+ */
642
+ #vcsStaleAt = Number.POSITIVE_INFINITY;
583
643
  /** Reused probe buffer for {@link #readStatusLineExternalInputs}; handed to the new cache entry on a miss. */
584
644
  #externalInputsProbe = new StatusLineExternalInputs();
585
645
  /** `adjustHsv` result for the gauge's threshold tint; pure in its source hex. */
586
646
  #dimmedAccentMemo: { sourceHex: string; hex: string } | undefined;
647
+ /** Separator widths for the plain and the styled (box/band) layouts; see {@link #separatorMetrics}. */
648
+ #plainSeparatorMetrics: SeparatorMetrics | undefined;
649
+ #styledSeparatorMetrics: SeparatorMetrics | undefined;
587
650
  /** Gauge boundary markers; a pure function of the session's compaction settings, model, and window. */
588
651
  #compactionBoundariesMemo:
589
652
  | {
@@ -807,27 +870,46 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
807
870
  #resolveRepository(cache: ActiveRepoCache): VcsRepo | null {
808
871
  if (cache.repository) return cache.repository;
809
872
  const now = Date.now();
810
- if (now - cache.repositoryCheckedAt < WATCHER_FAILURE_POLL_TTL_MS) return null;
811
- cache.repository = vcs.repo(cache.effectiveGitCwd);
812
- cache.repositoryCheckedAt = now;
873
+ if (now - cache.repositoryCheckedAt >= WATCHER_FAILURE_POLL_TTL_MS) {
874
+ cache.repository = vcs.repo(cache.effectiveGitCwd);
875
+ cache.repositoryCheckedAt = now;
876
+ }
877
+ // Still absent: re-probe on the bounded interval so a later `git init` shows up.
878
+ if (!cache.repository) this.#noteVcsStaleAt(cache.repositoryCheckedAt + WATCHER_FAILURE_POLL_TTL_MS);
813
879
  return cache.repository;
814
880
  }
815
881
 
816
882
  #resolveDisplayRepository(cache: ActiveRepoCache): VcsRepo | null {
817
883
  if (cache.displayRepository) return cache.displayRepository;
818
884
  const now = Date.now();
819
- if (now - cache.displayRepositoryCheckedAt < WATCHER_FAILURE_POLL_TTL_MS) return null;
820
- let display: VcsRepo | null;
821
- try {
822
- display = vcs.repoForDisplay(cache.effectiveGitCwd);
823
- } catch {
824
- display = null;
885
+ if (now - cache.displayRepositoryCheckedAt >= WATCHER_FAILURE_POLL_TTL_MS) {
886
+ let display: VcsRepo | null;
887
+ try {
888
+ display = vcs.repoForDisplay(cache.effectiveGitCwd);
889
+ } catch {
890
+ display = null;
891
+ }
892
+ cache.displayRepository = display ?? cache.repository;
893
+ cache.displayRepositoryCheckedAt = now;
894
+ }
895
+ if (!cache.displayRepository) {
896
+ this.#noteVcsStaleAt(cache.displayRepositoryCheckedAt + WATCHER_FAILURE_POLL_TTL_MS);
825
897
  }
826
- cache.displayRepository = display ?? cache.repository;
827
- cache.displayRepositoryCheckedAt = now;
828
898
  return cache.displayRepository;
829
899
  }
830
900
 
901
+ /** Lower {@link #vcsStaleAt} to `at` when a served VCS cache expires sooner. */
902
+ #noteVcsStaleAt(at: number): void {
903
+ if (at < this.#vcsStaleAt) this.#vcsStaleAt = at;
904
+ }
905
+
906
+ /** Expire the render memo once a served VCS cache has gone stale, so this frame refetches. */
907
+ #expireStaleVcsRender(nowMs: number): void {
908
+ if (nowMs < this.#vcsStaleAt) return;
909
+ this.#vcsStaleAt = Number.POSITIVE_INFINITY;
910
+ this.#invalidateStatusLineRenderCache();
911
+ }
912
+
831
913
  /**
832
914
  * Re-point the status line at another session (focus proxy). Invalidate: model/context/usage all derive
833
915
  * from it. `focusedAgentId` is the focused subagent id while the view is proxied, undefined for main.
@@ -1228,7 +1310,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1228
1310
  * a 40ms frame timer so the fade keeps animating after the working loader
1229
1311
  * (the usual repaint driver) has stopped.
1230
1312
  */
1231
- #brandFgAnsi(working: boolean, sessionAccentEnabled: boolean): string {
1313
+ #brandFgAnsi(working: boolean, sessionAccentEnabled: boolean, brandVisible: boolean): string {
1232
1314
  const sessionName = sessionAccentEnabled ? this.session.sessionManager?.getSessionName() : undefined;
1233
1315
  const idleHex = theme.getColorHex("dim");
1234
1316
  const workingHex =
@@ -1242,7 +1324,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1242
1324
  startedAt: now,
1243
1325
  };
1244
1326
  this.#brandWorking = working;
1245
- this.#startBrandFadeTimer();
1327
+ // Only a visible `pi` segment needs fade frames; other bars stay quiet.
1328
+ if (brandVisible) this.#startBrandFadeTimer();
1246
1329
  }
1247
1330
  const hex = this.#sampleBrandHex(working ? workingHex : idleHex, now);
1248
1331
  return getSessionAccentAnsi(hex) ?? theme.getFgAnsi(working ? "accent" : "dim");
@@ -1441,7 +1524,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1441
1524
  taggedRepository[GIT_VIEW] = gitRepository;
1442
1525
  }
1443
1526
  if (!gitRepository) {
1444
- if (this.#jjBranchActive || Date.now() - this.#jjBranchLastFetch < JJ_REFRESH_TTL_MS) {
1527
+ if (this.#jjBranchActive) return this.#cachedJjBranch;
1528
+ if (Date.now() - this.#jjBranchLastFetch < JJ_REFRESH_TTL_MS) {
1529
+ this.#noteVcsStaleAt(this.#jjBranchLastFetch + JJ_REFRESH_TTL_MS);
1445
1530
  return this.#cachedJjBranch;
1446
1531
  }
1447
1532
  const request: JjResolveRequest = {
@@ -1468,6 +1553,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1468
1553
  if (this.#jjCacheGeneration === generation) this.#jjBranchLastFetch = Date.now();
1469
1554
  }
1470
1555
  if (this.#jjCacheGeneration !== generation || this.#disposed) return;
1556
+ this.#noteVcsStaleAt(this.#jjBranchLastFetch + JJ_REFRESH_TTL_MS);
1471
1557
  const changed = next !== this.#cachedJjBranch;
1472
1558
  this.#cachedJjBranch = next;
1473
1559
  if (changed) {
@@ -1481,6 +1567,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1481
1567
  this.#gitWatcherUnavailable &&
1482
1568
  (this.#branchLastFetch === undefined || Date.now() - this.#branchLastFetch >= WATCHER_FAILURE_POLL_TTL_MS);
1483
1569
  if (this.#cachedBranch !== undefined && this.#cachedBranchCwd === gitCwd && !fallbackCacheExpired) {
1570
+ if (this.#gitWatcherUnavailable && this.#branchLastFetch !== undefined) {
1571
+ this.#noteVcsStaleAt(this.#branchLastFetch + WATCHER_FAILURE_POLL_TTL_MS);
1572
+ }
1484
1573
  return this.#cachedBranch;
1485
1574
  }
1486
1575
 
@@ -1533,6 +1622,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1533
1622
  this.#cachedBranchRepoId = repoId;
1534
1623
  this.#cachedBranch = next;
1535
1624
  this.#branchLastFetch = Date.now();
1625
+ if (this.#gitWatcherUnavailable) {
1626
+ this.#noteVcsStaleAt(this.#branchLastFetch + WATCHER_FAILURE_POLL_TTL_MS);
1627
+ }
1536
1628
  if (prev !== next) {
1537
1629
  this.#invalidateStatusLineRenderCache();
1538
1630
  this.#onBranchChange?.();
@@ -1553,6 +1645,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1553
1645
  this.#cachedBranchCwd = gitCwd;
1554
1646
  this.#cachedBranchRepoId = gitHeadPath;
1555
1647
  this.#branchLastFetch = Date.now();
1648
+ if (this.#gitWatcherUnavailable) this.#noteVcsStaleAt(this.#branchLastFetch + WATCHER_FAILURE_POLL_TTL_MS);
1556
1649
  if (!head) {
1557
1650
  this.#cachedBranch = null;
1558
1651
  return null;
@@ -1594,7 +1687,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1594
1687
  const repository = this.#resolveRepository(activeRepoCache);
1595
1688
  if (!repository) return null;
1596
1689
  if (repository.kind() === "jj") {
1597
- if (this.#jjStatusActive || Date.now() - this.#jjStatusLastFetch < JJ_REFRESH_TTL_MS) {
1690
+ if (this.#jjStatusActive) return this.#cachedJjStatus;
1691
+ if (Date.now() - this.#jjStatusLastFetch < JJ_REFRESH_TTL_MS) {
1692
+ this.#noteVcsStaleAt(this.#jjStatusLastFetch + JJ_REFRESH_TTL_MS);
1598
1693
  return this.#cachedJjStatus;
1599
1694
  }
1600
1695
  const request: JjResolveRequest = {
@@ -1616,6 +1711,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1616
1711
  if (this.#jjCacheGeneration === generation) this.#jjStatusLastFetch = Date.now();
1617
1712
  }
1618
1713
  if (this.#jjCacheGeneration !== generation || this.#disposed) return;
1714
+ this.#noteVcsStaleAt(this.#jjStatusLastFetch + JJ_REFRESH_TTL_MS);
1619
1715
  const prev = this.#cachedJjStatus;
1620
1716
  this.#cachedJjStatus = next;
1621
1717
  if (JSON.stringify(prev) !== JSON.stringify(next)) {
@@ -1630,6 +1726,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1630
1726
  return this.#cachedGitStatusCwd === gitCwd ? this.#cachedGitStatus : null;
1631
1727
  }
1632
1728
  if (this.#cachedGitStatusCwd === gitCwd && Date.now() - this.#gitStatusLastFetch < GIT_STATUS_TTL_MS) {
1729
+ this.#noteVcsStaleAt(this.#gitStatusLastFetch + GIT_STATUS_TTL_MS);
1633
1730
  return this.#cachedGitStatus;
1634
1731
  }
1635
1732
 
@@ -1649,6 +1746,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1649
1746
  this.#cachedGitStatusCwd = gitCwd;
1650
1747
  this.#gitStatusLastFetch = this.#gitStatusGeneration === generation ? Date.now() : 0;
1651
1748
  this.#gitStatusInFlightCwd = undefined;
1749
+ // A zeroed stamp (superseded generation) is already due: refetch next frame.
1750
+ this.#noteVcsStaleAt(this.#gitStatusLastFetch + GIT_STATUS_TTL_MS);
1652
1751
  if (!this.#disposed && JSON.stringify(prev) !== JSON.stringify(nextStatus)) {
1653
1752
  this.#invalidateStatusLineRenderCache();
1654
1753
  this.#onBranchChange?.();
@@ -2369,7 +2468,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2369
2468
  const gitPr = includePr ? this.#lookupPr(activeRepoCache) : null;
2370
2469
  const compactionSpeculation = this.session.compactionSpeculation ?? "idle";
2371
2470
  this.#syncSpeculationBlink(compactionSpeculation);
2372
- const sessionAccentEnabled = this.#resolveSettings().sessionAccent !== false;
2471
+ const settings = this.#resolveSettings();
2472
+ const sessionAccentEnabled = settings.sessionAccent !== false;
2473
+ const brandVisible = settings.leftSegments.includes("pi") || settings.rightSegments.includes("pi");
2373
2474
  const turnElapsedMs = this.getTurnElapsedMs();
2374
2475
  return {
2375
2476
  session: this.session,
@@ -2408,7 +2509,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2408
2509
  activeMs: this.getActiveMs(),
2409
2510
  turnElapsedMs,
2410
2511
  now: new Date(nowMs),
2411
- brandFgAnsi: this.#brandFgAnsi(turnElapsedMs !== null, sessionAccentEnabled),
2512
+ brandFgAnsi: this.#brandFgAnsi(turnElapsedMs !== null, sessionAccentEnabled, brandVisible),
2412
2513
  git: {
2413
2514
  branch: gitBranch,
2414
2515
  status: gitStatus,
@@ -2637,19 +2738,30 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2637
2738
 
2638
2739
  /**
2639
2740
  * Smallest wall-clock unit that can change a visible configured segment.
2640
- * A zero tick keeps truly static bars cached indefinitely; active animation,
2641
- * clocks, countdowns, and VCS fallback polling advance only at their own
2642
- * display/probe cadence.
2741
+ * A zero tick keeps truly static bars cached indefinitely; animation, clocks,
2742
+ * and countdowns advance only at their own display cadence. VCS refreshes are
2743
+ * deadline-driven ({@link #expireStaleVcsRender}), not ticked.
2643
2744
  */
2644
2745
  #statusLineClock(nowMs: number, effectiveSettings: EffectiveStatusLineSettings): number {
2645
2746
  const leftSegments = effectiveSettings.leftSegments;
2646
2747
  const rightSegments = effectiveSettings.rightSegments;
2647
- const meter = this.#meter();
2648
- if (meter.activeStartedAt !== null || this.#brandFade !== null) {
2748
+ const turnActive = this.#meter().activeStartedAt !== null;
2749
+ // The `pi` brand is the only spinner-rate animation: its braille spinner
2750
+ // while a turn runs and its color fade across turn edges. While
2751
+ // focus-proxied it shows the viewed agent's id instead.
2752
+ if (
2753
+ (turnActive || this.#brandFade !== null) &&
2754
+ this.#focusedAgentId === undefined &&
2755
+ (leftSegments.includes("pi") || rightSegments.includes("pi"))
2756
+ ) {
2649
2757
  return Math.floor(nowMs / SPINNER_ADVANCE_MS);
2650
2758
  }
2651
2759
  const includesTime = leftSegments.includes("time") || rightSegments.includes("time");
2652
2760
  if (
2761
+ // A running turn also moves readouts that have no invalidation path of
2762
+ // their own (background-job badge, live and vibe-worker tok/s): refresh
2763
+ // them once a second instead of on the spinner tick.
2764
+ turnActive ||
2653
2765
  leftSegments.includes("time_spent") ||
2654
2766
  rightSegments.includes("time_spent") ||
2655
2767
  (this.#loopModeStatus?.limit?.kind === "duration" &&
@@ -2661,12 +2773,6 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2661
2773
  if (includesTime) {
2662
2774
  return Math.floor(nowMs / 60_000);
2663
2775
  }
2664
- if (this.#gitEnabled() && (hasGitBackedSegment(leftSegments) || hasGitBackedSegment(rightSegments))) {
2665
- return Math.floor(nowMs / 1_000);
2666
- }
2667
- if (this.#gitEnabled() && (hasPathSegment(leftSegments) || hasPathSegment(rightSegments))) {
2668
- return Math.floor(nowMs / WATCHER_FAILURE_POLL_TTL_MS);
2669
- }
2670
2776
  return 0;
2671
2777
  }
2672
2778
 
@@ -2675,6 +2781,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2675
2781
  const externalInputs = this.#externalInputsProbe;
2676
2782
  this.#readStatusLineExternalInputs(externalInputs);
2677
2783
  const nowMs = Date.now();
2784
+ this.#expireStaleVcsRender(nowMs);
2678
2785
  const clockTick = this.#statusLineClock(nowMs, effectiveSettings);
2679
2786
  if (clockTick !== this.#statusLineClockTick) {
2680
2787
  this.#statusLineClockTick = clockTick;
@@ -2710,6 +2817,33 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2710
2817
  return result;
2711
2818
  }
2712
2819
 
2820
+ /**
2821
+ * Separator glyphs and cell widths for the plain or styled layouts, measured
2822
+ * once per theme (and style) instead of on every rebuild.
2823
+ */
2824
+ #separatorMetrics(plain: boolean, style: StatusLineSeparatorStyle): SeparatorMetrics {
2825
+ const themeEpoch = getThemeEpoch();
2826
+ const memo = plain ? this.#plainSeparatorMetrics : this.#styledSeparatorMetrics;
2827
+ if (memo && memo.themeRef === theme && memo.themeEpoch === themeEpoch && (plain || memo.style === style)) {
2828
+ return memo;
2829
+ }
2830
+ const def = plain ? PLAIN_SEPARATOR : getSeparator(style, theme);
2831
+ const metrics: SeparatorMetrics = {
2832
+ themeRef: theme,
2833
+ themeEpoch,
2834
+ style,
2835
+ def,
2836
+ leftSepWidth: visibleWidth(def.left),
2837
+ rightSepWidth: visibleWidth(def.right),
2838
+ leftCapWidth: def.endCaps ? visibleWidth(def.endCaps.right) : 0,
2839
+ rightCapWidth: def.endCaps ? visibleWidth(def.endCaps.left) : 0,
2840
+ bandCapWidth: def.endCaps ? visibleWidth(theme.sep.powerlineCapLeft) : 0,
2841
+ };
2842
+ if (plain) this.#plainSeparatorMetrics = metrics;
2843
+ else this.#styledSeparatorMetrics = metrics;
2844
+ return metrics;
2845
+ }
2846
+
2713
2847
  /**
2714
2848
  * Build the status bar for one of five layouts:
2715
2849
  * - `box`: powerline groups joined by the context-reactive gauge line
@@ -2746,9 +2880,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2746
2880
  nowMs,
2747
2881
  previewTitle,
2748
2882
  );
2749
- const separatorDef = plain
2750
- ? { left: "·", right: "·" }
2751
- : getSeparator(effectiveSettings.separator ?? "powerline-thin", theme);
2883
+ const separators = this.#separatorMetrics(plain, effectiveSettings.separator ?? "powerline-thin");
2884
+ const separatorDef = separators.def;
2752
2885
 
2753
2886
  // `transparent` reuses the empty-string sentinel (`\x1b[49m`) so the bar
2754
2887
  // inherits the terminal's default background, matching custom themes that
@@ -2819,17 +2952,18 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2819
2952
  const leftWidths = left.map(part => visibleWidth(part));
2820
2953
  const rightWidths = right.map(part => visibleWidth(part));
2821
2954
 
2822
- const leftSepWidth = visibleWidth(separatorDef.left);
2823
- const rightSepWidth = visibleWidth(separatorDef.right);
2955
+ const leftSepWidth = separators.leftSepWidth;
2956
+ const rightSepWidth = separators.rightSepWidth;
2824
2957
  // Transparent mode drops powerline caps (they need a bg fill to bridge),
2825
2958
  // so the width budget excludes them too.
2826
- const leftCapWidth = separatorDef.endCaps && !transparentBg ? visibleWidth(separatorDef.endCaps.right) : 0;
2827
- const rightCapWidth = separatorDef.endCaps && !transparentBg ? visibleWidth(separatorDef.endCaps.left) : 0;
2959
+ const capsVisible = separatorDef.endCaps !== undefined && !transparentBg;
2960
+ const leftCapWidth = capsVisible ? separators.leftCapWidth : 0;
2961
+ const rightCapWidth = capsVisible ? separators.rightCapWidth : 0;
2828
2962
  // The band layout opens flush against the terminal edge with a soft cap
2829
2963
  // (rust omp's status band). Like the other caps it needs an opaque
2830
2964
  // background to bridge, and only powerline separator styles carry caps.
2831
- const bandCap = layout === "band" && separatorDef.endCaps && !transparentBg ? theme.sep.powerlineCapLeft : "";
2832
- const bandCapWidth = visibleWidth(bandCap);
2965
+ const bandCap = layout === "band" && capsVisible ? theme.sep.powerlineCapLeft : "";
2966
+ const bandCapWidth = bandCap ? separators.bandCapWidth : 0;
2833
2967
 
2834
2968
  const groupWidth = (widths: number[], capWidth: number, sepWidth: number): number => {
2835
2969
  if (widths.length === 0) return 0;
@@ -3096,29 +3230,51 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
3096
3230
  }
3097
3231
  const thresholdColor = getSessionAccentAnsi(dimmedAccent.hex) ?? usedColor;
3098
3232
 
3233
+ // Emit runs, not cells: each stretch of plain rule between markers and
3234
+ // labels is one `repeat`, and color escapes change only at run edges.
3235
+ // Precedence per cell: percent label > threshold > speculation > window label.
3236
+ const percentEnd = percentStart >= 0 ? percentStart + percentLabel.length : -1;
3237
+ const windowEnd = windowStart >= 0 ? windowStart + windowLabel.length : -1;
3099
3238
  let out = "\x1b[49m";
3100
3239
  let activeColor = "";
3101
- for (let i = 0; i < gapWidth; i++) {
3102
- let color = i < usedCount ? usedColor : unusedColor;
3103
- let glyph = horizontal;
3104
- if (percentStart >= 0 && i >= percentStart && i < percentStart + percentLabel.length) {
3240
+ let i = 0;
3241
+ while (i < gapWidth) {
3242
+ let color: string;
3243
+ let text: string;
3244
+ if (i >= percentStart && i < percentEnd) {
3245
+ const end = Math.min(percentEnd, gapWidth);
3105
3246
  color = percentOverflow ? overflowColor : usedColor;
3106
- glyph = percentLabel.charAt(i - percentStart);
3247
+ text = percentLabel.slice(i - percentStart, end - percentStart);
3248
+ i = end;
3107
3249
  } else if (i === thresholdIdx) {
3108
3250
  color = thresholdColor;
3109
- glyph = thresholdGlyph;
3251
+ text = thresholdGlyph;
3252
+ i++;
3110
3253
  } else if (i === speculationIdx) {
3111
3254
  color = speculationColor;
3112
- glyph = speculationGlyph;
3113
- } else if (windowStart >= 0 && i >= windowStart && i < windowStart + windowLabel.length) {
3114
- color = thresholdColor;
3115
- glyph = windowLabel.charAt(i - windowStart);
3255
+ text = speculationGlyph;
3256
+ i++;
3257
+ } else {
3258
+ const inWindow = i >= windowStart && i < windowEnd;
3259
+ let end = Math.min(inWindow ? windowEnd : i < usedCount ? usedCount : gapWidth, gapWidth);
3260
+ if (percentStart > i && percentStart < end) end = percentStart;
3261
+ if (thresholdIdx > i && thresholdIdx < end) end = thresholdIdx;
3262
+ if (speculationIdx > i && speculationIdx < end) end = speculationIdx;
3263
+ if (!inWindow && windowStart > i && windowStart < end) end = windowStart;
3264
+ if (inWindow) {
3265
+ color = thresholdColor;
3266
+ text = windowLabel.slice(i - windowStart, end - windowStart);
3267
+ } else {
3268
+ color = i < usedCount ? usedColor : unusedColor;
3269
+ text = horizontal.repeat(end - i);
3270
+ }
3271
+ i = end;
3116
3272
  }
3117
3273
  if (color !== activeColor) {
3118
3274
  out += color;
3119
3275
  activeColor = color;
3120
3276
  }
3121
- out += glyph;
3277
+ out += text;
3122
3278
  }
3123
3279
  return `${out}\x1b[39m`;
3124
3280
  }
@@ -3305,6 +3461,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
3305
3461
  const probe = this.#nativeInputsProbe;
3306
3462
  this.#readStatusLineExternalInputs(probe);
3307
3463
  const nowMs = Date.now();
3464
+ this.#expireStaleVcsRender(nowMs);
3308
3465
  const clockTick = this.#nativeClock(nowMs, effectiveSettings);
3309
3466
  const memo = this.#nativeMemo;
3310
3467
  if (
@@ -3491,7 +3648,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
3491
3648
  /**
3492
3649
  * Wall-clock granularity of the native bar. Spinners, turn timers and the
3493
3650
  * brand fade are terminal-clocked, so only wall-clock text (time, loop
3494
- * countdowns) and VCS fallback polling advance it.
3651
+ * countdowns) advances it; VCS refreshes are deadline-driven
3652
+ * ({@link #expireStaleVcsRender}).
3495
3653
  */
3496
3654
  #nativeClock(nowMs: number, effectiveSettings: EffectiveStatusLineSettings): number {
3497
3655
  const segments = [...effectiveSettings.leftSegments, ...effectiveSettings.rightSegments];
@@ -3503,8 +3661,6 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
3503
3661
  return Math.floor(nowMs / 1_000);
3504
3662
  }
3505
3663
  if (includesTime) return Math.floor(nowMs / 60_000);
3506
- if (this.#gitEnabled() && hasGitBackedSegment(segments)) return Math.floor(nowMs / 1_000);
3507
- if (this.#gitEnabled() && hasPathSegment(segments)) return Math.floor(nowMs / WATCHER_FAILURE_POLL_TTL_MS);
3508
3664
  return 0;
3509
3665
  }
3510
3666
 
@@ -969,16 +969,19 @@ const sessionSegment: StatusLineSegment = {
969
969
  },
970
970
  };
971
971
 
972
+ /** Short (first-label) machine hostname; resolved once — `os.hostname()` is a syscall per call. */
973
+ let shortHostname: string | undefined;
974
+
972
975
  const hostnameSegment: StatusLineSegment = {
973
976
  id: "hostname",
974
977
  render(ctx) {
975
- const name = ctx.hostname ?? os.hostname().split(".")[0];
978
+ const name = ctx.hostname ?? (shortHostname ??= os.hostname().split(".")[0]);
976
979
  const content = withIcon(theme.icon.host, name);
977
980
  const ansi = sessionAccentAnsi(ctx);
978
981
  return { content: ansi ? `${ansi}${content}\x1b[39m` : content, visible: true };
979
982
  },
980
983
  describe(ctx) {
981
- const name = ctx.hostname ?? os.hostname().split(".")[0];
984
+ const name = ctx.hostname ?? (shortHostname ??= os.hostname().split(".")[0]);
982
985
  return segView([span(name, sessionAccentAnsi(ctx) ? "accent" : undefined)], "host");
983
986
  },
984
987
  };
package/src/terminal.ts CHANGED
@@ -1799,10 +1799,11 @@ export class ProcessTerminal implements Terminal {
1799
1799
 
1800
1800
  #handleTspMessage(sequence: string): void {
1801
1801
  const message = parseTspMessage(sequence);
1802
- if (message?.verb === "r") {
1803
- if (message.reply.r === "hello") this.#resolveTspSupport(message.reply);
1802
+ if (message?.verb === "r" && message.reply.r === "hello") {
1803
+ this.#resolveTspSupport(message.reply);
1804
1804
  return;
1805
1805
  }
1806
+ // Events and every other reply (`blobs`) go to the native backend.
1806
1807
  this.#inputHandler?.(sequence);
1807
1808
  }
1808
1809