Skip to content

Sonny: /switch lists every agent to pick, and each agent acts in the terminal it is spoken to in - #604

Merged
lydakis merged 10 commits into
mainfrom
claude/project-thread-7nasaw
Nov 1, 2026
Merged

lydakis merged 10 commits into
mainfrom
claude/project-thread-7nasaw

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

What happened

George had one Sonny running in Ghostty and another in Rex. In the Ghostty one he typed a bare /switch, which only printed a hint asking for a name. His next words then went to the agent as an ordinary message, and the agent opened agent.lead with show_agent. That window opened in Rex. The cause is that mux::for_agent read a single place per project, recorded by whichever Sonny last laid the project out. A Sonny in a bare terminal never writes one, so it could never take the project back. The Rex window also kept opening tabs for new tasks while George was typing in Ghostty.

What changes

1. Each agent acts in the terminal it is spoken to in. ~/.agent/sonny/places/<hash>.json now holds one entry per Sonny window of the project: {pid, bot, used_ms, place | null}. A bare terminal's entry has no place. A window marks itself, at most once a second, on any of these:

  • a key
  • a click
  • a paste
  • coming to the front

For agent B, mux::latest_for picks the open window used last among those showing B. If no window shows B, it tries the windows showing the agent that made B, and so on up to the first lead (via created_by). If none of those has a window, it uses the project's window used last. Three things use that rule:

  • B's show_agent and run_in_pane calls (for_agent)
  • open_lead on the other lead's own windows
  • a lead's new task tabs (Fleet::show is gated on mux::mine(lead))

So with one lead in Ghostty and another lead of the project in Rex, each acts where it is spoken to. The Ghostty lead's calls open nothing anywhere and return an error saying nothing opened would be seen. The Rex lead keeps opening its tasks' tabs. Every window Sonny opens in a layout is told its home with --window-place: show_agent, the lead's task tabs, and /switch. A window opened by hand takes the newest home known.

This is tmux's rule for a command that names no client, the client used most recently, taken per agent. The trade-off tmux accepts is that a window you only look at, without typing, clicking or focusing it, doesn't count. One case still shares a record: the same agent open in two terminals goes with whichever was used last.

2. One /switch picker; /lead alone is the same list. The picker sits over the composer (the one list component, using fuzzy.rs):

  • Rows are ordered: this folder's leads, then the project's other agents, then other projects' leads, then the rest.
  • The current agent is marked •. The agent beside the conversation is picked to start, otherwise the first one that isn't this window.
  • A muted detail shows working and, for other projects, their folder in fish form.
  • The last row, new lead [NAME], makes a new lead.
  • Picks are weighted like slash commands, stored in picks.json under agents.

/switch NAME still opens an agent at once. A name that matches no agent opens the list narrowed to it. This follows Claude Code's and Codex's /resume: one searchable list rather than a command per kind. A follow-up PR, still under discussion, replaces the new-lead row and /lead with a /new command.

Design pass

Checked against the interface system's "Pickers" and "Finding and confirming" rules and the visual system:

  • the same list component: 8 rows, a blank row above, reversed pick, never bold
  • matched letters in bold
  • • marks the current agent
  • muted detail
  • the key line follows the grammar: ↑↓ pick · enter switch · esc close
  • no new hue

/switch in Flexoki dark, narrowed to fix, the new-lead row, Flexoki light, NO_COLOR

Tests

  • mux: covers the window used last, which agent acts where with two terminals on two agents (each_agent_acts_in_the_terminal_it_is_spoken_to_in), closed windows, pruning, /switch handing on its place, and the liveness check.
  • switch: ordering, the beside agent picked first, narrowing, and the new lead's name.
  • The app test for /switch.
  • The Sky haiku test now waits for the read already in flight (it raced on the macOS runner).
  • cargo test -p sonny: 905 passed. Clippy: clean. fmt: clean.

The runtime job's single failure on 353b3a1 is flake #612, from main, in code this PR doesn't touch. There is no daemon or protocol change.

…ast typed

/switch alone (and /lead alone) opens one list of every agent over the
composer, found by typing with the shared matcher: the folder's leads
first, then the project's agents, then other projects' leads, then the
rest; the agent beside the conversation is picked to start, and a last
row makes a new lead. /switch NAME still opens an agent at once, and a
name found in none lists what it narrows to.

Each of a project's Sonny windows now notes where it is (none for a bare
terminal) and when the person last used it. An agent's show_agent and
run_in_pane, and the lead's new task tabs, follow the open window used
last, as tmux picks the most recent client, so a Sonny in Ghostty no
longer opens agents in another terminal's Rex session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
…ad's tabs opening there

Codex review on #604: a worker window marking itself made the lead's
window not the latest, so later task tabs stopped opening even in the
same home; and a worker borrowed whichever home was typed in last.
A lead now opens task tabs while the window used last is in its own
home, and an agent's window takes its home once, when it starts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
Codex review on #604: /switch execs the other agent's Sonny in the same
process, so the old project kept counting the window as open. Before
exec its entry is kept as a closed window's (pid 0), its place kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
…once

Codex review on #604: a task's window that replaced its lead's (the only
open one) could not learn its home, so it never marked; it now gets the
place it replaced in the same terminal (--window-place, unlisted). And a
quick return from another window was lost to the once-a-second throttle:
only typing is throttled now; Enter, clicks, pastes and focus mark at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
Codex review on #604: a window opened by show_agent with every Sonny
closed could not learn its home. Every window Sonny opens in a layout
(show_agent, the lead's task tabs, /switch) now gets --window-place; a
window opened by hand falls back to the newest home known, open or closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
The test wrote another sky's haiku while the read started at Ready could
still be on its way; on a slow runner that older read landed last and
the haiku was never seen. It now lets that read land first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
@lydakis lydakis self-assigned this Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T17:05:27.065158Z 160de22 New commits
🔒 Security Review ✅ Completed 2026-11-01T08:38:02.146649Z 7d64979 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d64979b5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/main.rs Resolved
Comment thread sonny/src/mux.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4616d39ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/mux.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6307844273

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/mux.rs Resolved
Comment thread sonny/src/mux.rs Resolved
…-7nasaw

# Conflicts:
#	sonny/FEATURES.md
#	sonny/src/main.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2aa4891fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/mux.rs Resolved

lydakis commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

The runtime job on 353b3a1 failed in test_a_terminal_poll_past_the_hold_parks_its_turn_off_the_active_slot: the daemon returned no result for a submit. This PR changes only Sonny, and that daemon test came from #567 unchanged. Locally it passes 32 of 32 runs, including runs under CPU load, so there's no fix to port yet; it's filed as #612. Every other check passed, and the Codex review of this head is clean. I can't re-run jobs from here (403), so the PR stays open and watched until the runtime job is green.


Generated by Claude Code

George (on #604): talking to one agent in Ghostty and another in Rex at
once, each should act where it is spoken to. The places record was one
most-recent window per project; it now notes the agent each window shows,
and an agent's show_agent/run_in_pane, and a lead's task tabs, go by the
window used last of those showing that agent, a task's by its maker's,
then the project's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8kk4PkzKWAc5neW8
@lydakis lydakis changed the title Sonny: /switch lists every agent to pick, and agents open where you last typed Sonny: /switch lists every agent to pick, and each agent acts in the terminal it is spoken to in Nov 1, 2026
@lydakis
lydakis merged commit 3232b4d into main Nov 1, 2026
10 checks passed
lydakis pushed a commit that referenced this pull request Nov 1, 2026
lydakis added a commit that referenced this pull request Nov 8, 2026
…each multiplexer the machine has (#810)

* Sonny: agents ask `sonny where` for their terminal, with a skill for each multiplexer the machine has

An agent's run_in_pane and show_agent calls go to the window the person
used last among those showing it (#604), but Sonny installed one
multiplexer skill for every agent: the one for the terminal the last
Sonny started in, removing the others. With a project open in Herdr and
in cmux, the cmux agent opened its tabs in cmux yet said it was in Herdr.

- `sonny where [AGENT]` prints the multiplexer and the workspace or
  session the agent's calls act in now, by the tools' own rule
  (mux::aim, which for_agent now opens). It reads the places file and
  asks a multiplexer only when no window says.
- Sonny installs the skill of every multiplexer the machine has and
  removes one it no longer has; each tells the agent to run
  `sonny where` first and to follow the skill it names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGDUmvDiLkLgbMSmJMF

* FEATURES: sonny where row names #810

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGDUmvDiLkLgbMSmJMF

* sonny where: find the window places under the daemon's own socket from a sandboxed shell

A sandboxed agent's shell on macOS reaches the daemon by the bot's own
socket, which no Sonny window notes its place under, so `sonny where`
fell back to asking the multiplexers and could name the wrong one. It
now reads the places noted under the socket it was given, else under the
store's own socket, which Sonny windows use unless one is named.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGDUmvDiLkLgbMSmJMF

---------

Co-authored-by: Claude <[email protected]>
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