Repository navigation
fix(extensions): keep TOML command prompts identical to the body - #5570
Merged
Merged
Conversation
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)
Contributor
There was a problem hiding this comment.
🟢 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)
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CommandRegistrar.render_toml_commandwrites the multiline prompt forms with the closing delimiter on its own line:TOML only trims the newline right after the opening delimiter, so the parsed
promptis 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 coreTomlIntegration._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, thenspecify extension add --dev ./extwithcommands/hello.md=---\ndescription: Say hello\n---\n\nSay hello to {{args}}\n.tomllibreads.gemini/commands/speckit.tomldemo.hello.tomlasprompt == "Say hello to {{args}}\n", while the core.gemini/commands/speckit.plan.tomlprompt 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
.venvand 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 andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
New parametrized test in
tests/test_extensions.pyassertingtomllib.loads(output)["prompt"] == bodyexactly, 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 comparedprompt.strip(), which hid the extra newline; they now compare exactly. On main these 12 cases fail; with the fix allrender_toml_commandtests pass.Full suite with
-n autoon 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 --devreproduction above, before and after.AI Disclosure
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.