Files
tanweai__pua/hooks/hooks.json
T
xsser 1be1c478b6 release: v3.2.0 — teardown protocol (agent lifecycle accounting)
PUA v3.1 之前覆盖 agent 生命周期的前 4 阶段(Define → Spawn → Monitor →
Accept),缺后 3 阶段(Release → Cleanup → Orphan handling),导致验收通过的
agent 堆在上下文、worktree 变孤儿、tmux pane 常驻、后台 agent 永久吃 token。
v3.2 补齐会计层:SubagentStop hook + 3 个新 slash 命令 + teardown 协议文档。

Why (Netflix Keeper Test): 职业球队里打完比赛的球员必须下场,继续站场上只会
拖垮全队节奏。agent 也一样。

What:
- NEW hooks/subagent-teardown.sh — SubagentStop 会计,写 teardown.jsonl +
  从 active-agents.json 移除(单行 compact jsonl)
- NEW commands/team-status.md — 列在场阵容(活跃 agent / PID / TTL / age)
- NEW commands/reap-orphans.md — 扫 stale agent(mtime > 30min)批量回收
- NEW commands/teardown-all.md — 级联释放 P10 → P9 → P8 → P7 全员下场
- NEW skills/pua/references/teardown-protocol.md — 生命周期 7 阶段协议 +
  6 条 Release 规则 + Cleanup checklist + Orphan 三层防御

Bugfix:
- hooks/pua-loop-hook.sh: 新增 Gate 0(SubagentStop isolation),state file
  路径改为绝对路径 $HOME/.claude/pua/loop-active.md(SESSION_ID 在 setup
  时不可用,固定名)+ legacy fallback
- scripts/setup-pua-loop.sh: ABS + legacy 双写 state
- hooks/hooks.json: 注册 SubagentStop → subagent-teardown.sh
- commands/on.md: 修复 feedback_frequency=0 tombstone 不恢复的不对称 bug
- commands/cancel-pua-loop.md + team-status.md: 移除不支持的
  Read(~/...) tilde 权限语法

E2E 验证 (10/10 全绿):
T1 hooks.json syntax | T2 teardown jsonl compact | T3 active-agents 选择性清除
T4 setup 双写 MD5 identical | T5 Gate 0 真拦截 SubagentStop
T6 主会话 Stop 注入 decision:block valid JSON | T7 Gate 0 对带 transcript
的 sub 仍拦截 | T8 无 tilde | T9 feedback_frequency 恢复 | T10 SubagentStop 注册
2026-04-18 02:40:57 +08:00

91 lines
3.8 KiB
JSON

{
"description": "PUA v3 hooks: additionalContext injection, failure detection, frustration interception, state management",
"hooks": {
"UserPromptSubmit": [
{
"matcher": "try harder|别偷懒|又错了|还不行|怎么搞|stop giving|you broke|third time|降智|原地打转|能不能靠谱|认真点|不行啊|为什么还不行|你怎么又|换个方法|stop spinning|figure it out|you keep failing|加油|再试试|质量太差|重新做|PUA模式|怎么又失败",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/frustration-trigger.sh",
"timeout": 5
}
]
}
],
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/failure-detector.sh",
"timeout": 5
}
]
}
],
"PreCompact": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
"prompt": "[PUA v2 PreCompact — State Checkpoint]\n\nCheck FIRST: did PUA actually trigger this session? Look for ANY of these markers in your recent output:\n- [PUA生效 🔥] (Chinese skill)\n- [Auto-select: ...] or [PIP-REPORT] (English skill)\n- [PUA-REPORT] (Japanese skill)\nIf NONE of these markers appear, skip everything below and do nothing.\n\nIf PUA WAS active: Context compaction is about to happen. You MUST immediately dump your PUA v2 runtime state to ~/.pua/builder-journal.md using the Write tool BEFORE compaction erases it.\n\nWrite the following to ~/.pua/builder-journal.md (create ~/.pua/ if needed):\n\n```markdown\n# PUA v2 Builder Journal — Compaction Checkpoint\n\n## Timestamp\n{current ISO timestamp}\n\n## Runtime State\n- pressure_level: L{0-4}\n- failure_count: {number}\n- current_flavor: {flavor name}\n- pua_triggered_count: {number of [PUA生效 🔥] this session}\n\n## Active Task\n{what you were working on — 1-2 sentences}\n\n## Tried Approaches\n{list of approaches tried and their outcomes}\n\n## Excluded Possibilities\n{what has been ruled out}\n\n## Next Hypothesis\n{what you planned to try next}\n\n## Key Context\n{any critical information that would be lost in compaction — file paths, error messages, architectural decisions}\n```\n\nThis is NOT optional. Compaction without state dump = losing pressure level and failure history = cheating. The pressure doesn't reset just because context got compressed.\n\nAfter writing, output: > [PUA Checkpoint] State saved to builder-journal.md. Pressure level and failure history preserved."
}
]
}
],
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/session-restore.sh",
"timeout": 5
}
]
},
{
"matcher": "startup|resume",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/session-restore.sh",
"timeout": 5
}
]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/pua-loop-hook.sh"
},
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/stop-feedback.sh",
"timeout": 10
}
]
}
],
"SubagentStop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-teardown.sh",
"timeout": 5
}
]
}
]
}
}