Skip to content

Commit 4d7fe7f

Browse files
jawwad-aliclaude
andcommitted
fix(integrations): dispatch goose commands via goose run (github#2416)
`YamlIntegration` never overrode `build_exec_args()`, so `GooseIntegration` inherited the `IntegrationBase` no-op that returns `None`. Callers read `None` as "this CLI is unavailable", so every workflow command/prompt step targeting Goose reported `CLI not found or not installed` even with `goose` on PATH. Reproduced with the agent CLI present on PATH (shutil.which stubbed to a real path, subprocess.run stubbed): amp -> completed argv=['amp', '-p', '/speckit.specify'] opencode -> completed argv=['opencode', 'run', '--command', 'speckit.specify'] goose -> FAILED "integration 'goose' CLI not found or not installed" Implement `build_exec_args()` for Goose. Per the goose CLI docs there is no `-p` flag; the non-interactive entry point is `goose run`, which takes `-t/--text` for free-form text, `--recipe` for a stored recipe, `--params KEY=VALUE` for recipe parameters, plus `--model` and `--output-format`. Spec Kit installs its commands as Goose *recipes* under `.goose/recipes/`, each declaring an optional `args` parameter (already enforced by test_setup_declares_args_parameter_for_args_prompt), so a `/speckit.<name> <rest>` invocation maps exactly onto `--recipe <path> --params args=<rest>`. This mirrors `OpencodeIntegration`, which maps the same leading slash-command onto opencode's `--command`. The recipe path is derived from the same two sources `setup()` uses -- `config["folder"]` + `config["commands_subdir"]` and `command_filename()` -- so the dispatch target cannot drift from the installed file; a test asserts the resolved `--recipe` path exists after `setup()`. Dotted extension commands (`speckit.git.commit`) round-trip. Extra args are applied before the canonical flags so Spec Kit's selection stays authoritative, matching opencode. No behaviour change for other integrations, and `requires_cli` is untouched. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 655a3cb commit 4d7fe7f

3 files changed

Lines changed: 168 additions & 0 deletions

File tree

‎src/specify_cli/integrations/goose/__init__.py‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Goose integration — open source AI agent (Agentic AI Foundation)."""
22

3+
from __future__ import annotations
4+
35
from ..base import YamlIntegration
46

57

@@ -18,3 +20,74 @@ class GooseIntegration(YamlIntegration):
1820
"args": "{{args}}",
1921
"extension": ".yaml",
2022
}
23+
24+
def build_exec_args(
25+
self,
26+
prompt: str,
27+
*,
28+
model: str | None = None,
29+
output_json: bool = True,
30+
) -> list[str] | None:
31+
"""Build CLI arguments for non-interactive ``goose`` execution.
32+
33+
``YamlIntegration`` never overrode ``build_exec_args()``, so Goose
34+
inherited the ``IntegrationBase`` no-op returning ``None``. Callers read
35+
``None`` as "this CLI is unavailable", so a workflow command/prompt step
36+
targeting Goose reported ``CLI not found or not installed`` even with
37+
``goose`` on ``PATH`` (the Goose item in issue #2416).
38+
39+
``goose`` has no ``-p`` flag; its non-interactive entry point is
40+
``goose run``, which takes ``-t/--text`` for free-form text,
41+
``--recipe`` for a stored recipe, ``--params KEY=VALUE`` for recipe
42+
parameters, plus ``--model`` and ``--output-format``.
43+
44+
Spec Kit installs its commands as Goose *recipes* under
45+
``.goose/recipes/``, each declaring an optional ``args`` string
46+
parameter, so a ``/speckit.<name> <rest>`` invocation maps onto
47+
``--recipe <path> --params args=<rest>``. This mirrors
48+
``OpencodeIntegration``, which maps the same leading slash-command onto
49+
opencode's native ``--command``.
50+
"""
51+
args = [self._resolve_executable(), "run"]
52+
# Operator-injected extra args land before Spec Kit's canonical flags so
53+
# --model/--output-format stay authoritative under repeated-flag CLI
54+
# semantics (mirrors OpencodeIntegration).
55+
self._apply_extra_args_env_var(args)
56+
57+
if model:
58+
args.extend(["--model", model])
59+
if output_json:
60+
args.extend(["--output-format", "json"])
61+
62+
if prompt.startswith("/"):
63+
command, _, remainder = prompt[1:].partition(" ")
64+
if command:
65+
# Derive the recipe path from the same two sources ``setup()``
66+
# uses -- ``config["folder"]`` + ``config["commands_subdir"]``
67+
# (exactly what ``commands_dest()`` does) and
68+
# ``command_filename()`` -- so the dispatch target cannot drift
69+
# from the file that was actually installed.
70+
# ``command_filename`` re-adds the ``speckit.`` prefix and the
71+
# ``.yaml`` extension, so strip the prefix first; a dotted
72+
# extension command (``speckit.git.commit``) round-trips too.
73+
stem = (
74+
command[len("speckit."):]
75+
if command.startswith("speckit.")
76+
else command
77+
)
78+
folder = (self.config.get("folder") or "").strip("/")
79+
subdir = (self.config.get("commands_subdir") or "").strip("/")
80+
# Relative, forward-slash path: dispatch runs with
81+
# ``cwd=project_root``, and goose accepts a POSIX separator on
82+
# every platform (``commands_dest()`` yields backslashes on
83+
# win32).
84+
parts = [
85+
p for p in (folder, subdir, self.command_filename(stem)) if p
86+
]
87+
args.extend(["--recipe", "/".join(parts)])
88+
if remainder.strip():
89+
args.extend(["--params", f"args={remainder}"])
90+
return args
91+
92+
args.extend(["-t", prompt])
93+
return args

‎tests/integrations/test_extra_args.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,39 @@ def test_executable_env_var_devin_integration(monkeypatch):
565565
assert args[0] == "/opt/devin"
566566

567567

568+
def test_goose_integration_honours_extra_args(monkeypatch):
569+
"""Goose gained ``build_exec_args()`` (the Goose item in #2416), so it must
570+
honour the shared extra-args hook like every other dispatching integration."""
571+
from specify_cli.integrations.goose import GooseIntegration
572+
573+
monkeypatch.setenv("SPECKIT_INTEGRATION_GOOSE_EXTRA_ARGS", "--debug")
574+
args = GooseIntegration().build_exec_args("hi", output_json=False)
575+
assert args == ["goose", "run", "--debug", "-t", "hi"]
576+
577+
578+
def test_goose_extra_args_cannot_clobber_prompt_derived_recipe(monkeypatch):
579+
"""Operator-injected extra args must appear BEFORE the prompt-derived
580+
``--recipe`` so Spec Kit's command selection wins under repeated-flag CLI
581+
semantics (mirrors the opencode ``--command`` guarantee above)."""
582+
from specify_cli.integrations.goose import GooseIntegration
583+
584+
monkeypatch.setenv("SPECKIT_INTEGRATION_GOOSE_EXTRA_ARGS", "--recipe evil.yaml")
585+
args = GooseIntegration().build_exec_args("/speckit.specify", output_json=False)
586+
assert args.index("evil.yaml") < args.index(
587+
".goose/recipes/speckit.specify.yaml"
588+
)
589+
590+
591+
def test_executable_env_var_goose_integration(monkeypatch):
592+
"""GooseIntegration honours the executable env var."""
593+
from specify_cli.integrations.goose import GooseIntegration
594+
595+
monkeypatch.setenv("SPECKIT_INTEGRATION_GOOSE_EXECUTABLE", "/opt/goose")
596+
args = GooseIntegration().build_exec_args("hi")
597+
assert args[0] == "/opt/goose"
598+
assert args[1] == "run"
599+
600+
568601
def test_executable_env_var_opencode_integration(monkeypatch):
569602
"""OpencodeIntegration honours the executable env var."""
570603
from specify_cli.integrations.opencode import OpencodeIntegration

‎tests/integrations/test_integration_goose.py‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,65 @@ def test_register_commands_resolves_placeholders_in_recipe(self, tmp_path):
8383
assert "{SCRIPT}" not in prompt
8484
assert "__AGENT__" not in prompt
8585
assert "$ARGUMENTS" not in prompt
86+
87+
88+
class TestGooseCliDispatch:
89+
"""`goose` must produce argv for non-interactive dispatch.
90+
91+
`YamlIntegration` never overrode `build_exec_args()`, so Goose inherited the
92+
`IntegrationBase` no-op returning `None`. Callers read `None` as "CLI
93+
unavailable", so a workflow command/prompt step targeting Goose reported
94+
"CLI not found or not installed" even with `goose` on PATH — the Goose item
95+
in issue #2416. `goose run` supports `-t/--text`, `--recipe`,
96+
`--params KEY=VALUE`, `--model` and `--output-format`.
97+
"""
98+
99+
def test_build_exec_args_is_not_none(self):
100+
integration = get_integration("goose")
101+
assert integration.build_exec_args("/speckit.specify") is not None
102+
103+
def test_slash_command_maps_to_recipe(self):
104+
integration = get_integration("goose")
105+
args = integration.build_exec_args("/speckit.specify", output_json=False)
106+
assert args[1] == "run"
107+
assert "--recipe" in args
108+
assert args[args.index("--recipe") + 1] == ".goose/recipes/speckit.specify.yaml"
109+
# No trailing args -> no --params
110+
assert "--params" not in args
111+
112+
def test_slash_command_arguments_map_to_params(self):
113+
integration = get_integration("goose")
114+
args = integration.build_exec_args("/speckit.specify add auth", output_json=False)
115+
assert args[args.index("--params") + 1] == "args=add auth"
116+
117+
def test_dotted_extension_command_maps_to_recipe(self):
118+
integration = get_integration("goose")
119+
args = integration.build_exec_args("/speckit.git.commit msg", output_json=False)
120+
assert args[args.index("--recipe") + 1] == (
121+
".goose/recipes/speckit.git.commit.yaml"
122+
)
123+
124+
def test_free_form_prompt_uses_text_flag(self):
125+
"""goose has no `-p`; free-form text goes to `-t/--text`."""
126+
integration = get_integration("goose")
127+
args = integration.build_exec_args("just do it", output_json=False)
128+
assert args[-2:] == ["-t", "just do it"]
129+
assert "--recipe" not in args
130+
131+
def test_model_and_output_format_flags(self):
132+
integration = get_integration("goose")
133+
args = integration.build_exec_args("hi", model="gpt-4o", output_json=True)
134+
assert args[args.index("--model") + 1] == "gpt-4o"
135+
assert args[args.index("--output-format") + 1] == "json"
136+
137+
def test_recipe_target_matches_what_setup_writes(self, tmp_path):
138+
"""Anti-drift: the dispatched `--recipe` path must be the file `setup()`
139+
actually installed, so the two cannot diverge."""
140+
integration = get_integration("goose")
141+
manifest = IntegrationManifest("goose", tmp_path)
142+
created = integration.setup(tmp_path, manifest, script_type="sh")
143+
assert created
144+
145+
args = integration.build_exec_args("/speckit.specify hello")
146+
recipe = args[args.index("--recipe") + 1]
147+
assert (tmp_path / recipe).is_file(), f"{recipe} was not installed by setup()"

0 commit comments

Comments
 (0)