Repository navigation
fix(claude): send a single user request to the CLI as written - #427
Open
JodyeJack (2vqmgh2pbd-cmyk) wants to merge 1 commit into
Open
JodyeJack (2vqmgh2pbd-cmyk) wants to merge 1 commit into
JodyeJack (2vqmgh2pbd-cmyk) wants to merge 1 commit into
Conversation
_build_prompt_from_messages rendered even a lone user message as a transcript: "History:", then "- User: " with every later line indented by two spaces, then "Answer the latest user request.". chat_target, chat_optimizer and chat_with_deployment always send exactly one user turn, so the target never saw the request as written, and whitespace-sensitive input such as code reached it re-indented. A single user turn with no tools and no structured output now goes to the CLI verbatim. Multi-turn, tool and structured-output calls keep the transcript form. So does a request that starts with "/": claude -p runs a known slash command such as /help without calling the model.
Contributor
|
JodyeJack (@2vqmgh2pbd-cmyk) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This branch has not been deployed
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.
Summary
claude_chatnow sends a single user turn with no tools and no structured output to the CLI as written, instead of as an indented transcript. Multi-turn, tool and structured-output calls keep the transcript form. So does a request that starts with/, becauseclaude -pruns a known slash command such as/helpwithout calling the model.User impact: every
chat_target(),chat_optimizer()andchat_with_deployment()call showed the model a transcript frame and re-indented text instead of the request. So did theclaude_code_execchat path, which shares the builder. The skill under optimization is the system prompt, and rollouts are scored on the target's replies, so the skill was tuned against a framing that deployment never uses. The fix changes what the target sees, so scores from earlierclaude_chatruns are not directly comparable.Proof: the two verbatim tests fail on
mainat22c1ed8and pass with this change; the four guard tests pass on both.Reproduce
On
main:With this change:
codex_backend.pybuilds its prompt the same way; this PR leaves it alone. Withclaude -p, a prompt of/helpreportsnum_turns: 0and never reaches the model, which is why a request that starts with/stays wrapped.Changes
_build_prompt_from_messages()returns the user text unchanged for a single user turn without tools or structured output, unless the text is empty or starts with/.tests/test_claude_backend_prompt.pycovers the verbatim case, the stdin and system prompt file thatchat_target()hands the CLI, and guards for the multi-turn, tool, structured, slash and empty cases.Tests
python -m pytest -qon macOS, rebased onmainat22c1ed8: 2348 passed (2342 onmain). The only failures are the two tests intests/test_sleep_adopt_skill_subset.pythat also fail onmainon macOS, where the temporary directory sits behind the/varsymlink.