add-coder 0.3.26 → 0.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +282 -155
- package/dist/index.js +481 -209
- package/package.json +15 -4
- package/templates/.add-coder-src-hash.json +186 -185
- package/templates/adapters/claude/hooks/doc-format-guard.ts +32 -0
- package/templates/adapters/claude/hooks/lib/claude-env.ts +7 -0
- package/templates/adapters/claude/hooks/notification.ts +24 -0
- package/templates/adapters/claude/hooks/permission-denied.ts +33 -0
- package/templates/adapters/claude/hooks/permission-gate.ts +12 -0
- package/templates/adapters/claude/hooks/post-tool-failure.ts +4 -0
- package/templates/adapters/claude/hooks/post-tool-use.ts +17 -0
- package/templates/adapters/claude/hooks/pre-compact.ts +10 -0
- package/templates/adapters/claude/hooks/pre-tool-use.ts +81 -0
- package/templates/adapters/claude/hooks/prompt-submit.ts +82 -0
- package/templates/adapters/claude/hooks/review-checklist.ts +4 -0
- package/templates/adapters/claude/hooks/session-end.ts +10 -0
- package/templates/adapters/claude/hooks/session-start.ts +24 -0
- package/templates/adapters/claude/hooks/stop-check.ts +15 -0
- package/templates/adapters/claude/hooks/stop-failure.ts +34 -0
- package/templates/adapters/claude/hooks/subagent-guard.ts +25 -0
- package/templates/adapters/claude/hooks/subagent-stop.ts +12 -0
- package/templates/adapters/claude/settings.json +13 -13
- package/templates/adapters/codex/config.toml.example +12 -0
- package/templates/adapters/codex/hooks/doc-format-guard.ts +30 -0
- package/templates/adapters/codex/hooks/notification.ts +26 -0
- package/templates/adapters/codex/hooks/permission-gate.ts +15 -0
- package/templates/adapters/codex/hooks/post-tool-failure.ts +14 -0
- package/templates/adapters/codex/hooks/post-tool-use.ts +85 -0
- package/templates/adapters/codex/hooks/pre-compact.ts +20 -0
- package/templates/adapters/codex/hooks/pre-tool-use.ts +141 -0
- package/templates/adapters/codex/hooks/prompt-submit.ts +38 -0
- package/templates/adapters/codex/hooks/review-checklist.ts +5 -0
- package/templates/adapters/codex/hooks/session-end.ts +19 -0
- package/templates/adapters/codex/hooks/session-start.ts +45 -0
- package/templates/adapters/codex/hooks/stop-check.ts +59 -0
- package/templates/adapters/codex/hooks/subagent-guard.ts +22 -0
- package/templates/adapters/codex/hooks/subagent-stop.ts +20 -0
- package/templates/adapters/codex/hooks.json +67 -1
- package/templates/adapters/qoder/hooks/doc-format-guard.ts +34 -0
- package/templates/adapters/qoder/hooks/lib/context-inject.ts +61 -0
- package/templates/adapters/qoder/hooks/lib/qoder-env.ts +23 -0
- package/templates/adapters/qoder/hooks/lib/review-checklist.ts +5 -0
- package/templates/adapters/qoder/hooks/notification.ts +34 -0
- package/templates/adapters/qoder/hooks/permission-gate.ts +26 -0
- package/templates/adapters/qoder/hooks/post-tool-failure.ts +30 -0
- package/templates/adapters/qoder/hooks/post-tool-use.ts +32 -0
- package/templates/adapters/qoder/hooks/pre-compact.ts +16 -0
- package/templates/adapters/qoder/hooks/pre-tool-use.ts +112 -0
- package/templates/adapters/qoder/hooks/prompt-submit.ts +66 -0
- package/templates/adapters/qoder/hooks/review-checklist.ts +24 -0
- package/templates/adapters/qoder/hooks/session-end.ts +27 -0
- package/templates/adapters/qoder/hooks/session-start.ts +83 -0
- package/templates/adapters/qoder/hooks/stop-check.ts +69 -0
- package/templates/adapters/qoder/hooks/subagent-guard.ts +16 -0
- package/templates/adapters/qoder/hooks/subagent-stop.ts +33 -0
- package/templates/adapters/qoder/settings.json +13 -13
- package/templates/adapters/trae/hooks/doc-format-guard.ts +30 -0
- package/templates/adapters/trae/hooks/notification.ts +22 -0
- package/templates/adapters/trae/hooks/permission-gate.ts +15 -0
- package/templates/adapters/trae/hooks/post-tool-failure.ts +14 -0
- package/templates/adapters/trae/hooks/post-tool-use.ts +24 -0
- package/templates/adapters/trae/hooks/pre-compact.ts +15 -0
- package/templates/adapters/trae/hooks/pre-tool-use.ts +40 -0
- package/templates/adapters/trae/hooks/prompt-submit.ts +29 -0
- package/templates/adapters/trae/hooks/review-checklist.ts +5 -0
- package/templates/adapters/trae/hooks/session-end.ts +16 -0
- package/templates/adapters/trae/hooks/session-start.ts +15 -0
- package/templates/adapters/trae/hooks/stop-check.ts +20 -0
- package/templates/adapters/trae/hooks/subagent-guard.ts +22 -0
- package/templates/adapters/trae/hooks/subagent-stop.ts +15 -0
- package/templates/adapters/trae/hooks.json +1 -1
- package/templates/adapters/vscode/hooks/doc-format-guard.ts +27 -0
- package/templates/adapters/vscode/hooks/notification.ts +22 -0
- package/templates/adapters/vscode/hooks/permission-gate.ts +15 -0
- package/templates/adapters/vscode/hooks/post-tool-failure.ts +32 -0
- package/templates/adapters/vscode/hooks/post-tool-use.ts +25 -0
- package/templates/adapters/vscode/hooks/pre-compact.ts +15 -0
- package/templates/adapters/vscode/hooks/pre-tool-use.ts +78 -0
- package/templates/adapters/vscode/hooks/prompt-submit.ts +74 -0
- package/templates/adapters/vscode/hooks/review-checklist.ts +5 -0
- package/templates/adapters/vscode/hooks/session-end.ts +16 -0
- package/templates/adapters/vscode/hooks/session-start.ts +24 -0
- package/templates/adapters/vscode/hooks/stop-check.ts +21 -0
- package/templates/adapters/vscode/hooks/subagent-guard.ts +21 -0
- package/templates/adapters/vscode/hooks/subagent-stop.ts +15 -0
- package/templates/core/docs/ADD-governance-claude-code.md +4 -4
- package/templates/core/docs/ADD-governance-codex.md +6 -6
- package/templates/core/docs/ADD-governance-qoder-cn.md +5 -5
- package/templates/core/docs/ADD-governance-trae.md +3 -3
- package/templates/core/docs/ADD-governance-vscode-copilot.md +22 -23
- package/templates/core/governance/audit-bridge.ts +47 -0
- package/templates/core/governance/common.ts +299 -0
- package/templates/core/governance/context-inject.ts +53 -0
- package/templates/core/governance/doc-format-guard.ts +440 -0
- package/templates/core/governance/notification-router.ts +62 -0
- package/templates/core/governance/notify.ts +66 -0
- package/templates/core/governance/permission-gate-router.ts +42 -0
- package/templates/core/governance/post-tool-failure-router.ts +56 -0
- package/templates/core/governance/post-tool-router.ts +212 -0
- package/templates/core/governance/pre-compact-guard.ts +41 -0
- package/templates/core/governance/pre-tool-guard.ts +309 -0
- package/templates/core/governance/preload-templates.ts +241 -0
- package/templates/core/governance/prompt-router.ts +222 -0
- package/templates/core/governance/review-checklist-guard.ts +186 -0
- package/templates/core/governance/rules.ts +720 -0
- package/templates/core/governance/session-end.ts +88 -0
- package/templates/core/governance/session-start-guard.ts +99 -0
- package/templates/core/governance/state-detect.ts +6 -0
- package/templates/core/governance/stop-router.ts +140 -0
- package/templates/core/governance/subagent-guard-router.ts +35 -0
- package/templates/core/governance/subagent-stop-router.ts +93 -0
- package/templates/core/governance/subagent-stop.ts +75 -0
- package/templates/core/governance/vocabulary.ts +109 -0
- package/templates/core/hooks/doc-format-guard.ts +21 -0
- package/templates/core/hooks/notification.ts +11 -0
- package/templates/core/hooks/permission-gate.ts +7 -0
- package/templates/core/hooks/post-tool-failure.ts +7 -0
- package/templates/core/hooks/post-tool-use.ts +23 -0
- package/templates/core/hooks/pre-compact.ts +9 -0
- package/templates/core/hooks/pre-tool-use.ts +30 -0
- package/templates/core/hooks/prompt-submit.ts +11 -0
- package/templates/core/hooks/review-checklist.ts +4 -0
- package/templates/core/hooks/session-end.ts +10 -0
- package/templates/core/hooks/session-start.ts +9 -0
- package/templates/core/hooks/stop-check.ts +14 -0
- package/templates/core/hooks/subagent-guard.ts +8 -0
- package/templates/core/hooks/subagent-stop.ts +9 -0
- package/templates/core/prisma/add.prisma +140 -82
- package/templates/core/rules/project_rules.md +27 -24
- package/templates/core/scripts/db-ensure.sh +8 -0
- package/templates/core/scripts/gen-plan-index.sh +4 -15
- package/templates/core/scripts/mcp-server/notifications/hitl.ts +9 -1
- package/templates/core/scripts/mcp-server/notifications/hook.ts +25 -9
- package/templates/core/scripts/mcp-server/resources/hitl-approval-widget.ts +34 -0
- package/templates/core/scripts/mcp-server/resources/hook-events-report.ts +14 -2
- package/templates/core/scripts/mcp-server/resources/index.ts +2 -0
- package/templates/core/scripts/mcp-server/sampling/review.ts +25 -10
- package/templates/core/scripts/mcp-server/shared/db-types.ts +33 -8
- package/templates/core/scripts/mcp-server/shared/dps-scoring.strategy.ts +1 -1
- package/templates/core/scripts/mcp-server/shared/env.ts +28 -8
- package/templates/core/scripts/mcp-server/shared/fs.ts +3 -0
- package/templates/core/scripts/mcp-server/shared/hitl-interaction.strategy.ts +2 -3
- package/templates/core/scripts/mcp-server/shared/hitl-lifecycle-mutation.ts +129 -0
- package/templates/core/scripts/mcp-server/shared/hitl-proposal-mutation.ts +98 -0
- package/templates/core/scripts/mcp-server/shared/hitl-ui.ts +3 -0
- package/templates/core/scripts/mcp-server/shared/plan-lifecycle-events.ts +62 -0
- package/templates/core/scripts/mcp-server/shared/plan-lifecycle-mutation.ts +78 -0
- package/templates/core/scripts/mcp-server/shared/plan-lifecycle-subscriber.ts +145 -0
- package/templates/core/scripts/mcp-server/shared/plan-lifecycle.ts +153 -0
- package/templates/core/scripts/mcp-server/shared/plan-round-events.ts +56 -0
- package/templates/core/scripts/mcp-server/shared/plan-round-mutation.ts +143 -0
- package/templates/core/scripts/mcp-server/shared/plan-round-store.ts +47 -0
- package/templates/core/scripts/mcp-server/shared/plan-round-subscriber.ts +99 -0
- package/templates/core/scripts/mcp-server/shared/plan-status-store.ts +37 -0
- package/templates/core/scripts/mcp-server/shared/plan-tracking-mutation.ts +71 -0
- package/templates/core/scripts/mcp-server/shared/prisma.ts +12 -6
- package/templates/core/scripts/mcp-server/shared/project-root-strategy.ts +1 -2
- package/templates/core/scripts/mcp-server/shared/quant-recheck.strategy.ts +16 -0
- package/templates/core/scripts/mcp-server/shared/redact.ts +28 -0
- package/templates/core/scripts/mcp-server/shared/response.ts +3 -2
- package/templates/core/scripts/mcp-server/shared/runtime-context.ts +77 -0
- package/templates/core/scripts/mcp-server/shared/schema-topology.ts +159 -0
- package/templates/core/scripts/mcp-server/tools/audit.ts +49 -7
- package/templates/core/scripts/mcp-server/tools/context.ts +117 -121
- package/templates/core/scripts/mcp-server/tools/contract.ts +34 -9
- package/templates/core/scripts/mcp-server/tools/gateway/check_add_route_status.ts +50 -3
- package/templates/core/scripts/mcp-server/tools/gateway/check_doc_similarity.ts +218 -0
- package/templates/core/scripts/mcp-server/tools/gateway/check_dps.ts +22 -7
- package/templates/core/scripts/mcp-server/tools/gateway/check_rahs.ts +86 -4
- package/templates/core/scripts/mcp-server/tools/gateway/check_spec_sync.ts +19 -6
- package/templates/core/scripts/mcp-server/tools/gateway/index.ts +2 -0
- package/templates/core/scripts/mcp-server/tools/hitl.ts +160 -75
- package/templates/core/scripts/mcp-server/tools/hook-event-report.ts +9 -2
- package/templates/core/scripts/mcp-server/tools/index.ts +69 -3
- package/templates/core/scripts/mcp-server/tools/plan.ts +152 -17
- package/templates/core/scripts/mcp-server/tools/review.ts +44 -15
- package/templates/core/scripts/mcp-server.ts +60 -1
- package/templates/core/scripts/plan-status-bridge.ts +26 -0
- package/templates/core/skills/add-paradigm/SKILL.md +2 -2
- package/templates/core/templates/add-route-template.schema.json +24 -56
- package/templates/core/templates/collab-contract-template.md +1 -1
- package/templates/core/templates/handoff-multi-round-template.schema.json +48 -0
- package/templates/core/templates/handoff-single-round-template.schema.json +92 -0
- package/templates/core/templates/handoff-single-round.schema.json +1 -1
- package/templates/core/templates/hitl-approval-widget.html +222 -37
- package/templates/core/templates/spec-template.schema.json +9 -46
- package/templates/core/templates/standard-plan-template.schema.json +1 -1
- package/templates/core/templates/tasks-template.schema.json +13 -54
- package/templates/adapters/claude/hooks/doc-format-guard.sh +0 -202
- package/templates/adapters/claude/hooks/lib/common.sh +0 -261
- package/templates/adapters/claude/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/claude/hooks/lib/notify.sh +0 -34
- package/templates/adapters/claude/hooks/lib/preload-templates.sh +0 -187
- package/templates/adapters/claude/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/claude/hooks/lib/state-detect.sh +0 -117
- package/templates/adapters/claude/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/claude/hooks/lib/vocabulary.sh +0 -56
- package/templates/adapters/claude/hooks/notification.sh +0 -45
- package/templates/adapters/claude/hooks/permission-denied.sh +0 -42
- package/templates/adapters/claude/hooks/permission-gate.sh +0 -18
- package/templates/adapters/claude/hooks/post-tool-failure.sh +0 -10
- package/templates/adapters/claude/hooks/post-tool-use.sh +0 -35
- package/templates/adapters/claude/hooks/pre-compact.sh +0 -37
- package/templates/adapters/claude/hooks/pre-tool-use.sh +0 -153
- package/templates/adapters/claude/hooks/prompt-submit.sh +0 -99
- package/templates/adapters/claude/hooks/review-checklist.sh +0 -10
- package/templates/adapters/claude/hooks/session-end.sh +0 -21
- package/templates/adapters/claude/hooks/session-start.sh +0 -36
- package/templates/adapters/claude/hooks/stop-check.sh +0 -45
- package/templates/adapters/claude/hooks/stop-failure.sh +0 -44
- package/templates/adapters/claude/hooks/subagent-guard.sh +0 -36
- package/templates/adapters/claude/hooks/subagent-stop.sh +0 -20
- package/templates/adapters/codex/hooks/doc-format-guard.sh +0 -261
- package/templates/adapters/codex/hooks/lib/common.sh +0 -261
- package/templates/adapters/codex/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/codex/hooks/lib/notify.sh +0 -34
- package/templates/adapters/codex/hooks/lib/preload-templates.sh +0 -187
- package/templates/adapters/codex/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/codex/hooks/lib/state-detect.sh +0 -117
- package/templates/adapters/codex/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/codex/hooks/lib/vocabulary.sh +0 -56
- package/templates/adapters/codex/hooks/notification.sh +0 -45
- package/templates/adapters/codex/hooks/permission-gate.sh +0 -18
- package/templates/adapters/codex/hooks/post-tool-failure.sh +0 -10
- package/templates/adapters/codex/hooks/post-tool-use.sh +0 -138
- package/templates/adapters/codex/hooks/pre-compact.sh +0 -37
- package/templates/adapters/codex/hooks/pre-tool-use.sh +0 -217
- package/templates/adapters/codex/hooks/prompt-submit.sh +0 -87
- package/templates/adapters/codex/hooks/review-checklist.sh +0 -10
- package/templates/adapters/codex/hooks/session-end.sh +0 -38
- package/templates/adapters/codex/hooks/session-start.sh +0 -53
- package/templates/adapters/codex/hooks/stop-check.sh +0 -45
- package/templates/adapters/codex/hooks/subagent-guard.sh +0 -15
- package/templates/adapters/codex/hooks/subagent-stop.sh +0 -47
- package/templates/adapters/qoder/hooks/doc-format-guard.sh +0 -260
- package/templates/adapters/qoder/hooks/lib/common.sh +0 -261
- package/templates/adapters/qoder/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/qoder/hooks/lib/notify.sh +0 -34
- package/templates/adapters/qoder/hooks/lib/preload-templates.sh +0 -187
- package/templates/adapters/qoder/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/qoder/hooks/lib/state-detect.sh +0 -117
- package/templates/adapters/qoder/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/qoder/hooks/lib/vocabulary.sh +0 -56
- package/templates/adapters/qoder/hooks/notification.sh +0 -25
- package/templates/adapters/qoder/hooks/permission-gate.sh +0 -8
- package/templates/adapters/qoder/hooks/post-tool-failure.sh +0 -8
- package/templates/adapters/qoder/hooks/post-tool-use.sh +0 -121
- package/templates/adapters/qoder/hooks/pre-compact.sh +0 -37
- package/templates/adapters/qoder/hooks/pre-tool-use.sh +0 -154
- package/templates/adapters/qoder/hooks/prompt-submit.sh +0 -96
- package/templates/adapters/qoder/hooks/review-checklist.sh +0 -157
- package/templates/adapters/qoder/hooks/session-end.sh +0 -24
- package/templates/adapters/qoder/hooks/session-start.sh +0 -45
- package/templates/adapters/qoder/hooks/stop-check.sh +0 -48
- package/templates/adapters/qoder/hooks/subagent-guard.sh +0 -27
- package/templates/adapters/qoder/hooks/subagent-stop.sh +0 -26
- package/templates/adapters/trae/hooks/doc-format-guard.sh +0 -261
- package/templates/adapters/trae/hooks/lib/common.sh +0 -261
- package/templates/adapters/trae/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/trae/hooks/lib/notify.sh +0 -34
- package/templates/adapters/trae/hooks/lib/preload-templates.sh +0 -187
- package/templates/adapters/trae/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/trae/hooks/lib/state-detect.sh +0 -117
- package/templates/adapters/trae/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/trae/hooks/lib/vocabulary.sh +0 -56
- package/templates/adapters/trae/hooks/notification.sh +0 -45
- package/templates/adapters/trae/hooks/permission-gate.sh +0 -18
- package/templates/adapters/trae/hooks/post-tool-failure.sh +0 -10
- package/templates/adapters/trae/hooks/post-tool-use.sh +0 -138
- package/templates/adapters/trae/hooks/pre-compact.sh +0 -37
- package/templates/adapters/trae/hooks/pre-tool-use.sh +0 -217
- package/templates/adapters/trae/hooks/prompt-submit.sh +0 -87
- package/templates/adapters/trae/hooks/review-checklist.sh +0 -10
- package/templates/adapters/trae/hooks/session-end.sh +0 -38
- package/templates/adapters/trae/hooks/session-start.sh +0 -53
- package/templates/adapters/trae/hooks/stop-check.sh +0 -45
- package/templates/adapters/trae/hooks/subagent-guard.sh +0 -15
- package/templates/adapters/trae/hooks/subagent-stop.sh +0 -47
- package/templates/adapters/vscode/hooks/doc-format-guard.sh +0 -201
- package/templates/adapters/vscode/hooks/lib/common.sh +0 -261
- package/templates/adapters/vscode/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/vscode/hooks/lib/notify.sh +0 -34
- package/templates/adapters/vscode/hooks/lib/preload-templates.sh +0 -187
- package/templates/adapters/vscode/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/vscode/hooks/lib/state-detect.sh +0 -117
- package/templates/adapters/vscode/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/vscode/hooks/lib/vocabulary.sh +0 -56
- package/templates/adapters/vscode/hooks/notification.sh +0 -45
- package/templates/adapters/vscode/hooks/permission-gate.sh +0 -18
- package/templates/adapters/vscode/hooks/post-tool-failure.sh +0 -28
- package/templates/adapters/vscode/hooks/post-tool-use.sh +0 -35
- package/templates/adapters/vscode/hooks/pre-compact.sh +0 -37
- package/templates/adapters/vscode/hooks/pre-tool-use.sh +0 -153
- package/templates/adapters/vscode/hooks/prompt-submit.sh +0 -99
- package/templates/adapters/vscode/hooks/review-checklist.sh +0 -10
- package/templates/adapters/vscode/hooks/session-end.sh +0 -13
- package/templates/adapters/vscode/hooks/session-start.sh +0 -35
- package/templates/adapters/vscode/hooks/stop-check.sh +0 -53
- package/templates/adapters/vscode/hooks/subagent-guard.sh +0 -37
- package/templates/adapters/vscode/hooks/subagent-stop.sh +0 -12
- package/templates/core/hooks/doc-format-guard.sh +0 -261
- package/templates/core/hooks/lib/common.sh +0 -261
- package/templates/core/hooks/lib/context-inject.sh +0 -96
- package/templates/core/hooks/lib/notify.sh +0 -34
- package/templates/core/hooks/lib/preload-templates.sh +0 -187
- package/templates/core/hooks/lib/session-end.sh +0 -76
- package/templates/core/hooks/lib/state-detect.sh +0 -117
- package/templates/core/hooks/lib/subagent-stop.sh +0 -90
- package/templates/core/hooks/lib/vocabulary.sh +0 -56
- package/templates/core/hooks/notification.sh +0 -45
- package/templates/core/hooks/permission-gate.sh +0 -18
- package/templates/core/hooks/post-tool-failure.sh +0 -10
- package/templates/core/hooks/post-tool-use.sh +0 -138
- package/templates/core/hooks/pre-compact.sh +0 -37
- package/templates/core/hooks/pre-tool-use.sh +0 -217
- package/templates/core/hooks/prompt-submit.sh +0 -87
- package/templates/core/hooks/review-checklist.sh +0 -10
- package/templates/core/hooks/session-end.sh +0 -38
- package/templates/core/hooks/session-start.sh +0 -53
- package/templates/core/hooks/stop-check.sh +0 -45
- package/templates/core/hooks/subagent-guard.sh +0 -15
- package/templates/core/hooks/subagent-stop.sh +0 -47
- package/templates/shared/hooks-lib/common.sh +0 -22
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 13:19:01
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 13:21:29
|
|
7
|
-
# @FilePath : /add-coder/templates/core/hooks/lib/preload-templates.sh
|
|
8
|
-
# @Description : ADD 模板预读脚本
|
|
9
|
-
###
|
|
10
|
-
# preload-templates.sh — ADD 模板预读脚本
|
|
11
|
-
# 路径: templates/core/hooks/lib/preload-templates.sh
|
|
12
|
-
#
|
|
13
|
-
# 用法:
|
|
14
|
-
# preload-templates.sh --index # 输出模板清单(文件名 + 用途)
|
|
15
|
-
# preload-templates.sh --full # 输出全部模板全文
|
|
16
|
-
# preload-templates.sh --full --top 5 # 输出前 5 个最常用模板全文
|
|
17
|
-
# preload-templates.sh --full --mark # 全文输出 + 落 tpl-injected 标记
|
|
18
|
-
#
|
|
19
|
-
# 被 SessionStart(--index)和 UserPromptSubmit(--full)调用。
|
|
20
|
-
# tpl-injected 标记文件用于去重——同会话二次命中时不重复注入。
|
|
21
|
-
|
|
22
|
-
set -euo pipefail
|
|
23
|
-
|
|
24
|
-
# 模板目录(相对于本脚本)
|
|
25
|
-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
26
|
-
TEMPLATES_DIR="${SCRIPT_DIR}/../../../core/templates"
|
|
27
|
-
|
|
28
|
-
# tpl-injected 标记文件路径(项目级,/tmp 下按项目 hash 区分)
|
|
29
|
-
PROJECT_HASH=$(echo "${PROJECT_DIR:-$PWD}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")
|
|
30
|
-
TPL_FLAG="/tmp/add_tpl_${PROJECT_HASH}"
|
|
31
|
-
|
|
32
|
-
# 模板清单(文件名:用途描述,按常用度排序)
|
|
33
|
-
# 顺序即 --top N 的优先级
|
|
34
|
-
declare -A TEMPLATES=(
|
|
35
|
-
["simple-plan-template.md"]="需求方案(简单版):六节结构,元信息+背景+方案+架构+实施+验收"
|
|
36
|
-
["spec-template.md"]="功能规格:Why/What Changes/Impact/WHEN-THEN Requirements"
|
|
37
|
-
["tasks-template.md"]="任务拆分:Phase→Task→SubTask层级"
|
|
38
|
-
["checklist-template.md"]="验收清单:[T]编译期+[R]运行时+ADD规则合规"
|
|
39
|
-
["review-template.md"]="方案审查(ADD-9):问题复现+方案对比+决策结论+影响评估"
|
|
40
|
-
["standard-plan-template.md"]="需求方案(标准版):PLAN元信息+背景+方案+架构+实施Task+验收+关联文档"
|
|
41
|
-
["add-route-template-heavyweight.md"]="ADD执行路线图(重型):每Step验证并更新状态+spec_sync交叉校验"
|
|
42
|
-
["add-route-template.md"]="ADD执行路线图(轻量):标准Step产出检查"
|
|
43
|
-
["handoff-single-round-template.md"]="单轮交接:9章节(含恢复上下文审计查询)"
|
|
44
|
-
["handoff-multi-round-template.md"]="多轮交接:全局拓扑+每轮13子章节+收敛规则+启动模板"
|
|
45
|
-
["review-implementation-template.md"]="实现审查(ADD-10):格式契约+框架版本+数据模型+E2E curl"
|
|
46
|
-
["review-runtime-template.md"]="运行时纠偏(ADD-11):发现列表+根因分析+流程改进项"
|
|
47
|
-
["prd-standard-template.md"]="产品需求文档(新建):背景目标+用户场景+功能需求+验收标准"
|
|
48
|
-
["prd-incremental-template.md"]="产品需求文档(增量):变更摘要+diff式记录"
|
|
49
|
-
["fix-verification-template.md"]="修复验证模板"
|
|
50
|
-
["report-template.md"]="代码审查报告模板"
|
|
51
|
-
["runtime-report-template.md"]="运行时报告模板"
|
|
52
|
-
["TERMINOLOGY.md"]="模板术语速查"
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
# 按优先级排序的模板文件名列表
|
|
56
|
-
PRIORITY_ORDER=(
|
|
57
|
-
"simple-plan-template.md"
|
|
58
|
-
"spec-template.md"
|
|
59
|
-
"tasks-template.md"
|
|
60
|
-
"checklist-template.md"
|
|
61
|
-
"review-template.md"
|
|
62
|
-
"standard-plan-template.md"
|
|
63
|
-
"add-route-template-heavyweight.md"
|
|
64
|
-
"add-route-template.md"
|
|
65
|
-
"handoff-single-round-template.md"
|
|
66
|
-
"handoff-multi-round-template.md"
|
|
67
|
-
"review-implementation-template.md"
|
|
68
|
-
"review-runtime-template.md"
|
|
69
|
-
"prd-standard-template.md"
|
|
70
|
-
"prd-incremental-template.md"
|
|
71
|
-
"fix-verification-template.md"
|
|
72
|
-
"report-template.md"
|
|
73
|
-
"runtime-report-template.md"
|
|
74
|
-
"TERMINOLOGY.md"
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
# 读取模板文件内容(strip frontmatter)
|
|
78
|
-
read_template_content() {
|
|
79
|
-
local file="$1"
|
|
80
|
-
if [ -f "$file" ]; then
|
|
81
|
-
# 跳过 YAML frontmatter(--- 开头和 --- 结束之间的内容)
|
|
82
|
-
awk '
|
|
83
|
-
BEGIN { in_fm=0; started=0 }
|
|
84
|
-
NR==1 && /^---$/ { in_fm=1; next }
|
|
85
|
-
in_fm && /^---$/ { in_fm=0; next }
|
|
86
|
-
!in_fm { print }
|
|
87
|
-
' "$file"
|
|
88
|
-
fi
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
# ── --index 模式:输出模板清单 ──
|
|
92
|
-
|
|
93
|
-
output_index() {
|
|
94
|
-
echo "## ADD 可用模板清单"
|
|
95
|
-
echo ""
|
|
96
|
-
echo "| # | 模板文件 | 用途 |"
|
|
97
|
-
echo "|---|---------|------|"
|
|
98
|
-
local i=1
|
|
99
|
-
for tmpl in "${PRIORITY_ORDER[@]}"; do
|
|
100
|
-
if [ -f "$TEMPLATES_DIR/$tmpl" ]; then
|
|
101
|
-
echo "| $i | $tmpl | ${TEMPLATES[$tmpl]:-模板文件} |"
|
|
102
|
-
((i++))
|
|
103
|
-
fi
|
|
104
|
-
done
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
# ── --full 模式:输出模板全文 ──
|
|
108
|
-
|
|
109
|
-
output_full() {
|
|
110
|
-
local top="${1:-0}" # 0 = 全部
|
|
111
|
-
|
|
112
|
-
echo "## ADD 模板全文内容"
|
|
113
|
-
echo ""
|
|
114
|
-
|
|
115
|
-
local count=0
|
|
116
|
-
for tmpl in "${PRIORITY_ORDER[@]}"; do
|
|
117
|
-
if [ ! -f "$TEMPLATES_DIR/$tmpl" ]; then
|
|
118
|
-
continue
|
|
119
|
-
fi
|
|
120
|
-
|
|
121
|
-
count=$((count + 1))
|
|
122
|
-
if [ "$top" -gt 0 ] && [ "$count" -gt "$top" ]; then
|
|
123
|
-
break
|
|
124
|
-
fi
|
|
125
|
-
|
|
126
|
-
echo "---"
|
|
127
|
-
echo "### $tmpl"
|
|
128
|
-
echo ""
|
|
129
|
-
read_template_content "$TEMPLATES_DIR/$tmpl"
|
|
130
|
-
echo ""
|
|
131
|
-
done
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
# ── 标记文件管理 ──
|
|
135
|
-
|
|
136
|
-
mark_injected() {
|
|
137
|
-
touch "$TPL_FLAG" 2>/dev/null || true
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
is_injected() {
|
|
141
|
-
[ -f "$TPL_FLAG" ]
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
clear_injected() {
|
|
145
|
-
rm -f "$TPL_FLAG" 2>/dev/null || true
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
# ── 主入口 ──
|
|
149
|
-
|
|
150
|
-
main() {
|
|
151
|
-
local mode="index"
|
|
152
|
-
local top=0
|
|
153
|
-
local do_mark=false
|
|
154
|
-
|
|
155
|
-
while [ $# -gt 0 ]; do
|
|
156
|
-
case "$1" in
|
|
157
|
-
--index) mode="index"; shift ;;
|
|
158
|
-
--full) mode="full"; shift ;;
|
|
159
|
-
--top)
|
|
160
|
-
top="${2:-0}"
|
|
161
|
-
shift 2
|
|
162
|
-
;;
|
|
163
|
-
--mark) do_mark=true; shift ;;
|
|
164
|
-
*) shift ;;
|
|
165
|
-
esac
|
|
166
|
-
done
|
|
167
|
-
|
|
168
|
-
case "$mode" in
|
|
169
|
-
index)
|
|
170
|
-
output_index
|
|
171
|
-
;;
|
|
172
|
-
full)
|
|
173
|
-
# 去重检查:如果已注入且没有主动要求重新注入,跳过
|
|
174
|
-
if is_injected && ! $do_mark; then
|
|
175
|
-
echo "[ADD preload] 模板已在本会话注入,跳过重复注入(tpl-injected 标记存在)" >&2
|
|
176
|
-
exit 0
|
|
177
|
-
fi
|
|
178
|
-
|
|
179
|
-
output_full "$top"
|
|
180
|
-
|
|
181
|
-
# 落标记文件
|
|
182
|
-
mark_injected
|
|
183
|
-
;;
|
|
184
|
-
esac
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
main "$@"
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 13:20:43
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 13:34:19
|
|
7
|
-
# @FilePath : /add-coder/templates/core/hooks/lib/session-end.sh
|
|
8
|
-
# @Description : SessionEnd 治理卡位
|
|
9
|
-
###
|
|
10
|
-
# session-end.sh — SessionEnd 治理卡位
|
|
11
|
-
# 路径: templates/core/hooks/lib/session-end.sh
|
|
12
|
-
#
|
|
13
|
-
# 治理职能(卡位 #2):
|
|
14
|
-
# ① 清理 tpl-injected 标记文件
|
|
15
|
-
# ② 会话审计结算(汇总 tool 调用统计)
|
|
16
|
-
# ③ Stop 未触发兜底: 若 Stop 未执行验收检查,补执行 checklist 快照(best-effort)
|
|
17
|
-
#
|
|
18
|
-
# 用法: 被各 IDE adapter 的 SessionEnd hook 脚本 source 并调用 main
|
|
19
|
-
|
|
20
|
-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
21
|
-
source "$SCRIPT_DIR/common.sh" 2>/dev/null || true
|
|
22
|
-
|
|
23
|
-
# 清理 tpl-injected 标记
|
|
24
|
-
cleanup_tpl_flag() {
|
|
25
|
-
local project_hash=$(echo "${PROJECT_DIR:-$PWD}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")
|
|
26
|
-
rm -f "/tmp/add_tpl_${project_hash}" 2>/dev/null || true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
# 清理 dev action 标记
|
|
30
|
-
cleanup_dev_flag() {
|
|
31
|
-
local project_hash=$(echo "${PROJECT_DIR:-$PWD}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")
|
|
32
|
-
rm -f "/tmp/add_dev_${project_hash}" 2>/dev/null || true
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# Stop 未触发兜底: 如果 dev action 标记还在(说明 Stop 没执行验收检查)
|
|
36
|
-
stop_fallback() {
|
|
37
|
-
if has_dev_action 2>/dev/null; then
|
|
38
|
-
echo "[ADD SessionEnd] ⚠️ 检测到 dev action 标记未清除——Stop 可能未触发验收检查" >&2
|
|
39
|
-
|
|
40
|
-
# 尝试找到 handoff 做 checklist 快照
|
|
41
|
-
local state=""
|
|
42
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
43
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
44
|
-
fi
|
|
45
|
-
|
|
46
|
-
if [ -n "$state" ]; then
|
|
47
|
-
local handoff=$(echo "$state" | awk -F'::' '{print $4}')
|
|
48
|
-
local add_route=$(echo "$state" | awk -F'::' '{print $5}')
|
|
49
|
-
if [ -f "$handoff" ]; then
|
|
50
|
-
echo "[ADD SessionEnd] 补执行 checklist 快照(best-effort,不阻断)" >&2
|
|
51
|
-
if type check_add_completeness >/dev/null 2>&1; then
|
|
52
|
-
check_add_completeness "$handoff" "$add_route" >&2 2>/dev/null || true
|
|
53
|
-
fi
|
|
54
|
-
fi
|
|
55
|
-
fi
|
|
56
|
-
fi
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
main() {
|
|
60
|
-
# ① 清理标记文件
|
|
61
|
-
cleanup_tpl_flag
|
|
62
|
-
cleanup_dev_flag
|
|
63
|
-
|
|
64
|
-
# ② 审计结算(输出到 stderr 供日志记录)
|
|
65
|
-
echo "[ADD SessionEnd] 会话结束 — $(date -Iseconds)" >&2
|
|
66
|
-
|
|
67
|
-
# ③ Stop 未触发兜底
|
|
68
|
-
stop_fallback
|
|
69
|
-
|
|
70
|
-
exit 0
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
# 被 source 时不自动执行,source 后调用 main
|
|
74
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
75
|
-
main "$@"
|
|
76
|
-
fi
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# state-detect.sh — ADD 活跃流程检测 + dev action 追踪
|
|
3
|
-
# 共享库
|
|
4
|
-
|
|
5
|
-
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}}"
|
|
6
|
-
|
|
7
|
-
# 动态探测 MAGIC_DIR(兼容多 adapter,source 自 hook 脚本时继承调用者的 HOOK_DIR)
|
|
8
|
-
if [ -z "${MAGIC_DIR:-}" ]; then
|
|
9
|
-
if [ -n "${HOOK_DIR:-}" ]; then
|
|
10
|
-
MAGIC_DIR="$(basename "$(dirname "$HOOK_DIR")")"
|
|
11
|
-
else
|
|
12
|
-
for m in ".claude" ".qoder" ".vscode" ".add"; do
|
|
13
|
-
[ -d "$PROJECT_DIR/$m" ] && { MAGIC_DIR="$m"; break; }
|
|
14
|
-
done
|
|
15
|
-
MAGIC_DIR="${MAGIC_DIR:-.add}"
|
|
16
|
-
fi
|
|
17
|
-
fi
|
|
18
|
-
|
|
19
|
-
MAGIC_PATH="$PROJECT_DIR/$MAGIC_DIR"
|
|
20
|
-
PLANS_DIR="$MAGIC_PATH/plans"
|
|
21
|
-
|
|
22
|
-
# dev action 标记文件(项目级,PreToolUse 写入,Stop 读取)
|
|
23
|
-
DEV_FLAG="/tmp/add_dev_$(echo "$PROJECT_DIR" | md5sum 2>/dev/null | cut -c1-8 || echo "default")"
|
|
24
|
-
|
|
25
|
-
# 检测活跃 ADD 流程
|
|
26
|
-
# 返回: "plan_keyword::step_x/total::round_n/total_r::handoff_path::add_route_path" 或 ""
|
|
27
|
-
detect_active_add() {
|
|
28
|
-
local handoff=""
|
|
29
|
-
local today_dir="$PLANS_DIR/$(date +%Y-%m)"
|
|
30
|
-
[ -d "$today_dir" ] && handoff=$(find "$today_dir" -name "*handoff*.md" -mtime -7 -type f 2>/dev/null | head -1)
|
|
31
|
-
[ -z "$handoff" ] && handoff=$(find "$PLANS_DIR" -name "*handoff*.md" -mtime -7 -type f 2>/dev/null | head -1)
|
|
32
|
-
[ -z "$handoff" ] && return 1
|
|
33
|
-
|
|
34
|
-
local plan_kw=$(basename "$handoff" | sed 's/-handoff.*//')
|
|
35
|
-
|
|
36
|
-
# add-route
|
|
37
|
-
local add_route=$(find "$PLANS_DIR" -name "*add-route*.md" -type f 2>/dev/null | head -1)
|
|
38
|
-
|
|
39
|
-
# Step 统计(从 add-route)
|
|
40
|
-
local step_info="?"
|
|
41
|
-
if [ -f "$add_route" ]; then
|
|
42
|
-
local ck=$(grep -c '\[x\]' "$add_route" 2>/dev/null || true)
|
|
43
|
-
local uc=$(grep -c '\[ \]' "$add_route" 2>/dev/null || true)
|
|
44
|
-
ck=${ck:-0}; uc=${uc:-0}
|
|
45
|
-
local total=$((ck + uc))
|
|
46
|
-
[ "$total" -gt 0 ] && step_info="${ck}/${total}"
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
# 轮次统计(从 handoff)
|
|
50
|
-
local round_info="?"
|
|
51
|
-
if grep -q '<第[0-9]轮>' "$handoff" 2>/dev/null; then
|
|
52
|
-
local ck=$(grep -c '\[x\]' "$handoff" 2>/dev/null || true); ck=${ck:-0}
|
|
53
|
-
local total=$(grep -c '<第[0-9]轮>' "$handoff" 2>/dev/null || true); total=${total:-0}
|
|
54
|
-
[ "$total" -gt 0 ] && round_info="${ck}/${total}"
|
|
55
|
-
else
|
|
56
|
-
round_info="1/1"
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
echo "${plan_kw}::${step_info}::${round_info}::${handoff}::${add_route:-none}"
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
# 标记 dev action
|
|
63
|
-
mark_dev_action() {
|
|
64
|
-
touch "$DEV_FLAG" 2>/dev/null || true
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
# 检测 dev action
|
|
68
|
-
has_dev_action() {
|
|
69
|
-
[ -f "$DEV_FLAG" ]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
# 清理 dev action 标记(验收闭环后调用)
|
|
73
|
-
clear_dev_action() {
|
|
74
|
-
rm -f "$DEV_FLAG" 2>/dev/null || true
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
# 检查验收完整度,返回 issues 文本
|
|
78
|
-
check_add_completeness() {
|
|
79
|
-
local handoff="$1" add_route="$2"
|
|
80
|
-
local issues=""
|
|
81
|
-
|
|
82
|
-
# devlog(内容已回流至 handoff,检查 handoff 是否含验收结果)
|
|
83
|
-
if [ -f "$handoff" ] && ! grep -qE '验收|收敛|闭环|本轮改了什么|devlog' "$handoff" 2>/dev/null; then
|
|
84
|
-
issues="${issues} [ ] devlog 缺失(handoff 无验收记录)\n"
|
|
85
|
-
fi
|
|
86
|
-
|
|
87
|
-
# handoff 验证标准
|
|
88
|
-
if [ -f "$handoff" ]; then
|
|
89
|
-
local uc=$(grep -c '\[ \]' "$handoff" 2>/dev/null || echo "0")
|
|
90
|
-
[ "$uc" -gt 0 ] && issues="${issues} [ ] handoff ${uc} 项未勾选\n"
|
|
91
|
-
fi
|
|
92
|
-
|
|
93
|
-
# add-route Step
|
|
94
|
-
if [ -f "$add_route" ]; then
|
|
95
|
-
local uc=$(grep -c '\[ \]' "$add_route" 2>/dev/null || echo "0")
|
|
96
|
-
[ "$uc" -gt 0 ] && issues="${issues} [ ] add-route ${uc} Step 未闭环\n"
|
|
97
|
-
fi
|
|
98
|
-
|
|
99
|
-
echo -e "$issues"
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
# 检查是否已验收(幂等保护)
|
|
103
|
-
# 返回 0 = 未验收,1 = 已验收
|
|
104
|
-
is_already_accepted() {
|
|
105
|
-
local add_route="$1" handoff="$2"
|
|
106
|
-
# add-route Step 8 是否已 [x]
|
|
107
|
-
if [ -f "$add_route" ]; then
|
|
108
|
-
# 检查 Step 8 产出项是否勾选
|
|
109
|
-
if grep -A 10 'Step 8' "$add_route" 2>/dev/null | grep -q '\[x\].*验证并更新项目状态'; then
|
|
110
|
-
# handoff 是否有验收记录
|
|
111
|
-
if [ -f "$handoff" ] && grep -qE '✅.*验收|收敛|全部闭环|全部.*完成' "$handoff" 2>/dev/null; then
|
|
112
|
-
return 0
|
|
113
|
-
fi
|
|
114
|
-
fi
|
|
115
|
-
fi
|
|
116
|
-
return 1
|
|
117
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 13:21:03
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 13:21:22
|
|
7
|
-
# @FilePath : /add-coder/templates/core/hooks/lib/subagent-stop.sh
|
|
8
|
-
# @Description : SubagentStop 治理卡位
|
|
9
|
-
###
|
|
10
|
-
# subagent-stop.sh — SubagentStop 治理卡位
|
|
11
|
-
# 路径: templates/core/hooks/lib/subagent-stop.sh
|
|
12
|
-
#
|
|
13
|
-
# 治理职能(卡位 #11):
|
|
14
|
-
# ① 子 agent 结果边界校验: 检查交付物是否在 spec 边界内(不越界、不遗漏)
|
|
15
|
-
# ② 审计聚合: 将子 agent 的 sub-traceId 审计记录合并回主 traceId
|
|
16
|
-
# ③ 阻断能力: 子 agent 结果不符合 spec → exit 2 要求重做
|
|
17
|
-
#
|
|
18
|
-
# 用法: 被各 IDE adapter 的 SubagentStop hook 脚本 source 并调用 main
|
|
19
|
-
|
|
20
|
-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
21
|
-
source "$SCRIPT_DIR/common.sh" 2>/dev/null || true
|
|
22
|
-
|
|
23
|
-
# 边界校验: 检查子 agent 交付物是否超出 spec 定义的文件范围
|
|
24
|
-
# 参数: $1 = subagent_name, $2 = 子 agent 交付物文件列表(空格分隔)
|
|
25
|
-
check_boundary() {
|
|
26
|
-
local subagent_name="$1"
|
|
27
|
-
local deliverables="$2"
|
|
28
|
-
|
|
29
|
-
# 获取活跃 ADD 状态
|
|
30
|
-
local state=""
|
|
31
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
32
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
if [ -z "$state" ]; then
|
|
36
|
-
# 无活跃 Plan —— 无 spec 可参考,仅告警不阻断
|
|
37
|
-
echo "[ADD SubagentStop] ⚠️ 无活跃 ADD Plan,无法校验 $subagent_name 的交付物边界" >&2
|
|
38
|
-
return 0
|
|
39
|
-
fi
|
|
40
|
-
|
|
41
|
-
local plan_kw=$(echo "$state" | awk -F'::' '{print $1}')
|
|
42
|
-
local handoff=$(echo "$state" | awk -F'::' '{print $4}')
|
|
43
|
-
|
|
44
|
-
echo "[ADD SubagentStop] $subagent_name 已完成,交付物: $deliverables" >&2
|
|
45
|
-
echo "[ADD SubagentStop] 关联 Plan: $plan_kw | handoff: $handoff" >&2
|
|
46
|
-
|
|
47
|
-
# best-effort: 如果 handoff 中列出了允许的文件范围,检查交付物是否在其中
|
|
48
|
-
if [ -f "$handoff" ] && [ -n "$deliverables" ]; then
|
|
49
|
-
local violations=""
|
|
50
|
-
for f in $deliverables; do
|
|
51
|
-
if ! grep -q "$f" "$handoff" 2>/dev/null; then
|
|
52
|
-
violations="${violations} $f"
|
|
53
|
-
fi
|
|
54
|
-
done
|
|
55
|
-
if [ -n "$violations" ]; then
|
|
56
|
-
echo "[ADD SubagentStop] ❌ $subagent_name 交付物超出 spec 边界: $violations" >&2
|
|
57
|
-
echo "[ADD SubagentStop] 请检查这些文件是否属于本轮 spec 范围,或更新 handoff 文件清单" >&2
|
|
58
|
-
return 1
|
|
59
|
-
fi
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
return 0
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
main() {
|
|
66
|
-
local subagent_name="${1:-unknown}"
|
|
67
|
-
|
|
68
|
-
# 从 stdin 解析 JSON(hook 事件传入)
|
|
69
|
-
local input=$(parse_input 2>/dev/null || echo "{}")
|
|
70
|
-
local deliverables=""
|
|
71
|
-
|
|
72
|
-
# 尝试从 stdin JSON 提取交付物信息
|
|
73
|
-
local agent_type=$(echo "$input" | grep -o '"agent_type"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
74
|
-
[ -n "$agent_type" ] && subagent_name="${subagent_name}($agent_type)"
|
|
75
|
-
|
|
76
|
-
# ① 边界校验
|
|
77
|
-
if ! check_boundary "$subagent_name" "$deliverables"; then
|
|
78
|
-
echo "[ADD SubagentStop] 要求重做——交付物超出 spec 边界" >&2
|
|
79
|
-
exit "${EXIT_BLOCK:-2}"
|
|
80
|
-
fi
|
|
81
|
-
|
|
82
|
-
# ② 审计聚合(输出到 stderr 供日志记录)
|
|
83
|
-
echo "[ADD SubagentStop] $subagent_name 边界校验通过 — $(date -Iseconds)" >&2
|
|
84
|
-
|
|
85
|
-
exit 0
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
89
|
-
main "$@"
|
|
90
|
-
fi
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# vocabulary.sh — 从 vocabulary markdown 表格加载触发词
|
|
3
|
-
# 单一数据源: .qoder/vocabulary/add-governance-vocabulary.md §类别 A-F 表格
|
|
4
|
-
|
|
5
|
-
# 动态探测 MAGIC_DIR
|
|
6
|
-
if [ -z "${MAGIC_DIR:-}" ]; then
|
|
7
|
-
for m in ".claude" ".qoder" ".vscode" ".add"; do
|
|
8
|
-
[ -d "${PROJECT_DIR:-$PWD}/$m" ] && { MAGIC_DIR="$m"; break; }
|
|
9
|
-
done
|
|
10
|
-
MAGIC_DIR="${MAGIC_DIR:-.add}"
|
|
11
|
-
fi
|
|
12
|
-
VOCABULARY_FILE="${PROJECT_DIR:-$PWD}/$MAGIC_DIR/vocabulary/add-governance-vocabulary.md"
|
|
13
|
-
|
|
14
|
-
# 输出格式: 优先级::触发词正则::响应文本(:: 避免与触发词内的 | 冲突)
|
|
15
|
-
load_triggers() {
|
|
16
|
-
[ ! -f "$VOCABULARY_FILE" ] && return 1
|
|
17
|
-
sed -n '/^## 类别 A: 文档类型/,/^## 类别 [G-Z]/p' "$VOCABULARY_FILE" \
|
|
18
|
-
| grep -E '^\| (P0|P1|P2) ' \
|
|
19
|
-
| while IFS='|' read -r _ prio raw_trigger action; do
|
|
20
|
-
prio=$(echo "$prio" | xargs)
|
|
21
|
-
trigger=$(echo "$raw_trigger" | sed 's/`//g;s/ *\/ */|/g;s/^ *//;s/ *$//')
|
|
22
|
-
action=$(echo "$action" | xargs)
|
|
23
|
-
[ -z "$trigger" ] && continue
|
|
24
|
-
echo "${prio}::${trigger}::${action}"
|
|
25
|
-
done || true
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
match_trigger() {
|
|
29
|
-
local prompt="$1"
|
|
30
|
-
while IFS= read -r line; do
|
|
31
|
-
[ -z "$line" ] && continue
|
|
32
|
-
local prio="${line%%::*}"
|
|
33
|
-
local rest="${line#*::}"
|
|
34
|
-
local regex="${rest%%::*}"
|
|
35
|
-
local action="${rest#*::}"
|
|
36
|
-
# 跳过开发关键词检测行(由 Layer 2/3 分流处理,特征:超长regex含"修bug")
|
|
37
|
-
if echo "$regex" | grep -qE '修\.\?bug|fix\.\?bug' 2>/dev/null; then
|
|
38
|
-
continue
|
|
39
|
-
fi
|
|
40
|
-
if echo "$prompt" | grep -qiE "$regex" 2>/dev/null; then
|
|
41
|
-
echo "[ADD 触发] ${regex} → ${action}"
|
|
42
|
-
fi
|
|
43
|
-
done < <(load_triggers 2>/dev/null)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
load_dev_keywords() {
|
|
47
|
-
load_triggers 2>/dev/null | while IFS= read -r line; do
|
|
48
|
-
[ -z "$line" ] && continue
|
|
49
|
-
# 只取包含"开发|改功能"的开发关键词检测行
|
|
50
|
-
if echo "$line" | grep -q '开发|改功能' 2>/dev/null; then
|
|
51
|
-
local rest="${line#*::}"
|
|
52
|
-
local regex="${rest%%::*}"
|
|
53
|
-
echo "$regex"
|
|
54
|
-
fi
|
|
55
|
-
done || true
|
|
56
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Notification — Review 提醒 + Token 预警(Claude Code 适配)
|
|
3
|
-
# 治理卡位 #12: 开发提醒/Token 预警
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
input=$(cat)
|
|
7
|
-
ntype=$(echo "$input" | jq -r '.notification_type // ""' 2>/dev/null || echo "")
|
|
8
|
-
|
|
9
|
-
if [ "$ntype" != "result" ]; then
|
|
10
|
-
exit 0
|
|
11
|
-
fi
|
|
12
|
-
|
|
13
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
14
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
15
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
16
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
17
|
-
|
|
18
|
-
export PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$PWD}"
|
|
19
|
-
|
|
20
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
21
|
-
[ -z "$state" ] && exit 0
|
|
22
|
-
|
|
23
|
-
IFS='::' read -r plan _ _ _ _ <<< "$state"
|
|
24
|
-
|
|
25
|
-
# 动态探测
|
|
26
|
-
if [ -z "${MAGIC_DIR:-}" ]; then
|
|
27
|
-
for m in ".claude" ".qoder" ".vscode" ".add"; do
|
|
28
|
-
[ -d "${PROJECT_DIR:-$PWD}/$m" ] && { MAGIC_DIR="$m"; break; }
|
|
29
|
-
done
|
|
30
|
-
MAGIC_DIR="${MAGIC_DIR:-.claude}"
|
|
31
|
-
fi
|
|
32
|
-
reviews_dir="${PROJECT_DIR}/$MAGIC_DIR/reviews"
|
|
33
|
-
if ls "$reviews_dir"/*.md >/dev/null 2>&1; then
|
|
34
|
-
echo "[ADD Notification] Plan: ${plan} — 请检查 Review 文档: ${reviews_dir}"
|
|
35
|
-
fi
|
|
36
|
-
exit 0
|
|
37
|
-
#!/bin/bash
|
|
38
|
-
# Notification — 通知事件处理(Claude Code 适配)
|
|
39
|
-
set -euo pipefail
|
|
40
|
-
|
|
41
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
42
|
-
SHARED_LIB="$HOOK_DIR/../../shared/hooks-lib/common.sh"
|
|
43
|
-
[ -f "$SHARED_LIB" ] && source "$SHARED_LIB"
|
|
44
|
-
|
|
45
|
-
exit 0
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 13:36:32
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 13:36:33
|
|
7
|
-
# @FilePath : /add-coder/templates/adapters/claude/hooks/permission-denied.sh
|
|
8
|
-
# @Description :
|
|
9
|
-
###
|
|
10
|
-
# permission-denied.sh — Claude Code PermissionDenied:拒绝记录 + 替代方案
|
|
11
|
-
# 治理卡位 #14: 拒绝原因记录 + 替代方案注入
|
|
12
|
-
# Claude Code 独有事件
|
|
13
|
-
set -euo pipefail
|
|
14
|
-
|
|
15
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
16
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
17
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
18
|
-
|
|
19
|
-
input=$(parse_input)
|
|
20
|
-
tool_name=$(json_get "$input" "tool_name")
|
|
21
|
-
[ -z "$tool_name" ] && tool_name=$(echo "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "unknown")
|
|
22
|
-
|
|
23
|
-
reason=$(json_get "$input" "reason")
|
|
24
|
-
[ -z "$reason" ] && reason=$(echo "$input" | grep -o '"reason"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "权限被拒绝")
|
|
25
|
-
|
|
26
|
-
# 记录拒绝
|
|
27
|
-
echo "[ADD PermissionDenied] ${tool_name} 被拒绝: ${reason}" >&2
|
|
28
|
-
|
|
29
|
-
# 按工具类型提供替代建议
|
|
30
|
-
case "$tool_name" in
|
|
31
|
-
Bash)
|
|
32
|
-
echo "[ADD PermissionDenied] 建议: 使用安全的等价命令,或通过 permission-gate.sh 白名单放行" >&2
|
|
33
|
-
;;
|
|
34
|
-
Write|Edit)
|
|
35
|
-
echo "[ADD PermissionDenied] 建议: 检查目标路径是否在项目范围内,敏感文件(.env等)不可写入" >&2
|
|
36
|
-
;;
|
|
37
|
-
Read)
|
|
38
|
-
echo "[ADD PermissionDenied] 建议: 该文件可能受读保护,尝试读取项目公有文件替代" >&2
|
|
39
|
-
;;
|
|
40
|
-
esac
|
|
41
|
-
|
|
42
|
-
exit 0
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# PermissionRequest — 权限请求门禁(Claude Code 适配)
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
|
|
5
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
-
SHARED_LIB="$HOOK_DIR/../../shared/hooks-lib/common.sh"
|
|
7
|
-
[ -f "$SHARED_LIB" ] && source "$SHARED_LIB"
|
|
8
|
-
|
|
9
|
-
input=$(parse_input)
|
|
10
|
-
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
|
|
11
|
-
|
|
12
|
-
# 高风险工具需要二次确认
|
|
13
|
-
case "$tool_name" in
|
|
14
|
-
Bash|Write|Edit)
|
|
15
|
-
echo "[ADD PermissionGate] 高风险工具: ${tool_name},请确认操作。"
|
|
16
|
-
;;
|
|
17
|
-
esac
|
|
18
|
-
exit 0
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# PostToolUseFailure — 工具失败后处理(Claude Code 适配)
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
|
|
5
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
-
SHARED_LIB="$HOOK_DIR/../../shared/hooks-lib/common.sh"
|
|
7
|
-
[ -f "$SHARED_LIB" ] && source "$SHARED_LIB"
|
|
8
|
-
|
|
9
|
-
echo "[ADD PostToolFailure] 工具调用失败,请检查错误信息并修复。"
|
|
10
|
-
exit 0
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# post-tool-use.sh — Claude Code PostToolUse:格式化 + 文档守卫 + 审计提醒
|
|
3
|
-
# 治理卡位 #5: 格式化 + ADD文档守卫 + 审计落库 + 结果增强
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
8
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
9
|
-
|
|
10
|
-
input=$(parse_input)
|
|
11
|
-
tool_name=$(json_get "$input" "tool_name")
|
|
12
|
-
[ -z "$tool_name" ] && tool_name=$(echo "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
13
|
-
|
|
14
|
-
# ── Edit/Write matcher: 格式化 + ADD文档守卫 ──
|
|
15
|
-
if [ "$tool_name" = "Edit" ] || [ "$tool_name" = "Write" ]; then
|
|
16
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
17
|
-
[ -z "$file_path" ] && exit 0
|
|
18
|
-
|
|
19
|
-
# ADD 文档结构守卫:写入 plans/specs/reviews 后提示
|
|
20
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add)/(plans|specs|reviews)/'; then
|
|
21
|
-
echo "[ADD PostToolUse] ADD 文档已写入: ${file_path}。请确保章节完整、双向链接齐全、增量修订格式正确。" >&2
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
# 审计提醒(所有文件写入)
|
|
25
|
-
echo "[ADD PostToolUse] 文件已写入: ${file_path}。请执行 record_dev_operation 落库审计(ADD-7)。" >&2
|
|
26
|
-
exit 0
|
|
27
|
-
fi
|
|
28
|
-
|
|
29
|
-
# ── Bash matcher: 结果增强 ──
|
|
30
|
-
if [ "$tool_name" = "Bash" ]; then
|
|
31
|
-
echo "[ADD PostToolUse] 命令执行完成。如有 lint/tsc 错误请修复。" >&2
|
|
32
|
-
exit 0
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
exit 0
|