@pi-chamber/web 1.0.3 → 1.0.4-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/dist/assets/DiagramView-DfZMQkXY.js +1 -0
  2. package/dist/assets/{DiffView-D19Jps0i.js → DiffView-BjWUdbL5.js} +6 -6
  3. package/dist/assets/FileSaveConflictDialog-u5L4k_5k.js +3 -0
  4. package/dist/assets/FilesView-qP1ypN9J.js +6 -0
  5. package/dist/assets/GitHubDetailScaffold-zCKCy5OJ.js +11 -0
  6. package/dist/assets/GitHubLinkPicker-CwxKY3lN.js +1 -0
  7. package/dist/assets/GitHubListPrimitives-Ck3zllel.js +1 -0
  8. package/dist/assets/GitView-y2k2i4gR.js +9 -0
  9. package/dist/assets/IssuesSurface-HWgR87N3.js +7 -0
  10. package/dist/assets/JsonTreeView-DSuC4naV.js +1 -0
  11. package/dist/assets/{MarkdownRendererImpl-DV5Xkj8N.js → MarkdownRendererImpl-CT5ln9em.js} +5 -5
  12. package/dist/assets/PatchDiff-DArTeWeK.js +1 -0
  13. package/dist/assets/PierreDiffViewer-DQKujzLb.js +134 -0
  14. package/dist/assets/PullRequestsSurface-Cfb1wSvC.js +2 -0
  15. package/dist/assets/SessionSwitcherContent-DEGJyZBl.js +1 -0
  16. package/dist/assets/SessionSwitcherDropdown-cC9wVBH7.js +2 -0
  17. package/dist/assets/SessionUnreadDot-CELKNVIM.js +1 -0
  18. package/dist/assets/SettingsView-CZvRRgJe.js +6 -0
  19. package/dist/assets/SettingsWindow-CZM1dmVb.js +1 -0
  20. package/dist/assets/ToolOutputDialog-DClOSbJc.js +8 -0
  21. package/dist/assets/ToolPartDiffPreview-BaFiGUDE.js +1 -0
  22. package/dist/assets/{VirtualizedFileDiff-CJondRlh.js → VirtualizedFileDiff-D6KbvKc6.js} +3 -3
  23. package/dist/assets/Virtualizer-wpC51ZBQ.js +1 -0
  24. package/dist/assets/collapsible-DhV9d4dT.js +1 -0
  25. package/dist/assets/computeVirtualFileMetrics-CeMpF2xC.js +3 -0
  26. package/dist/assets/{contextFileOpenGuard-CsZL8yie.js → contextFileOpenGuard-Ck5u_kAP.js} +1 -1
  27. package/dist/assets/gitStatusPredicates-DEBSqUNE.js +1 -0
  28. package/dist/assets/githubLink-DT7i2NlH.js +10 -0
  29. package/dist/assets/index-6IO1AcJI.js +10 -0
  30. package/dist/assets/index-BAmzAlNx.css +1 -0
  31. package/dist/assets/index-eDf4LKLY.js +1 -0
  32. package/dist/assets/main-BczEScAA.js +2 -0
  33. package/dist/assets/main-CHLNMYeJ.js +136 -0
  34. package/dist/assets/markdownCore-C4Gk5Zht.js +2 -0
  35. package/dist/assets/miniChat-Do3hE87Z.js +2 -0
  36. package/dist/assets/mobile-CTnihwfa.js +2 -0
  37. package/dist/assets/permissionStore-B9Hkrqny.js +1 -0
  38. package/dist/assets/pi-session-focus-preference-LDVCJ_YR.js +10 -0
  39. package/dist/assets/renderDiffWithHighlighter-CDsgOnkH.js +1 -0
  40. package/dist/assets/renderElectronMiniChatApp-DSa3gYqR.js +2 -0
  41. package/dist/assets/renderFileWithHighlighter-TpKRyfCY.js +1 -0
  42. package/dist/assets/renderMobileApp-CPE-3uMl.js +11 -0
  43. package/dist/assets/runtimeEndpointReset-CzJfovWI.js +62 -0
  44. package/dist/assets/{runtimeSurface-BdndJV2m.js → runtimeSurface-DW_Ia4q3.js} +1 -1
  45. package/dist/assets/shell-CjFT_Tl9.js +1 -0
  46. package/dist/assets/sprite-HGQGInUp.js +6510 -0
  47. package/dist/assets/useAppFontEffects-CG3_yteE.js +212 -0
  48. package/dist/assets/{useFilesViewSearch-DJ3psTKU.js → useFilesViewSearch-C_LzYIgD.js} +1 -1
  49. package/dist/assets/useGitHubRemoteSearch-DsxWOzKZ.js +1 -0
  50. package/dist/assets/useSwitcherItems-BmoCnS9W.js +1 -0
  51. package/dist/assets/vendor-base-ui-DIkTOIJS.js +1 -0
  52. package/dist/assets/{vendor-beautiful-mermaid-D3YCkKz7.js → vendor-beautiful-mermaid-DApbjBp2.js} +1 -1
  53. package/dist/assets/vendor-boot-DyL2td56.js +69 -0
  54. package/dist/assets/vendor-codemirror-autocomplete-DsFn4GLp.js +1 -0
  55. package/dist/assets/vendor-codemirror-lang-angular-B_NMmBbS.js +1 -0
  56. package/dist/assets/vendor-codemirror-lang-cpp-GOE7Gjd0.js +1 -0
  57. package/dist/assets/vendor-codemirror-lang-css-Dwf2XpnZ.js +1 -0
  58. package/dist/assets/vendor-codemirror-lang-go-C2KHbcll.js +7 -0
  59. package/dist/assets/vendor-codemirror-lang-html-DcKqyeGk.js +1 -0
  60. package/dist/assets/vendor-codemirror-lang-java-6eGbyB2k.js +1 -0
  61. package/dist/assets/vendor-codemirror-lang-javascript-DpTUrvx8.js +13 -0
  62. package/dist/assets/vendor-codemirror-lang-jinja-xSUJjXhr.js +1 -0
  63. package/dist/assets/vendor-codemirror-lang-json-CLGxdOCz.js +1 -0
  64. package/dist/assets/vendor-codemirror-lang-less-6nXi1rS9.js +1 -0
  65. package/dist/assets/vendor-codemirror-lang-liquid-B9hmb9P8.js +1 -0
  66. package/dist/assets/vendor-codemirror-lang-markdown-DmFP9s6x.js +1 -0
  67. package/dist/assets/vendor-codemirror-lang-php-DC6To8iX.js +1 -0
  68. package/dist/assets/vendor-codemirror-lang-python-yuxIkjit.js +3 -0
  69. package/dist/assets/vendor-codemirror-lang-rust-di1Sjz-0.js +1 -0
  70. package/dist/assets/vendor-codemirror-lang-sass-BWpV9NPV.js +1 -0
  71. package/dist/assets/{vendor-codemirror-lang-sql-HpQWHJjv.js → vendor-codemirror-lang-sql-C_RazIaB.js} +2 -2
  72. package/dist/assets/vendor-codemirror-lang-vue-BYL0r7KR.js +1 -0
  73. package/dist/assets/vendor-codemirror-lang-wast-BiVarhcz.js +1 -0
  74. package/dist/assets/vendor-codemirror-lang-xml-Cn1lY1ts.js +1 -0
  75. package/dist/assets/vendor-codemirror-lang-yaml-BZ6mZw9L.js +1 -0
  76. package/dist/assets/vendor-codemirror-language-data-DglcKYWT.js +2 -0
  77. package/dist/assets/vendor-codemirror-search-DaE6R5gH.js +2 -0
  78. package/dist/assets/{vendor-elkjs-mzfkf0ML.js → vendor-elkjs-D27273Ms.js} +1 -1
  79. package/dist/assets/{vendor-heic2any-BHsbokcA.js → vendor-heic2any-pq-UTQQR.js} +1 -1
  80. package/dist/assets/vendor-lezer-cpp-Dt99h3WT.js +1 -0
  81. package/dist/assets/vendor-lezer-css-DNU_fzPI.js +1 -0
  82. package/dist/assets/vendor-lezer-go-BEFtcNyS.js +1 -0
  83. package/dist/assets/vendor-lezer-html-DDGRhRUz.js +1 -0
  84. package/dist/assets/vendor-lezer-java-DmfZtW09.js +1 -0
  85. package/dist/assets/vendor-lezer-javascript-oje4tdp_.js +1 -0
  86. package/dist/assets/vendor-lezer-json-BRXb_bDX.js +1 -0
  87. package/dist/assets/vendor-lezer-lr-BU2qmu_5.js +1 -0
  88. package/dist/assets/{vendor-lezer-markdown-C6g-d6P3.js → vendor-lezer-markdown-CicYv7V9.js} +4 -4
  89. package/dist/assets/vendor-lezer-php-COORrTpE.js +1 -0
  90. package/dist/assets/vendor-lezer-python-Cuvm9X9Y.js +1 -0
  91. package/dist/assets/vendor-lezer-rust-C_zOfHbX.js +1 -0
  92. package/dist/assets/vendor-lezer-sass-DWP4w7O1.js +1 -0
  93. package/dist/assets/vendor-lezer-xml-Br6nOYeG.js +1 -0
  94. package/dist/assets/vendor-lezer-yaml-CYQmm6Sb.js +1 -0
  95. package/dist/assets/{vendor-lru_map-Cy8fTs3_.js → vendor-lru_map-DOPmc7GU.js} +1 -1
  96. package/dist/assets/{vendor-qrcode-B0KNSajT.js → vendor-qrcode-Dv4uniC1.js} +1 -1
  97. package/dist/assets/vendor-react-DASdDPIk.js +1 -0
  98. package/dist/assets/{vendor-react-drawio-BYDptOsj.js → vendor-react-drawio-Duu5LgQA.js} +1 -1
  99. package/dist/assets/{vendor-replit-codemirror-vim-DaSwPsXt.js → vendor-replit-codemirror-vim-CZy3BUVv.js} +15 -15
  100. package/dist/assets/vendor-zustand-CUi8eEds.js +6 -0
  101. package/dist/assets/{web-components-CCKlju0Z.js → web-components-CH3-XV-n.js} +4 -4
  102. package/dist/index.html +7 -9
  103. package/dist/mini-chat.html +6 -8
  104. package/dist/mobile.html +6 -8
  105. package/package.json +1 -1
  106. package/server/index.js +3 -1
  107. package/server/lib/fs/DOCUMENTATION.md +1 -1
  108. package/server/lib/fs/routes.js +1 -50
  109. package/server/lib/git/DOCUMENTATION.md +18 -11
  110. package/server/lib/git/index.js +8 -3
  111. package/server/lib/git/routes.js +0 -129
  112. package/server/lib/git/service.js +40 -152
  113. package/server/lib/git/service.test.js +42 -18
  114. package/server/lib/github/DOCUMENTATION.md +271 -0
  115. package/server/lib/github/cache.js +164 -0
  116. package/server/lib/github/checks.js +230 -0
  117. package/server/lib/github/client.js +305 -0
  118. package/server/lib/github/context.js +177 -0
  119. package/server/lib/github/contracts.test.js +235 -0
  120. package/server/lib/github/correctness.test.js +356 -0
  121. package/server/lib/github/credential.js +46 -0
  122. package/server/lib/github/errors.js +151 -0
  123. package/server/lib/github/gh-cli.js +336 -0
  124. package/server/lib/github/index.js +27 -0
  125. package/server/lib/github/issues.js +495 -0
  126. package/server/lib/github/pulls.js +699 -0
  127. package/server/lib/github/repo-scope.js +688 -0
  128. package/server/lib/github/routes.js +599 -0
  129. package/server/lib/github/security.test.js +275 -0
  130. package/server/lib/github/templates.js +153 -0
  131. package/server/lib/package-manager-detect-child.js +12 -0
  132. package/server/lib/package-manager.js +366 -92
  133. package/server/lib/package-manager.test.js +109 -0
  134. package/server/lib/pi/routes-extension-events.test.js +268 -4
  135. package/server/lib/pi/routes.js +109 -25
  136. package/server/lib/pi/routes.test.js +118 -0
  137. package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -3
  138. package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +222 -0
  139. package/server/lib/pi/session-daemon/extension-bridge.js +415 -42
  140. package/server/lib/pi/session-daemon/extension-name.js +87 -0
  141. package/server/lib/pi/session-daemon/extension-name.test.js +143 -0
  142. package/server/lib/pi/session-daemon/extension-theme.js +142 -0
  143. package/server/lib/pi/session-daemon/extension-theme.test.js +117 -0
  144. package/server/lib/pi/session-daemon/extension-tool-render.js +365 -0
  145. package/server/lib/pi/session-daemon/extension-tool-render.test.js +607 -0
  146. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +322 -2
  147. package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +244 -0
  148. package/server/lib/pi/session-daemon/session-daemon.js +204 -33
  149. package/server/lib/pi/session-daemon/session-daemon.test.js +218 -0
  150. package/server/lib/pi/ui-settings-store.js +1 -1
  151. package/server/lib/static-cache-control.js +18 -0
  152. package/server/lib/static-cache-control.test.js +25 -0
  153. package/server/lib/workspace/host.js +2 -0
  154. package/dist/assets/DiagramView-Bj1ZrdhI.js +0 -1
  155. package/dist/assets/FileSaveConflictDialog-2Z4V_gZU.js +0 -3
  156. package/dist/assets/FilesView-K18gBSws.js +0 -6
  157. package/dist/assets/GitView-Hm1KBPaD.js +0 -8
  158. package/dist/assets/JsonTreeView-fNsiZEIo.js +0 -1
  159. package/dist/assets/PatchDiff-DZaJG6jj.js +0 -1
  160. package/dist/assets/SessionSwitcherContent-RAsmsuYk.js +0 -1
  161. package/dist/assets/SessionSwitcherDropdown-DuLPlIF_.js +0 -2
  162. package/dist/assets/SessionUnreadDot-Dm6k5OCd.js +0 -1
  163. package/dist/assets/SettingsView-Chu4zbWo.js +0 -6
  164. package/dist/assets/SettingsWindow-CJzFmmfu.js +0 -1
  165. package/dist/assets/ToolOutputDialog-uYeXsAGc.js +0 -8
  166. package/dist/assets/ToolPartDiffPreview-DnAHVRs-.js +0 -1
  167. package/dist/assets/Virtualizer-BSHVMKgK.js +0 -1
  168. package/dist/assets/collapsible-BH1vXEAI.js +0 -1
  169. package/dist/assets/computeVirtualFileMetrics-DXkR5jdw.js +0 -3
  170. package/dist/assets/gitStatusPredicates-BW8heN1a.js +0 -134
  171. package/dist/assets/index-5fyXnZFi.css +0 -1
  172. package/dist/assets/index-BrgKwTb0.js +0 -1
  173. package/dist/assets/index-C-sV_9sb.js +0 -8
  174. package/dist/assets/isDiffPlainText-DZFr1Tta.js +0 -1
  175. package/dist/assets/isFilePlainText-KNpEMvb-.js +0 -1
  176. package/dist/assets/main-BPY2ug1A.js +0 -135
  177. package/dist/assets/main-BRIjzIRl.js +0 -2
  178. package/dist/assets/markdownCore-DYizLr1N.js +0 -3
  179. package/dist/assets/miniChat-Dva4MINl.js +0 -2
  180. package/dist/assets/mobile-6jNUNv_x.js +0 -2
  181. package/dist/assets/permissionStore-iKN1K2_x.js +0 -1
  182. package/dist/assets/renderElectronMiniChatApp-BIeBrZmO.js +0 -2
  183. package/dist/assets/renderMobileApp-BDCtZpeS.js +0 -11
  184. package/dist/assets/runtimeEndpointReset-DqdGOWp8.js +0 -53
  185. package/dist/assets/useAppFontEffects-BABx-DxZ.js +0 -6722
  186. package/dist/assets/usePushVisibilityBeacon-BciEu3HS.js +0 -10
  187. package/dist/assets/useSwitcherItems-C7_5TB_n.js +0 -1
  188. package/dist/assets/vendor-aria-hidden-DvXkyWUv.js +0 -1
  189. package/dist/assets/vendor-base-ui-DXSHfszQ.js +0 -1
  190. package/dist/assets/vendor-class-variance-authority-5VPnzWs2.js +0 -1
  191. package/dist/assets/vendor-cmdk-zXx6sGnS.js +0 -1
  192. package/dist/assets/vendor-codemirror-autocomplete-wd6iRebq.js +0 -1
  193. package/dist/assets/vendor-codemirror-commands-CNlncqrr.js +0 -1
  194. package/dist/assets/vendor-codemirror-lang-angular-DU_4KiiW.js +0 -1
  195. package/dist/assets/vendor-codemirror-lang-cpp-CmIT9Z5_.js +0 -1
  196. package/dist/assets/vendor-codemirror-lang-css-djiuoTi8.js +0 -1
  197. package/dist/assets/vendor-codemirror-lang-go-COZSwZYW.js +0 -7
  198. package/dist/assets/vendor-codemirror-lang-html-CKHqhW5R.js +0 -1
  199. package/dist/assets/vendor-codemirror-lang-java-CNMP5hyC.js +0 -1
  200. package/dist/assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js +0 -13
  201. package/dist/assets/vendor-codemirror-lang-jinja-DaKn_b1k.js +0 -1
  202. package/dist/assets/vendor-codemirror-lang-json-CZ07HmNC.js +0 -1
  203. package/dist/assets/vendor-codemirror-lang-less-wJdQiDBf.js +0 -1
  204. package/dist/assets/vendor-codemirror-lang-liquid-0z48Roi8.js +0 -1
  205. package/dist/assets/vendor-codemirror-lang-markdown-DtcZDGqe.js +0 -1
  206. package/dist/assets/vendor-codemirror-lang-php-W8plS-JQ.js +0 -1
  207. package/dist/assets/vendor-codemirror-lang-python-DzzokVau.js +0 -3
  208. package/dist/assets/vendor-codemirror-lang-rust-C4ulBVpf.js +0 -1
  209. package/dist/assets/vendor-codemirror-lang-sass-BkZJYEwS.js +0 -1
  210. package/dist/assets/vendor-codemirror-lang-vue-DiBPljCc.js +0 -1
  211. package/dist/assets/vendor-codemirror-lang-wast-DoABsogh.js +0 -1
  212. package/dist/assets/vendor-codemirror-lang-xml-BhLJhOCH.js +0 -1
  213. package/dist/assets/vendor-codemirror-lang-yaml-D95i1Y5R.js +0 -1
  214. package/dist/assets/vendor-codemirror-language-BByA_dGF.js +0 -3
  215. package/dist/assets/vendor-codemirror-language-data-BB5mQv-R.js +0 -2
  216. package/dist/assets/vendor-codemirror-search-BV44140v.js +0 -2
  217. package/dist/assets/vendor-codemirror-state-CNWM3Q8V.js +0 -5
  218. package/dist/assets/vendor-codemirror-view-Ct4T37Ue.js +0 -4
  219. package/dist/assets/vendor-crelt-C8TCjufn.js +0 -1
  220. package/dist/assets/vendor-detect-node-es-l0sNRNKZ.js +0 -1
  221. package/dist/assets/vendor-dnd-kit-accessibility-DZKKhs9S.js +0 -1
  222. package/dist/assets/vendor-dnd-kit-core-C9qcAm_1.js +0 -5
  223. package/dist/assets/vendor-dnd-kit-sortable-D8ozj8M-.js +0 -1
  224. package/dist/assets/vendor-dnd-kit-utilities-DTY1C6ST.js +0 -1
  225. package/dist/assets/vendor-floating-ui-core-CXmKXOXc.js +0 -1
  226. package/dist/assets/vendor-floating-ui-dom-WyXykhNi.js +0 -1
  227. package/dist/assets/vendor-floating-ui-react-dom-BZOGXAGe.js +0 -1
  228. package/dist/assets/vendor-floating-ui-utils-BzXdqYpP.js +0 -1
  229. package/dist/assets/vendor-framer-motion-CfplGuM0.js +0 -1
  230. package/dist/assets/vendor-get-nonce-C-Z93AgS.js +0 -1
  231. package/dist/assets/vendor-lezer-common-B3-cUCR_.js +0 -1
  232. package/dist/assets/vendor-lezer-cpp-BleAU9o-.js +0 -1
  233. package/dist/assets/vendor-lezer-css-C5xB6jxd.js +0 -1
  234. package/dist/assets/vendor-lezer-go-CXK1UKk8.js +0 -1
  235. package/dist/assets/vendor-lezer-highlight-CDMHUZ74.js +0 -1
  236. package/dist/assets/vendor-lezer-html-C0I1p52t.js +0 -1
  237. package/dist/assets/vendor-lezer-java-D_zzj-NV.js +0 -1
  238. package/dist/assets/vendor-lezer-javascript-D7Tj24ot.js +0 -1
  239. package/dist/assets/vendor-lezer-json-Iaex0UN-.js +0 -1
  240. package/dist/assets/vendor-lezer-lr-bhwg1HMg.js +0 -1
  241. package/dist/assets/vendor-lezer-php-_DHrbsZG.js +0 -1
  242. package/dist/assets/vendor-lezer-python-CvuFxeZl.js +0 -1
  243. package/dist/assets/vendor-lezer-rust-Lqgd5SAo.js +0 -1
  244. package/dist/assets/vendor-lezer-sass-Dnm2lY4t.js +0 -1
  245. package/dist/assets/vendor-lezer-xml-hUDuAyS5.js +0 -1
  246. package/dist/assets/vendor-lezer-yaml-BNIl6S_O.js +0 -1
  247. package/dist/assets/vendor-marijn-find-cluster-break-DXwl3gUT.js +0 -1
  248. package/dist/assets/vendor-motion-dom-DhJ-sYS5.js +0 -1
  249. package/dist/assets/vendor-motion-l0sNRNKZ.js +0 -1
  250. package/dist/assets/vendor-motion-utils-CKEGc_YG.js +0 -1
  251. package/dist/assets/vendor-radix-ui-primitive-Dc_FVRD7.js +0 -1
  252. package/dist/assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js +0 -1
  253. package/dist/assets/vendor-radix-ui-react-context-CFsX-AUC.js +0 -1
  254. package/dist/assets/vendor-radix-ui-react-dialog-D2yhEu2p.js +0 -5
  255. package/dist/assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js +0 -1
  256. package/dist/assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js +0 -1
  257. package/dist/assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js +0 -1
  258. package/dist/assets/vendor-radix-ui-react-id-D2kS9K1j.js +0 -1
  259. package/dist/assets/vendor-radix-ui-react-portal-YgCRIyi7.js +0 -1
  260. package/dist/assets/vendor-radix-ui-react-presence-D432pCMB.js +0 -1
  261. package/dist/assets/vendor-radix-ui-react-primitive-DkH8dMOR.js +0 -1
  262. package/dist/assets/vendor-radix-ui-react-slot-BIDFZX0-.js +0 -1
  263. package/dist/assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js +0 -1
  264. package/dist/assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js +0 -1
  265. package/dist/assets/vendor-radix-ui-react-use-effect-event-D94va83M.js +0 -1
  266. package/dist/assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js +0 -1
  267. package/dist/assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js +0 -1
  268. package/dist/assets/vendor-react-B5Z1Mdn3.js +0 -9
  269. package/dist/assets/vendor-react-remove-scroll-bar-CSAHp1YF.js +0 -38
  270. package/dist/assets/vendor-react-remove-scroll-vR1dy1aP.js +0 -4
  271. package/dist/assets/vendor-react-style-singleton-Ctw6HnYx.js +0 -1
  272. package/dist/assets/vendor-reselect-l0sNRNKZ.js +0 -1
  273. package/dist/assets/vendor-scheduler-7OC5HNn7.js +0 -1
  274. package/dist/assets/vendor-simplewebauthn-browser-VDA66rT_.js +0 -2
  275. package/dist/assets/vendor-sonner-BDtm25td.js +0 -1
  276. package/dist/assets/vendor-style-mod-NZ5MEPvj.js +0 -3
  277. package/dist/assets/vendor-tanstack-react-virtual-2skouoFw.js +0 -1
  278. package/dist/assets/vendor-tanstack-virtual-core-Dubg10g5.js +0 -1
  279. package/dist/assets/vendor-tslib-De9GV7Vy.js +0 -1
  280. package/dist/assets/vendor-use-callback-ref-CVVuCyLj.js +0 -1
  281. package/dist/assets/vendor-use-sidecar-Vv4V8Nd1.js +0 -1
  282. package/dist/assets/vendor-use-sync-external-store-D0AXkdQC.js +0 -1
  283. package/dist/assets/vendor-w3c-keyname-Vcq4gwWv.js +0 -1
  284. package/dist/assets/vendor-zustand-GVb4H8HE.js +0 -6
  285. package/server/lib/git/credentials.js +0 -41
  286. package/server/lib/git/identity-storage.js +0 -122
  287. /package/dist/assets/{vendor-katex-CNckGUMB.js → vendor-katex-DZG0Ov6p.js} +0 -0
  288. /package/dist/assets/{vendor-katex-Cp579UoJ.css → vendor-katex-css-Cp579UoJ.css} +0 -0
  289. /package/dist/assets/{vendor-xterm-xterm-CrXqRur4.js → vendor-xterm-xterm-B-qIQCd3.js} +0 -0
  290. /package/dist/assets/{vendor-xterm-xterm-DDGTF8rc.css → vendor-xterm-xterm-css-DDGTF8rc.css} +0 -0
@@ -0,0 +1,271 @@
1
+ # GitHub Module Documentation
2
+
3
+ ## Purpose
4
+
5
+ Server-side GitHub pull request and issue integration for the PiChamber web
6
+ server runtime. Every GitHub call runs here; the shared UI talks to
7
+ `/api/github/*` through `RuntimeAPIs.github`, so web, desktop, hosted
8
+ mobile, and Capacitor share one code path. Tokens never reach a client.
9
+
10
+ ## Entrypoints and structure
11
+
12
+ - `packages/web/server/lib/github/`: module directory.
13
+ - `index.js`: module re-exports (`registerGitHubRoutes` and the service
14
+ factories; route tests inject fakes through
15
+ `registerGitHubRoutes(app, overrides)`).
16
+ - `routes.js`: thin Express adapter (`registerGitHubRoutes`), §5.3 routes.
17
+ - `gh-cli.js`: `gh` binary resolution (login-shell PATH), version gate,
18
+ `auth status` (JSON with plain-text fallback), `auth token` reads.
19
+ Binary and version are cached for the process lifetime; the working
20
+ `auth status` flavor is remembered so older gh CLIs do not pay a
21
+ failed `--json` spawn on every call.
22
+ - `credential.js`: per-operation token pinning, fingerprinting, viewer cache.
23
+ - `client.js`: native-fetch REST + GraphQL, 8 s timeout, ETag cache,
24
+ rate-limit detection, taxonomy error mapping, host safety.
25
+ - `repo-scope.js`: §4 discovery, remote parsing, allow-list matching, fork
26
+ metadata loader.
27
+ - `templates.js`: issue-template listing (`.github/ISSUE_TEMPLATE/*.md`
28
+ via the contents API, YAML forms skipped) with a 5 min TTL cache.
29
+ - `pulls.js` / `issues.js` / `checks.js`: domain reads and mutations with
30
+ TTL caches and stale fallback. Detail/comment reads request
31
+ `Accept: application/vnd.github.full+json` (`FULL_ACCEPT` in `pulls.js`)
32
+ so responses carry `body_html` alongside `body`; the mappers expose it
33
+ as `bodyHtml` on PR detail bodies, PR conversation comments, reviews,
34
+ review-thread comments (`bodyHTML` in `REVIEW_THREADS_QUERY`), issue
35
+ bodies, and issue comments. List summaries stay body-free. PR detail carries per-section
36
+ `sectionErrors` (`reviews`/`threads`); issue detail carries
37
+ `sectionErrors` (`linkedPullRequests`); checks carry `sectionErrors`
38
+ (`runs`/`statuses`). A failed section keeps its array as `[]` but is
39
+ never authoritative empty — callers render the section error.
40
+ - `pulls.js` also serves PR conversation comments through the issues
41
+ comments API for the PR number (paginated, ~15 s cache; posting
42
+ invalidates the number's entries so the re-read sees the comment).
43
+ Both detail readers attach
44
+ `viewerPermission` (`level` + `fallback`), `capabilities`, and
45
+ `viewerLogin` (see Credential model); issue detail additionally returns
46
+ `linkedPullRequests` (number, title, state, draft, url, repo) resolved
47
+ via GraphQL (`closedByPullRequestsReferences` plus `CrossReferenced` /
48
+ `Connected` timeline PR sources, deduped).
49
+ - `context.js`: agent-facing context payloads with budgets (§8).
50
+ - `cache.js`: TTL caches with in-flight coalescing + rate-limit windows,
51
+ plus shared key/predicate helpers (`repoCachePrefix`,
52
+ `repoInvalidatePredicate`, `nextCursor`).
53
+ - Shared mapping/validation helpers: `mapUser`/`mapLabel` live in
54
+ `pulls.js` (imported by `issues.js`); `parsePerPage`/`parseEnumParam`
55
+ and the viewer-context loader (`buildViewerContextLoader`) live in
56
+ `repo-scope.js`; `toSectionError` lives in `errors.js`.
57
+ - `errors.js`: §5.1 taxonomy, HTTP mapping, secret redaction.
58
+
59
+ Registered in `packages/web/server/lib/workspace/host.js` via
60
+ `registerGitHubRoutes(app)` alongside the git/fs routes. All `/api/*`
61
+ routes run behind the global auth gate in
62
+ `lib/server/core-routes.js`, which is what protects the mutating routes —
63
+ no per-route auth is added here.
64
+
65
+ ## Credential model (§3.1, §3.2)
66
+
67
+ - Source of truth is the GitHub CLI's active account. No login flow, no
68
+ stored tokens, no account switcher.
69
+ - Binary: `GH_BINARY` / `PICHAMBER_GH_BINARY` override, then the
70
+ login-shell PATH (`$SHELL -l -c 'printf %s "$PATH"'`, 2.5 s timeout,
71
+ 5 min cache), then the process PATH via the shared
72
+ `lib/tunnels/executable-search.js` helpers.
73
+ - Minimum gh version: `2.4.0` (`MIN_GH_VERSION` in `gh-cli.js`), floored by
74
+ the flags used (`gh auth token --hostname`, plain `gh auth status`).
75
+ `gh auth status --json hosts` is attempted first and plain-text parsing
76
+ is the fallback — installed gh 2.46 does not accept `--json`, so the
77
+ fallback is currently the working path.
78
+ - Token: `gh auth token --hostname <host>` via `execFile` (arg array, no
79
+ shell), 5 s timeout, memory only, ~30 s cache per host.
80
+ - Pinning: `withPinnedCredential(host, task)` reads the token once per
81
+ logical operation; every request in the chain uses that token. Cache keys
82
+ use `sha256(host + token)` fingerprints, never the token.
83
+ - Viewer (`GET /user`) cached per fingerprint ~10 min, successes only.
84
+ - Viewer permission reuses the repo-info loader (`GET /repos/{owner}/{repo}`
85
+ `permissions`: `admin`, `maintain`, `push`, `triage`, `pull`), so it is
86
+ cached per fingerprint + repo ~5 min with successes only. Resolution never
87
+ throws: failure resolves to `{ level: null, fallback: true }` with
88
+ permissive capabilities, so the UI keeps controls enabled and the single
89
+ attempt reports the server error instead of hiding controls silently.
90
+ - Never runs `gh auth switch/login/logout/setup-git`, never writes git
91
+ config or `~/.git-credentials`. `gh` stdout is never logged or forwarded.
92
+
93
+ ## Scope resolution (§4.1, §4.2)
94
+
95
+ - Containing: `git rev-parse --show-toplevel`. Enclosing: upward walk from
96
+ the containing root's parent, bounded at `$HOME`/filesystem root (64
97
+ levels max). Nested: breadth-first walk below the root — max depth 4,
98
+ max 50 repos, max 5000 dirs, 2 s budget, skipping `node_modules`, `.git`,
99
+ build/output dirs; `.gitmodules` paths marked `submodule: true`;
100
+ ignored paths filtered with one batched `git check-ignore --stdin`
101
+ spawn. Any cutoff sets `truncated: true`, never a silent short list.
102
+ - Worktrees share the containing checkout's identity `(host, owner, repo)`.
103
+ - Remote parsing: `https://`, `http://`, `ssh://`, scp-like
104
+ `git@host:owner/repo`, optional `.git`/port/credentials. Default remote:
105
+ tracking → `origin` → `upstream` → first GitHub remote. Fork parent via
106
+ `GET /repos/{owner}/{repo}` (lazy, credential required).
107
+ - Git reads run fail-closed: `GIT_TERMINAL_PROMPT=0`,
108
+ `GCM_INTERACTIVE=never`, empty `GIT_ASKPASS`/`SSH_ASKPASS`. Scope cached
109
+ per directory 30 s; `POST /api/github/invalidate` clears it.
110
+ - `GET /api/github/scope` enriches every GitHub entry with fork/parent/
111
+ default-branch metadata (the UI reads these for whichever repository is
112
+ selected), paced at 4 concurrent repo-info reads; repeat loads hit the
113
+ 5 min repo-info cache.
114
+ - v1 enables `github.com` only; the client stays host-aware for later
115
+ Enterprise enablement.
116
+
117
+ ## Caching (§5.2)
118
+
119
+ | Read | TTL |
120
+ |---|---|
121
+ | Lists (PRs, issues) | 30 s |
122
+ | PR / issue detail | 15 s |
123
+ | Checks | 15 s |
124
+ | PR files, PR/issue comments, job steps, annotations, repo meta | ~15 s (mutations invalidate; comment posts invalidate that number) |
125
+ | Scope | 30 s per directory |
126
+ | Repo info (fork, default branch) | 5 min |
127
+ | Viewer | 10 min per fingerprint |
128
+ | Viewer permission (`GET /repos/{o}/{r}` `permissions`) | 5 min per fingerprint + repo (shared repo-info cache) |
129
+ | Token | ~30 s per host |
130
+ | Issue templates | 5 min |
131
+
132
+ Only successes are cached. Identical in-flight reads coalesce.
133
+ Rate-limited/timed-out reads serve last-good with `stale: true` +
134
+ `fetchedAt`; any other failure propagates so it never reads as empty.
135
+ Per-section failures (PR reviews/threads, check runs/statuses) surface in
136
+ `sectionErrors` instead of degrading to `[]`.
137
+ Background reads should check `client.isRateLimited(host)` and pause
138
+ during the window; user actions are still attempted.
139
+
140
+ `body_html` attachment/private images are rewritten by GitHub to
141
+ short-lived signed URLs (expire ~5 min). Detail caches hold them only
142
+ 15 s and comment lists only ~15 s, so a served body can never outlive
143
+ its image URLs by a meaningful margin.
144
+
145
+ ## Error taxonomy (§5.1)
146
+
147
+ Success payload, or `{ error: … }`:
148
+
149
+ - `{ kind: 'unavailable', reason }`: `gh-missing` | `gh-outdated` |
150
+ `gh-unauthenticated` | `not-github` | `no-repository` | `no-access` |
151
+ `scope-missing` (with `scopes` when known).
152
+ - `{ kind: 'rate-limited', retryAt }` (ms epoch).
153
+ - `{ kind: 'failed', message }` (secret-free).
154
+
155
+ HTTP mapping: `scope-missing` → 403; `not-github` / `no-repository` /
156
+ `no-access` (incl. repo allow-list rejection) → 404; `gh-*` → 503;
157
+ `rate-limited` → 429; `failed` → 502; bad input → 400
158
+ `{ error: { kind: 'failed', message } }` (via `inputError`, same body shape
159
+ with `statusCode` 400 so callers can distinguish bad input from upstream
160
+ failures).
161
+
162
+ ## Routes (§5.3 + UI support)
163
+
164
+ All repo-scoped routes take `directory` (query or body) plus
165
+ `repo=host/owner/name`, validated against the scope allow-list.
166
+
167
+ ```
168
+ GET /api/github/status
169
+ GET /api/github/scope?directory=
170
+ GET /api/github/pulls?repo=&directory=&state=&filter=&q=&cursor=&sort=
171
+ GET /api/github/pulls/:number?repo=&directory=
172
+ GET /api/github/pulls/:number/files?repo=&directory=&cursor=
173
+ GET /api/github/pulls/:number/checks?repo=&directory=&details=
174
+ GET /api/github/pulls/:number/comments?repo=&directory=&cursor=
175
+ GET /api/github/pr-status?directory=&branch=
176
+ POST /api/github/pulls { title, head, base, body?, draft? }
177
+ POST /api/github/pulls/:number/actions { action, expectedHeadSha? }
178
+ POST /api/github/pulls/:number/comments { body }
179
+ POST /api/github/pulls/:number/reviews { event, body?, comments?[], commitId? }
180
+ POST /api/github/pulls/:number/threads/:threadId { action: reply|resolve|unresolve, body?, commentId? }
181
+ PATCH /api/github/pulls/:number { title?, body? }
182
+ POST /api/github/pulls/:number/checkout { mode: worktree|current }
183
+ GET /api/github/issues?repo=&directory=&state=&filter=&q=&labels=&cursor=&sort=
184
+ GET /api/github/issues/:number?repo=&directory=
185
+ GET /api/github/issues/:number/comments?repo=&directory=&cursor=
186
+ POST /api/github/issues { title, body?, labels?, assignees?, milestone? }
187
+ PATCH /api/github/issues/:number { title?, body?, state?, stateReason?, labels?, assignees?, milestone? }
188
+ POST /api/github/issues/:number/comments { body }
189
+ GET /api/github/meta?repo=&directory=&kinds= { kinds?: labels|assignees }
190
+ GET /api/github/templates?repo=&directory= markdown issue templates (name, filename, body)
191
+ GET /api/github/checks/jobs?repo=&directory=&runId=&jobId=
192
+ GET /api/github/checks/annotations?repo=&directory=&checkRunId=
193
+ POST /api/github/checks/rerun { repo, directory, runId }
194
+ GET /api/github/context?type=&repo=&directory=&number=[&ref=][&includeDiff=]
195
+ POST /api/github/invalidate { directory?, repo?, kind?, number? }
196
+ ```
197
+
198
+ - `state`: pulls `open|closed|merged|all`; issues `open|closed|all`.
199
+ Unknown values are 400 input errors (absent/empty keeps the default).
200
+ - `filter`: pulls `all|mine|review|assigned`; issues `all|mine|assigned|mentioned`.
201
+ Unknown values are 400 input errors.
202
+ - `sort`: `updated|created` on both list routes; unknown values are 400s.
203
+ - `cursor`/`perPage`: validated as before (`perPage` 1..100, default 30).
204
+ - `cursor`: opaque page cursor (page number). `nextCursor: null` ends paging.
205
+ `state=merged` advances from the raw closed page, so a page filtered to
206
+ zero merged PRs still continues paging instead of stalling.
207
+ - `pr-status`: PR for the directory's branch (open preferred over
208
+ closed/merged), checks summary for open PRs; default branch returns
209
+ `{ pr: null, skippedDefaultBranch: true }`. Branch names are capped at
210
+ 300 characters.
211
+ - `pulls/:number/checks`: resolves the head SHA with one single-resource
212
+ PR read, not the full detail fan-out (reviews/threads/viewer).
213
+ - `pulls/:number/comments`: top-level PR conversation comments via the
214
+ issues comments API for the PR number (oldest-first pages of 100,
215
+ `nextCursor`, ~15 s cache; failures propagate so they never read as empty).
216
+ - Thread ids (`threads/:threadId`) must be non-empty strings ≤ 200 chars.
217
+ - `issues/:number` detail now returns `linkedPullRequests` (with
218
+ `sectionErrors.linkedPullRequests` on GraphQL failure) plus
219
+ `viewerPermission`/`capabilities`/`viewerLogin`; `pulls/:number` detail
220
+ returns `viewerPermission`/`capabilities`/`viewerLogin`.
221
+ - Mutation results stay lightweight: `runAction`/`updatePull` return
222
+ `pr: null` and `updateIssue` returns `issue: null` (the UI re-reads
223
+ after invalidating). Caches are still invalidated server-side.
224
+ Unmapped summary fields (`headLabel`, `maintainerCanModify`,
225
+ `requestedTeams`) were dropped — no UI reader consumed them.
226
+ - `meta` loads labels + assignees concurrently and is cached ~15 s;
227
+ template candidate files load with a concurrency of 4 in priority order.
228
+ - `checkout`: fetches `refs/pull/<n>/head` with git only into
229
+ `pr-<n>-<slug>`, then creates the worktree through
230
+ `lib/git/service.js` (`validateWorktreeCreate`/`createWorktree`,
231
+ dynamically imported so git-module refactors degrade to an explicit
232
+ error rather than a crash). A leftover local branch is reused (the live
233
+ worktree path when still checked out, otherwise a safe ancestor-only
234
+ fast-forward plus a `mode: 'existing'` attach that preserves local
235
+ commits). `mode: current` creates the branch and checks it out in place
236
+ instead (also fast-forwarding only when safe and not checked out elsewhere).
237
+ - `context` types: `issue`, `pr` (`includeDiff=1`), `checks` (PR number
238
+ or explicit `ref`), `threads`. See `context.js` for budgets. A failed
239
+ comments/files fetch inside `issue`/`pr` context is marked with a
240
+ `Note: … could not be loaded` line in the context text — partial reads
241
+ stay partial and never render as authoritative empty. No new response
242
+ fields were added (`warnings` is a builder input only).
243
+
244
+ ## Invariants
245
+
246
+ - Never mutate shared user state: no git config writes, no `gh auth`
247
+ mutations, no credential files.
248
+ - Tokens: memory only; never logged, returned, or embedded in errors;
249
+ `gh` output never forwarded raw. `redactSecrets` guards fragments.
250
+ - `execFile` with argument arrays only. Owner/repo charset validated,
251
+ numbers are positive integers, before use in URLs or git refs.
252
+ - `repo` restricted to resolver-produced repositories (§5.3 allow-list).
253
+ - Mutations are idempotent-safe on retry and never auto-retried after an
254
+ uncertain outcome; destructive UI actions need confirmation (UI layer).
255
+ - Markdown from GitHub renders through `GitHubRichBody` (GitHub's own
256
+ `bodyHTML`, sanitized again client-side with DOMPurify) with a sanitized
257
+ markdown fallback; images load without credentials (UI layer).
258
+ - Never return an empty list on failure; stale serves are explicit. A
259
+ failed section (`sectionErrors`) never reads as an empty section.
260
+
261
+ ## Notes for contributors
262
+
263
+ - Add domain logic in `pulls.js` / `issues.js` / `checks.js`, keep
264
+ `routes.js` a thin adapter (validation + allow-list + error mapping).
265
+ - New reads need a TTL cache entry above, fingerprint-scoped keys, and
266
+ `readWithStaleFallback` where last-good serves are appropriate.
267
+ - Tests live beside the module (`*.test.js`, vitest). `gh` is faked via
268
+ injected `execFileAsync`; HTTP via injected `fetchImpl`; no network.
269
+ - `loadGitService` in `routes.js` dynamically imports
270
+ `lib/git/service.js`: do not statically import the git module from here
271
+ (it is under concurrent refactor and must degrade gracefully).
@@ -0,0 +1,164 @@
1
+ /** Bounded TTL caches with in-flight coalescing (§5.2). See DOCUMENTATION.md. */
2
+
3
+ export const createTtlCache = ({ ttlMs = 30_000, maxEntries = 500, now = Date.now } = {}) => {
4
+ const entries = new Map();
5
+ const inFlight = new Map();
6
+
7
+ const prune = () => {
8
+ const at = now();
9
+ for (const [key, entry] of entries) {
10
+ if (entry.expiresAt <= at) entries.delete(key);
11
+ }
12
+ while (entries.size > maxEntries) {
13
+ const oldest = entries.keys().next();
14
+ if (oldest.done) break;
15
+ entries.delete(oldest.value);
16
+ }
17
+ };
18
+
19
+ return {
20
+ get(key) {
21
+ const entry = entries.get(key);
22
+ if (!entry) return undefined;
23
+ if (entry.expiresAt <= now()) {
24
+ entries.delete(key);
25
+ return undefined;
26
+ }
27
+ // LRU refresh.
28
+ entries.delete(key);
29
+ entries.set(key, entry);
30
+ return entry.value;
31
+ },
32
+ peek(key) {
33
+ const entry = entries.get(key);
34
+ return entry && entry.expiresAt > now() ? entry.value : undefined;
35
+ },
36
+ /** Last good value even when expired (for stale:true serves). Never throws. */
37
+ peekStale(key) {
38
+ const entry = entries.get(key);
39
+ return entry ? { value: entry.value, fetchedAt: entry.fetchedAt } : undefined;
40
+ },
41
+ set(key, value) {
42
+ entries.delete(key);
43
+ entries.set(key, { value, expiresAt: now() + ttlMs, fetchedAt: now() });
44
+ prune();
45
+ },
46
+ delete(key) {
47
+ entries.delete(key);
48
+ },
49
+ invalidate(predicate) {
50
+ if (typeof predicate !== 'function') {
51
+ entries.clear();
52
+ return;
53
+ }
54
+ for (const key of [...entries.keys()]) {
55
+ if (predicate(key)) entries.delete(key);
56
+ }
57
+ },
58
+ clear() {
59
+ entries.clear();
60
+ inFlight.clear();
61
+ },
62
+ size() {
63
+ return entries.size;
64
+ },
65
+ /**
66
+ * Return the cached value, or run `loader` once for concurrent callers.
67
+ * Only resolved values are stored; rejections never populate the cache.
68
+ */
69
+ async getOrLoad(key, loader) {
70
+ const cached = entries.get(key);
71
+ if (cached && cached.expiresAt > now()) {
72
+ entries.delete(key);
73
+ entries.set(key, cached);
74
+ return { value: cached.value, fetchedAt: cached.fetchedAt, fromCache: true };
75
+ }
76
+ const pending = inFlight.get(key);
77
+ if (pending) {
78
+ const settled = await pending;
79
+ return { value: settled.value, fetchedAt: settled.fetchedAt, fromCache: true };
80
+ }
81
+ const task = (async () => {
82
+ const value = await loader();
83
+ entries.delete(key);
84
+ const record = { value, expiresAt: now() + ttlMs, fetchedAt: now() };
85
+ entries.set(key, record);
86
+ prune();
87
+ return record;
88
+ })();
89
+ inFlight.set(key, task);
90
+ try {
91
+ const record = await task;
92
+ return { value: record.value, fetchedAt: record.fetchedAt, fromCache: false };
93
+ } finally {
94
+ if (inFlight.get(key) === task) inFlight.delete(key);
95
+ }
96
+ },
97
+ };
98
+ };
99
+
100
+ export const createRateLimitWindows = ({ now = Date.now } = {}) => {
101
+ const windows = new Map();
102
+ return {
103
+ isRateLimited(host) {
104
+ const retryAt = windows.get(String(host || '').toLowerCase());
105
+ if (!retryAt) return false;
106
+ if (retryAt <= now()) {
107
+ windows.delete(String(host || '').toLowerCase());
108
+ return false;
109
+ }
110
+ return true;
111
+ },
112
+ getRetryAt(host) {
113
+ return windows.get(String(host || '').toLowerCase()) ?? null;
114
+ },
115
+ setRateLimited(host, retryAt) {
116
+ const at = Number.isFinite(retryAt) ? retryAt : now() + 60_000;
117
+ windows.set(String(host || '').toLowerCase(), at);
118
+ },
119
+ clear(host) {
120
+ if (host) windows.delete(String(host || '').toLowerCase());
121
+ else windows.clear();
122
+ },
123
+ };
124
+ };
125
+
126
+ /**
127
+ * Run `loader` through `cache.getOrLoad`; when the fresh read fails with a
128
+ * rate-limit or transport failure and a last-good value exists, serve it
129
+ * marked `{ stale: true, fetchedAt }` instead of throwing. Any other error
130
+ * propagates unchanged so failures never masquerade as authoritative data.
131
+ */
132
+ /** Fingerprint + repo prefix shared by every per-repo cache key. */
133
+ export const repoCachePrefix = (credential, repo) => `${credential?.fingerprint || ''}:${repo.host}/${repo.owner}/${repo.repo}`;
134
+
135
+ /**
136
+ * Invalidate predicate for fingerprint + repo (+number) scoped caches.
137
+ * `matchNumberInside` preserves the pulls detail oldest behavior where a
138
+ * number can also appear mid-key; over-invalidation only costs a refetch.
139
+ */
140
+ export const repoInvalidatePredicate = ({ fingerprint = '', repo = null, number = null, matchNumberInside = false } = {}) => (key) => {
141
+ if (fingerprint && !key.startsWith(fingerprint)) return false;
142
+ if (repo && !key.includes(`${repo.host}/${repo.owner}/${repo.repo}`)) return false;
143
+ if (number !== null && number !== undefined) {
144
+ const token = `:${number}`;
145
+ if (!key.endsWith(token) && !(matchNumberInside && key.includes(`${token}:`))) return false;
146
+ }
147
+ return true;
148
+ };
149
+
150
+ /** Opaque page cursor: advance only when the raw page came back full. */
151
+ export const nextCursor = (items, page, perPage) => ((Array.isArray(items) ? items.length : 0) === perPage ? String(page + 1) : null);
152
+ export const readWithStaleFallback = async (cache, key, loader, { staleOnRateLimit = true } = {}) => {
153
+ try {
154
+ const record = await cache.getOrLoad(key, loader);
155
+ return { value: record.value, fetchedAt: record.fetchedAt, stale: false };
156
+ } catch (error) {
157
+ const usable = error?.kind === 'failed'
158
+ || (staleOnRateLimit && error?.kind === 'rate-limited');
159
+ if (!usable) throw error;
160
+ const lastGood = cache.peekStale(key);
161
+ if (!lastGood) throw error;
162
+ return { value: lastGood.value, fetchedAt: lastGood.fetchedAt, stale: true, error };
163
+ }
164
+ };
@@ -0,0 +1,230 @@
1
+ /** Check runs + commit statuses rollup, job steps, annotations, re-runs. See DOCUMENTATION.md. */
2
+
3
+ import { createTtlCache, readWithStaleFallback, repoCachePrefix, repoInvalidatePredicate } from './cache.js';
4
+ import { inputError, toSectionError } from './errors.js';
5
+
6
+ export const CHECKS_TTL_MS = 15_000;
7
+ export const SHORT_TTL_MS = 15_000;
8
+
9
+ const normalizeConclusion = (status, conclusion) => {
10
+ if (status === 'queued' || status === 'in_progress' || status === 'waiting' || status === 'requested') {
11
+ return 'pending';
12
+ }
13
+ if (!conclusion) return status === 'completed' ? 'unknown' : 'pending';
14
+ if (conclusion === 'success' || conclusion === 'neutral' || conclusion === 'skipped') return 'success';
15
+ if (conclusion === 'failure' || conclusion === 'timed_out' || conclusion === 'action_required' || conclusion === 'cancelled') {
16
+ return 'failure';
17
+ }
18
+ return 'pending';
19
+ };
20
+
21
+ export const rollupCheckStates = (runs) => {
22
+ let success = 0;
23
+ let failure = 0;
24
+ let pending = 0;
25
+ for (const run of runs) {
26
+ const state = normalizeConclusion(run.status, run.conclusion);
27
+ if (state === 'success') success += 1;
28
+ else if (state === 'failure') failure += 1;
29
+ else pending += 1;
30
+ }
31
+ return {
32
+ state: runs.length === 0 ? 'unknown' : (failure > 0 ? 'failure' : (pending > 0 ? 'pending' : 'success')),
33
+ total: runs.length,
34
+ success,
35
+ failure,
36
+ pending,
37
+ };
38
+ };
39
+
40
+ const workflowRunIdFromUrl = (url) => {
41
+ const match = typeof url === 'string' ? url.match(/\/actions\/runs\/(\d+)/) : null;
42
+ return match ? Number(match[1]) : null;
43
+ };
44
+
45
+ const mapJob = (job) => ({
46
+ id: job.id,
47
+ name: job.name || '',
48
+ status: job.status || null,
49
+ conclusion: job.conclusion || null,
50
+ startedAt: job.started_at || null,
51
+ completedAt: job.completed_at || null,
52
+ detailsUrl: job.html_url || null,
53
+ steps: (job.steps || []).map((step) => ({
54
+ name: step.name || '',
55
+ status: step.status || null,
56
+ conclusion: step.conclusion || null,
57
+ number: step.number ?? null,
58
+ startedAt: step.started_at || null,
59
+ completedAt: step.completed_at || null,
60
+ })),
61
+ });
62
+
63
+ const mapCheckRun = (run) => ({
64
+ id: run.id,
65
+ name: run.name || '',
66
+ status: run.status || null,
67
+ conclusion: run.conclusion || null,
68
+ state: normalizeConclusion(run.status, run.conclusion),
69
+ startedAt: run.started_at || null,
70
+ completedAt: run.completed_at || null,
71
+ detailsUrl: run.details_url || run.html_url || null,
72
+ app: run.app ? { name: run.app.name || null, slug: run.app.slug || null } : null,
73
+ // Actions check runs are jobs: the check-run id is the job id, and the
74
+ // workflow run id (needed for re-runs) only appears in the details URL.
75
+ runId: workflowRunIdFromUrl(run.details_url || run.html_url),
76
+ });
77
+
78
+ export const createChecksService = ({ client, now = Date.now } = {}) => {
79
+ if (!client || typeof client.request !== 'function') {
80
+ throw new Error('createChecksService requires client');
81
+ }
82
+ const checksCache = createTtlCache({ ttlMs: CHECKS_TTL_MS, maxEntries: 300, now });
83
+ const stepsCache = createTtlCache({ ttlMs: SHORT_TTL_MS, maxEntries: 300, now });
84
+ const annotationsCache = createTtlCache({ ttlMs: SHORT_TTL_MS, maxEntries: 300, now });
85
+
86
+ const getChecks = async (credential, repo, ref, { details = false } = {}) => {
87
+ if (typeof ref !== 'string' || !ref.trim() || ref.length > 200) {
88
+ throw inputError('A commit SHA or ref is required.');
89
+ }
90
+ const cleanRef = ref.trim();
91
+ const key = `${repoCachePrefix(credential, repo)}:checks:${cleanRef}:${details ? 'full' : 'summary'}`;
92
+ const load = async () => {
93
+ const [runsSettled, statusesSettled] = await Promise.all([
94
+ client.request({
95
+ credential, host: repo.host, method: 'GET',
96
+ path: `/repos/${repo.owner}/${repo.repo}/commits/${encodeURIComponent(cleanRef)}/check-runs`,
97
+ query: { per_page: 100 },
98
+ operation: 'check runs',
99
+ }).then((response) => ({ ok: true, response }), (error) => ({ ok: false, error })),
100
+ client.request({
101
+ credential, host: repo.host, method: 'GET',
102
+ path: `/repos/${repo.owner}/${repo.repo}/commits/${encodeURIComponent(cleanRef)}/statuses`,
103
+ query: { per_page: 100 },
104
+ operation: 'commit statuses',
105
+ }).then((response) => ({ ok: true, response }), (error) => ({ ok: false, error })),
106
+ ]);
107
+ // A failed source is never an authoritative empty result: surface it
108
+ // in `sectionErrors` so callers render a failure, not "no checks".
109
+ // When both sources fail the whole read fails so stale fallback applies.
110
+ if (!runsSettled.ok && !statusesSettled.ok) {
111
+ throw runsSettled.error;
112
+ }
113
+ const sectionErrors = {};
114
+ if (!runsSettled.ok) sectionErrors.runs = toSectionError(runsSettled.error);
115
+ if (!statusesSettled.ok) sectionErrors.statuses = toSectionError(statusesSettled.error);
116
+ const runsResponse = runsSettled.ok ? runsSettled.response : { body: { check_runs: [] } };
117
+ const statusesResponse = statusesSettled.ok ? statusesSettled.response : { body: [] };
118
+ const runs = (runsResponse.body?.check_runs || []).map(mapCheckRun);
119
+ const statuses = (Array.isArray(statusesResponse.body) ? statusesResponse.body : []).map((status) => ({
120
+ id: status.id ?? null,
121
+ context: status.context || '',
122
+ state: status.state || null,
123
+ description: status.description || null,
124
+ targetUrl: status.target_url || null,
125
+ creator: status.creator ? { login: status.creator.login || null } : null,
126
+ createdAt: status.created_at || null,
127
+ }));
128
+ const combined = [
129
+ ...runs.map((run) => ({ status: run.status === 'completed' ? 'completed' : 'in_progress', conclusion: run.conclusion })),
130
+ ...statuses.map((status) => ({
131
+ status: status.state === 'pending' ? 'in_progress' : 'completed',
132
+ conclusion: status.state === 'success' ? 'success' : (status.state === 'failure' || status.state === 'error' ? 'failure' : null),
133
+ })),
134
+ ];
135
+ const summary = rollupCheckStates(combined);
136
+ const earliestStarted = runs
137
+ .map((run) => run.startedAt)
138
+ .filter(Boolean)
139
+ .sort()[0] || null;
140
+ return {
141
+ summary: { ...summary, startedAt: earliestStarted },
142
+ runs: details ? runs : runs.map((run) => ({
143
+ id: run.id, name: run.name, state: run.state, conclusion: run.conclusion,
144
+ detailsUrl: run.detailsUrl, app: run.app, runId: run.runId,
145
+ })),
146
+ statuses: details ? statuses : statuses.map((status) => ({ context: status.context, state: status.state })),
147
+ ...(Object.keys(sectionErrors).length > 0 ? { sectionErrors } : {}),
148
+ };
149
+ };
150
+ const { value, fetchedAt, stale } = await readWithStaleFallback(checksCache, key, load);
151
+ return { repo: { ...repo }, ref: cleanRef, ...value, fetchedAt, ...(stale ? { stale: true } : {}) };
152
+ };
153
+
154
+ // Cached ~15 s so concurrent drill-down mounts coalesce; a re-run
155
+ // invalidates this repo's entries so fresh steps are one re-read away.
156
+ const getJobSteps = async (credential, repo, { runId = null, jobId = null } = {}) => {
157
+ const hasJob = jobId !== null && jobId !== undefined && jobId !== '';
158
+ const id = Number(hasJob ? jobId : runId);
159
+ if (!Number.isInteger(id) || id < 1) throw inputError('A workflow job or run id is required.');
160
+ // A single job (check-run id) is one direct read; a run lists its jobs.
161
+ const key = `${repoCachePrefix(credential, repo)}:jobs:${hasJob ? 'job' : 'run'}:${id}`;
162
+ const load = async () => {
163
+ if (hasJob) {
164
+ const response = await client.request({
165
+ credential, host: repo.host, method: 'GET',
166
+ path: `/repos/${repo.owner}/${repo.repo}/actions/jobs/${id}`,
167
+ operation: 'workflow job',
168
+ });
169
+ return { runId: response.body?.run_id ?? null, jobs: [mapJob(response.body || {})] };
170
+ }
171
+ const response = await client.request({
172
+ credential, host: repo.host, method: 'GET',
173
+ path: `/repos/${repo.owner}/${repo.repo}/actions/runs/${id}/jobs`,
174
+ query: { per_page: 100 },
175
+ operation: 'workflow jobs',
176
+ });
177
+ return { runId: id, jobs: (response.body?.jobs || []).map(mapJob) };
178
+ };
179
+ const { value, fetchedAt, stale } = await readWithStaleFallback(stepsCache, key, load);
180
+ return { repo: { ...repo }, runId: value.runId, jobs: value.jobs, fetchedAt, ...(stale ? { stale: true } : {}) };
181
+ };
182
+
183
+ const getAnnotations = async (credential, repo, { checkRunId }) => {
184
+ const id = Number(checkRunId);
185
+ if (!Number.isInteger(id) || id < 1) throw inputError('A check run id is required.');
186
+ const key = `${repoCachePrefix(credential, repo)}:annotations:${id}`;
187
+ const load = async () => {
188
+ const response = await client.request({
189
+ credential, host: repo.host, method: 'GET',
190
+ path: `/repos/${repo.owner}/${repo.repo}/check-runs/${id}/annotations`,
191
+ query: { per_page: 100 },
192
+ operation: 'check annotations',
193
+ });
194
+ return {
195
+ annotations: (Array.isArray(response.body) ? response.body : []).map((annotation) => ({
196
+ path: annotation.path || null,
197
+ startLine: annotation.start_line ?? null,
198
+ endLine: annotation.end_line ?? null,
199
+ level: annotation.annotation_level || null,
200
+ message: annotation.message || '',
201
+ title: annotation.title || null,
202
+ })),
203
+ };
204
+ };
205
+ const { value, fetchedAt, stale } = await readWithStaleFallback(annotationsCache, key, load);
206
+ return { repo: { ...repo }, checkRunId: id, ...value, fetchedAt, ...(stale ? { stale: true } : {}) };
207
+ };
208
+
209
+ const rerunFailed = async (credential, repo, { runId }) => {
210
+ const run = Number(runId);
211
+ if (!Number.isInteger(run) || run < 1) throw inputError('A workflow run id is required.');
212
+ await client.request({
213
+ credential, host: repo.host, method: 'POST',
214
+ path: `/repos/${repo.owner}/${repo.repo}/actions/runs/${run}/rerun-failed-jobs`,
215
+ operation: 're-run failed jobs',
216
+ });
217
+ invalidate(credential, repo);
218
+ return { ok: true, runId: run, fetchedAt: now() };
219
+ };
220
+
221
+ const invalidate = (credential = null, repo = null) => {
222
+ const fingerprint = credential?.fingerprint || '';
223
+ const predicate = repoInvalidatePredicate({ fingerprint, repo });
224
+ checksCache.invalidate(predicate);
225
+ stepsCache.invalidate(predicate);
226
+ annotationsCache.invalidate(predicate);
227
+ };
228
+
229
+ return { getChecks, getJobSteps, getAnnotations, rerunFailed, invalidate, rollupCheckStates };
230
+ };