Skip to content

Agents CLI: Ctrl-C and Ctrl-D cancel the configuration questions - #1655

Open
longquanzheng wants to merge 2 commits into
mainfrom
agents-cli-init-ctrl-c
Open

longquanzheng wants to merge 2 commits into
mainfrom
agents-cli-init-ctrl-c

Conversation

@longquanzheng

Copy link
Copy Markdown
Contributor

Summary

Ctrl-C or Ctrl-D at any configuration question of init, or of the first-run setup that run, sessions, and connectors start without a configuration file, now stops the command right away in both CLI cores. It prints Cancelled; no configuration written., writes no file, and exits with 130 for Ctrl-C and 1 for Ctrl-D. The terminal leaves raw mode.

Why

Trying dex-agents-claude-sdk init, Ctrl-C did nothing at the questions.

  • TypeScript core: the terminal input had no interrupt handler during the questions. Readline in raw mode passed Ctrl-C to a no-op handler.
  • Python core: the first-run questions ran inside asyncio.run. Its SIGINT handler kept Ctrl-C from ending input(). In init, Ctrl-C printed a KeyboardInterrupt traceback. Ctrl-D took the default answer and could write a default configuration.

TypeScript: each question waits with an abort signal that Ctrl-C triggers. The terminal input closes after the questions, so Ctrl-C also ends startup. Python: the configuration loads before asyncio.run. Ctrl-C and Ctrl-D raise a cancellation that run_agent_cli maps to the exit code. The exit-code docs (runAgentCli, run_agent_cli, the Python core README, and the agents CLI reference) list the new codes.

Testing

  • New pseudo-terminal integration tests in both cores: Ctrl-C at the first init question, Ctrl-C at the third question of the first-run setup, and Ctrl-D. Each asserts the exit code, the message, and that no configuration file exists; Python also asserts no traceback. They failed before the fix.
  • TypeScript adds a terminal test: after the first-run setup the chat still reads the terminal. Its pseudo-terminal fixture uses Python's pty module, because Node cannot open a pseudo-terminal.
  • Full TypeScript and Python CLI core suites, ruff, mypy, typecheck, make copyright-check, and docs npm run check ran locally. Two existing connectors-warning tests fail in both suites on this machine because a connectors MCP answers there; the Python pair also fails with the origin/main code. CI runs them without one.

Ctrl-C at an init or first-run configuration question now prints
"Cancelled; no configuration written.", writes no file, and exits with
130; Ctrl-D does the same with exit code 1.

TypeScript: the terminal input had no interrupt handler during the
questions, so readline's SIGINT went to a no-op. Each question now waits
with an abort signal that Ctrl-C triggers, and the input is closed after
the questions so raw mode ends before startup.

Python: the first-run questions ran inside asyncio.run, whose SIGINT
handler kept Ctrl-C from ending input(), and Ctrl-D took the default
answer. The configuration now loads before asyncio.run, and both keys
raise a cancellation that run_agent_cli maps to the exit code.

Pseudo-terminal tests cover Ctrl-C at the first and a later question
and Ctrl-D in both CLI cores.
Closing the terminal input after the first-run questions dropped lines
already queued, so a chat message typed together with the last answer
was lost. close() now returns the unread lines and the chat's new
terminal input starts with them.

Pseudo-terminal tests in both CLI cores send the last answer and a chat
message in one write and expect the chat to echo it.
@longquanzheng
longquanzheng enabled auto-merge (squash) November 11, 2026 22:50

This branch has not been deployed

No deployments
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.

1 participant