@vybestack/llxprt-code 0.1.18 → 0.1.19-beta
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 +1 -0
- package/dist/package.json +6 -4
- package/dist/src/acp/acpPeer.js +72 -64
- package/dist/src/acp/acpPeer.js.map +1 -1
- package/dist/src/commands/mcp/add.d.ts +7 -0
- package/dist/src/commands/mcp/add.js +155 -0
- package/dist/src/commands/mcp/add.js.map +1 -0
- package/dist/src/commands/mcp/list.d.ts +8 -0
- package/dist/src/commands/mcp/list.js +110 -0
- package/dist/src/commands/mcp/list.js.map +1 -0
- package/dist/src/commands/mcp/remove.d.ts +7 -0
- package/dist/src/commands/mcp/remove.js +44 -0
- package/dist/src/commands/mcp/remove.js.map +1 -0
- package/dist/src/commands/mcp.d.ts +7 -0
- package/dist/src/commands/mcp.js +23 -0
- package/dist/src/commands/mcp.js.map +1 -0
- package/dist/src/config/auth.js +5 -0
- package/dist/src/config/auth.js.map +1 -1
- package/dist/src/config/config.js +80 -37
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/keyBindings.d.ts +64 -0
- package/dist/src/config/keyBindings.js +137 -0
- package/dist/src/config/keyBindings.js.map +1 -0
- package/dist/src/config/settings.d.ts +7 -1
- package/dist/src/config/settings.js +20 -4
- package/dist/src/config/settings.js.map +1 -1
- package/dist/src/gemini.js +12 -109
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +1 -1
- package/dist/src/generated/git-commit.js +1 -1
- package/dist/src/nonInteractiveCli.js +0 -1
- package/dist/src/nonInteractiveCli.js.map +1 -1
- package/dist/src/providers/logging/git-stats-service-impl.d.ts +19 -0
- package/dist/src/providers/logging/git-stats-service-impl.js +25 -0
- package/dist/src/providers/logging/git-stats-service-impl.js.map +1 -0
- package/dist/src/providers/logging/git-stats.d.ts +43 -0
- package/dist/src/providers/logging/git-stats.js +137 -0
- package/dist/src/providers/logging/git-stats.js.map +1 -0
- package/dist/src/providers/providerManagerInstance.js +7 -0
- package/dist/src/providers/providerManagerInstance.js.map +1 -1
- package/dist/src/services/BuiltinCommandLoader.js +2 -0
- package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
- package/dist/src/services/todo-continuation/todoContinuationService.d.ts +172 -0
- package/dist/src/services/todo-continuation/todoContinuationService.js +387 -0
- package/dist/src/services/todo-continuation/todoContinuationService.js.map +1 -0
- package/dist/src/services/todo-continuation/todoContinuationService.spec.d.ts +6 -0
- package/dist/src/services/todo-continuation/todoContinuationService.spec.js +385 -0
- package/dist/src/services/todo-continuation/todoContinuationService.spec.js.map +1 -0
- package/dist/src/ui/App.js +111 -35
- package/dist/src/ui/App.js.map +1 -1
- package/dist/src/ui/IdeIntegrationNudge.d.ts +14 -0
- package/dist/src/ui/IdeIntegrationNudge.js +32 -0
- package/dist/src/ui/IdeIntegrationNudge.js.map +1 -0
- package/dist/src/ui/colors.d.ts +5 -0
- package/dist/src/ui/colors.js +51 -0
- package/dist/src/ui/colors.js.map +1 -1
- package/dist/src/ui/commands/chatCommand.js +16 -0
- package/dist/src/ui/commands/chatCommand.js.map +1 -1
- package/dist/src/ui/commands/diagnosticsCommand.js +9 -1
- package/dist/src/ui/commands/diagnosticsCommand.js.map +1 -1
- package/dist/src/ui/commands/ideCommand.js +67 -31
- package/dist/src/ui/commands/ideCommand.js.map +1 -1
- package/dist/src/ui/commands/loggingCommand.d.ts +15 -0
- package/dist/src/ui/commands/loggingCommand.js +421 -0
- package/dist/src/ui/commands/loggingCommand.js.map +1 -0
- package/dist/src/ui/commands/mcpCommand.js.map +1 -1
- package/dist/src/ui/commands/privacyCommand.d.ts +3 -0
- package/dist/src/ui/commands/privacyCommand.js +6 -3
- package/dist/src/ui/commands/privacyCommand.js.map +1 -1
- package/dist/src/ui/commands/profileCommand.js +1 -0
- package/dist/src/ui/commands/profileCommand.js.map +1 -1
- package/dist/src/ui/commands/setCommand.js +2 -0
- package/dist/src/ui/commands/setCommand.js.map +1 -1
- package/dist/src/ui/commands/setupGithubCommand.js +90 -26
- package/dist/src/ui/commands/setupGithubCommand.js.map +1 -1
- package/dist/src/ui/commands/toolsCommand.js.map +1 -1
- package/dist/src/ui/commands/types.d.ts +14 -2
- package/dist/src/ui/commands/types.js.map +1 -1
- package/dist/src/ui/components/AuthInProgress.js +3 -3
- package/dist/src/ui/components/AuthInProgress.js.map +1 -1
- package/dist/src/ui/components/ContextUsageDisplay.d.ts +10 -0
- package/dist/src/ui/components/ContextUsageDisplay.js +27 -0
- package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -0
- package/dist/src/ui/components/FolderTrustDialog.d.ts +16 -0
- package/dist/src/ui/components/FolderTrustDialog.js +38 -0
- package/dist/src/ui/components/FolderTrustDialog.js.map +1 -0
- package/dist/src/ui/components/Footer.d.ts +0 -1
- package/dist/src/ui/components/Footer.js +132 -15
- package/dist/src/ui/components/Footer.js.map +1 -1
- package/dist/src/ui/components/InputPrompt.js +32 -28
- package/dist/src/ui/components/InputPrompt.js.map +1 -1
- package/dist/src/ui/components/LoggingDialog.d.ts +37 -0
- package/dist/src/ui/components/LoggingDialog.js +155 -0
- package/dist/src/ui/components/LoggingDialog.js.map +1 -0
- package/dist/src/ui/components/MemoryUsageDisplay.js +6 -4
- package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/ProviderDialog.js +100 -26
- package/dist/src/ui/components/ProviderDialog.js.map +1 -1
- package/dist/src/ui/components/ProviderModelDialog.js +99 -27
- package/dist/src/ui/components/ProviderModelDialog.js.map +1 -1
- package/dist/src/ui/components/TodoPanel.d.ts +11 -0
- package/dist/src/ui/components/TodoPanel.js +206 -0
- package/dist/src/ui/components/TodoPanel.js.map +1 -0
- package/dist/src/ui/components/ToolsDialog.d.ts +2 -2
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js +116 -16
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.js +36 -8
- package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
- package/dist/src/ui/components/todo-utils.d.ts +16 -0
- package/dist/src/ui/components/todo-utils.js +41 -0
- package/dist/src/ui/components/todo-utils.js.map +1 -0
- package/dist/src/ui/contexts/SettingsContext.d.ts +9 -0
- package/dist/src/ui/contexts/SettingsContext.js +15 -0
- package/dist/src/ui/contexts/SettingsContext.js.map +1 -0
- package/dist/src/ui/contexts/TodoContext.d.ts +15 -0
- package/dist/src/ui/contexts/TodoContext.js +18 -0
- package/dist/src/ui/contexts/TodoContext.js.map +1 -0
- package/dist/src/ui/contexts/TodoProvider.d.ts +7 -0
- package/dist/src/ui/contexts/TodoProvider.js +62 -0
- package/dist/src/ui/contexts/TodoProvider.js.map +1 -0
- package/dist/src/ui/contexts/ToolCallContext.d.ts +19 -0
- package/dist/src/ui/contexts/ToolCallContext.js +13 -0
- package/dist/src/ui/contexts/ToolCallContext.js.map +1 -0
- package/dist/src/ui/contexts/ToolCallProvider.d.ts +12 -0
- package/dist/src/ui/contexts/ToolCallProvider.js +62 -0
- package/dist/src/ui/contexts/ToolCallProvider.js.map +1 -0
- package/dist/src/ui/hooks/atCommandProcessor.js +28 -4
- package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/slashCommandProcessor.d.ts +5 -1
- package/dist/src/ui/hooks/slashCommandProcessor.js +137 -112
- package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useAtCompletion.d.ts +23 -0
- package/dist/src/ui/hooks/useAtCompletion.js +180 -0
- package/dist/src/ui/hooks/useAtCompletion.js.map +1 -0
- package/dist/src/ui/hooks/useConsoleMessages.js +7 -0
- package/dist/src/ui/hooks/useConsoleMessages.js.map +1 -1
- package/dist/src/ui/hooks/useFolderTrust.d.ts +11 -0
- package/dist/src/ui/hooks/useFolderTrust.js +22 -0
- package/dist/src/ui/hooks/useFolderTrust.js.map +1 -0
- package/dist/src/ui/hooks/useGeminiStream.d.ts +1 -1
- package/dist/src/ui/hooks/useGeminiStream.js +16 -4
- package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
- package/dist/src/ui/hooks/useReactToolScheduler.js +12 -12
- package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
- package/dist/src/ui/hooks/useResponsive.d.ts +14 -0
- package/dist/src/ui/hooks/useResponsive.js +19 -0
- package/dist/src/ui/hooks/useResponsive.js.map +1 -0
- package/dist/src/ui/hooks/useTodoContinuation.d.ts +31 -0
- package/dist/src/ui/hooks/useTodoContinuation.js +148 -0
- package/dist/src/ui/hooks/useTodoContinuation.js.map +1 -0
- package/dist/src/ui/hooks/useTodoContinuation.spec.d.ts +6 -0
- package/dist/src/ui/hooks/useTodoContinuation.spec.js +378 -0
- package/dist/src/ui/hooks/useTodoContinuation.spec.js.map +1 -0
- package/dist/src/ui/hooks/useToolsDialog.d.ts +2 -2
- package/dist/src/ui/hooks/useToolsDialog.js.map +1 -1
- package/dist/src/ui/keyMatchers.d.ts +26 -0
- package/dist/src/ui/keyMatchers.js +68 -0
- package/dist/src/ui/keyMatchers.js.map +1 -0
- package/dist/src/ui/privacy/PrivacyNotice.js +10 -4
- package/dist/src/ui/privacy/PrivacyNotice.js.map +1 -1
- package/dist/src/ui/themes/semantic-resolver.d.ts +12 -0
- package/dist/src/ui/themes/semantic-resolver.js +32 -0
- package/dist/src/ui/themes/semantic-resolver.js.map +1 -0
- package/dist/src/ui/themes/semantic-tokens.d.ts +52 -0
- package/dist/src/ui/themes/semantic-tokens.js +7 -0
- package/dist/src/ui/themes/semantic-tokens.js.map +1 -0
- package/dist/src/ui/themes/theme-compat.d.ts +34 -0
- package/dist/src/ui/themes/theme-compat.js +65 -0
- package/dist/src/ui/themes/theme-compat.js.map +1 -0
- package/dist/src/ui/themes/theme-manager.d.ts +8 -0
- package/dist/src/ui/themes/theme-manager.js +18 -0
- package/dist/src/ui/themes/theme-manager.js.map +1 -1
- package/dist/src/ui/types.d.ts +1 -1
- package/dist/src/ui/utils/CodeColorizer.d.ts +2 -1
- package/dist/src/ui/utils/CodeColorizer.js +4 -3
- package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
- package/dist/src/ui/utils/ConsolePatcher.d.ts +1 -0
- package/dist/src/ui/utils/ConsolePatcher.js +3 -0
- package/dist/src/ui/utils/ConsolePatcher.js.map +1 -1
- package/dist/src/ui/utils/MarkdownDisplay.js +4 -2
- package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
- package/dist/src/ui/utils/commandUtils.d.ts +1 -0
- package/dist/src/ui/utils/commandUtils.js +22 -1
- package/dist/src/ui/utils/commandUtils.js.map +1 -1
- package/dist/src/ui/utils/responsive.d.ts +16 -0
- package/dist/src/ui/utils/responsive.js +111 -0
- package/dist/src/ui/utils/responsive.js.map +1 -0
- package/dist/src/utils/cleanup.d.ts +2 -2
- package/dist/src/utils/cleanup.js +2 -2
- package/dist/src/utils/cleanup.js.map +1 -1
- package/dist/src/utils/gitUtils.d.ts +21 -1
- package/dist/src/utils/gitUtils.js +70 -3
- package/dist/src/utils/gitUtils.js.map +1 -1
- package/dist/src/utils/privacy/ConversationDataRedactor.d.ts +75 -0
- package/dist/src/utils/privacy/ConversationDataRedactor.js +412 -0
- package/dist/src/utils/privacy/ConversationDataRedactor.js.map +1 -0
- package/dist/src/utils/privacy/PrivacyManager.d.ts +58 -0
- package/dist/src/utils/privacy/PrivacyManager.js +133 -0
- package/dist/src/utils/privacy/PrivacyManager.js.map +1 -0
- package/dist/src/utils/sandbox.js +430 -401
- package/dist/src/utils/sandbox.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -4
- package/dist/src/ui/components/IDEContextDetailDisplay.d.ts +0 -12
- package/dist/src/ui/components/IDEContextDetailDisplay.js +0 -17
- package/dist/src/ui/components/IDEContextDetailDisplay.js.map +0 -1
@@ -11,6 +11,7 @@ import { readFile } from 'node:fs/promises';
|
|
11
11
|
import { quote, parse } from 'shell-quote';
|
12
12
|
import { USER_SETTINGS_DIR, SETTINGS_DIRECTORY_NAME, } from '../config/settings.js';
|
13
13
|
import { promisify } from 'util';
|
14
|
+
import { ConsolePatcher } from '../ui/utils/ConsolePatcher.js';
|
14
15
|
const execAsync = promisify(exec);
|
15
16
|
function getContainerPath(hostPath) {
|
16
17
|
if (os.platform() !== 'win32') {
|
@@ -143,99 +144,438 @@ function entrypoint(workdir) {
|
|
143
144
|
return ['bash', '-c', args.join(' ')];
|
144
145
|
}
|
145
146
|
export async function start_sandbox(config, nodeArgs = [], cliConfig) {
|
146
|
-
|
147
|
-
|
147
|
+
const patcher = new ConsolePatcher({
|
148
|
+
debugMode: cliConfig?.getDebugMode() || !!process.env.DEBUG,
|
149
|
+
stderr: true,
|
150
|
+
});
|
151
|
+
patcher.patch();
|
152
|
+
try {
|
153
|
+
if (config.command === 'sandbox-exec') {
|
154
|
+
// disallow BUILD_SANDBOX
|
155
|
+
if (process.env.BUILD_SANDBOX) {
|
156
|
+
console.error('ERROR: cannot BUILD_SANDBOX when using macOS Seatbelt');
|
157
|
+
process.exit(1);
|
158
|
+
}
|
159
|
+
const profile = (process.env.SEATBELT_PROFILE ??= 'permissive-open');
|
160
|
+
let profileFile = new URL(`sandbox-macos-${profile}.sb`, import.meta.url)
|
161
|
+
.pathname;
|
162
|
+
// if profile name is not recognized, then look for file under project settings directory
|
163
|
+
if (!BUILTIN_SEATBELT_PROFILES.includes(profile)) {
|
164
|
+
profileFile = path.join(SETTINGS_DIRECTORY_NAME, `sandbox-macos-${profile}.sb`);
|
165
|
+
}
|
166
|
+
if (!fs.existsSync(profileFile)) {
|
167
|
+
console.error(`ERROR: missing macos seatbelt profile file '${profileFile}'`);
|
168
|
+
process.exit(1);
|
169
|
+
}
|
170
|
+
// Log on STDERR so it doesn't clutter the output on STDOUT
|
171
|
+
console.error(`using macos seatbelt (profile: ${profile}) ...`);
|
172
|
+
// if DEBUG is set, convert to --inspect-brk in NODE_OPTIONS
|
173
|
+
const nodeOptions = [
|
174
|
+
...(process.env.DEBUG ? ['--inspect-brk'] : []),
|
175
|
+
...nodeArgs,
|
176
|
+
].join(' ');
|
177
|
+
const args = [
|
178
|
+
'-D',
|
179
|
+
`TARGET_DIR=${fs.realpathSync(process.cwd())}`,
|
180
|
+
'-D',
|
181
|
+
`TMP_DIR=${fs.realpathSync(os.tmpdir())}`,
|
182
|
+
'-D',
|
183
|
+
`HOME_DIR=${fs.realpathSync(os.homedir())}`,
|
184
|
+
'-D',
|
185
|
+
`CACHE_DIR=${fs.realpathSync(execSync(`getconf DARWIN_USER_CACHE_DIR`).toString().trim())}`,
|
186
|
+
];
|
187
|
+
// Add included directories from the workspace context
|
188
|
+
// Always add 5 INCLUDE_DIR parameters to ensure .sb files can reference them
|
189
|
+
const MAX_INCLUDE_DIRS = 5;
|
190
|
+
const targetDir = fs.realpathSync(cliConfig?.getTargetDir() || '');
|
191
|
+
const includedDirs = [];
|
192
|
+
if (cliConfig) {
|
193
|
+
const workspaceContext = cliConfig.getWorkspaceContext();
|
194
|
+
const directories = workspaceContext.getDirectories();
|
195
|
+
// Filter out TARGET_DIR
|
196
|
+
for (const dir of directories) {
|
197
|
+
const realDir = fs.realpathSync(dir);
|
198
|
+
if (realDir !== targetDir) {
|
199
|
+
includedDirs.push(realDir);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
for (let i = 0; i < MAX_INCLUDE_DIRS; i++) {
|
204
|
+
let dirPath = '/dev/null'; // Default to a safe path that won't cause issues
|
205
|
+
if (i < includedDirs.length) {
|
206
|
+
dirPath = includedDirs[i];
|
207
|
+
}
|
208
|
+
args.push('-D', `INCLUDE_DIR_${i}=${dirPath}`);
|
209
|
+
}
|
210
|
+
args.push('-f', profileFile, 'sh', '-c', [
|
211
|
+
`SANDBOX=sandbox-exec`,
|
212
|
+
`NODE_OPTIONS="${nodeOptions}"`,
|
213
|
+
...process.argv.map((arg) => quote([arg])),
|
214
|
+
].join(' '));
|
215
|
+
// start and set up proxy if GEMINI_SANDBOX_PROXY_COMMAND is set
|
216
|
+
const proxyCommand = process.env.GEMINI_SANDBOX_PROXY_COMMAND;
|
217
|
+
let proxyProcess = undefined;
|
218
|
+
let sandboxProcess = undefined;
|
219
|
+
const sandboxEnv = { ...process.env };
|
220
|
+
if (proxyCommand) {
|
221
|
+
const proxy = process.env.HTTPS_PROXY ||
|
222
|
+
process.env.https_proxy ||
|
223
|
+
process.env.HTTP_PROXY ||
|
224
|
+
process.env.http_proxy ||
|
225
|
+
'http://localhost:8877';
|
226
|
+
sandboxEnv['HTTPS_PROXY'] = proxy;
|
227
|
+
sandboxEnv['https_proxy'] = proxy; // lower-case can be required, e.g. for curl
|
228
|
+
sandboxEnv['HTTP_PROXY'] = proxy;
|
229
|
+
sandboxEnv['http_proxy'] = proxy;
|
230
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
231
|
+
if (noProxy) {
|
232
|
+
sandboxEnv['NO_PROXY'] = noProxy;
|
233
|
+
sandboxEnv['no_proxy'] = noProxy;
|
234
|
+
}
|
235
|
+
proxyProcess = spawn(proxyCommand, {
|
236
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
237
|
+
shell: true,
|
238
|
+
detached: true,
|
239
|
+
});
|
240
|
+
// install handlers to stop proxy on exit/signal
|
241
|
+
const stopProxy = () => {
|
242
|
+
console.log('stopping proxy ...');
|
243
|
+
if (proxyProcess?.pid) {
|
244
|
+
process.kill(-proxyProcess.pid, 'SIGTERM');
|
245
|
+
}
|
246
|
+
};
|
247
|
+
process.on('exit', stopProxy);
|
248
|
+
process.on('SIGINT', stopProxy);
|
249
|
+
process.on('SIGTERM', stopProxy);
|
250
|
+
// commented out as it disrupts ink rendering
|
251
|
+
// proxyProcess.stdout?.on('data', (data) => {
|
252
|
+
// console.info(data.toString());
|
253
|
+
// });
|
254
|
+
proxyProcess.stderr?.on('data', (data) => {
|
255
|
+
console.error(data.toString());
|
256
|
+
});
|
257
|
+
proxyProcess.on('close', (code, signal) => {
|
258
|
+
console.error(`ERROR: proxy command '${proxyCommand}' exited with code ${code}, signal ${signal}`);
|
259
|
+
if (sandboxProcess?.pid) {
|
260
|
+
process.kill(-sandboxProcess.pid, 'SIGTERM');
|
261
|
+
}
|
262
|
+
process.exit(1);
|
263
|
+
});
|
264
|
+
console.log('waiting for proxy to start ...');
|
265
|
+
await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
|
266
|
+
}
|
267
|
+
// spawn child and let it inherit stdio
|
268
|
+
sandboxProcess = spawn(config.command, args, {
|
269
|
+
stdio: 'inherit',
|
270
|
+
});
|
271
|
+
await new Promise((resolve) => sandboxProcess?.on('close', resolve));
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
console.error(`hopping into sandbox (command: ${config.command}) ...`);
|
275
|
+
// determine full path for gemini-cli to distinguish linked vs installed setting
|
276
|
+
const gcPath = fs.realpathSync(process.argv[1]);
|
277
|
+
const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
|
278
|
+
const isCustomProjectSandbox = fs.existsSync(projectSandboxDockerfile);
|
279
|
+
const image = config.image;
|
280
|
+
const workdir = path.resolve(process.cwd());
|
281
|
+
const containerWorkdir = getContainerPath(workdir);
|
282
|
+
// if BUILD_SANDBOX is set, then call scripts/build_sandbox.js under gemini-cli repo
|
283
|
+
//
|
284
|
+
// note this can only be done with binary linked from gemini-cli repo
|
148
285
|
if (process.env.BUILD_SANDBOX) {
|
149
|
-
|
286
|
+
if (!gcPath.includes('gemini-cli/packages/')) {
|
287
|
+
console.error('ERROR: cannot build sandbox using installed gemini binary; ' +
|
288
|
+
'run `npm link ./packages/cli` under gemini-cli repo to switch to linked binary.');
|
289
|
+
process.exit(1);
|
290
|
+
}
|
291
|
+
else {
|
292
|
+
console.error('building sandbox ...');
|
293
|
+
const gcRoot = gcPath.split('/packages/')[0];
|
294
|
+
// if project folder has sandbox.Dockerfile under project settings folder, use that
|
295
|
+
let buildArgs = '';
|
296
|
+
const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
|
297
|
+
if (isCustomProjectSandbox) {
|
298
|
+
console.error(`using ${projectSandboxDockerfile} for sandbox`);
|
299
|
+
buildArgs += `-f ${path.resolve(projectSandboxDockerfile)} -i ${image}`;
|
300
|
+
}
|
301
|
+
execSync(`cd ${gcRoot} && node scripts/build_sandbox.js -s ${buildArgs}`, {
|
302
|
+
stdio: 'inherit',
|
303
|
+
env: {
|
304
|
+
...process.env,
|
305
|
+
GEMINI_SANDBOX: config.command, // in case sandbox is enabled via flags (see config.ts under cli package)
|
306
|
+
},
|
307
|
+
});
|
308
|
+
}
|
309
|
+
}
|
310
|
+
// stop if image is missing
|
311
|
+
if (!(await ensureSandboxImageIsPresent(config.command, image))) {
|
312
|
+
const remedy = image === LOCAL_DEV_SANDBOX_IMAGE_NAME
|
313
|
+
? 'Try running `npm run build:all` or `npm run build:sandbox` under the gemini-cli repo to build it locally, or check the image name and your network connection.'
|
314
|
+
: 'Please check the image name, your network connection, or notify gemini-cli-dev@google.com if the issue persists.';
|
315
|
+
console.error(`ERROR: Sandbox image '${image}' is missing or could not be pulled. ${remedy}`);
|
150
316
|
process.exit(1);
|
151
317
|
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
//
|
156
|
-
if (
|
157
|
-
|
318
|
+
// use interactive mode and auto-remove container on exit
|
319
|
+
// run init binary inside container to forward signals & reap zombies
|
320
|
+
const args = ['run', '-i', '--rm', '--init', '--workdir', containerWorkdir];
|
321
|
+
// add custom flags from SANDBOX_FLAGS
|
322
|
+
if (process.env.SANDBOX_FLAGS) {
|
323
|
+
const flags = parse(process.env.SANDBOX_FLAGS, process.env).filter((f) => typeof f === 'string');
|
324
|
+
args.push(...flags);
|
158
325
|
}
|
159
|
-
if
|
160
|
-
|
161
|
-
|
326
|
+
// add TTY only if stdin is TTY as well, i.e. for piped input don't init TTY in container
|
327
|
+
if (process.stdin.isTTY) {
|
328
|
+
args.push('-t');
|
162
329
|
}
|
163
|
-
//
|
164
|
-
|
165
|
-
//
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
for (const dir of directories) {
|
190
|
-
const realDir = fs.realpathSync(dir);
|
191
|
-
if (realDir !== targetDir) {
|
192
|
-
includedDirs.push(realDir);
|
193
|
-
}
|
330
|
+
// mount current directory as working directory in sandbox (set via --workdir)
|
331
|
+
args.push('--volume', `${workdir}:${containerWorkdir}`);
|
332
|
+
// mount user settings directory inside container, after creating if missing
|
333
|
+
// note user/home changes inside sandbox and we mount at BOTH paths for consistency
|
334
|
+
const userSettingsDirOnHost = USER_SETTINGS_DIR;
|
335
|
+
const userSettingsDirInSandbox = getContainerPath(`/home/node/${SETTINGS_DIRECTORY_NAME}`);
|
336
|
+
if (!fs.existsSync(userSettingsDirOnHost)) {
|
337
|
+
fs.mkdirSync(userSettingsDirOnHost);
|
338
|
+
}
|
339
|
+
args.push('--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`);
|
340
|
+
if (userSettingsDirInSandbox !== userSettingsDirOnHost) {
|
341
|
+
args.push('--volume', `${userSettingsDirOnHost}:${getContainerPath(userSettingsDirOnHost)}`);
|
342
|
+
}
|
343
|
+
// mount os.tmpdir() as os.tmpdir() inside container
|
344
|
+
args.push('--volume', `${os.tmpdir()}:${getContainerPath(os.tmpdir())}`);
|
345
|
+
// mount gcloud config directory if it exists
|
346
|
+
const gcloudConfigDir = path.join(os.homedir(), '.config', 'gcloud');
|
347
|
+
if (fs.existsSync(gcloudConfigDir)) {
|
348
|
+
args.push('--volume', `${gcloudConfigDir}:${getContainerPath(gcloudConfigDir)}:ro`);
|
349
|
+
}
|
350
|
+
// mount ADC file if GOOGLE_APPLICATION_CREDENTIALS is set
|
351
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
352
|
+
const adcFile = process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
353
|
+
if (fs.existsSync(adcFile)) {
|
354
|
+
args.push('--volume', `${adcFile}:${getContainerPath(adcFile)}:ro`);
|
355
|
+
args.push('--env', `GOOGLE_APPLICATION_CREDENTIALS=${getContainerPath(adcFile)}`);
|
194
356
|
}
|
195
357
|
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
358
|
+
// mount paths listed in SANDBOX_MOUNTS
|
359
|
+
if (process.env.SANDBOX_MOUNTS) {
|
360
|
+
for (let mount of process.env.SANDBOX_MOUNTS.split(',')) {
|
361
|
+
if (mount.trim()) {
|
362
|
+
// parse mount as from:to:opts
|
363
|
+
let [from, to, opts] = mount.trim().split(':');
|
364
|
+
to = to || from; // default to mount at same path inside container
|
365
|
+
opts = opts || 'ro'; // default to read-only
|
366
|
+
mount = `${from}:${to}:${opts}`;
|
367
|
+
// check that from path is absolute
|
368
|
+
if (!path.isAbsolute(from)) {
|
369
|
+
console.error(`ERROR: path '${from}' listed in SANDBOX_MOUNTS must be absolute`);
|
370
|
+
process.exit(1);
|
371
|
+
}
|
372
|
+
// check that from path exists on host
|
373
|
+
if (!fs.existsSync(from)) {
|
374
|
+
console.error(`ERROR: missing mount path '${from}' listed in SANDBOX_MOUNTS`);
|
375
|
+
process.exit(1);
|
376
|
+
}
|
377
|
+
console.error(`SANDBOX_MOUNTS: ${from} -> ${to} (${opts})`);
|
378
|
+
args.push('--volume', mount);
|
379
|
+
}
|
200
380
|
}
|
201
|
-
|
202
|
-
|
203
|
-
args.push('
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
381
|
+
}
|
382
|
+
// expose env-specified ports on the sandbox
|
383
|
+
ports().forEach((p) => args.push('--publish', `${p}:${p}`));
|
384
|
+
// if DEBUG is set, expose debugging port
|
385
|
+
if (process.env.DEBUG) {
|
386
|
+
const debugPort = process.env.DEBUG_PORT || '9229';
|
387
|
+
args.push(`--publish`, `${debugPort}:${debugPort}`);
|
388
|
+
}
|
389
|
+
// copy proxy environment variables, replacing localhost with SANDBOX_PROXY_NAME
|
390
|
+
// copy as both upper-case and lower-case as is required by some utilities
|
391
|
+
// LLXPRT_SANDBOX_PROXY_COMMAND implies HTTPS_PROXY unless HTTP_PROXY is set
|
209
392
|
const proxyCommand = process.env.LLXPRT_SANDBOX_PROXY_COMMAND;
|
210
|
-
let proxyProcess = undefined;
|
211
|
-
let sandboxProcess = undefined;
|
212
|
-
const sandboxEnv = { ...process.env };
|
213
393
|
if (proxyCommand) {
|
214
|
-
|
394
|
+
let proxy = process.env.HTTPS_PROXY ||
|
215
395
|
process.env.https_proxy ||
|
216
396
|
process.env.HTTP_PROXY ||
|
217
397
|
process.env.http_proxy ||
|
218
398
|
'http://localhost:8877';
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
399
|
+
proxy = proxy.replace('localhost', SANDBOX_PROXY_NAME);
|
400
|
+
if (proxy) {
|
401
|
+
args.push('--env', `HTTPS_PROXY=${proxy}`);
|
402
|
+
args.push('--env', `https_proxy=${proxy}`); // lower-case can be required, e.g. for curl
|
403
|
+
args.push('--env', `HTTP_PROXY=${proxy}`);
|
404
|
+
args.push('--env', `http_proxy=${proxy}`);
|
405
|
+
}
|
223
406
|
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
224
407
|
if (noProxy) {
|
225
|
-
|
226
|
-
|
408
|
+
args.push('--env', `NO_PROXY=${noProxy}`);
|
409
|
+
args.push('--env', `no_proxy=${noProxy}`);
|
410
|
+
}
|
411
|
+
// if using proxy, switch to internal networking through proxy
|
412
|
+
if (proxy) {
|
413
|
+
execSync(`${config.command} network inspect ${SANDBOX_NETWORK_NAME} || ${config.command} network create --internal ${SANDBOX_NETWORK_NAME}`);
|
414
|
+
args.push('--network', SANDBOX_NETWORK_NAME);
|
415
|
+
// if proxy command is set, create a separate network w/ host access (i.e. non-internal)
|
416
|
+
// we will run proxy in its own container connected to both host network and internal network
|
417
|
+
// this allows proxy to work even on rootless podman on macos with host<->vm<->container isolation
|
418
|
+
if (proxyCommand) {
|
419
|
+
execSync(`${config.command} network inspect ${SANDBOX_PROXY_NAME} || ${config.command} network create ${SANDBOX_PROXY_NAME}`);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
// name container after image, plus numeric suffix to avoid conflicts
|
424
|
+
const imageName = parseImageName(image);
|
425
|
+
let index = 0;
|
426
|
+
const containerNameCheck = execSync(`${config.command} ps -a --format "{{.Names}}"`)
|
427
|
+
.toString()
|
428
|
+
.trim();
|
429
|
+
while (containerNameCheck.includes(`${imageName}-${index}`)) {
|
430
|
+
index++;
|
431
|
+
}
|
432
|
+
const containerName = `${imageName}-${index}`;
|
433
|
+
args.push('--name', containerName, '--hostname', containerName);
|
434
|
+
// copy GEMINI_API_KEY(s)
|
435
|
+
if (process.env.GEMINI_API_KEY) {
|
436
|
+
args.push('--env', `GEMINI_API_KEY=${process.env.GEMINI_API_KEY}`);
|
437
|
+
}
|
438
|
+
if (process.env.GOOGLE_API_KEY) {
|
439
|
+
args.push('--env', `GOOGLE_API_KEY=${process.env.GOOGLE_API_KEY}`);
|
440
|
+
}
|
441
|
+
// copy GOOGLE_GENAI_USE_VERTEXAI
|
442
|
+
if (process.env.GOOGLE_GENAI_USE_VERTEXAI) {
|
443
|
+
args.push('--env', `GOOGLE_GENAI_USE_VERTEXAI=${process.env.GOOGLE_GENAI_USE_VERTEXAI}`);
|
444
|
+
}
|
445
|
+
// copy GOOGLE_GENAI_USE_GCA
|
446
|
+
if (process.env.GOOGLE_GENAI_USE_GCA) {
|
447
|
+
args.push('--env', `GOOGLE_GENAI_USE_GCA=${process.env.GOOGLE_GENAI_USE_GCA}`);
|
448
|
+
}
|
449
|
+
// copy GOOGLE_CLOUD_PROJECT
|
450
|
+
if (process.env.GOOGLE_CLOUD_PROJECT) {
|
451
|
+
args.push('--env', `GOOGLE_CLOUD_PROJECT=${process.env.GOOGLE_CLOUD_PROJECT}`);
|
452
|
+
}
|
453
|
+
// copy GOOGLE_CLOUD_LOCATION
|
454
|
+
if (process.env.GOOGLE_CLOUD_LOCATION) {
|
455
|
+
args.push('--env', `GOOGLE_CLOUD_LOCATION=${process.env.GOOGLE_CLOUD_LOCATION}`);
|
456
|
+
}
|
457
|
+
// copy GEMINI_MODEL
|
458
|
+
if (process.env.GEMINI_MODEL) {
|
459
|
+
args.push('--env', `GEMINI_MODEL=${process.env.GEMINI_MODEL}`);
|
460
|
+
}
|
461
|
+
// copy TERM and COLORTERM to try to maintain terminal setup
|
462
|
+
if (process.env.TERM) {
|
463
|
+
args.push('--env', `TERM=${process.env.TERM}`);
|
464
|
+
}
|
465
|
+
if (process.env.COLORTERM) {
|
466
|
+
args.push('--env', `COLORTERM=${process.env.COLORTERM}`);
|
467
|
+
}
|
468
|
+
// Pass through IDE mode environment variables
|
469
|
+
for (const envVar of [
|
470
|
+
'GEMINI_CLI_IDE_SERVER_PORT',
|
471
|
+
'GEMINI_CLI_IDE_WORKSPACE_PATH',
|
472
|
+
'TERM_PROGRAM',
|
473
|
+
]) {
|
474
|
+
if (process.env[envVar]) {
|
475
|
+
args.push('--env', `${envVar}=${process.env[envVar]}`);
|
476
|
+
}
|
477
|
+
}
|
478
|
+
// copy VIRTUAL_ENV if under working directory
|
479
|
+
// also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
|
480
|
+
// sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)
|
481
|
+
// directory will be empty if not set up, which is still preferable to having host binaries
|
482
|
+
if (process.env.VIRTUAL_ENV?.toLowerCase().startsWith(workdir.toLowerCase())) {
|
483
|
+
const sandboxVenvPath = path.resolve(SETTINGS_DIRECTORY_NAME, 'sandbox.venv');
|
484
|
+
if (!fs.existsSync(sandboxVenvPath)) {
|
485
|
+
fs.mkdirSync(sandboxVenvPath, { recursive: true });
|
227
486
|
}
|
228
|
-
|
487
|
+
args.push('--volume', `${sandboxVenvPath}:${getContainerPath(process.env.VIRTUAL_ENV)}`);
|
488
|
+
args.push('--env', `VIRTUAL_ENV=${getContainerPath(process.env.VIRTUAL_ENV)}`);
|
489
|
+
}
|
490
|
+
// copy additional environment variables from SANDBOX_ENV
|
491
|
+
if (process.env.SANDBOX_ENV) {
|
492
|
+
for (let env of process.env.SANDBOX_ENV.split(',')) {
|
493
|
+
if ((env = env.trim())) {
|
494
|
+
if (env.includes('=')) {
|
495
|
+
console.error(`SANDBOX_ENV: ${env}`);
|
496
|
+
args.push('--env', env);
|
497
|
+
}
|
498
|
+
else {
|
499
|
+
console.error('ERROR: SANDBOX_ENV must be a comma-separated list of key=value pairs');
|
500
|
+
process.exit(1);
|
501
|
+
}
|
502
|
+
}
|
503
|
+
}
|
504
|
+
}
|
505
|
+
// copy NODE_OPTIONS
|
506
|
+
const existingNodeOptions = process.env.NODE_OPTIONS || '';
|
507
|
+
const allNodeOptions = [
|
508
|
+
...(existingNodeOptions ? [existingNodeOptions] : []),
|
509
|
+
...nodeArgs,
|
510
|
+
].join(' ');
|
511
|
+
if (allNodeOptions.length > 0) {
|
512
|
+
args.push('--env', `NODE_OPTIONS="${allNodeOptions}"`);
|
513
|
+
}
|
514
|
+
// set SANDBOX as container name
|
515
|
+
args.push('--env', `SANDBOX=${containerName}`);
|
516
|
+
// for podman only, use empty --authfile to skip unnecessary auth refresh overhead
|
517
|
+
if (config.command === 'podman') {
|
518
|
+
const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
|
519
|
+
fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
|
520
|
+
args.push('--authfile', emptyAuthFilePath);
|
521
|
+
}
|
522
|
+
// Determine if the current user's UID/GID should be passed to the sandbox.
|
523
|
+
// See shouldUseCurrentUserInSandbox for more details.
|
524
|
+
let userFlag = '';
|
525
|
+
const finalEntrypoint = entrypoint(workdir);
|
526
|
+
if (process.env.GEMINI_CLI_INTEGRATION_TEST === 'true') {
|
527
|
+
args.push('--user', 'root');
|
528
|
+
userFlag = '--user root';
|
529
|
+
}
|
530
|
+
else if (await shouldUseCurrentUserInSandbox()) {
|
531
|
+
// For the user-creation logic to work, the container must start as root.
|
532
|
+
// The entrypoint script then handles dropping privileges to the correct user.
|
533
|
+
args.push('--user', 'root');
|
534
|
+
const uid = execSync('id -u').toString().trim();
|
535
|
+
const gid = execSync('id -g').toString().trim();
|
536
|
+
// Instead of passing --user to the main sandbox container, we let it
|
537
|
+
// start as root, then create a user with the host's UID/GID, and
|
538
|
+
// finally switch to that user to run the gemini process. This is
|
539
|
+
// necessary on Linux to ensure the user exists within the
|
540
|
+
// container's /etc/passwd file, which is required by os.userInfo().
|
541
|
+
const username = 'gemini';
|
542
|
+
const homeDir = getContainerPath(os.homedir());
|
543
|
+
const setupUserCommands = [
|
544
|
+
// Use -f with groupadd to avoid errors if the group already exists.
|
545
|
+
`groupadd -f -g ${gid} ${username}`,
|
546
|
+
// Create user only if it doesn't exist. Use -o for non-unique UID.
|
547
|
+
`id -u ${username} &>/dev/null || useradd -o -u ${uid} -g ${gid} -d ${homeDir} -s /bin/bash ${username}`,
|
548
|
+
].join(' && ');
|
549
|
+
const originalCommand = finalEntrypoint[2];
|
550
|
+
const escapedOriginalCommand = originalCommand.replace(/'/g, "'\\''");
|
551
|
+
// Use `su -p` to preserve the environment.
|
552
|
+
const suCommand = `su -p ${username} -c '${escapedOriginalCommand}'`;
|
553
|
+
// The entrypoint is always `['bash', '-c', '<command>']`, so we modify the command part.
|
554
|
+
finalEntrypoint[2] = `${setupUserCommands} && ${suCommand}`;
|
555
|
+
// We still need userFlag for the simpler proxy container, which does not have this issue.
|
556
|
+
userFlag = `--user ${uid}:${gid}`;
|
557
|
+
// When forcing a UID in the sandbox, $HOME can be reset to '/', so we copy $HOME as well.
|
558
|
+
args.push('--env', `HOME=${os.homedir()}`);
|
559
|
+
}
|
560
|
+
// push container image name
|
561
|
+
args.push(image);
|
562
|
+
// push container entrypoint (including args)
|
563
|
+
args.push(...finalEntrypoint);
|
564
|
+
// start and set up proxy if GEMINI_SANDBOX_PROXY_COMMAND is set
|
565
|
+
let proxyProcess = undefined;
|
566
|
+
let sandboxProcess = undefined;
|
567
|
+
if (proxyCommand) {
|
568
|
+
// run proxyCommand in its own container
|
569
|
+
const proxyContainerCommand = `${config.command} run --rm --init ${userFlag} --name ${SANDBOX_PROXY_NAME} --network ${SANDBOX_PROXY_NAME} -p 8877:8877 -v ${process.cwd()}:${workdir} --workdir ${workdir} ${image} ${proxyCommand}`;
|
570
|
+
proxyProcess = spawn(proxyContainerCommand, {
|
229
571
|
stdio: ['ignore', 'pipe', 'pipe'],
|
230
572
|
shell: true,
|
231
573
|
detached: true,
|
232
574
|
});
|
233
575
|
// install handlers to stop proxy on exit/signal
|
234
576
|
const stopProxy = () => {
|
235
|
-
console.log('stopping proxy ...');
|
236
|
-
|
237
|
-
process.kill(-proxyProcess.pid, 'SIGTERM');
|
238
|
-
}
|
577
|
+
console.log('stopping proxy container ...');
|
578
|
+
execSync(`${config.command} rm -f ${SANDBOX_PROXY_NAME}`);
|
239
579
|
};
|
240
580
|
process.on('exit', stopProxy);
|
241
581
|
process.on('SIGINT', stopProxy);
|
@@ -245,10 +585,10 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig) {
|
|
245
585
|
// console.info(data.toString());
|
246
586
|
// });
|
247
587
|
proxyProcess.stderr?.on('data', (data) => {
|
248
|
-
console.error(data.toString());
|
588
|
+
console.error(data.toString().trim());
|
249
589
|
});
|
250
590
|
proxyProcess.on('close', (code, signal) => {
|
251
|
-
console.error(`ERROR: proxy command '${
|
591
|
+
console.error(`ERROR: proxy container command '${proxyContainerCommand}' exited with code ${code}, signal ${signal}`);
|
252
592
|
if (sandboxProcess?.pid) {
|
253
593
|
process.kill(-sandboxProcess.pid, 'SIGTERM');
|
254
594
|
}
|
@@ -256,344 +596,33 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig) {
|
|
256
596
|
});
|
257
597
|
console.log('waiting for proxy to start ...');
|
258
598
|
await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
|
599
|
+
// connect proxy container to sandbox network
|
600
|
+
// (workaround for older versions of docker that don't support multiple --network args)
|
601
|
+
await execAsync(`${config.command} network connect ${SANDBOX_NETWORK_NAME} ${SANDBOX_PROXY_NAME}`);
|
259
602
|
}
|
260
603
|
// spawn child and let it inherit stdio
|
261
604
|
sandboxProcess = spawn(config.command, args, {
|
262
605
|
stdio: 'inherit',
|
263
606
|
});
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
const isCustomProjectSandbox = fs.existsSync(projectSandboxDockerfile);
|
272
|
-
const image = config.image;
|
273
|
-
const workdir = path.resolve(process.cwd());
|
274
|
-
const containerWorkdir = getContainerPath(workdir);
|
275
|
-
// if BUILD_SANDBOX is set, then call scripts/build_sandbox.js under llxprt-code repo
|
276
|
-
//
|
277
|
-
// note this can only be done with binary linked from llxprt-code repo
|
278
|
-
if (process.env.BUILD_SANDBOX) {
|
279
|
-
if (!gcPath.includes('llxprt-code/packages/')) {
|
280
|
-
console.error('ERROR: cannot build sandbox using installed llxprt binary; ' +
|
281
|
-
'run `npm link ./packages/cli` under llxprt-code repo to switch to linked binary.');
|
282
|
-
process.exit(1);
|
283
|
-
}
|
284
|
-
else {
|
285
|
-
console.error('building sandbox ...');
|
286
|
-
const gcRoot = gcPath.split('/packages/')[0];
|
287
|
-
// if project folder has sandbox.Dockerfile under project settings folder, use that
|
288
|
-
let buildArgs = '';
|
289
|
-
const projectSandboxDockerfile = path.join(SETTINGS_DIRECTORY_NAME, 'sandbox.Dockerfile');
|
290
|
-
if (isCustomProjectSandbox) {
|
291
|
-
console.error(`using ${projectSandboxDockerfile} for sandbox`);
|
292
|
-
buildArgs += `-f ${path.resolve(projectSandboxDockerfile)} -i ${image}`;
|
293
|
-
}
|
294
|
-
execSync(`cd ${gcRoot} && node scripts/build_sandbox.js -s ${buildArgs}`, {
|
295
|
-
stdio: 'inherit',
|
296
|
-
env: {
|
297
|
-
...process.env,
|
298
|
-
LLXPRT_SANDBOX: config.command, // in case sandbox is enabled via flags (see config.ts under cli package)
|
299
|
-
},
|
300
|
-
});
|
301
|
-
}
|
302
|
-
}
|
303
|
-
// stop if image is missing
|
304
|
-
if (!(await ensureSandboxImageIsPresent(config.command, image))) {
|
305
|
-
const remedy = image === LOCAL_DEV_SANDBOX_IMAGE_NAME
|
306
|
-
? 'Try running `npm run build:all` or `npm run build:sandbox` under the llxprt-code repo to build it locally, or check the image name and your network connection.'
|
307
|
-
: 'Please check the image name, your network connection, or report issues at https://github.com/acoliver/llxprt-code/issues if the issue persists.';
|
308
|
-
console.error(`ERROR: Sandbox image '${image}' is missing or could not be pulled. ${remedy}`);
|
309
|
-
process.exit(1);
|
310
|
-
}
|
311
|
-
// use interactive mode and auto-remove container on exit
|
312
|
-
// run init binary inside container to forward signals & reap zombies
|
313
|
-
const args = ['run', '-i', '--rm', '--init', '--workdir', containerWorkdir];
|
314
|
-
// add custom flags from SANDBOX_FLAGS
|
315
|
-
if (process.env.SANDBOX_FLAGS) {
|
316
|
-
const flags = parse(process.env.SANDBOX_FLAGS, process.env).filter((f) => typeof f === 'string');
|
317
|
-
args.push(...flags);
|
318
|
-
}
|
319
|
-
// add TTY only if stdin is TTY as well, i.e. for piped input don't init TTY in container
|
320
|
-
if (process.stdin.isTTY) {
|
321
|
-
args.push('-t');
|
322
|
-
}
|
323
|
-
// mount current directory as working directory in sandbox (set via --workdir)
|
324
|
-
args.push('--volume', `${workdir}:${containerWorkdir}`);
|
325
|
-
// mount user settings directory inside container, after creating if missing
|
326
|
-
// note user/home changes inside sandbox and we mount at BOTH paths for consistency
|
327
|
-
const userSettingsDirOnHost = USER_SETTINGS_DIR;
|
328
|
-
const userSettingsDirInSandbox = getContainerPath(`/home/node/${SETTINGS_DIRECTORY_NAME}`);
|
329
|
-
if (!fs.existsSync(userSettingsDirOnHost)) {
|
330
|
-
fs.mkdirSync(userSettingsDirOnHost);
|
331
|
-
}
|
332
|
-
args.push('--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`);
|
333
|
-
if (userSettingsDirInSandbox !== userSettingsDirOnHost) {
|
334
|
-
args.push('--volume', `${userSettingsDirOnHost}:${getContainerPath(userSettingsDirOnHost)}`);
|
335
|
-
}
|
336
|
-
// mount os.tmpdir() as os.tmpdir() inside container
|
337
|
-
args.push('--volume', `${os.tmpdir()}:${getContainerPath(os.tmpdir())}`);
|
338
|
-
// mount gcloud config directory if it exists
|
339
|
-
const gcloudConfigDir = path.join(os.homedir(), '.config', 'gcloud');
|
340
|
-
if (fs.existsSync(gcloudConfigDir)) {
|
341
|
-
args.push('--volume', `${gcloudConfigDir}:${getContainerPath(gcloudConfigDir)}:ro`);
|
342
|
-
}
|
343
|
-
// mount ADC file if GOOGLE_APPLICATION_CREDENTIALS is set
|
344
|
-
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
345
|
-
const adcFile = process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
346
|
-
if (fs.existsSync(adcFile)) {
|
347
|
-
args.push('--volume', `${adcFile}:${getContainerPath(adcFile)}:ro`);
|
348
|
-
args.push('--env', `GOOGLE_APPLICATION_CREDENTIALS=${getContainerPath(adcFile)}`);
|
349
|
-
}
|
350
|
-
}
|
351
|
-
// mount paths listed in SANDBOX_MOUNTS
|
352
|
-
if (process.env.SANDBOX_MOUNTS) {
|
353
|
-
for (let mount of process.env.SANDBOX_MOUNTS.split(',')) {
|
354
|
-
if (mount.trim()) {
|
355
|
-
// parse mount as from:to:opts
|
356
|
-
let [from, to, opts] = mount.trim().split(':');
|
357
|
-
to = to || from; // default to mount at same path inside container
|
358
|
-
opts = opts || 'ro'; // default to read-only
|
359
|
-
mount = `${from}:${to}:${opts}`;
|
360
|
-
// check that from path is absolute
|
361
|
-
if (!path.isAbsolute(from)) {
|
362
|
-
console.error(`ERROR: path '${from}' listed in SANDBOX_MOUNTS must be absolute`);
|
363
|
-
process.exit(1);
|
364
|
-
}
|
365
|
-
// check that from path exists on host
|
366
|
-
if (!fs.existsSync(from)) {
|
367
|
-
console.error(`ERROR: missing mount path '${from}' listed in SANDBOX_MOUNTS`);
|
368
|
-
process.exit(1);
|
369
|
-
}
|
370
|
-
console.error(`SANDBOX_MOUNTS: ${from} -> ${to} (${opts})`);
|
371
|
-
args.push('--volume', mount);
|
372
|
-
}
|
373
|
-
}
|
374
|
-
}
|
375
|
-
// expose env-specified ports on the sandbox
|
376
|
-
ports().forEach((p) => args.push('--publish', `${p}:${p}`));
|
377
|
-
// if DEBUG is set, expose debugging port
|
378
|
-
if (process.env.DEBUG) {
|
379
|
-
const debugPort = process.env.DEBUG_PORT || '9229';
|
380
|
-
args.push(`--publish`, `${debugPort}:${debugPort}`);
|
381
|
-
}
|
382
|
-
// copy proxy environment variables, replacing localhost with SANDBOX_PROXY_NAME
|
383
|
-
// copy as both upper-case and lower-case as is required by some utilities
|
384
|
-
// LLXPRT_SANDBOX_PROXY_COMMAND implies HTTPS_PROXY unless HTTP_PROXY is set
|
385
|
-
const proxyCommand = process.env.LLXPRT_SANDBOX_PROXY_COMMAND;
|
386
|
-
if (proxyCommand) {
|
387
|
-
let proxy = process.env.HTTPS_PROXY ||
|
388
|
-
process.env.https_proxy ||
|
389
|
-
process.env.HTTP_PROXY ||
|
390
|
-
process.env.http_proxy ||
|
391
|
-
'http://localhost:8877';
|
392
|
-
proxy = proxy.replace('localhost', SANDBOX_PROXY_NAME);
|
393
|
-
if (proxy) {
|
394
|
-
args.push('--env', `HTTPS_PROXY=${proxy}`);
|
395
|
-
args.push('--env', `https_proxy=${proxy}`); // lower-case can be required, e.g. for curl
|
396
|
-
args.push('--env', `HTTP_PROXY=${proxy}`);
|
397
|
-
args.push('--env', `http_proxy=${proxy}`);
|
398
|
-
}
|
399
|
-
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
400
|
-
if (noProxy) {
|
401
|
-
args.push('--env', `NO_PROXY=${noProxy}`);
|
402
|
-
args.push('--env', `no_proxy=${noProxy}`);
|
403
|
-
}
|
404
|
-
// if using proxy, switch to internal networking through proxy
|
405
|
-
if (proxy) {
|
406
|
-
execSync(`${config.command} network inspect ${SANDBOX_NETWORK_NAME} || ${config.command} network create --internal ${SANDBOX_NETWORK_NAME}`);
|
407
|
-
args.push('--network', SANDBOX_NETWORK_NAME);
|
408
|
-
// if proxy command is set, create a separate network w/ host access (i.e. non-internal)
|
409
|
-
// we will run proxy in its own container connected to both host network and internal network
|
410
|
-
// this allows proxy to work even on rootless podman on macos with host<->vm<->container isolation
|
411
|
-
if (proxyCommand) {
|
412
|
-
execSync(`${config.command} network inspect ${SANDBOX_PROXY_NAME} || ${config.command} network create ${SANDBOX_PROXY_NAME}`);
|
413
|
-
}
|
414
|
-
}
|
415
|
-
}
|
416
|
-
// name container after image, plus numeric suffix to avoid conflicts
|
417
|
-
const imageName = parseImageName(image);
|
418
|
-
let index = 0;
|
419
|
-
const containerNameCheck = execSync(`${config.command} ps -a --format "{{.Names}}"`)
|
420
|
-
.toString()
|
421
|
-
.trim();
|
422
|
-
while (containerNameCheck.includes(`${imageName}-${index}`)) {
|
423
|
-
index++;
|
424
|
-
}
|
425
|
-
const containerName = `${imageName}-${index}`;
|
426
|
-
args.push('--name', containerName, '--hostname', containerName);
|
427
|
-
// copy GEMINI_API_KEY(s)
|
428
|
-
if (process.env.GEMINI_API_KEY) {
|
429
|
-
args.push('--env', `GEMINI_API_KEY=${process.env.GEMINI_API_KEY}`);
|
430
|
-
}
|
431
|
-
if (process.env.GOOGLE_API_KEY) {
|
432
|
-
args.push('--env', `GOOGLE_API_KEY=${process.env.GOOGLE_API_KEY}`);
|
433
|
-
}
|
434
|
-
// copy GOOGLE_GENAI_USE_VERTEXAI
|
435
|
-
if (process.env.GOOGLE_GENAI_USE_VERTEXAI) {
|
436
|
-
args.push('--env', `GOOGLE_GENAI_USE_VERTEXAI=${process.env.GOOGLE_GENAI_USE_VERTEXAI}`);
|
437
|
-
}
|
438
|
-
// copy GOOGLE_GENAI_USE_GCA
|
439
|
-
if (process.env.GOOGLE_GENAI_USE_GCA) {
|
440
|
-
args.push('--env', `GOOGLE_GENAI_USE_GCA=${process.env.GOOGLE_GENAI_USE_GCA}`);
|
441
|
-
}
|
442
|
-
// copy GOOGLE_CLOUD_PROJECT
|
443
|
-
if (process.env.GOOGLE_CLOUD_PROJECT) {
|
444
|
-
args.push('--env', `GOOGLE_CLOUD_PROJECT=${process.env.GOOGLE_CLOUD_PROJECT}`);
|
445
|
-
}
|
446
|
-
// copy GOOGLE_CLOUD_LOCATION
|
447
|
-
if (process.env.GOOGLE_CLOUD_LOCATION) {
|
448
|
-
args.push('--env', `GOOGLE_CLOUD_LOCATION=${process.env.GOOGLE_CLOUD_LOCATION}`);
|
449
|
-
}
|
450
|
-
// copy GEMINI_MODEL
|
451
|
-
if (process.env.GEMINI_MODEL) {
|
452
|
-
args.push('--env', `GEMINI_MODEL=${process.env.GEMINI_MODEL}`);
|
453
|
-
}
|
454
|
-
// copy TERM and COLORTERM to try to maintain terminal setup
|
455
|
-
if (process.env.TERM) {
|
456
|
-
args.push('--env', `TERM=${process.env.TERM}`);
|
457
|
-
}
|
458
|
-
if (process.env.COLORTERM) {
|
459
|
-
args.push('--env', `COLORTERM=${process.env.COLORTERM}`);
|
460
|
-
}
|
461
|
-
// copy VIRTUAL_ENV if under working directory
|
462
|
-
// also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
|
463
|
-
// sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)
|
464
|
-
// directory will be empty if not set up, which is still preferable to having host binaries
|
465
|
-
if (process.env.VIRTUAL_ENV?.toLowerCase().startsWith(workdir.toLowerCase())) {
|
466
|
-
const sandboxVenvPath = path.resolve(SETTINGS_DIRECTORY_NAME, 'sandbox.venv');
|
467
|
-
if (!fs.existsSync(sandboxVenvPath)) {
|
468
|
-
fs.mkdirSync(sandboxVenvPath, { recursive: true });
|
469
|
-
}
|
470
|
-
args.push('--volume', `${sandboxVenvPath}:${getContainerPath(process.env.VIRTUAL_ENV)}`);
|
471
|
-
args.push('--env', `VIRTUAL_ENV=${getContainerPath(process.env.VIRTUAL_ENV)}`);
|
472
|
-
}
|
473
|
-
// copy additional environment variables from SANDBOX_ENV
|
474
|
-
if (process.env.SANDBOX_ENV) {
|
475
|
-
for (let env of process.env.SANDBOX_ENV.split(',')) {
|
476
|
-
if ((env = env.trim())) {
|
477
|
-
if (env.includes('=')) {
|
478
|
-
console.error(`SANDBOX_ENV: ${env}`);
|
479
|
-
args.push('--env', env);
|
480
|
-
}
|
481
|
-
else {
|
482
|
-
console.error('ERROR: SANDBOX_ENV must be a comma-separated list of key=value pairs');
|
483
|
-
process.exit(1);
|
607
|
+
sandboxProcess.on('error', (err) => {
|
608
|
+
console.error('Sandbox process error:', err);
|
609
|
+
});
|
610
|
+
await new Promise((resolve) => {
|
611
|
+
sandboxProcess?.on('close', (code, signal) => {
|
612
|
+
if (code !== 0) {
|
613
|
+
console.log(`Sandbox process exited with code: ${code}, signal: ${signal}`);
|
484
614
|
}
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
// copy NODE_OPTIONS
|
489
|
-
const existingNodeOptions = process.env.NODE_OPTIONS || '';
|
490
|
-
const allNodeOptions = [
|
491
|
-
...(existingNodeOptions ? [existingNodeOptions] : []),
|
492
|
-
...nodeArgs,
|
493
|
-
].join(' ');
|
494
|
-
if (allNodeOptions.length > 0) {
|
495
|
-
args.push('--env', `NODE_OPTIONS="${allNodeOptions}"`);
|
496
|
-
}
|
497
|
-
// set SANDBOX as container name
|
498
|
-
args.push('--env', `SANDBOX=${containerName}`);
|
499
|
-
// for podman only, use empty --authfile to skip unnecessary auth refresh overhead
|
500
|
-
if (config.command === 'podman') {
|
501
|
-
const emptyAuthFilePath = path.join(os.tmpdir(), 'empty_auth.json');
|
502
|
-
fs.writeFileSync(emptyAuthFilePath, '{}', 'utf-8');
|
503
|
-
args.push('--authfile', emptyAuthFilePath);
|
615
|
+
resolve();
|
616
|
+
});
|
617
|
+
});
|
504
618
|
}
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
const finalEntrypoint = entrypoint(workdir);
|
509
|
-
if (await shouldUseCurrentUserInSandbox()) {
|
510
|
-
// For the user-creation logic to work, the container must start as root.
|
511
|
-
// The entrypoint script then handles dropping privileges to the correct user.
|
512
|
-
args.push('--user', 'root');
|
513
|
-
const uid = execSync('id -u').toString().trim();
|
514
|
-
const gid = execSync('id -g').toString().trim();
|
515
|
-
// Instead of passing --user to the main sandbox container, we let it
|
516
|
-
// start as root, then create a user with the host's UID/GID, and
|
517
|
-
// finally switch to that user to run the gemini process. This is
|
518
|
-
// necessary on Linux to ensure the user exists within the
|
519
|
-
// container's /etc/passwd file, which is required by os.userInfo().
|
520
|
-
const username = 'gemini';
|
521
|
-
const homeDir = getContainerPath(os.homedir());
|
522
|
-
const setupUserCommands = [
|
523
|
-
// Use -f with groupadd to avoid errors if the group already exists.
|
524
|
-
`groupadd -f -g ${gid} ${username}`,
|
525
|
-
// Create user only if it doesn't exist. Use -o for non-unique UID.
|
526
|
-
`id -u ${username} &>/dev/null || useradd -o -u ${uid} -g ${gid} -d ${homeDir} -s /bin/bash ${username}`,
|
527
|
-
].join(' && ');
|
528
|
-
const originalCommand = finalEntrypoint[2];
|
529
|
-
const escapedOriginalCommand = originalCommand.replace(/'/g, "'\\''");
|
530
|
-
// Use `su -p` to preserve the environment.
|
531
|
-
const suCommand = `su -p ${username} -c '${escapedOriginalCommand}'`;
|
532
|
-
// The entrypoint is always `['bash', '-c', '<command>']`, so we modify the command part.
|
533
|
-
finalEntrypoint[2] = `${setupUserCommands} && ${suCommand}`;
|
534
|
-
// We still need userFlag for the simpler proxy container, which does not have this issue.
|
535
|
-
userFlag = `--user ${uid}:${gid}`;
|
536
|
-
// When forcing a UID in the sandbox, $HOME can be reset to '/', so we copy $HOME as well.
|
537
|
-
args.push('--env', `HOME=${os.homedir()}`);
|
619
|
+
catch (error) {
|
620
|
+
console.error('Sandbox error:', error);
|
621
|
+
throw error;
|
538
622
|
}
|
539
|
-
|
540
|
-
|
541
|
-
// push container entrypoint (including args)
|
542
|
-
args.push(...finalEntrypoint);
|
543
|
-
// start and set up proxy if LLXPRT_SANDBOX_PROXY_COMMAND is set
|
544
|
-
let proxyProcess = undefined;
|
545
|
-
let sandboxProcess = undefined;
|
546
|
-
if (proxyCommand) {
|
547
|
-
// run proxyCommand in its own container
|
548
|
-
const proxyContainerCommand = `${config.command} run --rm --init ${userFlag} --name ${SANDBOX_PROXY_NAME} --network ${SANDBOX_PROXY_NAME} -p 8877:8877 -v ${process.cwd()}:${workdir} --workdir ${workdir} ${image} ${proxyCommand}`;
|
549
|
-
proxyProcess = spawn(proxyContainerCommand, {
|
550
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
551
|
-
shell: true,
|
552
|
-
detached: true,
|
553
|
-
});
|
554
|
-
// install handlers to stop proxy on exit/signal
|
555
|
-
const stopProxy = () => {
|
556
|
-
console.log('stopping proxy container ...');
|
557
|
-
execSync(`${config.command} rm -f ${SANDBOX_PROXY_NAME}`);
|
558
|
-
};
|
559
|
-
process.on('exit', stopProxy);
|
560
|
-
process.on('SIGINT', stopProxy);
|
561
|
-
process.on('SIGTERM', stopProxy);
|
562
|
-
// commented out as it disrupts ink rendering
|
563
|
-
// proxyProcess.stdout?.on('data', (data) => {
|
564
|
-
// console.info(data.toString());
|
565
|
-
// });
|
566
|
-
proxyProcess.stderr?.on('data', (data) => {
|
567
|
-
console.error(data.toString().trim());
|
568
|
-
});
|
569
|
-
proxyProcess.on('close', (code, signal) => {
|
570
|
-
console.error(`ERROR: proxy container command '${proxyContainerCommand}' exited with code ${code}, signal ${signal}`);
|
571
|
-
if (sandboxProcess?.pid) {
|
572
|
-
process.kill(-sandboxProcess.pid, 'SIGTERM');
|
573
|
-
}
|
574
|
-
process.exit(1);
|
575
|
-
});
|
576
|
-
console.log('waiting for proxy to start ...');
|
577
|
-
await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
|
578
|
-
// connect proxy container to sandbox network
|
579
|
-
// (workaround for older versions of docker that don't support multiple --network args)
|
580
|
-
await execAsync(`${config.command} network connect ${SANDBOX_NETWORK_NAME} ${SANDBOX_PROXY_NAME}`);
|
623
|
+
finally {
|
624
|
+
patcher.cleanup();
|
581
625
|
}
|
582
|
-
// spawn child and let it inherit stdio
|
583
|
-
sandboxProcess = spawn(config.command, args, {
|
584
|
-
stdio: 'inherit',
|
585
|
-
});
|
586
|
-
sandboxProcess.on('error', (err) => {
|
587
|
-
console.error('Sandbox process error:', err);
|
588
|
-
});
|
589
|
-
await new Promise((resolve) => {
|
590
|
-
sandboxProcess?.on('close', (code, signal) => {
|
591
|
-
if (code !== 0) {
|
592
|
-
console.log(`Sandbox process exited with code: ${code}, signal: ${signal}`);
|
593
|
-
}
|
594
|
-
resolve();
|
595
|
-
});
|
596
|
-
});
|
597
626
|
}
|
598
627
|
// Helper functions to ensure sandbox image is present
|
599
628
|
async function imageExists(sandbox, image) {
|