@timurproko/a1 0.1.8-dev.3b54f21 → 0.1.8-dev.407

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 (643) hide show
  1. package/README.md +159 -65
  2. package/bin/cli.js +28 -10
  3. package/bin/guardian.js +12 -6
  4. package/bin/module-identity.js +69 -35
  5. package/bin/pi-tui.d.ts +6 -0
  6. package/bin/pi-tui.js +28 -0
  7. package/bin/release-cleanup.js +8 -0
  8. package/bin/supervisor.js +2 -2
  9. package/bin/sync-pi-tui-proxy.js +97 -0
  10. package/bin/ui.js +62 -21
  11. package/bin/update-recovery.js +274 -0
  12. package/bin/warmup.js +27 -0
  13. package/dist/cli/capabilities.d.ts +6 -0
  14. package/dist/{src/cli → cli}/capabilities.js +1 -1
  15. package/dist/{src/cli → cli}/dispatch.d.ts +15 -1
  16. package/dist/cli/dispatch.js +261 -0
  17. package/dist/cli/package-messages.d.ts +26 -0
  18. package/dist/cli/package-messages.js +71 -0
  19. package/dist/{src/cli → cli}/packages.d.ts +11 -2
  20. package/dist/{src/cli → cli}/packages.js +24 -27
  21. package/dist/{src/cli → cli}/version-stats.d.ts +6 -0
  22. package/dist/cli/version-stats.js +112 -0
  23. package/dist/composition/agent-engine-bridge.d.ts +3 -0
  24. package/dist/composition/agent-engine-bridge.js +108 -0
  25. package/dist/composition/index.d.ts +3 -0
  26. package/dist/composition/index.js +3 -0
  27. package/dist/composition/owned-ui.d.ts +35 -0
  28. package/dist/composition/owned-ui.js +118 -0
  29. package/dist/composition/process.d.ts +16 -0
  30. package/dist/composition/process.js +45 -0
  31. package/dist/composition/settings-route-host.d.ts +8 -0
  32. package/dist/composition/settings-route-host.js +75 -0
  33. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/capability-ports.d.ts +2 -2
  34. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain-validation.js +22 -4
  35. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain.d.ts +17 -0
  36. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/package-ports.d.ts +6 -0
  37. package/dist/contracts/owned-ui/image-attachments.d.ts +36 -0
  38. package/dist/contracts/owned-ui/image-attachments.js +67 -0
  39. package/dist/contracts/owned-ui/index.d.ts +8 -0
  40. package/dist/contracts/owned-ui/index.js +8 -0
  41. package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/model.d.ts +123 -0
  42. package/dist/contracts/owned-ui/prompt-history.d.ts +55 -0
  43. package/dist/contracts/owned-ui/prompt-history.js +23 -0
  44. package/dist/contracts/owned-ui/prompt-suggestions.d.ts +3 -0
  45. package/dist/contracts/owned-ui/prompt-suggestions.js +44 -0
  46. package/dist/contracts/owned-ui/suggestion-diagnostics.d.ts +22 -0
  47. package/dist/contracts/owned-ui/suggestion-diagnostics.js +9 -0
  48. package/dist/contracts/owned-ui/transcript-lifecycle.d.ts +5 -0
  49. package/dist/contracts/owned-ui/transcript-lifecycle.js +33 -0
  50. package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/validation.d.ts +5 -1
  51. package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/validation.js +129 -4
  52. package/dist/{src/foundation/presentation-contracts → contracts/presentation}/index.d.ts +8 -0
  53. package/dist/{src/features → features}/launch/development-launch.js +11 -3
  54. package/dist/{src/features → features}/launch/index.d.ts +0 -1
  55. package/dist/{src/features → features}/launch/index.js +0 -1
  56. package/dist/features/launch/intent.d.ts +10 -0
  57. package/dist/features/launch/intent.js +8 -0
  58. package/dist/{src/features → features}/launch/prepare-launch.d.ts +0 -2
  59. package/dist/{src/features → features}/launch/prepare-launch.js +2 -9
  60. package/dist/{src/features → features}/launch/profile-paths.d.ts +3 -2
  61. package/dist/{src/features → features}/launch/profile-paths.js +13 -8
  62. package/dist/{src/features → features}/launch/runtime-selection.d.ts +2 -5
  63. package/dist/{src/features → features}/owned-ui/customization.d.ts +3 -1
  64. package/dist/{src/features → features}/owned-ui/customization.js +3 -1
  65. package/dist/{src/features → features}/owned-ui/diagnostics.d.ts +2 -1
  66. package/dist/{src/features → features}/owned-ui/diagnostics.js +1 -0
  67. package/dist/{src/features → features}/owned-ui/index.d.ts +2 -0
  68. package/dist/{src/features → features}/owned-ui/index.js +2 -0
  69. package/dist/features/owned-ui/project-trust-prompt.d.ts +25 -0
  70. package/dist/features/owned-ui/project-trust-prompt.js +149 -0
  71. package/dist/{src/features → features}/owned-ui/run.d.ts +2 -2
  72. package/dist/features/owned-ui/run.js +32 -0
  73. package/dist/features/owned-ui/session-fork-prompt.d.ts +8 -0
  74. package/dist/features/owned-ui/session-fork-prompt.js +34 -0
  75. package/dist/{src/features → features}/owned-ui/settings-app.d.ts +3 -3
  76. package/dist/{src/features → features}/owned-ui/settings-app.js +105 -56
  77. package/dist/features/prompt-history/image-sidecar.d.ts +32 -0
  78. package/dist/features/prompt-history/image-sidecar.js +130 -0
  79. package/dist/features/prompt-history/index.d.ts +4 -0
  80. package/dist/features/prompt-history/index.js +3 -0
  81. package/dist/features/prompt-history/paths.d.ts +5 -0
  82. package/dist/features/prompt-history/paths.js +17 -0
  83. package/dist/features/prompt-history/service.d.ts +54 -0
  84. package/dist/features/prompt-history/service.js +425 -0
  85. package/dist/features/prompt-history/store.d.ts +16 -0
  86. package/dist/features/prompt-history/store.js +223 -0
  87. package/dist/features/prompt-history/worker.d.ts +9 -0
  88. package/dist/features/prompt-history/worker.js +45 -0
  89. package/dist/features/prompt-suggestions/diagnostics.d.ts +18 -0
  90. package/dist/features/prompt-suggestions/diagnostics.js +82 -0
  91. package/dist/features/prompt-suggestions/index.d.ts +1 -0
  92. package/dist/features/prompt-suggestions/index.js +1 -0
  93. package/dist/{src/features → features}/workspace/capabilities.d.ts +1 -1
  94. package/dist/{src/features → features}/workspace/reducer.d.ts +2 -1
  95. package/dist/{src/features → features}/workspace/reducer.js +2 -1
  96. package/dist/{src/features → features}/workspace/router.d.ts +2 -1
  97. package/dist/{src/features → features}/workspace/router.js +1 -0
  98. package/dist/{src/features → features}/workspace/store.d.ts +2 -1
  99. package/dist/{src/features → features}/workspace/store.js +1 -0
  100. package/dist/foundation/launch-context/index.d.ts +59 -0
  101. package/dist/foundation/launch-context/index.js +136 -0
  102. package/dist/{src/foundation → foundation}/launch-guardian/main.d.ts +2 -0
  103. package/dist/{src/foundation → foundation}/launch-guardian/main.js +23 -8
  104. package/dist/{src/foundation → foundation}/lifecycle/index.d.ts +2 -0
  105. package/dist/{src/foundation → foundation}/lifecycle/index.js +2 -0
  106. package/dist/{src/foundation → foundation}/lifecycle/model.d.ts +1 -1
  107. package/dist/{src/foundation → foundation}/lifecycle/model.js +1 -1
  108. package/dist/foundation/lifecycle/paths.d.ts +30 -0
  109. package/dist/{src/foundation → foundation}/lifecycle/paths.js +29 -1
  110. package/dist/foundation/lifecycle/session-selection.d.ts +9 -0
  111. package/dist/foundation/lifecycle/session-selection.js +39 -0
  112. package/dist/foundation/lifecycle/supervisor-startup.d.ts +30 -0
  113. package/dist/foundation/lifecycle/supervisor-startup.js +106 -0
  114. package/dist/{src/foundation → foundation}/native-host-protocol/codec.d.ts +2 -0
  115. package/dist/{src/foundation → foundation}/native-host-protocol/codec.js +2 -0
  116. package/dist/{src/foundation → foundation}/native-host-protocol/messages.d.ts +1 -1
  117. package/dist/{src/foundation → foundation}/native-host-protocol/messages.js +1 -1
  118. package/dist/foundation/process-containment/darwin-process-inspector.d.ts +5 -0
  119. package/dist/foundation/process-containment/darwin-process-inspector.js +7 -0
  120. package/dist/{src/foundation → foundation}/process-containment/index.d.ts +1 -0
  121. package/dist/{src/foundation → foundation}/process-containment/index.js +1 -0
  122. package/dist/{src/foundation → foundation}/process-containment/linux-process-inspector.d.ts +1 -0
  123. package/dist/{src/foundation → foundation}/process-containment/linux-process-inspector.js +1 -0
  124. package/dist/{src/foundation → foundation}/process-containment/native-guardian-containment.d.ts +1 -0
  125. package/dist/{src/foundation → foundation}/process-containment/native-guardian-containment.js +1 -0
  126. package/dist/{src/foundation → foundation}/process-containment/windows-process-inspector.d.ts +3 -1
  127. package/dist/{src/foundation → foundation}/process-containment/windows-process-inspector.js +5 -2
  128. package/dist/{src/foundation → foundation}/protocol/client.d.ts +1 -0
  129. package/dist/{src/foundation → foundation}/protocol/client.js +1 -0
  130. package/dist/{src/foundation → foundation}/protocol/messages.d.ts +1 -0
  131. package/dist/{src/foundation → foundation}/protocol/messages.js +1 -0
  132. package/dist/foundation/release/bootstrap.d.ts +55 -0
  133. package/dist/{src/foundation → foundation}/release/bootstrap.js +219 -46
  134. package/dist/foundation/release/cohort-state.d.ts +157 -0
  135. package/dist/foundation/release/cohort-state.js +472 -0
  136. package/dist/foundation/release/dependency-certification-retention.d.ts +7 -0
  137. package/dist/foundation/release/dependency-certification-retention.js +88 -0
  138. package/dist/foundation/release/dependency-certification.d.ts +24 -0
  139. package/dist/foundation/release/dependency-certification.js +266 -0
  140. package/dist/foundation/release/dependency-layer.d.ts +81 -0
  141. package/dist/foundation/release/dependency-layer.js +466 -0
  142. package/dist/foundation/release/endpoints.d.ts +20 -0
  143. package/dist/foundation/release/endpoints.js +50 -0
  144. package/dist/foundation/release/immutable-platform.d.ts +6 -0
  145. package/dist/foundation/release/immutable-platform.js +13 -0
  146. package/dist/{src/foundation → foundation}/release/index.d.ts +6 -0
  147. package/dist/{src/foundation → foundation}/release/index.js +6 -0
  148. package/dist/foundation/release/release-gc.d.ts +71 -0
  149. package/dist/foundation/release/release-gc.js +764 -0
  150. package/dist/{src/foundation → foundation}/release/release-store.d.ts +9 -3
  151. package/dist/{src/foundation → foundation}/release/release-store.js +74 -14
  152. package/dist/{src/foundation → foundation}/release/release.d.ts +6 -1
  153. package/dist/{src/foundation → foundation}/release/release.js +15 -4
  154. package/dist/foundation/release/restart-certification.d.ts +68 -0
  155. package/dist/foundation/release/restart-certification.js +227 -0
  156. package/dist/foundation/release/update-launch.d.ts +6 -0
  157. package/dist/foundation/release/update-launch.js +17 -0
  158. package/dist/foundation/release/update-recovery.d.ts +76 -0
  159. package/dist/foundation/release/update-recovery.js +356 -0
  160. package/dist/{src/foundation → foundation}/release/update-transaction.d.ts +11 -0
  161. package/dist/{src/foundation → foundation}/release/update-transaction.js +13 -1
  162. package/dist/{src/foundation → foundation}/release/update.d.ts +40 -4
  163. package/dist/{src/foundation → foundation}/release/update.js +196 -78
  164. package/dist/foundation/release/warmup.d.ts +3 -0
  165. package/dist/foundation/release/warmup.js +47 -0
  166. package/dist/foundation/startup/index.d.ts +1 -0
  167. package/dist/foundation/startup/index.js +1 -0
  168. package/dist/foundation/startup/startup-runtime.d.ts +36 -0
  169. package/dist/foundation/startup/startup-runtime.js +142 -0
  170. package/dist/{src/foundation → foundation}/storage/control-store.d.ts +2 -1
  171. package/dist/{src/foundation → foundation}/storage/control-store.js +39 -4
  172. package/dist/{src/foundation → foundation}/structured-agent-runtime/backpressure.d.ts +2 -1
  173. package/dist/{src/foundation → foundation}/structured-agent-runtime/backpressure.js +2 -1
  174. package/dist/{src/foundation → foundation}/structured-agent-runtime/commands.d.ts +2 -1
  175. package/dist/{src/foundation → foundation}/structured-agent-runtime/commands.js +2 -1
  176. package/dist/{src/foundation → foundation}/structured-agent-runtime/handshake.d.ts +1 -1
  177. package/dist/{src/foundation → foundation}/structured-agent-runtime/handshake.js +1 -1
  178. package/dist/{src/foundation → foundation}/structured-agent-runtime/reconnection.d.ts +2 -1
  179. package/dist/{src/foundation → foundation}/structured-agent-runtime/reconnection.js +2 -1
  180. package/dist/{src/foundation → foundation}/structured-agent-runtime/state.d.ts +2 -1
  181. package/dist/{src/foundation → foundation}/structured-agent-runtime/state.js +2 -1
  182. package/dist/foundation/supervision/index.d.ts +3 -0
  183. package/dist/foundation/supervision/index.js +3 -0
  184. package/dist/foundation/supervision/main.d.ts +1 -0
  185. package/dist/foundation/supervision/main.js +84 -0
  186. package/dist/foundation/supervision/paths.d.ts +1 -0
  187. package/dist/foundation/supervision/paths.js +1 -0
  188. package/dist/foundation/supervision/server.d.ts +51 -0
  189. package/dist/{src/foundation → foundation}/supervision/server.js +142 -20
  190. package/dist/foundation/terminal-cleanup/fatal-exit.d.ts +12 -0
  191. package/dist/foundation/terminal-cleanup/fatal-exit.js +85 -0
  192. package/dist/foundation/terminal-cleanup/index.d.ts +2 -0
  193. package/dist/foundation/terminal-cleanup/index.js +2 -0
  194. package/dist/foundation/terminal-cleanup/terminal-reset.d.ts +4 -0
  195. package/dist/foundation/terminal-cleanup/terminal-reset.js +40 -0
  196. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/components.d.ts +1 -1
  197. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/conformance.d.ts +1 -0
  198. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/conformance.js +3 -2
  199. package/dist/integrations/pi/components/editor-interaction.d.ts +38 -0
  200. package/dist/integrations/pi/components/history-editor-loader.d.ts +5 -0
  201. package/dist/integrations/pi/components/history-editor-loader.js +5 -0
  202. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/index.d.ts +2 -1
  203. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/index.js +2 -1
  204. package/dist/integrations/pi/components/owned-editor-ux.d.ts +74 -0
  205. package/dist/integrations/pi/components/owned-editor-ux.js +1093 -0
  206. package/dist/integrations/pi/components/path-word-ranges.d.ts +2 -0
  207. package/dist/integrations/pi/components/path-word-ranges.js +37 -0
  208. package/dist/integrations/pi/components/prompt-input-port.d.ts +18 -0
  209. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-components.d.ts +1 -0
  210. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-components.js +1 -0
  211. package/dist/integrations/pi/components/shell-editor-autocomplete.js +297 -0
  212. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-extension-ui.d.ts +1 -1
  213. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-footer-status.d.ts +4 -4
  214. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-footer-status.js +58 -23
  215. package/dist/integrations/pi/components/shell-presenters-info.d.ts +43 -0
  216. package/dist/integrations/pi/components/shell-presenters-info.js +114 -0
  217. package/dist/integrations/pi/components/shell-presenters-transcript.d.ts +29 -0
  218. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-presenters-transcript.js +174 -170
  219. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-selectors-dialogs.d.ts +8 -4
  220. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-selectors-dialogs.js +10 -6
  221. package/dist/integrations/pi/components/shell-shared-facade.d.ts +213 -0
  222. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-shared-facade.js +5 -2
  223. package/dist/integrations/pi/components/submitted-prompt-adapter.d.ts +15 -0
  224. package/dist/integrations/pi/components/submitted-prompt-adapter.js +43 -0
  225. package/dist/integrations/pi/components/tool-image-presentation.d.ts +21 -0
  226. package/dist/integrations/pi/components/tool-image-presentation.js +86 -0
  227. package/dist/integrations/pi/components/tool-result-adapter.d.ts +6 -0
  228. package/dist/integrations/pi/components/tool-result-adapter.js +27 -0
  229. package/dist/integrations/pi/components/transcript-image-resolver.d.ts +7 -0
  230. package/dist/integrations/pi/components/transcript-image-resolver.js +19 -0
  231. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/adjacent/core/keybindings.d.ts +11 -2
  232. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/adjacent/core/keybindings.js +41 -3
  233. package/dist/integrations/pi/components/upstream/assets/earendil-image.json +12 -0
  234. package/dist/integrations/pi/components/upstream/components/earendil-announcement.js +42 -0
  235. package/dist/integrations/pi/components/upstream/components/owned-editor.d.ts +40 -0
  236. package/dist/integrations/pi/components/upstream/components/owned-editor.js +166 -0
  237. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/scoped-models-selector.d.ts +1 -1
  238. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/scoped-models-selector.js +3 -1
  239. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-footer.d.ts +3 -2
  240. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-footer.js +12 -7
  241. package/dist/integrations/pi/components/upstream/components/tool-execution.d.ts +61 -0
  242. package/dist/integrations/pi/components/upstream/components/tool-execution.js +344 -0
  243. package/dist/integrations/pi/components/upstream/history/editor-core.d.ts +280 -0
  244. package/dist/integrations/pi/components/upstream/history/editor-core.js +2062 -0
  245. package/dist/integrations/pi/components/upstream/history/kill-ring.d.ts +32 -0
  246. package/dist/integrations/pi/components/upstream/history/kill-ring.js +48 -0
  247. package/dist/integrations/pi/components/upstream/history/printable-key.d.ts +1 -0
  248. package/dist/integrations/pi/components/upstream/history/printable-key.js +40 -0
  249. package/dist/integrations/pi/components/upstream/history/text-helpers.d.ts +14 -0
  250. package/dist/integrations/pi/components/upstream/history/text-helpers.js +28 -0
  251. package/dist/integrations/pi/components/upstream/history/undo-stack.d.ts +22 -0
  252. package/dist/integrations/pi/components/upstream/history/undo-stack.js +36 -0
  253. package/dist/integrations/pi/components/upstream/history/word-navigation.d.ts +24 -0
  254. package/dist/integrations/pi/components/upstream/history/word-navigation.js +100 -0
  255. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/adapter.d.ts +74 -6
  256. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/adapter.js +1340 -228
  257. package/dist/integrations/pi/engine/changelog.d.ts +2 -0
  258. package/dist/integrations/pi/engine/changelog.js +63 -0
  259. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/conformance.d.ts +4 -2
  260. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/conformance.js +15 -5
  261. package/dist/integrations/pi/engine/http-dispatcher.d.ts +4 -0
  262. package/dist/integrations/pi/engine/http-dispatcher.js +25 -0
  263. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/index.d.ts +4 -0
  264. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/index.js +4 -0
  265. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/model-auth-integration.d.ts +2 -1
  266. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/model-auth-integration.js +1 -0
  267. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/package-integration.d.ts +1 -1
  268. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/package-integration.js +32 -26
  269. package/dist/integrations/pi/engine/pending-delivery.d.ts +30 -0
  270. package/dist/integrations/pi/engine/pending-delivery.js +158 -0
  271. package/dist/integrations/pi/engine/project-trust-preflight.d.ts +22 -0
  272. package/dist/integrations/pi/engine/project-trust-preflight.js +50 -0
  273. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/resource-extension-integration.d.ts +2 -1
  274. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/resource-extension-integration.js +1 -0
  275. package/dist/integrations/pi/engine/resources/changelog.json +12 -0
  276. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/runtime-integration.d.ts +19 -1
  277. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/runtime-integration.js +56 -5
  278. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/session-integration.d.ts +4 -2
  279. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/session-integration.js +19 -4
  280. package/dist/integrations/pi/engine/session-selection.d.ts +28 -0
  281. package/dist/integrations/pi/engine/session-selection.js +90 -0
  282. package/dist/integrations/pi/engine/settings-effects.d.ts +66 -0
  283. package/dist/integrations/pi/engine/settings-effects.js +249 -0
  284. package/dist/integrations/pi/engine/settings-integration.d.ts +43 -0
  285. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/settings-integration.js +102 -108
  286. package/dist/integrations/pi/engine/tool-rendering.d.ts +13 -0
  287. package/dist/integrations/pi/engine/tool-rendering.js +145 -0
  288. package/dist/integrations/pi/engine/transcript-image-assets.d.ts +11 -0
  289. package/dist/integrations/pi/engine/transcript-image-assets.js +86 -0
  290. package/dist/integrations/pi/engine/windows-filesystem-hygiene.d.ts +21 -0
  291. package/dist/integrations/pi/engine/windows-filesystem-hygiene.js +55 -0
  292. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflow-controllers.d.ts +3 -2
  293. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflow-controllers.js +1 -0
  294. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflows.d.ts +19 -2
  295. package/dist/integrations/pi/session-ui/clipboard-diagnostics.d.ts +16 -0
  296. package/dist/integrations/pi/session-ui/clipboard-diagnostics.js +65 -0
  297. package/dist/integrations/pi/session-ui/clipboard-image.d.ts +11 -0
  298. package/dist/integrations/pi/session-ui/clipboard-image.js +38 -0
  299. package/dist/integrations/pi/session-ui/editor-hyperlink-budget.d.ts +9 -0
  300. package/dist/integrations/pi/session-ui/editor-hyperlink-budget.js +23 -0
  301. package/dist/integrations/pi/session-ui/image-preparation-client.d.ts +20 -0
  302. package/dist/integrations/pi/session-ui/image-preparation-client.js +145 -0
  303. package/dist/integrations/pi/session-ui/image-preparation.d.ts +18 -0
  304. package/dist/integrations/pi/session-ui/image-preparation.js +126 -0
  305. package/dist/integrations/pi/session-ui/image-source.d.ts +13 -0
  306. package/dist/integrations/pi/session-ui/image-source.js +171 -0
  307. package/dist/integrations/pi/session-ui/image-worker.d.ts +17 -0
  308. package/dist/integrations/pi/session-ui/image-worker.js +23 -0
  309. package/dist/integrations/pi/session-ui/index.d.ts +5 -0
  310. package/dist/integrations/pi/session-ui/index.js +5 -0
  311. package/dist/integrations/pi/session-ui/paste-executor.d.ts +10 -0
  312. package/dist/integrations/pi/session-ui/paste-executor.js +232 -0
  313. package/dist/integrations/pi/session-ui/paste-helper.d.ts +1 -0
  314. package/dist/integrations/pi/session-ui/paste-helper.js +173 -0
  315. package/dist/integrations/pi/session-ui/paste-preparation-client.d.ts +16 -0
  316. package/dist/integrations/pi/session-ui/paste-preparation-client.js +159 -0
  317. package/dist/integrations/pi/session-ui/paste-protocol.d.ts +78 -0
  318. package/dist/integrations/pi/session-ui/paste-protocol.js +18 -0
  319. package/dist/integrations/pi/session-ui/paste-text-preparation.d.ts +20 -0
  320. package/dist/integrations/pi/session-ui/paste-text-preparation.js +134 -0
  321. package/dist/integrations/pi/session-ui/paste-text-worker.d.ts +1 -0
  322. package/dist/integrations/pi/session-ui/paste-text-worker.js +12 -0
  323. package/dist/integrations/pi/session-ui/path-chip-presentation.d.ts +7 -0
  324. package/dist/integrations/pi/session-ui/path-chip-presentation.js +24 -0
  325. package/dist/integrations/pi/session-ui/prompt-chips.d.ts +72 -0
  326. package/dist/integrations/pi/session-ui/prompt-chips.js +503 -0
  327. package/dist/integrations/pi/session-ui/prompt-history-controller.d.ts +36 -0
  328. package/dist/integrations/pi/session-ui/prompt-history-controller.js +170 -0
  329. package/dist/integrations/pi/session-ui/prompt-suggestion-controller.d.ts +35 -0
  330. package/dist/integrations/pi/session-ui/prompt-suggestion-controller.js +207 -0
  331. package/dist/integrations/pi/session-ui/response-copy-coordinator.d.ts +27 -0
  332. package/dist/integrations/pi/session-ui/response-copy-coordinator.js +189 -0
  333. package/dist/integrations/pi/session-ui/response-copy-helper.d.ts +1 -0
  334. package/dist/integrations/pi/session-ui/response-copy-helper.js +122 -0
  335. package/dist/integrations/pi/session-ui/response-copy-protocol.d.ts +56 -0
  336. package/dist/integrations/pi/session-ui/response-copy-protocol.js +5 -0
  337. package/dist/integrations/pi/session-ui/response-copy-transport.d.ts +31 -0
  338. package/dist/integrations/pi/session-ui/response-copy-transport.js +187 -0
  339. package/dist/integrations/pi/session-ui/route-host.d.ts +5 -0
  340. package/dist/integrations/pi/session-ui/route-host.js +1 -0
  341. package/dist/integrations/pi/session-ui/session-shell-root.d.ts +221 -0
  342. package/dist/integrations/pi/session-ui/session-shell-root.js +1305 -0
  343. package/dist/integrations/pi/session-ui/session-shell.d.ts +55 -0
  344. package/dist/integrations/pi/session-ui/session-shell.js +1792 -0
  345. package/dist/integrations/pi/session-ui/session-viewport-controller.d.ts +56 -0
  346. package/dist/integrations/pi/session-ui/session-viewport-controller.js +569 -0
  347. package/dist/integrations/pi/session-ui/stream-presentation-coalescer.d.ts +29 -0
  348. package/dist/integrations/pi/session-ui/stream-presentation-coalescer.js +79 -0
  349. package/dist/integrations/pi/session-ui/system-clipboard.d.ts +20 -0
  350. package/dist/integrations/pi/session-ui/system-clipboard.js +156 -0
  351. package/dist/integrations/pi/session-ui/text-paste.d.ts +5 -0
  352. package/dist/integrations/pi/session-ui/text-paste.js +16 -0
  353. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/adapter.d.ts +10 -1
  354. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/adapter.js +255 -11
  355. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/contracts.d.ts +32 -6
  356. package/dist/integrations/pi/tui-runtime/contracts.js +1 -0
  357. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.d.ts +81 -0
  358. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.js +424 -0
  359. package/dist/integrations/pi/tui-runtime/index.d.ts +7 -0
  360. package/dist/integrations/pi/tui-runtime/index.js +7 -0
  361. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.d.ts +39 -0
  362. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.js +139 -0
  363. package/dist/integrations/pi/tui-runtime/mouse-report-input.d.ts +13 -0
  364. package/dist/integrations/pi/tui-runtime/mouse-report-input.js +59 -0
  365. package/dist/integrations/pi/tui-runtime/overlay-geometry.d.ts +32 -0
  366. package/dist/integrations/pi/tui-runtime/overlay-geometry.js +159 -0
  367. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/presentation-adapter.d.ts +1 -1
  368. package/dist/native/darwin-arm64/manifest.json +4 -4
  369. package/dist/native/darwin-arm64/process-guardian +0 -0
  370. package/dist/native/linux-x64/manifest.json +3 -3
  371. package/dist/native/linux-x64/process-guardian +0 -0
  372. package/dist/native/win32-x64/manifest.json +3 -3
  373. package/dist/native/win32-x64/process-guardian.exe +0 -0
  374. package/dist/{src/product-identity.d.ts → product-identity.d.ts} +4 -4
  375. package/dist/{src/product-identity.js → product-identity.js} +7 -38
  376. package/dist/{src/product-identity.json → product-identity.json} +13 -27
  377. package/dist/runtime-payload-inventory.json +122333 -0
  378. package/dist/{src/foundation/ui-apps → ui/apps}/contracts.d.ts +23 -1
  379. package/dist/{src/foundation/ui-apps → ui/apps}/host.d.ts +1 -1
  380. package/dist/{src/foundation/ui-apps → ui/apps}/host.js +14 -10
  381. package/dist/{src/foundation/ui-apps → ui/apps}/registry.d.ts +1 -0
  382. package/dist/{src/foundation/ui-apps → ui/apps}/registry.js +1 -0
  383. package/dist/{src/foundation/ui-components → ui/components}/dialog-panel.js +5 -3
  384. package/dist/{src/foundation/ui-components → ui/components}/frame.d.ts +1 -0
  385. package/dist/{src/foundation/ui-components → ui/components}/frame.js +1 -0
  386. package/dist/{src/foundation/ui-components → ui/components}/index.d.ts +7 -0
  387. package/dist/{src/foundation/ui-components → ui/components}/index.js +7 -0
  388. package/dist/{src/foundation/ui-components → ui/components}/line-input.d.ts +2 -8
  389. package/dist/{src/foundation/ui-components → ui/components}/line-input.js +7 -28
  390. package/dist/{src/foundation/ui-components → ui/components}/list-view.d.ts +0 -6
  391. package/dist/{src/foundation/ui-components → ui/components}/list-view.js +14 -7
  392. package/dist/{src/foundation/ui-components → ui/components}/mouse.d.ts +10 -0
  393. package/dist/{src/foundation/ui-components → ui/components}/mouse.js +24 -0
  394. package/dist/ui/components/progress-status.d.ts +2 -0
  395. package/dist/ui/components/progress-status.js +4 -0
  396. package/dist/ui/components/prompt-input.d.ts +32 -0
  397. package/dist/ui/components/prompt-input.js +54 -0
  398. package/dist/ui/components/prompt-row.d.ts +14 -0
  399. package/dist/ui/components/prompt-row.js +20 -0
  400. package/dist/{src/foundation/ui-components → ui/components}/scrollbar.d.ts +26 -0
  401. package/dist/{src/foundation/ui-components → ui/components}/scrollbar.js +35 -0
  402. package/dist/ui/components/selection-copy.d.ts +24 -0
  403. package/dist/ui/components/selection-copy.js +39 -0
  404. package/dist/{src/foundation/ui-components → ui/components}/shortcuts.d.ts +1 -0
  405. package/dist/{src/foundation/ui-components → ui/components}/shortcuts.js +1 -0
  406. package/dist/ui/components/spans.d.ts +28 -0
  407. package/dist/ui/components/spans.js +266 -0
  408. package/dist/ui/components/submitted-prompt.d.ts +23 -0
  409. package/dist/ui/components/submitted-prompt.js +50 -0
  410. package/dist/{src/foundation/ui-components → ui/components}/surface.d.ts +0 -5
  411. package/dist/{src/foundation/ui-components → ui/components}/surface.js +1 -5
  412. package/dist/ui/components/text-selection.d.ts +62 -0
  413. package/dist/ui/components/text-selection.js +210 -0
  414. package/dist/{src/foundation/ui-components → ui/components}/text.d.ts +14 -0
  415. package/dist/{src/foundation/ui-components → ui/components}/text.js +67 -5
  416. package/dist/ui/components/transcript-viewport.d.ts +173 -0
  417. package/dist/ui/components/transcript-viewport.js +753 -0
  418. package/dist/ui/components/visible-hyperlinks.d.ts +26 -0
  419. package/dist/ui/components/visible-hyperlinks.js +97 -0
  420. package/dist/{src/foundation/owned-ui-settings → ui/settings}/declarations.d.ts +8 -1
  421. package/dist/ui/settings/declarations.js +94 -0
  422. package/dist/{src/foundation/owned-ui-settings → ui/settings}/migrations.d.ts +1 -1
  423. package/dist/{src/foundation/owned-ui-settings → ui/settings}/migrations.js +28 -2
  424. package/dist/{src/foundation/owned-ui-settings → ui/settings}/sections.d.ts +6 -19
  425. package/dist/{src/foundation/owned-ui-settings → ui/settings}/sections.js +41 -22
  426. package/dist/{src/foundation/owned-ui-settings → ui/settings}/session.d.ts +9 -17
  427. package/dist/ui/settings/session.js +164 -0
  428. package/dist/{src/foundation/owned-ui-settings → ui/settings}/store.d.ts +1 -0
  429. package/dist/{src/foundation/owned-ui-settings → ui/settings}/store.js +2 -1
  430. package/docs/architecture/boundaries.md +14 -10
  431. package/docs/architecture/code-documentation.md +77 -0
  432. package/docs/architecture/history-editor-provenance.md +100 -0
  433. package/docs/architecture/internal-naming.md +91 -0
  434. package/docs/architecture/process-guardian-provenance.md +3 -1
  435. package/docs/architecture/project-structure.md +69 -30
  436. package/docs/architecture/prompt-suggestions.md +68 -0
  437. package/docs/architecture/resource-and-data-policy.md +28 -2
  438. package/docs/architecture/response-copy-delivery.md +83 -0
  439. package/docs/architecture/tool-image-presentation.md +62 -0
  440. package/docs/architecture/toolchain.md +24 -10
  441. package/docs/architecture/ui-reference-provenance.md +59 -5
  442. package/docs/ci-release-runbook.md +236 -79
  443. package/docs/features/launch-profiles.md +24 -17
  444. package/docs/features/modal-content-interaction.md +37 -0
  445. package/docs/features/prompt-history.md +149 -0
  446. package/docs/local-worktree-cleanup.md +128 -0
  447. package/docs/manual-code-streaming-cleanup.md +88 -0
  448. package/docs/manual-ghost-link-baseline.md +89 -0
  449. package/docs/manual-launch-instance-acceptance.md +12 -35
  450. package/docs/manual-owned-ui-checkpoint.md +78 -0
  451. package/docs/manual-pi-boundary-candidate.md +4 -5
  452. package/docs/manual-terminal-colour-check.md +4 -3
  453. package/docs/openspec-archive-automation.md +128 -0
  454. package/docs/repository-governance-live-acceptance.md +77 -0
  455. package/package.json +45 -28
  456. package/dist/src/cli/capabilities.d.ts +0 -15
  457. package/dist/src/cli/dispatch.js +0 -142
  458. package/dist/src/cli/version-stats.js +0 -72
  459. package/dist/src/composition/index.d.ts +0 -48
  460. package/dist/src/composition/index.js +0 -258
  461. package/dist/src/features/launch/intent.d.ts +0 -7
  462. package/dist/src/features/launch/intent.js +0 -4
  463. package/dist/src/features/launch/profiles.d.ts +0 -12
  464. package/dist/src/features/launch/profiles.js +0 -26
  465. package/dist/src/features/owned-ui/run.js +0 -15
  466. package/dist/src/foundation/lifecycle/paths.d.ts +0 -10
  467. package/dist/src/foundation/owned-ui-contracts/index.d.ts +0 -3
  468. package/dist/src/foundation/owned-ui-contracts/index.js +0 -3
  469. package/dist/src/foundation/owned-ui-settings/declarations.js +0 -39
  470. package/dist/src/foundation/owned-ui-settings/session.js +0 -145
  471. package/dist/src/foundation/pi-component-adapter/shell-editor-autocomplete.js +0 -162
  472. package/dist/src/foundation/pi-component-adapter/shell-presenters-transcript.d.ts +0 -57
  473. package/dist/src/foundation/pi-component-adapter/shell-shared-facade.d.ts +0 -116
  474. package/dist/src/foundation/pi-component-adapter/upstream/components/earendil-announcement.js +0 -19
  475. package/dist/src/foundation/pi-component-adapter/upstream/components/owned-editor.d.ts +0 -18
  476. package/dist/src/foundation/pi-component-adapter/upstream/components/owned-editor.js +0 -55
  477. package/dist/src/foundation/pi-engine-adapter/settings-integration.d.ts +0 -55
  478. package/dist/src/foundation/pi-owned-ui-integration/index.d.ts +0 -2
  479. package/dist/src/foundation/pi-owned-ui-integration/index.js +0 -2
  480. package/dist/src/foundation/pi-owned-ui-integration/route-host.d.ts +0 -29
  481. package/dist/src/foundation/pi-owned-ui-integration/session-shell.d.ts +0 -106
  482. package/dist/src/foundation/pi-owned-ui-integration/session-shell.js +0 -1518
  483. package/dist/src/foundation/pi-tui-runtime-adapter/index.d.ts +0 -4
  484. package/dist/src/foundation/pi-tui-runtime-adapter/index.js +0 -4
  485. package/dist/src/foundation/release/bootstrap.d.ts +0 -29
  486. package/dist/src/foundation/release/cohort-state.d.ts +0 -70
  487. package/dist/src/foundation/release/cohort-state.js +0 -202
  488. package/dist/src/foundation/release/release-gc.d.ts +0 -5
  489. package/dist/src/foundation/release/release-gc.js +0 -16
  490. package/dist/src/foundation/supervision/index.d.ts +0 -3
  491. package/dist/src/foundation/supervision/index.js +0 -3
  492. package/dist/src/foundation/supervision/main.d.ts +0 -1
  493. package/dist/src/foundation/supervision/main.js +0 -41
  494. package/dist/src/foundation/supervision/paths.d.ts +0 -1
  495. package/dist/src/foundation/supervision/paths.js +0 -1
  496. package/dist/src/foundation/supervision/server.d.ts +0 -22
  497. package/dist/src/foundation/ui-components/spans.d.ts +0 -7
  498. package/dist/src/foundation/ui-components/spans.js +0 -59
  499. package/docs/manual-transparent-checkpoint.md +0 -53
  500. /package/dist/{src/cli → cli}/index.d.ts +0 -0
  501. /package/dist/{src/cli → cli}/index.js +0 -0
  502. /package/dist/{src/cli → cli}/version.d.ts +0 -0
  503. /package/dist/{src/cli → cli}/version.js +0 -0
  504. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/capability-ports.js +0 -0
  505. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain-validation.d.ts +0 -0
  506. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain.js +0 -0
  507. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/index.d.ts +0 -0
  508. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/index.js +0 -0
  509. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.d.ts +0 -0
  510. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.js +0 -0
  511. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/package-ports.js +0 -0
  512. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/ports.d.ts +0 -0
  513. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/ports.js +0 -0
  514. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.d.ts +0 -0
  515. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.js +0 -0
  516. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.d.ts +0 -0
  517. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.js +0 -0
  518. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/extension-ui.d.ts +0 -0
  519. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/extension-ui.js +0 -0
  520. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/model.js +0 -0
  521. /package/dist/{src/foundation/presentation-contracts → contracts/presentation}/index.js +0 -0
  522. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/index.d.ts +0 -0
  523. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/index.js +0 -0
  524. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/model.d.ts +0 -0
  525. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/model.js +0 -0
  526. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/validation.d.ts +0 -0
  527. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/validation.js +0 -0
  528. /package/dist/{src/features → features}/launch/development-launch.d.ts +0 -0
  529. /package/dist/{src/features → features}/launch/initialize-profile.d.ts +0 -0
  530. /package/dist/{src/features → features}/launch/initialize-profile.js +0 -0
  531. /package/dist/{src/features → features}/launch/runtime-selection.js +0 -0
  532. /package/dist/{src/features → features}/workspace/capabilities.js +0 -0
  533. /package/dist/{src/features → features}/workspace/index.d.ts +0 -0
  534. /package/dist/{src/features → features}/workspace/index.js +0 -0
  535. /package/dist/{src/features → features}/workspace/presentation.d.ts +0 -0
  536. /package/dist/{src/features → features}/workspace/presentation.js +0 -0
  537. /package/dist/{src/features → features}/workspace/reconciliation.d.ts +0 -0
  538. /package/dist/{src/features → features}/workspace/reconciliation.js +0 -0
  539. /package/dist/{src/foundation → foundation}/launch-guardian/index.d.ts +0 -0
  540. /package/dist/{src/foundation → foundation}/launch-guardian/index.js +0 -0
  541. /package/dist/{src/foundation → foundation}/lifecycle/commands.d.ts +0 -0
  542. /package/dist/{src/foundation → foundation}/lifecycle/commands.js +0 -0
  543. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.d.ts +0 -0
  544. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.js +0 -0
  545. /package/dist/{src/foundation → foundation}/native-host-protocol/evidence.d.ts +0 -0
  546. /package/dist/{src/foundation → foundation}/native-host-protocol/evidence.js +0 -0
  547. /package/dist/{src/foundation → foundation}/native-host-protocol/index.d.ts +0 -0
  548. /package/dist/{src/foundation → foundation}/native-host-protocol/index.js +0 -0
  549. /package/dist/{src/foundation → foundation}/native-host-protocol/proof-gate.d.ts +0 -0
  550. /package/dist/{src/foundation → foundation}/native-host-protocol/proof-gate.js +0 -0
  551. /package/dist/{src/foundation → foundation}/process-containment/artifact.d.ts +0 -0
  552. /package/dist/{src/foundation → foundation}/process-containment/artifact.js +0 -0
  553. /package/dist/{src/foundation → foundation}/process-containment/contracts.d.ts +0 -0
  554. /package/dist/{src/foundation → foundation}/process-containment/contracts.js +0 -0
  555. /package/dist/{src/foundation → foundation}/protocol/index.d.ts +0 -0
  556. /package/dist/{src/foundation → foundation}/protocol/index.js +0 -0
  557. /package/dist/{src/foundation → foundation}/release/cohort-selection.d.ts +0 -0
  558. /package/dist/{src/foundation → foundation}/release/cohort-selection.js +0 -0
  559. /package/dist/{src/foundation → foundation}/release/concurrency.d.ts +0 -0
  560. /package/dist/{src/foundation → foundation}/release/concurrency.js +0 -0
  561. /package/dist/{src/foundation → foundation}/release/process-cleanup.d.ts +0 -0
  562. /package/dist/{src/foundation → foundation}/release/process-cleanup.js +0 -0
  563. /package/dist/{src/foundation → foundation}/release/stable-release.d.ts +0 -0
  564. /package/dist/{src/foundation → foundation}/release/stable-release.js +0 -0
  565. /package/dist/{src/foundation → foundation}/storage/index.d.ts +0 -0
  566. /package/dist/{src/foundation → foundation}/storage/index.js +0 -0
  567. /package/dist/{src/foundation → foundation}/structured-agent-runtime/index.d.ts +0 -0
  568. /package/dist/{src/foundation → foundation}/structured-agent-runtime/index.js +0 -0
  569. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/components.js +0 -0
  570. /package/dist/{src/foundation/pi-owned-ui-integration/route-host.js → integrations/pi/components/editor-interaction.js} +0 -0
  571. /package/dist/{src/foundation/pi-tui-runtime-adapter/contracts.js → integrations/pi/components/prompt-input-port.js} +0 -0
  572. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/resources/builtin-themes.d.ts +0 -0
  573. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/resources/builtin-themes.js +0 -0
  574. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-editor-autocomplete.d.ts +0 -0
  575. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-extension-ui.js +0 -0
  576. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.d.ts +0 -0
  577. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.js +0 -0
  578. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/countdown-timer.d.ts +0 -0
  579. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/countdown-timer.js +0 -0
  580. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/custom-entry.d.ts +0 -0
  581. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/custom-entry.js +0 -0
  582. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/daxnuts.d.ts +0 -0
  583. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/daxnuts.js +0 -0
  584. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/earendil-announcement.d.ts +0 -0
  585. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/extension-editor.d.ts +0 -0
  586. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/extension-editor.js +0 -0
  587. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/first-time-setup.d.ts +0 -0
  588. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/first-time-setup.js +0 -0
  589. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/markdown-transform.d.ts +0 -0
  590. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/markdown-transform.js +0 -0
  591. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/mermaid.d.ts +0 -0
  592. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/mermaid.js +0 -0
  593. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector-search.d.ts +0 -0
  594. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector-search.js +0 -0
  595. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector.d.ts +0 -0
  596. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector.js +0 -0
  597. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/skill-invocation-message.d.ts +0 -0
  598. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/skill-invocation-message.js +0 -0
  599. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/status-indicator.d.ts +0 -0
  600. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/status-indicator.js +0 -0
  601. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/tree-selector.d.ts +0 -0
  602. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/tree-selector.js +0 -0
  603. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/trust-selector.d.ts +0 -0
  604. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/trust-selector.js +0 -0
  605. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/external-editor.d.ts +0 -0
  606. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/external-editor.js +0 -0
  607. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/model-search.d.ts +0 -0
  608. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/model-search.js +0 -0
  609. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme-controller.d.ts +0 -0
  610. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme-controller.js +0 -0
  611. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme.d.ts +0 -0
  612. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme.js +0 -0
  613. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/pi-settings-metadata.json +0 -0
  614. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.d.ts +0 -0
  615. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.js +0 -0
  616. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflows.js +0 -0
  617. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/conformance.d.ts +0 -0
  618. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/conformance.js +0 -0
  619. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/presentation-adapter.js +0 -0
  620. /package/dist/{src/foundation/ui-apps → ui/apps}/contracts.js +0 -0
  621. /package/dist/{src/foundation/ui-apps → ui/apps}/index.d.ts +0 -0
  622. /package/dist/{src/foundation/ui-apps → ui/apps}/index.js +0 -0
  623. /package/dist/{src/foundation/ui-components → ui/components}/dialog-panel.d.ts +0 -0
  624. /package/dist/{src/foundation/ui-components → ui/components}/label.d.ts +0 -0
  625. /package/dist/{src/foundation/ui-components → ui/components}/label.js +0 -0
  626. /package/dist/{src/foundation/ui-components → ui/components}/list-block.d.ts +0 -0
  627. /package/dist/{src/foundation/ui-components → ui/components}/list-block.js +0 -0
  628. /package/dist/{src/foundation/ui-components → ui/components}/pane.d.ts +0 -0
  629. /package/dist/{src/foundation/ui-components → ui/components}/pane.js +0 -0
  630. /package/dist/{src/foundation/ui-components → ui/components}/revision.d.ts +0 -0
  631. /package/dist/{src/foundation/ui-components → ui/components}/revision.js +0 -0
  632. /package/dist/{src/foundation/ui-components → ui/components}/status-line.d.ts +0 -0
  633. /package/dist/{src/foundation/ui-components → ui/components}/status-line.js +0 -0
  634. /package/dist/{src/foundation/ui-components → ui/components}/stepper.d.ts +0 -0
  635. /package/dist/{src/foundation/ui-components → ui/components}/stepper.js +0 -0
  636. /package/dist/{src/foundation/ui-components → ui/components}/theme.d.ts +0 -0
  637. /package/dist/{src/foundation/ui-components → ui/components}/theme.js +0 -0
  638. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.d.ts +0 -0
  639. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.js +0 -0
  640. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/index.d.ts +0 -0
  641. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/index.js +0 -0
  642. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.d.ts +0 -0
  643. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.js +0 -0
@@ -0,0 +1,1093 @@
1
+ import { ImageAttachmentError, MAX_CLIPBOARD_TEXT_BYTES } from "../../../contracts/owned-ui/index.js";
2
+ import { CURSOR_MARKER, decodeKittyPrintable, visibleWidth, } from "#pi-tui";
3
+ import { promptPathWordRanges } from "./path-word-ranges.js";
4
+ export class OwnedEditorUxInterception {
5
+ interceptors;
6
+ fallback;
7
+ constructor(interceptors, fallback) {
8
+ this.interceptors = interceptors;
9
+ this.fallback = fallback;
10
+ }
11
+ handleInput(data) {
12
+ const invoke = (index, input) => {
13
+ const interceptor = this.interceptors[index];
14
+ if (interceptor === undefined) {
15
+ this.fallback.handleInput(input);
16
+ return;
17
+ }
18
+ interceptor.handleInput(input, (replacement = input) => invoke(index + 1, replacement));
19
+ };
20
+ invoke(0, data);
21
+ }
22
+ render(width) {
23
+ const invoke = (index) => {
24
+ const interceptor = this.interceptors[index];
25
+ return interceptor === undefined
26
+ ? this.fallback.render(width)
27
+ : interceptor.render(width, () => invoke(index + 1));
28
+ };
29
+ return invoke(0);
30
+ }
31
+ reset() {
32
+ for (const interceptor of this.interceptors)
33
+ interceptor.reset();
34
+ }
35
+ cancelPendingPastes() {
36
+ for (const interceptor of this.interceptors)
37
+ interceptor.cancelPendingPastes?.();
38
+ }
39
+ handlePointer(event) {
40
+ return this.interceptors.some(interceptor => interceptor.handlePointer?.(event) === true);
41
+ }
42
+ hasSelection() {
43
+ return this.interceptors.some(interceptor => interceptor.hasSelection?.() === true);
44
+ }
45
+ ownsPointer() {
46
+ return this.interceptors.some(interceptor => interceptor.ownsPointer?.() === true);
47
+ }
48
+ pasteClipboard() {
49
+ return this.interceptors.some(interceptor => interceptor.pasteClipboard?.() === true);
50
+ }
51
+ }
52
+ const ATOMIC_SEGMENTATION = Symbol("a1.editor.atomicSegmentation");
53
+ const ATOMIC_SPACE_SENTINEL = "\uE000";
54
+ const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: "grapheme" });
55
+ const MULTI_CLICK_MS = 500;
56
+ export function createPromptSelectionInterceptor(editor, keybindings, options) {
57
+ return new PromptSelectionInterceptor(editor, keybindings, options);
58
+ }
59
+ class PromptSelectionInterceptor {
60
+ editor;
61
+ keybindings;
62
+ options;
63
+ #selection;
64
+ #pointerSelecting = false;
65
+ #lastClick;
66
+ #redoStack = [];
67
+ #selectionRevision = 0;
68
+ #pasteGeneration = 0;
69
+ #terminalPaste;
70
+ #wordDirection;
71
+ #geometry;
72
+ constructor(editor, keybindings, options) {
73
+ this.editor = editor;
74
+ this.keybindings = keybindings;
75
+ this.options = options;
76
+ installAtomicSegmentation(editor, options.atomicRanges, () => this.#wordDirection);
77
+ }
78
+ handleInput(data, next) {
79
+ if (this.#handleTerminalPaste(data, next))
80
+ return;
81
+ if (this.keybindings.matches(data, "owned.editor.selectAll")) {
82
+ this.#selectAll();
83
+ return;
84
+ }
85
+ if (this.keybindings.matches(data, "owned.editor.extendLeft")) {
86
+ this.#extend(-1);
87
+ return;
88
+ }
89
+ if (this.keybindings.matches(data, "owned.editor.extendRight")) {
90
+ this.#extend(1);
91
+ return;
92
+ }
93
+ if (this.keybindings.matches(data, "tui.input.copy") && this.hasSelection()) {
94
+ this.options.copyText(this.options.expandCopiedText(this.#selectedText()));
95
+ this.#collapseCopiedSelection();
96
+ return;
97
+ }
98
+ if (this.keybindings.matches(data, "owned.editor.cut") && this.hasSelection()) {
99
+ this.options.copyText(this.options.expandCopiedText(this.#selectedText()));
100
+ if (!this.#deleteSelection())
101
+ this.#deleteAtomicFocus();
102
+ return;
103
+ }
104
+ if (this.keybindings.matches(data, "owned.editor.paste")) {
105
+ this.pasteClipboard();
106
+ return;
107
+ }
108
+ if (this.keybindings.matches(data, "owned.editor.redo")) {
109
+ this.#redo();
110
+ return;
111
+ }
112
+ if (this.keybindings.matches(data, "tui.editor.undo")) {
113
+ const before = this.#snapshot();
114
+ this.#clearSelection(false);
115
+ next();
116
+ if (!sameSnapshot(before, this.#snapshot()))
117
+ this.#redoStack.push(before);
118
+ this.#requestRender();
119
+ return;
120
+ }
121
+ const selection = this.#orderedSelection();
122
+ if (selection !== undefined) {
123
+ if (this.keybindings.matches(data, "tui.editor.deleteCharBackward")
124
+ || this.keybindings.matches(data, "tui.editor.deleteCharForward")
125
+ || this.keybindings.matches(data, "tui.editor.deleteWordBackward")
126
+ || this.keybindings.matches(data, "tui.editor.deleteWordForward")) {
127
+ this.#deleteSelection();
128
+ return;
129
+ }
130
+ const inserted = insertedText(data);
131
+ if (inserted !== undefined) {
132
+ this.#replaceSelection(inserted);
133
+ return;
134
+ }
135
+ if (data.includes("\u001b[200~")) {
136
+ this.#deleteSelection();
137
+ next();
138
+ return;
139
+ }
140
+ if (this.keybindings.matches(data, "tui.editor.cursorLeft")
141
+ || this.keybindings.matches(data, "tui.editor.cursorWordLeft")) {
142
+ this.#setCursor(selection.start);
143
+ this.#clearSelection();
144
+ return;
145
+ }
146
+ if (this.keybindings.matches(data, "tui.editor.cursorRight")
147
+ || this.keybindings.matches(data, "tui.editor.cursorWordRight")) {
148
+ this.#setCursor(selection.end);
149
+ this.#clearSelection();
150
+ return;
151
+ }
152
+ this.#clearSelection(false);
153
+ }
154
+ else if ((this.keybindings.matches(data, "tui.editor.deleteCharBackward")
155
+ || this.keybindings.matches(data, "tui.editor.deleteCharForward")
156
+ || this.keybindings.matches(data, "tui.editor.deleteWordBackward")
157
+ || this.keybindings.matches(data, "tui.editor.deleteWordForward"))
158
+ && this.#deleteAtomicFocus()) {
159
+ return;
160
+ }
161
+ if (this.keybindings.matches(data, "tui.editor.cursorWordLeft")) {
162
+ const before = this.#cursor();
163
+ const startedWithAtomicFocus = this.#atomicFocus() !== undefined;
164
+ this.#delegateWord(-1, next);
165
+ let after = this.#cursor();
166
+ const landedAtomic = this.#atomicRangeAt(after);
167
+ if (!startedWithAtomicFocus && landedAtomic?.start === after.col && after.col > 0) {
168
+ const line = editorState(this.editor).lines[after.line] ?? "";
169
+ const previous = [...GRAPHEMES.segment(line.slice(0, after.col))].at(-1);
170
+ if (previous !== undefined && !/^\s+$/u.test(previous.segment)) {
171
+ this.#delegateWord(-1, next);
172
+ after = this.#cursor();
173
+ }
174
+ }
175
+ const line = editorState(this.editor).lines[after.line] ?? "";
176
+ const landedPath = promptPathWordRanges(line).some(range => range.start === after.col);
177
+ if (!samePosition(before, after) && !landedPath)
178
+ this.#moveOntoPreviousSeparator();
179
+ this.#requestRender();
180
+ return;
181
+ }
182
+ const beforeText = this.editor.getText();
183
+ const wordDirection = this.#wordDirectionFor(data);
184
+ if (wordDirection === undefined)
185
+ next();
186
+ else
187
+ this.#delegateWord(wordDirection, next);
188
+ if (this.editor.getText() !== beforeText)
189
+ this.#redoStack = [];
190
+ }
191
+ render(width, next) {
192
+ const state = editorState(this.editor);
193
+ const hidden = state.lines.map(line => this.options.hiddenRanges?.(line) ?? []);
194
+ if (!hidden.some(ranges => ranges.length > 0))
195
+ return this.#renderVisible(width, next);
196
+ const original = { ...state, lines: [...state.lines] };
197
+ const selection = this.#selection;
198
+ const project = (position) => ({
199
+ line: position.line,
200
+ col: hideColumn(position.col, hidden[position.line] ?? []),
201
+ });
202
+ const lines = state.lines.map((line, index) => {
203
+ for (const range of [...(hidden[index] ?? [])].reverse())
204
+ line = line.slice(0, range.start) + line.slice(range.end);
205
+ return line;
206
+ });
207
+ // Rationale: project pending clipboard identities out before layout, not after painting.
208
+ // Keep the semantic draft/undo/submission markers intact and restore them even if rendering throws.
209
+ try {
210
+ this.#setRenderState(lines, project({ line: original.cursorLine, col: original.cursorCol }));
211
+ if (selection !== undefined)
212
+ this.#selection = { anchor: project(selection.anchor), head: project(selection.head) };
213
+ const rows = this.#renderVisible(width, next);
214
+ if (this.#geometry !== undefined) {
215
+ this.#geometry.hiddenRanges = hidden;
216
+ this.#geometry.lines = lines;
217
+ }
218
+ return rows;
219
+ }
220
+ finally {
221
+ this.#setRenderState(original.lines, { line: original.cursorLine, col: original.cursorCol });
222
+ this.#selection = selection;
223
+ }
224
+ }
225
+ #setRenderState(lines, cursor) {
226
+ if (this.editor.interaction !== undefined)
227
+ this.editor.interaction.replaceLines(lines);
228
+ else
229
+ editorState(this.editor).lines = lines;
230
+ this.#setCursor(cursor);
231
+ }
232
+ #renderVisible(width, next) {
233
+ const rows = next().map(row => row.replaceAll(ATOMIC_SPACE_SENTINEL, " "));
234
+ const shared = this.options.promptGeometry?.(width, this.editor.getPaddingX());
235
+ const padding = shared?.paddingX ?? Math.min(this.editor.getPaddingX(), Math.max(0, Math.floor((width - 1) / 2)));
236
+ const prefixWidth = shared?.prefixWidth ?? 0;
237
+ const contentWidth = shared?.contentWidth ?? Math.max(1, width - padding * 2);
238
+ const layoutWidth = shared?.layoutWidth ?? Math.max(1, contentWidth - (padding ? 0 : 1));
239
+ const visualLines = editorVisualLineMap(this.editor, layoutWidth)
240
+ ?? buildVisualLineMap(editorState(this.editor).lines, layoutWidth);
241
+ const scrollOffset = this.editor.interaction?.scrollOffset() ?? numericProperty(this.editor, "scrollOffset");
242
+ const maxVisibleLines = Math.max(5, Math.floor(this.options.getRows() * 0.3));
243
+ const textRows = Math.max(0, Math.min(visualLines.length - scrollOffset, maxVisibleLines, rows.length - 2));
244
+ this.#geometry = { width, padding, prefixWidth, layoutWidth, visualLines, scrollOffset, textRows, hiddenRanges: [] };
245
+ if (this.#atomicFocus() !== undefined) {
246
+ for (let row = 0; row < rows.length; row += 1) {
247
+ rows[row] = (rows[row] ?? "").replaceAll(CURSOR_MARKER, "");
248
+ }
249
+ }
250
+ const selection = this.#orderedSelection();
251
+ if (selection !== undefined) {
252
+ for (let row = 0; row < textRows; row += 1) {
253
+ const visual = visualLines[scrollOffset + row];
254
+ if (visual === undefined || visual.logicalLine < selection.start.line || visual.logicalLine > selection.end.line)
255
+ continue;
256
+ const segmentStart = visual.startCol;
257
+ const segmentEnd = visual.startCol + visual.length;
258
+ const from = visual.logicalLine === selection.start.line ? Math.max(selection.start.col, segmentStart) : segmentStart;
259
+ const to = visual.logicalLine === selection.end.line ? Math.min(selection.end.col, segmentEnd) : segmentEnd;
260
+ if (to <= from)
261
+ continue;
262
+ const line = editorState(this.editor).lines[visual.logicalLine] ?? "";
263
+ const fromColumn = prefixWidth + padding + visibleWidth(line.slice(segmentStart, from));
264
+ const toColumn = fromColumn + visibleWidth(line.slice(from, to));
265
+ const rendered = rows[row + 1];
266
+ if (rendered !== undefined && toColumn > fromColumn) {
267
+ rows[row + 1] = this.options.paintSelection(rendered, fromColumn, toColumn, false);
268
+ }
269
+ }
270
+ }
271
+ return rows.map((row, index) => this.options.decorateRow(row, width, index));
272
+ }
273
+ reset() {
274
+ this.#selection = undefined;
275
+ this.#pointerSelecting = false;
276
+ this.#lastClick = undefined;
277
+ this.#redoStack = [];
278
+ this.#selectionRevision += 1;
279
+ }
280
+ cancelPendingPastes() {
281
+ this.#pasteGeneration += 1;
282
+ this.#terminalPaste = undefined;
283
+ }
284
+ hasSelection() {
285
+ return this.#activeRange() !== undefined;
286
+ }
287
+ pasteClipboard() {
288
+ this.#pasteFromClipboard();
289
+ return true;
290
+ }
291
+ ownsPointer() {
292
+ return this.#pointerSelecting;
293
+ }
294
+ handlePointer(event) {
295
+ if (event.button !== 0)
296
+ return false;
297
+ if (event.kind === "press")
298
+ return this.#pointerPress(event.column, event.row);
299
+ if (event.kind === "motion") {
300
+ if (!this.#pointerSelecting)
301
+ return false;
302
+ let position = this.#positionAt(event.column, event.row, true);
303
+ if (position !== undefined && this.#selection !== undefined) {
304
+ const atomic = this.#atomicRangeAt(position);
305
+ if (atomic !== undefined) {
306
+ const beforeAnchor = position.line < this.#selection.anchor.line
307
+ || (position.line === this.#selection.anchor.line && atomic.start < this.#selection.anchor.col);
308
+ position = { line: position.line, col: beforeAnchor ? atomic.start : atomic.end };
309
+ }
310
+ this.#selection = { ...this.#selection, head: position };
311
+ this.#selectionRevision += 1;
312
+ this.#requestRender();
313
+ }
314
+ return true;
315
+ }
316
+ if (!this.#pointerSelecting)
317
+ return false;
318
+ this.#pointerSelecting = false;
319
+ const ordered = this.#orderedSelection();
320
+ if (ordered === undefined && this.#selection !== undefined)
321
+ this.#setCursor(this.#selection.head);
322
+ if (ordered === undefined)
323
+ this.#clearSelection(false);
324
+ this.#requestRender();
325
+ return true;
326
+ }
327
+ #pointerPress(column, row) {
328
+ const position = this.#positionAt(column, row, false);
329
+ if (position === undefined)
330
+ return false;
331
+ const atomic = this.#atomicRangeAt(position);
332
+ if (atomic !== undefined) {
333
+ this.#selection = {
334
+ anchor: { line: position.line, col: atomic.start },
335
+ head: { line: position.line, col: atomic.start },
336
+ };
337
+ this.#setCursor({ line: position.line, col: atomic.start });
338
+ this.#pointerSelecting = true;
339
+ this.#lastClick = undefined;
340
+ this.#selectionRevision += 1;
341
+ this.#requestRender();
342
+ return true;
343
+ }
344
+ const now = Date.now();
345
+ const previous = this.#lastClick;
346
+ const count = previous !== undefined
347
+ && now - previous.time <= MULTI_CLICK_MS
348
+ && previous.line === position.line
349
+ && Math.abs(previous.col - position.col) <= 1
350
+ ? previous.count + 1
351
+ : 1;
352
+ this.#lastClick = { time: now, ...position, count };
353
+ const kind = ((count - 1) % 3) + 1;
354
+ if (kind === 2)
355
+ this.#selectWord(position);
356
+ else if (kind === 3)
357
+ this.#selectLine(position.line);
358
+ else
359
+ this.#selection = { anchor: position, head: position };
360
+ this.#pointerSelecting = true;
361
+ this.#selectionRevision += 1;
362
+ this.#requestRender();
363
+ return true;
364
+ }
365
+ #positionAt(column, row, clampRow) {
366
+ const geometry = this.#geometry;
367
+ if (geometry === undefined || geometry.textRows === 0)
368
+ return undefined;
369
+ let textRow = row - 2;
370
+ if (clampRow)
371
+ textRow = clamp(textRow, 0, geometry.textRows - 1);
372
+ if (textRow < 0 || textRow >= geometry.textRows)
373
+ return undefined;
374
+ const visual = geometry.visualLines[geometry.scrollOffset + textRow];
375
+ if (visual === undefined)
376
+ return undefined;
377
+ const line = (geometry.lines ?? editorState(this.editor).lines)[visual.logicalLine] ?? "";
378
+ const segment = line.slice(visual.startCol, visual.startCol + visual.length);
379
+ const displayColumn = Math.max(0, column - 1 - geometry.padding - geometry.prefixWidth);
380
+ return {
381
+ line: visual.logicalLine,
382
+ col: restoreColumn(visual.startCol + indexAtDisplayWidth(segment, displayColumn), geometry.hiddenRanges[visual.logicalLine] ?? []),
383
+ };
384
+ }
385
+ #selectWord(position) {
386
+ const atomic = this.#atomicRangeAt(position);
387
+ if (atomic !== undefined) {
388
+ this.#selection = {
389
+ anchor: { line: position.line, col: atomic.start },
390
+ head: { line: position.line, col: atomic.end },
391
+ };
392
+ return;
393
+ }
394
+ const line = editorState(this.editor).lines[position.line] ?? "";
395
+ const segments = [...GRAPHEMES.segment(line)].map(({ segment, index }) => ({
396
+ class: charClass(segment), start: index, end: index + segment.length,
397
+ }));
398
+ let selected = segments.findIndex(segment => position.col >= segment.start && position.col < segment.end);
399
+ if (selected < 0 && segments.length > 0 && position.col === line.length)
400
+ selected = segments.length - 1;
401
+ if (selected < 0)
402
+ return;
403
+ let start = selected;
404
+ let end = selected;
405
+ while (start > 0 && segments[start - 1]?.class === segments[selected]?.class)
406
+ start -= 1;
407
+ while (end + 1 < segments.length && segments[end + 1]?.class === segments[selected]?.class)
408
+ end += 1;
409
+ this.#selection = {
410
+ anchor: { line: position.line, col: segments[start]?.start ?? position.col },
411
+ head: { line: position.line, col: segments[end]?.end ?? position.col },
412
+ };
413
+ }
414
+ #selectLine(line) {
415
+ const text = editorState(this.editor).lines[line] ?? "";
416
+ this.#selection = { anchor: { line, col: 0 }, head: { line, col: text.length } };
417
+ }
418
+ #selectAll() {
419
+ const lines = editorState(this.editor).lines;
420
+ const finalLine = Math.max(0, lines.length - 1);
421
+ this.#selection = {
422
+ anchor: { line: 0, col: 0 },
423
+ head: { line: finalLine, col: (lines[finalLine] ?? "").length },
424
+ };
425
+ this.#pointerSelecting = false;
426
+ this.#selectionRevision += 1;
427
+ this.#requestRender();
428
+ }
429
+ #extend(delta) {
430
+ const cursor = this.#cursor();
431
+ if (this.#selection === undefined)
432
+ this.#selection = { anchor: cursor, head: cursor };
433
+ else if (!samePosition(cursor, this.#selection.head))
434
+ this.#setCursor(this.#selection.head);
435
+ this.#moveCursor(delta);
436
+ this.#selection = { anchor: this.#selection.anchor, head: this.#cursor() };
437
+ this.#pointerSelecting = false;
438
+ this.#lastClick = undefined;
439
+ this.#selectionRevision += 1;
440
+ this.#requestRender();
441
+ }
442
+ #handleTerminalPaste(data, next) {
443
+ const start = data.indexOf("\x1b[200~");
444
+ if (this.#terminalPaste === undefined) {
445
+ if (start < 0)
446
+ return false;
447
+ if (start > 0) {
448
+ const before = data.slice(0, start);
449
+ this.handleInput(before, (replacement = before) => next(replacement));
450
+ }
451
+ this.#terminalPaste = { parts: [], piece: "", tail: "", bytes: 0, oversized: false };
452
+ data = data.slice(start + 6);
453
+ }
454
+ // Protocol: inspect only the new fragment plus a delimiter-sized suffix, not the whole growing body.
455
+ const pending = this.#terminalPaste;
456
+ const fragment = pending.tail + data;
457
+ const end = fragment.indexOf("\x1b[201~");
458
+ const append = (part) => {
459
+ if (pending.oversized || part.length === 0)
460
+ return;
461
+ if (this.options.beginTextPaste !== undefined) {
462
+ pending.bytes += Buffer.byteLength(part);
463
+ if (pending.bytes > MAX_CLIPBOARD_TEXT_BYTES) {
464
+ pending.oversized = true;
465
+ pending.parts = [];
466
+ pending.piece = "";
467
+ return;
468
+ }
469
+ }
470
+ // Performance: bound fragment metadata even if a terminal supplies one character per input chunk.
471
+ pending.piece += part;
472
+ if (pending.piece.length >= 16_384) {
473
+ pending.parts.push(pending.piece);
474
+ pending.piece = "";
475
+ }
476
+ };
477
+ if (end < 0) {
478
+ let cut = Math.max(0, fragment.length - 5);
479
+ if (cut > 0 && /[\uD800-\uDBFF]/u.test(fragment[cut - 1]) && /[\uDC00-\uDFFF]/u.test(fragment[cut]))
480
+ cut--;
481
+ append(fragment.slice(0, cut));
482
+ pending.tail = fragment.slice(cut);
483
+ return true;
484
+ }
485
+ append(fragment.slice(0, end));
486
+ const remaining = fragment.slice(end + 6);
487
+ this.#terminalPaste = undefined;
488
+ this.options.onPasteInput?.(pending.bytes);
489
+ if (pending.oversized) {
490
+ this.options.onPasteRejected?.(new ImageAttachmentError("paste-size"));
491
+ if (remaining.length > 0)
492
+ this.handleInput(remaining, (replacement = remaining) => next(replacement));
493
+ return true;
494
+ }
495
+ const text = pending.parts.join("") + pending.piece;
496
+ if (text.length > 0)
497
+ this.#redoStack = [];
498
+ if (text.length === 0)
499
+ this.pasteClipboard();
500
+ else if (this.options.beginTextPaste !== undefined && (this.options.deferTextPaste?.(text) ?? true))
501
+ this.#pasteFromClipboard(text);
502
+ else {
503
+ const transformed = this.options.transformPastedContent({ kind: "text", text });
504
+ if (transformed === text && this.#orderedSelection() === undefined)
505
+ next(`\x1b[200~${text}\x1b[201~`);
506
+ else {
507
+ if (this.#orderedSelection() !== undefined)
508
+ this.#replaceSelection(transformed);
509
+ else
510
+ this.editor.insertTextAtCursor(transformed);
511
+ this.#redoStack = [];
512
+ this.#requestRender();
513
+ }
514
+ }
515
+ if (remaining.length > 0)
516
+ this.handleInput(remaining, (replacement = remaining) => next(replacement));
517
+ return true;
518
+ }
519
+ #pasteFromClipboard(source) {
520
+ const begin = source === undefined ? this.options.beginClipboardPaste
521
+ : this.options.beginTextPaste === undefined ? undefined : () => this.options.beginTextPaste(source);
522
+ if (begin !== undefined) {
523
+ const generation = this.#pasteGeneration;
524
+ const restore = this.#orderedSelection() === undefined ? "" : this.#selectedText();
525
+ const paste = begin();
526
+ this.#redoStack = [];
527
+ if (this.#orderedSelection() !== undefined)
528
+ this.#replaceSelection(paste.marker);
529
+ else
530
+ this.editor.insertTextAtCursor(paste.marker);
531
+ this.#requestRender();
532
+ const replace = (text) => {
533
+ if (generation === this.#pasteGeneration)
534
+ this.#replacePasteMarker(paste.marker, paste.isCurrent?.() === false ? restore : text || restore);
535
+ paste.complete?.();
536
+ };
537
+ void paste.result.then(replace).catch(() => replace(restore));
538
+ return;
539
+ }
540
+ const revision = this.#selectionRevision;
541
+ const selection = this.#orderedSelection();
542
+ const atomicFocus = this.#atomicFocus();
543
+ void this.options.readClipboardContent().then(content => {
544
+ if (content === null)
545
+ return;
546
+ const text = this.options.transformPastedContent(content);
547
+ if (text.length === 0)
548
+ return;
549
+ if (selection !== undefined && revision === this.#selectionRevision && this.#orderedSelection() !== undefined) {
550
+ this.#replaceSelection(text);
551
+ return;
552
+ }
553
+ if (atomicFocus !== undefined && samePosition(this.#cursor(), atomicFocus.start)) {
554
+ this.editor.insertTextAtCursor(text);
555
+ }
556
+ else {
557
+ this.#clearSelection(false);
558
+ this.editor.insertTextAtCursor(text);
559
+ }
560
+ this.#redoStack = [];
561
+ this.#requestRender();
562
+ }).catch(() => { });
563
+ }
564
+ #replacePasteMarker(marker, replacement) {
565
+ const current = this.editor.getText();
566
+ const from = current.indexOf(marker);
567
+ const text = normalizeInsertedText(replacement);
568
+ if (from < 0) {
569
+ this.#rewritePasteSnapshots(marker, text);
570
+ return;
571
+ }
572
+ const to = from + marker.length;
573
+ const lines = editorState(this.editor).lines;
574
+ const remap = (position) => {
575
+ const offset = positionOffset(lines, position);
576
+ return offset <= from ? offset : offset >= to ? offset + text.length - marker.length : from + text.length;
577
+ };
578
+ const cursor = remap(this.#cursor());
579
+ const selection = this.#selection === undefined ? undefined : { anchor: remap(this.#selection.anchor), head: remap(this.#selection.head) };
580
+ const next = current.slice(0, from) + text + current.slice(to);
581
+ // Compatibility: completing a paste updates its provisional undo snapshots, not the user's undo history.
582
+ if (this.editor.interaction !== undefined)
583
+ this.editor.interaction.replaceLines(next.split("\n"));
584
+ else
585
+ editorState(this.editor).lines = next.split("\n");
586
+ this.#rewritePasteSnapshots(marker, text);
587
+ this.#setCursor(positionAtOffset(next, cursor));
588
+ this.editor.onChange?.(this.editor.getText());
589
+ this.editor.invalidate();
590
+ if (selection !== undefined)
591
+ this.#selection = { anchor: positionAtOffset(next, selection.anchor), head: positionAtOffset(next, selection.head) };
592
+ this.#requestRender();
593
+ }
594
+ #rewritePasteSnapshots(marker, text) {
595
+ // Concurrency: even a removed reservation must be retired from redo/undo snapshots, or a canceled paste can reappear.
596
+ if (this.editor.interaction !== undefined)
597
+ this.editor.interaction.updateUndoStates(state => replaceSnapshotMarker(state, marker, text));
598
+ else {
599
+ const undo = Reflect.get(this.editor, "undoStack");
600
+ const snapshots = typeof undo === "object" && undo !== null ? Reflect.get(undo, "stack") : undefined;
601
+ if (Array.isArray(snapshots))
602
+ for (const snapshot of snapshots) {
603
+ const state = typeof snapshot === "object" && snapshot !== null ? Reflect.get(snapshot, "state") : undefined;
604
+ if (isEditorState(state))
605
+ replaceSnapshotMarker(state, marker, text);
606
+ }
607
+ }
608
+ for (const snapshot of this.#redoStack) {
609
+ const state = { lines: snapshot.text.split("\n"), cursorLine: snapshot.cursor.line, cursorCol: snapshot.cursor.col };
610
+ replaceSnapshotMarker(state, marker, text);
611
+ snapshot.text = state.lines.join("\n");
612
+ snapshot.cursor = { line: state.cursorLine, col: state.cursorCol };
613
+ }
614
+ }
615
+ #replaceSelection(text) {
616
+ const selection = this.#orderedSelection();
617
+ if (selection === undefined) {
618
+ this.editor.insertTextAtCursor(text);
619
+ return;
620
+ }
621
+ const normalized = normalizeInsertedText(text);
622
+ const current = this.editor.getText();
623
+ const lines = editorState(this.editor).lines;
624
+ const from = positionOffset(lines, selection.start);
625
+ const to = positionOffset(lines, selection.end);
626
+ const next = current.slice(0, from) + normalized + current.slice(to);
627
+ this.editor.setText(next);
628
+ this.#setCursor(positionAtOffset(next, from + normalized.length));
629
+ this.#redoStack = [];
630
+ this.#clearSelection(false);
631
+ this.#requestRender();
632
+ }
633
+ #deleteSelection() {
634
+ const selection = this.#orderedSelection();
635
+ if (selection === undefined)
636
+ return false;
637
+ const current = this.editor.getText();
638
+ const lines = editorState(this.editor).lines;
639
+ const from = positionOffset(lines, selection.start);
640
+ const to = positionOffset(lines, selection.end);
641
+ this.editor.setText(current.slice(0, from) + current.slice(to));
642
+ this.#setCursor(positionAtOffset(this.editor.getText(), from));
643
+ this.#redoStack = [];
644
+ this.#clearSelection(false);
645
+ this.#requestRender();
646
+ return true;
647
+ }
648
+ #deleteAtomicFocus() {
649
+ const focus = this.#atomicFocus();
650
+ if (focus === undefined)
651
+ return false;
652
+ const current = this.editor.getText();
653
+ const lines = editorState(this.editor).lines;
654
+ const from = positionOffset(lines, focus.start);
655
+ const to = positionOffset(lines, focus.end);
656
+ this.editor.setText(current.slice(0, from) + current.slice(to));
657
+ this.#setCursor(positionAtOffset(this.editor.getText(), from));
658
+ this.#redoStack = [];
659
+ this.#clearSelection(false);
660
+ this.#requestRender();
661
+ return true;
662
+ }
663
+ #redo() {
664
+ const snapshot = this.#redoStack.pop();
665
+ if (snapshot === undefined)
666
+ return;
667
+ this.editor.setText(snapshot.text);
668
+ this.#setCursor(snapshot.cursor);
669
+ this.#clearSelection(false);
670
+ this.#requestRender();
671
+ }
672
+ #collapseCopiedSelection() {
673
+ const selection = this.#activeRange();
674
+ if (selection === undefined)
675
+ return;
676
+ const line = editorState(this.editor).lines[selection.end.line] ?? "";
677
+ let column = selection.end.col;
678
+ while (true) {
679
+ const adjacent = this.options.atomicRanges(line).find(range => range.start === column);
680
+ if (adjacent === undefined)
681
+ break;
682
+ column = adjacent.end;
683
+ }
684
+ this.#setCursor({ line: selection.end.line, col: column });
685
+ this.#clearSelection(false);
686
+ this.#requestRender();
687
+ }
688
+ #selectedText() {
689
+ const selection = this.#activeRange();
690
+ if (selection === undefined)
691
+ return "";
692
+ const current = this.editor.getText();
693
+ const lines = editorState(this.editor).lines;
694
+ return current.slice(positionOffset(lines, selection.start), positionOffset(lines, selection.end));
695
+ }
696
+ #activeRange() {
697
+ return this.#orderedSelection() ?? this.#atomicFocus();
698
+ }
699
+ #atomicFocus() {
700
+ if (this.#orderedSelection() !== undefined)
701
+ return undefined;
702
+ const state = editorState(this.editor);
703
+ const line = state.lines[state.cursorLine] ?? "";
704
+ const range = this.options.atomicRanges(line).find(candidate => candidate.start === state.cursorCol);
705
+ return range === undefined ? undefined : {
706
+ start: { line: state.cursorLine, col: range.start },
707
+ end: { line: state.cursorLine, col: range.end },
708
+ };
709
+ }
710
+ #orderedSelection() {
711
+ const selection = this.#selection;
712
+ if (selection === undefined || samePosition(selection.anchor, selection.head))
713
+ return undefined;
714
+ return positionBefore(selection.anchor, selection.head)
715
+ ? { start: selection.anchor, end: selection.head }
716
+ : { start: selection.head, end: selection.anchor };
717
+ }
718
+ #clearSelection(render = true) {
719
+ if (this.#selection === undefined && !this.#pointerSelecting)
720
+ return;
721
+ this.#selection = undefined;
722
+ this.#pointerSelecting = false;
723
+ this.#selectionRevision += 1;
724
+ if (render)
725
+ this.#requestRender();
726
+ }
727
+ #cursor() {
728
+ return this.editor.getCursor();
729
+ }
730
+ #setCursor(position) {
731
+ if (this.editor.interaction !== undefined) {
732
+ this.editor.interaction.setCursor(position.line, position.col);
733
+ return;
734
+ }
735
+ const state = editorState(this.editor);
736
+ const line = clamp(position.line, 0, Math.max(0, state.lines.length - 1));
737
+ state.cursorLine = line;
738
+ state.cursorCol = clamp(position.col, 0, (state.lines[line] ?? "").length);
739
+ }
740
+ #moveCursor(delta) {
741
+ const state = editorState(this.editor);
742
+ const line = state.lines[state.cursorLine] ?? "";
743
+ const atomic = this.options.atomicRanges(line).find(range => delta < 0
744
+ ? state.cursorCol > range.start && state.cursorCol <= range.end
745
+ : state.cursorCol >= range.start && state.cursorCol < range.end);
746
+ if (atomic !== undefined) {
747
+ state.cursorCol = delta < 0 ? atomic.start : atomic.end;
748
+ this.editor.interaction?.setCursor(state.cursorLine, state.cursorCol);
749
+ return;
750
+ }
751
+ if (delta < 0) {
752
+ if (state.cursorCol > 0) {
753
+ const segments = [...GRAPHEMES.segment(line.slice(0, state.cursorCol))];
754
+ state.cursorCol -= segments.at(-1)?.segment.length ?? 1;
755
+ }
756
+ else if (state.cursorLine > 0) {
757
+ state.cursorLine -= 1;
758
+ state.cursorCol = (state.lines[state.cursorLine] ?? "").length;
759
+ }
760
+ this.editor.interaction?.setCursor(state.cursorLine, state.cursorCol);
761
+ return;
762
+ }
763
+ if (state.cursorCol < line.length) {
764
+ state.cursorCol += [...GRAPHEMES.segment(line.slice(state.cursorCol))][0]?.segment.length ?? 1;
765
+ }
766
+ else if (state.cursorLine < state.lines.length - 1) {
767
+ state.cursorLine += 1;
768
+ state.cursorCol = 0;
769
+ }
770
+ this.editor.interaction?.setCursor(state.cursorLine, state.cursorCol);
771
+ }
772
+ #atomicRangeAt(position) {
773
+ const line = editorState(this.editor).lines[position.line] ?? "";
774
+ return this.options.atomicRanges(line).find(range => position.col >= range.start && position.col < range.end);
775
+ }
776
+ #moveOntoPreviousSeparator() {
777
+ const cursor = this.#cursor();
778
+ if (cursor.col === 0)
779
+ return;
780
+ const line = editorState(this.editor).lines[cursor.line] ?? "";
781
+ const previous = [...GRAPHEMES.segment(line.slice(0, cursor.col))].at(-1);
782
+ if (previous !== undefined && /^\s+$/u.test(previous.segment))
783
+ this.#moveCursor(-1);
784
+ }
785
+ #snapshot() {
786
+ return { text: this.editor.getText(), cursor: this.#cursor() };
787
+ }
788
+ #wordDirectionFor(data) {
789
+ if (this.keybindings.matches(data, "tui.editor.deleteWordBackward"))
790
+ return -1;
791
+ if (this.keybindings.matches(data, "tui.editor.deleteWordForward")
792
+ || this.keybindings.matches(data, "tui.editor.cursorWordRight"))
793
+ return 1;
794
+ return undefined;
795
+ }
796
+ #delegateWord(direction, next) {
797
+ this.#wordDirection = direction;
798
+ try {
799
+ next();
800
+ }
801
+ finally {
802
+ this.#wordDirection = undefined;
803
+ }
804
+ }
805
+ #requestRender() {
806
+ this.options.requestRender();
807
+ }
808
+ }
809
+ function installAtomicSegmentation(editor, rangesForText, wordDirection) {
810
+ const transform = (text, mode, values) => {
811
+ const ranges = rangesForText(text).map(range => ({ ...range, wordLike: false }));
812
+ if (mode === "word") {
813
+ for (const range of contextualPathRanges(editor, text, wordDirection())) {
814
+ if (!ranges.some(existing => rangesOverlap(existing, range)))
815
+ ranges.push({ ...range, wordLike: true });
816
+ }
817
+ }
818
+ ranges.sort((left, right) => left.start - right.start);
819
+ if (mode === "grapheme" && ranges.length > 0 && hasSegmentLookup(values)) {
820
+ const indexed = atomicSegmentsByBoundary(text, ranges, offset => values.containing(offset));
821
+ if (indexed !== undefined)
822
+ return indexed;
823
+ }
824
+ const segments = [...values].filter(isEditorSegment);
825
+ if (ranges.length === 0)
826
+ return segments;
827
+ const merged = [];
828
+ let rangeIndex = 0;
829
+ for (const segment of segments) {
830
+ while ((ranges[rangeIndex]?.end ?? Number.POSITIVE_INFINITY) <= segment.index)
831
+ rangeIndex += 1;
832
+ const range = ranges[rangeIndex];
833
+ if (range !== undefined && segment.index >= range.start && segment.index < range.end) {
834
+ if (segment.index === range.start) {
835
+ const source = text.slice(range.start, range.end);
836
+ merged.push({
837
+ segment: range.wordLike ? "w".repeat(source.length) : source.replaceAll(" ", ATOMIC_SPACE_SENTINEL),
838
+ index: range.start,
839
+ input: text,
840
+ ...(range.wordLike ? { isWordLike: true } : {}),
841
+ });
842
+ }
843
+ continue;
844
+ }
845
+ merged.push(segment);
846
+ }
847
+ return merged;
848
+ };
849
+ if (editor.interaction !== undefined) {
850
+ editor.interaction.setSegmentTransform(transform);
851
+ return;
852
+ }
853
+ if (Reflect.get(editor, ATOMIC_SEGMENTATION) === true)
854
+ return;
855
+ const originalValue = Reflect.get(editor, "segment");
856
+ if (typeof originalValue !== "function")
857
+ return;
858
+ const original = originalValue.bind(editor);
859
+ Reflect.set(editor, "segment", (text, mode) => transform(text, mode, original(text, mode)));
860
+ Reflect.set(editor, ATOMIC_SEGMENTATION, true);
861
+ }
862
+ /** Narrow the optional indexed segment capability without a dynamic callback invocation. */
863
+ function hasSegmentLookup(values) {
864
+ return typeof values === "object" && values !== null && "containing" in values && typeof values.containing === "function";
865
+ }
866
+ /** Skip atomic interiors using the supplied segmenter's boundaries; preserve the iterable fallback exactly. */
867
+ function atomicSegmentsByBoundary(text, ranges, containing) {
868
+ const merged = [];
869
+ let offset = 0, rangeIndex = 0;
870
+ while (offset < text.length) {
871
+ const segment = containing(offset);
872
+ if (!isEditorSegment(segment) || segment.index !== offset || segment.segment.length === 0)
873
+ return undefined;
874
+ while ((ranges[rangeIndex]?.end ?? Number.POSITIVE_INFINITY) <= offset)
875
+ rangeIndex++;
876
+ const range = ranges[rangeIndex];
877
+ if (range !== undefined && offset >= range.start && offset < range.end) {
878
+ if (range.end > text.length)
879
+ return undefined;
880
+ const last = containing(range.end - 1);
881
+ if (!isEditorSegment(last) || last.index + last.segment.length < range.end)
882
+ return undefined;
883
+ if (offset === range.start)
884
+ merged.push({ segment: text.slice(range.start, range.end).replaceAll(" ", ATOMIC_SPACE_SENTINEL), index: range.start, input: text });
885
+ // Compatibility: the old iterable consumes the entire final grapheme, even if it crosses the chip end.
886
+ offset = last.index + last.segment.length;
887
+ }
888
+ else {
889
+ merged.push(segment);
890
+ offset += segment.segment.length;
891
+ }
892
+ }
893
+ return merged;
894
+ }
895
+ function contextualPathRanges(editor, text, direction) {
896
+ if (direction === undefined)
897
+ return promptPathWordRanges(text);
898
+ const state = editorState(editor);
899
+ const line = state.lines[state.cursorLine] ?? "";
900
+ const offset = direction < 0 ? 0 : state.cursorCol;
901
+ if (text !== (direction < 0 ? line.slice(0, state.cursorCol) : line.slice(state.cursorCol))) {
902
+ return promptPathWordRanges(text);
903
+ }
904
+ const end = offset + text.length;
905
+ return promptPathWordRanges(line).flatMap(range => {
906
+ const start = Math.max(range.start, offset);
907
+ const finish = Math.min(range.end, end);
908
+ return finish <= start ? [] : [{ start: start - offset, end: finish - offset }];
909
+ });
910
+ }
911
+ function rangesOverlap(left, right) {
912
+ return left.start < right.end && right.start < left.end;
913
+ }
914
+ function isEditorSegment(value) {
915
+ if (typeof value !== "object" || value === null)
916
+ return false;
917
+ const segment = Reflect.get(value, "segment");
918
+ const index = Reflect.get(value, "index");
919
+ const input = Reflect.get(value, "input");
920
+ return typeof segment === "string" && typeof index === "number" && typeof input === "string";
921
+ }
922
+ function insertedText(data) {
923
+ if (!data || data.includes("\u001b[200~"))
924
+ return undefined;
925
+ const kitty = decodeKittyPrintable(data);
926
+ if (kitty !== undefined)
927
+ return kitty;
928
+ return data.charCodeAt(0) >= 32 ? data : undefined;
929
+ }
930
+ function indexAtDisplayWidth(text, target) {
931
+ if (target <= 0)
932
+ return 0;
933
+ let width = 0;
934
+ let index = 0;
935
+ for (const { segment } of GRAPHEMES.segment(text)) {
936
+ const next = width + visibleWidth(segment);
937
+ if (next > target)
938
+ break;
939
+ width = next;
940
+ index += segment.length;
941
+ }
942
+ return index;
943
+ }
944
+ function charClass(value) {
945
+ if (/\s/u.test(value))
946
+ return 0;
947
+ if (/[\p{L}\p{N}_]/u.test(value))
948
+ return 1;
949
+ return 2;
950
+ }
951
+ function positionBefore(left, right) {
952
+ return left.line < right.line || (left.line === right.line && left.col <= right.col);
953
+ }
954
+ function samePosition(left, right) {
955
+ return left.line === right.line && left.col === right.col;
956
+ }
957
+ function sameSnapshot(left, right) {
958
+ return left.text === right.text && samePosition(left.cursor, right.cursor);
959
+ }
960
+ function hideColumn(column, ranges) {
961
+ return column - ranges.reduce((removed, range) => removed + Math.max(0, Math.min(column, range.end) - range.start), 0);
962
+ }
963
+ function restoreColumn(column, ranges) {
964
+ let restored = column;
965
+ for (const range of ranges)
966
+ if (restored >= range.start)
967
+ restored += range.end - range.start;
968
+ return restored;
969
+ }
970
+ function editorState(editor) {
971
+ if (editor.interaction !== undefined)
972
+ return editor.interaction.snapshot();
973
+ const value = Object.getOwnPropertyDescriptor(editor, "state")?.value;
974
+ if (!isEditorState(value))
975
+ throw new Error("Pi editor state is unavailable");
976
+ return value;
977
+ }
978
+ function isEditorState(value) {
979
+ if (typeof value !== "object" || value === null)
980
+ return false;
981
+ const lines = Object.getOwnPropertyDescriptor(value, "lines")?.value;
982
+ const cursorLine = Object.getOwnPropertyDescriptor(value, "cursorLine")?.value;
983
+ const cursorCol = Object.getOwnPropertyDescriptor(value, "cursorCol")?.value;
984
+ return Array.isArray(lines) && lines.every(line => typeof line === "string")
985
+ && typeof cursorLine === "number" && typeof cursorCol === "number";
986
+ }
987
+ function numericProperty(target, key) {
988
+ const value = Object.getOwnPropertyDescriptor(target, key)?.value;
989
+ return typeof value === "number" ? value : 0;
990
+ }
991
+ /** Shares the existing atomic-aware body layout with prompt/menu composition. */
992
+ export function editorVisualLineCount(editor, width) {
993
+ return editorVisualLineMap(editor, width)?.length;
994
+ }
995
+ function editorVisualLineMap(editor, width) {
996
+ if (editor.interaction !== undefined)
997
+ return editor.interaction.visualLines(width);
998
+ const builder = Reflect.get(editor, "buildVisualLineMap");
999
+ if (typeof builder !== "function")
1000
+ return undefined;
1001
+ const value = builder.call(editor, width);
1002
+ if (!Array.isArray(value) || !value.every(isVisualLine))
1003
+ return undefined;
1004
+ return value;
1005
+ }
1006
+ function isVisualLine(value) {
1007
+ if (typeof value !== "object" || value === null)
1008
+ return false;
1009
+ return typeof Reflect.get(value, "logicalLine") === "number"
1010
+ && typeof Reflect.get(value, "startCol") === "number"
1011
+ && typeof Reflect.get(value, "length") === "number";
1012
+ }
1013
+ function buildVisualLineMap(lines, width) {
1014
+ const visualLines = [];
1015
+ for (let logicalLine = 0; logicalLine < lines.length; logicalLine += 1) {
1016
+ const line = lines[logicalLine] ?? "";
1017
+ if (line.length === 0) {
1018
+ visualLines.push({ logicalLine, startCol: 0, length: 0 });
1019
+ continue;
1020
+ }
1021
+ for (const chunk of wrapLine(line, width)) {
1022
+ visualLines.push({ logicalLine, startCol: chunk.start, length: chunk.end - chunk.start });
1023
+ }
1024
+ }
1025
+ return visualLines;
1026
+ }
1027
+ function wrapLine(line, width) {
1028
+ if (visibleWidth(line) <= width)
1029
+ return [{ start: 0, end: line.length }];
1030
+ const segments = [...GRAPHEMES.segment(line)];
1031
+ const chunks = [];
1032
+ let start = 0;
1033
+ let currentWidth = 0;
1034
+ let wrapAt = -1;
1035
+ let widthAtWrap = 0;
1036
+ for (let index = 0; index < segments.length; index += 1) {
1037
+ const segment = segments[index];
1038
+ if (segment === undefined)
1039
+ continue;
1040
+ const segmentWidth = visibleWidth(segment.segment);
1041
+ if (currentWidth + segmentWidth > width) {
1042
+ if (wrapAt > start && currentWidth - widthAtWrap + segmentWidth <= width) {
1043
+ chunks.push({ start, end: wrapAt });
1044
+ start = wrapAt;
1045
+ currentWidth -= widthAtWrap;
1046
+ }
1047
+ else if (start < segment.index) {
1048
+ chunks.push({ start, end: segment.index });
1049
+ start = segment.index;
1050
+ currentWidth = 0;
1051
+ }
1052
+ wrapAt = -1;
1053
+ }
1054
+ currentWidth += segmentWidth;
1055
+ const next = segments[index + 1];
1056
+ if (/\s/u.test(segment.segment) && next !== undefined && !/\s/u.test(next.segment)) {
1057
+ wrapAt = next.index;
1058
+ widthAtWrap = currentWidth;
1059
+ }
1060
+ }
1061
+ chunks.push({ start, end: line.length });
1062
+ return chunks;
1063
+ }
1064
+ function positionOffset(lines, position) {
1065
+ let offset = 0;
1066
+ for (let line = 0; line < position.line; line += 1)
1067
+ offset += (lines[line] ?? "").length + 1;
1068
+ return offset + position.col;
1069
+ }
1070
+ function positionAtOffset(text, requestedOffset) {
1071
+ const offset = clamp(requestedOffset, 0, text.length);
1072
+ const before = text.slice(0, offset).split("\n");
1073
+ return { line: before.length - 1, col: (before.at(-1) ?? "").length };
1074
+ }
1075
+ function replaceSnapshotMarker(state, marker, replacement) {
1076
+ const text = state.lines.join("\n");
1077
+ const from = text.indexOf(marker);
1078
+ if (from < 0)
1079
+ return;
1080
+ const cursor = positionOffset(state.lines, { line: state.cursorLine, col: state.cursorCol });
1081
+ const offset = cursor <= from ? cursor : cursor >= from + marker.length ? cursor + replacement.length - marker.length : from + replacement.length;
1082
+ const next = text.slice(0, from) + replacement + text.slice(from + marker.length);
1083
+ const position = positionAtOffset(next, offset);
1084
+ state.lines = next.split("\n");
1085
+ state.cursorLine = position.line;
1086
+ state.cursorCol = position.col;
1087
+ }
1088
+ function normalizeInsertedText(text) {
1089
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\t/g, " ");
1090
+ }
1091
+ function clamp(value, minimum, maximum) {
1092
+ return Math.max(minimum, Math.min(maximum, value));
1093
+ }