Skip to content

fix(extensions): keep TOML command prompts identical to the body - #5570

Merged
mnriem merged 1 commit into
github:mainfrom
leninworld:fix/toml-command-prompt-newline
Nov 25, 2026
Merged

mnriem merged 1 commit into
github:mainfrom
leninworld:fix/toml-command-prompt-newline

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Description

CommandRegistrar.render_toml_command writes the multiline prompt forms with the closing delimiter on its own line:

prompt = """
Say hello to {{args}}
"""

TOML only trims the newline right after the opening delimiter, so the parsed prompt is the body plus "\n" (an empty body becomes "\n"). This affects every extension and preset command rendered for a TOML agent (Gemini, Tabnine). The escaped basic string branches of the same function already round-trip the body exactly, and the core TomlIntegration._render_toml (#2096) deliberately does not add a trailing newline, so core and extension commands disagree today.

Reproduction on main: specify init --here --integration gemini --ignore-agent-tools, then specify extension add --dev ./ext with commands/hello.md = ---\ndescription: Say hello\n---\n\nSay hello to {{args}}\n. tomllib reads .gemini/commands/speckit.tomldemo.hello.toml as prompt == "Say hello to {{args}}\n", while the core .gemini/commands/speckit.plan.toml prompt has no trailing newline. With this change the extension prompt is "Say hello to {{args}}".

The fix closes the multiline string right after the body, following TomlIntegration._render_toml_string: a body ending in " gets a line-ending backslash before """ so the file stays valid, and a literal (''') body ending in ' falls back to the escaped basic string. Branch selection, control-character handling and the rest of the output are unchanged. As before, a CRLF inside a multiline string reads back as LF (TOML allows parsers to normalize newlines); command files are read with universal newlines, so bodies reaching the renderer use LF.

Testing

Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.

  • Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)

  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS

  • Tested with a sample project (if applicable)

  • New parametrized test in tests/test_extensions.py asserting tomllib.loads(output)["prompt"] == body exactly, and which string form was used, for: a single line, an empty body, a trailing newline, a leading newline, a trailing " and "", a multi-line body, a backslash body ('''), a backslash body ending in ' and a body with """ ending in ' (escaped basic string). The two existing backslash tests compared prompt.strip(), which hid the extra newline; they now compare exactly. On main these 12 cases fail; with the fix all render_toml_command tests pass.

  • Full suite with -n auto on macOS: 17258 passed, 635 skipped, 1 failed: test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, which fails on main in my environment too.

  • uvx ruff@0.15.0 check src tests: all checks passed.

  • Sample project: the specify init / specify extension add --dev reproduction above, before and after.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: The bug was found by OpenAI Codex CLI (model: gpt-5.6-sol, medium reasoning, autonomous, read-only code review), which also wrote the fix and tests (code generation). Claude Code (model: Claude Opus 5.5, autonomous) reproduced the bug end to end, reviewed the change, ran the tests and lint, and wrote this description. The commit carries Assisted-by: trailers.

render_toml_command put the closing """ or ''' on its own line, so the
parsed prompt of every extension or preset command rendered for a TOML
agent (gemini, tabnine) gained a trailing newline, and an empty body
became "\n". The escaped basic string branches of the same function
already round-trip the body exactly, and the core TomlIntegration
renderer does not force a trailing newline either.

Close the multiline strings right after the body, so an LF body
round-trips exactly. A body ending in a
double quote gets a line-ending backslash before the closing delimiter;
a literal body ending in a single quote falls back to the escaped basic
string, matching TomlIntegration._render_toml_string.

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
@leninworld
leninworld requested a review from mnriem as a code owner November 25, 2026 16:20
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the TOML prompt-preservation change, though the reported regression tests were not independently rerun.

No open issues 🎉

What changed in this PR

This PR aligns extension and preset TOML prompts with core integrations by preserving the command body without adding a trailing newline.

Changes:

  • Close multiline TOML strings immediately after the body, with safe handling for trailing quotes.
  • Add exact round-trip regression cases and remove whitespace trimming from existing assertions.

Regression results are reported in the PR; tests were not independently rerun.

File Description
tests/​test_extensions.py Adds exact prompt comparisons covering whitespace, quotes, and backslashes.
src/​specify_cli/​agents.py Prevents added trailing newlines while preserving valid TOML string delimiters.

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the TOML prompt-rendering changes, though reported regression results were not independently verified.

No open issues 🎉

Review effort: Balanced

@mnriem
mnriem merged commit 3df7575 into github:main Nov 25, 2026
14 checks passed
@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants