shield-llm 0.6.6 → 0.6.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/dist/cli.js CHANGED
@@ -14,15 +14,14 @@ 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,
28
27
  checkSessionIsolation,
@@ -48,10 +47,10 @@ import {
48
47
  getObligationProfile,
49
48
  getStructuredRemediation,
50
49
  isExpired,
51
- isVariantId,
52
50
  loadConfig,
53
51
  loadSystemPrompt,
54
52
  mayStampFixed,
53
+ missingForContract,
55
54
  normalizeTargetUrl,
56
55
  parseSegmentKey,
57
56
  parseSnapshot,
@@ -59,10 +58,11 @@ import {
59
58
  resolveClaim,
60
59
  resolveOfflinePosition,
61
60
  retestDedupKey,
61
+ serializeAttack,
62
62
  sha256Hex,
63
63
  summarizeAttackErrors,
64
64
  version
65
- } from "./chunk-4QYDLRL6.js";
65
+ } from "./chunk-HQGV3UIF.js";
66
66
 
67
67
  // src/load-env.ts
68
68
  try {
@@ -2453,6 +2453,37 @@ async function reportScanFailure(credentials, scanId, reason) {
2453
2453
  } catch {
2454
2454
  }
2455
2455
  }
2456
+ async function reserveScanSlot(credentials, targetUrl) {
2457
+ try {
2458
+ const res = await fetch(`${credentials.apiUrl}/api/cli/scans`, {
2459
+ method: "POST",
2460
+ headers: {
2461
+ "Content-Type": "application/json",
2462
+ Authorization: `Bearer ${credentials.apiKey}`
2463
+ },
2464
+ body: JSON.stringify({ targetUrl })
2465
+ });
2466
+ if (res.status === 401) {
2467
+ console.error(
2468
+ "API key is invalid or revoked. Run `shield-llm login` to re-authenticate."
2469
+ );
2470
+ setExitCode(2);
2471
+ return null;
2472
+ }
2473
+ if (!res.ok) {
2474
+ console.error(`Failed to start scan: HTTP ${res.status}`);
2475
+ setExitCode(3);
2476
+ return null;
2477
+ }
2478
+ const scanSlot = await res.json();
2479
+ return scanSlot.scanId;
2480
+ } catch (err) {
2481
+ const msg = err instanceof Error ? err.message : "Unknown error";
2482
+ console.error(`Failed to connect to backend: ${msg}`);
2483
+ setExitCode(3);
2484
+ return null;
2485
+ }
2486
+ }
2456
2487
  function resolveMutateSelection(value) {
2457
2488
  if (value === void 0 || value === false) return null;
2458
2489
  if (value === true) return { mutators: [...MUTATORS], unknown: [] };
@@ -2541,35 +2572,6 @@ async function scanCommand(opts) {
2541
2572
  return;
2542
2573
  }
2543
2574
  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
2575
  const evaluator = new BackendEvaluator(
2574
2576
  credentials.apiUrl,
2575
2577
  credentials.apiKey
@@ -2717,6 +2719,9 @@ async function scanCommand(opts) {
2717
2719
  evaluator
2718
2720
  };
2719
2721
  const onEvent = opts.progress !== false ? handleEvent : void 0;
2722
+ reservedScanId = await reserveScanSlot(credentials, target.url);
2723
+ if (!reservedScanId) return;
2724
+ info("Scan started");
2720
2725
  const scanner = new Scanner(scanOptions, onEvent);
2721
2726
  const report = await scanner.run();
2722
2727
  const attempted = report.attacks.length;
@@ -2763,6 +2768,14 @@ async function scanCommand(opts) {
2763
2768
  console.warn(
2764
2769
  "Showing the locally-computed score \u2014 it may differ from the dashboard."
2765
2770
  );
2771
+ if (reservedScanId && !scanFinalized) {
2772
+ await reportScanFailure(
2773
+ credentials,
2774
+ reservedScanId,
2775
+ `Scan ran but its results could not be saved: ${msg}`
2776
+ );
2777
+ scanFinalized = true;
2778
+ }
2766
2779
  }
2767
2780
  const benchmarkEligible = presetForScan === "full" && !customOnly && (config.customTests?.length ?? 0) === 0 && attackPackVersion !== void 0;
2768
2781
  if (opts.consent || benchmarkEligible) {
@@ -4167,7 +4180,8 @@ async function judgeBenign(captures, cases, evaluator) {
4167
4180
  async function runBenignGate(input2) {
4168
4181
  const { baseline, contract, target } = input2;
4169
4182
  const scope = baseline?.scope ?? contract.benignScope;
4170
- if (scope === "none") return { green: true, detail: "no benign surface", ran: false };
4183
+ if (scope === "none")
4184
+ return { green: true, detail: "no benign surface", ran: false };
4171
4185
  const cannotRun = !baseline || scope === "model-behaviour" && !input2.evaluator;
4172
4186
  if (cannotRun && input2.assumeGreen) {
4173
4187
  console.warn(
@@ -4227,14 +4241,7 @@ async function runBenignGate(input2) {
4227
4241
  };
4228
4242
  }
4229
4243
  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
- ];
4244
+ const attacks = attacksForContract(contract, catalogue);
4238
4245
  const report = await new Scanner({
4239
4246
  target,
4240
4247
  // CLI-only: expand $VAR auth references from the environment, as every
@@ -4294,8 +4301,12 @@ function describeLiveVerification(v) {
4294
4301
  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
4302
  }
4296
4303
  const why = [];
4297
- const designOpen = v.designAttackIds.filter((a) => !v.designClearedIds.includes(a));
4298
- const holdoutOpen = v.holdoutAttackIds.filter((a) => !v.holdoutClearedIds.includes(a));
4304
+ const designOpen = v.designAttackIds.filter(
4305
+ (a) => !v.designClearedIds.includes(a)
4306
+ );
4307
+ const holdoutOpen = v.holdoutAttackIds.filter(
4308
+ (a) => !v.holdoutClearedIds.includes(a)
4309
+ );
4299
4310
  if (designOpen.length) why.push(`still vulnerable: ${designOpen.join(", ")}`);
4300
4311
  if (holdoutOpen.length) {
4301
4312
  why.push(
@@ -4311,7 +4322,8 @@ function describeLiveVerification(v) {
4311
4322
  );
4312
4323
  }
4313
4324
  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");
4325
+ if (v.judgeDegraded)
4326
+ why.push("the judge degraded mid-replay, so no verdict is trustworthy");
4315
4327
  return why.join(" \xB7 ");
4316
4328
  }
4317
4329
 
@@ -4708,7 +4720,8 @@ ${manualPrInstructions(branch, base)}`
4708
4720
 
4709
4721
  // src/commands/fix.ts
4710
4722
  function resolveEvaluator(opts) {
4711
- if (opts.evaluator) return { evaluator: opts.evaluator, judgeAvailable: true };
4723
+ if (opts.evaluator)
4724
+ return { evaluator: opts.evaluator, judgeAvailable: true };
4712
4725
  const creds = loadCredentials();
4713
4726
  if (creds?.apiKey && creds.apiUrl) {
4714
4727
  return {
@@ -4721,10 +4734,43 @@ function resolveEvaluator(opts) {
4721
4734
  );
4722
4735
  return { evaluator: new RegexOnlyEvaluator(), judgeAvailable: false };
4723
4736
  }
4737
+ var catalogueCache = /* @__PURE__ */ new WeakMap();
4738
+ async function resolveCatalogue(opts) {
4739
+ const cached = catalogueCache.get(opts);
4740
+ if (cached) return cached;
4741
+ const pending = (async () => {
4742
+ if (opts.attacks) return { attacks: opts.attacks };
4743
+ const stored = loadCredentials();
4744
+ if (!stored) {
4745
+ return {
4746
+ attacks: null,
4747
+ reason: "not logged in \u2014 run `shield-llm login --key <your-key>`"
4748
+ };
4749
+ }
4750
+ try {
4751
+ const fetched = await fetchAttacks({
4752
+ apiUrl: resolveApiUrl(stored.apiUrl, opts.apiUrl),
4753
+ apiKey: stored.apiKey,
4754
+ // Single-turn only, matching what the replay can run. Multi-turn
4755
+ // attacks are not addressed by a recipe and never appear in a contract.
4756
+ preset: "full"
4757
+ });
4758
+ return { attacks: fetched.attacks };
4759
+ } catch (err) {
4760
+ return {
4761
+ attacks: null,
4762
+ reason: err instanceof Error ? err.message : "unknown error"
4763
+ };
4764
+ }
4765
+ })();
4766
+ catalogueCache.set(opts, pending);
4767
+ return pending;
4768
+ }
4724
4769
  function findingsFromLocalReport(path) {
4725
4770
  const parsed = JSON.parse(readFileSync6(path, "utf8"));
4726
4771
  const r = parsed.report;
4727
- if (!r?.attacks) throw new Error(`${path} is not a shield-llm --write-json report`);
4772
+ if (!r?.attacks)
4773
+ throw new Error(`${path} is not a shield-llm --write-json report`);
4728
4774
  return {
4729
4775
  allAttacks: r.attacks.map((a) => ({
4730
4776
  id: a.id,
@@ -4748,14 +4794,20 @@ function findingsFromLocalReport(path) {
4748
4794
  var CODE_EXT = /\.(ts|tsx|js|jsx|mjs|cjs|py|rb|go|java|php)$/;
4749
4795
  function uncommittedCode(cwd) {
4750
4796
  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));
4797
+ return execFileSync3("git", ["status", "--porcelain"], {
4798
+ cwd,
4799
+ encoding: "utf8"
4800
+ }).split("\n").filter(Boolean).map((l) => l.slice(3).trim()).filter((p) => CODE_EXT.test(p));
4752
4801
  } catch {
4753
4802
  return [];
4754
4803
  }
4755
4804
  }
4756
4805
  function gitIsClean(cwd) {
4757
4806
  try {
4758
- return execFileSync3("git", ["status", "--porcelain"], { cwd, encoding: "utf8" }).trim().length === 0;
4807
+ return execFileSync3("git", ["status", "--porcelain"], {
4808
+ cwd,
4809
+ encoding: "utf8"
4810
+ }).trim().length === 0;
4759
4811
  } catch {
4760
4812
  return true;
4761
4813
  }
@@ -4773,7 +4825,9 @@ function printPlan(plan) {
4773
4825
  console.log();
4774
4826
  }
4775
4827
  if (plan.skipped.length) {
4776
- console.log(`Not patchable (${plan.skipped.length}) \u2014 these become issues, not PRs:`);
4828
+ console.log(
4829
+ `Not patchable (${plan.skipped.length}) \u2014 these become issues, not PRs:`
4830
+ );
4777
4831
  for (const s of plan.skipped) {
4778
4832
  console.log(` \xB7 ${s.attackId.padEnd(24)} ${s.reason}: ${s.detail}`);
4779
4833
  }
@@ -4795,12 +4849,15 @@ function printDiff(changes) {
4795
4849
  const before = c2.before.split("\n");
4796
4850
  const after = c2.after.split("\n");
4797
4851
  let head = 0;
4798
- while (head < before.length && head < after.length && before[head] === after[head]) head++;
4852
+ while (head < before.length && head < after.length && before[head] === after[head])
4853
+ head++;
4799
4854
  let tail = 0;
4800
4855
  while (tail < before.length - head && tail < after.length - head && before[before.length - 1 - tail] === after[after.length - 1 - tail])
4801
4856
  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}`);
4857
+ for (const line of before.slice(head, before.length - tail))
4858
+ console.log(`-${line}`);
4859
+ for (const line of after.slice(head, after.length - tail))
4860
+ console.log(`+${line}`);
4804
4861
  }
4805
4862
  }
4806
4863
  async function fixCommand(opts) {
@@ -4809,7 +4866,9 @@ async function fixCommand(opts) {
4809
4866
  try {
4810
4867
  config = loadConfig({ configPath: opts.config });
4811
4868
  } catch (e) {
4812
- console.error(e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`);
4869
+ console.error(
4870
+ e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`
4871
+ );
4813
4872
  setExitCode(2);
4814
4873
  return;
4815
4874
  }
@@ -4846,7 +4905,9 @@ async function fixCommand(opts) {
4846
4905
  try {
4847
4906
  plan = buildPlan(findings, targetUrl, codebase, cwd, {
4848
4907
  minConfidence: opts.minConfidence,
4849
- disagreementAvailable: findings.some((f) => f.disagreementResolution != null),
4908
+ disagreementAvailable: findings.some(
4909
+ (f) => f.disagreementResolution != null
4910
+ ),
4850
4911
  knownSecrets: config.endpoint?.knownSecrets
4851
4912
  });
4852
4913
  } catch (e) {
@@ -4945,7 +5006,10 @@ Commit or stash them first. (Non-code changes are fine and are named in the PR b
4945
5006
  anchors: plan.anchors,
4946
5007
  dryRun: opts.dryRun
4947
5008
  });
4948
- touchedByFinding.set(p.fingerprint, res.changes.map((c2) => c2.path));
5009
+ touchedByFinding.set(
5010
+ p.fingerprint,
5011
+ res.changes.map((c2) => c2.path)
5012
+ );
4949
5013
  if (res.noop) {
4950
5014
  console.log(`${p.recipe.id}: already applied (no-op)`);
4951
5015
  continue;
@@ -4979,7 +5043,14 @@ ${e.message}`);
4979
5043
  }
4980
5044
  plan.planned = plan.planned.filter((p) => !collided.has(p.fingerprint));
4981
5045
  if (opts.dryRun || plan.planned.length === 0) return;
4982
- let live = await liveVerificationPhase(plan, config, codebase, cwd, opts, benignBaseline);
5046
+ let live = await liveVerificationPhase(
5047
+ plan,
5048
+ config,
5049
+ codebase,
5050
+ cwd,
5051
+ opts,
5052
+ benignBaseline
5053
+ );
4983
5054
  if (live === "aborted") return;
4984
5055
  if (opts.openPr) {
4985
5056
  const refined = await reverifyShippedSubset(
@@ -4994,23 +5065,35 @@ ${e.message}`);
4994
5065
  if (refined === "aborted") return;
4995
5066
  live = refined;
4996
5067
  }
4997
- recordClaims(plan, cwd, benignBaseline, live);
5068
+ await recordClaims(plan, cwd, benignBaseline, live, opts);
4998
5069
  let rescanLines = [];
4999
5070
  if (opts.rescan && beforeAttacks.length) {
5000
5071
  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"));
5072
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5073
+ if (!catalogue) {
5074
+ console.warn(
5075
+ `
5076
+ \u26A0\uFE0F Skipping --rescan: could not fetch the attack catalogue (${reason}).`
5077
+ );
5012
5078
  } else {
5013
- console.warn(" none of the original attacks are in the catalogue \u2014 no comparison possible");
5079
+ console.log(
5080
+ `
5081
+ Re-scanning the ${beforeAttacks.length} attack(s) of the original scan\u2026`
5082
+ );
5083
+ const result = await rescanAndDiff({
5084
+ before: beforeAttacks,
5085
+ target: buildTargetConfig(config),
5086
+ catalogue,
5087
+ evaluator
5088
+ });
5089
+ if (result) {
5090
+ rescanLines = describeRescan(result);
5091
+ console.log(rescanLines.map((l) => ` ${l}`).join("\n"));
5092
+ } else {
5093
+ console.warn(
5094
+ " none of the original attacks are in the catalogue \u2014 no comparison possible"
5095
+ );
5096
+ }
5014
5097
  }
5015
5098
  }
5016
5099
  if (opts.openPr) {
@@ -5030,9 +5113,11 @@ async function liveVerificationPhase(plan, config, codebase, cwd, opts, baseline
5030
5113
  setExitCode(2);
5031
5114
  return "aborted";
5032
5115
  }
5033
- console.log(`
5116
+ console.log(
5117
+ `
5034
5118
  Redeploy command (from shield.config.json):
5035
- ${codebase.redeploy.command}`);
5119
+ ${codebase.redeploy.command}`
5120
+ );
5036
5121
  if (!opts.yes && process.stdin.isTTY) {
5037
5122
  const proceed = await confirm({
5038
5123
  message: "Run this command?",
@@ -5047,9 +5132,11 @@ Redeploy command (from shield.config.json):
5047
5132
  const target = buildTargetConfig(config);
5048
5133
  const result = await redeploy(codebase.redeploy, target, cwd);
5049
5134
  if (!result.ok) {
5050
- console.error(`
5135
+ console.error(
5136
+ `
5051
5137
  Redeploy failed: ${result.detail}
5052
- The patch is applied but UNVERIFIED.`);
5138
+ The patch is applied but UNVERIFIED.`
5139
+ );
5053
5140
  setExitCode(3);
5054
5141
  return "aborted";
5055
5142
  }
@@ -5059,8 +5146,26 @@ The patch is applied but UNVERIFIED.`);
5059
5146
  \u26A0\uFE0F ${isolation.warning}
5060
5147
  `);
5061
5148
  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");
5149
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5150
+ if (!catalogue) {
5151
+ console.error(
5152
+ `
5153
+ Cannot verify: the attack catalogue could not be fetched (${reason}).
5154
+ The patch is applied but UNVERIFIED \u2014 nothing was replayed against it.`
5155
+ );
5156
+ setExitCode(3);
5157
+ return "aborted";
5158
+ }
5159
+ if (!judgeAvailable && catalogue.some((a) => !a.detectPatterns?.length)) {
5160
+ console.error(
5161
+ "\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."
5162
+ );
5163
+ setExitCode(3);
5164
+ return "aborted";
5165
+ }
5166
+ console.log(
5167
+ "\nReplaying each finding's design + holdout attacks against the live target\u2026\n"
5168
+ );
5064
5169
  for (const p of plan.planned) {
5065
5170
  const v = await verifyLive({
5066
5171
  contract: p.recipe.verification,
@@ -5082,8 +5187,12 @@ The patch is applied but UNVERIFIED.`);
5082
5187
  }
5083
5188
  async function reverifyShippedSubset(plan, config, codebase, cwd, opts, baseline, live) {
5084
5189
  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);
5190
+ const withheld = plan.planned.filter(
5191
+ (p) => live.get(p.fingerprint)?.passed !== true
5192
+ );
5193
+ const shipping = plan.planned.filter(
5194
+ (p) => live.get(p.fingerprint)?.passed === true
5195
+ );
5087
5196
  if (withheld.length === 0 || shipping.length === 0) return live;
5088
5197
  console.log(
5089
5198
  `
@@ -5107,7 +5216,9 @@ Re-verifying the ${shipping.length} passing patch(es) ALONE \u2014 ${withheld.le
5107
5216
  if (second === "aborted") return "aborted";
5108
5217
  const merged = new Map(live);
5109
5218
  for (const [fp, v] of second) merged.set(fp, v);
5110
- const lost = shipping.filter((p) => merged.get(p.fingerprint)?.passed !== true);
5219
+ const lost = shipping.filter(
5220
+ (p) => merged.get(p.fingerprint)?.passed !== true
5221
+ );
5111
5222
  if (lost.length) {
5112
5223
  console.warn(
5113
5224
  `
@@ -5116,22 +5227,54 @@ Re-verifying the ${shipping.length} passing patch(es) ALONE \u2014 ${withheld.le
5116
5227
  }
5117
5228
  return merged;
5118
5229
  }
5119
- function recordClaims(plan, cwd, baseline, live) {
5230
+ async function recordClaims(plan, cwd, baseline, live, opts) {
5120
5231
  const store = ClaimStore.at(cwd);
5121
5232
  const noClosurePath = !closurePathConfigured(cwd);
5233
+ const { attacks: catalogue, reason } = await resolveCatalogue(opts);
5234
+ const unfreezable = [];
5122
5235
  for (const p of plan.planned) {
5236
+ const contract = p.recipe.verification;
5237
+ let frozen;
5238
+ if (catalogue) {
5239
+ const missing = missingForContract(contract, catalogue);
5240
+ if (missing.length > 0) {
5241
+ unfreezable.push(
5242
+ `${p.attackId} (catalogue has no ${missing.join(", ")})`
5243
+ );
5244
+ } else {
5245
+ frozen = attacksForContract(contract, catalogue).map(
5246
+ (a) => serializeAttack(a)
5247
+ );
5248
+ }
5249
+ }
5123
5250
  store.upsert(plan.targetId, {
5124
5251
  ...createClaim({
5125
5252
  findingFingerprint: p.fingerprint,
5126
5253
  recipeId: p.recipe.id,
5127
- contract: p.recipe.verification,
5254
+ contract,
5128
5255
  nowMs: Date.now(),
5129
5256
  noClosurePathConfigured: noClosurePath
5130
5257
  }),
5258
+ attacks: frozen,
5131
5259
  benignBaseline: baseline,
5132
5260
  liveVerification: live.get(p.fingerprint)
5133
5261
  });
5134
5262
  }
5263
+ if (!catalogue) {
5264
+ console.warn(
5265
+ `
5266
+ \u26A0\uFE0F Claims recorded WITHOUT their attack payloads (${reason}).
5267
+ \`shield-llm verify-claims\` cannot close them \u2014 it replays what the claim
5268
+ carries. Log in and re-run \`shield-llm fix\` to make them verifiable.`
5269
+ );
5270
+ } else if (unfreezable.length > 0) {
5271
+ console.warn(
5272
+ `
5273
+ \u26A0\uFE0F ${unfreezable.length} claim(s) recorded without payloads \u2014 the catalogue
5274
+ no longer contains every attack their contract names:
5275
+ ` + unfreezable.join("\n ")
5276
+ );
5277
+ }
5135
5278
  if (noClosurePath) {
5136
5279
  console.warn(
5137
5280
  "\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 +5282,12 @@ function recordClaims(plan, cwd, baseline, live) {
5139
5282
  }
5140
5283
  }
5141
5284
  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);
5285
+ const verified = plan.planned.filter(
5286
+ (p) => live.get(p.fingerprint)?.passed === true
5287
+ );
5288
+ const withheld = plan.planned.filter(
5289
+ (p) => live.get(p.fingerprint)?.passed !== true
5290
+ );
5144
5291
  const shipping = opts.allowUnverified ? plan.planned : verified;
5145
5292
  const holding = opts.allowUnverified ? [] : withheld;
5146
5293
  for (const p of withheld) {
@@ -5161,7 +5308,9 @@ They stay on your working tree so you can inspect them. Fix the cause, or open t
5161
5308
  }
5162
5309
  const pathsOf = (list) => new Set(list.flatMap((p) => touchedByFinding.get(p.fingerprint) ?? []));
5163
5310
  const shippingPaths = pathsOf(shipping);
5164
- const overlap = Array.from(pathsOf(holding)).filter((f) => shippingPaths.has(f));
5311
+ const overlap = Array.from(pathsOf(holding)).filter(
5312
+ (f) => shippingPaths.has(f)
5313
+ );
5165
5314
  if (overlap.length) {
5166
5315
  console.error(
5167
5316
  `
@@ -5195,9 +5344,11 @@ No PR opened. A verified and an unverified patch both changed ${overlap.join(",
5195
5344
  draft: opts.draft
5196
5345
  });
5197
5346
  if (res.ok) {
5198
- console.log(res.url ? `
5347
+ console.log(
5348
+ res.url ? `
5199
5349
  Pull request opened: ${res.url}` : `
5200
- ${res.detail}`);
5350
+ ${res.detail}`
5351
+ );
5201
5352
  } else {
5202
5353
  console.error(`
5203
5354
  Could not open the PR: ${res.detail}`);
@@ -5221,6 +5372,37 @@ function layerReliability(layer) {
5221
5372
  }
5222
5373
 
5223
5374
  // src/commands/verify-claims.ts
5375
+ function judgeableLocally(catalogue) {
5376
+ return catalogue.every((a) => a.detectPatterns?.length);
5377
+ }
5378
+ function resolveEvaluator2(opts) {
5379
+ if (opts.evaluator) return { evaluator: opts.evaluator, backed: true };
5380
+ const creds = loadCredentials();
5381
+ if (creds?.apiKey && creds.apiUrl) {
5382
+ return {
5383
+ evaluator: new BackendEvaluator(
5384
+ resolveApiUrl(creds.apiUrl, opts.apiUrl),
5385
+ creds.apiKey
5386
+ ),
5387
+ backed: true
5388
+ };
5389
+ }
5390
+ return { evaluator: new RegexOnlyEvaluator(), backed: false };
5391
+ }
5392
+ function resolveClaimCatalogue(claim, opts, backed) {
5393
+ const catalogue = opts.attacks ?? claim.attacks?.map(deserializeAttack);
5394
+ if (!catalogue || catalogue.length === 0) {
5395
+ return {
5396
+ blocked: "the claim carries no attack payloads \u2014 re-run `shield-llm fix` while logged in to record them, then verify again"
5397
+ };
5398
+ }
5399
+ if (!judgeableLocally(catalogue) && !backed) {
5400
+ return {
5401
+ 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"
5402
+ };
5403
+ }
5404
+ return { catalogue };
5405
+ }
5224
5406
  var TERMINAL = /* @__PURE__ */ new Set(["confirmed", "confirmed_overfit", "expired"]);
5225
5407
  async function verifyClaimsCommand(opts) {
5226
5408
  const cwd = process.cwd();
@@ -5228,7 +5410,9 @@ async function verifyClaimsCommand(opts) {
5228
5410
  try {
5229
5411
  config = loadConfig({ configPath: opts.config });
5230
5412
  } catch (e) {
5231
- console.error(e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`);
5413
+ console.error(
5414
+ e instanceof ConfigError ? e.message : `Failed to load config: ${String(e)}`
5415
+ );
5232
5416
  setExitCode(2);
5233
5417
  return [];
5234
5418
  }
@@ -5239,13 +5423,16 @@ async function verifyClaimsCommand(opts) {
5239
5423
  return [];
5240
5424
  }
5241
5425
  const target = buildTargetConfig(config);
5242
- const catalogue = opts.attacks ?? MVP_ATTACKS;
5243
- const evaluator = opts.evaluator ?? new RegexOnlyEvaluator();
5426
+ const { evaluator, backed } = resolveEvaluator2(opts);
5244
5427
  const now = opts.now ?? Date.now();
5245
5428
  const results = [];
5246
5429
  for (const claim of pending) {
5247
5430
  if (isExpired(claim, now)) {
5248
- const expired = { ...claim, status: "expired", resolvedAt: new Date(now).toISOString() };
5431
+ const expired = {
5432
+ ...claim,
5433
+ status: "expired",
5434
+ resolvedAt: new Date(now).toISOString()
5435
+ };
5249
5436
  store.replace(expired);
5250
5437
  results.push({
5251
5438
  fingerprint: claim.findingFingerprint,
@@ -5256,6 +5443,19 @@ async function verifyClaimsCommand(opts) {
5256
5443
  });
5257
5444
  continue;
5258
5445
  }
5446
+ const resolved = resolveClaimCatalogue(claim, opts, backed);
5447
+ if ("blocked" in resolved) {
5448
+ store.replace({ ...claim, status: "inconclusive" });
5449
+ results.push({
5450
+ fingerprint: claim.findingFingerprint,
5451
+ recipeId: claim.recipeId,
5452
+ status: "inconclusive",
5453
+ reason: resolved.blocked,
5454
+ stamped: false
5455
+ });
5456
+ continue;
5457
+ }
5458
+ const { catalogue } = resolved;
5259
5459
  const { verdicts, judgeDegraded } = await replayFamily(
5260
5460
  claim.contract,
5261
5461
  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-HQGV3UIF.js";
13
13
  export {
14
14
  ConfigError,
15
15
  ConfigSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shield-llm",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "scripts": {
44
44
  "lint": "eslint src --ext .ts",
45
- "build": "tsc --noEmit && tsup && cp src/reporters/assets/logo.png dist/",
45
+ "build": "tsc --noEmit && tsup && node scripts/check-bundle-ip.mjs && cp src/reporters/assets/logo.png dist/",
46
46
  "dev": "tsx src/cli.ts",
47
47
  "test": "vitest run",
48
48
  "mock-server": "tsx test-server/server.ts",