Files
tanweai__pua/hooks/hooks.json
T
xsser d40ca8a164 feat(pua): add silent heartbeat stats
Summary:
- Add a silent SessionStart heartbeat hook that posts minimal anonymous
  install activity to Cloudflare without emitting stdout, stderr, or
  additionalContext.
- Add the Cloudflare Pages heartbeat endpoint, D1 migration, and
  admin-only stats page at #/admin/heartbeats.
- Add heartbeat regression gates, release consistency checks, FAQ/design
  notes, and bump marketplace/package versions to 3.4.3.

Rationale:
- Active-user measurement belongs in a hook-side mechanical gate, not in
  the model prompt, so the worker context cannot narrate or leak the
  telemetry behavior.
- Privacy gates disable the signal for offline mode, telemetry opt-out,
  and feedback-off users before any local telemetry identity is created.

Tests:
- bash evals/test-heartbeat.sh
- bash evals/test-release-consistency.sh
- static eval suite: governance, feedback auth, integrity guard, issue
  regressions, Microsoft flavor, platform compat, loop hook, Windows
  Python hooks, YAML frontmatter
- bash evals/test-behavior.sh
- npm --prefix landing run build
- ./landing/node_modules/.bin/tsc -p pi/pua/tsconfig.json
- git diff --check

Co-authored-by: Codex <codex@openai.com>
2026-05-09 17:01:38 +08:00

112 lines
4.1 KiB
JSON

{
"description": "PUA v3 hooks: additionalContext injection, failure detection, frustration interception, integrity guard, state management",
"hooks": {
"UserPromptSubmit": [
{
"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/heartbeat.sh\"",
"timeout": 2
},
{
"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/heartbeat.sh\"",
"timeout": 2
},
{
"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
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash|Read|Grep|Glob|Edit|Write|MultiEdit|WebSearch|WebFetch",
"hooks": [
{
"type": "command",
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/integrity-guard.sh\"",
"timeout": 5
}
]
}
]
}
}