Skip to content

fix: preserve newlines in ACP command argument parsing#24008

Open
feisuzhu wants to merge 1 commit intoanomalyco:devfrom
feisuzhu:fix-acp-command-parsing
Open

fix: preserve newlines in ACP command argument parsing#24008
feisuzhu wants to merge 1 commit intoanomalyco:devfrom
feisuzhu:fix-acp-command-parsing

Conversation

@feisuzhu
Copy link
Copy Markdown

@feisuzhu feisuzhu commented Apr 23, 2026

Issue for this PR

Closes #24012

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ACP command argument parsing in agent.ts destroys 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:

const [name, ...rest] = text.slice(1).split(/\s+/)
return { name, args: rest.join(" ").trim() }

split(/\s+/) treats \n, \r, \t identically to spaces — it splits the entire string on every whitespace character. Then rest.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:

const match = text.slice(1).match(/^(\S+)(?:\s([\s\S]*))?$/)
if (!match) return
return { name: match[1], args: (match[2] ?? "").trim() }

(\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>. (pivot is 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.tsprompt.ts $ARGUMENTS substitution → plugin command.execute.before hook.

Screenshots / recordings

N/A — backend text processing change, no UI impact.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Newlines in command should be preserved in ACP mode

1 participant