dsh-remote-vs 0.21.0 → 0.22.0

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/lib/index.js CHANGED
@@ -4861,13 +4861,89 @@ function trackedStatusCommand(root) {
4861
4861
  return [cdLine(root), "git --no-pager status --porcelain -z -uno -- ."].join("\n");
4862
4862
  }
4863
4863
  /**
4864
+ * Directory names the ledger does not count as session changes.
4865
+ *
4866
+ * Build output and dependency caches are the two things a build leaves behind,
4867
+ * and neither is this session's work. `--exclude-standard` only covers what the
4868
+ * repository's own ignore rules name, so a checkout whose build directory is NOT
4869
+ * ignored pays twice: thousands of paths fill the 500-row list (sorted, and
4870
+ * `build/`/`out/` sort BEFORE `src/`, so the real changes get truncated away) and
4871
+ * every listed path costs a read out of the 8 MiB transfer budget.
4872
+ *
4873
+ * The names mirror the three lists the plugin already prunes by elsewhere
4874
+ * (`client/quickopen-model.ts` `EXCLUDED_DIRECTORIES`, `p2/file-refs.ts`
4875
+ * `REMOTE_FILE_SEARCH_EXCLUDED_DIRECTORIES`, `search-ops.ts` `PRUNE_DIRS`). One
4876
+ * vocabulary, four consumers: fold them into a shared module when one of those
4877
+ * surfaces is next touched, instead of adding a fifth spelling here.
4878
+ */
4879
+ const UNTRACKED_EXCLUDED_DIRECTORIES = [
4880
+ ".git",
4881
+ "node_modules",
4882
+ "dist",
4883
+ "build",
4884
+ "out",
4885
+ "coverage",
4886
+ "target",
4887
+ ".next",
4888
+ ".nuxt",
4889
+ ".turbo",
4890
+ ".venv",
4891
+ "__pycache__",
4892
+ ".pytest_cache",
4893
+ ".mypy_cache",
4894
+ ".gradle"
4895
+ ];
4896
+ /** Ceiling on the pathspecs one command carries (a cap, not a policy). */
4897
+ const MAX_EXCLUDE_DIRS = 32;
4898
+ /**
4899
+ * Keep only directory names a pathspec may name safely.
4900
+ *
4901
+ * A value that is absolute, carries a separator, walks up or looks like a flag
4902
+ * is DROPPED rather than rejected: the list is configuration, and one bad entry
4903
+ * must not stop the scan — the scan's job is to say what changed, not to police
4904
+ * a setting. Dropping is also the conservative direction: a name that is not
4905
+ * excluded is merely visible, while a malformed pathspec would hide paths the
4906
+ * user never asked to hide (or turn `--exclude` into another flag).
4907
+ *
4908
+ * @param dirs - candidate names (undefined = none).
4909
+ * @returns the usable names, deduplicated, in the given order.
4910
+ */
4911
+ function excludeDirNames(dirs) {
4912
+ const kept = [];
4913
+ for (const raw of dirs ?? []) {
4914
+ const name = raw.trim();
4915
+ if (name === "" || name === "." || name === "..") continue;
4916
+ if (name.includes("/") || name.includes("\\") || name.includes("\0")) continue;
4917
+ if (/[*?[\]]/.test(name)) continue;
4918
+ if (name.startsWith("-")) continue;
4919
+ if (kept.includes(name)) continue;
4920
+ if (kept.length >= MAX_EXCLUDE_DIRS) break;
4921
+ kept.push(name);
4922
+ }
4923
+ return kept;
4924
+ }
4925
+ /**
4864
4926
  * New files git is not tracking yet (the ones a session usually creates).
4865
4927
  *
4928
+ * The exclusions are pushed down as pathspecs (`:(exclude)out`) rather than
4929
+ * filtered after the fact, so those paths never cross the wire and never enter
4930
+ * the 500-row cap. Measured on a tree with 3000 build outputs + 300 sources:
4931
+ * 3300 records / 61.5 KB unfiltered versus 300 records / 6.8 KB with two
4932
+ * exclusions — the walk itself costs the same either way (git still descends
4933
+ * those directories), so the win is wire bytes, parse time and the read budget,
4934
+ * not scan latency.
4935
+ *
4866
4936
  * @param root - remote absolute POSIX directory (the session cwd).
4937
+ * @param excludeDirs - directory names to leave out (see {@link excludeDirNames}).
4867
4938
  * @returns a `sh` script printing NUL-separated paths.
4868
4939
  */
4869
- function untrackedCommand(root) {
4870
- return [cdLine(root), "git ls-files --others --exclude-standard -z -- ."].join("\n");
4940
+ function untrackedCommand(root, excludeDirs = []) {
4941
+ const pathspec = [
4942
+ "--",
4943
+ ".",
4944
+ ...excludeDirNames(excludeDirs).map((name) => shq(`:(exclude)${name}`))
4945
+ ].join(" ");
4946
+ return [cdLine(root), `git ls-files --others --exclude-standard -z ${pathspec}`].join("\n");
4871
4947
  }
4872
4948
  /**
4873
4949
  * Parse `git status --porcelain -z -uno` output.
@@ -5518,6 +5594,44 @@ function lastLineOfSide(lines, tag) {
5518
5594
  }
5519
5595
  return -1;
5520
5596
  }
5597
+ /**
5598
+ * Serialize a WHOLE file comparison as ONE patch (one header, every hunk).
5599
+ *
5600
+ * "Revert everything this session did to this file" is `git apply -R` of the
5601
+ * file's complete diff, and that is a single write instead of one write per
5602
+ * hunk. Concatenating `hunkPatch` output would also apply (git tolerates the
5603
+ * repeated headers and re-anchors each block by offset), but it says the same
5604
+ * file begins twice and depends on offset guessing — a real unified diff names
5605
+ * the file once and lets git place every hunk against one picture.
5606
+ *
5607
+ * Verified against git 2.x: the result reverse-applies to a file whose content
5608
+ * is `hunks`' new side, and leaves it byte-identical to the old side.
5609
+ *
5610
+ * @param displayPath - repo-relative path, as the panel shows it.
5611
+ * @param hunks - every hunk of the comparison, in ascending order.
5612
+ * @returns the patch, or '' when there is nothing to write (no hunks).
5613
+ */
5614
+ function filePatch(displayPath, hunks) {
5615
+ if (hunks.length === 0) return "";
5616
+ const out = [`--- a/${displayPath}`, `+++ b/${displayPath}`];
5617
+ for (const hunk of hunks) {
5618
+ out.push(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
5619
+ const markers = /* @__PURE__ */ new Set();
5620
+ if (hunk.oldNoEol === true) {
5621
+ const at = lastLineOfSide(hunk.lines, "-");
5622
+ if (at >= 0) markers.add(at);
5623
+ }
5624
+ if (hunk.newNoEol === true) {
5625
+ const at = lastLineOfSide(hunk.lines, "+");
5626
+ if (at >= 0) markers.add(at);
5627
+ }
5628
+ for (let index = 0; index < hunk.lines.length; index += 1) {
5629
+ out.push(hunk.lines[index] ?? "");
5630
+ if (markers.has(index)) out.push("\");
5631
+ }
5632
+ }
5633
+ return `${out.join("\n")}\n`;
5634
+ }
5521
5635
  //#endregion
5522
5636
  //#region src/changes/recorder.ts
5523
5637
  /**
@@ -5533,6 +5647,20 @@ function panelStatus(status) {
5533
5647
  const WATCHDOG_GRACE_MS = 5e3;
5534
5648
  /** Sentinel for "the host call never came back". */
5535
5649
  const WATCHDOG_FIRED = "watchdog-fired";
5650
+ /**
5651
+ * Per-file budget for the ONE read a click asks for (`diff`).
5652
+ *
5653
+ * A scan compares hundreds of paths and stays at 256 KiB; a single file the user
5654
+ * asked to review is a different trade — 2 MiB is enough for the large sources
5655
+ * a monorepo carries while keeping the base64 reply (≈2.7 MB) inside what one
5656
+ * exec comfortably returns.
5657
+ */
5658
+ const DIFF_MAX_FILE_BYTES = 2 * 1024 * 1024;
5659
+ /** The single-file read budget, as `readPaths` wants it. */
5660
+ const DIFF_LIMITS = {
5661
+ perFile: DIFF_MAX_FILE_BYTES,
5662
+ total: DIFF_MAX_FILE_BYTES
5663
+ };
5536
5664
  /** POSIX join — `node:path` would apply Windows semantics on the host. */
5537
5665
  function posixJoin(base, rel) {
5538
5666
  if (rel.startsWith("/")) return rel;
@@ -5582,6 +5710,7 @@ var SessionChanges = class {
5582
5710
  const ledger = this.ledgers.get(sessionId);
5583
5711
  if (ledger === void 0) return null;
5584
5712
  const unavailable = ledger.unavailable ?? (ledger.untrackedFailure === void 0 ? void 0 : `new-file scan unavailable: ${ledger.untrackedFailure} (use the refresh button to retry)`);
5713
+ const excludedDirs = this.excludedDirs();
5585
5714
  return {
5586
5715
  alias: ledger.alias,
5587
5716
  root: ledger.root,
@@ -5590,6 +5719,7 @@ var SessionChanges = class {
5590
5719
  added: ledger.added,
5591
5720
  deleted: ledger.deleted,
5592
5721
  at: ledger.at,
5722
+ ...excludedDirs.length === 0 ? {} : { excludedDirs },
5593
5723
  pending: ledger.untrackedJob !== void 0 || ledger.pending && ledger.files.length > 0,
5594
5724
  ...ledger.truncated === true ? { truncated: true } : {},
5595
5725
  ...unavailable === void 0 ? {} : { unavailable }
@@ -5604,6 +5734,14 @@ var SessionChanges = class {
5604
5734
  * change the file between scans, and replaying a cached copy against a fresh
5605
5735
  * buffer is exactly how the painted lines end up at the wrong places.
5606
5736
  *
5737
+ * This is the ONE read a user asks for by clicking a row, so it is allowed a
5738
+ * larger per-file budget than a scan (`DIFF_MAX_FILE_BYTES`): a file the list
5739
+ * had to withhold as "too large" can still be reviewed and reverted here,
5740
+ * while a scan stays cheap. A withheld HEAD side is retaken at that budget
5741
+ * (git has the bytes); a withheld BASELINE side is not — that snapshot
5742
+ * described the session's own starting point and cannot be reconstructed, so
5743
+ * the file stays display-only rather than guessing a wrong reverse.
5744
+ *
5607
5745
  * @param sessionId - live session owning the ledger.
5608
5746
  * @param path - the file's remote absolute path (as listed in the summary).
5609
5747
  * @returns hunks for decorations, or null when the session/file is unknown.
@@ -5617,7 +5755,7 @@ var SessionChanges = class {
5617
5755
  let afterText = record.after;
5618
5756
  let binary = record.binary;
5619
5757
  let truncated = record.truncated;
5620
- const fresh = await this.readPaths(ledger, [record.display], "worktree");
5758
+ const fresh = await this.readPaths(ledger, [record.display], "worktree", DIFF_LIMITS);
5621
5759
  if (ledger.disposed) return null;
5622
5760
  const side = fresh.get(record.display);
5623
5761
  if (side !== void 0) {
@@ -5633,14 +5771,30 @@ var SessionChanges = class {
5633
5771
  hunks: [],
5634
5772
  ...status === void 0 ? {} : { status }
5635
5773
  };
5636
- const hunks = diffText(record.before ?? "", afterText ?? "").hunks.map((hunk) => ({
5774
+ let beforeText = record.before;
5775
+ if (beforeText === null && record.beforeFrom === "head") {
5776
+ const head = await this.readPaths(ledger, [record.display], "head", DIFF_LIMITS);
5777
+ if (ledger.disposed) return null;
5778
+ beforeText = head.get(record.display)?.text ?? null;
5779
+ }
5780
+ const result = diffText(beforeText ?? "", afterText ?? "");
5781
+ /**
5782
+ * The reverse patch exists only when the comparison is complete and has an
5783
+ * old side. A whole-file creation has no old side: its reverse is "delete the
5784
+ * file", which a patch cannot express (the client uses
5785
+ * `RemoteChangedFile.revert` for that case instead). Withheld bytes are not
5786
+ * evidence either, so a truncated after side gets no patch — the client's
5787
+ * undo path then refuses (`changes.undoMissing`) instead of guessing.
5788
+ */
5789
+ const reverse = beforeText !== null && !truncated ? filePatch(record.display, result.hunks) : "";
5790
+ const hunks = result.hunks.map((hunk) => ({
5637
5791
  oldStart: hunk.oldStart,
5638
5792
  oldCount: hunk.oldLines,
5639
5793
  newStart: hunk.newStart,
5640
5794
  newCount: hunk.newLines,
5641
5795
  heading: "",
5642
5796
  lines: hunk.lines,
5643
- patch: record.undoable ? hunkPatch(record.display, hunk) : ""
5797
+ patch: reverse === "" ? "" : hunkPatch(record.display, hunk)
5644
5798
  }));
5645
5799
  if (hunks.length === 0) return {
5646
5800
  kind: "missing",
@@ -5654,6 +5808,7 @@ var SessionChanges = class {
5654
5808
  path,
5655
5809
  display: record.display,
5656
5810
  hunks,
5811
+ ...reverse === "" ? {} : { patch: reverse },
5657
5812
  ...status === void 0 ? {} : { status },
5658
5813
  ...truncated ? { truncated: true } : {}
5659
5814
  };
@@ -5922,7 +6077,9 @@ var SessionChanges = class {
5922
6077
  let added = 0;
5923
6078
  let deleted = 0;
5924
6079
  for (const entry of listed) {
5925
- const beforeSide = baseline.get(entry.path) ?? head.get(entry.path);
6080
+ const fromBaseline = baseline.get(entry.path);
6081
+ const fromHead = head.get(entry.path);
6082
+ const beforeSide = fromBaseline ?? fromHead;
5926
6083
  const afterSide = after.get(entry.path);
5927
6084
  const before = beforeSide?.text ?? null;
5928
6085
  const afterText = afterSide?.text ?? null;
@@ -5932,7 +6089,7 @@ var SessionChanges = class {
5932
6089
  if (!binary && !fileTruncated && before === afterText) continue;
5933
6090
  if ((binary || fileTruncated) && sameStat(beforeSide, afterSide)) continue;
5934
6091
  const oversized = fileTruncated && !binary;
5935
- const undoable = !binary && !oversized && beforeSide !== void 0 && !(before === null);
6092
+ const revert = !binary && !oversized && beforeSide !== void 0 && !(before === null) ? "patch" : entry.status === "A" ? "delete" : void 0;
5936
6093
  const diff = binary || oversized ? {
5937
6094
  added: 0,
5938
6095
  deleted: 0
@@ -5947,7 +6104,7 @@ var SessionChanges = class {
5947
6104
  after: afterText,
5948
6105
  binary,
5949
6106
  truncated: fileTruncated,
5950
- undoable
6107
+ beforeFrom: fromBaseline !== void 0 ? "baseline" : fromHead !== void 0 ? "head" : "none"
5951
6108
  });
5952
6109
  added += diff.added;
5953
6110
  deleted += diff.deleted;
@@ -5958,7 +6115,8 @@ var SessionChanges = class {
5958
6115
  deleted: diff.deleted,
5959
6116
  ...binary ? { binary: true } : {},
5960
6117
  ...oversized ? { oversized: true } : {},
5961
- ...status === void 0 ? {} : { status }
6118
+ ...status === void 0 ? {} : { status },
6119
+ ...revert === void 0 ? {} : { revert }
5962
6120
  });
5963
6121
  }
5964
6122
  files.sort((left, right) => left.display.localeCompare(right.display));
@@ -6077,7 +6235,7 @@ var SessionChanges = class {
6077
6235
  ledger.untrackedAt = Date.now();
6078
6236
  ledger.untrackedJob = (async () => {
6079
6237
  const started = Date.now();
6080
- const scan = await this.run(ledger.alias, untrackedCommand(root), this.untrackedBudget());
6238
+ const scan = await this.run(ledger.alias, untrackedCommand(root, this.excludedDirs()), this.untrackedBudget());
6081
6239
  ledger.untrackedMs = Date.now() - started;
6082
6240
  if (ledger.disposed) return;
6083
6241
  if (ledger.root !== root) return;
@@ -6159,10 +6317,10 @@ var SessionChanges = class {
6159
6317
  }
6160
6318
  }
6161
6319
  /** Read a batch of files, capped per file and in total. */
6162
- async readPaths(ledger, paths, side) {
6320
+ async readPaths(ledger, paths, side, limits) {
6163
6321
  if (paths.length === 0) return /* @__PURE__ */ new Map();
6164
- const perFile = this.deps.maxFileBytes ?? 256 * 1024;
6165
- const total = this.deps.maxTotalBytes ?? 8 * 1024 * 1024;
6322
+ const perFile = limits?.perFile ?? this.deps.maxFileBytes ?? 256 * 1024;
6323
+ const total = limits?.total ?? this.deps.maxTotalBytes ?? 8 * 1024 * 1024;
6166
6324
  const command = side === "worktree" ? readWorktreeCommand(ledger.root, paths, perFile, total) : readHeadCommand(ledger.root, paths, perFile, total);
6167
6325
  const result = await this.run(ledger.alias, command);
6168
6326
  if (!result.ok) {
@@ -6225,6 +6383,15 @@ var SessionChanges = class {
6225
6383
  untrackedBudget() {
6226
6384
  return this.deps.untrackedBudgetMs ?? this.budget(this.deps.timeouts().gitMs, 1e4, 18e4);
6227
6385
  }
6386
+ /**
6387
+ * The exclusions this ledger scans with, normalized once per call.
6388
+ *
6389
+ * `??` and not `||`: an explicit empty array is a caller saying "count
6390
+ * everything", which must stay distinguishable from "not configured".
6391
+ */
6392
+ excludedDirs() {
6393
+ return excludeDirNames(this.deps.excludeDirs ?? UNTRACKED_EXCLUDED_DIRECTORIES);
6394
+ }
6228
6395
  budget(configured, floor, ceiling) {
6229
6396
  return Math.max(floor, Math.min(Number.isFinite(configured) && configured > 0 ? configured : 3e4, ceiling));
6230
6397
  }
@@ -55,6 +55,12 @@ export interface SessionChangesDeps {
55
55
  untrackedBudgetMs?: number;
56
56
  /** How often the untracked scan may run again (default five seconds). */
57
57
  untrackedRefreshMs?: number;
58
+ /**
59
+ * Directory names the untracked scan leaves out (build output, dependency
60
+ * caches). Defaults to {@link UNTRACKED_EXCLUDED_DIRECTORIES}; an explicit
61
+ * empty array turns the exclusion off.
62
+ */
63
+ excludeDirs?: readonly string[];
58
64
  /**
59
65
  * Override the per-exec budget outright.
60
66
  *
@@ -84,6 +90,14 @@ export declare class SessionChanges {
84
90
  * change the file between scans, and replaying a cached copy against a fresh
85
91
  * buffer is exactly how the painted lines end up at the wrong places.
86
92
  *
93
+ * This is the ONE read a user asks for by clicking a row, so it is allowed a
94
+ * larger per-file budget than a scan (`DIFF_MAX_FILE_BYTES`): a file the list
95
+ * had to withhold as "too large" can still be reviewed and reverted here,
96
+ * while a scan stays cheap. A withheld HEAD side is retaken at that budget
97
+ * (git has the bytes); a withheld BASELINE side is not — that snapshot
98
+ * described the session's own starting point and cannot be reconstructed, so
99
+ * the file stays display-only rather than guessing a wrong reverse.
100
+ *
87
101
  * @param sessionId - live session owning the ledger.
88
102
  * @param path - the file's remote absolute path (as listed in the summary).
89
103
  * @returns hunks for decorations, or null when the session/file is unknown.
@@ -267,6 +281,13 @@ export declare class SessionChanges {
267
281
  * command are visible ONLY through this scan.
268
282
  */
269
283
  private untrackedBudget;
284
+ /**
285
+ * The exclusions this ledger scans with, normalized once per call.
286
+ *
287
+ * `??` and not `||`: an explicit empty array is a caller saying "count
288
+ * everything", which must stay distinguishable from "not configured".
289
+ */
290
+ private excludedDirs;
270
291
  private budget;
271
292
  private warn;
272
293
  }
@@ -109,13 +109,53 @@ export declare const READ_EXIT: {
109
109
  * @returns a `sh` script printing NUL-separated porcelain v1 records.
110
110
  */
111
111
  export declare function trackedStatusCommand(root: string): string;
112
+ /**
113
+ * Directory names the ledger does not count as session changes.
114
+ *
115
+ * Build output and dependency caches are the two things a build leaves behind,
116
+ * and neither is this session's work. `--exclude-standard` only covers what the
117
+ * repository's own ignore rules name, so a checkout whose build directory is NOT
118
+ * ignored pays twice: thousands of paths fill the 500-row list (sorted, and
119
+ * `build/`/`out/` sort BEFORE `src/`, so the real changes get truncated away) and
120
+ * every listed path costs a read out of the 8 MiB transfer budget.
121
+ *
122
+ * The names mirror the three lists the plugin already prunes by elsewhere
123
+ * (`client/quickopen-model.ts` `EXCLUDED_DIRECTORIES`, `p2/file-refs.ts`
124
+ * `REMOTE_FILE_SEARCH_EXCLUDED_DIRECTORIES`, `search-ops.ts` `PRUNE_DIRS`). One
125
+ * vocabulary, four consumers: fold them into a shared module when one of those
126
+ * surfaces is next touched, instead of adding a fifth spelling here.
127
+ */
128
+ export declare const UNTRACKED_EXCLUDED_DIRECTORIES: readonly string[];
129
+ /**
130
+ * Keep only directory names a pathspec may name safely.
131
+ *
132
+ * A value that is absolute, carries a separator, walks up or looks like a flag
133
+ * is DROPPED rather than rejected: the list is configuration, and one bad entry
134
+ * must not stop the scan — the scan's job is to say what changed, not to police
135
+ * a setting. Dropping is also the conservative direction: a name that is not
136
+ * excluded is merely visible, while a malformed pathspec would hide paths the
137
+ * user never asked to hide (or turn `--exclude` into another flag).
138
+ *
139
+ * @param dirs - candidate names (undefined = none).
140
+ * @returns the usable names, deduplicated, in the given order.
141
+ */
142
+ export declare function excludeDirNames(dirs: readonly string[] | undefined): string[];
112
143
  /**
113
144
  * New files git is not tracking yet (the ones a session usually creates).
114
145
  *
146
+ * The exclusions are pushed down as pathspecs (`:(exclude)out`) rather than
147
+ * filtered after the fact, so those paths never cross the wire and never enter
148
+ * the 500-row cap. Measured on a tree with 3000 build outputs + 300 sources:
149
+ * 3300 records / 61.5 KB unfiltered versus 300 records / 6.8 KB with two
150
+ * exclusions — the walk itself costs the same either way (git still descends
151
+ * those directories), so the win is wire bytes, parse time and the read budget,
152
+ * not scan latency.
153
+ *
115
154
  * @param root - remote absolute POSIX directory (the session cwd).
155
+ * @param excludeDirs - directory names to leave out (see {@link excludeDirNames}).
116
156
  * @returns a `sh` script printing NUL-separated paths.
117
157
  */
118
- export declare function untrackedCommand(root: string): string;
158
+ export declare function untrackedCommand(root: string, excludeDirs?: readonly string[]): string;
119
159
  /**
120
160
  * Parse `git status --porcelain -z -uno` output.
121
161
  *
@@ -63,3 +63,21 @@ export declare function diffText(before: string, after: string, context?: number
63
63
  * @param hunk - one hunk of {@link diffText}.
64
64
  */
65
65
  export declare function hunkPatch(displayPath: string, hunk: TextHunk): string;
66
+ /**
67
+ * Serialize a WHOLE file comparison as ONE patch (one header, every hunk).
68
+ *
69
+ * "Revert everything this session did to this file" is `git apply -R` of the
70
+ * file's complete diff, and that is a single write instead of one write per
71
+ * hunk. Concatenating `hunkPatch` output would also apply (git tolerates the
72
+ * repeated headers and re-anchors each block by offset), but it says the same
73
+ * file begins twice and depends on offset guessing — a real unified diff names
74
+ * the file once and lets git place every hunk against one picture.
75
+ *
76
+ * Verified against git 2.x: the result reverse-applies to a file whose content
77
+ * is `hunks`' new side, and leaves it byte-identical to the old side.
78
+ *
79
+ * @param displayPath - repo-relative path, as the panel shows it.
80
+ * @param hunks - every hunk of the comparison, in ascending order.
81
+ * @returns the patch, or '' when there is nothing to write (no hunks).
82
+ */
83
+ export declare function filePatch(displayPath: string, hunks: readonly TextHunk[]): string;
@@ -18,4 +18,6 @@ export declare function XTerm(props: {
18
18
  * which correctly re-runs the line.
19
19
  */
20
20
  initialInput?: string;
21
+ /** Translator for the right-click menu (copy / paste / select all). */
22
+ t: (key: string) => string;
21
23
  }): ReactNode;
@@ -12,8 +12,15 @@
12
12
  * written with `node:fs`), which the probe measured as 58 remote sessions with
13
13
  * zero change events.
14
14
  *
15
- * Clicking a row opens the file in the remote editor and hands the editor the
16
- * same hunks, so the changed lines are painted in place.
15
+ * Three things happen here, and they are deliberately different in kind:
16
+ * - a row's LEFT click opens the file and hands the editor the same hunks, so the
17
+ * changed lines are painted in place;
18
+ * - a row's RIGHT click offers the writes ("revert everything this session did to
19
+ * this file", "undo a tracked creation") plus the navigation shortcuts. The
20
+ * host decides which of those exist (`RemoteChangedFile.revert`), because only
21
+ * git knows whether a creation has a copy to fall back on;
22
+ * - the ✓ on a row is a LOCAL review note (`review-state.ts`): it writes nothing,
23
+ * it is what makes a thirty-file refactor converge.
17
24
  */
18
25
  import './changes.css';
19
26
  /**
@@ -31,6 +31,8 @@ export declare const EMPTY_CHANGE_SET: ChangeSet;
31
31
  *
32
32
  * @param hunks - served hunks for the whole session.
33
33
  * @param stamp - identity of the comparison (file + baseline + turn).
34
+ * @param filePatch - the host's whole-file reverse patch, when it served one
35
+ * (see `ChangeSet.filePatch`); '' / missing = nothing to revert as a whole.
34
36
  * @returns the mark set the editor paints, or {@link EMPTY_CHANGE_SET}.
35
37
  */
36
- export declare function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string): ChangeSet;
38
+ export declare function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string, filePatch?: string): ChangeSet;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 「这个文件我看过了」的本地标记。
3
+ *
4
+ * 会话改动面板原本只能看、不能收敛:一次三十个文件的重构,没有任何地方记得"这个我
5
+ * 已经审过",列表和游标每次都从头上开始。这里补的是**纯客户端**的审阅状态 —— 它不
6
+ * 写远端、不进账本、不影响任何一次 `git` 调用,因此是这条路线上唯一零风险的收敛手段
7
+ * ("接受改动"的另一半语义是真正的 `git apply --cached`,那要求基线等于索引,属于另一
8
+ * 个决定,**不在本模块**里)。
9
+ *
10
+ * ## 为什么键里带计数
11
+ *
12
+ * 键 = 路径 + 增删行数 + 状态。会话又改了同一批行(行数随之变化)时,旧标记自然失效,
13
+ * 文件重新变成"未审阅"——这正是想要的效果,而且不需要监听任何事件。行数完全没变的
14
+ * 二次编辑仍会被当成"已审阅",这是这套方案的已知盲点:它与"审阅的是哪一版"这个事实
15
+ * 相比,代价远小于为每个文件拉一次 diff 去算指纹。
16
+ *
17
+ * 纯函数 + 一个带上限的表,`scripts/check-review-state.mjs` 直接驱动真实的判定。
18
+ */
19
+ /** 面板能给的一行(`RemoteChangedFile` 的投影)。 */
20
+ export interface ReviewSubject {
21
+ /** 远端绝对路径(唯一标识)。 */
22
+ path: string;
23
+ added: number;
24
+ deleted: number;
25
+ status?: string;
26
+ }
27
+ /** 已审阅集合:键 → 1(用对象是为了能直接 JSON 往返)。 */
28
+ export type ReviewedMap = Readonly<Record<string, 1>>;
29
+ /** 一个会话最多记住这么多条(长命页面不能无限长)。 */
30
+ export declare const REVIEW_CAP = 1000;
31
+ /**
32
+ * 一行的审阅键。
33
+ *
34
+ * 计数进键里是刻意的:见文件头。`status` 也进键,因为"删掉了又加回来"和"一直在改"
35
+ * 是两件不同的事,标签变了就该重新看一遍。
36
+ *
37
+ * @param file - 面板的一行。
38
+ * @returns 稳定的键(路径里可能有任意字符,用 NUL 分隔不会与计数撞)。
39
+ */
40
+ export declare function reviewKeyOf(file: ReviewSubject): string;
41
+ /** 这一行是否已被标为审阅。 */
42
+ export declare function isReviewed(file: ReviewSubject, reviewed: ReviewedMap): boolean;
43
+ /** 已审阅的行数(只数当前列表里的,所以它永远 ≤ 列表长度)。 */
44
+ export declare function reviewedCount(files: readonly ReviewSubject[], reviewed: ReviewedMap): number;
45
+ /** 切换一行的标记,返回新表(输入不被修改)。 */
46
+ export declare function toggleReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap, file: ReviewSubject): Record<string, 1>;
47
+ /** 全标或全清。 */
48
+ export declare function setAllReviewed(files: readonly ReviewSubject[], on: boolean): Record<string, 1>;
49
+ /**
50
+ * 丢掉不属于当前列表的键。
51
+ *
52
+ * 列表每 3 秒重建一次,一条被删掉(或计数变了)的键如果留着,下次同一路径回到列表
53
+ * 时会被当成"已审阅"——那是凭空出现的勾。清理放在每次写入与每次加载后都做,代价是
54
+ * O(列表长度)。
55
+ */
56
+ export declare function pruneReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap): Record<string, 1>;
57
+ /**
58
+ * 解析持久化的一串 JSON。
59
+ *
60
+ * 任何畸形输入都给空表而不是抛错:这份状态是"看过没看过",读不出来最多重看一遍,
61
+ * 不值得让面板崩掉。键必须是字符串、值必须是 1,且受 {@link REVIEW_CAP} 限制。
62
+ *
63
+ * @param raw - `localStorage` 里存着的那串文本(可能为 null)。
64
+ */
65
+ export declare function parseReviewed(raw: string | null | undefined): Record<string, 1>;
66
+ /** 序列化(键数量已受上限约束,所以这串不会无限长)。 */
67
+ export declare function serializeReviewed(reviewed: ReviewedMap): string;
@@ -11,7 +11,7 @@
11
11
  * them here keeps the check meaningful in both directions: every entry must
12
12
  * exist in both dictionaries, and nothing else may be unreferenced.
13
13
  */
14
- export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd"];
14
+ export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "term.copy", "term.paste", "term.selectAll", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd"];
15
15
  export type Lang = 'zh' | 'en';
16
16
  export declare function detectLang(): Lang;
17
17
  export declare function makeT(lang: Lang): (key: string) => string;
@@ -290,6 +290,12 @@ export interface ExplorerValue {
290
290
  * `changeSet.marks`,`hunk` 是 `patches` 的下标)。
291
291
  */
292
292
  undoChange: (tabId: string, mark: ChangeMark) => Promise<void>;
293
+ /**
294
+ * 撤销本会话对某个文件的**全部**改动(改动面板那一行的动作)。
295
+ *
296
+ * @returns 远端是否真的写了(`false` = 被某道门拒了,文件未变)。
297
+ */
298
+ revertFileChanges: (target: RevertFileTarget) => Promise<boolean>;
293
299
  /**
294
300
  * Write one file tab back to the remote host.
295
301
  * @returns true only when the write really succeeded — the caller uses it to
@@ -765,5 +771,50 @@ export declare function gotoChange(tabId: string, dir: 1 | -1): number | undefin
765
771
  */
766
772
  export declare function markChangeStale(tabId: string): void;
767
773
  export declare function undoChange(tabId: string, mark: ChangeMark): Promise<void>;
774
+ /**
775
+ * Coordinates for "undo everything this session did to this file".
776
+ *
777
+ * Handed over by the change panel, which is the only surface that knows both the
778
+ * file and the session it belongs to. `mode` comes from the HOST
779
+ * (`RemoteChangedFile.revert`), never from the client: only git can say whether a
780
+ * creation has a copy to fall back on.
781
+ */
782
+ export interface RevertFileTarget {
783
+ sessionId: string;
784
+ bindingId: string;
785
+ alias: string;
786
+ root: string;
787
+ path: string;
788
+ display: string;
789
+ mode: 'patch' | 'delete';
790
+ }
791
+ /**
792
+ * Revert one file's WHOLE session change set (the panel row's action).
793
+ *
794
+ * Three things make this a separate path from `undoChange`, and each one is
795
+ * load-bearing:
796
+ *
797
+ * 1. **It works without an open tab.** The panel lists files nobody opened, so
798
+ * the coordinates cannot come from `undoContext()` (which describes the tab on
799
+ * screen). They arrive with the call and are validated by the SAME rules
800
+ * (`resolveUndoTarget`: session agreement, binding identity, path under the
801
+ * ledger root) — a row from another conversation, or from a sibling binding
802
+ * that happens to share the alias, is refused rather than guessed.
803
+ * 2. **It is ONE remote write.** The host serves the file as a single patch, which
804
+ * is exactly what `git apply -R` needs to restore the session baseline; a loop
805
+ * of per-hunk applies would shift every later hunk and report a conflict
806
+ * halfway through, leaving the file half reverted.
807
+ * 3. **A creation is not a patch.** `mode: 'delete'` (a tracked addition, where
808
+ * git still holds the bytes) deletes the file behind an explicit confirmation;
809
+ * an untracked creation never reaches here, because the host offers no mode
810
+ * for it.
811
+ *
812
+ * The order of the gates is the one `undoChange` established: an unsaved buffer
813
+ * refuses first (a remote write must never overwrite what the user has not
814
+ * saved), then the offline check, then the coordinates, then the patch.
815
+ *
816
+ * @returns whether the remote was actually written.
817
+ */
818
+ export declare function revertFileChanges(target: RevertFileTarget): Promise<boolean>;
768
819
  /** Mount-time hook: boot the store for a given ctx. */
769
820
  export declare function useBootstrap(ctx: Context): void;
@@ -54,6 +54,14 @@ export interface RemovedChip {
54
54
  truncated: boolean;
55
55
  /** 这个 chip 落在哪一行(1-based)。**省略 = 所属 mark 的 `from` 行**。 */
56
56
  line?: number;
57
+ /**
58
+ * 这个 chip 代表的**被删行数**(省略或 1 = 单行/行内片段)。
59
+ *
60
+ * 一个整块删除(例如删掉 10 行)不能画成 10 个 chip 叠在同一列上 —— 那既读不出
61
+ * "删了 10 行",也读不出内容。此时 `count > 1`,`text` 改为携带**预览**(前若干
62
+ * 行的原文,供 tooltip),渲染成一个 `−N 行已删除` 的可读胶囊。
63
+ */
64
+ count?: number;
57
65
  }
58
66
  /**
59
67
  * 一处改动:**1-based、闭区间**的行号。
@@ -95,6 +103,15 @@ export interface ChangeSet {
95
103
  * 护栏,比在浏览器里重算一遍替换区间可靠。
96
104
  */
97
105
  patches?: string[];
106
+ /**
107
+ * 整文件的补丁(一个文件头 + 全部 hunk),用于"撤销该文件的全部改动"。
108
+ *
109
+ * 一次远端写而不是逐 hunk 循环:后者会让后面每个 hunk 的行号整体错位,撤到一半
110
+ * 报冲突,文件就停在半截状态。补丁由 Host 生成(浏览器一侧没有基线内容,自己拼
111
+ * 出来的补丁只会把别人的改动一起盖掉)。省略 = 这个文件没有可整体撤销的补丁
112
+ * (新建 / 二进制 / 字节被上限扣下)。
113
+ */
114
+ filePatch?: string;
98
115
  }
99
116
  /** 换一份改动标记;`null` = 清空(有改动数据,但没有任何要画的东西)。 */
100
117
  export declare const setChangeSet: import("@codemirror/state").StateEffectType<ChangeSet | null>;
@@ -195,6 +195,15 @@ export declare function ContextMenu(props: {
195
195
  y: number;
196
196
  entries: MenuEntry[];
197
197
  onClose: () => void;
198
+ /**
199
+ * Extra class on the menu box, for a surface that lives OUTSIDE `.rvs-root`.
200
+ *
201
+ * The menu is portalled to `document.body`, so the `--rvs-*` variables defined
202
+ * on the root never reach it: an outside surface (the change panel above the
203
+ * composer) supplies its own palette through this hook instead of forking the
204
+ * component.
205
+ */
206
+ className?: string;
198
207
  }): ReactNode;
199
208
  /** Hook: context-menu state + the handler that opens it. */
200
209
  export declare function useContextMenu(): {