@oh-my-pi/pi-tui 18.14.2 → 18.16.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 (93) hide show
  1. package/CHANGELOG.md +64 -50
  2. package/README.md +1 -1
  3. package/dist/types/app-keybindings.d.ts +5 -0
  4. package/dist/types/apps/session-picker.d.ts +5 -3
  5. package/dist/types/chat/bash-execution.d.ts +4 -1
  6. package/dist/types/chat/eval-execution.d.ts +2 -0
  7. package/dist/types/chat/execution-shared.d.ts +14 -8
  8. package/dist/types/chat/transcript-render-helpers.d.ts +8 -0
  9. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  10. package/dist/types/chrome/transcript-status.d.ts +2 -2
  11. package/dist/types/components/editor.d.ts +15 -6
  12. package/dist/types/components/loader.d.ts +2 -0
  13. package/dist/types/keybinding-matchers.d.ts +7 -0
  14. package/dist/types/overlays/btw-history-panel.d.ts +13 -0
  15. package/dist/types/overlays/btw-history.d.ts +24 -0
  16. package/dist/types/overlays/btw-inject.d.ts +22 -0
  17. package/dist/types/overlays/btw-panel.d.ts +7 -0
  18. package/dist/types/overlays/hook-editor.d.ts +2 -0
  19. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  20. package/dist/types/overlays/session-selector.d.ts +24 -3
  21. package/dist/types/render/render-utils.d.ts +21 -1
  22. package/dist/types/status-line/startup.d.ts +0 -15
  23. package/dist/types/terminal-capabilities.d.ts +1 -1
  24. package/dist/types/theme/symbols.d.ts +3 -1
  25. package/dist/types/theme/theme-class.d.ts +1 -0
  26. package/dist/types/tools/grouped-file-output.d.ts +76 -8
  27. package/dist/types/tools/hashline-format.d.ts +5 -0
  28. package/dist/types/tools/native-view.d.ts +2 -0
  29. package/dist/types/tools/output-meta.d.ts +27 -0
  30. package/dist/types/tools/read.d.ts +10 -0
  31. package/dist/types/tools/wait.d.ts +2 -0
  32. package/dist/types/utils.d.ts +4 -0
  33. package/package.json +9 -9
  34. package/src/app-keybindings.ts +5 -0
  35. package/src/apps/session-picker.ts +7 -3
  36. package/src/chat/bash-execution.ts +20 -9
  37. package/src/chat/chat-transcript-builder.ts +5 -2
  38. package/src/chat/eval-execution.ts +14 -7
  39. package/src/chat/execution-shared.ts +39 -18
  40. package/src/chat/read-tool-group.ts +56 -36
  41. package/src/chat/transcript-render-helpers.ts +52 -6
  42. package/src/chrome/dynamic-border.ts +28 -2
  43. package/src/chrome/transcript-status.ts +5 -3
  44. package/src/components/editor.ts +123 -24
  45. package/src/components/key-value-list.ts +9 -9
  46. package/src/components/loader.ts +7 -0
  47. package/src/components/section.ts +1 -9
  48. package/src/components/table.ts +1 -9
  49. package/src/keybinding-matchers.ts +13 -0
  50. package/src/overlays/btw-history-panel.ts +98 -14
  51. package/src/overlays/btw-history.ts +65 -0
  52. package/src/overlays/btw-inject.ts +91 -0
  53. package/src/overlays/btw-panel.ts +53 -12
  54. package/src/overlays/hook-editor.ts +6 -0
  55. package/src/overlays/jobs-panel.ts +45 -19
  56. package/src/overlays/model-browser.ts +65 -8
  57. package/src/overlays/session-selector.ts +131 -26
  58. package/src/overlays/usage-dashboard.ts +2 -2
  59. package/src/render/code-cell.ts +1 -1
  60. package/src/render/file-list.ts +4 -7
  61. package/src/render/render-utils.ts +36 -6
  62. package/src/setup/scenes/glyph.ts +1 -1
  63. package/src/status-line/startup.ts +36 -70
  64. package/src/terminal-capabilities.ts +5 -0
  65. package/src/theme/symbols.ts +16 -9
  66. package/src/theme/theme-class.ts +3 -0
  67. package/src/tmux.ts +1 -0
  68. package/src/tools/agent-tree.ts +13 -11
  69. package/src/tools/ask.ts +13 -6
  70. package/src/tools/ast-edit.ts +48 -93
  71. package/src/tools/ast-grep.ts +22 -66
  72. package/src/tools/bash.ts +7 -0
  73. package/src/tools/default-renderer.ts +1 -1
  74. package/src/tools/edit.ts +50 -43
  75. package/src/tools/fetch.ts +2 -1
  76. package/src/tools/find.ts +6 -3
  77. package/src/tools/github.ts +14 -46
  78. package/src/tools/glob.ts +2 -1
  79. package/src/tools/grep.ts +43 -287
  80. package/src/tools/grouped-file-output.ts +250 -64
  81. package/src/tools/hashline-format.ts +5 -0
  82. package/src/tools/json-tree.ts +1 -5
  83. package/src/tools/lsp.ts +53 -25
  84. package/src/tools/native-view.ts +11 -5
  85. package/src/tools/output-meta.ts +68 -4
  86. package/src/tools/proc-render.ts +3 -3
  87. package/src/tools/read.ts +14 -0
  88. package/src/tools/task.ts +34 -77
  89. package/src/tools/vibe.ts +4 -4
  90. package/src/tools/wait.ts +8 -5
  91. package/src/tools/write.ts +17 -27
  92. package/src/tools/yield.ts +1 -1
  93. package/src/utils.ts +10 -0
@@ -10,7 +10,12 @@
10
10
  import { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
11
11
  import type { Model } from "@oh-my-pi/pi-ai";
12
12
  import { buildModel } from "@oh-my-pi/pi-catalog/build";
13
- import { getEffectiveTokenCost, getModelPricingStatus, modelsAreEqual } from "@oh-my-pi/pi-catalog/models";
13
+ import {
14
+ getEffectiveTokenCost,
15
+ getFactoryDroidCreditRate,
16
+ getModelPricingStatus,
17
+ modelsAreEqual,
18
+ } from "@oh-my-pi/pi-catalog/models";
14
19
  import { modelKind, type ModelKind, type ModelPricingStatus } from "@oh-my-pi/pi-catalog/types";
15
20
  import type { Component } from "../tui";
16
21
  import { FuzzyCorpus, fuzzyRank } from "../fuzzy";
@@ -747,7 +752,7 @@ function isFreeModel(model: Model): boolean {
747
752
  const declared = declaredPricingStatus(model);
748
753
  if (declared !== undefined) return declared === "free";
749
754
  const cost = model.cost ? getEffectiveTokenCost(model.cost) : undefined;
750
- const credits = model.factoryDroidCredits;
755
+ const credits = getFactoryDroidCreditRate(model)?.rate;
751
756
  return (!cost || (cost.input === 0 && cost.output === 0)) && (credits === undefined || credits === 0);
752
757
  }
753
758
 
@@ -761,15 +766,22 @@ function formatCostLeg(n: number): string {
761
766
  return s.includes(".") ? s.replace(/\.?0+$/, "") : s;
762
767
  }
763
768
 
769
+ /** `2× from 2026-11-22` when a dated Factory Droid credit card changes the rate in force now; undefined otherwise. */
770
+ function nextCreditRateNote(model: Model): string | undefined {
771
+ const next = getFactoryDroidCreditRate(model)?.next;
772
+ return next ? `${formatCostLeg(next.rate)}× from ${new Date(next.at).toISOString().slice(0, 10)}` : undefined;
773
+ }
774
+
764
775
  /**
765
- * Adds Factory Droid's `N×` base Standard Credits rate to a dollar price,
766
- * replacing the price when the model has no dollar reference. Neither the
767
- * reference price nor the base credit rate includes live promotions.
776
+ * Adds Factory Droid's `N×` Standard Credits rate in force now (its dated
777
+ * `credit-rates` card applied) to a dollar price, replacing the price when the
778
+ * model has no dollar reference. The dollar reference never includes vendor
779
+ * promotions; the preview and detail facts name the next rate (`nextCreditRateNote`).
768
780
  */
769
781
  function withCreditBadge(model: Model, price: string): string {
770
- const credits = model.factoryDroidCredits;
782
+ const credits = getFactoryDroidCreditRate(model);
771
783
  if (credits === undefined) return price;
772
- const badge = `${formatCostLeg(credits)}×`;
784
+ const badge = `${formatCostLeg(credits.rate)}×`;
773
785
  const cost = getEffectiveTokenCost(model.cost);
774
786
  return cost.input !== 0 || cost.output !== 0 ? `${price} ${badge}` : badge;
775
787
  }
@@ -820,7 +832,9 @@ function previewPrice(model: Model): string {
820
832
  const cost = getEffectiveTokenCost(model.cost);
821
833
  const parts = [`$${formatCostLeg(cost.input)} in`, `$${formatCostLeg(cost.output)} out`];
822
834
  if (cost.cacheRead > 0) parts.push(`$${formatCostLeg(cost.cacheRead)} cache`);
823
- return withCreditBadge(model, parts.join(" · "));
835
+ const priced = withCreditBadge(model, parts.join(" · "));
836
+ const note = nextCreditRateNote(model);
837
+ return note ? `${priced} (${note})` : priced;
824
838
  }
825
839
 
826
840
  /**
@@ -1025,6 +1039,8 @@ export class ModelBrowser implements Component {
1025
1039
  | undefined;
1026
1040
  /** Theme-formatted catalog metric cells per item; rebuilt when the item's model or the theme changes. */
1027
1041
  #metricCells = new WeakMap<ModelBrowserItem, MetricCells>();
1042
+ /** Earliest dated credit-rate change among models whose rows are memoized; passing it rebuilds them. */
1043
+ #nextCreditChange = Number.POSITIVE_INFINITY;
1028
1044
  /** Non-separator items of the last ranked visible list, for {@link queryMatches}. */
1029
1045
  #queryMatches: { visible: readonly ModelBrowserItem[]; matches: readonly ModelBrowserItem[] } | undefined;
1030
1046
  #hoveredIndex: number | null = null;
@@ -1116,6 +1132,7 @@ export class ModelBrowser implements Component {
1116
1132
 
1117
1133
  /** Replace the scope's base items; the live query re-applies and selection is pinned by selector. */
1118
1134
  setItems(items: ModelBrowserItem[]): void {
1135
+ for (const item of items) this.#noteCreditChange(item.model);
1119
1136
  const selectedKey = this.getSelected()?.selector;
1120
1137
  this.#menu.setItems(this.#insertSeparator(items), selectedKey);
1121
1138
  this.onSelectionChange?.(this.getSelected());
@@ -1511,6 +1528,7 @@ export class ModelBrowser implements Component {
1511
1528
  #metricCellsFor(item: ModelBrowserItem): MetricCells {
1512
1529
  const cached = this.#metricCells.get(item);
1513
1530
  if (cached?.model === item.model && cached.theme === theme) return cached;
1531
+ this.#noteCreditChange(item.model);
1514
1532
  const intelligence = formatIntelligence(item.model);
1515
1533
  const ctx = formatContext(item.model);
1516
1534
  const cost = formatCostPair(item.model);
@@ -1627,6 +1645,9 @@ export class ModelBrowser implements Component {
1627
1645
  } else if (model.tps != null && Number.isFinite(model.tps) && model.tps > 0) {
1628
1646
  facts.push(`~${formatTps(model.tps)}`);
1629
1647
  }
1648
+ // Last fact before prose, so narrow widths cut it before capability and perf facts.
1649
+ const nextCredits = nextCreditRateNote(model);
1650
+ if (nextCredits) facts.push(nextCredits);
1630
1651
  if (model.description) {
1631
1652
  const description = formatDescription(model.description);
1632
1653
  if (description) facts.push(description);
@@ -1658,6 +1679,7 @@ export class ModelBrowser implements Component {
1658
1679
  }
1659
1680
 
1660
1681
  render(width: number): string[] {
1682
+ this.#syncCreditClock();
1661
1683
  const lines: string[] = [];
1662
1684
 
1663
1685
  const searchIcon = theme.fg("accent", theme.symbol("icon.search"));
@@ -1749,6 +1771,30 @@ export class ModelBrowser implements Component {
1749
1771
 
1750
1772
  invalidate(): void {}
1751
1773
 
1774
+ /** Called for every listed model and before a row is memoized: its credit rate changes at its next dated card. */
1775
+ #noteCreditChange(model: Model): void {
1776
+ const at = getFactoryDroidCreditRate(model)?.next?.at;
1777
+ if (at !== undefined && at < this.#nextCreditChange) this.#nextCreditChange = at;
1778
+ }
1779
+
1780
+ /**
1781
+ * A dated credit rate took effect since rows were memoized: rebuild every
1782
+ * memoized row, and re-rank the list, whose `free` search word follows the
1783
+ * rate too.
1784
+ */
1785
+ #syncCreditClock(): void {
1786
+ if (Date.now() < this.#nextCreditChange) return;
1787
+ this.#nextCreditChange = Number.POSITIVE_INFINITY;
1788
+ this.#metricCells = new WeakMap();
1789
+ this.#pickerPreview = undefined;
1790
+ this.#bumpPickerEpoch();
1791
+ this.#ranker = undefined;
1792
+ this.#menu.setItems(this.#menu.items);
1793
+ for (const item of this.#menu.items) {
1794
+ if (item.id !== "separator") this.#noteCreditChange(item.model);
1795
+ }
1796
+ }
1797
+
1752
1798
  #bumpNativeEpoch(): void {
1753
1799
  this.#nativeEpoch++;
1754
1800
  this.#itemNodes.clear();
@@ -1767,6 +1813,7 @@ export class ModelBrowser implements Component {
1767
1813
  * scrolls), and the selection's facts and role chips.
1768
1814
  */
1769
1815
  describe(): NativeNode {
1816
+ this.#syncCreditClock();
1770
1817
  this.#nativeSearch ??= row([text([span(theme.symbol("icon.search"), "accent")]), this.#searchInput], {
1771
1818
  gap: "sm",
1772
1819
  align: "center",
@@ -1837,6 +1884,7 @@ export class ModelBrowser implements Component {
1837
1884
  if (item.id === "separator") return node("rule", undefined, undefined, "separator");
1838
1885
  const cached = this.#itemNodes.get(item.selector);
1839
1886
  if (cached?.item === item) return cached.node;
1887
+ this.#noteCreditChange(item.model);
1840
1888
 
1841
1889
  const label: TspSpan[] = [];
1842
1890
  if (this.#showProvider) label.push(span(`${item.provider}/`, "dim"));
@@ -1879,6 +1927,7 @@ export class ModelBrowser implements Component {
1879
1927
  return prev.node;
1880
1928
  }
1881
1929
 
1930
+ if (selected) this.#noteCreditChange(selected.model);
1882
1931
  const children: NativeChild[] = [];
1883
1932
  if (selected) {
1884
1933
  const model = selected.model;
@@ -1903,6 +1952,8 @@ export class ModelBrowser implements Component {
1903
1952
  } else if (model.tps != null && Number.isFinite(model.tps) && model.tps > 0) {
1904
1953
  facts.push(`~${formatTps(model.tps)}`);
1905
1954
  }
1955
+ const nextCredits = nextCreditRateNote(model);
1956
+ if (nextCredits) facts.push(nextCredits);
1906
1957
  children.push(text([span(facts.join(" · "), "muted")], { wrap: "word" }));
1907
1958
  const description = model.description ? formatDescription(model.description) : "";
1908
1959
  if (description) children.push(text([span(description, "dim")], { wrap: "word", lines: 2 }));
@@ -1977,6 +2028,7 @@ export class ModelBrowser implements Component {
1977
2028
  * role moving) keeps the last whole `items` and patches it.
1978
2029
  */
1979
2030
  pickerItems(catalogue: readonly ModelBrowserItem[]): ModelPickerCatalogue {
2031
+ this.#syncCreditClock();
1980
2032
  const memo = this.#pickerItems;
1981
2033
  if (memo?.catalogue === catalogue && memo.epoch === this.#pickerEpoch && memo.roles === this.#roles) {
1982
2034
  return memo.value;
@@ -2028,6 +2080,7 @@ export class ModelBrowser implements Component {
2028
2080
  ) {
2029
2081
  return cached.value;
2030
2082
  }
2083
+ this.#noteCreditChange(model);
2031
2084
  const facts: Record<string, TspText | number> = {};
2032
2085
  const int = model.int != null && Number.isFinite(model.int) ? model.int : undefined;
2033
2086
  if (int !== undefined) facts.int = String(Math.round(int));
@@ -2174,6 +2227,7 @@ export class ModelBrowser implements Component {
2174
2227
  * below the list): one inline fact line and the held-role chips.
2175
2228
  */
2176
2229
  pickerPreview(mode: "full" | "compact", current?: string): readonly NativeChild[] {
2230
+ this.#syncCreditClock();
2177
2231
  const selected = this.getSelected();
2178
2232
  const item = selected && !this.#isDisabled(selected) ? selected : undefined;
2179
2233
  const key = `${mode}\0${current ?? ""}\0${this.#settings.revision}`;
@@ -2187,6 +2241,7 @@ export class ModelBrowser implements Component {
2187
2241
  ) {
2188
2242
  return memo.children;
2189
2243
  }
2244
+ if (item) this.#noteCreditChange(item.model);
2190
2245
  const children = item ? this.modelPreview(item, mode, current) : [];
2191
2246
  this.#pickerPreview = { item, epoch: this.#pickerEpoch, roles: this.#roles, key, children };
2192
2247
  return children;
@@ -2232,6 +2287,8 @@ export class ModelBrowser implements Component {
2232
2287
  if (ctx > 0) facts.push({ k: "ctx", v: formatNumber(ctx).toLowerCase() });
2233
2288
  if (out > 0) facts.push({ k: "out", v: formatNumber(out).toLowerCase() });
2234
2289
  facts.push({ k: "price", v: isFreeModel(model) ? "free" : formatCostDetail(model) });
2290
+ const nextCredits = nextCreditRateNote(model);
2291
+ if (nextCredits) facts.push({ k: "then", v: nextCredits });
2235
2292
  facts.push({ k: "reasoning", v: model.reasoning ? "yes" : "no" });
2236
2293
  const children: NativeChild[] = [node("kv", { items: facts, layout: "inline" })];
2237
2294
  const chips: NativeChild[] = [];
@@ -52,6 +52,17 @@ export interface SessionSelectorEntry {
52
52
  /** Path to the parent session when this one was forked. */
53
53
  parentSessionPath?: string;
54
54
  }
55
+
56
+ /**
57
+ * One picker scope's rows, possibly in two passes: `sessions` show at once
58
+ * (e.g. rows built from a title index), and `complete` settles with the full
59
+ * listing that replaces them, keeping the query, the selected session, and
60
+ * deletes/renames made meanwhile.
61
+ */
62
+ export interface SessionListing<T extends SessionSelectorEntry = SessionSelectorEntry> {
63
+ sessions: T[];
64
+ complete?: Promise<T[]>;
65
+ }
55
66
  import { shortenPath } from "../render/render-utils";
56
67
  import { formTheme } from "../chrome/form-theme";
57
68
  import { HookSelectorComponent } from "./hook-selector";
@@ -309,6 +320,17 @@ function sessionTextLower(session: SessionSelectorEntry): string {
309
320
  return textLower;
310
321
  }
311
322
 
323
+ /**
324
+ * Set a session's title and drop the caches built from the old one: the
325
+ * native row embeds it and the search haystack holds it, so the next describe
326
+ * rebuilds the row and search matches the new title.
327
+ */
328
+ function retitle(session: SessionSelectorEntry, title: string): void {
329
+ session.title = title;
330
+ delete (session as NativeSessionInfo)[kNativeItem];
331
+ delete (session as SearchableSessionInfo)[kSearchTextLower];
332
+ }
333
+
312
334
  function tokenizeSessionQuery(query: string): string[] {
313
335
  const trimmed = query.trim().toLowerCase();
314
336
  return trimmed ? trimmed.split(/\s+/) : [];
@@ -638,6 +660,22 @@ class SessionList<T extends SessionSelectorEntry> implements Component {
638
660
  if (index >= 0) this.#menu.setSelectedIndex(index);
639
661
  }
640
662
 
663
+ /**
664
+ * Swap in the complete listing of the shown scope (a scan that finished
665
+ * after the picker opened), keeping the query and the selected session:
666
+ * rows arriving above the cursor never move it onto another session.
667
+ */
668
+ refreshSessions(sessions: T[], showCwd: boolean): void {
669
+ const selected = this.#menu.selectedItem?.path;
670
+ const moved = this.#selectionMoved;
671
+ this.#datasetVersion++;
672
+ this.#allSessions = sessions;
673
+ this.#showCwd = showCwd;
674
+ this.#filterSessions(this.#searchInput.getValue());
675
+ if (selected !== undefined) this.#menu.setSelectedKey(selected);
676
+ this.#selectionMoved = moved;
677
+ }
678
+
641
679
  /** Replace the visible dataset, e.g. when toggling folder/all-projects scope. */
642
680
  setSessions(sessions: T[], showCwd: boolean, pinnedIds?: ReadonlySet<string>): void {
643
681
  this.#datasetVersion++;
@@ -837,14 +875,9 @@ class SessionList<T extends SessionSelectorEntry> implements Component {
837
875
  const entry = this.#allSessions.find(s => s.path === sessionPath);
838
876
  if (!entry) return;
839
877
  this.#datasetVersion++;
840
- entry.title = title;
841
- // The cached native item embeds the old title, and the search haystack
842
- // caches it too: drop both so the next describe rebuilds the row and
843
- // the literal/fuzzy search paths match the new title. Selection is
844
- // path-keyed, so the same-query refilter keeps the cursor on the
845
- // renamed session.
846
- delete (entry as NativeSessionInfo)[kNativeItem];
847
- delete (entry as SearchableSessionInfo)[kSearchTextLower];
878
+ // Selection is path-keyed, so the same-query refilter keeps the cursor
879
+ // on the renamed session.
880
+ retitle(entry, title);
848
881
  this.#filterSessions(this.#searchInput.getValue());
849
882
  }
850
883
 
@@ -1430,10 +1463,15 @@ export interface SessionSelectorOptions<T extends SessionSelectorEntry = Session
1430
1463
  /** Persist the selected session's pin state (pin keys / the picker's Pin action). */
1431
1464
  onSetPinned?: (session: T, pinned: boolean) => Promise<void>;
1432
1465
  historyMatcher?: SessionHistoryMatcher;
1466
+ /**
1467
+ * Complete folder listing when the constructor's `sessions` are a
1468
+ * preliminary subset; replaces them once it settles (see {@link SessionListing}).
1469
+ */
1470
+ completeSessions?: Promise<T[]>;
1433
1471
  /** Loads sessions across all projects for the all-projects scope toggle (Tab). */
1434
- loadAllSessions?: () => Promise<T[]>;
1435
- /** Preloaded all-projects list; cached so the first Tab toggle is instant. */
1436
- allSessions?: T[];
1472
+ loadAllSessions?: () => Promise<SessionListing<T>>;
1473
+ /** Preloaded all-projects listing; cached so the first Tab toggle is instant. */
1474
+ allSessions?: SessionListing<T>;
1437
1475
  /** Picker heading; defaults to "Resume Session". */
1438
1476
  title?: string;
1439
1477
  /** Primary action label; defaults to "Resume" (ANSI footer defaults to "select"). */
@@ -1492,10 +1530,18 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1492
1530
  #onRename?: (session: T, title: string) => Promise<string | null>;
1493
1531
  #onSetPinned?: (session: T, pinned: boolean) => Promise<void>;
1494
1532
  #onRequestRender?: () => void;
1495
- readonly #loadAllSessions?: () => Promise<T[]>;
1533
+ readonly #loadAllSessions?: () => Promise<SessionListing<T>>;
1496
1534
  #folderSessions: T[];
1497
- readonly #folderShowCwd: boolean;
1535
+ readonly #showCwdOption: boolean | undefined;
1498
1536
  #globalSessions: T[] | null = null;
1537
+ /** Paths deleted in this picker: a listing scanned before the delete must not bring them back. */
1538
+ readonly #deletedPaths = new Set<string>();
1539
+ /** Titles renamed in this picker, by path: a listing scanned before the rename must not revert them. */
1540
+ readonly #renamedTitles = new Map<string, string>();
1541
+ /** The picker resolved (select, cancel, exit) or was disposed; {@link unlockInput} reopens it after a failed resume. */
1542
+ #closed = false;
1543
+ /** The shown scope's complete listing landed while closed; {@link unlockInput} shows it. */
1544
+ #refreshPending = false;
1499
1545
  #scope: "folder" | "all" = "folder";
1500
1546
  #toggling = false;
1501
1547
  #inputLocked = false;
@@ -1565,10 +1611,8 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1565
1611
  this.#onSetPinned = options.onSetPinned;
1566
1612
  this.#loadAllSessions = options.loadAllSessions;
1567
1613
  this.#folderSessions = sessions;
1568
- // Storage directory, not recorded cwd: one folder's sessions may record
1569
- // symlink aliases of the same path, which must not turn the column on.
1570
- this.#folderShowCwd = options.showCwd ?? new Set(sessions.map(session => path.dirname(session.path))).size > 1;
1571
- this.#globalSessions = options.allSessions ?? null;
1614
+ this.#showCwdOption = options.showCwd;
1615
+ this.#globalSessions = options.allSessions?.sessions ?? null;
1572
1616
  this.#getTerminalRows = options.getTerminalRows ?? (() => 24);
1573
1617
  this.#fillHeight = options.fillHeight ?? false;
1574
1618
  this.#title = options.title ?? "Resume Session";
@@ -1586,7 +1630,7 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1586
1630
  // projects' history (issue #3099).
1587
1631
  this.#sessionList = new SessionList(
1588
1632
  sessions,
1589
- this.#folderShowCwd,
1633
+ this.#folderShowCwd(),
1590
1634
  options.historyMatcher,
1591
1635
  options.getTerminalRows,
1592
1636
  options.pinnedIds,
@@ -1595,14 +1639,17 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1595
1639
  // Every exit path cancels the list's pending history merge, so a stale
1596
1640
  // debounce timer can never run its SQLite lookup after the picker closed.
1597
1641
  this.#sessionList.onSelect = session => {
1642
+ this.#closed = true;
1598
1643
  this.#sessionList.dispose();
1599
1644
  onSelect(session);
1600
1645
  };
1601
1646
  this.#sessionList.onCancel = () => {
1647
+ this.#closed = true;
1602
1648
  this.#sessionList.dispose();
1603
1649
  onCancel();
1604
1650
  };
1605
1651
  this.#sessionList.onExit = () => {
1652
+ this.#closed = true;
1606
1653
  this.#sessionList.dispose();
1607
1654
  onExit();
1608
1655
  };
@@ -1630,6 +1677,60 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1630
1677
  this.#contentSlot = new Container();
1631
1678
  this.#contentSlot.addChild(this.#sessionList);
1632
1679
  this.addChild(this.#contentSlot);
1680
+ this.#awaitComplete("folder", { sessions, complete: options.completeSessions });
1681
+ if (options.allSessions) this.#awaitComplete("all", options.allSessions);
1682
+ }
1683
+
1684
+ /**
1685
+ * Whether folder rows show their directory: when the caller did not say,
1686
+ * when they span storage directories (e.g. merged worktrees). Storage
1687
+ * directory, not recorded cwd: one folder's sessions may record symlink
1688
+ * aliases of the same path, which must not turn the column on.
1689
+ */
1690
+ #folderShowCwd(): boolean {
1691
+ return this.#showCwdOption ?? new Set(this.#folderSessions.map(session => path.dirname(session.path))).size > 1;
1692
+ }
1693
+
1694
+ /**
1695
+ * Replace `scope`'s preliminary rows with `listing.complete` once it
1696
+ * settles. A failed scan keeps the preliminary rows and reports the error.
1697
+ */
1698
+ #awaitComplete(scope: "folder" | "all", listing: SessionListing<T>): void {
1699
+ void listing.complete?.then(
1700
+ sessions => {
1701
+ // Settled to the preliminary rows themselves: nothing new to show.
1702
+ if (sessions === listing.sessions) return;
1703
+ const next = this.#withEdits(sessions);
1704
+ if (scope === "folder") this.#folderSessions = next;
1705
+ else this.#globalSessions = next;
1706
+ if (scope !== this.#scope) return;
1707
+ if (this.#closed) this.#refreshPending = true;
1708
+ else this.#refreshShownScope();
1709
+ },
1710
+ (err: unknown) => {
1711
+ if (this.#closed) return;
1712
+ this.#showError(err instanceof Error ? err.message : String(err));
1713
+ this.#onRequestRender?.();
1714
+ },
1715
+ );
1716
+ }
1717
+
1718
+ #refreshShownScope(): void {
1719
+ this.#refreshPending = false;
1720
+ if (this.#scope === "folder") this.#sessionList.refreshSessions(this.#folderSessions, this.#folderShowCwd());
1721
+ else if (this.#globalSessions) this.#sessionList.refreshSessions(this.#globalSessions, true);
1722
+ this.#onRequestRender?.();
1723
+ }
1724
+
1725
+ /** `sessions` with this picker's deletes and renames applied. */
1726
+ #withEdits(sessions: T[]): T[] {
1727
+ if (this.#deletedPaths.size === 0 && this.#renamedTitles.size === 0) return sessions;
1728
+ const kept = sessions.filter(session => !this.#deletedPaths.has(session.path));
1729
+ for (const session of kept) {
1730
+ const title = this.#renamedTitles.get(session.path);
1731
+ if (title !== undefined) retitle(session, title);
1732
+ }
1733
+ return kept;
1633
1734
  }
1634
1735
 
1635
1736
  #headerLabel(): string {
@@ -1654,15 +1755,18 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1654
1755
  this.#messageContainer.addChild(new Text(theme.fg("muted", "Loading all projects…"), 0, 0));
1655
1756
  this.#message = { kind: "loading", text: "Loading all projects…" };
1656
1757
  this.#onRequestRender?.();
1758
+ let listing: SessionListing<T>;
1657
1759
  try {
1658
- global = await this.#loadAllSessions();
1760
+ listing = await this.#loadAllSessions();
1659
1761
  } catch (err) {
1660
1762
  this.#showError(err instanceof Error ? err.message : String(err));
1661
1763
  this.#toggling = false;
1662
1764
  this.#onRequestRender?.();
1663
1765
  return;
1664
1766
  }
1767
+ global = this.#withEdits(listing.sessions);
1665
1768
  this.#globalSessions = global;
1769
+ this.#awaitComplete("all", listing);
1666
1770
  this.#messageContainer.clear();
1667
1771
  this.#message = undefined;
1668
1772
  this.#toggling = false;
@@ -1671,7 +1775,7 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1671
1775
  this.#sessionList.setSessions(global, true);
1672
1776
  } else {
1673
1777
  this.#scope = "folder";
1674
- this.#sessionList.setSessions(this.#folderSessions, this.#folderShowCwd);
1778
+ this.#sessionList.setSessions(this.#folderSessions, this.#folderShowCwd());
1675
1779
  }
1676
1780
  this.title = this.#headerLabel();
1677
1781
  this.#onRequestRender?.();
@@ -1687,6 +1791,8 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1687
1791
  /** Re-enable input after a failed resume so the user can pick again. */
1688
1792
  unlockInput(): void {
1689
1793
  this.#inputLocked = false;
1794
+ this.#closed = false;
1795
+ if (this.#refreshPending) this.#refreshShownScope();
1690
1796
  }
1691
1797
 
1692
1798
  /**
@@ -1695,6 +1801,7 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1695
1801
  * child-walking dispose would miss its pending history-merge timer.
1696
1802
  */
1697
1803
  override dispose(): void {
1804
+ this.#closed = true;
1698
1805
  this.#sessionList.dispose();
1699
1806
  clearTimeout(this.#previewTimer);
1700
1807
  super.dispose();
@@ -1731,6 +1838,7 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1731
1838
  try {
1732
1839
  const deleted = await this.#onDelete(session);
1733
1840
  if (deleted) {
1841
+ this.#deletedPaths.add(session.path);
1734
1842
  this.#sessionList.removeSession(session.path);
1735
1843
  this.#folderSessions = this.#folderSessions.filter(s => s.path !== session.path);
1736
1844
  if (this.#globalSessions) {
@@ -1775,13 +1883,10 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1775
1883
  * them or a scope switch shows the old title again.
1776
1884
  */
1777
1885
  #syncScopeTitles(sessionPath: string, title: string): void {
1886
+ this.#renamedTitles.set(sessionPath, title);
1778
1887
  for (const cache of [this.#folderSessions, this.#globalSessions]) {
1779
- if (!cache) continue;
1780
- const entry = cache.find(s => s.path === sessionPath);
1781
- if (!entry) continue;
1782
- entry.title = title;
1783
- delete (entry as NativeSessionInfo)[kNativeItem];
1784
- delete (entry as SearchableSessionInfo)[kSearchTextLower];
1888
+ const entry = cache?.find(s => s.path === sessionPath);
1889
+ if (entry) retitle(entry, title);
1785
1890
  }
1786
1891
  }
1787
1892
 
@@ -649,8 +649,8 @@ export interface UsageDashboardOptions {
649
649
  export function formatActivityErrorDetail(error: string, homeDir = os.homedir()): string {
650
650
  let text = replaceTabs(sanitizeText(error)).replace(/\s+/g, " ").trim();
651
651
  if (homeDir) {
652
- const escaped = homeDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
653
- const forward = homeDir.replaceAll("\\", "/").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
652
+ const escaped = RegExp.escape(homeDir);
653
+ const forward = RegExp.escape(homeDir.replaceAll("\\", "/"));
654
654
  text = text.replace(new RegExp(`${escaped}|${forward}`, "gi"), "~");
655
655
  }
656
656
  return text.replace(/\.+$/, "");
@@ -74,7 +74,7 @@ function formatHeader(options: CodeCellOptions, theme: Theme): { title: string;
74
74
  if (status) {
75
75
  const icon = formatStatusIcon(
76
76
  status === "complete"
77
- ? "done"
77
+ ? "success"
78
78
  : status === "error"
79
79
  ? "error"
80
80
  : status === "warning"
@@ -6,6 +6,7 @@ import { node, span } from "../native/describe";
6
6
  import type { NativeNode } from "../native/node";
7
7
  import type { Theme } from "../theme/theme";
8
8
  import { fileLinkSpan } from "./hyperlink";
9
+ import { formatStyledPath } from "./render-utils";
9
10
  import { renderTreeList } from "./tree-list";
10
11
 
11
12
  /** A file-list item with optional display metadata. */
@@ -69,15 +70,11 @@ export function renderFileList(options: FileListOptions, theme: Theme): string[]
69
70
  const isDirectory = entry.isDirectory ?? entry.path.endsWith("/");
70
71
  const displayPath = entry.path;
71
72
  const lang = isDirectory ? undefined : getLanguageFromPath(displayPath);
72
- const icon = !showIcons
73
- ? ""
74
- : isDirectory
75
- ? theme.fg("accent", theme.icon.folder)
76
- : theme.fg("muted", theme.getLangIcon(lang));
77
- const labelColor = isDirectory ? "accent" : "toolOutput";
73
+ // Type icons stay muted beside the dim directory and colored file name.
74
+ const icon = !showIcons ? "" : theme.fg("muted", isDirectory ? theme.icon.folder : theme.getLangIcon(lang));
78
75
  const meta = entry.meta ? ` ${theme.fg("dim", entry.meta)}` : "";
79
76
  const iconPrefix = icon ? `${icon} ` : "";
80
- const pathStr = theme.fg(labelColor, displayPath);
77
+ const pathStr = formatStyledPath(displayPath, theme);
81
78
  const linkedPath = entry.absPath && hyperlinkFn ? hyperlinkFn(entry.absPath, pathStr) : pathStr;
82
79
  return `${iconPrefix}${linkedPath}${meta}`;
83
80
  },
@@ -13,7 +13,7 @@ import { expandWindowsLongPath, getWindowsShortPath } from "@oh-my-pi/pi-natives
13
13
  import { pluralize, sanitizeText } from "@oh-my-pi/pi-utils";
14
14
  import { formatKeyHint, type KeyId } from "../app-keybindings";
15
15
  import { getKeybindings } from "../keybindings";
16
- import type { Theme } from "../theme/theme";
16
+ import type { Theme, ThemeColor } from "../theme/theme";
17
17
  import type { Component } from "../tui";
18
18
  import { replaceTabs, sliceByColumn, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../utils";
19
19
  import { Hasher } from "./utils";
@@ -293,9 +293,8 @@ export { formatAge, formatBytes, formatCount, formatDuration, formatNumber, plur
293
293
  export function formatStatusIcon(status: ToolUIStatus, theme: Theme, spinnerFrame?: number): string {
294
294
  switch (status) {
295
295
  case "success":
296
- return theme.styledSymbol("status.success", "success");
297
296
  case "done":
298
- return theme.styledSymbol("status.done", "success");
297
+ return theme.styledSymbol("status.success", "success");
299
298
  case "error":
300
299
  return theme.styledSymbol("status.error", "error");
301
300
  case "warning":
@@ -435,6 +434,34 @@ export function formatEmptyMessage(message: string, theme: Theme): string {
435
434
  return `${theme.styledSymbol("status.warning", "warning")} ${theme.fg("muted", message)}`;
436
435
  }
437
436
 
437
+ /**
438
+ * Color of a file's name, or a whole URL, in tool bodies: it keeps paths apart
439
+ * from the tool titles above them (bronze in titanium).
440
+ */
441
+ export const FILE_NAME_COLOR = "customMessageLabel" satisfies ThemeColor;
442
+
443
+ /**
444
+ * Where a display path's final segment (file or folder name) starts, past its
445
+ * last `/` or `\` separator; a trailing-slash directory keeps its slash on the
446
+ * name. Shared by the terminal ({@link formatStyledPath}) and Tern file rows.
447
+ */
448
+ export function pathNameStart(filePath: string): number {
449
+ let end = filePath.length;
450
+ while (end > 0 && (filePath[end - 1] === "/" || filePath[end - 1] === "\\")) end--;
451
+ return end === 0 ? 0 : Math.max(filePath.lastIndexOf("/", end - 1), filePath.lastIndexOf("\\", end - 1)) + 1;
452
+ }
453
+
454
+ /**
455
+ * A file path in a tool body: the directory (with its trailing separator) dim,
456
+ * the final segment in {@link FILE_NAME_COLOR}. Tool headers keep paths in
457
+ * their plain subject color instead.
458
+ */
459
+ export function formatStyledPath(filePath: string, theme: Theme): string {
460
+ const cut = pathNameStart(filePath);
461
+ const name = theme.fg(FILE_NAME_COLOR, filePath.slice(cut));
462
+ return cut > 0 ? `${theme.fg("dim", filePath.slice(0, cut))}${name}` : name;
463
+ }
464
+
438
465
  // =============================================================================
439
466
  // Code Frame Formatting
440
467
  // =============================================================================
@@ -459,7 +486,10 @@ export function formatCodeFrameLine(
459
486
  // Tool UI Helpers
460
487
  // =============================================================================
461
488
 
462
- /** Status states supported by shared tool renderer icons. */
489
+ /**
490
+ * Status states supported by shared tool renderer icons. `done` is a deprecated
491
+ * alias of `success`, kept for extension renderers.
492
+ */
463
493
  export type ToolUIStatus = "success" | "done" | "error" | "warning" | "info" | "pending" | "running" | "aborted";
464
494
  /** Semantic foreground colors used by tool renderer labels. */
465
495
  export type ToolUIColor = "success" | "error" | "warning" | "accent" | "muted";
@@ -600,7 +630,7 @@ export function formatDiagnostics(
600
630
  const fileBranch = isLastFileNode ? theme.tree.last : theme.tree.branch;
601
631
 
602
632
  const fileIcon = theme.fg("muted", getLangIcon(filePath));
603
- output += `\n ${theme.fg("dim", fileBranch)} ${fileIcon} ${theme.fg("accent", filePath)}`;
633
+ output += `\n ${theme.fg("dim", fileBranch)} ${fileIcon} ${formatStyledPath(filePath, theme)}`;
604
634
 
605
635
  for (let di = 0; di < diagnostics.length && diagsShown < maxDiags; di++) {
606
636
  const d = diagnostics[di];
@@ -624,7 +654,7 @@ export function formatDiagnostics(
624
654
  : d.severity === "warning"
625
655
  ? theme.styledSymbol("status.warning", "warning")
626
656
  : theme.styledSymbol("status.info", "muted");
627
- const location = theme.fg("dim", `:${d.line}:${d.col}`);
657
+ const location = theme.fg("muted", `:${d.line}:${d.col}`);
628
658
  const codeTag = d.code ? theme.fg("dim", ` (${d.code})`) : "";
629
659
  const msgColor = d.severity === "error" ? "error" : d.severity === "warning" ? "warning" : "toolOutput";
630
660
 
@@ -20,7 +20,7 @@ const GLYPH_LABELS: Readonly<Record<SymbolPreset, string>> = {
20
20
  const GLYPH_SAMPLES: Readonly<Record<SymbolPreset, string>> = {
21
21
  nerd: "   󰉋 ",
22
22
  unicode: "✔ ✖ 📁 ⬢ ╭─╮ ├─ • ⠋ →",
23
- ascii: "[ok] [x] > + [D] +-+ |-- * ->",
23
+ ascii: "[+] [-] > + [D] +-+ |-- * ->",
24
24
  };
25
25
 
26
26
  /** One picker row per preset; the description column shows live sample glyphs instead of prose. */