@deepseek-ai/dsh-experimental-client-ui-forge 0.2.2-alpha.3 → 0.2.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +8 -8
- package/README.md +41 -14
- package/README.zh.md +40 -13
- package/lib/client.js +13 -11800
- package/lib/client.js.map +1 -0
- package/lib/index.js +1340 -115
- package/lib/typert.host.js +1715 -212
- package/lib/typert.remote-client.d.ts +42 -5
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +1523 -244
- package/lib/types/client/ActionToast.d.ts.map +1 -0
- package/lib/types/client/ActionToast.js.map +1 -0
- package/lib/types/client/BaseMenu.d.ts +30 -0
- package/lib/types/client/BaseMenu.d.ts.map +1 -0
- package/lib/types/client/BaseMenu.js.map +1 -0
- package/lib/types/client/ChangeRequestCard.d.ts +9 -5
- package/lib/types/client/ChangeRequestCard.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestCard.js.map +1 -0
- package/lib/types/client/ChangeRequestOverview.d.ts +124 -0
- package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestOverview.js.map +1 -0
- package/lib/types/client/ChangedFiles.d.ts +2 -0
- package/lib/types/client/ChangedFiles.d.ts.map +1 -0
- package/lib/types/client/ChangedFiles.js.map +1 -0
- package/lib/types/client/ChangesTab.d.ts +30 -5
- package/lib/types/client/ChangesTab.d.ts.map +1 -0
- package/lib/types/client/ChangesTab.js.map +1 -0
- package/lib/types/client/ChangesTabTitle.d.ts.map +1 -0
- package/lib/types/client/ChangesTabTitle.js.map +1 -0
- package/lib/types/client/CommitMenu.d.ts +41 -0
- package/lib/types/client/CommitMenu.d.ts.map +1 -0
- package/lib/types/client/CommitMenu.js.map +1 -0
- package/lib/types/client/DiffFile.d.ts +47 -15
- package/lib/types/client/DiffFile.d.ts.map +1 -0
- package/lib/types/client/DiffFile.js.map +1 -0
- package/lib/types/client/FileLabel.d.ts.map +1 -0
- package/lib/types/client/FileLabel.js.map +1 -0
- package/lib/types/client/FileTreePane.d.ts +4 -2
- package/lib/types/client/FileTreePane.d.ts.map +1 -0
- package/lib/types/client/FileTreePane.js.map +1 -0
- package/lib/types/client/ForgeTab.d.ts +9 -1
- package/lib/types/client/ForgeTab.d.ts.map +1 -0
- package/lib/types/client/ForgeTab.js.map +1 -0
- package/lib/types/client/ForgeTabTitle.d.ts.map +1 -0
- package/lib/types/client/ForgeTabTitle.js.map +1 -0
- package/lib/types/client/HeaderButton.d.ts.map +1 -0
- package/lib/types/client/HeaderButton.js.map +1 -0
- package/lib/types/client/LocalChangesCard.d.ts.map +1 -0
- package/lib/types/client/LocalChangesCard.js.map +1 -0
- package/lib/types/client/RefreshGlyph.d.ts.map +1 -0
- package/lib/types/client/RefreshGlyph.js.map +1 -0
- package/lib/types/client/ReviewComposer.d.ts +20 -6
- package/lib/types/client/ReviewComposer.d.ts.map +1 -0
- package/lib/types/client/ReviewComposer.js.map +1 -0
- package/lib/types/client/ReviewControls.d.ts +79 -0
- package/lib/types/client/ReviewControls.d.ts.map +1 -0
- package/lib/types/client/ReviewControls.js.map +1 -0
- package/lib/types/client/ReviewThread.d.ts +4 -4
- package/lib/types/client/ReviewThread.d.ts.map +1 -0
- package/lib/types/client/ReviewThread.js.map +1 -0
- package/lib/types/client/ReviewThreads.d.ts +108 -0
- package/lib/types/client/ReviewThreads.d.ts.map +1 -0
- package/lib/types/client/ReviewThreads.js.map +1 -0
- package/lib/types/client/SessionHoverForge.d.ts.map +1 -0
- package/lib/types/client/SessionHoverForge.js.map +1 -0
- package/lib/types/client/SessionRowForge.d.ts +1 -1
- package/lib/types/client/SessionRowForge.d.ts.map +1 -0
- package/lib/types/client/SessionRowForge.js.map +1 -0
- package/lib/types/client/SubmitReview.d.ts +12 -4
- package/lib/types/client/SubmitReview.d.ts.map +1 -0
- package/lib/types/client/SubmitReview.js.map +1 -0
- package/lib/types/client/ThreadList.d.ts +43 -0
- package/lib/types/client/ThreadList.d.ts.map +1 -0
- package/lib/types/client/ThreadList.js.map +1 -0
- package/lib/types/client/ViewOptionsMenu.d.ts +31 -0
- package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -0
- package/lib/types/client/ViewOptionsMenu.js.map +1 -0
- package/lib/types/client/WorktreeProgress.d.ts.map +1 -0
- package/lib/types/client/WorktreeProgress.js.map +1 -0
- package/lib/types/client/WorktreeSettings.d.ts +12 -0
- package/lib/types/client/WorktreeSettings.d.ts.map +1 -0
- package/lib/types/client/WorktreeSettings.js.map +1 -0
- package/lib/types/client/WorktreeToggle.d.ts.map +1 -0
- package/lib/types/client/WorktreeToggle.js.map +1 -0
- package/lib/types/client/changes-address.d.ts.map +1 -0
- package/lib/types/client/changes-address.js.map +1 -0
- package/lib/types/client/changes-store.d.ts +20 -5
- package/lib/types/client/changes-store.d.ts.map +1 -0
- package/lib/types/client/changes-store.js.map +1 -0
- package/lib/types/client/checkout.d.ts.map +1 -0
- package/lib/types/client/checkout.js.map +1 -0
- package/lib/types/client/code-selection.d.ts.map +1 -0
- package/lib/types/client/code-selection.js.map +1 -0
- package/lib/types/client/diff-rows.d.ts.map +1 -0
- package/lib/types/client/diff-rows.js.map +1 -0
- package/lib/types/client/file-tree.d.ts.map +1 -0
- package/lib/types/client/file-tree.js.map +1 -0
- package/lib/types/client/format.d.ts.map +1 -0
- package/lib/types/client/format.js.map +1 -0
- package/lib/types/client/glyphs.d.ts +4 -2
- package/lib/types/client/glyphs.d.ts.map +1 -0
- package/lib/types/client/glyphs.js.map +1 -0
- package/lib/types/client/host-viewed.d.ts +84 -0
- package/lib/types/client/host-viewed.d.ts.map +1 -0
- package/lib/types/client/host-viewed.js.map +1 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/locales.d.ts +175 -3
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/locales.js.map +1 -0
- package/lib/types/client/menu-search.d.ts +10 -0
- package/lib/types/client/menu-search.d.ts.map +1 -0
- package/lib/types/client/menu-search.js.map +1 -0
- package/lib/types/client/mount.d.ts +4 -0
- package/lib/types/client/mount.d.ts.map +1 -0
- package/lib/types/client/mount.js.map +1 -0
- package/lib/types/client/review-queue.d.ts +5 -8
- package/lib/types/client/review-queue.d.ts.map +1 -0
- package/lib/types/client/review-queue.js.map +1 -0
- package/lib/types/client/review-threads.d.ts +108 -0
- package/lib/types/client/review-threads.d.ts.map +1 -0
- package/lib/types/client/review-threads.js.map +1 -0
- package/lib/types/client/review.d.ts +31 -4
- package/lib/types/client/review.d.ts.map +1 -0
- package/lib/types/client/review.js.map +1 -0
- package/lib/types/client/section-reach.d.ts +26 -0
- package/lib/types/client/section-reach.d.ts.map +1 -0
- package/lib/types/client/section-reach.js.map +1 -0
- package/lib/types/client/session-list.d.ts.map +1 -0
- package/lib/types/client/session-list.js.map +1 -0
- package/lib/types/client/source.d.ts.map +1 -0
- package/lib/types/client/source.js.map +1 -0
- package/lib/types/client/status.d.ts.map +1 -0
- package/lib/types/client/status.js.map +1 -0
- package/lib/types/client/thread-state.d.ts +68 -0
- package/lib/types/client/thread-state.d.ts.map +1 -0
- package/lib/types/client/thread-state.js.map +1 -0
- package/lib/types/client/toolbar-fold.d.ts +19 -0
- package/lib/types/client/toolbar-fold.d.ts.map +1 -0
- package/lib/types/client/toolbar-fold.js.map +1 -0
- package/lib/types/client/viewed-files.d.ts +70 -0
- package/lib/types/client/viewed-files.d.ts.map +1 -0
- package/lib/types/client/viewed-files.js.map +1 -0
- package/lib/types/client/worktree-settings-form.d.ts +32 -0
- package/lib/types/client/worktree-settings-form.d.ts.map +1 -0
- package/lib/types/client/worktree-settings-form.js.map +1 -0
- package/lib/types/commit-range.d.ts +17 -0
- package/lib/types/commit-range.d.ts.map +1 -0
- package/lib/types/commit-range.js.map +1 -0
- package/lib/types/diff.d.ts +10 -2
- package/lib/types/diff.d.ts.map +1 -0
- package/lib/types/diff.js.map +1 -0
- package/lib/types/git.d.ts.map +1 -0
- package/lib/types/git.js.map +1 -0
- package/lib/types/index.d.ts +194 -14
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/layers.d.ts +66 -0
- package/lib/types/layers.d.ts.map +1 -0
- package/lib/types/layers.js.map +1 -0
- package/lib/types/local-diff.d.ts +54 -6
- package/lib/types/local-diff.d.ts.map +1 -0
- package/lib/types/local-diff.js.map +1 -0
- package/lib/types/panel.d.ts.map +1 -0
- package/lib/types/panel.js.map +1 -0
- package/lib/types/parse.d.ts +16 -0
- package/lib/types/parse.d.ts.map +1 -0
- package/lib/types/parse.js.map +1 -0
- package/lib/types/patch-cache.d.ts +12 -7
- package/lib/types/patch-cache.d.ts.map +1 -0
- package/lib/types/patch-cache.js.map +1 -0
- package/lib/types/review-cache.d.ts +54 -0
- package/lib/types/review-cache.d.ts.map +1 -0
- package/lib/types/review-cache.js.map +1 -0
- package/lib/types/states.d.ts.map +1 -0
- package/lib/types/states.js.map +1 -0
- package/lib/types/types.d.ts +113 -11
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js.map +1 -0
- package/lib/types/wildmatch.d.ts +14 -0
- package/lib/types/wildmatch.d.ts.map +1 -0
- package/lib/types/wildmatch.js.map +1 -0
- package/lib/types/worktree.d.ts +8 -6
- package/lib/types/worktree.d.ts.map +1 -0
- package/lib/types/worktree.js.map +1 -0
- package/package.json +59 -49
- package/src/client/ActionToast.tsx +38 -0
- package/src/client/BaseMenu.module.css +153 -0
- package/src/client/BaseMenu.tsx +180 -0
- package/src/client/ChangeRequestCard.tsx +439 -0
- package/src/client/ChangeRequestOverview.module.css +196 -0
- package/src/client/ChangeRequestOverview.tsx +620 -0
- package/src/client/ChangedFiles.module.css +26 -0
- package/src/client/ChangedFiles.tsx +144 -0
- package/src/client/ChangesTab.module.css +984 -0
- package/src/client/ChangesTab.tsx +1288 -0
- package/src/client/ChangesTabTitle.tsx +28 -0
- package/src/client/CommitMenu.module.css +139 -0
- package/src/client/CommitMenu.tsx +186 -0
- package/src/client/DiffFile.tsx +621 -0
- package/src/client/FileLabel.module.css +53 -0
- package/src/client/FileLabel.tsx +66 -0
- package/src/client/FileTreePane.module.css +10 -0
- package/src/client/FileTreePane.tsx +79 -0
- package/src/client/ForgeTab.module.css +627 -0
- package/src/client/ForgeTab.tsx +263 -0
- package/src/client/ForgeTabTitle.tsx +21 -0
- package/src/client/HeaderButton.module.css +29 -0
- package/src/client/HeaderButton.tsx +68 -0
- package/src/client/LocalChangesCard.tsx +83 -0
- package/src/client/RefreshGlyph.module.css +22 -0
- package/src/client/RefreshGlyph.tsx +35 -0
- package/src/client/ReviewComposer.module.css +37 -0
- package/src/client/ReviewComposer.tsx +128 -0
- package/src/client/ReviewControls.module.css +162 -0
- package/src/client/ReviewControls.tsx +191 -0
- package/src/client/ReviewThread.tsx +96 -0
- package/src/client/ReviewThreads.module.css +326 -0
- package/src/client/ReviewThreads.tsx +443 -0
- package/src/client/SessionHoverForge.tsx +72 -0
- package/src/client/SessionList.module.css +85 -0
- package/src/client/SessionRowForge.tsx +86 -0
- package/src/client/SubmitReview.module.css +26 -0
- package/src/client/SubmitReview.tsx +95 -0
- package/src/client/ThreadList.module.css +218 -0
- package/src/client/ThreadList.tsx +165 -0
- package/src/client/ViewOptionsMenu.tsx +79 -0
- package/src/client/WorktreeProgress.module.css +226 -0
- package/src/client/WorktreeProgress.tsx +280 -0
- package/src/client/WorktreeSettings.module.css +29 -0
- package/src/client/WorktreeSettings.tsx +42 -0
- package/src/client/WorktreeToggle.module.css +132 -0
- package/src/client/WorktreeToggle.tsx +165 -0
- package/src/client/changes-address.ts +110 -0
- package/src/client/changes-store.ts +155 -0
- package/src/client/checkout.ts +75 -0
- package/src/client/code-selection.ts +53 -0
- package/src/client/diff-rows.ts +199 -0
- package/src/client/file-tree.ts +86 -0
- package/src/client/format.ts +37 -0
- package/src/client/glyphs.tsx +151 -0
- package/src/client/host-viewed.ts +195 -0
- package/src/client/index.ts +31 -0
- package/src/client/locales.ts +3446 -0
- package/src/client/menu-search.ts +16 -0
- package/src/client/mount.ts +439 -0
- package/src/client/review-queue.ts +256 -0
- package/src/client/review-threads.ts +204 -0
- package/src/client/review.ts +120 -0
- package/src/client/section-reach.ts +61 -0
- package/src/client/session-list.ts +79 -0
- package/src/client/source.ts +274 -0
- package/src/client/status.ts +171 -0
- package/src/client/thread-state.ts +127 -0
- package/src/client/toolbar-fold.ts +70 -0
- package/src/client/viewed-files.ts +178 -0
- package/src/client/worktree-settings-form.ts +43 -0
- package/src/commit-range.ts +27 -0
- package/src/css-modules.d.ts +5 -0
- package/src/diff.ts +162 -0
- package/src/git.ts +293 -0
- package/src/index.ts +1162 -0
- package/src/layers.ts +163 -0
- package/src/local-diff.ts +438 -0
- package/src/panel.ts +422 -0
- package/src/parse.ts +137 -0
- package/src/patch-cache.ts +73 -0
- package/src/review-cache.ts +98 -0
- package/src/states.ts +350 -0
- package/src/types.ts +504 -0
- package/src/wildmatch.ts +121 -0
- package/src/worktree.ts +576 -0
package/lib/index.js
CHANGED
|
@@ -4,14 +4,16 @@ import { changeRequestKey } from "@deepseek-ai/dsh-experimental-forge";
|
|
|
4
4
|
import { appendPluginRecord, pluginRecordOf } from "@deepseek-ai/dsh-session";
|
|
5
5
|
import { MAX_TIMER_DELAY_MS, deadline } from "@deepseek-ai/dsh-timeout";
|
|
6
6
|
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
7
|
+
import { assertNever } from "@deepseek-ai/dsh-util-values";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
7
9
|
import { parsePatch } from "diff";
|
|
8
10
|
import { FsError } from "@deepseek-ai/dsh-fs";
|
|
9
|
-
import
|
|
11
|
+
import picomatch from "picomatch";
|
|
12
|
+
import { isDeepStrictEqual } from "node:util";
|
|
10
13
|
import { isAbsolute, relative, sep } from "node:path";
|
|
11
|
-
import { generatedWorktreeName } from "@deepseek-ai/dsh-experimental-worktree";
|
|
14
|
+
import { CREATED_RECORD, createdWorktreeSchema, generatedWorktreeName } from "@deepseek-ai/dsh-experimental-worktree";
|
|
12
15
|
import { z as z$1 } from "zod";
|
|
13
16
|
import { Buffer } from "node:buffer";
|
|
14
|
-
import { createHash } from "node:crypto";
|
|
15
17
|
import { defineDomain } from "@deepseek-ai/dsh-storage-domain";
|
|
16
18
|
//#region lib/types/parse.js
|
|
17
19
|
/** Parsers for the porcelain output of the read-only Git commands the panel runs. */
|
|
@@ -35,6 +37,39 @@ function parseName(output) {
|
|
|
35
37
|
const [name = ""] = output.split(/\r?\n/);
|
|
36
38
|
return name.length === 0 ? null : name;
|
|
37
39
|
}
|
|
40
|
+
/** Ref prefixes of the branches the `branch` scope can compare with: local branches, then remote-tracking branches. */
|
|
41
|
+
const BASE_REF_PREFIXES = ["refs/heads/", "refs/remotes/"];
|
|
42
|
+
/**
|
|
43
|
+
* Select the branches the `branch` scope can compare with from `git for-each-ref`
|
|
44
|
+
* output, keeping its order and leaving out symbolic refs and the checked-out branch.
|
|
45
|
+
* @param output - stdout of `git for-each-ref --format=%(refname)%00%(symref)` over {@link BASE_REF_PREFIXES}.
|
|
46
|
+
* @param current - checked-out branch, or null when HEAD is detached.
|
|
47
|
+
* @param query - text the names must contain, ignoring case; empty or blank for every branch.
|
|
48
|
+
* @param limit - most branches in each group.
|
|
49
|
+
* @returns remote-tracking and local branches, at most `limit` of each.
|
|
50
|
+
*/
|
|
51
|
+
function parseBaseBranches(output, current, query, limit) {
|
|
52
|
+
const [heads, remotes] = BASE_REF_PREFIXES;
|
|
53
|
+
const needle = query.trim().toLowerCase();
|
|
54
|
+
const remote = [];
|
|
55
|
+
const local = [];
|
|
56
|
+
for (const line of output.split(/\r?\n/)) {
|
|
57
|
+
const [ref = "", symref = ""] = line.split("\0");
|
|
58
|
+
if (symref.length > 0) continue;
|
|
59
|
+
const group = ref.startsWith(heads) ? local : ref.startsWith(remotes) ? remote : void 0;
|
|
60
|
+
if (group === void 0 || group.length >= limit) continue;
|
|
61
|
+
const name = ref.slice(group === local ? heads.length : remotes.length);
|
|
62
|
+
if (name.length === 0 || group === local && name === current || !name.toLowerCase().includes(needle)) continue;
|
|
63
|
+
group.push({
|
|
64
|
+
ref,
|
|
65
|
+
name
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
remote,
|
|
70
|
+
local
|
|
71
|
+
};
|
|
72
|
+
}
|
|
38
73
|
/**
|
|
39
74
|
* Order worktree base branches: the checked-out branch first, then the other
|
|
40
75
|
* listed branches in listed order.
|
|
@@ -43,7 +78,7 @@ function parseName(output) {
|
|
|
43
78
|
* @param limit - most names to return.
|
|
44
79
|
* @returns distinct branch names, at most `limit`.
|
|
45
80
|
*/
|
|
46
|
-
function baseBranches(current, output, limit) {
|
|
81
|
+
function baseBranches$1(current, output, limit) {
|
|
47
82
|
const listed = output.split(/\r?\n/).filter((name) => name.length > 0 && name !== current);
|
|
48
83
|
return (current === null ? listed : [current, ...listed]).slice(0, limit);
|
|
49
84
|
}
|
|
@@ -288,7 +323,7 @@ async function listBranches(ctx, config, session, directory, limit, signal) {
|
|
|
288
323
|
});
|
|
289
324
|
return {
|
|
290
325
|
current,
|
|
291
|
-
branches: baseBranches(current, refs.stdout, limit)
|
|
326
|
+
branches: baseBranches$1(current, refs.stdout, limit)
|
|
292
327
|
};
|
|
293
328
|
}
|
|
294
329
|
/** A failed read cancels its siblings and returns only after every read has finished cleanup. */
|
|
@@ -425,6 +460,8 @@ function firstLine(text) {
|
|
|
425
460
|
const NULL_PATH = "/dev/null";
|
|
426
461
|
/** Bytes Git inspects for a NUL byte before it calls content binary. */
|
|
427
462
|
const BINARY_PROBE_BYTES = 8e3;
|
|
463
|
+
/** Blob names of both sides on a Git `index` header line, which identify a binary change that carries no hunks. */
|
|
464
|
+
const INDEX_LINE = /^index ([0-9a-f]+\.\.[0-9a-f]+)/m;
|
|
428
465
|
/**
|
|
429
466
|
* Parse a Git-style unified patch, as `git diff` or a code host prints it,
|
|
430
467
|
* with `a/` and `b/` path prefixes. Hunk ranges follow jsdiff: a range that
|
|
@@ -433,7 +470,9 @@ const BINARY_PROBE_BYTES = 8e3;
|
|
|
433
470
|
* @returns one file per patch section in patch order.
|
|
434
471
|
*/
|
|
435
472
|
function parseDiff(patch) {
|
|
436
|
-
|
|
473
|
+
const parsed = parsePatch(patch);
|
|
474
|
+
const headers = patch.split(/^(?=diff --git )/m).filter((section) => section.startsWith("diff --git "));
|
|
475
|
+
return parsed.flatMap((section, index) => {
|
|
437
476
|
const before = pathOf(section.oldFileName, "a/");
|
|
438
477
|
const after = pathOf(section.newFileName, "b/");
|
|
439
478
|
const path = after ?? before;
|
|
@@ -443,25 +482,43 @@ function parseDiff(patch) {
|
|
|
443
482
|
let deletions = 0;
|
|
444
483
|
for (const hunk of section.hunks) for (const line of hunk.lines) if (line.startsWith("+")) additions++;
|
|
445
484
|
else if (line.startsWith("-")) deletions++;
|
|
485
|
+
const binary = section.isBinary === true;
|
|
486
|
+
const previousPath = status === "renamed" ? before : null;
|
|
487
|
+
const hunks = section.hunks.map(({ oldStart, oldLines, newStart, newLines, lines }) => ({
|
|
488
|
+
oldStart,
|
|
489
|
+
oldLines,
|
|
490
|
+
newStart,
|
|
491
|
+
newLines,
|
|
492
|
+
lines
|
|
493
|
+
}));
|
|
494
|
+
const header = binary && headers.length === parsed.length ? String(headers[index]) : "";
|
|
495
|
+
const blobs = INDEX_LINE.exec(header)?.[1] ?? "";
|
|
496
|
+
const modes = `${section.oldMode ?? ""}..${section.newMode ?? ""}`;
|
|
446
497
|
return [{
|
|
447
498
|
path,
|
|
448
|
-
previousPath
|
|
499
|
+
previousPath,
|
|
449
500
|
status,
|
|
450
|
-
binary
|
|
501
|
+
binary,
|
|
451
502
|
oversized: false,
|
|
452
503
|
untracked: false,
|
|
453
504
|
additions,
|
|
454
505
|
deletions,
|
|
455
|
-
hunks
|
|
456
|
-
|
|
457
|
-
oldLines,
|
|
458
|
-
newStart,
|
|
459
|
-
newLines,
|
|
460
|
-
lines
|
|
461
|
-
}))
|
|
506
|
+
hunks,
|
|
507
|
+
digest: changeDigest(path, previousPath, status, hunks, blobs, modes)
|
|
462
508
|
}];
|
|
463
509
|
});
|
|
464
510
|
}
|
|
511
|
+
/** Digest of one change: its paths, status, hunks, file modes, and the identity of content that hunks do not show. */
|
|
512
|
+
function changeDigest(path, previousPath, status, hunks, content, modes) {
|
|
513
|
+
return createHash("sha256").update(JSON.stringify([
|
|
514
|
+
path,
|
|
515
|
+
previousPath,
|
|
516
|
+
status,
|
|
517
|
+
hunks,
|
|
518
|
+
content,
|
|
519
|
+
modes
|
|
520
|
+
])).digest("hex").slice(0, 32);
|
|
521
|
+
}
|
|
465
522
|
/**
|
|
466
523
|
* Describe an untracked file as added in full.
|
|
467
524
|
* @param path - path relative to the repository root.
|
|
@@ -469,36 +526,57 @@ function parseDiff(patch) {
|
|
|
469
526
|
* @returns the file with one hunk of added lines, none when it is empty, or none and `binary` when its content is not text.
|
|
470
527
|
*/
|
|
471
528
|
function untrackedFile(path, content) {
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
529
|
+
const text = decodeText(content);
|
|
530
|
+
if (text === void 0) return addedFile(path, [], {
|
|
531
|
+
binary: true,
|
|
532
|
+
oversized: false,
|
|
533
|
+
content: createHash("sha256").update(content).digest("hex")
|
|
534
|
+
});
|
|
535
|
+
if (text.length === 0) return addedFile(path, [], {
|
|
476
536
|
binary: false,
|
|
477
537
|
oversized: false,
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
deletions: 0,
|
|
481
|
-
hunks: []
|
|
482
|
-
};
|
|
483
|
-
const text = decodeText(content);
|
|
484
|
-
if (text === void 0) return {
|
|
485
|
-
...file,
|
|
486
|
-
binary: true
|
|
487
|
-
};
|
|
488
|
-
if (text.length === 0) return file;
|
|
538
|
+
content: ""
|
|
539
|
+
});
|
|
489
540
|
const lines = text.split("\n");
|
|
490
541
|
const ended = lines.at(-1) === "";
|
|
491
542
|
if (ended) lines.pop();
|
|
543
|
+
return addedFile(path, [{
|
|
544
|
+
oldStart: 1,
|
|
545
|
+
oldLines: 0,
|
|
546
|
+
newStart: 1,
|
|
547
|
+
newLines: lines.length,
|
|
548
|
+
lines: [...lines.map((line) => `+${line}`), ...ended ? [] : ["\"]]
|
|
549
|
+
}], {
|
|
550
|
+
binary: false,
|
|
551
|
+
oversized: false,
|
|
552
|
+
content: ""
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Describe an untracked file over `maxDiffBytes`, which carries no hunks and whose content is not read.
|
|
557
|
+
* @param path - path relative to the repository root.
|
|
558
|
+
* @returns the oversized added file.
|
|
559
|
+
*/
|
|
560
|
+
function oversizedUntrackedFile(path) {
|
|
561
|
+
return addedFile(path, [], {
|
|
562
|
+
binary: false,
|
|
563
|
+
oversized: true,
|
|
564
|
+
content: "oversized"
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
/** An untracked file as added, whose digest also covers `content`, the identity of content its hunks do not show. */
|
|
568
|
+
function addedFile(path, hunks, { binary, oversized, content }) {
|
|
492
569
|
return {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
570
|
+
path,
|
|
571
|
+
previousPath: null,
|
|
572
|
+
status: "added",
|
|
573
|
+
binary,
|
|
574
|
+
oversized,
|
|
575
|
+
untracked: true,
|
|
576
|
+
additions: hunks[0]?.newLines ?? 0,
|
|
577
|
+
deletions: 0,
|
|
578
|
+
hunks,
|
|
579
|
+
digest: changeDigest(path, null, "added", hunks, content, "")
|
|
502
580
|
};
|
|
503
581
|
}
|
|
504
582
|
/**
|
|
@@ -554,6 +632,356 @@ function pathOf(name, prefix) {
|
|
|
554
632
|
return name.startsWith(prefix) ? name.slice(prefix.length) : name;
|
|
555
633
|
}
|
|
556
634
|
//#endregion
|
|
635
|
+
//#region lib/types/commit-range.js
|
|
636
|
+
/**
|
|
637
|
+
* Checks of a chosen run of commits against a commit list, shared by the Host, which reads the run's changes, and the
|
|
638
|
+
* commit picker, which refuses a run before asking for them.
|
|
639
|
+
*/
|
|
640
|
+
/**
|
|
641
|
+
* Find the first commit of a chosen run in a commit list. Two ends describe the run only when each commit after the
|
|
642
|
+
* first has the commit listed before it as its first parent, so the changes from the first commit's first parent to the
|
|
643
|
+
* last commit are exactly the run's changes.
|
|
644
|
+
* @param commits - listed commits, oldest first.
|
|
645
|
+
* @param range - the chosen run.
|
|
646
|
+
* @returns the first chosen commit; `missing` when an end is not listed or `to` is listed before `from`; `not-linear`
|
|
647
|
+
* when a commit of the run does not have the commit listed before it as its first parent.
|
|
648
|
+
*/
|
|
649
|
+
function rangeStart(commits, range) {
|
|
650
|
+
const first = commits.findIndex((commit) => commit.sha === range.from);
|
|
651
|
+
const last = commits.findIndex((commit) => commit.sha === range.to);
|
|
652
|
+
const start = commits[first];
|
|
653
|
+
if (start === void 0 || last < first) return "missing";
|
|
654
|
+
for (let index = first + 1; index <= last; index++) if (commits[index]?.parent !== commits[index - 1]?.sha) return "not-linear";
|
|
655
|
+
return start;
|
|
656
|
+
}
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region lib/types/wildmatch.js
|
|
659
|
+
/**
|
|
660
|
+
* Patterns of `.gitattributes` lines, matched as Git's wildmatch matches them: `*` and `?` stay within one path
|
|
661
|
+
* segment, `**` between slashes or at either end crosses segments, `[...]` sets take `!` or `^` for negation, ranges,
|
|
662
|
+
* and POSIX classes, `\` makes the next character literal, and every other character, including `(`, `{`, and `+`,
|
|
663
|
+
* is literal. Matching is case-sensitive, as in Git unless `core.ignoreCase` is set, and compares characters where Git
|
|
664
|
+
* compares UTF-8 bytes, so `?` and ranges differ from Git only for characters outside ASCII.
|
|
665
|
+
*/
|
|
666
|
+
/** ASCII members of each POSIX class wildmatch accepts, written as regular expression class ranges. */
|
|
667
|
+
const CLASSES = {
|
|
668
|
+
alnum: "a-zA-Z0-9",
|
|
669
|
+
alpha: "a-zA-Z",
|
|
670
|
+
blank: " \\t",
|
|
671
|
+
cntrl: "\\x00-\\x1f\\x7f",
|
|
672
|
+
digit: "0-9",
|
|
673
|
+
graph: "\\x21-\\x7e",
|
|
674
|
+
lower: "a-z",
|
|
675
|
+
print: "\\x20-\\x7e",
|
|
676
|
+
punct: "\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e",
|
|
677
|
+
space: "\\t-\\r ",
|
|
678
|
+
upper: "A-Z",
|
|
679
|
+
xdigit: "0-9a-fA-F"
|
|
680
|
+
};
|
|
681
|
+
/** Write one character literally in a regular expression, inside or outside a class. */
|
|
682
|
+
function literal(char) {
|
|
683
|
+
return /[\\^$.*+?()[\]{}|/-]/.test(char) ? `\\${char}` : char;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Translate a bracket expression that starts at `pattern[start]`, which is `[`.
|
|
687
|
+
* @returns the regular expression class and the index of the closing `]`, or undefined for an unterminated set or an
|
|
688
|
+
* unknown class, which wildmatch treats as matching nothing.
|
|
689
|
+
*/
|
|
690
|
+
function bracket(pattern, start) {
|
|
691
|
+
let index = start + 1;
|
|
692
|
+
const negated = pattern[index] === "!" || pattern[index] === "^";
|
|
693
|
+
if (negated) index += 1;
|
|
694
|
+
const members = [];
|
|
695
|
+
for (let first = true; first || pattern[index] !== "]"; first = false, index += 1) {
|
|
696
|
+
let char = pattern[index];
|
|
697
|
+
if (char === void 0) return void 0;
|
|
698
|
+
if (char === "[" && pattern[index + 1] === ":") {
|
|
699
|
+
const close = pattern.indexOf("]", index + 2);
|
|
700
|
+
if (close === -1) return void 0;
|
|
701
|
+
if (close > index + 2 && pattern[close - 1] === ":") {
|
|
702
|
+
const range = CLASSES[pattern.slice(index + 2, close - 1)];
|
|
703
|
+
if (range === void 0) return void 0;
|
|
704
|
+
members.push(range);
|
|
705
|
+
index = close;
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (char === "\\") {
|
|
710
|
+
index += 1;
|
|
711
|
+
char = pattern[index];
|
|
712
|
+
if (char === void 0) return void 0;
|
|
713
|
+
}
|
|
714
|
+
const to = pattern[index + 2];
|
|
715
|
+
if (pattern[index + 1] === "-" && to !== void 0 && to !== "]") {
|
|
716
|
+
index += 2;
|
|
717
|
+
let end = to;
|
|
718
|
+
if (end === "\\") {
|
|
719
|
+
index += 1;
|
|
720
|
+
end = pattern[index] ?? "";
|
|
721
|
+
if (end === "") return void 0;
|
|
722
|
+
}
|
|
723
|
+
members.push(char <= end ? `${literal(char)}-${literal(end)}` : literal(char));
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
members.push(literal(char));
|
|
727
|
+
}
|
|
728
|
+
const set = members.join("");
|
|
729
|
+
return {
|
|
730
|
+
source: negated ? `[^/${set}]` : `(?!/)[${set}]`,
|
|
731
|
+
end: index
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Compile one `.gitattributes` pattern, without the leading `/` that anchors it, into a test of a path.
|
|
736
|
+
* @param pattern - the pattern as written, which the caller has checked is not quoted, negated, or a directory.
|
|
737
|
+
* @returns a test of the text the pattern applies to, or undefined for a pattern that can match nothing.
|
|
738
|
+
*/
|
|
739
|
+
function wildmatch(pattern) {
|
|
740
|
+
let source = "";
|
|
741
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
742
|
+
const char = pattern.charAt(index);
|
|
743
|
+
if (char === "\\") {
|
|
744
|
+
const next = pattern[index + 1];
|
|
745
|
+
if (next === void 0) return void 0;
|
|
746
|
+
source += literal(next);
|
|
747
|
+
index += 1;
|
|
748
|
+
} else if (char === "?") source += "[^/]";
|
|
749
|
+
else if (char === "*") {
|
|
750
|
+
let last = index;
|
|
751
|
+
while (pattern[last + 1] === "*") last += 1;
|
|
752
|
+
const after = pattern[last + 1];
|
|
753
|
+
const crossing = last > index && (index === 0 || pattern[index - 1] === "/") && (after === void 0 || after === "/");
|
|
754
|
+
if (crossing && after === "/") {
|
|
755
|
+
source += "(?:.*/)?";
|
|
756
|
+
index = last + 1;
|
|
757
|
+
} else {
|
|
758
|
+
source += crossing ? ".*" : "[^/]*";
|
|
759
|
+
index = last;
|
|
760
|
+
}
|
|
761
|
+
} else if (char === "[") {
|
|
762
|
+
const set = bracket(pattern, index);
|
|
763
|
+
if (set === void 0) return void 0;
|
|
764
|
+
source += set.source;
|
|
765
|
+
index = set.end;
|
|
766
|
+
} else source += literal(char);
|
|
767
|
+
}
|
|
768
|
+
const expression = new RegExp(`^${source}$`, "s");
|
|
769
|
+
return (text) => expression.test(text);
|
|
770
|
+
}
|
|
771
|
+
//#endregion
|
|
772
|
+
//#region lib/types/layers.js
|
|
773
|
+
/**
|
|
774
|
+
* Review layers of changed files. A repository's root `.gitattributes` decides first: its `dsh-review-layer`
|
|
775
|
+
* attribute names a layer, and `linguist-generated` places a file in the `test` layer. The panel's `testPaths` and
|
|
776
|
+
* `interfacePaths` configuration comes next, then the built-in rules, which follow the default file and directory
|
|
777
|
+
* conventions of common languages and tools; every other file is in the `implementation` layer.
|
|
778
|
+
*/
|
|
779
|
+
/** Path of the attributes file read beside each diff, relative to the repository root. */
|
|
780
|
+
const ATTRIBUTES_PATH = ".gitattributes";
|
|
781
|
+
/** The attribute GitHub Linguist reads to treat a file as generated. */
|
|
782
|
+
const GENERATED = "linguist-generated";
|
|
783
|
+
const LAYERS = new Set([
|
|
784
|
+
"interface",
|
|
785
|
+
"implementation",
|
|
786
|
+
"test"
|
|
787
|
+
]);
|
|
788
|
+
/** Whether an attribute value names a layer. */
|
|
789
|
+
function isLayer(value) {
|
|
790
|
+
return LAYERS.has(value);
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Tests, test data, snapshots, locale dictionaries, and lockfiles by the default conventions of their tools: test
|
|
794
|
+
* directories, Jest and Vitest `*.spec.*` and `*.test.*` files, `go test` `*_test.go` files and `testdata/`
|
|
795
|
+
* directories, pytest's `test_*.py`, `*_test.py`, and `conftest.py`, RSpec's `spec/` and `*_spec.rb`, SwiftPM's
|
|
796
|
+
* `Tests/`, .NET `*.Tests/` projects, Jest and insta snapshots, i18next and Rails `locales/`, gettext catalogs,
|
|
797
|
+
* Apple `.lproj` strings, Android string resources, and the lockfiles of npm, pnpm, Yarn, Bun, Cargo, Go modules,
|
|
798
|
+
* Poetry, uv, Pipenv, Bundler, Composer, SwiftPM, NuGet, Gradle, pub, Mix, and Nix flakes.
|
|
799
|
+
*/
|
|
800
|
+
const BUILT_IN_TEST_PATHS = [
|
|
801
|
+
"**/test/**",
|
|
802
|
+
"**/tests/**",
|
|
803
|
+
"**/Tests/**",
|
|
804
|
+
"**/__tests__/**",
|
|
805
|
+
"**/spec/**",
|
|
806
|
+
"**/e2e/**",
|
|
807
|
+
"**/testdata/**",
|
|
808
|
+
"**/__mocks__/**",
|
|
809
|
+
"**/__fixtures__/**",
|
|
810
|
+
"**/*.Tests/**",
|
|
811
|
+
"**/*.spec.*",
|
|
812
|
+
"**/*.test.*",
|
|
813
|
+
"**/*.e2e.*",
|
|
814
|
+
"**/*_test.go",
|
|
815
|
+
"**/test_*.py",
|
|
816
|
+
"**/*_test.py",
|
|
817
|
+
"**/conftest.py",
|
|
818
|
+
"**/*_spec.rb",
|
|
819
|
+
"**/__snapshots__/**",
|
|
820
|
+
"**/*.snap",
|
|
821
|
+
"**/locales/**",
|
|
822
|
+
"**/*.po",
|
|
823
|
+
"**/*.pot",
|
|
824
|
+
"**/*.lproj/*.strings",
|
|
825
|
+
"**/res/values-*/strings.xml",
|
|
826
|
+
"**/package-lock.json",
|
|
827
|
+
"**/npm-shrinkwrap.json",
|
|
828
|
+
"**/pnpm-lock.yaml",
|
|
829
|
+
"**/yarn.lock",
|
|
830
|
+
"**/bun.lock",
|
|
831
|
+
"**/bun.lockb",
|
|
832
|
+
"**/Cargo.lock",
|
|
833
|
+
"**/go.sum",
|
|
834
|
+
"**/poetry.lock",
|
|
835
|
+
"**/uv.lock",
|
|
836
|
+
"**/Pipfile.lock",
|
|
837
|
+
"**/Gemfile.lock",
|
|
838
|
+
"**/composer.lock",
|
|
839
|
+
"**/Package.resolved",
|
|
840
|
+
"**/packages.lock.json",
|
|
841
|
+
"**/gradle.lockfile",
|
|
842
|
+
"**/pubspec.lock",
|
|
843
|
+
"**/mix.lock",
|
|
844
|
+
"**/flake.lock"
|
|
845
|
+
];
|
|
846
|
+
/**
|
|
847
|
+
* Package manifests of npm, Go modules, Cargo, Python packaging, Bundler and RubyGems, Maven, Gradle, MSBuild,
|
|
848
|
+
* SwiftPM, Composer, pub, and Mix; TypeScript declarations, Python stubs, and C and C++ headers; and interface
|
|
849
|
+
* definitions of Protocol Buffers, GraphQL, Thrift, and OpenAPI.
|
|
850
|
+
*/
|
|
851
|
+
const BUILT_IN_INTERFACE_PATHS = [
|
|
852
|
+
"**/package.json",
|
|
853
|
+
"**/go.mod",
|
|
854
|
+
"**/Cargo.toml",
|
|
855
|
+
"**/pyproject.toml",
|
|
856
|
+
"**/setup.py",
|
|
857
|
+
"**/setup.cfg",
|
|
858
|
+
"**/Gemfile",
|
|
859
|
+
"**/*.gemspec",
|
|
860
|
+
"**/pom.xml",
|
|
861
|
+
"**/build.gradle",
|
|
862
|
+
"**/build.gradle.kts",
|
|
863
|
+
"**/*.csproj",
|
|
864
|
+
"**/Package.swift",
|
|
865
|
+
"**/composer.json",
|
|
866
|
+
"**/pubspec.yaml",
|
|
867
|
+
"**/mix.exs",
|
|
868
|
+
"**/*.d.ts",
|
|
869
|
+
"**/*.d.mts",
|
|
870
|
+
"**/*.d.cts",
|
|
871
|
+
"**/*.pyi",
|
|
872
|
+
"**/*.h",
|
|
873
|
+
"**/*.hpp",
|
|
874
|
+
"**/*.proto",
|
|
875
|
+
"**/*.graphql",
|
|
876
|
+
"**/*.graphqls",
|
|
877
|
+
"**/*.thrift",
|
|
878
|
+
"**/openapi.{json,yaml,yml}",
|
|
879
|
+
"**/swagger.{json,yaml,yml}"
|
|
880
|
+
];
|
|
881
|
+
/**
|
|
882
|
+
* Compile globs into one matcher; `*` matches dot files and never crosses `/`.
|
|
883
|
+
* @param globs - picomatch globs.
|
|
884
|
+
* @returns whether a repository-relative path matches any glob.
|
|
885
|
+
*/
|
|
886
|
+
function matcherOf(globs) {
|
|
887
|
+
return globs.length === 0 ? () => false : picomatch([...globs], { dot: true });
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Read the review attributes a `.gitattributes` text gives each path. Lines apply in order, so a later line overrides
|
|
891
|
+
* an earlier one. `dsh-review-layer=<layer>` names `test`, `interface`, or `implementation`; another value,
|
|
892
|
+
* `-dsh-review-layer`, and `!dsh-review-layer` leave the layer unspecified. `linguist-generated` and `=true` set
|
|
893
|
+
* the generated attribute, `-linguist-generated` and `=false` unset it, and `!linguist-generated` returns it to
|
|
894
|
+
* unspecified. Patterns follow Git's wildmatch rules, as {@link wildmatch} describes: a pattern without `/` matches a
|
|
895
|
+
* file name at any depth, and one with `/` matches the path from the repository root. Macro definitions, quoted
|
|
896
|
+
* patterns, negated patterns, which Git ignores in attributes, and patterns ending in `/`, which name directories and
|
|
897
|
+
* so never match a file, are skipped.
|
|
898
|
+
* @param attributes - the text of the root `.gitattributes`, empty without one.
|
|
899
|
+
* @returns the attributes of a repository-relative path.
|
|
900
|
+
*/
|
|
901
|
+
function attributesOf(attributes) {
|
|
902
|
+
const rules = [];
|
|
903
|
+
for (const raw of attributes.split(/\r?\n/)) {
|
|
904
|
+
const [pattern, ...fields] = raw.trim().split(/\s+/);
|
|
905
|
+
if (pattern === void 0 || pattern === "" || pattern.startsWith("#") || pattern.startsWith("[attr]") || pattern.startsWith("\"") || pattern.startsWith("!") || pattern.endsWith("/")) continue;
|
|
906
|
+
let layer;
|
|
907
|
+
let generated;
|
|
908
|
+
for (const field of fields) if (field === GENERATED || field === `${GENERATED}=true`) generated = true;
|
|
909
|
+
else if (field === `-${GENERATED}` || field === `${GENERATED}=false`) generated = false;
|
|
910
|
+
else if (field === `!${GENERATED}`) generated = null;
|
|
911
|
+
else if (field.startsWith(`dsh-review-layer=`)) {
|
|
912
|
+
const value = field.slice(17);
|
|
913
|
+
layer = isLayer(value) ? value : null;
|
|
914
|
+
} else if (field === `-dsh-review-layer` || field === `!dsh-review-layer`) layer = null;
|
|
915
|
+
const test = wildmatch(pattern.replace(/^\//, ""));
|
|
916
|
+
if (test === void 0 || layer === void 0 && generated === void 0) continue;
|
|
917
|
+
const match = pattern.includes("/") ? test : (path) => test(path.slice(path.lastIndexOf("/") + 1));
|
|
918
|
+
rules.push({
|
|
919
|
+
match,
|
|
920
|
+
layer,
|
|
921
|
+
generated
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
return (path) => {
|
|
925
|
+
let layer;
|
|
926
|
+
let generated;
|
|
927
|
+
for (const rule of rules) {
|
|
928
|
+
if (!rule.match(path)) continue;
|
|
929
|
+
if (rule.layer !== void 0) layer = rule.layer;
|
|
930
|
+
if (rule.generated !== void 0) generated = rule.generated;
|
|
931
|
+
}
|
|
932
|
+
return {
|
|
933
|
+
layer: layer ?? void 0,
|
|
934
|
+
generated: generated === true
|
|
935
|
+
};
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
/** Classifies changed files into review layers by a repository's attributes, the panel's globs, and the built-in rules. */
|
|
939
|
+
var FileLayers = class {
|
|
940
|
+
rules;
|
|
941
|
+
/**
|
|
942
|
+
* @param testPaths - configured globs of the `test` layer, checked before the built-in rules.
|
|
943
|
+
* @param interfacePaths - configured globs of the `interface` layer, checked after `testPaths` and before the built-in rules.
|
|
944
|
+
*/
|
|
945
|
+
constructor(testPaths, interfacePaths) {
|
|
946
|
+
this.rules = [
|
|
947
|
+
{
|
|
948
|
+
layer: "test",
|
|
949
|
+
match: matcherOf(testPaths)
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
layer: "interface",
|
|
953
|
+
match: matcherOf(interfacePaths)
|
|
954
|
+
},
|
|
955
|
+
{
|
|
956
|
+
layer: "test",
|
|
957
|
+
match: matcherOf(BUILT_IN_TEST_PATHS)
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
layer: "interface",
|
|
961
|
+
match: matcherOf(BUILT_IN_INTERFACE_PATHS)
|
|
962
|
+
}
|
|
963
|
+
];
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Place each file in its layer: the layer its attributes name, else `test` for a generated file, else the first
|
|
967
|
+
* configured or built-in rule its path matches, else `implementation`.
|
|
968
|
+
* @param files - parsed files.
|
|
969
|
+
* @param attributes - the text of the repository's root `.gitattributes`, empty without one.
|
|
970
|
+
* @returns the files in the same order with their layers.
|
|
971
|
+
*/
|
|
972
|
+
classify(files, attributes) {
|
|
973
|
+
const attributesAt = attributesOf(attributes);
|
|
974
|
+
return files.map((file) => {
|
|
975
|
+
const { layer, generated } = attributesAt(file.path);
|
|
976
|
+
const ruled = layer ?? (generated ? "test" : this.rules.find((rule) => rule.match(file.path))?.layer) ?? "implementation";
|
|
977
|
+
return {
|
|
978
|
+
...file,
|
|
979
|
+
layer: ruled
|
|
980
|
+
};
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
//#endregion
|
|
557
985
|
//#region lib/types/local-diff.js
|
|
558
986
|
/**
|
|
559
987
|
* Local changes of a Session's checkout: where the `branch` scope forks, the
|
|
@@ -574,6 +1002,22 @@ var FilterConfigError = class extends Error {
|
|
|
574
1002
|
var NoForkPoint = class extends Error {
|
|
575
1003
|
name = "NoForkPoint";
|
|
576
1004
|
};
|
|
1005
|
+
/** Thrown when the base branch chosen for the `branch` scope does not exist. */
|
|
1006
|
+
var BaseMissing = class extends Error {
|
|
1007
|
+
name = "BaseMissing";
|
|
1008
|
+
};
|
|
1009
|
+
/** Thrown when chosen commits are not among the commits of the `branch` scope, or are out of order. */
|
|
1010
|
+
var CommitsMissing = class extends Error {
|
|
1011
|
+
name = "CommitsMissing";
|
|
1012
|
+
};
|
|
1013
|
+
/** Thrown when chosen commits of the `branch` scope are not a run in which each commit's first parent is the one before it. */
|
|
1014
|
+
var CommitsNotLinear = class extends Error {
|
|
1015
|
+
name = "CommitsNotLinear";
|
|
1016
|
+
};
|
|
1017
|
+
/** A full SHA-1 or SHA-256 object name, the only form of a chosen commit Git receives. */
|
|
1018
|
+
const COMMIT = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
1019
|
+
/** One commit per record: object name, first parent, author, author date, and subject, separated by NUL. */
|
|
1020
|
+
const LOG_FORMAT = "--format=%H%x00%P%x00%an%x00%aI%x00%s%x1e";
|
|
577
1021
|
/** No executable diff helpers or submodule working-tree inspection; preserve recorded submodule commit changes. */
|
|
578
1022
|
const DIFF = [
|
|
579
1023
|
"-c",
|
|
@@ -615,7 +1059,7 @@ async function diffFilterOverrides(git) {
|
|
|
615
1059
|
/** Characters Git inspects for a NUL character before it calls content binary. */
|
|
616
1060
|
const BINARY_PROBE = 8e3;
|
|
617
1061
|
/**
|
|
618
|
-
* Find where the `branch` scope forks: the base commit of the worktree the
|
|
1062
|
+
* Find where the `branch` scope forks while no base branch is chosen: the base commit of the worktree the
|
|
619
1063
|
* Session created while the checkout is that worktree, else the merge base of
|
|
620
1064
|
* HEAD with the default branch of the first remote that names one, in the
|
|
621
1065
|
* order the panel recognizes code hosts.
|
|
@@ -627,7 +1071,8 @@ const BINARY_PROBE = 8e3;
|
|
|
627
1071
|
async function forkPoint(git, inspection, created) {
|
|
628
1072
|
if (created !== null && created.path === inspection.checkout.root) return {
|
|
629
1073
|
commit: created.baseCommit,
|
|
630
|
-
label: created.from ?? created.baseCommit.slice(0, 7)
|
|
1074
|
+
label: created.from ?? created.baseCommit.slice(0, 7),
|
|
1075
|
+
worktree: true
|
|
631
1076
|
};
|
|
632
1077
|
for (const remote of remoteOrder(inspection.upstream, inspection.remotes)) {
|
|
633
1078
|
const head = await git("remote-head", [
|
|
@@ -654,26 +1099,90 @@ async function forkPoint(git, inspection, created) {
|
|
|
654
1099
|
const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null;
|
|
655
1100
|
return commit === null ? null : {
|
|
656
1101
|
commit,
|
|
657
|
-
label: base
|
|
1102
|
+
label: base,
|
|
1103
|
+
worktree: false
|
|
658
1104
|
};
|
|
659
1105
|
}
|
|
660
1106
|
return null;
|
|
661
1107
|
}
|
|
662
1108
|
/**
|
|
1109
|
+
* Find where the `branch` scope forks from a chosen base branch: the merge base of HEAD with it.
|
|
1110
|
+
* @param git - runner bound to the checkout.
|
|
1111
|
+
* @param ref - full ref name under `refs/heads/` or `refs/remotes/`.
|
|
1112
|
+
* @returns the fork point, or null when HEAD shares no history with the branch or has no commit.
|
|
1113
|
+
* @throws BaseMissing when the ref does not exist; an Error for another ref name or when Git fails.
|
|
1114
|
+
*/
|
|
1115
|
+
async function chosenForkPoint(git, ref) {
|
|
1116
|
+
const prefix = BASE_REF_PREFIXES.find((candidate) => ref.startsWith(candidate) && ref.length > candidate.length);
|
|
1117
|
+
if (prefix === void 0) throw new Error(`forge-panel: ${JSON.stringify(ref)} is not a branch ref`);
|
|
1118
|
+
const name = ref.slice(prefix.length);
|
|
1119
|
+
if ((await git("show-ref", [
|
|
1120
|
+
"show-ref",
|
|
1121
|
+
"--verify",
|
|
1122
|
+
"--quiet",
|
|
1123
|
+
ref
|
|
1124
|
+
], [0, 1])).exitCode !== 0) throw new BaseMissing(`The base branch ${name} does not exist`);
|
|
1125
|
+
const merge = await git("merge-base", [
|
|
1126
|
+
"merge-base",
|
|
1127
|
+
"HEAD",
|
|
1128
|
+
ref
|
|
1129
|
+
], [
|
|
1130
|
+
0,
|
|
1131
|
+
1,
|
|
1132
|
+
128
|
|
1133
|
+
]);
|
|
1134
|
+
const commit = merge.exitCode === 0 ? parseName(merge.stdout) : null;
|
|
1135
|
+
return commit === null ? null : {
|
|
1136
|
+
commit,
|
|
1137
|
+
label: name,
|
|
1138
|
+
worktree: false
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* List the branches the `branch` scope can compare with.
|
|
1143
|
+
* @param git - runner bound to the checkout.
|
|
1144
|
+
* @param inspection - the checkout and its remotes.
|
|
1145
|
+
* @param created - worktree the Session created, or null.
|
|
1146
|
+
* @param query - text the branch names must contain, ignoring case; empty for every branch.
|
|
1147
|
+
* @param limit - most branches in each group.
|
|
1148
|
+
* @returns the automatic fork point, then remote-tracking and local branches, most recently committed first.
|
|
1149
|
+
* @throws an Error when Git fails or prints more than the runner's output limit.
|
|
1150
|
+
*/
|
|
1151
|
+
async function baseBranches(git, inspection, created, query, limit) {
|
|
1152
|
+
const fork = await forkPoint(git, inspection, created);
|
|
1153
|
+
const refs = await git("base-branches", [
|
|
1154
|
+
"for-each-ref",
|
|
1155
|
+
"--sort=-committerdate",
|
|
1156
|
+
"--format=%(refname)%00%(symref)",
|
|
1157
|
+
...BASE_REF_PREFIXES
|
|
1158
|
+
]);
|
|
1159
|
+
return {
|
|
1160
|
+
automatic: fork === null ? null : {
|
|
1161
|
+
name: fork.label,
|
|
1162
|
+
worktree: fork.worktree
|
|
1163
|
+
},
|
|
1164
|
+
...parseBaseBranches(refs.stdout, inspection.checkout.branch, query, limit)
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
663
1168
|
* Read changes at `root` with command-local clean/process filter overrides and without
|
|
664
1169
|
* submodule working-tree inspection. Git's built-in newline, ident, and encoding conversions still apply.
|
|
1170
|
+
* Each file's layer follows `layers` and the root `.gitattributes` of the new side: the index for `staged`,
|
|
1171
|
+
* else the working tree.
|
|
665
1172
|
* @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
|
|
666
1173
|
* @param config - Git and size limits.
|
|
667
1174
|
* @param session - Session whose sandbox policy and execution world apply.
|
|
668
1175
|
* @param root - top-level directory of the checkout.
|
|
669
1176
|
* @param fork - fork point of the `branch` scope, or null without one.
|
|
670
1177
|
* @param scope - which changes to read.
|
|
1178
|
+
* @param layers - classifier of each file's review layer.
|
|
671
1179
|
* @param signal - cancellation of every command and read.
|
|
672
1180
|
* @returns tracked files in Git's order, then untracked files unless the scope is `staged`.
|
|
673
1181
|
* @throws NoForkPoint for the `branch` scope without `fork`; FilterConfigError when filter configuration
|
|
674
|
-
* cannot be read within `maxDiffBytes`; DiffTooLarge for oversized comparison output
|
|
1182
|
+
* cannot be read within `maxDiffBytes`; DiffTooLarge for oversized comparison output or `.gitattributes`;
|
|
1183
|
+
* an Error when Git or the `.gitattributes` read fails.
|
|
675
1184
|
*/
|
|
676
|
-
async function localDiff(ctx, config, session, root, fork, scope, signal) {
|
|
1185
|
+
async function localDiff(ctx, config, session, root, fork, scope, layers, signal) {
|
|
677
1186
|
const git = gitIn(ctx, {
|
|
678
1187
|
...config,
|
|
679
1188
|
maxOutputBytes: config.maxDiffBytes
|
|
@@ -682,6 +1191,7 @@ async function localDiff(ctx, config, session, root, fork, scope, signal) {
|
|
|
682
1191
|
switch (scope.kind) {
|
|
683
1192
|
case "branch":
|
|
684
1193
|
if (fork === null) throw new NoForkPoint("The checkout has no fork point to compare its branch with");
|
|
1194
|
+
if (scope.commits !== null) return await commitsDiff(git, fork, scope.commits, layers);
|
|
685
1195
|
range = [fork.commit];
|
|
686
1196
|
break;
|
|
687
1197
|
case "uncommitted":
|
|
@@ -702,21 +1212,31 @@ async function localDiff(ctx, config, session, root, fork, scope, signal) {
|
|
|
702
1212
|
...range,
|
|
703
1213
|
"--"
|
|
704
1214
|
], void 0, overrides))).stdout);
|
|
705
|
-
if (scope.kind === "staged")
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1215
|
+
if (scope.kind === "staged") {
|
|
1216
|
+
const shown = await bounded(git("attributes", ["show", `:${ATTRIBUTES_PATH}`], [0, 128]));
|
|
1217
|
+
return {
|
|
1218
|
+
base: null,
|
|
1219
|
+
files: layers.classify(tracked, shown.exitCode === 0 ? shown.stdout : ""),
|
|
1220
|
+
omitted: 0
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
710
1223
|
const untracked = await untrackedFiles(ctx, config, git, root, signal);
|
|
1224
|
+
let attributes = "";
|
|
1225
|
+
try {
|
|
1226
|
+
attributes = decodeText(await readFile(ctx, config, root, ".gitattributes", signal)) ?? "";
|
|
1227
|
+
} catch (error) {
|
|
1228
|
+
if (!(error instanceof FsError && error.code === "FS_NOT_FOUND")) throw error;
|
|
1229
|
+
}
|
|
711
1230
|
return {
|
|
712
1231
|
base: fork === null || scope.kind !== "branch" ? null : fork.label,
|
|
713
|
-
files: [...tracked, ...untracked.files],
|
|
1232
|
+
files: layers.classify([...tracked, ...untracked.files], attributes),
|
|
714
1233
|
omitted: untracked.omitted
|
|
715
1234
|
};
|
|
716
1235
|
}
|
|
717
1236
|
/**
|
|
718
1237
|
* Read the new side of one file in a scope, which supplies the unchanged
|
|
719
|
-
* lines between hunks: the index for `staged`,
|
|
1238
|
+
* lines between hunks: the index for `staged`, the last chosen commit for
|
|
1239
|
+
* chosen commits of the `branch` scope, else the working tree.
|
|
720
1240
|
* @param ctx - context that provides `fs`, `subprocess`, `sandbox`, and `sandboxPolicy`.
|
|
721
1241
|
* @param config - Git and size limits.
|
|
722
1242
|
* @param session - Session whose sandbox policy and execution world apply.
|
|
@@ -730,11 +1250,13 @@ async function localDiff(ctx, config, session, root, fork, scope, signal) {
|
|
|
730
1250
|
async function localText(ctx, config, session, root, scope, path, signal) {
|
|
731
1251
|
if (!insideCheckout(path)) throw new Error(`forge-panel: ${JSON.stringify(path)} is not a path inside the checkout`);
|
|
732
1252
|
let text;
|
|
733
|
-
|
|
1253
|
+
const commit = scope.kind === "staged" ? "" : scope.kind === "branch" && scope.commits !== null ? scope.commits.to : void 0;
|
|
1254
|
+
if (commit !== void 0) {
|
|
1255
|
+
if (commit !== "" && !COMMIT.test(commit)) throw new CommitsMissing("The chosen commit is not a full object name");
|
|
734
1256
|
const shown = (await bounded(gitIn(ctx, {
|
|
735
1257
|
...config,
|
|
736
1258
|
maxOutputBytes: config.maxDiffBytes
|
|
737
|
-
}, session, root, signal)("show", ["show",
|
|
1259
|
+
}, session, root, signal)("show", ["show", `${commit}:${path}`]))).stdout;
|
|
738
1260
|
text = shown.slice(0, BINARY_PROBE).includes("\0") ? void 0 : shown;
|
|
739
1261
|
} else text = decodeText(await readFile(ctx, config, root, path, signal));
|
|
740
1262
|
if (text === void 0) throw new Error(`forge-panel: ${path} is binary`);
|
|
@@ -814,14 +1336,86 @@ async function aheadOf(git, branch, commit) {
|
|
|
814
1336
|
`${commit}..HEAD`
|
|
815
1337
|
])).stdout.trim());
|
|
816
1338
|
}
|
|
1339
|
+
/**
|
|
1340
|
+
* List the commits of the `branch` scope: those reachable from HEAD but not from the fork point, parents before children.
|
|
1341
|
+
* @param git - runner bound to the checkout, whose output limit bounds the listing.
|
|
1342
|
+
* @param fork - fork point of the `branch` scope.
|
|
1343
|
+
* @param limit - most commits listed.
|
|
1344
|
+
* @returns the newest `limit` commits, ending with HEAD's commit, and HEAD's commit.
|
|
1345
|
+
* @throws an Error when Git fails or prints more than the runner's output limit.
|
|
1346
|
+
*/
|
|
1347
|
+
async function localCommits(git, fork, limit) {
|
|
1348
|
+
const head = (await git("head", [
|
|
1349
|
+
"rev-parse",
|
|
1350
|
+
"--verify",
|
|
1351
|
+
"HEAD"
|
|
1352
|
+
])).stdout.trim();
|
|
1353
|
+
const listed = await branchCommits(git, fork, limit + 1);
|
|
1354
|
+
return {
|
|
1355
|
+
headSha: head,
|
|
1356
|
+
commits: listed.slice(-limit),
|
|
1357
|
+
truncated: listed.length > limit
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Commits between the fork point and HEAD, parents before children.
|
|
1362
|
+
* @param limit - when given, only the newest `limit` commits in topological order.
|
|
1363
|
+
*/
|
|
1364
|
+
async function branchCommits(git, fork, limit) {
|
|
1365
|
+
return (await git("log", [
|
|
1366
|
+
"log",
|
|
1367
|
+
"--no-show-signature",
|
|
1368
|
+
"--topo-order",
|
|
1369
|
+
"--reverse",
|
|
1370
|
+
...limit === void 0 ? [] : [`--max-count=${String(limit)}`],
|
|
1371
|
+
LOG_FORMAT,
|
|
1372
|
+
`${fork.commit}..HEAD`,
|
|
1373
|
+
"--"
|
|
1374
|
+
])).stdout.split("").flatMap((record) => {
|
|
1375
|
+
const fields = record.replace(/^\n/, "").split("\0");
|
|
1376
|
+
if (fields.length !== 5) return [];
|
|
1377
|
+
const [sha, parents, author, authoredAt, title] = fields;
|
|
1378
|
+
return [{
|
|
1379
|
+
sha,
|
|
1380
|
+
parent: /^\S+/.exec(parents)?.[0] ?? null,
|
|
1381
|
+
title,
|
|
1382
|
+
author,
|
|
1383
|
+
authoredAt
|
|
1384
|
+
}];
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
/** The committed changes of consecutive commits of the `branch` scope, from the first commit's first parent to the last. */
|
|
1388
|
+
async function commitsDiff(git, fork, chosen, layers) {
|
|
1389
|
+
if (!COMMIT.test(chosen.from) || !COMMIT.test(chosen.to)) throw new CommitsMissing("The chosen commits are not full object names");
|
|
1390
|
+
const start = rangeStart(await branchCommits(git, fork), chosen);
|
|
1391
|
+
if (start === "missing") throw new CommitsMissing("The chosen commits are no longer on the branch");
|
|
1392
|
+
if (start === "not-linear") throw new CommitsNotLinear("The chosen commits are not one run of first parents");
|
|
1393
|
+
const parent = start.parent ?? await emptyTree(git);
|
|
1394
|
+
const overrides = await diffFilterOverrides(git);
|
|
1395
|
+
const files = parseDiff((await bounded(git("diff", [
|
|
1396
|
+
...DIFF,
|
|
1397
|
+
parent,
|
|
1398
|
+
chosen.to,
|
|
1399
|
+
"--"
|
|
1400
|
+
], void 0, overrides))).stdout);
|
|
1401
|
+
const shown = await bounded(git("attributes", ["show", `${chosen.to}:${ATTRIBUTES_PATH}`], [0, 128]));
|
|
1402
|
+
return {
|
|
1403
|
+
base: fork.label,
|
|
1404
|
+
files: layers.classify(files, shown.exitCode === 0 ? shown.stdout : ""),
|
|
1405
|
+
omitted: 0
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
817
1408
|
/** HEAD, or the empty tree while the checked-out branch has no commit. */
|
|
818
1409
|
async function headOrEmptyTree(git) {
|
|
819
|
-
|
|
1410
|
+
return (await git("head", [
|
|
820
1411
|
"rev-parse",
|
|
821
1412
|
"--verify",
|
|
822
1413
|
"--quiet",
|
|
823
1414
|
"HEAD"
|
|
824
|
-
], [0, 1])).exitCode === 0
|
|
1415
|
+
], [0, 1])).exitCode === 0 ? "HEAD" : await emptyTree(git);
|
|
1416
|
+
}
|
|
1417
|
+
/** The object name of the empty tree. */
|
|
1418
|
+
async function emptyTree(git) {
|
|
825
1419
|
return (await git("empty-tree", [
|
|
826
1420
|
"hash-object",
|
|
827
1421
|
"-t",
|
|
@@ -844,10 +1438,7 @@ async function untrackedFiles(ctx, config, git, root, signal) {
|
|
|
844
1438
|
content = await readFile(ctx, config, root, path, signal);
|
|
845
1439
|
} catch (error) {
|
|
846
1440
|
if (error instanceof DiffTooLarge) {
|
|
847
|
-
files.push(
|
|
848
|
-
...untrackedFile(path, new Uint8Array()),
|
|
849
|
-
oversized: true
|
|
850
|
-
});
|
|
1441
|
+
files.push(oversizedUntrackedFile(path));
|
|
851
1442
|
continue;
|
|
852
1443
|
}
|
|
853
1444
|
if (error instanceof FsError) continue;
|
|
@@ -921,16 +1512,18 @@ const recordSchema = z$1.discriminatedUnion("action", [
|
|
|
921
1512
|
]);
|
|
922
1513
|
/**
|
|
923
1514
|
* The `forgeWorktree` unit. `request` and `cancel` records change the request
|
|
924
|
-
* until the first `turn/start` or creation; the first
|
|
925
|
-
*
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
*
|
|
1515
|
+
* until the first `turn/start` or creation; the first creation of an open
|
|
1516
|
+
* request applies until the first `step/start`, read from the worktree
|
|
1517
|
+
* service's `plugin:worktree/created` record, or from the `created` record that
|
|
1518
|
+
* earlier panels wrote. Records outside those periods leave the state
|
|
1519
|
+
* unchanged. The unit also follows the Session's working directory, so
|
|
1520
|
+
* clients, including the Session summary, see the created worktree only while
|
|
1521
|
+
* that directory is the worktree or lies below it. Restoration records retain
|
|
1522
|
+
* incomplete checkout recovery across reloads.
|
|
930
1523
|
*/
|
|
931
1524
|
const forgeWorktreeProjection = {
|
|
932
1525
|
key: "forgeWorktree",
|
|
933
|
-
stateVersion:
|
|
1526
|
+
stateVersion: 5,
|
|
934
1527
|
stateSchema: z$1.object({
|
|
935
1528
|
request: z$1.object({ from: z$1.string().min(1).nullable() }).strict().nullable(),
|
|
936
1529
|
created: worktreeSchema.nullable(),
|
|
@@ -986,6 +1579,16 @@ function apply(state, event) {
|
|
|
986
1579
|
}
|
|
987
1580
|
function applyRecord(state, event) {
|
|
988
1581
|
const record = pluginRecordOf(event);
|
|
1582
|
+
if (record?.type === CREATED_RECORD) {
|
|
1583
|
+
const created = createdWorktreeSchema.safeParse(record.data);
|
|
1584
|
+
return !created.success || state.created !== null || state.stepped || state.request === null ? state : {
|
|
1585
|
+
...state,
|
|
1586
|
+
created: {
|
|
1587
|
+
...created.data,
|
|
1588
|
+
from: state.request.from
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
989
1592
|
if (record?.type !== "plugin:client-ui-forge/worktree") return state;
|
|
990
1593
|
const parsed = recordSchema.safeParse(record.data);
|
|
991
1594
|
if (!parsed.success) return state;
|
|
@@ -1299,16 +1902,6 @@ var WorktreeCreations = class {
|
|
|
1299
1902
|
throw new CreationFailure(status.branch, status.phase, messageOf(error), error);
|
|
1300
1903
|
}
|
|
1301
1904
|
signal.throwIfAborted();
|
|
1302
|
-
appendPluginRecord(session, WORKTREE_RECORD, {
|
|
1303
|
-
action: "created",
|
|
1304
|
-
worktree: {
|
|
1305
|
-
path: created.path,
|
|
1306
|
-
branch: created.branch,
|
|
1307
|
-
from,
|
|
1308
|
-
baseCommit: created.baseCommit,
|
|
1309
|
-
repositoryRoot: created.repositoryRoot
|
|
1310
|
-
}
|
|
1311
|
-
});
|
|
1312
1905
|
return created;
|
|
1313
1906
|
} finally {
|
|
1314
1907
|
this.live.delete(session);
|
|
@@ -1698,6 +2291,7 @@ var SessionPanel = class {
|
|
|
1698
2291
|
};
|
|
1699
2292
|
}
|
|
1700
2293
|
publish(next) {
|
|
2294
|
+
if (isDeepStrictEqual(next, this.current)) return;
|
|
1701
2295
|
this.current = next;
|
|
1702
2296
|
for (const notify of [...this.followers]) notify();
|
|
1703
2297
|
}
|
|
@@ -1913,12 +2507,12 @@ function hostOf(repository) {
|
|
|
1913
2507
|
//#endregion
|
|
1914
2508
|
//#region lib/types/patch-cache.js
|
|
1915
2509
|
/**
|
|
1916
|
-
* Change request patches kept in memory, so the changes view reads
|
|
1917
|
-
* from the code host again while a change request keeps its head commit and base branch.
|
|
2510
|
+
* Change request patches kept in memory with the repository attributes read beside them, so the changes view reads
|
|
2511
|
+
* neither from the code host again while a change request keeps its head commit and base branch.
|
|
1918
2512
|
*/
|
|
1919
2513
|
/**
|
|
1920
2514
|
* One patch per change request, bounded by the total UTF-8 size of the kept
|
|
1921
|
-
* patches; the least recently read patch leaves first.
|
|
2515
|
+
* patches and their attributes; the least recently read patch leaves first.
|
|
1922
2516
|
*/
|
|
1923
2517
|
var PatchCache = class {
|
|
1924
2518
|
maxBytes;
|
|
@@ -1932,29 +2526,29 @@ var PatchCache = class {
|
|
|
1932
2526
|
* Read the patch kept for a change request at a version, marking it the most recently read.
|
|
1933
2527
|
* @param key - the change request.
|
|
1934
2528
|
* @param version - head commit and base branch the reader needs.
|
|
1935
|
-
* @returns the patch, or undefined when none is kept at that version.
|
|
2529
|
+
* @returns the patch and its attributes, or undefined when none is kept at that version.
|
|
1936
2530
|
*/
|
|
1937
2531
|
get(key, version) {
|
|
1938
2532
|
const entry = this.entries.get(key);
|
|
1939
2533
|
if (entry?.version !== version) return void 0;
|
|
1940
2534
|
this.entries.delete(key);
|
|
1941
2535
|
this.entries.set(key, entry);
|
|
1942
|
-
return entry.
|
|
2536
|
+
return entry.value;
|
|
1943
2537
|
}
|
|
1944
2538
|
/**
|
|
1945
2539
|
* Keep a patch in place of the change request's earlier one, then drop the
|
|
1946
2540
|
* least recently read patches until the rest fit within `maxBytes`.
|
|
1947
2541
|
* @param key - the change request.
|
|
1948
2542
|
* @param version - head commit and base branch the patch was read at.
|
|
1949
|
-
* @param
|
|
2543
|
+
* @param value - the patch and its attributes.
|
|
1950
2544
|
*/
|
|
1951
|
-
set(key, version,
|
|
2545
|
+
set(key, version, value) {
|
|
1952
2546
|
this.remove(key);
|
|
1953
|
-
const bytes = Buffer.byteLength(patch);
|
|
2547
|
+
const bytes = Buffer.byteLength(value.patch) + Buffer.byteLength(value.attributes);
|
|
1954
2548
|
if (bytes > this.maxBytes) return;
|
|
1955
2549
|
this.entries.set(key, {
|
|
1956
2550
|
version,
|
|
1957
|
-
|
|
2551
|
+
value,
|
|
1958
2552
|
bytes
|
|
1959
2553
|
});
|
|
1960
2554
|
this.bytes += bytes;
|
|
@@ -1970,6 +2564,96 @@ var PatchCache = class {
|
|
|
1970
2564
|
this.bytes -= entry.bytes;
|
|
1971
2565
|
}
|
|
1972
2566
|
};
|
|
2567
|
+
//#endregion
|
|
2568
|
+
//#region lib/types/review-cache.js
|
|
2569
|
+
/**
|
|
2570
|
+
* Review threads of change requests kept in memory, so the changes view reads them from the code host again only
|
|
2571
|
+
* after the change request's head or update time changes, the kept threads reach their age limit, or a review write drops them.
|
|
2572
|
+
*/
|
|
2573
|
+
/**
|
|
2574
|
+
* One read of review threads per change request, bounded by age and by the total UTF-8 size of the kept reads as
|
|
2575
|
+
* JSON; the least recently read change request leaves first. A read that started before a drop of any change request
|
|
2576
|
+
* is not kept, so threads read before a write never replace the drop.
|
|
2577
|
+
*/
|
|
2578
|
+
var ReviewCache = class {
|
|
2579
|
+
maxBytes;
|
|
2580
|
+
maxAgeMs;
|
|
2581
|
+
entries = /* @__PURE__ */ new Map();
|
|
2582
|
+
bytes = 0;
|
|
2583
|
+
/** Number of drops so far. */
|
|
2584
|
+
drops = 0;
|
|
2585
|
+
/**
|
|
2586
|
+
* @param maxBytes - most UTF-8 bytes kept together; a larger read is not kept.
|
|
2587
|
+
* @param maxAgeMs - age in milliseconds at which a kept read is no longer returned.
|
|
2588
|
+
*/
|
|
2589
|
+
constructor(maxBytes, maxAgeMs) {
|
|
2590
|
+
this.maxBytes = maxBytes;
|
|
2591
|
+
this.maxAgeMs = maxAgeMs;
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Read the threads kept for a change request at a version while they are younger than the age limit, marking them
|
|
2595
|
+
* the most recently read.
|
|
2596
|
+
* @param key - the change request.
|
|
2597
|
+
* @param version - head commit and update time the reader needs.
|
|
2598
|
+
* @param now - current epoch milliseconds.
|
|
2599
|
+
* @returns the threads, or undefined when none are kept at that version or they reached the age limit.
|
|
2600
|
+
*/
|
|
2601
|
+
get(key, version, now) {
|
|
2602
|
+
const entry = this.entries.get(key);
|
|
2603
|
+
if (entry?.version !== version || now - entry.readAt >= this.maxAgeMs) return void 0;
|
|
2604
|
+
this.entries.delete(key);
|
|
2605
|
+
this.entries.set(key, entry);
|
|
2606
|
+
return entry.review;
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Name the cache's state when a read starts, for {@link ReviewCache.set}.
|
|
2610
|
+
* @returns the token of the read.
|
|
2611
|
+
*/
|
|
2612
|
+
token() {
|
|
2613
|
+
return this.drops;
|
|
2614
|
+
}
|
|
2615
|
+
/**
|
|
2616
|
+
* Keep a read in place of the change request's earlier one, then drop the least recently read change requests
|
|
2617
|
+
* until the rest fit within `maxBytes`. A read whose token a drop outdated is not kept.
|
|
2618
|
+
* @param key - the change request.
|
|
2619
|
+
* @param version - head commit and update time the threads were read at.
|
|
2620
|
+
* @param review - the threads.
|
|
2621
|
+
* @param readAt - epoch milliseconds when the read started.
|
|
2622
|
+
* @param token - what {@link ReviewCache.token} returned when the read started.
|
|
2623
|
+
*/
|
|
2624
|
+
set(key, version, review, readAt, token) {
|
|
2625
|
+
if (token !== this.drops) return;
|
|
2626
|
+
this.forget(key);
|
|
2627
|
+
const bytes = Buffer.byteLength(JSON.stringify(review));
|
|
2628
|
+
if (bytes > this.maxBytes) return;
|
|
2629
|
+
this.entries.set(key, {
|
|
2630
|
+
version,
|
|
2631
|
+
review,
|
|
2632
|
+
readAt,
|
|
2633
|
+
bytes
|
|
2634
|
+
});
|
|
2635
|
+
this.bytes += bytes;
|
|
2636
|
+
for (const [oldest, entry] of this.entries) {
|
|
2637
|
+
if (this.bytes <= this.maxBytes) break;
|
|
2638
|
+
this.entries.delete(oldest);
|
|
2639
|
+
this.bytes -= entry.bytes;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Forget the threads kept for a change request, and every read in flight, after a write changed them.
|
|
2644
|
+
* @param key - the change request.
|
|
2645
|
+
*/
|
|
2646
|
+
drop(key) {
|
|
2647
|
+
this.drops += 1;
|
|
2648
|
+
this.forget(key);
|
|
2649
|
+
}
|
|
2650
|
+
forget(key) {
|
|
2651
|
+
const previous = this.entries.get(key);
|
|
2652
|
+
if (previous === void 0) return;
|
|
2653
|
+
this.entries.delete(key);
|
|
2654
|
+
this.bytes -= previous.bytes;
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
1973
2657
|
/** Stored states keyed by {@link storedKey}; derived data, so a record that fails its schema is set aside. */
|
|
1974
2658
|
const changeRequestStatesDomain = defineDomain({
|
|
1975
2659
|
name: "forge_panel_change_requests",
|
|
@@ -2335,18 +3019,30 @@ let ForgePanelController = (() => {
|
|
|
2335
3019
|
let _instanceExtraInitializers = [];
|
|
2336
3020
|
let _follow_decorators;
|
|
2337
3021
|
let _changeRequestStates_decorators;
|
|
3022
|
+
let _worktreeCleanup_decorators;
|
|
2338
3023
|
let _branches_decorators;
|
|
3024
|
+
let _diffBases_decorators;
|
|
2339
3025
|
let _track_decorators;
|
|
2340
3026
|
let _dismiss_decorators;
|
|
2341
3027
|
let _refresh_decorators;
|
|
2342
3028
|
let _localDiff_decorators;
|
|
3029
|
+
let _localCommits_decorators;
|
|
2343
3030
|
let _localText_decorators;
|
|
2344
3031
|
let _changeRequestChecks_decorators;
|
|
3032
|
+
let _changeRequestCommits_decorators;
|
|
2345
3033
|
let _changeRequestDiff_decorators;
|
|
2346
3034
|
let _changeRequestText_decorators;
|
|
3035
|
+
let _changeRequestViewed_decorators;
|
|
3036
|
+
let _setFileViewed_decorators;
|
|
3037
|
+
let _changeRequestReview_decorators;
|
|
2347
3038
|
let _submitReview_decorators;
|
|
3039
|
+
let _changeRequestReviewWrite_decorators;
|
|
2348
3040
|
let _markReady_decorators;
|
|
2349
3041
|
let _merge_decorators;
|
|
3042
|
+
let _rerunChecks_decorators;
|
|
3043
|
+
let _requestReviews_decorators;
|
|
3044
|
+
let _reviewerCandidates_decorators;
|
|
3045
|
+
let _updateBranch_decorators;
|
|
2350
3046
|
let _requestWorktree_decorators;
|
|
2351
3047
|
let _cancelWorktree_decorators;
|
|
2352
3048
|
let _stopCreation_decorators;
|
|
@@ -2358,18 +3054,30 @@ let ForgePanelController = (() => {
|
|
|
2358
3054
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
2359
3055
|
_follow_decorators = [Remote({ mode: "stream" })];
|
|
2360
3056
|
_changeRequestStates_decorators = [Remote({ mode: "stream" })];
|
|
3057
|
+
_worktreeCleanup_decorators = [Remote];
|
|
2361
3058
|
_branches_decorators = [Remote];
|
|
3059
|
+
_diffBases_decorators = [Remote];
|
|
2362
3060
|
_track_decorators = [Remote];
|
|
2363
3061
|
_dismiss_decorators = [Remote];
|
|
2364
3062
|
_refresh_decorators = [Remote];
|
|
2365
3063
|
_localDiff_decorators = [Remote];
|
|
3064
|
+
_localCommits_decorators = [Remote];
|
|
2366
3065
|
_localText_decorators = [Remote];
|
|
2367
3066
|
_changeRequestChecks_decorators = [Remote];
|
|
3067
|
+
_changeRequestCommits_decorators = [Remote];
|
|
2368
3068
|
_changeRequestDiff_decorators = [Remote];
|
|
2369
3069
|
_changeRequestText_decorators = [Remote];
|
|
3070
|
+
_changeRequestViewed_decorators = [Remote];
|
|
3071
|
+
_setFileViewed_decorators = [Remote];
|
|
3072
|
+
_changeRequestReview_decorators = [Remote];
|
|
2370
3073
|
_submitReview_decorators = [Remote];
|
|
3074
|
+
_changeRequestReviewWrite_decorators = [Remote];
|
|
2371
3075
|
_markReady_decorators = [Remote];
|
|
2372
3076
|
_merge_decorators = [Remote];
|
|
3077
|
+
_rerunChecks_decorators = [Remote];
|
|
3078
|
+
_requestReviews_decorators = [Remote];
|
|
3079
|
+
_reviewerCandidates_decorators = [Remote];
|
|
3080
|
+
_updateBranch_decorators = [Remote];
|
|
2373
3081
|
_requestWorktree_decorators = [Remote];
|
|
2374
3082
|
_cancelWorktree_decorators = [Remote];
|
|
2375
3083
|
_stopCreation_decorators = [Remote];
|
|
@@ -2398,6 +3106,17 @@ let ForgePanelController = (() => {
|
|
|
2398
3106
|
},
|
|
2399
3107
|
metadata: _metadata
|
|
2400
3108
|
}, null, _instanceExtraInitializers);
|
|
3109
|
+
__esDecorate(this, null, _worktreeCleanup_decorators, {
|
|
3110
|
+
kind: "method",
|
|
3111
|
+
name: "worktreeCleanup",
|
|
3112
|
+
static: false,
|
|
3113
|
+
private: false,
|
|
3114
|
+
access: {
|
|
3115
|
+
has: (obj) => "worktreeCleanup" in obj,
|
|
3116
|
+
get: (obj) => obj.worktreeCleanup
|
|
3117
|
+
},
|
|
3118
|
+
metadata: _metadata
|
|
3119
|
+
}, null, _instanceExtraInitializers);
|
|
2401
3120
|
__esDecorate(this, null, _branches_decorators, {
|
|
2402
3121
|
kind: "method",
|
|
2403
3122
|
name: "branches",
|
|
@@ -2409,6 +3128,17 @@ let ForgePanelController = (() => {
|
|
|
2409
3128
|
},
|
|
2410
3129
|
metadata: _metadata
|
|
2411
3130
|
}, null, _instanceExtraInitializers);
|
|
3131
|
+
__esDecorate(this, null, _diffBases_decorators, {
|
|
3132
|
+
kind: "method",
|
|
3133
|
+
name: "diffBases",
|
|
3134
|
+
static: false,
|
|
3135
|
+
private: false,
|
|
3136
|
+
access: {
|
|
3137
|
+
has: (obj) => "diffBases" in obj,
|
|
3138
|
+
get: (obj) => obj.diffBases
|
|
3139
|
+
},
|
|
3140
|
+
metadata: _metadata
|
|
3141
|
+
}, null, _instanceExtraInitializers);
|
|
2412
3142
|
__esDecorate(this, null, _track_decorators, {
|
|
2413
3143
|
kind: "method",
|
|
2414
3144
|
name: "track",
|
|
@@ -2453,6 +3183,17 @@ let ForgePanelController = (() => {
|
|
|
2453
3183
|
},
|
|
2454
3184
|
metadata: _metadata
|
|
2455
3185
|
}, null, _instanceExtraInitializers);
|
|
3186
|
+
__esDecorate(this, null, _localCommits_decorators, {
|
|
3187
|
+
kind: "method",
|
|
3188
|
+
name: "localCommits",
|
|
3189
|
+
static: false,
|
|
3190
|
+
private: false,
|
|
3191
|
+
access: {
|
|
3192
|
+
has: (obj) => "localCommits" in obj,
|
|
3193
|
+
get: (obj) => obj.localCommits
|
|
3194
|
+
},
|
|
3195
|
+
metadata: _metadata
|
|
3196
|
+
}, null, _instanceExtraInitializers);
|
|
2456
3197
|
__esDecorate(this, null, _localText_decorators, {
|
|
2457
3198
|
kind: "method",
|
|
2458
3199
|
name: "localText",
|
|
@@ -2475,6 +3216,17 @@ let ForgePanelController = (() => {
|
|
|
2475
3216
|
},
|
|
2476
3217
|
metadata: _metadata
|
|
2477
3218
|
}, null, _instanceExtraInitializers);
|
|
3219
|
+
__esDecorate(this, null, _changeRequestCommits_decorators, {
|
|
3220
|
+
kind: "method",
|
|
3221
|
+
name: "changeRequestCommits",
|
|
3222
|
+
static: false,
|
|
3223
|
+
private: false,
|
|
3224
|
+
access: {
|
|
3225
|
+
has: (obj) => "changeRequestCommits" in obj,
|
|
3226
|
+
get: (obj) => obj.changeRequestCommits
|
|
3227
|
+
},
|
|
3228
|
+
metadata: _metadata
|
|
3229
|
+
}, null, _instanceExtraInitializers);
|
|
2478
3230
|
__esDecorate(this, null, _changeRequestDiff_decorators, {
|
|
2479
3231
|
kind: "method",
|
|
2480
3232
|
name: "changeRequestDiff",
|
|
@@ -2497,6 +3249,39 @@ let ForgePanelController = (() => {
|
|
|
2497
3249
|
},
|
|
2498
3250
|
metadata: _metadata
|
|
2499
3251
|
}, null, _instanceExtraInitializers);
|
|
3252
|
+
__esDecorate(this, null, _changeRequestViewed_decorators, {
|
|
3253
|
+
kind: "method",
|
|
3254
|
+
name: "changeRequestViewed",
|
|
3255
|
+
static: false,
|
|
3256
|
+
private: false,
|
|
3257
|
+
access: {
|
|
3258
|
+
has: (obj) => "changeRequestViewed" in obj,
|
|
3259
|
+
get: (obj) => obj.changeRequestViewed
|
|
3260
|
+
},
|
|
3261
|
+
metadata: _metadata
|
|
3262
|
+
}, null, _instanceExtraInitializers);
|
|
3263
|
+
__esDecorate(this, null, _setFileViewed_decorators, {
|
|
3264
|
+
kind: "method",
|
|
3265
|
+
name: "setFileViewed",
|
|
3266
|
+
static: false,
|
|
3267
|
+
private: false,
|
|
3268
|
+
access: {
|
|
3269
|
+
has: (obj) => "setFileViewed" in obj,
|
|
3270
|
+
get: (obj) => obj.setFileViewed
|
|
3271
|
+
},
|
|
3272
|
+
metadata: _metadata
|
|
3273
|
+
}, null, _instanceExtraInitializers);
|
|
3274
|
+
__esDecorate(this, null, _changeRequestReview_decorators, {
|
|
3275
|
+
kind: "method",
|
|
3276
|
+
name: "changeRequestReview",
|
|
3277
|
+
static: false,
|
|
3278
|
+
private: false,
|
|
3279
|
+
access: {
|
|
3280
|
+
has: (obj) => "changeRequestReview" in obj,
|
|
3281
|
+
get: (obj) => obj.changeRequestReview
|
|
3282
|
+
},
|
|
3283
|
+
metadata: _metadata
|
|
3284
|
+
}, null, _instanceExtraInitializers);
|
|
2500
3285
|
__esDecorate(this, null, _submitReview_decorators, {
|
|
2501
3286
|
kind: "method",
|
|
2502
3287
|
name: "submitReview",
|
|
@@ -2508,6 +3293,17 @@ let ForgePanelController = (() => {
|
|
|
2508
3293
|
},
|
|
2509
3294
|
metadata: _metadata
|
|
2510
3295
|
}, null, _instanceExtraInitializers);
|
|
3296
|
+
__esDecorate(this, null, _changeRequestReviewWrite_decorators, {
|
|
3297
|
+
kind: "method",
|
|
3298
|
+
name: "changeRequestReviewWrite",
|
|
3299
|
+
static: false,
|
|
3300
|
+
private: false,
|
|
3301
|
+
access: {
|
|
3302
|
+
has: (obj) => "changeRequestReviewWrite" in obj,
|
|
3303
|
+
get: (obj) => obj.changeRequestReviewWrite
|
|
3304
|
+
},
|
|
3305
|
+
metadata: _metadata
|
|
3306
|
+
}, null, _instanceExtraInitializers);
|
|
2511
3307
|
__esDecorate(this, null, _markReady_decorators, {
|
|
2512
3308
|
kind: "method",
|
|
2513
3309
|
name: "markReady",
|
|
@@ -2530,6 +3326,50 @@ let ForgePanelController = (() => {
|
|
|
2530
3326
|
},
|
|
2531
3327
|
metadata: _metadata
|
|
2532
3328
|
}, null, _instanceExtraInitializers);
|
|
3329
|
+
__esDecorate(this, null, _rerunChecks_decorators, {
|
|
3330
|
+
kind: "method",
|
|
3331
|
+
name: "rerunChecks",
|
|
3332
|
+
static: false,
|
|
3333
|
+
private: false,
|
|
3334
|
+
access: {
|
|
3335
|
+
has: (obj) => "rerunChecks" in obj,
|
|
3336
|
+
get: (obj) => obj.rerunChecks
|
|
3337
|
+
},
|
|
3338
|
+
metadata: _metadata
|
|
3339
|
+
}, null, _instanceExtraInitializers);
|
|
3340
|
+
__esDecorate(this, null, _requestReviews_decorators, {
|
|
3341
|
+
kind: "method",
|
|
3342
|
+
name: "requestReviews",
|
|
3343
|
+
static: false,
|
|
3344
|
+
private: false,
|
|
3345
|
+
access: {
|
|
3346
|
+
has: (obj) => "requestReviews" in obj,
|
|
3347
|
+
get: (obj) => obj.requestReviews
|
|
3348
|
+
},
|
|
3349
|
+
metadata: _metadata
|
|
3350
|
+
}, null, _instanceExtraInitializers);
|
|
3351
|
+
__esDecorate(this, null, _reviewerCandidates_decorators, {
|
|
3352
|
+
kind: "method",
|
|
3353
|
+
name: "reviewerCandidates",
|
|
3354
|
+
static: false,
|
|
3355
|
+
private: false,
|
|
3356
|
+
access: {
|
|
3357
|
+
has: (obj) => "reviewerCandidates" in obj,
|
|
3358
|
+
get: (obj) => obj.reviewerCandidates
|
|
3359
|
+
},
|
|
3360
|
+
metadata: _metadata
|
|
3361
|
+
}, null, _instanceExtraInitializers);
|
|
3362
|
+
__esDecorate(this, null, _updateBranch_decorators, {
|
|
3363
|
+
kind: "method",
|
|
3364
|
+
name: "updateBranch",
|
|
3365
|
+
static: false,
|
|
3366
|
+
private: false,
|
|
3367
|
+
access: {
|
|
3368
|
+
has: (obj) => "updateBranch" in obj,
|
|
3369
|
+
get: (obj) => obj.updateBranch
|
|
3370
|
+
},
|
|
3371
|
+
metadata: _metadata
|
|
3372
|
+
}, null, _instanceExtraInitializers);
|
|
2533
3373
|
__esDecorate(this, null, _requestWorktree_decorators, {
|
|
2534
3374
|
kind: "method",
|
|
2535
3375
|
name: "requestWorktree",
|
|
@@ -2624,7 +3464,12 @@ let ForgePanelController = (() => {
|
|
|
2624
3464
|
worktreePrefix: z.string().default("dsh-"),
|
|
2625
3465
|
maxDiffBytes: z.number().default(8388608),
|
|
2626
3466
|
maxUntrackedFiles: z.number().default(100),
|
|
2627
|
-
maxCachedDiffBytes: z.number().default(16777216)
|
|
3467
|
+
maxCachedDiffBytes: z.number().default(16777216),
|
|
3468
|
+
maxCommits: z.number().default(250),
|
|
3469
|
+
testPaths: z.array(z.string()).default([]),
|
|
3470
|
+
interfacePaths: z.array(z.string()).default([]),
|
|
3471
|
+
maxCachedReviewBytes: z.number().default(16777216),
|
|
3472
|
+
reviewRefreshMs: z.number().default(6e4)
|
|
2628
3473
|
});
|
|
2629
3474
|
home = __runInitializers(this, _instanceExtraInitializers);
|
|
2630
3475
|
config;
|
|
@@ -2632,6 +3477,8 @@ let ForgePanelController = (() => {
|
|
|
2632
3477
|
worktreeStates;
|
|
2633
3478
|
creations;
|
|
2634
3479
|
patches;
|
|
3480
|
+
layers;
|
|
3481
|
+
reviews;
|
|
2635
3482
|
states;
|
|
2636
3483
|
stopPanels;
|
|
2637
3484
|
stopStates;
|
|
@@ -2643,7 +3490,8 @@ let ForgePanelController = (() => {
|
|
|
2643
3490
|
"gitTimeoutMs",
|
|
2644
3491
|
"graceMs",
|
|
2645
3492
|
"maxOutputBytes",
|
|
2646
|
-
"readinessTimeoutMs"
|
|
3493
|
+
"readinessTimeoutMs",
|
|
3494
|
+
"reviewRefreshMs"
|
|
2647
3495
|
]) {
|
|
2648
3496
|
const value = resolved[key];
|
|
2649
3497
|
if (!Number.isSafeInteger(value) || value <= 0 || value > MAX_TIMER_DELAY_MS) throw new Error(`forge-panel: ${key} must be a positive integer no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
@@ -2652,12 +3500,17 @@ let ForgePanelController = (() => {
|
|
|
2652
3500
|
"maxBranches",
|
|
2653
3501
|
"maxDiffBytes",
|
|
2654
3502
|
"maxUntrackedFiles",
|
|
2655
|
-
"maxCachedDiffBytes"
|
|
3503
|
+
"maxCachedDiffBytes",
|
|
3504
|
+
"maxCommits",
|
|
3505
|
+
"maxCachedReviewBytes"
|
|
2656
3506
|
]) if (!Number.isSafeInteger(resolved[key]) || resolved[key] <= 0) throw new Error(`forge-panel: ${key} must be a positive integer`);
|
|
2657
3507
|
if (!branchPrefix(resolved.worktreePrefix)) throw new Error("forge-panel: worktreePrefix must start a valid Git branch name");
|
|
3508
|
+
for (const key of ["testPaths", "interfacePaths"]) if (resolved[key].some((glob) => glob.trim() === "")) throw new Error(`forge-panel: ${key} entries must not be empty`);
|
|
3509
|
+
this.layers = new FileLayers(resolved.testPaths, resolved.interfacePaths);
|
|
2658
3510
|
this.home = ctx;
|
|
2659
3511
|
this.config = resolved;
|
|
2660
3512
|
this.patches = new PatchCache(resolved.maxCachedDiffBytes);
|
|
3513
|
+
this.reviews = new ReviewCache(resolved.maxCachedReviewBytes, resolved.reviewRefreshMs);
|
|
2661
3514
|
this.stopPanels = ctx.effect(() => async () => {
|
|
2662
3515
|
const panels = [...this.panels.values()];
|
|
2663
3516
|
this.panels.clear();
|
|
@@ -2732,6 +3585,15 @@ let ForgePanelController = (() => {
|
|
|
2732
3585
|
}), signal);
|
|
2733
3586
|
}
|
|
2734
3587
|
/**
|
|
3588
|
+
* Read or await the worktree service's archive cleanup of the Session's checkout.
|
|
3589
|
+
* @param session - Session whose cleanup is visible to the caller.
|
|
3590
|
+
* @param revision - null reads now; a matching revision waits for completion.
|
|
3591
|
+
* @returns the cleanup state, or null without a worktree service, an attempt, or a current revision.
|
|
3592
|
+
*/
|
|
3593
|
+
async worktreeCleanup(session, revision) {
|
|
3594
|
+
return await this.home.get("worktrees")?.cleanupOf(session, revision) ?? null;
|
|
3595
|
+
}
|
|
3596
|
+
/**
|
|
2735
3597
|
* List the local branches that can start a worktree of the Session's current checkout.
|
|
2736
3598
|
* @param session - Session whose current directory is listed.
|
|
2737
3599
|
* @param signal - request cancellation.
|
|
@@ -2742,6 +3604,23 @@ let ForgePanelController = (() => {
|
|
|
2742
3604
|
return await listBranches(this.home, this.config, session, this.home.workingDirectory.get(session), this.config.maxBranches, signal);
|
|
2743
3605
|
}
|
|
2744
3606
|
/**
|
|
3607
|
+
* List the branches the `branch` scope of the Session's current checkout can compare with.
|
|
3608
|
+
* @param session - Session whose checkout is read.
|
|
3609
|
+
* @param query - text the branch names must contain, ignoring case; empty for every branch.
|
|
3610
|
+
* @param signal - request cancellation.
|
|
3611
|
+
* @returns the automatic fork point and at most `maxBranches` remote-tracking and local branches each,
|
|
3612
|
+
* most recently committed first, without the checked-out branch.
|
|
3613
|
+
* @throws `forgePanel/not-a-checkout` outside a checkout; the Git error when Git fails or the listed refs exceed `maxDiffBytes`.
|
|
3614
|
+
*/
|
|
3615
|
+
async diffBases(session, query, signal) {
|
|
3616
|
+
signal.throwIfAborted();
|
|
3617
|
+
const inspection = await this.checkoutOf(session, signal);
|
|
3618
|
+
return await baseBranches(gitIn(this.home, {
|
|
3619
|
+
...this.config,
|
|
3620
|
+
maxOutputBytes: this.config.maxDiffBytes
|
|
3621
|
+
}, session, inspection.checkout.root, signal), inspection, this.worktreeState(session).created, query, this.config.maxBranches);
|
|
3622
|
+
}
|
|
3623
|
+
/**
|
|
2745
3624
|
* Bind a change request to a Session by URL, or restore a dismissed binding.
|
|
2746
3625
|
* @param session - Session that receives the binding.
|
|
2747
3626
|
* @param url - web URL of the change request.
|
|
@@ -2781,27 +3660,56 @@ let ForgePanelController = (() => {
|
|
|
2781
3660
|
* @param scope - which changes to read.
|
|
2782
3661
|
* @param signal - request cancellation.
|
|
2783
3662
|
* @returns the files, the base of the `branch` scope, and the untracked files left out.
|
|
2784
|
-
* @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/
|
|
2785
|
-
*
|
|
2786
|
-
*
|
|
3663
|
+
* @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/base-missing` when the base branch
|
|
3664
|
+
* chosen for the `branch` scope does not exist; `forgePanel/no-fork-point` for the `branch` scope without
|
|
3665
|
+
* a fork point; `forgePanel/commits-missing` when chosen commits are not between the fork point and HEAD in order;
|
|
3666
|
+
* `forgePanel/commits-not-linear` when a chosen commit's first parent is not the commit listed before it;
|
|
3667
|
+
* `forgePanel/filter-config-failed` when filter configuration cannot be read completely, before
|
|
3668
|
+
* any comparison; `forgePanel/diff-too-large` over `maxDiffBytes`; the Git error when Git fails.
|
|
2787
3669
|
*/
|
|
2788
3670
|
async localDiff(session, scope, signal) {
|
|
2789
3671
|
signal.throwIfAborted();
|
|
2790
3672
|
const inspection = await this.checkoutOf(session, signal);
|
|
2791
3673
|
const root = inspection.checkout.root;
|
|
2792
|
-
const
|
|
2793
|
-
|
|
3674
|
+
const git = gitIn(this.home, this.config, session, root, signal);
|
|
3675
|
+
const created = this.worktreeState(session).created;
|
|
3676
|
+
const fork = scope.kind !== "branch" ? null : await diffing(scope.base === null ? forkPoint(git, inspection, created) : chosenForkPoint(git, scope.base));
|
|
3677
|
+
return await diffing(localDiff(this.home, this.config, session, root, fork, scope, this.layers, signal));
|
|
3678
|
+
}
|
|
3679
|
+
/**
|
|
3680
|
+
* List the commits of the `branch` scope of the Session's current checkout, which the changes view can show one or
|
|
3681
|
+
* several of instead of the whole scope.
|
|
3682
|
+
* @param session - Session whose checkout is read.
|
|
3683
|
+
* @param base - the base ref of the `branch` scope, or null for its automatic fork point.
|
|
3684
|
+
* @param signal - request cancellation.
|
|
3685
|
+
* @returns the newest `maxCommits` commits between the fork point and HEAD, oldest first, and HEAD's commit.
|
|
3686
|
+
* @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/base-missing` when the base branch does not
|
|
3687
|
+
* exist; `forgePanel/no-fork-point` without a fork point; the Git error when Git fails or the listing exceeds `maxDiffBytes`.
|
|
3688
|
+
*/
|
|
3689
|
+
async localCommits(session, base, signal) {
|
|
3690
|
+
signal.throwIfAborted();
|
|
3691
|
+
const inspection = await this.checkoutOf(session, signal);
|
|
3692
|
+
const git = gitIn(this.home, {
|
|
3693
|
+
...this.config,
|
|
3694
|
+
maxOutputBytes: this.config.maxDiffBytes
|
|
3695
|
+
}, session, inspection.checkout.root, signal);
|
|
3696
|
+
const created = this.worktreeState(session).created;
|
|
3697
|
+
const fork = await diffing(base === null ? forkPoint(git, inspection, created) : chosenForkPoint(git, base));
|
|
3698
|
+
if (fork === null) throw new RemoteError("forgePanel/no-fork-point", "The checkout has no fork point to compare its branch with", {});
|
|
3699
|
+
return await localCommits(git, fork, this.config.maxCommits);
|
|
2794
3700
|
}
|
|
2795
3701
|
/**
|
|
2796
3702
|
* Read the new side of one changed file in a scope, which supplies the
|
|
2797
|
-
* unchanged lines between its hunks: the index for `staged`,
|
|
3703
|
+
* unchanged lines between its hunks: the index for `staged`, the last chosen commit for chosen commits of
|
|
3704
|
+
* the `branch` scope, else the working tree.
|
|
2798
3705
|
* @param session - Session whose checkout is read.
|
|
2799
3706
|
* @param scope - the scope the diff was read in.
|
|
2800
3707
|
* @param path - path relative to the checkout's top-level directory, as the diff names it.
|
|
2801
3708
|
* @param signal - request cancellation.
|
|
2802
3709
|
* @returns the text.
|
|
2803
3710
|
* @throws `forgePanel/not-a-checkout` outside a checkout; `forgePanel/diff-too-large` over `maxDiffBytes`;
|
|
2804
|
-
*
|
|
3711
|
+
* `forgePanel/commits-missing` for a chosen commit that is not a full object name; an error for a path outside
|
|
3712
|
+
* the checkout, binary content, or a failed read.
|
|
2805
3713
|
*/
|
|
2806
3714
|
async localText(session, scope, path, signal) {
|
|
2807
3715
|
signal.throwIfAborted();
|
|
@@ -2827,33 +3735,56 @@ let ForgePanelController = (() => {
|
|
|
2827
3735
|
return result;
|
|
2828
3736
|
}
|
|
2829
3737
|
/**
|
|
3738
|
+
* List the commits of a change request of a Session at its current head, which the changes view can show one or
|
|
3739
|
+
* several of instead of the whole change request.
|
|
3740
|
+
* @param session - Session the change request is bound to.
|
|
3741
|
+
* @param url - binding URL of the change request.
|
|
3742
|
+
* @param signal - request cancellation.
|
|
3743
|
+
* @returns the commits oldest first with the head they were read at, or null when the provider does not read commits.
|
|
3744
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3745
|
+
* `forgePanel/diff-failed` when the host does not list them.
|
|
3746
|
+
*/
|
|
3747
|
+
async changeRequestCommits(session, url, signal) {
|
|
3748
|
+
signal.throwIfAborted();
|
|
3749
|
+
const list = await this.home.forge.commits(this.bound(session, url).ref, signal);
|
|
3750
|
+
if (list !== void 0 && "code" in list) throw readError(list);
|
|
3751
|
+
return list ?? null;
|
|
3752
|
+
}
|
|
3753
|
+
/**
|
|
2830
3754
|
* Read the changes of a change request of a Session as its code host
|
|
2831
|
-
* computes them,
|
|
2832
|
-
*
|
|
2833
|
-
*
|
|
3755
|
+
* computes them, with each file's layer following the root `.gitattributes`
|
|
3756
|
+
* of the commit the diff ends at. Without `commits` the diff covers the change
|
|
3757
|
+
* request at the head commit of its latest status; a patch already read at the
|
|
3758
|
+
* same head commit and base branch is reused from memory with its attributes, for
|
|
3759
|
+
* any Session, until `maxCachedDiffBytes` evicts it. With `commits`, it covers those
|
|
3760
|
+
* commits, from the first one's first parent to the last, and is read every time.
|
|
2834
3761
|
* @param session - Session the change request is bound to.
|
|
2835
3762
|
* @param url - binding URL of the change request.
|
|
3763
|
+
* @param commits - consecutive commits of the change request, or null for all of it.
|
|
2836
3764
|
* @param signal - request cancellation.
|
|
2837
|
-
* @returns the files, the
|
|
3765
|
+
* @returns the files, the commit they end at, each file's web page, and the commits the checkout has beyond the head.
|
|
2838
3766
|
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3767
|
+
* `forgePanel/commits-missing` when chosen commits are not among the change request's commits in order;
|
|
3768
|
+
* `forgePanel/commits-not-linear` when a chosen commit's first parent is not the commit listed before it;
|
|
3769
|
+
* `forgePanel/stale-head` without `commits` when the head moved past the latest status, which is then polled again;
|
|
2839
3770
|
* `forgePanel/diff-too-large` when the host or its provider refuses the diff over a size limit;
|
|
2840
|
-
* `forgePanel/diff-failed` before its status was read
|
|
3771
|
+
* `forgePanel/diff-failed` before its status was read, for a first chosen commit without a parent, and when the host
|
|
3772
|
+
* does not provide the commits, the diff, or an existing `.gitattributes` otherwise.
|
|
2841
3773
|
*/
|
|
2842
|
-
async changeRequestDiff(session, url, signal) {
|
|
3774
|
+
async changeRequestDiff(session, url, commits, signal) {
|
|
2843
3775
|
signal.throwIfAborted();
|
|
2844
3776
|
const { ref, update } = this.bound(session, url);
|
|
2845
3777
|
if (update === null || !("snapshot" in update)) throw new RemoteError("forgePanel/diff-failed", "The change request status has not been read yet", {});
|
|
3778
|
+
if (commits !== null) return await this.commitsDiff(ref, commits, signal);
|
|
2846
3779
|
const { headSha, headBranch, baseBranch } = update.snapshot;
|
|
2847
3780
|
const key = changeRequestKey(ref);
|
|
2848
3781
|
const version = JSON.stringify([headSha, baseBranch]);
|
|
2849
|
-
let
|
|
2850
|
-
if (
|
|
2851
|
-
|
|
2852
|
-
if (typeof read !== "string") throw readError(read);
|
|
3782
|
+
let read = this.patches.get(key, version);
|
|
3783
|
+
if (read === void 0) {
|
|
3784
|
+
read = await this.patchAt(ref, headSha, async (operation) => await this.home.forge.diff(ref, headSha, operation), signal);
|
|
2853
3785
|
this.patches.set(key, version, read);
|
|
2854
|
-
patch = read;
|
|
2855
3786
|
}
|
|
2856
|
-
const files = parseDiff(patch);
|
|
3787
|
+
const files = this.layers.classify(parseDiff(read.patch), read.attributes);
|
|
2857
3788
|
let localAhead = null;
|
|
2858
3789
|
try {
|
|
2859
3790
|
localAhead = await aheadOf(gitIn(this.home, this.config, session, this.home.workingDirectory.get(session), signal), headBranch, headSha);
|
|
@@ -2887,7 +3818,79 @@ let ForgePanelController = (() => {
|
|
|
2887
3818
|
return text;
|
|
2888
3819
|
}
|
|
2889
3820
|
/**
|
|
2890
|
-
*
|
|
3821
|
+
* Read the signed-in user's viewed marks on the files of a change request of a Session, which the host keeps for the
|
|
3822
|
+
* whole change request.
|
|
3823
|
+
* @param session - Session the change request is bound to.
|
|
3824
|
+
* @param url - binding URL of the change request.
|
|
3825
|
+
* @param headSha - head commit of the shown diff; marks read at another head are refused.
|
|
3826
|
+
* @param signal - request cancellation.
|
|
3827
|
+
* @returns the marks at `headSha`, or null when the provider keeps no viewed marks.
|
|
3828
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3829
|
+
* `forgePanel/stale-head` when the head moved past `headSha`, which is then polled again; `forgePanel/viewed-failed`
|
|
3830
|
+
* when the host does not provide the marks otherwise.
|
|
3831
|
+
*/
|
|
3832
|
+
async changeRequestViewed(session, url, headSha, signal) {
|
|
3833
|
+
signal.throwIfAborted();
|
|
3834
|
+
const result = await this.home.forge.viewedFiles(this.bound(session, url).ref, headSha, signal);
|
|
3835
|
+
if (result === void 0) return null;
|
|
3836
|
+
if ("code" in result) throw new RemoteError(result.code === "stale" ? "forgePanel/stale-head" : "forgePanel/viewed-failed", result.message, {});
|
|
3837
|
+
return result;
|
|
3838
|
+
}
|
|
3839
|
+
/**
|
|
3840
|
+
* Set or clear the signed-in user's viewed mark on one file of a change request of a Session.
|
|
3841
|
+
* @param session - Session the change request is bound to.
|
|
3842
|
+
* @param url - binding URL of the change request.
|
|
3843
|
+
* @param request - the file, its mark, and the head commit of the shown diff.
|
|
3844
|
+
* @param signal - request cancellation.
|
|
3845
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3846
|
+
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
|
|
3847
|
+
* reason when the host refuses, cannot be reached, or keeps no viewed marks; `forgePanel/action-unknown` when the host
|
|
3848
|
+
* did not confirm whether it saved the mark.
|
|
3849
|
+
*/
|
|
3850
|
+
async setFileViewed(session, url, request, signal) {
|
|
3851
|
+
signal.throwIfAborted();
|
|
3852
|
+
const { ref } = this.bound(session, url);
|
|
3853
|
+
if (request.path === "") throw new Error("Invalid viewed file");
|
|
3854
|
+
const failure = await this.home.forge.setViewed(ref, request, signal);
|
|
3855
|
+
if (failure !== void 0) throw actionError(failure);
|
|
3856
|
+
}
|
|
3857
|
+
/**
|
|
3858
|
+
* Read the review threads of a change request of a Session at the head commit of its displayed diff. Threads read
|
|
3859
|
+
* at the same head commit and update time are reused from memory, for any Session, until they are
|
|
3860
|
+
* `reviewRefreshMs` old, `maxCachedReviewBytes` evicts them, or a review write through this panel drops them; a read
|
|
3861
|
+
* again after that age, or a `fresh` read, shows threads resolved elsewhere since, which do not change a GitHub pull
|
|
3862
|
+
* request's update time.
|
|
3863
|
+
* @param session - Session the change request is bound to.
|
|
3864
|
+
* @param url - binding URL of the change request.
|
|
3865
|
+
* @param headSha - head commit of the displayed diff.
|
|
3866
|
+
* @param fresh - whether to read from the host even when threads at this head and update time are kept, as after the
|
|
3867
|
+
* reader refreshes the view; the result replaces the kept threads.
|
|
3868
|
+
* @param signal - request cancellation.
|
|
3869
|
+
* @returns the threads at `headSha`, with `current` positions numbering the files of that diff.
|
|
3870
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3871
|
+
* `forgePanel/stale-head` when the latest status or the host names another head, which a host answer polls again;
|
|
3872
|
+
* `forgePanel/review-unsupported` when the provider cannot read reviews; `forgePanel/review-failed` before the
|
|
3873
|
+
* status was read and when the host does not provide the threads otherwise.
|
|
3874
|
+
*/
|
|
3875
|
+
async changeRequestReview(session, url, headSha, fresh, signal) {
|
|
3876
|
+
signal.throwIfAborted();
|
|
3877
|
+
const { ref, update } = this.bound(session, url);
|
|
3878
|
+
if (update === null || !("snapshot" in update)) throw new RemoteError("forgePanel/review-failed", "The change request status has not been read yet", {});
|
|
3879
|
+
if (update.snapshot.headSha !== headSha) throw new RemoteError("forgePanel/stale-head", `The change request head moved from ${headSha} to ${update.snapshot.headSha}`, {});
|
|
3880
|
+
const key = changeRequestKey(ref);
|
|
3881
|
+
const version = JSON.stringify([headSha, update.snapshot.updatedAt]);
|
|
3882
|
+
const readAt = Date.now();
|
|
3883
|
+
const kept = fresh ? void 0 : this.reviews.get(key, version, readAt);
|
|
3884
|
+
if (kept !== void 0) return kept;
|
|
3885
|
+
const token = this.reviews.token();
|
|
3886
|
+
const review = await this.home.forge.readReview(ref, headSha, signal);
|
|
3887
|
+
if ("code" in review) throw reviewError(review);
|
|
3888
|
+
this.reviews.set(key, version, review, readAt, token);
|
|
3889
|
+
return review;
|
|
3890
|
+
}
|
|
3891
|
+
/**
|
|
3892
|
+
* Publish a line comment or completed review for a visible Session binding. The threads kept for the change request
|
|
3893
|
+
* are dropped once the host answers, so the next read shows the comments.
|
|
2891
3894
|
* @param session - Session retaining the change request.
|
|
2892
3895
|
* @param url - visible binding URL.
|
|
2893
3896
|
* @param request - reviewed head, ranges, plain text, and explicit review decision.
|
|
@@ -2897,11 +3900,39 @@ let ForgePanelController = (() => {
|
|
|
2897
3900
|
async submitReview(session, url, request, signal) {
|
|
2898
3901
|
signal.throwIfAborted();
|
|
2899
3902
|
const { ref } = this.bound(session, url);
|
|
2900
|
-
if (
|
|
3903
|
+
if (!isCommit(request.headSha)) throw new Error("Invalid review commit");
|
|
2901
3904
|
const comments = request.kind === "comment" ? [request.comment] : request.comments;
|
|
2902
|
-
if (comments.
|
|
3905
|
+
if (!comments.every(validComment)) throw new Error("Invalid review comment");
|
|
2903
3906
|
if (request.kind === "review" && request.event !== "approve" && request.body.trim() === "" && comments.length === 0) throw new Error("Empty review");
|
|
2904
|
-
|
|
3907
|
+
try {
|
|
3908
|
+
return await this.home.forge.submitReview(ref, request, signal);
|
|
3909
|
+
} finally {
|
|
3910
|
+
this.reviews.drop(changeRequestKey(ref));
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
/**
|
|
3914
|
+
* Write to the review threads or the pending review of a change request of a Session while its head is still the
|
|
3915
|
+
* head the user saw. The threads kept for the change request are dropped once the host answers, so the next read
|
|
3916
|
+
* shows the write, which a resolve does not show through a GitHub pull request's update time.
|
|
3917
|
+
* @param session - Session the change request is bound to.
|
|
3918
|
+
* @param url - binding URL of the change request.
|
|
3919
|
+
* @param write - the write and the head commit of the threads the user saw.
|
|
3920
|
+
* @param signal - request cancellation.
|
|
3921
|
+
* @returns whether the host took the write; `stale` once the head moved, which polls the change request again, and
|
|
3922
|
+
* `unknown` when the outcome must be checked on the host before the write is tried again.
|
|
3923
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves; an error
|
|
3924
|
+
* for a write without text, a head that is not a commit object name, or an invalid line range.
|
|
3925
|
+
*/
|
|
3926
|
+
async changeRequestReviewWrite(session, url, write, signal) {
|
|
3927
|
+
signal.throwIfAborted();
|
|
3928
|
+
const { ref } = this.bound(session, url);
|
|
3929
|
+
if (!isCommit(write.headSha)) throw new Error("Invalid review commit");
|
|
3930
|
+
if (!validWrite(write)) throw new Error("Invalid review write");
|
|
3931
|
+
try {
|
|
3932
|
+
return await this.home.forge.writeReview(ref, write, signal);
|
|
3933
|
+
} finally {
|
|
3934
|
+
this.reviews.drop(changeRequestKey(ref));
|
|
3935
|
+
}
|
|
2905
3936
|
}
|
|
2906
3937
|
/**
|
|
2907
3938
|
* Mark a draft change request of a Session ready for review; the change
|
|
@@ -2938,6 +3969,78 @@ let ForgePanelController = (() => {
|
|
|
2938
3969
|
if (failure !== void 0) throw actionError(failure);
|
|
2939
3970
|
}
|
|
2940
3971
|
/**
|
|
3972
|
+
* Rerun the failed checks of a change request of a Session while its head is still the commit whose checks the user
|
|
3973
|
+
* saw; the change request is polled again once the host answers.
|
|
3974
|
+
* @param session - Session the change request is bound to.
|
|
3975
|
+
* @param url - binding URL of the change request.
|
|
3976
|
+
* @param request - the head commit whose checks the user saw.
|
|
3977
|
+
* @param signal - request cancellation.
|
|
3978
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3979
|
+
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
|
|
3980
|
+
* reason when the host refuses, cannot be reached, or reruns no checks; `forgePanel/action-unknown` when the host did
|
|
3981
|
+
* not confirm whether it started the rerun.
|
|
3982
|
+
*/
|
|
3983
|
+
async rerunChecks(session, url, request, signal) {
|
|
3984
|
+
signal.throwIfAborted();
|
|
3985
|
+
const failure = await this.home.forge.rerunChecks(this.bound(session, url).ref, request, signal);
|
|
3986
|
+
if (failure !== void 0) throw actionError(failure);
|
|
3987
|
+
}
|
|
3988
|
+
/**
|
|
3989
|
+
* Request reviews of a change request of a Session from more reviewers; the change request is polled again once the
|
|
3990
|
+
* host answers.
|
|
3991
|
+
* @param session - Session the change request is bound to.
|
|
3992
|
+
* @param url - binding URL of the change request.
|
|
3993
|
+
* @param reviewers - the reviewers to ask, by kind and login.
|
|
3994
|
+
* @param signal - request cancellation.
|
|
3995
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
3996
|
+
* `forgePanel/action-failed` with the host's reason when the host refuses, cannot be reached, or requests no reviews;
|
|
3997
|
+
* `forgePanel/action-unknown` when the host did not confirm whether it requested the reviews.
|
|
3998
|
+
*/
|
|
3999
|
+
async requestReviews(session, url, reviewers, signal) {
|
|
4000
|
+
signal.throwIfAborted();
|
|
4001
|
+
const { ref } = this.bound(session, url);
|
|
4002
|
+
if (reviewers.length === 0 || reviewers.some((reviewer) => reviewer.login.trim() === "")) throw new Error("Invalid reviewers");
|
|
4003
|
+
const failure = await this.home.forge.requestReviews(ref, { reviewers }, signal);
|
|
4004
|
+
if (failure !== void 0) throw actionError(failure);
|
|
4005
|
+
}
|
|
4006
|
+
/**
|
|
4007
|
+
* List accounts a review of a change request of a Session can be requested from.
|
|
4008
|
+
* @param session - Session the change request is bound to.
|
|
4009
|
+
* @param url - binding URL of the change request.
|
|
4010
|
+
* @param query - text the login or name contains; empty for the host's suggestions and first accounts.
|
|
4011
|
+
* @param signal - request cancellation.
|
|
4012
|
+
* @returns the accounts, the host's suggestions first.
|
|
4013
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
4014
|
+
* `forgePanel/reviewers-failed` when the host does not list them.
|
|
4015
|
+
*/
|
|
4016
|
+
async reviewerCandidates(session, url, query, signal) {
|
|
4017
|
+
signal.throwIfAborted();
|
|
4018
|
+
const result = await this.home.forge.reviewerCandidates(this.bound(session, url).ref, query, signal);
|
|
4019
|
+
if ("code" in result) throw new RemoteError("forgePanel/reviewers-failed", result.message, {});
|
|
4020
|
+
return result;
|
|
4021
|
+
}
|
|
4022
|
+
/**
|
|
4023
|
+
* Bring the base branch's new commits into the head branch of a change request of a Session while its head is still
|
|
4024
|
+
* `headSha`; the change request is polled again once the host answers.
|
|
4025
|
+
* @param session - Session the change request is bound to.
|
|
4026
|
+
* @param url - binding URL of the change request.
|
|
4027
|
+
* @param method - merge commit or rebase.
|
|
4028
|
+
* @param headSha - head commit the user confirmed.
|
|
4029
|
+
* @param signal - request cancellation.
|
|
4030
|
+
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
|
|
4031
|
+
* `forgePanel/stale-head` when the head moved past `headSha`; `forgePanel/action-failed` with the host's reason when
|
|
4032
|
+
* the host refuses, cannot be reached, or updates no branches; `forgePanel/action-unknown` when the host did not
|
|
4033
|
+
* confirm whether it started the update.
|
|
4034
|
+
*/
|
|
4035
|
+
async updateBranch(session, url, method, headSha, signal) {
|
|
4036
|
+
signal.throwIfAborted();
|
|
4037
|
+
const failure = await this.home.forge.updateBranch(this.bound(session, url).ref, {
|
|
4038
|
+
method,
|
|
4039
|
+
headSha
|
|
4040
|
+
}, signal);
|
|
4041
|
+
if (failure !== void 0) throw actionError(failure);
|
|
4042
|
+
}
|
|
4043
|
+
/**
|
|
2941
4044
|
* Ask for a new worktree before the Session's first turn, replacing an open
|
|
2942
4045
|
* request and forgetting a failed attempt. While the next message waits in
|
|
2943
4046
|
* the inbox, or else at the first step proposal, the panel creates a branch
|
|
@@ -3076,6 +4179,62 @@ let ForgePanelController = (() => {
|
|
|
3076
4179
|
const missing = panel === void 0 ? await missingWorktree(this.home, this.config, session, this.worktreeState(session), directory, signal) : await panel.checkMissing(signal);
|
|
3077
4180
|
return this.home.workingDirectory.get(session) === directory ? missing : null;
|
|
3078
4181
|
}
|
|
4182
|
+
/** The changes of consecutive commits of a change request, from the first one's first parent to the last. */
|
|
4183
|
+
async commitsDiff(ref, commits, signal) {
|
|
4184
|
+
const list = await this.home.forge.commits(ref, signal);
|
|
4185
|
+
if (list === void 0) throw new RemoteError("forgePanel/diff-failed", "The code host provider does not read commits", {});
|
|
4186
|
+
if ("code" in list) throw readError(list);
|
|
4187
|
+
const start = rangeStart(list.commits, commits);
|
|
4188
|
+
if (start === "missing") throw new RemoteError("forgePanel/commits-missing", "The chosen commits are no longer in the change request", {});
|
|
4189
|
+
if (start === "not-linear") throw new RemoteError("forgePanel/commits-not-linear", "The chosen commits are not one run of first parents", {});
|
|
4190
|
+
const parent = start.parent;
|
|
4191
|
+
if (parent === null) throw new RemoteError("forgePanel/diff-failed", "The first chosen commit has no parent to compare with", {});
|
|
4192
|
+
const { patch, attributes } = await this.patchAt(ref, commits.to, async (operation) => await this.home.forge.compare(ref, parent, commits.to, operation), signal);
|
|
4193
|
+
const files = this.layers.classify(parseDiff(patch), attributes);
|
|
4194
|
+
const fileUrls = Object.fromEntries(files.map((file) => [file.path, this.home.forge.fileUrl(ref, commits.to, file.path)]));
|
|
4195
|
+
return {
|
|
4196
|
+
headSha: commits.to,
|
|
4197
|
+
files,
|
|
4198
|
+
localAhead: null,
|
|
4199
|
+
fileUrls
|
|
4200
|
+
};
|
|
4201
|
+
}
|
|
4202
|
+
/**
|
|
4203
|
+
* Read a patch that ends at `commit` together with the root `.gitattributes` at that commit. A failed patch read
|
|
4204
|
+
* cancels the attributes read. Both reads end before the result: the patch's failure passes on first, and the
|
|
4205
|
+
* attributes failure only after the patch was read, so the outcome does not depend on which read ends first.
|
|
4206
|
+
* @param ref - change request whose repository holds the commit.
|
|
4207
|
+
* @param commit - commit the patch ends at.
|
|
4208
|
+
* @param readPatch - reads the patch under the given cancellation.
|
|
4209
|
+
* @param signal - request cancellation.
|
|
4210
|
+
* @returns the patch and the attributes text, empty when the commit has none.
|
|
4211
|
+
* @throws the Remote error for a refused patch or attributes read, or `signal.reason` when it aborts.
|
|
4212
|
+
*/
|
|
4213
|
+
async patchAt(ref, commit, readPatch, signal) {
|
|
4214
|
+
const unneeded = new AbortController();
|
|
4215
|
+
const patch = readPatch(signal).then((result) => {
|
|
4216
|
+
if (typeof result !== "string") throw readError(result);
|
|
4217
|
+
return result;
|
|
4218
|
+
});
|
|
4219
|
+
const attributes = this.attributesAt(ref, commit, AbortSignal.any([signal, unneeded.signal]));
|
|
4220
|
+
patch.then(void 0, () => {
|
|
4221
|
+
unneeded.abort();
|
|
4222
|
+
});
|
|
4223
|
+
const [text, rules] = await Promise.allSettled([patch, attributes]);
|
|
4224
|
+
if (text.status === "rejected") throw text.reason;
|
|
4225
|
+
if (rules.status === "rejected") throw rules.reason;
|
|
4226
|
+
return {
|
|
4227
|
+
patch: text.value,
|
|
4228
|
+
attributes: rules.value
|
|
4229
|
+
};
|
|
4230
|
+
}
|
|
4231
|
+
/** The root `.gitattributes` of a change request's repository at a commit, empty when the commit has none. */
|
|
4232
|
+
async attributesAt(ref, commit, signal) {
|
|
4233
|
+
const attributes = await this.home.forge.fileText(ref, commit, ATTRIBUTES_PATH, signal);
|
|
4234
|
+
if (typeof attributes === "string") return attributes;
|
|
4235
|
+
if (attributes.code === "not-found") return "";
|
|
4236
|
+
throw readError(attributes);
|
|
4237
|
+
}
|
|
3079
4238
|
/** Inspect the checkout of the Session's current directory, which local diffs read. */
|
|
3080
4239
|
async checkoutOf(session, signal) {
|
|
3081
4240
|
const inspection = await inspectCheckout(this.home, this.config, session, this.home.workingDirectory.get(session), signal);
|
|
@@ -3190,15 +4349,78 @@ let ForgePanelController = (() => {
|
|
|
3190
4349
|
};
|
|
3191
4350
|
})();
|
|
3192
4351
|
/**
|
|
4352
|
+
* Whether a value names a full commit object name.
|
|
4353
|
+
* @param value - the value from the browser.
|
|
4354
|
+
* @returns whether it is 40 or 64 hexadecimal digits.
|
|
4355
|
+
*/
|
|
4356
|
+
function isCommit(value) {
|
|
4357
|
+
return /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(value);
|
|
4358
|
+
}
|
|
4359
|
+
/**
|
|
4360
|
+
* Whether a line comment from the browser names a path, consecutive positive lines, and text.
|
|
4361
|
+
* @param comment - the comment.
|
|
4362
|
+
* @returns whether a provider may write it.
|
|
4363
|
+
*/
|
|
4364
|
+
function validComment(comment) {
|
|
4365
|
+
return comment.path !== "" && comment.body.trim() !== "" && Number.isSafeInteger(comment.startLine) && comment.startLine >= 1 && Number.isSafeInteger(comment.endLine) && comment.endLine >= comment.startLine;
|
|
4366
|
+
}
|
|
4367
|
+
/**
|
|
4368
|
+
* Whether a review write from the browser names its target and carries text where the write needs it.
|
|
4369
|
+
* @param write - the write.
|
|
4370
|
+
* @returns whether a provider may perform it.
|
|
4371
|
+
*/
|
|
4372
|
+
function validWrite(write) {
|
|
4373
|
+
switch (write.kind) {
|
|
4374
|
+
case "reply": return write.thread !== "" && write.body.trim() !== "";
|
|
4375
|
+
case "resolve": return write.thread !== "";
|
|
4376
|
+
case "edit-comment": return write.comment !== "" && write.body.trim() !== "";
|
|
4377
|
+
case "delete-comment": return write.comment !== "";
|
|
4378
|
+
case "add-pending": return validComment(write.comment);
|
|
4379
|
+
case "submit-pending": return write.review !== "" && (write.event !== "request-changes" || write.body.trim() !== "");
|
|
4380
|
+
case "discard-pending": return write.review !== "";
|
|
4381
|
+
/* v8 ignore next -- closed ForgeReviewWrite kind union exhaustiveness guard */
|
|
4382
|
+
default: return assertNever(write, "ForgeReviewWrite.kind");
|
|
4383
|
+
}
|
|
4384
|
+
}
|
|
4385
|
+
/**
|
|
3193
4386
|
* Report why the code host did not provide a diff or file.
|
|
3194
4387
|
* @param failure - the provider's failure.
|
|
3195
|
-
* @returns `forgePanel/diff-too-large` for an answer over a size limit,
|
|
4388
|
+
* @returns `forgePanel/diff-too-large` for an answer over a size limit, `forgePanel/stale-head` for a head that moved,
|
|
4389
|
+
* else `forgePanel/diff-failed`, with the provider's message.
|
|
3196
4390
|
*/
|
|
3197
4391
|
function readError(failure) {
|
|
3198
|
-
|
|
4392
|
+
switch (failure.code) {
|
|
4393
|
+
case "too-large": return new RemoteError("forgePanel/diff-too-large", failure.message, {});
|
|
4394
|
+
case "stale": return new RemoteError("forgePanel/stale-head", failure.message, {});
|
|
4395
|
+
case "not-found":
|
|
4396
|
+
case "unauthenticated":
|
|
4397
|
+
case "unsupported":
|
|
4398
|
+
case "unavailable": return new RemoteError("forgePanel/diff-failed", failure.message, {});
|
|
4399
|
+
/* v8 ignore next -- closed ForgeFailure code union exhaustiveness guard */
|
|
4400
|
+
default: return assertNever(failure.code, "ForgeFailure.code");
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
/**
|
|
4404
|
+
* Report why the code host did not provide review threads.
|
|
4405
|
+
* @param failure - the provider's failure.
|
|
4406
|
+
* @returns `forgePanel/stale-head` for a head that moved, `forgePanel/review-unsupported` for a provider without
|
|
4407
|
+
* review reads, else `forgePanel/review-failed`, with the provider's message.
|
|
4408
|
+
*/
|
|
4409
|
+
function reviewError(failure) {
|
|
4410
|
+
switch (failure.code) {
|
|
4411
|
+
case "stale": return new RemoteError("forgePanel/stale-head", failure.message, {});
|
|
4412
|
+
case "unsupported": return new RemoteError("forgePanel/review-unsupported", failure.message, {});
|
|
4413
|
+
case "not-found":
|
|
4414
|
+
case "unauthenticated":
|
|
4415
|
+
case "too-large":
|
|
4416
|
+
case "unavailable": return new RemoteError("forgePanel/review-failed", failure.message, {});
|
|
4417
|
+
/* v8 ignore next -- closed ForgeFailure code union exhaustiveness guard */
|
|
4418
|
+
default: return assertNever(failure.code, "ForgeFailure.code");
|
|
4419
|
+
}
|
|
3199
4420
|
}
|
|
3200
4421
|
/**
|
|
3201
|
-
* Settle a diff read, reporting its size limit
|
|
4422
|
+
* Settle a diff read, reporting its size limit, its filter configuration, a missing fork point, a missing base branch, and chosen
|
|
4423
|
+
* commits that are not on the branch as Remote errors.
|
|
3202
4424
|
* @param reading - the read.
|
|
3203
4425
|
* @returns what the read returned.
|
|
3204
4426
|
*/
|
|
@@ -3209,6 +4431,9 @@ async function diffing(reading) {
|
|
|
3209
4431
|
if (error instanceof FilterConfigError) throw new RemoteError("forgePanel/filter-config-failed", error.message, {}, { cause: error });
|
|
3210
4432
|
if (error instanceof DiffTooLarge) throw new RemoteError("forgePanel/diff-too-large", error.message, {}, { cause: error });
|
|
3211
4433
|
if (error instanceof NoForkPoint) throw new RemoteError("forgePanel/no-fork-point", error.message, {}, { cause: error });
|
|
4434
|
+
if (error instanceof BaseMissing) throw new RemoteError("forgePanel/base-missing", error.message, {}, { cause: error });
|
|
4435
|
+
if (error instanceof CommitsMissing) throw new RemoteError("forgePanel/commits-missing", error.message, {}, { cause: error });
|
|
4436
|
+
if (error instanceof CommitsNotLinear) throw new RemoteError("forgePanel/commits-not-linear", error.message, {}, { cause: error });
|
|
3212
4437
|
throw error;
|
|
3213
4438
|
}
|
|
3214
4439
|
}
|
|
@@ -3218,7 +4443,7 @@ async function diffing(reading) {
|
|
|
3218
4443
|
* @returns the Remote error to throw.
|
|
3219
4444
|
*/
|
|
3220
4445
|
function actionError(failure) {
|
|
3221
|
-
return new RemoteError(failure.code === "stale" ? "forgePanel/stale-head" : "forgePanel/action-failed", failure.message, {});
|
|
4446
|
+
return new RemoteError(failure.code === "stale" ? "forgePanel/stale-head" : failure.code === "unknown" ? "forgePanel/action-unknown" : "forgePanel/action-failed", failure.message, {});
|
|
3222
4447
|
}
|
|
3223
4448
|
/**
|
|
3224
4449
|
* Whether `prefix` followed by hexadecimal digits is a branch name that Git
|