Skip to content

A skill to stop your coding agent from burying the answer. ADHD-friendly output.

fix(opencode): register /i-have-adhd from plugin config for global installs (#140)

wakqasahmed21db42859f44
diff --git a/.opencode/plugins/i-have-adhd.mjs b/.opencode/plugins/i-have-adhd.mjs
index f0e9438..8b55f1b 100644
--- a/.opencode/plugins/i-have-adhd.mjs
+++ b/.opencode/plugins/i-have-adhd.mjs
@@ -23,6 +23,19 @@ 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 };
+}
// 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.
@@ -50,6 +63,20 @@ 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()).
+ try {
+ config.command = config.command || {};
+ if (!config.command['i-have-adhd']) {
+ config.command['i-have-adhd'] = commandDefinition();
+ }
+ } catch (e) {
+ // Missing/unreadable command file should not break config loading.
+ }
},
// Always-on: append the ruleset to the system prompt every turn while the
diff --git a/tests/opencode_plugin_driver.mjs b/tests/opencode_plugin_driver.mjs
index 943d286..1ea53fc 100644
--- a/tests/opencode_plugin_driver.mjs
+++ b/tests/opencode_plugin_driver.mjs
@@ -1,12 +1,26 @@
-// 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.
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 = {};
+ 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 --git a/tests/test_opencode_plugin.py b/tests/test_opencode_plugin.py
index c1a1c58..77fd9c9 100644
--- a/tests/test_opencode_plugin.py
+++ b/tests/test_opencode_plugin.py
@@ -1,3 +1,4 @@
+import json
import os
import shutil
import subprocess
@@ -24,15 +25,18 @@ class OpenCodePluginTest(unittest.TestCase):
self.config_dir = Path(self.temp_dir.name) / "config"
(self.config_dir / "opencode").mkdir(parents=True)
- def run_plugin(self):
+ def run_plugin(self, mode=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)
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,
@@ -65,6 +69,24 @@ class OpenCodePluginTest(unittest.TestCase):
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"])
+
if __name__ == "__main__":
unittest.main()