@timurproko/a1 0.1.8-dev.235df0e → 0.1.8-dev.260

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 (485) hide show
  1. package/README.md +107 -67
  2. package/bin/cli.js +28 -10
  3. package/bin/guardian.js +8 -3
  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 +47 -20
  11. package/bin/warmup.js +27 -0
  12. package/dist/cli/capabilities.d.ts +6 -0
  13. package/dist/{src/cli → cli}/capabilities.js +1 -1
  14. package/dist/{src/cli → cli}/dispatch.d.ts +15 -1
  15. package/dist/cli/dispatch.js +261 -0
  16. package/dist/cli/package-messages.d.ts +26 -0
  17. package/dist/cli/package-messages.js +71 -0
  18. package/dist/{src/cli → cli}/packages.d.ts +11 -2
  19. package/dist/{src/cli → cli}/packages.js +24 -27
  20. package/dist/{src/cli → cli}/version-stats.d.ts +6 -0
  21. package/dist/cli/version-stats.js +112 -0
  22. package/dist/composition/agent-engine-bridge.d.ts +3 -0
  23. package/dist/composition/agent-engine-bridge.js +108 -0
  24. package/dist/composition/index.d.ts +3 -0
  25. package/dist/composition/index.js +3 -0
  26. package/dist/composition/owned-ui.d.ts +31 -0
  27. package/dist/composition/owned-ui.js +66 -0
  28. package/dist/composition/process.d.ts +16 -0
  29. package/dist/composition/process.js +45 -0
  30. package/dist/composition/settings-route-host.d.ts +8 -0
  31. package/dist/composition/settings-route-host.js +75 -0
  32. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/capability-ports.d.ts +2 -2
  33. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain-validation.js +22 -4
  34. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain.d.ts +17 -0
  35. package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/package-ports.d.ts +6 -0
  36. package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/model.d.ts +36 -0
  37. package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/validation.js +25 -0
  38. package/dist/{src/features → features}/launch/development-launch.js +11 -3
  39. package/dist/{src/features → features}/launch/index.d.ts +0 -1
  40. package/dist/{src/features → features}/launch/index.js +0 -1
  41. package/dist/features/launch/intent.d.ts +10 -0
  42. package/dist/features/launch/intent.js +8 -0
  43. package/dist/{src/features → features}/launch/prepare-launch.d.ts +0 -2
  44. package/dist/{src/features → features}/launch/prepare-launch.js +2 -9
  45. package/dist/{src/features → features}/launch/profile-paths.d.ts +1 -2
  46. package/dist/{src/features → features}/launch/profile-paths.js +2 -8
  47. package/dist/{src/features → features}/launch/runtime-selection.d.ts +2 -5
  48. package/dist/{src/features → features}/owned-ui/customization.d.ts +3 -1
  49. package/dist/{src/features → features}/owned-ui/customization.js +3 -1
  50. package/dist/{src/features → features}/owned-ui/diagnostics.d.ts +2 -1
  51. package/dist/{src/features → features}/owned-ui/diagnostics.js +1 -0
  52. package/dist/{src/features → features}/owned-ui/index.d.ts +2 -0
  53. package/dist/{src/features → features}/owned-ui/index.js +2 -0
  54. package/dist/features/owned-ui/project-trust-prompt.d.ts +25 -0
  55. package/dist/features/owned-ui/project-trust-prompt.js +149 -0
  56. package/dist/{src/features → features}/owned-ui/run.d.ts +2 -2
  57. package/dist/{src/features → features}/owned-ui/run.js +2 -0
  58. package/dist/features/owned-ui/session-fork-prompt.d.ts +8 -0
  59. package/dist/features/owned-ui/session-fork-prompt.js +34 -0
  60. package/dist/{src/features → features}/owned-ui/settings-app.d.ts +3 -3
  61. package/dist/{src/features → features}/owned-ui/settings-app.js +103 -54
  62. package/dist/{src/features → features}/workspace/capabilities.d.ts +1 -1
  63. package/dist/{src/features → features}/workspace/reducer.d.ts +2 -1
  64. package/dist/{src/features → features}/workspace/reducer.js +2 -1
  65. package/dist/{src/features → features}/workspace/router.d.ts +2 -1
  66. package/dist/{src/features → features}/workspace/router.js +1 -0
  67. package/dist/{src/features → features}/workspace/store.d.ts +2 -1
  68. package/dist/{src/features → features}/workspace/store.js +1 -0
  69. package/dist/{src/foundation → foundation}/launch-guardian/main.d.ts +2 -0
  70. package/dist/{src/foundation → foundation}/launch-guardian/main.js +18 -5
  71. package/dist/{src/foundation → foundation}/lifecycle/index.d.ts +2 -0
  72. package/dist/{src/foundation → foundation}/lifecycle/index.js +2 -0
  73. package/dist/{src/foundation → foundation}/lifecycle/model.d.ts +1 -1
  74. package/dist/{src/foundation → foundation}/lifecycle/model.js +1 -1
  75. package/dist/foundation/lifecycle/paths.d.ts +30 -0
  76. package/dist/{src/foundation → foundation}/lifecycle/paths.js +29 -1
  77. package/dist/foundation/lifecycle/session-selection.d.ts +9 -0
  78. package/dist/foundation/lifecycle/session-selection.js +39 -0
  79. package/dist/foundation/lifecycle/supervisor-startup.d.ts +30 -0
  80. package/dist/foundation/lifecycle/supervisor-startup.js +106 -0
  81. package/dist/{src/foundation → foundation}/native-host-protocol/codec.d.ts +2 -0
  82. package/dist/{src/foundation → foundation}/native-host-protocol/codec.js +2 -0
  83. package/dist/{src/foundation → foundation}/native-host-protocol/messages.d.ts +1 -1
  84. package/dist/{src/foundation → foundation}/native-host-protocol/messages.js +1 -1
  85. package/dist/foundation/process-containment/darwin-process-inspector.d.ts +5 -0
  86. package/dist/foundation/process-containment/darwin-process-inspector.js +7 -0
  87. package/dist/{src/foundation → foundation}/process-containment/index.d.ts +1 -0
  88. package/dist/{src/foundation → foundation}/process-containment/index.js +1 -0
  89. package/dist/{src/foundation → foundation}/process-containment/linux-process-inspector.d.ts +1 -0
  90. package/dist/{src/foundation → foundation}/process-containment/linux-process-inspector.js +1 -0
  91. package/dist/{src/foundation → foundation}/process-containment/native-guardian-containment.d.ts +1 -0
  92. package/dist/{src/foundation → foundation}/process-containment/native-guardian-containment.js +1 -0
  93. package/dist/{src/foundation → foundation}/process-containment/windows-process-inspector.d.ts +3 -1
  94. package/dist/{src/foundation → foundation}/process-containment/windows-process-inspector.js +5 -2
  95. package/dist/{src/foundation → foundation}/protocol/client.d.ts +1 -0
  96. package/dist/{src/foundation → foundation}/protocol/client.js +1 -0
  97. package/dist/{src/foundation → foundation}/protocol/messages.d.ts +1 -0
  98. package/dist/{src/foundation → foundation}/protocol/messages.js +1 -0
  99. package/dist/{src/foundation → foundation}/release/bootstrap.d.ts +25 -6
  100. package/dist/{src/foundation → foundation}/release/bootstrap.js +124 -34
  101. package/dist/foundation/release/cohort-state.d.ts +156 -0
  102. package/dist/foundation/release/cohort-state.js +471 -0
  103. package/dist/foundation/release/dependency-layer.d.ts +82 -0
  104. package/dist/foundation/release/dependency-layer.js +497 -0
  105. package/dist/foundation/release/endpoints.d.ts +20 -0
  106. package/dist/foundation/release/endpoints.js +50 -0
  107. package/dist/foundation/release/immutable-platform.d.ts +6 -0
  108. package/dist/foundation/release/immutable-platform.js +13 -0
  109. package/dist/{src/foundation → foundation}/release/index.d.ts +4 -0
  110. package/dist/{src/foundation → foundation}/release/index.js +4 -0
  111. package/dist/foundation/release/release-gc.d.ts +71 -0
  112. package/dist/foundation/release/release-gc.js +734 -0
  113. package/dist/{src/foundation → foundation}/release/release-store.d.ts +7 -3
  114. package/dist/{src/foundation → foundation}/release/release-store.js +65 -13
  115. package/dist/{src/foundation → foundation}/release/release.d.ts +4 -1
  116. package/dist/{src/foundation → foundation}/release/release.js +10 -3
  117. package/dist/foundation/release/restart-certification.d.ts +67 -0
  118. package/dist/foundation/release/restart-certification.js +211 -0
  119. package/dist/{src/foundation → foundation}/release/update-transaction.d.ts +1 -0
  120. package/dist/{src/foundation → foundation}/release/update-transaction.js +1 -0
  121. package/dist/{src/foundation → foundation}/release/update.d.ts +19 -3
  122. package/dist/{src/foundation → foundation}/release/update.js +116 -56
  123. package/dist/foundation/release/warmup.d.ts +3 -0
  124. package/dist/foundation/release/warmup.js +35 -0
  125. package/dist/foundation/startup/index.d.ts +1 -0
  126. package/dist/foundation/startup/index.js +1 -0
  127. package/dist/foundation/startup/startup-runtime.d.ts +36 -0
  128. package/dist/foundation/startup/startup-runtime.js +140 -0
  129. package/dist/{src/foundation → foundation}/storage/control-store.d.ts +2 -1
  130. package/dist/{src/foundation → foundation}/storage/control-store.js +39 -4
  131. package/dist/{src/foundation → foundation}/structured-agent-runtime/backpressure.d.ts +2 -1
  132. package/dist/{src/foundation → foundation}/structured-agent-runtime/backpressure.js +2 -1
  133. package/dist/{src/foundation → foundation}/structured-agent-runtime/commands.d.ts +2 -1
  134. package/dist/{src/foundation → foundation}/structured-agent-runtime/commands.js +2 -1
  135. package/dist/{src/foundation → foundation}/structured-agent-runtime/handshake.d.ts +1 -1
  136. package/dist/{src/foundation → foundation}/structured-agent-runtime/handshake.js +1 -1
  137. package/dist/{src/foundation → foundation}/structured-agent-runtime/reconnection.d.ts +2 -1
  138. package/dist/{src/foundation → foundation}/structured-agent-runtime/reconnection.js +2 -1
  139. package/dist/{src/foundation → foundation}/structured-agent-runtime/state.d.ts +2 -1
  140. package/dist/{src/foundation → foundation}/structured-agent-runtime/state.js +2 -1
  141. package/dist/foundation/supervision/index.d.ts +3 -0
  142. package/dist/foundation/supervision/index.js +3 -0
  143. package/dist/foundation/supervision/main.d.ts +1 -0
  144. package/dist/foundation/supervision/main.js +80 -0
  145. package/dist/foundation/supervision/paths.d.ts +1 -0
  146. package/dist/foundation/supervision/paths.js +1 -0
  147. package/dist/{src/foundation → foundation}/supervision/server.d.ts +19 -1
  148. package/dist/{src/foundation → foundation}/supervision/server.js +65 -3
  149. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/components.d.ts +1 -1
  150. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/conformance.d.ts +1 -0
  151. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/conformance.js +3 -2
  152. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/index.d.ts +1 -1
  153. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/index.js +1 -1
  154. package/dist/integrations/pi/components/owned-editor-ux.d.ts +55 -0
  155. package/dist/integrations/pi/components/owned-editor-ux.js +778 -0
  156. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-components.d.ts +1 -0
  157. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-components.js +1 -0
  158. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-editor-autocomplete.js +54 -6
  159. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-extension-ui.d.ts +1 -1
  160. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-footer-status.d.ts +3 -3
  161. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-footer-status.js +49 -18
  162. package/dist/integrations/pi/components/shell-presenters-info.d.ts +36 -0
  163. package/dist/integrations/pi/components/shell-presenters-info.js +78 -0
  164. package/dist/integrations/pi/components/shell-presenters-transcript.d.ts +25 -0
  165. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-presenters-transcript.js +92 -131
  166. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-selectors-dialogs.d.ts +5 -2
  167. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-selectors-dialogs.js +2 -1
  168. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-shared-facade.d.ts +57 -8
  169. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-shared-facade.js +4 -2
  170. package/dist/integrations/pi/components/submitted-prompt-adapter.d.ts +13 -0
  171. package/dist/integrations/pi/components/submitted-prompt-adapter.js +27 -0
  172. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/adjacent/core/keybindings.d.ts +10 -2
  173. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/adjacent/core/keybindings.js +36 -3
  174. package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-footer.d.ts +1 -1
  175. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/adapter.d.ts +28 -4
  176. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/adapter.js +714 -127
  177. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/conformance.d.ts +2 -0
  178. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/conformance.js +4 -2
  179. package/dist/integrations/pi/engine/http-dispatcher.d.ts +4 -0
  180. package/dist/integrations/pi/engine/http-dispatcher.js +25 -0
  181. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/index.d.ts +4 -0
  182. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/index.js +4 -0
  183. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/model-auth-integration.d.ts +2 -1
  184. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/model-auth-integration.js +1 -0
  185. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/package-integration.d.ts +1 -1
  186. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/package-integration.js +32 -26
  187. package/dist/integrations/pi/engine/project-trust-preflight.d.ts +22 -0
  188. package/dist/integrations/pi/engine/project-trust-preflight.js +50 -0
  189. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/resource-extension-integration.d.ts +2 -1
  190. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/resource-extension-integration.js +1 -0
  191. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/runtime-integration.d.ts +19 -1
  192. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/runtime-integration.js +47 -5
  193. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/session-integration.d.ts +4 -2
  194. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/session-integration.js +19 -4
  195. package/dist/integrations/pi/engine/session-selection.d.ts +28 -0
  196. package/dist/integrations/pi/engine/session-selection.js +90 -0
  197. package/dist/integrations/pi/engine/settings-effects.d.ts +66 -0
  198. package/dist/integrations/pi/engine/settings-effects.js +249 -0
  199. package/dist/integrations/pi/engine/settings-integration.d.ts +43 -0
  200. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/settings-integration.js +102 -108
  201. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflow-controllers.d.ts +3 -2
  202. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflow-controllers.js +1 -0
  203. package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflows.d.ts +18 -1
  204. package/dist/integrations/pi/session-ui/clipboard-image.d.ts +11 -0
  205. package/dist/integrations/pi/session-ui/clipboard-image.js +29 -0
  206. package/dist/{src/foundation/pi-owned-ui-integration → integrations/pi/session-ui}/index.d.ts +1 -0
  207. package/dist/{src/foundation/pi-owned-ui-integration → integrations/pi/session-ui}/index.js +1 -0
  208. package/dist/integrations/pi/session-ui/prompt-chips.d.ts +23 -0
  209. package/dist/integrations/pi/session-ui/prompt-chips.js +246 -0
  210. package/dist/integrations/pi/session-ui/route-host.d.ts +5 -0
  211. package/dist/integrations/pi/session-ui/session-shell-root.d.ts +141 -0
  212. package/dist/integrations/pi/session-ui/session-shell-root.js +1158 -0
  213. package/dist/integrations/pi/session-ui/session-shell.d.ts +55 -0
  214. package/dist/{src/foundation/pi-owned-ui-integration → integrations/pi/session-ui}/session-shell.js +479 -719
  215. package/dist/integrations/pi/session-ui/session-viewport-controller.d.ts +45 -0
  216. package/dist/integrations/pi/session-ui/session-viewport-controller.js +463 -0
  217. package/dist/integrations/pi/session-ui/stream-presentation-coalescer.d.ts +29 -0
  218. package/dist/integrations/pi/session-ui/stream-presentation-coalescer.js +79 -0
  219. package/dist/integrations/pi/session-ui/system-clipboard.d.ts +20 -0
  220. package/dist/integrations/pi/session-ui/system-clipboard.js +130 -0
  221. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/adapter.d.ts +8 -1
  222. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/adapter.js +216 -9
  223. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/contracts.d.ts +29 -6
  224. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.d.ts +74 -0
  225. package/dist/integrations/pi/tui-runtime/damage-aware-terminal.js +380 -0
  226. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/index.d.ts +2 -0
  227. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/index.js +2 -0
  228. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.d.ts +39 -0
  229. package/dist/integrations/pi/tui-runtime/input-presentation-coordinator.js +139 -0
  230. package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/presentation-adapter.d.ts +1 -1
  231. package/dist/native/darwin-arm64/manifest.json +4 -4
  232. package/dist/native/darwin-arm64/process-guardian +0 -0
  233. package/dist/native/linux-x64/manifest.json +3 -3
  234. package/dist/native/linux-x64/process-guardian +0 -0
  235. package/dist/native/win32-x64/manifest.json +3 -3
  236. package/dist/native/win32-x64/process-guardian.exe +0 -0
  237. package/dist/{src/product-identity.d.ts → product-identity.d.ts} +3 -3
  238. package/dist/{src/product-identity.js → product-identity.js} +7 -5
  239. package/dist/{src/product-identity.json → product-identity.json} +11 -6
  240. package/dist/runtime-payload-inventory.json +122328 -0
  241. package/dist/{src/foundation/ui-apps → ui/apps}/contracts.d.ts +23 -1
  242. package/dist/{src/foundation/ui-apps → ui/apps}/host.d.ts +1 -1
  243. package/dist/{src/foundation/ui-apps → ui/apps}/host.js +14 -10
  244. package/dist/{src/foundation/ui-apps → ui/apps}/registry.d.ts +1 -0
  245. package/dist/{src/foundation/ui-apps → ui/apps}/registry.js +1 -0
  246. package/dist/{src/foundation/ui-components → ui/components}/dialog-panel.js +5 -3
  247. package/dist/{src/foundation/ui-components → ui/components}/frame.d.ts +1 -0
  248. package/dist/{src/foundation/ui-components → ui/components}/frame.js +1 -0
  249. package/dist/{src/foundation/ui-components → ui/components}/index.d.ts +5 -0
  250. package/dist/{src/foundation/ui-components → ui/components}/index.js +5 -0
  251. package/dist/{src/foundation/ui-components → ui/components}/line-input.d.ts +1 -6
  252. package/dist/{src/foundation/ui-components → ui/components}/line-input.js +4 -9
  253. package/dist/{src/foundation/ui-components → ui/components}/list-view.d.ts +0 -6
  254. package/dist/{src/foundation/ui-components → ui/components}/list-view.js +14 -7
  255. package/dist/{src/foundation/ui-components → ui/components}/mouse.d.ts +10 -0
  256. package/dist/{src/foundation/ui-components → ui/components}/mouse.js +23 -0
  257. package/dist/ui/components/progress-status.d.ts +2 -0
  258. package/dist/ui/components/progress-status.js +4 -0
  259. package/dist/ui/components/prompt-row.d.ts +14 -0
  260. package/dist/ui/components/prompt-row.js +20 -0
  261. package/dist/{src/foundation/ui-components → ui/components}/scrollbar.d.ts +26 -0
  262. package/dist/{src/foundation/ui-components → ui/components}/scrollbar.js +35 -0
  263. package/dist/{src/foundation/ui-components → ui/components}/shortcuts.d.ts +1 -0
  264. package/dist/{src/foundation/ui-components → ui/components}/shortcuts.js +1 -0
  265. package/dist/ui/components/spans.d.ts +25 -0
  266. package/dist/ui/components/spans.js +257 -0
  267. package/dist/ui/components/submitted-prompt.d.ts +23 -0
  268. package/dist/ui/components/submitted-prompt.js +50 -0
  269. package/dist/{src/foundation/ui-components → ui/components}/surface.d.ts +0 -5
  270. package/dist/{src/foundation/ui-components → ui/components}/surface.js +1 -5
  271. package/dist/ui/components/text-selection.d.ts +62 -0
  272. package/dist/ui/components/text-selection.js +208 -0
  273. package/dist/{src/foundation/ui-components → ui/components}/text.d.ts +14 -0
  274. package/dist/{src/foundation/ui-components → ui/components}/text.js +66 -4
  275. package/dist/ui/components/transcript-viewport.d.ts +152 -0
  276. package/dist/ui/components/transcript-viewport.js +631 -0
  277. package/dist/ui/components/visible-hyperlinks.d.ts +19 -0
  278. package/dist/ui/components/visible-hyperlinks.js +64 -0
  279. package/dist/{src/foundation/owned-ui-settings → ui/settings}/declarations.d.ts +8 -1
  280. package/dist/{src/foundation/owned-ui-settings → ui/settings}/declarations.js +33 -5
  281. package/dist/{src/foundation/owned-ui-settings → ui/settings}/migrations.d.ts +1 -1
  282. package/dist/{src/foundation/owned-ui-settings → ui/settings}/migrations.js +21 -2
  283. package/dist/{src/foundation/owned-ui-settings → ui/settings}/sections.d.ts +6 -19
  284. package/dist/{src/foundation/owned-ui-settings → ui/settings}/sections.js +32 -23
  285. package/dist/{src/foundation/owned-ui-settings → ui/settings}/session.d.ts +9 -17
  286. package/dist/{src/foundation/owned-ui-settings → ui/settings}/session.js +65 -55
  287. package/dist/{src/foundation/owned-ui-settings → ui/settings}/store.d.ts +1 -0
  288. package/dist/{src/foundation/owned-ui-settings → ui/settings}/store.js +2 -1
  289. package/docs/architecture/boundaries.md +9 -9
  290. package/docs/architecture/code-documentation.md +77 -0
  291. package/docs/architecture/process-guardian-provenance.md +3 -1
  292. package/docs/architecture/project-structure.md +67 -30
  293. package/docs/architecture/resource-and-data-policy.md +1 -1
  294. package/docs/architecture/toolchain.md +10 -10
  295. package/docs/architecture/ui-reference-provenance.md +36 -5
  296. package/docs/ci-release-runbook.md +186 -79
  297. package/docs/features/launch-profiles.md +24 -17
  298. package/docs/manual-ghost-link-baseline.md +89 -0
  299. package/docs/manual-launch-instance-acceptance.md +12 -35
  300. package/docs/manual-owned-ui-checkpoint.md +78 -0
  301. package/docs/manual-pi-boundary-candidate.md +4 -5
  302. package/docs/manual-terminal-colour-check.md +4 -3
  303. package/docs/repository-governance-live-acceptance.md +77 -0
  304. package/package.json +37 -27
  305. package/dist/src/cli/capabilities.d.ts +0 -15
  306. package/dist/src/cli/dispatch.js +0 -177
  307. package/dist/src/cli/version-stats.js +0 -72
  308. package/dist/src/composition/index.d.ts +0 -48
  309. package/dist/src/composition/index.js +0 -258
  310. package/dist/src/features/launch/intent.d.ts +0 -7
  311. package/dist/src/features/launch/intent.js +0 -4
  312. package/dist/src/features/launch/profiles.d.ts +0 -12
  313. package/dist/src/features/launch/profiles.js +0 -26
  314. package/dist/src/foundation/lifecycle/paths.d.ts +0 -10
  315. package/dist/src/foundation/pi-component-adapter/shell-presenters-transcript.d.ts +0 -57
  316. package/dist/src/foundation/pi-engine-adapter/settings-integration.d.ts +0 -55
  317. package/dist/src/foundation/pi-owned-ui-integration/route-host.d.ts +0 -29
  318. package/dist/src/foundation/pi-owned-ui-integration/session-shell.d.ts +0 -106
  319. package/dist/src/foundation/release/cohort-state.d.ts +0 -70
  320. package/dist/src/foundation/release/cohort-state.js +0 -202
  321. package/dist/src/foundation/release/release-gc.d.ts +0 -5
  322. package/dist/src/foundation/release/release-gc.js +0 -16
  323. package/dist/src/foundation/supervision/index.d.ts +0 -3
  324. package/dist/src/foundation/supervision/index.js +0 -3
  325. package/dist/src/foundation/supervision/main.d.ts +0 -1
  326. package/dist/src/foundation/supervision/main.js +0 -41
  327. package/dist/src/foundation/supervision/paths.d.ts +0 -1
  328. package/dist/src/foundation/supervision/paths.js +0 -1
  329. package/dist/src/foundation/ui-components/spans.d.ts +0 -7
  330. package/dist/src/foundation/ui-components/spans.js +0 -59
  331. package/docs/manual-transparent-checkpoint.md +0 -53
  332. /package/dist/{src/cli → cli}/index.d.ts +0 -0
  333. /package/dist/{src/cli → cli}/index.js +0 -0
  334. /package/dist/{src/cli → cli}/version.d.ts +0 -0
  335. /package/dist/{src/cli → cli}/version.js +0 -0
  336. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/capability-ports.js +0 -0
  337. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain-validation.d.ts +0 -0
  338. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/domain.js +0 -0
  339. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/index.d.ts +0 -0
  340. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/index.js +0 -0
  341. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.d.ts +0 -0
  342. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/model.js +0 -0
  343. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/package-ports.js +0 -0
  344. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/ports.d.ts +0 -0
  345. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/ports.js +0 -0
  346. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.d.ts +0 -0
  347. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/serialization.js +0 -0
  348. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.d.ts +0 -0
  349. /package/dist/{src/foundation/agent-engine-contracts → contracts/agent-engine}/validation.js +0 -0
  350. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/extension-ui.d.ts +0 -0
  351. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/extension-ui.js +0 -0
  352. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/index.d.ts +0 -0
  353. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/index.js +0 -0
  354. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/model.js +0 -0
  355. /package/dist/{src/foundation/owned-ui-contracts → contracts/owned-ui}/validation.d.ts +0 -0
  356. /package/dist/{src/foundation/presentation-contracts → contracts/presentation}/index.d.ts +0 -0
  357. /package/dist/{src/foundation/presentation-contracts → contracts/presentation}/index.js +0 -0
  358. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/index.d.ts +0 -0
  359. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/index.js +0 -0
  360. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/model.d.ts +0 -0
  361. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/model.js +0 -0
  362. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/validation.d.ts +0 -0
  363. /package/dist/{src/foundation/workspace-contracts → contracts/workspace}/validation.js +0 -0
  364. /package/dist/{src/features → features}/launch/development-launch.d.ts +0 -0
  365. /package/dist/{src/features → features}/launch/initialize-profile.d.ts +0 -0
  366. /package/dist/{src/features → features}/launch/initialize-profile.js +0 -0
  367. /package/dist/{src/features → features}/launch/runtime-selection.js +0 -0
  368. /package/dist/{src/features → features}/workspace/capabilities.js +0 -0
  369. /package/dist/{src/features → features}/workspace/index.d.ts +0 -0
  370. /package/dist/{src/features → features}/workspace/index.js +0 -0
  371. /package/dist/{src/features → features}/workspace/presentation.d.ts +0 -0
  372. /package/dist/{src/features → features}/workspace/presentation.js +0 -0
  373. /package/dist/{src/features → features}/workspace/reconciliation.d.ts +0 -0
  374. /package/dist/{src/features → features}/workspace/reconciliation.js +0 -0
  375. /package/dist/{src/foundation → foundation}/launch-guardian/index.d.ts +0 -0
  376. /package/dist/{src/foundation → foundation}/launch-guardian/index.js +0 -0
  377. /package/dist/{src/foundation → foundation}/lifecycle/commands.d.ts +0 -0
  378. /package/dist/{src/foundation → foundation}/lifecycle/commands.js +0 -0
  379. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.d.ts +0 -0
  380. /package/dist/{src/foundation → foundation}/lifecycle/launch-instance.js +0 -0
  381. /package/dist/{src/foundation → foundation}/native-host-protocol/evidence.d.ts +0 -0
  382. /package/dist/{src/foundation → foundation}/native-host-protocol/evidence.js +0 -0
  383. /package/dist/{src/foundation → foundation}/native-host-protocol/index.d.ts +0 -0
  384. /package/dist/{src/foundation → foundation}/native-host-protocol/index.js +0 -0
  385. /package/dist/{src/foundation → foundation}/native-host-protocol/proof-gate.d.ts +0 -0
  386. /package/dist/{src/foundation → foundation}/native-host-protocol/proof-gate.js +0 -0
  387. /package/dist/{src/foundation → foundation}/process-containment/artifact.d.ts +0 -0
  388. /package/dist/{src/foundation → foundation}/process-containment/artifact.js +0 -0
  389. /package/dist/{src/foundation → foundation}/process-containment/contracts.d.ts +0 -0
  390. /package/dist/{src/foundation → foundation}/process-containment/contracts.js +0 -0
  391. /package/dist/{src/foundation → foundation}/protocol/index.d.ts +0 -0
  392. /package/dist/{src/foundation → foundation}/protocol/index.js +0 -0
  393. /package/dist/{src/foundation → foundation}/release/cohort-selection.d.ts +0 -0
  394. /package/dist/{src/foundation → foundation}/release/cohort-selection.js +0 -0
  395. /package/dist/{src/foundation → foundation}/release/concurrency.d.ts +0 -0
  396. /package/dist/{src/foundation → foundation}/release/concurrency.js +0 -0
  397. /package/dist/{src/foundation → foundation}/release/process-cleanup.d.ts +0 -0
  398. /package/dist/{src/foundation → foundation}/release/process-cleanup.js +0 -0
  399. /package/dist/{src/foundation → foundation}/release/stable-release.d.ts +0 -0
  400. /package/dist/{src/foundation → foundation}/release/stable-release.js +0 -0
  401. /package/dist/{src/foundation → foundation}/storage/index.d.ts +0 -0
  402. /package/dist/{src/foundation → foundation}/storage/index.js +0 -0
  403. /package/dist/{src/foundation → foundation}/structured-agent-runtime/index.d.ts +0 -0
  404. /package/dist/{src/foundation → foundation}/structured-agent-runtime/index.js +0 -0
  405. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/components.js +0 -0
  406. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/resources/builtin-themes.d.ts +0 -0
  407. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/resources/builtin-themes.js +0 -0
  408. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-editor-autocomplete.d.ts +0 -0
  409. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/shell-extension-ui.js +0 -0
  410. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.d.ts +0 -0
  411. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/theme.js +0 -0
  412. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/countdown-timer.d.ts +0 -0
  413. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/countdown-timer.js +0 -0
  414. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/custom-entry.d.ts +0 -0
  415. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/custom-entry.js +0 -0
  416. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/daxnuts.d.ts +0 -0
  417. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/daxnuts.js +0 -0
  418. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/earendil-announcement.d.ts +0 -0
  419. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/earendil-announcement.js +0 -0
  420. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/extension-editor.d.ts +0 -0
  421. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/extension-editor.js +0 -0
  422. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/first-time-setup.d.ts +0 -0
  423. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/first-time-setup.js +0 -0
  424. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/markdown-transform.d.ts +0 -0
  425. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/markdown-transform.js +0 -0
  426. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/mermaid.d.ts +0 -0
  427. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/mermaid.js +0 -0
  428. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/owned-editor.d.ts +0 -0
  429. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/owned-editor.js +0 -0
  430. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/scoped-models-selector.d.ts +0 -0
  431. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/scoped-models-selector.js +0 -0
  432. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-footer.js +0 -0
  433. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector-search.d.ts +0 -0
  434. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector-search.js +0 -0
  435. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector.d.ts +0 -0
  436. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/session-selector.js +0 -0
  437. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/skill-invocation-message.d.ts +0 -0
  438. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/skill-invocation-message.js +0 -0
  439. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/status-indicator.d.ts +0 -0
  440. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/status-indicator.js +0 -0
  441. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/tree-selector.d.ts +0 -0
  442. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/tree-selector.js +0 -0
  443. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/trust-selector.d.ts +0 -0
  444. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/components/trust-selector.js +0 -0
  445. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/external-editor.d.ts +0 -0
  446. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/external-editor.js +0 -0
  447. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/model-search.d.ts +0 -0
  448. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/model-search.js +0 -0
  449. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme-controller.d.ts +0 -0
  450. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme-controller.js +0 -0
  451. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme.d.ts +0 -0
  452. /package/dist/{src/foundation/pi-component-adapter → integrations/pi/components}/upstream/theme/theme.js +0 -0
  453. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/pi-settings-metadata.json +0 -0
  454. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.d.ts +0 -0
  455. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/public-main-entry.js +0 -0
  456. /package/dist/{src/foundation/pi-engine-adapter → integrations/pi/engine}/workflows.js +0 -0
  457. /package/dist/{src/foundation/pi-owned-ui-integration → integrations/pi/session-ui}/route-host.js +0 -0
  458. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/conformance.d.ts +0 -0
  459. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/conformance.js +0 -0
  460. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/contracts.js +0 -0
  461. /package/dist/{src/foundation/pi-tui-runtime-adapter → integrations/pi/tui-runtime}/presentation-adapter.js +0 -0
  462. /package/dist/{src/foundation/ui-apps → ui/apps}/contracts.js +0 -0
  463. /package/dist/{src/foundation/ui-apps → ui/apps}/index.d.ts +0 -0
  464. /package/dist/{src/foundation/ui-apps → ui/apps}/index.js +0 -0
  465. /package/dist/{src/foundation/ui-components → ui/components}/dialog-panel.d.ts +0 -0
  466. /package/dist/{src/foundation/ui-components → ui/components}/label.d.ts +0 -0
  467. /package/dist/{src/foundation/ui-components → ui/components}/label.js +0 -0
  468. /package/dist/{src/foundation/ui-components → ui/components}/list-block.d.ts +0 -0
  469. /package/dist/{src/foundation/ui-components → ui/components}/list-block.js +0 -0
  470. /package/dist/{src/foundation/ui-components → ui/components}/pane.d.ts +0 -0
  471. /package/dist/{src/foundation/ui-components → ui/components}/pane.js +0 -0
  472. /package/dist/{src/foundation/ui-components → ui/components}/revision.d.ts +0 -0
  473. /package/dist/{src/foundation/ui-components → ui/components}/revision.js +0 -0
  474. /package/dist/{src/foundation/ui-components → ui/components}/status-line.d.ts +0 -0
  475. /package/dist/{src/foundation/ui-components → ui/components}/status-line.js +0 -0
  476. /package/dist/{src/foundation/ui-components → ui/components}/stepper.d.ts +0 -0
  477. /package/dist/{src/foundation/ui-components → ui/components}/stepper.js +0 -0
  478. /package/dist/{src/foundation/ui-components → ui/components}/theme.d.ts +0 -0
  479. /package/dist/{src/foundation/ui-components → ui/components}/theme.js +0 -0
  480. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.d.ts +0 -0
  481. /package/dist/{src/foundation/ui-components → ui/components}/value-menu.js +0 -0
  482. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/index.d.ts +0 -0
  483. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/index.js +0 -0
  484. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.d.ts +0 -0
  485. /package/dist/{src/foundation/owned-ui-settings → ui/settings}/resolution.js +0 -0
@@ -0,0 +1,1158 @@
1
+ import { backgroundSgrSpan, composeSubmittedPromptRows, displayWidth, formatSubmittedPromptTime, heldNativeHyperlinkStyle, hyperlinkSgrSpan, nativeHyperlinkStyle, overlaySpan, progressStatusText, submittedPromptLayout, stripAnsi, } from "../../../ui/components/index.js";
2
+ import { PINNED_PI_HIDDEN_COMMAND_NAMES, PINNED_PI_WORKFLOW_COMMAND_NAMES, } from "../engine/index.js";
3
+ import { createPiExtensionUiBridge, createPiQueuedInputStatus, createPiShellArmin, createPiShellAuthProviderSelector, createPiShellChangelog, createPiShellCollapsedChangelog, createPiShellDaxnuts, createPiShellDialog, createPiShellEarendilAnnouncement, createPiShellEditor, createPiShellExtensionSelector, createPiShellFooter, createPiShellHeader, createPiShellHotkeys, createPiShellLoadedResources, createPiShellLoginDialog, createPiShellModelSelector, createPiShellOperationLoader, createPiShellReloadBox, createPiShellScopedModelsSelector, createPiShellSelector, createPiShellSessionInfo, createPiShellSessionSelector, createPiShellSettingsSelector, createPiShellStatus, createPiShellTranscriptComponent, createPiShellTreeSelector, createPiShellTrustSelector, createPiShellUserMessageSelector, onPiThemeChange, piShellVisibleWidth, piTheme, renderPiShellPackageUpdateNotice, renderPiShellStartupDiagnostic, renderPiShellStatusText, renderPiShellTranscriptBlock, } from "../components/index.js";
4
+ import { PiTuiRuntimeAdapter, classifyPiTuiInput, } from "../tui-runtime/index.js";
5
+ import { PromptChipStore } from "./prompt-chips.js";
6
+ import { SessionViewportController } from "./session-viewport-controller.js";
7
+ /** Composes backend session state into the owned transcript, viewport, editor, and dock presentation. */
8
+ export class OwnedUiSessionShellRoot {
9
+ editor;
10
+ header;
11
+ resources;
12
+ #cwd;
13
+ #transcript = new Map();
14
+ #blocksById = new Map();
15
+ #renderedRows = new Map();
16
+ // Performance: document layouts are shared by wheel, rail, jump, and selection frames.
17
+ #documentLayouts = new Map();
18
+ #themeUnsubscribe;
19
+ #transcriptOrder = [];
20
+ #view;
21
+ #status;
22
+ #footer;
23
+ #queued;
24
+ #extensionRenderers;
25
+ #imageAssets;
26
+ #promptChips = new PromptChipStore();
27
+ #customViewport;
28
+ #submittedPromptComposer;
29
+ #viewportController;
30
+ #viewportTheme;
31
+ #onViewportFrame;
32
+ #componentRuntime;
33
+ #toolsExpanded = false;
34
+ #thinkingVisible = true;
35
+ #mermaidRenderingMode = "off";
36
+ #showImages = true;
37
+ #imageWidthCells = 80;
38
+ #outputPad = 1;
39
+ #workflowTranscriptSequence = 0;
40
+ #workflowStatusAnchors = new Map();
41
+ #workflowStatusMessages = new Map();
42
+ #lastWorkflowStatusId;
43
+ #inputSurface;
44
+ #inputSurfaceCoordination = "editor";
45
+ #dockInputReuseEnabled;
46
+ #dockInputCandidate = false;
47
+ #dockInputSnapshot;
48
+ #dockInputStatusSignature;
49
+ #visibleViewportSnapshot;
50
+ #fullViewportCompositions = 0;
51
+ #dockOnlyViewportCompositions = 0;
52
+ #transcriptBlockRenders = 0;
53
+ #extensionHeader = null;
54
+ #extensionFooter = null;
55
+ #extensionWidgets = new Map();
56
+ #extensionStatuses = new Map();
57
+ #extensionWorkingMessage;
58
+ #extensionWorkingVisible = true;
59
+ constructor(view, cwd, handlers, startup = {}, agentDir, extensionRenderers = {
60
+ getMessageRenderer: () => undefined,
61
+ getToolDefinition: () => undefined,
62
+ }, sessionLayout = "pinned", imageAssets) {
63
+ this.#view = view;
64
+ this.#customViewport = sessionLayout === "custom-viewport";
65
+ this.#submittedPromptComposer = this.#customViewport
66
+ ? {
67
+ layout: submittedPromptLayout,
68
+ compose: (rows, width, source, style) => composeSubmittedPromptRows(rows, width, source, style)
69
+ .map(row => nativeHyperlinkStyle(row, nativeTranscriptLinkColor)),
70
+ }
71
+ : undefined;
72
+ this.#cwd = cwd;
73
+ this.#extensionRenderers = extensionRenderers;
74
+ this.#imageAssets = imageAssets;
75
+ this.#componentRuntime = handlers;
76
+ this.#onViewportFrame = handlers.onViewportFrame;
77
+ this.#dockInputReuseEnabled = handlers.enableDockInputReuse ?? true;
78
+ this.header = createPiShellHeader(startup);
79
+ this.resources = createPiShellLoadedResources(startup.resources ?? [], startup.expanded ?? false);
80
+ this.#status = createPiShellStatus(view, progressStatusText, handlers);
81
+ this.#footer = createPiShellFooter(this.#viewWithExtensionStatuses(view), cwd);
82
+ this.#queued = createPiQueuedInputStatus(view.editor.queuedSubmissions, this.#customViewport ? "custom-viewport" : "pinned");
83
+ this.editor = createPiShellEditor({
84
+ ...handlers,
85
+ keybindingProfile: this.#customViewport ? "a1" : "pi",
86
+ paintEditorSelection: (line, from, to, atomic) => backgroundSgrSpan(line, from, to, atomic ? "\u001b[7m" : "\u001b[27m\u001b[48;2;38;79;120m", atomic ? "\u001b[27m" : "\u001b[49m", piShellVisibleWidth),
87
+ transformPastedContent: content => this.#promptChips.transformPastedContent(content),
88
+ editorAtomicRanges: line => this.#promptChips.atomicRanges(line),
89
+ decorateEditorRow: (row, width) => {
90
+ const plain = stripAnsi(row);
91
+ const ranges = this.#promptChips.hyperlinkRanges(plain);
92
+ if (ranges.length === 0)
93
+ return row;
94
+ const linkResetAndTail = `\u001b]8;;\u001b\\\u001b[24m${" ".repeat(Math.max(0, width - piShellVisibleWidth(row)))}`;
95
+ // Platform: VS15 is zero-column and default-ignorable. It breaks Windows Terminal's
96
+ // plain-text URL detector only in the held-button paint; semantic text stays exact.
97
+ const paintRow = this.#viewportController.editorPointerSelecting
98
+ ? row.replaceAll("https://", "https:\uFE0E//").replaceAll("http://", "http:\uFE0E//")
99
+ : row;
100
+ const decorated = this.#viewportController.editorPointerSelecting
101
+ ? ranges.reduce((result, range) => backgroundSgrSpan(result, piShellVisibleWidth(plain.slice(0, range.start)), piShellVisibleWidth(plain.slice(0, range.end)), "\u001b[4:4m", "\u001b[24m", piShellVisibleWidth), paintRow)
102
+ : ranges.reduce((result, range) => hyperlinkSgrSpan(result, piShellVisibleWidth(plain.slice(0, range.start)), piShellVisibleWidth(plain.slice(0, range.end)), range.target, piShellVisibleWidth), row);
103
+ // Platform: Windows Terminal can retain stale native dotted-link cells when a mutable
104
+ // prompt replaces a longer URL. Explicit non-link spaces overwrite that tail.
105
+ return `${decorated}${linkResetAndTail}`;
106
+ },
107
+ expandCopiedEditorText: text => this.#promptChips.expandCopiedText(text),
108
+ cwd,
109
+ ...(agentDir === undefined ? {} : { agentDir }),
110
+ onToolsExpand: () => this.#setToolsExpanded(!this.#toolsExpanded),
111
+ });
112
+ this.#viewportController = new SessionViewportController({
113
+ enabled: this.#customViewport,
114
+ editor: this.editor,
115
+ requestRender: force => this.#componentRuntime.requestRender(force),
116
+ requestHyperlinkCleanup: () => handlers.requestHyperlinkCleanup?.(),
117
+ hasEditorLinks: () => this.#promptChips.hyperlinkRanges(this.editor.getText()).length > 0,
118
+ });
119
+ // Performance: stable painter identities let the neutral viewport retain row-level
120
+ // selection variants while each callback still resolves the live Pi theme.
121
+ this.#viewportTheme = {
122
+ track: text => `${SCROLLBAR_CELL_RESET}${piTheme().fg("dim", text)}`,
123
+ thumb: text => `${SCROLLBAR_CELL_RESET}${piTheme().fg("accent", text)}`,
124
+ sticky: (text, hovered) => piTheme().bg(hovered ? "selectedBg" : "toolPendingBg", piTheme().fg("text", withoutTerminalBackground(text))),
125
+ quietSticky: text => `\u001b[2m${text.replace(/\u001b\[(?:0|22)m/g, "$&\u001b[2m")}\u001b[22m`,
126
+ bottomControl: (text, hovered) => piTheme().bg(hovered ? "selectedBg" : "toolPendingBg", piTheme().fg("text", text)),
127
+ selection: (line, from, to) => backgroundSgrSpan(line, from, to, "\u001b[48;2;38;79;120m", "\u001b[49m"),
128
+ };
129
+ this.editor.setThinkingLevel(view.thinkingLevel);
130
+ this.#inputSurface = this.editor;
131
+ for (const block of view.transcript) {
132
+ if (block.kind === "user")
133
+ this.editor.addToHistory(block.text);
134
+ }
135
+ this.#syncTranscript(view.transcript);
136
+ // Invariant: colours come from the active theme, so rendered rows outlive their revision only
137
+ // until the theme under them changes.
138
+ this.#themeUnsubscribe = onPiThemeChange(() => {
139
+ this.#renderedRows.clear();
140
+ this.#documentLayouts.clear();
141
+ });
142
+ }
143
+ setEditorPaddingX(padding) {
144
+ this.editor.setPaddingX(padding);
145
+ this.#documentLayouts.clear();
146
+ }
147
+ setAutocompleteMaxVisible(maxVisible) {
148
+ this.editor.setAutocompleteMaxVisible(maxVisible);
149
+ }
150
+ setOutputPad(padding) {
151
+ if (this.#outputPad === padding)
152
+ return;
153
+ this.#outputPad = padding;
154
+ this.#status.setOutputPad(padding);
155
+ for (const component of this.#transcript.values())
156
+ component.setOutputPad(padding);
157
+ this.#invalidateTranscriptPresentation();
158
+ }
159
+ setHideThinkingBlock(hidden) {
160
+ if (this.#thinkingVisible === !hidden)
161
+ return;
162
+ this.#thinkingVisible = !hidden;
163
+ for (const component of this.#transcript.values())
164
+ component.setHideThinkingBlock(hidden);
165
+ this.#invalidateTranscriptPresentation();
166
+ }
167
+ setMermaidRenderingMode(mode) {
168
+ if (this.#mermaidRenderingMode === mode)
169
+ return;
170
+ this.#mermaidRenderingMode = mode;
171
+ for (const component of this.#transcript.values())
172
+ component.setMermaidRenderingMode(mode);
173
+ this.#invalidateTranscriptPresentation();
174
+ }
175
+ setImagePresentation(showImages, imageWidthCells) {
176
+ if (this.#showImages === showImages && this.#imageWidthCells === imageWidthCells)
177
+ return;
178
+ this.#showImages = showImages;
179
+ this.#imageWidthCells = imageWidthCells;
180
+ for (const component of this.#transcript.values())
181
+ component.setImagePresentation(showImages, imageWidthCells);
182
+ this.#invalidateTranscriptPresentation();
183
+ }
184
+ preparePromptSubmission(text) {
185
+ return this.#promptChips.prepareSubmission(text);
186
+ }
187
+ update(view) {
188
+ if (view.diagnostics.length !== this.#view.diagnostics.length
189
+ || view.diagnostics.some((diagnostic, index) => diagnostic.sequence !== this.#view.diagnostics[index]?.sequence)) {
190
+ this.#documentLayouts.clear();
191
+ }
192
+ this.#view = view;
193
+ this.#status.update(view);
194
+ this.#footer.update(this.#viewWithExtensionStatuses(view));
195
+ this.#queued.update(view.editor.queuedSubmissions);
196
+ this.#syncTranscript(view.transcript);
197
+ this.editor.setSubmitEnabled(view.lifecycle !== "stopping" && view.lifecycle !== "stopped" && view.lifecycle !== "failed");
198
+ this.editor.setThinkingLevel(view.thinkingLevel);
199
+ this.invalidate();
200
+ }
201
+ /**
202
+ * Applies one block: its component is created or updated in place and the order grows
203
+ * only when the block is new. A streamed chunk costs one component update rather than a
204
+ * walk of the whole transcript.
205
+ */
206
+ applyTranscriptBlock(block) {
207
+ this.#blocksById.set(block.id, block);
208
+ const component = this.#transcript.get(block.id);
209
+ if (component === undefined) {
210
+ const created = createPiShellTranscriptComponent(block, this.#cwd, this.#extensionRenderers, this.#submittedPromptComposer, this.#outputPad, !this.#thinkingVisible, this.#mermaidRenderingMode, this.#showImages, this.#imageWidthCells, this.#imageAssets);
211
+ created.setExpanded(this.#toolsExpanded);
212
+ this.#transcript.set(block.id, created);
213
+ this.#transcriptOrder.push(block.id);
214
+ }
215
+ else if (component.revision !== block.revision) {
216
+ component.update(block);
217
+ }
218
+ // Performance: one chunk touches one block, and the updated component tracks its own dirtiness.
219
+ // Invalidating the whole shell here would re-wrap the entire transcript per chunk.
220
+ this.#renderedRows.delete(block.id);
221
+ this.#documentLayouts.clear();
222
+ }
223
+ render(width) {
224
+ if (!this.#customViewport) {
225
+ this.#viewportController.setEditorPointerFrame(undefined);
226
+ return [...this.#renderDocument(width), ...this.#renderDock(width)];
227
+ }
228
+ const height = Math.max(0, this.#componentRuntime.getRows());
229
+ const dock = this.#renderDockLayout(width);
230
+ // Invariant: ordinary transcript content uses the full terminal width. The rail is an
231
+ // overlay, not a lost wrapping cell. Submitted prompts alone retain the
232
+ // intentional final gutter after their right-aligned timestamp.
233
+ const documentWidth = width;
234
+ const document = this.#renderDocumentLayout(documentWidth);
235
+ const statusRows = this.#renderStatus(width);
236
+ const statusSignature = statusRows.length === 0 ? undefined : `${statusRows.length}\u0000${statusRows.join("\u0000")}`;
237
+ const snapshot = this.#visibleViewportSnapshot;
238
+ const dockInputCandidate = this.#dockInputCandidate;
239
+ const dockInputSnapshot = dockInputCandidate ? this.#dockInputSnapshot : undefined;
240
+ const dockInputStatusSignature = dockInputCandidate ? this.#dockInputStatusSignature : statusSignature;
241
+ // Invariant: queued rows stay docked while live Working rows form one scrollable tail.
242
+ const scrollRows = [...document.rows, ...statusRows];
243
+ const dockRows = dock.rows;
244
+ const selectableDocumentRowCount = document.rows.length;
245
+ const dockStartRow = height - dockRows.length + 1;
246
+ const editorOffset = dock.editorOffset;
247
+ this.#viewportController.setEditorPointerFrame(this.usesDefaultInputSurface()
248
+ ? {
249
+ rowStart: dockStartRow + editorOffset,
250
+ rowEnd: dockStartRow + editorOffset + dock.inputRows - 1,
251
+ }
252
+ : undefined);
253
+ this.#dockInputCandidate = false;
254
+ let frame = dockInputCandidate
255
+ && snapshot !== undefined
256
+ && snapshot.width === width
257
+ && snapshot.height === height
258
+ && snapshot.documentRows === (dockInputSnapshot?.documentRows ?? scrollRows)
259
+ && snapshot.statusSignature === dockInputStatusSignature
260
+ && snapshot.promptAnchors === (dockInputSnapshot?.promptAnchors ?? document.promptAnchors)
261
+ && snapshot.dockLength === dockRows.length
262
+ && snapshot.inputSurface === (dockInputSnapshot?.inputSurface ?? this.#inputSurface)
263
+ && snapshot.viewportRevision === (dockInputSnapshot?.viewportRevision ?? this.#viewportController.presentationRevision)
264
+ && snapshot.selectionRevision === (dockInputSnapshot?.selectionRevision ?? this.#viewportController.selectionRevision)
265
+ ? this.#viewportController.composeDockOnly(dockRows, width, height)
266
+ : null;
267
+ // Performance: a still-active spinner can tick before its first delayed presentation.
268
+ // Its newest tail signature is recomputed below and therefore cannot hide that change.
269
+ if (frame !== null && dockInputStatusSignature !== statusSignature)
270
+ frame = null;
271
+ if (frame === null) {
272
+ frame = this.#viewportController.compose({
273
+ documentRows: scrollRows,
274
+ ...(this.#viewportController.transcriptPointerSelecting
275
+ ? { paintDocumentRow: heldNativeHyperlinkStyle }
276
+ : {}),
277
+ // Invariant: selection and copying stop at the real document tail; live Working
278
+ // rows remain transient presentation chrome at every fit boundary.
279
+ selectableDocumentRowCount,
280
+ dockRows,
281
+ promptAnchors: document.promptAnchors,
282
+ width,
283
+ height,
284
+ // Invariant: the control belongs immediately above the complete dock,
285
+ // never on top of a queued or Working row.
286
+ bottomControlRow: Math.max(0, height - Math.min(height, dockRows.length) - 1),
287
+ theme: this.#viewportTheme,
288
+ });
289
+ this.#fullViewportCompositions += 1;
290
+ }
291
+ else
292
+ this.#dockOnlyViewportCompositions += 1;
293
+ this.#visibleViewportSnapshot = {
294
+ width,
295
+ height,
296
+ documentRows: scrollRows,
297
+ statusSignature,
298
+ dockInputStatusSignature,
299
+ promptAnchors: document.promptAnchors,
300
+ dockLength: dockRows.length,
301
+ inputSurface: this.#inputSurface,
302
+ viewportRevision: this.#viewportController.presentationRevision,
303
+ selectionRevision: this.#viewportController.selectionRevision,
304
+ };
305
+ this.#onViewportFrame?.(frame);
306
+ return frame.rows;
307
+ }
308
+ viewportFrameDescriptor() {
309
+ return this.#viewportController.frame?.descriptor ?? null;
310
+ }
311
+ /** Visible rows of the transient working-status tail, for rendering evidence. */
312
+ viewportTransientTailRowCount() {
313
+ return this.#viewportController.frame?.hits.transientTail.length ?? 0;
314
+ }
315
+ hasActiveSelection() {
316
+ return this.#viewportController.hasSelection || this.editor.hasSelection();
317
+ }
318
+ setViewportConfig(config) {
319
+ if (this.#viewportController.setConfig(config))
320
+ this.#documentLayouts.clear();
321
+ }
322
+ resumeViewportFollowing() {
323
+ this.#viewportController.resumeFollowing();
324
+ }
325
+ noteCompletedAssistantMessage() {
326
+ this.#viewportController.noteCompletedAssistantMessage();
327
+ }
328
+ resetViewport() {
329
+ this.#viewportController.reset();
330
+ }
331
+ clearViewportPointerState() {
332
+ this.#viewportController.clearPointerState();
333
+ }
334
+ handleViewportPreInput(data, allowWheel = true, now = Date.now()) {
335
+ return this.#viewportController.handlePreInput(data, allowWheel, now);
336
+ }
337
+ #renderDock(width) {
338
+ return this.#renderDockLayout(width).rows;
339
+ }
340
+ #renderDockLayout(width) {
341
+ const queued = this.#view.editor.queuedSubmissions.length === 0 ? [] : this.#queued.render(width);
342
+ const statusRows = this.#customViewport ? this.#status.renderDock(width) : this.#renderStatus(width);
343
+ const transientRows = [...queued, ...statusRows];
344
+ const aboveWidgets = this.#renderWidgets("aboveEditor", width);
345
+ const input = this.#inputSurface.render(width);
346
+ const belowWidgets = this.#renderWidgets("belowEditor", width);
347
+ const footer = this.#renderFooter(width);
348
+ const rowsWithoutTransient = [...aboveWidgets, ...input, ...belowWidgets, ...footer];
349
+ return {
350
+ rows: [...transientRows, ...rowsWithoutTransient],
351
+ editorOffset: transientRows.length + aboveWidgets.length,
352
+ inputRows: input.length,
353
+ };
354
+ }
355
+ layoutRoot() {
356
+ const document = layoutPort(width => this.#renderDocument(width), () => this.invalidate());
357
+ const queued = layoutPort(width => this.#view.editor.queuedSubmissions.length === 0 ? [] : this.#queued.render(width), () => this.#queued.invalidate());
358
+ const aboveWidgets = layoutPort(width => this.#renderWidgets("aboveEditor", width), () => this.#invalidateExtensions());
359
+ const status = layoutPort(width => this.#renderStatus(width), () => this.#status.invalidate());
360
+ const editor = layoutPort(width => this.#inputSurface.render(width), () => this.#inputSurface.invalidate(), data => this.#inputSurface.handleInput?.(data));
361
+ const belowWidgets = layoutPort(width => this.#renderWidgets("belowEditor", width), () => this.#invalidateExtensions());
362
+ const footer = layoutPort(width => this.#renderFooter(width), () => (this.#extensionFooter ?? this.#footer).invalidate());
363
+ return {
364
+ type: "stack",
365
+ direction: "vertical",
366
+ children: [
367
+ {
368
+ basis: 0,
369
+ grow: 1,
370
+ shrink: 1,
371
+ minSize: 1,
372
+ node: {
373
+ type: "scroll",
374
+ id: "transcript",
375
+ follow: "end",
376
+ primary: true,
377
+ overscroll: "chain",
378
+ scrollbar: "auto",
379
+ scrollbarStyle: text => piTheme().bg("scrollbarThumb", text),
380
+ child: { type: "component", component: document },
381
+ },
382
+ },
383
+ {
384
+ basis: "auto",
385
+ grow: 0,
386
+ shrink: 1,
387
+ minSize: 1,
388
+ node: {
389
+ type: "stack",
390
+ direction: "vertical",
391
+ children: [
392
+ { shrink: 1, minSize: 0, node: { type: "component", component: queued } },
393
+ { shrink: 1, minSize: 0, node: { type: "component", component: status } },
394
+ { shrink: 1, minSize: 0, node: { type: "component", component: aboveWidgets } },
395
+ { shrink: 1, minSize: 3, node: { type: "component", component: editor } },
396
+ { shrink: 1, minSize: 0, node: { type: "component", component: belowWidgets } },
397
+ { shrink: 1, minSize: 1, node: { type: "component", component: footer } },
398
+ ],
399
+ },
400
+ },
401
+ ],
402
+ };
403
+ }
404
+ #renderDocument(width) {
405
+ return this.#renderDocumentLayout(width).rows;
406
+ }
407
+ #renderDocumentLayout(width) {
408
+ // Performance: extension headers may animate independently of transcript revisions, so
409
+ // only the stable built-in document participates in this frame cache.
410
+ const cached = this.#extensionHeader === null ? this.#documentLayouts.get(width) : undefined;
411
+ if (cached !== undefined)
412
+ return cached;
413
+ const diagnostics = this.#view.diagnostics;
414
+ const startupRows = diagnostics
415
+ .filter(diagnostic => diagnostic.code === "engine-startup")
416
+ .flatMap(diagnostic => renderPiShellStartupDiagnostic(diagnostic, width));
417
+ const resourceRows = this.#customViewport ? [] : [...this.resources.render(width)];
418
+ if (resourceRows.at(-1) === "")
419
+ resourceRows.pop();
420
+ const headerRows = this.#extensionHeader !== null
421
+ ? this.#extensionHeader.render(width)
422
+ : this.#customViewport ? [] : this.header.render(width);
423
+ const rows = [
424
+ ...startupRows,
425
+ ...headerRows,
426
+ ...resourceRows,
427
+ ];
428
+ const promptAnchors = [];
429
+ for (let index = 0; index < this.#transcriptOrder.length; index += 1) {
430
+ const id = this.#transcriptOrder[index];
431
+ const block = this.#blocksById.get(id);
432
+ if (!this.#thinkingVisible && block?.kind === "thinking")
433
+ continue;
434
+ const blockWidth = this.#customViewport
435
+ && block?.kind === "user"
436
+ && this.#viewportController.config.scrollbarAppearance !== "hidden"
437
+ && width > 1
438
+ ? width - 1
439
+ : width;
440
+ const blockRows = this.#blockRows(id, block, blockWidth);
441
+ if (block?.kind === "user") {
442
+ // Compatibility: the first natural prompt gets one breathing row at the document top.
443
+ // Once scrolling advances, the prompt itself reaches row zero and then
444
+ // becomes sticky there, so the spacer is never pinned with it.
445
+ if (this.#customViewport && index === 0)
446
+ rows.push("");
447
+ else if (index > 0)
448
+ rows.push("");
449
+ }
450
+ const firstRow = rows.length;
451
+ rows.push(...blockRows);
452
+ if (block?.kind === "user" && blockRows[0] !== undefined) {
453
+ promptAnchors.push({
454
+ id: block.id,
455
+ firstRow,
456
+ lastRow: Math.max(firstRow, rows.length - 1),
457
+ sourceRow: pinnedPromptSourceRow(block, blockRows[0], blockWidth),
458
+ });
459
+ }
460
+ }
461
+ rows.push(...diagnostics
462
+ .filter(diagnostic => diagnostic.code === "package-updates")
463
+ .flatMap(diagnostic => renderPiShellPackageUpdateNotice(diagnostic.message.split("\n").filter(line => line.startsWith("- ")).map(line => line.slice(2)), width)));
464
+ rows.push(...diagnostics
465
+ .filter(diagnostic => diagnostic.code === "changelog-collapsed" || diagnostic.code === "changelog-expanded")
466
+ .flatMap(diagnostic => diagnostic.code === "changelog-collapsed"
467
+ ? createPiShellCollapsedChangelog().render(width)
468
+ : createPiShellChangelog(diagnostic.message).render(width)));
469
+ rows.push(...diagnostics
470
+ .filter(diagnostic => diagnostic.code !== "engine-startup" && diagnostic.code !== "package-updates"
471
+ && diagnostic.code !== "changelog-collapsed" && diagnostic.code !== "changelog-expanded")
472
+ .slice(-3)
473
+ .flatMap(diagnostic => renderPiShellTranscriptBlock({
474
+ id: `diagnostic-${diagnostic.sequence}`,
475
+ kind: diagnostic.severity === "error" ? "error" : "system",
476
+ status: "finalized",
477
+ revision: diagnostic.sequence,
478
+ title: diagnostic.code,
479
+ text: diagnostic.message,
480
+ payload: {},
481
+ }, width, this.#cwd)));
482
+ const layout = { rows: Object.freeze(rows), promptAnchors: Object.freeze(promptAnchors) };
483
+ if (this.#extensionHeader === null) {
484
+ this.#documentLayouts.set(width, layout);
485
+ // Performance: the custom viewport commonly probes full width and reserved-rail width.
486
+ while (this.#documentLayouts.size > 2)
487
+ this.#documentLayouts.delete(this.#documentLayouts.keys().next().value);
488
+ }
489
+ return layout;
490
+ }
491
+ // Performance: finalized blocks cache by revision and width; live blocks always render.
492
+ #blockRows(id, block, width) {
493
+ const component = this.#transcript.get(id);
494
+ if (component === undefined)
495
+ return [];
496
+ const render = () => {
497
+ this.#transcriptBlockRenders += 1;
498
+ const rows = component.render(width);
499
+ if (!this.#customViewport || block?.kind === "user")
500
+ return rows;
501
+ return rows.map(row => nativeHyperlinkStyle(row, nativeTranscriptLinkColor));
502
+ };
503
+ if (block === undefined || block.status !== "finalized")
504
+ return render();
505
+ let byWidth = this.#renderedRows.get(id);
506
+ const cached = byWidth?.get(width);
507
+ if (cached?.revision === block.revision)
508
+ return cached.rows;
509
+ const rows = render();
510
+ if (byWidth === undefined) {
511
+ byWidth = new Map();
512
+ this.#renderedRows.set(id, byWidth);
513
+ }
514
+ byWidth.set(width, { revision: block.revision, rows });
515
+ // Invariant: bare A1 probes full width before reserving the overflowing rail column;
516
+ // retain both widths without turning resize history into an unbounded cache.
517
+ while (byWidth.size > 2)
518
+ byWidth.delete(byWidth.keys().next().value);
519
+ return rows;
520
+ }
521
+ transcriptComponent(id) {
522
+ return this.#transcript.get(id);
523
+ }
524
+ exitTranscript(width) {
525
+ const rows = [];
526
+ for (const id of this.#transcriptOrder) {
527
+ const block = this.#blocksById.get(id);
528
+ if (block === undefined || (!this.#thinkingVisible && block.kind === "thinking"))
529
+ continue;
530
+ if (rows.length > 0 && block.kind === "user")
531
+ rows.push("");
532
+ rows.push(...this.#blockRows(id, block, width).map(sanitizeExitTranscriptRow));
533
+ }
534
+ while (rows.at(-1) === "")
535
+ rows.pop();
536
+ return rows.join("\n");
537
+ }
538
+ appendWorkflowStatus(message) {
539
+ const previousId = this.#lastWorkflowStatusId;
540
+ if (previousId !== undefined
541
+ && this.#transcriptOrder.at(-1) === previousId
542
+ && this.#workflowStatusAnchors.get(previousId) === this.#view.transcript.length) {
543
+ this.#workflowStatusMessages.set(previousId, message);
544
+ this.#documentLayouts.clear();
545
+ this.invalidate();
546
+ return;
547
+ }
548
+ const id = this.#appendAnchoredWorkflowComponent(width => [
549
+ "",
550
+ ...renderPiShellStatusText(this.#workflowStatusMessages.get(id) ?? message, width, this.#outputPad),
551
+ ]);
552
+ this.#workflowStatusMessages.set(id, message);
553
+ this.#lastWorkflowStatusId = id;
554
+ }
555
+ appendWorkflowMessage(message) {
556
+ if (message.kind === "status") {
557
+ this.appendWorkflowStatus(message.message);
558
+ return;
559
+ }
560
+ this.#lastWorkflowStatusId = undefined;
561
+ const prefix = message.kind === "warning" ? "Warning" : message.kind === "error" ? "Error" : undefined;
562
+ const color = message.kind === "accent" ? "accent" : message.kind;
563
+ const text = prefix === undefined ? message.message : `${prefix}: ${message.message}`;
564
+ this.#appendAnchoredWorkflowComponent(() => ["", ` ${piTheme().fg(color, text)}`]);
565
+ }
566
+ appendWorkflowResult(result) {
567
+ if (result.messages !== undefined) {
568
+ for (const message of result.messages)
569
+ this.appendWorkflowMessage(message);
570
+ return;
571
+ }
572
+ if (result.messageKind === "silent" || (result.outcome === "cancelled" && result.messageKind === undefined))
573
+ return;
574
+ if (result.command === "reload" && result.outcome === "completed") {
575
+ this.appendWorkflowStatus(result.message);
576
+ return;
577
+ }
578
+ if (result.command === "session" && result.outcome === "completed" && result.presentation?.kind === "session-info") {
579
+ this.#lastWorkflowStatusId = undefined;
580
+ const sessionInfo = createPiShellSessionInfo(result.presentation);
581
+ this.#appendAnchoredWorkflowComponent(width => sessionInfo.render(width), () => sessionInfo.dispose?.());
582
+ return;
583
+ }
584
+ if (result.command === "hotkeys" && result.outcome === "completed") {
585
+ this.#lastWorkflowStatusId = undefined;
586
+ const hotkeys = createPiShellHotkeys();
587
+ this.#appendAnchoredWorkflowComponent(width => hotkeys.render(width), () => hotkeys.dispose?.());
588
+ return;
589
+ }
590
+ if (result.command === "changelog" && result.outcome === "completed") {
591
+ this.#lastWorkflowStatusId = undefined;
592
+ const changelog = createPiShellChangelog(result.detail ?? "No changelog entries found.");
593
+ this.#appendAnchoredWorkflowComponent(width => changelog.render(width), () => changelog.dispose?.());
594
+ return;
595
+ }
596
+ if (result.outcome === "failed") {
597
+ this.appendWorkflowMessage({
598
+ kind: result.messageKind === "warning" ? "warning" : "error",
599
+ message: result.message,
600
+ });
601
+ return;
602
+ }
603
+ if (result.outcome === "completed" && (result.command === "quit" || result.command === "compact"))
604
+ return;
605
+ if (result.command === "new" && result.outcome === "completed") {
606
+ this.appendWorkflowMessage({ kind: "accent", message: result.message });
607
+ return;
608
+ }
609
+ if (result.command === "name" && result.outcome === "completed") {
610
+ this.#lastWorkflowStatusId = undefined;
611
+ this.#appendAnchoredWorkflowComponent(() => [
612
+ ...(result.detail ? ["", ` ${piTheme().fg("warning", `Warning: ${result.detail}`)}`] : []),
613
+ "",
614
+ ` ${piTheme().fg("dim", result.message)}`,
615
+ ]);
616
+ return;
617
+ }
618
+ if (result.command === "debug" && result.outcome === "completed") {
619
+ this.#lastWorkflowStatusId = undefined;
620
+ this.#appendAnchoredWorkflowComponent(() => [
621
+ "",
622
+ ` ${piTheme().fg("accent", result.message)}`,
623
+ ...(result.detail ? [` ${piTheme().fg("muted", result.detail)}`] : []),
624
+ ]);
625
+ return;
626
+ }
627
+ if (result.command === "arminsayshi" && result.outcome === "completed") {
628
+ this.#lastWorkflowStatusId = undefined;
629
+ const armin = createPiShellArmin(this.#componentRuntime);
630
+ this.#appendAnchoredWorkflowComponent(width => ["", ...armin.render(width)], () => armin.dispose?.());
631
+ return;
632
+ }
633
+ if (result.command === "dementedelves" && result.outcome === "completed") {
634
+ this.#lastWorkflowStatusId = undefined;
635
+ const announcement = createPiShellEarendilAnnouncement();
636
+ this.#appendAnchoredWorkflowComponent(width => ["", ...announcement.render(width)], () => announcement.dispose?.());
637
+ return;
638
+ }
639
+ const message = result.command === "share" && result.detail
640
+ ? `${result.message}\nGist: ${result.detail}`
641
+ : result.message;
642
+ this.appendWorkflowStatus(message);
643
+ }
644
+ appendDaxnuts() {
645
+ this.#lastWorkflowStatusId = undefined;
646
+ const daxnuts = createPiShellDaxnuts(this.#componentRuntime);
647
+ this.#appendAnchoredWorkflowComponent(width => ["", ...daxnuts.render(width)], () => daxnuts.dispose?.());
648
+ }
649
+ toggleThinkingVisibility() {
650
+ this.setHideThinkingBlock(this.#thinkingVisible);
651
+ }
652
+ get toolsExpanded() {
653
+ return this.#toolsExpanded;
654
+ }
655
+ setToolsExpanded(expanded) {
656
+ this.#setToolsExpanded(expanded);
657
+ }
658
+ setExtensionWidget(key, component, placement) {
659
+ const previous = this.#extensionWidgets.get(key)?.component;
660
+ if (component === null)
661
+ this.#extensionWidgets.delete(key);
662
+ else
663
+ this.#extensionWidgets.set(key, { component, placement });
664
+ if (previous !== undefined && previous !== component)
665
+ previous.dispose?.();
666
+ this.invalidate();
667
+ }
668
+ setExtensionHeader(component) {
669
+ if (this.#extensionHeader !== component)
670
+ this.#extensionHeader?.dispose?.();
671
+ this.#extensionHeader = component;
672
+ this.#documentLayouts.clear();
673
+ this.invalidate();
674
+ }
675
+ setExtensionFooter(component) {
676
+ if (this.#extensionFooter !== component)
677
+ this.#extensionFooter?.dispose?.();
678
+ this.#extensionFooter = component;
679
+ this.invalidate();
680
+ }
681
+ setExtensionStatus(key, text) {
682
+ if (text === undefined)
683
+ this.#extensionStatuses.delete(key);
684
+ else
685
+ this.#extensionStatuses.set(key, text);
686
+ this.#footer.update(this.#viewWithExtensionStatuses(this.#view));
687
+ this.invalidate();
688
+ }
689
+ setExtensionWorking(message, visible = this.#extensionWorkingVisible) {
690
+ this.#extensionWorkingMessage = message;
691
+ this.#extensionWorkingVisible = visible;
692
+ this.#status.setWorkingOverride(visible ? message : undefined);
693
+ this.invalidate();
694
+ }
695
+ resetWorkflowPresentation() {
696
+ for (const id of this.#workflowStatusAnchors.keys()) {
697
+ this.#transcript.get(id)?.dispose?.();
698
+ this.#transcript.delete(id);
699
+ }
700
+ this.#workflowStatusAnchors.clear();
701
+ this.#workflowStatusMessages.clear();
702
+ this.#transcriptOrder = this.#transcriptOrder.filter(id => !id.startsWith("workflow-status-"));
703
+ this.#lastWorkflowStatusId = undefined;
704
+ this.#documentLayouts.clear();
705
+ this.invalidate();
706
+ }
707
+ resetExtensionUi() {
708
+ this.#extensionHeader?.dispose?.();
709
+ this.#extensionFooter?.dispose?.();
710
+ for (const { component } of this.#extensionWidgets.values())
711
+ component.dispose?.();
712
+ this.#extensionHeader = null;
713
+ this.#extensionFooter = null;
714
+ this.#extensionWidgets.clear();
715
+ this.#extensionStatuses.clear();
716
+ this.#extensionWorkingMessage = undefined;
717
+ this.#status.setWorkingOverride(undefined);
718
+ this.#footer.update(this.#viewWithExtensionStatuses(this.#view));
719
+ // Invariant: an extension renderer may have drawn transcript blocks that are now unrendered by it.
720
+ this.#renderedRows.clear();
721
+ this.#documentLayouts.clear();
722
+ this.invalidate();
723
+ }
724
+ addExtensionNotification(message, type) {
725
+ if (type === "info") {
726
+ this.appendWorkflowStatus(message);
727
+ return;
728
+ }
729
+ this.#lastWorkflowStatusId = undefined;
730
+ const prefix = type === "warning" ? "Warning" : "Error";
731
+ this.#appendAnchoredWorkflowComponent(() => ["", ` ${piTheme().fg(type, `${prefix}: ${message}`)}`]);
732
+ }
733
+ extensionFooterData() {
734
+ return {
735
+ getGitBranch: () => this.#view.status.footer?.branch ?? null,
736
+ getExtensionStatuses: () => new Map(this.#extensionStatuses),
737
+ getAvailableProviderCount: () => this.#view.status.footer?.availableProviderCount ?? 1,
738
+ onBranchChange: () => () => { },
739
+ };
740
+ }
741
+ usesDefaultInputSurface() {
742
+ return this.#inputSurface === this.editor;
743
+ }
744
+ inputCoordinationSurface() {
745
+ return this.#inputSurfaceCoordination;
746
+ }
747
+ viewportCompositionEvidence() {
748
+ return { full: this.#fullViewportCompositions, dockOnly: this.#dockOnlyViewportCompositions };
749
+ }
750
+ transcriptRenderCount() {
751
+ return this.#transcriptBlockRenders;
752
+ }
753
+ setInputSurface(component, disposePrevious = true, coordination = "owned") {
754
+ const next = component ?? this.editor;
755
+ const nextCoordination = next === this.editor ? "editor" : coordination;
756
+ if (next === this.#inputSurface) {
757
+ this.#inputSurfaceCoordination = nextCoordination;
758
+ return;
759
+ }
760
+ this.#dockInputCandidate = false;
761
+ this.#inputSurface.setFocused?.(false);
762
+ if (disposePrevious && this.#inputSurface !== this.editor)
763
+ this.#inputSurface.dispose?.();
764
+ this.#inputSurface = next;
765
+ this.#inputSurfaceCoordination = nextCoordination;
766
+ this.#inputSurface.setFocused?.(true);
767
+ this.invalidate();
768
+ }
769
+ handleInput(data) {
770
+ this.#dockInputCandidate = this.#customViewport && this.#dockInputReuseEnabled
771
+ && classifyPiTuiInput(data, this.#inputSurfaceCoordination) === "safe";
772
+ if (this.#dockInputCandidate)
773
+ this.#captureDockInputSnapshot();
774
+ try {
775
+ this.#inputSurface.handleInput?.(data);
776
+ }
777
+ catch (error) {
778
+ this.#dockInputCandidate = false;
779
+ throw error;
780
+ }
781
+ }
782
+ #captureDockInputSnapshot() {
783
+ const width = Math.max(1, this.#componentRuntime.getColumns());
784
+ const statusRows = this.#renderStatus(width);
785
+ this.#dockInputStatusSignature = statusRows.length === 0 ? undefined : `${statusRows.length}\u0000${statusRows.join("\u0000")}`;
786
+ const snapshot = this.#visibleViewportSnapshot;
787
+ this.#dockInputSnapshot = snapshot === undefined
788
+ ? undefined
789
+ : {
790
+ documentRows: snapshot.documentRows,
791
+ statusSignature: this.#dockInputStatusSignature,
792
+ promptAnchors: snapshot.promptAnchors,
793
+ inputSurface: this.#inputSurface,
794
+ viewportRevision: this.#viewportController.presentationRevision,
795
+ selectionRevision: this.#viewportController.selectionRevision,
796
+ };
797
+ }
798
+ invalidate() {
799
+ this.header.invalidate();
800
+ this.resources.invalidate();
801
+ for (const component of this.#transcript.values())
802
+ component.invalidate();
803
+ this.editor.invalidate();
804
+ if (this.#inputSurface !== this.editor)
805
+ this.#inputSurface.invalidate();
806
+ this.#invalidateExtensions();
807
+ this.#status.invalidate();
808
+ this.#footer.invalidate();
809
+ this.#queued.invalidate();
810
+ }
811
+ setFocused(focused) {
812
+ this.#inputSurface.setFocused?.(focused);
813
+ }
814
+ dispose() {
815
+ this.clearViewportPointerState();
816
+ this.#themeUnsubscribe();
817
+ this.header.dispose?.();
818
+ this.resources.dispose?.();
819
+ for (const component of this.#transcript.values())
820
+ component.dispose?.();
821
+ this.#transcript.clear();
822
+ this.#renderedRows.clear();
823
+ this.#documentLayouts.clear();
824
+ this.#visibleViewportSnapshot = undefined;
825
+ this.#dockInputCandidate = false;
826
+ this.#dockInputSnapshot = undefined;
827
+ this.#dockInputStatusSignature = undefined;
828
+ if (this.#inputSurface !== this.editor)
829
+ this.#inputSurface.dispose?.();
830
+ this.#extensionHeader?.dispose?.();
831
+ this.#extensionFooter?.dispose?.();
832
+ for (const { component } of this.#extensionWidgets.values())
833
+ component.dispose?.();
834
+ this.#extensionWidgets.clear();
835
+ this.editor.dispose?.();
836
+ this.#status.dispose?.();
837
+ this.#footer.dispose?.();
838
+ this.#queued.dispose?.();
839
+ }
840
+ #invalidateTranscriptPresentation() {
841
+ this.#renderedRows.clear();
842
+ this.#documentLayouts.clear();
843
+ this.invalidate();
844
+ }
845
+ #syncTranscript(blocks) {
846
+ const previousIds = this.#transcriptOrder.filter(id => !id.startsWith("workflow-status-"));
847
+ const transcriptChanged = previousIds.length !== blocks.length || blocks.some((block, index) => {
848
+ const previous = this.#blocksById.get(block.id);
849
+ return previousIds[index] !== block.id || previous?.revision !== block.revision;
850
+ });
851
+ if (transcriptChanged)
852
+ this.#documentLayouts.clear();
853
+ this.#blocksById.clear();
854
+ for (const block of blocks)
855
+ this.#blocksById.set(block.id, block);
856
+ const nextIds = new Set(blocks.map(block => block.id));
857
+ for (const [id, component] of this.#transcript) {
858
+ if (id.startsWith("workflow-status-") || nextIds.has(id))
859
+ continue;
860
+ component.dispose?.();
861
+ this.#transcript.delete(id);
862
+ this.#renderedRows.delete(id);
863
+ }
864
+ for (const block of blocks) {
865
+ const component = this.#transcript.get(block.id);
866
+ if (component === undefined) {
867
+ const created = createPiShellTranscriptComponent(block, this.#cwd, this.#extensionRenderers, this.#submittedPromptComposer, this.#outputPad, !this.#thinkingVisible, this.#mermaidRenderingMode, this.#showImages, this.#imageWidthCells, this.#imageAssets);
868
+ created.setExpanded(this.#toolsExpanded);
869
+ this.#transcript.set(block.id, created);
870
+ }
871
+ else if (component.revision !== block.revision) {
872
+ component.update(block);
873
+ }
874
+ }
875
+ const statusIds = [...this.#workflowStatusAnchors.keys()];
876
+ const order = [];
877
+ for (let index = 0; index <= blocks.length; index += 1) {
878
+ for (const statusId of statusIds) {
879
+ if (this.#workflowStatusAnchors.get(statusId) === index)
880
+ order.push(statusId);
881
+ }
882
+ const block = blocks[index];
883
+ if (block !== undefined)
884
+ order.push(block.id);
885
+ }
886
+ const placed = new Set(order);
887
+ for (const statusId of statusIds) {
888
+ if (!placed.has(statusId))
889
+ order.push(statusId);
890
+ }
891
+ this.#transcriptOrder = order;
892
+ }
893
+ #appendAnchoredWorkflowComponent(render, dispose) {
894
+ this.#workflowTranscriptSequence += 1;
895
+ const id = `workflow-status-${this.#workflowTranscriptSequence}`;
896
+ const component = {
897
+ id,
898
+ revision: 1,
899
+ render,
900
+ handleInput() { },
901
+ invalidate() { },
902
+ update() { },
903
+ setExpanded() { },
904
+ setOutputPad() { },
905
+ setHideThinkingBlock() { },
906
+ setMermaidRenderingMode() { },
907
+ setImagePresentation() { },
908
+ ...(dispose === undefined ? {} : { dispose }),
909
+ };
910
+ this.#transcript.set(id, component);
911
+ this.#workflowStatusAnchors.set(id, this.#view.transcript.length);
912
+ this.#transcriptOrder.push(id);
913
+ this.#documentLayouts.clear();
914
+ this.invalidate();
915
+ return id;
916
+ }
917
+ #renderWidgets(placement, width) {
918
+ const rows = [...this.#extensionWidgets.values()]
919
+ .filter(widget => widget.placement === placement)
920
+ .flatMap(widget => widget.component.render(width));
921
+ return placement === "aboveEditor" ? ["", ...rows] : rows;
922
+ }
923
+ #renderStatus(width) {
924
+ return this.#customViewport ? this.#status.renderLive(width) : this.#status.render(width);
925
+ }
926
+ #renderFooter(width) {
927
+ return (this.#extensionFooter ?? this.#footer).render(width);
928
+ }
929
+ #viewWithExtensionStatuses(view) {
930
+ const footer = view.status.footer;
931
+ const statuses = new Map(footer?.extensionStatuses ?? []);
932
+ for (const [key, text] of this.#extensionStatuses)
933
+ statuses.set(key, text);
934
+ return {
935
+ ...view,
936
+ status: {
937
+ ...view.status,
938
+ footer: {
939
+ branch: footer?.branch ?? null,
940
+ sessionName: footer?.sessionName ?? null,
941
+ availableProviderCount: footer?.availableProviderCount ?? 1,
942
+ extensionStatuses: [...statuses],
943
+ },
944
+ },
945
+ };
946
+ }
947
+ #invalidateExtensions() {
948
+ this.#extensionHeader?.invalidate();
949
+ this.#extensionFooter?.invalidate();
950
+ for (const { component } of this.#extensionWidgets.values())
951
+ component.invalidate();
952
+ }
953
+ #setToolsExpanded(expanded) {
954
+ this.#toolsExpanded = expanded;
955
+ this.header.setExpanded(expanded);
956
+ this.resources.setExpanded(expanded);
957
+ for (const component of this.#transcript.values())
958
+ component.setExpanded(expanded);
959
+ // Invariant: expansion changes what a block draws without changing its revision.
960
+ this.#renderedRows.clear();
961
+ this.#documentLayouts.clear();
962
+ this.invalidate();
963
+ }
964
+ }
965
+ const SCROLLBAR_CELL_RESET = "\u001b[22;23;24;25;27;28;29;39;54;55m";
966
+ const KITTY_IMAGE_CONTROL = /\u001b_G[\s\S]*?\u001b\\/g;
967
+ const ITERM_IMAGE_CONTROL = /\u001b]1337;File=[^\u0007]*(?:\u0007|\u001b\\)/g;
968
+ /** Keep semantic SGR/OSC styling while excluding non-replayable image payloads. */
969
+ function sanitizeExitTranscriptRow(row) {
970
+ return row.replace(KITTY_IMAGE_CONTROL, "").replace(ITERM_IMAGE_CONTROL, "");
971
+ }
972
+ const TERMINAL_BACKGROUND = /\u001b\[(?:4[0-9]|10[0-7]|48(?:[;:][0-9;:]*)?)m/g;
973
+ /** Web URLs use link blue; file targets retain A1's cyan interactive accent. */
974
+ function nativeTranscriptLinkColor(text, target) {
975
+ return piTheme().fg(/^file:/iu.test(target) ? "accent" : "mdLink", text);
976
+ }
977
+ /** Repaint a source prompt with viewport chrome while preserving text, links, and foreground roles. */
978
+ function withoutTerminalBackground(text) {
979
+ return text.replace(TERMINAL_BACKGROUND, "");
980
+ }
981
+ /** A pinned timestamp is content now, not secondary transcript metadata. */
982
+ function pinnedPromptSourceRow(block, sourceRow, width) {
983
+ if (typeof block.payload !== "object" || block.payload === null)
984
+ return sourceRow;
985
+ const value = block.payload.timestamp;
986
+ if (typeof value !== "number" || !Number.isFinite(value))
987
+ return sourceRow;
988
+ const timestamp = formatSubmittedPromptTime(value);
989
+ if (timestamp === null || submittedPromptLayout(width, value).timestamp === null)
990
+ return sourceRow;
991
+ const rowWidth = displayWidth(sourceRow);
992
+ const timestampWidth = displayWidth(timestamp);
993
+ if (rowWidth < timestampWidth)
994
+ return sourceRow;
995
+ return overlaySpan(sourceRow, rowWidth - timestampWidth, rowWidth, piTheme().fg("userMessageText", timestamp));
996
+ }
997
+ function layoutPort(render, invalidate, handleInput) {
998
+ return {
999
+ render,
1000
+ invalidate,
1001
+ ...(handleInput === undefined ? {} : { handleInput }),
1002
+ };
1003
+ }
1004
+ export function shellResourceEntries(backend) {
1005
+ const resources = backend.nonVisualResources().map(resource => ({
1006
+ section: resource.kind === "skill"
1007
+ ? "Skills"
1008
+ : resource.kind === "prompt-template"
1009
+ ? "Prompts"
1010
+ : resource.kind === "theme"
1011
+ ? "Themes"
1012
+ : "Context",
1013
+ label: resource.kind === "prompt-template"
1014
+ ? `/${resource.label}`
1015
+ : resource.kind === "agent-context" || resource.kind === "system-prompt"
1016
+ ? compactResourceLabel(resource.sourcePath ?? resource.label)
1017
+ : resource.label,
1018
+ sourcePath: resource.sourcePath,
1019
+ diagnostic: resource.diagnostic,
1020
+ }));
1021
+ const extensions = backend.extensionResources().filter(extension => !extension.hidden);
1022
+ const loadedExtensions = extensions.filter(extension => extension.diagnostic === null);
1023
+ const extensionLabels = compactExtensionLabels(loadedExtensions);
1024
+ for (const extension of extensions) {
1025
+ const labelIndex = loadedExtensions.indexOf(extension);
1026
+ resources.push({
1027
+ section: "Extensions",
1028
+ label: extensionLabels[labelIndex] ?? compactResourceLabel(extension.sourcePath ?? extension.resolvedPath ?? "extension"),
1029
+ sourcePath: extension.sourcePath ?? extension.resolvedPath,
1030
+ diagnostic: extension.diagnostic,
1031
+ });
1032
+ }
1033
+ return resources;
1034
+ }
1035
+ function compactResourceLabel(path) {
1036
+ const segments = compactPathSegments(path);
1037
+ const leaf = segments.at(-1) ?? path;
1038
+ if ((leaf === "index.ts" || leaf === "index.js") && segments.length > 1)
1039
+ return segments.at(-2) ?? leaf;
1040
+ return leaf;
1041
+ }
1042
+ /**
1043
+ * Pinned from InteractiveMode's compact extension-label helpers at Pi commit
1044
+ * 914cf1472e715297caa30db4b9535d534a9eb718. The source metadata crosses an
1045
+ * A1-owned boundary first; the owned shell never inspects Pi's private root.
1046
+ */
1047
+ function compactExtensionLabels(extensions) {
1048
+ const localExtensions = extensions
1049
+ .filter(extension => !isPackageExtensionSource(extension.sourceInfo))
1050
+ .map(extension => {
1051
+ const path = extension.sourcePath ?? extension.resolvedPath ?? "extension";
1052
+ const segments = compactPathSegments(path);
1053
+ if (segments.length > 1 && (segments.at(-1) === "index.ts" || segments.at(-1) === "index.js"))
1054
+ segments.pop();
1055
+ return { extension, segments };
1056
+ });
1057
+ return extensions.map(extension => {
1058
+ const resourcePath = extension.sourcePath ?? extension.resolvedPath ?? "extension";
1059
+ if (isPackageExtensionSource(extension.sourceInfo)) {
1060
+ return compactPackageExtensionLabel(resourcePath, extension.sourceInfo);
1061
+ }
1062
+ const localIndex = localExtensions.findIndex(item => item.extension === extension);
1063
+ const segments = localExtensions[localIndex]?.segments;
1064
+ if (!segments || segments.length === 0)
1065
+ return compactResourceLabel(resourcePath);
1066
+ for (let count = 1; count <= segments.length; count += 1) {
1067
+ const candidate = segments.slice(-count).join("/");
1068
+ if (localExtensions.every((item, itemIndex) => itemIndex === localIndex || item.segments.slice(-count).join("/") !== candidate)) {
1069
+ return candidate;
1070
+ }
1071
+ }
1072
+ return segments.join("/");
1073
+ });
1074
+ }
1075
+ function compactPackageExtensionLabel(resourcePath, sourceInfo) {
1076
+ const sourceLabel = compactPackageSourceLabel(sourceInfo.source);
1077
+ if (!sourceLabel)
1078
+ return compactResourceLabel(resourcePath);
1079
+ const shortPath = shortPackagePath(resourcePath, sourceInfo).replaceAll("\\", "/");
1080
+ const packagePath = shortPath.startsWith("extensions/") ? shortPath.slice("extensions/".length) : shortPath;
1081
+ const slash = packagePath.lastIndexOf("/");
1082
+ const fileName = slash < 0 ? packagePath : packagePath.slice(slash + 1);
1083
+ const directory = slash < 0 ? "" : packagePath.slice(0, slash);
1084
+ const extension = fileName.lastIndexOf(".");
1085
+ const name = extension <= 0 ? fileName : fileName.slice(0, extension);
1086
+ if (name === "index")
1087
+ return !directory || directory === "." ? sourceLabel : `${sourceLabel}:${directory}`;
1088
+ return `${sourceLabel}:${packagePath}`;
1089
+ }
1090
+ function compactPackageSourceLabel(source) {
1091
+ if (source.startsWith("npm:"))
1092
+ return source.slice("npm:".length) || source;
1093
+ if (!source.startsWith("git:"))
1094
+ return source;
1095
+ const gitSource = source.slice("git:".length).trim();
1096
+ let repositoryPath;
1097
+ const scpLike = gitSource.match(/^git@[^:]+:(.+)$/);
1098
+ if (scpLike?.[1]) {
1099
+ repositoryPath = scpLike[1];
1100
+ }
1101
+ else if (/^[a-z]+:\/\//i.test(gitSource)) {
1102
+ try {
1103
+ repositoryPath = new URL(gitSource).pathname.replace(/^\/+/, "");
1104
+ }
1105
+ catch {
1106
+ return source;
1107
+ }
1108
+ }
1109
+ else {
1110
+ const slash = gitSource.indexOf("/");
1111
+ if (slash >= 0)
1112
+ repositoryPath = gitSource.slice(slash + 1);
1113
+ }
1114
+ if (!repositoryPath)
1115
+ return source;
1116
+ const ref = repositoryPath.indexOf("@");
1117
+ const withoutRef = ref < 0 ? repositoryPath : repositoryPath.slice(0, ref);
1118
+ return withoutRef.replace(/\.git$/, "") || source;
1119
+ }
1120
+ function shortPackagePath(resourcePath, sourceInfo) {
1121
+ const fullPath = normalizeResourcePath(resourcePath);
1122
+ const baseDir = sourceInfo.baseDir === null ? undefined : normalizeResourcePath(sourceInfo.baseDir).replace(/\/$/, "");
1123
+ if (baseDir) {
1124
+ const npmRoot = baseDir.match(/^(.*\/node_modules)\/(@?[^/]+(?:\/[^/]+)?)$/);
1125
+ if (npmRoot?.[1] && fullPath.startsWith(`${npmRoot[1]}/`))
1126
+ return relativeResourcePath(baseDir, fullPath);
1127
+ if (fullPath === baseDir)
1128
+ return ".";
1129
+ if (fullPath.startsWith(`${baseDir}/`))
1130
+ return fullPath.slice(baseDir.length + 1);
1131
+ }
1132
+ const npmMatch = fullPath.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);
1133
+ if (npmMatch?.[2] && sourceInfo.source.startsWith("npm:"))
1134
+ return npmMatch[2];
1135
+ const gitMatch = fullPath.match(/git\/[^/]+\/[^/]+\/(.*)/);
1136
+ if (gitMatch?.[1] && sourceInfo.source.startsWith("git:"))
1137
+ return gitMatch[1];
1138
+ return resourcePath;
1139
+ }
1140
+ function relativeResourcePath(from, to) {
1141
+ const fromSegments = from.split("/").filter(Boolean);
1142
+ const toSegments = to.split("/").filter(Boolean);
1143
+ let common = 0;
1144
+ while (common < fromSegments.length && common < toSegments.length
1145
+ && fromSegments[common]?.toLowerCase() === toSegments[common]?.toLowerCase())
1146
+ common += 1;
1147
+ return [...fromSegments.slice(common).map(() => ".."), ...toSegments.slice(common)].join("/") || ".";
1148
+ }
1149
+ function compactPathSegments(path) {
1150
+ return normalizeResourcePath(path).split("/").filter(segment => segment.length > 0 && segment !== "~");
1151
+ }
1152
+ function normalizeResourcePath(path) {
1153
+ return path.replaceAll("\\", "/");
1154
+ }
1155
+ function isPackageExtensionSource(sourceInfo) {
1156
+ const source = sourceInfo?.source ?? "";
1157
+ return source.startsWith("npm:") || source.startsWith("git:");
1158
+ }