@indigoai-us/hq-cloud 6.18.109 → 6.18.110
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/dist/bin/area-ledger-migration.d.ts.map +1 -1
- package/dist/bin/area-ledger-migration.js +5 -3
- package/dist/bin/area-ledger-migration.js.map +1 -1
- package/dist/bin/backup-prune-runner.js +2 -2
- package/dist/bin/backup-prune-runner.js.map +1 -1
- package/dist/bin/runner-output-guard.d.ts +39 -0
- package/dist/bin/runner-output-guard.d.ts.map +1 -0
- package/dist/bin/runner-output-guard.js +104 -0
- package/dist/bin/runner-output-guard.js.map +1 -0
- package/dist/bin/sync-runner-company.d.ts +9 -0
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +76 -6
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +37 -1
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +37 -3
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/cli/conflict.d.ts +30 -1
- package/dist/cli/conflict.d.ts.map +1 -1
- package/dist/cli/conflict.js +69 -3
- package/dist/cli/conflict.js.map +1 -1
- package/dist/cli/reconcile-skip-reason.d.ts +1 -1
- package/dist/cli/reconcile-skip-reason.d.ts.map +1 -1
- package/dist/cli/reconcile-skip-reason.js +2 -0
- package/dist/cli/reconcile-skip-reason.js.map +1 -1
- package/dist/cli/reindex.d.ts.map +1 -1
- package/dist/cli/reindex.js +228 -43
- package/dist/cli/reindex.js.map +1 -1
- package/dist/cli/rescue-core.d.ts +98 -2
- package/dist/cli/rescue-core.d.ts.map +1 -1
- package/dist/cli/rescue-core.js +487 -74
- package/dist/cli/rescue-core.js.map +1 -1
- package/dist/cli/rescue.d.ts.map +1 -1
- package/dist/cli/rescue.js +37 -9
- package/dist/cli/rescue.js.map +1 -1
- package/dist/cli/share.d.ts +35 -8
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +437 -32
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/sync.d.ts +70 -5
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +439 -77
- package/dist/cli/sync.js.map +1 -1
- package/dist/cognito-auth.d.ts +10 -0
- package/dist/cognito-auth.d.ts.map +1 -1
- package/dist/cognito-auth.js +162 -1
- package/dist/cognito-auth.js.map +1 -1
- package/dist/ignore.d.ts.map +1 -1
- package/dist/ignore.js +43 -21
- package/dist/ignore.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/journal-row-store.d.ts +3 -0
- package/dist/journal-row-store.d.ts.map +1 -1
- package/dist/journal-row-store.js +21 -0
- package/dist/journal-row-store.js.map +1 -1
- package/dist/journal-snapshot-decoder.js +2 -0
- package/dist/journal-snapshot-decoder.js.map +1 -1
- package/dist/journal-snapshot-v4.d.ts.map +1 -1
- package/dist/journal-snapshot-v4.js +6 -1
- package/dist/journal-snapshot-v4.js.map +1 -1
- package/dist/journal.d.ts +1 -1
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +20 -20
- package/dist/journal.js.map +1 -1
- package/dist/lib/append-log-merge.d.ts +43 -0
- package/dist/lib/append-log-merge.d.ts.map +1 -0
- package/dist/lib/append-log-merge.js +424 -0
- package/dist/lib/append-log-merge.js.map +1 -0
- package/dist/lib/same-path-upload-lock.d.ts +27 -1
- package/dist/lib/same-path-upload-lock.d.ts.map +1 -1
- package/dist/lib/same-path-upload-lock.js +32 -1
- package/dist/lib/same-path-upload-lock.js.map +1 -1
- package/dist/object-io.d.ts +36 -1
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +93 -12
- package/dist/object-io.js.map +1 -1
- package/dist/operation-lock.d.ts +27 -1
- package/dist/operation-lock.d.ts.map +1 -1
- package/dist/operation-lock.js +94 -8
- package/dist/operation-lock.js.map +1 -1
- package/dist/outposts/client.d.ts +19 -6
- package/dist/outposts/client.d.ts.map +1 -1
- package/dist/outposts/client.js +16 -5
- package/dist/outposts/client.js.map +1 -1
- package/dist/outposts/command.d.ts +2 -1
- package/dist/outposts/command.d.ts.map +1 -1
- package/dist/outposts/command.js +81 -13
- package/dist/outposts/command.js.map +1 -1
- package/dist/outposts/self-deploy.d.ts.map +1 -1
- package/dist/outposts/self-deploy.js +3 -0
- package/dist/outposts/self-deploy.js.map +1 -1
- package/dist/private-folder-transport.d.ts +0 -2
- package/dist/private-folder-transport.d.ts.map +1 -1
- package/dist/private-folder-transport.js +17 -16
- package/dist/private-folder-transport.js.map +1 -1
- package/dist/push-identity-fence.d.ts +116 -3
- package/dist/push-identity-fence.d.ts.map +1 -1
- package/dist/push-identity-fence.js +625 -62
- package/dist/push-identity-fence.js.map +1 -1
- package/dist/qmd-reindex.d.ts.map +1 -1
- package/dist/qmd-reindex.js +3 -2
- package/dist/qmd-reindex.js.map +1 -1
- package/dist/s3.d.ts +30 -9
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +110 -82
- package/dist/s3.js.map +1 -1
- package/dist/sync/area-ledger-migration.d.ts +17 -0
- package/dist/sync/area-ledger-migration.d.ts.map +1 -1
- package/dist/sync/area-ledger-migration.js +37 -3
- package/dist/sync/area-ledger-migration.js.map +1 -1
- package/dist/sync/scattered-delete-burst.d.ts +61 -0
- package/dist/sync/scattered-delete-burst.d.ts.map +1 -0
- package/dist/sync/scattered-delete-burst.js +111 -0
- package/dist/sync/scattered-delete-burst.js.map +1 -0
- package/dist/sync/unattended-delete-hold.d.ts +102 -0
- package/dist/sync/unattended-delete-hold.d.ts.map +1 -0
- package/dist/sync/unattended-delete-hold.js +164 -0
- package/dist/sync/unattended-delete-hold.js.map +1 -0
- package/dist/sync-core.d.ts +5 -6
- package/dist/sync-core.d.ts.map +1 -1
- package/dist/sync-core.js +5 -6
- package/dist/sync-core.js.map +1 -1
- package/dist/types.d.ts +13 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vault-client.d.ts +6 -0
- package/dist/vault-client.d.ts.map +1 -1
- package/dist/vault-client.js +53 -8
- package/dist/vault-client.js.map +1 -1
- package/dist/vault-key-grammar.d.ts +44 -0
- package/dist/vault-key-grammar.d.ts.map +1 -0
- package/dist/vault-key-grammar.js +158 -0
- package/dist/vault-key-grammar.js.map +1 -0
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +4 -1
- package/dist/watcher.js.map +1 -1
- package/dist/windows-extended-path.d.ts +22 -0
- package/dist/windows-extended-path.d.ts.map +1 -0
- package/dist/windows-extended-path.js +55 -0
- package/dist/windows-extended-path.js.map +1 -0
- package/package.json +1 -1
package/dist/cli/rescue-core.js
CHANGED
|
@@ -40,7 +40,7 @@ import { assertRescuePathTypeUnchanged, isRescueTransientDirectory, rescueSnapsh
|
|
|
40
40
|
import { applyBackupPrune, canonicalRootHash, inventoryManagedSnapshots, isManagedSnapshotManifest, } from "../backup-prune.js";
|
|
41
41
|
import { makeRestoreProbePath, makeRestoreStagePath, } from "../restore-staging.js";
|
|
42
42
|
import { readCoreSourceStamp, writeCoreSourceStamp } from "./core-source-stamp.js";
|
|
43
|
-
import { rsyncFilterRuleMatches, runNativeOverlay } from "./rescue-native-copy.js";
|
|
43
|
+
import { compileRsyncPattern, rsyncFilterRuleMatches, runNativeOverlay, } from "./rescue-native-copy.js";
|
|
44
44
|
import { chooseRescueGit, GIT_VERSION_PROBE_TIMEOUT_MS, gitTooOldMessage, parseGitVersion, pinGitFirstOnPath, RESCUE_MIN_GIT_VERSION, } from "./rescue-git.js";
|
|
45
45
|
const MAX_CLONE_FILES_PER_BATCH = 200;
|
|
46
46
|
const MAX_CLONE_BATCH_PATH_BYTES = 64 * 1024;
|
|
@@ -320,6 +320,12 @@ function classifyGitFailure(result) {
|
|
|
320
320
|
if (isMissingMacCommandLineTools(diagnostic)) {
|
|
321
321
|
return "missing-dependency";
|
|
322
322
|
}
|
|
323
|
+
// A dead or unresolvable http.proxy in git config is not a flaky network.
|
|
324
|
+
// Retrying it three times only delays the same error, and blaming the
|
|
325
|
+
// Internet connection hides the setting that caused it.
|
|
326
|
+
if (diagnostic.includes("could not resolve proxy")) {
|
|
327
|
+
return "proxy-config";
|
|
328
|
+
}
|
|
323
329
|
// Interrupted transfers are retryable. Corrupt packs, checksum mismatches,
|
|
324
330
|
// and other integrity failures are not: retrying those three times hides the
|
|
325
331
|
// real error and can write a bad clone more than once.
|
|
@@ -328,7 +334,6 @@ function classifyGitFailure(result) {
|
|
|
328
334
|
const transientNetworkSignals = [
|
|
329
335
|
"resolving timed out",
|
|
330
336
|
"could not resolve host",
|
|
331
|
-
"could not resolve proxy",
|
|
332
337
|
"temporary failure in name resolution",
|
|
333
338
|
"network is unreachable",
|
|
334
339
|
"connection timed out",
|
|
@@ -545,14 +550,38 @@ function buildRsyncLauncher(candidatePath) {
|
|
|
545
550
|
}
|
|
546
551
|
return { command: "rsync", leadingArgs: [] };
|
|
547
552
|
}
|
|
553
|
+
/** The `rsync --version` probe may not hang the rescue; a hung shim fails closed. */
|
|
554
|
+
export const RSYNC_PROBE_TIMEOUT_MS = 15_000;
|
|
555
|
+
/** Error code for a Windows shim path that cmd.exe cannot be trusted to parse. */
|
|
556
|
+
export const RSYNC_UNSAFE_SHIM_PATH = "EUNSAFEPATH";
|
|
557
|
+
/**
|
|
558
|
+
* True when a `.cmd`/`.bat` path can be passed to `cmd.exe /d /c` as one
|
|
559
|
+
* argument. Node quotes an argument only for spaces and quotes, and cmd.exe
|
|
560
|
+
* still expands `%VAR%` and treats `& | < > ^ ( ) @ !` specially, so a path
|
|
561
|
+
* with any of them is refused rather than launched.
|
|
562
|
+
*/
|
|
563
|
+
export function isCmdSafeShimPath(candidatePath) {
|
|
564
|
+
return !/[&|<>^%!"()@]/.test(candidatePath);
|
|
565
|
+
}
|
|
548
566
|
/** Find rsync on PATH and run `rsync --version` through the overlay's launcher. */
|
|
549
567
|
function probeRsync(env) {
|
|
550
568
|
const resolvedPath = envValue(env, "PATH");
|
|
551
569
|
const entries = pathEntries(resolvedPath);
|
|
552
570
|
const foundRsync = findRsyncOnPath(entries, env);
|
|
553
571
|
const launcher = buildRsyncLauncher(foundRsync?.path);
|
|
572
|
+
if (process.platform === "win32" &&
|
|
573
|
+
foundRsync &&
|
|
574
|
+
isWindowsShimPath(foundRsync.path) &&
|
|
575
|
+
!isCmdSafeShimPath(foundRsync.path)) {
|
|
576
|
+
// cmd.exe would re-parse these characters inside the path, so the shim
|
|
577
|
+
// is never launched (here or by the overlay).
|
|
578
|
+
const error = Object.assign(new Error("rsync shim path contains characters cmd.exe would interpret"), { code: RSYNC_UNSAFE_SHIM_PATH });
|
|
579
|
+
const probe = { status: 126, stdout: "", stderr: "", error, signal: null };
|
|
580
|
+
return { launcher, foundRsync, entries, resolvedPath, probe, output: "\n", working: false };
|
|
581
|
+
}
|
|
554
582
|
const probe = runWithSpawnError(launcher.command, [...launcher.leadingArgs, "--version"], {
|
|
555
583
|
env,
|
|
584
|
+
timeout: RSYNC_PROBE_TIMEOUT_MS,
|
|
556
585
|
});
|
|
557
586
|
const output = `${probe.stdout}\n${probe.stderr}`;
|
|
558
587
|
const working = probe.status === 0 && /\brsync\b.*\bversion\b/i.test(output);
|
|
@@ -563,6 +592,30 @@ function probeRsync(env) {
|
|
|
563
592
|
* with ENOENT. A present but unexecutable, failing, or unrecognised rsync is
|
|
564
593
|
* not "absent" and still stops the rescue.
|
|
565
594
|
*/
|
|
595
|
+
/**
|
|
596
|
+
* On Windows, the rsync on PATH plainly cannot run: it could not be spawned
|
|
597
|
+
* (ENOENT, EACCES), its shim path is unsafe for cmd.exe, or it exited non-zero
|
|
598
|
+
* with no output at all. A timeout, a signal, unrecognised version output or
|
|
599
|
+
* a non-zero exit that printed something is not "cannot run" and still stops
|
|
600
|
+
* the rescue, so a misconfigured rsync the user installed stays loud.
|
|
601
|
+
*/
|
|
602
|
+
export function rsyncCannotRunOnWindows(result) {
|
|
603
|
+
const code = result.probe.error && "code" in result.probe.error
|
|
604
|
+
? result.probe.error.code
|
|
605
|
+
: undefined;
|
|
606
|
+
if (code === "ENOENT" || code === "EACCES" || code === RSYNC_UNSAFE_SHIM_PATH)
|
|
607
|
+
return true;
|
|
608
|
+
if (result.probe.error || result.probe.signal)
|
|
609
|
+
return false;
|
|
610
|
+
return result.probe.status !== 0 && result.output.trim() === "";
|
|
611
|
+
}
|
|
612
|
+
/** One-line reason for the log when the Windows fallback is taken. */
|
|
613
|
+
function rsyncProbeFailureSummary(result) {
|
|
614
|
+
const error = result.probe.error;
|
|
615
|
+
if (error)
|
|
616
|
+
return error.code ?? error.name;
|
|
617
|
+
return `exit ${result.probe.status}, no output`;
|
|
618
|
+
}
|
|
566
619
|
function rsyncIsMissing(result) {
|
|
567
620
|
const code = result.probe.error && "code" in result.probe.error
|
|
568
621
|
? result.probe.error.code
|
|
@@ -583,8 +636,9 @@ export const COPY_ENGINE_ENV = "HQ_RESCUE_COPY_ENGINE";
|
|
|
583
636
|
*
|
|
584
637
|
* A working rsync is used as before. When rsync is not on PATH at all, the
|
|
585
638
|
* overlay uses the built-in file copy (./rescue-native-copy.ts) with the same
|
|
586
|
-
* filters, instead of failing with exit 127.
|
|
587
|
-
*
|
|
639
|
+
* filters, instead of failing with exit 127. On Windows an rsync that is on
|
|
640
|
+
* PATH but plainly cannot run (see rsyncCannotRunOnWindows) also uses the
|
|
641
|
+
* built-in copy; any other broken rsync still fails the preflight. `HQ_RESCUE_COPY_ENGINE=rsync`
|
|
588
642
|
* keeps the old rsync-only behaviour; `HQ_RESCUE_COPY_ENGINE=native` uses
|
|
589
643
|
* the built-in copy even when rsync works.
|
|
590
644
|
*/
|
|
@@ -605,6 +659,16 @@ export function selectOverlayCopyEngine(env, out, err) {
|
|
|
605
659
|
out("==> Copy engine: built-in file copy (rsync not found on PATH)\n");
|
|
606
660
|
return { kind: "native" };
|
|
607
661
|
}
|
|
662
|
+
// On Windows an rsync that is on PATH but plainly cannot run (a .cmd shim
|
|
663
|
+
// whose target is gone, an MSYS rsync missing its DLLs) is common and not
|
|
664
|
+
// something the user chose. Use the built-in copy there too, and say why.
|
|
665
|
+
// Any other probe failure, every failure off Windows, and
|
|
666
|
+
// HQ_RESCUE_COPY_ENGINE=rsync still stop the rescue.
|
|
667
|
+
if (forced === "" && process.platform === "win32" && rsyncCannotRunOnWindows(result)) {
|
|
668
|
+
const where = result.foundRsync?.path ?? "PATH";
|
|
669
|
+
out(`==> Copy engine: built-in file copy (rsync at ${boundedDiagnostic(where, 256)} could not run: ${boundedDiagnostic(rsyncProbeFailureSummary(result), 128)})\n`);
|
|
670
|
+
return { kind: "native" };
|
|
671
|
+
}
|
|
608
672
|
return reportRsyncPreflightFailure(result, err);
|
|
609
673
|
}
|
|
610
674
|
/** Print the rsync preflight diagnostic and stop the rescue. */
|
|
@@ -614,7 +678,9 @@ function reportRsyncPreflightFailure({ foundRsync, entries, resolvedPath, probe,
|
|
|
614
678
|
const errorDetail = "code" in probe.error && typeof probe.error.code === "string"
|
|
615
679
|
? probe.error.code
|
|
616
680
|
: probe.error.name;
|
|
617
|
-
err(
|
|
681
|
+
err(errorDetail === "ETIMEDOUT"
|
|
682
|
+
? ` rsync --version did not finish within ${RSYNC_PROBE_TIMEOUT_MS / 1000}s (ETIMEDOUT).\n`
|
|
683
|
+
: ` rsync was not found or could not be executed (${errorDetail}).\n`);
|
|
618
684
|
}
|
|
619
685
|
else if (probe.signal) {
|
|
620
686
|
err(` rsync was terminated by signal ${probe.signal}.\n`);
|
|
@@ -1954,6 +2020,144 @@ export function fullOverlayRsyncFilters(extraPreserve = []) {
|
|
|
1954
2020
|
filters.push(`--exclude=${p}`);
|
|
1955
2021
|
return filters;
|
|
1956
2022
|
}
|
|
2023
|
+
/**
|
|
2024
|
+
* The full overlay filter list for a rescue run. rsync and the native copy
|
|
2025
|
+
* engine apply the first rule that matches, so the order is:
|
|
2026
|
+
* 1. `--preserve` entries (full mode), so a preserved path is never written,
|
|
2027
|
+
* even when a kept install rule below names it;
|
|
2028
|
+
* 2. the install exclusions (kept rules, then excluded ones), in both modes;
|
|
2029
|
+
* 3. the mode's own rules: the narrow-path includes, or the full overlay list.
|
|
2030
|
+
*/
|
|
2031
|
+
export function overlayRsyncFilters(narrowPaths, extraPreserve) {
|
|
2032
|
+
if (narrowPaths.length !== 0) {
|
|
2033
|
+
const filters = [...installExcludedRsyncFilters()];
|
|
2034
|
+
for (const n of narrowPaths) {
|
|
2035
|
+
filters.push(`--include=/${n}`, `--include=/${n}/***`);
|
|
2036
|
+
}
|
|
2037
|
+
filters.push("--exclude=/*");
|
|
2038
|
+
return filters;
|
|
2039
|
+
}
|
|
2040
|
+
return [
|
|
2041
|
+
...extraPreserve.map((p) => `--exclude=${p}`),
|
|
2042
|
+
...installExcludedRsyncFilters(),
|
|
2043
|
+
...fullOverlayRsyncFilters([...extraPreserve]),
|
|
2044
|
+
];
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Test and build files of a release that an install does not receive.
|
|
2048
|
+
*
|
|
2049
|
+
* The release tree (hq-core, and hq-core-staging on the staging channel) keeps
|
|
2050
|
+
* its tests, fixtures and hook corpora, because its own CI runs them. An
|
|
2051
|
+
* install runs none of them, so the overlay does not copy them and the
|
|
2052
|
+
* classifier treats them as absent from the release.
|
|
2053
|
+
*
|
|
2054
|
+
* The list is explicit, in rsync filter syntax. A name with no `/` matches at
|
|
2055
|
+
* any depth, a trailing `/` matches directories only, and a leading `/`
|
|
2056
|
+
* anchors the pattern at the release root. It was derived from the files the
|
|
2057
|
+
* hq-core-staging promotion carried on 2026-11-13:
|
|
2058
|
+
* - `tests/`, `__tests__/`, `__fixtures__/`, `__snapshots__/`: test folders
|
|
2059
|
+
* at any depth (core/scripts/tests, .claude/hooks/tests, skill and worker
|
|
2060
|
+
* test folders, the root `tests/`).
|
|
2061
|
+
* - the anchored folders: the root `test/`, the hook corpus, and two
|
|
2062
|
+
* fixture folders with other names.
|
|
2063
|
+
* - `*.test.<ext>` and `*.spec.<ext>` for code extensions, and `test_*.py`:
|
|
2064
|
+
* test files that sit beside the code they test.
|
|
2065
|
+
* - the anchored files: test runners whose names do not fit a pattern.
|
|
2066
|
+
*
|
|
2067
|
+
* No pattern matches on `-test.` or `test-` alone: worker skill documents such
|
|
2068
|
+
* as `keyboard-test.md`, `screen-reader-test.md`, `write-test.md` and
|
|
2069
|
+
* `load-test.md` are shipped content. `core/hook-tests/` is not listed either:
|
|
2070
|
+
* `hq doctor --deep` reads those hook cases on an install.
|
|
2071
|
+
*/
|
|
2072
|
+
const INSTALL_TEST_EXTENSIONS = ["sh", "bash", "mjs", "cjs", "js", "ts", "tsx", "py", "ps1"];
|
|
2073
|
+
export const INSTALL_EXCLUDED_PATTERNS = [
|
|
2074
|
+
// Everything in core/scripts/tests that INSTALL_KEPT_PATTERNS does not name.
|
|
2075
|
+
"/core/scripts/tests/*",
|
|
2076
|
+
"tests/",
|
|
2077
|
+
"__tests__/",
|
|
2078
|
+
"__fixtures__/",
|
|
2079
|
+
"__snapshots__/",
|
|
2080
|
+
"/test/",
|
|
2081
|
+
"/core/scripts/hook-corpus/",
|
|
2082
|
+
"/core/workers/public/content-shared/test/",
|
|
2083
|
+
"/.claude/skills/daily-brief/scripts/fixtures/",
|
|
2084
|
+
...INSTALL_TEST_EXTENSIONS.flatMap((ext) => [`*.test.${ext}`, `*.spec.${ext}`]),
|
|
2085
|
+
"test_*.py",
|
|
2086
|
+
"/core/scripts/test-codex-hook-adapter.sh",
|
|
2087
|
+
"/core/scripts/anywhere-parity-test.sh",
|
|
2088
|
+
"/core/scripts/anywhere-vm-test.sh",
|
|
2089
|
+
"/.claude/skills/outpost-host/test-guard.sh",
|
|
2090
|
+
];
|
|
2091
|
+
/**
|
|
2092
|
+
* Release paths that match a pattern above and are still installed, because a
|
|
2093
|
+
* shipped script runs them. A kept pattern wins over an excluded one. Remove
|
|
2094
|
+
* an entry when its caller stops shipping.
|
|
2095
|
+
*/
|
|
2096
|
+
export const INSTALL_KEPT_PATTERNS = [
|
|
2097
|
+
// core/workers/public/qa-tester/src/runner.ts runs these Playwright specs
|
|
2098
|
+
// against a target site. They are the worker's payload.
|
|
2099
|
+
"/core/workers/public/qa-tester/tests/***",
|
|
2100
|
+
// The folder itself, so the files named below can be reached.
|
|
2101
|
+
"/core/scripts/tests/",
|
|
2102
|
+
// core/scripts/check-skill-edit.sh runs these six.
|
|
2103
|
+
"/core/scripts/tests/skill-script-refs.test.sh",
|
|
2104
|
+
"/core/scripts/tests/skill-core-script-references.test.sh",
|
|
2105
|
+
"/core/scripts/tests/skill-body-positional-placeholders.test.sh",
|
|
2106
|
+
"/core/scripts/tests/skill-company-bind-before-read.test.sh",
|
|
2107
|
+
"/core/scripts/tests/agent-runtime-skill-metadata.test.sh",
|
|
2108
|
+
"/core/scripts/tests/agent-runtime-permissions.test.sh",
|
|
2109
|
+
// core/scripts/ci/run-shell-smoke-timeout-tests.sh runs these two.
|
|
2110
|
+
"/core/scripts/tests/hook-timeout-sentry.test.sh",
|
|
2111
|
+
"/core/scripts/tests/hook-timeout-watchdog-attribution.test.sh",
|
|
2112
|
+
];
|
|
2113
|
+
/** The install exclusions as overlay filters. They go first: the first match wins. */
|
|
2114
|
+
export function installExcludedRsyncFilters() {
|
|
2115
|
+
return [
|
|
2116
|
+
...INSTALL_KEPT_PATTERNS.map((pattern) => `--include=${pattern}`),
|
|
2117
|
+
...INSTALL_EXCLUDED_PATTERNS.map((pattern) => `--exclude=${pattern}`),
|
|
2118
|
+
];
|
|
2119
|
+
}
|
|
2120
|
+
const INSTALL_KEPT_MATCHERS = INSTALL_KEPT_PATTERNS.map(compileRsyncPattern);
|
|
2121
|
+
const INSTALL_EXCLUDED_MATCHERS = INSTALL_EXCLUDED_PATTERNS.map(compileRsyncPattern);
|
|
2122
|
+
/**
|
|
2123
|
+
* True when `rel` (POSIX separators, relative to the HQ root) is a release
|
|
2124
|
+
* file that an install does not receive. Every ancestor folder is checked, as
|
|
2125
|
+
* rsync does, and a kept pattern wins over an excluded one at each level.
|
|
2126
|
+
*/
|
|
2127
|
+
export function isInstallExcluded(rel) {
|
|
2128
|
+
const segments = rel.split("/").filter((segment) => segment.length > 0);
|
|
2129
|
+
for (let depth = 1; depth <= segments.length; depth++) {
|
|
2130
|
+
const prefix = segments.slice(0, depth).join("/");
|
|
2131
|
+
const isDir = depth < segments.length;
|
|
2132
|
+
if (INSTALL_KEPT_MATCHERS.some((matches) => matches(prefix, isDir)))
|
|
2133
|
+
continue;
|
|
2134
|
+
if (INSTALL_EXCLUDED_MATCHERS.some((matches) => matches(prefix, isDir)))
|
|
2135
|
+
return true;
|
|
2136
|
+
}
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* True when the folder that holds `rel` is the physical folder that path names
|
|
2141
|
+
* under the HQ root. A folder on the way that is a link makes this false,
|
|
2142
|
+
* whether the link points inside or outside the HQ root, so a release file is
|
|
2143
|
+
* never removed through a link.
|
|
2144
|
+
*/
|
|
2145
|
+
export function installPathIsInsideRoot(hqRoot, rel) {
|
|
2146
|
+
const parentSegments = rel
|
|
2147
|
+
.split("/")
|
|
2148
|
+
.filter((segment) => segment.length > 0)
|
|
2149
|
+
.slice(0, -1);
|
|
2150
|
+
if (path.isAbsolute(rel) || rel.split("/").includes(".."))
|
|
2151
|
+
return false;
|
|
2152
|
+
try {
|
|
2153
|
+
const root = fs.realpathSync.native(hqRoot);
|
|
2154
|
+
const parent = fs.realpathSync.native(path.join(hqRoot, ...parentSegments));
|
|
2155
|
+
return parent === path.join(root, ...parentSegments);
|
|
2156
|
+
}
|
|
2157
|
+
catch {
|
|
2158
|
+
return false;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
1957
2161
|
/**
|
|
1958
2162
|
* True when rsync's overlay, run with `filters` (the rescue's `--include=` and
|
|
1959
2163
|
* `--exclude=` list), would transfer `rel`. Every ancestor directory is
|
|
@@ -2313,10 +2517,10 @@ function assertClaudeSettingsAdmission(hqRoot, err) {
|
|
|
2313
2517
|
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) {
|
|
2314
2518
|
const hqRoot = resolveHqRoot(cfg, err);
|
|
2315
2519
|
const RUN_TS = utcStamp(new Date(), "dash");
|
|
2316
|
-
// Choose the overlay engine before classification/allocation.
|
|
2317
|
-
//
|
|
2318
|
-
//
|
|
2319
|
-
//
|
|
2520
|
+
// Choose the overlay engine before classification/allocation. No rsync at
|
|
2521
|
+
// all (stock Windows) uses the built-in copy, and so does a Windows rsync
|
|
2522
|
+
// that plainly cannot run. Any other broken rsync stops here, before an
|
|
2523
|
+
// enormous snapshot is allocated, rather than failing later at overlay.
|
|
2320
2524
|
const copyEngine = selectOverlayCopyEngine(env, out, err);
|
|
2321
2525
|
// The release clone uses `--filter=blob:none`, which needs git 2.19+. Check
|
|
2322
2526
|
// before the prompt so an old git fails with a plain message instead of a
|
|
@@ -2508,7 +2712,11 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2508
2712
|
err(`git ${gitResult.command} did not finish${bound} and was stopped ` +
|
|
2509
2713
|
`(${gitResult.attempts} attempt${gitResult.attempts === 1 ? "" : "s"}).\n`);
|
|
2510
2714
|
}
|
|
2511
|
-
if (gitResult.failureKind === "
|
|
2715
|
+
if (gitResult.failureKind === "proxy-config") {
|
|
2716
|
+
err("HQ_RESCUE_FAILURE_KIND=proxy-config\n");
|
|
2717
|
+
err("error: Git could not resolve the http.proxy setting. Check git config http.proxy (including the HQ root's local .git/config), then retry. Nothing was changed.\n");
|
|
2718
|
+
}
|
|
2719
|
+
else if (gitResult.failureKind === "network-unreachable") {
|
|
2512
2720
|
err("HQ_RESCUE_FAILURE_KIND=network-unreachable\n");
|
|
2513
2721
|
err("error: HQ could not reach GitHub after retries. Check your Internet connection, then retry. Nothing was changed.\n");
|
|
2514
2722
|
}
|
|
@@ -2522,18 +2730,19 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2522
2730
|
throw new ExitError(5);
|
|
2523
2731
|
};
|
|
2524
2732
|
// One bounded ls-remote per update, not per clone or checkout attempt.
|
|
2525
|
-
//
|
|
2526
|
-
// any other probe error is left for the clone to report, so a
|
|
2527
|
-
// probe cannot mask a later clone failure.
|
|
2528
|
-
const probeResult = runGitWithNetworkRetry(["ls-remote", "--exit-code", cloneUrl, cfg.ref], { env, timeout: gitReachabilityProbeTimeoutMs }, out);
|
|
2733
|
+
// network-unreachable, missing-dependency, and proxy-config stop the rescue
|
|
2734
|
+
// here; any other probe error is left for the clone to report, so a
|
|
2735
|
+
// successful probe cannot mask a later clone failure.
|
|
2736
|
+
const probeResult = runGitWithNetworkRetry(["ls-remote", "--exit-code", cloneUrl, cfg.ref], { cwd: tmpdir, env, timeout: gitReachabilityProbeTimeoutMs }, out);
|
|
2529
2737
|
if (probeResult.failureKind === "network-unreachable" ||
|
|
2530
|
-
probeResult.failureKind === "missing-dependency"
|
|
2738
|
+
probeResult.failureKind === "missing-dependency" ||
|
|
2739
|
+
probeResult.failureKind === "proxy-config") {
|
|
2531
2740
|
reportFatalGitFailure(probeResult, "error: clone failed\n");
|
|
2532
2741
|
}
|
|
2533
2742
|
out("\n");
|
|
2534
2743
|
if (cfg.historyCheck) {
|
|
2535
2744
|
out(`==> Cloning ${cloneUrlDisplay} @${cfg.ref} (full history, blob:none filter) ...\n`);
|
|
2536
|
-
const cloneResult = runGitWithNetworkRetry(["clone", "--filter=blob:none", cloneUrl, srcDir], { env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2745
|
+
const cloneResult = runGitWithNetworkRetry(["clone", "--filter=blob:none", cloneUrl, srcDir], { cwd: tmpdir, env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2537
2746
|
if (cloneResult.result.status !== 0) {
|
|
2538
2747
|
reportFatalGitFailure(cloneResult, "error: clone failed\n");
|
|
2539
2748
|
}
|
|
@@ -2544,7 +2753,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2544
2753
|
}
|
|
2545
2754
|
else {
|
|
2546
2755
|
out(`==> Cloning ${cloneUrlDisplay} @${cfg.ref} (shallow) ...\n`);
|
|
2547
|
-
const shallowCloneResult = runGitWithNetworkRetry(["clone", "--depth", "1", "--branch", cfg.ref, cloneUrl, srcDir], { env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2756
|
+
const shallowCloneResult = runGitWithNetworkRetry(["clone", "--depth", "1", "--branch", cfg.ref, cloneUrl, srcDir], { cwd: tmpdir, env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2548
2757
|
if (shallowCloneResult.result.status !== 0) {
|
|
2549
2758
|
if (shouldStopAfterShallowCloneFailure(shallowCloneResult)) {
|
|
2550
2759
|
reportFatalGitFailure(shallowCloneResult, "error: clone failed\n");
|
|
@@ -2552,7 +2761,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2552
2761
|
reportGitFailure(shallowCloneResult.result);
|
|
2553
2762
|
out(" (shallow branch clone failed; trying full clone + checkout)\n");
|
|
2554
2763
|
fs.rmSync(srcDir, { recursive: true, force: true });
|
|
2555
|
-
const cloneResult = runGitWithNetworkRetry(["clone", cloneUrl, srcDir], { env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2764
|
+
const cloneResult = runGitWithNetworkRetry(["clone", cloneUrl, srcDir], { cwd: tmpdir, env }, out, () => fs.rmSync(srcDir, { recursive: true, force: true }));
|
|
2556
2765
|
if (cloneResult.result.status !== 0) {
|
|
2557
2766
|
reportFatalGitFailure(cloneResult, "error: clone failed\n");
|
|
2558
2767
|
}
|
|
@@ -2606,20 +2815,12 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2606
2815
|
}
|
|
2607
2816
|
// --- Build wipe/overlay arg sets per mode ---
|
|
2608
2817
|
const pruneNames = [];
|
|
2609
|
-
|
|
2610
|
-
if (cfg.narrowPaths.length !== 0) {
|
|
2611
|
-
for (const n of cfg.narrowPaths) {
|
|
2612
|
-
rsyncExcludes.push(`--include=/${n}`);
|
|
2613
|
-
rsyncExcludes.push(`--include=/${n}/***`);
|
|
2614
|
-
}
|
|
2615
|
-
rsyncExcludes.push("--exclude=/*");
|
|
2616
|
-
}
|
|
2617
|
-
else {
|
|
2818
|
+
if (cfg.narrowPaths.length === 0) {
|
|
2618
2819
|
pruneNames.push(...ALWAYS_PRESERVED_NAMES);
|
|
2619
2820
|
for (const p of cfg.extraPreserve)
|
|
2620
2821
|
pruneNames.push(p);
|
|
2621
|
-
rsyncExcludes = fullOverlayRsyncFilters(cfg.extraPreserve);
|
|
2622
2822
|
}
|
|
2823
|
+
const rsyncExcludes = overlayRsyncFilters(cfg.narrowPaths, cfg.extraPreserve);
|
|
2623
2824
|
// --- Compute the wipe-set top-level roots ---
|
|
2624
2825
|
const wipeToplevel = [];
|
|
2625
2826
|
if (cfg.narrowPaths.length !== 0) {
|
|
@@ -2655,6 +2856,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2655
2856
|
userConflict: 0,
|
|
2656
2857
|
userOverwrite: 0,
|
|
2657
2858
|
userKeptLocal: 0,
|
|
2859
|
+
installExcludedKept: 0,
|
|
2658
2860
|
claudeDiffAppend: 0,
|
|
2659
2861
|
symlinkDropped: 0,
|
|
2660
2862
|
cloudSymlinkReconciled: 0,
|
|
@@ -2699,6 +2901,11 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2699
2901
|
}
|
|
2700
2902
|
else {
|
|
2701
2903
|
out(`==> Walking wipe set, classifying vs. ${cfg.sourceRepo}@${cfg.ref} ...\n`);
|
|
2904
|
+
const packDirs = installedSkillPackDirs(hqRoot, releaseSkillNames(ctx));
|
|
2905
|
+
if (packDirs.length > 0) {
|
|
2906
|
+
ctx.skipDirs = new Set(packDirs);
|
|
2907
|
+
out(`==> Leaving ${packDirs.length} installed skill pack${packDirs.length === 1 ? "" : "s"} from ${SKILLS_LOCK_FILE} in place without classifying: ${packDirs.map((d) => d.slice(SKILLS_DIR.length + 1)).join(", ")}\n`);
|
|
2908
|
+
}
|
|
2702
2909
|
// Batch the per-file git facts (hashes + floor lookups) up front so the
|
|
2703
2910
|
// walk below is map lookups, not ~3 git spawns per file.
|
|
2704
2911
|
precomputeGitMaps(ctx, wipeToplevel);
|
|
@@ -2716,6 +2923,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2716
2923
|
out(` user-edit (conflict quarantine): ${counts.userConflict} files\n`);
|
|
2717
2924
|
out(` user-edit (overwrite-safe): ${counts.userOverwrite} files\n`);
|
|
2718
2925
|
out(` user-edit (kept local): ${counts.userKeptLocal} files\n`);
|
|
2926
|
+
out(` release test files kept (not installed): ${counts.installExcludedKept} files\n`);
|
|
2719
2927
|
out(` cloud-symlink reconciled: ${counts.cloudSymlinkReconciled} files\n`);
|
|
2720
2928
|
out(` drift reconciled (== upstream): ${counts.driftReconciled} files\n`);
|
|
2721
2929
|
out(` reindex symlinks dropped: ${counts.symlinkDropped} entries\n`);
|
|
@@ -3037,7 +3245,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
3037
3245
|
mutationStarted = true;
|
|
3038
3246
|
applyClassifiedActions(ctx, backupDir);
|
|
3039
3247
|
out("\n");
|
|
3040
|
-
out(`==> Walk complete (user-only: ${counts.userOnly}, unchanged: ${counts.unchanged}, user-edit-rescued: ${counts.userEdit}, conflict-quarantined: ${counts.userConflict}, overwrite-safe: ${counts.userOverwrite}, kept-local: ${counts.userKeptLocal}, cloud-symlink-reconciled: ${counts.cloudSymlinkReconciled}, symlinks-dropped: ${counts.symlinkDropped})\n`);
|
|
3248
|
+
out(`==> Walk complete (user-only: ${counts.userOnly}, unchanged: ${counts.unchanged}, user-edit-rescued: ${counts.userEdit}, conflict-quarantined: ${counts.userConflict}, overwrite-safe: ${counts.userOverwrite}, kept-local: ${counts.userKeptLocal}, release-test-kept: ${counts.installExcludedKept}, cloud-symlink-reconciled: ${counts.cloudSymlinkReconciled}, symlinks-dropped: ${counts.symlinkDropped})\n`);
|
|
3041
3249
|
// --- Overlay source onto HQ root ---
|
|
3042
3250
|
out("==> Overlaying source onto HQ root ...\n");
|
|
3043
3251
|
// `unchangedList` is only populated during applyClassifiedActions above, so
|
|
@@ -3221,6 +3429,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
3221
3429
|
out(` user-edits (conflict quarantine): ${counts.userConflict} files\n`);
|
|
3222
3430
|
out(` user-edits (overwrite-safe): ${counts.userOverwrite} files\n`);
|
|
3223
3431
|
out(` user-edit (kept local): ${counts.userKeptLocal} files\n`);
|
|
3432
|
+
out(` release test files kept (not installed): ${counts.installExcludedKept} files\n`);
|
|
3224
3433
|
out(` cloud-symlink reconciled: ${counts.cloudSymlinkReconciled} files\n`);
|
|
3225
3434
|
out(` drift reconciled (== upstream): ${counts.driftReconciled} files\n`);
|
|
3226
3435
|
out(` reindex symlinks dropped: ${counts.symlinkDropped} entries\n`);
|
|
@@ -3256,6 +3465,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
3256
3465
|
lines.push(` user-edit (conflict quarantine): ${counts.userConflict}`);
|
|
3257
3466
|
lines.push(` user-edit (overwrite-safe): ${counts.userOverwrite}`);
|
|
3258
3467
|
lines.push(` user-edit (kept local, ignore file): ${counts.userKeptLocal}`);
|
|
3468
|
+
lines.push(` release test files kept (not installed): ${counts.installExcludedKept}`);
|
|
3259
3469
|
lines.push(` cloud-symlink reconciled: ${counts.cloudSymlinkReconciled}`);
|
|
3260
3470
|
lines.push(` drift reconciled (== upstream HEAD): ${counts.driftReconciled}`);
|
|
3261
3471
|
lines.push(` reindex symlinks dropped: ${counts.symlinkDropped}`);
|
|
@@ -3399,6 +3609,9 @@ function recordDecision(ctx, decision) {
|
|
|
3399
3609
|
case "user-only":
|
|
3400
3610
|
ctx.counts.userOnly += 1;
|
|
3401
3611
|
return;
|
|
3612
|
+
case "install-excluded-kept":
|
|
3613
|
+
ctx.counts.installExcludedKept += 1;
|
|
3614
|
+
return;
|
|
3402
3615
|
case "cloud-symlink-reconciled":
|
|
3403
3616
|
ctx.counts.cloudSymlinkReconciled += 1;
|
|
3404
3617
|
return;
|
|
@@ -4008,6 +4221,24 @@ export function applyArrayRemovals(theirs, ours, base) {
|
|
|
4008
4221
|
}
|
|
4009
4222
|
}
|
|
4010
4223
|
}
|
|
4224
|
+
/**
|
|
4225
|
+
* True when every array element that `release` and `ours` share (at the same
|
|
4226
|
+
* path) is also present in `candidate`. Used to find how far back an older
|
|
4227
|
+
* release settings.json can be while still being one the local file could have
|
|
4228
|
+
* been laid from: a version missing an element the local file has from the
|
|
4229
|
+
* release is older than the version the local file was laid from.
|
|
4230
|
+
*/
|
|
4231
|
+
export function holdsSharedArrayEntries(candidate, ours, release) {
|
|
4232
|
+
if (Array.isArray(release) && Array.isArray(ours)) {
|
|
4233
|
+
const cand = Array.isArray(candidate) ? candidate : [];
|
|
4234
|
+
return release.every((e) => !ours.some((o) => jsonDeepEqual(o, e)) || cand.some((c) => jsonDeepEqual(c, e)));
|
|
4235
|
+
}
|
|
4236
|
+
if (isPlainObject(release) && isPlainObject(ours)) {
|
|
4237
|
+
const cand = isPlainObject(candidate) ? candidate : {};
|
|
4238
|
+
return Object.keys(release).every((k) => holdsSharedArrayEntries(cand[k], ours[k], release[k]));
|
|
4239
|
+
}
|
|
4240
|
+
return true;
|
|
4241
|
+
}
|
|
4011
4242
|
/**
|
|
4012
4243
|
* Re-compose the machine env.PATH for the freshly-overlaid release template.
|
|
4013
4244
|
* Runs the SAME composer setup.sh uses (core/scripts/compose-settings-path.sh)
|
|
@@ -4327,18 +4558,70 @@ export function reconcileClaudeSettings(ctx, preRescueSettingsJson, out, err) {
|
|
|
4327
4558
|
// realBase = settings.json at the last-sync floor (only trustworthy in
|
|
4328
4559
|
// history_floor mode). Removals require it; additions fall back to theirs.
|
|
4329
4560
|
let realBase;
|
|
4561
|
+
let removalBase;
|
|
4330
4562
|
if (baselineMode === "history_floor" && historyFloor) {
|
|
4331
|
-
const
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4563
|
+
const settingsAt = (rev) => {
|
|
4564
|
+
const show = run("git", ["show", `${rev}:.claude/settings.json`], {
|
|
4565
|
+
cwd: srcDir,
|
|
4566
|
+
env,
|
|
4567
|
+
});
|
|
4568
|
+
return show.status === 0 ? jsonParseOrNull(show.stdout) : undefined;
|
|
4569
|
+
};
|
|
4570
|
+
const revParse = (rev) => {
|
|
4571
|
+
const r = run("git", ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`], {
|
|
4572
|
+
cwd: srcDir,
|
|
4573
|
+
env,
|
|
4574
|
+
});
|
|
4575
|
+
return r.status === 0 ? r.stdout.trim() : "";
|
|
4576
|
+
};
|
|
4577
|
+
realBase = settingsAt(historyFloor);
|
|
4578
|
+
removalBase = realBase;
|
|
4579
|
+
const floorCommit = revParse(historyFloor);
|
|
4580
|
+
if (isPlainObject(realBase) && floorCommit !== "" && floorCommit === revParse("HEAD")) {
|
|
4581
|
+
// DEV-6811: the floor IS the release being applied, so its settings.json
|
|
4582
|
+
// is the release file itself and every release entry missing locally
|
|
4583
|
+
// (e.g. a hook a recent release added that never got wired in) would
|
|
4584
|
+
// look like a user removal. Walk back through older versions of
|
|
4585
|
+
// settings.json while each still holds every release array entry the
|
|
4586
|
+
// local file has: the local file was laid from such a version or an
|
|
4587
|
+
// older one, so entries added after it were never there to remove.
|
|
4588
|
+
// Removals are then detected against the oldest such version. When the
|
|
4589
|
+
// previous version already lacks an entry the local file has, the base
|
|
4590
|
+
// stays the release file (a repeat run at the same release).
|
|
4591
|
+
const changes = run("git", ["log", "-n", "50", "--format=%H", "HEAD", "--", ".claude/settings.json"], { cwd: srcDir, env });
|
|
4592
|
+
const changeShas = changes.status === 0 ? changes.stdout.split("\n").map((s) => s.trim()).filter(Boolean) : [];
|
|
4593
|
+
let readFailed = changes.status !== 0;
|
|
4594
|
+
for (const sha of changeShas) {
|
|
4595
|
+
const older = settingsAt(`${sha}^`);
|
|
4596
|
+
if (!isPlainObject(older)) {
|
|
4597
|
+
// The tree is local in a blob:none clone, so a path that exists but
|
|
4598
|
+
// whose content could not be read (failed blob fetch) or parsed is
|
|
4599
|
+
// a read failure. A path that does not exist ends the walk normally.
|
|
4600
|
+
const exists = run("git", ["rev-parse", "--verify", "--quiet", `${sha}^:.claude/settings.json`], {
|
|
4601
|
+
cwd: srcDir,
|
|
4602
|
+
env,
|
|
4603
|
+
});
|
|
4604
|
+
if (exists.status === 0)
|
|
4605
|
+
readFailed = true;
|
|
4606
|
+
break;
|
|
4607
|
+
}
|
|
4608
|
+
if (!holdsSharedArrayEntries(older, ours, realBase))
|
|
4609
|
+
break;
|
|
4610
|
+
removalBase = older;
|
|
4611
|
+
}
|
|
4612
|
+
if (readFailed) {
|
|
4613
|
+
// Fall back to the floor file, as before this fix. The drift may stay
|
|
4614
|
+
// unfixed this run, but a user's deliberate removals are never undone
|
|
4615
|
+
// (undoing them would be permanent: the next run sees them as kept).
|
|
4616
|
+
removalBase = realBase;
|
|
4617
|
+
err(" WARN: could not read an older release version of .claude/settings.json; kept the previous behavior\n");
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4337
4620
|
}
|
|
4338
|
-
// Removals: only with a REAL
|
|
4339
|
-
// would look like removals).
|
|
4340
|
-
if (isPlainObject(
|
|
4341
|
-
applyArrayRemovals(theirs, ours,
|
|
4621
|
+
// Removals: only with a REAL older-release base (never theirs — release-only
|
|
4622
|
+
// entries would look like removals).
|
|
4623
|
+
if (isPlainObject(removalBase)) {
|
|
4624
|
+
applyArrayRemovals(theirs, ours, removalBase);
|
|
4342
4625
|
}
|
|
4343
4626
|
// Additions drift: base = realBase when available, else theirs (conservative
|
|
4344
4627
|
// head_compare fallback — never loses a customization). See design note.
|
|
@@ -4680,8 +4963,10 @@ function classifyOne(ctx, filesystemRel) {
|
|
|
4680
4963
|
}
|
|
4681
4964
|
return { kind: "skip", rel };
|
|
4682
4965
|
}
|
|
4683
|
-
// Is path in upstream HEAD?
|
|
4684
|
-
|
|
4966
|
+
// Is path in upstream HEAD? A test or build file of the release counts as
|
|
4967
|
+
// absent: the release tree holds it and the install does not receive it.
|
|
4968
|
+
const installExcluded = isInstallExcluded(rel);
|
|
4969
|
+
const inHead = !installExcluded && existsFollow(srcPath) ? 1 : 0;
|
|
4685
4970
|
// Is path in last-sync floor? Read the batched precompute (floorShas); fall
|
|
4686
4971
|
// back to a per-file probe for any rel not represented there. A non-null
|
|
4687
4972
|
// entry both proves presence (inFloor=1) and carries the baseline blob SHA,
|
|
@@ -4707,6 +4992,26 @@ function classifyOne(ctx, filesystemRel) {
|
|
|
4707
4992
|
if (inHead === 0 && inFloor === 0) {
|
|
4708
4993
|
return { kind: "user-only", rel };
|
|
4709
4994
|
}
|
|
4995
|
+
// A release test file the previous release installed. Remove it only when
|
|
4996
|
+
// it is byte-identical to that released copy and no folder on its path is a
|
|
4997
|
+
// link. Anything else is kept in place and reported. Without a
|
|
4998
|
+
// floor (head_compare) inFloor is 0 and the file was left as user-only above.
|
|
4999
|
+
if (installExcluded) {
|
|
5000
|
+
if (!installPathIsInsideRoot(ctx.hqRoot, rel)) {
|
|
5001
|
+
return { kind: "install-excluded-kept", rel, reason: "linked-folder" };
|
|
5002
|
+
}
|
|
5003
|
+
const localSha = ctx.localShas?.get(rel) ??
|
|
5004
|
+
run("git", ["hash-object", localPath], { env: ctx.env }).stdout.trim();
|
|
5005
|
+
const floorSha = baselineSha ??
|
|
5006
|
+
run("git", ["rev-parse", `${ctx.historyFloor}:${rel}`], {
|
|
5007
|
+
cwd: ctx.srcDir,
|
|
5008
|
+
env: ctx.env,
|
|
5009
|
+
}).stdout.trim();
|
|
5010
|
+
if (!localSha || !floorSha || localSha !== floorSha) {
|
|
5011
|
+
return { kind: "install-excluded-kept", rel, reason: "edited" };
|
|
5012
|
+
}
|
|
5013
|
+
return { kind: "unchanged-delete", rel };
|
|
5014
|
+
}
|
|
4710
5015
|
// Path is/was in upstream. Determine if user edited it.
|
|
4711
5016
|
let userEdited = 0;
|
|
4712
5017
|
// Set only by the floor comparison below — the one arm that proves the local
|
|
@@ -4833,6 +5138,9 @@ function renderDryRunDecision(ctx, decision) {
|
|
|
4833
5138
|
ctx.out(` unchanged (delete; absent upstream): ${decision.rel}\n`);
|
|
4834
5139
|
}
|
|
4835
5140
|
break;
|
|
5141
|
+
case "install-excluded-kept":
|
|
5142
|
+
ctx.out(` ${installExcludedKeptLine(decision)}\n`);
|
|
5143
|
+
break;
|
|
4836
5144
|
case "wholesale-replace-template":
|
|
4837
5145
|
ctx.out(" wholesale-replace: companies/_template (template carve-out)\n");
|
|
4838
5146
|
break;
|
|
@@ -4975,6 +5283,13 @@ function buildRescueActions(ctx) {
|
|
|
4975
5283
|
});
|
|
4976
5284
|
}
|
|
4977
5285
|
break;
|
|
5286
|
+
case "install-excluded-kept":
|
|
5287
|
+
// Nothing moves or is deleted, and the overlay never writes here.
|
|
5288
|
+
add(`keep release test file: ${decision.rel}`, [], () => {
|
|
5289
|
+
ctx.out(` ${installExcludedKeptLine(decision)}\n`);
|
|
5290
|
+
ctx.appendLog(`kept-release-test-file\t${decision.rel}\t(${decision.reason === "edited" ? "differs from the released copy" : "a folder on its path is a link"}; no longer installed, left in place)\n`);
|
|
5291
|
+
});
|
|
5292
|
+
break;
|
|
4978
5293
|
case "wholesale-replace-template":
|
|
4979
5294
|
add("wholesale-replace: companies/_template", [decision.rel], () => fs.rmSync(path.join(ctx.hqRoot, "companies", "_template"), {
|
|
4980
5295
|
recursive: true,
|
|
@@ -4986,8 +5301,16 @@ function buildRescueActions(ctx) {
|
|
|
4986
5301
|
return actions;
|
|
4987
5302
|
}
|
|
4988
5303
|
function unchangedDeletePathExistsUpstream(ctx, rel) {
|
|
5304
|
+
// The release clone still holds its test files; the install does not get them.
|
|
5305
|
+
if (isInstallExcluded(normalizeRescueRelativePath(rel, ctx.pathSep)))
|
|
5306
|
+
return false;
|
|
4989
5307
|
return lexists(path.join(ctx.srcDir, rel));
|
|
4990
5308
|
}
|
|
5309
|
+
export function installExcludedKeptLine(decision) {
|
|
5310
|
+
return decision.reason === "edited"
|
|
5311
|
+
? `kept (release test file you changed; HQ no longer installs it, delete it by hand): ${decision.rel}`
|
|
5312
|
+
: `kept (release test file reached through a linked folder; rescue does not delete through a link): ${decision.rel}`;
|
|
5313
|
+
}
|
|
4991
5314
|
/** Make rsync's size+mtime quick check notice changed bytes in the same second. */
|
|
4992
5315
|
function ensureRsyncDetectsChangedFile(localPath, upstreamPath) {
|
|
4993
5316
|
const local = lstatOrNull(localPath);
|
|
@@ -5028,7 +5351,7 @@ function precomputeGitMaps(ctx, wipeToplevel) {
|
|
|
5028
5351
|
const rels = lst.isFile()
|
|
5029
5352
|
? [rootRel]
|
|
5030
5353
|
: lst.isDirectory()
|
|
5031
|
-
? findFilesAndSymlinks(rootAbs, ctx.hqRoot)
|
|
5354
|
+
? findFilesAndSymlinks(rootAbs, ctx.hqRoot, ctx.skipDirs)
|
|
5032
5355
|
: [];
|
|
5033
5356
|
for (const filesystemRel of rels) {
|
|
5034
5357
|
// A path containing a newline can't survive line-delimited batch stdin;
|
|
@@ -5051,27 +5374,26 @@ function precomputeGitMaps(ctx, wipeToplevel) {
|
|
|
5051
5374
|
ctx.localShas = new Map();
|
|
5052
5375
|
return;
|
|
5053
5376
|
}
|
|
5054
|
-
// Pass 1: floor existence + blob SHA for every rel, in chunked batches.
|
|
5055
|
-
// `cat-file --batch-check` prints "<sha> <type> <size>" for a present object
|
|
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`
|
|
5058
|
-
// (sha). It reads only the git object DB — never local file contents — so it
|
|
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.
|
|
5063
5377
|
const floorShas = new Map();
|
|
5064
5378
|
if (allRels.length > 0) {
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
}
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5379
|
+
let tree;
|
|
5380
|
+
try {
|
|
5381
|
+
tree = readTreeObjectShas(ctx.historyFloor, {
|
|
5382
|
+
cwd: ctx.srcDir,
|
|
5383
|
+
env: ctx.env,
|
|
5384
|
+
});
|
|
5385
|
+
}
|
|
5386
|
+
catch (e) {
|
|
5387
|
+
if (!(e instanceof GitBatchError))
|
|
5388
|
+
throw e;
|
|
5389
|
+
process.stderr.write(`\nERROR: listing the last-synced release failed while classifying ${allRels.length} paths; aborting before any file is touched.\n${e.message}\n`);
|
|
5390
|
+
throw new ExitError(1);
|
|
5391
|
+
}
|
|
5392
|
+
for (const [rel, sha] of tree)
|
|
5393
|
+
floorShas.set(rel, sha);
|
|
5394
|
+
for (const rel of allRels) {
|
|
5395
|
+
if (!floorShas.has(rel))
|
|
5396
|
+
floorShas.set(rel, null);
|
|
5075
5397
|
}
|
|
5076
5398
|
}
|
|
5077
5399
|
ctx.floorShas = floorShas;
|
|
@@ -5128,16 +5450,31 @@ export function hashLocalFilesInChunks(absPaths, env, warn, chunkSize = GIT_BATC
|
|
|
5128
5450
|
}
|
|
5129
5451
|
return out;
|
|
5130
5452
|
}
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5453
|
+
/**
|
|
5454
|
+
* Object SHA for every blob, symlink and tree path in `ref`, keyed by its
|
|
5455
|
+
* repo-relative path. Reads tree objects only, so a `--filter=blob:none`
|
|
5456
|
+
* clone answers it from its local object store with no promisor fetch.
|
|
5457
|
+
*/
|
|
5458
|
+
export function readTreeObjectShas(ref, opts) {
|
|
5459
|
+
const args = ["ls-tree", "-r", "-t", "-z", "--full-tree", ref];
|
|
5460
|
+
const res = run("git", args, {
|
|
5461
|
+
cwd: opts.cwd,
|
|
5462
|
+
env: opts.env,
|
|
5463
|
+
maxBuffer: GIT_BATCH_MAX_BUFFER,
|
|
5464
|
+
});
|
|
5465
|
+
if (res.status !== 0 || res.error || res.signal) {
|
|
5466
|
+
throw new GitBatchError(args, res, 0, 1);
|
|
5134
5467
|
}
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5468
|
+
const shas = new Map();
|
|
5469
|
+
for (const entry of res.stdout.split("\0")) {
|
|
5470
|
+
const tab = entry.indexOf("\t");
|
|
5471
|
+
if (tab < 0)
|
|
5472
|
+
continue;
|
|
5473
|
+
const [, type, sha] = entry.slice(0, tab).split(" ");
|
|
5474
|
+
if (type === "blob" || type === "tree")
|
|
5475
|
+
shas.set(entry.slice(tab + 1), sha);
|
|
5140
5476
|
}
|
|
5477
|
+
return shas;
|
|
5141
5478
|
}
|
|
5142
5479
|
function walkAndProcess(ctx, rootRel) {
|
|
5143
5480
|
const rootAbs = path.join(ctx.hqRoot, rootRel);
|
|
@@ -5188,7 +5525,7 @@ function walkAndProcess(ctx, rootRel) {
|
|
|
5188
5525
|
return;
|
|
5189
5526
|
}
|
|
5190
5527
|
// Top-level directory: recursive walk, pruning canonical transient state.
|
|
5191
|
-
for (const rel of findFilesAndSymlinks(rootAbs, ctx.hqRoot)) {
|
|
5528
|
+
for (const rel of findFilesAndSymlinks(rootAbs, ctx.hqRoot, ctx.skipDirs)) {
|
|
5192
5529
|
recordDecision(ctx, classifyOne(ctx, rel));
|
|
5193
5530
|
}
|
|
5194
5531
|
}
|
|
@@ -5197,7 +5534,7 @@ function walkAndProcess(ctx, rootRel) {
|
|
|
5197
5534
|
* transient directories and never descending into directory symlinks. Order is
|
|
5198
5535
|
* deterministic so classification and apply plans remain reproducible.
|
|
5199
5536
|
*/
|
|
5200
|
-
function findFilesAndSymlinks(rootAbs, hqRoot) {
|
|
5537
|
+
function findFilesAndSymlinks(rootAbs, hqRoot, skipDirs = EMPTY_SKIP_DIRS) {
|
|
5201
5538
|
const found = [];
|
|
5202
5539
|
const walk = (dir) => {
|
|
5203
5540
|
let entries;
|
|
@@ -5226,6 +5563,8 @@ function findFilesAndSymlinks(rootAbs, hqRoot) {
|
|
|
5226
5563
|
const rel = abs.slice(hqRoot.length + 1);
|
|
5227
5564
|
if (isRescueTransientDirectory(rel))
|
|
5228
5565
|
continue;
|
|
5566
|
+
if (skipDirs.size > 0 && skipDirs.has(rel.replace(/\\/g, "/")))
|
|
5567
|
+
continue;
|
|
5229
5568
|
walk(abs);
|
|
5230
5569
|
continue;
|
|
5231
5570
|
}
|
|
@@ -5237,6 +5576,75 @@ function findFilesAndSymlinks(rootAbs, hqRoot) {
|
|
|
5237
5576
|
walk(rootAbs);
|
|
5238
5577
|
return found;
|
|
5239
5578
|
}
|
|
5579
|
+
const EMPTY_SKIP_DIRS = new Set();
|
|
5580
|
+
const SKILLS_LOCK_FILE = "skills-lock.json";
|
|
5581
|
+
const SKILLS_DIR = ".claude/skills";
|
|
5582
|
+
/**
|
|
5583
|
+
* Skill packs the operator installed from a third-party source are recorded
|
|
5584
|
+
* in `<hqRoot>/skills-lock.json` and copied under `.claude/skills/<name>`.
|
|
5585
|
+
* The release never ships them, so every file inside classifies as user-only
|
|
5586
|
+
* and is left in place; walking them only costs time (one Shopify toolkit is
|
|
5587
|
+
* 27k files). Return the `.claude/skills/<name>` directories that are safe to
|
|
5588
|
+
* leave out of the walk: listed in the lock file, a real directory locally,
|
|
5589
|
+
* and absent from both the release HEAD and the baseline floor, so no file
|
|
5590
|
+
* inside can be release content.
|
|
5591
|
+
*/
|
|
5592
|
+
export function installedSkillPackDirs(hqRoot, releaseSkillNames) {
|
|
5593
|
+
let lock;
|
|
5594
|
+
try {
|
|
5595
|
+
lock = JSON.parse(fs.readFileSync(path.join(hqRoot, SKILLS_LOCK_FILE), "utf-8"));
|
|
5596
|
+
}
|
|
5597
|
+
catch {
|
|
5598
|
+
return [];
|
|
5599
|
+
}
|
|
5600
|
+
const skills = lock && typeof lock === "object" ? lock.skills : undefined;
|
|
5601
|
+
if (!skills || typeof skills !== "object" || Array.isArray(skills))
|
|
5602
|
+
return [];
|
|
5603
|
+
const dirs = [];
|
|
5604
|
+
for (const name of Object.keys(skills).sort()) {
|
|
5605
|
+
if (name === "" ||
|
|
5606
|
+
name === "." ||
|
|
5607
|
+
name === ".." ||
|
|
5608
|
+
name.includes("/") ||
|
|
5609
|
+
name.includes("\\") ||
|
|
5610
|
+
name.includes("\n")) {
|
|
5611
|
+
continue;
|
|
5612
|
+
}
|
|
5613
|
+
if (releaseSkillNames.has(name))
|
|
5614
|
+
continue;
|
|
5615
|
+
const st = lstatOrNull(path.join(hqRoot, SKILLS_DIR, name));
|
|
5616
|
+
if (!st || !st.isDirectory())
|
|
5617
|
+
continue;
|
|
5618
|
+
dirs.push(`${SKILLS_DIR}/${name}`);
|
|
5619
|
+
}
|
|
5620
|
+
return dirs;
|
|
5621
|
+
}
|
|
5622
|
+
/** Skill directory names present in the release HEAD and, when there is one, the baseline floor. */
|
|
5623
|
+
function releaseSkillNames(ctx) {
|
|
5624
|
+
const names = new Set();
|
|
5625
|
+
let headEntries = [];
|
|
5626
|
+
try {
|
|
5627
|
+
headEntries = fs.readdirSync(path.join(ctx.srcDir, SKILLS_DIR));
|
|
5628
|
+
}
|
|
5629
|
+
catch {
|
|
5630
|
+
headEntries = [];
|
|
5631
|
+
}
|
|
5632
|
+
for (const name of headEntries)
|
|
5633
|
+
names.add(name);
|
|
5634
|
+
if (ctx.baselineMode === "history_floor") {
|
|
5635
|
+
const res = run("git", ["ls-tree", "--name-only", `${ctx.historyFloor}:${SKILLS_DIR}`], {
|
|
5636
|
+
cwd: ctx.srcDir,
|
|
5637
|
+
env: ctx.env,
|
|
5638
|
+
});
|
|
5639
|
+
if (res.status === 0) {
|
|
5640
|
+
for (const line of res.stdout.split("\n")) {
|
|
5641
|
+
if (line !== "")
|
|
5642
|
+
names.add(line);
|
|
5643
|
+
}
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
return names;
|
|
5647
|
+
}
|
|
5240
5648
|
// --- restore file mtimes from git commit history ---
|
|
5241
5649
|
function restoreMtimesFromGit(srcDir, env, out) {
|
|
5242
5650
|
// Deepen a shallow clone so per-file commit times are real.
|
|
@@ -6474,13 +6882,18 @@ function isSkippedSnapshotPath(ctx, rel) {
|
|
|
6474
6882
|
* backslash escapes only in a pattern that holds a wildcard (`*`, `?`, `[`,
|
|
6475
6883
|
* or the `/***` suffix of a recursive entry), so escape only then; a plain
|
|
6476
6884
|
* name with a backslash is compared literally and must stay as it is.
|
|
6885
|
+
* A backslash inside an escaped entry is written as a bracket class holding
|
|
6886
|
+
* one escaped backslash, because openrsync ignores a doubled backslash there.
|
|
6477
6887
|
*/
|
|
6478
6888
|
export function appendLiteralRsyncExclude(excludeList, rel, recursive = false) {
|
|
6479
6889
|
let pattern = rel;
|
|
6480
6890
|
if (recursive || /[*?[]/.test(pattern)) {
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6891
|
+
// A backslash becomes a bracket class holding one escaped backslash, not a
|
|
6892
|
+
// doubled backslash. GNU rsync reads both, but openrsync (the /usr/bin/rsync
|
|
6893
|
+
// on macOS) does not honour the doubled form and would leave the path
|
|
6894
|
+
// unprotected. The bracket form matches a literal backslash in GNU rsync,
|
|
6895
|
+
// openrsync, and the built-in copy.
|
|
6896
|
+
pattern = pattern.replace(/[\\*?[]/g, (ch) => ch === "\\" ? "[\\\\]" : `\\${ch}`);
|
|
6484
6897
|
}
|
|
6485
6898
|
fs.appendFileSync(excludeList, `/${pattern}${recursive ? "/***" : ""}\0`);
|
|
6486
6899
|
}
|