diff options
Diffstat (limited to 'packages/cli')
| -rw-r--r-- | packages/cli/package.json | 2 | ||||
| -rw-r--r-- | packages/cli/src/gemini.ts | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/packages/cli/package.json b/packages/cli/package.json index 3699328a..c2e8ba2c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -42,6 +42,7 @@ "lowlight": "^3.3.0", "react": "^18.3.1", "read-package-up": "^11.0.0", + "shell-quote": "^1.8.2", "yargs": "^17.7.2" }, "devDependencies": { @@ -49,6 +50,7 @@ "@types/dotenv": "^6.1.1", "@types/node": "^20.11.24", "@types/react": "^19.1.0", + "@types/shell-quote": "^1.7.5", "@types/yargs": "^17.0.32", "typescript": "^5.3.3", "vitest": "^3.1.1" diff --git a/packages/cli/src/gemini.ts b/packages/cli/src/gemini.ts index 1d189493..2cecbedb 100644 --- a/packages/cli/src/gemini.ts +++ b/packages/cli/src/gemini.ts @@ -8,6 +8,7 @@ import os from 'os'; import path from 'path'; import fs from 'fs'; import React from 'react'; +import { quote } from 'shell-quote'; import { render } from 'ink'; import { App } from './ui/App.js'; import { loadCliConfig } from './config/config.js'; @@ -204,17 +205,24 @@ async function start_sandbox(sandbox: string) { } // open additional ports if SANDBOX_PORTS is set + // also set up redirects (via socat) so servers can listen on localhost instead of 0.0.0.0 + let bash_cmd = ''; if (process.env.SANDBOX_PORTS) { for (let port of process.env.SANDBOX_PORTS.split(',')) { if ((port = port.trim())) { console.log(`SANDBOX_PORTS: ${port}`); args.push('-p', `${port}:${port}`); + bash_cmd += `socat TCP4-LISTEN:${port},bind=$(hostname -i),fork,reuseaddr TCP4:127.0.0.1:${port} 2> /dev/null & `; } } } - // append remaining args (image, node, node args, cli path, cli args) - args.push(image, 'node', ...nodeArgs, cliPath, ...process.argv.slice(2)); + // append remaining args (image, bash -c "node node_args... cli path cli_args...") + // node_args and cli_args need to be quoted before being inserted into bash_cmd + const quotedNodeArgs = nodeArgs.map((arg) => quote([arg])); + const quotedCliArgs = process.argv.slice(2).map((arg) => quote([arg])); + bash_cmd += `node ${quotedNodeArgs.join(' ')} ${quote([cliPath])} ${quotedCliArgs.join(' ')}`; + args.push(image, 'bash', '-c', bash_cmd); // spawn child and let it inherit stdio const child = spawn(sandbox, args, { |
