Repository navigation
refactor(hooks): hand rules 7-8 over with the first hwip_ask result - #3
Merged
Merged
Conversation
The NORMAL SessionStart text carried "Handling the response" in every session, although those rules only govern a hwip_ask answer. A PostToolUse hook on hwip_ask now injects the same CORE_RULES section once per session context, so terminal sessions that never ask stop paying for it. Claude Code attaches the context to the background-move result too, so the rules still land before a slow answer. The handling-injected mark follows remote-injected: every SessionStart drops it, and a REMOTE start (which ships the rules) sets it. A mark the ask hook wrote ages out after 30 minutes because /rewind can drop the carrying result without a SessionStart, and a subagent call never touches it. Slicing moves to hooks/core-rules.js so both hooks read the same text.
Every NORMAL session on the default quiet dial pays for this block. The rewording keeps each fact (only high counts, skip/push are inert, once on an awaited completion, never routine, ignored on a hwip_ask turn, not to reach a user who left) and cuts the block from 592 to 397 chars. A length check plus clause-level fact checks pin it. Push Signal stays out of the cross-harness extraction, so the extract is unchanged; the one-way copy is left as is.
Ship the slimmer NORMAL injection and the hwip_ask result hook to existing installs; Claude Code only refreshes a plugin when its version changes.
ARCHITECTURE.md named only the SessionStart writes; the ask hook also writes the mark, which ages out after 30 minutes, and subagent calls never touch it. The quiet-block length check now counts code points with node, since wc -m under LC_ALL=C counted the heading's em dash as three and left one char of headroom.
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.
Summary
NORMAL 상태로 시작하는 모든 세션이 내던 SessionStart 주입문을 3,348자에서 2,489자로 줄였다(−859자, 기본 quiet 다이얼 기준). 모델이 할 수 있는 일은 그대로다.
hwip_ask결과와 함께 들어간다. 이 규칙은hwip_ask답을 다룰 때만 쓰인다. 그래서 시작 주입문에서 빼고,^mcp__.*__hwip_ask$에 거는 새 PostToolUse 훅이 세션 컨텍스트마다 한 번 주입한다. 주입하는 문구는docs/CORE_RULES.md의 같은 섹션을 그대로 잘라 쓴다.REMOTE·one-way·muted 분기, Rule 9,
hwip-remote.sh출력, mcp-server 는 건드리지 않았다.Changes
hooks/hwip-ask-result.js(신규): PostToolUse 훅.handling-injected-<sid>로 한 번만 주입한다.agent_id있음)이면 마크를 읽지도 쓰지도 않는다.hooks/core-rules.js(신규):section·pickBranch·상태 경로·훅 입력 읽기를 두 훅이 같이 쓰도록 모았다.hooks/hwip-setup.js:normal()에서 Handling 을 뺐다. 마크 처리를 일반화했다.session-start마크를 남긴다(그 계약에 규칙 7·8 이 이미 들어 있다)..claude-plugin/plugin.json: PostToolUse matcher 항목을 추가했다(timeout 5).docs/CORE_RULES.md: quiet Push Signal 문구를 바꾸고 Last updated 를 갱신했다.tests/test-hwip-ask-result.sh(신규, 28개)와tests/test-hwip-setup.sh(+8개): 위 동작을 고정한다.docs/HOOKS-EXPLAINED.md·docs/ARCHITECTURE.md·README.md·tests/README.md: 새 훅과 크기를 반영했다.How to Test
Evidence
bash tests/test-hwip-setup.sh에서✗ NORMAL leaves rules 7·8 to the hwip_ask result와✗ quiet Push Signal fits in 400 chars(블록 592자)가 실패했다.bash tests/test-hwip-ask-result.sh는 훅이 없어✗ injects rules 7·8로 실패했다.additionalContext는 빠른 반환(claude -p)이면 tool result 와 함께 모델에 들어간다.hwip_ask(interactive tmux)에서는 "moved to background" 결과에 붙어 최종 답보다 먼저 도착한다.agent_id·agent_type이 들어 있고,session_id는 부모와 같다. main 호출에는 둘 다 없다.Acceptance
audit: ok (5 checked rows at 32f59cc)Risks
src/templates.ts의PROMPT_HOOK_CORE는 여전히 Handling 을 담는다. 다른 하네스에는 PostToolUse 가 없어서 시작 주입문에 계속 실어야 한다. 이 PR 은 Claude Code 플러그인 주입만 줄인다.scripts/hwip-mode.sh:77이session_id없이 setup 을 다시 돌리면 모든 세션의handling-injected-*마크가 지워진다. 결과는 세션마다 규칙이 한 번 더 들어가는 것뿐이다(fail open). 이 PR 이 만든 문제가 아니다.Merge danger
Alternatives considered
hwip_ask결과 JSON 에 넣는 안은 버렸다.ask.test.ts가 결과 JSON 을toEqual로 고정하고 있어 서버 릴리스와 플러그인 버전이 어긋난다.hwip-mode.sh는 호출자 stdin 을 물려받아 setup 을 돌리는데, 이 경로에서 블로킹 읽기가 멈춘다. setup 은 원래의 non-blocking 읽기를 유지한다.Auto-decided
remote-injected-<sid>와 같은 방식이다. 모든 SessionStart 가 마크를 지우고, REMOTE 계약을 내보내는 시작이 마크를 세운다.hwip_ask가 실제로 돌아왔다면 그 답에는 규칙 7·8 이 필요하기 때문이다.!apiKey조기 종료 경로의 마크 처리: 설정이 없으면hwip_ask가 돌 수 없다.XDG_STATE_HOME: 셸 훅들과 공유하는 기존 공식이다.폰 실사용 확인 (운영 hwip, 브랜치 플러그인
--plugin-dir)hwip_ask결과에 PostToolUse 가 규칙 7·8 을 한 번 넣었고, 마크ask가 남았다.echo hwip-ok를 실행했다(규칙 7).hwipState: REMOTE여서 모델이 다음 응답을hwip_ask로 끝냈다. 이 두 번째 결과에는 규칙이 다시 주입되지 않았다.hwipState: NORMAL로 돌아왔다.Release
0.1.2로 올렸다(사용자 결정). Claude Code 는 버전이 바뀌어야 설치본을 갱신한다.Checklist
bash tests/run-all.sh17/17node scripts/lint-rules-sync.jsSync contract holds/review --fullApprove(범프 뒤 재리뷰 포함)🤖 Generated with Claude Code