Repository navigation
Refuse a direct Herdr agent launch and point to hide agent spawn - #688
Merged
Merged
Conversation
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.
Contributor
Author
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: 선행 #668, #670 (둘 다 이미 main에 merge됨)
Summary
herdr agent start로 직접 띄운 자식은 부모 기록이 없어 관계도에 선이 없고 watch도 없어, 멈춰도 아무도 깨우지 않습니다.PreToolUse(Bash matcher)를 더해, 등록된 checkout의 Herdr pane에서 이런 호출을 실행 전에 거절합니다.hide agent spawn --parent here --name ... --kind ... --repo ... --branch ...명령을 담아, 에이전트가 한 번에 다시 시도합니다.herdr agent start, 그리고 첫 단어가 에이전트 종류인herdr pane run/send-text뿐이고, 그 밖의 호출은 출력도 지연도 없이 그대로 실행됩니다.종과herdr 직접 실행 차단항목이 에이전트별로 더해집니다(해당 없는 에이전트는 -).Review
cd x && herdr agent start ...)은 호출 전체를 거절하고, 이유에 나머지 명령을 따로 실행하라고 적습니다. 열린 질문의 답입니다.BeforeAgent)는 이 PR에 없고, D-10--branch는 호출자의 현재 branch, D-12 원칙 intake는 gen-prd 절차의 가정입니다.BeforeAgent를 설치하지 않고 기능 목록에 -로 둡니다. D-06/B7(3개 에이전트), D-09/B8, B11(연결 기기)은 미납품 또는 미검증입니다.--session,--machine, 다른HERDR_SOCKET_PATH/HERDR_SESSION(inline,env,export)을 지정한 호출은 거절하지 않습니다. 격리 검증용 Herdr가 그렇게 뜹니다.source로 설정하면 읽지 못해 거절됩니다.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을 막아 포함한 테스트 완화(원인 증명이 아닌 완화).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-inhide로 등록/미등록/꺼짐/무응답/느림/타 에이전트 세션)를 확인했습니다.agent start, 연쇄pane run,send-text거절,hide agent spawn으로 부모 선과 watch가 생기는 것, Codex가PreToolUse(Bash)를 Trusted로 표시하는 것을 봤습니다.rm -P로 지웠습니다.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
agents/prd/herdr-spawn-guard/prd.md(sha256 52bd96d6a437c1cf127f32196c8d9244449e5c91fe22a4706e854d541f34afc5)agents/runs/herdr-spawn-guard/verification-report.jsonandagents/runs/herdr-spawn-guard/verification-report.md; source fingerprint 28ef9b50e63a91ddb8b024a247e4ef06c9d38d74999fcd5b03a26d4b718a25b6bash scripts/verify-cargo.sh test(exit 0)bash scripts/verify-cargo.sh lint(exit 0)ledger_unavailable은 픽스처 상태 폴더 권한(0755) 때문이라 제품 결함이 아니며, 체크아웃 바인딩 pane 건은 알려진 한계로 문서화했습니다.export로 다른 Herdr를 가리키는 호출을 모두 고쳤습니다.<<\EOF, here-string 회귀를 고쳤고 새 Fix now는 없습니다.<intent>자리표시자,hide_project::git::branch의 무제한 HEAD 읽기, delivery 진단 저장소 공유,$포함 값의 다른 Herdr 판정,sudo/timeoutwrapper, 한 통합 테스트의 timeout.