A skill to stop your coding agent from burying the answer. ADHD-friendly output.
fix(opencode): share JSON command metadata with the native loader
ayghrid1634a63cb51
diff --cc .opencode/command/i-have-adhd.mdindex 6016fae,6016fae..7ab0e00--- a/.opencode/command/i-have-adhd.md+++ b/.opencode/command/i-have-adhd.md@@@ -1,5 -1,5 +1,5 @@@-----description: Shape output for a reader with ADHD for the rest of this session++{"description": "Shape output for a reader with ADHD for the rest of this session"}---Use the `i-have-adhd` skill and apply its ruleset to every response for thediff --cc .opencode/plugins/i-have-adhd.mjsindex 8b55f1b,f0e9438..310b263--- a/.opencode/plugins/i-have-adhd.mjs+++ b/.opencode/plugins/i-have-adhd.mjs@@@ -23,19 -23,6 +23,15 @@@ import { fileURLToPath } from 'url'const __dirname = path.dirname(fileURLToPath(import.meta.url));const skillsDir = path.resolve(__dirname, '../../skills');const skillPath = path.join(skillsDir, 'i-have-adhd', 'SKILL.md');+const commandPath = path.join(__dirname, '..', 'command', 'i-have-adhd.md');+- // Parse the project-scope command file (frontmatter description + template- // body) so the global-install route gets the same command without a second- // copy of the text to keep in sync.- function commandDefinition() {- const raw = fs.readFileSync(commandPath, 'utf8');- const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---[^\S\r\n]*(?:\r?\n|$)([\s\S]*)$/);- if (!match) return { description: undefined, template: raw };- const [, frontmatter, template] = match;- const description = frontmatter.match(/^description:\s*(.+)$/m)?.[1]?.trim();- return { description, template };++// JSON is valid YAML frontmatter; share native command metadata without a YAML dependency.++async function commandDefinition() {++ const raw = await fs.promises.readFile(commandPath, 'utf8');++ const match = raw.match(/^---[^\S\r\n]*\r?\n([\s\S]*?)\r?\n---[^\S\r\n]*(?:\r?\n|$)([\s\S]*)$/);++ if (!match) throw new Error('Missing command frontmatter');++ return { ...JSON.parse(match[1]), template: match[2].trim() };+}// Always-on opt-in flag, mirroring Claude Code's ~/.claude/.i-have-adhd-always// but under OpenCode's config dir so the two tools stay independent.@@@ -63,20 -50,6 +59,16 @@@ export default async () =>config.skills = config.skills || {};config.skills.paths = config.skills.paths || [];if (!config.skills.paths.includes(skillsDir)) config.skills.paths.push(skillsDir);+- // Register /i-have-adhd directly from the plugin config so a global- // install (plugin path outside the checkout, opencode run from an- // unrelated project) gets the command too. Project-scope runs also- // pick up .opencode/command/i-have-adhd.md natively; whichever loads- // first wins, and both carry the same text (see commandDefinition()).++ // Global installs need a command entry; preserve native or user-defined commands.+ try {+ config.command = config.command || {};+ if (!config.command['i-have-adhd']) {- config.command['i-have-adhd'] = commandDefinition();++ config.command['i-have-adhd'] = await commandDefinition();+ }+ } catch (e) {- // Missing/unreadable command file should not break config loading.++ // Missing or malformed command files must not break skill discovery.+ }},// Always-on: append the ruleset to the system prompt every turn while thediff --cc CONTRIBUTING.mdindex 9d95b66,9d95b66..cecd11d--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@@ -74,6 -74,6 +74,8 @@@ cmp skills/i-have-adhd/SKILL.md .cursorReview platform-specific manifests and documentation whenever shared names, descriptions, paths, or behavior change.++Keep `.opencode/command/i-have-adhd.md` frontmatter as a JSON object between the `---` delimiters. JSON is valid YAML, so OpenCode's native loader and the global plugin can share the same command metadata without an additional parser dependency.++## VerificationRun relevant checks and include the commands and results in the PR. For Python and evaluation-harness changes:diff --cc tests/opencode_plugin_driver.mjsindex 1ea53fc,943d286..70421d1--- a/tests/opencode_plugin_driver.mjs+++ b/tests/opencode_plugin_driver.mjs@@@ -1,26 -1,12 +1,27 @@@-// Test driver for the OpenCode plugin. Imports the plugin at argv[2], runs its-// `experimental.chat.system.transform` hook against an empty system prompt, and-// prints the resulting system text so tests can assert on the injected banner.-// Nothing is printed when the hook injects nothing (always-on flag absent).+// Test driver for the OpenCode plugin. Imports the plugin at argv[2] and runs+// one of its hooks depending on argv[3]:+//+// (default) runs `experimental.chat.system.transform` against an empty+// system prompt and prints the resulting system text so tests+// can assert on the injected banner. Nothing is printed when the+// hook injects nothing (always-on flag absent).- // config runs the `config` hook against an empty config object and- // prints the resulting config as JSON, so tests can assert on- // registered skills/commands without a running OpenCode server.++// config runs the `config` hook twice, seeded by optional JSON at argv[4],++// and prints the resulting config to check registration, overrides,++// and idempotency without a running OpenCode server.import { pathToFileURL } from 'node:url';const pluginPath = process.argv[2];+const mode = process.argv[3];const { default: init } = await import(pathToFileURL(pluginPath).href);const hooks = await init();-const output = { system: [] };-await hooks['experimental.chat.system.transform']({}, output);-process.stdout.write(output.system.join('\n---SEP---\n'));++if (mode === 'config') {- const config = {};++ const config = JSON.parse(process.argv[4] || "{}");++ await hooks.config(config);+ await hooks.config(config);+ process.stdout.write(JSON.stringify(config));+} else {+ const output = { system: [] };+ await hooks['experimental.chat.system.transform']({}, output);+ process.stdout.write(output.system.join('\n---SEP---\n'));+}diff --cc tests/test_opencode_plugin.pyindex 77fd9c9,c1a1c58..816ba47--- a/tests/test_opencode_plugin.py+++ b/tests/test_opencode_plugin.py@@@ -25,18 -24,15 +25,20 @@@ class OpenCodePluginTest(unittest.TestCself.config_dir = Path(self.temp_dir.name) / "config"(self.config_dir / "opencode").mkdir(parents=True)- def run_plugin(self, mode=None):- def run_plugin(self):++ def run_plugin(self, mode=None, config=None):env = os.environ.copy()env["XDG_CONFIG_HOME"] = str(self.config_dir)+ args = [+ "node",+ str(ROOT / "tests" / "opencode_plugin_driver.mjs"),+ str(self.plugin_root / ".opencode" / "plugins" / "i-have-adhd.mjs"),+ ]+ if mode:+ args.append(mode)++ if config is not None:++ args.append(json.dumps(config))return subprocess.run(- [- "node",- str(ROOT / "tests" / "opencode_plugin_driver.mjs"),- str(self.plugin_root / ".opencode" / "plugins" / "i-have-adhd.mjs"),- ],+ args,check=False,capture_output=True,text=True,@@@ -69,24 -65,6 +71,65 @@@self.assertEqual(0, result.returncode, result.stderr)self.assertIn("Fixture body, fence never closed.", result.stdout)+ def test_config_hook_registers_the_slash_command(self):+ # Regression test for #140: a global install (plugin loaded from a+ # path outside any checkout, no project-scope .opencode/command/+ # directory in play) must still get /i-have-adhd, because OpenCode's+ # skill-sourced commands are not surfaced in the TUI's `/` menu.+ result = self.run_plugin(mode="config")+ self.assertEqual(0, result.returncode, result.stderr)+ config = json.loads(result.stdout)+ command = config["command"]["i-have-adhd"]+ self.assertIn("ADHD", command["description"])+ self.assertIn("stop adhd mode", command["template"])++ def test_config_hook_still_registers_the_skills_path(self):+ result = self.run_plugin(mode="config")+ self.assertEqual(0, result.returncode, result.stderr)+ config = json.loads(result.stdout)+ self.assertIn(str(self.plugin_root / "skills"), config["skills"]["paths"])+++ def test_config_preserves_existing_command(self):++ custom = {"description": "User command", "template": "Keep this", "agent": "plan"}++ result = self.run_plugin("config", {"command": {"i-have-adhd": custom}})++ self.assertEqual(0, result.returncode, result.stderr)++ self.assertEqual(custom, json.loads(result.stdout)["command"]["i-have-adhd"])++++ def test_repeated_config_does_not_duplicate_skill_paths(self):++ result = self.run_plugin("config")++ self.assertEqual(0, result.returncode, result.stderr)++ self.assertEqual([str(self.plugin_root / "skills")], json.loads(result.stdout)["skills"]["paths"])++++ def test_command_preserves_metadata_and_trims_template(self):++ metadata = {"description": 'ADHD: "focus"\nnext line', "agent": "plan",++ "model": "fixture/model", "subtask": True}++ command = self.plugin_root / ".opencode/command/i-have-adhd.md"++ command.write_bytes(("--- \r\n" + json.dumps(metadata) +++ "\r\n--- \t\r\n\r\nUse the skill.\r\n\r\n").encode())++ result = self.run_plugin("config")++ self.assertEqual(0, result.returncode, result.stderr)++ self.assertEqual({**metadata, "template": "Use the skill."},++ json.loads(result.stdout)["command"]["i-have-adhd"])++++ def test_missing_command_keeps_skill_discovery(self):++ (self.plugin_root / ".opencode/command/i-have-adhd.md").unlink()++ result = self.run_plugin("config")++ self.assertEqual(0, result.returncode, result.stderr)++ config = json.loads(result.stdout)++ self.assertNotIn("i-have-adhd", config["command"])++ self.assertEqual([str(self.plugin_root / "skills")], config["skills"]["paths"])++++ def test_malformed_command_does_not_leak_frontmatter_into_prompt(self):++ command = self.plugin_root / ".opencode/command/i-have-adhd.md"++ for text in ["---\n{broken}\n---\nBody", '---\n{"description":"unclosed"}\nBody']:++ with self.subTest(text=text):++ command.write_text(text)++ result = self.run_plugin("config")++ self.assertEqual(0, result.returncode, result.stderr)++ config = json.loads(result.stdout)++ self.assertNotIn("i-have-adhd", config["command"])++ self.assertEqual([str(self.plugin_root / "skills")], config["skills"]["paths"])++if __name__ == "__main__":unittest.main()