Repository navigation
Support stop_task over the interactive PTY transport - #3
Merged
Merged
Conversation
Implements stop_task(task_id) for PtyCLITransport (previously an "unsupported" control error) by reconstructing the live background-task set from the transcript and driving the CLI's /tasks dialog. - Task registry (task_id -> description/status), fed from _emit_line: a spawning tool_use -> the tool_result whose text carries the task-id -> a <task-notification> whose terminal status retires it. - /tasks dialog driver (parse_tasks_dialog / task_row_matches): open the dialog, navigate to the uniquely-matching selected row, press x. - Safety: detection gated on the dialog's "x to kill"/"x to stop" footer so ordinary output is never mistaken for it; the kill keystroke fires only on a unique verbatim match of the selected row (ambiguous/no-match -> error, never a wrong kill); confirms termination; no ESC when the dialog never opened (won't interrupt a turn). The dialog layout is an undocumented TUI contract -- row identification is fixture-tested and flagged for re-verification against the bundled CLI. https://claude.ai/code/session_01RVo5bksX7e8McFKqGbbuDH
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
PtyCLITransportpreviously rejectedstop_taskwith an "unsupported" control error. This implements it by reconstructing the live background-task set from the transcript and driving the CLI's/tasksdialog to stop the requested task.What changed
_track_tasks, fed from_emit_line) — reconstructs live tasks with no side channel: a spawningtool_use(Bash run_in_background/Agent/Task/Workflow/Monitor) → thetool_resultwhose text carries the assigned task-id → a<task-notification>whose terminal status retires it. Keyed by task-id with the task's description (for dialog matching). This complements PR Hold the PTY turn open until spawned background tasks finish #2's existing turn-hold tracker (which keys_pending_tasksby tool-use id); both now share_BACKGROUND_TASK_TOOLS/_TASK_NOTIFICATION_RE/_TERMINAL_TASK_STATUSES./tasksdialog driver (parse_tasks_dialog/task_row_matchesinpty_question.py,_stop_task) — opens the dialog via the existingpytescreen, navigates to the row matching the target, and pressesx.x to kill/x to stopfooter so ordinary output (even text mentioning "kill" with an "esc to interrupt" footer, or a markdown>blockquote) is never mistaken for the dialog. On success it confirms the task left the registry (errors otherwise); if/tasksnever opens, no ESC is sent (won't interrupt a turn).The dialog layout is an undocumented TUI contract — row identification is fixture-tested and flagged for re-verification against the bundled CLI; every failure mode degrades to a clear error rather than a wrong kill.
Tests
New
TestTaskRegistry/TestStopTask(transport) andparse_tasks_dialog/task_row_matches/task_label_keycases (parser), including regressions for: dialog misdetection of ordinary output, sibling-command discrimination (npm run build:prodvs:staging), ambiguity refusal,esc-in-command rows, age-column stability, navigation to a non-initial row, unconfirmed-kill error, no-ESC-on-failure, and the task-id word boundary.ruff check/formatclean,mypy src/clean. Relevant suites green; PR #2'sTestBackgroundTaskHoldstill passes alongside the new tracker.https://claude.ai/code/session_01RVo5bksX7e8McFKqGbbuDH
Generated by Claude Code