@exorcist-98/cli 0.3.0 → 0.3.1
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/README.md +8 -8
- package/definitions/EX-036-lifecycle-script-exfiltration.yaml +27 -0
- package/dist/index.mjs +1207 -454
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4566,8 +4566,8 @@ var init_prompts = __esm({
|
|
|
4566
4566
|
|
|
4567
4567
|
// ../core/src/secrets-check.ts
|
|
4568
4568
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
4569
|
-
import { readFileSync as readFileSync3, statSync } from "node:fs";
|
|
4570
|
-
import { resolve as
|
|
4569
|
+
import { readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
|
|
4570
|
+
import { resolve as resolve3 } from "node:path";
|
|
4571
4571
|
function placeholderRanges(text) {
|
|
4572
4572
|
const ranges = [];
|
|
4573
4573
|
PLACEHOLDER_RE.lastIndex = 0;
|
|
@@ -4623,10 +4623,10 @@ function findStagedSecrets(cwd = process.cwd()) {
|
|
|
4623
4623
|
const hits = [];
|
|
4624
4624
|
let filesChecked = 0;
|
|
4625
4625
|
for (const name of names) {
|
|
4626
|
-
const full =
|
|
4626
|
+
const full = resolve3(root, name);
|
|
4627
4627
|
let text;
|
|
4628
4628
|
try {
|
|
4629
|
-
if (
|
|
4629
|
+
if (statSync2(full).size > MAX_BYTES2) continue;
|
|
4630
4630
|
const buf = readFileSync3(full);
|
|
4631
4631
|
if (buf.subarray(0, 512).includes(0)) continue;
|
|
4632
4632
|
text = buf.toString("utf8");
|
|
@@ -8539,7 +8539,7 @@ var require_compile = __commonJS({
|
|
|
8539
8539
|
const schOrFunc = root.refs[ref];
|
|
8540
8540
|
if (schOrFunc)
|
|
8541
8541
|
return schOrFunc;
|
|
8542
|
-
let _sch =
|
|
8542
|
+
let _sch = resolve31.call(this, root, ref);
|
|
8543
8543
|
if (_sch === void 0) {
|
|
8544
8544
|
const schema2 = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
8545
8545
|
const { schemaId } = this.opts;
|
|
@@ -8566,7 +8566,7 @@ var require_compile = __commonJS({
|
|
|
8566
8566
|
function sameSchemaEnv(s1, s2) {
|
|
8567
8567
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
8568
8568
|
}
|
|
8569
|
-
function
|
|
8569
|
+
function resolve31(root, ref) {
|
|
8570
8570
|
let sch;
|
|
8571
8571
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
8572
8572
|
ref = sch;
|
|
@@ -9430,7 +9430,7 @@ var require_fast_uri = __commonJS({
|
|
|
9430
9430
|
}
|
|
9431
9431
|
return uri;
|
|
9432
9432
|
}
|
|
9433
|
-
function
|
|
9433
|
+
function resolve31(baseURI, relativeURI, options) {
|
|
9434
9434
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
9435
9435
|
const {
|
|
9436
9436
|
parsed: baseParsed,
|
|
@@ -9466,50 +9466,50 @@ var require_fast_uri = __commonJS({
|
|
|
9466
9466
|
schemelessOptions.skipEscape = true;
|
|
9467
9467
|
return serialize(resolved, schemelessOptions);
|
|
9468
9468
|
}
|
|
9469
|
-
function resolveComponent(base,
|
|
9469
|
+
function resolveComponent(base, relative13, options, skipNormalization) {
|
|
9470
9470
|
const target = {};
|
|
9471
9471
|
if (!skipNormalization) {
|
|
9472
9472
|
base = parse6(serialize(base, options), options);
|
|
9473
|
-
|
|
9473
|
+
relative13 = parse6(serialize(relative13, options), options);
|
|
9474
9474
|
}
|
|
9475
9475
|
options = options || {};
|
|
9476
|
-
if (!options.tolerant &&
|
|
9477
|
-
target.scheme =
|
|
9478
|
-
target.userinfo =
|
|
9479
|
-
target.host =
|
|
9480
|
-
target.port =
|
|
9481
|
-
target.path = removeDotSegments(
|
|
9482
|
-
target.query =
|
|
9476
|
+
if (!options.tolerant && relative13.scheme) {
|
|
9477
|
+
target.scheme = relative13.scheme;
|
|
9478
|
+
target.userinfo = relative13.userinfo;
|
|
9479
|
+
target.host = relative13.host;
|
|
9480
|
+
target.port = relative13.port;
|
|
9481
|
+
target.path = removeDotSegments(relative13.path || "");
|
|
9482
|
+
target.query = relative13.query;
|
|
9483
9483
|
} else {
|
|
9484
|
-
if (
|
|
9485
|
-
target.userinfo =
|
|
9486
|
-
target.host =
|
|
9487
|
-
target.port =
|
|
9488
|
-
target.path = removeDotSegments(
|
|
9489
|
-
target.query =
|
|
9484
|
+
if (relative13.userinfo !== void 0 || relative13.host !== void 0 || relative13.port !== void 0) {
|
|
9485
|
+
target.userinfo = relative13.userinfo;
|
|
9486
|
+
target.host = relative13.host;
|
|
9487
|
+
target.port = relative13.port;
|
|
9488
|
+
target.path = removeDotSegments(relative13.path || "");
|
|
9489
|
+
target.query = relative13.query;
|
|
9490
9490
|
} else {
|
|
9491
|
-
if (!
|
|
9491
|
+
if (!relative13.path) {
|
|
9492
9492
|
target.path = base.path;
|
|
9493
|
-
if (
|
|
9494
|
-
target.query =
|
|
9493
|
+
if (relative13.query !== void 0) {
|
|
9494
|
+
target.query = relative13.query;
|
|
9495
9495
|
} else {
|
|
9496
9496
|
target.query = base.query;
|
|
9497
9497
|
}
|
|
9498
9498
|
} else {
|
|
9499
|
-
if (
|
|
9500
|
-
target.path = removeDotSegments(
|
|
9499
|
+
if (relative13.path[0] === "/") {
|
|
9500
|
+
target.path = removeDotSegments(relative13.path);
|
|
9501
9501
|
} else {
|
|
9502
9502
|
const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
|
|
9503
9503
|
if (baseHasAuthority && !base.path) {
|
|
9504
|
-
target.path = "/" +
|
|
9504
|
+
target.path = "/" + relative13.path;
|
|
9505
9505
|
} else if (!base.path) {
|
|
9506
|
-
target.path =
|
|
9506
|
+
target.path = relative13.path;
|
|
9507
9507
|
} else {
|
|
9508
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
9508
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative13.path;
|
|
9509
9509
|
}
|
|
9510
9510
|
target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
|
|
9511
9511
|
}
|
|
9512
|
-
target.query =
|
|
9512
|
+
target.query = relative13.query;
|
|
9513
9513
|
}
|
|
9514
9514
|
target.userinfo = base.userinfo;
|
|
9515
9515
|
target.host = base.host;
|
|
@@ -9517,7 +9517,7 @@ var require_fast_uri = __commonJS({
|
|
|
9517
9517
|
}
|
|
9518
9518
|
target.scheme = base.scheme;
|
|
9519
9519
|
}
|
|
9520
|
-
target.fragment =
|
|
9520
|
+
target.fragment = relative13.fragment;
|
|
9521
9521
|
return target;
|
|
9522
9522
|
}
|
|
9523
9523
|
function equal(uriA, uriB, options) {
|
|
@@ -9821,7 +9821,7 @@ var require_fast_uri = __commonJS({
|
|
|
9821
9821
|
var fastUri = {
|
|
9822
9822
|
SCHEMES,
|
|
9823
9823
|
normalize: normalize2,
|
|
9824
|
-
resolve:
|
|
9824
|
+
resolve: resolve31,
|
|
9825
9825
|
resolveComponent,
|
|
9826
9826
|
equal,
|
|
9827
9827
|
serialize,
|
|
@@ -12904,12 +12904,12 @@ var require_isexe = __commonJS({
|
|
|
12904
12904
|
if (typeof Promise !== "function") {
|
|
12905
12905
|
throw new TypeError("callback not provided");
|
|
12906
12906
|
}
|
|
12907
|
-
return new Promise(function(
|
|
12907
|
+
return new Promise(function(resolve31, reject) {
|
|
12908
12908
|
isexe(path, options || {}, function(er, is) {
|
|
12909
12909
|
if (er) {
|
|
12910
12910
|
reject(er);
|
|
12911
12911
|
} else {
|
|
12912
|
-
|
|
12912
|
+
resolve31(is);
|
|
12913
12913
|
}
|
|
12914
12914
|
});
|
|
12915
12915
|
});
|
|
@@ -12975,27 +12975,27 @@ var require_which = __commonJS({
|
|
|
12975
12975
|
opt = {};
|
|
12976
12976
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
12977
12977
|
const found = [];
|
|
12978
|
-
const step = (i) => new Promise((
|
|
12978
|
+
const step = (i) => new Promise((resolve31, reject) => {
|
|
12979
12979
|
if (i === pathEnv.length)
|
|
12980
|
-
return opt.all && found.length ?
|
|
12980
|
+
return opt.all && found.length ? resolve31(found) : reject(getNotFoundError(cmd));
|
|
12981
12981
|
const ppRaw = pathEnv[i];
|
|
12982
12982
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
12983
12983
|
const pCmd = path.join(pathPart, cmd);
|
|
12984
12984
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
12985
|
-
|
|
12985
|
+
resolve31(subStep(p, i, 0));
|
|
12986
12986
|
});
|
|
12987
|
-
const subStep = (p, i, ii) => new Promise((
|
|
12987
|
+
const subStep = (p, i, ii) => new Promise((resolve31, reject) => {
|
|
12988
12988
|
if (ii === pathExt.length)
|
|
12989
|
-
return
|
|
12989
|
+
return resolve31(step(i + 1));
|
|
12990
12990
|
const ext = pathExt[ii];
|
|
12991
12991
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
12992
12992
|
if (!er && is) {
|
|
12993
12993
|
if (opt.all)
|
|
12994
12994
|
found.push(p + ext);
|
|
12995
12995
|
else
|
|
12996
|
-
return
|
|
12996
|
+
return resolve31(p + ext);
|
|
12997
12997
|
}
|
|
12998
|
-
return
|
|
12998
|
+
return resolve31(subStep(p, i, ii + 1));
|
|
12999
12999
|
});
|
|
13000
13000
|
});
|
|
13001
13001
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -16452,7 +16452,8 @@ var MatchSchema = external_exports.object({
|
|
|
16452
16452
|
// `detonation` is the Detonation Chamber (EX-024, m5-detonation): a
|
|
16453
16453
|
// sandboxed model run, only with `--detonate`.
|
|
16454
16454
|
// `path-names` checks the names of every walked path (EX-029, path-names.ts).
|
|
16455
|
-
|
|
16455
|
+
// `lifecycle-scripts` follows a package.json lifecycle script into the local file it runs (EX-036, lifecycle-scripts.ts).
|
|
16456
|
+
analysis: external_exports.enum(["trifecta", "detonation", "path-names", "lifecycle-scripts"]).optional(),
|
|
16456
16457
|
// Text an element hides from a person by its style (EX-028, hidden-text.ts):
|
|
16457
16458
|
// reported only when the hidden text addresses the AI or asks for actions.
|
|
16458
16459
|
hidden_text: external_exports.boolean().optional(),
|
|
@@ -18558,7 +18559,7 @@ function skipArgument(text, p, lang, limit) {
|
|
|
18558
18559
|
}
|
|
18559
18560
|
return -1;
|
|
18560
18561
|
}
|
|
18561
|
-
function findKeyString(text, open3, lang, limit,
|
|
18562
|
+
function findKeyString(text, open3, lang, limit, sep6) {
|
|
18562
18563
|
let depth = 0;
|
|
18563
18564
|
let i = open3;
|
|
18564
18565
|
let lit = null;
|
|
@@ -18568,7 +18569,7 @@ function findKeyString(text, open3, lang, limit, sep3) {
|
|
|
18568
18569
|
};
|
|
18569
18570
|
const sepAt = (p) => {
|
|
18570
18571
|
const j = skipTrivia(text, p, lang, limit);
|
|
18571
|
-
if (text[j] !==
|
|
18572
|
+
if (text[j] !== sep6 || sep6 === "=" && text[j + 1] === "=") return -1;
|
|
18572
18573
|
return j + 1;
|
|
18573
18574
|
};
|
|
18574
18575
|
while (i < limit) {
|
|
@@ -18926,12 +18927,328 @@ function checkPathSegment(name) {
|
|
|
18926
18927
|
return null;
|
|
18927
18928
|
}
|
|
18928
18929
|
|
|
18930
|
+
// ../core/src/lifecycle-scripts.ts
|
|
18931
|
+
import { closeSync, existsSync, openSync, readSync, realpathSync, statSync } from "node:fs";
|
|
18932
|
+
import { isAbsolute as isAbsolute2, join as join5, relative as relative3, resolve as resolve2, sep } from "node:path";
|
|
18933
|
+
|
|
18934
|
+
// ../core/src/shell-words.ts
|
|
18935
|
+
var MAX_COMMAND_CHARS = 65536;
|
|
18936
|
+
var REDIRECT = /^\d*[<>]+&?\d*-?$/;
|
|
18937
|
+
var REDIRECT_WITH_TARGET = /^\d*[<>]+&?[^\s<>]/;
|
|
18938
|
+
function splitShell(command) {
|
|
18939
|
+
if (command.length > MAX_COMMAND_CHARS) return { ok: false };
|
|
18940
|
+
const segments = [];
|
|
18941
|
+
let words3 = [];
|
|
18942
|
+
let cur = "";
|
|
18943
|
+
let started = false;
|
|
18944
|
+
let quote = null;
|
|
18945
|
+
const endWord = () => {
|
|
18946
|
+
if (started) words3.push(cur);
|
|
18947
|
+
cur = "";
|
|
18948
|
+
started = false;
|
|
18949
|
+
};
|
|
18950
|
+
const endSegment = () => {
|
|
18951
|
+
endWord();
|
|
18952
|
+
const kept = [];
|
|
18953
|
+
for (let i = 0; i < words3.length; i++) {
|
|
18954
|
+
const w = words3[i] ?? "";
|
|
18955
|
+
if (REDIRECT.test(w)) {
|
|
18956
|
+
i += 1;
|
|
18957
|
+
continue;
|
|
18958
|
+
}
|
|
18959
|
+
if (REDIRECT_WITH_TARGET.test(w)) continue;
|
|
18960
|
+
kept.push(w);
|
|
18961
|
+
}
|
|
18962
|
+
if (kept.length > 0) segments.push(kept);
|
|
18963
|
+
words3 = [];
|
|
18964
|
+
};
|
|
18965
|
+
for (let i = 0; i < command.length; i++) {
|
|
18966
|
+
const c = command[i] ?? "";
|
|
18967
|
+
if (quote === "'") {
|
|
18968
|
+
if (c === "'") quote = null;
|
|
18969
|
+
else cur += c;
|
|
18970
|
+
continue;
|
|
18971
|
+
}
|
|
18972
|
+
if (quote === '"') {
|
|
18973
|
+
if (c === '"') quote = null;
|
|
18974
|
+
else if (c === "\\" && i + 1 < command.length && /["\\$`]/.test(command[i + 1] ?? "")) {
|
|
18975
|
+
cur += command[i + 1] ?? "";
|
|
18976
|
+
i += 1;
|
|
18977
|
+
} else cur += c;
|
|
18978
|
+
continue;
|
|
18979
|
+
}
|
|
18980
|
+
if (c === "\\") {
|
|
18981
|
+
if (i + 1 >= command.length) return { ok: false };
|
|
18982
|
+
cur += command[i + 1] ?? "";
|
|
18983
|
+
started = true;
|
|
18984
|
+
i += 1;
|
|
18985
|
+
} else if (c === "'" || c === '"') {
|
|
18986
|
+
quote = c;
|
|
18987
|
+
started = true;
|
|
18988
|
+
} else if (c === " " || c === " ") {
|
|
18989
|
+
endWord();
|
|
18990
|
+
} else if (c === ";" || c === "\n" || c === "|" || c === "&" || c === "(" || c === ")") {
|
|
18991
|
+
if (c === "&" && (/[<>]$/.test(cur) || command[i + 1] === ">")) {
|
|
18992
|
+
cur += c;
|
|
18993
|
+
started = true;
|
|
18994
|
+
continue;
|
|
18995
|
+
}
|
|
18996
|
+
endSegment();
|
|
18997
|
+
} else {
|
|
18998
|
+
cur += c;
|
|
18999
|
+
started = true;
|
|
19000
|
+
}
|
|
19001
|
+
}
|
|
19002
|
+
if (quote !== null) return { ok: false };
|
|
19003
|
+
endSegment();
|
|
19004
|
+
return { ok: true, segments };
|
|
19005
|
+
}
|
|
19006
|
+
function isPlainWord(word) {
|
|
19007
|
+
return word !== "" && !/[$`*?[\]{}]/.test(word) && !word.startsWith("~") && !word.includes("\0");
|
|
19008
|
+
}
|
|
19009
|
+
function stripPrefixes(words3) {
|
|
19010
|
+
let i = 0;
|
|
19011
|
+
for (; ; ) {
|
|
19012
|
+
const w = words3[i];
|
|
19013
|
+
if (w === void 0) break;
|
|
19014
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(w)) {
|
|
19015
|
+
i += 1;
|
|
19016
|
+
continue;
|
|
19017
|
+
}
|
|
19018
|
+
if (w === "env" || w === "sudo" || w === "time" || w === "nohup" || w === "command" || w === "exec") {
|
|
19019
|
+
i += 1;
|
|
19020
|
+
continue;
|
|
19021
|
+
}
|
|
19022
|
+
if (w === "cross-env") {
|
|
19023
|
+
i += 1;
|
|
19024
|
+
continue;
|
|
19025
|
+
}
|
|
19026
|
+
break;
|
|
19027
|
+
}
|
|
19028
|
+
return words3.slice(i);
|
|
19029
|
+
}
|
|
19030
|
+
|
|
19031
|
+
// ../core/src/lifecycle-scripts.ts
|
|
19032
|
+
var INSTALL_HOOKS = [
|
|
19033
|
+
"preinstall",
|
|
19034
|
+
"install",
|
|
19035
|
+
"postinstall",
|
|
19036
|
+
"prepublish",
|
|
19037
|
+
"preprepare",
|
|
19038
|
+
"prepare",
|
|
19039
|
+
"postprepare",
|
|
19040
|
+
"prepublishOnly",
|
|
19041
|
+
"prepack",
|
|
19042
|
+
"postpack"
|
|
19043
|
+
];
|
|
19044
|
+
var HOOK_BASES = /* @__PURE__ */ new Set(["test", "start", "stop", "restart", "build", "install", "publish", "version", "pack", "uninstall", "shrinkwrap"]);
|
|
19045
|
+
var MAX_FOLLOW_DEPTH = 3;
|
|
19046
|
+
var MAX_SOURCE_BYTES = 1048576;
|
|
19047
|
+
var MAX_SCRIPTS = 500;
|
|
19048
|
+
function parseScripts(pkgText) {
|
|
19049
|
+
try {
|
|
19050
|
+
const parsed = JSON.parse(pkgText);
|
|
19051
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
19052
|
+
const s = parsed["scripts"];
|
|
19053
|
+
if (typeof s !== "object" || s === null || Array.isArray(s)) return {};
|
|
19054
|
+
const out = {};
|
|
19055
|
+
for (const [k, v] of Object.entries(s).slice(0, MAX_SCRIPTS)) if (typeof v === "string") out[k] = v;
|
|
19056
|
+
return out;
|
|
19057
|
+
} catch {
|
|
19058
|
+
return {};
|
|
19059
|
+
}
|
|
19060
|
+
}
|
|
19061
|
+
function isAutoScript(name, scripts) {
|
|
19062
|
+
if (INSTALL_HOOKS.includes(name)) return true;
|
|
19063
|
+
const m = /^(pre|post)(.+)$/.exec(name);
|
|
19064
|
+
if (!m) return false;
|
|
19065
|
+
const base = m[2] ?? "";
|
|
19066
|
+
return Object.prototype.hasOwnProperty.call(scripts, base) || HOOK_BASES.has(base);
|
|
19067
|
+
}
|
|
19068
|
+
function autoScriptNames(scripts) {
|
|
19069
|
+
return Object.keys(scripts).filter((n) => isAutoScript(n, scripts));
|
|
19070
|
+
}
|
|
19071
|
+
var INTERPRETERS = /* @__PURE__ */ new Set(["node", "nodejs", "tsx", "ts-node", "bun", "deno", "sh", "bash", "zsh", "dash", "python", "python3", "ruby", "perl", "php"]);
|
|
19072
|
+
var INLINE_FLAGS = /* @__PURE__ */ new Set(["-e", "-c", "-p", "--eval", "--print"]);
|
|
19073
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set(["-r", "--require", "--import", "--loader", "--experimental-loader", "-C", "-W", "-X", "-m"]);
|
|
19074
|
+
var RUN_WORDS = /* @__PURE__ */ new Set(["run", "run-script", "rum", "urn"]);
|
|
19075
|
+
function cleanRel(p) {
|
|
19076
|
+
if (!isPlainWord(p) || /^[a-z][a-z0-9+.-]*:/i.test(p) || isAbsolute2(p) || p.length > 300) return null;
|
|
19077
|
+
const rel = p.replace(/^(?:\.\/)+/, "");
|
|
19078
|
+
return rel === "" ? null : rel;
|
|
19079
|
+
}
|
|
19080
|
+
function scriptTargets(name, scripts, depth = 0, seen = /* @__PURE__ */ new Set()) {
|
|
19081
|
+
const out = { files: [], inline: [], scripts: [] };
|
|
19082
|
+
const text = scripts[name];
|
|
19083
|
+
if (text === void 0 || seen.has(name) || depth > MAX_FOLLOW_DEPTH) return out;
|
|
19084
|
+
seen.add(name);
|
|
19085
|
+
out.inline.push(text);
|
|
19086
|
+
const split = splitShell(text);
|
|
19087
|
+
if (!split.ok) return out;
|
|
19088
|
+
for (const raw of split.segments) {
|
|
19089
|
+
const words3 = stripPrefixes(raw);
|
|
19090
|
+
const head = words3[0];
|
|
19091
|
+
if (head === void 0) continue;
|
|
19092
|
+
const base = head.split("/").pop() ?? head;
|
|
19093
|
+
if ((base === "npm" || base === "pnpm" || base === "yarn") && depth < MAX_FOLLOW_DEPTH) {
|
|
19094
|
+
const sub = words3[1] === "run" || RUN_WORDS.has(words3[1] ?? "") ? words3[2] : base === "yarn" || base === "pnpm" ? words3[1] : void 0;
|
|
19095
|
+
if (sub !== void 0 && Object.prototype.hasOwnProperty.call(scripts, sub)) {
|
|
19096
|
+
out.scripts.push(sub);
|
|
19097
|
+
const inner = scriptTargets(sub, scripts, depth + 1, seen);
|
|
19098
|
+
out.files.push(...inner.files);
|
|
19099
|
+
out.inline.push(...inner.inline);
|
|
19100
|
+
out.scripts.push(...inner.scripts);
|
|
19101
|
+
}
|
|
19102
|
+
continue;
|
|
19103
|
+
}
|
|
19104
|
+
if (INTERPRETERS.has(base)) {
|
|
19105
|
+
for (let i = 1; i < words3.length; i++) {
|
|
19106
|
+
const w = words3[i] ?? "";
|
|
19107
|
+
if (INLINE_FLAGS.has(w)) {
|
|
19108
|
+
out.inline.push(words3[i + 1] ?? "");
|
|
19109
|
+
break;
|
|
19110
|
+
}
|
|
19111
|
+
if (VALUE_FLAGS.has(w)) {
|
|
19112
|
+
i += 1;
|
|
19113
|
+
continue;
|
|
19114
|
+
}
|
|
19115
|
+
if (w.startsWith("-")) continue;
|
|
19116
|
+
if (base === "deno" && (w === "run" || w === "task")) continue;
|
|
19117
|
+
const rel = cleanRel(w);
|
|
19118
|
+
if (rel !== null) out.files.push(rel);
|
|
19119
|
+
break;
|
|
19120
|
+
}
|
|
19121
|
+
continue;
|
|
19122
|
+
}
|
|
19123
|
+
if (head.startsWith("./") || head.startsWith("scripts/") || head.includes("/") && !head.startsWith("-") && !head.includes(":")) {
|
|
19124
|
+
const rel = cleanRel(head);
|
|
19125
|
+
if (rel !== null) out.files.push(rel);
|
|
19126
|
+
}
|
|
19127
|
+
}
|
|
19128
|
+
return out;
|
|
19129
|
+
}
|
|
19130
|
+
var SECRET_PATTERNS = [
|
|
19131
|
+
[/(?<![\w])\.env(?!\.(?:example|sample|template|dist))(?:\.[A-Za-z]+)?(?![\w-])/, ".env"],
|
|
19132
|
+
[/(?<![\w])\.npmrc\b/, ".npmrc"],
|
|
19133
|
+
[/(?<![\w])\.aws(?![\w-])/, "~/.aws"],
|
|
19134
|
+
[/(?<![\w])\.ssh(?![\w-])/, "~/.ssh"],
|
|
19135
|
+
[/\bid_(?:rsa|ed25519|ecdsa)\b/, "a private key file"],
|
|
19136
|
+
[/(?<![\w])\.(?:netrc|git-credentials|pypirc)\b/, "a credentials file"],
|
|
19137
|
+
[/JSON\.stringify\(\s*process\.env\s*[,)]/, "the whole of process.env"],
|
|
19138
|
+
[/Object\.(?:entries|keys|values|fromEntries|assign)\(\s*(?:\{\}\s*,\s*)?process\.env\s*\)/, "the whole of process.env"],
|
|
19139
|
+
[/\{\s*\.\.\.\s*process\.env\s*\}/, "the whole of process.env"],
|
|
19140
|
+
[/\bdict\(\s*os\.environ\s*\)|\bos\.environ\.(?:items|copy)\(\)|json\.dumps\(\s*os\.environ/, "the whole of os.environ"],
|
|
19141
|
+
[/(?:^|[;&|]\s*|\$\(\s*)(?:printenv|env)\s*(?:$|[|>)]|\s*\|)/, "the whole environment"]
|
|
19142
|
+
];
|
|
19143
|
+
var SEND_PATTERNS = [
|
|
19144
|
+
[/\bhttps?\.(?:request|get)\s*\(/, "an http request"],
|
|
19145
|
+
[/\bfetch\s*\(/, "fetch"],
|
|
19146
|
+
[/\baxios(?:\.\w+)?\s*\(|\bgot(?:\.(?:post|get|put))?\s*\(\s*['"`]/, "an http client call"],
|
|
19147
|
+
[/new\s+XMLHttpRequest\b|new\s+WebSocket\s*\(/, "a browser-style request"],
|
|
19148
|
+
[/\bnet\.(?:connect|createConnection|Socket)\b/, "a socket"],
|
|
19149
|
+
[/require\(\s*['"](?:node:)?dgram['"]\s*\)|from\s+['"](?:node:)?dgram['"]/, "a datagram socket"],
|
|
19150
|
+
[/\b(?:curl|wget)\s+(?:-\S+\s+)*\S/, "curl or wget"],
|
|
19151
|
+
[/\/dev\/tcp\//, "/dev/tcp"],
|
|
19152
|
+
[/\bnc\s+\S+\s+\d+/, "netcat"],
|
|
19153
|
+
[/\burlopen\s*\(|\brequests\.(?:get|post|put)\s*\(|\bhttp\.client\b|\bsocket\.(?:socket|create_connection)\b|\bsmtplib\b/, "a python network call"]
|
|
19154
|
+
];
|
|
19155
|
+
var lineHit = (lines, patterns) => {
|
|
19156
|
+
for (let i = 0; i < lines.length; i++) {
|
|
19157
|
+
const line = lines[i] ?? "";
|
|
19158
|
+
if (line.length > 4e3) continue;
|
|
19159
|
+
for (const [re2, label] of patterns) if (re2.test(line)) return { line: i + 1, label };
|
|
19160
|
+
}
|
|
19161
|
+
return null;
|
|
19162
|
+
};
|
|
19163
|
+
function analyzeSource(text) {
|
|
19164
|
+
const lines = text.split(/\r?\n/);
|
|
19165
|
+
return { secret: lineHit(lines, SECRET_PATTERNS), send: lineHit(lines, SEND_PATTERNS) };
|
|
19166
|
+
}
|
|
19167
|
+
function locateScript(pkgText, name) {
|
|
19168
|
+
const start = pkgText.search(/"scripts"\s*:/);
|
|
19169
|
+
const esc3 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
19170
|
+
const re2 = new RegExp(`"${esc3}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`, "g");
|
|
19171
|
+
re2.lastIndex = Math.max(0, start);
|
|
19172
|
+
const m = re2.exec(pkgText);
|
|
19173
|
+
if (!m) return { line: 1, col: 1, span: name.slice(0, 120) };
|
|
19174
|
+
const valueIndex = m.index + m[0].indexOf('"', m[0].indexOf(":")) + 1;
|
|
19175
|
+
const before = pkgText.slice(0, valueIndex);
|
|
19176
|
+
const line = before.split("\n").length;
|
|
19177
|
+
const col = valueIndex - (before.lastIndexOf("\n") + 1) + 1;
|
|
19178
|
+
return { line, col, span: (m[1] ?? "").slice(0, 120) };
|
|
19179
|
+
}
|
|
19180
|
+
function lifecycleFindings(input) {
|
|
19181
|
+
const scripts = parseScripts(input.pkgText);
|
|
19182
|
+
const names = (input.names ?? autoScriptNames(scripts)).filter((n) => Object.prototype.hasOwnProperty.call(scripts, n));
|
|
19183
|
+
const hits = [];
|
|
19184
|
+
for (const name of names) {
|
|
19185
|
+
let found = null;
|
|
19186
|
+
try {
|
|
19187
|
+
const targets = scriptTargets(name, scripts);
|
|
19188
|
+
const where2 = locateScript(input.pkgText, name);
|
|
19189
|
+
const base = { script: name, scriptText: scripts[name] ?? "", ...where2 };
|
|
19190
|
+
for (const rel of [...new Set(targets.files)]) {
|
|
19191
|
+
const text = input.readLocal(rel);
|
|
19192
|
+
if (text === null) continue;
|
|
19193
|
+
const a = analyzeSource(text);
|
|
19194
|
+
if (a.secret && a.send) {
|
|
19195
|
+
found = { ...base, file: rel, secret: a.secret, send: a.send };
|
|
19196
|
+
break;
|
|
19197
|
+
}
|
|
19198
|
+
}
|
|
19199
|
+
if (!found) {
|
|
19200
|
+
for (const inline of targets.inline) {
|
|
19201
|
+
const a = analyzeSource(inline);
|
|
19202
|
+
if (a.secret && a.send) {
|
|
19203
|
+
found = { ...base, file: null, secret: a.secret, send: a.send };
|
|
19204
|
+
break;
|
|
19205
|
+
}
|
|
19206
|
+
}
|
|
19207
|
+
}
|
|
19208
|
+
} catch {
|
|
19209
|
+
found = null;
|
|
19210
|
+
}
|
|
19211
|
+
if (found) hits.push(found);
|
|
19212
|
+
}
|
|
19213
|
+
return hits;
|
|
19214
|
+
}
|
|
19215
|
+
function describeHit(h) {
|
|
19216
|
+
const where2 = h.file === null ? `The script text itself reads ${h.secret.label} and sends data out (${h.send.label}).` : `It runs ${h.file}, which reads ${h.secret.label} (line ${h.secret.line}) and sends data out through ${h.send.label} (line ${h.send.line}).`;
|
|
19217
|
+
return `The "${h.script}" script of package.json runs by itself when a package manager installs or tests this project. ${where2}`;
|
|
19218
|
+
}
|
|
19219
|
+
function readLocalText(pkgDir, rel) {
|
|
19220
|
+
try {
|
|
19221
|
+
const abs = resolve2(pkgDir, rel);
|
|
19222
|
+
const within = (root, p) => {
|
|
19223
|
+
const r = relative3(root, p);
|
|
19224
|
+
return r !== "" && !r.startsWith("..") && !isAbsolute2(r) && !r.split(sep).includes("..");
|
|
19225
|
+
};
|
|
19226
|
+
if (!within(pkgDir, abs) || !existsSync(abs)) return null;
|
|
19227
|
+
const real = realpathSync(abs);
|
|
19228
|
+
if (!within(realpathSync(pkgDir), real)) return null;
|
|
19229
|
+
const st = statSync(real);
|
|
19230
|
+
if (!st.isFile() || st.size > MAX_SOURCE_BYTES) return null;
|
|
19231
|
+
const buf = Buffer.alloc(st.size);
|
|
19232
|
+
const fd = openSync(real, "r");
|
|
19233
|
+
try {
|
|
19234
|
+
readSync(fd, buf, 0, st.size, 0);
|
|
19235
|
+
} finally {
|
|
19236
|
+
closeSync(fd);
|
|
19237
|
+
}
|
|
19238
|
+
if (buf.includes(0)) return null;
|
|
19239
|
+
return buf.toString("utf8");
|
|
19240
|
+
} catch {
|
|
19241
|
+
return null;
|
|
19242
|
+
}
|
|
19243
|
+
}
|
|
19244
|
+
|
|
18929
19245
|
// ../core/src/scanner/orchestrator.ts
|
|
19246
|
+
import { dirname } from "node:path";
|
|
18930
19247
|
init_heuristic_engine();
|
|
18931
19248
|
|
|
18932
19249
|
// ../core/src/capabilities.ts
|
|
18933
19250
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
18934
|
-
import { join as
|
|
19251
|
+
import { join as join6 } from "node:path";
|
|
18935
19252
|
init_zod();
|
|
18936
19253
|
var CAPABILITIES = ["private-data", "untrusted-input", "exfiltration"];
|
|
18937
19254
|
var CAPABILITIES_FILE = "capabilities.yaml";
|
|
@@ -19004,7 +19321,7 @@ function parseCapabilityRules(data) {
|
|
|
19004
19321
|
async function loadCapabilityRules(definitionsDir) {
|
|
19005
19322
|
let raw;
|
|
19006
19323
|
try {
|
|
19007
|
-
raw = await readFile2(
|
|
19324
|
+
raw = await readFile2(join6(definitionsDir, CAPABILITIES_FILE), "utf8");
|
|
19008
19325
|
} catch {
|
|
19009
19326
|
return { ok: false, missing: true, error: `${CAPABILITIES_FILE} was not found in ${definitionsDir}` };
|
|
19010
19327
|
}
|
|
@@ -19286,7 +19603,7 @@ function classifyCapabilities(server, rules) {
|
|
|
19286
19603
|
init_zod();
|
|
19287
19604
|
import { constants } from "node:fs";
|
|
19288
19605
|
import { lstat, open as open2 } from "node:fs/promises";
|
|
19289
|
-
import { join as
|
|
19606
|
+
import { join as join7 } from "node:path";
|
|
19290
19607
|
init_severity_paths();
|
|
19291
19608
|
init_walker();
|
|
19292
19609
|
var TRIFECTA_RULE_ID = "EX-023";
|
|
@@ -19425,7 +19742,7 @@ function parsePins(json2) {
|
|
|
19425
19742
|
return out;
|
|
19426
19743
|
}
|
|
19427
19744
|
async function readPins(root, maxBytes = MAX_PINS_BYTES) {
|
|
19428
|
-
const path =
|
|
19745
|
+
const path = join7(root, ".exorcist", "pins.json");
|
|
19429
19746
|
const none = (note) => ({ pins: /* @__PURE__ */ new Map(), note });
|
|
19430
19747
|
let info;
|
|
19431
19748
|
try {
|
|
@@ -19585,6 +19902,21 @@ async function* pathNameFindings(root, def) {
|
|
|
19585
19902
|
} catch {
|
|
19586
19903
|
}
|
|
19587
19904
|
}
|
|
19905
|
+
function lifecycleScanFindings(text, absPath, rel, def) {
|
|
19906
|
+
const dir = dirname(absPath);
|
|
19907
|
+
return lifecycleFindings({ pkgText: text, readLocal: (r) => readLocalText(dir, r) }).map((h) => ({
|
|
19908
|
+
source: "signature",
|
|
19909
|
+
ruleId: def.id,
|
|
19910
|
+
title: def.title,
|
|
19911
|
+
severity: def.severity,
|
|
19912
|
+
file: rel,
|
|
19913
|
+
line: h.line,
|
|
19914
|
+
col: h.col,
|
|
19915
|
+
span: h.span,
|
|
19916
|
+
owasp: def.owasp,
|
|
19917
|
+
fix: `${describeHit(h)} ${def.fix}`
|
|
19918
|
+
}));
|
|
19919
|
+
}
|
|
19588
19920
|
async function mapRepo(root, options) {
|
|
19589
19921
|
const rules = await loadCapabilityRules(options.definitionsDir);
|
|
19590
19922
|
if (!rules.ok) return { ok: false, error: rules.error };
|
|
@@ -19620,6 +19952,7 @@ async function* scanRepo(root, options) {
|
|
|
19620
19952
|
let filesSkipped = 0;
|
|
19621
19953
|
let findingsTotal = 0;
|
|
19622
19954
|
const ex026 = defs.find((d) => d.id === "EX-026");
|
|
19955
|
+
const ex036 = defs.find((d) => d.id === "EX-036" && d.enabled !== false && d.match.analysis === "lifecycle-scripts");
|
|
19623
19956
|
for await (const file of walkRepo(root, options.maxFileSizeBytes)) {
|
|
19624
19957
|
yield { type: "file", file };
|
|
19625
19958
|
if (file.tooLarge) {
|
|
@@ -19655,7 +19988,8 @@ async function* scanRepo(root, options) {
|
|
|
19655
19988
|
const heurs = options.bedrockClient ? await runHeuristics(file, norm2, sigs, options.bedrockClient) : [];
|
|
19656
19989
|
const traps = canaryFindings(text, file.rel, records, ex022);
|
|
19657
19990
|
const sourceTools = (file.role === "code" || file.role === "unknown") && languageOf(file.rel) !== null ? scanSourceTools(file, text, defs) : [];
|
|
19658
|
-
|
|
19991
|
+
const lifecycle = ex036 && file.role === "manifest" && file.rel.split("/").pop() === "package.json" ? lifecycleScanFindings(text, file.path, file.rel, ex036) : [];
|
|
19992
|
+
let deduped = deduplicate([...sigs, ...heurs, ...traps, ...sandboxFindings(text, file.rel), ...sourceTools, ...lifecycle]);
|
|
19659
19993
|
if (checkVault && deduped.length > 0 && file.rel.includes(".exorcist/vault/")) {
|
|
19660
19994
|
const backup = checkVault(file.rel, await readFile3(file.path));
|
|
19661
19995
|
if (backup) deduped = deduped.map((f) => asBackupFinding(f, backup));
|
|
@@ -19705,7 +20039,7 @@ async function* scanRepo(root, options) {
|
|
|
19705
20039
|
init_zod();
|
|
19706
20040
|
|
|
19707
20041
|
// ../core/src/version.ts
|
|
19708
|
-
var SCANNER_VERSION = "0.3.
|
|
20042
|
+
var SCANNER_VERSION = "0.3.1";
|
|
19709
20043
|
|
|
19710
20044
|
// ../core/src/redact-secrets.ts
|
|
19711
20045
|
var MIN_LENGTH_FOR_PREFIX = 16;
|
|
@@ -19995,6 +20329,10 @@ var ENTRIES = {
|
|
|
19995
20329
|
headline: "This project file switches off the sandbox around your AI tool servers",
|
|
19996
20330
|
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."
|
|
19997
20331
|
},
|
|
20332
|
+
"EX-036": {
|
|
20333
|
+
headline: "A script that runs by itself sends your secrets out",
|
|
20334
|
+
attack: 'This package has a script that npm, pnpm or yarn runs on its own (on install, or before or after "npm test"), and the file it runs reads your .env or other credentials and sends data to another computer. Your AI agent only has to run the tests or install the project; it does not have to obey anything.'
|
|
20335
|
+
},
|
|
19998
20336
|
"EX-027": {
|
|
19999
20337
|
headline: "Your AI read untrusted text and private data, and now wants to send something out",
|
|
20000
20338
|
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."
|
|
@@ -20115,7 +20453,7 @@ function toBadgeSvg(findings) {
|
|
|
20115
20453
|
|
|
20116
20454
|
// ../core/src/exorcise.ts
|
|
20117
20455
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
20118
|
-
import { join as
|
|
20456
|
+
import { join as join8 } from "node:path";
|
|
20119
20457
|
|
|
20120
20458
|
// ../../node_modules/.pnpm/diff@8.0.4/node_modules/diff/libesm/diff/base.js
|
|
20121
20459
|
var Diff = class {
|
|
@@ -20973,7 +21311,7 @@ async function exorciseRepo(root, findings, opts = {}) {
|
|
|
20973
21311
|
for (const [file, list2] of [...byFile.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
20974
21312
|
let bytes;
|
|
20975
21313
|
try {
|
|
20976
|
-
bytes = await readFile4(
|
|
21314
|
+
bytes = await readFile4(join8(root, file));
|
|
20977
21315
|
} catch {
|
|
20978
21316
|
continue;
|
|
20979
21317
|
}
|
|
@@ -21047,13 +21385,13 @@ var DEFAULT_TAR_LIMITS = {
|
|
|
21047
21385
|
// ../core/src/origin.ts
|
|
21048
21386
|
import { execFile as execFile2 } from "node:child_process";
|
|
21049
21387
|
import { readFile as readFile5, realpath, stat as stat2 } from "node:fs/promises";
|
|
21050
|
-
import { isAbsolute as
|
|
21388
|
+
import { isAbsolute as isAbsolute4, join as join10, relative as relative4, resolve as resolve5 } from "node:path";
|
|
21051
21389
|
|
|
21052
21390
|
// ../core/src/repo-config-guard.ts
|
|
21053
21391
|
import { execFile } from "node:child_process";
|
|
21054
|
-
import { existsSync, readFileSync as readFileSync4, realpathSync, statSync as
|
|
21392
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync3 } from "node:fs";
|
|
21055
21393
|
import { tmpdir } from "node:os";
|
|
21056
|
-
import { dirname, isAbsolute as
|
|
21394
|
+
import { dirname as dirname2, isAbsolute as isAbsolute3, join as join9, resolve as resolve4 } from "node:path";
|
|
21057
21395
|
function stripComment(s) {
|
|
21058
21396
|
let inQuote = false;
|
|
21059
21397
|
for (let i = 0; i < s.length; i++) {
|
|
@@ -21133,34 +21471,34 @@ function dangerousKey(e) {
|
|
|
21133
21471
|
function locateRepo(start) {
|
|
21134
21472
|
let dir;
|
|
21135
21473
|
try {
|
|
21136
|
-
dir =
|
|
21474
|
+
dir = realpathSync2(start);
|
|
21137
21475
|
} catch {
|
|
21138
21476
|
return null;
|
|
21139
21477
|
}
|
|
21140
21478
|
for (; ; ) {
|
|
21141
|
-
const dotGit =
|
|
21142
|
-
if (
|
|
21479
|
+
const dotGit = join9(dir, ".git");
|
|
21480
|
+
if (existsSync2(dotGit)) {
|
|
21143
21481
|
let gitDir = null;
|
|
21144
21482
|
try {
|
|
21145
|
-
if (
|
|
21483
|
+
if (statSync3(dotGit).isDirectory()) gitDir = dotGit;
|
|
21146
21484
|
else {
|
|
21147
21485
|
const m = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync4(dotGit, "utf8"));
|
|
21148
|
-
if (m?.[1]) gitDir =
|
|
21486
|
+
if (m?.[1]) gitDir = isAbsolute3(m[1]) ? m[1] : resolve4(dir, m[1]);
|
|
21149
21487
|
}
|
|
21150
21488
|
} catch {
|
|
21151
21489
|
return null;
|
|
21152
21490
|
}
|
|
21153
|
-
if (!gitDir || !
|
|
21491
|
+
if (!gitDir || !existsSync2(gitDir)) return null;
|
|
21154
21492
|
let commonDir = gitDir;
|
|
21155
|
-
const commonFile =
|
|
21156
|
-
if (
|
|
21493
|
+
const commonFile = join9(gitDir, "commondir");
|
|
21494
|
+
if (existsSync2(commonFile)) {
|
|
21157
21495
|
const c = readFileSync4(commonFile, "utf8").trim();
|
|
21158
|
-
commonDir =
|
|
21496
|
+
commonDir = isAbsolute3(c) ? c : resolve4(gitDir, c);
|
|
21159
21497
|
}
|
|
21160
|
-
const configFiles = [
|
|
21498
|
+
const configFiles = [join9(commonDir, "config"), join9(gitDir, "config.worktree")].filter((f, i, all) => all.indexOf(f) === i && existsSync2(f));
|
|
21161
21499
|
return { workTree: dir, gitDir, configFiles };
|
|
21162
21500
|
}
|
|
21163
|
-
const up =
|
|
21501
|
+
const up = dirname2(dir);
|
|
21164
21502
|
if (up === dir) return null;
|
|
21165
21503
|
dir = up;
|
|
21166
21504
|
}
|
|
@@ -21209,7 +21547,7 @@ async function guardRepoConfig(target) {
|
|
|
21209
21547
|
for (const file of repo.configFiles) {
|
|
21210
21548
|
let text;
|
|
21211
21549
|
try {
|
|
21212
|
-
if (
|
|
21550
|
+
if (statSync3(file).size > MAX_CONFIG_BYTES) return { ok: false, kind: "unreadable-config", message: `${file} is too large to check. ${advice}`, keys: [] };
|
|
21213
21551
|
text = readFileSync4(file, "utf8");
|
|
21214
21552
|
} catch {
|
|
21215
21553
|
return { ok: false, kind: "unreadable-config", message: `${file} could not be read. ${advice}`, keys: [] };
|
|
@@ -21352,7 +21690,7 @@ function runGit(cwd, args, timeoutMs) {
|
|
|
21352
21690
|
async function gitRepoRoot(cwd) {
|
|
21353
21691
|
const r = await runGit(cwd, ["rev-parse", "--show-toplevel"], 5e3);
|
|
21354
21692
|
const root = r.ok ? r.stdout.replace(/\n$/, "") : "";
|
|
21355
|
-
return root !== "" &&
|
|
21693
|
+
return root !== "" && isAbsolute4(root) ? root : null;
|
|
21356
21694
|
}
|
|
21357
21695
|
async function openRepo(target) {
|
|
21358
21696
|
const guard = await guardRepoConfig(target);
|
|
@@ -21379,7 +21717,7 @@ async function shallowBoundaries(repoRoot) {
|
|
|
21379
21717
|
const r = await runGit(repoRoot, ["rev-parse", "--git-path", "shallow"], 5e3);
|
|
21380
21718
|
if (!r.ok) return /* @__PURE__ */ new Set();
|
|
21381
21719
|
const rel = r.stdout.replace(/\n$/, "");
|
|
21382
|
-
const file =
|
|
21720
|
+
const file = isAbsolute4(rel) ? rel : join10(repoRoot, rel);
|
|
21383
21721
|
try {
|
|
21384
21722
|
const text = await readFile5(file, "utf8");
|
|
21385
21723
|
return new Set(text.split("\n").map((l) => l.trim()).filter((l) => OBJECT_ID.test(l)));
|
|
@@ -21439,9 +21777,9 @@ function mapLineToHead(workText, headText, line) {
|
|
|
21439
21777
|
}
|
|
21440
21778
|
var MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
21441
21779
|
async function readWorkTree(repoRoot, relFile) {
|
|
21442
|
-
const abs =
|
|
21443
|
-
const rel =
|
|
21444
|
-
if (rel === "" || rel.startsWith("..") ||
|
|
21780
|
+
const abs = resolve5(repoRoot, relFile);
|
|
21781
|
+
const rel = relative4(repoRoot, abs);
|
|
21782
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute4(rel)) return null;
|
|
21445
21783
|
try {
|
|
21446
21784
|
if ((await stat2(abs)).size > MAX_FILE_BYTES) return null;
|
|
21447
21785
|
return await readFile5(abs, "utf8");
|
|
@@ -21629,16 +21967,16 @@ A trap token has been copied out of its trap. Find what copied it, remove the co
|
|
|
21629
21967
|
}
|
|
21630
21968
|
|
|
21631
21969
|
// ../core/src/on-access.ts
|
|
21632
|
-
import { closeSync, existsSync as
|
|
21970
|
+
import { closeSync as closeSync2, existsSync as existsSync4, openSync as openSync2, readFileSync as readFileSync6, readSync as readSync2, statSync as statSync5 } from "node:fs";
|
|
21633
21971
|
import { createHash as createHash3 } from "node:crypto";
|
|
21634
|
-
import { basename as basename4, relative as
|
|
21972
|
+
import { basename as basename4, relative as relative6, resolve as resolve7 } from "node:path";
|
|
21635
21973
|
|
|
21636
21974
|
// ../core/src/allowed-reads.ts
|
|
21637
21975
|
init_zod();
|
|
21638
21976
|
import { createHash as createHash2 } from "node:crypto";
|
|
21639
|
-
import { existsSync as
|
|
21977
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync5, realpathSync as realpathSync3, renameSync, statSync as statSync4, writeFileSync } from "node:fs";
|
|
21640
21978
|
import { homedir } from "node:os";
|
|
21641
|
-
import { basename as basename3, dirname as
|
|
21979
|
+
import { basename as basename3, dirname as dirname3, isAbsolute as isAbsolute5, join as join11, parse, relative as relative5, resolve as resolve6 } from "node:path";
|
|
21642
21980
|
var Hash = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
21643
21981
|
var Entry = external_exports.object({ path: external_exports.string().min(1), sha256: Hash });
|
|
21644
21982
|
var AllowedReadsSchema = external_exports.object({ version: external_exports.literal(2), project: external_exports.string(), entries: external_exports.array(Entry) });
|
|
@@ -21648,20 +21986,20 @@ function sha256Bytes(data) {
|
|
|
21648
21986
|
}
|
|
21649
21987
|
function sha256File(file) {
|
|
21650
21988
|
try {
|
|
21651
|
-
if (!
|
|
21989
|
+
if (!existsSync3(file) || !statSync4(file).isFile()) return null;
|
|
21652
21990
|
return sha256Bytes(readFileSync5(file));
|
|
21653
21991
|
} catch {
|
|
21654
21992
|
return null;
|
|
21655
21993
|
}
|
|
21656
21994
|
}
|
|
21657
21995
|
function realPath(p) {
|
|
21658
|
-
const abs =
|
|
21996
|
+
const abs = resolve6(p);
|
|
21659
21997
|
const rest = [];
|
|
21660
|
-
for (let dir = abs; ; dir =
|
|
21998
|
+
for (let dir = abs; ; dir = dirname3(dir)) {
|
|
21661
21999
|
try {
|
|
21662
|
-
return
|
|
22000
|
+
return join11(realpathSync3(dir), ...rest.reverse());
|
|
21663
22001
|
} catch {
|
|
21664
|
-
if (
|
|
22002
|
+
if (dirname3(dir) === dir) return abs;
|
|
21665
22003
|
rest.push(basename3(dir));
|
|
21666
22004
|
}
|
|
21667
22005
|
}
|
|
@@ -21669,21 +22007,21 @@ function realPath(p) {
|
|
|
21669
22007
|
function findProjectRoot(cwd) {
|
|
21670
22008
|
const start = realPath(cwd);
|
|
21671
22009
|
const { root } = parse(start);
|
|
21672
|
-
for (let dir = start; ; dir =
|
|
21673
|
-
if (PROJECT_MARKERS.some((m) =>
|
|
21674
|
-
if (dir === root ||
|
|
22010
|
+
for (let dir = start; ; dir = dirname3(dir)) {
|
|
22011
|
+
if (PROJECT_MARKERS.some((m) => existsSync3(join11(dir, m)))) return dir;
|
|
22012
|
+
if (dir === root || dirname3(dir) === dir) break;
|
|
21675
22013
|
}
|
|
21676
22014
|
return start;
|
|
21677
22015
|
}
|
|
21678
22016
|
function isInside(p, dir) {
|
|
21679
|
-
const rel =
|
|
21680
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
22017
|
+
const rel = relative5(realPath(dir), realPath(p));
|
|
22018
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
21681
22019
|
}
|
|
21682
22020
|
function allowedReadsLocation(cwd, env = process.env) {
|
|
21683
22021
|
const project = findProjectRoot(cwd);
|
|
21684
22022
|
const fromEnv = env["EXORCIST_DIR"];
|
|
21685
|
-
const base = fromEnv ?
|
|
21686
|
-
const file =
|
|
22023
|
+
const base = fromEnv ? resolve6(project, fromEnv) : join11(homedir(), ".exorcist");
|
|
22024
|
+
const file = join11(base, "allowed-reads", `${sha256Bytes(Buffer.from(project, "utf8"))}.json`);
|
|
21687
22025
|
if (isInside(file, project)) {
|
|
21688
22026
|
return { ok: false, error: `Allowances cannot be kept inside the project (${file}): the project itself could plant them. Set EXORCIST_DIR to a folder outside ${project}.` };
|
|
21689
22027
|
}
|
|
@@ -21694,7 +22032,7 @@ function allowKey(realAbsPath, sha2564) {
|
|
|
21694
22032
|
}
|
|
21695
22033
|
function readAllowedReads(cwd, env = process.env) {
|
|
21696
22034
|
const loc = allowedReadsLocation(cwd, env);
|
|
21697
|
-
if (!loc.ok || !
|
|
22035
|
+
if (!loc.ok || !existsSync3(loc.file)) return /* @__PURE__ */ new Set();
|
|
21698
22036
|
try {
|
|
21699
22037
|
if (isInside(loc.file, loc.project)) return /* @__PURE__ */ new Set();
|
|
21700
22038
|
const result = AllowedReadsSchema.safeParse(JSON.parse(readFileSync5(loc.file, "utf8")));
|
|
@@ -21705,14 +22043,14 @@ function readAllowedReads(cwd, env = process.env) {
|
|
|
21705
22043
|
}
|
|
21706
22044
|
}
|
|
21707
22045
|
function addAllowedRead(cwd, file, env = process.env, expected) {
|
|
21708
|
-
const abs = realPath(
|
|
22046
|
+
const abs = realPath(resolve6(cwd, file));
|
|
21709
22047
|
const hash = sha256File(abs);
|
|
21710
22048
|
if (hash === null) return { ok: false, error: "Cannot read the file, so it cannot be allowed." };
|
|
21711
22049
|
if (expected !== void 0 && hash !== expected) return { ok: false, error: "The file changed while you were confirming. Nothing was allowed; run allow-read again." };
|
|
21712
22050
|
const loc = allowedReadsLocation(cwd, env);
|
|
21713
22051
|
if (!loc.ok) return loc;
|
|
21714
22052
|
let entries = [];
|
|
21715
|
-
if (
|
|
22053
|
+
if (existsSync3(loc.file)) {
|
|
21716
22054
|
try {
|
|
21717
22055
|
const parsed = AllowedReadsSchema.safeParse(JSON.parse(readFileSync5(loc.file, "utf8")));
|
|
21718
22056
|
if (parsed.success && parsed.data.project === loc.project) entries = parsed.data.entries;
|
|
@@ -21720,7 +22058,7 @@ function addAllowedRead(cwd, file, env = process.env, expected) {
|
|
|
21720
22058
|
}
|
|
21721
22059
|
}
|
|
21722
22060
|
entries = [...entries.filter((e) => e.path !== abs), { path: abs, sha256: hash }];
|
|
21723
|
-
mkdirSync(
|
|
22061
|
+
mkdirSync(dirname3(loc.file), { recursive: true });
|
|
21724
22062
|
const tmp = `${loc.file}.tmp-${process.pid}`;
|
|
21725
22063
|
writeFileSync(tmp, `${JSON.stringify({ version: 2, project: loc.project, entries }, null, 2)}
|
|
21726
22064
|
`, "utf8");
|
|
@@ -21766,11 +22104,11 @@ function regexJobs(defs, role) {
|
|
|
21766
22104
|
function sha256FileChunked(file) {
|
|
21767
22105
|
const h = createHash3("sha256");
|
|
21768
22106
|
const buf = Buffer.alloc(1048576);
|
|
21769
|
-
const fd =
|
|
22107
|
+
const fd = openSync2(file, "r");
|
|
21770
22108
|
try {
|
|
21771
|
-
for (let n =
|
|
22109
|
+
for (let n = readSync2(fd, buf); n > 0; n = readSync2(fd, buf)) h.update(buf.subarray(0, n));
|
|
21772
22110
|
} finally {
|
|
21773
|
-
|
|
22111
|
+
closeSync2(fd);
|
|
21774
22112
|
}
|
|
21775
22113
|
return h.digest("hex");
|
|
21776
22114
|
}
|
|
@@ -21820,7 +22158,7 @@ function extractReadPaths(toolInput, cwd) {
|
|
|
21820
22158
|
const resolved = [];
|
|
21821
22159
|
const seen = /* @__PURE__ */ new Set();
|
|
21822
22160
|
for (const p of raw) {
|
|
21823
|
-
const abs =
|
|
22161
|
+
const abs = resolve7(cwd, p);
|
|
21824
22162
|
if (!seen.has(abs)) {
|
|
21825
22163
|
seen.add(abs);
|
|
21826
22164
|
resolved.push(abs);
|
|
@@ -21850,7 +22188,7 @@ function allowAdvice(names) {
|
|
|
21850
22188
|
];
|
|
21851
22189
|
}
|
|
21852
22190
|
function relLabel(abs, cwd) {
|
|
21853
|
-
const rel =
|
|
22191
|
+
const rel = relative6(cwd, abs);
|
|
21854
22192
|
return rel === "" || rel.startsWith("..") ? basename4(abs) : rel;
|
|
21855
22193
|
}
|
|
21856
22194
|
function timedOutSerious(f, defs) {
|
|
@@ -21889,8 +22227,8 @@ function decideRead(event, defs, opts = {}) {
|
|
|
21889
22227
|
let text;
|
|
21890
22228
|
let bytes;
|
|
21891
22229
|
try {
|
|
21892
|
-
if (!
|
|
21893
|
-
const stat4 =
|
|
22230
|
+
if (!existsSync4(abs)) continue;
|
|
22231
|
+
const stat4 = statSync5(abs);
|
|
21894
22232
|
if (!stat4.isFile()) continue;
|
|
21895
22233
|
if (stat4.size > MAX_SCAN_BYTES) {
|
|
21896
22234
|
const big = relLabel(abs, cwd);
|
|
@@ -21981,8 +22319,8 @@ function decideRead(event, defs, opts = {}) {
|
|
|
21981
22319
|
}
|
|
21982
22320
|
|
|
21983
22321
|
// ../core/src/mcp-write-guard.ts
|
|
21984
|
-
import { readFileSync as readFileSync7, statSync as
|
|
21985
|
-
import { isAbsolute as
|
|
22322
|
+
import { readFileSync as readFileSync7, statSync as statSync6 } from "node:fs";
|
|
22323
|
+
import { isAbsolute as isAbsolute6, join as join12, resolve as resolve8 } from "node:path";
|
|
21986
22324
|
var PATH_KEYS = ["path", "file_path", "filePath", "target", "destination", "file"];
|
|
21987
22325
|
var COMMAND_KEYS = /* @__PURE__ */ new Set(["command", "cmd", "script", "commands"]);
|
|
21988
22326
|
var MAX_PATH_LEN = 1024;
|
|
@@ -22001,9 +22339,9 @@ function expand(raw, home, cwd) {
|
|
|
22001
22339
|
}
|
|
22002
22340
|
}
|
|
22003
22341
|
if (s === "~") s = home;
|
|
22004
|
-
else if (s.startsWith("~/") || s.startsWith("~\\")) s =
|
|
22342
|
+
else if (s.startsWith("~/") || s.startsWith("~\\")) s = join12(home, s.slice(2));
|
|
22005
22343
|
s = s.replace(/^\$\{HOME\}|^\$HOME(?![A-Za-z0-9_])/, home);
|
|
22006
|
-
return
|
|
22344
|
+
return isAbsolute6(s) ? resolve8(s) : resolve8(cwd, s);
|
|
22007
22345
|
}
|
|
22008
22346
|
function isMcpConfigPath(real) {
|
|
22009
22347
|
const parts = real.split(/[\\/]+/).slice(-3).map((p) => p.toLowerCase());
|
|
@@ -22097,11 +22435,11 @@ function writeTargets(seg) {
|
|
|
22097
22435
|
const t = args.findIndex((a) => a === "-t" || a === "--target-directory");
|
|
22098
22436
|
if (t >= 0 && args[t + 1] !== void 0) {
|
|
22099
22437
|
const dir = args[t + 1];
|
|
22100
|
-
out.push(dir, ...operands.filter((a) => a !== dir).map((a) =>
|
|
22438
|
+
out.push(dir, ...operands.filter((a) => a !== dir).map((a) => join12(dir, a.split("/").pop() ?? a)));
|
|
22101
22439
|
} else if (operands.length >= 2) out.push(operands[operands.length - 1]);
|
|
22102
22440
|
if (operands.length >= 2) {
|
|
22103
22441
|
const last = operands[operands.length - 1];
|
|
22104
|
-
if (/[\\/]$/.test(last)) out.push(
|
|
22442
|
+
if (/[\\/]$/.test(last)) out.push(join12(last, operands[0].split("/").pop() ?? ""));
|
|
22105
22443
|
}
|
|
22106
22444
|
}
|
|
22107
22445
|
return out;
|
|
@@ -22134,7 +22472,7 @@ var MOVERS = /* @__PURE__ */ new Set(["cp", "mv", "install", "ln"]);
|
|
|
22134
22472
|
var REMOVERS = /* @__PURE__ */ new Set(["rm", "rmdir", "unlink", "shred", "touch", "truncate", "mkdir"]);
|
|
22135
22473
|
function prepare(event, cwd) {
|
|
22136
22474
|
if (!isRecord(event) || !isRecord(event["tool_input"])) return null;
|
|
22137
|
-
const base = typeof event["cwd"] === "string" && event["cwd"] !== "" ?
|
|
22475
|
+
const base = typeof event["cwd"] === "string" && event["cwd"] !== "" ? resolve8(cwd, event["cwd"]) : resolve8(cwd);
|
|
22138
22476
|
const toolName = typeof event["tool_name"] === "string" ? event["tool_name"] : "";
|
|
22139
22477
|
const shellTool = /shell|bash|exec|command|terminal/i.test(toolName);
|
|
22140
22478
|
const input = event["tool_input"];
|
|
@@ -22257,7 +22595,7 @@ function readString(text, start) {
|
|
|
22257
22595
|
}
|
|
22258
22596
|
function readDisk(path) {
|
|
22259
22597
|
try {
|
|
22260
|
-
if (
|
|
22598
|
+
if (statSync6(path).size > MAX_READ_BYTES) return void 0;
|
|
22261
22599
|
return readFileSync7(path, "utf8");
|
|
22262
22600
|
} catch {
|
|
22263
22601
|
return void 0;
|
|
@@ -22310,7 +22648,7 @@ function isGuardFileWrite(event, home, cwd) {
|
|
|
22310
22648
|
}
|
|
22311
22649
|
function decideMcpWrite(event, home, cwd) {
|
|
22312
22650
|
if (!isRecord(event) || !isRecord(event["tool_input"])) return { target: "other" };
|
|
22313
|
-
const base = typeof event["cwd"] === "string" && event["cwd"] !== "" ?
|
|
22651
|
+
const base = typeof event["cwd"] === "string" && event["cwd"] !== "" ? resolve8(cwd, event["cwd"]) : resolve8(cwd);
|
|
22314
22652
|
const toolName = typeof event["tool_name"] === "string" ? event["tool_name"] : "";
|
|
22315
22653
|
const shellTool = /shell|bash|exec|command|terminal/i.test(toolName);
|
|
22316
22654
|
const paths2 = [];
|
|
@@ -22505,7 +22843,7 @@ function envWriteBlockMessage(d, envValues = []) {
|
|
|
22505
22843
|
|
|
22506
22844
|
// ../core/src/env-values.ts
|
|
22507
22845
|
import { lstatSync, readdirSync, readFileSync as readFileSync8 } from "node:fs";
|
|
22508
|
-
import { join as
|
|
22846
|
+
import { join as join13 } from "node:path";
|
|
22509
22847
|
var MIN_ENV_VALUE_LENGTH = 8;
|
|
22510
22848
|
var MAX_ENV_FILE_BYTES = 256 * 1024;
|
|
22511
22849
|
var COMMON_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -22575,7 +22913,7 @@ function loadEnvValues(cwd) {
|
|
|
22575
22913
|
const seen = /* @__PURE__ */ new Set();
|
|
22576
22914
|
for (const name of names) {
|
|
22577
22915
|
try {
|
|
22578
|
-
const path =
|
|
22916
|
+
const path = join13(cwd, name);
|
|
22579
22917
|
const st = lstatSync(path);
|
|
22580
22918
|
if (!st.isFile() || st.size > MAX_ENV_FILE_BYTES) continue;
|
|
22581
22919
|
for (const v of parseEnvValues(readFileSync8(path, "utf8"))) {
|
|
@@ -22676,9 +23014,9 @@ var BUNDLED_DEFINITIONS_DATE = "2026-11-24";
|
|
|
22676
23014
|
// ../core/src/liveupdate.ts
|
|
22677
23015
|
init_zod();
|
|
22678
23016
|
import { createHash as createHash4, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes as randomBytes2, sign as edSign, verify as edVerify } from "node:crypto";
|
|
22679
|
-
import { closeSync as
|
|
23017
|
+
import { closeSync as closeSync3, fstatSync, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync3, readFileSync as readFileSync9, readSync as readSync3, readdirSync as readdirSync2, renameSync as renameSync2, rmSync, statSync as statSync7, writeFileSync as writeFileSync2 } from "node:fs";
|
|
22680
23018
|
import { homedir as homedir2 } from "node:os";
|
|
22681
|
-
import { basename as basename5, join as
|
|
23019
|
+
import { basename as basename5, join as join14, resolve as resolve9 } from "node:path";
|
|
22682
23020
|
var DEFINITIONS_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
22683
23021
|
MCowBQYDK2VwAyEAn4o+dmOJXIzsygT2CF/3go/1E/bk9Ub16r4hGtJJjhM=
|
|
22684
23022
|
-----END PUBLIC KEY-----
|
|
@@ -22862,19 +23200,19 @@ function checkBundle(tar, o = {}) {
|
|
|
22862
23200
|
}
|
|
22863
23201
|
function installedDefinitionsRoot(env = process.env) {
|
|
22864
23202
|
const fromEnv = env["EXORCIST_DEFINITIONS_HOME"];
|
|
22865
|
-
if (fromEnv) return
|
|
22866
|
-
return
|
|
23203
|
+
if (fromEnv) return resolve9(fromEnv);
|
|
23204
|
+
return join14(env["HOME"] || env["USERPROFILE"] || homedir2(), ".exorcist", "definitions");
|
|
22867
23205
|
}
|
|
22868
23206
|
function verifySetFolder(dir, expectedVersion, publicKeyPem) {
|
|
22869
23207
|
try {
|
|
22870
23208
|
if (!lstatSync2(dir).isDirectory()) return fail("not a real folder (a symlink or a file)");
|
|
22871
|
-
const defsDir =
|
|
22872
|
-
for (const [p, kind] of [[
|
|
23209
|
+
const defsDir = join14(dir, "definitions");
|
|
23210
|
+
for (const [p, kind] of [[join14(dir, MANIFEST_NAME), "file"], [join14(dir, SIGNATURE_NAME), "file"], [defsDir, "dir"]]) {
|
|
22873
23211
|
const st = lstatSync2(p);
|
|
22874
23212
|
if (kind === "file" ? !st.isFile() : !st.isDirectory()) return fail(`${basename5(p)} is not a plain ${kind === "file" ? "file" : "folder"}`);
|
|
22875
23213
|
}
|
|
22876
|
-
const manifestBytes = readFileSync9(
|
|
22877
|
-
const bad = verifySignature(manifestBytes, readFileSync9(
|
|
23214
|
+
const manifestBytes = readFileSync9(join14(dir, MANIFEST_NAME));
|
|
23215
|
+
const bad = verifySignature(manifestBytes, readFileSync9(join14(dir, SIGNATURE_NAME)), publicKeyPem);
|
|
22878
23216
|
if (bad) return fail("the manifest signature does not verify");
|
|
22879
23217
|
const m = parseManifest(manifestBytes);
|
|
22880
23218
|
if (!m.ok) return m;
|
|
@@ -22884,7 +23222,7 @@ function verifySetFolder(dir, expectedVersion, publicKeyPem) {
|
|
|
22884
23222
|
const extra = onDisk.filter((n) => !listed.includes(n));
|
|
22885
23223
|
if (extra.length > 0) return fail(`definitions/ holds files the manifest does not list: ${extra.map((n) => printable(n)).join(", ")}`);
|
|
22886
23224
|
for (const name of listed) {
|
|
22887
|
-
const p =
|
|
23225
|
+
const p = join14(defsDir, name);
|
|
22888
23226
|
let st;
|
|
22889
23227
|
try {
|
|
22890
23228
|
st = lstatSync2(p);
|
|
@@ -22911,7 +23249,7 @@ function inspectInstalledSets(root, publicKeyPem = DEFINITIONS_PUBLIC_KEY) {
|
|
|
22911
23249
|
} catch {
|
|
22912
23250
|
return [];
|
|
22913
23251
|
}
|
|
22914
|
-
return names.filter(isValidVersion).sort((a, b) => compareVersions(b, a)).map((name) => ({ name, dir:
|
|
23252
|
+
return names.filter(isValidVersion).sort((a, b) => compareVersions(b, a)).map((name) => ({ name, dir: join14(root, name), ...verifyInstalledSet(join14(root, name), publicKeyPem) }));
|
|
22915
23253
|
}
|
|
22916
23254
|
function findActiveInstalledSet(o = {}) {
|
|
22917
23255
|
const root = o.root ?? installedDefinitionsRoot(o.env);
|
|
@@ -22924,7 +23262,7 @@ function findActiveInstalledSet(o = {}) {
|
|
|
22924
23262
|
}
|
|
22925
23263
|
const newer = names.filter((n) => isValidVersion(n) && compareVersions(n, BUNDLED_DEFINITIONS_VERSION) > 0).sort((a, b) => compareVersions(b, a));
|
|
22926
23264
|
for (const name of newer) {
|
|
22927
|
-
const r = verifyInstalledSet(
|
|
23265
|
+
const r = verifyInstalledSet(join14(root, name), pem);
|
|
22928
23266
|
if (r.ok) return r.set;
|
|
22929
23267
|
}
|
|
22930
23268
|
return null;
|
|
@@ -22943,7 +23281,7 @@ function installBundle(tar, o) {
|
|
|
22943
23281
|
if (compareVersions(version2, o.currentVersion) <= 0) {
|
|
22944
23282
|
return fail(`The bundle is version ${version2}, which is not newer than the definitions in use (${o.currentVersion}).`);
|
|
22945
23283
|
}
|
|
22946
|
-
const final =
|
|
23284
|
+
const final = join14(o.root, version2);
|
|
22947
23285
|
let exists = true;
|
|
22948
23286
|
try {
|
|
22949
23287
|
lstatSync2(final);
|
|
@@ -22951,14 +23289,14 @@ function installBundle(tar, o) {
|
|
|
22951
23289
|
exists = false;
|
|
22952
23290
|
}
|
|
22953
23291
|
if (exists) return fail(`${final} already exists. Remove it to install version ${version2} again.`);
|
|
22954
|
-
const staging =
|
|
23292
|
+
const staging = join14(o.root, `.staging-${randomBytes2(6).toString("hex")}`);
|
|
22955
23293
|
try {
|
|
22956
23294
|
mkdirSync2(o.root, { recursive: true, mode: 448 });
|
|
22957
23295
|
mkdirSync2(staging, { mode: 448 });
|
|
22958
|
-
mkdirSync2(
|
|
22959
|
-
for (const f of b.files) writeFileSync2(
|
|
22960
|
-
writeFileSync2(
|
|
22961
|
-
writeFileSync2(
|
|
23296
|
+
mkdirSync2(join14(staging, "definitions"));
|
|
23297
|
+
for (const f of b.files) writeFileSync2(join14(staging, f.path), f.data, { flag: "wx", mode: 420 });
|
|
23298
|
+
writeFileSync2(join14(staging, MANIFEST_NAME), b.manifestBytes, { flag: "wx", mode: 420 });
|
|
23299
|
+
writeFileSync2(join14(staging, SIGNATURE_NAME), b.sig, { flag: "wx", mode: 420 });
|
|
22962
23300
|
const check3 = verifySetFolder(staging, version2, pem);
|
|
22963
23301
|
if (!check3.ok) return fail(`The staged copy did not verify (${check3.error}).`);
|
|
22964
23302
|
renameSync2(staging, final);
|
|
@@ -23046,15 +23384,15 @@ async function downloadBundle(url, o = {}) {
|
|
|
23046
23384
|
function readBundleFile(path, limitBytes = DOWNLOAD_LIMIT_BYTES) {
|
|
23047
23385
|
let fd = null;
|
|
23048
23386
|
try {
|
|
23049
|
-
if (!
|
|
23050
|
-
fd =
|
|
23387
|
+
if (!statSync7(path).isFile()) return fail(`${path} is not a regular file.`);
|
|
23388
|
+
fd = openSync3(path, "r");
|
|
23051
23389
|
const st = fstatSync(fd);
|
|
23052
23390
|
if (!st.isFile()) return fail(`${path} is not a regular file.`);
|
|
23053
23391
|
if (st.size > limitBytes) return fail(`The bundle is larger than the ${limitBytes / 1048576} MB limit.`);
|
|
23054
23392
|
const buf = Buffer.alloc(limitBytes + 1);
|
|
23055
23393
|
let n = 0;
|
|
23056
23394
|
for (; ; ) {
|
|
23057
|
-
const r =
|
|
23395
|
+
const r = readSync3(fd, buf, n, buf.length - n, null);
|
|
23058
23396
|
if (r === 0) break;
|
|
23059
23397
|
n += r;
|
|
23060
23398
|
if (n > limitBytes) return fail(`The bundle is larger than the ${limitBytes / 1048576} MB limit.`);
|
|
@@ -23064,7 +23402,7 @@ function readBundleFile(path, limitBytes = DOWNLOAD_LIMIT_BYTES) {
|
|
|
23064
23402
|
} catch (e) {
|
|
23065
23403
|
return fail(`Could not read ${path} (${e.code ?? "error"}).`);
|
|
23066
23404
|
} finally {
|
|
23067
|
-
if (fd !== null)
|
|
23405
|
+
if (fd !== null) closeSync3(fd);
|
|
23068
23406
|
}
|
|
23069
23407
|
}
|
|
23070
23408
|
async function loadBundleSource(from, o = {}) {
|
|
@@ -23072,7 +23410,7 @@ async function loadBundleSource(from, o = {}) {
|
|
|
23072
23410
|
if (!/^https:\/\//i.test(from)) return fail("The update source must be an https:// URL or a local file.");
|
|
23073
23411
|
return downloadBundle(from, { ...o.fetchImpl ? { fetchImpl: o.fetchImpl } : {}, ...o.timeoutMs ? { timeoutMs: o.timeoutMs } : {} });
|
|
23074
23412
|
}
|
|
23075
|
-
return readBundleFile(
|
|
23413
|
+
return readBundleFile(resolve9(o.cwd ?? process.cwd(), from));
|
|
23076
23414
|
}
|
|
23077
23415
|
async function runLiveUpdate(o) {
|
|
23078
23416
|
const lookup = { root: o.root, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} };
|
|
@@ -23319,8 +23657,291 @@ var SessionJsonSchema = external_exports.object({
|
|
|
23319
23657
|
approveForMe: external_exports.boolean().optional()
|
|
23320
23658
|
}).passthrough();
|
|
23321
23659
|
|
|
23660
|
+
// ../core/src/run-scripts-guard.ts
|
|
23661
|
+
import { existsSync as existsSync5, realpathSync as realpathSync4, statSync as statSync8 } from "node:fs";
|
|
23662
|
+
import { isAbsolute as isAbsolute7, join as join15, relative as relative7, resolve as resolve10, sep as sep2 } from "node:path";
|
|
23663
|
+
import { readFileSync as readFileSync10 } from "node:fs";
|
|
23664
|
+
var MAX_PKG_BYTES = 1048576;
|
|
23665
|
+
var PM = /* @__PURE__ */ new Set(["npm", "pnpm", "yarn", "npx", "pnpx"]);
|
|
23666
|
+
var VALUE_FLAGS2 = /* @__PURE__ */ new Set(["--prefix", "-C", "--cwd", "--workspace", "-w", "--filter", "-F", "--package", "-p", "--loglevel", "--registry", "--userconfig"]);
|
|
23667
|
+
var DIR_FLAGS = /* @__PURE__ */ new Set(["--prefix", "-C", "--cwd"]);
|
|
23668
|
+
var INSTALL_SET = [...INSTALL_HOOKS];
|
|
23669
|
+
var withHooks = (n) => [`pre${n}`, n, `post${n}`];
|
|
23670
|
+
function namesFor(pm, sub, arg, scripts) {
|
|
23671
|
+
const s = sub ?? "";
|
|
23672
|
+
if (pm === "npm" || pm === "pnpm" || pm === "yarn") {
|
|
23673
|
+
if (["test", "t", "tst"].includes(s)) return withHooks("test");
|
|
23674
|
+
if (["start", "stop", "restart"].includes(s)) return withHooks(s);
|
|
23675
|
+
if (["run", "run-script", "rum", "urn"].includes(s)) return arg === void 0 ? [] : withHooks(arg);
|
|
23676
|
+
if (["install", "i", "add", "ci", "install-test", "it", "cit", "isntall"].includes(s)) return [...INSTALL_SET, ...s === "it" || s === "install-test" || s === "cit" ? withHooks("test") : []];
|
|
23677
|
+
if (pm === "yarn" && sub === void 0) return INSTALL_SET;
|
|
23678
|
+
if (["publish", "pack", "version"].includes(s)) return [...withHooks(s), "prepare", "prepublishOnly", "prepack", "postpack"];
|
|
23679
|
+
if ((pm === "pnpm" || pm === "yarn") && scripts.has(s)) return withHooks(s);
|
|
23680
|
+
}
|
|
23681
|
+
return [];
|
|
23682
|
+
}
|
|
23683
|
+
function afterFlags(words3, from) {
|
|
23684
|
+
const rest = [];
|
|
23685
|
+
let dir = null;
|
|
23686
|
+
for (let i = from; i < words3.length; i++) {
|
|
23687
|
+
const w = words3[i] ?? "";
|
|
23688
|
+
if (w === "--") {
|
|
23689
|
+
rest.push(...words3.slice(i + 1));
|
|
23690
|
+
break;
|
|
23691
|
+
}
|
|
23692
|
+
if (w.startsWith("-")) {
|
|
23693
|
+
const eq = w.indexOf("=");
|
|
23694
|
+
const flag = eq > 0 ? w.slice(0, eq) : w;
|
|
23695
|
+
if (eq > 0) {
|
|
23696
|
+
if (DIR_FLAGS.has(flag)) dir = w.slice(eq + 1);
|
|
23697
|
+
continue;
|
|
23698
|
+
}
|
|
23699
|
+
if (VALUE_FLAGS2.has(flag)) {
|
|
23700
|
+
if (DIR_FLAGS.has(flag)) dir = words3[i + 1] ?? null;
|
|
23701
|
+
i += 1;
|
|
23702
|
+
}
|
|
23703
|
+
continue;
|
|
23704
|
+
}
|
|
23705
|
+
rest.push(w);
|
|
23706
|
+
}
|
|
23707
|
+
return { rest, dir };
|
|
23708
|
+
}
|
|
23709
|
+
function plansForCommand(command, cwd, scriptsOf) {
|
|
23710
|
+
const split = splitShell(command);
|
|
23711
|
+
if (!split.ok) return null;
|
|
23712
|
+
const plans = [];
|
|
23713
|
+
let dir = cwd;
|
|
23714
|
+
for (const raw of split.segments) {
|
|
23715
|
+
const words3 = stripPrefixes(raw);
|
|
23716
|
+
const head = words3[0];
|
|
23717
|
+
if (head === void 0) continue;
|
|
23718
|
+
const base = head.split("/").pop() ?? head;
|
|
23719
|
+
if (base === "cd" || base === "pushd") {
|
|
23720
|
+
const target = words3[1];
|
|
23721
|
+
if (target !== void 0 && isPlainWord(target) && !target.startsWith("-")) dir = resolve10(dir, target);
|
|
23722
|
+
continue;
|
|
23723
|
+
}
|
|
23724
|
+
if (!PM.has(base)) continue;
|
|
23725
|
+
const { rest, dir: flagDir } = afterFlags(words3, 1);
|
|
23726
|
+
const where2 = flagDir !== null && isPlainWord(flagDir) ? resolve10(dir, flagDir) : dir;
|
|
23727
|
+
const sub = rest[0];
|
|
23728
|
+
if (base === "npx" || base === "pnpx" || base === "npm" && (sub === "exec" || sub === "x") || base === "pnpm" && sub === "exec") {
|
|
23729
|
+
const bin = base === "npx" || base === "pnpx" ? rest[0] : rest[1];
|
|
23730
|
+
if (bin !== void 0 && isPlainWord(bin)) plans.push({ dir: where2, names: [], bin });
|
|
23731
|
+
continue;
|
|
23732
|
+
}
|
|
23733
|
+
const names = namesFor(base, sub, rest[1], scriptsOf(where2));
|
|
23734
|
+
if (names.length > 0) plans.push({ dir: where2, names });
|
|
23735
|
+
}
|
|
23736
|
+
return plans;
|
|
23737
|
+
}
|
|
23738
|
+
function readPackage(dir) {
|
|
23739
|
+
try {
|
|
23740
|
+
const p = join15(dir, "package.json");
|
|
23741
|
+
if (!existsSync5(p) || statSync8(p).size > MAX_PKG_BYTES) return null;
|
|
23742
|
+
return readFileSync10(p, "utf8");
|
|
23743
|
+
} catch {
|
|
23744
|
+
return null;
|
|
23745
|
+
}
|
|
23746
|
+
}
|
|
23747
|
+
function scriptNamesOf(dir) {
|
|
23748
|
+
const text = readPackage(dir);
|
|
23749
|
+
if (text === null) return /* @__PURE__ */ new Set();
|
|
23750
|
+
try {
|
|
23751
|
+
const s = JSON.parse(text).scripts;
|
|
23752
|
+
return new Set(typeof s === "object" && s !== null ? Object.keys(s) : []);
|
|
23753
|
+
} catch {
|
|
23754
|
+
return /* @__PURE__ */ new Set();
|
|
23755
|
+
}
|
|
23756
|
+
}
|
|
23757
|
+
var inside2 = (root, p) => {
|
|
23758
|
+
const r = relative7(root, p);
|
|
23759
|
+
return r !== "" && !r.startsWith("..") && !isAbsolute7(r) && !r.split(sep2).includes("..");
|
|
23760
|
+
};
|
|
23761
|
+
function localBinHit(dir, workspace, bin) {
|
|
23762
|
+
try {
|
|
23763
|
+
const link = join15(dir, "node_modules", ".bin", bin);
|
|
23764
|
+
if (bin.includes("/") || !existsSync5(link)) return null;
|
|
23765
|
+
const real = realpathSync4(link);
|
|
23766
|
+
const ws = realpathSync4(workspace);
|
|
23767
|
+
if (!inside2(ws, real) || real.split(sep2).includes("node_modules")) return null;
|
|
23768
|
+
const text = readLocalText(ws, relative7(ws, real));
|
|
23769
|
+
if (text === null) return null;
|
|
23770
|
+
const a = analyzeSource(text);
|
|
23771
|
+
if (!a.secret || !a.send) return null;
|
|
23772
|
+
const file = relative7(ws, real);
|
|
23773
|
+
return { script: `npx ${bin}`, scriptText: bin, line: 1, col: 1, span: bin, file, secret: a.secret, send: a.send };
|
|
23774
|
+
} catch {
|
|
23775
|
+
return null;
|
|
23776
|
+
}
|
|
23777
|
+
}
|
|
23778
|
+
var isShellTool = (tool) => tool === void 0 || typeof tool === "string" && /shell|bash|command|exec/i.test(tool);
|
|
23779
|
+
function eventCommand(event) {
|
|
23780
|
+
if (typeof event !== "object" || event === null) return null;
|
|
23781
|
+
const e = event;
|
|
23782
|
+
if (!isShellTool(e["tool_name"])) return null;
|
|
23783
|
+
const input = e["tool_input"];
|
|
23784
|
+
if (typeof input !== "object" || input === null) return null;
|
|
23785
|
+
const c = input["command"] ?? input["cmd"];
|
|
23786
|
+
return typeof c === "string" && c !== "" ? c : null;
|
|
23787
|
+
}
|
|
23788
|
+
function eventCwd(event, fallback) {
|
|
23789
|
+
const c = typeof event === "object" && event !== null ? event["cwd"] : void 0;
|
|
23790
|
+
return typeof c === "string" && isAbsolute7(c) ? c : fallback;
|
|
23791
|
+
}
|
|
23792
|
+
function decideRunScripts(event, fallbackCwd) {
|
|
23793
|
+
try {
|
|
23794
|
+
const command = eventCommand(event);
|
|
23795
|
+
if (command === null) return { block: false };
|
|
23796
|
+
const cwd = eventCwd(event, fallbackCwd);
|
|
23797
|
+
const plans = plansForCommand(command, cwd, scriptNamesOf);
|
|
23798
|
+
if (plans === null) return { block: false, parseFailed: true };
|
|
23799
|
+
for (const plan of plans) {
|
|
23800
|
+
if (plan.bin !== void 0) {
|
|
23801
|
+
const hit2 = localBinHit(plan.dir, cwd, plan.bin);
|
|
23802
|
+
if (hit2) return { block: true, hit: hit2, dir: plan.dir };
|
|
23803
|
+
continue;
|
|
23804
|
+
}
|
|
23805
|
+
const pkgText = readPackage(plan.dir);
|
|
23806
|
+
if (pkgText === null) continue;
|
|
23807
|
+
const hits = lifecycleFindings({ pkgText, readLocal: (rel) => readLocalText(plan.dir, rel), names: plan.names });
|
|
23808
|
+
const hit = hits[0];
|
|
23809
|
+
if (hit) return { block: true, hit, dir: plan.dir };
|
|
23810
|
+
}
|
|
23811
|
+
return { block: false };
|
|
23812
|
+
} catch {
|
|
23813
|
+
return { block: false };
|
|
23814
|
+
}
|
|
23815
|
+
}
|
|
23816
|
+
function runScriptsBlockMessage(hit) {
|
|
23817
|
+
const file = hit.file === null ? "its own text" : shownName(hit.file);
|
|
23818
|
+
return [
|
|
23819
|
+
"Exorcist 98 blocked this command: a package script it would run reads secrets and sends them out. Nothing was run.",
|
|
23820
|
+
` script ${shownName(hit.script)} in package.json, which uses ${file}`,
|
|
23821
|
+
hit.file === null ? ` The script text reads ${hit.secret.label} and sends data out (${hit.send.label}).` : ` The file reads ${hit.secret.label} (line ${hit.secret.line}) and sends data out through ${hit.send.label} (line ${hit.send.line}).`,
|
|
23822
|
+
"Do not look for a way around this block (running the file by hand, editing the script, using another package manager).",
|
|
23823
|
+
"Tell the user what was blocked. They can read the file and run `exorcist scan` on the project before deciding."
|
|
23824
|
+
].join("\n");
|
|
23825
|
+
}
|
|
23826
|
+
|
|
23827
|
+
// ../core/src/shell-read-guard.ts
|
|
23828
|
+
import { readdirSync as readdirSync3 } from "node:fs";
|
|
23829
|
+
import { basename as basename6, dirname as dirname4, isAbsolute as isAbsolute8, relative as relative8, resolve as resolve11, sep as sep3 } from "node:path";
|
|
23830
|
+
var MAX_TARGETS = 20;
|
|
23831
|
+
var VALUE_FLAGS3 = {
|
|
23832
|
+
cat: /* @__PURE__ */ new Set(),
|
|
23833
|
+
head: /* @__PURE__ */ new Set(["-n", "-c", "--lines", "--bytes"]),
|
|
23834
|
+
tail: /* @__PURE__ */ new Set(["-n", "-c", "--lines", "--bytes", "-s", "--sleep-interval"]),
|
|
23835
|
+
less: /* @__PURE__ */ new Set(["-b", "-h", "-j", "-p", "-P", "-t", "-T", "-x", "-y", "-z"]),
|
|
23836
|
+
more: /* @__PURE__ */ new Set(["-n", "-p"]),
|
|
23837
|
+
bat: /* @__PURE__ */ new Set(["-l", "--language", "-r", "--line-range", "--theme", "--style", "--tabs", "--wrap"]),
|
|
23838
|
+
batcat: /* @__PURE__ */ new Set(["-l", "--language", "-r", "--line-range", "--theme", "--style", "--tabs", "--wrap"]),
|
|
23839
|
+
nl: /* @__PURE__ */ new Set(["-b", "-d", "-f", "-h", "-i", "-l", "-n", "-s", "-v", "-w"]),
|
|
23840
|
+
sed: /* @__PURE__ */ new Set(["-e", "-f", "--expression", "--file", "-l", "-E", "-s"]),
|
|
23841
|
+
awk: /* @__PURE__ */ new Set(["-F", "-v", "-f", "--file", "-e", "--source"]),
|
|
23842
|
+
gawk: /* @__PURE__ */ new Set(["-F", "-v", "-f", "--file", "-e", "--source"]),
|
|
23843
|
+
grep: /* @__PURE__ */ new Set(["-e", "-f", "-m", "-A", "-B", "-C", "--include", "--exclude", "--exclude-dir", "--regexp", "--file", "--max-count", "--label", "--color", "-d", "-D"])
|
|
23844
|
+
};
|
|
23845
|
+
VALUE_FLAGS3["egrep"] = VALUE_FLAGS3["grep"] ?? /* @__PURE__ */ new Set();
|
|
23846
|
+
VALUE_FLAGS3["fgrep"] = VALUE_FLAGS3["grep"] ?? /* @__PURE__ */ new Set();
|
|
23847
|
+
var FILE_PROGRAMS = new Set(Object.keys(VALUE_FLAGS3));
|
|
23848
|
+
var FIRST_IS_PROGRAM = /* @__PURE__ */ new Set(["sed", "awk", "gawk", "grep", "egrep", "fgrep"]);
|
|
23849
|
+
var GIVES_PROGRAM = /* @__PURE__ */ new Set(["-e", "-f", "--expression", "--file", "--regexp", "--source"]);
|
|
23850
|
+
function readTargets(words3) {
|
|
23851
|
+
const w = stripPrefixes(words3);
|
|
23852
|
+
const head = w[0];
|
|
23853
|
+
if (head === void 0) return [];
|
|
23854
|
+
const prog = head.split("/").pop() ?? head;
|
|
23855
|
+
if (!FILE_PROGRAMS.has(prog)) return [];
|
|
23856
|
+
if (prog === "sed" && !w.some((x) => /^-[A-Za-z]*n[A-Za-z]*$/.test(x) || x === "--quiet" || x === "--silent")) return [];
|
|
23857
|
+
const valueFlags = VALUE_FLAGS3[prog] ?? /* @__PURE__ */ new Set();
|
|
23858
|
+
const files = [];
|
|
23859
|
+
let programGiven = !FIRST_IS_PROGRAM.has(prog);
|
|
23860
|
+
let afterDashes = false;
|
|
23861
|
+
for (let i = 1; i < w.length; i++) {
|
|
23862
|
+
const a = w[i] ?? "";
|
|
23863
|
+
if (!afterDashes && a === "--") {
|
|
23864
|
+
afterDashes = true;
|
|
23865
|
+
continue;
|
|
23866
|
+
}
|
|
23867
|
+
if (!afterDashes && a.startsWith("-") && a !== "-") {
|
|
23868
|
+
if (GIVES_PROGRAM.has(a)) programGiven = true;
|
|
23869
|
+
if (valueFlags.has(a)) {
|
|
23870
|
+
if ((a === "-f" || a === "--file") && prog !== "grep" && prog !== "egrep" && prog !== "fgrep") {
|
|
23871
|
+
const v = w[i + 1];
|
|
23872
|
+
if (v !== void 0) files.push(v);
|
|
23873
|
+
}
|
|
23874
|
+
i += 1;
|
|
23875
|
+
}
|
|
23876
|
+
continue;
|
|
23877
|
+
}
|
|
23878
|
+
if (!programGiven) {
|
|
23879
|
+
programGiven = true;
|
|
23880
|
+
continue;
|
|
23881
|
+
}
|
|
23882
|
+
files.push(a);
|
|
23883
|
+
}
|
|
23884
|
+
return files;
|
|
23885
|
+
}
|
|
23886
|
+
function isSimpleGlob(word) {
|
|
23887
|
+
if (/[$`[\]{}~]/.test(word) || word.includes("\0") || !/[*?]/.test(word) || word.includes("**")) return false;
|
|
23888
|
+
const dir = dirname4(word);
|
|
23889
|
+
return !/[*?]/.test(dir) && !/[*?]/.test(word.slice(0, word.length - basename6(word).length));
|
|
23890
|
+
}
|
|
23891
|
+
function expandSimpleGlob(word, dir) {
|
|
23892
|
+
try {
|
|
23893
|
+
const base = basename6(word);
|
|
23894
|
+
const re2 = new RegExp(`^${base.replace(/[.+^${}()|\\[\]]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".")}$`);
|
|
23895
|
+
const folder = resolve11(dir, dirname4(word));
|
|
23896
|
+
return readdirSync3(folder).filter((n) => re2.test(n) && (!n.startsWith(".") || base.startsWith("."))).sort().slice(0, MAX_TARGETS).map((n) => resolve11(folder, n));
|
|
23897
|
+
} catch {
|
|
23898
|
+
return [];
|
|
23899
|
+
}
|
|
23900
|
+
}
|
|
23901
|
+
function shellReadPaths(command, cwd, workspace) {
|
|
23902
|
+
const split = splitShell(command);
|
|
23903
|
+
if (!split.ok) return null;
|
|
23904
|
+
const out = [];
|
|
23905
|
+
let dir = cwd;
|
|
23906
|
+
for (const raw of split.segments) {
|
|
23907
|
+
const words3 = stripPrefixes(raw);
|
|
23908
|
+
const base = (words3[0] ?? "").split("/").pop();
|
|
23909
|
+
if (base === "cd" || base === "pushd") {
|
|
23910
|
+
const t = words3[1];
|
|
23911
|
+
if (t !== void 0 && isPlainWord(t) && !t.startsWith("-")) dir = resolve11(dir, t);
|
|
23912
|
+
continue;
|
|
23913
|
+
}
|
|
23914
|
+
for (const f of readTargets(words3)) {
|
|
23915
|
+
const candidates = isPlainWord(f) ? [resolve11(dir, f)] : isSimpleGlob(f) ? expandSimpleGlob(f, dir) : [];
|
|
23916
|
+
for (const abs of candidates) {
|
|
23917
|
+
const rel = relative8(workspace, abs);
|
|
23918
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute8(rel) || rel.split(sep3).includes("..")) continue;
|
|
23919
|
+
if (!out.includes(abs)) out.push(abs);
|
|
23920
|
+
if (out.length >= MAX_TARGETS) return out;
|
|
23921
|
+
}
|
|
23922
|
+
}
|
|
23923
|
+
}
|
|
23924
|
+
return out;
|
|
23925
|
+
}
|
|
23926
|
+
function decideShellRead(event, defs, opts = {}, fallbackCwd = process.cwd()) {
|
|
23927
|
+
try {
|
|
23928
|
+
const command = eventCommand(event);
|
|
23929
|
+
if (command === null) return { exitCode: 0, message: "" };
|
|
23930
|
+
const cwd = eventCwd(event, opts.cwd ?? fallbackCwd);
|
|
23931
|
+
const paths2 = shellReadPaths(command, cwd, cwd);
|
|
23932
|
+
if (paths2 === null || paths2.length === 0) return { exitCode: 0, message: "" };
|
|
23933
|
+
const d = decideRead({ tool_name: "read", cwd, tool_input: { paths: paths2 } }, defs, { ...opts, cwd });
|
|
23934
|
+
if (d.exitCode === 2) {
|
|
23935
|
+
return { exitCode: 2, message: d.message.replace("Exorcist 98 blocked this read:", "Exorcist 98 blocked this command, which reads a file through the shell:") };
|
|
23936
|
+
}
|
|
23937
|
+
return d;
|
|
23938
|
+
} catch {
|
|
23939
|
+
return { exitCode: 0, message: "" };
|
|
23940
|
+
}
|
|
23941
|
+
}
|
|
23942
|
+
|
|
23322
23943
|
// src/commands/approve.ts
|
|
23323
|
-
import { existsSync as
|
|
23944
|
+
import { existsSync as existsSync15, readFileSync as readFileSync19 } from "node:fs";
|
|
23324
23945
|
|
|
23325
23946
|
// ../shield/src/hash.ts
|
|
23326
23947
|
import { createHash as createHash6 } from "node:crypto";
|
|
@@ -23398,7 +24019,7 @@ var LineSplitter = class {
|
|
|
23398
24019
|
|
|
23399
24020
|
// ../shield/src/policy.ts
|
|
23400
24021
|
init_zod();
|
|
23401
|
-
import { existsSync as
|
|
24022
|
+
import { existsSync as existsSync6, readFileSync as readFileSync11 } from "node:fs";
|
|
23402
24023
|
var PolicySchema = external_exports.object({
|
|
23403
24024
|
allowedHosts: external_exports.array(external_exports.string().min(1)).default([]),
|
|
23404
24025
|
mode: external_exports.enum(["enforce", "monitor"]).default("enforce"),
|
|
@@ -23466,10 +24087,10 @@ var PolicySchema = external_exports.object({
|
|
|
23466
24087
|
}).strict();
|
|
23467
24088
|
var DEFAULT_POLICY = { allowedHosts: [], mode: "enforce", autoQuarantine: false, firstUse: "pin", notify: true, verifyCalls: true, launchPin: "block", aiReview: false, sessionGuard: "hold" };
|
|
23468
24089
|
function loadPolicy(path) {
|
|
23469
|
-
if (!
|
|
24090
|
+
if (!existsSync6(path)) return { ok: true, policy: DEFAULT_POLICY };
|
|
23470
24091
|
let json2;
|
|
23471
24092
|
try {
|
|
23472
|
-
json2 = JSON.parse(
|
|
24093
|
+
json2 = JSON.parse(readFileSync11(path, "utf8"));
|
|
23473
24094
|
} catch {
|
|
23474
24095
|
return { ok: false, error: `The policy file ${path} is not valid JSON.` };
|
|
23475
24096
|
}
|
|
@@ -23493,8 +24114,8 @@ function hostAllowed(host, allowed) {
|
|
|
23493
24114
|
|
|
23494
24115
|
// ../shield/src/state.ts
|
|
23495
24116
|
init_zod();
|
|
23496
|
-
import { appendFileSync, existsSync as
|
|
23497
|
-
import { dirname as
|
|
24117
|
+
import { appendFileSync, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync12, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24118
|
+
import { dirname as dirname5, join as join16 } from "node:path";
|
|
23498
24119
|
var Sha256 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
23499
24120
|
var PinSchema = external_exports.object({
|
|
23500
24121
|
hash: Sha256,
|
|
@@ -23538,15 +24159,15 @@ var StateSchema = external_exports.object({
|
|
|
23538
24159
|
servers: external_exports.record(ServerStateSchema).default({})
|
|
23539
24160
|
});
|
|
23540
24161
|
var emptyState = () => ({ version: 1, servers: {} });
|
|
23541
|
-
var statePath = (dir) =>
|
|
23542
|
-
var policyPath = (dir) =>
|
|
23543
|
-
var alertsPath = (dir) =>
|
|
23544
|
-
var vaultPath = (dir) =>
|
|
24162
|
+
var statePath = (dir) => join16(dir, "pins.json");
|
|
24163
|
+
var policyPath = (dir) => join16(dir, "policy.json");
|
|
24164
|
+
var alertsPath = (dir) => join16(dir, "alerts.jsonl");
|
|
24165
|
+
var vaultPath = (dir) => join16(dir, "vault");
|
|
23545
24166
|
function loadState(path) {
|
|
23546
|
-
if (!
|
|
24167
|
+
if (!existsSync7(path)) return { ok: true, state: emptyState() };
|
|
23547
24168
|
let json2;
|
|
23548
24169
|
try {
|
|
23549
|
-
json2 = JSON.parse(
|
|
24170
|
+
json2 = JSON.parse(readFileSync12(path, "utf8"));
|
|
23550
24171
|
} catch {
|
|
23551
24172
|
return { ok: false, error: `The pin file ${path} is not valid JSON. Fix or delete it; the shield will not run without it.` };
|
|
23552
24173
|
}
|
|
@@ -23557,7 +24178,7 @@ function loadState(path) {
|
|
|
23557
24178
|
return { ok: true, state: parsed.data };
|
|
23558
24179
|
}
|
|
23559
24180
|
function saveState(path, state) {
|
|
23560
|
-
mkdirSync3(
|
|
24181
|
+
mkdirSync3(dirname5(path), { recursive: true });
|
|
23561
24182
|
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
23562
24183
|
writeFileSync3(tmp, `${JSON.stringify(state, null, 2)}
|
|
23563
24184
|
`, "utf8");
|
|
@@ -23572,7 +24193,7 @@ function serverState(state, name) {
|
|
|
23572
24193
|
return s;
|
|
23573
24194
|
}
|
|
23574
24195
|
function appendAlert(path, alert) {
|
|
23575
|
-
mkdirSync3(
|
|
24196
|
+
mkdirSync3(dirname5(path), { recursive: true });
|
|
23576
24197
|
appendFileSync(path, `${JSON.stringify(alert)}
|
|
23577
24198
|
`, "utf8");
|
|
23578
24199
|
}
|
|
@@ -24184,8 +24805,8 @@ function throttle(o = {}) {
|
|
|
24184
24805
|
}
|
|
24185
24806
|
|
|
24186
24807
|
// ../shield/src/canary.ts
|
|
24187
|
-
import { existsSync as
|
|
24188
|
-
import { dirname as
|
|
24808
|
+
import { existsSync as existsSync8, lstatSync as lstatSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync13, readdirSync as readdirSync4, realpathSync as realpathSync5, rmdirSync, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
24809
|
+
import { dirname as dirname6, isAbsolute as isAbsolute9, join as join17, resolve as resolve12 } from "node:path";
|
|
24189
24810
|
var TRAPS = [
|
|
24190
24811
|
{
|
|
24191
24812
|
name: ".env.canary",
|
|
@@ -24228,36 +24849,36 @@ function plantCanaries(root, o = {}) {
|
|
|
24228
24849
|
return { ok: false, error: `Canary traps are already planted in ${root}. To replace them, run "exorcist canary --remove" first.` };
|
|
24229
24850
|
}
|
|
24230
24851
|
for (const d of [".exorcist", CANARY_TRAP_DIR]) {
|
|
24231
|
-
const path =
|
|
24232
|
-
if (
|
|
24852
|
+
const path = join17(root, d);
|
|
24853
|
+
if (existsSync8(path) || isSymlink(path)) {
|
|
24233
24854
|
if (!isRealDir(path)) return { ok: false, error: `${path} is not a real folder (a symlink or a file); no traps were planted.` };
|
|
24234
24855
|
}
|
|
24235
24856
|
}
|
|
24236
24857
|
const traps = TRAPS.slice(0, count);
|
|
24237
24858
|
for (const t of traps) {
|
|
24238
|
-
const path =
|
|
24239
|
-
if (
|
|
24859
|
+
const path = join17(root, CANARY_TRAP_DIR, t.name);
|
|
24860
|
+
if (existsSync8(path)) return { ok: false, error: `${path} already exists; it was not overwritten.` };
|
|
24240
24861
|
}
|
|
24241
24862
|
const created = (o.now ? o.now() : /* @__PURE__ */ new Date()).toISOString();
|
|
24242
24863
|
const records = [];
|
|
24243
|
-
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !
|
|
24864
|
+
const madeDirs = [".exorcist", CANARY_TRAP_DIR].filter((d) => !existsSync8(join17(root, d)));
|
|
24244
24865
|
try {
|
|
24245
|
-
mkdirSync4(
|
|
24866
|
+
mkdirSync4(join17(root, CANARY_TRAP_DIR), { recursive: true });
|
|
24246
24867
|
for (const t of traps) {
|
|
24247
24868
|
const token = newToken();
|
|
24248
24869
|
const file = `${CANARY_TRAP_DIR}/${t.name}`;
|
|
24249
|
-
writeFileSync4(
|
|
24870
|
+
writeFileSync4(join17(root, file), t.body(token), { flag: "wx" });
|
|
24250
24871
|
records.push({ token, file, created });
|
|
24251
24872
|
}
|
|
24252
24873
|
writeFileSync4(recordsFile, `${JSON.stringify({ version: 1, canaries: records, ...madeDirs.length > 0 ? { madeDirs } : {} }, null, 2)}
|
|
24253
24874
|
`);
|
|
24254
24875
|
} catch (err) {
|
|
24255
|
-
for (const r of records) rmSync2(
|
|
24256
|
-
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(
|
|
24876
|
+
for (const r of records) rmSync2(join17(root, r.file), { force: true });
|
|
24877
|
+
for (const d of [...madeDirs].reverse()) rmdirIfEmpty(join17(root, d));
|
|
24257
24878
|
return { ok: false, error: `Could not plant the canary traps: ${firstLine(err)}` };
|
|
24258
24879
|
}
|
|
24259
24880
|
const result = { ok: true, records, recordsFile };
|
|
24260
|
-
if (o.stateDir &&
|
|
24881
|
+
if (o.stateDir && resolve12(o.stateDir) !== resolve12(root, ".exorcist")) {
|
|
24261
24882
|
const told = setPolicyCanaries(o.stateDir, recordsFile);
|
|
24262
24883
|
if (!told.ok) return { ok: false, error: `Planted the traps, but could not tell the Shield where they are: ${told.error}` };
|
|
24263
24884
|
result.policyUpdated = policyPath(o.stateDir);
|
|
@@ -24270,7 +24891,7 @@ function loadCanaries(root) {
|
|
|
24270
24891
|
}
|
|
24271
24892
|
function rmdirIfEmpty(path) {
|
|
24272
24893
|
try {
|
|
24273
|
-
if (lstatSync3(path).isDirectory() &&
|
|
24894
|
+
if (lstatSync3(path).isDirectory() && readdirSync4(path).length === 0) rmdirSync(path);
|
|
24274
24895
|
} catch {
|
|
24275
24896
|
}
|
|
24276
24897
|
}
|
|
@@ -24295,18 +24916,18 @@ function removeCanaries(root, o = {}) {
|
|
|
24295
24916
|
if (!existing.ok) return existing;
|
|
24296
24917
|
const removed = [];
|
|
24297
24918
|
const warnings = [];
|
|
24298
|
-
const stateFolder =
|
|
24299
|
-
const trapFolder =
|
|
24919
|
+
const stateFolder = join17(root, ".exorcist");
|
|
24920
|
+
const trapFolder = join17(root, CANARY_TRAP_DIR);
|
|
24300
24921
|
const foldersReal = isRealDir(stateFolder) && isRealDir(trapFolder);
|
|
24301
24922
|
let trapReal = null;
|
|
24302
24923
|
try {
|
|
24303
|
-
trapReal = foldersReal ?
|
|
24924
|
+
trapReal = foldersReal ? realpathSync5(trapFolder) : null;
|
|
24304
24925
|
} catch {
|
|
24305
24926
|
trapReal = null;
|
|
24306
24927
|
}
|
|
24307
24928
|
let left = 0;
|
|
24308
24929
|
for (const r of existing.canaries) {
|
|
24309
|
-
const full =
|
|
24930
|
+
const full = join17(root, r.file);
|
|
24310
24931
|
const name = r.file.slice(`${CANARY_TRAP_DIR}/`.length);
|
|
24311
24932
|
const leave = (why) => {
|
|
24312
24933
|
left++;
|
|
@@ -24331,11 +24952,11 @@ function removeCanaries(root, o = {}) {
|
|
|
24331
24952
|
continue;
|
|
24332
24953
|
}
|
|
24333
24954
|
try {
|
|
24334
|
-
if (
|
|
24955
|
+
if (realpathSync5(dirname6(full)) !== trapReal) {
|
|
24335
24956
|
leave("it is not inside the trap folder.");
|
|
24336
24957
|
continue;
|
|
24337
24958
|
}
|
|
24338
|
-
if (!
|
|
24959
|
+
if (!readFileSync13(full, "utf8").includes(r.token)) {
|
|
24339
24960
|
leave("it no longer holds the token it was planted with, so it may not be the trap any more.");
|
|
24340
24961
|
continue;
|
|
24341
24962
|
}
|
|
@@ -24362,14 +24983,14 @@ function removeCanaries(root, o = {}) {
|
|
|
24362
24983
|
}
|
|
24363
24984
|
if (existing.madeDirs.includes(CANARY_TRAP_DIR)) rmdirIfEmpty(trapFolder);
|
|
24364
24985
|
if (existing.madeDirs.includes(".exorcist")) rmdirIfEmpty(stateFolder);
|
|
24365
|
-
if (o.stateDir &&
|
|
24986
|
+
if (o.stateDir && resolve12(o.stateDir) !== resolve12(root, ".exorcist")) clearPolicyCanaries(o.stateDir, recordsFile);
|
|
24366
24987
|
return { ok: true, removed, warnings };
|
|
24367
24988
|
}
|
|
24368
24989
|
function readPolicyObject(stateDir2) {
|
|
24369
24990
|
const path = policyPath(stateDir2);
|
|
24370
|
-
if (!
|
|
24991
|
+
if (!existsSync8(path)) return { ok: true, obj: {} };
|
|
24371
24992
|
try {
|
|
24372
|
-
const json2 = JSON.parse(
|
|
24993
|
+
const json2 = JSON.parse(readFileSync13(path, "utf8"));
|
|
24373
24994
|
if (!json2 || typeof json2 !== "object" || Array.isArray(json2)) return { ok: false, error: `${path} is not a JSON object.` };
|
|
24374
24995
|
return { ok: true, obj: json2 };
|
|
24375
24996
|
} catch (err) {
|
|
@@ -24381,7 +25002,7 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
24381
25002
|
if (!p.ok) return p;
|
|
24382
25003
|
try {
|
|
24383
25004
|
mkdirSync4(stateDir2, { recursive: true });
|
|
24384
|
-
writeFileSync4(policyPath(stateDir2), `${JSON.stringify({ ...p.obj, canaries:
|
|
25005
|
+
writeFileSync4(policyPath(stateDir2), `${JSON.stringify({ ...p.obj, canaries: resolve12(recordsFile) }, null, 2)}
|
|
24385
25006
|
`);
|
|
24386
25007
|
return { ok: true };
|
|
24387
25008
|
} catch (err) {
|
|
@@ -24390,7 +25011,7 @@ function setPolicyCanaries(stateDir2, recordsFile) {
|
|
|
24390
25011
|
}
|
|
24391
25012
|
function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
24392
25013
|
const p = readPolicyObject(stateDir2);
|
|
24393
|
-
if (!p.ok || p.obj["canaries"] !==
|
|
25014
|
+
if (!p.ok || p.obj["canaries"] !== resolve12(recordsFile)) return;
|
|
24394
25015
|
const { canaries: _gone, ...rest } = p.obj;
|
|
24395
25016
|
try {
|
|
24396
25017
|
if (Object.keys(rest).length === 0) rmSync2(policyPath(stateDir2));
|
|
@@ -24400,8 +25021,8 @@ function clearPolicyCanaries(stateDir2, recordsFile) {
|
|
|
24400
25021
|
}
|
|
24401
25022
|
}
|
|
24402
25023
|
function canariesFileFor(stateDir2, policyCanaries) {
|
|
24403
|
-
if (!policyCanaries) return
|
|
24404
|
-
return
|
|
25024
|
+
if (!policyCanaries) return join17(stateDir2, "canaries.json");
|
|
25025
|
+
return isAbsolute9(policyCanaries) ? policyCanaries : resolve12(stateDir2, policyCanaries);
|
|
24405
25026
|
}
|
|
24406
25027
|
function allStrings(value) {
|
|
24407
25028
|
const out = [];
|
|
@@ -24436,8 +25057,8 @@ function findCanary(value, canaries) {
|
|
|
24436
25057
|
init_zod();
|
|
24437
25058
|
import { createHash as createHash7, randomBytes as randomBytes3 } from "node:crypto";
|
|
24438
25059
|
import { spawnSync } from "node:child_process";
|
|
24439
|
-
import { lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as
|
|
24440
|
-
import { join as
|
|
25060
|
+
import { lstatSync as lstatSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync14, readdirSync as readdirSync5, renameSync as renameSync4, rmSync as rmSync3, unlinkSync, writeFileSync as writeFileSync5 } from "node:fs";
|
|
25061
|
+
import { join as join18 } from "node:path";
|
|
24441
25062
|
var SESSION_RULE_ID = "EX-027";
|
|
24442
25063
|
var SESSION_TTL_MS = 2 * 60 * 60 * 1e3;
|
|
24443
25064
|
var MAX_FACTS = 32;
|
|
@@ -24620,14 +25241,14 @@ var TMP_RE = /\.tmp$/;
|
|
|
24620
25241
|
function code(err) {
|
|
24621
25242
|
return err && typeof err === "object" && "code" in err ? String(err.code) : "error";
|
|
24622
25243
|
}
|
|
24623
|
-
var sessionsPath = (stateDir2) =>
|
|
25244
|
+
var sessionsPath = (stateDir2) => join18(stateDir2, "sessions");
|
|
24624
25245
|
var FileSessionStore = class {
|
|
24625
25246
|
constructor(stateDir2, key, ttlMs = SESSION_TTL_MS) {
|
|
24626
25247
|
this.key = key;
|
|
24627
25248
|
this.ttlMs = ttlMs;
|
|
24628
25249
|
if (!isSessionKey(key)) throw new Error(`Invalid session key "${key}".`);
|
|
24629
25250
|
this.root = sessionsPath(stateDir2);
|
|
24630
|
-
this.dir =
|
|
25251
|
+
this.dir = join18(this.root, key);
|
|
24631
25252
|
}
|
|
24632
25253
|
dir;
|
|
24633
25254
|
root;
|
|
@@ -24637,7 +25258,7 @@ var FileSessionStore = class {
|
|
|
24637
25258
|
const problems = [];
|
|
24638
25259
|
let names;
|
|
24639
25260
|
try {
|
|
24640
|
-
names =
|
|
25261
|
+
names = readdirSync5(this.dir);
|
|
24641
25262
|
} catch (err) {
|
|
24642
25263
|
if (code(err) === "ENOENT") return { records, problems };
|
|
24643
25264
|
return { records, problems: [`the session folder ${this.dir} could not be read (${code(err)})`] };
|
|
@@ -24649,7 +25270,7 @@ var FileSessionStore = class {
|
|
|
24649
25270
|
problems.push(`${name} in ${this.dir} is not a session record`);
|
|
24650
25271
|
continue;
|
|
24651
25272
|
}
|
|
24652
|
-
const path =
|
|
25273
|
+
const path = join18(this.dir, name);
|
|
24653
25274
|
let st;
|
|
24654
25275
|
try {
|
|
24655
25276
|
st = lstatSync4(path);
|
|
@@ -24668,7 +25289,7 @@ var FileSessionStore = class {
|
|
|
24668
25289
|
}
|
|
24669
25290
|
let json2;
|
|
24670
25291
|
try {
|
|
24671
|
-
json2 = JSON.parse(
|
|
25292
|
+
json2 = JSON.parse(readFileSync14(path, "utf8"));
|
|
24672
25293
|
} catch (err) {
|
|
24673
25294
|
if (code(err) !== "ENOENT") problems.push(`${name} is not valid JSON`);
|
|
24674
25295
|
continue;
|
|
@@ -24683,7 +25304,7 @@ var FileSessionStore = class {
|
|
|
24683
25304
|
return { records, problems };
|
|
24684
25305
|
}
|
|
24685
25306
|
write(record3) {
|
|
24686
|
-
const path =
|
|
25307
|
+
const path = join18(this.dir, `${record3.writer}.json`);
|
|
24687
25308
|
const tmp = `${path}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
|
|
24688
25309
|
try {
|
|
24689
25310
|
mkdirSync5(this.dir, { recursive: true, mode: 448 });
|
|
@@ -24707,24 +25328,24 @@ var FileSessionStore = class {
|
|
|
24707
25328
|
this.lastPrune = t;
|
|
24708
25329
|
const old = (st, age) => t - st.mtimeMs > age;
|
|
24709
25330
|
try {
|
|
24710
|
-
for (const name of
|
|
25331
|
+
for (const name of readdirSync5(this.dir)) {
|
|
24711
25332
|
if (name === `${own}.json`) continue;
|
|
24712
|
-
const p =
|
|
25333
|
+
const p = join18(this.dir, name);
|
|
24713
25334
|
const st = lstatSync4(p);
|
|
24714
25335
|
if (st.isFile() && old(st, TMP_RE.test(name) ? 6e4 : this.ttlMs)) unlinkSync(p);
|
|
24715
25336
|
}
|
|
24716
25337
|
} catch {
|
|
24717
25338
|
}
|
|
24718
25339
|
try {
|
|
24719
|
-
for (const name of
|
|
25340
|
+
for (const name of readdirSync5(this.root).slice(0, MAX_SESSION_DIRS)) {
|
|
24720
25341
|
if (name === this.key || !KEY_RE.test(name)) continue;
|
|
24721
|
-
const p =
|
|
25342
|
+
const p = join18(this.root, name);
|
|
24722
25343
|
const st = lstatSync4(p);
|
|
24723
25344
|
if (!st.isDirectory()) continue;
|
|
24724
|
-
const entries =
|
|
25345
|
+
const entries = readdirSync5(p);
|
|
24725
25346
|
const newest = entries.reduce((m, e) => {
|
|
24726
25347
|
try {
|
|
24727
|
-
return Math.max(m, lstatSync4(
|
|
25348
|
+
return Math.max(m, lstatSync4(join18(p, e)).mtimeMs);
|
|
24728
25349
|
} catch {
|
|
24729
25350
|
return m;
|
|
24730
25351
|
}
|
|
@@ -24739,7 +25360,7 @@ function liveSessions(stateDir2, now = /* @__PURE__ */ new Date(), ttlMs = SESSI
|
|
|
24739
25360
|
const root = sessionsPath(stateDir2);
|
|
24740
25361
|
let names;
|
|
24741
25362
|
try {
|
|
24742
|
-
names =
|
|
25363
|
+
names = readdirSync5(root);
|
|
24743
25364
|
} catch {
|
|
24744
25365
|
return [];
|
|
24745
25366
|
}
|
|
@@ -24899,7 +25520,7 @@ function macOsAuth(o = {}) {
|
|
|
24899
25520
|
} catch {
|
|
24900
25521
|
return { kind: "fail" };
|
|
24901
25522
|
}
|
|
24902
|
-
return new Promise((
|
|
25523
|
+
return new Promise((resolve31) => {
|
|
24903
25524
|
let settled = false;
|
|
24904
25525
|
let timer;
|
|
24905
25526
|
let child;
|
|
@@ -24907,7 +25528,7 @@ function macOsAuth(o = {}) {
|
|
|
24907
25528
|
if (settled) return;
|
|
24908
25529
|
settled = true;
|
|
24909
25530
|
if (timer !== void 0) clearTimeout(timer);
|
|
24910
|
-
|
|
25531
|
+
resolve31(r);
|
|
24911
25532
|
};
|
|
24912
25533
|
try {
|
|
24913
25534
|
const base = o.env ?? process.env;
|
|
@@ -25884,12 +26505,12 @@ var ShieldEngine = class {
|
|
|
25884
26505
|
|
|
25885
26506
|
// ../shield/src/proxy.ts
|
|
25886
26507
|
import { spawn } from "node:child_process";
|
|
25887
|
-
import { existsSync as
|
|
25888
|
-
import { dirname as
|
|
26508
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync8, readFileSync as readFileSync18, statSync as statSync11 } from "node:fs";
|
|
26509
|
+
import { dirname as dirname10 } from "node:path";
|
|
25889
26510
|
|
|
25890
26511
|
// ../shield/src/lockfile.ts
|
|
25891
|
-
import { existsSync as
|
|
25892
|
-
import { dirname as
|
|
26512
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
26513
|
+
import { dirname as dirname7, join as join19, parse as parsePath, resolve as resolve13 } from "node:path";
|
|
25893
26514
|
init_zod();
|
|
25894
26515
|
var Sha2562 = external_exports.string().regex(/^[0-9a-f]{64}$/);
|
|
25895
26516
|
var LockToolSchema = external_exports.object({
|
|
@@ -26062,12 +26683,12 @@ function seedFromLock(s, ls, report, o) {
|
|
|
26062
26683
|
var PROJECT_MARKERS2 = [".git", ".kiro", ".exorcist"];
|
|
26063
26684
|
function findLockFile(starts) {
|
|
26064
26685
|
for (const start of starts) {
|
|
26065
|
-
const { root } = parsePath(
|
|
26066
|
-
for (let dir =
|
|
26067
|
-
const candidate =
|
|
26068
|
-
if (
|
|
26069
|
-
if (PROJECT_MARKERS2.some((m) =>
|
|
26070
|
-
if (dir === root ||
|
|
26686
|
+
const { root } = parsePath(resolve13(start));
|
|
26687
|
+
for (let dir = resolve13(start); ; dir = dirname7(dir)) {
|
|
26688
|
+
const candidate = join19(dir, LOCK_FILE);
|
|
26689
|
+
if (existsSync9(candidate)) return candidate;
|
|
26690
|
+
if (PROJECT_MARKERS2.some((m) => existsSync9(join19(dir, m)))) break;
|
|
26691
|
+
if (dir === root || dirname7(dir) === dir) break;
|
|
26071
26692
|
}
|
|
26072
26693
|
}
|
|
26073
26694
|
return null;
|
|
@@ -26075,11 +26696,11 @@ function findLockFile(starts) {
|
|
|
26075
26696
|
|
|
26076
26697
|
// ../shield/src/vault.ts
|
|
26077
26698
|
import { createHash as createHash8, randomBytes as randomBytes4 } from "node:crypto";
|
|
26078
|
-
import { copyFileSync, existsSync as
|
|
26079
|
-
import { basename as
|
|
26699
|
+
import { copyFileSync, existsSync as existsSync10, mkdirSync as mkdirSync6, readFileSync as readFileSync15, readdirSync as readdirSync6, rmSync as rmSync4, statSync as statSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
26700
|
+
import { basename as basename7, dirname as dirname8, isAbsolute as isAbsolute10, join as join20, resolve as resolve14 } from "node:path";
|
|
26080
26701
|
init_zod();
|
|
26081
26702
|
var SafeRel = external_exports.string().min(1).max(1024).refine(
|
|
26082
|
-
(p) => !
|
|
26703
|
+
(p) => !isAbsolute10(p) && !p.includes("\\") && !p.includes("\0") && p.split("/").every((seg) => seg !== "" && seg !== "." && seg !== ".."),
|
|
26083
26704
|
"unsafe path"
|
|
26084
26705
|
);
|
|
26085
26706
|
var EditedFileSchema = external_exports.object({
|
|
@@ -26109,20 +26730,20 @@ function newId(label, now) {
|
|
|
26109
26730
|
return `${stamp}-${slug}-${randomBytes4(2).toString("hex")}`;
|
|
26110
26731
|
}
|
|
26111
26732
|
function entryDir(vaultDir, id) {
|
|
26112
|
-
return
|
|
26733
|
+
return join20(vaultDir, id);
|
|
26113
26734
|
}
|
|
26114
26735
|
function writeManifest(vaultDir, e) {
|
|
26115
|
-
writeFileSync6(
|
|
26736
|
+
writeFileSync6(join20(entryDir(vaultDir, e.id), "manifest.json"), `${JSON.stringify(e, null, 2)}
|
|
26116
26737
|
`, "utf8");
|
|
26117
26738
|
}
|
|
26118
26739
|
function listEntries(vaultDir) {
|
|
26119
|
-
if (!
|
|
26740
|
+
if (!existsSync10(vaultDir)) return [];
|
|
26120
26741
|
const out = [];
|
|
26121
|
-
for (const name of
|
|
26122
|
-
const file =
|
|
26123
|
-
if (!
|
|
26742
|
+
for (const name of readdirSync6(vaultDir)) {
|
|
26743
|
+
const file = join20(vaultDir, name, "manifest.json");
|
|
26744
|
+
if (!existsSync10(file)) continue;
|
|
26124
26745
|
try {
|
|
26125
|
-
const parsed = EntrySchema.safeParse(JSON.parse(
|
|
26746
|
+
const parsed = EntrySchema.safeParse(JSON.parse(readFileSync15(file, "utf8")));
|
|
26126
26747
|
if (parsed.success) out.push(parsed.data);
|
|
26127
26748
|
} catch {
|
|
26128
26749
|
}
|
|
@@ -26140,7 +26761,7 @@ function activeFor(vaultDir, target, serverName) {
|
|
|
26140
26761
|
function readConfig(path) {
|
|
26141
26762
|
let text;
|
|
26142
26763
|
try {
|
|
26143
|
-
text =
|
|
26764
|
+
text = readFileSync15(path, "utf8");
|
|
26144
26765
|
} catch {
|
|
26145
26766
|
return fail2(`Could not read ${path}.`);
|
|
26146
26767
|
}
|
|
@@ -26155,7 +26776,7 @@ function readConfig(path) {
|
|
|
26155
26776
|
var writeConfig = (path, cfg) => writeFileSync6(path, `${JSON.stringify(cfg, null, 2)}
|
|
26156
26777
|
`, "utf8");
|
|
26157
26778
|
function quarantineServer(o) {
|
|
26158
|
-
const configPath =
|
|
26779
|
+
const configPath = resolve14(o.configPath);
|
|
26159
26780
|
const cfg = readConfig(configPath);
|
|
26160
26781
|
if (!cfg.ok) return cfg;
|
|
26161
26782
|
const entry = cfg.value.mcpServers?.[o.serverName];
|
|
@@ -26169,7 +26790,7 @@ function quarantineServer(o) {
|
|
|
26169
26790
|
mkdirSync6(dir, { recursive: true });
|
|
26170
26791
|
const backup = `${JSON.stringify(entry, null, 2)}
|
|
26171
26792
|
`;
|
|
26172
|
-
writeFileSync6(
|
|
26793
|
+
writeFileSync6(join20(dir, "entry.json"), backup, "utf8");
|
|
26173
26794
|
const e = {
|
|
26174
26795
|
id,
|
|
26175
26796
|
kind: "mcp-server",
|
|
@@ -26186,17 +26807,17 @@ function quarantineServer(o) {
|
|
|
26186
26807
|
return { ok: true, value: e };
|
|
26187
26808
|
}
|
|
26188
26809
|
function quarantineFile(o) {
|
|
26189
|
-
const target =
|
|
26190
|
-
if (!
|
|
26810
|
+
const target = resolve14(o.filePath);
|
|
26811
|
+
if (!existsSync10(target) || !statSync9(target).isFile()) return fail2(`${target} is not a file.`);
|
|
26191
26812
|
if (activeFor(o.vaultDir, target)) return fail2(`${target} is already in the vault.`);
|
|
26192
26813
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
26193
|
-
const id = newId(
|
|
26814
|
+
const id = newId(basename7(target), now);
|
|
26194
26815
|
const dir = entryDir(o.vaultDir, id);
|
|
26195
|
-
mkdirSync6(
|
|
26196
|
-
const stored =
|
|
26816
|
+
mkdirSync6(join20(dir, "files"), { recursive: true });
|
|
26817
|
+
const stored = join20(dir, "files", basename7(target));
|
|
26197
26818
|
copyFileSync(target, stored);
|
|
26198
|
-
const digest = sha2562(
|
|
26199
|
-
if (digest !== sha2562(
|
|
26819
|
+
const digest = sha2562(readFileSync15(stored));
|
|
26820
|
+
if (digest !== sha2562(readFileSync15(target))) {
|
|
26200
26821
|
rmSync4(dir, { recursive: true, force: true });
|
|
26201
26822
|
return fail2("The backup did not match the original, so nothing was moved.");
|
|
26202
26823
|
}
|
|
@@ -26206,27 +26827,27 @@ function quarantineFile(o) {
|
|
|
26206
26827
|
return { ok: true, value: e };
|
|
26207
26828
|
}
|
|
26208
26829
|
function backupAndRewrite(o) {
|
|
26209
|
-
const root =
|
|
26830
|
+
const root = resolve14(o.root);
|
|
26210
26831
|
if (o.files.length === 0) return fail2("There are no files to change.");
|
|
26211
26832
|
for (const f of o.files) {
|
|
26212
26833
|
if (!SafeRel.safeParse(f.rel).success) return fail2(`Refusing to write outside ${root}: ${f.rel}`);
|
|
26213
|
-
const path =
|
|
26214
|
-
if (!
|
|
26215
|
-
if (sha2562(
|
|
26834
|
+
const path = join20(root, f.rel);
|
|
26835
|
+
if (!existsSync10(path)) return fail2(`${f.rel} is gone; nothing was changed.`);
|
|
26836
|
+
if (sha2562(readFileSync15(path)) !== sha2562(Buffer.from(f.before, "utf8"))) {
|
|
26216
26837
|
return fail2(`${f.rel} changed since it was scanned; nothing was changed. Run exorcise again.`);
|
|
26217
26838
|
}
|
|
26218
26839
|
}
|
|
26219
26840
|
const now = o.now ?? /* @__PURE__ */ new Date();
|
|
26220
|
-
const id = newId(`exorcise-${
|
|
26841
|
+
const id = newId(`exorcise-${basename7(root)}`, now);
|
|
26221
26842
|
const dir = entryDir(o.vaultDir, id);
|
|
26222
26843
|
const files = [];
|
|
26223
26844
|
try {
|
|
26224
26845
|
for (const f of o.files) {
|
|
26225
|
-
const stored =
|
|
26226
|
-
mkdirSync6(
|
|
26227
|
-
copyFileSync(
|
|
26228
|
-
const digest = sha2562(
|
|
26229
|
-
if (digest !== sha2562(
|
|
26846
|
+
const stored = join20(dir, "files", f.rel);
|
|
26847
|
+
mkdirSync6(dirname8(stored), { recursive: true });
|
|
26848
|
+
copyFileSync(join20(root, f.rel), stored);
|
|
26849
|
+
const digest = sha2562(readFileSync15(stored));
|
|
26850
|
+
if (digest !== sha2562(readFileSync15(join20(root, f.rel)))) throw new Error("mismatch");
|
|
26230
26851
|
files.push({ rel: f.rel, sha256: digest, after: sha2562(Buffer.from(f.after, "utf8")) });
|
|
26231
26852
|
}
|
|
26232
26853
|
} catch {
|
|
@@ -26244,57 +26865,57 @@ function backupAndRewrite(o) {
|
|
|
26244
26865
|
status: "quarantined"
|
|
26245
26866
|
};
|
|
26246
26867
|
writeManifest(o.vaultDir, e);
|
|
26247
|
-
for (const f of o.files) writeFileSync6(
|
|
26868
|
+
for (const f of o.files) writeFileSync6(join20(root, f.rel), f.after, "utf8");
|
|
26248
26869
|
return { ok: true, value: e };
|
|
26249
26870
|
}
|
|
26250
26871
|
function restoreExorcised(vaultDir, e, force) {
|
|
26251
26872
|
const files = e.files ?? [];
|
|
26252
26873
|
const blocked = files.filter((f) => {
|
|
26253
|
-
const path =
|
|
26254
|
-
if (!
|
|
26255
|
-
const now = sha2562(
|
|
26874
|
+
const path = join20(e.target, f.rel);
|
|
26875
|
+
if (!existsSync10(path)) return false;
|
|
26876
|
+
const now = sha2562(readFileSync15(path));
|
|
26256
26877
|
return now !== f.after && now !== f.sha256;
|
|
26257
26878
|
});
|
|
26258
26879
|
if (blocked.length > 0 && !force) {
|
|
26259
26880
|
return fail2(`${blocked.map((f) => f.rel).join(", ")} changed after the exorcism. Use --force to overwrite ${blocked.length === 1 ? "it" : "them"} with the backup.`);
|
|
26260
26881
|
}
|
|
26261
26882
|
for (const f of files) {
|
|
26262
|
-
const stored =
|
|
26263
|
-
if (sha2562(
|
|
26883
|
+
const stored = join20(entryDir(vaultDir, e.id), "files", f.rel);
|
|
26884
|
+
if (sha2562(readFileSync15(stored)) !== f.sha256) return fail2(`The backup of ${f.rel} is damaged (sha256 does not match); nothing was restored.`);
|
|
26264
26885
|
}
|
|
26265
26886
|
for (const f of files) {
|
|
26266
|
-
const path =
|
|
26267
|
-
mkdirSync6(
|
|
26268
|
-
copyFileSync(
|
|
26887
|
+
const path = join20(e.target, f.rel);
|
|
26888
|
+
mkdirSync6(dirname8(path), { recursive: true });
|
|
26889
|
+
copyFileSync(join20(entryDir(vaultDir, e.id), "files", f.rel), path);
|
|
26269
26890
|
}
|
|
26270
26891
|
return { ok: true, value: null };
|
|
26271
26892
|
}
|
|
26272
26893
|
function backupFile(vaultDir, e) {
|
|
26273
|
-
return e.kind === "mcp-server" ?
|
|
26894
|
+
return e.kind === "mcp-server" ? join20(entryDir(vaultDir, e.id), "entry.json") : join20(entryDir(vaultDir, e.id), "files", basename7(e.target));
|
|
26274
26895
|
}
|
|
26275
26896
|
function diffEntry(vaultDir, id) {
|
|
26276
26897
|
const e = getEntry(vaultDir, id);
|
|
26277
26898
|
if (!e) return fail2(`There is no vault entry "${id}".`);
|
|
26278
26899
|
if (e.kind === "exorcise") {
|
|
26279
26900
|
const parts = (e.files ?? []).map((f) => {
|
|
26280
|
-
const path =
|
|
26281
|
-
const before2 =
|
|
26282
|
-
const after2 =
|
|
26901
|
+
const path = join20(e.target, f.rel);
|
|
26902
|
+
const before2 = readFileSync15(join20(entryDir(vaultDir, e.id), "files", f.rel), "utf8");
|
|
26903
|
+
const after2 = existsSync10(path) ? readFileSync15(path, "utf8") : "";
|
|
26283
26904
|
return createTwoFilesPatch(`${f.rel} (backup)`, `${f.rel} (now)`, before2, after2, "", "", { context: 3 });
|
|
26284
26905
|
});
|
|
26285
26906
|
return { ok: true, value: parts.join("") };
|
|
26286
26907
|
}
|
|
26287
|
-
const before =
|
|
26908
|
+
const before = readFileSync15(backupFile(vaultDir, e), "utf8");
|
|
26288
26909
|
let after = "";
|
|
26289
26910
|
if (e.kind === "mcp-server") {
|
|
26290
26911
|
const cfg = readConfig(e.target);
|
|
26291
26912
|
const now = cfg.ok ? cfg.value.mcpServers?.[e.serverName ?? ""] : void 0;
|
|
26292
26913
|
after = now ? `${JSON.stringify(now, null, 2)}
|
|
26293
26914
|
` : "";
|
|
26294
|
-
} else if (
|
|
26295
|
-
after =
|
|
26915
|
+
} else if (existsSync10(e.target)) {
|
|
26916
|
+
after = readFileSync15(e.target, "utf8");
|
|
26296
26917
|
}
|
|
26297
|
-
const label = e.kind === "mcp-server" ? `${e.serverName} in ${
|
|
26918
|
+
const label = e.kind === "mcp-server" ? `${e.serverName} in ${basename7(e.target)}` : basename7(e.target);
|
|
26298
26919
|
return { ok: true, value: createTwoFilesPatch(`${label} (backup)`, `${label} (now)`, before, after, "", "", { context: 3 }) };
|
|
26299
26920
|
}
|
|
26300
26921
|
function restoreEntry(vaultDir, id, opts = {}) {
|
|
@@ -26307,7 +26928,7 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
26307
26928
|
} else if (e.kind === "mcp-server") {
|
|
26308
26929
|
const cfg = readConfig(e.target);
|
|
26309
26930
|
if (!cfg.ok) return cfg;
|
|
26310
|
-
const original = JSON.parse(
|
|
26931
|
+
const original = JSON.parse(readFileSync15(backupFile(vaultDir, e), "utf8"));
|
|
26311
26932
|
const servers = cfg.value.mcpServers ??= {};
|
|
26312
26933
|
const current = servers[e.serverName ?? ""];
|
|
26313
26934
|
if (!current) {
|
|
@@ -26320,10 +26941,10 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
26320
26941
|
writeConfig(e.target, cfg.value);
|
|
26321
26942
|
} else {
|
|
26322
26943
|
const stored = backupFile(vaultDir, e);
|
|
26323
|
-
if (
|
|
26944
|
+
if (existsSync10(e.target) && sha2562(readFileSync15(e.target)) !== e.sha256 && !opts.force) {
|
|
26324
26945
|
return fail2(`${e.target} exists and is different from the quarantined file. Use --force to overwrite it.`);
|
|
26325
26946
|
}
|
|
26326
|
-
mkdirSync6(
|
|
26947
|
+
mkdirSync6(resolve14(e.target, ".."), { recursive: true });
|
|
26327
26948
|
copyFileSync(stored, e.target);
|
|
26328
26949
|
}
|
|
26329
26950
|
const done = { ...e, status: "restored" };
|
|
@@ -26333,14 +26954,14 @@ function restoreEntry(vaultDir, id, opts = {}) {
|
|
|
26333
26954
|
|
|
26334
26955
|
// ../shield/src/events.ts
|
|
26335
26956
|
init_zod();
|
|
26336
|
-
import { closeSync as
|
|
26337
|
-
import { join as
|
|
26957
|
+
import { closeSync as closeSync5, constants as constants3, fstatSync as fstatSync3, lstatSync as lstatSync6, mkdirSync as mkdirSync7, openSync as openSync5, readSync as readSync5, renameSync as renameSync6, rmdirSync as rmdirSync2, writeSync as writeSync2 } from "node:fs";
|
|
26958
|
+
import { join as join22 } from "node:path";
|
|
26338
26959
|
|
|
26339
26960
|
// ../shield/src/chain.ts
|
|
26340
26961
|
init_zod();
|
|
26341
26962
|
import { createHash as createHash9, randomBytes as randomBytes5 } from "node:crypto";
|
|
26342
|
-
import { closeSync as
|
|
26343
|
-
import { join as
|
|
26963
|
+
import { closeSync as closeSync4, constants as constants2, fstatSync as fstatSync2, lstatSync as lstatSync5, openSync as openSync4, readFileSync as readFileSync16, readSync as readSync4, renameSync as renameSync5, unlinkSync as unlinkSync2, writeSync } from "node:fs";
|
|
26964
|
+
import { join as join21 } from "node:path";
|
|
26344
26965
|
|
|
26345
26966
|
// ../shield/src/chain-core.ts
|
|
26346
26967
|
init_zod();
|
|
@@ -26546,8 +27167,8 @@ function verifyChain(lines, head, genesis, opts) {
|
|
|
26546
27167
|
// ../shield/src/chain.ts
|
|
26547
27168
|
var ok = (value) => ({ ok: true, value });
|
|
26548
27169
|
var fail3 = (error2) => ({ ok: false, error: error2 });
|
|
26549
|
-
var headPath = (dir) =>
|
|
26550
|
-
var genesisPath = (dir) =>
|
|
27170
|
+
var headPath = (dir) => join21(dir, "events.head.json");
|
|
27171
|
+
var genesisPath = (dir) => join21(dir, "events.genesis.json");
|
|
26551
27172
|
var GenesisFileSchema = external_exports.object({ v: external_exports.literal(1), genesis: external_exports.string().regex(HEX64) }).strict();
|
|
26552
27173
|
var MAX_FILE_BYTES4 = 4096;
|
|
26553
27174
|
function errCode(e) {
|
|
@@ -26559,15 +27180,15 @@ function readSmall(path) {
|
|
|
26559
27180
|
const st = lstatSync5(path, { throwIfNoEntry: false });
|
|
26560
27181
|
if (st === void 0) return ok(null);
|
|
26561
27182
|
if (!st.isFile()) return fail3("not a regular file");
|
|
26562
|
-
fd =
|
|
27183
|
+
fd = openSync4(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
26563
27184
|
if (fstatSync2(fd).size > MAX_FILE_BYTES4) return fail3("file is too large");
|
|
26564
|
-
return ok(
|
|
27185
|
+
return ok(readFileSync16(fd, "utf8"));
|
|
26565
27186
|
} catch (e) {
|
|
26566
27187
|
return errCode(e) === "ENOENT" ? ok(null) : fail3(`could not read (${errCode(e)})`);
|
|
26567
27188
|
} finally {
|
|
26568
27189
|
if (fd !== null) {
|
|
26569
27190
|
try {
|
|
26570
|
-
|
|
27191
|
+
closeSync4(fd);
|
|
26571
27192
|
} catch {
|
|
26572
27193
|
}
|
|
26573
27194
|
}
|
|
@@ -26593,7 +27214,7 @@ function readGenesis(dir) {
|
|
|
26593
27214
|
function writeNew(path, text) {
|
|
26594
27215
|
let fd = null;
|
|
26595
27216
|
try {
|
|
26596
|
-
fd =
|
|
27217
|
+
fd = openSync4(path, constants2.O_WRONLY | constants2.O_CREAT | constants2.O_EXCL | constants2.O_NOFOLLOW, 384);
|
|
26597
27218
|
writeSync(fd, text);
|
|
26598
27219
|
return ok(void 0);
|
|
26599
27220
|
} catch (e) {
|
|
@@ -26601,7 +27222,7 @@ function writeNew(path, text) {
|
|
|
26601
27222
|
} finally {
|
|
26602
27223
|
if (fd !== null) {
|
|
26603
27224
|
try {
|
|
26604
|
-
|
|
27225
|
+
closeSync4(fd);
|
|
26605
27226
|
} catch {
|
|
26606
27227
|
}
|
|
26607
27228
|
}
|
|
@@ -26632,7 +27253,7 @@ function readHead(dir) {
|
|
|
26632
27253
|
function writeHeadAtomic(dir, head) {
|
|
26633
27254
|
const parsed = HeadRecordSchema.safeParse(head);
|
|
26634
27255
|
if (!parsed.success) return fail3("head file: record is not valid");
|
|
26635
|
-
const tmp =
|
|
27256
|
+
const tmp = join21(dir, `events.head.json.${process.pid}.${randomBytes5(4).toString("hex")}.tmp`);
|
|
26636
27257
|
const w = writeNew(tmp, `${JSON.stringify(parsed.data)}
|
|
26637
27258
|
`);
|
|
26638
27259
|
if (!w.ok) return fail3(`head file: could not write (${w.error})`);
|
|
@@ -26654,7 +27275,7 @@ function readEventsInto(path, out) {
|
|
|
26654
27275
|
const st = lstatSync5(path, { throwIfNoEntry: false });
|
|
26655
27276
|
if (st === void 0) return ok(null);
|
|
26656
27277
|
if (!st.isFile()) return fail3("not a regular file");
|
|
26657
|
-
fd =
|
|
27278
|
+
fd = openSync4(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
26658
27279
|
const buf = Buffer.alloc(CHUNK);
|
|
26659
27280
|
let carry = Buffer.alloc(0);
|
|
26660
27281
|
const take = (raw) => {
|
|
@@ -26671,7 +27292,7 @@ function readEventsInto(path, out) {
|
|
|
26671
27292
|
if (r.success) out.push(r.data);
|
|
26672
27293
|
};
|
|
26673
27294
|
for (; ; ) {
|
|
26674
|
-
const n =
|
|
27295
|
+
const n = readSync4(fd, buf, 0, CHUNK, null);
|
|
26675
27296
|
if (n === 0) break;
|
|
26676
27297
|
let from = 0;
|
|
26677
27298
|
for (; ; ) {
|
|
@@ -26693,7 +27314,7 @@ function readEventsInto(path, out) {
|
|
|
26693
27314
|
} finally {
|
|
26694
27315
|
if (fd !== null) {
|
|
26695
27316
|
try {
|
|
26696
|
-
|
|
27317
|
+
closeSync4(fd);
|
|
26697
27318
|
} catch {
|
|
26698
27319
|
}
|
|
26699
27320
|
}
|
|
@@ -26723,9 +27344,9 @@ function verifyLogDir(dir, opts) {
|
|
|
26723
27344
|
}
|
|
26724
27345
|
|
|
26725
27346
|
// ../shield/src/events.ts
|
|
26726
|
-
var eventsPath = (dir) =>
|
|
26727
|
-
var oldEventsPath = (dir) =>
|
|
26728
|
-
var lockPath = (dir) =>
|
|
27347
|
+
var eventsPath = (dir) => join22(dir, "events.jsonl");
|
|
27348
|
+
var oldEventsPath = (dir) => join22(dir, "events.1.jsonl");
|
|
27349
|
+
var lockPath = (dir) => join22(dir, "events.lock");
|
|
26729
27350
|
var MAX_EVENT_BYTES = 1024 * 1024;
|
|
26730
27351
|
var MAX_LINE_BYTES = 8 * 1024;
|
|
26731
27352
|
var STALE_LOCK_MS = 1e4;
|
|
@@ -26933,7 +27554,7 @@ var EventLog = class {
|
|
|
26933
27554
|
}
|
|
26934
27555
|
}
|
|
26935
27556
|
const flags = constants3.O_WRONLY | constants3.O_APPEND | constants3.O_CREAT | (constants3.O_NOFOLLOW ?? 0);
|
|
26936
|
-
const fd =
|
|
27557
|
+
const fd = openSync5(this.path, flags, 384);
|
|
26937
27558
|
try {
|
|
26938
27559
|
if (!fstatSync3(fd).isFile()) {
|
|
26939
27560
|
this.fail(`${this.path} is not a regular file`);
|
|
@@ -26941,7 +27562,7 @@ var EventLog = class {
|
|
|
26941
27562
|
}
|
|
26942
27563
|
writeSync2(fd, line);
|
|
26943
27564
|
} finally {
|
|
26944
|
-
|
|
27565
|
+
closeSync5(fd);
|
|
26945
27566
|
}
|
|
26946
27567
|
return true;
|
|
26947
27568
|
}
|
|
@@ -27015,7 +27636,7 @@ function parseEventLines(text) {
|
|
|
27015
27636
|
function readFrom(path, from) {
|
|
27016
27637
|
let fd;
|
|
27017
27638
|
try {
|
|
27018
|
-
fd =
|
|
27639
|
+
fd = openSync5(path, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0));
|
|
27019
27640
|
} catch {
|
|
27020
27641
|
return null;
|
|
27021
27642
|
}
|
|
@@ -27032,7 +27653,7 @@ function readFrom(path, from) {
|
|
|
27032
27653
|
const buf = Buffer.alloc(len);
|
|
27033
27654
|
let got = 0;
|
|
27034
27655
|
while (got < len) {
|
|
27035
|
-
const n =
|
|
27656
|
+
const n = readSync5(fd, buf, got, len - got, start + got);
|
|
27036
27657
|
if (n === 0) break;
|
|
27037
27658
|
got += n;
|
|
27038
27659
|
}
|
|
@@ -27042,7 +27663,7 @@ function readFrom(path, from) {
|
|
|
27042
27663
|
if (dropFirst) text = text.slice(text.indexOf("\n") + 1);
|
|
27043
27664
|
return { text, end: start + lastNl + 1, st };
|
|
27044
27665
|
} finally {
|
|
27045
|
-
|
|
27666
|
+
closeSync5(fd);
|
|
27046
27667
|
}
|
|
27047
27668
|
}
|
|
27048
27669
|
var EventTail = class {
|
|
@@ -27103,15 +27724,15 @@ var EventTail = class {
|
|
|
27103
27724
|
|
|
27104
27725
|
// ../shield/src/launch.ts
|
|
27105
27726
|
import { createHash as createHash10 } from "node:crypto";
|
|
27106
|
-
import { existsSync as
|
|
27107
|
-
import { dirname as
|
|
27727
|
+
import { existsSync as existsSync11, readFileSync as readFileSync17, statSync as statSync10 } from "node:fs";
|
|
27728
|
+
import { dirname as dirname9, isAbsolute as isAbsolute11, join as join23, parse as parsePath2, relative as relative9, resolve as resolve15, sep as sep4 } from "node:path";
|
|
27108
27729
|
var sha2563 = (b) => createHash10("sha256").update(b).digest("hex");
|
|
27109
27730
|
var MAX_HASHED_BYTES = 64 * 1024 * 1024;
|
|
27110
27731
|
var fsReader = (path) => {
|
|
27111
27732
|
try {
|
|
27112
|
-
const st =
|
|
27733
|
+
const st = statSync10(path);
|
|
27113
27734
|
if (!st.isFile()) return { kind: "other" };
|
|
27114
|
-
return { kind: "file", size: st.size, mtimeMs: st.mtimeMs, read: () =>
|
|
27735
|
+
return { kind: "file", size: st.size, mtimeMs: st.mtimeMs, read: () => readFileSync17(path) };
|
|
27115
27736
|
} catch {
|
|
27116
27737
|
return { kind: "other" };
|
|
27117
27738
|
}
|
|
@@ -27127,7 +27748,7 @@ var RUNNERS2 = {
|
|
|
27127
27748
|
bun: ["x"],
|
|
27128
27749
|
pipx: ["run"]
|
|
27129
27750
|
};
|
|
27130
|
-
var
|
|
27751
|
+
var INTERPRETERS2 = /^(node|nodejs|deno|bun|python\d*(\.\d+)?|pythonw|uv|uvx|npx|pnpx|bunx|pnpm|npm|yarn|pipx|java|ruby|php|dotnet|docker|podman|sh|bash|zsh|cmd|powershell|pwsh)$/i;
|
|
27131
27752
|
var baseName3 = (c) => c.split(/[\\/]/).pop()?.replace(/\.(cmd|exe)$/i, "") ?? c;
|
|
27132
27753
|
function packageSpec(command, args) {
|
|
27133
27754
|
const sub = RUNNERS2[baseName3(command)];
|
|
@@ -27178,17 +27799,17 @@ function launchEntryOf(entry) {
|
|
|
27178
27799
|
}
|
|
27179
27800
|
var PROJECT_MARKERS3 = [".git", ".kiro"];
|
|
27180
27801
|
function configLabel(configPath) {
|
|
27181
|
-
const abs =
|
|
27802
|
+
const abs = resolve15(configPath);
|
|
27182
27803
|
const { root } = parsePath2(abs);
|
|
27183
|
-
for (let dir =
|
|
27184
|
-
if (PROJECT_MARKERS3.some((m) =>
|
|
27185
|
-
if (dir === root ||
|
|
27804
|
+
for (let dir = dirname9(abs); ; dir = dirname9(dir)) {
|
|
27805
|
+
if (PROJECT_MARKERS3.some((m) => existsSync11(join23(dir, m)))) return relative9(dir, abs).split(sep4).join("/");
|
|
27806
|
+
if (dir === root || dirname9(dir) === dir) return abs;
|
|
27186
27807
|
}
|
|
27187
27808
|
}
|
|
27188
27809
|
function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
27189
27810
|
const fileLine = (label, value) => {
|
|
27190
27811
|
if (value.length === 0 || value.length > 4096) return void 0;
|
|
27191
|
-
const path =
|
|
27812
|
+
const path = isAbsolute11(value) ? value : resolve15(cwd, value);
|
|
27192
27813
|
const f = reader(path);
|
|
27193
27814
|
if (f.kind !== "file") return void 0;
|
|
27194
27815
|
const content = f.size <= MAX_HASHED_BYTES ? `sha256:${sha2563(f.read())}` : `size:${f.size} mtime:${Math.round(f.mtimeMs)}`;
|
|
@@ -27196,7 +27817,7 @@ function launchFingerprint(command, args, cwd, reader = fsReader, entry = {}) {
|
|
|
27196
27817
|
};
|
|
27197
27818
|
const parts = [];
|
|
27198
27819
|
const commandIsPath = /[\\/]/.test(command);
|
|
27199
|
-
const own = commandIsPath && !
|
|
27820
|
+
const own = commandIsPath && !INTERPRETERS2.test(baseName3(command)) ? fileLine("command", command) : void 0;
|
|
27200
27821
|
parts.push(own ?? `command ${command}`);
|
|
27201
27822
|
const spec = packageSpec(command, args);
|
|
27202
27823
|
if (spec) parts.push(`package ${spec}`);
|
|
@@ -27238,11 +27859,11 @@ function checkLaunch(s, pin, now = /* @__PURE__ */ new Date()) {
|
|
|
27238
27859
|
// ../shield/src/ai-review.ts
|
|
27239
27860
|
var NONE = { block: [], warn: [] };
|
|
27240
27861
|
function withTimeout(p, ms) {
|
|
27241
|
-
return new Promise((
|
|
27862
|
+
return new Promise((resolve31, reject) => {
|
|
27242
27863
|
const t = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms);
|
|
27243
27864
|
p.then((v) => {
|
|
27244
27865
|
clearTimeout(t);
|
|
27245
|
-
|
|
27866
|
+
resolve31(v);
|
|
27246
27867
|
}, (e) => {
|
|
27247
27868
|
clearTimeout(t);
|
|
27248
27869
|
reject(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -27356,16 +27977,16 @@ async function prepareShield(o) {
|
|
|
27356
27977
|
log(canariesFile.error);
|
|
27357
27978
|
return FAIL_CLOSED_EXIT;
|
|
27358
27979
|
}
|
|
27359
|
-
if (policy.policy.canaries && !
|
|
27980
|
+
if (policy.policy.canaries && !existsSync12(canariesAt)) log(`The policy names canary records at ${canariesAt}, but there is no such file; no canary traps are active.`);
|
|
27360
27981
|
const canaries = canariesFile.canaries.map((r) => ({ token: r.token, file: r.file }));
|
|
27361
27982
|
if (canaries.length > 0) log(`Watching for ${canaries.length} canary token${canaries.length === 1 ? "" : "s"} (EX-022).`);
|
|
27362
27983
|
let lockExpected;
|
|
27363
27984
|
let lockLaunch;
|
|
27364
|
-
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [
|
|
27365
|
-
if (lockFile &&
|
|
27985
|
+
const lockFile = o.lockPath === void 0 ? findLockFile([...o.configPath ? [dirname10(o.configPath)] : [], process.cwd()]) : o.lockPath;
|
|
27986
|
+
if (lockFile && existsSync12(lockFile)) {
|
|
27366
27987
|
let text;
|
|
27367
27988
|
try {
|
|
27368
|
-
text =
|
|
27989
|
+
text = readFileSync18(lockFile, "utf8");
|
|
27369
27990
|
} catch {
|
|
27370
27991
|
log(`Could not read ${lockFile}; running with the local pins only.`);
|
|
27371
27992
|
}
|
|
@@ -27463,7 +28084,7 @@ async function prepareShield(o) {
|
|
|
27463
28084
|
let dirty = false;
|
|
27464
28085
|
const readMtime = () => {
|
|
27465
28086
|
try {
|
|
27466
|
-
return
|
|
28087
|
+
return statSync11(statePath(o.dir)).mtimeMs;
|
|
27467
28088
|
} catch {
|
|
27468
28089
|
return 0;
|
|
27469
28090
|
}
|
|
@@ -27594,7 +28215,7 @@ async function prepareShield(o) {
|
|
|
27594
28215
|
function readConfigEntry(configPath, server) {
|
|
27595
28216
|
let json2;
|
|
27596
28217
|
try {
|
|
27597
|
-
json2 = JSON.parse(
|
|
28218
|
+
json2 = JSON.parse(readFileSync18(configPath, "utf8"));
|
|
27598
28219
|
} catch {
|
|
27599
28220
|
return { ok: false, error: "the MCP config could not be read as JSON" };
|
|
27600
28221
|
}
|
|
@@ -27677,16 +28298,16 @@ async function runProxy(o) {
|
|
|
27677
28298
|
});
|
|
27678
28299
|
prepared.attach(run2);
|
|
27679
28300
|
const stopWatch = prepared.watch(run2);
|
|
27680
|
-
return await new Promise((
|
|
28301
|
+
return await new Promise((resolve31) => {
|
|
27681
28302
|
child.on("error", (err) => {
|
|
27682
28303
|
stopWatch();
|
|
27683
28304
|
log(`Could not start "${o.command}": ${err.message}`);
|
|
27684
|
-
|
|
28305
|
+
resolve31(127);
|
|
27685
28306
|
});
|
|
27686
28307
|
child.on("close", (code3) => {
|
|
27687
28308
|
stopWatch();
|
|
27688
28309
|
for (const l of fromServer.flush()) fromServerLine(l);
|
|
27689
|
-
void serverQueue.then(() =>
|
|
28310
|
+
void serverQueue.then(() => resolve31(code3 ?? 1));
|
|
27690
28311
|
});
|
|
27691
28312
|
});
|
|
27692
28313
|
}
|
|
@@ -27718,9 +28339,9 @@ var SseParser = class {
|
|
|
27718
28339
|
const out = [];
|
|
27719
28340
|
let nl = this.buf.search(/\r\n|\n|\r/);
|
|
27720
28341
|
while (nl !== -1) {
|
|
27721
|
-
const
|
|
28342
|
+
const sep6 = this.buf.startsWith("\r\n", nl) ? 2 : 1;
|
|
27722
28343
|
const line = this.buf.slice(0, nl);
|
|
27723
|
-
this.buf = this.buf.slice(nl +
|
|
28344
|
+
this.buf = this.buf.slice(nl + sep6);
|
|
27724
28345
|
if (line === "") {
|
|
27725
28346
|
if (this.data.length > 0) out.push(this.data.join("\n"));
|
|
27726
28347
|
this.data = [];
|
|
@@ -27891,7 +28512,7 @@ async function runRemoteProxy(o) {
|
|
|
27891
28512
|
const fromClient = new LineSplitter();
|
|
27892
28513
|
prepared.attach(deliver);
|
|
27893
28514
|
const stopWatch = prepared.watch(deliver);
|
|
27894
|
-
return await new Promise((
|
|
28515
|
+
return await new Promise((resolve31) => {
|
|
27895
28516
|
stdin.on("data", (chunk) => {
|
|
27896
28517
|
for (const l of fromClient.push(chunk)) deliver(engine.onClientLine(l));
|
|
27897
28518
|
});
|
|
@@ -27911,19 +28532,19 @@ async function runRemoteProxy(o) {
|
|
|
27911
28532
|
} catch {
|
|
27912
28533
|
}
|
|
27913
28534
|
}
|
|
27914
|
-
|
|
28535
|
+
resolve31(0);
|
|
27915
28536
|
})();
|
|
27916
28537
|
});
|
|
27917
28538
|
});
|
|
27918
28539
|
}
|
|
27919
28540
|
|
|
27920
28541
|
// ../shield/src/locate.ts
|
|
27921
|
-
import { existsSync as
|
|
27922
|
-
import { dirname as
|
|
28542
|
+
import { existsSync as existsSync13, readdirSync as readdirSync7, statSync as statSync12 } from "node:fs";
|
|
28543
|
+
import { dirname as dirname11, isAbsolute as isAbsolute12, join as join24, parse as parse2, resolve as resolve16 } from "node:path";
|
|
27923
28544
|
import { fileURLToPath } from "node:url";
|
|
27924
28545
|
function hasDefinitions(dir) {
|
|
27925
28546
|
try {
|
|
27926
|
-
return
|
|
28547
|
+
return statSync12(dir).isDirectory() && readdirSync7(dir).some((f) => /^EX-\d{3}.*\.yaml$/.test(f));
|
|
27927
28548
|
} catch {
|
|
27928
28549
|
return false;
|
|
27929
28550
|
}
|
|
@@ -27931,28 +28552,28 @@ function hasDefinitions(dir) {
|
|
|
27931
28552
|
function findDefinitionsDir(o) {
|
|
27932
28553
|
const env = o.env ?? process.env;
|
|
27933
28554
|
const cwd = o.cwd ?? process.cwd();
|
|
27934
|
-
if (o.explicit) return
|
|
28555
|
+
if (o.explicit) return resolve16(cwd, o.explicit);
|
|
27935
28556
|
const fromEnv = env["EXORCIST_DEFINITIONS"];
|
|
27936
|
-
if (fromEnv) return
|
|
28557
|
+
if (fromEnv) return resolve16(cwd, fromEnv);
|
|
27937
28558
|
const installed = findActiveInstalledSet({ env, ...o.publicKeyPem ? { publicKeyPem: o.publicKeyPem } : {} });
|
|
27938
28559
|
if (installed && hasDefinitions(installed.definitionsDir)) return installed.definitionsDir;
|
|
27939
|
-
const here =
|
|
27940
|
-
const candidates = [
|
|
28560
|
+
const here = dirname11(fileURLToPath(o.callerUrl));
|
|
28561
|
+
const candidates = [join24(here, "..", "definitions"), join24(here, "..", "..", "..", "definitions"), join24(cwd, "definitions")];
|
|
27941
28562
|
return candidates.find(hasDefinitions) ?? null;
|
|
27942
28563
|
}
|
|
27943
28564
|
var PROJECT_MARKERS4 = [".exorcist", ".kiro", ".git"];
|
|
27944
28565
|
function findStateDir(o = {}) {
|
|
27945
28566
|
const env = o.env ?? process.env;
|
|
27946
|
-
const cwd =
|
|
27947
|
-
if (o.explicit) return
|
|
28567
|
+
const cwd = resolve16(o.cwd ?? process.cwd());
|
|
28568
|
+
if (o.explicit) return resolve16(cwd, o.explicit);
|
|
27948
28569
|
const fromEnv = env["EXORCIST_DIR"];
|
|
27949
|
-
if (fromEnv) return
|
|
28570
|
+
if (fromEnv) return isAbsolute12(fromEnv) ? fromEnv : resolve16(cwd, fromEnv);
|
|
27950
28571
|
const { root } = parse2(cwd);
|
|
27951
|
-
for (let dir = cwd; ; dir =
|
|
27952
|
-
if (PROJECT_MARKERS4.some((m) =>
|
|
27953
|
-
if (dir === root ||
|
|
28572
|
+
for (let dir = cwd; ; dir = dirname11(dir)) {
|
|
28573
|
+
if (PROJECT_MARKERS4.some((m) => existsSync13(join24(dir, m)))) return join24(dir, ".exorcist");
|
|
28574
|
+
if (dir === root || dirname11(dir) === dir) break;
|
|
27954
28575
|
}
|
|
27955
|
-
return
|
|
28576
|
+
return join24(cwd, ".exorcist");
|
|
27956
28577
|
}
|
|
27957
28578
|
|
|
27958
28579
|
// ../shield/src/wrap.ts
|
|
@@ -28094,11 +28715,11 @@ function unwrapConfig(config2) {
|
|
|
28094
28715
|
unwrapped.push(name);
|
|
28095
28716
|
continue;
|
|
28096
28717
|
}
|
|
28097
|
-
const
|
|
28098
|
-
const original = args[
|
|
28099
|
-
if (
|
|
28718
|
+
const sep6 = separatorIndex(args);
|
|
28719
|
+
const original = args[sep6 + 1];
|
|
28720
|
+
if (sep6 === -1 || original === void 0) continue;
|
|
28100
28721
|
entry["command"] = original;
|
|
28101
|
-
const rest = args.slice(
|
|
28722
|
+
const rest = args.slice(sep6 + 2);
|
|
28102
28723
|
if (rest.length > 0) entry["args"] = rest;
|
|
28103
28724
|
else delete entry["args"];
|
|
28104
28725
|
unwrapped.push(name);
|
|
@@ -28135,8 +28756,8 @@ var DEFAULT_DIR = "the project's .exorcist folder (or EXORCIST_DIR)";
|
|
|
28135
28756
|
// src/commands/on-access.ts
|
|
28136
28757
|
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
28137
28758
|
import { execFile as execFile4 } from "node:child_process";
|
|
28138
|
-
import { existsSync as
|
|
28139
|
-
import { resolve as
|
|
28759
|
+
import { existsSync as existsSync14, statSync as statSync13 } from "node:fs";
|
|
28760
|
+
import { resolve as resolve17 } from "node:path";
|
|
28140
28761
|
import { createInterface } from "node:readline";
|
|
28141
28762
|
var ALLOW_READ_HELP = `Usage: exorcist allow-read <file>
|
|
28142
28763
|
|
|
@@ -28220,7 +28841,7 @@ function recordApproval(audit, outcome, now) {
|
|
|
28220
28841
|
return false;
|
|
28221
28842
|
}
|
|
28222
28843
|
}
|
|
28223
|
-
function
|
|
28844
|
+
function eventCwd2(stdin) {
|
|
28224
28845
|
try {
|
|
28225
28846
|
const parsed = JSON.parse(stdin);
|
|
28226
28847
|
if (typeof parsed?.cwd === "string" && parsed.cwd) return parsed.cwd;
|
|
@@ -28229,7 +28850,7 @@ function eventCwd(stdin) {
|
|
|
28229
28850
|
return process.cwd();
|
|
28230
28851
|
}
|
|
28231
28852
|
async function onAccessCommand(stdin, io) {
|
|
28232
|
-
const cwd =
|
|
28853
|
+
const cwd = eventCwd2(stdin);
|
|
28233
28854
|
let defs = [];
|
|
28234
28855
|
const defsDir = findDefinitionsDir2();
|
|
28235
28856
|
if (defsDir) {
|
|
@@ -28328,8 +28949,8 @@ ${ALLOW_READ_HELP}`);
|
|
|
28328
28949
|
io.err("exorcist allow-read only runs in an interactive terminal: the user must review the file and run it themselves. Nothing was allowed.");
|
|
28329
28950
|
return 1;
|
|
28330
28951
|
}
|
|
28331
|
-
const file =
|
|
28332
|
-
if (!
|
|
28952
|
+
const file = resolve17(target);
|
|
28953
|
+
if (!existsSync14(file) || !statSync13(file).isFile()) {
|
|
28333
28954
|
io.err(`Not a readable file: ${shownName(target)}`);
|
|
28334
28955
|
return 1;
|
|
28335
28956
|
}
|
|
@@ -28475,13 +29096,13 @@ async function alertsCommand(argv, io) {
|
|
|
28475
29096
|
if (!h.ok) io.out(`Event log head: unreadable (${h.error.replace(/[^\x20-\x7e]/g, "?")}).`);
|
|
28476
29097
|
else io.out(h.value === null ? "Event log head: none yet (nothing has been logged in this folder)." : `Event log head: ${h.value.hash} (event ${h.value.seq})`);
|
|
28477
29098
|
};
|
|
28478
|
-
if (!
|
|
29099
|
+
if (!existsSync15(file)) {
|
|
28479
29100
|
io.out("No alerts.");
|
|
28480
29101
|
printHead();
|
|
28481
29102
|
return 0;
|
|
28482
29103
|
}
|
|
28483
29104
|
const n = Math.max(1, Number.parseInt(str4(p.values["last"]) ?? "20", 10) || 20);
|
|
28484
|
-
const lines =
|
|
29105
|
+
const lines = readFileSync19(file, "utf8").split("\n").filter(Boolean).slice(-n);
|
|
28485
29106
|
for (const l of lines) {
|
|
28486
29107
|
try {
|
|
28487
29108
|
const a = JSON.parse(l);
|
|
@@ -28494,17 +29115,17 @@ async function alertsCommand(argv, io) {
|
|
|
28494
29115
|
}
|
|
28495
29116
|
|
|
28496
29117
|
// src/commands/baseline.ts
|
|
28497
|
-
import { statSync as
|
|
28498
|
-
import { join as
|
|
29118
|
+
import { statSync as statSync16, writeFileSync as writeFileSync8 } from "node:fs";
|
|
29119
|
+
import { join as join27, resolve as resolve20 } from "node:path";
|
|
28499
29120
|
|
|
28500
29121
|
// src/commands/scan.ts
|
|
28501
|
-
import { existsSync as
|
|
28502
|
-
import { basename as
|
|
29122
|
+
import { existsSync as existsSync17, readFileSync as readFileSync21, realpathSync as realpathSync6, statSync as statSync15, writeFileSync as writeFileSync7 } from "node:fs";
|
|
29123
|
+
import { basename as basename9, dirname as dirname12, isAbsolute as isAbsolute13, join as join26, relative as relative10, resolve as resolve19 } from "node:path";
|
|
28503
29124
|
init_bedrock();
|
|
28504
29125
|
|
|
28505
29126
|
// src/commands/detonate.ts
|
|
28506
|
-
import { existsSync as
|
|
28507
|
-
import { basename as
|
|
29127
|
+
import { existsSync as existsSync16, readFileSync as readFileSync20, statSync as statSync14 } from "node:fs";
|
|
29128
|
+
import { basename as basename8, join as join25, resolve as resolve18 } from "node:path";
|
|
28508
29129
|
init_bedrock();
|
|
28509
29130
|
var DEFAULT_DETONATE_MAX = 10;
|
|
28510
29131
|
var EX024 = "EX-024";
|
|
@@ -28583,12 +29204,12 @@ async function runDetonations(root, findings, client, max, def) {
|
|
|
28583
29204
|
for (const t of targets) {
|
|
28584
29205
|
let text;
|
|
28585
29206
|
try {
|
|
28586
|
-
text =
|
|
29207
|
+
text = readFileSync20(join25(root, t.file), "utf8");
|
|
28587
29208
|
} catch {
|
|
28588
29209
|
tally.inconclusive++;
|
|
28589
29210
|
continue;
|
|
28590
29211
|
}
|
|
28591
|
-
const r = await detonate(text, "file", client, { fileName:
|
|
29212
|
+
const r = await detonate(text, "file", client, { fileName: basename8(t.file) });
|
|
28592
29213
|
calls += r.modelCalls;
|
|
28593
29214
|
tally[r.verdict]++;
|
|
28594
29215
|
reports.push({ file: t.file, report: r });
|
|
@@ -28646,18 +29267,18 @@ ${DETONATE_HELP}`);
|
|
|
28646
29267
|
io.err(`Unknown format "${format}". Use text or json.`);
|
|
28647
29268
|
return 2;
|
|
28648
29269
|
}
|
|
28649
|
-
const abs =
|
|
28650
|
-
if (!
|
|
29270
|
+
const abs = resolve18(target);
|
|
29271
|
+
if (!existsSync16(abs) || !statSync14(abs).isFile()) {
|
|
28651
29272
|
io.err(`File not found: ${target}`);
|
|
28652
29273
|
return 2;
|
|
28653
29274
|
}
|
|
28654
|
-
if (
|
|
29275
|
+
if (statSync14(abs).size > MAX_FILE_BYTES5) {
|
|
28655
29276
|
io.err(`${target} is larger than 1 MB; detonate a smaller part of it.`);
|
|
28656
29277
|
return 2;
|
|
28657
29278
|
}
|
|
28658
29279
|
const client = await makeChamberClient(io, "exorcist detonate", deps.client);
|
|
28659
29280
|
if (client === false) return 2;
|
|
28660
|
-
const report = await detonate(
|
|
29281
|
+
const report = await detonate(readFileSync20(abs, "utf8"), placement, client, { fileName: basename8(abs) });
|
|
28661
29282
|
if (format === "json") io.out(`${JSON.stringify({ file: target, model: modelIdFor("haiku"), ...report }, null, 2)}
|
|
28662
29283
|
`);
|
|
28663
29284
|
else io.out(renderTranscript(target, report));
|
|
@@ -28721,9 +29342,9 @@ Openers: // # <!-- /* -- ; A reason is required. Hidden characters (EX-00
|
|
|
28721
29342
|
secrets (EX-011) cannot be silenced this way. The comment's own text is still scanned.
|
|
28722
29343
|
`;
|
|
28723
29344
|
function readIgnoreFile(root) {
|
|
28724
|
-
const file =
|
|
28725
|
-
if (!
|
|
28726
|
-
return
|
|
29345
|
+
const file = join26(root, ".exorcistignore");
|
|
29346
|
+
if (!existsSync17(file)) return [];
|
|
29347
|
+
return readFileSync21(file, "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
28727
29348
|
}
|
|
28728
29349
|
function isIgnored(rel, prefixes) {
|
|
28729
29350
|
return prefixes.some((p) => {
|
|
@@ -28817,14 +29438,14 @@ async function makeAiClient(rawMax, io, real) {
|
|
|
28817
29438
|
};
|
|
28818
29439
|
}
|
|
28819
29440
|
async function runScan(opts, io) {
|
|
28820
|
-
const abs =
|
|
28821
|
-
if (!
|
|
29441
|
+
const abs = resolve19(opts.target);
|
|
29442
|
+
if (!existsSync17(abs)) {
|
|
28822
29443
|
io.err(`Path not found: ${opts.target}`);
|
|
28823
29444
|
return { ok: false, code: 2 };
|
|
28824
29445
|
}
|
|
28825
|
-
const isFile =
|
|
28826
|
-
const root = isFile ?
|
|
28827
|
-
const only = isFile ?
|
|
29446
|
+
const isFile = statSync15(abs).isFile();
|
|
29447
|
+
const root = isFile ? dirname12(abs) : abs;
|
|
29448
|
+
const only = isFile ? basename9(abs) : null;
|
|
28828
29449
|
const defsDir = findDefinitionsDir2(opts.definitions);
|
|
28829
29450
|
if (!defsDir) {
|
|
28830
29451
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -28868,17 +29489,17 @@ async function runScan(opts, io) {
|
|
|
28868
29489
|
function makeRootReader(root) {
|
|
28869
29490
|
let realRoot;
|
|
28870
29491
|
try {
|
|
28871
|
-
realRoot =
|
|
29492
|
+
realRoot = realpathSync6(root);
|
|
28872
29493
|
} catch {
|
|
28873
29494
|
return () => null;
|
|
28874
29495
|
}
|
|
28875
29496
|
return (file) => {
|
|
28876
29497
|
try {
|
|
28877
|
-
const real =
|
|
28878
|
-
const rel =
|
|
28879
|
-
if (rel === "" || rel.startsWith("..") ||
|
|
28880
|
-
if (
|
|
28881
|
-
return
|
|
29498
|
+
const real = realpathSync6(resolve19(realRoot, file));
|
|
29499
|
+
const rel = relative10(realRoot, real);
|
|
29500
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute13(rel)) return null;
|
|
29501
|
+
if (statSync15(real).size > MAX_DIRECTIVE_FILE_BYTES) return null;
|
|
29502
|
+
return readFileSync21(real, "utf8");
|
|
28882
29503
|
} catch {
|
|
28883
29504
|
return null;
|
|
28884
29505
|
}
|
|
@@ -28936,7 +29557,7 @@ ${SCAN_HELP}`);
|
|
|
28936
29557
|
if (baselinePath !== void 0) {
|
|
28937
29558
|
let text;
|
|
28938
29559
|
try {
|
|
28939
|
-
text =
|
|
29560
|
+
text = readFileSync21(resolve19(baselinePath), "utf8");
|
|
28940
29561
|
} catch {
|
|
28941
29562
|
io.err(`Could not read the baseline file ${baselinePath}. Check the path, or create one with: exorcist baseline <folder>`);
|
|
28942
29563
|
return 2;
|
|
@@ -29049,7 +29670,7 @@ ${BASELINE_HELP}`);
|
|
|
29049
29670
|
}
|
|
29050
29671
|
const target = p.positionals[0] ?? ".";
|
|
29051
29672
|
try {
|
|
29052
|
-
if (!
|
|
29673
|
+
if (!statSync16(resolve20(target)).isDirectory()) {
|
|
29053
29674
|
io.err(`${target} is a file. Give a folder to baseline.`);
|
|
29054
29675
|
return 2;
|
|
29055
29676
|
}
|
|
@@ -29062,7 +29683,7 @@ ${BASELINE_HELP}`);
|
|
|
29062
29683
|
const { findings, root } = result.run;
|
|
29063
29684
|
const { active } = applyInline(findings, makeRootReader(root));
|
|
29064
29685
|
const baseline = buildBaseline(active);
|
|
29065
|
-
const out = str4(p.values["output"]) ??
|
|
29686
|
+
const out = str4(p.values["output"]) ?? join27(root, BASELINE_FILE);
|
|
29066
29687
|
try {
|
|
29067
29688
|
writeFileSync8(out, `${JSON.stringify(baseline, null, 2)}
|
|
29068
29689
|
`, "utf8");
|
|
@@ -29075,7 +29696,7 @@ ${BASELINE_HELP}`);
|
|
|
29075
29696
|
}
|
|
29076
29697
|
|
|
29077
29698
|
// src/commands/canary.ts
|
|
29078
|
-
import { resolve as
|
|
29699
|
+
import { resolve as resolve21 } from "node:path";
|
|
29079
29700
|
var CANARY_HELP = `Usage: exorcist canary plant [dir] Plant canary traps in a project (3 by default)
|
|
29080
29701
|
exorcist canary --list [dir] Show the planted traps
|
|
29081
29702
|
exorcist canary --remove [dir] Remove the trap files and their records
|
|
@@ -29123,7 +29744,7 @@ ${CANARY_HELP}`);
|
|
|
29123
29744
|
${CANARY_HELP}`);
|
|
29124
29745
|
return 2;
|
|
29125
29746
|
}
|
|
29126
|
-
const dir =
|
|
29747
|
+
const dir = resolve21(positionals[0] ?? ".");
|
|
29127
29748
|
const wantList = p.values["list"] === true || sub === "list";
|
|
29128
29749
|
const wantRemove = p.values["remove"] === true || sub === "remove";
|
|
29129
29750
|
const wantPlant = sub === "plant";
|
|
@@ -29189,8 +29810,8 @@ function remove(io, dir, state) {
|
|
|
29189
29810
|
|
|
29190
29811
|
// src/commands/config.ts
|
|
29191
29812
|
import { createHash as createHash11 } from "node:crypto";
|
|
29192
|
-
import { existsSync as
|
|
29193
|
-
import { join as
|
|
29813
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync9, readFileSync as readFileSync22, rmSync as rmSync5, writeFileSync as writeFileSync9 } from "node:fs";
|
|
29814
|
+
import { join as join28, resolve as resolve22 } from "node:path";
|
|
29194
29815
|
var WRAP_HELP = `Usage: exorcist wrap <mcp.json> [options]
|
|
29195
29816
|
exorcist unwrap <mcp.json>
|
|
29196
29817
|
|
|
@@ -29201,16 +29822,16 @@ unwrap Put the original file back byte for byte, if it was not edited since
|
|
|
29201
29822
|
|
|
29202
29823
|
Options (wrap):
|
|
29203
29824
|
--bin <command> Command that runs the shield (default: exorcist)
|
|
29204
|
-
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.
|
|
29825
|
+
--bin-arg <arg> Argument before "shield" (repeatable), e.g. --bin npx --bin-arg -y --bin-arg @exorcist-98/cli@0.3.1
|
|
29205
29826
|
--dir <folder> State folder (default: ${DEFAULT_DIR})
|
|
29206
29827
|
--dry-run Show the result without writing the file
|
|
29207
29828
|
`;
|
|
29208
29829
|
function backupPath(dir, configPath) {
|
|
29209
|
-
return
|
|
29830
|
+
return join28(dir, "wrap-backups", `${createHash11("sha256").update(configPath).digest("hex").slice(0, 32)}.json`);
|
|
29210
29831
|
}
|
|
29211
29832
|
function readBackup(file) {
|
|
29212
29833
|
try {
|
|
29213
|
-
const b = JSON.parse(
|
|
29834
|
+
const b = JSON.parse(readFileSync22(file, "utf8"));
|
|
29214
29835
|
return typeof b.original === "string" && typeof b.wrapped === "string" && typeof b.path === "string" ? b : null;
|
|
29215
29836
|
} catch {
|
|
29216
29837
|
return null;
|
|
@@ -29228,12 +29849,12 @@ function dirsInConfig(cfg) {
|
|
|
29228
29849
|
return out;
|
|
29229
29850
|
}
|
|
29230
29851
|
function readConfig2(path, io) {
|
|
29231
|
-
if (!
|
|
29852
|
+
if (!existsSync18(path)) {
|
|
29232
29853
|
io.err(`File not found: ${path}`);
|
|
29233
29854
|
return null;
|
|
29234
29855
|
}
|
|
29235
29856
|
try {
|
|
29236
|
-
const json2 = JSON.parse(
|
|
29857
|
+
const json2 = JSON.parse(readFileSync22(path, "utf8"));
|
|
29237
29858
|
if (!json2 || typeof json2 !== "object" || Array.isArray(json2)) throw new Error("not an object");
|
|
29238
29859
|
return json2;
|
|
29239
29860
|
} catch {
|
|
@@ -29266,10 +29887,10 @@ ${WRAP_HELP}`);
|
|
|
29266
29887
|
${WRAP_HELP}`);
|
|
29267
29888
|
return 2;
|
|
29268
29889
|
}
|
|
29269
|
-
const path =
|
|
29890
|
+
const path = resolve22(file);
|
|
29270
29891
|
const cfg = readConfig2(path, io);
|
|
29271
29892
|
if (!cfg) return 2;
|
|
29272
|
-
const text =
|
|
29893
|
+
const text = readFileSync22(path, "utf8");
|
|
29273
29894
|
let next;
|
|
29274
29895
|
let names;
|
|
29275
29896
|
if (mode === "wrap") {
|
|
@@ -29295,7 +29916,7 @@ ${WRAP_HELP}`);
|
|
|
29295
29916
|
writeFileSync9(path, out, "utf8");
|
|
29296
29917
|
const b = backupPath(stateDir(str4(p.values["dir"])), path);
|
|
29297
29918
|
try {
|
|
29298
|
-
mkdirSync9(
|
|
29919
|
+
mkdirSync9(join28(b, ".."), { recursive: true, mode: 448 });
|
|
29299
29920
|
writeFileSync9(b, JSON.stringify({ path, original: text, wrapped: out }), { mode: 384 });
|
|
29300
29921
|
} catch {
|
|
29301
29922
|
io.err("Could not save a copy of the original file; unwrap will still restore the original commands.");
|
|
@@ -29354,7 +29975,7 @@ import { randomBytes as randomBytes8, timingSafeEqual } from "node:crypto";
|
|
|
29354
29975
|
import { createServer } from "node:http";
|
|
29355
29976
|
|
|
29356
29977
|
// src/console/model.ts
|
|
29357
|
-
import { lstatSync as lstatSync7, readdirSync as
|
|
29978
|
+
import { lstatSync as lstatSync7, readdirSync as readdirSync8 } from "node:fs";
|
|
29358
29979
|
var BACKLOG = 400;
|
|
29359
29980
|
var MAX_SHIELDS = 64;
|
|
29360
29981
|
var MAX_SESSIONS = 16;
|
|
@@ -29479,7 +30100,7 @@ var ConsoleModel = class {
|
|
|
29479
30100
|
const root = sessionsPath(this.dir);
|
|
29480
30101
|
let names = [];
|
|
29481
30102
|
try {
|
|
29482
|
-
names =
|
|
30103
|
+
names = readdirSync8(root).filter((k) => isSessionKey(k));
|
|
29483
30104
|
} catch {
|
|
29484
30105
|
names = [];
|
|
29485
30106
|
}
|
|
@@ -30271,11 +30892,11 @@ data: ${data}
|
|
|
30271
30892
|
});
|
|
30272
30893
|
server.headersTimeout = 1e4;
|
|
30273
30894
|
server.requestTimeout = 0;
|
|
30274
|
-
await new Promise((
|
|
30895
|
+
await new Promise((resolve31, reject) => {
|
|
30275
30896
|
server.once("error", reject);
|
|
30276
30897
|
server.listen(o.port ?? 0, "127.0.0.1", () => {
|
|
30277
30898
|
server.off("error", reject);
|
|
30278
|
-
|
|
30899
|
+
resolve31();
|
|
30279
30900
|
});
|
|
30280
30901
|
});
|
|
30281
30902
|
port = server.address().port;
|
|
@@ -30323,11 +30944,11 @@ function openCommand(platform, url) {
|
|
|
30323
30944
|
if (platform === "win32") return { file: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
|
|
30324
30945
|
return { file: "xdg-open", args: [url] };
|
|
30325
30946
|
}
|
|
30326
|
-
var untilSignal = () => new Promise((
|
|
30947
|
+
var untilSignal = () => new Promise((resolve31) => {
|
|
30327
30948
|
const stop = () => {
|
|
30328
30949
|
process.off("SIGINT", stop);
|
|
30329
30950
|
process.off("SIGTERM", stop);
|
|
30330
|
-
|
|
30951
|
+
resolve31();
|
|
30331
30952
|
};
|
|
30332
30953
|
process.on("SIGINT", stop);
|
|
30333
30954
|
process.on("SIGTERM", stop);
|
|
@@ -30382,8 +31003,8 @@ ${CONSOLE_HELP}`);
|
|
|
30382
31003
|
}
|
|
30383
31004
|
|
|
30384
31005
|
// src/commands/exorcise.ts
|
|
30385
|
-
import { existsSync as
|
|
30386
|
-
import { basename as
|
|
31006
|
+
import { existsSync as existsSync19, readFileSync as readFileSync23, statSync as statSync17 } from "node:fs";
|
|
31007
|
+
import { basename as basename10, dirname as dirname13, isAbsolute as isAbsolute14, relative as relative11, resolve as resolve23 } from "node:path";
|
|
30387
31008
|
var EXORCISE_HELP = `Usage: exorcist exorcise [path] [options]
|
|
30388
31009
|
|
|
30389
31010
|
Disinfect: repair the threats that have one safe, mechanical fix, and report
|
|
@@ -30467,14 +31088,14 @@ ${EXORCISE_HELP}`);
|
|
|
30467
31088
|
return 2;
|
|
30468
31089
|
}
|
|
30469
31090
|
const target = p.positionals[0] ?? ".";
|
|
30470
|
-
const abs =
|
|
30471
|
-
if (!
|
|
31091
|
+
const abs = resolve23(target);
|
|
31092
|
+
if (!existsSync19(abs)) {
|
|
30472
31093
|
io.err(`Path not found: ${target}`);
|
|
30473
31094
|
return 2;
|
|
30474
31095
|
}
|
|
30475
|
-
const isFile =
|
|
30476
|
-
const root = isFile ?
|
|
30477
|
-
const single = isFile ?
|
|
31096
|
+
const isFile = statSync17(abs).isFile();
|
|
31097
|
+
const root = isFile ? dirname13(abs) : abs;
|
|
31098
|
+
const single = isFile ? basename10(abs) : null;
|
|
30478
31099
|
const defsDir = findDefinitionsDir2(str4(p.values["definitions"]));
|
|
30479
31100
|
if (!defsDir) {
|
|
30480
31101
|
io.err("Could not find the virus definitions. Pass --definitions <dir> or set EXORCIST_DEFINITIONS.");
|
|
@@ -30492,10 +31113,10 @@ ${EXORCISE_HELP}`);
|
|
|
30492
31113
|
return 2;
|
|
30493
31114
|
}
|
|
30494
31115
|
const vault = vaultPath(stateDir(str4(p.values["dir"])));
|
|
30495
|
-
const state =
|
|
31116
|
+
const state = relative11(root, resolve23(vault, ".."));
|
|
30496
31117
|
const ignore = [...strs(p.values["ignore"]), ...readIgnoreFile(root)];
|
|
30497
31118
|
if (state === "") ignore.push("vault");
|
|
30498
|
-
else if (!state.startsWith("..") && !
|
|
31119
|
+
else if (!state.startsWith("..") && !isAbsolute14(state)) ignore.push(state.replace(/\\/g, "/"));
|
|
30499
31120
|
const keep = (rel) => (single === null || rel === single) && !isIgnored(rel, ignore);
|
|
30500
31121
|
const findings = [];
|
|
30501
31122
|
try {
|
|
@@ -30541,7 +31162,7 @@ ${EXORCISE_HELP}`);
|
|
|
30541
31162
|
return 1;
|
|
30542
31163
|
}
|
|
30543
31164
|
const changedSet = new Set(changed.map((r) => r.file));
|
|
30544
|
-
const now = changed.map((r) => ({ file: r.file, text:
|
|
31165
|
+
const now = changed.map((r) => ({ file: r.file, text: readFileSync23(resolve23(root, r.file), "utf8") }));
|
|
30545
31166
|
const after = [...findings.filter((f) => !changedSet.has(f.file)), ...rescanTexts(now, defs).filter((f) => keep(f.file))];
|
|
30546
31167
|
const removed = Math.max(0, findings.length - after.length);
|
|
30547
31168
|
const dirFlag = str4(p.values["dir"]) ? ` --dir ${str4(p.values["dir"])}` : "";
|
|
@@ -30560,9 +31181,9 @@ ${EXORCISE_HELP}`);
|
|
|
30560
31181
|
}
|
|
30561
31182
|
|
|
30562
31183
|
// src/commands/gate.ts
|
|
30563
|
-
import { existsSync as
|
|
31184
|
+
import { existsSync as existsSync20 } from "node:fs";
|
|
30564
31185
|
import { lstat as lstat2, readFile as readFile6 } from "node:fs/promises";
|
|
30565
|
-
import { resolve as
|
|
31186
|
+
import { resolve as resolve24 } from "node:path";
|
|
30566
31187
|
var GATE_HELP = `Usage: exorcist gate [dir] [--fail-on <critical|high|medium|low>] [--dir <state folder>]
|
|
30567
31188
|
The gate for the end of an agent's turn. It looks only at the files an AI agent
|
|
30568
31189
|
obeys (steering, specs, hooks, custom agents, MCP configs, AGENTS.md and the
|
|
@@ -30646,8 +31267,8 @@ ${GATE_HELP}`);
|
|
|
30646
31267
|
${GATE_HELP}`);
|
|
30647
31268
|
return 2;
|
|
30648
31269
|
}
|
|
30649
|
-
const start =
|
|
30650
|
-
if (!
|
|
31270
|
+
const start = resolve24(p.positionals[0] ?? ".");
|
|
31271
|
+
if (!existsSync20(start)) return nothingChecked(io, "that folder does not exist");
|
|
30651
31272
|
const top = await gitRepoRoot(start);
|
|
30652
31273
|
if (!top) return nothingChecked(io, "this folder is not a git repository, or git is not available");
|
|
30653
31274
|
const repo = { root: top };
|
|
@@ -30664,7 +31285,7 @@ ${GATE_HELP}`);
|
|
|
30664
31285
|
const onDisk = [];
|
|
30665
31286
|
const sizes = /* @__PURE__ */ new Map();
|
|
30666
31287
|
for (const rel of changed.files) {
|
|
30667
|
-
const info = await lstat2(
|
|
31288
|
+
const info = await lstat2(resolve24(repo.root, rel)).catch(() => null);
|
|
30668
31289
|
if (!info || !info.isFile()) continue;
|
|
30669
31290
|
onDisk.push(rel);
|
|
30670
31291
|
sizes.set(rel, info.size);
|
|
@@ -30681,7 +31302,7 @@ ${GATE_HELP}`);
|
|
|
30681
31302
|
if (f) added.push(f);
|
|
30682
31303
|
continue;
|
|
30683
31304
|
}
|
|
30684
|
-
const after = await readFile6(
|
|
31305
|
+
const after = await readFile6(resolve24(repo.root, rel), "utf8").catch(() => null);
|
|
30685
31306
|
if (after === null) continue;
|
|
30686
31307
|
const before = then.has(rel) ? await committed(repo.root, rel) : null;
|
|
30687
31308
|
added.push(...gateFindings(rel, before, after, defs));
|
|
@@ -30699,7 +31320,7 @@ ${head}`);
|
|
|
30699
31320
|
|
|
30700
31321
|
// src/commands/guard-mcp-write.ts
|
|
30701
31322
|
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
30702
|
-
import { createReadStream, createWriteStream, openSync as
|
|
31323
|
+
import { createReadStream, createWriteStream, openSync as openSync6, writeSync as writeSync3 } from "node:fs";
|
|
30703
31324
|
import { homedir as homedir3 } from "node:os";
|
|
30704
31325
|
import { createInterface as createInterface2 } from "node:readline";
|
|
30705
31326
|
var GUARD_MCP_WRITE_HELP = `Usage: exorcist guard-mcp-write (Kiro hook helper)
|
|
@@ -30719,7 +31340,7 @@ var PROMPT_TIMEOUT_MS = 125e3;
|
|
|
30719
31340
|
function hookDeps() {
|
|
30720
31341
|
let fd = null;
|
|
30721
31342
|
try {
|
|
30722
|
-
fd =
|
|
31343
|
+
fd = openSync6("/dev/tty", "r+");
|
|
30723
31344
|
} catch {
|
|
30724
31345
|
fd = null;
|
|
30725
31346
|
}
|
|
@@ -30814,7 +31435,7 @@ async function guardMcpWriteCommand(stdin, io, deps = hookDeps()) {
|
|
|
30814
31435
|
}
|
|
30815
31436
|
|
|
30816
31437
|
// src/commands/guard-env-write.ts
|
|
30817
|
-
import { isAbsolute as
|
|
31438
|
+
import { isAbsolute as isAbsolute15 } from "node:path";
|
|
30818
31439
|
var GUARD_ENV_WRITE_HELP = `Usage: exorcist guard-env-write (Kiro hook helper)
|
|
30819
31440
|
Reads a Kiro PreToolUse hook event for a file write (fs_write, str_replace) from
|
|
30820
31441
|
stdin. When the text to be written holds a value from a .env file of this project
|
|
@@ -30826,7 +31447,7 @@ understand, is allowed: the hook must never stop the agent from working.
|
|
|
30826
31447
|
`;
|
|
30827
31448
|
function projectDir(event) {
|
|
30828
31449
|
const cwd = typeof event === "object" && event !== null ? event["cwd"] : void 0;
|
|
30829
|
-
return typeof cwd === "string" && cwd !== "" &&
|
|
31450
|
+
return typeof cwd === "string" && cwd !== "" && isAbsolute15(cwd) ? cwd : process.cwd();
|
|
30830
31451
|
}
|
|
30831
31452
|
function guardEnvWriteCommand(stdin, io) {
|
|
30832
31453
|
let event;
|
|
@@ -30843,7 +31464,7 @@ function guardEnvWriteCommand(stdin, io) {
|
|
|
30843
31464
|
}
|
|
30844
31465
|
|
|
30845
31466
|
// src/commands/guard-web-fetch.ts
|
|
30846
|
-
import { isAbsolute as
|
|
31467
|
+
import { isAbsolute as isAbsolute16 } from "node:path";
|
|
30847
31468
|
var GUARD_WEB_FETCH_HELP = `Usage: exorcist guard-web-fetch (Kiro hook helper)
|
|
30848
31469
|
Reads a Kiro PreToolUse hook event for the web_fetch tool from stdin. When the
|
|
30849
31470
|
address holds a secret (a key or token), a canary token, or a value from a .env
|
|
@@ -30855,7 +31476,7 @@ understand, is allowed: the hook must never stop the agent from working.
|
|
|
30855
31476
|
`;
|
|
30856
31477
|
function projectDir2(event) {
|
|
30857
31478
|
const cwd = typeof event === "object" && event !== null ? event["cwd"] : void 0;
|
|
30858
|
-
return typeof cwd === "string" && cwd !== "" &&
|
|
31479
|
+
return typeof cwd === "string" && cwd !== "" && isAbsolute16(cwd) ? cwd : process.cwd();
|
|
30859
31480
|
}
|
|
30860
31481
|
function guardWebFetchCommand(stdin, io) {
|
|
30861
31482
|
let event;
|
|
@@ -30875,9 +31496,101 @@ function guardWebFetchCommand(stdin, io) {
|
|
|
30875
31496
|
return 2;
|
|
30876
31497
|
}
|
|
30877
31498
|
|
|
31499
|
+
// src/commands/guard-run-scripts.ts
|
|
31500
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync21 } from "node:fs";
|
|
31501
|
+
import { isAbsolute as isAbsolute17, join as join29 } from "node:path";
|
|
31502
|
+
var GUARD_RUN_SCRIPTS_HELP = `Usage: exorcist guard-run-scripts (Kiro hook helper)
|
|
31503
|
+
Reads a Kiro PreToolUse hook event for a shell tool from stdin. When the command
|
|
31504
|
+
would run a package script (npm test, npm run x, npm install, pnpm, yarn, npx of a
|
|
31505
|
+
local bin) whose file reads a secret (.env, .npmrc, ~/.aws, ~/.ssh, the whole
|
|
31506
|
+
environment) and sends data out, the command is blocked. Nothing is ever run.
|
|
31507
|
+
Exit codes: 0 allow, 2 block (the script and the file on stderr, never file text).
|
|
31508
|
+
Anything it cannot work out is allowed: the hook must never stop the agent from
|
|
31509
|
+
working. A command it cannot parse is allowed and noted in .exorcist/kiro-hooks.log.
|
|
31510
|
+
`;
|
|
31511
|
+
var cwdOf = (event) => {
|
|
31512
|
+
const c = typeof event === "object" && event !== null ? event["cwd"] : void 0;
|
|
31513
|
+
return typeof c === "string" && isAbsolute17(c) ? c : process.cwd();
|
|
31514
|
+
};
|
|
31515
|
+
function logParseFailure(cwd) {
|
|
31516
|
+
try {
|
|
31517
|
+
const dir = join29(cwd, ".exorcist");
|
|
31518
|
+
if (!existsSync21(dir)) return;
|
|
31519
|
+
appendFileSync2(join29(dir, "kiro-hooks.log"), `${(/* @__PURE__ */ new Date()).toISOString()} guard-run-scripts: the command could not be parsed, so it was allowed exit=0
|
|
31520
|
+
`);
|
|
31521
|
+
} catch {
|
|
31522
|
+
}
|
|
31523
|
+
}
|
|
31524
|
+
function guardRunScriptsCommand(stdin, io) {
|
|
31525
|
+
let event;
|
|
31526
|
+
try {
|
|
31527
|
+
event = JSON.parse(stdin);
|
|
31528
|
+
} catch {
|
|
31529
|
+
return 0;
|
|
31530
|
+
}
|
|
31531
|
+
const cwd = cwdOf(event);
|
|
31532
|
+
const d = decideRunScripts(event, cwd);
|
|
31533
|
+
if (d.block) {
|
|
31534
|
+
io.err(runScriptsBlockMessage(d.hit));
|
|
31535
|
+
return 2;
|
|
31536
|
+
}
|
|
31537
|
+
if (d.parseFailed) logParseFailure(cwd);
|
|
31538
|
+
return 0;
|
|
31539
|
+
}
|
|
31540
|
+
|
|
31541
|
+
// src/commands/guard-shell-read.ts
|
|
31542
|
+
import { isAbsolute as isAbsolute18 } from "node:path";
|
|
31543
|
+
var GUARD_SHELL_READ_HELP = `Usage: exorcist guard-shell-read (Kiro hook helper)
|
|
31544
|
+
Reads a Kiro PreToolUse hook event for a shell tool from stdin. When the command
|
|
31545
|
+
reads a file in this project with cat, head, tail, less, more, sed -n, awk, bat, nl
|
|
31546
|
+
or grep, the file is scanned the way "exorcist on-access" scans it, and the command
|
|
31547
|
+
is blocked when a high or critical rule fires. Globs and words with $, backticks or
|
|
31548
|
+
~ are skipped, files outside the project are not scanned, and the command is never run.
|
|
31549
|
+
Exit codes: 0 allow, 2 block (the file name and the rule on stderr, never file text).
|
|
31550
|
+
Anything it cannot read or understand is allowed.
|
|
31551
|
+
`;
|
|
31552
|
+
var cwdOf2 = (stdin) => {
|
|
31553
|
+
try {
|
|
31554
|
+
const c = JSON.parse(stdin).cwd;
|
|
31555
|
+
if (typeof c === "string" && isAbsolute18(c)) return c;
|
|
31556
|
+
} catch {
|
|
31557
|
+
}
|
|
31558
|
+
return process.cwd();
|
|
31559
|
+
};
|
|
31560
|
+
async function guardShellReadCommand(stdin, io) {
|
|
31561
|
+
let event;
|
|
31562
|
+
try {
|
|
31563
|
+
event = JSON.parse(stdin);
|
|
31564
|
+
} catch {
|
|
31565
|
+
return 0;
|
|
31566
|
+
}
|
|
31567
|
+
const cwd = cwdOf2(stdin);
|
|
31568
|
+
const defsDir = findDefinitionsDir2();
|
|
31569
|
+
if (!defsDir) {
|
|
31570
|
+
io.err("Exorcist 98 guard-shell-read: no virus definitions were found, so the command was allowed.");
|
|
31571
|
+
return 0;
|
|
31572
|
+
}
|
|
31573
|
+
let defs;
|
|
31574
|
+
try {
|
|
31575
|
+
defs = await loadDefinitions(defsDir);
|
|
31576
|
+
} catch {
|
|
31577
|
+
io.err("Exorcist 98 guard-shell-read: the virus definitions could not be loaded, so the command was allowed.");
|
|
31578
|
+
return 0;
|
|
31579
|
+
}
|
|
31580
|
+
let allowed = /* @__PURE__ */ new Set();
|
|
31581
|
+
try {
|
|
31582
|
+
allowed = readAllowedReads(cwd);
|
|
31583
|
+
} catch {
|
|
31584
|
+
allowed = /* @__PURE__ */ new Set();
|
|
31585
|
+
}
|
|
31586
|
+
const d = decideShellRead(event, defs, { cwd, allowed }, cwd);
|
|
31587
|
+
if (d.message) io.err(d.message);
|
|
31588
|
+
return d.exitCode;
|
|
31589
|
+
}
|
|
31590
|
+
|
|
30878
31591
|
// src/commands/hook-scan.ts
|
|
30879
|
-
import { existsSync as
|
|
30880
|
-
import { resolve as
|
|
31592
|
+
import { existsSync as existsSync22, statSync as statSync18 } from "node:fs";
|
|
31593
|
+
import { resolve as resolve25 } from "node:path";
|
|
30881
31594
|
async function hookScanCommand(stdin, io) {
|
|
30882
31595
|
let event;
|
|
30883
31596
|
try {
|
|
@@ -30887,14 +31600,14 @@ async function hookScanCommand(stdin, io) {
|
|
|
30887
31600
|
}
|
|
30888
31601
|
if (typeof event.file_path !== "string" || event.file_path === "") return 0;
|
|
30889
31602
|
const base = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
30890
|
-
const file =
|
|
30891
|
-
if (!
|
|
31603
|
+
const file = resolve25(base, event.file_path);
|
|
31604
|
+
if (!existsSync22(file) || !statSync18(file).isFile()) return 0;
|
|
30892
31605
|
return await scanCommand([file, "--fail-on", "high"], { out: io.err, err: io.err });
|
|
30893
31606
|
}
|
|
30894
31607
|
|
|
30895
31608
|
// src/commands/init.ts
|
|
30896
|
-
import { chmodSync, existsSync as
|
|
30897
|
-
import { dirname as
|
|
31609
|
+
import { chmodSync, existsSync as existsSync23, lstatSync as lstatSync8, mkdirSync as mkdirSync10, readFileSync as readFileSync24, writeFileSync as writeFileSync10 } from "node:fs";
|
|
31610
|
+
import { dirname as dirname14, join as join30, resolve as resolve26 } from "node:path";
|
|
30898
31611
|
|
|
30899
31612
|
// src/kiro-hook-script.ts
|
|
30900
31613
|
var KIRO_HOOK_SCRIPT = [
|
|
@@ -31012,8 +31725,8 @@ function reviewerAgentForProject(mcpCommand) {
|
|
|
31012
31725
|
}
|
|
31013
31726
|
|
|
31014
31727
|
// src/commands/init.ts
|
|
31015
|
-
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.
|
|
31016
|
-
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.
|
|
31728
|
+
var DEFAULT_BIN = "npx -y @exorcist-98/cli@0.3.1";
|
|
31729
|
+
var DEFAULT_MCP_BIN = "npx -y @exorcist-98/mcp-server@0.3.1";
|
|
31017
31730
|
var MISSING_FROM_DEFAULT_BIN = /* @__PURE__ */ new Set();
|
|
31018
31731
|
var INIT_HELP = `Usage: exorcist init [folder] [--kiro] [--shield] [--sandbox] [--no-agent] [--force]
|
|
31019
31732
|
[--bin <command>] [--mcp-bin <command>]
|
|
@@ -31027,6 +31740,8 @@ Add Exorcist 98 to a Kiro project:
|
|
|
31027
31740
|
.kiro/hooks/exorcist-mcp-write-guard.json a person must confirm any agent write to an MCP config (Kiro hook)
|
|
31028
31741
|
.kiro/hooks/exorcist-guard-web-fetch.json block a web fetch whose address holds a secret, canary or .env value (Kiro hook)
|
|
31029
31742
|
.kiro/hooks/exorcist-guard-env-write.json block writing a .env value into any other file (Kiro hook)
|
|
31743
|
+
.kiro/hooks/exorcist-guard-run-scripts.json block a package script (npm test, install ...) that reads secrets and sends them out (Kiro hook)
|
|
31744
|
+
.kiro/hooks/exorcist-guard-shell-read.json scan a file before a shell command (cat, head, grep ...) reads it (Kiro hook)
|
|
31030
31745
|
.kiro/steering/exorcist.md tell the agent how to treat tool output
|
|
31031
31746
|
.exorcist/kiro-hook.sh puts Node on PATH for the Kiro hooks (Kiro's hook PATH has none)
|
|
31032
31747
|
.exorcist/.gitignore keeps the hook log out of git
|
|
@@ -31050,7 +31765,7 @@ Existing files are never overwritten unless you pass --force.
|
|
|
31050
31765
|
var SANDBOX_REL = ".kiro/settings/sandbox.json";
|
|
31051
31766
|
var SANDBOX_SETTINGS = { enabled: true, networkAccess: "DEFAULT_BLOCKED", mcpSandboxing: true };
|
|
31052
31767
|
function writeSandboxFile(root, io) {
|
|
31053
|
-
const path =
|
|
31768
|
+
const path = join30(root, SANDBOX_REL);
|
|
31054
31769
|
let present = false;
|
|
31055
31770
|
try {
|
|
31056
31771
|
lstatSync8(path);
|
|
@@ -31058,7 +31773,7 @@ function writeSandboxFile(root, io) {
|
|
|
31058
31773
|
} catch {
|
|
31059
31774
|
}
|
|
31060
31775
|
if (!present) {
|
|
31061
|
-
mkdirSync10(
|
|
31776
|
+
mkdirSync10(dirname14(path), { recursive: true });
|
|
31062
31777
|
try {
|
|
31063
31778
|
writeFileSync10(path, `${JSON.stringify(SANDBOX_SETTINGS, null, 2)}
|
|
31064
31779
|
`, { encoding: "utf8", flag: "wx" });
|
|
@@ -31124,9 +31839,9 @@ function splitCommand(s) {
|
|
|
31124
31839
|
}
|
|
31125
31840
|
var MAX_NAME = 60;
|
|
31126
31841
|
function describeMcpConfig(path) {
|
|
31127
|
-
if (!
|
|
31842
|
+
if (!existsSync23(path)) return { exists: false, warnings: [], line: "no .kiro/settings/mcp.json yet (the mcp-scan hook scans it once you add one)" };
|
|
31128
31843
|
try {
|
|
31129
|
-
const cfg = JSON.parse(
|
|
31844
|
+
const cfg = JSON.parse(readFileSync24(path, "utf8"));
|
|
31130
31845
|
const entries = Object.entries(cfg.mcpServers ?? {});
|
|
31131
31846
|
const shielded = entries.filter(([, e]) => isWrapped(e)).map(([n]) => n);
|
|
31132
31847
|
const warnings = entries.filter(([, e]) => Array.isArray(e.autoApprove) && e.autoApprove.includes("*")).map(([n]) => `WARNING: server "${displayMessage(n.slice(0, MAX_NAME).replace(/[\t\n\r]/g, " "))}${n.length > MAX_NAME ? "..." : ""}" has autoApprove "*": your agent can run every tool of it without asking you. List only the tools you trust, or remove autoApprove.`);
|
|
@@ -31162,7 +31877,7 @@ ${INIT_HELP}`);
|
|
|
31162
31877
|
${INIT_HELP}`);
|
|
31163
31878
|
return 2;
|
|
31164
31879
|
}
|
|
31165
|
-
const root =
|
|
31880
|
+
const root = resolve26(p.positionals[0] ?? ".");
|
|
31166
31881
|
const bin = str4(p.values["bin"]) ?? DEFAULT_BIN;
|
|
31167
31882
|
const mcpBin = str4(p.values["mcp-bin"]) ?? DEFAULT_MCP_BIN;
|
|
31168
31883
|
const force = p.values["force"] === true;
|
|
@@ -31194,6 +31909,8 @@ ${INIT_HELP}`);
|
|
|
31194
31909
|
const mcpWriteOff = isDefaultBin && MISSING_FROM_DEFAULT_BIN.has("guard-mcp-write");
|
|
31195
31910
|
const webFetchOff = isDefaultBin && MISSING_FROM_DEFAULT_BIN.has("guard-web-fetch");
|
|
31196
31911
|
const envWriteOff = isDefaultBin && MISSING_FROM_DEFAULT_BIN.has("guard-env-write");
|
|
31912
|
+
const runScriptsOff = isDefaultBin && MISSING_FROM_DEFAULT_BIN.has("guard-run-scripts");
|
|
31913
|
+
const shellReadOff = isDefaultBin && MISSING_FROM_DEFAULT_BIN.has("guard-shell-read");
|
|
31197
31914
|
const files = [
|
|
31198
31915
|
{
|
|
31199
31916
|
rel: ".kiro/hooks/exorcist-secrets.json",
|
|
@@ -31269,6 +31986,28 @@ ${INIT_HELP}`);
|
|
|
31269
31986
|
...envWriteOff ? { enabled: false } : {}
|
|
31270
31987
|
})
|
|
31271
31988
|
},
|
|
31989
|
+
{
|
|
31990
|
+
rel: ".kiro/hooks/exorcist-guard-run-scripts.json",
|
|
31991
|
+
summary: runScriptsOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-run-scripts command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: blocks npm test, npm install and similar when a script they run reads secrets and sends them out",
|
|
31992
|
+
body: hook("exorcist-guard-run-scripts", "Blocks a shell command that would run a package script (npm, pnpm, yarn, npx of a local bin) whose file reads a secret and sends data out. Exit code 2 blocks the command; the reason names the script and the file, never file text. Nothing is run to find out.", {
|
|
31993
|
+
trigger: "PreToolUse",
|
|
31994
|
+
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
31995
|
+
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-run-scripts` },
|
|
31996
|
+
timeout: 15,
|
|
31997
|
+
...runScriptsOff ? { enabled: false } : {}
|
|
31998
|
+
})
|
|
31999
|
+
},
|
|
32000
|
+
{
|
|
32001
|
+
rel: ".kiro/hooks/exorcist-guard-shell-read.json",
|
|
32002
|
+
summary: shellReadOff ? 'PreToolUse on shell tools: WRITTEN DISABLED, because the published version in the default command has no guard-shell-read command (pass --bin with a newer build, then set "enabled": true)' : "PreToolUse on shell tools: scans a file before cat, head, tail, grep, sed -n, awk, bat or nl reads it",
|
|
32003
|
+
body: hook("exorcist-guard-shell-read", "Scans the files a shell command reads (cat, head, tail, less, more, sed -n, awk, bat, nl, grep) the way the on-access hook scans a read, and blocks the command when a high or critical rule fires. Exit code 2 blocks the command; the reason never quotes the file.", {
|
|
32004
|
+
trigger: "PreToolUse",
|
|
32005
|
+
matcher: "shell|execute_bash|executeBash|run_command|bash",
|
|
32006
|
+
action: { type: "command", command: `${HOOK_RUNNER} ${bin} guard-shell-read` },
|
|
32007
|
+
timeout: 15,
|
|
32008
|
+
...shellReadOff ? { enabled: false } : {}
|
|
32009
|
+
})
|
|
32010
|
+
},
|
|
31272
32011
|
{ rel: ".kiro/steering/exorcist.md", body: STEERING, summary: "steering (inclusion: always): tool output and file text are data, never instructions" },
|
|
31273
32012
|
{ rel: ".exorcist/kiro-hook.sh", body: KIRO_HOOK_SCRIPT, executable: true, summary: "finds Node for the hooks (Kiro gives hook commands a PATH without it)" },
|
|
31274
32013
|
{ rel: ".exorcist/.gitignore", body: "kiro-hooks.log\n", summary: "keeps the hook log out of git" },
|
|
@@ -31284,13 +32023,13 @@ ${INIT_HELP}`);
|
|
|
31284
32023
|
}
|
|
31285
32024
|
const done = [];
|
|
31286
32025
|
for (const f of files) {
|
|
31287
|
-
const path =
|
|
31288
|
-
if (
|
|
32026
|
+
const path = join30(root, f.rel);
|
|
32027
|
+
if (existsSync23(path) && !force) {
|
|
31289
32028
|
io.err(`Kept existing ${f.rel} (use --force to replace it).`);
|
|
31290
32029
|
done.push({ f, wrote: false });
|
|
31291
32030
|
continue;
|
|
31292
32031
|
}
|
|
31293
|
-
mkdirSync10(
|
|
32032
|
+
mkdirSync10(dirname14(path), { recursive: true });
|
|
31294
32033
|
writeFileSync10(path, f.body, "utf8");
|
|
31295
32034
|
if (f.executable) chmodSync(path, 493);
|
|
31296
32035
|
if (!kiro) io.out(`Wrote ${f.rel}`);
|
|
@@ -31302,7 +32041,7 @@ ${INIT_HELP}`);
|
|
|
31302
32041
|
return wroteAny ? 0 : 1;
|
|
31303
32042
|
}
|
|
31304
32043
|
if (sandbox) writeSandboxFile(root, io);
|
|
31305
|
-
const mcpPath =
|
|
32044
|
+
const mcpPath = join30(root, ".kiro/settings/mcp.json");
|
|
31306
32045
|
let shieldOk = true;
|
|
31307
32046
|
let shieldLine = null;
|
|
31308
32047
|
if (shield) {
|
|
@@ -31312,7 +32051,7 @@ ${INIT_HELP}`);
|
|
|
31312
32051
|
shieldOk = false;
|
|
31313
32052
|
} else {
|
|
31314
32053
|
const [head, ...rest] = binWords;
|
|
31315
|
-
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${
|
|
32054
|
+
const args = [mcpPath, `--bin=${head}`, ...rest.map((a) => `--bin-arg=${a}`), `--dir=${join30(root, ".exorcist")}`];
|
|
31316
32055
|
const notes = [];
|
|
31317
32056
|
const code3 = await wrapCommand(args, { out: io.out, err: (s) => notes.push(s) }, "wrap");
|
|
31318
32057
|
for (const n of notes) io.err(n);
|
|
@@ -31356,7 +32095,7 @@ ${INIT_HELP}`);
|
|
|
31356
32095
|
"then reconnect MCP servers in the MCP panel so they start through the Shield."
|
|
31357
32096
|
];
|
|
31358
32097
|
if (isDefaultBin) {
|
|
31359
|
-
lines.push("Commands run through npx (@exorcist-98/cli@0.3.
|
|
32098
|
+
lines.push("Commands run through npx (@exorcist-98/cli@0.3.1). If Kiro cannot start a wrapped server or a hook cannot find npx,");
|
|
31360
32099
|
lines.push('rerun with --bin "<absolute path to node> <absolute path to the exorcist CLI>" and --force.');
|
|
31361
32100
|
}
|
|
31362
32101
|
io.out(lines.join("\n"));
|
|
@@ -31365,8 +32104,8 @@ ${INIT_HELP}`);
|
|
|
31365
32104
|
}
|
|
31366
32105
|
|
|
31367
32106
|
// src/commands/lock.ts
|
|
31368
|
-
import { existsSync as
|
|
31369
|
-
import { isAbsolute as
|
|
32107
|
+
import { existsSync as existsSync24, readFileSync as readFileSync25, writeFileSync as writeFileSync11 } from "node:fs";
|
|
32108
|
+
import { isAbsolute as isAbsolute19, join as join31, resolve as resolve27 } from "node:path";
|
|
31370
32109
|
|
|
31371
32110
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
31372
32111
|
var NEVER2 = Object.freeze({
|
|
@@ -37236,7 +37975,7 @@ var Protocol = class {
|
|
|
37236
37975
|
return;
|
|
37237
37976
|
}
|
|
37238
37977
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
37239
|
-
await new Promise((
|
|
37978
|
+
await new Promise((resolve31) => setTimeout(resolve31, pollInterval));
|
|
37240
37979
|
options?.signal?.throwIfAborted();
|
|
37241
37980
|
}
|
|
37242
37981
|
} catch (error2) {
|
|
@@ -37253,7 +37992,7 @@ var Protocol = class {
|
|
|
37253
37992
|
*/
|
|
37254
37993
|
request(request, resultSchema, options) {
|
|
37255
37994
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
37256
|
-
return new Promise((
|
|
37995
|
+
return new Promise((resolve31, reject) => {
|
|
37257
37996
|
const earlyReject = (error2) => {
|
|
37258
37997
|
reject(error2);
|
|
37259
37998
|
};
|
|
@@ -37331,7 +38070,7 @@ var Protocol = class {
|
|
|
37331
38070
|
if (!parseResult.success) {
|
|
37332
38071
|
reject(parseResult.error);
|
|
37333
38072
|
} else {
|
|
37334
|
-
|
|
38073
|
+
resolve31(parseResult.data);
|
|
37335
38074
|
}
|
|
37336
38075
|
} catch (error2) {
|
|
37337
38076
|
reject(error2);
|
|
@@ -37593,12 +38332,12 @@ var Protocol = class {
|
|
|
37593
38332
|
}
|
|
37594
38333
|
} catch {
|
|
37595
38334
|
}
|
|
37596
|
-
return new Promise((
|
|
38335
|
+
return new Promise((resolve31, reject) => {
|
|
37597
38336
|
if (signal.aborted) {
|
|
37598
38337
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
37599
38338
|
return;
|
|
37600
38339
|
}
|
|
37601
|
-
const timeoutId = setTimeout(
|
|
38340
|
+
const timeoutId = setTimeout(resolve31, interval);
|
|
37602
38341
|
signal.addEventListener("abort", () => {
|
|
37603
38342
|
clearTimeout(timeoutId);
|
|
37604
38343
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -38549,7 +39288,7 @@ var StdioClientTransport = class {
|
|
|
38549
39288
|
if (this._process) {
|
|
38550
39289
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
38551
39290
|
}
|
|
38552
|
-
return new Promise((
|
|
39291
|
+
return new Promise((resolve31, reject) => {
|
|
38553
39292
|
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
38554
39293
|
// merge default env with server env because mcp server needs some env vars
|
|
38555
39294
|
env: {
|
|
@@ -38566,7 +39305,7 @@ var StdioClientTransport = class {
|
|
|
38566
39305
|
this.onerror?.(error2);
|
|
38567
39306
|
});
|
|
38568
39307
|
this._process.on("spawn", () => {
|
|
38569
|
-
|
|
39308
|
+
resolve31();
|
|
38570
39309
|
});
|
|
38571
39310
|
this._process.on("close", (_code) => {
|
|
38572
39311
|
this._process = void 0;
|
|
@@ -38631,22 +39370,22 @@ var StdioClientTransport = class {
|
|
|
38631
39370
|
if (this._process) {
|
|
38632
39371
|
const processToClose = this._process;
|
|
38633
39372
|
this._process = void 0;
|
|
38634
|
-
const closePromise = new Promise((
|
|
39373
|
+
const closePromise = new Promise((resolve31) => {
|
|
38635
39374
|
processToClose.once("close", () => {
|
|
38636
|
-
|
|
39375
|
+
resolve31();
|
|
38637
39376
|
});
|
|
38638
39377
|
});
|
|
38639
39378
|
try {
|
|
38640
39379
|
processToClose.stdin?.end();
|
|
38641
39380
|
} catch {
|
|
38642
39381
|
}
|
|
38643
|
-
await Promise.race([closePromise, new Promise((
|
|
39382
|
+
await Promise.race([closePromise, new Promise((resolve31) => setTimeout(resolve31, 2e3).unref())]);
|
|
38644
39383
|
if (processToClose.exitCode === null) {
|
|
38645
39384
|
try {
|
|
38646
39385
|
processToClose.kill("SIGTERM");
|
|
38647
39386
|
} catch {
|
|
38648
39387
|
}
|
|
38649
|
-
await Promise.race([closePromise, new Promise((
|
|
39388
|
+
await Promise.race([closePromise, new Promise((resolve31) => setTimeout(resolve31, 2e3).unref())]);
|
|
38650
39389
|
}
|
|
38651
39390
|
if (processToClose.exitCode === null) {
|
|
38652
39391
|
try {
|
|
@@ -38658,15 +39397,15 @@ var StdioClientTransport = class {
|
|
|
38658
39397
|
this._readBuffer.clear();
|
|
38659
39398
|
}
|
|
38660
39399
|
send(message) {
|
|
38661
|
-
return new Promise((
|
|
39400
|
+
return new Promise((resolve31) => {
|
|
38662
39401
|
if (!this._process?.stdin) {
|
|
38663
39402
|
throw new Error("Not connected");
|
|
38664
39403
|
}
|
|
38665
39404
|
const json2 = serializeMessage(message);
|
|
38666
39405
|
if (this._process.stdin.write(json2)) {
|
|
38667
|
-
|
|
39406
|
+
resolve31();
|
|
38668
39407
|
} else {
|
|
38669
|
-
this._process.stdin.once("drain",
|
|
39408
|
+
this._process.stdin.once("drain", resolve31);
|
|
38670
39409
|
}
|
|
38671
39410
|
});
|
|
38672
39411
|
}
|
|
@@ -38675,7 +39414,7 @@ var StdioClientTransport = class {
|
|
|
38675
39414
|
// src/commands/lock.ts
|
|
38676
39415
|
init_zod();
|
|
38677
39416
|
var DEFAULT_LOCK_TIMEOUT_MS = 2e4;
|
|
38678
|
-
var DEFAULT_CONFIG =
|
|
39417
|
+
var DEFAULT_CONFIG = join31(".kiro", "settings", "mcp.json");
|
|
38679
39418
|
var MAX_PAGES = 100;
|
|
38680
39419
|
var LOCK_HELP = `Usage: exorcist lock [options]
|
|
38681
39420
|
exorcist lock --check [options]
|
|
@@ -38726,7 +39465,7 @@ var EntrySchema2 = external_exports.object({
|
|
|
38726
39465
|
function readConfig3(path) {
|
|
38727
39466
|
let json2;
|
|
38728
39467
|
try {
|
|
38729
|
-
json2 = JSON.parse(
|
|
39468
|
+
json2 = JSON.parse(readFileSync25(path, "utf8"));
|
|
38730
39469
|
} catch {
|
|
38731
39470
|
return { ok: false, error: `${path} is not valid JSON.` };
|
|
38732
39471
|
}
|
|
@@ -38739,7 +39478,7 @@ var RawToolsPage = external_exports.object({ tools: external_exports.array(exter
|
|
|
38739
39478
|
var firstLine2 = (err) => (err instanceof Error ? err.message : String(err)).split("\n")[0]?.slice(0, 300) ?? "unknown error";
|
|
38740
39479
|
async function listTools(o) {
|
|
38741
39480
|
const transport = new StdioClientTransport({ command: o.command, args: o.args, env: o.env, cwd: o.cwd, stderr: "ignore" });
|
|
38742
|
-
const client = new Client({ name: "exorcist-lock", version: "0.3.
|
|
39481
|
+
const client = new Client({ name: "exorcist-lock", version: "0.3.1" }, { capabilities: {} });
|
|
38743
39482
|
let timer;
|
|
38744
39483
|
const timedOut = new Promise((res) => {
|
|
38745
39484
|
timer = setTimeout(() => res({ ok: false, error: `it did not list its tools within ${o.timeoutMs} ms.` }), o.timeoutMs);
|
|
@@ -38822,7 +39561,7 @@ async function collectListings(config2, o) {
|
|
|
38822
39561
|
if (loaders.length > 0) {
|
|
38823
39562
|
warnings.push(`HIGH EX-025: "${name}" sets ${loaders.join(", ")} in its env, which changes how its program loads (for example NODE_OPTIONS=--require runs extra code first). Make sure you know why it is there.`);
|
|
38824
39563
|
}
|
|
38825
|
-
const cwd = entry.cwd === void 0 ? o.cwd :
|
|
39564
|
+
const cwd = entry.cwd === void 0 ? o.cwd : isAbsolute19(entry.cwd) ? entry.cwd : resolve27(o.cwd, entry.cwd);
|
|
38826
39565
|
if (o.static) {
|
|
38827
39566
|
const old = o.previous && Object.hasOwn(o.previous.servers, name) ? o.previous.servers[name] : void 0;
|
|
38828
39567
|
kept.push([name, { launch: launchFingerprint(command, entry.args, cwd, void 0, pinEntry).hash, tools: old?.tools ?? {} }]);
|
|
@@ -38891,7 +39630,7 @@ ${LOCK_HELP}`);
|
|
|
38891
39630
|
io.err("--timeout must be a positive whole number of milliseconds.");
|
|
38892
39631
|
return 2;
|
|
38893
39632
|
}
|
|
38894
|
-
const lockPath2 =
|
|
39633
|
+
const lockPath2 = resolve27(str4(p.values["lock"]) ?? LOCK_FILE);
|
|
38895
39634
|
const checking = p.values["check"] === true;
|
|
38896
39635
|
const fromShield = p.values["from-shield"] === true;
|
|
38897
39636
|
const isStatic = p.values["static"] === true;
|
|
@@ -38904,10 +39643,10 @@ ${LOCK_HELP}`);
|
|
|
38904
39643
|
return 2;
|
|
38905
39644
|
}
|
|
38906
39645
|
let previous;
|
|
38907
|
-
if (
|
|
39646
|
+
if (existsSync24(lockPath2)) {
|
|
38908
39647
|
let text2;
|
|
38909
39648
|
try {
|
|
38910
|
-
text2 =
|
|
39649
|
+
text2 = readFileSync25(lockPath2, "utf8");
|
|
38911
39650
|
} catch (err) {
|
|
38912
39651
|
io.err(`Could not read ${lockPath2}: ${firstLine2(err)}`);
|
|
38913
39652
|
return 2;
|
|
@@ -38932,8 +39671,8 @@ ${LOCK_HELP}`);
|
|
|
38932
39671
|
}
|
|
38933
39672
|
current = pinsToLock(st.state);
|
|
38934
39673
|
} else {
|
|
38935
|
-
const configPath =
|
|
38936
|
-
if (!
|
|
39674
|
+
const configPath = resolve27(str4(p.values["config"]) ?? DEFAULT_CONFIG);
|
|
39675
|
+
if (!existsSync24(configPath)) {
|
|
38937
39676
|
io.err(`MCP config not found: ${configPath}. Pass --config <file>, or --from-shield.`);
|
|
38938
39677
|
return 2;
|
|
38939
39678
|
}
|
|
@@ -38981,8 +39720,8 @@ ${LOCK_HELP}`);
|
|
|
38981
39720
|
}
|
|
38982
39721
|
|
|
38983
39722
|
// src/commands/map.ts
|
|
38984
|
-
import { existsSync as
|
|
38985
|
-
import { resolve as
|
|
39723
|
+
import { existsSync as existsSync25, statSync as statSync19 } from "node:fs";
|
|
39724
|
+
import { resolve as resolve28 } from "node:path";
|
|
38986
39725
|
var MAP_HELP = `Usage: exorcist map [dir] [options]
|
|
38987
39726
|
|
|
38988
39727
|
The Haunted House Map: for every MCP config in a folder (default: the current
|
|
@@ -39077,8 +39816,8 @@ ${MAP_HELP}`);
|
|
|
39077
39816
|
return 2;
|
|
39078
39817
|
}
|
|
39079
39818
|
const target = p.positionals[0] ?? ".";
|
|
39080
|
-
const root =
|
|
39081
|
-
if (!
|
|
39819
|
+
const root = resolve28(target);
|
|
39820
|
+
if (!existsSync25(root) || !statSync19(root).isDirectory()) {
|
|
39082
39821
|
io.err(`Folder not found: ${target}`);
|
|
39083
39822
|
return 2;
|
|
39084
39823
|
}
|
|
@@ -39100,8 +39839,8 @@ ${MAP_HELP}`);
|
|
|
39100
39839
|
}
|
|
39101
39840
|
|
|
39102
39841
|
// src/commands/origin.ts
|
|
39103
|
-
import { existsSync as
|
|
39104
|
-
import { posix, relative as
|
|
39842
|
+
import { existsSync as existsSync26, realpathSync as realpathSync7, statSync as statSync20 } from "node:fs";
|
|
39843
|
+
import { posix, relative as relative12, resolve as resolve29, sep as sep5 } from "node:path";
|
|
39105
39844
|
var ORIGIN_HELP = `Usage: exorcist origin [dir] [options]
|
|
39106
39845
|
|
|
39107
39846
|
Scan a git repository, then walk its history to find the commit that
|
|
@@ -39223,8 +39962,8 @@ ${ORIGIN_HELP}`);
|
|
|
39223
39962
|
${ORIGIN_HELP}`);
|
|
39224
39963
|
return 2;
|
|
39225
39964
|
}
|
|
39226
|
-
const target =
|
|
39227
|
-
if (!
|
|
39965
|
+
const target = resolve29(p.positionals[0] ?? ".");
|
|
39966
|
+
if (!existsSync26(target) || !statSync20(target).isDirectory()) {
|
|
39228
39967
|
io.err(`Not a directory: ${target}`);
|
|
39229
39968
|
return 2;
|
|
39230
39969
|
}
|
|
@@ -39238,8 +39977,8 @@ ${ORIGIN_HELP}`);
|
|
|
39238
39977
|
return 2;
|
|
39239
39978
|
}
|
|
39240
39979
|
const { root: repoRoot, shallow, boundaries } = repo;
|
|
39241
|
-
const scanRoot =
|
|
39242
|
-
const prefix =
|
|
39980
|
+
const scanRoot = realpathSync7(target);
|
|
39981
|
+
const prefix = relative12(realpathSync7(repoRoot), scanRoot).split(sep5).join("/");
|
|
39243
39982
|
if (prefix.startsWith("..")) {
|
|
39244
39983
|
io.err(`The folder is outside the git repository git reported (${repoRoot}).`);
|
|
39245
39984
|
return 2;
|
|
@@ -39311,7 +40050,7 @@ ${ORIGIN_HELP}`);
|
|
|
39311
40050
|
}
|
|
39312
40051
|
|
|
39313
40052
|
// src/commands/shield.ts
|
|
39314
|
-
import { resolve as
|
|
40053
|
+
import { resolve as resolve30 } from "node:path";
|
|
39315
40054
|
var SHIELD_HELP = `Usage: exorcist shield --server <name> [options] -- <command> [args...]
|
|
39316
40055
|
exorcist shield --server <name> --url <https://...> [options]
|
|
39317
40056
|
|
|
@@ -39362,9 +40101,9 @@ function parseHeaders(literal2, fromEnv, env) {
|
|
|
39362
40101
|
return { ok: true, headers };
|
|
39363
40102
|
}
|
|
39364
40103
|
async function shieldCommand(argv, io) {
|
|
39365
|
-
const
|
|
39366
|
-
const flags =
|
|
39367
|
-
const rest =
|
|
40104
|
+
const sep6 = argv.indexOf("--");
|
|
40105
|
+
const flags = sep6 === -1 ? argv : argv.slice(0, sep6);
|
|
40106
|
+
const rest = sep6 === -1 ? [] : argv.slice(sep6 + 1);
|
|
39368
40107
|
const p = parse3(flags, {
|
|
39369
40108
|
server: { type: "string" },
|
|
39370
40109
|
config: { type: "string" },
|
|
@@ -39416,7 +40155,7 @@ ${SHIELD_HELP}`);
|
|
|
39416
40155
|
server,
|
|
39417
40156
|
dir: stateDir(str4(p.values["dir"])),
|
|
39418
40157
|
definitionsDir: defs,
|
|
39419
|
-
...config2 ? { configPath:
|
|
40158
|
+
...config2 ? { configPath: resolve30(config2) } : {},
|
|
39420
40159
|
// Desktop notifications for critical and high alerts; EXORCIST_NOTIFY=0 or policy notify:false turns them off.
|
|
39421
40160
|
...process.env["EXORCIST_NOTIFY"] === "0" ? {} : { notify: desktopNotifier() }
|
|
39422
40161
|
};
|
|
@@ -39736,7 +40475,7 @@ ${VERIFY_LOG_HELP}`);
|
|
|
39736
40475
|
}
|
|
39737
40476
|
|
|
39738
40477
|
// src/index.ts
|
|
39739
|
-
var VERSION = "0.3.
|
|
40478
|
+
var VERSION = "0.3.1";
|
|
39740
40479
|
var HELP = `Exorcist 98 ${VERSION}: antivirus for AI coding agents
|
|
39741
40480
|
|
|
39742
40481
|
Usage: exorcist <command> [options]
|
|
@@ -39774,6 +40513,8 @@ Commands:
|
|
|
39774
40513
|
finding (read-only; run by the Kiro Stop hook)
|
|
39775
40514
|
guard-mcp-write Hook helper: a person must confirm any agent write to an MCP config
|
|
39776
40515
|
guard-web-fetch Hook helper: block a web fetch whose address holds a secret, canary or .env value
|
|
40516
|
+
guard-run-scripts Hook helper: block a package script (npm test, install ...) that reads secrets and sends them out
|
|
40517
|
+
guard-shell-read Hook helper: scan a file before a shell command (cat, head, grep ...) reads it
|
|
39777
40518
|
guard-env-write Hook helper: block writing a .env value into any other file
|
|
39778
40519
|
guard-commit Hook helper: block git commit while secrets are staged
|
|
39779
40520
|
hook-scan Hook helper: scan the file named in a Kiro "file saved" event
|
|
@@ -39855,6 +40596,18 @@ async function main(argv) {
|
|
|
39855
40596
|
return 0;
|
|
39856
40597
|
}
|
|
39857
40598
|
return guardWebFetchCommand(await readStdin(), stdio);
|
|
40599
|
+
case "guard-run-scripts":
|
|
40600
|
+
if (rest.includes("--help") || rest.includes("-h")) {
|
|
40601
|
+
stdio.out(GUARD_RUN_SCRIPTS_HELP);
|
|
40602
|
+
return 0;
|
|
40603
|
+
}
|
|
40604
|
+
return guardRunScriptsCommand(await readStdin(), stdio);
|
|
40605
|
+
case "guard-shell-read":
|
|
40606
|
+
if (rest.includes("--help") || rest.includes("-h")) {
|
|
40607
|
+
stdio.out(GUARD_SHELL_READ_HELP);
|
|
40608
|
+
return 0;
|
|
40609
|
+
}
|
|
40610
|
+
return await guardShellReadCommand(await readStdin(), stdio);
|
|
39858
40611
|
case "guard-env-write":
|
|
39859
40612
|
if (rest.includes("--help") || rest.includes("-h")) {
|
|
39860
40613
|
stdio.out(GUARD_ENV_WRITE_HELP);
|