@deepseek-ai/dsh-experimental-client-ui-forge 0.2.3-alpha.2 → 0.2.3-alpha.4

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 (350) hide show
  1. package/README.i18n.yaml +10 -10
  2. package/README.md +37 -19
  3. package/README.zh.md +37 -19
  4. package/lib/client.js +22 -17
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +941 -188
  7. package/lib/typert.host.js +894 -175
  8. package/lib/typert.remote-client.d.ts +35 -17
  9. package/lib/typert.remote-client.d.ts.map +1 -1
  10. package/lib/typert.remote-client.js +751 -146
  11. package/lib/types/client/ActionToast.d.ts +1 -1
  12. package/lib/types/client/ActionToast.d.ts.map +1 -1
  13. package/lib/types/client/ActionToast.js.map +1 -1
  14. package/lib/types/client/BaseMenu.d.ts +6 -4
  15. package/lib/types/client/BaseMenu.d.ts.map +1 -1
  16. package/lib/types/client/BaseMenu.js.map +1 -1
  17. package/lib/types/client/BranchPicker.d.ts +84 -0
  18. package/lib/types/client/BranchPicker.d.ts.map +1 -0
  19. package/lib/types/client/BranchPicker.js.map +1 -0
  20. package/lib/types/client/ChangeRequestCard.d.ts +31 -13
  21. package/lib/types/client/ChangeRequestCard.d.ts.map +1 -1
  22. package/lib/types/client/ChangeRequestCard.js.map +1 -1
  23. package/lib/types/client/ChangeRequestOverview.d.ts +28 -6
  24. package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -1
  25. package/lib/types/client/ChangeRequestOverview.js.map +1 -1
  26. package/lib/types/client/ChangeRequestsSection.d.ts +5 -3
  27. package/lib/types/client/ChangeRequestsSection.d.ts.map +1 -1
  28. package/lib/types/client/ChangeRequestsSection.js.map +1 -1
  29. package/lib/types/client/ChangeStatus.d.ts +41 -0
  30. package/lib/types/client/ChangeStatus.d.ts.map +1 -0
  31. package/lib/types/client/ChangeStatus.js.map +1 -0
  32. package/lib/types/client/ChangedFiles.d.ts +1 -1
  33. package/lib/types/client/ChangedFiles.d.ts.map +1 -1
  34. package/lib/types/client/ChangedFiles.js.map +1 -1
  35. package/lib/types/client/ChangesLoading.d.ts +1 -1
  36. package/lib/types/client/ChangesLoading.d.ts.map +1 -1
  37. package/lib/types/client/ChangesTab.d.ts +35 -12
  38. package/lib/types/client/ChangesTab.d.ts.map +1 -1
  39. package/lib/types/client/ChangesTab.js.map +1 -1
  40. package/lib/types/client/ChangesTabTitle.d.ts +1 -1
  41. package/lib/types/client/ChangesTabTitle.d.ts.map +1 -1
  42. package/lib/types/client/ChangesTabTitle.js.map +1 -1
  43. package/lib/types/client/CommitMenu.d.ts +11 -8
  44. package/lib/types/client/CommitMenu.d.ts.map +1 -1
  45. package/lib/types/client/CommitMenu.js.map +1 -1
  46. package/lib/types/client/CopyCommandButton.d.ts +19 -0
  47. package/lib/types/client/CopyCommandButton.d.ts.map +1 -0
  48. package/lib/types/client/CopyCommandButton.js.map +1 -0
  49. package/lib/types/client/DiffFile.d.ts +36 -5
  50. package/lib/types/client/DiffFile.d.ts.map +1 -1
  51. package/lib/types/client/DiffFile.js.map +1 -1
  52. package/lib/types/client/EnvironmentRows.d.ts +6 -6
  53. package/lib/types/client/EnvironmentRows.d.ts.map +1 -1
  54. package/lib/types/client/EnvironmentRows.js.map +1 -1
  55. package/lib/types/client/FileLabel.d.ts +5 -5
  56. package/lib/types/client/FileLabel.d.ts.map +1 -1
  57. package/lib/types/client/FileLabel.js.map +1 -1
  58. package/lib/types/client/HeadMenu.d.ts +35 -0
  59. package/lib/types/client/HeadMenu.d.ts.map +1 -0
  60. package/lib/types/client/HeadMenu.js.map +1 -0
  61. package/lib/types/client/HostSettings.d.ts +33 -0
  62. package/lib/types/client/HostSettings.d.ts.map +1 -0
  63. package/lib/types/client/HostSettings.js.map +1 -0
  64. package/lib/types/client/LensFilter.d.ts +2 -2
  65. package/lib/types/client/LensFilter.d.ts.map +1 -1
  66. package/lib/types/client/LensFilter.js.map +1 -1
  67. package/lib/types/client/ReasonButton.js.map +1 -1
  68. package/lib/types/client/RefreshGlyph.js.map +1 -1
  69. package/lib/types/client/ReviewComposer.d.ts +1 -1
  70. package/lib/types/client/ReviewComposer.d.ts.map +1 -1
  71. package/lib/types/client/ReviewComposer.js.map +1 -1
  72. package/lib/types/client/ReviewControls.d.ts +1 -1
  73. package/lib/types/client/ReviewControls.d.ts.map +1 -1
  74. package/lib/types/client/ReviewControls.js.map +1 -1
  75. package/lib/types/client/ReviewThread.d.ts +1 -1
  76. package/lib/types/client/ReviewThread.d.ts.map +1 -1
  77. package/lib/types/client/ReviewThread.js.map +1 -1
  78. package/lib/types/client/ReviewThreads.d.ts +21 -4
  79. package/lib/types/client/ReviewThreads.d.ts.map +1 -1
  80. package/lib/types/client/ReviewThreads.js.map +1 -1
  81. package/lib/types/client/SessionHoverForge.d.ts +1 -1
  82. package/lib/types/client/SessionHoverForge.d.ts.map +1 -1
  83. package/lib/types/client/SessionHoverForge.js.map +1 -1
  84. package/lib/types/client/SessionRowForge.d.ts +1 -1
  85. package/lib/types/client/SessionRowForge.d.ts.map +1 -1
  86. package/lib/types/client/SessionRowForge.js.map +1 -1
  87. package/lib/types/client/SubmitReview.d.ts +1 -1
  88. package/lib/types/client/SubmitReview.d.ts.map +1 -1
  89. package/lib/types/client/SubmitReview.js.map +1 -1
  90. package/lib/types/client/ThreadList.d.ts +3 -1
  91. package/lib/types/client/ThreadList.d.ts.map +1 -1
  92. package/lib/types/client/ThreadList.js.map +1 -1
  93. package/lib/types/client/ViewOptionsMenu.d.ts +1 -1
  94. package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -1
  95. package/lib/types/client/ViewOptionsMenu.js.map +1 -1
  96. package/lib/types/client/WorktreeNameDialog.d.ts +1 -1
  97. package/lib/types/client/WorktreeNameDialog.d.ts.map +1 -1
  98. package/lib/types/client/WorktreeNameDialog.js.map +1 -1
  99. package/lib/types/client/WorktreeProgress.d.ts +1 -1
  100. package/lib/types/client/WorktreeProgress.d.ts.map +1 -1
  101. package/lib/types/client/WorktreeProgress.js.map +1 -1
  102. package/lib/types/client/WorktreeSettings.d.ts +1 -1
  103. package/lib/types/client/WorktreeSettings.d.ts.map +1 -1
  104. package/lib/types/client/WorktreeSettings.js.map +1 -1
  105. package/lib/types/client/WorktreeToggle.d.ts +1 -1
  106. package/lib/types/client/WorktreeToggle.d.ts.map +1 -1
  107. package/lib/types/client/WorktreeToggle.js.map +1 -1
  108. package/lib/types/client/annotations.d.ts +1 -1
  109. package/lib/types/client/annotations.d.ts.map +1 -1
  110. package/lib/types/client/branch-search.d.ts +1 -1
  111. package/lib/types/client/branch-search.d.ts.map +1 -1
  112. package/lib/types/client/branch-search.js.map +1 -1
  113. package/lib/types/client/changes-address.d.ts +1 -1
  114. package/lib/types/client/changes-address.d.ts.map +1 -1
  115. package/lib/types/client/changes-service.d.ts +1 -1
  116. package/lib/types/client/changes-service.d.ts.map +1 -1
  117. package/lib/types/client/changes-store.d.ts +25 -6
  118. package/lib/types/client/changes-store.d.ts.map +1 -1
  119. package/lib/types/client/changes-store.js.map +1 -1
  120. package/lib/types/client/checkout.d.ts +1 -1
  121. package/lib/types/client/checkout.d.ts.map +1 -1
  122. package/lib/types/client/code-selection.d.ts.map +1 -1
  123. package/lib/types/client/code-selection.js.map +1 -1
  124. package/lib/types/client/forge-copy.d.ts +8 -1
  125. package/lib/types/client/forge-copy.d.ts.map +1 -1
  126. package/lib/types/client/forge-copy.js.map +1 -1
  127. package/lib/types/client/format.d.ts +1 -1
  128. package/lib/types/client/format.d.ts.map +1 -1
  129. package/lib/types/client/format.js.map +1 -1
  130. package/lib/types/client/glyphs.d.ts +36 -1
  131. package/lib/types/client/glyphs.d.ts.map +1 -1
  132. package/lib/types/client/glyphs.js.map +1 -1
  133. package/lib/types/client/highlight-context.d.ts +1 -1
  134. package/lib/types/client/highlight-context.d.ts.map +1 -1
  135. package/lib/types/client/host-settings-form.d.ts +69 -0
  136. package/lib/types/client/host-settings-form.d.ts.map +1 -0
  137. package/lib/types/client/host-settings-form.js.map +1 -0
  138. package/lib/types/client/host-sign-in.d.ts +31 -0
  139. package/lib/types/client/host-sign-in.d.ts.map +1 -0
  140. package/lib/types/client/host-sign-in.js.map +1 -0
  141. package/lib/types/client/index.d.ts +1 -2
  142. package/lib/types/client/index.d.ts.map +1 -1
  143. package/lib/types/client/index.js.map +1 -1
  144. package/lib/types/client/local-writes.d.ts +47 -0
  145. package/lib/types/client/local-writes.d.ts.map +1 -0
  146. package/lib/types/client/local-writes.js.map +1 -0
  147. package/lib/types/client/locales.d.ts +111 -13
  148. package/lib/types/client/locales.d.ts.map +1 -1
  149. package/lib/types/client/locales.js.map +1 -1
  150. package/lib/types/client/minute-clock.d.ts +7 -0
  151. package/lib/types/client/minute-clock.d.ts.map +1 -0
  152. package/lib/types/client/minute-clock.js.map +1 -0
  153. package/lib/types/client/mount.d.ts +15 -1
  154. package/lib/types/client/mount.d.ts.map +1 -1
  155. package/lib/types/client/mount.js.map +1 -1
  156. package/lib/types/client/review-page/ReviewActivity.d.ts +44 -0
  157. package/lib/types/client/review-page/ReviewActivity.d.ts.map +1 -0
  158. package/lib/types/client/review-page/ReviewActivity.js.map +1 -0
  159. package/lib/types/client/review-page/ReviewChat.d.ts +1 -1
  160. package/lib/types/client/review-page/ReviewChat.d.ts.map +1 -1
  161. package/lib/types/client/review-page/ReviewChat.js.map +1 -1
  162. package/lib/types/client/review-page/ReviewDetail.d.ts +26 -9
  163. package/lib/types/client/review-page/ReviewDetail.d.ts.map +1 -1
  164. package/lib/types/client/review-page/ReviewDetail.js.map +1 -1
  165. package/lib/types/client/review-page/ReviewLabels.d.ts +1 -1
  166. package/lib/types/client/review-page/ReviewLabels.d.ts.map +1 -1
  167. package/lib/types/client/review-page/ReviewLabels.js.map +1 -1
  168. package/lib/types/client/review-page/ReviewList.d.ts +10 -8
  169. package/lib/types/client/review-page/ReviewList.d.ts.map +1 -1
  170. package/lib/types/client/review-page/ReviewList.js.map +1 -1
  171. package/lib/types/client/review-page/ReviewNav.d.ts +1 -1
  172. package/lib/types/client/review-page/ReviewNav.d.ts.map +1 -1
  173. package/lib/types/client/review-page/ReviewPage.d.ts +17 -14
  174. package/lib/types/client/review-page/ReviewPage.d.ts.map +1 -1
  175. package/lib/types/client/review-page/ReviewPage.js.map +1 -1
  176. package/lib/types/client/review-page/ReviewSkeleton.d.ts +26 -0
  177. package/lib/types/client/review-page/ReviewSkeleton.d.ts.map +1 -0
  178. package/lib/types/client/review-page/ReviewSkeleton.js.map +1 -0
  179. package/lib/types/client/review-page/ReviewStatus.d.ts +19 -13
  180. package/lib/types/client/review-page/ReviewStatus.d.ts.map +1 -1
  181. package/lib/types/client/review-page/ReviewStatus.js.map +1 -1
  182. package/lib/types/client/review-page/review-activity.d.ts +37 -0
  183. package/lib/types/client/review-page/review-activity.d.ts.map +1 -0
  184. package/lib/types/client/review-page/review-activity.js.map +1 -0
  185. package/lib/types/client/review-page/review-lists.d.ts +48 -13
  186. package/lib/types/client/review-page/review-lists.d.ts.map +1 -1
  187. package/lib/types/client/review-page/review-lists.js.map +1 -1
  188. package/lib/types/client/review-page/review-mount.d.ts +3 -1
  189. package/lib/types/client/review-page/review-mount.d.ts.map +1 -1
  190. package/lib/types/client/review-page/review-mount.js.map +1 -1
  191. package/lib/types/client/review-page/review-store.d.ts +19 -9
  192. package/lib/types/client/review-page/review-store.d.ts.map +1 -1
  193. package/lib/types/client/review-page/review-store.js.map +1 -1
  194. package/lib/types/client/review-queue.d.ts +1 -1
  195. package/lib/types/client/review-queue.d.ts.map +1 -1
  196. package/lib/types/client/review-queue.js.map +1 -1
  197. package/lib/types/client/review-threads.d.ts +15 -8
  198. package/lib/types/client/review-threads.d.ts.map +1 -1
  199. package/lib/types/client/review-threads.js.map +1 -1
  200. package/lib/types/client/review.d.ts +12 -1
  201. package/lib/types/client/review.d.ts.map +1 -1
  202. package/lib/types/client/review.js.map +1 -1
  203. package/lib/types/client/row-form-labels.d.ts +12 -0
  204. package/lib/types/client/row-form-labels.d.ts.map +1 -0
  205. package/lib/types/client/row-form-labels.js.map +1 -0
  206. package/lib/types/client/session-list.d.ts +1 -1
  207. package/lib/types/client/session-list.d.ts.map +1 -1
  208. package/lib/types/client/slots.d.ts +1 -1
  209. package/lib/types/client/slots.d.ts.map +1 -1
  210. package/lib/types/client/source.d.ts +1 -1
  211. package/lib/types/client/source.d.ts.map +1 -1
  212. package/lib/types/client/status.d.ts +7 -6
  213. package/lib/types/client/status.d.ts.map +1 -1
  214. package/lib/types/client/status.js.map +1 -1
  215. package/lib/types/client/thread-state.d.ts +2 -2
  216. package/lib/types/client/thread-state.d.ts.map +1 -1
  217. package/lib/types/client/thread-state.js.map +1 -1
  218. package/lib/types/client/toolbar-fold.d.ts +16 -6
  219. package/lib/types/client/toolbar-fold.d.ts.map +1 -1
  220. package/lib/types/client/toolbar-fold.js.map +1 -1
  221. package/lib/types/client/worktree-settings-form.d.ts +1 -1
  222. package/lib/types/client/worktree-settings-form.d.ts.map +1 -1
  223. package/lib/types/client/worktree-settings-form.js.map +1 -1
  224. package/lib/types/diff.d.ts.map +1 -1
  225. package/lib/types/diff.js.map +1 -1
  226. package/lib/types/git.d.ts +22 -0
  227. package/lib/types/git.d.ts.map +1 -1
  228. package/lib/types/git.js.map +1 -1
  229. package/lib/types/index.d.ts +137 -36
  230. package/lib/types/index.d.ts.map +1 -1
  231. package/lib/types/index.js.map +1 -1
  232. package/lib/types/local-diff.d.ts +81 -23
  233. package/lib/types/local-diff.d.ts.map +1 -1
  234. package/lib/types/local-diff.js.map +1 -1
  235. package/lib/types/local-write.d.ts +44 -0
  236. package/lib/types/local-write.d.ts.map +1 -0
  237. package/lib/types/local-write.js.map +1 -0
  238. package/lib/types/panel.js.map +1 -1
  239. package/lib/types/parse.d.ts +12 -3
  240. package/lib/types/parse.d.ts.map +1 -1
  241. package/lib/types/parse.js.map +1 -1
  242. package/lib/types/restore.d.ts +12 -0
  243. package/lib/types/restore.d.ts.map +1 -0
  244. package/lib/types/restore.js.map +1 -0
  245. package/lib/types/types.d.ts +128 -13
  246. package/lib/types/types.d.ts.map +1 -1
  247. package/lib/types/viewer-lists.d.ts +22 -13
  248. package/lib/types/viewer-lists.d.ts.map +1 -1
  249. package/lib/types/viewer-lists.js.map +1 -1
  250. package/lib/types/worktree.js.map +1 -1
  251. package/package.json +62 -58
  252. package/src/client/ActionToast.tsx +2 -2
  253. package/src/client/BaseMenu.module.css +15 -3
  254. package/src/client/BaseMenu.tsx +25 -88
  255. package/src/client/BranchPicker.tsx +170 -0
  256. package/src/client/ChangeRequestCard.tsx +194 -70
  257. package/src/client/ChangeRequestOverview.tsx +194 -82
  258. package/src/client/ChangeRequestsSection.tsx +45 -14
  259. package/src/client/ChangeStatus.module.css +70 -0
  260. package/src/client/ChangeStatus.tsx +104 -0
  261. package/src/client/ChangedFiles.tsx +22 -9
  262. package/src/client/ChangesLoading.tsx +1 -1
  263. package/src/client/ChangesTab.module.css +181 -33
  264. package/src/client/ChangesTab.tsx +499 -183
  265. package/src/client/ChangesTabTitle.tsx +2 -2
  266. package/src/client/CommitMenu.tsx +83 -42
  267. package/src/client/CopyCommandButton.tsx +25 -0
  268. package/src/client/DiffFile.tsx +147 -29
  269. package/src/client/EnvironmentRows.tsx +34 -28
  270. package/src/client/FileLabel.module.css +16 -18
  271. package/src/client/FileLabel.tsx +16 -32
  272. package/src/client/Forge.module.css +26 -6
  273. package/src/client/HeadMenu.tsx +69 -0
  274. package/src/client/HostSettings.module.css +194 -0
  275. package/src/client/HostSettings.tsx +194 -0
  276. package/src/client/LensFilter.tsx +13 -11
  277. package/src/client/ReasonButton.tsx +1 -1
  278. package/src/client/RefreshGlyph.tsx +1 -1
  279. package/src/client/ReviewComposer.tsx +31 -19
  280. package/src/client/ReviewControls.tsx +18 -9
  281. package/src/client/ReviewThread.tsx +65 -23
  282. package/src/client/ReviewThreads.tsx +133 -38
  283. package/src/client/SessionHoverForge.tsx +2 -2
  284. package/src/client/SessionRowForge.tsx +2 -2
  285. package/src/client/SubmitReview.tsx +7 -5
  286. package/src/client/ThreadList.module.css +4 -3
  287. package/src/client/ThreadList.tsx +11 -8
  288. package/src/client/ViewOptionsMenu.tsx +12 -10
  289. package/src/client/WorktreeNameDialog.tsx +17 -13
  290. package/src/client/WorktreeProgress.tsx +13 -11
  291. package/src/client/WorktreeSettings.tsx +8 -14
  292. package/src/client/WorktreeToggle.tsx +67 -37
  293. package/src/client/annotations.ts +1 -1
  294. package/src/client/branch-search.tsx +2 -2
  295. package/src/client/changes-address.ts +1 -1
  296. package/src/client/changes-service.ts +1 -1
  297. package/src/client/changes-store.ts +57 -10
  298. package/src/client/checkout.ts +1 -1
  299. package/src/client/code-selection.ts +3 -1
  300. package/src/client/forge-copy.ts +11 -1
  301. package/src/client/format.ts +2 -2
  302. package/src/client/glyphs.tsx +72 -5
  303. package/src/client/highlight-context.ts +1 -1
  304. package/src/client/host-settings-form.ts +115 -0
  305. package/src/client/host-sign-in.ts +46 -0
  306. package/src/client/index.ts +1 -2
  307. package/src/client/local-writes.ts +129 -0
  308. package/src/client/locales.ts +881 -97
  309. package/src/client/minute-clock.ts +19 -0
  310. package/src/client/mount.ts +121 -57
  311. package/src/client/review-page/ReviewActivity.tsx +406 -0
  312. package/src/client/review-page/ReviewChat.tsx +48 -19
  313. package/src/client/review-page/ReviewDetail.tsx +246 -78
  314. package/src/client/review-page/ReviewLabels.tsx +2 -2
  315. package/src/client/review-page/ReviewList.tsx +173 -151
  316. package/src/client/review-page/ReviewNav.tsx +1 -1
  317. package/src/client/review-page/ReviewPage.module.css +571 -23
  318. package/src/client/review-page/ReviewPage.tsx +84 -53
  319. package/src/client/review-page/ReviewSkeleton.tsx +108 -0
  320. package/src/client/review-page/ReviewStatus.tsx +74 -44
  321. package/src/client/review-page/review-activity.ts +64 -0
  322. package/src/client/review-page/review-lists.ts +85 -22
  323. package/src/client/review-page/review-mount.ts +24 -7
  324. package/src/client/review-page/review-store.ts +24 -7
  325. package/src/client/review-queue.ts +7 -3
  326. package/src/client/review-threads.ts +24 -12
  327. package/src/client/review.ts +20 -2
  328. package/src/client/row-form-labels.ts +17 -0
  329. package/src/client/session-list.ts +1 -1
  330. package/src/client/slots.ts +1 -1
  331. package/src/client/source.ts +1 -1
  332. package/src/client/status.ts +20 -9
  333. package/src/client/thread-state.ts +8 -7
  334. package/src/client/toolbar-fold.ts +59 -14
  335. package/src/client/worktree-settings-form.ts +1 -1
  336. package/src/diff.ts +8 -5
  337. package/src/git.ts +31 -1
  338. package/src/index.ts +319 -70
  339. package/src/local-diff.ts +151 -48
  340. package/src/local-write.ts +159 -0
  341. package/src/panel.ts +1 -1
  342. package/src/parse.ts +26 -4
  343. package/src/restore.ts +15 -0
  344. package/src/types.ts +121 -17
  345. package/src/viewer-lists.ts +124 -48
  346. package/src/worktree.ts +1 -1
  347. package/lib/types/client/AttentionIndicator.d.ts +0 -22
  348. package/lib/types/client/AttentionIndicator.d.ts.map +0 -1
  349. package/lib/types/client/AttentionIndicator.js.map +0 -1
  350. package/src/client/AttentionIndicator.tsx +0 -37
package/src/local-diff.ts CHANGED
@@ -18,9 +18,10 @@ 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
20
  import { branchLabel } from './branch-name.ts'
21
- import { BASE_REF_PREFIXES, parseBaseBranches, parseName, remoteOrder } from './parse.ts'
21
+ import { BASE_REF_PREFIXES, parseBaseBranches, parseName, parseWorktrees, remoteOrder } from './parse.ts'
22
22
  import type {
23
- ForgeCommitRange, ForgeLocalChanges, ForgeLocalCommits, ForgeLocalDiff, ForgeLocalScope, ForgeBaseBranches, ForgeSessionWorktree,
23
+ ForgeBaseBranches, ForgeCheckout, ForgeCommitRange, ForgeLocalChanges, ForgeLocalCommits, ForgeLocalDiff, ForgeLocalScope,
24
+ ForgeSessionWorktree,
24
25
  } from './types.ts'
25
26
  import type { ForgeCommit } from '@deepseek-ai/dsh-experimental-forge/types'
26
27
 
@@ -62,6 +63,11 @@ export class BaseMissing extends Error {
62
63
  override name = 'BaseMissing'
63
64
  }
64
65
 
66
+ /** Thrown when the branch a scope reads in place of the checked-out one does not exist. */
67
+ export class HeadMissing extends Error {
68
+ override name = 'HeadMissing'
69
+ }
70
+
65
71
  /** Thrown when chosen commits are not among the commits of the `branch` scope, or are out of order. */
66
72
  export class CommitsMissing extends Error {
67
73
  override name = 'CommitsMissing'
@@ -104,17 +110,51 @@ async function diffFilterOverrides(git: Git): Promise<Readonly<Record<string, st
104
110
  const BINARY_PROBE = 8000
105
111
 
106
112
  /**
107
- * Find where the `branch` scope forks while no base branch is chosen: the base commit of the worktree the
108
- * Session created while the checkout is that worktree, else the merge base of
109
- * HEAD with the default branch of the first remote that names one, in the
110
- * order the panel recognizes code hosts.
113
+ * The Session's own HEAD, which a branch shown in place of the Session's checkout is compared with while no base
114
+ * branch is chosen: a reader of another branch asks what it changed since it left the Session's work.
115
+ */
116
+ export interface SessionHead {
117
+ /** Full object name of the commit the Session's HEAD names. */
118
+ readonly commit: string
119
+ /** Name the panel shows for it: the checked-out branch, or the abbreviated commit of a detached HEAD. */
120
+ readonly label: string
121
+ /** Full ref of the checked-out branch, which the automatic base stands for in a base listing; null when HEAD is detached. */
122
+ readonly ref: string | null
123
+ }
124
+
125
+ /**
126
+ * Read the Session's own HEAD.
127
+ * @param git - runner bound to the Session's checkout.
128
+ * @param checkout - that checkout.
129
+ * @returns the commit and its name, or null while the checked-out branch has no commit.
130
+ * @throws an Error when Git fails.
131
+ */
132
+ export async function sessionHead(git: Git, checkout: ForgeCheckout): Promise<SessionHead | null> {
133
+ const head = await git('session-head', ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}'], [0, 1])
134
+ const commit = head.exitCode === 0 ? parseName(head.stdout) : null
135
+ if (commit === null) return null
136
+ return checkout.branch === null ? { commit, label: commit.slice(0, 7), ref: null }
137
+ : { commit, label: checkout.branch, ref: `${BASE_REF_PREFIXES[0]}${checkout.branch}` }
138
+ }
139
+
140
+ /**
141
+ * Find where the `branch` scope forks while no base branch is chosen. For a branch shown in place of the Session's
142
+ * checkout: the merge base of the tip with the Session's own HEAD. For the Session's checkout: the base commit of the
143
+ * worktree the Session created while the checkout is that worktree, else the merge base of HEAD with the default
144
+ * branch of the first remote that names one, in the order the panel recognizes code hosts.
111
145
  * @param git - runner bound to the checkout.
112
146
  * @param inspection - the checkout and its remotes.
113
- * @param created - worktree the Session created, or null.
114
- * @returns the fork point, or null when no remote names a default branch or HEAD shares no history with it.
147
+ * @param created - worktree the checkout's Session created, or null.
148
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref, which no created worktree applies to.
149
+ * @param against - the Session's own HEAD while the scope shows another branch, or null for the Session's checkout.
150
+ * @returns the fork point, or null when the tip shares no history with what it is compared with, or no remote names
151
+ * a default branch for the Session's checkout.
115
152
  */
116
- export async function forkPoint(git: Git, inspection: Inspection, created: ForgeSessionWorktree | null): Promise<ForkPoint | null> {
117
- if (created !== null && created.path === inspection.checkout.root) {
153
+ export async function forkPoint(
154
+ git: Git, inspection: Inspection, created: ForgeSessionWorktree | null, tip = 'HEAD', against: SessionHead | null = null,
155
+ ): Promise<ForkPoint | null> {
156
+ if (against !== null) return await mergeBase(git, tip, against.commit, against.label)
157
+ if (tip === 'HEAD' && created !== null && created.path === inspection.checkout.root) {
118
158
  const label = created.from === null ? created.baseCommit.slice(0, 7) : branchLabel(created.from)
119
159
  return { commit: created.baseCommit, label, worktree: true }
120
160
  }
@@ -122,40 +162,66 @@ export async function forkPoint(git: Git, inspection: Inspection, created: Forge
122
162
  const head = await git('remote-head', ['symbolic-ref', '--quiet', '--short', `refs/remotes/${remote.name}/HEAD`], [0, 1, 128])
123
163
  const base = head.exitCode === 0 ? parseName(head.stdout) : null
124
164
  if (base === null) continue
125
- const merge = await git('merge-base', ['merge-base', 'HEAD', base], [0, 1, 128])
126
- const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null
127
- return commit === null ? null : { commit, label: base, worktree: false }
165
+ return await mergeBase(git, tip, base, base)
128
166
  }
129
167
  return null
130
168
  }
131
169
 
170
+ /** The merge base of the tip with a revision, under the name the panel shows for that revision; null without shared history. */
171
+ async function mergeBase(git: Git, tip: string, revision: string, label: string): Promise<ForkPoint | null> {
172
+ const merge = await git('merge-base', ['merge-base', tip, revision], [0, 1, 128])
173
+ const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null
174
+ return commit === null ? null : { commit, label, worktree: false }
175
+ }
176
+
132
177
  /**
133
- * Find where the `branch` scope forks from a chosen base branch: the merge base of HEAD with it.
178
+ * Find where the `branch` scope forks from a chosen base branch: the merge base of the tip with it.
134
179
  * @param git - runner bound to the checkout.
135
180
  * @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
136
- * @returns the fork point, or null when HEAD shares no history with the branch or has no commit.
181
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref.
182
+ * @returns the fork point, or null when the tip shares no history with the branch or has no commit.
137
183
  * @throws BaseMissing when the ref does not exist; an Error for another ref name or when Git fails.
138
184
  */
139
- export async function chosenForkPoint(git: Git, ref: string): Promise<ForkPoint | null> {
185
+ export async function chosenForkPoint(git: Git, ref: string, tip = 'HEAD'): Promise<ForkPoint | null> {
186
+ const { name, present } = await branchOf(git, ref)
187
+ if (!present) throw new BaseMissing(`The base branch ${name} does not exist`)
188
+ return await mergeBase(git, tip, ref, name)
189
+ }
190
+
191
+ /**
192
+ * Check the branch a scope shows in place of the checkout.
193
+ * @param git - runner bound to a checkout of the repository.
194
+ * @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
195
+ * @returns the ref, which Git may receive as a revision.
196
+ * @throws HeadMissing when the ref does not exist; an Error for another ref name or when Git fails.
197
+ */
198
+ export async function branchTip(git: Git, ref: string): Promise<string> {
199
+ const { name, present } = await branchOf(git, ref)
200
+ if (!present) throw new HeadMissing(`The branch ${name} does not exist`)
201
+ return ref
202
+ }
203
+
204
+ /** The name of a branch ref and whether the ref exists; another ref name is refused before Git reads it. */
205
+ async function branchOf(git: Git, ref: string): Promise<{ readonly name: string; readonly present: boolean }> {
140
206
  const prefix = BASE_REF_PREFIXES.find(candidate => ref.startsWith(candidate) && ref.length > candidate.length)
141
207
  if (prefix === undefined) throw new Error(`forge-panel: ${JSON.stringify(ref)} is not a branch ref`)
142
- const name = ref.slice(prefix.length)
143
208
  // `--verify` accepts only an exact ref path, so revision syntax such as `@{1}` never resolves.
144
209
  const present = await git('show-ref', ['show-ref', '--verify', '--quiet', ref], [0, 1])
145
- if (present.exitCode !== 0) throw new BaseMissing(`The base branch ${name} does not exist`)
146
- const merge = await git('merge-base', ['merge-base', 'HEAD', ref], [0, 1, 128])
147
- const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null
148
- return commit === null ? null : { commit, label: name, worktree: false }
210
+ return { name: ref.slice(prefix.length), present: present.exitCode === 0 }
149
211
  }
150
212
 
151
213
  /**
152
214
  * List the branches the `branch` scope can compare with.
153
215
  * @param git - runner bound to the checkout.
154
216
  * @param inspection - the checkout and its remotes.
155
- * @param created - worktree the Session created, or null.
217
+ * @param created - worktree the checkout's Session created, or null.
156
218
  * @param query - text the branch names must contain, ignoring case; empty for every branch.
157
219
  * @param limit - most branches in each group.
158
- * @returns the automatic fork point, then remote-tracking and local branches, most recently committed first.
220
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref, which the listing leaves out.
221
+ * @param against - the Session's own HEAD while the scope shows another branch, or null for the Session's checkout;
222
+ * the listing leaves its branch out, because the automatic fork point already compares with it.
223
+ * @returns the automatic fork point, then remote-tracking and local branches, most recently committed first; a local
224
+ * branch that a worktree has checked out names the directory Git registered for it.
159
225
  * @throws an Error when Git fails or prints more than the runner's output limit.
160
226
  */
161
227
  export async function baseBranches(
@@ -164,17 +230,38 @@ export async function baseBranches(
164
230
  created: ForgeSessionWorktree | null,
165
231
  query: string,
166
232
  limit: number,
233
+ tip = 'HEAD',
234
+ against: SessionHead | null = null,
167
235
  ): Promise<ForgeBaseBranches> {
168
- const fork = await forkPoint(git, inspection, created)
236
+ const fork = await forkPoint(git, inspection, created, tip, against)
169
237
  const refs = await git('base-branches', [
170
238
  'for-each-ref', '--sort=-committerdate', '--format=%(refname)%00%(symref)', ...BASE_REF_PREFIXES,
171
239
  ])
240
+ const shown = tip !== 'HEAD' ? tip : inspection.checkout.branch === null ? null : `${BASE_REF_PREFIXES[0]}${inspection.checkout.branch}`
241
+ const hidden = [shown, against === null ? null : against.ref].filter(ref => ref !== null)
242
+ const { remote, local } = parseBaseBranches(refs.stdout, hidden, query, limit)
243
+ const trees = await branchWorktrees(git)
172
244
  return {
173
245
  automatic: fork === null ? null : { name: fork.label, worktree: fork.worktree },
174
- ...parseBaseBranches(refs.stdout, inspection.checkout.branch, query, limit),
246
+ remote,
247
+ local: local.map((branch) => {
248
+ const worktree = trees.get(branch.ref)
249
+ return worktree === undefined ? branch : { ...branch, worktree }
250
+ }),
175
251
  }
176
252
  }
177
253
 
254
+ /**
255
+ * Find the worktree of the repository that has each branch checked out.
256
+ * @param git - runner bound to a checkout of the repository.
257
+ * @returns the directory Git registered for each checked-out branch, by full ref name, without a worktree that Git
258
+ * marks as gone and one without a branch. {@link parseWorktrees} says why a caller confirms the directory.
259
+ * @throws an Error when Git fails or prints more than the runner's output limit.
260
+ */
261
+ export async function branchWorktrees(git: Git): Promise<ReadonlyMap<string, string>> {
262
+ return parseWorktrees((await git('worktrees', ['worktree', 'list', '--porcelain'])).stdout)
263
+ }
264
+
178
265
  /**
179
266
  * Read changes at `root` with command-local clean/process filter overrides and without
180
267
  * submodule working-tree inspection. Git's built-in newline, ident, and encoding conversions still apply.
@@ -183,12 +270,14 @@ export async function baseBranches(
183
270
  * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
184
271
  * @param config - Git and size limits.
185
272
  * @param session - Session whose sandbox policy and execution world apply.
186
- * @param root - top-level directory of the checkout.
273
+ * @param root - top-level directory of the checkout the scope reads: the Session's own, or the worktree of its `head`.
187
274
  * @param fork - fork point of the `branch` scope, or null without one.
188
- * @param scope - which changes to read.
275
+ * @param scope - which changes to read; its `head` is already resolved into `root` and `tip`.
189
276
  * @param layers - classifier of each file's review layer.
190
277
  * @param signal - cancellation of every command and read.
191
- * @returns tracked files in Git's order, then untracked files unless the scope is `staged`.
278
+ * @param tip - `HEAD` to read the checkout at `root` with its working tree, or a verified branch ref that the
279
+ * `branch` scope reads from its commits alone.
280
+ * @returns tracked files in Git's order, then untracked files unless the scope is `staged` or reads a branch's commits.
192
281
  * @throws NoForkPoint for the `branch` scope without `fork`; FilterConfigError when filter configuration
193
282
  * cannot be read within `maxDiffBytes`; DiffTooLarge for oversized comparison output or `.gitattributes`;
194
283
  * an Error when Git or the `.gitattributes` read fails.
@@ -202,13 +291,15 @@ export async function localDiff(
202
291
  scope: ForgeLocalScope,
203
292
  layers: FileLayers,
204
293
  signal: AbortSignal,
294
+ tip = 'HEAD',
205
295
  ): Promise<ForgeLocalDiff> {
206
296
  const git = gitIn(ctx, { ...config, maxOutputBytes: config.maxDiffBytes }, session, root, signal)
207
297
  let range: readonly string[]
208
298
  switch (scope.kind) {
209
299
  case 'branch':
210
300
  if (fork === null) throw new NoForkPoint('The checkout has no fork point to compare its branch with')
211
- if (scope.commits !== null) return await commitsDiff(git, fork, scope.commits, layers)
301
+ if (scope.commits !== null) return await commitsDiff(git, fork, scope.commits, layers, tip)
302
+ if (tip !== 'HEAD') return await treeDiff(git, fork, fork.commit, tip, layers)
212
303
  range = [fork.commit]
213
304
  break
214
305
  case 'uncommitted': range = [await headOrEmptyTree(git)]; break
@@ -240,7 +331,7 @@ export async function localDiff(
240
331
  /**
241
332
  * Read the new side of one file in a scope, which supplies the unchanged
242
333
  * lines between hunks: the index for `staged`, the last chosen commit for
243
- * chosen commits of the `branch` scope, else the working tree.
334
+ * chosen commits of the `branch` scope, the branch for a head read from its commits, else the working tree.
244
335
  * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
245
336
  * @param config - Git and size limits.
246
337
  * @param session - Session whose sandbox policy and execution world apply.
@@ -248,6 +339,7 @@ export async function localDiff(
248
339
  * @param scope - the scope whose new side to read.
249
340
  * @param path - path relative to `root`, as the diff names it.
250
341
  * @param signal - cancellation.
342
+ * @param tip - `HEAD` for the checkout at `root`, or a verified branch ref whose commits the `branch` scope reads.
251
343
  * @returns the text.
252
344
  * @throws DiffTooLarge over `maxDiffBytes`; an Error for a path outside the checkout, binary content, or a failed read.
253
345
  */
@@ -259,12 +351,14 @@ export async function localText(
259
351
  scope: ForgeLocalScope,
260
352
  path: string,
261
353
  signal: AbortSignal,
354
+ tip = 'HEAD',
262
355
  ): Promise<string> {
263
356
  if (!insideCheckout(path)) throw new Error(`forge-panel: ${JSON.stringify(path)} is not a path inside the checkout`)
264
357
  let text: string | undefined
265
- const commit = scope.kind === 'staged' ? '' : scope.kind === 'branch' && scope.commits !== null ? scope.commits.to : undefined
358
+ const chosen = scope.kind === 'branch' && scope.commits !== null ? scope.commits.to : undefined
359
+ if (chosen !== undefined && !COMMIT.test(chosen)) throw new CommitsMissing('The chosen commit is not a full object name')
360
+ const commit = scope.kind === 'staged' ? '' : chosen ?? (scope.kind === 'branch' && tip !== 'HEAD' ? tip : undefined)
266
361
  if (commit !== undefined) {
267
- if (commit !== '' && !COMMIT.test(commit)) throw new CommitsMissing('The chosen commit is not a full object name')
268
362
  const git = gitIn(ctx, { ...config, maxOutputBytes: config.maxDiffBytes }, session, root, signal)
269
363
  const shown = (await bounded(git('show', ['show', `${commit}:${path}`]))).stdout
270
364
  text = shown.slice(0, BINARY_PROBE).includes('\0') ? undefined : shown
@@ -374,27 +468,28 @@ export async function aheadOf(git: Git, branch: string, commit: string): Promise
374
468
  }
375
469
 
376
470
  /**
377
- * List the commits of the `branch` scope: those reachable from HEAD but not from the fork point, parents before children.
471
+ * List the commits of the `branch` scope: those reachable from the tip but not from the fork point, parents before children.
378
472
  * @param git - runner bound to the checkout, whose output limit bounds the listing.
379
473
  * @param fork - fork point of the `branch` scope.
380
474
  * @param limit - most commits listed.
381
- * @returns the newest `limit` commits, ending with HEAD's commit, and HEAD's commit.
475
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref.
476
+ * @returns the newest `limit` commits, ending with the tip's commit, and the tip's commit.
382
477
  * @throws an Error when Git fails or prints more than the runner's output limit.
383
478
  */
384
- export async function localCommits(git: Git, fork: ForkPoint, limit: number): Promise<ForgeLocalCommits> {
385
- const head = (await git('head', ['rev-parse', '--verify', 'HEAD'])).stdout.trim()
386
- const listed = await branchCommits(git, fork, limit + 1)
479
+ export async function localCommits(git: Git, fork: ForkPoint, limit: number, tip = 'HEAD'): Promise<ForgeLocalCommits> {
480
+ const head = (await git('head', ['rev-parse', '--verify', tip])).stdout.trim()
481
+ const listed = await branchCommits(git, fork, tip, limit + 1)
387
482
  return { headSha: head, commits: listed.slice(-limit), truncated: listed.length > limit }
388
483
  }
389
484
 
390
485
  /**
391
- * Commits between the fork point and HEAD, parents before children.
486
+ * Commits between the fork point and the tip, parents before children.
392
487
  * @param limit - when given, only the newest `limit` commits in topological order.
393
488
  */
394
- async function branchCommits(git: Git, fork: ForkPoint, limit?: number): Promise<ForgeCommit[]> {
489
+ async function branchCommits(git: Git, fork: ForkPoint, tip: string, limit?: number): Promise<ForgeCommit[]> {
395
490
  // A configured `log.showSignature` would print verification text before the fields and run the verifying program.
396
491
  const count = limit === undefined ? [] : [`--max-count=${String(limit)}`]
397
- const output = await git('log', ['log', '--no-show-signature', '--topo-order', '--reverse', ...count, LOG_FORMAT, `${fork.commit}..HEAD`, '--'])
492
+ const output = await git('log', ['log', '--no-show-signature', '--topo-order', '--reverse', ...count, LOG_FORMAT, `${fork.commit}..${tip}`, '--'])
398
493
  return output.stdout.split('\x1e').flatMap((record): ForgeCommit[] => {
399
494
  const fields = record.replace(/^\n/, '').split('\0')
400
495
  // The text after the last record holds no fields.
@@ -405,16 +500,20 @@ async function branchCommits(git: Git, fork: ForkPoint, limit?: number): Promise
405
500
  }
406
501
 
407
502
  /** The committed changes of consecutive commits of the `branch` scope, from the first commit's first parent to the last. */
408
- async function commitsDiff(git: Git, fork: ForkPoint, chosen: ForgeCommitRange, layers: FileLayers): Promise<ForgeLocalDiff> {
503
+ async function commitsDiff(git: Git, fork: ForkPoint, chosen: ForgeCommitRange, layers: FileLayers, tip: string): Promise<ForgeLocalDiff> {
409
504
  if (!COMMIT.test(chosen.from) || !COMMIT.test(chosen.to)) throw new CommitsMissing('The chosen commits are not full object names')
410
- const start = rangeStart(await branchCommits(git, fork), chosen)
505
+ const start = rangeStart(await branchCommits(git, fork, tip), chosen)
411
506
  if (start === 'missing') throw new CommitsMissing('The chosen commits are no longer on the branch')
412
507
  if (start === 'not-linear') throw new CommitsNotLinear('The chosen commits are not one run of first parents')
413
- // A first commit without a parent starts an unrelated history that HEAD merged; it adds every file.
414
- const parent = start.parent ?? await emptyTree(git)
508
+ // A first commit without a parent starts an unrelated history that the tip merged; it adds every file.
509
+ return await treeDiff(git, fork, start.parent ?? await emptyTree(git), chosen.to, layers)
510
+ }
511
+
512
+ /** The committed changes from one revision to another, with each file's layer read at the newer one. */
513
+ async function treeDiff(git: Git, fork: ForkPoint, from: string, to: string, layers: FileLayers): Promise<ForgeLocalDiff> {
415
514
  const overrides = await diffFilterOverrides(git)
416
- const files = parseDiff((await bounded(git('diff', [...DIFF, parent, chosen.to, '--'], undefined, overrides))).stdout)
417
- const shown = await bounded(git('attributes', ['show', `${chosen.to}:${ATTRIBUTES_PATH}`], [0, 128]))
515
+ const files = parseDiff((await bounded(git('diff', [...DIFF, from, to, '--'], undefined, overrides))).stdout)
516
+ const shown = await bounded(git('attributes', ['show', `${to}:${ATTRIBUTES_PATH}`], [0, 128]))
418
517
  return { base: fork.label, files: layers.classify(files, shown.exitCode === 0 ? shown.stdout : ''), omitted: 0 }
419
518
  }
420
519
 
@@ -478,8 +577,12 @@ async function bounded(output: Promise<GitOutput>): Promise<GitOutput> {
478
577
  }
479
578
  }
480
579
 
481
- /** Whether a diff path stays inside the checkout: relative, without NUL, and without a `..` segment. */
482
- function insideCheckout(path: string): boolean {
580
+ /**
581
+ * Whether a diff path stays inside the checkout: relative, without NUL, and without a `..` segment.
582
+ * @param path - path as a diff names it.
583
+ * @returns whether Git and the filesystem may receive it relative to the checkout root.
584
+ */
585
+ export function insideCheckout(path: string): boolean {
483
586
  if (path.length === 0 || path.includes('\0') || path.startsWith('/') || /^[A-Za-z]:/.test(path)) return false
484
587
  return path.split(/[/\\]/).every(segment => segment !== '..')
485
588
  }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Writes a person makes from the changes view to a Session's checkout: staging, unstaging, and restoring whole files,
3
+ * and returning index entries to an earlier state. The press is that person's authorization, so Git runs through the
4
+ * mounted subprocess provider without the Session's sandbox policy, which bounds what the Agent does. Staging and
5
+ * restoring run the clean and smudge filters the repository configures.
6
+ */
7
+
8
+ import type { Context } from '@deepseek-ai/cordis'
9
+ import type { Session } from '@deepseek-ai/dsh-session'
10
+ import { assertNever } from '@deepseek-ai/dsh-util-values'
11
+ import { gitUnconfined } from './git.ts'
12
+ import type { Git } from './git.ts'
13
+ import type { FileLayers } from './layers.ts'
14
+ import { insideCheckout, localDiff } from './local-diff.ts'
15
+ import type { DiffConfig } from './local-diff.ts'
16
+ import { restorable } from './restore.ts'
17
+ import type { ForgeDiffFile, ForgeLocalWrite, ForgeLocalWriteFile, ForgeLocalWriteResult } from './types.ts'
18
+
19
+ /** Thrown before anything is written when a file's unstaged change differs from the change the reader saw. */
20
+ export class LocalChangesStale extends Error {
21
+ override name = 'LocalChangesStale'
22
+ }
23
+
24
+ /**
25
+ * Thrown before anything is written when a file listed as deleted has a directory at its path. Git takes a path for
26
+ * the directory and everything in it, so staging the deletion would stage those files and restoring the file would
27
+ * delete them.
28
+ */
29
+ export class LocalPathReplaced extends Error {
30
+ override name = 'LocalPathReplaced'
31
+ }
32
+
33
+ /** A full SHA-1 or SHA-256 object name, the only form of a tree Git receives. */
34
+ const TREE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
35
+
36
+ /** Characters of paths one command receives. Windows limits a command line to 32,767 characters, which Git's own arguments share. */
37
+ const PATH_CHARACTERS = 16_000
38
+
39
+ /**
40
+ * Apply one write to the checkout at `root`. `stage` and `restore` first read the `unstaged` scope again, under the
41
+ * Session's sandbox policy as every read, and refuse the whole write when a file's change is not the one the reader
42
+ * saw or a deleted file's path holds a directory; `unstage` and `reindex` change index entries only. The writing
43
+ * commands run unconfined; paths reach Git as literal pathspecs, and a restore leaves submodules alone whatever
44
+ * `submodule.recurse` says.
45
+ * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
46
+ * @param config - Git and size limits.
47
+ * @param session - Session whose sandbox policy the reads use.
48
+ * @param root - top-level directory of the checkout.
49
+ * @param write - the write.
50
+ * @param layers - classifier the `unstaged` scope is read with.
51
+ * @param signal - cancellation of every command and read.
52
+ * @returns the index before a `stage` or `unstage` as a tree, for undoing it.
53
+ * @throws LocalChangesStale when a file changed since it was read; LocalPathReplaced when a deleted file's path holds
54
+ * a directory; an Error for a path outside the checkout, a tree that is not a full object name, or a file that
55
+ * {@link restorable} leaves out of a restore; the errors of {@link localDiff}; GitFailed when Git fails. A failure
56
+ * after the first command leaves the paths of the earlier commands written.
57
+ */
58
+ export async function localWrite(
59
+ ctx: Context,
60
+ config: DiffConfig,
61
+ session: Session,
62
+ root: string,
63
+ write: ForgeLocalWrite,
64
+ layers: FileLayers,
65
+ signal: AbortSignal,
66
+ ): Promise<ForgeLocalWriteResult> {
67
+ const git = gitUnconfined(ctx, config, root, signal)
68
+ const unstaged = (files: readonly ForgeLocalWriteFile[]): Promise<ForgeDiffFile[]> =>
69
+ listed(ctx, config, session, root, files, layers, signal)
70
+ switch (write.kind) {
71
+ case 'stage': {
72
+ const files = await unstaged(write.files)
73
+ const undo = await indexTree(git)
74
+ // A rename the index already expects stages the removal of its old path with the new one.
75
+ await run(git, 'add', ['add', '--'], files.flatMap(file => file.previousPath === null ? [file.path] : [file.previousPath, file.path]))
76
+ return { undo }
77
+ }
78
+ case 'unstage': {
79
+ const paths = contained(write.paths)
80
+ const undo = await indexTree(git)
81
+ await run(git, 'reset', ['reset', '-q', '--'], paths)
82
+ return { undo }
83
+ }
84
+ case 'restore': {
85
+ const files = await unstaged(write.files)
86
+ const refused = files.find(file => !restorable(file))
87
+ if (refused !== undefined) throw new Error(`forge-panel: ${refused.path} is a submodule or has no index content, so it cannot be restored`)
88
+ await run(git, 'restore', ['restore', '--worktree', '--no-recurse-submodules', '--'], files.filter(file => !file.untracked).map(file => file.path))
89
+ await run(git, 'clean', ['clean', '-f', '-q', '--'], files.filter(file => file.untracked).map(file => file.path))
90
+ return { undo: null }
91
+ }
92
+ case 'reindex':
93
+ if (!TREE.test(write.tree)) throw new Error('forge-panel: the tree to return to is not a full object name')
94
+ await run(git, 'reset', ['reset', '-q', write.tree, '--'], contained(write.paths))
95
+ return { undo: null }
96
+ /* v8 ignore next -- closed ForgeLocalWrite union exhaustiveness guard */
97
+ default: return assertNever(write, 'ForgeLocalWrite.kind')
98
+ }
99
+ }
100
+
101
+ /**
102
+ * The files as the `unstaged` scope lists them now; a file that is gone or whose change differs is stale, and a
103
+ * deleted file whose path holds a directory is refused.
104
+ */
105
+ async function listed(
106
+ ctx: Context,
107
+ config: DiffConfig,
108
+ session: Session,
109
+ root: string,
110
+ files: readonly ForgeLocalWriteFile[],
111
+ layers: FileLayers,
112
+ signal: AbortSignal,
113
+ ): Promise<ForgeDiffFile[]> {
114
+ const current = new Map((await localDiff(ctx, config, session, root, null, { kind: 'unstaged' }, layers, signal)).files.map(file => [file.path, file]))
115
+ const matched = files.map((seen) => {
116
+ const file = current.get(seen.path)
117
+ if (file?.digest !== seen.digest) throw new LocalChangesStale(`${seen.path} changed since it was read`)
118
+ return file
119
+ })
120
+ for (const file of matched) {
121
+ // Only a deleted file leaves its path free for a directory.
122
+ if (file.status !== 'deleted') continue
123
+ const entry = await ctx.fs.lstat(file.path, { cwd: root }, signal)
124
+ if (entry?.type === 'directory') throw new LocalPathReplaced(`${file.path} is a directory now; stage or restore the files in it instead`)
125
+ }
126
+ return matched
127
+ }
128
+
129
+ /** The paths, each of which stays inside the checkout. */
130
+ function contained(paths: readonly string[]): readonly string[] {
131
+ const outside = paths.find(path => !insideCheckout(path))
132
+ if (outside !== undefined) throw new Error(`forge-panel: ${JSON.stringify(outside)} is not a path inside the checkout`)
133
+ return paths
134
+ }
135
+
136
+ /** Write the index as a tree; null while it holds unmerged entries or cannot be locked, which the write that follows reports. */
137
+ async function indexTree(git: Git): Promise<string | null> {
138
+ const written = await git('write-tree', ['write-tree'], [0, 128])
139
+ return written.exitCode === 0 ? written.stdout.trim() : null
140
+ }
141
+
142
+ /** Run one subcommand over the paths as literal pathspecs, in as many commands as the command-line limit needs. */
143
+ async function run(git: Git, name: string, command: readonly string[], paths: readonly string[]): Promise<void> {
144
+ let batch: string[] = []
145
+ let characters = 0
146
+ const flush = async (): Promise<void> => {
147
+ if (batch.length === 0) return
148
+ const args = ['--literal-pathspecs', ...command, ...batch]
149
+ batch = []
150
+ characters = 0
151
+ await git(name, args)
152
+ }
153
+ for (const path of paths) {
154
+ if (characters + path.length > PATH_CHARACTERS) await flush()
155
+ batch.push(path)
156
+ characters += path.length + 1
157
+ }
158
+ await flush()
159
+ }
package/src/panel.ts CHANGED
@@ -6,7 +6,7 @@ import type { ChangeRequestRef, ChangeRequestSnapshot, ForgeReadiness, ForgeRepo
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'
9
- import { pluginRecordOf } from '@deepseek-ai/dsh-session'
9
+ import { pluginRecordOf } from '@deepseek-ai/dsh-session-store'
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'
package/src/parse.ts CHANGED
@@ -37,16 +37,16 @@ export const BASE_REF_PREFIXES = ['refs/heads/', 'refs/remotes/'] as const
37
37
 
38
38
  /**
39
39
  * Select the branches the `branch` scope can compare with from `git for-each-ref`
40
- * output, keeping its order and leaving out symbolic refs and the checked-out branch.
40
+ * output, keeping its order and leaving out symbolic refs and the hidden branches.
41
41
  * @param output - stdout of `git for-each-ref --format=%(refname)%00%(symref)` over {@link BASE_REF_PREFIXES}.
42
- * @param current - checked-out branch, or null when HEAD is detached.
42
+ * @param hidden - full refs the listing leaves out: the branch the scope shows, and the branch the automatic base stands for.
43
43
  * @param query - text the names must contain, ignoring case; empty or blank for every branch.
44
44
  * @param limit - most branches in each group.
45
45
  * @returns remote-tracking and local branches, at most `limit` of each.
46
46
  */
47
47
  export function parseBaseBranches(
48
48
  output: string,
49
- current: string | null,
49
+ hidden: readonly string[],
50
50
  query: string,
51
51
  limit: number,
52
52
  ): { readonly remote: ForgeBaseBranch[]; readonly local: ForgeBaseBranch[] } {
@@ -60,12 +60,34 @@ export function parseBaseBranches(
60
60
  const group = ref.startsWith(heads) ? local : ref.startsWith(remotes) ? remote : undefined
61
61
  if (group === undefined || group.length >= limit) continue
62
62
  const name = ref.slice(group === local ? heads.length : remotes.length)
63
- if (name.length === 0 || (group === local && name === current) || !name.toLowerCase().includes(needle)) continue
63
+ if (name.length === 0 || hidden.includes(ref) || !name.toLowerCase().includes(needle)) continue
64
64
  group.push({ ref, name })
65
65
  }
66
66
  return { remote, local }
67
67
  }
68
68
 
69
+ /**
70
+ * Read which worktree has each branch checked out from `git worktree list --porcelain` output: one block of lines for
71
+ * each worktree, ended by an empty line. The NUL-separated form of the listing needs Git 2.36, so the lines are read
72
+ * instead; a directory whose name holds a line break is cut at the break, and Git before 2.31 does not mark a worktree
73
+ * whose directory is gone, so a caller confirms the directory before it reads there.
74
+ * @param output - stdout of the listing.
75
+ * @returns the directory of each worktree by the full ref of its branch, without detached, bare, and prunable entries.
76
+ */
77
+ export function parseWorktrees(output: string): Map<string, string> {
78
+ const found = new Map<string, string>()
79
+ for (const entry of output.split('\n\n')) {
80
+ const fields = entry.split('\n')
81
+ const value = (name: string): string | undefined => fields.find(field => field.startsWith(`${name} `))?.slice(name.length + 1)
82
+ const path = value('worktree')
83
+ const branch = value('branch')
84
+ // A prunable entry names a directory that is gone; its branch can only be read from its commits.
85
+ if (path === undefined || branch === undefined || fields.some(field => field === 'prunable' || field.startsWith('prunable '))) continue
86
+ found.set(branch, path)
87
+ }
88
+ return found
89
+ }
90
+
69
91
  /**
70
92
  * Select the branches a new worktree can start from out of `git for-each-ref` output, keeping its order within
71
93
  * each group: the checked-out branch, each remote's default branch, the other local branches, and the other
package/src/restore.ts ADDED
@@ -0,0 +1,15 @@
1
+ /** Which unstaged changes a restore of the changes view can act on. */
2
+
3
+ import type { ForgeDiffFile } from './types.ts'
4
+
5
+ /**
6
+ * Whether restoring a file of the `unstaged` scope has content to return to or an untracked file to delete. A file the
7
+ * index tracks without content, as `git add --intent-to-add` leaves it, shows as added or renamed and has neither:
8
+ * Git would replace it with an empty file. A submodule is left out as well: `git restore` succeeds on it and leaves
9
+ * the commit it has checked out.
10
+ * @param file - a file as the `unstaged` scope lists it.
11
+ * @returns whether a restore of the file is offered and accepted.
12
+ */
13
+ export function restorable(file: Pick<ForgeDiffFile, 'untracked' | 'status' | 'submodule'>): boolean {
14
+ return !file.submodule && (file.untracked || file.status === 'modified' || file.status === 'deleted')
15
+ }