shield-llm 0.5.0 → 0.5.2

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.
@@ -5106,8 +5106,8 @@ function isIpPrivate(ip) {
5106
5106
  const mapped = addr.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
5107
5107
  if (mapped) addr = mapped[1];
5108
5108
  if (isIP(addr) === 4) {
5109
- const [a, b, c, d] = addr.split(".").map(Number);
5110
- if ([a, b, c, d].some((p) => Number.isNaN(p) || p < 0 || p > 255)) {
5109
+ const [a, b, c2, d] = addr.split(".").map(Number);
5110
+ if ([a, b, c2, d].some((p) => Number.isNaN(p) || p < 0 || p > 255)) {
5111
5111
  return true;
5112
5112
  }
5113
5113
  if (a === 0) return true;
@@ -5117,7 +5117,7 @@ function isIpPrivate(ip) {
5117
5117
  if (a === 172 && b >= 16 && b <= 31) return true;
5118
5118
  if (a === 192 && b === 168) return true;
5119
5119
  if (a === 100 && b >= 64 && b <= 127) return true;
5120
- if (a === 255 && b === 255 && c === 255 && d === 255) return true;
5120
+ if (a === 255 && b === 255 && c2 === 255 && d === 255) return true;
5121
5121
  return false;
5122
5122
  }
5123
5123
  const lower = addr.toLowerCase();
@@ -6669,39 +6669,50 @@ function evaluateThresholds(report, thresholds) {
6669
6669
  };
6670
6670
  }
6671
6671
 
6672
+ // src/display/colors.ts
6673
+ import { styleText } from "util";
6674
+ var make = (fmt) => (text) => styleText(fmt, text);
6675
+ var c = {
6676
+ cyan: make("cyan"),
6677
+ red: make("red"),
6678
+ green: make("green"),
6679
+ yellow: make("yellow"),
6680
+ blue: make("blue"),
6681
+ gray: make("gray"),
6682
+ white: make("white"),
6683
+ bold: make("bold"),
6684
+ dim: make("dim"),
6685
+ redBold: make(["red", "bold"]),
6686
+ greenBold: make(["green", "bold"]),
6687
+ bgYellowBlackBold: make(["bgYellow", "black", "bold"])
6688
+ };
6689
+
6672
6690
  // src/reporters/compliance.ts
6673
- import chalk from "chalk";
6674
6691
  function formatComplianceTerminal(result, target) {
6675
6692
  const lines = [];
6676
6693
  lines.push("");
6677
- lines.push(chalk.bold("\u2550\u2550\u2550 EU AI Act Compliance \u2550\u2550\u2550"));
6694
+ lines.push(c.bold("\u2550\u2550\u2550 EU AI Act Compliance \u2550\u2550\u2550"));
6678
6695
  lines.push("");
6679
- lines.push(` Target: ${chalk.white(target)}`);
6696
+ lines.push(` Target: ${c.white(target)}`);
6680
6697
  lines.push(` Score: ${complianceScoreColor(result.overallScore)}`);
6681
6698
  lines.push(
6682
6699
  ` Status: ${statusColor(result.status, getComplianceLabel(result.status))}`
6683
6700
  );
6684
6701
  lines.push(` Framework: ${result.framework} (${result.frameworkVersion})`);
6685
6702
  lines.push("");
6686
- lines.push(chalk.bold(" Article Coverage:"));
6703
+ lines.push(c.bold(" Article Coverage:"));
6687
6704
  const sorted = [...result.aspects].filter((a) => a.totalTests > 0).sort((a, b) => a.score - b.score);
6688
6705
  for (const aspect of sorted) {
6689
6706
  const label = ASPECT_ARTICLE_LABELS[aspect.aspect];
6690
6707
  const bar = makeBar(aspect.score, 20);
6691
6708
  const scoreStr = complianceScoreColor(aspect.score);
6692
- const stats = chalk.dim(
6693
- `${aspect.passedTests}/${aspect.totalTests} passed`
6694
- );
6695
- lines.push(
6696
- ` ${label.padEnd(16)} ${bar} ${scoreStr} ${stats}`
6697
- );
6709
+ const stats = c.dim(`${aspect.passedTests}/${aspect.totalTests} passed`);
6710
+ lines.push(` ${label.padEnd(16)} ${bar} ${scoreStr} ${stats}`);
6698
6711
  }
6699
6712
  if (result.nonCompliances.length > 0) {
6700
6713
  lines.push("");
6701
6714
  lines.push(
6702
- chalk.red.bold(
6703
- ` Non-Compliances (${result.nonCompliances.length}):`
6704
- )
6715
+ c.redBold(` Non-Compliances (${result.nonCompliances.length}):`)
6705
6716
  );
6706
6717
  const seen = /* @__PURE__ */ new Set();
6707
6718
  for (const nc of result.nonCompliances) {
@@ -6709,7 +6720,7 @@ function formatComplianceTerminal(result, target) {
6709
6720
  if (seen.has(key)) continue;
6710
6721
  seen.add(key);
6711
6722
  lines.push(
6712
- ` ${chalk.red("\u2717")} ${nc.testName} \u2014 ${nc.article.articleNumber} (${nc.article.complianceAspect})`
6723
+ ` ${c.red("\u2717")} ${nc.testName} \u2014 ${nc.article.articleNumber} (${nc.article.complianceAspect})`
6713
6724
  );
6714
6725
  }
6715
6726
  }
@@ -6719,19 +6730,17 @@ function formatComplianceTerminal(result, target) {
6719
6730
  if (compliantAspects.length > 0) {
6720
6731
  lines.push("");
6721
6732
  lines.push(
6722
- chalk.green.bold(
6723
- ` Compliant (${compliantAspects.length}/7 aspects):`
6724
- )
6733
+ c.greenBold(` Compliant (${compliantAspects.length}/7 aspects):`)
6725
6734
  );
6726
6735
  for (const a of compliantAspects) {
6727
6736
  lines.push(
6728
- ` ${chalk.green("\u2713")} ${ASPECT_ARTICLE_LABELS[a.aspect]} \u2014 ${a.aspect} (${a.score}%)`
6737
+ ` ${c.green("\u2713")} ${ASPECT_ARTICLE_LABELS[a.aspect]} \u2014 ${a.aspect} (${a.score}%)`
6729
6738
  );
6730
6739
  }
6731
6740
  }
6732
6741
  lines.push("");
6733
- lines.push(chalk.dim(" Disclaimer: This is an automated assessment, not a"));
6734
- lines.push(chalk.dim(" legal compliance certification."));
6742
+ lines.push(c.dim(" Disclaimer: This is an automated assessment, not a"));
6743
+ lines.push(c.dim(" legal compliance certification."));
6735
6744
  lines.push("");
6736
6745
  return lines.join("\n");
6737
6746
  }
@@ -6769,27 +6778,27 @@ function makeBar(score, width) {
6769
6778
  const filledChar = "\u2588";
6770
6779
  const emptyChar = "\u2591";
6771
6780
  const bar = filledChar.repeat(filled) + emptyChar.repeat(empty);
6772
- if (score >= 90) return chalk.green(bar);
6773
- if (score >= 70) return chalk.yellow(bar);
6774
- if (score >= 40) return chalk.red(bar);
6775
- return chalk.red.bold(bar);
6781
+ if (score >= 90) return c.green(bar);
6782
+ if (score >= 70) return c.yellow(bar);
6783
+ if (score >= 40) return c.red(bar);
6784
+ return c.redBold(bar);
6776
6785
  }
6777
6786
  function complianceScoreColor(score) {
6778
- if (score >= 90) return chalk.green.bold(`${score}%`);
6779
- if (score >= 70) return chalk.yellow(`${score}%`);
6780
- if (score >= 40) return chalk.red(`${score}%`);
6781
- return chalk.red.bold(`${score}%`);
6787
+ if (score >= 90) return c.greenBold(`${score}%`);
6788
+ if (score >= 70) return c.yellow(`${score}%`);
6789
+ if (score >= 40) return c.red(`${score}%`);
6790
+ return c.redBold(`${score}%`);
6782
6791
  }
6783
6792
  function statusColor(status, label) {
6784
6793
  switch (status) {
6785
6794
  case "COMPLIANT":
6786
- return chalk.green.bold(label);
6795
+ return c.greenBold(label);
6787
6796
  case "PARTIALLY_COMPLIANT":
6788
- return chalk.yellow(label);
6797
+ return c.yellow(label);
6789
6798
  case "NON_COMPLIANT":
6790
- return chalk.red(label);
6799
+ return c.red(label);
6791
6800
  case "CRITICAL":
6792
- return chalk.red.bold(label);
6801
+ return c.redBold(label);
6793
6802
  default:
6794
6803
  return label;
6795
6804
  }
@@ -8810,22 +8819,22 @@ ${d.passedTests.map(passedTestRow).join("")} </tbody>
8810
8819
  ${pageFooter(d.generatedAt)}</div>
8811
8820
  `;
8812
8821
  }
8813
- var coverageRow = (c) => ` <tr>
8822
+ var coverageRow = (c2) => ` <tr>
8814
8823
  <td>
8815
8824
  <div class="owasp-category-cell">
8816
- <span class="owasp-category-id">${esc(c.id)}</span>
8817
- <span class="owasp-category-name">${esc(c.name)}</span>
8825
+ <span class="owasp-category-id">${esc(c2.id)}</span>
8826
+ <span class="owasp-category-name">${esc(c2.name)}</span>
8818
8827
  </div>
8819
8828
  </td>
8820
- <td>${esc(c.tests)}</td>
8821
- <td>${esc(c.passed)}</td>
8822
- <td${c.failed > 0 ? ' style="color: var(--critical-text); font-weight: 600;"' : ""}>${esc(c.failed)}</td>
8829
+ <td>${esc(c2.tests)}</td>
8830
+ <td>${esc(c2.passed)}</td>
8831
+ <td${c2.failed > 0 ? ' style="color: var(--critical-text); font-weight: 600;"' : ""}>${esc(c2.failed)}</td>
8823
8832
  <td>
8824
8833
  <div class="score-mini-bar">
8825
8834
  <div class="score-mini-bar-track">
8826
- <div class="score-mini-bar-fill ${c.percentage === 100 ? "full" : c.percentage > 0 ? "partial" : "none"}" style="width: ${esc(c.percentage)}%"></div>
8835
+ <div class="score-mini-bar-fill ${c2.percentage === 100 ? "full" : c2.percentage > 0 ? "partial" : "none"}" style="width: ${esc(c2.percentage)}%"></div>
8827
8836
  </div>
8828
- <span class="score-mini-text" style="color: ${c.percentage === 100 ? "var(--pass-text)" : "var(--high-text)"};">${esc(c.percentage)}%</span>
8837
+ <span class="score-mini-text" style="color: ${c2.percentage === 100 ? "var(--pass-text)" : "var(--high-text)"};">${esc(c2.percentage)}%</span>
8829
8838
  </div>
8830
8839
  </td>
8831
8840
  </tr>
@@ -9125,6 +9134,7 @@ export {
9125
9134
  buildAuthFromFlags,
9126
9135
  loadSystemPrompt,
9127
9136
  ConfigError,
9137
+ c,
9128
9138
  analyzeJudgeHealth,
9129
9139
  evaluateThresholds,
9130
9140
  formatComplianceTerminal,
package/dist/cli.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  analyzeJudgeHealth,
9
9
  buildAuthFromFlags,
10
10
  buildTargetConfig,
11
+ c,
11
12
  calculateComplianceScore,
12
13
  computeCatalogHash,
13
14
  computeScanKey,
@@ -26,15 +27,20 @@ import {
26
27
  parseSnapshot,
27
28
  resolveOfflinePosition,
28
29
  summarizeAttackErrors
29
- } from "./chunk-IB7T5OJ2.js";
30
+ } from "./chunk-CWJWN44I.js";
30
31
  import "./chunk-I7M3BZK7.js";
31
32
 
33
+ // src/load-env.ts
34
+ try {
35
+ process.loadEnvFile();
36
+ } catch {
37
+ }
38
+
32
39
  // src/cli.ts
33
- import "dotenv/config";
34
40
  import { Command, CommanderError } from "commander";
35
41
 
36
42
  // package.json
37
- var version = "0.5.0";
43
+ var version = "0.5.2";
38
44
 
39
45
  // src/credentials.ts
40
46
  import {
@@ -230,7 +236,77 @@ Attack catalogue \u2014 ${total} attack(s)${wanted ? ` (severity: ${wanted})` :
230
236
 
231
237
  // src/commands/benchmark.ts
232
238
  import { writeFileSync as writeFileSync2 } from "fs";
233
- import { confirm, select } from "@inquirer/prompts";
239
+
240
+ // src/lib/prompts.ts
241
+ import * as readline from "readline/promises";
242
+ import { stdin, stdout } from "process";
243
+ async function withReadline(fn) {
244
+ const rl = readline.createInterface({ input: stdin, output: stdout });
245
+ rl.on("SIGINT", () => {
246
+ rl.close();
247
+ process.exit(130);
248
+ });
249
+ try {
250
+ return await fn(rl);
251
+ } finally {
252
+ rl.close();
253
+ }
254
+ }
255
+ async function input(opts) {
256
+ return withReadline(async (rl) => {
257
+ const suffix = opts.default !== void 0 ? ` (${opts.default})` : "";
258
+ for (; ; ) {
259
+ const answer = (await rl.question(`${opts.message}${suffix} `)).trim();
260
+ const value = answer === "" && opts.default !== void 0 ? opts.default : answer;
261
+ if (opts.validate) {
262
+ const result = await opts.validate(value);
263
+ if (result !== true) {
264
+ process.stderr.write(
265
+ `${typeof result === "string" ? result : "Invalid input"}
266
+ `
267
+ );
268
+ continue;
269
+ }
270
+ }
271
+ return value;
272
+ }
273
+ });
274
+ }
275
+ async function confirm(opts) {
276
+ const def = opts.default ?? false;
277
+ const hint = def ? "(Y/n)" : "(y/N)";
278
+ return withReadline(async (rl) => {
279
+ for (; ; ) {
280
+ const answer = (await rl.question(`${opts.message} ${hint} `)).trim().toLowerCase();
281
+ if (answer === "") return def;
282
+ if (answer === "y" || answer === "yes") return true;
283
+ if (answer === "n" || answer === "no") return false;
284
+ }
285
+ });
286
+ }
287
+ async function select(opts) {
288
+ const { choices } = opts;
289
+ const defaultIndex = opts.default !== void 0 ? choices.findIndex((ch) => ch.value === opts.default) : -1;
290
+ return withReadline(async (rl) => {
291
+ stdout.write(`${opts.message}
292
+ `);
293
+ choices.forEach((ch, i) => {
294
+ const marker = i === defaultIndex ? " (default)" : "";
295
+ stdout.write(` ${i + 1}) ${ch.name}${marker}
296
+ `);
297
+ });
298
+ const prompt = `Enter a number (1-${choices.length})${defaultIndex >= 0 ? ` [${defaultIndex + 1}]` : ""}: `;
299
+ for (; ; ) {
300
+ const answer = (await rl.question(prompt)).trim();
301
+ if (answer === "" && defaultIndex >= 0)
302
+ return choices[defaultIndex].value;
303
+ const n = Number(answer);
304
+ if (Number.isInteger(n) && n >= 1 && n <= choices.length) {
305
+ return choices[n - 1].value;
306
+ }
307
+ }
308
+ });
309
+ }
234
310
 
235
311
  // src/benchmark/api.ts
236
312
  var BenchmarkApiError = class extends Error {
@@ -249,6 +325,13 @@ async function request(creds, method, path, body) {
249
325
  method,
250
326
  headers: {
251
327
  Authorization: `Bearer ${creds.apiKey}`,
328
+ // The /api/benchmark/* routes are dual-auth (browser session OR API
329
+ // key), so — unlike the API-key-only /api/cli/* routes — they are NOT
330
+ // exempt from the middleware's CSRF same-origin check. A non-browser
331
+ // client sends no Origin and is rejected with 403 "Invalid origin".
332
+ // Send Origin = the configured backend so the same-origin check passes.
333
+ // API-key auth carries no ambient-cookie CSRF risk, so this is safe.
334
+ Origin: new URL(creds.apiUrl).origin,
252
335
  ...body !== void 0 && { "Content-Type": "application/json" }
253
336
  },
254
337
  ...body !== void 0 && { body: JSON.stringify(body) }
@@ -481,9 +564,9 @@ async function cohortsCommand(opts) {
481
564
  );
482
565
  return;
483
566
  }
484
- for (const c of cohorts) {
567
+ for (const c2 of cohorts) {
485
568
  console.log(
486
- `${c.id} ${c.displayName} pack v${c.activePackVersion} k_min=${c.kMin} targets=${c.targetCount} submissions=${c.submissionCount}`
569
+ `${c2.id} ${c2.displayName} pack v${c2.activePackVersion} k_min=${c2.kMin} targets=${c2.targetCount} submissions=${c2.submissionCount}`
487
570
  );
488
571
  }
489
572
  } catch (err) {
@@ -663,9 +746,9 @@ async function interactiveSubmitFlow(creds, scanId, log) {
663
746
  }
664
747
  const cohortId = cohorts.length === 1 ? cohorts[0].id : await select({
665
748
  message: "Cohort to contribute to:",
666
- choices: cohorts.map((c) => ({
667
- name: `${c.displayName} (pack v${c.activePackVersion})`,
668
- value: c.id
749
+ choices: cohorts.map((c2) => ({
750
+ name: `${c2.displayName} (pack v${c2.activePackVersion})`,
751
+ value: c2.id
669
752
  }))
670
753
  });
671
754
  const detail = await getCohort(creds, cohortId);
@@ -693,7 +776,6 @@ async function interactiveSubmitFlow(creds, scanId, log) {
693
776
  // src/commands/init.ts
694
777
  import { existsSync as existsSync2, writeFileSync as writeFileSync3 } from "fs";
695
778
  import { resolve } from "path";
696
- import { select as select2, input, confirm as confirm2 } from "@inquirer/prompts";
697
779
  var CONFIG_FILENAME = "shield.config.json";
698
780
  async function initCommand() {
699
781
  console.log("\nShield LLM \u2014 Configuration wizard\n");
@@ -706,7 +788,7 @@ async function initCommand() {
706
788
  }
707
789
  const configPath = resolve(CONFIG_FILENAME);
708
790
  if (existsSync2(configPath)) {
709
- const overwrite = await confirm2({
791
+ const overwrite = await confirm({
710
792
  message: `${CONFIG_FILENAME} already exists. Overwrite?`,
711
793
  default: false
712
794
  });
@@ -726,7 +808,7 @@ async function initCommand() {
726
808
  }
727
809
  }
728
810
  });
729
- const method = await select2({
811
+ const method = await select({
730
812
  message: "HTTP method:",
731
813
  choices: [
732
814
  { value: "POST", name: "POST (most chatbots)" },
@@ -738,7 +820,7 @@ async function initCommand() {
738
820
  const auth = await collectAuth();
739
821
  const { body, responseField } = await collectBodyShape();
740
822
  const customHeaders = await collectCustomHeaders();
741
- const preset = await select2({
823
+ const preset = await select({
742
824
  message: "Default scan preset:",
743
825
  choices: [
744
826
  { value: "owasp", name: "owasp \u2014 OWASP LLM Top 10 (10 tests)" },
@@ -791,7 +873,7 @@ ${issues}`);
791
873
  console.log("");
792
874
  }
793
875
  async function collectAuth() {
794
- const authType = await select2({
876
+ const authType = await select({
795
877
  message: "How does your endpoint authenticate?",
796
878
  choices: [
797
879
  { value: "none", name: "No authentication" },
@@ -842,7 +924,7 @@ async function collectAuth() {
842
924
  return { type: "oauth2", clientId, clientSecret, tokenUrl };
843
925
  }
844
926
  async function collectBodyShape() {
845
- const shape = await select2({
927
+ const shape = await select({
846
928
  message: "Request body shape:",
847
929
  choices: [
848
930
  {
@@ -868,7 +950,7 @@ async function collectBodyShape() {
868
950
  default: "message"
869
951
  });
870
952
  const body = { [promptField]: "{{prompt}}" };
871
- const addExtra = await confirm2({
953
+ const addExtra = await confirm({
872
954
  message: "Add extra fixed fields to the request body (assistant_id, thread_id, ...) ?",
873
955
  default: false
874
956
  });
@@ -883,7 +965,7 @@ async function collectBodyShape() {
883
965
  message: `Value for "${key}":`
884
966
  });
885
967
  body[key] = value;
886
- more = await confirm2({ message: "Another field?", default: false });
968
+ more = await confirm({ message: "Another field?", default: false });
887
969
  }
888
970
  }
889
971
  const responseField = await input({
@@ -893,7 +975,7 @@ async function collectBodyShape() {
893
975
  return { body, responseField };
894
976
  }
895
977
  async function collectCustomHeaders() {
896
- const add = await confirm2({
978
+ const add = await confirm({
897
979
  message: "Add custom request headers?",
898
980
  default: false
899
981
  });
@@ -910,7 +992,7 @@ async function collectCustomHeaders() {
910
992
  });
911
993
  warnIfHardcodedSecret(value);
912
994
  headers[name] = value;
913
- more = await confirm2({ message: "Another header?", default: false });
995
+ more = await confirm({ message: "Another header?", default: false });
914
996
  }
915
997
  return headers;
916
998
  }
@@ -1227,21 +1309,119 @@ var BackendEvaluator = class {
1227
1309
  }
1228
1310
  };
1229
1311
 
1312
+ // src/display/spinner.ts
1313
+ var FRAMES_UNICODE = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1314
+ var FRAMES_ASCII = ["-", "\\", "|", "/"];
1315
+ function unicodeSupported() {
1316
+ if (process.platform !== "win32") {
1317
+ return /UTF-?8/i.test(
1318
+ process.env.LC_ALL || process.env.LC_CTYPE || process.env.LANG || ""
1319
+ );
1320
+ }
1321
+ return Boolean(
1322
+ process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode"
1323
+ );
1324
+ }
1325
+ var AnsiSpinner = class {
1326
+ constructor() {
1327
+ this._text = "";
1328
+ this.timer = null;
1329
+ this.frame = 0;
1330
+ this.cursorHidden = false;
1331
+ this.isTTY = process.stderr.isTTY === true;
1332
+ this.frames = unicodeSupported() ? FRAMES_UNICODE : FRAMES_ASCII;
1333
+ this.sym = unicodeSupported() ? { ok: "\u2714", fail: "\u2716", warn: "\u26A0", info: "\u2139" } : { ok: "\u221A", fail: "\xD7", warn: "\u203C", info: "i" };
1334
+ }
1335
+ get text() {
1336
+ return this._text;
1337
+ }
1338
+ set text(value) {
1339
+ this._text = value;
1340
+ if (this.isTTY && this.timer) this.render();
1341
+ }
1342
+ render() {
1343
+ process.stderr.write(
1344
+ `\r\x1B[K${c.cyan(this.frames[this.frame])} ${this._text}`
1345
+ );
1346
+ }
1347
+ start(text) {
1348
+ if (text !== void 0) this._text = text;
1349
+ if (!this.isTTY) {
1350
+ if (text) process.stderr.write(`${text}
1351
+ `);
1352
+ return this;
1353
+ }
1354
+ if (!this.cursorHidden) {
1355
+ process.stderr.write("\x1B[?25l");
1356
+ this.cursorHidden = true;
1357
+ }
1358
+ if (this.timer) clearInterval(this.timer);
1359
+ this.render();
1360
+ this.timer = setInterval(() => {
1361
+ this.frame = (this.frame + 1) % this.frames.length;
1362
+ this.render();
1363
+ }, 80);
1364
+ this.timer.unref?.();
1365
+ return this;
1366
+ }
1367
+ stop() {
1368
+ if (this.timer) {
1369
+ clearInterval(this.timer);
1370
+ this.timer = null;
1371
+ }
1372
+ if (this.isTTY) process.stderr.write("\r\x1B[K");
1373
+ if (this.cursorHidden) {
1374
+ process.stderr.write("\x1B[?25h");
1375
+ this.cursorHidden = false;
1376
+ }
1377
+ return this;
1378
+ }
1379
+ persist(symbol, text) {
1380
+ if (this.timer) {
1381
+ clearInterval(this.timer);
1382
+ this.timer = null;
1383
+ }
1384
+ if (this.isTTY) process.stderr.write("\r\x1B[K");
1385
+ process.stderr.write(`${symbol} ${text ?? this._text}
1386
+ `);
1387
+ return this;
1388
+ }
1389
+ succeed(text) {
1390
+ return this.persist(c.green(this.sym.ok), text);
1391
+ }
1392
+ fail(text) {
1393
+ return this.persist(c.red(this.sym.fail), text);
1394
+ }
1395
+ warn(text) {
1396
+ return this.persist(c.yellow(this.sym.warn), text);
1397
+ }
1398
+ info(text) {
1399
+ return this.persist(c.cyan(this.sym.info), text);
1400
+ }
1401
+ };
1402
+ function createSpinner() {
1403
+ const spinner2 = new AnsiSpinner();
1404
+ if (process.stderr.isTTY) {
1405
+ process.once("exit", () => spinner2.stop());
1406
+ process.once("SIGINT", () => {
1407
+ spinner2.stop();
1408
+ process.exit(130);
1409
+ });
1410
+ }
1411
+ return spinner2;
1412
+ }
1413
+
1230
1414
  // src/display/progress.ts
1231
- import chalk from "chalk";
1232
- import ora from "ora";
1233
- var spinner = ora();
1415
+ var spinner = createSpinner();
1234
1416
  var currentAttackName = "";
1235
1417
  function handleEvent(event) {
1236
1418
  switch (event.type) {
1237
1419
  case "scan:start":
1238
- spinner.start(
1239
- chalk.cyan(`Starting scan (${event.totalAttacks} attacks)...`)
1240
- );
1420
+ spinner.start(c.cyan(`Starting scan (${event.totalAttacks} attacks)...`));
1241
1421
  break;
1242
1422
  case "scan:resume":
1243
1423
  spinner.info(
1244
- chalk.cyan(
1424
+ c.cyan(
1245
1425
  `Resuming \u2014 ${event.completed}/${event.total} attacks already done, running the rest`
1246
1426
  )
1247
1427
  );
@@ -1249,7 +1429,7 @@ function handleEvent(event) {
1249
1429
  break;
1250
1430
  case "attack:start":
1251
1431
  currentAttackName = event.attack.name;
1252
- spinner.text = chalk.cyan(
1432
+ spinner.text = c.cyan(
1253
1433
  `[${event.index + 1}/${event.total}] ${event.attack.name} (${severityColor(event.attack.severity)})`
1254
1434
  );
1255
1435
  break;
@@ -1258,14 +1438,14 @@ function handleEvent(event) {
1258
1438
  const prefix = `[${event.index + 1}/${event.total}]`;
1259
1439
  if (result.error) {
1260
1440
  spinner.warn(
1261
- `${prefix} ${result.name} \u2014 ${chalk.yellow("error")}: ${result.error}`
1441
+ `${prefix} ${result.name} \u2014 ${c.yellow("error")}: ${result.error}`
1262
1442
  );
1263
1443
  } else if (result.vulnerable) {
1264
1444
  spinner.fail(
1265
- `${prefix} ${result.name} \u2014 ${chalk.red("VULNERABLE")} (${severityColor(result.severity)})`
1445
+ `${prefix} ${result.name} \u2014 ${c.red("VULNERABLE")} (${severityColor(result.severity)})`
1266
1446
  );
1267
1447
  } else {
1268
- spinner.succeed(`${prefix} ${result.name} \u2014 ${chalk.green("secure")}`);
1448
+ spinner.succeed(`${prefix} ${result.name} \u2014 ${c.green("secure")}`);
1269
1449
  }
1270
1450
  if (event.index < event.total - 1) {
1271
1451
  spinner.start();
@@ -1273,18 +1453,18 @@ function handleEvent(event) {
1273
1453
  break;
1274
1454
  }
1275
1455
  case "crescendo:turn":
1276
- spinner.text = chalk.cyan(
1456
+ spinner.text = c.cyan(
1277
1457
  `${currentAttackName} \u2014 turn ${event.turn}/${event.totalTurns}`
1278
1458
  );
1279
1459
  break;
1280
1460
  case "attack:retry":
1281
- spinner.text = chalk.yellow(
1461
+ spinner.text = c.yellow(
1282
1462
  `${currentAttackName} \u2014 ${event.reason === "rate_limited" ? "rate limited" : "server error"}, backing off ${(event.waitMs / 1e3).toFixed(1)}s (retry ${event.attempt}/${event.maxRetries})`
1283
1463
  );
1284
1464
  break;
1285
1465
  case "scan:rate_limited":
1286
1466
  spinner.fail(
1287
- chalk.red(
1467
+ c.red(
1288
1468
  `Rate limited by target \u2014 skipping remaining attacks${event.retryAfterSec ? ` (retry after ${event.retryAfterSec}s)` : ""}`
1289
1469
  )
1290
1470
  );
@@ -1297,9 +1477,9 @@ function handleEvent(event) {
1297
1477
  }
1298
1478
  function printSummary(report, thresholds) {
1299
1479
  console.log("");
1300
- console.log(chalk.bold("\u2550\u2550\u2550 Shield LLM Scan Results \u2550\u2550\u2550"));
1480
+ console.log(c.bold("\u2550\u2550\u2550 Shield LLM Scan Results \u2550\u2550\u2550"));
1301
1481
  console.log("");
1302
- console.log(` Target: ${chalk.white(report.target)}`);
1482
+ console.log(` Target: ${c.white(report.target)}`);
1303
1483
  console.log(` Score: ${scoreColor(report.score)}`);
1304
1484
  console.log(` Grade: ${gradeColor(report.grade)}`);
1305
1485
  console.log(` Duration: ${(report.durationMs / 1e3).toFixed(1)}s`);
@@ -1308,15 +1488,15 @@ function printSummary(report, thresholds) {
1308
1488
  const secure = report.attacks.filter((a) => !a.vulnerable && !a.error);
1309
1489
  const errors = report.attacks.filter((a) => a.error);
1310
1490
  console.log(
1311
- ` ${chalk.red(`${vulnerable.length} vulnerable`)} \xB7 ${chalk.green(`${secure.length} secure`)} \xB7 ${chalk.yellow(`${errors.length} errors`)}`
1491
+ ` ${c.red(`${vulnerable.length} vulnerable`)} \xB7 ${c.green(`${secure.length} secure`)} \xB7 ${c.yellow(`${errors.length} errors`)}`
1312
1492
  );
1313
1493
  if (vulnerable.length > 0) {
1314
1494
  console.log("");
1315
- console.log(chalk.red.bold(" Vulnerabilities:"));
1495
+ console.log(c.redBold(" Vulnerabilities:"));
1316
1496
  for (const a of vulnerable) {
1317
1497
  const conf = a.llmEvaluation ? ` (${(a.llmEvaluation.confidence * 100).toFixed(0)}% confidence)` : "";
1318
1498
  console.log(
1319
- ` ${chalk.red("\u2717")} ${a.name} \u2014 ${severityColor(a.severity)}${conf}`
1499
+ ` ${c.red("\u2717")} ${a.name} \u2014 ${severityColor(a.severity)}${conf}`
1320
1500
  );
1321
1501
  }
1322
1502
  }
@@ -1324,21 +1504,21 @@ function printSummary(report, thresholds) {
1324
1504
  if (judge.degraded) {
1325
1505
  console.log("");
1326
1506
  console.log(
1327
- chalk.bgYellow.black.bold(" JUDGE DEGRADED ") + chalk.yellow(
1507
+ c.bgYellowBlackBold(" JUDGE DEGRADED ") + c.yellow(
1328
1508
  ` ${judge.degradedCount}/${judge.totalEvaluated} verdicts fell back to regex (${judge.errorSummary}).`
1329
1509
  )
1330
1510
  );
1331
1511
  console.log(
1332
- chalk.yellow(
1512
+ c.yellow(
1333
1513
  " Regex-only verdicts are less reliable than LLM-assisted ones. False positives likely. Fix the LLM provider config and re-run."
1334
1514
  )
1335
1515
  );
1336
1516
  }
1337
1517
  console.log("");
1338
1518
  if (thresholds.passed) {
1339
- console.log(chalk.green.bold(" \u2713 PASSED \u2014 all thresholds met"));
1519
+ console.log(c.greenBold(" \u2713 PASSED \u2014 all thresholds met"));
1340
1520
  } else {
1341
- console.log(chalk.red.bold(" \u2717 FAILED \u2014 threshold violations:"));
1521
+ console.log(c.redBold(" \u2717 FAILED \u2014 threshold violations:"));
1342
1522
  for (const reason of thresholds.reasons) {
1343
1523
  console.log(` - ${reason}`);
1344
1524
  }
@@ -1348,36 +1528,36 @@ function printSummary(report, thresholds) {
1348
1528
  function severityColor(severity) {
1349
1529
  switch (severity) {
1350
1530
  case "CRITICAL":
1351
- return chalk.red.bold(severity);
1531
+ return c.redBold(severity);
1352
1532
  case "HIGH":
1353
1533
  case "CRESCENDO":
1354
1534
  case "COMBO":
1355
- return chalk.yellow(severity);
1535
+ return c.yellow(severity);
1356
1536
  case "MEDIUM":
1357
- return chalk.blue(severity);
1537
+ return c.blue(severity);
1358
1538
  default:
1359
- return chalk.gray(severity);
1539
+ return c.gray(severity);
1360
1540
  }
1361
1541
  }
1362
1542
  function scoreColor(score) {
1363
- if (score >= 90) return chalk.green.bold(`${score}/100`);
1364
- if (score >= 75) return chalk.green(`${score}/100`);
1365
- if (score >= 60) return chalk.yellow(`${score}/100`);
1366
- if (score >= 40) return chalk.red(`${score}/100`);
1367
- return chalk.red.bold(`${score}/100`);
1543
+ if (score >= 90) return c.greenBold(`${score}/100`);
1544
+ if (score >= 75) return c.green(`${score}/100`);
1545
+ if (score >= 60) return c.yellow(`${score}/100`);
1546
+ if (score >= 40) return c.red(`${score}/100`);
1547
+ return c.redBold(`${score}/100`);
1368
1548
  }
1369
1549
  function gradeColor(grade) {
1370
1550
  switch (grade) {
1371
1551
  case "A":
1372
- return chalk.green.bold(grade);
1552
+ return c.greenBold(grade);
1373
1553
  case "B":
1374
- return chalk.green(grade);
1554
+ return c.green(grade);
1375
1555
  case "C":
1376
- return chalk.yellow(grade);
1556
+ return c.yellow(grade);
1377
1557
  case "D":
1378
- return chalk.red(grade);
1558
+ return c.red(grade);
1379
1559
  default:
1380
- return chalk.red.bold(grade);
1560
+ return c.redBold(grade);
1381
1561
  }
1382
1562
  }
1383
1563
 
@@ -1632,7 +1812,7 @@ async function retestCommand(scanId, opts) {
1632
1812
  attacks: plan.singles.map((s) => s.attack),
1633
1813
  multiTurnAttacks: plan.multiTurn.map((m) => m.attack),
1634
1814
  includeCrescendo: plan.multiTurn.length > 0,
1635
- customTests: plan.customs.map((c) => c.test),
1815
+ customTests: plan.customs.map((c2) => c2.test),
1636
1816
  concurrency: config.concurrency,
1637
1817
  delayMs: config.delayMs,
1638
1818
  attackTimeoutMs: config.attackTimeoutMs,
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  generatePdf,
10
10
  loadConfig,
11
11
  loadSystemPrompt
12
- } from "./chunk-IB7T5OJ2.js";
12
+ } from "./chunk-CWJWN44I.js";
13
13
  import "./chunk-I7M3BZK7.js";
14
14
  export {
15
15
  ConfigError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shield-llm",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -50,21 +50,9 @@
50
50
  "prepublishOnly": "pnpm build"
51
51
  },
52
52
  "dependencies": {
53
- "@inquirer/prompts": "^8.2.1",
54
- "chalk": "^5.3.0",
55
53
  "commander": "^12.0.0",
56
- "dotenv": "^17.2.3",
57
- "ora": "^8.0.0",
58
54
  "zod": "^3.23.0"
59
55
  },
60
- "peerDependencies": {
61
- "puppeteer": ">=24"
62
- },
63
- "peerDependenciesMeta": {
64
- "puppeteer": {
65
- "optional": true
66
- }
67
- },
68
56
  "devDependencies": {
69
57
  "@shield-llm/scanner-core": "workspace:*",
70
58
  "@shield-llm/shared": "workspace:*",