add-coder 0.3.26 → 0.3.28

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