@google/gemini-cli 0.67.0 → 0.69.0-preview.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/README.md +18 -24
- package/bundle/{chunk-IDJ4QXBF.js → chunk-2KKDGWF2.js} +1 -1
- package/bundle/{chunk-7LX6MRZ6.js → chunk-2ONJU4V7.js} +1 -1
- package/bundle/chunk-3HEOCQDN.js +65 -0
- package/bundle/{chunk-VO6PFWLY.js → chunk-4SOPZCNA.js} +29 -15
- package/bundle/{chunk-56IGTM4O.js → chunk-6KCLIS6W.js} +1 -1
- package/bundle/{chunk-2E3ETS5J.js → chunk-BRHBBQC5.js} +2 -2
- package/bundle/{chunk-M73CYIV5.js → chunk-C5BED6L6.js} +2 -2
- package/bundle/{chunk-VK766A3F.js → chunk-CGQSFR2I.js} +7 -2
- package/bundle/{chunk-OJ62HCXG.js → chunk-CWHEOJXF.js} +7 -2
- package/bundle/{chunk-LAR4JEC7.js → chunk-DWMZSQYG.js} +6050 -2877
- package/bundle/{chunk-QTXJG3I3.js → chunk-GDCMMKZ2.js} +1 -1
- package/bundle/{chunk-YUO7RUF4.js → chunk-GQ7FZNO2.js} +1 -1
- package/bundle/{chunk-GBUWHRK6.js → chunk-JJWPYMIO.js} +3 -3
- package/bundle/{chunk-NGQU3QTQ.js → chunk-KUXCUQKX.js} +5859 -2837
- package/bundle/{chunk-P62CI7AR.js → chunk-LYKP3S67.js} +29 -15
- package/bundle/{chunk-O7MGOE2I.js → chunk-MP4TVGOP.js} +6050 -2877
- package/bundle/{chunk-IGE3G3WZ.js → chunk-PH5XENTH.js} +1 -1
- package/bundle/{chunk-CJFBYU4J.js → chunk-RBDD6IBU.js} +937 -327
- package/bundle/{chunk-5RNHNFYV.js → chunk-SYOIMUZI.js} +937 -327
- package/bundle/{chunk-BW65QRZA.js → chunk-U3FFDEKY.js} +29 -15
- package/bundle/{chunk-MQNW2IRI.js → chunk-U5FJ6OGB.js} +2 -2
- package/bundle/{chunk-PUNFASKY.js → chunk-UAHZWXSG.js} +7 -2
- package/bundle/chunk-UW3ZS3BH.js +65 -0
- package/bundle/{chunk-4JH2G4F4.js → chunk-V7L3FMBE.js} +3 -3
- package/bundle/chunk-VQTELFV3.js +65 -0
- package/bundle/{chunk-QA5FT4VY.js → chunk-YODS6HR2.js} +3 -3
- package/bundle/{chunk-XETHQLRU.js → chunk-YP5TA33N.js} +937 -327
- package/bundle/{cleanup-B6AOSVD4.js → cleanup-3T2KXSP4.js} +2 -2
- package/bundle/{cleanup-BRFB47DL.js → cleanup-NNQCI4KC.js} +2 -2
- package/bundle/{cleanup-S5QFYCEP.js → cleanup-TA4VYDXQ.js} +2 -2
- package/bundle/{core-N27LU4DK.js → core-6XF5EO7Z.js} +37 -1
- package/bundle/{dist-E6RCLXQU.js → core-TUJHM7E7.js} +37 -1
- package/bundle/{devtoolsService-6V46WMXX.js → devtoolsService-7EMPANTX.js} +2 -2
- package/bundle/{devtoolsService-E74ZMDMM.js → devtoolsService-I7WFRUEA.js} +2 -2
- package/bundle/{devtoolsService-EFJXZRFD.js → devtoolsService-RCBUZGYD.js} +2 -2
- package/bundle/{core-GTUUQBGE.js → dist-OSQFIX7F.js} +37 -1
- package/bundle/docs/changelogs/index.md +42 -0
- package/bundle/docs/changelogs/latest.md +89 -91
- package/bundle/docs/changelogs/preview.md +106 -90
- package/bundle/docs/cli/sandbox.md +8 -2
- package/bundle/docs/cli/themes.md +56 -8
- package/bundle/docs/cli/trusted-folders.md +13 -0
- package/bundle/docs/extensions/releasing.md +32 -0
- package/bundle/docs/reference/commands.md +4 -0
- package/bundle/docs/reference/configuration.md +10 -10
- package/bundle/docs/reference/policy-engine.md +6 -0
- package/bundle/formatError-KEQ3HU3Y.js +14 -0
- package/bundle/formatError-LJFIC7G3.js +14 -0
- package/bundle/formatError-MIUNQEYE.js +14 -0
- package/bundle/{gemini-QWDTSJTS.js → gemini-22ON2CZG.js} +601 -142
- package/bundle/{gemini-4JPKPLQN.js → gemini-HLS52ZNZ.js} +601 -142
- package/bundle/{gemini-VF5FS3OM.js → gemini-ZZZEFPSK.js} +601 -142
- package/bundle/gemini.js +14 -13
- package/bundle/{interactiveCli-QJZZISQQ.js → interactiveCli-5HMWVTK2.js} +2967 -2329
- package/bundle/{interactiveCli-FQ3YKGOG.js → interactiveCli-HQBE3C3C.js} +2967 -2329
- package/bundle/{interactiveCli-F2YYMYTP.js → interactiveCli-NKFQZXB5.js} +2967 -2329
- package/bundle/{liteRtServerManager-JAV3GR4V.js → liteRtServerManager-2IOXWO76.js} +4 -4
- package/bundle/{liteRtServerManager-X5CCMKM6.js → liteRtServerManager-AG4Y5JMZ.js} +4 -4
- package/bundle/{liteRtServerManager-27R2M6XE.js → liteRtServerManager-OFNVXXQ4.js} +4 -4
- package/bundle/{oauth2-provider-6UCP23AQ.js → oauth2-provider-2DHNJ2S3.js} +1 -1
- package/bundle/{oauth2-provider-H2KV36NU.js → oauth2-provider-OEGXLWIL.js} +1 -1
- package/bundle/{oauth2-provider-C65IJMNQ.js → oauth2-provider-YDNSNN32.js} +1 -1
- package/bundle/policies/yolo.toml +1 -0
- package/bundle/sandbox-macos-permissive-open.sb +8 -0
- package/bundle/sandbox-macos-permissive-proxied.sb +8 -0
- package/bundle/sandbox-macos-restrictive-open.sb +1 -0
- package/bundle/sandbox-macos-restrictive-proxied.sb +1 -0
- package/bundle/sandbox-macos-strict-open.sb +1 -0
- package/bundle/sandbox-macos-strict-proxied.sb +1 -0
- package/bundle/{start-GNOA75NQ.js → start-7GJH3MKY.js} +6 -6
- package/bundle/{start-K2AYYNST.js → start-JSVKPUTV.js} +6 -6
- package/bundle/{start-E4ZL44QM.js → start-N33LF5WK.js} +6 -6
- package/package.json +1 -1
|
@@ -2,7 +2,10 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
|
|
|
2
2
|
import {
|
|
3
3
|
startCommand,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-YODS6HR2.js";
|
|
6
|
+
import {
|
|
7
|
+
formatCliError
|
|
8
|
+
} from "./chunk-VQTELFV3.js";
|
|
6
9
|
import {
|
|
7
10
|
BuiltinCommandLoader,
|
|
8
11
|
CommandService,
|
|
@@ -45,11 +48,11 @@ import {
|
|
|
45
48
|
updateExtension,
|
|
46
49
|
validateAuthMethod,
|
|
47
50
|
validateContextFilePath
|
|
48
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-YP5TA33N.js";
|
|
49
52
|
import {
|
|
50
53
|
exitCli,
|
|
51
54
|
require_source
|
|
52
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-2ONJU4V7.js";
|
|
53
56
|
import {
|
|
54
57
|
appEvents
|
|
55
58
|
} from "./chunk-5PS3AYFU.js";
|
|
@@ -89,12 +92,12 @@ import {
|
|
|
89
92
|
saveModelChange,
|
|
90
93
|
setAmbiguousCharactersWide,
|
|
91
94
|
stripAnsi
|
|
92
|
-
} from "./chunk-
|
|
95
|
+
} from "./chunk-U3FFDEKY.js";
|
|
93
96
|
import {
|
|
94
97
|
RELAUNCH_EXIT_CODE,
|
|
95
98
|
require_semver
|
|
96
|
-
} from "./chunk-
|
|
97
|
-
import "./chunk-
|
|
99
|
+
} from "./chunk-C5BED6L6.js";
|
|
100
|
+
import "./chunk-GQ7FZNO2.js";
|
|
98
101
|
import {
|
|
99
102
|
cleanupCheckpoints,
|
|
100
103
|
registerCleanup,
|
|
@@ -103,7 +106,7 @@ import {
|
|
|
103
106
|
runExitCleanup,
|
|
104
107
|
runSyncCleanup,
|
|
105
108
|
setupSignalHandlers
|
|
106
|
-
} from "./chunk-
|
|
109
|
+
} from "./chunk-CGQSFR2I.js";
|
|
107
110
|
import {
|
|
108
111
|
ASK_USER_TOOL_NAME,
|
|
109
112
|
AjvJsonSchemaValidator,
|
|
@@ -139,6 +142,8 @@ import {
|
|
|
139
142
|
FatalUntrustedWorkspaceError,
|
|
140
143
|
FileDiscoveryService,
|
|
141
144
|
FolderTrustDiscoveryService,
|
|
145
|
+
GEMINI_CLI_IN_SHELL_ENV_VAR,
|
|
146
|
+
GEMINI_CLI_NESTED_SESSION_ENV_VAR,
|
|
142
147
|
GEMINI_DIR,
|
|
143
148
|
GEMINI_MODEL_ALIAS_AUTO,
|
|
144
149
|
GeminiEventType,
|
|
@@ -165,6 +170,7 @@ import {
|
|
|
165
170
|
MCPServerStatus,
|
|
166
171
|
McpError,
|
|
167
172
|
MessageBusType,
|
|
173
|
+
NESTED_INTERACTIVE_SESSION_ERROR,
|
|
168
174
|
OTHER_BLOCKED_MESSAGE,
|
|
169
175
|
OutputFormat,
|
|
170
176
|
PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL,
|
|
@@ -263,6 +269,7 @@ import {
|
|
|
263
269
|
logToolCall,
|
|
264
270
|
logUserPrompt,
|
|
265
271
|
mergeCapabilities,
|
|
272
|
+
normalizeError,
|
|
266
273
|
parseAndFormatApiError,
|
|
267
274
|
partListUnionToString,
|
|
268
275
|
patchStdio,
|
|
@@ -289,7 +296,7 @@ import {
|
|
|
289
296
|
updatePolicy,
|
|
290
297
|
writeToStderr,
|
|
291
298
|
writeToStdout
|
|
292
|
-
} from "./chunk-
|
|
299
|
+
} from "./chunk-KUXCUQKX.js";
|
|
293
300
|
import "./chunk-664ZODQF.js";
|
|
294
301
|
import "./chunk-IUUIT4SU.js";
|
|
295
302
|
import "./chunk-L6PII3GR.js";
|
|
@@ -1574,11 +1581,11 @@ var parser = new YargsParser({
|
|
|
1574
1581
|
resolve: resolve2,
|
|
1575
1582
|
// TODO: figure out a way to combine ESM and CJS coverage, such that
|
|
1576
1583
|
// we can exercise all the lines below:
|
|
1577
|
-
require: (
|
|
1584
|
+
require: (path19) => {
|
|
1578
1585
|
if (typeof __require !== "undefined") {
|
|
1579
|
-
return __require(
|
|
1580
|
-
} else if (
|
|
1581
|
-
return JSON.parse(readFileSync(
|
|
1586
|
+
return __require(path19);
|
|
1587
|
+
} else if (path19.match(/\.json$/)) {
|
|
1588
|
+
return JSON.parse(readFileSync(path19, "utf8"));
|
|
1582
1589
|
} else {
|
|
1583
1590
|
throw Error("only .json config files are supported in ESM");
|
|
1584
1591
|
}
|
|
@@ -6382,27 +6389,27 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
6382
6389
|
var __filename = fileURLToPath2(import.meta.url);
|
|
6383
6390
|
var __dirname2 = dirname3(__filename);
|
|
6384
6391
|
var EXAMPLES_PATH = join(__dirname2, "examples");
|
|
6385
|
-
async function pathExists(
|
|
6392
|
+
async function pathExists(path19) {
|
|
6386
6393
|
try {
|
|
6387
|
-
await access(
|
|
6394
|
+
await access(path19);
|
|
6388
6395
|
return true;
|
|
6389
6396
|
} catch {
|
|
6390
6397
|
return false;
|
|
6391
6398
|
}
|
|
6392
6399
|
}
|
|
6393
|
-
async function createDirectory(
|
|
6394
|
-
if (await pathExists(
|
|
6395
|
-
throw new Error(`Path already exists: ${
|
|
6400
|
+
async function createDirectory(path19) {
|
|
6401
|
+
if (await pathExists(path19)) {
|
|
6402
|
+
throw new Error(`Path already exists: ${path19}`);
|
|
6396
6403
|
}
|
|
6397
|
-
await mkdir(
|
|
6404
|
+
await mkdir(path19, { recursive: true });
|
|
6398
6405
|
}
|
|
6399
|
-
async function copyDirectory(template,
|
|
6400
|
-
await createDirectory(
|
|
6406
|
+
async function copyDirectory(template, path19) {
|
|
6407
|
+
await createDirectory(path19);
|
|
6401
6408
|
const examplePath = join(EXAMPLES_PATH, template);
|
|
6402
6409
|
const entries = await readdir(examplePath, { withFileTypes: true });
|
|
6403
6410
|
for (const entry of entries) {
|
|
6404
6411
|
const srcPath = join(examplePath, entry.name);
|
|
6405
|
-
const destPath = join(
|
|
6412
|
+
const destPath = join(path19, entry.name);
|
|
6406
6413
|
await cp(srcPath, destPath, { recursive: true });
|
|
6407
6414
|
}
|
|
6408
6415
|
}
|
|
@@ -6512,6 +6519,57 @@ async function validateExtension(args) {
|
|
|
6512
6519
|
`Warning: Version '${extensionConfig.version}' does not appear to be standard semver (e.g., 1.0.0).`
|
|
6513
6520
|
);
|
|
6514
6521
|
}
|
|
6522
|
+
if (extensionConfig.mcpServers) {
|
|
6523
|
+
if (typeof extensionConfig.mcpServers !== "object" || extensionConfig.mcpServers === null || Array.isArray(extensionConfig.mcpServers)) {
|
|
6524
|
+
errors.push('The "mcpServers" field must be an object.');
|
|
6525
|
+
} else {
|
|
6526
|
+
for (const [serverName, serverConfig] of Object.entries(
|
|
6527
|
+
extensionConfig.mcpServers
|
|
6528
|
+
)) {
|
|
6529
|
+
if (typeof serverConfig !== "object" || serverConfig === null || Array.isArray(serverConfig)) {
|
|
6530
|
+
errors.push(
|
|
6531
|
+
`MCP server configuration for "${serverName}" must be an object.`
|
|
6532
|
+
);
|
|
6533
|
+
continue;
|
|
6534
|
+
}
|
|
6535
|
+
const hasCommand = typeof serverConfig.command === "string" && serverConfig.command.trim().length > 0;
|
|
6536
|
+
const hasUrl = typeof serverConfig.url === "string" && serverConfig.url.trim().length > 0;
|
|
6537
|
+
const hasHttpUrl = typeof serverConfig.httpUrl === "string" && serverConfig.httpUrl.trim().length > 0;
|
|
6538
|
+
const hasTcp = typeof serverConfig.tcp === "string" && serverConfig.tcp.trim().length > 0 || typeof serverConfig.tcp === "number";
|
|
6539
|
+
if (!hasCommand && !hasUrl && !hasHttpUrl && !hasTcp) {
|
|
6540
|
+
errors.push(
|
|
6541
|
+
`MCP server "${serverName}" must specify a transport (e.g., "command", "url", or "httpUrl").`
|
|
6542
|
+
);
|
|
6543
|
+
}
|
|
6544
|
+
if (hasHttpUrl) {
|
|
6545
|
+
warnings.push(
|
|
6546
|
+
`MCP server "${serverName}" uses deprecated "httpUrl". Consider using "url" with "type": "http" instead.`
|
|
6547
|
+
);
|
|
6548
|
+
}
|
|
6549
|
+
const errorPrefix = `MCP server "${serverName}" specifies an invalid `;
|
|
6550
|
+
if (hasUrl && serverConfig.url) {
|
|
6551
|
+
const hasPlaceholder = serverConfig.url.includes("$");
|
|
6552
|
+
if (!hasPlaceholder) {
|
|
6553
|
+
try {
|
|
6554
|
+
new URL(serverConfig.url);
|
|
6555
|
+
} catch {
|
|
6556
|
+
errors.push(`${errorPrefix}URL: "${serverConfig.url}".`);
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6559
|
+
}
|
|
6560
|
+
if (hasHttpUrl && serverConfig.httpUrl) {
|
|
6561
|
+
const hasPlaceholder = serverConfig.httpUrl.includes("$");
|
|
6562
|
+
if (!hasPlaceholder) {
|
|
6563
|
+
try {
|
|
6564
|
+
new URL(serverConfig.httpUrl);
|
|
6565
|
+
} catch {
|
|
6566
|
+
errors.push(`${errorPrefix}httpUrl: "${serverConfig.httpUrl}".`);
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
6569
|
+
}
|
|
6570
|
+
}
|
|
6571
|
+
}
|
|
6572
|
+
}
|
|
6515
6573
|
if (warnings.length > 0) {
|
|
6516
6574
|
debugLogger.warn("Validation warnings:");
|
|
6517
6575
|
for (const warning of warnings) {
|
|
@@ -6683,7 +6741,7 @@ async function handleEnable3(args) {
|
|
|
6683
6741
|
const result = enableSkill(settings, name);
|
|
6684
6742
|
const feedback = renderSkillActionFeedback(
|
|
6685
6743
|
result,
|
|
6686
|
-
(label,
|
|
6744
|
+
(label, path19) => `${import_chalk5.default.bold(label)} (${import_chalk5.default.dim(path19)})`
|
|
6687
6745
|
);
|
|
6688
6746
|
debugLogger.log(feedback);
|
|
6689
6747
|
}
|
|
@@ -6713,7 +6771,7 @@ async function handleDisable3(args) {
|
|
|
6713
6771
|
const result = disableSkill(settings, name, scope);
|
|
6714
6772
|
const feedback = renderSkillActionFeedback(
|
|
6715
6773
|
result,
|
|
6716
|
-
(label,
|
|
6774
|
+
(label, path19) => `${import_chalk6.default.bold(label)} (${import_chalk6.default.dim(path19)})`
|
|
6717
6775
|
);
|
|
6718
6776
|
debugLogger.log(feedback);
|
|
6719
6777
|
}
|
|
@@ -6956,8 +7014,10 @@ var EVENT_MAPPING = {
|
|
|
6956
7014
|
PostToolUse: "AfterTool",
|
|
6957
7015
|
UserPromptSubmit: "BeforeAgent",
|
|
6958
7016
|
Stop: "AfterAgent",
|
|
6959
|
-
|
|
7017
|
+
SubagentStop: "AfterAgent",
|
|
6960
7018
|
// Gemini doesn't have sub-agents, map to AfterAgent
|
|
7019
|
+
SubAgentStop: "AfterAgent",
|
|
7020
|
+
// Fallback for alternate casing
|
|
6961
7021
|
SessionStart: "SessionStart",
|
|
6962
7022
|
SessionEnd: "SessionEnd",
|
|
6963
7023
|
PreCompact: "PreCompress",
|
|
@@ -7045,7 +7105,10 @@ function migrateClaudeHooks(claudeConfig) {
|
|
|
7045
7105
|
}
|
|
7046
7106
|
return migratedDef;
|
|
7047
7107
|
});
|
|
7048
|
-
geminiHooks[geminiEventName] =
|
|
7108
|
+
geminiHooks[geminiEventName] = [
|
|
7109
|
+
...geminiHooks[geminiEventName] || [],
|
|
7110
|
+
...migratedDefinitions
|
|
7111
|
+
];
|
|
7049
7112
|
}
|
|
7050
7113
|
return geminiHooks;
|
|
7051
7114
|
}
|
|
@@ -7838,6 +7901,16 @@ var RequestPermissionResponseSchema = external_exports.object({
|
|
|
7838
7901
|
})
|
|
7839
7902
|
])
|
|
7840
7903
|
});
|
|
7904
|
+
function isAnsiOutput(value) {
|
|
7905
|
+
return Array.isArray(value) && value.every(
|
|
7906
|
+
(line) => Array.isArray(line) && line.every(
|
|
7907
|
+
(token) => typeof token === "object" && token !== null && "text" in token && typeof token.text === "string"
|
|
7908
|
+
)
|
|
7909
|
+
);
|
|
7910
|
+
}
|
|
7911
|
+
function ansiOutputToPlainText(ansiOutput) {
|
|
7912
|
+
return ansiOutput.map((line) => line.map((token) => token.text).join("")).join("\n").trim();
|
|
7913
|
+
}
|
|
7841
7914
|
function toToolCallContent(toolResult) {
|
|
7842
7915
|
if (toolResult.error?.message) {
|
|
7843
7916
|
throw new Error(toolResult.error.message);
|
|
@@ -7848,6 +7921,12 @@ function toToolCallContent(toolResult) {
|
|
|
7848
7921
|
type: "content",
|
|
7849
7922
|
content: { type: "text", text: toolResult.returnDisplay }
|
|
7850
7923
|
};
|
|
7924
|
+
} else if (isAnsiOutput(toolResult.returnDisplay)) {
|
|
7925
|
+
const text = ansiOutputToPlainText(toolResult.returnDisplay);
|
|
7926
|
+
if (!text) {
|
|
7927
|
+
return null;
|
|
7928
|
+
}
|
|
7929
|
+
return { type: "content", content: { type: "text", text } };
|
|
7851
7930
|
} else {
|
|
7852
7931
|
if ("fileName" in toolResult.returnDisplay) {
|
|
7853
7932
|
return {
|
|
@@ -8324,7 +8403,7 @@ async function loadSandboxConfig(settings, argv) {
|
|
|
8324
8403
|
}
|
|
8325
8404
|
const command2 = getSandboxCommand(sandboxValue);
|
|
8326
8405
|
const packageJson = await getPackageJson(__dirname3);
|
|
8327
|
-
const image = process.env["GEMINI_SANDBOX_IMAGE"] ?? "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.
|
|
8406
|
+
const image = process.env["GEMINI_SANDBOX_IMAGE"] ?? "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.69.0-preview.0" ?? customImage ?? packageJson?.config?.sandboxImageUri;
|
|
8328
8407
|
const isNative = command2 === "windows-native" || command2 === "sandbox-exec" || command2 === "lxc";
|
|
8329
8408
|
return command2 && (image || isNative) ? { enabled: true, allowedPaths, networkAccess, command: command2, image } : void 0;
|
|
8330
8409
|
}
|
|
@@ -8727,6 +8806,40 @@ async function parseArguments(settings) {
|
|
|
8727
8806
|
} else if (typeof queryArg === "string") {
|
|
8728
8807
|
q = queryArg;
|
|
8729
8808
|
}
|
|
8809
|
+
const trimmedQuery = q?.trim() ?? "";
|
|
8810
|
+
const rawQueryTokens = trimmedQuery.length > 0 ? trimmedQuery.split(/\s+/) : [];
|
|
8811
|
+
const firstQueryToken = rawQueryTokens[0]?.toLowerCase();
|
|
8812
|
+
const secondQueryToken = rawQueryTokens[1]?.toLowerCase();
|
|
8813
|
+
const isQuotedPrompt = rawQueryTokens.length > 1 && process3.argv.some((arg) => arg.trim() === trimmedQuery);
|
|
8814
|
+
const isInvalidConfigSubcommand = !result["isCommand"] && (firstQueryToken === "config" && (secondQueryToken === void 0 || secondQueryToken.startsWith("-") || [
|
|
8815
|
+
"set",
|
|
8816
|
+
"get",
|
|
8817
|
+
"list",
|
|
8818
|
+
"delete",
|
|
8819
|
+
"unset",
|
|
8820
|
+
"edit",
|
|
8821
|
+
"show",
|
|
8822
|
+
"default-model",
|
|
8823
|
+
"model"
|
|
8824
|
+
].includes(secondQueryToken)) || (firstQueryToken === "set" || firstQueryToken === "model") && secondQueryToken !== void 0 && ["set", "get", "list", "default-model", "model"].includes(
|
|
8825
|
+
secondQueryToken
|
|
8826
|
+
)) && !isQuotedPrompt;
|
|
8827
|
+
const isInNestedShell = process3.env[GEMINI_CLI_IN_SHELL_ENV_VAR] === "1" || process3.env[GEMINI_CLI_NESTED_SESSION_ENV_VAR] === "1";
|
|
8828
|
+
if (isInNestedShell) {
|
|
8829
|
+
const isAllowedNonInteractive = Boolean(result["isCommand"]) || Boolean(result["listModels"]) || Boolean(result["list-models"]) || Boolean(result["listExtensions"]) || Boolean(result["list-extensions"]) || Boolean(result["listSessions"]) || Boolean(result["list-sessions"]) || Boolean(result["deleteSession"]) || Boolean(result["delete-session"]) || Boolean(result["prompt"]) && !result["promptInteractive"] && !result["prompt-interactive"] && !isInvalidConfigSubcommand;
|
|
8830
|
+
if (!isAllowedNonInteractive) {
|
|
8831
|
+
debugLogger.error(NESTED_INTERACTIVE_SESSION_ERROR);
|
|
8832
|
+
await runExitCleanup();
|
|
8833
|
+
process3.exit(1);
|
|
8834
|
+
}
|
|
8835
|
+
}
|
|
8836
|
+
if (isInvalidConfigSubcommand) {
|
|
8837
|
+
debugLogger.error(
|
|
8838
|
+
`Error: Unknown command "${rawQueryTokens[0]}". To switch models or update settings, use built-in slash commands (/model, /settings).`
|
|
8839
|
+
);
|
|
8840
|
+
await runExitCleanup();
|
|
8841
|
+
process3.exit(1);
|
|
8842
|
+
}
|
|
8730
8843
|
if (q && !result["prompt"]) {
|
|
8731
8844
|
if (!isHeadlessMode()) {
|
|
8732
8845
|
startupMessages.push(
|
|
@@ -9057,12 +9170,13 @@ async function loadCliConfig(settings, sessionId, argv, options = {}) {
|
|
|
9057
9170
|
usageStatisticsEnabled: settings.privacy?.usageStatisticsEnabled,
|
|
9058
9171
|
fileFiltering,
|
|
9059
9172
|
checkpointing: settings.general?.checkpointing?.enabled,
|
|
9060
|
-
proxy: process3.env["HTTPS_PROXY"] || process3.env["https_proxy"] || process3.env["HTTP_PROXY"] || process3.env["http_proxy"],
|
|
9173
|
+
proxy: process3.env["HTTPS_PROXY"] || process3.env["https_proxy"] || process3.env["HTTP_PROXY"] || process3.env["http_proxy"] || process3.env["ALL_PROXY"] || process3.env["all_proxy"],
|
|
9061
9174
|
cwd,
|
|
9062
9175
|
fileDiscoveryService: fileService,
|
|
9063
9176
|
bugCommand: settings.advanced?.bugCommand,
|
|
9064
9177
|
model: resolvedModel,
|
|
9065
9178
|
maxSessionTurns: settings.model?.maxSessionTurns,
|
|
9179
|
+
requestTimeoutMs: settings.model?.requestTimeoutMs,
|
|
9066
9180
|
listExtensions: argv.listExtensions || false,
|
|
9067
9181
|
listSessions: argv.listSessions || false,
|
|
9068
9182
|
deleteSession: argv.deleteSession,
|
|
@@ -9193,22 +9307,30 @@ async function resolveWorktreeSettings(cwd) {
|
|
|
9193
9307
|
}
|
|
9194
9308
|
|
|
9195
9309
|
// packages/cli/src/utils/readStdin.ts
|
|
9196
|
-
function
|
|
9197
|
-
|
|
9198
|
-
if (buf.length <= maxBytes) return
|
|
9310
|
+
function truncateUtf8Buffer(buf, maxBytes) {
|
|
9311
|
+
if (maxBytes <= 0) return "";
|
|
9312
|
+
if (buf.length <= maxBytes) return buf.toString("utf8");
|
|
9199
9313
|
let end = maxBytes;
|
|
9200
9314
|
while (end > 0 && (buf[end] & 192) === 128) {
|
|
9201
9315
|
end--;
|
|
9202
9316
|
}
|
|
9203
9317
|
return buf.subarray(0, end).toString("utf8");
|
|
9204
9318
|
}
|
|
9319
|
+
function truncateUtf8Bytes(str, maxBytes) {
|
|
9320
|
+
if (maxBytes <= 0) return "";
|
|
9321
|
+
return truncateUtf8Buffer(Buffer.from(str, "utf8"), maxBytes);
|
|
9322
|
+
}
|
|
9205
9323
|
async function readStdin() {
|
|
9324
|
+
if (process.stdin.isTTY || process.stdin.destroyed || process.stdin.readableEnded) {
|
|
9325
|
+
return "";
|
|
9326
|
+
}
|
|
9206
9327
|
const MAX_STDIN_SIZE = 8 * 1024 * 1024;
|
|
9207
9328
|
return new Promise((resolve10, reject) => {
|
|
9208
9329
|
let data = "";
|
|
9209
9330
|
let totalSize = 0;
|
|
9331
|
+
let settled = false;
|
|
9210
9332
|
process.stdin.setEncoding("utf8");
|
|
9211
|
-
const pipedInputShouldBeAvailableInMs =
|
|
9333
|
+
const pipedInputShouldBeAvailableInMs = 1e3;
|
|
9212
9334
|
let pipedInputTimerId = setTimeout(() => {
|
|
9213
9335
|
onEnd();
|
|
9214
9336
|
}, pipedInputShouldBeAvailableInMs);
|
|
@@ -9219,26 +9341,46 @@ async function readStdin() {
|
|
|
9219
9341
|
clearTimeout(pipedInputTimerId);
|
|
9220
9342
|
pipedInputTimerId = null;
|
|
9221
9343
|
}
|
|
9222
|
-
|
|
9344
|
+
let chunkByteLength;
|
|
9345
|
+
let chunkBuffer;
|
|
9346
|
+
let chunkStr = "";
|
|
9347
|
+
if (Buffer.isBuffer(chunk)) {
|
|
9348
|
+
chunkBuffer = chunk;
|
|
9349
|
+
chunkByteLength = chunk.length;
|
|
9350
|
+
} else {
|
|
9351
|
+
chunkStr = typeof chunk === "string" ? chunk : String(chunk);
|
|
9352
|
+
chunkByteLength = Buffer.byteLength(chunkStr, "utf8");
|
|
9353
|
+
}
|
|
9223
9354
|
if (totalSize + chunkByteLength > MAX_STDIN_SIZE) {
|
|
9224
9355
|
const remainingBytes = MAX_STDIN_SIZE - totalSize;
|
|
9225
|
-
data += truncateUtf8Bytes(
|
|
9356
|
+
data += chunkBuffer ? truncateUtf8Buffer(chunkBuffer, remainingBytes) : truncateUtf8Bytes(chunkStr, remainingBytes);
|
|
9226
9357
|
debugLogger.warn(
|
|
9227
9358
|
`Warning: stdin input truncated to ${MAX_STDIN_SIZE} bytes.`
|
|
9228
9359
|
);
|
|
9229
|
-
|
|
9230
|
-
|
|
9360
|
+
cleanup();
|
|
9361
|
+
if (typeof process.stdin.unpipe === "function") {
|
|
9362
|
+
process.stdin.unpipe();
|
|
9363
|
+
}
|
|
9364
|
+
if (typeof process.stdin.pause === "function") {
|
|
9365
|
+
process.stdin.pause();
|
|
9366
|
+
}
|
|
9367
|
+
settled = true;
|
|
9368
|
+
resolve10(data);
|
|
9231
9369
|
break;
|
|
9232
9370
|
}
|
|
9233
|
-
data +=
|
|
9371
|
+
data += chunkBuffer ? chunkBuffer.toString("utf8") : chunkStr;
|
|
9234
9372
|
totalSize += chunkByteLength;
|
|
9235
9373
|
}
|
|
9236
9374
|
};
|
|
9237
9375
|
const onEnd = () => {
|
|
9376
|
+
if (settled) return;
|
|
9377
|
+
settled = true;
|
|
9238
9378
|
cleanup();
|
|
9239
9379
|
resolve10(data);
|
|
9240
9380
|
};
|
|
9241
9381
|
const onError = (err) => {
|
|
9382
|
+
if (settled) return;
|
|
9383
|
+
settled = true;
|
|
9242
9384
|
cleanup();
|
|
9243
9385
|
reject(err);
|
|
9244
9386
|
};
|
|
@@ -9267,7 +9409,7 @@ import { createHash as createHash2 } from "node:crypto";
|
|
|
9267
9409
|
import v8 from "node:v8";
|
|
9268
9410
|
import os6 from "node:os";
|
|
9269
9411
|
import dns from "node:dns";
|
|
9270
|
-
import * as
|
|
9412
|
+
import * as path18 from "node:path";
|
|
9271
9413
|
import * as fsPromises from "node:fs/promises";
|
|
9272
9414
|
|
|
9273
9415
|
// packages/cli/src/utils/sandbox.ts
|
|
@@ -9606,6 +9748,9 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
9606
9748
|
(global-name "com.apple.SystemConfiguration.DNSConfiguration")
|
|
9607
9749
|
(global-name "com.apple.SystemConfiguration.configd")
|
|
9608
9750
|
)
|
|
9751
|
+
(allow mach-lookup
|
|
9752
|
+
(global-name "com.apple.FSEvents")
|
|
9753
|
+
)
|
|
9609
9754
|
(allow system-socket
|
|
9610
9755
|
(require-all
|
|
9611
9756
|
(socket-domain AF_SYSTEM)
|
|
@@ -9772,6 +9917,9 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
9772
9917
|
(global-name "com.apple.SystemConfiguration.DNSConfiguration")
|
|
9773
9918
|
(global-name "com.apple.SystemConfiguration.configd")
|
|
9774
9919
|
)
|
|
9920
|
+
(allow mach-lookup
|
|
9921
|
+
(global-name "com.apple.FSEvents")
|
|
9922
|
+
)
|
|
9775
9923
|
(allow system-socket
|
|
9776
9924
|
(require-all
|
|
9777
9925
|
(socket-domain AF_SYSTEM)
|
|
@@ -9860,6 +10008,7 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
9860
10008
|
(allow file-read*
|
|
9861
10009
|
(literal (string-append (param "HOME_DIR") "/.gemini/settings.json"))
|
|
9862
10010
|
(literal (string-append (param "HOME_DIR") "/.gemini/keybindings.json"))
|
|
10011
|
+
(literal (string-append (param "HOME_DIR") "/.gemini/theme.json"))
|
|
9863
10012
|
)
|
|
9864
10013
|
(allow process-exec)
|
|
9865
10014
|
(allow process-fork)
|
|
@@ -10007,6 +10156,7 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
10007
10156
|
(allow file-read*
|
|
10008
10157
|
(literal (string-append (param "HOME_DIR") "/.gemini/settings.json"))
|
|
10009
10158
|
(literal (string-append (param "HOME_DIR") "/.gemini/keybindings.json"))
|
|
10159
|
+
(literal (string-append (param "HOME_DIR") "/.gemini/theme.json"))
|
|
10010
10160
|
)
|
|
10011
10161
|
(allow process-exec)
|
|
10012
10162
|
(allow process-fork)
|
|
@@ -10157,6 +10307,7 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
10157
10307
|
(subpath (param "CACHE_DIR"))
|
|
10158
10308
|
(literal (string-append (param "HOME_DIR") "/.gemini/settings.json"))
|
|
10159
10309
|
(literal (string-append (param "HOME_DIR") "/.gemini/keybindings.json"))
|
|
10310
|
+
(literal (string-append (param "HOME_DIR") "/.gemini/theme.json"))
|
|
10160
10311
|
(subpath (string-append (param "HOME_DIR") "/.npm"))
|
|
10161
10312
|
(subpath (string-append (param "HOME_DIR") "/.cache"))
|
|
10162
10313
|
(literal (string-append (param "HOME_DIR") "/.gitconfig"))
|
|
@@ -10330,6 +10481,7 @@ var BUILTIN_SEATBELT_PROFILE_CONTENTS = {
|
|
|
10330
10481
|
(subpath (param "CACHE_DIR"))
|
|
10331
10482
|
(literal (string-append (param "HOME_DIR") "/.gemini/settings.json"))
|
|
10332
10483
|
(literal (string-append (param "HOME_DIR") "/.gemini/keybindings.json"))
|
|
10484
|
+
(literal (string-append (param "HOME_DIR") "/.gemini/theme.json"))
|
|
10333
10485
|
(subpath (string-append (param "HOME_DIR") "/.npm"))
|
|
10334
10486
|
(subpath (string-append (param "HOME_DIR") "/.cache"))
|
|
10335
10487
|
(literal (string-append (param "HOME_DIR") "/.gitconfig"))
|
|
@@ -11392,6 +11544,45 @@ function isRecord3(value) {
|
|
|
11392
11544
|
}
|
|
11393
11545
|
var execAsync = promisify(exec);
|
|
11394
11546
|
var execFileAsync = promisify(execFile);
|
|
11547
|
+
var PODMAN_INFO_TIMEOUT_MS = 5e3;
|
|
11548
|
+
async function isPodmanRootless() {
|
|
11549
|
+
const formats = [
|
|
11550
|
+
"{{.Host.Security.Rootless}}",
|
|
11551
|
+
"{{.Host.ServiceIsRootless}}"
|
|
11552
|
+
];
|
|
11553
|
+
for (const format3 of formats) {
|
|
11554
|
+
try {
|
|
11555
|
+
const { stdout } = await execFileAsync(
|
|
11556
|
+
"podman",
|
|
11557
|
+
["info", "--format", format3],
|
|
11558
|
+
{
|
|
11559
|
+
encoding: "utf-8",
|
|
11560
|
+
timeout: PODMAN_INFO_TIMEOUT_MS,
|
|
11561
|
+
killSignal: "SIGKILL"
|
|
11562
|
+
}
|
|
11563
|
+
);
|
|
11564
|
+
const trimmed = String(stdout ?? "").trim().toLowerCase();
|
|
11565
|
+
if (trimmed === "true") {
|
|
11566
|
+
return true;
|
|
11567
|
+
}
|
|
11568
|
+
if (trimmed === "false") {
|
|
11569
|
+
return false;
|
|
11570
|
+
}
|
|
11571
|
+
} catch (err) {
|
|
11572
|
+
const isMissingBinary = isNodeError(err) && err.code === "ENOENT";
|
|
11573
|
+
const timedOut = isRecord3(err) && err["killed"] === true;
|
|
11574
|
+
if (isMissingBinary || timedOut) {
|
|
11575
|
+
break;
|
|
11576
|
+
}
|
|
11577
|
+
}
|
|
11578
|
+
}
|
|
11579
|
+
return false;
|
|
11580
|
+
}
|
|
11581
|
+
function hasUsernsFlag(flags) {
|
|
11582
|
+
return flags.some(
|
|
11583
|
+
(flag) => flag === "--userns" || flag.startsWith("--userns=")
|
|
11584
|
+
);
|
|
11585
|
+
}
|
|
11395
11586
|
async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs = []) {
|
|
11396
11587
|
const patcher = new ConsolePatcher({
|
|
11397
11588
|
debugMode: cliConfig?.getDebugMode() || !!process.env["DEBUG"],
|
|
@@ -11730,12 +11921,10 @@ async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs = []) {
|
|
|
11730
11921
|
if (config.command === "runsc") {
|
|
11731
11922
|
args.push("--runtime=runsc");
|
|
11732
11923
|
}
|
|
11733
|
-
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
args.push(...flags);
|
|
11738
|
-
}
|
|
11924
|
+
const customFlags = process.env["SANDBOX_FLAGS"] ? (0, import_shell_quote2.parse)(process.env["SANDBOX_FLAGS"], process.env).filter(
|
|
11925
|
+
(f) => typeof f === "string"
|
|
11926
|
+
) : [];
|
|
11927
|
+
args.push(...customFlags);
|
|
11739
11928
|
if (process.stdin.isTTY) {
|
|
11740
11929
|
args.push("-t");
|
|
11741
11930
|
}
|
|
@@ -12048,6 +12237,9 @@ async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs = []) {
|
|
|
12048
12237
|
userFlag = "--user root";
|
|
12049
12238
|
} else if (await shouldUseCurrentUserInSandbox()) {
|
|
12050
12239
|
args.push("--user", "root");
|
|
12240
|
+
if (command2 === "podman" && !hasUsernsFlag(customFlags) && await isPodmanRootless()) {
|
|
12241
|
+
args.push("--userns=keep-id");
|
|
12242
|
+
}
|
|
12051
12243
|
const uid = (await execAsync("id -u")).stdout.trim();
|
|
12052
12244
|
const gid = (await execAsync("id -g")).stdout.trim();
|
|
12053
12245
|
const username = "gemini";
|
|
@@ -12491,6 +12683,159 @@ async function ensureSandboxImageIsPresent(sandbox, image, cliConfig) {
|
|
|
12491
12683
|
return false;
|
|
12492
12684
|
}
|
|
12493
12685
|
|
|
12686
|
+
// packages/cli/src/utils/sandboxFolderTrust.ts
|
|
12687
|
+
import * as path11 from "node:path";
|
|
12688
|
+
import * as readline2 from "node:readline";
|
|
12689
|
+
import { Writable } from "node:stream";
|
|
12690
|
+
var TRUST_WORKSPACE_ENV = "GEMINI_CLI_TRUST_WORKSPACE";
|
|
12691
|
+
function parseTrustChoice(answer) {
|
|
12692
|
+
switch (answer.trim()) {
|
|
12693
|
+
case "1":
|
|
12694
|
+
return TrustLevel.TRUST_FOLDER;
|
|
12695
|
+
case "2":
|
|
12696
|
+
return TrustLevel.TRUST_PARENT;
|
|
12697
|
+
case "3":
|
|
12698
|
+
return TrustLevel.DO_NOT_TRUST;
|
|
12699
|
+
default:
|
|
12700
|
+
return void 0;
|
|
12701
|
+
}
|
|
12702
|
+
}
|
|
12703
|
+
async function resolveFolderTrustForSandbox({
|
|
12704
|
+
sandboxCommand,
|
|
12705
|
+
settings,
|
|
12706
|
+
interactive,
|
|
12707
|
+
workspaceDir = process.cwd(),
|
|
12708
|
+
promptForTrustLevel = promptForFolderTrustLevel
|
|
12709
|
+
}) {
|
|
12710
|
+
if (sandboxCommand !== "sandbox-exec") {
|
|
12711
|
+
return;
|
|
12712
|
+
}
|
|
12713
|
+
if (!isFolderTrustEnabled(settings.merged)) {
|
|
12714
|
+
return;
|
|
12715
|
+
}
|
|
12716
|
+
const trust = isWorkspaceTrusted(settings.merged, workspaceDir);
|
|
12717
|
+
if (trust.source === "env") {
|
|
12718
|
+
return;
|
|
12719
|
+
}
|
|
12720
|
+
let isTrusted = trust.isTrusted;
|
|
12721
|
+
if (isTrusted === void 0) {
|
|
12722
|
+
if (!interactive) {
|
|
12723
|
+
return;
|
|
12724
|
+
}
|
|
12725
|
+
const trustLevel = await promptForTrustLevel(workspaceDir);
|
|
12726
|
+
if (trustLevel === void 0) {
|
|
12727
|
+
throw new FatalCancellationError(
|
|
12728
|
+
"A folder trust level must be selected to continue."
|
|
12729
|
+
);
|
|
12730
|
+
}
|
|
12731
|
+
try {
|
|
12732
|
+
await loadTrustedFolders().setValue(workspaceDir, trustLevel);
|
|
12733
|
+
} catch {
|
|
12734
|
+
throw new FatalConfigError("Failed to save trust settings.");
|
|
12735
|
+
}
|
|
12736
|
+
isTrusted = trustLevel !== TrustLevel.DO_NOT_TRUST;
|
|
12737
|
+
}
|
|
12738
|
+
process.env[TRUST_WORKSPACE_ENV] = isTrusted ? "true" : "false";
|
|
12739
|
+
}
|
|
12740
|
+
function formatFolderTrustPrompt(workspaceDir, discoveryResults) {
|
|
12741
|
+
const folderName = stripAnsi(path11.basename(workspaceDir)).trim() || stripAnsi(workspaceDir);
|
|
12742
|
+
const parentDir = path11.dirname(workspaceDir);
|
|
12743
|
+
const parentFolderName = stripAnsi(path11.basename(parentDir)).trim() || stripAnsi(parentDir);
|
|
12744
|
+
const lines = [
|
|
12745
|
+
"",
|
|
12746
|
+
"Do you trust the files in this folder?",
|
|
12747
|
+
"",
|
|
12748
|
+
"Trusting a folder allows Gemini CLI to load its local configurations, including custom commands, hooks, MCP servers, agent skills, and settings. These configurations could execute code on your behalf or change the behavior of the CLI.",
|
|
12749
|
+
""
|
|
12750
|
+
];
|
|
12751
|
+
const appendSection = (title, items) => {
|
|
12752
|
+
if (items.length === 0) {
|
|
12753
|
+
return;
|
|
12754
|
+
}
|
|
12755
|
+
lines.push(title);
|
|
12756
|
+
for (const item of items) {
|
|
12757
|
+
lines.push(` \u2022 ${stripAnsi(item)}`);
|
|
12758
|
+
}
|
|
12759
|
+
lines.push("");
|
|
12760
|
+
};
|
|
12761
|
+
if (discoveryResults) {
|
|
12762
|
+
appendSection("Discovery Errors:", discoveryResults.discoveryErrors ?? []);
|
|
12763
|
+
appendSection(
|
|
12764
|
+
"Security Warnings:",
|
|
12765
|
+
discoveryResults.securityWarnings ?? []
|
|
12766
|
+
);
|
|
12767
|
+
const groups = [
|
|
12768
|
+
["Commands", discoveryResults.commands ?? []],
|
|
12769
|
+
["MCP Servers", discoveryResults.mcps ?? []],
|
|
12770
|
+
["Hooks", discoveryResults.hooks ?? []],
|
|
12771
|
+
["Skills", discoveryResults.skills ?? []],
|
|
12772
|
+
["Agents", discoveryResults.agents ?? []],
|
|
12773
|
+
["Setting overrides", discoveryResults.settings ?? []]
|
|
12774
|
+
];
|
|
12775
|
+
const nonEmptyGroups = groups.filter(([, items]) => items.length > 0);
|
|
12776
|
+
if (nonEmptyGroups.length > 0) {
|
|
12777
|
+
lines.push("This folder contains:");
|
|
12778
|
+
for (const [label, items] of nonEmptyGroups) {
|
|
12779
|
+
lines.push(` \u2022 ${label} (${items.length}):`);
|
|
12780
|
+
for (const item of items) {
|
|
12781
|
+
lines.push(` - ${stripAnsi(item)}`);
|
|
12782
|
+
}
|
|
12783
|
+
}
|
|
12784
|
+
lines.push("");
|
|
12785
|
+
}
|
|
12786
|
+
}
|
|
12787
|
+
lines.push(
|
|
12788
|
+
` 1. Trust folder (${folderName})`,
|
|
12789
|
+
` 2. Trust parent folder (${parentFolderName})`,
|
|
12790
|
+
" 3. Don't trust",
|
|
12791
|
+
"",
|
|
12792
|
+
"This choice is saved before Gemini CLI starts in the macOS Seatbelt sandbox.",
|
|
12793
|
+
""
|
|
12794
|
+
);
|
|
12795
|
+
return lines.join("\n");
|
|
12796
|
+
}
|
|
12797
|
+
function createTerminalOutput() {
|
|
12798
|
+
return new Writable({
|
|
12799
|
+
decodeStrings: false,
|
|
12800
|
+
write(chunk, _encoding, callback) {
|
|
12801
|
+
writeToStdout(chunk);
|
|
12802
|
+
callback();
|
|
12803
|
+
}
|
|
12804
|
+
});
|
|
12805
|
+
}
|
|
12806
|
+
async function promptForFolderTrustLevel(workspaceDir, input = process.stdin, output = createTerminalOutput()) {
|
|
12807
|
+
let discoveryResults;
|
|
12808
|
+
try {
|
|
12809
|
+
discoveryResults = await FolderTrustDiscoveryService.discover(workspaceDir);
|
|
12810
|
+
} catch {
|
|
12811
|
+
}
|
|
12812
|
+
output.write(formatFolderTrustPrompt(workspaceDir, discoveryResults));
|
|
12813
|
+
return new Promise((resolve10) => {
|
|
12814
|
+
const rl = readline2.createInterface({ input, output, terminal: false });
|
|
12815
|
+
let settled = false;
|
|
12816
|
+
const finish = (trustLevel) => {
|
|
12817
|
+
if (settled) {
|
|
12818
|
+
return;
|
|
12819
|
+
}
|
|
12820
|
+
settled = true;
|
|
12821
|
+
rl.close();
|
|
12822
|
+
resolve10(trustLevel);
|
|
12823
|
+
};
|
|
12824
|
+
rl.on("line", (line) => {
|
|
12825
|
+
const trustLevel = parseTrustChoice(line);
|
|
12826
|
+
if (trustLevel) {
|
|
12827
|
+
finish(trustLevel);
|
|
12828
|
+
return;
|
|
12829
|
+
}
|
|
12830
|
+
output.write("Enter 1, 2, or 3.\n");
|
|
12831
|
+
rl.prompt();
|
|
12832
|
+
});
|
|
12833
|
+
rl.on("close", () => finish(void 0));
|
|
12834
|
+
rl.setPrompt("Select an option [1-3]: ");
|
|
12835
|
+
rl.prompt();
|
|
12836
|
+
});
|
|
12837
|
+
}
|
|
12838
|
+
|
|
12494
12839
|
// packages/cli/src/utils/startupWarnings.ts
|
|
12495
12840
|
import fs8 from "node:fs/promises";
|
|
12496
12841
|
import os4 from "node:os";
|
|
@@ -12518,7 +12863,7 @@ async function getStartupWarnings() {
|
|
|
12518
12863
|
// packages/cli/src/utils/userStartupWarnings.ts
|
|
12519
12864
|
import fs9 from "node:fs/promises";
|
|
12520
12865
|
import { homedir as osHomedir } from "node:os";
|
|
12521
|
-
import
|
|
12866
|
+
import path12 from "node:path";
|
|
12522
12867
|
import process5 from "node:process";
|
|
12523
12868
|
var homeDirectoryCheck = {
|
|
12524
12869
|
id: "home-directory",
|
|
@@ -12532,7 +12877,7 @@ var homeDirectoryCheck = {
|
|
|
12532
12877
|
fs9.realpath(workspaceRoot),
|
|
12533
12878
|
fs9.realpath(osHomedir())
|
|
12534
12879
|
]);
|
|
12535
|
-
if (
|
|
12880
|
+
if (path12.resolve(workspaceRealPath) === path12.resolve(homeRealPath)) {
|
|
12536
12881
|
if (isFolderTrustEnabled(settings) && isWorkspaceTrusted(settings).isTrusted) {
|
|
12537
12882
|
return null;
|
|
12538
12883
|
}
|
|
@@ -12551,7 +12896,7 @@ var rootDirectoryCheck = {
|
|
|
12551
12896
|
try {
|
|
12552
12897
|
const workspaceRealPath = await fs9.realpath(workspaceRoot);
|
|
12553
12898
|
const errorMessage = "Warning: You are running Gemini CLI in the root directory. Your entire folder structure will be used for context. It is strongly recommended to run in a project-specific directory.";
|
|
12554
|
-
if (
|
|
12899
|
+
if (path12.dirname(workspaceRealPath) === workspaceRealPath) {
|
|
12555
12900
|
return errorMessage;
|
|
12556
12901
|
}
|
|
12557
12902
|
return null;
|
|
@@ -12610,7 +12955,7 @@ async function getUserStartupWarnings(settings, workspaceRoot = process5.cwd(),
|
|
|
12610
12955
|
}
|
|
12611
12956
|
|
|
12612
12957
|
// packages/cli/src/nonInteractiveCli.ts
|
|
12613
|
-
import
|
|
12958
|
+
import readline4 from "node:readline";
|
|
12614
12959
|
|
|
12615
12960
|
// packages/cli/src/ui/noninteractive/nonInteractiveUi.ts
|
|
12616
12961
|
function createNonInteractiveUI() {
|
|
@@ -12817,8 +13162,11 @@ function handleToolError(toolName, toolError, config, errorType, resultDisplay)
|
|
|
12817
13162
|
}
|
|
12818
13163
|
debugLogger.warn(errorMessage);
|
|
12819
13164
|
}
|
|
12820
|
-
function handleCancellationError(config) {
|
|
12821
|
-
const cancellationError = new FatalCancellationError(
|
|
13165
|
+
function handleCancellationError(config, exitCode = 130) {
|
|
13166
|
+
const cancellationError = new FatalCancellationError(
|
|
13167
|
+
"Operation cancelled.",
|
|
13168
|
+
exitCode
|
|
13169
|
+
);
|
|
12822
13170
|
if (config.getOutputFormat() === OutputFormat.STREAM_JSON) {
|
|
12823
13171
|
const streamFormatter = new StreamJsonFormatter();
|
|
12824
13172
|
const metrics = uiTelemetryService.getMetrics();
|
|
@@ -12934,7 +13282,7 @@ var TextOutput = class {
|
|
|
12934
13282
|
};
|
|
12935
13283
|
|
|
12936
13284
|
// packages/cli/src/nonInteractiveCliAgentSession.ts
|
|
12937
|
-
import
|
|
13285
|
+
import readline3 from "node:readline";
|
|
12938
13286
|
async function runNonInteractive({
|
|
12939
13287
|
config,
|
|
12940
13288
|
settings,
|
|
@@ -12952,7 +13300,7 @@ async function runNonInteractive({
|
|
|
12952
13300
|
}
|
|
12953
13301
|
});
|
|
12954
13302
|
if (process.env["GEMINI_CLI_ACTIVITY_LOG_TARGET"]) {
|
|
12955
|
-
const { setupInitialActivityLogger } = await import("./devtoolsService-
|
|
13303
|
+
const { setupInitialActivityLogger } = await import("./devtoolsService-I7WFRUEA.js");
|
|
12956
13304
|
setupInitialActivityLogger(config);
|
|
12957
13305
|
}
|
|
12958
13306
|
const { stdout: workingStdout } = createWorkingStdio();
|
|
@@ -12983,9 +13331,17 @@ async function runNonInteractive({
|
|
|
12983
13331
|
}
|
|
12984
13332
|
throw err;
|
|
12985
13333
|
};
|
|
12986
|
-
|
|
13334
|
+
let abortExitCode = 130;
|
|
13335
|
+
const triggerAbort = (signal) => {
|
|
13336
|
+
if (signal === "SIGTERM") {
|
|
13337
|
+
abortExitCode = 143;
|
|
13338
|
+
} else if (signal === "SIGHUP") {
|
|
13339
|
+
abortExitCode = 129;
|
|
13340
|
+
} else {
|
|
13341
|
+
abortExitCode = 130;
|
|
13342
|
+
}
|
|
12987
13343
|
if (isAborting) {
|
|
12988
|
-
process.exit(
|
|
13344
|
+
process.exit(abortExitCode);
|
|
12989
13345
|
}
|
|
12990
13346
|
isAborting = true;
|
|
12991
13347
|
cancelMessageTimer = setTimeout(() => {
|
|
@@ -12993,30 +13349,35 @@ async function runNonInteractive({
|
|
|
12993
13349
|
}, 200);
|
|
12994
13350
|
abortController.abort();
|
|
12995
13351
|
};
|
|
13352
|
+
const onSigint = () => triggerAbort("SIGINT");
|
|
13353
|
+
const onSigterm = () => triggerAbort("SIGTERM");
|
|
13354
|
+
const onSighup = () => triggerAbort("SIGHUP");
|
|
12996
13355
|
const setupCancellation = () => {
|
|
12997
|
-
process.on("SIGINT",
|
|
12998
|
-
process.on("SIGTERM",
|
|
13356
|
+
process.on("SIGINT", onSigint);
|
|
13357
|
+
process.on("SIGTERM", onSigterm);
|
|
13358
|
+
process.on("SIGHUP", onSighup);
|
|
12999
13359
|
if (!process.stdin?.isTTY) {
|
|
13000
13360
|
return;
|
|
13001
13361
|
}
|
|
13002
13362
|
stdinWasRaw = process.stdin.isRaw || false;
|
|
13003
13363
|
process.stdin.setRawMode(true);
|
|
13004
13364
|
process.stdin.resume();
|
|
13005
|
-
rl =
|
|
13365
|
+
rl = readline3.createInterface({
|
|
13006
13366
|
input: process.stdin,
|
|
13007
13367
|
escapeCodeTimeout: 0
|
|
13008
13368
|
});
|
|
13009
|
-
|
|
13369
|
+
readline3.emitKeypressEvents(process.stdin, rl);
|
|
13010
13370
|
keypressHandler = (str, key) => {
|
|
13011
13371
|
if (key && key.ctrl && key.name === "c" || str === "") {
|
|
13012
|
-
triggerAbort();
|
|
13372
|
+
triggerAbort("SIGINT");
|
|
13013
13373
|
}
|
|
13014
13374
|
};
|
|
13015
13375
|
process.stdin.on("keypress", keypressHandler);
|
|
13016
13376
|
};
|
|
13017
13377
|
const cleanupCancellation = () => {
|
|
13018
|
-
process.off("SIGINT",
|
|
13019
|
-
process.off("SIGTERM",
|
|
13378
|
+
process.off("SIGINT", onSigint);
|
|
13379
|
+
process.off("SIGTERM", onSigterm);
|
|
13380
|
+
process.off("SIGHUP", onSighup);
|
|
13020
13381
|
process.stdout.off("error", handleStdoutError);
|
|
13021
13382
|
if (cancelMessageTimer) {
|
|
13022
13383
|
clearTimeout(cancelMessageTimer);
|
|
@@ -13122,7 +13483,7 @@ async function runNonInteractive({
|
|
|
13122
13483
|
};
|
|
13123
13484
|
abortController.signal.addEventListener("abort", abortSession);
|
|
13124
13485
|
if (abortController.signal.aborted) {
|
|
13125
|
-
throw new FatalCancellationError("Operation cancelled.");
|
|
13486
|
+
throw new FatalCancellationError("Operation cancelled.", abortExitCode);
|
|
13126
13487
|
}
|
|
13127
13488
|
const { streamId } = await session.send({
|
|
13128
13489
|
message: {
|
|
@@ -13168,64 +13529,63 @@ async function runNonInteractive({
|
|
|
13168
13529
|
const reconstructFatalError = (event) => {
|
|
13169
13530
|
const errorMeta = event._meta;
|
|
13170
13531
|
const name = typeof errorMeta?.["errorName"] === "string" ? errorMeta["errorName"] : void 0;
|
|
13532
|
+
const rawError = errorMeta?.["rawError"];
|
|
13533
|
+
const normalized = normalizeError(
|
|
13534
|
+
rawError ?? {
|
|
13535
|
+
message: event.message,
|
|
13536
|
+
status: errorMeta?.["status"],
|
|
13537
|
+
code: errorMeta?.["code"]
|
|
13538
|
+
}
|
|
13539
|
+
);
|
|
13540
|
+
const code = normalized.code ?? (typeof normalized.status === "string" ? normalized.status : void 0);
|
|
13171
13541
|
let errToThrow;
|
|
13172
13542
|
switch (name) {
|
|
13173
13543
|
case "FatalAuthenticationError":
|
|
13174
|
-
errToThrow = new FatalAuthenticationError(
|
|
13544
|
+
errToThrow = new FatalAuthenticationError(normalized.message);
|
|
13175
13545
|
break;
|
|
13176
13546
|
case "FatalInputError":
|
|
13177
|
-
errToThrow = new FatalInputError(
|
|
13547
|
+
errToThrow = new FatalInputError(normalized.message);
|
|
13178
13548
|
break;
|
|
13179
13549
|
case "FatalSandboxError":
|
|
13180
|
-
errToThrow = new FatalSandboxError(
|
|
13550
|
+
errToThrow = new FatalSandboxError(normalized.message);
|
|
13181
13551
|
break;
|
|
13182
13552
|
case "FatalConfigError":
|
|
13183
|
-
errToThrow = new FatalConfigError(
|
|
13553
|
+
errToThrow = new FatalConfigError(normalized.message);
|
|
13184
13554
|
break;
|
|
13185
13555
|
case "FatalTurnLimitedError":
|
|
13186
|
-
errToThrow = new FatalTurnLimitedError(
|
|
13556
|
+
errToThrow = new FatalTurnLimitedError(normalized.message);
|
|
13187
13557
|
break;
|
|
13188
13558
|
case "FatalToolExecutionError":
|
|
13189
|
-
errToThrow = new FatalToolExecutionError(
|
|
13559
|
+
errToThrow = new FatalToolExecutionError(normalized.message);
|
|
13190
13560
|
break;
|
|
13191
13561
|
case "FatalCancellationError":
|
|
13192
|
-
errToThrow = new FatalCancellationError(
|
|
13562
|
+
errToThrow = new FatalCancellationError(
|
|
13563
|
+
normalized.message,
|
|
13564
|
+
abortExitCode
|
|
13565
|
+
);
|
|
13193
13566
|
break;
|
|
13194
13567
|
case "FatalError":
|
|
13195
13568
|
errToThrow = new FatalError(
|
|
13196
|
-
|
|
13569
|
+
normalized.message,
|
|
13197
13570
|
typeof errorMeta?.["exitCode"] === "number" ? errorMeta["exitCode"] : 1
|
|
13198
13571
|
);
|
|
13199
13572
|
break;
|
|
13200
13573
|
default:
|
|
13201
|
-
errToThrow =
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
|
|
13206
|
-
}
|
|
13207
|
-
|
|
13574
|
+
errToThrow = Object.assign(
|
|
13575
|
+
new Error(
|
|
13576
|
+
normalized.message,
|
|
13577
|
+
rawError !== void 0 ? { cause: rawError } : void 0
|
|
13578
|
+
),
|
|
13579
|
+
name ? { name } : {}
|
|
13580
|
+
);
|
|
13208
13581
|
break;
|
|
13209
13582
|
}
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
}
|
|
13215
|
-
}
|
|
13216
|
-
if (errorMeta?.["code"] !== void 0) {
|
|
13217
|
-
Object.defineProperty(errToThrow, "code", {
|
|
13218
|
-
value: errorMeta["code"],
|
|
13219
|
-
enumerable: true
|
|
13220
|
-
});
|
|
13221
|
-
}
|
|
13222
|
-
if (errorMeta?.["status"] !== void 0) {
|
|
13223
|
-
Object.defineProperty(errToThrow, "status", {
|
|
13224
|
-
value: errorMeta["status"],
|
|
13225
|
-
enumerable: true
|
|
13226
|
-
});
|
|
13227
|
-
}
|
|
13228
|
-
return errToThrow;
|
|
13583
|
+
return Object.assign(errToThrow, {
|
|
13584
|
+
...errorMeta?.["exitCode"] !== void 0 ? { exitCode: errorMeta["exitCode"] } : {},
|
|
13585
|
+
...typeof normalized.status === "number" ? { status: normalized.status } : {},
|
|
13586
|
+
...code !== void 0 ? { code } : {},
|
|
13587
|
+
...normalized.details !== void 0 ? { details: normalized.details } : {}
|
|
13588
|
+
});
|
|
13229
13589
|
};
|
|
13230
13590
|
let responseText = "";
|
|
13231
13591
|
let preToolResponseText;
|
|
@@ -13452,7 +13812,8 @@ async function runNonInteractive({
|
|
|
13452
13812
|
await runExitCleanup();
|
|
13453
13813
|
}
|
|
13454
13814
|
if (abortController.signal.aborted || isFatalCancellationError(errorToHandle)) {
|
|
13455
|
-
|
|
13815
|
+
const exitCode = isFatalCancellationError(errorToHandle) ? errorToHandle.exitCode : abortExitCode;
|
|
13816
|
+
handleCancellationError(config, exitCode);
|
|
13456
13817
|
}
|
|
13457
13818
|
if (errorToHandle) {
|
|
13458
13819
|
handleError(errorToHandle, config);
|
|
@@ -13480,7 +13841,7 @@ async function runNonInteractive2(params) {
|
|
|
13480
13841
|
}
|
|
13481
13842
|
});
|
|
13482
13843
|
if (process.env["GEMINI_CLI_ACTIVITY_LOG_TARGET"]) {
|
|
13483
|
-
const { setupInitialActivityLogger } = await import("./devtoolsService-
|
|
13844
|
+
const { setupInitialActivityLogger } = await import("./devtoolsService-I7WFRUEA.js");
|
|
13484
13845
|
setupInitialActivityLogger(config);
|
|
13485
13846
|
}
|
|
13486
13847
|
const { stdout: workingStdout } = createWorkingStdio();
|
|
@@ -13511,9 +13872,17 @@ async function runNonInteractive2(params) {
|
|
|
13511
13872
|
}
|
|
13512
13873
|
throw err;
|
|
13513
13874
|
};
|
|
13514
|
-
|
|
13875
|
+
let abortExitCode = 130;
|
|
13876
|
+
const triggerAbort = (signal) => {
|
|
13877
|
+
if (signal === "SIGTERM") {
|
|
13878
|
+
abortExitCode = 143;
|
|
13879
|
+
} else if (signal === "SIGHUP") {
|
|
13880
|
+
abortExitCode = 129;
|
|
13881
|
+
} else {
|
|
13882
|
+
abortExitCode = 130;
|
|
13883
|
+
}
|
|
13515
13884
|
if (isAborting) {
|
|
13516
|
-
process.exit(
|
|
13885
|
+
process.exit(abortExitCode);
|
|
13517
13886
|
}
|
|
13518
13887
|
isAborting = true;
|
|
13519
13888
|
cancelMessageTimer = setTimeout(() => {
|
|
@@ -13521,30 +13890,35 @@ async function runNonInteractive2(params) {
|
|
|
13521
13890
|
}, 200);
|
|
13522
13891
|
abortController.abort();
|
|
13523
13892
|
};
|
|
13893
|
+
const handleSigInt = () => triggerAbort("SIGINT");
|
|
13894
|
+
const handleSigTerm = () => triggerAbort("SIGTERM");
|
|
13895
|
+
const handleSigHup = () => triggerAbort("SIGHUP");
|
|
13524
13896
|
const setupCancellation = () => {
|
|
13525
|
-
process.on("SIGINT",
|
|
13526
|
-
process.on("SIGTERM",
|
|
13897
|
+
process.on("SIGINT", handleSigInt);
|
|
13898
|
+
process.on("SIGTERM", handleSigTerm);
|
|
13899
|
+
process.on("SIGHUP", handleSigHup);
|
|
13527
13900
|
if (!process.stdin?.isTTY) {
|
|
13528
13901
|
return;
|
|
13529
13902
|
}
|
|
13530
13903
|
stdinWasRaw = process.stdin.isRaw || false;
|
|
13531
13904
|
process.stdin.setRawMode(true);
|
|
13532
13905
|
process.stdin.resume();
|
|
13533
|
-
rl =
|
|
13906
|
+
rl = readline4.createInterface({
|
|
13534
13907
|
input: process.stdin,
|
|
13535
13908
|
escapeCodeTimeout: 0
|
|
13536
13909
|
});
|
|
13537
|
-
|
|
13910
|
+
readline4.emitKeypressEvents(process.stdin, rl);
|
|
13538
13911
|
keypressHandler = (str, key) => {
|
|
13539
13912
|
if (key && key.ctrl && key.name === "c" || str === "") {
|
|
13540
|
-
triggerAbort();
|
|
13913
|
+
triggerAbort("SIGINT");
|
|
13541
13914
|
}
|
|
13542
13915
|
};
|
|
13543
13916
|
process.stdin.on("keypress", keypressHandler);
|
|
13544
13917
|
};
|
|
13545
13918
|
const cleanupCancellation = () => {
|
|
13546
|
-
process.off("SIGINT",
|
|
13547
|
-
process.off("SIGTERM",
|
|
13919
|
+
process.off("SIGINT", handleSigInt);
|
|
13920
|
+
process.off("SIGTERM", handleSigTerm);
|
|
13921
|
+
process.off("SIGHUP", handleSigHup);
|
|
13548
13922
|
process.stdout.off("error", handleStdoutError);
|
|
13549
13923
|
if (cancelMessageTimer) {
|
|
13550
13924
|
clearTimeout(cancelMessageTimer);
|
|
@@ -13657,7 +14031,7 @@ async function runNonInteractive2(params) {
|
|
|
13657
14031
|
let responseText = "";
|
|
13658
14032
|
for await (const event of responseStream) {
|
|
13659
14033
|
if (abortController.signal.aborted) {
|
|
13660
|
-
handleCancellationError(config);
|
|
14034
|
+
handleCancellationError(config, abortExitCode);
|
|
13661
14035
|
}
|
|
13662
14036
|
if (event.type === GeminiEventType.Content) {
|
|
13663
14037
|
const isRaw = config.getRawOutput() || config.getAcceptRawOutputRisk();
|
|
@@ -13711,7 +14085,20 @@ async function runNonInteractive2(params) {
|
|
|
13711
14085
|
}
|
|
13712
14086
|
warnings.push(message);
|
|
13713
14087
|
} else if (event.type === GeminiEventType.Error) {
|
|
13714
|
-
|
|
14088
|
+
const normalized = normalizeError(event.value?.error);
|
|
14089
|
+
const code = normalized.code ?? (typeof normalized.status === "string" ? normalized.status : void 0);
|
|
14090
|
+
const err = Object.assign(
|
|
14091
|
+
new Error(
|
|
14092
|
+
normalized.message,
|
|
14093
|
+
normalized.originalError !== void 0 ? { cause: normalized.originalError } : void 0
|
|
14094
|
+
),
|
|
14095
|
+
{
|
|
14096
|
+
...typeof normalized.status === "number" ? { status: normalized.status } : {},
|
|
14097
|
+
...code !== void 0 ? { code } : {},
|
|
14098
|
+
...normalized.details !== void 0 ? { details: normalized.details } : {}
|
|
14099
|
+
}
|
|
14100
|
+
);
|
|
14101
|
+
throw err;
|
|
13715
14102
|
} else if (event.type === GeminiEventType.AgentExecutionStopped) {
|
|
13716
14103
|
const stopMessage = `Agent execution stopped: ${event.value.systemMessage?.trim() || event.value.reason}`;
|
|
13717
14104
|
if (config.getOutputFormat() === OutputFormat.TEXT) {
|
|
@@ -13800,13 +14187,27 @@ async function runNonInteractive2(params) {
|
|
|
13800
14187
|
}
|
|
13801
14188
|
if (toolCallRequests.length > 0) {
|
|
13802
14189
|
if (abortController.signal.aborted) {
|
|
13803
|
-
throw new FatalCancellationError(
|
|
14190
|
+
throw new FatalCancellationError(
|
|
14191
|
+
"Operation cancelled.",
|
|
14192
|
+
abortExitCode
|
|
14193
|
+
);
|
|
13804
14194
|
}
|
|
13805
14195
|
textOutput.ensureTrailingNewline();
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
14196
|
+
let completedToolCalls;
|
|
14197
|
+
try {
|
|
14198
|
+
completedToolCalls = await scheduler.schedule(
|
|
14199
|
+
toolCallRequests,
|
|
14200
|
+
abortController.signal
|
|
14201
|
+
);
|
|
14202
|
+
} catch (scheduleError) {
|
|
14203
|
+
if (abortController.signal.aborted) {
|
|
14204
|
+
throw new FatalCancellationError(
|
|
14205
|
+
"Operation cancelled.",
|
|
14206
|
+
abortExitCode
|
|
14207
|
+
);
|
|
14208
|
+
}
|
|
14209
|
+
throw scheduleError;
|
|
14210
|
+
}
|
|
13810
14211
|
const toolResponseParts = [];
|
|
13811
14212
|
for (const completedToolCall of completedToolCalls) {
|
|
13812
14213
|
const toolResponse = completedToolCall.response;
|
|
@@ -13884,6 +14285,12 @@ async function runNonInteractive2(params) {
|
|
|
13884
14285
|
}
|
|
13885
14286
|
return;
|
|
13886
14287
|
}
|
|
14288
|
+
if (abortController.signal.aborted) {
|
|
14289
|
+
throw new FatalCancellationError(
|
|
14290
|
+
"Operation cancelled.",
|
|
14291
|
+
abortExitCode
|
|
14292
|
+
);
|
|
14293
|
+
}
|
|
13887
14294
|
currentMessages = [{ role: "user", parts: toolResponseParts }];
|
|
13888
14295
|
} else {
|
|
13889
14296
|
if (streamFormatter) {
|
|
@@ -13923,7 +14330,8 @@ async function runNonInteractive2(params) {
|
|
|
13923
14330
|
await runExitCleanup();
|
|
13924
14331
|
}
|
|
13925
14332
|
if (abortController.signal.aborted || isFatalCancellationError(errorToHandle)) {
|
|
13926
|
-
|
|
14333
|
+
const exitCode = isFatalCancellationError(errorToHandle) ? errorToHandle.exitCode : abortExitCode;
|
|
14334
|
+
handleCancellationError(config, exitCode);
|
|
13927
14335
|
}
|
|
13928
14336
|
if (errorToHandle) {
|
|
13929
14337
|
handleError(errorToHandle, config);
|
|
@@ -15469,7 +15877,7 @@ var RequestError = class _RequestError extends Error {
|
|
|
15469
15877
|
};
|
|
15470
15878
|
|
|
15471
15879
|
// packages/cli/src/acp/acpStdioTransport.ts
|
|
15472
|
-
import { Readable, Writable } from "node:stream";
|
|
15880
|
+
import { Readable, Writable as Writable2 } from "node:stream";
|
|
15473
15881
|
|
|
15474
15882
|
// packages/cli/src/acp/acpErrors.ts
|
|
15475
15883
|
function getAcpErrorMessage(error) {
|
|
@@ -15496,7 +15904,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
15496
15904
|
|
|
15497
15905
|
// packages/cli/src/acp/acpSession.ts
|
|
15498
15906
|
import * as fs12 from "node:fs/promises";
|
|
15499
|
-
import * as
|
|
15907
|
+
import * as path15 from "node:path";
|
|
15500
15908
|
import { randomUUID } from "node:crypto";
|
|
15501
15909
|
|
|
15502
15910
|
// packages/cli/src/acp/commands/commandRegistry.ts
|
|
@@ -15938,7 +16346,7 @@ var UpdateExtensionCommand = class {
|
|
|
15938
16346
|
|
|
15939
16347
|
// packages/cli/src/acp/commands/init.ts
|
|
15940
16348
|
import * as fs10 from "node:fs";
|
|
15941
|
-
import * as
|
|
16349
|
+
import * as path13 from "node:path";
|
|
15942
16350
|
var InitCommand = class {
|
|
15943
16351
|
name = "init";
|
|
15944
16352
|
description = "Analyzes the project and creates a tailored GEMINI.md file";
|
|
@@ -15948,7 +16356,7 @@ var InitCommand = class {
|
|
|
15948
16356
|
if (!targetDir) {
|
|
15949
16357
|
throw new Error("Command requires a workspace.");
|
|
15950
16358
|
}
|
|
15951
|
-
const geminiMdPath =
|
|
16359
|
+
const geminiMdPath = path13.join(targetDir, "GEMINI.md");
|
|
15952
16360
|
const result = performInit(fs10.existsSync(geminiMdPath));
|
|
15953
16361
|
switch (result.type) {
|
|
15954
16362
|
case "message":
|
|
@@ -15981,7 +16389,7 @@ ${result.content}`
|
|
|
15981
16389
|
|
|
15982
16390
|
// packages/cli/src/acp/commands/restore.ts
|
|
15983
16391
|
import * as fs11 from "node:fs/promises";
|
|
15984
|
-
import * as
|
|
16392
|
+
import * as path14 from "node:path";
|
|
15985
16393
|
var RestoreCommand = class {
|
|
15986
16394
|
name = "restore";
|
|
15987
16395
|
description = "Restore to a previous checkpoint, or list available checkpoints to restore. This will reset the conversation and file history to the state it was in when the checkpoint was created";
|
|
@@ -16003,7 +16411,7 @@ var RestoreCommand = class {
|
|
|
16003
16411
|
}
|
|
16004
16412
|
const selectedFile = argsStr.endsWith(".json") ? argsStr : `${argsStr}.json`;
|
|
16005
16413
|
const checkpointDir = config.storage.getProjectTempCheckpointsDir();
|
|
16006
|
-
const filePath =
|
|
16414
|
+
const filePath = path14.join(checkpointDir, selectedFile);
|
|
16007
16415
|
let data;
|
|
16008
16416
|
try {
|
|
16009
16417
|
data = await fs11.readFile(filePath, "utf-8");
|
|
@@ -16077,7 +16485,7 @@ var ListCheckpointsCommand = class {
|
|
|
16077
16485
|
}
|
|
16078
16486
|
const checkpointFiles = /* @__PURE__ */ new Map();
|
|
16079
16487
|
for (const file of jsonFiles) {
|
|
16080
|
-
const filePath =
|
|
16488
|
+
const filePath = path14.join(checkpointDir, file);
|
|
16081
16489
|
const data = await fs11.readFile(filePath, "utf-8");
|
|
16082
16490
|
checkpointFiles.set(file, data);
|
|
16083
16491
|
}
|
|
@@ -16287,6 +16695,7 @@ var Session = class {
|
|
|
16287
16695
|
CoreEvent.ApprovalModeChanged,
|
|
16288
16696
|
this.handleApprovalModeChanged
|
|
16289
16697
|
);
|
|
16698
|
+
coreEvents.on(CoreEvent.RetryAttempt, this.handleRetryAttempt);
|
|
16290
16699
|
this.context.config.getMessageBus()?.subscribe(
|
|
16291
16700
|
MessageBusType.TOOL_CONFIRMATION_REQUEST,
|
|
16292
16701
|
this.handleToolConfirmationRequest,
|
|
@@ -16380,11 +16789,26 @@ var Session = class {
|
|
|
16380
16789
|
});
|
|
16381
16790
|
}
|
|
16382
16791
|
};
|
|
16792
|
+
handleRetryAttempt = (payload) => {
|
|
16793
|
+
if (payload.sessionId === this.id) {
|
|
16794
|
+
const delaySec = Math.max(1, Math.round(payload.delayMs / 1e3));
|
|
16795
|
+
this.sendUpdate({
|
|
16796
|
+
sessionUpdate: "agent_thought_chunk",
|
|
16797
|
+
content: {
|
|
16798
|
+
type: "text",
|
|
16799
|
+
text: `[Retry ${payload.attempt}/${payload.maxAttempts}] ${payload.error || "Request failed"}. Retrying in ${delaySec}s...`
|
|
16800
|
+
}
|
|
16801
|
+
}).catch((err) => {
|
|
16802
|
+
debugLogger.error(`Failed to send retry session update: ${err}`);
|
|
16803
|
+
});
|
|
16804
|
+
}
|
|
16805
|
+
};
|
|
16383
16806
|
async dispose() {
|
|
16384
16807
|
coreEvents.off(
|
|
16385
16808
|
CoreEvent.ApprovalModeChanged,
|
|
16386
16809
|
this.handleApprovalModeChanged
|
|
16387
16810
|
);
|
|
16811
|
+
coreEvents.off(CoreEvent.RetryAttempt, this.handleRetryAttempt);
|
|
16388
16812
|
this.disposeController.abort();
|
|
16389
16813
|
if (this.context.config?.dispose) {
|
|
16390
16814
|
try {
|
|
@@ -16561,6 +16985,7 @@ ${thought.description}`;
|
|
|
16561
16985
|
let currentParts = parts;
|
|
16562
16986
|
let turnCount = 0;
|
|
16563
16987
|
const maxTurns = this.context.config.getMaxSessionTurns();
|
|
16988
|
+
let isFirstChunkAfterRetry = false;
|
|
16564
16989
|
while (true) {
|
|
16565
16990
|
turnCount++;
|
|
16566
16991
|
if (maxTurns >= 0 && turnCount > maxTurns) {
|
|
@@ -16592,10 +17017,13 @@ ${thought.description}`;
|
|
|
16592
17017
|
type: "text",
|
|
16593
17018
|
text: event.value
|
|
16594
17019
|
};
|
|
16595
|
-
|
|
17020
|
+
const update = {
|
|
16596
17021
|
sessionUpdate: "agent_message_chunk",
|
|
16597
|
-
content
|
|
16598
|
-
|
|
17022
|
+
content,
|
|
17023
|
+
...isFirstChunkAfterRetry ? { _meta: { retry: true, reset: true } } : {}
|
|
17024
|
+
};
|
|
17025
|
+
isFirstChunkAfterRetry = false;
|
|
17026
|
+
await this.sendUpdate(update);
|
|
16599
17027
|
break;
|
|
16600
17028
|
}
|
|
16601
17029
|
case GeminiEventType.Thought: {
|
|
@@ -16607,6 +17035,22 @@ ${event.value.description}`;
|
|
|
16607
17035
|
});
|
|
16608
17036
|
break;
|
|
16609
17037
|
}
|
|
17038
|
+
case GeminiEventType.Retry: {
|
|
17039
|
+
toolCallRequests.length = 0;
|
|
17040
|
+
debugLogger.warn(
|
|
17041
|
+
"Model stream interrupted mid-response; retrying prompt..."
|
|
17042
|
+
);
|
|
17043
|
+
await this.sendUpdate({
|
|
17044
|
+
sessionUpdate: "agent_thought_chunk",
|
|
17045
|
+
content: {
|
|
17046
|
+
type: "text",
|
|
17047
|
+
text: "_[Stream interrupted. Retrying response...]_"
|
|
17048
|
+
},
|
|
17049
|
+
_meta: { retry: true }
|
|
17050
|
+
});
|
|
17051
|
+
isFirstChunkAfterRetry = true;
|
|
17052
|
+
break;
|
|
17053
|
+
}
|
|
16610
17054
|
case GeminiEventType.ToolCallRequest:
|
|
16611
17055
|
toolCallRequests.push(event.value);
|
|
16612
17056
|
break;
|
|
@@ -17078,7 +17522,7 @@ ${event.value.description}`;
|
|
|
17078
17522
|
} else if (result.status === "invalid") {
|
|
17079
17523
|
continue;
|
|
17080
17524
|
} else {
|
|
17081
|
-
absolutePath =
|
|
17525
|
+
absolutePath = path15.resolve(
|
|
17082
17526
|
this.context.config.getTargetDir(),
|
|
17083
17527
|
pathName
|
|
17084
17528
|
);
|
|
@@ -17152,7 +17596,7 @@ ${event.value.description}`;
|
|
|
17152
17596
|
}
|
|
17153
17597
|
try {
|
|
17154
17598
|
if (!validationError) {
|
|
17155
|
-
if ((
|
|
17599
|
+
if ((path15.isAbsolute(pathName) || !isWithinRoot(
|
|
17156
17600
|
absolutePath,
|
|
17157
17601
|
this.context.config.getTargetDir()
|
|
17158
17602
|
)) && !readDirectly) {
|
|
@@ -17250,7 +17694,7 @@ ${contentToPush}`;
|
|
|
17250
17694
|
const lines = globResult.llmContent.split("\n");
|
|
17251
17695
|
if (lines.length > 1 && lines[1]) {
|
|
17252
17696
|
const firstMatchAbsolute = lines[1].trim();
|
|
17253
|
-
currentPathSpec =
|
|
17697
|
+
currentPathSpec = path15.relative(
|
|
17254
17698
|
this.context.config.getTargetDir(),
|
|
17255
17699
|
firstMatchAbsolute
|
|
17256
17700
|
);
|
|
@@ -17375,13 +17819,15 @@ ${REFERENCE_CONTENT_START}`
|
|
|
17375
17819
|
const match = fileContentRegex.exec(part);
|
|
17376
17820
|
if (match) {
|
|
17377
17821
|
const filePathSpecInContent = match[1];
|
|
17378
|
-
const fileActualContent = match[2]
|
|
17822
|
+
const fileActualContent = match[2];
|
|
17379
17823
|
processedQueryParts.push({
|
|
17380
17824
|
text: `
|
|
17381
17825
|
Content from @${filePathSpecInContent}:
|
|
17382
17826
|
`
|
|
17383
17827
|
});
|
|
17384
|
-
|
|
17828
|
+
if (fileActualContent !== "") {
|
|
17829
|
+
processedQueryParts.push({ text: fileActualContent });
|
|
17830
|
+
}
|
|
17385
17831
|
} else {
|
|
17386
17832
|
processedQueryParts.push({ text: part });
|
|
17387
17833
|
}
|
|
@@ -17471,7 +17917,7 @@ Content from @${contextPart.uri}:
|
|
|
17471
17917
|
|
|
17472
17918
|
// packages/cli/src/acp/acpFileSystemService.ts
|
|
17473
17919
|
import os5 from "node:os";
|
|
17474
|
-
import
|
|
17920
|
+
import path16 from "node:path";
|
|
17475
17921
|
var AcpFileSystemService = class {
|
|
17476
17922
|
constructor(connection, sessionId, capabilities, fallback, root) {
|
|
17477
17923
|
this.connection = connection;
|
|
@@ -17480,7 +17926,7 @@ var AcpFileSystemService = class {
|
|
|
17480
17926
|
this.fallback = fallback;
|
|
17481
17927
|
this.root = root;
|
|
17482
17928
|
}
|
|
17483
|
-
geminiDir =
|
|
17929
|
+
geminiDir = path16.join(os5.homedir(), ".gemini");
|
|
17484
17930
|
shouldUseFallback(filePath) {
|
|
17485
17931
|
return !isWithinRoot(filePath, this.root) || isWithinRoot(filePath, this.geminiDir);
|
|
17486
17932
|
}
|
|
@@ -17730,9 +18176,11 @@ var AcpSessionManager = class {
|
|
|
17730
18176
|
currentModelId
|
|
17731
18177
|
}
|
|
17732
18178
|
};
|
|
17733
|
-
|
|
18179
|
+
try {
|
|
18180
|
+
await session.streamHistory(messages);
|
|
18181
|
+
} catch (err) {
|
|
17734
18182
|
debugLogger.error(`Error streaming history: ${err}`);
|
|
17735
|
-
}
|
|
18183
|
+
}
|
|
17736
18184
|
setTimeout(() => {
|
|
17737
18185
|
session?.sendAvailableCommands().catch((err) => {
|
|
17738
18186
|
debugLogger.error(`Error sending available commands: ${err}`);
|
|
@@ -18033,7 +18481,7 @@ var GeminiAgent = class {
|
|
|
18033
18481
|
// packages/cli/src/acp/acpStdioTransport.ts
|
|
18034
18482
|
async function runAcpClient(config, settings, argv) {
|
|
18035
18483
|
const { stdout: workingStdout } = createWorkingStdio();
|
|
18036
|
-
const stdout =
|
|
18484
|
+
const stdout = Writable2.toWeb(workingStdout);
|
|
18037
18485
|
const stdin = Readable.toWeb(process.stdin);
|
|
18038
18486
|
const stream = ndJsonStream(stdout, stdin);
|
|
18039
18487
|
const connection = new AgentSideConnection(
|
|
@@ -18179,6 +18627,7 @@ async function setupTerminalAndTheme(config, settings) {
|
|
|
18179
18627
|
terminalCapabilityManager.areAmbiguousCharactersWide()
|
|
18180
18628
|
);
|
|
18181
18629
|
}
|
|
18630
|
+
themeManager.loadUserThemes?.();
|
|
18182
18631
|
themeManager.loadCustomThemes(settings.merged.ui.customThemes);
|
|
18183
18632
|
if (settings.merged.ui.theme) {
|
|
18184
18633
|
if (!themeManager.setActiveTheme(settings.merged.ui.theme)) {
|
|
@@ -18212,7 +18661,7 @@ async function setupTerminalAndTheme(config, settings) {
|
|
|
18212
18661
|
|
|
18213
18662
|
// packages/cli/src/utils/logCleanup.ts
|
|
18214
18663
|
import { promises as fs13 } from "node:fs";
|
|
18215
|
-
import * as
|
|
18664
|
+
import * as path17 from "node:path";
|
|
18216
18665
|
var RETENTION_PERIOD_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
18217
18666
|
async function cleanupBackgroundLogs(debugMode = false) {
|
|
18218
18667
|
try {
|
|
@@ -18227,7 +18676,7 @@ async function cleanupBackgroundLogs(debugMode = false) {
|
|
|
18227
18676
|
let deletedCount = 0;
|
|
18228
18677
|
for (const entry of entries) {
|
|
18229
18678
|
if (entry.isFile() && entry.name.endsWith(".log")) {
|
|
18230
|
-
const filePath =
|
|
18679
|
+
const filePath = path17.join(logDir, entry.name);
|
|
18231
18680
|
try {
|
|
18232
18681
|
const stats = await fs13.stat(filePath);
|
|
18233
18682
|
if (now - stats.mtime.getTime() > RETENTION_PERIOD_MS) {
|
|
@@ -18572,8 +19021,8 @@ async function resolveSessionId(resumeArg, sessionIdArg, sessionFileArg) {
|
|
|
18572
19021
|
sessionData.projectHash = getProjectHash(storage.getProjectRoot());
|
|
18573
19022
|
sessionData.startTime = isoNow;
|
|
18574
19023
|
sessionData.lastUpdated = isoNow;
|
|
18575
|
-
const chatsDir =
|
|
18576
|
-
const newSessionPath =
|
|
19024
|
+
const chatsDir = path18.join(storage.getProjectTempDir(), "chats");
|
|
19025
|
+
const newSessionPath = path18.join(
|
|
18577
19026
|
chatsDir,
|
|
18578
19027
|
`session-${now}-${newSessionId.slice(0, 8)}.jsonl`
|
|
18579
19028
|
);
|
|
@@ -18641,7 +19090,7 @@ async function resolveSessionId(resumeArg, sessionIdArg, sessionFileArg) {
|
|
|
18641
19090
|
}
|
|
18642
19091
|
}
|
|
18643
19092
|
async function startInteractiveUI(config, settings, startupWarnings, workspaceRoot = process.cwd(), resumedSessionData, initializationResult) {
|
|
18644
|
-
const { startInteractiveUI: doStartUI } = await import("./interactiveCli-
|
|
19093
|
+
const { startInteractiveUI: doStartUI } = await import("./interactiveCli-5HMWVTK2.js");
|
|
18645
19094
|
await doStartUI(
|
|
18646
19095
|
config,
|
|
18647
19096
|
settings,
|
|
@@ -18760,6 +19209,7 @@ async function main() {
|
|
|
18760
19209
|
});
|
|
18761
19210
|
adminControlsListner.setConfig(partialConfig);
|
|
18762
19211
|
let initialAuthFailed = false;
|
|
19212
|
+
let initialAuthError = void 0;
|
|
18763
19213
|
if (!settings.merged.security.auth.useExternal && !argv.isCommand) {
|
|
18764
19214
|
try {
|
|
18765
19215
|
if (partialConfig.isInteractive() && settings.merged.security.auth.selectedType) {
|
|
@@ -18787,8 +19237,9 @@ async function main() {
|
|
|
18787
19237
|
process.exit(ExitCodes.SUCCESS);
|
|
18788
19238
|
}
|
|
18789
19239
|
if (!(err instanceof ValidationRequiredError)) {
|
|
18790
|
-
debugLogger.
|
|
19240
|
+
debugLogger.debug("Error authenticating:", err);
|
|
18791
19241
|
initialAuthFailed = true;
|
|
19242
|
+
initialAuthError = err;
|
|
18792
19243
|
}
|
|
18793
19244
|
}
|
|
18794
19245
|
}
|
|
@@ -18824,6 +19275,9 @@ async function main() {
|
|
|
18824
19275
|
const sandboxConfig = await loadSandboxConfig(settings.merged, argv);
|
|
18825
19276
|
if (sandboxConfig) {
|
|
18826
19277
|
if (initialAuthFailed) {
|
|
19278
|
+
writeToStderr(
|
|
19279
|
+
formatCliError(initialAuthError, { debug: isDebugMode2 }) + "\n"
|
|
19280
|
+
);
|
|
18827
19281
|
await runExitCleanup();
|
|
18828
19282
|
process.exit(ExitCodes.FATAL_AUTHENTICATION_ERROR);
|
|
18829
19283
|
}
|
|
@@ -18848,6 +19302,11 @@ ${finalArgs[promptIndex + 1]}`;
|
|
|
18848
19302
|
return finalArgs;
|
|
18849
19303
|
};
|
|
18850
19304
|
const sandboxArgs = injectStdinIntoArgs(process.argv, stdinData);
|
|
19305
|
+
await resolveFolderTrustForSandbox({
|
|
19306
|
+
sandboxCommand: sandboxConfig.command,
|
|
19307
|
+
settings,
|
|
19308
|
+
interactive: partialConfig.isInteractive() && !!process.stdin?.isTTY && !!process.stdout?.isTTY
|
|
19309
|
+
});
|
|
18851
19310
|
await relaunchOnExitCode(
|
|
18852
19311
|
() => start_sandbox(sandboxConfig, memoryArgs, partialConfig, sandboxArgs)
|
|
18853
19312
|
);
|
|
@@ -18866,7 +19325,7 @@ ${finalArgs[promptIndex + 1]}`;
|
|
|
18866
19325
|
await config.storage.initialize();
|
|
18867
19326
|
adminControlsListner.setConfig(config);
|
|
18868
19327
|
if (config.isInteractive() && settings.merged.general.devtools) {
|
|
18869
|
-
const { setupInitialActivityLogger } = await import("./devtoolsService-
|
|
19328
|
+
const { setupInitialActivityLogger } = await import("./devtoolsService-I7WFRUEA.js");
|
|
18870
19329
|
setupInitialActivityLogger(config);
|
|
18871
19330
|
}
|
|
18872
19331
|
registerTelemetryConfig(config);
|
|
@@ -18925,7 +19384,7 @@ ${finalArgs[promptIndex + 1]}`;
|
|
|
18925
19384
|
const initAppHandle = startupProfiler.start("initialize_app");
|
|
18926
19385
|
const initializationResult = await initializeApp(config, settings);
|
|
18927
19386
|
initAppHandle?.end();
|
|
18928
|
-
import("./liteRtServerManager-
|
|
19387
|
+
import("./liteRtServerManager-OFNVXXQ4.js").then(({ LiteRtServerManager }) => {
|
|
18929
19388
|
const mergedGemma = settings.merged.experimental?.gemmaModelRouter;
|
|
18930
19389
|
if (!mergedGemma) return;
|
|
18931
19390
|
const userGemma = settings.forScope("User" /* User */).settings.experimental?.gemmaModelRouter;
|