Skip to content

feat: report agent hook status to hided and judge status hook first - #1899

Merged
yansfil merged 22 commits into
mainfrom
feat/hooks-first-status
Oct 30, 2026
Merged

yansfil merged 22 commits into
mainfrom
feat/hooks-first-status

Conversation

@yansfil

@yansfil yansfil commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

에이전트 훅이 상태를 Herdr에 쓰고 hide가 그걸 다시 읽던 길을 없애고, 훅이 hided에 직접 보고합니다.
상태는 훅이 보고한 턴, 세션 파일, Herdr 순으로 판단합니다. Herdr의 상태는 세션에 훅 턴이 없을 때만 씁니다.
훅 턴은 같은 세션의 다음 훅 이벤트, 또는 그 턴보다 나중에 읽힌 세션 파일의 턴 끝(Claude Esc 중단 포함)까지 유지되고, 시간 기준은 없습니다. 권한 대기(Claude PermissionRequest와 Notification, Codex PermissionRequest, OpenCode permission)는 waiting 턴으로 보고됩니다.
hided가 없으면 훅은 2초 안에 끝나고, 실패는 화면 경고 없이 last-report-failure.json과 진단 로그에 남습니다.

스크린샷 없음: 화면 코드 변경 없음 (web/src, site/, design/을 건드리지 않음)

Review

  • 판단해 주세요: 에이전트별로 남은 빈칸입니다. 각 항목은 다음 훅 이벤트나 Herdr 상태가 메웁니다.
    • OpenCode 2, Pi, omp는 권한 대기를 보고하지 않습니다(훅 이벤트가 없음).
    • Grok과 Antigravity는 사용자 중단(interrupt)을 보고하지 않아, 중단 뒤에도 working으로 남다가 다음 이벤트에서 바뀝니다.
    • Claude의 권한 대기는 턴이 아니라 호출 단위로 둡니다. PermissionRequest가 가리킨 호출(도구 이름과 입력 digest, 키 순서 무관)마다 열린 승인을 두고, 하나라도 열려 있으면 행은 '나를 기다림'입니다. 그 호출이 끝나거나 세션 파일에 결과가 적히면 닫힙니다. 서브에이전트가 연 승인도 같습니다. 메인 Stop은 턴만 끝내고 열린 승인은 그대로 둡니다. Claude 2.1.314는 Agent를 백그라운드로 돌리고, 서브에이전트 이벤트도 메인 session_id로 옵니다(검증 로그로 확인). 프롬프트와 중단은 열린 승인을 모두 닫습니다. 한 세션에 최대 16개입니다.
    • 대화창 거절은 훅 이벤트가 없습니다(PermissionDenied는 auto mode 전용). 두 곳에서 세션 파일의 결과로 승인을 닫습니다. helper는 다음 훅 이벤트(도구 호출이나 Stop)에서 파일 끝 256 KiB를 읽습니다. 코어는 Herdr 상태 변화마다 label worker가 이미 하는 읽기에서, 최근 64개 호출 중 키별 마지막 호출에 결과가 있는 키를 받아 승인보다 나중 seq일 때 닫습니다. 그래서 의견을 붙여 거절한 뒤 글만 쓰는 턴도 Stop 전에 working이 되고, 같은 명령을 두 번 부르면 둘째 호출의 결과를 기다립니다. 두 곳 모두 입력이 같은 호출만 봅니다. 백그라운드 서브에이전트의 호출은 메인 세션 파일에 없으니, 메인의 같은 도구 호출 결과로 서브에이전트 승인이 닫히지 않습니다. 세션 읽기가 중단(Esc)을 찾으면 턴과 함께 열린 승인도 모두 닫습니다. Mutex 아래 I/O는 없습니다.
    • 훅이 updatedInput으로 입력을 바꾸면 digest가 달라 그 호출의 끝이 대기를 풀지 못합니다. 세션 파일에 결과가 적힌 뒤의 다음 호출이나 Stop이 풉니다.
    • Claude에서 첫 출력 전에 Esc를 누르면 Claude 2.1.314는 프롬프트를 입력창에 되돌립니다. 세션 파일에는 프롬프트 기록과 훅 첨부만 남고, 에이전트 기록, 중단 기록, Stop, Notification은 없습니다(로컬 세션 파일에서 확인, 다시 보낸 프롬프트는 같은 parentUuid). 그래서 Claude 읽기에서 프롬프트 뒤에 에이전트 기록이 없는 턴을 Unanswered로 읽습니다. 훅 턴보다 나중 seq에서 Herdr가 at rest로 읽을 때 그 턴을 쉼(idle)으로 끝냅니다. 시간 문턱은 없습니다. 출력이 있었던 턴에는 적용되지 않습니다. 생각만 하고 아무 기록도 쓰기 전인 턴에서 Herdr가 at rest로 읽으면 잘못 끝날 수 있습니다. 다음 훅 이벤트가 working으로 되돌립니다.
    • hided 재시작: 열린 승인은 코어 메모리에만 있습니다. 재시작 뒤 아직 열린 대화창은 그 세션의 다음 훅 보고 전까지 세션 파일과 Herdr로 판단합니다.
    • 서브에이전트가 자기 대화창에서 거절하면 결과는 서브에이전트 자신의 파일에 적힙니다. 메인 세션 파일에는 없으므로 이 승인은 메인의 다음 프롬프트나 중단(Esc)까지 열려 있습니다. 후속으로 서브에이전트 자신의 세션 파일까지 읽으면 메울 수 있습니다.
    • 빠른 재시작: 새 세션이 이미 보고한 뒤에 Herdr가 끝난 세션의 id를 처음 말하면, 그 말이 더 새것으로 읽혀 새 세션의 턴은 다음 훅 이벤트부터 보입니다.
    • Claude의 PreToolUse와 PostToolUse는 매처가 없어 모든 도구에서 돕니다. Codex의 매처는 그대로라 Codex에서 MCP 도구를 승인하면 다음 셸, 질문, 파일 도구나 Stop까지 waiting입니다.
    • 같은 pane에서 다시 띄운 에이전트: Herdr가 낡은 세션 id를 말하고 그 id로 보고한 세션이 없으면, Herdr가 id를 바꾼 뒤 마지막으로 보고한 세션을 따릅니다. 대화형 세션의 훅이 한 번도 보고하지 않았는데 같은 pane의 claude -p가 보고했다면 그 턴이 보일 수 있습니다.
    • Herdr가 pane을 넘긴(handoff) 뒤에는 엔진이 pane에 에이전트가 없다고 알릴 때 사실이 지워집니다.
    • Codex 공유 서버처럼 pane에 묶이지 않은 호출은 agent_pane_required로 거절됩니다.
  • 조심해서 볼 파일:
    • herdr-core/src/agent_hooks/facts.rs - runtime mutex 밖의 자체 잠금, 저장은 LatestFile; 첫 실행에 pane 파일에서 한 번 시드합니다.
    • herdr-core/src/sidebar.rs - 축 판단 순서(hook -> session file -> Herdr)가 바뀐 자리.
    • hided/src/hook_request.rs, hided/src/cli.rs - pane 증명 요구와 failure path(거절도 JSON으로 답함).
    • herdr-core/src/agent_hooks/facts.rs의 end_by_session_read와 bound - 세션 파일 턴 끝이 훅 턴을 끝내는 조건(그 턴이 처음 놓인 Herdr seq보다 나중의 읽기, Herdr는 idle/done), 그리고 낡은 Herdr 세션보다 훅 세션을 따르는 조건.
    • hide-agent-hooks/src/bin/hide-agent-hooks.rs의 report_recorded_turn과 run_prompt_hook - prompt 보고를 바깥 프로세스로 옮김. 안쪽 프로세스가 예산에서 잘려도 결과가 남음. 바깥 프로세스가 stdin을 먼저 읽어 그 세션으로 보고하고, 같은 바이트를 안쪽 프로세스 stdin으로 넘김(--payload truncated|unread로 읽기 결과 전달). 그래서 pane에서 마지막으로 보고한 claude -p 세션에 붙지 않음.
    • hide-session/src/turns.rs의 TurnMark::Prompt, TurnMark::Reply, TurnEnded::Unanswered - Claude 읽기만 응답 기록을 표시하므로 다른 에이전트 턴은 Unanswered가 되지 않음. herdr-core/src/agent_hooks/facts.rs가 이를 쉼으로 끝냄.
    • hide-node-link/src/protocol.rs - main의 64(PR 리뷰 상태)와 겹쳐 이 PR의 기기 훅 보고를 NodeLink 65로 올림(docs/ARCHITECTURE.md 함께).
    • hide-agent-hooks/src/counters.rs의 Said와 fold_said - 턴과 열린 승인 집합을 pane 파일 잠금 아래에서 한 번에 바꿈(병렬 훅이 서로 덮지 않게). hide-session/src/calls.rs - 호출 키와 세션 파일 결과 읽기를 helper와 세션 읽기가 함께 씀(helper가 hide-session에 의존하게 됨).
    • herdr-core/src/agent_hooks/facts.rs의 close_answered_waits - 보고의 waiting과 세션 읽기의 answered_calls로 승인을 닫음.
    • hide-host/src/panes.rs - 기기 pane 다리가 거절을 호출자에게 답하기 전에 먼저 기록하게 순서를 바꿈. remote mailbox 레인의 node_contract::a_device_pane_s_proof_crosses_the_link_and_its_refusals_are_reported가 31640faa7에서 두 번 연속 실패한 원인입니다. 테스트가 busy 답을 읽고 대기 연결 16개를 닫으면, 그 닫힘 기록이 busy 기록보다 먼저 들어갔습니다.
    • 엔진 경계: main의 refactor: route the core's Herdr calls through one engine boundary #1903 병합 뒤 hook token restorer용 hook_token_link/hook_token_connector를 지웠고, scripts/check-engine-boundary.py의 임시 허용 항목 세 개(hook_tokens.rs, report.rs, hide-agent-hooks.rs)도 지웠습니다.
    • hide-agent-hooks/src/report.rs의 deadline - 보고 deadline을 훅 시작 기준으로 하고, entry가 쓰는 install::hook_timeout에서 0.5초를 뺀 안쪽으로 묶음(Codex Interrupt 3초).
    • hide-agent-hooks/src/opencode/plugin.js, tui.js, pi_extension/extension.js - 턴 보고를 합쳐 보냄(진행 중 하나, 대기 중 최신 하나).
  • 엔진 노드 CI allowlist: hide-agent-hooks/src/report.rs의 Herdr 호출과 herdr-core/src/coordination/hook_tokens.rs(Restorer)를 지웠습니다. 둘 다 엔진 노드의 allowlist에 있습니다.
  • 비용 검토:
    • Claude는 이제 모든 도구 호출의 시작과 끝마다 helper를 한 번씩 실행합니다(예전에는 셸, 질문, 파일 도구만). helper는 pane 파일 하나를 읽고, 그 호출이 턴을 working으로 되돌릴 때만 hide 프로세스를 하나 띄웁니다.
    • 턴을 말하는 다른 이벤트(prompt, Stop, 권한, 알림, 중단)는 매번 hide 하나로 보고합니다. 세션 시작과 서브에이전트 수 변경도 같습니다.
    • 코어는 보고 하나에 사실 한 칸을 바꾸고, 바뀐 경우에만 저장하고 다시 게시합니다. 같은 보고가 반복되면 게시 요청이 없습니다(런타임 테스트로 확인).
    • 세션 파일 읽기(Claude Esc로 턴이 끝나는 근거)는 에이전트 라벨 설정과 무관하게 돕니다. 라벨을 끄면 분석과 AI 필드만 빠지고, label worker는 Herdr 상태가 바뀔 때마다 세션을 읽어 사실을 올립니다(labels::tests::an_interruption_is_read_from_the_session_file_with_summaries_off, runtime::tests::labels::a_hook_turn_ends_on_the_session_files_interruption_with_summaries_off).
    • helper의 세션 파일 꼬리 읽기(거절 확인)는 세션이 이름 붙은 호출을 기다리는 동안의 도구 이벤트에서만 돕니다. 평소 도구 호출에는 없습니다. 코어가 아닌 helper 프로세스 안에서 돌고 256 KiB로 묶입니다.
    • 이 읽기는 고빈도 경로가 아닙니다. label worker의 읽기 스레드에서 Herdr 상태 변화 한 번에 한 번 돌고, 훅 보고나 tick마다 다시 읽지 않습니다(기존 no per-tick reread 테스트). 이번 PR은 새 읽기를 더하지 않았고, 이미 읽던 기록에서 턴 끝 표시를 하나 더 꺼냅니다.
    • Mutex<Runtime> 아래에서는 파일 I/O가 없습니다. 읽은 결과는 잠금 밖에서 만든 overlay로 넘어오고, 잠금 안에서는 그 읽기의 Herdr seq와 훅 턴의 seq를 비교하는 일만 합니다(end_by_session_read).

Evidence

  • 확인한 것:
    • scripts/verify-cargo.sh lint, scripts/verify-cargo.sh test 통과.
    • scripts/verify-web.sh web typecheck, web lint 통과.
    • e2e: pane-connection, opencode-plugin, pi-omp-extension, grok-cursor-hooks, direct-prompt-observation, agents-follow-herdr 통과(실제 고정 Herdr와 후보 hided).
    • B13(디버그 빌드, hided 없음, 부하 평균 49): SessionStart 0.45-1.65 s, Stop 0.43-1.59 s, PermissionRequest 0.43-1.13 s. 첫 실행이 가장 느림.
    • 실패 기록: {"event":"PermissionRequest","error":"unavailable",...}. 화면 경고 없음.
    • 훅 하나당 프로세스 비용: 턴을 말하는 이벤트는 hide 프로세스 1개(디버그 약 0.13 s, 부하 없을 때), 도구 이벤트는 0개.
    • Claude 모든 도구에서 helper 실행(디버그 빌드, 30회씩, 부하 평균 52): Grep PreToolUse 중앙값 21 ms(p90 39), Grep PostToolUse 19 ms(p90 32), 결과 300 KiB인 Read PostToolUse 25 ms(p90 67). hide 프로세스 0개. 잘린 Read 결과는 format 진단을 남기지 않음.
    • 검증 1회차 지적 고침: Claude Esc(세션 파일 [Request interrupted by user], 2.1.314 실제 파일에서 모양 확인, 어댑터 계약 테스트), 같은 pane 재시작(런타임 테스트), 병렬/서브에이전트 호출이 대기를 지우던 것(헬퍼 통합 테스트와 단위 테스트), 사라진 prompt 보고(바깥 프로세스가 보고하고 모든 실패를 report.failed 로그 줄로 남김), Codex Interrupt 타임아웃 3초.
    • B10 런타임 테스트 a_waiting_hook_report_reaches_the_row_as_an_approval_until_the_turn_runs_again: Waiting 보고, 재게시 요청, 행 approval/stopped(Herdr는 working), 같은 보고 반복 시 요청 없음, Working 보고 후 none/working.
    • B19: agent journey 워크플로를 fake model로 직접 실행(run 41060503507). linux, macos, windows 각각 7개 에이전트 x 12칸 통과(Grok guidance_memory는 N/A). 각 행은 일하는 중을 읽고 답 뒤에 쉬는 상태를 읽음. 격리된 Herdr 0.9.5와 후보 hided.
  • 확인하지 못한 것:
    • '나를 기다림'의 실측: journey의 에이전트는 승인 없이 돌아 권한 대기가 생기지 않습니다. 이 상태는 런타임 테스트, sidebar 테스트, e2e(opencode permission)로만 확인했습니다.
    • Codex Interrupt가 실제로 오는지는 실행으로 확인하지 못했습니다. PermissionRequest는 격리 검증에서 0.166.0이 실제로 보냄을 확인했습니다.
    • 첫 권한 대기에서 0.27초 만에 working으로 돌아간 1회 관찰은 그 실행에 호출 로그가 없어 원인을 확인하지 못했습니다. 병렬 호출과 서브에이전트 호출이 대기를 지우는 경로는 막았습니다.
    • 로컬 macOS에서 서명된 에이전트로 실행한 journey: 실행하지 않음(부하 평균 49-135, 디스크 여유 6-8 GiB).

Agent hooks report each session's turn and subagent counts to the core
through a hided hook request (`hide workspace status --hook`), proven
from the pane like every other hook request, instead of writing Herdr
pane metadata. The core keeps the facts per pane and session, lays them
on the session it projects, and saves what a restart needs, so the Herdr
token restorer is gone.

Activity, completion and approval are judged by the hook's turn first,
then the session file, then Herdr. Claude Code and Codex register
PermissionRequest, Claude Code Notification and Codex Interrupt; the
OpenCode plugins and the Pi and omp extension report their turns.
The hook counts are read from the snapshot rather than Herdr pane tokens, and a hook whose report must reach hided runs from inside the agent's own process in its pane, which the pane proof requires.
A key is answered only when its last call has a result, so a command run twice waits on its second run. The helper's session-file check no longer falls back to the tool's last call for a key with an input, so a background subagent's approval, asked after the main Stop under the main session's file, stays open until its call ends. An interruption the session read finds closes the open approvals with the turn.
@yansfil
yansfil merged commit d87a02c into main Oct 30, 2026
85 of 87 checks passed
@yansfil
yansfil deleted the feat/hooks-first-status branch October 30, 2026 18:26
yansfil added a commit that referenced this pull request Oct 30, 2026
…undary (#1912)

## Summary

Agents in a Hide pane were taught to drive panes with Herdr's own CLI
(`herdr agent prompt`, `herdr workspace report-metadata`,
`HERDR_BIN_PATH`), which goes around Hide and leaves no letter, reply or
retry.
This adds the Hide commands that replace them, running through the
core's engine boundary, and removes Herdr from everything Hide teaches
an agent.

- `hide pane read <pane>` and `hide agent read <agent>` print a pane's
last 120 lines, unwrapped (`--lines`, at most 2,000).
- `hide pane send <pane> <text>` types text and presses Enter only with
`--enter` (at most 16 KiB).
- `hide pane open --beside [--focus] -- <command>` runs a command in a
new pane beside the caller and prints its id; focus stays unless
`--focus`. Several words after `--` stay one argument each, quoted for
the machine's shell (POSIX, PowerShell on Windows); one word is typed as
written.
- `hide workspace purpose <text>` sets the checkout's one-line purpose
(at most 40 characters).
- `hide request send … --force` puts a letter into the recipient's input
now, even while it works, and records it like any letter; while
someone's text is in that input it is refused with `composer_not_empty`
and nothing is typed or recorded.
- A refusal is one JSON line with the reason and the next step, and a
non-zero exit.

스크린샷 없음: 화면을 바꾸지 않음 (CLI 명령과 에이전트 안내 문구만 바뀜)

```
$ hide request send w1:p1 --intent … --kind report --body "…" --force   # agent working, input empty
{"ok":true,"result":{"id":"letter-1","forced":true,…}}
$ hide request send w1:p1 … --force                                       # "half typed words" in the input
{"ok":false,"reason":"composer_not_empty","next_action":"Someone is typing in the recipient's input, so nothing was typed or recorded; send it again without --force, and it is delivered once they submit"}
$ hide pane read w1:p1 --lines 2001
{"ok":false,"error":{"code":"lines_out_of_range","message":"Pass --lines from 1 to 2000"}}
```

## Review

- **판단해 주세요**: `--force` checks the input twice, once at send (refuses,
records nothing) and again right before typing; if someone started
typing in between, the letter is not typed and stays as an ordinary
`--now` letter (`delivery.forced_deferred` in the log). Is staying as a
letter the right outcome there?
- **결정됨 (PRD D-14)**: an agent kind whose hook takes letters at tool
calls (five kinds, `tool_letters` in `hide_agent_adapter`) gets a forced
letter at its next tool call, as `--now` already does; only kinds
without that hook have it typed into their input mid-turn.
- **조심해서 볼 파일**: `herdr-core/src/delivery/doorbell.rs` - forced letters
skip the working wait, unread turn and draft hold, but still wait on an
operator approval or a blocked pane; the composer re-read runs in the
pass, off the lock.
- **조심해서 볼 파일**: `herdr-core/src/runtime/pane_command.rs` - what is read
under `Mutex<Runtime>`: caller proof, target pane or agent, engine
handle; every Herdr call runs after the lock in
`herdr-core/src/pane_command.rs` `Prepared::run`.
- **조심해서 볼 파일**: `hide-agent-hooks/src/install.rs`
`Quoting::command_line` - which characters stay bare and the `& `
PowerShell needs before a quoted program; tested for both shells on
every system.
- **조심해서 볼 파일**: `hided/src/server.rs` - the new `pane` scoped request
type is exempt from the 16 KiB frame limit because a send carries up to
16 KiB of text plus its envelope.
- **조심해서 볼 파일**: `hide-agent-hooks/src/runtime.rs`,
`hided/assets/guide.md` - the guidance text agents read at session
start; the guide skill stub moves to version 4 so installed stubs are
rewritten.
- **비용 검토**: no resident work. Each command is one request; `pane open`
polls the new shell at 100 ms for at most 10 s off the lock before
typing the command.

## Evidence

- **확인한 것**: `scripts/verify-cargo.sh lint && scripts/verify-cargo.sh
test` on 4bf7815: 6,555 tests passed, 0 failed (45 binaries); rerun on
the final commit is recorded on the mission.
- **확인한 것**: one live run per command on an isolated Herdr 0.9.5 with
this branch's hided (0c56889) and one agent of a kind without
tool-call letters, busy on a sleep job:
- `--force` while it worked: the bell line was typed at once, the letter
went to delivered with the hook's receipt, and the agent kept working.
- `--force` after typing "half typed words" into its input: refused
`composer_not_empty`, exit 2; the draft stayed and the refused text
never appeared.
- `pane read` and `agent read` returned the agent's screen; `agent read`
names pane `w1:p1`.
- `pane open --beside -- sh -c 'echo X spaced'` ran in a new pane of the
same tab with its script as one argument (printed `X spaced`), and focus
did not move.
- `pane send` without `--enter` typed but did not run the line; with
`--enter` it ran.
  - `workspace purpose` set the workspace's `purpose` token.
- Refused with exit 2, reason and next step: 2,001 lines, an unknown
pane, an unknown agent, a 41-character purpose, a 16 KiB + 1 send;
without a pane credential it was refused `checkout_not_registered`.
- The run cleaned up its processes, socket and probe; the config guard
restored nothing and reported no change of its own.
- **확인한 것**: the input race is pinned by runtime tests: typed into a
working agent over an empty input; text in the input at typing time
keeps it as a letter; text at send time refuses and records nothing; a
deferred letter is held as `draft` for text and `composer_unconfirmed`
for an unread screen.
- **확인한 것**: runtime tests pin how a command finds its target: an agent
by name, registration id or pane, `target_ambiguous` for two of one
name, `remote:<device>:pane:<id>` on that device's engine, the purpose's
engine workspace or `purpose_no_workspace`, and `caller_context_changed`
/ `pane_required`.
- **확인한 것**: `scripts/check-engine-boundary.py` passes with its
allow-list unchanged; tests pin that the session-start note, `hide
guide` and `hide mission help` name no Herdr, and that every command
they teach is in `contracts/hide-cli.json`.
- **확인하지 못한 것**: the second input check (someone starts typing between
the send and the typing) was not reproduced live; only the runtime test
covers it.
- **확인하지 못한 것**: forced letters were run live into one agent kind only,
and the commands only on macOS; Linux and Windows run them in this PR's
CI lanes.
- **확인하지 못한 것**: commands against a connected device's pane
(`remote:<device>:pane:<id>`) were not run live.

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

- Base: origin/main 83ac3ea; head: see the PR.
- Overlap: #1900 and #1899 touch `contracts/hide-cli.json`,
`docs/agent-hooks.md`, `hide-agent-hooks/src/runtime.rs` and
`hided/src/cli.rs`; merge-order says stay, merge main once after each
lands.

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