@deepseek-ai/dsh-experimental-client-ui-forge 0.2.3-alpha.1 → 0.2.3-alpha.3

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 (315) hide show
  1. package/README.i18n.yaml +8 -8
  2. package/README.md +29 -12
  3. package/README.zh.md +29 -12
  4. package/lib/client.js +21 -16
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +874 -170
  7. package/lib/typert.host.js +831 -156
  8. package/lib/typert.remote-client.d.ts +29 -11
  9. package/lib/typert.remote-client.d.ts.map +1 -1
  10. package/lib/typert.remote-client.js +727 -134
  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/AttentionIndicator.d.ts +1 -1
  15. package/lib/types/client/AttentionIndicator.d.ts.map +1 -1
  16. package/lib/types/client/BaseMenu.d.ts +6 -4
  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/BranchPicker.d.ts +84 -0
  20. package/lib/types/client/BranchPicker.d.ts.map +1 -0
  21. package/lib/types/client/BranchPicker.js.map +1 -0
  22. package/lib/types/client/ChangeRequestCard.d.ts +21 -12
  23. package/lib/types/client/ChangeRequestCard.d.ts.map +1 -1
  24. package/lib/types/client/ChangeRequestCard.js.map +1 -1
  25. package/lib/types/client/ChangeRequestOverview.d.ts +12 -6
  26. package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -1
  27. package/lib/types/client/ChangeRequestOverview.js.map +1 -1
  28. package/lib/types/client/ChangeRequestsSection.d.ts +5 -3
  29. package/lib/types/client/ChangeRequestsSection.d.ts.map +1 -1
  30. package/lib/types/client/ChangeRequestsSection.js.map +1 -1
  31. package/lib/types/client/ChangedFiles.d.ts +1 -1
  32. package/lib/types/client/ChangedFiles.d.ts.map +1 -1
  33. package/lib/types/client/ChangedFiles.js.map +1 -1
  34. package/lib/types/client/ChangesLoading.d.ts +1 -1
  35. package/lib/types/client/ChangesLoading.d.ts.map +1 -1
  36. package/lib/types/client/ChangesTab.d.ts +15 -7
  37. package/lib/types/client/ChangesTab.d.ts.map +1 -1
  38. package/lib/types/client/ChangesTab.js.map +1 -1
  39. package/lib/types/client/ChangesTabTitle.d.ts +1 -1
  40. package/lib/types/client/ChangesTabTitle.d.ts.map +1 -1
  41. package/lib/types/client/ChangesTabTitle.js.map +1 -1
  42. package/lib/types/client/CommitMenu.d.ts +3 -3
  43. package/lib/types/client/CommitMenu.d.ts.map +1 -1
  44. package/lib/types/client/CommitMenu.js.map +1 -1
  45. package/lib/types/client/DiffFile.d.ts +16 -2
  46. package/lib/types/client/DiffFile.d.ts.map +1 -1
  47. package/lib/types/client/DiffFile.js.map +1 -1
  48. package/lib/types/client/EnvironmentRows.d.ts +6 -6
  49. package/lib/types/client/EnvironmentRows.d.ts.map +1 -1
  50. package/lib/types/client/EnvironmentRows.js.map +1 -1
  51. package/lib/types/client/FileLabel.js.map +1 -1
  52. package/lib/types/client/HeadMenu.d.ts +35 -0
  53. package/lib/types/client/HeadMenu.d.ts.map +1 -0
  54. package/lib/types/client/HeadMenu.js.map +1 -0
  55. package/lib/types/client/HostSettings.d.ts +33 -0
  56. package/lib/types/client/HostSettings.d.ts.map +1 -0
  57. package/lib/types/client/HostSettings.js.map +1 -0
  58. package/lib/types/client/LensFilter.d.ts +2 -2
  59. package/lib/types/client/LensFilter.d.ts.map +1 -1
  60. package/lib/types/client/LensFilter.js.map +1 -1
  61. package/lib/types/client/ReasonButton.js.map +1 -1
  62. package/lib/types/client/RefreshGlyph.js.map +1 -1
  63. package/lib/types/client/ReviewComposer.d.ts +1 -1
  64. package/lib/types/client/ReviewComposer.d.ts.map +1 -1
  65. package/lib/types/client/ReviewComposer.js.map +1 -1
  66. package/lib/types/client/ReviewControls.d.ts +1 -1
  67. package/lib/types/client/ReviewControls.d.ts.map +1 -1
  68. package/lib/types/client/ReviewControls.js.map +1 -1
  69. package/lib/types/client/ReviewThread.d.ts +1 -1
  70. package/lib/types/client/ReviewThread.d.ts.map +1 -1
  71. package/lib/types/client/ReviewThread.js.map +1 -1
  72. package/lib/types/client/ReviewThreads.d.ts +4 -2
  73. package/lib/types/client/ReviewThreads.d.ts.map +1 -1
  74. package/lib/types/client/ReviewThreads.js.map +1 -1
  75. package/lib/types/client/SessionHoverForge.d.ts +1 -1
  76. package/lib/types/client/SessionHoverForge.d.ts.map +1 -1
  77. package/lib/types/client/SessionHoverForge.js.map +1 -1
  78. package/lib/types/client/SessionRowForge.d.ts +1 -1
  79. package/lib/types/client/SessionRowForge.d.ts.map +1 -1
  80. package/lib/types/client/SessionRowForge.js.map +1 -1
  81. package/lib/types/client/SubmitReview.d.ts +1 -1
  82. package/lib/types/client/SubmitReview.d.ts.map +1 -1
  83. package/lib/types/client/SubmitReview.js.map +1 -1
  84. package/lib/types/client/ThreadList.d.ts +3 -1
  85. package/lib/types/client/ThreadList.d.ts.map +1 -1
  86. package/lib/types/client/ThreadList.js.map +1 -1
  87. package/lib/types/client/ViewOptionsMenu.d.ts +1 -1
  88. package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -1
  89. package/lib/types/client/ViewOptionsMenu.js.map +1 -1
  90. package/lib/types/client/WorktreeNameDialog.d.ts +1 -1
  91. package/lib/types/client/WorktreeNameDialog.d.ts.map +1 -1
  92. package/lib/types/client/WorktreeNameDialog.js.map +1 -1
  93. package/lib/types/client/WorktreeProgress.d.ts +1 -1
  94. package/lib/types/client/WorktreeProgress.d.ts.map +1 -1
  95. package/lib/types/client/WorktreeProgress.js.map +1 -1
  96. package/lib/types/client/WorktreeSettings.d.ts +1 -1
  97. package/lib/types/client/WorktreeSettings.d.ts.map +1 -1
  98. package/lib/types/client/WorktreeSettings.js.map +1 -1
  99. package/lib/types/client/WorktreeToggle.d.ts +1 -1
  100. package/lib/types/client/WorktreeToggle.d.ts.map +1 -1
  101. package/lib/types/client/WorktreeToggle.js.map +1 -1
  102. package/lib/types/client/annotations.d.ts +1 -1
  103. package/lib/types/client/annotations.d.ts.map +1 -1
  104. package/lib/types/client/branch-search.d.ts +1 -1
  105. package/lib/types/client/branch-search.d.ts.map +1 -1
  106. package/lib/types/client/branch-search.js.map +1 -1
  107. package/lib/types/client/changes-address.d.ts +1 -1
  108. package/lib/types/client/changes-address.d.ts.map +1 -1
  109. package/lib/types/client/changes-service.d.ts +1 -1
  110. package/lib/types/client/changes-service.d.ts.map +1 -1
  111. package/lib/types/client/changes-store.d.ts +18 -2
  112. package/lib/types/client/changes-store.d.ts.map +1 -1
  113. package/lib/types/client/changes-store.js.map +1 -1
  114. package/lib/types/client/checkout.d.ts +1 -1
  115. package/lib/types/client/checkout.d.ts.map +1 -1
  116. package/lib/types/client/code-selection.d.ts.map +1 -1
  117. package/lib/types/client/code-selection.js.map +1 -1
  118. package/lib/types/client/forge-copy.d.ts +8 -1
  119. package/lib/types/client/forge-copy.d.ts.map +1 -1
  120. package/lib/types/client/forge-copy.js.map +1 -1
  121. package/lib/types/client/format.d.ts +1 -1
  122. package/lib/types/client/format.d.ts.map +1 -1
  123. package/lib/types/client/format.js.map +1 -1
  124. package/lib/types/client/glyphs.d.ts +23 -1
  125. package/lib/types/client/glyphs.d.ts.map +1 -1
  126. package/lib/types/client/glyphs.js.map +1 -1
  127. package/lib/types/client/highlight-context.d.ts +1 -1
  128. package/lib/types/client/highlight-context.d.ts.map +1 -1
  129. package/lib/types/client/host-settings-form.d.ts +69 -0
  130. package/lib/types/client/host-settings-form.d.ts.map +1 -0
  131. package/lib/types/client/host-settings-form.js.map +1 -0
  132. package/lib/types/client/host-sign-in.d.ts +31 -0
  133. package/lib/types/client/host-sign-in.d.ts.map +1 -0
  134. package/lib/types/client/host-sign-in.js.map +1 -0
  135. package/lib/types/client/local-writes.d.ts +47 -0
  136. package/lib/types/client/local-writes.d.ts.map +1 -0
  137. package/lib/types/client/local-writes.js.map +1 -0
  138. package/lib/types/client/locales.d.ts +106 -9
  139. package/lib/types/client/locales.d.ts.map +1 -1
  140. package/lib/types/client/locales.js.map +1 -1
  141. package/lib/types/client/mount.d.ts +15 -1
  142. package/lib/types/client/mount.d.ts.map +1 -1
  143. package/lib/types/client/mount.js.map +1 -1
  144. package/lib/types/client/review-page/ReviewActivity.d.ts +44 -0
  145. package/lib/types/client/review-page/ReviewActivity.d.ts.map +1 -0
  146. package/lib/types/client/review-page/ReviewActivity.js.map +1 -0
  147. package/lib/types/client/review-page/ReviewChat.d.ts +1 -1
  148. package/lib/types/client/review-page/ReviewChat.d.ts.map +1 -1
  149. package/lib/types/client/review-page/ReviewChat.js.map +1 -1
  150. package/lib/types/client/review-page/ReviewDetail.d.ts +23 -9
  151. package/lib/types/client/review-page/ReviewDetail.d.ts.map +1 -1
  152. package/lib/types/client/review-page/ReviewDetail.js.map +1 -1
  153. package/lib/types/client/review-page/ReviewLabels.d.ts +1 -1
  154. package/lib/types/client/review-page/ReviewLabels.d.ts.map +1 -1
  155. package/lib/types/client/review-page/ReviewLabels.js.map +1 -1
  156. package/lib/types/client/review-page/ReviewList.d.ts +10 -8
  157. package/lib/types/client/review-page/ReviewList.d.ts.map +1 -1
  158. package/lib/types/client/review-page/ReviewList.js.map +1 -1
  159. package/lib/types/client/review-page/ReviewNav.d.ts +1 -1
  160. package/lib/types/client/review-page/ReviewNav.d.ts.map +1 -1
  161. package/lib/types/client/review-page/ReviewPage.d.ts +15 -12
  162. package/lib/types/client/review-page/ReviewPage.d.ts.map +1 -1
  163. package/lib/types/client/review-page/ReviewPage.js.map +1 -1
  164. package/lib/types/client/review-page/ReviewSkeleton.d.ts +26 -0
  165. package/lib/types/client/review-page/ReviewSkeleton.d.ts.map +1 -0
  166. package/lib/types/client/review-page/ReviewSkeleton.js.map +1 -0
  167. package/lib/types/client/review-page/ReviewStatus.d.ts +5 -3
  168. package/lib/types/client/review-page/ReviewStatus.d.ts.map +1 -1
  169. package/lib/types/client/review-page/ReviewStatus.js.map +1 -1
  170. package/lib/types/client/review-page/review-activity.d.ts +37 -0
  171. package/lib/types/client/review-page/review-activity.d.ts.map +1 -0
  172. package/lib/types/client/review-page/review-activity.js.map +1 -0
  173. package/lib/types/client/review-page/review-lists.d.ts +48 -13
  174. package/lib/types/client/review-page/review-lists.d.ts.map +1 -1
  175. package/lib/types/client/review-page/review-lists.js.map +1 -1
  176. package/lib/types/client/review-page/review-mount.d.ts +3 -1
  177. package/lib/types/client/review-page/review-mount.d.ts.map +1 -1
  178. package/lib/types/client/review-page/review-mount.js.map +1 -1
  179. package/lib/types/client/review-page/review-store.d.ts +18 -8
  180. package/lib/types/client/review-page/review-store.d.ts.map +1 -1
  181. package/lib/types/client/review-page/review-store.js.map +1 -1
  182. package/lib/types/client/review-queue.d.ts +1 -1
  183. package/lib/types/client/review-queue.d.ts.map +1 -1
  184. package/lib/types/client/review-queue.js.map +1 -1
  185. package/lib/types/client/review-threads.d.ts +1 -1
  186. package/lib/types/client/review-threads.d.ts.map +1 -1
  187. package/lib/types/client/review.d.ts +12 -1
  188. package/lib/types/client/review.d.ts.map +1 -1
  189. package/lib/types/client/review.js.map +1 -1
  190. package/lib/types/client/row-form-labels.d.ts +12 -0
  191. package/lib/types/client/row-form-labels.d.ts.map +1 -0
  192. package/lib/types/client/row-form-labels.js.map +1 -0
  193. package/lib/types/client/session-list.d.ts +1 -1
  194. package/lib/types/client/session-list.d.ts.map +1 -1
  195. package/lib/types/client/slots.d.ts +1 -1
  196. package/lib/types/client/slots.d.ts.map +1 -1
  197. package/lib/types/client/source.d.ts +1 -1
  198. package/lib/types/client/source.d.ts.map +1 -1
  199. package/lib/types/client/status.d.ts +7 -0
  200. package/lib/types/client/status.d.ts.map +1 -1
  201. package/lib/types/client/status.js.map +1 -1
  202. package/lib/types/client/worktree-settings-form.d.ts +1 -1
  203. package/lib/types/client/worktree-settings-form.d.ts.map +1 -1
  204. package/lib/types/client/worktree-settings-form.js.map +1 -1
  205. package/lib/types/diff.d.ts.map +1 -1
  206. package/lib/types/diff.js.map +1 -1
  207. package/lib/types/git.d.ts +22 -0
  208. package/lib/types/git.d.ts.map +1 -1
  209. package/lib/types/git.js.map +1 -1
  210. package/lib/types/index.d.ts +113 -25
  211. package/lib/types/index.d.ts.map +1 -1
  212. package/lib/types/index.js.map +1 -1
  213. package/lib/types/local-diff.d.ts +81 -23
  214. package/lib/types/local-diff.d.ts.map +1 -1
  215. package/lib/types/local-diff.js.map +1 -1
  216. package/lib/types/local-write.d.ts +44 -0
  217. package/lib/types/local-write.d.ts.map +1 -0
  218. package/lib/types/local-write.js.map +1 -0
  219. package/lib/types/parse.d.ts +12 -3
  220. package/lib/types/parse.d.ts.map +1 -1
  221. package/lib/types/parse.js.map +1 -1
  222. package/lib/types/restore.d.ts +12 -0
  223. package/lib/types/restore.d.ts.map +1 -0
  224. package/lib/types/restore.js.map +1 -0
  225. package/lib/types/types.d.ts +106 -8
  226. package/lib/types/types.d.ts.map +1 -1
  227. package/lib/types/viewer-lists.d.ts +22 -13
  228. package/lib/types/viewer-lists.d.ts.map +1 -1
  229. package/lib/types/viewer-lists.js.map +1 -1
  230. package/package.json +60 -58
  231. package/src/client/ActionToast.tsx +2 -2
  232. package/src/client/AttentionIndicator.tsx +1 -1
  233. package/src/client/BaseMenu.module.css +12 -3
  234. package/src/client/BaseMenu.tsx +25 -88
  235. package/src/client/BranchPicker.tsx +161 -0
  236. package/src/client/ChangeRequestCard.tsx +138 -44
  237. package/src/client/ChangeRequestOverview.tsx +21 -9
  238. package/src/client/ChangeRequestsSection.tsx +12 -6
  239. package/src/client/ChangedFiles.tsx +2 -2
  240. package/src/client/ChangesLoading.tsx +1 -1
  241. package/src/client/ChangesTab.module.css +95 -16
  242. package/src/client/ChangesTab.tsx +190 -72
  243. package/src/client/ChangesTabTitle.tsx +2 -2
  244. package/src/client/CommitMenu.tsx +7 -5
  245. package/src/client/DiffFile.tsx +67 -11
  246. package/src/client/EnvironmentRows.tsx +21 -17
  247. package/src/client/FileLabel.tsx +1 -1
  248. package/src/client/Forge.module.css +28 -1
  249. package/src/client/HeadMenu.tsx +69 -0
  250. package/src/client/HostSettings.module.css +194 -0
  251. package/src/client/HostSettings.tsx +192 -0
  252. package/src/client/LensFilter.tsx +2 -2
  253. package/src/client/ReasonButton.tsx +1 -1
  254. package/src/client/RefreshGlyph.tsx +1 -1
  255. package/src/client/ReviewComposer.tsx +2 -2
  256. package/src/client/ReviewControls.tsx +10 -3
  257. package/src/client/ReviewThread.tsx +2 -2
  258. package/src/client/ReviewThreads.tsx +7 -4
  259. package/src/client/SessionHoverForge.tsx +2 -2
  260. package/src/client/SessionRowForge.tsx +2 -2
  261. package/src/client/SubmitReview.tsx +2 -2
  262. package/src/client/ThreadList.tsx +6 -3
  263. package/src/client/ViewOptionsMenu.tsx +2 -2
  264. package/src/client/WorktreeNameDialog.tsx +2 -2
  265. package/src/client/WorktreeProgress.tsx +2 -2
  266. package/src/client/WorktreeSettings.tsx +4 -11
  267. package/src/client/WorktreeToggle.tsx +2 -2
  268. package/src/client/annotations.ts +1 -1
  269. package/src/client/branch-search.tsx +2 -2
  270. package/src/client/changes-address.ts +1 -1
  271. package/src/client/changes-service.ts +1 -1
  272. package/src/client/changes-store.ts +49 -5
  273. package/src/client/checkout.ts +1 -1
  274. package/src/client/code-selection.ts +3 -1
  275. package/src/client/forge-copy.ts +11 -1
  276. package/src/client/format.ts +2 -2
  277. package/src/client/glyphs.tsx +50 -5
  278. package/src/client/highlight-context.ts +1 -1
  279. package/src/client/host-settings-form.ts +115 -0
  280. package/src/client/host-sign-in.ts +46 -0
  281. package/src/client/local-writes.ts +129 -0
  282. package/src/client/locales.ts +841 -65
  283. package/src/client/mount.ts +56 -7
  284. package/src/client/review-page/ReviewActivity.tsx +405 -0
  285. package/src/client/review-page/ReviewChat.tsx +2 -2
  286. package/src/client/review-page/ReviewDetail.tsx +201 -64
  287. package/src/client/review-page/ReviewLabels.tsx +2 -2
  288. package/src/client/review-page/ReviewList.tsx +153 -136
  289. package/src/client/review-page/ReviewNav.tsx +1 -1
  290. package/src/client/review-page/ReviewPage.module.css +490 -13
  291. package/src/client/review-page/ReviewPage.tsx +44 -21
  292. package/src/client/review-page/ReviewSkeleton.tsx +108 -0
  293. package/src/client/review-page/ReviewStatus.tsx +14 -9
  294. package/src/client/review-page/review-activity.ts +64 -0
  295. package/src/client/review-page/review-lists.ts +85 -22
  296. package/src/client/review-page/review-mount.ts +24 -7
  297. package/src/client/review-page/review-store.ts +24 -7
  298. package/src/client/review-queue.ts +7 -3
  299. package/src/client/review-threads.ts +1 -1
  300. package/src/client/review.ts +20 -2
  301. package/src/client/row-form-labels.ts +17 -0
  302. package/src/client/session-list.ts +1 -1
  303. package/src/client/slots.ts +1 -1
  304. package/src/client/source.ts +1 -1
  305. package/src/client/status.ts +20 -0
  306. package/src/client/worktree-settings-form.ts +1 -1
  307. package/src/diff.ts +8 -5
  308. package/src/git.ts +31 -1
  309. package/src/index.ts +241 -50
  310. package/src/local-diff.ts +151 -48
  311. package/src/local-write.ts +159 -0
  312. package/src/parse.ts +26 -4
  313. package/src/restore.ts +15 -0
  314. package/src/types.ts +97 -12
  315. package/src/viewer-lists.ts +124 -48
package/lib/index.js CHANGED
@@ -90,14 +90,14 @@ function parseName(output) {
90
90
  const BASE_REF_PREFIXES = ["refs/heads/", "refs/remotes/"];
91
91
  /**
92
92
  * Select the branches the `branch` scope can compare with from `git for-each-ref`
93
- * output, keeping its order and leaving out symbolic refs and the checked-out branch.
93
+ * output, keeping its order and leaving out symbolic refs and the hidden branches.
94
94
  * @param output - stdout of `git for-each-ref --format=%(refname)%00%(symref)` over {@link BASE_REF_PREFIXES}.
95
- * @param current - checked-out branch, or null when HEAD is detached.
95
+ * @param hidden - full refs the listing leaves out: the branch the scope shows, and the branch the automatic base stands for.
96
96
  * @param query - text the names must contain, ignoring case; empty or blank for every branch.
97
97
  * @param limit - most branches in each group.
98
98
  * @returns remote-tracking and local branches, at most `limit` of each.
99
99
  */
100
- function parseBaseBranches(output, current, query, limit) {
100
+ function parseBaseBranches(output, hidden, query, limit) {
101
101
  const [heads, remotes] = BASE_REF_PREFIXES;
102
102
  const needle = query.trim().toLowerCase();
103
103
  const remote = [];
@@ -108,7 +108,7 @@ function parseBaseBranches(output, current, query, limit) {
108
108
  const group = ref.startsWith(heads) ? local : ref.startsWith(remotes) ? remote : void 0;
109
109
  if (group === void 0 || group.length >= limit) continue;
110
110
  const name = ref.slice(group === local ? heads.length : remotes.length);
111
- if (name.length === 0 || group === local && name === current || !name.toLowerCase().includes(needle)) continue;
111
+ if (name.length === 0 || hidden.includes(ref) || !name.toLowerCase().includes(needle)) continue;
112
112
  group.push({
113
113
  ref,
114
114
  name
@@ -120,6 +120,26 @@ function parseBaseBranches(output, current, query, limit) {
120
120
  };
121
121
  }
122
122
  /**
123
+ * Read which worktree has each branch checked out from `git worktree list --porcelain` output: one block of lines for
124
+ * each worktree, ended by an empty line. The NUL-separated form of the listing needs Git 2.36, so the lines are read
125
+ * instead; a directory whose name holds a line break is cut at the break, and Git before 2.31 does not mark a worktree
126
+ * whose directory is gone, so a caller confirms the directory before it reads there.
127
+ * @param output - stdout of the listing.
128
+ * @returns the directory of each worktree by the full ref of its branch, without detached, bare, and prunable entries.
129
+ */
130
+ function parseWorktrees(output) {
131
+ const found = /* @__PURE__ */ new Map();
132
+ for (const entry of output.split("\n\n")) {
133
+ const fields = entry.split("\n");
134
+ const value = (name) => fields.find((field) => field.startsWith(`${name} `))?.slice(name.length + 1);
135
+ const path = value("worktree");
136
+ const branch = value("branch");
137
+ if (path === void 0 || branch === void 0 || fields.some((field) => field === "prunable" || field.startsWith("prunable "))) continue;
138
+ found.set(branch, path);
139
+ }
140
+ return found;
141
+ }
142
+ /**
123
143
  * Select the branches a new worktree can start from out of `git for-each-ref` output, keeping its order within
124
144
  * each group: the checked-out branch, each remote's default branch, the other local branches, and the other
125
145
  * remote-tracking branches of each remote. A remote's default branch is the branch its `refs/remotes/<remote>/HEAD`
@@ -269,7 +289,7 @@ function remoteOrder(upstream, remotes) {
269
289
  //#endregion
270
290
  //#region lib/types/git.js
271
291
  /** Git queries in a Session's current directory, using its permissions and execution world. */
272
- var __addDisposableResource$2 = function(env, value, async) {
292
+ var __addDisposableResource$3 = function(env, value, async) {
273
293
  if (value !== null && value !== void 0) {
274
294
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
275
295
  var dispose, inner;
@@ -298,7 +318,7 @@ var __addDisposableResource$2 = function(env, value, async) {
298
318
  } else if (async) env.stack.push({ async: true });
299
319
  return value;
300
320
  };
301
- var __disposeResources$2 = (function(SuppressedError) {
321
+ var __disposeResources$3 = (function(SuppressedError) {
302
322
  return function(env) {
303
323
  function fail(e) {
304
324
  env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
@@ -331,6 +351,20 @@ var __disposeResources$2 = (function(SuppressedError) {
331
351
  var GitOutputTooLarge = class extends Error {
332
352
  name = "GitOutputTooLarge";
333
353
  };
354
+ /** Thrown when a Git command ends with an exit code its caller does not allow, or by a signal. */
355
+ var GitFailed = class extends Error {
356
+ diagnostic;
357
+ name = "GitFailed";
358
+ /**
359
+ * @param command - the caller's name of the command.
360
+ * @param outcome - the exit code, or the signal that ended the process.
361
+ * @param diagnostic - first non-blank line Git printed on standard error, or `no diagnostic`.
362
+ */
363
+ constructor(command, outcome, diagnostic) {
364
+ super(`git ${command} failed (${String(outcome)}): ${diagnostic}`);
365
+ this.diagnostic = diagnostic;
366
+ }
367
+ };
334
368
  /**
335
369
  * Clear inherited repository, configuration, and replacement-ref selectors;
336
370
  * disable prompts, optional index writes, and lazy fetches of missing objects.
@@ -483,6 +517,23 @@ function gitIn(ctx, config, session, directory, signal, root) {
483
517
  return (name, args, allowedExitCodes = [0], configOverrides = {}) => runGit(ctx, config, policy, directory, name, args, signal, allowedExitCodes, configOverrides);
484
518
  }
485
519
  /**
520
+ * Bind a Git runner that no Session's sandbox policy confines, for a write a person asked for in the interface: the
521
+ * press is that person's authorization, as archiving is for the worktree service's removal of a checkout. Commands
522
+ * keep the mounted subprocess provider, the scrubbed environment, the fixed command prefix, and `config`'s limits.
523
+ * @param ctx - context that provides `subprocess`.
524
+ * @param config - executable and process limits.
525
+ * @param directory - working directory of every command.
526
+ * @param signal - cancellation of every command.
527
+ * @returns the runner.
528
+ */
529
+ function gitUnconfined(ctx, config, directory, signal) {
530
+ const policy = {
531
+ mode: "danger-full-access",
532
+ workspaceRoot: directory
533
+ };
534
+ return (name, args, allowedExitCodes = [0], configOverrides = {}) => runGit(ctx, config, policy, directory, name, args, signal, allowedExitCodes, configOverrides);
535
+ }
536
+ /**
486
537
  * Read the checked-out local branch, including an unborn one; null when HEAD is detached or names a ref outside
487
538
  * `refs/heads/`. The full ref is read because the short form turns `main` into `heads/main` while a tag shares the name.
488
539
  */
@@ -511,7 +562,7 @@ async function runGit(ctx, config, policy, cwd, name, args, signal, allowedExitC
511
562
  hasError: false
512
563
  };
513
564
  try {
514
- const timeout = __addDisposableResource$2(env_1, deadline(signal, config.gitTimeoutMs, "FORGE_PANEL_GIT_TIMEOUT"), false);
565
+ const timeout = __addDisposableResource$3(env_1, deadline(signal, config.gitTimeoutMs, "FORGE_PANEL_GIT_TIMEOUT"), false);
515
566
  const command = [
516
567
  await ctx.subprocess.resolveExecutable(config.gitCommand, void 0, timeout.signal),
517
568
  ...GIT_PREFIX,
@@ -545,7 +596,7 @@ async function runGit(ctx, config, policy, cwd, name, args, signal, allowedExitC
545
596
  const captured = child.collected;
546
597
  const stdout = captured.stdout.readFrom(0);
547
598
  const stderr = captured.stderr.readFrom(0);
548
- if (outcome.exitCode === null || !allowedExitCodes.includes(outcome.exitCode)) throw new Error(`git ${name} failed (${outcome.signal ?? outcome.exitCode}): ${firstLine(stderr.text)}`);
599
+ if (outcome.exitCode === null || !allowedExitCodes.includes(outcome.exitCode)) throw new GitFailed(name, outcome.signal ?? outcome.exitCode, firstLine(stderr.text));
549
600
  if (stdout.lossy) throw new GitOutputTooLarge(`git ${name} output exceeds maxOutputBytes`);
550
601
  return {
551
602
  stdout: stdout.text,
@@ -560,7 +611,7 @@ async function runGit(ctx, config, policy, cwd, name, args, signal, allowedExitC
560
611
  env_1.error = e_1;
561
612
  env_1.hasError = true;
562
613
  } finally {
563
- __disposeResources$2(env_1);
614
+ __disposeResources$3(env_1);
564
615
  }
565
616
  }
566
617
  function firstLine(text) {
@@ -575,6 +626,8 @@ const NULL_PATH = "/dev/null";
575
626
  const BINARY_PROBE_BYTES = 8e3;
576
627
  /** Blob names of both sides on a Git `index` header line, which identify a binary change that carries no hunks. */
577
628
  const INDEX_LINE = /^index ([0-9a-f]+\.\.[0-9a-f]+)/m;
629
+ /** A header line that carries the file mode of a submodule entry: the `index` line of a change, or a creation or deletion. */
630
+ const SUBMODULE_LINE = /^(?:index [0-9a-f]+\.\.[0-9a-f]+ 160000|(?:new|deleted) file mode 160000)$/m;
578
631
  /**
579
632
  * Parse a Git-style unified patch, as `git diff` or a code host prints it,
580
633
  * with `a/` and `b/` path prefixes. Hunk ranges follow jsdiff: a range that
@@ -604,8 +657,8 @@ function parseDiff(patch) {
604
657
  newLines,
605
658
  lines
606
659
  }));
607
- const header = binary && headers.length === parsed.length ? String(headers[index]) : "";
608
- const blobs = INDEX_LINE.exec(header)?.[1] ?? "";
660
+ const header = headers.length === parsed.length ? String(headers[index]) : "";
661
+ const blobs = binary ? INDEX_LINE.exec(header)?.[1] ?? "" : "";
609
662
  const modes = `${section.oldMode ?? ""}..${section.newMode ?? ""}`;
610
663
  return [{
611
664
  path,
@@ -614,6 +667,7 @@ function parseDiff(patch) {
614
667
  binary,
615
668
  oversized: false,
616
669
  untracked: false,
670
+ submodule: SUBMODULE_LINE.test(header),
617
671
  additions,
618
672
  deletions,
619
673
  hunks,
@@ -686,6 +740,7 @@ function addedFile(path, hunks, { binary, oversized, content }) {
686
740
  binary,
687
741
  oversized,
688
742
  untracked: true,
743
+ submodule: false,
689
744
  additions: hunks[0]?.newLines ?? 0,
690
745
  deletions: 0,
691
746
  hunks,
@@ -1119,6 +1174,10 @@ var NoForkPoint = class extends Error {
1119
1174
  var BaseMissing = class extends Error {
1120
1175
  name = "BaseMissing";
1121
1176
  };
1177
+ /** Thrown when the branch a scope reads in place of the checked-out one does not exist. */
1178
+ var HeadMissing = class extends Error {
1179
+ name = "HeadMissing";
1180
+ };
1122
1181
  /** Thrown when chosen commits are not among the commits of the `branch` scope, or are out of order. */
1123
1182
  var CommitsMissing = class extends Error {
1124
1183
  name = "CommitsMissing";
@@ -1172,17 +1231,47 @@ async function diffFilterOverrides(git) {
1172
1231
  /** Characters Git inspects for a NUL character before it calls content binary. */
1173
1232
  const BINARY_PROBE = 8e3;
1174
1233
  /**
1175
- * Find where the `branch` scope forks while no base branch is chosen: the base commit of the worktree the
1176
- * Session created while the checkout is that worktree, else the merge base of
1177
- * HEAD with the default branch of the first remote that names one, in the
1178
- * order the panel recognizes code hosts.
1234
+ * Read the Session's own HEAD.
1235
+ * @param git - runner bound to the Session's checkout.
1236
+ * @param checkout - that checkout.
1237
+ * @returns the commit and its name, or null while the checked-out branch has no commit.
1238
+ * @throws an Error when Git fails.
1239
+ */
1240
+ async function sessionHead(git, checkout) {
1241
+ const head = await git("session-head", [
1242
+ "rev-parse",
1243
+ "--verify",
1244
+ "--quiet",
1245
+ "HEAD^{commit}"
1246
+ ], [0, 1]);
1247
+ const commit = head.exitCode === 0 ? parseName(head.stdout) : null;
1248
+ if (commit === null) return null;
1249
+ return checkout.branch === null ? {
1250
+ commit,
1251
+ label: commit.slice(0, 7),
1252
+ ref: null
1253
+ } : {
1254
+ commit,
1255
+ label: checkout.branch,
1256
+ ref: `${BASE_REF_PREFIXES[0]}${checkout.branch}`
1257
+ };
1258
+ }
1259
+ /**
1260
+ * Find where the `branch` scope forks while no base branch is chosen. For a branch shown in place of the Session's
1261
+ * checkout: the merge base of the tip with the Session's own HEAD. For the Session's checkout: the base commit of the
1262
+ * worktree the Session created while the checkout is that worktree, else the merge base of HEAD with the default
1263
+ * branch of the first remote that names one, in the order the panel recognizes code hosts.
1179
1264
  * @param git - runner bound to the checkout.
1180
1265
  * @param inspection - the checkout and its remotes.
1181
- * @param created - worktree the Session created, or null.
1182
- * @returns the fork point, or null when no remote names a default branch or HEAD shares no history with it.
1266
+ * @param created - worktree the checkout's Session created, or null.
1267
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref, which no created worktree applies to.
1268
+ * @param against - the Session's own HEAD while the scope shows another branch, or null for the Session's checkout.
1269
+ * @returns the fork point, or null when the tip shares no history with what it is compared with, or no remote names
1270
+ * a default branch for the Session's checkout.
1183
1271
  */
1184
- async function forkPoint(git, inspection, created) {
1185
- if (created !== null && created.path === inspection.checkout.root) {
1272
+ async function forkPoint(git, inspection, created, tip = "HEAD", against = null) {
1273
+ if (against !== null) return await mergeBase(git, tip, against.commit, against.label);
1274
+ if (tip === "HEAD" && created !== null && created.path === inspection.checkout.root) {
1186
1275
  const label = created.from === null ? created.baseCommit.slice(0, 7) : branchLabel(created.from);
1187
1276
  return {
1188
1277
  commit: created.baseCommit,
@@ -1203,45 +1292,16 @@ async function forkPoint(git, inspection, created) {
1203
1292
  ]);
1204
1293
  const base = head.exitCode === 0 ? parseName(head.stdout) : null;
1205
1294
  if (base === null) continue;
1206
- const merge = await git("merge-base", [
1207
- "merge-base",
1208
- "HEAD",
1209
- base
1210
- ], [
1211
- 0,
1212
- 1,
1213
- 128
1214
- ]);
1215
- const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null;
1216
- return commit === null ? null : {
1217
- commit,
1218
- label: base,
1219
- worktree: false
1220
- };
1295
+ return await mergeBase(git, tip, base, base);
1221
1296
  }
1222
1297
  return null;
1223
1298
  }
1224
- /**
1225
- * Find where the `branch` scope forks from a chosen base branch: the merge base of HEAD with it.
1226
- * @param git - runner bound to the checkout.
1227
- * @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
1228
- * @returns the fork point, or null when HEAD shares no history with the branch or has no commit.
1229
- * @throws BaseMissing when the ref does not exist; an Error for another ref name or when Git fails.
1230
- */
1231
- async function chosenForkPoint(git, ref) {
1232
- const prefix = BASE_REF_PREFIXES.find((candidate) => ref.startsWith(candidate) && ref.length > candidate.length);
1233
- if (prefix === void 0) throw new Error(`forge-panel: ${JSON.stringify(ref)} is not a branch ref`);
1234
- const name = ref.slice(prefix.length);
1235
- if ((await git("show-ref", [
1236
- "show-ref",
1237
- "--verify",
1238
- "--quiet",
1239
- ref
1240
- ], [0, 1])).exitCode !== 0) throw new BaseMissing(`The base branch ${name} does not exist`);
1299
+ /** The merge base of the tip with a revision, under the name the panel shows for that revision; null without shared history. */
1300
+ async function mergeBase(git, tip, revision, label) {
1241
1301
  const merge = await git("merge-base", [
1242
1302
  "merge-base",
1243
- "HEAD",
1244
- ref
1303
+ tip,
1304
+ revision
1245
1305
  ], [
1246
1306
  0,
1247
1307
  1,
@@ -1250,37 +1310,105 @@ async function chosenForkPoint(git, ref) {
1250
1310
  const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null;
1251
1311
  return commit === null ? null : {
1252
1312
  commit,
1253
- label: name,
1313
+ label,
1254
1314
  worktree: false
1255
1315
  };
1256
1316
  }
1257
1317
  /**
1318
+ * Find where the `branch` scope forks from a chosen base branch: the merge base of the tip with it.
1319
+ * @param git - runner bound to the checkout.
1320
+ * @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
1321
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref.
1322
+ * @returns the fork point, or null when the tip shares no history with the branch or has no commit.
1323
+ * @throws BaseMissing when the ref does not exist; an Error for another ref name or when Git fails.
1324
+ */
1325
+ async function chosenForkPoint(git, ref, tip = "HEAD") {
1326
+ const { name, present } = await branchOf(git, ref);
1327
+ if (!present) throw new BaseMissing(`The base branch ${name} does not exist`);
1328
+ return await mergeBase(git, tip, ref, name);
1329
+ }
1330
+ /**
1331
+ * Check the branch a scope shows in place of the checkout.
1332
+ * @param git - runner bound to a checkout of the repository.
1333
+ * @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
1334
+ * @returns the ref, which Git may receive as a revision.
1335
+ * @throws HeadMissing when the ref does not exist; an Error for another ref name or when Git fails.
1336
+ */
1337
+ async function branchTip(git, ref) {
1338
+ const { name, present } = await branchOf(git, ref);
1339
+ if (!present) throw new HeadMissing(`The branch ${name} does not exist`);
1340
+ return ref;
1341
+ }
1342
+ /** The name of a branch ref and whether the ref exists; another ref name is refused before Git reads it. */
1343
+ async function branchOf(git, ref) {
1344
+ const prefix = BASE_REF_PREFIXES.find((candidate) => ref.startsWith(candidate) && ref.length > candidate.length);
1345
+ if (prefix === void 0) throw new Error(`forge-panel: ${JSON.stringify(ref)} is not a branch ref`);
1346
+ const present = await git("show-ref", [
1347
+ "show-ref",
1348
+ "--verify",
1349
+ "--quiet",
1350
+ ref
1351
+ ], [0, 1]);
1352
+ return {
1353
+ name: ref.slice(prefix.length),
1354
+ present: present.exitCode === 0
1355
+ };
1356
+ }
1357
+ /**
1258
1358
  * List the branches the `branch` scope can compare with.
1259
1359
  * @param git - runner bound to the checkout.
1260
1360
  * @param inspection - the checkout and its remotes.
1261
- * @param created - worktree the Session created, or null.
1361
+ * @param created - worktree the checkout's Session created, or null.
1262
1362
  * @param query - text the branch names must contain, ignoring case; empty for every branch.
1263
1363
  * @param limit - most branches in each group.
1264
- * @returns the automatic fork point, then remote-tracking and local branches, most recently committed first.
1364
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref, which the listing leaves out.
1365
+ * @param against - the Session's own HEAD while the scope shows another branch, or null for the Session's checkout;
1366
+ * the listing leaves its branch out, because the automatic fork point already compares with it.
1367
+ * @returns the automatic fork point, then remote-tracking and local branches, most recently committed first; a local
1368
+ * branch that a worktree has checked out names the directory Git registered for it.
1265
1369
  * @throws an Error when Git fails or prints more than the runner's output limit.
1266
1370
  */
1267
- async function baseBranches(git, inspection, created, query, limit) {
1268
- const fork = await forkPoint(git, inspection, created);
1371
+ async function baseBranches(git, inspection, created, query, limit, tip = "HEAD", against = null) {
1372
+ const fork = await forkPoint(git, inspection, created, tip, against);
1269
1373
  const refs = await git("base-branches", [
1270
1374
  "for-each-ref",
1271
1375
  "--sort=-committerdate",
1272
1376
  "--format=%(refname)%00%(symref)",
1273
1377
  ...BASE_REF_PREFIXES
1274
1378
  ]);
1379
+ const hidden = [tip !== "HEAD" ? tip : inspection.checkout.branch === null ? null : `${BASE_REF_PREFIXES[0]}${inspection.checkout.branch}`, against === null ? null : against.ref].filter((ref) => ref !== null);
1380
+ const { remote, local } = parseBaseBranches(refs.stdout, hidden, query, limit);
1381
+ const trees = await branchWorktrees(git);
1275
1382
  return {
1276
1383
  automatic: fork === null ? null : {
1277
1384
  name: fork.label,
1278
1385
  worktree: fork.worktree
1279
1386
  },
1280
- ...parseBaseBranches(refs.stdout, inspection.checkout.branch, query, limit)
1387
+ remote,
1388
+ local: local.map((branch) => {
1389
+ const worktree = trees.get(branch.ref);
1390
+ return worktree === void 0 ? branch : {
1391
+ ...branch,
1392
+ worktree
1393
+ };
1394
+ })
1281
1395
  };
1282
1396
  }
1283
1397
  /**
1398
+ * Find the worktree of the repository that has each branch checked out.
1399
+ * @param git - runner bound to a checkout of the repository.
1400
+ * @returns the directory Git registered for each checked-out branch, by full ref name, without a worktree that Git
1401
+ * marks as gone and one without a branch. {@link parseWorktrees} says why a caller confirms the directory.
1402
+ * @throws an Error when Git fails or prints more than the runner's output limit.
1403
+ */
1404
+ async function branchWorktrees(git) {
1405
+ return parseWorktrees((await git("worktrees", [
1406
+ "worktree",
1407
+ "list",
1408
+ "--porcelain"
1409
+ ])).stdout);
1410
+ }
1411
+ /**
1284
1412
  * Read changes at `root` with command-local clean/process filter overrides and without
1285
1413
  * submodule working-tree inspection. Git's built-in newline, ident, and encoding conversions still apply.
1286
1414
  * Each file's layer follows `layers` and the root `.gitattributes` of the new side: the index for `staged`,
@@ -1288,17 +1416,19 @@ async function baseBranches(git, inspection, created, query, limit) {
1288
1416
  * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
1289
1417
  * @param config - Git and size limits.
1290
1418
  * @param session - Session whose sandbox policy and execution world apply.
1291
- * @param root - top-level directory of the checkout.
1419
+ * @param root - top-level directory of the checkout the scope reads: the Session's own, or the worktree of its `head`.
1292
1420
  * @param fork - fork point of the `branch` scope, or null without one.
1293
- * @param scope - which changes to read.
1421
+ * @param scope - which changes to read; its `head` is already resolved into `root` and `tip`.
1294
1422
  * @param layers - classifier of each file's review layer.
1295
1423
  * @param signal - cancellation of every command and read.
1296
- * @returns tracked files in Git's order, then untracked files unless the scope is `staged`.
1424
+ * @param tip - `HEAD` to read the checkout at `root` with its working tree, or a verified branch ref that the
1425
+ * `branch` scope reads from its commits alone.
1426
+ * @returns tracked files in Git's order, then untracked files unless the scope is `staged` or reads a branch's commits.
1297
1427
  * @throws NoForkPoint for the `branch` scope without `fork`; FilterConfigError when filter configuration
1298
1428
  * cannot be read within `maxDiffBytes`; DiffTooLarge for oversized comparison output or `.gitattributes`;
1299
1429
  * an Error when Git or the `.gitattributes` read fails.
1300
1430
  */
1301
- async function localDiff(ctx, config, session, root, fork, scope, layers, signal) {
1431
+ async function localDiff(ctx, config, session, root, fork, scope, layers, signal, tip = "HEAD") {
1302
1432
  const git = gitIn(ctx, {
1303
1433
  ...config,
1304
1434
  maxOutputBytes: config.maxDiffBytes
@@ -1307,7 +1437,8 @@ async function localDiff(ctx, config, session, root, fork, scope, layers, signal
1307
1437
  switch (scope.kind) {
1308
1438
  case "branch":
1309
1439
  if (fork === null) throw new NoForkPoint("The checkout has no fork point to compare its branch with");
1310
- if (scope.commits !== null) return await commitsDiff(git, fork, scope.commits, layers);
1440
+ if (scope.commits !== null) return await commitsDiff(git, fork, scope.commits, layers, tip);
1441
+ if (tip !== "HEAD") return await treeDiff(git, fork, fork.commit, tip, layers);
1311
1442
  range = [fork.commit];
1312
1443
  break;
1313
1444
  case "uncommitted":
@@ -1352,7 +1483,7 @@ async function localDiff(ctx, config, session, root, fork, scope, layers, signal
1352
1483
  /**
1353
1484
  * Read the new side of one file in a scope, which supplies the unchanged
1354
1485
  * lines between hunks: the index for `staged`, the last chosen commit for
1355
- * chosen commits of the `branch` scope, else the working tree.
1486
+ * chosen commits of the `branch` scope, the branch for a head read from its commits, else the working tree.
1356
1487
  * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
1357
1488
  * @param config - Git and size limits.
1358
1489
  * @param session - Session whose sandbox policy and execution world apply.
@@ -1360,15 +1491,17 @@ async function localDiff(ctx, config, session, root, fork, scope, layers, signal
1360
1491
  * @param scope - the scope whose new side to read.
1361
1492
  * @param path - path relative to `root`, as the diff names it.
1362
1493
  * @param signal - cancellation.
1494
+ * @param tip - `HEAD` for the checkout at `root`, or a verified branch ref whose commits the `branch` scope reads.
1363
1495
  * @returns the text.
1364
1496
  * @throws DiffTooLarge over `maxDiffBytes`; an Error for a path outside the checkout, binary content, or a failed read.
1365
1497
  */
1366
- async function localText(ctx, config, session, root, scope, path, signal) {
1498
+ async function localText(ctx, config, session, root, scope, path, signal, tip = "HEAD") {
1367
1499
  if (!insideCheckout(path)) throw new Error(`forge-panel: ${JSON.stringify(path)} is not a path inside the checkout`);
1368
1500
  let text;
1369
- const commit = scope.kind === "staged" ? "" : scope.kind === "branch" && scope.commits !== null ? scope.commits.to : void 0;
1501
+ const chosen = scope.kind === "branch" && scope.commits !== null ? scope.commits.to : void 0;
1502
+ if (chosen !== void 0 && !COMMIT.test(chosen)) throw new CommitsMissing("The chosen commit is not a full object name");
1503
+ const commit = scope.kind === "staged" ? "" : chosen ?? (scope.kind === "branch" && tip !== "HEAD" ? tip : void 0);
1370
1504
  if (commit !== void 0) {
1371
- if (commit !== "" && !COMMIT.test(commit)) throw new CommitsMissing("The chosen commit is not a full object name");
1372
1505
  const shown = (await bounded(gitIn(ctx, {
1373
1506
  ...config,
1374
1507
  maxOutputBytes: config.maxDiffBytes
@@ -1494,20 +1627,21 @@ async function aheadOf(git, branch, commit) {
1494
1627
  ])).stdout.trim());
1495
1628
  }
1496
1629
  /**
1497
- * List the commits of the `branch` scope: those reachable from HEAD but not from the fork point, parents before children.
1630
+ * List the commits of the `branch` scope: those reachable from the tip but not from the fork point, parents before children.
1498
1631
  * @param git - runner bound to the checkout, whose output limit bounds the listing.
1499
1632
  * @param fork - fork point of the `branch` scope.
1500
1633
  * @param limit - most commits listed.
1501
- * @returns the newest `limit` commits, ending with HEAD's commit, and HEAD's commit.
1634
+ * @param tip - revision the scope shows: HEAD for the checkout, or a branch ref.
1635
+ * @returns the newest `limit` commits, ending with the tip's commit, and the tip's commit.
1502
1636
  * @throws an Error when Git fails or prints more than the runner's output limit.
1503
1637
  */
1504
- async function localCommits(git, fork, limit) {
1638
+ async function localCommits(git, fork, limit, tip = "HEAD") {
1505
1639
  const head = (await git("head", [
1506
1640
  "rev-parse",
1507
1641
  "--verify",
1508
- "HEAD"
1642
+ tip
1509
1643
  ])).stdout.trim();
1510
- const listed = await branchCommits(git, fork, limit + 1);
1644
+ const listed = await branchCommits(git, fork, tip, limit + 1);
1511
1645
  return {
1512
1646
  headSha: head,
1513
1647
  commits: listed.slice(-limit),
@@ -1515,10 +1649,10 @@ async function localCommits(git, fork, limit) {
1515
1649
  };
1516
1650
  }
1517
1651
  /**
1518
- * Commits between the fork point and HEAD, parents before children.
1652
+ * Commits between the fork point and the tip, parents before children.
1519
1653
  * @param limit - when given, only the newest `limit` commits in topological order.
1520
1654
  */
1521
- async function branchCommits(git, fork, limit) {
1655
+ async function branchCommits(git, fork, tip, limit) {
1522
1656
  return (await git("log", [
1523
1657
  "log",
1524
1658
  "--no-show-signature",
@@ -1526,7 +1660,7 @@ async function branchCommits(git, fork, limit) {
1526
1660
  "--reverse",
1527
1661
  ...limit === void 0 ? [] : [`--max-count=${String(limit)}`],
1528
1662
  LOG_FORMAT,
1529
- `${fork.commit}..HEAD`,
1663
+ `${fork.commit}..${tip}`,
1530
1664
  "--"
1531
1665
  ])).stdout.split("").flatMap((record) => {
1532
1666
  const fields = record.replace(/^\n/, "").split("\0");
@@ -1542,20 +1676,23 @@ async function branchCommits(git, fork, limit) {
1542
1676
  });
1543
1677
  }
1544
1678
  /** The committed changes of consecutive commits of the `branch` scope, from the first commit's first parent to the last. */
1545
- async function commitsDiff(git, fork, chosen, layers) {
1679
+ async function commitsDiff(git, fork, chosen, layers, tip) {
1546
1680
  if (!COMMIT.test(chosen.from) || !COMMIT.test(chosen.to)) throw new CommitsMissing("The chosen commits are not full object names");
1547
- const start = rangeStart(await branchCommits(git, fork), chosen);
1681
+ const start = rangeStart(await branchCommits(git, fork, tip), chosen);
1548
1682
  if (start === "missing") throw new CommitsMissing("The chosen commits are no longer on the branch");
1549
1683
  if (start === "not-linear") throw new CommitsNotLinear("The chosen commits are not one run of first parents");
1550
- const parent = start.parent ?? await emptyTree(git);
1684
+ return await treeDiff(git, fork, start.parent ?? await emptyTree(git), chosen.to, layers);
1685
+ }
1686
+ /** The committed changes from one revision to another, with each file's layer read at the newer one. */
1687
+ async function treeDiff(git, fork, from, to, layers) {
1551
1688
  const overrides = await diffFilterOverrides(git);
1552
1689
  const files = parseDiff((await bounded(git("diff", [
1553
1690
  ...DIFF,
1554
- parent,
1555
- chosen.to,
1691
+ from,
1692
+ to,
1556
1693
  "--"
1557
1694
  ], void 0, overrides))).stdout);
1558
- const shown = await bounded(git("attributes", ["show", `${chosen.to}:${ATTRIBUTES_PATH}`], [0, 128]));
1695
+ const shown = await bounded(git("attributes", ["show", `${to}:${ATTRIBUTES_PATH}`], [0, 128]));
1559
1696
  return {
1560
1697
  base: fork.label,
1561
1698
  files: layers.classify(files, shown.exitCode === 0 ? shown.stdout : ""),
@@ -1630,15 +1767,177 @@ async function bounded(output) {
1630
1767
  throw error;
1631
1768
  }
1632
1769
  }
1633
- /** Whether a diff path stays inside the checkout: relative, without NUL, and without a `..` segment. */
1770
+ /**
1771
+ * Whether a diff path stays inside the checkout: relative, without NUL, and without a `..` segment.
1772
+ * @param path - path as a diff names it.
1773
+ * @returns whether Git and the filesystem may receive it relative to the checkout root.
1774
+ */
1634
1775
  function insideCheckout(path) {
1635
1776
  if (path.length === 0 || path.includes("\0") || path.startsWith("/") || /^[A-Za-z]:/.test(path)) return false;
1636
1777
  return path.split(/[/\\]/).every((segment) => segment !== "..");
1637
1778
  }
1638
1779
  //#endregion
1780
+ //#region lib/types/restore.js
1781
+ /** Which unstaged changes a restore of the changes view can act on. */
1782
+ /**
1783
+ * Whether restoring a file of the `unstaged` scope has content to return to or an untracked file to delete. A file the
1784
+ * index tracks without content, as `git add --intent-to-add` leaves it, shows as added or renamed and has neither:
1785
+ * Git would replace it with an empty file. A submodule is left out as well: `git restore` succeeds on it and leaves
1786
+ * the commit it has checked out.
1787
+ * @param file - a file as the `unstaged` scope lists it.
1788
+ * @returns whether a restore of the file is offered and accepted.
1789
+ */
1790
+ function restorable(file) {
1791
+ return !file.submodule && (file.untracked || file.status === "modified" || file.status === "deleted");
1792
+ }
1793
+ //#endregion
1794
+ //#region lib/types/local-write.js
1795
+ /**
1796
+ * Writes a person makes from the changes view to a Session's checkout: staging, unstaging, and restoring whole files,
1797
+ * and returning index entries to an earlier state. The press is that person's authorization, so Git runs through the
1798
+ * mounted subprocess provider without the Session's sandbox policy, which bounds what the Agent does. Staging and
1799
+ * restoring run the clean and smudge filters the repository configures.
1800
+ */
1801
+ /** Thrown before anything is written when a file's unstaged change differs from the change the reader saw. */
1802
+ var LocalChangesStale = class extends Error {
1803
+ name = "LocalChangesStale";
1804
+ };
1805
+ /**
1806
+ * Thrown before anything is written when a file listed as deleted has a directory at its path. Git takes a path for
1807
+ * the directory and everything in it, so staging the deletion would stage those files and restoring the file would
1808
+ * delete them.
1809
+ */
1810
+ var LocalPathReplaced = class extends Error {
1811
+ name = "LocalPathReplaced";
1812
+ };
1813
+ /** A full SHA-1 or SHA-256 object name, the only form of a tree Git receives. */
1814
+ const TREE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
1815
+ /** Characters of paths one command receives. Windows limits a command line to 32,767 characters, which Git's own arguments share. */
1816
+ const PATH_CHARACTERS = 16e3;
1817
+ /**
1818
+ * Apply one write to the checkout at `root`. `stage` and `restore` first read the `unstaged` scope again, under the
1819
+ * Session's sandbox policy as every read, and refuse the whole write when a file's change is not the one the reader
1820
+ * saw or a deleted file's path holds a directory; `unstage` and `reindex` change index entries only. The writing
1821
+ * commands run unconfined; paths reach Git as literal pathspecs, and a restore leaves submodules alone whatever
1822
+ * `submodule.recurse` says.
1823
+ * @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
1824
+ * @param config - Git and size limits.
1825
+ * @param session - Session whose sandbox policy the reads use.
1826
+ * @param root - top-level directory of the checkout.
1827
+ * @param write - the write.
1828
+ * @param layers - classifier the `unstaged` scope is read with.
1829
+ * @param signal - cancellation of every command and read.
1830
+ * @returns the index before a `stage` or `unstage` as a tree, for undoing it.
1831
+ * @throws LocalChangesStale when a file changed since it was read; LocalPathReplaced when a deleted file's path holds
1832
+ * a directory; an Error for a path outside the checkout, a tree that is not a full object name, or a file that
1833
+ * {@link restorable} leaves out of a restore; the errors of {@link localDiff}; GitFailed when Git fails. A failure
1834
+ * after the first command leaves the paths of the earlier commands written.
1835
+ */
1836
+ async function localWrite(ctx, config, session, root, write, layers, signal) {
1837
+ const git = gitUnconfined(ctx, config, root, signal);
1838
+ const unstaged = (files) => listed(ctx, config, session, root, files, layers, signal);
1839
+ switch (write.kind) {
1840
+ case "stage": {
1841
+ const files = await unstaged(write.files);
1842
+ const undo = await indexTree(git);
1843
+ await run(git, "add", ["add", "--"], files.flatMap((file) => file.previousPath === null ? [file.path] : [file.previousPath, file.path]));
1844
+ return { undo };
1845
+ }
1846
+ case "unstage": {
1847
+ const paths = contained(write.paths);
1848
+ const undo = await indexTree(git);
1849
+ await run(git, "reset", [
1850
+ "reset",
1851
+ "-q",
1852
+ "--"
1853
+ ], paths);
1854
+ return { undo };
1855
+ }
1856
+ case "restore": {
1857
+ const files = await unstaged(write.files);
1858
+ const refused = files.find((file) => !restorable(file));
1859
+ if (refused !== void 0) throw new Error(`forge-panel: ${refused.path} is a submodule or has no index content, so it cannot be restored`);
1860
+ await run(git, "restore", [
1861
+ "restore",
1862
+ "--worktree",
1863
+ "--no-recurse-submodules",
1864
+ "--"
1865
+ ], files.filter((file) => !file.untracked).map((file) => file.path));
1866
+ await run(git, "clean", [
1867
+ "clean",
1868
+ "-f",
1869
+ "-q",
1870
+ "--"
1871
+ ], files.filter((file) => file.untracked).map((file) => file.path));
1872
+ return { undo: null };
1873
+ }
1874
+ case "reindex":
1875
+ if (!TREE.test(write.tree)) throw new Error("forge-panel: the tree to return to is not a full object name");
1876
+ await run(git, "reset", [
1877
+ "reset",
1878
+ "-q",
1879
+ write.tree,
1880
+ "--"
1881
+ ], contained(write.paths));
1882
+ return { undo: null };
1883
+ /* v8 ignore next -- closed ForgeLocalWrite union exhaustiveness guard */
1884
+ default: return assertNever(write, "ForgeLocalWrite.kind");
1885
+ }
1886
+ }
1887
+ /**
1888
+ * The files as the `unstaged` scope lists them now; a file that is gone or whose change differs is stale, and a
1889
+ * deleted file whose path holds a directory is refused.
1890
+ */
1891
+ async function listed(ctx, config, session, root, files, layers, signal) {
1892
+ const current = new Map((await localDiff(ctx, config, session, root, null, { kind: "unstaged" }, layers, signal)).files.map((file) => [file.path, file]));
1893
+ const matched = files.map((seen) => {
1894
+ const file = current.get(seen.path);
1895
+ if (file?.digest !== seen.digest) throw new LocalChangesStale(`${seen.path} changed since it was read`);
1896
+ return file;
1897
+ });
1898
+ for (const file of matched) {
1899
+ if (file.status !== "deleted") continue;
1900
+ if ((await ctx.fs.lstat(file.path, { cwd: root }, signal))?.type === "directory") throw new LocalPathReplaced(`${file.path} is a directory now; stage or restore the files in it instead`);
1901
+ }
1902
+ return matched;
1903
+ }
1904
+ /** The paths, each of which stays inside the checkout. */
1905
+ function contained(paths) {
1906
+ const outside = paths.find((path) => !insideCheckout(path));
1907
+ if (outside !== void 0) throw new Error(`forge-panel: ${JSON.stringify(outside)} is not a path inside the checkout`);
1908
+ return paths;
1909
+ }
1910
+ /** Write the index as a tree; null while it holds unmerged entries or cannot be locked, which the write that follows reports. */
1911
+ async function indexTree(git) {
1912
+ const written = await git("write-tree", ["write-tree"], [0, 128]);
1913
+ return written.exitCode === 0 ? written.stdout.trim() : null;
1914
+ }
1915
+ /** Run one subcommand over the paths as literal pathspecs, in as many commands as the command-line limit needs. */
1916
+ async function run(git, name, command, paths) {
1917
+ let batch = [];
1918
+ let characters = 0;
1919
+ const flush = async () => {
1920
+ if (batch.length === 0) return;
1921
+ const args = [
1922
+ "--literal-pathspecs",
1923
+ ...command,
1924
+ ...batch
1925
+ ];
1926
+ batch = [];
1927
+ characters = 0;
1928
+ await git(name, args);
1929
+ };
1930
+ for (const path of paths) {
1931
+ if (characters + path.length > PATH_CHARACTERS) await flush();
1932
+ batch.push(path);
1933
+ characters += path.length + 1;
1934
+ }
1935
+ await flush();
1936
+ }
1937
+ //#endregion
1639
1938
  //#region lib/types/lenses.js
1640
1939
  /** Filter lenses registered on the forge panel host, the runs that classify one diff with one of them, and the kept results. */
1641
- var __addDisposableResource$1 = function(env, value, async) {
1940
+ var __addDisposableResource$2 = function(env, value, async) {
1642
1941
  if (value !== null && value !== void 0) {
1643
1942
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
1644
1943
  var dispose, inner;
@@ -1667,7 +1966,7 @@ var __addDisposableResource$1 = function(env, value, async) {
1667
1966
  } else if (async) env.stack.push({ async: true });
1668
1967
  return value;
1669
1968
  };
1670
- var __disposeResources$1 = (function(SuppressedError) {
1969
+ var __disposeResources$2 = (function(SuppressedError) {
1671
1970
  return function(env) {
1672
1971
  function fail(e) {
1673
1972
  env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
@@ -1807,7 +2106,7 @@ async function runLens(registration, subject, limits, signal, progress) {
1807
2106
  hasError: false
1808
2107
  };
1809
2108
  try {
1810
- const operation = __addDisposableResource$1(env_1, deadline(AbortSignal.any([signal, registration.lifetime]), limits.timeoutMs, "FORGE_LENS_TIMEOUT"), false).signal;
2109
+ const operation = __addDisposableResource$2(env_1, deadline(AbortSignal.any([signal, registration.lifetime]), limits.timeoutMs, "FORGE_LENS_TIMEOUT"), false).signal;
1811
2110
  const byPath = new Map(subject.files.map((file) => [file.path, file]));
1812
2111
  let read = 0;
1813
2112
  const overBudget = () => new LensFailed(`the lens read more than maxLensReadBytes (${limits.maxReadBytes} bytes) of file text`);
@@ -1855,7 +2154,7 @@ async function runLens(registration, subject, limits, signal, progress) {
1855
2154
  env_1.error = e_1;
1856
2155
  env_1.hasError = true;
1857
2156
  } finally {
1858
- __disposeResources$1(env_1);
2157
+ __disposeResources$2(env_1);
1859
2158
  }
1860
2159
  }
1861
2160
  /**
@@ -2562,7 +2861,7 @@ var WorktreeCreations = class {
2562
2861
  //#endregion
2563
2862
  //#region lib/types/panel.js
2564
2863
  /** Live panel state of one followed Session, shared by all of its followers. */
2565
- var __addDisposableResource = function(env, value, async) {
2864
+ var __addDisposableResource$1 = function(env, value, async) {
2566
2865
  if (value !== null && value !== void 0) {
2567
2866
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
2568
2867
  var dispose, inner;
@@ -2591,7 +2890,7 @@ var __addDisposableResource = function(env, value, async) {
2591
2890
  } else if (async) env.stack.push({ async: true });
2592
2891
  return value;
2593
2892
  };
2594
- var __disposeResources = (function(SuppressedError) {
2893
+ var __disposeResources$1 = (function(SuppressedError) {
2595
2894
  return function(env) {
2596
2895
  function fail(e) {
2597
2896
  env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
@@ -3038,13 +3337,13 @@ var SessionPanel = class {
3038
3337
  hasError: false
3039
3338
  };
3040
3339
  try {
3041
- const timeout = __addDisposableResource(env_1, deadline(this.lifetime.signal, this.config.readinessTimeoutMs, "FORGE_PANEL_READINESS_TIMEOUT"), false);
3340
+ const timeout = __addDisposableResource$1(env_1, deadline(this.lifetime.signal, this.config.readinessTimeoutMs, "FORGE_PANEL_READINESS_TIMEOUT"), false);
3042
3341
  readiness = await this.ctx.forge.readiness(repository, timeout.signal);
3043
3342
  } catch (e_1) {
3044
3343
  env_1.error = e_1;
3045
3344
  env_1.hasError = true;
3046
3345
  } finally {
3047
- __disposeResources(env_1);
3346
+ __disposeResources$1(env_1);
3048
3347
  }
3049
3348
  } catch (error) {
3050
3349
  readiness = {
@@ -3617,9 +3916,10 @@ var ChangeRequestStates = class {
3617
3916
  /**
3618
3917
  * The review page's lists of the signed-in user's change requests and its navigation count. Lists are read only while
3619
3918
  * some reader streams them and the count only while some reader streams it; neither joins the forge's status polling.
3620
- * Readers of one repository scope share one poller, which reads every list of every host each round, hosts in parallel
3621
- * and each host's lists one after another, so one host has at most one read in flight. A round with a failure delays
3622
- * the next round as status polling does after consecutive failures.
3919
+ * Readers of one repository scope share one poller, which reads every list of every due host each round, hosts in
3920
+ * parallel and each host's lists one after another, so one host has at most one read in flight. A host whose read
3921
+ * failed is read again later each time, as status polling waits after consecutive failures, while the other hosts
3922
+ * keep their cadence. A scope that names a repository reads only the host the repository is on.
3623
3923
  */
3624
3924
  /** The lists in the order the page shows them. */
3625
3925
  const FILTERS = [
@@ -3678,18 +3978,16 @@ var Reader = class {
3678
3978
  }
3679
3979
  }
3680
3980
  };
3681
- /** A loop that runs one round, waits, and repeats until stopped; a refresh ends the wait early. */
3981
+ /** A loop that runs one round, waits as long as the round asks, and repeats until stopped; a refresh ends the wait early. */
3682
3982
  var Poller = class {
3683
3983
  round;
3684
- delay;
3685
3984
  aborter = new AbortController();
3686
3985
  wake;
3687
3986
  refreshing = false;
3688
- failures = 0;
3689
3987
  done;
3690
- constructor(round, delay) {
3988
+ /** @param round - runs one round, `forced` after a refresh, and resolves to the milliseconds to wait before the next. */
3989
+ constructor(round) {
3691
3990
  this.round = round;
3692
- this.delay = delay;
3693
3991
  this.done = this.loop();
3694
3992
  }
3695
3993
  refresh() {
@@ -3708,12 +4006,12 @@ var Poller = class {
3708
4006
  async loop() {
3709
4007
  const { signal } = this.aborter;
3710
4008
  while (!signal.aborted) {
4009
+ const forced = this.refreshing;
3711
4010
  this.refreshing = false;
3712
- const succeeded = await this.round(signal);
3713
- this.failures = succeeded ? 0 : this.failures + 1;
4011
+ const wait = await this.round(signal, forced);
3714
4012
  if (this.skipsWait(signal)) continue;
3715
4013
  await new Promise((resolve) => {
3716
- const timer = setTimeout(resolve, this.delay(this.failures));
4014
+ const timer = setTimeout(resolve, wait);
3717
4015
  this.wake = () => {
3718
4016
  clearTimeout(timer);
3719
4017
  resolve();
@@ -3723,24 +4021,65 @@ var Poller = class {
3723
4021
  }
3724
4022
  }
3725
4023
  };
3726
- /** The readers of one repository scope, the poller they share, and what it read. */
4024
+ /**
4025
+ * When each host of one poller is read next. A host is due at once until its first read settles; after a read it is
4026
+ * due one delay after the start of the round that read it, and the delay grows with its consecutive failed reads.
4027
+ */
4028
+ var HostSchedule = class {
4029
+ delay;
4030
+ hosts = /* @__PURE__ */ new Map();
4031
+ /** @param delay - milliseconds between two reads of a host after the given number of consecutive failed reads. */
4032
+ constructor(delay) {
4033
+ this.delay = delay;
4034
+ }
4035
+ /** Whether a round that starts at `now` reads the host. */
4036
+ due(key, now) {
4037
+ return (this.hosts.get(key)?.dueAt ?? 0) <= now;
4038
+ }
4039
+ /** Record whether the read of the host succeeded in the round that started at `started`. */
4040
+ settle(key, started, succeeded) {
4041
+ const failures = succeeded ? 0 : (this.hosts.get(key)?.failures ?? 0) + 1;
4042
+ this.hosts.set(key, {
4043
+ failures,
4044
+ dueAt: started + this.delay(failures)
4045
+ });
4046
+ }
4047
+ /** Milliseconds from `now` until the first of `keys` is due, or the delay between two successful reads without any key. */
4048
+ wait(keys, now) {
4049
+ if (keys.length === 0) return this.delay(0);
4050
+ return Math.max(0, Math.min(...keys.map((key) => this.hosts.get(key)?.dueAt ?? 0)) - now);
4051
+ }
4052
+ };
4053
+ /** The readers of one repository scope, the poller they share, when each host is read next, and what was read. */
3727
4054
  var Scope = class {
4055
+ repository;
3728
4056
  readers = /* @__PURE__ */ new Set();
3729
4057
  hosts = /* @__PURE__ */ new Map();
4058
+ schedule;
3730
4059
  reading = false;
3731
4060
  poller;
3732
4061
  /**
3733
- * @param round - reads every list of the scope once; resolves to whether every read succeeded.
3734
- * @param delay - milliseconds before the next round after the given number of consecutive failed rounds.
4062
+ * @param repository - the repository the scope lists in, or null for every repository of every host.
4063
+ * @param round - reads the scope's due hosts once, every host when `forced`; resolves to the wait before the next round.
4064
+ * @param delay - milliseconds between two reads of a host after the given number of consecutive failed reads.
3735
4065
  */
3736
- constructor(round, delay) {
3737
- this.poller = new Poller((signal) => round(this, signal), delay);
4066
+ constructor(repository, round, delay) {
4067
+ this.repository = repository;
4068
+ this.schedule = new HostSchedule(delay);
4069
+ this.poller = new Poller((signal, forced) => round(this, signal, forced));
4070
+ }
4071
+ /** The hosts the scope reads, in registration and configuration order: every host, or the one its repository is on. */
4072
+ targets(order) {
4073
+ const only = this.repository?.host.toLowerCase();
4074
+ return order.flatMap((source) => source.hosts.filter((host) => only === void 0 || host === only).map((host) => ({
4075
+ source,
4076
+ host,
4077
+ key: hostKey(source.forge, host)
4078
+ })));
3738
4079
  }
3739
4080
  frame(order) {
3740
- const hosts = [];
3741
- for (const source of order) for (const host of source.hosts) hosts.push(this.hosts.get(hostKey(source.forge, host)) ?? emptyHost(source, host));
3742
4081
  return {
3743
- hosts,
4082
+ hosts: this.targets(order).map(({ source, host, key }) => this.hosts.get(key) ?? emptyHost(source, host)),
3744
4083
  reading: this.reading
3745
4084
  };
3746
4085
  }
@@ -3752,6 +4091,7 @@ var ViewerLists = class {
3752
4091
  scopes = /* @__PURE__ */ new Map();
3753
4092
  countReaders = /* @__PURE__ */ new Set();
3754
4093
  counts = /* @__PURE__ */ new Map();
4094
+ countSchedule = new HostSchedule((failures) => this.delay(this.timing.countIntervalMs, failures));
3755
4095
  countPoller;
3756
4096
  disposed = false;
3757
4097
  /**
@@ -3765,17 +4105,17 @@ var ViewerLists = class {
3765
4105
  /**
3766
4106
  * Stream the lists of one repository scope: the lists read so far first, then a frame after each read settles.
3767
4107
  * The stream ends when `signal` aborts or the hub is disposed; the last stream of a scope stops its reads.
3768
- * @param scope - one repository, or null for every repository.
4108
+ * @param scope - one repository on its host, or null for every repository of every host.
3769
4109
  * @param signal - ends the stream.
3770
4110
  * @returns frames, each complete.
3771
4111
  */
3772
4112
  async *lists(scope, signal) {
3773
4113
  signal.throwIfAborted();
3774
4114
  if (this.disposed) return;
3775
- const key = scope === null ? "" : `${scope.owner}/${scope.name}`.toLowerCase();
4115
+ const key = scope === null ? "" : `${scope.host}\n${scope.owner}/${scope.name}`.toLowerCase();
3776
4116
  let state = this.scopes.get(key);
3777
4117
  if (state === void 0) {
3778
- state = new Scope((created, round) => this.readScope(created, scope, round), (failures) => this.delay(this.timing.listIntervalMs, failures));
4118
+ state = new Scope(scope, (created, round, forced) => this.readScope(created, round, forced), (failures) => this.delay(this.timing.listIntervalMs, failures));
3779
4119
  this.scopes.set(key, state);
3780
4120
  }
3781
4121
  const reader = new Reader(signal);
@@ -3804,7 +4144,7 @@ var ViewerLists = class {
3804
4144
  const reader = new Reader(signal);
3805
4145
  this.countReaders.add(reader);
3806
4146
  reader.push(this.countFrame());
3807
- this.countPoller ??= new Poller((round) => this.readCounts(round), (failures) => this.delay(this.timing.countIntervalMs, failures));
4147
+ this.countPoller ??= new Poller((round, forced) => this.readCounts(round, forced));
3808
4148
  try {
3809
4149
  yield* reader.frames();
3810
4150
  } finally {
@@ -3851,12 +4191,20 @@ var ViewerLists = class {
3851
4191
  await poller.stop();
3852
4192
  }));
3853
4193
  }
3854
- /** Read every list of every host once; resolves to whether every read succeeded. */
3855
- async readScope(scope, repository, signal) {
3856
- const order = this.sources.sources();
4194
+ /**
4195
+ * Read every list of the scope's due hosts once, of every host when `forced`.
4196
+ * @returns milliseconds until the scope's next host is due.
4197
+ */
4198
+ async readScope(scope, signal, forced) {
4199
+ const started = Date.now();
4200
+ const targets = scope.targets(this.sources.sources());
4201
+ const repository = scope.repository === null ? null : {
4202
+ owner: scope.repository.owner,
4203
+ name: scope.repository.name
4204
+ };
3857
4205
  scope.reading = true;
3858
4206
  this.publish(scope);
3859
- const results = await Promise.all(order.flatMap((source) => source.hosts.map(async (host) => {
4207
+ await Promise.all(targets.filter((target) => forced || scope.schedule.due(target.key, started)).map(async ({ source, host, key }) => {
3860
4208
  let succeeded = true;
3861
4209
  let hostFailure;
3862
4210
  for (const filter of FILTERS) {
@@ -3868,31 +4216,59 @@ var ViewerLists = class {
3868
4216
  limit: Math.min(source.maxItems, this.timing.pageSize)
3869
4217
  };
3870
4218
  const result = hostFailure ?? await this.read(() => this.sources.list(source.forge, query, signal), signal);
3871
- if (signal.aborted) return false;
4219
+ if (signal.aborted) return;
3872
4220
  if ("code" in result && HOST_FAILURES.has(result.code)) hostFailure = result;
3873
4221
  succeeded = this.settle(scope, source, host, filter, result) && succeeded;
3874
4222
  if (repository === null && !("code" in result) && filter === "review-requested") {
3875
- this.counts.set(hostKey(source.forge, host), result.total);
4223
+ this.counts.set(key, result.total);
3876
4224
  this.publishCount();
3877
4225
  }
3878
4226
  this.publish(scope);
3879
4227
  }
3880
- return succeeded;
3881
- })));
4228
+ const signIn = hostFailure?.code === "unauthenticated" ? await this.signInOf(scope, source, host, signal) : null;
4229
+ if (signal.aborted) return;
4230
+ const current = scope.hosts.get(key) ?? emptyHost(source, host);
4231
+ if (current.signIn !== signIn) {
4232
+ scope.hosts.set(key, {
4233
+ ...current,
4234
+ signIn
4235
+ });
4236
+ this.publish(scope);
4237
+ }
4238
+ scope.schedule.settle(key, started, succeeded);
4239
+ }));
3882
4240
  scope.reading = false;
3883
4241
  if (!signal.aborted) this.publish(scope);
3884
- return results.every(Boolean);
4242
+ return scope.schedule.wait(targets.map((target) => target.key), Date.now());
4243
+ }
4244
+ /** The sign-in command the scope already holds for the host, else the one its provider names now, else null. */
4245
+ async signInOf(scope, source, host, signal) {
4246
+ const known = scope.hosts.get(hostKey(source.forge, host))?.signIn ?? null;
4247
+ if (known !== null) return known;
4248
+ const command = await this.read(() => this.sources.signIn(source.forge, host, signal), signal);
4249
+ return typeof command === "string" ? command : null;
3885
4250
  }
3886
- /** Read the count of every host once; resolves to whether every read succeeded. */
3887
- async readCounts(signal) {
3888
- return (await Promise.all(this.sources.sources().flatMap((source) => source.hosts.map(async (host) => {
3889
- if (!source.filters.has("review-requested")) return true;
4251
+ /**
4252
+ * Read the count of every due host once, of every host when `forced`.
4253
+ * @returns milliseconds until the next host is due.
4254
+ */
4255
+ async readCounts(signal, forced) {
4256
+ const started = Date.now();
4257
+ const targets = this.sources.sources().filter((source) => source.filters.has("review-requested")).flatMap((source) => source.hosts.map((host) => ({
4258
+ source,
4259
+ host,
4260
+ key: hostKey(source.forge, host)
4261
+ })));
4262
+ await Promise.all(targets.filter((target) => forced || this.countSchedule.due(target.key, started)).map(async ({ source, host, key }) => {
3890
4263
  const result = await this.read(() => this.sources.count(source.forge, host, signal), signal);
3891
- if (signal.aborted || "code" in result) return false;
3892
- this.counts.set(hostKey(source.forge, host), result.get("review-requested") ?? 0);
3893
- this.publishCount();
3894
- return true;
3895
- })))).every(Boolean);
4264
+ if (signal.aborted) return;
4265
+ if (!("code" in result)) {
4266
+ this.counts.set(key, result.get("review-requested") ?? 0);
4267
+ this.publishCount();
4268
+ }
4269
+ this.countSchedule.settle(key, started, !("code" in result));
4270
+ }));
4271
+ return this.countSchedule.wait(targets.map((target) => target.key), Date.now());
3896
4272
  }
3897
4273
  /** Run one read, turning a rejection into an `unavailable` failure and reporting it unless `signal` aborted. */
3898
4274
  async read(run, signal) {
@@ -3969,6 +4345,7 @@ function emptyHost(source, host) {
3969
4345
  forge: source.forge,
3970
4346
  host,
3971
4347
  viewer: null,
4348
+ signIn: null,
3972
4349
  lists
3973
4350
  };
3974
4351
  }
@@ -4013,6 +4390,64 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
4013
4390
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
4014
4391
  done = true;
4015
4392
  };
4393
+ var __addDisposableResource = function(env, value, async) {
4394
+ if (value !== null && value !== void 0) {
4395
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4396
+ var dispose, inner;
4397
+ if (async) {
4398
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
4399
+ dispose = value[Symbol.asyncDispose];
4400
+ }
4401
+ if (dispose === void 0) {
4402
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
4403
+ dispose = value[Symbol.dispose];
4404
+ if (async) inner = dispose;
4405
+ }
4406
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
4407
+ if (inner) dispose = function() {
4408
+ try {
4409
+ inner.call(this);
4410
+ } catch (e) {
4411
+ return Promise.reject(e);
4412
+ }
4413
+ };
4414
+ env.stack.push({
4415
+ value,
4416
+ dispose,
4417
+ async
4418
+ });
4419
+ } else if (async) env.stack.push({ async: true });
4420
+ return value;
4421
+ };
4422
+ var __disposeResources = (function(SuppressedError) {
4423
+ return function(env) {
4424
+ function fail(e) {
4425
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
4426
+ env.hasError = true;
4427
+ }
4428
+ var r, s = 0;
4429
+ function next() {
4430
+ while (r = env.stack.pop()) try {
4431
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
4432
+ if (r.dispose) {
4433
+ var result = r.dispose.call(r.value);
4434
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
4435
+ fail(e);
4436
+ return next();
4437
+ });
4438
+ } else s |= 1;
4439
+ } catch (e) {
4440
+ fail(e);
4441
+ }
4442
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
4443
+ if (env.hasError) throw env.error;
4444
+ }
4445
+ return next();
4446
+ };
4447
+ })(typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
4448
+ var e = new Error(message);
4449
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4450
+ });
4016
4451
  /**
4017
4452
  * Serves the forge panel. Following a Session inspects the checkout of its
4018
4453
  * current directory using the Session's permissions and execution world, recognizes the
@@ -4036,9 +4471,12 @@ let ForgePanelController = (() => {
4036
4471
  let _reviewLists_decorators;
4037
4472
  let _reviewCount_decorators;
4038
4473
  let _reviewRefresh_decorators;
4474
+ let _hostReadiness_decorators;
4039
4475
  let _reviewPoll_decorators;
4040
4476
  let _reviewChangeRequest_decorators;
4041
4477
  let _reviewDescription_decorators;
4478
+ let _reviewActivity_decorators;
4479
+ let _reviewComment_decorators;
4042
4480
  let _reviewChecks_decorators;
4043
4481
  let _reviewThreads_decorators;
4044
4482
  let _reviewThreadWrite_decorators;
@@ -4050,6 +4488,7 @@ let ForgePanelController = (() => {
4050
4488
  let _reviewSetViewed_decorators;
4051
4489
  let _reviewMarkReady_decorators;
4052
4490
  let _reviewMerge_decorators;
4491
+ let _reviewSetAutoMerge_decorators;
4053
4492
  let _reviewRerunChecks_decorators;
4054
4493
  let _reviewRequestReviews_decorators;
4055
4494
  let _reviewReviewerCandidates_decorators;
@@ -4065,6 +4504,7 @@ let ForgePanelController = (() => {
4065
4504
  let _localDiff_decorators;
4066
4505
  let _localCommits_decorators;
4067
4506
  let _localText_decorators;
4507
+ let _localWrite_decorators;
4068
4508
  let _changeRequestChecks_decorators;
4069
4509
  let _changeRequestCommits_decorators;
4070
4510
  let _changeRequestDiff_decorators;
@@ -4078,6 +4518,7 @@ let ForgePanelController = (() => {
4078
4518
  let _changeRequestReviewWrite_decorators;
4079
4519
  let _markReady_decorators;
4080
4520
  let _merge_decorators;
4521
+ let _setAutoMerge_decorators;
4081
4522
  let _rerunChecks_decorators;
4082
4523
  let _requestReviews_decorators;
4083
4524
  let _reviewerCandidates_decorators;
@@ -4096,9 +4537,12 @@ let ForgePanelController = (() => {
4096
4537
  _reviewLists_decorators = [Remote({ mode: "stream" })];
4097
4538
  _reviewCount_decorators = [Remote({ mode: "stream" })];
4098
4539
  _reviewRefresh_decorators = [Remote];
4540
+ _hostReadiness_decorators = [Remote];
4099
4541
  _reviewPoll_decorators = [Remote];
4100
4542
  _reviewChangeRequest_decorators = [Remote({ mode: "stream" })];
4101
4543
  _reviewDescription_decorators = [Remote];
4544
+ _reviewActivity_decorators = [Remote];
4545
+ _reviewComment_decorators = [Remote];
4102
4546
  _reviewChecks_decorators = [Remote];
4103
4547
  _reviewThreads_decorators = [Remote];
4104
4548
  _reviewThreadWrite_decorators = [Remote];
@@ -4110,6 +4554,7 @@ let ForgePanelController = (() => {
4110
4554
  _reviewSetViewed_decorators = [Remote];
4111
4555
  _reviewMarkReady_decorators = [Remote];
4112
4556
  _reviewMerge_decorators = [Remote];
4557
+ _reviewSetAutoMerge_decorators = [Remote];
4113
4558
  _reviewRerunChecks_decorators = [Remote];
4114
4559
  _reviewRequestReviews_decorators = [Remote];
4115
4560
  _reviewReviewerCandidates_decorators = [Remote];
@@ -4125,6 +4570,7 @@ let ForgePanelController = (() => {
4125
4570
  _localDiff_decorators = [Remote];
4126
4571
  _localCommits_decorators = [Remote];
4127
4572
  _localText_decorators = [Remote];
4573
+ _localWrite_decorators = [Remote];
4128
4574
  _changeRequestChecks_decorators = [Remote];
4129
4575
  _changeRequestCommits_decorators = [Remote];
4130
4576
  _changeRequestDiff_decorators = [Remote];
@@ -4138,6 +4584,7 @@ let ForgePanelController = (() => {
4138
4584
  _changeRequestReviewWrite_decorators = [Remote];
4139
4585
  _markReady_decorators = [Remote];
4140
4586
  _merge_decorators = [Remote];
4587
+ _setAutoMerge_decorators = [Remote];
4141
4588
  _rerunChecks_decorators = [Remote];
4142
4589
  _requestReviews_decorators = [Remote];
4143
4590
  _reviewerCandidates_decorators = [Remote];
@@ -4203,6 +4650,17 @@ let ForgePanelController = (() => {
4203
4650
  },
4204
4651
  metadata: _metadata
4205
4652
  }, null, _instanceExtraInitializers);
4653
+ __esDecorate(this, null, _hostReadiness_decorators, {
4654
+ kind: "method",
4655
+ name: "hostReadiness",
4656
+ static: false,
4657
+ private: false,
4658
+ access: {
4659
+ has: (obj) => "hostReadiness" in obj,
4660
+ get: (obj) => obj.hostReadiness
4661
+ },
4662
+ metadata: _metadata
4663
+ }, null, _instanceExtraInitializers);
4206
4664
  __esDecorate(this, null, _reviewPoll_decorators, {
4207
4665
  kind: "method",
4208
4666
  name: "reviewPoll",
@@ -4236,6 +4694,28 @@ let ForgePanelController = (() => {
4236
4694
  },
4237
4695
  metadata: _metadata
4238
4696
  }, null, _instanceExtraInitializers);
4697
+ __esDecorate(this, null, _reviewActivity_decorators, {
4698
+ kind: "method",
4699
+ name: "reviewActivity",
4700
+ static: false,
4701
+ private: false,
4702
+ access: {
4703
+ has: (obj) => "reviewActivity" in obj,
4704
+ get: (obj) => obj.reviewActivity
4705
+ },
4706
+ metadata: _metadata
4707
+ }, null, _instanceExtraInitializers);
4708
+ __esDecorate(this, null, _reviewComment_decorators, {
4709
+ kind: "method",
4710
+ name: "reviewComment",
4711
+ static: false,
4712
+ private: false,
4713
+ access: {
4714
+ has: (obj) => "reviewComment" in obj,
4715
+ get: (obj) => obj.reviewComment
4716
+ },
4717
+ metadata: _metadata
4718
+ }, null, _instanceExtraInitializers);
4239
4719
  __esDecorate(this, null, _reviewChecks_decorators, {
4240
4720
  kind: "method",
4241
4721
  name: "reviewChecks",
@@ -4357,6 +4837,17 @@ let ForgePanelController = (() => {
4357
4837
  },
4358
4838
  metadata: _metadata
4359
4839
  }, null, _instanceExtraInitializers);
4840
+ __esDecorate(this, null, _reviewSetAutoMerge_decorators, {
4841
+ kind: "method",
4842
+ name: "reviewSetAutoMerge",
4843
+ static: false,
4844
+ private: false,
4845
+ access: {
4846
+ has: (obj) => "reviewSetAutoMerge" in obj,
4847
+ get: (obj) => obj.reviewSetAutoMerge
4848
+ },
4849
+ metadata: _metadata
4850
+ }, null, _instanceExtraInitializers);
4360
4851
  __esDecorate(this, null, _reviewRerunChecks_decorators, {
4361
4852
  kind: "method",
4362
4853
  name: "reviewRerunChecks",
@@ -4522,6 +5013,17 @@ let ForgePanelController = (() => {
4522
5013
  },
4523
5014
  metadata: _metadata
4524
5015
  }, null, _instanceExtraInitializers);
5016
+ __esDecorate(this, null, _localWrite_decorators, {
5017
+ kind: "method",
5018
+ name: "localWrite",
5019
+ static: false,
5020
+ private: false,
5021
+ access: {
5022
+ has: (obj) => "localWrite" in obj,
5023
+ get: (obj) => obj.localWrite
5024
+ },
5025
+ metadata: _metadata
5026
+ }, null, _instanceExtraInitializers);
4525
5027
  __esDecorate(this, null, _changeRequestChecks_decorators, {
4526
5028
  kind: "method",
4527
5029
  name: "changeRequestChecks",
@@ -4665,6 +5167,17 @@ let ForgePanelController = (() => {
4665
5167
  },
4666
5168
  metadata: _metadata
4667
5169
  }, null, _instanceExtraInitializers);
5170
+ __esDecorate(this, null, _setAutoMerge_decorators, {
5171
+ kind: "method",
5172
+ name: "setAutoMerge",
5173
+ static: false,
5174
+ private: false,
5175
+ access: {
5176
+ has: (obj) => "setAutoMerge" in obj,
5177
+ get: (obj) => obj.setAutoMerge
5178
+ },
5179
+ metadata: _metadata
5180
+ }, null, _instanceExtraInitializers);
4668
5181
  __esDecorate(this, null, _rerunChecks_decorators, {
4669
5182
  kind: "method",
4670
5183
  name: "rerunChecks",
@@ -4899,6 +5412,10 @@ let ForgePanelController = (() => {
4899
5412
  sources: () => ctx.forge.viewerSources(),
4900
5413
  list: async (forge, query, signal) => await ctx.forge.listForViewer(forge, query, signal),
4901
5414
  count: async (forge, host, signal) => await ctx.forge.countForViewer(forge, host, signal),
5415
+ signIn: async (forge, host, signal) => (await ctx.forge.readiness({
5416
+ forge,
5417
+ host
5418
+ }, signal)).signIn?.command ?? null,
4902
5419
  report: (error) => {
4903
5420
  ctx.logger.warn(`forge-panel: reading a review list failed: ${String(error)}`);
4904
5421
  }
@@ -4993,9 +5510,11 @@ let ForgePanelController = (() => {
4993
5510
  /**
4994
5511
  * Stream the review page's lists of the signed-in user's open change requests on every host a provider lists them on:
4995
5512
  * the lists read so far first, then a frame after each read settles. Readers of one repository scope share one
4996
- * reader, which reads every `reviewListIntervalMs` while some stream lasts and backs off after failed rounds up to
4997
- * `reviewMaxBackoffMs`; nothing is read while no stream lasts. The stream ends when `signal` aborts or the Remote stops.
4998
- * @param repository - one repository to list in, or null for every repository the user can read.
5513
+ * reader, which reads each host every `reviewListIntervalMs` while some stream lasts and reads a host whose read failed
5514
+ * again later each time, up to `reviewMaxBackoffMs`, without delaying the other hosts; nothing is read while no stream
5515
+ * lasts. The stream ends when `signal` aborts or the Remote stops.
5516
+ * @param repository - one repository to list in, read on its host only, or null for every repository the user can
5517
+ * read on every host.
4999
5518
  * @param signal - ends the stream.
5000
5519
  * @returns frames, each complete.
5001
5520
  */
@@ -5021,6 +5540,45 @@ let ForgePanelController = (() => {
5021
5540
  this.viewerLists.refresh();
5022
5541
  }
5023
5542
  /**
5543
+ * Report whether a provider reaches one of its hosts with the Host's current credentials, for the host list on the
5544
+ * Plugins page of that provider's row. The read names no Session, so, like the review page reads, only callers that
5545
+ * may use the Host's code host credentials reach it.
5546
+ * @param forge - forge family of a registered provider, such as `gitlab`.
5547
+ * @param host - host name as the provider's configuration lists it.
5548
+ * @param signal - request cancellation.
5549
+ * @returns the provider's readiness for the host; `unavailable` with the reason when no provider serves the family,
5550
+ * the probe fails, or it runs past `readinessTimeoutMs`.
5551
+ */
5552
+ async hostReadiness(forge, host, signal) {
5553
+ signal.throwIfAborted();
5554
+ try {
5555
+ const env_1 = {
5556
+ stack: [],
5557
+ error: void 0,
5558
+ hasError: false
5559
+ };
5560
+ try {
5561
+ const timeout = __addDisposableResource(env_1, deadline(signal, this.config.readinessTimeoutMs, "FORGE_PANEL_READINESS_TIMEOUT"), false);
5562
+ return await this.home.forge.readiness({
5563
+ forge,
5564
+ host: host.toLowerCase()
5565
+ }, timeout.signal);
5566
+ } catch (e_1) {
5567
+ env_1.error = e_1;
5568
+ env_1.hasError = true;
5569
+ } finally {
5570
+ __disposeResources(env_1);
5571
+ }
5572
+ } catch (error) {
5573
+ signal.throwIfAborted();
5574
+ return {
5575
+ state: "unavailable",
5576
+ message: messageOf(error),
5577
+ signIn: null
5578
+ };
5579
+ }
5580
+ }
5581
+ /**
5024
5582
  * Poll one change request the review page shows at once; its stream reports the result.
5025
5583
  * @param url - web URL of the change request.
5026
5584
  * @param signal - request cancellation.
@@ -5092,6 +5650,37 @@ let ForgePanelController = (() => {
5092
5650
  return result;
5093
5651
  }
5094
5652
  /**
5653
+ * Read the activity of a change request for the review page: its comments, submitted reviews, commits, and changes
5654
+ * of state.
5655
+ * @param url - web URL of the change request.
5656
+ * @param signal - request cancellation.
5657
+ * @returns the activity, or null when the change request's provider reads none.
5658
+ * @throws `forgePanel/unrecognized-url` when no provider serves the URL; `forgePanel/activity-failed` with the
5659
+ * host's reason when the host does not provide it.
5660
+ */
5661
+ async reviewActivity(url, signal) {
5662
+ signal.throwIfAborted();
5663
+ const result = await this.home.forge.readActivity(this.served(url).ref, signal);
5664
+ if (!("code" in result)) return result;
5665
+ if (result.code === "unsupported") return null;
5666
+ throw new RemoteError("forgePanel/activity-failed", result.message, {});
5667
+ }
5668
+ /**
5669
+ * Add a comment to the conversation of a change request the review page shows.
5670
+ * @param url - web URL of the change request.
5671
+ * @param body - Markdown source of the comment.
5672
+ * @param signal - request cancellation.
5673
+ * @throws `forgePanel/unrecognized-url` when no provider serves the URL; `forgePanel/action-failed` when `body` is
5674
+ * blank, or with the host's reason; `forgePanel/action-unknown` when the host's answer did not confirm the comment.
5675
+ */
5676
+ async reviewComment(url, body, signal) {
5677
+ signal.throwIfAborted();
5678
+ const { ref } = this.served(url);
5679
+ if (body.trim() === "") throw new RemoteError("forgePanel/action-failed", "The comment is empty", {});
5680
+ const failure = await this.home.forge.addComment(ref, body, signal);
5681
+ if (failure !== void 0) throw actionError(failure);
5682
+ }
5683
+ /**
5095
5684
  * Read every check of a change request the review page shows.
5096
5685
  * @param url - web URL of the change request.
5097
5686
  * @param headSha - head commit whose checks the page shows.
@@ -5242,6 +5831,20 @@ let ForgePanelController = (() => {
5242
5831
  if (failure !== void 0) throw actionError(failure);
5243
5832
  }
5244
5833
  /**
5834
+ * Turn the code host's automatic merge of a change request the review page shows on, while its head is still the
5835
+ * request's `headSha`, or off.
5836
+ * @param url - web URL of the change request.
5837
+ * @param request - on with the merge method and the head commit the user confirmed, or off.
5838
+ * @param signal - request cancellation.
5839
+ * @throws `forgePanel/unrecognized-url` when no provider serves the URL; `forgePanel/stale-head`,
5840
+ * `forgePanel/action-failed`, or `forgePanel/action-unknown` with the host's reason.
5841
+ */
5842
+ async reviewSetAutoMerge(url, request, signal) {
5843
+ signal.throwIfAborted();
5844
+ const failure = await this.home.forge.setAutoMerge(this.served(url).ref, request, signal);
5845
+ if (failure !== void 0) throw actionError(failure);
5846
+ }
5847
+ /**
5245
5848
  * Rerun the failed checks of a change request the review page shows.
5246
5849
  * @param url - web URL of the change request.
5247
5850
  * @param request - the head commit whose checks the user saw.
@@ -5347,21 +5950,26 @@ let ForgePanelController = (() => {
5347
5950
  ])).stdout, inspection.checkout.branch, remoteOrder(inspection.upstream, inspection.remotes), query, this.config.maxBranches, (remote) => remoteRepository(remote, (url) => this.home.forge.repositoryFromRemote(url)));
5348
5951
  }
5349
5952
  /**
5350
- * List the branches the `branch` scope of the Session's current checkout can compare with.
5953
+ * List the branches the `branch` scope can compare with, for the Session's current checkout or for a head branch
5954
+ * read in its place.
5351
5955
  * @param session - Session whose checkout is read.
5956
+ * @param head - full ref of the branch the scope reads in place of the checked-out one, or null for the checkout.
5352
5957
  * @param query - text the branch names must contain, ignoring case; empty for every branch.
5353
5958
  * @param signal - request cancellation.
5354
5959
  * @returns the automatic fork point and at most `maxBranches` remote-tracking and local branches each,
5355
- * most recently committed first, without the checked-out branch.
5356
- * @throws `forgePanel/not-a-checkout` outside a checkout; the Git error when Git fails or the listed refs exceed `maxDiffBytes`.
5960
+ * most recently committed first, without the branch the scope shows and, for a head, without the Session's
5961
+ * checked-out branch, which the automatic fork point compares with; a local branch that a worktree has checked
5962
+ * out names that worktree's directory.
5963
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/head-missing` when the head does not exist; the
5964
+ * Git error when Git fails or the listed refs exceed `maxDiffBytes`.
5357
5965
  */
5358
- async diffBases(session, query, signal) {
5966
+ async diffBases(session, head, query, signal) {
5359
5967
  signal.throwIfAborted();
5360
- const inspection = await this.checkoutOf(session, signal);
5968
+ const { inspection, created, tip, against } = await this.localTarget(session, head, false, signal);
5361
5969
  return await baseBranches(gitIn(this.home, {
5362
5970
  ...this.config,
5363
5971
  maxOutputBytes: this.config.maxDiffBytes
5364
- }, session, inspection.checkout.root, signal), inspection, this.worktreeState(session).created, query, this.config.maxBranches);
5972
+ }, session, inspection.checkout.root, signal), inspection, created, query, this.config.maxBranches, tip, against);
5365
5973
  }
5366
5974
  /**
5367
5975
  * Bind a change request to a Session by URL, or restore a dismissed binding.
@@ -5410,13 +6018,15 @@ let ForgePanelController = (() => {
5410
6018
  for (const [session, panel] of this.panels) if (session.id === sessionId) await panel.revisit();
5411
6019
  }
5412
6020
  /**
5413
- * Read the changes one scope covers in the checkout of the Session's
5414
- * current directory, with Git using the Session's sandbox policy.
6021
+ * Read the changes one scope covers in the checkout of the Session's current directory, or for the head branch the
6022
+ * scope names: in the worktree that has it checked out, else from its commits. Git uses the Session's sandbox policy.
5415
6023
  * @param session - Session whose checkout is read.
5416
6024
  * @param scope - which changes to read.
5417
6025
  * @param signal - request cancellation.
5418
- * @returns the files, the base of the `branch` scope, and the untracked files left out.
5419
- * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/base-missing` when the base branch
6026
+ * @returns the files, the base of the `branch` scope, the untracked files left out, and the worktree read for a head.
6027
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/head-missing` when the head the scope names
6028
+ * does not exist; `forgePanel/no-working-tree` for another scope than `branch` whose head no worktree has checked
6029
+ * out; `forgePanel/base-missing` when the base branch
5420
6030
  * chosen for the `branch` scope does not exist; `forgePanel/no-fork-point` for the `branch` scope without
5421
6031
  * a fork point; `forgePanel/commits-missing` when chosen commits are not between the fork point and HEAD in order;
5422
6032
  * `forgePanel/commits-not-linear` when a chosen commit's first parent is not the commit listed before it;
@@ -5425,52 +6035,85 @@ let ForgePanelController = (() => {
5425
6035
  */
5426
6036
  async localDiff(session, scope, signal) {
5427
6037
  signal.throwIfAborted();
5428
- const inspection = await this.checkoutOf(session, signal);
6038
+ const { inspection, created, tip, worktree, against } = await this.localTarget(session, scope.head ?? null, scope.kind !== "branch", signal);
5429
6039
  const root = inspection.checkout.root;
5430
6040
  const git = gitIn(this.home, this.config, session, root, signal);
5431
- const created = this.worktreeState(session).created;
5432
- const fork = scope.kind !== "branch" ? null : await diffing(scope.base === null ? forkPoint(git, inspection, created) : chosenForkPoint(git, scope.base));
5433
- return await diffing(localDiff(this.home, this.config, session, root, fork, scope, this.layers, signal));
6041
+ const fork = scope.kind !== "branch" ? null : await diffing(scope.base === null ? forkPoint(git, inspection, created, tip, against) : chosenForkPoint(git, scope.base, tip));
6042
+ const diff = await diffing(localDiff(this.home, this.config, session, root, fork, scope, this.layers, signal, tip));
6043
+ return worktree === null ? diff : {
6044
+ ...diff,
6045
+ worktree
6046
+ };
5434
6047
  }
5435
6048
  /**
5436
- * List the commits of the `branch` scope of the Session's current checkout, which the changes view can show one or
5437
- * several of instead of the whole scope.
6049
+ * List the commits of the `branch` scope of the Session's current checkout or of a head branch read in its place,
6050
+ * which the changes view can show one or several of instead of the whole scope.
5438
6051
  * @param session - Session whose checkout is read.
6052
+ * @param head - full ref of the branch the scope reads in place of the checked-out one, or null for the checkout.
5439
6053
  * @param base - the base ref of the `branch` scope, or null for its automatic fork point.
5440
6054
  * @param signal - request cancellation.
5441
- * @returns the newest `maxCommits` commits between the fork point and HEAD, oldest first, and HEAD's commit.
5442
- * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/base-missing` when the base branch does not
5443
- * exist; `forgePanel/no-fork-point` without a fork point; the Git error when Git fails or the listing exceeds `maxDiffBytes`.
6055
+ * @returns the newest `maxCommits` commits between the fork point and the shown HEAD or branch, oldest first, and its commit.
6056
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/head-missing` when the head does not exist;
6057
+ * `forgePanel/base-missing` when the base branch does not exist; `forgePanel/no-fork-point` without a fork point;
6058
+ * the Git error when Git fails or the listing exceeds `maxDiffBytes`.
5444
6059
  */
5445
- async localCommits(session, base, signal) {
6060
+ async localCommits(session, head, base, signal) {
5446
6061
  signal.throwIfAborted();
5447
- const inspection = await this.checkoutOf(session, signal);
6062
+ const { inspection, created, tip, against } = await this.localTarget(session, head, false, signal);
5448
6063
  const git = gitIn(this.home, {
5449
6064
  ...this.config,
5450
6065
  maxOutputBytes: this.config.maxDiffBytes
5451
6066
  }, session, inspection.checkout.root, signal);
5452
- const created = this.worktreeState(session).created;
5453
- const fork = await diffing(base === null ? forkPoint(git, inspection, created) : chosenForkPoint(git, base));
6067
+ const fork = await diffing(base === null ? forkPoint(git, inspection, created, tip, against) : chosenForkPoint(git, base, tip));
5454
6068
  if (fork === null) throw new RemoteError("forgePanel/no-fork-point", "The checkout has no fork point to compare its branch with", {});
5455
- return await localCommits(git, fork, this.config.maxCommits);
6069
+ return await localCommits(git, fork, this.config.maxCommits, tip);
5456
6070
  }
5457
6071
  /**
5458
6072
  * Read the new side of one changed file in a scope, which supplies the
5459
6073
  * unchanged lines between its hunks: the index for `staged`, the last chosen commit for chosen commits of
5460
- * the `branch` scope, else the working tree.
6074
+ * the `branch` scope, the branch for a head read from its commits, else the working tree of the checkout the scope reads.
5461
6075
  * @param session - Session whose checkout is read.
5462
6076
  * @param scope - the scope the diff was read in.
5463
6077
  * @param path - path relative to the checkout's top-level directory, as the diff names it.
5464
6078
  * @param signal - request cancellation.
5465
6079
  * @returns the text.
5466
- * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/diff-too-large` over `maxDiffBytes`;
6080
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/head-missing` and `forgePanel/no-working-tree`
6081
+ * as for {@link ForgePanelController.localDiff}; `forgePanel/diff-too-large` over `maxDiffBytes`;
5467
6082
  * `forgePanel/commits-missing` for a chosen commit that is not a full object name; an error for a path outside
5468
6083
  * the checkout, binary content, or a failed read.
5469
6084
  */
5470
6085
  async localText(session, scope, path, signal) {
6086
+ signal.throwIfAborted();
6087
+ const { inspection, tip } = await this.localTarget(session, scope.head ?? null, scope.kind !== "branch", signal);
6088
+ return await diffing(localText(this.home, this.config, session, inspection.checkout.root, scope, path, signal, tip));
6089
+ }
6090
+ /**
6091
+ * Stage, unstage, or restore whole files in the checkout of the Session's current directory, or return index
6092
+ * entries to the tree an earlier write reported. The caller's press authorizes the write, so Git runs without the
6093
+ * Session's sandbox policy and under any access mode. The Session's panel inspects the checkout again afterwards,
6094
+ * whether or not the write succeeded.
6095
+ * @param session - Session whose checkout is written.
6096
+ * @param write - the write; `stage` and `restore` name each file with the digest of the change the reader saw.
6097
+ * @param signal - request cancellation.
6098
+ * @returns the index before a `stage` or `unstage` as a tree, for undoing it.
6099
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/local-stale` before anything is written when a
6100
+ * file's unstaged change is not the one the reader saw; `forgePanel/local-path-replaced` before anything is written
6101
+ * when a deleted file's path holds a directory; the errors of {@link ForgePanelController.localDiff} for the
6102
+ * `unstaged` scope; an error for a path outside the checkout, a tree that is not a full object name, a restore of a
6103
+ * submodule or of a file without index content, or a Git failure.
6104
+ */
6105
+ async localWrite(session, write, signal) {
5471
6106
  signal.throwIfAborted();
5472
6107
  const inspection = await this.checkoutOf(session, signal);
5473
- return await diffing(localText(this.home, this.config, session, inspection.checkout.root, scope, path, signal));
6108
+ try {
6109
+ return await diffing(localWrite(this.home, this.config, session, inspection.checkout.root, write, this.layers, signal));
6110
+ } catch (error) {
6111
+ if (error instanceof LocalChangesStale) throw new RemoteError("forgePanel/local-stale", error.message, {}, { cause: error });
6112
+ if (error instanceof LocalPathReplaced) throw new RemoteError("forgePanel/local-path-replaced", error.message, {}, { cause: error });
6113
+ throw error;
6114
+ } finally {
6115
+ this.panels.get(session)?.reinspect();
6116
+ }
5474
6117
  }
5475
6118
  /**
5476
6119
  * Load complete checks for the change request whose list the user opened.
@@ -5758,6 +6401,23 @@ let ForgePanelController = (() => {
5758
6401
  if (failure !== void 0) throw actionError(failure);
5759
6402
  }
5760
6403
  /**
6404
+ * Turn the code host's automatic merge of a change request of a Session on, while its head is still the request's
6405
+ * `headSha`, or off; the change request is polled again once the host answers.
6406
+ * @param session - Session the change request is bound to.
6407
+ * @param url - binding URL of the change request.
6408
+ * @param request - on with the merge method and the head commit the user confirmed, or off.
6409
+ * @param signal - request cancellation.
6410
+ * @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
6411
+ * `forgePanel/stale-head` when the head moved past the request's `headSha`; `forgePanel/action-failed` with the
6412
+ * host's reason when the host refuses otherwise, cannot be reached, or sets no automatic merge;
6413
+ * `forgePanel/action-unknown` when the host's answer did not confirm the change.
6414
+ */
6415
+ async setAutoMerge(session, url, request, signal) {
6416
+ signal.throwIfAborted();
6417
+ const failure = await this.home.forge.setAutoMerge(this.bound(session, url).ref, request, signal);
6418
+ if (failure !== void 0) throw actionError(failure);
6419
+ }
6420
+ /**
5761
6421
  * Rerun the failed checks of a change request of a Session while its head is still the commit whose checks the user
5762
6422
  * saw; the change request is polled again once the host answers.
5763
6423
  * @param session - Session the change request is bound to.
@@ -6043,6 +6703,49 @@ let ForgePanelController = (() => {
6043
6703
  if (attributes.code === "not-found") return "";
6044
6704
  throw readError(attributes);
6045
6705
  }
6706
+ /**
6707
+ * Resolve what a local read targets: the Session's own checkout with the worktree it created; for a head branch,
6708
+ * the worktree of the repository that has it checked out, read as a checkout; or, when none has, the verified
6709
+ * branch itself, read from its commits. A head branch also carries the Session's own HEAD, which is what it is
6710
+ * compared with while no base branch is chosen.
6711
+ * @param working - whether the read needs a working tree, as every scope but `branch` does.
6712
+ * @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/head-missing` when the branch does not exist;
6713
+ * `forgePanel/no-working-tree` when `working` and no worktree has the branch checked out.
6714
+ */
6715
+ async localTarget(session, head, working, signal) {
6716
+ const own = await this.checkoutOf(session, signal);
6717
+ const ownTarget = {
6718
+ inspection: own,
6719
+ created: this.worktreeState(session).created,
6720
+ tip: "HEAD",
6721
+ worktree: null,
6722
+ against: null
6723
+ };
6724
+ if (head === null) return ownTarget;
6725
+ const git = gitIn(this.home, {
6726
+ ...this.config,
6727
+ maxOutputBytes: this.config.maxDiffBytes
6728
+ }, session, own.checkout.root, signal);
6729
+ const tip = await diffing(branchTip(git, head));
6730
+ const against = await sessionHead(git, own.checkout);
6731
+ const directory = head.startsWith("refs/heads/") ? (await branchWorktrees(git)).get(head) : void 0;
6732
+ const inspection = directory === void 0 || await this.home.fs.lstat(directory, void 0, signal) === void 0 ? void 0 : await inspectCheckout(this.home, this.config, session, directory, signal);
6733
+ if (inspection?.commonDir === own.commonDir && inspection.checkout.branch === head.slice(11)) return inspection.checkout.root === own.checkout.root ? ownTarget : {
6734
+ inspection,
6735
+ created: null,
6736
+ tip: "HEAD",
6737
+ worktree: inspection.checkout.root,
6738
+ against
6739
+ };
6740
+ if (working) throw new RemoteError("forgePanel/no-working-tree", "No worktree has the branch checked out, so it has no working tree", {});
6741
+ return {
6742
+ inspection: own,
6743
+ created: null,
6744
+ tip,
6745
+ worktree: null,
6746
+ against
6747
+ };
6748
+ }
6046
6749
  /** Inspect the checkout of the Session's current directory, which local diffs read. */
6047
6750
  async checkoutOf(session, signal) {
6048
6751
  const inspection = await inspectCheckout(this.home, this.config, session, this.home.workingDirectory.get(session), signal);
@@ -6223,7 +6926,7 @@ let ForgePanelController = (() => {
6223
6926
  await work(agent, signal);
6224
6927
  });
6225
6928
  } catch (error) {
6226
- throw new RemoteError("forgePanel/session-busy", "The Session is busy", {}, { cause: error });
6929
+ throw new RemoteError("forgePanel/session-busy", `The Session is busy: ${messageOf(error)}`, {}, { cause: error });
6227
6930
  }
6228
6931
  await running;
6229
6932
  }
@@ -6301,11 +7004,11 @@ let ForgePanelController = (() => {
6301
7004
  /** The files a lens request names with their reader and the key results for them are kept under. */
6302
7005
  async lensSubject(session, source, signal) {
6303
7006
  if (source.kind === "local") {
6304
- const inspection = await this.checkoutOf(session, signal);
6305
- const root = inspection.checkout.root;
6306
7007
  const { scope } = source;
6307
- const fork = scope.kind !== "branch" ? null : await diffing(scope.base === null ? forkPoint(gitIn(this.home, this.config, session, root, signal), inspection, this.worktreeState(session).created) : chosenForkPoint(gitIn(this.home, this.config, session, root, signal), scope.base));
6308
- const { files } = await diffing(localDiff(this.home, this.config, session, root, fork, scope, this.layers, signal));
7008
+ const { inspection, created, tip, against } = await this.localTarget(session, scope.head ?? null, scope.kind !== "branch", signal);
7009
+ const root = inspection.checkout.root;
7010
+ const fork = scope.kind !== "branch" ? null : await diffing(scope.base === null ? forkPoint(gitIn(this.home, this.config, session, root, signal), inspection, created, tip, against) : chosenForkPoint(gitIn(this.home, this.config, session, root, signal), scope.base, tip));
7011
+ const { files } = await diffing(localDiff(this.home, this.config, session, root, fork, scope, this.layers, signal, tip));
6309
7012
  return {
6310
7013
  key: JSON.stringify([
6311
7014
  "local",
@@ -6319,7 +7022,7 @@ let ForgePanelController = (() => {
6319
7022
  files,
6320
7023
  read: async (side, file, inner) => {
6321
7024
  if (file.binary || (side === "old" ? file.status === "added" : file.status === "deleted")) return null;
6322
- return side === "new" ? await diffing(localText(this.home, this.config, session, root, scope, file.path, inner)) : await diffing(localOldText(this.home, this.config, session, root, scope, fork, file.previousPath ?? file.path, inner));
7025
+ return side === "new" ? await diffing(localText(this.home, this.config, session, root, scope, file.path, inner, tip)) : await diffing(localOldText(this.home, this.config, session, root, scope, fork, file.previousPath ?? file.path, inner));
6323
7026
  }
6324
7027
  };
6325
7028
  }
@@ -6471,8 +7174,8 @@ function reviewError(failure) {
6471
7174
  }
6472
7175
  }
6473
7176
  /**
6474
- * Settle a diff read, reporting its size limit, its filter configuration, a missing fork point, a missing base branch, and chosen
6475
- * commits that are not on the branch as Remote errors.
7177
+ * Settle a diff read, reporting its size limit, its filter configuration, a missing fork point, a missing base branch, a missing
7178
+ * head, and chosen commits that are not on the branch as Remote errors.
6476
7179
  * @param reading - the read.
6477
7180
  * @returns what the read returned.
6478
7181
  */
@@ -6484,6 +7187,7 @@ async function diffing(reading) {
6484
7187
  if (error instanceof DiffTooLarge) throw new RemoteError("forgePanel/diff-too-large", error.message, {}, { cause: error });
6485
7188
  if (error instanceof NoForkPoint) throw new RemoteError("forgePanel/no-fork-point", error.message, {}, { cause: error });
6486
7189
  if (error instanceof BaseMissing) throw new RemoteError("forgePanel/base-missing", error.message, {}, { cause: error });
7190
+ if (error instanceof HeadMissing) throw new RemoteError("forgePanel/head-missing", error.message, {}, { cause: error });
6487
7191
  if (error instanceof CommitsMissing) throw new RemoteError("forgePanel/commits-missing", error.message, {}, { cause: error });
6488
7192
  if (error instanceof CommitsNotLinear) throw new RemoteError("forgePanel/commits-not-linear", error.message, {}, { cause: error });
6489
7193
  throw error;