@openchamber/web 1.18.4 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
  3. package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
  4. package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
  5. package/dist/assets/DiagramView-D0YNMix8.js +1 -0
  6. package/dist/assets/DiffView-BHWaMYCC.js +4 -0
  7. package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
  8. package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
  9. package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
  12. package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
  13. package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
  15. package/dist/assets/PlanView-Czu1KMJa.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
  17. package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
  18. package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
  19. package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
  20. package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
  22. package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
  25. package/dist/assets/de-DFdX3ABv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-iC-FKvV9.js +15 -0
  28. package/dist/assets/fr-BBbi_1AL.js +13 -0
  29. package/dist/assets/index-BiEgzzkg.js +1 -0
  30. package/dist/assets/index-Cwmuwk3V.js +7 -0
  31. package/dist/assets/index-GNm1wgUH.css +1 -0
  32. package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
  33. package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
  34. package/dist/assets/ja-DQLQJL2J.js +15 -0
  35. package/dist/assets/ko-BeElEB4Y.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-Dpzo18z7.js +2 -0
  38. package/dist/assets/main-WMjtYzJs.js +921 -0
  39. package/dist/assets/markdownCore--tDmyI_v.js +2 -0
  40. package/dist/assets/miniChat-ldEghBLB.js +2 -0
  41. package/dist/assets/mobile-Dk-VGreF.js +2 -0
  42. package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
  43. package/dist/assets/pl-CLHt2_vV.js +15 -0
  44. package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
  46. package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
  47. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
  48. package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
  49. package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
  50. package/dist/assets/uk-PhsC-c4-.js +15 -0
  51. package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
  52. package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
  85. package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
  86. package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
  87. package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
  88. package/dist/index.html +5 -4
  89. package/dist/mini-chat.html +4 -3
  90. package/dist/mobile.html +4 -3
  91. package/package.json +3 -5
  92. package/server/index.js +152 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +65 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +94 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +432 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  111. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  112. package/server/lib/dictation/local/worker-process.js +2 -2
  113. package/server/lib/dictation/openai-compatible-session.js +3 -2
  114. package/server/lib/dictation/stream-manager.js +77 -34
  115. package/server/lib/dictation/stream-manager.test.js +60 -2
  116. package/server/lib/fs/DOCUMENTATION.md +3 -0
  117. package/server/lib/fs/routes.js +149 -32
  118. package/server/lib/fs/routes.test.js +301 -0
  119. package/server/lib/git/DOCUMENTATION.md +8 -0
  120. package/server/lib/git/routes.js +43 -0
  121. package/server/lib/git/service.js +206 -72
  122. package/server/lib/git/service.test.js +222 -0
  123. package/server/lib/github/DOCUMENTATION.md +14 -3
  124. package/server/lib/github/pr-status.js +188 -83
  125. package/server/lib/github/pr-status.test.js +182 -0
  126. package/server/lib/github/routes.js +36 -30
  127. package/server/lib/notifications/template-runtime.js +2 -3
  128. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  129. package/server/lib/openchamber-control/actions.js +78 -0
  130. package/server/lib/openchamber-control/service.js +7 -0
  131. package/server/lib/openchamber-sessions/routes.js +14 -0
  132. package/server/lib/opencode/DOCUMENTATION.md +12 -6
  133. package/server/lib/opencode/claude-cli-auth.js +60 -0
  134. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  135. package/server/lib/opencode/feature-routes-runtime.js +16 -9
  136. package/server/lib/opencode/lifecycle.js +202 -26
  137. package/server/lib/opencode/lifecycle.test.js +179 -1
  138. package/server/lib/opencode/plugins.js +12 -3
  139. package/server/lib/opencode/plugins.test.js +18 -0
  140. package/server/lib/opencode/providers.js +9 -4
  141. package/server/lib/opencode/providers.test.js +27 -0
  142. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  143. package/server/lib/opencode/proxy.js +116 -6
  144. package/server/lib/opencode/proxy.test.js +158 -1
  145. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  146. package/server/lib/opencode/routes.js +4 -1
  147. package/server/lib/opencode/session-runtime.js +39 -2
  148. package/server/lib/opencode/session-runtime.test.js +74 -0
  149. package/server/lib/opencode/settings-helpers.js +26 -0
  150. package/server/lib/opencode/settings-helpers.test.js +57 -0
  151. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  152. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  153. package/server/lib/opencode/settings-runtime.js +83 -10
  154. package/server/lib/opencode/settings-runtime.test.js +85 -0
  155. package/server/lib/opencode/shared.js +120 -16
  156. package/server/lib/opencode/shared.test.js +185 -1
  157. package/server/lib/opencode/skill-routes.js +29 -73
  158. package/server/lib/opencode/skill-routes.test.js +2 -5
  159. package/server/lib/project-context/DOCUMENTATION.md +160 -0
  160. package/server/lib/project-context/routes.http.test.js +264 -0
  161. package/server/lib/project-context/routes.js +237 -0
  162. package/server/lib/project-context/runtime.js +672 -0
  163. package/server/lib/project-context/runtime.test.js +498 -0
  164. package/server/lib/projects/project-config.js +7 -2
  165. package/server/lib/quota/DOCUMENTATION.md +17 -2
  166. package/server/lib/quota/providers/claude/auth.js +113 -0
  167. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  168. package/server/lib/quota/providers/claude/index.js +151 -0
  169. package/server/lib/quota/providers/claude/index.test.js +147 -0
  170. package/server/lib/quota/providers/claude/transforms.js +127 -0
  171. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  172. package/server/lib/quota/providers/command-code.js +90 -0
  173. package/server/lib/quota/providers/command-code.test.js +85 -0
  174. package/server/lib/quota/providers/index.js +30 -2
  175. package/server/lib/quota/providers/index.test.js +10 -1
  176. package/server/lib/quota/providers/zai.js +26 -6
  177. package/server/lib/quota/providers/zai.test.js +33 -0
  178. package/server/lib/quota/utils/formatters.js +2 -1
  179. package/server/lib/scheduled-tasks/runtime.js +21 -2
  180. package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
  181. package/server/lib/session-knowledge/routes.js +107 -0
  182. package/server/lib/session-knowledge/runtime.js +331 -0
  183. package/server/lib/session-knowledge/runtime.test.js +275 -0
  184. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  185. package/server/lib/skills-catalog/cache.js +120 -1
  186. package/server/lib/skills-catalog/cache.test.js +77 -0
  187. package/server/lib/skills-catalog/curated-sources.js +21 -5
  188. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  189. package/server/lib/skills-catalog/disk-cache.js +52 -0
  190. package/server/lib/skills-catalog/github-meta.js +139 -0
  191. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  192. package/server/lib/skills-catalog/source.js +0 -5
  193. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  194. package/server/lib/small-model/call.js +46 -12
  195. package/server/lib/small-model/call.test.js +79 -0
  196. package/server/lib/small-model/index.js +57 -6
  197. package/server/lib/small-model/index.test.js +102 -2
  198. package/server/lib/small-model/routes.js +4 -2
  199. package/server/lib/small-model/runtime-providers.js +156 -0
  200. package/server/lib/small-model/runtime-providers.test.js +112 -0
  201. package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
  202. package/dist/assets/DiffView-DZIoOnV7.js +0 -4
  203. package/dist/assets/FilesView-BKL6YlKG.js +0 -14
  204. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
  205. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
  206. package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
  207. package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
  208. package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
  209. package/dist/assets/SettingsView-5RmswFZe.js +0 -28
  210. package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
  211. package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
  212. package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
  213. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
  214. package/dist/assets/de-u7gSnqWs.js +0 -9
  215. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  216. package/dist/assets/es-T9O7aAOr.js +0 -15
  217. package/dist/assets/fr-Oor7ewbE.js +0 -13
  218. package/dist/assets/index-BzIpNlNE.css +0 -1
  219. package/dist/assets/index-C0yNhuZw.js +0 -1
  220. package/dist/assets/index-DRpChWux.js +0 -7
  221. package/dist/assets/ja-DHpqbVmr.js +0 -15
  222. package/dist/assets/ko-CwLkS3nx.js +0 -15
  223. package/dist/assets/main-D7UcL3VQ.js +0 -2
  224. package/dist/assets/main-DPMd2iKS.js +0 -915
  225. package/dist/assets/markdownCore-DDrHVneM.js +0 -2
  226. package/dist/assets/miniChat-O_GVoEbc.js +0 -2
  227. package/dist/assets/mobile-Br4TtAqc.js +0 -2
  228. package/dist/assets/pl-CcZILN8q.js +0 -15
  229. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  230. package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
  231. package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
  232. package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
  233. package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
  234. package/dist/assets/uk-BA2kZR38.js +0 -15
  235. package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
  236. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  237. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  238. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  239. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  240. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  241. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  242. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  243. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  244. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  245. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  246. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  247. package/server/lib/quota/providers/claude.js +0 -107
  248. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  249. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  250. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  251. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -332,6 +332,38 @@ const safeListPulls = async (octokit, options) => {
332
332
  const REPO_PULLS_CACHE_TTL_MS = 45_000;
333
333
  const repoPullsCache = new Map();
334
334
 
335
+ // Remembered answer to "what is the newest closed/merged PR for this head?",
336
+ // so discovery polls do not re-ask GitHub every few minutes.
337
+ //
338
+ // A found record barely ever changes: it would take a second PR on the same
339
+ // head, and while that one is open the open-PR path wins and never reads this
340
+ // cache at all. "No history yet" is the volatile answer, since closing or
341
+ // merging a PR elsewhere flips it, so it expires far sooner. Either way, doing
342
+ // it from OpenChamber invalidates the entry immediately.
343
+ const HISTORICAL_PR_FOUND_TTL_MS = 6 * 60 * 60 * 1000;
344
+ const HISTORICAL_PR_ABSENT_TTL_MS = 10 * 60 * 1000;
345
+ const HISTORICAL_PR_CACHE_MAX_ENTRIES = 500;
346
+ const _historicalPrCache = new Map();
347
+
348
+ const isHistoricalPrCacheFresh = (entry) => {
349
+ if (!entry) {
350
+ return false;
351
+ }
352
+ const ttl = entry.pr ? HISTORICAL_PR_FOUND_TTL_MS : HISTORICAL_PR_ABSENT_TTL_MS;
353
+ return Date.now() - entry.fetchedAt < ttl;
354
+ };
355
+
356
+ const rememberHistoricalPr = (key, pr) => {
357
+ _historicalPrCache.delete(key);
358
+ _historicalPrCache.set(key, { pr, fetchedAt: Date.now() });
359
+ if (_historicalPrCache.size > HISTORICAL_PR_CACHE_MAX_ENTRIES) {
360
+ const oldest = _historicalPrCache.keys().next().value;
361
+ if (oldest !== undefined) {
362
+ _historicalPrCache.delete(oldest);
363
+ }
364
+ }
365
+ };
366
+
335
367
  export const invalidateRepoPullsCache = (owner, repo) => {
336
368
  const prefix = `${normalizeText(owner)}/${normalizeText(repo)}::`;
337
369
  for (const key of repoPullsCache.keys()) {
@@ -347,6 +379,13 @@ export const invalidateRepoPullsCache = (owner, repo) => {
347
379
  _searchMissCache.delete(key);
348
380
  }
349
381
  }
382
+ // A merge or close changes the branch's PR history, so drop it too.
383
+ const historicalPrefix = `${normalizeRepoKey(owner, repo)}::`;
384
+ for (const key of _historicalPrCache.keys()) {
385
+ if (key.startsWith(historicalPrefix)) {
386
+ _historicalPrCache.delete(key);
387
+ }
388
+ }
350
389
  };
351
390
 
352
391
  const getRepoPulls = (octokit, repo, state, { force = false } = {}) => {
@@ -440,60 +479,61 @@ const searchFallbackPr = async ({ octokit, branch, repoNames }) => {
440
479
 
441
480
  const normalizedRepoNames = new Set(repoNames.map((name) => normalizeLower(name)).filter(Boolean));
442
481
 
443
- for (const state of ['open', 'closed']) {
444
- let response;
445
- try {
446
- response = await octokit.rest.search.issuesAndPullRequests({
447
- q: `is:pr state:${state} head:${branch}`,
448
- per_page: 20,
449
- });
450
- // If we get here, search API works for this repo — clear the disabled flag
451
- _searchApiDisabledRepos.delete(repoKey);
452
- } catch (error) {
453
- noteIfGitHubRateLimit(error);
454
- if (error?.status === 403) {
455
- _searchApiDisabledRepos.set(repoKey, Date.now());
456
- return null;
457
- }
458
- if (error?.status === 404) {
459
- continue;
460
- }
461
- throw error;
482
+ // The Search API has a tiny quota, so it is only spent on live branch status.
483
+ // Closed/merged history is resolved by the cheaper per-head repo queries.
484
+ let response;
485
+ try {
486
+ response = await octokit.rest.search.issuesAndPullRequests({
487
+ q: `is:pr state:open head:${branch}`,
488
+ per_page: 20,
489
+ });
490
+ // If we get here, search API works for this repo — clear the disabled flag
491
+ _searchApiDisabledRepos.delete(repoKey);
492
+ } catch (error) {
493
+ noteIfGitHubRateLimit(error);
494
+ if (error?.status === 403) {
495
+ _searchApiDisabledRepos.set(repoKey, Date.now());
496
+ return null;
462
497
  }
498
+ if (error?.status === 404) {
499
+ rememberSearchMiss(missKey);
500
+ return null;
501
+ }
502
+ throw error;
503
+ }
463
504
 
464
- const items = Array.isArray(response?.data?.items) ? response.data.items : [];
465
- for (const item of items) {
466
- const repo = parseRepoFromApiUrl(item?.repository_url);
467
- if (!repo) {
468
- continue;
469
- }
470
- if (normalizedRepoNames.size > 0 && !normalizedRepoNames.has(normalizeLower(repo.repo))) {
505
+ const items = Array.isArray(response?.data?.items) ? response.data.items : [];
506
+ for (const item of items) {
507
+ const repo = parseRepoFromApiUrl(item?.repository_url);
508
+ if (!repo) {
509
+ continue;
510
+ }
511
+ if (normalizedRepoNames.size > 0 && !normalizedRepoNames.has(normalizeLower(repo.repo))) {
512
+ continue;
513
+ }
514
+ try {
515
+ const prResponse = await octokit.rest.pulls.get({
516
+ owner: repo.owner,
517
+ repo: repo.repo,
518
+ pull_number: item.number,
519
+ });
520
+ const pr = prResponse?.data;
521
+ if (!pr || normalizeText(pr.head?.ref) !== branch) {
471
522
  continue;
472
523
  }
473
- try {
474
- const prResponse = await octokit.rest.pulls.get({
524
+ return {
525
+ repo: {
475
526
  owner: repo.owner,
476
527
  repo: repo.repo,
477
- pull_number: item.number,
478
- });
479
- const pr = prResponse?.data;
480
- if (!pr || normalizeText(pr.head?.ref) !== branch) {
481
- continue;
482
- }
483
- return {
484
- repo: {
485
- owner: repo.owner,
486
- repo: repo.repo,
487
- url: `https://github.com/${repo.owner}/${repo.repo}`,
488
- },
489
- pr,
490
- };
491
- } catch (error) {
492
- if (error?.status === 403 || error?.status === 404) {
493
- continue;
494
- }
495
- throw error;
528
+ url: `https://github.com/${repo.owner}/${repo.repo}`,
529
+ },
530
+ pr,
531
+ };
532
+ } catch (error) {
533
+ if (error?.status === 403 || error?.status === 404) {
534
+ continue;
496
535
  }
536
+ throw error;
497
537
  }
498
538
  }
499
539
 
@@ -501,7 +541,22 @@ const searchFallbackPr = async ({ octokit, branch, repoNames }) => {
501
541
  return null;
502
542
  };
503
543
 
504
- const findFirstMatchingPr = async ({ octokit, target, branch, sourceCandidates, force = false, coverage = null }) => {
544
+ const isTerminalPr = (pr) => Boolean(pr) && (pr.state === 'closed' || Boolean(pr.merged_at));
545
+
546
+ /**
547
+ * Resolve the PRs a branch is associated with in one repo target.
548
+ *
549
+ * Returns both candidates because they answer different questions:
550
+ * `open` is live branch status, `historical` is the last closed/merged PR for
551
+ * the same head. The caller must prefer an open PR from ANY target over a
552
+ * historical one — otherwise a merged fork PR hides an open upstream PR.
553
+ *
554
+ * `includeHistory` is off by default and must stay that way for secondary
555
+ * targets. Live status is worth searching the whole fork network for; history
556
+ * is not, and doing it per target multiplied the serial GitHub calls until the
557
+ * route hit its resolve timeout and reported no status at all.
558
+ */
559
+ const findBranchPrCandidates = async ({ octokit, target, branch, sourceCandidates, force = false, coverage = null, includeHistory = false }) => {
505
560
  const matcher = buildSourceMatcher(sourceCandidates);
506
561
  const sourceOwners = [];
507
562
  sourceCandidates.forEach((candidate) => pushUnique(sourceOwners, candidate.repo?.owner));
@@ -511,46 +566,72 @@ const findFirstMatchingPr = async ({ octokit, target, branch, sourceCandidates,
511
566
  .filter((pr) => matcher.matches(pr, target.repo.repo))
512
567
  .sort((left, right) => matcher.compare(left, right, target.repo.repo))[0] ?? null;
513
568
 
514
- for (const state of ['open', 'closed']) {
515
- // Shared per-repo list first: one pulls.list answers every branch of the
516
- // repo within the TTL. A miss in a complete list is authoritative — skip
517
- // the per-branch query fan entirely.
518
- let listWasComplete = false;
519
- try {
520
- const listEntry = await getRepoPulls(octokit, target.repo, state, { force });
521
- const fromList = pickPreferred(listEntry.prs);
522
- if (fromList) {
523
- return fromList;
524
- }
525
- listWasComplete = listEntry.complete;
526
- } catch {
527
- // fall through to the precise per-branch queries
528
- }
529
- if (listWasComplete) {
530
- continue;
569
+ // The shared repo-level open list answers every branch of the repo within the
570
+ // TTL. A miss in a complete list is authoritative: no open PR exists here.
571
+ let openListWasComplete = false;
572
+ try {
573
+ const listEntry = await getRepoPulls(octokit, target.repo, 'open', { force });
574
+ const fromList = pickPreferred(listEntry.prs);
575
+ if (fromList) {
576
+ return { open: fromList, historical: null };
531
577
  }
532
- if (coverage) {
533
- coverage.authoritative = false;
578
+ openListWasComplete = listEntry.complete;
579
+ } catch {
580
+ // fall through to the precise per-head queries
581
+ }
582
+
583
+ if (!openListWasComplete && coverage) {
584
+ coverage.authoritative = false;
585
+ }
586
+
587
+ // A complete open list already proved there is no open PR in this repo. With
588
+ // no history to look up there is nothing left to ask GitHub.
589
+ if (openListWasComplete && !includeHistory) {
590
+ return { open: null, historical: null };
591
+ }
592
+
593
+ const historicalKey = `${normalizeRepoKey(target.repo?.owner, target.repo?.repo)}::${branch}`;
594
+ if (includeHistory && !force && openListWasComplete) {
595
+ const cached = _historicalPrCache.get(historicalKey);
596
+ if (isHistoricalPrCacheFresh(cached)) {
597
+ return { open: null, historical: cached.pr };
534
598
  }
599
+ }
535
600
 
536
- for (const owner of sourceOwners) {
537
- const directCandidates = await safeListPulls(octokit, {
538
- owner: target.repo.owner,
539
- repo: target.repo.repo,
540
- state,
541
- head: `${owner}:${branch}`,
542
- per_page: 100,
543
- });
544
- const direct = pickPreferred(directCandidates);
545
- if (direct) {
546
- return direct;
547
- }
601
+ // One query per source owner. With history enabled `state: 'all'` answers
602
+ // both questions at once, so asking for history never costs an extra call.
603
+ let historical = null;
604
+ for (const owner of sourceOwners) {
605
+ const directCandidates = await safeListPulls(octokit, {
606
+ owner: target.repo.owner,
607
+ repo: target.repo.repo,
608
+ state: includeHistory ? 'all' : 'open',
609
+ head: `${owner}:${branch}`,
610
+ per_page: 100,
611
+ });
612
+ const openMatch = pickPreferred(directCandidates.filter((pr) => !isTerminalPr(pr)));
613
+ if (openMatch) {
614
+ return { open: openMatch, historical: null };
615
+ }
616
+ if (includeHistory && !historical) {
617
+ // Among past PRs for the same head the newest one is the relevant record.
618
+ historical = directCandidates
619
+ .filter((pr) => normalizeText(pr?.head?.ref) === branch)
620
+ .filter((pr) => matcher.matches(pr, target.repo.repo))
621
+ .filter(isTerminalPr)
622
+ .sort((left, right) => (right?.number ?? 0) - (left?.number ?? 0))[0] ?? null;
548
623
  }
549
624
  }
550
625
 
551
- return null;
626
+ if (includeHistory) {
627
+ rememberHistoricalPr(historicalKey, historical);
628
+ }
629
+ return { open: null, historical };
552
630
  };
553
631
 
632
+ // Exported for focused unit tests of open-versus-historical branch matching.
633
+ export { findBranchPrCandidates };
634
+
554
635
  export async function resolveGitHubPrStatus({ octokit, directory, branch, remoteName, force = false }) {
555
636
  // A deleted worktree can still have a session in the sidebar that keeps
556
637
  // requesting its PR status. Bail before touching git or GitHub for a
@@ -602,6 +683,11 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
602
683
  let fallbackRemoteName = resolvedTargets[0].remoteName;
603
684
  let fallbackDefaultBranch = await getRepoDefaultBranch(octokit, fallbackRepo);
604
685
 
686
+ // The first closed/merged PR found, in target priority order. It is only
687
+ // returned once every target has been checked for an open PR, so an open
688
+ // upstream PR always wins over a merged fork PR for the same head.
689
+ let historicalMatch = null;
690
+
605
691
  for (const target of resolvedTargets) {
606
692
  const defaultBranch = await getRepoDefaultBranch(octokit, target.repo);
607
693
  if (!fallbackRepo) {
@@ -616,18 +702,33 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
616
702
  continue;
617
703
  }
618
704
 
619
- const pr = await findFirstMatchingPr({
705
+ // History is only asked of the branch's own repo and its own name: the
706
+ // ranked-first target is the remote this branch actually pushes to.
707
+ // Searching the rest of the fork network for history would multiply
708
+ // serial GitHub calls for no additional user-visible information.
709
+ const isPrimaryAssociation = target === resolvedTargets[0] && candidateBranch === branchCandidates[0];
710
+
711
+ const { open, historical } = await findBranchPrCandidates({
620
712
  octokit,
621
713
  target,
622
714
  branch: candidateBranch,
623
715
  sourceCandidates,
624
716
  force,
625
717
  coverage,
718
+ includeHistory: isPrimaryAssociation,
626
719
  });
627
- if (pr) {
720
+ if (open) {
628
721
  return {
629
722
  repo: target.repo,
630
- pr,
723
+ pr: open,
724
+ defaultBranch,
725
+ resolvedRemoteName: target.remoteName,
726
+ };
727
+ }
728
+ if (historical && !historicalMatch) {
729
+ historicalMatch = {
730
+ repo: target.repo,
731
+ pr: historical,
631
732
  defaultBranch,
632
733
  resolvedRemoteName: target.remoteName,
633
734
  };
@@ -654,6 +755,10 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
654
755
  }
655
756
  }
656
757
 
758
+ if (historicalMatch) {
759
+ return historicalMatch;
760
+ }
761
+
657
762
  return {
658
763
  repo: fallbackRepo,
659
764
  pr: null,
@@ -0,0 +1,182 @@
1
+ import { afterEach, beforeEach, describe, expect, mock, test, vi } from 'bun:test';
2
+
3
+ const listMock = mock(async () => ({ data: [] }));
4
+
5
+ mock.module('../git/index.js', () => ({
6
+ getRemotes: async () => [],
7
+ getStatus: async () => null,
8
+ }));
9
+
10
+ mock.module('./repo/index.js', () => ({
11
+ resolveGitHubRepoFromDirectory: async () => null,
12
+ }));
13
+
14
+ mock.module('./rate-limit.js', () => ({
15
+ noteIfGitHubRateLimit: () => {},
16
+ }));
17
+
18
+ const { findBranchPrCandidates, invalidateRepoPullsCache } = await import('./pr-status.js');
19
+
20
+ const openPr = {
21
+ number: 15,
22
+ state: 'open',
23
+ head: {
24
+ ref: 'feature',
25
+ label: 'acme:feature',
26
+ user: { login: 'acme' },
27
+ repo: { owner: { login: 'acme' }, name: 'app' },
28
+ },
29
+ };
30
+
31
+ const mergedPr = {
32
+ number: 12,
33
+ state: 'closed',
34
+ merged_at: '2026-01-01T00:00:00Z',
35
+ head: {
36
+ ref: 'feature',
37
+ label: 'acme:feature',
38
+ user: { login: 'acme' },
39
+ repo: { owner: { login: 'acme' }, name: 'app' },
40
+ },
41
+ };
42
+
43
+ const olderMergedPr = {
44
+ ...mergedPr,
45
+ number: 7,
46
+ merged_at: '2025-11-01T00:00:00Z',
47
+ };
48
+
49
+ const call = (overrides = {}) => findBranchPrCandidates({
50
+ octokit: { rest: { pulls: { list: listMock } } },
51
+ target: { repo: { owner: 'acme', repo: 'app' }, remoteName: 'origin' },
52
+ branch: 'feature',
53
+ sourceCandidates: [{ repo: { owner: 'acme', repo: 'app' } }],
54
+ force: true,
55
+ includeHistory: true,
56
+ ...overrides,
57
+ });
58
+
59
+ describe('findBranchPrCandidates', () => {
60
+ beforeEach(() => {
61
+ listMock.mockReset();
62
+ invalidateRepoPullsCache('acme', 'app');
63
+ });
64
+
65
+ afterEach(() => {
66
+ vi.useRealTimers();
67
+ });
68
+
69
+ test('an open PR wins and no history lookup is spent', async () => {
70
+ listMock.mockImplementation(async ({ state }) => (
71
+ state === 'open' ? { data: [openPr] } : { data: [mergedPr] }
72
+ ));
73
+
74
+ const { open, historical } = await call();
75
+
76
+ expect(open?.number).toBe(15);
77
+ expect(historical).toBeNull();
78
+ expect(listMock.mock.calls.every((entry) => entry[0]?.state === 'open')).toBe(true);
79
+ });
80
+
81
+ test('an open PR still wins when the shared open list missed it', async () => {
82
+ // A repo with more than one page of open PRs: the shared list is incomplete,
83
+ // so the per-head query is the one that must find the open PR.
84
+ listMock.mockImplementation(async ({ head }) => (
85
+ head ? { data: [mergedPr, openPr] } : { data: new Array(100).fill(null).map((_, index) => ({ number: index, state: 'open', head: { ref: 'other' } })) }
86
+ ));
87
+
88
+ const { open, historical } = await call();
89
+
90
+ expect(open?.number).toBe(15);
91
+ expect(historical).toBeNull();
92
+ });
93
+
94
+ test('returns the branch history when no open PR exists', async () => {
95
+ listMock.mockImplementation(async ({ head }) => (
96
+ head ? { data: [olderMergedPr, mergedPr] } : { data: [] }
97
+ ));
98
+
99
+ const { open, historical } = await call();
100
+
101
+ expect(open).toBeNull();
102
+ // The newest past PR for the head is the relevant record.
103
+ expect(historical?.number).toBe(12);
104
+ });
105
+
106
+ test('returns no history for a branch that never had a PR', async () => {
107
+ listMock.mockImplementation(async () => ({ data: [] }));
108
+
109
+ const { open, historical } = await call();
110
+
111
+ expect(open).toBeNull();
112
+ expect(historical).toBeNull();
113
+ expect(listMock.mock.calls.some((entry) => entry[0]?.state === 'all')).toBe(true);
114
+ });
115
+
116
+ test('spends no call on history for a secondary target', async () => {
117
+ listMock.mockImplementation(async ({ head }) => (
118
+ head ? { data: [mergedPr] } : { data: [] }
119
+ ));
120
+
121
+ const { open, historical } = await call({ includeHistory: false });
122
+
123
+ expect(open).toBeNull();
124
+ expect(historical).toBeNull();
125
+ // The complete open list already answered the only question that matters
126
+ // for a secondary repo in the fork network.
127
+ expect(listMock.mock.calls).toHaveLength(1);
128
+ expect(listMock.mock.calls[0]?.[0]?.state).toBe('open');
129
+ });
130
+
131
+ test('reuses the cached history instead of re-querying every poll', async () => {
132
+ listMock.mockImplementation(async ({ head }) => (
133
+ head ? { data: [mergedPr] } : { data: [] }
134
+ ));
135
+
136
+ await call();
137
+ const callsAfterFirst = listMock.mock.calls.length;
138
+
139
+ // A non-forced poll is answered entirely from the shared open list cache
140
+ // plus the remembered history — no extra GitHub call.
141
+ const { open, historical } = await call({ force: false });
142
+
143
+ expect(open).toBeNull();
144
+ expect(historical?.number).toBe(12);
145
+ expect(listMock.mock.calls.length).toBe(callsAfterFirst);
146
+ });
147
+
148
+ test('a found record outlives the shorter "no history" window', async () => {
149
+ const startedAt = Date.now();
150
+ listMock.mockImplementation(async ({ head }) => (
151
+ head ? { data: [mergedPr] } : { data: [] }
152
+ ));
153
+
154
+ await call();
155
+ const callsAfterFirst = listMock.mock.calls.length;
156
+
157
+ // Past the "no history" expiry, but far short of the found-record one. The
158
+ // shared open list is re-fetched; the history answer is not re-queried.
159
+ vi.useFakeTimers();
160
+ vi.setSystemTime(new Date(startedAt + 30 * 60 * 1000));
161
+ const { historical } = await call({ force: false });
162
+
163
+ expect(historical?.number).toBe(12);
164
+ expect(listMock.mock.calls.length).toBe(callsAfterFirst + 1);
165
+ expect(listMock.mock.calls.at(-1)?.[0]?.state).toBe('open');
166
+ });
167
+
168
+ test('re-queries a branch with no history once its shorter window passes', async () => {
169
+ const startedAt = Date.now();
170
+ listMock.mockImplementation(async () => ({ data: [] }));
171
+
172
+ await call();
173
+ const callsAfterFirst = listMock.mock.calls.length;
174
+
175
+ vi.useFakeTimers();
176
+ vi.setSystemTime(new Date(startedAt + 30 * 60 * 1000));
177
+ await call({ force: false });
178
+
179
+ expect(listMock.mock.calls.some((entry) => entry[0]?.state === 'all')).toBe(true);
180
+ expect(listMock.mock.calls.length).toBeGreaterThan(callsAfterFirst + 1);
181
+ });
182
+ });
@@ -574,10 +574,17 @@ export function registerGitHubRoutes(app) {
574
574
  return res.json({ connected: true, repo: searchRepo, branch, pr: null, checks: null, canMerge: false });
575
575
  }
576
576
 
577
+ const isMerged = Boolean(prData.merged || prData.merged_at);
578
+ const prState = isMerged ? 'merged' : (prData.state === 'closed' ? 'closed' : 'open');
579
+ // A closed/merged PR is a historical record for this branch: its checks
580
+ // are no longer actionable and it can never be merged from here, so skip
581
+ // the extra GitHub calls those two fields would cost.
582
+ const isHistorical = prState !== 'open';
583
+
577
584
  // Checks summary: prefer check-runs (Actions), fallback to classic statuses.
578
585
  let checks = null;
579
586
  const sha = prData.head?.sha;
580
- if (sha) {
587
+ if (sha && !isHistorical) {
581
588
  try {
582
589
  const runs = await octokit.rest.checks.listForRef({
583
590
  owner: searchRepo.owner,
@@ -610,38 +617,37 @@ export function registerGitHubRoutes(app) {
610
617
 
611
618
  // Permission check (best-effort)
612
619
  let canMerge = false;
613
- try {
614
- const auth = getGitHubAuth();
615
- // gh-CLI tokens have no persisted user record; resolve the login from
616
- // the API once (memoized) so permissions still resolve for them.
617
- let username = auth?.user?.login;
618
- if (!username) {
619
- if (!resolvedAuthLoginPromise) {
620
- resolvedAuthLoginPromise = octokit.rest.users.getAuthenticated()
621
- .then((resp) => resp?.data?.login || null)
622
- .catch(() => {
623
- resolvedAuthLoginPromise = null;
624
- return null;
625
- });
620
+ if (!isHistorical) {
621
+ try {
622
+ const auth = getGitHubAuth();
623
+ // gh-CLI tokens have no persisted user record; resolve the login from
624
+ // the API once (memoized) so permissions still resolve for them.
625
+ let username = auth?.user?.login;
626
+ if (!username) {
627
+ if (!resolvedAuthLoginPromise) {
628
+ resolvedAuthLoginPromise = octokit.rest.users.getAuthenticated()
629
+ .then((resp) => resp?.data?.login || null)
630
+ .catch(() => {
631
+ resolvedAuthLoginPromise = null;
632
+ return null;
633
+ });
634
+ }
635
+ username = await resolvedAuthLoginPromise;
626
636
  }
627
- username = await resolvedAuthLoginPromise;
628
- }
629
- if (username) {
630
- const perm = await octokit.rest.repos.getCollaboratorPermissionLevel({
631
- owner: searchRepo.owner,
632
- repo: searchRepo.repo,
633
- username,
634
- });
635
- const level = perm?.data?.permission;
636
- canMerge = level === 'admin' || level === 'maintain' || level === 'write';
637
+ if (username) {
638
+ const perm = await octokit.rest.repos.getCollaboratorPermissionLevel({
639
+ owner: searchRepo.owner,
640
+ repo: searchRepo.repo,
641
+ username,
642
+ });
643
+ const level = perm?.data?.permission;
644
+ canMerge = level === 'admin' || level === 'maintain' || level === 'write';
645
+ }
646
+ } catch {
647
+ canMerge = false;
637
648
  }
638
- } catch {
639
- canMerge = false;
640
649
  }
641
650
 
642
- const isMerged = Boolean(prData.merged || prData.merged_at);
643
- const mergedState = isMerged ? 'merged' : (prData.state === 'closed' ? 'closed' : 'open');
644
-
645
651
  return res.json({
646
652
  connected: true,
647
653
  repo: searchRepo,
@@ -651,7 +657,7 @@ export function registerGitHubRoutes(app) {
651
657
  title: prData.title,
652
658
  body: prData.body || '',
653
659
  url: prData.html_url,
654
- state: mergedState,
660
+ state: prState,
655
661
  draft: Boolean(prData.draft),
656
662
  base: prData.base?.ref,
657
663
  head: prData.head?.ref,
@@ -27,9 +27,8 @@ export const createNotificationTemplateRuntime = (deps) => {
27
27
 
28
28
  const formatProjectLabel = (label) => {
29
29
  if (!label || typeof label !== 'string') return '';
30
- return label
31
- .replace(/[-_]/g, ' ')
32
- .replace(/\b\w/g, (char) => char.toUpperCase());
30
+ // Folder names are shown exactly as they are on disk — no title-casing.
31
+ return label.trim();
33
32
  };
34
33
 
35
34
  const resolveNotificationTemplate = (template, variables) => {