@pi-chamber/web 1.0.7 → 1.0.8-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/assets/AgentsSurface-BmHImX8m.js +1 -0
  2. package/dist/assets/ChoicesArtifact-C71fGOm2.js +1 -0
  3. package/dist/assets/DiagramView-BZQxoiZu.js +1 -0
  4. package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-C70pbgk-.js} +6 -6
  5. package/dist/assets/FileSaveConflictDialog-Cu8c3gBV.js +3 -0
  6. package/dist/assets/FilesView-nFJYEdRw.js +6 -0
  7. package/dist/assets/GitHubDetailScaffold-Jvv_tgbl.js +11 -0
  8. package/dist/assets/GitHubLinkPicker-BXD2ODRi.js +1 -0
  9. package/dist/assets/GitHubListPrimitives-BWI706F0.js +1 -0
  10. package/dist/assets/{GitView-DD33ngnM.js → GitView-MIDG5RYW.js} +5 -5
  11. package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-uNlozeu0.js} +2 -2
  12. package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-CSLsTriz.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-Cs-7BfWi.js} +3 -3
  14. package/dist/assets/PatchDiff-axbsnbTJ.js +1 -0
  15. package/dist/assets/PierreDiffViewer-lwn6w_5w.js +147 -0
  16. package/dist/assets/PullRequestsSurface-o_AXDjbO.js +2 -0
  17. package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-C4CMlcbv.js} +1 -1
  18. package/dist/assets/SessionSwitcherDropdown-DCBVuCoo.js +2 -0
  19. package/dist/assets/SessionUnreadDot-DyeIrsro.js +1 -0
  20. package/dist/assets/SettingsView-BHBpt2Um.js +7 -0
  21. package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-Cb4st5y5.js} +1 -1
  22. package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
  23. package/dist/assets/SubagentsArtifact-BzeMEoFP.js +1 -0
  24. package/dist/assets/ToolOutputDialog-BP2mOWdV.js +8 -0
  25. package/dist/assets/ToolPartDiffPreview-D49XBR9b.js +1 -0
  26. package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-CLgDONEQ.js} +4 -4
  27. package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
  28. package/dist/assets/VisualFrame-CJrAvWSo.js +22 -0
  29. package/dist/assets/VisualsArtifact-DqLGgU-Q.js +1 -0
  30. package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-BeyKtQGB.js} +1 -1
  31. package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DmO6H8u6.js} +2 -2
  32. package/dist/assets/contextFileOpenGuard-DOK251YW.js +1 -0
  33. package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CnzR7kxA.js} +2 -2
  34. package/dist/assets/gitStatusPredicates-4kPg2t6j.js +1 -0
  35. package/dist/assets/githubLink-QvaLfNNT.js +10 -0
  36. package/dist/assets/{index-I2QYqABE.js → index-B2v0_mez.js} +8 -8
  37. package/dist/assets/index-D3F4JrPN.css +1 -0
  38. package/dist/assets/{index-ComwtfT4.js → index-DMX9wT1Z.js} +1 -1
  39. package/dist/assets/{main-DoiadX0a.js → main-BW9J3Y72.js} +2 -2
  40. package/dist/assets/main-BirYxac2.js +137 -0
  41. package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-CxmcPur8.js} +2 -2
  42. package/dist/assets/miniChat-BRB11eEs.js +2 -0
  43. package/dist/assets/{mobile-BucKVm1P.js → mobile-DJZYYCuB.js} +2 -2
  44. package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-B6QpoPRn.js} +1 -1
  45. package/dist/assets/pi-session-focus-preference-PWoh3LNA.js +9 -0
  46. package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-C48T6YFJ.js} +1 -1
  47. package/dist/assets/renderElectronMiniChatApp-N-BQdJl0.js +2 -0
  48. package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-8Kt2MyTN.js} +1 -1
  49. package/dist/assets/{renderMobileApp-Bp74b_Lo.js → renderMobileApp-B7cT7m5b.js} +3 -3
  50. package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +62 -0
  51. package/dist/assets/runtimeSurface-kIEoYsPP.js +1 -0
  52. package/dist/assets/selection-BTEdLRVK.js +1 -0
  53. package/dist/assets/useAppFontEffects-EcTZ_I_I.js +225 -0
  54. package/dist/assets/useGitHubRemoteSearch-DIBHNu8r.js +1 -0
  55. package/dist/assets/useSwitcherItems-DfLbfX37.js +1 -0
  56. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js → vendor-aparajita-capacitor-secure-storage-DUoR8t1G.js} +1 -1
  57. package/dist/assets/{vendor-base-ui-BCqPBzDj.js → vendor-base-ui-DE6jnTiC.js} +1 -1
  58. package/dist/assets/{vendor-boot-3SaHYVb1.js → vendor-boot-D-KEJjsM.js} +29 -29
  59. package/dist/assets/{vendor-capacitor-app-NbQ-WiPS.js → vendor-capacitor-app-CO5jS31X.js} +1 -1
  60. package/dist/assets/{vendor-capacitor-keyboard-CgrHt8iN.js → vendor-capacitor-keyboard-335osRpd.js} +1 -1
  61. package/dist/assets/{vendor-capacitor-status-bar-CWt0OF5t.js → vendor-capacitor-status-bar-lB9y4H9d.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-autocomplete-WThuuUAz.js → vendor-codemirror-autocomplete-BKvJ8PfM.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-BbLGCxF6.js → vendor-codemirror-lang-angular-wjCUD0bM.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-Cceks-9O.js → vendor-codemirror-lang-cpp-LJzlG8sJ.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-D1wpUg3Z.js → vendor-codemirror-lang-css-DoEEdEpW.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-Cv0zXHHM.js → vendor-codemirror-lang-go-DexsLPb8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-DbL8oT9H.js → vendor-codemirror-lang-html-h25V-Hp5.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CNugenuC.js → vendor-codemirror-lang-java-D8xoT8cv.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Bx_FIyZF.js → vendor-codemirror-lang-javascript-DF3GDYje.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-DDGjB3Zq.js → vendor-codemirror-lang-jinja-BboTHFdn.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-DIvqf9Pb.js → vendor-codemirror-lang-json-DCqvG1nE.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-D8r9dGG1.js → vendor-codemirror-lang-less-B8ZrSKJM.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-B24mguYi.js → vendor-codemirror-lang-liquid-DF9S5m5F.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-v3yG2sbf.js → vendor-codemirror-lang-markdown-6BNbCEPe.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-BcZGalqy.js → vendor-codemirror-lang-php-CQwAz1Hd.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-b-JqEwQy.js → vendor-codemirror-lang-python-DQym-8Tx.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-B1uZxDW-.js → vendor-codemirror-lang-rust-DknzOTkO.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-DqPrngKp.js → vendor-codemirror-lang-sass-dB0Rm5HI.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-UyCnpt-k.js → vendor-codemirror-lang-sql-CCQUnnD-.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-xDwYkovV.js → vendor-codemirror-lang-vue-h1M5bF00.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-CF3169p_.js → vendor-codemirror-lang-wast-DWgtlGfu.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-FCtVhuOb.js → vendor-codemirror-lang-xml-DncwoCUY.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-g0sPmAnv.js → vendor-codemirror-lang-yaml-C7QkS5ER.js} +1 -1
  84. package/dist/assets/{vendor-codemirror-language-data-B03xgzP2.js → vendor-codemirror-language-data-BUZIlm3G.js} +2 -2
  85. package/dist/assets/{vendor-codemirror-search-Dw3Wpu15.js → vendor-codemirror-search-BlDCaCMK.js} +1 -1
  86. package/dist/assets/{vendor-lezer-cpp-Cu3E-KUI.js → vendor-lezer-cpp-B4JK1BC1.js} +1 -1
  87. package/dist/assets/{vendor-lezer-css-Cb8vp67u.js → vendor-lezer-css-DRxDmhcy.js} +1 -1
  88. package/dist/assets/{vendor-lezer-go-BTsIaOm7.js → vendor-lezer-go-DsUgfmxi.js} +1 -1
  89. package/dist/assets/{vendor-lezer-html-UQMsUwj-.js → vendor-lezer-html-qr9pUPmM.js} +1 -1
  90. package/dist/assets/{vendor-lezer-java-BIWrFrAx.js → vendor-lezer-java-6UyNiQiB.js} +1 -1
  91. package/dist/assets/{vendor-lezer-javascript-BH2Etgoy.js → vendor-lezer-javascript-CUdJ0VGA.js} +1 -1
  92. package/dist/assets/{vendor-lezer-json-CE-QUCwM.js → vendor-lezer-json-BKYAA8Hu.js} +1 -1
  93. package/dist/assets/{vendor-lezer-lr-HY6Yc0Vr.js → vendor-lezer-lr-DluApmOX.js} +1 -1
  94. package/dist/assets/{vendor-lezer-markdown-xFL3Evwf.js → vendor-lezer-markdown-B-uzYzYT.js} +1 -1
  95. package/dist/assets/{vendor-lezer-php-Cr_mQGrG.js → vendor-lezer-php-DI6PNjlz.js} +1 -1
  96. package/dist/assets/{vendor-lezer-python-BNRFWCb0.js → vendor-lezer-python-Bj232yb5.js} +1 -1
  97. package/dist/assets/{vendor-lezer-rust-BvfOK5cU.js → vendor-lezer-rust-DlPG_Yau.js} +1 -1
  98. package/dist/assets/{vendor-lezer-sass-qoxiLisk.js → vendor-lezer-sass-CBsyWB2A.js} +1 -1
  99. package/dist/assets/{vendor-lezer-xml--x8SSpqU.js → vendor-lezer-xml-C1FmgtmE.js} +1 -1
  100. package/dist/assets/{vendor-lezer-yaml-BDo1JaEr.js → vendor-lezer-yaml-DpHmjriG.js} +1 -1
  101. package/dist/assets/{vendor-replit-codemirror-vim-D1Fe7FiY.js → vendor-replit-codemirror-vim-Cvk64got.js} +1 -1
  102. package/dist/assets/{web-components-CGDpzixf.js → web-components-C_DsTJis.js} +4 -4
  103. package/dist/index.html +4 -4
  104. package/dist/mini-chat.html +3 -3
  105. package/dist/mobile.html +3 -3
  106. package/package.json +2 -1
  107. package/plugins/registry.json +7 -0
  108. package/plugins/subagents/LICENSE +25 -0
  109. package/plugins/subagents/agents/planner.md +36 -0
  110. package/plugins/subagents/agents/reviewer.md +34 -0
  111. package/plugins/subagents/agents/scout.md +49 -0
  112. package/plugins/subagents/agents/worker.md +23 -0
  113. package/plugins/subagents/extension.js +631 -0
  114. package/plugins/subagents/extension.test.js +295 -0
  115. package/plugins/subagents/package.json +41 -0
  116. package/plugins/visuals/choices.js +168 -0
  117. package/plugins/visuals/extension.js +87 -0
  118. package/plugins/visuals/files.js +74 -0
  119. package/plugins/visuals/package.json +32 -0
  120. package/server/index.js +20 -0
  121. package/server/lib/github/DOCUMENTATION.md +4 -2
  122. package/server/lib/github/gh-cli.js +35 -9
  123. package/server/lib/github/gh-cli.test.js +122 -0
  124. package/server/lib/notifications/pi-notification-watcher.js +3 -0
  125. package/server/lib/notifications/pi-notification-watcher.test.js +10 -0
  126. package/server/lib/open-url/DOCUMENTATION.md +1 -1
  127. package/server/lib/pi/extension-protocol.js +54 -0
  128. package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
  129. package/server/lib/pi/routes-extension-events.test.js +115 -0
  130. package/server/lib/pi/routes.js +307 -5
  131. package/server/lib/pi/routes.test.js +296 -1
  132. package/server/lib/pi/session-daemon/DOCUMENTATION.md +25 -8
  133. package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
  134. package/server/lib/pi/session-daemon/extension-config.js +719 -0
  135. package/server/lib/pi/session-daemon/extension-config.test.js +618 -0
  136. package/server/lib/pi/session-daemon/extension-controls.js +177 -0
  137. package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
  138. package/server/lib/pi/session-daemon/extension-name.js +6 -0
  139. package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
  140. package/server/lib/pi/session-daemon/extension-palette.js +146 -0
  141. package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
  142. package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
  143. package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
  144. package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
  145. package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
  146. package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
  147. package/server/lib/pi/session-daemon/plugin-host.js +245 -0
  148. package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
  149. package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
  150. package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
  151. package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
  152. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
  153. package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
  154. package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
  155. package/server/lib/pi/session-daemon/session-daemon.js +568 -61
  156. package/server/lib/pi/session-daemon/session-daemon.test.js +164 -4
  157. package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
  158. package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
  159. package/server/lib/pi/session-daemon/supervisor.js +22 -3
  160. package/server/lib/pi/settings-store.js +14 -0
  161. package/server/lib/pi/settings-store.test.js +11 -0
  162. package/server/lib/plugins/DOCUMENTATION.md +186 -0
  163. package/server/lib/plugins/daemon-sync.js +78 -0
  164. package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
  165. package/server/lib/plugins/daemon-sync.test.js +96 -0
  166. package/server/lib/plugins/impact.js +139 -0
  167. package/server/lib/plugins/impact.test.js +82 -0
  168. package/server/lib/plugins/manifest.js +195 -0
  169. package/server/lib/plugins/manifest.test.js +118 -0
  170. package/server/lib/plugins/registry.js +59 -0
  171. package/server/lib/plugins/routes.js +92 -0
  172. package/server/lib/plugins/routes.test.js +219 -0
  173. package/server/lib/plugins/service.js +161 -0
  174. package/server/lib/plugins/store.js +261 -0
  175. package/server/lib/plugins/store.test.js +188 -0
  176. package/server/lib/plugins/visuals-extension.test.js +237 -0
  177. package/server/lib/server-browser/DOCUMENTATION.md +32 -7
  178. package/server/lib/server-browser/browser-tab.js +4 -1
  179. package/server/lib/server-browser/downloads.js +261 -34
  180. package/server/lib/server-browser/downloads.test.js +171 -0
  181. package/server/lib/server-browser/runtime.integration.test.js +47 -0
  182. package/server/lib/server-browser/runtime.js +16 -0
  183. package/server/lib/server-browser/server-browser.js +25 -6
  184. package/server/lib/tunnels/executable-search.js +5 -1
  185. package/server/lib/tunnels/executable-search.test.js +26 -0
  186. package/dist/assets/DiagramView-BB-aZobi.js +0 -1
  187. package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
  188. package/dist/assets/FilesView-DECxN8Z0.js +0 -6
  189. package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
  190. package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
  191. package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
  192. package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
  193. package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
  194. package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
  195. package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
  196. package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
  197. package/dist/assets/SettingsView-DcF-At5E.js +0 -6
  198. package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
  199. package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
  200. package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
  201. package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
  202. package/dist/assets/githubLink-ByPAyFjh.js +0 -10
  203. package/dist/assets/index-BaLCg7tL.css +0 -1
  204. package/dist/assets/main-DyFfbllq.js +0 -137
  205. package/dist/assets/miniChat-Ck6MEZ9Q.js +0 -2
  206. package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
  207. package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
  208. package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
  209. package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
  210. package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
  211. package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
  212. package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderElectronMiniChatApp-Cb7s7dWl.js","assets/vendor-boot-3SaHYVb1.js","assets/vendor-react-Bz1tRBxM.js","assets/vendor-clsx-B-dksMZM.js","assets/index-I2QYqABE.js","assets/vendor-zustand-CXhN0IMY.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-tailwind-merge-BKkUfl9q.js","assets/vendor-fuse.js-t_7AcMTv.js","assets/index-BaLCg7tL.css","assets/pi-session-focus-preference-Dx0UXPoO.js","assets/useAppFontEffects-ZTyNwFk6.js","assets/runtimeSurface-CFwnvks_.js","assets/nativeFileSave-Cp9i5QGd.js","assets/vendor-katex-css-Cp579UoJ.css"])))=>i.map(i=>d[i]);
2
- import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as t}from"./index-I2QYqABE.js";/* empty css */import"./vendor-zustand-CXhN0IMY.js";import"./vendor-react-Bz1tRBxM.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";window.__PICHAMBER_RUNTIME_APIS__=t();o(async()=>{const{renderElectronMiniChatApp:r}=await import("./renderElectronMiniChatApp-Cb7s7dWl.js");return{renderElectronMiniChatApp:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(({renderElectronMiniChatApp:r})=>{r()});
@@ -1,9 +0,0 @@
1
- import{h as R,af as D,ag as O,g as M,ah as j,ai as U,aj as H,ak as Y,al as W,a as z,am as K,an as b,ao as J,ap as V}from"./useAppFontEffects-ZTyNwFk6.js";import{w as q,u as A,x as Z,b as Q,v as k,y as X,z as ee,S as se,n as B}from"./index-I2QYqABE.js";const te=[];function L(){return[...te].reverse()}const oe={getLastAssistantMessage(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),null;const s=b();if(!s||s.length===0)return console.log("[ERROR] No messages in current session"),null;for(let t=s.length-1;t>=0;t--){const n=s[t];if(n.role==="assistant"){const c=(D(n.id)||[]).map(i=>{const u={id:i.id,type:i.type};return i.type==="text"?(u.text=i.text,u.textLength=i.text?.length||0):i.type==="tool"?(u.tool=i.tool,u.state=i.state?.status):(i.type==="step-start"||i.type==="step-finish")&&(u.isStepMarker=!0),u}),m=c.some(i=>i.type==="text"&&i.text&&i.text.trim().length>0),a=c.some(i=>i.type==="tool"),g=c.some(i=>i.type==="step-start"||i.type==="step-finish"),p=c.length===0,S=!m&&!a&&(!p||g),r={messageId:n.id,role:n.role,timestamp:n.time?.created||0,partsCount:c.length,parts:c,isEmpty:p,isEmptyResponse:S,raw:n};return console.log("[INSPECT] Last Assistant Message:",r),console.log("[SUMMARY] Summary:",{messageId:r.messageId,partsCount:r.partsCount,isEmpty:r.isEmpty,isEmptyResponse:r.isEmptyResponse,hasText:m,hasTools:a,hasStepMarkers:g,onlyStepMarkers:g&&!m&&!a}),r.isEmpty&&console.warn("[WARNING] Message has NO parts!"),r.isEmptyResponse&&(console.warn("[WARNING] Message has parts but NO meaningful content (empty text, no tools)!"),g&&!m&&!a&&(console.warn("[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!"),console.log("This is a known issue with Claude models (anthropic provider)"),console.log("Recommendation: Send a follow-up message or try a different model"))),r}}return console.log("[ERROR] No assistant messages found in current session"),null},truncateString(e,o=80){return!e||typeof e!="string"||e.length<=o?e:e.substring(0,o)+"…"},truncateMessages(e){return e.map(o=>({...o,parts:(D(o.id)||[]).map(s=>{const t={...s};return"text"in s&&(t.text=this.truncateString(s.text)),"textPreview"in s&&(t.textPreview=this.truncateString(s.textPreview)),s.state&&(t.state={...s.state},"output"in s.state&&(t.state.output=this.truncateString(s.state.output)),"error"in s.state&&(t.state.error=this.truncateString(s.state.error)),s.state.metadata&&"preview"in s.state.metadata&&(t.state.metadata={...s.state.metadata,preview:this.truncateString(s.state.metadata.preview)})),t})}))},getAllMessages(e=!1){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b();return console.log(`[MESSAGES] Total messages in session: ${t.length}`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] ${n.role} - ${n.id} - ${c.length} parts`)}),e?this.truncateMessages(t):t},async getAppStatus(){const e=A.getState(),o=R.getState(),s=z.getState(),t=e.currentDirectory||null,n=M().getState(),d=n.directory??null,c=K(),m=new Set,a={};c.forEach(l=>{const y=l.directory;typeof y=="string"&&y.trim().length>0?(m.add(y),a[y]=(a[y]??0)+1):a["(none)"]=(a["(none)"]??0)+1});const g=(()=>{if(typeof window>"u")return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem("lastDirectory"),homeDirectory:window.localStorage.getItem("homeDirectory")}}catch(l){return{available:!1,error:l instanceof Error?l.message:String(l)}}})(),p=k(),S=typeof window<"u"&&!!window.__PICHAMBER_ELECTRON__,r=async l=>{try{return await l.json()}catch{return null}},u=await(async l=>{try{const y=await ee(l);return y.ok?await r(y):{status:y.status}}catch(y){return{error:y instanceof Error?y.message:String(y)}}})("/api/pi/ui-settings");let I=null;try{I=await Z.health({runtimeKey:Q()})}catch(l){I={error:l instanceof Error?l.message:String(l)}}let w={isGitRepo:null};if(t)try{const l=k()?.git.checkIsGitRepository??X;w.isGitRepo=await l(t)}catch(l){w={isGitRepo:null,error:l instanceof Error?l.message:String(l)}}const E=s.projects.map(l=>({id:l.id,path:l.path,label:l.label})),h={runtime:{platform:p?.runtime?.platform??null,isDesktop:S,hasRuntimeApis:!!p,desktopServerOrigin:null},location:typeof window<"u"?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:t,piDirectory:d,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:s.projects.length,activeProjectId:s.activeProjectId,samples:E},sessions:{total:c.length,currentSessionId:o.currentSessionId,uniqueDirectories:m.size,directorySamples:Array.from(m).slice(0,5),directoryCounts:a},git:w,localStorage:g,pi:{health:I,connection:n.connection},pichamber:{settingsInfo:u},recentSendFailures:L(),currentSessionDirectoryResolution:o.currentSessionId?this.diagnoseSessionDirectory(o.currentSessionId):null};return console.log("[DEBUG] App status snapshot:",h),h},getRecentSendFailures(){const e=L();return e.length===0?console.log("[OK] No prompt sends were rejected in this session."):(console.warn(`[ALERT] ${e.length} rejected prompt send(s):`),console.table(e)),e},diagnoseSessionDirectory(e){const o=R.getState(),s=e??o.currentSessionId;if(!s)return console.log("[ERROR] No session selected and no session id passed"),null;const t=U(s),n=H().find(u=>u.id===s),d=n?.directory??null,c=s===o.currentSessionId?o.currentSessionDirectory:null,a=Y({session:n??null,currentDirectory:c}),g=o.getDirectoryForSession(s),p=W(s),S=[["owning child store",t],["session record",d],["current selection",c],["runtime memory",p.runtime],["persisted memory",p.persisted]],r=g?S.find(([,u])=>u&&u!==g):void 0,i={sessionId:s,isCurrentSession:s===o.currentSessionId,routedDirectory:g,resolvedFrom:a.source,conflict:r?{source:r[0],directory:r[1]}:null,sources:J(),details:{owningChildStore:t,sessionRecordDirectory:d,sessionIndexed:!!n,currentSessionDirectory:o.currentSessionDirectory,rememberedForRuntime:p.runtime,persistedAcrossRestarts:p.persisted,activeDirectory:A.getState().currentDirectory??null,piSessionDirectory:M().getState().directory??null}};return console.log("[DEBUG] Session directory resolution:",i),r?console.warn(`[ALERT] Directory sources disagree: routing to "${g}" while "${r[1]}" came from ${r[0]}.`):g?console.log("[OK] All known sources agree on the session directory."):console.warn("[ALERT] No directory resolved for this session — sends fall back to the active directory."),i},async buildDiagnosticsReport(){const e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return j(e)},async copyDiagnosticsReport(){const e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){const e=this.getLastAssistantMessage();if(!e)return!1;const o=e.isEmpty||e.isEmptyResponse;return o?(console.error("[ALERT] PROBLEMATIC MESSAGE DETECTED!"),console.log("Details:",{messageId:e.messageId,isEmpty:e.isEmpty,isEmptyResponse:e.isEmptyResponse,partsCount:e.partsCount}),e.parts.length>0&&console.log("Parts:",e.parts)):console.log("[OK] Last message looks good!"),o},getStreamingState(){const e=R.getState(),o=M().getState().reducer.bySession,s=new Map;for(const[n,d]of o)s.set(n,O(d));const t=e.currentSessionId?s.get(e.currentSessionId)??null:null;return console.log("[STREAM] Streaming State:",{streamingMessageId:t,streamingMessageIds:Array.from(s.entries())}),{streamingMessageId:t,streamingMessageIds:s}},findEmptyMessages(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b().filter(n=>n.role==="assistant").filter(n=>{const d=D(n.id)||[],c=d.some(a=>a.type==="text"&&a.text&&a.text.trim().length>0),m=d.some(a=>a.type==="tool");return d.length===0||!c&&!m});return console.log(`[INSPECT] Found ${t.length} empty assistant messages`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] Empty message:`,{messageId:n.id,partsCount:c.length,provider:n.providerID,model:n.modelID,timestamp:n.time?.created})}),t},showRetryHelp(){console.log(`[DEBUG] How to handle empty Claude responses:
2
- `),console.log("1. Check the last message:"),console.log(` __piDebug.getLastAssistantMessage()
3
- `),console.log("2. Find all empty messages in session:"),console.log(` __piDebug.findEmptyMessages()
4
- `),console.log("3. To retry, you can:"),console.log(" - Edit your last user message and resend"),console.log(' - Send a follow-up message like "Please provide the response"'),console.log(` - Try a different model (OpenAI models tend to be more reliable)
5
- `),console.log("[TIP] Empty responses are usually due to:"),console.log(" - Model rate limits"),console.log(" - Context length issues"),console.log(" - Model refusing to respond to certain prompts"),console.log(" - API errors from provider")},analyzeMessageCompletionConsistency(e={}){const{includeNonAssistant:o=!1,verbose:s=!0,maxTableRows:t=25}=e;if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),{summary:null,rows:[]};const c=b(),m=o?c:c.filter(r=>r.role==="assistant"),a={totalMessages:c.length,analyzedMessages:m.length,completedMissing:0,completedBeforeTool:0,completedBeforeReasoning:0,runningToolsWhenCompleted:0,reasoningOpenWhenCompleted:0,withTools:0,withReasoning:0},g=r=>typeof r=="number"&&Number.isFinite(r)?r:null,p=r=>{const i=r.filter(u=>typeof u=="number");return i.length>0?Math.max(...i):null},S=m.map((r,i)=>{const u=r,I=D(r.id)||[],w=u.time??{},E=g(w.completed),h=E!==null,l=I.filter(f=>f.type==="tool"),y=I.filter(f=>f.type==="reasoning"),C=p(l.map(f=>g(f.state?.time?.end??f.state?.time?.start))),_=p(y.map(f=>g(f.time?.end??f.time?.start))),$=p([C,_].filter(f=>f!==null)),P=l.some(f=>["pending","running","started"].includes(f.state?.status)),x=y.some(f=>typeof f.time?.end!="number");l.length>0&&(a.withTools+=1),y.length>0&&(a.withReasoning+=1),h||(a.completedMissing+=1);const v=!!(h&&typeof C=="number"&&E<C);v&&(a.completedBeforeTool+=1);const N=!!(h&&typeof _=="number"&&E<_);return N&&(a.completedBeforeReasoning+=1),h&&P&&(a.runningToolsWhenCompleted+=1),h&&x&&(a.reasoningOpenWhenCompleted+=1),{index:i,messageId:u.id,role:u.role,completedAt:E,latestToolTimestamp:C,latestReasoningTimestamp:_,latestPartTimestamp:$,completed_missing:!h,completed_before_tool:v,completed_before_reasoning:N,running_tools_when_completed:!!(h&&P),reasoning_open_when_completed:!!(h&&x),has_tools:l.length>0,has_reasoning:y.length>0}});return s&&(console.table(S.slice(0,t)),S.length>t&&console.log(`Displayed first ${t} rows out of ${S.length}.`),console.log("[SUMMARY] Message completion timing:",a)),{summary:a,rows:S}},checkCompletionStatus(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),null;const t=b().filter(w=>w.role==="assistant");if(t.length===0)return console.log("[ERROR] No assistant messages"),null;const n=t[t.length-1],c=(D(n.id)||[]).filter(w=>w.type==="step-finish"),m=n.finish==="stop",g=n.time?.completed,p=n.status,S=typeof g=="number"&&g>0||p==="completed",r=!!(S&&m),i=n.sessionID,u=i?O(M().getState().reducer.bySession.get(i)??null):null,I=n.id===u;return console.log("[SUMMARY] Completion Status:"),console.log("Message ID:",n.id),console.log("time.completed:",g,"(type:",typeof g,")"),console.log("status:",p),console.log("hasCompletedFlag:",S),console.log("hasStopReason:",m),console.log("messageIsComplete:",r),console.log("isStreamingCandidate:",I),console.log("streamingMessageId:",u),console.log("Step-finish parts:",c),{messageId:n.id,completed:g,status:p,hasCompletedFlag:S,hasStopReason:m,messageIsComplete:r,stepFinishParts:c,raw:n}}};typeof window<"u"&&(window.__piDebug=oe,q()&&(console.log("[DEBUG] Pi debug utilities loaded. Use window.__piDebug in the console."),console.log("Available commands:"),console.log(" __piDebug.getLastAssistantMessage() - Get last assistant message details"),console.log(" __piDebug.getAllMessages(truncate?) - List all messages (truncate=true for short preview)"),console.log(" __piDebug.truncateMessages(messages) - Truncate long fields in messages array"),console.log(" __piDebug.getAppStatus() - Show app status snapshot"),console.log(" __piDebug.diagnoseSessionDirectory(sessionId?) - Show how the session directory is resolved"),console.log(" __piDebug.getRecentSendFailures() - List prompt sends that were rejected and rolled back"),console.log(" __piDebug.checkLastMessage() - Check if last message is problematic"),console.log(" __piDebug.findEmptyMessages() - Find all empty assistant messages"),console.log(" __piDebug.showRetryHelp() - Show instructions for handling empty responses"),console.log(" __piDebug.getStreamingState() - Get streaming state info"),console.log(" __piDebug.analyzeMessageCompletionConsistency(opts?) - Compare time.completed vs part timings"),console.log(" __piDebug.checkCompletionStatus() - Check completion status of last message")),window.addEventListener("error",e=>{try{const o=e.message||"",s=e.filename||"";typeof o=="string"&&o.includes("this._renderer.value.dimensions")&&/xterm/i.test(String(s))&&e.preventDefault()}catch{}}));const ae=async()=>{if(typeof window>"u")return;let e=null;try{e=window.localStorage.getItem("lastDirectory")}catch(o){console.warn("Failed to read saved directory preferences:",o)}e&&A.getState().setDirectory(e,{showOverlay:!1})};let F=!1;const G="pichamber-typography-base",ne=()=>{if(typeof document>"u")return;const o=`:root {
6
- ${Object.entries(se).map(([n,d])=>` --text-${n.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${d};`).join(`
7
- `)}
8
- }
9
- `,s=document.getElementById(G);if(s){s.textContent=o;return}const t=document.createElement("style");t.id=G,t.textContent=o,document.head.appendChild(t)},le=()=>{F||typeof window>"u"||(F=!0,ne())},T=(e,o)=>!!(e&&o)&&B(e??null)===B(o??null);function ce(e,o){if(!e)return null;const s=M();if(T(s.getState().directory,e))return null;const t=R.getState();return V(t.newSessionDraft,t.currentSessionId)?null:t.currentSessionId&&T(t.currentSessionDirectory,e)?t.currentSessionId:o?.sessionId&&T(o.directory,e)?o.sessionId:s.lastSelectedSessionForDirectory(e)}export{ae as a,ce as f,le as s};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-DShvvGwC.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-boot-3SaHYVb1.js","assets/vendor-react-Bz1tRBxM.js","assets/vendor-clsx-B-dksMZM.js","assets/useAppFontEffects-ZTyNwFk6.js","assets/index-I2QYqABE.js","assets/vendor-zustand-CXhN0IMY.js","assets/vendor-tailwind-merge-BKkUfl9q.js","assets/vendor-fuse.js-t_7AcMTv.js","assets/index-BaLCg7tL.css","assets/runtimeSurface-CFwnvks_.js","assets/nativeFileSave-Cp9i5QGd.js"])))=>i.map(i=>d[i]);
2
- import{j as e,aR as ye}from"./vendor-boot-3SaHYVb1.js";import{R as c,a as me}from"./vendor-react-Bz1tRBxM.js";/* empty css */import{f as K,u as V,av as ge,a1 as Z,h as ie,ao as U,a0 as we,X as ve,o as le,v as je,q as be}from"./index-I2QYqABE.js";import{f as Se,a as Ie,s as Ce}from"./pi-session-focus-preference-Dx0UXPoO.js";import{df as Ne,I as Y,aA as De,aR as Pe,aS as Me,aT as ke,dg as Ee,dh as _e,h as j,aY as Oe,a as ae,O as P,cW as ce,di as Le,z as Re,bj as Te,bY as Ae,bE as Be,B as de,b$ as Fe,dj as ue,dk as ze,t as Ue,g as $e,Y as We,E as He,_ as Ge,$ as Ke,a0 as Ye,a4 as Ve,a6 as qe,a7 as Je,dl as Xe,bZ as Ze,aa as Qe,ab as et,ac as tt,ad as st,ae as rt}from"./useAppFontEffects-ZTyNwFk6.js";import{_ as nt}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./runtimeSurface-CFwnvks_.js";import"./nativeFileSave-Cp9i5QGd.js";const ot=({mode:t,children:r})=>e.jsx(Ne.Provider,{value:t,children:r}),it=Ee,at=_e,ct=({totalTokens:t,percentage:r,colorPercentage:n,contextLimit:a,outputLimit:o,size:u="default",isMobile:l=!1,hideIcon:D=!1,showPercentIcon:E=!1,className:p,valueClassName:f,percentIconClassName:_,onClick:M,pressed:L=!1,cacheRead:x,cacheWrite:C,cacheHitPercent:h})=>{const[b,i]=c.useState(!1),g=typeof n=="number"?n:r,m=it(r)??0,y=at(g),q=y==="critical"?"var(--status-error)":y==="warn"?"var(--status-warning)":"var(--status-success)",w=I=>I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toFixed(1).replace(/\.0$/,""),N=I=>I>=90?"text-status-error":I>=75?"text-status-warning":"text-status-success",k=20,$=3,W=(k-$)/2,re=2*Math.PI*W,J=re*(1-m/100),T=typeof o=="number"?Math.max(o,0):0,A=typeof x=="number"&&typeof C=="number",Q=A?Math.max(0,x):0,B=A?Math.max(0,C):0,O=typeof h=="number"&&Number.isFinite(h),R=[`Used tokens: ${w(t)}`,`Context limit: ${w(a)}`,`Output limit: ${w(T)}`,...A?[`Cache read: ${w(Q)}`,`Cache write: ${w(B)}`]:[],...O?[`Cache hit: ${h.toFixed(1)}%`]:[],`${Math.min(r,999).toFixed(1)}% used`],F=!l&&typeof M=="function",v=e.jsxs(e.Fragment,{children:[!l&&!D&&e.jsx(Y,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:K("font-medium inline-flex items-center gap-1.5",f),children:E?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${k} ${k}`,className:K("h-3.5 w-3.5 -rotate-90",_),role:"progressbar","aria-valuenow":Math.round(m),"aria-valuemin":0,"aria-valuemax":100,children:[e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:"var(--interactive-border)",strokeWidth:$}),e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:q,strokeWidth:$,strokeLinecap:"round",strokeDasharray:re,strokeDashoffset:J,className:"transition-[stroke-dashoffset,stroke] duration-300"})]}),e.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:N(g),children:Math.min(r,999).toFixed(1)}),"%"]})})]}),S=K("app-region-no-drag flex items-center gap-1.5 select-none",u==="compact"?"typography-micro":"typography-meta",F?K("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-subtle-foreground",p),H=F?e.jsx("button",{type:"button",className:S,"aria-label":"Context usage","aria-pressed":L,onClick:M,children:v}):e.jsx("div",{className:S,"aria-label":"Context usage",onClick:l?()=>i(!0):void 0,children:v});return l?e.jsxs(e.Fragment,{children:[H,e.jsx(De,{open:b,onClose:()=>i(!1),title:"Context usage",children:e.jsx("div",{className:"flex flex-col gap-1.5",children:e.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(t)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(a)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(T)})]}),A?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(Q)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(B)})]})]}):null,O?e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache hit"}),e.jsxs("span",{className:"typography-meta text-foreground font-medium",children:[h.toFixed(1),"%"]})]}):null,e.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e.jsxs("span",{className:K("typography-meta font-semibold",N(g)),children:[Math.min(r,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(Pe,{children:[e.jsx(Me,{asChild:!0,children:H}),e.jsx(ke,{children:e.jsx("div",{className:"space-y-0.5",children:R.map(I=>e.jsx("p",{className:"typography-micro leading-tight",children:I},I))})})]})},lt=c.lazy(()=>nt(()=>import("./SessionSwitcherDropdown-DShvvGwC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(t=>({default:t.SessionSwitcherDropdown}))),dt=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=typeof window<"u"?window.__PICHAMBER_HOME__:"";if(n&&r===n)return"~";if(n&&r.startsWith(`${n}/`))return`~/${r.slice(n.length+1)}`;const a=r.split("/").filter(Boolean);return a.length<=3?r:`.../${a.slice(-3).join("/")}`},se=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=r.replace(/\\/g,"/");return n==="/"?"/":n.replace(/\/+$/,"")},ut=({mode:t})=>{const r=j(s=>s.currentSessionId),n=j(s=>!!s.newSessionDraft?.open),a=j(s=>s.newSessionDraft?.selectedProjectId??null),o=V(s=>s.currentDirectory),u=ae(s=>s.projects),l=ae(s=>s.getActiveProject()),D=P(s=>s.getCurrentModel),E=P(s=>s.providers),p=ce(),f=Le(r??""),_=Re(),M=Te(s=>s.ensureStatus),L=j(s=>s.newSessionDraft?.open?se(s.newSessionDraft.directoryOverride??""):""),[x,C]=c.useState(!1),h=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,b=Number.isFinite(h)&&h>0,i=Ae(),g=b?h>=26?"h-12":h<=15?"h-14":"":"",m=c.useMemo(()=>r?p.find(s=>s.id===r)??null:null,[r,p]);c.useEffect(()=>{ge()&&Z("desktop_get_window_pinned").then(s=>{typeof s?.pinned=="boolean"&&C(s.pinned)})},[]);const y=m?.title?.trim()||(n||t==="draft"?"New session":"Session"),q=se(m?.directory??null),w=se(o),N=q||L||w,k=dt(N);c.useEffect(()=>{N&&M(N,_.git).catch(()=>{})},[M,N,_.git]);const $=c.useMemo(()=>{const s=N;return s?u.map(d=>({...d,normalizedPath:se(d.path)})).filter(d=>d.normalizedPath&&(d.normalizedPath===s||s.startsWith(`${d.normalizedPath}/`))).sort((d,G)=>G.path.length-d.path.length)[0]??null:null},[N,u]),W=c.useMemo(()=>{const s=$??l;if(!s)return k||"PiChamber";const d=s.label?.trim();return d||(s.path.split(/[\\/]/).filter(Boolean).at(-1)??s.path)},[l,k,$]),J=Be(N||null),T=J&&J!=="HEAD"?J:null,A=D(),Q=c.useMemo(()=>{for(let s=f.length-1;s>=0;s-=1){const d=f[s];if(d.role!=="assistant"||typeof d.providerID!="string"||typeof d.modelID!="string")continue;const te=E.find(X=>X.id===d.providerID)?.models.find(X=>X.id===d.modelID);if(te)return te}},[f,E]),B=A?.limit?A:Q,O=B&&typeof B.limit=="object"&&B.limit!==null?B.limit:null,R=O&&typeof O.context=="number"?O.context:0,F=O&&typeof O.output=="number"?O.output:0,v=c.useMemo(()=>{if(!r||f.length===0)return null;let s,d;for(let ne=f.length-1;ne>=0;ne-=1){const oe=f[ne];if(oe.role!=="assistant")continue;const z=oe.tokens;if(!z)continue;if(z.input+z.output+z.reasoning+(z.cache?.read??0)+(z.cache?.write??0)>0){s=z,d=oe.id;break}}if(!s)return null;const G=s.input+s.output+s.reasoning+(s.cache?.read??0)+(s.cache?.write??0),te=R>0?R:2e5,X=R>0?Math.round(G/R*100):0,xe=F>0?Math.round(s.output/F*100):void 0;return{totalTokens:G,percentage:X,contextLimit:R||0,outputLimit:F||void 0,normalizedOutput:xe,thresholdLimit:te,lastMessageId:d}},[R,r,f,F]),[S,H]=c.useState(null),I={WebkitAppRegion:"drag"},ee={WebkitAppRegion:"no-drag"};c.useEffect(()=>{if(!r){H(s=>s===null?s:null);return}if(v&&v.totalTokens>0){H(s=>s&&s.totalTokens===v.totalTokens&&s.percentage===v.percentage&&s.contextLimit===v.contextLimit&&(s.outputLimit??0)===(v.outputLimit??0)&&(s.normalizedOutput??0)===(v.normalizedOutput??0)&&s.thresholdLimit===v.thresholdLimit&&s.lastMessageId===v.lastMessageId?s:v);return}H(s=>s===null?s:null)},[v,r]);const fe=S&&S.contextLimit>0?Math.min(999,S.totalTokens/S.contextLimit*100):0,pe=c.useCallback(()=>{const s=!x;C(s),Z("desktop_set_window_pinned",{pinned:s}).catch(()=>{C(!s)})},[x]),he=c.useCallback(()=>{const s=r?{sessionId:r,directory:m?.directory??o??""}:{mode:"draft",directory:N||o||"",projectId:a};Z("desktop_focus_main_window",s).then(d=>d?.focused===!0?Z("desktop_close_current_window"):null)},[o,r,a,N,m]);return e.jsxs("header",{className:K("flex items-center gap-3 bg-background pr-3",b?"pl-[5.5rem]":"pl-3",i?"h-12":g||"min-h-14"),style:I,children:[e.jsx(me.Suspense,{fallback:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro font-normal leading-tight text-subtle-foreground",children:[e.jsx("span",{className:"truncate",children:W}),T?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(Y,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-subtle-foreground"}),e.jsx("span",{className:"truncate",children:T})]}):null]})]}),children:e.jsx(lt,{children:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro font-normal leading-tight text-subtle-foreground",children:[e.jsx("span",{className:"truncate",children:W}),T?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(Y,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-subtle-foreground"}),e.jsx("span",{className:"truncate",children:T})]}):null]})]})})}),e.jsx("div",{className:"min-w-0 flex-1"}),S&&S.totalTokens>0?e.jsx(ct,{totalTokens:S.totalTokens,percentage:fe,colorPercentage:S.percentage,contextLimit:S.contextLimit,outputLimit:S.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:pe,"aria-label":x?"Unpin Mini Chat window":"Pin Mini Chat window",title:x?"Unpin window":"Pin above other windows",style:ee,children:x?e.jsx(Y,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(Y,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:he,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(Y,{name:"external-link",className:"h-4 w-4"})}),e.jsx(Fe,{visible:i})]})},mt=({mode:t,autoOpenDraft:r=!1,unavailable:n=!1})=>{const a=j(o=>o.currentSessionId);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[e.jsx(ut,{mode:t}),e.jsx("main",{className:"min-h-0 flex-1",children:n?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:e.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Session unavailable"}),e.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:"This session could not be loaded. It may have been deleted, archived, or opened from a different project context."})]})}):e.jsx(ot,{mode:"mini-chat",children:e.jsx(Oe,{autoOpenDraft:r},a??"no-session")})})]})},ft=()=>{const t=ie(o=>o.shortcutOverrides),r=V(o=>o.currentDirectory),n=ae(o=>o.getActiveProject()),a=j(o=>o.openNewSessionDraft);c.useEffect(()=>{const o=l=>ve(l,t),u=l=>{if(U(l,o("focus_input"))){l.preventDefault(),ue();return}if(we()&&U(l,o("new_mini_chat"))){l.preventDefault(),Z("desktop_open_draft_mini_chat_window",{directory:r||n?.path||"",projectId:n?.id??null})?.catch(p=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",p)});return}if(U(l,o("new_chat"))){l.preventDefault(),a({selectedProjectId:n?.id??null,directoryOverride:r||n?.path||null,preserveDirectoryOverride:!!(r||n?.path)}),ue();return}if(U(l,o("open_model_selector"))){l.preventDefault();const{isModelSelectorOpen:p,setModelSelectorOpen:f}=ie.getState();f(!p);return}if(U(l,o("cycle_thinking_variant"))){if(P.getState().getCurrentModelVariants().length===0)return;l.preventDefault(),ze(1).catch(()=>{Ue.error("Couldn't update thinking")});return}const D=U(l,o("cycle_favorite_model_forward")),E=U(l,o("cycle_favorite_model_backward"));if(D||E){const{favoriteModels:p,addRecentModel:f}=ie.getState();if(p.length===0)return;l.preventDefault();const{currentProviderId:_,currentModelId:M,setProvider:L,setModel:x}=P.getState(),C=p.findIndex(i=>i.providerID===_&&i.modelID===M),b=p[(C+(D?1:-1)+p.length)%p.length];L(b.providerID),x(b.modelID),f(b.providerID,b.modelID)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n?.id,n?.path,r,a,t])},pt="pichamber:mini-chat-presence",ht=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,r=t.get("mode")==="session"?"session":"draft",n=t.get("sessionId")?.trim()||null,a=t.get("directory")?.trim()||null,o=t.get("projectId")?.trim()||null;return{mode:r,sessionId:n,directory:a,projectId:o}},xt=({config:t})=>{const r=ce(),n=V(i=>i.currentDirectory),a=V(i=>i.setDirectory),o=j(i=>i.currentSessionId),u=j(i=>!!i.newSessionDraft?.open),l=j(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),D=j(i=>i.setCurrentSession),E=j(i=>i.openNewSessionDraft),p=P(i=>i.initializeApp),f=P(i=>i.isInitialized),_=P(i=>i.isConnected),M=P(i=>i.loadProviders),L=P(i=>i.providers.length),x=Ze();c.useEffect(()=>{p()},[p]),c.useEffect(()=>{if(f)return;let i=!0,g=0;const m=window.setInterval(()=>{if(i){if(g+=1,g>10){window.clearInterval(m);return}P.getState().isInitialized||P.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[f]);const C=c.useRef(!1);c.useEffect(()=>{if(!C.current&&t.mode==="session"&&t.directory){if(n===t.directory){C.current=!0;return}a(t.directory,{showOverlay:!1}),C.current=!0}},[t.directory,t.mode,n,a]),c.useEffect(()=>{t.mode!=="draft"||!u||o||!l||n===l||a(l,{showOverlay:!1})},[t.mode,n,o,l,u,a]),c.useEffect(()=>{_&&L===0&&M({source:"electronMiniChat:recovery"})},[_,M,L]);const h=c.useRef(!1);c.useEffect(()=>{if(h.current||t.mode!=="session"||!t.sessionId)return;if(o===t.sessionId){h.current=!0;return}if(o){h.current=!0;return}const i=r.find(m=>m.id===t.sessionId);if(!i){x.ensureSessionRenderable(t.sessionId);return}const g=i.directory??t.directory;D(t.sessionId,g),h.current=!0},[t,o,r,D,x]),c.useEffect(()=>{const i=g=>{const m=g.detail,y=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!y||j.getState().currentSessionId===y)return;const q=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():r.find(w=>w.id===y)?.directory??null;x.ensureSessionRenderable(y),D(y,q),h.current=!0};return window.addEventListener("pichamber:open-session",i),()=>window.removeEventListener("pichamber:open-session",i)},[r,D,x]),c.useEffect(()=>{t.mode!=="draft"||u||o||E({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,o,u,E]);const b=c.useRef(!1);return c.useEffect(()=>{if(b.current||!f)return;const i=()=>{if(b.current)return;b.current=!0;const y=typeof document<"u"?document.getElementById("initial-loading"):null;y&&(y.classList.add("fade-out"),window.setTimeout(()=>y.remove(),300))},g=t.mode==="session"?o===t.sessionId:u,m=window.setTimeout(i,g?100:1500);return()=>window.clearTimeout(m)},[f,t.mode,t.sessionId,o,u]),null},yt=()=>{const t=j(n=>n.currentSessionId),r=V(n=>n.currentDirectory);return c.useEffect(()=>{if(!t||!r||typeof BroadcastChannel>"u")return;const n=new BroadcastChannel(pt),a=l=>{n.postMessage({type:"mini-chat-session-presence",sessionId:t,directory:r,viewed:l})};a(!0);const o=window.setInterval(()=>a(!0),5e3),u=()=>a(!1);return window.addEventListener("beforeunload",u),()=>{window.clearInterval(o),window.removeEventListener("beforeunload",u),a(!1),n.close()}},[r,t]),null},gt=t=>{const r=ce(),n=j(u=>u.currentSessionId),[a,o]=c.useState(!1);return c.useEffect(()=>{if(t.mode!=="session"||!t.sessionId||n===t.sessionId){o(!1);return}if(r.some(l=>l.id===t.sessionId)){o(!1);return}const u=window.setTimeout(()=>o(!0),5e3);return()=>window.clearTimeout(u)},[t.mode,t.sessionId,n,r]),a};function wt({apis:t}){const r=c.useMemo(()=>ht(),[]),n=V(a=>a.currentDirectory);return c.useEffect(()=>{const a=n||r.directory;if(!a)return;const o=r.mode==="session"?{sessionId:r.sessionId,directory:r.directory}:null;$e().focusProject(a,Se(a,o))},[r.directory,r.mode,r.sessionId,n]),c.useEffect(()=>(le(t),()=>le(null)),[t]),We(),ft(),e.jsx(He,{children:e.jsx(Ge,{directory:n||r.directory,children:e.jsxs(Ke,{apis:t,children:[e.jsx(Ye,{}),e.jsx(Ve,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(vt,{config:r}),e.jsx(qe,{}),e.jsx(Je,{})]})})]})})})}const vt=({config:t})=>{const r=gt(t);return e.jsxs(e.Fragment,{children:[e.jsx(xt,{config:t}),e.jsx(yt,{}),e.jsx(Xe,{embeddedBackgroundWorkEnabled:!0}),e.jsx(mt,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:r})]})},jt=()=>{(async()=>{try{await Promise.all([be(),Ie()])}catch(t){console.error("[mini-chat-main] settings init failed:",t)}tt(),st(),rt(),Ce()})()};function Tt(t){const r=t??je();if(!r)throw new Error("Runtime APIs not registered");jt();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");ye.createRoot(n).render(e.jsx(me.StrictMode,{children:e.jsx(Qe,{children:e.jsx(et,{children:e.jsx(wt,{apis:r})})})}))}export{Tt as renderElectronMiniChatApp};