Download src/utils/interactive-cli-launch.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 5.48 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/interactive-cli-launch.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/utils/interactive-cli-launch.js
-
curl -L -o interactive-cli-launch.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/interactive-cli-launch.js
5.48 kB
| /** ๋ํํ CLI์๋ ๋ช ์์ argv์ ๊ฐ์ ์คํ ์ ์ฑ ์ ์ ์ฉํ๋ค. docs/specs/interactive-execution.md v1.1.0 */ | |
| const paths = require('../config/cli-paths'); | |
| const { shellTokens, quoteShellArgument } = require('../config/claude-execution-config'); | |
| function prepareLaunch({ cliCommand, cliArguments = [], model, profile, permissionBypass = false, maxTurns, cwd, env = process.env, terminalReplyLanguage }) { | |
| const tokens = shellTokens(cliCommand).map(token => token.value); | |
| if (!tokens.length) throw new Error('CLI command is required'); | |
| if (!Array.isArray(cliArguments) || !cliArguments.every(arg => typeof arg === 'string')) throw new Error('Invalid CLI arguments'); | |
| // ์ํฌํ๋ก์ฐ์ ํ๋ก์ ํธ ํฐ๋ฏธ๋์ด ๋์ผํ OMC bin ํด์์ ์ฌ์ฉํ๋ค. | |
| if (cliArguments.some(arg => arg.includes('{{omcBinPath}}'))) { | |
| const bin = require('../services/omc-runtime').resolveOmcBin(); | |
| cliArguments = cliArguments.map(arg => arg.replaceAll('{{omcBinPath}}', bin)); | |
| } | |
| let command = tokens[0], args = [...tokens.slice(1), ...cliArguments]; | |
| let cli = paths.normalizeExecutableName(command); | |
| // ๋ฒ ์ด(bare) ๋ช ๋ น์ด๋ก ์ง์ ๋ Antigravity(`antigravity` -> `agy`), Hermes(`~/.hermes/hermes-agent/venv/bin/hermes`), | |
| // Cursor(`cursor` -> `cursor-agent`) ๋ฑ์ ์ค์ ์ค์น ๋ฐ์ด๋๋ฆฌ ๊ฒฝ๋ก๋ก ํด์ํ๋ค. | |
| const catalogClis = ['antigravity', 'agy', 'hermes', 'hermes-agent', 'cursor', 'cursor-agent', 'aider', 'goose', 'qwen', 'codex', 'gemini', 'opencode', 'codeagent', 'pi', 'mimo', 'mimocode', 'gjc', 'ollama']; | |
| if (!/[\\/]/.test(command) && catalogClis.includes(cli)) { | |
| const resolvedBin = require('../herd/herd-cli-catalog').resolveCliBinaryPath(cli, env); | |
| if (resolvedBin) { | |
| command = resolvedBin; | |
| cli = cli === 'agy' ? 'antigravity' : cli === 'hermes-agent' ? 'hermes' : cli === 'cursor-agent' ? 'cursor' : cli; | |
| } else if (cli === 'antigravity') { | |
| command = 'agy'; | |
| } else if (cli === 'cursor') { | |
| command = 'cursor-agent'; | |
| } | |
| } | |
| if ((cli === 'hermes' || cli === 'hermes-agent') && require('../herd/herd-cli-catalog').shouldPrependHermesTui(args)) { | |
| args.unshift('--tui'); | |
| } | |
| // ํธ์ถ์๊ฐ ๋ช ์ํ ํฐ๋ฏธ๋ snapshot๋ง ์ฌ์ฉํ๋ค. ๊ณต์ ์คํ๊ธฐ์์๋ ์ ์ญ ์ค์ ์ ์ฝ์ง ์๋๋ค. | |
| const replyLanguage = terminalReplyLanguage && ['claude', 'opencode', 'codeagent'].includes(cli) | |
| ? require('./agent-reply-language').restore(terminalReplyLanguage, []) : undefined; | |
| if (model) { | |
| if (!paths.isModelFormatValid(cli, model)) throw new Error('Invalid model format for ' + cli); | |
| if (cli === 'hermes' || cli === 'hermes-agent') { | |
| if (!args.includes('-m')) args.push('-m', model); | |
| } else { | |
| args.push('--model', model); | |
| } | |
| } | |
| if (cli === 'claude') { | |
| if (permissionBypass && !args.includes('--dangerously-skip-permissions')) args.push('--dangerously-skip-permissions'); | |
| if (maxTurns !== undefined) { | |
| if (!Number.isSafeInteger(maxTurns) || maxTurns <= 0) throw new Error('Invalid CLI max turns'); | |
| args.push('--max-turns', String(maxTurns)); | |
| } | |
| } else if ((cli === 'antigravity' || cli === 'agy') && permissionBypass && !args.includes('--dangerously-skip-permissions')) { | |
| args.push('--dangerously-skip-permissions'); | |
| } else if ((cli === 'hermes' || cli === 'hermes-agent') && permissionBypass && !args.includes('--yolo')) { | |
| args.push('--yolo'); | |
| } | |
| const allowBypass = args.includes('--dangerously-skip-permissions') || args.includes('--yolo'); | |
| const selected = ['claude', 'opencode', 'codeagent'].includes(cli) ? require('../config/profile-execution-config').resolveProfile(cwd, profile) : profile; | |
| const rawArgs = [...args], rawEnv = { ...env }; | |
| const executionEnv = require('./execution-environment').getExecutionEnvironment(env, { cliCommand: quoteShellArgument(command), directArgs: args, cwd, profile: selected }); | |
| const runtimeCommand = command; | |
| if (process.platform === 'win32' && !/\.exe$/i.test(command)) { | |
| args = ['-NoLogo', '-NoProfile', '-Command', '& ' + [command, ...args].map(arg => quoteShellArgument(arg, true)).join(' ')]; | |
| command = 'powershell.exe'; | |
| } | |
| // ๋จ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ/ํฐ๋ฏธ๋ ์ค๋น๋ง์ผ๋ก ๋ฌธ๋งฅ lease๋ฅผ ๋ง๋ค์ง ์๋๋ค. ๊ณตํต ๋ํํ ์คํ๊ธฐ๊ฐ | |
| // ์ค์ ์ธ์ ์ ์์ ํ ๋ ํ๋ํ๋ฉฐ, ๋งค ํด ์์ ๋ด์ฉ์ ๋ค์ ์์งํด ์ฌ์ฌ์ฉ ์ฌ๋ถ๋ฅผ ์ ํ๋ค. | |
| const profilePreparation = { | |
| acquire: () => require('./cli-profile-scope').acquire({ command: runtimeCommand, profile: selected, cwd, | |
| ...(replyLanguage?.defaultLocale !== 'auto' && replyLanguage ? { terminalReplyLanguage: replyLanguage } : {}) }), | |
| ready: (...values) => require('./cli-profile-scope').ready(...values), | |
| prepare(contextId, headroomOwnerToken) { | |
| const nextArgs = [...rawArgs]; | |
| const nextEnv = require('./execution-environment').getExecutionEnvironment(rawEnv, { cliCommand: quoteShellArgument(runtimeCommand), directArgs: nextArgs, cwd, profile: selected, profileContextId: contextId, headroomOwnerToken }); | |
| return { env: nextEnv, args: process.platform === 'win32' && !/\.exe$/i.test(runtimeCommand) | |
| ? ['-NoLogo', '-NoProfile', '-Command', '& ' + [runtimeCommand, ...nextArgs].map(arg => quoteShellArgument(arg, true)).join(' ')] : nextArgs }; | |
| } | |
| }; | |
| return { command, runtimeCommand, args, env: executionEnv, cwd, allowBypass, cli, profilePreparation }; | |
| } | |
| module.exports = { prepareLaunch }; | |