@indigoai-us/hq-cloud 6.18.75 → 6.18.76

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 (84) hide show
  1. package/dist/agent-codex-instructions.d.ts.map +1 -1
  2. package/dist/agent-codex-instructions.js +4 -1
  3. package/dist/agent-codex-instructions.js.map +1 -1
  4. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  5. package/dist/bin/sync-runner-company.js +14 -0
  6. package/dist/bin/sync-runner-company.js.map +1 -1
  7. package/dist/bin/sync-runner-manifest.d.ts.map +1 -1
  8. package/dist/bin/sync-runner-manifest.js +17 -2
  9. package/dist/bin/sync-runner-manifest.js.map +1 -1
  10. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-watch-loop.js +2 -1
  12. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  13. package/dist/bin/sync-runner.d.ts +5 -0
  14. package/dist/bin/sync-runner.d.ts.map +1 -1
  15. package/dist/bin/sync-runner.js.map +1 -1
  16. package/dist/cli/reindex-knowledge.d.ts.map +1 -1
  17. package/dist/cli/reindex-knowledge.js +6 -1
  18. package/dist/cli/reindex-knowledge.js.map +1 -1
  19. package/dist/cli/rescue-core.d.ts +77 -0
  20. package/dist/cli/rescue-core.d.ts.map +1 -1
  21. package/dist/cli/rescue-core.js +467 -14
  22. package/dist/cli/rescue-core.js.map +1 -1
  23. package/dist/cli/share.d.ts +130 -0
  24. package/dist/cli/share.d.ts.map +1 -1
  25. package/dist/cli/share.js +50 -14
  26. package/dist/cli/share.js.map +1 -1
  27. package/dist/cli/sync.d.ts +46 -5
  28. package/dist/cli/sync.d.ts.map +1 -1
  29. package/dist/cli/sync.js +274 -23
  30. package/dist/cli/sync.js.map +1 -1
  31. package/dist/cloud-placeholder.d.ts +6 -0
  32. package/dist/cloud-placeholder.d.ts.map +1 -1
  33. package/dist/cloud-placeholder.js +16 -7
  34. package/dist/cloud-placeholder.js.map +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/lib/board-merge.d.ts +25 -0
  40. package/dist/lib/board-merge.d.ts.map +1 -0
  41. package/dist/lib/board-merge.js +201 -0
  42. package/dist/lib/board-merge.js.map +1 -0
  43. package/dist/lib/readlink-safe.d.ts +24 -1
  44. package/dist/lib/readlink-safe.d.ts.map +1 -1
  45. package/dist/lib/readlink-safe.js +29 -2
  46. package/dist/lib/readlink-safe.js.map +1 -1
  47. package/dist/manifest/build-manifest.d.ts.map +1 -1
  48. package/dist/manifest/build-manifest.js +2 -1
  49. package/dist/manifest/build-manifest.js.map +1 -1
  50. package/dist/manifest/upload-manifest.d.ts +11 -0
  51. package/dist/manifest/upload-manifest.d.ts.map +1 -1
  52. package/dist/manifest/upload-manifest.js +60 -3
  53. package/dist/manifest/upload-manifest.js.map +1 -1
  54. package/dist/s3.d.ts +15 -0
  55. package/dist/s3.d.ts.map +1 -1
  56. package/dist/s3.js +22 -6
  57. package/dist/s3.js.map +1 -1
  58. package/dist/scope-shrink.d.ts +86 -3
  59. package/dist/scope-shrink.d.ts.map +1 -1
  60. package/dist/scope-shrink.js +177 -24
  61. package/dist/scope-shrink.js.map +1 -1
  62. package/dist/session-log-capture.d.ts.map +1 -1
  63. package/dist/session-log-capture.js +18 -2
  64. package/dist/session-log-capture.js.map +1 -1
  65. package/dist/skill-telemetry.d.ts.map +1 -1
  66. package/dist/skill-telemetry.js +10 -5
  67. package/dist/skill-telemetry.js.map +1 -1
  68. package/dist/sync/area-ledger.d.ts +4 -2
  69. package/dist/sync/area-ledger.d.ts.map +1 -1
  70. package/dist/sync/area-ledger.js +16 -4
  71. package/dist/sync/area-ledger.js.map +1 -1
  72. package/dist/sync/pull-scope.d.ts +7 -0
  73. package/dist/sync/pull-scope.d.ts.map +1 -1
  74. package/dist/sync/pull-scope.js +2 -0
  75. package/dist/sync/pull-scope.js.map +1 -1
  76. package/dist/sync/scope-inventory-client.d.ts.map +1 -1
  77. package/dist/sync/scope-inventory-client.js +2 -1
  78. package/dist/sync/scope-inventory-client.js.map +1 -1
  79. package/dist/types.d.ts +20 -0
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/watcher.d.ts.map +1 -1
  82. package/dist/watcher.js +23 -0
  83. package/dist/watcher.js.map +1 -1
  84. package/package.json +1 -1
@@ -552,6 +552,142 @@ function bytesEqual(a, b) {
552
552
  return false;
553
553
  }
554
554
  }
555
+ /** Index entries recorded as symlinks (mode 120000), with their blob SHA. */
556
+ function gitSymlinkEntries(repoDir, env) {
557
+ const res = run("git", ["ls-files", "-s", "-z"], { cwd: repoDir, env });
558
+ if (res.status !== 0)
559
+ return [];
560
+ const entries = [];
561
+ for (const record of res.stdout.split("\0")) {
562
+ const tab = record.indexOf("\t");
563
+ if (tab < 0)
564
+ continue;
565
+ const [mode, sha] = record.slice(0, tab).split(/\s+/);
566
+ if (mode === "120000" && sha)
567
+ entries.push({ rel: record.slice(tab + 1), sha });
568
+ }
569
+ return entries;
570
+ }
571
+ /** Paths the index records as symlinks (mode 120000). */
572
+ function gitSymlinkPaths(repoDir, env) {
573
+ return gitSymlinkEntries(repoDir, env).map((entry) => entry.rel);
574
+ }
575
+ const gitSymlinkPathsAtRefCache = new Map();
576
+ /** Paths `ref` records as symlinks, computed once per (repo, ref). */
577
+ function gitSymlinkPathsAtRef(repoDir, ref, env) {
578
+ const key = `${path.resolve(repoDir)}\0${ref}`;
579
+ const cached = gitSymlinkPathsAtRefCache.get(key);
580
+ if (cached)
581
+ return cached;
582
+ const found = new Set();
583
+ const res = run("git", ["ls-tree", "-r", "-z", ref], { cwd: repoDir, env });
584
+ if (res.status === 0) {
585
+ for (const record of res.stdout.split("\0")) {
586
+ const tab = record.indexOf("\t");
587
+ if (tab < 0)
588
+ continue;
589
+ if (record.slice(0, tab).split(/\s+/)[0] === "120000") {
590
+ found.add(record.slice(tab + 1));
591
+ }
592
+ }
593
+ }
594
+ gitSymlinkPathsAtRefCache.set(key, found);
595
+ return found;
596
+ }
597
+ /** Resolve a link target against the link's dir; null if it leaves `root`. */
598
+ function resolveContainedLinkTarget(root, rel, linkText) {
599
+ if (!linkText || linkText.includes("\0") || path.isAbsolute(linkText)) {
600
+ return null;
601
+ }
602
+ const rootAbs = path.resolve(root);
603
+ const resolved = path.resolve(rootAbs, path.dirname(rel), linkText);
604
+ return resolved.startsWith(rootAbs + path.sep) ? resolved : null;
605
+ }
606
+ /**
607
+ * Git with `core.symlinks=false` (the Git for Windows default when the user
608
+ * lacks the symlink privilege) checks a mode-120000 entry out as a regular
609
+ * file whose bytes are the link target, e.g. a 17-byte `AGENTS.md` holding
610
+ * `.claude/CLAUDE.md`. The overlay then copies that stub into the HQ root and
611
+ * Codex starts with no charter (feedback_d0c2f082). Replace each stub in the
612
+ * clone with a copy of its file target, or a junction/symlink for a directory
613
+ * target, so the overlay lays down working content. Real symlinks are left
614
+ * alone. Returns the repo-relative paths that were replaced.
615
+ */
616
+ export function materializeGitSymlinkStubs(srcDir, env = process.env) {
617
+ const pending = gitSymlinkPaths(srcDir, env).filter((rel) => {
618
+ const st = lstatOrNull(path.join(srcDir, rel));
619
+ return st !== null && st.isFile();
620
+ });
621
+ const done = [];
622
+ // Several passes so a stub that points at another stub resolves once its
623
+ // target has been materialized.
624
+ let progressed = true;
625
+ while (pending.length > 0 && progressed) {
626
+ progressed = false;
627
+ for (let i = pending.length - 1; i >= 0; i--) {
628
+ const rel = pending[i];
629
+ const stubPath = path.join(srcDir, rel);
630
+ const linkText = fs.readFileSync(stubPath, "utf-8");
631
+ const resolved = resolveContainedLinkTarget(srcDir, rel, linkText);
632
+ if (resolved === null) {
633
+ pending.splice(i, 1);
634
+ continue;
635
+ }
636
+ if (pending.some((p) => path.resolve(srcDir, p) === resolved))
637
+ continue;
638
+ const targetStat = lstatOrNull(resolved);
639
+ if (targetStat === null) {
640
+ pending.splice(i, 1);
641
+ continue;
642
+ }
643
+ if (isFileFollow(resolved)) {
644
+ const tmp = `${stubPath}.hq-materialize-${process.pid}`;
645
+ fs.copyFileSync(resolved, tmp);
646
+ fs.renameSync(tmp, stubPath);
647
+ }
648
+ else if (isDir(resolved)) {
649
+ fs.rmSync(stubPath, { force: true });
650
+ createSymlinkOrJunction(linkText, stubPath, resolved);
651
+ }
652
+ else {
653
+ pending.splice(i, 1);
654
+ continue;
655
+ }
656
+ done.push(rel);
657
+ pending.splice(i, 1);
658
+ progressed = true;
659
+ }
660
+ }
661
+ return done.sort();
662
+ }
663
+ /**
664
+ * True when `localPath` is a regular-file stand-in for a path git records as
665
+ * a symlink at `ref`: either the raw stub text, or a copy of the link's target
666
+ * as it exists in the HQ root. Such a file is not a user edit, so the release
667
+ * may replace it.
668
+ */
669
+ export function isMaterializedGitSymlinkCopy(srcDir, ref, hqRoot, rel, localPath, env = process.env) {
670
+ const st = lstatOrNull(localPath);
671
+ if (!st || !st.isFile())
672
+ return false;
673
+ if (!gitSymlinkPathsAtRef(srcDir, ref, env).has(rel))
674
+ return false;
675
+ const show = run("git", ["show", `${ref}:${rel}`], { cwd: srcDir, env });
676
+ if (show.status !== 0 || !show.stdout)
677
+ return false;
678
+ const linkText = show.stdout;
679
+ let local;
680
+ try {
681
+ local = fs.readFileSync(localPath);
682
+ }
683
+ catch {
684
+ return false;
685
+ }
686
+ if (local.equals(Buffer.from(linkText, "utf-8")))
687
+ return true;
688
+ const resolved = resolveContainedLinkTarget(hqRoot, rel, linkText);
689
+ return resolved !== null && bytesEqual(localPath, resolved);
690
+ }
555
691
  function utcStamp(d, sep) {
556
692
  const p = (n) => String(n).padStart(2, "0");
557
693
  const date = `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}`;
@@ -1537,6 +1673,294 @@ export function rsyncOutputHasOnlyDirectoryChanges(output) {
1537
1673
  }
1538
1674
  return true;
1539
1675
  }
1676
+ /**
1677
+ * Extra receiver flags for a Cygwin rsync on Windows (cwRsync). `-a` carries
1678
+ * `-p`, `-o`, and `-g`. Cygwin applies those POSIX bits by writing an explicit
1679
+ * DACL on every file and directory it touches, including the HQ root and each
1680
+ * overlaid directory, and an elevated process can end up with a directory that
1681
+ * Win32 callers such as Node cannot list (EPERM on readdir after an overlay,
1682
+ * nightly run 38032085395). POSIX modes carry no meaning for HQ on Windows,
1683
+ * so leave the existing ACLs alone and give new entries a permissive mode.
1684
+ * The platform is explicit so the shape can be asserted on any host.
1685
+ */
1686
+ export function rsyncWindowsReceiverArgs(platform = process.platform) {
1687
+ if (platform !== "win32")
1688
+ return [];
1689
+ return ["--no-perms", "--no-owner", "--no-group", "--chmod=ugo=rwX"];
1690
+ }
1691
+ /** Set one `winsymlinks:` token in a CYGWIN/MSYS option string. */
1692
+ function withWinsymlinksNative(value) {
1693
+ const kept = (value ?? "")
1694
+ .split(/\s+/)
1695
+ .filter((token) => token.length > 0 && !/^winsymlinks(:|$)/i.test(token));
1696
+ return [...kept, "winsymlinks:native"].join(" ");
1697
+ }
1698
+ /**
1699
+ * Environment for a Cygwin or MSYS2 rsync on Windows. Cygwin 3.1.5 and later
1700
+ * create WSL-style symlinks (reparse tag IO_REPARSE_TAG_LX_SYMLINK) by
1701
+ * default, which Explorer, cmd, and Node cannot open (feedback_a60339e8).
1702
+ * cwRsync and Cygwin's rsync read `CYGWIN`; MSYS2's rsync (the one Git for
1703
+ * Windows users add from MSYS2) reads `MSYS`. `winsymlinks:native` asks both
1704
+ * runtimes for a native NTFS symlink and falls back to the runtime default
1705
+ * when the account cannot create one; `nativestrict` would instead fail the
1706
+ * overlay with rsync status 23. `normalizeWindowsGitSymlinks` repairs any
1707
+ * link that still comes out in a non-native form. Other platforms keep the
1708
+ * caller's environment unchanged.
1709
+ */
1710
+ export function rsyncWindowsEnv(env, platform = process.platform) {
1711
+ if (platform !== "win32")
1712
+ return env;
1713
+ const next = { ...env };
1714
+ for (const name of ["CYGWIN", "MSYS"]) {
1715
+ // Windows environment names are case-insensitive. Reuse the caller's key
1716
+ // so the child does not receive two spellings of the same variable.
1717
+ const existingKey = Object.keys(next).find((key) => key.toUpperCase() === name) ?? name;
1718
+ next[existingKey] = withWinsymlinksNative(envValue(env, name));
1719
+ }
1720
+ return next;
1721
+ }
1722
+ /** One `--include=`/`--exclude=` rule as rsync's receiver filter applies it. */
1723
+ function rsyncFilterRuleMatches(rawPattern, rel, isDir) {
1724
+ let pattern = rawPattern;
1725
+ let tripleStar = false;
1726
+ if (pattern.endsWith("/***")) {
1727
+ tripleStar = true;
1728
+ pattern = pattern.slice(0, -4);
1729
+ }
1730
+ else if (pattern.endsWith("/")) {
1731
+ if (!isDir)
1732
+ return false;
1733
+ pattern = pattern.replace(/\/+$/, "");
1734
+ }
1735
+ const anchored = pattern.startsWith("/");
1736
+ if (anchored)
1737
+ pattern = pattern.replace(/^\/+/, "");
1738
+ if (pattern.length === 0)
1739
+ return false;
1740
+ let body = "";
1741
+ for (let i = 0; i < pattern.length; i++) {
1742
+ const ch = pattern[i];
1743
+ if (ch === "*") {
1744
+ if (pattern[i + 1] === "*") {
1745
+ body += ".*";
1746
+ i++;
1747
+ }
1748
+ else {
1749
+ body += "[^/]*";
1750
+ }
1751
+ }
1752
+ else if (ch === "?") {
1753
+ body += "[^/]";
1754
+ }
1755
+ else if (ch === "[") {
1756
+ const close = pattern.indexOf("]", i + 1);
1757
+ if (close < 0) {
1758
+ body += "\\[";
1759
+ }
1760
+ else {
1761
+ body += pattern.slice(i, close + 1).replace(/\\/g, "\\\\");
1762
+ i = close;
1763
+ }
1764
+ }
1765
+ else {
1766
+ body += ch.replace(/[.+^${}()|\\]/g, "\\$&");
1767
+ }
1768
+ }
1769
+ if (tripleStar)
1770
+ body += "(/.*)?";
1771
+ const hasSlash = pattern.includes("/") || tripleStar;
1772
+ let source;
1773
+ if (anchored)
1774
+ source = `^${body}$`;
1775
+ else if (hasSlash)
1776
+ source = `^(.*/)?${body}$`;
1777
+ else
1778
+ source = `^${body}$`;
1779
+ const subject = !anchored && !hasSlash ? rel.slice(rel.lastIndexOf("/") + 1) : rel;
1780
+ return new RegExp(source).test(subject);
1781
+ }
1782
+ /**
1783
+ * True when rsync's overlay, run with `filters` (the rescue's `--include=` and
1784
+ * `--exclude=` list), would transfer `rel`. Every ancestor directory is
1785
+ * checked first, because rsync never descends into an excluded directory; the
1786
+ * first matching rule wins at each level.
1787
+ */
1788
+ export function rsyncFiltersAdmit(filters, rel) {
1789
+ const segments = rel.split("/").filter((segment) => segment.length > 0);
1790
+ for (let depth = 1; depth <= segments.length; depth++) {
1791
+ const prefix = segments.slice(0, depth).join("/");
1792
+ const isDir = depth < segments.length;
1793
+ for (const filter of filters) {
1794
+ const include = filter.startsWith("--include=");
1795
+ if (!include && !filter.startsWith("--exclude="))
1796
+ continue;
1797
+ const pattern = filter.slice(include ? "--include=".length : "--exclude=".length);
1798
+ if (!rsyncFilterRuleMatches(pattern, prefix, isDir))
1799
+ continue;
1800
+ if (!include)
1801
+ return false;
1802
+ break;
1803
+ }
1804
+ }
1805
+ return true;
1806
+ }
1807
+ const defaultWindowsLinkOps = {
1808
+ symlink(linkText, destination, type) {
1809
+ // Node stores a relative Windows symlink target with backslashes, so the
1810
+ // forward-slash git link text resolves for Explorer and cmd too.
1811
+ fs.symlinkSync(linkText, destination, type);
1812
+ },
1813
+ junction(resolvedTarget, destination) {
1814
+ fs.symlinkSync(resolvedTarget, destination, "junction");
1815
+ },
1816
+ copyFile(resolvedTarget, destination) {
1817
+ fs.copyFileSync(resolvedTarget, destination);
1818
+ },
1819
+ };
1820
+ /** Cygwin's fallback "magic cookie" symlink is a system file with this header. */
1821
+ const CYGWIN_SYMLINK_COOKIE = Buffer.from("!<symlink>", "latin1");
1822
+ function readFileOrNull(p) {
1823
+ try {
1824
+ return fs.readFileSync(p);
1825
+ }
1826
+ catch {
1827
+ return null;
1828
+ }
1829
+ }
1830
+ function realpathOrNull(p) {
1831
+ try {
1832
+ return fs.realpathSync.native(p);
1833
+ }
1834
+ catch {
1835
+ return null;
1836
+ }
1837
+ }
1838
+ /** Remove a link or file entry without following it or recursing into a target. */
1839
+ function removeLinkEntry(p) {
1840
+ try {
1841
+ fs.unlinkSync(p);
1842
+ }
1843
+ catch (error) {
1844
+ const code = error.code;
1845
+ if (code === "ENOENT")
1846
+ return;
1847
+ // A Windows directory symlink or junction is removed with RemoveDirectory.
1848
+ // rmdir never removes a real directory that still has entries.
1849
+ if (code === "EPERM" || code === "EISDIR" || code === "EACCES") {
1850
+ fs.rmdirSync(p);
1851
+ return;
1852
+ }
1853
+ throw error;
1854
+ }
1855
+ }
1856
+ /**
1857
+ * Whether `destination` already gives native Windows tools the link's
1858
+ * content: a directory link that lists the target directory, or a file whose
1859
+ * bytes match the target file (a native symlink, or the copy fallback).
1860
+ */
1861
+ function windowsLinkIsUsable(destination, resolvedTarget, targetIsDir) {
1862
+ if (targetIsDir) {
1863
+ try {
1864
+ fs.readdirSync(destination);
1865
+ }
1866
+ catch {
1867
+ return false;
1868
+ }
1869
+ const real = realpathOrNull(destination);
1870
+ return real !== null && real === realpathOrNull(resolvedTarget);
1871
+ }
1872
+ const local = readFileOrNull(destination);
1873
+ const target = readFileOrNull(resolvedTarget);
1874
+ return local !== null && target !== null && local.equals(target);
1875
+ }
1876
+ /**
1877
+ * Replace `destination` with a native link to the release target unless it
1878
+ * is already usable or holds user content. Returns false when left alone.
1879
+ */
1880
+ function replaceWithNativeLink(destination, linkText, resolved, targetIsDir, ops) {
1881
+ const lst = lstatOrNull(destination);
1882
+ if (lst) {
1883
+ if (lst.isDirectory() && !lst.isSymbolicLink())
1884
+ return false;
1885
+ if (windowsLinkIsUsable(destination, resolved, targetIsDir))
1886
+ return false;
1887
+ if (lst.isFile()) {
1888
+ // A readable regular file that is neither the git stub text nor a
1889
+ // Cygwin cookie is user content; the release does not own it.
1890
+ const bytes = readFileOrNull(destination);
1891
+ if (bytes !== null &&
1892
+ !bytes.equals(Buffer.from(linkText, "utf-8")) &&
1893
+ !bytes.subarray(0, CYGWIN_SYMLINK_COOKIE.length).equals(CYGWIN_SYMLINK_COOKIE)) {
1894
+ return false;
1895
+ }
1896
+ }
1897
+ removeLinkEntry(destination);
1898
+ }
1899
+ else {
1900
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
1901
+ }
1902
+ const type = targetIsDir ? "dir" : "file";
1903
+ try {
1904
+ ops.symlink(linkText, destination, type);
1905
+ }
1906
+ catch (error) {
1907
+ if (error.code !== "EPERM")
1908
+ throw error;
1909
+ // No symlink privilege: junctions need none, and a file copy is what
1910
+ // Git for Windows itself would give a core.symlinks=false checkout.
1911
+ if (targetIsDir)
1912
+ ops.junction(resolved, destination);
1913
+ else
1914
+ ops.copyFile(resolved, destination);
1915
+ }
1916
+ return true;
1917
+ }
1918
+ /**
1919
+ * After the overlay on Windows, make every release symlink readable by
1920
+ * native tools. Cygwin rsync can lay a link down as a WSL reparse point
1921
+ * (LX_SYMLINK) or a "!<symlink>" cookie file, and earlier rescues left such
1922
+ * links behind as unchanged files; Explorer and Node cannot open either
1923
+ * (feedback_a60339e8). Each mode-120000 path the overlay covers is replaced
1924
+ * with a native symlink; without the symlink privilege (no Developer Mode) a
1925
+ * directory target becomes a junction and a file target becomes a copy.
1926
+ *
1927
+ * Left alone: real directories (a flattened copy), files the user edited,
1928
+ * links that already resolve to the release target, paths the overlay's
1929
+ * filters exclude, and targets that are missing or leave `hqRoot`.
1930
+ * Returns the repo-relative paths that were rewritten and any that could not
1931
+ * be. No-op off Windows.
1932
+ */
1933
+ export function normalizeWindowsGitSymlinks(srcDir, hqRoot, filters, env = process.env, platform = process.platform, ops = defaultWindowsLinkOps) {
1934
+ const repaired = [];
1935
+ const failed = [];
1936
+ if (platform !== "win32")
1937
+ return { repaired, failed };
1938
+ for (const { rel, sha } of gitSymlinkEntries(srcDir, env)) {
1939
+ if (!rsyncFiltersAdmit(filters, rel))
1940
+ continue;
1941
+ const blob = run("git", ["cat-file", "blob", sha], { cwd: srcDir, env });
1942
+ if (blob.status !== 0)
1943
+ continue;
1944
+ const linkText = blob.stdout;
1945
+ const resolved = resolveContainedLinkTarget(hqRoot, rel, linkText);
1946
+ if (resolved === null)
1947
+ continue;
1948
+ const targetIsDir = isDir(resolved);
1949
+ if (!targetIsDir && !isFileFollow(resolved))
1950
+ continue;
1951
+ const destination = path.join(hqRoot, rel);
1952
+ try {
1953
+ if (!replaceWithNativeLink(destination, linkText, resolved, targetIsDir, ops))
1954
+ continue;
1955
+ }
1956
+ catch (error) {
1957
+ failed.push({ rel, reason: error instanceof Error ? error.message : String(error) });
1958
+ continue;
1959
+ }
1960
+ repaired.push(rel);
1961
+ }
1962
+ return { repaired: repaired.sort(), failed };
1963
+ }
1540
1964
  function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, rsyncExcludes, env) {
1541
1965
  const newest = [...unresolved].sort((left, right) => right.entry.completedMs - left.entry.completedMs ||
1542
1966
  right.entry.createdMs - left.entry.createdMs ||
@@ -1556,9 +1980,10 @@ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, r
1556
1980
  "--dry-run",
1557
1981
  "--itemize-changes",
1558
1982
  ...rsyncExcludes,
1983
+ ...rsyncWindowsReceiverArgs(),
1559
1984
  toCygwinRsyncPath(srcDir + "/"),
1560
1985
  toCygwinRsyncPath(hqRoot + "/"),
1561
- ], { env });
1986
+ ], { env: rsyncWindowsEnv(env) });
1562
1987
  if (releaseProof.status !== 0 ||
1563
1988
  !rsyncOutputHasOnlyDirectoryChanges(`${releaseProof.stdout}\n${releaseProof.stderr}`)) {
1564
1989
  failures.push("release-bytes");
@@ -1809,6 +2234,11 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
1809
2234
  env,
1810
2235
  }).stdout.trim();
1811
2236
  out(`==> Source SHA: ${srcSha}\n`);
2237
+ // --- Replace git symlink stubs (core.symlinks=false, e.g. Windows) ---
2238
+ const materialized = materializeGitSymlinkStubs(srcDir, env);
2239
+ if (materialized.length > 0) {
2240
+ out(`==> Materialized ${materialized.length} symlink(s) git checked out as text stubs\n`);
2241
+ }
1812
2242
  // --- Restore file mtimes from git history ---
1813
2243
  restoreMtimesFromGit(srcDir, env, out);
1814
2244
  // --- Resolve history floor ---
@@ -2033,12 +2463,13 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2033
2463
  "-a",
2034
2464
  ...overlayProtect,
2035
2465
  ...rsyncExcludes,
2466
+ ...rsyncWindowsReceiverArgs(),
2036
2467
  toCygwinRsyncPath(srcDir + "/"),
2037
2468
  toCygwinRsyncPath(hqRoot + "/"),
2038
2469
  ];
2039
2470
  // Exercise the exact overlay command before any classified delete/move. A
2040
2471
  // Cygwin path conversion or filter failure therefore leaves the root intact.
2041
- const overlayPreflight = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, "--dry-run", ...overlayArgs], { env });
2472
+ const overlayPreflight = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, "--dry-run", ...overlayArgs], { env: rsyncWindowsEnv(env) });
2042
2473
  if (overlayPreflight.status !== 0) {
2043
2474
  reportRsyncFailure(overlayPreflight.status, "dry-run", overlayPreflight.stderr, err);
2044
2475
  throw new ExitError(overlayPreflight.status || 1);
@@ -2277,11 +2708,12 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2277
2708
  "--from0",
2278
2709
  `--exclude-from=${unchangedList}`,
2279
2710
  ...rsyncExcludes,
2711
+ ...rsyncWindowsReceiverArgs(),
2280
2712
  toCygwinRsyncPath(srcDir + "/"),
2281
2713
  toCygwinRsyncPath(hqRoot + "/"),
2282
2714
  ]
2283
2715
  : overlayArgs;
2284
- const overlay = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, ...overlayRunArgs], { env });
2716
+ const overlay = run(rsyncLauncher.command, [...rsyncLauncher.leadingArgs, ...overlayRunArgs], { env: rsyncWindowsEnv(env) });
2285
2717
  if (overlay.status !== 0) {
2286
2718
  // bash runs under set -e: a failed rsync aborts with its status.
2287
2719
  reportRsyncFailure(overlay.status, "overlay", overlay.stderr, err);
@@ -2325,6 +2757,16 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
2325
2757
  }
2326
2758
  throw new ExitError(overlay.status || 1);
2327
2759
  }
2760
+ // --- Native Windows links (feedback_a60339e8) ---
2761
+ // Before the preserved sub-paths come back, so a preserved path keeps the
2762
+ // user's bytes even when it sits where the release ships a symlink.
2763
+ const nativeLinks = normalizeWindowsGitSymlinks(srcDir, hqRoot, rsyncExcludes, env);
2764
+ if (nativeLinks.repaired.length > 0) {
2765
+ out(`==> Rewrote ${nativeLinks.repaired.length} symlink(s) in native Windows form: ${nativeLinks.repaired.join(", ")}\n`);
2766
+ }
2767
+ for (const failure of nativeLinks.failed) {
2768
+ err(`warning: could not rewrite ${failure.rel} as a native Windows link: ${failure.reason}\n`);
2769
+ }
2328
2770
  // --- Restore preserved sub-paths ---
2329
2771
  if (preserveMap.length > 0) {
2330
2772
  const restoreFailures = restorePreservedSubpaths(preserveMap, shuttle, hqRoot, cfg.backupRoot, backupDir, out);
@@ -3266,13 +3708,8 @@ function mergeUsablePathEntries(...pathsAndEnv) {
3266
3708
  // must not classify every usable PATH entry as temporary.
3267
3709
  if (root === path.parse(root).root)
3268
3710
  return false;
3269
- if (homePath) {
3270
- const homeRelative = path.relative(root, homePath);
3271
- if (homeRelative === "" ||
3272
- (!homeRelative.startsWith(`..${path.sep}`) && homeRelative !== "..")) {
3273
- return false;
3274
- }
3275
- }
3711
+ if (homePath && pathIsInside(root, homePath, true))
3712
+ return false;
3276
3713
  return true;
3277
3714
  });
3278
3715
  const result = [];
@@ -3290,10 +3727,10 @@ function mergeUsablePathEntries(...pathsAndEnv) {
3290
3727
  }))
3291
3728
  continue;
3292
3729
  const absolute = path.resolve(entry);
3293
- if (temporaryRoots.some((root) => {
3294
- const relative = path.relative(path.resolve(root), absolute);
3295
- return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== "..");
3296
- }))
3730
+ // pathIsInside rejects an absolute path.relative result. On Windows that
3731
+ // is what a different drive returns: the fallback roots such as /tmp
3732
+ // resolve on the cwd drive, so a C:\ entry is not inside D:\tmp.
3733
+ if (temporaryRoots.some((root) => pathIsInside(root, absolute, true)))
3297
3734
  continue;
3298
3735
  const key = process.platform === "win32" ? normalized.toLowerCase() : normalized;
3299
3736
  if (seen.has(key))
@@ -3846,6 +4283,16 @@ function classifyOne(ctx, filesystemRel) {
3846
4283
  // in_floor=1, in_head=0: upstream removed since last sync — rescue.
3847
4284
  userEdited = 1;
3848
4285
  }
4286
+ // A regular-file stand-in for an upstream symlink (Windows stub or the copy
4287
+ // materializeGitSymlinkStubs laid down last time) is release-owned content,
4288
+ // not a user edit. Let the release copy replace it.
4289
+ if (userEdited === 1 &&
4290
+ isMaterializedGitSymlinkCopy(ctx.srcDir, ctx.baselineMode === "history_floor" && inFloor === 1
4291
+ ? ctx.historyFloor
4292
+ : "HEAD", ctx.hqRoot, rel, localPath, ctx.env)) {
4293
+ userEdited = 0;
4294
+ editProvenAgainstFloor = false;
4295
+ }
3849
4296
  // Cloud-update reclassification.
3850
4297
  if (userEdited === 1 && isCloudFlattenedSymlinkEquiv(ctx, rel, localPath)) {
3851
4298
  return { kind: "cloud-symlink-reconciled", rel };
@@ -4065,6 +4512,12 @@ function buildRescueActions(ctx) {
4065
4512
  else {
4066
4513
  add(`delete unchanged absent upstream: ${decision.rel}`, [decision.rel], () => {
4067
4514
  fs.rmSync(localPath, { force: true });
4515
+ // `force` tolerates an already-missing path; it must not turn a
4516
+ // refused unlink into a "deleted" log line while the file stays
4517
+ // in place for the overlay to see.
4518
+ if (lexists(localPath)) {
4519
+ throw new Error(`could not delete ${decision.rel}: still present after unlink`);
4520
+ }
4068
4521
  ctx.appendLog(`deleted\t${decision.rel}\t(unchanged vs baseline; absent from upstream)\n`);
4069
4522
  });
4070
4523
  }