Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/specify_cli/integrations/opencode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions tests/integrations/test_integration_opencode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for OpencodeIntegration."""

from specify_cli.integrations import get_integration

from .test_integration_base_markdown import MarkdownIntegrationTests


Expand All @@ -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"]
Loading