Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix: dispatch opencode commands via run (#2410)

Andrii Furmanetsc079b2cc320c
diff --git a/src/specify_cli/integrations/opencode/__init__.py b/src/specify_cli/integrations/opencode/__init__.py
index be4dcc309..17db2bd11 100644
--- a/src/specify_cli/integrations/opencode/__init__.py
+++ b/src/specify_cli/integrations/opencode/__init__.py
@@ -19,3 +19,27 @@ class OpencodeIntegration(MarkdownIntegration):
"extension": ".md",
}
context_file = "AGENTS.md"
+
+ def build_exec_args(
+ self,
+ prompt: str,
+ *,
+ model: str | None = None,
+ output_json: bool = True,
+ ) -> list[str] | None:
+ args = [self.key, "run"]
+
+ message = prompt
+ if prompt.startswith("/"):
+ command, _, remainder = prompt[1:].partition(" ")
+ if command:
+ args.extend(["--command", command])
+ message = remainder
+
+ if model:
+ args.extend(["-m", model])
+ if output_json:
+ args.extend(["--format", "json"])
+ if message:
+ args.append(message)
+ return args
diff --git a/tests/integrations/test_integration_opencode.py b/tests/integrations/test_integration_opencode.py
index 4f3aee5d9..427fd1516 100644
--- a/tests/integrations/test_integration_opencode.py
+++ b/tests/integrations/test_integration_opencode.py
@@ -1,5 +1,7 @@
"""Tests for OpencodeIntegration."""
+from specify_cli.integrations import get_integration
+
from .test_integration_base_markdown import MarkdownIntegrationTests
@@ -9,3 +11,49 @@ class TestOpencodeIntegration(MarkdownIntegrationTests):
COMMANDS_SUBDIR = "command"
REGISTRAR_DIR = ".opencode/command"
CONTEXT_FILE = "AGENTS.md"
+
+ def test_build_exec_args_uses_run_command_dispatch(self):
+ integration = get_integration(self.KEY)
+
+ args = integration.build_exec_args(
+ "/speckit.specify build a login page",
+ output_json=False,
+ )
+
+ assert args == [
+ "opencode",
+ "run",
+ "--command",
+ "speckit.specify",
+ "build a login page",
+ ]
+ assert "-p" not in args
+ assert "--output-format" not in args
+
+ def test_build_exec_args_maps_model_and_json_flags(self):
+ integration = get_integration(self.KEY)
+
+ args = integration.build_exec_args(
+ "/speckit.plan add OAuth",
+ model="anthropic/claude-sonnet-4",
+ output_json=True,
+ )
+
+ assert args == [
+ "opencode",
+ "run",
+ "--command",
+ "speckit.plan",
+ "-m",
+ "anthropic/claude-sonnet-4",
+ "--format",
+ "json",
+ "add OAuth",
+ ]
+
+ def test_build_exec_args_keeps_plain_prompt_dispatch(self):
+ integration = get_integration(self.KEY)
+
+ args = integration.build_exec_args("explain this repository", output_json=False)
+
+ assert args == ["opencode", "run", "explain this repository"]