@timurproko/a1 0.1.8-dev.50ebb19 → 0.1.8-dev.512

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 (869) hide show
  1. package/README.md +168 -65
  2. package/bin/activate.js +8 -0
  3. package/bin/cli.js +33 -11
  4. package/bin/guardian.js +16 -6
  5. package/bin/module-identity.js +76 -69
  6. package/bin/module-resolver.js +138 -0
  7. package/bin/pinned-pi-public.d.ts +3 -0
  8. package/bin/pinned-pi-public.js +93 -0
  9. package/bin/release-cleanup.js +8 -0
  10. package/bin/supervisor.js +2 -2
  11. package/bin/sync-pi-tui-proxy.js +7 -0
  12. package/bin/ui.js +67 -22
  13. package/bin/update-recovery.js +343 -0
  14. package/bin/warmup.js +28 -0
  15. package/dist/app/session-shell/clipboard-diagnostics.d.ts +16 -0
  16. package/dist/app/session-shell/clipboard-diagnostics.js +65 -0
  17. package/dist/app/session-shell/clipboard-image.d.ts +11 -0
  18. package/dist/app/session-shell/clipboard-image.js +38 -0
  19. package/dist/app/session-shell/editor-hyperlink-budget.d.ts +9 -0
  20. package/dist/app/session-shell/editor-hyperlink-budget.js +23 -0
  21. package/dist/app/session-shell/helper-pool.d.ts +33 -0
  22. package/dist/app/session-shell/helper-pool.js +98 -0
  23. package/dist/app/session-shell/image-preparation-client.d.ts +20 -0
  24. package/dist/app/session-shell/image-preparation-client.js +145 -0
  25. package/dist/app/session-shell/image-preparation.d.ts +18 -0
  26. package/dist/app/session-shell/image-preparation.js +126 -0
  27. package/dist/app/session-shell/image-source.d.ts +13 -0
  28. package/dist/app/session-shell/image-source.js +171 -0
  29. package/dist/app/session-shell/image-worker.d.ts +17 -0
  30. package/dist/app/session-shell/image-worker.js +23 -0
  31. package/dist/app/session-shell/index.d.ts +7 -0
  32. package/dist/app/session-shell/index.js +4 -0
  33. package/dist/app/session-shell/paste-executor.d.ts +18 -0
  34. package/dist/app/session-shell/paste-executor.js +253 -0
  35. package/dist/app/session-shell/paste-helper.js +173 -0
  36. package/dist/app/session-shell/paste-preparation-client.d.ts +31 -0
  37. package/dist/app/session-shell/paste-preparation-client.js +170 -0
  38. package/dist/app/session-shell/paste-protocol.d.ts +78 -0
  39. package/dist/app/session-shell/paste-protocol.js +18 -0
  40. package/dist/app/session-shell/paste-text-preparation.d.ts +6 -0
  41. package/dist/app/session-shell/paste-text-preparation.js +134 -0
  42. package/dist/app/session-shell/paste-text-worker.js +12 -0
  43. package/dist/app/session-shell/paste-types.d.ts +17 -0
  44. package/dist/app/session-shell/path-chip-presentation.d.ts +7 -0
  45. package/dist/app/session-shell/path-chip-presentation.js +24 -0
  46. package/dist/app/session-shell/prompt-chips.d.ts +76 -0
  47. package/dist/app/session-shell/prompt-chips.js +507 -0
  48. package/dist/app/session-shell/prompt-history-controller.d.ts +36 -0
  49. package/dist/app/session-shell/prompt-history-controller.js +170 -0
  50. package/dist/app/session-shell/prompt-suggestion-controller.d.ts +35 -0
  51. package/dist/app/session-shell/prompt-suggestion-controller.js +207 -0
  52. package/dist/app/session-shell/quit-outro-effects.d.ts +29 -0
  53. package/dist/app/session-shell/quit-outro-effects.js +242 -0
  54. package/dist/app/session-shell/quit-outro.d.ts +38 -0
  55. package/dist/app/session-shell/quit-outro.js +98 -0
  56. package/dist/app/session-shell/response-copy-coordinator.d.ts +27 -0
  57. package/dist/app/session-shell/response-copy-coordinator.js +187 -0
  58. package/dist/app/session-shell/response-copy-helper.js +122 -0
  59. package/dist/app/session-shell/response-copy-protocol.d.ts +56 -0
  60. package/dist/app/session-shell/response-copy-protocol.js +5 -0
  61. package/dist/app/session-shell/response-copy-transport.d.ts +39 -0
  62. package/dist/app/session-shell/response-copy-transport.js +217 -0
  63. package/dist/app/session-shell/session-shell-root.d.ts +265 -0
  64. package/dist/app/session-shell/session-shell-root.js +1366 -0
  65. package/dist/app/session-shell/session-shell.d.ts +59 -0
  66. package/dist/app/session-shell/session-shell.js +1917 -0
  67. package/dist/app/session-shell/session-viewport-controller.d.ts +61 -0
  68. package/dist/app/session-shell/session-viewport-controller.js +597 -0
  69. package/dist/app/session-shell/stream-presentation-coalescer.d.ts +29 -0
  70. package/dist/app/session-shell/stream-presentation-coalescer.js +79 -0
  71. package/dist/app/session-shell/system-clipboard.d.ts +20 -0
  72. package/dist/app/session-shell/system-clipboard.js +159 -0
  73. package/dist/app/session-shell/text-paste.d.ts +5 -0
  74. package/dist/app/session-shell/text-paste.js +16 -0
  75. package/dist/cli/capabilities.d.ts +6 -0
  76. package/dist/cli/capabilities.js +7 -0
  77. package/dist/cli/dispatch.d.ts +46 -0
  78. package/dist/cli/dispatch.js +261 -0
  79. package/dist/cli/index.d.ts +8 -0
  80. package/dist/cli/index.js +4 -0
  81. package/dist/cli/package-messages.d.ts +26 -0
  82. package/dist/cli/package-messages.js +71 -0
  83. package/dist/cli/packages.d.ts +32 -0
  84. package/dist/cli/packages.js +81 -0
  85. package/dist/cli/version-stats.d.ts +22 -0
  86. package/dist/cli/version-stats.js +112 -0
  87. package/dist/composition/index.d.ts +2 -0
  88. package/dist/composition/index.js +2 -0
  89. package/dist/composition/owned-ui.d.ts +37 -0
  90. package/dist/composition/owned-ui.js +136 -0
  91. package/dist/composition/settings-route-host.d.ts +7 -0
  92. package/dist/composition/settings-route-host.js +110 -0
  93. package/dist/contracts/agent-engine/capability-ports.d.ts +95 -0
  94. package/dist/contracts/agent-engine/domain-validation.js +107 -0
  95. package/dist/contracts/agent-engine/domain.d.ts +138 -0
  96. package/dist/contracts/agent-engine/index.d.ts +11 -0
  97. package/dist/contracts/agent-engine/index.js +6 -0
  98. package/dist/contracts/agent-engine/package-ports.d.ts +60 -0
  99. package/dist/contracts/agent-engine/ports.js +1 -0
  100. package/dist/contracts/owned-ui/extension-ui.d.ts +310 -0
  101. package/dist/contracts/owned-ui/image-attachments.d.ts +36 -0
  102. package/dist/contracts/owned-ui/image-attachments.js +67 -0
  103. package/dist/contracts/owned-ui/index.d.ts +12 -0
  104. package/dist/contracts/owned-ui/index.js +8 -0
  105. package/dist/contracts/owned-ui/model.d.ts +378 -0
  106. package/dist/contracts/owned-ui/prompt-history.d.ts +55 -0
  107. package/dist/contracts/owned-ui/prompt-history.js +23 -0
  108. package/dist/contracts/owned-ui/prompt-suggestions.d.ts +3 -0
  109. package/dist/contracts/owned-ui/prompt-suggestions.js +44 -0
  110. package/dist/contracts/owned-ui/suggestion-diagnostics.d.ts +22 -0
  111. package/dist/contracts/owned-ui/suggestion-diagnostics.js +9 -0
  112. package/dist/contracts/owned-ui/transcript-lifecycle.d.ts +5 -0
  113. package/dist/contracts/owned-ui/transcript-lifecycle.js +33 -0
  114. package/dist/contracts/owned-ui/validation.d.ts +15 -0
  115. package/dist/contracts/owned-ui/validation.js +523 -0
  116. package/dist/contracts/presentation/index.d.ts +104 -0
  117. package/dist/features/launch/development-launch.js +36 -0
  118. package/dist/features/launch/index.d.ts +12 -0
  119. package/dist/features/launch/index.js +6 -0
  120. package/dist/features/launch/intent.d.ts +12 -0
  121. package/dist/features/launch/intent.js +8 -0
  122. package/dist/features/launch/prepare-launch.d.ts +11 -0
  123. package/dist/features/launch/prepare-launch.js +14 -0
  124. package/dist/features/launch/profile-paths.d.ts +16 -0
  125. package/dist/features/launch/profile-paths.js +36 -0
  126. package/dist/features/launch/runtime-selection.d.ts +16 -0
  127. package/dist/features/launch/runtime-selection.js +13 -0
  128. package/dist/features/owned-ui/index.d.ts +6 -0
  129. package/dist/features/owned-ui/index.js +4 -0
  130. package/dist/features/owned-ui/project-trust-prompt.d.ts +25 -0
  131. package/dist/features/owned-ui/project-trust-prompt.js +149 -0
  132. package/dist/features/owned-ui/run.d.ts +17 -0
  133. package/dist/features/owned-ui/run.js +64 -0
  134. package/dist/features/owned-ui/session-fork-prompt.d.ts +8 -0
  135. package/dist/features/owned-ui/session-fork-prompt.js +34 -0
  136. package/dist/features/owned-ui/settings-app.d.ts +21 -0
  137. package/dist/features/owned-ui/settings-app.js +807 -0
  138. package/dist/features/owned-ui/settings-route.d.ts +2 -0
  139. package/dist/features/owned-ui/settings-route.js +2 -0
  140. package/dist/features/prompt-history/image-sidecar.d.ts +32 -0
  141. package/dist/features/prompt-history/image-sidecar.js +130 -0
  142. package/dist/features/prompt-history/index.d.ts +4 -0
  143. package/dist/features/prompt-history/index.js +3 -0
  144. package/dist/features/prompt-history/paths.d.ts +5 -0
  145. package/dist/features/prompt-history/paths.js +17 -0
  146. package/dist/features/prompt-history/service.d.ts +54 -0
  147. package/dist/features/prompt-history/service.js +425 -0
  148. package/dist/features/prompt-history/store.d.ts +16 -0
  149. package/dist/features/prompt-history/store.js +219 -0
  150. package/dist/features/prompt-history/worker.d.ts +9 -0
  151. package/dist/features/prompt-history/worker.js +45 -0
  152. package/dist/features/prompt-suggestions/diagnostics.d.ts +18 -0
  153. package/dist/features/prompt-suggestions/diagnostics.js +82 -0
  154. package/dist/features/prompt-suggestions/index.d.ts +2 -0
  155. package/dist/features/prompt-suggestions/index.js +1 -0
  156. package/dist/foundation/launch-context/index.d.ts +59 -0
  157. package/dist/foundation/launch-context/index.js +136 -0
  158. package/dist/foundation/launch-guardian/index.d.ts +2 -0
  159. package/dist/foundation/launch-guardian/index.js +1 -0
  160. package/dist/foundation/launch-guardian/main.d.ts +33 -0
  161. package/dist/foundation/launch-guardian/main.js +180 -0
  162. package/dist/foundation/lifecycle/commands.js +1 -0
  163. package/dist/foundation/lifecycle/index.d.ts +11 -0
  164. package/dist/foundation/lifecycle/index.js +5 -0
  165. package/dist/foundation/lifecycle/model.d.ts +64 -0
  166. package/dist/foundation/lifecycle/model.js +40 -0
  167. package/dist/foundation/lifecycle/paths.d.ts +30 -0
  168. package/dist/foundation/lifecycle/paths.js +70 -0
  169. package/dist/foundation/lifecycle/session-selection.d.ts +9 -0
  170. package/dist/foundation/lifecycle/session-selection.js +39 -0
  171. package/dist/foundation/lifecycle/supervisor-startup.d.ts +30 -0
  172. package/dist/foundation/lifecycle/supervisor-startup.js +106 -0
  173. package/dist/foundation/process-containment/darwin-process-inspector.d.ts +5 -0
  174. package/dist/foundation/process-containment/darwin-process-inspector.js +7 -0
  175. package/dist/foundation/process-containment/index.d.ts +8 -0
  176. package/dist/foundation/process-containment/index.js +6 -0
  177. package/dist/foundation/process-containment/linux-process-inspector.d.ts +7 -0
  178. package/dist/foundation/process-containment/linux-process-inspector.js +27 -0
  179. package/dist/foundation/process-containment/native-guardian-containment.d.ts +17 -0
  180. package/dist/foundation/process-containment/native-guardian-containment.js +140 -0
  181. package/dist/foundation/process-containment/windows-process-inspector.d.ts +19 -0
  182. package/dist/foundation/process-containment/windows-process-inspector.js +56 -0
  183. package/dist/foundation/protocol/client.d.ts +18 -0
  184. package/dist/foundation/protocol/client.js +130 -0
  185. package/dist/foundation/protocol/index.d.ts +3 -0
  186. package/dist/foundation/protocol/index.js +2 -0
  187. package/dist/foundation/protocol/messages.d.ts +90 -0
  188. package/dist/foundation/protocol/messages.js +100 -0
  189. package/dist/foundation/release/bootstrap.d.ts +51 -0
  190. package/dist/foundation/release/bootstrap.js +427 -0
  191. package/dist/foundation/release/cohort-state.d.ts +157 -0
  192. package/dist/foundation/release/cohort-state.js +472 -0
  193. package/dist/foundation/release/dependency-certification-retention.d.ts +7 -0
  194. package/dist/foundation/release/dependency-certification-retention.js +88 -0
  195. package/dist/foundation/release/dependency-certification.d.ts +24 -0
  196. package/dist/foundation/release/dependency-certification.js +266 -0
  197. package/dist/foundation/release/dependency-layer.d.ts +78 -0
  198. package/dist/foundation/release/dependency-layer.js +466 -0
  199. package/dist/foundation/release/endpoints.d.ts +24 -0
  200. package/dist/foundation/release/endpoints.js +134 -0
  201. package/dist/foundation/release/immutable-platform.d.ts +6 -0
  202. package/dist/foundation/release/immutable-platform.js +13 -0
  203. package/dist/foundation/release/index.d.ts +32 -0
  204. package/dist/foundation/release/index.js +17 -0
  205. package/dist/foundation/release/release-gc.d.ts +71 -0
  206. package/dist/foundation/release/release-gc.js +764 -0
  207. package/dist/foundation/release/release-store.d.ts +49 -0
  208. package/dist/foundation/release/release-store.js +235 -0
  209. package/dist/foundation/release/release.d.ts +43 -0
  210. package/dist/foundation/release/release.js +215 -0
  211. package/dist/foundation/release/restart-certification.d.ts +68 -0
  212. package/dist/foundation/release/restart-certification.js +227 -0
  213. package/dist/foundation/release/types.d.ts +11 -0
  214. package/dist/foundation/release/types.js +1 -0
  215. package/dist/foundation/release/update-activation.d.ts +72 -0
  216. package/dist/foundation/release/update-activation.js +204 -0
  217. package/dist/foundation/release/update-launch.d.ts +6 -0
  218. package/dist/foundation/release/update-launch.js +17 -0
  219. package/dist/foundation/release/update-recovery.d.ts +76 -0
  220. package/dist/foundation/release/update-recovery.js +356 -0
  221. package/dist/foundation/release/update-transaction.d.ts +42 -0
  222. package/dist/foundation/release/update-transaction.js +101 -0
  223. package/dist/foundation/release/update.d.ts +114 -0
  224. package/dist/foundation/release/update.js +633 -0
  225. package/dist/foundation/release/warmup.d.ts +3 -0
  226. package/dist/foundation/release/warmup.js +47 -0
  227. package/dist/foundation/startup/index.d.ts +4 -0
  228. package/dist/foundation/startup/index.js +2 -0
  229. package/dist/foundation/startup/startup-budget.d.ts +46 -0
  230. package/dist/foundation/startup/startup-budget.js +42 -0
  231. package/dist/foundation/startup/startup-descriptor.js +34 -0
  232. package/dist/foundation/startup/startup-runtime.d.ts +27 -0
  233. package/dist/foundation/startup/startup-runtime.js +128 -0
  234. package/dist/foundation/storage/control-store.d.ts +18 -0
  235. package/dist/foundation/storage/control-store.js +342 -0
  236. package/dist/foundation/storage/index.d.ts +1 -0
  237. package/dist/foundation/storage/index.js +1 -0
  238. package/dist/foundation/supervision/index.d.ts +3 -0
  239. package/dist/foundation/supervision/index.js +3 -0
  240. package/dist/foundation/supervision/main.d.ts +1 -0
  241. package/dist/foundation/supervision/main.js +84 -0
  242. package/dist/foundation/supervision/paths.d.ts +1 -0
  243. package/dist/foundation/supervision/paths.js +1 -0
  244. package/dist/foundation/supervision/server.d.ts +46 -0
  245. package/dist/foundation/supervision/server.js +573 -0
  246. package/dist/foundation/terminal-cleanup/fatal-exit.d.ts +12 -0
  247. package/dist/foundation/terminal-cleanup/fatal-exit.js +87 -0
  248. package/dist/foundation/terminal-cleanup/index.d.ts +3 -0
  249. package/dist/foundation/terminal-cleanup/index.js +2 -0
  250. package/dist/foundation/terminal-cleanup/terminal-reset.d.ts +4 -0
  251. package/dist/foundation/terminal-cleanup/terminal-reset.js +40 -0
  252. package/dist/integrations/pi/components/components.d.ts +4 -0
  253. package/dist/integrations/pi/components/components.js +64 -0
  254. package/dist/integrations/pi/components/conformance.d.ts +18 -0
  255. package/dist/integrations/pi/components/conformance.js +70 -0
  256. package/dist/integrations/pi/components/editor-interaction.d.ts +38 -0
  257. package/dist/integrations/pi/components/editor-interaction.js +1 -0
  258. package/dist/integrations/pi/components/history-editor-loader.d.ts +5 -0
  259. package/dist/integrations/pi/components/history-editor-loader.js +5 -0
  260. package/dist/integrations/pi/components/index.d.ts +21 -0
  261. package/dist/integrations/pi/components/index.js +13 -0
  262. package/dist/integrations/pi/components/owned-editor-ux.d.ts +74 -0
  263. package/dist/integrations/pi/components/owned-editor-ux.js +1094 -0
  264. package/dist/integrations/pi/components/path-word-ranges.d.ts +2 -0
  265. package/dist/integrations/pi/components/path-word-ranges.js +37 -0
  266. package/dist/integrations/pi/components/prompt-input-port.d.ts +18 -0
  267. package/dist/integrations/pi/components/prompt-input-port.js +1 -0
  268. package/dist/integrations/pi/components/resources/builtin-themes.d.ts +167 -0
  269. package/dist/integrations/pi/components/resources/builtin-themes.js +168 -0
  270. package/dist/integrations/pi/components/shell-components.d.ts +7 -0
  271. package/dist/integrations/pi/components/shell-components.js +7 -0
  272. package/dist/integrations/pi/components/shell-editor-autocomplete.js +298 -0
  273. package/dist/integrations/pi/components/shell-extension-ui.d.ts +35 -0
  274. package/dist/integrations/pi/components/shell-extension-ui.js +280 -0
  275. package/dist/integrations/pi/components/shell-footer-status.d.ts +7 -0
  276. package/dist/integrations/pi/components/shell-footer-status.js +248 -0
  277. package/dist/integrations/pi/components/shell-presenters-info.d.ts +43 -0
  278. package/dist/integrations/pi/components/shell-presenters-info.js +114 -0
  279. package/dist/integrations/pi/components/shell-presenters-transcript.d.ts +29 -0
  280. package/dist/integrations/pi/components/shell-presenters-transcript.js +433 -0
  281. package/dist/integrations/pi/components/shell-selectors-dialogs.d.ts +123 -0
  282. package/dist/integrations/pi/components/shell-selectors-dialogs.js +242 -0
  283. package/dist/integrations/pi/components/shell-shared-facade.d.ts +217 -0
  284. package/dist/integrations/pi/components/shell-shared-facade.js +92 -0
  285. package/dist/integrations/pi/components/submitted-prompt-adapter.d.ts +17 -0
  286. package/dist/integrations/pi/components/submitted-prompt-adapter.js +49 -0
  287. package/dist/integrations/pi/components/tool-image-presentation.d.ts +21 -0
  288. package/dist/integrations/pi/components/tool-image-presentation.js +83 -0
  289. package/dist/integrations/pi/components/tool-result-adapter.d.ts +6 -0
  290. package/dist/integrations/pi/components/tool-result-adapter.js +27 -0
  291. package/dist/integrations/pi/components/transcript-image-resolver.d.ts +7 -0
  292. package/dist/integrations/pi/components/transcript-image-resolver.js +19 -0
  293. package/dist/integrations/pi/components/upstream/adjacent/core/keybindings.d.ts +445 -0
  294. package/dist/integrations/pi/components/upstream/adjacent/core/keybindings.js +370 -0
  295. package/dist/integrations/pi/components/upstream/assets/earendil-image.json +12 -0
  296. package/dist/integrations/pi/components/upstream/components/countdown-timer.d.ts +13 -0
  297. package/dist/integrations/pi/components/upstream/components/daxnuts.d.ts +29 -0
  298. package/dist/integrations/pi/components/upstream/components/daxnuts.js +146 -0
  299. package/dist/integrations/pi/components/upstream/components/earendil-announcement.d.ts +4 -0
  300. package/dist/integrations/pi/components/upstream/components/earendil-announcement.js +48 -0
  301. package/dist/integrations/pi/components/upstream/components/extension-editor.d.ts +20 -0
  302. package/dist/integrations/pi/components/upstream/components/extension-editor.js +84 -0
  303. package/dist/integrations/pi/components/upstream/components/mermaid.js +81 -0
  304. package/dist/integrations/pi/components/upstream/components/owned-editor.d.ts +46 -0
  305. package/dist/integrations/pi/components/upstream/components/owned-editor.js +187 -0
  306. package/dist/integrations/pi/components/upstream/components/scoped-models-selector.d.ts +59 -0
  307. package/dist/integrations/pi/components/upstream/components/scoped-models-selector.js +346 -0
  308. package/dist/integrations/pi/components/upstream/components/session-footer.d.ts +11 -0
  309. package/dist/integrations/pi/components/upstream/components/session-footer.js +123 -0
  310. package/dist/integrations/pi/components/upstream/components/session-selector-search.js +161 -0
  311. package/dist/integrations/pi/components/upstream/components/session-selector.d.ts +95 -0
  312. package/dist/integrations/pi/components/upstream/components/session-selector.js +893 -0
  313. package/dist/integrations/pi/components/upstream/components/skill-invocation-message.d.ts +21 -0
  314. package/dist/integrations/pi/components/upstream/components/skill-invocation-message.js +46 -0
  315. package/dist/integrations/pi/components/upstream/components/status-indicator.d.ts +35 -0
  316. package/dist/integrations/pi/components/upstream/components/status-indicator.js +69 -0
  317. package/dist/integrations/pi/components/upstream/components/tool-execution.d.ts +67 -0
  318. package/dist/integrations/pi/components/upstream/components/tool-execution.js +365 -0
  319. package/dist/integrations/pi/components/upstream/components/tree-selector.d.ts +101 -0
  320. package/dist/integrations/pi/components/upstream/components/tree-selector.js +1275 -0
  321. package/dist/integrations/pi/components/upstream/components/trust-selector.d.ts +33 -0
  322. package/dist/integrations/pi/components/upstream/components/trust-selector.js +81 -0
  323. package/dist/integrations/pi/components/upstream/external-editor.js +43 -0
  324. package/dist/integrations/pi/components/upstream/history/editor-core.d.ts +289 -0
  325. package/dist/integrations/pi/components/upstream/history/editor-core.js +2144 -0
  326. package/dist/integrations/pi/components/upstream/history/kill-ring.d.ts +35 -0
  327. package/dist/integrations/pi/components/upstream/history/kill-ring.js +51 -0
  328. package/dist/integrations/pi/components/upstream/history/printable-key.d.ts +1 -0
  329. package/dist/integrations/pi/components/upstream/history/printable-key.js +43 -0
  330. package/dist/integrations/pi/components/upstream/history/text-helpers.d.ts +14 -0
  331. package/dist/integrations/pi/components/upstream/history/text-helpers.js +31 -0
  332. package/dist/integrations/pi/components/upstream/history/undo-stack.d.ts +25 -0
  333. package/dist/integrations/pi/components/upstream/history/undo-stack.js +39 -0
  334. package/dist/integrations/pi/components/upstream/history/word-navigation.d.ts +24 -0
  335. package/dist/integrations/pi/components/upstream/history/word-navigation.js +103 -0
  336. package/dist/integrations/pi/components/upstream/model-search.d.ts +18 -0
  337. package/dist/integrations/pi/components/upstream/theme/theme-controller.d.ts +33 -0
  338. package/dist/integrations/pi/components/upstream/theme/theme-controller.js +114 -0
  339. package/dist/integrations/pi/components/upstream/theme/theme.d.ts +61 -0
  340. package/dist/integrations/pi/components/upstream/theme/theme.js +337 -0
  341. package/dist/integrations/pi/engine/adapter.d.ts +135 -0
  342. package/dist/integrations/pi/engine/adapter.js +648 -0
  343. package/dist/integrations/pi/engine/changelog.d.ts +2 -0
  344. package/dist/integrations/pi/engine/changelog.js +63 -0
  345. package/dist/integrations/pi/engine/command-dispatch.d.ts +41 -0
  346. package/dist/integrations/pi/engine/command-dispatch.js +125 -0
  347. package/dist/integrations/pi/engine/compaction-progress.d.ts +28 -0
  348. package/dist/integrations/pi/engine/compaction-progress.js +96 -0
  349. package/dist/integrations/pi/engine/conformance.d.ts +39 -0
  350. package/dist/integrations/pi/engine/conformance.js +140 -0
  351. package/dist/integrations/pi/engine/event-delivery.d.ts +100 -0
  352. package/dist/integrations/pi/engine/event-delivery.js +184 -0
  353. package/dist/integrations/pi/engine/extension-ui-binding.d.ts +35 -0
  354. package/dist/integrations/pi/engine/extension-ui-binding.js +81 -0
  355. package/dist/integrations/pi/engine/http-dispatcher.d.ts +4 -0
  356. package/dist/integrations/pi/engine/http-dispatcher.js +25 -0
  357. package/dist/integrations/pi/engine/index.d.ts +18 -0
  358. package/dist/integrations/pi/engine/index.js +10 -0
  359. package/dist/integrations/pi/engine/message-values.d.ts +29 -0
  360. package/dist/integrations/pi/engine/message-values.js +168 -0
  361. package/dist/integrations/pi/engine/package-integration.d.ts +13 -0
  362. package/dist/integrations/pi/engine/package-integration.js +118 -0
  363. package/dist/integrations/pi/engine/pending-delivery.d.ts +30 -0
  364. package/dist/integrations/pi/engine/pending-delivery.js +156 -0
  365. package/dist/integrations/pi/engine/pi-settings-metadata.json +385 -0
  366. package/dist/integrations/pi/engine/project-trust-preflight.d.ts +22 -0
  367. package/dist/integrations/pi/engine/project-trust-preflight.js +50 -0
  368. package/dist/integrations/pi/engine/prompt-suggestions.d.ts +30 -0
  369. package/dist/integrations/pi/engine/prompt-suggestions.js +102 -0
  370. package/dist/integrations/pi/engine/provider-authentication.d.ts +34 -0
  371. package/dist/integrations/pi/engine/provider-authentication.js +209 -0
  372. package/dist/integrations/pi/engine/resource-catalog.d.ts +49 -0
  373. package/dist/integrations/pi/engine/resource-catalog.js +289 -0
  374. package/dist/integrations/pi/engine/resources/changelog.json +12 -0
  375. package/dist/integrations/pi/engine/runtime-integration.d.ts +53 -0
  376. package/dist/integrations/pi/engine/runtime-integration.js +118 -0
  377. package/dist/integrations/pi/engine/session-events.d.ts +48 -0
  378. package/dist/integrations/pi/engine/session-events.js +223 -0
  379. package/dist/integrations/pi/engine/session-integration.d.ts +67 -0
  380. package/dist/integrations/pi/engine/session-integration.js +195 -0
  381. package/dist/integrations/pi/engine/session-runtime.d.ts +84 -0
  382. package/dist/integrations/pi/engine/session-runtime.js +249 -0
  383. package/dist/integrations/pi/engine/session-selection.d.ts +28 -0
  384. package/dist/integrations/pi/engine/session-selection.js +90 -0
  385. package/dist/integrations/pi/engine/settings-bridge.d.ts +121 -0
  386. package/dist/integrations/pi/engine/settings-bridge.js +514 -0
  387. package/dist/integrations/pi/engine/settings-metadata.d.ts +31 -0
  388. package/dist/integrations/pi/engine/settings-metadata.js +67 -0
  389. package/dist/integrations/pi/engine/settings-port.d.ts +42 -0
  390. package/dist/integrations/pi/engine/settings-port.js +353 -0
  391. package/dist/integrations/pi/engine/tool-rendering.d.ts +13 -0
  392. package/dist/integrations/pi/engine/tool-rendering.js +145 -0
  393. package/dist/integrations/pi/engine/transcript-image-assets.d.ts +11 -0
  394. package/dist/integrations/pi/engine/transcript-image-assets.js +86 -0
  395. package/dist/integrations/pi/engine/transcript-projection.d.ts +39 -0
  396. package/dist/integrations/pi/engine/transcript-projection.js +405 -0
  397. package/dist/integrations/pi/engine/usage-view.d.ts +4 -0
  398. package/dist/integrations/pi/engine/usage-view.js +56 -0
  399. package/dist/integrations/pi/engine/windows-filesystem-hygiene.d.ts +21 -0
  400. package/dist/integrations/pi/engine/windows-filesystem-hygiene.js +55 -0
  401. package/dist/integrations/pi/engine/workflow-contexts.d.ts +59 -0
  402. package/dist/integrations/pi/engine/workflow-contexts.js +316 -0
  403. package/dist/integrations/pi/engine/workflow-runner.d.ts +60 -0
  404. package/dist/integrations/pi/engine/workflow-runner.js +509 -0
  405. package/dist/integrations/pi/engine/workflow-support.d.ts +33 -0
  406. package/dist/integrations/pi/engine/workflow-support.js +352 -0
  407. package/dist/integrations/pi/engine/workflows.d.ts +251 -0
  408. package/dist/integrations/pi/engine/workflows.js +63 -0
  409. package/dist/integrations/pi/startup-public.d.ts +2 -0
  410. package/dist/integrations/pi/startup-public.js +2223 -0
  411. package/dist/integrations/pi/startup-public.manifest.json +12502 -0
  412. package/dist/integrations/pi/tui-runtime/adapter.d.ts +56 -0
  413. package/dist/integrations/pi/tui-runtime/adapter.js +783 -0
  414. package/dist/integrations/pi/tui-runtime/contracts.d.ts +156 -0
  415. package/dist/integrations/pi/tui-runtime/contracts.js +1 -0
  416. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.d.ts +88 -0
  417. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.js +433 -0
  418. package/dist/integrations/pi/tui-runtime/index.d.ts +9 -0
  419. package/dist/integrations/pi/tui-runtime/index.js +5 -0
  420. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.d.ts +39 -0
  421. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.js +139 -0
  422. package/dist/integrations/pi/tui-runtime/mouse-report-input.d.ts +13 -0
  423. package/dist/integrations/pi/tui-runtime/mouse-report-input.js +57 -0
  424. package/dist/integrations/pi/tui-runtime/overlay-geometry.d.ts +32 -0
  425. package/dist/integrations/pi/tui-runtime/overlay-geometry.js +158 -0
  426. package/dist/integrations/pi/tui-runtime/presentation-adapter.d.ts +4 -0
  427. package/dist/integrations/pi/tui-runtime/presentation-adapter.js +48 -0
  428. package/dist/native/darwin-arm64/manifest.json +4 -4
  429. package/dist/native/darwin-arm64/process-guardian +0 -0
  430. package/dist/native/linux-x64/manifest.json +3 -3
  431. package/dist/native/linux-x64/process-guardian +0 -0
  432. package/dist/native/win32-x64/manifest.json +3 -3
  433. package/dist/native/win32-x64/process-guardian.exe +0 -0
  434. package/dist/product-identity.d.ts +37 -0
  435. package/dist/product-identity.js +119 -0
  436. package/dist/product-identity.json +85 -0
  437. package/dist/runtime-payload-inventory.json +127148 -0
  438. package/dist/ui/apps/contracts.d.ts +64 -0
  439. package/dist/ui/apps/host.d.ts +42 -0
  440. package/dist/ui/apps/host.js +156 -0
  441. package/dist/ui/apps/index.d.ts +5 -0
  442. package/dist/ui/apps/index.js +3 -0
  443. package/dist/ui/apps/registry.d.ts +12 -0
  444. package/dist/ui/apps/registry.js +33 -0
  445. package/dist/ui/components/dialog-panel.js +49 -0
  446. package/dist/ui/components/frame.d.ts +22 -0
  447. package/dist/ui/components/frame.js +55 -0
  448. package/dist/ui/components/index.d.ts +47 -0
  449. package/dist/ui/components/index.js +25 -0
  450. package/dist/ui/components/line-input.d.ts +68 -0
  451. package/dist/ui/components/line-input.js +224 -0
  452. package/dist/ui/components/list-view.d.ts +60 -0
  453. package/dist/ui/components/list-view.js +82 -0
  454. package/dist/ui/components/mouse.d.ts +25 -0
  455. package/dist/ui/components/mouse.js +70 -0
  456. package/dist/ui/components/progress-status.d.ts +2 -0
  457. package/dist/ui/components/progress-status.js +4 -0
  458. package/dist/ui/components/prompt-input.d.ts +32 -0
  459. package/dist/ui/components/prompt-input.js +51 -0
  460. package/dist/ui/components/scrollbar.d.ts +88 -0
  461. package/dist/ui/components/scrollbar.js +137 -0
  462. package/dist/ui/components/selection-copy.d.ts +24 -0
  463. package/dist/ui/components/selection-copy.js +39 -0
  464. package/dist/ui/components/shortcuts.d.ts +58 -0
  465. package/dist/ui/components/shortcuts.js +82 -0
  466. package/dist/ui/components/spans.d.ts +28 -0
  467. package/dist/ui/components/spans.js +266 -0
  468. package/dist/ui/components/submitted-prompt.d.ts +23 -0
  469. package/dist/ui/components/submitted-prompt.js +50 -0
  470. package/dist/ui/components/surface.d.ts +20 -0
  471. package/dist/ui/components/surface.js +44 -0
  472. package/dist/ui/components/text-selection.d.ts +62 -0
  473. package/dist/ui/components/text-selection.js +210 -0
  474. package/dist/ui/components/text.d.ts +38 -0
  475. package/dist/ui/components/text.js +185 -0
  476. package/dist/ui/components/transcript-viewport.d.ts +173 -0
  477. package/dist/ui/components/transcript-viewport.js +753 -0
  478. package/dist/ui/components/visible-hyperlinks.d.ts +26 -0
  479. package/dist/ui/components/visible-hyperlinks.js +97 -0
  480. package/dist/ui/settings/declarations.d.ts +141 -0
  481. package/dist/ui/settings/declarations.js +135 -0
  482. package/dist/ui/settings/index.d.ts +10 -0
  483. package/dist/ui/settings/index.js +5 -0
  484. package/dist/ui/settings/manager.d.ts +54 -0
  485. package/dist/ui/settings/manager.js +256 -0
  486. package/dist/ui/settings/migrations.d.ts +13 -0
  487. package/dist/ui/settings/migrations.js +74 -0
  488. package/dist/ui/settings/sections.d.ts +52 -0
  489. package/dist/ui/settings/sections.js +112 -0
  490. package/docs/architecture/boundaries.md +17 -13
  491. package/docs/architecture/code-documentation.md +77 -0
  492. package/docs/architecture/history-editor-provenance.md +100 -0
  493. package/docs/architecture/internal-naming.md +93 -0
  494. package/docs/architecture/process-guardian-provenance.md +3 -1
  495. package/docs/architecture/project-structure.md +69 -30
  496. package/docs/architecture/prompt-suggestions.md +68 -0
  497. package/docs/architecture/resource-and-data-policy.md +28 -2
  498. package/docs/architecture/response-copy-delivery.md +85 -0
  499. package/docs/architecture/terminal-host-proof-gate.md +1 -1
  500. package/docs/architecture/terminal-host-spike-evidence.md +1 -1
  501. package/docs/architecture/tool-image-presentation.md +62 -0
  502. package/docs/architecture/toolchain.md +32 -10
  503. package/docs/architecture/ui-reference-provenance.md +60 -6
  504. package/docs/ci-release-runbook.md +256 -79
  505. package/docs/features/launch-profiles.md +24 -17
  506. package/docs/features/modal-content-interaction.md +37 -0
  507. package/docs/features/prompt-history.md +149 -0
  508. package/docs/local-worktree-cleanup.md +212 -0
  509. package/docs/manual-code-streaming-cleanup.md +88 -0
  510. package/docs/manual-ghost-link-baseline.md +89 -0
  511. package/docs/manual-launch-instance-acceptance.md +12 -35
  512. package/docs/manual-owned-ui-checkpoint.md +79 -0
  513. package/docs/manual-pi-boundary-candidate.md +4 -5
  514. package/docs/manual-terminal-colour-check.md +4 -3
  515. package/docs/openspec-archive-automation.md +259 -0
  516. package/docs/repository-governance-live-acceptance.md +77 -0
  517. package/docs/validation.md +100 -0
  518. package/package.json +52 -34
  519. package/dist/src/cli/capabilities.d.ts +0 -15
  520. package/dist/src/cli/capabilities.js +0 -7
  521. package/dist/src/cli/dispatch.d.ts +0 -32
  522. package/dist/src/cli/dispatch.js +0 -142
  523. package/dist/src/cli/index.d.ts +0 -5
  524. package/dist/src/cli/index.js +0 -5
  525. package/dist/src/cli/packages.d.ts +0 -23
  526. package/dist/src/cli/packages.js +0 -84
  527. package/dist/src/cli/version-stats.d.ts +0 -16
  528. package/dist/src/cli/version-stats.js +0 -72
  529. package/dist/src/cli/version.d.ts +0 -2
  530. package/dist/src/cli/version.js +0 -23
  531. package/dist/src/composition/index.d.ts +0 -48
  532. package/dist/src/composition/index.js +0 -258
  533. package/dist/src/features/launch/development-launch.js +0 -28
  534. package/dist/src/features/launch/index.d.ts +0 -7
  535. package/dist/src/features/launch/index.js +0 -7
  536. package/dist/src/features/launch/intent.d.ts +0 -7
  537. package/dist/src/features/launch/intent.js +0 -4
  538. package/dist/src/features/launch/prepare-launch.d.ts +0 -13
  539. package/dist/src/features/launch/prepare-launch.js +0 -21
  540. package/dist/src/features/launch/profile-paths.d.ts +0 -15
  541. package/dist/src/features/launch/profile-paths.js +0 -31
  542. package/dist/src/features/launch/profiles.d.ts +0 -12
  543. package/dist/src/features/launch/profiles.js +0 -26
  544. package/dist/src/features/launch/runtime-selection.d.ts +0 -19
  545. package/dist/src/features/launch/runtime-selection.js +0 -13
  546. package/dist/src/features/owned-ui/customization.d.ts +0 -38
  547. package/dist/src/features/owned-ui/customization.js +0 -108
  548. package/dist/src/features/owned-ui/diagnostics.d.ts +0 -33
  549. package/dist/src/features/owned-ui/diagnostics.js +0 -94
  550. package/dist/src/features/owned-ui/index.d.ts +0 -4
  551. package/dist/src/features/owned-ui/index.js +0 -4
  552. package/dist/src/features/owned-ui/run.d.ts +0 -11
  553. package/dist/src/features/owned-ui/run.js +0 -15
  554. package/dist/src/features/owned-ui/settings-app.d.ts +0 -22
  555. package/dist/src/features/owned-ui/settings-app.js +0 -633
  556. package/dist/src/features/workspace/capabilities.d.ts +0 -31
  557. package/dist/src/features/workspace/capabilities.js +0 -75
  558. package/dist/src/features/workspace/index.d.ts +0 -6
  559. package/dist/src/features/workspace/index.js +0 -6
  560. package/dist/src/features/workspace/presentation.d.ts +0 -30
  561. package/dist/src/features/workspace/presentation.js +0 -70
  562. package/dist/src/features/workspace/reconciliation.d.ts +0 -15
  563. package/dist/src/features/workspace/reconciliation.js +0 -82
  564. package/dist/src/features/workspace/reducer.d.ts +0 -42
  565. package/dist/src/features/workspace/reducer.js +0 -213
  566. package/dist/src/features/workspace/router.d.ts +0 -31
  567. package/dist/src/features/workspace/router.js +0 -124
  568. package/dist/src/features/workspace/store.d.ts +0 -17
  569. package/dist/src/features/workspace/store.js +0 -54
  570. package/dist/src/foundation/agent-engine-contracts/capability-ports.d.ts +0 -95
  571. package/dist/src/foundation/agent-engine-contracts/domain-validation.js +0 -89
  572. package/dist/src/foundation/agent-engine-contracts/domain.d.ts +0 -116
  573. package/dist/src/foundation/agent-engine-contracts/index.d.ts +0 -8
  574. package/dist/src/foundation/agent-engine-contracts/index.js +0 -8
  575. package/dist/src/foundation/agent-engine-contracts/package-ports.d.ts +0 -54
  576. package/dist/src/foundation/launch-guardian/index.d.ts +0 -1
  577. package/dist/src/foundation/launch-guardian/index.js +0 -1
  578. package/dist/src/foundation/launch-guardian/main.d.ts +0 -31
  579. package/dist/src/foundation/launch-guardian/main.js +0 -165
  580. package/dist/src/foundation/lifecycle/index.d.ts +0 -4
  581. package/dist/src/foundation/lifecycle/index.js +0 -4
  582. package/dist/src/foundation/lifecycle/model.d.ts +0 -64
  583. package/dist/src/foundation/lifecycle/model.js +0 -40
  584. package/dist/src/foundation/lifecycle/paths.d.ts +0 -10
  585. package/dist/src/foundation/lifecycle/paths.js +0 -42
  586. package/dist/src/foundation/native-host-protocol/codec.d.ts +0 -11
  587. package/dist/src/foundation/native-host-protocol/codec.js +0 -56
  588. package/dist/src/foundation/native-host-protocol/evidence.d.ts +0 -67
  589. package/dist/src/foundation/native-host-protocol/evidence.js +0 -141
  590. package/dist/src/foundation/native-host-protocol/index.d.ts +0 -4
  591. package/dist/src/foundation/native-host-protocol/index.js +0 -4
  592. package/dist/src/foundation/native-host-protocol/messages.d.ts +0 -56
  593. package/dist/src/foundation/native-host-protocol/messages.js +0 -149
  594. package/dist/src/foundation/native-host-protocol/proof-gate.d.ts +0 -13
  595. package/dist/src/foundation/native-host-protocol/proof-gate.js +0 -33
  596. package/dist/src/foundation/owned-ui-contracts/extension-ui.d.ts +0 -302
  597. package/dist/src/foundation/owned-ui-contracts/index.d.ts +0 -3
  598. package/dist/src/foundation/owned-ui-contracts/index.js +0 -3
  599. package/dist/src/foundation/owned-ui-contracts/model.d.ts +0 -241
  600. package/dist/src/foundation/owned-ui-contracts/validation.d.ts +0 -11
  601. package/dist/src/foundation/owned-ui-contracts/validation.js +0 -395
  602. package/dist/src/foundation/owned-ui-settings/declarations.d.ts +0 -13
  603. package/dist/src/foundation/owned-ui-settings/declarations.js +0 -39
  604. package/dist/src/foundation/owned-ui-settings/index.d.ts +0 -6
  605. package/dist/src/foundation/owned-ui-settings/index.js +0 -6
  606. package/dist/src/foundation/owned-ui-settings/migrations.d.ts +0 -13
  607. package/dist/src/foundation/owned-ui-settings/migrations.js +0 -28
  608. package/dist/src/foundation/owned-ui-settings/sections.d.ts +0 -70
  609. package/dist/src/foundation/owned-ui-settings/sections.js +0 -93
  610. package/dist/src/foundation/owned-ui-settings/session.d.ts +0 -44
  611. package/dist/src/foundation/owned-ui-settings/session.js +0 -145
  612. package/dist/src/foundation/owned-ui-settings/store.d.ts +0 -28
  613. package/dist/src/foundation/owned-ui-settings/store.js +0 -90
  614. package/dist/src/foundation/pi-component-adapter/components.d.ts +0 -4
  615. package/dist/src/foundation/pi-component-adapter/components.js +0 -64
  616. package/dist/src/foundation/pi-component-adapter/conformance.d.ts +0 -17
  617. package/dist/src/foundation/pi-component-adapter/conformance.js +0 -69
  618. package/dist/src/foundation/pi-component-adapter/index.d.ts +0 -13
  619. package/dist/src/foundation/pi-component-adapter/index.js +0 -13
  620. package/dist/src/foundation/pi-component-adapter/resources/builtin-themes.d.ts +0 -165
  621. package/dist/src/foundation/pi-component-adapter/resources/builtin-themes.js +0 -166
  622. package/dist/src/foundation/pi-component-adapter/shell-components.d.ts +0 -6
  623. package/dist/src/foundation/pi-component-adapter/shell-components.js +0 -6
  624. package/dist/src/foundation/pi-component-adapter/shell-editor-autocomplete.js +0 -162
  625. package/dist/src/foundation/pi-component-adapter/shell-extension-ui.d.ts +0 -35
  626. package/dist/src/foundation/pi-component-adapter/shell-extension-ui.js +0 -279
  627. package/dist/src/foundation/pi-component-adapter/shell-footer-status.d.ts +0 -7
  628. package/dist/src/foundation/pi-component-adapter/shell-footer-status.js +0 -189
  629. package/dist/src/foundation/pi-component-adapter/shell-presenters-transcript.d.ts +0 -57
  630. package/dist/src/foundation/pi-component-adapter/shell-presenters-transcript.js +0 -429
  631. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.d.ts +0 -113
  632. package/dist/src/foundation/pi-component-adapter/shell-selectors-dialogs.js +0 -235
  633. package/dist/src/foundation/pi-component-adapter/shell-shared-facade.d.ts +0 -116
  634. package/dist/src/foundation/pi-component-adapter/shell-shared-facade.js +0 -87
  635. package/dist/src/foundation/pi-component-adapter/upstream/adjacent/core/keybindings.d.ts +0 -422
  636. package/dist/src/foundation/pi-component-adapter/upstream/adjacent/core/keybindings.js +0 -296
  637. package/dist/src/foundation/pi-component-adapter/upstream/components/countdown-timer.d.ts +0 -10
  638. package/dist/src/foundation/pi-component-adapter/upstream/components/custom-entry.d.ts +0 -17
  639. package/dist/src/foundation/pi-component-adapter/upstream/components/custom-entry.js +0 -51
  640. package/dist/src/foundation/pi-component-adapter/upstream/components/daxnuts.d.ts +0 -22
  641. package/dist/src/foundation/pi-component-adapter/upstream/components/daxnuts.js +0 -142
  642. package/dist/src/foundation/pi-component-adapter/upstream/components/earendil-announcement.d.ts +0 -4
  643. package/dist/src/foundation/pi-component-adapter/upstream/components/earendil-announcement.js +0 -19
  644. package/dist/src/foundation/pi-component-adapter/upstream/components/extension-editor.d.ts +0 -17
  645. package/dist/src/foundation/pi-component-adapter/upstream/components/extension-editor.js +0 -81
  646. package/dist/src/foundation/pi-component-adapter/upstream/components/first-time-setup.d.ts +0 -24
  647. package/dist/src/foundation/pi-component-adapter/upstream/components/first-time-setup.js +0 -105
  648. package/dist/src/foundation/pi-component-adapter/upstream/components/markdown-transform.d.ts +0 -2
  649. package/dist/src/foundation/pi-component-adapter/upstream/components/markdown-transform.js +0 -18
  650. package/dist/src/foundation/pi-component-adapter/upstream/components/mermaid.js +0 -77
  651. package/dist/src/foundation/pi-component-adapter/upstream/components/owned-editor.d.ts +0 -18
  652. package/dist/src/foundation/pi-component-adapter/upstream/components/owned-editor.js +0 -55
  653. package/dist/src/foundation/pi-component-adapter/upstream/components/scoped-models-selector.d.ts +0 -55
  654. package/dist/src/foundation/pi-component-adapter/upstream/components/scoped-models-selector.js +0 -342
  655. package/dist/src/foundation/pi-component-adapter/upstream/components/session-footer.d.ts +0 -10
  656. package/dist/src/foundation/pi-component-adapter/upstream/components/session-footer.js +0 -120
  657. package/dist/src/foundation/pi-component-adapter/upstream/components/session-selector-search.js +0 -159
  658. package/dist/src/foundation/pi-component-adapter/upstream/components/session-selector.d.ts +0 -95
  659. package/dist/src/foundation/pi-component-adapter/upstream/components/session-selector.js +0 -889
  660. package/dist/src/foundation/pi-component-adapter/upstream/components/skill-invocation-message.d.ts +0 -19
  661. package/dist/src/foundation/pi-component-adapter/upstream/components/skill-invocation-message.js +0 -44
  662. package/dist/src/foundation/pi-component-adapter/upstream/components/status-indicator.d.ts +0 -30
  663. package/dist/src/foundation/pi-component-adapter/upstream/components/status-indicator.js +0 -59
  664. package/dist/src/foundation/pi-component-adapter/upstream/components/tree-selector.d.ts +0 -98
  665. package/dist/src/foundation/pi-component-adapter/upstream/components/tree-selector.js +0 -1272
  666. package/dist/src/foundation/pi-component-adapter/upstream/components/trust-selector.d.ts +0 -33
  667. package/dist/src/foundation/pi-component-adapter/upstream/components/trust-selector.js +0 -76
  668. package/dist/src/foundation/pi-component-adapter/upstream/external-editor.js +0 -39
  669. package/dist/src/foundation/pi-component-adapter/upstream/model-search.d.ts +0 -15
  670. package/dist/src/foundation/pi-component-adapter/upstream/theme/theme-controller.d.ts +0 -25
  671. package/dist/src/foundation/pi-component-adapter/upstream/theme/theme-controller.js +0 -117
  672. package/dist/src/foundation/pi-component-adapter/upstream/theme/theme.d.ts +0 -61
  673. package/dist/src/foundation/pi-component-adapter/upstream/theme/theme.js +0 -326
  674. package/dist/src/foundation/pi-engine-adapter/adapter.d.ts +0 -164
  675. package/dist/src/foundation/pi-engine-adapter/adapter.js +0 -2367
  676. package/dist/src/foundation/pi-engine-adapter/conformance.d.ts +0 -37
  677. package/dist/src/foundation/pi-engine-adapter/conformance.js +0 -130
  678. package/dist/src/foundation/pi-engine-adapter/index.d.ts +0 -10
  679. package/dist/src/foundation/pi-engine-adapter/index.js +0 -10
  680. package/dist/src/foundation/pi-engine-adapter/model-auth-integration.d.ts +0 -30
  681. package/dist/src/foundation/pi-engine-adapter/model-auth-integration.js +0 -61
  682. package/dist/src/foundation/pi-engine-adapter/package-integration.d.ts +0 -13
  683. package/dist/src/foundation/pi-engine-adapter/package-integration.js +0 -112
  684. package/dist/src/foundation/pi-engine-adapter/pi-settings-metadata.json +0 -374
  685. package/dist/src/foundation/pi-engine-adapter/resource-extension-integration.d.ts +0 -31
  686. package/dist/src/foundation/pi-engine-adapter/resource-extension-integration.js +0 -80
  687. package/dist/src/foundation/pi-engine-adapter/runtime-integration.d.ts +0 -35
  688. package/dist/src/foundation/pi-engine-adapter/runtime-integration.js +0 -67
  689. package/dist/src/foundation/pi-engine-adapter/session-integration.d.ts +0 -43
  690. package/dist/src/foundation/pi-engine-adapter/session-integration.js +0 -97
  691. package/dist/src/foundation/pi-engine-adapter/settings-integration.d.ts +0 -55
  692. package/dist/src/foundation/pi-engine-adapter/settings-integration.js +0 -233
  693. package/dist/src/foundation/pi-engine-adapter/workflow-controllers.d.ts +0 -20
  694. package/dist/src/foundation/pi-engine-adapter/workflow-controllers.js +0 -48
  695. package/dist/src/foundation/pi-engine-adapter/workflows.d.ts +0 -173
  696. package/dist/src/foundation/pi-engine-adapter/workflows.js +0 -60
  697. package/dist/src/foundation/pi-owned-ui-integration/index.d.ts +0 -2
  698. package/dist/src/foundation/pi-owned-ui-integration/index.js +0 -2
  699. package/dist/src/foundation/pi-owned-ui-integration/route-host.d.ts +0 -29
  700. package/dist/src/foundation/pi-owned-ui-integration/session-shell.d.ts +0 -106
  701. package/dist/src/foundation/pi-owned-ui-integration/session-shell.js +0 -1518
  702. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.d.ts +0 -39
  703. package/dist/src/foundation/pi-tui-runtime-adapter/adapter.js +0 -493
  704. package/dist/src/foundation/pi-tui-runtime-adapter/conformance.d.ts +0 -18
  705. package/dist/src/foundation/pi-tui-runtime-adapter/conformance.js +0 -145
  706. package/dist/src/foundation/pi-tui-runtime-adapter/contracts.d.ts +0 -120
  707. package/dist/src/foundation/pi-tui-runtime-adapter/index.d.ts +0 -4
  708. package/dist/src/foundation/pi-tui-runtime-adapter/index.js +0 -4
  709. package/dist/src/foundation/pi-tui-runtime-adapter/presentation-adapter.d.ts +0 -4
  710. package/dist/src/foundation/pi-tui-runtime-adapter/presentation-adapter.js +0 -48
  711. package/dist/src/foundation/presentation-contracts/index.d.ts +0 -96
  712. package/dist/src/foundation/process-containment/index.d.ts +0 -5
  713. package/dist/src/foundation/process-containment/index.js +0 -5
  714. package/dist/src/foundation/process-containment/linux-process-inspector.d.ts +0 -6
  715. package/dist/src/foundation/process-containment/linux-process-inspector.js +0 -26
  716. package/dist/src/foundation/process-containment/native-guardian-containment.d.ts +0 -16
  717. package/dist/src/foundation/process-containment/native-guardian-containment.js +0 -139
  718. package/dist/src/foundation/process-containment/windows-process-inspector.d.ts +0 -17
  719. package/dist/src/foundation/process-containment/windows-process-inspector.js +0 -53
  720. package/dist/src/foundation/protocol/client.d.ts +0 -17
  721. package/dist/src/foundation/protocol/client.js +0 -129
  722. package/dist/src/foundation/protocol/index.d.ts +0 -2
  723. package/dist/src/foundation/protocol/index.js +0 -2
  724. package/dist/src/foundation/protocol/messages.d.ts +0 -89
  725. package/dist/src/foundation/protocol/messages.js +0 -99
  726. package/dist/src/foundation/release/bootstrap.d.ts +0 -29
  727. package/dist/src/foundation/release/bootstrap.js +0 -335
  728. package/dist/src/foundation/release/cohort-state.d.ts +0 -70
  729. package/dist/src/foundation/release/cohort-state.js +0 -202
  730. package/dist/src/foundation/release/index.d.ts +0 -10
  731. package/dist/src/foundation/release/index.js +0 -10
  732. package/dist/src/foundation/release/release-gc.d.ts +0 -5
  733. package/dist/src/foundation/release/release-gc.js +0 -16
  734. package/dist/src/foundation/release/release-store.d.ts +0 -43
  735. package/dist/src/foundation/release/release-store.js +0 -175
  736. package/dist/src/foundation/release/release.d.ts +0 -38
  737. package/dist/src/foundation/release/release.js +0 -204
  738. package/dist/src/foundation/release/update-transaction.d.ts +0 -31
  739. package/dist/src/foundation/release/update-transaction.js +0 -89
  740. package/dist/src/foundation/release/update.d.ts +0 -82
  741. package/dist/src/foundation/release/update.js +0 -527
  742. package/dist/src/foundation/storage/control-store.d.ts +0 -61
  743. package/dist/src/foundation/storage/control-store.js +0 -530
  744. package/dist/src/foundation/storage/index.d.ts +0 -1
  745. package/dist/src/foundation/storage/index.js +0 -1
  746. package/dist/src/foundation/structured-agent-runtime/backpressure.d.ts +0 -46
  747. package/dist/src/foundation/structured-agent-runtime/backpressure.js +0 -118
  748. package/dist/src/foundation/structured-agent-runtime/commands.d.ts +0 -52
  749. package/dist/src/foundation/structured-agent-runtime/commands.js +0 -164
  750. package/dist/src/foundation/structured-agent-runtime/handshake.d.ts +0 -41
  751. package/dist/src/foundation/structured-agent-runtime/handshake.js +0 -151
  752. package/dist/src/foundation/structured-agent-runtime/index.d.ts +0 -5
  753. package/dist/src/foundation/structured-agent-runtime/index.js +0 -5
  754. package/dist/src/foundation/structured-agent-runtime/reconnection.d.ts +0 -37
  755. package/dist/src/foundation/structured-agent-runtime/reconnection.js +0 -129
  756. package/dist/src/foundation/structured-agent-runtime/state.d.ts +0 -56
  757. package/dist/src/foundation/structured-agent-runtime/state.js +0 -118
  758. package/dist/src/foundation/supervision/index.d.ts +0 -3
  759. package/dist/src/foundation/supervision/index.js +0 -3
  760. package/dist/src/foundation/supervision/main.d.ts +0 -1
  761. package/dist/src/foundation/supervision/main.js +0 -41
  762. package/dist/src/foundation/supervision/paths.d.ts +0 -1
  763. package/dist/src/foundation/supervision/paths.js +0 -1
  764. package/dist/src/foundation/supervision/server.d.ts +0 -22
  765. package/dist/src/foundation/supervision/server.js +0 -451
  766. package/dist/src/foundation/ui-apps/contracts.d.ts +0 -42
  767. package/dist/src/foundation/ui-apps/host.d.ts +0 -42
  768. package/dist/src/foundation/ui-apps/host.js +0 -152
  769. package/dist/src/foundation/ui-apps/index.d.ts +0 -3
  770. package/dist/src/foundation/ui-apps/index.js +0 -3
  771. package/dist/src/foundation/ui-apps/registry.d.ts +0 -11
  772. package/dist/src/foundation/ui-apps/registry.js +0 -32
  773. package/dist/src/foundation/ui-components/dialog-panel.js +0 -47
  774. package/dist/src/foundation/ui-components/frame.d.ts +0 -21
  775. package/dist/src/foundation/ui-components/frame.js +0 -54
  776. package/dist/src/foundation/ui-components/index.d.ts +0 -18
  777. package/dist/src/foundation/ui-components/index.js +0 -18
  778. package/dist/src/foundation/ui-components/line-input.d.ts +0 -74
  779. package/dist/src/foundation/ui-components/line-input.js +0 -245
  780. package/dist/src/foundation/ui-components/list-view.d.ts +0 -66
  781. package/dist/src/foundation/ui-components/list-view.js +0 -76
  782. package/dist/src/foundation/ui-components/mouse.d.ts +0 -15
  783. package/dist/src/foundation/ui-components/mouse.js +0 -46
  784. package/dist/src/foundation/ui-components/scrollbar.d.ts +0 -62
  785. package/dist/src/foundation/ui-components/scrollbar.js +0 -102
  786. package/dist/src/foundation/ui-components/shortcuts.d.ts +0 -57
  787. package/dist/src/foundation/ui-components/shortcuts.js +0 -81
  788. package/dist/src/foundation/ui-components/spans.d.ts +0 -7
  789. package/dist/src/foundation/ui-components/spans.js +0 -59
  790. package/dist/src/foundation/ui-components/surface.d.ts +0 -20
  791. package/dist/src/foundation/ui-components/surface.js +0 -38
  792. package/dist/src/foundation/ui-components/text.d.ts +0 -24
  793. package/dist/src/foundation/ui-components/text.js +0 -123
  794. package/dist/src/foundation/workspace-contracts/index.d.ts +0 -2
  795. package/dist/src/foundation/workspace-contracts/index.js +0 -2
  796. package/dist/src/foundation/workspace-contracts/model.d.ts +0 -248
  797. package/dist/src/foundation/workspace-contracts/model.js +0 -2
  798. package/dist/src/foundation/workspace-contracts/validation.d.ts +0 -13
  799. package/dist/src/foundation/workspace-contracts/validation.js +0 -335
  800. package/dist/src/product-identity.d.ts +0 -37
  801. package/dist/src/product-identity.js +0 -150
  802. package/dist/src/product-identity.json +0 -99
  803. package/docs/manual-transparent-checkpoint.md +0 -53
  804. /package/dist/{src/foundation/agent-engine-contracts/domain.js → app/session-shell/paste-helper.d.ts} +0 -0
  805. /package/dist/{src/foundation/agent-engine-contracts/ports.js → app/session-shell/paste-text-worker.d.ts} +0 -0
  806. /package/dist/{src/foundation/lifecycle/commands.js → app/session-shell/paste-types.js} +0 -0
  807. /package/dist/{src/foundation/pi-owned-ui-integration/route-host.js → app/session-shell/response-copy-helper.d.ts} +0 -0
  808. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/capability-ports.js +0 -0
  809. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain-validation.d.ts +0 -0
  810. /package/dist/{src/foundation/pi-tui-runtime-adapter/contracts.js → contracts/agent-engine/domain.js} +0 -0
  811. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.d.ts +0 -0
  812. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.js +0 -0
  813. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/package-ports.js +0 -0
  814. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/ports.d.ts +0 -0
  815. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.d.ts +0 -0
  816. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.js +0 -0
  817. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.d.ts +0 -0
  818. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.js +0 -0
  819. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/extension-ui.js +0 -0
  820. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/model.js +0 -0
  821. /package/dist/{src/foundation/presentation-contracts → contracts/presentation}/index.js +0 -0
  822. /package/dist/{src/features → features}/launch/development-launch.d.ts +0 -0
  823. /package/dist/{src/features → features}/launch/initialize-profile.d.ts +0 -0
  824. /package/dist/{src/features → features}/launch/initialize-profile.js +0 -0
  825. /package/dist/{src/foundation → foundation}/lifecycle/commands.d.ts +0 -0
  826. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.d.ts +0 -0
  827. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.js +0 -0
  828. /package/dist/{src/foundation → foundation}/process-containment/artifact.d.ts +0 -0
  829. /package/dist/{src/foundation → foundation}/process-containment/artifact.js +0 -0
  830. /package/dist/{src/foundation → foundation}/process-containment/contracts.d.ts +0 -0
  831. /package/dist/{src/foundation → foundation}/process-containment/contracts.js +0 -0
  832. /package/dist/{src/foundation → foundation}/release/cohort-selection.d.ts +0 -0
  833. /package/dist/{src/foundation → foundation}/release/cohort-selection.js +0 -0
  834. /package/dist/{src/foundation → foundation}/release/concurrency.d.ts +0 -0
  835. /package/dist/{src/foundation → foundation}/release/concurrency.js +0 -0
  836. /package/dist/{src/foundation → foundation}/release/process-cleanup.d.ts +0 -0
  837. /package/dist/{src/foundation → foundation}/release/process-cleanup.js +0 -0
  838. /package/dist/{src/foundation → foundation}/release/stable-release.d.ts +0 -0
  839. /package/dist/{src/foundation → foundation}/release/stable-release.js +0 -0
  840. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-editor-autocomplete.d.ts +0 -0
  841. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.d.ts +0 -0
  842. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.js +0 -0
  843. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/countdown-timer.js +0 -0
  844. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/mermaid.d.ts +0 -0
  845. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector-search.d.ts +0 -0
  846. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/external-editor.d.ts +0 -0
  847. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/model-search.js +0 -0
  848. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.d.ts +0 -0
  849. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.js +0 -0
  850. /package/dist/{src/foundation/ui-apps → ui/apps}/contracts.js +0 -0
  851. /package/dist/{src/foundation/ui-components → ui/components}/dialog-panel.d.ts +0 -0
  852. /package/dist/{src/foundation/ui-components → ui/components}/label.d.ts +0 -0
  853. /package/dist/{src/foundation/ui-components → ui/components}/label.js +0 -0
  854. /package/dist/{src/foundation/ui-components → ui/components}/list-block.d.ts +0 -0
  855. /package/dist/{src/foundation/ui-components → ui/components}/list-block.js +0 -0
  856. /package/dist/{src/foundation/ui-components → ui/components}/pane.d.ts +0 -0
  857. /package/dist/{src/foundation/ui-components → ui/components}/pane.js +0 -0
  858. /package/dist/{src/foundation/ui-components → ui/components}/revision.d.ts +0 -0
  859. /package/dist/{src/foundation/ui-components → ui/components}/revision.js +0 -0
  860. /package/dist/{src/foundation/ui-components → ui/components}/status-line.d.ts +0 -0
  861. /package/dist/{src/foundation/ui-components → ui/components}/status-line.js +0 -0
  862. /package/dist/{src/foundation/ui-components → ui/components}/stepper.d.ts +0 -0
  863. /package/dist/{src/foundation/ui-components → ui/components}/stepper.js +0 -0
  864. /package/dist/{src/foundation/ui-components → ui/components}/theme.d.ts +0 -0
  865. /package/dist/{src/foundation/ui-components → ui/components}/theme.js +0 -0
  866. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.d.ts +0 -0
  867. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.js +0 -0
  868. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.d.ts +0 -0
  869. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.js +0 -0
@@ -0,0 +1,2144 @@
1
+ /**
2
+ * Provenance: @earendil-works/pi-tui 0.85.1 (MIT), commit d981de1229ef899957bbe968bc8dcda02a21f477,
3
+ * packages/tui/src/components/editor.ts.
4
+ * Modifications: Owned editor core or minimal editor-local helper subset; public imports, strict
5
+ * types, typed persistent-history hooks, and semantic border state with the user-approved numeric-only
6
+ * history label. Public terminal runtime/exports remain shared and unchanged. See
7
+ * docs/architecture/history-editor-provenance.md.
8
+ * Deviations: compact-history-counter-label, persistent-history-owned-editor-boundary.
9
+ */
10
+ import { getKeybindings, matchesKey, CURSOR_MARKER, sliceByColumn, truncateToWidth, visibleWidth, SelectList } from "@earendil-works/pi-tui";
11
+ import { decodePrintableKey } from "./printable-key.js";
12
+ import { KillRing } from "./kill-ring.js";
13
+ import { UndoStack } from "./undo-stack.js";
14
+ import { cjkBreakRegex, getGraphemeSegmenter, getWordSegmenter, isWhitespaceChar } from "./text-helpers.js";
15
+ import { findWordBackward, findWordForward } from "./word-navigation.js";
16
+ const graphemeSegmenter = getGraphemeSegmenter();
17
+ const wordSegmenter = getWordSegmenter();
18
+ /** Regex matching paste markers like `[paste #1 +123 lines]` or `[paste #2 1234 chars]`. */
19
+ const PASTE_MARKER_REGEX = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
20
+ /** Non-global version for single-segment testing. */
21
+ const PASTE_MARKER_SINGLE = /^\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]$/;
22
+ /** Check if a segment is a paste marker (i.e. was merged by segmentWithMarkers). */
23
+ function isPasteMarker(segment) {
24
+ return segment.length >= 10 && PASTE_MARKER_SINGLE.test(segment);
25
+ }
26
+ /**
27
+ * A segmenter that wraps Intl.Segmenter and merges graphemes that fall
28
+ * within paste markers into single atomic segments. This makes cursor
29
+ * movement, deletion, word-wrap, etc. treat paste markers as single units.
30
+ *
31
+ * Only markers whose numeric ID exists in `validIds` are merged.
32
+ */
33
+ function segmentWithMarkers(text, baseSegmenter, validIds) {
34
+ // Fast path: no paste markers in the text or no valid IDs.
35
+ if (validIds.size === 0 || !text.includes("[paste #")) {
36
+ return baseSegmenter.segment(text);
37
+ }
38
+ // Find all marker spans with valid IDs.
39
+ const markers = [];
40
+ for (const m of text.matchAll(PASTE_MARKER_REGEX)) {
41
+ const id = Number.parseInt(m[1], 10);
42
+ if (!validIds.has(id))
43
+ continue;
44
+ markers.push({ start: m.index, end: m.index + m[0].length });
45
+ }
46
+ if (markers.length === 0) {
47
+ return baseSegmenter.segment(text);
48
+ }
49
+ // Build merged segment list.
50
+ const baseSegments = baseSegmenter.segment(text);
51
+ const result = [];
52
+ let markerIdx = 0;
53
+ for (const seg of baseSegments) {
54
+ // Skip past markers that are entirely before this segment.
55
+ while (markerIdx < markers.length && markers[markerIdx].end <= seg.index) {
56
+ markerIdx++;
57
+ }
58
+ const marker = markerIdx < markers.length ? markers[markerIdx] : null;
59
+ if (marker && seg.index >= marker.start && seg.index < marker.end) {
60
+ // This segment falls inside a marker.
61
+ // If this is the first segment of the marker, emit a merged segment.
62
+ if (seg.index === marker.start) {
63
+ const markerText = text.slice(marker.start, marker.end);
64
+ result.push({
65
+ segment: markerText,
66
+ index: marker.start,
67
+ input: text,
68
+ });
69
+ }
70
+ // Otherwise skip (already merged into the first segment).
71
+ }
72
+ else {
73
+ result.push(seg);
74
+ }
75
+ }
76
+ return result;
77
+ }
78
+ /**
79
+ * Split a line into word-wrapped chunks.
80
+ * Wraps at word boundaries when possible, falling back to character-level
81
+ * wrapping for words longer than the available width.
82
+ *
83
+ * @param line - The text line to wrap
84
+ * @param maxWidth - Maximum visible width per chunk
85
+ * @param preSegmented - Optional pre-segmented graphemes (e.g. with paste-marker awareness).
86
+ * When omitted the default Intl.Segmenter is used.
87
+ * @returns Array of chunks with text and position information
88
+ */
89
+ export function wordWrapLine(line, maxWidth, preSegmented) {
90
+ if (!line || maxWidth <= 0) {
91
+ return [{ text: "", startIndex: 0, endIndex: 0 }];
92
+ }
93
+ const lineWidth = visibleWidth(line);
94
+ if (lineWidth <= maxWidth) {
95
+ return [{ text: line, startIndex: 0, endIndex: line.length }];
96
+ }
97
+ const chunks = [];
98
+ const segments = preSegmented ?? [...graphemeSegmenter.segment(line)];
99
+ let currentWidth = 0;
100
+ let chunkStart = 0;
101
+ // Wrap opportunity: the position after the last whitespace before a non-whitespace
102
+ // grapheme, i.e. where a line break is allowed.
103
+ let wrapOppIndex = -1;
104
+ let wrapOppWidth = 0;
105
+ for (let i = 0; i < segments.length; i++) {
106
+ const seg = segments[i];
107
+ const grapheme = seg.segment;
108
+ const gWidth = visibleWidth(grapheme);
109
+ const charIndex = seg.index;
110
+ const isWs = !isPasteMarker(grapheme) && isWhitespaceChar(grapheme);
111
+ // Overflow check before advancing.
112
+ if (currentWidth + gWidth > maxWidth) {
113
+ if (wrapOppIndex >= 0 && currentWidth - wrapOppWidth + gWidth <= maxWidth) {
114
+ // Backtrack to last wrap opportunity (the remaining content
115
+ // plus the current grapheme still fits within maxWidth).
116
+ chunks.push({ text: line.slice(chunkStart, wrapOppIndex), startIndex: chunkStart, endIndex: wrapOppIndex });
117
+ chunkStart = wrapOppIndex;
118
+ currentWidth -= wrapOppWidth;
119
+ }
120
+ else if (chunkStart < charIndex) {
121
+ // No viable wrap opportunity: force-break at current position.
122
+ // This also handles the case where backtracking to a word
123
+ // boundary wouldn't help because the remaining content plus
124
+ // the current grapheme (e.g. a wide character) still exceeds
125
+ // maxWidth.
126
+ chunks.push({ text: line.slice(chunkStart, charIndex), startIndex: chunkStart, endIndex: charIndex });
127
+ chunkStart = charIndex;
128
+ currentWidth = 0;
129
+ }
130
+ wrapOppIndex = -1;
131
+ }
132
+ if (gWidth > maxWidth) {
133
+ // Single atomic segment wider than maxWidth (e.g. paste marker
134
+ // in a narrow terminal). Re-wrap it at grapheme granularity.
135
+ // The segment remains logically atomic for cursor
136
+ // movement / editing — the split is purely visual for word-wrap layout.
137
+ const subChunks = wordWrapLine(grapheme, maxWidth);
138
+ for (let j = 0; j < subChunks.length - 1; j++) {
139
+ const sc = subChunks[j];
140
+ chunks.push({ text: sc.text, startIndex: charIndex + sc.startIndex, endIndex: charIndex + sc.endIndex });
141
+ }
142
+ const last = subChunks[subChunks.length - 1];
143
+ chunkStart = charIndex + last.startIndex;
144
+ currentWidth = visibleWidth(last.text);
145
+ wrapOppIndex = -1;
146
+ continue;
147
+ }
148
+ // Advance.
149
+ currentWidth += gWidth;
150
+ // Record wrap opportunity: whitespace followed by non-whitespace
151
+ // (multiple spaces join; the break point is after the last space),
152
+ // or at a boundary where either side is CJK (CJK allows breaking
153
+ // between any adjacent characters).
154
+ const next = segments[i + 1];
155
+ if (isWs && next && (isPasteMarker(next.segment) || !isWhitespaceChar(next.segment))) {
156
+ wrapOppIndex = next.index;
157
+ wrapOppWidth = currentWidth;
158
+ }
159
+ else if (!isWs && next && !isWhitespaceChar(next.segment)) {
160
+ const isCjk = !isPasteMarker(grapheme) && cjkBreakRegex.test(grapheme);
161
+ const nextIsCjk = !isPasteMarker(next.segment) && cjkBreakRegex.test(next.segment);
162
+ if (isCjk || nextIsCjk) {
163
+ wrapOppIndex = next.index;
164
+ wrapOppWidth = currentWidth;
165
+ }
166
+ }
167
+ }
168
+ // Push final chunk.
169
+ chunks.push({ text: line.slice(chunkStart), startIndex: chunkStart, endIndex: line.length });
170
+ return chunks;
171
+ }
172
+ const SLASH_COMMAND_SELECT_LIST_LAYOUT = {
173
+ minPrimaryColumnWidth: 12,
174
+ maxPrimaryColumnWidth: 32,
175
+ };
176
+ const ATTACHMENT_AUTOCOMPLETE_DEBOUNCE_MS = 20;
177
+ const DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS = ["@", "#"];
178
+ function escapeCharacterClass(value) {
179
+ return value.replace(/[\\^$.*+?()[\]{}|-]/g, "\\$&");
180
+ }
181
+ function buildTriggerPattern(triggerCharacters) {
182
+ return new RegExp(`(?:^|[\\s])[${triggerCharacters.map(escapeCharacterClass).join("")}][^\\s]*$`);
183
+ }
184
+ function buildDebouncePattern(triggerCharacters) {
185
+ const escapedWithoutAt = triggerCharacters.filter((character) => character !== "@").map(escapeCharacterClass);
186
+ return new RegExp(`(?:^|[ \\t])(?:@(?:"[^"]*|[^\\s]*)|[${escapedWithoutAt.join("")}][^\\s]*)$`);
187
+ }
188
+ function createScrollBorder(direction, hiddenLineCount, width) {
189
+ const availableWidth = Math.max(0, width);
190
+ const label = ` ${direction} ${hiddenLineCount} more `;
191
+ const labelWidth = visibleWidth(label);
192
+ if (labelWidth + 2 <= availableWidth) {
193
+ const leftWidth = Math.floor((availableWidth - labelWidth) / 2);
194
+ return "─".repeat(leftWidth) + label + "─".repeat(availableWidth - leftWidth - labelWidth);
195
+ }
196
+ const indicator = `─── ${direction} ${hiddenLineCount} more `;
197
+ const remaining = availableWidth - visibleWidth(indicator);
198
+ if (remaining >= 0)
199
+ return indicator + "─".repeat(remaining);
200
+ const ellipsis = "...".slice(0, availableWidth);
201
+ const indicatorWidth = availableWidth - visibleWidth(ellipsis);
202
+ return sliceByColumn(indicator, 0, indicatorWidth, true) + ellipsis;
203
+ }
204
+ export class HistoryEditorCore {
205
+ segmentTransform;
206
+ interaction = {
207
+ snapshot: () => ({ ...this.state, lines: [...this.state.lines] }),
208
+ setCursor: (line, col) => {
209
+ this.state.cursorLine = Math.max(0, Math.min(this.state.lines.length - 1, line));
210
+ this.state.cursorCol = Math.max(0, Math.min(this.state.lines[this.state.cursorLine].length, col));
211
+ },
212
+ replaceLines: lines => { this.state.lines = [...lines]; },
213
+ updateUndoStates: update => {
214
+ this.undoStack.updateSnapshots(snapshot => update(snapshot.state));
215
+ if (this.historyDraft !== null) {
216
+ const draft = structuredClone(this.historyDraft);
217
+ update(draft);
218
+ this.historyDraft = draft;
219
+ }
220
+ },
221
+ scrollOffset: () => this.scrollOffset,
222
+ visualLines: width => this.buildVisualLineMap(width),
223
+ setSegmentTransform: transform => { this.segmentTransform = transform; },
224
+ };
225
+ state = {
226
+ lines: [""],
227
+ cursorLine: 0,
228
+ cursorCol: 0,
229
+ };
230
+ /** Focusable interface - set by TUI when focus changes */
231
+ focused = false;
232
+ tui;
233
+ theme;
234
+ paddingX = 0;
235
+ // Store last render geometry for cursor navigation and mouse hit-testing.
236
+ lastWidth = 80;
237
+ renderedVisibleLineCount = 1;
238
+ renderedAutocompleteHeight = 0;
239
+ // Vertical scrolling support
240
+ scrollOffset = 0;
241
+ // Border color (can be changed dynamically)
242
+ borderColor;
243
+ // Autocomplete support
244
+ autocompleteProvider;
245
+ autocompleteTriggerCharacters = [...DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS];
246
+ autocompleteTriggerPattern = buildTriggerPattern(this.autocompleteTriggerCharacters);
247
+ autocompleteDebouncePattern = buildDebouncePattern(this.autocompleteTriggerCharacters);
248
+ autocompleteList;
249
+ autocompleteState = null;
250
+ autocompletePrefix = "";
251
+ autocompleteMaxVisible = 5;
252
+ autocompleteAbort;
253
+ autocompleteDebounceTimer;
254
+ autocompleteRequestTask = Promise.resolve();
255
+ autocompleteStartToken = 0;
256
+ autocompleteRequestId = 0;
257
+ // Paste tracking for large pastes
258
+ pastes = new Map();
259
+ pasteCounter = 0;
260
+ // Bracketed paste mode buffering
261
+ pasteBuffer = "";
262
+ isInPaste = false;
263
+ // Prompt history for up/down navigation
264
+ history = [];
265
+ historyIndex = -1; // -1 = not browsing, 0 = most recent, 1 = older, etc.
266
+ historyDraft = null;
267
+ recall = {
268
+ replace: entries => this.replaceHistoryEntries(entries),
269
+ position: () => this.getHistoryPosition(),
270
+ observe: listener => {
271
+ this.onHistoryChange = listener;
272
+ return () => { if (this.onHistoryChange === listener)
273
+ delete this.onHistoryChange; };
274
+ },
275
+ reset: () => this.resetHistoryBrowsing(),
276
+ };
277
+ persistentHistory = false;
278
+ styleHistoryLabel;
279
+ historyPasteDraft = null;
280
+ pendingHistory;
281
+ onHistoryChange;
282
+ configurePersistentHistory(enabled) {
283
+ this.persistentHistory = enabled;
284
+ this.exitHistoryBrowsing();
285
+ }
286
+ replaceHistoryEntries(entries) {
287
+ const snapshot = [...new Set(entries.map(text => text.trim()).filter(Boolean))].slice(0, 100);
288
+ if (this.historyIndex >= 0)
289
+ this.pendingHistory = snapshot;
290
+ else
291
+ this.history = snapshot;
292
+ }
293
+ getHistoryPosition() {
294
+ return { index: this.historyIndex, total: this.history.length };
295
+ }
296
+ resetHistoryBrowsing() {
297
+ this.exitHistoryBrowsing();
298
+ }
299
+ applyPendingHistory() {
300
+ if (this.pendingHistory === undefined)
301
+ return;
302
+ this.history = this.pendingHistory;
303
+ this.pendingHistory = undefined;
304
+ }
305
+ notifyHistory() {
306
+ this.onHistoryChange?.(this.getHistoryPosition());
307
+ }
308
+ // Kill ring for Emacs-style kill/yank operations
309
+ killRing = new KillRing();
310
+ lastAction = null;
311
+ // Character jump mode
312
+ jumpMode = null;
313
+ // Preferred visual column for vertical cursor movement (sticky column)
314
+ preferredVisualCol = null;
315
+ // When the cursor is snapped to the start of an atomic segment, e.g. a
316
+ // paste marker, cursorCol no longer reflects where the cursor would have
317
+ // landed. This field stores the pre-snap cursorCol so that the next
318
+ // vertical move can resolve it to a visual column on whatever VL it belongs
319
+ // to.
320
+ snappedFromCursorCol = null;
321
+ // Undo support
322
+ undoStack = new UndoStack();
323
+ onSubmit;
324
+ onChange;
325
+ disableSubmit = false;
326
+ constructor(tui, theme, options = {}) {
327
+ this.tui = tui;
328
+ this.persistentHistory = options.persistentHistory ?? false;
329
+ this.styleHistoryLabel = options.styleHistoryLabel ?? (text => text);
330
+ this.theme = theme;
331
+ this.borderColor = theme.borderColor;
332
+ const paddingX = options.paddingX ?? 0;
333
+ this.paddingX = Number.isFinite(paddingX) ? Math.max(0, Math.floor(paddingX)) : 0;
334
+ const maxVisible = options.autocompleteMaxVisible ?? 5;
335
+ this.autocompleteMaxVisible = Number.isFinite(maxVisible) ? Math.max(3, Math.min(20, Math.floor(maxVisible))) : 5;
336
+ }
337
+ /** Set of currently valid paste IDs, for marker-aware segmentation. */
338
+ validPasteIds() {
339
+ return new Set(this.pastes.keys());
340
+ }
341
+ /** Segment text with paste-marker awareness, only merging markers with valid IDs. */
342
+ segment(text, mode) {
343
+ const segments = segmentWithMarkers(text, mode === "word" ? wordSegmenter : graphemeSegmenter, this.validPasteIds());
344
+ return this.segmentTransform?.(text, mode, segments) ?? segments;
345
+ }
346
+ getPaddingX() {
347
+ return this.paddingX;
348
+ }
349
+ setPaddingX(padding) {
350
+ const newPadding = Number.isFinite(padding) ? Math.max(0, Math.floor(padding)) : 0;
351
+ if (this.paddingX !== newPadding) {
352
+ this.paddingX = newPadding;
353
+ this.tui.requestRender();
354
+ }
355
+ }
356
+ getAutocompleteMaxVisible() {
357
+ return this.autocompleteMaxVisible;
358
+ }
359
+ setAutocompleteMaxVisible(maxVisible) {
360
+ const newMaxVisible = Number.isFinite(maxVisible) ? Math.max(3, Math.min(20, Math.floor(maxVisible))) : 5;
361
+ if (this.autocompleteMaxVisible !== newMaxVisible) {
362
+ this.autocompleteMaxVisible = newMaxVisible;
363
+ this.tui.requestRender();
364
+ }
365
+ }
366
+ setAutocompleteProvider(provider) {
367
+ this.cancelAutocomplete();
368
+ this.autocompleteProvider = provider;
369
+ this.setAutocompleteTriggerCharacters(provider.triggerCharacters ?? []);
370
+ }
371
+ /**
372
+ * Add a prompt to history for up/down arrow navigation.
373
+ * Called after successful submission.
374
+ */
375
+ addToHistory(text) {
376
+ const trimmed = text.trim();
377
+ if (!trimmed)
378
+ return;
379
+ if (this.persistentHistory) {
380
+ this.replaceHistoryEntries([trimmed, ...(this.pendingHistory ?? this.history)]);
381
+ return;
382
+ }
383
+ // Don't add consecutive duplicates
384
+ if (this.history.length > 0 && this.history[0] === trimmed)
385
+ return;
386
+ this.history.unshift(trimmed);
387
+ // Limit history size
388
+ if (this.history.length > 100) {
389
+ this.history.pop();
390
+ }
391
+ }
392
+ isEditorEmpty() {
393
+ return this.state.lines.length === 1 && this.state.lines[0] === "";
394
+ }
395
+ isOnFirstVisualLine() {
396
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
397
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
398
+ return currentVisualLine === 0;
399
+ }
400
+ isOnLastVisualLine() {
401
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
402
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
403
+ return currentVisualLine === visualLines.length - 1;
404
+ }
405
+ navigateHistory(direction) {
406
+ this.lastAction = null;
407
+ if (this.history.length === 0)
408
+ return;
409
+ const newIndex = this.historyIndex - direction; // Up(-1) increases index, Down(1) decreases
410
+ if (newIndex < -1 || newIndex >= this.history.length)
411
+ return;
412
+ // Capture state when first entering history browsing mode
413
+ if (this.historyIndex === -1 && newIndex >= 0) {
414
+ this.pushUndoSnapshot();
415
+ this.historyDraft = structuredClone(this.state);
416
+ if (this.persistentHistory)
417
+ this.historyPasteDraft = { pastes: this.pastes, counter: this.pasteCounter };
418
+ }
419
+ this.historyIndex = newIndex;
420
+ if (this.historyIndex === -1) {
421
+ const draft = this.historyDraft;
422
+ this.historyDraft = null;
423
+ if (this.historyPasteDraft !== null) {
424
+ this.pastes = this.historyPasteDraft.pastes;
425
+ this.pasteCounter = this.historyPasteDraft.counter;
426
+ this.historyPasteDraft = null;
427
+ }
428
+ if (draft) {
429
+ this.state = draft;
430
+ this.preferredVisualCol = null;
431
+ this.snappedFromCursorCol = null;
432
+ this.scrollOffset = 0;
433
+ if (this.onChange)
434
+ this.onChange(this.getText());
435
+ }
436
+ else {
437
+ this.setTextInternal("");
438
+ }
439
+ }
440
+ else {
441
+ if (this.persistentHistory) {
442
+ this.pastes = new Map();
443
+ this.pasteCounter = 0;
444
+ }
445
+ const placement = this.persistentHistory
446
+ ? direction === -1 ? "end" : "start"
447
+ : direction === -1 ? "start" : "end";
448
+ this.setTextInternal(this.history[this.historyIndex] || "", placement);
449
+ }
450
+ if (this.historyIndex === -1)
451
+ this.applyPendingHistory();
452
+ this.notifyHistory();
453
+ }
454
+ exitHistoryBrowsing() {
455
+ const wasBrowsing = this.historyIndex >= 0;
456
+ this.historyIndex = -1;
457
+ this.historyDraft = null;
458
+ this.historyPasteDraft = null;
459
+ this.applyPendingHistory();
460
+ if (wasBrowsing)
461
+ this.notifyHistory();
462
+ }
463
+ /** Internal setText that doesn't reset history state - used by navigateHistory */
464
+ setTextInternal(text, cursorPlacement = "end") {
465
+ const lines = text.split("\n");
466
+ this.state.lines = lines.length === 0 ? [""] : lines;
467
+ this.state.cursorLine = cursorPlacement === "start" ? 0 : this.state.lines.length - 1;
468
+ this.setCursorCol(cursorPlacement === "start" ? 0 : this.state.lines[this.state.cursorLine]?.length || 0);
469
+ // Reset scroll - render() will adjust to show cursor
470
+ this.scrollOffset = 0;
471
+ if (this.onChange) {
472
+ this.onChange(this.getText());
473
+ }
474
+ }
475
+ invalidate() {
476
+ // No cached state to invalidate currently
477
+ }
478
+ renderTopBorder(width, hiddenLineCount) {
479
+ if (this.persistentHistory && this.historyIndex >= 0) {
480
+ const overflow = hiddenLineCount > 0 ? ` · ↑ ${hiddenLineCount} more` : "";
481
+ const label = `─── ${this.history.length - this.historyIndex}/${this.history.length}${overflow} `;
482
+ const shown = truncateToWidth(label, width);
483
+ const remaining = Math.max(0, width - visibleWidth(shown));
484
+ return this.borderColor(shown.slice(0, 4)) + this.styleHistoryLabel(shown.slice(4)) + this.borderColor("─".repeat(remaining));
485
+ }
486
+ const border = hiddenLineCount > 0 ? createScrollBorder("↑", hiddenLineCount, width) : "─".repeat(width);
487
+ return this.borderColor(border);
488
+ }
489
+ renderBottomBorder(width, hiddenLineCount) {
490
+ const border = hiddenLineCount > 0 ? createScrollBorder("↓", hiddenLineCount, width) : "─".repeat(width);
491
+ return this.borderColor(border);
492
+ }
493
+ render(width) {
494
+ const maxPadding = Math.max(0, Math.floor((width - 1) / 2));
495
+ const paddingX = Math.min(this.paddingX, maxPadding);
496
+ const contentWidth = Math.max(1, width - paddingX * 2);
497
+ // Layout width: with padding the cursor can overflow into it,
498
+ // without padding we reserve 1 column for the cursor.
499
+ const layoutWidth = Math.max(1, contentWidth - (paddingX ? 0 : 1));
500
+ // Store for cursor navigation (must match wrapping width)
501
+ this.lastWidth = layoutWidth;
502
+ // Layout the text
503
+ const layoutLines = this.layoutText(layoutWidth);
504
+ // Calculate max visible lines: 30% of terminal height, minimum 5 lines
505
+ const terminalRows = this.tui.terminal.rows;
506
+ const maxVisibleLines = Math.max(5, Math.floor(terminalRows * 0.3));
507
+ // Find the cursor line index in layoutLines
508
+ let cursorLineIndex = layoutLines.findIndex((line) => line.hasCursor);
509
+ if (cursorLineIndex === -1)
510
+ cursorLineIndex = 0;
511
+ // Adjust scroll offset to keep cursor visible
512
+ if (cursorLineIndex < this.scrollOffset) {
513
+ this.scrollOffset = cursorLineIndex;
514
+ }
515
+ else if (cursorLineIndex >= this.scrollOffset + maxVisibleLines) {
516
+ this.scrollOffset = cursorLineIndex - maxVisibleLines + 1;
517
+ }
518
+ // Clamp scroll offset to valid range
519
+ const maxScrollOffset = Math.max(0, layoutLines.length - maxVisibleLines);
520
+ this.scrollOffset = Math.max(0, Math.min(this.scrollOffset, maxScrollOffset));
521
+ // Get visible lines slice
522
+ const visibleLines = layoutLines.slice(this.scrollOffset, this.scrollOffset + maxVisibleLines);
523
+ this.renderedVisibleLineCount = visibleLines.length;
524
+ const result = [];
525
+ const leftPadding = " ".repeat(paddingX);
526
+ const rightPadding = leftPadding;
527
+ // Render top border (with scroll indicator if scrolled down)
528
+ result.push(this.renderTopBorder(width, this.scrollOffset));
529
+ // Render each visible layout line
530
+ // Emit hardware cursor marker when focused so TUI can position the
531
+ // hardware cursor for IME candidate-window placement even while
532
+ // autocomplete (e.g. slash-command menu) is visible.
533
+ const emitCursorMarker = this.focused;
534
+ for (const layoutLine of visibleLines) {
535
+ let displayText = layoutLine.text;
536
+ let lineVisibleWidth = visibleWidth(layoutLine.text);
537
+ let cursorInPadding = false;
538
+ // Add cursor if this line has it
539
+ if (layoutLine.hasCursor && layoutLine.cursorPos !== undefined) {
540
+ const before = displayText.slice(0, layoutLine.cursorPos);
541
+ const after = displayText.slice(layoutLine.cursorPos);
542
+ // Hardware cursor marker (zero-width, emitted before fake cursor for IME positioning)
543
+ const marker = emitCursorMarker ? CURSOR_MARKER : "";
544
+ if (after.length > 0) {
545
+ // Cursor is on a character (grapheme) - replace it with highlighted version
546
+ // Get the first grapheme from 'after'
547
+ const afterGraphemes = [...this.segment(after, "grapheme")];
548
+ const firstGrapheme = afterGraphemes[0]?.segment || "";
549
+ const restAfter = after.slice(firstGrapheme.length);
550
+ const cursor = `\x1b[7m${firstGrapheme}\x1b[0m`;
551
+ displayText = before + marker + cursor + restAfter;
552
+ // lineVisibleWidth stays the same - we're replacing, not adding
553
+ }
554
+ else {
555
+ // Cursor is at the end - add highlighted space
556
+ const cursor = "\x1b[7m \x1b[0m";
557
+ displayText = before + marker + cursor;
558
+ lineVisibleWidth = lineVisibleWidth + 1;
559
+ // If cursor overflows content width into the padding, flag it
560
+ if (lineVisibleWidth > contentWidth && paddingX > 0) {
561
+ cursorInPadding = true;
562
+ }
563
+ }
564
+ }
565
+ // Calculate padding based on actual visible width
566
+ const padding = " ".repeat(Math.max(0, contentWidth - lineVisibleWidth));
567
+ const lineRightPadding = cursorInPadding ? rightPadding.slice(1) : rightPadding;
568
+ // Render the line (no side borders, just horizontal lines above and below)
569
+ result.push(`${leftPadding}${displayText}${padding}${lineRightPadding}`);
570
+ }
571
+ // Render bottom border (with scroll indicator if more content below)
572
+ const linesBelow = layoutLines.length - (this.scrollOffset + visibleLines.length);
573
+ result.push(this.renderBottomBorder(width, linesBelow));
574
+ // Add autocomplete list if active
575
+ this.renderedAutocompleteHeight = 0;
576
+ if (this.autocompleteState && this.autocompleteList) {
577
+ const autocompleteResult = this.autocompleteList.render(contentWidth);
578
+ this.renderedAutocompleteHeight = autocompleteResult.length;
579
+ for (const line of autocompleteResult) {
580
+ const lineWidth = visibleWidth(line);
581
+ const linePadding = " ".repeat(Math.max(0, contentWidth - lineWidth));
582
+ result.push(`${leftPadding}${line}${linePadding}${rightPadding}`);
583
+ }
584
+ }
585
+ return result;
586
+ }
587
+ handleMouse(event) {
588
+ const autocompleteStartRow = this.renderedVisibleLineCount + 2;
589
+ if (this.autocompleteState &&
590
+ this.autocompleteList &&
591
+ event.y >= autocompleteStartRow &&
592
+ event.y < autocompleteStartRow + this.renderedAutocompleteHeight) {
593
+ const maxPadding = Math.max(0, Math.floor((event.width - 1) / 2));
594
+ const paddingX = Math.min(this.paddingX, maxPadding);
595
+ const contentWidth = Math.max(1, event.width - paddingX * 2);
596
+ const result = this.autocompleteList.handleMouse?.({
597
+ ...event,
598
+ x: event.x - paddingX,
599
+ y: event.y - autocompleteStartRow,
600
+ width: contentWidth,
601
+ height: this.renderedAutocompleteHeight,
602
+ });
603
+ return result ? { ...result, focus: true } : undefined;
604
+ }
605
+ // Leave press/drag/release unhandled so the renderer's screen-level text
606
+ // selection can run over the editor rows (drag to select, release to copy).
607
+ // The renderer synthesizes a click when press and release land on the same
608
+ // cell without movement, which is the gesture that positions the cursor.
609
+ if (event.type !== "click" || event.button !== "left")
610
+ return undefined;
611
+ if (event.y <= 0 || event.y > this.renderedVisibleLineCount)
612
+ return { handled: true, focus: true };
613
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
614
+ const visualLineIndex = this.scrollOffset + event.y - 1;
615
+ const visualLine = visualLines[visualLineIndex];
616
+ if (!visualLine)
617
+ return { handled: true, focus: true };
618
+ const logicalLine = this.state.lines[visualLine.logicalLine] ?? "";
619
+ const chunkEnd = visualLine.startCol + visualLine.length;
620
+ const chunk = logicalLine.slice(visualLine.startCol, chunkEnd);
621
+ const maxPadding = Math.max(0, Math.floor((event.width - 1) / 2));
622
+ const paddingX = Math.min(this.paddingX, maxPadding);
623
+ const targetColumn = Math.max(0, event.x - paddingX);
624
+ let visibleColumn = 0;
625
+ let targetIndex = chunk.length;
626
+ let lastGraphemeIndex = 0;
627
+ for (const grapheme of this.segment(chunk, "grapheme")) {
628
+ const nextColumn = visibleColumn + visibleWidth(grapheme.segment);
629
+ lastGraphemeIndex = grapheme.index;
630
+ if (targetColumn < nextColumn) {
631
+ targetIndex = grapheme.index;
632
+ break;
633
+ }
634
+ visibleColumn = nextColumn;
635
+ }
636
+ const isLastSegment = visualLineIndex === visualLines.length - 1 ||
637
+ visualLines[visualLineIndex + 1]?.logicalLine !== visualLine.logicalLine;
638
+ if (!isLastSegment && targetIndex === chunk.length && chunk.length > 0)
639
+ targetIndex = lastGraphemeIndex;
640
+ this.state.cursorLine = visualLine.logicalLine;
641
+ this.setCursorCol(visualLine.startCol + targetIndex);
642
+ this.lastAction = null;
643
+ this.exitHistoryBrowsing();
644
+ if (this.autocompleteState)
645
+ this.updateAutocomplete();
646
+ return { handled: true, focus: true };
647
+ }
648
+ handleInput(data) {
649
+ const kb = getKeybindings();
650
+ // Handle character jump mode (awaiting next character to jump to)
651
+ if (this.jumpMode !== null) {
652
+ // Cancel if the hotkey is pressed again
653
+ if (kb.matches(data, "tui.editor.jumpForward") || kb.matches(data, "tui.editor.jumpBackward")) {
654
+ this.jumpMode = null;
655
+ return;
656
+ }
657
+ const printable = decodePrintableKey(data) ?? (data.charCodeAt(0) >= 32 ? data : undefined);
658
+ if (printable !== undefined) {
659
+ // Printable character - perform the jump
660
+ const direction = this.jumpMode;
661
+ this.jumpMode = null;
662
+ this.jumpToChar(printable, direction);
663
+ return;
664
+ }
665
+ // Control character - cancel and fall through to normal handling
666
+ this.jumpMode = null;
667
+ }
668
+ // Handle bracketed paste mode
669
+ if (data.includes("\x1b[200~")) {
670
+ this.isInPaste = true;
671
+ this.pasteBuffer = "";
672
+ data = data.replace("\x1b[200~", "");
673
+ }
674
+ if (this.isInPaste) {
675
+ this.pasteBuffer += data;
676
+ const endIndex = this.pasteBuffer.indexOf("\x1b[201~");
677
+ if (endIndex !== -1) {
678
+ const pasteContent = this.pasteBuffer.substring(0, endIndex);
679
+ if (pasteContent.length > 0) {
680
+ this.handlePaste(pasteContent);
681
+ }
682
+ this.isInPaste = false;
683
+ const remaining = this.pasteBuffer.substring(endIndex + 6);
684
+ this.pasteBuffer = "";
685
+ if (remaining.length > 0) {
686
+ this.handleInput(remaining);
687
+ }
688
+ return;
689
+ }
690
+ return;
691
+ }
692
+ // Ctrl+C - let parent handle (exit/clear)
693
+ if (kb.matches(data, "tui.input.copy")) {
694
+ return;
695
+ }
696
+ // Undo
697
+ if (kb.matches(data, "tui.editor.undo")) {
698
+ this.undo();
699
+ return;
700
+ }
701
+ // Handle autocomplete mode
702
+ if (this.autocompleteState && this.autocompleteList) {
703
+ if (kb.matches(data, "tui.select.cancel")) {
704
+ this.cancelAutocomplete();
705
+ return;
706
+ }
707
+ if (kb.matches(data, "tui.select.up") || kb.matches(data, "tui.select.down")) {
708
+ this.autocompleteList.handleInput(data);
709
+ return;
710
+ }
711
+ if (kb.matches(data, "tui.input.tab")) {
712
+ const selected = this.autocompleteList.getSelectedItem();
713
+ if (selected && this.autocompleteProvider) {
714
+ this.pushUndoSnapshot();
715
+ this.lastAction = null;
716
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
717
+ this.state.lines = result.lines;
718
+ this.state.cursorLine = result.cursorLine;
719
+ this.setCursorCol(result.cursorCol);
720
+ this.cancelAutocomplete();
721
+ if (this.onChange)
722
+ this.onChange(this.getText());
723
+ }
724
+ return;
725
+ }
726
+ if (kb.matches(data, "tui.select.confirm")) {
727
+ const selected = this.autocompleteList.getSelectedItem();
728
+ if (selected && this.autocompleteProvider) {
729
+ this.pushUndoSnapshot();
730
+ this.lastAction = null;
731
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
732
+ this.state.lines = result.lines;
733
+ this.state.cursorLine = result.cursorLine;
734
+ this.setCursorCol(result.cursorCol);
735
+ if (this.autocompletePrefix.startsWith("/")) {
736
+ this.cancelAutocomplete();
737
+ // Fall through to submit
738
+ }
739
+ else {
740
+ this.cancelAutocomplete();
741
+ if (this.onChange)
742
+ this.onChange(this.getText());
743
+ return;
744
+ }
745
+ }
746
+ }
747
+ }
748
+ // Tab - trigger completion
749
+ if (kb.matches(data, "tui.input.tab") && !this.autocompleteState) {
750
+ this.handleTabCompletion();
751
+ return;
752
+ }
753
+ // Deletion actions
754
+ if (kb.matches(data, "tui.editor.deleteToLineEnd")) {
755
+ this.deleteToEndOfLine();
756
+ return;
757
+ }
758
+ if (kb.matches(data, "tui.editor.deleteToLineStart")) {
759
+ this.deleteToStartOfLine();
760
+ return;
761
+ }
762
+ if (kb.matches(data, "tui.editor.deleteWordBackward")) {
763
+ this.deleteWordBackwards();
764
+ return;
765
+ }
766
+ if (kb.matches(data, "tui.editor.deleteWordForward")) {
767
+ this.deleteWordForward();
768
+ return;
769
+ }
770
+ if (kb.matches(data, "tui.editor.deleteCharBackward") || matchesKey(data, "shift+backspace")) {
771
+ this.handleBackspace();
772
+ return;
773
+ }
774
+ if (kb.matches(data, "tui.editor.deleteCharForward") || matchesKey(data, "shift+delete")) {
775
+ this.handleForwardDelete();
776
+ return;
777
+ }
778
+ // Kill ring actions
779
+ if (kb.matches(data, "tui.editor.yank")) {
780
+ this.yank();
781
+ return;
782
+ }
783
+ if (kb.matches(data, "tui.editor.yankPop")) {
784
+ this.yankPop();
785
+ return;
786
+ }
787
+ // Dedicated history actions always browse entries instead of moving the cursor.
788
+ if (kb.matches(data, "tui.editor.historyPrevious")) {
789
+ this.cancelAutocomplete();
790
+ this.navigateHistory(-1);
791
+ return;
792
+ }
793
+ if (kb.matches(data, "tui.editor.historyNext")) {
794
+ this.cancelAutocomplete();
795
+ this.navigateHistory(1);
796
+ return;
797
+ }
798
+ // Cursor movement actions
799
+ if (kb.matches(data, "tui.editor.cursorLineStart")) {
800
+ this.moveToLineStart();
801
+ return;
802
+ }
803
+ if (kb.matches(data, "tui.editor.cursorLineEnd")) {
804
+ this.moveToLineEnd();
805
+ return;
806
+ }
807
+ if (kb.matches(data, "tui.editor.cursorWordLeft")) {
808
+ this.moveWordBackwards();
809
+ return;
810
+ }
811
+ if (kb.matches(data, "tui.editor.cursorWordRight")) {
812
+ this.moveWordForwards();
813
+ return;
814
+ }
815
+ // New line
816
+ if (kb.matches(data, "tui.input.newLine") ||
817
+ (data.charCodeAt(0) === 10 && data.length > 1) ||
818
+ data === "\x1b\r" ||
819
+ data === "\x1b[13;2~" ||
820
+ (data.length > 1 && data.includes("\x1b") && data.includes("\r")) ||
821
+ (data === "\n" && data.length === 1)) {
822
+ if (this.shouldSubmitOnBackslashEnter(data, kb)) {
823
+ this.handleBackspace();
824
+ this.submitValue();
825
+ return;
826
+ }
827
+ this.addNewLine();
828
+ return;
829
+ }
830
+ // Submit (Enter)
831
+ if (kb.matches(data, "tui.input.submit")) {
832
+ if (this.disableSubmit)
833
+ return;
834
+ // Workaround for terminals without Shift+Enter support:
835
+ // If char before cursor is \, delete it and insert newline instead of submitting.
836
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
837
+ if (this.state.cursorCol > 0 && currentLine[this.state.cursorCol - 1] === "\\") {
838
+ this.handleBackspace();
839
+ this.addNewLine();
840
+ return;
841
+ }
842
+ this.submitValue();
843
+ return;
844
+ }
845
+ // Arrow key navigation (with history support)
846
+ if (kb.matches(data, "tui.editor.cursorUp")) {
847
+ if (this.isOnFirstVisualLine() &&
848
+ (this.isEditorEmpty() || this.historyIndex > -1 || this.state.cursorCol === 0)) {
849
+ this.navigateHistory(-1);
850
+ }
851
+ else if (this.isOnFirstVisualLine()) {
852
+ // Already at top - jump to start of line
853
+ this.moveToLineStart();
854
+ }
855
+ else {
856
+ this.moveCursor(-1, 0);
857
+ }
858
+ return;
859
+ }
860
+ if (kb.matches(data, "tui.editor.cursorDown")) {
861
+ if (this.historyIndex > -1 && this.isOnLastVisualLine()) {
862
+ this.navigateHistory(1);
863
+ }
864
+ else if (this.isOnLastVisualLine()) {
865
+ // Already at bottom - jump to end of line
866
+ this.moveToLineEnd();
867
+ }
868
+ else {
869
+ this.moveCursor(1, 0);
870
+ }
871
+ return;
872
+ }
873
+ if (kb.matches(data, "tui.editor.cursorRight")) {
874
+ this.moveCursor(0, 1);
875
+ return;
876
+ }
877
+ if (kb.matches(data, "tui.editor.cursorLeft")) {
878
+ this.moveCursor(0, -1);
879
+ return;
880
+ }
881
+ // Page up/down - scroll by page and move cursor
882
+ if (kb.matches(data, "tui.editor.pageUp")) {
883
+ this.pageScroll(-1);
884
+ return;
885
+ }
886
+ if (kb.matches(data, "tui.editor.pageDown")) {
887
+ this.pageScroll(1);
888
+ return;
889
+ }
890
+ // Character jump mode triggers
891
+ if (kb.matches(data, "tui.editor.jumpForward")) {
892
+ this.jumpMode = "forward";
893
+ return;
894
+ }
895
+ if (kb.matches(data, "tui.editor.jumpBackward")) {
896
+ this.jumpMode = "backward";
897
+ return;
898
+ }
899
+ // Shift+Space - insert regular space
900
+ if (matchesKey(data, "shift+space")) {
901
+ this.insertCharacter(" ");
902
+ return;
903
+ }
904
+ const printable = decodePrintableKey(data);
905
+ if (printable !== undefined) {
906
+ this.insertCharacter(printable);
907
+ return;
908
+ }
909
+ // Regular characters
910
+ if (data.charCodeAt(0) >= 32) {
911
+ this.insertCharacter(data);
912
+ }
913
+ }
914
+ layoutText(contentWidth) {
915
+ const layoutLines = [];
916
+ if (this.state.lines.length === 0 || (this.state.lines.length === 1 && this.state.lines[0] === "")) {
917
+ // Empty editor
918
+ layoutLines.push({
919
+ text: "",
920
+ hasCursor: true,
921
+ cursorPos: 0,
922
+ });
923
+ return layoutLines;
924
+ }
925
+ // Process each logical line
926
+ for (let i = 0; i < this.state.lines.length; i++) {
927
+ const line = this.state.lines[i] || "";
928
+ const isCurrentLine = i === this.state.cursorLine;
929
+ const lineVisibleWidth = visibleWidth(line);
930
+ if (lineVisibleWidth <= contentWidth) {
931
+ // Line fits in one layout line
932
+ if (isCurrentLine) {
933
+ layoutLines.push({
934
+ text: line,
935
+ hasCursor: true,
936
+ cursorPos: this.state.cursorCol,
937
+ });
938
+ }
939
+ else {
940
+ layoutLines.push({
941
+ text: line,
942
+ hasCursor: false,
943
+ });
944
+ }
945
+ }
946
+ else {
947
+ // Line needs wrapping - use word-aware wrapping
948
+ const chunks = wordWrapLine(line, contentWidth, [...this.segment(line, "grapheme")]);
949
+ for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
950
+ const chunk = chunks[chunkIndex];
951
+ if (!chunk)
952
+ continue;
953
+ const cursorPos = this.state.cursorCol;
954
+ const isLastChunk = chunkIndex === chunks.length - 1;
955
+ // Determine if cursor is in this chunk
956
+ // For word-wrapped chunks, we need to handle the case where
957
+ // cursor might be in trimmed whitespace at end of chunk
958
+ let hasCursorInChunk = false;
959
+ let adjustedCursorPos = 0;
960
+ if (isCurrentLine) {
961
+ if (isLastChunk) {
962
+ // Last chunk: cursor belongs here if >= startIndex
963
+ hasCursorInChunk = cursorPos >= chunk.startIndex;
964
+ adjustedCursorPos = cursorPos - chunk.startIndex;
965
+ }
966
+ else {
967
+ // Non-last chunk: cursor belongs here if in range [startIndex, endIndex)
968
+ // But we need to handle the visual position in the trimmed text
969
+ hasCursorInChunk = cursorPos >= chunk.startIndex && cursorPos < chunk.endIndex;
970
+ if (hasCursorInChunk) {
971
+ adjustedCursorPos = cursorPos - chunk.startIndex;
972
+ // Clamp to text length (in case cursor was in trimmed whitespace)
973
+ if (adjustedCursorPos > chunk.text.length) {
974
+ adjustedCursorPos = chunk.text.length;
975
+ }
976
+ }
977
+ }
978
+ }
979
+ if (hasCursorInChunk) {
980
+ layoutLines.push({
981
+ text: chunk.text,
982
+ hasCursor: true,
983
+ cursorPos: adjustedCursorPos,
984
+ });
985
+ }
986
+ else {
987
+ layoutLines.push({
988
+ text: chunk.text,
989
+ hasCursor: false,
990
+ });
991
+ }
992
+ }
993
+ }
994
+ }
995
+ return layoutLines;
996
+ }
997
+ getText() {
998
+ return this.state.lines.join("\n");
999
+ }
1000
+ expandPasteMarkers(text) {
1001
+ let result = text;
1002
+ for (const [pasteId, pasteContent] of this.pastes) {
1003
+ const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
1004
+ result = result.replace(markerRegex, () => pasteContent);
1005
+ }
1006
+ return result;
1007
+ }
1008
+ /**
1009
+ * Get text with paste markers expanded to their actual content.
1010
+ * Use this when you need the full content (e.g., for external editor).
1011
+ */
1012
+ getExpandedText() {
1013
+ return this.expandPasteMarkers(this.state.lines.join("\n"));
1014
+ }
1015
+ getLines() {
1016
+ return [...this.state.lines];
1017
+ }
1018
+ getCursor() {
1019
+ return { line: this.state.cursorLine, col: this.state.cursorCol };
1020
+ }
1021
+ setText(text) {
1022
+ this.cancelAutocomplete();
1023
+ this.lastAction = null;
1024
+ this.exitHistoryBrowsing();
1025
+ const normalized = this.normalizeText(text);
1026
+ // Push undo snapshot if content differs (makes programmatic changes undoable)
1027
+ if (this.getText() !== normalized) {
1028
+ this.pushUndoSnapshot();
1029
+ }
1030
+ this.pastes.clear();
1031
+ this.pasteCounter = 0;
1032
+ this.setTextInternal(normalized);
1033
+ }
1034
+ /**
1035
+ * Insert text at the current cursor position.
1036
+ * Used for programmatic insertion (e.g., clipboard image markers).
1037
+ * This is atomic for undo - single undo restores entire pre-insert state.
1038
+ */
1039
+ insertTextAtCursor(text) {
1040
+ if (!text)
1041
+ return;
1042
+ this.cancelAutocomplete();
1043
+ this.pushUndoSnapshot();
1044
+ this.lastAction = null;
1045
+ this.exitHistoryBrowsing();
1046
+ this.insertTextAtCursorInternal(text);
1047
+ }
1048
+ /**
1049
+ * Normalize text for editor storage:
1050
+ * - Normalize line endings (\r\n and \r -> \n)
1051
+ * - Expand tabs to 4 spaces
1052
+ */
1053
+ normalizeText(text) {
1054
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\t/g, " ");
1055
+ }
1056
+ /**
1057
+ * Internal text insertion at cursor. Handles single and multi-line text.
1058
+ * Does not push undo snapshots or trigger autocomplete - caller is responsible.
1059
+ * Normalizes line endings and calls onChange once at the end.
1060
+ */
1061
+ insertTextAtCursorInternal(text) {
1062
+ if (!text)
1063
+ return;
1064
+ // Normalize line endings and tabs
1065
+ const normalized = this.normalizeText(text);
1066
+ const insertedLines = normalized.split("\n");
1067
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1068
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1069
+ const afterCursor = currentLine.slice(this.state.cursorCol);
1070
+ if (insertedLines.length === 1) {
1071
+ // Single line - insert at cursor position
1072
+ this.state.lines[this.state.cursorLine] = beforeCursor + normalized + afterCursor;
1073
+ this.setCursorCol(this.state.cursorCol + normalized.length);
1074
+ }
1075
+ else {
1076
+ // Multi-line insertion
1077
+ this.state.lines = [
1078
+ // All lines before current line
1079
+ ...this.state.lines.slice(0, this.state.cursorLine),
1080
+ // The first inserted line merged with text before cursor
1081
+ beforeCursor + insertedLines[0],
1082
+ // All middle inserted lines
1083
+ ...insertedLines.slice(1, -1),
1084
+ // The last inserted line with text after cursor
1085
+ insertedLines[insertedLines.length - 1] + afterCursor,
1086
+ // All lines after current line
1087
+ ...this.state.lines.slice(this.state.cursorLine + 1),
1088
+ ];
1089
+ this.state.cursorLine += insertedLines.length - 1;
1090
+ this.setCursorCol((insertedLines[insertedLines.length - 1] || "").length);
1091
+ }
1092
+ if (this.onChange) {
1093
+ this.onChange(this.getText());
1094
+ }
1095
+ }
1096
+ // All the editor methods from before...
1097
+ insertCharacter(char, skipUndoCoalescing) {
1098
+ this.exitHistoryBrowsing();
1099
+ // Undo coalescing (fish-style):
1100
+ // - Consecutive word chars coalesce into one undo unit
1101
+ // - Space captures state before itself (so undo removes space+following word together)
1102
+ // - Each space is separately undoable
1103
+ // Skip coalescing when called from atomic operations (e.g., handlePaste)
1104
+ if (!skipUndoCoalescing) {
1105
+ if (isWhitespaceChar(char) || this.lastAction !== "type-word") {
1106
+ this.pushUndoSnapshot();
1107
+ }
1108
+ this.lastAction = "type-word";
1109
+ }
1110
+ const line = this.state.lines[this.state.cursorLine] || "";
1111
+ const before = line.slice(0, this.state.cursorCol);
1112
+ const after = line.slice(this.state.cursorCol);
1113
+ this.state.lines[this.state.cursorLine] = before + char + after;
1114
+ this.setCursorCol(this.state.cursorCol + char.length);
1115
+ if (this.onChange) {
1116
+ this.onChange(this.getText());
1117
+ }
1118
+ // Check if we should trigger or update autocomplete
1119
+ if (!this.autocompleteState) {
1120
+ // Auto-trigger for "/" at the start of a line (slash commands)
1121
+ if (char === "/" && this.isAtStartOfMessage()) {
1122
+ this.tryTriggerAutocomplete();
1123
+ }
1124
+ // Auto-trigger for symbol-based completion like @, #, or provider triggers at token boundaries
1125
+ else if (this.autocompleteTriggerCharacters.includes(char)) {
1126
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1127
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1128
+ const charBeforeSymbol = textBeforeCursor[textBeforeCursor.length - 2];
1129
+ if (textBeforeCursor.length === 1 || charBeforeSymbol === " " || charBeforeSymbol === "\t") {
1130
+ this.tryTriggerAutocomplete();
1131
+ }
1132
+ }
1133
+ // Also auto-trigger when typing letters in a slash command or symbol completion context
1134
+ else if (/[a-zA-Z0-9.\-_]/.test(char)) {
1135
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1136
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1137
+ // Check if we're in a slash command (with or without space for arguments)
1138
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
1139
+ this.tryTriggerAutocomplete();
1140
+ }
1141
+ // Check if we're in a symbol-based completion context like @, #, or provider triggers
1142
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1143
+ this.tryTriggerAutocomplete();
1144
+ }
1145
+ }
1146
+ }
1147
+ else {
1148
+ this.updateAutocomplete();
1149
+ }
1150
+ }
1151
+ handlePaste(pastedText) {
1152
+ this.cancelAutocomplete();
1153
+ this.exitHistoryBrowsing();
1154
+ this.lastAction = null;
1155
+ this.pushUndoSnapshot();
1156
+ // Some terminals (e.g. tmux popups with extended-keys-format=csi-u) re-encode
1157
+ // control bytes inside bracketed paste as CSI-u Ctrl+<letter> sequences
1158
+ // (ESC [ <codepoint> ; 5 u). Decode those back to their literal byte so the
1159
+ // per-char filter below preserves newlines instead of stripping ESC and
1160
+ // leaking the printable tail (e.g. "[106;5u") into the editor.
1161
+ const decodedText = pastedText.replace(/\x1b\[(\d+);5u/g, (match, code) => {
1162
+ const cp = Number(code);
1163
+ if (cp >= 97 && cp <= 122)
1164
+ return String.fromCharCode(cp - 96);
1165
+ if (cp >= 65 && cp <= 90)
1166
+ return String.fromCharCode(cp - 64);
1167
+ return match;
1168
+ });
1169
+ // Clean the pasted text: normalize line endings, expand tabs
1170
+ const cleanText = this.normalizeText(decodedText);
1171
+ // Filter out non-printable characters except newlines
1172
+ let filteredText = cleanText
1173
+ .split("")
1174
+ .filter((char) => char === "\n" || char.charCodeAt(0) >= 32)
1175
+ .join("");
1176
+ // If pasting a file path (starts with /, ~, or .) and the character before
1177
+ // the cursor is a word character, prepend a space for better readability
1178
+ if (/^[/~.]/.test(filteredText)) {
1179
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1180
+ const charBeforeCursor = this.state.cursorCol > 0 ? currentLine[this.state.cursorCol - 1] : "";
1181
+ if (charBeforeCursor && /\w/.test(charBeforeCursor)) {
1182
+ filteredText = ` ${filteredText}`;
1183
+ }
1184
+ }
1185
+ // Split into lines to check for large paste
1186
+ const pastedLines = filteredText.split("\n");
1187
+ // Check if this is a large paste (> 10 lines or > 1000 characters)
1188
+ const totalChars = filteredText.length;
1189
+ if (pastedLines.length > 10 || totalChars > 1000) {
1190
+ // Store the paste and insert a marker
1191
+ this.pasteCounter++;
1192
+ const pasteId = this.pasteCounter;
1193
+ this.pastes.set(pasteId, filteredText);
1194
+ // Insert marker like "[paste #1 +123 lines]" or "[paste #1 1234 chars]"
1195
+ const marker = pastedLines.length > 10
1196
+ ? `[paste #${pasteId} +${pastedLines.length} lines]`
1197
+ : `[paste #${pasteId} ${totalChars} chars]`;
1198
+ this.insertTextAtCursorInternal(marker);
1199
+ return;
1200
+ }
1201
+ if (pastedLines.length === 1) {
1202
+ // Single line - insert atomically (do not trigger autocomplete during paste)
1203
+ this.insertTextAtCursorInternal(filteredText);
1204
+ return;
1205
+ }
1206
+ // Multi-line paste - use direct state manipulation
1207
+ this.insertTextAtCursorInternal(filteredText);
1208
+ }
1209
+ addNewLine() {
1210
+ this.cancelAutocomplete();
1211
+ this.exitHistoryBrowsing();
1212
+ this.lastAction = null;
1213
+ this.pushUndoSnapshot();
1214
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1215
+ const before = currentLine.slice(0, this.state.cursorCol);
1216
+ const after = currentLine.slice(this.state.cursorCol);
1217
+ // Split current line
1218
+ this.state.lines[this.state.cursorLine] = before;
1219
+ this.state.lines.splice(this.state.cursorLine + 1, 0, after);
1220
+ // Move cursor to start of new line
1221
+ this.state.cursorLine++;
1222
+ this.setCursorCol(0);
1223
+ if (this.onChange) {
1224
+ this.onChange(this.getText());
1225
+ }
1226
+ }
1227
+ shouldSubmitOnBackslashEnter(data, kb) {
1228
+ if (this.disableSubmit)
1229
+ return false;
1230
+ if (!matchesKey(data, "enter"))
1231
+ return false;
1232
+ const submitKeys = kb.getKeys("tui.input.submit");
1233
+ const hasShiftEnter = submitKeys.includes("shift+enter") || submitKeys.includes("shift+return");
1234
+ if (!hasShiftEnter)
1235
+ return false;
1236
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1237
+ return this.state.cursorCol > 0 && currentLine[this.state.cursorCol - 1] === "\\";
1238
+ }
1239
+ submitValue() {
1240
+ this.cancelAutocomplete();
1241
+ const result = this.expandPasteMarkers(this.state.lines.join("\n")).trim();
1242
+ this.state = { lines: [""], cursorLine: 0, cursorCol: 0 };
1243
+ this.pastes.clear();
1244
+ this.pasteCounter = 0;
1245
+ this.exitHistoryBrowsing();
1246
+ this.scrollOffset = 0;
1247
+ this.undoStack.clear();
1248
+ this.lastAction = null;
1249
+ if (this.onChange)
1250
+ this.onChange("");
1251
+ if (this.onSubmit)
1252
+ this.onSubmit(result);
1253
+ }
1254
+ handleBackspace() {
1255
+ this.exitHistoryBrowsing();
1256
+ this.lastAction = null;
1257
+ if (this.state.cursorCol > 0) {
1258
+ this.pushUndoSnapshot();
1259
+ // Delete grapheme before cursor (handles emojis, combining characters, etc.)
1260
+ let line = this.state.lines[this.state.cursorLine] || "";
1261
+ const beforeCursor = line.slice(0, this.state.cursorCol);
1262
+ // Find the last grapheme in the text before cursor
1263
+ const graphemes = [...this.segment(beforeCursor, "grapheme")];
1264
+ const lastGrapheme = graphemes[graphemes.length - 1];
1265
+ const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
1266
+ const isPastedSegmented = PASTE_MARKER_SINGLE.exec(lastGrapheme.segment);
1267
+ if (isPastedSegmented) {
1268
+ // This contains the id part e.g 4 from [paste #4 +123 lines]
1269
+ const targetId = Number(isPastedSegmented[1]);
1270
+ this.pastes.delete(targetId);
1271
+ this.pasteCounter--;
1272
+ // Shift registry entries down in ascending id order, independent
1273
+ // of marker order in the text ([paste #3] becomes [paste #2] when
1274
+ // [paste #1] is removed).
1275
+ const higherIds = [...this.pastes.keys()].filter((id) => id > targetId).sort((a, b) => a - b);
1276
+ for (const id of higherIds) {
1277
+ this.pastes.set(id - 1, this.pastes.get(id));
1278
+ this.pastes.delete(id);
1279
+ }
1280
+ // Renumber markers with ids greater than the removed one.
1281
+ this.state.lines = this.state.lines.map((line) => line.replace(PASTE_MARKER_REGEX, (fullMatch, idGroup, suffixGroup) => {
1282
+ const x = Number(idGroup);
1283
+ if (x <= targetId)
1284
+ return fullMatch;
1285
+ return `[paste #${x - 1}${suffixGroup}]`;
1286
+ }));
1287
+ }
1288
+ line = this.state.lines[this.state.cursorLine] || "";
1289
+ const before = line.slice(0, this.state.cursorCol - graphemeLength);
1290
+ const after = line.slice(this.state.cursorCol);
1291
+ this.state.lines[this.state.cursorLine] = before + after;
1292
+ this.setCursorCol(this.state.cursorCol - graphemeLength);
1293
+ }
1294
+ else if (this.state.cursorLine > 0) {
1295
+ this.pushUndoSnapshot();
1296
+ // Merge with previous line
1297
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1298
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1299
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1300
+ this.state.lines.splice(this.state.cursorLine, 1);
1301
+ this.state.cursorLine--;
1302
+ this.setCursorCol(previousLine.length);
1303
+ }
1304
+ if (this.onChange) {
1305
+ this.onChange(this.getText());
1306
+ }
1307
+ // Update or re-trigger autocomplete after backspace
1308
+ if (this.autocompleteState) {
1309
+ this.updateAutocomplete();
1310
+ }
1311
+ else {
1312
+ // If autocomplete was cancelled (no matches), re-trigger if we're in a completable context
1313
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1314
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1315
+ // Slash command context
1316
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
1317
+ this.tryTriggerAutocomplete();
1318
+ }
1319
+ // Symbol-based completion context like @, #, or provider triggers
1320
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1321
+ this.tryTriggerAutocomplete();
1322
+ }
1323
+ }
1324
+ }
1325
+ /**
1326
+ * Set cursor column and clear preferredVisualCol.
1327
+ * Use this for all non-vertical cursor movements to reset sticky column behavior.
1328
+ */
1329
+ setCursorCol(col) {
1330
+ this.state.cursorCol = col;
1331
+ this.preferredVisualCol = null;
1332
+ this.snappedFromCursorCol = null;
1333
+ }
1334
+ /**
1335
+ * Move cursor to a target visual line, applying sticky column logic.
1336
+ * Shared by moveCursor() and pageScroll().
1337
+ */
1338
+ moveToVisualLine(visualLines, currentVisualLine, targetVisualLine) {
1339
+ const currentVL = visualLines[currentVisualLine];
1340
+ const targetVL = visualLines[targetVisualLine];
1341
+ if (!(currentVL && targetVL))
1342
+ return;
1343
+ // When the cursor was snapped to a segment start, resolve the pre-snap
1344
+ // position against the VL it belongs to. This gives the correct visual
1345
+ // column even after a resize reshuffles VLs.
1346
+ let currentVisualCol;
1347
+ if (this.snappedFromCursorCol !== null) {
1348
+ const vlIndex = this.findVisualLineAt(visualLines, currentVL.logicalLine, this.snappedFromCursorCol);
1349
+ currentVisualCol = this.snappedFromCursorCol - visualLines[vlIndex].startCol;
1350
+ }
1351
+ else {
1352
+ currentVisualCol = this.state.cursorCol - currentVL.startCol;
1353
+ }
1354
+ // For non-last segments, clamp to length-1 to stay within the segment
1355
+ const isLastSourceSegment = currentVisualLine === visualLines.length - 1 ||
1356
+ visualLines[currentVisualLine + 1]?.logicalLine !== currentVL.logicalLine;
1357
+ const sourceMaxVisualCol = isLastSourceSegment ? currentVL.length : Math.max(0, currentVL.length - 1);
1358
+ const isLastTargetSegment = targetVisualLine === visualLines.length - 1 ||
1359
+ visualLines[targetVisualLine + 1]?.logicalLine !== targetVL.logicalLine;
1360
+ const targetMaxVisualCol = isLastTargetSegment ? targetVL.length : Math.max(0, targetVL.length - 1);
1361
+ const moveToVisualCol = this.computeVerticalMoveColumn(currentVisualCol, sourceMaxVisualCol, targetMaxVisualCol);
1362
+ // Set cursor position
1363
+ this.state.cursorLine = targetVL.logicalLine;
1364
+ const targetCol = targetVL.startCol + moveToVisualCol;
1365
+ const logicalLine = this.state.lines[targetVL.logicalLine] || "";
1366
+ this.state.cursorCol = Math.min(targetCol, logicalLine.length);
1367
+ // Snap cursor to atomic segment boundary (e.g. paste markers)
1368
+ // so the cursor never lands in the middle of a multi-grapheme unit.
1369
+ // Single-grapheme segments don't need snapping.
1370
+ const segments = [...this.segment(logicalLine, "grapheme")];
1371
+ for (const seg of segments) {
1372
+ if (seg.index > this.state.cursorCol)
1373
+ break;
1374
+ if (seg.segment.length <= 1)
1375
+ continue;
1376
+ if (this.state.cursorCol < seg.index + seg.segment.length) {
1377
+ const isContinuation = seg.index < targetVL.startCol;
1378
+ const isMovingDown = targetVisualLine > currentVisualLine;
1379
+ if (isContinuation && isMovingDown) {
1380
+ // The segment started on a previous visual line, and we
1381
+ // already visited it on the way down. Skip all remaining
1382
+ // continuation VLs and land on the first VL past it.
1383
+ const segEnd = seg.index + seg.segment.length;
1384
+ let next = targetVisualLine + 1;
1385
+ while (next < visualLines.length &&
1386
+ visualLines[next].logicalLine === targetVL.logicalLine &&
1387
+ visualLines[next].startCol < segEnd) {
1388
+ next++;
1389
+ }
1390
+ if (next < visualLines.length) {
1391
+ this.moveToVisualLine(visualLines, currentVisualLine, next);
1392
+ return;
1393
+ }
1394
+ }
1395
+ // Snap to the start of the segment so it gets highlighted.
1396
+ // Store the pre-snap position so the next vertical move can
1397
+ // resolve it to the correct visual column.
1398
+ this.snappedFromCursorCol = this.state.cursorCol;
1399
+ this.state.cursorCol = seg.index;
1400
+ return;
1401
+ }
1402
+ }
1403
+ // No snap occurred – we moved out of the atomic segment.
1404
+ this.snappedFromCursorCol = null;
1405
+ }
1406
+ /**
1407
+ * Compute the target visual column for vertical cursor movement.
1408
+ * Implements the sticky column decision table:
1409
+ *
1410
+ * | P | S | T | U | Scenario | Set Preferred | Move To |
1411
+ * |---|---|---|---| ---------------------------------------------------- |---------------|-------------|
1412
+ * | 0 | * | 0 | - | Start nav, target fits | null | current |
1413
+ * | 0 | * | 1 | - | Start nav, target shorter | current | target end |
1414
+ * | 1 | 0 | 0 | 0 | Clamped, target fits preferred | null | preferred |
1415
+ * | 1 | 0 | 0 | 1 | Clamped, target longer but still can't fit preferred | keep | target end |
1416
+ * | 1 | 0 | 1 | - | Clamped, target even shorter | keep | target end |
1417
+ * | 1 | 1 | 0 | - | Rewrapped, target fits current | null | current |
1418
+ * | 1 | 1 | 1 | - | Rewrapped, target shorter than current | current | target end |
1419
+ *
1420
+ * Where:
1421
+ * - P = preferred col is set
1422
+ * - S = cursor in middle of source line (not clamped to end)
1423
+ * - T = target line shorter than current visual col
1424
+ * - U = target line shorter than preferred col
1425
+ */
1426
+ computeVerticalMoveColumn(currentVisualCol, sourceMaxVisualCol, targetMaxVisualCol) {
1427
+ const hasPreferred = this.preferredVisualCol !== null; // P
1428
+ const cursorInMiddle = currentVisualCol < sourceMaxVisualCol; // S
1429
+ const targetTooShort = targetMaxVisualCol < currentVisualCol; // T
1430
+ if (!hasPreferred || cursorInMiddle) {
1431
+ if (targetTooShort) {
1432
+ // Cases 2 and 7
1433
+ this.preferredVisualCol = currentVisualCol;
1434
+ return targetMaxVisualCol;
1435
+ }
1436
+ // Cases 1 and 6
1437
+ this.preferredVisualCol = null;
1438
+ return currentVisualCol;
1439
+ }
1440
+ const targetCantFitPreferred = targetMaxVisualCol < this.preferredVisualCol; // U
1441
+ if (targetTooShort || targetCantFitPreferred) {
1442
+ // Cases 4 and 5
1443
+ return targetMaxVisualCol;
1444
+ }
1445
+ // Case 3
1446
+ const result = this.preferredVisualCol;
1447
+ this.preferredVisualCol = null;
1448
+ return result;
1449
+ }
1450
+ moveToLineStart() {
1451
+ this.lastAction = null;
1452
+ this.setCursorCol(0);
1453
+ }
1454
+ moveToLineEnd() {
1455
+ this.lastAction = null;
1456
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1457
+ this.setCursorCol(currentLine.length);
1458
+ }
1459
+ deleteToStartOfLine() {
1460
+ this.exitHistoryBrowsing();
1461
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1462
+ if (this.state.cursorCol > 0) {
1463
+ this.pushUndoSnapshot();
1464
+ // Calculate text to be deleted and save to kill ring (backward deletion = prepend)
1465
+ const deletedText = currentLine.slice(0, this.state.cursorCol);
1466
+ this.killRing.push(deletedText, { prepend: true, accumulate: this.lastAction === "kill" });
1467
+ this.lastAction = "kill";
1468
+ // Delete from start of line up to cursor
1469
+ this.state.lines[this.state.cursorLine] = currentLine.slice(this.state.cursorCol);
1470
+ this.setCursorCol(0);
1471
+ }
1472
+ else if (this.state.cursorLine > 0) {
1473
+ this.pushUndoSnapshot();
1474
+ // At start of line - merge with previous line, treating newline as deleted text
1475
+ this.killRing.push("\n", { prepend: true, accumulate: this.lastAction === "kill" });
1476
+ this.lastAction = "kill";
1477
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1478
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1479
+ this.state.lines.splice(this.state.cursorLine, 1);
1480
+ this.state.cursorLine--;
1481
+ this.setCursorCol(previousLine.length);
1482
+ }
1483
+ if (this.onChange) {
1484
+ this.onChange(this.getText());
1485
+ }
1486
+ }
1487
+ deleteToEndOfLine() {
1488
+ this.exitHistoryBrowsing();
1489
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1490
+ if (this.state.cursorCol < currentLine.length) {
1491
+ this.pushUndoSnapshot();
1492
+ // Calculate text to be deleted and save to kill ring (forward deletion = append)
1493
+ const deletedText = currentLine.slice(this.state.cursorCol);
1494
+ this.killRing.push(deletedText, { prepend: false, accumulate: this.lastAction === "kill" });
1495
+ this.lastAction = "kill";
1496
+ // Delete from cursor to end of line
1497
+ this.state.lines[this.state.cursorLine] = currentLine.slice(0, this.state.cursorCol);
1498
+ }
1499
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1500
+ this.pushUndoSnapshot();
1501
+ // At end of line - merge with next line, treating newline as deleted text
1502
+ this.killRing.push("\n", { prepend: false, accumulate: this.lastAction === "kill" });
1503
+ this.lastAction = "kill";
1504
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1505
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1506
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1507
+ }
1508
+ if (this.onChange) {
1509
+ this.onChange(this.getText());
1510
+ }
1511
+ }
1512
+ deleteWordBackwards() {
1513
+ this.exitHistoryBrowsing();
1514
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1515
+ // If at start of line, behave like backspace at column 0 (merge with previous line)
1516
+ if (this.state.cursorCol === 0) {
1517
+ if (this.state.cursorLine > 0) {
1518
+ this.pushUndoSnapshot();
1519
+ // Treat newline as deleted text (backward deletion = prepend)
1520
+ this.killRing.push("\n", { prepend: true, accumulate: this.lastAction === "kill" });
1521
+ this.lastAction = "kill";
1522
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1523
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1524
+ this.state.lines.splice(this.state.cursorLine, 1);
1525
+ this.state.cursorLine--;
1526
+ this.setCursorCol(previousLine.length);
1527
+ }
1528
+ }
1529
+ else {
1530
+ this.pushUndoSnapshot();
1531
+ // Save lastAction before cursor movement (moveWordBackwards resets it)
1532
+ const wasKill = this.lastAction === "kill";
1533
+ const oldCursorCol = this.state.cursorCol;
1534
+ this.moveWordBackwards();
1535
+ const deleteFrom = this.state.cursorCol;
1536
+ this.setCursorCol(oldCursorCol);
1537
+ const deletedText = currentLine.slice(deleteFrom, this.state.cursorCol);
1538
+ this.killRing.push(deletedText, { prepend: true, accumulate: wasKill });
1539
+ this.lastAction = "kill";
1540
+ this.state.lines[this.state.cursorLine] =
1541
+ currentLine.slice(0, deleteFrom) + currentLine.slice(this.state.cursorCol);
1542
+ this.setCursorCol(deleteFrom);
1543
+ }
1544
+ if (this.onChange) {
1545
+ this.onChange(this.getText());
1546
+ }
1547
+ }
1548
+ deleteWordForward() {
1549
+ this.exitHistoryBrowsing();
1550
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1551
+ // If at end of line, merge with next line (delete the newline)
1552
+ if (this.state.cursorCol >= currentLine.length) {
1553
+ if (this.state.cursorLine < this.state.lines.length - 1) {
1554
+ this.pushUndoSnapshot();
1555
+ // Treat newline as deleted text (forward deletion = append)
1556
+ this.killRing.push("\n", { prepend: false, accumulate: this.lastAction === "kill" });
1557
+ this.lastAction = "kill";
1558
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1559
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1560
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1561
+ }
1562
+ }
1563
+ else {
1564
+ this.pushUndoSnapshot();
1565
+ // Save lastAction before cursor movement (moveWordForwards resets it)
1566
+ const wasKill = this.lastAction === "kill";
1567
+ const oldCursorCol = this.state.cursorCol;
1568
+ this.moveWordForwards();
1569
+ const deleteTo = this.state.cursorCol;
1570
+ this.setCursorCol(oldCursorCol);
1571
+ const deletedText = currentLine.slice(this.state.cursorCol, deleteTo);
1572
+ this.killRing.push(deletedText, { prepend: false, accumulate: wasKill });
1573
+ this.lastAction = "kill";
1574
+ this.state.lines[this.state.cursorLine] =
1575
+ currentLine.slice(0, this.state.cursorCol) + currentLine.slice(deleteTo);
1576
+ }
1577
+ if (this.onChange) {
1578
+ this.onChange(this.getText());
1579
+ }
1580
+ }
1581
+ handleForwardDelete() {
1582
+ this.exitHistoryBrowsing();
1583
+ this.lastAction = null;
1584
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1585
+ if (this.state.cursorCol < currentLine.length) {
1586
+ this.pushUndoSnapshot();
1587
+ // Delete grapheme at cursor position (handles emojis, combining characters, etc.)
1588
+ const afterCursor = currentLine.slice(this.state.cursorCol);
1589
+ // Find the first grapheme at cursor
1590
+ const graphemes = [...this.segment(afterCursor, "grapheme")];
1591
+ const firstGrapheme = graphemes[0];
1592
+ const graphemeLength = firstGrapheme ? firstGrapheme.segment.length : 1;
1593
+ const before = currentLine.slice(0, this.state.cursorCol);
1594
+ const after = currentLine.slice(this.state.cursorCol + graphemeLength);
1595
+ this.state.lines[this.state.cursorLine] = before + after;
1596
+ }
1597
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1598
+ this.pushUndoSnapshot();
1599
+ // At end of line - merge with next line
1600
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1601
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1602
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1603
+ }
1604
+ if (this.onChange) {
1605
+ this.onChange(this.getText());
1606
+ }
1607
+ // Update or re-trigger autocomplete after forward delete
1608
+ if (this.autocompleteState) {
1609
+ this.updateAutocomplete();
1610
+ }
1611
+ else {
1612
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1613
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1614
+ // Slash command context
1615
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
1616
+ this.tryTriggerAutocomplete();
1617
+ }
1618
+ // Symbol-based completion context like @, #, or provider triggers
1619
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1620
+ this.tryTriggerAutocomplete();
1621
+ }
1622
+ }
1623
+ }
1624
+ /**
1625
+ * Build a mapping from visual lines to logical positions.
1626
+ * Returns an array where each element represents a visual line with:
1627
+ * - logicalLine: index into this.state.lines
1628
+ * - startCol: starting column in the logical line
1629
+ * - length: length of this visual line segment
1630
+ */
1631
+ buildVisualLineMap(width) {
1632
+ const visualLines = [];
1633
+ for (let i = 0; i < this.state.lines.length; i++) {
1634
+ const line = this.state.lines[i] || "";
1635
+ const lineVisWidth = visibleWidth(line);
1636
+ if (line.length === 0) {
1637
+ // Empty line still takes one visual line
1638
+ visualLines.push({ logicalLine: i, startCol: 0, length: 0 });
1639
+ }
1640
+ else if (lineVisWidth <= width) {
1641
+ visualLines.push({ logicalLine: i, startCol: 0, length: line.length });
1642
+ }
1643
+ else {
1644
+ // Line needs wrapping - use word-aware wrapping
1645
+ const chunks = wordWrapLine(line, width, [...this.segment(line, "grapheme")]);
1646
+ for (const chunk of chunks) {
1647
+ visualLines.push({
1648
+ logicalLine: i,
1649
+ startCol: chunk.startIndex,
1650
+ length: chunk.endIndex - chunk.startIndex,
1651
+ });
1652
+ }
1653
+ }
1654
+ }
1655
+ return visualLines;
1656
+ }
1657
+ /**
1658
+ * Find the visual line index that contains the given logical position.
1659
+ */
1660
+ findVisualLineAt(visualLines, line, col) {
1661
+ for (let i = 0; i < visualLines.length; i++) {
1662
+ const vl = visualLines[i];
1663
+ if (!vl || vl.logicalLine !== line)
1664
+ continue;
1665
+ const offset = col - vl.startCol;
1666
+ // Cursor is in this segment if it's within range. For the last
1667
+ // segment of a logical line, cursor can be at length (end position)
1668
+ const isLastSegmentOfLine = i === visualLines.length - 1 || visualLines[i + 1]?.logicalLine !== vl.logicalLine;
1669
+ if (offset >= 0 && (offset < vl.length || (isLastSegmentOfLine && offset === vl.length))) {
1670
+ return i;
1671
+ }
1672
+ }
1673
+ return visualLines.length - 1;
1674
+ }
1675
+ /**
1676
+ * Find the visual line index for the current cursor position.
1677
+ */
1678
+ findCurrentVisualLine(visualLines) {
1679
+ return this.findVisualLineAt(visualLines, this.state.cursorLine, this.state.cursorCol);
1680
+ }
1681
+ moveCursor(deltaLine, deltaCol) {
1682
+ this.lastAction = null;
1683
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
1684
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
1685
+ if (deltaLine !== 0) {
1686
+ const targetVisualLine = currentVisualLine + deltaLine;
1687
+ if (targetVisualLine >= 0 && targetVisualLine < visualLines.length) {
1688
+ this.moveToVisualLine(visualLines, currentVisualLine, targetVisualLine);
1689
+ }
1690
+ }
1691
+ if (deltaCol !== 0) {
1692
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1693
+ if (deltaCol > 0) {
1694
+ // Moving right - move by one grapheme (handles emojis, combining characters, etc.)
1695
+ if (this.state.cursorCol < currentLine.length) {
1696
+ const afterCursor = currentLine.slice(this.state.cursorCol);
1697
+ const graphemes = [...this.segment(afterCursor, "grapheme")];
1698
+ const firstGrapheme = graphemes[0];
1699
+ this.setCursorCol(this.state.cursorCol + (firstGrapheme ? firstGrapheme.segment.length : 1));
1700
+ }
1701
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1702
+ // Wrap to start of next logical line
1703
+ this.state.cursorLine++;
1704
+ this.setCursorCol(0);
1705
+ }
1706
+ else {
1707
+ // At end of last line - can't move, but set preferredVisualCol for up/down navigation
1708
+ const currentVL = visualLines[currentVisualLine];
1709
+ if (currentVL) {
1710
+ this.preferredVisualCol = this.state.cursorCol - currentVL.startCol;
1711
+ }
1712
+ }
1713
+ }
1714
+ else {
1715
+ // Moving left - move by one grapheme (handles emojis, combining characters, etc.)
1716
+ if (this.state.cursorCol > 0) {
1717
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1718
+ const graphemes = [...this.segment(beforeCursor, "grapheme")];
1719
+ const lastGrapheme = graphemes[graphemes.length - 1];
1720
+ this.setCursorCol(this.state.cursorCol - (lastGrapheme ? lastGrapheme.segment.length : 1));
1721
+ }
1722
+ else if (this.state.cursorLine > 0) {
1723
+ // Wrap to end of previous logical line
1724
+ this.state.cursorLine--;
1725
+ const prevLine = this.state.lines[this.state.cursorLine] || "";
1726
+ this.setCursorCol(prevLine.length);
1727
+ }
1728
+ }
1729
+ }
1730
+ // Keep an open autocomplete picker in sync with the new cursor
1731
+ // position: cursor movement changes the text before the cursor, so a
1732
+ // picker computed for the old position is stale. Re-query so it
1733
+ // refreshes — or closes when the new position yields no suggestions —
1734
+ // mirroring insertCharacter()/handleBackspace(). Without this, arrowing
1735
+ // left from `/cmd ` back into the command name leaves the argument
1736
+ // picker showing against a `/cmd` prefix (and a Tab there would
1737
+ // concatenate the stale suggestion onto the partial command name).
1738
+ if (this.autocompleteState) {
1739
+ this.updateAutocomplete();
1740
+ }
1741
+ }
1742
+ /**
1743
+ * Scroll by a page (direction: -1 for up, 1 for down).
1744
+ * Moves cursor by the page size while keeping it in bounds.
1745
+ */
1746
+ pageScroll(direction) {
1747
+ this.lastAction = null;
1748
+ const terminalRows = this.tui.terminal.rows;
1749
+ const pageSize = Math.max(5, Math.floor(terminalRows * 0.3));
1750
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
1751
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
1752
+ const targetVisualLine = Math.max(0, Math.min(visualLines.length - 1, currentVisualLine + direction * pageSize));
1753
+ this.moveToVisualLine(visualLines, currentVisualLine, targetVisualLine);
1754
+ }
1755
+ moveWordBackwards() {
1756
+ this.lastAction = null;
1757
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1758
+ // If at start of line, move to end of previous line
1759
+ if (this.state.cursorCol === 0) {
1760
+ if (this.state.cursorLine > 0) {
1761
+ this.state.cursorLine--;
1762
+ const prevLine = this.state.lines[this.state.cursorLine] || "";
1763
+ this.setCursorCol(prevLine.length);
1764
+ }
1765
+ return;
1766
+ }
1767
+ this.setCursorCol(findWordBackward(currentLine, this.state.cursorCol, {
1768
+ segment: (text) => this.segment(text, "word"),
1769
+ isAtomicSegment: isPasteMarker,
1770
+ }));
1771
+ }
1772
+ /**
1773
+ * Yank (paste) the most recent kill ring entry at cursor position.
1774
+ */
1775
+ yank() {
1776
+ if (this.killRing.length === 0)
1777
+ return;
1778
+ this.pushUndoSnapshot();
1779
+ const text = this.killRing.peek();
1780
+ this.insertYankedText(text);
1781
+ this.lastAction = "yank";
1782
+ }
1783
+ /**
1784
+ * Cycle through kill ring (only works immediately after yank or yank-pop).
1785
+ * Replaces the last yanked text with the previous entry in the ring.
1786
+ */
1787
+ yankPop() {
1788
+ // Only works if we just yanked and have more than one entry
1789
+ if (this.lastAction !== "yank" || this.killRing.length <= 1)
1790
+ return;
1791
+ this.pushUndoSnapshot();
1792
+ // Delete the previously yanked text (still at end of ring before rotation)
1793
+ this.deleteYankedText();
1794
+ // Rotate the ring: move end to front
1795
+ this.killRing.rotate();
1796
+ // Insert the new most recent entry (now at end after rotation)
1797
+ const text = this.killRing.peek();
1798
+ this.insertYankedText(text);
1799
+ this.lastAction = "yank";
1800
+ }
1801
+ /**
1802
+ * Insert text at cursor position (used by yank operations).
1803
+ */
1804
+ insertYankedText(text) {
1805
+ this.exitHistoryBrowsing();
1806
+ const lines = text.split("\n");
1807
+ if (lines.length === 1) {
1808
+ // Single line - insert at cursor
1809
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1810
+ const before = currentLine.slice(0, this.state.cursorCol);
1811
+ const after = currentLine.slice(this.state.cursorCol);
1812
+ this.state.lines[this.state.cursorLine] = before + text + after;
1813
+ this.setCursorCol(this.state.cursorCol + text.length);
1814
+ }
1815
+ else {
1816
+ // Multi-line insert
1817
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1818
+ const before = currentLine.slice(0, this.state.cursorCol);
1819
+ const after = currentLine.slice(this.state.cursorCol);
1820
+ // First line merges with text before cursor
1821
+ this.state.lines[this.state.cursorLine] = before + (lines[0] || "");
1822
+ // Insert middle lines
1823
+ for (let i = 1; i < lines.length - 1; i++) {
1824
+ this.state.lines.splice(this.state.cursorLine + i, 0, lines[i] || "");
1825
+ }
1826
+ // Last line merges with text after cursor
1827
+ const lastLineIndex = this.state.cursorLine + lines.length - 1;
1828
+ this.state.lines.splice(lastLineIndex, 0, (lines[lines.length - 1] || "") + after);
1829
+ // Update cursor position
1830
+ this.state.cursorLine = lastLineIndex;
1831
+ this.setCursorCol((lines[lines.length - 1] || "").length);
1832
+ }
1833
+ if (this.onChange) {
1834
+ this.onChange(this.getText());
1835
+ }
1836
+ }
1837
+ /**
1838
+ * Delete the previously yanked text (used by yank-pop).
1839
+ * The yanked text is derived from killRing[end] since it hasn't been rotated yet.
1840
+ */
1841
+ deleteYankedText() {
1842
+ const yankedText = this.killRing.peek();
1843
+ if (!yankedText)
1844
+ return;
1845
+ const yankLines = yankedText.split("\n");
1846
+ if (yankLines.length === 1) {
1847
+ // Single line - delete backward from cursor
1848
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1849
+ const deleteLen = yankedText.length;
1850
+ const before = currentLine.slice(0, this.state.cursorCol - deleteLen);
1851
+ const after = currentLine.slice(this.state.cursorCol);
1852
+ this.state.lines[this.state.cursorLine] = before + after;
1853
+ this.setCursorCol(this.state.cursorCol - deleteLen);
1854
+ }
1855
+ else {
1856
+ // Multi-line delete - cursor is at end of last yanked line
1857
+ const startLine = this.state.cursorLine - (yankLines.length - 1);
1858
+ const startCol = (this.state.lines[startLine] || "").length - (yankLines[0] || "").length;
1859
+ // Get text after cursor on current line
1860
+ const afterCursor = (this.state.lines[this.state.cursorLine] || "").slice(this.state.cursorCol);
1861
+ // Get text before yank start position
1862
+ const beforeYank = (this.state.lines[startLine] || "").slice(0, startCol);
1863
+ // Remove all lines from startLine to cursorLine and replace with merged line
1864
+ this.state.lines.splice(startLine, yankLines.length, beforeYank + afterCursor);
1865
+ // Update cursor
1866
+ this.state.cursorLine = startLine;
1867
+ this.setCursorCol(startCol);
1868
+ }
1869
+ if (this.onChange) {
1870
+ this.onChange(this.getText());
1871
+ }
1872
+ }
1873
+ pushUndoSnapshot() {
1874
+ this.undoStack.push({ state: this.state, pastes: this.pastes, pasteCounter: this.pasteCounter });
1875
+ }
1876
+ undo() {
1877
+ this.exitHistoryBrowsing();
1878
+ const snapshot = this.undoStack.pop();
1879
+ if (!snapshot)
1880
+ return;
1881
+ Object.assign(this.state, snapshot.state);
1882
+ this.pastes = snapshot.pastes;
1883
+ this.pasteCounter = snapshot.pasteCounter;
1884
+ this.lastAction = null;
1885
+ this.preferredVisualCol = null;
1886
+ if (this.onChange) {
1887
+ this.onChange(this.getText());
1888
+ }
1889
+ }
1890
+ /**
1891
+ * Jump to the first occurrence of a character in the specified direction.
1892
+ * Multi-line search. Case-sensitive. Skips the current cursor position.
1893
+ */
1894
+ jumpToChar(char, direction) {
1895
+ this.lastAction = null;
1896
+ const isForward = direction === "forward";
1897
+ const lines = this.state.lines;
1898
+ const end = isForward ? lines.length : -1;
1899
+ const step = isForward ? 1 : -1;
1900
+ for (let lineIdx = this.state.cursorLine; lineIdx !== end; lineIdx += step) {
1901
+ const line = lines[lineIdx] || "";
1902
+ const isCurrentLine = lineIdx === this.state.cursorLine;
1903
+ // Current line: start after/before cursor; other lines: search full line
1904
+ const searchFrom = isCurrentLine
1905
+ ? isForward
1906
+ ? this.state.cursorCol + 1
1907
+ : this.state.cursorCol - 1
1908
+ : undefined;
1909
+ const idx = isForward ? line.indexOf(char, searchFrom) : line.lastIndexOf(char, searchFrom);
1910
+ if (idx !== -1) {
1911
+ this.state.cursorLine = lineIdx;
1912
+ this.setCursorCol(idx);
1913
+ return;
1914
+ }
1915
+ }
1916
+ // No match found - cursor stays in place
1917
+ }
1918
+ moveWordForwards() {
1919
+ this.lastAction = null;
1920
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1921
+ // If at end of line, move to start of next line
1922
+ if (this.state.cursorCol >= currentLine.length) {
1923
+ if (this.state.cursorLine < this.state.lines.length - 1) {
1924
+ this.state.cursorLine++;
1925
+ this.setCursorCol(0);
1926
+ }
1927
+ return;
1928
+ }
1929
+ this.setCursorCol(findWordForward(currentLine, this.state.cursorCol, {
1930
+ segment: (text) => this.segment(text, "word"),
1931
+ isAtomicSegment: isPasteMarker,
1932
+ }));
1933
+ }
1934
+ // Slash menu only allowed on the first line of the editor
1935
+ isSlashMenuAllowed() {
1936
+ return this.state.cursorLine === 0;
1937
+ }
1938
+ // Helper method to check if cursor is at start of message (for slash command detection)
1939
+ isAtStartOfMessage() {
1940
+ if (!this.isSlashMenuAllowed())
1941
+ return false;
1942
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1943
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1944
+ return beforeCursor.trim() === "" || beforeCursor.trim() === "/";
1945
+ }
1946
+ isInSlashCommandContext(textBeforeCursor) {
1947
+ return this.isSlashMenuAllowed() && textBeforeCursor.trimStart().startsWith("/");
1948
+ }
1949
+ // Autocomplete methods
1950
+ /**
1951
+ * Find the best autocomplete item index for the given prefix.
1952
+ * Returns -1 if no match is found.
1953
+ *
1954
+ * Match priority:
1955
+ * 1. Exact match (prefix === item.value) -> always selected
1956
+ * 2. Prefix match -> first item whose value starts with prefix
1957
+ * 3. No match -> -1 (keep default highlight)
1958
+ *
1959
+ * Matching is case-sensitive and checks item.value only.
1960
+ */
1961
+ getBestAutocompleteMatchIndex(items, prefix) {
1962
+ if (!prefix)
1963
+ return -1;
1964
+ let firstPrefixIndex = -1;
1965
+ for (let i = 0; i < items.length; i++) {
1966
+ const value = items[i].value;
1967
+ if (value === prefix) {
1968
+ return i; // Exact match always wins
1969
+ }
1970
+ if (firstPrefixIndex === -1 && value.startsWith(prefix)) {
1971
+ firstPrefixIndex = i;
1972
+ }
1973
+ }
1974
+ return firstPrefixIndex;
1975
+ }
1976
+ createAutocompleteList(prefix, items) {
1977
+ const layout = prefix.startsWith("/") ? SLASH_COMMAND_SELECT_LIST_LAYOUT : undefined;
1978
+ const list = new SelectList(items, this.autocompleteMaxVisible, this.theme.selectList, layout);
1979
+ list.onSelect = (selected) => {
1980
+ if (!this.autocompleteProvider)
1981
+ return;
1982
+ this.pushUndoSnapshot();
1983
+ this.lastAction = null;
1984
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
1985
+ this.state.lines = result.lines;
1986
+ this.state.cursorLine = result.cursorLine;
1987
+ this.setCursorCol(result.cursorCol);
1988
+ this.cancelAutocomplete();
1989
+ this.onChange?.(this.getText());
1990
+ };
1991
+ return list;
1992
+ }
1993
+ tryTriggerAutocomplete(explicitTab = false) {
1994
+ this.requestAutocomplete({ force: false, explicitTab });
1995
+ }
1996
+ handleTabCompletion() {
1997
+ if (!this.autocompleteProvider)
1998
+ return;
1999
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
2000
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
2001
+ if (this.isInSlashCommandContext(beforeCursor) && !beforeCursor.trimStart().includes(" ")) {
2002
+ this.handleSlashCommandCompletion();
2003
+ }
2004
+ else {
2005
+ this.forceFileAutocomplete(true);
2006
+ }
2007
+ }
2008
+ handleSlashCommandCompletion() {
2009
+ this.requestAutocomplete({ force: false, explicitTab: true });
2010
+ }
2011
+ forceFileAutocomplete(explicitTab = false) {
2012
+ this.requestAutocomplete({ force: true, explicitTab });
2013
+ }
2014
+ requestAutocomplete(options) {
2015
+ if (!this.autocompleteProvider)
2016
+ return;
2017
+ if (options.force) {
2018
+ const shouldTrigger = !this.autocompleteProvider.shouldTriggerFileCompletion ||
2019
+ this.autocompleteProvider.shouldTriggerFileCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol);
2020
+ if (!shouldTrigger) {
2021
+ return;
2022
+ }
2023
+ }
2024
+ this.cancelAutocompleteRequest();
2025
+ const startToken = ++this.autocompleteStartToken;
2026
+ const debounceMs = this.getAutocompleteDebounceMs(options);
2027
+ if (debounceMs > 0) {
2028
+ this.autocompleteDebounceTimer = setTimeout(() => {
2029
+ this.autocompleteDebounceTimer = undefined;
2030
+ void this.startAutocompleteRequest(startToken, options);
2031
+ }, debounceMs);
2032
+ return;
2033
+ }
2034
+ void this.startAutocompleteRequest(startToken, options);
2035
+ }
2036
+ async startAutocompleteRequest(startToken, options) {
2037
+ const previousTask = this.autocompleteRequestTask;
2038
+ this.autocompleteRequestTask = (async () => {
2039
+ await previousTask;
2040
+ if (startToken !== this.autocompleteStartToken || !this.autocompleteProvider) {
2041
+ return;
2042
+ }
2043
+ const controller = new AbortController();
2044
+ this.autocompleteAbort = controller;
2045
+ const requestId = ++this.autocompleteRequestId;
2046
+ const snapshotText = this.getText();
2047
+ const snapshotLine = this.state.cursorLine;
2048
+ const snapshotCol = this.state.cursorCol;
2049
+ await this.runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options);
2050
+ })();
2051
+ await this.autocompleteRequestTask;
2052
+ }
2053
+ setAutocompleteTriggerCharacters(triggerCharacters) {
2054
+ const next = [...DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS];
2055
+ for (const character of triggerCharacters) {
2056
+ if (character.length !== 1 || character === "/" || isWhitespaceChar(character) || next.includes(character)) {
2057
+ continue;
2058
+ }
2059
+ next.push(character);
2060
+ }
2061
+ this.autocompleteTriggerCharacters = next;
2062
+ this.autocompleteTriggerPattern = buildTriggerPattern(next);
2063
+ this.autocompleteDebouncePattern = buildDebouncePattern(next);
2064
+ }
2065
+ getAutocompleteDebounceMs(options) {
2066
+ if (options.explicitTab || options.force) {
2067
+ return 0;
2068
+ }
2069
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
2070
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
2071
+ return this.autocompleteDebouncePattern.test(textBeforeCursor) ? ATTACHMENT_AUTOCOMPLETE_DEBOUNCE_MS : 0;
2072
+ }
2073
+ async runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options) {
2074
+ if (!this.autocompleteProvider)
2075
+ return;
2076
+ const suggestions = await this.autocompleteProvider.getSuggestions(this.state.lines, this.state.cursorLine, this.state.cursorCol, { signal: controller.signal, force: options.force });
2077
+ if (!this.isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol)) {
2078
+ return;
2079
+ }
2080
+ this.autocompleteAbort = undefined;
2081
+ if (!suggestions || !Array.isArray(suggestions.items) || suggestions.items.length === 0) {
2082
+ this.cancelAutocomplete();
2083
+ this.tui.requestRender();
2084
+ return;
2085
+ }
2086
+ if (options.force && options.explicitTab && suggestions.items.length === 1) {
2087
+ const item = suggestions.items[0];
2088
+ this.pushUndoSnapshot();
2089
+ this.lastAction = null;
2090
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, item, suggestions.prefix);
2091
+ this.state.lines = result.lines;
2092
+ this.state.cursorLine = result.cursorLine;
2093
+ this.setCursorCol(result.cursorCol);
2094
+ if (this.onChange)
2095
+ this.onChange(this.getText());
2096
+ this.tui.requestRender();
2097
+ return;
2098
+ }
2099
+ this.applyAutocompleteSuggestions(suggestions, options.force ? "force" : "regular");
2100
+ this.tui.requestRender();
2101
+ }
2102
+ isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol) {
2103
+ return (!controller.signal.aborted &&
2104
+ requestId === this.autocompleteRequestId &&
2105
+ this.getText() === snapshotText &&
2106
+ this.state.cursorLine === snapshotLine &&
2107
+ this.state.cursorCol === snapshotCol);
2108
+ }
2109
+ applyAutocompleteSuggestions(suggestions, state) {
2110
+ this.autocompletePrefix = suggestions.prefix;
2111
+ this.autocompleteList = this.createAutocompleteList(suggestions.prefix, suggestions.items);
2112
+ const bestMatchIndex = this.getBestAutocompleteMatchIndex(suggestions.items, suggestions.prefix);
2113
+ if (bestMatchIndex >= 0) {
2114
+ this.autocompleteList.setSelectedIndex(bestMatchIndex);
2115
+ }
2116
+ this.autocompleteState = state;
2117
+ }
2118
+ cancelAutocompleteRequest() {
2119
+ this.autocompleteStartToken += 1;
2120
+ if (this.autocompleteDebounceTimer) {
2121
+ clearTimeout(this.autocompleteDebounceTimer);
2122
+ this.autocompleteDebounceTimer = undefined;
2123
+ }
2124
+ this.autocompleteAbort?.abort();
2125
+ this.autocompleteAbort = undefined;
2126
+ }
2127
+ clearAutocompleteUi() {
2128
+ this.autocompleteState = null;
2129
+ this.autocompleteList = undefined;
2130
+ this.autocompletePrefix = "";
2131
+ }
2132
+ cancelAutocomplete() {
2133
+ this.cancelAutocompleteRequest();
2134
+ this.clearAutocompleteUi();
2135
+ }
2136
+ isShowingAutocomplete() {
2137
+ return this.autocompleteState !== null;
2138
+ }
2139
+ updateAutocomplete() {
2140
+ if (!this.autocompleteState || !this.autocompleteProvider)
2141
+ return;
2142
+ this.requestAutocomplete({ force: this.autocompleteState === "force", explicitTab: false });
2143
+ }
2144
+ }