Support herdr as a terminal workspace manager beside tmux #422
Labels
No labels
bug
contract
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
iterative-works/iw-cli#422
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
iw start,iw openandiw rmcan only manage a terminal workspace with tmux. We now use herdr as our terminal workspace manager for agent work. In herdr,iw startcreates a tmux session inside a herdr pane, which gives a nested, unusable workspace.The tool must detect the terminal workspace manager and use it.
Scope
In scope: the worktree session lifecycle (create, exists, attach, focus, close, send command) behind one backend-neutral port, with a tmux adapter and a herdr adapter, selected automatically.
Out of scope (follow-up issues):
herdr agent prompt --wait --until idle) as a replacement for blind keystrokes.--promptkeeps send-keys semantics for now.herdr worktree create).iwkeeps creating its worktrees with git.Design
1. Close the port leak first
SessionHooks.scala:52andSessionHooks.scala:81callTmuxAdapter.sendKeysdirectly and bypass theTmuxOpsport. No backend swap is possible until the send-command operation is part of the port.2. Generalise the port
TmuxOps(core/commands/CommandEnv.scala:373) becomes a backend-neutral port for "one named terminal workspace per worktree". The operation names must not name tmux.3. Add a herdr adapter
The adapter speaks the herdr socket API through the
herdrCLI and parses the JSON replies with upickle (already a dependency,core/project.scala:8).Verified mapping:
sessionExists(name)herdr workspace list, match onlabelcreateSession(name, dir)herdr workspace create --cwd DIR --label NAME --no-focussendKeys(name, cmd)herdr pane run <pane_id> <cmd>(sends the text and Enter)killSession(name)herdr workspace close <id>isInsideTmuxHERDR_ENV=1currentSessionNameHERDR_WORKSPACE_ID, thenherdr workspace get <id>for the labelswitchSession(name)herdr workspace focus <id>attachSession(name)herdr workspace focus <id>, then attach the session (NOT YET VERIFIED)Herdr addresses every object by ID, not by label. The adapter must resolve label to
workspace_idon each call.workspace createreturns theworkspace_idand theroot_pane.pane_idtogether, so no second lookup is necessary on the create path.4. Select the adapter
HERDR_ENV=1selects herdr. If it is absent, tmux stays the backend. An explicit override must stay possible for the tests.5. Doctor check
commands/start.hook-doctor.scalamust check that a terminal workspace manager is available, not that tmux is available.Findings from the live probe
Two probe workspaces were created and closed in a running herdr server.
Tmux.scala:24-30removesIW_*variables to prevent leakage into the session. A herdr pane inherits the environment of the herdr server, not of the calling process. The probe pane showed noIW_*variable except the globally setIW_HOME..envrcin each new pane. TheDirenvSetuphook stays necessary, but only for itsdirenv allowon a new worktree.herdr worktree openneeds a parent workspace. Without--workspace <parent repo workspace id>it fails withlinked_worktree_source. With it, it succeeds and reportsalready_open. It gives the workspace real worktree metadata, whichworkspace createdoes not. Proposal: useworktree openwhen the parent repo workspace exists, and fall back toworkspace create.Acceptance
iw start <KEY>creates the worktree and a herdr workspace with the session name as its label, runs the setup hooks in it, and focuses it.iw open <KEY>focuses the existing workspace, or creates it if it is absent.iw rm <KEY>closes the workspace and refuses to run from inside that same workspace.iw doctorreports the workspace manager it found.Tests
test/contract/tmux_adapter_contract.bats, skipped whenherdris not in PATH.FakeCommandEnvharness tests (StartHarnessTest,OpenHarnessTest,RmHarnessTest) carry over after the port rename.