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,153 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# pre-tool-use.sh — VS Code Copilot PreToolUse:四路守卫
|
|
3
|
-
# 治理卡位 #4: 危险命令拦截 / 模板路径兜底 / 写入前置守卫 / 敏感文件保护
|
|
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
|
-
[ -f "$HOOK_DIR/lib/notify.sh" ] && source "$HOOK_DIR/lib/notify.sh" 2>/dev/null || true
|
|
11
|
-
MAGIC_DIR="$CURRENT_MAGIC"
|
|
12
|
-
|
|
13
|
-
# ── Hook 通知: 提前计算 Plan 关联信息 ──
|
|
14
|
-
ACTIVE_PLAN=$(detect_active_add 2>/dev/null || true)
|
|
15
|
-
if [ -n "$ACTIVE_PLAN" ]; then
|
|
16
|
-
PLAN_KEYWORD="${ACTIVE_PLAN%%::*}"
|
|
17
|
-
PLAN_STATUS="active"
|
|
18
|
-
else
|
|
19
|
-
PLAN_KEYWORD="no-active-plan"
|
|
20
|
-
PLAN_STATUS="none"
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
|
-
input=$(parse_input)
|
|
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
|
-
export PROJECT_DIR="$PWD"
|
|
28
|
-
|
|
29
|
-
# ── ① Bash matcher: 危险命令拦截 + 终端写文件拦截 ──
|
|
30
|
-
if [ "$tool_name" = "Bash" ]; then
|
|
31
|
-
cmd=$(echo "$input" | grep -o '"command"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
32
|
-
# 危险命令
|
|
33
|
-
if echo "$cmd" | grep -qiE 'rm[[:space:]]+-rf[[:space:]]+/|DROP[[:space:]]+TABLE|git[[:space:]]+push[[:space:]]+--force|mkfs\.|dd[[:space:]]+if='; then
|
|
34
|
-
echo "⛔ 危险命令已被阻止: $cmd" >&2
|
|
35
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "危险命令已被阻止" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
36
|
-
exit $EXIT_BLOCK
|
|
37
|
-
fi
|
|
38
|
-
# 终端写文件拦截(含 > / >> / << heredoc / mv / touch / python -c > file)
|
|
39
|
-
if echo "$cmd" | grep -qE '(cat|echo|tee|sed[[:space:]]+-i|awk|printf|cp|mv|dd|touch)[[:space:]]*.*([>]{1,2}|[|][[:space:]]*tee|<<)'; then
|
|
40
|
-
echo "⛔ 禁止通过终端命令直接写文件: $cmd。请使用 Write/Edit/SearchReplace 工具。" >&2
|
|
41
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过终端直接写文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
42
|
-
exit $EXIT_BLOCK
|
|
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
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过 cp/mv/touch 操作文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
48
|
-
exit $EXIT_BLOCK
|
|
49
|
-
fi
|
|
50
|
-
# python/node/ruby/perl/php 脚本解释器 — 可写任意文件
|
|
51
|
-
if echo "$cmd" | grep -qE '(^|;|\|\||&&|\|)\s*(python3?|node|ruby|perl|php)(\s|$)'; then
|
|
52
|
-
echo "⛔ 禁止通过脚本解释器直接写文件: $cmd。请使用 Write 或 SearchReplace 工具。" >&2
|
|
53
|
-
write_hook_event "pre-tool-use" "deny" "$cmd" "禁止通过脚本解释器直接修改文件" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
54
|
-
exit $EXIT_BLOCK
|
|
55
|
-
fi
|
|
56
|
-
mark_dev_action
|
|
57
|
-
exit 0
|
|
58
|
-
fi
|
|
59
|
-
|
|
60
|
-
# ── ② Write/Edit matcher: 文件写入前置守卫 ──
|
|
61
|
-
if [ "$tool_name" = "Write" ] || [ "$tool_name" = "Edit" ] || [ "$tool_name" = "SearchReplace" ]; then
|
|
62
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
63
|
-
[ -z "$file_path" ] && exit 0
|
|
64
|
-
|
|
65
|
-
# 检查是否写入 plans/specs/reviews 目录但无活跃 ADD Plan
|
|
66
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode)/(plans|specs|reviews)/'; then
|
|
67
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
68
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
69
|
-
if [ -z "$state" ]; then
|
|
70
|
-
echo "[ADD 提示] 正在写入 Plan/Spec/Review 文档但无活跃 ADD Plan——首次创建场景放行,建议先执行 add-paradigm 生成 Plan+add-route" >&2
|
|
71
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"allow\",\"permissionDecisionReason\":\"无活跃 ADD Plan 但为 Plan/Spec/Review 写入(首次创建场景),提示而非拦截\"}}"
|
|
72
|
-
write_hook_event "pre-tool-use" "info" "$file_path" "无活跃 ADD Plan 下写入 Plan/Spec/Review(首次创建放行)" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
73
|
-
exit $EXIT_BLOCK
|
|
74
|
-
fi
|
|
75
|
-
fi
|
|
76
|
-
fi
|
|
77
|
-
|
|
78
|
-
# 敏感文件保护
|
|
79
|
-
if echo "$file_path" | grep -qE '\.env$|\.env\.production$|\.env\.local$|credentials|secrets'; then
|
|
80
|
-
echo "⛔ 敏感文件受保护,禁止写入: $file_path" >&2
|
|
81
|
-
write_hook_event "pre-tool-use" "deny" "$file_path" "敏感文件受保护" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
82
|
-
exit $EXIT_BLOCK
|
|
83
|
-
fi
|
|
84
|
-
|
|
85
|
-
# 模板类型前置注入 — plans/ 写入前提示应选模板
|
|
86
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(plans)/'; then
|
|
87
|
-
fname=$(basename "$file_path")
|
|
88
|
-
if echo "$fname" | grep -qE 'plan-v[0-9]'; then
|
|
89
|
-
echo "💡 [ADD PreToolUse] 写入 Plan → 模板: standard-plan-template.md(标准)或 simple-plan-template.md(≤3文件)" >&2
|
|
90
|
-
elif echo "$fname" | grep -qE 'add-route'; then
|
|
91
|
-
echo "💡 [ADD PreToolUse] 写入 ADD Route → 模板: add-route-template.md" >&2
|
|
92
|
-
elif echo "$fname" | grep -qE 'handoff'; then
|
|
93
|
-
echo "💡 [ADD PreToolUse] 写入 Handoff → 模板: handoff-single-round-template.md(单轮)或 handoff-multi-round-template.md(多轮)" >&2
|
|
94
|
-
fi
|
|
95
|
-
# Write 大文件适配 — 已存在大文件建议用 SearchReplace 分块
|
|
96
|
-
if echo "$tool_name" | grep -qE 'Write' && [ -f "$file_path" ]; then
|
|
97
|
-
fsize=$(wc -c < "$file_path" 2>/dev/null || echo "0")
|
|
98
|
-
if [ "$fsize" -gt 2000 ] 2>/dev/null; then
|
|
99
|
-
echo "⚠️ [ADD PreToolUse] 文件已有 ${fsize} 字节,Write 全量覆盖可能触发工具 payload 限制。建议用 SearchReplace 分块追加。" >&2
|
|
100
|
-
fi
|
|
101
|
-
fi
|
|
102
|
-
fi
|
|
103
|
-
|
|
104
|
-
# §C: HITL tongyi 检查 — plans/ + PLAN_REVIEW reviews/ 写入前必须有 .hitl-tongyi-{planName} 哨兵
|
|
105
|
-
# implementation/runtime review 不需要 HITL,走 §B 活跃 Plan 检查
|
|
106
|
-
# handoff 是 Step 8 收敛产物(多轮交接手册),不经 HITL 审批,同样豁免
|
|
107
|
-
if echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(plans)/'; then
|
|
108
|
-
if echo "$file_path" | grep -qE '\-handoff'; then
|
|
109
|
-
_do_hitl=false # handoff 不被 HITL 拦截(Step 8 产物,无独立审批)
|
|
110
|
-
else
|
|
111
|
-
_do_hitl=true
|
|
112
|
-
fi
|
|
113
|
-
elif echo "$file_path" | grep -qE '\.(qoder|claude|add|vscode|trae)/(reviews)/'; then
|
|
114
|
-
if echo "$file_path" | grep -qE '-(implementation|runtime)'; then
|
|
115
|
-
_do_hitl=false # implementation/runtime review 不被 HITL 拦截
|
|
116
|
-
else
|
|
117
|
-
_do_hitl=true # PLAN_REVIEW 需要 HITL
|
|
118
|
-
fi
|
|
119
|
-
else
|
|
120
|
-
_do_hitl=false
|
|
121
|
-
fi
|
|
122
|
-
|
|
123
|
-
if [ "$_do_hitl" = true ]; then
|
|
124
|
-
_relative=$(echo "$file_path" | sed 's|.*/\.\(qoder\|claude\|add\|vscode\|trae\)/\(plans\|reviews\)/||')
|
|
125
|
-
_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$//')
|
|
126
|
-
if [ -n "$_planName" ]; then
|
|
127
|
-
_tongyi_marker="${PROJECT_DIR}/${MAGIC_DIR}/hitl/.tongyi-${_planName}"
|
|
128
|
-
if [ ! -f "$_tongyi_marker" ]; then
|
|
129
|
-
echo "⛔ [ADD PreToolUse §C] HITL 未 tongyi: $file_path" >&2
|
|
130
|
-
echo " 原因: 哨兵文件 $_tongyi_marker 不存在" >&2
|
|
131
|
-
echo " 操作: 请先调用 create_hitl 创建审批,再 update_hitl({ status: \"TONGYI\" })" >&2
|
|
132
|
-
_reason="HITL 未 tongyi: 哨兵 ${_tongyi_marker} 不存在。请先 create_hitl → 人工 tongyi → update_hitl 后再写入"
|
|
133
|
-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"${_reason}\",\"additionalContext\":\"${_reason}\"}}"
|
|
134
|
-
write_hook_event "pre-tool-use" "deny" "$file_path" "HITL 未 tongyi: $_tongyi_marker" "$PLAN_KEYWORD" "$PLAN_STATUS" 2>/dev/null || true
|
|
135
|
-
exit 0
|
|
136
|
-
fi
|
|
137
|
-
fi
|
|
138
|
-
fi
|
|
139
|
-
|
|
140
|
-
mark_dev_action
|
|
141
|
-
exit 0
|
|
142
|
-
fi
|
|
143
|
-
|
|
144
|
-
# ── ③ Read matcher: 模板路径兜底 ──
|
|
145
|
-
if [ "$tool_name" = "Read" ]; then
|
|
146
|
-
file_path=$(echo "$input" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
147
|
-
if echo "$file_path" | grep -q 'templates/'; then
|
|
148
|
-
echo "[ADD PreToolUse] 提示: 模板文件已通过 hook 预读到上下文,可跳过重复读取" >&2
|
|
149
|
-
fi
|
|
150
|
-
exit 0
|
|
151
|
-
fi
|
|
152
|
-
|
|
153
|
-
exit 0
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# UserPromptSubmit — 触发词路由 + 模板全文注入(VS Code Copilot 适配)
|
|
3
|
-
# 治理卡位 #3: Layer 1 精准触发 → Layer 2 阻断 → Layer 3 状态注入
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
8
|
-
|
|
9
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
10
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
11
|
-
[ -f "$HOOK_DIR/lib/notify.sh" ] && source "$HOOK_DIR/lib/notify.sh" 2>/dev/null || true
|
|
12
|
-
[ -f "$HOOK_DIR/lib/vocabulary.sh" ] && source "$HOOK_DIR/lib/vocabulary.sh" 2>/dev/null || true
|
|
13
|
-
|
|
14
|
-
export PROJECT_DIR="$PWD"
|
|
15
|
-
|
|
16
|
-
input=$(parse_input)
|
|
17
|
-
prompt=$(echo "$input" | grep -o '"prompt"[[:space:]]*:[[:space:]]*"[^"]*"' 2>/dev/null | sed 's/.*: *"\([^"]*\)".*/\1/' || echo "")
|
|
18
|
-
[ -z "$prompt" ] && exit 0
|
|
19
|
-
|
|
20
|
-
# ─── Layer 1: 精准触发词路由 + 验收幂等保护 ───
|
|
21
|
-
matched=$(match_trigger "$prompt")
|
|
22
|
-
if [ -n "$matched" ]; then
|
|
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
|
-
cat <<EOF
|
|
30
|
-
[ADD 验收] ⚠️ 已验收。进入 Review 模式:
|
|
31
|
-
① 重新检查 checklist [T]/[R] 项
|
|
32
|
-
② 审查 audit 记录完整性
|
|
33
|
-
③ 如有差异 → Review 回流至 handoff(增量更新)
|
|
34
|
-
④ 无差异 → 记录 'Review 已确认,无新发现'
|
|
35
|
-
EOF
|
|
36
|
-
exit 0
|
|
37
|
-
fi
|
|
38
|
-
fi
|
|
39
|
-
fi
|
|
40
|
-
echo "$matched"
|
|
41
|
-
exit 0
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
# ─── 开发关键词检测(从词汇表动态加载) ───
|
|
45
|
-
dev_kw=$(load_dev_keywords 2>/dev/null || true)
|
|
46
|
-
if [ -z "$dev_kw" ]; then
|
|
47
|
-
exit 0
|
|
48
|
-
fi
|
|
49
|
-
|
|
50
|
-
if ! echo "$prompt" | grep -qiE "$dev_kw"; then
|
|
51
|
-
exit 0
|
|
52
|
-
fi
|
|
53
|
-
|
|
54
|
-
echo "[ADD PromptSubmit] 检测到开发关键词" >&2
|
|
55
|
-
|
|
56
|
-
# ─── Layer 2: 无活跃 ADD → 提示(不阻断) ───
|
|
57
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
58
|
-
if [ -z "$state" ]; then
|
|
59
|
-
cat <<'EOF'
|
|
60
|
-
[ADD 提示] 检测到开发任务,但无活跃 ADD Plan。建议先执行 add-paradigm SKILL:
|
|
61
|
-
Step 0: 文档先行 (Plan → Review → Specs)
|
|
62
|
-
Step 3: 代码实现 + 审计植入
|
|
63
|
-
Step 8: 收敛判断
|
|
64
|
-
EOF
|
|
65
|
-
write_hook_event "prompt-submit" "info" "$prompt" "无活跃 ADD Plan 下检测到开发任务" "no-active-plan" "none" 2>/dev/null || true
|
|
66
|
-
exit 0
|
|
67
|
-
fi
|
|
68
|
-
|
|
69
|
-
# ─── Layer 3: 有活跃 ADD → 注入状态 + 模板全文 ───
|
|
70
|
-
IFS='::' read -r plan step rounds handoff add_route <<< "$state"
|
|
71
|
-
cat <<EOF
|
|
72
|
-
[ADD 当前状态]
|
|
73
|
-
Plan: ${plan}
|
|
74
|
-
轮次: ${rounds}
|
|
75
|
-
当前 Step: ${step}
|
|
76
|
-
handoff: ${handoff}
|
|
77
|
-
EOF
|
|
78
|
-
|
|
79
|
-
# ─── Hook 治理日报(注入 AI 上下文)───
|
|
80
|
-
HOOK_JSONL="${MAGIC_DIR}/reports/hook-events.jsonl"
|
|
81
|
-
if [ -f "$HOOK_JSONL" ]; then
|
|
82
|
-
TODAY="$(date +%Y-%m-%d)"
|
|
83
|
-
TOTAL=$(grep -c "\"ts\":\"${TODAY}" "$HOOK_JSONL" 2>/dev/null || echo 0)
|
|
84
|
-
NO_PLAN=$(grep "\"ts\":\"${TODAY}" "$HOOK_JSONL" 2>/dev/null | grep -c '"planKeyword":"no-active-plan"' || echo 0)
|
|
85
|
-
if [ "$TOTAL" -gt 0 ] 2>/dev/null; then
|
|
86
|
-
echo "[Hook 治理] 今日提示: ${TOTAL} 次 | 无 Plan 提示: ${NO_PLAN} 次"
|
|
87
|
-
if [ "$NO_PLAN" -ge 10 ] 2>/dev/null; then
|
|
88
|
-
echo "[Hook ⚠️] 无 Plan 提示已达 ${NO_PLAN} 次(≥10),建议创建 Plan"
|
|
89
|
-
fi
|
|
90
|
-
fi
|
|
91
|
-
fi
|
|
92
|
-
|
|
93
|
-
# 模板全文注入(tpl-injected 去重)
|
|
94
|
-
TPL_SCRIPT="$HOOK_DIR/lib/preload-templates.sh"
|
|
95
|
-
if [ -f "$TPL_SCRIPT" ]; then
|
|
96
|
-
bash "$TPL_SCRIPT" --full --top 5
|
|
97
|
-
fi
|
|
98
|
-
|
|
99
|
-
exit 0
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# review-checklist.sh — Review 检查清单校验(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 ReviewChecklist] 请在提交前确认 checklist.md 全部项已勾选。"
|
|
10
|
-
exit 0
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# SessionEnd — VS Code Copilot 适配(薄包装)
|
|
3
|
-
# 治理卡位 #2: 标记清理 + 会话审计结算 + Stop未触发兜底
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
export PROJECT_DIR="$PWD"
|
|
8
|
-
|
|
9
|
-
# source 共享版本并自动执行 main()
|
|
10
|
-
SHARED="$HOOK_DIR/lib/session-end.sh"
|
|
11
|
-
if [ -f "$SHARED" ]; then
|
|
12
|
-
source "$SHARED"
|
|
13
|
-
fi
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# SessionStart — ADD 上下文恢复 + 模板索引注入(VS Code Copilot 适配)
|
|
3
|
-
# 治理卡位 #1: ADD状态恢复 + 模板索引注入
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
8
|
-
|
|
9
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
10
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
11
|
-
|
|
12
|
-
# VS Code Copilot 运行 hook 时 cwd=项目根
|
|
13
|
-
export PROJECT_DIR="$PWD"
|
|
14
|
-
|
|
15
|
-
# ── ① ADD 状态恢复 ──
|
|
16
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
17
|
-
if [ -n "$state" ]; then
|
|
18
|
-
IFS='::' read -r plan step rounds handoff add_route <<< "$state"
|
|
19
|
-
cat <<EOF
|
|
20
|
-
[ADD SessionStart] 检测到活跃 ADD Plan:
|
|
21
|
-
Plan: ${plan}
|
|
22
|
-
轮次: ${rounds}
|
|
23
|
-
当前 Step: ${step}
|
|
24
|
-
handoff: ${handoff}
|
|
25
|
-
恢复命令: query_audit_logs({ planKeyword: '${plan}' })
|
|
26
|
-
EOF
|
|
27
|
-
fi
|
|
28
|
-
|
|
29
|
-
# ── ② 模板索引注入 ──
|
|
30
|
-
TPL_SCRIPT="$HOOK_DIR/lib/preload-templates.sh"
|
|
31
|
-
if [ -f "$TPL_SCRIPT" ]; then
|
|
32
|
-
bash "$TPL_SCRIPT" --index
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
exit 0
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 17:05:03
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 17:05:06
|
|
7
|
-
# @FilePath : /add-coder/templates/adapters/vscode/hooks/stop-check.sh
|
|
8
|
-
# @Description :
|
|
9
|
-
###
|
|
10
|
-
# stop-check.sh — VS Code Copilot Stop:四象限分流 + 验收检查
|
|
11
|
-
# 治理卡位 #7: 验收检查 + devlog + 阻断
|
|
12
|
-
# DB lifecycle 真相源(协议层):DB 不可用时 fail-closed,禁止回退 Handoff/add-route 猜测
|
|
13
|
-
set -euo pipefail
|
|
14
|
-
|
|
15
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
16
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
17
|
-
export MAGIC_DIR=$(basename "$(dirname "$HOOK_DIR")")
|
|
18
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
19
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
20
|
-
|
|
21
|
-
export PROJECT_DIR="$PWD"
|
|
22
|
-
|
|
23
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
24
|
-
has_dev=$(has_dev_action 2>/dev/null && echo "true" || echo "false")
|
|
25
|
-
|
|
26
|
-
# ═══════ Q0: DB 不可用 → fail closed(禁止当“无 Plan”) ═══════
|
|
27
|
-
if [ "${state%%::*}" = "__STATUS_UNAVAILABLE__" ]; then
|
|
28
|
-
reason=$(echo "$state" | awk -F'::' '{print $2}')
|
|
29
|
-
echo "[ADD Stop] ⛔ Plan status 暂不可用(${reason})。未回退 Handoff/add-route 猜测,请恢复数据库或 MCP resolver 后重试。" >&2
|
|
30
|
-
exit "${EXIT_BLOCK:-2}"
|
|
31
|
-
fi
|
|
32
|
-
|
|
33
|
-
# ═══════ Q1: 无 ADD + 无 dev → 正常停 ═══════
|
|
34
|
-
if [ -z "$state" ] && [ "$has_dev" != "true" ]; then
|
|
35
|
-
exit 0
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
# ═══════ Q2: 无 ADD + 有 dev → 严重违规,few-shot 注入 ═══════
|
|
39
|
-
if [ -z "$state" ] && [ "$has_dev" = "true" ]; then
|
|
40
|
-
build_stop_context "no_add_has_dev" >&2
|
|
41
|
-
exit $EXIT_BLOCK
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
IFS='::' read -r plan step rounds handoff add_route <<< "$state"
|
|
45
|
-
|
|
46
|
-
# ═══════ Q3: 有 ADD + 无 dev → 注入状态 ═══════
|
|
47
|
-
if [ "$has_dev" != "true" ]; then
|
|
48
|
-
echo "[ADD Stop] Plan: ${plan}, 轮次: ${rounds}, Step: ${step}"
|
|
49
|
-
echo "本次无代码改动。下次继续时执行 session-init 恢复上下文。"
|
|
50
|
-
exit 0
|
|
51
|
-
fi
|
|
52
|
-
|
|
53
|
-
# ═══════ Q4: 有 ADD + 有 dev → 验收检查 ═══════
|
|
54
|
-
issues=$(check_add_completeness "$handoff" "$add_route" 2>/dev/null || true)
|
|
55
|
-
if [ -n "$issues" ]; then
|
|
56
|
-
build_stop_context "has_add_dev_unclosed" "$issues" >&2
|
|
57
|
-
exit $EXIT_BLOCK
|
|
58
|
-
fi
|
|
59
|
-
|
|
60
|
-
clear_dev_action 2>/dev/null || true
|
|
61
|
-
echo "[ADD Stop] ✅ 验收通过——checklist 全部勾选,devlog 已记录。"
|
|
62
|
-
exit 0
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
###
|
|
3
|
-
# @Author : xiaomingming wujixmm@gmail.com
|
|
4
|
-
# @Date : 2026-07-17 17:05:26
|
|
5
|
-
# @LastEditors : xiaomingming wujixmm@gmail.com
|
|
6
|
-
# @LastEditTime : 2026-07-17 17:05:29
|
|
7
|
-
# @FilePath : /add-coder/templates/adapters/vscode/hooks/subagent-guard.sh
|
|
8
|
-
# @Description :
|
|
9
|
-
###
|
|
10
|
-
# SubagentStart — 子代理 ADD 上下文注入(VS Code Copilot 适配)
|
|
11
|
-
# 治理卡位 #10: ADD上下文注入子agent + 审计初始化
|
|
12
|
-
set -euo pipefail
|
|
13
|
-
|
|
14
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
15
|
-
export CURRENT_MAGIC=$(basename "$(dirname "$HOOK_DIR")")
|
|
16
|
-
COMMON_LIB="$HOOK_DIR/lib/common.sh"
|
|
17
|
-
[ -f "$COMMON_LIB" ] && source "$COMMON_LIB"
|
|
18
|
-
|
|
19
|
-
export PROJECT_DIR="$PWD"
|
|
20
|
-
|
|
21
|
-
# 获取当前 ADD 状态并注入子 agent
|
|
22
|
-
if type detect_active_add >/dev/null 2>&1; then
|
|
23
|
-
state=$(detect_active_add 2>/dev/null || true)
|
|
24
|
-
if [ -n "$state" ]; then
|
|
25
|
-
IFS='::' read -r plan step rounds handoff add_route <<< "$state"
|
|
26
|
-
cat <<EOF
|
|
27
|
-
[ADD SubagentStart] 子代理上下文注入:
|
|
28
|
-
Plan: ${plan}
|
|
29
|
-
Step: ${step}
|
|
30
|
-
轮次: ${rounds}
|
|
31
|
-
handoff: ${handoff}
|
|
32
|
-
遵循 ADD 规范,完成后请检查 checklist 对应项
|
|
33
|
-
EOF
|
|
34
|
-
fi
|
|
35
|
-
fi
|
|
36
|
-
|
|
37
|
-
exit 0
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# SubagentStop — VS Code Copilot 适配(薄包装)
|
|
3
|
-
# 治理卡位 #11: 子agent边界校验 + 审计聚合 + 阻断
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
HOOK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
7
|
-
export PROJECT_DIR="$PWD"
|
|
8
|
-
|
|
9
|
-
SHARED="$HOOK_DIR/lib/subagent-stop.sh"
|
|
10
|
-
if [ -f "$SHARED" ]; then
|
|
11
|
-
source "$SHARED"
|
|
12
|
-
fi
|