@google/gemini-cli-a2a-server 0.62.0-preview.0 → 0.63.0-nightly.20260928.g2fe7c2d3f
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/a2a-server.mjs +578 -119
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/a2a-server.mjs
CHANGED
|
@@ -66160,7 +66160,8 @@ function hasBlockedPathSegment(p2) {
|
|
|
66160
66160
|
const segments = p2.split(/[/\\]/);
|
|
66161
66161
|
for (const segment of segments) {
|
|
66162
66162
|
const clean = trimTrailingSpacesAndDots(segment.split(":")[0]).toLowerCase();
|
|
66163
|
-
|
|
66163
|
+
const isEnvFile = clean === ".env" || clean.startsWith(".env.") && !SAFE_ENV_TEMPLATES.has(clean);
|
|
66164
|
+
if (clean === ".git" || isEnvFile || clean === "node_modules" || GIT_SFN_REGEX.test(clean) || ENV_SFN_REGEX.test(clean) || NODE_MODULES_SFN_REGEX.test(clean)) {
|
|
66164
66165
|
return true;
|
|
66165
66166
|
}
|
|
66166
66167
|
if (clean.startsWith("gha-creds-") && clean.endsWith(".json") || GHA_CREDS_SFN_REGEX.test(clean)) {
|
|
@@ -66169,16 +66170,22 @@ function hasBlockedPathSegment(p2) {
|
|
|
66169
66170
|
}
|
|
66170
66171
|
return false;
|
|
66171
66172
|
}
|
|
66172
|
-
var GEMINI_DIR, GOOGLE_ACCOUNTS_FILENAME, GIT_SFN_REGEX, ENV_SFN_REGEX, NODE_MODULES_SFN_REGEX, GHA_CREDS_SFN_REGEX;
|
|
66173
|
+
var GEMINI_DIR, GOOGLE_ACCOUNTS_FILENAME, GIT_SFN_REGEX, ENV_SFN_REGEX, NODE_MODULES_SFN_REGEX, GHA_CREDS_SFN_REGEX, SAFE_ENV_TEMPLATES;
|
|
66173
66174
|
var init_paths = __esm({
|
|
66174
66175
|
"packages/core/dist/src/utils/paths.js"() {
|
|
66175
66176
|
"use strict";
|
|
66176
66177
|
GEMINI_DIR = ".gemini";
|
|
66177
66178
|
GOOGLE_ACCOUNTS_FILENAME = "google_accounts.json";
|
|
66178
66179
|
GIT_SFN_REGEX = /^(git|gi[0-9a-f]{4})~\d+$/;
|
|
66179
|
-
ENV_SFN_REGEX = /^(env|en[0-9a-f]{4})~\d
|
|
66180
|
+
ENV_SFN_REGEX = /^(env|en[0-9a-f]{4})~\d+(\..+)?$/i;
|
|
66180
66181
|
NODE_MODULES_SFN_REGEX = /^(node_m|no[0-9a-f]{4})~\d+$/;
|
|
66181
66182
|
GHA_CREDS_SFN_REGEX = /^(gha-cr|gh[0-9a-f]{4})~\d+\.jso(n)?$/;
|
|
66183
|
+
SAFE_ENV_TEMPLATES = /* @__PURE__ */ new Set([
|
|
66184
|
+
".env.example",
|
|
66185
|
+
".env.sample",
|
|
66186
|
+
".env.template",
|
|
66187
|
+
".env.dist"
|
|
66188
|
+
]);
|
|
66182
66189
|
}
|
|
66183
66190
|
});
|
|
66184
66191
|
|
|
@@ -68266,7 +68273,7 @@ var init_ignorePatterns = __esm({
|
|
|
68266
68273
|
});
|
|
68267
68274
|
|
|
68268
68275
|
// packages/core/dist/src/utils/constants.js
|
|
68269
|
-
var REFERENCE_CONTENT_END, DEFAULT_MAX_LINES_TEXT_FILE, MAX_LINE_LENGTH_TEXT_FILE, MAX_FILE_SIZE_MB;
|
|
68276
|
+
var REFERENCE_CONTENT_END, DEFAULT_MAX_LINES_TEXT_FILE, MAX_LINE_LENGTH_TEXT_FILE, MAX_FILE_SIZE_MB, MAX_STORED_TOOL_OUTPUT_BYTES;
|
|
68270
68277
|
var init_constants = __esm({
|
|
68271
68278
|
"packages/core/dist/src/utils/constants.js"() {
|
|
68272
68279
|
"use strict";
|
|
@@ -68274,6 +68281,7 @@ var init_constants = __esm({
|
|
|
68274
68281
|
DEFAULT_MAX_LINES_TEXT_FILE = 2e3;
|
|
68275
68282
|
MAX_LINE_LENGTH_TEXT_FILE = 2e3;
|
|
68276
68283
|
MAX_FILE_SIZE_MB = 20;
|
|
68284
|
+
MAX_STORED_TOOL_OUTPUT_BYTES = 64 * 1024;
|
|
68277
68285
|
}
|
|
68278
68286
|
});
|
|
68279
68287
|
|
|
@@ -68354,8 +68362,41 @@ function decodeUTF32(buf, littleEndian) {
|
|
|
68354
68362
|
}
|
|
68355
68363
|
return out2;
|
|
68356
68364
|
}
|
|
68357
|
-
async function
|
|
68358
|
-
const
|
|
68365
|
+
async function readSecureFileBuffer(filePath, expectedStats) {
|
|
68366
|
+
const initialStats = expectedStats ?? await fs10.promises.stat(filePath);
|
|
68367
|
+
let fileHandle;
|
|
68368
|
+
try {
|
|
68369
|
+
if (typeof fs10.promises.open === "function") {
|
|
68370
|
+
try {
|
|
68371
|
+
fileHandle = await fs10.promises.open(filePath, "r");
|
|
68372
|
+
} catch {
|
|
68373
|
+
}
|
|
68374
|
+
if (fileHandle && typeof fileHandle.stat === "function") {
|
|
68375
|
+
const handleStats = await fileHandle.stat();
|
|
68376
|
+
if (initialStats.dev !== void 0 && initialStats.ino !== void 0 && handleStats && handleStats.dev !== void 0 && handleStats.ino !== void 0 && (initialStats.dev !== handleStats.dev || initialStats.ino !== handleStats.ino)) {
|
|
68377
|
+
throw new Error(`File device or inode changed during read: ${filePath}`);
|
|
68378
|
+
}
|
|
68379
|
+
}
|
|
68380
|
+
}
|
|
68381
|
+
const contentBuffer = fileHandle ? await fileHandle.readFile() : await fs10.promises.readFile(filePath);
|
|
68382
|
+
let postStats;
|
|
68383
|
+
try {
|
|
68384
|
+
postStats = await fs10.promises.stat(filePath);
|
|
68385
|
+
} catch {
|
|
68386
|
+
}
|
|
68387
|
+
if (postStats && initialStats.dev !== void 0 && initialStats.ino !== void 0 && postStats.dev !== void 0 && postStats.ino !== void 0 && (initialStats.dev !== postStats.dev || initialStats.ino !== postStats.ino)) {
|
|
68388
|
+
throw new Error(`File device or inode changed during read: ${filePath}`);
|
|
68389
|
+
}
|
|
68390
|
+
return contentBuffer;
|
|
68391
|
+
} finally {
|
|
68392
|
+
if (fileHandle) {
|
|
68393
|
+
await fileHandle.close().catch(() => {
|
|
68394
|
+
});
|
|
68395
|
+
}
|
|
68396
|
+
}
|
|
68397
|
+
}
|
|
68398
|
+
async function readFileWithEncoding(filePath, expectedStats) {
|
|
68399
|
+
const full = await readSecureFileBuffer(filePath, expectedStats);
|
|
68359
68400
|
if (full.length === 0)
|
|
68360
68401
|
return "";
|
|
68361
68402
|
const bom = detectBOM(full);
|
|
@@ -68554,14 +68595,14 @@ async function processSingleFileContent(filePath, rootDirectory, _fileSystemServ
|
|
|
68554
68595
|
returnDisplay: `Skipped large SVG file (>1MB): ${relativePathForDisplay}`
|
|
68555
68596
|
};
|
|
68556
68597
|
}
|
|
68557
|
-
const content = await readFileWithEncoding(filePath);
|
|
68598
|
+
const content = await readFileWithEncoding(filePath, stats);
|
|
68558
68599
|
return {
|
|
68559
68600
|
llmContent: content,
|
|
68560
68601
|
returnDisplay: `Read SVG as text: ${relativePathForDisplay}`
|
|
68561
68602
|
};
|
|
68562
68603
|
}
|
|
68563
68604
|
case "text": {
|
|
68564
|
-
const content = await readFileWithEncoding(filePath);
|
|
68605
|
+
const content = await readFileWithEncoding(filePath, stats);
|
|
68565
68606
|
const lines = content.split(/\r?\n/);
|
|
68566
68607
|
const originalLineCount = lines.length;
|
|
68567
68608
|
let sliceStart = 0;
|
|
@@ -68611,7 +68652,7 @@ async function processSingleFileContent(filePath, rootDirectory, _fileSystemServ
|
|
|
68611
68652
|
errorType: ToolErrorType.READ_CONTENT_FAILURE
|
|
68612
68653
|
};
|
|
68613
68654
|
}
|
|
68614
|
-
const contentBuffer = await
|
|
68655
|
+
const contentBuffer = await readSecureFileBuffer(filePath, stats);
|
|
68615
68656
|
const base64Data = contentBuffer.toString("base64");
|
|
68616
68657
|
return {
|
|
68617
68658
|
llmContent: {
|
|
@@ -68627,7 +68668,7 @@ async function processSingleFileContent(filePath, rootDirectory, _fileSystemServ
|
|
|
68627
68668
|
case "pdf":
|
|
68628
68669
|
case "video": {
|
|
68629
68670
|
const mimeType = getSpecificMimeType(filePath) ?? "application/octet-stream";
|
|
68630
|
-
const contentBuffer = await
|
|
68671
|
+
const contentBuffer = await readSecureFileBuffer(filePath, stats);
|
|
68631
68672
|
const base64Data = contentBuffer.toString("base64");
|
|
68632
68673
|
return {
|
|
68633
68674
|
llmContent: {
|
|
@@ -221252,8 +221293,8 @@ var GIT_COMMIT_INFO, CLI_VERSION;
|
|
|
221252
221293
|
var init_git_commit = __esm({
|
|
221253
221294
|
"packages/core/dist/src/generated/git-commit.js"() {
|
|
221254
221295
|
"use strict";
|
|
221255
|
-
GIT_COMMIT_INFO = "
|
|
221256
|
-
CLI_VERSION = "0.
|
|
221296
|
+
GIT_COMMIT_INFO = "2fe7c2d3f";
|
|
221297
|
+
CLI_VERSION = "0.63.0-nightly.20260928.g2fe7c2d3f";
|
|
221257
221298
|
}
|
|
221258
221299
|
});
|
|
221259
221300
|
|
|
@@ -292634,7 +292675,12 @@ var init_chatRecordingService = __esm({
|
|
|
292634
292675
|
if (this.kind === "subagent") {
|
|
292635
292676
|
filename = `${safeSessionId}.jsonl`;
|
|
292636
292677
|
} else {
|
|
292637
|
-
|
|
292678
|
+
const shortId = safeSessionId.slice(0, 8);
|
|
292679
|
+
filename = `${SESSION_FILE_PREFIX}${timestamp2}-${shortId}.jsonl`;
|
|
292680
|
+
let collisionIndex = 1;
|
|
292681
|
+
while (fs36.existsSync(path30.join(chatsDir, filename))) {
|
|
292682
|
+
filename = `${SESSION_FILE_PREFIX}${timestamp2}-${collisionIndex++}-${shortId}.jsonl`;
|
|
292683
|
+
}
|
|
292638
292684
|
}
|
|
292639
292685
|
this.conversationFile = path30.join(chatsDir, filename);
|
|
292640
292686
|
const directories = this.kind === "subagent" ? [
|
|
@@ -336984,7 +337030,7 @@ function getVersion() {
|
|
|
336984
337030
|
}
|
|
336985
337031
|
versionPromise = (async () => {
|
|
336986
337032
|
const pkgJson = await getPackageJson(__dirname4);
|
|
336987
|
-
return "0.
|
|
337033
|
+
return "0.63.0-nightly.20260928.g2fe7c2d3f";
|
|
336988
337034
|
})();
|
|
336989
337035
|
return versionPromise;
|
|
336990
337036
|
}
|
|
@@ -344447,10 +344493,11 @@ function getSafeGitEnv(baseEnv = process.env) {
|
|
|
344447
344493
|
}
|
|
344448
344494
|
return {
|
|
344449
344495
|
...cleanedEnv,
|
|
344496
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
344450
344497
|
GIT_CONFIG_GLOBAL: devNullPath,
|
|
344451
344498
|
GIT_CONFIG_SYSTEM: devNullPath,
|
|
344452
344499
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
344453
|
-
GIT_CONFIG_COUNT: "
|
|
344500
|
+
GIT_CONFIG_COUNT: "7",
|
|
344454
344501
|
GIT_CONFIG_KEY_0: "credential.helper",
|
|
344455
344502
|
GIT_CONFIG_VALUE_0: "",
|
|
344456
344503
|
GIT_CONFIG_KEY_1: "core.fsmonitor",
|
|
@@ -344464,9 +344511,7 @@ function getSafeGitEnv(baseEnv = process.env) {
|
|
|
344464
344511
|
GIT_CONFIG_KEY_5: "core.editor",
|
|
344465
344512
|
GIT_CONFIG_VALUE_5: "",
|
|
344466
344513
|
GIT_CONFIG_KEY_6: "sequence.editor",
|
|
344467
|
-
GIT_CONFIG_VALUE_6: ""
|
|
344468
|
-
GIT_CONFIG_KEY_7: "diff.external",
|
|
344469
|
-
GIT_CONFIG_VALUE_7: ""
|
|
344514
|
+
GIT_CONFIG_VALUE_6: ""
|
|
344470
344515
|
};
|
|
344471
344516
|
}
|
|
344472
344517
|
function isGitRepository(directory) {
|
|
@@ -344773,7 +344818,14 @@ var init_read_file = __esm({
|
|
|
344773
344818
|
};
|
|
344774
344819
|
}
|
|
344775
344820
|
async execute(_options) {
|
|
344776
|
-
const
|
|
344821
|
+
const sanitizedPath = resolveDefensiveToolPath(this.params.file_path, this.config.getTargetDir());
|
|
344822
|
+
let targetPathToRead = this.resolvedPath;
|
|
344823
|
+
try {
|
|
344824
|
+
targetPathToRead = resolveToRealPath(path53.resolve(this.config.getTargetDir(), sanitizedPath));
|
|
344825
|
+
} catch {
|
|
344826
|
+
targetPathToRead = path53.resolve(this.config.getTargetDir(), sanitizedPath);
|
|
344827
|
+
}
|
|
344828
|
+
const validationError = this.config.validatePathAccess(targetPathToRead, "read");
|
|
344777
344829
|
if (validationError) {
|
|
344778
344830
|
return {
|
|
344779
344831
|
llmContent: validationError,
|
|
@@ -344784,7 +344836,7 @@ var init_read_file = __esm({
|
|
|
344784
344836
|
}
|
|
344785
344837
|
};
|
|
344786
344838
|
}
|
|
344787
|
-
const result2 = await processSingleFileContent(
|
|
344839
|
+
const result2 = await processSingleFileContent(targetPathToRead, this.config.getTargetDir(), this.config.getFileSystemService(), this.params.start_line, this.params.end_line);
|
|
344788
344840
|
if (result2.error) {
|
|
344789
344841
|
return {
|
|
344790
344842
|
llmContent: result2.llmContent,
|
|
@@ -344810,12 +344862,12 @@ ${result2.llmContent}`;
|
|
|
344810
344862
|
llmContent = result2.llmContent || "";
|
|
344811
344863
|
}
|
|
344812
344864
|
const lines = typeof result2.llmContent === "string" ? result2.llmContent.split("\n").length : void 0;
|
|
344813
|
-
const mimetype = getSpecificMimeType(
|
|
344865
|
+
const mimetype = getSpecificMimeType(targetPathToRead);
|
|
344814
344866
|
const programming_language = getProgrammingLanguage({
|
|
344815
|
-
file_path:
|
|
344867
|
+
file_path: targetPathToRead
|
|
344816
344868
|
});
|
|
344817
|
-
logFileOperation(this.config, new FileOperationEvent(READ_FILE_TOOL_NAME, FileOperation.READ, lines, mimetype, path53.extname(
|
|
344818
|
-
const jitContext = await discoverJitContext(this.config,
|
|
344869
|
+
logFileOperation(this.config, new FileOperationEvent(READ_FILE_TOOL_NAME, FileOperation.READ, lines, mimetype, path53.extname(targetPathToRead), programming_language));
|
|
344870
|
+
const jitContext = await discoverJitContext(this.config, targetPathToRead);
|
|
344819
344871
|
if (jitContext) {
|
|
344820
344872
|
if (typeof llmContent === "string") {
|
|
344821
344873
|
llmContent = appendJitContext(llmContent, jitContext);
|
|
@@ -344888,6 +344940,7 @@ var init_read_mcp_resource = __esm({
|
|
|
344888
344940
|
init_tool_names();
|
|
344889
344941
|
init_coreTools();
|
|
344890
344942
|
init_tool_error();
|
|
344943
|
+
init_textUtils();
|
|
344891
344944
|
ReadMcpResourceTool = class _ReadMcpResourceTool extends BaseDeclarativeTool {
|
|
344892
344945
|
context;
|
|
344893
344946
|
static Name = READ_MCP_RESOURCE_TOOL_NAME;
|
|
@@ -344975,7 +345028,7 @@ var init_read_mcp_resource = __esm({
|
|
|
344975
345028
|
}
|
|
344976
345029
|
}
|
|
344977
345030
|
return {
|
|
344978
|
-
llmContent: contentText
|
|
345031
|
+
llmContent: contentText ? wrapUntrusted(contentText) : "No content returned from resource.",
|
|
344979
345032
|
returnDisplay: this.resource ? `Successfully read resource "${this.resource.name}" from server "${this.resource.serverName}"` : `Successfully read resource: ${uri}`
|
|
344980
345033
|
};
|
|
344981
345034
|
} catch (e3) {
|
|
@@ -345003,6 +345056,7 @@ var init_list_mcp_resources = __esm({
|
|
|
345003
345056
|
init_tool_names();
|
|
345004
345057
|
init_coreTools();
|
|
345005
345058
|
init_tool_error();
|
|
345059
|
+
init_textUtils();
|
|
345006
345060
|
ListMcpResourcesTool = class _ListMcpResourcesTool extends BaseDeclarativeTool {
|
|
345007
345061
|
context;
|
|
345008
345062
|
static Name = LIST_MCP_RESOURCES_TOOL_NAME;
|
|
@@ -345059,7 +345113,7 @@ var init_list_mcp_resources = __esm({
|
|
|
345059
345113
|
content += "\n";
|
|
345060
345114
|
}
|
|
345061
345115
|
return {
|
|
345062
|
-
llmContent: content,
|
|
345116
|
+
llmContent: wrapUntrusted(content),
|
|
345063
345117
|
returnDisplay: `Listed ${resources.length} resources.`
|
|
345064
345118
|
};
|
|
345065
345119
|
}
|
|
@@ -358115,6 +358169,7 @@ import { spawn as cpSpawn } from "node:child_process";
|
|
|
358115
358169
|
import { TextDecoder as TextDecoder2 } from "node:util";
|
|
358116
358170
|
import os31 from "node:os";
|
|
358117
358171
|
import fs53, { mkdirSync as mkdirSync4 } from "node:fs";
|
|
358172
|
+
import fsPromises9 from "node:fs/promises";
|
|
358118
358173
|
import path60 from "node:path";
|
|
358119
358174
|
function ensurePromptvarsDisabled(command, shell) {
|
|
358120
358175
|
if (shell !== "bash") {
|
|
@@ -358273,6 +358328,7 @@ var init_shellExecutionService = __esm({
|
|
|
358273
358328
|
static activeChildProcesses = /* @__PURE__ */ new Map();
|
|
358274
358329
|
static backgroundLogPids = /* @__PURE__ */ new Set();
|
|
358275
358330
|
static backgroundLogStreams = /* @__PURE__ */ new Map();
|
|
358331
|
+
static backgroundTempDirs = /* @__PURE__ */ new Map();
|
|
358276
358332
|
static backgroundProcessHistory = /* @__PURE__ */ new Map();
|
|
358277
358333
|
static getLogDir() {
|
|
358278
358334
|
return path60.join(Storage2.getGlobalTempDir(), "background-processes");
|
|
@@ -358300,6 +358356,10 @@ ${truncated}`;
|
|
|
358300
358356
|
}
|
|
358301
358357
|
}
|
|
358302
358358
|
static async cleanupLogStream(pid) {
|
|
358359
|
+
const tempDir = this.backgroundTempDirs.get(pid);
|
|
358360
|
+
this.backgroundTempDirs.delete(pid);
|
|
358361
|
+
const rmPromise = tempDir ? fsPromises9.rm(tempDir, { recursive: true, force: true }).catch(() => {
|
|
358362
|
+
}) : Promise.resolve();
|
|
358303
358363
|
const stream2 = this.backgroundLogStreams.get(pid);
|
|
358304
358364
|
if (stream2) {
|
|
358305
358365
|
await new Promise((resolve23) => {
|
|
@@ -358308,6 +358368,7 @@ ${truncated}`;
|
|
|
358308
358368
|
this.backgroundLogStreams.delete(pid);
|
|
358309
358369
|
}
|
|
358310
358370
|
this.backgroundLogPids.delete(pid);
|
|
358371
|
+
await rmPromise;
|
|
358311
358372
|
}
|
|
358312
358373
|
/**
|
|
358313
358374
|
* Executes a shell command using `node-pty`, capturing all output and lifecycle events.
|
|
@@ -358400,8 +358461,7 @@ ${truncated}`;
|
|
|
358400
358461
|
["core.sshCommand", ""],
|
|
358401
358462
|
["core.pager", "cat"],
|
|
358402
358463
|
["core.editor", ""],
|
|
358403
|
-
["sequence.editor", ""]
|
|
358404
|
-
["diff.external", ""]
|
|
358464
|
+
["sequence.editor", ""]
|
|
358405
358465
|
];
|
|
358406
358466
|
for (const [overrideKey, overrideVal] of defaultGitOverrides) {
|
|
358407
358467
|
const keyVar = `GIT_CONFIG_KEY_${gitConfigCount}`;
|
|
@@ -358479,6 +358539,33 @@ ${truncated}`;
|
|
|
358479
358539
|
}
|
|
358480
358540
|
}
|
|
358481
358541
|
}
|
|
358542
|
+
if (child.stdout) {
|
|
358543
|
+
child.stdout.removeAllListeners();
|
|
358544
|
+
try {
|
|
358545
|
+
child.stdout.destroy();
|
|
358546
|
+
} catch {
|
|
358547
|
+
}
|
|
358548
|
+
}
|
|
358549
|
+
if (child.stderr) {
|
|
358550
|
+
child.stderr.removeAllListeners();
|
|
358551
|
+
try {
|
|
358552
|
+
child.stderr.destroy();
|
|
358553
|
+
} catch {
|
|
358554
|
+
}
|
|
358555
|
+
}
|
|
358556
|
+
const stdin = child.stdin;
|
|
358557
|
+
if (stdin) {
|
|
358558
|
+
stdin.removeAllListeners();
|
|
358559
|
+
try {
|
|
358560
|
+
stdin.destroy();
|
|
358561
|
+
} catch {
|
|
358562
|
+
}
|
|
358563
|
+
}
|
|
358564
|
+
child.removeAllListeners("error");
|
|
358565
|
+
child.removeAllListeners("close");
|
|
358566
|
+
state.sniffChunks.length = 0;
|
|
358567
|
+
stdoutDecoder = null;
|
|
358568
|
+
stderrDecoder = null;
|
|
358482
358569
|
return;
|
|
358483
358570
|
};
|
|
358484
358571
|
var cleanup = cleanup2;
|
|
@@ -358506,7 +358593,8 @@ ${truncated}`;
|
|
|
358506
358593
|
process: child,
|
|
358507
358594
|
state,
|
|
358508
358595
|
command: shellExecutionConfig.originalCommand ?? commandToExecute,
|
|
358509
|
-
sessionId: shellExecutionConfig.sessionId
|
|
358596
|
+
sessionId: shellExecutionConfig.sessionId,
|
|
358597
|
+
tempDir: shellExecutionConfig.tempDir
|
|
358510
358598
|
});
|
|
358511
358599
|
}
|
|
358512
358600
|
const lifecycleHandle = child.pid ? ExecutionLifecycleService.attachExecution(child.pid, {
|
|
@@ -358610,6 +358698,7 @@ ${truncated}`;
|
|
|
358610
358698
|
cleanup2();
|
|
358611
358699
|
cmdCleanup?.();
|
|
358612
358700
|
let combinedOutput = state.output;
|
|
358701
|
+
state.output = "";
|
|
358613
358702
|
if (state.truncated) {
|
|
358614
358703
|
const truncationMessage = `
|
|
358615
358704
|
[GEMINI_CLI_WARNING: Output truncated. The buffer is limited to ${MAX_CHILD_PROCESS_BUFFER_SIZE / (1024 * 1024)}MB.]`;
|
|
@@ -358645,9 +358734,8 @@ ${truncated}`;
|
|
|
358645
358734
|
historyItem.endTime = Date.now();
|
|
358646
358735
|
}
|
|
358647
358736
|
onOutputEvent(event);
|
|
358648
|
-
_ShellExecutionService.
|
|
358649
|
-
|
|
358650
|
-
});
|
|
358737
|
+
_ShellExecutionService.activeChildProcesses.delete(pid);
|
|
358738
|
+
_ShellExecutionService.cleanupLogStream(pid);
|
|
358651
358739
|
ExecutionLifecycleService.completeWithResult(pid, resultPayload);
|
|
358652
358740
|
} else {
|
|
358653
358741
|
resolveWithoutPid?.(resultPayload);
|
|
@@ -358857,7 +358945,8 @@ ${truncated}`;
|
|
|
358857
358945
|
maxSerializedLines: shellExecutionConfig.maxSerializedLines,
|
|
358858
358946
|
command: shellExecutionConfig.originalCommand ?? commandToExecute,
|
|
358859
358947
|
sessionId: shellExecutionConfig.sessionId,
|
|
358860
|
-
cancelRender
|
|
358948
|
+
cancelRender,
|
|
358949
|
+
tempDir: shellExecutionConfig.tempDir
|
|
358861
358950
|
});
|
|
358862
358951
|
const result2 = ExecutionLifecycleService.attachExecution(assignedPid, {
|
|
358863
358952
|
executionMethod: ptyInfo?.name ?? "node-pty",
|
|
@@ -359274,18 +359363,32 @@ ${truncated}`;
|
|
|
359274
359363
|
* This resolves the execution promise but keeps the PTY active.
|
|
359275
359364
|
*
|
|
359276
359365
|
* @param pid The process ID of the target PTY.
|
|
359366
|
+
* @param sessionId Optional session ID for process history tracking.
|
|
359367
|
+
* @param command Optional command string for display.
|
|
359368
|
+
* @param tempDir Optional temporary directory path owned by this execution to clean up on exit.
|
|
359277
359369
|
*/
|
|
359278
|
-
static background(pid, sessionId, command) {
|
|
359279
|
-
if (this.backgroundLogPids.has(pid)) {
|
|
359280
|
-
return;
|
|
359281
|
-
}
|
|
359370
|
+
static background(pid, sessionId, command, tempDir) {
|
|
359282
359371
|
const activePty = this.activePtys.get(pid);
|
|
359283
359372
|
const activeChild = this.activeChildProcesses.get(pid);
|
|
359373
|
+
const resolvedTempDir = tempDir ?? activePty?.tempDir ?? activeChild?.tempDir;
|
|
359284
359374
|
const resolvedSessionId = sessionId ?? activePty?.sessionId ?? activeChild?.sessionId;
|
|
359285
359375
|
const resolvedCommand = command ?? activePty?.command ?? activeChild?.command ?? "unknown command";
|
|
359286
359376
|
if (!resolvedSessionId) {
|
|
359287
359377
|
throw new Error("Session ID is required for background operations");
|
|
359288
359378
|
}
|
|
359379
|
+
if (!activePty && !activeChild) {
|
|
359380
|
+
if (resolvedTempDir) {
|
|
359381
|
+
fsPromises9.rm(resolvedTempDir, { recursive: true, force: true }).catch(() => {
|
|
359382
|
+
});
|
|
359383
|
+
}
|
|
359384
|
+
return;
|
|
359385
|
+
}
|
|
359386
|
+
if (resolvedTempDir) {
|
|
359387
|
+
this.backgroundTempDirs.set(pid, resolvedTempDir);
|
|
359388
|
+
}
|
|
359389
|
+
if (this.backgroundLogPids.has(pid)) {
|
|
359390
|
+
return;
|
|
359391
|
+
}
|
|
359289
359392
|
const MAX_BACKGROUND_PROCESS_HISTORY_SIZE = 100;
|
|
359290
359393
|
const history = this.backgroundProcessHistory.get(resolvedSessionId) ?? /* @__PURE__ */ new Map();
|
|
359291
359394
|
if (history.size >= MAX_BACKGROUND_PROCESS_HISTORY_SIZE) {
|
|
@@ -359297,7 +359400,8 @@ ${truncated}`;
|
|
|
359297
359400
|
history.set(pid, {
|
|
359298
359401
|
command: resolvedCommand,
|
|
359299
359402
|
status: "running",
|
|
359300
|
-
startTime: Date.now()
|
|
359403
|
+
startTime: Date.now(),
|
|
359404
|
+
...resolvedTempDir ? { tempDir: resolvedTempDir } : {}
|
|
359301
359405
|
});
|
|
359302
359406
|
this.backgroundProcessHistory.set(resolvedSessionId, history);
|
|
359303
359407
|
const logPath = this.getLogFilePath(pid);
|
|
@@ -359437,8 +359541,15 @@ ${truncated}`;
|
|
|
359437
359541
|
} catch {
|
|
359438
359542
|
}
|
|
359439
359543
|
}
|
|
359544
|
+
for (const tempDir of this.backgroundTempDirs.values()) {
|
|
359545
|
+
try {
|
|
359546
|
+
fs53.rmSync(tempDir, { recursive: true, force: true });
|
|
359547
|
+
} catch {
|
|
359548
|
+
}
|
|
359549
|
+
}
|
|
359440
359550
|
this.backgroundLogPids.clear();
|
|
359441
359551
|
this.backgroundLogStreams.clear();
|
|
359552
|
+
this.backgroundTempDirs.clear();
|
|
359442
359553
|
this.backgroundProcessHistory.clear();
|
|
359443
359554
|
}
|
|
359444
359555
|
};
|
|
@@ -359583,7 +359694,7 @@ var init_proactivePermissions = __esm({
|
|
|
359583
359694
|
});
|
|
359584
359695
|
|
|
359585
359696
|
// packages/core/dist/src/tools/shell.js
|
|
359586
|
-
import
|
|
359697
|
+
import fsPromises10 from "node:fs/promises";
|
|
359587
359698
|
import fs55 from "node:fs";
|
|
359588
359699
|
import path62 from "node:path";
|
|
359589
359700
|
import os33 from "node:os";
|
|
@@ -359766,15 +359877,19 @@ exit $__code`;
|
|
|
359766
359877
|
getExplanation() {
|
|
359767
359878
|
return this.getContextualDetails().trim();
|
|
359768
359879
|
}
|
|
359880
|
+
hasTaintedOrBuildFileRisk() {
|
|
359881
|
+
const command = stripShellWrapper(this.params.command);
|
|
359882
|
+
const history = this.getHistory();
|
|
359883
|
+
const untrustedContext = extractUntrustedContext(history);
|
|
359884
|
+
const untrustedFlags = findUntrustedFlags(command, untrustedContext);
|
|
359885
|
+
const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
|
|
359886
|
+
const isBuildCmd = isBuildOrTestCommand(command);
|
|
359887
|
+
return untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0;
|
|
359888
|
+
}
|
|
359769
359889
|
getPolicyUpdateOptions(outcome) {
|
|
359770
359890
|
if (outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave || outcome === ToolConfirmationOutcome.ProceedAlways) {
|
|
359771
359891
|
const command = stripShellWrapper(this.params.command);
|
|
359772
|
-
|
|
359773
|
-
const untrustedContext = extractUntrustedContext(history);
|
|
359774
|
-
const untrustedFlags = findUntrustedFlags(command, untrustedContext);
|
|
359775
|
-
const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
|
|
359776
|
-
const isBuildCmd = isBuildOrTestCommand(command);
|
|
359777
|
-
if (untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0) {
|
|
359892
|
+
if (this.hasTaintedOrBuildFileRisk()) {
|
|
359778
359893
|
return void 0;
|
|
359779
359894
|
}
|
|
359780
359895
|
const rootCommands = [...new Set(getCommandRoots(command))];
|
|
@@ -359790,24 +359905,18 @@ exit $__code`;
|
|
|
359790
359905
|
if (forcedDecision === "deny") {
|
|
359791
359906
|
return super.shouldConfirmExecute(abortSignal, forcedDecision);
|
|
359792
359907
|
}
|
|
359793
|
-
|
|
359794
|
-
const history = this.getHistory();
|
|
359795
|
-
const untrustedContext = extractUntrustedContext(history);
|
|
359796
|
-
const untrustedFlags = findUntrustedFlags(command, untrustedContext);
|
|
359797
|
-
const modifiedBuildFiles = getModifiedBuildFiles(this.context.config);
|
|
359798
|
-
const isBuildCmd = isBuildOrTestCommand(command);
|
|
359799
|
-
if (untrustedFlags.length > 0 || isBuildCmd && modifiedBuildFiles.length > 0) {
|
|
359908
|
+
if (this.hasTaintedOrBuildFileRisk()) {
|
|
359800
359909
|
return this.getConfirmationDetails(abortSignal);
|
|
359801
359910
|
}
|
|
359802
|
-
if (this.context.config.getApprovalMode() === ApprovalMode.YOLO) {
|
|
359911
|
+
if (this.context.config.getApprovalMode() === ApprovalMode.YOLO && forcedDecision !== "ask_user") {
|
|
359803
359912
|
return super.shouldConfirmExecute(abortSignal, forcedDecision);
|
|
359804
359913
|
}
|
|
359805
359914
|
if (this.params[PARAM_ADDITIONAL_PERMISSIONS]) {
|
|
359806
359915
|
return this.getConfirmationDetails(abortSignal);
|
|
359807
359916
|
}
|
|
359808
359917
|
if (this.context.config.getSandboxEnabled()) {
|
|
359809
|
-
const
|
|
359810
|
-
const rootCommands = getCommandRoots(
|
|
359918
|
+
const command = stripShellWrapper(this.params.command);
|
|
359919
|
+
const rootCommands = getCommandRoots(command);
|
|
359811
359920
|
const rawRootCommand = rootCommands[0];
|
|
359812
359921
|
if (rawRootCommand) {
|
|
359813
359922
|
const rootCommand = normalizeCommand(rawRootCommand);
|
|
@@ -359818,7 +359927,7 @@ exit $__code`;
|
|
|
359818
359927
|
const approved = this.context.config.sandboxPolicyManager.getCommandPermissions(rootCommand);
|
|
359819
359928
|
const hasNetwork = modeConfig.network || approved.network;
|
|
359820
359929
|
const missingNetwork = !!proactive.network && !hasNetwork;
|
|
359821
|
-
const parsed = parseCommandDetails(
|
|
359930
|
+
const parsed = parseCommandDetails(command);
|
|
359822
359931
|
const subCommand = parsed?.details[0]?.args?.[0];
|
|
359823
359932
|
const needsNetwork = isNetworkReliantCommand(rootCommand, subCommand);
|
|
359824
359933
|
if (needsNetwork) {
|
|
@@ -359938,6 +360047,7 @@ exit $__code`;
|
|
|
359938
360047
|
const isWindows2 = os33.platform() === "win32";
|
|
359939
360048
|
let tempFilePath = "";
|
|
359940
360049
|
let tempDir = "";
|
|
360050
|
+
let isBackgrounded = false;
|
|
359941
360051
|
const timeoutMs = this.context.config.getShellToolInactivityTimeout();
|
|
359942
360052
|
const timeoutController = new AbortController();
|
|
359943
360053
|
let timeoutTimer;
|
|
@@ -360080,7 +360190,8 @@ exit $__code`;
|
|
|
360080
360190
|
}
|
|
360081
360191
|
},
|
|
360082
360192
|
backgroundCompletionBehavior: this.context.config.getShellBackgroundCompletionBehavior(),
|
|
360083
|
-
originalCommand: strippedCommand
|
|
360193
|
+
originalCommand: strippedCommand,
|
|
360194
|
+
tempDir
|
|
360084
360195
|
});
|
|
360085
360196
|
if (pid) {
|
|
360086
360197
|
if (setExecutionIdCallback) {
|
|
@@ -360093,7 +360204,12 @@ exit $__code`;
|
|
|
360093
360204
|
let promotionTimer = setTimeout(() => {
|
|
360094
360205
|
promotionTimer = null;
|
|
360095
360206
|
if (!completed) {
|
|
360096
|
-
|
|
360207
|
+
try {
|
|
360208
|
+
ShellExecutionService.background(pid, sessionId, strippedCommand, tempDir);
|
|
360209
|
+
isBackgrounded = true;
|
|
360210
|
+
} catch (err2) {
|
|
360211
|
+
debugLogger.error("Failed to background shell execution:", err2);
|
|
360212
|
+
}
|
|
360097
360213
|
}
|
|
360098
360214
|
}, delay3);
|
|
360099
360215
|
const clearPromotionTimer = () => {
|
|
@@ -360130,20 +360246,22 @@ ${cumulativeOutput}`,
|
|
|
360130
360246
|
}
|
|
360131
360247
|
}
|
|
360132
360248
|
const result2 = await resultPromise;
|
|
360133
|
-
if (
|
|
360249
|
+
if (result2.backgrounded) {
|
|
360250
|
+
isBackgrounded = true;
|
|
360251
|
+
} else {
|
|
360134
360252
|
flushOutput();
|
|
360135
360253
|
}
|
|
360136
360254
|
const backgroundPIDs = [];
|
|
360137
360255
|
if (os33.platform() !== "win32") {
|
|
360138
360256
|
let tempFileExists = false;
|
|
360139
360257
|
try {
|
|
360140
|
-
await
|
|
360258
|
+
await fsPromises10.access(tempFilePath);
|
|
360141
360259
|
tempFileExists = true;
|
|
360142
360260
|
} catch {
|
|
360143
360261
|
tempFileExists = false;
|
|
360144
360262
|
}
|
|
360145
360263
|
if (tempFileExists) {
|
|
360146
|
-
const backgroundPIDContent = await
|
|
360264
|
+
const backgroundPIDContent = await fsPromises10.readFile(tempFilePath, "utf8");
|
|
360147
360265
|
const backgroundPIDLines = backgroundPIDContent.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
360148
360266
|
for (const line of backgroundPIDLines) {
|
|
360149
360267
|
if (!/^\d+$/.test(line)) {
|
|
@@ -360369,16 +360487,16 @@ ${result2.output}`;
|
|
|
360369
360487
|
}
|
|
360370
360488
|
signal.removeEventListener("abort", onAbort);
|
|
360371
360489
|
timeoutController.signal.removeEventListener("abort", onAbort);
|
|
360372
|
-
if (!
|
|
360490
|
+
if (!isBackgrounded) {
|
|
360373
360491
|
if (tempFilePath) {
|
|
360374
360492
|
try {
|
|
360375
|
-
await
|
|
360493
|
+
await fsPromises10.unlink(tempFilePath);
|
|
360376
360494
|
} catch {
|
|
360377
360495
|
}
|
|
360378
360496
|
}
|
|
360379
360497
|
if (tempDir) {
|
|
360380
360498
|
try {
|
|
360381
|
-
await
|
|
360499
|
+
await fsPromises10.rm(tempDir, { recursive: true, force: true });
|
|
360382
360500
|
} catch {
|
|
360383
360501
|
}
|
|
360384
360502
|
}
|
|
@@ -366601,6 +366719,7 @@ var init_web_search = __esm({
|
|
|
366601
366719
|
init_coreTools();
|
|
366602
366720
|
init_resolver();
|
|
366603
366721
|
init_llmRole();
|
|
366722
|
+
init_textUtils();
|
|
366604
366723
|
WebSearchToolInvocation = class extends BaseToolInvocation {
|
|
366605
366724
|
context;
|
|
366606
366725
|
constructor(context2, params, messageBus, _toolName, _toolDisplayName) {
|
|
@@ -366671,7 +366790,7 @@ var init_web_search = __esm({
|
|
|
366671
366790
|
return {
|
|
366672
366791
|
llmContent: `Web search results for "${this.params.query}":
|
|
366673
366792
|
|
|
366674
|
-
${modifiedResponseText}`,
|
|
366793
|
+
${wrapUntrusted(modifiedResponseText)}`,
|
|
366675
366794
|
returnDisplay: `Search results for "${this.params.query}" returned.`,
|
|
366676
366795
|
sources
|
|
366677
366796
|
};
|
|
@@ -371214,6 +371333,117 @@ var init_types13 = __esm({
|
|
|
371214
371333
|
});
|
|
371215
371334
|
|
|
371216
371335
|
// packages/core/dist/src/context/chatCompressionService.js
|
|
371336
|
+
function isExemptRetrievalTool(toolName, exemptTools = RETRIEVAL_TOOL_NAMES_EXEMPT_FROM_COLLAPSE) {
|
|
371337
|
+
if (!toolName) {
|
|
371338
|
+
return false;
|
|
371339
|
+
}
|
|
371340
|
+
const normalized = toolName.toLowerCase();
|
|
371341
|
+
if (exemptTools.has(normalized)) {
|
|
371342
|
+
return true;
|
|
371343
|
+
}
|
|
371344
|
+
return normalized.endsWith("read_file") || normalized.endsWith("read_files") || normalized.endsWith("read_many_files") || normalized.endsWith("read_resource");
|
|
371345
|
+
}
|
|
371346
|
+
function collapseOlderFunctionResponses(history, maxBytesPerOldResponse = COLLAPSED_FUNCTION_RESPONSE_MAX_BYTES, segmenter2 = defaultGraphemeSegmenter, protectedTurns = RECENT_TURNS_PROTECTED, exemptTools = RETRIEVAL_TOOL_NAMES_EXEMPT_FROM_COLLAPSE) {
|
|
371347
|
+
const toolIndices = [];
|
|
371348
|
+
for (let i3 = 0; i3 < history.length; i3++) {
|
|
371349
|
+
if (history[i3].role === "user" && history[i3].parts?.some((p2) => !!p2.functionResponse)) {
|
|
371350
|
+
toolIndices.push(i3);
|
|
371351
|
+
}
|
|
371352
|
+
}
|
|
371353
|
+
if (toolIndices.length <= protectedTurns) {
|
|
371354
|
+
return history;
|
|
371355
|
+
}
|
|
371356
|
+
const cutoffToolIndex = toolIndices[toolIndices.length - protectedTurns];
|
|
371357
|
+
const collapseString = (str2) => {
|
|
371358
|
+
const totalBytes = Buffer.byteLength(str2, "utf8");
|
|
371359
|
+
if (totalBytes <= maxBytesPerOldResponse) {
|
|
371360
|
+
return str2;
|
|
371361
|
+
}
|
|
371362
|
+
const previewBytes = maxBytesPerOldResponse;
|
|
371363
|
+
let preview = "";
|
|
371364
|
+
let currentBytes = 0;
|
|
371365
|
+
for (const { segment } of segmenter2.segment(str2)) {
|
|
371366
|
+
const segmentBytes = Buffer.byteLength(segment, "utf8");
|
|
371367
|
+
if (currentBytes + segmentBytes > previewBytes) {
|
|
371368
|
+
break;
|
|
371369
|
+
}
|
|
371370
|
+
preview += segment;
|
|
371371
|
+
currentBytes += segmentBytes;
|
|
371372
|
+
}
|
|
371373
|
+
const omittedBytes = totalBytes - currentBytes;
|
|
371374
|
+
return `${preview}
|
|
371375
|
+
... [Tool output collapsed from previous turn: ${omittedBytes} bytes omitted to conserve memory] ...`;
|
|
371376
|
+
};
|
|
371377
|
+
const collapseValue = (val) => {
|
|
371378
|
+
if (typeof val === "string") {
|
|
371379
|
+
return collapseString(val);
|
|
371380
|
+
}
|
|
371381
|
+
if (Array.isArray(val)) {
|
|
371382
|
+
let arrayModified = false;
|
|
371383
|
+
const newVal = val.map((item) => {
|
|
371384
|
+
const collapsed = collapseValue(item);
|
|
371385
|
+
if (collapsed !== item) {
|
|
371386
|
+
arrayModified = true;
|
|
371387
|
+
}
|
|
371388
|
+
return collapsed;
|
|
371389
|
+
});
|
|
371390
|
+
return arrayModified ? newVal : val;
|
|
371391
|
+
}
|
|
371392
|
+
if (typeof val === "object" && val !== null) {
|
|
371393
|
+
const proto = Object.getPrototypeOf(val);
|
|
371394
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
371395
|
+
return val;
|
|
371396
|
+
}
|
|
371397
|
+
let objModified = false;
|
|
371398
|
+
const copy = {};
|
|
371399
|
+
for (const [k2, v2] of Object.entries(val)) {
|
|
371400
|
+
const collapsed = collapseValue(v2);
|
|
371401
|
+
if (collapsed !== v2) {
|
|
371402
|
+
objModified = true;
|
|
371403
|
+
}
|
|
371404
|
+
copy[k2] = collapsed;
|
|
371405
|
+
}
|
|
371406
|
+
return objModified ? copy : val;
|
|
371407
|
+
}
|
|
371408
|
+
return val;
|
|
371409
|
+
};
|
|
371410
|
+
let modified = false;
|
|
371411
|
+
const newHistory = history.map((content, idx) => {
|
|
371412
|
+
if (idx >= cutoffToolIndex || content.role !== "user" || !content.parts) {
|
|
371413
|
+
return content;
|
|
371414
|
+
}
|
|
371415
|
+
let partsModified = false;
|
|
371416
|
+
const newParts = content.parts.map((part) => {
|
|
371417
|
+
if (!part.functionResponse?.response) {
|
|
371418
|
+
return part;
|
|
371419
|
+
}
|
|
371420
|
+
if (isExemptRetrievalTool(part.functionResponse.name, exemptTools)) {
|
|
371421
|
+
return part;
|
|
371422
|
+
}
|
|
371423
|
+
const resp = part.functionResponse.response;
|
|
371424
|
+
const newResp = collapseValue(resp);
|
|
371425
|
+
if (newResp !== resp) {
|
|
371426
|
+
partsModified = true;
|
|
371427
|
+
return {
|
|
371428
|
+
...part,
|
|
371429
|
+
functionResponse: {
|
|
371430
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
371431
|
+
...part.functionResponse,
|
|
371432
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
371433
|
+
response: newResp
|
|
371434
|
+
}
|
|
371435
|
+
};
|
|
371436
|
+
}
|
|
371437
|
+
return part;
|
|
371438
|
+
});
|
|
371439
|
+
if (partsModified) {
|
|
371440
|
+
modified = true;
|
|
371441
|
+
return { ...content, parts: newParts };
|
|
371442
|
+
}
|
|
371443
|
+
return content;
|
|
371444
|
+
});
|
|
371445
|
+
return modified ? newHistory : history;
|
|
371446
|
+
}
|
|
371217
371447
|
function findCompressSplitPoint(contents, fraction) {
|
|
371218
371448
|
if (fraction <= 0 || fraction >= 1) {
|
|
371219
371449
|
throw new Error("Fraction must be between 0 and 1");
|
|
@@ -371325,7 +371555,7 @@ async function truncateHistoryToBudget(history, config2) {
|
|
|
371325
371555
|
}
|
|
371326
371556
|
return truncatedHistory;
|
|
371327
371557
|
}
|
|
371328
|
-
var DEFAULT_COMPRESSION_TOKEN_THRESHOLD, COMPRESSION_PRESERVE_THRESHOLD, COMPRESSION_FUNCTION_RESPONSE_TOKEN_BUDGET, ChatCompressionService;
|
|
371558
|
+
var DEFAULT_COMPRESSION_TOKEN_THRESHOLD, RECENT_TURNS_PROTECTED, RETRIEVAL_TOOL_NAMES_EXEMPT_FROM_COLLAPSE, COLLAPSED_FUNCTION_RESPONSE_MAX_BYTES, defaultGraphemeSegmenter, COMPRESSION_PRESERVE_THRESHOLD, COMPRESSION_FUNCTION_RESPONSE_TOKEN_BUDGET, ChatCompressionService;
|
|
371329
371559
|
var init_chatCompressionService = __esm({
|
|
371330
371560
|
"packages/core/dist/src/context/chatCompressionService.js"() {
|
|
371331
371561
|
"use strict";
|
|
@@ -371342,6 +371572,22 @@ var init_chatCompressionService = __esm({
|
|
|
371342
371572
|
init_models();
|
|
371343
371573
|
init_types13();
|
|
371344
371574
|
DEFAULT_COMPRESSION_TOKEN_THRESHOLD = 0.5;
|
|
371575
|
+
RECENT_TURNS_PROTECTED = 3;
|
|
371576
|
+
RETRIEVAL_TOOL_NAMES_EXEMPT_FROM_COLLAPSE = /* @__PURE__ */ new Set([
|
|
371577
|
+
"read_file",
|
|
371578
|
+
"read_many_files",
|
|
371579
|
+
"get_internal_docs",
|
|
371580
|
+
"read_mcp_resource",
|
|
371581
|
+
"grep",
|
|
371582
|
+
"rip_grep",
|
|
371583
|
+
"glob",
|
|
371584
|
+
"search_file_content",
|
|
371585
|
+
"find_files"
|
|
371586
|
+
]);
|
|
371587
|
+
COLLAPSED_FUNCTION_RESPONSE_MAX_BYTES = 2048;
|
|
371588
|
+
defaultGraphemeSegmenter = new Intl.Segmenter(void 0, {
|
|
371589
|
+
granularity: "grapheme"
|
|
371590
|
+
});
|
|
371345
371591
|
COMPRESSION_PRESERVE_THRESHOLD = 0.3;
|
|
371346
371592
|
COMPRESSION_FUNCTION_RESPONSE_TOKEN_BUDGET = 5e4;
|
|
371347
371593
|
ChatCompressionService = class {
|
|
@@ -371359,10 +371605,12 @@ var init_chatCompressionService = __esm({
|
|
|
371359
371605
|
}
|
|
371360
371606
|
const trigger = force ? PreCompressTrigger.Manual : PreCompressTrigger.Auto;
|
|
371361
371607
|
await config2.getHookSystem()?.firePreCompressEvent(trigger);
|
|
371362
|
-
const
|
|
371608
|
+
const lastPromptTokenCount = chat.getLastPromptTokenCount();
|
|
371609
|
+
const originalTokenCount = lastPromptTokenCount > 0 ? lastPromptTokenCount : estimateTokenCountSync(curatedHistory.flatMap((c2) => c2.parts || []));
|
|
371363
371610
|
if (!force) {
|
|
371364
371611
|
const threshold = await config2.getCompressionThreshold() ?? DEFAULT_COMPRESSION_TOKEN_THRESHOLD;
|
|
371365
|
-
|
|
371612
|
+
const isOverModelThreshold = originalTokenCount >= threshold * tokenLimit(model);
|
|
371613
|
+
if (!isOverModelThreshold) {
|
|
371366
371614
|
return {
|
|
371367
371615
|
newHistory: null,
|
|
371368
371616
|
info: {
|
|
@@ -371500,6 +371748,8 @@ First, reason in your scratchpad. Then, generate the updated <state_snapshot>.`
|
|
|
371500
371748
|
}
|
|
371501
371749
|
};
|
|
371502
371750
|
} else {
|
|
371751
|
+
historyToCompressTruncated.length = 0;
|
|
371752
|
+
originalHistoryToCompress.length = 0;
|
|
371503
371753
|
return {
|
|
371504
371754
|
newHistory: extraHistory,
|
|
371505
371755
|
info: {
|
|
@@ -371514,6 +371764,135 @@ First, reason in your scratchpad. Then, generate the updated <state_snapshot>.`
|
|
|
371514
371764
|
}
|
|
371515
371765
|
});
|
|
371516
371766
|
|
|
371767
|
+
// packages/core/dist/src/utils/tool-utils.js
|
|
371768
|
+
function isToolCallResponseInfo(data) {
|
|
371769
|
+
return typeof data === "object" && data !== null && "callId" in data && "responseParts" in data;
|
|
371770
|
+
}
|
|
371771
|
+
function getToolSuggestion(unknownToolName, allToolNames, topN = 3) {
|
|
371772
|
+
const matches = allToolNames.map((toolName) => ({
|
|
371773
|
+
name: toolName,
|
|
371774
|
+
distance: import_fast_levenshtein2.default.get(unknownToolName, toolName)
|
|
371775
|
+
}));
|
|
371776
|
+
matches.sort((a, b2) => a.distance - b2.distance);
|
|
371777
|
+
const topNResults = matches.slice(0, topN);
|
|
371778
|
+
if (topNResults.length === 0) {
|
|
371779
|
+
return "";
|
|
371780
|
+
}
|
|
371781
|
+
const suggestedNames = topNResults.map((match2) => `"${match2.name}"`).join(", ");
|
|
371782
|
+
if (topNResults.length > 1) {
|
|
371783
|
+
return ` Did you mean one of: ${suggestedNames}?`;
|
|
371784
|
+
} else {
|
|
371785
|
+
return ` Did you mean ${suggestedNames}?`;
|
|
371786
|
+
}
|
|
371787
|
+
}
|
|
371788
|
+
function truncateToolOutput(text, maxBytes = MAX_STORED_TOOL_OUTPUT_BYTES, savedFilePath) {
|
|
371789
|
+
if (Buffer.byteLength(text, "utf8") <= maxBytes) {
|
|
371790
|
+
return text;
|
|
371791
|
+
}
|
|
371792
|
+
const suffix = savedFilePath ? `
|
|
371793
|
+
... [Tool output truncated to conserve memory. For full output see: ${savedFilePath}]` : "\n... [Tool output truncated to conserve memory]";
|
|
371794
|
+
const targetBytes = Math.max(0, maxBytes - Buffer.byteLength(suffix, "utf8"));
|
|
371795
|
+
let accumulatedBytes = 0;
|
|
371796
|
+
let truncatedText = "";
|
|
371797
|
+
for (const { segment } of segmenter.segment(text)) {
|
|
371798
|
+
const segmentBytes = Buffer.byteLength(segment, "utf8");
|
|
371799
|
+
if (accumulatedBytes + segmentBytes > targetBytes) {
|
|
371800
|
+
break;
|
|
371801
|
+
}
|
|
371802
|
+
accumulatedBytes += segmentBytes;
|
|
371803
|
+
truncatedText += segment;
|
|
371804
|
+
}
|
|
371805
|
+
return truncatedText + suffix;
|
|
371806
|
+
}
|
|
371807
|
+
function truncateFunctionResponsePart(part, maxBytes = MAX_STORED_TOOL_OUTPUT_BYTES, savedFilePath) {
|
|
371808
|
+
if (part.text && Buffer.byteLength(part.text, "utf8") > maxBytes) {
|
|
371809
|
+
return {
|
|
371810
|
+
...part,
|
|
371811
|
+
text: truncateToolOutput(part.text, maxBytes, savedFilePath)
|
|
371812
|
+
};
|
|
371813
|
+
}
|
|
371814
|
+
if (!part.functionResponse?.response) {
|
|
371815
|
+
return part;
|
|
371816
|
+
}
|
|
371817
|
+
const resp = part.functionResponse.response;
|
|
371818
|
+
if (typeof resp === "string") {
|
|
371819
|
+
if (Buffer.byteLength(resp, "utf8") > maxBytes) {
|
|
371820
|
+
return {
|
|
371821
|
+
...part,
|
|
371822
|
+
functionResponse: {
|
|
371823
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
371824
|
+
...part.functionResponse,
|
|
371825
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
371826
|
+
response: truncateToolOutput(resp, maxBytes, savedFilePath)
|
|
371827
|
+
}
|
|
371828
|
+
};
|
|
371829
|
+
}
|
|
371830
|
+
return part;
|
|
371831
|
+
}
|
|
371832
|
+
if (typeof resp === "object" && resp !== null) {
|
|
371833
|
+
const truncateValue = (val) => {
|
|
371834
|
+
if (typeof val === "string") {
|
|
371835
|
+
if (Buffer.byteLength(val, "utf8") > maxBytes) {
|
|
371836
|
+
return truncateToolOutput(val, maxBytes, savedFilePath);
|
|
371837
|
+
}
|
|
371838
|
+
return val;
|
|
371839
|
+
}
|
|
371840
|
+
if (Array.isArray(val)) {
|
|
371841
|
+
let arrayModified = false;
|
|
371842
|
+
const newVal = val.map((item) => {
|
|
371843
|
+
const truncated = truncateValue(item);
|
|
371844
|
+
if (truncated !== item) {
|
|
371845
|
+
arrayModified = true;
|
|
371846
|
+
}
|
|
371847
|
+
return truncated;
|
|
371848
|
+
});
|
|
371849
|
+
return arrayModified ? newVal : val;
|
|
371850
|
+
}
|
|
371851
|
+
if (typeof val === "object" && val !== null) {
|
|
371852
|
+
const proto = Object.getPrototypeOf(val);
|
|
371853
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
371854
|
+
return val;
|
|
371855
|
+
}
|
|
371856
|
+
let objModified = false;
|
|
371857
|
+
const copy = {};
|
|
371858
|
+
for (const [k2, v2] of Object.entries(val)) {
|
|
371859
|
+
const truncated = truncateValue(v2);
|
|
371860
|
+
if (truncated !== v2) {
|
|
371861
|
+
objModified = true;
|
|
371862
|
+
}
|
|
371863
|
+
copy[k2] = truncated;
|
|
371864
|
+
}
|
|
371865
|
+
return objModified ? copy : val;
|
|
371866
|
+
}
|
|
371867
|
+
return val;
|
|
371868
|
+
};
|
|
371869
|
+
const newResp = truncateValue(resp);
|
|
371870
|
+
if (newResp !== resp) {
|
|
371871
|
+
return {
|
|
371872
|
+
...part,
|
|
371873
|
+
functionResponse: {
|
|
371874
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
371875
|
+
...part.functionResponse,
|
|
371876
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
371877
|
+
response: newResp
|
|
371878
|
+
}
|
|
371879
|
+
};
|
|
371880
|
+
}
|
|
371881
|
+
}
|
|
371882
|
+
return part;
|
|
371883
|
+
}
|
|
371884
|
+
var import_fast_levenshtein2, segmenter;
|
|
371885
|
+
var init_tool_utils = __esm({
|
|
371886
|
+
"packages/core/dist/src/utils/tool-utils.js"() {
|
|
371887
|
+
"use strict";
|
|
371888
|
+
init_src3();
|
|
371889
|
+
init_shell_utils();
|
|
371890
|
+
import_fast_levenshtein2 = __toESM(require_levenshtein(), 1);
|
|
371891
|
+
init_constants();
|
|
371892
|
+
segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
371893
|
+
}
|
|
371894
|
+
});
|
|
371895
|
+
|
|
371517
371896
|
// packages/core/dist/src/agents/types.js
|
|
371518
371897
|
function isSubagentProgress(obj) {
|
|
371519
371898
|
return typeof obj === "object" && obj !== null && "isSubagentProgress" in obj && obj.isSubagentProgress === true;
|
|
@@ -381221,37 +381600,6 @@ var init_toolCallContext = __esm({
|
|
|
381221
381600
|
}
|
|
381222
381601
|
});
|
|
381223
381602
|
|
|
381224
|
-
// packages/core/dist/src/utils/tool-utils.js
|
|
381225
|
-
function isToolCallResponseInfo(data) {
|
|
381226
|
-
return typeof data === "object" && data !== null && "callId" in data && "responseParts" in data;
|
|
381227
|
-
}
|
|
381228
|
-
function getToolSuggestion(unknownToolName, allToolNames, topN = 3) {
|
|
381229
|
-
const matches = allToolNames.map((toolName) => ({
|
|
381230
|
-
name: toolName,
|
|
381231
|
-
distance: import_fast_levenshtein2.default.get(unknownToolName, toolName)
|
|
381232
|
-
}));
|
|
381233
|
-
matches.sort((a, b2) => a.distance - b2.distance);
|
|
381234
|
-
const topNResults = matches.slice(0, topN);
|
|
381235
|
-
if (topNResults.length === 0) {
|
|
381236
|
-
return "";
|
|
381237
|
-
}
|
|
381238
|
-
const suggestedNames = topNResults.map((match2) => `"${match2.name}"`).join(", ");
|
|
381239
|
-
if (topNResults.length > 1) {
|
|
381240
|
-
return ` Did you mean one of: ${suggestedNames}?`;
|
|
381241
|
-
} else {
|
|
381242
|
-
return ` Did you mean ${suggestedNames}?`;
|
|
381243
|
-
}
|
|
381244
|
-
}
|
|
381245
|
-
var import_fast_levenshtein2;
|
|
381246
|
-
var init_tool_utils = __esm({
|
|
381247
|
-
"packages/core/dist/src/utils/tool-utils.js"() {
|
|
381248
|
-
"use strict";
|
|
381249
|
-
init_src3();
|
|
381250
|
-
init_shell_utils();
|
|
381251
|
-
import_fast_levenshtein2 = __toESM(require_levenshtein(), 1);
|
|
381252
|
-
}
|
|
381253
|
-
});
|
|
381254
|
-
|
|
381255
381603
|
// packages/core/dist/src/scheduler/state-manager.js
|
|
381256
381604
|
var SchedulerStateManager;
|
|
381257
381605
|
var init_state_manager = __esm({
|
|
@@ -383049,7 +383397,7 @@ ${summary}
|
|
|
383049
383397
|
|
|
383050
383398
|
// packages/core/dist/src/context/toolOutputMaskingService.js
|
|
383051
383399
|
import path70 from "node:path";
|
|
383052
|
-
import * as
|
|
383400
|
+
import * as fsPromises11 from "node:fs/promises";
|
|
383053
383401
|
var DEFAULT_TOOL_PROTECTION_THRESHOLD, DEFAULT_MIN_PRUNABLE_TOKENS_THRESHOLD, DEFAULT_PROTECT_LATEST_TURN, MASKING_INDICATOR_TAG, TOOL_OUTPUTS_DIR3, EXEMPT_TOOLS, ToolOutputMaskingService;
|
|
383054
383402
|
var init_toolOutputMaskingService = __esm({
|
|
383055
383403
|
"packages/core/dist/src/context/toolOutputMaskingService.js"() {
|
|
@@ -383136,7 +383484,7 @@ var init_toolOutputMaskingService = __esm({
|
|
|
383136
383484
|
const safeSessionId = sanitizeFilenamePart(sessionId);
|
|
383137
383485
|
toolOutputsDir = path70.join(toolOutputsDir, `session-${safeSessionId}`);
|
|
383138
383486
|
}
|
|
383139
|
-
await
|
|
383487
|
+
await fsPromises11.mkdir(toolOutputsDir, { recursive: true });
|
|
383140
383488
|
for (const item of prunableParts) {
|
|
383141
383489
|
const { contentIndex, partIndex, content, tokens } = item;
|
|
383142
383490
|
const contentRecord = newHistory[contentIndex];
|
|
@@ -383149,7 +383497,7 @@ var init_toolOutputMaskingService = __esm({
|
|
|
383149
383497
|
const safeCallId = sanitizeFilenamePart(callId).toLowerCase();
|
|
383150
383498
|
const fileName = `${safeToolName}_${safeCallId}_${Math.random().toString(36).substring(7)}.txt`;
|
|
383151
383499
|
const filePath = path70.join(toolOutputsDir, fileName);
|
|
383152
|
-
await
|
|
383500
|
+
await fsPromises11.writeFile(filePath, content, "utf-8");
|
|
383153
383501
|
const originalResponse = (
|
|
383154
383502
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
383155
383503
|
part.functionResponse.response || {}
|
|
@@ -386692,6 +387040,15 @@ var init_client3 = __esm({
|
|
|
386692
387040
|
coreEvents.off(CoreEvent.ApprovalModeChanged, this.handleApprovalModeChanged);
|
|
386693
387041
|
}
|
|
386694
387042
|
async resumeChat(history, resumedSessionData) {
|
|
387043
|
+
if (resumedSessionData?.filePath) {
|
|
387044
|
+
const previousRecordingService = this.chat?.getChatRecordingService?.();
|
|
387045
|
+
if (previousRecordingService && previousRecordingService.getConversationFilePath?.() !== resumedSessionData.filePath) {
|
|
387046
|
+
try {
|
|
387047
|
+
await previousRecordingService.deleteCurrentSessionIfNotResumableAsync?.();
|
|
387048
|
+
} catch {
|
|
387049
|
+
}
|
|
387050
|
+
}
|
|
387051
|
+
}
|
|
386695
387052
|
this.chat = await this.startChat(history, resumedSessionData);
|
|
386696
387053
|
this.updateTelemetryTokenCount();
|
|
386697
387054
|
}
|
|
@@ -387462,6 +387819,8 @@ var init_tool_executor = __esm({
|
|
|
387462
387819
|
init_coreToolHookTriggers();
|
|
387463
387820
|
init_fileUtils();
|
|
387464
387821
|
init_generateContentResponseUtilities();
|
|
387822
|
+
init_tool_utils();
|
|
387823
|
+
init_constants();
|
|
387465
387824
|
init_types3();
|
|
387466
387825
|
init_constants2();
|
|
387467
387826
|
ToolExecutor = class {
|
|
@@ -387563,13 +387922,16 @@ var init_tool_executor = __esm({
|
|
|
387563
387922
|
const originalContentLength = content.length;
|
|
387564
387923
|
const { outputFile: savedPath } = await saveTruncatedToolOutput(content, toolName, callId, this.config.storage.getProjectTempDir(), this.context.promptId);
|
|
387565
387924
|
outputFile = savedPath;
|
|
387566
|
-
|
|
387925
|
+
let truncatedContent = formatTruncatedToolOutput(content, outputFile, threshold);
|
|
387567
387926
|
logToolOutputTruncated(this.config, new ToolOutputTruncatedEvent(call.request.prompt_id, {
|
|
387568
387927
|
toolName,
|
|
387569
387928
|
originalContentLength,
|
|
387570
387929
|
truncatedContentLength: truncatedContent.length,
|
|
387571
387930
|
threshold
|
|
387572
387931
|
}));
|
|
387932
|
+
if (typeof truncatedContent === "string" && Buffer.byteLength(truncatedContent, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387933
|
+
truncatedContent = truncateToolOutput(truncatedContent, MAX_STORED_TOOL_OUTPUT_BYTES);
|
|
387934
|
+
}
|
|
387573
387935
|
return { truncatedContent, outputFile };
|
|
387574
387936
|
}
|
|
387575
387937
|
} else if (Array.isArray(content) && content.length === 1 && "tool" in call && call.tool instanceof DiscoveredMCPTool) {
|
|
@@ -387581,7 +387943,10 @@ var init_tool_executor = __esm({
|
|
|
387581
387943
|
const originalContentLength = textContent2.length;
|
|
387582
387944
|
const { outputFile: savedPath } = await saveTruncatedToolOutput(textContent2, toolName, callId, this.config.storage.getProjectTempDir(), this.context.promptId);
|
|
387583
387945
|
outputFile = savedPath;
|
|
387584
|
-
|
|
387946
|
+
let truncatedText = formatTruncatedToolOutput(textContent2, outputFile, threshold);
|
|
387947
|
+
if (typeof truncatedText === "string" && Buffer.byteLength(truncatedText, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387948
|
+
truncatedText = truncateToolOutput(truncatedText, MAX_STORED_TOOL_OUTPUT_BYTES);
|
|
387949
|
+
}
|
|
387585
387950
|
const truncatedContent = [
|
|
387586
387951
|
{ ...firstPart, text: truncatedText }
|
|
387587
387952
|
];
|
|
@@ -387595,7 +387960,45 @@ var init_tool_executor = __esm({
|
|
|
387595
387960
|
}
|
|
387596
387961
|
}
|
|
387597
387962
|
}
|
|
387598
|
-
|
|
387963
|
+
const ensureOutputFile = async (rawText) => {
|
|
387964
|
+
if (!outputFile) {
|
|
387965
|
+
try {
|
|
387966
|
+
const { outputFile: savedPath } = await saveTruncatedToolOutput(rawText, toolName, callId, this.config.storage.getProjectTempDir(), this.context.promptId);
|
|
387967
|
+
outputFile = savedPath;
|
|
387968
|
+
} catch {
|
|
387969
|
+
}
|
|
387970
|
+
}
|
|
387971
|
+
return outputFile;
|
|
387972
|
+
};
|
|
387973
|
+
let finalContent = content;
|
|
387974
|
+
if (typeof finalContent === "string") {
|
|
387975
|
+
if (Buffer.byteLength(finalContent, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387976
|
+
const savedPath = await ensureOutputFile(finalContent);
|
|
387977
|
+
finalContent = truncateToolOutput(finalContent, MAX_STORED_TOOL_OUTPUT_BYTES, savedPath);
|
|
387978
|
+
}
|
|
387979
|
+
} else if (Array.isArray(finalContent)) {
|
|
387980
|
+
finalContent = await Promise.all(finalContent.map(async (part) => {
|
|
387981
|
+
if (typeof part === "string" && Buffer.byteLength(part, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387982
|
+
const savedPath = await ensureOutputFile(part);
|
|
387983
|
+
return truncateToolOutput(part, MAX_STORED_TOOL_OUTPUT_BYTES, savedPath);
|
|
387984
|
+
}
|
|
387985
|
+
if (typeof part === "object" && part !== null && "text" in part && typeof part.text === "string" && Buffer.byteLength(part.text, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387986
|
+
const savedPath = await ensureOutputFile(part.text);
|
|
387987
|
+
return {
|
|
387988
|
+
...part,
|
|
387989
|
+
text: truncateToolOutput(part.text, MAX_STORED_TOOL_OUTPUT_BYTES, savedPath)
|
|
387990
|
+
};
|
|
387991
|
+
}
|
|
387992
|
+
return part;
|
|
387993
|
+
}));
|
|
387994
|
+
} else if (typeof finalContent === "object" && finalContent !== null && "text" in finalContent && typeof finalContent.text === "string" && Buffer.byteLength(finalContent.text, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
387995
|
+
const savedPath = await ensureOutputFile(finalContent.text);
|
|
387996
|
+
finalContent = {
|
|
387997
|
+
...finalContent,
|
|
387998
|
+
text: truncateToolOutput(finalContent.text, MAX_STORED_TOOL_OUTPUT_BYTES, savedPath)
|
|
387999
|
+
};
|
|
388000
|
+
}
|
|
388001
|
+
return { truncatedContent: finalContent, outputFile };
|
|
387599
388002
|
}
|
|
387600
388003
|
async createCancelledResult(call, reason, toolResult) {
|
|
387601
388004
|
const errorMessage = `[Operation Cancelled] ${reason}`;
|
|
@@ -387774,6 +388177,9 @@ var init_tool_modifier = __esm({
|
|
|
387774
388177
|
});
|
|
387775
388178
|
|
|
387776
388179
|
// packages/core/dist/src/scheduler/scheduler.js
|
|
388180
|
+
function isTaintRiskDetectable(invocation) {
|
|
388181
|
+
return typeof invocation === "object" && invocation !== null && "hasTaintedOrBuildFileRisk" in invocation && typeof invocation.hasTaintedOrBuildFileRisk === "function";
|
|
388182
|
+
}
|
|
387777
388183
|
var createErrorResponse, Scheduler;
|
|
387778
388184
|
var init_scheduler = __esm({
|
|
387779
388185
|
"packages/core/dist/src/scheduler/scheduler.js"() {
|
|
@@ -388157,6 +388563,10 @@ var init_scheduler = __esm({
|
|
|
388157
388563
|
if (hookDecision === "ask") {
|
|
388158
388564
|
decision = PolicyDecision.ASK_USER;
|
|
388159
388565
|
}
|
|
388566
|
+
const hasTaintRisk = isTaintRiskDetectable(toolCall.invocation) && toolCall.invocation.hasTaintedOrBuildFileRisk();
|
|
388567
|
+
if (decision === PolicyDecision.ALLOW && hasTaintRisk) {
|
|
388568
|
+
decision = this.config.isInteractive?.() ?? true ? PolicyDecision.ASK_USER : PolicyDecision.DENY;
|
|
388569
|
+
}
|
|
388160
388570
|
if (decision === PolicyDecision.DENY) {
|
|
388161
388571
|
const { errorMessage, errorType } = getPolicyDenialError(this.config, rule);
|
|
388162
388572
|
this.state.updateStatus(callId, CoreToolCallStatus.Error, createErrorResponse(toolCall.request, new Error(errorMessage), errorType));
|
|
@@ -388165,6 +388575,7 @@ var init_scheduler = __esm({
|
|
|
388165
388575
|
let outcome = ToolConfirmationOutcome.ProceedOnce;
|
|
388166
388576
|
let lastDetails;
|
|
388167
388577
|
if (decision === PolicyDecision.ASK_USER) {
|
|
388578
|
+
const forcedDecision = hookDecision === "ask" || policyDecision === PolicyDecision.ALLOW && hasTaintRisk ? "ask_user" : void 0;
|
|
388168
388579
|
const result2 = await resolveConfirmation(toolCall, signal, {
|
|
388169
388580
|
config: this.config,
|
|
388170
388581
|
messageBus: this.messageBus,
|
|
@@ -388174,7 +388585,7 @@ var init_scheduler = __esm({
|
|
|
388174
388585
|
schedulerId: this.schedulerId,
|
|
388175
388586
|
onWaitingForConfirmation: this.onWaitingForConfirmation,
|
|
388176
388587
|
systemMessage: hookSystemMessage,
|
|
388177
|
-
forcedDecision
|
|
388588
|
+
forcedDecision
|
|
388178
388589
|
});
|
|
388179
388590
|
outcome = result2.outcome;
|
|
388180
388591
|
lastDetails = result2.lastDetails;
|
|
@@ -389046,6 +389457,8 @@ var init_local_executor = __esm({
|
|
|
389046
389457
|
init_turn();
|
|
389047
389458
|
init_types3();
|
|
389048
389459
|
init_chatCompressionService();
|
|
389460
|
+
init_constants();
|
|
389461
|
+
init_tool_utils();
|
|
389049
389462
|
init_environmentContext();
|
|
389050
389463
|
init_snippets();
|
|
389051
389464
|
init_promptIdContext();
|
|
@@ -389055,6 +389468,8 @@ var init_local_executor = __esm({
|
|
|
389055
389468
|
init_errors2();
|
|
389056
389469
|
init_utils6();
|
|
389057
389470
|
init_models();
|
|
389471
|
+
init_tokenLimits();
|
|
389472
|
+
init_tokenCalculation();
|
|
389058
389473
|
init_mnemonist();
|
|
389059
389474
|
init_thoughtUtils();
|
|
389060
389475
|
init_debugLogger();
|
|
@@ -389572,13 +389987,30 @@ var init_local_executor = __esm({
|
|
|
389572
389987
|
}
|
|
389573
389988
|
async tryCompressChat(chat, prompt_id, abortSignal) {
|
|
389574
389989
|
const model = this.definition.modelConfig.model ?? DEFAULT_GEMINI_MODEL;
|
|
389990
|
+
const threshold = await this.context.config.getCompressionThreshold() ?? DEFAULT_COMPRESSION_TOKEN_THRESHOLD;
|
|
389991
|
+
const modelLimit = tokenLimit(model);
|
|
389992
|
+
const lastPromptTokenCount = chat.getLastPromptTokenCount();
|
|
389993
|
+
const currentHistory = chat.getHistory(false);
|
|
389994
|
+
const originalTokenCount = lastPromptTokenCount > 0 ? lastPromptTokenCount : estimateTokenCountSync(currentHistory.flatMap((c2) => c2.parts || []));
|
|
389995
|
+
if (originalTokenCount >= threshold * modelLimit) {
|
|
389996
|
+
const collapsedHistory = collapseOlderFunctionResponses(currentHistory);
|
|
389997
|
+
if (collapsedHistory !== currentHistory) {
|
|
389998
|
+
const existingTurns = chat.getHistoryTurns?.(false) ?? [];
|
|
389999
|
+
const turns = collapsedHistory.map((c2, idx) => ({
|
|
390000
|
+
id: existingTurns[idx]?.id ?? randomUUID15(),
|
|
390001
|
+
content: c2
|
|
390002
|
+
}));
|
|
390003
|
+
chat.setHistory(turns);
|
|
390004
|
+
}
|
|
390005
|
+
}
|
|
389575
390006
|
const { newHistory, info: info2 } = await this.compressionService.compress(chat, prompt_id, false, model, this.context.config, this.hasFailedCompressionAttempt, abortSignal);
|
|
389576
390007
|
if (info2.compressionStatus === CompressionStatus.COMPRESSION_FAILED_INFLATED_TOKEN_COUNT) {
|
|
389577
390008
|
this.hasFailedCompressionAttempt = true;
|
|
389578
390009
|
} else if (info2.compressionStatus === CompressionStatus.COMPRESSED) {
|
|
389579
390010
|
if (newHistory) {
|
|
389580
|
-
const
|
|
389581
|
-
|
|
390011
|
+
const existingTurns = chat.getHistoryTurns?.(false) ?? [];
|
|
390012
|
+
const turns = newHistory.map((c2, idx) => ({
|
|
390013
|
+
id: existingTurns[idx]?.id ?? randomUUID15(),
|
|
389582
390014
|
content: c2
|
|
389583
390015
|
}));
|
|
389584
390016
|
chat.setHistory(turns);
|
|
@@ -389586,8 +390018,9 @@ var init_local_executor = __esm({
|
|
|
389586
390018
|
}
|
|
389587
390019
|
} else if (info2.compressionStatus === CompressionStatus.CONTENT_TRUNCATED) {
|
|
389588
390020
|
if (newHistory) {
|
|
389589
|
-
const
|
|
389590
|
-
|
|
390021
|
+
const existingTurns = chat.getHistoryTurns?.(false) ?? [];
|
|
390022
|
+
const turns = newHistory.map((c2, idx) => ({
|
|
390023
|
+
id: existingTurns[idx]?.id ?? randomUUID15(),
|
|
389591
390024
|
content: c2
|
|
389592
390025
|
}));
|
|
389593
390026
|
chat.setHistory(turns);
|
|
@@ -389770,6 +390203,15 @@ var init_local_executor = __esm({
|
|
|
389770
390203
|
signal,
|
|
389771
390204
|
onWaitingForConfirmation
|
|
389772
390205
|
});
|
|
390206
|
+
for (const call of completedCalls) {
|
|
390207
|
+
const outputFile = call.response?.outputFile;
|
|
390208
|
+
if (call.response?.responseParts) {
|
|
390209
|
+
call.response.responseParts = call.response.responseParts.map((p2) => truncateFunctionResponsePart(p2, MAX_STORED_TOOL_OUTPUT_BYTES, outputFile));
|
|
390210
|
+
}
|
|
390211
|
+
if (typeof call.response?.resultDisplay === "string" && Buffer.byteLength(call.response.resultDisplay, "utf8") > MAX_STORED_TOOL_OUTPUT_BYTES) {
|
|
390212
|
+
call.response.resultDisplay = truncateToolOutput(call.response.resultDisplay, MAX_STORED_TOOL_OUTPUT_BYTES, outputFile);
|
|
390213
|
+
}
|
|
390214
|
+
}
|
|
389773
390215
|
chat.recordCompletedToolCalls(model, completedCalls);
|
|
389774
390216
|
for (const call of completedCalls) {
|
|
389775
390217
|
const toolName = toolNameMap.get(call.request.callId) || call.request.name;
|
|
@@ -389835,7 +390277,7 @@ var init_local_executor = __esm({
|
|
|
389835
390277
|
const callId = functionCall.id ?? `${promptId}-${index}`;
|
|
389836
390278
|
const part = syncResults.get(callId);
|
|
389837
390279
|
if (part) {
|
|
389838
|
-
toolResponseParts.push(part);
|
|
390280
|
+
toolResponseParts.push(truncateFunctionResponsePart(part, MAX_STORED_TOOL_OUTPUT_BYTES));
|
|
389839
390281
|
continue;
|
|
389840
390282
|
}
|
|
389841
390283
|
const isAborted2 = signal.aborted;
|
|
@@ -403346,11 +403788,14 @@ var init_policy_engine = __esm({
|
|
|
403346
403788
|
isAlwaysAllowRule(rule) {
|
|
403347
403789
|
return rule.priority !== void 0 && Math.round(rule.priority % 1 * 1e3) === ALWAYS_ALLOW_PRIORITY_FRACTION;
|
|
403348
403790
|
}
|
|
403349
|
-
shouldDowngradeForRedirection(command, allowRedirection) {
|
|
403791
|
+
shouldDowngradeForRedirection(command, allowRedirection, rule) {
|
|
403350
403792
|
if (allowRedirection)
|
|
403351
403793
|
return false;
|
|
403352
403794
|
if (!hasRedirection(command))
|
|
403353
403795
|
return false;
|
|
403796
|
+
if (rule?.argsPattern && !allowRedirection) {
|
|
403797
|
+
return true;
|
|
403798
|
+
}
|
|
403354
403799
|
if (this.approvalMode === ApprovalMode.AUTO_EDIT || this.approvalMode === ApprovalMode.YOLO) {
|
|
403355
403800
|
return false;
|
|
403356
403801
|
}
|
|
@@ -403437,7 +403882,7 @@ var init_policy_engine = __esm({
|
|
|
403437
403882
|
}
|
|
403438
403883
|
let aggregateDecision = ruleDecision;
|
|
403439
403884
|
let responsibleRule = rule && ruleDecision === rule.decision ? rule : void 0;
|
|
403440
|
-
if (this.shouldDowngradeForRedirection(command, allowRedirection)) {
|
|
403885
|
+
if (this.shouldDowngradeForRedirection(command, allowRedirection, rule)) {
|
|
403441
403886
|
if (aggregateDecision === PolicyDecision.ALLOW) {
|
|
403442
403887
|
debugLogger.debug(`[PolicyEngine.check] Downgrading ALLOW to ASK_USER for redirected command: ${command}`);
|
|
403443
403888
|
aggregateDecision = PolicyDecision.ASK_USER;
|
|
@@ -403476,7 +403921,7 @@ var init_policy_engine = __esm({
|
|
|
403476
403921
|
}
|
|
403477
403922
|
aggregateDecision = PolicyDecision.ASK_USER;
|
|
403478
403923
|
}
|
|
403479
|
-
if (subResult.decision === PolicyDecision.ALLOW && this.shouldDowngradeForRedirection(subCmd, allowRedirection)) {
|
|
403924
|
+
if (subResult.decision === PolicyDecision.ALLOW && this.shouldDowngradeForRedirection(subCmd, subResult.rule?.allowRedirection ?? allowRedirection, subResult.rule)) {
|
|
403480
403925
|
if (aggregateDecision === PolicyDecision.ALLOW) {
|
|
403481
403926
|
aggregateDecision = PolicyDecision.ASK_USER;
|
|
403482
403927
|
responsibleRule = void 0;
|
|
@@ -403660,6 +404105,9 @@ var init_policy_engine = __esm({
|
|
|
403660
404105
|
}
|
|
403661
404106
|
}
|
|
403662
404107
|
}
|
|
404108
|
+
if (this.nonInteractive && decision === PolicyDecision.ASK_USER) {
|
|
404109
|
+
decision = PolicyDecision.DENY;
|
|
404110
|
+
}
|
|
403663
404111
|
return {
|
|
403664
404112
|
decision,
|
|
403665
404113
|
rule: matchedRule
|
|
@@ -406459,7 +406907,7 @@ import * as os34 from "node:os";
|
|
|
406459
406907
|
import * as path89 from "node:path";
|
|
406460
406908
|
function getWindowsPowerShellPath() {
|
|
406461
406909
|
let systemRoot = process.env["SystemRoot"] || process.env["systemroot"] || process.env["windir"] || process.env["WINDIR"] || "C:\\Windows";
|
|
406462
|
-
if (!/^[a-zA-Z]
|
|
406910
|
+
if (!/^[a-zA-Z]:\\Windows\\?$/i.test(systemRoot) || systemRoot.includes("..")) {
|
|
406463
406911
|
systemRoot = "C:\\Windows";
|
|
406464
406912
|
}
|
|
406465
406913
|
const pathModule = os34.platform() === "win32" ? path89.win32 : path89.posix;
|
|
@@ -407299,13 +407747,14 @@ var init_context_builder = __esm({
|
|
|
407299
407747
|
|
|
407300
407748
|
// packages/core/dist/src/safety/built-in.js
|
|
407301
407749
|
import * as path91 from "node:path";
|
|
407302
|
-
var VSCODE_SFN_REGEX, AllowedPathChecker;
|
|
407750
|
+
var VSCODE_SFN_REGEX, GEMINI_SFN_REGEX, AllowedPathChecker;
|
|
407303
407751
|
var init_built_in = __esm({
|
|
407304
407752
|
"packages/core/dist/src/safety/built-in.js"() {
|
|
407305
407753
|
"use strict";
|
|
407306
407754
|
init_protocol2();
|
|
407307
407755
|
init_paths();
|
|
407308
|
-
VSCODE_SFN_REGEX = /^(vscode|vs[0-9a-f]{4})~\d
|
|
407756
|
+
VSCODE_SFN_REGEX = /^(vscode|vs[0-9a-f]{4})~\d+(\..+)?$/i;
|
|
407757
|
+
GEMINI_SFN_REGEX = /^(gemini|ge[0-9a-f]{4})~\d+(\..+)?$/i;
|
|
407309
407758
|
AllowedPathChecker = class {
|
|
407310
407759
|
async check(input) {
|
|
407311
407760
|
const { toolCall, context: context2 } = input;
|
|
@@ -407328,6 +407777,7 @@ var init_built_in = __esm({
|
|
|
407328
407777
|
}
|
|
407329
407778
|
let hasBlockedSegment = false;
|
|
407330
407779
|
let isVscodePath = false;
|
|
407780
|
+
let isGeminiPath = false;
|
|
407331
407781
|
for (const resolvedDir of resolvedAllowedDirs) {
|
|
407332
407782
|
if (!this.isPathAllowed(resolvedPath, resolvedDir))
|
|
407333
407783
|
continue;
|
|
@@ -407341,6 +407791,9 @@ var init_built_in = __esm({
|
|
|
407341
407791
|
if (clean === ".vscode" || VSCODE_SFN_REGEX.test(clean)) {
|
|
407342
407792
|
isVscodePath = true;
|
|
407343
407793
|
}
|
|
407794
|
+
if (clean === ".gemini" || GEMINI_SFN_REGEX.test(clean)) {
|
|
407795
|
+
isGeminiPath = true;
|
|
407796
|
+
}
|
|
407344
407797
|
}
|
|
407345
407798
|
}
|
|
407346
407799
|
if (hasBlockedSegment) {
|
|
@@ -407349,6 +407802,12 @@ var init_built_in = __esm({
|
|
|
407349
407802
|
reason: `Access to sensitive path "${p2}" in argument "${argName}" is blocked.`
|
|
407350
407803
|
};
|
|
407351
407804
|
}
|
|
407805
|
+
if (isGeminiPath) {
|
|
407806
|
+
return {
|
|
407807
|
+
decision: SafetyCheckDecision.ASK_USER,
|
|
407808
|
+
reason: `Modifying .gemini configuration files requires explicit user confirmation.`
|
|
407809
|
+
};
|
|
407810
|
+
}
|
|
407352
407811
|
if (isVscodePath) {
|
|
407353
407812
|
return {
|
|
407354
407813
|
decision: SafetyCheckDecision.ASK_USER,
|
|
@@ -439180,7 +439639,7 @@ var wo = (s6) => {
|
|
|
439180
439639
|
// packages/a2a-server/src/persistence/gcs.ts
|
|
439181
439640
|
var fse = __toESM(require_lib7(), 1);
|
|
439182
439641
|
init_dist4();
|
|
439183
|
-
import { promises as
|
|
439642
|
+
import { promises as fsPromises12, createReadStream as createReadStream5 } from "node:fs";
|
|
439184
439643
|
import { join as join35 } from "node:path";
|
|
439185
439644
|
|
|
439186
439645
|
// packages/a2a-server/src/config/config.ts
|
|
@@ -439924,7 +440383,7 @@ var GCSTaskStore = class {
|
|
|
439924
440383
|
`Task ${taskId} metadata saved to GCS: gs://${this.bucketName}/${metadataObjectPath}`
|
|
439925
440384
|
);
|
|
439926
440385
|
if (await fse.pathExists(workDir)) {
|
|
439927
|
-
const entries = await
|
|
440386
|
+
const entries = await fsPromises12.readdir(workDir);
|
|
439928
440387
|
if (entries.length > 0) {
|
|
439929
440388
|
const tmpArchiveFile = join35(tmpdir(), getTmpArchiveFilename(taskId));
|
|
439930
440389
|
try {
|