Skip to content

feat(focus): open an event's own Herdr pane - #307

Merged
adefreitas merged 3 commits into
StackOneHQ:mainfrom
adefreitas:feat/herdr-focus
Dec 3, 2026
Merged

adefreitas merged 3 commits into
StackOneHQ:mainfrom
adefreitas:feat/herdr-focus

Conversation

@adefreitas

Copy link
Copy Markdown
Collaborator

This PR makes Open on an event go to the agent's own pane when the agent runs inside Herdr, a terminal workspace manager.

Herdr runs agents under its own server, so the hook's process walk ends at the terminal around it (Ghostty, here), and every Herdr pane shares that terminal's session ID. Open raised Ghostty on whichever pane Herdr last showed.

Open now reads HERDR_PANE_ID and HERDR_SOCKET_PATH from the agent's environment, or from its shell's once the agent has exited, the same way tmux focus reads TMUX_PANE. It then asks Herdr over its socket to focus the pane's workspace, tab and pane (pane.get, then workspace.focus, tab.focus, pane.focus). That happens before the terminal is raised, so an approval keystroke reaches the right pane. Outside Herdr nothing changes: no HERDR_PANE_ID, no call.

Checks

  • make test-without-xcode passes: 2151 tests, 0 failures. New tests cover reading the target from ps eww output, no target outside Herdr or without a socket, the focus order, and a pane-only focus when pane.get can't be read.
  • pane.get over a real Herdr 0.9.1 socket returns the workspace and tab IDs this code reads. The focus switch itself has not been tried end to end yet.

🤖 Generated with Claude Code

@hiskudin hiskudin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This checks out against Herdr's source. pane.get and pane.focus take pane_id, workspace.focus and tab.focus take their ids, the framing is newline-delimited JSON, and the pane_info reply has the shape location(fromReply:) reads. Also good:

  • The socket work is all on background queues.
  • The request JSON goes through JSONSerialization, so nothing can be injected through it.
  • A stale socket falls through to the old behaviour.
  • tmux events still return first.

The suite passes locally (2151), but gh pr checks shows no CI run on this branch yet.

Two things I'd fix are inline. Smaller ones:

  • A hung Herdr delays Open. With a 1 s timeout per call and up to four calls before the terminal is raised, an approval keystroke can land about 2 s late. It's off the main thread, though.
  • Extra work outside Herdr. Every Open now pays up to two ps eww forks, Herdr or not, including the activate-immediately path.
  • Test gaps. The tests cover the pure helpers. call (a reply split across recvs, a refused socket, the timeout), focus against a fake socket server, and the agent-then-shell fallback aren't covered. The description also says the switch hasn't been tried end to end.
  • Shared parser. parseEnvValues matches MY_HERDR_PANE_ID=, matches the same text in argv (which comes before env), and cuts values at a space. That's the same as TMUX_PANE, so it isn't new here.

Comment thread panel/Panel.swift Resolved
Comment thread panel/HerdrFocus.swift Resolved
adefreitas and others added 3 commits December 3, 2026 10:50
Herdr runs agents under its own server, so the terminal the hook finds
(Ghostty) is shared by every Herdr pane, and Open raised it on whatever
pane Herdr last showed. Open now reads HERDR_PANE_ID and
HERDR_SOCKET_PATH from the agent's environment (or its shell's, once the
agent has exited) and asks Herdr to focus that pane's workspace, tab and
pane, before the terminal is raised and any approval keystroke is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Only read Herdr's env when a process named herdr is among the agent's ancestors, so agents that merely inherited HERDR_PANE_ID (e.g. from `code .`) no longer switch Herdr's view. The walk uses proc_pidinfo (no fork), is capped at 32 hops, and runs before the `ps eww` read.
- Set SO_NOSIGPIPE on the socket so a Herdr that closes before the write cannot raise SIGPIPE.
- Test the socket path against a fake Herdr server (request order and ids, refused socket, hang-up) and the ancestry rule through an injectable lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI's compiler resolved bind to an instance method in the test class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adefreitas
adefreitas merged commit e28adb4 into StackOneHQ:main Dec 3, 2026
6 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.

2 participants