@bike4mind/cli 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AgentHistoryStore-C3hJOgpM.mjs → AgentHistoryStore-DrZ47hqO.mjs} +503 -46
- package/dist/{ApiClient-CeuIcSY8.mjs → ApiClient-B8VxyNEM.mjs} +3 -3
- package/dist/{BubblewrapRuntime-BF5wXaNS.mjs → BubblewrapRuntime-DotKnqtu.mjs} +2 -2
- package/dist/ConfigStore-1lUx9qD8.mjs +2 -0
- package/dist/{ConfigStore-nr0ebq4v.mjs → ConfigStore-DfuE49PH.mjs} +17 -1
- package/dist/{Logger-CovZt7LL.mjs → Logger-D6QD3c7G.mjs} +2878 -1200
- package/dist/{SandboxOrchestrator-DTz_5Zub.mjs → SandboxOrchestrator-Cm9L1TRR.mjs} +1 -1
- package/dist/{SandboxRuntimeAdapter-X0HAkbpW.mjs → SandboxRuntimeAdapter-DF9hg5Xl.mjs} +1 -1
- package/dist/{SandboxRuntimeAdapter-CC5KlbZ8.mjs → SandboxRuntimeAdapter-HEkl0-qG.mjs} +2 -2
- package/dist/{SeatbeltRuntime-zdxVqGZ3.mjs → SeatbeltRuntime-CYsIp616.mjs} +2 -2
- package/dist/{WorkItemsClient-lKJCPP0j.mjs → WorkItemsClient-sUftLgOz.mjs} +1 -1
- package/dist/{buildToolSearch-BlOSK4m3.mjs → buildToolSearch-Bb-DPCb0.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-De8Q0ivE.mjs} +163 -40
- package/dist/{fit-vnmP4Dfc.mjs → fit-BsHUrxwe.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-Ca1l2hMC.mjs} +1 -1
- package/dist/{package-BTvxFRbB.mjs → package-hEkaJgsy.mjs} +1 -1
- package/dist/{pathValidation-BRqf4HFX-CHwtwp3O.mjs → pathValidation-C4ADzpUR-BPIpINwZ.mjs} +36 -12
- package/dist/{serve-BLBhPkyw.mjs → serve-CiSddein.mjs} +91 -18
- package/dist/{updateChecker-uDIZuEZg.mjs → updateChecker-dZqiMftm.mjs} +1 -1
- package/package.json +12 -13
- 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
|
|
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-DfuE49PH.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-De8Q0ivE.mjs";
|
|
4
|
+
import { At as isPlaceholderImageSigningSecret, B as LOW_CONFIDENCE_COMPLETION_MODES, G as NotFoundError, Gt as secureParameters, Ht as reasoningChannelOf, I as ExpectedToolError, Jt as splitEquals, M as DecisionTextPartSchema, Mt as isRetryableError, N as DecisionsRequestSchema, Ot as isExpectedToolError, Rt as obfuscateApiKey, St as getMcpProviderMetadata, T as ChatModels, U as McpServerName, V as MODEL_DECLINED_MESSAGE, Y as PermissionDeniedError, a as htmlFirstH1, dt as assertAuthOriginMatchesApiKey, fn as frontmatterHasSourceStamp, h as ApiKeyType, ht as createReasoningWithholder, i as htmlErrorTitle, in as withholdsReasoning, it as SEARCH_RESULT_CARDS_LANGUAGE, jt as isProviderRefusalStopReason, kt as isPlaceholderApiKey, n as SESSION_ID_PATTERN, o as escapeArtifactBodyJson, qt as signImageUrl, r as isValidSessionId, rn as withRetry, 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-D6QD3c7G.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-Ca1l2hMC.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";
|
|
@@ -1270,6 +1270,7 @@ var apiKeyService_exports$1 = /* @__PURE__ */ __exportAll$2({
|
|
|
1270
1270
|
setApiKey: () => setApiKey,
|
|
1271
1271
|
sharedAdminKeyProviders: () => sharedAdminKeyProviders,
|
|
1272
1272
|
t: () => apiKeyService_exports$2,
|
|
1273
|
+
usableApiKey: () => usableApiKey,
|
|
1273
1274
|
userKeyProviders: () => userKeyProviders
|
|
1274
1275
|
});
|
|
1275
1276
|
const createApiKeySchema = z$1.object({
|
|
@@ -1348,6 +1349,15 @@ const ENV_KEY_MAP = {
|
|
|
1348
1349
|
const envKey = (name) => process.env.B4M_SELF_HOST === "true" && process.env[name]?.trim() || null;
|
|
1349
1350
|
/** What getEffectiveLLMApiKeys returns in place of a user's own key once it has expired. */
|
|
1350
1351
|
const EXPIRED_API_KEY = "expired";
|
|
1352
|
+
/**
|
|
1353
|
+
* The trimmed key when `value` is a usable credential, else null: absent, blank, the expired marker
|
|
1354
|
+
* and any recognized placeholder are not credentials. The one predicate for "can this go upstream".
|
|
1355
|
+
*/
|
|
1356
|
+
const usableApiKey = (value) => {
|
|
1357
|
+
const trimmed = value?.trim();
|
|
1358
|
+
if (!trimmed || trimmed === "expired" || isPlaceholderApiKey(trimmed)) return null;
|
|
1359
|
+
return trimmed;
|
|
1360
|
+
};
|
|
1351
1361
|
const getSerperKey = async (adapters) => {
|
|
1352
1362
|
const { db } = adapters;
|
|
1353
1363
|
return (await db.adminSettings.findBySettingName("SerperKey"))?.settingValue;
|
|
@@ -1566,6 +1576,7 @@ var apiKeyService_exports$2 = /* @__PURE__ */ __exportAll({
|
|
|
1566
1576
|
listOwnApiKeys: () => listOwnApiKeys,
|
|
1567
1577
|
setApiKey: () => setApiKey,
|
|
1568
1578
|
sharedAdminKeyProviders: () => sharedAdminKeyProviders,
|
|
1579
|
+
usableApiKey: () => usableApiKey,
|
|
1569
1580
|
userKeyProviders: () => userKeyProviders
|
|
1570
1581
|
});
|
|
1571
1582
|
//#endregion
|
|
@@ -1621,7 +1632,7 @@ function createStructuredResultValidator(schema) {
|
|
|
1621
1632
|
};
|
|
1622
1633
|
}
|
|
1623
1634
|
//#endregion
|
|
1624
|
-
//#region ../../b4m-core/services/dist/webfetch-
|
|
1635
|
+
//#region ../../b4m-core/services/dist/webfetch-DXZS-v_A.mjs
|
|
1625
1636
|
const htmlToMarkdown = (html, _isArxiv = false) => {
|
|
1626
1637
|
const turndownService = new turndown({
|
|
1627
1638
|
headingStyle: "atx",
|
|
@@ -1907,6 +1918,7 @@ async function plainFetchScrape(url, options) {
|
|
|
1907
1918
|
title
|
|
1908
1919
|
};
|
|
1909
1920
|
}
|
|
1921
|
+
const URL_NOT_IN_CONVERSATION_MESSAGE = "This URL does not appear in anything the user sent or in an earlier search, page, file or tool result in this conversation, so it was not fetched. Only fetch URLs exactly as they appear there; to find a page, use web_search, or ask the user to paste the link.";
|
|
1910
1922
|
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
1911
1923
|
const PDF_TIMEOUT_MS = 9e4;
|
|
1912
1924
|
const WEB_FETCH_CONTENT_CAP = 5e4;
|
|
@@ -2185,6 +2197,10 @@ const webFetchTool = {
|
|
|
2185
2197
|
toolFn: async (value) => {
|
|
2186
2198
|
const params = value;
|
|
2187
2199
|
Logger.globalInstance.log("🌐 WebFetch Tool: Starting fetch for URL:", params.url);
|
|
2200
|
+
if (context.urlProvenance && !context.urlProvenance.allows(params.url)) {
|
|
2201
|
+
context.logger.warn("WebFetch refused a URL not present in the conversation");
|
|
2202
|
+
throw new ExpectedToolError(URL_NOT_IN_CONVERSATION_MESSAGE);
|
|
2203
|
+
}
|
|
2188
2204
|
try {
|
|
2189
2205
|
await context.statusUpdate({}, `Fetching content from ${params.url}...`);
|
|
2190
2206
|
const result = await firecrawlFetch({ db: context.db }, params.url, { offset: params.offset });
|
|
@@ -2368,7 +2384,7 @@ const WEB_SEARCH_MAP_PROMPT = [
|
|
|
2368
2384
|
"explanation or citations. Omit it only if none of the places actually answer the question."
|
|
2369
2385
|
].join("\n");
|
|
2370
2386
|
//#endregion
|
|
2371
|
-
//#region ../../b4m-core/services/dist/websearch-
|
|
2387
|
+
//#region ../../b4m-core/services/dist/websearch-Cce90Bvo.mjs
|
|
2372
2388
|
/**
|
|
2373
2389
|
* Shown to the model under tool results that carry the turn's shared numbers, so it cites them the
|
|
2374
2390
|
* way forced retrieval's header asks it to cite the documents numbered before them. Keep it a directive:
|
|
@@ -2718,6 +2734,7 @@ async function serpApiSearch(adapters, query, num_results, options) {
|
|
|
2718
2734
|
setSerpApiGeoTargeting(searchParams, options);
|
|
2719
2735
|
const bucket = recencyBucket(options?.recencyDays);
|
|
2720
2736
|
if (bucket) searchParams.set("tbs", SERPAPI_QDR[bucket]);
|
|
2737
|
+
if (options?.pageOffset && options.pageOffset > 0) searchParams.set("start", String(options.pageOffset));
|
|
2721
2738
|
url.search = searchParams.toString();
|
|
2722
2739
|
const maxAttempts = Math.min(Math.max(1, options?.maxAttempts ?? SERPAPI_MAX_ATTEMPTS), SERPAPI_MAX_ATTEMPTS);
|
|
2723
2740
|
const failures = [];
|
|
@@ -3010,10 +3027,13 @@ function createSearxngProvider(baseUrl) {
|
|
|
3010
3027
|
});
|
|
3011
3028
|
const bucket = recencyBucket(options?.recencyDays);
|
|
3012
3029
|
if (bucket) params.set("time_range", bucket);
|
|
3030
|
+
const pageno = options?.pageIndex && options.pageIndex > 1 ? options.pageIndex : 1;
|
|
3031
|
+
if (pageno > 1) params.set("pageno", String(pageno));
|
|
3013
3032
|
url.search = params.toString();
|
|
3014
3033
|
const request = {
|
|
3015
3034
|
q: query,
|
|
3016
3035
|
...bucket && { time_range: bucket },
|
|
3036
|
+
...pageno > 1 && { pageno },
|
|
3017
3037
|
limit
|
|
3018
3038
|
};
|
|
3019
3039
|
const controller = new AbortController();
|
|
@@ -3695,7 +3715,7 @@ async function isOperationalBillingEnabled(db, logger, holder) {
|
|
|
3695
3715
|
return holder ? isFreeTierHolder(holder) : false;
|
|
3696
3716
|
}
|
|
3697
3717
|
//#endregion
|
|
3698
|
-
//#region ../../b4m-core/services/dist/toolGenerators-
|
|
3718
|
+
//#region ../../b4m-core/services/dist/toolGenerators-CflzUkRh.mjs
|
|
3699
3719
|
const diceRoll = async (parameters) => {
|
|
3700
3720
|
if (!parameters?.sides || !parameters?.times) throw new Error("Tool dice roll: Missing required parameters");
|
|
3701
3721
|
return sum(times(parameters.times, () => random(1, parameters.sides))).toString();
|
|
@@ -4561,7 +4581,7 @@ const askUserQuestionTool = {
|
|
|
4561
4581
|
* re-export them without pulling the full tool graph. `index.ts` re-exports them
|
|
4562
4582
|
* so the server barrel's public API is unchanged.
|
|
4563
4583
|
*/
|
|
4564
|
-
const generateTools = (userId, user, logger, { db, getEntitlements, retrievalFilter, kbScope, inlinedAttachmentIds, attachedFileIds, fullyInlinedAttachmentIds, suppressLakeArms, sessionRetrievalTags, sessionReaderConsentDatalakeTags, sessionLakeScopeExplicit, sessionIncludeLibraryFiles, sessionPreauthorizedLakeIds, organizationId, governingOrgModelPolicy, authOrigin, apiKeyId, questId, requestConfirmation, slackDestination, numberCitables, decide, toLedgerModel, getAbortSignal }, storage, imageGenerateStorage, statusUpdate, onStart, onFinish, llm, config, model, imageProcessorLambdaName, tools, allowedDirectories, entitlementKeys = [], sessionId, codeMinifier, availableModels, onToolLlmUsage, servingModel) => {
|
|
4584
|
+
const generateTools = (userId, user, logger, { db, getEntitlements, retrievalFilter, kbScope, inlinedAttachmentIds, attachedFileIds, fullyInlinedAttachmentIds, suppressLakeArms, sessionRetrievalTags, sessionReaderConsentDatalakeTags, sessionLakeScopeExplicit, sessionIncludeLibraryFiles, sessionPreauthorizedLakeIds, organizationId, governingOrgModelPolicy, authOrigin, apiKeyId, questId, requestConfirmation, urlProvenance, slackDestination, numberCitables, decide, toLedgerModel, getAbortSignal }, storage, imageGenerateStorage, statusUpdate, onStart, onFinish, llm, config, model, imageProcessorLambdaName, tools, allowedDirectories, entitlementKeys = [], sessionId, codeMinifier, availableModels, onToolLlmUsage, servingModel) => {
|
|
4565
4585
|
assertAuthOriginMatchesApiKey(authOrigin, apiKeyId);
|
|
4566
4586
|
const context = {
|
|
4567
4587
|
userId,
|
|
@@ -4569,6 +4589,7 @@ const generateTools = (userId, user, logger, { db, getEntitlements, retrievalFil
|
|
|
4569
4589
|
sessionId,
|
|
4570
4590
|
questId,
|
|
4571
4591
|
requestConfirmation,
|
|
4592
|
+
urlProvenance,
|
|
4572
4593
|
slackDestination,
|
|
4573
4594
|
logger,
|
|
4574
4595
|
db,
|
|
@@ -5133,7 +5154,7 @@ function formatSpanPreview(filePath, matchedText, replacement) {
|
|
|
5133
5154
|
/**
|
|
5134
5155
|
* Authorized, read-only resolve for the permission layer: validate the path,
|
|
5135
5156
|
* read the file, and resolve the span WITHOUT writing. Runs the SAME path
|
|
5136
|
-
* authorization ({@link
|
|
5157
|
+
* authorization ({@link assertWritablePath}) and matcher ({@link resolveEdit}) as
|
|
5137
5158
|
* the write path, so a preflight can never read a path the tool itself would
|
|
5138
5159
|
* refuse (no raw-model-path read - closes the auth-bypass / special-file-DoS
|
|
5139
5160
|
* hole) and its fuzzy verdict matches what execution will do. Throws the same
|
|
@@ -5141,7 +5162,7 @@ function formatSpanPreview(filePath, matchedText, replacement) {
|
|
|
5141
5162
|
*/
|
|
5142
5163
|
async function resolveEditLocalFile(params, allowedDirectories) {
|
|
5143
5164
|
const { path: filePath, old_string, new_string } = params;
|
|
5144
|
-
const resolvedPath =
|
|
5165
|
+
const resolvedPath = assertWritablePath(filePath, allowedDirectories, "edit");
|
|
5145
5166
|
if (!existsSync(resolvedPath)) throw new Error(`File not found: ${filePath}`);
|
|
5146
5167
|
const currentContent = await promises.readFile(resolvedPath, "utf-8");
|
|
5147
5168
|
const resolved = resolveEdit(currentContent, old_string, new_string);
|
|
@@ -5155,7 +5176,7 @@ async function resolveEditLocalFile(params, allowedDirectories) {
|
|
|
5155
5176
|
}
|
|
5156
5177
|
async function editLocalFile(params, allowedDirectories) {
|
|
5157
5178
|
const { path: filePath, old_string, new_string, confirmedFuzzyHash, gateSnapshot } = params;
|
|
5158
|
-
const resolvedPath =
|
|
5179
|
+
const resolvedPath = assertWritablePath(filePath, allowedDirectories, "edit");
|
|
5159
5180
|
if (!existsSync(resolvedPath)) throw new Error(`File not found: ${filePath}`);
|
|
5160
5181
|
const currentContent = await promises.readFile(resolvedPath, "utf-8");
|
|
5161
5182
|
const currentHash = sha256(currentContent);
|
|
@@ -6842,10 +6863,10 @@ const latticeToolDefinitions = {
|
|
|
6842
6863
|
*/
|
|
6843
6864
|
const getCliOnlyTools = async () => {
|
|
6844
6865
|
const [{ createFileTool }, { globFilesTool }, { grepSearchTool }, { deleteFileTool }, { bashExecuteTool }] = await Promise.all([
|
|
6845
|
-
import("./createFile-
|
|
6846
|
-
import("./globFiles-
|
|
6847
|
-
import("./grepSearch-
|
|
6848
|
-
import("./deleteFile-
|
|
6866
|
+
import("./createFile-CPKmd6Uf-Bk-3V2T3.mjs"),
|
|
6867
|
+
import("./globFiles-CoapsO8G-CpvQo-R2.mjs"),
|
|
6868
|
+
import("./grepSearch-DeH7M2e7-BIvo-yNy.mjs"),
|
|
6869
|
+
import("./deleteFile-CD_xQ7Y6-C1X4Ievb.mjs"),
|
|
6849
6870
|
import("./bashExecute-CrdPpBqk-CgK1gZa2.mjs")
|
|
6850
6871
|
]);
|
|
6851
6872
|
return {
|
|
@@ -8289,6 +8310,186 @@ function maxLevel(a, b) {
|
|
|
8289
8310
|
function isOperator$1(token) {
|
|
8290
8311
|
return typeof token === "object" && token !== null && "op" in token;
|
|
8291
8312
|
}
|
|
8313
|
+
function isComment(token) {
|
|
8314
|
+
return typeof token === "object" && token !== null && "comment" in token;
|
|
8315
|
+
}
|
|
8316
|
+
const SHELL_METACHARACTERS = /* @__PURE__ */ new Set([
|
|
8317
|
+
";",
|
|
8318
|
+
"&",
|
|
8319
|
+
"|",
|
|
8320
|
+
"(",
|
|
8321
|
+
")",
|
|
8322
|
+
"<",
|
|
8323
|
+
">"
|
|
8324
|
+
]);
|
|
8325
|
+
const BASH_BLANKS = /* @__PURE__ */ new Set([
|
|
8326
|
+
" ",
|
|
8327
|
+
" ",
|
|
8328
|
+
"\n"
|
|
8329
|
+
]);
|
|
8330
|
+
const OPAQUE_SHELL_KEYWORDS = /* @__PURE__ */ new Set([
|
|
8331
|
+
"if",
|
|
8332
|
+
"then",
|
|
8333
|
+
"elif",
|
|
8334
|
+
"else",
|
|
8335
|
+
"fi",
|
|
8336
|
+
"for",
|
|
8337
|
+
"while",
|
|
8338
|
+
"until",
|
|
8339
|
+
"do",
|
|
8340
|
+
"done",
|
|
8341
|
+
"case",
|
|
8342
|
+
"esac",
|
|
8343
|
+
"function",
|
|
8344
|
+
"select",
|
|
8345
|
+
"coproc",
|
|
8346
|
+
"time",
|
|
8347
|
+
"!",
|
|
8348
|
+
"{",
|
|
8349
|
+
"}",
|
|
8350
|
+
"[[",
|
|
8351
|
+
"]]"
|
|
8352
|
+
]);
|
|
8353
|
+
/** Stands in for a command substitution; its code is classified on its own. */
|
|
8354
|
+
const SUBSTITUTION_PLACEHOLDER = "__cmdsub__";
|
|
8355
|
+
/**
|
|
8356
|
+
* Rewrite a bash command so shell-quote tokenizes it the way bash does. Unquoted newlines become
|
|
8357
|
+
* `;`, bash comments are dropped, a mid-word `#` and whitespace bash does not split on are
|
|
8358
|
+
* escaped, heredocs require approval, and each `$(...)` or backquote substitution (quoted or
|
|
8359
|
+
* not) is replaced by a placeholder word and returned
|
|
8360
|
+
* separately for classification.
|
|
8361
|
+
*/
|
|
8362
|
+
function scanShellCommand(command) {
|
|
8363
|
+
const substitutions = [];
|
|
8364
|
+
const { text } = scanCode(command, 0, null, substitutions);
|
|
8365
|
+
return {
|
|
8366
|
+
text,
|
|
8367
|
+
substitutions
|
|
8368
|
+
};
|
|
8369
|
+
}
|
|
8370
|
+
/** Scan unquoted shell code from `start` until `stop` closes it, or to the end of input. */
|
|
8371
|
+
function scanCode(src, start, stop, substitutions) {
|
|
8372
|
+
let out = "";
|
|
8373
|
+
let wordStart = true;
|
|
8374
|
+
let parenDepth = 0;
|
|
8375
|
+
let caseDepth = 0;
|
|
8376
|
+
let index = start;
|
|
8377
|
+
for (; index < src.length; index += 1) {
|
|
8378
|
+
const character = src[index];
|
|
8379
|
+
if (character === stop && (stop === "`" || parenDepth === 0 && caseDepth === 0)) return {
|
|
8380
|
+
text: out,
|
|
8381
|
+
end: index
|
|
8382
|
+
};
|
|
8383
|
+
if (wordStart && /^case[\s;]/.test(src.slice(index, index + 5))) caseDepth += 1;
|
|
8384
|
+
if (wordStart && caseDepth > 0 && /^esac(?:[\s;)&|]|$)/.test(src.slice(index, index + 5))) caseDepth -= 1;
|
|
8385
|
+
if (character === "'") {
|
|
8386
|
+
const close = src.indexOf("'", index + 1);
|
|
8387
|
+
const end = close < 0 ? src.length - 1 : close;
|
|
8388
|
+
out += src.slice(index, end + 1);
|
|
8389
|
+
index = end;
|
|
8390
|
+
wordStart = false;
|
|
8391
|
+
continue;
|
|
8392
|
+
}
|
|
8393
|
+
if (character === "$" && src[index + 1] === "'") {
|
|
8394
|
+
let end = index + 2;
|
|
8395
|
+
while (end < src.length && src[end] !== "'") end += src[end] === "\\" ? 2 : 1;
|
|
8396
|
+
out += src.slice(index, end + 1);
|
|
8397
|
+
index = end;
|
|
8398
|
+
wordStart = false;
|
|
8399
|
+
continue;
|
|
8400
|
+
}
|
|
8401
|
+
if (character === "$" && src[index + 1] === "(" || character === "`") {
|
|
8402
|
+
index = scanSubstitution(src, index, substitutions);
|
|
8403
|
+
out += SUBSTITUTION_PLACEHOLDER;
|
|
8404
|
+
wordStart = false;
|
|
8405
|
+
continue;
|
|
8406
|
+
}
|
|
8407
|
+
if (character === "\"") {
|
|
8408
|
+
const quoted = scanDoubleQuoted(src, index + 1, substitutions);
|
|
8409
|
+
out += `"${quoted.text}"`;
|
|
8410
|
+
index = quoted.end;
|
|
8411
|
+
wordStart = false;
|
|
8412
|
+
continue;
|
|
8413
|
+
}
|
|
8414
|
+
if (character === "\\") {
|
|
8415
|
+
if (src[index + 1] === "\n") {
|
|
8416
|
+
index += 1;
|
|
8417
|
+
continue;
|
|
8418
|
+
}
|
|
8419
|
+
out += character + (src[index + 1] ?? "");
|
|
8420
|
+
index += 1;
|
|
8421
|
+
wordStart = false;
|
|
8422
|
+
continue;
|
|
8423
|
+
}
|
|
8424
|
+
if (character === "#") {
|
|
8425
|
+
if (wordStart) {
|
|
8426
|
+
while (index + 1 < src.length && src[index + 1] !== "\n") index += 1;
|
|
8427
|
+
continue;
|
|
8428
|
+
}
|
|
8429
|
+
out += "\\#";
|
|
8430
|
+
continue;
|
|
8431
|
+
}
|
|
8432
|
+
if (character === "\n") {
|
|
8433
|
+
out += ";";
|
|
8434
|
+
wordStart = true;
|
|
8435
|
+
continue;
|
|
8436
|
+
}
|
|
8437
|
+
if (character === "<" && src[index + 1] === "<" && src[index + 2] !== "<") throw new Error("Heredoc syntax requires approval");
|
|
8438
|
+
if (character === "<" && src.startsWith("<<<", index)) {
|
|
8439
|
+
out += "<<<";
|
|
8440
|
+
index += 2;
|
|
8441
|
+
wordStart = true;
|
|
8442
|
+
continue;
|
|
8443
|
+
}
|
|
8444
|
+
if (BASH_BLANKS.has(character) || SHELL_METACHARACTERS.has(character)) {
|
|
8445
|
+
if (character === "(") parenDepth += 1;
|
|
8446
|
+
if (character === ")" && parenDepth > 0) parenDepth -= 1;
|
|
8447
|
+
out += character;
|
|
8448
|
+
wordStart = true;
|
|
8449
|
+
continue;
|
|
8450
|
+
}
|
|
8451
|
+
if (/\s/.test(character)) {
|
|
8452
|
+
out += `\\${character}`;
|
|
8453
|
+
wordStart = false;
|
|
8454
|
+
continue;
|
|
8455
|
+
}
|
|
8456
|
+
out += character;
|
|
8457
|
+
wordStart = false;
|
|
8458
|
+
}
|
|
8459
|
+
return {
|
|
8460
|
+
text: out,
|
|
8461
|
+
end: index
|
|
8462
|
+
};
|
|
8463
|
+
}
|
|
8464
|
+
/** Record the code of the substitution opening at `index`; returns the index of its closer. */
|
|
8465
|
+
function scanSubstitution(src, index, substitutions) {
|
|
8466
|
+
const backquote = src[index] === "`";
|
|
8467
|
+
const codeStart = index + (backquote ? 1 : 2);
|
|
8468
|
+
const { end } = scanCode(src, codeStart, backquote ? "`" : ")", []);
|
|
8469
|
+
const code = src.slice(codeStart, end);
|
|
8470
|
+
if (backquote && /\\[`$\\]/.test(code)) throw new Error("Unsupported escaped backquote substitution");
|
|
8471
|
+
substitutions.push(code);
|
|
8472
|
+
return end;
|
|
8473
|
+
}
|
|
8474
|
+
/** Scan a double-quoted string body from `start`; returns its text and the closing quote index. */
|
|
8475
|
+
function scanDoubleQuoted(src, start, substitutions) {
|
|
8476
|
+
let text = "";
|
|
8477
|
+
let index = start;
|
|
8478
|
+
for (; index < src.length && src[index] !== "\""; index += 1) {
|
|
8479
|
+
const character = src[index];
|
|
8480
|
+
if (character === "\\") {
|
|
8481
|
+
text += character + (src[index + 1] ?? "");
|
|
8482
|
+
index += 1;
|
|
8483
|
+
} else if (character === "$" && src[index + 1] === "(" || character === "`") {
|
|
8484
|
+
index = scanSubstitution(src, index, substitutions);
|
|
8485
|
+
text += SUBSTITUTION_PLACEHOLDER;
|
|
8486
|
+
} else text += character;
|
|
8487
|
+
}
|
|
8488
|
+
return {
|
|
8489
|
+
text,
|
|
8490
|
+
end: index
|
|
8491
|
+
};
|
|
8492
|
+
}
|
|
8292
8493
|
function asString(token) {
|
|
8293
8494
|
if (typeof token === "string") return token;
|
|
8294
8495
|
if (typeof token === "object" && token !== null && "pattern" in token) return token.pattern;
|
|
@@ -8392,11 +8593,27 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8392
8593
|
const inner = args.slice(index);
|
|
8393
8594
|
if (inner.length === 0) return level;
|
|
8394
8595
|
const prog = programName$1(inner[0]);
|
|
8596
|
+
if (ENV_ASSIGNMENT.test(inner[0]) || OPAQUE_SHELL_KEYWORDS.has(prog)) {
|
|
8597
|
+
reasons.push("shell context requires approval");
|
|
8598
|
+
return "high";
|
|
8599
|
+
}
|
|
8600
|
+
if (prog.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8601
|
+
reasons.push("computed program requires approval");
|
|
8602
|
+
return "high";
|
|
8603
|
+
}
|
|
8604
|
+
if ((DESTINATION_WRITERS.has(prog) || OPERAND_WRITERS.has(prog) || prog === "dd") && inner.slice(1).some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) {
|
|
8605
|
+
reasons.push("computed writer arguments require approval");
|
|
8606
|
+
return "high";
|
|
8607
|
+
}
|
|
8395
8608
|
if (INTERPRETERS.has(prog)) {
|
|
8396
8609
|
const codeCandidates = interpreterCodeCandidates(inner, EVAL_E_INTERPRETERS.has(prog) ? /[ce]/ : /c/);
|
|
8397
8610
|
if (codeCandidates.length > 0) {
|
|
8398
8611
|
reasons.push(`inline code executed via '${prog}'`);
|
|
8399
8612
|
for (const code of codeCandidates) {
|
|
8613
|
+
if (code.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8614
|
+
reasons.push("computed interpreter code requires approval");
|
|
8615
|
+
return "high";
|
|
8616
|
+
}
|
|
8400
8617
|
const nested = classifyAtDepth(code, depth + 1);
|
|
8401
8618
|
reasons.push(...nested.reasons);
|
|
8402
8619
|
level = maxLevel(level, nested.level);
|
|
@@ -8406,6 +8623,10 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8406
8623
|
}
|
|
8407
8624
|
if (prog === "eval" && inner.length > 1) {
|
|
8408
8625
|
reasons.push("dynamic evaluation via 'eval'");
|
|
8626
|
+
if (inner.slice(1).some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) {
|
|
8627
|
+
reasons.push("computed eval code requires approval");
|
|
8628
|
+
return "high";
|
|
8629
|
+
}
|
|
8409
8630
|
const nested = classifyAtDepth(inner.slice(1).join(" "), depth + 1);
|
|
8410
8631
|
reasons.push(...nested.reasons);
|
|
8411
8632
|
return maxLevel(level, nested.level);
|
|
@@ -8418,6 +8639,10 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8418
8639
|
reasons.push("write to a raw block device via tee");
|
|
8419
8640
|
return maxLevel(level, "high");
|
|
8420
8641
|
}
|
|
8642
|
+
if (gitDirectoryWriteTarget(prog, inner.slice(1))) {
|
|
8643
|
+
reasons.push(`'${prog}' writes to a protected or unresolved path`);
|
|
8644
|
+
return maxLevel(level, "high");
|
|
8645
|
+
}
|
|
8421
8646
|
if (prog === "rm") {
|
|
8422
8647
|
const flags = inner.slice(1).filter((arg) => arg.startsWith("-"));
|
|
8423
8648
|
const targets = inner.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
@@ -8430,12 +8655,131 @@ function classifySimpleCommand(args, reasons, depth) {
|
|
|
8430
8655
|
reasons.push("file removal via 'rm'");
|
|
8431
8656
|
return maxLevel(level, "medium");
|
|
8432
8657
|
}
|
|
8658
|
+
if (prog === "git" && setsProgramRunningGitConfig(inner.slice(1))) {
|
|
8659
|
+
reasons.push("git config naming a program git runs");
|
|
8660
|
+
return maxLevel(level, "high");
|
|
8661
|
+
}
|
|
8433
8662
|
if ((prog === "chmod" || prog === "chown" || prog === "chgrp") && inner.some((arg) => shortFlagContains(arg, RECURSIVE_SHORT_FLAGS) || arg === "--recursive")) {
|
|
8434
8663
|
reasons.push(`recursive '${prog}'`);
|
|
8435
8664
|
return maxLevel(level, "high");
|
|
8436
8665
|
}
|
|
8437
8666
|
return level;
|
|
8438
8667
|
}
|
|
8668
|
+
/** Programs whose last operand is the path they write. */
|
|
8669
|
+
const DESTINATION_WRITERS = /* @__PURE__ */ new Set([
|
|
8670
|
+
"cp",
|
|
8671
|
+
"install",
|
|
8672
|
+
"ln",
|
|
8673
|
+
"rsync",
|
|
8674
|
+
"scp"
|
|
8675
|
+
]);
|
|
8676
|
+
/** Programs that may write or remove any path operand. */
|
|
8677
|
+
const OPERAND_WRITERS = /* @__PURE__ */ new Set([
|
|
8678
|
+
"mv",
|
|
8679
|
+
"tee",
|
|
8680
|
+
"touch",
|
|
8681
|
+
"truncate",
|
|
8682
|
+
"sed",
|
|
8683
|
+
"chmod",
|
|
8684
|
+
"chown",
|
|
8685
|
+
"chgrp",
|
|
8686
|
+
"patch",
|
|
8687
|
+
"rm",
|
|
8688
|
+
"unlink"
|
|
8689
|
+
]);
|
|
8690
|
+
function gitDirectoryWriteTarget(prog, args) {
|
|
8691
|
+
const operands = args.filter((arg) => !arg.startsWith("-"));
|
|
8692
|
+
if (DESTINATION_WRITERS.has(prog)) {
|
|
8693
|
+
const targets = args.flatMap((arg, index) => {
|
|
8694
|
+
if (arg === "-t" || arg === "--target-directory") return args[index + 1] ?? [];
|
|
8695
|
+
if (arg.startsWith("--target-directory=")) return arg.slice(19);
|
|
8696
|
+
if (/^-t./.test(arg)) return arg.slice(2);
|
|
8697
|
+
return [];
|
|
8698
|
+
});
|
|
8699
|
+
targets.push(operands[operands.length - 1] ?? "");
|
|
8700
|
+
return targets.some(isProtectedOrUnresolvedPath);
|
|
8701
|
+
}
|
|
8702
|
+
if (OPERAND_WRITERS.has(prog)) return operands.some(isProtectedOrUnresolvedPath);
|
|
8703
|
+
if (prog === "dd") return args.some((arg) => arg.startsWith("of=") && isProtectedOrUnresolvedPath(arg.slice(3)));
|
|
8704
|
+
return false;
|
|
8705
|
+
}
|
|
8706
|
+
/** Config keys whose value is a program, script or hook location git runs. */
|
|
8707
|
+
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;
|
|
8708
|
+
const GIT_GLOBAL_VALUE_OPTIONS = /* @__PURE__ */ new Set([
|
|
8709
|
+
"-C",
|
|
8710
|
+
"-c",
|
|
8711
|
+
"--git-dir",
|
|
8712
|
+
"--work-tree",
|
|
8713
|
+
"--namespace",
|
|
8714
|
+
"--super-prefix",
|
|
8715
|
+
"--config-env",
|
|
8716
|
+
"--attr-source"
|
|
8717
|
+
]);
|
|
8718
|
+
const GIT_CONFIG_READ_OPTIONS = /* @__PURE__ */ new Set([
|
|
8719
|
+
"--get",
|
|
8720
|
+
"--get-all",
|
|
8721
|
+
"--get-regexp",
|
|
8722
|
+
"--get-urlmatch",
|
|
8723
|
+
"--get-color",
|
|
8724
|
+
"--get-colorbool",
|
|
8725
|
+
"--list",
|
|
8726
|
+
"-l"
|
|
8727
|
+
]);
|
|
8728
|
+
const GIT_CONFIG_VALUE_OPTIONS = /* @__PURE__ */ new Set([
|
|
8729
|
+
"-f",
|
|
8730
|
+
"--file",
|
|
8731
|
+
"--blob",
|
|
8732
|
+
"--type",
|
|
8733
|
+
"--default",
|
|
8734
|
+
"--comment",
|
|
8735
|
+
"--value"
|
|
8736
|
+
]);
|
|
8737
|
+
/** `git -c <key>=<value>` or a `git config` write whose key names a program git runs. */
|
|
8738
|
+
function setsProgramRunningGitConfig(args) {
|
|
8739
|
+
if (args.some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER))) return true;
|
|
8740
|
+
const programKey = (key) => key.includes(SUBSTITUTION_PLACEHOLDER) || PROGRAM_GIT_CONFIG_KEY.test(key);
|
|
8741
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
8742
|
+
const arg = args[index];
|
|
8743
|
+
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;
|
|
8744
|
+
if (configValue !== void 0 && programKey(configValue.split("=")[0])) return true;
|
|
8745
|
+
if (GIT_GLOBAL_VALUE_OPTIONS.has(arg)) {
|
|
8746
|
+
index += 1;
|
|
8747
|
+
continue;
|
|
8748
|
+
}
|
|
8749
|
+
if (arg.startsWith("-")) continue;
|
|
8750
|
+
if (arg !== "config") return false;
|
|
8751
|
+
const words = [];
|
|
8752
|
+
let options = true;
|
|
8753
|
+
let readOnly = false;
|
|
8754
|
+
let unset = false;
|
|
8755
|
+
for (let cursor = index + 1; cursor < args.length; cursor += 1) {
|
|
8756
|
+
const word = args[cursor];
|
|
8757
|
+
if (options && word === "--") {
|
|
8758
|
+
options = false;
|
|
8759
|
+
continue;
|
|
8760
|
+
}
|
|
8761
|
+
if (options && GIT_CONFIG_READ_OPTIONS.has(word)) {
|
|
8762
|
+
readOnly = true;
|
|
8763
|
+
continue;
|
|
8764
|
+
}
|
|
8765
|
+
if (options && (word === "--unset" || word === "--unset-all")) {
|
|
8766
|
+
unset = true;
|
|
8767
|
+
continue;
|
|
8768
|
+
}
|
|
8769
|
+
if (options && GIT_CONFIG_VALUE_OPTIONS.has(word)) {
|
|
8770
|
+
cursor += 1;
|
|
8771
|
+
continue;
|
|
8772
|
+
}
|
|
8773
|
+
if (options && word.startsWith("-")) continue;
|
|
8774
|
+
words.push(word);
|
|
8775
|
+
}
|
|
8776
|
+
if (readOnly || words[0] === "get" || words[0] === "list") return false;
|
|
8777
|
+
const keyIndex = words[0] === "set" || words[0] === "unset" ? 1 : 0;
|
|
8778
|
+
const key = words[keyIndex];
|
|
8779
|
+
return (unset || words[0] === "unset" || words.length > keyIndex + 1) && key !== void 0 && programKey(key);
|
|
8780
|
+
}
|
|
8781
|
+
return false;
|
|
8782
|
+
}
|
|
8439
8783
|
/**
|
|
8440
8784
|
* Detect a fork bomb: a shell function that recursively calls itself and
|
|
8441
8785
|
* backgrounds the call, e.g. `:(){ :|:& };:`. shell-quote does not model function
|
|
@@ -8482,33 +8826,56 @@ function classifyAtDepth(command, depth) {
|
|
|
8482
8826
|
level: "high",
|
|
8483
8827
|
reasons: ["fork bomb pattern"]
|
|
8484
8828
|
};
|
|
8829
|
+
let scan;
|
|
8485
8830
|
let tokens;
|
|
8486
8831
|
try {
|
|
8487
|
-
|
|
8832
|
+
scan = scanShellCommand(trimmed);
|
|
8833
|
+
tokens = parse$1(scan.text, () => SUBSTITUTION_PLACEHOLDER);
|
|
8488
8834
|
} catch {
|
|
8489
8835
|
return {
|
|
8490
8836
|
level: "high",
|
|
8491
8837
|
reasons: ["command could not be parsed (fail closed)"]
|
|
8492
8838
|
};
|
|
8493
8839
|
}
|
|
8840
|
+
if (tokens.some(isComment)) return {
|
|
8841
|
+
level: "high",
|
|
8842
|
+
reasons: ["command text could not be fully analyzed (fail closed)"]
|
|
8843
|
+
};
|
|
8494
8844
|
if (tokens.length === 0) return {
|
|
8495
8845
|
level: "low",
|
|
8496
8846
|
reasons: []
|
|
8497
8847
|
};
|
|
8498
8848
|
const reasons = [];
|
|
8499
8849
|
let level = "low";
|
|
8850
|
+
for (const code of scan.substitutions) {
|
|
8851
|
+
const nested = classifyAtDepth(code, depth + 1);
|
|
8852
|
+
reasons.push(...nested.reasons);
|
|
8853
|
+
level = maxLevel(level, maxLevel(nested.level, "unclassified"));
|
|
8854
|
+
}
|
|
8500
8855
|
const segmentProgs = [];
|
|
8501
8856
|
const joinerAfter = [];
|
|
8857
|
+
const segmentComputedInputs = [];
|
|
8502
8858
|
let current = [];
|
|
8503
8859
|
let currentHerestrings = [];
|
|
8504
8860
|
let pendingHerestring = false;
|
|
8861
|
+
let pendingRedirectOperand = false;
|
|
8862
|
+
let currentRedirectInput = false;
|
|
8505
8863
|
const flushSegment = (joiner) => {
|
|
8864
|
+
if (pendingRedirectOperand || pendingHerestring) {
|
|
8865
|
+
reasons.push("incomplete redirection requires approval");
|
|
8866
|
+
level = "high";
|
|
8867
|
+
}
|
|
8506
8868
|
if (current.length > 0) {
|
|
8507
8869
|
const localReasons = [];
|
|
8508
8870
|
let segmentLevel = classifySimpleCommand(current, localReasons, depth);
|
|
8509
8871
|
const lead = leadingProgram(current);
|
|
8510
8872
|
if (currentHerestrings.length > 0 && (INTERPRETERS.has(lead) || SOURCE_BUILTINS.has(lead))) for (const code of currentHerestrings) {
|
|
8511
8873
|
localReasons.push(`inline code executed via '${lead} <<<'`);
|
|
8874
|
+
if (code.includes(SUBSTITUTION_PLACEHOLDER)) {
|
|
8875
|
+
localReasons.push("computed interpreter input requires approval");
|
|
8876
|
+
segmentLevel = "high";
|
|
8877
|
+
continue;
|
|
8878
|
+
}
|
|
8512
8879
|
const nested = classifyAtDepth(code, depth + 1);
|
|
8513
8880
|
localReasons.push(...nested.reasons);
|
|
8514
8881
|
segmentLevel = maxLevel(segmentLevel, nested.level);
|
|
@@ -8516,16 +8883,24 @@ function classifyAtDepth(command, depth) {
|
|
|
8516
8883
|
level = maxLevel(level, segmentLevel);
|
|
8517
8884
|
reasons.push(...localReasons);
|
|
8518
8885
|
segmentProgs.push(lead);
|
|
8886
|
+
segmentComputedInputs.push(current.some((arg) => arg.includes(SUBSTITUTION_PLACEHOLDER)) || currentHerestrings.length > 0 || currentRedirectInput);
|
|
8519
8887
|
joinerAfter.push(joiner);
|
|
8520
8888
|
}
|
|
8521
8889
|
current = [];
|
|
8522
8890
|
currentHerestrings = [];
|
|
8523
8891
|
pendingHerestring = false;
|
|
8892
|
+
pendingRedirectOperand = false;
|
|
8893
|
+
currentRedirectInput = false;
|
|
8524
8894
|
};
|
|
8525
8895
|
for (const token of tokens) {
|
|
8526
8896
|
if (isOperator$1(token)) {
|
|
8527
8897
|
const op = token.op;
|
|
8528
8898
|
if (op === "<<<") {
|
|
8899
|
+
level = maxLevel(level, "unclassified");
|
|
8900
|
+
if (/^\d+$/.test(current[current.length - 1] ?? "")) {
|
|
8901
|
+
reasons.push("ambiguous file descriptor requires approval");
|
|
8902
|
+
level = "high";
|
|
8903
|
+
}
|
|
8529
8904
|
pendingHerestring = true;
|
|
8530
8905
|
continue;
|
|
8531
8906
|
}
|
|
@@ -8533,10 +8908,24 @@ function classifyAtDepth(command, depth) {
|
|
|
8533
8908
|
flushSegment(op);
|
|
8534
8909
|
continue;
|
|
8535
8910
|
}
|
|
8911
|
+
if (WRITE_REDIRECT_OPS.has(op) || op === "<" || op === "<&" || op === ">&") {
|
|
8912
|
+
if (op === "<" || op === "<&" || op === "<>") currentRedirectInput = true;
|
|
8913
|
+
level = maxLevel(level, "unclassified");
|
|
8914
|
+
if (/^\d+$/.test(current[current.length - 1] ?? "")) {
|
|
8915
|
+
reasons.push("ambiguous file descriptor requires approval");
|
|
8916
|
+
level = "high";
|
|
8917
|
+
}
|
|
8918
|
+
pendingRedirectOperand = true;
|
|
8919
|
+
continue;
|
|
8920
|
+
}
|
|
8536
8921
|
continue;
|
|
8537
8922
|
}
|
|
8538
8923
|
const str = asString(token);
|
|
8539
8924
|
if (str !== null) {
|
|
8925
|
+
if (pendingRedirectOperand) {
|
|
8926
|
+
pendingRedirectOperand = false;
|
|
8927
|
+
continue;
|
|
8928
|
+
}
|
|
8540
8929
|
if (pendingHerestring) {
|
|
8541
8930
|
currentHerestrings.push(str);
|
|
8542
8931
|
pendingHerestring = false;
|
|
@@ -8548,10 +8937,19 @@ function classifyAtDepth(command, depth) {
|
|
|
8548
8937
|
reasons.push("fetch-and-execute: downloaded content executed by an interpreter");
|
|
8549
8938
|
level = maxLevel(level, "high");
|
|
8550
8939
|
}
|
|
8551
|
-
if (
|
|
8940
|
+
if (groupFeedsInterpreter(segmentProgs, joinerAfter, (index) => segmentComputedInputs[index] === true)) {
|
|
8941
|
+
reasons.push("pipeline script input requires approval");
|
|
8942
|
+
level = "high";
|
|
8943
|
+
}
|
|
8944
|
+
const redirected = writeRedirectTargets(tokens);
|
|
8945
|
+
if (redirected.some((target) => BLOCK_DEVICE_RE.test(target))) {
|
|
8552
8946
|
reasons.push("write redirected to a raw block device");
|
|
8553
8947
|
level = maxLevel(level, "high");
|
|
8554
8948
|
}
|
|
8949
|
+
if (redirected.some(isProtectedOrUnresolvedPath)) {
|
|
8950
|
+
reasons.push("write redirected to a protected or unresolved path");
|
|
8951
|
+
level = maxLevel(level, "high");
|
|
8952
|
+
}
|
|
8555
8953
|
return {
|
|
8556
8954
|
level,
|
|
8557
8955
|
reasons
|
|
@@ -8575,14 +8973,20 @@ const FETCH_EXEC_CONNECTORS = /* @__PURE__ */ new Set([
|
|
|
8575
8973
|
* pipe or a process-substitution boundary.
|
|
8576
8974
|
*/
|
|
8577
8975
|
function isFetchAndExecute(progs, joinerAfter) {
|
|
8976
|
+
return groupFeedsInterpreter(progs, joinerAfter, (index) => NETWORK_FETCHERS.has(progs[index]));
|
|
8977
|
+
}
|
|
8978
|
+
function groupFeedsInterpreter(progs, joinerAfter, isSource) {
|
|
8578
8979
|
let start = 0;
|
|
8579
8980
|
while (start < progs.length) {
|
|
8580
8981
|
let end = start;
|
|
8581
8982
|
while (end < progs.length - 1 && FETCH_EXEC_CONNECTORS.has(joinerAfter[end])) end += 1;
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8983
|
+
let source = false;
|
|
8984
|
+
let sink = false;
|
|
8985
|
+
for (let index = start; index <= end; index += 1) {
|
|
8986
|
+
source ||= isSource(index);
|
|
8987
|
+
sink ||= FETCH_SINK_PROGRAMS.has(progs[index]);
|
|
8988
|
+
}
|
|
8989
|
+
if (source && sink) return true;
|
|
8586
8990
|
start = end + 1;
|
|
8587
8991
|
}
|
|
8588
8992
|
return false;
|
|
@@ -8607,7 +9011,8 @@ const WRITE_REDIRECT_OPS = /* @__PURE__ */ new Set([
|
|
|
8607
9011
|
"&>>",
|
|
8608
9012
|
"<>"
|
|
8609
9013
|
]);
|
|
8610
|
-
function
|
|
9014
|
+
function writeRedirectTargets(tokens) {
|
|
9015
|
+
const targets = [];
|
|
8611
9016
|
for (let i = 0; i < tokens.length; i += 1) {
|
|
8612
9017
|
const token = tokens[i];
|
|
8613
9018
|
if (isOperator$1(token) && WRITE_REDIRECT_OPS.has(token.op)) {
|
|
@@ -8615,11 +9020,16 @@ function writesToBlockDevice(tokens) {
|
|
|
8615
9020
|
const following = tokens[targetIndex];
|
|
8616
9021
|
if (isOperator$1(following) && following.op === "|") targetIndex += 1;
|
|
8617
9022
|
const target = asString(tokens[targetIndex]);
|
|
8618
|
-
if (target
|
|
9023
|
+
if (target) targets.push(target);
|
|
8619
9024
|
}
|
|
8620
9025
|
}
|
|
8621
|
-
return
|
|
9026
|
+
return targets;
|
|
9027
|
+
}
|
|
9028
|
+
/** A path with a `.git` segment, compared the way case-insensitive filesystems and Windows do. */
|
|
9029
|
+
function isGitDirectoryPath(target) {
|
|
9030
|
+
return target.split(/[\\/]/).some((segment) => segment.replace(/[. ]+$/, "").toLowerCase() === ".git");
|
|
8622
9031
|
}
|
|
9032
|
+
const isProtectedOrUnresolvedPath = (target) => isGitDirectoryPath(target) || target.includes(SUBSTITUTION_PLACEHOLDER);
|
|
8623
9033
|
//#endregion
|
|
8624
9034
|
//#region src/tools/gateway/stages/commandRisk.ts
|
|
8625
9035
|
/**
|
|
@@ -8706,7 +9116,7 @@ var ServerToolExecutor = class {
|
|
|
8706
9116
|
const status = err?.response?.status || "unknown";
|
|
8707
9117
|
if (err?.response?.data?.errorCode === "insufficient_credits") return outOfCreditsToolResult(toolName, err.response.data.error);
|
|
8708
9118
|
logger.error(`[ServerToolExecutor] Request failed for ${toolName}: ${errorMessage} (status: ${status})`);
|
|
8709
|
-
logger.debug(`[ServerToolExecutor]
|
|
9119
|
+
logger.debug(`[ServerToolExecutor] Error code: ${err?.code ?? "none"}`);
|
|
8710
9120
|
return `Error executing ${toolName}: ${errorMessage}`;
|
|
8711
9121
|
}
|
|
8712
9122
|
}
|
|
@@ -9629,6 +10039,7 @@ function wrapToolWithPermission(tool, deps) {
|
|
|
9629
10039
|
const originalFn = tool.toolFn;
|
|
9630
10040
|
const toolName = tool.toolSchema.name;
|
|
9631
10041
|
const isMcpTool = tool._isMcpTool === true;
|
|
10042
|
+
if (isMcpTool) permissionManager.catalog.markMcpTool(toolName);
|
|
9632
10043
|
return {
|
|
9633
10044
|
...tool,
|
|
9634
10045
|
toolFn: async (input) => {
|
|
@@ -14023,7 +14434,7 @@ async function requestShellCommandPermission(toolName, command, cwd, deps) {
|
|
|
14023
14434
|
allowed: false,
|
|
14024
14435
|
reason: "Parent session ended"
|
|
14025
14436
|
};
|
|
14026
|
-
if (!permissionManager.needsPermission(toolName)) return { allowed: true };
|
|
14437
|
+
if (permissionManager.isExactCommandSessionTrusted(toolName, command, cwd) || !permissionManager.needsPermission(toolName)) return { allowed: true };
|
|
14027
14438
|
const risk = classifyCommandRisk(command);
|
|
14028
14439
|
const reasons = risk.reasons.length ? `\nReasons: ${risk.reasons.join("; ")}` : "";
|
|
14029
14440
|
const preview = `Hook shell command [${risk.level} risk] in ${cwd}:\n${command}${reasons}`;
|
|
@@ -14037,7 +14448,7 @@ async function requestShellCommandPermission(toolName, command, cwd, deps) {
|
|
|
14037
14448
|
};
|
|
14038
14449
|
switch (action) {
|
|
14039
14450
|
case "allow-session":
|
|
14040
|
-
permissionManager.
|
|
14451
|
+
permissionManager.trustExactCommandForSession(toolName, command, cwd);
|
|
14041
14452
|
return { allowed: true };
|
|
14042
14453
|
case "allow-once":
|
|
14043
14454
|
case "allow-always": return { allowed: true };
|
|
@@ -15075,8 +15486,11 @@ function optionsAreReadOnly(args, grammar) {
|
|
|
15075
15486
|
const REFUSED_OPTIONS = {
|
|
15076
15487
|
go: { long: [
|
|
15077
15488
|
"-exec",
|
|
15489
|
+
"--exec",
|
|
15078
15490
|
"-toolexec",
|
|
15079
|
-
"
|
|
15491
|
+
"--toolexec",
|
|
15492
|
+
"-vettool",
|
|
15493
|
+
"--vettool"
|
|
15080
15494
|
] },
|
|
15081
15495
|
cargo: { long: ["--config"] }
|
|
15082
15496
|
};
|
|
@@ -15260,11 +15674,11 @@ function sessionCommandPrefixes(command) {
|
|
|
15260
15674
|
const text = command.replace(/\s+$/, "");
|
|
15261
15675
|
if (text.length === 0) return null;
|
|
15262
15676
|
if (hasShellExpansion(text)) return null;
|
|
15263
|
-
if (/[\
|
|
15677
|
+
if (/[^\S \t]/.test(text) || /`/.test(text) || text.includes("$(") || text.includes("<(") || text.includes(">(")) return null;
|
|
15264
15678
|
if (classifyCommandRisk(text).level === "high") return null;
|
|
15265
15679
|
let tokens;
|
|
15266
15680
|
try {
|
|
15267
|
-
tokens = parse$1(text, (key) => `$${key}`);
|
|
15681
|
+
tokens = parse$1(scanShellCommand(text).text, (key) => `$${key}`);
|
|
15268
15682
|
} catch {
|
|
15269
15683
|
return null;
|
|
15270
15684
|
}
|
|
@@ -15278,6 +15692,7 @@ function sessionCommandPrefixes(command) {
|
|
|
15278
15692
|
words = [];
|
|
15279
15693
|
return true;
|
|
15280
15694
|
};
|
|
15695
|
+
if (tokens.some(isComment)) return null;
|
|
15281
15696
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
15282
15697
|
const token = tokens[index];
|
|
15283
15698
|
if (isOperator(token)) {
|
|
@@ -15318,6 +15733,7 @@ var PermissionManager = class {
|
|
|
15318
15733
|
this.trustedTools = /* @__PURE__ */ new Set();
|
|
15319
15734
|
this.sessionTrustedTools = /* @__PURE__ */ new Set();
|
|
15320
15735
|
this.sessionTrustedCommands = /* @__PURE__ */ new Map();
|
|
15736
|
+
this.sessionTrustedExactCommands = /* @__PURE__ */ new Map();
|
|
15321
15737
|
this.deniedTools = /* @__PURE__ */ new Set();
|
|
15322
15738
|
this._sandboxMode = "disabled";
|
|
15323
15739
|
this._sandboxActive = false;
|
|
@@ -15381,7 +15797,7 @@ var PermissionManager = class {
|
|
|
15381
15797
|
* Get list of all trusted tools
|
|
15382
15798
|
*/
|
|
15383
15799
|
getTrustedTools() {
|
|
15384
|
-
return Array.from(this.trustedTools).sort();
|
|
15800
|
+
return Array.from(this.trustedTools).filter((toolName) => this.catalog.canTrust(toolName)).sort();
|
|
15385
15801
|
}
|
|
15386
15802
|
/**
|
|
15387
15803
|
* Check if a tool is currently trusted
|
|
@@ -15455,6 +15871,22 @@ var PermissionManager = class {
|
|
|
15455
15871
|
return prefixes !== null && prefixes.every((prefix) => approved.has(prefix));
|
|
15456
15872
|
}
|
|
15457
15873
|
/**
|
|
15874
|
+
* Trust, for the current session, later calls of this tool with exactly this command text run
|
|
15875
|
+
* in this directory. Used where the command does not come from the model (lifecycle hooks), so
|
|
15876
|
+
* it is never scoped.
|
|
15877
|
+
*/
|
|
15878
|
+
trustExactCommandForSession(toolName, command, cwd) {
|
|
15879
|
+
if (this.deniedTools.has(toolName)) return false;
|
|
15880
|
+
const approved = this.sessionTrustedExactCommands.get(toolName) ?? /* @__PURE__ */ new Set();
|
|
15881
|
+
approved.add(JSON.stringify([cwd, command]));
|
|
15882
|
+
this.sessionTrustedExactCommands.set(toolName, approved);
|
|
15883
|
+
return true;
|
|
15884
|
+
}
|
|
15885
|
+
isExactCommandSessionTrusted(toolName, command, cwd) {
|
|
15886
|
+
if (this.deniedTools.has(toolName)) return false;
|
|
15887
|
+
return this.sessionTrustedExactCommands.get(toolName)?.has(JSON.stringify([cwd, command])) ?? false;
|
|
15888
|
+
}
|
|
15889
|
+
/**
|
|
15458
15890
|
* Check if a tool is trusted for the current session
|
|
15459
15891
|
*/
|
|
15460
15892
|
isSessionTrusted(toolName) {
|
|
@@ -15473,6 +15905,7 @@ var PermissionManager = class {
|
|
|
15473
15905
|
clearSessionTrust() {
|
|
15474
15906
|
this.sessionTrustedTools.clear();
|
|
15475
15907
|
this.sessionTrustedCommands.clear();
|
|
15908
|
+
this.sessionTrustedExactCommands.clear();
|
|
15476
15909
|
this.sandboxEscalationApprovals.clear();
|
|
15477
15910
|
}
|
|
15478
15911
|
/**
|
|
@@ -19724,8 +20157,8 @@ async function buildSandbox(input) {
|
|
|
19724
20157
|
const { config, sessionId, permissionManager, checkpointStore } = input;
|
|
19725
20158
|
const log = input.log ?? consoleLog;
|
|
19726
20159
|
const [{ createSandboxRuntime }, { SandboxOrchestrator }, { DEFAULT_SANDBOX_CONFIG }, { ProxyManager }, { ViolationLogStore }] = await Promise.all([
|
|
19727
|
-
import("./SandboxRuntimeAdapter-
|
|
19728
|
-
import("./SandboxOrchestrator-
|
|
20160
|
+
import("./SandboxRuntimeAdapter-DF9hg5Xl.mjs"),
|
|
20161
|
+
import("./SandboxOrchestrator-Cm9L1TRR.mjs"),
|
|
19729
20162
|
import("./types-BFIvwByC.mjs"),
|
|
19730
20163
|
import("./ProxyManager-TxEKlgdO.mjs"),
|
|
19731
20164
|
import("./ViolationLogStore-byEhxa2A.mjs")
|
|
@@ -20655,7 +21088,7 @@ const MODEL_ALIASES = {
|
|
|
20655
21088
|
"claude-4.7-opus": ChatModels.CLAUDE_4_7_OPUS,
|
|
20656
21089
|
"claude-4.6-opus": ChatModels.CLAUDE_4_6_OPUS,
|
|
20657
21090
|
"claude-4.6-sonnet": ChatModels.CLAUDE_4_6_SONNET,
|
|
20658
|
-
"claude-4.5-opus": ChatModels.
|
|
21091
|
+
"claude-4.5-opus": ChatModels.CLAUDE_4_8_OPUS,
|
|
20659
21092
|
"claude-4.5-sonnet": ChatModels.CLAUDE_5_5_SONNET,
|
|
20660
21093
|
"claude-4.5-haiku": ChatModels.CLAUDE_4_5_HAIKU,
|
|
20661
21094
|
"claude-4-opus": ChatModels.CLAUDE_4_8_OPUS,
|
|
@@ -20665,13 +21098,8 @@ const MODEL_ALIASES = {
|
|
|
20665
21098
|
"claude-3.5-sonnet": ChatModels.CLAUDE_5_5_SONNET,
|
|
20666
21099
|
"claude-3.5-haiku": ChatModels.CLAUDE_4_5_HAIKU,
|
|
20667
21100
|
"claude-3-opus": ChatModels.CLAUDE_4_8_OPUS,
|
|
20668
|
-
"gpt-4o": ChatModels.GPT4o,
|
|
20669
|
-
"gpt-4o-mini": ChatModels.GPT4o_MINI,
|
|
20670
21101
|
"gpt-4.1": ChatModels.GPT4_1,
|
|
20671
21102
|
"gpt-4.1-mini": ChatModels.GPT4_1_MINI,
|
|
20672
|
-
"gpt-5": ChatModels.GPT5,
|
|
20673
|
-
"gpt-5-mini": ChatModels.GPT5_MINI,
|
|
20674
|
-
"gpt-5-nano": ChatModels.GPT5_NANO,
|
|
20675
21103
|
"gpt-5.1": ChatModels.GPT5_1,
|
|
20676
21104
|
"gpt-5.2": ChatModels.GPT5_2,
|
|
20677
21105
|
"gpt-5.4": ChatModels.GPT5_4,
|
|
@@ -20681,6 +21109,10 @@ const MODEL_ALIASES = {
|
|
|
20681
21109
|
"gpt-5.6-sol": ChatModels.GPT5_6_SOL,
|
|
20682
21110
|
"gpt-5.6-luna": ChatModels.GPT5_6_LUNA,
|
|
20683
21111
|
"gpt-5.6-terra": ChatModels.GPT5_6_TERRA,
|
|
21112
|
+
"gpt-6.2-astra": ChatModels.GPT6_2_ASTRA,
|
|
21113
|
+
"gpt-6.2-sol": ChatModels.GPT6_2_SOL,
|
|
21114
|
+
"gpt-6.1-terra": ChatModels.GPT6_1_TERRA,
|
|
21115
|
+
"gpt-6-luna": ChatModels.GPT6_LUNA,
|
|
20684
21116
|
gemini: ChatModels.GEMINI_3_5_FLASH,
|
|
20685
21117
|
"gemini-pro": ChatModels.GEMINI_3_1_PRO_PREVIEW,
|
|
20686
21118
|
"gemini-flash": ChatModels.GEMINI_3_5_FLASH,
|
|
@@ -20694,8 +21126,8 @@ const MODEL_ALIASES = {
|
|
|
20694
21126
|
grok: ChatModels.GROK_4_5,
|
|
20695
21127
|
"grok-3": ChatModels.GROK_4_5,
|
|
20696
21128
|
"grok-3-fast": ChatModels.GROK_4_5,
|
|
20697
|
-
"grok-3-mini": ChatModels.
|
|
20698
|
-
"grok-3-mini-fast": ChatModels.
|
|
21129
|
+
"grok-3-mini": ChatModels.GROK_4_5,
|
|
21130
|
+
"grok-3-mini-fast": ChatModels.GROK_4_5,
|
|
20699
21131
|
"grok-2": ChatModels.GROK_4_5,
|
|
20700
21132
|
"grok-2-vision": ChatModels.GROK_4_5,
|
|
20701
21133
|
deepseek: ChatModels.DEEPSEEK_FLASH,
|
|
@@ -20726,17 +21158,42 @@ const SUNSETTING_MODEL_ALIASES = {
|
|
|
20726
21158
|
"gpt-4.1-nano": {
|
|
20727
21159
|
model: ChatModels.GPT4_1_NANO,
|
|
20728
21160
|
retiresOn: "2026-10-23",
|
|
20729
|
-
successor: "gpt-
|
|
21161
|
+
successor: "gpt-6-luna"
|
|
20730
21162
|
},
|
|
20731
21163
|
"o4-mini": {
|
|
20732
21164
|
model: ChatModels.O4_MINI,
|
|
20733
21165
|
retiresOn: "2026-10-23",
|
|
20734
|
-
successor: "gpt-
|
|
21166
|
+
successor: "gpt-6-luna"
|
|
20735
21167
|
},
|
|
20736
21168
|
o3: {
|
|
20737
21169
|
model: ChatModels.O3,
|
|
20738
21170
|
retiresOn: "2026-12-11",
|
|
20739
21171
|
successor: "gpt-5.5"
|
|
21172
|
+
},
|
|
21173
|
+
"gpt-5": {
|
|
21174
|
+
model: ChatModels.GPT5,
|
|
21175
|
+
retiresOn: "2026-12-11",
|
|
21176
|
+
successor: "gpt-6.2-sol"
|
|
21177
|
+
},
|
|
21178
|
+
"gpt-5-mini": {
|
|
21179
|
+
model: ChatModels.GPT5_MINI,
|
|
21180
|
+
retiresOn: "2026-12-11",
|
|
21181
|
+
successor: "gpt-6-luna"
|
|
21182
|
+
},
|
|
21183
|
+
"gpt-5-nano": {
|
|
21184
|
+
model: ChatModels.GPT5_NANO,
|
|
21185
|
+
retiresOn: "2026-12-11",
|
|
21186
|
+
successor: "gpt-6-luna"
|
|
21187
|
+
},
|
|
21188
|
+
"gpt-4o": {
|
|
21189
|
+
model: ChatModels.GPT4o,
|
|
21190
|
+
retiresOn: "2027-01-14",
|
|
21191
|
+
successor: "gpt-6-luna"
|
|
21192
|
+
},
|
|
21193
|
+
"gpt-4o-mini": {
|
|
21194
|
+
model: ChatModels.GPT4o_MINI,
|
|
21195
|
+
retiresOn: "2027-01-14",
|
|
21196
|
+
successor: "gpt-6-luna"
|
|
20740
21197
|
}
|
|
20741
21198
|
};
|
|
20742
21199
|
/**
|
|
@@ -20748,8 +21205,8 @@ const RETIRED_MODEL_ALIASES = {
|
|
|
20748
21205
|
"gpt-4.5": "gpt-5.5",
|
|
20749
21206
|
o1: "gpt-5.5",
|
|
20750
21207
|
"o1-preview": "gpt-5.5",
|
|
20751
|
-
"o1-mini": "gpt-
|
|
20752
|
-
"o3-mini": "gpt-
|
|
21208
|
+
"o1-mini": "gpt-6-luna",
|
|
21209
|
+
"o3-mini": "gpt-6-luna",
|
|
20753
21210
|
"gemini-2.0-flash": "gemini-flash",
|
|
20754
21211
|
"gemini-1.5-pro": "gemini-pro",
|
|
20755
21212
|
"gemini-1.5-flash": "gemini-flash",
|