@chongyan/autospec 1.0.1 → 1.0.2

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 (283) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +447 -321
  3. package/README.md +418 -286
  4. package/knowledge/01-principles/00-principles-hierarchy.md +247 -0
  5. package/knowledge/01-principles/01-first-principles.md +241 -0
  6. package/knowledge/01-principles/02-strategic-principles.md +286 -0
  7. package/knowledge/01-principles/03-tactical-principles.md +385 -0
  8. package/knowledge/01-principles/04-operational-principles.md +275 -0
  9. package/knowledge/01-principles/05-domain-principles.md +539 -0
  10. package/knowledge/01-principles/06-methodology-principles.md +281 -0
  11. package/knowledge/01-principles/07-cognitive-principles.md +277 -0
  12. package/knowledge/01-principles/08-auto-fix-principles.md +320 -0
  13. package/knowledge/01-principles/09-constitution.md +220 -0
  14. package/knowledge/{principles/evolution.md → 01-principles/10-evolution-mechanism.md} +160 -14
  15. package/knowledge/01-principles/README.en.md +385 -0
  16. package/knowledge/01-principles/README.md +385 -0
  17. package/knowledge/{process/overview.md → 02-process/00-overview.md} +90 -5
  18. package/knowledge/02-process/README.en.md +143 -0
  19. package/knowledge/02-process/README.md +186 -0
  20. package/knowledge/{guides/support/pipeline-protocol.md → 03-guides/00-pipeline-protocol.md} +10 -10
  21. package/knowledge/{guides/support/team-orchestrator.md → 03-guides/01-team-orchestrator.md} +53 -8
  22. package/knowledge/{guides/stages/requirement-analyzer.md → 03-guides/02-analyze-requirement.md} +3 -3
  23. package/knowledge/{guides/stages/ai-effect-evaluator.md → 03-guides/08-evaluate-ai-effect.md} +14 -7
  24. package/knowledge/{guides/support/skill-distiller.md → 03-guides/19-distill-skill.md} +3 -3
  25. package/knowledge/{guides/support/skill-updater.md → 03-guides/20-update-skill.md} +1 -1
  26. package/knowledge/{guides/support/methodology-extractor.md → 03-guides/22-extract-methodology.md} +2 -2
  27. package/knowledge/{guides/support/complexity-assessor.md → 03-guides/24-assess-complexity.md} +6 -4
  28. package/knowledge/{guides/support/tech-stack-analyzer.md → 03-guides/26-analyze-tech-stack.md} +1 -1
  29. package/knowledge/{guides/domain-driven-design.md → 03-guides/42-apply-ddd.md} +1 -1
  30. package/knowledge/{process/ai-sdlc.md → 03-guides/43-run-ai-sdlc.md} +1 -1
  31. package/knowledge/{guides/knowledge-management.md → 03-guides/44-manage-knowledge.md} +4 -4
  32. package/knowledge/03-guides/README.en.md +212 -0
  33. package/knowledge/03-guides/README.md +212 -0
  34. package/knowledge/{checklists/requirement.md → 04-checklists/00-requirement.md} +1 -1
  35. package/knowledge/{checklists/design.md → 04-checklists/01-design.md} +1 -1
  36. package/knowledge/{checklists/code.md → 04-checklists/02-code.md} +16 -1
  37. package/knowledge/{checklists/release.md → 04-checklists/04-release.md} +1 -1
  38. package/knowledge/04-checklists/README.en.md +119 -0
  39. package/knowledge/04-checklists/README.md +123 -0
  40. package/knowledge/{config/validation-patterns.yaml → 05-config/00-validation-patterns.yaml} +1 -1
  41. package/knowledge/{config/team-tasks.yaml → 05-config/02-team-tasks.yaml} +2 -2
  42. package/knowledge/05-config/03-role-composition.yaml +346 -0
  43. package/knowledge/{config/skill-compositions.yaml → 05-config/05-skill-compositions.yaml} +24 -24
  44. package/knowledge/05-config/README.en.md +54 -0
  45. package/knowledge/05-config/README.md +132 -0
  46. package/knowledge/06-environment/00-template-registry.md +310 -0
  47. package/knowledge/06-environment/01-detection-patterns.yaml +1692 -0
  48. package/knowledge/{environment → 06-environment}/README.en.md +4 -0
  49. package/knowledge/{environment → 06-environment}/README.md +66 -25
  50. package/knowledge/{standards/coding-style.md → 07-standards/00-coding-style.md} +123 -4
  51. package/knowledge/{standards/code-review.md → 07-standards/01-code-review.md} +3 -3
  52. package/knowledge/{standards/data-consistency.md → 07-standards/02-data-consistency.md} +1 -1
  53. package/knowledge/{standards/document-versioning.md → 07-standards/03-document-versioning.md} +1 -1
  54. package/knowledge/{standards/risk-detection.md → 07-standards/04-risk-detection.md} +5 -5
  55. package/knowledge/07-standards/README.en.md +119 -0
  56. package/knowledge/07-standards/README.md +123 -0
  57. package/knowledge/08-organization/00-vision-mission.md +113 -0
  58. package/knowledge/{organization/ai-native-team.md → 08-organization/01-ai-native-culture.md} +1 -1
  59. package/knowledge/{organization/team-metrics.md → 08-organization/02-team-metrics.md} +1 -1
  60. package/knowledge/08-organization/03-committee-structure.md +54 -0
  61. package/knowledge/08-organization/04-governance-metrics.md +55 -0
  62. package/knowledge/08-organization/05-improvement-process.md +71 -0
  63. package/knowledge/08-organization/README.en.md +165 -0
  64. package/knowledge/08-organization/README.md +165 -0
  65. package/knowledge/09-templates/00-requirement-proposal.md +344 -0
  66. package/knowledge/09-templates/01-architecture-design.md +494 -0
  67. package/knowledge/09-templates/02-api-design.md +408 -0
  68. package/knowledge/09-templates/03-database-design.md +313 -0
  69. package/knowledge/09-templates/04-product-design.md +237 -0
  70. package/knowledge/09-templates/05-domain-business.md +388 -0
  71. package/knowledge/09-templates/06-test-design.md +268 -0
  72. package/knowledge/09-templates/07-evaluation-design.md +372 -0
  73. package/knowledge/09-templates/08-component-knowledge.md +272 -0
  74. package/knowledge/09-templates/09-best-practices.md +218 -0
  75. package/knowledge/{environment/middleware-knowledge.md → 09-templates/10-middleware-knowledge.md} +106 -1
  76. package/knowledge/09-templates/README.en.md +222 -0
  77. package/knowledge/09-templates/README.md +216 -0
  78. package/knowledge/README.en.md +372 -0
  79. package/knowledge/README.md +354 -99
  80. package/package.json +1 -1
  81. package/plugins/.claude-plugin/plugin.json +460 -81
  82. package/plugins/agents/roles/ceo.md +1 -1
  83. package/plugins/agents/roles/product-owner.md +1 -1
  84. package/plugins/agents/roles/tech-lead.md +1 -1
  85. package/plugins/agents/support/consistency-checker.md +36 -3
  86. package/plugins/agents/support/monitoring-agent.md +215 -0
  87. package/plugins/agents/support/safety-auditor.md +2 -2
  88. package/plugins/agents/support/stage-gate-evaluator.md +95 -11
  89. package/plugins/agents/support/test-coverage-reviewer.md +1 -1
  90. package/plugins/benchmarks/templates/README.md +165 -13
  91. package/plugins/benchmarks/templates/commands/apply-template.yaml +108 -0
  92. package/plugins/benchmarks/templates/commands/archive-template.yaml +65 -0
  93. package/plugins/benchmarks/templates/commands/env-export-template.yaml +64 -0
  94. package/plugins/benchmarks/templates/commands/env-sync-template.yaml +104 -0
  95. package/plugins/benchmarks/templates/commands/env-template-template.yaml +96 -0
  96. package/plugins/benchmarks/templates/commands/env-template.yaml +58 -0
  97. package/plugins/benchmarks/templates/commands/env-update-template.yaml +110 -0
  98. package/plugins/benchmarks/templates/commands/env-validate-template.yaml +95 -0
  99. package/plugins/benchmarks/templates/commands/field-evolve-template.yaml +104 -0
  100. package/plugins/benchmarks/templates/commands/project-evolve-template.yaml +104 -0
  101. package/plugins/benchmarks/templates/commands/propose-template.yaml +88 -0
  102. package/plugins/benchmarks/templates/commands/review-template.yaml +124 -0
  103. package/plugins/benchmarks/templates/commands/run-template.yaml +127 -0
  104. package/plugins/benchmarks/templates/commands/test-template.yaml +149 -0
  105. package/plugins/benchmarks/templates/pipeline/experiment-template.yaml +92 -0
  106. package/plugins/benchmarks/templates/pipeline/hotfix-template.yaml +81 -0
  107. package/plugins/benchmarks/templates/skills/agile-iteration-template.yaml +78 -0
  108. package/plugins/benchmarks/templates/skills/benchmark-executor-template.yaml +114 -0
  109. package/plugins/benchmarks/templates/skills/benchmark-generator-template.yaml +52 -0
  110. package/plugins/benchmarks/templates/skills/delivery-stage-template.yaml +130 -0
  111. package/plugins/benchmarks/templates/skills/design-stage-template.yaml +131 -0
  112. package/plugins/benchmarks/templates/skills/experiment-iteration-template.yaml +60 -0
  113. package/plugins/benchmarks/templates/skills/exploration-phase-template.yaml +114 -0
  114. package/plugins/benchmarks/templates/skills/field-evolve-analyzer-template.yaml +51 -0
  115. package/plugins/benchmarks/templates/skills/field-evolve-distiller-template.yaml +34 -0
  116. package/plugins/benchmarks/templates/skills/field-evolve-executor-template.yaml +50 -0
  117. package/plugins/benchmarks/templates/skills/field-evolve-fixer-template.yaml +52 -0
  118. package/plugins/benchmarks/templates/skills/field-evolve-learner-template.yaml +33 -0
  119. package/plugins/benchmarks/templates/skills/field-evolve-scanner-template.yaml +74 -0
  120. package/plugins/benchmarks/templates/skills/field-evolve-template.yaml +71 -0
  121. package/plugins/benchmarks/templates/skills/field-evolve-verifier-template.yaml +51 -0
  122. package/plugins/benchmarks/templates/skills/hotfix-iteration-template.yaml +54 -0
  123. package/plugins/benchmarks/templates/skills/implementation-stage-template.yaml +127 -0
  124. package/plugins/benchmarks/templates/skills/layer1-validation-template.yaml +121 -0
  125. package/plugins/benchmarks/templates/skills/project-evolve-analyzer-template.yaml +51 -0
  126. package/plugins/benchmarks/templates/skills/project-evolve-fixer-template.yaml +52 -0
  127. package/plugins/benchmarks/templates/skills/project-evolve-generator-template.yaml +34 -0
  128. package/plugins/benchmarks/templates/skills/project-evolve-learner-template.yaml +50 -0
  129. package/plugins/benchmarks/templates/skills/project-evolve-reviewer-template.yaml +50 -0
  130. package/plugins/benchmarks/templates/skills/project-evolve-scanner-template.yaml +75 -0
  131. package/plugins/benchmarks/templates/skills/project-evolve-template.yaml +72 -0
  132. package/plugins/benchmarks/templates/skills/project-evolve-verifier-template.yaml +51 -0
  133. package/plugins/benchmarks/templates/skills/skill-forge-template.yaml +117 -0
  134. package/plugins/benchmarks/templates/skills/startup-guard-template.yaml +103 -0
  135. package/plugins/benchmarks/templates/skills/testing-stage-template.yaml +146 -0
  136. package/plugins/benchmarks/templates/skills/waterfall-iteration-template.yaml +55 -0
  137. package/plugins/commands/README.en.md +2 -2
  138. package/plugins/commands/README.md +2 -2
  139. package/plugins/commands/apply.md +102 -16
  140. package/plugins/commands/archive.md +60 -4
  141. package/plugins/commands/env-sync.md +1047 -406
  142. package/plugins/commands/env-template.md +11 -135
  143. package/plugins/commands/env-update.md +1 -1
  144. package/plugins/commands/env-validate.md +3 -3
  145. package/plugins/commands/explore.md +118 -1
  146. package/plugins/commands/field-evolve.md +51 -175
  147. package/plugins/commands/project-evolve.md +167 -68
  148. package/plugins/commands/propose.md +97 -6
  149. package/plugins/commands/review.md +5 -5
  150. package/plugins/commands/run.md +841 -13
  151. package/plugins/commands/status.md +138 -17
  152. package/plugins/commands/test.md +389 -0
  153. package/plugins/hooks/constitution-guard.js +1 -1
  154. package/plugins/hooks/environment-autocommit.js +366 -24
  155. package/plugins/hooks/environment-manager.js +3 -2
  156. package/plugins/hooks/execution-tracker.js +109 -4
  157. package/plugins/hooks/layer1-validator.js +117 -1
  158. package/plugins/hooks/lib/auto-fix-loop.js +605 -0
  159. package/plugins/hooks/lib/environment-config-loader.js +11 -7
  160. package/plugins/hooks/lib/hook-state-manager.js +98 -0
  161. package/plugins/hooks/lib/memory-extractor.js +27 -5
  162. package/plugins/hooks/lib/memory-manager.js +1 -1
  163. package/plugins/hooks/lib/test-auto-fix.test.js +194 -0
  164. package/plugins/hooks/monitoring-trigger.js +467 -0
  165. package/plugins/skills/README.en.md +15 -3
  166. package/plugins/skills/README.md +21 -11
  167. package/plugins/skills/agile-iteration/SKILL.md +187 -0
  168. package/plugins/skills/delivery-stage/SKILL.md +133 -12
  169. package/plugins/skills/design-stage/SKILL.md +103 -12
  170. package/plugins/skills/experiment-evaluator/SKILL.md +271 -0
  171. package/plugins/skills/experiment-iteration/SKILL.md +154 -0
  172. package/plugins/skills/exploration-phase/SKILL.md +93 -10
  173. package/plugins/skills/field-evolve-analyzer/SKILL.md +65 -0
  174. package/plugins/skills/field-evolve-distiller/SKILL.md +66 -0
  175. package/plugins/skills/field-evolve-executor/SKILL.md +94 -0
  176. package/plugins/skills/field-evolve-executor/executor.js +342 -0
  177. package/plugins/skills/field-evolve-fixer/SKILL.md +69 -0
  178. package/plugins/skills/field-evolve-learner/SKILL.md +65 -0
  179. package/plugins/skills/field-evolve-scanner/SKILL.md +87 -0
  180. package/plugins/skills/field-evolve-scanner/scripts/fallback-scanner.js +288 -0
  181. package/plugins/skills/field-evolve-verifier/SKILL.md +64 -0
  182. package/plugins/skills/hotfix-iteration/SKILL.md +279 -0
  183. package/plugins/skills/implementation-stage/SKILL.md +156 -15
  184. package/plugins/skills/layer1-validation/SKILL.md +1 -1
  185. package/plugins/skills/pending-dashboard/SKILL.md +9 -8
  186. package/plugins/skills/project-evolve-analyzer/SKILL.md +95 -0
  187. package/plugins/skills/project-evolve-fixer/SKILL.md +99 -0
  188. package/plugins/skills/project-evolve-generator/SKILL.md +149 -0
  189. package/plugins/skills/project-evolve-learner/SKILL.md +103 -0
  190. package/plugins/skills/project-evolve-reviewer/SKILL.md +104 -0
  191. package/plugins/skills/project-evolve-scanner/SKILL.md +95 -0
  192. package/plugins/skills/project-evolve-scanner/scripts/dependency-reuse-checker.js +395 -0
  193. package/plugins/skills/project-evolve-scanner/scripts/subsystem-coverage.js +315 -0
  194. package/plugins/skills/project-evolve-verifier/SKILL.md +105 -0
  195. package/plugins/skills/requirement-stage/SKILL.md +47 -13
  196. package/plugins/skills/skill-forge/SKILL.md +2 -2
  197. package/plugins/skills/testing-stage/SKILL.md +583 -8
  198. package/plugins/skills/waterfall-iteration/SKILL.md +115 -0
  199. package/scripts/cli/index.js +1 -1
  200. package/scripts/cli/init.js +30 -4
  201. package/scripts/cli/list.js +3 -2
  202. package/scripts/config/commands.config.js +8 -8
  203. package/scripts/config/hooks.config.js +1 -1
  204. package/scripts/install/constants.js +204 -165
  205. package/scripts/state.js +210 -1
  206. package/knowledge/config/README.en.md +0 -44
  207. package/knowledge/config/README.md +0 -44
  208. package/knowledge/config/role-composition.yaml +0 -98
  209. package/knowledge/config/team-triggers.yaml +0 -198
  210. package/knowledge/domain/README.md +0 -115
  211. package/knowledge/domain/flows/README.md +0 -194
  212. package/knowledge/domain/glossary.md +0 -143
  213. package/knowledge/domain/rules.md +0 -138
  214. package/knowledge/environment/component-knowledge.md +0 -316
  215. package/knowledge/environment/detection-patterns.yaml +0 -502
  216. package/knowledge/environment/template-registry.md +0 -321
  217. package/knowledge/guides/requirement-engineering.md +0 -329
  218. package/knowledge/guides/system-design.md +0 -352
  219. package/knowledge/principles/constitution.md +0 -134
  220. package/knowledge/principles/core-principles.md +0 -368
  221. package/knowledge/principles/design-philosophy.md +0 -877
  222. package/knowledge/process/README.en.md +0 -38
  223. package/knowledge/process/README.md +0 -48
  224. package/knowledge/templates/ai-evaluation.md +0 -150
  225. package/knowledge/templates/api-design.md +0 -117
  226. package/knowledge/templates/database-design.md +0 -132
  227. package/knowledge/templates/domain-driven-design.md +0 -321
  228. package/knowledge/templates/product-proposal.md +0 -201
  229. package/knowledge/templates/system-design.md +0 -227
  230. package/knowledge/templates/task-breakdown.md +0 -107
  231. package/knowledge/templates/test-case.md +0 -170
  232. package/plugins/commands/validate.md +0 -108
  233. package/plugins/skills/benchmark-executor/README.md +0 -93
  234. package/plugins/skills/evolution-process/SKILL.md +0 -291
  235. package/plugins/skills/project-evolution/SKILL.md +0 -847
  236. package/scripts/evolution/evolution-router.js +0 -273
  237. package/scripts/evolution/evolution-signal-collector.js +0 -307
  238. package/scripts/evolution/knowledge-loader.js +0 -346
  239. package/scripts/evolution/marketplace.js +0 -317
  240. package/scripts/evolution/version-manager.js +0 -371
  241. /package/knowledge/{process → 02-process}/01-requirement.md +0 -0
  242. /package/knowledge/{process → 02-process}/02-design.md +0 -0
  243. /package/knowledge/{process → 02-process}/03-implementation.md +0 -0
  244. /package/knowledge/{process → 02-process}/04-review.md +0 -0
  245. /package/knowledge/{process → 02-process}/05-testing.md +0 -0
  246. /package/knowledge/{process → 02-process}/06-delivery.md +0 -0
  247. /package/knowledge/{guides/stages/design-planner.md → 03-guides/03-design-solution.md} +0 -0
  248. /package/knowledge/{guides/stages/code-implementer.md → 03-guides/04-implement-code.md} +0 -0
  249. /package/knowledge/{guides/stages/test-planner.md → 03-guides/05-plan-testing.md} +0 -0
  250. /package/knowledge/{guides/stages/test-generator.md → 03-guides/06-generate-tests.md} +0 -0
  251. /package/knowledge/{guides/stages/release-checker.md → 03-guides/07-check-release.md} +0 -0
  252. /package/knowledge/{guides/stages/requirement-reviewer.md → 03-guides/09-review-requirement.md} +0 -0
  253. /package/knowledge/{guides/stages/design-reviewer.md → 03-guides/10-review-design.md} +0 -0
  254. /package/knowledge/{guides/stages/code-reviewer.md → 03-guides/11-review-code.md} +0 -0
  255. /package/knowledge/{guides/stages/test-reviewer.md → 03-guides/12-review-testing.md} +0 -0
  256. /package/knowledge/{guides/stages/security-reviewer.md → 03-guides/13-audit-security.md} +0 -0
  257. /package/knowledge/{guides/stages/consistency-checker.md → 03-guides/14-check-consistency.md} +0 -0
  258. /package/knowledge/{guides/stages/unit-test-runner.md → 03-guides/15-run-unit-tests.md} +0 -0
  259. /package/knowledge/{guides/stages/integration-test-runner.md → 03-guides/16-run-integration-tests.md} +0 -0
  260. /package/knowledge/{guides/stages/test-context-analyzer.md → 03-guides/17-analyze-test-context.md} +0 -0
  261. /package/knowledge/{guides/support/practice-logger.md → 03-guides/18-log-practice.md} +0 -0
  262. /package/knowledge/{guides/support/skill-validator.md → 03-guides/21-validate-skill.md} +0 -0
  263. /package/knowledge/{guides/support/scope-inference.md → 03-guides/23-infer-scope.md} +0 -0
  264. /package/knowledge/{guides/support/component-discovery.md → 03-guides/25-discover-component.md} +0 -0
  265. /package/knowledge/{guides/support/environment-scanner.md → 03-guides/27-scan-environment.md} +0 -0
  266. /package/knowledge/{guides/support/environment-validator.md → 03-guides/28-validate-environment.md} +0 -0
  267. /package/knowledge/{guides/support/knowledge-generator.md → 03-guides/29-generate-knowledge.md} +0 -0
  268. /package/knowledge/{guides/support/ai-capability-analyzer.md → 03-guides/30-analyze-ai-capability.md} +0 -0
  269. /package/knowledge/{guides/support/ai-component-analyzer.md → 03-guides/31-analyze-ai-component.md} +0 -0
  270. /package/knowledge/{guides/support/ai-agent-analyzer.md → 03-guides/32-analyze-ai-agent.md} +0 -0
  271. /package/knowledge/{guides/support/ai-rag-analyzer.md → 03-guides/33-analyze-ai-rag.md} +0 -0
  272. /package/knowledge/{guides/support/ai-task-assessor.md → 03-guides/34-assess-ai-task.md} +0 -0
  273. /package/knowledge/{guides/support/ai-pipeline-evaluator.md → 03-guides/35-evaluate-ai-pipeline.md} +0 -0
  274. /package/knowledge/{guides/support/ai-artifact-evaluator.md → 03-guides/36-evaluate-ai-artifact.md} +0 -0
  275. /package/knowledge/{guides/support/ai-evaluation-planner.md → 03-guides/37-plan-ai-evaluation.md} +0 -0
  276. /package/knowledge/{guides/support/ai-path-evaluator.md → 03-guides/38-evaluate-ai-path.md} +0 -0
  277. /package/knowledge/{guides/support/ai-data-validator.md → 03-guides/39-validate-ai-data.md} +0 -0
  278. /package/knowledge/{guides/support/ai-anomaly-analyzer.md → 03-guides/40-detect-ai-anomaly.md} +0 -0
  279. /package/knowledge/{guides/support/ai-test-diagnostics.md → 03-guides/41-diagnose-ai-test.md} +0 -0
  280. /package/knowledge/{guides/support/test-runner.md → 03-guides/45-test-runner.md} +0 -0
  281. /package/knowledge/{checklists/test.md → 04-checklists/03-test.md} +0 -0
  282. /package/knowledge/{config/team-stage.yaml → 05-config/01-team-stage.yaml} +0 -0
  283. /package/knowledge/{config/role-extensions.yaml → 05-config/04-role-extensions.yaml} +0 -0
@@ -0,0 +1,467 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * AutoSpec Hook: Monitoring Trigger
5
+ *
6
+ * 后台监控触发器 Hook,负责:
7
+ * 1. 累积代码变更计数
8
+ * 2. 根据复杂度权衡触发后台监控检查
9
+ * 3. 输出监控提醒到主上下文
10
+ *
11
+ * Security Level: LOW - fail-open + logging
12
+ */
13
+
14
+ import { createHookLogger, safeJsonParse, handleHookError, readStdin, findProjectRootAsync } from './lib/hook-logger.js';
15
+ import { recordHookExecution } from './lib/hook-error-recorder.js';
16
+ import { getState, getCurrentStageSubsystems } from './lib/hook-state-manager.js';
17
+ import fs from 'fs';
18
+ import path from 'path';
19
+
20
+ const logger = createHookLogger('monitoring-trigger');
21
+
22
+ // 监控触发配置
23
+ const MONITORING_CONFIG = {
24
+ highComplexity: {
25
+ interval: 5 * 60 * 1000, // 5 分钟
26
+ threshold: 1, // 1 次变更触发
27
+ checkDepth: 'deep'
28
+ },
29
+ mediumComplexity: {
30
+ interval: 10 * 60 * 1000, // 10 分钟
31
+ threshold: 3, // 3 次变更触发
32
+ checkDepth: 'medium'
33
+ },
34
+ lowComplexity: {
35
+ interval: 20 * 60 * 1000, // 20 分钟
36
+ threshold: 5, // 5 次变更触发
37
+ checkDepth: 'light'
38
+ }
39
+ };
40
+
41
+ // 变更累积文件
42
+ function getChangeCounterPath(projectRoot) {
43
+ return path.join(projectRoot, '.autospec', 'runtime', 'change-counter.json');
44
+ }
45
+
46
+ // 最后检查时间文件
47
+ function getLastCheckPath(projectRoot) {
48
+ return path.join(projectRoot, '.autospec', 'runtime', 'last-check.json');
49
+ }
50
+
51
+ /**
52
+ * 读取变更计数器
53
+ */
54
+ function readChangeCounter(projectRoot) {
55
+ const counterPath = getChangeCounterPath(projectRoot);
56
+ if (fs.existsSync(counterPath)) {
57
+ try {
58
+ return JSON.parse(fs.readFileSync(counterPath, 'utf-8'));
59
+ } catch {
60
+ return { total: 0, bySubsystem: {}, lastChangeAt: null };
61
+ }
62
+ }
63
+ return { total: 0, bySubsystem: {}, lastChangeAt: null };
64
+ }
65
+
66
+ /**
67
+ * 写入变更计数器
68
+ */
69
+ function writeChangeCounter(projectRoot, counter) {
70
+ const counterPath = getChangeCounterPath(projectRoot);
71
+ const dir = path.dirname(counterPath);
72
+ if (!fs.existsSync(dir)) {
73
+ fs.mkdirSync(dir, { recursive: true });
74
+ }
75
+ fs.writeFileSync(counterPath, JSON.stringify(counter, null, 2), 'utf-8');
76
+ }
77
+
78
+ /**
79
+ * 读取最后检查时间
80
+ */
81
+ function readLastCheck(projectRoot) {
82
+ const lastCheckPath = getLastCheckPath(projectRoot);
83
+ if (fs.existsSync(lastCheckPath)) {
84
+ try {
85
+ return JSON.parse(fs.readFileSync(lastCheckPath, 'utf-8'));
86
+ } catch {
87
+ return { lastCheckAt: null, lastCheckType: null };
88
+ }
89
+ }
90
+ return { lastCheckAt: null, lastCheckType: null };
91
+ }
92
+
93
+ /**
94
+ * 写入最后检查时间
95
+ */
96
+ function writeLastCheck(projectRoot, checkInfo) {
97
+ const lastCheckPath = getLastCheckPath(projectRoot);
98
+ const dir = path.dirname(lastCheckPath);
99
+ if (!fs.existsSync(dir)) {
100
+ fs.mkdirSync(dir, { recursive: true });
101
+ }
102
+ fs.writeFileSync(lastCheckPath, JSON.stringify(checkInfo, null, 2), 'utf-8');
103
+ }
104
+
105
+ /**
106
+ * 获取任务复杂度
107
+ */
108
+ function getComplexity(state) {
109
+ // 从 state 中读取复杂度评估
110
+ // 如果没有,默认为中等复杂度
111
+ return state?.complexity || 'medium';
112
+ }
113
+
114
+ /**
115
+ * 检测子系统变更
116
+ */
117
+ function detectSubsystemChange(filePath, subsystems) {
118
+ if (!filePath || !subsystems || subsystems.length === 0) {
119
+ return null;
120
+ }
121
+
122
+ const relativePath = filePath.replace(process.cwd() + '/', '').replace(process.cwd() + '\\', '');
123
+
124
+ for (const sub of subsystems) {
125
+ if (relativePath.startsWith(sub.path + '/') ||
126
+ relativePath.startsWith(sub.path + '\\') ||
127
+ relativePath.startsWith(sub.name + '/')) {
128
+ return sub.name;
129
+ }
130
+ }
131
+
132
+ return null;
133
+ }
134
+
135
+ /**
136
+ * 检查是否需要触发监控
137
+ */
138
+ function shouldTriggerMonitoring(counter, lastCheck, complexity) {
139
+ const config = MONITORING_CONFIG[complexity] || MONITORING_CONFIG.mediumComplexity;
140
+ const now = Date.now();
141
+
142
+ // 检查时间间隔
143
+ const timeSinceLastCheck = lastCheck.lastCheckAt ? now - new Date(lastCheck.lastCheckAt).getTime() : Infinity;
144
+ const timeThresholdReached = timeSinceLastCheck >= config.interval;
145
+
146
+ // 检查变更阈值
147
+ const changeThresholdReached = counter.total >= config.threshold;
148
+
149
+ // 时间和变更阈值都达到时才触发
150
+ return timeThresholdReached && changeThresholdReached;
151
+ }
152
+
153
+ /**
154
+ * 触发监控检查
155
+ */
156
+ async function triggerMonitoring(projectRoot, complexity) {
157
+ try {
158
+ logger.info('Triggering monitoring check', { complexity });
159
+
160
+ // 记录最后检查时间
161
+ writeLastCheck(projectRoot, {
162
+ lastCheckAt: new Date().toISOString(),
163
+ lastCheckType: 'monitoring',
164
+ complexity
165
+ });
166
+
167
+ // 重置变更计数器
168
+ writeChangeCounter(projectRoot, { total: 0, bySubsystem: {}, lastChangeAt: null });
169
+
170
+ // 执行实际的监控检查
171
+ const alerts = await executeMonitoringCheck(projectRoot, complexity);
172
+
173
+ // 输出提醒(如果有)
174
+ if (alerts && alerts.length > 0) {
175
+ outputMonitoringAlert(projectRoot, alerts);
176
+ }
177
+
178
+ return true;
179
+ } catch (e) {
180
+ logger.error('Failed to trigger monitoring', { error: e.message });
181
+ return false;
182
+ }
183
+ }
184
+
185
+ /**
186
+ * 执行监控检查(调用 checker 脚本)
187
+ */
188
+ async function executeMonitoringCheck(projectRoot, complexity) {
189
+ const alerts = [];
190
+
191
+ try {
192
+ // 1. 读取 state 获取子系统列表
193
+ const state = getState(projectRoot, true);
194
+ const subsystems = getCurrentStageSubsystems(projectRoot);
195
+
196
+ if (subsystems.length === 0) {
197
+ // 单系统模式,不执行深度检查
198
+ return alerts;
199
+ }
200
+
201
+ // 2. 调用子系统覆盖检查
202
+ const { generateCoverageReport } = await import('../skills/project-evolve-scanner/scripts/subsystem-coverage.js');
203
+ const coverageReport = generateCoverageReport({
204
+ projectRoot,
205
+ state,
206
+ designSubsystems: subsystems
207
+ });
208
+
209
+ // 3. 检查子系统覆盖问题
210
+ if (coverageReport.summary.pending > 0) {
211
+ const pendingSubsystems = coverageReport.subsystems
212
+ .filter(s => s.status === 'pending')
213
+ .map(s => s.name);
214
+
215
+ alerts.push({
216
+ severity: coverageReport.summary.pending >= 2 ? 'high' : 'medium',
217
+ title: '子系统未开始实现',
218
+ description: `检测到 ${coverageReport.summary.pending} 个子系统尚未开始:${pendingSubsystems.join(', ')}`,
219
+ suggestion: '检查开发顺序依赖,确认是否需要优先处理某些子系统'
220
+ });
221
+ }
222
+
223
+ // 4. 检查 Layer 1 验证状态
224
+ const pendingLayer1 = coverageReport.subsystems
225
+ .filter(s => s.status === 'completed' && !s.layer1)
226
+ .map(s => s.name);
227
+
228
+ if (pendingLayer1.length > 0) {
229
+ alerts.push({
230
+ severity: 'high',
231
+ title: '子系统未执行 Layer 1 验证',
232
+ description: `检测到 ${pendingLayer1.length} 个子系统已完成但未执行验证:${pendingLayer1.join(', ')}`,
233
+ suggestion: '执行 build/test/lint 验证后再标记为完成'
234
+ });
235
+ }
236
+
237
+ // 5. 检查监控问题修复情况
238
+ const monitoringIssuesPath = path.join(projectRoot, '.autospec', 'monitoring-issues.json');
239
+ if (fs.existsSync(monitoringIssuesPath)) {
240
+ try {
241
+ const issues = JSON.parse(fs.readFileSync(monitoringIssuesPath, 'utf-8'));
242
+ const openIssues = issues.filter(i => i.status === 'open' || i.status === 'acknowledged');
243
+
244
+ if (openIssues.length > 0) {
245
+ const criticalIssues = openIssues.filter(i => i.severity === 'critical' || i.severity === 'high');
246
+ if (criticalIssues.length > 0) {
247
+ alerts.push({
248
+ severity: 'critical',
249
+ title: '存在未解决的高优先级监控问题',
250
+ description: `检测到 ${criticalIssues.length} 个高优先级问题未解决`,
251
+ suggestion: `查看详情:.autospec/monitoring-issues.json`,
252
+ issues: criticalIssues.map(i => ({ id: i.id, title: i.title, severity: i.severity }))
253
+ });
254
+ }
255
+ }
256
+ } catch (e) {
257
+ logger.debug('Failed to read monitoring issues', { error: e.message });
258
+ }
259
+ }
260
+
261
+ // 6. 写入监控报告
262
+ const reportPath = path.join(projectRoot, '.autospec', 'monitoring-report.md');
263
+ const reportDir = path.dirname(reportPath);
264
+ if (!fs.existsSync(reportDir)) {
265
+ fs.mkdirSync(reportDir, { recursive: true });
266
+ }
267
+
268
+ let reportContent = `# AutoSpec 监控报告\n\n`;
269
+ reportContent += `**检查时间**: ${new Date().toISOString()}\n`;
270
+ reportContent += `**复杂度**: ${complexity}\n\n`;
271
+ reportContent += `## 子系统覆盖\n\n`;
272
+ reportContent += `- 总计:${coverageReport.summary.totalSubsystems} 个子系统\n`;
273
+ reportContent += `- 已完成:${coverageReport.summary.completed}\n`;
274
+ reportContent += `- 进行中:${coverageReport.summary.inProgress}\n`;
275
+ reportContent += `- 待开始:${coverageReport.summary.pending}\n`;
276
+ reportContent += `- 覆盖率:${coverageReport.summary.coverageRate}%\n\n`;
277
+
278
+ if (alerts.length > 0) {
279
+ reportContent += `## 发现的问题\n\n`;
280
+ for (let i = 0; i < alerts.length; i++) {
281
+ const alert = alerts[i];
282
+ reportContent += `### ${i + 1}. [${alert.severity.toUpperCase()}] ${alert.title}\n`;
283
+ reportContent += `- ${alert.description}\n`;
284
+ if (alert.suggestion) {
285
+ reportContent += `- 建议:${alert.suggestion}\n`;
286
+ }
287
+ reportContent += '\n';
288
+ }
289
+ } else {
290
+ reportContent += `## 检查结果\n\n✅ 未发现明显问题\n`;
291
+ }
292
+
293
+ fs.writeFileSync(reportPath, reportContent, 'utf-8');
294
+ logger.info('Monitoring report written', { path: reportPath });
295
+
296
+ } catch (e) {
297
+ logger.error('Failed to execute monitoring check', { error: e.message });
298
+ alerts.push({
299
+ severity: 'low',
300
+ title: '监控检查执行失败',
301
+ description: `错误信息:${e.message}`,
302
+ suggestion: '检查日志详情'
303
+ });
304
+ }
305
+
306
+ return alerts;
307
+ }
308
+
309
+ /**
310
+ * 输出监控提醒
311
+ */
312
+ function outputMonitoringAlert(projectRoot, alerts) {
313
+ if (!alerts || alerts.length === 0) {
314
+ return;
315
+ }
316
+
317
+ const output = {
318
+ hookSpecificOutput: {
319
+ hookEventName: 'PostToolUse',
320
+ additionalContext: buildAlertMessage(alerts)
321
+ }
322
+ };
323
+
324
+ process.stdout.write(JSON.stringify(output));
325
+ }
326
+
327
+ /**
328
+ * 构建提醒消息
329
+ */
330
+ function buildAlertMessage(alerts) {
331
+ let message = '**[AutoSpec 监控提醒]**\n\n';
332
+
333
+ for (const alert of alerts) {
334
+ const icon = alert.severity === 'critical' ? '❗' :
335
+ alert.severity === 'high' ? '⚠️' :
336
+ alert.severity === 'medium' ? 'ℹ️' : '📝';
337
+
338
+ message += `${icon} **${alert.severity.toUpperCase()}** - ${alert.title}\n`;
339
+ message += `- ${alert.description}\n`;
340
+ if (alert.suggestion) {
341
+ message += `- 建议:${alert.suggestion}\n`;
342
+ }
343
+ message += '\n';
344
+ }
345
+
346
+ message += '查看详情:`.autospec/monitoring-report.md`\n';
347
+
348
+ return message;
349
+ }
350
+
351
+ async function main() {
352
+ const startTime = Date.now();
353
+ let input;
354
+ let projectRoot = null;
355
+
356
+ try {
357
+ const rawInput = await readStdin(1000);
358
+ input = safeJsonParse(rawInput, null, 'hook input');
359
+
360
+ if (!input) {
361
+ logger.debug('Empty or invalid input, skipping');
362
+ process.exit(0);
363
+ }
364
+
365
+ // 只处理 PostToolUse 事件
366
+ const eventName = input.event_name;
367
+ if (eventName !== 'PostToolUse') {
368
+ logger.debug('Not a PostToolUse event, skipping');
369
+ process.exit(0);
370
+ }
371
+
372
+ // 只处理 Write/Edit 操作
373
+ const toolName = input.tool_name;
374
+ if (toolName !== 'Write' && toolName !== 'Edit') {
375
+ logger.debug('Not a Write/Edit operation, skipping');
376
+ process.exit(0);
377
+ }
378
+
379
+ // Find project root
380
+ const cwd = input.cwd || process.cwd();
381
+ projectRoot = await findProjectRootAsync(cwd);
382
+
383
+ if (!projectRoot) {
384
+ logger.debug('No .autospec directory found, skipping');
385
+ process.exit(0);
386
+ }
387
+
388
+ // 获取当前状态
389
+ const state = getState(projectRoot, true);
390
+ if (!state) {
391
+ logger.debug('No active pipeline, skipping');
392
+ process.exit(0);
393
+ }
394
+
395
+ // 获取子系统列表
396
+ const subsystems = getCurrentStageSubsystems(projectRoot);
397
+ if (subsystems.length === 0) {
398
+ // 单系统模式,轻量监控
399
+ logger.debug('Single-system mode, light monitoring');
400
+ }
401
+
402
+ // 读取变更计数器
403
+ let counter = readChangeCounter(projectRoot);
404
+
405
+ // 检测文件变更属于哪个子系统
406
+ const filePath = input.tool_input?.file_path || '';
407
+ if (filePath && !filePath.includes('.autospec')) {
408
+ const subsystemName = detectSubsystemChange(filePath, subsystems);
409
+
410
+ if (subsystemName) {
411
+ counter.bySubsystem[subsystemName] = (counter.bySubsystem[subsystemName] || 0) + 1;
412
+ logger.debug(`Subsystem change detected: ${subsystemName}`);
413
+ }
414
+
415
+ counter.total++;
416
+ counter.lastChangeAt = new Date().toISOString();
417
+ }
418
+
419
+ // 写入变更计数器
420
+ writeChangeCounter(projectRoot, counter);
421
+
422
+ // 检查是否需要触发监控
423
+ const complexity = getComplexity(state);
424
+ const lastCheck = readLastCheck(projectRoot);
425
+
426
+ if (shouldTriggerMonitoring(counter, lastCheck, complexity)) {
427
+ const triggered = await triggerMonitoring(projectRoot, complexity);
428
+
429
+ if (triggered) {
430
+ logger.info('Monitoring check triggered', { complexity, changeCount: counter.total });
431
+
432
+ // 输出提醒(如果有)
433
+ // 注意:实际的警报由 monitoring-agent 生成
434
+ // 这里只输出触发通知
435
+ const output = {
436
+ hookSpecificOutput: {
437
+ hookEventName: 'PostToolUse',
438
+ additionalContext: `**[AutoSpec 监控]** 已触发后台巡检(复杂度:${complexity},变更数:${counter.total})`
439
+ }
440
+ };
441
+ process.stdout.write(JSON.stringify(output));
442
+ }
443
+ }
444
+
445
+ // 记录成功执行
446
+ recordHookExecution(projectRoot, 'monitoring-trigger', input, null, startTime - Date.now(), true);
447
+ process.exit(0);
448
+
449
+ } catch (err) {
450
+ // 使用增强的错误处理
451
+ const result = handleHookError('monitoring-trigger', err, {
452
+ eventName: input?.event_name || 'Unknown',
453
+ projectRoot,
454
+ input
455
+ });
456
+
457
+ // 记录失败的执行
458
+ if (projectRoot) {
459
+ recordHookExecution(projectRoot, 'monitoring-trigger', input, result, Date.now() - startTime, false);
460
+ }
461
+
462
+ process.stdout.write(JSON.stringify(result.hookSpecificOutput));
463
+ process.exit(0);
464
+ }
465
+ }
466
+
467
+ main();
@@ -20,8 +20,20 @@ skills/
20
20
  │ └── SKILL.md # QA testing stage
21
21
  ├── delivery-stage/
22
22
  │ └── SKILL.md # Delivery and deployment stage
23
- ├── evolution-process/
24
- │ └── SKILL.md # Self-evolution (auto-triggered)
23
+ ├── field-evolve-scanner/ # L2 Field evolution - Scanner
24
+ ├── field-evolve-executor/ # L2 Field evolution - Executor
25
+ ├── field-evolve-analyzer/ # L2 Field evolution - Analyzer
26
+ ├── field-evolve-fixer/ # L2 Field evolution - Fixer
27
+ ├── field-evolve-verifier/ # L2 Field evolution - Verifier
28
+ ├── field-evolve-learner/ # L2 Field evolution - Learner
29
+ ├── field-evolve-distiller/ # L2 Field evolution - Distiller
30
+ ├── project-evolve-scanner/ # L3 Project evolution - Scanner
31
+ ├── project-evolve-analyzer/ # L3 Project evolution - Analyzer
32
+ ├── project-evolve-fixer/ # L3 Project evolution - Fixer
33
+ ├── project-evolve-verifier/ # L3 Project evolution - Verifier
34
+ ├── project-evolve-reviewer/ # L3 Project evolution - Reviewer
35
+ ├── project-evolve-learner/ # L3 Project evolution - Learner
36
+ ├── project-evolve-generator/ # L3 Project evolution - Generator
25
37
  ├── pending-dashboard/
26
38
  │ └── SKILL.md # Pending dashboard (session startup trigger)
27
39
  └── README.md # This file
@@ -32,7 +44,7 @@ skills/
32
44
  **Auto-triggered**:
33
45
  - `startup-guard`: Auto-triggered when development task detected
34
46
  - `layer1-validation`: Auto-triggered after code changes
35
- - `evolution-process`: Auto-triggered after pipeline completion
47
+ - `field-evolve-*`: Auto-triggered after pipeline completion (L2 Field-Evolve)
36
48
  - `pending-dashboard`: Auto-triggered on session startup
37
49
 
38
50
  **Stage-based**:
@@ -7,7 +7,7 @@
7
7
  ```
8
8
  ┌─────────────────────────────────────────────────────────────────┐
9
9
  │ 人类维护层 (Human-maintained) │
10
- │ ../knowledge/domain/ - 业务知识(术语、规则、流程)
10
+ │ ../knowledge/03-guides/domain-*.md - 业务知识(术语、规则)
11
11
  │ 由领域专家维护,AI 读取但不修改 │
12
12
  └─────────────────────────────────────────────────────────────────┘
13
13
  ↓ 驱动
@@ -48,10 +48,20 @@ skills/
48
48
  │ └── SKILL.md # QA测试阶段(含 Benchmarks 评测)
49
49
  ├── delivery-stage/
50
50
  │ └── SKILL.md # 交付部署阶段
51
- ├── evolution-process/
52
- │ └── SKILL.md # 自进化(自动触发)- L2 Field-Evolve
53
- ├── project-evolution/
54
- │ └── SKILL.md # 项目进化 - L3 Project-Evolve
51
+ ├── field-evolve-scanner/ # L2 领域进化 - 扫描
52
+ ├── field-evolve-executor/ # L2 领域进化 - 执行
53
+ ├── field-evolve-analyzer/ # L2 领域进化 - 分析
54
+ ├── field-evolve-fixer/ # L2 领域进化 - 修复
55
+ ├── field-evolve-verifier/ # L2 领域进化 - 验证
56
+ ├── field-evolve-learner/ # L2 领域进化 - 学习
57
+ ├── field-evolve-distiller/ # L2 领域进化 - 蒸馏
58
+ ├── project-evolve-scanner/ # L3 项目进化 - 扫描
59
+ ├── project-evolve-analyzer/ # L3 项目进化 - 分析
60
+ ├── project-evolve-fixer/ # L3 项目进化 - 修复
61
+ ├── project-evolve-verifier/ # L3 项目进化 - 验证
62
+ ├── project-evolve-reviewer/ # L3 项目进化 - 审查
63
+ ├── project-evolve-learner/ # L3 项目进化 - 学习
64
+ ├── project-evolve-generator/ # L3 项目进化 - 生成
55
65
  ├── benchmark-generator/
56
66
  │ ├── SKILL.md # Benchmarks 自动生成
57
67
  │ └── README.md # 使用文档
@@ -73,7 +83,7 @@ skills/
73
83
  **自动触发型**:
74
84
  - `startup-guard`:检测到开发任务时自动触发
75
85
  - `layer1-validation`:代码变更后自动触发
76
- - `evolution-process`:流程完成后自动触发(L2 Field-Evolve)
86
+ - `field-evolve-*`:流程完成后自动触发(L2 Field-Evolve)
77
87
  - `pending-dashboard`:会话启动时自动触发
78
88
 
79
89
  **阶段流程型**:
@@ -89,15 +99,15 @@ skills/
89
99
 
90
100
  **进化支撑型**:
91
101
  - `skill-forge`:技能锻造系统(蒸馏新建/迭代进化/Description优化)
92
- - `project-evolution`:项目自我进化(L3 Project-Evolve)
102
+ - `project-evolve-*`:项目自我进化技能组(L3 Project-Evolve)
93
103
 
94
104
  ### 按三层自进化体系分类
95
105
 
96
- | 层级 | 命令 | Skill |
97
- |------|------|-------|
106
+ | 层级 | 命令 | Skill 组合 |
107
+ |------|------|-----------|
98
108
  | L1: Self-Evolve | `/self-evolve` | `self-evolve/*`(位于 `.claude/skills/`) |
99
- | L2: Field-Evolve | `/autospec:field-evolve` | `evolution-process` |
100
- | L3: Project-Evolve | `/autospec:project-evolve` | `project-evolution` |
109
+ | L2: Field-Evolve | `/autospec:field-evolve` | `field-evolve-{scanner,executor,analyzer,fixer,verifier,learner,distiller}` |
110
+ | L3: Project-Evolve | `/autospec:project-evolve` | `project-evolve-{scanner,analyzer,fixer,verifier,reviewer,learner,generator}` |
101
111
 
102
112
  ## 变量替换
103
113