Skip to content

fix(acp): route shell commands through terminal args#1393

Open
hanhan3344 wants to merge 2 commits intoMoonshotAI:mainfrom
hanhan3344:fix/acp-shell-terminal-command-args
Open

fix(acp): route shell commands through terminal args#1393
hanhan3344 wants to merge 2 commits intoMoonshotAI:mainfrom
hanhan3344:fix/acp-shell-terminal-command-args

Conversation

@hanhan3344
Copy link

@hanhan3344 hanhan3344 commented Mar 10, 2026

Summary

  • fix ACP Shell terminal execution to pass the shell executable in command and the shell invocation in args
  • adapt the ACP terminal integration to the current ACP SDK response shape using terminal_id
  • add a regression test covering bash and PowerShell command/args routing

Problem

When kimi acp was used behind ACP clients with terminal support, Shell commands like echo test could fail with errors like:

  • spawn echo test ENOENT
  • spawn ls -la ENOENT

The ACP terminal adapter passed the entire shell command string as terminal/create.command, which made clients try to spawn the full string as an executable path.

The adapter also assumed create_terminal() returned a TerminalHandle, but the current ACP SDK returns a response containing terminal_id, with follow-up terminal operations happening through separate RPC methods.

Fix

  • use the existing Shell tool's _shell_args() to split shell execution into executable + args
  • call terminal/create with:
    • command=<shell executable>
    • args=[shell flags..., user command]
  • use terminal_id with terminal/wait_for_exit, terminal/output, terminal/kill, and terminal/release

Validation

  • uv run pytest tests/acp/test_protocol_v1.py tests/acp/test_terminal_tool.py -q

Open with Devin

Copilot AI review requested due to automatic review settings March 10, 2026 14:55
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes ACP terminal-backed Shell execution by correctly splitting shell invocation into an executable (command) plus arguments (args), and updates the ACP terminal adapter to use terminal_id-based follow-up RPCs per the current ACP SDK.

Changes:

  • Route Shell commands through terminal/create as command=<shell executable> and args=[shell flags..., user command].
  • Update terminal lifecycle calls to use terminal_id (wait_for_terminal_exit, terminal_output, kill_terminal, release_terminal).
  • Add a regression test covering bash and PowerShell command/args routing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/acp/test_terminal_tool.py Adds regression coverage asserting correct command/args routing for bash and PowerShell in ACP terminal mode.
src/kimi_cli/acp/tools.py Updates ACP Terminal tool to construct shell argv properly and use terminal_id-based ACP RPC methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 90 to 96
try:
shell_argv = self._shell_tool._shell_args(params.command)
term = await self._acp_conn.create_terminal(
command=params.command,
command=shell_argv[0],
session_id=self._acp_session_id,
args=list(shell_argv[1:]),
output_byte_limit=builder.max_chars,
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Terminal calls self._shell_tool._shell_args(...), which is a private helper on Shell (leading underscore) and creates a cross-module dependency on an implementation detail. To make this more stable, consider exposing a public method (e.g., shell_args()/get_shell_invocation()), or moving the argv-building logic to a shared utility that both tools use, and have Terminal call that instead.

Copilot uses AI. Check for mistakes.
@hanhan3344
Copy link
Author

Addressed Copilot's maintainability suggestion in follow-up commit e1d00c7:

  • exposed a public Shell.shell_args() helper
  • updated the ACP terminal adapter to call the public API instead of the private _shell_args() method
  • added a focused unit test for Shell.shell_args()

Validation:
uv run pytest tests/acp/test_protocol_v1.py tests/acp/test_terminal_tool.py tests/tools/test_shell_invocation.py -q

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.

2 participants