add-coder 0.3.27 → 0.3.29
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 +252 -150
- package/package.json +2 -1
- package/templates/.add-coder-src-hash.json +126 -148
- 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/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 +5 -5
- 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 +3 -3
- package/templates/core/docs/ADD-governance-codex.md +5 -5
- package/templates/core/docs/ADD-governance-qoder-cn.md +4 -4
- package/templates/core/docs/ADD-governance-trae.md +2 -2
- package/templates/core/docs/ADD-governance-vscode-copilot.md +21 -22
- 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/scripts/mcp-server/tools/gateway/check_rahs.ts +12 -1
- package/templates/core/scripts/mcp-server/tools/plan.ts +12 -2
- package/templates/adapters/claude/hooks/doc-format-guard.sh +0 -283
- package/templates/adapters/claude/hooks/lib/common.sh +0 -220
- package/templates/adapters/claude/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/claude/hooks/lib/notify.sh +0 -36
- package/templates/adapters/claude/hooks/lib/preload-templates.sh +0 -212
- package/templates/adapters/claude/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/claude/hooks/lib/state-detect.sh +0 -13
- package/templates/adapters/claude/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/claude/hooks/lib/vocabulary.sh +0 -62
- 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 -54
- 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 -343
- package/templates/adapters/codex/hooks/lib/common.sh +0 -209
- package/templates/adapters/codex/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/codex/hooks/lib/notify.sh +0 -36
- package/templates/adapters/codex/hooks/lib/preload-templates.sh +0 -208
- package/templates/adapters/codex/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/codex/hooks/lib/state-detect.sh +0 -8
- package/templates/adapters/codex/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/codex/hooks/lib/vocabulary.sh +0 -51
- package/templates/adapters/codex/hooks/notification.sh +0 -30
- 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 -43
- package/templates/adapters/codex/hooks/pre-compact.sh +0 -37
- package/templates/adapters/codex/hooks/pre-tool-use.sh +0 -130
- package/templates/adapters/codex/hooks/prompt-submit.sh +0 -92
- 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 -63
- package/templates/adapters/codex/hooks/stop-check.sh +0 -71
- 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 -341
- package/templates/adapters/qoder/hooks/lib/common.sh +0 -223
- package/templates/adapters/qoder/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/qoder/hooks/lib/notify.sh +0 -36
- package/templates/adapters/qoder/hooks/lib/preload-templates.sh +0 -212
- package/templates/adapters/qoder/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/qoder/hooks/lib/state-detect.sh +0 -13
- package/templates/adapters/qoder/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/qoder/hooks/lib/vocabulary.sh +0 -62
- 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 -59
- 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 -343
- package/templates/adapters/trae/hooks/lib/common.sh +0 -220
- package/templates/adapters/trae/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/trae/hooks/lib/notify.sh +0 -36
- package/templates/adapters/trae/hooks/lib/preload-templates.sh +0 -212
- package/templates/adapters/trae/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/trae/hooks/lib/state-detect.sh +0 -10
- package/templates/adapters/trae/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/trae/hooks/lib/vocabulary.sh +0 -62
- 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 -223
- 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 -54
- 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 -282
- package/templates/adapters/vscode/hooks/lib/common.sh +0 -220
- package/templates/adapters/vscode/hooks/lib/context-inject.sh +0 -96
- package/templates/adapters/vscode/hooks/lib/notify.sh +0 -36
- package/templates/adapters/vscode/hooks/lib/preload-templates.sh +0 -212
- package/templates/adapters/vscode/hooks/lib/session-end.sh +0 -76
- package/templates/adapters/vscode/hooks/lib/state-detect.sh +0 -13
- package/templates/adapters/vscode/hooks/lib/subagent-stop.sh +0 -90
- package/templates/adapters/vscode/hooks/lib/vocabulary.sh +0 -62
- package/templates/adapters/vscode/hooks/notification.sh +0 -43
- 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 -62
- 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 -343
- package/templates/core/hooks/lib/common.sh +0 -220
- package/templates/core/hooks/lib/context-inject.sh +0 -96
- package/templates/core/hooks/lib/notify.sh +0 -36
- package/templates/core/hooks/lib/preload-templates.sh +0 -212
- package/templates/core/hooks/lib/session-end.sh +0 -76
- package/templates/core/hooks/lib/state-detect.sh +0 -10
- package/templates/core/hooks/lib/subagent-stop.sh +0 -90
- package/templates/core/hooks/lib/vocabulary.sh +0 -62
- 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 -223
- 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 -54
- 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,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,62 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# vocabulary.sh — 从 vocabulary markdown 表格加载触发词
|
|
3
|
-
# 单一数据源: {MAGIC_DIR}/vocabulary/add-governance-vocabulary.md §类别 A-F 表格
|
|
4
|
-
# 协议层契约(Review P1 #5): 仅当前 magicDir scope;入口注入 MAGIC_DIR 或物理位置推导;
|
|
5
|
-
# 禁止跨端扫描与 .add fallback,禁止 adapter 名称默认值。
|
|
6
|
-
|
|
7
|
-
# MAGIC_DIR 解析: 入口注入优先;未注入时从脚本物理位置(<magicDir>/hooks/lib/)反推
|
|
8
|
-
if [ -z "${MAGIC_DIR:-}" ]; then
|
|
9
|
-
if [ -n "${HOOK_DIR:-}" ]; then
|
|
10
|
-
MAGIC_DIR="$(basename "$(dirname "$HOOK_DIR")")"
|
|
11
|
-
else
|
|
12
|
-
# 无注入且无物理位置 → 无法判定 → 返回空(调用方 fail-closed,禁止猜测 adapter)
|
|
13
|
-
VOCABULARY_FILE=""
|
|
14
|
-
fi
|
|
15
|
-
fi
|
|
16
|
-
if [ -n "${MAGIC_DIR:-}" ]; then
|
|
17
|
-
VOCABULARY_FILE="${PROJECT_DIR:-$PWD}/$MAGIC_DIR/vocabulary/add-governance-vocabulary.md"
|
|
18
|
-
fi
|
|
19
|
-
|
|
20
|
-
# 输出格式: 优先级::触发词正则::响应文本(:: 避免与触发词内的 | 冲突)
|
|
21
|
-
load_triggers() {
|
|
22
|
-
[ ! -f "$VOCABULARY_FILE" ] && return 1
|
|
23
|
-
sed -n '/^## 类别 A: 文档类型/,/^## 类别 [G-Z]/p' "$VOCABULARY_FILE" \
|
|
24
|
-
| grep -E '^\| (P0|P1|P2) ' \
|
|
25
|
-
| while IFS='|' read -r _ prio raw_trigger action; do
|
|
26
|
-
prio=$(echo "$prio" | xargs)
|
|
27
|
-
trigger=$(echo "$raw_trigger" | sed 's/`//g;s/ *\/ */|/g;s/^ *//;s/ *$//')
|
|
28
|
-
action=$(echo "$action" | xargs)
|
|
29
|
-
[ -z "$trigger" ] && continue
|
|
30
|
-
echo "${prio}::${trigger}::${action}"
|
|
31
|
-
done || true
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
match_trigger() {
|
|
35
|
-
local prompt="$1"
|
|
36
|
-
while IFS= read -r line; do
|
|
37
|
-
[ -z "$line" ] && continue
|
|
38
|
-
local prio="${line%%::*}"
|
|
39
|
-
local rest="${line#*::}"
|
|
40
|
-
local regex="${rest%%::*}"
|
|
41
|
-
local action="${rest#*::}"
|
|
42
|
-
# 跳过开发关键词检测行(由 Layer 2/3 分流处理,特征:超长regex含"修bug")
|
|
43
|
-
if echo "$regex" | grep -qE '修\.\?bug|fix\.\?bug' 2>/dev/null; then
|
|
44
|
-
continue
|
|
45
|
-
fi
|
|
46
|
-
if echo "$prompt" | grep -qiE "$regex" 2>/dev/null; then
|
|
47
|
-
echo "[ADD 触发] ${regex} → ${action}"
|
|
48
|
-
fi
|
|
49
|
-
done < <(load_triggers 2>/dev/null)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
load_dev_keywords() {
|
|
53
|
-
load_triggers 2>/dev/null | while IFS= read -r line; do
|
|
54
|
-
[ -z "$line" ] && continue
|
|
55
|
-
# 只取包含"开发|改功能"的开发关键词检测行
|
|
56
|
-
if echo "$line" | grep -q '开发|改功能' 2>/dev/null; then
|
|
57
|
-
local rest="${line#*::}"
|
|
58
|
-
local regex="${rest%%::*}"
|
|
59
|
-
echo "$regex"
|
|
60
|
-
fi
|
|
61
|
-
done || true
|
|
62
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# notification.sh — Qoder CN Notification:Review 提醒
|
|
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
|
-
export PROJECT_DIR="${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}"
|
|
16
|
-
source "$HOOK_DIR/lib/common.sh" 2>/dev/null || true
|
|
17
|
-
|
|
18
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
19
|
-
[ -z "$state" ] && exit 0
|
|
20
|
-
|
|
21
|
-
reviews_dir="${PROJECT_DIR}/.qoder/reviews"
|
|
22
|
-
if ls "$reviews_dir"/*.md >/dev/null 2>&1; then
|
|
23
|
-
echo "[ADD Notification] 请检查 Review 文档: ${reviews_dir}"
|
|
24
|
-
fi
|
|
25
|
-
exit 0
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# permission-gate.sh — PermissionRequest 人工卡位(不干预)
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
# ADD Review 卡位由 Qoder 本身的权限弹窗处理,此 hook 仅做日志
|
|
5
|
-
input=$(cat)
|
|
6
|
-
tool_name=$(echo "$input" | jq -r '.tool_name // "unknown"')
|
|
7
|
-
echo "[ADD PermissionRequest] 工具 ${tool_name} 请求权限。如有 Review 文档待确认,请先检查。" >&2
|
|
8
|
-
exit 0
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# post-tool-failure.sh — PostToolUseFailure 错误定位
|
|
3
|
-
set -euo pipefail
|
|
4
|
-
input=$(cat)
|
|
5
|
-
tool_name=$(echo "$input" | jq -r '.tool_name // "unknown"')
|
|
6
|
-
error=$(echo "$input" | jq -r '.error // "unknown"')
|
|
7
|
-
echo "[ADD PostToolUseFailure] 工具 ${tool_name} 失败: ${error}。检查是否需要回退到上一 ADD Step 重新执行。" >&2
|
|
8
|
-
exit 0
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# post-tool-use.sh — Qoder CN PostToolUse:格式化 + 文档守卫 + 审计提醒 + DPS 自动化
|
|
3
|
-
# 治理卡位 #5: 格式化 + ADD文档守卫 + 审计落库 + 结果增强 + 哨兵自动化
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
input=$(cat)
|
|
7
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
9
|
-
export PROJECT_DIR="${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}"
|
|
10
|
-
source "$HOOK_DIR/lib/common.sh" 2>/dev/null || true
|
|
11
|
-
MAGIC_DIR="$CURRENT_MAGIC"
|
|
12
|
-
|
|
13
|
-
tool_name=$(json_get "$input" "tool_name")
|
|
14
|
-
[ -z "$tool_name" ] && tool_name=$(echo "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
15
|
-
|
|
16
|
-
# ═══════════════ §1: HITL DPS 自动化 — check_dps ≥ 80 → 自动建哨兵 ═══════════════
|
|
17
|
-
if echo "$input" | grep -q '"check_dps"'; then
|
|
18
|
-
dps_score=$(echo "$input" | grep -oP 'DPS\s*=\s*\K\d+' 2>/dev/null || echo "")
|
|
19
|
-
plan_keyword=$(echo "$input" | grep -oP '"planKeyword"\s*:\s*"\K[^"]+' 2>/dev/null || echo "")
|
|
20
|
-
|
|
21
|
-
if [ -n "$dps_score" ] && [ -n "$plan_keyword" ]; then
|
|
22
|
-
if [ "$dps_score" -ge 80 ] 2>/dev/null; then
|
|
23
|
-
sentinel="${PROJECT_DIR}/${MAGIC_DIR}/hitl/.tongyi-${plan_keyword}"
|
|
24
|
-
if [ ! -f "$sentinel" ]; then
|
|
25
|
-
touch "$sentinel" 2>/dev/null || true
|
|
26
|
-
echo "[ADD PostToolUse] ✅ DPS=${dps_score} ≥80, HITL 自动通过 → ${sentinel}" >&2
|
|
27
|
-
fi
|
|
28
|
-
else
|
|
29
|
-
echo "[ADD PostToolUse] ⚠️ DPS=${dps_score} <80, 需 Review 后手动建哨兵 .tongyi-${plan_keyword}" >&2
|
|
30
|
-
fi
|
|
31
|
-
fi
|
|
32
|
-
fi
|
|
33
|
-
|
|
34
|
-
# ═══════════════ §2: Edit/Write matcher ═══════════════
|
|
35
|
-
if [ "$tool_name" = "Edit" ] || [ "$tool_name" = "Write" ]; then
|
|
36
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
37
|
-
[ -z "$file_path" ] && exit 0
|
|
38
|
-
|
|
39
|
-
# §2a: ADD 文档结构守卫
|
|
40
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add)/(plans|specs|reviews)/'; then
|
|
41
|
-
echo "[ADD PostToolUse] ADD 文档已写入: ${file_path}。请确保章节完整、双向链接齐全。" >&2
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
# §2b: plan_track 自动触发 — specs/ 或 add-route 写入后提醒
|
|
45
|
-
if echo "$file_path" | grep -qE '/(specs|plans)/.*add-route'; then
|
|
46
|
-
plan_name=""
|
|
47
|
-
if echo "$file_path" | grep -qE 'add-route'; then
|
|
48
|
-
plan_prefix=$(basename "$file_path" | sed 's/-add-route-v[0-9]*\.md$//')
|
|
49
|
-
plan_dir=$(dirname "$file_path")
|
|
50
|
-
if [ -d "$plan_dir" ]; then
|
|
51
|
-
plan_file=$(ls "$plan_dir"/*-plan-v*.md 2>/dev/null | head -1 || echo "")
|
|
52
|
-
if [ -n "$plan_file" ]; then
|
|
53
|
-
plan_name=$(basename "$plan_file" .md)
|
|
54
|
-
fi
|
|
55
|
-
fi
|
|
56
|
-
fi
|
|
57
|
-
if [ -n "$plan_name" ]; then
|
|
58
|
-
echo "[ADD PostToolUse] 📊 请执行 plan_track({ planName: \"${plan_name}\" }) 落库同步" >&2
|
|
59
|
-
fi
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
# §2c: devlog 自动提醒 — add-route Step 8 全 [x] 时提醒
|
|
63
|
-
if echo "$file_path" | grep -qE 'add-route.*\.md$'; then
|
|
64
|
-
if [ -f "$file_path" ]; then
|
|
65
|
-
step8_unchecked=$(sed -n '/## Step 8/,/^## /p' "$file_path" 2>/dev/null | grep -c '^\- \[ \]' 2>/dev/null || echo "0")
|
|
66
|
-
step8_checked=$(sed -n '/## Step 8/,/^## /p' "$file_path" 2>/dev/null | grep -c '^\- \[x\]' 2>/dev/null || echo "0")
|
|
67
|
-
if [ "$step8_unchecked" = "0" ] && [ "$step8_checked" -gt 0 ]; then
|
|
68
|
-
echo "[ADD PostToolUse] ⚠️ Step 8 全部收敛完成!请写 devlog日志(走mcp) → 更新 handoff" >&2
|
|
69
|
-
fi
|
|
70
|
-
fi
|
|
71
|
-
fi
|
|
72
|
-
|
|
73
|
-
# §2d: schema.json 自动 regen 提醒
|
|
74
|
-
if echo "$file_path" | grep -qE 'templates/.*\.md$'; then
|
|
75
|
-
schema_file="${file_path%.md}.schema.json"
|
|
76
|
-
if [ -f "$schema_file" ]; then
|
|
77
|
-
echo "[ADD PostToolUse] 🔄 模板已修改,请检查 ${schema_file} 是否需更新" >&2
|
|
78
|
-
fi
|
|
79
|
-
fi
|
|
80
|
-
|
|
81
|
-
echo "[ADD PostToolUse] 文件已写入: ${file_path}。请执行 record_dev_operation 落库审计(ADD-7)。" >&2
|
|
82
|
-
exit 0
|
|
83
|
-
fi
|
|
84
|
-
|
|
85
|
-
# ═══════════════ §3: Bash matcher ═══════════════
|
|
86
|
-
if [ "$tool_name" = "Bash" ]; then
|
|
87
|
-
echo "[ADD PostToolUse] 命令执行完成。如有 lint/tsc 错误请修复。" >&2
|
|
88
|
-
exit 0
|
|
89
|
-
fi
|
|
90
|
-
|
|
91
|
-
exit 0
|
|
92
|
-
#!/bin/bash
|
|
93
|
-
# post-tool-use.sh — Qoder CN PostToolUse:格式化 + 文档守卫 + 审计提醒
|
|
94
|
-
# 治理卡位 #5: 格式化 + ADD文档守卫 + 审计落库 + 结果增强
|
|
95
|
-
set -euo pipefail
|
|
96
|
-
|
|
97
|
-
input=$(cat)
|
|
98
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
99
|
-
source "$HOOK_DIR/lib/common.sh" 2>/dev/null || true
|
|
100
|
-
|
|
101
|
-
tool_name=$(json_get "$input" "tool_name")
|
|
102
|
-
[ -z "$tool_name" ] && tool_name=$(echo "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
103
|
-
|
|
104
|
-
if [ "$tool_name" = "Edit" ] || [ "$tool_name" = "Write" ]; then
|
|
105
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
106
|
-
[ -z "$file_path" ] && exit 0
|
|
107
|
-
|
|
108
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add)/(plans|specs|reviews)/'; then
|
|
109
|
-
echo "[ADD PostToolUse] ADD 文档已写入: ${file_path}。请确保章节完整、双向链接齐全、增量修订格式正确。" >&2
|
|
110
|
-
fi
|
|
111
|
-
|
|
112
|
-
echo "[ADD PostToolUse] 文件已写入: ${file_path}。请执行 record_dev_operation 落库审计(ADD-7)。" >&2
|
|
113
|
-
exit 0
|
|
114
|
-
fi
|
|
115
|
-
|
|
116
|
-
if [ "$tool_name" = "Bash" ]; then
|
|
117
|
-
echo "[ADD PostToolUse] 命令执行完成。如有 lint/tsc 错误请修复。" >&2
|
|
118
|
-
exit 0
|
|
119
|
-
fi
|
|
120
|
-
|
|
121
|
-
exit 0
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# pre-compact.sh — 上下文压缩前 ADD 状态保存(Claude Code 适配)
|
|
3
|
-
# 治理卡位 #9: ADD状态保存 + 恢复清单导出 + tpl标记清理
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
8
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
9
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
10
|
-
|
|
11
|
-
export PROJECT_DIR="${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}"
|
|
12
|
-
|
|
13
|
-
# ── ① 获取 ADD 状态并保存到标记文件 ──
|
|
14
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
15
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
16
|
-
if [ -n "$state" ]; then
|
|
17
|
-
IFS='::' read -r plan step rounds handoff add_route <<< "$state"
|
|
18
|
-
|
|
19
|
-
# 写入恢复标记文件(SessionStart 恢复时读取)
|
|
20
|
-
RECOVERY_FILE="/tmp/add_recovery_$(echo "${PROJECT_DIR}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")"
|
|
21
|
-
cat > "$RECOVERY_FILE" <<EOF
|
|
22
|
-
plan=${plan}
|
|
23
|
-
step=${step}
|
|
24
|
-
rounds=${rounds}
|
|
25
|
-
handoff=${handoff}
|
|
26
|
-
add_route=${add_route}
|
|
27
|
-
EOF
|
|
28
|
-
|
|
29
|
-
echo "[ADD PreCompact] ADD 状态已保存: Plan=${plan}, Step=${step}" >&2
|
|
30
|
-
fi
|
|
31
|
-
fi
|
|
32
|
-
|
|
33
|
-
# ── ② 清理 tpl-injected 标记(compact 后上下文丢失,下次需重注) ──
|
|
34
|
-
TPL_FLAG="/tmp/add_tpl_$(echo "${PROJECT_DIR}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")"
|
|
35
|
-
rm -f "$TPL_FLAG" 2>/dev/null || true
|
|
36
|
-
|
|
37
|
-
exit 0
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# pre-tool-use.sh — Qoder CN PreToolUse:四路守卫
|
|
3
|
-
# 治理卡位 #4: 危险命令拦截 / 模板路径兜底 / 写入前置守卫 / 敏感文件保护
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
input=$(cat)
|
|
7
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
9
|
-
export PROJECT_DIR="${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}"
|
|
10
|
-
source "$HOOK_DIR/lib/common.sh" 2>/dev/null || true
|
|
11
|
-
source "$HOOK_DIR/lib/notify.sh" 2>/dev/null || true
|
|
12
|
-
MAGIC_DIR="$CURRENT_MAGIC"
|
|
13
|
-
|
|
14
|
-
# ── Hook 通知: 提前计算 Plan 关联信息 ──
|
|
15
|
-
ACTIVE_PLAN=$(detect_active_add 2>/dev/null || true)
|
|
16
|
-
if [ -n "$ACTIVE_PLAN" ]; then
|
|
17
|
-
PLAN_KEYWORD="${ACTIVE_PLAN%%::*}"
|
|
18
|
-
PLAN_STATUS="active"
|
|
19
|
-
else
|
|
20
|
-
PLAN_KEYWORD="no-active-plan"
|
|
21
|
-
PLAN_STATUS="none"
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
tool_name=$(json_get "$input" "tool_name")
|
|
25
|
-
[ -z "$tool_name" ] && tool_name=$(echo "$input" | grep -o '"tool_name"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
26
|
-
|
|
27
|
-
# ── ① Bash matcher: 危险命令拦截 + 终端写文件拦截 ──
|
|
28
|
-
if [ "$tool_name" = "Bash" ]; then
|
|
29
|
-
cmd=$(echo "$input" | grep -o '"command"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
30
|
-
# 危险命令
|
|
31
|
-
if echo "$cmd" | grep -qiE 'rm[[:space:]]+-rf[[:space:]]+/|DROP[[:space:]]+TABLE|git[[:space:]]+push[[:space:]]+--force|mkfs\.|dd[[:space:]]+if='; then
|
|
32
|
-
echo "⛔ 危险命令已被阻止: $cmd" >&2
|
|
33
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"危险命令已被阻止\"}}"
|
|
34
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "危险命令已被阻止" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
35
|
-
exit 2
|
|
36
|
-
fi
|
|
37
|
-
# 终端写文件拦截(含 > / >> / << heredoc / mv / touch / python -c > file)
|
|
38
|
-
if echo "$cmd" | grep -qE '(cat|echo|tee|sed[[:space:]]+-i|awk|printf|cp|mv|dd|touch)[[:space:]]*.*([>]{1,2}|[|][[:space:]]*tee|<<)'; then
|
|
39
|
-
echo "⛔ 禁止通过终端命令直接写文件: $cmd。请使用 Write/Edit/SearchReplace 工具。" >&2
|
|
40
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"禁止通过终端直接写文件,请使用 IDE 工具\"}}"
|
|
41
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过终端直接写文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
42
|
-
exit 2
|
|
43
|
-
fi
|
|
44
|
-
# cp / mv / touch — 可创建或覆盖文件,无重定向也拦(对齐 core §A 检测5)
|
|
45
|
-
if echo "$cmd" | grep -qE '(^|;|\|\||&&|\|)\s*(cp|mv|touch)\b'; then
|
|
46
|
-
echo "⛔ 禁止通过 cp/mv/touch 操作文件: $cmd。请使用 Write 或 SearchReplace 工具。" >&2
|
|
47
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"禁止通过 cp/mv/touch 操作文件,请使用 IDE 工具\"}}"
|
|
48
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过 cp/mv/touch 操作文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
49
|
-
exit 2
|
|
50
|
-
fi
|
|
51
|
-
# python/node/ruby/perl/php 脚本解释器 — 可写任意文件
|
|
52
|
-
if echo "$cmd" | grep -qE '(^|;|\|\||&&|\|)\s*(python3?|node|ruby|perl|php)(\s|$)'; then
|
|
53
|
-
echo "⛔ 禁止通过脚本解释器直接写文件: $cmd。请使用 Write 或 SearchReplace 工具。" >&2
|
|
54
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"禁止通过脚本解释器直接写文件,请使用 IDE 工具\"}}"
|
|
55
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过脚本解释器直接修改文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
56
|
-
exit 2
|
|
57
|
-
fi
|
|
58
|
-
mark_dev_action 2>/dev/null || true
|
|
59
|
-
exit 0
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
# ── ② Write/Edit matcher: 文件写入前置守卫 ──
|
|
63
|
-
if [ "$tool_name" = "Write" ] || [ "$tool_name" = "Edit" ] || [ "$tool_name" = "SearchReplace" ]; then
|
|
64
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
65
|
-
[ -z "$file_path" ] && exit 0
|
|
66
|
-
|
|
67
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add)/(plans|specs|reviews)/'; then
|
|
68
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
69
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
70
|
-
if [ -z "$state" ]; then
|
|
71
|
-
echo "[ADD 提示] 正在写入 Plan/Spec/Review 文档但无活跃 ADD Plan——首次创建场景放行,建议先执行 add-paradigm 生成 Plan+add-route" >&2
|
|
72
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"allow\",\"permissionDecisionReason\":\"无活跃 ADD Plan 但为 Plan/Spec/Review 写入(首次创建场景),提示而非拦截\"}}"
|
|
73
|
-
write_hook_event "pre-tool-use" "info" "$file_path" "无活跃 ADD Plan 下写入 Plan/Spec/Review(首次创建放行)" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
74
|
-
exit 0
|
|
75
|
-
fi
|
|
76
|
-
fi
|
|
77
|
-
fi
|
|
78
|
-
|
|
79
|
-
if echo "$file_path" | grep -qE '\.env$|\.env\.production$|\.env\.local$|credentials|secrets'; then
|
|
80
|
-
echo "⛔ 敏感文件受保护,禁止写入: $file_path" >&2
|
|
81
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"敏感文件受保护\"}}"
|
|
82
|
-
write_hook_event "pre-tool-use" "deny" "$file_path" "敏感文件受保护" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
83
|
-
exit 2
|
|
84
|
-
fi
|
|
85
|
-
|
|
86
|
-
# §B: 模板类型前置注入 — plans/ 写入前提示应选模板
|
|
87
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(plans)/'; then
|
|
88
|
-
fname=$(basename "$file_path")
|
|
89
|
-
if echo "$fname" | grep -qE 'plan-v[0-9]'; then
|
|
90
|
-
echo "💡 [ADD PreToolUse] 写入 Plan → 模板: standard-plan-template.md(标准)或 simple-plan-template.md(≤3文件)" >&2
|
|
91
|
-
elif echo "$fname" | grep -qE 'add-route'; then
|
|
92
|
-
echo "💡 [ADD PreToolUse] 写入 ADD Route → 模板: add-route-template.md" >&2
|
|
93
|
-
elif echo "$fname" | grep -qE 'handoff'; then
|
|
94
|
-
echo "💡 [ADD PreToolUse] 写入 Handoff → 模板: handoff-single-round-template.md(单轮)或 handoff-multi-round-template.md(多轮)" >&2
|
|
95
|
-
fi
|
|
96
|
-
# Qoder Write 大文件适配 — 已存在大文件建议用 SearchReplace 分块
|
|
97
|
-
if echo "$tool_name" | grep -qE 'Write' && [ -f "$file_path" ]; then
|
|
98
|
-
fsize=$(wc -c < "$file_path" 2>/dev/null || echo "0")
|
|
99
|
-
if [ "$fsize" -gt 2000 ] 2>/dev/null; then
|
|
100
|
-
echo "⚠️ [ADD PreToolUse] 文件已有 ${fsize} 字节,Write 全量覆盖可能触发 Qoder 40500。建议用 SearchReplace 分块追加。" >&2
|
|
101
|
-
fi
|
|
102
|
-
fi
|
|
103
|
-
fi
|
|
104
|
-
|
|
105
|
-
# §C: HITL tongyi 检查 — plans/ + PLAN_REVIEW reviews/ 写入前必须有 .hitl-tongyi-{planName} 哨兵
|
|
106
|
-
# implementation/runtime review 不需要 HITL,走 §B 活跃 Plan 检查
|
|
107
|
-
# handoff 是 Step 8 收敛产物(多轮交接手册),不经 HITL 审批,同样豁免
|
|
108
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(plans)/'; then
|
|
109
|
-
if echo "$file_path" | grep -qE '\-handoff'; then
|
|
110
|
-
_do_hitl=false # handoff 不被 HITL 拦截(Step 8 产物,无独立审批)
|
|
111
|
-
else
|
|
112
|
-
_do_hitl=true
|
|
113
|
-
fi
|
|
114
|
-
elif echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(reviews)/'; then
|
|
115
|
-
if echo "$file_path" | grep -qE '-(implementation|runtime)'; then
|
|
116
|
-
_do_hitl=false # implementation/runtime review 不被 HITL 拦截
|
|
117
|
-
else
|
|
118
|
-
_do_hitl=true # PLAN_REVIEW 需要 HITL
|
|
119
|
-
fi
|
|
120
|
-
else
|
|
121
|
-
_do_hitl=false
|
|
122
|
-
fi
|
|
123
|
-
|
|
124
|
-
if [ "$_do_hitl" = true ]; then
|
|
125
|
-
_relative=$(echo "$file_path" | sed 's|.*/\.\(qoder\|claude\|add\|vscode\|trae\)/\(plans\|reviews\)/||')
|
|
126
|
-
_planName=$(basename "$_relative" .md | sed 's/\.hitl$//;s/-plan-v[0-9]*$//;s/-add-route-v[0-9]*$//;s/-review-v[0-9]*$//;s/-review-implementation$//;s/-review-runtime$//')
|
|
127
|
-
if [ -n "$_planName" ]; then
|
|
128
|
-
_tongyi_marker="${PROJECT_DIR}/${MAGIC_DIR}/hitl/.tongyi-${_planName}"
|
|
129
|
-
if [ ! -f "$_tongyi_marker" ]; then
|
|
130
|
-
echo "⛔ [ADD PreToolUse §C] HITL 未 tongyi: $file_path" >&2
|
|
131
|
-
echo " 原因: 哨兵文件 $_tongyi_marker 不存在" >&2
|
|
132
|
-
echo " 操作: 请先调用 create_hitl 创建审批,再 update_hitl({ status: \"TONGYI\" })" >&2
|
|
133
|
-
_msg="⛔ HITL 未 tongyi: 哨兵 ${_tongyi_marker} 不存在。请先 create_hitl → 人工 tongyi → update_hitl 后再写入"
|
|
134
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"${_msg}\",\"additionalContext\":\"${_msg}\"}}"
|
|
135
|
-
write_hook_event "pre-tool-use" "ask" "$file_path" "HITL 未 tongyi: $_tongyi_marker" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
136
|
-
exit 2
|
|
137
|
-
fi
|
|
138
|
-
fi
|
|
139
|
-
fi
|
|
140
|
-
|
|
141
|
-
mark_dev_action 2>/dev/null || true
|
|
142
|
-
exit 0
|
|
143
|
-
fi
|
|
144
|
-
|
|
145
|
-
# ── ③ Read matcher: 模板路径兜底 ──
|
|
146
|
-
if [ "$tool_name" = "Read" ]; then
|
|
147
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
148
|
-
if echo "$file_path" | grep -q 'templates/'; then
|
|
149
|
-
echo "[ADD PreToolUse] 提示: 模板文件已通过 hook 预读到上下文,可跳过重复读取" >&2
|
|
150
|
-
fi
|
|
151
|
-
exit 0
|
|
152
|
-
fi
|
|
153
|
-
|
|
154
|
-
exit 0
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# prompt-submit.sh — UserPromptSubmit 触发词智能路由(★入口)
|
|
3
|
-
# 治理卡位 #3: 触发词路由 + 模板全文注入(增量插入,保留 Layer 1/2/3)
|
|
4
|
-
input=$(cat)
|
|
5
|
-
prompt=$(echo "$input" | jq -r '.prompt // empty')
|
|
6
|
-
[ -z "$prompt" ] && exit 0
|
|
7
|
-
|
|
8
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
9
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
10
|
-
export PROJECT_DIR="${QODER_PROJECT_DIR:-${QODERCN_PROJECT_DIR:-$PWD}}"
|
|
11
|
-
source "$HOOK_DIR/lib/common.sh" 2>/dev/null || true
|
|
12
|
-
source "$HOOK_DIR/lib/vocabulary.sh"
|
|
13
|
-
source "$HOOK_DIR/lib/state-detect.sh"
|
|
14
|
-
source "$HOOK_DIR/lib/notify.sh" 2>/dev/null || true
|
|
15
|
-
|
|
16
|
-
# ─── additionalContext 注入(Qoder CN IDE 通过 stdout JSON 注入模型上下文)───
|
|
17
|
-
echo '{"hookSpecificOutput":{"hookEventName":"UserPromptSubmit","additionalContext":"ADD workflow active. Templates preloaded. Use add-paradigm SKILL."}}'
|
|
18
|
-
|
|
19
|
-
# ─── Layer 1: 精准 P0 触发词 ───
|
|
20
|
-
matched=$(match_trigger "$prompt")
|
|
21
|
-
if [ -n "$matched" ]; then
|
|
22
|
-
# 验收幂等保护: 如果已验收,提示不重复
|
|
23
|
-
if echo "$prompt" | grep -qiE '验收|收敛' 2>/dev/null; then
|
|
24
|
-
add_state=$(detect_active_add 2>/dev/null || true)
|
|
25
|
-
if [ -n "$add_state" ]; then
|
|
26
|
-
_handoff=$(echo "$add_state" | awk -F'::' '{print $4}')
|
|
27
|
-
_add_route=$(echo "$add_state" | awk -F'::' '{print $5}')
|
|
28
|
-
if is_already_accepted "$_add_route" "$_handoff" 2>/dev/null; then
|
|
29
|
-
printf '%s\n' \
|
|
30
|
-
"[ADD 验收] ⚠️ 已验收。进入 Review 模式:" \
|
|
31
|
-
" ① 重新检查 checklist [T]/[R] 项" \
|
|
32
|
-
" ② 审查 audit 记录完整性" \
|
|
33
|
-
" ③ 如有差异 → Review 回流至 handoff(增量更新,不覆盖已有结论)" \
|
|
34
|
-
" ④ 无差异 → 记录 'Review 已确认,无新发现'" \
|
|
35
|
-
" ★ 同步检查: 如 checklist 有新 cuid 但 handoff 审计表缺失 → 更新 handoff ADD-7 表 + query_audit_logs 命令"
|
|
36
|
-
# 执行 checklist 质量检查
|
|
37
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
38
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
39
|
-
"$HOOK_DIR/review-checklist.sh" "$_handoff" "$_add_route" 2>/dev/null
|
|
40
|
-
exit 0
|
|
41
|
-
fi
|
|
42
|
-
fi
|
|
43
|
-
fi
|
|
44
|
-
echo "$matched"
|
|
45
|
-
exit 0
|
|
46
|
-
fi
|
|
47
|
-
|
|
48
|
-
# ─── 开发关键词检测 ───
|
|
49
|
-
dev_kw=$(load_dev_keywords 2>/dev/null || true)
|
|
50
|
-
if [ -z "$dev_kw" ]; then
|
|
51
|
-
exit 0
|
|
52
|
-
fi
|
|
53
|
-
|
|
54
|
-
if ! echo "$prompt" | grep -qiE "$dev_kw"; then
|
|
55
|
-
exit 0
|
|
56
|
-
fi
|
|
57
|
-
|
|
58
|
-
# ─── Layer 2/3: 按活跃 ADD 分流 ───
|
|
59
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
60
|
-
if [ -z "$state" ]; then
|
|
61
|
-
# Layer 2: 无活跃 ADD → 提示启动(不阻断)
|
|
62
|
-
cat >&2 <<'EOF'
|
|
63
|
-
[ADD 提示] 检测到开发任务,但无活跃 ADD Plan。建议先执行 add-paradigm SKILL:
|
|
64
|
-
Step 0: 文档先行 (Plan → Review → Specs)
|
|
65
|
-
Step 3: 代码实现 + 审计植入
|
|
66
|
-
Step 8: 收敛判断
|
|
67
|
-
EOF
|
|
68
|
-
write_hook_event "prompt-submit" "info" "$prompt" "无活跃 ADD Plan 下检测到开发任务" "no-active-plan" "none" 2>/dev/null || true
|
|
69
|
-
exit 0
|
|
70
|
-
fi
|
|
71
|
-
|
|
72
|
-
# Layer 3: 有活跃 ADD → 注入状态
|
|
73
|
-
plan=$(echo "$state" | awk -F'::' '{print $1}')
|
|
74
|
-
step=$(echo "$state" | awk -F'::' '{print $2}')
|
|
75
|
-
rounds=$(echo "$state" | awk -F'::' '{print $3}')
|
|
76
|
-
handoff=$(echo "$state" | awk -F'::' '{print $4}')
|
|
77
|
-
add_route=$(echo "$state" | awk -F'::' '{print $5}')
|
|
78
|
-
add_ctx="[ADD 状态] Plan: ${plan}, 轮次: ${rounds}, Step: ${step}, handoff: ${handoff}"
|
|
79
|
-
|
|
80
|
-
# ─── Hook 治理日报 ───
|
|
81
|
-
HOOK_JSONL="${MAGIC_DIR}/reports/hook-events.jsonl"
|
|
82
|
-
if [ -f "$HOOK_JSONL" ]; then
|
|
83
|
-
TODAY="$(date +%Y-%m-%d)"
|
|
84
|
-
TOTAL=$(grep -c "\"ts\":\"${TODAY}" "$HOOK_JSONL" 2>/dev/null || echo 0)
|
|
85
|
-
NO_PLAN=$(grep "\"ts\":\"${TODAY}" "$HOOK_JSONL" 2>/dev/null | grep -c '"planKeyword":"no-active-plan"' || echo 0)
|
|
86
|
-
if [ "$TOTAL" -gt 0 ] 2>/dev/null; then
|
|
87
|
-
add_ctx="${add_ctx}\n[Hook 治理] 今日提示: ${TOTAL} 次 | 无 Plan 提示: ${NO_PLAN} 次"
|
|
88
|
-
if [ "$NO_PLAN" -ge 10 ] 2>/dev/null; then
|
|
89
|
-
add_ctx="${add_ctx}\n[Hook ⚠️] 无 Plan 提示已达 ${NO_PLAN} 次(≥10),建议创建 Plan"
|
|
90
|
-
fi
|
|
91
|
-
fi
|
|
92
|
-
fi
|
|
93
|
-
|
|
94
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"UserPromptSubmit\",\"additionalContext\":\"${add_ctx}\"}}"
|
|
95
|
-
exit 0
|
|
96
|
-
|