scene-capability-engine 3.0.0
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/CHANGELOG.md +2513 -0
- package/LICENSE +21 -0
- package/README.md +765 -0
- package/README.zh.md +630 -0
- package/bin/kiro-spec-engine.js +796 -0
- package/bin/kse.js +3 -0
- package/bin/sce.js +3 -0
- package/bin/sco.js +3 -0
- package/docs/331-poc-adaptation-roadmap.md +156 -0
- package/docs/331-poc-dual-track-integration-guide.md +120 -0
- package/docs/331-poc-weekly-delivery-checklist.md +52 -0
- package/docs/OFFLINE_INSTALL.md +96 -0
- package/docs/README.md +279 -0
- package/docs/adopt-migration-guide.md +599 -0
- package/docs/adoption-guide.md +616 -0
- package/docs/agent-hooks-analysis.md +815 -0
- package/docs/architecture.md +733 -0
- package/docs/articles/ai-driven-development-philosophy-and-practice-review.md +208 -0
- package/docs/articles/ai-driven-development-philosophy-and-practice.en.md +459 -0
- package/docs/articles/ai-driven-development-philosophy-and-practice.md +492 -0
- package/docs/autonomous-control-guide.md +851 -0
- package/docs/command-reference.md +1368 -0
- package/docs/community.md +115 -0
- package/docs/cross-tool-guide.md +555 -0
- package/docs/developer-guide.md +619 -0
- package/docs/document-governance.md +865 -0
- package/docs/environment-management-guide.md +526 -0
- package/docs/examples/add-export-command/design.md +194 -0
- package/docs/examples/add-export-command/requirements.md +110 -0
- package/docs/examples/add-export-command/tasks.md +88 -0
- package/docs/examples/add-rest-api/design.md +855 -0
- package/docs/examples/add-rest-api/requirements.md +323 -0
- package/docs/examples/add-rest-api/tasks.md +355 -0
- package/docs/examples/add-user-dashboard/design.md +192 -0
- package/docs/examples/add-user-dashboard/requirements.md +143 -0
- package/docs/examples/add-user-dashboard/tasks.md +91 -0
- package/docs/faq.md +697 -0
- package/docs/handoffs/evidence/ontology/moqui-template-baseline-2026-02-17-232922.json +156 -0
- package/docs/handoffs/evidence/ontology/moqui-template-baseline-2026-02-17-232922.md +24 -0
- package/docs/images/wechat-qr.png +0 -0
- package/docs/integration-modes.md +529 -0
- package/docs/integration-philosophy.md +313 -0
- package/docs/knowledge-management-guide.md +263 -0
- package/docs/manual-workflows-guide.md +418 -0
- package/docs/moqui-capability-matrix.md +73 -0
- package/docs/moqui-template-core-library-playbook.md +109 -0
- package/docs/multi-agent-coordination-guide.md +553 -0
- package/docs/multi-repo-management-guide.md +1344 -0
- package/docs/quick-start-with-ai-tools.md +375 -0
- package/docs/quick-start.md +146 -0
- package/docs/release-checklist.md +121 -0
- package/docs/releases/README.md +13 -0
- package/docs/releases/v1.46.2-validation.md +45 -0
- package/docs/releases/v1.46.2.md +50 -0
- package/docs/scene-runtime-guide.md +347 -0
- package/docs/spec-collaboration-guide.md +369 -0
- package/docs/spec-locking-guide.md +225 -0
- package/docs/spec-numbering-guide.md +348 -0
- package/docs/spec-workflow.md +519 -0
- package/docs/steering-strategy-guide.md +196 -0
- package/docs/team-collaboration-guide.md +465 -0
- package/docs/testing-strategy.md +272 -0
- package/docs/tools/claude-guide.md +654 -0
- package/docs/tools/cursor-guide.md +706 -0
- package/docs/tools/generic-guide.md +446 -0
- package/docs/tools/kiro-guide.md +308 -0
- package/docs/tools/vscode-guide.md +445 -0
- package/docs/tools/windsurf-guide.md +391 -0
- package/docs/troubleshooting.md +1135 -0
- package/docs/upgrade-guide.md +639 -0
- package/docs/value-observability-guide.md +127 -0
- package/docs/zh/README.md +341 -0
- package/docs/zh/quick-start.md +764 -0
- package/docs/zh/release-checklist.md +121 -0
- package/docs/zh/releases/README.md +13 -0
- package/docs/zh/releases/v1.46.2-validation.md +45 -0
- package/docs/zh/releases/v1.46.2.md +50 -0
- package/docs/zh/spec-numbering-guide.md +348 -0
- package/docs/zh/tools/claude-guide.md +349 -0
- package/docs/zh/tools/cursor-guide.md +281 -0
- package/docs/zh/tools/generic-guide.md +499 -0
- package/docs/zh/tools/kiro-guide.md +342 -0
- package/docs/zh/tools/vscode-guide.md +449 -0
- package/docs/zh/tools/windsurf-guide.md +378 -0
- package/docs/zh/value-observability-guide.md +127 -0
- package/docs//344/272/244/344/273/230/346/270/205/345/215/225.md +75 -0
- package/lib/adoption/adoption-logger.js +487 -0
- package/lib/adoption/adoption-strategy.js +538 -0
- package/lib/adoption/backup-manager.js +420 -0
- package/lib/adoption/conflict-resolver.js +410 -0
- package/lib/adoption/detection-engine.js +275 -0
- package/lib/adoption/diff-viewer.js +226 -0
- package/lib/adoption/error-formatter.js +509 -0
- package/lib/adoption/file-classifier.js +385 -0
- package/lib/adoption/progress-reporter.js +534 -0
- package/lib/adoption/smart-orchestrator.js +470 -0
- package/lib/adoption/strategy-selector.js +218 -0
- package/lib/adoption/summary-generator.js +493 -0
- package/lib/adoption/template-sync.js +605 -0
- package/lib/auto/autonomous-engine.js +485 -0
- package/lib/auto/checkpoint-manager.js +300 -0
- package/lib/auto/close-loop-runner.js +2476 -0
- package/lib/auto/config-schema.js +176 -0
- package/lib/auto/decision-engine.js +344 -0
- package/lib/auto/error-recovery-manager.js +580 -0
- package/lib/auto/goal-decomposer.js +278 -0
- package/lib/auto/progress-tracker.js +502 -0
- package/lib/auto/safety-manager.js +186 -0
- package/lib/auto/semantic-decomposer.js +137 -0
- package/lib/auto/state-manager.js +126 -0
- package/lib/auto/task-queue-manager.js +340 -0
- package/lib/backup/backup-system.js +372 -0
- package/lib/backup/selective-backup.js +207 -0
- package/lib/collab/agent-registry.js +240 -0
- package/lib/collab/collab-manager.js +285 -0
- package/lib/collab/contract-manager.js +320 -0
- package/lib/collab/coordinator.js +370 -0
- package/lib/collab/dependency-manager.js +280 -0
- package/lib/collab/index.js +20 -0
- package/lib/collab/integration-manager.js +202 -0
- package/lib/collab/merge-coordinator.js +252 -0
- package/lib/collab/metadata-manager.js +233 -0
- package/lib/collab/multi-agent-config.js +120 -0
- package/lib/collab/spec-lifecycle-manager.js +304 -0
- package/lib/collab/sync-barrier.js +88 -0
- package/lib/collab/visualizer.js +208 -0
- package/lib/commands/adopt.js +749 -0
- package/lib/commands/auto.js +19559 -0
- package/lib/commands/collab.js +275 -0
- package/lib/commands/context.js +99 -0
- package/lib/commands/docs.js +808 -0
- package/lib/commands/doctor.js +273 -0
- package/lib/commands/env.js +420 -0
- package/lib/commands/knowledge.js +309 -0
- package/lib/commands/lock.js +235 -0
- package/lib/commands/ops.js +409 -0
- package/lib/commands/orchestrate.js +446 -0
- package/lib/commands/prompt.js +105 -0
- package/lib/commands/repo.js +118 -0
- package/lib/commands/rollback.js +219 -0
- package/lib/commands/scene.js +15549 -0
- package/lib/commands/spec-bootstrap.js +147 -0
- package/lib/commands/spec-gate.js +157 -0
- package/lib/commands/spec-pipeline.js +205 -0
- package/lib/commands/status.js +321 -0
- package/lib/commands/task.js +199 -0
- package/lib/commands/templates.js +654 -0
- package/lib/commands/upgrade.js +231 -0
- package/lib/commands/value.js +569 -0
- package/lib/commands/watch.js +684 -0
- package/lib/commands/workflows.js +240 -0
- package/lib/commands/workspace-multi.js +325 -0
- package/lib/commands/workspace.js +189 -0
- package/lib/context/context-exporter.js +378 -0
- package/lib/context/prompt-generator.js +482 -0
- package/lib/data/moqui-capability-lexicon.json +45 -0
- package/lib/environment/backup-system.js +189 -0
- package/lib/environment/environment-manager.js +379 -0
- package/lib/environment/environment-registry.js +168 -0
- package/lib/gitignore/gitignore-backup.js +229 -0
- package/lib/gitignore/gitignore-detector.js +239 -0
- package/lib/gitignore/gitignore-integration.js +267 -0
- package/lib/gitignore/gitignore-transformer.js +193 -0
- package/lib/gitignore/layered-rules-template.js +42 -0
- package/lib/governance/archive-tool.js +284 -0
- package/lib/governance/cleanup-tool.js +237 -0
- package/lib/governance/config-manager.js +186 -0
- package/lib/governance/diagnostic-engine.js +271 -0
- package/lib/governance/doc-reference-checker.js +200 -0
- package/lib/governance/execution-logger.js +243 -0
- package/lib/governance/file-scanner.js +285 -0
- package/lib/governance/hooks-manager.js +333 -0
- package/lib/governance/reporter.js +337 -0
- package/lib/governance/validation-engine.js +181 -0
- package/lib/i18n.js +79 -0
- package/lib/knowledge/entry-manager.js +208 -0
- package/lib/knowledge/index-manager.js +261 -0
- package/lib/knowledge/knowledge-manager.js +273 -0
- package/lib/knowledge/template-manager.js +191 -0
- package/lib/lock/index.js +21 -0
- package/lib/lock/lock-file.js +192 -0
- package/lib/lock/lock-manager.js +321 -0
- package/lib/lock/machine-identifier.js +135 -0
- package/lib/lock/steering-file-lock.js +207 -0
- package/lib/lock/task-lock-manager.js +345 -0
- package/lib/operations/audit-logger.js +293 -0
- package/lib/operations/feedback-manager.js +1147 -0
- package/lib/operations/index.js +23 -0
- package/lib/operations/models/index.js +170 -0
- package/lib/operations/operations-manager.js +151 -0
- package/lib/operations/operations-validator.js +280 -0
- package/lib/operations/permission-manager.js +354 -0
- package/lib/operations/template-loader.js +143 -0
- package/lib/orchestrator/agent-spawner.js +629 -0
- package/lib/orchestrator/bootstrap-prompt-builder.js +236 -0
- package/lib/orchestrator/index.js +19 -0
- package/lib/orchestrator/orchestration-engine.js +1270 -0
- package/lib/orchestrator/orchestrator-config.js +173 -0
- package/lib/orchestrator/status-monitor.js +591 -0
- package/lib/python-checker.js +209 -0
- package/lib/repo/config-manager.js +580 -0
- package/lib/repo/errors/config-error.js +13 -0
- package/lib/repo/errors/git-error.js +15 -0
- package/lib/repo/errors/repo-error.js +14 -0
- package/lib/repo/git-operations.js +181 -0
- package/lib/repo/handlers/.gitkeep +1 -0
- package/lib/repo/handlers/exec-handler.js +155 -0
- package/lib/repo/handlers/health-handler.js +169 -0
- package/lib/repo/handlers/init-handler.js +197 -0
- package/lib/repo/handlers/status-handler.js +176 -0
- package/lib/repo/output-formatter.js +184 -0
- package/lib/repo/path-resolver.js +178 -0
- package/lib/repo/repo-manager.js +514 -0
- package/lib/scene-runtime/audit-emitter.js +59 -0
- package/lib/scene-runtime/binding-plugin-loader.js +351 -0
- package/lib/scene-runtime/binding-registry.js +349 -0
- package/lib/scene-runtime/eval-bridge.js +44 -0
- package/lib/scene-runtime/index.js +19 -0
- package/lib/scene-runtime/moqui-adapter.js +620 -0
- package/lib/scene-runtime/moqui-client.js +606 -0
- package/lib/scene-runtime/moqui-extractor.js +2029 -0
- package/lib/scene-runtime/plan-compiler.js +208 -0
- package/lib/scene-runtime/policy-gate.js +58 -0
- package/lib/scene-runtime/runtime-executor.js +358 -0
- package/lib/scene-runtime/scene-loader.js +96 -0
- package/lib/scene-runtime/scene-ontology.js +959 -0
- package/lib/scene-runtime/scene-template-linter.js +852 -0
- package/lib/scene-runtime/templates/scene-template-erp-query-v0.1.yaml +28 -0
- package/lib/scene-runtime/templates/scene-template-hybrid-shadow-v0.1.yaml +34 -0
- package/lib/spec/bootstrap/context-collector.js +48 -0
- package/lib/spec/bootstrap/draft-generator.js +158 -0
- package/lib/spec/bootstrap/questionnaire-engine.js +70 -0
- package/lib/spec/bootstrap/trace-emitter.js +59 -0
- package/lib/spec/multi-spec-orchestrate.js +93 -0
- package/lib/spec/pipeline/constants.js +6 -0
- package/lib/spec/pipeline/stage-adapters.js +118 -0
- package/lib/spec/pipeline/stage-runner.js +146 -0
- package/lib/spec/pipeline/state-store.js +119 -0
- package/lib/spec-gate/engine/gate-engine.js +165 -0
- package/lib/spec-gate/policy/default-policy.js +22 -0
- package/lib/spec-gate/policy/policy-loader.js +103 -0
- package/lib/spec-gate/result-emitter.js +81 -0
- package/lib/spec-gate/rules/default-rules.js +156 -0
- package/lib/spec-gate/rules/rule-registry.js +51 -0
- package/lib/steering/adoption-config.js +164 -0
- package/lib/steering/compliance-auto-fixer.js +204 -0
- package/lib/steering/compliance-cache.js +99 -0
- package/lib/steering/compliance-error-reporter.js +70 -0
- package/lib/steering/context-sync-manager.js +273 -0
- package/lib/steering/index.js +92 -0
- package/lib/steering/spec-steering.js +230 -0
- package/lib/steering/steering-compliance-checker.js +73 -0
- package/lib/steering/steering-loader.js +144 -0
- package/lib/steering/steering-manager.js +289 -0
- package/lib/task/index.js +12 -0
- package/lib/task/task-claimer.js +489 -0
- package/lib/task/task-status-store.js +418 -0
- package/lib/templates/cache-manager.js +440 -0
- package/lib/templates/content-generalizer.js +247 -0
- package/lib/templates/frontmatter-generator.js +128 -0
- package/lib/templates/git-handler.js +471 -0
- package/lib/templates/metadata-collector.js +328 -0
- package/lib/templates/path-utils.js +144 -0
- package/lib/templates/registry-parser.js +505 -0
- package/lib/templates/spec-reader.js +216 -0
- package/lib/templates/template-applicator.js +249 -0
- package/lib/templates/template-creator.js +256 -0
- package/lib/templates/template-error.js +143 -0
- package/lib/templates/template-exporter.js +502 -0
- package/lib/templates/template-manager.js +782 -0
- package/lib/templates/template-validator.js +361 -0
- package/lib/upgrade/migration-engine.js +382 -0
- package/lib/upgrade/migrations/.gitkeep +52 -0
- package/lib/upgrade/migrations/1.0.0-to-1.1.0.js +78 -0
- package/lib/utils/file-diff.js +177 -0
- package/lib/utils/fs-utils.js +274 -0
- package/lib/utils/tool-detector.js +383 -0
- package/lib/utils/validation.js +324 -0
- package/lib/value/gate-summary-emitter.js +99 -0
- package/lib/value/metric-contract-loader.js +210 -0
- package/lib/value/risk-evaluator.js +117 -0
- package/lib/value/weekly-snapshot-builder.js +61 -0
- package/lib/version/version-checker.js +156 -0
- package/lib/version/version-manager.js +327 -0
- package/lib/watch/action-executor.js +458 -0
- package/lib/watch/event-debouncer.js +323 -0
- package/lib/watch/execution-logger.js +550 -0
- package/lib/watch/file-watcher.js +499 -0
- package/lib/watch/presets.js +266 -0
- package/lib/watch/watch-manager.js +533 -0
- package/lib/workspace/multi/global-config.js +150 -0
- package/lib/workspace/multi/index.js +22 -0
- package/lib/workspace/multi/path-utils.js +173 -0
- package/lib/workspace/multi/workspace-context-resolver.js +244 -0
- package/lib/workspace/multi/workspace-registry.js +196 -0
- package/lib/workspace/multi/workspace-state-manager.js +537 -0
- package/lib/workspace/multi/workspace.js +90 -0
- package/lib/workspace/workspace-manager.js +370 -0
- package/lib/workspace/workspace-sync.js +356 -0
- package/locales/en.json +114 -0
- package/locales/zh.json +114 -0
- package/package.json +102 -0
- package/template/.kiro/README.md +247 -0
- package/template/.kiro/hooks/check-spec-on-create.kiro.hook +17 -0
- package/template/.kiro/hooks/run-tests-on-save.kiro.hook +13 -0
- package/template/.kiro/hooks/sync-tasks-on-edit.kiro.hook +16 -0
- package/template/.kiro/specs/SPEC_WORKFLOW_GUIDE.md +134 -0
- package/template/.kiro/steering/CORE_PRINCIPLES.md +133 -0
- package/template/.kiro/steering/CURRENT_CONTEXT.md +30 -0
- package/template/.kiro/steering/ENVIRONMENT.md +35 -0
- package/template/.kiro/steering/RULES_GUIDE.md +46 -0
- package/template/.kiro/templates/operations/default/change-impact.md +112 -0
- package/template/.kiro/templates/operations/default/deployment.md +91 -0
- package/template/.kiro/templates/operations/default/feedback-response.md +269 -0
- package/template/.kiro/templates/operations/default/migration-plan.md +172 -0
- package/template/.kiro/templates/operations/default/monitoring.md +135 -0
- package/template/.kiro/templates/operations/default/operations.md +135 -0
- package/template/.kiro/templates/operations/default/rollback.md +143 -0
- package/template/.kiro/templates/operations/default/tools.yaml +364 -0
- package/template/.kiro/templates/operations/default/troubleshooting.md +123 -0
- package/template/.kiro/tools/backup_manager.py +295 -0
- package/template/.kiro/tools/configuration_manager.py +218 -0
- package/template/.kiro/tools/document_evaluator.py +550 -0
- package/template/.kiro/tools/enhancement_logger.py +168 -0
- package/template/.kiro/tools/error_handler.py +335 -0
- package/template/.kiro/tools/improvement_identifier.py +444 -0
- package/template/.kiro/tools/modification_applicator.py +737 -0
- package/template/.kiro/tools/quality_gate_enforcer.py +207 -0
- package/template/.kiro/tools/quality_scorer.py +305 -0
- package/template/.kiro/tools/report_generator.py +154 -0
- package/template/.kiro/tools/ultrawork_enhancer.py +676 -0
- package/template/.kiro/tools/ultrawork_enhancer_refactored.py +0 -0
- package/template/.kiro/tools/ultrawork_enhancer_v2.py +463 -0
- package/template/.kiro/tools/ultrawork_enhancer_v3.py +606 -0
- package/template/.kiro/tools/workflow_quality_gate.py +100 -0
- package/template/README.md +111 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Document Evaluator - 文档质量评估组件
|
|
4
|
+
|
|
5
|
+
负责分析文档结构和内容,评估质量并识别改进领域
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
from typing import Dict, List, Optional
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class QualityAssessment:
|
|
15
|
+
"""质量评估结果"""
|
|
16
|
+
score: float # 0-10
|
|
17
|
+
criteria_scores: Dict[str, float] = field(default_factory=dict)
|
|
18
|
+
missing_sections: List[str] = field(default_factory=list)
|
|
19
|
+
incomplete_sections: List[str] = field(default_factory=list)
|
|
20
|
+
issues: List[str] = field(default_factory=list)
|
|
21
|
+
language: str = 'en'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DocumentEvaluator:
|
|
25
|
+
"""
|
|
26
|
+
文档评估器 - 分析文档质量
|
|
27
|
+
|
|
28
|
+
支持中英文文档评估
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
self.language = None
|
|
33
|
+
|
|
34
|
+
def _detect_language(self, content: str) -> str:
|
|
35
|
+
"""
|
|
36
|
+
检测文档语言
|
|
37
|
+
返回: 'zh' (中文) 或 'en' (英文)
|
|
38
|
+
"""
|
|
39
|
+
# 统计中文字符数量
|
|
40
|
+
chinese_chars = len(re.findall(r'[\u4e00-\u9fff]', content))
|
|
41
|
+
# 统计英文单词数量
|
|
42
|
+
english_words = len(re.findall(r'\b[a-zA-Z]+\b', content))
|
|
43
|
+
|
|
44
|
+
# 如果中文字符超过100个,判定为中文
|
|
45
|
+
if chinese_chars > 100:
|
|
46
|
+
return 'zh'
|
|
47
|
+
# 如果英文单词超过中文字符的3倍,判定为英文
|
|
48
|
+
elif english_words > chinese_chars * 3:
|
|
49
|
+
return 'en'
|
|
50
|
+
# 默认中文
|
|
51
|
+
return 'zh'
|
|
52
|
+
|
|
53
|
+
def assess_requirements_quality(self, content: str, language: Optional[str] = None) -> QualityAssessment:
|
|
54
|
+
"""评估 Requirements 文档质量 (0-10) - 支持中英文,增强评分算法"""
|
|
55
|
+
lang = language or self._detect_language(content)
|
|
56
|
+
self.language = lang
|
|
57
|
+
|
|
58
|
+
score = 0.0
|
|
59
|
+
criteria_scores = {}
|
|
60
|
+
missing_sections = []
|
|
61
|
+
incomplete_sections = []
|
|
62
|
+
issues = []
|
|
63
|
+
|
|
64
|
+
if lang == 'zh':
|
|
65
|
+
# 中文评分标准 - 增强版
|
|
66
|
+
# 基础结构检查 (2分) - 更严格的检查
|
|
67
|
+
structure_score = 0.0
|
|
68
|
+
|
|
69
|
+
# 检查概述/Introduction
|
|
70
|
+
if "## 1. 概述" in content or "## Introduction" in content or "## 概述" in content:
|
|
71
|
+
structure_score += 0.5
|
|
72
|
+
# 检查概述内容是否充实
|
|
73
|
+
intro_match = re.search(r'##.*?概述.*?\n(.*?)(?=\n##|\Z)', content, re.DOTALL | re.IGNORECASE)
|
|
74
|
+
if intro_match and len(intro_match.group(1).strip()) < 100:
|
|
75
|
+
incomplete_sections.append("概述内容过于简短")
|
|
76
|
+
else:
|
|
77
|
+
missing_sections.append("概述/Introduction")
|
|
78
|
+
|
|
79
|
+
# 检查用户故事
|
|
80
|
+
if "## 2. 用户故事" in content or "用户故事" in content or "User Story" in content:
|
|
81
|
+
structure_score += 0.5
|
|
82
|
+
else:
|
|
83
|
+
missing_sections.append("用户故事")
|
|
84
|
+
|
|
85
|
+
# 检查功能需求
|
|
86
|
+
if "## 3. 功能需求" in content or "功能需求" in content or "Functional Requirements" in content:
|
|
87
|
+
structure_score += 0.5
|
|
88
|
+
else:
|
|
89
|
+
missing_sections.append("功能需求")
|
|
90
|
+
|
|
91
|
+
# 检查非功能需求
|
|
92
|
+
if "## 4. 非功能需求" in content or "非功能需求" in content or "Non-functional" in content:
|
|
93
|
+
structure_score += 0.5
|
|
94
|
+
else:
|
|
95
|
+
missing_sections.append("非功能需求")
|
|
96
|
+
|
|
97
|
+
criteria_scores['structure'] = structure_score
|
|
98
|
+
score += structure_score
|
|
99
|
+
|
|
100
|
+
# EARS 格式检查 (2分) - 更精确的模式匹配
|
|
101
|
+
ears_patterns = len(re.findall(r'(?:WHEN|当|如果).*?(?:THEN|那么|则).*?(?:SHALL|应该|必须)', content, re.IGNORECASE | re.DOTALL))
|
|
102
|
+
ears_score = min(ears_patterns * 0.15, 2.0)
|
|
103
|
+
criteria_scores['ears_format'] = ears_score
|
|
104
|
+
score += ears_score
|
|
105
|
+
|
|
106
|
+
if ears_patterns < 5:
|
|
107
|
+
issues.append(f"EARS 格式验收标准较少 (当前 {ears_patterns},建议 5+)")
|
|
108
|
+
elif ears_patterns < 10:
|
|
109
|
+
issues.append(f"EARS 格式验收标准可以更多 (当前 {ears_patterns},建议 10+)")
|
|
110
|
+
|
|
111
|
+
# 用户故事质量 (2分) - 检查格式完整性
|
|
112
|
+
user_story_patterns = len(re.findall(r'(?:作为|As a).*?(?:我希望|I want).*?(?:以便|So that)', content, re.IGNORECASE | re.DOTALL))
|
|
113
|
+
user_story_score = min(user_story_patterns * 0.25, 2.0)
|
|
114
|
+
criteria_scores['user_stories'] = user_story_score
|
|
115
|
+
score += user_story_score
|
|
116
|
+
|
|
117
|
+
if user_story_patterns < 3:
|
|
118
|
+
issues.append(f"用户故事较少 (当前 {user_story_patterns},建议 3+)")
|
|
119
|
+
|
|
120
|
+
# 验收标准完整性 (2分) - 检查每个需求是否有验收标准
|
|
121
|
+
acceptance_criteria = len(re.findall(r'(?:\*\*验收标准\*\*:|Acceptance Criteria)', content, re.IGNORECASE))
|
|
122
|
+
requirements_count = len(re.findall(r'### \d+\.\d+', content))
|
|
123
|
+
|
|
124
|
+
if requirements_count > 0:
|
|
125
|
+
acceptance_ratio = acceptance_criteria / requirements_count
|
|
126
|
+
acceptance_score = min(acceptance_ratio * 2.0, 2.0)
|
|
127
|
+
else:
|
|
128
|
+
acceptance_score = min(acceptance_criteria * 0.3, 2.0)
|
|
129
|
+
|
|
130
|
+
criteria_scores['acceptance_criteria'] = acceptance_score
|
|
131
|
+
score += acceptance_score
|
|
132
|
+
|
|
133
|
+
if acceptance_criteria < requirements_count:
|
|
134
|
+
issues.append(f"部分需求缺少验收标准 ({acceptance_criteria}/{requirements_count})")
|
|
135
|
+
|
|
136
|
+
# 非功能需求覆盖 (1分) - 更全面的检查
|
|
137
|
+
nfr_keywords = ['性能', '安全', '可用性', '可维护性', '兼容性', '可扩展性']
|
|
138
|
+
nfr_coverage = sum(1 for keyword in nfr_keywords if keyword in content)
|
|
139
|
+
nfr_score = min(nfr_coverage * 0.17, 1.0)
|
|
140
|
+
criteria_scores['nfr_coverage'] = nfr_score
|
|
141
|
+
score += nfr_score
|
|
142
|
+
|
|
143
|
+
missing_nfr = [kw for kw in nfr_keywords if kw not in content]
|
|
144
|
+
if missing_nfr:
|
|
145
|
+
issues.append(f"缺少非功能需求: {', '.join(missing_nfr)}")
|
|
146
|
+
|
|
147
|
+
# 约束条件 (1分)
|
|
148
|
+
if "约束条件" in content or "限制" in content or "Constraints" in content:
|
|
149
|
+
criteria_scores['constraints'] = 1.0
|
|
150
|
+
score += 1.0
|
|
151
|
+
else:
|
|
152
|
+
criteria_scores['constraints'] = 0.0
|
|
153
|
+
missing_sections.append("约束条件")
|
|
154
|
+
else:
|
|
155
|
+
# 英文评分标准 - 增强版
|
|
156
|
+
# 基础结构检查 (2分) - 更严格的检查
|
|
157
|
+
structure_score = 0.0
|
|
158
|
+
|
|
159
|
+
# 检查 Introduction/Overview
|
|
160
|
+
if "## Introduction" in content or "## Overview" in content:
|
|
161
|
+
structure_score += 0.5
|
|
162
|
+
# 检查内容是否充实
|
|
163
|
+
intro_match = re.search(r'##.*?(?:Introduction|Overview).*?\n(.*?)(?=\n##|\Z)', content, re.DOTALL | re.IGNORECASE)
|
|
164
|
+
if intro_match and len(intro_match.group(1).strip()) < 100:
|
|
165
|
+
incomplete_sections.append("Introduction/Overview content is too brief")
|
|
166
|
+
else:
|
|
167
|
+
missing_sections.append("Introduction/Overview")
|
|
168
|
+
|
|
169
|
+
# 检查 Glossary
|
|
170
|
+
if "## Glossary" in content or "## Terminology" in content:
|
|
171
|
+
structure_score += 0.5
|
|
172
|
+
# 检查是否有定义
|
|
173
|
+
glossary_match = re.search(r'##.*?(?:Glossary|Terminology).*?\n(.*?)(?=\n##|\Z)', content, re.DOTALL | re.IGNORECASE)
|
|
174
|
+
if glossary_match:
|
|
175
|
+
definitions = len(re.findall(r'^\s*-\s*\*\*.*?\*\*:', glossary_match.group(1), re.MULTILINE))
|
|
176
|
+
if definitions < 3:
|
|
177
|
+
incomplete_sections.append(f"Glossary has few definitions ({definitions}, suggest 3+)")
|
|
178
|
+
else:
|
|
179
|
+
missing_sections.append("Glossary")
|
|
180
|
+
|
|
181
|
+
# 检查 Requirements
|
|
182
|
+
if "## Requirements" in content or "## Functional Requirements" in content:
|
|
183
|
+
structure_score += 0.5
|
|
184
|
+
else:
|
|
185
|
+
missing_sections.append("Requirements")
|
|
186
|
+
|
|
187
|
+
# 检查 Non-functional Requirements
|
|
188
|
+
if "Non-functional" in content or "Non-Functional" in content:
|
|
189
|
+
structure_score += 0.5
|
|
190
|
+
else:
|
|
191
|
+
missing_sections.append("Non-functional Requirements")
|
|
192
|
+
|
|
193
|
+
criteria_scores['structure'] = structure_score
|
|
194
|
+
score += structure_score
|
|
195
|
+
|
|
196
|
+
# EARS 格式检查 (2分) - 更精确的模式匹配
|
|
197
|
+
ears_patterns = len(re.findall(r'(?:WHEN|IF|WHILE|WHERE).*?(?:THEN|THE\s+system\s+SHALL)', content, re.IGNORECASE | re.DOTALL))
|
|
198
|
+
ears_score = min(ears_patterns * 0.12, 2.0)
|
|
199
|
+
criteria_scores['ears_format'] = ears_score
|
|
200
|
+
score += ears_score
|
|
201
|
+
|
|
202
|
+
if ears_patterns < 5:
|
|
203
|
+
issues.append(f"Few EARS-format acceptance criteria (current {ears_patterns}, target 5+)")
|
|
204
|
+
elif ears_patterns < 10:
|
|
205
|
+
issues.append(f"EARS-format criteria could be more (current {ears_patterns}, target 10+)")
|
|
206
|
+
|
|
207
|
+
# 用户故事质量 (2分) - 检查格式完整性
|
|
208
|
+
user_story_patterns = len(re.findall(r'(?:As a|As an).*?I want.*?(?:So that|so that)', content, re.IGNORECASE | re.DOTALL))
|
|
209
|
+
user_story_score = min(user_story_patterns * 0.2, 2.0)
|
|
210
|
+
criteria_scores['user_stories'] = user_story_score
|
|
211
|
+
score += user_story_score
|
|
212
|
+
|
|
213
|
+
if user_story_patterns < 3:
|
|
214
|
+
issues.append(f"Few user stories (current {user_story_patterns}, target 3+)")
|
|
215
|
+
|
|
216
|
+
# 验收标准完整性 (2分) - 检查每个需求是否有验收标准
|
|
217
|
+
acceptance_criteria = len(re.findall(r'(?:Acceptance Criteria|#### Acceptance Criteria)', content, re.IGNORECASE))
|
|
218
|
+
requirements_count = len(re.findall(r'### Requirement \d+', content, re.IGNORECASE))
|
|
219
|
+
|
|
220
|
+
if requirements_count > 0:
|
|
221
|
+
acceptance_ratio = acceptance_criteria / requirements_count
|
|
222
|
+
acceptance_score = min(acceptance_ratio * 2.0, 2.0)
|
|
223
|
+
else:
|
|
224
|
+
acceptance_score = min(acceptance_criteria * 0.25, 2.0)
|
|
225
|
+
|
|
226
|
+
criteria_scores['acceptance_criteria'] = acceptance_score
|
|
227
|
+
score += acceptance_score
|
|
228
|
+
|
|
229
|
+
if acceptance_criteria < requirements_count:
|
|
230
|
+
issues.append(f"Some requirements lack acceptance criteria ({acceptance_criteria}/{requirements_count})")
|
|
231
|
+
|
|
232
|
+
# 非功能需求覆盖 (1分) - 更全面的检查
|
|
233
|
+
nfr_keywords = ['performance', 'security', 'usability', 'maintainability', 'compatibility', 'scalability', 'reliability']
|
|
234
|
+
nfr_coverage = sum(1 for keyword in nfr_keywords if keyword.lower() in content.lower())
|
|
235
|
+
nfr_score = min(nfr_coverage * 0.14, 1.0)
|
|
236
|
+
criteria_scores['nfr_coverage'] = nfr_score
|
|
237
|
+
score += nfr_score
|
|
238
|
+
|
|
239
|
+
missing_nfr = [kw for kw in nfr_keywords if kw.lower() not in content.lower()]
|
|
240
|
+
if len(missing_nfr) > 3:
|
|
241
|
+
issues.append(f"Missing non-functional requirements: {', '.join(missing_nfr[:3])}")
|
|
242
|
+
|
|
243
|
+
# 约束条件 (1分)
|
|
244
|
+
if "constraint" in content.lower() or "limitation" in content.lower():
|
|
245
|
+
criteria_scores['constraints'] = 1.0
|
|
246
|
+
score += 1.0
|
|
247
|
+
else:
|
|
248
|
+
criteria_scores['constraints'] = 0.0
|
|
249
|
+
missing_sections.append("Constraints")
|
|
250
|
+
|
|
251
|
+
return QualityAssessment(
|
|
252
|
+
score=min(score, 10.0),
|
|
253
|
+
criteria_scores=criteria_scores,
|
|
254
|
+
missing_sections=missing_sections,
|
|
255
|
+
incomplete_sections=incomplete_sections,
|
|
256
|
+
issues=issues,
|
|
257
|
+
language=lang
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
def assess_design_quality(self, design_content: str, requirements_content: str, language: Optional[str] = None) -> QualityAssessment:
|
|
261
|
+
"""评估 Design 文档质量 (0-10) - 支持中英文,增强评分算法"""
|
|
262
|
+
lang = language or self._detect_language(design_content)
|
|
263
|
+
self.language = lang
|
|
264
|
+
|
|
265
|
+
score = 0.0
|
|
266
|
+
criteria_scores = {}
|
|
267
|
+
missing_sections = []
|
|
268
|
+
incomplete_sections = []
|
|
269
|
+
issues = []
|
|
270
|
+
|
|
271
|
+
if lang == 'zh':
|
|
272
|
+
# 中文评分标准 - 增强版
|
|
273
|
+
# 基础结构检查 (2.5分) - 更严格的检查
|
|
274
|
+
structure_score = 0.0
|
|
275
|
+
|
|
276
|
+
# 检查系统概述
|
|
277
|
+
if "## 1. 系统概述" in design_content or "## 1. 概述" in design_content or "## Overview" in design_content:
|
|
278
|
+
structure_score += 0.5
|
|
279
|
+
# 检查内容充实度
|
|
280
|
+
overview_match = re.search(r'##.*?概述.*?\n(.*?)(?=\n##|\Z)', design_content, re.DOTALL | re.IGNORECASE)
|
|
281
|
+
if overview_match and len(overview_match.group(1).strip()) < 150:
|
|
282
|
+
incomplete_sections.append("系统概述内容过于简短")
|
|
283
|
+
else:
|
|
284
|
+
missing_sections.append("系统概述")
|
|
285
|
+
|
|
286
|
+
# 检查架构设计
|
|
287
|
+
if "## 2. 架构设计" in design_content or "## Architecture" in design_content:
|
|
288
|
+
structure_score += 0.5
|
|
289
|
+
else:
|
|
290
|
+
missing_sections.append("架构设计")
|
|
291
|
+
|
|
292
|
+
# 检查组件设计
|
|
293
|
+
if "## 3. 组件设计" in design_content or "## Components" in design_content:
|
|
294
|
+
structure_score += 0.5
|
|
295
|
+
else:
|
|
296
|
+
missing_sections.append("组件设计")
|
|
297
|
+
|
|
298
|
+
# 检查数据流/接口设计
|
|
299
|
+
if "## 4. 数据流设计" in design_content or "## 4. 接口设计" in design_content or "## Interface" in design_content:
|
|
300
|
+
structure_score += 0.5
|
|
301
|
+
else:
|
|
302
|
+
missing_sections.append("数据流/接口设计")
|
|
303
|
+
|
|
304
|
+
# 检查错误处理
|
|
305
|
+
if "错误处理" in design_content or "异常处理" in design_content or "Error Handling" in design_content:
|
|
306
|
+
structure_score += 0.5
|
|
307
|
+
else:
|
|
308
|
+
missing_sections.append("错误处理策略")
|
|
309
|
+
|
|
310
|
+
criteria_scores['structure'] = structure_score
|
|
311
|
+
score += structure_score
|
|
312
|
+
|
|
313
|
+
# 需求追溯性检查 (2.5分) - 更精确的匹配
|
|
314
|
+
req_references = len(re.findall(r'(?:需求|Requirements?|Validates:)\s*\d+\.\d+', design_content, re.IGNORECASE))
|
|
315
|
+
# 检查双向追溯
|
|
316
|
+
bidirectional_refs = len(re.findall(r'Validates:\s*Requirements?\s*\d+\.\d+', design_content, re.IGNORECASE))
|
|
317
|
+
|
|
318
|
+
traceability_score = min(req_references * 0.15, 2.0)
|
|
319
|
+
if bidirectional_refs > 0:
|
|
320
|
+
traceability_score += min(bidirectional_refs * 0.1, 0.5)
|
|
321
|
+
|
|
322
|
+
criteria_scores['traceability'] = traceability_score
|
|
323
|
+
score += traceability_score
|
|
324
|
+
|
|
325
|
+
if req_references < 3:
|
|
326
|
+
issues.append(f"需求追溯较少 (当前 {req_references},建议 5+)")
|
|
327
|
+
if bidirectional_refs == 0:
|
|
328
|
+
issues.append("缺少双向追溯 (Validates: Requirements X.Y)")
|
|
329
|
+
|
|
330
|
+
# 架构图和设计图 (1.5分) - 检查图表质量
|
|
331
|
+
mermaid_diagrams = len(re.findall(r'```mermaid', design_content))
|
|
332
|
+
plantuml_diagrams = len(re.findall(r'```plantuml', design_content))
|
|
333
|
+
diagram_keywords = len(re.findall(r'架构图|设计图|流程图|时序图', design_content))
|
|
334
|
+
|
|
335
|
+
total_diagrams = mermaid_diagrams + plantuml_diagrams + diagram_keywords
|
|
336
|
+
diagram_score = min(total_diagrams * 0.4, 1.5)
|
|
337
|
+
criteria_scores['diagrams'] = diagram_score
|
|
338
|
+
score += diagram_score
|
|
339
|
+
|
|
340
|
+
if total_diagrams == 0:
|
|
341
|
+
missing_sections.append("架构图/设计图")
|
|
342
|
+
elif total_diagrams < 2:
|
|
343
|
+
issues.append(f"设计图较少 (当前 {total_diagrams},建议 2+)")
|
|
344
|
+
|
|
345
|
+
# 组件详细度 (1.5分) - 检查组件描述完整性
|
|
346
|
+
component_sections = len(re.findall(r'### \d+\.\d+', design_content))
|
|
347
|
+
interface_definitions = len(re.findall(r'(?:接口定义|Interface|API|方法|Method)', design_content, re.IGNORECASE))
|
|
348
|
+
responsibility_mentions = len(re.findall(r'(?:职责|Responsibility|负责)', design_content, re.IGNORECASE))
|
|
349
|
+
|
|
350
|
+
component_score = 0.0
|
|
351
|
+
if component_sections > 0:
|
|
352
|
+
component_score += min(component_sections * 0.15, 0.5)
|
|
353
|
+
if interface_definitions > 0:
|
|
354
|
+
component_score += min(interface_definitions * 0.1, 0.5)
|
|
355
|
+
if responsibility_mentions > 0:
|
|
356
|
+
component_score += min(responsibility_mentions * 0.1, 0.5)
|
|
357
|
+
|
|
358
|
+
criteria_scores['component_detail'] = component_score
|
|
359
|
+
score += component_score
|
|
360
|
+
|
|
361
|
+
if component_sections < 3:
|
|
362
|
+
issues.append(f"组件数量较少 (当前 {component_sections},建议 3+)")
|
|
363
|
+
|
|
364
|
+
# 技术选型说明 (1分)
|
|
365
|
+
tech_keywords = ['技术选型', '技术栈', '框架选择', '数据库', 'API', '协议']
|
|
366
|
+
tech_coverage = sum(1 for keyword in tech_keywords if keyword in design_content)
|
|
367
|
+
tech_score = min(tech_coverage * 0.2, 1.0)
|
|
368
|
+
criteria_scores['technology'] = tech_score
|
|
369
|
+
score += tech_score
|
|
370
|
+
|
|
371
|
+
if tech_coverage < 2:
|
|
372
|
+
issues.append("技术选型说明不足")
|
|
373
|
+
|
|
374
|
+
# 非功能需求设计 (1分)
|
|
375
|
+
nfr_design = ['性能设计', '安全设计', '可扩展性', '容错机制', '监控', '日志']
|
|
376
|
+
nfr_coverage = sum(1 for keyword in nfr_design if keyword in design_content)
|
|
377
|
+
nfr_score = min(nfr_coverage * 0.2, 1.0)
|
|
378
|
+
criteria_scores['nfr_design'] = nfr_score
|
|
379
|
+
score += nfr_score
|
|
380
|
+
|
|
381
|
+
missing_nfr = [kw for kw in nfr_design if kw not in design_content]
|
|
382
|
+
if len(missing_nfr) > 3:
|
|
383
|
+
issues.append(f"缺少非功能需求设计: {', '.join(missing_nfr[:3])}")
|
|
384
|
+
|
|
385
|
+
# 接口定义完整性 (1分)
|
|
386
|
+
interface_indicators = len(re.findall(r'(?:接口定义|API\s*设计|数据结构|参数说明|返回值)', design_content))
|
|
387
|
+
interface_score = min(interface_indicators * 0.25, 1.0)
|
|
388
|
+
criteria_scores['interfaces'] = interface_score
|
|
389
|
+
score += interface_score
|
|
390
|
+
else:
|
|
391
|
+
# 英文评分标准 - 增强版
|
|
392
|
+
# 基础结构检查 (2.5分) - 更严格的检查
|
|
393
|
+
structure_score = 0.0
|
|
394
|
+
|
|
395
|
+
# 检查 Overview/Introduction
|
|
396
|
+
if "## Overview" in design_content or "## Introduction" in design_content:
|
|
397
|
+
structure_score += 0.5
|
|
398
|
+
# 检查内容充实度
|
|
399
|
+
overview_match = re.search(r'##.*?(?:Overview|Introduction).*?\n(.*?)(?=\n##|\Z)', design_content, re.DOTALL | re.IGNORECASE)
|
|
400
|
+
if overview_match and len(overview_match.group(1).strip()) < 150:
|
|
401
|
+
incomplete_sections.append("Overview/Introduction content is too brief")
|
|
402
|
+
else:
|
|
403
|
+
missing_sections.append("Overview/Introduction")
|
|
404
|
+
|
|
405
|
+
# 检查 Architecture
|
|
406
|
+
if "## Architecture" in design_content or "## System Architecture" in design_content:
|
|
407
|
+
structure_score += 0.5
|
|
408
|
+
else:
|
|
409
|
+
missing_sections.append("Architecture")
|
|
410
|
+
|
|
411
|
+
# 检查 Components
|
|
412
|
+
if "## Components" in design_content or "## Component" in design_content:
|
|
413
|
+
structure_score += 0.5
|
|
414
|
+
else:
|
|
415
|
+
missing_sections.append("Components")
|
|
416
|
+
|
|
417
|
+
# 检查 Interfaces/Data Flow
|
|
418
|
+
if "## Interface" in design_content or "## Data Flow" in design_content or "## API" in design_content:
|
|
419
|
+
structure_score += 0.5
|
|
420
|
+
else:
|
|
421
|
+
missing_sections.append("Interfaces/Data Flow")
|
|
422
|
+
|
|
423
|
+
# 检查 Error Handling
|
|
424
|
+
if "Error Handling" in design_content or "Exception Handling" in design_content:
|
|
425
|
+
structure_score += 0.5
|
|
426
|
+
else:
|
|
427
|
+
missing_sections.append("Error Handling")
|
|
428
|
+
|
|
429
|
+
criteria_scores['structure'] = structure_score
|
|
430
|
+
score += structure_score
|
|
431
|
+
|
|
432
|
+
# 需求追溯性检查 (2.5分) - 更精确的匹配
|
|
433
|
+
req_references = len(re.findall(r'Requirement[s]?\s+\d+\.\d+|_Requirements:\s+\d+\.\d+|Validates:\s+Requirements?\s+\d+\.\d+', design_content, re.IGNORECASE))
|
|
434
|
+
# 检查双向追溯
|
|
435
|
+
bidirectional_refs = len(re.findall(r'Validates:\s*Requirements?\s+\d+\.\d+', design_content, re.IGNORECASE))
|
|
436
|
+
|
|
437
|
+
traceability_score = min(req_references * 0.12, 2.0)
|
|
438
|
+
if bidirectional_refs > 0:
|
|
439
|
+
traceability_score += min(bidirectional_refs * 0.08, 0.5)
|
|
440
|
+
|
|
441
|
+
criteria_scores['traceability'] = traceability_score
|
|
442
|
+
score += traceability_score
|
|
443
|
+
|
|
444
|
+
if req_references < 3:
|
|
445
|
+
issues.append(f"Few requirements references (current {req_references}, target 5+)")
|
|
446
|
+
if bidirectional_refs == 0:
|
|
447
|
+
issues.append("Missing bidirectional traceability (Validates: Requirements X.Y)")
|
|
448
|
+
|
|
449
|
+
# 架构图和设计图 (1.5分) - 检查图表质量
|
|
450
|
+
mermaid_diagrams = len(re.findall(r'```mermaid', design_content))
|
|
451
|
+
plantuml_diagrams = len(re.findall(r'```plantuml', design_content))
|
|
452
|
+
diagram_keywords = len(re.findall(r'Architecture Diagram|Component Diagram|Sequence Diagram|Flow Diagram', design_content, re.IGNORECASE))
|
|
453
|
+
|
|
454
|
+
total_diagrams = mermaid_diagrams + plantuml_diagrams + diagram_keywords
|
|
455
|
+
diagram_score = min(total_diagrams * 0.35, 1.5)
|
|
456
|
+
criteria_scores['diagrams'] = diagram_score
|
|
457
|
+
score += diagram_score
|
|
458
|
+
|
|
459
|
+
if total_diagrams == 0:
|
|
460
|
+
missing_sections.append("Architecture/Design Diagrams")
|
|
461
|
+
elif total_diagrams < 2:
|
|
462
|
+
issues.append(f"Few diagrams (current {total_diagrams}, target 2+)")
|
|
463
|
+
|
|
464
|
+
# 组件详细度 (1.5分) - 检查组件描述完整性
|
|
465
|
+
component_sections = len(re.findall(r'### \d+\.', design_content))
|
|
466
|
+
interface_definitions = len(re.findall(r'(?:Interface|API|Method|Function)\s*(?:Definition|Signature)', design_content, re.IGNORECASE))
|
|
467
|
+
responsibility_mentions = len(re.findall(r'Responsibility|Responsibilities|Purpose', design_content, re.IGNORECASE))
|
|
468
|
+
dependency_mentions = len(re.findall(r'Depend(?:s|encies)|Requires?', design_content, re.IGNORECASE))
|
|
469
|
+
|
|
470
|
+
component_score = 0.0
|
|
471
|
+
if component_sections > 0:
|
|
472
|
+
component_score += min(component_sections * 0.12, 0.5)
|
|
473
|
+
if interface_definitions > 0:
|
|
474
|
+
component_score += min(interface_definitions * 0.08, 0.4)
|
|
475
|
+
if responsibility_mentions > 0:
|
|
476
|
+
component_score += min(responsibility_mentions * 0.08, 0.3)
|
|
477
|
+
if dependency_mentions > 0:
|
|
478
|
+
component_score += min(dependency_mentions * 0.06, 0.3)
|
|
479
|
+
|
|
480
|
+
criteria_scores['component_detail'] = component_score
|
|
481
|
+
score += component_score
|
|
482
|
+
|
|
483
|
+
if component_sections < 3:
|
|
484
|
+
issues.append(f"Few components (current {component_sections}, target 3+)")
|
|
485
|
+
|
|
486
|
+
# 技术选型说明 (1分)
|
|
487
|
+
tech_keywords = ['technology', 'framework', 'database', 'api', 'protocol', 'stack', 'library']
|
|
488
|
+
tech_coverage = sum(1 for keyword in tech_keywords if keyword.lower() in design_content.lower())
|
|
489
|
+
tech_score = min(tech_coverage * 0.15, 1.0)
|
|
490
|
+
criteria_scores['technology'] = tech_score
|
|
491
|
+
score += tech_score
|
|
492
|
+
|
|
493
|
+
if tech_coverage < 2:
|
|
494
|
+
issues.append("Insufficient technology stack explanation")
|
|
495
|
+
|
|
496
|
+
# 非功能需求设计 (1分)
|
|
497
|
+
nfr_design = ['performance', 'security', 'scalability', 'fault tolerance', 'monitoring', 'logging', 'error handling']
|
|
498
|
+
nfr_coverage = sum(1 for keyword in nfr_design if keyword.lower() in design_content.lower())
|
|
499
|
+
nfr_score = min(nfr_coverage * 0.15, 1.0)
|
|
500
|
+
criteria_scores['nfr_design'] = nfr_score
|
|
501
|
+
score += nfr_score
|
|
502
|
+
|
|
503
|
+
missing_nfr = [kw for kw in nfr_design if kw.lower() not in design_content.lower()]
|
|
504
|
+
if len(missing_nfr) > 4:
|
|
505
|
+
issues.append(f"Missing non-functional design: {', '.join(missing_nfr[:3])}")
|
|
506
|
+
|
|
507
|
+
# 接口定义完整性 (1分)
|
|
508
|
+
interface_indicators = len(re.findall(r'(?:Interface|API\s+Design|Data\s+Model|Data\s+Structure|Parameter|Return\s+Value)', design_content, re.IGNORECASE))
|
|
509
|
+
interface_score = min(interface_indicators * 0.2, 1.0)
|
|
510
|
+
criteria_scores['interfaces'] = interface_score
|
|
511
|
+
score += interface_score
|
|
512
|
+
|
|
513
|
+
return QualityAssessment(
|
|
514
|
+
score=min(score, 10.0),
|
|
515
|
+
criteria_scores=criteria_scores,
|
|
516
|
+
missing_sections=missing_sections,
|
|
517
|
+
incomplete_sections=incomplete_sections,
|
|
518
|
+
issues=issues,
|
|
519
|
+
language=lang
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
def assess_tasks_quality(self, content: str) -> QualityAssessment:
|
|
523
|
+
"""评估 Tasks 文档完整性"""
|
|
524
|
+
# 匹配不同状态的任务
|
|
525
|
+
completed_tasks = re.findall(r'- \[x\] (.+)', content)
|
|
526
|
+
in_progress_tasks = re.findall(r'- \[-\] (.+)', content)
|
|
527
|
+
not_started_tasks = re.findall(r'- \[ \] (.+)', content)
|
|
528
|
+
queued_tasks = re.findall(r'- \[~\] (.+)', content)
|
|
529
|
+
|
|
530
|
+
total_count = len(completed_tasks) + len(in_progress_tasks) + len(not_started_tasks) + len(queued_tasks)
|
|
531
|
+
completed_count = len(completed_tasks)
|
|
532
|
+
|
|
533
|
+
# 基于完成率计算分数
|
|
534
|
+
completion_rate = (completed_count / total_count * 100) if total_count > 0 else 0
|
|
535
|
+
score = completion_rate / 10.0 # 转换为 0-10 分
|
|
536
|
+
|
|
537
|
+
issues = []
|
|
538
|
+
if total_count == 0:
|
|
539
|
+
issues.append("No tasks found in document")
|
|
540
|
+
elif completion_rate < 50:
|
|
541
|
+
issues.append(f"Low completion rate: {completion_rate:.1f}%")
|
|
542
|
+
|
|
543
|
+
return QualityAssessment(
|
|
544
|
+
score=min(score, 10.0),
|
|
545
|
+
criteria_scores={'completion_rate': score},
|
|
546
|
+
missing_sections=[],
|
|
547
|
+
incomplete_sections=[],
|
|
548
|
+
issues=issues,
|
|
549
|
+
language='en'
|
|
550
|
+
)
|