@openchamber/web 1.24.1 → 2.0.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 (442) hide show
  1. package/bin/cli.test.js +22 -0
  2. package/bin/lib/commands-connect-url.js +3 -8
  3. package/bin/lib/commands-status.js +5 -0
  4. package/bin/lib/commands-tunnel.js +3 -0
  5. package/dist/assets/{CodeMirrorCommentWidgets-DvUH815P.js → CodeMirrorCommentWidgets-hJbl3JX4.js} +1 -1
  6. package/dist/assets/DiffView-BucGEJYa.js +4 -0
  7. package/dist/assets/FilesView-CQcaaAVP.js +17 -0
  8. package/dist/assets/{GitView-Bxuv3dfP.js → GitView-DY4pelsO.js} +4 -4
  9. package/dist/assets/{GuestAttachDialog-B0u3Q5uO.js → GuestAttachDialog-D6mHDTB2.js} +1 -1
  10. package/dist/assets/GuestSurfacePane--DJ7rsmY.js +1 -0
  11. package/dist/assets/{JsonTreeView-BBVPFM5K.js → JsonTreeView-DEXI2NvJ.js} +1 -1
  12. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  13. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  14. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  15. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  16. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  17. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  18. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  19. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  20. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  21. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  22. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  23. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  24. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  25. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  26. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  27. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  30. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  31. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  32. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  33. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  34. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  35. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  36. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  37. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  38. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  39. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  40. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  41. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  42. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  43. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  44. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  45. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  47. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  48. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  49. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  50. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  51. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  52. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  53. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  54. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  55. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  56. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  57. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  58. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  59. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  60. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  61. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  62. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  63. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  64. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  65. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  66. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  67. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  69. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  70. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  71. package/dist/assets/LinearIssuesView-BTNc-4dN.js +1 -0
  72. package/dist/assets/MarkdownImageGallery-wcUUcf8l.js +1 -0
  73. package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +12 -0
  74. package/dist/assets/OnboardingScreen-FJUreEgI.js +1 -0
  75. package/dist/assets/{PatchDiff-C4rE5k6z.js → PatchDiff-C0oOkKnO.js} +1 -1
  76. package/dist/assets/PierreDiffViewer-asuSQAsf.js +210 -0
  77. package/dist/assets/PlanView-DGbasNHP.js +5 -0
  78. package/dist/assets/PluginPane-DImv8hV2.js +3 -0
  79. package/dist/assets/SettingsView-DOjuOljf.js +29 -0
  80. package/dist/assets/SettingsWindow-By4cqnqy.js +1 -0
  81. package/dist/assets/SubmoduleDiffSummary-C0P2tXLU.js +1 -0
  82. package/dist/assets/ToolOutputDialog-Cayc-yIM.js +15 -0
  83. package/dist/assets/ToolPartDiffPreview-B0jmpPQz.js +8 -0
  84. package/dist/assets/{VirtualizedFileDiff-CZgXWHjU.js → VirtualizedFileDiff-DsOpvWZD.js} +4 -4
  85. package/dist/assets/{WalkthroughView-wSpED5L4.js → WalkthroughView-CCakjyn9.js} +2 -2
  86. package/dist/assets/appThemeRegistry-Bw5oTm41.js +1 -0
  87. package/dist/assets/{commitAndPush-DZnzlhvc.js → commitAndPush-sGEelpjh.js} +1 -1
  88. package/dist/assets/{computeVirtualFileMetrics-VYnT_A2h.js → computeVirtualFileMetrics-B-4aLf4A.js} +1 -1
  89. package/dist/assets/de-CD9utsNj.js +10 -0
  90. package/dist/assets/es-NNum2rX8.js +16 -0
  91. package/dist/assets/fr-CJLGmduQ.js +14 -0
  92. package/dist/assets/index-B6r0Kv-B.js +1 -0
  93. package/dist/assets/index-DjGPR5vW.js +41 -0
  94. package/dist/assets/index-fCXJ-8Qt.css +1 -0
  95. package/dist/assets/{isDiffPlainText-ImDG3Uhg.js → isDiffPlainText-Ok-kgtJA.js} +1 -1
  96. package/dist/assets/{isFilePlainText-D_YDVYDb.js → isFilePlainText-0dLnkYm8.js} +1 -1
  97. package/dist/assets/ja-BuddHNi6.js +16 -0
  98. package/dist/assets/ko-BrwMbHmf.js +16 -0
  99. package/dist/assets/main-CjXBM_Xe.js +2 -0
  100. package/dist/assets/main-CxVyUDU_.js +896 -0
  101. package/dist/assets/markdownCore-B6PpX409.js +5 -0
  102. package/dist/assets/miniChat-DZ3OAeLN.js +2 -0
  103. package/dist/assets/mobile-CH0LOIF-.js +2 -0
  104. package/dist/assets/{patchFileDiff-DDQ6Rq5e.js → patchFileDiff-BFRGKaGH.js} +3 -3
  105. package/dist/assets/pl-BwN4TNlP.js +16 -0
  106. package/dist/assets/pt-BR-BhMtownO.js +16 -0
  107. package/dist/assets/renderElectronMiniChatApp-CB1uLYvh.js +2 -0
  108. package/dist/assets/renderMobileApp-nQ4sjQtb.js +25 -0
  109. package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +27 -0
  110. package/dist/assets/scheduledTasksApi-6DsL_SwM.js +1 -0
  111. package/dist/assets/{shikiHighlight-1imXsir9.js → shikiHighlight-CocY80VR.js} +1 -1
  112. package/dist/assets/{textMateThemeFromAppTheme-Dgqc63LZ.js → textMateThemeFromAppTheme-CF77r8FA.js} +1 -1
  113. package/dist/assets/tr-DRzvqMdi.js +7 -0
  114. package/dist/assets/uk-b2aYOSNh.js +16 -0
  115. package/dist/assets/useAppFontEffects-Dc5nTHi8.js +7337 -0
  116. package/dist/assets/useInlineCommentController-Dbza5c8l.js +2 -0
  117. package/dist/assets/useRootScrollLock-CSCLv396.js +2 -0
  118. package/dist/assets/{vendor-codemirror-language-data-BDyxuqK4.js → vendor-codemirror-language-data-CkmYWcRI.js} +2 -2
  119. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  120. package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
  121. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
  122. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  123. package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-Gea9uBlY.js} +4 -4
  124. package/dist/assets/{web-components-D7FinaeH.js → web-components-nsStrYq9.js} +2 -2
  125. package/dist/assets/zh-CN-DZeUThm_.js +16 -0
  126. package/dist/assets/zh-TW-2fRE7uc6.js +16 -0
  127. package/dist/index.html +15 -7
  128. package/dist/mini-chat.html +7 -5
  129. package/dist/mobile.html +7 -5
  130. package/package.json +8 -7
  131. package/server/index.d.ts +1 -0
  132. package/server/index.js +248 -90
  133. package/server/lib/agent-tool/DOCUMENTATION.md +45 -15
  134. package/server/lib/agent-tool/runtime.js +189 -61
  135. package/server/lib/agent-tool/runtime.test.js +229 -75
  136. package/server/lib/browser-control/DOCUMENTATION.md +37 -2
  137. package/server/lib/browser-control/provider.js +217 -0
  138. package/server/lib/browser-control/provider.test.js +251 -0
  139. package/server/lib/context-obligatory/runtime.js +61 -50
  140. package/server/lib/context-obligatory/runtime.test.js +62 -162
  141. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  142. package/server/lib/event-stream/delta-coalescer.js +0 -0
  143. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  144. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  145. package/server/lib/event-stream/global-hub.js +10 -1
  146. package/server/lib/event-stream/global-hub.test.js +27 -26
  147. package/server/lib/event-stream/index.js +6 -0
  148. package/server/lib/event-stream/protocol.js +26 -19
  149. package/server/lib/event-stream/protocol.test.js +18 -7
  150. package/server/lib/event-stream/rebind.test.js +5 -5
  151. package/server/lib/event-stream/runtime.test.js +17 -15
  152. package/server/lib/event-stream/translate-v2.js +313 -0
  153. package/server/lib/event-stream/translate-v2.test.js +209 -0
  154. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  155. package/server/lib/fs/DOCUMENTATION.md +6 -3
  156. package/server/lib/fs/byte-range.js +35 -0
  157. package/server/lib/fs/byte-range.test.js +31 -0
  158. package/server/lib/fs/routes.js +103 -46
  159. package/server/lib/fs/routes.test.js +239 -18
  160. package/server/lib/git/DOCUMENTATION.md +2 -2
  161. package/server/lib/git/service.js +106 -9
  162. package/server/lib/git/service.test.js +18 -0
  163. package/server/lib/github/DOCUMENTATION.md +1 -1
  164. package/server/lib/github/pr-status.js +22 -2
  165. package/server/lib/github/pr-status.test.js +27 -14
  166. package/server/lib/guests/DOCUMENTATION.md +13 -0
  167. package/server/lib/guests/catalog.js +12 -0
  168. package/server/lib/guests/catalog.test.js +33 -0
  169. package/server/lib/guests/routes.js +10 -1
  170. package/server/lib/guests/service.js +192 -14
  171. package/server/lib/guests/service.test.js +201 -1
  172. package/server/lib/guests/surface.js +630 -0
  173. package/server/lib/guests/surface.test.js +486 -0
  174. package/server/lib/markdown-image-grants/routes.js +18 -5
  175. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  176. package/server/lib/message-queue/DOCUMENTATION.md +36 -22
  177. package/server/lib/message-queue/runtime.js +170 -100
  178. package/server/lib/message-queue/runtime.test.js +184 -82
  179. package/server/lib/notifications/DOCUMENTATION.md +28 -0
  180. package/server/lib/notifications/control-stream.http.test.js +68 -0
  181. package/server/lib/notifications/emitter-runtime.js +15 -0
  182. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  183. package/server/lib/notifications/push-runtime.js +5 -1
  184. package/server/lib/notifications/push-runtime.test.js +2 -2
  185. package/server/lib/notifications/routes.js +5 -0
  186. package/server/lib/notifications/runtime.js +115 -26
  187. package/server/lib/notifications/template-runtime.js +13 -15
  188. package/server/lib/notifications/template-runtime.test.js +16 -9
  189. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  190. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  191. package/server/lib/openchamber-control/actions.js +3 -2
  192. package/server/lib/openchamber-control/error.js +1 -1
  193. package/server/lib/openchamber-control/file-open.js +59 -0
  194. package/server/lib/openchamber-control/file-open.test.js +57 -0
  195. package/server/lib/openchamber-control/routes.test.js +12 -0
  196. package/server/lib/openchamber-control/service.js +102 -49
  197. package/server/lib/openchamber-control/service.test.js +84 -44
  198. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  199. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  200. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  201. package/server/lib/openchamber-sessions/routes.js +398 -328
  202. package/server/lib/openchamber-sessions/routes.test.js +786 -700
  203. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  204. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  205. package/server/lib/opencode/DOCUMENTATION.md +450 -30
  206. package/server/lib/opencode/agents.js +233 -327
  207. package/server/lib/opencode/auth.js +41 -44
  208. package/server/lib/opencode/auth.test.js +92 -0
  209. package/server/lib/opencode/bootstrap-runtime.js +1 -0
  210. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  211. package/server/lib/opencode/cli-upgrade.js +18 -0
  212. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  213. package/server/lib/opencode/commands.js +164 -145
  214. package/server/lib/opencode/compatibility.d.ts +16 -0
  215. package/server/lib/opencode/compatibility.js +88 -0
  216. package/server/lib/opencode/compatibility.test.js +62 -0
  217. package/server/lib/opencode/config-entity-routes.js +58 -29
  218. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  219. package/server/lib/opencode/config-mutation-response.js +17 -7
  220. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  221. package/server/lib/opencode/config-paths.test.js +2 -2
  222. package/server/lib/opencode/config-v2.d.ts +183 -0
  223. package/server/lib/opencode/config-v2.js +801 -0
  224. package/server/lib/opencode/config-v2.test.js +466 -0
  225. package/server/lib/opencode/credential-db.js +144 -0
  226. package/server/lib/opencode/credential-db.test.js +104 -0
  227. package/server/lib/opencode/env-runtime.js +48 -9
  228. package/server/lib/opencode/env-runtime.test.js +45 -0
  229. package/server/lib/opencode/feature-routes-runtime.js +15 -5
  230. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  231. package/server/lib/opencode/lifecycle.js +85 -30
  232. package/server/lib/opencode/lifecycle.test.js +80 -8
  233. package/server/lib/opencode/login-shell-env.js +27 -0
  234. package/server/lib/opencode/managed-config-file.js +119 -0
  235. package/server/lib/opencode/managed-config-file.test.js +152 -0
  236. package/server/lib/opencode/managed-plugin-config.js +33 -13
  237. package/server/lib/opencode/mcp.js +43 -149
  238. package/server/lib/opencode/network-runtime.js +6 -7
  239. package/server/lib/opencode/openchamber-routes.test.js +0 -1
  240. package/server/lib/opencode/plugin-routes.js +3 -3
  241. package/server/lib/opencode/plugin-routes.test.js +6 -24
  242. package/server/lib/opencode/plugins.js +91 -40
  243. package/server/lib/opencode/plugins.test.js +28 -15
  244. package/server/lib/opencode/providers.js +63 -83
  245. package/server/lib/opencode/providers.test.js +128 -59
  246. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  247. package/server/lib/opencode/proxy.js +179 -129
  248. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  249. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  250. package/server/lib/opencode/response-envelope.js +14 -0
  251. package/server/lib/opencode/response-envelope.test.js +23 -0
  252. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  253. package/server/lib/opencode/routes.js +121 -428
  254. package/server/lib/opencode/server-utils-runtime.js +10 -4
  255. package/server/lib/opencode/session-activity.js +78 -0
  256. package/server/lib/opencode/session-runtime.js +79 -0
  257. package/server/lib/opencode/session-runtime.test.js +43 -0
  258. package/server/lib/opencode/settings-helpers.js +9 -9
  259. package/server/lib/opencode/settings-helpers.test.js +7 -12
  260. package/server/lib/opencode/settings-registry.json +6 -8
  261. package/server/lib/opencode/settings-runtime.js +18 -1
  262. package/server/lib/opencode/settings-runtime.test.js +31 -2
  263. package/server/lib/opencode/shared.js +54 -22
  264. package/server/lib/opencode/shared.test.js +8 -4
  265. package/server/lib/opencode/shutdown-runtime.js +54 -7
  266. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  267. package/server/lib/opencode/skill-routes.js +23 -24
  268. package/server/lib/opencode/skills.js +7 -5
  269. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  270. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  271. package/server/lib/opencode/v1-migration-topup.js +288 -0
  272. package/server/lib/opencode/v1-migration-topup.test.js +266 -0
  273. package/server/lib/opencode/v2-install.d.ts +8 -0
  274. package/server/lib/opencode/v2-install.js +158 -0
  275. package/server/lib/opencode/v2-install.test.js +124 -0
  276. package/server/lib/opencode/watcher.js +10 -3
  277. package/server/lib/opencode/watcher.test.js +17 -21
  278. package/server/lib/opencode/websearch-config.js +66 -0
  279. package/server/lib/permission-auto-accept/runtime.js +38 -22
  280. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  281. package/server/lib/projects/project-config.js +2 -2
  282. package/server/lib/quota/DOCUMENTATION.md +4 -0
  283. package/server/lib/quota/providers/xai.js +4 -4
  284. package/server/lib/realtime-proxy-terminal.test.js +150 -0
  285. package/server/lib/realtime-proxy.js +2 -0
  286. package/server/lib/relay/tunnel-host.js +4 -1
  287. package/server/lib/relay/tunnel-host.test.js +7 -0
  288. package/server/lib/routing/DOCUMENTATION.md +52 -19
  289. package/server/lib/routing/defaults.js +23 -6
  290. package/server/lib/routing/jev.js +17 -7
  291. package/server/lib/routing/routes.http.test.js +68 -33
  292. package/server/lib/routing/routes.js +65 -22
  293. package/server/lib/routing/runtime.js +145 -48
  294. package/server/lib/routing/runtime.test.js +79 -55
  295. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  296. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  297. package/server/lib/scheduled-tasks/runtime.js +83 -76
  298. package/server/lib/scheduled-tasks/runtime.test.js +67 -1
  299. package/server/lib/session-assist/DOCUMENTATION.md +8 -3
  300. package/server/lib/session-assist/context.js +122 -46
  301. package/server/lib/session-assist/context.test.js +117 -49
  302. package/server/lib/session-assist/runtime.js +52 -22
  303. package/server/lib/session-assist/runtime.test.js +145 -173
  304. package/server/lib/session-goal/DOCUMENTATION.md +23 -15
  305. package/server/lib/session-goal/create.js +9 -12
  306. package/server/lib/session-goal/create.test.js +27 -28
  307. package/server/lib/session-goal/runtime.js +164 -77
  308. package/server/lib/session-goal/runtime.test.js +271 -519
  309. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  310. package/server/lib/session-knowledge/runtime.js +59 -41
  311. package/server/lib/session-knowledge/runtime.test.js +90 -20
  312. package/server/lib/small-model/DOCUMENTATION.md +154 -196
  313. package/server/lib/small-model/client.js +113 -0
  314. package/server/lib/small-model/index.js +296 -158
  315. package/server/lib/small-model/index.test.js +423 -256
  316. package/server/lib/small-model/routes.js +1 -1
  317. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  318. package/server/lib/spaces/code-in-bait.js +185 -0
  319. package/server/lib/spaces/code-in.js +641 -0
  320. package/server/lib/spaces/code-in.test.js +1048 -0
  321. package/server/lib/spaces/errors.js +8 -0
  322. package/server/lib/spaces/exec-http.js +94 -0
  323. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  324. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  325. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  326. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  327. package/server/lib/spaces/hardening.js +457 -0
  328. package/server/lib/spaces/hardening.test.js +368 -0
  329. package/server/lib/spaces/host-git.js +127 -0
  330. package/server/lib/spaces/host-git.test.js +137 -0
  331. package/server/lib/spaces/labels.js +234 -0
  332. package/server/lib/spaces/labels.test.js +219 -0
  333. package/server/lib/spaces/layout.js +184 -0
  334. package/server/lib/spaces/layout.test.js +30 -0
  335. package/server/lib/spaces/manager.js +82 -0
  336. package/server/lib/spaces/manager.test.js +114 -0
  337. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  338. package/server/lib/spaces/places/contract-suite.js +156 -0
  339. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  340. package/server/lib/spaces/places/contract.test.js +6 -0
  341. package/server/lib/spaces/places/docker-engine.js +126 -0
  342. package/server/lib/spaces/places/docker-live-support.js +202 -0
  343. package/server/lib/spaces/places/docker-tools.js +186 -0
  344. package/server/lib/spaces/places/docker.js +587 -0
  345. package/server/lib/spaces/places/docker.test.js +1610 -0
  346. package/server/lib/spaces/places/escape-suite.js +1018 -0
  347. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  348. package/server/lib/spaces/places/fake-docker.js +375 -0
  349. package/server/lib/spaces/places/memory-place.js +103 -0
  350. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  351. package/server/lib/spaces/places/registry.js +43 -0
  352. package/server/lib/spaces/places/registry.test.js +50 -0
  353. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  354. package/server/lib/spaces/run-command.js +261 -0
  355. package/server/lib/spaces/run-command.test.js +396 -0
  356. package/server/lib/spaces/space-server.js +190 -0
  357. package/server/lib/spaces/space-server.test.js +335 -0
  358. package/server/lib/spaces/tools-filler.js +82 -0
  359. package/server/lib/spaces/tools-filler.test.js +148 -0
  360. package/server/lib/spaces/tools-pack.js +49 -0
  361. package/server/lib/spaces/tools-pack.test.js +57 -0
  362. package/server/lib/spaces/tools.js +137 -0
  363. package/server/lib/spaces/tools.test.js +153 -0
  364. package/server/lib/terminal/DOCUMENTATION.md +21 -2
  365. package/server/lib/terminal/runtime.js +10 -3
  366. package/server/lib/terminal/runtime.test.js +22 -0
  367. package/server/lib/terminal/shutdown.js +106 -0
  368. package/server/lib/terminal/shutdown.test.js +84 -0
  369. package/server/lib/tts/openai-sdk.js +11 -0
  370. package/server/lib/tts/service.js +7 -5
  371. package/server/lib/tts/service.test.js +78 -0
  372. package/server/lib/tts/stt.js +3 -2
  373. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  374. package/server/lib/tunnels/routes.js +7 -0
  375. package/server/lib/tunnels/routes.test.js +55 -0
  376. package/server/lib/ui-auth/ui-auth.js +38 -2
  377. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  378. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  379. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  380. package/server/lib/walkthrough/pull-request.js +61 -8
  381. package/server/lib/walkthrough/pull-request.test.js +54 -1
  382. package/server/lib/walkthrough/routes.js +20 -0
  383. package/server/lib/walkthrough/routes.test.js +19 -0
  384. package/server/opencode-proxy.test.js +190 -166
  385. package/server/opencode-worktree-readiness.test.js +5 -4
  386. package/dist/assets/DiffView-DkC3xlRJ.js +0 -4
  387. package/dist/assets/FilesView-D0bM9FVB.js +0 -13
  388. package/dist/assets/LinearIssuesView-UI1FcSC8.js +0 -1
  389. package/dist/assets/MarkdownImageGallery-CUJxH8Le.js +0 -1
  390. package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +0 -12
  391. package/dist/assets/OnboardingScreen-5Gou9cGD.js +0 -1
  392. package/dist/assets/PierreDiffViewer-ByRVu6ss.js +0 -161
  393. package/dist/assets/PlanView-u2yi5XGJ.js +0 -5
  394. package/dist/assets/PluginPane-QxjsKYeO.js +0 -3
  395. package/dist/assets/SettingsView-Fo5ZqMaT.js +0 -29
  396. package/dist/assets/SettingsWindow-HVDVANjJ.js +0 -1
  397. package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +0 -1
  398. package/dist/assets/ToolOutputDialog-3J6IRayW.js +0 -15
  399. package/dist/assets/ToolPartDiffPreview-DarxPjSd.js +0 -8
  400. package/dist/assets/appThemeRegistry-Cf8KitzT.js +0 -1
  401. package/dist/assets/de-BM_8EDD3.js +0 -10
  402. package/dist/assets/es-CxZjlqpo.js +0 -16
  403. package/dist/assets/fr-VCixCnMW.js +0 -14
  404. package/dist/assets/index-3U4CtS9b.js +0 -1
  405. package/dist/assets/index-B9Hvzjwl.css +0 -1
  406. package/dist/assets/index-DLHQogv8.js +0 -40
  407. package/dist/assets/ja-CZ5k_GyD.js +0 -16
  408. package/dist/assets/ko-7YM3A1Xh.js +0 -16
  409. package/dist/assets/main-CycplCph.js +0 -2
  410. package/dist/assets/main-DFYTCx5o.js +0 -896
  411. package/dist/assets/markdownCore-DHvqMxPn.js +0 -5
  412. package/dist/assets/miniChat-DIQKfY2V.js +0 -2
  413. package/dist/assets/mobile-BMwz5q-m.js +0 -2
  414. package/dist/assets/pl-BcgDO_w5.js +0 -16
  415. package/dist/assets/pt-BR-CU2u_1q5.js +0 -16
  416. package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +0 -2
  417. package/dist/assets/renderMobileApp-D0Y8DtkA.js +0 -25
  418. package/dist/assets/runtimeEndpointReset-DhC3REb2.js +0 -25
  419. package/dist/assets/scheduledTasksApi-D8pq6gQz.js +0 -1
  420. package/dist/assets/tr-DuYhOzNe.js +0 -7
  421. package/dist/assets/uk-Cuk7-uvq.js +0 -16
  422. package/dist/assets/useAppFontEffects-BItUWdo4.js +0 -7333
  423. package/dist/assets/useInlineCommentController-CkbKsm7m.js +0 -2
  424. package/dist/assets/useRootScrollLock-vmzxZjWA.js +0 -2
  425. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  426. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  427. package/dist/assets/zh-CN-CUWoiRHd.js +0 -16
  428. package/dist/assets/zh-TW-CQ8EBSBN.js +0 -16
  429. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  430. package/server/lib/routing/feature-flag.js +0 -11
  431. package/server/lib/small-model/call.js +0 -820
  432. package/server/lib/small-model/call.test.js +0 -1110
  433. package/server/lib/small-model/catalog.js +0 -13
  434. package/server/lib/small-model/resolve.js +0 -131
  435. package/server/lib/small-model/resolve.test.js +0 -197
  436. package/server/lib/small-model/runtime-providers.js +0 -164
  437. package/server/lib/small-model/runtime-providers.test.js +0 -118
  438. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  439. package/server/lib/system-prompt/runtime.js +0 -49
  440. package/server/lib/system-prompt/runtime.test.js +0 -76
  441. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
  442. /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
@@ -1,6 +1,8 @@
1
1
  import { EventEmitter } from 'events';
2
+ import { Readable, Writable } from 'node:stream';
2
3
  import path from 'path';
3
4
  import { copyFile, mkdir, mkdtemp, rm } from 'node:fs/promises';
5
+ import * as nativeFs from 'node:fs/promises';
4
6
  import { tmpdir } from 'node:os';
5
7
  import { execFileSync } from 'node:child_process';
6
8
  import { pathToFileURL } from 'node:url';
@@ -571,8 +573,7 @@ describe('fs read', () => {
571
573
  expect(fsPromises.readFile).toHaveBeenCalledWith('/shared/target.txt', 'utf8');
572
574
  });
573
575
 
574
- it('rejects outside workspace reads without a grant', async () => {
575
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
576
+ it('reads outside workspace files without a grant', async () => {
576
577
  const fsPromises = {
577
578
  stat: vi.fn(async () => ({ isFile: () => true, size: 3 })),
578
579
  readFile: vi.fn(async () => 'secret'),
@@ -581,10 +582,9 @@ describe('fs read', () => {
581
582
 
582
583
  const res = await callRead(handler, { path: '/etc/passwd', allowOutsideWorkspace: 'true' });
583
584
 
584
- expect(res.statusCode).toBe(400);
585
- expect(res.body).toEqual({ error: 'Outside workspace file access requires a grant' });
586
- expect(fsPromises.readFile).not.toHaveBeenCalled();
587
- warn.mockRestore();
585
+ expect(res.statusCode).toBe(200);
586
+ expect(res.body).toBe('secret');
587
+ expect(fsPromises.readFile).toHaveBeenCalledWith('/etc/passwd', 'utf8');
588
588
  });
589
589
 
590
590
  it('allows outside workspace reads with an exact-path grant', async () => {
@@ -610,7 +610,7 @@ describe('fs read', () => {
610
610
  expect(res.body).toBe('secret');
611
611
  });
612
612
 
613
- it('rejects outside workspace grants for a different canonical path', async () => {
613
+ it('ignores legacy grants when reading another outside file', async () => {
614
614
  const fsPromises = {
615
615
  realpath: vi.fn(async (targetPath) => targetPath),
616
616
  stat: vi.fn(async () => ({ isFile: () => true, size: 6 })),
@@ -629,35 +629,58 @@ describe('fs read', () => {
629
629
  outsideFileGrant: grant.outsideFileGrant,
630
630
  });
631
631
 
632
- expect(res.statusCode).toBe(400);
633
- expect(res.body).toEqual({ error: 'Outside workspace file grant does not match requested path' });
634
- expect(fsPromises.readFile).not.toHaveBeenCalled();
632
+ expect(res.statusCode).toBe(200);
633
+ expect(res.body).toBe('secret');
634
+ expect(fsPromises.readFile).toHaveBeenCalledWith('/outside/b.txt', 'utf8');
635
635
  });
636
636
 
637
- it('sets no-referrer on raw responses served through outside file grants', async () => {
637
+ it('reads outside raw files without a grant and sets no-referrer', async () => {
638
638
  const fsPromises = {
639
639
  realpath: vi.fn(async (targetPath) => targetPath),
640
640
  stat: vi.fn(async () => ({ isFile: () => true, size: 6 })),
641
641
  readFile: vi.fn(async () => Buffer.from('secret')),
642
642
  };
643
- const grant = await mintOutsideFileGrant('/outside/image.png', {
644
- scopes: ['raw'],
645
- fsPromises,
646
- path: path.posix,
647
- crypto: { randomUUID: () => 'grant-raw' },
648
- });
649
643
  const handler = registerRaw(fsPromises);
650
644
 
651
645
  const res = await callRaw(handler, {
652
646
  path: '/outside/image.png',
653
647
  allowOutsideWorkspace: 'true',
654
- outsideFileGrant: grant.outsideFileGrant,
655
648
  });
656
649
 
657
650
  expect(res.statusCode).toBe(200);
658
651
  expect(res.getHeader('referrer-policy')).toBe('no-referrer');
659
652
  });
660
653
 
654
+ it('stats outside files without a grant', async () => {
655
+ const { app, getRoute } = createRouteRegistry();
656
+ registerFsRoutes(app, {
657
+ path: path.posix,
658
+ os: { homedir: () => '/home/user' },
659
+ fsPromises: {
660
+ realpath: async (targetPath) => targetPath,
661
+ stat: async () => ({ isFile: () => true, size: 100, mtimeMs: 123 }),
662
+ },
663
+ normalizeDirectoryPath: (p) => p,
664
+ resolveProjectDirectory: async () => ({ directory: '/repo' }),
665
+ openchamberUserConfigRoot: '/home/user/.config',
666
+ });
667
+ const res = await callRead(getRoute('GET', '/api/fs/stat'), { path: '/tmp/plan.txt', allowOutsideWorkspace: 'true' });
668
+ expect(res.statusCode).toBe(200);
669
+ expect(res.body).toEqual({ path: '/tmp/plan.txt', isFile: true, size: 100, mtimeMs: 123 });
670
+ });
671
+
672
+ it.each([
673
+ ['ENOENT', 404, { error: 'File not found' }],
674
+ ['EACCES', 403, { error: 'Access to file denied', reason: 'os-permission' }],
675
+ ])('reports %s for outside files instead of requiring a grant', async (code, status, body) => {
676
+ const handler = registerRead({
677
+ realpath: async () => { throw Object.assign(new Error(code), { code }); },
678
+ });
679
+ const res = await callRead(handler, { path: '/tmp/plan.txt', allowOutsideWorkspace: 'true' });
680
+ expect(res.statusCode).toBe(status);
681
+ expect(res.body).toEqual(body);
682
+ });
683
+
661
684
  it('rejects outside workspace mkdir without a trusted directory grant', async () => {
662
685
  const fsPromises = {
663
686
  mkdir: vi.fn(async () => undefined),
@@ -1011,6 +1034,88 @@ describe('fs exec git-read cache', () => {
1011
1034
  });
1012
1035
  });
1013
1036
 
1037
+ describe('fs raw byte ranges', () => {
1038
+ const createStreamingResponse = () => {
1039
+ const chunks = [];
1040
+ const headers = new Map();
1041
+ let statusCode = 200;
1042
+ const res = new Writable({
1043
+ write(chunk, _encoding, callback) {
1044
+ chunks.push(Buffer.from(chunk));
1045
+ callback();
1046
+ },
1047
+ });
1048
+ Object.assign(res, {
1049
+ status(code) { statusCode = code; return res; },
1050
+ json(payload) { chunks.push(Buffer.from(JSON.stringify(payload))); return res; },
1051
+ type() { return res; },
1052
+ send(payload) { chunks.push(Buffer.from(payload)); return res; },
1053
+ setHeader(name, value) { headers.set(name.toLowerCase(), value); return res; },
1054
+ getHeader(name) { return headers.get(name.toLowerCase()); },
1055
+ });
1056
+ return {
1057
+ res,
1058
+ finished: new Promise((resolve) => res.on('finish', resolve)),
1059
+ get statusCode() { return statusCode; },
1060
+ get body() { return Buffer.concat(chunks).toString('utf8'); },
1061
+ };
1062
+ };
1063
+
1064
+ const registerRawWithFile = (bytes) => {
1065
+ const open = vi.fn(async () => ({
1066
+ createReadStream: ({ start, end }) => Readable.from([bytes.subarray(start, end + 1)]),
1067
+ }));
1068
+ const readFile = vi.fn(async () => bytes);
1069
+ const handler = registerRaw({
1070
+ stat: async () => ({ isFile: () => true, size: bytes.length }),
1071
+ open,
1072
+ readFile,
1073
+ });
1074
+ return { handler, open, readFile };
1075
+ };
1076
+
1077
+ it('answers a bytes span with 206, the span headers, and only those bytes', async () => {
1078
+ const { handler, open, readFile } = registerRawWithFile(Buffer.from('0123456789'));
1079
+ const response = createStreamingResponse();
1080
+
1081
+ await handler({ query: { path: '/repo/clip.mp4' }, headers: { range: 'bytes=3-' } }, response.res);
1082
+ await response.finished;
1083
+
1084
+ expect(response.statusCode).toBe(206);
1085
+ expect(response.getHeader?.('content-range') ?? response.res.getHeader('content-range')).toBe('bytes 3-9/10');
1086
+ expect(response.res.getHeader('content-length')).toBe('7');
1087
+ expect(response.res.getHeader('accept-ranges')).toBe('bytes');
1088
+ expect(response.body).toBe('3456789');
1089
+ expect(open).toHaveBeenCalledWith('/repo/clip.mp4', 'r');
1090
+ expect(readFile).not.toHaveBeenCalled();
1091
+ });
1092
+
1093
+ it('serves the whole file, advertising ranges, when no span is asked for', async () => {
1094
+ const { handler, open } = registerRawWithFile(Buffer.from('0123456789'));
1095
+ const res = createMockResponse();
1096
+
1097
+ await handler({ query: { path: '/repo/clip.mp4' }, headers: {} }, res);
1098
+
1099
+ expect(res.statusCode).toBe(200);
1100
+ expect(res.getHeader('accept-ranges')).toBe('bytes');
1101
+ expect(res.body.toString('utf8')).toBe('0123456789');
1102
+ expect(open).not.toHaveBeenCalled();
1103
+ });
1104
+
1105
+ it('rejects a span past the end with 416 and the file size', async () => {
1106
+ const { handler, open } = registerRawWithFile(Buffer.from('0123456789'));
1107
+ const res = createMockResponse();
1108
+ res.end = vi.fn(() => res);
1109
+
1110
+ await handler({ query: { path: '/repo/clip.mp4' }, headers: { range: 'bytes=10-' } }, res);
1111
+
1112
+ expect(res.statusCode).toBe(416);
1113
+ expect(res.getHeader('content-range')).toBe('bytes */10');
1114
+ expect(res.end).toHaveBeenCalled();
1115
+ expect(open).not.toHaveBeenCalled();
1116
+ });
1117
+ });
1118
+
1014
1119
  describe('fs raw download Content-Disposition', () => {
1015
1120
  it('uses RFC 5987 filename*= encoding for non-ASCII filenames on download', async () => {
1016
1121
  const fsPromises = {
@@ -1445,6 +1550,7 @@ describe('fs stat directory error handling', () => {
1445
1550
  try {
1446
1551
  await mkdir(path.join(directory, 'fs'));
1447
1552
  await copyFile(new URL('./routes.js', import.meta.url), path.join(directory, 'fs/routes.mjs'));
1553
+ await copyFile(new URL('./byte-range.js', import.meta.url), path.join(directory, 'fs/byte-range.js'));
1448
1554
  await copyFile(new URL('../path-realpath-cache.js', import.meta.url), path.join(directory, 'path-realpath-cache.js'));
1449
1555
  expect(() => execFileSync('node', [
1450
1556
  '--input-type=module',
@@ -1586,6 +1692,40 @@ describe('fs managed chats root', () => {
1586
1692
  expect(res.body.chatsRoot).toBe('/srv/openchamber-chats');
1587
1693
  });
1588
1694
 
1695
+ it('fails home lookup on permission errors and retries the next request', async () => {
1696
+ const failure = Object.assign(new Error('permission denied'), { code: 'EACCES' });
1697
+ let inaccessible = true;
1698
+ const { home } = registerWithChatsRoot({ fsPromises: {
1699
+ realpath: async directory => { if (inaccessible) throw failure; return directory; },
1700
+ } });
1701
+ const failed = createMockResponse();
1702
+ await home(undefined, failed);
1703
+ expect(failed.statusCode).toBe(500);
1704
+ expect(failed.body).toEqual({ error: 'permission denied' });
1705
+ inaccessible = false;
1706
+ const recovered = createMockResponse();
1707
+ await home(undefined, recovered);
1708
+ expect(recovered.statusCode).toBe(200);
1709
+ expect(recovered.body.chatsRoot).toBe('/home/user/.config/openchamber/chats');
1710
+ });
1711
+
1712
+ it('keeps an accessible relocated root available when legacy alias lookup fails', async () => {
1713
+ const { home } = registerWithChatsRoot({
1714
+ managedChatsRoot: '/srv/chat-alias',
1715
+ fsPromises: {
1716
+ realpath: async directory => {
1717
+ if (directory === '/srv/chat-alias') return '/storage/chats';
1718
+ throw Object.assign(new Error('legacy root is inaccessible'), { code: 'EACCES' });
1719
+ },
1720
+ },
1721
+ });
1722
+ const response = createMockResponse();
1723
+ await home(undefined, response);
1724
+ expect(response.statusCode).toBe(200);
1725
+ expect(response.body.canonicalChatsRoot).toBe('/storage/chats');
1726
+ expect(response.body.canonicalLegacyChatsRoot).toBeUndefined();
1727
+ });
1728
+
1589
1729
  it('allows mkdir inside the relocated chats root outside the active workspace', async () => {
1590
1730
  const mkdirCalls = [];
1591
1731
  const { mkdir } = registerWithChatsRoot({
@@ -1605,6 +1745,22 @@ describe('fs managed chats root', () => {
1605
1745
  expect(mkdirCalls).toEqual(['/srv/openchamber-chats/2026-08-25/session-a']);
1606
1746
  });
1607
1747
 
1748
+ it('accepts a canonical relocated root even when the config root cannot be resolved', async () => {
1749
+ const { mkdir } = registerWithChatsRoot({
1750
+ managedChatsRoot: '/srv/chat-alias',
1751
+ fsPromises: {
1752
+ realpath: async directory => {
1753
+ if (directory === '/srv/chat-alias') return '/storage/chats';
1754
+ throw Object.assign(new Error('permission denied'), { code: 'EACCES' });
1755
+ },
1756
+ },
1757
+ });
1758
+ const response = createMockResponse();
1759
+ await mkdir({ body: { path: '/storage/chats/day/session-a' } }, response);
1760
+ expect(response.statusCode).toBe(200);
1761
+ expect(response.body.path).toBe('/storage/chats/day/session-a');
1762
+ });
1763
+
1608
1764
  it('still rejects mkdir outside the workspace and all managed roots', async () => {
1609
1765
  const { mkdir } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
1610
1766
 
@@ -1615,3 +1771,68 @@ describe('fs managed chats root', () => {
1615
1771
  expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
1616
1772
  });
1617
1773
  });
1774
+
1775
+ describe('canonical managed roots with real filesystem aliases', () => {
1776
+ const setup = async (context, { relocated = false, caseAlias = false } = {}) => {
1777
+ const root = await nativeFs.mkdtemp(path.join(tmpdir(), 'oc-canonical-chats-'));
1778
+ context.onTestFinished(() => nativeFs.rm(root, { recursive: true, force: true }));
1779
+ const home = path.join(root, 'Home');
1780
+ await nativeFs.mkdir(home);
1781
+ const reportedHome = path.join(root, caseAlias ? 'home' : 'home-alias');
1782
+ if (!caseAlias) await nativeFs.symlink(home, reportedHome, 'junction');
1783
+ const config = path.join(reportedHome, '.config/openchamber');
1784
+ const rawChats = relocated ? path.join(reportedHome, 'scratch/chats') : path.join(config, 'chats');
1785
+ const canonicalHome = await nativeFs.realpath(home);
1786
+ if (caseAlias && await nativeFs.realpath(reportedHome).catch(() => null) !== canonicalHome) {
1787
+ context.skip('This volume distinguishes Home from home');
1788
+ }
1789
+ const canonicalChats = path.join(canonicalHome, relocated ? 'scratch/chats' : '.config/openchamber/chats');
1790
+ const { app, getRoute } = createRouteRegistry();
1791
+ registerFsRoutes(app, {
1792
+ os: { homedir: () => reportedHome }, path, fsPromises: nativeFs,
1793
+ normalizeDirectoryPath: value => value,
1794
+ resolveProjectDirectory: async () => ({ directory: path.join(root, 'unrelated-project') }),
1795
+ openchamberUserConfigRoot: config, managedChatsRoot: rawChats,
1796
+ });
1797
+ return { getRoute, canonicalHome, canonicalChats, rawChats, reportedHome };
1798
+ };
1799
+
1800
+ for (const relocated of [false, true]) {
1801
+ it(`returns canonical paths before the ${relocated ? 'relocated' : 'default'} root exists and permits its lifecycle`, async context => {
1802
+ const { getRoute, canonicalHome, canonicalChats, rawChats, reportedHome } = await setup(context, { relocated });
1803
+ const home = createMockResponse();
1804
+ await getRoute('GET', '/api/fs/home')({}, home);
1805
+ expect(home.body).toEqual({
1806
+ home: reportedHome, chatsRoot: rawChats,
1807
+ canonicalChatsRoot: canonicalChats,
1808
+ canonicalLegacyChatsRoot: path.join(canonicalHome, '.config/openchamber/chats'),
1809
+ });
1810
+ await expect(nativeFs.stat(canonicalChats)).rejects.toMatchObject({ code: 'ENOENT' });
1811
+
1812
+ const directory = path.join(home.body.canonicalChatsRoot, 'day/session-a');
1813
+ const created = createMockResponse();
1814
+ await getRoute('POST', '/api/fs/mkdir')({ body: { path: directory } }, created);
1815
+ expect(created.statusCode).toBe(200);
1816
+ expect(await nativeFs.realpath(directory)).toBe(directory);
1817
+ const deleted = createMockResponse();
1818
+ await getRoute('POST', '/api/fs/delete')({ body: { path: directory } }, deleted);
1819
+ expect(deleted.statusCode).toBe(200);
1820
+ await expect(nativeFs.stat(directory)).rejects.toMatchObject({ code: 'ENOENT' });
1821
+
1822
+ const legacy = createMockResponse();
1823
+ await getRoute('POST', '/api/fs/mkdir')({ body: { path: path.join(rawChats, 'legacy-session') } }, legacy);
1824
+ expect(legacy.statusCode).toBe(200);
1825
+ expect((await nativeFs.stat(path.join(canonicalChats, 'legacy-session'))).isDirectory()).toBe(true);
1826
+ });
1827
+ }
1828
+
1829
+ it('reports on-disk home casing on a case-insensitive macOS volume', { skip: process.platform !== 'darwin' }, async context => {
1830
+ const { getRoute, canonicalChats, rawChats, reportedHome } = await setup(context, { caseAlias: true });
1831
+ const response = createMockResponse();
1832
+ await getRoute('GET', '/api/fs/home')({}, response);
1833
+ expect(response.body).toEqual({
1834
+ home: reportedHome, chatsRoot: rawChats,
1835
+ canonicalChatsRoot: canonicalChats, canonicalLegacyChatsRoot: canonicalChats,
1836
+ });
1837
+ });
1838
+ });
@@ -16,7 +16,7 @@ This module provides Git repository operations for the web server runtime, inclu
16
16
  The following functions are exported and used by the web server:
17
17
 
18
18
  ### Repository Operations
19
- - `isGitRepository(directory)`: Check if a directory is a Git repository.
19
+ - `isGitRepository(directory)`: Check if a directory is a Git repository. A repository whose root is the home directory or a filesystem root (`C:\`, `/`) answers `false` (`unsupportedRepositoryRootReason`): such a repository covers the whole disk, every status read would walk it, and it is nearly always an accidental `git init`. All Git surfaces then show the non-repository state for that directory.
20
20
  - `getGlobalIdentity()`: Get global Git user.name, user.email, and core.sshCommand.
21
21
  - `getCurrentIdentity(directory)`: Get local Git identity (fallback to global if not set locally).
22
22
  - `hasLocalIdentity(directory)`: Check if local Git identity is configured.
@@ -24,7 +24,7 @@ The following functions are exported and used by the web server:
24
24
  - `getRemoteUrl(directory, remoteName)`: Get URL for a specific remote.
25
25
 
26
26
  ### Status and Diff Operations
27
- - `getStatus(directory, { mode })`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state. `mode: 'light'` skips the diff stats. One read runs per directory at a time and at most four run across directories (`serial-refresh.js`): a call made while a read is running waits for one follow-up read that starts after the call, so no caller gets a snapshot older than its request, and every caller that arrives during one read shares that single follow-up at the widest mode any of them asked for. Clients refresh after every completed agent tool call and from several surfaces at once; on a large repository (a status read is a dozen Git processes walking the working tree) this bound is what keeps identical `git status` processes from piling up side by side. Untracked files are listed with `-unormal` and each new directory is then expanded to its files with a bounded `ls-files` listing (`UNTRACKED_DIRECTORY_EXPANSION_LIMIT`, 1000): up to that many files the result equals `-uall`; beyond it the directory stays one `dir/` entry, because `-uall` would walk a forgotten build or dependency directory in full on every read. A nested repository stays a `dir/` entry as before.
27
+ - `getStatus(directory, { mode })`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state. `mode: 'light'` skips the diff stats. One read runs per directory at a time and at most four run across directories (`serial-refresh.js`): a call made while a read is running waits for one follow-up read that starts after the call, so no caller gets a snapshot older than its request, and every caller that arrives during one read shares that single follow-up at the widest mode any of them asked for. Clients refresh after every completed agent tool call and from several surfaces at once; on a large repository (a status read is a dozen Git processes walking the working tree) this bound is what keeps identical `git status` processes from piling up side by side. A slot is held only while the read is alive: every process the read spawns is killed after two minutes without output (one minute for the untracked-directory listing, thirty seconds for the repository probe), so a Git process that hangs, which happens on Windows, fails that read instead of holding a slot until someone kills it by hand. On Windows the listing is ended with `taskkill /T`, because the spawned `git.exe` is Git for Windows' launcher and killing it alone leaves the real `git` child walking the tree as an orphan. Untracked files are listed with `-unormal` and each new directory is then expanded to its files with a bounded `ls-files` listing (`UNTRACKED_DIRECTORY_EXPANSION_LIMIT`, 1000): up to that many files the result equals `-uall`; beyond it the directory stays one `dir/` entry, because `-uall` would walk a forgotten build or dependency directory in full on every read. A nested repository stays a `dir/` entry as before.
28
28
  - `getTrackingBranch(directory)`: Upstream of the checked-out branch as `remote/branch` (the same value as `status.tracking`, including an upstream whose remote ref is gone), or `null` when HEAD is detached or unborn or no upstream is configured. Reads refs and config only. Callers that need just the tracking name (GitHub PR status polling, PR creation) use this instead of `getStatus`.
29
29
  - `getDiff(directory, { path, staged, contextLines })`: Get diff output for files or entire working tree with full Git blob identities. Untracked symbolic links are represented as link entries without following their targets.
30
30
  - `getPathDiff(directory, { path, staged, contextLines })`: `getDiff` for one path, returning `{ diff, submodule }`. `submodule` is `null` for ordinary paths. For a gitlink it is `{ headCommit, indexCommit, worktreeCommit, hasTrackedChanges, hasUntrackedFiles, hasConflict }`, because a submodule that only gained untracked files shows as modified in status while its patch is empty. `worktreeCommit` is `null` when the submodule is not checked out. An unmerged gitlink has no single index commit, so it reports `hasConflict: true` with `indexCommit: null`. Exposed as `GET /api/git/diff`.
@@ -359,9 +359,13 @@ const buildGitEnv = async () => {
359
359
  return env;
360
360
  };
361
361
 
362
- const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false } = {}) => {
362
+ const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false, stallTimeoutMs = 0 } = {}) => {
363
363
  const env = await buildGitEnv();
364
364
  const spawnOptions = { windowsHide: true };
365
+ // simple-git's block timeout kills the process once it has produced no
366
+ // output for this long. Opt-in per caller: a background read must never hold
367
+ // a limiter slot forever, while a silent long push or fetch must not be cut.
368
+ const timeout = stallTimeoutMs > 0 ? { block: stallTimeoutMs } : undefined;
365
369
  const binary = getGitBinary();
366
370
  const hasCustomBinary = typeof binary === 'string' && binary.trim() && binary !== 'git' && binary !== 'git.exe';
367
371
  const unsafe = hasCustomBinary || allowUnsafeSshCommand || allowUnsafeCredentialHelper
@@ -386,6 +390,7 @@ const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafe
386
390
  spawnOptions,
387
391
  binary,
388
392
  unsafe,
393
+ ...(timeout ? { timeout } : {}),
389
394
  });
390
395
  };
391
396
 
@@ -491,14 +496,14 @@ const resolveGitRepositoryRoot = async (directoryPath, git) => {
491
496
  : path.resolve(directoryPath, normalizedTopLevel);
492
497
  };
493
498
 
494
- const createRepositoryGitContext = async (directory) => {
499
+ const createRepositoryGitContext = async (directory, gitOptions = {}) => {
495
500
  const directoryPath = normalizeDirectoryPath(directory);
496
501
  if (typeof directoryPath !== 'string' || !directoryPath.trim()) {
497
502
  throw new Error('Git directory is required');
498
503
  }
499
- const directoryGit = await createGit(directoryPath);
504
+ const directoryGit = await createGit(directoryPath, gitOptions);
500
505
  const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
501
- const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot);
506
+ const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot, gitOptions);
502
507
  return { directoryPath, directoryGit, repoRoot, git };
503
508
  };
504
509
 
@@ -1014,13 +1019,16 @@ const isMissingDirectoryError = (error) => {
1014
1019
  return /directory that does not exist|does not exist|no such file or directory/i.test(text);
1015
1020
  };
1016
1021
 
1017
- const runGitCommand = async (cwd, args) => {
1022
+ const runGitCommand = async (cwd, args, { timeoutMs = 0 } = {}) => {
1018
1023
  try {
1019
1024
  const { stdout, stderr } = await execFileAsync(getGitBinary(), args, {
1020
1025
  cwd,
1021
1026
  env: await buildGitEnv(),
1022
1027
  windowsHide: true,
1023
1028
  maxBuffer: 20 * 1024 * 1024,
1029
+ // Only short probes pass a timeout; commands that legitimately run long
1030
+ // (a fetch into a temporary clone) keep the default of none.
1031
+ ...(timeoutMs > 0 ? { timeout: timeoutMs, killSignal: 'SIGKILL' } : {}),
1024
1032
  });
1025
1033
  return {
1026
1034
  success: true,
@@ -2147,14 +2155,45 @@ const applyUpstreamConfiguration = async (args) => {
2147
2155
  );
2148
2156
  };
2149
2157
 
2158
+ /**
2159
+ * A repository whose root is the user's home directory or a filesystem root
2160
+ * (`C:\`, `/`) covers the whole disk. Every status read walks Program Files
2161
+ * or the entire home tree, which is minutes of Git work per refresh and, on
2162
+ * Windows, the process pile-ups users report. Such a repository is nearly
2163
+ * always an accidental `git init` in the wrong place, so OpenChamber treats
2164
+ * it as no repository at all. Returns the reason or null for a normal root.
2165
+ */
2166
+ export const unsupportedRepositoryRootReason = (repoRoot, home = os.homedir()) => {
2167
+ if (typeof repoRoot !== 'string' || !repoRoot.trim()) return null;
2168
+ const resolved = path.resolve(repoRoot.trim());
2169
+ if (path.resolve(path.parse(resolved).root) === resolved) return 'filesystem-root';
2170
+ if (typeof home === 'string' && home.trim() && path.resolve(home.trim()) === resolved) return 'home';
2171
+ return null;
2172
+ };
2173
+
2174
+ const warnedUnsupportedRoots = new Set();
2175
+
2150
2176
  export async function isGitRepository(directory) {
2151
2177
  const directoryPath = normalizeDirectoryPath(directory);
2152
2178
  if (!directoryPath || !fs.existsSync(directoryPath)) {
2153
2179
  return false;
2154
2180
  }
2155
2181
 
2156
- const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir']);
2157
- return result.success;
2182
+ const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
2183
+ if (!result.success) return false;
2184
+
2185
+ // `--show-toplevel` has no answer inside a bare repository or a .git
2186
+ // directory; those keep the previous answer rather than being rejected.
2187
+ const topLevel = await runGitCommand(directoryPath, ['rev-parse', '--show-toplevel'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
2188
+ if (!topLevel.success) return true;
2189
+ const repoRoot = topLevel.stdout.trim();
2190
+ const reason = unsupportedRepositoryRootReason(repoRoot);
2191
+ if (!reason) return true;
2192
+ if (!warnedUnsupportedRoots.has(repoRoot)) {
2193
+ warnedUnsupportedRoots.add(repoRoot);
2194
+ console.warn(`[git] Ignoring repository rooted at ${repoRoot} (${reason}): Git features are disabled for ${directoryPath}`);
2195
+ }
2196
+ return false;
2158
2197
  }
2159
2198
 
2160
2199
  export async function getGlobalIdentity() {
@@ -2282,7 +2321,38 @@ export async function setLocalIdentity(directory, profile) {
2282
2321
  // .gitignore.
2283
2322
  const UNTRACKED_DIRECTORY_EXPANSION_LIMIT = 1000;
2284
2323
 
2324
+ // A status read holds one of MAX_CONCURRENT_STATUS_READS slots until it
2325
+ // finishes. Git never gets a terminal here, but a process can still hang on
2326
+ // Windows (a locked index, a stuck filesystem monitor, an unreachable network
2327
+ // drive), and a hung process would hold its slot forever: four of them and no
2328
+ // status read runs again until someone kills them by hand. Every process the
2329
+ // read spawns is therefore killed when it stops producing output for this long,
2330
+ // and the read fails instead of wedging the limiter. Two minutes is far above
2331
+ // what a healthy read spends silent, even on a very large tree.
2332
+ const GIT_STATUS_STALL_TIMEOUT_MS = 120_000;
2333
+ const GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS = 60_000;
2334
+ const GIT_PROBE_TIMEOUT_MS = 30_000;
2335
+
2285
2336
  // Untracked files under `dirPath` (repository-relative, trailing slash), read
2337
+ // Git for Windows runs commands through a launcher: the `git.exe` we spawn is a
2338
+ // wrapper whose child is the real `git`. Killing only the wrapper leaves that
2339
+ // child alive, still walking the tree on its own (a repository rooted at a
2340
+ // drive root sends it through Program Files), and it shows up in Task Manager
2341
+ // as a stuck pair until someone ends it by hand. Windows has no process groups
2342
+ // to signal, so the tree is ended through taskkill.
2343
+ const killProcessTree = (child) => {
2344
+ if (!child.pid) return;
2345
+ if (process.platform === 'win32') {
2346
+ try {
2347
+ spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).on('error', () => {});
2348
+ } catch {
2349
+ child.kill('SIGKILL');
2350
+ }
2351
+ return;
2352
+ }
2353
+ child.kill('SIGKILL');
2354
+ };
2355
+
2286
2356
  // from a streamed `ls-files` that is stopped once the bound is exceeded so a
2287
2357
  // huge directory is never listed in full. `paths` is complete when
2288
2358
  // `truncated` is false.
@@ -2299,16 +2369,29 @@ const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
2299
2369
  let pending = '';
2300
2370
  let truncated = false;
2301
2371
  let settled = false;
2372
+ let stallTimer = null;
2302
2373
  const finish = (error) => {
2303
2374
  if (settled) return;
2304
2375
  settled = true;
2376
+ if (stallTimer) clearTimeout(stallTimer);
2305
2377
  if (error) {
2306
2378
  reject(error);
2307
2379
  return;
2308
2380
  }
2309
2381
  resolve({ paths, truncated });
2310
2382
  };
2383
+ // A listing that goes silent is killed rather than left holding the
2384
+ // status read (and its limiter slot) open.
2385
+ const armStallTimer = () => {
2386
+ if (stallTimer) clearTimeout(stallTimer);
2387
+ stallTimer = setTimeout(() => {
2388
+ killProcessTree(child);
2389
+ finish(new Error(`git ls-files produced no output for ${GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS}ms in ${dirPath}`));
2390
+ }, GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS);
2391
+ };
2392
+ armStallTimer();
2311
2393
  child.stdout.on('data', (chunk) => {
2394
+ armStallTimer();
2312
2395
  if (truncated) return;
2313
2396
  pending += chunk.toString('utf8');
2314
2397
  const records = pending.split('\0');
@@ -2318,7 +2401,7 @@ const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
2318
2401
  paths.push(record);
2319
2402
  if (paths.length > limit) {
2320
2403
  truncated = true;
2321
- child.kill();
2404
+ killProcessTree(child);
2322
2405
  finish();
2323
2406
  return;
2324
2407
  }
@@ -2418,6 +2501,18 @@ export async function getTrackingBranch(directory) {
2418
2501
  return tracking || null;
2419
2502
  }
2420
2503
 
2504
+ // Whether `sha` is reachable from the checked-out HEAD. An object git has never
2505
+ // fetched fails the same way an unrelated commit does: not an ancestor.
2506
+ export async function isAncestorOfHead(directory, sha) {
2507
+ const normalizedDirectory = normalizeDirectoryPath(directory);
2508
+ const normalizedSha = typeof sha === 'string' ? sha.trim() : '';
2509
+ if (!normalizedDirectory || !/^[0-9a-f]{7,64}$/i.test(normalizedSha)) {
2510
+ return false;
2511
+ }
2512
+ const result = await runGitCommand(normalizedDirectory, ['merge-base', '--is-ancestor', normalizedSha, 'HEAD']);
2513
+ return result.success;
2514
+ }
2515
+
2421
2516
  async function readStatus(normalizedDirectory, lightMode) {
2422
2517
  try {
2423
2518
  // Prefer an explicit non-repo check before simple-git status so a missing
@@ -2426,7 +2521,9 @@ async function readStatus(normalizedDirectory, lightMode) {
2426
2521
  throw new Error('fatal: not a git repository (or any of the parent directories): .git');
2427
2522
  }
2428
2523
 
2429
- const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory);
2524
+ const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory, {
2525
+ stallTimeoutMs: GIT_STATUS_STALL_TIMEOUT_MS,
2526
+ });
2430
2527
 
2431
2528
  // `-unormal` lists a directory with no tracked files as one `dir/` entry
2432
2529
  // and stops walking it at its first file. `-uall` would walk every file
@@ -8,6 +8,7 @@ import { loadSourceSections, parseSource, sourceKey } from '../walkthrough/sourc
8
8
  import { registerGitRoutes } from './routes.js';
9
9
 
10
10
  import {
11
+ unsupportedRepositoryRootReason,
11
12
  checkoutBranch,
12
13
  checkoutCommit,
13
14
  cherryPick,
@@ -131,6 +132,23 @@ async function createTempRepo() {
131
132
  // resolveBaseRefForLog
132
133
  // ---------------------------------------------------------------------------
133
134
 
135
+ describe('unsupportedRepositoryRootReason', () => {
136
+ it('rejects a repository rooted at a filesystem root or the home directory', () => {
137
+ const home = path.join(os.tmpdir(), 'unsupported-root-home');
138
+ expect(unsupportedRepositoryRootReason('/', home)).toBe('filesystem-root');
139
+ expect(unsupportedRepositoryRootReason(path.parse(process.cwd()).root, home)).toBe('filesystem-root');
140
+ expect(unsupportedRepositoryRootReason(home, home)).toBe('home');
141
+ expect(unsupportedRepositoryRootReason(`${home}${path.sep}`, home)).toBe('home');
142
+ });
143
+
144
+ it('accepts an ordinary project root, including one directly under home', () => {
145
+ const home = path.join(os.tmpdir(), 'unsupported-root-home');
146
+ expect(unsupportedRepositoryRootReason(path.join(home, 'project'), home)).toBeNull();
147
+ expect(unsupportedRepositoryRootReason(path.join(os.tmpdir(), 'repo'), home)).toBeNull();
148
+ expect(unsupportedRepositoryRootReason('', home)).toBeNull();
149
+ });
150
+ });
151
+
134
152
  describe('resolveBaseRefForLog', () => {
135
153
  it('returns the local ref unchanged when it exists, even if origin also exists', async () => {
136
154
  const checkRef = async (ref) => ref === 'main' || ref === 'refs/remotes/origin/main';
@@ -83,7 +83,7 @@ that page, so callers cannot mistake a partial page for a complete one.
83
83
  - It first searches for **open** PRs by likely source owner plus exact head branch.
84
84
  - If that fails, it falls back to broader GitHub search for open PRs on the branch name.
85
85
  - An **open PR from any candidate repo always wins** over a closed/merged one, so a merged fork PR can never hide an open upstream PR for the same head.
86
- - Only when no target has an open PR does it return the branch's newest closed/merged PR, as history.
86
+ - Only when no target has an open PR does it return the branch's newest closed/merged PR, as history — and only when that PR's head commit is an ancestor of the checkout's `HEAD`. History is matched by branch name, and names get reused: a fresh worktree cut from the default branch under a name that was merged before must not inherit the old PR.
87
87
  - History is looked up **only for the ranked-first remote and the branch's own name** — the repo it actually pushes to. Live status is worth searching the whole fork network for; history is not, and asking every target for it multiplies serial GitHub calls until the route hits its `12s` resolve timeout and returns no status at all.
88
88
  - The history answer is remembered per repo+branch so discovery polls do not re-query it: a found closed/merged record for `6h`, and "no history yet" for `10m`. A found record only changes if a second PR appears on the same head, and while that one is open the open-PR path wins without ever reading this cache.
89
89
  - Creating, merging, or closing a PR invalidates both the shared repo pull list and that remembered history.
@@ -1,5 +1,5 @@
1
1
  import { stat } from 'node:fs/promises';
2
- import { getRemotes, getTrackingBranch } from '../git/index.js';
2
+ import { getRemotes, getTrackingBranch, isAncestorOfHead } from '../git/index.js';
3
3
  import { resolveGitHubRepoFromDirectory } from './repo/index.js';
4
4
  import { noteIfGitHubRateLimit } from './rate-limit.js';
5
5
 
@@ -543,6 +543,26 @@ const searchFallbackPr = async ({ octokit, branch, repoNames }) => {
543
543
 
544
544
  const isTerminalPr = (pr) => Boolean(pr) && (pr.state === 'closed' || Boolean(pr.merged_at));
545
545
 
546
+ // A closed/merged PR is matched by head branch NAME, and names get reused: a
547
+ // fresh worktree called `feature` cut from the default branch would inherit
548
+ // the merged PR of last month's `feature`. The PR only belongs to this checkout
549
+ // when the commit it was merged or closed at is part of the checkout's history.
550
+ // `isAncestor` is the git check, replaceable so the tests need no git repository.
551
+ const isHistoricalPrOfCheckout = async (directory, pr, { isAncestor = isAncestorOfHead } = {}) => {
552
+ const headSha = normalizeText(pr?.head?.sha);
553
+ if (!headSha) {
554
+ return false;
555
+ }
556
+ try {
557
+ return await isAncestor(directory, headSha);
558
+ } catch {
559
+ return false;
560
+ }
561
+ };
562
+
563
+ // Exported for focused unit tests.
564
+ export { isHistoricalPrOfCheckout };
565
+
546
566
  /**
547
567
  * Resolve the PRs a branch is associated with in one repo target.
548
568
  *
@@ -764,7 +784,7 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
764
784
  }
765
785
  }
766
786
 
767
- if (historicalMatch) {
787
+ if (historicalMatch && await isHistoricalPrOfCheckout(directory, historicalMatch.pr)) {
768
788
  return historicalMatch;
769
789
  }
770
790