@pi-chamber/web 0.7.1 → 0.8.0

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 (190) hide show
  1. package/README.md +2 -1
  2. package/bin/cli.js +2 -2
  3. package/bin/cli.test.js +98 -1
  4. package/bin/lib/DOCUMENTATION.md +2 -1
  5. package/bin/lib/cli-args.js +8 -5
  6. package/bin/lib/cli-startup.js +10 -7
  7. package/bin/lib/cli-startup.test.js +28 -0
  8. package/bin/lib/commands-startup.js +152 -6
  9. package/dist/assets/{DiagramEditor-C7xe1Brl.js → DiagramEditor-YPSKccgo.js} +1 -1
  10. package/dist/assets/DiagramView-C-PbBHce.js +1 -0
  11. package/dist/assets/DiffView-DfltyfN2.js +18 -0
  12. package/dist/assets/FilesView-BEjbLiK2.js +6 -0
  13. package/dist/assets/GitView-B_zTaXX4.js +8 -0
  14. package/dist/assets/JsonTreeView-9p4txyB_.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl-CbRPLK2x.js +12 -0
  16. package/dist/assets/PatchDiff-rKjeUBRl.js +1 -0
  17. package/dist/assets/SessionSwitcherContent-C_VxKFJy.js +1 -0
  18. package/dist/assets/SessionSwitcherDropdown-_k4P32o9.js +2 -0
  19. package/dist/assets/SessionUnreadDot-bT_0MixU.js +1 -0
  20. package/dist/assets/SettingsView-CqZ1ZAWG.js +2 -0
  21. package/dist/assets/SettingsWindow-C7vVE35-.js +1 -0
  22. package/dist/assets/ToolOutputDialog-GBbzATa6.js +8 -0
  23. package/dist/assets/ToolPartDiffPreview-Bdb9p5uS.js +1 -0
  24. package/dist/assets/{VirtualizedFileDiff-DFx8xsmh.js → VirtualizedFileDiff-CA8hQyz9.js} +4 -4
  25. package/dist/assets/{Virtualizer-BxW2CJGB.js → Virtualizer-BSHVMKgK.js} +1 -1
  26. package/dist/assets/{appThemeRegistry-BK0dHKa6.js → appThemeRegistry-gegrE2dq.js} +1 -1
  27. package/dist/assets/collapsible-uwSKBy-K.js +1 -0
  28. package/dist/assets/computeVirtualFileMetrics-9LNCLvAG.js +3 -0
  29. package/dist/assets/contextFileOpenGuard-CZSqdEHk.js +1 -0
  30. package/dist/assets/gitStatusPredicates-CRmbLl-x.js +134 -0
  31. package/dist/assets/index-BeJEipxi.js +1 -0
  32. package/dist/assets/index-CaP8oFLB.js +8 -0
  33. package/dist/assets/index-Dq8CnRYM.css +1 -0
  34. package/dist/assets/isDiffPlainText-YYyZNTdb.js +1 -0
  35. package/dist/assets/isFilePlainText-C70Z71bG.js +1 -0
  36. package/dist/assets/main-CsdVAKy_.js +135 -0
  37. package/dist/assets/main-GMQIZjuQ.js +2 -0
  38. package/dist/assets/{markdownCore-CzWR_p3k.js → markdownCore-BgVcDt0q.js} +2 -2
  39. package/dist/assets/miniChat-W6YsdiWR.js +2 -0
  40. package/dist/assets/mobile-BFR9CR5w.js +2 -0
  41. package/dist/assets/{permissionStore-BRcQ9Jgt.js → permissionStore-iKN1K2_x.js} +1 -1
  42. package/dist/assets/registerCustomTheme-DmolaWWZ.js +1 -0
  43. package/dist/assets/renderElectronMiniChatApp-B8ZiW-3E.js +2 -0
  44. package/dist/assets/renderMobileApp-C5CdsYP6.js +11 -0
  45. package/dist/assets/runtimeEndpointReset-D3AZYuoF.js +54 -0
  46. package/dist/assets/{runtimeSurface-OhCUGSKg.js → runtimeSurface-B818u-_c.js} +1 -1
  47. package/dist/assets/themeResolver-yJ9XpNMI.js +1 -0
  48. package/dist/assets/{WindowsWindowControls-DIqnZ2uU.js → useAppFontEffects-CYzYRbLp.js} +126 -499
  49. package/dist/assets/useFilesViewSearch-C--GWtn-.js +7 -0
  50. package/dist/assets/usePushVisibilityBeacon-D9lajdAc.js +10 -0
  51. package/dist/assets/useSwitcherItems-DOoi3x_8.js +1 -0
  52. package/dist/assets/vendor-base-ui-vkqQ2P9o.js +1 -0
  53. package/dist/assets/{vendor-beautiful-mermaid-r4GK_usS.js → vendor-beautiful-mermaid-DneUawHp.js} +1 -1
  54. package/dist/assets/{vendor-cmdk-BCEUzcHE.js → vendor-cmdk-zXx6sGnS.js} +1 -1
  55. package/dist/assets/{vendor-codemirror-autocomplete-BS2SpSAZ.js → vendor-codemirror-autocomplete-wd6iRebq.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-commands-RrgJ8H_6.js → vendor-codemirror-commands-DYppkHEk.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-ADhO_TUK.js → vendor-codemirror-lang-angular-DU_4KiiW.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-cpp-BGCWj7Om.js → vendor-codemirror-lang-cpp-CmIT9Z5_.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-css-Ba8JZ6fp.js → vendor-codemirror-lang-css-djiuoTi8.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-lang-go-DyTiHXo4.js → vendor-codemirror-lang-go-COZSwZYW.js} +1 -1
  61. package/dist/assets/{vendor-codemirror-lang-html-DK27qQri.js → vendor-codemirror-lang-html-CKHqhW5R.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-lang-java-CvFfnhPQ.js → vendor-codemirror-lang-java-CNMP5hyC.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-javascript-BUlYhQ3o.js → vendor-codemirror-lang-javascript-DuOEwJ3f.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-jinja-wBMtAEvT.js → vendor-codemirror-lang-jinja-DaKn_b1k.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-json-CqayksDf.js → vendor-codemirror-lang-json-CZ07HmNC.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-less-Ct3-H1PB.js → vendor-codemirror-lang-less-wJdQiDBf.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-liquid-XspREksq.js → vendor-codemirror-lang-liquid-0z48Roi8.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-markdown-CvO36Y1p.js → vendor-codemirror-lang-markdown-DtcZDGqe.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-php-BlUF9cCe.js → vendor-codemirror-lang-php-W8plS-JQ.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-python-_2bIYTiJ.js → vendor-codemirror-lang-python-DzzokVau.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-rust-BdTYih_U.js → vendor-codemirror-lang-rust-C4ulBVpf.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sass-E6MhfOFk.js → vendor-codemirror-lang-sass-BkZJYEwS.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-sql-B1BRhQSF.js → vendor-codemirror-lang-sql-HpQWHJjv.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-vue-BYQJRa1Q.js → vendor-codemirror-lang-vue-DiBPljCc.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-wast-D706yuyC.js → vendor-codemirror-lang-wast-DoABsogh.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-xml--MfWU6Dj.js → vendor-codemirror-lang-xml-BhLJhOCH.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-yaml-CRUFIbRX.js → vendor-codemirror-lang-yaml-D95i1Y5R.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-language-E2vgV9K3.js → vendor-codemirror-language-BByA_dGF.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-language-data-Dv4zaHRN.js → vendor-codemirror-language-data-DS_4W5G4.js} +2 -2
  80. package/dist/assets/{vendor-codemirror-search-8kyQdB3f.js → vendor-codemirror-search-BV44140v.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-view-DSzLbZiS.js → vendor-codemirror-view-Ct4T37Ue.js} +1 -1
  82. package/dist/assets/{vendor-dnd-kit-accessibility-Cv52zwWT.js → vendor-dnd-kit-accessibility-DZKKhs9S.js} +1 -1
  83. package/dist/assets/{vendor-dnd-kit-core-GipZW2tY.js → vendor-dnd-kit-core-CP8ck10N.js} +1 -1
  84. package/dist/assets/{vendor-dnd-kit-sortable-Ct2QxIHb.js → vendor-dnd-kit-sortable-B-Icjoj4.js} +1 -1
  85. package/dist/assets/{vendor-dnd-kit-utilities-CrOcp0Bp.js → vendor-dnd-kit-utilities-DTY1C6ST.js} +1 -1
  86. package/dist/assets/{vendor-elkjs-CRCLNXjf.js → vendor-elkjs-mzfkf0ML.js} +1 -1
  87. package/dist/assets/{vendor-floating-ui-dom-Bkw82kL9.js → vendor-floating-ui-dom-WyXykhNi.js} +1 -1
  88. package/dist/assets/{vendor-floating-ui-react-dom-sVFnuruh.js → vendor-floating-ui-react-dom-BZOGXAGe.js} +1 -1
  89. package/dist/assets/{vendor-framer-motion-DJASDzNt.js → vendor-framer-motion-BUygY0oN.js} +1 -1
  90. package/dist/assets/{vendor-heic2any-L8hyfc24.js → vendor-heic2any-BHsbokcA.js} +1 -1
  91. package/dist/assets/{vendor-lru_map-B-cPXHXW.js → vendor-lru_map-Cy8fTs3_.js} +1 -1
  92. package/dist/assets/{vendor-pierre-theming-C6Z4M5_u.js → vendor-pierre-theming-Dgp7B_O4.js} +1 -1
  93. package/dist/assets/{vendor-qrcode-COsmt6jn.js → vendor-qrcode-B0KNSajT.js} +1 -1
  94. package/dist/assets/{vendor-radix-ui-react-compose-refs-D1GnwnP9.js → vendor-radix-ui-react-compose-refs-8xy6TJML.js} +1 -1
  95. package/dist/assets/{vendor-radix-ui-react-context-CM4yFQ2I.js → vendor-radix-ui-react-context-CFsX-AUC.js} +1 -1
  96. package/dist/assets/{vendor-radix-ui-react-dialog-jX3Dld8c.js → vendor-radix-ui-react-dialog-D2yhEu2p.js} +1 -1
  97. package/dist/assets/{vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js → vendor-radix-ui-react-dismissable-layer-DrorBNg9.js} +1 -1
  98. package/dist/assets/{vendor-radix-ui-react-focus-guards-D5MZ0nQs.js → vendor-radix-ui-react-focus-guards-BfdFmL7c.js} +1 -1
  99. package/dist/assets/{vendor-radix-ui-react-focus-scope-C2K7lNPv.js → vendor-radix-ui-react-focus-scope-D2BkImwt.js} +1 -1
  100. package/dist/assets/{vendor-radix-ui-react-id-BcxRjnbX.js → vendor-radix-ui-react-id-D2kS9K1j.js} +1 -1
  101. package/dist/assets/vendor-radix-ui-react-portal-YgCRIyi7.js +1 -0
  102. package/dist/assets/{vendor-radix-ui-react-presence-Btn-Dp7L.js → vendor-radix-ui-react-presence-D432pCMB.js} +1 -1
  103. package/dist/assets/{vendor-radix-ui-react-primitive-CfpW6_IT.js → vendor-radix-ui-react-primitive-DkH8dMOR.js} +1 -1
  104. package/dist/assets/{vendor-radix-ui-react-slot-BxUc3Pvz.js → vendor-radix-ui-react-slot-BIDFZX0-.js} +1 -1
  105. package/dist/assets/{vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js → vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js} +1 -1
  106. package/dist/assets/{vendor-radix-ui-react-use-controllable-state-C_ecoh35.js → vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js} +1 -1
  107. package/dist/assets/vendor-radix-ui-react-use-effect-event-D94va83M.js +1 -0
  108. package/dist/assets/{vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js → vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js} +1 -1
  109. package/dist/assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js +1 -0
  110. package/dist/assets/{vendor-react-DYyjh7Q0.js → vendor-react-B5Z1Mdn3.js} +1 -1
  111. package/dist/assets/{vendor-react-drawio-Boqanm0j.js → vendor-react-drawio-BYDptOsj.js} +1 -1
  112. package/dist/assets/{vendor-react-remove-scroll-bar-C9YRs2nU.js → vendor-react-remove-scroll-bar-CSAHp1YF.js} +1 -1
  113. package/dist/assets/{vendor-react-remove-scroll-CfeMe0DL.js → vendor-react-remove-scroll-vR1dy1aP.js} +1 -1
  114. package/dist/assets/{vendor-react-style-singleton-B1H4bWSG.js → vendor-react-style-singleton-Ctw6HnYx.js} +1 -1
  115. package/dist/assets/{vendor-replit-codemirror-vim-BJY5fGLS.js → vendor-replit-codemirror-vim-CGHHNQxC.js} +1 -1
  116. package/dist/assets/{vendor-sonner-CW8w438f.js → vendor-sonner-BDtm25td.js} +1 -1
  117. package/dist/assets/{vendor-tanstack-react-virtual-IrbCBGJ4.js → vendor-tanstack-react-virtual-2skouoFw.js} +1 -1
  118. package/dist/assets/{vendor-use-callback-ref-CJB0R85I.js → vendor-use-callback-ref-CVVuCyLj.js} +1 -1
  119. package/dist/assets/{vendor-use-sidecar-C-AuTczP.js → vendor-use-sidecar-Vv4V8Nd1.js} +1 -1
  120. package/dist/assets/{vendor-use-sync-external-store-B7OScDIw.js → vendor-use-sync-external-store-D0AXkdQC.js} +1 -1
  121. package/dist/assets/{vendor-zustand-CnsBKjP5.js → vendor-zustand-GVb4H8HE.js} +1 -1
  122. package/dist/assets/{web-components-BOt08OHk.js → web-components-C2cMNPqE.js} +2 -2
  123. package/dist/index.html +6 -6
  124. package/dist/mini-chat.html +5 -5
  125. package/dist/mobile.html +5 -5
  126. package/package.json +1 -1
  127. package/server/lib/git/DOCUMENTATION.md +3 -2
  128. package/server/lib/git/routes.js +27 -0
  129. package/server/lib/git/routes.test.js +41 -0
  130. package/server/lib/git/service.js +7 -1
  131. package/server/lib/git/service.test.js +23 -0
  132. package/server/lib/package-manager.js +32 -1
  133. package/server/lib/package-manager.test.js +21 -0
  134. package/server/lib/pi/attachment-store.js +95 -22
  135. package/server/lib/pi/attachment-store.test.js +23 -0
  136. package/server/lib/pi/routes.js +383 -49
  137. package/server/lib/pi/routes.test.js +377 -3
  138. package/server/lib/pi/session-daemon/DOCUMENTATION.md +3 -3
  139. package/server/lib/pi/session-daemon/prompt-operations.test.js +318 -0
  140. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +2 -0
  141. package/server/lib/pi/session-daemon/session-daemon.js +316 -25
  142. package/server/lib/pi/session-daemon/session-daemon.test.js +137 -0
  143. package/server/lib/pi/session-daemon/supervisor.test.js +1 -1
  144. package/server/lib/pi/snippets-store.js +400 -0
  145. package/server/lib/pi/snippets-store.test.js +252 -0
  146. package/server/lib/relay/host-client.test.js +79 -15
  147. package/server/lib/server/cors.js +2 -0
  148. package/server/lib/server/cors.test.js +6 -5
  149. package/dist/assets/CommitSection-DuGkZ_bm.js +0 -1
  150. package/dist/assets/DiagramView-BTqROEWP.js +0 -1
  151. package/dist/assets/DiffView-hcqXTjEc.js +0 -18
  152. package/dist/assets/FilesView-GadyKxta.js +0 -14
  153. package/dist/assets/GitView-BKy-hYUN.js +0 -6
  154. package/dist/assets/JsonTreeView-CGc4eTGI.js +0 -1
  155. package/dist/assets/MarkdownRendererImpl-CqfEAhPM.js +0 -12
  156. package/dist/assets/PatchDiff-P17-Byb8.js +0 -1
  157. package/dist/assets/PierreDiffViewer-BbUCO4IF.js +0 -136
  158. package/dist/assets/SessionSwitcherContent-j6KFBSe0.js +0 -1
  159. package/dist/assets/SessionSwitcherDropdown-DSVeuuVL.js +0 -2
  160. package/dist/assets/SessionUnreadDot-BVBBEBTg.js +0 -1
  161. package/dist/assets/SettingsView-FnmtcWZc.js +0 -4
  162. package/dist/assets/SettingsWindow-Bascj0V3.js +0 -1
  163. package/dist/assets/ToolOutputDialog-CPMzJ27S.js +0 -15
  164. package/dist/assets/ToolPartDiffPreview-BZSRKHHM.js +0 -8
  165. package/dist/assets/collapsible-DlqZyxEY.js +0 -1
  166. package/dist/assets/computeVirtualFileMetrics-elCbdk6U.js +0 -3
  167. package/dist/assets/contextFileOpenGuard-BmQ7Zu-L.js +0 -1
  168. package/dist/assets/index-BerHSX92.js +0 -1
  169. package/dist/assets/index-ChFxkws4.js +0 -8
  170. package/dist/assets/index-DZ-f_hCQ.css +0 -1
  171. package/dist/assets/isDiffPlainText-CvfRfc7h.js +0 -1
  172. package/dist/assets/isFilePlainText-_vq9Ghu3.js +0 -1
  173. package/dist/assets/main-DTCOwPr3.js +0 -2
  174. package/dist/assets/main-DYs-nZO6.js +0 -133
  175. package/dist/assets/miniChat-C2XxEA3N.js +0 -2
  176. package/dist/assets/mobile-BQhAOqV7.js +0 -2
  177. package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
  178. package/dist/assets/renderElectronMiniChatApp-M2bY1WKA.js +0 -2
  179. package/dist/assets/renderMobileApp-BnpHUUhY.js +0 -14
  180. package/dist/assets/themeResolver-BmJyTmjJ.js +0 -1
  181. package/dist/assets/useInlineCommentController-DC0iNSYX.js +0 -2
  182. package/dist/assets/usePanelSlide-aeAIo1cp.js +0 -56
  183. package/dist/assets/usePushVisibilityBeacon-om5Qlrt6.js +0 -10
  184. package/dist/assets/useSwitcherItems-Bln2r_Q2.js +0 -1
  185. package/dist/assets/vendor-base-ui-DL8r2fgQ.js +0 -1
  186. package/dist/assets/vendor-radix-ui-react-portal-xlJWBfDg.js +0 -1
  187. package/dist/assets/vendor-radix-ui-react-use-effect-event-DkJl_Rn_.js +0 -1
  188. package/dist/assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js +0 -1
  189. package/dist/assets/vendor-remixicon-react-CzPq62YO.js +0 -1
  190. /package/dist/assets/{usePanelSlide-BV3KOtdA.css → runtimeEndpointReset-BV3KOtdA.css} +0 -0
@@ -702,6 +702,37 @@ describe('Pi session daemon spike', () => {
702
702
  await client.close();
703
703
  });
704
704
 
705
+ it('leaves an extension-only session unnamed until its first conversation prompt', async () => {
706
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-extension-title-'));
707
+ const endpoint = testDaemonEndpoint(root);
708
+ const runtime = new FakeRuntime({ cwd: root, session: new FakeSession('pi-session-old') });
709
+ daemon = createSessionDaemon({
710
+ endpoint,
711
+ credential,
712
+ cwd: root,
713
+ createRuntime: async () => runtime,
714
+ });
715
+ await daemon.start();
716
+
717
+ const client = connectClient(endpoint);
718
+ await client.authenticate();
719
+ await client.request('sessions.create', { cwd: root });
720
+ runtime.session.extensionRunner = {
721
+ getRegisteredCommands: () => [{ invocationName: 'balance' }],
722
+ };
723
+
724
+ await client.request('sessions.prompt', { sessionId: 'pi-session-new', text: '/balance' });
725
+ expect(runtime.session.names).toEqual([]);
726
+
727
+ const promptedUpdated = client.next((frame) => frame.event === 'session.updated' && frame.payload?.title === 'Build the feature');
728
+ await client.request('sessions.prompt', { sessionId: 'pi-session-new', text: 'Build the feature' });
729
+ await expect(promptedUpdated).resolves.toMatchObject({
730
+ payload: { sessionId: 'pi-session-new', title: 'Build the feature' },
731
+ });
732
+ expect(runtime.session.names).toEqual(['Build the feature']);
733
+ await client.close();
734
+ });
735
+
705
736
  it('creates a global session from the literal home-directory target', async () => {
706
737
  const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
707
738
  const endpoint = testDaemonEndpoint(root);
@@ -1846,6 +1877,45 @@ describe('Pi session daemon spike', () => {
1846
1877
  await client.close();
1847
1878
  });
1848
1879
 
1880
+ it('publishes session.model when an extension command switches the model without a session event', async () => {
1881
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-command-model-'));
1882
+ const endpoint = testDaemonEndpoint(root);
1883
+ const sessionFile = join(root, 'session-1.jsonl');
1884
+ await writeFile(sessionFile, `{"type":"session","id":"session-1","cwd":"${root}"}\n`);
1885
+ const session = new FakeSession('session-1', sessionFile);
1886
+ // Pi notifies extensions of model switches, not session subscribers:
1887
+ // mutate live runtime state without emitting any session event.
1888
+ session.prompt = async () => {
1889
+ session.model = { provider: 'openai-codex', id: 'gpt-5.6-luna' };
1890
+ };
1891
+ daemon = createSessionDaemon({
1892
+ endpoint,
1893
+ credential,
1894
+ cwd: root,
1895
+ createRuntime: async () => new FakeRuntime({ cwd: root, session }),
1896
+ listSessions: async () => [
1897
+ { path: sessionFile, id: 'session-1', cwd: root, created: new Date(), modified: new Date(), messageCount: 0 },
1898
+ ],
1899
+ });
1900
+ await daemon.start();
1901
+ const client = connectClient(endpoint);
1902
+ await client.authenticate();
1903
+
1904
+ const modelChanged = client.next((frame) => frame.event === 'session.model');
1905
+ await expect(client.request('sessions.prompt', {
1906
+ sessionId: 'session-1',
1907
+ text: '/balance',
1908
+ })).resolves.toMatchObject({ result: { accepted: true } });
1909
+
1910
+ await expect(modelChanged).resolves.toMatchObject({
1911
+ payload: {
1912
+ sessionId: 'session-1',
1913
+ model: { providerId: 'openai-codex', modelId: 'gpt-5.6-luna' },
1914
+ },
1915
+ });
1916
+ await client.close();
1917
+ });
1918
+
1849
1919
  it('acknowledges a prompt without waiting for the agent turn to finish', async () => {
1850
1920
  const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-prompt-ack-'));
1851
1921
  const endpoint = testDaemonEndpoint(root);
@@ -1884,6 +1954,73 @@ describe('Pi session daemon spike', () => {
1884
1954
  await client.close();
1885
1955
  });
1886
1956
 
1957
+ it('handles prompt with image attachments and sends multi-part content', async () => {
1958
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-prompt-img-'));
1959
+ const endpoint = testDaemonEndpoint(root);
1960
+ const sessionFile = join(root, 'session-1.jsonl');
1961
+ const imageFile = join(root, 'test.png');
1962
+ await writeFile(sessionFile, `{"type":"session","id":"session-1","cwd":"${root}"}\n`);
1963
+ await writeFile(imageFile, Buffer.from('fake-png-data'));
1964
+ const session = new FakeSession('session-1', sessionFile);
1965
+ const finishSends = [];
1966
+ session.sendUserMessage = (content, options) => {
1967
+ session.sent.push({ text: content, options });
1968
+ return new Promise((resolve) => finishSends.push(resolve));
1969
+ };
1970
+ daemon = createSessionDaemon({
1971
+ endpoint,
1972
+ credential,
1973
+ cwd: root,
1974
+ createRuntime: async () => new FakeRuntime({ cwd: root, session }),
1975
+ listSessions: async () => [
1976
+ { path: sessionFile, id: 'session-1', cwd: root, created: new Date(), modified: new Date(), messageCount: 0 },
1977
+ ],
1978
+ });
1979
+ await daemon.start();
1980
+ const client = connectClient(endpoint);
1981
+ await client.authenticate();
1982
+
1983
+ await client.request('sessions.prompt', {
1984
+ sessionId: 'session-1',
1985
+ text: 'first without a file',
1986
+ messageId: 'msg-0',
1987
+ });
1988
+ const firstUserStart = client.next((frame) => frame.event === 'assistant.message.start' && frame.payload.role === 'user');
1989
+ session.emit({ type: 'message_start', message: { role: 'user', content: 'first without a file', timestamp: 900 } });
1990
+
1991
+ const response = await client.request('sessions.prompt', {
1992
+ sessionId: 'session-1',
1993
+ text: 'what is this?',
1994
+ attachments: [{
1995
+ name: 'image-1.png',
1996
+ mime: 'image/png',
1997
+ path: imageFile,
1998
+ size: 13,
1999
+ }],
2000
+ messageId: 'msg-1',
2001
+ });
2002
+
2003
+ expect(response.result).toEqual({ accepted: true, messageId: 'msg-1' });
2004
+ const secondUserStart = client.next((frame) => frame.event === 'assistant.message.start'
2005
+ && frame.payload?.role === 'user'
2006
+ && frame.payload?.text === 'what is this?');
2007
+ session.emit({ type: 'message_start', message: { role: 'user', content: session.sent[1].text, timestamp: 1_000 } });
2008
+ await expect(firstUserStart).resolves.not.toHaveProperty('payload.files');
2009
+ await expect(secondUserStart).resolves.toMatchObject({
2010
+ payload: {
2011
+ role: 'user',
2012
+ text: 'what is this?',
2013
+ files: [{ type: 'file', mime: 'image/png', filename: 'image-1.png' }],
2014
+ },
2015
+ });
2016
+ expect(session.sent).toHaveLength(2);
2017
+ expect(Array.isArray(session.sent[1].text)).toBe(true);
2018
+ expect(session.sent[1].text[0]).toEqual({ type: 'text', text: 'what is this?' });
2019
+ expect(session.sent[1].text[1]).toEqual({ type: 'image', mimeType: 'image/png', data: Buffer.from('fake-png-data').toString('base64') });
2020
+ for (const finish of finishSends) finish();
2021
+ await client.close();
2022
+ });
2023
+
1887
2024
  it('starts a new turn when follow-up arrives after the stream has already ended', async () => {
1888
2025
  const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-followup-idle-'));
1889
2026
  const endpoint = testDaemonEndpoint(root);
@@ -92,7 +92,7 @@ describe('Pi session daemon supervisor', () => {
92
92
  await expect(supervisor.health()).resolves.toEqual({
93
93
  state: 'ready',
94
94
  protocolVersion: 1,
95
- capabilities: expect.arrayContaining(['projects.list', 'projects.select', 'sessions.list', 'sessions.create', 'sessions.open', 'sessions.rename', 'sessions.delete', 'sessions.tree', 'sessions.navigate', 'sessions.fork', 'sessions.clone', 'sessions.prompt', 'sessions.steer', 'sessions.followUp', 'sessions.abort', 'sessions.setModel', 'sessions.setThinking', 'sessions.compact', 'providers.list', 'providers.config.get', 'providers.models.set', 'providers.status', 'providers.login', 'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set', 'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.delete']),
95
+ capabilities: expect.arrayContaining(['projects.list', 'projects.select', 'sessions.list', 'sessions.create', 'sessions.open', 'sessions.rename', 'sessions.delete', 'sessions.tree', 'sessions.navigate', 'sessions.fork', 'sessions.clone', 'sessions.prompt', 'sessions.steer', 'sessions.followUp', 'sessions.abort', 'sessions.setModel', 'sessions.setThinking', 'sessions.compact', 'providers.list', 'providers.config.get', 'providers.models.set', 'providers.status', 'providers.login', 'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set', 'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.update', 'resources.prompts.delete']),
96
96
  });
97
97
  await expect(supervisor.request('sessions.list')).resolves.toMatchObject({ sessions: expect.any(Array) });
98
98
 
@@ -0,0 +1,400 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import {
3
+ chmod,
4
+ mkdir,
5
+ readFile,
6
+ rename,
7
+ rm,
8
+ writeFile,
9
+ } from "node:fs/promises";
10
+ import { dirname, isAbsolute, join, normalize } from "node:path";
11
+
12
+ import { resolvePiChamberDataDir } from "../pichamber-data-dir.js";
13
+
14
+ const MAX_FILE_BYTES = 2 * 1024 * 1024;
15
+ const MAX_CONTENT_CHARS = 200_000;
16
+ const MAX_DESCRIPTION_CHARS = 4_000;
17
+ const MAX_ALIASES = 10;
18
+ const NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
19
+ const FORBIDDEN_KEYS = new Set(["__proto__", "prototype", "constructor"]);
20
+
21
+ const invalid = (code = "SNIPPETS_INVALID") => {
22
+ const error = new Error("PiChamber snippets are invalid.");
23
+ error.code = code;
24
+ return error;
25
+ };
26
+
27
+ const isRecord = (value) =>
28
+ value !== null && typeof value === "object" && !Array.isArray(value);
29
+
30
+ const normalizeName = (value) =>
31
+ typeof value === "string" ? value.trim() : "";
32
+
33
+ const validateName = (value) => {
34
+ const name = normalizeName(value);
35
+ if (!NAME_PATTERN.test(name)) throw invalid("INVALID_ARGUMENT");
36
+ return name;
37
+ };
38
+
39
+ const validateContent = (value) => {
40
+ if (
41
+ typeof value !== "string" ||
42
+ value.length === 0 ||
43
+ value.length > MAX_CONTENT_CHARS
44
+ ) {
45
+ throw invalid("INVALID_ARGUMENT");
46
+ }
47
+ return value;
48
+ };
49
+
50
+ const validateDescription = (value) => {
51
+ if (value === undefined) return "";
52
+ if (typeof value !== "string" || value.length > MAX_DESCRIPTION_CHARS)
53
+ throw invalid("INVALID_ARGUMENT");
54
+ return value;
55
+ };
56
+
57
+ const validateAliases = (value) => {
58
+ if (value === undefined) return [];
59
+ if (!Array.isArray(value) || value.length > MAX_ALIASES)
60
+ throw invalid("INVALID_ARGUMENT");
61
+ const seen = new Set();
62
+ const aliases = [];
63
+ for (const entry of value) {
64
+ const alias = normalizeName(entry);
65
+ if (!NAME_PATTERN.test(alias)) throw invalid("INVALID_ARGUMENT");
66
+ const lower = alias.toLowerCase();
67
+ if (seen.has(lower)) throw invalid("INVALID_ARGUMENT");
68
+ seen.add(lower);
69
+ aliases.push(alias);
70
+ }
71
+ return aliases;
72
+ };
73
+
74
+ const validateScope = (value) => {
75
+ if (value !== "global" && value !== "project")
76
+ throw invalid("INVALID_ARGUMENT");
77
+ return value;
78
+ };
79
+
80
+ const validateDirectory = (value, scope) => {
81
+ if (scope === "global") return null;
82
+ if (
83
+ typeof value !== "string" ||
84
+ value.trim().length === 0 ||
85
+ value.length > 2048
86
+ ) {
87
+ throw invalid("INVALID_ARGUMENT");
88
+ }
89
+ const trimmed = value.trim();
90
+ if (trimmed === "~") return trimmed;
91
+ if (!isAbsolute(trimmed)) throw invalid("INVALID_ARGUMENT");
92
+ return normalize(trimmed);
93
+ };
94
+
95
+ const validateSnippetRecord = (value) => {
96
+ if (!isRecord(value)) throw invalid();
97
+ const id =
98
+ typeof value.id === "string" &&
99
+ value.id.length > 0 &&
100
+ value.id.length <= 128
101
+ ? value.id
102
+ : null;
103
+ if (!id) throw invalid();
104
+ const name = validateName(value.name);
105
+ if (
106
+ typeof value.content !== "string" ||
107
+ value.content.length === 0 ||
108
+ value.content.length > MAX_CONTENT_CHARS
109
+ )
110
+ throw invalid();
111
+ const description = validateDescription(value.description);
112
+ const aliases = validateAliases(value.aliases);
113
+ const scope = validateScope(value.scope);
114
+ const directory =
115
+ scope === "project" ? validateDirectory(value.directory, scope) : null;
116
+ const createdAt =
117
+ Number.isSafeInteger(value.createdAt) && value.createdAt > 0
118
+ ? value.createdAt
119
+ : null;
120
+ const updatedAt =
121
+ Number.isSafeInteger(value.updatedAt) && value.updatedAt > 0
122
+ ? value.updatedAt
123
+ : null;
124
+ if (!createdAt || !updatedAt) throw invalid();
125
+ return {
126
+ id,
127
+ name,
128
+ content: value.content,
129
+ description,
130
+ aliases,
131
+ scope,
132
+ directory,
133
+ createdAt,
134
+ updatedAt,
135
+ };
136
+ };
137
+
138
+ const validateSnapshot = (value) => {
139
+ if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.snippets))
140
+ throw invalid();
141
+ const snippets = value.snippets.map(validateSnippetRecord);
142
+ const ids = new Set();
143
+ for (const snippet of snippets) {
144
+ if (ids.has(snippet.id)) throw invalid();
145
+ ids.add(snippet.id);
146
+ try {
147
+ assertUniqueInBucket(snippets, snippet, snippet.id);
148
+ } catch {
149
+ throw invalid();
150
+ }
151
+ }
152
+ const snapshot = { version: 1, snippets };
153
+ if (Buffer.byteLength(JSON.stringify(snapshot)) > MAX_FILE_BYTES)
154
+ throw invalid();
155
+ return snapshot;
156
+ };
157
+
158
+ const bucketKey = (snippet) =>
159
+ snippet.scope === "project" ? `project:${snippet.directory ?? ""}` : "global";
160
+
161
+ const assertUniqueInBucket = (snippets, candidate, ignoreId) => {
162
+ const bucket = bucketKey(candidate);
163
+ const taken = new Map();
164
+ for (const snippet of snippets) {
165
+ if (snippet.id === ignoreId) continue;
166
+ if (bucketKey(snippet) !== bucket) continue;
167
+ taken.set(snippet.name.toLowerCase(), snippet.name);
168
+ for (const alias of snippet.aliases ?? [])
169
+ taken.set(alias.toLowerCase(), alias);
170
+ }
171
+ const candidateTokens = [candidate.name, ...(candidate.aliases ?? [])].map(
172
+ (token) => token.toLowerCase(),
173
+ );
174
+ const seenCandidate = new Set();
175
+ for (const token of candidateTokens) {
176
+ if (seenCandidate.has(token)) throw invalid("INVALID_ARGUMENT");
177
+ seenCandidate.add(token);
178
+ if (taken.has(token)) {
179
+ const error = invalid("INVALID_ARGUMENT");
180
+ error.message = "A PiChamber snippet with that name already exists.";
181
+ throw error;
182
+ }
183
+ }
184
+ };
185
+
186
+ export const createPiSnippetsStore = ({
187
+ file = join(resolvePiChamberDataDir(), "pi", "snippets.json"),
188
+ fs = { chmod, mkdir, readFile, rename, rm, writeFile },
189
+ } = {}) => {
190
+ let mutation = Promise.resolve();
191
+
192
+ const readRaw = async () => {
193
+ try {
194
+ const raw = await fs.readFile(file, "utf8");
195
+ if (Buffer.byteLength(raw) > MAX_FILE_BYTES) throw invalid();
196
+ return validateSnapshot(JSON.parse(raw));
197
+ } catch (error) {
198
+ if (error?.code === "ENOENT") return { version: 1, snippets: [] };
199
+ if (
200
+ error?.code === "SNIPPETS_INVALID" ||
201
+ error?.code === "INVALID_ARGUMENT"
202
+ )
203
+ throw error;
204
+ throw invalid();
205
+ }
206
+ };
207
+
208
+ const writeRaw = async (snapshot) => {
209
+ const validated = validateSnapshot(snapshot);
210
+ const parent = dirname(file);
211
+ await fs.mkdir(parent, { recursive: true, mode: 0o700 });
212
+ const temporary = `${file}.tmp-${process.pid}-${randomUUID()}`;
213
+ try {
214
+ await fs.writeFile(temporary, `${JSON.stringify(validated, null, 2)}\n`, {
215
+ encoding: "utf8",
216
+ mode: 0o600,
217
+ });
218
+ await fs.rename(temporary, file);
219
+ } catch (error) {
220
+ await fs.rm(temporary, { force: true }).catch(() => {});
221
+ throw error;
222
+ }
223
+ if (process.platform !== "win32")
224
+ await fs.chmod(file, 0o600).catch(() => {});
225
+ return validated;
226
+ };
227
+
228
+ const snippetsForDirectory = (snapshot, directory) => {
229
+ const wanted =
230
+ typeof directory === "string" && directory.trim().length > 0
231
+ ? validateDirectory(directory, "project")
232
+ : null;
233
+ return snapshot.snippets.filter(
234
+ (snippet) =>
235
+ snippet.scope === "global" ||
236
+ (wanted !== null && snippet.directory === wanted),
237
+ );
238
+ };
239
+
240
+ const transact = (operation) => {
241
+ const pending = mutation.then(operation);
242
+ mutation = pending.catch(() => {});
243
+ return pending;
244
+ };
245
+
246
+ const list = async (directory) => {
247
+ await mutation;
248
+ return snippetsForDirectory(await readRaw(), directory);
249
+ };
250
+
251
+ const create = async (input) => {
252
+ return transact(async () => {
253
+ if (!isRecord(input)) throw invalid("INVALID_ARGUMENT");
254
+ for (const key of Object.keys(input)) {
255
+ if (FORBIDDEN_KEYS.has(key)) throw invalid("INVALID_ARGUMENT");
256
+ }
257
+ const allowedCreateKeys = new Set([
258
+ "name",
259
+ "content",
260
+ "description",
261
+ "aliases",
262
+ "scope",
263
+ "directory",
264
+ ]);
265
+ for (const key of Object.keys(input)) {
266
+ if (!allowedCreateKeys.has(key)) throw invalid("INVALID_ARGUMENT");
267
+ }
268
+ const scope = validateScope(input.scope ?? "global");
269
+ const directory = validateDirectory(input.directory, scope);
270
+ const candidate = {
271
+ id: randomUUID(),
272
+ name: validateName(input.name),
273
+ content: validateContent(input.content),
274
+ description: validateDescription(input.description),
275
+ aliases: validateAliases(input.aliases),
276
+ scope,
277
+ directory,
278
+ createdAt: Date.now(),
279
+ updatedAt: Date.now(),
280
+ };
281
+ const snapshot = await readRaw();
282
+ assertUniqueInBucket(snapshot.snippets, candidate, null);
283
+ const next = await writeRaw({
284
+ version: 1,
285
+ snippets: [...snapshot.snippets, candidate],
286
+ });
287
+ return snippetsForDirectory(next, directory);
288
+ });
289
+ };
290
+
291
+ const update = async (id, input, directory) => {
292
+ return transact(async () => {
293
+ if (typeof id !== "string" || id.length === 0 || id.length > 128)
294
+ throw invalid("INVALID_ARGUMENT");
295
+ if (!isRecord(input)) throw invalid("INVALID_ARGUMENT");
296
+ for (const key of Object.keys(input)) {
297
+ if (FORBIDDEN_KEYS.has(key)) throw invalid("INVALID_ARGUMENT");
298
+ }
299
+ const allowedKeys = new Set([
300
+ "name",
301
+ "content",
302
+ "description",
303
+ "aliases",
304
+ "scope",
305
+ "directory",
306
+ ]);
307
+ for (const key of Object.keys(input)) {
308
+ if (!allowedKeys.has(key)) throw invalid("INVALID_ARGUMENT");
309
+ }
310
+ const snapshot = await readRaw();
311
+ const index = snapshot.snippets.findIndex((snippet) => snippet.id === id);
312
+ if (index === -1) {
313
+ const error = invalid("INVALID_ARGUMENT");
314
+ error.code = "SNIPPET_NOT_FOUND";
315
+ throw error;
316
+ }
317
+ const current = snapshot.snippets[index];
318
+ const wanted =
319
+ typeof directory === "string" && directory.trim().length > 0
320
+ ? validateDirectory(directory, "project")
321
+ : null;
322
+ if (current.scope === "project" && current.directory !== wanted) {
323
+ const error = invalid("INVALID_ARGUMENT");
324
+ error.code = "SNIPPET_NOT_FOUND";
325
+ throw error;
326
+ }
327
+ const nextName =
328
+ input.name !== undefined ? validateName(input.name) : current.name;
329
+ const nextScope =
330
+ input.scope !== undefined ? validateScope(input.scope) : current.scope;
331
+ let nextDirectory = current.directory;
332
+ if (nextScope === "global") {
333
+ nextDirectory = null;
334
+ } else if (input.directory !== undefined) {
335
+ nextDirectory = validateDirectory(input.directory, "project");
336
+ } else if (current.scope === "project") {
337
+ nextDirectory = current.directory;
338
+ } else {
339
+ nextDirectory = wanted;
340
+ }
341
+ if (nextScope === "project" && nextDirectory === null) {
342
+ throw invalid("INVALID_ARGUMENT");
343
+ }
344
+ const nextSnippet = {
345
+ ...current,
346
+ name: nextName,
347
+ scope: nextScope,
348
+ directory: nextDirectory,
349
+ ...(input.content !== undefined
350
+ ? { content: validateContent(input.content) }
351
+ : {}),
352
+ ...(input.description !== undefined
353
+ ? { description: validateDescription(input.description) }
354
+ : {}),
355
+ ...(input.aliases !== undefined
356
+ ? { aliases: validateAliases(input.aliases) }
357
+ : {}),
358
+ updatedAt: Date.now(),
359
+ };
360
+ assertUniqueInBucket(snapshot.snippets, nextSnippet, id);
361
+ const next = await writeRaw({
362
+ version: 1,
363
+ snippets: snapshot.snippets.map((snippet, i) =>
364
+ i === index ? nextSnippet : snippet,
365
+ ),
366
+ });
367
+ return snippetsForDirectory(next, wanted ?? nextDirectory);
368
+ });
369
+ };
370
+
371
+ const remove = async (id, directory) => {
372
+ return transact(async () => {
373
+ if (typeof id !== "string" || id.length === 0)
374
+ throw invalid("INVALID_ARGUMENT");
375
+ const snapshot = await readRaw();
376
+ const existing = snapshot.snippets.find((snippet) => snippet.id === id);
377
+ if (!existing) {
378
+ const error = invalid("INVALID_ARGUMENT");
379
+ error.code = "SNIPPET_NOT_FOUND";
380
+ throw error;
381
+ }
382
+ const wanted =
383
+ typeof directory === "string" && directory.trim().length > 0
384
+ ? validateDirectory(directory, "project")
385
+ : null;
386
+ if (existing.scope === "project" && existing.directory !== wanted) {
387
+ const error = invalid("INVALID_ARGUMENT");
388
+ error.code = "SNIPPET_NOT_FOUND";
389
+ throw error;
390
+ }
391
+ const next = await writeRaw({
392
+ version: 1,
393
+ snippets: snapshot.snippets.filter((snippet) => snippet.id !== id),
394
+ });
395
+ return snippetsForDirectory(next, wanted);
396
+ });
397
+ };
398
+
399
+ return { file, list, create, update, remove };
400
+ };