@bike4mind/cli 5.0.0 → 5.0.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/dist/{AgentHistoryStore-C3hJOgpM.mjs → AgentHistoryStore-DW6BBbVj.mjs} +442 -30
- package/dist/{ApiClient-CeuIcSY8.mjs → ApiClient-D4bDuWXg.mjs} +3 -3
- package/dist/{BubblewrapRuntime-BF5wXaNS.mjs → BubblewrapRuntime-D3EO5Y0C.mjs} +2 -2
- package/dist/{ConfigStore-nr0ebq4v.mjs → ConfigStore-BuLA_-uZ.mjs} +17 -1
- package/dist/ConfigStore-DdqxfmDr.mjs +2 -0
- package/dist/{Logger-CovZt7LL.mjs → Logger-CjaYx85U.mjs} +1055 -706
- package/dist/{SandboxOrchestrator-DTz_5Zub.mjs → SandboxOrchestrator-yORi2eFV.mjs} +1 -1
- package/dist/{SandboxRuntimeAdapter-X0HAkbpW.mjs → SandboxRuntimeAdapter-BjJwJNfg.mjs} +1 -1
- package/dist/{SandboxRuntimeAdapter-CC5KlbZ8.mjs → SandboxRuntimeAdapter-BmkaFzqU.mjs} +2 -2
- package/dist/{SeatbeltRuntime-zdxVqGZ3.mjs → SeatbeltRuntime-CyZNmFwD.mjs} +2 -2
- package/dist/{WorkItemsClient-lKJCPP0j.mjs → WorkItemsClient-xmo0DrCm.mjs} +1 -1
- package/dist/{buildToolSearch-BlOSK4m3.mjs → buildToolSearch-CXxEtVKc.mjs} +2 -2
- package/dist/commands/acpCommand.mjs +5 -5
- package/dist/commands/apiCommand.mjs +1 -1
- package/dist/commands/doctorCommand.mjs +2 -2
- package/dist/commands/envCommand.mjs +1 -1
- package/dist/commands/headlessCommand.mjs +6 -6
- package/dist/commands/mcpCommand.mjs +3 -3
- package/dist/commands/mirrorCommand.mjs +2 -2
- package/dist/commands/modelsCommand.mjs +4 -4
- package/dist/commands/pluginCommand.mjs +1 -1
- package/dist/commands/skillsCommand.mjs +3 -3
- package/dist/commands/updateCommand.mjs +2 -2
- package/dist/{createFile-B8bur5Rb-CVzCarEA.mjs → createFile-CPKmd6Uf-Bk-3V2T3.mjs} +3 -3
- package/dist/{deleteFile-9B3gW_Nb-DG2sovIl.mjs → deleteFile-CD_xQ7Y6-C1X4Ievb.mjs} +17 -4
- package/dist/{dist-BrBjZ6Cv.mjs → dist-DsMzCRLX.mjs} +64 -32
- package/dist/{fit-vnmP4Dfc.mjs → fit-C9eLTDcR.mjs} +3 -3
- package/dist/{globFiles-CwJ8qmYo-BR5b2KvO.mjs → globFiles-CoapsO8G-CpvQo-R2.mjs} +9 -5
- package/dist/{grepSearch-CLtEqT4j-BnKPtNWr.mjs → grepSearch-DeH7M2e7-BIvo-yNy.mjs} +2 -2
- package/dist/index.mjs +9 -9
- package/dist/{modelServers-CjSlPFsg.mjs → modelServers-DeOGFwLi.mjs} +1 -1
- package/dist/{package-BTvxFRbB.mjs → package-CvffLo0I.mjs} +1 -1
- package/dist/{pathValidation-BRqf4HFX-CHwtwp3O.mjs → pathValidation-C4ADzpUR-BPIpINwZ.mjs} +36 -12
- package/dist/{serve-BLBhPkyw.mjs → serve-tmC__JNj.mjs} +6 -6
- package/dist/{updateChecker-uDIZuEZg.mjs → updateChecker-U4AfrPKj.mjs} +1 -1
- package/package.json +10 -10
- package/dist/ConfigStore--dPqdX3O.mjs +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as NotAuthenticatedError, D as sanitizeTerminalText, d as sandboxedCommandArg, l as commandTextOf, p as writePathOf, s as loadContextFiles, u as isReadOnlyTool, w as SessionRevokedError } from "./ConfigStore-
|
|
3
|
-
import { a as extractErrorMessage, d as BaseStorage, f as isPrivateIP, h as redactLogValue, l as OllamaBackend, m as redactLogText, n as B4mStreamEndedError, o as getSettingsMap, p as Logger, r as createClient, s as getSettingsValue, t as B4mApiError, u as OpenAICompatibleBackend } from "./dist-
|
|
4
|
-
import { At as isProviderRefusalStopReason, B as LOW_CONFIDENCE_COMPLETION_MODES, G as NotFoundError, I as ExpectedToolError, Kt as signImageUrl, Lt as obfuscateApiKey, M as DecisionTextPartSchema, N as DecisionsRequestSchema, Ot as isExpectedToolError, St as getMcpProviderMetadata, T as ChatModels, U as McpServerName, V as MODEL_DECLINED_MESSAGE, Vt as reasoningChannelOf, Wt as secureParameters, Y as PermissionDeniedError, a as htmlFirstH1, dn as frontmatterHasSourceStamp, dt as assertAuthOriginMatchesApiKey, h as ApiKeyType, ht as createReasoningWithholder, i as htmlErrorTitle, it as SEARCH_RESULT_CARDS_LANGUAGE, jt as isRetryableError, kt as isPlaceholderImageSigningSecret, n as SESSION_ID_PATTERN, nn as withRetry, o as escapeArtifactBodyJson, qt as splitEquals, r as isValidSessionId, rn as withholdsReasoning, st as UnprocessableEntityError, t as logger, ut as WORK_ITEM_STATUSES, w as CUSTOM_MCP_DATA_NOTICE, wt as googleMapsSearchUrl, x as CONFIDENCE_GATE_MODES, yt as fromCliTodos, z as LOCATION_MAP_LANGUAGE } from "./Logger-
|
|
2
|
+
import { C as NotAuthenticatedError, D as sanitizeTerminalText, d as sandboxedCommandArg, l as commandTextOf, p as writePathOf, s as loadContextFiles, u as isReadOnlyTool, w as SessionRevokedError } from "./ConfigStore-BuLA_-uZ.mjs";
|
|
3
|
+
import { a as extractErrorMessage, d as BaseStorage, f as isPrivateIP, h as redactLogValue, l as OllamaBackend, m as redactLogText, n as B4mStreamEndedError, o as getSettingsMap, p as Logger, r as createClient, s as getSettingsValue, t as B4mApiError, u as OpenAICompatibleBackend } from "./dist-DsMzCRLX.mjs";
|
|
4
|
+
import { At as isProviderRefusalStopReason, B as LOW_CONFIDENCE_COMPLETION_MODES, G as NotFoundError, I as ExpectedToolError, Kt as signImageUrl, Lt as obfuscateApiKey, M as DecisionTextPartSchema, N as DecisionsRequestSchema, Ot as isExpectedToolError, St as getMcpProviderMetadata, T as ChatModels, U as McpServerName, V as MODEL_DECLINED_MESSAGE, Vt as reasoningChannelOf, Wt as secureParameters, Y as PermissionDeniedError, a as htmlFirstH1, dn as frontmatterHasSourceStamp, dt as assertAuthOriginMatchesApiKey, h as ApiKeyType, ht as createReasoningWithholder, i as htmlErrorTitle, it as SEARCH_RESULT_CARDS_LANGUAGE, jt as isRetryableError, kt as isPlaceholderImageSigningSecret, n as SESSION_ID_PATTERN, nn as withRetry, o as escapeArtifactBodyJson, qt as splitEquals, r as isValidSessionId, rn as withholdsReasoning, st as UnprocessableEntityError, t as logger, ut as WORK_ITEM_STATUSES, w as CUSTOM_MCP_DATA_NOTICE, wt as googleMapsSearchUrl, x as CONFIDENCE_GATE_MODES, yt as fromCliTodos, z as LOCATION_MAP_LANGUAGE } from "./Logger-CjaYx85U.mjs";
|
|
5
5
|
import { r as isReservedCommandName } from "./RemoteSkillSource-HqoLRV56.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { a as isPathAllowed, n as assertWritablePath, t as assertPathAllowed } from "./pathValidation-C4ADzpUR-BPIpINwZ.mjs";
|
|
7
7
|
import { n as isTerminalShellStatus, t as getShellSessionManager } from "./ShellSessionManager-6o8KZzl1-vrbPAUTq.mjs";
|
|
8
8
|
import { d as detectRuntimes, m as modelBlobsOf } from "./dist-K7a9yOUb.mjs";
|
|
9
|
-
import { A as serverRuntimeId, B as parseGenerationInput, Ct as withDefaultOllamaPort, F as GENERATION_FIELDS, H as parseModelContextSetting, I as LOCAL_OLLAMA_RUNTIME_ID, L as REASONING_EFFORT_SETTINGS, R as effortSent, S as desktopUserDataFile, V as parseLocalModelId, X as clean, a as needsCredential, f as serverFetch, i as loginHint, l as resolveServerTarget, m as unusableStatus, r as loadModelServers, y as SSH_PROBE_TIMEOUT_MS, z as localModelId } from "./modelServers-
|
|
9
|
+
import { A as serverRuntimeId, B as parseGenerationInput, Ct as withDefaultOllamaPort, F as GENERATION_FIELDS, H as parseModelContextSetting, I as LOCAL_OLLAMA_RUNTIME_ID, L as REASONING_EFFORT_SETTINGS, R as effortSent, S as desktopUserDataFile, V as parseLocalModelId, X as clean, a as needsCredential, f as serverFetch, i as loginHint, l as resolveServerTarget, m as unusableStatus, r as loadModelServers, y as SSH_PROBE_TIMEOUT_MS, z as localModelId } from "./modelServers-DeOGFwLi.mjs";
|
|
10
10
|
import { createHash, randomBytes } from "crypto";
|
|
11
11
|
import { existsSync, lstatSync, promises, readdirSync, realpathSync, rmSync, statSync } from "fs";
|
|
12
12
|
import os, { homedir } from "os";
|
|
@@ -5133,7 +5133,7 @@ function formatSpanPreview(filePath, matchedText, replacement) {
|
|
|
5133
5133
|
/**
|
|
5134
5134
|
* Authorized, read-only resolve for the permission layer: validate the path,
|
|
5135
5135
|
* read the file, and resolve the span WITHOUT writing. Runs the SAME path
|
|
5136
|
-
* authorization ({@link
|
|
5136
|
+
* authorization ({@link assertWritablePath}) and matcher ({@link resolveEdit}) as
|
|
5137
5137
|
* the write path, so a preflight can never read a path the tool itself would
|
|
5138
5138
|
* refuse (no raw-model-path read - closes the auth-bypass / special-file-DoS
|
|
5139
5139
|
* hole) and its fuzzy verdict matches what execution will do. Throws the same
|
|
@@ -5141,7 +5141,7 @@ function formatSpanPreview(filePath, matchedText, replacement) {
|
|
|
5141
5141
|
*/
|
|
5142
5142
|
async function resolveEditLocalFile(params, allowedDirectories) {
|
|
5143
5143
|
const { path: filePath, old_string, new_string } = params;
|
|
5144
|
-
const resolvedPath =
|
|
5144
|
+
const resolvedPath = assertWritablePath(filePath, allowedDirectories, "edit");
|
|
5145
5145
|
if (!existsSync(resolvedPath)) throw new Error(`File not found: ${filePath}`);
|
|
5146
5146
|
const currentContent = await promises.readFile(resolvedPath, "utf-8");
|
|
5147
5147
|
const resolved = resolveEdit(currentContent, old_string, new_string);
|
|
@@ -5155,7 +5155,7 @@ async function resolveEditLocalFile(params, allowedDirectories) {
|
|
|
5155
5155
|
}
|
|
5156
5156
|
async function editLocalFile(params, allowedDirectories) {
|
|
5157
5157
|
const { path: filePath, old_string, new_string, confirmedFuzzyHash, gateSnapshot } = params;
|
|
5158
|
-
const resolvedPath =
|
|
5158
|
+
const resolvedPath = assertWritablePath(filePath, allowedDirectories, "edit");
|
|
5159
5159
|
if (!existsSync(resolvedPath)) throw new Error(`File not found: ${filePath}`);
|
|
5160
5160
|
const currentContent = await promises.readFile(resolvedPath, "utf-8");
|
|
5161
5161
|
const currentHash = sha256(currentContent);
|
|
@@ -6842,10 +6842,10 @@ const latticeToolDefinitions = {
|
|
|
6842
6842
|
*/
|
|
6843
6843
|
const getCliOnlyTools = async () => {
|
|
6844
6844
|
const [{ createFileTool }, { globFilesTool }, { grepSearchTool }, { deleteFileTool }, { bashExecuteTool }] = await Promise.all([
|
|
6845
|
-
import("./createFile-
|
|
6846
|
-
import("./globFiles-
|
|
6847
|
-
import("./grepSearch-
|
|
6848
|
-
import("./deleteFile-
|
|
6845
|
+
import("./createFile-CPKmd6Uf-Bk-3V2T3.mjs"),
|
|
6846
|
+
import("./globFiles-CoapsO8G-CpvQo-R2.mjs"),
|
|
6847
|
+
import("./grepSearch-DeH7M2e7-BIvo-yNy.mjs"),
|
|
6848
|
+
import("./deleteFile-CD_xQ7Y6-C1X4Ievb.mjs"),
|
|
6849
6849
|
import("./bashExecute-CrdPpBqk-CgK1gZa2.mjs")
|
|
6850
6850
|
]);
|
|
6851
6851
|
return {
|
|
@@ -8289,6 +8289,186 @@ function maxLevel(a, b) {
|
|
|
8289
8289
|
function isOperator$1(token) {
|
|
8290
8290
|
return typeof token === "object" && token !== null && "op" in token;
|
|
8291
8291
|
}
|
|
8292
|
+
function isComment(token) {
|
|
8293
|
+
return typeof token === "object" && token !== null && "comment" in token;
|
|
8294
|
+
}
|
|
8295
|
+
const SHELL_METACHARACTERS = /* @__PURE__ */ new Set([
|
|
8296
|
+
";",
|
|
8297
|
+
"&",
|
|
8298
|
+
"|",
|
|
8299
|
+
"(",
|
|
8300
|
+
")",
|
|
8301
|
+
"<",
|
|
8302
|
+
">"
|
|
8303
|
+
]);
|
|
8304
|
+
const BASH_BLANKS = /* @__PURE__ */ new Set([
|
|
8305
|
+
" ",
|
|
8306
|
+
" ",
|
|
8307
|
+
"\n"
|
|
8308
|
+
]);
|
|
8309
|
+
const OPAQUE_SHELL_KEYWORDS = /* @__PURE__ */ new Set([
|
|
8310
|
+
"if",
|
|
8311
|
+
"then",
|
|
8312
|
+
"elif",
|
|
8313
|
+
"else",
|
|
8314
|
+
"fi",
|
|
8315
|
+
"for",
|
|
8316
|
+
"while",
|
|
8317
|
+
"until",
|
|
8318
|
+
"do",
|
|
8319
|
+
"done",
|
|
8320
|
+
"case",
|
|
8321
|
+
"esac",
|
|
8322
|
+
"function",
|
|
8323
|
+
"select",
|
|
8324
|
+
"coproc",
|
|
8325
|
+
"time",
|
|
8326
|
+
"!",
|
|
8327
|
+
"{",
|
|
8328
|
+
"}",
|
|
8329
|
+
"[[",
|
|
8330
|
+
"]]"
|
|
8331
|
+
]);
|
|
8332
|
+
/** Stands in for a command substitution; its code is classified on its own. */
|
|
8333
|
+
const SUBSTITUTION_PLACEHOLDER = "__cmdsub__";
|
|
8334
|
+
/**
|
|
8335
|
+
* Rewrite a bash command so shell-quote tokenizes it the way bash does. Unquoted newlines become
|
|
8336
|
+
* `;`, bash comments are dropped, a mid-word `#` and whitespace bash does not split on are
|
|
8337
|
+
* escaped, heredocs require approval, and each `$(...)` or backquote substitution (quoted or
|
|
8338
|
+
* not) is replaced by a placeholder word and returned
|
|
8339
|
+
* separately for classification.
|
|
8340
|
+
*/
|
|
8341
|
+
function scanShellCommand(command) {
|
|
8342
|
+
const substitutions = [];
|
|
8343
|
+
const { text } = scanCode(command, 0, null, substitutions);
|
|
8344
|
+
return {
|
|
8345
|
+
text,
|
|
8346
|
+
substitutions
|
|
8347
|
+
};
|
|
8348
|
+
}
|
|
8349
|
+
/** Scan unquoted shell code from `start` until `stop` closes it, or to the end of input. */
|
|
8350
|
+
function scanCode(src, start, stop, substitutions) {
|
|
8351
|
+
let out = "";
|
|
8352
|
+
let wordStart = true;
|
|
8353
|
+
let parenDepth = 0;
|
|
8354
|
+
let caseDepth = 0;
|
|
8355
|
+
let index = start;
|
|
8356
|
+
for (; index < src.length; index += 1) {
|
|
8357
|
+
const character = src[index];
|
|
8358
|
+
if (character === stop && (stop === "`" || parenDepth === 0 && caseDepth === 0)) return {
|
|
8359
|
+
text: out,
|
|
8360
|
+
end: index
|
|
8361
|
+
};
|
|
8362
|
+
if (wordStart && /^case[\s;]/.test(src.slice(index, index + 5))) caseDepth += 1;
|
|
8363
|
+
if (wordStart && caseDepth > 0 && /^esac(?:[\s;)&|]|$)/.test(src.slice(index, index + 5))) caseDepth -= 1;
|
|
8364
|
+
if (character === "'") {
|
|
8365
|
+
const close = src.indexOf("'", index + 1);
|
|
8366
|
+
const end = close < 0 ? src.length - 1 : close;
|
|
8367
|
+
out += src.slice(index, end + 1);
|
|
8368
|
+
index = end;
|
|
8369
|
+
wordStart = false;
|
|
8370
|
+
continue;
|
|
8371
|
+
}
|
|
8372
|
+
if (character === "$" && src[index + 1] === "'") {
|
|
8373
|
+
let end = index + 2;
|
|
8374
|
+
while (end < src.length && src[end] !== "'") end += src[end] === "\\" ? 2 : 1;
|
|
8375
|
+
out += src.slice(index, end + 1);
|
|
8376
|
+
index = end;
|
|
8377
|
+
wordStart = false;
|
|
8378
|
+
continue;
|
|
8379
|
+
}
|
|
8380
|
+
if (character === "$" && src[index + 1] === "(" || character === "`") {
|
|
8381
|
+
index = scanSubstitution(src, index, substitutions);
|
|
8382
|
+
out += SUBSTITUTION_PLACEHOLDER;
|
|
8383
|
+
wordStart = false;
|
|
8384
|
+
continue;
|
|
8385
|
+
}
|
|
8386
|
+
if (character === "\"") {
|
|
8387
|
+
const quoted = scanDoubleQuoted(src, index + 1, substitutions);
|
|
8388
|
+
out += `"${quoted.text}"`;
|
|
8389
|
+
index = quoted.end;
|
|
8390
|
+
wordStart = false;
|
|
8391
|
+
continue;
|
|
8392
|
+
}
|
|
8393
|
+
if (character === "\\") {
|
|
8394
|
+
if (src[index + 1] === "\n") {
|
|
8395
|
+
index += 1;
|
|
8396
|
+
continue;
|
|
8397
|
+
}
|
|
8398
|
+
out += character + (src[index + 1] ?? "");
|
|
8399
|
+
index += 1;
|
|
8400
|
+
wordStart = false;
|
|
8401
|
+
continue;
|
|
8402
|
+
}
|
|
8403
|
+
if (character === "#") {
|
|
8404
|
+
if (wordStart) {
|
|
8405
|
+
while (index + 1 < src.length && src[index + 1] !== "\n") index += 1;
|
|
8406
|
+
continue;
|
|
8407
|
+
}
|
|
8408
|
+
out += "\\#";
|
|
8409
|
+
continue;
|
|
8410
|
+
}
|
|
8411
|
+
if (character === "\n") {
|
|
8412
|
+
out += ";";
|
|
8413
|
+
wordStart = true;
|
|
8414
|
+
continue;
|
|
8415
|
+
}
|
|
8416
|
+
if (character === "<" && src[index + 1] === "<" && src[index + 2] !== "<") throw new Error("Heredoc syntax requires approval");
|
|
8417
|
+
if (character === "<" && src.startsWith("<<<", index)) {
|
|
8418
|
+
out += "<<<";
|
|
8419
|
+
index += 2;
|
|
8420
|
+
wordStart = true;
|
|
8421
|
+
continue;
|
|
8422
|
+
}
|
|
8423
|
+
if (BASH_BLANKS.has(character) || SHELL_METACHARACTERS.has(character)) {
|
|
8424
|
+
if (character === "(") parenDepth += 1;
|
|
8425
|
+
if (character === ")" && parenDepth > 0) parenDepth -= 1;
|
|
8426
|
+
out += character;
|
|
8427
|
+
wordStart = true;
|
|
8428
|
+
continue;
|
|
8429
|
+
}
|
|
8430
|
+
if (/\s/.test(character)) {
|
|
8431
|
+
out += `\\${character}`;
|
|
8432
|
+
wordStart = false;
|
|
8433
|
+
continue;
|
|
8434
|
+
}
|
|
8435
|
+
out += character;
|
|
8436
|
+
wordStart = false;
|
|
8437
|
+
}
|
|
8438
|
+
return {
|
|
8439
|
+
text: out,
|
|
8440
|
+
end: index
|
|
8441
|
+
};
|
|
8442
|
+
}
|
|
8443
|
+
/** Record the code of the substitution opening at `index`; returns the index of its closer. */
|
|
8444
|
+
function scanSubstitution(src, index, substitutions) {
|
|
8445
|
+
const backquote = src[index] === "`";
|
|
8446
|
+
const codeStart = index + (backquote ? 1 : 2);
|
|
8447
|
+
const { end } = scanCode(src, codeStart, backquote ? "`" : ")", []);
|
|
8448
|
+
const code = src.slice(codeStart, end);
|
|
8449
|
+
if (backquote && /\\[`$\\]/.test(code)) throw new Error("Unsupported escaped backquote substitution");
|
|
8450
|
+
substitutions.push(code);
|
|
8451
|
+
return end;
|
|
8452
|
+
}
|
|
8453
|
+
/** Scan a double-quoted string body from `start`; returns its text and the closing quote index. */
|
|
8454
|
+
function scanDoubleQuoted(src, start, substitutions) {
|
|
8455
|
+
let text = "";
|
|
8456
|
+
let index = start;
|
|
8457
|
+
for (; index < src.length && src[index] !== "\""; index += 1) {
|
|
8458
|
+
const character = src[index];
|
|
8459
|
+
if (character === "\\") {
|
|
8460
|
+
text += character + (src[index + 1] ?? "");
|
|
8461
|
+
index += 1;
|
|
8462
|
+
} else if (character === "$" && src[index + 1] === "(" || character === "`") {
|
|
8463
|
+
index = scanSubstitution(src, index, substitutions);
|
|
8464
|
+
text += SUBSTITUTION_PLACEHOLDER;
|
|
8465
|
+
} else text += character;
|
|
8466
|
+
}
|
|
8467
|
+
return {
|
|
8468
|
+
text,
|
|
8469
|
+
end: index
|
|
8470
|
+
};
|
|
8471
|
+
}
|
|
8292
8472
|
function asString(token) {
|
|
8293
8473
|
if (typeof token === "string") return token;
|
|
8294
8474
|
if (typeof token === "object" && token !== null && "pattern" in token) return token.pattern;
|
|
@@ -8392,11 +8572,27 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8392
8572
|
const inner = args.slice(index);
|
|
8393
8573
|
if (inner.length === 0) return level;
|
|
8394
8574
|
const prog = programName$1(inner[0]);
|
|
8575
|
+
if (ENV_ASSIGNMENT.test(inner[0]) || OPAQUE_SHELL_KEYWORDS.has(prog)) {
|
|
8576
|
+
reasons.push("shell context requires approval");
|
|
8577
|
+
return "high";
|
|
8578
|
+
}
|
|
8579
|
+
if (prog.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8580
|
+
reasons.push("computed program requires approval");
|
|
8581
|
+
return "high";
|
|
8582
|
+
}
|
|
8583
|
+
if ((DESTINATION_WRITERS.has(prog) || OPERAND_WRITERS.has(prog) || prog === "dd") && inner.slice(1).some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) {
|
|
8584
|
+
reasons.push("computed writer arguments require approval");
|
|
8585
|
+
return "high";
|
|
8586
|
+
}
|
|
8395
8587
|
if (INTERPRETERS.has(prog)) {
|
|
8396
8588
|
const codeCandidates = interpreterCodeCandidates(inner, EVAL_E_INTERPRETERS.has(prog) ? /[ce]/ : /c/);
|
|
8397
8589
|
if (codeCandidates.length > 0) {
|
|
8398
8590
|
reasons.push(`inline code executed via '${prog}'`);
|
|
8399
8591
|
for (const code of codeCandidates) {
|
|
8592
|
+
if (code.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8593
|
+
reasons.push("computed interpreter code requires approval");
|
|
8594
|
+
return "high";
|
|
8595
|
+
}
|
|
8400
8596
|
const nested = classifyAtDepth(code, depth + 1);
|
|
8401
8597
|
reasons.push(...nested.reasons);
|
|
8402
8598
|
level = maxLevel(level, nested.level);
|
|
@@ -8406,6 +8602,10 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8406
8602
|
}
|
|
8407
8603
|
if (prog === "eval" && inner.length > 1) {
|
|
8408
8604
|
reasons.push("dynamic evaluation via 'eval'");
|
|
8605
|
+
if (inner.slice(1).some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) {
|
|
8606
|
+
reasons.push("computed eval code requires approval");
|
|
8607
|
+
return "high";
|
|
8608
|
+
}
|
|
8409
8609
|
const nested = classifyAtDepth(inner.slice(1).join(" "), depth + 1);
|
|
8410
8610
|
reasons.push(...nested.reasons);
|
|
8411
8611
|
return maxLevel(level, nested.level);
|
|
@@ -8418,6 +8618,10 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8418
8618
|
reasons.push("write to a raw block device via tee");
|
|
8419
8619
|
return maxLevel(level, "high");
|
|
8420
8620
|
}
|
|
8621
|
+
if (gitDirectoryWriteTarget(prog, inner.slice(1))) {
|
|
8622
|
+
reasons.push(`'${prog}' writes to a protected or unresolved path`);
|
|
8623
|
+
return maxLevel(level, "high");
|
|
8624
|
+
}
|
|
8421
8625
|
if (prog === "rm") {
|
|
8422
8626
|
const flags = inner.slice(1).filter((arg) => arg.startsWith("-"));
|
|
8423
8627
|
const targets = inner.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
@@ -8430,12 +8634,131 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8430
8634
|
reasons.push("file removal via 'rm'");
|
|
8431
8635
|
return maxLevel(level, "medium");
|
|
8432
8636
|
}
|
|
8637
|
+
if (prog === "git" && setsProgramRunningGitConfig(inner.slice(1))) {
|
|
8638
|
+
reasons.push("git config naming a program git runs");
|
|
8639
|
+
return maxLevel(level, "high");
|
|
8640
|
+
}
|
|
8433
8641
|
if ((prog === "chmod" || prog === "chown" || prog === "chgrp") && inner.some((arg) => shortFlagContains(arg, RECURSIVE_SHORT_FLAGS) || arg === "--recursive")) {
|
|
8434
8642
|
reasons.push(`recursive '${prog}'`);
|
|
8435
8643
|
return maxLevel(level, "high");
|
|
8436
8644
|
}
|
|
8437
8645
|
return level;
|
|
8438
8646
|
}
|
|
8647
|
+
/** Programs whose last operand is the path they write. */
|
|
8648
|
+
const DESTINATION_WRITERS = /* @__PURE__ */ new Set([
|
|
8649
|
+
"cp",
|
|
8650
|
+
"install",
|
|
8651
|
+
"ln",
|
|
8652
|
+
"rsync",
|
|
8653
|
+
"scp"
|
|
8654
|
+
]);
|
|
8655
|
+
/** Programs that may write or remove any path operand. */
|
|
8656
|
+
const OPERAND_WRITERS = /* @__PURE__ */ new Set([
|
|
8657
|
+
"mv",
|
|
8658
|
+
"tee",
|
|
8659
|
+
"touch",
|
|
8660
|
+
"truncate",
|
|
8661
|
+
"sed",
|
|
8662
|
+
"chmod",
|
|
8663
|
+
"chown",
|
|
8664
|
+
"chgrp",
|
|
8665
|
+
"patch",
|
|
8666
|
+
"rm",
|
|
8667
|
+
"unlink"
|
|
8668
|
+
]);
|
|
8669
|
+
function gitDirectoryWriteTarget(prog, args) {
|
|
8670
|
+
const operands = args.filter((arg) => !arg.startsWith("-"));
|
|
8671
|
+
if (DESTINATION_WRITERS.has(prog)) {
|
|
8672
|
+
const targets = args.flatMap((arg, index) => {
|
|
8673
|
+
if (arg === "-t" || arg === "--target-directory") return args[index + 1] ?? [];
|
|
8674
|
+
if (arg.startsWith("--target-directory=")) return arg.slice(19);
|
|
8675
|
+
if (/^-t./.test(arg)) return arg.slice(2);
|
|
8676
|
+
return [];
|
|
8677
|
+
});
|
|
8678
|
+
targets.push(operands[operands.length - 1] ?? "");
|
|
8679
|
+
return targets.some(isProtectedOrUnresolvedPath);
|
|
8680
|
+
}
|
|
8681
|
+
if (OPERAND_WRITERS.has(prog)) return operands.some(isProtectedOrUnresolvedPath);
|
|
8682
|
+
if (prog === "dd") return args.some((arg) => arg.startsWith("of=") && isProtectedOrUnresolvedPath(arg.slice(3)));
|
|
8683
|
+
return false;
|
|
8684
|
+
}
|
|
8685
|
+
/** Config keys whose value is a program, script or hook location git runs. */
|
|
8686
|
+
const PROGRAM_GIT_CONFIG_KEY = /^(core\.(hookspath|fsmonitor|sshcommand|pager|editor|askpass|gitproxy)|sequence\.editor|diff\.external|gpg(\.[^.]+)?\.program|credential(\..+)?\.helper|alias\..+|(diff|merge|filter|difftool|mergetool)\..+\.(command|cmd|textconv|driver|clean|smudge|process)|.+\.sshcommand|uploadpack\.packobjectshook|include(if\..+)?\.path)$/i;
|
|
8687
|
+
const GIT_GLOBAL_VALUE_OPTIONS = /* @__PURE__ */ new Set([
|
|
8688
|
+
"-C",
|
|
8689
|
+
"-c",
|
|
8690
|
+
"--git-dir",
|
|
8691
|
+
"--work-tree",
|
|
8692
|
+
"--namespace",
|
|
8693
|
+
"--super-prefix",
|
|
8694
|
+
"--config-env",
|
|
8695
|
+
"--attr-source"
|
|
8696
|
+
]);
|
|
8697
|
+
const GIT_CONFIG_READ_OPTIONS = /* @__PURE__ */ new Set([
|
|
8698
|
+
"--get",
|
|
8699
|
+
"--get-all",
|
|
8700
|
+
"--get-regexp",
|
|
8701
|
+
"--get-urlmatch",
|
|
8702
|
+
"--get-color",
|
|
8703
|
+
"--get-colorbool",
|
|
8704
|
+
"--list",
|
|
8705
|
+
"-l"
|
|
8706
|
+
]);
|
|
8707
|
+
const GIT_CONFIG_VALUE_OPTIONS = /* @__PURE__ */ new Set([
|
|
8708
|
+
"-f",
|
|
8709
|
+
"--file",
|
|
8710
|
+
"--blob",
|
|
8711
|
+
"--type",
|
|
8712
|
+
"--default",
|
|
8713
|
+
"--comment",
|
|
8714
|
+
"--value"
|
|
8715
|
+
]);
|
|
8716
|
+
/** `git -c <key>=<value>` or a `git config` write whose key names a program git runs. */
|
|
8717
|
+
function setsProgramRunningGitConfig(args) {
|
|
8718
|
+
if (args.some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) return true;
|
|
8719
|
+
const programKey = (key) => key.includes(SUBSTITUTION_PLACEHOLDER) || PROGRAM_GIT_CONFIG_KEY.test(key);
|
|
8720
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
8721
|
+
const arg = args[index];
|
|
8722
|
+
const configValue = arg === "-c" || arg === "--config-env" ? args[index + 1] : arg.startsWith("-c") && arg.length > 2 ? arg.slice(2) : arg.startsWith("--config-env=") ? arg.slice(13) : void 0;
|
|
8723
|
+
if (configValue !== void 0 && programKey(configValue.split("=")[0])) return true;
|
|
8724
|
+
if (GIT_GLOBAL_VALUE_OPTIONS.has(arg)) {
|
|
8725
|
+
index += 1;
|
|
8726
|
+
continue;
|
|
8727
|
+
}
|
|
8728
|
+
if (arg.startsWith("-")) continue;
|
|
8729
|
+
if (arg !== "config") return false;
|
|
8730
|
+
const words = [];
|
|
8731
|
+
let options = true;
|
|
8732
|
+
let readOnly = false;
|
|
8733
|
+
let unset = false;
|
|
8734
|
+
for (let cursor = index + 1; cursor < args.length; cursor += 1) {
|
|
8735
|
+
const word = args[cursor];
|
|
8736
|
+
if (options && word === "--") {
|
|
8737
|
+
options = false;
|
|
8738
|
+
continue;
|
|
8739
|
+
}
|
|
8740
|
+
if (options && GIT_CONFIG_READ_OPTIONS.has(word)) {
|
|
8741
|
+
readOnly = true;
|
|
8742
|
+
continue;
|
|
8743
|
+
}
|
|
8744
|
+
if (options && (word === "--unset" || word === "--unset-all")) {
|
|
8745
|
+
unset = true;
|
|
8746
|
+
continue;
|
|
8747
|
+
}
|
|
8748
|
+
if (options && GIT_CONFIG_VALUE_OPTIONS.has(word)) {
|
|
8749
|
+
cursor += 1;
|
|
8750
|
+
continue;
|
|
8751
|
+
}
|
|
8752
|
+
if (options && word.startsWith("-")) continue;
|
|
8753
|
+
words.push(word);
|
|
8754
|
+
}
|
|
8755
|
+
if (readOnly || words[0] === "get" || words[0] === "list") return false;
|
|
8756
|
+
const keyIndex = words[0] === "set" || words[0] === "unset" ? 1 : 0;
|
|
8757
|
+
const key = words[keyIndex];
|
|
8758
|
+
return (unset || words[0] === "unset" || words.length > keyIndex + 1) && key !== void 0 && programKey(key);
|
|
8759
|
+
}
|
|
8760
|
+
return false;
|
|
8761
|
+
}
|
|
8439
8762
|
/**
|
|
8440
8763
|
* Detect a fork bomb: a shell function that recursively calls itself and
|
|
8441
8764
|
* backgrounds the call, e.g. `:(){ :|:& };:`. shell-quote does not model function
|
|
@@ -8482,33 +8805,56 @@ function classifyAtDepth(command, depth) {
|
|
|
8482
8805
|
level: "high",
|
|
8483
8806
|
reasons: ["fork bomb pattern"]
|
|
8484
8807
|
};
|
|
8808
|
+
let scan;
|
|
8485
8809
|
let tokens;
|
|
8486
8810
|
try {
|
|
8487
|
-
|
|
8811
|
+
scan = scanShellCommand(trimmed);
|
|
8812
|
+
tokens = parse$1(scan.text, () => SUBSTITUTION_PLACEHOLDER);
|
|
8488
8813
|
} catch {
|
|
8489
8814
|
return {
|
|
8490
8815
|
level: "high",
|
|
8491
8816
|
reasons: ["command could not be parsed (fail closed)"]
|
|
8492
8817
|
};
|
|
8493
8818
|
}
|
|
8819
|
+
if (tokens.some(isComment)) return {
|
|
8820
|
+
level: "high",
|
|
8821
|
+
reasons: ["command text could not be fully analyzed (fail closed)"]
|
|
8822
|
+
};
|
|
8494
8823
|
if (tokens.length === 0) return {
|
|
8495
8824
|
level: "low",
|
|
8496
8825
|
reasons: []
|
|
8497
8826
|
};
|
|
8498
8827
|
const reasons = [];
|
|
8499
8828
|
let level = "low";
|
|
8829
|
+
for (const code of scan.substitutions) {
|
|
8830
|
+
const nested = classifyAtDepth(code, depth + 1);
|
|
8831
|
+
reasons.push(...nested.reasons);
|
|
8832
|
+
level = maxLevel(level, maxLevel(nested.level, "unclassified"));
|
|
8833
|
+
}
|
|
8500
8834
|
const segmentProgs = [];
|
|
8501
8835
|
const joinerAfter = [];
|
|
8836
|
+
const segmentComputedInputs = [];
|
|
8502
8837
|
let current = [];
|
|
8503
8838
|
let currentHerestrings = [];
|
|
8504
8839
|
let pendingHerestring = false;
|
|
8840
|
+
let pendingRedirectOperand = false;
|
|
8841
|
+
let currentRedirectInput = false;
|
|
8505
8842
|
const flushSegment = (joiner) => {
|
|
8843
|
+
if (pendingRedirectOperand || pendingHerestring) {
|
|
8844
|
+
reasons.push("incomplete redirection requires approval");
|
|
8845
|
+
level = "high";
|
|
8846
|
+
}
|
|
8506
8847
|
if (current.length > 0) {
|
|
8507
8848
|
const localReasons = [];
|
|
8508
8849
|
let segmentLevel = classifySimpleCommand(current, localReasons, depth);
|
|
8509
8850
|
const lead = leadingProgram(current);
|
|
8510
8851
|
if (currentHerestrings.length > 0 && (INTERPRETERS.has(lead) || SOURCE_BUILTINS.has(lead))) for (const code of currentHerestrings) {
|
|
8511
8852
|
localReasons.push(`inline code executed via '${lead} <<<'`);
|
|
8853
|
+
if (code.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8854
|
+
localReasons.push("computed interpreter input requires approval");
|
|
8855
|
+
segmentLevel = "high";
|
|
8856
|
+
continue;
|
|
8857
|
+
}
|
|
8512
8858
|
const nested = classifyAtDepth(code, depth + 1);
|
|
8513
8859
|
localReasons.push(...nested.reasons);
|
|
8514
8860
|
segmentLevel = maxLevel(segmentLevel, nested.level);
|
|
@@ -8516,16 +8862,24 @@ function classifyAtDepth(command, depth) {
|
|
|
8516
8862
|
level = maxLevel(level, segmentLevel);
|
|
8517
8863
|
reasons.push(...localReasons);
|
|
8518
8864
|
segmentProgs.push(lead);
|
|
8865
|
+
segmentComputedInputs.push(current.some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER)) || currentHerestrings.length > 0 || currentRedirectInput);
|
|
8519
8866
|
joinerAfter.push(joiner);
|
|
8520
8867
|
}
|
|
8521
8868
|
current = [];
|
|
8522
8869
|
currentHerestrings = [];
|
|
8523
8870
|
pendingHerestring = false;
|
|
8871
|
+
pendingRedirectOperand = false;
|
|
8872
|
+
currentRedirectInput = false;
|
|
8524
8873
|
};
|
|
8525
8874
|
for (const token of tokens) {
|
|
8526
8875
|
if (isOperator$1(token)) {
|
|
8527
8876
|
const op = token.op;
|
|
8528
8877
|
if (op === "<<<") {
|
|
8878
|
+
level = maxLevel(level, "unclassified");
|
|
8879
|
+
if (/^\d+$/.test(current[current.length - 1] ?? "")) {
|
|
8880
|
+
reasons.push("ambiguous file descriptor requires approval");
|
|
8881
|
+
level = "high";
|
|
8882
|
+
}
|
|
8529
8883
|
pendingHerestring = true;
|
|
8530
8884
|
continue;
|
|
8531
8885
|
}
|
|
@@ -8533,10 +8887,24 @@ function classifyAtDepth(command, depth) {
|
|
|
8533
8887
|
flushSegment(op);
|
|
8534
8888
|
continue;
|
|
8535
8889
|
}
|
|
8890
|
+
if (WRITE_REDIRECT_OPS.has(op) || op === "<" || op === "<&" || op === ">&") {
|
|
8891
|
+
if (op === "<" || op === "<&" || op === "<>") currentRedirectInput = true;
|
|
8892
|
+
level = maxLevel(level, "unclassified");
|
|
8893
|
+
if (/^\d+$/.test(current[current.length - 1] ?? "")) {
|
|
8894
|
+
reasons.push("ambiguous file descriptor requires approval");
|
|
8895
|
+
level = "high";
|
|
8896
|
+
}
|
|
8897
|
+
pendingRedirectOperand = true;
|
|
8898
|
+
continue;
|
|
8899
|
+
}
|
|
8536
8900
|
continue;
|
|
8537
8901
|
}
|
|
8538
8902
|
const str = asString(token);
|
|
8539
8903
|
if (str !== null) {
|
|
8904
|
+
if (pendingRedirectOperand) {
|
|
8905
|
+
pendingRedirectOperand = false;
|
|
8906
|
+
continue;
|
|
8907
|
+
}
|
|
8540
8908
|
if (pendingHerestring) {
|
|
8541
8909
|
currentHerestrings.push(str);
|
|
8542
8910
|
pendingHerestring = false;
|
|
@@ -8548,10 +8916,19 @@ function classifyAtDepth(command, depth) {
|
|
|
8548
8916
|
reasons.push("fetch-and-execute: downloaded content executed by an interpreter");
|
|
8549
8917
|
level = maxLevel(level, "high");
|
|
8550
8918
|
}
|
|
8551
|
-
if (
|
|
8919
|
+
if (groupFeedsInterpreter(segmentProgs, joinerAfter, (index) => segmentComputedInputs[index] === true)) {
|
|
8920
|
+
reasons.push("pipeline script input requires approval");
|
|
8921
|
+
level = "high";
|
|
8922
|
+
}
|
|
8923
|
+
const redirected = writeRedirectTargets(tokens);
|
|
8924
|
+
if (redirected.some((target) => BLOCK_DEVICE_RE.test(target))) {
|
|
8552
8925
|
reasons.push("write redirected to a raw block device");
|
|
8553
8926
|
level = maxLevel(level, "high");
|
|
8554
8927
|
}
|
|
8928
|
+
if (redirected.some(isProtectedOrUnresolvedPath)) {
|
|
8929
|
+
reasons.push("write redirected to a protected or unresolved path");
|
|
8930
|
+
level = maxLevel(level, "high");
|
|
8931
|
+
}
|
|
8555
8932
|
return {
|
|
8556
8933
|
level,
|
|
8557
8934
|
reasons
|
|
@@ -8575,14 +8952,20 @@ const FETCH_EXEC_CONNECTORS = /* @__PURE__ */ new Set([
|
|
|
8575
8952
|
* pipe or a process-substitution boundary.
|
|
8576
8953
|
*/
|
|
8577
8954
|
function isFetchAndExecute(progs, joinerAfter) {
|
|
8955
|
+
return groupFeedsInterpreter(progs, joinerAfter, (index) => NETWORK_FETCHERS.has(progs[index]));
|
|
8956
|
+
}
|
|
8957
|
+
function groupFeedsInterpreter(progs, joinerAfter, isSource) {
|
|
8578
8958
|
let start = 0;
|
|
8579
8959
|
while (start < progs.length) {
|
|
8580
8960
|
let end = start;
|
|
8581
8961
|
while (end < progs.length - 1 && FETCH_EXEC_CONNECTORS.has(joinerAfter[end])) end += 1;
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8962
|
+
let source = false;
|
|
8963
|
+
let sink = false;
|
|
8964
|
+
for (let index = start; index <= end; index += 1) {
|
|
8965
|
+
source ||= isSource(index);
|
|
8966
|
+
sink ||= FETCH_SINK_PROGRAMS.has(progs[index]);
|
|
8967
|
+
}
|
|
8968
|
+
if (source && sink) return true;
|
|
8586
8969
|
start = end + 1;
|
|
8587
8970
|
}
|
|
8588
8971
|
return false;
|
|
@@ -8607,7 +8990,8 @@ const WRITE_REDIRECT_OPS = /* @__PURE__ */ new Set([
|
|
|
8607
8990
|
"&>>",
|
|
8608
8991
|
"<>"
|
|
8609
8992
|
]);
|
|
8610
|
-
function
|
|
8993
|
+
function writeRedirectTargets(tokens) {
|
|
8994
|
+
const targets = [];
|
|
8611
8995
|
for (let i = 0; i < tokens.length; i += 1) {
|
|
8612
8996
|
const token = tokens[i];
|
|
8613
8997
|
if (isOperator$1(token) && WRITE_REDIRECT_OPS.has(token.op)) {
|
|
@@ -8615,11 +8999,16 @@ function writesToBlockDevice(tokens) {
|
|
|
8615
8999
|
const following = tokens[targetIndex];
|
|
8616
9000
|
if (isOperator$1(following) && following.op === "|") targetIndex += 1;
|
|
8617
9001
|
const target = asString(tokens[targetIndex]);
|
|
8618
|
-
if (target
|
|
9002
|
+
if (target) targets.push(target);
|
|
8619
9003
|
}
|
|
8620
9004
|
}
|
|
8621
|
-
return
|
|
9005
|
+
return targets;
|
|
8622
9006
|
}
|
|
9007
|
+
/** A path with a `.git` segment, compared the way case-insensitive filesystems and Windows do. */
|
|
9008
|
+
function isGitDirectoryPath(target) {
|
|
9009
|
+
return target.split(/[\\/]/).some((segment) => segment.replace(/[. ]+$/, "").toLowerCase() === ".git");
|
|
9010
|
+
}
|
|
9011
|
+
const isProtectedOrUnresolvedPath = (target) => isGitDirectoryPath(target) || target.includes(SUBSTITUTION_PLACEHOLDER);
|
|
8623
9012
|
//#endregion
|
|
8624
9013
|
//#region src/tools/gateway/stages/commandRisk.ts
|
|
8625
9014
|
/**
|
|
@@ -8706,7 +9095,7 @@ var ServerToolExecutor = class {
|
|
|
8706
9095
|
const status = err?.response?.status || "unknown";
|
|
8707
9096
|
if (err?.response?.data?.errorCode === "insufficient_credits") return outOfCreditsToolResult(toolName, err.response.data.error);
|
|
8708
9097
|
logger.error(`[ServerToolExecutor] Request failed for ${toolName}: ${errorMessage} (status: ${status})`);
|
|
8709
|
-
logger.debug(`[ServerToolExecutor]
|
|
9098
|
+
logger.debug(`[ServerToolExecutor] Error code: ${err?.code ?? "none"}`);
|
|
8710
9099
|
return `Error executing ${toolName}: ${errorMessage}`;
|
|
8711
9100
|
}
|
|
8712
9101
|
}
|
|
@@ -9629,6 +10018,7 @@ function wrapToolWithPermission(tool, deps) {
|
|
|
9629
10018
|
const originalFn = tool.toolFn;
|
|
9630
10019
|
const toolName = tool.toolSchema.name;
|
|
9631
10020
|
const isMcpTool = tool._isMcpTool === true;
|
|
10021
|
+
if (isMcpTool) permissionManager.catalog.markMcpTool(toolName);
|
|
9632
10022
|
return {
|
|
9633
10023
|
...tool,
|
|
9634
10024
|
toolFn: async (input) => {
|
|
@@ -14023,7 +14413,7 @@ async function requestShellCommandPermission(toolName, command, cwd, deps) {
|
|
|
14023
14413
|
allowed: false,
|
|
14024
14414
|
reason: "Parent session ended"
|
|
14025
14415
|
};
|
|
14026
|
-
if (!permissionManager.needsPermission(toolName)) return { allowed: true };
|
|
14416
|
+
if (permissionManager.isExactCommandSessionTrusted(toolName, command, cwd) || !permissionManager.needsPermission(toolName)) return { allowed: true };
|
|
14027
14417
|
const risk = classifyCommandRisk(command);
|
|
14028
14418
|
const reasons = risk.reasons.length ? `\nReasons: ${risk.reasons.join("; ")}` : "";
|
|
14029
14419
|
const preview = `Hook shell command [${risk.level} risk] in ${cwd}:\n${command}${reasons}`;
|
|
@@ -14037,7 +14427,7 @@ async function requestShellCommandPermission(toolName, command, cwd, deps) {
|
|
|
14037
14427
|
};
|
|
14038
14428
|
switch (action) {
|
|
14039
14429
|
case "allow-session":
|
|
14040
|
-
permissionManager.
|
|
14430
|
+
permissionManager.trustExactCommandForSession(toolName, command, cwd);
|
|
14041
14431
|
return { allowed: true };
|
|
14042
14432
|
case "allow-once":
|
|
14043
14433
|
case "allow-always": return { allowed: true };
|
|
@@ -15075,8 +15465,11 @@ function optionsAreReadOnly(args, grammar) {
|
|
|
15075
15465
|
const REFUSED_OPTIONS = {
|
|
15076
15466
|
go: { long: [
|
|
15077
15467
|
"-exec",
|
|
15468
|
+
"--exec",
|
|
15078
15469
|
"-toolexec",
|
|
15079
|
-
"
|
|
15470
|
+
"--toolexec",
|
|
15471
|
+
"-vettool",
|
|
15472
|
+
"--vettool"
|
|
15080
15473
|
] },
|
|
15081
15474
|
cargo: { long: ["--config"] }
|
|
15082
15475
|
};
|
|
@@ -15260,11 +15653,11 @@ function sessionCommandPrefixes(command) {
|
|
|
15260
15653
|
const text = command.replace(/\s+$/, "");
|
|
15261
15654
|
if (text.length === 0) return null;
|
|
15262
15655
|
if (hasShellExpansion(text)) return null;
|
|
15263
|
-
if (/[\
|
|
15656
|
+
if (/[^\S \t]/.test(text) || /`/.test(text) || text.includes("$(") || text.includes("<(") || text.includes(">(")) return null;
|
|
15264
15657
|
if (classifyCommandRisk(text).level === "high") return null;
|
|
15265
15658
|
let tokens;
|
|
15266
15659
|
try {
|
|
15267
|
-
tokens = parse$1(text, (key) => `$${key}`);
|
|
15660
|
+
tokens = parse$1(scanShellCommand(text).text, (key) => `$${key}`);
|
|
15268
15661
|
} catch {
|
|
15269
15662
|
return null;
|
|
15270
15663
|
}
|
|
@@ -15278,6 +15671,7 @@ function sessionCommandPrefixes(command) {
|
|
|
15278
15671
|
words = [];
|
|
15279
15672
|
return true;
|
|
15280
15673
|
};
|
|
15674
|
+
if (tokens.some(isComment)) return null;
|
|
15281
15675
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
15282
15676
|
const token = tokens[index];
|
|
15283
15677
|
if (isOperator(token)) {
|
|
@@ -15318,6 +15712,7 @@ var PermissionManager = class {
|
|
|
15318
15712
|
this.trustedTools = /* @__PURE__ */ new Set();
|
|
15319
15713
|
this.sessionTrustedTools = /* @__PURE__ */ new Set();
|
|
15320
15714
|
this.sessionTrustedCommands = /* @__PURE__ */ new Map();
|
|
15715
|
+
this.sessionTrustedExactCommands = /* @__PURE__ */ new Map();
|
|
15321
15716
|
this.deniedTools = /* @__PURE__ */ new Set();
|
|
15322
15717
|
this._sandboxMode = "disabled";
|
|
15323
15718
|
this._sandboxActive = false;
|
|
@@ -15381,7 +15776,7 @@ var PermissionManager = class {
|
|
|
15381
15776
|
* Get list of all trusted tools
|
|
15382
15777
|
*/
|
|
15383
15778
|
getTrustedTools() {
|
|
15384
|
-
return Array.from(this.trustedTools).sort();
|
|
15779
|
+
return Array.from(this.trustedTools).filter((toolName) => this.catalog.canTrust(toolName)).sort();
|
|
15385
15780
|
}
|
|
15386
15781
|
/**
|
|
15387
15782
|
* Check if a tool is currently trusted
|
|
@@ -15455,6 +15850,22 @@ var PermissionManager = class {
|
|
|
15455
15850
|
return prefixes !== null && prefixes.every((prefix) => approved.has(prefix));
|
|
15456
15851
|
}
|
|
15457
15852
|
/**
|
|
15853
|
+
* Trust, for the current session, later calls of this tool with exactly this command text run
|
|
15854
|
+
* in this directory. Used where the command does not come from the model (lifecycle hooks), so
|
|
15855
|
+
* it is never scoped.
|
|
15856
|
+
*/
|
|
15857
|
+
trustExactCommandForSession(toolName, command, cwd) {
|
|
15858
|
+
if (this.deniedTools.has(toolName)) return false;
|
|
15859
|
+
const approved = this.sessionTrustedExactCommands.get(toolName) ?? /* @__PURE__ */ new Set();
|
|
15860
|
+
approved.add(JSON.stringify([cwd, command]));
|
|
15861
|
+
this.sessionTrustedExactCommands.set(toolName, approved);
|
|
15862
|
+
return true;
|
|
15863
|
+
}
|
|
15864
|
+
isExactCommandSessionTrusted(toolName, command, cwd) {
|
|
15865
|
+
if (this.deniedTools.has(toolName)) return false;
|
|
15866
|
+
return this.sessionTrustedExactCommands.get(toolName)?.has(JSON.stringify([cwd, command])) ?? false;
|
|
15867
|
+
}
|
|
15868
|
+
/**
|
|
15458
15869
|
* Check if a tool is trusted for the current session
|
|
15459
15870
|
*/
|
|
15460
15871
|
isSessionTrusted(toolName) {
|
|
@@ -15473,6 +15884,7 @@ var PermissionManager = class {
|
|
|
15473
15884
|
clearSessionTrust() {
|
|
15474
15885
|
this.sessionTrustedTools.clear();
|
|
15475
15886
|
this.sessionTrustedCommands.clear();
|
|
15887
|
+
this.sessionTrustedExactCommands.clear();
|
|
15476
15888
|
this.sandboxEscalationApprovals.clear();
|
|
15477
15889
|
}
|
|
15478
15890
|
/**
|
|
@@ -19724,8 +20136,8 @@ async function buildSandbox(input) {
|
|
|
19724
20136
|
const { config, sessionId, permissionManager, checkpointStore } = input;
|
|
19725
20137
|
const log = input.log ?? consoleLog;
|
|
19726
20138
|
const [{ createSandboxRuntime }, { SandboxOrchestrator }, { DEFAULT_SANDBOX_CONFIG }, { ProxyManager }, { ViolationLogStore }] = await Promise.all([
|
|
19727
|
-
import("./SandboxRuntimeAdapter-
|
|
19728
|
-
import("./SandboxOrchestrator-
|
|
20139
|
+
import("./SandboxRuntimeAdapter-BjJwJNfg.mjs"),
|
|
20140
|
+
import("./SandboxOrchestrator-yORi2eFV.mjs"),
|
|
19729
20141
|
import("./types-BFIvwByC.mjs"),
|
|
19730
20142
|
import("./ProxyManager-TxEKlgdO.mjs"),
|
|
19731
20143
|
import("./ViolationLogStore-byEhxa2A.mjs")
|