bada-terminal / src /config /cli-paths.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
18.3 kB
/**
* cli-paths.js โ€” ํ™œ์„ฑ CLI(claude/opencode/mimo/mimocode/antigravity)๋ณ„ ๊ฒฝ๋กœ ํ”„๋กœํŒŒ์ผ ํ—ฌํผ
*
* BADA๋Š” ์›๋ž˜ Claude Code(~/.claude) ๊ฒฝ๋กœ๋ฅผ ํ•˜๋“œ์ฝ”๋”ฉํ•˜๊ณ  ์žˆ์—ˆ์œผ๋‚˜, ์˜คํ”ˆ์ฝ”๋“œ(opencode) ๋“ฑ
* ๋‹ค๋ฅธ CLI์™€์˜ ์™„์ „ ์—ฐ๋™์„ ์œ„ํ•ด ํ™œ์„ฑ CLI์— ๋”ฐ๋ผ ํ™ˆ/๋ฐ์ดํ„ฐ/์„ค์ •/๋ฃฐ/์„ธ์…˜ ๊ฒฝ๋กœ๋ฅผ ๋™์ ์œผ๋กœ
* ๊ฒฐ์ •ํ•ด์•ผ ํ•œ๋‹ค. ์ด ๋ชจ๋“ˆ์ด ๊ทธ ๋‹จ์ผ ์ง„์‹ค ๊ณต๊ธ‰์›(Single Source of Truth)์ด๋‹ค.
*
* ์‚ฌ์šฉ์ฒ˜(ํ•˜๋“œ์ฝ”๋”ฉ ์ œ๊ฑฐ ๋Œ€์ƒ):
* - src/batch-manager.js : ๋””๋ฒ„๊ทธ ๋กœ๊ทธ ํŒŒ์ผ ์œ„์น˜
* - src/session-syncer.js : ์„ธ์…˜ ํžˆ์Šคํ† ๋ฆฌ ์Šค์บ” ๋””๋ ‰ํ† ๋ฆฌ
* - src/batch-step-runners.js : n8n MCP ์„ค์ • ํŒŒ์ผ ํƒ์ƒ‰ ๊ฒฝ๋กœ
* - src/dev-preference-tracker.js: ํ•™์Šต ๊ทœ์น™ ํŒŒ์ผ(.clauderules vs AGENTS.md ์„น์…˜)
*
* ์‹ค๊ฒฝ๋กœ ๊ฒ€์ฆ(2026-07-08, macOS ๋กœ์ปฌ opencode v1.1.x ๊ธฐ์ค€):
* - opencode ์„ค์ • : ~/.config/opencode/opencode.json (XDG_CONFIG_HOME ์šฐ์„ )
* - opencode ๋ฐ์ดํ„ฐ: ~/.local/share/opencode/storage/{session,message,part}/ (XDG_DATA_HOME ์šฐ์„ )
* - opencode ๊ทœ์น™ : ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ AGENTS.md (+ opencode.json์˜ instructions ๋ฐฐ์—ด)
*/
const path = require('path');
const os = require('os');
const fs = require('fs');
const ctx = require('../context');
/** XDG ๊ทœ์•ฝ ๊ธฐ๋ฐ˜ ์„ค์ • ํ™ˆ (opencode๊ฐ€ ์ด ๊ทœ์•ฝ์„ ๋”ฐ๋ฆ„) */
function xdgConfigHome() {
return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');
}
/** XDG ๊ทœ์•ฝ ๊ธฐ๋ฐ˜ ๋ฐ์ดํ„ฐ ํ™ˆ (opencode ์„ธ์…˜ ์ €์žฅ์†Œ ์œ„์น˜) */
function xdgDataHome() {
return process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
}
/**
* CLI๋ณ„ ๊ฒฝ๋กœ ํ”„๋กœํŒŒ์ผ ํ…Œ์ด๋ธ”.
* ์ƒˆ CLI๋ฅผ ์ง€์›ํ•˜๋ ค๋ฉด ์—ฌ๊ธฐ์— ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค(ํ˜ธ์ถœ๋ถ€ ์ˆ˜์ • ๋ถˆํ•„์š”).
*
* ๊ฐ ํ”„๋กœํŒŒ์ผ ํ•„๋“œ:
* - homeDir : CLI์˜ ์„ค์ • ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ (BADA ๋ถ€์† ํŒŒ์ผ๋„ ์ด๊ณณ์— ๋‘”๋‹ค)
* - dataDir : ์„ธ์…˜ ๋“ฑ ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ† ๋ฆฌ (์—†์œผ๋ฉด homeDir์™€ ๋™์ผ)
* - settingsFiles: MCP ์„œ๋ฒ„ ์„ค์ • ๋“ฑ์„ ๋‹ด๋Š” ์„ค์ • ํŒŒ์ผ ํ›„๋ณด ๋ชฉ๋ก (์šฐ์„ ์ˆœ์œ„ ์ˆœ)
* - sessions : ์„ธ์…˜ ํžˆ์Šคํ† ๋ฆฌ ์ €์žฅ ๋ฐฉ์‹
* { format: 'claude-jsonl', dir } โ†’ <dir>/<projDir>/*.jsonl (Claude Code ๋ฐฉ์‹)
* { format: 'opencode-storage', dir } โ†’ <dir>/storage/{session,message,part} (opencode ๋ฐฉ์‹)
* null โ†’ ์„ธ์…˜ ๋™๊ธฐํ™” ๋ฏธ์ง€์›
* - rules : ํ”„๋กœ์ ํŠธ ํ•™์Šต ๊ทœ์น™ ๊ธฐ๋ก ๋ฐฉ์‹
* { mode: 'file', filename } โ†’ ๊ธฐ์กด CLI ํŒŒ์ผ ๊ฒฝ๋กœ (.clauderules, ์ƒ์„ฑ๊ธฐ๋Š” ์ž์ฒด ๊ตฌ์—ญ๋งŒ ๊ฐฑ์‹ )
* { mode: 'section', filename } โ†’ ์‚ฌ์šฉ์ž ํŒŒ์ผ ๋‚ด ๋งˆํฌ ์„น์…˜๋งŒ ๊ฐฑ์‹  (AGENTS.md)
*/
function buildProfiles() {
const home = os.homedir();
const ocData = path.join(xdgDataHome(), 'opencode');
return {
claude: {
homeDir: path.join(home, '.claude'),
dataDir: path.join(home, '.claude'),
settingsFiles: [path.join(home, '.claude', 'settings.json')],
sessions: { format: 'claude-jsonl', dir: path.join(home, '.claude', 'projects') },
// ์‹ค์ œ CLI ์š”์ฒญ์œผ๋กœ ํ™•์ธํ•œ ๋„ค์ดํ‹ฐ๋ธŒ ๊ฒฝ๋กœ. ๋ ˆ๊ฑฐ์‹œ ํŒŒ์ผ์€ ์ž์ฒด ๊ตฌ์—ญ๋งŒ ํ•จ๊ป˜ ๊ฐฑ์‹ ํ•œ๋‹ค.
rules: { mode: 'section', filename: 'CLAUDE.md', legacyFilename: '.clauderules', inlineSkills: false }
},
opencode: {
homeDir: path.join(xdgConfigHome(), 'opencode'),
dataDir: path.join(xdgDataHome(), 'opencode'),
settingsFiles: [
path.join(xdgConfigHome(), 'opencode', 'opencode.json'),
path.join(xdgConfigHome(), 'opencode', 'opencode.jsonc')
],
sessions: { format: 'opencode-storage', dir: ocData },
// opencode๋Š” ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ์˜ AGENTS.md๋ฅผ ์ž๋™์œผ๋กœ ์ฝ๋Š”๋‹ค.
// AGENTS.md๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์ž‘์„ฑํ•˜๋Š” ํŒŒ์ผ์ด๋ฏ€๋กœ ์ „์ฒด ๋ฎ์–ด์“ฐ๊ธฐ ๊ธˆ์ง€ โ†’ ์„น์…˜ ๊ฐฑ์‹  ๋ชจ๋“œ.
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
codeagent: {
homeDir: path.join(xdgConfigHome(), 'codeagent'),
dataDir: path.join(xdgDataHome(), 'codeagent'),
settingsFiles: [
path.join(xdgConfigHome(), 'codeagent', 'codeagent.json'),
path.join(xdgConfigHome(), 'codeagent', 'codeagent.jsonc'),
path.join(xdgConfigHome(), 'codeagent', 'opencode.json'),
path.join(xdgConfigHome(), 'codeagent', 'opencode.jsonc')
],
sessions: { format: 'opencode-storage', dir: path.join(xdgDataHome(), 'codeagent') },
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
// ์•„๋ž˜ CLI๋“ค์€ ์ •ํ™•ํ•œ ๊ทœ์•ฝ์ด ํ™•์ •๋˜๊ธฐ ์ „๊นŒ์ง€ Claude ์œ ์‚ฌ(~/.<cli>) ๊ธฐ๋ณธ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค.
// ์‹ค์ œ ๊ฒฝ๋กœ๊ฐ€ ๋‹ค๋ฅด๋ฉด ์ด ํ…Œ์ด๋ธ”๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋œ๋‹ค.
mimo: {
homeDir: path.join(home, '.mimo'),
dataDir: path.join(home, '.mimo'),
settingsFiles: [path.join(home, '.mimo', 'settings.json')],
sessions: null,
rules: { mode: 'file', filename: '.clauderules' }
},
mimocode: {
homeDir: path.join(home, '.mimocode'),
dataDir: path.join(home, '.mimocode'),
settingsFiles: [path.join(home, '.mimocode', 'settings.json')],
sessions: null,
rules: { mode: 'file', filename: '.clauderules' }
},
antigravity: {
homeDir: fs.existsSync(path.join(home, '.gemini', 'antigravity-cli'))
? path.join(home, '.gemini', 'antigravity-cli')
: path.join(home, '.antigravity'),
dataDir: fs.existsSync(path.join(home, '.gemini', 'antigravity-cli'))
? path.join(home, '.gemini', 'antigravity-cli')
: path.join(home, '.antigravity'),
settingsFiles: [
path.join(home, '.gemini', 'antigravity-cli', 'settings.json'),
path.join(home, '.antigravity', 'settings.json')
],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
agy: {
homeDir: fs.existsSync(path.join(home, '.gemini', 'antigravity-cli'))
? path.join(home, '.gemini', 'antigravity-cli')
: path.join(home, '.antigravity'),
dataDir: fs.existsSync(path.join(home, '.gemini', 'antigravity-cli'))
? path.join(home, '.gemini', 'antigravity-cli')
: path.join(home, '.antigravity'),
settingsFiles: [
path.join(home, '.gemini', 'antigravity-cli', 'settings.json'),
path.join(home, '.antigravity', 'settings.json')
],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
hermes: {
homeDir: path.join(home, '.hermes'),
dataDir: path.join(home, '.hermes'),
settingsFiles: [
path.join(home, '.hermes', 'config.yaml'),
path.join(home, '.hermes', 'settings.json')
],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
'hermes-agent': {
homeDir: path.join(home, '.hermes'),
dataDir: path.join(home, '.hermes'),
settingsFiles: [
path.join(home, '.hermes', 'config.yaml'),
path.join(home, '.hermes', 'settings.json')
],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
codex: {
homeDir: path.join(home, '.codex'),
dataDir: path.join(home, '.codex'),
settingsFiles: [
path.join(home, '.codex', 'config.toml'),
path.join(home, '.codex', 'settings.json')
],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
gemini: {
homeDir: path.join(home, '.gemini'),
dataDir: path.join(home, '.gemini'),
settingsFiles: [path.join(home, '.gemini', 'settings.json')],
sessions: null,
rules: { mode: 'section', filename: 'GEMINI.md', inlineSkills: true }
},
aider: {
homeDir: path.join(home, '.aider'),
dataDir: path.join(home, '.aider'),
settingsFiles: [path.join(home, '.aider.conf.yml')],
sessions: null,
rules: { mode: 'section', filename: 'CONVENTIONS.md', inlineSkills: false }
},
goose: {
homeDir: path.join(xdgConfigHome(), 'goose'),
dataDir: path.join(xdgDataHome(), 'goose'),
settingsFiles: [path.join(xdgConfigHome(), 'goose', 'config.yaml')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
qwen: {
homeDir: path.join(home, '.qwen'),
dataDir: path.join(home, '.qwen'),
settingsFiles: [path.join(home, '.qwen', 'settings.json')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
cursor: {
homeDir: path.join(home, '.cursor'),
dataDir: path.join(home, '.cursor'),
settingsFiles: [path.join(home, '.cursor', 'mcp.json')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
'cursor-agent': {
homeDir: path.join(home, '.cursor'),
dataDir: path.join(home, '.cursor'),
settingsFiles: [path.join(home, '.cursor', 'mcp.json')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
pi: {
homeDir: path.join(home, '.pi'),
dataDir: path.join(home, '.pi'),
settingsFiles: [path.join(home, '.pi', 'settings.json')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
},
gjc: {
homeDir: path.join(home, '.gjc'),
dataDir: path.join(home, '.gjc'),
settingsFiles: [path.join(home, '.gjc', 'settings.json')],
sessions: null,
rules: { mode: 'section', filename: 'AGENTS.md', inlineSkills: true }
}
};
}
/**
* ์ง€์ • CLI(์ƒ๋žต ์‹œ ํ™œ์„ฑ CLI)์˜ ๊ฒฝ๋กœ ํ”„๋กœํŒŒ์ผ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
* ์•Œ ์ˆ˜ ์—†๋Š” CLI ์ด๋ฆ„์€ claude ํ”„๋กœํŒŒ์ผ๋กœ ํด๋ฐฑํ•œ๋‹ค. ์„ ํƒ CLI์˜ ์ž˜๋ชป๋œ DB ์„ค์ •์€ ์˜ค๋ฅ˜๋กœ ์ „๋‹ฌํ•œ๋‹ค.
* (ํ˜ธ์ถœ๋ถ€๊ฐ€ ๋Œ€๋ถ€๋ถ„ ๋กœ๊ทธ/๋ฒ ์ŠคํŠธ์—ํฌํŠธ ๊ฒฝ๋กœ๋ผ ์˜ˆ์™ธ ์ „ํŒŒ๊ฐ€ ๋” ์œ„ํ—˜ํ•˜๊ธฐ ๋•Œ๋ฌธ).
* @param {string} [cli] CLI ์‹๋ณ„์ž. ์ƒ๋žต ์‹œ ctx.getActiveCli() ์‚ฌ์šฉ
* @returns {{homeDir:string, dataDir:string, settingsFiles:string[], sessions:object|null, rules:object}}
*/
function getCliPaths(cli) {
let target = cli;
if (!target) {
try { target = ctx.getActiveCli(); }
catch (e) {
console.error('[CliPaths] getActiveCli ์‹คํŒจ, claude๋กœ ํด๋ฐฑ:', e.message);
target = 'claude';
}
}
const profiles = buildProfiles();
const name = normalizeCliName(target), profile = profiles[name] || profiles.claude;
if (name === 'opencode') {
// ๋‹ค๋ฅธ CLI์˜ ์กฐํšŒ๋ฅผ OpenCode ์ „์šฉ ํ™˜๊ฒฝ ์„ค์ • ์˜ค๋ฅ˜๋กœ ์ค‘๋‹จํ•˜์ง€ ์•Š๋Š”๋‹ค.
const { selectedDatabase, environmentValue } = require('../utils/opencode-database-path');
const selected = selectedDatabase(profile.sessions.dir, environmentValue(process.env, 'OPENCODE_DB'));
if (selected.kind !== 'default') profile.sessions.database = selected.file;
}
return profile;
}
/**
* BADA ๋ถ€์† ํŒŒ์ผ(๋””๋ฒ„๊ทธ ๋กœ๊ทธ ๋“ฑ)์„ ๋‘˜ ํ™œ์„ฑ CLI ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ณด์žฅ(์ƒ์„ฑ)ํ•˜๊ณ  ๋ฐ˜ํ™˜ํ•œ๋‹ค.
* ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ ์‹คํŒจ ์‹œ์—๋„ ๊ฒฝ๋กœ ๋ฌธ์ž์—ด์€ ๋ฐ˜ํ™˜ํ•œ๋‹ค(ํ˜ธ์ถœ๋ถ€์—์„œ append ์‹คํŒจ๋ฅผ ๊ฐœ๋ณ„ ์ฒ˜๋ฆฌ).
* @param {string} filename ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„ ํŒŒ์ผ๋ช… (์˜ˆ: 'desktop-cli-debug.log')
* @returns {string} ์ ˆ๋Œ€ ๊ฒฝ๋กœ
*/
function getCliHomeFilePath(filename) {
const { homeDir } = getCliPaths();
try {
if (!fs.existsSync(homeDir)) fs.mkdirSync(homeDir, { recursive: true });
} catch (e) {
console.error(`[CliPaths] CLI ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ ์‹คํŒจ(${homeDir}):`, e.message);
}
return path.join(homeDir, filename);
}
/**
* MCP ์„œ๋ฒ„ ์„ค์ • ํƒ์ƒ‰์šฉ ์„ค์ • ํŒŒ์ผ ํ›„๋ณด ๋ชฉ๋ก์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
* ํ™œ์„ฑ CLI์˜ ์„ค์ • ํŒŒ์ผ์„ ์ตœ์šฐ์„ ์œผ๋กœ ๋‘๊ณ , ํ•˜์œ„ ํ˜ธํ™˜์„ ์œ„ํ•ด ๊ธฐ์กด ํ•˜๋“œ์ฝ”๋”ฉ ๊ฒฝ๋กœ
* (~/.gemini/settings.json, ~/.claude/settings.json)๋ฅผ ๋’ค์— ์œ ์ง€ํ•œ๋‹ค. ์ค‘๋ณต์€ ์ œ๊ฑฐ.
* @returns {string[]} ์ ˆ๋Œ€ ๊ฒฝ๋กœ ๋ฐฐ์—ด (์šฐ์„ ์ˆœ์œ„ ์ˆœ)
*/
function getMcpSettingsCandidates() {
const home = os.homedir();
const legacy = [
path.join(home, '.gemini', 'settings.json'),
path.join(home, '.claude', 'settings.json')
];
const active = getCliPaths().settingsFiles || [];
return [...new Set([...active, ...legacy])];
}
/**
* ์—์ด์ „ํŠธ์šฉ PTY/ํ—ค๋“œ๋ฆฌ์Šค ์„ธ์…˜ ๊ธฐ๋™ ์‹œ CLI ๋ช…๋ น ๋’ค์— ๋ถ™์ผ ์ธ์ž ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
*
* ๋ฐฐ๊ฒฝ: ๊ธฐ์กด์—๋Š” ๋ชจ๋“  ์—”์ง„์— Claude Code ์ „์šฉ ํ”Œ๋ž˜๊ทธ(--dangerously-skip-permissions,
* --max-turns)๋ฅผ ๋ถ€์ฐฉํ•ด opencode ๋“ฑ ํƒ€ CLI์—์„œ ๊ธฐ๋™์ด ์‹คํŒจํ–ˆ๋‹ค(unknown flag).
* CLI๋ณ„๋กœ ์•„๋Š” ํ”Œ๋ž˜๊ทธ๋งŒ ๋ถ€์ฐฉํ•˜๋„๋ก ์—ฌ๊ธฐ์„œ ๋ถ„๊ธฐํ•œ๋‹ค.
*
* @param {string} cli CLI ์‹๋ณ„์ž
* @param {{maxTurns?: number}} [opts] ์˜ต์…˜ (claude์˜ --max-turns ๊ฐ’)
* @returns {string} ์ธ์ž ๋ฌธ์ž์—ด (์—†์œผ๋ฉด ๋นˆ ๋ฌธ์ž์—ด โ€” ํ˜ธ์ถœ๋ถ€์—์„œ ๊ณต๋ฐฑ ์ฒ˜๋ฆฌ)
*/
function getAgentLaunchFlags(cli, opts = {}) {
cli = normalizeCliName(cli);
const maxTurns = Number(opts.maxTurns) > 0 ? Number(opts.maxTurns) : 30;
switch (cli) {
case 'claude':
// Claude Code: ์ž๋™ํ™” ์‹คํ–‰์ด๋ฏ€๋กœ ๊ถŒํ•œ ํ”„๋กฌํ”„ํŠธ ์ƒ๋žต + ํ„ด ์ƒํ•œ
return `--dangerously-skip-permissions --max-turns ${maxTurns}`;
case 'agy':
case 'antigravity':
// Antigravity CLI(`agy`): ๊ถŒํ•œ ์ž๋™ ์Šน์ธ ํ”Œ๋ž˜๊ทธ ์ง€์› (`--max-turns`๋Š” ๋ฏธ์ง€์›)
return '--dangerously-skip-permissions';
case 'hermes':
case 'hermes-agent':
// Hermes Agent: `--yolo`๋กœ ๋„๊ตฌ ์Šน์ธ ์šฐํšŒ ์ง€์›
return '--yolo';
case 'opencode':
case 'codeagent':
// opencode / codeagent: ๊ถŒํ•œ ํ”„๋กฌํ”„ํŠธ ๊ฐœ๋…์ด ๋‹ฌ๋ผ ๋Œ€์‘ ํ”Œ๋ž˜๊ทธ ์—†์Œ. ๋ฏธ์ง€ ํ”Œ๋ž˜๊ทธ๋ฅผ ์ฃผ๋ฉด
// ๊ธฐ๋™ ์ž์ฒด๊ฐ€ ์‹คํŒจํ•˜๋ฏ€๋กœ ์•„๋ฌด๊ฒƒ๋„ ๋ถ™์ด์ง€ ์•Š๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•˜๋‹ค.
return '';
default:
// ๊ธฐํƒ€ CLI: ํ”Œ๋ž˜๊ทธ ์—†์ด ๊ธฐ๋™ (๋ณด์ˆ˜์  ๊ธฐ๋ณธ๊ฐ’)
return '';
}
}
/**
* --model ๊ฐ’์ด ํ•ด๋‹น CLI์˜ ํ˜•์‹ ๊ทœ์•ฝ์— ๋งž๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค.
* opencode๋Š” 'provider/model' ํ˜•์‹(์Šฌ๋ž˜์‹œ ํฌํ•จ)์„ ์š”๊ตฌํ•˜๋ฏ€๋กœ, claude์‹ ๋ณ„์นญ
* ('opus', 'sonnet' ๋“ฑ)์„ ๊ทธ๋Œ€๋กœ ๋„˜๊ธฐ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚œ๋‹ค โ†’ ๋ถ€์ฐฉ ์ƒ๋žต ํŒ๋‹จ์šฉ.
* @param {string} cli CLI ์‹๋ณ„์ž
* @param {string} model ๋ชจ๋ธ ๋ฌธ์ž์—ด
* @returns {boolean} true๋ฉด --model ๋ถ€์ฐฉ ๊ฐ€๋Šฅ
*/
function isModelFormatValid(cli, model) {
cli = normalizeCliName(cli);
if (!model) return false;
if (cli === 'opencode' || cli === 'codeagent') return String(model).includes('/');
return true;
}
/**
* ํ—ค๋“œ๋ฆฌ์Šค(1ํšŒ ์‹คํ–‰ ํ›„ ์ข…๋ฃŒ) ์—์ด์ „ํŠธ ํ˜ธ์ถœ์šฉ ์ธ์ž ๋ฐฐ์—ด์„ ๋งŒ๋“ ๋‹ค.
*
* CLI๋ณ„ ํ˜ธ์ถœ ํ˜•์‹:
* - claude ๊ณ„์—ด : `claude -p "<ํ”„๋กฌํ”„ํŠธ>" [--permission-mode bypassPermissions] [--model m]`
* - opencode : `opencode run "<ํ”„๋กฌํ”„ํŠธ>" [--model provider/model]`
* (`-p`๋Š” ์ธ์‹ ๋ถˆ๊ฐ€, ๊ถŒํ•œ ์šฐํšŒ ํ”Œ๋ž˜๊ทธ ์—†์Œ โ€” ๋ถ€์ฐฉ ์‹œ ๊ธฐ๋™ ์‹คํŒจ)
* - mimo/mimocode: Claude ํฌํฌ ๊ณ„์—ด๋กœ ์ทจ๊ธ‰ (claude ํ˜•์‹)
* - antigravity : ํ˜•์‹ ๋ฏธํ™•์ • โ€” `-p`๋Š” ์‹œ๋„ํ•˜๋˜ ๊ถŒํ•œ ํ”Œ๋ž˜๊ทธ๋Š” ์ƒ๋žต(๋ณด์ˆ˜์ )
*
* @param {string} cli CLI ์‹๋ณ„์ž
* @param {object} opts
* @param {string} opts.prompt ์ „๋‹ฌํ•  ํ”„๋กฌํ”„ํŠธ ์ „๋ฌธ
* @param {string[]} [opts.extraArgs] cliCommand์— ๋”ธ๋ฆฐ ์ถ”๊ฐ€ ํ† ํฐ
* @param {boolean} [opts.permissionBypass] ๊ถŒํ•œ ํ”„๋กฌํ”„ํŠธ ์šฐํšŒ ์—ฌ๋ถ€
* @param {string} [opts.model] ๋ชจ๋ธ ์ง€์ • (ํ˜•์‹ ๋ถˆ์ผ์น˜ ์‹œ ์ž๋™ ์ƒ๋žต)
* @returns {string[]} spawn์šฉ ์ธ์ž ๋ฐฐ์—ด
*/
function buildHeadlessArgs(cli, opts = {}) {
cli = normalizeCliName(cli);
const { prompt = '', extraArgs = [], permissionBypass = false, model = '' } = opts;
const args = [];
if (cli === 'opencode' || cli === 'codeagent') {
args.push('run', ...extraArgs, prompt);
if (model && isModelFormatValid(cli, model)) {
args.push('--model', model);
} else if (model) {
console.warn(`[CliPaths] ๋ชจ๋ธ '${model}'์€(๋Š”) ${cli} ํ˜•์‹(provider/model)์ด ์•„๋‹ˆ์–ด์„œ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค.`);
}
return args;
}
if (cli === 'hermes' || cli === 'hermes-agent') {
args.push(...extraArgs, '-z', prompt);
if (permissionBypass && !args.includes('--yolo')) {
args.push('--yolo');
}
if (model && !args.includes('-m')) {
args.push('-m', model);
}
return args;
}
if (cli === 'antigravity' || cli === 'agy') {
args.push(...extraArgs, '-p', prompt);
if (permissionBypass && !args.includes('--dangerously-skip-permissions')) {
args.push('--dangerously-skip-permissions');
}
if (model && !args.includes('--model')) {
args.push('--model', model);
}
return args;
}
if (cli === 'codex') {
args.push('exec', ...extraArgs);
if (permissionBypass && !args.includes('--dangerously-bypass-approvals-and-sandbox')) {
args.push('--dangerously-bypass-approvals-and-sandbox');
}
if (model && !args.includes('--model')) {
args.push('--model', model);
}
args.push(prompt);
return args;
}
if (cli === 'aider') {
args.push(...extraArgs, '--message', prompt, '--yes-always');
if (model && !args.includes('--model')) {
args.push('--model', model);
}
return args;
}
// claude ๋ฐ claude ํฌํฌ ๊ณ„์—ด (๋ฏธํ™•์ • CLI ํฌํ•จ ํด๋ฐฑ)
args.push(...extraArgs, '-p', prompt);
if (permissionBypass && (cli === 'claude' || cli === 'mimo' || cli === 'mimocode')) {
args.push('--permission-mode', 'bypassPermissions');
}
if (model) args.push('--model', model);
return args;
}
/** ์ ˆ๋Œ€ ๊ฒฝ๋กœ ๋ฐ Windows ์‹คํ–‰ ํ™•์žฅ์ž๋ฅผ ๊ฐ™์€ CLI ๊ณ„์•ฝ์œผ๋กœ ํ•ด์„ํ•œ๋‹ค. */
function normalizeCliName(command) {
const token = /^(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(String(command || '').trim());
return normalizeExecutableName(token?.[1] || token?.[2] || token?.[3] || '');
}
// ์ด๋ฏธ argv[0]๋กœ ๋ถ„๋ฆฌํ•œ ๊ฒฝ๋กœ๋Š” ๊ณต๋ฐฑ์„ ๋‹ค์‹œ ํ† ํฐ ๊ฒฝ๊ณ„๋กœ ํ•ด์„ํ•˜์ง€ ์•Š๋Š”๋‹ค.
function normalizeExecutableName(executable) { return String(executable || '').split(/[\\/]/).pop().replace(/\.(exe|cmd|bat)$/i, '').toLowerCase(); }
module.exports = {
normalizeCliName,
normalizeExecutableName,
getCliPaths,
getCliHomeFilePath,
getMcpSettingsCandidates,
getAgentLaunchFlags,
isModelFormatValid,
buildHeadlessArgs
};