@imdeadpool/guardex 8.4.6 → 8.4.7

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.6",
3
+ "version": "8.4.7",
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": "a8a451a154513fecd94b366f5e57dd84c55a7a58"
100
+ "gitHead": "35e5af1b87965537ad1fa8d6b1784603d0e12a53"
101
101
  }
@@ -67,11 +67,11 @@ function worktreePathForBranch(repoRoot, branch, worktrees = null) {
67
67
  };
68
68
  }
69
69
 
70
- function resolveBaseBranch(repoRoot, branch) {
71
- const perBranch = readGitConfig(repoRoot, `branch.${branch}.guardexBase`);
70
+ function resolveBaseBranch(repoRoot, branch, readConfig = readGitConfig) {
71
+ const perBranch = readConfig(repoRoot, `branch.${branch}.guardexbase`);
72
72
  if (perBranch) return perBranch;
73
73
 
74
- const configuredBase = readGitConfig(repoRoot, 'multiagent.baseBranch');
74
+ const configuredBase = readConfig(repoRoot, 'multiagent.basebranch');
75
75
  // Infer from history; do NOT persist (inspect is read-only display).
76
76
  const inferred = inferBaseBranchFromHistory(repoRoot, branch, {
77
77
  configuredBase,
@@ -131,20 +131,26 @@ function readUntrackedFiles(worktreePath) {
131
131
  }
132
132
 
133
133
  function inspectAgentBranch(options) {
134
- const repoRoot = resolveRepoRoot(options.target || process.cwd());
134
+ return inspectBranch(resolveRepoRoot(options.target || process.cwd()), options);
135
+ }
136
+
137
+ function inspectBranch(repoRoot, options, readConfig, compareBase = compareRefForBase) {
135
138
  const branch = String(options.branch || '').trim();
136
139
  if (!branch) {
137
140
  throw new Error('--branch requires an agent branch name');
138
141
  }
139
142
 
140
- const baseBranch = resolveBaseBranch(repoRoot, branch);
141
- const compareRef = compareRefForBase(repoRoot, baseBranch);
143
+ const baseBranch = resolveBaseBranch(repoRoot, branch, readConfig);
144
+ const compareRef = compareBase(repoRoot, baseBranch);
142
145
  const { worktreePath, worktreeFound } = worktreePathForBranch(repoRoot, branch, options.worktrees);
143
146
  return { repoRoot, branch, baseBranch, compareRef, worktreePath, worktreeFound };
144
147
  }
145
148
 
146
149
  function changedFiles(options) {
147
- const context = inspectAgentBranch(options);
150
+ return changedFilesInContext(inspectAgentBranch(options));
151
+ }
152
+
153
+ function changedFilesInContext(context) {
148
154
  const diffTarget = context.worktreeFound ? context.compareRef : `${context.compareRef}...${context.branch}`;
149
155
  const result = git(context.worktreePath, ['diff', '--name-only', diffTarget, '--', '.', `:(exclude)${LOCK_FILE_RELATIVE}`]);
150
156
  const files = [...splitGitLines(result.stdout), ...(context.worktreeFound ? readUntrackedFiles(context.worktreePath) : [])];
@@ -152,6 +158,32 @@ function changedFiles(options) {
152
158
  return { ...context, files: uniqueFiles };
153
159
  }
154
160
 
161
+ function createChangedFilesReader(target, worktrees) {
162
+ const repoRoot = resolveRepoRoot(target);
163
+ // Git's scalar config getter takes the last value. Preserve that precedence
164
+ // and the subsection's case; only the section and key are canonicalized.
165
+ const result = git(repoRoot, ['config', '--null', '--get-regexp', '^(branch\\..*\\.guardexbase|multiagent\\.basebranch)$'],
166
+ { allowFailure: true });
167
+ const config = new Map();
168
+ if (result.status === 0) {
169
+ for (const entry of String(result.stdout || '').split('\0')) {
170
+ if (!entry) continue;
171
+ const separator = entry.indexOf('\n');
172
+ if (separator < 0) config.set(entry, '');
173
+ else config.set(entry.slice(0, separator), entry.slice(separator + 1).trim());
174
+ }
175
+ }
176
+ const readConfig = result.status === 0 || result.status === 1
177
+ ? (_repo, key) => config.get(key) || ''
178
+ : readGitConfig;
179
+ const compareRefs = new Map();
180
+ const compareBase = (repo, base) => {
181
+ if (!compareRefs.has(base)) compareRefs.set(base, compareRefForBase(repo, base));
182
+ return compareRefs.get(base);
183
+ };
184
+ return (branch) => changedFilesInContext(inspectBranch(repoRoot, { branch, worktrees }, readConfig, compareBase)).files;
185
+ }
186
+
155
187
  function branchDiff(options) {
156
188
  const context = inspectAgentBranch(options);
157
189
  const diffTarget = context.worktreeFound ? context.compareRef : `${context.compareRef}...${context.branch}`;
@@ -198,6 +230,7 @@ module.exports = {
198
230
  branchDiff,
199
231
  branchLocks,
200
232
  changedFiles,
233
+ createChangedFilesReader,
201
234
  inspectAgentBranch,
202
235
  listWorktrees,
203
236
  parseWorktreeList,
@@ -1,5 +1,5 @@
1
1
  const { fs, path, LOCK_FILE_RELATIVE, TOOL_NAME } = require('../context');
2
- const { changedFiles, listWorktrees } = require('./inspect');
2
+ const { createChangedFilesReader, listWorktrees } = require('./inspect');
3
3
  const { listAgentSessions } = require('./sessions');
4
4
 
5
5
  function uniqueSorted(values) {
@@ -35,13 +35,21 @@ function readLockDetails(repoRoot) {
35
35
  return { counts, files };
36
36
  }
37
37
 
38
- function readChangedFiles(repoRoot, branch, worktrees) {
39
- if (!branch) return [];
40
- try {
41
- return changedFiles({ target: repoRoot, branch, worktrees }).files || [];
42
- } catch (_error) {
43
- return [];
44
- }
38
+ function statusChangedFilesReader() {
39
+ let readFiles;
40
+ const byBranch = new Map();
41
+ return (repoRoot, branch, worktrees) => {
42
+ if (!branch) return [];
43
+ if (!byBranch.has(branch)) {
44
+ try {
45
+ readFiles ||= createChangedFilesReader(repoRoot, worktrees);
46
+ byBranch.set(branch, readFiles(branch));
47
+ } catch (_error) {
48
+ byBranch.set(branch, []);
49
+ }
50
+ }
51
+ return [...byBranch.get(branch)];
52
+ };
45
53
  }
46
54
 
47
55
  function normalizePr(session) {
@@ -53,7 +61,7 @@ function normalizePr(session) {
53
61
  };
54
62
  }
55
63
 
56
- function normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, readChanges = readChangedFiles) {
64
+ function normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, readChanges) {
57
65
  const branch = session.branch || '';
58
66
  const worktreePath = session.worktreePath || '';
59
67
  const claimedFiles = uniqueSorted([
@@ -84,14 +92,17 @@ function normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, re
84
92
  }
85
93
 
86
94
  function buildAgentsStatusPayload(repoRoot) {
95
+ const sessions = listAgentSessions(repoRoot);
96
+ if (!sessions.length) return { schemaVersion: 1, repoRoot, sessions };
87
97
  const lockDetails = readLockDetails(repoRoot);
88
98
  // Hoist the invariant `git worktree list` out of the per-session loop: fetch it
89
99
  // once here instead of once inside every session's changedFiles() (~6N -> ~6+N).
90
100
  const worktrees = listWorktrees(repoRoot);
101
+ const readChanges = statusChangedFilesReader();
91
102
  return {
92
103
  schemaVersion: 1,
93
104
  repoRoot,
94
- sessions: listAgentSessions(repoRoot).map((session) => normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees)),
105
+ sessions: sessions.map((session) => normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, readChanges)),
95
106
  };
96
107
  }
97
108
 
@@ -151,8 +162,9 @@ function writeStatusCommand(repoRoot, options = {}, output = process.stdout, dep
151
162
  output.write(`[${TOOL_NAME}] Agent sessions: ${sessions.length} (${repoRoot})\n`);
152
163
  const lockDetails = readLockDetails(repoRoot);
153
164
  const worktrees = (deps.listWorktrees || listWorktrees)(repoRoot);
165
+ const readChanges = deps.readChangedFiles || statusChangedFilesReader();
154
166
  for (const session of sessions) {
155
- const row = normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, deps.readChangedFiles);
167
+ const row = normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, readChanges);
156
168
  output.write(`${renderSession(row)}\n`);
157
169
  }
158
170
  }