File size: 5,479 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | /** ๋ํํ 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 };
|