From 0f5f6873ee0f28cd4f120e3b3a6a7cf90cddef2b Mon Sep 17 00:00:00 2001 From: Labish Bardiya Date: Thu, 19 Nov 2026 01:45:32 +0530 Subject: [PATCH] fix(opencode): ship missing command subagents --- scripts/build-opencode-agents.js | 54 ++++++++++++++++++ scripts/build-opencode.js | 1 + tests/opencode-review-agents.test.js | 85 ++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 scripts/build-opencode-agents.js create mode 100644 tests/opencode-review-agents.test.js diff --git a/scripts/build-opencode-agents.js b/scripts/build-opencode-agents.js new file mode 100644 index 000000000..5918a9634 --- /dev/null +++ b/scripts/build-opencode-agents.js @@ -0,0 +1,54 @@ +const fs = require('node:fs'); +const path = require('node:path'); +const yaml = require('js-yaml'); + +const repoRoot = path.resolve(__dirname, '..'); +const outputDir = path.join(repoRoot, '.opencode', 'agents'); +const agentNames = [ + 'code-simplifier', + 'comment-analyzer', + 'pr-test-analyzer', + 'silent-failure-hunter', + 'type-design-analyzer', + 'react-reviewer', + 'typescript-reviewer', + 'react-build-resolver', + 'vue-reviewer', + 'code-architect', + 'code-explorer', + 'fastapi-reviewer', + 'flutter-reviewer', + 'dart-build-resolver', + 'gan-planner', + 'gan-generator', + 'gan-evaluator', + 'conversation-analyzer', + 'marketing-agent', +]; + +fs.mkdirSync(outputDir, { recursive: true }); + +for (const name of agentNames) { + const sourcePath = path.join(repoRoot, 'agents', `${name}.md`); + const source = fs.readFileSync(sourcePath, 'utf8'); + const match = source.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/); + if (!match) throw new Error(`Expected YAML frontmatter in ${sourcePath}`); + + const [, frontmatter, prompt] = match; + const agent = yaml.load(frontmatter); + const tools = Array.isArray(agent.tools) + ? agent.tools + : String(agent.tools ?? '').split(',').map(tool => tool.trim()); + + const definition = { + description: agent.description, + mode: 'subagent', + permission: { + edit: tools.includes('Edit') || tools.includes('Write') ? 'allow' : 'deny', + bash: tools.includes('Bash') ? 'ask' : 'deny', + }, + }; + + const output = `---\n${yaml.dump(definition)}---\n${prompt}`; + fs.writeFileSync(path.join(outputDir, `${name}.md`), output); +} diff --git a/scripts/build-opencode.js b/scripts/build-opencode.js index 73610cd38..66286e9d2 100644 --- a/scripts/build-opencode.js +++ b/scripts/build-opencode.js @@ -24,3 +24,4 @@ execFileSync(process.execPath, [tscEntrypoint, "-p", path.join(opencodeDir, "tsc cwd: rootDir, stdio: "inherit", }) +require("./build-opencode-agents") diff --git a/tests/opencode-review-agents.test.js b/tests/opencode-review-agents.test.js new file mode 100644 index 000000000..13305d27a --- /dev/null +++ b/tests/opencode-review-agents.test.js @@ -0,0 +1,85 @@ +const assert = require('node:assert/strict'); +const { execFileSync } = require('node:child_process'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const test = require('node:test'); + +const agentsByCommand = { + 'review-pr': [ + 'code-reviewer', + 'comment-analyzer', + 'pr-test-analyzer', + 'silent-failure-hunter', + 'type-design-analyzer', + 'code-simplifier', + ], + 'react-review': ['react-reviewer', 'typescript-reviewer'], + 'react-test': ['react-reviewer'], + 'react-build': ['react-build-resolver'], + 'vue-review': ['vue-reviewer', 'typescript-reviewer'], + 'feature-dev': ['code-architect', 'code-explorer'], + 'orch-fix-defect': ['code-explorer'], + 'fastapi-review': ['fastapi-reviewer'], + 'flutter-review': ['flutter-reviewer'], + 'flutter-build': ['dart-build-resolver'], + 'flutter-test': ['dart-build-resolver', 'flutter-reviewer'], + 'gan-build': ['gan-planner', 'gan-generator', 'gan-evaluator'], + 'hookify': ['conversation-analyzer'], + 'marketing-campaign': ['marketing-agent'], +}; + +test('a full OpenCode install includes agents required by affected commands', () => { + const repoRoot = path.resolve(__dirname, '..'); + const home = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-review-agents-')); + const configHome = path.join(home, '.config'); + const installRoot = path.join(configHome, 'opencode'); + + try { + execFileSync(process.execPath, ['scripts/build-opencode.js'], { + cwd: repoRoot, + stdio: 'pipe', + }); + + execFileSync(process.execPath, [ + 'scripts/install-apply.js', + '--target', 'opencode', + '--profile', 'full', + '--no-hooks', + ], { + cwd: repoRoot, + env: { + ...process.env, + HOME: home, + USERPROFILE: home, + XDG_CONFIG_HOME: configHome, + OPENCODE_CONFIG_DIR: installRoot, + }, + stdio: ['ignore', 'ignore', 'pipe'], + }); + + const config = JSON.parse( + fs.readFileSync(path.join(installRoot, 'opencode.json'), 'utf8') + ); + const missing = []; + + for (const [command, agents] of Object.entries(agentsByCommand)) { + const commandFile = path.join(installRoot, 'commands', `${command}.md`); + assert.ok(fs.existsSync(commandFile), `Expected /${command} to be installed`); + + for (const name of agents) { + const hasAgentFile = ['agents', 'agent'].some(folder => + fs.existsSync(path.join(installRoot, folder, `${name}.md`)) + ); + + if (!Object.hasOwn(config.agent ?? {}, name) && !hasAgentFile) { + missing.push(`/${command} -> ${name}`); + } + } + } + + assert.deepEqual(missing, [], `Missing OpenCode agents: ${missing.join(', ')}`); + } finally { + fs.rmSync(home, { recursive: true, force: true }); + } +});