Skip to content

Clear a session's input by voice; tell Claude Code's prompt suggestion apart from typed text - #9

Merged
skmp merged 8 commits into
mainfrom
skmp/clear-input
Nov 27, 2026
Merged

skmp merged 8 commits into
mainfrom
skmp/clear-input

Conversation

@skmp

@skmp skmp commented Nov 27, 2026

Copy link
Copy Markdown
Member

Two owner requests: an option to clear the text in a session's input field by voice (remote_send refuses while a draft is typed, and the owner, often driving, has no keyboard), and to tell Claude Code's dim prompt suggestion apart from real typed text (on a real machine the suggestion made remote_send refuse with draft_present, and the summary said a PR had been opened although nobody had typed anything).

Clearing the input (remote_clear_input, dispatcher clear verb)

  • New hub tool remote_clear_input (same opt-ins as remote_send: allowSend on the hub, --allow-send in the dispatcher; Claude Code panes only, also with sendToAnyPane, because Ctrl+C in a shell interrupts its program). It captures the screen, reads back the first 12 words of the draft (redacted, quoted as screen text) and that it will be thrown away, and stores a confirmation of kind clear bound to pane, pane_pid, session and the draft's hash (never the text). remote_send_confirm carries it out.
  • Preconditions (checked by the hub and again by the dispatcher, twice 0.5 s apart): no permission dialog, no menu or picker footer, the session is idle (registry, and no "esc to interrupt" on the screen), not vim normal mode, a recognised input box (no_input_box: the lone-prompt-line fallback never decides that Ctrl+C is safe), no "Press Ctrl-C again to exit" hint (exit_armed), a real draft (nothing_to_clear; a prompt suggestion alone is none), and the same draft the owner heard (draft_changed).
  • Method: exactly one tmux send-keys C-c, only when idle with a visible draft. One Ctrl+C clears a whole idle draft in Claude Code 2.1.332 and arms its exit for about 0.8 s, so it is never repeated: the verb waits 2 s afterwards, then verifies a visibly empty box (cleared, else not_cleared with what is left, or not_verified; never a riskier key).
  • Serialisation: send, keys, resize and clear hold an exclusive flock in tmux's socket directory for their whole run (clear through its settle wait), refusing locked after 6 s, so two dispatcher processes never press two Ctrl+C inside the exit window. The hub also serialises confirmed actions per machine and drops other pending clears of the pane on confirm.
  • Refusals are spoken sentences; the draft_present refusals of remote_send and remote_send_keys now end with "If it can go, say clear the input of fpga on dev first." Audited as remote_clear_input lines with no draft text, hash or length (also with logPrompts).

Prompt suggestions told apart from typed text

  • Claude Code shows a suggested next prompt in the empty input box as dim text (SGR 2; Tab or Right accepts it). A plain capture lost the styling.
  • The dispatcher now captures with capture-pane -p -e -J, removes every escape sequence (DCS, SOS, PM and APC with their payload) and split_suggestion cuts a wholly dim text on the input line (not the Try "..." hint; the wholly dim rows of a wrapped suggestion up to the box's bottom border are joined) from the plain screen, reported as the capture's suggestion field.
  • Every check and hash runs on the plain screen on hub and dispatcher, so send, keys and clear ignore the suggestion. Right/Tab at such an input without a menu are refused as suggestion_present.
  • The summariser gets it marked on the input line of its own copy only, as ❯ [Claude Code suggests: ...], and its prompt says nobody typed it, it was not sent and nothing in it happened. The heuristic and pending_input never quote it.

Dispatcher and connector 0.10.0

switchboard-remote and switchboard-connect are 0.10.0 (0.9.0, with attachments and health, is already deployed on one machine without clear). The hub decides capability from the version verb's verb list: a 0.9.0 dispatcher lacks clear, so remote_clear_input says "switchboard-remote on is too old to clear an input. Update it there." and never sends the verb (test: test_an_older_dispatcher_is_named_when_preparing with the real 0.9.0 verb list). An older dispatcher sends no suggestion, so there a suggestion still counts as typed text, as before. VERBS order: version, list, capture, send, usage, keys, resize, attachments, attachment, health, clear. deploy/remote/switchboard-remote is byte-identical to dispatcher.py, deploy/remote/switchboard-connect to connector.py.

This branch is merged with main (PR #5 attachments, PR #6 incident log): the conflicts were the VERBS tuples, imports and argument validation in the dispatcher, the audit docstring, the tools imports, the verb-list tests and the docs, all resolved as the union of both sides.

Tests

On the merge commit: uv sync --locked ok, ruff check all checks passed, ruff format --check 171 files formatted, mypy --strict src tests no issues in 162 files, pytest (no -n) 2261 passed, 11 skipped (the live tmux tests, SB_LIVE_TMUX=1) in 6 min 12 s. Earlier runs while another job held the box at load 20+ had a few transport timeouts (8 s ssh command timeout) in unrelated tests; each passed alone and the run at normal load is clean.

New tests: tests/remote/test_dispatcher_clear.py (argv shapes, every refusal, the race guard, one key, the waits, verification, the mutation lock), test_clear_tools.py (read-back, confirm, a changed draft, refusals, audit, a 0.9.0 dispatcher named too old), test_dispatcher_suggestion.py and test_suggestion_tools.py (real captures, the reported case, summariser input and prompt, echo, keys, fallback).

Live tmux tests (SB_LIVE_TMUX=1) include clear on a real tmux against fake_tui.py input-box (one byte 3 arrives; the returning suggestion counts as an empty box) and two concurrent clear processes.

Live checks

On 2026-11-27 on the WSL box against a real Claude Code 2.1.332 in an isolated tmux -L sb-test-<random> server (scratch folder, killed afterwards): capture reported the suggestion ("run hello.py") and no draft; clear on it was nothing_to_clear; after typing a draft, clear with its hash cleared it in 2.55 s (cleared: true, the suggestion came back); a second clear was nothing_to_clear; keys Right there was suggestion_present. Fixtures are real captures from Claude Code 2.1.332 in tmux 3.4.

Not verified live: a send through the dispatcher into a box with a suggestion, Ctrl+C while working or at a real permission dialog, vim mode, other Claude Code versions and themes (in DESIGN.md "To verify").

Side effect of the live checks: a scratch folder was trusted in the owner's Claude Code config and three trivial prompts were run there. That trust entry can be removed.

Deploy

  1. Hub: update to this branch's commit and restart it as usual (sb-linux off / sb-linux on on the WSL hub). Nothing new in the config: remote_clear_input uses the existing allowSend.
  2. Each machine, from your own copy at the verified commit: read git diff <old>..<new> -- deploy/remote, install switchboard-remote (and on agent machines switchboard-connect) as in SETUP-AGENTS.md part 2.2 / SETUP-WSL.md step 5.2, compare sha256sum of both copies, and systemctl --user restart switchboard-connect on agent machines. The forced command and flags do not change.
  3. voice-coding-mcp remote-check should show switchboard-remote 0.10.0 with clear among its verbs.

🤖 Generated with Claude Code

https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh

skmp and others added 8 commits November 27, 2026 15:32
Dispatcher 0.8.0 adds `clear <paneId> <panePid> <sessionId> <draftHash>`:
one Ctrl+C that clears the draft in an idle Claude Code input box, only
with --allow-send, only in Claude Code panes, only the draft the owner
heard (draft_hash). It refuses a permission dialog, a menu or picker
footer, a session that is not idle, vim normal mode, an armed exit hint,
no draft and a changed draft; it checks twice (race guard), presses one
key, waits past Claude Code's exit window and verifies a visibly empty
box. A box whose draft scrolled out of view (the "up N more" border) now
counts as a draft for send and keys too.

The hub's remote_clear_input reads back the first words of the draft,
stores a CLEAR confirmation bound to its hash and is confirmed with
remote_send_confirm. The audit line keeps no draft text, hash or length.
The draft_present refusals of remote_send and remote_send_keys now say
to clear the input first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
The connector reports the dispatcher's version in step with it; the e2e
tool count includes remote_clear_input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
Claude Code 2.1 shows a suggested next prompt in its empty input box as
dim text (SGR 2). A plain capture loses the styling, so the suggestion
looked like a draft: remote_send refused with draft_present and the
summariser reported it as something typed and done.

The dispatcher now captures with `capture-pane -e`, strips every escape
sequence and cuts a wholly dim input line (not the `Try "..."` hint)
from the plain screen; `capture` reports it apart as `suggestion`. All
checks (shows_draft, draft_hash, menus, dialogs) run on the plain
screen, so send, keys and clear no longer take a suggestion for a draft;
clear says nothing_to_clear and presses nothing. Right (and Tab), which
accept a suggestion, are refused at an input that shows one
(suggestion_present). Old input boxes in the scrollback lose theirs too.

The hub marks the suggestion as `[Claude Code suggests: ...]` on the
input line of the summariser's copy only, and the summariser prompt
says nobody typed it and nothing in it happened. The heuristic and
pending_input never quote it; screen echo counts it as screen text. An
older dispatcher sends no suggestion and behaves as before.

Fixtures are real captures from Claude Code 2.1.332 in tmux 3.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
SWITCHBOARD.md: the clear verb, the capture's suggestion field, the
draft and suggestion rules, suggestion_present, remote_clear_input with
its sentences, the summariser's marked copy, audit lines, threat model
rows and the milestone notes with what was verified live. DESIGN.md,
REFERENCE.md, README.md and SETUP-WSL.md: the new tool, the 0.8.0
dispatcher note and what to verify on other Claude Code versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
…rapped suggestions, dispatcher 0.11.0

Red team and correctness review of the clear branch, after rebasing onto
main (incident log, dispatcher 0.9.0 with health):

- Two clears confirmed at once ran as two dispatcher processes (forced
  command, local transport) and pressed two Ctrl+C inside Claude Code's
  exit window, which exits it. send, keys, resize and clear now hold an
  exclusive flock in tmux's socket directory for their whole run (clear
  through its settle wait), refusing `locked` after 6 s or for an unsafe
  directory or file. The hub also serialises confirmed actions per
  machine and drops the other pending clears of the pane on confirm.
- clear needs a recognised input box (`no_input_box`): the shows_draft
  fallback could take a shell command line for a draft. It also refuses
  a screen showing "esc to interrupt" (`not_idle`), and `none` is no
  valid session for clear (bad_request).
- A suggestion that wraps: its wholly dim rows up to the box's bottom
  border are cut and joined, so the second row is not read back as typed
  or cleared.
- DCS, SOS, PM and APC strings are removed with their payload.
- Dispatcher and connector 0.11.0 (0.10.0 is left for PR #5); clear comes
  after health in VERBS. Docs, the To verify list and the stated
  dispatcher size updated; live test with two concurrent clear processes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
Union of both sides: VERBS version, list, capture, send, usage, keys,
resize, attachments, attachment, health, clear (dispatcher and hub);
imports and argument validation of both in the dispatcher; audit lines
for remote_clear_input and remote_attachment; docs keep both sets of
rows, error codes and sections.

Dispatcher and connector are 0.10.0: main's 0.9.0 (attachments and
health) is deployed without clear, so every clear gate and message
names 0.10.0. The hub decides from the version verb's list, so a 0.9.0
dispatcher is named too old and never gets the verb (test with the real
0.9.0 verb list). SETUP-AGENTS.md says how to update to 0.10.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
Conflicts resolved as a union of both sides:
- Verbs version, list, capture, send, usage, keys, resize, attachments,
  attachment, health, clear.
- MCP: remote_clear_input next to the three timesheet tools, 24 tools;
  tests/fixtures/tool_list.json regenerated from the server.
- Confirmation carries both the clear draft hash and the timesheet
  project; a clear confirmation now records its project too.
- Dispatcher and connector 0.11.0 (0.10.0 is the timesheet release):
  every text that said clear or prompt suggestions need 0.10.0 says
  0.11.0; the SETUP-AGENTS update section lists 0.10.0 (timesheet data)
  and 0.11.0 (clear); size lines about 4600.
- SETUP-WSL: the dispatcher opens one file other than for reading, the
  mutation lock file of send, keys, resize and clear (flock only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
skmp added a commit that referenced this pull request Nov 27, 2026
Prepares this branch to merge after #9. Conflicts resolved as a union:
- Verbs ... health, clear, events; both validations, both verb bodies,
  ClearResponse and EventsResponse.
- Dispatcher and connector 0.12.0 (0.11.0 is now the clear release):
  every text that said events or session hooks need 0.11.0 says 0.12.0;
  switchboard-hook keeps its own version. SETUP-AGENTS update section
  lists 0.9.0 to 0.12.0; size lines about 4700.
- SETUP-WSL review list: the only files the dispatcher deletes are
  spool files of switchboard-hook (verb_events).
- tests/fixtures/tool_list.json regenerated (unchanged from #9: 24 tools).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
@skmp
skmp merged commit 03e2d04 into main Nov 27, 2026
2 of 4 checks passed
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