2026-04-01 09:17:21 -05:00
|
|
|
"""opencode integration."""
|
|
|
|
|
|
|
|
|
|
from ..base import MarkdownIntegration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OpencodeIntegration(MarkdownIntegration):
|
|
|
|
|
key = "opencode"
|
|
|
|
|
config = {
|
|
|
|
|
"name": "opencode",
|
|
|
|
|
"folder": ".opencode/",
|
2026-05-13 16:55:56 +02:00
|
|
|
"commands_subdir": "commands",
|
2026-04-01 09:17:21 -05:00
|
|
|
"install_url": "https://opencode.ai",
|
|
|
|
|
"requires_cli": True,
|
|
|
|
|
}
|
|
|
|
|
registrar_config = {
|
2026-05-13 16:55:56 +02:00
|
|
|
"dir": ".opencode/commands",
|
|
|
|
|
"legacy_dir": ".opencode/command",
|
2026-04-01 09:17:21 -05:00
|
|
|
"format": "markdown",
|
|
|
|
|
"args": "$ARGUMENTS",
|
|
|
|
|
"extension": ".md",
|
|
|
|
|
}
|
2026-04-29 17:39:45 +03:00
|
|
|
|
|
|
|
|
def build_exec_args(
|
|
|
|
|
self,
|
|
|
|
|
prompt: str,
|
|
|
|
|
*,
|
|
|
|
|
model: str | None = None,
|
|
|
|
|
output_json: bool = True,
|
|
|
|
|
) -> list[str] | None:
|
2026-05-29 10:19:31 -05:00
|
|
|
args = [self._resolve_executable(), "run"]
|
2026-05-29 02:00:15 +07:00
|
|
|
# Apply operator-injected extra args before the prompt-derived
|
|
|
|
|
# --command and the canonical --format/-m flags so Spec Kit's
|
|
|
|
|
# later appends remain authoritative under repeated-flag CLI
|
|
|
|
|
# semantics.
|
|
|
|
|
self._apply_extra_args_env_var(args)
|
2026-04-29 17:39:45 +03:00
|
|
|
|
|
|
|
|
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
|