pdd-skills 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/README.md +1478 -0
- package/bin/pdd.js +354 -0
- package/config/bpmn-rules.yaml +166 -0
- package/config/checkstyle.xml +105 -0
- package/config/eslint.config.js +48 -0
- package/config/pmd.xml +91 -0
- package/config/prd-rules.yaml +113 -0
- package/config/ruff.toml +45 -0
- package/config/sqlfluff.cfg +82 -0
- package/hooks/hook-executor.js +332 -0
- package/index.js +43 -0
- package/lib/api-routes.js +750 -0
- package/lib/api-server.js +408 -0
- package/lib/cache/cache-config.js +209 -0
- package/lib/cache/system-cache.js +852 -0
- package/lib/config-manager.js +373 -0
- package/lib/generate.js +528 -0
- package/lib/grpc/grpc-routes.js +1134 -0
- package/lib/grpc/grpc-server.js +912 -0
- package/lib/grpc/proto-definitions.js +1033 -0
- package/lib/init.js +172 -0
- package/lib/iteration/auto-fixer.js +1025 -0
- package/lib/iteration/auto-reviewer.js +923 -0
- package/lib/iteration/controller.js +577 -0
- package/lib/list.js +130 -0
- package/lib/mcp-server.js +548 -0
- package/lib/openclaw/api-integration.js +535 -0
- package/lib/openclaw/cli-integration.js +567 -0
- package/lib/openclaw/data-sync.js +845 -0
- package/lib/openclaw/openclaw-adapter.js +783 -0
- package/lib/plugin/example-plugins/code-stats/index.js +332 -0
- package/lib/plugin/example-plugins/code-stats/plugin.json +1 -0
- package/lib/plugin/example-plugins/custom-linter/index.js +472 -0
- package/lib/plugin/example-plugins/custom-linter/plugin.json +1 -0
- package/lib/plugin/example-plugins/hello-world/index.js +86 -0
- package/lib/plugin/example-plugins/hello-world/plugin.json +1 -0
- package/lib/plugin/plugin-manager.js +655 -0
- package/lib/plugin/plugin-sdk.js +565 -0
- package/lib/plugin/sandbox.js +627 -0
- package/lib/quality/rules/maintainability.js +418 -0
- package/lib/quality/rules/performance.js +498 -0
- package/lib/quality/rules/readability.js +441 -0
- package/lib/quality/rules/robustness.js +504 -0
- package/lib/quality/rules/security.js +444 -0
- package/lib/quality/scorer.js +576 -0
- package/lib/report.js +669 -0
- package/lib/sdk-base.js +301 -0
- package/lib/sdk-js.js +446 -0
- package/lib/sdk-python/README.md +546 -0
- package/lib/sdk-python/examples/basic_usage.py +450 -0
- package/lib/sdk-python/pdd_sdk/__init__.py +180 -0
- package/lib/sdk-python/pdd_sdk/client.py +1170 -0
- package/lib/sdk-python/pdd_sdk/events.py +423 -0
- package/lib/sdk-python/pdd_sdk/exceptions.py +158 -0
- package/lib/sdk-python/pdd_sdk/models.py +518 -0
- package/lib/sdk-python/pdd_sdk/utils.py +759 -0
- package/lib/token/budget-alert.js +367 -0
- package/lib/token/budget-manager.js +485 -0
- package/lib/update.js +54 -0
- package/lib/utils/logger.js +88 -0
- package/lib/verify.js +741 -0
- package/lib/version.js +52 -0
- package/lib/vm/README.md +102 -0
- package/lib/vm/dashboard/api-routes.js +669 -0
- package/lib/vm/dashboard/server.js +391 -0
- package/lib/vm/dashboard/sse.js +358 -0
- package/lib/vm/dashboard/static/css/dashboard.css +1378 -0
- package/lib/vm/dashboard/static/index.html +118 -0
- package/lib/vm/dashboard/static/js/app.js +949 -0
- package/lib/vm/dashboard/static/js/charts.js +913 -0
- package/lib/vm/dashboard/static/js/kanban-view.js +1053 -0
- package/lib/vm/dashboard/static/js/pipeline-view.js +463 -0
- package/lib/vm/dashboard/static/js/quality-view.js +598 -0
- package/lib/vm/dashboard/static/js/system-view.js +1021 -0
- package/lib/vm/data-provider.js +1191 -0
- package/lib/vm/event-bus.js +402 -0
- package/lib/vm/hooks/extract-hook.js +307 -0
- package/lib/vm/hooks/generate-hook.js +374 -0
- package/lib/vm/hooks/hook-interface.js +458 -0
- package/lib/vm/hooks/report-hook.js +331 -0
- package/lib/vm/hooks/verify-hook.js +454 -0
- package/lib/vm/models.js +1003 -0
- package/lib/vm/reconciler.js +855 -0
- package/lib/vm/scanner.js +988 -0
- package/lib/vm/state-schema.js +955 -0
- package/lib/vm/state-store.js +733 -0
- package/lib/vm/tui/components/card.js +339 -0
- package/lib/vm/tui/components/progress-bar.js +368 -0
- package/lib/vm/tui/components/sparkline.js +327 -0
- package/lib/vm/tui/components/status-light.js +294 -0
- package/lib/vm/tui/components/table.js +370 -0
- package/lib/vm/tui/input.js +335 -0
- package/lib/vm/tui/renderer.js +548 -0
- package/lib/vm/tui/screens/kanban-screen.js +397 -0
- package/lib/vm/tui/screens/overview-screen.js +357 -0
- package/lib/vm/tui/screens/quality-screen.js +336 -0
- package/lib/vm/tui/screens/system-screen.js +379 -0
- package/lib/vm/tui/tui.js +805 -0
- package/package.json +1 -0
- package/scripts/cso-analyzer.js +198 -0
- package/scripts/eval-runner.js +359 -0
- package/scripts/i18n-checker.js +109 -0
- package/scripts/linter/activiti-linter.js +272 -0
- package/scripts/linter/prd-linter.js +162 -0
- package/scripts/linter/report-generator.js +207 -0
- package/scripts/linter/run-linters.js +285 -0
- package/scripts/linter/sql-linter.js +166 -0
- package/scripts/token-analyzer.js +162 -0
- package/scripts/vm-test.js +180 -0
- package/skills/core/official-doc-writer/LICENSE +21 -0
- package/skills/core/official-doc-writer/README.md +232 -0
- package/skills/core/official-doc-writer/SKILL.md +475 -0
- package/skills/core/official-doc-writer/_meta.json +1 -0
- package/skills/core/official-doc-writer/document_generator.py +580 -0
- package/skills/core/official-doc-writer/evals/default-evals.json +1 -0
- package/skills/core/official-doc-writer/examples.md +150 -0
- package/skills/core/official-doc-writer/fonts/FONTS_LIST.md +45 -0
- package/skills/core/official-doc-writer/fonts/README.md +141 -0
- package/skills/core/official-doc-writer/fonts/SIMFANG.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMHEI.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMKAI.TTF +0 -0
- package/skills/core/official-doc-writer/fonts/SIMSUN.TTC +0 -0
- package/skills/core/official-doc-writer/fonts//346/226/271/346/255/243/345/260/217/346/240/207/345/256/213GBK.TTF +0 -0
- package/skills/core/official-doc-writer/references/GBT_9704-2012_/345/205/232/346/224/277/346/234/272/345/205/263/345/205/254/346/226/207/346/240/274/345/274/217.md +422 -0
- package/skills/core/official-doc-writer/scripts/__pycache__/generate_official_doc.cpython-313.pyc +0 -0
- package/skills/core/official-doc-writer/scripts/dialog_manager.py +564 -0
- package/skills/core/official-doc-writer/scripts/generate_official_doc.py +252 -0
- package/skills/core/official-doc-writer/scripts/install_fonts.py +390 -0
- package/skills/core/official-doc-writer/scripts/smart_prompts.py +363 -0
- package/skills/core/pdd-ba/SKILL.md +305 -0
- package/skills/core/pdd-ba/_meta.json +1 -0
- package/skills/core/pdd-ba/evals/default-evals.json +1 -0
- package/skills/core/pdd-code-reviewer/SKILL.md +378 -0
- package/skills/core/pdd-code-reviewer/_meta.json +1 -0
- package/skills/core/pdd-code-reviewer/evals/default-evals.json +1 -0
- package/skills/core/pdd-doc-change/SKILL.md +350 -0
- package/skills/core/pdd-doc-change/_meta.json +1 -0
- package/skills/core/pdd-doc-change/evals/default-evals.json +1 -0
- package/skills/core/pdd-doc-gardener/SKILL.md +248 -0
- package/skills/core/pdd-doc-gardener/_meta.json +1 -0
- package/skills/core/pdd-doc-gardener/evals/default-evals.json +1 -0
- package/skills/core/pdd-entropy-reduction/SKILL.md +360 -0
- package/skills/core/pdd-entropy-reduction/_meta.json +1 -0
- package/skills/core/pdd-entropy-reduction/evals/default-evals.json +1 -0
- package/skills/core/pdd-entropy-reduction/references/entropy-report-template.md +287 -0
- package/skills/core/pdd-entropy-reduction/references/golden-principles.md +573 -0
- package/skills/core/pdd-entropy-reduction/scripts/entropy_scan.py +712 -0
- package/skills/core/pdd-extract-features/SKILL.md +320 -0
- package/skills/core/pdd-extract-features/_meta.json +1 -0
- package/skills/core/pdd-extract-features/evals/default-evals.json +1 -0
- package/skills/core/pdd-generate-spec/SKILL.md +418 -0
- package/skills/core/pdd-generate-spec/_meta.json +1 -0
- package/skills/core/pdd-generate-spec/evals/default-evals.json +1 -0
- package/skills/core/pdd-implement-feature/SKILL.md +332 -0
- package/skills/core/pdd-implement-feature/_meta.json +1 -0
- package/skills/core/pdd-implement-feature/evals/default-evals.json +1 -0
- package/skills/core/pdd-main/SKILL.md +540 -0
- package/skills/core/pdd-main/_meta.json +1 -0
- package/skills/core/pdd-main/evals/default-evals.json +1 -0
- package/skills/core/pdd-main/evals/evals.json +215 -0
- package/skills/core/pdd-verify-feature/SKILL.md +474 -0
- package/skills/core/pdd-verify-feature/_meta.json +1 -0
- package/skills/core/pdd-verify-feature/evals/default-evals.json +1 -0
- package/skills/core/pdd-vm/evals/default-evals.json +1 -0
- package/skills/core/traffic-accident-assessor/LICENSE +29 -0
- package/skills/core/traffic-accident-assessor/SKILL.md +439 -0
- package/skills/core/traffic-accident-assessor/evals/evals.json +1 -0
- package/skills/core/traffic-accident-assessor/references/accident-types.md +369 -0
- package/skills/core/traffic-accident-assessor/references/liability-rules.md +287 -0
- package/skills/core/traffic-accident-assessor/references/traffic-laws.md +226 -0
- package/skills/core/traffic-accident-assessor/references//351/253/230/345/260/224/345/244/253/350/257/264/346/230/216/344/271/246.pdf +32576 -106
- package/skills/core/traffic-accident-assessor/scripts/generate_official_statement.py +588 -0
- package/skills/core/traffic-accident-assessor/scripts/generate_report.py +495 -0
- package/skills/core/traffic-accident-assessor/scripts/generate_statement.py +528 -0
- package/skills/core/traffic-accident-assessor.zip +0 -0
- package/skills/entropy/expert-arch-enforcer/SKILL.md +292 -0
- package/skills/entropy/expert-arch-enforcer/_meta.json +1 -0
- package/skills/entropy/expert-arch-enforcer/evals/default-evals.json +1 -0
- package/skills/entropy/expert-auto-refactor/SKILL.md +327 -0
- package/skills/entropy/expert-auto-refactor/_meta.json +1 -0
- package/skills/entropy/expert-auto-refactor/evals/default-evals.json +1 -0
- package/skills/entropy/expert-code-quality/SKILL.md +468 -0
- package/skills/entropy/expert-code-quality/_meta.json +1 -0
- package/skills/entropy/expert-code-quality/evals/default-evals.json +1 -0
- package/skills/entropy/expert-code-quality/evals/evals.json +109 -0
- package/skills/entropy/expert-code-quality/references/code-smells.md +605 -0
- package/skills/entropy/expert-code-quality/references/design-patterns.md +1111 -0
- package/skills/entropy/expert-code-quality/references/refactoring-catalog.md +1281 -0
- package/skills/entropy/expert-code-quality/references/solid-principles.md +524 -0
- package/skills/entropy/expert-entropy-auditor/SKILL.md +276 -0
- package/skills/entropy/expert-entropy-auditor/_meta.json +1 -0
- package/skills/entropy/expert-entropy-auditor/evals/default-evals.json +1 -0
- package/skills/expert/expert-activiti/SKILL.md +497 -0
- package/skills/expert/expert-activiti/_meta.json +1 -0
- package/skills/expert/expert-mysql/SKILL.md +832 -0
- package/skills/expert/expert-mysql/_meta.json +1 -0
- package/skills/expert/expert-performance/SKILL.md +379 -0
- package/skills/expert/expert-performance/_meta.json +1 -0
- package/skills/expert/expert-performance/evals/default-evals.json +1 -0
- package/skills/expert/expert-ruoyi/SKILL.md +472 -0
- package/skills/expert/expert-ruoyi/_meta.json +1 -0
- package/skills/expert/expert-security/SKILL.md +1341 -0
- package/skills/expert/expert-security/_meta.json +1 -0
- package/skills/expert/expert-security/evals/default-evals.json +1 -0
- package/skills/expert/software-architect/SKILL.md +350 -0
- package/skills/expert/software-architect/_meta.json +1 -0
- package/skills/expert/software-engineer/SKILL.md +437 -0
- package/skills/expert/software-engineer/_meta.json +1 -0
- package/skills/expert/software-engineer/architecture.md +130 -0
- package/skills/expert/software-engineer/patterns.md +151 -0
- package/skills/expert/software-engineer/testing.md +135 -0
- package/skills/expert/system-architect/SKILL.md +628 -0
- package/skills/expert/system-architect/_meta.json +1 -0
- package/skills/expert/system-architect/assets/templates/ARCHITECTURE.md +25 -0
- package/skills/expert/system-architect/assets/templates/README.md +44 -0
- package/skills/expert/system-architect/references/js-ts-standards.md +18 -0
- package/skills/expert/system-architect/references/python-standards.md +19 -0
- package/skills/expert/system-architect/references/scaffolding.md +61 -0
- package/skills/expert/system-architect/references/security-checklist.md +21 -0
- package/skills/openspec/openspec-apply-change/SKILL.md +156 -0
- package/skills/openspec/openspec-apply-change/_meta.json +1 -0
- package/skills/openspec/openspec-archive-change/SKILL.md +114 -0
- package/skills/openspec/openspec-archive-change/_meta.json +1 -0
- package/skills/openspec/openspec-bulk-archive-change/SKILL.md +246 -0
- package/skills/openspec/openspec-bulk-archive-change/_meta.json +1 -0
- package/skills/openspec/openspec-continue-change/SKILL.md +118 -0
- package/skills/openspec/openspec-continue-change/_meta.json +1 -0
- package/skills/openspec/openspec-explore/SKILL.md +288 -0
- package/skills/openspec/openspec-explore/_meta.json +1 -0
- package/skills/openspec/openspec-ff-change/SKILL.md +101 -0
- package/skills/openspec/openspec-ff-change/_meta.json +1 -0
- package/skills/openspec/openspec-new-change/SKILL.md +74 -0
- package/skills/openspec/openspec-new-change/_meta.json +1 -0
- package/skills/openspec/openspec-onboard/SKILL.md +554 -0
- package/skills/openspec/openspec-onboard/_meta.json +1 -0
- package/skills/openspec/openspec-sync-specs/SKILL.md +138 -0
- package/skills/openspec/openspec-sync-specs/_meta.json +1 -0
- package/skills/openspec/openspec-verify-change/SKILL.md +168 -0
- package/skills/openspec/openspec-verify-change/_meta.json +1 -0
- package/skills/pr/pdd-multi-review/SKILL.md +534 -0
- package/skills/pr/pdd-multi-review/_meta.json +1 -0
- package/skills/pr/pdd-pr-batch/SKILL.md +303 -0
- package/skills/pr/pdd-pr-batch/_meta.json +1 -0
- package/skills/pr/pdd-pr-create/SKILL.md +344 -0
- package/skills/pr/pdd-pr-create/_meta.json +1 -0
- package/skills/pr/pdd-pr-merge/SKILL.md +286 -0
- package/skills/pr/pdd-pr-merge/_meta.json +1 -0
- package/skills/pr/pdd-pr-review/SKILL.md +217 -0
- package/skills/pr/pdd-pr-review/_meta.json +1 -0
- package/skills/pr/pdd-task-manager/SKILL.md +636 -0
- package/skills/pr/pdd-task-manager/_meta.json +1 -0
- package/skills/pr/pdd-template-engine/SKILL.md +306 -0
- package/skills/pr/pdd-template-engine/_meta.json +1 -0
- package/templates/behavior-shaping/iron-law-template.md +87 -0
- package/templates/behavior-shaping/rationalization-template.md +62 -0
- package/templates/behavior-shaping/red-flags-template.md +70 -0
- package/templates/bilingual-template.md +139 -0
- package/templates/config/default.yaml +47 -0
- package/templates/project/default/README.md +31 -0
- package/templates/project/frontend/README.md +46 -0
- package/templates/project/java/README.md +48 -0
package/lib/report.js
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDD 报告生成模块
|
|
3
|
+
* 支持生成 MD/JSON/HTML 格式的分析报告
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
// 引入chalk用于彩色输出
|
|
14
|
+
let chalk;
|
|
15
|
+
try {
|
|
16
|
+
const chalkModule = await import('chalk');
|
|
17
|
+
chalk = chalkModule.default;
|
|
18
|
+
} catch {
|
|
19
|
+
chalk = {
|
|
20
|
+
cyan: (s) => s,
|
|
21
|
+
green: (s) => s,
|
|
22
|
+
yellow: (s) => s,
|
|
23
|
+
red: (s) => s,
|
|
24
|
+
blue: (s) => s,
|
|
25
|
+
magenta: (s) => s
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 收集项目数据用于报告生成
|
|
31
|
+
* @param {string} projectDir - 项目根目录
|
|
32
|
+
* @returns {Object} 项目数据
|
|
33
|
+
*/
|
|
34
|
+
async function collectProjectData(projectDir) {
|
|
35
|
+
const data = {
|
|
36
|
+
projectInfo: {
|
|
37
|
+
name: '',
|
|
38
|
+
version: '',
|
|
39
|
+
description: ''
|
|
40
|
+
},
|
|
41
|
+
structure: {
|
|
42
|
+
totalFiles: 0,
|
|
43
|
+
totalDirs: 0,
|
|
44
|
+
fileTypes: {},
|
|
45
|
+
directories: []
|
|
46
|
+
},
|
|
47
|
+
skills: [],
|
|
48
|
+
specs: [],
|
|
49
|
+
tests: [],
|
|
50
|
+
timestamp: new Date().toISOString()
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// 1. 收集项目基本信息
|
|
55
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
56
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
57
|
+
const pkg = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf-8'));
|
|
58
|
+
data.projectInfo.name = pkg.name || 'Unknown';
|
|
59
|
+
data.projectInfo.version = pkg.version || '0.0.0';
|
|
60
|
+
data.projectInfo.description = pkg.description || '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 2. 遍历目录结构
|
|
64
|
+
await traverseDirectory(projectDir, data);
|
|
65
|
+
|
|
66
|
+
// 3. 收集技能文件信息
|
|
67
|
+
const skillsDir = path.join(projectDir, 'skills');
|
|
68
|
+
if (fs.existsSync(skillsDir)) {
|
|
69
|
+
data.skills = await collectSkillsInfo(skillsDir);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 4. 收集规格文档信息
|
|
73
|
+
const specsDir = path.join(projectDir, 'dev-specs');
|
|
74
|
+
if (fs.existsSync(specsDir)) {
|
|
75
|
+
data.specs = await collectSpecsInfo(specsDir);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 5. 收集测试文件信息
|
|
79
|
+
const testsDir = path.join(projectDir, 'tests');
|
|
80
|
+
if (fs.existsSync(testsDir)) {
|
|
81
|
+
data.tests = await collectTestsInfo(testsDir);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(chalk.yellow(`⚠️ 收集项目数据时出错: ${error.message}`));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 遍历目录收集结构信息
|
|
93
|
+
* @param {string} dir - 目录路径
|
|
94
|
+
* @param {Object} data - 数据对象
|
|
95
|
+
*/
|
|
96
|
+
async function traverseDirectory(dir, data, depth = 0) {
|
|
97
|
+
if (depth > 5) return; // 防止无限递归
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
101
|
+
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
// 跳过隐藏目录和node_modules
|
|
104
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' ||
|
|
105
|
+
entry.name === '.git' || entry.name === 'dist' || entry.name === 'build') {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const fullPath = path.join(dir, entry.name);
|
|
110
|
+
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
data.totalDirs++;
|
|
113
|
+
|
|
114
|
+
if (depth < 2) { // 只记录前两层目录
|
|
115
|
+
data.directories.push({
|
|
116
|
+
name: entry.name,
|
|
117
|
+
path: path.relative(process.cwd(), fullPath)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
await traverseDirectory(fullPth, data, depth + 1);
|
|
122
|
+
} else if (entry.isFile()) {
|
|
123
|
+
data.totalFiles++;
|
|
124
|
+
|
|
125
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
126
|
+
data.fileTypes[ext] = (data.fileTypes[ext] || 0) + 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
// 忽略权限错误等
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 收集技能信息
|
|
136
|
+
* @param {string} skillsDir - 技能目录
|
|
137
|
+
* @returns {Array} 技能列表
|
|
138
|
+
*/
|
|
139
|
+
async function collectSkillsInfo(skillsDir) {
|
|
140
|
+
const skills = [];
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const categories = await fs.promises.readdir(skillsDir);
|
|
144
|
+
|
|
145
|
+
for (const category of categories) {
|
|
146
|
+
const categoryPath = path.join(skillsDir, category);
|
|
147
|
+
|
|
148
|
+
if (!fs.statSync(categoryPath).isDirectory()) continue;
|
|
149
|
+
|
|
150
|
+
const skillFiles = (await fs.promises.readdir(categoryPath))
|
|
151
|
+
.filter(f => f.endsWith('.md'));
|
|
152
|
+
|
|
153
|
+
for (const skillFile of skillFiles) {
|
|
154
|
+
const skillPath = path.join(categoryPath, skillFile);
|
|
155
|
+
const content = await fs.promises.readFile(skillPath, 'utf-8');
|
|
156
|
+
|
|
157
|
+
skills.push({
|
|
158
|
+
name: skillFile.replace('.md', ''),
|
|
159
|
+
category,
|
|
160
|
+
path: skillPath,
|
|
161
|
+
size: content.length,
|
|
162
|
+
lines: content.split('\n').length,
|
|
163
|
+
hasDescription: content.includes('description:'),
|
|
164
|
+
hasTriggers: content.includes('triggers:')
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error(chalk.yellow(`收集技能信息失败: ${error.message}`));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return skills;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 收集规格文档信息
|
|
177
|
+
* @param {string} specsDir - 规格文档目录
|
|
178
|
+
* @returns {Array} 规格列表
|
|
179
|
+
*/
|
|
180
|
+
async function collectSpecsInfo(specsDir) {
|
|
181
|
+
const specs = [];
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const files = await fs.promises.readdir(specsDir)
|
|
185
|
+
.filter(f => f.endsWith('.md') || f.endsWith('.json'));
|
|
186
|
+
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
const filePath = path.join(specsDir, file);
|
|
189
|
+
const stat = await fs.promises.stat(filePath);
|
|
190
|
+
|
|
191
|
+
specs.push({
|
|
192
|
+
name: file,
|
|
193
|
+
path: filePath,
|
|
194
|
+
size: stat.size,
|
|
195
|
+
modifiedAt: stat.mtime.toISOString(),
|
|
196
|
+
type: path.extname(file).slice(1)
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
// 规格目录可能不存在
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return specs;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 收集测试文件信息
|
|
208
|
+
* @param {string} testsDir - 测试目录
|
|
209
|
+
* @returns {Array} 测试列表
|
|
210
|
+
*/
|
|
211
|
+
async function collectTestsInfo(testsDir) {
|
|
212
|
+
const tests = [];
|
|
213
|
+
|
|
214
|
+
async function findTestFiles(dir) {
|
|
215
|
+
try {
|
|
216
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
217
|
+
|
|
218
|
+
for (const entry of entries) {
|
|
219
|
+
const fullPath = path.join(dir, entry.name);
|
|
220
|
+
|
|
221
|
+
if (entry.isDirectory() && !['node_modules', '.git'].includes(entry.name)) {
|
|
222
|
+
await findTestFiles(fullPath);
|
|
223
|
+
} else if (entry.isFile() &&
|
|
224
|
+
(entry.name.includes('.test.') ||
|
|
225
|
+
entry.name.includes('.spec.') ||
|
|
226
|
+
entry.name === 'test.js')) {
|
|
227
|
+
|
|
228
|
+
const content = await fs.promises.readFile(fullPath, 'utf-8');
|
|
229
|
+
tests.push({
|
|
230
|
+
name: entry.name,
|
|
231
|
+
path: fullPath,
|
|
232
|
+
lines: content.split('\n').length,
|
|
233
|
+
hasAssertions: /expect\(|assert\(|\.to(Equal|Be|Contain)/.test(content)
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
} catch {
|
|
238
|
+
// 忽略错误
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
await findTestFiles(testsDir);
|
|
243
|
+
return tests;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 生成分析报告
|
|
248
|
+
* @param {Object} options - 命令行选项
|
|
249
|
+
*/
|
|
250
|
+
export async function generateReport(options) {
|
|
251
|
+
try {
|
|
252
|
+
console.log(chalk.blue('📊 开始收集项目数据...\n'));
|
|
253
|
+
|
|
254
|
+
// 1. 收集项目数据
|
|
255
|
+
const projectDir = process.cwd();
|
|
256
|
+
const projectData = await collectProjectData(projectDir);
|
|
257
|
+
|
|
258
|
+
// 2. 根据类型生成不同格式的报告
|
|
259
|
+
const outputBase = options.output;
|
|
260
|
+
|
|
261
|
+
switch (options.type.toLowerCase()) {
|
|
262
|
+
case 'json':
|
|
263
|
+
await generateJSONReport(projectData, outputBase + '.json', options);
|
|
264
|
+
break;
|
|
265
|
+
case 'html':
|
|
266
|
+
await generateHTMLReport(projectData, outputBase + '.html', options);
|
|
267
|
+
break;
|
|
268
|
+
case 'md':
|
|
269
|
+
default:
|
|
270
|
+
await generateMarkdownReport(projectData, outputBase + '.md', options);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
console.log(chalk.green('\n✅ 报告生成完成!\n'));
|
|
275
|
+
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error(chalk.red(`\n❌ 报告生成失败: ${error.message}\n`));
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 生成 Markdown 格式报告
|
|
284
|
+
* @param {Object} data - 项目数据
|
|
285
|
+
* @param {string} outputPath - 输出路径
|
|
286
|
+
* @param {Object} options - 选项
|
|
287
|
+
*/
|
|
288
|
+
async function generateMarkdownReport(data, outputPath, options) {
|
|
289
|
+
let report = `# PDD 项目分析报告
|
|
290
|
+
|
|
291
|
+
> **生成时间:** ${new Date(data.timestamp).toLocaleString('zh-CN')}
|
|
292
|
+
> **项目名称:** ${data.projectInfo.name || 'Unknown'}
|
|
293
|
+
> **版本:** ${data.projectInfo.version || 'N/A'}
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 📋 项目概览
|
|
298
|
+
|
|
299
|
+
| 指标 | 数值 |
|
|
300
|
+
|------|------|
|
|
301
|
+
| 总文件数 | ${data.structure.totalFiles.toLocaleString()} |
|
|
302
|
+
| 总目录数 | ${data.structure.totalDirs.toLocaleString()} |
|
|
303
|
+
| 技能数量 | ${data.skills.length} |
|
|
304
|
+
| 规格文档 | ${data.specs.length} |
|
|
305
|
+
| 测试文件 | ${data.tests.length} |
|
|
306
|
+
|
|
307
|
+
`;
|
|
308
|
+
|
|
309
|
+
// 文件类型分布
|
|
310
|
+
if (options.includeStats && Object.keys(data.structure.fileTypes).length > 0) {
|
|
311
|
+
report += `## 📁 文件类型分布
|
|
312
|
+
|
|
313
|
+
| 扩展名 | 数量 | 占比 |
|
|
314
|
+
|--------|------|------|
|
|
315
|
+
${Object.entries(data.structure.fileTypes)
|
|
316
|
+
.sort((a, b) => b[1] - a[1])
|
|
317
|
+
.map(([ext, count]) => {
|
|
318
|
+
const percent = ((count / data.structure.totalFiles) * 100).toFixed(1);
|
|
319
|
+
return `| ${ext || '(无)'} | ${count} | ${percent}% |`;
|
|
320
|
+
})
|
|
321
|
+
.join('\n')}
|
|
322
|
+
|
|
323
|
+
`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 目录结构
|
|
327
|
+
if (data.directories.length > 0) {
|
|
328
|
+
report += `## 🗂️ 目录结构
|
|
329
|
+
|
|
330
|
+
\`\`\`
|
|
331
|
+
${process.cwd()}/
|
|
332
|
+
${data.directories.map(d => `├── ${d.name}/`).join('\n')}
|
|
333
|
+
\`\`\`
|
|
334
|
+
|
|
335
|
+
`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 技能统计
|
|
339
|
+
if (data.skills.length > 0) {
|
|
340
|
+
report += `## 🎯 技能统计
|
|
341
|
+
|
|
342
|
+
### 分类概览
|
|
343
|
+
|
|
344
|
+
`;
|
|
345
|
+
|
|
346
|
+
// 按分类统计
|
|
347
|
+
const skillsByCategory = {};
|
|
348
|
+
for (const skill of data.skills) {
|
|
349
|
+
if (!skillsByCategory[skill.category]) {
|
|
350
|
+
skillsByCategory[skill.category] = [];
|
|
351
|
+
}
|
|
352
|
+
skillsByCategory[skill.category].push(skill);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
for (const [category, skills] of Object.entries(skillsByCategory)) {
|
|
356
|
+
report += `#### ${category}
|
|
357
|
+
- 技能数量: ${skills.length}
|
|
358
|
+
- 完整性: ${skills.filter(s => s.hasDescription && s.hasTriggers).length}/${skills.length}
|
|
359
|
+
`;
|
|
360
|
+
|
|
361
|
+
if (options.includeStats) {
|
|
362
|
+
report += `- 技能列表:\n`;
|
|
363
|
+
for (const skill of skills.slice(0, 10)) {
|
|
364
|
+
report += ` - ${skill.name} (${skill.lines} 行)\n`;
|
|
365
|
+
}
|
|
366
|
+
if (skills.length > 10) {
|
|
367
|
+
report += ` - ... 还有 ${skills.length - 10} 个\n`;
|
|
368
|
+
}
|
|
369
|
+
report += '\n';
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 规格文档
|
|
375
|
+
if (data.specs.length > 0) {
|
|
376
|
+
report += `## 📄 规格文档
|
|
377
|
+
|
|
378
|
+
| 文档名称 | 类型 | 大小 | 最后修改 |
|
|
379
|
+
|----------|------|------|----------|
|
|
380
|
+
${data.specs.map(s => {
|
|
381
|
+
const sizeKB = (s.size / 1024).toFixed(2);
|
|
382
|
+
const modified = new Date(s.modifiedAt).toLocaleDateString('zh-CN');
|
|
383
|
+
return `| ${s.name} | ${s.type.toUpperCase()} | ${sizeKB} KB | ${modified} |`;
|
|
384
|
+
}).join('\n')}
|
|
385
|
+
|
|
386
|
+
`;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 测试覆盖情况
|
|
390
|
+
if (data.tests.length > 0) {
|
|
391
|
+
const testsWithAssertions = data.tests.filter(t => t.hasAssertions).length;
|
|
392
|
+
|
|
393
|
+
report += `## 🧪 测试概况
|
|
394
|
+
|
|
395
|
+
- **测试文件总数:** ${data.tests.length}
|
|
396
|
+
- **包含断言的测试:** ${testsWithAssertions}/${data.tests.length}
|
|
397
|
+
- **覆盖率估算:** ${((testsWithAssertions / Math.max(data.tests.length, 1)) * 100).toFixed(1)}%
|
|
398
|
+
|
|
399
|
+
### 测试文件列表
|
|
400
|
+
|
|
401
|
+
${data.tests.map(t => `- ${t.name} (${t.lines} 行)`).join('\n')}
|
|
402
|
+
|
|
403
|
+
`;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// 建议和改进方向
|
|
407
|
+
report += `## 💡 建议与改进
|
|
408
|
+
|
|
409
|
+
`;
|
|
410
|
+
|
|
411
|
+
const recommendations = generateRecommendations(data);
|
|
412
|
+
for (let i = 0; i < recommendations.length; i++) {
|
|
413
|
+
report += `${i + 1}. ${recommendations[i]}\n`;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
report += `
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
*本报告由 PDD-Skills CLI 工具自动生成*
|
|
420
|
+
`;
|
|
421
|
+
|
|
422
|
+
// 确保输出目录存在
|
|
423
|
+
const outputDir = path.dirname(outputPath);
|
|
424
|
+
if (!fs.existsSync(outputDir)) {
|
|
425
|
+
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
await fs.promises.writeFile(outputPath, report, 'utf-8');
|
|
429
|
+
console.log(chalk.cyan(`📝 Markdown报告已保存: ${outputPath}`));
|
|
430
|
+
|
|
431
|
+
// 显示报告预览(前30行)
|
|
432
|
+
console.log('\n' + '-'.repeat(70));
|
|
433
|
+
console.log('报告预览:');
|
|
434
|
+
console.log('-'.repeat(70) + '\n');
|
|
435
|
+
console.log(report.split('\n').slice(0, 40).join('\n'));
|
|
436
|
+
if (report.split('\n').length > 40) {
|
|
437
|
+
console.log('\n... (报告较长,请查看完整文件)');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* 生成 JSON 格式报告
|
|
443
|
+
* @param {Object} data - 项目数据
|
|
444
|
+
* @param {string} outputPath - 输出路径
|
|
445
|
+
* @param {Object} options - 选项
|
|
446
|
+
*/
|
|
447
|
+
async function generateJSONReport(data, outputPath, options) {
|
|
448
|
+
const jsonData = {
|
|
449
|
+
metadata: {
|
|
450
|
+
generatedAt: data.timestamp,
|
|
451
|
+
generator: 'pdd-skills',
|
|
452
|
+
version: '3.0.0'
|
|
453
|
+
},
|
|
454
|
+
project: data.projectInfo,
|
|
455
|
+
summary: {
|
|
456
|
+
totalFiles: data.structure.totalFiles,
|
|
457
|
+
totalDirectories: data.structure.totalDirs,
|
|
458
|
+
skillsCount: data.skills.length,
|
|
459
|
+
specsCount: data.specs.length,
|
|
460
|
+
testsCount: data.tests.length,
|
|
461
|
+
fileTypes: data.structure.fileTypes
|
|
462
|
+
},
|
|
463
|
+
skills: data.skills,
|
|
464
|
+
specs: data.specs,
|
|
465
|
+
tests: data.tests,
|
|
466
|
+
recommendations: generateRecommendations(data)
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const outputDir = path.dirname(outputPath);
|
|
470
|
+
if (!fs.existsSync(outputDir)) {
|
|
471
|
+
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
await fs.promises.writeFile(outputPath, JSON.stringify(jsonData, null, 2), 'utf-8');
|
|
475
|
+
console.log(chalk.cyan(`📊 JSON报告已保存: ${outputPath}`));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* 生成 HTML 格式报告
|
|
480
|
+
* @param {Object} data - 项目数据
|
|
481
|
+
* @param {string} outputPath - 输出路径
|
|
482
|
+
* @param {Object} options - 选项
|
|
483
|
+
*/
|
|
484
|
+
async function generateHTMLReport(data, outputPath, options) {
|
|
485
|
+
const html = `<!DOCTYPE html>
|
|
486
|
+
<html lang="zh-CN">
|
|
487
|
+
<head>
|
|
488
|
+
<meta charset="UTF-8">
|
|
489
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
490
|
+
<title>PDD 项目分析报告 - ${data.projectInfo.name}</title>
|
|
491
|
+
<style>
|
|
492
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
493
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; background: #f5f5f5; padding: 20px; }
|
|
494
|
+
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
|
495
|
+
h1 { color: #2c3e50; border-bottom: 3px solid #3498db; padding-bottom: 15px; margin-bottom: 25px; font-size: 28px; }
|
|
496
|
+
h2 { color: #34495e; margin-top: 35px; margin-bottom: 20px; font-size: 22px; border-left: 4px solid #3498db; padding-left: 15px; }
|
|
497
|
+
h3 { color: #555; margin-top: 25px; margin-bottom: 15px; font-size: 18px; }
|
|
498
|
+
table { width: 100%; border-collapse: collapse; margin: 20px 0; background: white; }
|
|
499
|
+
th, td { padding: 12px 15px; text-align: left; border: 1px solid #ddd; }
|
|
500
|
+
th { background: #3498db; color: white; font-weight: 600; }
|
|
501
|
+
tr:nth-child(even) { background: #f9f9f9; }
|
|
502
|
+
tr:hover { background: #f1f7ff; }
|
|
503
|
+
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 25px 0; }
|
|
504
|
+
.stat-card { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 25px; border-radius: 10px; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
|
|
505
|
+
.stat-number { font-size: 36px; font-weight: bold; display: block; margin-bottom: 8px; }
|
|
506
|
+
.stat-label { font-size: 14px; opacity: 0.9; }
|
|
507
|
+
.badge { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 600; background: #e8f4fd; color: #2980b9; }
|
|
508
|
+
.success { background: #d4edda; color: #155724; }
|
|
509
|
+
.warning { background: #fff3cd; color: #856404; }
|
|
510
|
+
.danger { background: #f8d7da; color: #721c24; }
|
|
511
|
+
.footer { text-align: center; margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; color: #888; font-size: 14px; }
|
|
512
|
+
code { background: #f4f4f4; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', monospace; font-size: 14px; }
|
|
513
|
+
</style>
|
|
514
|
+
</head>
|
|
515
|
+
<body>
|
|
516
|
+
<div class="container">
|
|
517
|
+
<h1>🔍 PDD 项目分析报告</h1>
|
|
518
|
+
|
|
519
|
+
<div style="background: #e8f4fd; padding: 20px; border-radius: 8px; margin-bottom: 25px;">
|
|
520
|
+
<strong>项目:</strong> ${data.projectInfo.name || 'Unknown'} |
|
|
521
|
+
<strong>版本:</strong> ${data.projectInfo.version || 'N/A'} |
|
|
522
|
+
<strong>生成时间:</strong> ${new Date(data.timestamp).toLocaleString('zh-CN')}
|
|
523
|
+
</div>
|
|
524
|
+
|
|
525
|
+
<div class="stats-grid">
|
|
526
|
+
<div class="stat-card">
|
|
527
|
+
<span class="stat-number">${data.structure.totalFiles.toLocaleString()}</span>
|
|
528
|
+
<span class="stat-label">总文件数</span>
|
|
529
|
+
</div>
|
|
530
|
+
<div class="stat-card" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
|
|
531
|
+
<span class="stat-number">${data.skills.length}</span>
|
|
532
|
+
<span class="stat-label">技能数量</span>
|
|
533
|
+
</div>
|
|
534
|
+
<div class="stat-card" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
|
|
535
|
+
<span class="stat-number">${data.specs.length}</span>
|
|
536
|
+
<span class="stat-label">规格文档</span>
|
|
537
|
+
</div>
|
|
538
|
+
<div class="stat-card" style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);">
|
|
539
|
+
<span class="stat-number">${data.tests.length}</span>
|
|
540
|
+
<span class="stat-label">测试文件</span>
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
|
|
544
|
+
<h2>📁 文件类型分布</h2>
|
|
545
|
+
<table>
|
|
546
|
+
<thead>
|
|
547
|
+
<tr><th>扩展名</th><th>数量</th><th>占比</th></tr>
|
|
548
|
+
</thead>
|
|
549
|
+
<tbody>
|
|
550
|
+
${Object.entries(data.structure.fileTypes)
|
|
551
|
+
.sort((a, b) => b[1] - a[1])
|
|
552
|
+
.slice(0, 15)
|
|
553
|
+
.map(([ext, count]) => {
|
|
554
|
+
const percent = ((count / data.structure.totalFiles) * 100).toFixed(1);
|
|
555
|
+
return `<tr><td><code>${ext || '(无)'}</code></td><td>${count}</td><td>${percent}%</td></tr>`;
|
|
556
|
+
}).join('\n')}
|
|
557
|
+
</tbody>
|
|
558
|
+
</table>
|
|
559
|
+
|
|
560
|
+
${data.skills.length > 0 ? `
|
|
561
|
+
<h2>🎯 技能统计</h2>
|
|
562
|
+
<table>
|
|
563
|
+
<thead>
|
|
564
|
+
<tr><th>分类</th><th>技能数</th><th>完整性</th></tr>
|
|
565
|
+
</thead>
|
|
566
|
+
<tbody>
|
|
567
|
+
${(() => {
|
|
568
|
+
const byCategory = {};
|
|
569
|
+
data.skills.forEach(s => {
|
|
570
|
+
if (!byCategory[s.category]) byCategory[s.category] = [];
|
|
571
|
+
byCategory[s.category].push(s);
|
|
572
|
+
});
|
|
573
|
+
return Object.entries(byCategory).map(([cat, skills]) => {
|
|
574
|
+
const complete = skills.filter(s => s.hasDescription && s.hasTriggers).length;
|
|
575
|
+
return `<tr><td><strong>${cat}</strong></td><td>${skills.length}</td><td><span class="badge ${complete === skills.length ? 'success' : complete > 0 ? 'warning' : 'danger'}">${complete}/${skills.length}</span></td></tr>`;
|
|
576
|
+
}).join('\n');
|
|
577
|
+
})()}
|
|
578
|
+
</tbody>
|
|
579
|
+
</table>
|
|
580
|
+
` : ''}
|
|
581
|
+
|
|
582
|
+
${data.tests.length > 0 ? `
|
|
583
|
+
<h2>🧪 测试概况</h2>
|
|
584
|
+
<table>
|
|
585
|
+
<thead>
|
|
586
|
+
<tr><th>测试文件</th><th>代码行数</th><th>状态</th></tr>
|
|
587
|
+
</thead>
|
|
588
|
+
<tbody>
|
|
589
|
+
${data.tests.map(t => `<tr><td>${t.name}</td><td>${t.lines}</td><td><span class="badge ${t.hasAssertions ? 'success' : 'warning'}">${t.hasAssertions ? '有断言' : '待完善'}</span></td></tr>`).join('\n')}
|
|
590
|
+
</tbody>
|
|
591
|
+
</table>
|
|
592
|
+
` : ''}
|
|
593
|
+
|
|
594
|
+
<h2>💡 建议</h2>
|
|
595
|
+
<ul style="line-height: 2;">
|
|
596
|
+
${generateRecommendations(data).map(r => `<li>${r}</li>`).join('\n')}
|
|
597
|
+
</ul>
|
|
598
|
+
|
|
599
|
+
<div class="footer">
|
|
600
|
+
<p>由 PDD-Skills CLI 自动生成 | ${new Date(data.timestamp).toLocaleString('zh-CN')}</p>
|
|
601
|
+
</div>
|
|
602
|
+
</div>
|
|
603
|
+
</body>
|
|
604
|
+
</html>`;
|
|
605
|
+
|
|
606
|
+
const outputDir = path.dirname(outputPath);
|
|
607
|
+
if (!fs.existsSync(outputDir)) {
|
|
608
|
+
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
await fs.promises.writeFile(outputPath, html, 'utf-8');
|
|
612
|
+
console.log(chalk.cyan(`🌐 HTML报告已保存: ${outputPath}`));
|
|
613
|
+
|
|
614
|
+
if (options.includeCharts) {
|
|
615
|
+
console.log(chalk.yellow('提示: 图表功能需要额外的前端库支持,当前使用基础表格展示'));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* 生成改进建议
|
|
621
|
+
* @param {Object} data - 项目数据
|
|
622
|
+
* @returns {Array} 建议列表
|
|
623
|
+
*/
|
|
624
|
+
function generateRecommendations(data) {
|
|
625
|
+
const recommendations = [];
|
|
626
|
+
|
|
627
|
+
// 技能相关建议
|
|
628
|
+
if (data.skills.length > 0) {
|
|
629
|
+
const incompleteSkills = data.skills.filter(s => !(s.hasDescription && s.hasTriggers));
|
|
630
|
+
if (incompleteSkills.length > 0) {
|
|
631
|
+
recommendations.push(`有 ${incompleteSkills.length} 个技能缺少完整的description或triggers,建议补充`);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// 规格文档建议
|
|
636
|
+
if (data.specs.length === 0) {
|
|
637
|
+
recommendations.push('项目缺少开发规格文档,建议在 dev-specs/ 目录下创建规格文件');
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// 测试相关建议
|
|
641
|
+
if (data.tests.length === 0) {
|
|
642
|
+
recommendations.push('未发现测试文件,建议添加单元测试以提高代码质量保障');
|
|
643
|
+
} else {
|
|
644
|
+
const testWithoutAssertions = data.tests.filter(t => !t.hasAssertions);
|
|
645
|
+
if (testWithoutAssertions.length > 0) {
|
|
646
|
+
recommendations.push(`${testWithoutAssertions.length} 个测试文件缺少断言,请检查测试有效性`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// README建议
|
|
651
|
+
const readmeExists = fs.existsSync(path.join(process.cwd(), 'README.md'));
|
|
652
|
+
if (!readmeExists) {
|
|
653
|
+
recommendations.push('项目缺少README.md文档,建议添加项目说明文档');
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// 文件组织建议
|
|
657
|
+
if (data.structure.totalFiles > 500) {
|
|
658
|
+
recommendations.push('项目文件较多,建议优化目录结构或考虑模块化拆分');
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// 如果没有问题
|
|
662
|
+
if (recommendations.length === 0) {
|
|
663
|
+
recommendations.push('项目结构良好,继续保持!');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
return recommendations;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export { generateReport, collectProjectData };
|