@indigoai-us/hq-cloud 6.18.107 → 6.18.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/bin/sync-runner-company.d.ts +1 -0
  2. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  3. package/dist/bin/sync-runner-company.js +29 -8
  4. package/dist/bin/sync-runner-company.js.map +1 -1
  5. package/dist/bin/sync-runner-manifest.d.ts +27 -0
  6. package/dist/bin/sync-runner-manifest.d.ts.map +1 -1
  7. package/dist/bin/sync-runner-manifest.js +104 -0
  8. package/dist/bin/sync-runner-manifest.js.map +1 -1
  9. package/dist/bin/sync-runner-planning.d.ts +48 -0
  10. package/dist/bin/sync-runner-planning.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-planning.js +140 -0
  12. package/dist/bin/sync-runner-planning.js.map +1 -1
  13. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  14. package/dist/bin/sync-runner-watch-loop.js +8 -2
  15. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  16. package/dist/bin/sync-runner.d.ts +1 -0
  17. package/dist/bin/sync-runner.d.ts.map +1 -1
  18. package/dist/bin/sync-runner.js +24 -1
  19. package/dist/bin/sync-runner.js.map +1 -1
  20. package/dist/cli/rescue-core.d.ts +64 -1
  21. package/dist/cli/rescue-core.d.ts.map +1 -1
  22. package/dist/cli/rescue-core.js +272 -125
  23. package/dist/cli/rescue-core.js.map +1 -1
  24. package/dist/cli/rescue-git.d.ts +47 -0
  25. package/dist/cli/rescue-git.d.ts.map +1 -0
  26. package/dist/cli/rescue-git.js +126 -0
  27. package/dist/cli/rescue-git.js.map +1 -0
  28. package/dist/cli/rescue-native-copy.d.ts +88 -0
  29. package/dist/cli/rescue-native-copy.d.ts.map +1 -0
  30. package/dist/cli/rescue-native-copy.js +823 -0
  31. package/dist/cli/rescue-native-copy.js.map +1 -0
  32. package/dist/cli/rescue-snapshot.d.ts +22 -0
  33. package/dist/cli/rescue-snapshot.d.ts.map +1 -1
  34. package/dist/cli/rescue-snapshot.js +27 -0
  35. package/dist/cli/rescue-snapshot.js.map +1 -1
  36. package/dist/cli/rescue.d.ts +21 -1
  37. package/dist/cli/rescue.d.ts.map +1 -1
  38. package/dist/cli/rescue.js +68 -2
  39. package/dist/cli/rescue.js.map +1 -1
  40. package/dist/cli/share.d.ts +14 -0
  41. package/dist/cli/share.d.ts.map +1 -1
  42. package/dist/cli/share.js +19 -8
  43. package/dist/cli/share.js.map +1 -1
  44. package/dist/cli/sync.d.ts +8 -0
  45. package/dist/cli/sync.d.ts.map +1 -1
  46. package/dist/cli/sync.js +5 -5
  47. package/dist/cli/sync.js.map +1 -1
  48. package/dist/cognito-auth.d.ts +57 -0
  49. package/dist/cognito-auth.d.ts.map +1 -1
  50. package/dist/cognito-auth.js +182 -3
  51. package/dist/cognito-auth.js.map +1 -1
  52. package/dist/ignore.d.ts +5 -1
  53. package/dist/ignore.d.ts.map +1 -1
  54. package/dist/ignore.js +32 -2
  55. package/dist/ignore.js.map +1 -1
  56. package/dist/index.d.ts +3 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +6 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/manifest/leg-skip-store.d.ts +59 -0
  61. package/dist/manifest/leg-skip-store.d.ts.map +1 -0
  62. package/dist/manifest/leg-skip-store.js +140 -0
  63. package/dist/manifest/leg-skip-store.js.map +1 -0
  64. package/dist/manifest/upload-manifest.d.ts +11 -0
  65. package/dist/manifest/upload-manifest.d.ts.map +1 -1
  66. package/dist/manifest/upload-manifest.js +30 -1
  67. package/dist/manifest/upload-manifest.js.map +1 -1
  68. package/dist/manifest-folder-alias.d.ts +70 -0
  69. package/dist/manifest-folder-alias.d.ts.map +1 -0
  70. package/dist/manifest-folder-alias.js +139 -0
  71. package/dist/manifest-folder-alias.js.map +1 -0
  72. package/dist/manifest-reconcile.d.ts +5 -0
  73. package/dist/manifest-reconcile.d.ts.map +1 -1
  74. package/dist/manifest-reconcile.js +14 -2
  75. package/dist/manifest-reconcile.js.map +1 -1
  76. package/dist/outposts/billing.d.ts +0 -2
  77. package/dist/outposts/billing.d.ts.map +1 -1
  78. package/dist/outposts/billing.js +0 -2
  79. package/dist/outposts/billing.js.map +1 -1
  80. package/dist/outposts/cli-billing.d.ts +8 -2
  81. package/dist/outposts/cli-billing.d.ts.map +1 -1
  82. package/dist/outposts/cli-billing.js +13 -8
  83. package/dist/outposts/cli-billing.js.map +1 -1
  84. package/dist/outposts/client.d.ts +6 -3
  85. package/dist/outposts/client.d.ts.map +1 -1
  86. package/dist/outposts/client.js +12 -8
  87. package/dist/outposts/client.js.map +1 -1
  88. package/dist/outposts/command.d.ts +30 -0
  89. package/dist/outposts/command.d.ts.map +1 -1
  90. package/dist/outposts/command.js +79 -13
  91. package/dist/outposts/command.js.map +1 -1
  92. package/dist/outposts/company-outposts.d.ts +2 -2
  93. package/dist/outposts/company-outposts.d.ts.map +1 -1
  94. package/dist/outposts/company-outposts.js +5 -4
  95. package/dist/outposts/company-outposts.js.map +1 -1
  96. package/dist/outposts/hq-pro-routes.d.ts +15 -0
  97. package/dist/outposts/hq-pro-routes.d.ts.map +1 -0
  98. package/dist/outposts/hq-pro-routes.js +21 -0
  99. package/dist/outposts/hq-pro-routes.js.map +1 -0
  100. package/dist/outposts/index.d.ts +3 -1
  101. package/dist/outposts/index.d.ts.map +1 -1
  102. package/dist/outposts/index.js +2 -1
  103. package/dist/outposts/index.js.map +1 -1
  104. package/dist/outposts/sizes.d.ts +56 -0
  105. package/dist/outposts/sizes.d.ts.map +1 -0
  106. package/dist/outposts/sizes.js +120 -0
  107. package/dist/outposts/sizes.js.map +1 -0
  108. package/dist/outposts/types.d.ts +3 -0
  109. package/dist/outposts/types.d.ts.map +1 -1
  110. package/dist/outposts/types.js +0 -11
  111. package/dist/outposts/types.js.map +1 -1
  112. package/dist/sync/pull-scope.d.ts +1 -1
  113. package/dist/sync/pull-scope.d.ts.map +1 -1
  114. package/dist/sync/pull-scope.js +8 -3
  115. package/dist/sync/pull-scope.js.map +1 -1
  116. package/dist/types.d.ts +7 -0
  117. package/dist/types.d.ts.map +1 -1
  118. package/package.json +1 -1
@@ -8,9 +8,11 @@
8
8
  * `git` (clone/checkout/hash-object/cat-file/ls-tree/show/log) and `rsync`
9
9
  * (the overlay) — are still invoked as subprocesses. YAML stamp reads and
10
10
  * writes are handled in-process so a rescue does not depend on optional YAML
11
- * executables being present. Reimplementing git's blob hashing or rsync's
12
- * include/exclude filter engine in pure JS would *increase* the risk of
13
- * behavioural drift, so the port reuses those exact tools and argument vectors.
11
+ * executables being present. Reimplementing git's blob hashing in pure JS
12
+ * would *increase* the risk of behavioural drift, so the port reuses git's
13
+ * exact commands. When rsync is not on PATH (a stock Windows install), the
14
+ * overlay runs the built-in copy in ./rescue-native-copy.ts with the same
15
+ * rsync argument vector; see {@link selectOverlayCopyEngine}.
14
16
  *
15
17
  * Behaviour (classification outcomes, on-disk results, log lines, exit codes)
16
18
  * is preserved 1:1 with the legacy script. See the original script's header in
@@ -34,10 +36,12 @@ import { createRequire } from "node:module";
34
36
  import * as os from "os";
35
37
  import * as path from "path";
36
38
  import yaml from "js-yaml";
37
- import { assertRescuePathTypeUnchanged, isRescueTransientDirectory, } from "./rescue-snapshot.js";
39
+ import { assertRescuePathTypeUnchanged, isRescueTransientDirectory, rescueSnapshotRoots, } from "./rescue-snapshot.js";
38
40
  import { applyBackupPrune, canonicalRootHash, inventoryManagedSnapshots, isManagedSnapshotManifest, } from "../backup-prune.js";
39
41
  import { makeRestoreProbePath, makeRestoreStagePath, } from "../restore-staging.js";
40
42
  import { readCoreSourceStamp, writeCoreSourceStamp } from "./core-source-stamp.js";
43
+ import { rsyncFilterRuleMatches, runNativeOverlay } from "./rescue-native-copy.js";
44
+ import { chooseRescueGit, GIT_VERSION_PROBE_TIMEOUT_MS, gitTooOldMessage, parseGitVersion, pinGitFirstOnPath, RESCUE_MIN_GIT_VERSION, } from "./rescue-git.js";
41
45
  const MAX_CLONE_FILES_PER_BATCH = 200;
42
46
  const MAX_CLONE_BATCH_PATH_BYTES = 64 * 1024;
43
47
  const require = createRequire(import.meta.url);
@@ -132,6 +136,7 @@ function runWithSpawnError(cmd, args, opts = {}) {
132
136
  input: opts.input,
133
137
  encoding: "utf-8",
134
138
  ...(typeof opts.timeout === "number" ? { timeout: opts.timeout } : {}),
139
+ ...(typeof opts.maxBuffer === "number" ? { maxBuffer: opts.maxBuffer } : {}),
135
140
  });
136
141
  return {
137
142
  status: res.status ?? (res.error ? 127 : 1),
@@ -141,6 +146,57 @@ function runWithSpawnError(cmd, args, opts = {}) {
141
146
  signal: res.signal,
142
147
  };
143
148
  }
149
+ export const GIT_BATCH_CHUNK_SIZE = 4096;
150
+ const GIT_BATCH_MAX_BUFFER = 256 * 1024 * 1024;
151
+ export class GitBatchError extends Error {
152
+ args;
153
+ result;
154
+ chunkStart;
155
+ chunkLength;
156
+ constructor(args, result, chunkStart, chunkLength) {
157
+ const detail = result.error?.message ??
158
+ (result.signal ? `killed by ${result.signal}` : `exit ${result.status}`);
159
+ super(`git ${args.join(" ")} failed on inputs ${chunkStart}..${chunkStart + chunkLength - 1}: ${detail}${result.stderr.trim() ? `\n${result.stderr.trim()}` : ""}`);
160
+ this.args = args;
161
+ this.result = result;
162
+ this.chunkStart = chunkStart;
163
+ this.chunkLength = chunkLength;
164
+ }
165
+ }
166
+ /**
167
+ * Feed `inputs` to a line-oriented git batch command and return exactly one
168
+ * output line per input, in order. Inputs are sent in chunks so no single
169
+ * child ever produces more output than spawnSync will buffer, and any chunk
170
+ * that fails (non-zero exit, signal, spawn error, short output) throws instead
171
+ * of returning a partial result.
172
+ */
173
+ export function runGitBatch(args, inputs, opts = {}) {
174
+ const chunkSize = Math.max(1, opts.chunkSize ?? GIT_BATCH_CHUNK_SIZE);
175
+ const lines = [];
176
+ for (let start = 0; start < inputs.length; start += chunkSize) {
177
+ const chunk = inputs.slice(start, start + chunkSize);
178
+ const res = run("git", args, {
179
+ cwd: opts.cwd,
180
+ env: opts.env,
181
+ input: chunk.join("\n") + "\n",
182
+ maxBuffer: GIT_BATCH_MAX_BUFFER,
183
+ });
184
+ if (res.status !== 0 || res.error || res.signal) {
185
+ throw new GitBatchError(args, res, start, chunk.length);
186
+ }
187
+ const out = res.stdout.endsWith("\n") ? res.stdout.slice(0, -1) : res.stdout;
188
+ const got = out === "" ? [] : out.split("\n");
189
+ if (got.length !== chunk.length) {
190
+ throw new GitBatchError(args, {
191
+ ...res,
192
+ stderr: `expected ${chunk.length} output lines, got ${got.length}`,
193
+ }, start, chunk.length);
194
+ }
195
+ for (const line of got)
196
+ lines.push(line);
197
+ }
198
+ return lines;
199
+ }
144
200
  /** Read an environment value without relying on Windows' case-insensitive proxy. */
145
201
  export function envValue(env, name) {
146
202
  for (const [key, value] of Object.entries(env)) {
@@ -489,8 +545,8 @@ function buildRsyncLauncher(candidatePath) {
489
545
  }
490
546
  return { command: "rsync", leadingArgs: [] };
491
547
  }
492
- /** The overlay requires rsync; do not allocate a recovery copy when it cannot run. */
493
- export function requireWorkingRsync(env, err) {
548
+ /** Find rsync on PATH and run `rsync --version` through the overlay's launcher. */
549
+ function probeRsync(env) {
494
550
  const resolvedPath = envValue(env, "PATH");
495
551
  const entries = pathEntries(resolvedPath);
496
552
  const foundRsync = findRsyncOnPath(entries, env);
@@ -499,8 +555,60 @@ export function requireWorkingRsync(env, err) {
499
555
  env,
500
556
  });
501
557
  const output = `${probe.stdout}\n${probe.stderr}`;
502
- if (probe.status === 0 && /\brsync\b.*\bversion\b/i.test(output))
503
- return launcher;
558
+ const working = probe.status === 0 && /\brsync\b.*\bversion\b/i.test(output);
559
+ return { launcher, foundRsync, entries, resolvedPath, probe, output, working };
560
+ }
561
+ /**
562
+ * rsync is absent, not broken: no candidate on PATH and the launch failed
563
+ * with ENOENT. A present but unexecutable, failing, or unrecognised rsync is
564
+ * not "absent" and still stops the rescue.
565
+ */
566
+ function rsyncIsMissing(result) {
567
+ const code = result.probe.error && "code" in result.probe.error
568
+ ? result.probe.error.code
569
+ : undefined;
570
+ return result.foundRsync === undefined && code === "ENOENT";
571
+ }
572
+ /** The rsync overlay; do not allocate a recovery copy when it cannot run. */
573
+ export function requireWorkingRsync(env, err) {
574
+ const result = probeRsync(env);
575
+ if (result.working)
576
+ return result.launcher;
577
+ return reportRsyncPreflightFailure(result, err);
578
+ }
579
+ /** Environment variable that forces an overlay engine: `native` or `rsync`. */
580
+ export const COPY_ENGINE_ENV = "HQ_RESCUE_COPY_ENGINE";
581
+ /**
582
+ * Choose the overlay copy engine before any snapshot is allocated.
583
+ *
584
+ * A working rsync is used as before. When rsync is not on PATH at all, the
585
+ * overlay uses the built-in file copy (./rescue-native-copy.ts) with the same
586
+ * filters, instead of failing with exit 127. An rsync that is on PATH but
587
+ * broken still fails the preflight, as before. `HQ_RESCUE_COPY_ENGINE=rsync`
588
+ * keeps the old rsync-only behaviour; `HQ_RESCUE_COPY_ENGINE=native` uses
589
+ * the built-in copy even when rsync works.
590
+ */
591
+ export function selectOverlayCopyEngine(env, out, err) {
592
+ const forced = (envValue(env, COPY_ENGINE_ENV) ?? "").trim().toLowerCase();
593
+ if (forced === "native") {
594
+ out(`==> Copy engine: built-in file copy (${COPY_ENGINE_ENV}=native)\n`);
595
+ return { kind: "native" };
596
+ }
597
+ if (forced !== "" && forced !== "rsync") {
598
+ err(`error: ${COPY_ENGINE_ENV} must be "native" or "rsync" (got ${JSON.stringify(boundedDiagnostic(forced, 64))}).\n`);
599
+ throw new ExitError(2);
600
+ }
601
+ const result = probeRsync(env);
602
+ if (result.working)
603
+ return { kind: "rsync", launcher: result.launcher };
604
+ if (forced === "" && rsyncIsMissing(result)) {
605
+ out("==> Copy engine: built-in file copy (rsync not found on PATH)\n");
606
+ return { kind: "native" };
607
+ }
608
+ return reportRsyncPreflightFailure(result, err);
609
+ }
610
+ /** Print the rsync preflight diagnostic and stop the rescue. */
611
+ function reportRsyncPreflightFailure({ foundRsync, entries, resolvedPath, probe, output }, err) {
504
612
  err("error: rsync preflight failed before any safety snapshot was allocated.\n");
505
613
  if (probe.error) {
506
614
  const errorDetail = "code" in probe.error && typeof probe.error.code === "string"
@@ -530,7 +638,7 @@ export function requireWorkingRsync(env, err) {
530
638
  : "(none)";
531
639
  err(` rsync found at: ${foundRsyncDiagnostic}\n`);
532
640
  err(` resolved PATH: ${boundedDiagnostic(resolvedPath ?? "(unset)", 1024)}\n`);
533
- err(" Install or repair rsync and retry. On Windows, install the Cygwin rsync package with the Cygwin installer and add its bin directory to PATH.\n");
641
+ err(" Install or repair rsync and retry. Or set HQ_RESCUE_COPY_ENGINE=native to use the built-in file copy instead. On Windows, install the Cygwin rsync package with the Cygwin installer and add its bin directory to PATH.\n");
534
642
  throw new ExitError(probe.status || 127);
535
643
  }
536
644
  // fs predicates mirroring bash test operators.
@@ -816,7 +924,15 @@ export function parseRescueArgs(argv) {
816
924
  " [--no-backup] [--backup-dir DIR] [--cloud-update]\n" +
817
925
  " [--dry-run] [--yes] [--recover-snapshots]\n" +
818
926
  " [--verify-restored-snapshot SNAPSHOT]\n" +
819
- " [--restore-snapshot SNAPSHOT]\n");
927
+ " [--restore-snapshot SNAPSHOT]\n" +
928
+ "\n" +
929
+ "environment:\n" +
930
+ " HQ_RESCUE_COPY_ENGINE=native|rsync\n" +
931
+ " How the release is copied into the HQ root. Unset: rsync when it\n" +
932
+ " works, the built-in file copy when rsync is not on PATH; a broken\n" +
933
+ " rsync stops the update. rsync: require rsync (exit 127 when it is\n" +
934
+ " missing). native: always use the built-in file copy. Any other\n" +
935
+ " value exits 2.\n");
820
936
  throw new ExitError(1);
821
937
  };
822
938
  let narrowCsv = "";
@@ -1634,10 +1750,12 @@ export function realpathOrExit(p, err) {
1634
1750
  }
1635
1751
  }
1636
1752
  }
1637
- function reportRsyncFailure(status, phase, stderr, err) {
1753
+ function reportRsyncFailure(status, phase, stderr, err, engine = "rsync") {
1638
1754
  if (stderr)
1639
1755
  err(stderr);
1640
- err(`rsync status ${status} during ${phase}\n`);
1756
+ // The built-in copy returns rsync's status codes (23 = some entries were
1757
+ // not copied), so the failure kinds and the restore path stay the same.
1758
+ err(`${engine === "native" ? "built-in file copy" : "rsync"} status ${status} during ${phase}\n`);
1641
1759
  err(`HQ_RESCUE_FAILURE_KIND=${status === 23 || status === 24 ? "rsync-partial" : "rsync-failed"}\n`);
1642
1760
  }
1643
1761
  function hashRecoveryTree(root, rootRel) {
@@ -1802,66 +1920,6 @@ export function rsyncWindowsEnv(env, platform = process.platform) {
1802
1920
  }
1803
1921
  return next;
1804
1922
  }
1805
- /** One `--include=`/`--exclude=` rule as rsync's receiver filter applies it. */
1806
- function rsyncFilterRuleMatches(rawPattern, rel, isDir) {
1807
- let pattern = rawPattern;
1808
- let tripleStar = false;
1809
- if (pattern.endsWith("/***")) {
1810
- tripleStar = true;
1811
- pattern = pattern.slice(0, -4);
1812
- }
1813
- else if (pattern.endsWith("/")) {
1814
- if (!isDir)
1815
- return false;
1816
- pattern = pattern.replace(/\/+$/, "");
1817
- }
1818
- const anchored = pattern.startsWith("/");
1819
- if (anchored)
1820
- pattern = pattern.replace(/^\/+/, "");
1821
- if (pattern.length === 0)
1822
- return false;
1823
- let body = "";
1824
- for (let i = 0; i < pattern.length; i++) {
1825
- const ch = pattern[i];
1826
- if (ch === "*") {
1827
- if (pattern[i + 1] === "*") {
1828
- body += ".*";
1829
- i++;
1830
- }
1831
- else {
1832
- body += "[^/]*";
1833
- }
1834
- }
1835
- else if (ch === "?") {
1836
- body += "[^/]";
1837
- }
1838
- else if (ch === "[") {
1839
- const close = pattern.indexOf("]", i + 1);
1840
- if (close < 0) {
1841
- body += "\\[";
1842
- }
1843
- else {
1844
- body += pattern.slice(i, close + 1).replace(/\\/g, "\\\\");
1845
- i = close;
1846
- }
1847
- }
1848
- else {
1849
- body += ch.replace(/[.+^${}()|\\]/g, "\\$&");
1850
- }
1851
- }
1852
- if (tripleStar)
1853
- body += "(/.*)?";
1854
- const hasSlash = pattern.includes("/") || tripleStar;
1855
- let source;
1856
- if (anchored)
1857
- source = `^${body}$`;
1858
- else if (hasSlash)
1859
- source = `^(.*/)?${body}$`;
1860
- else
1861
- source = `^${body}$`;
1862
- const subject = !anchored && !hasSlash ? rel.slice(rel.lastIndexOf("/") + 1) : rel;
1863
- return new RegExp(source).test(subject);
1864
- }
1865
1923
  /**
1866
1924
  * The rsync filter list for the full (preserve-list) overlay.
1867
1925
  *
@@ -2178,7 +2236,21 @@ function releaseLinkPointsAtStaging(destination, srcDir) {
2178
2236
  return true;
2179
2237
  return absolutePathIsInside(path.resolve(path.dirname(destination), linkText), srcDir);
2180
2238
  }
2181
- function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, rsyncExcludes, env) {
2239
+ /**
2240
+ * Run one overlay call. `args` is the full rsync argument vector, ending with
2241
+ * the Cygwin-form source and destination. The built-in copy reads the same
2242
+ * options and filters and takes the native `srcDir` and `hqRoot` paths.
2243
+ */
2244
+ function runOverlayCopy(engine, args, srcDir, hqRoot, env) {
2245
+ if (engine.kind === "rsync") {
2246
+ return run(engine.launcher.command, [...engine.launcher.leadingArgs, ...args], {
2247
+ env: rsyncWindowsEnv(env),
2248
+ });
2249
+ }
2250
+ const result = runNativeOverlay(srcDir, hqRoot, args.slice(0, -2));
2251
+ return { ...result, error: undefined, signal: null };
2252
+ }
2253
+ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, copyEngine, rsyncExcludes, env) {
2182
2254
  const newest = [...unresolved].sort((left, right) => right.entry.completedMs - left.entry.completedMs ||
2183
2255
  right.entry.createdMs - left.entry.createdMs ||
2184
2256
  right.entry.name.localeCompare(left.entry.name))[0];
@@ -2189,8 +2261,7 @@ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, r
2189
2261
  newest.entry.manifest.sourceSha !== srcSha) {
2190
2262
  failures.push("sha");
2191
2263
  }
2192
- const releaseProof = run(rsyncLauncher.command, [
2193
- ...rsyncLauncher.leadingArgs,
2264
+ const releaseProof = runOverlayCopy(copyEngine, [
2194
2265
  "-a",
2195
2266
  "--checksum",
2196
2267
  "--no-times",
@@ -2200,7 +2271,7 @@ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, r
2200
2271
  ...rsyncWindowsReceiverArgs(),
2201
2272
  toCygwinRsyncPath(srcDir + "/"),
2202
2273
  toCygwinRsyncPath(hqRoot + "/"),
2203
- ], { env: rsyncWindowsEnv(env) });
2274
+ ], srcDir, hqRoot, env);
2204
2275
  if (releaseProof.status !== 0 ||
2205
2276
  !rsyncOutputHasOnlyDirectoryChanges(`${releaseProof.stdout}\n${releaseProof.stderr}`)) {
2206
2277
  failures.push("release-bytes");
@@ -2242,10 +2313,27 @@ function assertClaudeSettingsAdmission(hqRoot, err) {
2242
2313
  function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTimeoutMs = GIT_REACHABILITY_PROBE_TIMEOUT_MS, stampWriter = writeCoreSourceStamp, restoreOnRsyncFailure = false, setupPathSettingsLocal = false, backupCapacityStatfsSync = fs.statfsSync, backupCapacityCloneProbe, backupCapacityStatSync = fs.statSync, pathSep = path.sep, snapshotClonePlatform = process.platform, snapshotCloneRunner = runDarwinClone) {
2243
2314
  const hqRoot = resolveHqRoot(cfg, err);
2244
2315
  const RUN_TS = utcStamp(new Date(), "dash");
2245
- // Both the release overlay and a restorable snapshot require rsync. A shim
2246
- // which merely starts but exits non-zero used to trigger an enormous cp -a
2247
- // fallback, then fail later at overlay. Stop before classification/allocation.
2248
- const rsyncLauncher = requireWorkingRsync(env, err);
2316
+ // Choose the overlay engine before classification/allocation. A shim which
2317
+ // merely starts but exits non-zero used to trigger an enormous cp -a
2318
+ // fallback, then fail later at overlay, so a broken rsync still stops here.
2319
+ // No rsync at all (stock Windows) uses the built-in copy instead.
2320
+ const copyEngine = selectOverlayCopyEngine(env, out, err);
2321
+ // The release clone uses `--filter=blob:none`, which needs git 2.19+. Check
2322
+ // before the prompt so an old git fails with a plain message instead of a
2323
+ // clone usage dump. A newer git later on PATH is pinned after the scratch
2324
+ // directory exists (below). The version probe uses the same hardened
2325
+ // environment as every other rescue git call (no credential helpers).
2326
+ const gitChoice = chooseRescueGit(env, (git) => {
2327
+ const probe = run(git, ["--version"], {
2328
+ env: gitNetworkEnv(withoutGitCredentialHelpers(env)),
2329
+ timeout: GIT_VERSION_PROBE_TIMEOUT_MS,
2330
+ });
2331
+ return probe.status === 0 ? parseGitVersion(probe.stdout) : null;
2332
+ });
2333
+ if (gitChoice.kind === "too-old") {
2334
+ err(gitTooOldMessage(gitChoice));
2335
+ throw new ExitError(1);
2336
+ }
2249
2337
  // --- Capture the pre-rescue .claude/settings.json (BEFORE the wipe) ---
2250
2338
  // This is `ours` for the post-overlay settings reconcile. It must be read now
2251
2339
  // because the overlay-safe classification deletes/overwrites it before
@@ -2372,6 +2460,10 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2372
2460
  }
2373
2461
  const tmpdir = fs.mkdtempSync(path.join(staging.root, "hq-replace-rescue-"));
2374
2462
  setTmp(tmpdir);
2463
+ if (gitChoice.kind === "pin") {
2464
+ env = pinGitFirstOnPath(env, path.join(tmpdir, "git-bin"), gitChoice.git);
2465
+ out(`==> Git: ${gitChoice.git} (${gitChoice.version}); ${gitChoice.skipped} is ${gitChoice.skippedVersion}, older than the ${RESCUE_MIN_GIT_VERSION} this update needs\n`);
2466
+ }
2375
2467
  const srcDir = path.join(tmpdir, "src");
2376
2468
  const rescueLog = path.join(tmpdir, "rescue-actions.log");
2377
2469
  fs.writeFileSync(rescueLog, "");
@@ -2555,11 +2647,6 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2555
2647
  wipeToplevel.push("companies/_template");
2556
2648
  }
2557
2649
  }
2558
- // `companies/_template` is a reserved, generated tree rather than company
2559
- // content. Snapshot manifests deliberately record only single-segment roots;
2560
- // keep the template in classification/overlay scope but out of the physical
2561
- // safety snapshot so restore validation remains fail-closed.
2562
- const snapshotRoots = wipeToplevel.filter((root) => root !== "companies/_template");
2563
2650
  // --- Classification state ---
2564
2651
  const counts = {
2565
2652
  userOnly: 0,
@@ -2700,9 +2787,9 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2700
2787
  ];
2701
2788
  // Exercise the exact overlay command before any classified delete/move. A
2702
2789
  // Cygwin path conversion or filter failure therefore leaves the root intact.
2703
- const overlayPreflight = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, "--dry-run", ...overlayArgs], { env: rsyncWindowsEnv(env) });
2790
+ const overlayPreflight = runOverlayCopy(copyEngine, ["--dry-run", ...overlayArgs], srcDir, hqRoot, env);
2704
2791
  if (overlayPreflight.status !== 0) {
2705
- reportRsyncFailure(overlayPreflight.status, "dry-run", overlayPreflight.stderr, err);
2792
+ reportRsyncFailure(overlayPreflight.status, "dry-run", overlayPreflight.stderr, err, copyEngine.kind);
2706
2793
  throw new ExitError(overlayPreflight.status || 1);
2707
2794
  }
2708
2795
  ctx.actions = buildRescueActions(ctx);
@@ -2716,6 +2803,28 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2716
2803
  reportUnwritableRescuePaths(hqRoot, unwritable, err);
2717
2804
  throw new ExitError(1);
2718
2805
  }
2806
+ // `companies/_template` is a reserved, generated tree rather than company
2807
+ // content. Snapshot manifests deliberately record only single-segment roots;
2808
+ // keep the template in classification/overlay scope but out of the physical
2809
+ // safety snapshot so restore validation remains fail-closed. User-only
2810
+ // top-level roots (not shipped by the release, not touched by any action,
2811
+ // not holding a shuttled sub-path) are left out too: rescue never changes
2812
+ // them, and a large one used to block the update with disk_full.
2813
+ let sourceToplevel = [];
2814
+ try {
2815
+ sourceToplevel = fs.readdirSync(srcDir);
2816
+ }
2817
+ catch {
2818
+ sourceToplevel = [];
2819
+ }
2820
+ const snapshotRoots = rescueSnapshotRoots({
2821
+ wipeToplevel,
2822
+ sourceEntries: sourceToplevel,
2823
+ affectedRels: ctx.actions.flatMap((action) => action.affectedRels),
2824
+ preserveSubpaths: cfg.preserveSubpaths,
2825
+ narrowMode: cfg.narrowPaths.length !== 0,
2826
+ });
2827
+ const unsnapshottedRoots = wipeToplevel.filter((root) => root !== "companies/_template" && !snapshotRoots.includes(root));
2719
2828
  // Snapshot allocation is deliberately after the entire read-only walk and
2720
2829
  // action-plan build. A no-op (or a classifier fault above) cannot consume
2721
2830
  // backup space.
@@ -2742,7 +2851,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2742
2851
  if (postRestore.problem) {
2743
2852
  err(`error: post-restore permit is not usable: ${postRestore.problem}\n`);
2744
2853
  }
2745
- const proof = recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, rsyncExcludes, env);
2854
+ const proof = recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, copyEngine, rsyncExcludes, env);
2746
2855
  if (proof.eligible && proof.failures.length === 0) {
2747
2856
  out("==> Recovery proof passed: interrupted update matches the release and preserved paths; continuing.\n");
2748
2857
  err("HQ_RESCUE_NOTE=recovery-proof-passed\n");
@@ -2775,6 +2884,9 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2775
2884
  backupDir = allocateSnapshotDir(cfg.backupRoot, RUN_TS, canonicalRootHash(hqRoot), runId);
2776
2885
  out("\n");
2777
2886
  out(`==> Safety snapshot -> ${backupDir}\n`);
2887
+ if (unsnapshottedRoots.length > 0) {
2888
+ out(` left out (user-only, not changed by this update): ${unsnapshottedRoots.join(", ")}\n`);
2889
+ }
2778
2890
  const snapshotSymlinks = [];
2779
2891
  const snapshotSkippedErrors = [];
2780
2892
  try {
@@ -2944,10 +3056,10 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2944
3056
  toCygwinRsyncPath(hqRoot + "/"),
2945
3057
  ]
2946
3058
  : overlayArgs;
2947
- const overlay = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, ...overlayRunArgs], { env: rsyncWindowsEnv(env) });
3059
+ const overlay = runOverlayCopy(copyEngine, overlayRunArgs, srcDir, hqRoot, env);
2948
3060
  if (overlay.status !== 0) {
2949
3061
  // bash runs under set -e: a failed rsync aborts with its status.
2950
- reportRsyncFailure(overlay.status, "overlay", overlay.stderr, err);
3062
+ reportRsyncFailure(overlay.status, "overlay", overlay.stderr, err, copyEngine.kind);
2951
3063
  if (restoreOnRsyncFailure) {
2952
3064
  const manifest = backupDir ? readSnapshotManifest(backupDir, hqRoot) : null;
2953
3065
  if (!manifest || hasSkippedSnapshotEntries(manifest)) {
@@ -4939,30 +5051,26 @@ function precomputeGitMaps(ctx, wipeToplevel) {
4939
5051
  ctx.localShas = new Map();
4940
5052
  return;
4941
5053
  }
4942
- // Pass 1: floor existence + blob SHA for every rel, in one process.
5054
+ // Pass 1: floor existence + blob SHA for every rel, in chunked batches.
4943
5055
  // `cat-file --batch-check` prints "<sha> <type> <size>" for a present object
4944
- // or "<input> missing" otherwise, one line per input in order. This single
4945
- // pass replaces BOTH the per-file `cat-file -e` (existence) and `rev-parse`
5056
+ // or "<input> missing" otherwise, one line per input in order. This
5057
+ // replaces BOTH the per-file `cat-file -e` (existence) and `rev-parse`
4946
5058
  // (sha). It reads only the git object DB — never local file contents — so it
4947
- // stays cheap even on a 100k-file wipe set.
5059
+ // stays cheap even on a 100k-file wipe set. A batch failure aborts the
5060
+ // rescue before anything is touched: falling back to per-file spawns across
5061
+ // a wipe set this size would mean tens of thousands of git processes and a
5062
+ // machine-wide slowdown for the better part of an hour.
4948
5063
  const floorShas = new Map();
4949
5064
  if (allRels.length > 0) {
4950
- const res = run("git", ["cat-file", "--batch-check"], {
4951
- cwd: ctx.srcDir,
4952
- env: ctx.env,
4953
- input: allRels.map((rel) => `${ctx.historyFloor}:${rel}`).join("\n") + "\n",
4954
- });
4955
- if (res.status === 0) {
4956
- const lines = res.stdout.split("\n");
4957
- for (let i = 0; i < allRels.length; i++) {
4958
- const line = lines[i] ?? "";
4959
- if (line === "" || line.endsWith(" missing")) {
4960
- floorShas.set(allRels[i], null);
4961
- }
4962
- else {
4963
- const sha = line.split(" ")[0];
4964
- floorShas.set(allRels[i], sha || null);
4965
- }
5065
+ const lines = runGitBatchOrAbort(["cat-file", "--batch-check"], allRels.map((rel) => `${ctx.historyFloor}:${rel}`), { cwd: ctx.srcDir, env: ctx.env });
5066
+ for (let i = 0; i < allRels.length; i++) {
5067
+ const line = lines[i];
5068
+ if (line === "" || line.endsWith(" missing")) {
5069
+ floorShas.set(allRels[i], null);
5070
+ }
5071
+ else {
5072
+ const sha = line.split(" ")[0];
5073
+ floorShas.set(allRels[i], sha || null);
4966
5074
  }
4967
5075
  }
4968
5076
  }
@@ -4982,22 +5090,55 @@ function precomputeGitMaps(ctx, wipeToplevel) {
4982
5090
  hashAbs.push(fileAbs[i]);
4983
5091
  }
4984
5092
  }
4985
- if (hashAbs.length > 0) {
4986
- const res = run("git", ["hash-object", "--stdin-paths"], {
4987
- env: ctx.env,
4988
- input: hashAbs.join("\n") + "\n",
4989
- });
4990
- if (res.status === 0) {
4991
- const lines = res.stdout.split("\n");
4992
- for (let i = 0; i < hashRels.length; i++) {
4993
- const sha = (lines[i] ?? "").trim();
4994
- if (sha)
4995
- localShas.set(hashRels[i], sha);
4996
- }
4997
- }
5093
+ const hashes = hashLocalFilesInChunks(hashAbs, ctx.env, (msg) => process.stderr.write(msg));
5094
+ for (let i = 0; i < hashRels.length; i++) {
5095
+ const sha = hashes[i];
5096
+ if (sha)
5097
+ localShas.set(hashRels[i], sha);
4998
5098
  }
4999
5099
  ctx.localShas = localShas;
5000
5100
  }
5101
+ /**
5102
+ * Blob SHA for each local file, in order; "" where the file could not be
5103
+ * hashed. `git hash-object --stdin-paths` stops at the first file it cannot
5104
+ * open (a cloud placeholder, a permission-denied file, one deleted mid-walk),
5105
+ * so a chunk that fails is retried one file at a time. That bounds the
5106
+ * per-file spawns to one chunk, and an unhashable file simply stays out of
5107
+ * the map, which classifyOne treats as a local edit.
5108
+ */
5109
+ export function hashLocalFilesInChunks(absPaths, env, warn, chunkSize = GIT_BATCH_CHUNK_SIZE) {
5110
+ const out = [];
5111
+ for (let start = 0; start < absPaths.length; start += chunkSize) {
5112
+ const chunk = absPaths.slice(start, start + chunkSize);
5113
+ let lines;
5114
+ try {
5115
+ lines = runGitBatch(["hash-object", "--stdin-paths"], chunk, {
5116
+ env,
5117
+ chunkSize,
5118
+ });
5119
+ }
5120
+ catch (e) {
5121
+ if (!(e instanceof GitBatchError))
5122
+ throw e;
5123
+ warn(`warning: batched hash of ${chunk.length} files failed (${e.message.split("\n").slice(-1)[0]}); hashing them one at a time\n`);
5124
+ lines = chunk.map((abs) => run("git", ["hash-object", abs], { env }).stdout);
5125
+ }
5126
+ for (const line of lines)
5127
+ out.push(line.trim());
5128
+ }
5129
+ return out;
5130
+ }
5131
+ function runGitBatchOrAbort(args, inputs, opts) {
5132
+ try {
5133
+ return runGitBatch(args, inputs, opts);
5134
+ }
5135
+ catch (e) {
5136
+ if (!(e instanceof GitBatchError))
5137
+ throw e;
5138
+ process.stderr.write(`\nERROR: batched git lookup failed while classifying ${inputs.length} paths; aborting before any file is touched.\n${e.message}\n`);
5139
+ throw new ExitError(1);
5140
+ }
5141
+ }
5001
5142
  function walkAndProcess(ctx, rootRel) {
5002
5143
  const rootAbs = path.join(ctx.hqRoot, rootRel);
5003
5144
  if (!lexists(rootAbs))
@@ -6328,9 +6469,15 @@ function rescuePathsOverlap(first, second) {
6328
6469
  function isSkippedSnapshotPath(ctx, rel) {
6329
6470
  return ctx.skippedSnapshotRels.some((skippedRel) => rescuePathsOverlap(rel, skippedRel));
6330
6471
  }
6331
- function appendLiteralRsyncExclude(excludeList, rel, recursive = false) {
6472
+ /**
6473
+ * Protect one path from the overlay with an exact rsync exclude. rsync reads
6474
+ * backslash escapes only in a pattern that holds a wildcard (`*`, `?`, `[`,
6475
+ * or the `/***` suffix of a recursive entry), so escape only then; a plain
6476
+ * name with a backslash is compared literally and must stay as it is.
6477
+ */
6478
+ export function appendLiteralRsyncExclude(excludeList, rel, recursive = false) {
6332
6479
  let pattern = rel;
6333
- if (/[\\*?[]/.test(pattern)) {
6480
+ if (recursive || /[*?[]/.test(pattern)) {
6334
6481
  pattern = pattern
6335
6482
  .replace(/\\/g, "\\\\")
6336
6483
  .replace(/([*?[])/g, "\\$1");