fix: preserve newlines in ACP command argument parsing#24008
Open
feisuzhu wants to merge 1 commit intoanomalyco:devfrom
Open
fix: preserve newlines in ACP command argument parsing#24008feisuzhu wants to merge 1 commit intoanomalyco:devfrom
feisuzhu wants to merge 1 commit intoanomalyco:devfrom
Conversation
split(/\s+/) + join(" ") collapsed all whitespace (including newlines)
in command arguments into single spaces. Use a regex match on the first
whitespace boundary instead, so the rest of the input is passed through
verbatim.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #24012
Type of change
What does this PR do?
ACP command argument parsing in
agent.tsdestroys newlines. When an ACP client sends a command like/pivot prometheus\nmy multi-line prompt, the argument text arrives with all newlines replaced by spaces.The bug is at the command extraction logic around line 1451. The old code does:
split(/\s+/)treats\n,\r,\tidentically to spaces — it splits the entire string on every whitespace character. Thenrest.join(" ")glues everything back with single spaces, losing the original whitespace structure.The fix splits only on the first whitespace boundary and passes the rest through verbatim:
(\S+)captures the command name (no whitespace).(?:\s([\s\S]*))?optionally matches one whitespace delimiter then captures everything after it — including newlines — as-is. The[\s\S]*with no flags is the standard JS idiom for "match anything including newlines". Only.trim()on the final args string removes leading/trailing whitespace, which is the same behavior as before for edge-trimming.How did you verify your code works?
Tested end-to-end with an in-house ACP client sending a multi-line prompt via
/pivot prometheus\n<53 lines of markdown>. (pivotis an custom tool that switches agent and then send the prompt) Before the fix, the prompt arrived at the plugin hook with all newlines collapsed to spaces. After the fix, newlines are preserved through the full pipeline:agent.ts→prompt.ts$ARGUMENTSsubstitution → plugincommand.execute.beforehook.Screenshots / recordings
N/A — backend text processing change, no UI impact.
Checklist