Repository navigation
feat(backends): open hc task terminals beside the Firstmate that launched them - #8003
LuizBrugnera wants to merge 3 commits into
Conversation
When Firstmate itself runs in a live hc terminal of the task's session, create_task now makes the task terminal that terminal's child and gives it that terminal's herdr.space, so Herdr.app shows the crew as sub-agents in the Firstmate's own space. FM_HC_SPACE still wins when set, and outside an hc terminal nothing changes: --no-parent and fm-<hometag>. HC_TERMINAL_ID reaches every descendant of an hc terminal, including ones attached to another session's core, so it counts only when the address answers live in the task's session and that terminal's shell pid is an ancestor of the spawning process. --outlive-parent and --no-notify still apply, so a task survives Firstmate's exit and hc never types into Firstmate's composer. Fake-hc cases cover a real ancestor, an explicit FM_HC_SPACE, an unplaced caller, a live non-ancestor, and an unknown id; a real-hc smoke case runs create_task inside a stand-in Firstmate terminal (hc 0.1.14, Linux).
[Medium impact] The PR appears safe to merge; the previous finding is fixed and no new issues were found. Reviews (2) · Last reviewed commit: "no-mistakes(ci): I added FM_HC_SPACE to ..." · Reviewed by Greptile |
…sts/fm-backend-hc-smoke.test.sh (line 37), so it now reads `unset HC_TERMINAL_ID HC_TERMINAL_SOCKET HC_SCOPE HC_SOCKET FM_HC_SPACE`. This was the only change, as you asked. The rule behind it is that the smoke suite's outside-task check must not depend on the developer's environment. The suite's only other inherited `herdr.space` input is HC_TERMINAL_ID, and that line already unsets it. `bash -n` passes. I could not run the smoke suite itself: hc is not on PATH here, so the script printed `skip: hc not found` and exited before running any checks
…nals beside the Firstmate that launched them # Conflicts: # bin/backends/hc.sh # docs/hc-backend.md # tests/fm-backend-hc-smoke.test.sh # tests/fm-backend-hc.test.sh
|
Hi! I'm following this one closely: I'm waiting on the hc backend work to move my Firstmate setup to the Herdr desktop app. Having task terminals open next to the Firstmate that launched them would make the app layout much more usable for me. If anything is needed to move this forward (testing on macOS against a real Herdr.app/herdr-core, reproducing a review finding, or picking up a follow-up), I'm happy to help. Just let me know. |
|
Speaking as Kun's firstmate: thank you @LuizBrugnera, and sorry for the wait. I approved your first-time fork CI, and the quick checks pass on |
|
Thanks for the thorough triage and for approving the fork CI. Understood that this waits on Kun's call on the default layout. If Kun prefers keeping today's layout as the default, I can put the side-by-side terminals behind an opt-in instead, or rebase onto main myself once there's a decision. Happy to adjust either way. |
|
Speaking as Kun's firstmate: thank you @LuizBrugnera for the kind reply and for offering both options. You don't need to rebase. The conflict with main is ours to fix if Kun says go. I've noted your offer to put the side-by-side terminals behind an opt-in so Kun has it when he decides. Until then, nothing is needed from you. This is waiting on Kun, not on you. |
|
Weighing in on the open question here: we'd prefer the side-by-side layout as an opt-in rather than the new default. We expect to keep running both hc and the Herdr TUI going forward, so the default layout should keep working for homes on either one, with beside-the-launcher terminals available for homes that want them. @LuizBrugnera's offer to put this behind an opt-in sounds like the right shape to us. Thanks for the careful work on this. |
…STMATE=1) Task terminals open as children of Firstmate's own hc terminal, in its herdr.space, only when FM_HC_BESIDE_FIRSTMATE=1. Unset or any other value keeps the kunchenguid#7963 default: --no-parent and herdr.space=FM_HC_SPACE or fm-<hometag>. Tests cover the default staying off and the opt-in on; the docs and the real-hc smoke record describe the opt-in.
|
@rchristensen thanks for weighing in. Side-by-side placement is now opt-in (16740b2): by default hc task terminals keep #7963's layout ( |
Intent
Follow-up to #7963 (the experimental, explicit-only hc / herdr-core runtime backend), offered on that PR as "optional space and parent inheritance" and accepted by its author for after it landed.
Goal: an opt-in,
FM_HC_BESIDE_FIRSTMATE=1, that opens each hc task terminal beside the Firstmate that launched it in Herdr.app.With the opt-in set and Firstmate running inside a live hc terminal of the same session, each task terminal is created as that terminal's child (
--parent <firstmate terminal> --outlive-parent --no-notify) with the sameherdr.spacelabel, so the crew shows as its sub-agents with one tab each.The default does not change: with the opt-in unset or any value other than
1, or with no qualifying Firstmate terminal, behavior stays exactly as #7963 shipped it:--no-parentandherdr.space=${FM_HC_SPACE:-fm-<hometag>}.An explicit FM_HC_SPACE still wins over the caller's space.
Deliberate decisions: HC_TERMINAL_ID is only a hint and is never used to select the backend (hc stays explicit-only).
The adapter accepts it as the parent only when
hc geton the task's own session reports that terminal live and the terminal's own process (its top-levelpid, the shell hc started in it, notforeground.pid) is an ancestor of the spawning process (a bounded walk of 64 parents).The terminal's shell pid is deliberate: it is an ancestor of whatever runs inside the terminal, so the check holds when Firstmate runs under a launcher or wrapper that holds the foreground, and it still rejects an id inherited through a tmux or Herdr server, which daemonize outside that shell's tree.
A stale id, an id from another session, or an inherited id of an unrelated terminal falls back to the default with no error.
--outlive-parentstays, so closing or restarting the Firstmate terminal never kills its crew.Keep #7963's names (backend
hc,firstmate.*labels,hc_terminal); no private host names, IPs, accounts or people; one sentence per line in Markdown.What Changed
bin/backends/hc.shaddsfm_backend_hc_caller_terminal. It treatsHC_TERMINAL_IDonly as a hint. The id is accepted only whenhc geton the task's session reports that terminalliveand the terminal's top-level shellpidis an ancestor of the spawning process, checked by walking up at most 64 parents. A stale id, an id from another session, or an id inherited from an unrelated terminal returns nothing, with no error.fm_backend_hc_create_taskconsults it only whenFM_HC_BESIDE_FIRSTMATE=1. When a caller terminal is found, the task starts with--parent <firstmate terminal>instead of--no-parentand uses that terminal'sherdr.spacelabel. The space is chosen in this order:FM_HC_SPACE, then the caller's space, thenfm-<hometag>.--outlive-parentand--no-notifyare always passed. Without the opt-in, or when no caller terminal is found, behavior is the same as feat(backends): add experimental explicit-only hc (herdr-core) runtime backend #7963.tests/fm-backend-hc.test.shcheck that with the opt-in unset,0, oryes, a qualifying Firstmate terminal is neither looked up nor adopted, while the same setup with1adopts it. With the opt-in on, they cover an ancestor caller, theFM_HC_SPACEoverride, a caller with no space, a live terminal that is not an ancestor, and an unknown id.tests/fm-backend-hc-smoke.test.shchecks that a task created inside a stand-in Firstmate terminal has no parent and gets the default space by default, and with the opt-in reports that terminal as parent and shares its space. It also checks that, with the opt-in on, a task created from outside has no parent and gets the default space.docs/hc-backend.mddocuments the opt-in and its placement rules, anddocs/verification/runtime-backends.mdrecords the smoke run.Update: opt-in instead of a new default
Following the review discussion, side-by-side placement is now opt-in, so the default layout stays the same for homes on hc and on the Herdr TUI.
This update was pushed directly, without a new no-mistakes run, so the Testing and Pipeline sections below describe the earlier default-on head (
12ea73a5).For this head, checks were run by hand:
bash tests/fm-backend-hc.test.sh: 14 of 14 pass, including the new opt-in case.not ok - opt-in unset: the task must start with no parent).tests/fm-backend-hc-smoke.test.shagainst realhc 0.1.14(installed into a throwaway directory with the official installer, which checks its SHA-256, then removed): all pass, transcript indocs/verification/runtime-backends.md.bin/fm-lint.shandbin/fm-doc-audience-check.shpass.The branch is still based on the merge base of feat(backends): add experimental explicit-only hc (herdr-core) runtime backend #7963, so the conflict with main that was already flagged is unchanged.
🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change matches the intent. It is bounded to the explicit-only hc backend, adopts a parent only after a live same-session
hc getand a bounded check that the terminal's shell is an ancestor, otherwise falls back silently to the #7963 behavior, and has fake-hc and real-hc tests for each required case.Testing
hc was not on PATH, so I installed hc 0.1.14 into a disposable /tmp directory from herdr-core's official installer and deleted it when done. With that binary I ran the real-hc smoke suite, which passed, including the new stand-in Firstmate terminal case. The fake-hc suite passed all 13 cases. I also ran 11 adversarial live checks of my own against two private real hc cores, all of which passed: - A task launched through a wrapper that holds the foreground (foreground pid differs from the shell pid) still becomes the Firstmate terminal's child in its space. - FM_HC_SPACE overrides the caller's space and keeps the parent. - An inherited id reaching a setsid-daemonized process, or a tmux server started inside the terminal, falls back to no parent and the home space. - An id from another session falls back too, even when the same address is live in the target session. - An unknown id, a live non-ancestor id, and the stale id of a closed Firstmate terminal all fall back with no error. - Children stay live after their Firstmate terminal is killed. A mutation that bypasses the ancestry walk makes the fake suite fail on the non-ancestor case, as the intent requires. Because that check is a unit-suite mutation and not a live product run, it is recorded as untested. Logs and the scenario script are in the evidence directory. There is no UI surface to screenshot. The hc CLI reports parent and labels as JSON, which the logs capture. The worktree is clean, and all private cores and temp dirs I created are gone.Evidence: Real-hc smoke suite transcript (hc 0.1.14)
Source: Real-hc smoke suite transcript (hc 0.1.14)
Evidence: Adversarial live scenarios transcript
Source: Adversarial live scenarios transcript
Evidence: Adversarial live scenario script
Source: Adversarial live scenario script
Evidence: Fake-hc suite transcript
Source: Fake-hc suite transcript
Evidence: Mutation (ancestry check removed) makes the fake test fail
Source: Mutation (ancestry check removed) makes the fake test fail
Evidence: Adversarial results summary
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
Installed hc 0.1.14 from the official install script into a disposable /tmp dir (HC_VERSION=0.1.14 HC_INSTALL_DIR=/tmp/hcdl.*/bin) and removed it afterwardsenv -u HC_TERMINAL_ID -u HC_SESSION PATH=/tmp/hcdl.*/bin:$PATH bash tests/fm-backend-hc-smoke.test.sh(real hc, private core)bash tests/fm-backend-hc.test.sh(fake-hc suite, 13 cases)bash hc-adversarial-live.sh <worktree>: 11 live checks on two private real hc cores (wrapper-held foreground, FM_HC_SPACE override, setsid-daemonized descendant, tmux server started inside the terminal, colliding id from another session, unknown id, live non-ancestor id, parent closed with children still live, stale id after close)Mutation check: a throwaway copy of the repo with the ancestry walk short-circuited, then rantests/fm-backend-hc.test.shon it✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.