Download src/config/opencode-agent-sync.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 7.96 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/config/opencode-agent-sync.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/config/opencode-agent-sync.js
-
curl -L -o opencode-agent-sync.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/config/opencode-agent-sync.js
7.96 kB
| /** | |
| * opencode-agent-sync.js โ Claude Code ์๋ธ์์ด์ ํธ๋ฅผ opencode ์์ด์ ํธ๋ก ๋ฏธ๋ฌ๋ง | |
| * | |
| * ๋ฐฐ๊ฒฝ: ~/.claude/agents/*.md ์ ์๋ธ์์ด์ ํธ(analyst, architect, code-reviewer ๋ฑ)๋ | |
| * Claude Code ์ ์ฉ ๋ฐ๊ฒฌ ๋ฉ์ปค๋์ฆ์ด๋ผ opencode์์๋ ์ ํ ์ธ์๋์ง ์๋ ๋ฝ์ธ์ด ์์๋ค. | |
| * opencode๋ ~/.config/opencode/agent/*.md (frontmatter=AgentConfig, ๋ณธ๋ฌธ=ํ๋กฌํํธ)๋ฅผ | |
| * ์ฝ์ผ๋ฏ๋ก, ํ์์ ๋ณํํด ๋ฏธ๋ฌ๋งํ๋ค. (๊ท์ฝ ์ค์ธก ๊ฒ์ฆ: 2026-07-11, `opencode agent list`๊ฐ | |
| * ๊ธ๋ก๋ฒ agent/ ๋๋ ํ ๋ฆฌ์ .md๋ฅผ subagent๋ก ์ธ์ํจ โ TR-027 ์ฐ์ฅ) | |
| * | |
| * ํ์ ๋์: | |
| * - ํ์ผ๋ช โ opencode ์์ด์ ํธ ์ด๋ฆ (๋์ผ ์ ์ง) | |
| * - description โ description (์์ผ๋ฉด ๋ฏธ๋ฌ๋ง ์ ์ธ โ opencode ์คํค๋ง ํ์๊ฐ) | |
| * - (mode) โ 'subagent' ๊ณ ์ | |
| * - model ๋ณ์นญ(opus ๋ฑ) โ ์๋ต (opencode๋ provider/model ํ์ โ ์ธ์ ๋ชจ๋ธ ์์์ด ์์ ) | |
| * - tools/disallowedTools โ opencode tools ๋งต(boolean)์ผ๋ก ๋ณํ (์๋ ค์ง ํด๋ช ๋ง) | |
| * - ๋ณธ๋ฌธ โ ํ๋กฌํํธ ๊ทธ๋๋ก | |
| * | |
| * ์์ ์์น: | |
| * 1) ์์ฑ ํ์ผ์๋ BADA ๋ฏธ๋ฌ ๋ง์ปค๋ฅผ ์ฌ๊ณ , ๋ง์ปค ์๋ ํ์ผ๋ง ๊ฐฑ์ /์ญ์ ํ๋ค | |
| * (์ฌ์ฉ์๊ฐ ์ง์ ๋ง๋ opencode ์์ด์ ํธ๋ ์ ๋ ๊ฑด๋๋ฆฌ์ง ์์). | |
| * 2) ์๋ณธ์ด ์ฌ๋ผ์ง ๋ฏธ๋ฌ ํ์ผ(๊ณ ์)์ ์ ๊ฑฐํด ๋ชฉ๋ก ์ค์ผ์ ๋ง๋๋ค. | |
| * 3) ์๋ณธ ํด์๊ฐ ๊ฐ์ผ๋ฉด ์ฌ๊ธฐ๋กํ์ง ์๋๋ค (๋ฉฑ๋ฑ). | |
| */ | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const os = require('os'); | |
| const crypto = require('crypto'); | |
| const cliPaths = require('./cli-paths'); | |
| /** ์์ฑ ํ์ผ ์๋ณ์ฉ ๋ง์ปค (๋ณธ๋ฌธ ์ต์๋จ HTML ์ฃผ์) */ | |
| const MIRROR_MARKER = '<!-- BADA-MIRROR: claude-agent'; | |
| /** Claude Code ํด๋ช โ opencode ํด๋ช ๋์ํ (์๋ ค์ง ๊ฒ๋ง ๋ณํ, ๋ฏธ์ง์ ํด์ ์๋ต) */ | |
| const TOOL_NAME_MAP = { | |
| bash: 'bash', read: 'read', write: 'write', edit: 'edit', | |
| grep: 'grep', glob: 'glob', webfetch: 'webfetch', websearch: 'websearch', | |
| agent: 'task', task: 'task', todowrite: 'todowrite', todoread: 'todoread', | |
| list: 'list', patch: 'patch' | |
| }; | |
| /** | |
| * ๋งํฌ๋ค์ด frontmatter๋ฅผ ๋จ์ ํ์ฑํ๋ค (์ธ๋ถ ์์กด์ฑ ์์ด key: value ํ ์ค ํ์๋ง). | |
| * Claude ์์ด์ ํธ ์ ์๋ ์ค์ฒฉ YAML์ ์ฐ์ง ์์ผ๋ฏ๋ก ์ด ์์ค์ด๋ฉด ์ถฉ๋ถํ๋ค. | |
| * @returns {{ meta: Object, body: string }|null} frontmatter ๋ถ์ฌ ์ null | |
| */ | |
| function parseFrontmatter(content) { | |
| const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/); | |
| if (!m) return null; | |
| const meta = {}; | |
| for (const line of m[1].split(/\r?\n/)) { | |
| const kv = line.match(/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/); | |
| if (kv) meta[kv[1]] = kv[2].trim(); | |
| } | |
| return { meta, body: m[2] || '' }; | |
| } | |
| /** ์ผํ ๊ตฌ๋ถ ํด ๋ชฉ๋ก ๋ฌธ์์ด โ opencode tools ๋งต ํญ๋ชฉ๋ค */ | |
| function mapToolList(listStr, enabled, toolsOut) { | |
| if (!listStr) return; | |
| for (const raw of String(listStr).split(',')) { | |
| const key = raw.trim().toLowerCase(); | |
| if (!key) continue; | |
| const mapped = TOOL_NAME_MAP[key]; | |
| if (mapped) toolsOut[mapped] = enabled; | |
| // ๋์ํ์ ์๋ ํด(claude ์ ์ฉ MCP ํด ๋ฑ)์ ์๋ต โ opencode๊ฐ ๋ชจ๋ฅด๋ ํค ์ฃผ์ ๋ฐฉ์ง | |
| } | |
| } | |
| /** | |
| * Claude ์์ด์ ํธ .md ํ ๊ฑด์ opencode ์์ด์ ํธ .md ๋ก ๋ณํํ๋ค. | |
| * @param {string} name ์์ด์ ํธ ์ด๋ฆ(ํ์ผ๋ช stem) | |
| * @param {string} content ์๋ณธ ํ์ผ ์ ์ฒด ๋ด์ฉ | |
| * @returns {string|null} ๋ณํ ๊ฒฐ๊ณผ (๋ณํ ๋ถ๊ฐ ์ null) | |
| */ | |
| function convertAgentMd(name, content) { | |
| const parsed = parseFrontmatter(content); | |
| if (!parsed) return null; | |
| const { meta, body } = parsed; | |
| if (!meta.description) return null; // opencode ์คํค๋ง์์ description์ ์ฌ์ค์ ํ์ | |
| const tools = {}; | |
| mapToolList(meta.tools, true, tools); | |
| mapToolList(meta.disallowedTools, false, tools); | |
| const srcHash = crypto.createHash('sha256').update(content).digest('hex').slice(0, 16); | |
| const fmLines = [ | |
| '---', | |
| // YAML ๋ฌธ์์ด ์์ ํ: ์๋ฐ์ดํ ์ด์ค์ผ์ดํ ํ ์ธ์ฉ | |
| `description: "${meta.description.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`, | |
| 'mode: subagent' | |
| ]; | |
| if (Object.keys(tools).length > 0) { | |
| fmLines.push('tools:'); | |
| for (const [k, v] of Object.entries(tools)) fmLines.push(` ${k}: ${v}`); | |
| } | |
| fmLines.push('---'); | |
| return `${fmLines.join('\n')}\n${MIRROR_MARKER} src=${name}.md hash=${srcHash} โ BADA๊ฐ ~/.claude/agents ์์ ์๋ ๋ฏธ๋ฌ๋ง. ์ง์ ์์ ๊ธ์ง -->\n\n${body.trim()}\n`; | |
| } | |
| /** | |
| * ~/.claude/agents/*.md ์ ์ฒด๋ฅผ opencode ๊ธ๋ก๋ฒ agent ๋๋ ํ ๋ฆฌ๋ก ๋ฏธ๋ฌ๋งํ๋ค. | |
| * ํ์ฑ CLI๊ฐ opencode๊ฐ ์๋๊ฑฐ๋ opencode ๋ฏธ์ค์น๋ฉด ์๋ฌด๊ฒ๋ ํ์ง ์๋๋ค. | |
| * @returns {{ synced: number, removed: number, skipped: number, reason?: string }} | |
| */ | |
| function syncClaudeAgentsToOpencode() { | |
| const result = { synced: 0, removed: 0, skipped: 0 }; | |
| const ctx = require('../context'); | |
| let activeCli; | |
| try { | |
| activeCli = ctx.getActiveCli(); | |
| } catch (e) { | |
| return { ...result, reason: 'ํ์ฑ CLI ํ์ธ ์คํจ: ' + e.message }; | |
| } | |
| if (activeCli !== 'opencode' && activeCli !== 'codeagent') { | |
| return { ...result, reason: 'ํ์ฑ CLI๊ฐ opencode/codeagent ์๋' }; | |
| } | |
| try { | |
| const ocHome = cliPaths.getCliPaths(activeCli).homeDir; | |
| if (!fs.existsSync(ocHome)) { | |
| return { ...result, reason: `${activeCli} ์ค์ ํ ๋ถ์ฌ: ${ocHome}` }; | |
| } | |
| const srcDir = path.join(os.homedir(), '.claude', 'agents'); | |
| const dstDir = path.join(ocHome, 'agent'); | |
| const srcFiles = fs.existsSync(srcDir) | |
| ? fs.readdirSync(srcDir).filter(f => f.endsWith('.md')) | |
| : []; | |
| fs.mkdirSync(dstDir, { recursive: true }); | |
| // 1) ์์ฑ/๊ฐฑ์ โ ์๋ณธ ํด์๊ฐ ๊ฐ์ผ๋ฉด ์คํต (๋ฉฑ๋ฑ) | |
| const validTargets = new Set(); | |
| for (const file of srcFiles) { | |
| try { | |
| const content = fs.readFileSync(path.join(srcDir, file), 'utf-8'); | |
| const converted = convertAgentMd(path.basename(file, '.md'), content); | |
| if (!converted) { result.skipped++; continue; } | |
| const dstPath = path.join(dstDir, file); | |
| validTargets.add(file); | |
| if (fs.existsSync(dstPath)) { | |
| const existing = fs.readFileSync(dstPath, 'utf-8'); | |
| if (!existing.includes(MIRROR_MARKER)) { | |
| // ๋๋ช ์ ์ฌ์ฉ์ ์ ์ ์์ด์ ํธ ์กด์ฌ โ ๋ฎ์ด์ฐ์ง ์๋๋ค (์์ ์์น 1) | |
| result.skipped++; | |
| continue; | |
| } | |
| if (existing === converted) continue; // ๋ณ๊ฒฝ ์์ | |
| } | |
| fs.writeFileSync(dstPath, converted, 'utf-8'); | |
| result.synced++; | |
| } catch (fileErr) { | |
| console.error(`[OpencodeAgentSync] ๋ณํ ์คํจ(๊ฑด๋๋): ${file} โ ${fileErr.message}`); | |
| result.skipped++; | |
| } | |
| } | |
| // 2) ๊ณ ์ ๋ฏธ๋ฌ ์ ๊ฑฐ โ ๋ง์ปค ์๋ ํ์ผ ์ค ์๋ณธ์ด ์ฌ๋ผ์ง ๊ฒ๋ง | |
| for (const file of fs.readdirSync(dstDir).filter(f => f.endsWith('.md'))) { | |
| try { | |
| if (validTargets.has(file)) continue; | |
| const content = fs.readFileSync(path.join(dstDir, file), 'utf-8'); | |
| if (content.includes(MIRROR_MARKER) && !fs.existsSync(path.join(srcDir, file))) { | |
| fs.unlinkSync(path.join(dstDir, file)); | |
| result.removed++; | |
| } | |
| } catch (orphanErr) { | |
| console.error(`[OpencodeAgentSync] ๊ณ ์ ์ ๋ฆฌ ์คํจ(๋ฌด์): ${file} โ ${orphanErr.message}`); | |
| } | |
| } | |
| if (result.synced > 0 || result.removed > 0) { | |
| console.log(`[OpencodeAgentSync] ${activeCli} ์๋ธ์์ด์ ํธ ๋ฏธ๋ฌ๋ง ์๋ฃ โ (๊ฐฑ์ ${result.synced}, ์ ๊ฑฐ ${result.removed}, ์คํต ${result.skipped})`); | |
| } | |
| return result; | |
| } catch (e) { | |
| console.error(`[OpencodeAgentSync] ${activeCli} ๋ฏธ๋ฌ๋ง ์คํจ(๋ฌด์ํ๊ณ ๊ณ์):`, e.message); | |
| return { ...result, reason: e.message }; | |
| } | |
| } | |
| module.exports = { syncClaudeAgentsToOpencode, convertAgentMd, parseFrontmatter }; | |