@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.
- package/LICENSE +21 -0
- package/README.en.md +472 -0
- package/README.md +476 -0
- package/bin/autospec.js +3 -0
- package/knowledge/README.md +144 -0
- package/knowledge/checklists/code.md +182 -0
- package/knowledge/checklists/design.md +196 -0
- package/knowledge/checklists/release.md +70 -0
- package/knowledge/checklists/requirement.md +169 -0
- package/knowledge/checklists/test.md +46 -0
- package/knowledge/config/README.en.md +44 -0
- package/knowledge/config/README.md +44 -0
- package/knowledge/config/role-composition.yaml +98 -0
- package/knowledge/config/role-extensions.yaml +140 -0
- package/knowledge/config/skill-compositions.yaml +142 -0
- package/knowledge/config/team-stage.yaml +95 -0
- package/knowledge/config/team-tasks.yaml +139 -0
- package/knowledge/config/team-triggers.yaml +198 -0
- package/knowledge/config/validation-patterns.yaml +137 -0
- package/knowledge/domain/README.md +115 -0
- package/knowledge/domain/flows/README.md +194 -0
- package/knowledge/domain/glossary.md +143 -0
- package/knowledge/domain/rules.md +138 -0
- package/knowledge/environment/README.en.md +36 -0
- package/knowledge/environment/README.md +87 -0
- package/knowledge/environment/component-knowledge.md +316 -0
- package/knowledge/environment/detection-patterns.yaml +502 -0
- package/knowledge/environment/middleware-knowledge.md +237 -0
- package/knowledge/environment/template-registry.md +321 -0
- package/knowledge/guides/domain-driven-design.md +345 -0
- package/knowledge/guides/knowledge-management.md +369 -0
- package/knowledge/guides/requirement-engineering.md +329 -0
- package/knowledge/guides/stages/ai-effect-evaluator.md +93 -0
- package/knowledge/guides/stages/code-implementer.md +205 -0
- package/knowledge/guides/stages/code-reviewer.md +111 -0
- package/knowledge/guides/stages/consistency-checker.md +177 -0
- package/knowledge/guides/stages/design-planner.md +401 -0
- package/knowledge/guides/stages/design-reviewer.md +83 -0
- package/knowledge/guides/stages/integration-test-runner.md +105 -0
- package/knowledge/guides/stages/release-checker.md +205 -0
- package/knowledge/guides/stages/requirement-analyzer.md +195 -0
- package/knowledge/guides/stages/requirement-reviewer.md +83 -0
- package/knowledge/guides/stages/security-reviewer.md +89 -0
- package/knowledge/guides/stages/test-context-analyzer.md +250 -0
- package/knowledge/guides/stages/test-generator.md +241 -0
- package/knowledge/guides/stages/test-planner.md +183 -0
- package/knowledge/guides/stages/test-reviewer.md +76 -0
- package/knowledge/guides/stages/unit-test-runner.md +83 -0
- package/knowledge/guides/support/ai-agent-analyzer.md +362 -0
- package/knowledge/guides/support/ai-anomaly-analyzer.md +213 -0
- package/knowledge/guides/support/ai-artifact-evaluator.md +192 -0
- package/knowledge/guides/support/ai-capability-analyzer.md +193 -0
- package/knowledge/guides/support/ai-component-analyzer.md +169 -0
- package/knowledge/guides/support/ai-data-validator.md +276 -0
- package/knowledge/guides/support/ai-evaluation-planner.md +374 -0
- package/knowledge/guides/support/ai-path-evaluator.md +274 -0
- package/knowledge/guides/support/ai-pipeline-evaluator.md +219 -0
- package/knowledge/guides/support/ai-rag-analyzer.md +339 -0
- package/knowledge/guides/support/ai-task-assessor.md +418 -0
- package/knowledge/guides/support/ai-test-diagnostics.md +133 -0
- package/knowledge/guides/support/complexity-assessor.md +268 -0
- package/knowledge/guides/support/component-discovery.md +183 -0
- package/knowledge/guides/support/environment-scanner.md +207 -0
- package/knowledge/guides/support/environment-validator.md +207 -0
- package/knowledge/guides/support/knowledge-generator.md +234 -0
- package/knowledge/guides/support/methodology-extractor.md +55 -0
- package/knowledge/guides/support/pipeline-protocol.md +438 -0
- package/knowledge/guides/support/practice-logger.md +359 -0
- package/knowledge/guides/support/scope-inference.md +174 -0
- package/knowledge/guides/support/skill-distiller.md +91 -0
- package/knowledge/guides/support/skill-updater.md +45 -0
- package/knowledge/guides/support/skill-validator.md +72 -0
- package/knowledge/guides/support/team-orchestrator.md +323 -0
- package/knowledge/guides/support/tech-stack-analyzer.md +139 -0
- package/knowledge/guides/support/test-runner.md +254 -0
- package/knowledge/guides/system-design.md +352 -0
- package/knowledge/organization/ai-native-team.md +318 -0
- package/knowledge/organization/team-metrics.md +228 -0
- package/knowledge/principles/constitution.md +134 -0
- package/knowledge/principles/core-principles.md +368 -0
- package/knowledge/principles/design-philosophy.md +877 -0
- package/knowledge/principles/evolution.md +553 -0
- package/knowledge/process/01-requirement.md +113 -0
- package/knowledge/process/02-design.md +123 -0
- package/knowledge/process/03-implementation.md +90 -0
- package/knowledge/process/04-review.md +80 -0
- package/knowledge/process/05-testing.md +90 -0
- package/knowledge/process/06-delivery.md +88 -0
- package/knowledge/process/README.en.md +38 -0
- package/knowledge/process/README.md +48 -0
- package/knowledge/process/ai-sdlc.md +475 -0
- package/knowledge/process/overview.md +319 -0
- package/knowledge/standards/code-review.md +876 -0
- package/knowledge/standards/coding-style.md +940 -0
- package/knowledge/standards/data-consistency.md +1085 -0
- package/knowledge/standards/document-versioning.md +210 -0
- package/knowledge/standards/risk-detection.md +186 -0
- package/knowledge/templates/ai-evaluation.md +150 -0
- package/knowledge/templates/api-design.md +117 -0
- package/knowledge/templates/database-design.md +132 -0
- package/knowledge/templates/domain-driven-design.md +321 -0
- package/knowledge/templates/product-proposal.md +201 -0
- package/knowledge/templates/system-design.md +227 -0
- package/knowledge/templates/task-breakdown.md +107 -0
- package/knowledge/templates/test-case.md +170 -0
- package/package.json +53 -0
- package/plugins/.claude-plugin/plugin.json +134 -0
- package/plugins/agents/roles/ai-engineer.md +129 -0
- package/plugins/agents/roles/backend-engineer.md +165 -0
- package/plugins/agents/roles/ceo.md +94 -0
- package/plugins/agents/roles/data-engineer.md +135 -0
- package/plugins/agents/roles/devops-engineer.md +181 -0
- package/plugins/agents/roles/frontend-engineer.md +129 -0
- package/plugins/agents/roles/product-owner.md +98 -0
- package/plugins/agents/roles/quality-engineer.md +129 -0
- package/plugins/agents/roles/security-engineer.md +180 -0
- package/plugins/agents/roles/tech-lead.md +97 -0
- package/plugins/agents/support/blind-comparator.md +88 -0
- package/plugins/agents/support/consistency-checker.md +103 -0
- package/plugins/agents/support/failure-diagnostician.md +141 -0
- package/plugins/agents/support/independent-reviewer.md +80 -0
- package/plugins/agents/support/safety-auditor.md +121 -0
- package/plugins/agents/support/skill-benchmarker.md +86 -0
- package/plugins/agents/support/skill-forger.md +105 -0
- package/plugins/agents/support/stage-gate-evaluator.md +121 -0
- package/plugins/agents/support/test-coverage-reviewer.md +73 -0
- package/plugins/benchmarks/templates/README.md +44 -0
- package/plugins/benchmarks/templates/commands/explore-template.yaml +48 -0
- package/plugins/benchmarks/templates/pipeline/agile-template.yaml +84 -0
- package/plugins/benchmarks/templates/pipeline/waterfall-template.yaml +106 -0
- package/plugins/benchmarks/templates/skills/requirement-analyzer-template.yaml +48 -0
- package/plugins/commands/README.en.md +96 -0
- package/plugins/commands/README.md +96 -0
- package/plugins/commands/apply.md +191 -0
- package/plugins/commands/archive.md +76 -0
- package/plugins/commands/env-export.md +79 -0
- package/plugins/commands/env-sync.md +640 -0
- package/plugins/commands/env-template.md +223 -0
- package/plugins/commands/env-update.md +264 -0
- package/plugins/commands/env-validate.md +176 -0
- package/plugins/commands/env.md +79 -0
- package/plugins/commands/explore.md +76 -0
- package/plugins/commands/field-evolve.md +536 -0
- package/plugins/commands/memory.md +249 -0
- package/plugins/commands/project-evolve.md +821 -0
- package/plugins/commands/propose.md +93 -0
- package/plugins/commands/review.md +140 -0
- package/plugins/commands/run.md +224 -0
- package/plugins/commands/status.md +62 -0
- package/plugins/commands/validate.md +108 -0
- package/plugins/hooks/README.en.md +56 -0
- package/plugins/hooks/README.md +56 -0
- package/plugins/hooks/ai-project-guard.js +329 -0
- package/plugins/hooks/artifact-evaluation-hook.js +237 -0
- package/plugins/hooks/constitution-guard.js +211 -0
- package/plugins/hooks/environment-autocommit.js +264 -0
- package/plugins/hooks/environment-manager.js +778 -0
- package/plugins/hooks/execution-tracker.js +354 -0
- package/plugins/hooks/frozen-zone-guard.js +140 -0
- package/plugins/hooks/layer1-validator.js +423 -0
- package/plugins/hooks/lib/artifact-evaluator.js +414 -0
- package/plugins/hooks/lib/benchmarks/change-detector.js +390 -0
- package/plugins/hooks/lib/benchmarks/evaluator.js +605 -0
- package/plugins/hooks/lib/benchmarks/integration-example.js +169 -0
- package/plugins/hooks/lib/data-and-ai-detector.js +275 -0
- package/plugins/hooks/lib/detection-pattern-loader.js +865 -0
- package/plugins/hooks/lib/directory-discovery.js +395 -0
- package/plugins/hooks/lib/environment-config-loader.js +341 -0
- package/plugins/hooks/lib/environment-detector.js +553 -0
- package/plugins/hooks/lib/environment-evolver.js +564 -0
- package/plugins/hooks/lib/environment-registry.js +813 -0
- package/plugins/hooks/lib/execution-path.js +427 -0
- package/plugins/hooks/lib/hook-error-recorder.js +245 -0
- package/plugins/hooks/lib/hook-logger.js +538 -0
- package/plugins/hooks/lib/hook-runner.js +97 -0
- package/plugins/hooks/lib/hook-runner.sh +44 -0
- package/plugins/hooks/lib/hook-state-manager.js +480 -0
- package/plugins/hooks/lib/memory-extractor.js +377 -0
- package/plugins/hooks/lib/memory-manager.js +673 -0
- package/plugins/hooks/lib/metrics-analyzer.js +489 -0
- package/plugins/hooks/lib/project-evolution/auto-fixer.js +511 -0
- package/plugins/hooks/lib/project-evolution/memory-manager.js +346 -0
- package/plugins/hooks/lib/project-evolution/pattern-detector.js +476 -0
- package/plugins/hooks/lib/project-evolution/semantic-indexer.js +480 -0
- package/plugins/hooks/lib/project-structure-detector.js +326 -0
- package/plugins/hooks/lib/rollback-tracker.js +346 -0
- package/plugins/hooks/lib/source-code-scanner.js +596 -0
- package/plugins/hooks/lib/technology-stack-detector.js +374 -0
- package/plugins/hooks/lib/test-failure-analyzer.js +375 -0
- package/plugins/hooks/lib/test-failure-fixer.js +268 -0
- package/plugins/hooks/lib/trace-context.js +277 -0
- package/plugins/hooks/lib/validation-patterns.js +415 -0
- package/plugins/hooks/memory-sync.js +171 -0
- package/plugins/hooks/pipeline-observer.js +413 -0
- package/plugins/hooks/scope-sentinel.js +204 -0
- package/plugins/hooks/trace-initialization.js +169 -0
- package/plugins/memory/templates/code-quality.yaml +149 -0
- package/plugins/memory/templates/multi-system.yaml +155 -0
- package/plugins/memory/templates/team-habits.yaml +119 -0
- package/plugins/memory/templates/testing.yaml +121 -0
- package/plugins/skills/README.en.md +47 -0
- package/plugins/skills/README.md +104 -0
- package/plugins/skills/benchmark-executor/README.md +93 -0
- package/plugins/skills/benchmark-executor/SKILL.md +647 -0
- package/plugins/skills/benchmark-generator/SKILL.md +349 -0
- package/plugins/skills/delivery-stage/SKILL.md +203 -0
- package/plugins/skills/design-stage/SKILL.md +216 -0
- package/plugins/skills/evolution-process/SKILL.md +291 -0
- package/plugins/skills/exploration-phase/SKILL.md +133 -0
- package/plugins/skills/implementation-stage/SKILL.md +179 -0
- package/plugins/skills/layer1-validation/SKILL.md +79 -0
- package/plugins/skills/pending-dashboard/SKILL.md +109 -0
- package/plugins/skills/project-evolution/SKILL.md +847 -0
- package/plugins/skills/requirement-stage/SKILL.md +183 -0
- package/plugins/skills/skill-forge/SKILL.md +223 -0
- package/plugins/skills/skill-forge/references/description-guide.md +92 -0
- package/plugins/skills/skill-forge/references/quality-rubric.md +104 -0
- package/plugins/skills/skill-forge/references/skill-template.md +106 -0
- package/plugins/skills/startup-guard/SKILL.md +38 -0
- package/plugins/skills/testing-stage/SKILL.md +195 -0
- package/scripts/cli/global-init.js +288 -0
- package/scripts/cli/global.js +324 -0
- package/scripts/cli/index.js +55 -0
- package/scripts/cli/init.js +382 -0
- package/scripts/cli/list.js +69 -0
- package/scripts/cli/org.js +340 -0
- package/scripts/cli/update.js +44 -0
- package/scripts/config/commands.config.js +145 -0
- package/scripts/config/hooks.config.js +197 -0
- package/scripts/evolution/evolution-router.js +273 -0
- package/scripts/evolution/evolution-signal-collector.js +307 -0
- package/scripts/evolution/knowledge-loader.js +346 -0
- package/scripts/evolution/marketplace.js +317 -0
- package/scripts/evolution/version-manager.js +371 -0
- package/scripts/install/agents.js +106 -0
- package/scripts/install/commands.js +133 -0
- package/scripts/install/constants.js +424 -0
- package/scripts/install/hook-logger.js +536 -0
- package/scripts/install/hooks.js +110 -0
- package/scripts/install/index.js +39 -0
- package/scripts/install/skills.js +95 -0
- package/scripts/postinstall.js +25 -0
- package/scripts/state.js +376 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmarks Integration Example
|
|
3
|
+
* 实战项目 benchmarks 集成示例
|
|
4
|
+
*
|
|
5
|
+
* 展示如何在实际项目中使用 AutoSpec benchmarks 系统进行自动化评测
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const ChangeDetector = require('./change-detector');
|
|
9
|
+
const BenchmarkEvaluator = require('./evaluator');
|
|
10
|
+
|
|
11
|
+
class BenchmarksIntegration {
|
|
12
|
+
constructor(projectRoot) {
|
|
13
|
+
this.projectRoot = projectRoot;
|
|
14
|
+
this.changeDetector = new ChangeDetector(projectRoot);
|
|
15
|
+
this.evaluator = new BenchmarkEvaluator(projectRoot);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 初始化 benchmarks 系统
|
|
20
|
+
*/
|
|
21
|
+
init() {
|
|
22
|
+
this.changeDetector.init();
|
|
23
|
+
this.evaluator.init();
|
|
24
|
+
|
|
25
|
+
// 启动文件监听
|
|
26
|
+
this.setupWatchers();
|
|
27
|
+
|
|
28
|
+
console.log('✅ Benchmarks 系统已初始化');
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 设置文件监听器
|
|
34
|
+
*/
|
|
35
|
+
setupWatchers() {
|
|
36
|
+
const stages = ['requirement', 'design', 'implementation', 'testing'];
|
|
37
|
+
|
|
38
|
+
for (const stage of stages) {
|
|
39
|
+
this.changeDetector.on('change', (changes) => {
|
|
40
|
+
console.log(`\n📝 检测到 ${changes.stage} 阶段产出物变更:`);
|
|
41
|
+
console.log(this.changeDetector.generateChangeSummary(changes));
|
|
42
|
+
|
|
43
|
+
// 自动触发评测
|
|
44
|
+
this.runEvaluation(changes.stage);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 执行评测
|
|
51
|
+
*/
|
|
52
|
+
async runEvaluation(stage) {
|
|
53
|
+
console.log(`\n🔍 正在执行 ${stage} 阶段 benchmarks 评测...`);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const report = await this.evaluator.evaluate(stage, {
|
|
57
|
+
trigger: 'auto'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// 输出评测结果摘要
|
|
61
|
+
this.printReportSummary(report);
|
|
62
|
+
|
|
63
|
+
// 根据结果采取行动
|
|
64
|
+
await this.handleEvaluationResult(report);
|
|
65
|
+
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`评测执行失败: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 打印评测报告摘要
|
|
73
|
+
*/
|
|
74
|
+
printReportSummary(report) {
|
|
75
|
+
const { summary } = report;
|
|
76
|
+
|
|
77
|
+
console.log('\n📊 评测结果:');
|
|
78
|
+
console.log(` 总分: ${summary.overall_score} (${summary.grade})`);
|
|
79
|
+
console.log(` 通过: ${summary.passed}/${summary.total}`);
|
|
80
|
+
console.log(` 通过率: ${summary.pass_rate}%`);
|
|
81
|
+
console.log(` 耗时: ${summary.duration_ms}ms`);
|
|
82
|
+
|
|
83
|
+
// 显示未通过的 benchmark
|
|
84
|
+
const failed = report.results.filter(r => r.status === 'failed');
|
|
85
|
+
if (failed.length > 0) {
|
|
86
|
+
console.log('\n❌ 未通过的 Benchmarks:');
|
|
87
|
+
for (const result of failed) {
|
|
88
|
+
console.log(` - ${result.benchmark_id}: ${result.name} (${result.score}分)`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 显示改进建议
|
|
93
|
+
if (report.recommendations.length > 0) {
|
|
94
|
+
console.log('\n💡 改进建议:');
|
|
95
|
+
for (const rec of report.recommendations.slice(0, 3)) {
|
|
96
|
+
console.log(` [${rec.priority}] ${rec.suggestion}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 处理评测结果
|
|
103
|
+
*/
|
|
104
|
+
async handleEvaluationResult(report) {
|
|
105
|
+
const { summary } = report;
|
|
106
|
+
|
|
107
|
+
// 判断是否通过准出标准
|
|
108
|
+
const passed = summary.overall_score >= 80 &&
|
|
109
|
+
report.results.every(r =>
|
|
110
|
+
r.priority !== 'P0' || r.status === 'passed'
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (passed) {
|
|
114
|
+
console.log('\n✅ 评测通过,允许进入下一阶段');
|
|
115
|
+
this.updateStageState(report.stage, 'passed');
|
|
116
|
+
} else {
|
|
117
|
+
console.log('\n⚠️ 评测未通过,需要改进');
|
|
118
|
+
this.updateStageState(report.stage, 'failed');
|
|
119
|
+
|
|
120
|
+
// 如果有可自动修复的建议,尝试自动修复
|
|
121
|
+
const autoFixable = report.recommendations.filter(r => r.auto_fixable);
|
|
122
|
+
if (autoFixable.length > 0) {
|
|
123
|
+
console.log(`\n🔧 尝试自动修复 ${autoFixable.length} 个问题...`);
|
|
124
|
+
// 执行自动修复...
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 更新阶段状态
|
|
131
|
+
*/
|
|
132
|
+
updateStageState(stage, status) {
|
|
133
|
+
// 更新 .autospec/runtime/state.json
|
|
134
|
+
const statePath = `${this.projectRoot}/.autospec/runtime/state.json`;
|
|
135
|
+
// 实现状态更新逻辑...
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 手动触发评测
|
|
140
|
+
*/
|
|
141
|
+
async manualEvaluate(stage) {
|
|
142
|
+
return this.runEvaluation(stage);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 获取评测历史趋势
|
|
147
|
+
*/
|
|
148
|
+
getTrend(stage) {
|
|
149
|
+
return this.evaluator.getTrend(stage);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 使用示例
|
|
154
|
+
async function main() {
|
|
155
|
+
const projectRoot = process.cwd();
|
|
156
|
+
const benchmarks = new BenchmarksIntegration(projectRoot);
|
|
157
|
+
|
|
158
|
+
benchmarks.init();
|
|
159
|
+
|
|
160
|
+
// 手动触发 requirement 阶段评测
|
|
161
|
+
// await benchmarks.manualEvaluate('requirement');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports = { BenchmarksIntegration };
|
|
165
|
+
|
|
166
|
+
// 如果直接运行此文件
|
|
167
|
+
if (require.main === module) {
|
|
168
|
+
main().catch(console.error);
|
|
169
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据/AI 开发检测模块(配置驱动)
|
|
3
|
+
*
|
|
4
|
+
* 检测数据开发和 AI 开发相关组件,规则从配置文件加载。
|
|
5
|
+
* 包括:
|
|
6
|
+
* - 数据仓库、ETL 管道、数据处理
|
|
7
|
+
* - 模型训练、推理服务、LLM 应用、Agent 框架
|
|
8
|
+
* - 向量存储、评测框架
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import { getDataComponentRules, getAIComponentRules, getIgnoreDirectories } from './environment-config-loader.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 检测数据/AI 组件
|
|
17
|
+
* @param {string} projectDir - 项目根目录
|
|
18
|
+
* @param {Array} techStacks - 已检测的技术栈
|
|
19
|
+
* @returns {Object} 数据/AI 组件检测结果
|
|
20
|
+
*/
|
|
21
|
+
export function detectDataAIComponents(projectDir, techStacks) {
|
|
22
|
+
const result = {
|
|
23
|
+
hasDataComponents: false,
|
|
24
|
+
hasAIComponents: false,
|
|
25
|
+
needsEvaluation: false,
|
|
26
|
+
components: []
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 从配置加载规则
|
|
30
|
+
const dataRules = getDataComponentRules();
|
|
31
|
+
const aiRules = getAIComponentRules();
|
|
32
|
+
const ignoreDirs = getIgnoreDirectories();
|
|
33
|
+
|
|
34
|
+
// 收集所有依赖
|
|
35
|
+
const allDependencies = new Set();
|
|
36
|
+
for (const tech of techStacks) {
|
|
37
|
+
if (tech.dependencies) {
|
|
38
|
+
tech.dependencies.forEach(d => allDependencies.add(d.toLowerCase()));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 扫描目录
|
|
43
|
+
const directories = scanDirectories(projectDir, ignoreDirs);
|
|
44
|
+
|
|
45
|
+
// 扫描文件模式
|
|
46
|
+
const filePatterns = scanFilePatterns(projectDir, ignoreDirs);
|
|
47
|
+
|
|
48
|
+
// 检测数据组件
|
|
49
|
+
for (const [key, rule] of Object.entries(dataRules)) {
|
|
50
|
+
const detected = detectComponent(key, rule, directories, filePatterns, allDependencies, projectDir);
|
|
51
|
+
if (detected) {
|
|
52
|
+
result.components.push(detected);
|
|
53
|
+
result.hasDataComponents = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 检测 AI 组件
|
|
58
|
+
const detectedAIComponents = {};
|
|
59
|
+
for (const [key, rule] of Object.entries(aiRules)) {
|
|
60
|
+
// 跳过需要组合检测的
|
|
61
|
+
if (rule.requiresBoth) continue;
|
|
62
|
+
|
|
63
|
+
const detected = detectComponent(key, rule, directories, filePatterns, allDependencies, projectDir);
|
|
64
|
+
if (detected) {
|
|
65
|
+
result.components.push(detected);
|
|
66
|
+
result.hasAIComponents = true;
|
|
67
|
+
detectedAIComponents[key] = detected;
|
|
68
|
+
|
|
69
|
+
if (rule.needsEvaluation) {
|
|
70
|
+
result.needsEvaluation = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 检测 RAG 应用(需要向量存储 + LLM)
|
|
76
|
+
const ragRule = aiRules.ragApplication;
|
|
77
|
+
if (ragRule && detectedAIComponents.vectorStore && detectedAIComponents.llmApplication) {
|
|
78
|
+
result.components.push({
|
|
79
|
+
name: 'ragApplication',
|
|
80
|
+
label: ragRule.label,
|
|
81
|
+
type: ragRule.type,
|
|
82
|
+
needsEvaluation: true,
|
|
83
|
+
detectedFrom: 'combination',
|
|
84
|
+
components: ['vectorStore', 'llmApplication']
|
|
85
|
+
});
|
|
86
|
+
result.needsEvaluation = true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 检测单个组件
|
|
94
|
+
*/
|
|
95
|
+
function detectComponent(key, rule, directories, filePatterns, dependencies, projectDir) {
|
|
96
|
+
const signals = [];
|
|
97
|
+
|
|
98
|
+
// 检查构建文件
|
|
99
|
+
if (rule.buildFiles) {
|
|
100
|
+
for (const bf of rule.buildFiles) {
|
|
101
|
+
const found = findBuildFile(projectDir, bf);
|
|
102
|
+
if (found) {
|
|
103
|
+
signals.push({ type: 'buildFile', value: found, weight: 3 });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 检查目录
|
|
109
|
+
if (rule.directories) {
|
|
110
|
+
for (const dir of rule.directories) {
|
|
111
|
+
if (directories.has(dir.toLowerCase())) {
|
|
112
|
+
signals.push({ type: 'directory', value: dir, weight: 2 });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 检查文件模式
|
|
118
|
+
if (rule.filePatterns) {
|
|
119
|
+
for (const pattern of rule.filePatterns) {
|
|
120
|
+
if (filePatterns.has(pattern.toLowerCase().replace('*', ''))) {
|
|
121
|
+
signals.push({ type: 'filePattern', value: pattern, weight: 1 });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 检查依赖
|
|
127
|
+
if (rule.dependencies) {
|
|
128
|
+
for (const dep of rule.dependencies) {
|
|
129
|
+
if (dependencies.has(dep.toLowerCase())) {
|
|
130
|
+
signals.push({ type: 'dependency', value: dep, weight: 2 });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 如果有信号,返回检测结果
|
|
136
|
+
if (signals.length > 0) {
|
|
137
|
+
const totalWeight = signals.reduce((sum, s) => sum + s.weight, 0);
|
|
138
|
+
return {
|
|
139
|
+
name: rule.label || key,
|
|
140
|
+
type: rule.type,
|
|
141
|
+
needsEvaluation: rule.needsEvaluation || false,
|
|
142
|
+
signals: signals,
|
|
143
|
+
confidence: totalWeight >= 3 ? 'high' : (totalWeight >= 2 ? 'medium' : 'low')
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 扫描目录
|
|
152
|
+
*/
|
|
153
|
+
function scanDirectories(projectDir, ignoreDirs) {
|
|
154
|
+
const directories = new Set();
|
|
155
|
+
|
|
156
|
+
function scan(dir, depth) {
|
|
157
|
+
if (depth > 2) return;
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
161
|
+
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
if (entry.isDirectory() && !shouldIgnoreDir(entry.name, ignoreDirs)) {
|
|
164
|
+
directories.add(entry.name.toLowerCase());
|
|
165
|
+
scan(path.join(dir, entry.name), depth + 1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch (e) {
|
|
169
|
+
// 忽略
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
scan(projectDir, 0);
|
|
174
|
+
return directories;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 扫描文件模式
|
|
179
|
+
*/
|
|
180
|
+
function scanFilePatterns(projectDir, ignoreDirs) {
|
|
181
|
+
const patterns = new Set();
|
|
182
|
+
|
|
183
|
+
function scan(dir, depth) {
|
|
184
|
+
if (depth > 2) return;
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
188
|
+
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
const fullPath = path.join(dir, entry.name);
|
|
191
|
+
|
|
192
|
+
if (entry.isDirectory() && !shouldIgnoreDir(entry.name, ignoreDirs)) {
|
|
193
|
+
scan(fullPath, depth + 1);
|
|
194
|
+
} else if (entry.isFile()) {
|
|
195
|
+
// 提取文件名模式
|
|
196
|
+
const name = entry.name.toLowerCase();
|
|
197
|
+
patterns.add(name);
|
|
198
|
+
|
|
199
|
+
// 提取关键词模式
|
|
200
|
+
if (name.includes('train')) patterns.add('train');
|
|
201
|
+
if (name.includes('eval')) patterns.add('eval');
|
|
202
|
+
if (name.includes('agent')) patterns.add('agent');
|
|
203
|
+
if (name.includes('pipeline')) patterns.add('pipeline');
|
|
204
|
+
if (name.includes('dag')) patterns.add('dag');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// 忽略
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
scan(projectDir, 0);
|
|
213
|
+
return patterns;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 查找构建文件
|
|
218
|
+
*/
|
|
219
|
+
function findBuildFile(projectDir, fileName) {
|
|
220
|
+
const searchPaths = ['.', 'src', 'lib', 'app'];
|
|
221
|
+
|
|
222
|
+
for (const sp of searchPaths) {
|
|
223
|
+
const fullPath = path.join(projectDir, sp, fileName);
|
|
224
|
+
if (fs.existsSync(fullPath)) {
|
|
225
|
+
return path.join(sp, fileName);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 判断是否应该忽略的目录
|
|
234
|
+
*/
|
|
235
|
+
function shouldIgnoreDir(name, ignoreDirs) {
|
|
236
|
+
return ignoreDirs.includes(name) || name.startsWith('.');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 获取数据/AI 组件摘要
|
|
241
|
+
*/
|
|
242
|
+
export function getDataAISummary(components) {
|
|
243
|
+
if (!components || components.length === 0) {
|
|
244
|
+
return '未检测到数据/AI 组件';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const lines = [];
|
|
248
|
+
const dataComps = components.filter(c =>
|
|
249
|
+
c.type.startsWith('data') || c.type === 'etl-pipeline'
|
|
250
|
+
);
|
|
251
|
+
const aiComps = components.filter(c =>
|
|
252
|
+
c.type.includes('llm') || c.type.includes('agent') ||
|
|
253
|
+
c.type.includes('model') || c.type.includes('inference') ||
|
|
254
|
+
c.type.includes('vector') || c.type.includes('rag') ||
|
|
255
|
+
c.type.includes('evaluation')
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
if (dataComps.length > 0) {
|
|
259
|
+
lines.push('数据组件:');
|
|
260
|
+
for (const comp of dataComps) {
|
|
261
|
+
const evalLabel = comp.needsEvaluation ? ' [需效果评测]' : '';
|
|
262
|
+
lines.push(` - ${comp.name}${evalLabel}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (aiComps.length > 0) {
|
|
267
|
+
lines.push('AI 组件:');
|
|
268
|
+
for (const comp of aiComps) {
|
|
269
|
+
const evalLabel = comp.needsEvaluation ? ' [需效果评测]' : '';
|
|
270
|
+
lines.push(` - ${comp.name}${evalLabel}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return lines.join('\n');
|
|
275
|
+
}
|