Skip to content

Commit c079b2c

Browse files
authored
fix: dispatch opencode commands via run (#2410)
1 parent 1049e17 commit c079b2c

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/specify_cli/integrations/opencode/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ class OpencodeIntegration(MarkdownIntegration):
1919
"extension": ".md",
2020
}
2121
context_file = "AGENTS.md"
22+
23+
def build_exec_args(
24+
self,
25+
prompt: str,
26+
*,
27+
model: str | None = None,
28+
output_json: bool = True,
29+
) -> list[str] | None:
30+
args = [self.key, "run"]
31+
32+
message = prompt
33+
if prompt.startswith("/"):
34+
command, _, remainder = prompt[1:].partition(" ")
35+
if command:
36+
args.extend(["--command", command])
37+
message = remainder
38+
39+
if model:
40+
args.extend(["-m", model])
41+
if output_json:
42+
args.extend(["--format", "json"])
43+
if message:
44+
args.append(message)
45+
return args

tests/integrations/test_integration_opencode.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for OpencodeIntegration."""
22

3+
from specify_cli.integrations import get_integration
4+
35
from .test_integration_base_markdown import MarkdownIntegrationTests
46

57

@@ -9,3 +11,49 @@ class TestOpencodeIntegration(MarkdownIntegrationTests):
911
COMMANDS_SUBDIR = "command"
1012
REGISTRAR_DIR = ".opencode/command"
1113
CONTEXT_FILE = "AGENTS.md"
14+
15+
def test_build_exec_args_uses_run_command_dispatch(self):
16+
integration = get_integration(self.KEY)
17+
18+
args = integration.build_exec_args(
19+
"/speckit.specify build a login page",
20+
output_json=False,
21+
)
22+
23+
assert args == [
24+
"opencode",
25+
"run",
26+
"--command",
27+
"speckit.specify",
28+
"build a login page",
29+
]
30+
assert "-p" not in args
31+
assert "--output-format" not in args
32+
33+
def test_build_exec_args_maps_model_and_json_flags(self):
34+
integration = get_integration(self.KEY)
35+
36+
args = integration.build_exec_args(
37+
"/speckit.plan add OAuth",
38+
model="anthropic/claude-sonnet-4",
39+
output_json=True,
40+
)
41+
42+
assert args == [
43+
"opencode",
44+
"run",
45+
"--command",
46+
"speckit.plan",
47+
"-m",
48+
"anthropic/claude-sonnet-4",
49+
"--format",
50+
"json",
51+
"add OAuth",
52+
]
53+
54+
def test_build_exec_args_keeps_plain_prompt_dispatch(self):
55+
integration = get_integration(self.KEY)
56+
57+
args = integration.build_exec_args("explain this repository", output_json=False)
58+
59+
assert args == ["opencode", "run", "explain this repository"]

0 commit comments

Comments
 (0)