@exorcist-98/mcp-server 0.1.2 → 0.3.0

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/index.mjs CHANGED
@@ -11602,6 +11602,23 @@ async function isBinary(filePath) {
11602
11602
  async function* walkRepo(root, maxFileSize = MAX_FILE_SIZE) {
11603
11603
  yield* walkDir(root, root, maxFileSize);
11604
11604
  }
11605
+ async function* walkPaths(root) {
11606
+ yield* walkPathsIn(root, root);
11607
+ }
11608
+ async function* walkPathsIn(root, dir) {
11609
+ const dh = await opendir(dir);
11610
+ for await (const entry of dh) {
11611
+ const absPath = join4(dir, entry.name);
11612
+ const rel = relative2(root, absPath).replace(/\\/g, "/");
11613
+ if (entry.isDirectory()) {
11614
+ if (SKIP_DIRS.has(entry.name)) continue;
11615
+ yield { rel, isDirectory: true };
11616
+ yield* walkPathsIn(root, absPath);
11617
+ } else {
11618
+ yield { rel, isDirectory: false };
11619
+ }
11620
+ }
11621
+ }
11605
11622
  async function* walkDir(root, dir, maxFileSize) {
11606
11623
  const dh = await opendir(dir);
11607
11624
  for await (const entry of dh) {
@@ -11842,7 +11859,7 @@ function locateQuote(text, quote) {
11842
11859
  const viaMask = tryIn(masked);
11843
11860
  return viaMask ? { ...viaMask, shown: masked.slice(viaMask.index, viaMask.end) } : null;
11844
11861
  }
11845
- function positionOf(text, needle) {
11862
+ function positionOf2(text, needle) {
11846
11863
  const idx = text.indexOf(needle);
11847
11864
  if (idx === -1) return null;
11848
11865
  const before = text.slice(0, idx);
@@ -11936,9 +11953,9 @@ function decodesToText(v) {
11936
11953
  if (/^[A-Za-z0-9+\/]{16,}={0,2}$/.test(v) && v.length % 4 === 0) bytes = Buffer.from(v, "base64");
11937
11954
  else if (/^(?:[0-9a-f]{2}){12,}$/i.test(v)) bytes = Buffer.from(v, "hex");
11938
11955
  if (!bytes || bytes.length < 12) return false;
11939
- let printable2 = 0;
11940
- for (const b of bytes) if (b >= 32 && b < 127 || b === 10) printable2++;
11941
- return printable2 / bytes.length > 0.9 && /[A-Za-z]{3,}\s+[A-Za-z]{2,}/.test(bytes.toString("latin1"));
11956
+ let printable3 = 0;
11957
+ for (const b of bytes) if (b >= 32 && b < 127 || b === 10) printable3++;
11958
+ return printable3 / bytes.length > 0.9 && /[A-Za-z]{3,}\s+[A-Za-z]{2,}/.test(bytes.toString("latin1"));
11942
11959
  }
11943
11960
  function unquote(v) {
11944
11961
  const q = v[0];
@@ -12066,7 +12083,7 @@ async function judgeWholeFile(file, norm, client, maskedRuns = 0) {
12066
12083
  if (start >= text.length) break;
12067
12084
  const v = await judgeText(text.slice(start, start + MAX_JUDGED_CHARS), file.rel, client, maskedRuns);
12068
12085
  if (!v) continue;
12069
- const pos = positionOf(text, v.span);
12086
+ const pos = positionOf2(text, v.span);
12070
12087
  if (!pos) continue;
12071
12088
  return [{
12072
12089
  source: "heuristic",
@@ -22400,7 +22417,7 @@ var StdioServerTransport = class {
22400
22417
 
22401
22418
  // src/index.ts
22402
22419
  init_zod();
22403
- import { homedir as homedir2 } from "node:os";
22420
+ import { homedir as homedir3 } from "node:os";
22404
22421
  import { delimiter } from "node:path";
22405
22422
 
22406
22423
  // src/tools.ts
@@ -22633,7 +22650,7 @@ function requireSnippet() {
22633
22650
  if (hasRequiredSnippet) return snippet;
22634
22651
  hasRequiredSnippet = 1;
22635
22652
  const common2 = requireCommon();
22636
- function getLine(buffer, lineStart, lineEnd, position2, maxLineLength) {
22653
+ function getLine(buffer, lineStart, lineEnd2, position2, maxLineLength) {
22637
22654
  let head = "";
22638
22655
  let tail = "";
22639
22656
  const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
@@ -22641,12 +22658,12 @@ function requireSnippet() {
22641
22658
  head = " ... ";
22642
22659
  lineStart = position2 - maxHalfLength + head.length;
22643
22660
  }
22644
- if (lineEnd - position2 > maxHalfLength) {
22661
+ if (lineEnd2 - position2 > maxHalfLength) {
22645
22662
  tail = " ...";
22646
- lineEnd = position2 + maxHalfLength - tail.length;
22663
+ lineEnd2 = position2 + maxHalfLength - tail.length;
22647
22664
  }
22648
22665
  return {
22649
- str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
22666
+ str: head + buffer.slice(lineStart, lineEnd2).replace(/\t/g, "\u2192") + tail,
22650
22667
  pos: position2 - lineStart + head.length
22651
22668
  // relative position
22652
22669
  };
@@ -25676,7 +25693,11 @@ var MatchSchema = external_exports.object({
25676
25693
  // capabilities.yaml). The signature engine skips such rules.
25677
25694
  // `detonation` is the Detonation Chamber (EX-024, m5-detonation): a
25678
25695
  // sandboxed model run, only with `--detonate`.
25679
- analysis: external_exports.enum(["trifecta", "detonation"]).optional(),
25696
+ // `path-names` checks the names of every walked path (EX-029, path-names.ts).
25697
+ analysis: external_exports.enum(["trifecta", "detonation", "path-names"]).optional(),
25698
+ // Text an element hides from a person by its style (EX-028, hidden-text.ts):
25699
+ // reported only when the hidden text addresses the AI or asks for actions.
25700
+ hidden_text: external_exports.boolean().optional(),
25680
25701
  // unicode_class only: a single U+200B directly after `@` and before a name
25681
25702
  // is the way changelogs stop GitHub from notifying the person. Reported at
25682
25703
  // `severity` and not counted toward the escalation of many short runs.
@@ -25689,11 +25710,11 @@ var MatchSchema = external_exports.object({
25689
25710
  severity: external_exports.enum(["critical", "high", "medium", "low"])
25690
25711
  }).optional()
25691
25712
  }).superRefine((val, ctx2) => {
25692
- const hasAny = val.regex !== void 0 || val.unicode_class !== void 0 && val.unicode_class.length > 0 || val.json_path !== void 0 || val.analysis !== void 0;
25713
+ const hasAny = val.regex !== void 0 || val.unicode_class !== void 0 && val.unicode_class.length > 0 || val.json_path !== void 0 || val.hidden_text === true || val.analysis !== void 0;
25693
25714
  if (!hasAny) {
25694
25715
  ctx2.addIssue({
25695
25716
  code: external_exports.ZodIssueCode.custom,
25696
- message: "match must contain at least one of: regex, unicode_class, json_path, analysis"
25717
+ message: "match must contain at least one of: regex, unicode_class, json_path, analysis, hidden_text"
25697
25718
  });
25698
25719
  }
25699
25720
  if (val.value_regex !== void 0 && val.json_path === void 0) {
@@ -25914,6 +25935,9 @@ function flagTagOffsets(text) {
25914
25935
  }
25915
25936
  return out;
25916
25937
  }
25938
+ function isHiddenCodePoint(cp) {
25939
+ return CP_TO_CLASS.has(cp);
25940
+ }
25917
25941
  function findHiddenUnicode(text) {
25918
25942
  const hits = [];
25919
25943
  const flagTags = flagTagOffsets(text);
@@ -26618,6 +26642,224 @@ function decodeHidden(text) {
26618
26642
  return out.slice(0, MAX_HIDDEN_RUNS);
26619
26643
  }
26620
26644
 
26645
+ // ../core/src/hidden-text.ts
26646
+ var MAX_HIDDEN_ELEMENT = 2e3;
26647
+ var VOID_TAGS = /* @__PURE__ */ new Set(["img", "input", "br", "hr", "meta", "link", "area", "base", "col", "embed", "source", "track", "wbr"]);
26648
+ var AI_NAME_UPPER = /\bAI\b/;
26649
+ var AI_WORDS = /\b(?:assistants?|agents?|llms?|kiro|claude|copilot|chatgpt|gemini|cursor|language\s+models?|(?:the|this)\s+model)\b/i;
26650
+ var ACTION_VERB = "(?:write|rewrite|edit|modify|overwrite|run|execute|fetch|download|send|upload|start|launch|add|append|install|delete|remove|exfiltrate|forward|email)";
26651
+ var ACTION_OBJECT = "(?:files?|config(?:uration)?s?|servers?|commands?|scripts?|mcp|credentials?|secrets?|tokens?|api\\s+keys?|\\.env|\\S*\\.json|~\\/\\S+)";
26652
+ var ACTION = new RegExp(`\\b${ACTION_VERB}\\b[^.\\n!?]{0,60}?(?:\\b${ACTION_OBJECT}(?![\\w-])|${"~\\/"}|\\.env\\b)`, "i");
26653
+ var OVERRIDE = /\b(?:ignore|disregard|forget)\s+(?:all\s+|any\s+|the\s+)?(?:previous|prior|above|earlier)\b/i;
26654
+ function addressesAi(text) {
26655
+ if (text.length === 0) return false;
26656
+ return AI_NAME_UPPER.test(text) || AI_WORDS.test(text) || OVERRIDE.test(text) || ACTION.test(text);
26657
+ }
26658
+ function parseColour(raw) {
26659
+ const v = raw.trim().toLowerCase().replace(/\s*!important$/, "");
26660
+ if (v === "white") return [255, 255, 255];
26661
+ if (v === "black") return [0, 0, 0];
26662
+ const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(v);
26663
+ if (hex) {
26664
+ const h = hex[1];
26665
+ const f = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
26666
+ return [parseInt(f.slice(0, 2), 16), parseInt(f.slice(2, 4), 16), parseInt(f.slice(4, 6), 16)];
26667
+ }
26668
+ const rgb = /^rgba?\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*(?:[,/]\s*[\d.]+%?\s*)?\)$/.exec(v);
26669
+ if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])];
26670
+ return null;
26671
+ }
26672
+ function distance(a, b) {
26673
+ return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]), Math.abs(a[2] - b[2]));
26674
+ }
26675
+ function px(raw) {
26676
+ const m = /^(-?\d*\.?\d+)\s*(px|pt|em|rem|%|vw|vh)?$/.exec(raw.trim().toLowerCase());
26677
+ if (!m) return null;
26678
+ const n = Number(m[1]);
26679
+ const unit = m[2] ?? "";
26680
+ if (n === 0) return 0;
26681
+ if (unit === "px" || unit === "") return n;
26682
+ if (unit === "pt") return n * 1.333;
26683
+ if (unit === "em" || unit === "rem") return n * 16;
26684
+ return null;
26685
+ }
26686
+ function parseStyle(style) {
26687
+ const out = /* @__PURE__ */ new Map();
26688
+ for (const part of style.split(";")) {
26689
+ const i = part.indexOf(":");
26690
+ if (i < 1) continue;
26691
+ out.set(part.slice(0, i).trim().toLowerCase(), part.slice(i + 1).trim().replace(/\s*!important$/i, ""));
26692
+ }
26693
+ return out;
26694
+ }
26695
+ function hidingMethod(style) {
26696
+ const css = parseStyle(style);
26697
+ if (css.get("display")?.toLowerCase() === "none") return "display-none";
26698
+ if (css.get("visibility")?.toLowerCase() === "hidden") return "visibility-hidden";
26699
+ const opacity = css.get("opacity");
26700
+ if (opacity !== void 0 && /^0*\.?0+%?$/.test(opacity.trim())) return "opacity-zero";
26701
+ const size = css.get("font-size");
26702
+ if (size !== void 0) {
26703
+ const n = px(size);
26704
+ if (n !== null && n <= 2) return "font-size";
26705
+ }
26706
+ for (const key of ["left", "top", "right", "bottom", "text-indent", "margin-left"]) {
26707
+ const v = css.get(key);
26708
+ if (v !== void 0) {
26709
+ const n = px(v);
26710
+ if (n !== null && n <= -999) return "off-screen";
26711
+ }
26712
+ }
26713
+ const w = css.get("width");
26714
+ const h = css.get("height");
26715
+ const clipped = /^(hidden|clip)$/i.test(css.get("overflow") ?? "");
26716
+ if (clipped && (w !== void 0 && px(w) === 0 || h !== void 0 && px(h) === 0)) return "zero-box";
26717
+ const colour = css.get("color");
26718
+ if (colour !== void 0) {
26719
+ const c = parseColour(colour);
26720
+ if (c) {
26721
+ const bg = parseColour(css.get("background-color") ?? css.get("background") ?? "");
26722
+ if (bg ? distance(c, bg) <= 8 : distance(c, [255, 255, 255]) <= 5) return "colour";
26723
+ }
26724
+ }
26725
+ return null;
26726
+ }
26727
+ var OPEN_TAG = /<([a-zA-Z][a-zA-Z0-9-]*)\b([^<>]*?)\bstyle\s*=\s*(?:"([^"]*)"|'([^']*)')[^<>]*>/g;
26728
+ function plainElementText(html) {
26729
+ return html.replace(/<[^>]*>/g, " ").replace(/&nbsp;/gi, " ").replace(/&amp;/gi, "&").replace(/\s+/g, " ").trim();
26730
+ }
26731
+ var AI_META_NAME = /^(?:ai|llm|assistant|gpt|chatgpt|claude|kiro|copilot|agent|ai-agent|bot-instructions)(?:[-_:.][a-z0-9_.:-]*)?$/i;
26732
+ var META_TAG = /<meta\b[^<>]*>/gi;
26733
+ var IMG_TAG = /<img\b[^<>]*>/gi;
26734
+ var MD_IMAGE = /!\[([^\]\n]{1,500})\]\(/g;
26735
+ var AI_WORD = "(?:AI|assistants?|agents?|llms?|language\\s+models?|kiro|claude|copilot|chatgpt|gemini|cursor)";
26736
+ var ALT_ADDRESS = new RegExp(
26737
+ `(?:^|[.!?]\\s+)(?:hey\\s+|dear\\s+|attention\\s+)?${AI_WORD}\\s*[,:]|\\b(?:if\\s+you\\s+are|you\\s+are\\s+an?|note\\s+to|message\\s+for|instructions?\\s+for|attention)\\b[^.\\n]{0,30}\\b${AI_WORD}\\b`,
26738
+ "i"
26739
+ );
26740
+ function attr(tag, name) {
26741
+ const m = new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, "i").exec(tag);
26742
+ return m ? m[1] ?? m[2] ?? "" : null;
26743
+ }
26744
+ function altInstructs(alt) {
26745
+ const t = alt.replace(/\s+/g, " ").trim();
26746
+ return t.length > 0 && (ALT_ADDRESS.test(t) || OVERRIDE.test(t) || ACTION.test(t));
26747
+ }
26748
+ function metaTagFindings(text) {
26749
+ const out = [];
26750
+ META_TAG.lastIndex = 0;
26751
+ let m;
26752
+ while ((m = META_TAG.exec(text)) !== null) {
26753
+ const name = attr(m[0], "name");
26754
+ const content = attr(m[0], "content");
26755
+ if (name === null || content === null || !AI_META_NAME.test(name.trim())) continue;
26756
+ const body = content.replace(/&nbsp;/gi, " ").replace(/&amp;/gi, "&").replace(/\s+/g, " ").trim();
26757
+ if (!addressesAi(body)) continue;
26758
+ out.push({ index: m.index, length: m[0].length, method: "meta-tag", text: body });
26759
+ }
26760
+ return out;
26761
+ }
26762
+ function altTextFindings(text) {
26763
+ const out = [];
26764
+ let m;
26765
+ IMG_TAG.lastIndex = 0;
26766
+ while ((m = IMG_TAG.exec(text)) !== null) {
26767
+ const alt = attr(m[0], "alt");
26768
+ if (alt !== null && altInstructs(alt)) out.push({ index: m.index, length: m[0].length, method: "alt-text", text: alt.replace(/\s+/g, " ").trim() });
26769
+ }
26770
+ MD_IMAGE.lastIndex = 0;
26771
+ while ((m = MD_IMAGE.exec(text)) !== null) {
26772
+ const alt = m[1];
26773
+ if (altInstructs(alt)) out.push({ index: m.index, length: m[0].length, method: "alt-text", text: alt.replace(/\s+/g, " ").trim() });
26774
+ }
26775
+ return out;
26776
+ }
26777
+ function findHiddenText(text) {
26778
+ const all = [...findHiddenElements(text), ...metaTagFindings(text), ...altTextFindings(text)];
26779
+ return all.sort((a, b) => a.index - b.index);
26780
+ }
26781
+ function findHiddenElements(text) {
26782
+ const out = [];
26783
+ OPEN_TAG.lastIndex = 0;
26784
+ let lastEnd = -1;
26785
+ let m;
26786
+ while ((m = OPEN_TAG.exec(text)) !== null) {
26787
+ const name = m[1].toLowerCase();
26788
+ if (VOID_TAGS.has(name) || m.index < lastEnd) continue;
26789
+ const method = hidingMethod(m[3] ?? m[4] ?? "");
26790
+ if (method === null) continue;
26791
+ const start = m.index + m[0].length;
26792
+ const window = text.slice(start, start + MAX_HIDDEN_ELEMENT);
26793
+ const close = window.toLowerCase().indexOf(`</${name}`);
26794
+ const inner = close === -1 ? window : window.slice(0, close);
26795
+ const body = plainElementText(inner);
26796
+ if (!addressesAi(body)) continue;
26797
+ const end = start + inner.length;
26798
+ out.push({ index: m.index, length: end - m.index, method, text: body });
26799
+ lastEnd = end;
26800
+ }
26801
+ return out;
26802
+ }
26803
+
26804
+ // ../core/src/json-loose.ts
26805
+ function parseJsonLoose(text) {
26806
+ try {
26807
+ return JSON.parse(text);
26808
+ } catch {
26809
+ }
26810
+ try {
26811
+ return JSON.parse(stripJsonComments(text));
26812
+ } catch {
26813
+ return void 0;
26814
+ }
26815
+ }
26816
+ function stripJsonComments(text) {
26817
+ let out = "";
26818
+ let i = text.charCodeAt(0) === 65279 ? 1 : 0;
26819
+ while (i < text.length) {
26820
+ const c = text[i];
26821
+ const next = text[i + 1];
26822
+ if (c === '"') {
26823
+ let j = i + 1;
26824
+ while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
26825
+ out += text.slice(i, j + 1);
26826
+ i = j + 1;
26827
+ } else if (c === "/" && next === "/") {
26828
+ while (i < text.length && text[i] !== "\n") i++;
26829
+ } else if (c === "/" && next === "*") {
26830
+ const end = text.indexOf("*/", i + 2);
26831
+ i = end === -1 ? text.length : end + 2;
26832
+ out += " ";
26833
+ } else {
26834
+ out += c;
26835
+ i++;
26836
+ }
26837
+ }
26838
+ return dropTrailingCommas(out);
26839
+ }
26840
+ function dropTrailingCommas(text) {
26841
+ let out = "";
26842
+ let i = 0;
26843
+ while (i < text.length) {
26844
+ const c = text[i];
26845
+ if (c === '"') {
26846
+ let j = i + 1;
26847
+ while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
26848
+ out += text.slice(i, j + 1);
26849
+ i = j + 1;
26850
+ } else if (c === ",") {
26851
+ let j = i + 1;
26852
+ while (j < text.length && /\s/.test(text[j])) j++;
26853
+ if (text[j] !== "}" && text[j] !== "]") out += c;
26854
+ i++;
26855
+ } else {
26856
+ out += c;
26857
+ i++;
26858
+ }
26859
+ }
26860
+ return out;
26861
+ }
26862
+
26621
26863
  // ../core/src/scanner/signature-engine.ts
26622
26864
  init_severity_paths();
26623
26865
 
@@ -27052,9 +27294,9 @@ function isHexText(s) {
27052
27294
  }
27053
27295
  function looksLikeText(bytes) {
27054
27296
  if (bytes.length < 24) return false;
27055
- let printable2 = 0;
27056
- for (const b of bytes) if (b >= 32 && b < 127 || b === 10 || b === 13 || b === 9) printable2++;
27057
- if (printable2 / bytes.length < 0.95) return false;
27297
+ let printable3 = 0;
27298
+ for (const b of bytes) if (b >= 32 && b < 127 || b === 10 || b === 13 || b === 9) printable3++;
27299
+ if (printable3 / bytes.length < 0.95) return false;
27058
27300
  const text = bytes.toString("latin1");
27059
27301
  if (/^\s*[{[]/.test(text)) return false;
27060
27302
  const words2 = text.split(/\s+/).filter((w) => /[A-Za-z]{2,}/.test(w)).length;
@@ -27185,6 +27427,13 @@ function runSignatures(file, norm, defs, limitMs = REGEX_TIME_LIMIT_MS) {
27185
27427
  findings.push(...capPerFile(def, mineOut));
27186
27428
  }
27187
27429
  }
27430
+ if (match.hidden_text) {
27431
+ for (const h of findHiddenText(norm.plain)) {
27432
+ if (!ctx2.allows(def, h.text, h.index, norm.plain, h.index)) continue;
27433
+ const { line, col } = offsetToPosition(norm.original, norm.plainMap?.[h.index] ?? h.index);
27434
+ findings.push({ ...base, line, col, span: truncateSpan(h.text) });
27435
+ }
27436
+ }
27188
27437
  if (match.unicode_class && match.unicode_class.length > 0) {
27189
27438
  let run = [];
27190
27439
  const mineStart = findings.length;
@@ -27230,12 +27479,8 @@ function runSignatures(file, norm, defs, limitMs = REGEX_TIME_LIMIT_MS) {
27230
27479
  }
27231
27480
  }
27232
27481
  if (match.json_path) {
27233
- let parsed;
27234
- try {
27235
- parsed = JSON.parse(norm.original);
27236
- } catch {
27237
- continue;
27238
- }
27482
+ const parsed = parseJsonLoose(norm.original);
27483
+ if (parsed === void 0) continue;
27239
27484
  if (parsed === null || typeof parsed !== "object") continue;
27240
27485
  let results2;
27241
27486
  try {
@@ -27374,6 +27619,546 @@ function makeContext(file, norm, defs, limitMs) {
27374
27619
  };
27375
27620
  }
27376
27621
 
27622
+ // ../core/src/scanner/scan-text.ts
27623
+ function scanText(text, role, defs, label = "(text)", limitMs = REGEX_TIME_LIMIT_MS) {
27624
+ const file = { path: label, rel: label, role, sizeBytes: text.length };
27625
+ return runSignatures(file, normalize(text, role), defs, limitMs);
27626
+ }
27627
+
27628
+ // ../core/src/source-tools.ts
27629
+ var MAX_SITES = 100;
27630
+ var MAX_AHEAD = 2e4;
27631
+ var TS_EXT = [".ts", ".tsx", ".js", ".mjs", ".cjs", ".mts"];
27632
+ function languageOf(relPath) {
27633
+ const lower = String(relPath).toLowerCase();
27634
+ if (TS_EXT.some((e) => lower.endsWith(e))) return "ts";
27635
+ if (lower.endsWith(".py")) return "py";
27636
+ if (lower.endsWith(".go")) return "go";
27637
+ return null;
27638
+ }
27639
+ var isIdent = (c) => c !== void 0 && (c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9" || c === "_" || c === "$");
27640
+ var isHex = (s) => s.length > 0 && [...s].every((c) => c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F");
27641
+ var isQuote = (c) => c === '"' || c === "'" || c === "`";
27642
+ function fromCode(code) {
27643
+ if (!Number.isInteger(code) || code < 0 || code > 1114111) return null;
27644
+ return String.fromCodePoint(code);
27645
+ }
27646
+ function readEscape(text, i, lang, limit) {
27647
+ const n = text[i + 1];
27648
+ if (n === void 0 || i + 1 >= limit) return null;
27649
+ if (n === "\n") return { out: "", len: 2 };
27650
+ if (n === "\r") return { out: "", len: text[i + 2] === "\n" ? 3 : 2 };
27651
+ const simple = { n: "\n", t: " ", r: "\r", b: "\b", f: "\f", v: "\v", a: "\x07" };
27652
+ if (n === "u" && text[i + 2] === "{" && lang === "ts") {
27653
+ const close = text.indexOf("}", i + 3);
27654
+ const hex = close === -1 || close - i > 12 ? "" : text.slice(i + 3, close);
27655
+ const ch = isHex(hex) ? fromCode(parseInt(hex, 16)) : null;
27656
+ return ch === null ? null : { out: ch, len: close - i + 1 };
27657
+ }
27658
+ const widths = { x: 2, u: 4 };
27659
+ const w = n === "U" && lang !== "ts" ? 8 : widths[n];
27660
+ if (w !== void 0) {
27661
+ const hex = text.slice(i + 2, i + 2 + w);
27662
+ const ch = hex.length === w && isHex(hex) ? fromCode(parseInt(hex, 16)) : null;
27663
+ return ch === null ? { out: lang === "py" ? `\\${n}` : n, len: 2 } : { out: ch, len: 2 + w };
27664
+ }
27665
+ if (lang === "go" && n >= "0" && n <= "7") {
27666
+ const oct = text.slice(i + 1, i + 4);
27667
+ if (oct.length === 3 && [...oct].every((c) => c >= "0" && c <= "7")) return { out: String.fromCharCode(parseInt(oct, 8)), len: 4 };
27668
+ }
27669
+ const s = simple[n];
27670
+ if (s !== void 0) return { out: s, len: 2 };
27671
+ if (n === "0" && lang !== "go") return { out: "\0", len: 2 };
27672
+ return { out: lang === "py" && n !== "\\" && n !== '"' && n !== "'" ? `\\${n}` : n, len: 2 };
27673
+ }
27674
+ function readLiteral(text, q, lang, limit, raw = false) {
27675
+ const quote = text[q];
27676
+ if (!isQuote(quote) || quote === void 0) return null;
27677
+ if (quote === "`" && lang === "py") return null;
27678
+ if (quote === "'" && lang === "go") return null;
27679
+ const triple = lang === "py" && text[q + 1] === quote && text[q + 2] === quote;
27680
+ const open3 = triple ? 3 : 1;
27681
+ const goRaw = lang === "go" && quote === "`";
27682
+ const start = q + open3;
27683
+ let value = "";
27684
+ const map2 = [];
27685
+ const push2 = (s, at) => {
27686
+ for (let k = 0; k < s.length; k++) {
27687
+ value += s[k];
27688
+ map2.push(at);
27689
+ }
27690
+ };
27691
+ let i = start;
27692
+ while (i < limit) {
27693
+ const c = text[i];
27694
+ if (c === void 0) return null;
27695
+ if (triple ? c === quote && text[i + 1] === quote && text[i + 2] === quote : c === quote) {
27696
+ map2.push(i);
27697
+ return { value, map: map2, start, contentEnd: i, next: i + open3 };
27698
+ }
27699
+ if (c === "\n" && !triple && !goRaw && quote !== "`") return null;
27700
+ if (lang === "ts" && quote === "`" && c === "$" && text[i + 1] === "{") return null;
27701
+ if (c === "\\" && !goRaw && !raw) {
27702
+ const e = readEscape(text, i, lang, limit);
27703
+ if (e === null) return null;
27704
+ push2(e.out, i);
27705
+ i += e.len;
27706
+ continue;
27707
+ }
27708
+ push2(c, i);
27709
+ i++;
27710
+ }
27711
+ return null;
27712
+ }
27713
+ function skipQuoted(text, q, lang, limit) {
27714
+ const quote = text[q];
27715
+ if (quote === void 0) return -1;
27716
+ const triple = lang === "py" && text[q + 1] === quote && text[q + 2] === quote;
27717
+ let i = q + (triple ? 3 : 1);
27718
+ while (i < limit) {
27719
+ const c = text[i];
27720
+ if (c === "\\" && !(lang === "go" && quote === "`")) {
27721
+ i += 2;
27722
+ continue;
27723
+ }
27724
+ if (triple ? c === quote && text[i + 1] === quote && text[i + 2] === quote : c === quote) return i + (triple ? 3 : 1);
27725
+ if (c === "\n" && !triple && quote !== "`") return -1;
27726
+ i++;
27727
+ }
27728
+ return -1;
27729
+ }
27730
+ function readPyString(text, p, limit) {
27731
+ let i = p;
27732
+ let raw = false;
27733
+ while (i < p + 2 && "rRuUbBfF".includes(text[i] ?? "#")) {
27734
+ if (text[i] === "r" || text[i] === "R") raw = true;
27735
+ i++;
27736
+ }
27737
+ return readLiteral(text, i, "py", limit, raw);
27738
+ }
27739
+ function skipTrivia(text, p, lang, limit) {
27740
+ let i = p;
27741
+ while (i < limit) {
27742
+ const c = text[i];
27743
+ if (c === " " || c === " " || c === "\n" || c === "\r") {
27744
+ i++;
27745
+ continue;
27746
+ }
27747
+ if (lang === "py" && c === "#") {
27748
+ i = lineEnd(text, i);
27749
+ continue;
27750
+ }
27751
+ if (lang !== "py" && c === "/" && text[i + 1] === "/") {
27752
+ i = lineEnd(text, i);
27753
+ continue;
27754
+ }
27755
+ if (lang !== "py" && c === "/" && text[i + 1] === "*") {
27756
+ const close = text.indexOf("*/", i + 2);
27757
+ if (close === -1 || close >= limit) return limit;
27758
+ i = close + 2;
27759
+ continue;
27760
+ }
27761
+ break;
27762
+ }
27763
+ return i;
27764
+ }
27765
+ function lineEnd(text, i) {
27766
+ const nl = text.indexOf("\n", i);
27767
+ return nl === -1 ? text.length : nl + 1;
27768
+ }
27769
+ function skipArgument(text, p, lang, limit) {
27770
+ let depth = 0;
27771
+ let i = p;
27772
+ while (i < limit) {
27773
+ const c = text[i];
27774
+ if (isQuote(c)) {
27775
+ const j = skipQuoted(text, i, lang, limit);
27776
+ if (j < 0) return -1;
27777
+ i = j;
27778
+ continue;
27779
+ }
27780
+ if (lang === "py" && c === "#" || lang !== "py" && c === "/" && (text[i + 1] === "/" || text[i + 1] === "*")) {
27781
+ const j = skipTrivia(text, i, lang, limit);
27782
+ i = j > i ? j : i + 1;
27783
+ continue;
27784
+ }
27785
+ if (c === "(" || c === "[" || c === "{") depth++;
27786
+ else if (c === ")" || c === "]" || c === "}") {
27787
+ if (depth === 0) return i;
27788
+ depth--;
27789
+ } else if (c === "," && depth === 0) return i;
27790
+ i++;
27791
+ }
27792
+ return -1;
27793
+ }
27794
+ function findKeyString(text, open3, lang, limit, sep2) {
27795
+ let depth = 0;
27796
+ let i = open3;
27797
+ let lit = null;
27798
+ const valueAt = (p) => {
27799
+ const v = skipTrivia(text, p, lang, limit);
27800
+ return lang === "py" ? readPyString(text, v, limit) : readLiteral(text, v, lang, limit);
27801
+ };
27802
+ const sepAt = (p) => {
27803
+ const j = skipTrivia(text, p, lang, limit);
27804
+ if (text[j] !== sep2 || sep2 === "=" && text[j + 1] === "=") return -1;
27805
+ return j + 1;
27806
+ };
27807
+ while (i < limit) {
27808
+ const c = text[i];
27809
+ if (c === void 0) break;
27810
+ if (isQuote(c)) {
27811
+ const l = lang === "ts" && depth === 1 ? readLiteral(text, i, lang, limit) : null;
27812
+ if (l && l.value === "description" && lit === null) {
27813
+ const s = sepAt(l.next);
27814
+ if (s >= 0) lit = valueAt(s);
27815
+ }
27816
+ const j = l ? l.next : skipQuoted(text, i, lang, limit);
27817
+ if (j < 0) return { lit, after: -1 };
27818
+ i = j;
27819
+ continue;
27820
+ }
27821
+ if (lang === "py" && c === "#" || lang !== "py" && c === "/" && (text[i + 1] === "/" || text[i + 1] === "*")) {
27822
+ const j = skipTrivia(text, i, lang, limit);
27823
+ i = j > i ? j : i + 1;
27824
+ continue;
27825
+ }
27826
+ if (c === "(" || c === "[" || c === "{") depth++;
27827
+ else if (c === ")" || c === "]" || c === "}") {
27828
+ depth--;
27829
+ if (depth <= 0) return { lit, after: i + 1 };
27830
+ } else if (depth === 1 && isIdent(c) && !isIdent(text[i - 1]) && text[i - 1] !== ".") {
27831
+ let j = i;
27832
+ while (j < limit && isIdent(text[j])) j++;
27833
+ if (j - i === "description".length && text.startsWith("description", i) && lit === null) {
27834
+ const s = sepAt(j);
27835
+ if (s >= 0) lit = valueAt(s);
27836
+ }
27837
+ i = j;
27838
+ continue;
27839
+ }
27840
+ i++;
27841
+ }
27842
+ return { lit, after: -1 };
27843
+ }
27844
+ var toFound = (l) => ({ text: l.value, offset: l.start, end: l.contentEnd, map: l.map });
27845
+ function indexesOf(text, needle, budget) {
27846
+ const out = [];
27847
+ let from = 0;
27848
+ while (budget.left > 0) {
27849
+ const i = text.indexOf(needle, from);
27850
+ if (i === -1) break;
27851
+ out.push(i);
27852
+ budget.left--;
27853
+ from = i + needle.length;
27854
+ }
27855
+ return out;
27856
+ }
27857
+ var lim = (text, from) => Math.min(text.length, from + MAX_AHEAD);
27858
+ function extractTs(text, budget, out) {
27859
+ for (const at of indexesOf(text, ".tool(", budget)) {
27860
+ const limit = lim(text, at);
27861
+ const first = skipTrivia(text, at + 6, "ts", limit);
27862
+ const e = skipArgument(text, first, "ts", limit);
27863
+ if (e < 0 || text[e] !== ",") continue;
27864
+ const p = skipTrivia(text, e + 1, "ts", limit);
27865
+ const l = isQuote(text[p]) ? readLiteral(text, p, "ts", limit) : null;
27866
+ if (l) out.push(toFound(l));
27867
+ }
27868
+ for (const needle of ["registerTool(", "registerTool<"]) {
27869
+ for (const at of indexesOf(text, needle, budget)) {
27870
+ const limit = lim(text, at);
27871
+ let paren = at + needle.length - 1;
27872
+ if (needle.endsWith("<")) {
27873
+ paren = text.indexOf("(", at + needle.length);
27874
+ if (paren === -1 || paren > at + 300) continue;
27875
+ }
27876
+ const first = skipTrivia(text, paren + 1, "ts", limit);
27877
+ const e = skipArgument(text, first, "ts", limit);
27878
+ if (e < 0 || text[e] !== ",") continue;
27879
+ const p = skipTrivia(text, e + 1, "ts", limit);
27880
+ if (text[p] !== "{") continue;
27881
+ const { lit } = findKeyString(text, p, "ts", limit, ":");
27882
+ if (lit) out.push(toFound(lit));
27883
+ }
27884
+ }
27885
+ }
27886
+ function docstringAfter(text, from, limit) {
27887
+ let i = from;
27888
+ let def = -1;
27889
+ while (i < limit) {
27890
+ const nl = text.indexOf("\n", i);
27891
+ if (nl === -1 || nl + 1 >= limit) return null;
27892
+ let p2 = nl + 1;
27893
+ while (text[p2] === " " || text[p2] === " ") p2++;
27894
+ if (text.startsWith("def ", p2) || text.startsWith("async def ", p2)) {
27895
+ def = p2;
27896
+ break;
27897
+ }
27898
+ if (text.startsWith("class ", p2)) return null;
27899
+ i = nl + 1;
27900
+ }
27901
+ if (def < 0) return null;
27902
+ let depth = 0;
27903
+ let j = def;
27904
+ let colon = -1;
27905
+ while (j < limit) {
27906
+ const c = text[j];
27907
+ if (isQuote(c)) {
27908
+ const k = skipQuoted(text, j, "py", limit);
27909
+ if (k < 0) return null;
27910
+ j = k;
27911
+ continue;
27912
+ }
27913
+ if (c === "#") {
27914
+ j = lineEnd(text, j);
27915
+ continue;
27916
+ }
27917
+ if (c === "(" || c === "[" || c === "{") depth++;
27918
+ else if (c === ")" || c === "]" || c === "}") depth--;
27919
+ else if (c === ":" && depth === 0) {
27920
+ colon = j;
27921
+ break;
27922
+ }
27923
+ j++;
27924
+ }
27925
+ if (colon < 0) return null;
27926
+ const p = skipTrivia(text, colon + 1, "py", limit);
27927
+ return readPyString(text, p, limit);
27928
+ }
27929
+ function extractPy(text, budget, out) {
27930
+ for (const name of ["@mcp.tool", "@server.tool", "@app.tool"]) {
27931
+ for (const at of indexesOf(text, name, budget)) {
27932
+ let b = at - 1;
27933
+ while (b >= 0 && (text[b] === " " || text[b] === " ")) b--;
27934
+ if (b >= 0 && text[b] !== "\n") continue;
27935
+ const nameEnd = at + name.length;
27936
+ if (isIdent(text[nameEnd]) || text[nameEnd] === ".") continue;
27937
+ const limit = lim(text, at);
27938
+ let after = nameEnd;
27939
+ let lit = null;
27940
+ if (text[nameEnd] === "(") {
27941
+ const r = findKeyString(text, nameEnd, "py", limit, "=");
27942
+ lit = r.lit;
27943
+ if (r.after > 0) after = r.after;
27944
+ }
27945
+ lit ??= docstringAfter(text, after, limit);
27946
+ if (lit) out.push(toFound(lit));
27947
+ }
27948
+ }
27949
+ }
27950
+ function extractGo(text, budget, out) {
27951
+ for (const at of indexesOf(text, "WithDescription(", budget)) {
27952
+ if (isIdent(text[at - 1])) continue;
27953
+ const limit = lim(text, at);
27954
+ const p = skipTrivia(text, at + "WithDescription(".length, "go", limit);
27955
+ const l = text[p] === '"' || text[p] === "`" ? readLiteral(text, p, "go", limit) : null;
27956
+ if (l) out.push(toFound(l));
27957
+ }
27958
+ }
27959
+ function extract(text, lang) {
27960
+ const out = [];
27961
+ const budget = { left: MAX_SITES };
27962
+ if (lang === "ts") extractTs(text, budget, out);
27963
+ else if (lang === "py") extractPy(text, budget, out);
27964
+ else extractGo(text, budget, out);
27965
+ const seen = /* @__PURE__ */ new Set();
27966
+ return out.filter((f) => !seen.has(f.offset) && seen.add(f.offset)).sort((a, b) => a.offset - b.offset);
27967
+ }
27968
+ function positionOf(text, offset) {
27969
+ let line = 1;
27970
+ let lastNl = -1;
27971
+ let i = text.indexOf("\n");
27972
+ while (i !== -1 && i < offset) {
27973
+ line++;
27974
+ lastNl = i;
27975
+ i = text.indexOf("\n", i + 1);
27976
+ }
27977
+ return { line, col: offset - lastNl };
27978
+ }
27979
+ function indexOfLineCol(s, line, col) {
27980
+ let start = 0;
27981
+ for (let l = 1; l < line; l++) {
27982
+ const nl = s.indexOf("\n", start);
27983
+ if (nl === -1) return 0;
27984
+ start = nl + 1;
27985
+ }
27986
+ return start + col - 1;
27987
+ }
27988
+ var ORDER_HINT = /^(?:before using this tool|(?:prior to|before) (?:invoking|calling|running|using) (?:this|any|the))\b/i;
27989
+ var SENSITIVE_TARGET = /~\/\.ssh|id_rsa|\.env\b|\bcredentials?\b|\bprivate key\b|\bapi[ _-]?key\b|\btoken\b|\bpassword\b/i;
27990
+ var CONCEALMENT = /\b(?:do not|don't|dont) (?:tell|inform|mention|notify)\b|\bwithout (?:telling|informing|notifying|asking)\b|\b(?:secret|hidden|silently)\b/i;
27991
+ var SEND_VERB = /\b(?:send|upload|forward|exfiltrate|post|include|attach)(?:s|es|ed|ing)?\b/i;
27992
+ var URL_OR_HOST = /https?:\/\/|\bwww\.|\b[a-z0-9-]+(?:\.[a-z0-9-]+)*\.(?:com|net|org|io|dev|xyz|invalid|test|example)\b/i;
27993
+ var SENTENCE_WINDOW = 500;
27994
+ function sentenceAround(whole, from, to) {
27995
+ const isEnd = (i) => {
27996
+ const c = whole.charAt(i);
27997
+ if (c === "\n") return true;
27998
+ return (c === "." || c === "!" || c === "?") && (i + 1 >= whole.length || /\s/.test(whole.charAt(i + 1)));
27999
+ };
28000
+ let start = Math.min(from, whole.length);
28001
+ const lo = Math.max(0, start - SENTENCE_WINDOW);
28002
+ while (start > lo && !isEnd(start - 1)) start--;
28003
+ let end = Math.max(Math.min(to, whole.length), start);
28004
+ const hi = Math.min(whole.length, end + SENTENCE_WINDOW);
28005
+ while (end < hi && !isEnd(end)) end++;
28006
+ return whole.slice(start, end);
28007
+ }
28008
+ function isSuspiciousSentence(sentence) {
28009
+ if (CONCEALMENT.test(sentence) || SENSITIVE_TARGET.test(sentence)) return true;
28010
+ return SEND_VERB.test(sentence) && URL_OR_HOST.test(sentence);
28011
+ }
28012
+ function isQuietHint(span, whole, at) {
28013
+ return ORDER_HINT.test(span.trim()) && !isSuspiciousSentence(sentenceAround(whole, at, at + span.length));
28014
+ }
28015
+ function scanSourceTools(file, text, defs) {
28016
+ try {
28017
+ const def = defs.find((d) => d.id === "EX-005");
28018
+ const lang = languageOf(file.rel);
28019
+ if (!def || lang === null || typeof text !== "string") return [];
28020
+ const out = [];
28021
+ for (const s of extract(text, lang)) {
28022
+ for (const hit of scanText(s.text, "mcp-config", [def], file.rel)) {
28023
+ const idx = Math.min(Math.max(indexOfLineCol(s.text, hit.line, hit.col), 0), s.text.length);
28024
+ if (isQuietHint(hit.span, s.text, idx)) continue;
28025
+ const at = s.map[idx] ?? s.offset;
28026
+ out.push({ ...hit, file: file.rel, ...positionOf(text, at) });
28027
+ }
28028
+ }
28029
+ return out;
28030
+ } catch {
28031
+ return [];
28032
+ }
28033
+ }
28034
+
28035
+ // ../core/src/sandbox-policy.ts
28036
+ init_canary();
28037
+ var SANDBOX_RULE_ID = "EX-035";
28038
+ var SANDBOX_FILE = /(?:^|\/)\.kiro\/settings\/sandbox\.json$/;
28039
+ var OWASP = ["ASI05 Unexpected Code Execution", "LLM06:2025 Excessive Agency"];
28040
+ var FIX = 'A project file can only tighten the global sandbox policy, so if your global policy turns the sandbox and MCP wrapping on, it still applies here. To be covered in every project, set "enabled": true and "mcpSandboxing": true in your global ~/.kiro/settings/sandbox.json (or in this file).';
28041
+ function indexOfFalse(text, key) {
28042
+ const re2 = new RegExp(`"${key}"\\s*:\\s*false`, "g");
28043
+ for (let m = re2.exec(text); m; m = re2.exec(text)) {
28044
+ const lineStart = text.lastIndexOf("\n", m.index) + 1;
28045
+ if (!text.slice(lineStart, m.index).includes("//")) return m.index;
28046
+ }
28047
+ return -1;
28048
+ }
28049
+ function sandboxFindings(text, rel) {
28050
+ if (!SANDBOX_FILE.test(rel.replace(/\\/g, "/"))) return [];
28051
+ const doc = parseJsonLoose(text);
28052
+ if (typeof doc !== "object" || doc === null || Array.isArray(doc)) return [];
28053
+ const obj = doc;
28054
+ const mcpOff = obj["mcpSandboxing"] === false;
28055
+ const allOff = obj["enabled"] === false;
28056
+ if (!mcpOff && !allOff) return [];
28057
+ const key = mcpOff ? "mcpSandboxing" : "enabled";
28058
+ const at = indexOfFalse(text, key);
28059
+ if (at < 0) return [];
28060
+ const m = new RegExp(`^"${key}"\\s*:\\s*false`).exec(text.slice(at));
28061
+ const { line, col } = lineColOf(text, at);
28062
+ return [{
28063
+ source: "signature",
28064
+ ruleId: SANDBOX_RULE_ID,
28065
+ title: mcpOff ? "Info: MCP sandboxing is off in this project" : "Info: the command sandbox is off in this project",
28066
+ severity: "low",
28067
+ file: rel,
28068
+ line,
28069
+ col,
28070
+ span: m ? m[0] : `"${key}": false`,
28071
+ owasp: OWASP,
28072
+ fix: FIX
28073
+ }];
28074
+ }
28075
+
28076
+ // ../core/src/path-names.ts
28077
+ var MAX_PATH_SPAN = 120;
28078
+ var CONTROL = /[\u0000-\u001F\u007F-\u009F]/;
28079
+ var AI_NAMES = /* @__PURE__ */ new Set(["assistant", "agent", "ai", "claude", "kiro", "copilot", "llm"]);
28080
+ var FILLER = /* @__PURE__ */ new Set(["please", "now", "first", "then", "also", "always", "you", "must", "should", "to"]);
28081
+ var ACTION_VERBS = /* @__PURE__ */ new Set([
28082
+ "read",
28083
+ "send",
28084
+ "upload",
28085
+ "post",
28086
+ "email",
28087
+ "leak",
28088
+ "exfiltrate",
28089
+ "forward",
28090
+ "paste",
28091
+ "copy",
28092
+ "print",
28093
+ "cat",
28094
+ "run",
28095
+ "execute",
28096
+ "fetch",
28097
+ "curl",
28098
+ "download",
28099
+ "write",
28100
+ "edit",
28101
+ "delete",
28102
+ "reveal",
28103
+ "dump",
28104
+ "ignore",
28105
+ "disregard",
28106
+ "forget"
28107
+ ]);
28108
+ var SENSITIVE = /* @__PURE__ */ new Set([
28109
+ "env",
28110
+ "dotenv",
28111
+ "secret",
28112
+ "secrets",
28113
+ "credential",
28114
+ "credentials",
28115
+ "token",
28116
+ "tokens",
28117
+ "key",
28118
+ "keys",
28119
+ "ssh",
28120
+ "passwd",
28121
+ "password",
28122
+ "passwords",
28123
+ "apikey"
28124
+ ]);
28125
+ var OVERRIDE2 = /^(?:(?:please|now|first|you must|always) )?(?:ignore|disregard|forget|override) (?:all |any |the |your |every )?(?:previous|prior|above|earlier|preceding|system) (?:instructions?|rules|prompts?|context|guidelines|directives)\b/;
28126
+ function nameWords(name) {
28127
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s._+\-]+/).map((w) => w.toLowerCase()).filter((w) => w.length > 0);
28128
+ }
28129
+ function escapePathSpan(name) {
28130
+ let out = "";
28131
+ let count = 0;
28132
+ for (const ch of name) {
28133
+ const cp = ch.codePointAt(0) ?? 0;
28134
+ const shown = isHiddenCodePoint(cp) || CONTROL.test(ch) || cp === 8232 || cp === 8233 ? `[U+${cp.toString(16).toUpperCase().padStart(4, "0")}]` : ch;
28135
+ if (count >= MAX_PATH_SPAN) return `${out}\u2026`;
28136
+ out += shown;
28137
+ count++;
28138
+ }
28139
+ return out;
28140
+ }
28141
+ function readsAsInstruction(words2) {
28142
+ if (words2.length < 3) return false;
28143
+ if (OVERRIDE2.test(words2.join(" "))) return true;
28144
+ if (words2.length < 4) return false;
28145
+ const verbs = words2.filter((w) => ACTION_VERBS.has(w));
28146
+ const hasSensitive = words2.some((w) => SENSITIVE.has(w));
28147
+ const aiNamed = words2.some((w) => AI_NAMES.has(w));
28148
+ if (aiNamed && verbs.length >= 1 && hasSensitive) return true;
28149
+ const lead = words2.filter((w, i) => !(FILLER.has(w) && words2.slice(0, i).every((p) => FILLER.has(p))));
28150
+ const first = lead[0];
28151
+ return first !== void 0 && ACTION_VERBS.has(first) && verbs.length >= 2 && hasSensitive;
28152
+ }
28153
+ function checkPathSegment(name) {
28154
+ if (name.length === 0) return null;
28155
+ if (CONTROL.test(name) || findHiddenUnicode(name).length > 0) {
28156
+ return { kind: "hidden-chars", span: escapePathSpan(name) };
28157
+ }
28158
+ if (readsAsInstruction(nameWords(name))) return { kind: "instruction", span: escapePathSpan(name) };
28159
+ return null;
28160
+ }
28161
+
27377
28162
  // ../core/src/scanner/orchestrator.ts
27378
28163
  init_heuristic_engine();
27379
28164
 
@@ -27776,7 +28561,7 @@ function stripJsonc(text) {
27776
28561
  }
27777
28562
  return out.replace(/,(\s*[}\]])/g, "$1");
27778
28563
  }
27779
- function parseJsonLoose(text) {
28564
+ function parseJsonLoose2(text) {
27780
28565
  try {
27781
28566
  return JSON.parse(text);
27782
28567
  } catch {
@@ -27831,7 +28616,7 @@ function serverEntries(servers) {
27831
28616
  function parseMcpConfig(rel, role, text) {
27832
28617
  if (role !== "mcp-config" && !(role === "config" && /\.jsonc?$/i.test(rel))) return null;
27833
28618
  if (role === "config" && !text.includes("mcpServers")) return null;
27834
- const top = Obj.safeParse(parseJsonLoose(text));
28619
+ const top = Obj.safeParse(parseJsonLoose2(text));
27835
28620
  if (!top.success) return null;
27836
28621
  const doc = top.data;
27837
28622
  const entries = [];
@@ -28005,6 +28790,34 @@ async function trifectaReport(root, configs, rules, defs) {
28005
28790
  });
28006
28791
  return { map: { configs: maps }, findings, notes: note ? [note] : [] };
28007
28792
  }
28793
+ async function* pathNameFindings(root, def) {
28794
+ const seen = /* @__PURE__ */ new Set();
28795
+ try {
28796
+ for await (const p of walkPaths(root)) {
28797
+ const segments = p.rel.split("/");
28798
+ for (let i = 0; i < segments.length; i++) {
28799
+ const prefix = segments.slice(0, i + 1).join("/");
28800
+ if (seen.has(prefix)) continue;
28801
+ seen.add(prefix);
28802
+ const hit = checkPathSegment(segments[i] ?? "");
28803
+ if (!hit) continue;
28804
+ yield {
28805
+ source: "signature",
28806
+ ruleId: def.id,
28807
+ title: def.title,
28808
+ severity: def.severity,
28809
+ file: prefix,
28810
+ line: 1,
28811
+ col: 1,
28812
+ span: hit.span,
28813
+ owasp: def.owasp,
28814
+ fix: def.fix
28815
+ };
28816
+ }
28817
+ }
28818
+ } catch {
28819
+ }
28820
+ }
28008
28821
  async function* scanRepo(root, options) {
28009
28822
  const defs = await loadDefinitions(options.definitionsDir);
28010
28823
  const canaries = loadCanariesFile(canariesPath(root));
@@ -28055,7 +28868,8 @@ async function* scanRepo(root, options) {
28055
28868
  const sigs = runSignatures(file, norm, defs);
28056
28869
  const heurs = options.bedrockClient ? await runHeuristics(file, norm, sigs, options.bedrockClient) : [];
28057
28870
  const traps = canaryFindings(text, file.rel, records, ex022);
28058
- let deduped = deduplicate([...sigs, ...heurs, ...traps]);
28871
+ const sourceTools = (file.role === "code" || file.role === "unknown") && languageOf(file.rel) !== null ? scanSourceTools(file, text, defs) : [];
28872
+ let deduped = deduplicate([...sigs, ...heurs, ...traps, ...sandboxFindings(text, file.rel), ...sourceTools]);
28059
28873
  if (checkVault && deduped.length > 0 && file.rel.includes(".exorcist/vault/")) {
28060
28874
  const backup = checkVault(file.rel, await readFile3(file.path));
28061
28875
  if (backup) deduped = deduped.map((f) => asBackupFinding(f, backup));
@@ -28083,6 +28897,13 @@ async function* scanRepo(root, options) {
28083
28897
  yield { type: "error", file: "capabilities.yaml", message: capabilities.error };
28084
28898
  }
28085
28899
  }
28900
+ const ex029 = defs.find((d) => d.id === "EX-029" && d.enabled !== false && d.match.analysis === "path-names");
28901
+ if (ex029) {
28902
+ for await (const finding of pathNameFindings(root, ex029)) {
28903
+ findingsTotal++;
28904
+ yield { type: "finding", finding };
28905
+ }
28906
+ }
28086
28907
  yield {
28087
28908
  type: "done",
28088
28909
  stats: {
@@ -28094,12 +28915,6 @@ async function* scanRepo(root, options) {
28094
28915
  };
28095
28916
  }
28096
28917
 
28097
- // ../core/src/scanner/scan-text.ts
28098
- function scanText(text, role, defs, label = "(text)", limitMs = REGEX_TIME_LIMIT_MS) {
28099
- const file = { path: label, rel: label, role, sizeBytes: text.length };
28100
- return runSignatures(file, normalize(text, role), defs, limitMs);
28101
- }
28102
-
28103
28918
  // ../core/src/reporters/json-reporter.ts
28104
28919
  init_zod();
28105
28920
 
@@ -28170,6 +28985,11 @@ var FindingSchema = external_exports.object({
28170
28985
  owasp: external_exports.array(external_exports.string()),
28171
28986
  fix: external_exports.string()
28172
28987
  }).passthrough();
28988
+ var SuppressedSchema = external_exports.object({
28989
+ baseline: external_exports.number().int().nonnegative(),
28990
+ inline: external_exports.array(external_exports.object({ ruleId: external_exports.string(), file: external_exports.string(), line: external_exports.number(), reason: external_exports.string() })),
28991
+ rejected: external_exports.array(external_exports.object({ ruleId: external_exports.string(), file: external_exports.string(), line: external_exports.number(), cause: external_exports.string() }))
28992
+ });
28173
28993
  var ScanReportSchema = external_exports.object({
28174
28994
  version: external_exports.literal("1"),
28175
28995
  createdAt: external_exports.string().datetime(),
@@ -28178,7 +28998,9 @@ var ScanReportSchema = external_exports.object({
28178
28998
  scanner: external_exports.object({ name: external_exports.string(), version: external_exports.string() }).optional(),
28179
28999
  target: external_exports.string().optional(),
28180
29000
  stats: ScanStatsSchema,
28181
- findings: external_exports.array(FindingSchema)
29001
+ findings: external_exports.array(FindingSchema),
29002
+ // Findings hidden by the baseline or inline directives. Optional (m9).
29003
+ suppressed: SuppressedSchema.optional()
28182
29004
  });
28183
29005
 
28184
29006
  // ../core/src/plain.ts
@@ -28275,6 +29097,38 @@ var ENTRIES = {
28275
29097
  headline: "Together, these tool servers can leak your secrets",
28276
29098
  attack: 'Each tool server looks harmless alone. But one agent session that can read private data, read text anyone can write (a web page, an issue, an email) and send data somewhere can be told by that text to copy your secrets out. This is the "lethal trifecta".'
28277
29099
  },
29100
+ "EX-028": {
29101
+ headline: "Text you cannot see is giving your AI orders",
29102
+ attack: "A page or file contains text that is styled to be invisible (white, tiny, off-screen or hidden) but a model still reads it. Here it talks to the AI or tells it to write, run, fetch or send something. This is how a web page can try to steer an agent that was only asked to summarise it."
29103
+ },
29104
+ "EX-029": {
29105
+ headline: "A file or folder name is giving your AI orders",
29106
+ attack: 'The name of a file or folder reads like an instruction ("ignore previous instructions...") or hides invisible characters. An agent that lists the project reads every name, so a name alone can steer it.'
29107
+ },
29108
+ "EX-030": {
29109
+ headline: "This text asks your AI to change its own settings or guards",
29110
+ attack: "A file tells the agent to add a wildcard to its trusted commands, switch on auto-approve, or edit its hooks, custom agents, steering files or AGENTS.md. If the agent obeys, it stops asking you before it runs commands, and the change stays after the poisoned file is gone."
29111
+ },
29112
+ "EX-031": {
29113
+ headline: "This text tells your AI to skip, delete or weaken your tests and checks",
29114
+ attack: 'A file tells the agent to add .skip to tests, delete a test file as "flaky", commit with --no-verify, add "|| true" to a CI step, lower a coverage threshold, or make a failing check pass without fixing it. A bad change then gets through because the checks no longer catch it.'
29115
+ },
29116
+ "EX-032": {
29117
+ headline: "This text tells your AI to send your code somewhere else",
29118
+ attack: "A file tells the agent to push to a remote that is not your origin, add a new remote, publish a package, switch the package registry, or open a pull request against another repository. If the agent obeys, your code or a poisoned package leaves your control."
29119
+ },
29120
+ "EX-033": {
29121
+ headline: "This settings file lets your AI run any command without asking you",
29122
+ attack: "A committed settings file lists a wildcard or a bare shell name as trusted (Kiro trusted commands, Claude Code or Cursor allow rules). Whoever wrote the file decides that the agent never asks before running a command, so a poisoned file elsewhere in the project can then run anything on your machine."
29123
+ },
29124
+ "EX-034": {
29125
+ headline: "This settings file lets Copilot run any terminal command without asking you",
29126
+ attack: "The terminal auto-approve map in a committed settings file marks a pattern that matches every command as approved. The agent then runs commands without showing you a prompt."
29127
+ },
29128
+ "EX-035": {
29129
+ headline: "This project file switches off the sandbox around your AI tool servers",
29130
+ attack: "A committed Kiro sandbox file turns MCP sandboxing, or the whole command sandbox, off, so local tool servers run without the operating-system boundary. This is only information: a project file can only tighten your global sandbox policy, so your global setting may still apply."
29131
+ },
28278
29132
  "EX-027": {
28279
29133
  headline: "Your AI read untrusted text and private data, and now wants to send something out",
28280
29134
  attack: "Earlier in this session your AI read text anyone can write (a web page, an issue, a message) and then private data (a secrets file, a key). Each step looked harmless. Sending data out now is exactly how a prompt injection steals it, so the Shield holds the call until you say yes."
@@ -28299,6 +29153,11 @@ function plainFor(ruleId, fallbackTitle) {
28299
29153
  };
28300
29154
  }
28301
29155
 
29156
+ // ../core/src/plural.ts
29157
+ function plural(n, one, many = `${one}s`) {
29158
+ return `${n} ${n === 1 ? one : many}`;
29159
+ }
29160
+
28302
29161
  // ../core/src/exorcise.ts
28303
29162
  init_walker();
28304
29163
  var RULE_CLASSES = {
@@ -28398,7 +29257,33 @@ var AllowedReadsSchema = external_exports.object({ version: external_exports.lit
28398
29257
  init_walker();
28399
29258
  var MAX_SCAN_BYTES = 10 * 1048576;
28400
29259
 
29260
+ // ../core/src/mcp-write-guard.ts
29261
+ var MAX_READ_BYTES = 2 * 1024 * 1024;
29262
+
29263
+ // ../core/src/web-fetch-guard.ts
29264
+ init_zod();
29265
+ init_canary();
29266
+ var EventSchema = external_exports.object({
29267
+ tool_name: external_exports.string().optional(),
29268
+ tool_input: external_exports.record(external_exports.unknown())
29269
+ });
29270
+
29271
+ // ../core/src/env-write-guard.ts
29272
+ init_zod();
29273
+ var EventSchema2 = external_exports.object({
29274
+ tool_name: external_exports.string().optional(),
29275
+ tool_input: external_exports.record(external_exports.unknown())
29276
+ });
29277
+ var MAX_TEXT_CHARS = 2 * 1024 * 1024;
29278
+
29279
+ // ../core/src/env-values.ts
29280
+ var MAX_ENV_FILE_BYTES = 256 * 1024;
29281
+
29282
+ // ../core/src/gate.ts
29283
+ init_walker();
29284
+
28401
29285
  // ../core/src/index.ts
29286
+ init_walker();
28402
29287
  init_heuristic_engine();
28403
29288
  init_walker();
28404
29289
 
@@ -28560,6 +29445,41 @@ init_zod();
28560
29445
  var NpmLatest = external_exports.object({ version: external_exports.string().max(100) });
28561
29446
  var PypiProject = external_exports.object({ info: external_exports.object({ version: external_exports.string().max(100) }) });
28562
29447
 
29448
+ // ../core/src/baseline.ts
29449
+ init_zod();
29450
+ var BASELINE_VERSION = 1;
29451
+ var BaselineEntrySchema = external_exports.object({
29452
+ ruleId: external_exports.string().min(1),
29453
+ file: external_exports.string().min(1),
29454
+ fingerprint: external_exports.string().regex(/^[0-9a-f]{32}$/),
29455
+ line: external_exports.number().int().min(0)
29456
+ }).strict();
29457
+ var BaselineSchema = external_exports.object({
29458
+ version: external_exports.literal(BASELINE_VERSION),
29459
+ entries: external_exports.array(BaselineEntrySchema)
29460
+ }).strict();
29461
+
29462
+ // ../core/src/kiro-evidence.ts
29463
+ init_zod();
29464
+ var KiroEventSchema = external_exports.object({
29465
+ id: external_exports.string(),
29466
+ timestamp: external_exports.string(),
29467
+ payload: external_exports.object({ type: external_exports.string() }).passthrough()
29468
+ }).passthrough();
29469
+ var CRED_KEY = "(?:(?<![A-Za-z])|(?<=\\\\[nrt]))(?<key>aws_secret_access_key|aws_access_key_id|aws_session_token|password|_authToken)";
29470
+ var CRED_DELIMITED_SOURCE = `${CRED_KEY}(?<sep>(?:\\\\*["'])?[ \\t]*[=:][ \\t]*)(?:(?<q>\\\\*["'])(?<quoted>[^"'\\\\]{4,})|(?<bare>[^\\s"'\\\\,;}]{4,}))`;
29471
+ var DROP = Symbol("drop");
29472
+ var SessionJsonSchema = external_exports.object({
29473
+ id: external_exports.string().optional(),
29474
+ title: external_exports.string().optional(),
29475
+ agentMode: external_exports.string().optional(),
29476
+ createdAt: external_exports.string().optional(),
29477
+ lastModifiedAt: external_exports.string().optional(),
29478
+ modelId: external_exports.string().optional(),
29479
+ autopilot: external_exports.boolean().optional(),
29480
+ approveForMe: external_exports.boolean().optional()
29481
+ }).passthrough();
29482
+
28563
29483
  // ../shield/src/paraphrase.ts
28564
29484
  var W = String.raw`[\s\W_]{0,3}`;
28565
29485
  var words = (...ws) => ws.join(`${W}`);
@@ -28592,7 +29512,7 @@ var SET_ASIDE = any(
28592
29512
  "(?:do\\W{0,3}not|don'?t|stop|no\\W{0,3}longer)\\W{0,3}(?:follow(?:ing)?|obey(?:ing)?|listen(?:ing)?\\W{0,3}to|heed(?:ing)?|honou?r(?:ing)?)"
28593
29513
  );
28594
29514
  var PREVIOUS = any("previous", "prior", "earlier", "above", "preceding", "foregoing", "original", "initial", "system", "developer", "your", "all");
28595
- var FILLER = any("the", "any", "every", "of", "old", "existing", "current", "default", "these", "those", "such", "other");
29515
+ var FILLER2 = any("the", "any", "every", "of", "old", "existing", "current", "default", "these", "those", "such", "other");
28596
29516
  var ORDERS = any(
28597
29517
  "instructions?",
28598
29518
  "directions?",
@@ -28621,8 +29541,8 @@ var BEFORE = any(
28621
29541
  "the\\W{0,3}(?:conversation|chat)\\W{0,3}so\\W{0,3}far",
28622
29542
  "your\\W{0,3}(?:task|job|instructions)"
28623
29543
  );
28624
- var OVERRIDE = [
28625
- new RegExp(`\\b${SET_ASIDE}${W}(?:${FILLER}${W}){0,2}${PREVIOUS}${W}(?:${any(FILLER, PREVIOUS)}${W}){0,2}${ORDERS}\\b`, "i"),
29544
+ var OVERRIDE3 = [
29545
+ new RegExp(`\\b${SET_ASIDE}${W}(?:${FILLER2}${W}){0,2}${PREVIOUS}${W}(?:${any(FILLER2, PREVIOUS)}${W}){0,2}${ORDERS}\\b`, "i"),
28626
29546
  new RegExp(`\\b${SET_ASIDE}${W}${BEFORE}`, "i"),
28627
29547
  new RegExp(`\\b${any("new", "updated", "revised", "real", "actual", "true", "secret", "hidden", "important", "priority", "urgent", "override")}${W}${any("instructions?", "task", "objective", "directives?", "mission", "orders?", "goal")}${W}(?:is|are|:|for\\W{0,3}(?:you|the\\W{0,3}(?:assistant|ai|agent|model)))`, "i"),
28628
29548
  new RegExp(`\\b${words("your", any("real", "actual", "true", "new", "only"), any("task", "job", "goal", "purpose", "instructions?", "mission"))}${W}(?:is|are|now)\\b`, "i"),
@@ -28636,7 +29556,7 @@ var CONCEAL = [
28636
29556
  new RegExp(`\\b${any("silently", "quietly", "covertly", "secretly", "discreetly", "invisibly", "in\\W{0,3}the\\W{0,3}background", "behind\\W{0,3}the\\W{0,3}scenes")}${W}${any("send", "upload", "post", "run", "execute", "call", "forward", "copy", "include", "attach", "email", "transmit")}`, "i"),
28637
29557
  new RegExp(`\\b${any("the\\W{0,3}user\\W{0,3}(?:must|should)\\W{0,3}not\\W{0,3}(?:know|see|find\\W{0,3}out)", "hide\\W{0,3}(?:this|it)\\W{0,3}from")}`, "i")
28638
29558
  ];
28639
- var SENSITIVE = any(
29559
+ var SENSITIVE2 = any(
28640
29560
  "\\.env\\b",
28641
29561
  "env(?:ironment)?\\W{0,3}(?:file|variables?|vars)",
28642
29562
  "credentials?",
@@ -28668,8 +29588,8 @@ var SENSITIVE = any(
28668
29588
  "system\\W{0,3}prompt"
28669
29589
  );
28670
29590
  var SEND = any("send", "post", "upload", "transmit", "forward", "e-?mail", "share", "exfiltrate", "leak", "submit", "paste", "copy", "include", "attach", "append", "embed", "encode", "write", "dump", "print", "reveal", "output", "return", "read");
28671
- var ACTION = [
28672
- new RegExp(`\\b${SEND}${W}(?:(?:the|all|any|every|your|my|their|of|full|entire|contents?|values?)${W}){0,4}${SENSITIVE}`, "i"),
29591
+ var ACTION2 = [
29592
+ new RegExp(`\\b${SEND}${W}(?:(?:the|all|any|every|your|my|their|of|full|entire|contents?|values?)${W}){0,4}${SENSITIVE2}`, "i"),
28673
29593
  new RegExp(`\\b${any("run", "execute", "exec", "eval", "invoke", "type", "enter", "paste")}${W}(?:this|the\\W{0,3}following|these)?${W}?(?:command|script|code|line)?s?${W}?[:\`'"]?${W}?${any("curl", "wget", "bash", "sh\\W{0,3}-c", "zsh", "powershell", "iex", "invoke-expression", "rm\\W{0,3}-rf", "chmod", "base64\\W{0,3}-d", "nc\\W", "ncat", "python\\W{0,3}-c", "node\\W{0,3}-e", "eval")}`, "i"),
28674
29594
  new RegExp(`\\b${any("curl", "wget")}\\b[^\\n]{0,120}\\|\\s*(?:ba|z)?sh\\b`, "i"),
28675
29595
  new RegExp(`\\b${any("call", "use", "invoke", "trigger")}${W}(?:the${W})?[\\w.-]{2,40}${W}tool${W}${any("with", "to\\W{0,3}send", "to\\W{0,3}upload", "to\\W{0,3}delete", "to\\W{0,3}write")}`, "i"),
@@ -28916,9 +29836,99 @@ function quarantineServer(o) {
28916
29836
 
28917
29837
  // ../shield/src/events.ts
28918
29838
  init_zod();
29839
+
29840
+ // ../shield/src/chain.ts
29841
+ init_zod();
29842
+
29843
+ // ../shield/src/chain-core.ts
29844
+ init_zod();
29845
+
29846
+ // ../shield/src/sha256.ts
29847
+ var K = new Uint32Array([
29848
+ 1116352408,
29849
+ 1899447441,
29850
+ 3049323471,
29851
+ 3921009573,
29852
+ 961987163,
29853
+ 1508970993,
29854
+ 2453635748,
29855
+ 2870763221,
29856
+ 3624381080,
29857
+ 310598401,
29858
+ 607225278,
29859
+ 1426881987,
29860
+ 1925078388,
29861
+ 2162078206,
29862
+ 2614888103,
29863
+ 3248222580,
29864
+ 3835390401,
29865
+ 4022224774,
29866
+ 264347078,
29867
+ 604807628,
29868
+ 770255983,
29869
+ 1249150122,
29870
+ 1555081692,
29871
+ 1996064986,
29872
+ 2554220882,
29873
+ 2821834349,
29874
+ 2952996808,
29875
+ 3210313671,
29876
+ 3336571891,
29877
+ 3584528711,
29878
+ 113926993,
29879
+ 338241895,
29880
+ 666307205,
29881
+ 773529912,
29882
+ 1294757372,
29883
+ 1396182291,
29884
+ 1695183700,
29885
+ 1986661051,
29886
+ 2177026350,
29887
+ 2456956037,
29888
+ 2730485921,
29889
+ 2820302411,
29890
+ 3259730800,
29891
+ 3345764771,
29892
+ 3516065817,
29893
+ 3600352804,
29894
+ 4094571909,
29895
+ 275423344,
29896
+ 430227734,
29897
+ 506948616,
29898
+ 659060556,
29899
+ 883997877,
29900
+ 958139571,
29901
+ 1322822218,
29902
+ 1537002063,
29903
+ 1747873779,
29904
+ 1955562222,
29905
+ 2024104815,
29906
+ 2227730452,
29907
+ 2361852424,
29908
+ 2428436474,
29909
+ 2756734187,
29910
+ 3204031479,
29911
+ 3329325298
29912
+ ]);
29913
+
29914
+ // ../shield/src/chain-core.ts
29915
+ var HEX64 = /^[0-9a-f]{64}$/;
29916
+ var HeadRecordSchema = external_exports.object({
29917
+ v: external_exports.literal(1),
29918
+ genesis: external_exports.string().regex(HEX64),
29919
+ seq: external_exports.number().int().positive(),
29920
+ hash: external_exports.string().regex(HEX64)
29921
+ }).strict();
29922
+
29923
+ // ../shield/src/chain.ts
29924
+ var GenesisFileSchema = external_exports.object({ v: external_exports.literal(1), genesis: external_exports.string().regex(HEX64) }).strict();
29925
+ var CHUNK = 1 << 20;
29926
+
29927
+ // ../shield/src/events.ts
28919
29928
  var MAX_EVENT_BYTES = 1024 * 1024;
28920
29929
  var MAX_LINE_BYTES = 8 * 1024;
28921
- var MAX_READ_BYTES = 8 * 1024 * 1024;
29930
+ var MAX_READ_BYTES2 = 8 * 1024 * 1024;
29931
+ var HEX642 = /^[0-9a-f]{64}$/;
28922
29932
  var NAME_CHARS2 = 80;
28923
29933
  var WHY_CHARS = 400;
28924
29934
  var MESSAGE_CHARS = 600;
@@ -28932,7 +29942,11 @@ var Base = {
28932
29942
  time: Time2,
28933
29943
  pid: external_exports.number().int().positive(),
28934
29944
  server: Name2,
28935
- session: external_exports.string().regex(KEY_RE).optional()
29945
+ session: external_exports.string().regex(KEY_RE).optional(),
29946
+ /** Hash-chain fields (chain.ts). Absent on lines written before the chain existed or when the lock could not be taken. */
29947
+ seq: external_exports.number().int().positive().optional(),
29948
+ prev: external_exports.string().regex(HEX642).optional(),
29949
+ hash: external_exports.string().regex(HEX642).optional()
28936
29950
  };
28937
29951
  var StartEvent = external_exports.object({
28938
29952
  ...Base,
@@ -29033,7 +30047,8 @@ function isWrapped(entry) {
29033
30047
  }
29034
30048
 
29035
30049
  // src/tools.ts
29036
- import { basename as basename5, dirname as dirname3, isAbsolute as isAbsolute4, join as join10, relative as relative3, resolve as resolve5 } from "node:path";
30050
+ import { homedir as homedir2 } from "node:os";
30051
+ import { basename as basename5, dirname as dirname3, isAbsolute as isAbsolute4, join as join10, relative as relative3, resolve as resolve5, sep } from "node:path";
29037
30052
  var quotesWanted = (ctx2, asked) => asked === true && ctx2.noQuotes !== true;
29038
30053
  var RANK = { critical: 0, high: 1, medium: 2, low: 3 };
29039
30054
  var HIDDEN2 = /[\u200B-\u200D\uFEFF\u202A-\u202E\u2066-\u2069\u{E0000}-\u{E007F}]/gu;
@@ -29044,21 +30059,110 @@ function reveal(s) {
29044
30059
  function findDefinitionsDir2(cwd) {
29045
30060
  return findDefinitionsDir({ callerUrl: import.meta.url, cwd });
29046
30061
  }
29047
- function resolveInside(cwd, p, roots = []) {
29048
- const bases = [realpathSync(cwd), ...roots.filter((r) => existsSync3(r)).map((r) => realpathSync(r))];
30062
+ function resolveInside(cwd, p, roots = [], primary) {
30063
+ const real = (d) => realpathSync(d);
30064
+ const extra = roots.filter((r) => existsSync3(r)).map(real);
30065
+ const first = primary !== void 0 && extra.includes(real(primary)) ? [real(primary)] : [];
30066
+ const bases = [.../* @__PURE__ */ new Set([...first, real(cwd), ...extra])];
29049
30067
  const tries = isAbsolute4(p) ? [p] : bases.map((b) => resolve5(b, p));
29050
30068
  const found = tries.find((t) => existsSync3(t));
29051
30069
  if (!found) return { ok: false, error: `Path not found: ${p}` };
29052
- const real = realpathSync(found);
30070
+ const target = realpathSync(found);
29053
30071
  const base = bases.find((b) => {
29054
- const rel = relative3(b, real);
30072
+ const rel = relative3(b, target);
29055
30073
  return !rel.startsWith("..") && !isAbsolute4(rel);
29056
30074
  });
29057
30075
  if (!base) {
29058
30076
  const where = bases.length > 1 ? `the project folder (${bases[0]}) or the folders your client shared` : `the project folder (${bases[0]})`;
29059
- return { ok: false, error: `"${p}" is outside ${where}. Only paths inside ${bases.length > 1 ? "them" : "it"} can be used.` };
30077
+ return { ok: false, outside: true, error: `"${p}" is outside ${where}. Only paths inside ${bases.length > 1 ? "them" : "it"} can be used.` };
30078
+ }
30079
+ return { ok: true, path: target, base };
30080
+ }
30081
+ var PROJECT_MARKERS = [
30082
+ ".git",
30083
+ ".kiro",
30084
+ ".claude",
30085
+ ".cursor",
30086
+ ".vscode",
30087
+ ".mcp.json",
30088
+ "mcp.json",
30089
+ "package.json",
30090
+ "pyproject.toml",
30091
+ "requirements.txt",
30092
+ "Cargo.toml",
30093
+ "go.mod",
30094
+ "pom.xml",
30095
+ "build.gradle",
30096
+ "Gemfile",
30097
+ "composer.json",
30098
+ "AGENTS.md",
30099
+ "CLAUDE.md",
30100
+ "README.md",
30101
+ "README"
30102
+ ];
30103
+ function looksLikeProject(dir) {
30104
+ const has = (n) => existsSync3(join10(dir, n));
30105
+ if (has("plugin.json") || has("POWER.md")) return false;
30106
+ return PROJECT_MARKERS.some(has);
30107
+ }
30108
+ var SENSITIVE_IN_HOME = [".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", ".config", ".password-store", join10("Library", "Keychains")];
30109
+ var SENSITIVE_ABSOLUTE = ["/etc", "/private/etc", "/System", "/var/root", "/root"];
30110
+ var isWithin = (base, p) => {
30111
+ const rel = relative3(base, p);
30112
+ return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
30113
+ };
30114
+ function sensitiveReason(real, home = homedir2()) {
30115
+ const realHome = existsSync3(home) ? realpathSync(home) : home;
30116
+ if (dirname3(real) === real) return "it is the filesystem root";
30117
+ if (isWithin(real, realHome)) return real === realHome ? "it is the home folder" : "it contains the home folder";
30118
+ for (const n of SENSITIVE_IN_HOME) {
30119
+ const s = join10(realHome, n);
30120
+ if (isWithin(s, real) || isWithin(real, s)) return `it holds credentials or settings (${n.split(sep)[0]})`;
30121
+ }
30122
+ for (const s of SENSITIVE_ABSOLUTE) if (isWithin(s, real)) return "it is a system folder";
30123
+ return null;
30124
+ }
30125
+ var printable2 = (s) => s.replace(/[\u0000-\u001F\u007F-\u009F\u200B-\u200F\u2028\u2029\u202A-\u202E\u2066-\u2069\uFEFF\u{E0000}-\u{E007F}]/gu, (c) => `[U+${(c.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0")}]`);
30126
+ function approvalMessage(folder) {
30127
+ const shown = printable2(folder);
30128
+ const where = shown.length > 300 ? `${shown.slice(0, 300)}...` : shown;
30129
+ return `Allow Exorcist 98 to read the folder ${where} for this session? It can scan the files in it, and disable MCP servers in its config files only if you ask. The permission ends when the server stops.`;
30130
+ }
30131
+ var FIXES = "Either set EXORCIST_ROOTS to the absolute path of the project folder in the env of the exorcist MCP server, or add the exorcist server to the workspace .kiro/settings/mcp.json, where Kiro starts it in the project folder.";
30132
+ function noProjectError(ctx2, p, inside2) {
30133
+ if (inside2.outside || isAbsolute4(p) || (ctx2.roots?.length ?? 0) > 0 || looksLikeProject(ctx2.cwd)) return null;
30134
+ const how = ctx2.ask ? "Call the tool again with the absolute path of the project folder; the person will be asked to allow it for this session. Other fixes: set EXORCIST_ROOTS to that folder in the env of the exorcist MCP server, or add the exorcist server to the workspace .kiro/settings/mcp.json, where Kiro starts it in the project folder." : FIXES;
30135
+ return `No project folder is known, so "${p}" was not scanned. This server was started in ${ctx2.cwd}, which is not a project, and the client did not share a workspace folder (MCP roots). Nothing was checked. ${how} Do not report this as a clean scan.`;
30136
+ }
30137
+ async function resolveAllowed(ctx2, p) {
30138
+ const first = resolveInside(ctx2.cwd, p, ctx2.roots, ctx2.base);
30139
+ if (first.ok || !first.outside || !isAbsolute4(p)) return first;
30140
+ const noRoots = (ctx2.roots?.length ?? 0) === 0;
30141
+ if (!ctx2.ask) {
30142
+ return noRoots && !looksLikeProject(ctx2.cwd) ? { ...first, error: `${first.error} No project folder is known. ${FIXES}` } : first;
30143
+ }
30144
+ let folder;
30145
+ try {
30146
+ const real = realpathSync(p);
30147
+ folder = statSync4(real).isDirectory() ? real : dirname3(real);
30148
+ } catch {
30149
+ return first;
30150
+ }
30151
+ const refused = sensitiveReason(folder, ctx2.home);
30152
+ if (refused) return { ok: false, outside: true, error: `${printable2(folder)} cannot be allowed: ${refused}.` };
30153
+ let yes = false;
30154
+ try {
30155
+ yes = await ctx2.ask(folder) === true;
30156
+ } catch {
30157
+ yes = false;
30158
+ }
30159
+ if (!yes) {
30160
+ return { ok: false, outside: true, error: `The person did not allow Exorcist 98 to read ${printable2(folder)}, so nothing was read. Do not ask again unless the user requests it.` };
29060
30161
  }
29061
- return { ok: true, path: real, base };
30162
+ ctx2.approved = [...ctx2.approved ?? [], folder];
30163
+ ctx2.roots = [...ctx2.roots ?? [], folder];
30164
+ ctx2.base ??= folder;
30165
+ return resolveInside(ctx2.cwd, p, ctx2.roots, ctx2.base);
29062
30166
  }
29063
30167
  function usableRoots(entries, home) {
29064
30168
  const out = [];
@@ -29111,12 +30215,15 @@ function describe(findings, limit, quotes) {
29111
30215
  return lines.join("\n");
29112
30216
  }
29113
30217
  function summary(findings, files) {
29114
- if (findings.length === 0) return `No threats found in ${files} files.`;
30218
+ if (findings.length === 0) return `No threats found. Scanned ${plural(files, "file")}.`;
29115
30219
  const counts = ["critical", "high", "medium", "low"].map((s) => ({ s, n: findings.filter((f) => f.severity === s).length })).filter((c) => c.n > 0).map((c) => `${c.n} ${c.s}`).join(", ");
29116
- return `${findings.length} threat${findings.length === 1 ? "" : "s"} in ${files} files (${counts}).`;
30220
+ const withFindings = new Set(findings.map((f) => f.file)).size;
30221
+ return `${plural(findings.length, "threat")} in ${plural(withFindings, "file")} (${counts}). Scanned ${plural(files, "file")}.`;
29117
30222
  }
29118
30223
  async function scanRepoTool(ctx2, a) {
29119
- const inside2 = resolveInside(ctx2.cwd, a.path, ctx2.roots);
30224
+ const inside2 = await resolveAllowed(ctx2, a.path);
30225
+ const none = noProjectError(ctx2, a.path, inside2);
30226
+ if (none) return err(none);
29120
30227
  if (!inside2.ok) return err(inside2.error);
29121
30228
  const defs = await loadDefs(ctx2);
29122
30229
  if (!defs.ok) return err(defs.error);
@@ -29134,7 +30241,9 @@ async function scanRepoTool(ctx2, a) {
29134
30241
  return { text: [summary(findings, files), quotes ? UNTRUSTED : "", describe(findings, limit, quotes)].filter(Boolean).join("\n") };
29135
30242
  }
29136
30243
  async function scanMcpConfigTool(ctx2, a) {
29137
- const inside2 = resolveInside(ctx2.cwd, a.path, ctx2.roots);
30244
+ const inside2 = await resolveAllowed(ctx2, a.path);
30245
+ const none = noProjectError(ctx2, a.path, inside2);
30246
+ if (none) return err(none);
29138
30247
  if (!inside2.ok) return err(inside2.error);
29139
30248
  if (!statSync4(inside2.path).isFile()) return err(`${a.path} is a folder. Give the path of an MCP config file.`);
29140
30249
  const defs = await loadDefs(ctx2);
@@ -29177,13 +30286,15 @@ async function explainFindingTool(ctx2, a) {
29177
30286
  return { text: lines.join("\n") };
29178
30287
  }
29179
30288
  async function quarantineTool(ctx2, a) {
29180
- const inside2 = resolveInside(ctx2.cwd, a.config, ctx2.roots);
30289
+ const inside2 = await resolveAllowed(ctx2, a.config);
30290
+ const none = noProjectError(ctx2, a.config, inside2);
30291
+ if (none) return err(none);
29181
30292
  if (!inside2.ok) return err(inside2.error);
29182
30293
  const r = quarantineServer({
29183
30294
  configPath: inside2.path,
29184
30295
  serverName: a.server,
29185
30296
  reason: a.reason?.slice(0, 200) ?? "quarantined from an AI agent request",
29186
- vaultDir: join10(realpathSync(ctx2.cwd), ".exorcist", "vault")
30297
+ vaultDir: join10(inside2.base, ".exorcist", "vault")
29187
30298
  });
29188
30299
  if (!r.ok) return err(r.error);
29189
30300
  return {
@@ -29193,17 +30304,42 @@ Tell the user. They can undo this with: exorcist vault restore ${r.value.id}`
29193
30304
  }
29194
30305
 
29195
30306
  // src/index.ts
29196
- var VERSION = "0.1.2";
30307
+ var VERSION = "0.3.0";
29197
30308
  var ctx = {
29198
30309
  cwd: process.cwd(),
30310
+ approved: [],
29199
30311
  definitionsDir: findDefinitionsDir2(process.cwd()) ?? "",
29200
30312
  noQuotes: process.env["EXORCIST_MCP_NO_QUOTES"] === "1"
29201
30313
  };
29202
30314
  var reply = (r) => ({ content: [{ type: "text", text: r.text }], ...r.isError ? { isError: true } : {} });
29203
30315
  var server = new McpServer({ name: "exorcist", version: VERSION });
30316
+ var canAsk = () => {
30317
+ const e = server.server.getClientCapabilities()?.elicitation;
30318
+ return e !== void 0 && (e.form !== void 0 || e.url === void 0);
30319
+ };
30320
+ async function askPerson(folder) {
30321
+ try {
30322
+ const r = await server.server.elicitInput(
30323
+ {
30324
+ mode: "form",
30325
+ message: approvalMessage(folder),
30326
+ requestedSchema: {
30327
+ type: "object",
30328
+ properties: { allow: { type: "boolean", title: "Allow for this session", description: "Yes lets Exorcist 98 read this folder until the server stops. No reads nothing.", default: false } },
30329
+ required: ["allow"]
30330
+ }
30331
+ },
30332
+ { timeout: 12e4 }
30333
+ );
30334
+ return r.action === "accept" && r.content?.["allow"] === true;
30335
+ } catch {
30336
+ return false;
30337
+ }
30338
+ }
29204
30339
  var clientRoots = null;
29205
30340
  async function refreshRoots() {
29206
30341
  const fromEnv = (process.env["EXORCIST_ROOTS"] ?? "").split(delimiter);
30342
+ const home = homedir3();
29207
30343
  let fromClient = [];
29208
30344
  if (server.server.getClientCapabilities()?.roots) {
29209
30345
  if (clientRoots === null) {
@@ -29215,13 +30351,17 @@ async function refreshRoots() {
29215
30351
  }
29216
30352
  fromClient = clientRoots;
29217
30353
  }
29218
- ctx.roots = usableRoots([...fromEnv, ...fromClient], homedir2());
30354
+ const approved = ctx.approved ?? [];
30355
+ ctx.base = usableRoots(fromClient, home)[0] ?? usableRoots(fromEnv, home)[0] ?? approved[0];
30356
+ ctx.roots = usableRoots([...fromEnv, ...fromClient, ...approved], home);
29219
30357
  }
29220
30358
  server.server.setNotificationHandler(RootsListChangedNotificationSchema, async () => {
29221
30359
  clientRoots = null;
29222
30360
  });
29223
30361
  var withRoots = (fn) => async (a) => {
29224
30362
  await refreshRoots();
30363
+ if (canAsk()) ctx.ask = askPerson;
30364
+ else delete ctx.ask;
29225
30365
  return fn(ctx, a);
29226
30366
  };
29227
30367
  server.registerTool(
@@ -29230,7 +30370,7 @@ server.registerTool(
29230
30370
  title: "Scan a folder for attacks on AI agents",
29231
30371
  description: "Scan a folder or file inside the project for hidden instructions, poisoned tool descriptions, dangerous hooks and leaked secrets. Returns plain-language findings with file and line. Quoted text is left out unless includeQuotes is true.",
29232
30372
  inputSchema: {
29233
- path: external_exports.string().min(1).describe("Folder or file to scan, relative to the project folder"),
30373
+ path: external_exports.string().min(1).describe('Folder or file to scan, relative to the project folder (use "." for the whole project)'),
29234
30374
  maxFindings: external_exports.number().int().min(1).max(100).optional().describe("How many findings to list (default 25)"),
29235
30375
  includeQuotes: external_exports.boolean().optional().describe("Include the matched text, revealed and marked untrusted")
29236
30376
  },