@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,122 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createGhCli } from './gh-cli.js';
4
+
5
+ const { parseJsonAuthStatus } = createGhCli()._internals;
6
+
7
+ describe('parseJsonAuthStatus', () => {
8
+ it('reads the current gh shape, where each host maps to a list of accounts', () => {
9
+ // `gh auth status --json hosts` on gh 2.103.
10
+ const hosts = parseJsonAuthStatus(JSON.stringify({
11
+ hosts: {
12
+ 'github.com': [
13
+ {
14
+ state: 'success',
15
+ active: true,
16
+ host: 'github.com',
17
+ login: 'octocat',
18
+ tokenSource: 'keyring',
19
+ scopes: 'gist, read:org, repo, workflow',
20
+ gitProtocol: 'https',
21
+ },
22
+ ],
23
+ },
24
+ }));
25
+
26
+ expect(hosts).toEqual([
27
+ {
28
+ host: 'github.com',
29
+ authenticated: true,
30
+ login: 'octocat',
31
+ scopes: ['gist', 'read:org', 'repo', 'workflow'],
32
+ },
33
+ ]);
34
+ });
35
+
36
+ it('keeps only the active account when a host has several', () => {
37
+ const hosts = parseJsonAuthStatus(JSON.stringify({
38
+ hosts: {
39
+ 'github.com': [
40
+ { state: 'success', active: false, host: 'github.com', login: 'work-account', scopes: 'repo' },
41
+ { state: 'success', active: true, host: 'github.com', login: 'octocat', scopes: 'gist, repo' },
42
+ ],
43
+ },
44
+ }));
45
+
46
+ expect(hosts).toEqual([
47
+ { host: 'github.com', authenticated: true, login: 'octocat', scopes: ['gist', 'repo'] },
48
+ ]);
49
+ });
50
+
51
+ it('reads a flat per-host object', () => {
52
+ const hosts = parseJsonAuthStatus(JSON.stringify({
53
+ hosts: { 'github.com': { user: 'octocat', tokenScopes: ['repo'] } },
54
+ }));
55
+
56
+ expect(hosts).toEqual([
57
+ { host: 'github.com', authenticated: true, login: 'octocat', scopes: ['repo'] },
58
+ ]);
59
+ });
60
+
61
+ it('reads a top-level array of hosts', () => {
62
+ const hosts = parseJsonAuthStatus(JSON.stringify({
63
+ hosts: [{ hostname: 'github.com', user: 'octocat' }],
64
+ }));
65
+
66
+ expect(hosts).toEqual([
67
+ { host: 'github.com', authenticated: true, login: 'octocat', scopes: [] },
68
+ ]);
69
+ });
70
+
71
+ it('reports a logged-out host as unauthenticated', () => {
72
+ const hosts = parseJsonAuthStatus(JSON.stringify({ hosts: { 'github.com': [] } }));
73
+
74
+ expect(hosts).toEqual([]);
75
+ });
76
+
77
+ it('does not report a rejected token as authenticated', () => {
78
+ // gh 2.103.3 for an invalid token: it still exits successfully in JSON
79
+ // mode and still sets `active: true`, so only `state` is trustworthy.
80
+ const hosts = parseJsonAuthStatus(JSON.stringify({
81
+ hosts: {
82
+ 'github.com': [
83
+ {
84
+ state: 'error',
85
+ error: 'non-200 OK status code: 401 Unauthorized',
86
+ active: true,
87
+ host: 'github.com',
88
+ login: '',
89
+ tokenSource: 'GH_TOKEN',
90
+ gitProtocol: 'https',
91
+ },
92
+ {
93
+ state: 'success',
94
+ active: false,
95
+ host: 'github.com',
96
+ login: 'octocat',
97
+ tokenSource: 'keyring',
98
+ scopes: 'repo',
99
+ gitProtocol: 'https',
100
+ },
101
+ ],
102
+ },
103
+ }));
104
+
105
+ // The host reports its active account only. The valid inactive one is not
106
+ // what `gh auth token` hands out, so it must not make the host read as
107
+ // signed in.
108
+ expect(hosts).toEqual([
109
+ { host: 'github.com', authenticated: false, login: null, scopes: [] },
110
+ ]);
111
+ });
112
+
113
+ it('trusts state over a login when the token was rejected', () => {
114
+ const hosts = parseJsonAuthStatus(JSON.stringify({
115
+ hosts: { 'github.com': { state: 'error', active: true, login: 'octocat' } },
116
+ }));
117
+
118
+ expect(hosts).toEqual([
119
+ { host: 'github.com', authenticated: false, login: 'octocat', scopes: [] },
120
+ ]);
121
+ });
122
+ });
@@ -0,0 +1,95 @@
1
+ # Marketplace (server)
2
+
3
+ ## Purpose
4
+
5
+ Lets Settings find and install Pi packages without a registry of our own.
6
+ Pi packages are npm packages with the `pi-package` keyword, the same list
7
+ pi.dev's package gallery shows. This module reads npm's public search and
8
+ package endpoints, adds a curated featured list from the PiChamber repo, and
9
+ answers the UI through `/api/pi/marketplace/*`. Installing is not here: it
10
+ is a Pi package-manager write owned by the session daemon
11
+ (`../pi/session-daemon/extension-config.js`, `POST /api/pi/extensions/packages`).
12
+
13
+ ## Entrypoints
14
+
15
+ - `npm-registry.js` is the only code that talks to npm.
16
+ `createNpmRegistry({ fetchImpl, registryUrl, downloadsUrl, timeoutMs })`
17
+ returns `searchRaw`, `latest(name)` and `weeklyDownloads(name)`. Responses
18
+ are size-capped (search 2 MB, manifest 512 KB) and time out after 8 s.
19
+ Failures are `MarketplaceError` with code `MARKETPLACE_UNAVAILABLE` or
20
+ `MARKETPLACE_PACKAGE_NOT_FOUND`. `summarizePackage` and `summarizeManifest`
21
+ reduce npm's answers to the fields the UI shows. Links pass `safeLink`
22
+ (http/https only). Requests carry the generic user agent `PiChamber` and
23
+ nothing about the user.
24
+ - `featured.js` owns the featured list. The built-in copy is
25
+ `packages/web/plugins/featured.json`; the remote copy is the same file on
26
+ the repo's `main` branch (`DEFAULT_FEATURED_URL`), refreshed at most every
27
+ 6 hours (10 minutes after a failure), capped at 64 KB, and cached at
28
+ `<dataDir>/pi/featured.json` as `{ fetchedAt, list }`. `get()` never waits
29
+ on the network: it answers with the newer of the cached and built-in lists
30
+ (by `updated`; on the same date the cached copy wins) and starts a refresh
31
+ in the background when one is due.
32
+ - `service.js` combines them with in-memory TTL caches (search 5 minutes,
33
+ package and downloads 10 minutes, 300 entries, shared in-flight requests,
34
+ failures not kept).
35
+ - `routes.js` registers the routes below. `server/index.js` builds the
36
+ registry, featured source and service.
37
+
38
+ ## List format
39
+
40
+ `featured.json`: `{ version: 1, updated: 'YYYY-MM-DD', featured: [{ name,
41
+ note? }], hidden: [name] }`. At most 24 featured entries with notes of at
42
+ most 120 characters, and 500 hidden names. Invalid names are dropped.
43
+ `hidden` is moderation: a hidden package is left out of search, featured and
44
+ package answers. Editing the file on `main` reaches every server within 6
45
+ hours; a release carries the file as the fallback.
46
+
47
+ ## Routes
48
+
49
+ - `GET /api/pi/marketplace/search?q=&from=&pichamber=1` →
50
+ `{ packages, total?, nextFrom }`. Pages of 20. `total` only without a
51
+ query (npm's count for the keyword).
52
+ - `GET /api/pi/marketplace/featured` → `{ packages, updated, source }`, in
53
+ the list's order. An entry npm cannot answer for comes back as
54
+ `{ name, note, unavailable: true }` rather than failing the list.
55
+ - `GET /api/pi/marketplace/package?name=` → the package summary plus
56
+ `license?`, `contains` (from its `pi` block), `pichamber` (its manifest
57
+ declares a `pichamber` block with a numeric `apiVersion`) and `isPiPackage`.
58
+ - `GET /api/pi/marketplace/versions?names=a,b` → `{ versions: { name:
59
+ version } }` for at most 50 names. Names npm cannot answer for are left out.
60
+ - Errors: 400 `INVALID_MARKETPLACE_REQUEST`, 404
61
+ `MARKETPLACE_PACKAGE_NOT_FOUND`, 502 `MARKETPLACE_UNAVAILABLE`. A failed
62
+ npm call is an error, never an empty list.
63
+
64
+ ## Invariants
65
+
66
+ - npm search text only ranks; it does not filter. A query for nonsense
67
+ returns popular packages that match nothing. The service keeps only hits
68
+ where a query word appears in the name, description or keywords, and stops
69
+ paging at the first page that has an unrelated hit, so the tail of
70
+ unrelated packages never shows.
71
+ - npm treats two keywords loosely, so the service asks for one
72
+ (`pichamber-plugin` with `pichamber=1`, otherwise `pi-package`) and checks
73
+ both itself.
74
+ - The `pichamber-plugin` keyword is a claim by the author: it marks a list
75
+ row. The package page reads the manifest and calls it a PiChamber plugin only
76
+ when the `pichamber` block is really there. A third-party package with
77
+ that block installs and runs as a plain Pi package; PiChamber does not load
78
+ its UI half.
79
+ - The bundled plugins (`pluginService.bundledPackageNames()`) and hidden
80
+ names never appear in an answer. The UI suggests the bundled plugin
81
+ instead when a search matches it.
82
+ - No README, images or other package content are fetched: only npm's
83
+ metadata, which is shown as text.
84
+
85
+ ## Configuration
86
+
87
+ - `PICHAMBER_NPM_REGISTRY_URL` and `PICHAMBER_NPM_DOWNLOADS_URL` point at
88
+ another registry (tests, mirrors).
89
+ - `PICHAMBER_FEATURED_URL` replaces the remote featured list; `off` turns the
90
+ refresh off so only the built-in copy is used.
91
+
92
+ ## Tests
93
+
94
+ `*.test.js` beside each file (vitest), with a fake `fetchImpl`; nothing
95
+ reaches the network.
@@ -0,0 +1,176 @@
1
+ // The marketplace's curated list: packages shown first, and packages never
2
+ // shown. It ships with the app (`packages/web/plugins/featured.json`) and is
3
+ // refreshed from the PiChamber repository, so picks change without a release.
4
+ // The last good remote copy is kept in the data folder. See DOCUMENTATION.md.
5
+
6
+ import { randomUUID } from 'node:crypto';
7
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
8
+ import { dirname, join } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ import { isValidNpmName } from './npm-registry.js';
12
+
13
+ const BUILTIN_FEATURED_PATH = fileURLToPath(new URL('../../../plugins/featured.json', import.meta.url));
14
+ export const DEFAULT_FEATURED_URL = 'https://raw.githubusercontent.com/RyderAsKing/PiChamber/main/packages/web/plugins/featured.json';
15
+
16
+ const REFRESH_MS = 6 * 60 * 60 * 1000;
17
+ /** After a failed refresh, wait this long before trying again. */
18
+ const RETRY_MS = 10 * 60 * 1000;
19
+ const TIMEOUT_MS = 5_000;
20
+ const MAX_BYTES = 64 * 1024;
21
+ const MAX_FEATURED = 24;
22
+ const MAX_HIDDEN = 500;
23
+ const MAX_NOTE_LENGTH = 120;
24
+ const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
25
+
26
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
27
+
28
+ /**
29
+ * Parse a featured file. Returns `undefined` when the file is unusable as a
30
+ * whole (wrong version, bad date, not an object); a bad entry is skipped.
31
+ * `{ version: 1, updated: 'YYYY-MM-DD', featured: [{ name, note? }], hidden: [name] }`.
32
+ */
33
+ export const parseFeaturedList = (value) => {
34
+ if (!isRecord(value) || value.version !== 1) return undefined;
35
+ if (typeof value.updated !== 'string' || !DATE_PATTERN.test(value.updated) || !Number.isFinite(Date.parse(value.updated))) {
36
+ return undefined;
37
+ }
38
+ const hidden = [];
39
+ for (const name of Array.isArray(value.hidden) ? value.hidden : []) {
40
+ if (isValidNpmName(name) && !hidden.includes(name)) hidden.push(name);
41
+ if (hidden.length === MAX_HIDDEN) break;
42
+ }
43
+ const featured = [];
44
+ for (const entry of Array.isArray(value.featured) ? value.featured : []) {
45
+ if (!isRecord(entry) || !isValidNpmName(entry.name) || hidden.includes(entry.name)) continue;
46
+ if (featured.some((item) => item.name === entry.name)) continue;
47
+ // eslint-disable-next-line no-control-regex
48
+ const note = typeof entry.note === 'string' ? entry.note.replace(/[\u0000-\u001f\u007f]+/g, ' ').trim() : '';
49
+ featured.push({ name: entry.name, ...(note.length > 0 && note.length <= MAX_NOTE_LENGTH ? { note } : {}) });
50
+ if (featured.length === MAX_FEATURED) break;
51
+ }
52
+ return { updated: value.updated, featured, hidden };
53
+ };
54
+
55
+ /** The newer of two lists by their `updated` date; `a` wins a tie. */
56
+ const newer = (a, b) => {
57
+ if (!a) return b;
58
+ if (!b) return a;
59
+ return b.updated > a.updated ? b : a;
60
+ };
61
+
62
+ /**
63
+ * `remoteUrl`: `null` turns refreshing off. Reads never wait for the network:
64
+ * they answer from the newest of the built-in and cached lists and start a
65
+ * refresh in the background when the cache is old.
66
+ */
67
+ export const createFeaturedSource = ({
68
+ builtinPath = BUILTIN_FEATURED_PATH,
69
+ cachePath,
70
+ remoteUrl = DEFAULT_FEATURED_URL,
71
+ fetchImpl = globalThis.fetch,
72
+ now = () => Date.now(),
73
+ logger = console,
74
+ } = {}) => {
75
+ let builtin;
76
+ let cached;
77
+ let cacheLoaded = false;
78
+ let fetchedAt = 0;
79
+ let lastAttempt = 0;
80
+ let refreshing = null;
81
+
82
+ const loadBuiltin = async () => {
83
+ if (builtin !== undefined) return builtin;
84
+ try {
85
+ builtin = parseFeaturedList(JSON.parse(await readFile(builtinPath, 'utf8'))) ?? null;
86
+ } catch {
87
+ builtin = null;
88
+ }
89
+ if (!builtin) logger.warn('[marketplace] the built-in featured list is unreadable');
90
+ return builtin;
91
+ };
92
+
93
+ const loadCache = async () => {
94
+ if (cacheLoaded || !cachePath) return;
95
+ cacheLoaded = true;
96
+ try {
97
+ const stored = JSON.parse(await readFile(cachePath, 'utf8'));
98
+ const list = parseFeaturedList(stored?.list);
99
+ if (list && Number.isFinite(stored.fetchedAt)) {
100
+ cached = list;
101
+ fetchedAt = stored.fetchedAt;
102
+ }
103
+ } catch {
104
+ // Missing or unreadable: the built-in list answers until a refresh lands.
105
+ }
106
+ };
107
+
108
+ const writeCache = async (list, at) => {
109
+ if (!cachePath) return;
110
+ const temporary = join(dirname(cachePath), `.featured.${randomUUID()}.tmp`);
111
+ try {
112
+ await mkdir(dirname(cachePath), { recursive: true, mode: 0o700 });
113
+ await writeFile(temporary, JSON.stringify({ fetchedAt: at, list: { version: 1, ...list } }), { mode: 0o600 });
114
+ await rename(temporary, cachePath);
115
+ } catch (error) {
116
+ await rm(temporary, { force: true }).catch(() => {});
117
+ logger.warn('[marketplace] could not keep the featured list', error?.code ?? error?.message ?? error);
118
+ }
119
+ };
120
+
121
+ const fetchRemote = async () => {
122
+ const controller = new AbortController();
123
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
124
+ timer.unref?.();
125
+ try {
126
+ const response = await fetchImpl(remoteUrl, {
127
+ headers: { accept: 'application/json', 'user-agent': 'PiChamber' },
128
+ signal: controller.signal,
129
+ });
130
+ if (!response.ok) throw new Error(`status ${response.status}`);
131
+ const text = await response.text();
132
+ if (text.length > MAX_BYTES) throw new Error('too large');
133
+ const list = parseFeaturedList(JSON.parse(text));
134
+ if (!list) throw new Error('malformed');
135
+ return list;
136
+ } finally {
137
+ clearTimeout(timer);
138
+ }
139
+ };
140
+
141
+ /** Fetch the remote list once; concurrent callers share the attempt. */
142
+ const refresh = () => {
143
+ if (!remoteUrl) return Promise.resolve(false);
144
+ if (refreshing) return refreshing;
145
+ lastAttempt = now();
146
+ refreshing = (async () => {
147
+ try {
148
+ const list = await fetchRemote();
149
+ const at = now();
150
+ cached = list;
151
+ fetchedAt = at;
152
+ await writeCache(list, at);
153
+ return true;
154
+ } catch (error) {
155
+ logger.warn('[marketplace] could not refresh the featured list', error?.message ?? error);
156
+ return false;
157
+ } finally {
158
+ refreshing = null;
159
+ }
160
+ })();
161
+ return refreshing;
162
+ };
163
+
164
+ /** `{ updated, featured, hidden, source: 'remote' | 'builtin' }`, never throws. */
165
+ const get = async () => {
166
+ const [base] = await Promise.all([loadBuiltin(), loadCache()]);
167
+ const time = now();
168
+ if (remoteUrl && time - fetchedAt > REFRESH_MS && time - lastAttempt > RETRY_MS) void refresh();
169
+ // On the same date the fetched copy wins: it is what the repository says now.
170
+ const list = newer(cached, base);
171
+ if (!list) return { updated: null, featured: [], hidden: [], source: 'builtin' };
172
+ return { ...list, source: list === base ? 'builtin' : 'remote' };
173
+ };
174
+
175
+ return { get, refresh };
176
+ };
@@ -0,0 +1,207 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { mkdtemp, readFile, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+
6
+ import { createFeaturedSource, parseFeaturedList } from './featured.js';
7
+
8
+ const tempDir = () => mkdtemp(join(tmpdir(), 'pichamber-featured-'));
9
+
10
+ const writeBuiltin = async (dir, list) => {
11
+ const path = join(dir, 'featured.json');
12
+ await writeFile(path, JSON.stringify(list));
13
+ return path;
14
+ };
15
+
16
+ const builtinList = (overrides = {}) => ({
17
+ version: 1,
18
+ updated: '2026-01-01',
19
+ featured: [{ name: 'pi-lens', note: 'Local pick' }],
20
+ hidden: [],
21
+ ...overrides,
22
+ });
23
+
24
+ const remoteResponse = (list) => ({
25
+ ok: true,
26
+ status: 200,
27
+ text: async () => JSON.stringify(list),
28
+ });
29
+
30
+ describe('parseFeaturedList', () => {
31
+ it('requires version 1 and a parseable date', () => {
32
+ expect(parseFeaturedList({ version: 2, updated: '2026-01-01', featured: [] })).toBeUndefined();
33
+ expect(parseFeaturedList({ version: 1, updated: 'not-a-date', featured: [] })).toBeUndefined();
34
+ expect(parseFeaturedList({ version: 1, updated: '2026/01/01', featured: [] })).toBeUndefined();
35
+ expect(parseFeaturedList(null)).toBeUndefined();
36
+ expect(parseFeaturedList(builtinList())).toMatchObject({ updated: '2026-01-01' });
37
+ });
38
+
39
+ it('skips bad names and drops duplicates', () => {
40
+ const list = parseFeaturedList(builtinList({
41
+ featured: [{ name: 'pi-lens' }, { name: 'Bad Name' }, { name: 'pi-lens' }, { name: '../x' }],
42
+ }));
43
+ expect(list.featured).toEqual([{ name: 'pi-lens' }]);
44
+ });
45
+
46
+ it('removes hidden names from featured', () => {
47
+ const list = parseFeaturedList(builtinList({
48
+ featured: [{ name: 'pi-lens' }, { name: 'evil-pkg' }],
49
+ hidden: ['evil-pkg'],
50
+ }));
51
+ expect(list.featured).toEqual([{ name: 'pi-lens' }]);
52
+ expect(list.hidden).toEqual(['evil-pkg']);
53
+ });
54
+
55
+ it('caps notes at 120 chars', () => {
56
+ const list = parseFeaturedList(builtinList({
57
+ featured: [{ name: 'pi-lens', note: 'x'.repeat(121) }, { name: 'pi-other', note: 'kept' }],
58
+ }));
59
+ expect(list.featured).toEqual([{ name: 'pi-lens' }, { name: 'pi-other', note: 'kept' }]);
60
+ });
61
+
62
+ it('caps featured at 24 entries', () => {
63
+ const featured = Array.from({ length: 30 }, (_, index) => ({ name: `pi-pkg-${index}` }));
64
+ const list = parseFeaturedList(builtinList({ featured }));
65
+ expect(list.featured).toHaveLength(24);
66
+ });
67
+ });
68
+
69
+ describe('createFeaturedSource', () => {
70
+ it('answers built-in when there is no cache and does not await the network', async () => {
71
+ const dir = await tempDir();
72
+ const builtinPath = await writeBuiltin(dir, builtinList());
73
+ const fetchImpl = vi.fn(() => new Promise(() => {}));
74
+ const source = createFeaturedSource({
75
+ builtinPath,
76
+ cachePath: join(dir, 'cache', 'featured.json'),
77
+ remoteUrl: 'https://example.com/featured.json',
78
+ fetchImpl,
79
+ logger: { warn: vi.fn() },
80
+ });
81
+ const result = await source.get();
82
+ expect(result).toMatchObject({ updated: '2026-01-01', source: 'builtin' });
83
+ expect(result.featured).toEqual([{ name: 'pi-lens', note: 'Local pick' }]);
84
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
85
+ });
86
+
87
+ it('writes the cache on refresh and later returns the remote list', async () => {
88
+ const dir = await tempDir();
89
+ const builtinPath = await writeBuiltin(dir, builtinList());
90
+ const cachePath = join(dir, 'cache', 'featured.json');
91
+ const remote = builtinList({ updated: '2026-02-01', featured: [{ name: 'pi-new', note: 'Fresh' }] });
92
+ const fetchImpl = vi.fn(async () => remoteResponse(remote));
93
+ let time = 1_000_000;
94
+ const source = createFeaturedSource({
95
+ builtinPath, cachePath, remoteUrl: 'https://example.com/featured.json', fetchImpl, now: () => time, logger: { warn: vi.fn() },
96
+ });
97
+ expect(await source.refresh()).toBe(true);
98
+ const stored = JSON.parse(await readFile(cachePath, 'utf8'));
99
+ expect(stored.list.featured).toEqual([{ name: 'pi-new', note: 'Fresh' }]);
100
+ time += 1000;
101
+ const result = await source.get();
102
+ expect(result).toMatchObject({ updated: '2026-02-01', source: 'remote' });
103
+ expect(result.featured).toEqual([{ name: 'pi-new', note: 'Fresh' }]);
104
+ });
105
+
106
+ it('prefers the remote copy on the same date but keeps a newer built-in', async () => {
107
+ const dir = await tempDir();
108
+ const sameDayRemote = builtinList({ updated: '2026-01-01', featured: [{ name: 'pi-remote' }] });
109
+ const source = createFeaturedSource({
110
+ builtinPath: await writeBuiltin(dir, builtinList()),
111
+ cachePath: join(dir, 'cache.json'),
112
+ remoteUrl: 'https://example.com/featured.json',
113
+ fetchImpl: async () => remoteResponse(sameDayRemote),
114
+ logger: { warn: vi.fn() },
115
+ });
116
+ expect(await source.refresh()).toBe(true);
117
+ expect((await source.get()).featured).toEqual([{ name: 'pi-remote' }]);
118
+
119
+ const dir2 = await tempDir();
120
+ const olderRemote = builtinList({ updated: '2025-01-01', featured: [{ name: 'pi-old' }] });
121
+ const newer = createFeaturedSource({
122
+ builtinPath: await writeBuiltin(dir2, builtinList({ updated: '2026-03-01' })),
123
+ cachePath: join(dir2, 'cache.json'),
124
+ remoteUrl: 'https://example.com/featured.json',
125
+ fetchImpl: async () => remoteResponse(olderRemote),
126
+ logger: { warn: vi.fn() },
127
+ });
128
+ expect(await newer.refresh()).toBe(true);
129
+ const result = await newer.get();
130
+ expect(result).toMatchObject({ updated: '2026-03-01', source: 'builtin' });
131
+ });
132
+
133
+ it('logs a failed refresh and does not retry within 10 minutes', async () => {
134
+ const dir = await tempDir();
135
+ const logger = { warn: vi.fn() };
136
+ const fetchImpl = vi.fn(async () => { throw new Error('down'); });
137
+ let time = 100_000_000_000;
138
+ const source = createFeaturedSource({
139
+ builtinPath: await writeBuiltin(dir, builtinList()),
140
+ cachePath: join(dir, 'cache.json'),
141
+ remoteUrl: 'https://example.com/featured.json',
142
+ fetchImpl,
143
+ now: () => time,
144
+ logger,
145
+ });
146
+ expect(await source.refresh()).toBe(false);
147
+ expect(logger.warn).toHaveBeenCalled();
148
+ const calls = fetchImpl.mock.calls.length;
149
+ const result = await source.get();
150
+ expect(result.source).toBe('builtin');
151
+ expect(fetchImpl.mock.calls.length).toBe(calls);
152
+ time += 11 * 60 * 1000;
153
+ await source.get();
154
+ expect(fetchImpl.mock.calls.length).toBe(calls + 1);
155
+ });
156
+
157
+ it('never fetches when remoteUrl is null', async () => {
158
+ const dir = await tempDir();
159
+ const fetchImpl = vi.fn(async () => remoteResponse(builtinList()));
160
+ const source = createFeaturedSource({
161
+ builtinPath: await writeBuiltin(dir, builtinList()),
162
+ cachePath: join(dir, 'cache.json'),
163
+ remoteUrl: null,
164
+ fetchImpl,
165
+ logger: { warn: vi.fn() },
166
+ });
167
+ expect(await source.refresh()).toBe(false);
168
+ expect((await source.get()).source).toBe('builtin');
169
+ expect(fetchImpl).not.toHaveBeenCalled();
170
+ });
171
+
172
+ it('ignores a malformed cache file', async () => {
173
+ const dir = await tempDir();
174
+ const cachePath = join(dir, 'cache.json');
175
+ await writeFile(cachePath, '{broken');
176
+ const source = createFeaturedSource({
177
+ builtinPath: await writeBuiltin(dir, builtinList()),
178
+ cachePath,
179
+ remoteUrl: null,
180
+ logger: { warn: vi.fn() },
181
+ });
182
+ const result = await source.get();
183
+ expect(result).toMatchObject({ updated: '2026-01-01', source: 'builtin' });
184
+ });
185
+
186
+ it('shares one fetch across concurrent refresh calls', async () => {
187
+ const dir = await tempDir();
188
+ const remote = builtinList({ updated: '2026-02-01' });
189
+ let release;
190
+ const gate = new Promise((resolve) => { release = resolve; });
191
+ const fetchImpl = vi.fn(() => gate.then(() => remoteResponse(remote)));
192
+ const source = createFeaturedSource({
193
+ builtinPath: await writeBuiltin(dir, builtinList()),
194
+ cachePath: join(dir, 'cache.json'),
195
+ remoteUrl: 'https://example.com/featured.json',
196
+ fetchImpl,
197
+ logger: { warn: vi.fn() },
198
+ });
199
+ const first = source.refresh();
200
+ const second = source.refresh();
201
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
202
+ release();
203
+ expect(await first).toBe(true);
204
+ expect(await second).toBe(true);
205
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
206
+ });
207
+ });