@chongyan/autospec 1.0.1

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 (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +472 -0
  3. package/README.md +476 -0
  4. package/bin/autospec.js +3 -0
  5. package/knowledge/README.md +144 -0
  6. package/knowledge/checklists/code.md +182 -0
  7. package/knowledge/checklists/design.md +196 -0
  8. package/knowledge/checklists/release.md +70 -0
  9. package/knowledge/checklists/requirement.md +169 -0
  10. package/knowledge/checklists/test.md +46 -0
  11. package/knowledge/config/README.en.md +44 -0
  12. package/knowledge/config/README.md +44 -0
  13. package/knowledge/config/role-composition.yaml +98 -0
  14. package/knowledge/config/role-extensions.yaml +140 -0
  15. package/knowledge/config/skill-compositions.yaml +142 -0
  16. package/knowledge/config/team-stage.yaml +95 -0
  17. package/knowledge/config/team-tasks.yaml +139 -0
  18. package/knowledge/config/team-triggers.yaml +198 -0
  19. package/knowledge/config/validation-patterns.yaml +137 -0
  20. package/knowledge/domain/README.md +115 -0
  21. package/knowledge/domain/flows/README.md +194 -0
  22. package/knowledge/domain/glossary.md +143 -0
  23. package/knowledge/domain/rules.md +138 -0
  24. package/knowledge/environment/README.en.md +36 -0
  25. package/knowledge/environment/README.md +87 -0
  26. package/knowledge/environment/component-knowledge.md +316 -0
  27. package/knowledge/environment/detection-patterns.yaml +502 -0
  28. package/knowledge/environment/middleware-knowledge.md +237 -0
  29. package/knowledge/environment/template-registry.md +321 -0
  30. package/knowledge/guides/domain-driven-design.md +345 -0
  31. package/knowledge/guides/knowledge-management.md +369 -0
  32. package/knowledge/guides/requirement-engineering.md +329 -0
  33. package/knowledge/guides/stages/ai-effect-evaluator.md +93 -0
  34. package/knowledge/guides/stages/code-implementer.md +205 -0
  35. package/knowledge/guides/stages/code-reviewer.md +111 -0
  36. package/knowledge/guides/stages/consistency-checker.md +177 -0
  37. package/knowledge/guides/stages/design-planner.md +401 -0
  38. package/knowledge/guides/stages/design-reviewer.md +83 -0
  39. package/knowledge/guides/stages/integration-test-runner.md +105 -0
  40. package/knowledge/guides/stages/release-checker.md +205 -0
  41. package/knowledge/guides/stages/requirement-analyzer.md +195 -0
  42. package/knowledge/guides/stages/requirement-reviewer.md +83 -0
  43. package/knowledge/guides/stages/security-reviewer.md +89 -0
  44. package/knowledge/guides/stages/test-context-analyzer.md +250 -0
  45. package/knowledge/guides/stages/test-generator.md +241 -0
  46. package/knowledge/guides/stages/test-planner.md +183 -0
  47. package/knowledge/guides/stages/test-reviewer.md +76 -0
  48. package/knowledge/guides/stages/unit-test-runner.md +83 -0
  49. package/knowledge/guides/support/ai-agent-analyzer.md +362 -0
  50. package/knowledge/guides/support/ai-anomaly-analyzer.md +213 -0
  51. package/knowledge/guides/support/ai-artifact-evaluator.md +192 -0
  52. package/knowledge/guides/support/ai-capability-analyzer.md +193 -0
  53. package/knowledge/guides/support/ai-component-analyzer.md +169 -0
  54. package/knowledge/guides/support/ai-data-validator.md +276 -0
  55. package/knowledge/guides/support/ai-evaluation-planner.md +374 -0
  56. package/knowledge/guides/support/ai-path-evaluator.md +274 -0
  57. package/knowledge/guides/support/ai-pipeline-evaluator.md +219 -0
  58. package/knowledge/guides/support/ai-rag-analyzer.md +339 -0
  59. package/knowledge/guides/support/ai-task-assessor.md +418 -0
  60. package/knowledge/guides/support/ai-test-diagnostics.md +133 -0
  61. package/knowledge/guides/support/complexity-assessor.md +268 -0
  62. package/knowledge/guides/support/component-discovery.md +183 -0
  63. package/knowledge/guides/support/environment-scanner.md +207 -0
  64. package/knowledge/guides/support/environment-validator.md +207 -0
  65. package/knowledge/guides/support/knowledge-generator.md +234 -0
  66. package/knowledge/guides/support/methodology-extractor.md +55 -0
  67. package/knowledge/guides/support/pipeline-protocol.md +438 -0
  68. package/knowledge/guides/support/practice-logger.md +359 -0
  69. package/knowledge/guides/support/scope-inference.md +174 -0
  70. package/knowledge/guides/support/skill-distiller.md +91 -0
  71. package/knowledge/guides/support/skill-updater.md +45 -0
  72. package/knowledge/guides/support/skill-validator.md +72 -0
  73. package/knowledge/guides/support/team-orchestrator.md +323 -0
  74. package/knowledge/guides/support/tech-stack-analyzer.md +139 -0
  75. package/knowledge/guides/support/test-runner.md +254 -0
  76. package/knowledge/guides/system-design.md +352 -0
  77. package/knowledge/organization/ai-native-team.md +318 -0
  78. package/knowledge/organization/team-metrics.md +228 -0
  79. package/knowledge/principles/constitution.md +134 -0
  80. package/knowledge/principles/core-principles.md +368 -0
  81. package/knowledge/principles/design-philosophy.md +877 -0
  82. package/knowledge/principles/evolution.md +553 -0
  83. package/knowledge/process/01-requirement.md +113 -0
  84. package/knowledge/process/02-design.md +123 -0
  85. package/knowledge/process/03-implementation.md +90 -0
  86. package/knowledge/process/04-review.md +80 -0
  87. package/knowledge/process/05-testing.md +90 -0
  88. package/knowledge/process/06-delivery.md +88 -0
  89. package/knowledge/process/README.en.md +38 -0
  90. package/knowledge/process/README.md +48 -0
  91. package/knowledge/process/ai-sdlc.md +475 -0
  92. package/knowledge/process/overview.md +319 -0
  93. package/knowledge/standards/code-review.md +876 -0
  94. package/knowledge/standards/coding-style.md +940 -0
  95. package/knowledge/standards/data-consistency.md +1085 -0
  96. package/knowledge/standards/document-versioning.md +210 -0
  97. package/knowledge/standards/risk-detection.md +186 -0
  98. package/knowledge/templates/ai-evaluation.md +150 -0
  99. package/knowledge/templates/api-design.md +117 -0
  100. package/knowledge/templates/database-design.md +132 -0
  101. package/knowledge/templates/domain-driven-design.md +321 -0
  102. package/knowledge/templates/product-proposal.md +201 -0
  103. package/knowledge/templates/system-design.md +227 -0
  104. package/knowledge/templates/task-breakdown.md +107 -0
  105. package/knowledge/templates/test-case.md +170 -0
  106. package/package.json +53 -0
  107. package/plugins/.claude-plugin/plugin.json +134 -0
  108. package/plugins/agents/roles/ai-engineer.md +129 -0
  109. package/plugins/agents/roles/backend-engineer.md +165 -0
  110. package/plugins/agents/roles/ceo.md +94 -0
  111. package/plugins/agents/roles/data-engineer.md +135 -0
  112. package/plugins/agents/roles/devops-engineer.md +181 -0
  113. package/plugins/agents/roles/frontend-engineer.md +129 -0
  114. package/plugins/agents/roles/product-owner.md +98 -0
  115. package/plugins/agents/roles/quality-engineer.md +129 -0
  116. package/plugins/agents/roles/security-engineer.md +180 -0
  117. package/plugins/agents/roles/tech-lead.md +97 -0
  118. package/plugins/agents/support/blind-comparator.md +88 -0
  119. package/plugins/agents/support/consistency-checker.md +103 -0
  120. package/plugins/agents/support/failure-diagnostician.md +141 -0
  121. package/plugins/agents/support/independent-reviewer.md +80 -0
  122. package/plugins/agents/support/safety-auditor.md +121 -0
  123. package/plugins/agents/support/skill-benchmarker.md +86 -0
  124. package/plugins/agents/support/skill-forger.md +105 -0
  125. package/plugins/agents/support/stage-gate-evaluator.md +121 -0
  126. package/plugins/agents/support/test-coverage-reviewer.md +73 -0
  127. package/plugins/benchmarks/templates/README.md +44 -0
  128. package/plugins/benchmarks/templates/commands/explore-template.yaml +48 -0
  129. package/plugins/benchmarks/templates/pipeline/agile-template.yaml +84 -0
  130. package/plugins/benchmarks/templates/pipeline/waterfall-template.yaml +106 -0
  131. package/plugins/benchmarks/templates/skills/requirement-analyzer-template.yaml +48 -0
  132. package/plugins/commands/README.en.md +96 -0
  133. package/plugins/commands/README.md +96 -0
  134. package/plugins/commands/apply.md +191 -0
  135. package/plugins/commands/archive.md +76 -0
  136. package/plugins/commands/env-export.md +79 -0
  137. package/plugins/commands/env-sync.md +640 -0
  138. package/plugins/commands/env-template.md +223 -0
  139. package/plugins/commands/env-update.md +264 -0
  140. package/plugins/commands/env-validate.md +176 -0
  141. package/plugins/commands/env.md +79 -0
  142. package/plugins/commands/explore.md +76 -0
  143. package/plugins/commands/field-evolve.md +536 -0
  144. package/plugins/commands/memory.md +249 -0
  145. package/plugins/commands/project-evolve.md +821 -0
  146. package/plugins/commands/propose.md +93 -0
  147. package/plugins/commands/review.md +140 -0
  148. package/plugins/commands/run.md +224 -0
  149. package/plugins/commands/status.md +62 -0
  150. package/plugins/commands/validate.md +108 -0
  151. package/plugins/hooks/README.en.md +56 -0
  152. package/plugins/hooks/README.md +56 -0
  153. package/plugins/hooks/ai-project-guard.js +329 -0
  154. package/plugins/hooks/artifact-evaluation-hook.js +237 -0
  155. package/plugins/hooks/constitution-guard.js +211 -0
  156. package/plugins/hooks/environment-autocommit.js +264 -0
  157. package/plugins/hooks/environment-manager.js +778 -0
  158. package/plugins/hooks/execution-tracker.js +354 -0
  159. package/plugins/hooks/frozen-zone-guard.js +140 -0
  160. package/plugins/hooks/layer1-validator.js +423 -0
  161. package/plugins/hooks/lib/artifact-evaluator.js +414 -0
  162. package/plugins/hooks/lib/benchmarks/change-detector.js +390 -0
  163. package/plugins/hooks/lib/benchmarks/evaluator.js +605 -0
  164. package/plugins/hooks/lib/benchmarks/integration-example.js +169 -0
  165. package/plugins/hooks/lib/data-and-ai-detector.js +275 -0
  166. package/plugins/hooks/lib/detection-pattern-loader.js +865 -0
  167. package/plugins/hooks/lib/directory-discovery.js +395 -0
  168. package/plugins/hooks/lib/environment-config-loader.js +341 -0
  169. package/plugins/hooks/lib/environment-detector.js +553 -0
  170. package/plugins/hooks/lib/environment-evolver.js +564 -0
  171. package/plugins/hooks/lib/environment-registry.js +813 -0
  172. package/plugins/hooks/lib/execution-path.js +427 -0
  173. package/plugins/hooks/lib/hook-error-recorder.js +245 -0
  174. package/plugins/hooks/lib/hook-logger.js +538 -0
  175. package/plugins/hooks/lib/hook-runner.js +97 -0
  176. package/plugins/hooks/lib/hook-runner.sh +44 -0
  177. package/plugins/hooks/lib/hook-state-manager.js +480 -0
  178. package/plugins/hooks/lib/memory-extractor.js +377 -0
  179. package/plugins/hooks/lib/memory-manager.js +673 -0
  180. package/plugins/hooks/lib/metrics-analyzer.js +489 -0
  181. package/plugins/hooks/lib/project-evolution/auto-fixer.js +511 -0
  182. package/plugins/hooks/lib/project-evolution/memory-manager.js +346 -0
  183. package/plugins/hooks/lib/project-evolution/pattern-detector.js +476 -0
  184. package/plugins/hooks/lib/project-evolution/semantic-indexer.js +480 -0
  185. package/plugins/hooks/lib/project-structure-detector.js +326 -0
  186. package/plugins/hooks/lib/rollback-tracker.js +346 -0
  187. package/plugins/hooks/lib/source-code-scanner.js +596 -0
  188. package/plugins/hooks/lib/technology-stack-detector.js +374 -0
  189. package/plugins/hooks/lib/test-failure-analyzer.js +375 -0
  190. package/plugins/hooks/lib/test-failure-fixer.js +268 -0
  191. package/plugins/hooks/lib/trace-context.js +277 -0
  192. package/plugins/hooks/lib/validation-patterns.js +415 -0
  193. package/plugins/hooks/memory-sync.js +171 -0
  194. package/plugins/hooks/pipeline-observer.js +413 -0
  195. package/plugins/hooks/scope-sentinel.js +204 -0
  196. package/plugins/hooks/trace-initialization.js +169 -0
  197. package/plugins/memory/templates/code-quality.yaml +149 -0
  198. package/plugins/memory/templates/multi-system.yaml +155 -0
  199. package/plugins/memory/templates/team-habits.yaml +119 -0
  200. package/plugins/memory/templates/testing.yaml +121 -0
  201. package/plugins/skills/README.en.md +47 -0
  202. package/plugins/skills/README.md +104 -0
  203. package/plugins/skills/benchmark-executor/README.md +93 -0
  204. package/plugins/skills/benchmark-executor/SKILL.md +647 -0
  205. package/plugins/skills/benchmark-generator/SKILL.md +349 -0
  206. package/plugins/skills/delivery-stage/SKILL.md +203 -0
  207. package/plugins/skills/design-stage/SKILL.md +216 -0
  208. package/plugins/skills/evolution-process/SKILL.md +291 -0
  209. package/plugins/skills/exploration-phase/SKILL.md +133 -0
  210. package/plugins/skills/implementation-stage/SKILL.md +179 -0
  211. package/plugins/skills/layer1-validation/SKILL.md +79 -0
  212. package/plugins/skills/pending-dashboard/SKILL.md +109 -0
  213. package/plugins/skills/project-evolution/SKILL.md +847 -0
  214. package/plugins/skills/requirement-stage/SKILL.md +183 -0
  215. package/plugins/skills/skill-forge/SKILL.md +223 -0
  216. package/plugins/skills/skill-forge/references/description-guide.md +92 -0
  217. package/plugins/skills/skill-forge/references/quality-rubric.md +104 -0
  218. package/plugins/skills/skill-forge/references/skill-template.md +106 -0
  219. package/plugins/skills/startup-guard/SKILL.md +38 -0
  220. package/plugins/skills/testing-stage/SKILL.md +195 -0
  221. package/scripts/cli/global-init.js +288 -0
  222. package/scripts/cli/global.js +324 -0
  223. package/scripts/cli/index.js +55 -0
  224. package/scripts/cli/init.js +382 -0
  225. package/scripts/cli/list.js +69 -0
  226. package/scripts/cli/org.js +340 -0
  227. package/scripts/cli/update.js +44 -0
  228. package/scripts/config/commands.config.js +145 -0
  229. package/scripts/config/hooks.config.js +197 -0
  230. package/scripts/evolution/evolution-router.js +273 -0
  231. package/scripts/evolution/evolution-signal-collector.js +307 -0
  232. package/scripts/evolution/knowledge-loader.js +346 -0
  233. package/scripts/evolution/marketplace.js +317 -0
  234. package/scripts/evolution/version-manager.js +371 -0
  235. package/scripts/install/agents.js +106 -0
  236. package/scripts/install/commands.js +133 -0
  237. package/scripts/install/constants.js +424 -0
  238. package/scripts/install/hook-logger.js +536 -0
  239. package/scripts/install/hooks.js +110 -0
  240. package/scripts/install/index.js +39 -0
  241. package/scripts/install/skills.js +95 -0
  242. package/scripts/postinstall.js +25 -0
  243. package/scripts/state.js +376 -0
@@ -0,0 +1,476 @@
1
+ /**
2
+ * Project-Evolve Pattern Detector
3
+ * 模式检测器 - 负责智能感知、代码扫描、模式识别
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { execSync } = require('child_process');
9
+
10
+ class PatternDetector {
11
+ constructor(projectRoot) {
12
+ this.projectRoot = projectRoot;
13
+ this.findings = [];
14
+ }
15
+
16
+ /**
17
+ * 扫描项目结构
18
+ */
19
+ scanProjectStructure() {
20
+ const structure = {
21
+ tech_stack: this.detectTechStack(),
22
+ directories: this.analyzeDirectories(),
23
+ is_multi_system: this.detectMultiSystem(),
24
+ subsystems: []
25
+ };
26
+
27
+ if (structure.is_multi_system) {
28
+ structure.subsystems = this.detectSubsystems();
29
+ }
30
+
31
+ return structure;
32
+ }
33
+
34
+ /**
35
+ * 检测技术栈
36
+ */
37
+ detectTechStack() {
38
+ const techStack = {
39
+ languages: [],
40
+ frameworks: [],
41
+ build_tools: [],
42
+ test_frameworks: [],
43
+ linters: []
44
+ };
45
+
46
+ // 检测 Node.js
47
+ if (fs.existsSync(path.join(this.projectRoot, 'package.json'))) {
48
+ techStack.languages.push('javascript');
49
+
50
+ const packageJson = JSON.parse(
51
+ fs.readFileSync(path.join(this.projectRoot, 'package.json'), 'utf8')
52
+ );
53
+
54
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
55
+
56
+ // 检测框架
57
+ if (deps.react) techStack.frameworks.push('react');
58
+ if (deps.vue) techStack.frameworks.push('vue');
59
+ if (deps.angular || deps['@angular/core']) techStack.frameworks.push('angular');
60
+ if (deps.next) techStack.frameworks.push('nextjs');
61
+ if (deps.express) techStack.frameworks.push('express');
62
+ if (deps.nestjs || deps['@nestjs/core']) techStack.frameworks.push('nestjs');
63
+
64
+ // 检测TypeScript
65
+ if (deps.typescript || packageJson.devDependencies?.typescript) {
66
+ techStack.languages.push('typescript');
67
+ }
68
+
69
+ // 检测测试框架
70
+ if (deps.jest) techStack.test_frameworks.push('jest');
71
+ if (deps.mocha) techStack.test_frameworks.push('mocha');
72
+ if (deps.vitest) techStack.test_frameworks.push('vitest');
73
+ if (deps.cypress) techStack.test_frameworks.push('cypress');
74
+ if (deps['@playwright/test']) techStack.test_frameworks.push('playwright');
75
+
76
+ // 检测lint工具
77
+ if (deps.eslint) techStack.linters.push('eslint');
78
+ if (deps.prettier) techStack.linters.push('prettier');
79
+ if (deps['@biomejs/biome']) techStack.linters.push('biome');
80
+ }
81
+
82
+ // 检测 Java
83
+ if (fs.existsSync(path.join(this.projectRoot, 'pom.xml'))) {
84
+ techStack.languages.push('java');
85
+ techStack.build_tools.push('maven');
86
+ }
87
+ if (fs.existsSync(path.join(this.projectRoot, 'build.gradle'))) {
88
+ techStack.languages.push('java');
89
+ techStack.build_tools.push('gradle');
90
+ }
91
+
92
+ // 检测 Go
93
+ if (fs.existsSync(path.join(this.projectRoot, 'go.mod'))) {
94
+ techStack.languages.push('go');
95
+ }
96
+
97
+ // 检测 Python
98
+ if (fs.existsSync(path.join(this.projectRoot, 'requirements.txt')) ||
99
+ fs.existsSync(path.join(this.projectRoot, 'pyproject.toml'))) {
100
+ techStack.languages.push('python');
101
+ }
102
+
103
+ return techStack;
104
+ }
105
+
106
+ /**
107
+ * 分析目录结构
108
+ */
109
+ analyzeDirectories() {
110
+ const structure = {
111
+ src: null,
112
+ test: null,
113
+ config: [],
114
+ docs: null
115
+ };
116
+
117
+ const commonSrcDirs = ['src', 'lib', 'app', 'source'];
118
+ const commonTestDirs = ['test', 'tests', '__tests__', 'spec', 'specs'];
119
+ const commonDocDirs = ['docs', 'doc', 'documentation', 'wiki'];
120
+
121
+ for (const dir of commonSrcDirs) {
122
+ if (fs.existsSync(path.join(this.projectRoot, dir))) {
123
+ structure.src = dir;
124
+ break;
125
+ }
126
+ }
127
+
128
+ for (const dir of commonTestDirs) {
129
+ if (fs.existsSync(path.join(this.projectRoot, dir))) {
130
+ structure.test = dir;
131
+ break;
132
+ }
133
+ }
134
+
135
+ for (const dir of commonDocDirs) {
136
+ if (fs.existsSync(path.join(this.projectRoot, dir))) {
137
+ structure.docs = dir;
138
+ break;
139
+ }
140
+ }
141
+
142
+ // 检测配置文件
143
+ const configFiles = [
144
+ '.eslintrc', '.eslintrc.js', '.eslintrc.json',
145
+ 'tsconfig.json', 'jsconfig.json',
146
+ 'jest.config.js', 'vitest.config.ts',
147
+ 'webpack.config.js', 'vite.config.ts',
148
+ '.prettierrc', 'biome.json'
149
+ ];
150
+
151
+ for (const file of configFiles) {
152
+ if (fs.existsSync(path.join(this.projectRoot, file))) {
153
+ structure.config.push(file);
154
+ }
155
+ }
156
+
157
+ return structure;
158
+ }
159
+
160
+ /**
161
+ * 检测是否为多系统项目
162
+ */
163
+ detectMultiSystem() {
164
+ const indicators = [
165
+ 'backend', 'frontend', 'mobile', 'web', 'server', 'client',
166
+ 'api', 'app', 'admin', 'dashboard',
167
+ 'data', 'ml', 'ai', 'model',
168
+ 'services', 'microservices'
169
+ ];
170
+
171
+ let subsystemCount = 0;
172
+
173
+ for (const indicator of indicators) {
174
+ const dirPath = path.join(this.projectRoot, indicator);
175
+ if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
176
+ subsystemCount++;
177
+ }
178
+ }
179
+
180
+ // 有2个或以上子系统目录,认为是多系统项目
181
+ return subsystemCount >= 2;
182
+ }
183
+
184
+ /**
185
+ * 检测子系统
186
+ */
187
+ detectSubsystems() {
188
+ const subsystems = [];
189
+ const subsystemPatterns = [
190
+ { name: 'backend', patterns: ['backend', 'server', 'api', 'services'] },
191
+ { name: 'frontend', patterns: ['frontend', 'web', 'client'] },
192
+ { name: 'mobile', patterns: ['mobile', 'app', 'ios', 'android'] },
193
+ { name: 'data', patterns: ['data', 'warehouse', 'datalake', 'etl'] },
194
+ { name: 'ai', patterns: ['ai', 'ml', 'model', 'predict'] }
195
+ ];
196
+
197
+ for (const { name, patterns } of subsystemPatterns) {
198
+ for (const pattern of patterns) {
199
+ const dirPath = path.join(this.projectRoot, pattern);
200
+
201
+ if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
202
+ const techStack = this.detectSubsystemTechStack(dirPath);
203
+
204
+ subsystems.push({
205
+ name: name,
206
+ path: pattern,
207
+ tech_stack: techStack,
208
+ build_file: this.findBuildFile(dirPath)
209
+ });
210
+
211
+ break;
212
+ }
213
+ }
214
+ }
215
+
216
+ return subsystems;
217
+ }
218
+
219
+ /**
220
+ * 检测子系统技术栈
221
+ */
222
+ detectSubsystemTechStack(subsystemPath) {
223
+ const techStack = [];
224
+
225
+ if (fs.existsSync(path.join(subsystemPath, 'package.json'))) {
226
+ techStack.push('nodejs');
227
+ }
228
+ if (fs.existsSync(path.join(subsystemPath, 'pom.xml'))) {
229
+ techStack.push('java');
230
+ }
231
+ if (fs.existsSync(path.join(subsystemPath, 'go.mod'))) {
232
+ techStack.push('go');
233
+ }
234
+ if (fs.existsSync(path.join(subsystemPath, 'requirements.txt'))) {
235
+ techStack.push('python');
236
+ }
237
+
238
+ return techStack;
239
+ }
240
+
241
+ /**
242
+ * 查找构建文件
243
+ */
244
+ findBuildFile(dirPath) {
245
+ const buildFiles = ['package.json', 'pom.xml', 'build.gradle', 'go.mod', 'Cargo.toml'];
246
+
247
+ for (const file of buildFiles) {
248
+ if (fs.existsSync(path.join(dirPath, file))) {
249
+ return file;
250
+ }
251
+ }
252
+
253
+ return null;
254
+ }
255
+
256
+ /**
257
+ * 检测代码质量问题
258
+ */
259
+ detectCodeQualityIssues(options = {}) {
260
+ const issues = [];
261
+
262
+ // 使用配置的lint工具检测
263
+ if (options.runLinters) {
264
+ const lintResults = this.runLinters();
265
+ issues.push(...lintResults);
266
+ }
267
+
268
+ // 检测重复代码
269
+ if (options.detectDuplicates) {
270
+ const duplicates = this.detectDuplicateCode();
271
+ issues.push(...duplicates);
272
+ }
273
+
274
+ // 检测死代码
275
+ if (options.detectDeadCode) {
276
+ const deadCode = this.detectDeadCode();
277
+ issues.push(...deadCode);
278
+ }
279
+
280
+ return issues;
281
+ }
282
+
283
+ /**
284
+ * 运行Lint工具
285
+ */
286
+ runLinters() {
287
+ const issues = [];
288
+
289
+ try {
290
+ // ESLint
291
+ if (fs.existsSync(path.join(this.projectRoot, '.eslintrc')) ||
292
+ fs.existsSync(path.join(this.projectRoot, '.eslintrc.js'))) {
293
+ const result = execSync('npx eslint . --format json', {
294
+ cwd: this.projectRoot,
295
+ encoding: 'utf8',
296
+ stdio: ['pipe', 'pipe', 'pipe']
297
+ });
298
+
299
+ const eslintResults = JSON.parse(result);
300
+ for (const fileResult of eslintResults) {
301
+ for (const message of fileResult.messages) {
302
+ issues.push({
303
+ type: 'lint',
304
+ severity: message.severity === 2 ? 'error' : 'warning',
305
+ file: fileResult.filePath,
306
+ line: message.line,
307
+ column: message.column,
308
+ message: message.message,
309
+ rule: message.ruleId,
310
+ tool: 'eslint'
311
+ });
312
+ }
313
+ }
314
+ }
315
+ } catch (error) {
316
+ // Lint错误也可能包含结果
317
+ if (error.stdout) {
318
+ try {
319
+ const eslintResults = JSON.parse(error.stdout);
320
+ // 处理结果...
321
+ } catch {}
322
+ }
323
+ }
324
+
325
+ return issues;
326
+ }
327
+
328
+ /**
329
+ * 检测重复代码(简化版)
330
+ */
331
+ detectDuplicateCode() {
332
+ // 实际实现中可以使用 jscpd 等工具
333
+ return [];
334
+ }
335
+
336
+ /**
337
+ * 检测死代码(简化版)
338
+ */
339
+ detectDeadCode() {
340
+ // 实际实现中可以使用 ts-prune, unimported 等工具
341
+ return [];
342
+ }
343
+
344
+ /**
345
+ * 分析测试覆盖缺口
346
+ */
347
+ analyzeTestCoverage() {
348
+ const coverage = {
349
+ overall: null,
350
+ gaps: []
351
+ };
352
+
353
+ try {
354
+ // 读取覆盖率报告
355
+ const coveragePath = path.join(this.projectRoot, 'coverage', 'coverage-summary.json');
356
+
357
+ if (fs.existsSync(coveragePath)) {
358
+ const coverageData = JSON.parse(fs.readFileSync(coveragePath, 'utf8'));
359
+ coverage.overall = coverageData.total;
360
+
361
+ // 识别低覆盖文件
362
+ for (const [file, data] of Object.entries(coverageData)) {
363
+ if (file === 'total') continue;
364
+
365
+ if (data.lines.pct < 60) {
366
+ coverage.gaps.push({
367
+ file: file,
368
+ line_coverage: data.lines.pct,
369
+ branch_coverage: data.branches?.pct || 0,
370
+ function_coverage: data.functions?.pct || 0
371
+ });
372
+ }
373
+ }
374
+ }
375
+ } catch (error) {
376
+ console.error('Failed to analyze coverage:', error.message);
377
+ }
378
+
379
+ return coverage;
380
+ }
381
+
382
+ /**
383
+ * 检测多系统接口漂移
384
+ */
385
+ detectInterfaceDrift(subsystems) {
386
+ const drifts = [];
387
+
388
+ // 简化实现:检查前后端接口定义
389
+ // 实际实现中需要解析API定义和调用代码
390
+
391
+ return drifts;
392
+ }
393
+
394
+ /**
395
+ * 检测共享逻辑机会
396
+ */
397
+ detectSharedLogicOpportunities(subsystems) {
398
+ const opportunities = [];
399
+
400
+ // 扫描各子系统的工具函数
401
+ const utilityPatterns = [];
402
+
403
+ for (const subsystem of subsystems) {
404
+ const utilsPath = path.join(this.projectRoot, subsystem.path, 'src', 'utils');
405
+
406
+ if (fs.existsSync(utilsPath)) {
407
+ // 收集工具函数签名
408
+ // 实际实现中需要解析AST
409
+ }
410
+ }
411
+
412
+ // 对比找出重复
413
+
414
+ return opportunities;
415
+ }
416
+
417
+ /**
418
+ * 计算文件变更频率
419
+ */
420
+ calculateChangeFrequency(filePath, days = 30) {
421
+ try {
422
+ const result = execSync(`git log --since="${days} days ago" --oneline -- "${filePath}" | wc -l`, {
423
+ cwd: this.projectRoot,
424
+ encoding: 'utf8'
425
+ });
426
+
427
+ return parseInt(result.trim(), 10);
428
+ } catch {
429
+ return 0;
430
+ }
431
+ }
432
+
433
+ /**
434
+ * 获取热点文件(变更频繁)
435
+ */
436
+ getHotspotFiles(options = {}) {
437
+ const hotspots = [];
438
+
439
+ try {
440
+ const days = options.days || 30;
441
+ const threshold = options.threshold || 5;
442
+
443
+ const result = execSync(
444
+ `git log --since="${days} days ago" --name-only --pretty=format: | sort | uniq -c | sort -rn | head -20`,
445
+ {
446
+ cwd: this.projectRoot,
447
+ encoding: 'utf8'
448
+ }
449
+ );
450
+
451
+ const lines = result.trim().split('\n');
452
+
453
+ for (const line of lines) {
454
+ const match = line.trim().match(/^\s*(\d+)\s+(.+)$/);
455
+
456
+ if (match) {
457
+ const count = parseInt(match[1], 10);
458
+ const file = match[2];
459
+
460
+ if (count >= threshold && file.match(/\.(js|ts|jsx|tsx|java|go|py)$/)) {
461
+ hotspots.push({
462
+ file: file,
463
+ change_count: count
464
+ });
465
+ }
466
+ }
467
+ }
468
+ } catch (error) {
469
+ console.error('Failed to get hotspots:', error.message);
470
+ }
471
+
472
+ return hotspots;
473
+ }
474
+ }
475
+
476
+ module.exports = PatternDetector;