Skip to content

Commit b1f8861

Browse files
hmohammadiclaude
andauthored
fix(integrations): dispatch Amp via execute mode (github#4581)
Fixes github#4580. `AmpIntegration` never overrode `build_exec_args()`, so it inherited `MarkdownIntegration`'s generic `-p <prompt> --model <model> --output-format json`. None of those flags exist in the Amp CLI, so every workflow `command:`/`prompt:` step targeting Amp aborted at argument parsing with `error: unknown option '-p'` before the agent ever ran. Amp's non-interactive entry point is `-x/--execute`, and its structured output flag is `--stream-json` (valid only alongside `--execute`), so this dispatches through those. `model` is deliberately dropped rather than remapped: Amp exposes no model-selection flag. `-m/--mode` takes an agent mode (low/medium/high/ ultra or a plugin mode), not a model identifier, so forwarding the caller's model onto it would silently select the wrong thing. Extra args from `SPECKIT_INTEGRATION_AMP_EXTRA_ARGS` are applied before `--execute` because the flag takes the prompt as an optional inline value; appending between the two would consume the prompt as the operator's flag value. Same fix shape as the one-off overrides for opencode (github#2409) and goose (github#3781). Part of the audit in github#2416. Claude-Session: https://claude.ai/code/session_01X8QcZkxX87sSjsfUzBRm9h Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 730dcf5 commit b1f8861

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Amp CLI integration."""
22

3+
from collections.abc import Mapping, Sequence
4+
from typing import Any
5+
36
from ..base import MarkdownIntegration
47

58

@@ -18,3 +21,32 @@ class AmpIntegration(MarkdownIntegration):
1821
"args": "$ARGUMENTS",
1922
"extension": ".md",
2023
}
24+
25+
def build_exec_args(
26+
self,
27+
prompt: str,
28+
*,
29+
model: str | None = None,
30+
output_json: bool = True,
31+
integration_args: Sequence[str] | None = None,
32+
integration_options: Mapping[str, Any] | None = None,
33+
) -> list[str] | None:
34+
self.validate_runtime_config(integration_args, integration_options)
35+
args = [self._resolve_executable()]
36+
# Operator-injected extra args go before --execute: the flag takes the
37+
# prompt as an optional inline value, so anything appended between the
38+
# two would be consumed as the message instead.
39+
self._apply_extra_args_env_var(args)
40+
41+
args.extend(["--execute", prompt])
42+
43+
if output_json:
44+
# Amp's structured output is --stream-json (Claude Code-compatible
45+
# stream JSON), valid only alongside --execute.
46+
args.append("--stream-json")
47+
48+
# `model` is deliberately dropped: Amp has no model-selection flag.
49+
# `-m/--mode` takes an agent mode (low/medium/high/ultra or a plugin
50+
# mode), not a model identifier, so forwarding the caller's model onto
51+
# it would silently select the wrong thing.
52+
return args

‎tests/integrations/test_integration_amp.py‎

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

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

57

@@ -8,3 +10,75 @@ class TestAmpIntegration(MarkdownIntegrationTests):
810
FOLDER = ".agents/"
911
COMMANDS_SUBDIR = "commands"
1012
REGISTRAR_DIR = ".agents/commands"
13+
14+
def test_build_exec_args_uses_execute_mode(self):
15+
"""Amp dispatches through execute mode, not the inherited `-p`.
16+
17+
The Amp CLI has no `-p`/`--prompt` flag; passing one aborts with
18+
`error: unknown option '-p'` before the agent runs (#4580).
19+
"""
20+
integration = get_integration(self.KEY)
21+
22+
args = integration.build_exec_args(
23+
"/speckit.specify build a login page",
24+
output_json=False,
25+
)
26+
27+
assert args == [
28+
"amp",
29+
"--execute",
30+
"/speckit.specify build a login page",
31+
]
32+
assert "-p" not in args
33+
34+
def test_build_exec_args_requests_stream_json(self):
35+
"""`--stream-json` is Amp's structured-output flag, used with --execute."""
36+
integration = get_integration(self.KEY)
37+
38+
args = integration.build_exec_args("/speckit.plan add OAuth", output_json=True)
39+
40+
assert args == [
41+
"amp",
42+
"--execute",
43+
"/speckit.plan add OAuth",
44+
"--stream-json",
45+
]
46+
assert "--output-format" not in args
47+
48+
def test_build_exec_args_omits_model_flag(self):
49+
"""Amp exposes no model-selection flag, so `model` is not forwarded.
50+
51+
`-m/--mode` takes an agent mode (low/medium/high/ultra), not a model
52+
identifier, so remapping the caller's model onto it would be wrong.
53+
"""
54+
integration = get_integration(self.KEY)
55+
56+
args = integration.build_exec_args(
57+
"explain this repository",
58+
model="gpt-5",
59+
output_json=False,
60+
)
61+
62+
assert args == ["amp", "--execute", "explain this repository"]
63+
assert "--model" not in args
64+
assert "-m" not in args
65+
assert "gpt-5" not in args
66+
67+
def test_build_exec_args_applies_extra_args_before_execute(self, monkeypatch):
68+
"""Operator-injected flags precede `--execute` so they stay global.
69+
70+
`--execute [message]` takes the prompt as an optional inline value, so
71+
injecting between the flag and the prompt would consume the prompt.
72+
"""
73+
monkeypatch.setenv("SPECKIT_INTEGRATION_AMP_EXTRA_ARGS", "--no-notifications")
74+
integration = get_integration(self.KEY)
75+
76+
args = integration.build_exec_args("check the build", output_json=True)
77+
78+
assert args == [
79+
"amp",
80+
"--no-notifications",
81+
"--execute",
82+
"check the build",
83+
"--stream-json",
84+
]

0 commit comments

Comments
 (0)