Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/apm_cli/core/script_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _transform_runtime_command(
# Handle individual runtime patterns without environment variables

# Handle "codex [args] file.prompt.md [more_args]" -> "codex exec [args] [more_args]"
if re.search(r"codex\s+.*" + re.escape(prompt_file), command):
if re.search(r"(^|\s)codex\s+.*" + re.escape(prompt_file), command):
match = re.search(
r"codex\s+(.*?)(" + re.escape(prompt_file) + r")(.*?)$", command
Comment on lines +346 to 348
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated codex detection still matches codex anywhere in the command (as long as it’s preceded by whitespace). That means a copilot command like copilot --model codex -p hello-world.prompt.md would still hit this codex branch and be rewritten to codex exec ..., because codex -p hello-world.prompt.md satisfies the regex. Since this section is explicitly for commands without env-var prefixes, the codex transform should only trigger when codex is the leading command token (optionally after leading whitespace), and the extraction regex should be aligned to that same anchored shape.

Suggested change
if re.search(r"(^|\s)codex\s+.*" + re.escape(prompt_file), command):
match = re.search(
r"codex\s+(.*?)(" + re.escape(prompt_file) + r")(.*?)$", command
# Only trigger when 'codex' is the leading command token (optionally after whitespace)
if re.search(r"^\s*codex\s+.*" + re.escape(prompt_file), command):
match = re.search(
r"^\s*codex\s+(.*?)(" + re.escape(prompt_file) + r")(.*?)$", command

Copilot uses AI. Check for mistakes.
)
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/test_script_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ def test_transform_runtime_command_copilot_removes_p_flag(self):
original, "hello-world.prompt.md", self.compiled_content, self.compiled_path
)
assert result == "copilot --log-level all"


def test_transform_runtime_command_copilot_with_codex_in_model_name(self):
"""Test copilot command with --model flag containing 'codex' substring is not misidentified."""
original = "copilot --allow-all-tools --model gpt-5.3-codex -p hello-world.prompt.md"
result = self.script_runner._transform_runtime_command(
original, "hello-world.prompt.md", self.compiled_content, self.compiled_path
)
assert result == "copilot --allow-all-tools --model gpt-5.3-codex"
Comment on lines +118 to +124
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regression test covers the substring case (gpt-5.3-codex), but the current codex regex would still misidentify copilot if the model value is exactly codex (e.g., copilot --model codex -p hello-world.prompt.md). Adding a test for that case will prevent future regressions and will fail with the current implementation until the codex detection is tightened to only match when codex is the actual command token.

Copilot generated this review using guidance from repository custom instructions.

def test_detect_runtime_copilot(self):
"""Test runtime detection for copilot commands."""
assert self.script_runner._detect_runtime("copilot --log-level all") == "copilot"
Expand Down
Loading