context-mode 2.0.0-next.17 → 2.0.0-next.20
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/SHA256SUMS +15 -15
- package/cli.mjs +59 -43
- package/copilot/plugin.json +1 -1
- package/fixtures/hook-roundtrip.json +20 -3
- package/gemini-extension.json +1 -1
- package/hook.mjs +92 -88
- package/opencode/plugin.js +583 -111
- package/package.json +5 -1
- package/pi/index.js +583 -138
- package/qwen-extension.json +1 -1
- package/run.mjs +371 -23
- package/search.mjs +371 -23
- package/server.mjs +172 -71
package/search.mjs
CHANGED
|
@@ -683,7 +683,8 @@ var RESULT_SUCCESS = "success";
|
|
|
683
683
|
function isRecord(v) {
|
|
684
684
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
685
685
|
}
|
|
686
|
-
var
|
|
686
|
+
var SHELL_TOOL_NAMES = Object.freeze(["bash", "powershell"]);
|
|
687
|
+
var NATIVE_TO_CANONICAL3 = Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"]));
|
|
687
688
|
function canonicalName3(name) {
|
|
688
689
|
if (name.startsWith(TOOL_NAME_PREFIX5)) return name.slice(TOOL_NAME_PREFIX5.length);
|
|
689
690
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
@@ -764,11 +765,11 @@ var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostTool
|
|
|
764
765
|
var MCP_PREFIX2 = "mcp_";
|
|
765
766
|
var MCP_SEP2 = "_";
|
|
766
767
|
var SESSION_START_NEW = "new";
|
|
767
|
-
var
|
|
768
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
768
769
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
769
770
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
770
771
|
var NATIVE_TO_CANONICAL4 = Object.fromEntries([
|
|
771
|
-
...
|
|
772
|
+
...SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]),
|
|
772
773
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
773
774
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
774
775
|
]);
|
|
@@ -896,8 +897,8 @@ var KIRO_EVENTS = {
|
|
|
896
897
|
};
|
|
897
898
|
var PROMPT_ENV = "USER_PROMPT";
|
|
898
899
|
var MCP_PREFIX3 = "mcp_";
|
|
899
|
-
var
|
|
900
|
-
var NATIVE_TO_CANONICAL5 = Object.fromEntries(
|
|
900
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
901
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
901
902
|
var MCP_SEP3 = "_";
|
|
902
903
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
903
904
|
function canonicalName5(name) {
|
|
@@ -1039,7 +1040,8 @@ var OPENCODE_EVENTS = {
|
|
|
1039
1040
|
"step-finish": "Usage"
|
|
1040
1041
|
};
|
|
1041
1042
|
var SHELL_TOOL_NAME = "bash";
|
|
1042
|
-
var
|
|
1043
|
+
var SHELL_TOOL_NAMES4 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1044
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES4.map((n) => [n, "Bash"])) };
|
|
1043
1045
|
function toCanonicalTool(name) {
|
|
1044
1046
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1045
1047
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1169,8 +1171,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1169
1171
|
installMode: "plugin",
|
|
1170
1172
|
projectSource: "arg:--agent+cwd",
|
|
1171
1173
|
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
1172
|
-
nativeTools: { shell: [
|
|
1174
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES] },
|
|
1173
1175
|
execReadOnlyHint: false,
|
|
1176
|
+
// D-PWSH-DUMP-1
|
|
1174
1177
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
1175
1178
|
compactDelivery: "pending-flag",
|
|
1176
1179
|
compactSummary: "none",
|
|
@@ -1188,7 +1191,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1188
1191
|
projectSource: "arg:workspaceFolder",
|
|
1189
1192
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
1190
1193
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
1191
|
-
nativeTools: { shell: [...
|
|
1194
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
1192
1195
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
1193
1196
|
execReadOnlyHint: false,
|
|
1194
1197
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -1207,7 +1210,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1207
1210
|
installMode: "mcp-entry",
|
|
1208
1211
|
projectSource: "arg:--agent+cwd",
|
|
1209
1212
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
1210
|
-
nativeTools: { shell: [...
|
|
1213
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
1211
1214
|
execReadOnlyHint: false,
|
|
1212
1215
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
1213
1216
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -3371,7 +3374,7 @@ function moreLine(intent, label) {
|
|
|
3371
3374
|
}
|
|
3372
3375
|
|
|
3373
3376
|
// src/core/policy/decide.ts
|
|
3374
|
-
import { resolve } from "node:path";
|
|
3377
|
+
import { resolve as resolve2 } from "node:path";
|
|
3375
3378
|
|
|
3376
3379
|
// src/core/policy/lexer.ts
|
|
3377
3380
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -4312,6 +4315,343 @@ function parseShell(cmd) {
|
|
|
4312
4315
|
return { ok: true, commands };
|
|
4313
4316
|
}
|
|
4314
4317
|
|
|
4318
|
+
// src/core/policy/powershell.ts
|
|
4319
|
+
import { resolve } from "node:path";
|
|
4320
|
+
var SQ = "'";
|
|
4321
|
+
var DQ = '"';
|
|
4322
|
+
var TICK = "`";
|
|
4323
|
+
var SPACES = " \r";
|
|
4324
|
+
var OPENERS = "([{";
|
|
4325
|
+
var CLOSERS = ")]}";
|
|
4326
|
+
var GLUE_END = " \r\n|;>";
|
|
4327
|
+
var FD_STAR = "*";
|
|
4328
|
+
var STDOUT_FD = "1";
|
|
4329
|
+
var METHOD_MARK = "::";
|
|
4330
|
+
var PAIR = METHOD_MARK.length;
|
|
4331
|
+
var MIN_STATIC_CALL = PAIR;
|
|
4332
|
+
function quoteEnd(text, at2) {
|
|
4333
|
+
const q = text.charAt(at2);
|
|
4334
|
+
for (let j = at2 + 1; j < text.length; j++) {
|
|
4335
|
+
const c = text.charAt(j);
|
|
4336
|
+
if (q === DQ && c === TICK) {
|
|
4337
|
+
j++;
|
|
4338
|
+
continue;
|
|
4339
|
+
}
|
|
4340
|
+
if (c !== q) continue;
|
|
4341
|
+
if (text.charAt(j + 1) === q) {
|
|
4342
|
+
j++;
|
|
4343
|
+
continue;
|
|
4344
|
+
}
|
|
4345
|
+
return j;
|
|
4346
|
+
}
|
|
4347
|
+
return -1;
|
|
4348
|
+
}
|
|
4349
|
+
function unquote(body, q) {
|
|
4350
|
+
let out = "";
|
|
4351
|
+
for (let j = 0; j < body.length; j++) {
|
|
4352
|
+
const c = body.charAt(j);
|
|
4353
|
+
if (q === DQ && c === TICK && j + 1 < body.length) {
|
|
4354
|
+
out += body.charAt(++j);
|
|
4355
|
+
continue;
|
|
4356
|
+
}
|
|
4357
|
+
if (c === q && body.charAt(j + 1) === q) j++;
|
|
4358
|
+
out += c;
|
|
4359
|
+
}
|
|
4360
|
+
return out;
|
|
4361
|
+
}
|
|
4362
|
+
function closeOf(text, at2) {
|
|
4363
|
+
let depth = 0;
|
|
4364
|
+
for (let j = at2; j < text.length; j++) {
|
|
4365
|
+
const c = text.charAt(j);
|
|
4366
|
+
if (c === SQ || c === DQ) {
|
|
4367
|
+
const e = quoteEnd(text, j);
|
|
4368
|
+
if (e < 0) return -1;
|
|
4369
|
+
j = e;
|
|
4370
|
+
continue;
|
|
4371
|
+
}
|
|
4372
|
+
if (c === TICK) {
|
|
4373
|
+
j++;
|
|
4374
|
+
continue;
|
|
4375
|
+
}
|
|
4376
|
+
if (OPENERS.includes(c)) depth++;
|
|
4377
|
+
else if (CLOSERS.includes(c) && --depth === 0) return j;
|
|
4378
|
+
}
|
|
4379
|
+
return -1;
|
|
4380
|
+
}
|
|
4381
|
+
function glueEnd(text, from) {
|
|
4382
|
+
let depth = 0;
|
|
4383
|
+
for (let j = from; j < text.length; j++) {
|
|
4384
|
+
const c = text.charAt(j);
|
|
4385
|
+
if (c === SQ || c === DQ) {
|
|
4386
|
+
const e = quoteEnd(text, j);
|
|
4387
|
+
if (e < 0) return text.length;
|
|
4388
|
+
j = e;
|
|
4389
|
+
continue;
|
|
4390
|
+
}
|
|
4391
|
+
if (OPENERS.includes(c)) depth++;
|
|
4392
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
4393
|
+
else if (depth <= 0 && GLUE_END.includes(c)) return j;
|
|
4394
|
+
}
|
|
4395
|
+
return text.length;
|
|
4396
|
+
}
|
|
4397
|
+
function splitArgs(inner) {
|
|
4398
|
+
const parts = [];
|
|
4399
|
+
let depth = 0;
|
|
4400
|
+
let from = 0;
|
|
4401
|
+
for (let j = 0; j < inner.length; j++) {
|
|
4402
|
+
const c = inner.charAt(j);
|
|
4403
|
+
if (c === SQ || c === DQ) {
|
|
4404
|
+
const e = quoteEnd(inner, j);
|
|
4405
|
+
if (e < 0) break;
|
|
4406
|
+
j = e;
|
|
4407
|
+
continue;
|
|
4408
|
+
}
|
|
4409
|
+
if (OPENERS.includes(c)) depth++;
|
|
4410
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
4411
|
+
else if (c === "," && depth === 0) {
|
|
4412
|
+
parts.push(inner.slice(from, j));
|
|
4413
|
+
from = j + 1;
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4416
|
+
parts.push(inner.slice(from));
|
|
4417
|
+
return parts;
|
|
4418
|
+
}
|
|
4419
|
+
var isFd = (w) => w !== "" && (w === FD_STAR || [...w].every((ch) => ch >= "0" && ch <= "9"));
|
|
4420
|
+
var fresh = () => ({ words: [], toFile: false, chained: false });
|
|
4421
|
+
function psParse(text) {
|
|
4422
|
+
const statements = [];
|
|
4423
|
+
let stages = [];
|
|
4424
|
+
let stage = fresh();
|
|
4425
|
+
let word = "";
|
|
4426
|
+
let has2 = false;
|
|
4427
|
+
let bare = true;
|
|
4428
|
+
let target = null;
|
|
4429
|
+
const n = text.length;
|
|
4430
|
+
const endWord = () => {
|
|
4431
|
+
if (!has2) return;
|
|
4432
|
+
if (target !== null) {
|
|
4433
|
+
if (target === "file") stage.toFile = true;
|
|
4434
|
+
target = null;
|
|
4435
|
+
} else stage.words.push(word);
|
|
4436
|
+
word = "";
|
|
4437
|
+
has2 = false;
|
|
4438
|
+
bare = true;
|
|
4439
|
+
};
|
|
4440
|
+
const endStage = () => {
|
|
4441
|
+
endWord();
|
|
4442
|
+
if (stage.words.length > 0 || stage.toFile) stages.push(stage);
|
|
4443
|
+
stage = fresh();
|
|
4444
|
+
};
|
|
4445
|
+
const endStatement = () => {
|
|
4446
|
+
endStage();
|
|
4447
|
+
if (stages.length > 0) statements.push(stages);
|
|
4448
|
+
stages = [];
|
|
4449
|
+
};
|
|
4450
|
+
const grow = (s, quoted) => {
|
|
4451
|
+
word += s;
|
|
4452
|
+
has2 = true;
|
|
4453
|
+
if (quoted) bare = false;
|
|
4454
|
+
};
|
|
4455
|
+
let i = 0;
|
|
4456
|
+
while (i < n) {
|
|
4457
|
+
const c = text.charAt(i);
|
|
4458
|
+
const next = text.charAt(i + 1);
|
|
4459
|
+
if (c === SQ || c === DQ) {
|
|
4460
|
+
const e = quoteEnd(text, i);
|
|
4461
|
+
grow(unquote(text.slice(i + 1, e < 0 ? n : e), c), true);
|
|
4462
|
+
i = e < 0 ? n : e + 1;
|
|
4463
|
+
} else if (c === TICK) {
|
|
4464
|
+
if (next !== "\n" && next !== "") grow(next, false);
|
|
4465
|
+
i += PAIR;
|
|
4466
|
+
} else if (c === "\n") {
|
|
4467
|
+
endStatement();
|
|
4468
|
+
i++;
|
|
4469
|
+
} else if (SPACES.includes(c)) {
|
|
4470
|
+
endWord();
|
|
4471
|
+
i++;
|
|
4472
|
+
} else if (c === ";") {
|
|
4473
|
+
endStatement();
|
|
4474
|
+
i++;
|
|
4475
|
+
} else if (c === "|") {
|
|
4476
|
+
if (next === "|") {
|
|
4477
|
+
endStatement();
|
|
4478
|
+
i += PAIR;
|
|
4479
|
+
} else {
|
|
4480
|
+
endStage();
|
|
4481
|
+
i++;
|
|
4482
|
+
}
|
|
4483
|
+
} else if (c === "&") {
|
|
4484
|
+
if (next === "&") {
|
|
4485
|
+
endStatement();
|
|
4486
|
+
i += PAIR;
|
|
4487
|
+
} else {
|
|
4488
|
+
if (has2 || stage.words.length > 0) grow(c, false);
|
|
4489
|
+
i++;
|
|
4490
|
+
}
|
|
4491
|
+
} else if (c === "#" && !has2) {
|
|
4492
|
+
while (i < n && text.charAt(i) !== "\n") i++;
|
|
4493
|
+
} else if (c === ">") {
|
|
4494
|
+
let fd = STDOUT_FD;
|
|
4495
|
+
if (has2 && bare && isFd(word)) {
|
|
4496
|
+
fd = word;
|
|
4497
|
+
word = "";
|
|
4498
|
+
has2 = false;
|
|
4499
|
+
} else if (has2) endWord();
|
|
4500
|
+
let j = i + 1;
|
|
4501
|
+
if (text.charAt(j) === ">") j++;
|
|
4502
|
+
if (text.charAt(j) === "&") {
|
|
4503
|
+
j++;
|
|
4504
|
+
while (j < n && !GLUE_END.includes(text.charAt(j))) j++;
|
|
4505
|
+
} else target = fd === STDOUT_FD || fd === FD_STAR ? "file" : "skip";
|
|
4506
|
+
i = j;
|
|
4507
|
+
} else if (c === "(" && has2 && bare && word.includes(METHOD_MARK)) {
|
|
4508
|
+
const e = closeOf(text, i);
|
|
4509
|
+
const inner = text.slice(i + 1, e < 0 ? n : e);
|
|
4510
|
+
endWord();
|
|
4511
|
+
for (const a of inner.trim() === "" ? [] : splitArgs(inner)) {
|
|
4512
|
+
const first = psParse(a)[0]?.[0]?.words[0];
|
|
4513
|
+
stage.words.push(first ?? a.trim());
|
|
4514
|
+
}
|
|
4515
|
+
i = e < 0 ? n : e + 1;
|
|
4516
|
+
if (i < n && !GLUE_END.includes(text.charAt(i))) {
|
|
4517
|
+
stage.chained = true;
|
|
4518
|
+
i = glueEnd(text, i);
|
|
4519
|
+
}
|
|
4520
|
+
} else if (c === "[" && !has2 && text.startsWith(METHOD_MARK, closeOf(text, i) + 1) && closeOf(text, i) >= 0) {
|
|
4521
|
+
const e = closeOf(text, i);
|
|
4522
|
+
grow(text.slice(i, e + 1), false);
|
|
4523
|
+
i = e + 1;
|
|
4524
|
+
} else if (OPENERS.includes(c) && (c !== "[" || !has2) || (c === "$" || c === "@") && OPENERS.includes(next) && next !== "[") {
|
|
4525
|
+
const open = c === "$" || c === "@" ? i + 1 : i;
|
|
4526
|
+
const e = closeOf(text, open);
|
|
4527
|
+
grow(text.slice(i, e < 0 ? n : e + 1), true);
|
|
4528
|
+
i = e < 0 ? n : e + 1;
|
|
4529
|
+
} else {
|
|
4530
|
+
grow(c, false);
|
|
4531
|
+
i++;
|
|
4532
|
+
}
|
|
4533
|
+
}
|
|
4534
|
+
endStatement();
|
|
4535
|
+
return statements;
|
|
4536
|
+
}
|
|
4537
|
+
var READ_COMMANDS = ["get-content", "gc", "cat", "type"];
|
|
4538
|
+
var FILE_CLASSES = ["[io.file]::", "[system.io.file]::"];
|
|
4539
|
+
var FILE_READS = ["readalltext", "readalllines", "readallbytes", "readlines"];
|
|
4540
|
+
var PATH_PARAMS = ["path", "literalpath"];
|
|
4541
|
+
var BOUND_PARAMS = ["totalcount", "head", "first", "tail", "last"];
|
|
4542
|
+
var VALUE_PARAMS = [...PATH_PARAMS, ...BOUND_PARAMS, "encoding", "readcount", "delimiter", "filter", "include", "exclude", "stream", "credential"];
|
|
4543
|
+
var SWITCH_PARAMS = ["raw", "wait", "force", "asbytestream"];
|
|
4544
|
+
var ALL_PARAMS = [...VALUE_PARAMS, ...SWITCH_PARAMS];
|
|
4545
|
+
var PASS_THROUGH = ["out-string", "write-output", "echo", "write", "out-host", "write-host", "out-default", "tee-object"];
|
|
4546
|
+
var CD_COMMANDS = ["cd", "chdir", "sl", "set-location", "pushd", "push-location"];
|
|
4547
|
+
var POWERSHELLS = ["powershell", "powershell.exe", "pwsh", "pwsh.exe"];
|
|
4548
|
+
var CMDS = ["cmd", "cmd.exe"];
|
|
4549
|
+
var CMD_RUN_FLAGS = ["/c", "/k", "/r"];
|
|
4550
|
+
var COMMAND_PARAM = "command";
|
|
4551
|
+
var DASH = "-";
|
|
4552
|
+
function cmdName(word) {
|
|
4553
|
+
const k = Math.max(word.lastIndexOf("\\"), word.lastIndexOf("/"));
|
|
4554
|
+
return (k >= 0 && k < word.length - 1 ? word.slice(k + 1) : word).toLowerCase();
|
|
4555
|
+
}
|
|
4556
|
+
function param(word, names) {
|
|
4557
|
+
const body = word.slice(DASH.length);
|
|
4558
|
+
const colon = body.indexOf(":");
|
|
4559
|
+
const name = (colon < 0 ? body : body.slice(0, colon)).toLowerCase();
|
|
4560
|
+
const inline = colon < 0 ? void 0 : body.slice(colon + 1);
|
|
4561
|
+
if (name === "") return { full: void 0, inline };
|
|
4562
|
+
if (names.includes(name)) return { full: name, inline };
|
|
4563
|
+
const hits = names.filter((p) => p.startsWith(name));
|
|
4564
|
+
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
4565
|
+
}
|
|
4566
|
+
function psDump(words) {
|
|
4567
|
+
if (words.length === 0) return null;
|
|
4568
|
+
const name = cmdName(words[0]);
|
|
4569
|
+
if (!READ_COMMANDS.includes(name)) {
|
|
4570
|
+
const lower = words[0].toLowerCase();
|
|
4571
|
+
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
4572
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words.length < MIN_STATIC_CALL) return null;
|
|
4573
|
+
return { file: words[1], bounded: false };
|
|
4574
|
+
}
|
|
4575
|
+
const files = [];
|
|
4576
|
+
let bounded = false;
|
|
4577
|
+
for (let k = 1; k < words.length; k++) {
|
|
4578
|
+
const a = words[k];
|
|
4579
|
+
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
4580
|
+
files.push(a);
|
|
4581
|
+
continue;
|
|
4582
|
+
}
|
|
4583
|
+
const p = param(a, ALL_PARAMS);
|
|
4584
|
+
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
4585
|
+
const value = p.inline ?? words[++k];
|
|
4586
|
+
if (value === void 0) return null;
|
|
4587
|
+
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
4588
|
+
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
4589
|
+
}
|
|
4590
|
+
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
4591
|
+
}
|
|
4592
|
+
function nestedScript(name, words) {
|
|
4593
|
+
if (POWERSHELLS.includes(name)) {
|
|
4594
|
+
for (let k = 1; k < words.length; k++) {
|
|
4595
|
+
const w = words[k];
|
|
4596
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
4597
|
+
const p = param(w, [COMMAND_PARAM]);
|
|
4598
|
+
if (p.full === void 0) continue;
|
|
4599
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words.slice(k + 1)].join(" ");
|
|
4600
|
+
}
|
|
4601
|
+
return null;
|
|
4602
|
+
}
|
|
4603
|
+
if (CMDS.includes(name)) {
|
|
4604
|
+
for (let k = 1; k < words.length; k++) {
|
|
4605
|
+
if (CMD_RUN_FLAGS.includes(words[k].toLowerCase())) return words.slice(k + 1).join(" ");
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
return null;
|
|
4609
|
+
}
|
|
4610
|
+
function cdTarget(words) {
|
|
4611
|
+
for (let k = 1; k < words.length; k++) {
|
|
4612
|
+
const w = words[k];
|
|
4613
|
+
if (w.toLowerCase() === "/d") continue;
|
|
4614
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
4615
|
+
const p = param(w, PATH_PARAMS);
|
|
4616
|
+
if (p.full !== void 0) return p.inline ?? words[k + 1] ?? null;
|
|
4617
|
+
}
|
|
4618
|
+
return null;
|
|
4619
|
+
}
|
|
4620
|
+
function walk(script, cwd, depth, found) {
|
|
4621
|
+
let dir = cwd;
|
|
4622
|
+
for (const stages of psParse(script)) {
|
|
4623
|
+
const head = stages[0];
|
|
4624
|
+
if (head.words.length === 0) continue;
|
|
4625
|
+
const name = cmdName(head.words[0]);
|
|
4626
|
+
if (stages.length === 1 && CD_COMMANDS.includes(name)) {
|
|
4627
|
+
const t = cdTarget(head.words);
|
|
4628
|
+
if (t !== null) dir = resolve(dir, t);
|
|
4629
|
+
continue;
|
|
4630
|
+
}
|
|
4631
|
+
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head.words) : null;
|
|
4632
|
+
if (inner !== null) {
|
|
4633
|
+
walk(inner, dir, depth + 1, found);
|
|
4634
|
+
continue;
|
|
4635
|
+
}
|
|
4636
|
+
if (head.toFile || head.chained) continue;
|
|
4637
|
+
const d = psDump(head.words);
|
|
4638
|
+
if (d === null || d.bounded) continue;
|
|
4639
|
+
let shown = true;
|
|
4640
|
+
for (let k = 1; k < stages.length; k++) {
|
|
4641
|
+
if (stages[k].toFile || !PASS_THROUGH.includes(cmdName(stages[k].words[0] ?? ""))) {
|
|
4642
|
+
shown = false;
|
|
4643
|
+
break;
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
if (shown) found.push(resolve(dir, d.file));
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
function psDumpFiles(script, cwd) {
|
|
4650
|
+
const found = [];
|
|
4651
|
+
walk(script, cwd, 0, found);
|
|
4652
|
+
return found;
|
|
4653
|
+
}
|
|
4654
|
+
|
|
4315
4655
|
// src/core/policy/subagent.ts
|
|
4316
4656
|
import { join as join2 } from "node:path";
|
|
4317
4657
|
|
|
@@ -4659,7 +4999,7 @@ function readPath(input) {
|
|
|
4659
4999
|
}
|
|
4660
5000
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
4661
5001
|
if (rules.length === 0) return null;
|
|
4662
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
5002
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve2(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
4663
5003
|
if (canonical === BASH) {
|
|
4664
5004
|
const cmd = str(input.command);
|
|
4665
5005
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -4711,7 +5051,7 @@ function webFetch(input, row) {
|
|
|
4711
5051
|
function bash(ev, row, input, rules) {
|
|
4712
5052
|
const cmd = str(input.command) ?? "";
|
|
4713
5053
|
const parsed = parseShell(cmd);
|
|
4714
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row.toolNamePrefix)) : ALLOW;
|
|
5054
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row.toolNamePrefix)) : psShellDump(cmd, ev.cwd, row) ?? ALLOW;
|
|
4715
5055
|
const cmds = unwrap(parsed.commands);
|
|
4716
5056
|
for (const c of cmds) {
|
|
4717
5057
|
const h = segmentHit(c, rules);
|
|
@@ -4723,7 +5063,7 @@ function bash(ev, row, input, rules) {
|
|
|
4723
5063
|
if (kind !== null) return deny(denyMessage(kind, cmd, row, str(input.description)));
|
|
4724
5064
|
}
|
|
4725
5065
|
}
|
|
4726
|
-
return shellDump(cmds, ev.cwd, row) ?? ALLOW;
|
|
5066
|
+
return shellDump(cmds, ev.cwd, row) ?? psShellDump(cmd, ev.cwd, row) ?? ALLOW;
|
|
4727
5067
|
}
|
|
4728
5068
|
function denyKind(c) {
|
|
4729
5069
|
const name = c.argv0.toLowerCase();
|
|
@@ -4770,7 +5110,7 @@ function read(ev, row, input) {
|
|
|
4770
5110
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4771
5111
|
const p = readPath(input);
|
|
4772
5112
|
if (p !== void 0) {
|
|
4773
|
-
const abs =
|
|
5113
|
+
const abs = resolve2(ev.cwd, p);
|
|
4774
5114
|
const size = fileSize(abs);
|
|
4775
5115
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
|
|
4776
5116
|
}
|
|
@@ -4783,7 +5123,7 @@ function shellDump(cmds, cwd, row) {
|
|
|
4783
5123
|
let verdict = null;
|
|
4784
5124
|
for (const c of cmds) {
|
|
4785
5125
|
const name = c.argv0.toLowerCase();
|
|
4786
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
5126
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve2(dir, c.args[0]);
|
|
4787
5127
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
4788
5128
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
4789
5129
|
const d = dumpTarget(name, c.args);
|
|
@@ -4792,12 +5132,20 @@ function shellDump(cmds, cwd, row) {
|
|
|
4792
5132
|
verdict = ALLOW;
|
|
4793
5133
|
continue;
|
|
4794
5134
|
}
|
|
4795
|
-
const abs =
|
|
5135
|
+
const abs = resolve2(dir, d.file);
|
|
4796
5136
|
const size = fileSize(abs);
|
|
4797
5137
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
|
|
4798
5138
|
}
|
|
4799
5139
|
return verdict;
|
|
4800
5140
|
}
|
|
5141
|
+
function psShellDump(cmd, cwd, row) {
|
|
5142
|
+
if (row.nativeTools.read !== void 0 && row.nativeTools.read.length > 0 && dumpRunsThenReplaces(row)) return null;
|
|
5143
|
+
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
5144
|
+
const size = fileSize(abs);
|
|
5145
|
+
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
|
|
5146
|
+
}
|
|
5147
|
+
return null;
|
|
5148
|
+
}
|
|
4801
5149
|
var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
|
|
4802
5150
|
function countFlag(a) {
|
|
4803
5151
|
if (has(DUMP_COUNT_FLAGS, a)) return 1;
|
|
@@ -4855,7 +5203,7 @@ function dumpTarget(name, args) {
|
|
|
4855
5203
|
}
|
|
4856
5204
|
|
|
4857
5205
|
// src/core/project/resolve.ts
|
|
4858
|
-
import { basename, dirname as dirname2, join as join4, resolve as
|
|
5206
|
+
import { basename, dirname as dirname2, join as join4, resolve as resolve3 } from "node:path";
|
|
4859
5207
|
|
|
4860
5208
|
// src/core/project/contain.ts
|
|
4861
5209
|
import { dirname, sep as sep2 } from "node:path";
|
|
@@ -5050,7 +5398,7 @@ function gitDirs(dir) {
|
|
|
5050
5398
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
5051
5399
|
if (gitDir !== null) {
|
|
5052
5400
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
5053
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
5401
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve3(gitDir, common)), worktree: cur, start };
|
|
5054
5402
|
}
|
|
5055
5403
|
const up = dirname2(cur);
|
|
5056
5404
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -5065,7 +5413,7 @@ function gitDirAt(dotGit) {
|
|
|
5065
5413
|
} else {
|
|
5066
5414
|
const line = firstLine(dotGit);
|
|
5067
5415
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
5068
|
-
gitDir =
|
|
5416
|
+
gitDir = resolve3(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
5069
5417
|
}
|
|
5070
5418
|
} catch {
|
|
5071
5419
|
return null;
|
|
@@ -5278,10 +5626,10 @@ function startArgv(argv) {
|
|
|
5278
5626
|
return sh === null ? null : [sh, ...argv];
|
|
5279
5627
|
}
|
|
5280
5628
|
function runProcess(argv, o) {
|
|
5281
|
-
return new Promise((
|
|
5629
|
+
return new Promise((resolve4) => {
|
|
5282
5630
|
const isWin2 = process.platform === "win32";
|
|
5283
5631
|
const start = startArgv(argv);
|
|
5284
|
-
if (start === null) return
|
|
5632
|
+
if (start === null) return resolve4(NOT_STARTED);
|
|
5285
5633
|
let child;
|
|
5286
5634
|
try {
|
|
5287
5635
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -5295,7 +5643,7 @@ function runProcess(argv, o) {
|
|
|
5295
5643
|
windowsHide: true
|
|
5296
5644
|
});
|
|
5297
5645
|
} catch {
|
|
5298
|
-
return
|
|
5646
|
+
return resolve4(NOT_STARTED);
|
|
5299
5647
|
}
|
|
5300
5648
|
const stdoutChunks = [];
|
|
5301
5649
|
const stderrChunks = [];
|
|
@@ -5320,7 +5668,7 @@ function runProcess(argv, o) {
|
|
|
5320
5668
|
settled = true;
|
|
5321
5669
|
clearTimeout(timer);
|
|
5322
5670
|
o.signal.removeEventListener("abort", onAbort);
|
|
5323
|
-
|
|
5671
|
+
resolve4({
|
|
5324
5672
|
stdout: Buffer.concat(stdoutChunks),
|
|
5325
5673
|
stderr: Buffer.concat(stderrChunks),
|
|
5326
5674
|
exitCode,
|