@imdeadpool/guardex 8.4.6 → 8.4.8
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 +2 -2
- package/src/agents/inspect.js +40 -7
- package/src/agents/status.js +23 -11
- package/src/pr-review.js +32 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imdeadpool/guardex",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.8",
|
|
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": "
|
|
100
|
+
"gitHead": "c1e778ff30fbe25c983621339113227edecbe6ec"
|
|
101
101
|
}
|
package/src/agents/inspect.js
CHANGED
|
@@ -67,11 +67,11 @@ function worktreePathForBranch(repoRoot, branch, worktrees = null) {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function resolveBaseBranch(repoRoot, branch) {
|
|
71
|
-
const perBranch =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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,
|
package/src/agents/status.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { fs, path, LOCK_FILE_RELATIVE, TOOL_NAME } = require('../context');
|
|
2
|
-
const {
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
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:
|
|
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,
|
|
167
|
+
const row = normalizeSessionForStatus(session, lockDetails, repoRoot, worktrees, readChanges);
|
|
156
168
|
output.write(`${renderSession(row)}\n`);
|
|
157
169
|
}
|
|
158
170
|
}
|
package/src/pr-review.js
CHANGED
|
@@ -148,8 +148,9 @@ function compactReviewPrompt(
|
|
|
148
148
|
'Also add a top-level "value" alongside "findings", even for clean diffs.',
|
|
149
149
|
'Estimate the net repository impact of merging this diff as written vs. not merging: weigh evidenced benefits against costs and risks, not finding count or diff size.',
|
|
150
150
|
'Use integer anchors: 0 severe net harm, 25 material harm, 50 neutral or trivial, 75 material benefit, 100 exceptional repository-level benefit.',
|
|
151
|
-
`"value":{"score":75,"drivers":[{"area":"${Object.keys(VALUE_AREAS).join('|')}","impact":"${Object.keys(VALUE_IMPACTS).join('|')}","reason":"changed behavior
|
|
151
|
+
`"value":{"score":75,"drivers":[{"area":"${Object.keys(VALUE_AREAS).join('|')}","impact":"${Object.keys(VALUE_IMPACTS).join('|')}","reason":"changed behavior and its consequence","evidence":{"path":"file","line":123}}],"improvements":[]}`,
|
|
152
152
|
'Give 1–3 distinct, diff-grounded drivers, up to 200 characters each. Use plain text. Do not invent benchmark results, test passes, or adoption. Return "value":null if there is not enough evidence.',
|
|
153
|
+
'When a specific line supports a driver, include its exact repository-relative path and integer new-side diff line, preferably an added line. Otherwise omit "evidence". Never return evidence URLs.',
|
|
153
154
|
'In "improvements", list at most two distinct, actionable changes or checks tied to the diff, highest impact first, up to 200 plain-text characters each. Omit generic advice, repeated findings, and predicted point gains. Use [] if nothing material is worth suggesting. Score only the PR as written.'
|
|
154
155
|
]
|
|
155
156
|
: []),
|
|
@@ -250,18 +251,23 @@ function normalizeValueText(text) {
|
|
|
250
251
|
return clean.length <= 200 ? clean : '';
|
|
251
252
|
}
|
|
252
253
|
|
|
253
|
-
function normalizeReviewValue(value) {
|
|
254
|
+
function normalizeReviewValue(value, lineMap) {
|
|
254
255
|
const { score, drivers, improvements } = value ?? {};
|
|
255
256
|
if (!Number.isInteger(score) || score < 0 || score > 100) return null;
|
|
256
257
|
if (!Array.isArray(drivers) || drivers.length < 1 || drivers.length > 3) return null;
|
|
257
258
|
const normalized = [];
|
|
258
259
|
for (const driver of drivers) {
|
|
259
|
-
const { area, impact, reason } = driver ?? {};
|
|
260
|
+
const { area, impact, reason, evidence } = driver ?? {};
|
|
260
261
|
if (typeof area !== 'string' || !Object.hasOwn(VALUE_AREAS, area)) return null;
|
|
261
262
|
if (typeof impact !== 'string' || !Object.hasOwn(VALUE_IMPACTS, impact)) return null;
|
|
262
263
|
const clean = normalizeValueText(reason);
|
|
263
264
|
if (!clean) return null;
|
|
264
|
-
|
|
265
|
+
const entry = { area, impact, reason: clean };
|
|
266
|
+
const { path, line } = evidence ?? {};
|
|
267
|
+
if (typeof path === 'string' && Number.isInteger(line) && line > 0 && lineMap.get(path)?.has(line)) {
|
|
268
|
+
entry.evidence = { path, line };
|
|
269
|
+
}
|
|
270
|
+
normalized.push(entry);
|
|
265
271
|
}
|
|
266
272
|
const actions = new Set();
|
|
267
273
|
if (Array.isArray(improvements)) {
|
|
@@ -279,15 +285,20 @@ function escapeValueText(text) {
|
|
|
279
285
|
return text.replace(/[&<>@\\[\]_*\x60~!|:.#$()+-]/g, (char) => `&#${char.charCodeAt(0)};`);
|
|
280
286
|
}
|
|
281
287
|
|
|
282
|
-
function reviewValueLines(value, truncated) {
|
|
288
|
+
function reviewValueLines(value, truncated, reviewDiffPath) {
|
|
283
289
|
if (truncated) return ['**PR value: unavailable** — diff is incomplete.'];
|
|
284
290
|
if (!value) return ['**PR value: unavailable** — no supported estimate for this diff.'];
|
|
285
291
|
return [
|
|
286
292
|
`**PR value: ${value.score}/100** — AI estimate from the diff; 50 = neutral. Not a merge verdict.`,
|
|
287
293
|
'',
|
|
288
|
-
...value.drivers.map(({ area, impact, reason }) =>
|
|
289
|
-
`- **${VALUE_IMPACTS[impact]} — ${VALUE_AREAS[area]}:** ${escapeValueText(reason)}
|
|
290
|
-
|
|
294
|
+
...value.drivers.map(({ area, impact, reason, evidence }) => {
|
|
295
|
+
const driver = `- **${VALUE_IMPACTS[impact]} — ${VALUE_AREAS[area]}:** ${escapeValueText(reason)}`;
|
|
296
|
+
if (!evidence) return driver;
|
|
297
|
+
const label = escapeValueText(`${evidence.path}:${evidence.line}`);
|
|
298
|
+
if (!reviewDiffPath) return `${driver} — ${label}`;
|
|
299
|
+
const hash = crypto.createHash('sha256').update(evidence.path).digest('hex');
|
|
300
|
+
return `${driver} — [${label}](${reviewDiffPath}#diff-${hash}R${evidence.line})`;
|
|
301
|
+
}),
|
|
291
302
|
...(value.improvements?.length
|
|
292
303
|
? [
|
|
293
304
|
'',
|
|
@@ -399,7 +410,8 @@ function renderReviewSummary({
|
|
|
399
410
|
gate,
|
|
400
411
|
degraded = false,
|
|
401
412
|
abide: abideResult,
|
|
402
|
-
value
|
|
413
|
+
value,
|
|
414
|
+
reviewDiffPath
|
|
403
415
|
}) {
|
|
404
416
|
const lines = [MARKER, '### 🛡️ GitGuardex code-assist', ''];
|
|
405
417
|
|
|
@@ -431,7 +443,7 @@ function renderReviewSummary({
|
|
|
431
443
|
);
|
|
432
444
|
}
|
|
433
445
|
|
|
434
|
-
lines.push('', ...reviewValueLines(value, truncated));
|
|
446
|
+
lines.push('', ...reviewValueLines(value, truncated, reviewDiffPath));
|
|
435
447
|
|
|
436
448
|
const footer = [`Provider \`${provider}\``];
|
|
437
449
|
if (commit) footer.push(`commit \`${commit.slice(0, 7)}\``);
|
|
@@ -776,6 +788,9 @@ function postGithubReview(pr, context, repoRoot, runner = run) {
|
|
|
776
788
|
throw new Error('PR changed before posting the PR Lens review; rerun against the current diff');
|
|
777
789
|
}
|
|
778
790
|
|
|
791
|
+
const slug = context.value?.drivers.some((driver) => driver.evidence) && /^\d+$/.test(pr)
|
|
792
|
+
? repoNameWithOwner(repoRoot, runner)
|
|
793
|
+
: '';
|
|
779
794
|
const summaryArgs = {
|
|
780
795
|
provider,
|
|
781
796
|
findings,
|
|
@@ -785,7 +800,9 @@ function postGithubReview(pr, context, repoRoot, runner = run) {
|
|
|
785
800
|
truncated,
|
|
786
801
|
gate,
|
|
787
802
|
abide: context.abide,
|
|
788
|
-
value: context.value
|
|
803
|
+
value: context.value,
|
|
804
|
+
// A root-relative link keeps the PR on the same GitHub host.
|
|
805
|
+
reviewDiffPath: slug ? `/${slug}/pull/${pr}/files` : ''
|
|
789
806
|
};
|
|
790
807
|
const payload = {
|
|
791
808
|
event: 'COMMENT',
|
|
@@ -925,7 +942,7 @@ function runProviderReviewPayload(provider, diff, repoRoot, timeoutMs, runner, s
|
|
|
925
942
|
return {
|
|
926
943
|
findings,
|
|
927
944
|
graph: settings.prLens ? payload.graph : undefined,
|
|
928
|
-
value: settings.truncated ? null :
|
|
945
|
+
value: settings.truncated ? null : payload.value
|
|
929
946
|
};
|
|
930
947
|
} catch (error) {
|
|
931
948
|
parseError = error;
|
|
@@ -1062,13 +1079,14 @@ function runPrReview(options, deps = {}) {
|
|
|
1062
1079
|
model = null;
|
|
1063
1080
|
review = reviewWithProvider();
|
|
1064
1081
|
}
|
|
1065
|
-
const { findings: providerFindings, graph
|
|
1082
|
+
const { findings: providerFindings, graph } = review;
|
|
1066
1083
|
const abideResult = collectAbideFindings(repoRoot, rawDiff, options, deps);
|
|
1067
1084
|
if (abideResult.status === 'failed')
|
|
1068
1085
|
console.log(`${TOOL_PREFIX} ${abideSummaryLine(abideResult)}`);
|
|
1069
1086
|
const findings = [...providerFindings, ...abideResult.findings];
|
|
1070
1087
|
let prLens;
|
|
1071
|
-
const { anchored, unanchored } = partitionByAnchor(findings, rawDiff);
|
|
1088
|
+
const { anchored, unanchored, lineMap } = partitionByAnchor(findings, rawDiff);
|
|
1089
|
+
const value = normalizeReviewValue(review.value, lineMap);
|
|
1072
1090
|
const gate = {
|
|
1073
1091
|
...evaluateReviewGate(findings, { blockSeverities: options.blockSeverities }),
|
|
1074
1092
|
blockSeverities: options.blockSeverities || ['high', 'critical']
|