@imdeadpool/guardex 8.4.9 → 8.4.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imdeadpool/guardex",
3
- "version": "8.4.9",
3
+ "version": "8.4.10",
4
4
  "description": "Guardian T-Rex for your multi-agent repo. Isolated worktrees, file locks, and PR-only merges stop parallel Codex & Claude agents from overwriting each other's work. Auto-wires Oh My Codex, Oh My Claude, OpenSpec, and Caveman.",
5
5
  "license": "MIT",
6
6
  "preferGlobal": true,
@@ -97,5 +97,5 @@
97
97
  "jsonc-parser": "3.3.1",
98
98
  "semver": "7.7.4"
99
99
  },
100
- "gitHead": "31cc942b5979b018a7d8e119e02d6fbc4a6e33bb"
100
+ "gitHead": "b15d3e4583fb463b711a0260377314e4c349964f"
101
101
  }
@@ -317,7 +317,8 @@ OPTIONS
317
317
  --target <path> Target repository (default: current directory)
318
318
  --base <branch> Base branch used to determine merged branches
319
319
  --branch <agent/*> Limit cleanup to one agent branch
320
- --dry-run Print actions without changing branches or worktrees
320
+ --dry-run Preview cleanup actions and estimated sizes in KiB
321
+ --deps-only Preview idle worktree node_modules (requires --dry-run)
321
322
  --force-dirty Allow cleanup of dirty worktrees
322
323
  --keep-remote Keep remote agent branches
323
324
  --prune-clean-worktrees Explicitly prune clean, unmerged agent worktrees
@@ -342,6 +343,22 @@ OPTIONS
342
343
  }
343
344
 
344
345
  const activeCwd = process.cwd();
346
+ if (rawArgs.includes('--deps-only')) {
347
+ for (let i = 0; i < rawArgs.length; i += 1) {
348
+ const flag = rawArgs[i];
349
+ if (flag === '--target' || flag === '--branch') i += 1;
350
+ else if (flag !== '--deps-only' && flag !== '--dry-run') {
351
+ throw new Error(`${flag} is not supported with --deps-only`);
352
+ }
353
+ }
354
+ const { target, branch, dryRun } = parseCleanupArgs(
355
+ rawArgs.filter((arg) => arg !== '--deps-only')
356
+ );
357
+ if (!dryRun) throw new Error('--deps-only requires --dry-run');
358
+ require('./post-branch-finish-cleanup').previewDependencyCleanup(target, branch);
359
+ process.exitCode = 0;
360
+ return;
361
+ }
345
362
  const options = parseCleanupArgs(rawArgs);
346
363
  const repoRoot = resolveRepoRoot(options.target);
347
364
 
@@ -1,5 +1,5 @@
1
1
  const crypto = require('node:crypto');
2
- const { cp, fs, path, TOOL_NAME } = require('../context');
2
+ const { cp, fs, path, TOOL_NAME, LOCK_FILE_RELATIVE } = require('../context');
3
3
  const { currentBranchName, listAgentWorktrees, resolveRepoRoot } = require('../git');
4
4
  const { extractTargetedArgs, run } = require('../core/runtime');
5
5
 
@@ -212,6 +212,70 @@ function commonGitDirectory(repoRoot) {
212
212
  return fs.realpathSync(path.resolve(repoRoot, result.stdout.trim()));
213
213
  }
214
214
 
215
+ function hasWorktreeClaims(worktreePath) {
216
+ try {
217
+ const claims = JSON.parse(fs.readFileSync(path.join(worktreePath, LOCK_FILE_RELATIVE), 'utf8'));
218
+ const locks = claims?.locks;
219
+ return (
220
+ !locks || typeof locks !== 'object' || Array.isArray(locks) || Object.keys(locks).length > 0
221
+ );
222
+ } catch (error) {
223
+ return error.code !== 'ENOENT';
224
+ }
225
+ }
226
+
227
+ function previewDependencyCleanup(target, branchFilter) {
228
+ const repo = fs.realpathSync(resolveSharedRepoRoot(target));
229
+ const gitWorktrees = path.join(commonGitDirectory(repo), 'worktrees');
230
+ let candidates = 0;
231
+ let total = 0;
232
+ for (const { worktreePath, branch } of listAgentWorktrees(repo)) {
233
+ if (branchFilter && branch !== branchFilter) continue;
234
+ if (!isManagedAgentWorktree(repo, worktreePath)) continue;
235
+ const deps = path.join(worktreePath, 'node_modules');
236
+ try {
237
+ if (!fs.lstatSync(deps).isDirectory() || fs.realpathSync(worktreePath) !== worktreePath)
238
+ continue;
239
+ const git = (...args) =>
240
+ run('git', ['-C', worktreePath, ...args], { env: { GIT_OPTIONAL_LOCKS: '0' } });
241
+ const registration = git('rev-parse', '--absolute-git-dir');
242
+ if (registration.status !== 0) continue;
243
+ const gitDir = fs.realpathSync(registration.stdout.trim());
244
+ if (
245
+ gitDir === gitWorktrees ||
246
+ !pathContains(gitWorktrees, gitDir) ||
247
+ fs.lstatSync(path.join(gitDir, 'locked'), { throwIfNoEntry: false })
248
+ )
249
+ continue;
250
+ if (hasWorktreeClaims(worktreePath) || probeWorktreeOwnership(worktreePath).active) continue;
251
+
252
+ const manifests = ['package.json', 'package-lock.json'];
253
+ const tracked = git('ls-files', '-z', '--', ...manifests, 'node_modules');
254
+ const files = tracked.stdout.split('\0').filter(Boolean);
255
+ if (
256
+ tracked.status !== 0 ||
257
+ files.length !== manifests.length ||
258
+ !manifests.every(
259
+ (file) => files.includes(file) && fs.lstatSync(path.join(worktreePath, file)).isFile()
260
+ ) ||
261
+ git('check-ignore', '-q', '--', 'node_modules/').status !== 0
262
+ )
263
+ continue;
264
+ const disk = run('du', ['-skx', deps], { cwd: repo });
265
+ const size = Number(disk.stdout.match(/^\d+(?=\s)/)?.[0]);
266
+ if (disk.status !== 0 || !Number.isSafeInteger(size)) continue;
267
+ console.log(`[gx:cleanup] [dry-run] candidate | ${branch} | ${size} KiB | ${deps}`);
268
+ total += size;
269
+ candidates += 1;
270
+ } catch {
271
+ // Missing or unreadable state is not evidence that dependencies are reclaimable.
272
+ }
273
+ }
274
+ console.log(
275
+ `[gx:cleanup] [dry-run] dependencies: candidates=${candidates}, estimated=${total} KiB`
276
+ );
277
+ }
278
+
215
279
  function cleanupQueueDirectory(repoRoot, create = false) {
216
280
  const directory = path.join(commonGitDirectory(repoRoot), 'gitguardex-pending-cleanup');
217
281
  if (create) {
@@ -431,19 +495,7 @@ function removeFinishedWorktreeLocked(plan) {
431
495
  } else if (pathContains(plan.worktreePath, candidate)) return false;
432
496
  }
433
497
  if (!found) return false;
434
- const claimsFile = path.join(plan.worktreePath, '.omx/state/agent-file-locks.json');
435
- try {
436
- const claims = JSON.parse(fs.readFileSync(claimsFile, 'utf8'));
437
- if (
438
- !claims?.locks ||
439
- typeof claims.locks !== 'object' ||
440
- Array.isArray(claims.locks) ||
441
- Object.keys(claims.locks).length
442
- )
443
- return false;
444
- } catch (error) {
445
- if (error.code !== 'ENOENT') return false;
446
- }
498
+ if (hasWorktreeClaims(plan.worktreePath)) return false;
447
499
  const commit = run('git', ['-C', plan.worktreePath, 'rev-parse', 'HEAD']);
448
500
  if (commit.status !== 0 || commit.stdout.trim() !== plan.expectedHead) return false;
449
501
  if (probeWorktreeOwnership(plan.worktreePath).active) return false;
@@ -590,6 +642,7 @@ module.exports = {
590
642
  probeLiveProcessInWorktree,
591
643
  probeWorktreeOwnership,
592
644
  prepareBranchFinishCleanup,
645
+ previewDependencyCleanup,
593
646
  persistFinishedCleanup,
594
647
  retryPendingFinishedCleanup,
595
648
  runDeferredCleanupWorker,
@@ -1104,6 +1104,15 @@ finish_interrupted_removals() {
1104
1104
  return 0
1105
1105
  }
1106
1106
 
1107
+ report_dry_run_storage() {
1108
+ [[ "$DRY_RUN" -eq 1 ]] || return 0
1109
+ local size kib estimate="unknown"
1110
+ if size="$(du -skx "$3" 2>/dev/null)" && read -r kib _ <<< "$size" && [[ "$kib" =~ ^[0-9]+$ ]]; then
1111
+ estimate="${kib} KiB"
1112
+ fi
1113
+ printf '[agent-worktree-prune] [dry-run] storage | %s | %s | %s | %s\n' "$1" "$estimate" "$2" "$3"
1114
+ }
1115
+
1107
1116
  remove_worktree_with_lock_guard() {
1108
1117
  local worktree="$1"
1109
1118
  local remove_reason="$2"
@@ -1647,7 +1656,7 @@ process_entry() {
1647
1656
  return
1648
1657
  fi
1649
1658
 
1650
- if [[ "$remove_reason" == "temporary-worktree" ]]; then
1659
+ if [[ "$DRY_RUN" -ne 1 && "$remove_reason" == "temporary-worktree" ]]; then
1651
1660
  git -C "$wt" rebase --abort >/dev/null 2>&1 || true
1652
1661
  git -C "$wt" merge --abort >/dev/null 2>&1 || true
1653
1662
  fi
@@ -1659,6 +1668,7 @@ process_entry() {
1659
1668
  skipped_dirty=$((skipped_dirty + 1))
1660
1669
  echo "[agent-worktree-prune] Skipping dirty worktree (${remove_reason}): ${wt}"
1661
1670
  summarize_worktree_dirt "$wt"
1671
+ report_dry_run_storage kept 'uncommitted changes' "$wt"
1662
1672
  return
1663
1673
  fi
1664
1674
  fi
@@ -1709,6 +1719,7 @@ process_entry() {
1709
1719
  if [[ -n "$_precious_ignored" ]]; then
1710
1720
  skipped_dirty=$((skipped_dirty + 1))
1711
1721
  echo "[agent-worktree-prune] Skipping worktree with precious ignored files (${remove_reason}): ${wt}"
1722
+ report_dry_run_storage kept 'protected ignored files' "$wt"
1712
1723
  while IFS= read -r _pi_path; do
1713
1724
  [[ -n "$_pi_path" ]] && echo "[agent-worktree-prune] ignored: ${_pi_path}"
1714
1725
  done <<< "$_precious_ignored"
@@ -1729,6 +1740,7 @@ process_entry() {
1729
1740
 
1730
1741
  mark_pending_removal "$wt"
1731
1742
  if remove_worktree_with_lock_guard "$wt" "$remove_reason" "$branch"; then
1743
+ report_dry_run_storage candidate "$remove_reason" "$wt"
1732
1744
  clear_pending_removal "$wt"
1733
1745
  # The worktree list just changed; branch_has_worktree must re-read it.
1734
1746
  invalidate_worktree_branches
@@ -1744,6 +1756,7 @@ process_entry() {
1744
1756
  if [[ "$remove_status" -eq 11 ]]; then
1745
1757
  skipped_active=$((skipped_active + 1))
1746
1758
  echo "[agent-worktree-prune] Skipping worktree with registered descendants: ${wt}"
1759
+ report_dry_run_storage kept 'registered descendants' "$wt"
1747
1760
  return
1748
1761
  fi
1749
1762
  if [[ "$remove_status" -ne 10 ]]; then
@@ -1751,6 +1764,7 @@ process_entry() {
1751
1764
  fi
1752
1765
  skipped_active=$((skipped_active + 1))
1753
1766
  echo "[agent-worktree-prune] Skipping actively locked worktree: ${wt}"
1767
+ report_dry_run_storage kept 'active claims or lock guard' "$wt"
1754
1768
  return
1755
1769
  fi
1756
1770
 
@@ -1942,6 +1956,7 @@ prune_dependency_snapshots() {
1942
1956
  [[ "$(stat -c %Y -- "$dir" 2>/dev/null || echo "$now")" -lt "$cutoff" ]] || continue
1943
1957
  if [[ "$DRY_RUN" -eq 1 ]]; then
1944
1958
  echo "[agent-worktree-prune] [dry-run] Would remove unused dependency snapshot: ${dir}"
1959
+ report_dry_run_storage candidate 'unused dependency snapshot' "$dir"
1945
1960
  continue
1946
1961
  fi
1947
1962
  # Sealed read-only on creation.