@deepseek-ai/dsh-experimental-client-ui-forge 0.2.2-rc.5 → 0.2.3-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/README.i18n.yaml +12 -12
  2. package/README.md +47 -30
  3. package/README.zh.md +47 -30
  4. package/lib/client.js +18 -8
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +2444 -406
  7. package/lib/typert.host.js +3433 -950
  8. package/lib/typert.remote-client.d.ts +89 -14
  9. package/lib/typert.remote-client.d.ts.map +1 -1
  10. package/lib/typert.remote-client.js +3155 -978
  11. package/lib/types/branch-name.d.ts +30 -0
  12. package/lib/types/branch-name.d.ts.map +1 -0
  13. package/lib/types/branch-name.js.map +1 -0
  14. package/lib/types/client/AttentionIndicator.d.ts +22 -0
  15. package/lib/types/client/AttentionIndicator.d.ts.map +1 -0
  16. package/lib/types/client/AttentionIndicator.js.map +1 -0
  17. package/lib/types/client/BaseMenu.d.ts.map +1 -1
  18. package/lib/types/client/BaseMenu.js.map +1 -1
  19. package/lib/types/client/ChangeRequestCard.d.ts +87 -9
  20. package/lib/types/client/ChangeRequestCard.d.ts.map +1 -1
  21. package/lib/types/client/ChangeRequestCard.js.map +1 -1
  22. package/lib/types/client/ChangeRequestOverview.d.ts +126 -10
  23. package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -1
  24. package/lib/types/client/ChangeRequestOverview.js.map +1 -1
  25. package/lib/types/client/ChangeRequestsSection.d.ts +76 -0
  26. package/lib/types/client/ChangeRequestsSection.d.ts.map +1 -0
  27. package/lib/types/client/ChangeRequestsSection.js.map +1 -0
  28. package/lib/types/client/ChangedFiles.d.ts +6 -2
  29. package/lib/types/client/ChangedFiles.d.ts.map +1 -1
  30. package/lib/types/client/ChangedFiles.js.map +1 -1
  31. package/lib/types/client/ChangesLoading.d.ts +14 -0
  32. package/lib/types/client/ChangesLoading.d.ts.map +1 -0
  33. package/lib/types/client/ChangesLoading.js.map +1 -0
  34. package/lib/types/client/ChangesTab.d.ts +62 -14
  35. package/lib/types/client/ChangesTab.d.ts.map +1 -1
  36. package/lib/types/client/ChangesTab.js.map +1 -1
  37. package/lib/types/client/ChangesTabTitle.js.map +1 -1
  38. package/lib/types/client/DiffFile.d.ts +23 -4
  39. package/lib/types/client/DiffFile.d.ts.map +1 -1
  40. package/lib/types/client/DiffFile.js.map +1 -1
  41. package/lib/types/client/EnvironmentRows.d.ts +79 -0
  42. package/lib/types/client/EnvironmentRows.d.ts.map +1 -0
  43. package/lib/types/client/EnvironmentRows.js.map +1 -0
  44. package/lib/types/client/FileTreePane.d.ts +5 -2
  45. package/lib/types/client/FileTreePane.d.ts.map +1 -1
  46. package/lib/types/client/FileTreePane.js.map +1 -1
  47. package/lib/types/client/LensFilter.d.ts +50 -0
  48. package/lib/types/client/LensFilter.d.ts.map +1 -0
  49. package/lib/types/client/LensFilter.js.map +1 -0
  50. package/lib/types/client/ReasonButton.d.ts +15 -0
  51. package/lib/types/client/ReasonButton.d.ts.map +1 -0
  52. package/lib/types/client/ReasonButton.js.map +1 -0
  53. package/lib/types/client/ReviewComposer.d.ts +11 -4
  54. package/lib/types/client/ReviewComposer.d.ts.map +1 -1
  55. package/lib/types/client/ReviewComposer.js.map +1 -1
  56. package/lib/types/client/ReviewControls.d.ts +18 -7
  57. package/lib/types/client/ReviewControls.d.ts.map +1 -1
  58. package/lib/types/client/ReviewControls.js.map +1 -1
  59. package/lib/types/client/ReviewThread.d.ts +3 -1
  60. package/lib/types/client/ReviewThread.d.ts.map +1 -1
  61. package/lib/types/client/ReviewThread.js.map +1 -1
  62. package/lib/types/client/ReviewThreads.d.ts +32 -2
  63. package/lib/types/client/ReviewThreads.d.ts.map +1 -1
  64. package/lib/types/client/ReviewThreads.js.map +1 -1
  65. package/lib/types/client/SessionHoverForge.d.ts.map +1 -1
  66. package/lib/types/client/SessionHoverForge.js.map +1 -1
  67. package/lib/types/client/SubmitReview.d.ts +4 -4
  68. package/lib/types/client/SubmitReview.d.ts.map +1 -1
  69. package/lib/types/client/SubmitReview.js.map +1 -1
  70. package/lib/types/client/ThreadList.js.map +1 -1
  71. package/lib/types/client/ViewOptionsMenu.d.ts +7 -1
  72. package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -1
  73. package/lib/types/client/ViewOptionsMenu.js.map +1 -1
  74. package/lib/types/client/WorktreeNameDialog.d.ts +38 -0
  75. package/lib/types/client/WorktreeNameDialog.d.ts.map +1 -0
  76. package/lib/types/client/WorktreeNameDialog.js.map +1 -0
  77. package/lib/types/client/WorktreeProgress.d.ts +14 -3
  78. package/lib/types/client/WorktreeProgress.d.ts.map +1 -1
  79. package/lib/types/client/WorktreeProgress.js.map +1 -1
  80. package/lib/types/client/WorktreeToggle.d.ts +22 -15
  81. package/lib/types/client/WorktreeToggle.d.ts.map +1 -1
  82. package/lib/types/client/WorktreeToggle.js.map +1 -1
  83. package/lib/types/client/action-notices.d.ts +25 -0
  84. package/lib/types/client/action-notices.d.ts.map +1 -0
  85. package/lib/types/client/action-notices.js.map +1 -0
  86. package/lib/types/client/annotations.d.ts +41 -0
  87. package/lib/types/client/annotations.d.ts.map +1 -0
  88. package/lib/types/client/annotations.js.map +1 -0
  89. package/lib/types/client/branch-search.d.ts +38 -0
  90. package/lib/types/client/branch-search.d.ts.map +1 -0
  91. package/lib/types/client/branch-search.js.map +1 -0
  92. package/lib/types/client/change-requests-store.d.ts +25 -0
  93. package/lib/types/client/change-requests-store.d.ts.map +1 -0
  94. package/lib/types/client/change-requests-store.js.map +1 -0
  95. package/lib/types/client/changes-address.d.ts +3 -1
  96. package/lib/types/client/changes-address.d.ts.map +1 -1
  97. package/lib/types/client/changes-address.js.map +1 -1
  98. package/lib/types/client/changes-service.d.ts +119 -0
  99. package/lib/types/client/changes-service.d.ts.map +1 -0
  100. package/lib/types/client/changes-service.js.map +1 -0
  101. package/lib/types/client/changes-store.d.ts +6 -2
  102. package/lib/types/client/changes-store.d.ts.map +1 -1
  103. package/lib/types/client/changes-store.js.map +1 -1
  104. package/lib/types/client/checkout.d.ts.map +1 -1
  105. package/lib/types/client/checkout.js.map +1 -1
  106. package/lib/types/client/diff-rows.d.ts +49 -7
  107. package/lib/types/client/diff-rows.d.ts.map +1 -1
  108. package/lib/types/client/diff-rows.js.map +1 -1
  109. package/lib/types/client/file-tree.d.ts +7 -0
  110. package/lib/types/client/file-tree.d.ts.map +1 -1
  111. package/lib/types/client/file-tree.js.map +1 -1
  112. package/lib/types/client/forge-copy.d.ts +29 -0
  113. package/lib/types/client/forge-copy.d.ts.map +1 -0
  114. package/lib/types/client/forge-copy.js.map +1 -0
  115. package/lib/types/client/format.d.ts +8 -0
  116. package/lib/types/client/format.d.ts.map +1 -1
  117. package/lib/types/client/format.js.map +1 -1
  118. package/lib/types/client/glyphs.d.ts +3 -3
  119. package/lib/types/client/glyphs.d.ts.map +1 -1
  120. package/lib/types/client/glyphs.js.map +1 -1
  121. package/lib/types/client/highlight-context.d.ts +73 -0
  122. package/lib/types/client/highlight-context.d.ts.map +1 -0
  123. package/lib/types/client/highlight-context.js.map +1 -0
  124. package/lib/types/client/index.d.ts +9 -5
  125. package/lib/types/client/index.d.ts.map +1 -1
  126. package/lib/types/client/index.js.map +1 -1
  127. package/lib/types/client/lens-filter.d.ts +69 -0
  128. package/lib/types/client/lens-filter.d.ts.map +1 -0
  129. package/lib/types/client/lens-filter.js.map +1 -0
  130. package/lib/types/client/locales.d.ts +188 -36
  131. package/lib/types/client/locales.d.ts.map +1 -1
  132. package/lib/types/client/locales.js.map +1 -1
  133. package/lib/types/client/mount.d.ts +0 -4
  134. package/lib/types/client/mount.d.ts.map +1 -1
  135. package/lib/types/client/mount.js.map +1 -1
  136. package/lib/types/client/review-page/ReviewChat.d.ts +112 -0
  137. package/lib/types/client/review-page/ReviewChat.d.ts.map +1 -0
  138. package/lib/types/client/review-page/ReviewChat.js.map +1 -0
  139. package/lib/types/client/review-page/ReviewDetail.d.ts +56 -0
  140. package/lib/types/client/review-page/ReviewDetail.d.ts.map +1 -0
  141. package/lib/types/client/review-page/ReviewDetail.js.map +1 -0
  142. package/lib/types/client/review-page/ReviewLabels.d.ts +32 -0
  143. package/lib/types/client/review-page/ReviewLabels.d.ts.map +1 -0
  144. package/lib/types/client/review-page/ReviewLabels.js.map +1 -0
  145. package/lib/types/client/review-page/ReviewList.d.ts +68 -0
  146. package/lib/types/client/review-page/ReviewList.d.ts.map +1 -0
  147. package/lib/types/client/review-page/ReviewList.js.map +1 -0
  148. package/lib/types/client/review-page/ReviewNav.d.ts +28 -0
  149. package/lib/types/client/review-page/ReviewNav.d.ts.map +1 -0
  150. package/lib/types/client/review-page/ReviewNav.js.map +1 -0
  151. package/lib/types/client/review-page/ReviewPage.d.ts +61 -0
  152. package/lib/types/client/review-page/ReviewPage.d.ts.map +1 -0
  153. package/lib/types/client/review-page/ReviewPage.js.map +1 -0
  154. package/lib/types/client/review-page/ReviewStatus.d.ts +37 -0
  155. package/lib/types/client/review-page/ReviewStatus.d.ts.map +1 -0
  156. package/lib/types/client/review-page/ReviewStatus.js.map +1 -0
  157. package/lib/types/client/review-page/host-stream.d.ts +24 -0
  158. package/lib/types/client/review-page/host-stream.d.ts.map +1 -0
  159. package/lib/types/client/review-page/host-stream.js.map +1 -0
  160. package/lib/types/client/review-page/review-lists.d.ts +116 -0
  161. package/lib/types/client/review-page/review-lists.d.ts.map +1 -0
  162. package/lib/types/client/review-page/review-lists.js.map +1 -0
  163. package/lib/types/client/review-page/review-mount.d.ts +50 -0
  164. package/lib/types/client/review-page/review-mount.d.ts.map +1 -0
  165. package/lib/types/client/review-page/review-mount.js.map +1 -0
  166. package/lib/types/client/review-page/review-store.d.ts +79 -0
  167. package/lib/types/client/review-page/review-store.d.ts.map +1 -0
  168. package/lib/types/client/review-page/review-store.js.map +1 -0
  169. package/lib/types/client/review-queue.d.ts +19 -0
  170. package/lib/types/client/review-queue.d.ts.map +1 -1
  171. package/lib/types/client/review-queue.js.map +1 -1
  172. package/lib/types/client/review-threads.d.ts +0 -8
  173. package/lib/types/client/review-threads.d.ts.map +1 -1
  174. package/lib/types/client/review-threads.js.map +1 -1
  175. package/lib/types/client/review.d.ts +18 -0
  176. package/lib/types/client/review.d.ts.map +1 -1
  177. package/lib/types/client/review.js.map +1 -1
  178. package/lib/types/client/slots.d.ts +114 -0
  179. package/lib/types/client/slots.d.ts.map +1 -0
  180. package/lib/types/client/slots.js.map +1 -0
  181. package/lib/types/client/source.d.ts +29 -23
  182. package/lib/types/client/source.d.ts.map +1 -1
  183. package/lib/types/client/source.js.map +1 -1
  184. package/lib/types/client/status.d.ts +13 -2
  185. package/lib/types/client/status.d.ts.map +1 -1
  186. package/lib/types/client/status.js.map +1 -1
  187. package/lib/types/git.d.ts +4 -15
  188. package/lib/types/git.d.ts.map +1 -1
  189. package/lib/types/git.js.map +1 -1
  190. package/lib/types/index.d.ts +346 -28
  191. package/lib/types/index.d.ts.map +1 -1
  192. package/lib/types/index.js.map +1 -1
  193. package/lib/types/lens-version.d.ts +14 -0
  194. package/lib/types/lens-version.d.ts.map +1 -0
  195. package/lib/types/lens-version.js.map +1 -0
  196. package/lib/types/lenses.d.ts +122 -0
  197. package/lib/types/lenses.d.ts.map +1 -0
  198. package/lib/types/lenses.js.map +1 -0
  199. package/lib/types/local-diff.d.ts +16 -0
  200. package/lib/types/local-diff.d.ts.map +1 -1
  201. package/lib/types/local-diff.js.map +1 -1
  202. package/lib/types/panel.d.ts +59 -8
  203. package/lib/types/panel.d.ts.map +1 -1
  204. package/lib/types/panel.js.map +1 -1
  205. package/lib/types/parse.d.ts +24 -8
  206. package/lib/types/parse.d.ts.map +1 -1
  207. package/lib/types/parse.js.map +1 -1
  208. package/lib/types/review-cache.d.ts +29 -19
  209. package/lib/types/review-cache.d.ts.map +1 -1
  210. package/lib/types/review-cache.js.map +1 -1
  211. package/lib/types/states.d.ts +11 -7
  212. package/lib/types/states.d.ts.map +1 -1
  213. package/lib/types/states.js.map +1 -1
  214. package/lib/types/types.d.ts +266 -20
  215. package/lib/types/types.d.ts.map +1 -1
  216. package/lib/types/viewer-lists.d.ts +113 -0
  217. package/lib/types/viewer-lists.d.ts.map +1 -0
  218. package/lib/types/viewer-lists.js.map +1 -0
  219. package/lib/types/worktree.d.ts +20 -11
  220. package/lib/types/worktree.d.ts.map +1 -1
  221. package/lib/types/worktree.js.map +1 -1
  222. package/locale/de.json +1 -1
  223. package/locale/en.json +1 -1
  224. package/locale/es.json +1 -1
  225. package/locale/fr.json +1 -1
  226. package/locale/ja.json +1 -1
  227. package/locale/pt.json +1 -1
  228. package/locale/ru.json +1 -1
  229. package/locale/zh.json +1 -1
  230. package/package.json +61 -52
  231. package/src/branch-name.ts +74 -0
  232. package/src/client/AttentionIndicator.tsx +37 -0
  233. package/src/client/BaseMenu.module.css +0 -20
  234. package/src/client/BaseMenu.tsx +9 -52
  235. package/src/client/ChangeRequestCard.tsx +276 -131
  236. package/src/client/ChangeRequestOverview.module.css +1 -1
  237. package/src/client/ChangeRequestOverview.tsx +183 -67
  238. package/src/client/ChangeRequestsSection.tsx +234 -0
  239. package/src/client/ChangedFiles.module.css +5 -1
  240. package/src/client/ChangedFiles.tsx +72 -36
  241. package/src/client/ChangesLoading.module.css +110 -0
  242. package/src/client/ChangesLoading.tsx +69 -0
  243. package/src/client/ChangesTab.module.css +83 -114
  244. package/src/client/ChangesTab.tsx +331 -100
  245. package/src/client/ChangesTabTitle.tsx +3 -3
  246. package/src/client/DiffFile.tsx +241 -45
  247. package/src/client/EnvironmentRows.tsx +263 -0
  248. package/src/client/FileLabel.tsx +1 -1
  249. package/src/client/FileTreePane.tsx +11 -6
  250. package/src/client/{ForgeTab.module.css → Forge.module.css} +130 -275
  251. package/src/client/LensFilter.module.css +87 -0
  252. package/src/client/LensFilter.tsx +105 -0
  253. package/src/client/ReasonButton.tsx +23 -0
  254. package/src/client/ReviewComposer.module.css +2 -8
  255. package/src/client/ReviewComposer.tsx +27 -8
  256. package/src/client/ReviewControls.module.css +39 -0
  257. package/src/client/ReviewControls.tsx +71 -15
  258. package/src/client/ReviewThread.tsx +55 -30
  259. package/src/client/ReviewThreads.module.css +24 -0
  260. package/src/client/ReviewThreads.tsx +56 -21
  261. package/src/client/SessionHoverForge.tsx +2 -1
  262. package/src/client/SubmitReview.tsx +11 -8
  263. package/src/client/ThreadList.tsx +1 -1
  264. package/src/client/ViewOptionsMenu.tsx +19 -4
  265. package/src/client/WorktreeNameDialog.module.css +53 -0
  266. package/src/client/WorktreeNameDialog.tsx +93 -0
  267. package/src/client/WorktreeProgress.tsx +100 -35
  268. package/src/client/WorktreeToggle.module.css +121 -5
  269. package/src/client/WorktreeToggle.tsx +178 -61
  270. package/src/client/action-notices.ts +38 -0
  271. package/src/client/annotations.ts +105 -0
  272. package/src/client/branch-search.tsx +77 -0
  273. package/src/client/change-requests-store.ts +50 -0
  274. package/src/client/changes-address.ts +3 -1
  275. package/src/client/changes-service.ts +173 -0
  276. package/src/client/changes-store.ts +103 -91
  277. package/src/client/checkout.ts +2 -1
  278. package/src/client/diff-rows.ts +100 -16
  279. package/src/client/file-tree.ts +29 -0
  280. package/src/client/forge-copy.ts +49 -0
  281. package/src/client/format.ts +14 -0
  282. package/src/client/glyphs.tsx +12 -13
  283. package/src/client/highlight-context.ts +213 -0
  284. package/src/client/index.ts +20 -5
  285. package/src/client/lens-filter.ts +136 -0
  286. package/src/client/locales.ts +1504 -288
  287. package/src/client/mount.ts +228 -109
  288. package/src/client/review-page/ReviewChat.tsx +311 -0
  289. package/src/client/review-page/ReviewDetail.tsx +331 -0
  290. package/src/client/review-page/ReviewLabels.tsx +94 -0
  291. package/src/client/review-page/ReviewList.tsx +461 -0
  292. package/src/client/review-page/ReviewNav.tsx +47 -0
  293. package/src/client/review-page/ReviewPage.module.css +946 -0
  294. package/src/client/review-page/ReviewPage.tsx +287 -0
  295. package/src/client/review-page/ReviewStatus.tsx +259 -0
  296. package/src/client/review-page/host-stream.ts +63 -0
  297. package/src/client/review-page/review-lists.ts +207 -0
  298. package/src/client/review-page/review-mount.ts +228 -0
  299. package/src/client/review-page/review-store.ts +94 -0
  300. package/src/client/review-queue.ts +30 -0
  301. package/src/client/review-threads.ts +0 -12
  302. package/src/client/review.ts +27 -0
  303. package/src/client/slots.ts +92 -0
  304. package/src/client/source.ts +67 -43
  305. package/src/client/status.ts +16 -4
  306. package/src/git.ts +16 -38
  307. package/src/index.ts +900 -152
  308. package/src/lens-version.ts +27 -0
  309. package/src/lenses.ts +284 -0
  310. package/src/local-diff.ts +48 -1
  311. package/src/panel.ts +123 -28
  312. package/src/parse.ts +86 -10
  313. package/src/review-cache.ts +57 -37
  314. package/src/states.ts +38 -18
  315. package/src/types.ts +267 -21
  316. package/src/viewer-lists.ts +375 -0
  317. package/src/worktree.ts +64 -34
  318. package/lib/types/client/ForgeTab.d.ts +0 -65
  319. package/lib/types/client/ForgeTab.d.ts.map +0 -1
  320. package/lib/types/client/ForgeTab.js.map +0 -1
  321. package/lib/types/client/ForgeTabTitle.d.ts +0 -11
  322. package/lib/types/client/ForgeTabTitle.d.ts.map +0 -1
  323. package/lib/types/client/ForgeTabTitle.js.map +0 -1
  324. package/lib/types/client/HeaderButton.d.ts +0 -27
  325. package/lib/types/client/HeaderButton.d.ts.map +0 -1
  326. package/lib/types/client/HeaderButton.js.map +0 -1
  327. package/lib/types/client/LocalChangesCard.d.ts +0 -29
  328. package/lib/types/client/LocalChangesCard.d.ts.map +0 -1
  329. package/lib/types/client/LocalChangesCard.js.map +0 -1
  330. package/src/client/ForgeTab.tsx +0 -263
  331. package/src/client/ForgeTabTitle.tsx +0 -21
  332. package/src/client/HeaderButton.module.css +0 -29
  333. package/src/client/HeaderButton.tsx +0 -68
  334. package/src/client/LocalChangesCard.tsx +0 -83
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The version of a diff's files that a lens request names. The panel host and the changes view compute it alike, so a
3
+ * request refers to exactly the files its view shows.
4
+ */
5
+
6
+ /**
7
+ * Name the files of one diff: equal versions describe the same paths with the same changes in the same order.
8
+ * @param files - the diff's files in display order.
9
+ * @returns 14 hexadecimal digits of a 53-bit hash over each path and change digest.
10
+ */
11
+ export function lensVersion(files: readonly { readonly path: string; readonly digest: string }[]): string {
12
+ // cyrb53: two 32-bit multiply-xorshift lanes folded into 53 bits.
13
+ let h1 = 0xdeadbeef
14
+ let h2 = 0x41c6ce57
15
+ for (const file of files) {
16
+ for (const text of [file.path, '\u0000', file.digest, '\u0001']) {
17
+ for (let index = 0; index < text.length; index += 1) {
18
+ const code = text.charCodeAt(index)
19
+ h1 = Math.imul(h1 ^ code, 2654435761)
20
+ h2 = Math.imul(h2 ^ code, 1597334677)
21
+ }
22
+ }
23
+ }
24
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909)
25
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909)
26
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, '0')
27
+ }
package/src/lenses.ts ADDED
@@ -0,0 +1,284 @@
1
+ /** Filter lenses registered on the forge panel host, the runs that classify one diff with one of them, and the kept results. */
2
+
3
+ import { deadline, timeoutOf } from '@deepseek-ai/dsh-timeout'
4
+ import type {
5
+ ForgeLens, ForgeLensFile, ForgeLensFrame, ForgeLensInput, ForgeLensKeep, ForgeLensSource, ForgeRegisteredLens,
6
+ } from './types.ts'
7
+
8
+ /** The files a lens kept, by path. */
9
+ export type LensFiles = Readonly<Record<string, ForgeLensKeep>>
10
+
11
+ /** Why a lens run produced no result; the message names the cause for the reader. */
12
+ export class LensFailed extends Error {
13
+ override name = 'LensFailed'
14
+ }
15
+
16
+ /** The reason a run stops when its lens's registration ends. */
17
+ export class LensWithdrawn extends Error {
18
+ override name = 'LensWithdrawn'
19
+ }
20
+
21
+ /** One registered lens and the runs that use it. */
22
+ export interface LensRegistration {
23
+ /** The lens as its plugin registered it. */
24
+ readonly lens: ForgeLens
25
+ /** Aborts with a {@link LensWithdrawn} once the registration ends. */
26
+ readonly lifetime: AbortSignal
27
+ /**
28
+ * Keep one run among the work the registration's disposer waits for.
29
+ * @param run - the run.
30
+ * @returns the same run.
31
+ */
32
+ track<T>(run: Promise<T>): Promise<T>
33
+ }
34
+
35
+ /**
36
+ * The lenses registered on one panel host. Identities are unique while registered; the follow streams of every reader
37
+ * receive the list after each change, and end once the registry closes.
38
+ */
39
+ export class LensRegistry {
40
+ private readonly entries = new Map<string, LensRegistration>()
41
+ private readonly listeners = new Set<() => void>()
42
+ private readonly closed = new AbortController()
43
+
44
+ /**
45
+ * Register a lens.
46
+ * @param lens - the lens.
47
+ * @returns the disposer, which aborts the lens's running classifications and waits for them.
48
+ * @throws when another registration holds `lens.id`.
49
+ */
50
+ add(lens: ForgeLens): () => Promise<void> {
51
+ if (this.entries.has(lens.id)) throw new Error(`forge-panel: a lens "${lens.id}" is already registered`)
52
+ const lifetime = new AbortController()
53
+ const runs = new Set<Promise<void>>()
54
+ const registration: LensRegistration = {
55
+ lens,
56
+ lifetime: lifetime.signal,
57
+ track: (run) => {
58
+ const settled = run.then(() => undefined, () => undefined)
59
+ runs.add(settled)
60
+ void settled.then(() => runs.delete(settled))
61
+ return run
62
+ },
63
+ }
64
+ this.entries.set(lens.id, registration)
65
+ this.changed()
66
+ return async () => {
67
+ this.entries.delete(lens.id)
68
+ lifetime.abort(new LensWithdrawn(`the lens "${lens.id}" was unregistered`))
69
+ this.changed()
70
+ await Promise.allSettled([...runs])
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Find a registered lens.
76
+ * @param id - its identity.
77
+ * @returns the registration, or undefined while no lens holds the identity.
78
+ */
79
+ get(id: string): LensRegistration | undefined {
80
+ return this.entries.get(id)
81
+ }
82
+
83
+ /**
84
+ * Stream the registered lenses: the current list first, then the list after each change; changes that arrive while
85
+ * the reader is busy collapse into the next list.
86
+ * @param signal - ends the stream.
87
+ * @returns identities and versions in registration order.
88
+ */
89
+ async *follow(signal: AbortSignal): AsyncIterable<readonly ForgeRegisteredLens[]> {
90
+ const stop = AbortSignal.any([signal, this.closed.signal])
91
+ let wake = Promise.withResolvers<void>()
92
+ const listener = (): void => { wake.resolve() }
93
+ this.listeners.add(listener)
94
+ stop.addEventListener('abort', listener)
95
+ try {
96
+ while (!stop.aborted) {
97
+ const current = wake
98
+ yield [...this.entries.values()].map(({ lens }) => ({ id: lens.id, version: lens.version }))
99
+ await current.promise
100
+ wake = Promise.withResolvers()
101
+ }
102
+ } finally {
103
+ this.listeners.delete(listener)
104
+ stop.removeEventListener('abort', listener)
105
+ }
106
+ }
107
+
108
+ /** End every follow stream; registrations still end through their own disposers. */
109
+ close(): void {
110
+ this.closed.abort()
111
+ }
112
+
113
+ private changed(): void {
114
+ for (const listener of this.listeners) listener()
115
+ }
116
+ }
117
+
118
+ /** One diff a lens classifies, with the reader of its files' sides. */
119
+ export interface LensSubject {
120
+ /** What the view shows. */
121
+ readonly source: ForgeLensSource
122
+ /** Every file of the diff in display order. */
123
+ readonly files: readonly ForgeLensFile[]
124
+ /**
125
+ * Read one side of a file of `files`.
126
+ * @returns the text, or null when the side does not exist or holds binary content.
127
+ */
128
+ readonly read: (side: 'old' | 'new', file: ForgeLensFile, signal: AbortSignal) => Promise<string | null>
129
+ }
130
+
131
+ /** Bounds of one lens run, from the panel's configuration. */
132
+ export interface LensLimits {
133
+ /** `lensTimeoutMs`. */
134
+ readonly timeoutMs: number
135
+ /** `maxLensReadBytes`. */
136
+ readonly maxReadBytes: number
137
+ /** `maxCachedLensBytes`, which bounds one result as JSON. */
138
+ readonly maxResultBytes: number
139
+ }
140
+
141
+ /**
142
+ * Classify one diff with one lens. The lens's signal aborts with the caller's, when the registration ends, and after
143
+ * `timeoutMs`; the run settles then even when the lens ignores its signal, while the registration's disposer waits until
144
+ * `classify` itself settles. A run whose signal aborted before it started does not call the lens. Paths the lens names
145
+ * outside the diff are left out of the result.
146
+ * @param registration - the registered lens.
147
+ * @param subject - the diff and its reader.
148
+ * @param limits - deadline, read budget, and result bound.
149
+ * @param signal - the caller's cancellation.
150
+ * @param progress - receives the lens's progress while it runs.
151
+ * @returns the files the lens kept.
152
+ * @throws `signal.reason` once the caller aborts; a {@link LensWithdrawn} once the registration ends; a
153
+ * {@link LensFailed} when the lens rejects, runs past the deadline, reads past the budget, or answers over the bound.
154
+ */
155
+ export async function runLens(
156
+ registration: LensRegistration,
157
+ subject: LensSubject,
158
+ limits: LensLimits,
159
+ signal: AbortSignal,
160
+ progress: (done: number, total: number) => void,
161
+ ): Promise<LensFiles> {
162
+ using timer = deadline(AbortSignal.any([signal, registration.lifetime]), limits.timeoutMs, 'FORGE_LENS_TIMEOUT')
163
+ const operation = timer.signal
164
+ const byPath = new Map(subject.files.map(file => [file.path, file]))
165
+ let read = 0
166
+ const overBudget = (): LensFailed => new LensFailed(`the lens read more than maxLensReadBytes (${limits.maxReadBytes} bytes) of file text`)
167
+ const input: ForgeLensInput = {
168
+ source: subject.source,
169
+ files: subject.files,
170
+ text: async (side, path, inner) => {
171
+ const file = byPath.get(path)
172
+ if (file === undefined) throw new Error(`forge-panel: ${JSON.stringify(path)} is not a file of this diff`)
173
+ if (read > limits.maxReadBytes) throw overBudget()
174
+ const text = await subject.read(side, file, AbortSignal.any([inner, operation]))
175
+ if (text === null) return null
176
+ read += Buffer.byteLength(text)
177
+ if (read > limits.maxReadBytes) throw overBudget()
178
+ return text
179
+ },
180
+ progress: (done, total) => { if (!operation.aborted) progress(done, total) },
181
+ }
182
+ let result: Awaited<ReturnType<ForgeLens['classify']>>
183
+ try {
184
+ // A registration that ended or a caller that left before the run starts never reaches the lens.
185
+ operation.throwIfAborted()
186
+ const stopped = new Promise<never>((_resolve, reject) => {
187
+ operation.addEventListener('abort', () => { reject(new Error('the lens run stopped', { cause: operation.reason })) }, { once: true })
188
+ })
189
+ // The race observes `stopped`; this handler only keeps a later abort from rejecting unobserved.
190
+ void stopped.catch(() => undefined)
191
+ // The registration's disposer waits for the classification itself; the race only decides when the caller hears back.
192
+ const classified = registration.track(Promise.resolve().then(() => registration.lens.classify(input, operation)))
193
+ result = await Promise.race([classified, stopped])
194
+ } catch (error) {
195
+ if (signal.aborted) throw signal.reason
196
+ if (registration.lifetime.aborted) throw registration.lifetime.reason
197
+ if (timeoutOf(operation) !== undefined) throw new LensFailed(`the lens ran past lensTimeoutMs (${limits.timeoutMs} ms)`)
198
+ if (error instanceof LensFailed) throw error
199
+ throw new LensFailed(`the lens failed: ${error instanceof Error ? error.message : String(error)}`)
200
+ }
201
+ if (read > limits.maxReadBytes) throw overBudget()
202
+ const files: Record<string, ForgeLensKeep> = {}
203
+ for (const [path, keep] of Object.entries(result.files)) {
204
+ if (byPath.has(path)) files[path] = keep
205
+ }
206
+ if (Buffer.byteLength(JSON.stringify(files)) > limits.maxResultBytes) {
207
+ throw new LensFailed(`the lens result exceeds maxCachedLensBytes (${limits.maxResultBytes} bytes)`)
208
+ }
209
+ return files
210
+ }
211
+
212
+ /**
213
+ * Turn one run into frames: the latest progress whenever the lens reported some since the last frame, then the result.
214
+ * @param run - starts the run with the progress receiver.
215
+ * @returns progress frames, then one result frame.
216
+ * @throws the run's failure after its last progress frame.
217
+ */
218
+ export async function* lensFrames(
219
+ run: (progress: (done: number, total: number) => void) => Promise<LensFiles>,
220
+ ): AsyncIterable<ForgeLensFrame> {
221
+ // A box, so the reads below see what the progress callback writes.
222
+ const reports: { latest: { readonly done: number; readonly total: number } | null; finished: boolean } = { latest: null, finished: false }
223
+ // A function, so each check reads what the settlement wrote rather than the value the loop condition narrowed.
224
+ const finished = (): boolean => reports.finished
225
+ let wake = Promise.withResolvers<void>()
226
+ const outcome = run((done, total) => {
227
+ reports.latest = { done, total }
228
+ wake.resolve()
229
+ })
230
+ const settled = outcome.then(() => { reports.finished = true }, () => { reports.finished = true })
231
+ while (!finished()) {
232
+ const current = wake
233
+ await Promise.race([current.promise, settled])
234
+ wake = Promise.withResolvers()
235
+ const reported = reports.latest
236
+ reports.latest = null
237
+ if (reported !== null && !finished()) yield { kind: 'progress', done: reported.done, total: reported.total }
238
+ }
239
+ yield { kind: 'result', files: await outcome }
240
+ }
241
+
242
+ /** Lens results kept for later requests, at most `maxBytes` of them as JSON, the least recently used dropped first. */
243
+ export class LensCache {
244
+ private readonly entries = new Map<string, { readonly files: LensFiles; readonly bytes: number }>()
245
+ private bytes = 0
246
+
247
+ /** @param maxBytes - `maxCachedLensBytes`. */
248
+ constructor(private readonly maxBytes: number) {}
249
+
250
+ /**
251
+ * Read a kept result, which becomes the most recently used.
252
+ * @param key - the request's files, lens, and lens version.
253
+ * @returns the result, or undefined when none is kept.
254
+ */
255
+ get(key: string): LensFiles | undefined {
256
+ const entry = this.entries.get(key)
257
+ if (entry === undefined) return undefined
258
+ this.entries.delete(key)
259
+ this.entries.set(key, entry)
260
+ return entry.files
261
+ }
262
+
263
+ /**
264
+ * Keep a result no larger than `maxBytes`, replacing one under the same key and dropping the least recently used
265
+ * results until the rest fit.
266
+ * @param key - the request's files, lens, and lens version.
267
+ * @param files - the result.
268
+ */
269
+ set(key: string, files: LensFiles): void {
270
+ const previous = this.entries.get(key)
271
+ if (previous !== undefined) {
272
+ this.entries.delete(key)
273
+ this.bytes -= previous.bytes
274
+ }
275
+ const bytes = Buffer.byteLength(JSON.stringify(files))
276
+ this.entries.set(key, { files, bytes })
277
+ this.bytes += bytes
278
+ for (const [oldest, entry] of this.entries) {
279
+ if (this.bytes <= this.maxBytes) break
280
+ this.entries.delete(oldest)
281
+ this.bytes -= entry.bytes
282
+ }
283
+ }
284
+ }
package/src/local-diff.ts CHANGED
@@ -17,6 +17,7 @@ import { gitIn, GitOutputTooLarge } from './git.ts'
17
17
  import type { Git, GitConfig, GitOutput, Inspection } from './git.ts'
18
18
  import { ATTRIBUTES_PATH } from './layers.ts'
19
19
  import type { FileLayers } from './layers.ts'
20
+ import { branchLabel } from './branch-name.ts'
20
21
  import { BASE_REF_PREFIXES, parseBaseBranches, parseName, remoteOrder } from './parse.ts'
21
22
  import type {
22
23
  ForgeCommitRange, ForgeLocalChanges, ForgeLocalCommits, ForgeLocalDiff, ForgeLocalScope, ForgeBaseBranches, ForgeSessionWorktree,
@@ -114,7 +115,8 @@ const BINARY_PROBE = 8000
114
115
  */
115
116
  export async function forkPoint(git: Git, inspection: Inspection, created: ForgeSessionWorktree | null): Promise<ForkPoint | null> {
116
117
  if (created !== null && created.path === inspection.checkout.root) {
117
- return { commit: created.baseCommit, label: created.from ?? created.baseCommit.slice(0, 7), worktree: true }
118
+ const label = created.from === null ? created.baseCommit.slice(0, 7) : branchLabel(created.from)
119
+ return { commit: created.baseCommit, label, worktree: true }
118
120
  }
119
121
  for (const remote of remoteOrder(inspection.upstream, inspection.remotes)) {
120
122
  const head = await git('remote-head', ['symbolic-ref', '--quiet', '--short', `refs/remotes/${remote.name}/HEAD`], [0, 1, 128])
@@ -273,6 +275,51 @@ export async function localText(
273
275
  return text
274
276
  }
275
277
 
278
+ /**
279
+ * Read the old side of one changed file in a scope: the fork point for the `branch` scope, the first parent of the
280
+ * first chosen commit for chosen commits, the index for `unstaged`, else HEAD.
281
+ * @param ctx - context that provides `subprocess`, `sandbox`, and `sandboxPolicy`.
282
+ * @param config - Git and size limits.
283
+ * @param session - Session whose sandbox policy and execution world apply.
284
+ * @param root - top-level directory of the checkout.
285
+ * @param scope - the scope whose old side to read.
286
+ * @param fork - the `branch` scope's fork point, or null for other scopes.
287
+ * @param path - path relative to `root` on the old side, as the diff names it.
288
+ * @param signal - cancellation.
289
+ * @returns the text, or null when the old side has no such file or holds binary content.
290
+ * @throws NoForkPoint for the `branch` scope without `fork`; CommitsMissing for a chosen commit that is not a full
291
+ * object name; DiffTooLarge over `maxDiffBytes`; an Error for a path outside the checkout or a failed read.
292
+ */
293
+ export async function localOldText(
294
+ ctx: Context,
295
+ config: DiffConfig,
296
+ session: Session,
297
+ root: string,
298
+ scope: ForgeLocalScope,
299
+ fork: ForkPoint | null,
300
+ path: string,
301
+ signal: AbortSignal,
302
+ ): Promise<string | null> {
303
+ if (!insideCheckout(path)) throw new Error(`forge-panel: ${JSON.stringify(path)} is not a path inside the checkout`)
304
+ let revision: string
305
+ switch (scope.kind) {
306
+ case 'branch':
307
+ if (fork === null) throw new NoForkPoint('The checkout has no fork point to compare its branch with')
308
+ if (scope.commits !== null && !COMMIT.test(scope.commits.from)) throw new CommitsMissing('The chosen commit is not a full object name')
309
+ revision = scope.commits === null ? fork.commit : `${scope.commits.from}^`
310
+ break
311
+ case 'unstaged': revision = ''; break
312
+ case 'uncommitted': case 'staged': revision = 'HEAD'; break
313
+ /* v8 ignore next -- closed ForgeLocalScope union exhaustiveness guard */
314
+ default: return assertNever(scope, 'ForgeLocalScope.kind')
315
+ }
316
+ const git = gitIn(ctx, { ...config, maxOutputBytes: config.maxDiffBytes }, session, root, signal)
317
+ // Git exits with 128 for a path or revision that does not exist, such as the parent of a root commit.
318
+ const shown = await bounded(git('show', ['show', `${revision}:${path}`], [0, 128]))
319
+ if (shown.exitCode !== 0 || shown.stdout.slice(0, BINARY_PROBE).includes('\0')) return null
320
+ return shown.stdout
321
+ }
322
+
276
323
  /**
277
324
  * Measure the `branch` scope for the panel's card.
278
325
  * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
package/src/panel.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { isDeepStrictEqual } from 'node:util'
4
4
  import type { Context } from '@deepseek-ai/cordis'
5
- import type { ChangeRequestSnapshot, ForgeReadiness, ForgeRepository } from '@deepseek-ai/dsh-experimental-forge'
5
+ import type { ChangeRequestRef, ChangeRequestSnapshot, ForgeReadiness, ForgeRepository } from '@deepseek-ai/dsh-experimental-forge'
6
6
  import type { SessionChangeRequest } from '@deepseek-ai/dsh-experimental-forge-session'
7
7
  import type {} from '@deepseek-ai/dsh-experimental-worktree'
8
8
  import type {} from '@deepseek-ai/dsh-sandbox-policy'
@@ -10,7 +10,6 @@ import { pluginRecordOf } from '@deepseek-ai/dsh-session'
10
10
  import type { Session, SessionEvent } from '@deepseek-ai/dsh-session'
11
11
  import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection'
12
12
  import { deadline } from '@deepseek-ai/dsh-timeout'
13
- import type {} from '@deepseek-ai/dsh-working-directory'
14
13
  import { gitIn, hasBranch, inspectCheckout } from './git.ts'
15
14
  import type { GitConfig, Inspection } from './git.ts'
16
15
  import { localChanges } from './local-diff.ts'
@@ -20,6 +19,7 @@ import type {
20
19
  ForgeCheckoutState, ForgeLocalChanges, ForgeMissingWorktree, ForgePanelChangeRequest, ForgePanelState, ForgePanelWorktree,
21
20
  ForgeWorktreeBlocker, ForgeWorktreeState,
22
21
  } from './types.ts'
22
+ import type {} from '@deepseek-ai/dsh-working-directory'
23
23
  import { within, WORKTREE_RECORD } from './worktree.ts'
24
24
  import type { WorktreeCreations } from './worktree.ts'
25
25
 
@@ -27,6 +27,10 @@ import type { WorktreeCreations } from './worktree.ts'
27
27
  export interface PanelConfig extends DiffConfig {
28
28
  /** Deadline in milliseconds for one provider sign-in probe. */
29
29
  readonly readinessTimeoutMs: number
30
+ /** Age in milliseconds past which the status of the Session's change requests is read at once when the panel starts. */
31
+ readonly statusMaxAgeMs: number
32
+ /** Prefix of generated worktree branch names, which a name the user types starts from. */
33
+ readonly worktreePrefix: string
30
34
  }
31
35
 
32
36
  /** The checkout's upstream branch and the remote URL its change requests are looked up at. */
@@ -37,17 +41,38 @@ interface Upstream {
37
41
  readonly branch: string
38
42
  }
39
43
 
44
+ /** What the panel of a Session leaves when its last follower left, for the next panel of that Session to start from. */
45
+ export interface KeptPanel {
46
+ /** The last published state. */
47
+ readonly state: ForgePanelState
48
+ /** The latest snapshot of each change request, by URL. */
49
+ readonly snapshots: ReadonlyMap<string, ChangeRequestSnapshot>
50
+ /** Why the last inspection found that no worktree can be created. */
51
+ readonly blocker: ForgeWorktreeBlocker | null
52
+ /** The unavailable worktree the last inspection found. */
53
+ readonly missing: ForgeMissingWorktree | null
54
+ /** Remote URL and branch of the upstream that a branch lookup covered. */
55
+ readonly discovered: string | null
56
+ }
57
+
40
58
  /**
41
59
  * Panel state of one Session. Construction starts the first checkout
42
- * inspection and watches the Session's change requests. Inspections run one at
60
+ * inspection and watches the Session's change requests. A panel given what the
61
+ * previous panel of the Session kept publishes that state first, with the
62
+ * current bindings and worktree facts, unless the Session has moved to another
63
+ * directory. Inspections run one at
43
64
  * a time; a request that arrives during one runs once more after it, and a
44
65
  * result for a directory the Session has since left is dropped. A sign-in
45
- * probe runs when an inspection recognizes a new code host and on `refresh`;
66
+ * probe runs when an inspection recognizes a new code host, after the first
67
+ * inspection of a panel whose kept probe did not find the host ready, on
68
+ * `refresh`, on `revisit` while the host is not ready, and once when status
69
+ * reads on a host shown as ready start to be refused as unauthenticated;
46
70
  * a probe result for a host the panel no longer shows is dropped. Each change
47
71
  * request keeps the latest snapshot a poll returned while later polls fail.
48
72
  * When an inspection finds an upstream branch on a remote a provider
49
73
  * recognizes, the open change requests of that branch are bound as discovered,
50
- * once per remote and branch until a refresh. The
74
+ * once per remote and branch until a refresh, or until a panel starts or is
75
+ * revisited while the Session shows no change request. The
51
76
  * worktree facts follow the `forgeWorktree` projection, the live creation, and the last failed one;
52
77
  * each inspection also decides whether the Session's sandbox can write the
53
78
  * checkout and its shared Git directory, which a new worktree needs, whether
@@ -65,16 +90,22 @@ export class SessionPanel {
65
90
  private missing: ForgeMissingWorktree | null = null
66
91
  private inspection: Promise<void> | null = null
67
92
  private rerun: Promise<void> | null = null
68
- /** Remote URL and branch of the upstream that the last branch lookup covered, until a refresh. */
93
+ /** Remote URL and branch of the upstream that the last branch lookup covered, until the next lookup is due. */
69
94
  private discovered: string | null = null
95
+ /** Whether the readiness the panel started with must be probed again after its first inspection. */
96
+ private unconfirmed = false
97
+ /** Whether a refused status read already started a sign-in probe, until no status read on the host is refused. */
98
+ private questioned = false
70
99
 
71
100
  /**
72
101
  * @param ctx - service context that provides the forge, Session, directory, and process services.
73
- * @param config - Git limits and the sign-in probe deadline.
102
+ * @param config - Git limits, the sign-in probe deadline, and the worktree branch name prefix.
74
103
  * @param session - Session the panel describes.
75
104
  * @param worktreeStates - reads the `forgeWorktree` projection of the Session.
76
105
  * @param creations - reads the running creation and restoration, the last failed creation, and what a message of the
77
106
  * Session waits for.
107
+ * @param reviewRevision - reads how many review changes were announced for a change request.
108
+ * @param kept - what the previous panel of the Session kept, when there was one.
78
109
  * @param onIdle - called when the last follower leaves.
79
110
  */
80
111
  constructor(
@@ -83,23 +114,38 @@ export class SessionPanel {
83
114
  readonly session: Session,
84
115
  private readonly worktreeStates: ProjectionHandle<ForgeWorktreeState>,
85
116
  private readonly creations: Pick<WorktreeCreations, 'of' | 'restorationOf' | 'failureOf' | 'waitingOf'>,
117
+ private readonly reviewRevision: (ref: ChangeRequestRef) => number,
118
+ kept: KeptPanel | undefined,
86
119
  private readonly onIdle: () => void,
87
120
  ) {
88
- this.current = {
89
- directory: ctx.workingDirectory.get(session),
90
- checkout: { state: 'pending' },
91
- repository: null,
92
- readiness: null,
93
- changeRequests: this.entries(ctx.forgeSession.changeRequests(session)),
94
- worktree: this.worktree(),
95
- local: null,
121
+ const directory = ctx.workingDirectory.get(session)
122
+ const start = kept?.state.directory === directory ? kept : undefined
123
+ if (start !== undefined) {
124
+ for (const [url, snapshot] of start.snapshots) this.snapshots.set(url, snapshot)
125
+ this.blocker = start.blocker
126
+ this.missing = start.missing
127
+ this.unconfirmed = start.state.readiness?.state !== 'ready'
96
128
  }
97
- this.stopWatching = ctx.forgeSession.watch(session, (changeRequests) => {
98
- this.publish({ ...this.current, changeRequests: this.entries(changeRequests) })
99
- })
129
+ const changeRequests = this.entries(ctx.forgeSession.changeRequests(session))
130
+ if (start !== undefined && changeRequests.length > 0) this.discovered = start.discovered
131
+ this.current = start === undefined
132
+ ? { directory, checkout: { state: 'pending' }, repository: null, readiness: null, changeRequests, worktree: this.worktree(), local: null }
133
+ : { ...start.state, changeRequests, worktree: this.worktree() }
134
+ this.stopWatching = ctx.forgeSession.watch(session, (latest) => {
135
+ this.publish({ ...this.current, changeRequests: this.entries(latest) })
136
+ this.confirmSignIn(latest)
137
+ }, { maxAgeMs: config.statusMaxAgeMs })
100
138
  void this.inspect()
101
139
  }
102
140
 
141
+ /**
142
+ * Name what the next panel of the Session starts from.
143
+ * @returns the last published state and what the inspections and status polls found.
144
+ */
145
+ keep(): KeptPanel {
146
+ return { state: this.current, snapshots: this.snapshots, blocker: this.blocker, missing: this.missing, discovered: this.discovered }
147
+ }
148
+
103
149
  /**
104
150
  * Yield the current state, then each later state, until `signal` aborts or the panel stops.
105
151
  * @param signal - ends this follower.
@@ -139,7 +185,7 @@ export class SessionPanel {
139
185
  * @param event - committed Session event.
140
186
  */
141
187
  observe(event: SessionEvent): void {
142
- if (event.type === 'working-directory/change') {
188
+ if (event.type === 'workspace-root/change') {
143
189
  this.publish({ ...this.current, directory: event.data.cwd, checkout: { state: 'pending' }, local: null })
144
190
  void this.inspect()
145
191
  } else if (event.type === 'tool/result' || event.type === 'sandbox/mode') {
@@ -198,6 +244,29 @@ export class SessionPanel {
198
244
  await Promise.all([inspection, probe])
199
245
  }
200
246
 
247
+ /**
248
+ * Bring the panel up to date after its surface showed again: reinspect the checkout, poll each bound change request
249
+ * whose latest poll is older than `statusMaxAgeMs`, probe sign-in again unless the last probe found the host ready,
250
+ * and let the inspection look the upstream branch up again while the Session shows no change request.
251
+ * @returns settles once the inspection and the sign-in probe have ended; each poll publishes its result when it finishes.
252
+ */
253
+ async revisit(): Promise<void> {
254
+ if (this.current.changeRequests.length === 0) this.discovered = null
255
+ const inspection = this.inspect()
256
+ const { repository, readiness } = this.current
257
+ // A null readiness has its probe in flight, or due after the inspection.
258
+ const probe = repository !== null && readiness !== null && readiness.state !== 'ready' ? this.probe(repository) : undefined
259
+ for (const entry of this.current.changeRequests) {
260
+ if (entry.ref !== null) this.ctx.forge.refresh(entry.ref, { maxAgeMs: this.config.statusMaxAgeMs })
261
+ }
262
+ await Promise.all([inspection, probe])
263
+ }
264
+
265
+ /** Publish the review revisions of the bound change requests after a review change was announced. */
266
+ reviewChanged(): void {
267
+ this.publish({ ...this.current, changeRequests: this.entries(this.ctx.forgeSession.changeRequests(this.session)) })
268
+ }
269
+
201
270
  /**
202
271
  * Stop inspections, probes, and the change request watch, end every follower, and wait for pending work.
203
272
  * @returns settles once pending inspections and probes have ended.
@@ -211,7 +280,9 @@ export class SessionPanel {
211
280
  private entries(changeRequests: readonly SessionChangeRequest[]): ForgePanelChangeRequest[] {
212
281
  return changeRequests.map((entry) => {
213
282
  if (entry.update !== null && 'snapshot' in entry.update) this.snapshots.set(entry.url, entry.update.snapshot)
214
- return { ...entry, snapshot: this.snapshots.get(entry.url) ?? null }
283
+ const reviewRevision = entry.ref === null ? 0 : this.reviewRevision(entry.ref)
284
+ const forge = entry.ref === null ? null : this.ctx.forge.describe(entry.ref.repository.forge) ?? null
285
+ return { ...entry, forge, snapshot: this.snapshots.get(entry.url) ?? null, reviewRevision }
215
286
  })
216
287
  }
217
288
 
@@ -220,6 +291,7 @@ export class SessionPanel {
220
291
  return {
221
292
  editable: this.ctx.get('worktrees') !== undefined && !state.locked && state.created === null,
222
293
  blocker: this.blocker,
294
+ namePrefix: this.config.worktreePrefix,
223
295
  request: state.request,
224
296
  created: state.created,
225
297
  creation: this.creations.of(this.session),
@@ -286,9 +358,9 @@ export class SessionPanel {
286
358
  }
287
359
  let missing: ForgeMissingWorktree | null = null
288
360
  try {
289
- const state = this.worktreeStates.stateOf(this.session)
290
- missing = await missingWorktree(this.ctx, this.config, this.session, state, directory, this.lifetime.signal)
291
- } catch (_error) {
361
+ missing = await missingWorktree(
362
+ this.ctx, this.config, this.session, this.worktreeStates.stateOf(this.session), directory, this.lifetime.signal)
363
+ } catch (_worktreeUnreadable) {
292
364
  // Without an answer from the filesystem or Git the panel offers no restoration.
293
365
  }
294
366
  if (this.lifetime.signal.aborted || this.current.directory !== directory) return
@@ -297,7 +369,8 @@ export class SessionPanel {
297
369
  const sameHost = repository !== null && this.current.repository !== null && hostOf(repository) === hostOf(this.current.repository)
298
370
  const readiness = sameHost ? this.current.readiness : null
299
371
  this.publish({ ...this.current, checkout, repository, readiness, worktree: this.worktree(), local })
300
- if (repository !== null && !sameHost) void this.probe(repository)
372
+ if (repository !== null && (!sameHost || this.unconfirmed)) void this.probe(repository)
373
+ this.unconfirmed = false
301
374
  if (upstream !== null) this.discover(upstream)
302
375
  }
303
376
 
@@ -322,10 +395,13 @@ export class SessionPanel {
322
395
  if (policy.mode === 'danger-full-access') return null
323
396
  if (policy.mode === 'read-only') return 'read-only'
324
397
  const root = this.ctx.fs.processPath(await this.ctx.fs.resolve(policy.workspaceRoot, { signal: this.lifetime.signal }))
325
- return within(root, inspection.checkout.root) && within(root, inspection.commonDir) ? null : 'outside-writable-root'
398
+ // The Git directory of a linked checkout lies outside its root; a grant the policy carries for it counts.
399
+ const writable = [root, ...policy.additionalWritableRoots ?? []]
400
+ const granted = writable.some(directory => within(directory, inspection.commonDir))
401
+ return within(root, inspection.checkout.root) && granted ? null : 'outside-writable-root'
326
402
  }
327
403
 
328
- /** Measure the `branch` scope; a failed measurement only hides the local changes card. */
404
+ /** Measure the `branch` scope; a failed measurement only hides the local changes row. */
329
405
  private async localOf(inspection: Inspection): Promise<ForgeLocalChanges | null> {
330
406
  try {
331
407
  return await localChanges(this.ctx, this.config, this.session, inspection, this.worktree().created, this.lifetime.signal)
@@ -345,6 +421,25 @@ export class SessionPanel {
345
421
  return null
346
422
  }
347
423
 
424
+ /**
425
+ * Probe sign-in again when a status read on the host the panel shows as ready was refused as unauthenticated, once
426
+ * until a status read on that host is no longer refused.
427
+ */
428
+ private confirmSignIn(changeRequests: readonly SessionChangeRequest[]): void {
429
+ const { repository, readiness } = this.current
430
+ if (repository === null) return
431
+ const refused = changeRequests.some(entry => entry.ref !== null && hostOf(entry.ref.repository) === hostOf(repository)
432
+ && entry.update !== null && 'failure' in entry.update && entry.update.failure.code === 'unauthenticated')
433
+ if (!refused) {
434
+ this.questioned = false
435
+ return
436
+ }
437
+ if (this.questioned || readiness?.state !== 'ready') return
438
+ this.questioned = true
439
+ this.publish({ ...this.current, readiness: null })
440
+ void this.probe(repository)
441
+ }
442
+
348
443
  /** Probe sign-in on the repository's host; resolves once the probe has ended. */
349
444
  private probe(repository: ForgeRepository): Promise<void> {
350
445
  const host = hostOf(repository)
@@ -354,7 +449,7 @@ export class SessionPanel {
354
449
  using timeout = deadline(this.lifetime.signal, this.config.readinessTimeoutMs, 'FORGE_PANEL_READINESS_TIMEOUT')
355
450
  readiness = await this.ctx.forge.readiness(repository, timeout.signal)
356
451
  } catch (error) {
357
- readiness = { state: 'unavailable', message: error instanceof Error ? error.message : String(error) }
452
+ readiness = { state: 'unavailable', message: error instanceof Error ? error.message : String(error), signIn: null }
358
453
  }
359
454
  if (this.lifetime.signal.aborted || this.current.repository === null || hostOf(this.current.repository) !== host) return
360
455
  this.publish({ ...this.current, readiness })
@@ -399,7 +494,7 @@ export async function missingWorktree(
399
494
  const root = await ctx.fs.resolve(top.stdout.replace(/\r?\n$/, ''), { cwd: created.path, signal })
400
495
  if (root.targetKey === target.targetKey) {
401
496
  const common = await git('common-dir', ['rev-parse', '--path-format=absolute', '--git-common-dir'])
402
- const source = await gitIn(ctx, config, session, created.repositoryRoot, signal)(
497
+ const source = await gitIn(ctx, config, session, created.repositoryRoot, signal, created.repositoryRoot)(
403
498
  'common-dir', ['rev-parse', '--path-format=absolute', '--git-common-dir'],
404
499
  )
405
500
  const actual = await ctx.fs.resolve(common.stdout.replace(/\r?\n$/, ''), { cwd: created.path, signal })