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

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 (265) hide show
  1. package/dist/assets/AgentsSurface-CcWBqAWV.js +1 -0
  2. package/dist/assets/ChoicesArtifact-Kk-qvrSB.js +1 -0
  3. package/dist/assets/DiagramView-DZUBo1uP.js +1 -0
  4. package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-CiZy4jFA.js} +6 -6
  5. package/dist/assets/FileSaveConflictDialog-DZ9NDwOO.js +3 -0
  6. package/dist/assets/FilesView-DqiZ9kw9.js +6 -0
  7. package/dist/assets/GitHubDetailScaffold-DM2DH7o8.js +11 -0
  8. package/dist/assets/GitHubLinkPicker-ChB8NZ1h.js +1 -0
  9. package/dist/assets/GitHubListPrimitives-CibDiJGq.js +1 -0
  10. package/dist/assets/{GitView-DD33ngnM.js → GitView--EaZQrBr.js} +5 -5
  11. package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-CySTpaD1.js} +3 -3
  12. package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-_yMHKKQZ.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-D_-2fQw0.js} +3 -3
  14. package/dist/assets/PatchDiff-bHObDlhD.js +1 -0
  15. package/dist/assets/PierreDiffViewer-UY7Cse-s.js +147 -0
  16. package/dist/assets/PullRequestsSurface-iXy6chwc.js +2 -0
  17. package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
  18. package/dist/assets/SessionSwitcherDropdown-CDOX-5Y2.js +2 -0
  19. package/dist/assets/SessionUnreadDot-Dwc3MdvA.js +1 -0
  20. package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
  21. package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-CUg49Mfh.js} +1 -1
  22. package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
  23. package/dist/assets/SubagentsArtifact-DUZX9tDe.js +1 -0
  24. package/dist/assets/ToolOutputDialog-BuZZaRw4.js +8 -0
  25. package/dist/assets/ToolPartDiffPreview-CKncG6i2.js +1 -0
  26. package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-BGZiLPe_.js} +4 -4
  27. package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
  28. package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
  29. package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
  30. package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-Bro9KrfM.js} +1 -1
  31. package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DJQqK49u.js} +2 -2
  32. package/dist/assets/contextFileOpenGuard-ByWK3Sru.js +1 -0
  33. package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CyJ3TOYD.js} +2 -2
  34. package/dist/assets/gitStatusPredicates-BsXrwngT.js +1 -0
  35. package/dist/assets/githubLink-g2bmC0qi.js +10 -0
  36. package/dist/assets/index-B_L9GVYw.css +1 -0
  37. package/dist/assets/{index-ComwtfT4.js → index-C9rUUQ_Y.js} +1 -1
  38. package/dist/assets/index-CKKWVoND.js +11 -0
  39. package/dist/assets/{main-DoiadX0a.js → main-DT-4_fhe.js} +2 -2
  40. package/dist/assets/main-DsLMU9CT.js +137 -0
  41. package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-QmM_aOnZ.js} +2 -2
  42. package/dist/assets/{miniChat-Ck6MEZ9Q.js → miniChat-BqGslD2z.js} +2 -2
  43. package/dist/assets/{mobile-BucKVm1P.js → mobile-C5JOcDIC.js} +2 -2
  44. package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-DSMsJqXM.js} +1 -1
  45. package/dist/assets/pi-session-focus-preference-Cc_S4zi1.js +9 -0
  46. package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
  47. package/dist/assets/renderElectronMiniChatApp-CiSkecEE.js +2 -0
  48. package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
  49. package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
  50. package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
  51. package/dist/assets/runtimeSurface-0K7vuUpd.js +1 -0
  52. package/dist/assets/selection-CnYkEsu_.js +1 -0
  53. package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
  54. package/dist/assets/useGitHubRemoteSearch-CgP-zEBj.js +1 -0
  55. package/dist/assets/useSwitcherItems-C8G5F0hs.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-BpncHjnV.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/featured.json +12 -0
  108. package/plugins/registry.json +7 -0
  109. package/plugins/subagents/LICENSE +25 -0
  110. package/plugins/subagents/agents/planner.md +36 -0
  111. package/plugins/subagents/agents/reviewer.md +34 -0
  112. package/plugins/subagents/agents/scout.md +49 -0
  113. package/plugins/subagents/agents/worker.md +23 -0
  114. package/plugins/subagents/extension.js +631 -0
  115. package/plugins/subagents/extension.test.js +295 -0
  116. package/plugins/subagents/package.json +41 -0
  117. package/plugins/visuals/choices.js +168 -0
  118. package/plugins/visuals/extension.js +90 -0
  119. package/plugins/visuals/files.js +74 -0
  120. package/plugins/visuals/package.json +32 -0
  121. package/server/index.js +103 -24
  122. package/server/lib/git/DOCUMENTATION.md +4 -0
  123. package/server/lib/git/service.js +70 -5
  124. package/server/lib/git/service.test.js +179 -0
  125. package/server/lib/github/DOCUMENTATION.md +6 -2
  126. package/server/lib/github/gh-cli.js +35 -9
  127. package/server/lib/github/gh-cli.test.js +122 -0
  128. package/server/lib/marketplace/DOCUMENTATION.md +95 -0
  129. package/server/lib/marketplace/featured.js +176 -0
  130. package/server/lib/marketplace/featured.test.js +207 -0
  131. package/server/lib/marketplace/npm-registry.js +255 -0
  132. package/server/lib/marketplace/npm-registry.test.js +227 -0
  133. package/server/lib/marketplace/routes.js +64 -0
  134. package/server/lib/marketplace/routes.test.js +119 -0
  135. package/server/lib/marketplace/service.js +225 -0
  136. package/server/lib/marketplace/service.test.js +174 -0
  137. package/server/lib/notifications/DOCUMENTATION.md +10 -4
  138. package/server/lib/notifications/pi-notification-watcher.js +95 -33
  139. package/server/lib/notifications/pi-notification-watcher.test.js +89 -0
  140. package/server/lib/open-url/DOCUMENTATION.md +2 -1
  141. package/server/lib/pi/extension-protocol.js +54 -0
  142. package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
  143. package/server/lib/pi/merged-event-stream.js +316 -0
  144. package/server/lib/pi/merged-event-stream.test.js +95 -0
  145. package/server/lib/pi/routes-daemon-pool.test.js +348 -0
  146. package/server/lib/pi/routes-extension-events.test.js +115 -0
  147. package/server/lib/pi/routes-merged-events.test.js +327 -0
  148. package/server/lib/pi/routes-sandbox.test.js +1684 -0
  149. package/server/lib/pi/routes.js +790 -87
  150. package/server/lib/pi/routes.test.js +381 -1
  151. package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
  152. package/server/lib/pi/sandbox/launcher.js +122 -0
  153. package/server/lib/pi/sandbox/launcher.test.js +91 -0
  154. package/server/lib/pi/sandbox/nono-launcher.js +455 -0
  155. package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
  156. package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
  157. package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
  158. package/server/lib/pi/sandbox/nono-profile.json +22 -0
  159. package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
  160. package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
  161. package/server/lib/pi/sandbox/project-sandbox.js +207 -0
  162. package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
  163. package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
  164. package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
  165. package/server/lib/pi/sandbox/trust-ask.js +135 -0
  166. package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
  167. package/server/lib/pi/sandbox/worktree-ids.js +96 -0
  168. package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
  169. package/server/lib/pi/session-daemon/DOCUMENTATION.md +47 -10
  170. package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
  171. package/server/lib/pi/session-daemon/daemon-process.js +10 -1
  172. package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
  173. package/server/lib/pi/session-daemon/extension-config.js +902 -0
  174. package/server/lib/pi/session-daemon/extension-config.test.js +798 -0
  175. package/server/lib/pi/session-daemon/extension-controls.js +177 -0
  176. package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
  177. package/server/lib/pi/session-daemon/extension-name.js +6 -0
  178. package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
  179. package/server/lib/pi/session-daemon/extension-palette.js +146 -0
  180. package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
  181. package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
  182. package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
  183. package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
  184. package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
  185. package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
  186. package/server/lib/pi/session-daemon/plugin-host.js +245 -0
  187. package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
  188. package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
  189. package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
  190. package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
  191. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
  192. package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
  193. package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
  194. package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
  195. package/server/lib/pi/session-daemon/session-daemon.js +927 -108
  196. package/server/lib/pi/session-daemon/session-daemon.test.js +391 -4
  197. package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
  198. package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
  199. package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
  200. package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
  201. package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
  202. package/server/lib/pi/session-daemon/session-lease.js +93 -15
  203. package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
  204. package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
  205. package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
  206. package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
  207. package/server/lib/pi/session-daemon/supervisor.js +408 -38
  208. package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
  209. package/server/lib/pi/settings-store.js +14 -0
  210. package/server/lib/pi/settings-store.test.js +11 -0
  211. package/server/lib/pi/ui-settings-store.js +88 -2
  212. package/server/lib/pi/ui-settings-store.test.js +118 -0
  213. package/server/lib/plugins/DOCUMENTATION.md +198 -0
  214. package/server/lib/plugins/daemon-sync.js +88 -0
  215. package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
  216. package/server/lib/plugins/daemon-sync.test.js +108 -0
  217. package/server/lib/plugins/impact.js +139 -0
  218. package/server/lib/plugins/impact.test.js +83 -0
  219. package/server/lib/plugins/manifest.js +220 -0
  220. package/server/lib/plugins/manifest.test.js +127 -0
  221. package/server/lib/plugins/registry.js +59 -0
  222. package/server/lib/plugins/routes.js +92 -0
  223. package/server/lib/plugins/routes.test.js +247 -0
  224. package/server/lib/plugins/service.js +183 -0
  225. package/server/lib/plugins/store.js +261 -0
  226. package/server/lib/plugins/store.test.js +188 -0
  227. package/server/lib/plugins/visuals-extension.test.js +237 -0
  228. package/server/lib/server/cross-process-lock.js +28 -3
  229. package/server/lib/server-browser/DOCUMENTATION.md +32 -7
  230. package/server/lib/server-browser/browser-tab.js +4 -1
  231. package/server/lib/server-browser/downloads.js +261 -34
  232. package/server/lib/server-browser/downloads.test.js +171 -0
  233. package/server/lib/server-browser/runtime.integration.test.js +47 -0
  234. package/server/lib/server-browser/runtime.js +16 -0
  235. package/server/lib/server-browser/server-browser.js +25 -6
  236. package/server/lib/tunnels/executable-search.js +5 -1
  237. package/server/lib/tunnels/executable-search.test.js +26 -0
  238. package/dist/assets/DiagramView-BB-aZobi.js +0 -1
  239. package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
  240. package/dist/assets/FilesView-DECxN8Z0.js +0 -6
  241. package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
  242. package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
  243. package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
  244. package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
  245. package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
  246. package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
  247. package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
  248. package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
  249. package/dist/assets/SettingsView-DcF-At5E.js +0 -6
  250. package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
  251. package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
  252. package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
  253. package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
  254. package/dist/assets/githubLink-ByPAyFjh.js +0 -10
  255. package/dist/assets/index-BaLCg7tL.css +0 -1
  256. package/dist/assets/index-I2QYqABE.js +0 -11
  257. package/dist/assets/main-DyFfbllq.js +0 -137
  258. package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
  259. package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
  260. package/dist/assets/renderMobileApp-Bp74b_Lo.js +0 -11
  261. package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
  262. package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
  263. package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
  264. package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
  265. package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
@@ -0,0 +1,255 @@
1
+ // Reads npm's public registry for the marketplace: search, a package's latest
2
+ // manifest, and weekly downloads. Every answer is reduced to a small,
3
+ // validated shape here, so nothing npm sends reaches the browser unchecked.
4
+ // See DOCUMENTATION.md.
5
+
6
+ const DEFAULT_REGISTRY_URL = 'https://registry.npmjs.org';
7
+ const DEFAULT_DOWNLOADS_URL = 'https://api.npmjs.org';
8
+
9
+ /** Pi's gallery lists npm packages with this keyword (Pi docs/packages.md). */
10
+ export const PI_PACKAGE_KEYWORD = 'pi-package';
11
+ /** Authors add this keyword to say the package has PiChamber support. */
12
+ export const PICHAMBER_KEYWORD = 'pichamber-plugin';
13
+
14
+ const USER_AGENT = 'PiChamber';
15
+ const DEFAULT_TIMEOUT_MS = 8_000;
16
+ const MAX_SEARCH_BYTES = 2 * 1024 * 1024;
17
+ const MAX_MANIFEST_BYTES = 512 * 1024;
18
+ const MAX_DOWNLOADS_BYTES = 16 * 1024;
19
+ const MAX_NAME_LENGTH = 214;
20
+ const MAX_DESCRIPTION_LENGTH = 300;
21
+ const MAX_KEYWORDS = 20;
22
+ const MAX_KEYWORD_LENGTH = 50;
23
+ const MAX_URL_LENGTH = 500;
24
+ const PI_RESOURCE_TYPES = ['extensions', 'skills', 'prompts', 'themes'];
25
+
26
+ const NPM_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
27
+ const VERSION_PATTERN = /^[0-9A-Za-z.+-]{1,64}$/;
28
+ const USERNAME_PATTERN = /^[A-Za-z0-9._~ -]{1,64}$/;
29
+ const LICENSE_PATTERN = /^[A-Za-z0-9.+() -]{1,64}$/;
30
+
31
+ export class MarketplaceError extends Error {
32
+ constructor(code, message = code) {
33
+ super(message);
34
+ this.code = code;
35
+ }
36
+ }
37
+
38
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
39
+
40
+ /** A name npm would accept for a new package, which is what `pi install npm:<name>` needs. */
41
+ export const isValidNpmName = (value) => (
42
+ typeof value === 'string' && value.length > 0 && value.length <= MAX_NAME_LENGTH && NPM_NAME_PATTERN.test(value)
43
+ );
44
+
45
+ /** One line of plain text: control characters removed, spaces collapsed, length capped. */
46
+ const plainText = (value, max) => {
47
+ if (typeof value !== 'string') return undefined;
48
+ // eslint-disable-next-line no-control-regex
49
+ const cleaned = value.replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim();
50
+ if (cleaned.length === 0) return undefined;
51
+ return cleaned.length > max ? `${cleaned.slice(0, max - 1).trimEnd()}…` : cleaned;
52
+ };
53
+
54
+ const keywordsOf = (value) => {
55
+ if (!Array.isArray(value)) return [];
56
+ const keywords = [];
57
+ for (const entry of value) {
58
+ const keyword = typeof entry === 'string' ? entry.trim().toLowerCase() : '';
59
+ if (keyword.length === 0 || keyword.length > MAX_KEYWORD_LENGTH || keywords.includes(keyword)) continue;
60
+ keywords.push(keyword);
61
+ if (keywords.length === MAX_KEYWORDS) break;
62
+ }
63
+ return keywords;
64
+ };
65
+
66
+ /** An http(s) link the UI may open, credentials removed. Anything else is dropped. */
67
+ export const safeLink = (value) => {
68
+ if (typeof value !== 'string' || value.length > MAX_URL_LENGTH) return undefined;
69
+ let text = value.trim();
70
+ // npm's repository field: `git+https://host/x.git`, `git://host/x`, `github:user/repo`.
71
+ if (/^github:/i.test(text)) text = `https://github.com/${text.slice('github:'.length)}`;
72
+ text = text.replace(/^git\+/i, '').replace(/^git:\/\//i, 'https://');
73
+ let url;
74
+ try {
75
+ url = new URL(text);
76
+ } catch {
77
+ return undefined;
78
+ }
79
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') return undefined;
80
+ url.username = '';
81
+ url.password = '';
82
+ if (url.hostname === 'github.com' || url.hostname === 'gitlab.com') url.pathname = url.pathname.replace(/\.git$/, '');
83
+ return url.toString();
84
+ };
85
+
86
+ const repositoryUrl = (repository) => safeLink(isRecord(repository) ? repository.url : repository);
87
+
88
+ const npmPageUrl = (name) => `https://www.npmjs.com/package/${name}`;
89
+
90
+ const isoDate = (value) => {
91
+ if (typeof value !== 'string') return undefined;
92
+ const time = Date.parse(value);
93
+ return Number.isFinite(time) ? new Date(time).toISOString() : undefined;
94
+ };
95
+
96
+ /** What a package's `pi` block says it adds, in Pi's resource order. */
97
+ const piContents = (pi) => (isRecord(pi)
98
+ ? PI_RESOURCE_TYPES.filter((type) => Array.isArray(pi[type]) && pi[type].length > 0)
99
+ : []);
100
+
101
+ /**
102
+ * Read a JSON body without trusting its size: the declared length is checked
103
+ * first, then the stream is cut off at `maxBytes`.
104
+ */
105
+ const readJson = async (response, maxBytes) => {
106
+ const declared = Number(response.headers?.get?.('content-length'));
107
+ if (Number.isFinite(declared) && declared > maxBytes) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer too large');
108
+ const reader = response.body?.getReader?.();
109
+ if (!reader) {
110
+ const text = await response.text();
111
+ if (text.length > maxBytes) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer too large');
112
+ return JSON.parse(text);
113
+ }
114
+ const chunks = [];
115
+ let size = 0;
116
+ for (;;) {
117
+ const { done, value } = await reader.read();
118
+ if (done) break;
119
+ size += value.byteLength;
120
+ if (size > maxBytes) {
121
+ await reader.cancel().catch(() => {});
122
+ throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer too large');
123
+ }
124
+ chunks.push(value);
125
+ }
126
+ return JSON.parse(Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString('utf8'));
127
+ };
128
+
129
+ /**
130
+ * One search hit or one manifest, reduced to what the marketplace shows.
131
+ * Returns `undefined` for an entry without a usable name.
132
+ */
133
+ export const summarizePackage = (pkg, extra = {}) => {
134
+ if (!isRecord(pkg) || !isValidNpmName(pkg.name)) return undefined;
135
+ const keywords = keywordsOf(pkg.keywords);
136
+ const version = typeof pkg.version === 'string' && VERSION_PATTERN.test(pkg.version) ? pkg.version : undefined;
137
+ const description = plainText(pkg.description, MAX_DESCRIPTION_LENGTH);
138
+ // Who maintains it, not who published: CI publishes as "GitHub Actions".
139
+ const maintainer = Array.isArray(pkg.maintainers) && isRecord(pkg.maintainers[0]) ? pkg.maintainers[0] : undefined;
140
+ const publisher = [maintainer?.username, maintainer?.name, isRecord(pkg.publisher) ? pkg.publisher.username : undefined]
141
+ .find((name) => typeof name === 'string' && USERNAME_PATTERN.test(name) && name !== 'GitHub Actions');
142
+ const date = isoDate(pkg.date);
143
+ const links = isRecord(pkg.links) ? pkg.links : {};
144
+ const repository = safeLink(links.repository) ?? repositoryUrl(pkg.repository);
145
+ const homepage = safeLink(links.homepage) ?? safeLink(pkg.homepage);
146
+ return {
147
+ name: pkg.name,
148
+ ...(version ? { version } : {}),
149
+ ...(description ? { description } : {}),
150
+ keywords,
151
+ ...(publisher ? { publisher } : {}),
152
+ ...(date ? { date } : {}),
153
+ ...(Number.isFinite(extra.weeklyDownloads) ? { weeklyDownloads: Math.max(0, Math.floor(extra.weeklyDownloads)) } : {}),
154
+ // From the keyword alone. The package page reads the manifest to confirm it.
155
+ pichamberKeyword: keywords.includes(PICHAMBER_KEYWORD),
156
+ links: {
157
+ npm: npmPageUrl(pkg.name),
158
+ ...(repository ? { repository } : {}),
159
+ ...(homepage && homepage !== repository ? { homepage } : {}),
160
+ },
161
+ };
162
+ };
163
+
164
+ /**
165
+ * The latest manifest, with what only the manifest knows: the license, what
166
+ * the `pi` block adds, and whether a `pichamber` block is really there.
167
+ */
168
+ export const summarizeManifest = (manifest) => {
169
+ const summary = summarizePackage(manifest);
170
+ if (!summary) return undefined;
171
+ const license = typeof manifest.license === 'string' && LICENSE_PATTERN.test(manifest.license) ? manifest.license : undefined;
172
+ return {
173
+ ...summary,
174
+ ...(license ? { license } : {}),
175
+ contains: piContents(manifest.pi),
176
+ pichamber: isRecord(manifest.pichamber) && typeof manifest.pichamber.apiVersion === 'number',
177
+ isPiPackage: summary.keywords.includes(PI_PACKAGE_KEYWORD),
178
+ };
179
+ };
180
+
181
+ /**
182
+ * `fetchImpl` is the global `fetch` by default; tests pass a stub. Every
183
+ * request has a timeout and a size cap. Failures throw `MarketplaceError`:
184
+ * `MARKETPLACE_UNAVAILABLE` (network, status, malformed answer) or
185
+ * `MARKETPLACE_PACKAGE_NOT_FOUND` (404 for a package).
186
+ */
187
+ export const createNpmRegistry = ({
188
+ fetchImpl = globalThis.fetch,
189
+ registryUrl = DEFAULT_REGISTRY_URL,
190
+ downloadsUrl = DEFAULT_DOWNLOADS_URL,
191
+ timeoutMs = DEFAULT_TIMEOUT_MS,
192
+ } = {}) => {
193
+ const getJson = async (url, maxBytes, { notFound } = {}) => {
194
+ const controller = new AbortController();
195
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
196
+ timer.unref?.();
197
+ try {
198
+ let response;
199
+ try {
200
+ response = await fetchImpl(url, {
201
+ headers: { accept: 'application/json', 'user-agent': USER_AGENT },
202
+ redirect: 'follow',
203
+ signal: controller.signal,
204
+ });
205
+ } catch {
206
+ throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm could not be reached');
207
+ }
208
+ if (response.status === 404 && notFound) throw new MarketplaceError(notFound);
209
+ if (!response.ok) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', `npm answered ${response.status}`);
210
+ try {
211
+ return await readJson(response, maxBytes);
212
+ } catch (error) {
213
+ if (error instanceof MarketplaceError) throw error;
214
+ throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer unreadable');
215
+ }
216
+ } finally {
217
+ clearTimeout(timer);
218
+ }
219
+ };
220
+
221
+ /**
222
+ * One page of npm's search. `text` ranks results; `keywords` filter them
223
+ * (npm's `keywords:` qualifier). Answers `{ total, objects }` with raw
224
+ * entries for `searchPackages` to reduce.
225
+ */
226
+ const searchRaw = async ({ text = '', keywords = [], from = 0, size = 20 }) => {
227
+ const query = [text, ...keywords.map((keyword) => `keywords:${keyword}`)].filter(Boolean).join(' ');
228
+ const url = new URL('/-/v1/search', registryUrl);
229
+ url.searchParams.set('text', query);
230
+ url.searchParams.set('size', String(size));
231
+ url.searchParams.set('from', String(from));
232
+ const body = await getJson(url, MAX_SEARCH_BYTES);
233
+ if (!isRecord(body) || !Array.isArray(body.objects)) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer malformed');
234
+ return { total: Number.isFinite(body.total) ? body.total : undefined, objects: body.objects };
235
+ };
236
+
237
+ /** The `latest` manifest of one package. */
238
+ const latest = async (name) => {
239
+ if (!isValidNpmName(name)) throw new MarketplaceError('INVALID_MARKETPLACE_REQUEST');
240
+ const url = new URL(`/${name.replace('/', '%2F')}/latest`, registryUrl);
241
+ const body = await getJson(url, MAX_MANIFEST_BYTES, { notFound: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
242
+ if (!isRecord(body) || body.name !== name) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE', 'npm answer malformed');
243
+ return body;
244
+ };
245
+
246
+ /** Downloads in the last week, or `undefined` when npm does not say. */
247
+ const weeklyDownloads = async (name) => {
248
+ if (!isValidNpmName(name)) throw new MarketplaceError('INVALID_MARKETPLACE_REQUEST');
249
+ const url = new URL(`/downloads/point/last-week/${name}`, downloadsUrl);
250
+ const body = await getJson(url, MAX_DOWNLOADS_BYTES, { notFound: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
251
+ return isRecord(body) && Number.isFinite(body.downloads) ? body.downloads : undefined;
252
+ };
253
+
254
+ return { searchRaw, latest, weeklyDownloads };
255
+ };
@@ -0,0 +1,227 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import {
4
+ createNpmRegistry,
5
+ isValidNpmName,
6
+ safeLink,
7
+ summarizeManifest,
8
+ summarizePackage,
9
+ } from './npm-registry.js';
10
+
11
+ const jsonResponse = (body, { status = 200, contentLength } = {}) => ({
12
+ status,
13
+ ok: status >= 200 && status < 300,
14
+ headers: {
15
+ get: (name) => (String(name).toLowerCase() === 'content-length' && contentLength !== undefined
16
+ ? String(contentLength)
17
+ : null),
18
+ },
19
+ text: async () => (typeof body === 'string' ? body : JSON.stringify(body)),
20
+ });
21
+
22
+ const errorResponse = (status) => ({
23
+ status,
24
+ ok: false,
25
+ headers: { get: () => null },
26
+ text: async () => '{}',
27
+ });
28
+
29
+ const streamResponse = (chunks) => ({
30
+ status: 200,
31
+ ok: true,
32
+ headers: { get: () => null },
33
+ body: {
34
+ getReader: () => {
35
+ let index = 0;
36
+ return {
37
+ read: async () => (index < chunks.length
38
+ ? { done: false, value: chunks[index++] }
39
+ : { done: true, value: undefined }),
40
+ cancel: async () => {},
41
+ };
42
+ },
43
+ },
44
+ });
45
+
46
+ describe('isValidNpmName', () => {
47
+ it('accepts plain and scoped names', () => {
48
+ expect(isValidNpmName('pi-lens')).toBe(true);
49
+ expect(isValidNpmName('@scope/x')).toBe(true);
50
+ expect(isValidNpmName('a'.repeat(214))).toBe(true);
51
+ });
52
+
53
+ it('rejects names npm would not take for a new package', () => {
54
+ expect(isValidNpmName('Uppercase')).toBe(false);
55
+ expect(isValidNpmName('../x')).toBe(false);
56
+ expect(isValidNpmName('foo@1.0.0')).toBe(false);
57
+ expect(isValidNpmName('npm:foo')).toBe(false);
58
+ expect(isValidNpmName('')).toBe(false);
59
+ expect(isValidNpmName('a'.repeat(215))).toBe(false);
60
+ expect(isValidNpmName(undefined)).toBe(false);
61
+ });
62
+ });
63
+
64
+ describe('safeLink', () => {
65
+ it('normalizes git urls and strips .git for github', () => {
66
+ const link = safeLink('git+https://github.com/user/repo.git');
67
+ expect(link).toContain('https://github.com/user/repo');
68
+ expect(link).not.toContain('.git');
69
+ });
70
+
71
+ it('expands the github: shorthand', () => {
72
+ expect(safeLink('github:user/repo')).toContain('https://github.com/user/repo');
73
+ });
74
+
75
+ it('strips credentials', () => {
76
+ const link = safeLink('https://user:pass@example.com/x');
77
+ expect(link).toContain('https://example.com/x');
78
+ expect(link).not.toContain('user');
79
+ expect(link).not.toContain('pass');
80
+ });
81
+
82
+ it('rejects dangerous and non-http schemes', () => {
83
+ expect(safeLink('javascript:alert(1)')).toBeUndefined();
84
+ expect(safeLink('file:///etc/passwd')).toBeUndefined();
85
+ expect(safeLink('not a url')).toBeUndefined();
86
+ expect(safeLink('')).toBeUndefined();
87
+ expect(safeLink(undefined)).toBeUndefined();
88
+ });
89
+ });
90
+
91
+ describe('summarizePackage', () => {
92
+ const valid = {
93
+ name: 'pi-lens',
94
+ version: '1.2.3',
95
+ description: 'A lens for pi.',
96
+ keywords: ['pi-package', 'pichamber-plugin'],
97
+ maintainers: [{ username: 'alice' }],
98
+ publisher: { username: 'GitHub Actions' },
99
+ };
100
+
101
+ it('summarizes a well-formed entry', () => {
102
+ const summary = summarizePackage(valid, { weeklyDownloads: 42 });
103
+ expect(summary).toMatchObject({
104
+ name: 'pi-lens',
105
+ version: '1.2.3',
106
+ publisher: 'alice',
107
+ weeklyDownloads: 42,
108
+ pichamberKeyword: true,
109
+ });
110
+ expect(summary.links.npm).toContain('pi-lens');
111
+ });
112
+
113
+ it('drops entries without a usable name', () => {
114
+ expect(summarizePackage({ ...valid, name: 'Bad Name' })).toBeUndefined();
115
+ expect(summarizePackage({ ...valid, name: '' })).toBeUndefined();
116
+ expect(summarizePackage(null)).toBeUndefined();
117
+ });
118
+
119
+ it('strips control characters and caps the description', () => {
120
+ const summary = summarizePackage({ ...valid, description: 'a\x00\x01b' });
121
+ expect(summary.description).toBe('a b');
122
+ const long = summarizePackage({ ...valid, description: 'x'.repeat(500) });
123
+ expect(long.description.length).toBeLessThanOrEqual(300);
124
+ expect(long.description).toContain('…');
125
+ });
126
+
127
+ it('prefers maintainers[0] over a publisher named GitHub Actions', () => {
128
+ expect(summarizePackage(valid).publisher).toBe('alice');
129
+ expect(summarizePackage({ ...valid, maintainers: undefined }).publisher).toBeUndefined();
130
+ });
131
+
132
+ it('reads pichamberKeyword from keywords and floors downloads', () => {
133
+ expect(summarizePackage({ ...valid, keywords: ['pi-package'] }).pichamberKeyword).toBe(false);
134
+ expect(summarizePackage(valid, { weeklyDownloads: 42.9 }).weeklyDownloads).toBe(42);
135
+ expect(summarizePackage(valid).weeklyDownloads).toBeUndefined();
136
+ });
137
+ });
138
+
139
+ describe('summarizeManifest', () => {
140
+ it('reads contains from the pi block', () => {
141
+ const summary = summarizeManifest({
142
+ name: 'pi-lens',
143
+ version: '1.0.0',
144
+ keywords: ['pi-package'],
145
+ license: 'MIT',
146
+ pi: { extensions: ['./extension.js'], skills: [] },
147
+ pichamber: { apiVersion: 1 },
148
+ });
149
+ expect(summary.contains).toEqual(['extensions']);
150
+ expect(summary.pichamber).toBe(true);
151
+ expect(summary.license).toBe('MIT');
152
+ expect(summary.isPiPackage).toBe(true);
153
+ });
154
+
155
+ it('requires an object pichamber block with a numeric apiVersion', () => {
156
+ const base = { name: 'pi-lens', keywords: ['pi-package'] };
157
+ expect(summarizeManifest({ ...base, pichamber: { apiVersion: 1 } }).pichamber).toBe(true);
158
+ expect(summarizeManifest({ ...base, pichamber: { apiVersion: '1' } }).pichamber).toBe(false);
159
+ expect(summarizeManifest({ ...base, pichamber: true }).pichamber).toBe(false);
160
+ expect(summarizeManifest(base).pichamber).toBe(false);
161
+ });
162
+
163
+ it('drops licenses outside the pattern', () => {
164
+ const summary = summarizeManifest({ name: 'pi-lens', keywords: [], license: 'MIT; rm -rf' });
165
+ expect(summary.license).toBeUndefined();
166
+ });
167
+ });
168
+
169
+ describe('createNpmRegistry', () => {
170
+ it('sends search params with the keyword qualifier, size, and from', async () => {
171
+ const fetchImpl = vi.fn(async () => jsonResponse({ total: 0, objects: [] }));
172
+ const registry = createNpmRegistry({ fetchImpl });
173
+ await registry.searchRaw({ text: 'lens', keywords: ['pi-package'], from: 5, size: 20 });
174
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
175
+ const [url, init] = fetchImpl.mock.calls[0];
176
+ const parsed = new URL(String(url));
177
+ expect(parsed.pathname).toBe('/-/v1/search');
178
+ expect(parsed.searchParams.get('text')).toContain('keywords:pi-package');
179
+ expect(parsed.searchParams.get('text')).toContain('lens');
180
+ expect(parsed.searchParams.get('size')).toBe('20');
181
+ expect(parsed.searchParams.get('from')).toBe('5');
182
+ expect(init.headers['user-agent']).toBe('PiChamber');
183
+ });
184
+
185
+ it('answers 404 on latest as not found', async () => {
186
+ const registry = createNpmRegistry({ fetchImpl: async () => errorResponse(404) });
187
+ await expect(registry.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
188
+ });
189
+
190
+ it('maps network throws and bad statuses to unavailable', async () => {
191
+ const throwing = createNpmRegistry({ fetchImpl: async () => { throw new Error('down'); } });
192
+ await expect(throwing.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
193
+ const fiveHundred = createNpmRegistry({ fetchImpl: async () => errorResponse(500) });
194
+ await expect(fiveHundred.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
195
+ });
196
+
197
+ it('maps malformed JSON to unavailable', async () => {
198
+ const registry = createNpmRegistry({ fetchImpl: async () => jsonResponse('{oops') });
199
+ await expect(registry.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
200
+ });
201
+
202
+ it('rejects an oversized body by content-length', async () => {
203
+ const registry = createNpmRegistry({
204
+ fetchImpl: async () => jsonResponse({ total: 0, objects: [] }, { contentLength: 5 * 1024 * 1024 }),
205
+ });
206
+ await expect(registry.searchRaw({ text: '', keywords: [] })).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
207
+ });
208
+
209
+ it('rejects a streamed body over the cap', async () => {
210
+ const registry = createNpmRegistry({
211
+ fetchImpl: async () => streamResponse([new Uint8Array(300 * 1024), new Uint8Array(300 * 1024)]),
212
+ });
213
+ await expect(registry.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
214
+ });
215
+
216
+ it('rejects a latest body whose name differs', async () => {
217
+ const registry = createNpmRegistry({ fetchImpl: async () => jsonResponse({ name: 'other' }) });
218
+ await expect(registry.latest('pi-lens')).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
219
+ });
220
+
221
+ it('URL-encodes the slash of a scoped name', async () => {
222
+ const fetchImpl = vi.fn(async () => jsonResponse({ name: '@scope/x' }));
223
+ const registry = createNpmRegistry({ fetchImpl });
224
+ await registry.latest('@scope/x');
225
+ expect(String(fetchImpl.mock.calls[0][0])).toContain('@scope%2Fx/latest');
226
+ });
227
+ });
@@ -0,0 +1,64 @@
1
+ // Authenticated marketplace routes (the global `/api` auth gate applies).
2
+ // They read npm and the featured list only; installing goes through the
3
+ // daemon (`POST /api/pi/extensions/packages`, see ../pi/routes.js).
4
+
5
+ const STATUS_BY_CODE = {
6
+ INVALID_MARKETPLACE_REQUEST: 400,
7
+ MARKETPLACE_PACKAGE_NOT_FOUND: 404,
8
+ MARKETPLACE_UNAVAILABLE: 502,
9
+ };
10
+
11
+ const sendError = (res, error) => {
12
+ const code = Object.hasOwn(STATUS_BY_CODE, error?.code) ? error.code : 'MARKETPLACE_UNAVAILABLE';
13
+ if (code === 'MARKETPLACE_UNAVAILABLE') console.warn('[marketplace] request failed', error?.message ?? error);
14
+ res.status(STATUS_BY_CODE[code]).json({ error: { code } });
15
+ };
16
+
17
+ const badRequest = (res) => res.status(400).json({ error: { code: 'INVALID_MARKETPLACE_REQUEST' } });
18
+
19
+ const optionalString = (value, max) => value === undefined || (typeof value === 'string' && value.length <= max);
20
+
21
+ export const registerMarketplaceRoutes = (app, { service }) => {
22
+ // `?q=` search text, `?from=` npm offset, `?pichamber=1` PiChamber-ready only.
23
+ app.get('/api/pi/marketplace/search', async (req, res) => {
24
+ const { q, from, pichamber } = req.query ?? {};
25
+ if (!optionalString(q, 500) || !optionalString(from, 8) || !optionalString(pichamber, 1)) return badRequest(res);
26
+ const offset = from === undefined ? 0 : Number(from);
27
+ if (!Number.isInteger(offset) || offset < 0) return badRequest(res);
28
+ try {
29
+ res.json(await service.search({ query: q ?? '', from: offset, pichamberOnly: pichamber === '1' }));
30
+ } catch (error) {
31
+ sendError(res, error);
32
+ }
33
+ });
34
+
35
+ app.get('/api/pi/marketplace/featured', async (_req, res) => {
36
+ try {
37
+ res.json(await service.featured());
38
+ } catch (error) {
39
+ sendError(res, error);
40
+ }
41
+ });
42
+
43
+ // A query parameter, since scoped names carry a slash.
44
+ app.get('/api/pi/marketplace/package', async (req, res) => {
45
+ const { name } = req.query ?? {};
46
+ if (typeof name !== 'string' || name.length > 214) return badRequest(res);
47
+ try {
48
+ res.json(await service.packageDetail(name));
49
+ } catch (error) {
50
+ sendError(res, error);
51
+ }
52
+ });
53
+
54
+ // `?names=a,b`: latest versions, for update checks on installed packages.
55
+ app.get('/api/pi/marketplace/versions', async (req, res) => {
56
+ const { names } = req.query ?? {};
57
+ if (typeof names !== 'string' || names.length > 12_000) return badRequest(res);
58
+ try {
59
+ res.json(await service.versions(names.length === 0 ? [] : names.split(',')));
60
+ } catch (error) {
61
+ sendError(res, error);
62
+ }
63
+ });
64
+ };
@@ -0,0 +1,119 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import express from 'express';
3
+
4
+ import { registerMarketplaceRoutes } from './routes.js';
5
+
6
+ const listen = (app) => new Promise((resolve, reject) => {
7
+ const server = app.listen(0, '127.0.0.1', () => resolve(server));
8
+ server.once('error', reject);
9
+ });
10
+
11
+ describe('marketplace routes', () => {
12
+ let server;
13
+
14
+ afterEach(async () => {
15
+ await new Promise((resolve) => (server ? server.close(resolve) : resolve()));
16
+ server = undefined;
17
+ });
18
+
19
+ const setup = async (service) => {
20
+ const app = express();
21
+ app.use(express.json());
22
+ registerMarketplaceRoutes(app, { service });
23
+ server = await listen(app);
24
+ const base = `http://127.0.0.1:${server.address().port}`;
25
+ const call = async (method, path, body) => {
26
+ const response = await fetch(`${base}${path}`, {
27
+ method,
28
+ headers: body === undefined ? {} : { 'content-type': 'application/json' },
29
+ body: body === undefined ? undefined : JSON.stringify(body),
30
+ });
31
+ return { status: response.status, body: await response.json() };
32
+ };
33
+ return { call };
34
+ };
35
+
36
+ it('rejects bad query params with 400', async () => {
37
+ const service = {
38
+ search: vi.fn(async () => ({ packages: [], nextFrom: null })),
39
+ packageDetail: vi.fn(),
40
+ versions: vi.fn(async () => ({ versions: {} })),
41
+ };
42
+ const { call } = await setup(service);
43
+ expect(await call('GET', '/api/pi/marketplace/search?from=abc'))
44
+ .toEqual({ status: 400, body: { error: { code: 'INVALID_MARKETPLACE_REQUEST' } } });
45
+ expect(await call('GET', '/api/pi/marketplace/search?from=1.5'))
46
+ .toEqual({ status: 400, body: { error: { code: 'INVALID_MARKETPLACE_REQUEST' } } });
47
+ expect(await call('GET', '/api/pi/marketplace/search?pichamber=yes'))
48
+ .toEqual({ status: 400, body: { error: { code: 'INVALID_MARKETPLACE_REQUEST' } } });
49
+ expect(await call('GET', '/api/pi/marketplace/package'))
50
+ .toEqual({ status: 400, body: { error: { code: 'INVALID_MARKETPLACE_REQUEST' } } });
51
+ expect(service.search).not.toHaveBeenCalled();
52
+ expect(service.packageDetail).not.toHaveBeenCalled();
53
+ });
54
+
55
+ it('maps service errors to 404 and 502', async () => {
56
+ const notFound = { code: 'MARKETPLACE_PACKAGE_NOT_FOUND' };
57
+ const unavailable = { code: 'MARKETPLACE_UNAVAILABLE' };
58
+ const service = {
59
+ search: vi.fn(async () => { throw notFound; }),
60
+ featured: vi.fn(async () => { throw unavailable; }),
61
+ packageDetail: vi.fn(async () => { throw notFound; }),
62
+ versions: vi.fn(async () => { throw unavailable; }),
63
+ };
64
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
65
+ try {
66
+ const { call } = await setup(service);
67
+ expect(await call('GET', '/api/pi/marketplace/search')).toEqual({ status: 404, body: { error: notFound } });
68
+ expect(await call('GET', '/api/pi/marketplace/featured')).toEqual({ status: 502, body: { error: unavailable } });
69
+ expect(await call('GET', '/api/pi/marketplace/package?name=pi-lens')).toEqual({ status: 404, body: { error: notFound } });
70
+ expect(await call('GET', '/api/pi/marketplace/versions?names=a')).toEqual({ status: 502, body: { error: unavailable } });
71
+ } finally {
72
+ warn.mockRestore();
73
+ }
74
+ });
75
+
76
+ it('answers unknown errors as unavailable with 502', async () => {
77
+ const service = {
78
+ search: vi.fn(async () => { throw new Error('boom'); }),
79
+ featured: vi.fn(),
80
+ packageDetail: vi.fn(),
81
+ versions: vi.fn(),
82
+ };
83
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
84
+ try {
85
+ const { call } = await setup(service);
86
+ expect(await call('GET', '/api/pi/marketplace/search')).toEqual({
87
+ status: 502,
88
+ body: { error: { code: 'MARKETPLACE_UNAVAILABLE' } },
89
+ });
90
+ } finally {
91
+ warn.mockRestore();
92
+ }
93
+ });
94
+
95
+ it('passes pichamber=1 through as pichamberOnly', async () => {
96
+ const service = {
97
+ search: vi.fn(async () => ({ packages: [], nextFrom: null })),
98
+ featured: vi.fn(async () => ({ packages: [], updated: null, source: 'builtin' })),
99
+ packageDetail: vi.fn(async (name) => ({ name })),
100
+ versions: vi.fn(async (names) => ({ versions: Object.fromEntries(names.map((name) => [name, '1.0.0'])) })),
101
+ };
102
+ const { call } = await setup(service);
103
+ expect(await call('GET', '/api/pi/marketplace/search?q=lens&pichamber=1&from=20')).toEqual({
104
+ status: 200,
105
+ body: { packages: [], nextFrom: null },
106
+ });
107
+ expect(service.search).toHaveBeenCalledWith({ query: 'lens', from: 20, pichamberOnly: true });
108
+ expect(await call('GET', '/api/pi/marketplace/package?name=pi-lens')).toEqual({
109
+ status: 200,
110
+ body: { name: 'pi-lens' },
111
+ });
112
+ expect(service.packageDetail).toHaveBeenCalledWith('pi-lens');
113
+ expect(await call('GET', '/api/pi/marketplace/versions?names=a,b')).toEqual({
114
+ status: 200,
115
+ body: { versions: { a: '1.0.0', b: '1.0.0' } },
116
+ });
117
+ expect(service.versions).toHaveBeenCalledWith(['a', 'b']);
118
+ });
119
+ });