omp-fabric 1.27.2 → 1.28.1

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 (121) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +1 -1
  3. package/dist/capture/interceptor.d.ts.map +1 -1
  4. package/dist/chunks/{chunk-OJZNMROB.js → chunk-4PPAWZM6.js} +36 -50
  5. package/dist/chunks/chunk-4PPAWZM6.js.map +7 -0
  6. package/dist/chunks/{chunk-KIH3KLZU.js → chunk-C2YMZNT5.js} +5 -5
  7. package/dist/chunks/chunk-C2YMZNT5.js.map +7 -0
  8. package/dist/chunks/chunk-CHXPTZUF.js +277 -0
  9. package/dist/chunks/chunk-CHXPTZUF.js.map +7 -0
  10. package/dist/chunks/chunk-CYNNPPN4.js +93 -0
  11. package/dist/chunks/chunk-CYNNPPN4.js.map +7 -0
  12. package/dist/chunks/{chunk-ANHZ3SWB.js → chunk-DGKGPZET.js} +9 -4
  13. package/dist/chunks/{chunk-ANHZ3SWB.js.map → chunk-DGKGPZET.js.map} +2 -2
  14. package/dist/chunks/{chunk-2BOZMRT5.js → chunk-FVNEGH4J.js} +32 -49
  15. package/dist/chunks/chunk-FVNEGH4J.js.map +7 -0
  16. package/dist/chunks/{chunk-CNCRWY4Q.js → chunk-GS6IWGXQ.js} +9 -1
  17. package/dist/chunks/chunk-GS6IWGXQ.js.map +7 -0
  18. package/dist/chunks/{chunk-7QKSPNXQ.js → chunk-V5FB7D4C.js} +3 -3
  19. package/dist/chunks/chunk-VDYGBL4Z.js +132 -0
  20. package/dist/chunks/chunk-VDYGBL4Z.js.map +7 -0
  21. package/dist/chunks/chunk-XVA63H6I.js +151 -0
  22. package/dist/chunks/chunk-XVA63H6I.js.map +7 -0
  23. package/dist/chunks/{chunk-NOZBB266.js → chunk-XZIQGFF7.js} +9 -13
  24. package/dist/chunks/chunk-XZIQGFF7.js.map +7 -0
  25. package/dist/chunks/{chunk-4XLJPEI4.js → chunk-ZJ7HHWW4.js} +20 -41
  26. package/dist/chunks/chunk-ZJ7HHWW4.js.map +7 -0
  27. package/dist/config.d.ts +2 -0
  28. package/dist/config.d.ts.map +1 -1
  29. package/dist/core/approval-controller.d.ts.map +1 -1
  30. package/dist/fabric-exec-tool.d.ts.map +1 -1
  31. package/dist/fabric-runtime-state.js +5 -3
  32. package/dist/fabric-runtime-state.js.map +1 -1
  33. package/dist/host-compatibility.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +180 -170
  36. package/dist/index.js.map +3 -3
  37. package/dist/residency/host.js +3 -3
  38. package/dist/residency/omp-entry.js +3 -3
  39. package/dist/topology/participant-directory.d.ts.map +1 -1
  40. package/dist/ui/arc-group.d.ts +1 -1
  41. package/dist/ui/arc-group.d.ts.map +1 -1
  42. package/dist/ui/code-preview-shell.d.ts +2 -2
  43. package/dist/ui/code-preview-shell.d.ts.map +1 -1
  44. package/dist/ui/controller.d.ts.map +1 -1
  45. package/dist/ui/conversation-chrome.d.ts +1 -5
  46. package/dist/ui/conversation-chrome.d.ts.map +1 -1
  47. package/dist/ui/conversation-chrome.js +2 -2
  48. package/dist/ui/conversation-queue.d.ts +3 -2
  49. package/dist/ui/conversation-queue.d.ts.map +1 -1
  50. package/dist/ui/conversation-render.d.ts +19 -23
  51. package/dist/ui/conversation-render.d.ts.map +1 -1
  52. package/dist/ui/conversation.d.ts +7 -17
  53. package/dist/ui/conversation.d.ts.map +1 -1
  54. package/dist/ui/conversation.js +317 -318
  55. package/dist/ui/conversation.js.map +3 -3
  56. package/dist/ui/core-tool-render.d.ts +1 -1
  57. package/dist/ui/core-tool-render.d.ts.map +1 -1
  58. package/dist/ui/dashboard-detail.d.ts +4 -4
  59. package/dist/ui/dashboard-detail.d.ts.map +1 -1
  60. package/dist/ui/dashboard-fabric-graph.d.ts +1 -1
  61. package/dist/ui/dashboard-fabric-graph.d.ts.map +1 -1
  62. package/dist/ui/dashboard-presentation.d.ts +1 -1
  63. package/dist/ui/dashboard-presentation.d.ts.map +1 -1
  64. package/dist/ui/dashboard.d.ts +8 -8
  65. package/dist/ui/dashboard.d.ts.map +1 -1
  66. package/dist/ui/dashboard.js +206 -343
  67. package/dist/ui/dashboard.js.map +3 -3
  68. package/dist/ui/diff-background.d.ts +1 -1
  69. package/dist/ui/diff-background.d.ts.map +1 -1
  70. package/dist/ui/fabric-actor-delivery-selector.d.ts +4 -4
  71. package/dist/ui/fabric-actor-delivery-selector.d.ts.map +1 -1
  72. package/dist/ui/fabric-actor-tool-selector.d.ts +5 -6
  73. package/dist/ui/fabric-actor-tool-selector.d.ts.map +1 -1
  74. package/dist/ui/fabric-host-event-selector.d.ts +4 -4
  75. package/dist/ui/fabric-host-event-selector.d.ts.map +1 -1
  76. package/dist/ui/fabric-model-selector.d.ts +4 -6
  77. package/dist/ui/fabric-model-selector.d.ts.map +1 -1
  78. package/dist/ui/fabric-render.d.ts +6 -6
  79. package/dist/ui/fabric-render.d.ts.map +1 -1
  80. package/dist/ui/fabric-thinking-selector.d.ts +4 -7
  81. package/dist/ui/fabric-thinking-selector.d.ts.map +1 -1
  82. package/dist/ui/highlight.d.ts +2 -13
  83. package/dist/ui/highlight.d.ts.map +1 -1
  84. package/dist/ui/row-balance.d.ts +6 -6
  85. package/dist/ui/row-balance.d.ts.map +1 -1
  86. package/dist/ui/settings.d.ts +6 -3
  87. package/dist/ui/settings.d.ts.map +1 -1
  88. package/dist/ui/settings.js +239 -113
  89. package/dist/ui/settings.js.map +3 -3
  90. package/dist/ui/state-file-preview.d.ts +1 -1
  91. package/dist/ui/state-file-preview.d.ts.map +1 -1
  92. package/dist/ui/tui/host-term.d.ts +16 -0
  93. package/dist/ui/tui/host-term.d.ts.map +1 -0
  94. package/dist/ui/tui/input.d.ts +19 -0
  95. package/dist/ui/tui/input.d.ts.map +1 -0
  96. package/dist/ui/tui/rows.d.ts +24 -0
  97. package/dist/ui/tui/rows.d.ts.map +1 -0
  98. package/dist/ui/tui/select-list.d.ts +28 -0
  99. package/dist/ui/tui/select-list.d.ts.map +1 -0
  100. package/dist/ui/tui/settings-list.d.ts +38 -0
  101. package/dist/ui/tui/settings-list.d.ts.map +1 -0
  102. package/dist/ui/tui/text-field.d.ts +40 -0
  103. package/dist/ui/tui/text-field.d.ts.map +1 -0
  104. package/dist/ui/tui/view.d.ts +26 -0
  105. package/dist/ui/tui/view.d.ts.map +1 -0
  106. package/dist/ui/widget.d.ts +3 -3
  107. package/dist/ui/widget.d.ts.map +1 -1
  108. package/docs/configuration.md +2 -0
  109. package/docs/interface.md +16 -3
  110. package/package.json +13 -12
  111. package/dist/chunks/chunk-2BOZMRT5.js.map +0 -7
  112. package/dist/chunks/chunk-4XLJPEI4.js.map +0 -7
  113. package/dist/chunks/chunk-CNCRWY4Q.js.map +0 -7
  114. package/dist/chunks/chunk-G2IBGGBM.js +0 -42
  115. package/dist/chunks/chunk-G2IBGGBM.js.map +0 -7
  116. package/dist/chunks/chunk-KIH3KLZU.js.map +0 -7
  117. package/dist/chunks/chunk-NOZBB266.js.map +0 -7
  118. package/dist/chunks/chunk-OJZNMROB.js.map +0 -7
  119. package/dist/ui/symbol-theme.d.ts +0 -3
  120. package/dist/ui/symbol-theme.d.ts.map +0 -1
  121. /package/dist/chunks/{chunk-7QKSPNXQ.js.map → chunk-V5FB7D4C.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.28.1
4
+
5
+ ### Changed
6
+
7
+ - OMP 19.2.1 is the minimum host. The peer floor of pi-coding-agent, pi-natives and pi-tui and `MINIMUM_OMP_HOST_VERSION` move from 19.2.0 to 19.2.1, the only host 1.28.0 ran on.
8
+ - Captured tools that declare `loadMode: "essential"` stay in the model-facing set in full code mode (#25, reported by @blyzer). `capture.keepEssentialVisible: false` hides them again; Schema enforce mode still keeps `fabric_exec` as the only model-facing tool.
9
+ - `fabric_exec` declares `loadMode: "essential"`, so the host never defers it out of the model-facing set (#21, by @UnderCooled).
10
+
11
+ ### Fixed
12
+
13
+ - A pi-tui module or export missing from the host no longer stops omp-fabric from loading. `term/paint`, `term/widgets`, `term/render`, `term/keymap` and `driver/input/decoder` load through dynamic imports, and each export Fabric calls is checked. When one is missing, Fabric warns once at startup and its views degrade: no mouse wheel scrolling, the default widget keys, keys taken from the host key event, and one notice row in place of a host-drawn preview. 19.2.1 itself dropped an internal pi-tui export (`oneLine` in `term/painters/picker`).
14
+ - `ParticipantDirectory.refresh()` no longer hands a caller the refresh that was already running. A caller that had just changed the mesh received a result read before its change; the heartbeat tick raced `tests/participant-directory.test.ts` this way on ubuntu (run 45939865443). A caller now waits for the running refresh and runs one more; the heartbeat still joins the running one.
15
+
16
+ ### Added
17
+
18
+ - `bun run check:host-imports` (`scripts/check-host-imports.mjs`) lists every `@oh-my-pi/*` specifier and named import in `dist/` and imports each one from the host packages; `--binary <omp>` also checks the module map compiled into an OMP binary. CI shard 1 runs it after the build.
19
+
20
+ ### Notes
21
+
22
+ - Prompt cost of the #25 change, `omp -p` on 19.2.1 with default full code mode: without an essential extension tool, 24 tools and 96,543 schema bytes before and after; one essential probe tool adds 1 tool and 324 schema bytes, and `capture.keepEssentialVisible: false` brings it back to 24.
23
+ - `tests/host-term-fallback.test.ts` fails 3 of its 4 tests with the static imports restored. `omp -p` on 19.2.1 with this build loads without the fallback warning.
24
+ - `check:host-imports` on 19.2.1: 83 files, 34 specifiers, 47 names in about 1.2 s, also clean with `--binary` against the installed omp 19.2.1.
25
+ - CI: Test run 45940500961 at the code commit ee4e5991 (#27) and run 45938061070 at bb9e8d9a (#21), green on ubuntu and windows.
26
+
27
+ ## 1.28.0
28
+
29
+ ### Changed (breaking)
30
+
31
+ - OMP 19.2.0 is the minimum host. OMP 19.2 replaced `@oh-my-pi/pi-tui` with a node-based TUI library and stopped re-exporting the old components from the `@oh-my-pi/pi-coding-agent` root, so 1.27.x fails to load there (`Export named 'truncateToWidth' not found`). The peer floor of pi-coding-agent, pi-natives and pi-tui moves from `>=18.4.4` to `>=19.2.0`, `MINIMUM_OMP_HOST_VERSION` from 18.4.4 to 19.2.0, and the host pins from 19.1.1 to 19.2.1. Hosts from 18.4.4 to 19.1.x stay on 1.27.x.
32
+ - The dashboard (`/fabric`) and the focused conversation (`/fabric chat`) open as full-screen overlays (`{ overlay: true, fullscreen: true }`). The old pi-tui positioning options (94% by 90% centered for the dashboard) no longer exist on the host.
33
+ - The conversation transcript is drawn by Fabric: the host no longer exposes its message, tool and summary components to extensions (none of the 1881 module ids in the 19.2.1 binary is under `pi-coding-agent/ui`). User prompts sit on the user message background, assistant text and thinking go through pi-tui Markdown, a tool with its own `renderCall` or `renderResult` (such as `fabric_exec`) draws itself, and other tools show a compact card with arguments and a result that the tool-expand key unfolds. Images inside tool results are no longer shown there, and `terminal.showImages` is no longer read.
34
+ - Mouse wheel scrolling in the conversation reaches Fabric through the host when OMP mouse reporting (`tui.mouse`) is on. Fabric no longer switches the terminal into mouse mode itself; with `tui.mouse` off, a terminal that turns the wheel into arrow keys on the alternate screen scrolls through the line keys.
35
+
36
+ ### Added
37
+
38
+ - `src/ui/tui/`: Fabric's own row primitives (`TextBlock`, `Stack`, `BlankRows`), a single and multi-line `TextField`, `SelectList` and `SettingsList`. Keys come from the pi-tui widget keymap that OMP keeps in sync with the user's keybindings (`select.*`, `editor.*`), and application actions (`app.tools.expand`, `app.message.followUp`, `tui.editor.pageUp`) from the host `KeybindingsManager`.
39
+ - `mountView` mounts a Fabric view as a pi-tui `canvas` node with a role painter and role widget, so key and paste events reach the view, repaints follow a signal, and wheel events reach `handleWheel` through the node's hit region.
40
+ - A Fabric view that throws while drawing shows one row, `⚠ Fabric view failed to render: <message>`, and reports the error once per failure streak; a throw while handling a key, paste or wheel event is reported the same way. The host only contains errors of the rows objects it mounts, and Fabric mounts its dashboard and conversation itself.
41
+
42
+ ### Removed
43
+
44
+ - `src/ui/symbol-theme.ts`, the copied pi-tui symbol table. Styling goes through the host theme (`theme.style("strong", …)` for bold), and diff backgrounds derive from `theme.hex` of `toolDiffAdded`, `toolDiffRemoved`, `toolSuccessBg` and `toolErrorBg`.
45
+ - `tests/fabric-exec-transcript-block.test.ts`, which tested the host `ToolExecutionComponent` that 19.2 removed.
46
+
47
+ ### Notes
48
+
49
+ - Live smoke on OMP 19.2.1 in tmux (160x45): the `/fabric` dashboard overview, topology and detail views, `/fabric settings` with section submenus and search, the approval dialog for `omp.bash` (Allow once ran the call), and `/fabric chat` on a spawned child agent (transcript, PageUp to older activity, the target picker, typing, Escape to close). Headless `omp -p` with 1.27.2 has no `fabric_exec`; this build runs it.
50
+ - Frame cost, same workload, median ms per frame from main (19.1.1) to this release: widget 0.0089 to 0.0087, dashboard overview 0.1616 to 0.1665, dashboard detail 0.1268 to 0.1329, conversation of 60 messages cold 0.5507 to 0.5772 and warm 0.3488 to 0.0448. Warm conversation frames with 20 tool results of 80 KB and a 2 MB image fell from 7.6032 to under 0.05 after the transcript block cache moved to input identity with eviction.
51
+ - Review: Agent Hendra asked in round 1 for the dashboard view to be disposed on close (its topology animation kept an 80 ms interval alive after closing), for view error containment, and for a cheaper transcript cache; round 2 approved 6a3e1801. Controller seam tests fail without the dispose (13 renders after close) and without the error containment.
52
+ - CI: Test run 45935666376 at 6a3e1801 (#26) and main Test run 45936254716 at the code commit 9b885f78, green on ubuntu and windows.
53
+
3
54
  ## 1.27.2
4
55
 
5
56
  ### Fixed
package/README.md CHANGED
@@ -62,7 +62,7 @@ Independent calls run in parallel, and the returned object enters the model cont
62
62
 
63
63
  ## Install
64
64
 
65
- Requires Node.js 24+ and OMP 18.4.4+. Fabric also checks a detectable OMP host version at startup and warns when an older host does not match the tool shapes Fabric types against.
65
+ Requires Node.js 24+ and OMP 19.2.1+. OMP 19.2 replaced the pi-tui component library, so hosts from 18.4.4 to 19.1.x stay on omp-fabric 1.27.x. Fabric also checks a detectable OMP host version at startup and warns when an older host does not match the tool shapes Fabric types against.
66
66
 
67
67
  ```bash
68
68
  omp install npm:omp-fabric
@@ -1 +1 @@
1
- {"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/capture/interceptor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAyB,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQnD,MAAM,WAAW,+BAA+B;IAC9C,SAAS,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACjD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC3C,gBAAgB,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,OAAO,EAAE,mBAAmB,CAAC;IAC7B,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CAC1D;AA2BD,KAAK,0BAA0B,GAAG;IAChC,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAC;AAaF,eAAO,MAAM,iCAAiC,GAC5C,WAAW,MAAM,KAChB,OAAO,CAAC,0BAA0B,EAAE,CAuBtC,CAAC;AAkGF,eAAO,MAAM,4BAA4B,GACvC,SAAS,4BAA4B,KACpC,OAAO,CAAC,+BAA+B,CAyCzC,CAAC"}
1
+ {"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/capture/interceptor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAyB,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQnD,MAAM,WAAW,+BAA+B;IAC9C,SAAS,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACjD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC3C,gBAAgB,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,OAAO,EAAE,mBAAmB,CAAC;IAC7B,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CAC1D;AA4BD,KAAK,0BAA0B,GAAG;IAChC,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAC;AAaF,eAAO,MAAM,iCAAiC,GAC5C,WAAW,MAAM,KAChB,OAAO,CAAC,0BAA0B,EAAE,CAuBtC,CAAC;AAkGF,eAAO,MAAM,4BAA4B,GACvC,SAAS,4BAA4B,KACpC,OAAO,CAAC,+BAA+B,CAyCzC,CAAC"}
@@ -1,19 +1,24 @@
1
+ import {
2
+ TextField
3
+ } from "./chunk-CHXPTZUF.js";
1
4
  import {
2
5
  INHERIT_VALUE,
3
6
  modelKey,
4
7
  sortByLastUsed
5
8
  } from "./chunk-7BOAOKWH.js";
9
+ import {
10
+ BlankRows,
11
+ Stack,
12
+ TextBlock
13
+ } from "./chunk-VDYGBL4Z.js";
14
+ import {
15
+ keyMatches,
16
+ keyOf
17
+ } from "./chunk-XVA63H6I.js";
6
18
 
7
19
  // src/ui/fabric-model-selector.ts
8
- import {
9
- Container,
10
- fuzzyFilter,
11
- getKeybindings,
12
- Input,
13
- Spacer,
14
- Text
15
- } from "@oh-my-pi/pi-tui";
16
- var FabricModelSelector = class extends Container {
20
+ import { fuzzyFilter } from "@oh-my-pi/pi-coding-agent/utils/fuzzy";
21
+ var FabricModelSelector = class extends Stack {
17
22
  theme;
18
23
  allEntries;
19
24
  filteredEntries;
@@ -22,13 +27,12 @@ var FabricModelSelector = class extends Container {
22
27
  currentValue;
23
28
  selectedIndex = 0;
24
29
  searchInput;
25
- listContainer = new Container();
30
+ listContainer = new Stack();
26
31
  onSelectCallback;
27
32
  onCancelCallback;
28
33
  headerText;
29
34
  inheritLabel;
30
35
  inheritName;
31
- _focused = false;
32
36
  constructor(options) {
33
37
  super();
34
38
  this.theme = options.theme;
@@ -44,51 +48,37 @@ var FabricModelSelector = class extends Container {
44
48
  this.filteredEntries = this.allEntries;
45
49
  const current = this.allEntries.findIndex((entry) => entry.value === this.currentValue);
46
50
  this.selectedIndex = current >= 0 ? current : 0;
47
- this.addChild(
48
- new Text(
49
- this.theme.fg("muted", this.headerText),
50
- 0,
51
- 0
52
- )
53
- );
54
- this.addChild(new Spacer(1));
55
- this.searchInput = new Input();
56
- this.searchInput.focused = true;
51
+ this.add(new TextBlock(this.theme.fg("muted", this.headerText)));
52
+ this.add(new BlankRows(1));
53
+ this.searchInput = new TextField();
57
54
  this.searchInput.onSubmit = () => {
58
55
  const entry = this.filteredEntries[this.selectedIndex];
59
56
  if (entry) this.handleSelect(entry);
60
57
  };
61
- this.addChild(this.searchInput);
62
- this.addChild(new Spacer(1));
63
- this.addChild(this.listContainer);
64
- this.addChild(new Spacer(1));
58
+ this.add(this.searchInput);
59
+ this.add(new BlankRows(1));
60
+ this.add(this.listContainer);
61
+ this.add(new BlankRows(1));
65
62
  this.updateList();
66
63
  }
67
- get focused() {
68
- return this._focused;
69
- }
70
- set focused(value) {
71
- this._focused = value;
72
- this.searchInput.focused = value;
73
- }
74
64
  handleInput(keyData) {
75
- const kb = getKeybindings();
76
- if (kb.matches(keyData, "tui.select.up")) {
65
+ const key = keyOf(keyData);
66
+ if (key && keyMatches(key, "select.up")) {
77
67
  if (this.filteredEntries.length === 0) return;
78
68
  this.selectedIndex = this.selectedIndex === 0 ? this.filteredEntries.length - 1 : this.selectedIndex - 1;
79
69
  this.updateList();
80
- } else if (kb.matches(keyData, "tui.select.down")) {
70
+ } else if (key && keyMatches(key, "select.down")) {
81
71
  if (this.filteredEntries.length === 0) return;
82
72
  this.selectedIndex = this.selectedIndex === this.filteredEntries.length - 1 ? 0 : this.selectedIndex + 1;
83
73
  this.updateList();
84
- } else if (kb.matches(keyData, "tui.select.confirm")) {
74
+ } else if (key && keyMatches(key, "select.confirm")) {
85
75
  const entry = this.filteredEntries[this.selectedIndex];
86
76
  if (entry) this.handleSelect(entry);
87
- } else if (kb.matches(keyData, "tui.select.cancel")) {
77
+ } else if (key && keyMatches(key, "select.cancel")) {
88
78
  this.onCancelCallback();
89
79
  } else {
90
80
  this.searchInput.handleInput(keyData);
91
- this.filterModels(this.searchInput.getValue());
81
+ this.filterModels(this.searchInput.getText());
92
82
  }
93
83
  }
94
84
  rpcChoices() {
@@ -166,24 +156,20 @@ var FabricModelSelector = class extends Container {
166
156
  const badge = entry.provider ? ` ${this.theme.fg("muted", `[${entry.provider}]`)}` : "";
167
157
  const check = isCurrent ? this.theme.fg("success", " \u2713") : "";
168
158
  const line = isSelected ? `${this.theme.fg("accent", "\u2192 ")}${this.theme.fg("accent", entry.id)}${badge}${check}` : ` ${entry.id}${badge}${check}`;
169
- this.listContainer.addChild(new Text(line, 0, 0));
159
+ this.listContainer.add(new TextBlock(line));
170
160
  }
171
161
  if (startIndex > 0 || endIndex < total) {
172
- this.listContainer.addChild(
173
- new Text(this.theme.fg("muted", ` (${this.selectedIndex + 1}/${total})`), 0, 0)
162
+ this.listContainer.add(
163
+ new TextBlock(this.theme.fg("muted", ` (${this.selectedIndex + 1}/${total})`))
174
164
  );
175
165
  }
176
166
  if (total === 0) {
177
- this.listContainer.addChild(new Text(this.theme.fg("muted", " No matching models"), 0, 0));
167
+ this.listContainer.add(new TextBlock(this.theme.fg("muted", " No matching models")));
178
168
  } else {
179
169
  const selected = this.filteredEntries[this.selectedIndex];
180
- this.listContainer.addChild(new Spacer(1));
181
- this.listContainer.addChild(
182
- new Text(
183
- this.theme.fg("muted", ` Model Name: ${selected ? selected.name : ""}`),
184
- 0,
185
- 0
186
- )
170
+ this.listContainer.add(new BlankRows(1));
171
+ this.listContainer.add(
172
+ new TextBlock(this.theme.fg("muted", ` Model Name: ${selected ? selected.name : ""}`))
187
173
  );
188
174
  }
189
175
  }
@@ -192,4 +178,4 @@ var FabricModelSelector = class extends Container {
192
178
  export {
193
179
  FabricModelSelector
194
180
  };
195
- //# sourceMappingURL=chunk-OJZNMROB.js.map
181
+ //# sourceMappingURL=chunk-4PPAWZM6.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/fabric-model-selector.ts"],
4
+ "sourcesContent": ["import type { Theme } from \"@oh-my-pi/pi-tui/theme/contract\";\nimport { fuzzyFilter } from \"@oh-my-pi/pi-coding-agent/utils/fuzzy\";\nimport { keyMatches, keyOf } from \"./tui/input.js\";\nimport { BlankRows, Stack, TextBlock } from \"./tui/rows.js\";\nimport { TextField } from \"./tui/text-field.js\";\nimport type { FabricView } from \"./tui/view.js\";\nimport { INHERIT_VALUE, modelKey, sortByLastUsed, type ModelLike, type ModelSource } from \"./model-picker.js\";\n\n/** A single pickable row in the Fabric model selector. */\ninterface ModelEntry {\n /** Value persisted to fabric.json: \"Inherit\" or `provider/id`. */\n value: string;\n /** Main text shown for the row (the model id, or \"Inherit\"). */\n id: string;\n /** Provider badge shown after the id; empty for the Inherit row. */\n provider: string;\n /** Human-readable name shown in the footer line. */\n name: string;\n /** Whether this is a real model (vs. the Inherit sentinel). */\n isModel: boolean;\n}\n\nexport interface FabricModelSelectorChoice {\n value: string;\n label: string;\n description: string;\n current: boolean;\n}\n\nexport interface FabricModelSelectorOptions {\n theme: Theme;\n source: ModelSource;\n /** The currently configured canonical model key or \"Inherit\". */\n currentValue: string;\n onSelect: (value: string) => void;\n onCancel: () => void;\n /** Header line above the search input. Defaults to the global-default wording. */\n headerText?: string;\n /** Label shown for the unset/default row. Defaults to Inherit. */\n inheritLabel?: string;\n /** Description shown for the unset/default row's footer name. */\n inheritName?: string;\n}\n\n/**\n * A /model-style searchable model picker adapted for Fabric: same look\n * (search input, list with `[provider]` badges and a \u2713 on\n * the current row, scroll indicator, and a \"Model Name:\" footer) but it writes\n * the Fabric default-model setting instead of the host's default model, and\n * pins an unset/default row on top. Order respects pi-model-sort (most recently\n * used first); search filters by fuzzy match and re-sorts by recency, matching\n * pi-model-sort's patched /model behavior.\n */\nexport class FabricModelSelector extends Stack implements FabricView {\n private readonly theme: Theme;\n private readonly allEntries: ModelEntry[];\n private filteredEntries: ModelEntry[];\n private readonly lastUsed: Record<string, number>;\n private readonly currentKey: string | null;\n private readonly currentValue: string;\n private selectedIndex = 0;\n private readonly searchInput: TextField;\n private readonly listContainer = new Stack();\n private readonly onSelectCallback: (value: string) => void;\n private readonly onCancelCallback: () => void;\n private readonly headerText: string;\n private readonly inheritLabel: string;\n private readonly inheritName: string;\n\n constructor(options: FabricModelSelectorOptions) {\n super();\n this.theme = options.theme;\n this.lastUsed = options.source.lastUsed;\n this.currentValue = options.currentValue;\n this.currentKey = options.currentValue === INHERIT_VALUE ? null : options.currentValue;\n this.onSelectCallback = options.onSelect;\n this.onCancelCallback = options.onCancel;\n this.headerText =\n options.headerText ??\n \"Default model for Fabric agents and actors. Pick Inherit to use the host session's model.\";\n this.inheritLabel = options.inheritLabel ?? INHERIT_VALUE;\n this.inheritName = options.inheritName ?? \"Use the host session's default model\";\n\n this.allEntries = this.buildEntries(options.source.models);\n this.filteredEntries = this.allEntries;\n const current = this.allEntries.findIndex((entry) => entry.value === this.currentValue);\n this.selectedIndex = current >= 0 ? current : 0;\n\n this.add(new TextBlock(this.theme.fg(\"muted\", this.headerText)));\n this.add(new BlankRows(1));\n this.searchInput = new TextField();\n this.searchInput.onSubmit = () => {\n const entry = this.filteredEntries[this.selectedIndex];\n if (entry) this.handleSelect(entry);\n };\n this.add(this.searchInput);\n this.add(new BlankRows(1));\n this.add(this.listContainer);\n this.add(new BlankRows(1));\n this.updateList();\n }\n\n handleInput(keyData: string): void {\n const key = keyOf(keyData);\n if (key && keyMatches(key, \"select.up\")) {\n if (this.filteredEntries.length === 0) return;\n this.selectedIndex =\n this.selectedIndex === 0 ? this.filteredEntries.length - 1 : this.selectedIndex - 1;\n this.updateList();\n } else if (key && keyMatches(key, \"select.down\")) {\n if (this.filteredEntries.length === 0) return;\n this.selectedIndex =\n this.selectedIndex === this.filteredEntries.length - 1 ? 0 : this.selectedIndex + 1;\n this.updateList();\n } else if (key && keyMatches(key, \"select.confirm\")) {\n const entry = this.filteredEntries[this.selectedIndex];\n if (entry) this.handleSelect(entry);\n } else if (key && keyMatches(key, \"select.cancel\")) {\n this.onCancelCallback();\n } else {\n this.searchInput.handleInput(keyData);\n this.filterModels(this.searchInput.getText());\n }\n }\n\n rpcChoices(): FabricModelSelectorChoice[] {\n return this.allEntries.map((entry) => ({\n value: entry.value,\n label: entry.id,\n description: entry.isModel ? `${entry.provider} \u00B7 ${entry.name}` : entry.name,\n current: entry.value === this.currentValue,\n }));\n }\n\n selectRpc(value: string): boolean {\n const entry = this.allEntries.find((candidate) => candidate.value === value);\n if (!entry) return false;\n this.handleSelect(entry);\n return true;\n }\n\n private handleSelect(entry: ModelEntry): void {\n this.onSelectCallback(entry.value);\n }\n\n private buildEntries(models: ModelLike[]): ModelEntry[] {\n const sorted = sortByLastUsed(models, this.lastUsed, this.currentKey);\n const inherit: ModelEntry = {\n value: INHERIT_VALUE,\n id: this.inheritLabel,\n provider: \"\",\n name: this.inheritName,\n isModel: false,\n };\n const modelEntries: ModelEntry[] = sorted.map((model) => ({\n value: modelKey(model.provider, model.id),\n id: model.id,\n provider: model.provider,\n name: model.name ?? model.id,\n isModel: true,\n }));\n return [inherit, ...modelEntries];\n }\n\n /** Filter by fuzzy match, then re-sort by recency (mirrors pi-model-sort). */\n private sortEntries(entries: ModelEntry[]): ModelEntry[] {\n const inherit = entries.find((entry) => !entry.isModel);\n const models = entries.filter((entry) => entry.isModel);\n const sorted = sortByLastUsed(\n models.map((entry) => ({ provider: entry.provider, id: entry.id, entry })),\n this.lastUsed,\n this.currentKey,\n ).map((item) => item.entry);\n return inherit ? [inherit, ...sorted] : sorted;\n }\n\n private filterModels(query: string): void {\n const matches = query.trim()\n ? fuzzyFilter(this.allEntries, query, (entry) => this.searchText(entry))\n : this.allEntries;\n this.filteredEntries = this.sortEntries(matches);\n const current = this.filteredEntries.findIndex((entry) => entry.value === this.currentValue);\n this.selectedIndex =\n current >= 0\n ? current\n : Math.min(this.selectedIndex, Math.max(0, this.filteredEntries.length - 1));\n this.updateList();\n }\n\n /** Mirrors getModelSelectorSearchText from OMP's /model selector. */\n private searchText(entry: ModelEntry): string {\n if (!entry.isModel) return `${entry.id} ${entry.name}`;\n return `${entry.provider} ${entry.provider}/${entry.id} ${entry.provider} ${entry.id} ${entry.name}`;\n }\n\n private updateList(): void {\n this.listContainer.clear();\n const maxVisible = 10;\n const total = this.filteredEntries.length;\n const startIndex = Math.max(\n 0,\n Math.min(this.selectedIndex - Math.floor(maxVisible / 2), total - maxVisible),\n );\n const endIndex = Math.min(startIndex + maxVisible, total);\n for (let i = startIndex; i < endIndex; i++) {\n const entry = this.filteredEntries[i];\n if (!entry) continue;\n const isSelected = i === this.selectedIndex;\n const isCurrent = entry.value === this.currentValue;\n const badge = entry.provider ? ` ${this.theme.fg(\"muted\", `[${entry.provider}]`)}` : \"\";\n const check = isCurrent ? this.theme.fg(\"success\", \" \u2713\") : \"\";\n const line = isSelected\n ? `${this.theme.fg(\"accent\", \"\\u2192 \")}${this.theme.fg(\"accent\", entry.id)}${badge}${check}`\n : ` ${entry.id}${badge}${check}`;\n this.listContainer.add(new TextBlock(line));\n }\n if (startIndex > 0 || endIndex < total) {\n this.listContainer.add(\n new TextBlock(this.theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${total})`)),\n );\n }\n if (total === 0) {\n this.listContainer.add(new TextBlock(this.theme.fg(\"muted\", \" No matching models\")));\n } else {\n const selected = this.filteredEntries[this.selectedIndex];\n this.listContainer.add(new BlankRows(1));\n this.listContainer.add(\n new TextBlock(this.theme.fg(\"muted\", ` Model Name: ${selected ? selected.name : \"\"}`)),\n );\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AACA,SAAS,mBAAmB;AAoDrB,IAAM,sBAAN,cAAkC,MAA4B;AAAA,EAClD;AAAA,EACA;AAAA,EACT;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACT,gBAAgB;AAAA,EACP;AAAA,EACA,gBAAgB,IAAI,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,SAAqC;AAC/C,UAAM;AACN,SAAK,QAAQ,QAAQ;AACrB,SAAK,WAAW,QAAQ,OAAO;AAC/B,SAAK,eAAe,QAAQ;AAC5B,SAAK,aAAa,QAAQ,iBAAiB,gBAAgB,OAAO,QAAQ;AAC1E,SAAK,mBAAmB,QAAQ;AAChC,SAAK,mBAAmB,QAAQ;AAChC,SAAK,aACH,QAAQ,cACR;AACF,SAAK,eAAe,QAAQ,gBAAgB;AAC5C,SAAK,cAAc,QAAQ,eAAe;AAE1C,SAAK,aAAa,KAAK,aAAa,QAAQ,OAAO,MAAM;AACzD,SAAK,kBAAkB,KAAK;AAC5B,UAAM,UAAU,KAAK,WAAW,UAAU,CAAC,UAAU,MAAM,UAAU,KAAK,YAAY;AACtF,SAAK,gBAAgB,WAAW,IAAI,UAAU;AAE9C,SAAK,IAAI,IAAI,UAAU,KAAK,MAAM,GAAG,SAAS,KAAK,UAAU,CAAC,CAAC;AAC/D,SAAK,IAAI,IAAI,UAAU,CAAC,CAAC;AACzB,SAAK,cAAc,IAAI,UAAU;AACjC,SAAK,YAAY,WAAW,MAAM;AAChC,YAAM,QAAQ,KAAK,gBAAgB,KAAK,aAAa;AACrD,UAAI,MAAO,MAAK,aAAa,KAAK;AAAA,IACpC;AACA,SAAK,IAAI,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,IAAI,IAAI,UAAU,IAAI,CAAC;AAAA,IAC5C;AACA,QAAI,aAAa,KAAK,WAAW,OAAO;AACtC,WAAK,cAAc;AAAA,QACjB,IAAI,UAAU,KAAK,MAAM,GAAG,SAAS,MAAM,KAAK,gBAAgB,CAAC,IAAI,KAAK,GAAG,CAAC;AAAA,MAChF;AAAA,IACF;AACA,QAAI,UAAU,GAAG;AACf,WAAK,cAAc,IAAI,IAAI,UAAU,KAAK,MAAM,GAAG,SAAS,sBAAsB,CAAC,CAAC;AAAA,IACtF,OAAO;AACL,YAAM,WAAW,KAAK,gBAAgB,KAAK,aAAa;AACxD,WAAK,cAAc,IAAI,IAAI,UAAU,CAAC,CAAC;AACvC,WAAK,cAAc;AAAA,QACjB,IAAI,UAAU,KAAK,MAAM,GAAG,SAAS,iBAAiB,WAAW,SAAS,OAAO,EAAE,EAAE,CAAC;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -1,5 +1,5 @@
1
1
  // src/ui/format.ts
2
- import { truncateToWidth, visibleWidth } from "@oh-my-pi/pi-tui";
2
+ import { truncate, visibleWidth } from "@oh-my-pi/pi-tui/text/width";
3
3
  var safeText = (value) => String(value ?? "").replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, " ").replace(/[\r\n\t]+/g, " ").replace(/\s+/g, " ").trim();
4
4
  var formatActorDataPreview = (data, maxChars = 200) => {
5
5
  if (data === void 0) return void 0;
@@ -38,7 +38,7 @@ var formatTokens = (tokens) => {
38
38
  var formatCost = (usd) => usd <= 0 ? "$0" : usd < 0.01 ? `$${usd.toFixed(4)}` : usd < 1 ? `$${usd.toFixed(3)}` : `$${usd.toFixed(2)}`;
39
39
  var formatClock = (timestamp) => new Date(timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
40
40
  var padToWidth = (value, width) => {
41
- const clipped = truncateToWidth(value, Math.max(0, width), "");
41
+ const clipped = truncate(value, Math.max(0, width), "");
42
42
  return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
43
43
  };
44
44
  var wrapPlainText = (value, width, maxLines = 100) => {
@@ -53,7 +53,7 @@ var wrapPlainText = (value, width, maxLines = 100) => {
53
53
  current = candidate;
54
54
  continue;
55
55
  }
56
- if (current) lines.push(truncateToWidth(current, width));
56
+ if (current) lines.push(truncate(current, width));
57
57
  current = word;
58
58
  while (visibleWidth(current) > width && lines.length < maxLines) {
59
59
  let chunk = "";
@@ -78,7 +78,7 @@ var wrapPlainText = (value, width, maxLines = 100) => {
78
78
  }
79
79
  if (lines.length >= maxLines) break;
80
80
  }
81
- if (current && lines.length < maxLines) lines.push(truncateToWidth(current, width));
81
+ if (current && lines.length < maxLines) lines.push(truncate(current, width));
82
82
  return lines;
83
83
  };
84
84
 
@@ -92,4 +92,4 @@ export {
92
92
  padToWidth,
93
93
  wrapPlainText
94
94
  };
95
- //# sourceMappingURL=chunk-KIH3KLZU.js.map
95
+ //# sourceMappingURL=chunk-C2YMZNT5.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/format.ts"],
4
+ "sourcesContent": ["import { truncate, visibleWidth } from \"@oh-my-pi/pi-tui/text/width\";\n\nexport const safeText = (value: unknown): string =>\n String(value ?? \"\")\n .replace(/\\x1b\\[[0-?]*[ -/]*[@-~]/g, \"\")\n .replace(/[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f]/g, \" \")\n .replace(/[\\r\\n\\t]+/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n\n\nexport const formatActorDataPreview = (data: unknown, maxChars = 200): string | undefined => {\n if (data === undefined) return undefined;\n const clip = (value: string): string => {\n const safe = safeText(value);\n return safe.length > maxChars ? `${safe.slice(0, Math.max(1, maxChars - 1))}\u2026` : safe;\n };\n if (typeof data === \"string\") return clip(data);\n if (\n typeof data === \"object\" &&\n data !== null &&\n !Array.isArray(data) &&\n (data as { fabricTruncated?: unknown }).fabricTruncated === true\n ) {\n const wrapper = data as { preview?: unknown; originalBytes?: unknown };\n const preview = clip(String(wrapper.preview ?? \"\"));\n const suffix =\n typeof wrapper.originalBytes === \"number\"\n ? `[truncated from ${wrapper.originalBytes} bytes]`\n : \"[truncated]\";\n return preview ? `${preview} ${suffix}` : suffix;\n }\n let serialized: string;\n try {\n serialized = JSON.stringify(data) ?? String(data);\n } catch {\n serialized = String(data);\n }\n return clip(serialized);\n};\n\nexport const formatDuration = (milliseconds: number): string => {\n const seconds = Math.max(0, Math.floor(milliseconds / 1_000));\n if (seconds < 60) return `${seconds}s`;\n const minutes = Math.floor(seconds / 60);\n if (minutes < 60) return `${minutes}m${String(seconds % 60).padStart(2, \"0\")}s`;\n const hours = Math.floor(minutes / 60);\n return `${hours}h${String(minutes % 60).padStart(2, \"0\")}m`;\n};\n\nexport const formatTokens = (tokens: number): string => {\n if (tokens < 1_000) return String(Math.max(0, Math.round(tokens)));\n if (tokens < 100_000) return `${(tokens / 1_000).toFixed(tokens < 10_000 ? 1 : 0)}k`;\n return `${(tokens / 1_000).toFixed(0)}k`;\n};\n\nexport const formatCost = (usd: number): string =>\n usd <= 0 ? \"$0\" : usd < 0.01 ? `$${usd.toFixed(4)}` : usd < 1 ? `$${usd.toFixed(3)}` : `$${usd.toFixed(2)}`;\n\nexport const formatClock = (timestamp: number): string =>\n new Date(timestamp).toLocaleTimeString([], { hour: \"2-digit\", minute: \"2-digit\" });\n\nexport const padToWidth = (value: string, width: number): string => {\n const clipped = truncate(value, Math.max(0, width), \"\");\n return clipped + \" \".repeat(Math.max(0, width - visibleWidth(clipped)));\n};\n\nexport const wrapPlainText = (value: string, width: number, maxLines = 100): string[] => {\n const safe = safeText(value);\n if (!safe || width <= 0 || maxLines <= 0) return [];\n const words = safe.split(\" \");\n const lines: string[] = [];\n let current = \"\";\n for (const word of words) {\n const candidate = current ? `${current} ${word}` : word;\n if (visibleWidth(candidate) <= width) {\n current = candidate;\n continue;\n }\n if (current) lines.push(truncate(current, width));\n current = word;\n while (visibleWidth(current) > width && lines.length < maxLines) {\n let chunk = \"\";\n let consumed = 0;\n const segments = [\n ...new Intl.Segmenter(undefined, { granularity: \"grapheme\" }).segment(current),\n ];\n for (const { segment } of segments) {\n const candidate = chunk + segment;\n if (visibleWidth(candidate) > width) {\n if (!chunk) {\n chunk = \"\u2026\";\n consumed += segment.length;\n }\n break;\n }\n chunk = candidate;\n consumed += segment.length;\n }\n if (chunk) lines.push(chunk);\n current = current.slice(consumed);\n }\n if (lines.length >= maxLines) break;\n }\n if (current && lines.length < maxLines) lines.push(truncate(current, width));\n return lines;\n};\n"],
5
+ "mappings": ";AAAA,SAAS,UAAU,oBAAoB;AAEhC,IAAM,WAAW,CAAC,UACvB,OAAO,SAAS,EAAE,EACf,QAAQ,4BAA4B,EAAE,EACtC,QAAQ,8CAA8C,GAAG,EACzD,QAAQ,cAAc,GAAG,EACzB,QAAQ,QAAQ,GAAG,EACnB,KAAK;AAGH,IAAM,yBAAyB,CAAC,MAAe,WAAW,QAA4B;AAC3F,MAAI,SAAS,OAAW,QAAO;AAC/B,QAAM,OAAO,CAAC,UAA0B;AACtC,UAAM,OAAO,SAAS,KAAK;AAC3B,WAAO,KAAK,SAAS,WAAW,GAAG,KAAK,MAAM,GAAG,KAAK,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,WAAM;AAAA,EACnF;AACA,MAAI,OAAO,SAAS,SAAU,QAAO,KAAK,IAAI;AAC9C,MACE,OAAO,SAAS,YAChB,SAAS,QACT,CAAC,MAAM,QAAQ,IAAI,KAClB,KAAuC,oBAAoB,MAC5D;AACA,UAAM,UAAU;AAChB,UAAM,UAAU,KAAK,OAAO,QAAQ,WAAW,EAAE,CAAC;AAClD,UAAM,SACJ,OAAO,QAAQ,kBAAkB,WAC7B,mBAAmB,QAAQ,aAAa,YACxC;AACN,WAAO,UAAU,GAAG,OAAO,IAAI,MAAM,KAAK;AAAA,EAC5C;AACA,MAAI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put,
4
+ typedText
5
+ } from "./chunk-XVA63H6I.js";
6
+
7
+ // src/ui/tui/text-field.ts
8
+ import { inverse } from "@oh-my-pi/pi-tui/theme/theme";
9
+ import { visibleWidth } from "@oh-my-pi/pi-tui/text/width";
10
+ var EDIT_ACTIONS = [
11
+ "editor.newLine",
12
+ "editor.cursorLeft",
13
+ "editor.cursorRight",
14
+ "editor.cursorWordLeft",
15
+ "editor.cursorWordRight",
16
+ "editor.cursorLineStart",
17
+ "editor.cursorLineEnd",
18
+ "editor.cursorUp",
19
+ "editor.cursorDown",
20
+ "editor.deleteCharBackward",
21
+ "editor.deleteCharForward",
22
+ "editor.deleteWordBackward",
23
+ "editor.deleteWordForward",
24
+ "editor.deleteToLineStart",
25
+ "editor.deleteToLineEnd",
26
+ "editor.yank",
27
+ "editor.undo"
28
+ ];
29
+ var UNDO_LIMIT = 100;
30
+ var segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
31
+ var graphemes = (text) => Array.from(segmenter.segment(text), (part) => part.segment);
32
+ var isWordChar = (grapheme) => /[\p{L}\p{N}_]/u.test(grapheme);
33
+ var TextField = class {
34
+ onSubmit;
35
+ onChange;
36
+ focused = true;
37
+ text = "";
38
+ cursor = 0;
39
+ killed = "";
40
+ undoStack = [];
41
+ preferredColumn;
42
+ lastCursorRow = 0;
43
+ multiline;
44
+ prompt;
45
+ constructor(options = {}) {
46
+ this.multiline = options.multiline ?? false;
47
+ this.prompt = options.prompt ?? (this.multiline ? "" : "> ");
48
+ }
49
+ getText() {
50
+ return this.text;
51
+ }
52
+ setText(text) {
53
+ const next = this.normalize(text);
54
+ if (next === this.text) return;
55
+ this.text = next;
56
+ this.cursor = next.length;
57
+ this.preferredColumn = void 0;
58
+ this.onChange?.(this.text);
59
+ }
60
+ get cursorRow() {
61
+ return this.lastCursorRow;
62
+ }
63
+ handleInput(data) {
64
+ for (const event of decodeTerminalInput(data)) {
65
+ if (event.type === "paste") this.insert(event.text);
66
+ else this.handleKey(event.key);
67
+ }
68
+ }
69
+ handleKey(key) {
70
+ if (key.id === "enter") {
71
+ this.onSubmit?.(this.text);
72
+ return true;
73
+ }
74
+ const action = actionOf(key.id, EDIT_ACTIONS);
75
+ if (action) return this.apply(action);
76
+ const typed = typedText(key);
77
+ if (typed === void 0) return false;
78
+ this.insert(typed);
79
+ return true;
80
+ }
81
+ render(width) {
82
+ return this.multiline ? this.renderLines(width) : [this.renderLine(width)];
83
+ }
84
+ apply(action) {
85
+ const before = this.text.slice(0, this.cursor);
86
+ const after = this.text.slice(this.cursor);
87
+ const lineStart = before.lastIndexOf("\n") + 1;
88
+ const lineEndOffset = after.indexOf("\n");
89
+ const lineEnd = lineEndOffset < 0 ? this.text.length : this.cursor + lineEndOffset;
90
+ switch (action) {
91
+ case "editor.newLine":
92
+ if (!this.multiline) return false;
93
+ this.insert("\n");
94
+ return true;
95
+ case "editor.cursorLeft":
96
+ return this.moveTo(this.cursor - (graphemes(before).at(-1)?.length ?? 0));
97
+ case "editor.cursorRight":
98
+ return this.moveTo(this.cursor + (graphemes(after)[0]?.length ?? 0));
99
+ case "editor.cursorWordLeft":
100
+ return this.moveTo(this.wordBoundaryBefore());
101
+ case "editor.cursorWordRight":
102
+ return this.moveTo(this.wordBoundaryAfter());
103
+ case "editor.cursorLineStart":
104
+ return this.moveTo(lineStart);
105
+ case "editor.cursorLineEnd":
106
+ return this.moveTo(lineEnd);
107
+ case "editor.cursorUp":
108
+ return this.moveVertical(-1);
109
+ case "editor.cursorDown":
110
+ return this.moveVertical(1);
111
+ case "editor.deleteCharBackward":
112
+ return this.remove(this.cursor - (graphemes(before).at(-1)?.length ?? 0), this.cursor, false);
113
+ case "editor.deleteCharForward":
114
+ return this.remove(this.cursor, this.cursor + (graphemes(after)[0]?.length ?? 0), false);
115
+ case "editor.deleteWordBackward":
116
+ return this.remove(this.wordBoundaryBefore(), this.cursor, true);
117
+ case "editor.deleteWordForward":
118
+ return this.remove(this.cursor, this.wordBoundaryAfter(), true);
119
+ case "editor.deleteToLineStart":
120
+ return this.remove(lineStart === this.cursor && lineStart > 0 ? lineStart - 1 : lineStart, this.cursor, true);
121
+ case "editor.deleteToLineEnd":
122
+ return this.remove(this.cursor, lineEnd === this.cursor && lineEnd < this.text.length ? lineEnd + 1 : lineEnd, true);
123
+ case "editor.yank":
124
+ if (this.killed === "") return false;
125
+ this.insert(this.killed);
126
+ return true;
127
+ case "editor.undo": {
128
+ const previous = this.undoStack.pop();
129
+ if (!previous) return false;
130
+ this.text = previous.text;
131
+ this.cursor = previous.cursor;
132
+ this.preferredColumn = void 0;
133
+ this.onChange?.(this.text);
134
+ return true;
135
+ }
136
+ default:
137
+ return false;
138
+ }
139
+ }
140
+ normalize(text) {
141
+ const unified = text.replace(/\r\n?/g, "\n");
142
+ return this.multiline ? unified : unified.replace(/\n/g, " ");
143
+ }
144
+ remember() {
145
+ this.undoStack.push({ text: this.text, cursor: this.cursor });
146
+ if (this.undoStack.length > UNDO_LIMIT) this.undoStack.shift();
147
+ }
148
+ insert(raw) {
149
+ const text = this.normalize(raw);
150
+ if (text === "") return;
151
+ this.remember();
152
+ this.text = `${this.text.slice(0, this.cursor)}${text}${this.text.slice(this.cursor)}`;
153
+ this.cursor += text.length;
154
+ this.preferredColumn = void 0;
155
+ this.onChange?.(this.text);
156
+ }
157
+ remove(from, to, kill) {
158
+ if (to <= from) return false;
159
+ this.remember();
160
+ if (kill) this.killed = this.text.slice(from, to);
161
+ this.text = `${this.text.slice(0, from)}${this.text.slice(to)}`;
162
+ this.cursor = from;
163
+ this.preferredColumn = void 0;
164
+ this.onChange?.(this.text);
165
+ return true;
166
+ }
167
+ moveTo(offset) {
168
+ this.cursor = Math.max(0, Math.min(offset, this.text.length));
169
+ this.preferredColumn = void 0;
170
+ return true;
171
+ }
172
+ moveVertical(direction) {
173
+ if (!this.multiline) return false;
174
+ const lines = this.text.split("\n");
175
+ let row = 0;
176
+ let offset = 0;
177
+ while (row < lines.length - 1 && offset + lines[row].length < this.cursor) {
178
+ offset += lines[row].length + 1;
179
+ row++;
180
+ }
181
+ const target = row + direction;
182
+ if (target < 0 || target >= lines.length) return false;
183
+ const column = this.preferredColumn ?? visibleWidth(this.text.slice(offset, this.cursor));
184
+ const targetStart = direction < 0 ? offset - lines[target].length - 1 : offset + lines[row].length + 1;
185
+ let position = targetStart;
186
+ let width = 0;
187
+ for (const grapheme of graphemes(lines[target])) {
188
+ const next = width + visibleWidth(grapheme);
189
+ if (next > column) break;
190
+ width = next;
191
+ position += grapheme.length;
192
+ }
193
+ this.cursor = position;
194
+ this.preferredColumn = column;
195
+ return true;
196
+ }
197
+ wordBoundaryBefore() {
198
+ const parts = graphemes(this.text.slice(0, this.cursor));
199
+ let index = parts.length;
200
+ while (index > 0 && !isWordChar(parts[index - 1])) index--;
201
+ while (index > 0 && isWordChar(parts[index - 1])) index--;
202
+ return parts.slice(0, index).join("").length;
203
+ }
204
+ wordBoundaryAfter() {
205
+ const parts = graphemes(this.text.slice(this.cursor));
206
+ let index = 0;
207
+ while (index < parts.length && !isWordChar(parts[index])) index++;
208
+ while (index < parts.length && isWordChar(parts[index])) index++;
209
+ return this.cursor + parts.slice(0, index).join("").length;
210
+ }
211
+ caret(grapheme) {
212
+ return this.focused ? inverse(grapheme) : grapheme;
213
+ }
214
+ renderLine(width) {
215
+ const room = Math.max(1, width - visibleWidth(this.prompt));
216
+ const before = graphemes(this.text.slice(0, this.cursor));
217
+ const after = graphemes(this.text.slice(this.cursor));
218
+ const atCursor = after.shift() ?? " ";
219
+ let used = visibleWidth(atCursor);
220
+ const left = [];
221
+ for (let index = before.length - 1; index >= 0 && used + visibleWidth(before[index]) <= room; index--) {
222
+ left.unshift(before[index]);
223
+ used += visibleWidth(before[index]);
224
+ }
225
+ const right = [];
226
+ for (const grapheme of after) {
227
+ if (used + visibleWidth(grapheme) > room) break;
228
+ right.push(grapheme);
229
+ used += visibleWidth(grapheme);
230
+ }
231
+ this.lastCursorRow = 0;
232
+ return `${this.prompt}${left.join("")}${this.caret(atCursor)}${right.join("")}`;
233
+ }
234
+ renderLines(width) {
235
+ const room = Math.max(1, width - visibleWidth(this.prompt));
236
+ const indent = " ".repeat(visibleWidth(this.prompt));
237
+ const rows = [];
238
+ let offset = 0;
239
+ this.lastCursorRow = 0;
240
+ for (const line of this.text.split("\n")) {
241
+ let row = "";
242
+ let used = 0;
243
+ let position = offset;
244
+ const cursorOnLine = this.cursor >= offset && this.cursor <= offset + line.length;
245
+ const flush = () => {
246
+ rows.push(`${rows.length === 0 ? this.prompt : indent}${row}`);
247
+ row = "";
248
+ used = 0;
249
+ };
250
+ for (const grapheme of graphemes(line)) {
251
+ const cells = visibleWidth(grapheme);
252
+ if (used + cells > room && used > 0) flush();
253
+ if (position === this.cursor) {
254
+ this.lastCursorRow = rows.length;
255
+ row += this.caret(grapheme);
256
+ } else {
257
+ row += grapheme;
258
+ }
259
+ used += cells;
260
+ position += grapheme.length;
261
+ }
262
+ if (cursorOnLine && this.cursor === offset + line.length) {
263
+ if (used + 1 > room && used > 0) flush();
264
+ this.lastCursorRow = rows.length;
265
+ row += this.caret(" ");
266
+ }
267
+ flush();
268
+ offset += line.length + 1;
269
+ }
270
+ return rows;
271
+ }
272
+ };
273
+
274
+ export {
275
+ TextField
276
+ };
277
+ //# sourceMappingURL=chunk-CHXPTZUF.js.map