Repository navigation
Discord notifications from session hooks, and notify_owner for agents - #8
Merged
Merged
Conversation
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
`events [<eventId>...]` deletes the named events of the switchboard-hook spool (~/.local/state/switchboard-hook/events) and answers up to 16 of the rest, oldest first. Only with the new owner opt-in --allow-events (allowEvents in the policy file): the spool covers every Claude Code session of the machine user. Each file is checked again (O_NOFOLLOW, own uid, 4 KB, exact keys, fixed kinds, UUIDs, pane ids, GitHub URLs) and deleted when it is not an event; a spool directory others can write, or a symlink, answers events_unsafe before anything is deleted. A verb rather than a new frame works over ssh, local and agent links, and older hubs and dispatchers keep working. The connector moves to 0.11.0 with it. The hub side gets the EventsResponse model. 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
A stdlib-only Python 3.8 program for each machine, shipped like the dispatcher (deploy/remote/switchboard-hook, `voice-coding-mcp remote-hook` prints it): - `hook`, for Notification (permission prompt, idle prompt, elicitation), Stop, StopFailure and PostToolUse on Bash (gh pr create / gh pr ready): writes one small event into a private spool (0700, files 0600, at most 200 of 4 KB). It keeps a hook's own short message, the error code of a failed turn and a validated pull request URL, never the transcript, the assistant's text or tool output. It prints nothing, exits 0 on every path and gives up after 5 s, so Claude Code never waits on it. - `mcp`, a stdio MCP server with notify_owner(message, level?, url?): GitHub links only, 5 notes per session and 20 per machine an hour. - `install` / `uninstall`: merge the hooks into the user's settings (backup, idempotent, other hooks kept, diff shown, --dry-run) and register the MCP server with `claude mcp add --scope user`. Tests use the hooks reference's payloads and temporary homes only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
- remote/events.py polls each machine's `events` verb (agent and local machines every 5 s, ssh machines only with events.sshPollSeconds), acknowledges in the next call, keeps seen ids and owed acks in stateDir/events.json (at least once, no repeats across restarts), and checks every field again. The machine is the link the answer came on, never a field of the event. At most events.maxPerHour per machine. - Each event is an `event` entry of the incident log (entry, component and source `session`); a session that stopped on an API error is an incident. The incidents tool and the CLI leave events out (`incidents list --events` shows them). - remote/discord.py posts to the owner's webhook, read only from SWITCHBOARD_DISCORD_WEBHOOK_URL (validated, removed from the process environment, never logged): allowed_mentions parse [], machine text as inline code, the hub's words escaped, coalescing, 429 retry_after, backoff, an hourly cap and incidents for drops and refusals. - One notify path: watcher pushes and incident pushes also go to Discord (discord.kinds); notify.url keeps working. incidents.notify is now wired into the running hub (it reached only the watcher before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
…0.11.0 SWITCHBOARD.md: the hook program, the events verb, the hub's poller, Discord rendering and failure handling, config tables, threat model rows, and the design rule for a future Discord bot (a reply never approves a merge, push or send by itself). DESIGN.md records the decisions and the bot rule in the security model. REFERENCE.md: the events and discord keys, SWITCHBOARD_DISCORD_WEBHOOK_URL, remote-hook and incidents --events. SETUP-AGENTS.md: installing the hooks and notify_owner, updating to 0.11.0. SETUP-WSL.md: creating the webhook and putting it only into the hub's environment file. 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
…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: verbs version, list, capture, send, usage, keys, resize, attachments, attachment, health, events; dispatcher policy flags --allow-attachments and --allow-events; config, http and tool plumbing of both sides; docs of both sides. Dispatcher and connector stay 0.11.0 here; the clear merge that follows moves them to 0.12.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
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
While a machine's hooks deliver events (events taken from it in the last 6 hours, remembered in events.json) and Discord takes that kind, the watcher's own "needs a decision" and "asks you something" pushes for that machine stand down, so a wait is reported once, by the hook. The hook's finished event stays on every turn (bursts are coalesced). Without Discord, or with the kind left out of discord.kinds, the watcher keeps pushing. Tests and docs (SWITCHBOARD.md, SETUP-WSL.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh
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.
The owner asked for a Discord message when a session on any machine waits for an approval or a question, finishes, fails or has a pull request to merge. He also wanted a
notify_ownertool that sessions call to tell him what matters, and every event recorded in the incident log. The base of this PR isskmp/incident-log(#6).Design
Machine side: no new connection.
deploy/remote/switchboard-hookis a new stdlib-only Python 3.8 file, installed like the dispatcher.voice-coding-mcp remote-hookprints it.hook: Claude Code runs it for these hooks. They were checked against the current hooks reference and the installed Claude Code 2.1.332.Notificationwithpermission_promptgivesapproval_needed.Notificationwithidle_prompt,elicitation_dialogoragent_needs_inputgivesquestion.Stopgivesfinished. It is skipped whilestop_hook_active, and for subagents.StopFailuregivesfailed, with the error code only.PostToolUseon Bash, forgh pr createorgh pr ready, givespr_opened. The URL is validated ashttps://github.com/<owner>/<repo>/pull/<n>.The hook writes one small file into a private spool:
~/.local/state/switchboard-hook/events, mode 0700, files 0600, at most 200 files of at most 4 KB. It keeps only Claude Code's own short notification text, the error code, the PR URL, the session id and name, the project folder's basename and the tmux pane. It never keeps the transcript,last_assistant_message, tool output or screen text. It never blocks Claude Code:asyncwith a 10 s timeout;mcp: a stdio MCP server with one tool,notify_owner(message, level?, url?). It accepts GitHub links only, at most 5 notes per session and 20 per machine per hour. It spools anowner_noteevent.installanduninstallchange~/.claude/settings.jsonand runclaude mcp add --scope user switchboard-notify(argv, no shell).--dry-runwrites and runs nothing.--allow-tooladds the allow rule fornotify_owner. It is off by default.Transfer: dispatcher 0.11.0, verb
events [<id>...], only with the new owner opt-in--allow-events. The verb deletes the events the hub names as taken and returns up to 16 more, oldest first.O_NOFOLLOW, owned by the user, 4 KB, exact keys, fixed kinds.bad_request. The connector code is unchanged; only its version number moves to 0.11.0.Hub:
remote/events.pypolls agent and local machines every 5 s. ssh machines are off by default, because each poll is one ssh login.stateDir/events.json. Delivery is at least once, with no repeats across restarts.machinefield is ignored.events.maxPerHour."entry": "event"line with component and sourcesession. Afailedevent opens an incident instead (session_failed). Theincidentstool and the CLI's default list leave events out;incidents list --eventsshows them.remote/discord.pyhandles Discord.SWITCHBOARD_DISCORD_WEBHOOK_URLin the hub's environment file, never fromconfig.json. It must be a Discord webhook URL. It is removed from the process environment at start, and it is never logged or echoed in errors.allowed_mentions: {"parse": []}. Text from machines is cleaned, redacted and shown as inline code, with backticks replaced and every@broken by a zero-width space. The hub's own words are escaped.retry_after; 5xx and network errors back off; 4xx is not retried.notifyincidents.discord.kinds), andnotify.urlworks as before. One extra fix:incidents.notifyfrom Incident log: what failed, where, when and why #6 was never passed to the running hub, so it pushed nothing. It is now.Future Discord bot (design only, recorded in DESIGN.md's security model and the SWITCHBOARD.md threat model): a reply in Discord never approves a merge, a push, a send or any other action by itself. Such an action needs the same steps as
remote_send_confirm:Discord text is untrusted input.
Tests
uv sync --locked,ruff check,ruff format --check,mypy --strict src testsandpytestall pass (1979 passed, 9 skipped).tests/remote/test_hook.py, the hook:claude: merge, idempotence, dry run, backup, uninstall, broken settings left alone;tools/call, bad arguments, rate limits;tests/remote/test_events.py, the dispatcher verb and the hub:--events, the incident when the webhook is missing;tests/remote/test_discord.py:retry_afterand with the header, clamping, 5xx and network retries, a deleted webhook, the hourly cap, quiet hours, the buffer bound;Deploy steps
/etc/voice-coding-mcp/env. Then set"discord": {"enabled": true}and"events": {"enabled": true}in the config and restart the hub. The full guide is in SETUP-WSL.md, "Discord notifications".switchboard-remoteandswitchboard-connect(0.11.0) and add--allow-eventsto the dispatcher flags. For an agent machine those flags are in the unit; for an ssh machine they are in theauthorized_keysforced command, which also needsevents.sshPollSeconds. Thensystemctl --user restart switchboard-connect.switchboard-hook, thenpython3 -I ~/.local/bin/switchboard-hook install --dry-run, theninstall. Restart running Claude Code sessions. SETUP-AGENTS.md, "Session hooks and notify_owner", has the details.Open questions
watchout ofdiscord.kinds. Should the watcher stand down by itself when a machine delivers events?finishedfires on every turn, including short interactive ones. It is coalesced, but should it be held back below a minimum turn length? That would need a start time from aUserPromptSubmithook.iffilter (Bash(gh pr *)) would avoid that, but I left it out to keep the settings valid on older versions.🤖 Generated with Claude Code
https://claude.ai/code/session_011moV3EPNNknRWZQ686AChh