Skip to content

Refuse a direct Herdr agent launch and point to hide agent spawn - #688

Merged
yansfil merged 9 commits into
mainfrom
prd/herdr-spawn-guard
Oct 7, 2026
Merged

yansfil merged 9 commits into
mainfrom
prd/herdr-spawn-guard

Conversation

@yansfil

@yansfil yansfil commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Related: 선행 #668, #670 (둘 다 이미 main에 merge됨)

Summary

  • 에이전트가 herdr agent start로 직접 띄운 자식은 부모 기록이 없어 관계도에 선이 없고 watch도 없어, 멈춰도 아무도 깨우지 않습니다.
  • Claude Code와 Codex CLI의 hook에 PreToolUse(Bash matcher)를 더해, 등록된 checkout의 Herdr pane에서 이런 호출을 실행 전에 거절합니다.
  • 거절 이유에 채워진 hide agent spawn --parent here --name ... --kind ... --repo ... --branch ... 명령을 담아, 에이전트가 한 번에 다시 시도합니다.
  • 대상은 herdr agent start, 그리고 첫 단어가 에이전트 종류인 herdr pane run/send-text뿐이고, 그 밖의 호출은 출력도 지연도 없이 그대로 실행됩니다.
  • Settings의 Partial 칩 목록에 종과 herdr 직접 실행 차단 항목이 에이전트별로 더해집니다(해당 없는 에이전트는 -).
Not run: this call starts an agent with herdr directly ... Start it through Hide instead:
hide agent spawn --parent here --name set-g --intent <intent> --kind claude --repo /path/repo --branch topic

Review

  • 판단해 주세요: 연쇄 호출(cd x && herdr agent start ...)은 호출 전체를 거절하고, 이유에 나머지 명령을 따로 실행하라고 적습니다. 열린 질문의 답입니다.
  • 판단해 주세요: 에이전트가 정한 가정 중 운영자가 확인하지 않은 것: D-09(Gemini BeforeAgent)는 이 PR에 없고, D-10 --branch는 호출자의 현재 branch, D-12 원칙 intake는 gen-prd 절차의 가정입니다.
  • 판단해 주세요: 범위 축소. Gemini CLI, Grok, Cursor는 이 머신에 없어 검증할 수 없으므로 가드와 BeforeAgent를 설치하지 않고 기능 목록에 -로 둡니다. D-06/B7(3개 에이전트), D-09/B8, B11(연결 기기)은 미납품 또는 미검증입니다.
  • 판단해 주세요: Hide가 붙지 않은 Herdr의 pane도 cwd가 등록 checkout이면 같은 거절을 받고, 안내 명령은 그 pane을 부모로 잡지 못합니다. D-03 문자 그대로이며, 가르려면 hided bootstrap 응답에 바인딩을 실어야 합니다.
  • 판단해 주세요: --session, --machine, 다른 HERDR_SOCKET_PATH/HERDR_SESSION(inline, env, export)을 지정한 호출은 거절하지 않습니다. 격리 검증용 Herdr가 그렇게 뜹니다. source로 설정하면 읽지 못해 거절됩니다.
  • 판단해 주세요: 새 Mac의 Codex 첫 실행은 "Hooks need review"에 Herdr 통합 hook 하나만 보여 줍니다. Hide의 가드는 이미 Trusted이며, 이번에는 고치지 않습니다.
  • 조심해서 볼 파일: hide-agent-hooks/src/spawn_guard.rs - 셸 렉서의 오탐은 평범한 호출을 거절하는 fail-closed이고, 미탐은 허용입니다.
  • 조심해서 볼 파일: hide-agent-hooks/src/bin/hide-agent-hooks.rs - 모든 Bash 호출의 고빈도 경로이고, 어떤 실패도 exit 0과 무출력이어야 합니다.
  • 조심해서 볼 파일: hide-agent-hooks/src/install.rs, codex_trust.rs - 운영자 소유 hook 파일 쓰기와 Codex 신뢰(matcher까지 일치해야 Trusted).
  • 조심해서 볼 파일: hide-kit/src/agents.rs, contracts/snapshot-wire-enums.json - snapshot wire enum 순서와 기능 표.
  • 조심해서 볼 파일: hided/tests/opener_lifecycle.rs - 이 PR의 범위 밖이지만 S1을 막아 포함한 테스트 완화(원인 증명이 아닌 완화).
  • 비용 검토: 입력(Bash 호출)당 프로세스 시작 1회이고, herdr가 payload에 없으면 파싱도 spawn도 하지 않습니다. 상세와 수치는 docs/PERFORMANCE_TESTING.md에 있습니다.
  • 비용 검토: hide workspace bootstrap 자식은 launch 때만 1개, 2.5초 상한, 출력 16 KiB 상한이며 모든 종료 경로에서 정리됩니다. 로그는 256 KiB와 이전본 1개로 상한이 있고, 락 안 작업과 알림 fan-out은 없습니다.

Evidence

  • 확인한 것: 전체 cargo test --workspace 통과(S1), clippy 포함 lint(S2) 통과, web typecheck/lint/test 1164개 통과, hide-agent-hooks의 단위 111개와 통합 테스트(stand-in hide로 등록/미등록/꺼짐/무응답/느림/타 에이전트 세션)를 확인했습니다.
  • 확인한 것: 격리 Herdr 0.9.1과 실제 Claude Code 2.1.292, Codex CLI 0.160에서 agent start, 연쇄 pane run, send-text 거절, hide agent spawn으로 부모 선과 watch가 생기는 것, Codex가 PreToolUse(Bash)를 Trusted로 표시하는 것을 봤습니다.
  • 확인한 것: 일반 Bash 호출은 두 TUI 모두 출력과 지연이 없고, 대몬이 꺼진 상태에서 호출은 그대로 실행됩니다(7~39 ms, exit 0).
  • 확인한 것: hook 비용(릴리스, p50/p95, 부하 평균 약 4): 프로세스 시작만 2.8/4.3 ms, 일반 호출 Claude Code 5.7/7.2 ms, Codex 5.6/8.0 ms, 거절된 launch 약 10/12 ms.
  • 확인한 것: 로그인 사본(Claude, Codex)을 격리 HOME에서만 썼고, 토큰이 갱신되지 않았음을 지문 비교로 확인한 뒤 rm -P로 지웠습니다.
  • 확인하지 못한 것: Gemini CLI, Grok, Cursor(미설치, D-06/B7, D-09/B8 미납품), B11 연결 기기, Windows, Codex에서 대몬이 꺼진 상태의 라이브 관찰(통합 테스트만).
  • 확인하지 못한 것: 라이브 검증은 첫 리뷰 때의 head에서 했고, 이후 렉서, 다른 Herdr 허용, 진단 로그 이동은 단위와 통합 테스트로만 확인했습니다. Partial 칩 화면은 직접 보지 않았습니다(두 에이전트는 모든 기능이 ✓라 칩에 나오지 않습니다).
  • 확인하지 못한 것: 새 Codex 자식의 첫 spawn은 native_identity_unavailable로 한 번 실패할 수 있고 같은 intent 재시도로 수렴합니다(기존 동작). opener_lifecycle 실패는 재현하지 못해 완화로만 고쳤습니다.
추가 증거
  • 거절 화면, 체인/send-text 거절, 부모 선과 watch, Codex 신뢰 목록, 지연 측정은 실행 기록에 보관되어 있고(저장소 밖), 이 PR에는 넣지 않았습니다.
  • opener_lifecycle: 새로 쓴 fake helper 스크립트의 첫 exec가 약 174 ms(두 번째는 8 ms)이고, 이것이 supervisor의 2초 acceptance 창 안에 들어가 부하가 큰 실행에서 pid 파일을 못 쓴 것으로 추정합니다(측정된 것은 비용까지). 스크립트를 창 밖에서 한 번 실행해 두도록 했습니다(macOS만).
Verification record
  • PRD: agents/prd/herdr-spawn-guard/prd.md (sha256 52bd96d6a437c1cf127f32196c8d9244449e5c91fe22a4706e854d541f34afc5)
  • Base 5a8d59b → head 8a018e6, verified 2026-10-07T01:20:24.034Z: PASS
  • Verification report: agents/runs/herdr-spawn-guard/verification-report.json and agents/runs/herdr-spawn-guard/verification-report.md; source fingerprint 28ef9b50e63a91ddb8b024a247e4ef06c9d38d74999fcd5b03a26d4b718a25b6
  • Suites:
    • S1: GREEN bash scripts/verify-cargo.sh test (exit 0)
    • S2: GREEN bash scripts/verify-cargo.sh lint (exit 0)
  • Reviews:
    • Fidelity, Code, Security at da5ea05: Fix now(렉서 fail-closed와 미탐, 다른 Herdr 대상, 미등록 응답의 분류, 진단의 로그 파일 이동, 예약어와 wrapper, owner 핸드셰이크 exit 2, INSTALL.md 표, 오래된 주석)를 고쳤고, 첫 spawn ledger_unavailable은 픽스처 상태 폴더 권한(0755) 때문이라 제품 결함이 아니며, 체크아웃 바인딩 pane 건은 알려진 한계로 문서화했습니다.
    • Fidelity+Code and Security follow-up at 8617857: heredoc 본문을 가진 launch가 빠지는 회귀, export로 다른 Herdr를 가리키는 호출을 모두 고쳤습니다.
    • Final follow-up at 0db57b5 and 77e1de53 (tree identical to the verified head): <<\EOF, here-string 회귀를 고쳤고 새 Fix now는 없습니다.
    • Follow-up improvements 미반영: send-text 오탐(문서화), PowerShell 인용과 <intent> 자리표시자, hide_project::git::branch의 무제한 HEAD 읽기, delivery 진단 저장소 공유, $ 포함 값의 다른 Herdr 판정, sudo/timeout wrapper, 한 통합 테스트의 timeout.
    • verify한 head는 리뷰한 77e1de53에 main(Pin tab move answers outside the stream, and keep replica moves in their own field #684 이후)을 충돌 없이 merge한 것입니다. merge로 들어온 main의 변경은 이 PR의 리뷰 대상이 아니며, 겹친 파일 4개의 자동 merge는 직접 diff로 확인했습니다.
  • Evidence: 22 registered (17 file, 5 log); paths are local to the run directory
    • agents/runs/herdr-spawn-guard/artifacts/step0-probe.md
    • agents/runs/herdr-spawn-guard/live/evidence/claude-b1-refusal-pane.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b1-agent-start-pane.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b2-chained-pane-run.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b2-send-text.txt
    • agents/runs/herdr-spawn-guard/live/evidence/claude-b3-spawn-pane.txt
    • agents/runs/herdr-spawn-guard/live/evidence/claude-b3-agent-list.json
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b3-spawn-pane.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b3-agent-list.json
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b4-pane-split-allowed.txt
    • agents/runs/herdr-spawn-guard/live/evidence/claude-b4-ordinary-call.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-b4-ordinary-call.txt
    • agents/runs/herdr-spawn-guard/live/evidence/claude-b6-daemon-down.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-hooks-trust-list.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-hooks-review-list.txt
    • agents/runs/herdr-spawn-guard/live/evidence/codex-first-screens.txt
    • agents/runs/herdr-spawn-guard/live/evidence/latency-release.txt
    • agents/runs/herdr-spawn-guard/live/evidence/guard-real-hide-timing.txt
    • agents/runs/herdr-spawn-guard/live/opener/first-exec-quiet.txt
    • agents/runs/herdr-spawn-guard/live/opener/chain-latency-quiet.txt
    • agents/runs/herdr-spawn-guard/live/opener/full-run-samples.txt
    • agents/runs/herdr-spawn-guard/live/opener/cause.md
  • Changed paths: 48 (see Files changed)

A PreToolUse hook on the shell tool reads the call, and when it starts an
agent with herdr agent start, herdr pane run or herdr pane send-text inside a
Herdr pane of a registered checkout, it refuses the call and answers with the
hide agent spawn command that does the same and records the parent and the
watch. Everything else runs untouched and never starts a process.

The entry joins the five existing events of Claude Code's and Codex CLI's hook, with
the matcher the Codex CLI trust step already reads from the one function that writes
it.
Two features join the Partial popover's list, Bell and SpawnGuard, in the
kit's one adapter table. Bell is read off a new row field that a core test
holds to the doorbell's own target list; SpawnGuard is read off the hook part
that now installs the PreToolUse entry. Gemini CLI, Grok, Cursor, OpenCode and
Pi read unsupported for both.
…pays for it

The hook guide gains the guard's parsing, registered-checkout test and
fail-open rules, the six-event list with the Bash matcher, and the Bell and
spawn_guard rows of the feature table. The delivery guide says what the guard
does to a direct Herdr launch, and the performance guide records the cost of
the entry on an ordinary shell call with its measurement boundary.
…m reading as a launch

Review of the spawn guard found four ways it acted where it should not or
missed what it should refuse.
A call that names another Herdr (--session, --machine, or a socket or session
assignment that differs from the pane's own) is no longer refused, because the
hide agent spawn it points to starts the child in the pane's own Herdr.
Text that ends inside a quote, a backtick or a substitution holds no launch, so
a commit message heredoc with an early parenthesis and an odd quote is not
refused.
A launch behind a compound-command keyword or a wrapper (for, while, if, a
brace group, time, exec, command, nohup, env) is now found.
Only the daemon's own answers that a caller is not in a Hide checkout let a
call run silently; every other outcome, a device bridge that is gone included,
runs it and appends one daemon.unreachable line to the guard's log, since a
hook's standard error reaches nobody.
A failed owner handshake in the hook's environment ends the outer hook with 0,
so it cannot refuse a call by exit code.
…ort to later herdr calls

A launch whose prompt is passed as "$(cat <<'EOF' ... EOF)" with an apostrophe
or odd quote in the body was being dropped as unterminated text; the
substitution now skips heredoc bodies the way the top-level line does, so that
launch is refused again and the commit-message case stays allowed.
An export, declare, typeset, bare assignment or unset of the variables that
choose a Herdr now aims every later herdr call in the same line away from the
pane's own, which is how an isolated server is reached.
Text typed into a pane skips only wrappers and assignments, so a sentence that
starts with "if" is not read as a compound command.
…eptance window

acceptance_timeout_ends_cli_spawned_before_watcher failed in full-workspace
runs with "fake helper never wrote its pid" and passed alone.
The fake helper is a script written fresh into a temp folder and run for the
first time inside the supervisor's two-second acceptance window.
macOS assesses the first exec of a file it has not run before, 174 ms for a
two-line script on a quiet machine against 8 ms for the second, and the cost
grows with the machine's other work.
When it passed the window, the owner ended the CLI tree before it wrote a pid.
The script is now run once with a warm-up flag that exits at once, outside any
window, the way the test already warms the hided binary.
… shell does

A heredoc delimiter that carried a backslash or quotes inside a substitution
was stored with them, so no body line matched it and the rest of the call was
swallowed as heredoc text, and a here-string on a line of a multi-line
substitution opened a heredoc by mistake.
Both made a real launch escape the guard; the delimiter is now the word a shell
reads and a here-string opens no body.
The opener test's warm-up run is limited to macOS, where the first-exec
assessment it pays exists, and the comments no longer claim more than was
measured.
@yansfil

yansfil commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merge check before merge: git merge-tree of origin/main c1e4c90 with head 8a018e6 has no conflicts; on that merge result scripts/verify-cargo.sh lint, scripts/verify-cargo.sh test (74 test binaries green) and scripts/verify-web.sh all passed.

@yansfil
yansfil merged commit 7852aef into main Oct 7, 2026
22 checks passed
@yansfil
yansfil deleted the prd/herdr-spawn-guard branch October 7, 2026 01:52
yansfil added a commit that referenced this pull request Oct 7, 2026
Related: PRD `agents/prd/codex-herdr-hook-trust/prd.md` · 선행: #670
(Codex hook 신뢰), #668 (kit의 Herdr 연동), #688 (spawn guard)

## Summary

- #670 이후 hide 자기 hook은 Codex에 신뢰로 기록되지만, kit이 같이 설치하는 Herdr의 Codex
hook은 남의 것이라 새 기기에서 "Hooks need review"가 뜨고, 승인 전까지 Herdr는 그 pane의 Codex
세션을 모른다.
- kit이 `herdr integration install codex`를 부르기 직전과 직후에
`~/.codex/hooks.json`을 읽어, 그 호출이 추가한 항목(event, matcher, 종류, command)을
kit 기록(`herdr_hooks`)에 남긴다. Herdr의 명령은 hide에 적혀 있지 않다.
- 기록된 항목은 #670의 `select_targets`가 hide 자기 항목과 같은 글자 단위 일치 규칙으로 함께 고른다.
신뢰 확인은 pass당 한 번이고, 에이전트 부품 설치 뒤로 옮겨 첫 설치에서 한 번의 app-server 세션으로 둘 다
신뢰된다.
- 운영자가 먼저 설치한 연동, 같은 스크립트 이름을 흉내 낸 명령, 다른 에이전트는 바뀌지 않는다.
`docs/agent-hooks.md`, `INSTALL.md`, `ARCHITECTURE.md`에 이 규칙과 2026-10-07
조사 결과를 적었다.

## Review

- **판단해 주세요 (보안)**: 학습은 설치 호출 전후 diff다. 그 한 번의 호출 구간에 다른 도구가 항목을 순수하게
추가하면 Herdr 것으로 기록되고 신뢰된다.
상한 4개, 사용자 권한의 쓰기가 필요하고, `config.toml`을 직접 쓰는 것보다 더 얻는 것은 없다. 호출 구간 밖의
쓰기, 다른 항목의 삭제나 수정은 막았다.
더 막으려면 `integration status`의 스크립트 경로를 명령에 요구하는 규칙이 필요한데, 손으로 쓴 Herdr 규칙에
가까워 넣지 않았다. 이 잔여 위험을 받아들이시겠습니까?
- **판단해 주세요 (기존 기기)**: `herdr:codex`만 있고 항목 기록이 없는 기기(#668 빌드가 설치)는 학습하지
못한다. Herdr가 이미 쓴 항목은 재설치해도 그대로라 kit에 추가로 보이지 않는다.
그 기기는 검토 화면을 한 번 보고, 승인하면 그 해시가 신뢰된다. Herdr가 옛 항목을 지우지 않고 새 항목만 더할 때만
회복하며, 제자리 교체는 기록에 없는 항목의 제거라 거절된다. 이전은 넣지 않았다.
- **판단해 주세요 (D-03 해석)**: 신뢰 확인을 #670의 자리(부품 루프 안)에서 `agent_kit::apply`
뒤로 옮겼다. Herdr 연동이 그때서야 설치되므로 B1에 필요하다. 프로세스와 확인 경로는 그대로 하나다.
- **운영자가 확인하지 않은 구현 측 가정**: D-02의 학습 방식(설치 시점 기록), D-04, D-05 조사(Cursor
현재 CLI와 Pi 사용자 extension은 문서 추정), D-06, D-07.
- **조심해서 볼 파일**: `hide-agent-hooks/src/codex_trust.rs` - 신뢰 대상
선택(`select_targets`, `learn_herdr_entries`), 가장 먼저 볼 곳.
`hide-kit/src/agent_kit.rs` - 설치 전후 읽기, `apply`/`reports` 분리.
`hide-kit/src/lib.rs` - 확인 위치와 Codex 부품 실패 전파. `hide-kit/src/record.rs`
- `herdr:codex`가 있을 때만 항목을 읽는 관문.
- **비용 검토**: 새 프로세스와 새 상태 파일은 없다. `codex app-server` 확인은 pass당 1회 그대로이고,
설치 호출마다 hooks.json 읽기 2회, 학습 항목 상한 4개다.

## Evidence

- **확인한 것**: 고정된 Herdr 0.9.1(sha가 `contracts/herdr-bundle.json`과 일치)과
codex-cli 0.160.0, 격리된 Herdr 서버, 비공개 HOME에서 실제 kit
pass(`hide_kit::apply`)를 돌려 봤다.
빈 `~/.codex`에서 한 pass로 7개 항목이 신뢰됐고 Codex가 "Hooks need review" 없이 시작했으며,
첫 턴 뒤 `herdr agent list`에 `agent_session`(source `herdr:codex`)과 hide의
`hide_hooks` 토큰이 있었다(B1, 수정 뒤 코드로 다시 확인).
반복 pass는 `config.toml`을 바이트 단위로 그대로 두었다(B6). 운영자가 먼저 설치한 연동은 신뢰되지 않아
Codex가 그 hook 하나만 검토 화면에 올렸다(B2). 같은 이름의 다른 경로 명령도 검토 화면에 올랐다(B3).
워크스페이스 전체 `cargo test`와 `lint`가 통과했다(kit 140개, `hide-agent-hooks` 통합
22개, 단위 25개 이상 포함). `auth.json` 사본의 지문은 끝까지 같았고 `rm -P`로 지웠다.
- **확인하지 못한 것**: B4(Herdr 명령 변경)와 B5(기록 실패)는 stand-in으로만 확인했고 실제
Herdr/Codex로는 보지 않았다. 패키지된 `hide.app`, 기기(device) 경로, Herdr가 명령을 제자리에서
바꾸는 실제 동작, Herdr 재설치가 `config.toml`의 `hooks.state`를 보존하는지, Cursor와 Pi의
실제 동작은 확인하지 못했다.

<details><summary>Verification record</summary>

- PRD: `agents/prd/codex-herdr-hook-trust/prd.md` (sha256
5efb1726de39a3c658cbe20a3d78b38b17f3e111d72cdce00b2e58ca7ed1a5ae)
- Base 7852aef → head f4ec34a, verified 2026-10-07T02:49:37.198Z: PASS
- Verification report:
`agents/runs/codex-herdr-hook-trust/verification-report.json` and
`agents/runs/codex-herdr-hook-trust/verification-report.md`; source
fingerprint
303af8c81f58d9b78dfe504150308ce977849713bc2efe752613539d398fa624
- Suites:
  - S1: GREEN `bash scripts/verify-cargo.sh test` (exit 0)
  - S2: GREEN `bash scripts/verify-cargo.sh lint` (exit 0)
- Reviews (조언용, 병합 권한 아님):
- 아래 SHA는 origin/main(9e9e6a9)으로 충돌 없이 리베이스하기 전 값이다. 이 PR의 diff는 같고,
리베이스한 head에서 verify가 다시 통과했다.
- Fidelity: a586392a, 4d199851, e27da3be, 0ff0c5f6 검토. Fix now 없음. 사람
결정으로 넘긴 것: 기존 기록 기기 미학습(위 Review 2번), 신뢰 확인 위치 이동. 문서 문구 두 건은 0ff0c5f6에서
반영.
- Code: a586392a에서 Fix now 3건(시험이 주장을 확인하지 못함, 오류 경로 시험 부족, 설치 전후 읽기 간격)
모두 4d199851에서 수정; 4d199851에서 1건(거절된 학습이 기록을 지움)을 e27da3be에서 수정;
e27da3be는 Fix now 없음. 0ff0c5f6(문서와 주석만 바뀜)은 Code와 Security가 다시 보지 않았고
Fidelity가 확인함.
- Security: a586392a에서 Fix now 1건(전후 읽기 창이 넓음)을 4d199851에서 좁힘; 4d199851과
e27da3be는 Fix now 없음.
- 받아들이지 않은 제안: 학습 집합 길이 상한, 기록에서 사라진 항목의 매 pass 정리, `integration status`
경로로 명령 교차 확인, 기록 로드 시 상한 검사(이유는 Review에).
- Follow-up improvements:
`a_refused_learn_keeps_what_was_recorded_before`에 설치 호출 발생 단언 추가,
`handler_type` 검사가 세 곳에 겹침.
- Evidence: 3 registered (2 file, 1 log); paths are local to the run
directory
  - agents/runs/codex-herdr-hook-trust/live/evidence.md
  - agents/runs/codex-herdr-hook-trust/live/b1/screen-after-prompt.txt
  - agents/runs/codex-herdr-hook-trust/live/evidence-rerun.md
- Changed paths: 22 (see Files changed)

</details>
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.

1 participant