shield-llm 0.6.6 → 0.6.9

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/dist/cli.js CHANGED
@@ -14,17 +14,17 @@ import {
14
14
  GUARDRAIL_PREFIX,
15
15
  LAYER_META,
16
16
  MUTATORS,
17
- MVP_ATTACKS,
18
17
  RECIPES,
19
18
  RegexOnlyEvaluator,
20
19
  Scanner,
21
20
  analyzeJudgeHealth,
21
+ attacksForContract,
22
22
  baseAttackId,
23
23
  buildAuthFromFlags,
24
24
  buildTargetConfig,
25
- buildVariantPayload,
26
25
  c,
27
26
  calculateComplianceScore,
27
+ checkConversationContext,
28
28
  checkSessionIsolation,
29
29
  computeCatalogHash,
30
30
  computeScanKey,
@@ -48,10 +48,10 @@ import {
48
48
  getObligationProfile,
49
49
  getStructuredRemediation,
50
50
  isExpired,
51
- isVariantId,
52
51
  loadConfig,
53
52
  loadSystemPrompt,
54
53
  mayStampFixed,
54
+ missingForContract,
55
55
  normalizeTargetUrl,
56
56
  parseSegmentKey,
57
57
  parseSnapshot,
@@ -59,10 +59,11 @@ import {
59
59
  resolveClaim,
60
60
  resolveOfflinePosition,
61
61
  retestDedupKey,
62
+ serializeAttack,
62
63
  sha256Hex,
63
64
  summarizeAttackErrors,
64
65
  version
65
- } from "./chunk-4QYDLRL6.js";
66
+ } from "./chunk-TWBU67PH.js";
66
67
 
67
68
  // src/load-env.ts
68
69
  try {
@@ -2453,6 +2454,37 @@ async function reportScanFailure(credentials, scanId, reason) {
2453
2454
  } catch {
2454
2455
  }
2455
2456
  }
2457
+ async function reserveScanSlot(credentials, targetUrl) {
2458
+ try {
2459
+ const res = await fetch(`${credentials.apiUrl}/api/cli/scans`, {
2460
+ method: "POST",
2461
+ headers: {
2462
+ "Content-Type": "application/json",
2463
+ Authorization: `Bearer ${credentials.apiKey}`
2464
+ },
2465
+ body: JSON.stringify({ targetUrl })
2466
+ });
2467
+ if (res.status === 401) {
2468
+ console.error(
2469
+ "API key is invalid or revoked. Run `shield-llm login` to re-authenticate."
2470
+ );
2471
+ setExitCode(2);
2472
+ return null;
2473
+ }
2474
+ if (!res.ok) {
2475
+ console.error(`Failed to start scan: HTTP ${res.status}`);
2476
+ setExitCode(3);
2477
+ return null;
2478
+ }
2479
+ const scanSlot = await res.json();
2480
+ return scanSlot.scanId;
2481
+ } catch (err) {
2482
+ const msg = err instanceof Error ? err.message : "Unknown error";
2483
+ console.error(`Failed to connect to backend: ${msg}`);
2484
+ setExitCode(3);
2485
+ return null;
2486
+ }
2487
+ }
2456
2488
  function resolveMutateSelection(value) {
2457
2489
  if (value === void 0 || value === false) return null;
2458
2490
  if (value === true) return { mutators: [...MUTATORS], unknown: [] };
@@ -2541,35 +2573,6 @@ async function scanCommand(opts) {
2541
2573
  return;
2542
2574
  }
2543
2575
  failTarget = { apiUrl: credentials.apiUrl, apiKey: credentials.apiKey };
2544
- try {
2545
- const res = await fetch(`${credentials.apiUrl}/api/cli/scans`, {
2546
- method: "POST",
2547
- headers: {
2548
- "Content-Type": "application/json",
2549
- Authorization: `Bearer ${credentials.apiKey}`
2550
- }
2551
- });
2552
- if (res.status === 401) {
2553
- console.error(
2554
- "API key is invalid or revoked. Run `shield-llm login` to re-authenticate."
2555
- );
2556
- setExitCode(2);
2557
- return;
2558
- }
2559
- if (!res.ok) {
2560
- console.error(`Failed to start scan: HTTP ${res.status}`);
2561
- setExitCode(3);
2562
- return;
2563
- }
2564
- const scanSlot = await res.json();
2565
- reservedScanId = scanSlot.scanId;
2566
- info("Scan started");
2567
- } catch (err) {
2568
- const msg = err instanceof Error ? err.message : "Unknown error";
2569
- console.error(`Failed to connect to backend: ${msg}`);
2570
- setExitCode(3);
2571
- return;
2572
- }
2573
2576
  const evaluator = new BackendEvaluator(
2574
2577
  credentials.apiUrl,
2575
2578
  credentials.apiKey
@@ -2671,6 +2674,14 @@ async function scanCommand(opts) {
2671
2674
  if (!isolation.isolated) console.warn(`
2672
2675
  \u26A0\uFE0F ${isolation.warning}
2673
2676
  `);
2677
+ if (includeCrescendo && (multiTurnAttacks?.length ?? 0) > 0) {
2678
+ const conversation = checkConversationContext(target);
2679
+ if (!conversation.carried) {
2680
+ console.warn(`
2681
+ \u26A0\uFE0F ${conversation.warning}
2682
+ `);
2683
+ }
2684
+ }
2674
2685
  const catalogHash = computeCatalogHash([
2675
2686
  ...(attacks ?? []).map((a) => a.id),
2676
2687
  ...(multiTurnAttacks ?? []).map((a) => a.id),
@@ -2717,8 +2728,20 @@ async function scanCommand(opts) {
2717
2728
  evaluator
2718
2729
  };
2719
2730
  const onEvent = opts.progress !== false ? handleEvent : void 0;
2731
+ reservedScanId = await reserveScanSlot(credentials, target.url);
2732
+ if (!reservedScanId) return;
2733
+ info("Scan started");
2720
2734
  const scanner = new Scanner(scanOptions, onEvent);
2721
2735
  const report = await scanner.run();
2736
+ if (report.stopReason === "auth") {
2737
+ const judged = scoredAttacks(report.attacks).length;
2738
+ const reason = `The target refused the scan's credentials (HTTP 401) after ${judged}/${report.attacks.length} attacks \u2014 the token has probably expired. Refresh it and re-run the same command: the ${judged} judged attack(s) resume from the checkpoint.`;
2739
+ await reportScanFailure(credentials, reservedScanId, reason);
2740
+ scanFinalized = true;
2741
+ console.error(`Scan stopped: ${reason}`);
2742
+ setExitCode(2);
2743
+ return;
2744
+ }
2722
2745
  const attempted = report.attacks.length;
2723
2746
  const evaluated = scoredAttacks(report.attacks).length;
2724
2747
  if (reservedScanId && attempted > 0 && evaluated === 0) {
@@ -2763,6 +2786,14 @@ async function scanCommand(opts) {
2763
2786
  console.warn(
2764
2787
  "Showing the locally-computed score \u2014 it may differ from the dashboard."
2765
2788
  );
2789
+ if (reservedScanId && !scanFinalized) {
2790
+ await reportScanFailure(
2791
+ credentials,
2792
+ reservedScanId,
2793
+ `Scan ran but its results could not be saved: ${msg}`
2794
+ );
2795
+ scanFinalized = true;
2796
+ }
2766
2797
  }
2767
2798
  const benchmarkEligible = presetForScan === "full" && !customOnly && (config.customTests?.length ?? 0) === 0 && attackPackVersion !== void 0;
2768
2799
  if (opts.consent || benchmarkEligible) {
@@ -4167,7 +4198,8 @@ async function judgeBenign(captures, cases, evaluator) {
4167
4198
  async function runBenignGate(input2) {
4168
4199
  const { baseline, contract, target } = input2;
4169
4200
  const scope = baseline?.scope ?? contract.benignScope;
4170
- if (scope === "none") return { green: true, detail: "no benign surface", ran: false };
4201
+ if (scope === "none")
4202
+ return { green: true, detail: "no benign surface", ran: false };
4171
4203
  const cannotRun = !baseline || scope === "model-behaviour" && !input2.evaluator;
4172
4204
  if (cannotRun && input2.assumeGreen) {
4173
4205
  console.warn(
@@ -4227,14 +4259,7 @@ async function runBenignGate(input2) {
4227
4259
  };
4228
4260
  }
4229
4261
  async function replayFamily(contract, target, catalogue, evaluator) {
4230
- const wanted = /* @__PURE__ */ new Set([
4231
- ...contract.designAttackIds,
4232
- ...contract.holdoutAttackIds
4233
- ]);
4234
- const attacks = [
4235
- ...catalogue.filter((a) => wanted.has(a.id)),
4236
- ...Array.from(wanted).filter(isVariantId).map((id) => buildVariantPayload(id, catalogue)).filter((a) => a !== null)
4237
- ];
4262
+ const attacks = attacksForContract(contract, catalogue);
4238
4263
  const report = await new Scanner({
4239
4264
  target,
4240
4265
  // CLI-only: expand $VAR auth references from the environment, as every
@@ -4294,8 +4319,12 @@ function describeLiveVerification(v) {
4294
4319
  return `design ${v.designClearedIds.length}/${v.designAttackIds.length} closed, holdout ${v.holdoutClearedIds.length}/${v.holdoutAttackIds.length} closed, benign ${v.benign.ran ? "green" : v.benign.detail}`;
4295
4320
  }
4296
4321
  const why = [];
4297
- const designOpen = v.designAttackIds.filter((a) => !v.designClearedIds.includes(a));
4298
- const holdoutOpen = v.holdoutAttackIds.filter((a) => !v.holdoutClearedIds.includes(a));
4322
+ const designOpen = v.designAttackIds.filter(
4323
+ (a) => !v.designClearedIds.includes(a)
4324
+ );
4325
+ const holdoutOpen = v.holdoutAttackIds.filter(
4326
+ (a) => !v.holdoutClearedIds.includes(a)
4327
+ );
4299
4328
  if (designOpen.length) why.push(`still vulnerable: ${designOpen.join(", ")}`);
4300
4329
  if (holdoutOpen.length) {
4301
4330
  why.push(
@@ -4311,7 +4340,8 @@ function describeLiveVerification(v) {
4311
4340
  );
4312
4341
  }
4313
4342
  if (!v.benign.green) why.push(`benign gate: ${v.benign.detail}`);
4314
- if (v.judgeDegraded) why.push("the judge degraded mid-replay, so no verdict is trustworthy");
4343
+ if (v.judgeDegraded)
4344
+ why.push("the judge degraded mid-replay, so no verdict is trustworthy");
4315
4345
  return why.join(" \xB7 ");
4316
4346
  }
4317
4347
 
@@ -4708,7 +4738,8 @@ ${manualPrInstructions(branch, base)}`
4708
4738
 
4709
4739
  // src/commands/fix.ts
4710
4740
  function resolveEvaluator(opts) {
4711
- if (opts.evaluator) return { evaluator: opts.evaluator, judgeAvailable: true };
4741
+ if (opts.evaluator)
4742
+ return { evaluator: opts.evaluator, judgeAvailable: true };
4712
4743
  const creds = loadCredentials();
4713
4744
  if (creds?.apiKey && creds.apiUrl) {
4714
4745
  return {
@@ -4721,10 +4752,43 @@ function resolveEvaluator(opts) {
4721
4752
  );
4722
4753
  return { evaluator: new RegexOnlyEvaluator(), judgeAvailable: false };
4723
4754
  }
4755
+ var catalogueCache = /* @__PURE__ */ new WeakMap();
4756
+ async function resolveCatalogue(opts) {
4757
+ const cached = catalogueCache.get(opts);
4758
+ if (cached) return cached;
4759
+ const pending = (async () => {
4760
+ if (opts.attacks) return { attacks: opts.attacks };
4761
+ const stored = loadCredentials();
4762
+ if (!stored) {
4763
+ return {
4764
+ attacks: null,
4765
+ reason: "not logged in \u2014 run `shield-llm login --key <your-key>`"
4766
+ };
4767
+ }
4768
+ try {
4769
+ const fetched = await fetchAttacks({
4770
+ apiUrl: resolveApiUrl(stored.apiUrl, opts.apiUrl),
4771
+ apiKey: stored.apiKey,
4772
+ // Single-turn only, matching what the replay can run. Multi-turn
4773
+ // attacks are not addressed by a recipe and never appear in a contract.
4774
+ preset: "full"
4775
+ });
4776
+ return { attacks: fetched.attacks };
4777
+ } catch (err) {
4778
+ return {
4779
+ attacks: null,
4780
+ reason: err instanceof Error ? err.message : "unknown error"
4781
+ };
4782
+ }
4783
+ })();
4784
+ catalogueCache.set(opts, pending);
4785
+ return pending;
4786
+ }
4724
4787
  function findingsFromLocalReport(path) {
4725
4788
  const parsed = JSON.parse(readFileSync6(path, "utf8"));
4726
4789
  const r = parsed.report;
4727
- if (!r?.attacks) throw new Error(`${path} is not a shield-llm --write-json report`);
4790
+ if (!r?.attacks)
4791
+ throw new Error(`${path} is not a shield-llm --write-json report`);
4728
4792
  return {
4729
4793
  allAttacks: r.attacks.map((a) => ({
4730
4794
  id: a.id,
@@ -4748,14 +4812,20 @@ function findingsFromLocalReport(path) {
4748
4812
  var CODE_EXT = /\.(ts|tsx|js|jsx|mjs|cjs|py|rb|go|java|php)$/;
4749
4813
  function uncommittedCode(cwd) {
4750
4814
  try {
4751
- return execFileSync3("git", ["status", "--porcelain"], { cwd, encoding: "utf8" }).split("\n").filter(Boolean).map((l) => l.slice(3).trim()).filter((p) => CODE_EXT.test(p));
4815
+ return execFileSync3("git", ["status", "--porcelain"], {
4816
+ cwd,
4817
+ encoding: "utf8"
4818
+ }).split("\n").filter(Boolean).map((l) => l.slice(3).trim()).filter((p) => CODE_EXT.test(p));
4752
4819
  } catch {
4753
4820
  return [];
4754
4821
  }
4755
4822
  }
4756
4823
  function gitIsClean(cwd) {
4757
4824
  try {
4758
- return execFileSync3("git", ["status", "--porcelain"], { cwd, encoding: "utf8" }).trim().length === 0;
4825
+ return execFileSync3("git", ["status", "--porcelain"], {
4826
+ cwd,
4827
+ encoding: "utf8"
4828
+ }).trim().length === 0;
4759
4829
  } catch {
4760
4830
  return true;
4761
4831
  }
@@ -4773,7 +4843,9 @@ function printPlan(plan) {
4773
4843
  console.log();
4774
4844
  }
4775
4845
  if (plan.skipped.length) {
4776
- console.log(`Not patchable (${plan.skipped.length}) \u2014 these become issues, not PRs:`);
4846
+ console.log(
4847
+ `Not patchable (${plan.skipped.length}) \u2014 these become issues, not PRs:`
4848
+ );
4777
4849
  for (const s of plan.skipped) {
4778
4850
  console.log(` \xB7 ${s.attackId.padEnd(24)} ${s.reason}: ${s.detail}`);
4779
4851
  }
@@ -4795,12 +4867,15 @@ function printDiff(changes) {
4795
4867
  const before = c2.before.split("\n");
4796
4868
  const after = c2.after.split("\n");
4797
4869
  let head = 0;
4798
- while (head < before.length && head < after.length && before[head] === after[head]) head++;
4870
+ while (head < before.length && head < after.length && before[head] === after[head])
4871
+ head++;
4799
4872
  let tail = 0;
4800
4873
  while (tail < before.length - head && tail < after.length - head && before[before.length - 1 - tail] === after[after.length - 1 - tail])
4801
4874
  tail++;
4802
- for (const line of before.slice(head, before.length - tail)) console.log(`-${line}`);
4803
- for (const line of after.slice(head, after.length - tail)) console.log(`+${line}`);
4875
+ for (const line of before.slice(head, before.length - tail))
4876
+ console.log(`-${line}`);
4877
+ for (const line of after.slice(head, after.length - tail))
4878
+ console.log(`+${line}`);
4804
4879
  }
4805
4880
  }
4806
4881
  async function fixCommand(opts) {
@@ -4809,7 +4884,9 @@ async function fixCommand(opts) {
4809
4884
  try {
4810
4885
  config = loadConfig({ configPath: opts.config });
4811
4886
  } catch (e) {
4812
- console.error(e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`);
4887
+ console.error(
4888
+ e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`
4889
+ );
4813
4890
  setExitCode(2);
4814
4891
  return;
4815
4892
  }
@@ -4846,7 +4923,9 @@ async function fixCommand(opts) {
4846
4923
  try {
4847
4924
  plan = buildPlan(findings, targetUrl, codebase, cwd, {
4848
4925
  minConfidence: opts.minConfidence,
4849
- disagreementAvailable: findings.some((f) => f.disagreementResolution != null),
4926
+ disagreementAvailable: findings.some(
4927
+ (f) => f.disagreementResolution != null
4928
+ ),
4850
4929
  knownSecrets: config.endpoint?.knownSecrets
4851
4930
  });
4852
4931
  } catch (e) {
@@ -4945,7 +5024,10 @@ Commit or stash them first. (Non-code changes are fine and are named in the PR b
4945
5024
  anchors: plan.anchors,
4946
5025
  dryRun: opts.dryRun
4947
5026
  });
4948
- touchedByFinding.set(p.fingerprint, res.changes.map((c2) => c2.path));
5027
+ touchedByFinding.set(
5028
+ p.fingerprint,
5029
+ res.changes.map((c2) => c2.path)
5030
+ );
4949
5031
  if (res.noop) {
4950
5032
  console.log(`${p.recipe.id}: already applied (no-op)`);
4951
5033
  continue;
@@ -4979,7 +5061,14 @@ ${e.message}`);
4979
5061
  }
4980
5062
  plan.planned = plan.planned.filter((p) => !collided.has(p.fingerprint));
4981
5063
  if (opts.dryRun || plan.planned.length === 0) return;
4982
- let live = await liveVerificationPhase(plan, config, codebase, cwd, opts, benignBaseline);
5064
+ let live = await liveVerificationPhase(
5065
+ plan,
5066
+ config,
5067
+ codebase,
5068
+ cwd,
5069
+ opts,
5070
+ benignBaseline
5071
+ );
4983
5072
  if (live === "aborted") return;
4984
5073
  if (opts.openPr) {
4985
5074
  const refined = await reverifyShippedSubset(
@@ -4994,23 +5083,35 @@ ${e.message}`);
4994
5083
  if (refined === "aborted") return;
4995
5084
  live = refined;
4996
5085
  }
4997
- recordClaims(plan, cwd, benignBaseline, live);
5086
+ await recordClaims(plan, cwd, benignBaseline, live, opts);
4998
5087
  let rescanLines = [];
4999
5088
  if (opts.rescan && beforeAttacks.length) {
5000
5089
  const { evaluator } = resolveEvaluator(opts);
5001
- console.log(`
5002
- Re-scanning the ${beforeAttacks.length} attack(s) of the original scan\u2026`);
5003
- const result = await rescanAndDiff({
5004
- before: beforeAttacks,
5005
- target: buildTargetConfig(config),
5006
- catalogue: opts.attacks ?? MVP_ATTACKS,
5007
- evaluator
5008
- });
5009
- if (result) {
5010
- rescanLines = describeRescan(result);
5011
- console.log(rescanLines.map((l) => ` ${l}`).join("\n"));
5090
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5091
+ if (!catalogue) {
5092
+ console.warn(
5093
+ `
5094
+ \u26A0\uFE0F Skipping --rescan: could not fetch the attack catalogue (${reason}).`
5095
+ );
5012
5096
  } else {
5013
- console.warn(" none of the original attacks are in the catalogue \u2014 no comparison possible");
5097
+ console.log(
5098
+ `
5099
+ Re-scanning the ${beforeAttacks.length} attack(s) of the original scan\u2026`
5100
+ );
5101
+ const result = await rescanAndDiff({
5102
+ before: beforeAttacks,
5103
+ target: buildTargetConfig(config),
5104
+ catalogue,
5105
+ evaluator
5106
+ });
5107
+ if (result) {
5108
+ rescanLines = describeRescan(result);
5109
+ console.log(rescanLines.map((l) => ` ${l}`).join("\n"));
5110
+ } else {
5111
+ console.warn(
5112
+ " none of the original attacks are in the catalogue \u2014 no comparison possible"
5113
+ );
5114
+ }
5014
5115
  }
5015
5116
  }
5016
5117
  if (opts.openPr) {
@@ -5030,9 +5131,11 @@ async function liveVerificationPhase(plan, config, codebase, cwd, opts, baseline
5030
5131
  setExitCode(2);
5031
5132
  return "aborted";
5032
5133
  }
5033
- console.log(`
5134
+ console.log(
5135
+ `
5034
5136
  Redeploy command (from shield.config.json):
5035
- ${codebase.redeploy.command}`);
5137
+ ${codebase.redeploy.command}`
5138
+ );
5036
5139
  if (!opts.yes && process.stdin.isTTY) {
5037
5140
  const proceed = await confirm({
5038
5141
  message: "Run this command?",
@@ -5047,9 +5150,11 @@ Redeploy command (from shield.config.json):
5047
5150
  const target = buildTargetConfig(config);
5048
5151
  const result = await redeploy(codebase.redeploy, target, cwd);
5049
5152
  if (!result.ok) {
5050
- console.error(`
5153
+ console.error(
5154
+ `
5051
5155
  Redeploy failed: ${result.detail}
5052
- The patch is applied but UNVERIFIED.`);
5156
+ The patch is applied but UNVERIFIED.`
5157
+ );
5053
5158
  setExitCode(3);
5054
5159
  return "aborted";
5055
5160
  }
@@ -5059,8 +5164,26 @@ The patch is applied but UNVERIFIED.`);
5059
5164
  \u26A0\uFE0F ${isolation.warning}
5060
5165
  `);
5061
5166
  const { evaluator, judgeAvailable } = resolveEvaluator(opts);
5062
- const catalogue = opts.attacks ?? MVP_ATTACKS;
5063
- console.log("\nReplaying each finding's design + holdout attacks against the live target\u2026\n");
5167
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5168
+ if (!catalogue) {
5169
+ console.error(
5170
+ `
5171
+ Cannot verify: the attack catalogue could not be fetched (${reason}).
5172
+ The patch is applied but UNVERIFIED \u2014 nothing was replayed against it.`
5173
+ );
5174
+ setExitCode(3);
5175
+ return "aborted";
5176
+ }
5177
+ if (!judgeAvailable && catalogue.some((a) => !a.detectPatterns?.length)) {
5178
+ console.error(
5179
+ "\nCannot verify: no judge is configured and the fetched attacks carry no detection patterns (they are recomputed server-side).\nThe patch is applied but UNVERIFIED \u2014 run `shield-llm login` and re-run with --verify."
5180
+ );
5181
+ setExitCode(3);
5182
+ return "aborted";
5183
+ }
5184
+ console.log(
5185
+ "\nReplaying each finding's design + holdout attacks against the live target\u2026\n"
5186
+ );
5064
5187
  for (const p of plan.planned) {
5065
5188
  const v = await verifyLive({
5066
5189
  contract: p.recipe.verification,
@@ -5082,8 +5205,12 @@ The patch is applied but UNVERIFIED.`);
5082
5205
  }
5083
5206
  async function reverifyShippedSubset(plan, config, codebase, cwd, opts, baseline, live) {
5084
5207
  if (opts.allowUnverified) return live;
5085
- const withheld = plan.planned.filter((p) => live.get(p.fingerprint)?.passed !== true);
5086
- const shipping = plan.planned.filter((p) => live.get(p.fingerprint)?.passed === true);
5208
+ const withheld = plan.planned.filter(
5209
+ (p) => live.get(p.fingerprint)?.passed !== true
5210
+ );
5211
+ const shipping = plan.planned.filter(
5212
+ (p) => live.get(p.fingerprint)?.passed === true
5213
+ );
5087
5214
  if (withheld.length === 0 || shipping.length === 0) return live;
5088
5215
  console.log(
5089
5216
  `
@@ -5107,7 +5234,9 @@ Re-verifying the ${shipping.length} passing patch(es) ALONE \u2014 ${withheld.le
5107
5234
  if (second === "aborted") return "aborted";
5108
5235
  const merged = new Map(live);
5109
5236
  for (const [fp, v] of second) merged.set(fp, v);
5110
- const lost = shipping.filter((p) => merged.get(p.fingerprint)?.passed !== true);
5237
+ const lost = shipping.filter(
5238
+ (p) => merged.get(p.fingerprint)?.passed !== true
5239
+ );
5111
5240
  if (lost.length) {
5112
5241
  console.warn(
5113
5242
  `
@@ -5116,22 +5245,54 @@ Re-verifying the ${shipping.length} passing patch(es) ALONE \u2014 ${withheld.le
5116
5245
  }
5117
5246
  return merged;
5118
5247
  }
5119
- function recordClaims(plan, cwd, baseline, live) {
5248
+ async function recordClaims(plan, cwd, baseline, live, opts) {
5120
5249
  const store = ClaimStore.at(cwd);
5121
5250
  const noClosurePath = !closurePathConfigured(cwd);
5251
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5252
+ const unfreezable = [];
5122
5253
  for (const p of plan.planned) {
5254
+ const contract = p.recipe.verification;
5255
+ let frozen;
5256
+ if (catalogue) {
5257
+ const missing = missingForContract(contract, catalogue);
5258
+ if (missing.length > 0) {
5259
+ unfreezable.push(
5260
+ `${p.attackId} (catalogue has no ${missing.join(", ")})`
5261
+ );
5262
+ } else {
5263
+ frozen = attacksForContract(contract, catalogue).map(
5264
+ (a) => serializeAttack(a)
5265
+ );
5266
+ }
5267
+ }
5123
5268
  store.upsert(plan.targetId, {
5124
5269
  ...createClaim({
5125
5270
  findingFingerprint: p.fingerprint,
5126
5271
  recipeId: p.recipe.id,
5127
- contract: p.recipe.verification,
5272
+ contract,
5128
5273
  nowMs: Date.now(),
5129
5274
  noClosurePathConfigured: noClosurePath
5130
5275
  }),
5276
+ attacks: frozen,
5131
5277
  benignBaseline: baseline,
5132
5278
  liveVerification: live.get(p.fingerprint)
5133
5279
  });
5134
5280
  }
5281
+ if (!catalogue) {
5282
+ console.warn(
5283
+ `
5284
+ \u26A0\uFE0F Claims recorded WITHOUT their attack payloads (${reason}).
5285
+ \`shield-llm verify-claims\` cannot close them \u2014 it replays what the claim
5286
+ carries. Log in and re-run \`shield-llm fix\` to make them verifiable.`
5287
+ );
5288
+ } else if (unfreezable.length > 0) {
5289
+ console.warn(
5290
+ `
5291
+ \u26A0\uFE0F ${unfreezable.length} claim(s) recorded without payloads \u2014 the catalogue
5292
+ no longer contains every attack their contract names:
5293
+ ` + unfreezable.join("\n ")
5294
+ );
5295
+ }
5135
5296
  if (noClosurePath) {
5136
5297
  console.warn(
5137
5298
  "\n\u26A0\uFE0F No closure path is wired for this target: neither `shield-llm verify-claims` in a deploy workflow nor a scheduled scan. These findings will stay open indefinitely \u2014 the PR would promise a verification nothing can deliver."
@@ -5139,8 +5300,12 @@ function recordClaims(plan, cwd, baseline, live) {
5139
5300
  }
5140
5301
  }
5141
5302
  function prPhase(plan, cwd, touchedByFinding, live, opts, rescanLines = []) {
5142
- const verified = plan.planned.filter((p) => live.get(p.fingerprint)?.passed === true);
5143
- const withheld = plan.planned.filter((p) => live.get(p.fingerprint)?.passed !== true);
5303
+ const verified = plan.planned.filter(
5304
+ (p) => live.get(p.fingerprint)?.passed === true
5305
+ );
5306
+ const withheld = plan.planned.filter(
5307
+ (p) => live.get(p.fingerprint)?.passed !== true
5308
+ );
5144
5309
  const shipping = opts.allowUnverified ? plan.planned : verified;
5145
5310
  const holding = opts.allowUnverified ? [] : withheld;
5146
5311
  for (const p of withheld) {
@@ -5161,7 +5326,9 @@ They stay on your working tree so you can inspect them. Fix the cause, or open t
5161
5326
  }
5162
5327
  const pathsOf = (list) => new Set(list.flatMap((p) => touchedByFinding.get(p.fingerprint) ?? []));
5163
5328
  const shippingPaths = pathsOf(shipping);
5164
- const overlap = Array.from(pathsOf(holding)).filter((f) => shippingPaths.has(f));
5329
+ const overlap = Array.from(pathsOf(holding)).filter(
5330
+ (f) => shippingPaths.has(f)
5331
+ );
5165
5332
  if (overlap.length) {
5166
5333
  console.error(
5167
5334
  `
@@ -5195,9 +5362,11 @@ No PR opened. A verified and an unverified patch both changed ${overlap.join(",
5195
5362
  draft: opts.draft
5196
5363
  });
5197
5364
  if (res.ok) {
5198
- console.log(res.url ? `
5365
+ console.log(
5366
+ res.url ? `
5199
5367
  Pull request opened: ${res.url}` : `
5200
- ${res.detail}`);
5368
+ ${res.detail}`
5369
+ );
5201
5370
  } else {
5202
5371
  console.error(`
5203
5372
  Could not open the PR: ${res.detail}`);
@@ -5221,6 +5390,37 @@ function layerReliability(layer) {
5221
5390
  }
5222
5391
 
5223
5392
  // src/commands/verify-claims.ts
5393
+ function judgeableLocally(catalogue) {
5394
+ return catalogue.every((a) => a.detectPatterns?.length);
5395
+ }
5396
+ function resolveEvaluator2(opts) {
5397
+ if (opts.evaluator) return { evaluator: opts.evaluator, backed: true };
5398
+ const creds = loadCredentials();
5399
+ if (creds?.apiKey && creds.apiUrl) {
5400
+ return {
5401
+ evaluator: new BackendEvaluator(
5402
+ resolveApiUrl(creds.apiUrl, opts.apiUrl),
5403
+ creds.apiKey
5404
+ ),
5405
+ backed: true
5406
+ };
5407
+ }
5408
+ return { evaluator: new RegexOnlyEvaluator(), backed: false };
5409
+ }
5410
+ function resolveClaimCatalogue(claim, opts, backed) {
5411
+ const catalogue = opts.attacks ?? claim.attacks?.map(deserializeAttack);
5412
+ if (!catalogue || catalogue.length === 0) {
5413
+ return {
5414
+ blocked: "the claim carries no attack payloads \u2014 re-run `shield-llm fix` while logged in to record them, then verify again"
5415
+ };
5416
+ }
5417
+ if (!judgeableLocally(catalogue) && !backed) {
5418
+ return {
5419
+ blocked: "no judge is configured and the frozen payloads carry no detection patterns (they are recomputed server-side) \u2014 run `shield-llm login` so the verification can be judged"
5420
+ };
5421
+ }
5422
+ return { catalogue };
5423
+ }
5224
5424
  var TERMINAL = /* @__PURE__ */ new Set(["confirmed", "confirmed_overfit", "expired"]);
5225
5425
  async function verifyClaimsCommand(opts) {
5226
5426
  const cwd = process.cwd();
@@ -5228,7 +5428,9 @@ async function verifyClaimsCommand(opts) {
5228
5428
  try {
5229
5429
  config = loadConfig({ configPath: opts.config });
5230
5430
  } catch (e) {
5231
- console.error(e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`);
5431
+ console.error(
5432
+ e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`
5433
+ );
5232
5434
  setExitCode(2);
5233
5435
  return [];
5234
5436
  }
@@ -5239,13 +5441,16 @@ async function verifyClaimsCommand(opts) {
5239
5441
  return [];
5240
5442
  }
5241
5443
  const target = buildTargetConfig(config);
5242
- const catalogue = opts.attacks ?? MVP_ATTACKS;
5243
- const evaluator = opts.evaluator ?? new RegexOnlyEvaluator();
5444
+ const { evaluator, backed } = resolveEvaluator2(opts);
5244
5445
  const now = opts.now ?? Date.now();
5245
5446
  const results = [];
5246
5447
  for (const claim of pending) {
5247
5448
  if (isExpired(claim, now)) {
5248
- const expired = { ...claim, status: "expired", resolvedAt: new Date(now).toISOString() };
5449
+ const expired = {
5450
+ ...claim,
5451
+ status: "expired",
5452
+ resolvedAt: new Date(now).toISOString()
5453
+ };
5249
5454
  store.replace(expired);
5250
5455
  results.push({
5251
5456
  fingerprint: claim.findingFingerprint,
@@ -5256,6 +5461,19 @@ async function verifyClaimsCommand(opts) {
5256
5461
  });
5257
5462
  continue;
5258
5463
  }
5464
+ const resolved = resolveClaimCatalogue(claim, opts, backed);
5465
+ if ("blocked" in resolved) {
5466
+ store.replace({ ...claim, status: "inconclusive" });
5467
+ results.push({
5468
+ fingerprint: claim.findingFingerprint,
5469
+ recipeId: claim.recipeId,
5470
+ status: "inconclusive",
5471
+ reason: resolved.blocked,
5472
+ stamped: false
5473
+ });
5474
+ continue;
5475
+ }
5476
+ const { catalogue } = resolved;
5259
5477
  const { verdicts, judgeDegraded } = await replayFamily(
5260
5478
  claim.contract,
5261
5479
  target,
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  generatePdf,
10
10
  loadConfig,
11
11
  loadSystemPrompt
12
- } from "./chunk-4QYDLRL6.js";
12
+ } from "./chunk-TWBU67PH.js";
13
13
  export {
14
14
  ConfigError,
15
15
  ConfigSchema,