@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
package/src/parse.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Parsers for the porcelain output of the read-only Git commands the panel runs. */
2
2
 
3
- import type { ForgeBaseBranch } from './types.ts'
3
+ import type { ForgeBaseBranch, ForgeRemoteDefault, ForgeWorktreeBases } from './types.ts'
4
4
 
5
5
  /** One remote with the URLs `git remote -v` prints for it. */
6
6
  export interface GitRemote {
@@ -23,7 +23,7 @@ export function parseTopLevel(output: string): string {
23
23
  }
24
24
 
25
25
  /**
26
- * Read the first line of a one-name output such as `git symbolic-ref --short HEAD`.
26
+ * Read the first line of a one-name output such as `git symbolic-ref --quiet HEAD`.
27
27
  * @param output - stdout of the command.
28
28
  * @returns the name, or null when the command printed none.
29
29
  */
@@ -67,16 +67,73 @@ export function parseBaseBranches(
67
67
  }
68
68
 
69
69
  /**
70
- * Order worktree base branches: the checked-out branch first, then the other
71
- * listed branches in listed order.
70
+ * Select the branches a new worktree can start from out of `git for-each-ref` output, keeping its order within
71
+ * each group: the checked-out branch, each remote's default branch, the other local branches, and the other
72
+ * remote-tracking branches of each remote. A remote's default branch is the branch its `refs/remotes/<remote>/HEAD`
73
+ * names; remote-tracking branches of unconfigured remotes and other symbolic refs are left out.
74
+ * @param output - stdout of `git for-each-ref --format=%(refname)%00%(symref)` over {@link BASE_REF_PREFIXES}.
72
75
  * @param current - checked-out branch, or null when HEAD is detached.
73
- * @param output - stdout of `git for-each-ref --format=%(refname:lstrip=2) refs/heads/`.
74
- * @param limit - most names to return.
75
- * @returns distinct branch names, at most `limit`.
76
+ * @param remotes - configured remotes in the order their groups take.
77
+ * @param query - text the names must contain, ignoring case; empty or blank for every branch.
78
+ * @param limit - most branches in the local group and in each remote's group.
79
+ * @param repositoryOf - the repository a remote's group names.
80
+ * @returns the branches, with remotes that have no listed branch left out.
76
81
  */
77
- export function baseBranches(current: string | null, output: string, limit: number): string[] {
78
- const listed = output.split(/\r?\n/).filter(name => name.length > 0 && name !== current)
79
- return (current === null ? listed : [current, ...listed]).slice(0, limit)
82
+ export function parseWorktreeBases(
83
+ output: string,
84
+ current: string | null,
85
+ remotes: readonly GitRemote[],
86
+ query: string,
87
+ limit: number,
88
+ repositoryOf: (remote: GitRemote) => string | null,
89
+ ): ForgeWorktreeBases {
90
+ const [heads, tracking] = BASE_REF_PREFIXES
91
+ const needle = query.trim().toLowerCase()
92
+ const matches = (name: string): boolean => name.toLowerCase().includes(needle)
93
+ const listed: string[] = []
94
+ const remoteHeads = new Map<string, string>()
95
+ for (const line of output.split(/\r?\n/)) {
96
+ const [ref = '', symref = ''] = line.split('\0')
97
+ if (ref.length === 0) continue
98
+ if (symref.length === 0) {
99
+ listed.push(ref)
100
+ continue
101
+ }
102
+ const owner = ref.startsWith(tracking) ? upstreamBranch(ref.slice(tracking.length), remotes) : undefined
103
+ if (owner?.branch === 'HEAD') remoteHeads.set(owner.remote.name, symref)
104
+ }
105
+ const present = new Set(listed)
106
+ const defaultRefs = new Set<string>()
107
+ const defaults: ForgeRemoteDefault[] = []
108
+ for (const remote of remotes) {
109
+ const target = remoteHeads.get(remote.name)
110
+ if (target === undefined || !present.has(target) || !target.startsWith(`${tracking}${remote.name}/`)) continue
111
+ defaultRefs.add(target)
112
+ const name = target.slice(tracking.length)
113
+ if (matches(name)) defaults.push({ ref: target, name, remote: remote.name })
114
+ }
115
+ const local: ForgeBaseBranch[] = []
116
+ const groups = remotes.map(remote => ({ remote, branches: [] as ForgeBaseBranch[] }))
117
+ for (const ref of listed) {
118
+ if (ref.startsWith(heads)) {
119
+ const name = ref.slice(heads.length)
120
+ if (name !== current && local.length < limit && matches(name)) local.push({ ref, name })
121
+ continue
122
+ }
123
+ if (!ref.startsWith(tracking) || defaultRefs.has(ref)) continue
124
+ const name = ref.slice(tracking.length)
125
+ const owner = upstreamBranch(name, remotes)?.remote
126
+ const group = groups.find(candidate => candidate.remote === owner)
127
+ if (group !== undefined && group.branches.length < limit && matches(name)) group.branches.push({ ref, name })
128
+ }
129
+ const currentRef = `${heads}${current ?? ''}`
130
+ return {
131
+ current: current !== null && present.has(currentRef) && matches(current) ? { ref: currentRef, name: current } : null,
132
+ defaults,
133
+ local,
134
+ remotes: groups.filter(group => group.branches.length > 0)
135
+ .map(({ remote, branches }) => ({ name: remote.name, repository: repositoryOf(remote), branches })),
136
+ }
80
137
  }
81
138
 
82
139
  /**
@@ -123,6 +180,25 @@ export function upstreamBranch(
123
180
  return remote === undefined ? undefined : { remote, branch: upstream.slice(remote.name.length + 1) }
124
181
  }
125
182
 
183
+ /**
184
+ * Name the repository a remote's group shows: `owner/name` of the first URL a provider recognizes, else the first URL
185
+ * without the user name and password a URL can carry as a token, since the name reaches the browser.
186
+ * @param remote - remote with its URLs, fetch URL first.
187
+ * @param recognize - the repository a provider recognizes from a URL, or undefined.
188
+ * @returns the name, or null for a remote without a URL.
189
+ */
190
+ export function remoteRepository(
191
+ remote: GitRemote,
192
+ recognize: (url: string) => { readonly owner: string; readonly name: string } | undefined,
193
+ ): string | null {
194
+ for (const url of remote.urls) {
195
+ const repository = recognize(url)
196
+ if (repository !== undefined) return `${repository.owner}/${repository.name}`
197
+ }
198
+ // A URL's user information ends at the last `@` before its path, query, or fragment.
199
+ return remote.urls[0]?.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/?#]*@/, '$1') ?? null
200
+ }
201
+
126
202
  /**
127
203
  * Order remotes for code host recognition: the upstream's remote first, then
128
204
  * `origin`, then the rest in listed order.
@@ -1,31 +1,32 @@
1
1
  /**
2
- * Review threads of change requests kept in memory, so the changes view reads them from the code host again only
3
- * after the change request's head or update time changes, the kept threads reach their age limit, or a review write drops them.
2
+ * Review reads of change requests kept in memory: the review threads and the viewed marks. The changes view reads
3
+ * them from the code host again only after the version they were read at changes, the kept read reaches its age
4
+ * limit, or a write drops it.
4
5
  */
5
6
 
6
7
  import { Buffer } from 'node:buffer'
7
- import type { ChangeRequestKey, ForgeReviewData } from '@deepseek-ai/dsh-experimental-forge'
8
+ import type { ChangeRequestKey } from '@deepseek-ai/dsh-experimental-forge'
8
9
 
9
- interface Entry {
10
- /** Head commit and update time the threads were read at. */
10
+ interface Entry<T> {
11
+ /** What the read was made at: the head commit and update time of review threads, the head commit of viewed marks. */
11
12
  readonly version: string
12
- readonly review: ForgeReviewData
13
+ readonly read: T
13
14
  /** Epoch milliseconds of the read. */
14
15
  readonly readAt: number
15
- /** UTF-8 size of the threads as JSON. */
16
+ /** UTF-8 size of the read as JSON. */
16
17
  readonly bytes: number
17
18
  }
18
19
 
19
20
  /**
20
- * One read of review threads per change request, bounded by age and by the total UTF-8 size of the kept reads as
21
- * JSON; the least recently read change request leaves first. A read that started before a drop of any change request
22
- * is not kept, so threads read before a write never replace the drop.
21
+ * One read of one kind per change request, bounded by age and by the total UTF-8 size of the kept reads as JSON; the
22
+ * least recently read change request leaves first. A read that started before a drop or an amendment of any change
23
+ * request is not kept, so a read made before a write never replaces what the write left.
23
24
  */
24
- export class ReviewCache {
25
- private readonly entries = new Map<ChangeRequestKey, Entry>()
25
+ export class ReviewCache<T> {
26
+ private readonly entries = new Map<ChangeRequestKey, Entry<T>>()
26
27
  private bytes = 0
27
- /** Number of drops so far. */
28
- private drops = 0
28
+ /** Number of drops and amendments so far. */
29
+ private writes = 0
29
30
 
30
31
  /**
31
32
  * @param maxBytes - most UTF-8 bytes kept together; a larger read is not kept.
@@ -34,19 +35,19 @@ export class ReviewCache {
34
35
  constructor(private readonly maxBytes: number, private readonly maxAgeMs: number) {}
35
36
 
36
37
  /**
37
- * Read the threads kept for a change request at a version while they are younger than the age limit, marking them
38
- * the most recently read.
38
+ * Read what is kept for a change request at a version while it is younger than the age limit, marking it the most
39
+ * recently read.
39
40
  * @param key - the change request.
40
- * @param version - head commit and update time the reader needs.
41
+ * @param version - the version the reader needs.
41
42
  * @param now - current epoch milliseconds.
42
- * @returns the threads, or undefined when none are kept at that version or they reached the age limit.
43
+ * @returns the kept read, or undefined when none is kept at that version or it reached the age limit.
43
44
  */
44
- get(key: ChangeRequestKey, version: string, now: number): ForgeReviewData | undefined {
45
+ get(key: ChangeRequestKey, version: string, now: number): T | undefined {
45
46
  const entry = this.entries.get(key)
46
47
  if (entry?.version !== version || now - entry.readAt >= this.maxAgeMs) return undefined
47
48
  this.entries.delete(key)
48
49
  this.entries.set(key, entry)
49
- return entry.review
50
+ return entry.read
50
51
  }
51
52
 
52
53
  /**
@@ -54,24 +55,52 @@ export class ReviewCache {
54
55
  * @returns the token of the read.
55
56
  */
56
57
  token(): number {
57
- return this.drops
58
+ return this.writes
58
59
  }
59
60
 
60
61
  /**
61
62
  * Keep a read in place of the change request's earlier one, then drop the least recently read change requests
62
- * until the rest fit within `maxBytes`. A read whose token a drop outdated is not kept.
63
+ * until the rest fit within `maxBytes`. A read whose token a drop or an amendment outdated is not kept.
63
64
  * @param key - the change request.
64
- * @param version - head commit and update time the threads were read at.
65
- * @param review - the threads.
65
+ * @param version - the version the read was made at.
66
+ * @param read - what was read.
66
67
  * @param readAt - epoch milliseconds when the read started.
67
68
  * @param token - what {@link ReviewCache.token} returned when the read started.
68
69
  */
69
- set(key: ChangeRequestKey, version: string, review: ForgeReviewData, readAt: number, token: number): void {
70
- if (token !== this.drops) return
70
+ set(key: ChangeRequestKey, version: string, read: T, readAt: number, token: number): void {
71
+ if (token !== this.writes) return
72
+ this.keep(key, version, read, readAt)
73
+ }
74
+
75
+ /**
76
+ * Forget the read kept for a change request, and every read in flight, after a write changed it.
77
+ * @param key - the change request.
78
+ */
79
+ drop(key: ChangeRequestKey): void {
80
+ this.writes += 1
81
+ this.forget(key)
82
+ }
83
+
84
+ /**
85
+ * Apply a write whose effect on the read is known: a read kept at `version` becomes `change(read)` and keeps its
86
+ * age, and one kept at another version is forgotten. Reads in flight are not kept, as after a drop.
87
+ * @param key - the change request.
88
+ * @param version - the version the write was made at.
89
+ * @param change - what the kept read is after the write.
90
+ */
91
+ amend(key: ChangeRequestKey, version: string, change: (read: T) => T): void {
92
+ this.writes += 1
93
+ const entry = this.entries.get(key)
94
+ if (entry === undefined) return
95
+ if (entry.version === version) this.keep(key, version, change(entry.read), entry.readAt)
96
+ else this.forget(key)
97
+ }
98
+
99
+ private keep(key: ChangeRequestKey, version: string, read: T, readAt: number): void {
71
100
  this.forget(key)
72
- const bytes = Buffer.byteLength(JSON.stringify(review))
101
+ const bytes = Buffer.byteLength(JSON.stringify(read))
73
102
  if (bytes > this.maxBytes) return
74
- this.entries.set(key, { version, review, readAt, bytes })
103
+ this.entries.set(key, { version, read, readAt, bytes })
75
104
  this.bytes += bytes
76
105
  for (const [oldest, entry] of this.entries) {
77
106
  if (this.bytes <= this.maxBytes) break
@@ -80,15 +109,6 @@ export class ReviewCache {
80
109
  }
81
110
  }
82
111
 
83
- /**
84
- * Forget the threads kept for a change request, and every read in flight, after a write changed them.
85
- * @param key - the change request.
86
- */
87
- drop(key: ChangeRequestKey): void {
88
- this.drops += 1
89
- this.forget(key)
90
- }
91
-
92
112
  private forget(key: ChangeRequestKey): void {
93
113
  const previous = this.entries.get(key)
94
114
  if (previous === undefined) return
package/src/states.ts CHANGED
@@ -2,16 +2,20 @@
2
2
  * The last known state of every change request that a listed Session binds,
3
3
  * for the Session list. One run starts with the first stream and stops with
4
4
  * the last: it reads the stored states, lists the Sessions with their
5
- * bindings, follows binding changes of loaded Sessions, and polls each bound
6
- * change request, once however many Sessions bind it. The forge service
7
- * owns polling cadence and terminal-state refresh. Every state change is stored, so a restart shows it before the
8
- * first poll.
5
+ * bindings, follows binding changes of loaded Sessions, and polls the brief of
6
+ * each bound change request, once however many Sessions bind it. The forge
7
+ * service owns polling cadence and terminal-state refresh; a run tells it the
8
+ * state it already holds, so a merged change request is not read again and one
9
+ * read by an earlier run of this process waits for its interval. Every state
10
+ * change is stored, so a restart shows it before the first poll.
9
11
  */
10
12
 
11
13
  import { createHash } from 'node:crypto'
12
14
  import { z } from 'zod'
13
15
  import { defineDomain } from '@deepseek-ai/dsh-storage-domain'
14
- import type { ChangeRequestListener, ChangeRequestRef, ChangeRequestSnapshot } from '@deepseek-ai/dsh-experimental-forge/types'
16
+ import type {
17
+ ChangeRequestBrief, ChangeRequestBriefListener, ChangeRequestKnownState, ChangeRequestRef,
18
+ } from '@deepseek-ai/dsh-experimental-forge/types'
15
19
  import type { SessionId } from '@deepseek-ai/dsh-session/types'
16
20
  import type { ForgeChangeRequestListState, ForgeChangeRequestStatesFrame } from './types.ts'
17
21
 
@@ -77,24 +81,24 @@ export interface ChangeRequestStateSources {
77
81
  readonly onBindings: (listener: (id: SessionId, urls: readonly string[]) => void) => () => void
78
82
  /** The change request a URL names, or undefined when no provider recognizes it. */
79
83
  readonly refOf: (url: string) => ChangeRequestRef | undefined
80
- /** Poll a change request until the returned disposer runs. */
81
- readonly watch: (ref: ChangeRequestRef, listener: ChangeRequestListener) => () => void
84
+ /** Poll the brief of a change request until the returned disposer runs; `known` times the first poll. */
85
+ readonly watch: (ref: ChangeRequestRef, listener: ChangeRequestBriefListener, known?: ChangeRequestKnownState) => () => void
82
86
  /** Open the stored states; the run owns and closes the returned handle. */
83
87
  readonly open: () => Promise<OpenedStates>
84
88
  /** Report a failed durable write; the state stays in memory. */
85
89
  readonly report: (error: unknown) => void
86
90
  }
87
91
 
88
- function listStateOf(snapshot: ChangeRequestSnapshot, url: string): ForgeChangeRequestListState {
92
+ function listStateOf(brief: ChangeRequestBrief, url: string): ForgeChangeRequestListState {
89
93
  return {
90
94
  url,
91
- number: snapshot.ref.number,
92
- title: snapshot.title,
93
- state: snapshot.state,
94
- draft: snapshot.draft,
95
- checksRollup: snapshot.checksRollup,
96
- reviewDecision: snapshot.reviewDecision,
97
- mergeability: snapshot.mergeability,
95
+ number: brief.ref.number,
96
+ title: brief.title,
97
+ state: brief.state,
98
+ draft: brief.draft,
99
+ checksRollup: brief.checksRollup,
100
+ reviewDecision: brief.reviewDecision,
101
+ mergeability: brief.mergeability,
98
102
  }
99
103
  }
100
104
 
@@ -161,10 +165,17 @@ class Run {
161
165
  private readonly writes = new Set<Promise<void>>()
162
166
  private stopped = false
163
167
 
168
+ /**
169
+ * @param sources - what the run reads, follows, and polls.
170
+ * @param readers - the streams the run publishes to.
171
+ * @param storage - the stored states, which the run owns and closes.
172
+ * @param readAt - epoch milliseconds of the latest read of each URL in this process, kept across runs.
173
+ */
164
174
  constructor(
165
175
  private readonly sources: ChangeRequestStateSources,
166
176
  private readonly readers: ReadonlySet<Reader>,
167
177
  private readonly storage: OpenedStates,
178
+ private readonly readAt: Map<string, number>,
168
179
  ) {
169
180
  for (const [, state] of storage.table.entries()) this.states.set(state.url, state)
170
181
  // Subscribe before listing; updates received during the read supersede its snapshot.
@@ -190,6 +201,7 @@ class Run {
190
201
  for (const [url] of this.states) {
191
202
  if (this.sessionsOf.has(url)) continue
192
203
  this.states.delete(url)
204
+ this.readAt.delete(url)
193
205
  this.write(() => this.storage.table.delete(storedKey(url)))
194
206
  }
195
207
  }
@@ -246,10 +258,16 @@ class Run {
246
258
  if (this.polls.has(url)) return
247
259
  const ref = this.sources.refOf(url)
248
260
  if (ref === undefined) return
261
+ const state = this.states.get(url)
262
+ // A stored state that this process has not read counts as read at the epoch, so every state but a merged one is read at once.
263
+ const known = state === undefined ? undefined : {
264
+ state: state.state, mergeability: state.mergeability, checksRollup: state.checksRollup, fetchedAt: this.readAt.get(url) ?? 0,
265
+ }
249
266
  this.polls.set(url, this.sources.watch(ref, (update) => {
250
267
  if ('failure' in update) return
251
- this.settle(url, ids, listStateOf(update.snapshot, url))
252
- }))
268
+ this.readAt.set(url, update.fetchedAt)
269
+ this.settle(url, ids, listStateOf(update.brief, url))
270
+ }, known))
253
271
  }
254
272
 
255
273
  private settle(url: string, ids: ReadonlySet<SessionId>, state: ForgeChangeRequestListState): void {
@@ -270,6 +288,8 @@ class Run {
270
288
  /** Streams the states of the change requests that listed Sessions bind. */
271
289
  export class ChangeRequestStates {
272
290
  private readonly readers = new Set<Reader>()
291
+ /** Epoch milliseconds of the latest read of each change request URL, which outlives the runs. */
292
+ private readonly readAt = new Map<string, number>()
273
293
  private stopping: Promise<void> = Promise.resolve()
274
294
  private disposed = false
275
295
  private run: { readonly started: Promise<Run | undefined>; readonly aborter: AbortController } | undefined
@@ -324,7 +344,7 @@ export class ChangeRequestStates {
324
344
  let run: Run | undefined
325
345
  try {
326
346
  aborter.signal.throwIfAborted()
327
- run = new Run(this.sources, this.readers, storage)
347
+ run = new Run(this.sources, this.readers, storage, this.readAt)
328
348
  await run.start(aborter.signal)
329
349
  return run
330
350
  } catch (error) {