@imdeadpool/guardex 8.4.7 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. 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.7",
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": "35e5af1b87965537ad1fa8d6b1784603d0e12a53"
100
+ "gitHead": "c1e778ff30fbe25c983621339113227edecbe6ec"
101
101
  }
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 or file and its consequence"}],"improvements":[]}`,
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
- normalized.push({ area, impact, reason: clean });
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 : normalizeReviewValue(payload.value)
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, value } = review;
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']