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.
Files changed (262) hide show
  1. package/README.md +252 -150
  2. package/package.json +2 -1
  3. package/templates/.add-coder-src-hash.json +126 -148
  4. package/templates/adapters/claude/hooks/doc-format-guard.ts +32 -0
  5. package/templates/adapters/claude/hooks/lib/claude-env.ts +7 -0
  6. package/templates/adapters/claude/hooks/notification.ts +24 -0
  7. package/templates/adapters/claude/hooks/permission-denied.ts +33 -0
  8. package/templates/adapters/claude/hooks/permission-gate.ts +12 -0
  9. package/templates/adapters/claude/hooks/post-tool-failure.ts +4 -0
  10. package/templates/adapters/claude/hooks/post-tool-use.ts +17 -0
  11. package/templates/adapters/claude/hooks/pre-compact.ts +10 -0
  12. package/templates/adapters/claude/hooks/pre-tool-use.ts +81 -0
  13. package/templates/adapters/claude/hooks/prompt-submit.ts +82 -0
  14. package/templates/adapters/claude/hooks/review-checklist.ts +4 -0
  15. package/templates/adapters/claude/hooks/session-end.ts +10 -0
  16. package/templates/adapters/claude/hooks/session-start.ts +24 -0
  17. package/templates/adapters/claude/hooks/stop-check.ts +15 -0
  18. package/templates/adapters/claude/hooks/stop-failure.ts +34 -0
  19. package/templates/adapters/claude/hooks/subagent-guard.ts +25 -0
  20. package/templates/adapters/claude/hooks/subagent-stop.ts +12 -0
  21. package/templates/adapters/claude/settings.json +13 -13
  22. package/templates/adapters/codex/hooks/doc-format-guard.ts +30 -0
  23. package/templates/adapters/codex/hooks/notification.ts +26 -0
  24. package/templates/adapters/codex/hooks/permission-gate.ts +15 -0
  25. package/templates/adapters/codex/hooks/post-tool-failure.ts +14 -0
  26. package/templates/adapters/codex/hooks/post-tool-use.ts +85 -0
  27. package/templates/adapters/codex/hooks/pre-compact.ts +20 -0
  28. package/templates/adapters/codex/hooks/pre-tool-use.ts +141 -0
  29. package/templates/adapters/codex/hooks/prompt-submit.ts +38 -0
  30. package/templates/adapters/codex/hooks/review-checklist.ts +5 -0
  31. package/templates/adapters/codex/hooks/session-end.ts +19 -0
  32. package/templates/adapters/codex/hooks/session-start.ts +45 -0
  33. package/templates/adapters/codex/hooks/stop-check.ts +59 -0
  34. package/templates/adapters/codex/hooks/subagent-guard.ts +22 -0
  35. package/templates/adapters/codex/hooks/subagent-stop.ts +20 -0
  36. package/templates/adapters/codex/hooks.json +5 -5
  37. package/templates/adapters/qoder/hooks/doc-format-guard.ts +34 -0
  38. package/templates/adapters/qoder/hooks/lib/context-inject.ts +61 -0
  39. package/templates/adapters/qoder/hooks/lib/qoder-env.ts +23 -0
  40. package/templates/adapters/qoder/hooks/lib/review-checklist.ts +5 -0
  41. package/templates/adapters/qoder/hooks/notification.ts +34 -0
  42. package/templates/adapters/qoder/hooks/permission-gate.ts +26 -0
  43. package/templates/adapters/qoder/hooks/post-tool-failure.ts +30 -0
  44. package/templates/adapters/qoder/hooks/post-tool-use.ts +32 -0
  45. package/templates/adapters/qoder/hooks/pre-compact.ts +16 -0
  46. package/templates/adapters/qoder/hooks/pre-tool-use.ts +112 -0
  47. package/templates/adapters/qoder/hooks/prompt-submit.ts +66 -0
  48. package/templates/adapters/qoder/hooks/review-checklist.ts +24 -0
  49. package/templates/adapters/qoder/hooks/session-end.ts +27 -0
  50. package/templates/adapters/qoder/hooks/session-start.ts +83 -0
  51. package/templates/adapters/qoder/hooks/stop-check.ts +69 -0
  52. package/templates/adapters/qoder/hooks/subagent-guard.ts +16 -0
  53. package/templates/adapters/qoder/hooks/subagent-stop.ts +33 -0
  54. package/templates/adapters/qoder/settings.json +13 -13
  55. package/templates/adapters/trae/hooks/doc-format-guard.ts +30 -0
  56. package/templates/adapters/trae/hooks/notification.ts +22 -0
  57. package/templates/adapters/trae/hooks/permission-gate.ts +15 -0
  58. package/templates/adapters/trae/hooks/post-tool-failure.ts +14 -0
  59. package/templates/adapters/trae/hooks/post-tool-use.ts +24 -0
  60. package/templates/adapters/trae/hooks/pre-compact.ts +15 -0
  61. package/templates/adapters/trae/hooks/pre-tool-use.ts +40 -0
  62. package/templates/adapters/trae/hooks/prompt-submit.ts +29 -0
  63. package/templates/adapters/trae/hooks/review-checklist.ts +5 -0
  64. package/templates/adapters/trae/hooks/session-end.ts +16 -0
  65. package/templates/adapters/trae/hooks/session-start.ts +15 -0
  66. package/templates/adapters/trae/hooks/stop-check.ts +20 -0
  67. package/templates/adapters/trae/hooks/subagent-guard.ts +22 -0
  68. package/templates/adapters/trae/hooks/subagent-stop.ts +15 -0
  69. package/templates/adapters/trae/hooks.json +1 -1
  70. package/templates/adapters/vscode/hooks/doc-format-guard.ts +27 -0
  71. package/templates/adapters/vscode/hooks/notification.ts +22 -0
  72. package/templates/adapters/vscode/hooks/permission-gate.ts +15 -0
  73. package/templates/adapters/vscode/hooks/post-tool-failure.ts +32 -0
  74. package/templates/adapters/vscode/hooks/post-tool-use.ts +25 -0
  75. package/templates/adapters/vscode/hooks/pre-compact.ts +15 -0
  76. package/templates/adapters/vscode/hooks/pre-tool-use.ts +78 -0
  77. package/templates/adapters/vscode/hooks/prompt-submit.ts +74 -0
  78. package/templates/adapters/vscode/hooks/review-checklist.ts +5 -0
  79. package/templates/adapters/vscode/hooks/session-end.ts +16 -0
  80. package/templates/adapters/vscode/hooks/session-start.ts +24 -0
  81. package/templates/adapters/vscode/hooks/stop-check.ts +21 -0
  82. package/templates/adapters/vscode/hooks/subagent-guard.ts +21 -0
  83. package/templates/adapters/vscode/hooks/subagent-stop.ts +15 -0
  84. package/templates/core/docs/ADD-governance-claude-code.md +3 -3
  85. package/templates/core/docs/ADD-governance-codex.md +5 -5
  86. package/templates/core/docs/ADD-governance-qoder-cn.md +4 -4
  87. package/templates/core/docs/ADD-governance-trae.md +2 -2
  88. package/templates/core/docs/ADD-governance-vscode-copilot.md +21 -22
  89. package/templates/core/governance/audit-bridge.ts +47 -0
  90. package/templates/core/governance/common.ts +299 -0
  91. package/templates/core/governance/context-inject.ts +53 -0
  92. package/templates/core/governance/doc-format-guard.ts +440 -0
  93. package/templates/core/governance/notification-router.ts +62 -0
  94. package/templates/core/governance/notify.ts +66 -0
  95. package/templates/core/governance/permission-gate-router.ts +42 -0
  96. package/templates/core/governance/post-tool-failure-router.ts +56 -0
  97. package/templates/core/governance/post-tool-router.ts +212 -0
  98. package/templates/core/governance/pre-compact-guard.ts +41 -0
  99. package/templates/core/governance/pre-tool-guard.ts +309 -0
  100. package/templates/core/governance/preload-templates.ts +241 -0
  101. package/templates/core/governance/prompt-router.ts +222 -0
  102. package/templates/core/governance/review-checklist-guard.ts +186 -0
  103. package/templates/core/governance/rules.ts +720 -0
  104. package/templates/core/governance/session-end.ts +88 -0
  105. package/templates/core/governance/session-start-guard.ts +99 -0
  106. package/templates/core/governance/state-detect.ts +6 -0
  107. package/templates/core/governance/stop-router.ts +140 -0
  108. package/templates/core/governance/subagent-guard-router.ts +35 -0
  109. package/templates/core/governance/subagent-stop-router.ts +93 -0
  110. package/templates/core/governance/subagent-stop.ts +75 -0
  111. package/templates/core/governance/vocabulary.ts +109 -0
  112. package/templates/core/hooks/doc-format-guard.ts +21 -0
  113. package/templates/core/hooks/notification.ts +11 -0
  114. package/templates/core/hooks/permission-gate.ts +7 -0
  115. package/templates/core/hooks/post-tool-failure.ts +7 -0
  116. package/templates/core/hooks/post-tool-use.ts +23 -0
  117. package/templates/core/hooks/pre-compact.ts +9 -0
  118. package/templates/core/hooks/pre-tool-use.ts +30 -0
  119. package/templates/core/hooks/prompt-submit.ts +11 -0
  120. package/templates/core/hooks/review-checklist.ts +4 -0
  121. package/templates/core/hooks/session-end.ts +10 -0
  122. package/templates/core/hooks/session-start.ts +9 -0
  123. package/templates/core/hooks/stop-check.ts +14 -0
  124. package/templates/core/hooks/subagent-guard.ts +8 -0
  125. package/templates/core/hooks/subagent-stop.ts +9 -0
  126. package/templates/core/scripts/mcp-server/tools/gateway/check_rahs.ts +12 -1
  127. package/templates/core/scripts/mcp-server/tools/plan.ts +12 -2
  128. package/templates/adapters/claude/hooks/doc-format-guard.sh +0 -283
  129. package/templates/adapters/claude/hooks/lib/common.sh +0 -220
  130. package/templates/adapters/claude/hooks/lib/context-inject.sh +0 -96
  131. package/templates/adapters/claude/hooks/lib/notify.sh +0 -36
  132. package/templates/adapters/claude/hooks/lib/preload-templates.sh +0 -212
  133. package/templates/adapters/claude/hooks/lib/session-end.sh +0 -76
  134. package/templates/adapters/claude/hooks/lib/state-detect.sh +0 -13
  135. package/templates/adapters/claude/hooks/lib/subagent-stop.sh +0 -90
  136. package/templates/adapters/claude/hooks/lib/vocabulary.sh +0 -62
  137. package/templates/adapters/claude/hooks/notification.sh +0 -45
  138. package/templates/adapters/claude/hooks/permission-denied.sh +0 -42
  139. package/templates/adapters/claude/hooks/permission-gate.sh +0 -18
  140. package/templates/adapters/claude/hooks/post-tool-failure.sh +0 -10
  141. package/templates/adapters/claude/hooks/post-tool-use.sh +0 -35
  142. package/templates/adapters/claude/hooks/pre-compact.sh +0 -37
  143. package/templates/adapters/claude/hooks/pre-tool-use.sh +0 -153
  144. package/templates/adapters/claude/hooks/prompt-submit.sh +0 -99
  145. package/templates/adapters/claude/hooks/review-checklist.sh +0 -10
  146. package/templates/adapters/claude/hooks/session-end.sh +0 -21
  147. package/templates/adapters/claude/hooks/session-start.sh +0 -36
  148. package/templates/adapters/claude/hooks/stop-check.sh +0 -54
  149. package/templates/adapters/claude/hooks/stop-failure.sh +0 -44
  150. package/templates/adapters/claude/hooks/subagent-guard.sh +0 -36
  151. package/templates/adapters/claude/hooks/subagent-stop.sh +0 -20
  152. package/templates/adapters/codex/hooks/doc-format-guard.sh +0 -343
  153. package/templates/adapters/codex/hooks/lib/common.sh +0 -209
  154. package/templates/adapters/codex/hooks/lib/context-inject.sh +0 -96
  155. package/templates/adapters/codex/hooks/lib/notify.sh +0 -36
  156. package/templates/adapters/codex/hooks/lib/preload-templates.sh +0 -208
  157. package/templates/adapters/codex/hooks/lib/session-end.sh +0 -76
  158. package/templates/adapters/codex/hooks/lib/state-detect.sh +0 -8
  159. package/templates/adapters/codex/hooks/lib/subagent-stop.sh +0 -90
  160. package/templates/adapters/codex/hooks/lib/vocabulary.sh +0 -51
  161. package/templates/adapters/codex/hooks/notification.sh +0 -30
  162. package/templates/adapters/codex/hooks/permission-gate.sh +0 -18
  163. package/templates/adapters/codex/hooks/post-tool-failure.sh +0 -10
  164. package/templates/adapters/codex/hooks/post-tool-use.sh +0 -43
  165. package/templates/adapters/codex/hooks/pre-compact.sh +0 -37
  166. package/templates/adapters/codex/hooks/pre-tool-use.sh +0 -130
  167. package/templates/adapters/codex/hooks/prompt-submit.sh +0 -92
  168. package/templates/adapters/codex/hooks/review-checklist.sh +0 -10
  169. package/templates/adapters/codex/hooks/session-end.sh +0 -38
  170. package/templates/adapters/codex/hooks/session-start.sh +0 -63
  171. package/templates/adapters/codex/hooks/stop-check.sh +0 -71
  172. package/templates/adapters/codex/hooks/subagent-guard.sh +0 -15
  173. package/templates/adapters/codex/hooks/subagent-stop.sh +0 -47
  174. package/templates/adapters/qoder/hooks/doc-format-guard.sh +0 -341
  175. package/templates/adapters/qoder/hooks/lib/common.sh +0 -223
  176. package/templates/adapters/qoder/hooks/lib/context-inject.sh +0 -96
  177. package/templates/adapters/qoder/hooks/lib/notify.sh +0 -36
  178. package/templates/adapters/qoder/hooks/lib/preload-templates.sh +0 -212
  179. package/templates/adapters/qoder/hooks/lib/session-end.sh +0 -76
  180. package/templates/adapters/qoder/hooks/lib/state-detect.sh +0 -13
  181. package/templates/adapters/qoder/hooks/lib/subagent-stop.sh +0 -90
  182. package/templates/adapters/qoder/hooks/lib/vocabulary.sh +0 -62
  183. package/templates/adapters/qoder/hooks/notification.sh +0 -25
  184. package/templates/adapters/qoder/hooks/permission-gate.sh +0 -8
  185. package/templates/adapters/qoder/hooks/post-tool-failure.sh +0 -8
  186. package/templates/adapters/qoder/hooks/post-tool-use.sh +0 -121
  187. package/templates/adapters/qoder/hooks/pre-compact.sh +0 -37
  188. package/templates/adapters/qoder/hooks/pre-tool-use.sh +0 -154
  189. package/templates/adapters/qoder/hooks/prompt-submit.sh +0 -96
  190. package/templates/adapters/qoder/hooks/review-checklist.sh +0 -157
  191. package/templates/adapters/qoder/hooks/session-end.sh +0 -24
  192. package/templates/adapters/qoder/hooks/session-start.sh +0 -45
  193. package/templates/adapters/qoder/hooks/stop-check.sh +0 -59
  194. package/templates/adapters/qoder/hooks/subagent-guard.sh +0 -27
  195. package/templates/adapters/qoder/hooks/subagent-stop.sh +0 -26
  196. package/templates/adapters/trae/hooks/doc-format-guard.sh +0 -343
  197. package/templates/adapters/trae/hooks/lib/common.sh +0 -220
  198. package/templates/adapters/trae/hooks/lib/context-inject.sh +0 -96
  199. package/templates/adapters/trae/hooks/lib/notify.sh +0 -36
  200. package/templates/adapters/trae/hooks/lib/preload-templates.sh +0 -212
  201. package/templates/adapters/trae/hooks/lib/session-end.sh +0 -76
  202. package/templates/adapters/trae/hooks/lib/state-detect.sh +0 -10
  203. package/templates/adapters/trae/hooks/lib/subagent-stop.sh +0 -90
  204. package/templates/adapters/trae/hooks/lib/vocabulary.sh +0 -62
  205. package/templates/adapters/trae/hooks/notification.sh +0 -45
  206. package/templates/adapters/trae/hooks/permission-gate.sh +0 -18
  207. package/templates/adapters/trae/hooks/post-tool-failure.sh +0 -10
  208. package/templates/adapters/trae/hooks/post-tool-use.sh +0 -138
  209. package/templates/adapters/trae/hooks/pre-compact.sh +0 -37
  210. package/templates/adapters/trae/hooks/pre-tool-use.sh +0 -223
  211. package/templates/adapters/trae/hooks/prompt-submit.sh +0 -87
  212. package/templates/adapters/trae/hooks/review-checklist.sh +0 -10
  213. package/templates/adapters/trae/hooks/session-end.sh +0 -38
  214. package/templates/adapters/trae/hooks/session-start.sh +0 -53
  215. package/templates/adapters/trae/hooks/stop-check.sh +0 -54
  216. package/templates/adapters/trae/hooks/subagent-guard.sh +0 -15
  217. package/templates/adapters/trae/hooks/subagent-stop.sh +0 -47
  218. package/templates/adapters/vscode/hooks/doc-format-guard.sh +0 -282
  219. package/templates/adapters/vscode/hooks/lib/common.sh +0 -220
  220. package/templates/adapters/vscode/hooks/lib/context-inject.sh +0 -96
  221. package/templates/adapters/vscode/hooks/lib/notify.sh +0 -36
  222. package/templates/adapters/vscode/hooks/lib/preload-templates.sh +0 -212
  223. package/templates/adapters/vscode/hooks/lib/session-end.sh +0 -76
  224. package/templates/adapters/vscode/hooks/lib/state-detect.sh +0 -13
  225. package/templates/adapters/vscode/hooks/lib/subagent-stop.sh +0 -90
  226. package/templates/adapters/vscode/hooks/lib/vocabulary.sh +0 -62
  227. package/templates/adapters/vscode/hooks/notification.sh +0 -43
  228. package/templates/adapters/vscode/hooks/permission-gate.sh +0 -18
  229. package/templates/adapters/vscode/hooks/post-tool-failure.sh +0 -28
  230. package/templates/adapters/vscode/hooks/post-tool-use.sh +0 -35
  231. package/templates/adapters/vscode/hooks/pre-compact.sh +0 -37
  232. package/templates/adapters/vscode/hooks/pre-tool-use.sh +0 -153
  233. package/templates/adapters/vscode/hooks/prompt-submit.sh +0 -99
  234. package/templates/adapters/vscode/hooks/review-checklist.sh +0 -10
  235. package/templates/adapters/vscode/hooks/session-end.sh +0 -13
  236. package/templates/adapters/vscode/hooks/session-start.sh +0 -35
  237. package/templates/adapters/vscode/hooks/stop-check.sh +0 -62
  238. package/templates/adapters/vscode/hooks/subagent-guard.sh +0 -37
  239. package/templates/adapters/vscode/hooks/subagent-stop.sh +0 -12
  240. package/templates/core/hooks/doc-format-guard.sh +0 -343
  241. package/templates/core/hooks/lib/common.sh +0 -220
  242. package/templates/core/hooks/lib/context-inject.sh +0 -96
  243. package/templates/core/hooks/lib/notify.sh +0 -36
  244. package/templates/core/hooks/lib/preload-templates.sh +0 -212
  245. package/templates/core/hooks/lib/session-end.sh +0 -76
  246. package/templates/core/hooks/lib/state-detect.sh +0 -10
  247. package/templates/core/hooks/lib/subagent-stop.sh +0 -90
  248. package/templates/core/hooks/lib/vocabulary.sh +0 -62
  249. package/templates/core/hooks/notification.sh +0 -45
  250. package/templates/core/hooks/permission-gate.sh +0 -18
  251. package/templates/core/hooks/post-tool-failure.sh +0 -10
  252. package/templates/core/hooks/post-tool-use.sh +0 -138
  253. package/templates/core/hooks/pre-compact.sh +0 -37
  254. package/templates/core/hooks/pre-tool-use.sh +0 -223
  255. package/templates/core/hooks/prompt-submit.sh +0 -87
  256. package/templates/core/hooks/review-checklist.sh +0 -10
  257. package/templates/core/hooks/session-end.sh +0 -38
  258. package/templates/core/hooks/session-start.sh +0 -53
  259. package/templates/core/hooks/stop-check.sh +0 -54
  260. package/templates/core/hooks/subagent-guard.sh +0 -15
  261. package/templates/core/hooks/subagent-stop.sh +0 -47
  262. package/templates/shared/hooks-lib/common.sh +0 -22
@@ -1,36 +0,0 @@
1
- #!/bin/bash
2
- # notify.sh — Hook 拦截事件写入 jsonl(零外部依赖,bash 原生)
3
- # 用法: source 后在 exit 2 前调用 write_hook_event
4
- #
5
- # 写入格式(7 字段 jsonl):
6
- # {"ts":"ISO8601","hook":"...","decision":"deny","cmd":"...","reason":"...","planKeyword":"...","planStatus":"..."}
7
- #
8
- # 磁盘管理:
9
- # - 单文件 ≤256KB,超限轮转为 .old(覆盖,不累积多份)
10
- # - 总量 ≤512KB(当前 + 一个 .old)
11
- # - MCP Server 宕机不丢事件,重启后从文件恢复消费
12
-
13
- write_hook_event() {
14
- local hook="$1" decision="$2" cmd="$3" reason="$4" plan="${5:-unknown}" status="${6:-none}" extra="${7:-}"
15
- local dir="${MAGIC_DIR:-.qoder}/reports"
16
- mkdir -p "$dir" 2>/dev/null || true
17
- local file="$dir/hook-events.jsonl"
18
-
19
- # 超过 256KB 自动轮转(262144 bytes)
20
- if [ -f "$file" ]; then
21
- local sz
22
- sz=$(stat -c%s "$file" 2>/dev/null || echo 0)
23
- [ "$sz" -gt 262144 ] && mv "$file" "${file}.old" 2>/dev/null || true
24
- fi
25
-
26
- # extra 为可选 JSON 片段(Task 1.5 数据契约:anchor_hit/struct_score/override 等),非空时以逗号拼接
27
- printf '{"ts":"%s","hook":"%s","decision":"%s","cmd":"%s","reason":"%s","planKeyword":"%s","planStatus":"%s"%s}\n' \
28
- "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
29
- "$hook" \
30
- "$decision" \
31
- "$cmd" \
32
- "$reason" \
33
- "$plan" \
34
- "$status" \
35
- "${extra:+,$extra}" >> "$file"
36
- }
@@ -1,212 +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
- # 模板目录(分发期物化到各 adapter 本地:<magicDir>/templates;禁止回指源仓)
25
- # 协议层契约(模板预载): 读 ${magicDir}/templates 本地物化副本;目录/标准模板缺失 fail-fast
26
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
27
- TEMPLATES_DIR="${SCRIPT_DIR}/../../templates"
28
-
29
- # tpl-injected 标记文件路径(项目级,/tmp 下按项目 hash 区分)
30
- PROJECT_HASH=$(echo "${PROJECT_DIR:-$PWD}" | md5sum 2>/dev/null | cut -c1-8 || echo "default")
31
- TPL_FLAG="/tmp/add_tpl_${PROJECT_HASH}"
32
-
33
- # 模板清单(文件名:用途描述,按常用度排序)
34
- # 顺序即 --top N 的优先级
35
- declare -A TEMPLATES=(
36
- ["simple-plan-template.md"]="需求方案(简单版):六节结构,元信息+背景+方案+架构+实施+验收"
37
- ["spec-template.md"]="功能规格:Why/What Changes/Impact/WHEN-THEN Requirements"
38
- ["tasks-template.md"]="任务拆分:Phase→Task→SubTask层级"
39
- ["checklist-template.md"]="验收清单:[T]编译期+[R]运行时+ADD规则合规"
40
- ["review-template.md"]="方案审查(ADD-9):问题复现+方案对比+决策结论+影响评估"
41
- ["standard-plan-template.md"]="需求方案(标准版):PLAN元信息+背景+方案+架构+实施Task+验收+关联文档"
42
- ["add-route-template-heavyweight.md"]="ADD执行路线图(重型):每Step验证并更新状态+spec_sync交叉校验"
43
- ["add-route-template.md"]="ADD执行路线图(轻量):标准Step产出检查"
44
- ["handoff-single-round-template.md"]="单轮交接:9章节(含恢复上下文审计查询)"
45
- ["handoff-multi-round-template.md"]="多轮交接:全局拓扑+每轮13子章节+收敛规则+启动模板"
46
- ["review-implementation-template.md"]="实现审查(ADD-10):格式契约+框架版本+数据模型+E2E curl"
47
- ["review-runtime-template.md"]="运行时纠偏(ADD-11):发现列表+根因分析+流程改进项"
48
- ["prd-standard-template.md"]="产品需求文档(新建):背景目标+用户场景+功能需求+验收标准"
49
- ["prd-incremental-template.md"]="产品需求文档(增量):变更摘要+diff式记录"
50
- ["fix-verification-template.md"]="修复验证模板"
51
- ["report-template.md"]="代码审查报告模板"
52
- ["runtime-report-template.md"]="运行时报告模板"
53
- ["TERMINOLOGY.md"]="模板术语速查"
54
- )
55
-
56
- # 按优先级排序的模板文件名列表
57
- PRIORITY_ORDER=(
58
- "simple-plan-template.md"
59
- "spec-template.md"
60
- "tasks-template.md"
61
- "checklist-template.md"
62
- "review-template.md"
63
- "standard-plan-template.md"
64
- "add-route-template-heavyweight.md"
65
- "add-route-template.md"
66
- "handoff-single-round-template.md"
67
- "handoff-multi-round-template.md"
68
- "review-implementation-template.md"
69
- "review-runtime-template.md"
70
- "prd-standard-template.md"
71
- "prd-incremental-template.md"
72
- "fix-verification-template.md"
73
- "report-template.md"
74
- "runtime-report-template.md"
75
- "TERMINOLOGY.md"
76
- )
77
-
78
- # 读取模板文件内容(strip frontmatter)
79
- read_template_content() {
80
- local file="$1"
81
- if [ -f "$file" ]; then
82
- # 跳过 YAML frontmatter(--- 开头和 --- 结束之间的内容)
83
- awk '
84
- BEGIN { in_fm=0; started=0 }
85
- NR==1 && /^---$/ { in_fm=1; next }
86
- in_fm && /^---$/ { in_fm=0; next }
87
- !in_fm { print }
88
- ' "$file"
89
- fi
90
- }
91
-
92
- # ── 模板目录存在性校验(fail-fast)──
93
-
94
- validate_templates_dir() {
95
- if [ ! -d "$TEMPLATES_DIR" ]; then
96
- echo "[ADD preload] 模板目录不存在: $TEMPLATES_DIR(生成态物化缺失,请执行 add-coder sync 后重试)" >&2
97
- exit 1
98
- fi
99
-
100
- local available=0
101
- local tmpl
102
- for tmpl in "${PRIORITY_ORDER[@]}"; do
103
- if [ -f "$TEMPLATES_DIR/$tmpl" ]; then
104
- available=$((available + 1))
105
- fi
106
- done
107
- if [ "$available" -eq 0 ]; then
108
- echo "[ADD preload] 模板目录中未找到 ADD 标准模板: $TEMPLATES_DIR(缺失清单: ${PRIORITY_ORDER[*]})" >&2
109
- exit 1
110
- fi
111
- }
112
-
113
- # ── --index 模式:输出模板清单 ──
114
-
115
- output_index() {
116
- echo "## ADD 可用模板清单"
117
- echo ""
118
- echo "| # | 模板文件 | 用途 |"
119
- echo "|---|---------|------|"
120
- local i=1
121
- for tmpl in "${PRIORITY_ORDER[@]}"; do
122
- if [ -f "$TEMPLATES_DIR/$tmpl" ]; then
123
- echo "| $i | $tmpl | ${TEMPLATES[$tmpl]:-模板文件} |"
124
- ((i++))
125
- fi
126
- done
127
- }
128
-
129
- # ── --full 模式:输出模板全文 ──
130
-
131
- output_full() {
132
- local top="${1:-0}" # 0 = 全部
133
-
134
- echo "## ADD 模板全文内容"
135
- echo ""
136
-
137
- local count=0
138
- for tmpl in "${PRIORITY_ORDER[@]}"; do
139
- if [ ! -f "$TEMPLATES_DIR/$tmpl" ]; then
140
- continue
141
- fi
142
-
143
- count=$((count + 1))
144
- if [ "$top" -gt 0 ] && [ "$count" -gt "$top" ]; then
145
- break
146
- fi
147
-
148
- echo "---"
149
- echo "### $tmpl"
150
- echo ""
151
- read_template_content "$TEMPLATES_DIR/$tmpl"
152
- echo ""
153
- done
154
- }
155
-
156
- # ── 标记文件管理 ──
157
-
158
- mark_injected() {
159
- touch "$TPL_FLAG" 2>/dev/null || true
160
- }
161
-
162
- is_injected() {
163
- [ -f "$TPL_FLAG" ]
164
- }
165
-
166
- clear_injected() {
167
- rm -f "$TPL_FLAG" 2>/dev/null || true
168
- }
169
-
170
- # ── 主入口 ──
171
-
172
- main() {
173
- local mode="index"
174
- local top=0
175
- local do_mark=false
176
-
177
- while [ $# -gt 0 ]; do
178
- case "$1" in
179
- --index) mode="index"; shift ;;
180
- --full) mode="full"; shift ;;
181
- --top)
182
- top="${2:-0}"
183
- shift 2
184
- ;;
185
- --mark) do_mark=true; shift ;;
186
- *) shift ;;
187
- esac
188
- done
189
-
190
- # 入口校验:目录缺失/标准模板缺失 → fail-fast(不再静默空输出)
191
- validate_templates_dir
192
-
193
- case "$mode" in
194
- index)
195
- output_index
196
- ;;
197
- full)
198
- # 去重检查:如果已注入且没有主动要求重新注入,跳过
199
- if is_injected && ! $do_mark; then
200
- echo "[ADD preload] 模板已在本会话注入,跳过重复注入(tpl-injected 标记存在)" >&2
201
- exit 0
202
- fi
203
-
204
- output_full "$top"
205
-
206
- # 落标记文件
207
- mark_injected
208
- ;;
209
- esac
210
- }
211
-
212
- 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,10 +0,0 @@
1
- #!/bin/bash
2
- # state-detect.sh — 兼容入口;状态裁决统一委托 common.sh,禁止维护第二套 magicDir 探测。
3
- # 协议层契约(Review P1 #5): 仅当前 magicDir scope;禁止跨端扫描与 .add fallback;
4
- # 禁止 adapter 名称默认值(入口注入 MAGIC_DIR 或物理位置推导)。
5
-
6
- if ! type detect_active_add >/dev/null 2>&1; then
7
- HOOK_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
- # shellcheck source=common.sh
9
- source "$HOOK_LIB_DIR/common.sh"
10
- fi
@@ -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,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="$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:-.add}"
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,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