@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,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Evaluator - 产出物评测核心模块
|
|
3
|
+
*
|
|
4
|
+
* 提供产出物质量评测功能:
|
|
5
|
+
* - 结构完整性检查(自动化,100%执行)
|
|
6
|
+
* - 一致性检测(复用 consistency-checker)
|
|
7
|
+
* - 质量评估(AI,采样执行)
|
|
8
|
+
* - 下游反馈追踪
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import { getState, getMetrics, updateMetrics } from './hook-state-manager.js';
|
|
14
|
+
import { getTraceId, recordEvent } from './trace-context.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 评测类型
|
|
18
|
+
*/
|
|
19
|
+
export const EVAL_TYPES = {
|
|
20
|
+
STRUCTURE: 'structure', // 结构完整性
|
|
21
|
+
CONSISTENCY: 'consistency', // 一致性检测
|
|
22
|
+
QUALITY: 'quality', // 质量评估(AI)
|
|
23
|
+
FEEDBACK: 'feedback' // 下游反馈
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 产出物类型
|
|
28
|
+
*/
|
|
29
|
+
export const ARTIFACT_TYPES = {
|
|
30
|
+
REQUIREMENT: 'requirement.md',
|
|
31
|
+
DESIGN: 'design.md',
|
|
32
|
+
CODE: 'code',
|
|
33
|
+
REVIEW: 'review',
|
|
34
|
+
TEST: 'test',
|
|
35
|
+
EVALUATION: 'evaluation'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 各产出物的结构完整性检查规则
|
|
40
|
+
*/
|
|
41
|
+
export const STRUCTURE_RULES = {
|
|
42
|
+
'requirement.md': {
|
|
43
|
+
requiredSections: ['背景', '目标', '范围', '验收标准'],
|
|
44
|
+
minLength: 500,
|
|
45
|
+
patterns: [
|
|
46
|
+
{ name: 'acceptanceCriteria', pattern: /验收标准|Acceptance/i, required: true },
|
|
47
|
+
{ name: 'scope', pattern: /范围|Scope/i, required: true }
|
|
48
|
+
],
|
|
49
|
+
noVagueWords: ['可能', '大概', '尽量', '适当', '也许']
|
|
50
|
+
},
|
|
51
|
+
'design.md': {
|
|
52
|
+
requiredSections: ['架构设计', '接口设计', '数据设计'],
|
|
53
|
+
minLength: 800,
|
|
54
|
+
patterns: [
|
|
55
|
+
{ name: 'api', pattern: /API|接口|endpoint/i, required: true },
|
|
56
|
+
{ name: 'requirementRef', pattern: /requirement|需求/i, required: false }
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
'review-requirement.md': {
|
|
60
|
+
requiredSections: ['审查结论', '问题清单', '改进建议'],
|
|
61
|
+
minLength: 300
|
|
62
|
+
},
|
|
63
|
+
'review-design.md': {
|
|
64
|
+
requiredSections: ['审查结论', '问题清单', '改进建议'],
|
|
65
|
+
minLength: 300
|
|
66
|
+
},
|
|
67
|
+
'review-code.md': {
|
|
68
|
+
requiredSections: ['审查结论', '问题清单', '改进建议'],
|
|
69
|
+
minLength: 300
|
|
70
|
+
},
|
|
71
|
+
'consistency-report.md': {
|
|
72
|
+
requiredSections: ['检查结论', '一致性分析'],
|
|
73
|
+
minLength: 200
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 产出物评测配置
|
|
79
|
+
*/
|
|
80
|
+
export const ARTIFACT_EVAL_CONFIG = {
|
|
81
|
+
'requirement.md': {
|
|
82
|
+
structure: { enabled: true, weight: 0.2 },
|
|
83
|
+
consistency: { enabled: false }, // 第一个产物,无需一致性检查
|
|
84
|
+
quality: { enabled: true, sampleRate: 0.3, weight: 0.5 },
|
|
85
|
+
feedback: { enabled: true, weight: 0.3 }
|
|
86
|
+
},
|
|
87
|
+
'design.md': {
|
|
88
|
+
structure: { enabled: true, weight: 0.15 },
|
|
89
|
+
consistency: { enabled: true, weight: 0.25 },
|
|
90
|
+
quality: { enabled: true, sampleRate: 0.3, weight: 0.4 },
|
|
91
|
+
feedback: { enabled: true, weight: 0.2 }
|
|
92
|
+
},
|
|
93
|
+
'review-code.md': {
|
|
94
|
+
structure: { enabled: true, weight: 0.15 },
|
|
95
|
+
consistency: { enabled: false },
|
|
96
|
+
quality: { enabled: true, sampleRate: 0.5, weight: 0.55 },
|
|
97
|
+
feedback: { enabled: true, weight: 0.3 }
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 执行结构完整性检查
|
|
103
|
+
* @param {string} artifactPath - 产出物路径
|
|
104
|
+
* @param {string} artifactType - 产出物类型
|
|
105
|
+
* @returns {Object} 检查结果
|
|
106
|
+
*/
|
|
107
|
+
export function checkStructure(artifactPath, artifactType) {
|
|
108
|
+
const rules = STRUCTURE_RULES[artifactType];
|
|
109
|
+
|
|
110
|
+
if (!rules) {
|
|
111
|
+
return {
|
|
112
|
+
passed: true,
|
|
113
|
+
score: 100,
|
|
114
|
+
issues: [],
|
|
115
|
+
message: '无结构检查规则,默认通过'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const issues = [];
|
|
120
|
+
let score = 100;
|
|
121
|
+
|
|
122
|
+
// 检查文件是否存在
|
|
123
|
+
if (!fs.existsSync(artifactPath)) {
|
|
124
|
+
return {
|
|
125
|
+
passed: false,
|
|
126
|
+
score: 0,
|
|
127
|
+
issues: [{ type: 'file_not_found', message: `文件不存在: ${artifactPath}` }],
|
|
128
|
+
message: '文件不存在'
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 读取文件内容
|
|
133
|
+
const content = fs.readFileSync(artifactPath, 'utf-8');
|
|
134
|
+
|
|
135
|
+
// 检查最小长度
|
|
136
|
+
if (rules.minLength && content.length < rules.minLength) {
|
|
137
|
+
issues.push({
|
|
138
|
+
type: 'too_short',
|
|
139
|
+
message: `内容长度不足: ${content.length} < ${rules.minLength}`,
|
|
140
|
+
severity: 'medium'
|
|
141
|
+
});
|
|
142
|
+
score -= 10;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 检查必要章节
|
|
146
|
+
if (rules.requiredSections) {
|
|
147
|
+
for (const section of rules.requiredSections) {
|
|
148
|
+
if (!content.includes(section)) {
|
|
149
|
+
issues.push({
|
|
150
|
+
type: 'missing_section',
|
|
151
|
+
message: `缺少必要章节: ${section}`,
|
|
152
|
+
severity: 'high'
|
|
153
|
+
});
|
|
154
|
+
score -= 15;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 检查模式匹配
|
|
160
|
+
if (rules.patterns) {
|
|
161
|
+
for (const pattern of rules.patterns) {
|
|
162
|
+
const found = pattern.pattern.test(content);
|
|
163
|
+
if (pattern.required && !found) {
|
|
164
|
+
issues.push({
|
|
165
|
+
type: 'missing_pattern',
|
|
166
|
+
message: `缺少必要内容: ${pattern.name}`,
|
|
167
|
+
severity: 'medium'
|
|
168
|
+
});
|
|
169
|
+
score -= 10;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 检查歧义词
|
|
175
|
+
if (rules.noVagueWords) {
|
|
176
|
+
for (const word of rules.noVagueWords) {
|
|
177
|
+
if (content.includes(word)) {
|
|
178
|
+
issues.push({
|
|
179
|
+
type: 'vague_word',
|
|
180
|
+
message: `发现歧义词: "${word}"`,
|
|
181
|
+
severity: 'low'
|
|
182
|
+
});
|
|
183
|
+
score -= 2;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
passed: score >= 60,
|
|
190
|
+
score: Math.max(0, score),
|
|
191
|
+
issues,
|
|
192
|
+
message: score >= 60 ? '结构检查通过' : '结构检查未通过'
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 检测产出物类型
|
|
198
|
+
* @param {string} filePath - 文件路径
|
|
199
|
+
* @returns {string|null} 产出物类型
|
|
200
|
+
*/
|
|
201
|
+
export function detectArtifactType(filePath) {
|
|
202
|
+
const fileName = path.basename(filePath);
|
|
203
|
+
|
|
204
|
+
for (const [type, pattern] of Object.entries(ARTIFACT_TYPES)) {
|
|
205
|
+
if (fileName.includes(pattern) || fileName === pattern) {
|
|
206
|
+
return type;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 检查路径模式
|
|
211
|
+
if (filePath.includes('requirement')) return 'REQUIREMENT';
|
|
212
|
+
if (filePath.includes('design')) return 'DESIGN';
|
|
213
|
+
if (filePath.includes('review-')) return 'REVIEW';
|
|
214
|
+
if (filePath.includes('test')) return 'TEST';
|
|
215
|
+
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 判断是否为关键产出物
|
|
221
|
+
* @param {string} filePath - 文件路径
|
|
222
|
+
* @returns {boolean}
|
|
223
|
+
*/
|
|
224
|
+
export function isKeyArtifact(filePath) {
|
|
225
|
+
const keyPatterns = [
|
|
226
|
+
'requirement.md',
|
|
227
|
+
'design.md',
|
|
228
|
+
'review-requirement.md',
|
|
229
|
+
'review-design.md',
|
|
230
|
+
'review-code.md',
|
|
231
|
+
'consistency-report.md',
|
|
232
|
+
'evaluation-report.md'
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
const fileName = path.basename(filePath);
|
|
236
|
+
return keyPatterns.some(p => fileName.includes(p));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 记录产出物评测结果
|
|
241
|
+
* @param {string} projectRoot - 项目根目录
|
|
242
|
+
* @param {string} artifactPath - 产出物路径
|
|
243
|
+
* @param {string} artifactType - 产出物类型
|
|
244
|
+
* @param {Object} evalResult - 评测结果
|
|
245
|
+
*/
|
|
246
|
+
export function recordArtifactEval(projectRoot, artifactPath, artifactType, evalResult) {
|
|
247
|
+
const metrics = getMetrics(projectRoot, false);
|
|
248
|
+
|
|
249
|
+
if (!metrics.artifacts) {
|
|
250
|
+
metrics.artifacts = {};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const artifactKey = path.basename(artifactPath);
|
|
254
|
+
|
|
255
|
+
if (!metrics.artifacts[artifactKey]) {
|
|
256
|
+
metrics.artifacts[artifactKey] = {
|
|
257
|
+
path: artifactPath,
|
|
258
|
+
type: artifactType,
|
|
259
|
+
evaluations: {},
|
|
260
|
+
overallScore: 0,
|
|
261
|
+
evaluatedAt: new Date().toISOString()
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 更新评测结果
|
|
266
|
+
metrics.artifacts[artifactKey].evaluations = {
|
|
267
|
+
...metrics.artifacts[artifactKey].evaluations,
|
|
268
|
+
...evalResult
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// 更新时间戳
|
|
272
|
+
metrics.artifacts[artifactKey].evaluatedAt = new Date().toISOString();
|
|
273
|
+
|
|
274
|
+
// 记录到 trace 日志
|
|
275
|
+
const traceId = getTraceId(projectRoot);
|
|
276
|
+
if (traceId) {
|
|
277
|
+
recordEvent(projectRoot, 'artifact_evaluated', {
|
|
278
|
+
source: 'artifact-evaluator',
|
|
279
|
+
data: {
|
|
280
|
+
artifactPath,
|
|
281
|
+
artifactType,
|
|
282
|
+
evalType: Object.keys(evalResult)[0],
|
|
283
|
+
score: Object.values(evalResult)[0]?.score
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
updateMetrics(projectRoot, metrics);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 计算产出物综合评分
|
|
293
|
+
* @param {Object} evaluations - 评测结果
|
|
294
|
+
* @param {string} artifactType - 产出物类型
|
|
295
|
+
* @returns {number} 综合评分
|
|
296
|
+
*/
|
|
297
|
+
export function calculateArtifactScore(evaluations, artifactType) {
|
|
298
|
+
const config = ARTIFACT_EVAL_CONFIG[artifactType];
|
|
299
|
+
if (!config) {
|
|
300
|
+
// 默认权重
|
|
301
|
+
let totalScore = 0;
|
|
302
|
+
let totalWeight = 0;
|
|
303
|
+
for (const [type, result] of Object.entries(evaluations)) {
|
|
304
|
+
if (result && typeof result.score === 'number') {
|
|
305
|
+
totalScore += result.score;
|
|
306
|
+
totalWeight++;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return totalWeight > 0 ? Math.round(totalScore / totalWeight) : 0;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let weightedScore = 0;
|
|
313
|
+
let totalWeight = 0;
|
|
314
|
+
|
|
315
|
+
for (const [type, weight] of Object.entries(config)) {
|
|
316
|
+
if (weight.enabled && evaluations[type] && typeof evaluations[type].score === 'number') {
|
|
317
|
+
weightedScore += evaluations[type].score * weight.weight;
|
|
318
|
+
totalWeight += weight.weight;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return totalWeight > 0 ? Math.round(weightedScore / totalWeight * 100) : 0;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 更新产出物质量汇总
|
|
327
|
+
* @param {string} projectRoot - 项目根目录
|
|
328
|
+
*/
|
|
329
|
+
export function updateArtifactSummary(projectRoot) {
|
|
330
|
+
const metrics = getMetrics(projectRoot, false);
|
|
331
|
+
const artifacts = metrics.artifacts || {};
|
|
332
|
+
|
|
333
|
+
const scores = [];
|
|
334
|
+
const lowScoreArtifacts = [];
|
|
335
|
+
let consistencyIssues = 0;
|
|
336
|
+
let qualityEvalCount = 0;
|
|
337
|
+
|
|
338
|
+
for (const [key, artifact] of Object.entries(artifacts)) {
|
|
339
|
+
if (artifact.overallScore) {
|
|
340
|
+
scores.push(artifact.overallScore);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (artifact.overallScore < 70) {
|
|
344
|
+
lowScoreArtifacts.push(key);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (artifact.evaluations?.consistency?.gaps?.length > 0) {
|
|
348
|
+
consistencyIssues += artifact.evaluations.consistency.gaps.length;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (artifact.evaluations?.quality) {
|
|
352
|
+
qualityEvalCount++;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
metrics.artifactSummary = {
|
|
357
|
+
averageScore: scores.length > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : 0,
|
|
358
|
+
lowScoreArtifacts,
|
|
359
|
+
consistencyIssues,
|
|
360
|
+
qualityEvalCount
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
updateMetrics(projectRoot, metrics);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 检查是否应该执行 AI 质量评估
|
|
368
|
+
* @param {string} projectRoot - 项目根目录
|
|
369
|
+
* @param {string} artifactType - 产出物类型
|
|
370
|
+
* @returns {Object} { shouldEval: boolean, reason: string }
|
|
371
|
+
*/
|
|
372
|
+
export function shouldRunQualityEval(projectRoot, artifactType) {
|
|
373
|
+
const config = ARTIFACT_EVAL_CONFIG[artifactType];
|
|
374
|
+
|
|
375
|
+
if (!config?.quality?.enabled) {
|
|
376
|
+
return { shouldEval: false, reason: '该产出物类型未启用质量评估' };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const metrics = getMetrics(projectRoot, true);
|
|
380
|
+
const artifact = Object.values(metrics?.artifacts || {}).find(a => a.type === artifactType);
|
|
381
|
+
|
|
382
|
+
// 首次生成:必评
|
|
383
|
+
if (!artifact?.evaluations?.quality) {
|
|
384
|
+
return { shouldEval: true, reason: '首次生成,建立基线' };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 低分产物:100% 重评
|
|
388
|
+
if (artifact.overallScore < 70) {
|
|
389
|
+
return { shouldEval: true, reason: '低分产出物,需要重评' };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 采样评估
|
|
393
|
+
const sampleRate = config.quality.sampleRate || 0.3;
|
|
394
|
+
const shouldSample = Math.random() < sampleRate;
|
|
395
|
+
|
|
396
|
+
return {
|
|
397
|
+
shouldEval: shouldSample,
|
|
398
|
+
reason: shouldSample ? '采样评估' : '跳过采样'
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export default {
|
|
403
|
+
EVAL_TYPES,
|
|
404
|
+
ARTIFACT_TYPES,
|
|
405
|
+
STRUCTURE_RULES,
|
|
406
|
+
ARTIFACT_EVAL_CONFIG,
|
|
407
|
+
checkStructure,
|
|
408
|
+
detectArtifactType,
|
|
409
|
+
isKeyArtifact,
|
|
410
|
+
recordArtifactEval,
|
|
411
|
+
calculateArtifactScore,
|
|
412
|
+
updateArtifactSummary,
|
|
413
|
+
shouldRunQualityEval
|
|
414
|
+
};
|