@tangle-network/agent-app 0.63.32 → 0.63.33

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.
@@ -786,7 +786,7 @@ import {
786
786
  writeFileSync
787
787
  } from "fs";
788
788
  import { hostname } from "os";
789
- import { basename as basename2, join as join4, relative, resolve as resolve2, sep } from "path";
789
+ import { basename as basename2, dirname as dirname2, join as join4, relative, resolve as resolve2, sep } from "path";
790
790
  import lockfile from "proper-lockfile";
791
791
  var SIGNOFF_CACHE_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1e3;
792
792
  var SIGNOFF_CACHE_MAX_BYTES = 4 * 1024 ** 3;
@@ -968,27 +968,65 @@ function collectInodes(path, keys, sizes) {
968
968
  }
969
969
  for (const child of children) collectInodes(join4(path, child), keys, sizes);
970
970
  }
971
+ function missingGitMetadata(tree) {
972
+ let gitDir;
973
+ try {
974
+ const marker = join4(tree, ".git");
975
+ if (!lstatSync(marker).isFile()) return false;
976
+ const pointer = /^gitdir: ([^\r\n]+)\r?\n?$/.exec(readFileSync3(marker, "utf8"));
977
+ if (!pointer) return false;
978
+ gitDir = resolve2(tree, pointer[1]);
979
+ } catch (error) {
980
+ if (error.code === "ENOENT") return false;
981
+ throw error;
982
+ }
983
+ try {
984
+ statSync2(gitDir);
985
+ } catch (error) {
986
+ if (error.code !== "ENOENT") throw error;
987
+ return basename2(dirname2(gitDir)) === "worktrees" && basename2(gitDir) === basename2(tree);
988
+ }
989
+ let common;
990
+ try {
991
+ common = readFileSync3(join4(gitDir, "commondir"), "utf8").trim();
992
+ } catch (error) {
993
+ if (error.code === "ENOENT") return false;
994
+ throw error;
995
+ }
996
+ if (!common) return false;
997
+ try {
998
+ statSync2(resolve2(gitDir, common));
999
+ return false;
1000
+ } catch (error) {
1001
+ if (error.code === "ENOENT") return true;
1002
+ throw error;
1003
+ }
1004
+ }
971
1005
  function entries(cacheDir, protectedSet, unknown) {
972
1006
  const found = [];
973
1007
  for (const [kind, child] of [["tree", "trees"], ["store", "stores"]]) {
974
1008
  const root = join4(cacheDir, child);
975
- if (!existsSync4(root)) continue;
1009
+ if (!existsSync4(root) || !lstatSync(root).isDirectory()) continue;
976
1010
  for (const entry of readdirSync(root, { withFileTypes: true })) {
977
1011
  if (!entry.isDirectory()) continue;
978
1012
  const path = join4(root, entry.name);
979
1013
  const recognized = kind === "store" ? /^[a-f0-9]{64}$/.test(entry.name) : existsSync4(join4(path, ".git"));
980
- let mtimeMs;
1014
+ const orphaned = kind === "tree" && recognized && missingGitMetadata(path);
1015
+ let current;
981
1016
  try {
982
- mtimeMs = statSync2(path).mtimeMs;
1017
+ current = lstatSync(path);
983
1018
  } catch (error) {
984
1019
  if (error.code === "ENOENT") continue;
985
1020
  throw error;
986
1021
  }
1022
+ if (!current.isDirectory()) continue;
987
1023
  found.push({
988
1024
  path,
989
1025
  kind,
990
- mtimeMs,
991
- protected: unknown || protectedSet.has(path) || !recognized,
1026
+ mtimeMs: current.mtimeMs,
1027
+ rootInode: `${current.dev}:${current.ino}`,
1028
+ orphaned,
1029
+ protected: unknown || protectedSet.has(path) || !recognized || orphaned,
992
1030
  inodes: /* @__PURE__ */ new Set()
993
1031
  });
994
1032
  }
@@ -998,10 +1036,35 @@ function entries(cacheDir, protectedSet, unknown) {
998
1036
  function removeEntry(entry) {
999
1037
  if (entry.kind === "store") {
1000
1038
  rmSync2(entry.path, { recursive: true, force: true });
1001
- return;
1039
+ return true;
1040
+ }
1041
+ try {
1042
+ const current = lstatSync(entry.path);
1043
+ if (!current.isDirectory() || entry.rootInode !== `${current.dev}:${current.ino}`) {
1044
+ throw new Error(`signoff: cached worktree changed before retirement: ${entry.path}`);
1045
+ }
1046
+ } catch (error) {
1047
+ if (error.code === "ENOENT") return true;
1048
+ throw error;
1049
+ }
1050
+ if (missingGitMetadata(entry.path)) {
1051
+ entry.orphaned = true;
1052
+ return false;
1002
1053
  }
1003
1054
  const git2 = spawnSync3("git", ["-C", entry.path, "worktree", "remove", "--force", entry.path], { encoding: "utf8" });
1004
- if (git2.status !== 0) throw new Error(`signoff: cannot retire cached worktree ${entry.path}: ${git2.stderr.trim()}`);
1055
+ if (git2.error) throw new Error(`signoff: cannot start Git to retire cached worktree ${entry.path}`, { cause: git2.error });
1056
+ if (git2.status === 0) return true;
1057
+ try {
1058
+ lstatSync(entry.path);
1059
+ } catch (error) {
1060
+ if (error.code === "ENOENT") return true;
1061
+ throw error;
1062
+ }
1063
+ if (missingGitMetadata(entry.path)) {
1064
+ entry.orphaned = true;
1065
+ return false;
1066
+ }
1067
+ throw new Error(`signoff: cannot retire cached worktree ${entry.path}: ${git2.stderr.trim()}`);
1005
1068
  }
1006
1069
  async function pruneSignoffCache(cacheDir, options = {}) {
1007
1070
  const root = cacheRoot(cacheDir);
@@ -1041,11 +1104,26 @@ async function pruneSignoffCache(cacheDir, options = {}) {
1041
1104
  if (bytes <= maxBytes) break;
1042
1105
  if (!selected.includes(entry)) select(entry);
1043
1106
  }
1044
- for (const entry of selected) removeEntry(entry);
1107
+ const removed = selected.filter(removeEntry).map((entry) => entry.path);
1108
+ let retained = sizes;
1109
+ if (removed.length !== selected.length) {
1110
+ retained = /* @__PURE__ */ new Map();
1111
+ for (const entry of candidates) {
1112
+ entry.inodes.clear();
1113
+ collectInodes(entry.path, entry.inodes, retained);
1114
+ }
1115
+ bytes = [...retained.values()].reduce((sum, size) => sum + size, 0);
1116
+ }
1117
+ const orphanedInodes = /* @__PURE__ */ new Set();
1118
+ for (const entry of candidates) if (entry.orphaned) {
1119
+ for (const key of entry.inodes) orphanedInodes.add(key);
1120
+ }
1045
1121
  return {
1046
1122
  beforeBytes,
1047
1123
  afterBytes: bytes,
1048
- removed: selected.map((entry) => entry.path),
1124
+ removed,
1125
+ orphaned: candidates.filter((entry) => entry.orphaned && entry.inodes.size).map((entry) => entry.path),
1126
+ orphanedBytes: [...orphanedInodes].reduce((sum, key) => sum + (retained.get(key) ?? 0), 0),
1049
1127
  overBudgetBytes: Math.max(0, bytes - maxBytes)
1050
1128
  };
1051
1129
  });
@@ -1479,7 +1557,7 @@ function resolveStore(options) {
1479
1557
  import { spawnSync as spawnSync4 } from "child_process";
1480
1558
  import { createHash as createHash3 } from "crypto";
1481
1559
  import { copyFileSync, existsSync as existsSync8, mkdirSync as mkdirSync3, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "fs";
1482
- import { dirname as dirname2, isAbsolute, join as join8, resolve as resolve3 } from "path";
1560
+ import { dirname as dirname3, isAbsolute, join as join8, resolve as resolve3 } from "path";
1483
1561
  function git(args, cwd) {
1484
1562
  const result = spawnSync4("git", args, { cwd, encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
1485
1563
  if (result.error) throw new Error(`signoff: git ${args.join(" ")} failed to start: ${result.error.message}`);
@@ -1501,7 +1579,7 @@ function materializeCleanTree(options) {
1501
1579
  const head = git(["rev-parse", "HEAD"], root).trim();
1502
1580
  const branch = git(["rev-parse", "--abbrev-ref", "HEAD"], root).trim();
1503
1581
  git(["worktree", "prune"], root);
1504
- mkdirSync3(dirname2(dest), { recursive: true });
1582
+ mkdirSync3(dirname3(dest), { recursive: true });
1505
1583
  if (existsSync8(dest)) rmSync4(dest, { recursive: true, force: true });
1506
1584
  git(["worktree", "add", "--detach", "--quiet", dest, head], root);
1507
1585
  let diffSha256 = null;
@@ -1510,7 +1588,7 @@ function materializeCleanTree(options) {
1510
1588
  const patch = git(["diff", "HEAD", "--binary", "--no-color", "--no-ext-diff"], root);
1511
1589
  if (patch.length > 0) {
1512
1590
  diffSha256 = createHash3("sha256").update(patch).digest("hex");
1513
- const patchFile = join8(dirname2(dest), `${dest.split("/").pop() ?? "tree"}.patch`);
1591
+ const patchFile = join8(dirname3(dest), `${dest.split("/").pop() ?? "tree"}.patch`);
1514
1592
  writeFileSync3(patchFile, patch);
1515
1593
  git(["apply", "--binary", "--whitespace=nowarn", patchFile], dest);
1516
1594
  rmSync4(patchFile, { force: true });
@@ -1518,7 +1596,7 @@ function materializeCleanTree(options) {
1518
1596
  untrackedFiles = zsplit(git(["ls-files", "--others", "--exclude-standard", "-z"], root));
1519
1597
  for (const rel of untrackedFiles) {
1520
1598
  const target = join8(dest, rel);
1521
- mkdirSync3(dirname2(target), { recursive: true });
1599
+ mkdirSync3(dirname3(target), { recursive: true });
1522
1600
  copyFileSync(join8(root, rel), target);
1523
1601
  }
1524
1602
  }
@@ -1532,7 +1610,7 @@ function materializeCleanTree(options) {
1532
1610
  );
1533
1611
  }
1534
1612
  const target = join8(dest, rel);
1535
- mkdirSync3(dirname2(target), { recursive: true });
1613
+ mkdirSync3(dirname3(target), { recursive: true });
1536
1614
  copyFileSync(from, target);
1537
1615
  carried.push(rel);
1538
1616
  }
@@ -1606,7 +1684,7 @@ async function runSignoff(options = {}) {
1606
1684
  cacheDir = session.cacheDir;
1607
1685
  const prune = async (root, keepPaths = []) => {
1608
1686
  const result = await pruneSignoffCache(root, { keepPaths });
1609
- if (result.removed.length || result.overBudgetBytes) {
1687
+ if (result.removed.length || result.orphaned.length || result.overBudgetBytes) {
1610
1688
  options.onEvent?.({ kind: "cache-prune", ...result });
1611
1689
  }
1612
1690
  };
@@ -2211,7 +2289,7 @@ function round(value) {
2211
2289
 
2212
2290
  // src/signoff/shell-alignment-cli.ts
2213
2291
  import { mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "fs";
2214
- import { dirname as dirname3, resolve as resolve5 } from "path";
2292
+ import { dirname as dirname4, resolve as resolve5 } from "path";
2215
2293
  function shellAlignmentUsage() {
2216
2294
  return [
2217
2295
  "Usage: agent-app-signoff shell-alignment --base-url <url> --route <path> [--route <path> ...] [options]",
@@ -2310,7 +2388,7 @@ ${shellAlignmentUsage()}
2310
2388
  const report = await checkShellAlignment(options);
2311
2389
  if (options.jsonPath) {
2312
2390
  const abs = resolve5(options.jsonPath);
2313
- mkdirSync4(dirname3(abs), { recursive: true });
2391
+ mkdirSync4(dirname4(abs), { recursive: true });
2314
2392
  writeFileSync4(abs, `${JSON.stringify(report, null, 2)}
2315
2393
  `);
2316
2394
  }
@@ -2599,7 +2677,7 @@ function formatSurfaceLadderReport(report) {
2599
2677
 
2600
2678
  // src/signoff/surface-ladder-cli.ts
2601
2679
  import { mkdirSync as mkdirSync5, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "fs";
2602
- import { dirname as dirname4, resolve as resolve6 } from "path";
2680
+ import { dirname as dirname5, resolve as resolve6 } from "path";
2603
2681
  function surfaceLadderUsage() {
2604
2682
  return [
2605
2683
  "Usage: agent-app-signoff surface-ladder --base-url <url> --route <path> [--route <path> ...] [options]",
@@ -2715,7 +2793,7 @@ ${surfaceLadderUsage()}
2715
2793
  const report = await checkSurfaceLadder(options);
2716
2794
  if (options.jsonPath) {
2717
2795
  const abs = resolve6(options.jsonPath);
2718
- mkdirSync5(dirname4(abs), { recursive: true });
2796
+ mkdirSync5(dirname5(abs), { recursive: true });
2719
2797
  writeFileSync5(abs, `${JSON.stringify(report, null, 2)}
2720
2798
  `);
2721
2799
  }
@@ -2805,7 +2883,7 @@ function formatWorkspaceSurfaceReport(report) {
2805
2883
 
2806
2884
  // src/signoff/workspace-surface-cli.ts
2807
2885
  import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "fs";
2808
- import { dirname as dirname5, resolve as resolve7 } from "path";
2886
+ import { dirname as dirname6, resolve as resolve7 } from "path";
2809
2887
  var USAGE = [
2810
2888
  "Usage: agent-app-signoff workspace-surface --base-url <url> --route <path> [--route <path> ...] [options]",
2811
2889
  "",
@@ -2838,7 +2916,7 @@ ${USAGE}
2838
2916
  const report = await checkWorkspaceSurface(options);
2839
2917
  if (options.jsonPath) {
2840
2918
  const abs = resolve7(options.jsonPath);
2841
- mkdirSync6(dirname5(abs), { recursive: true });
2919
+ mkdirSync6(dirname6(abs), { recursive: true });
2842
2920
  writeFileSync6(abs, `${JSON.stringify(report, null, 2)}
2843
2921
  `);
2844
2922
  }
@@ -2898,4 +2976,4 @@ export {
2898
2976
  formatWorkspaceSurfaceReport,
2899
2977
  runWorkspaceSurfaceCli
2900
2978
  };
2901
- //# sourceMappingURL=chunk-XGFGSZS5.js.map
2979
+ //# sourceMappingURL=chunk-XBUZ43VQ.js.map