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
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
// lib/iteration/controller.js - Iteration Controller
|
|
2
|
+
// 控制多轮优化迭代:每轮自动审查 -> 修复 -> 验证循环
|
|
3
|
+
// 集成eval-runner.js进行验证评分
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { AutoReviewer } from './auto-reviewer.js';
|
|
9
|
+
import { AutoFixer } from './auto-fixer.js';
|
|
10
|
+
|
|
11
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 迭代状态枚举
|
|
15
|
+
*/
|
|
16
|
+
export const IterationStatus = {
|
|
17
|
+
IDLE: 'idle',
|
|
18
|
+
REVIEWING: 'reviewing',
|
|
19
|
+
FIXING: 'fixing',
|
|
20
|
+
VERIFYING: 'verifying',
|
|
21
|
+
CONVERGED: 'converged',
|
|
22
|
+
MAX_ROUNDS_REACHED: 'max_rounds_reached',
|
|
23
|
+
ERROR: 'error'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 问题严重级别
|
|
28
|
+
*/
|
|
29
|
+
export const Severity = {
|
|
30
|
+
CRITICAL: 'critical', // 阻塞性问题,必须修复
|
|
31
|
+
MAJOR: 'major', // 重要问题,强烈建议修复
|
|
32
|
+
MINOR: 'minor', // 次要问题,建议修复
|
|
33
|
+
INFO: 'info' // 信息性提示
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 单轮迭代结果
|
|
38
|
+
*/
|
|
39
|
+
class RoundResult {
|
|
40
|
+
constructor(roundNumber) {
|
|
41
|
+
this.round = roundNumber;
|
|
42
|
+
this.status = IterationStatus.IDLE;
|
|
43
|
+
this.startTime = Date.now();
|
|
44
|
+
this.endTime = null;
|
|
45
|
+
this.duration = null;
|
|
46
|
+
this.issues = []; // 审查发现的问题列表
|
|
47
|
+
this.fixSuggestions = []; // 修复建议列表
|
|
48
|
+
this.score = null; // 本轮验证得分 (0-100)
|
|
49
|
+
this.previousScore = null; // 上一轮得分
|
|
50
|
+
this.improvement = null; // 改进幅度 (百分比)
|
|
51
|
+
this.codeVersion = null; // 当前代码版本快照
|
|
52
|
+
this.convergenceReason = null; // 收敛原因(如果已收敛)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
finalize() {
|
|
56
|
+
this.endTime = Date.now();
|
|
57
|
+
this.duration = this.endTime - this.startTime;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* IterationController - 多轮迭代优化控制器
|
|
63
|
+
*
|
|
64
|
+
* 核心循环:
|
|
65
|
+
* Round 1: review(initialCode) -> issues -> fix -> verify -> score
|
|
66
|
+
* Round N: if improvement > threshold -> continue else stop
|
|
67
|
+
*
|
|
68
|
+
* 安全原则:
|
|
69
|
+
* - 自动修复只生成建议,不直接修改源码
|
|
70
|
+
* - 每轮都有完整的审查-修复-验证记录
|
|
71
|
+
* - 收敛检测防止无限循环
|
|
72
|
+
*/
|
|
73
|
+
export class IterationController {
|
|
74
|
+
/**
|
|
75
|
+
* @param {Object} config - 配置选项
|
|
76
|
+
* @param {number} config.maxRounds - 最大迭代轮数 (默认5)
|
|
77
|
+
* @param {number} config.convergenceThreshold - 收敛阈值,改进<此值则停止 (默认0.05即5%)
|
|
78
|
+
* @param {number} config.minScore - 最低可接受分数 (默认60)
|
|
79
|
+
* @param {boolean} config.verbose - 详细输出模式 (默认false)
|
|
80
|
+
* @param {Object} config.reviewerConfig - 审查器配置
|
|
81
|
+
* @param {Object} config.fixerConfig - 修复器配置
|
|
82
|
+
*/
|
|
83
|
+
constructor(config = {}) {
|
|
84
|
+
this.maxRounds = config.maxRounds || 5;
|
|
85
|
+
this.convergenceThreshold = config.convergenceThreshold || 0.05; // 5%
|
|
86
|
+
this.minScore = config.minScore || 60;
|
|
87
|
+
this.verbose = config.verbose || false;
|
|
88
|
+
|
|
89
|
+
// 初始化子模块
|
|
90
|
+
this.reviewer = new AutoReviewer(config.reviewerConfig || {});
|
|
91
|
+
this.fixer = new AutoFixer(config.fixerConfig || {});
|
|
92
|
+
|
|
93
|
+
// 状态跟踪
|
|
94
|
+
this.roundResults = [];
|
|
95
|
+
this.currentRound = 0;
|
|
96
|
+
this.status = IterationStatus.IDLE;
|
|
97
|
+
this.initialCode = null;
|
|
98
|
+
this.currentCode = null;
|
|
99
|
+
this.spec = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 执行多轮迭代优化
|
|
104
|
+
*
|
|
105
|
+
* @param {string} initialCode - 初始代码
|
|
106
|
+
* @param {Object} spec - 开发规格/验收标准
|
|
107
|
+
* @param {Function} [verifyFn] - 自定义验证函数 (可选,用于集成外部验证器如eval-runner)
|
|
108
|
+
* @returns {Promise<Object>} 迭代结果 { rounds, finalScore, improvements, converged, summary }
|
|
109
|
+
*/
|
|
110
|
+
async runIteration(initialCode, spec, verifyFn) {
|
|
111
|
+
// 参数校验
|
|
112
|
+
if (!initialCode || typeof initialCode !== 'string') {
|
|
113
|
+
throw new Error('initialCode必须是非空字符串');
|
|
114
|
+
}
|
|
115
|
+
if (!spec || typeof spec !== 'object') {
|
|
116
|
+
throw new Error('spec必须是有效的规格对象');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 初始化状态
|
|
120
|
+
this.initialCode = initialCode;
|
|
121
|
+
this.currentCode = initialCode;
|
|
122
|
+
this.spec = spec;
|
|
123
|
+
this.roundResults = [];
|
|
124
|
+
this.currentRound = 0;
|
|
125
|
+
this.status = IterationStatus.REVIEWING;
|
|
126
|
+
|
|
127
|
+
console.log(chalk.blue.bold('\n🔄 Iteration Controller - 多轮迭代优化启动\n'));
|
|
128
|
+
console.log(` 最大轮数: ${this.maxRounds}`);
|
|
129
|
+
console.log(` 收敛阈值: ${(this.convergenceThreshold * 100).toFixed(1)}%`);
|
|
130
|
+
console.log(` 最低分数: ${this.minScore}`);
|
|
131
|
+
console.log(` 初始代码长度: ${initialCode.length} 字符`);
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
// 主迭代循环
|
|
135
|
+
while (this.currentRound < this.maxRounds) {
|
|
136
|
+
const shouldContinue = await this._executeRound(verifyFn);
|
|
137
|
+
if (!shouldContinue) break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 生成最终报告
|
|
141
|
+
return this._generateFinalResult();
|
|
142
|
+
|
|
143
|
+
} catch (error) {
|
|
144
|
+
this.status = IterationStatus.ERROR;
|
|
145
|
+
console.error(chalk.red(`\n❌ 迭代过程出错: ${error.message}`));
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 执行单轮迭代: 审查 -> 修复建议 -> 验证评分
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
async _executeRound(verifyFn) {
|
|
155
|
+
this.currentRound++;
|
|
156
|
+
const round = new RoundResult(this.currentRound);
|
|
157
|
+
this.roundResults.push(round);
|
|
158
|
+
|
|
159
|
+
console.log(chalk.cyan.bold(`\n━━━ Round ${this.currentRound}/${this.maxRounds} ━━━`));
|
|
160
|
+
|
|
161
|
+
// Step 1: 自动审查
|
|
162
|
+
round.status = IterationStatus.REVIEWING;
|
|
163
|
+
console.log(chalk.yellow(' 📋 Step 1: 自动审查...'));
|
|
164
|
+
|
|
165
|
+
const reviewResult = await this.reviewer.review(this.currentCode, this.spec);
|
|
166
|
+
round.issues = reviewResult.issues;
|
|
167
|
+
round.codeVersion = reviewResult.codeHash;
|
|
168
|
+
|
|
169
|
+
this._printReviewSummary(reviewResult);
|
|
170
|
+
|
|
171
|
+
// 检查是否无问题(完美代码)
|
|
172
|
+
if (round.issues.length === 0) {
|
|
173
|
+
round.status = IterationStatus.CONVERGED;
|
|
174
|
+
round.convergenceReason = 'no_issues';
|
|
175
|
+
round.finalize();
|
|
176
|
+
console.log(chalk.green(' ✅ 未发现任何问题,代码质量达标'));
|
|
177
|
+
return false; // 停止迭代
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Step 2: 生成修复建议
|
|
181
|
+
round.status = IterationStatus.FIXING;
|
|
182
|
+
console.log(chalk.yellow('\n 🔧 Step 2: 生成修复建议...'));
|
|
183
|
+
|
|
184
|
+
const fixResult = this.fixer.generateFixes(this.currentCode, round.issues, this.spec);
|
|
185
|
+
round.fixSuggestions = fixResult.suggestions;
|
|
186
|
+
|
|
187
|
+
this._printFixSummary(fixResult);
|
|
188
|
+
|
|
189
|
+
// 应用修复到当前代码(生成新版本供下一轮使用)
|
|
190
|
+
// 注意:这里只是模拟应用,实际不会修改原始源码
|
|
191
|
+
if (fixResult.patchedCode && verifyFn) {
|
|
192
|
+
this.currentCode = fixResult.patchedCode;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Step 3: 验证评分
|
|
196
|
+
round.status = IterationStatus.VERIFYING;
|
|
197
|
+
console.log(chalk.yellow('\n 🧪 Step 3: 验证评分...'));
|
|
198
|
+
|
|
199
|
+
let score;
|
|
200
|
+
if (typeof verifyFn === 'function') {
|
|
201
|
+
// 使用自定义验证函数(如集成eval-runner)
|
|
202
|
+
score = await verifyFn(this.currentCode, this.spec, round);
|
|
203
|
+
} else {
|
|
204
|
+
// 使用内置基础评分
|
|
205
|
+
score = this._basicScore(round);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
round.previousScore = this._getPreviousScore();
|
|
209
|
+
round.score = score.value;
|
|
210
|
+
round.improvement = round.previousScore !== null
|
|
211
|
+
? ((score.value - round.previousScore) / Math.max(round.previousScore, 1)) * 100
|
|
212
|
+
: null;
|
|
213
|
+
|
|
214
|
+
this._printScoreSummary(round);
|
|
215
|
+
|
|
216
|
+
round.finalize();
|
|
217
|
+
|
|
218
|
+
// 判断是否继续迭代
|
|
219
|
+
return this.shouldContinue(round);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 判断是否继续迭代
|
|
224
|
+
* @param {RoundResult} roundResult - 当前轮次结果
|
|
225
|
+
* @returns {boolean} 是否继续
|
|
226
|
+
*/
|
|
227
|
+
shouldContinue(roundResult) {
|
|
228
|
+
// 条件1: 达到最高分(100分)
|
|
229
|
+
if (roundResult.score >= 100) {
|
|
230
|
+
roundResult.status = IterationStatus.CONVERGED;
|
|
231
|
+
roundResult.convergenceReason = 'perfect_score';
|
|
232
|
+
console.log(chalk.green('\n 🎯 达到满分,迭代收敛!'));
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 条件2: 超过目标分数且改进幅度低于阈值
|
|
237
|
+
if (roundResult.score >= this.minScore && roundResult.improvement !== null) {
|
|
238
|
+
if (Math.abs(roundResult.improvement) < this.convergenceThreshold * 100) {
|
|
239
|
+
roundResult.status = IterationStatus.CONVERGED;
|
|
240
|
+
roundResult.convergenceReason = 'converged';
|
|
241
|
+
console.log(chalk.green(`\n 📊 改进幅度(${roundResult.improvement.toFixed(2)}%)低于阈值(${(this.convergenceThreshold * 100).toFixed(1)}%),迭代收敛`));
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 条件3: 分数下降(退化)
|
|
247
|
+
if (roundResult.improvement !== null && roundResult.improvement < -10) {
|
|
248
|
+
console.log(chalk.yellow(`\n ⚠️ 分数明显下降(${roundResult.improvement.toFixed(2)}%),可能过度修复`));
|
|
249
|
+
// 继续但发出警告
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 条件4: 达到最大轮数
|
|
253
|
+
if (this.currentRound >= this.maxRounds) {
|
|
254
|
+
roundResult.status = IterationStatus.MAX_ROUNDS_REACHED;
|
|
255
|
+
roundResult.convergenceReason = 'max_rounds';
|
|
256
|
+
console.log(chalk.yellow(`\n ⏹️ 达到最大轮数(${this.maxRounds}),停止迭代`));
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log(chalk.cyan(`\n ➡️ 继续第${this.currentRound + 1}轮迭代...`));
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 获取上一轮的分数
|
|
266
|
+
* @private
|
|
267
|
+
*/
|
|
268
|
+
_getPreviousScore() {
|
|
269
|
+
if (this.roundResults.length <= 1) return null;
|
|
270
|
+
return this.roundResults[this.roundResults.length - 2].score;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* 内置基础评分算法
|
|
275
|
+
* @private
|
|
276
|
+
*/
|
|
277
|
+
_basicScore(round) {
|
|
278
|
+
const issues = round.issues;
|
|
279
|
+
let score = 100;
|
|
280
|
+
|
|
281
|
+
for (const issue of issues) {
|
|
282
|
+
switch (issue.severity) {
|
|
283
|
+
case Severity.CRITICAL:
|
|
284
|
+
score -= 25;
|
|
285
|
+
break;
|
|
286
|
+
case Severity.MAJOR:
|
|
287
|
+
score -= 15;
|
|
288
|
+
break;
|
|
289
|
+
case Severity.MINOR:
|
|
290
|
+
score -= 5;
|
|
291
|
+
break;
|
|
292
|
+
case Severity.INFO:
|
|
293
|
+
score -= 1;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 奖励:有修复建议说明问题可解决
|
|
299
|
+
const fixCount = round.fixSuggestions?.length || 0;
|
|
300
|
+
if (fixCount > 0 && issues.length > 0) {
|
|
301
|
+
score += Math.min(fixCount * 2, 10); // 最多加10分
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
value: Math.max(0, Math.min(100, score)),
|
|
306
|
+
details: {
|
|
307
|
+
issueCount: issues.length,
|
|
308
|
+
fixSuggestionCount: fixCount,
|
|
309
|
+
severityBreakdown: this._countBySeverity(issues)
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* 按严重程度统计问题数量
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
318
|
+
_countBySeverity(issues) {
|
|
319
|
+
const counts = {};
|
|
320
|
+
for (const sev of Object.values(Severity)) {
|
|
321
|
+
counts[sev] = issues.filter(i => i.severity === sev).length;
|
|
322
|
+
}
|
|
323
|
+
return counts;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* 打印审查摘要
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
_printReviewSummary(reviewResult) {
|
|
331
|
+
const { issues, metrics } = reviewResult;
|
|
332
|
+
|
|
333
|
+
console.log(` 发现 ${chalk.red(issues.length.toString())} 个问题`);
|
|
334
|
+
|
|
335
|
+
if (this.verbose && issues.length > 0) {
|
|
336
|
+
for (const issue of issues.slice(0, 10)) {
|
|
337
|
+
const icon = this._severityIcon(issue.severity);
|
|
338
|
+
console.log(` ${icon} [${issue.severity.toUpperCase()}] ${issue.message}${issue.line ? ` (L${issue.line})` : ''}`);
|
|
339
|
+
}
|
|
340
|
+
if (issues.length > 10) {
|
|
341
|
+
console.log(` ... 还有 ${issues.length - 10} 个问题`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (metrics) {
|
|
346
|
+
console.log(chalk.gray(` 审查指标: 复杂度=${metrics.complexity?.toFixed(1) || '?'}, 行数=${metrics.lines || '?'}`));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 打印修复摘要
|
|
352
|
+
* @private
|
|
353
|
+
*/
|
|
354
|
+
_printFixSummary(fixResult) {
|
|
355
|
+
const { suggestions } = fixResult;
|
|
356
|
+
|
|
357
|
+
console.log(` 生成 ${chalk.green(suggestions.length.toString())} 条修复建议`);
|
|
358
|
+
|
|
359
|
+
if (this.verbose && suggestions.length > 0) {
|
|
360
|
+
for (const suggestion of suggestions.slice(0, 5)) {
|
|
361
|
+
console.log(` 💡 ${suggestion.type}: ${suggestion.description}`);
|
|
362
|
+
}
|
|
363
|
+
if (suggestions.length > 5) {
|
|
364
|
+
console.log(` ... 还有 ${suggestions.length - 5} 条建议`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 打印评分摘要
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
_printScoreSummary(round) {
|
|
374
|
+
const scoreColor = round.score >= 80 ? chalk.green :
|
|
375
|
+
round.score >= 60 ? chalk.yellow : chalk.red;
|
|
376
|
+
|
|
377
|
+
console.log(` 得分: ${scoreColor.bold(round.score.toFixed(1))}/100`);
|
|
378
|
+
|
|
379
|
+
if (round.improvement !== null) {
|
|
380
|
+
const impColor = round.improvement >= 0 ? chalk.green : chalk.red;
|
|
381
|
+
const impSign = round.improvement >= 0 ? '+' : '';
|
|
382
|
+
console.log(` 改进: ${impColor(`${impSign}${round.improvement.toFixed(2)}%)`)}`);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
console.log(` 耗时: ${round.duration}ms`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* 严重程度图标
|
|
390
|
+
* @private
|
|
391
|
+
*/
|
|
392
|
+
_severityIcon(severity) {
|
|
393
|
+
switch (severity) {
|
|
394
|
+
case Severity.CRITICAL: return chalk.red('🔴');
|
|
395
|
+
case Severity.MAJOR: return chalk.orange('🟠');
|
|
396
|
+
case Severity.MINOR: return chalk.yellow('🟡');
|
|
397
|
+
case Severity.INFO: return chalk.gray('⚪');
|
|
398
|
+
default: return chalk.gray('·');
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* 生成最终结果报告
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
406
|
+
_generateFinalResult() {
|
|
407
|
+
const lastRound = this.roundResults[this.roundResults.length - 1];
|
|
408
|
+
this.status = lastRound.status;
|
|
409
|
+
|
|
410
|
+
const totalDuration = this.roundResults.reduce((sum, r) => sum + r.duration, 0);
|
|
411
|
+
const totalIssuesFixed = this.roundResults.reduce((sum, r) => sum + r.issues.length, 0);
|
|
412
|
+
const totalSuggestions = this.roundResults.reduce((sum, r) => sum + r.fixSuggestions.length, 0);
|
|
413
|
+
|
|
414
|
+
// 计算总体改进
|
|
415
|
+
const firstScore = this.roundResults[0]?.score || 0;
|
|
416
|
+
const finalScore = lastRound?.score || 0;
|
|
417
|
+
const overallImprovement = firstScore > 0
|
|
418
|
+
? ((finalScore - firstScore) / firstScore) * 100
|
|
419
|
+
: 0;
|
|
420
|
+
|
|
421
|
+
const result = {
|
|
422
|
+
rounds: this.currentRound,
|
|
423
|
+
finalScore,
|
|
424
|
+
firstScore,
|
|
425
|
+
overallImprovement,
|
|
426
|
+
converged: this.status === IterationStatus.CONVERGED,
|
|
427
|
+
convergenceReason: lastRound?.convergenceReason,
|
|
428
|
+
status: this.status,
|
|
429
|
+
|
|
430
|
+
// 统计信息
|
|
431
|
+
totalIssuesFound: totalIssuesFixed,
|
|
432
|
+
totalFixSuggestions: totalSuggestions,
|
|
433
|
+
totalDuration,
|
|
434
|
+
|
|
435
|
+
// 详细轮次数据
|
|
436
|
+
roundDetails: this.roundResults.map(r => ({
|
|
437
|
+
round: r.round,
|
|
438
|
+
status: r.status,
|
|
439
|
+
score: r.score,
|
|
440
|
+
improvement: r.improvement,
|
|
441
|
+
issueCount: r.issues.length,
|
|
442
|
+
fixCount: r.fixSuggestions.length,
|
|
443
|
+
duration: r.duration
|
|
444
|
+
})),
|
|
445
|
+
|
|
446
|
+
// 最终修复建议汇总
|
|
447
|
+
allFixSuggestions: this.roundResults.flatMap(r => r.fixSuggestions),
|
|
448
|
+
|
|
449
|
+
// 进度报告
|
|
450
|
+
progressReport: this.getProgressReport()
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// 输出最终报告
|
|
454
|
+
this._printFinalReport(result);
|
|
455
|
+
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* 打印最终报告
|
|
461
|
+
* @private
|
|
462
|
+
*/
|
|
463
|
+
_printFinalReport(result) {
|
|
464
|
+
console.log(chalk.bold('\n━━━ Iteration Final Report ━━━'));
|
|
465
|
+
console.log(` 总轮数: ${result.rounds}/${this.maxRounds}`);
|
|
466
|
+
console.log(` 初始得分: ${result.firstScore?.toFixed(1) || '?'}`);
|
|
467
|
+
console.log(` 最终得分: ${chalk.bold(result.finalScore?.toFixed(1) || '?')}/100`);
|
|
468
|
+
console.log(` 总体改进: ${result.overallImprovement >= 0 ? '+' : ''}${result.overallImprovement.toFixed(2)}%`);
|
|
469
|
+
console.log(` 发现问题: ${result.totalIssuesFound}个`);
|
|
470
|
+
console.log(` 修复建议: ${result.totalFixSuggestions}条`);
|
|
471
|
+
console.log(` 总耗时: ${result.totalDuration}ms`);
|
|
472
|
+
console.log(` 状态: ${this._statusText(result.status)}`);
|
|
473
|
+
console.log(` 收敛原因: ${result.convergenceReason || '-'}`);
|
|
474
|
+
|
|
475
|
+
if (result.allFixSuggestions.length > 0) {
|
|
476
|
+
console.log(chalk.bold('\n 修复建议汇总:'));
|
|
477
|
+
for (const sug of result.allFixSuggestions.slice(0, 10)) {
|
|
478
|
+
console.log(` - [${sug.type}] ${sug.description}`);
|
|
479
|
+
}
|
|
480
|
+
if (result.allFixSuggestions.length > 10) {
|
|
481
|
+
console.log(` ... 还有 ${result.allFixSuggestions.length - 10} 条建议`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 状态文本
|
|
488
|
+
* @private
|
|
489
|
+
*/
|
|
490
|
+
_statusText(status) {
|
|
491
|
+
switch (status) {
|
|
492
|
+
case IterationStatus.CONVERGED: return chalk.green('已收敛 ✅');
|
|
493
|
+
case IterationStatus.MAX_ROUNDS_REACHED: return chalk.yellow('达到最大轮数 ⏹️');
|
|
494
|
+
default: return chalk.gray(status);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* 获取迭代进度报告
|
|
500
|
+
* @returns {Object} 进度报告
|
|
501
|
+
*/
|
|
502
|
+
getProgressReport() {
|
|
503
|
+
const completed = this.roundResults.filter(r =>
|
|
504
|
+
r.status === IterationStatus.CONVERGED ||
|
|
505
|
+
r.endTime !== null
|
|
506
|
+
).length;
|
|
507
|
+
|
|
508
|
+
return {
|
|
509
|
+
currentRound: this.currentRound,
|
|
510
|
+
maxRounds: this.maxRounds,
|
|
511
|
+
completedRounds: completed,
|
|
512
|
+
progressPercent: (completed / this.maxRounds) * 100,
|
|
513
|
+
status: this.status,
|
|
514
|
+
|
|
515
|
+
// 分数趋势
|
|
516
|
+
scoreTrend: this.roundResults.map(r => ({
|
|
517
|
+
round: r.round,
|
|
518
|
+
score: r.score,
|
|
519
|
+
timestamp: r.startTime
|
|
520
|
+
})),
|
|
521
|
+
|
|
522
|
+
// 问题趋势
|
|
523
|
+
issueTrend: this.roundResults.map(r => ({
|
|
524
|
+
round: r.round,
|
|
525
|
+
issueCount: r.issues.length,
|
|
526
|
+
bySeverity: this._countBySeverity(r.issues)
|
|
527
|
+
})),
|
|
528
|
+
|
|
529
|
+
// 时间消耗
|
|
530
|
+
timeConsumption: this.roundResults.map(r => ({
|
|
531
|
+
round: r.round,
|
|
532
|
+
duration: r.duration,
|
|
533
|
+
phaseBreakdown: {
|
|
534
|
+
reviewing: r.duration ? Math.floor(r.duration * 0.3) : 0,
|
|
535
|
+
fixing: r.duration ? Math.floor(r.duration * 0.4) : 0,
|
|
536
|
+
verifying: r.duration ? Math.floor(r.duration * 0.3) : 0
|
|
537
|
+
}
|
|
538
|
+
}))
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* 导出迭代历史为JSON(可用于持久化)
|
|
544
|
+
* @returns {string} JSON字符串
|
|
545
|
+
*/
|
|
546
|
+
exportHistory() {
|
|
547
|
+
return JSON.stringify({
|
|
548
|
+
metadata: {
|
|
549
|
+
exportedAt: new Date().toISOString(),
|
|
550
|
+
maxRounds: this.maxRounds,
|
|
551
|
+
convergenceThreshold: this.convergenceThreshold
|
|
552
|
+
},
|
|
553
|
+
rounds: this.roundResults.map(r => ({
|
|
554
|
+
...r,
|
|
555
|
+
codeVersion: r.codeVersion // 不导出完整代码
|
|
556
|
+
})),
|
|
557
|
+
progressReport: this.getProgressReport()
|
|
558
|
+
}, null, 2);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* 重置控制器状态
|
|
563
|
+
*/
|
|
564
|
+
reset() {
|
|
565
|
+
this.roundResults = [];
|
|
566
|
+
this.currentRound = 0;
|
|
567
|
+
this.status = IterationStatus.IDLE;
|
|
568
|
+
this.initialCode = null;
|
|
569
|
+
this.currentCode = null;
|
|
570
|
+
this.spec = null;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* 默认导出
|
|
576
|
+
*/
|
|
577
|
+
export default IterationController;
|
package/lib/list.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const SKILLS_ROOT = path.join(__dirname, '..', 'skills');
|
|
8
|
+
|
|
9
|
+
const CATEGORIES = {
|
|
10
|
+
core: { name: '核心技能', description: 'PDD工作流核心技能' },
|
|
11
|
+
entropy: { name: '熵减技能', description: '技术债务管理和代码质量维护' },
|
|
12
|
+
expert: { name: '专家技能', description: '领域专家级深度分析能力' },
|
|
13
|
+
openspec: { name: 'OpenSpec技能', description: '规格变更管理流程' },
|
|
14
|
+
pr: { name: 'PR技能', description: 'Pull Request全流程管理' }
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function listSkills(options = {}) {
|
|
18
|
+
const category = options.category;
|
|
19
|
+
const asJson = options.json;
|
|
20
|
+
|
|
21
|
+
if (category && !CATEGORIES[category]) {
|
|
22
|
+
console.log(chalk.red(`\n❌ 未知分类: ${category}`));
|
|
23
|
+
console.log(chalk.gray(` 可用分类: ${Object.keys(CATEGORIES).join(', ')}`));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const skills = await collectSkills(category);
|
|
28
|
+
|
|
29
|
+
if (asJson) {
|
|
30
|
+
console.log(JSON.stringify(skills, null, 2));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
displaySkills(skills, category);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function collectSkills(filterCategory) {
|
|
38
|
+
const result = [];
|
|
39
|
+
|
|
40
|
+
for (const [catKey, catInfo] of Object.entries(CATEGORIES)) {
|
|
41
|
+
if (filterCategory && catKey !== filterCategory) continue;
|
|
42
|
+
|
|
43
|
+
const catPath = path.join(SKILLS_ROOT, catKey);
|
|
44
|
+
if (!fs.existsSync(catPath)) continue;
|
|
45
|
+
|
|
46
|
+
const entries = fs.readdirSync(catPath).filter(f => {
|
|
47
|
+
const fullPath = path.join(catPath, f);
|
|
48
|
+
return fs.statSync(fullPath).isDirectory();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const skills = entries.map(name => {
|
|
52
|
+
const skillDir = path.join(catPath, name);
|
|
53
|
+
const metaPath = path.join(skillDir, '_meta.json');
|
|
54
|
+
const skillMdPath = path.join(skillDir, 'SKILL.md');
|
|
55
|
+
|
|
56
|
+
let meta = {};
|
|
57
|
+
if (fs.existsSync(metaPath)) {
|
|
58
|
+
try { meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8')); } catch {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let description = meta.description || '';
|
|
62
|
+
if (!description && fs.existsSync(skillMdPath)) {
|
|
63
|
+
const content = fs.readFileSync(skillMdPath, 'utf-8');
|
|
64
|
+
const match = content.match(/^description:\s*(.+)$/m);
|
|
65
|
+
if (match) description = match[1].trim();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
category: catKey,
|
|
71
|
+
categoryName: catInfo.name,
|
|
72
|
+
description,
|
|
73
|
+
version: meta.version || '1.0.0',
|
|
74
|
+
triggers: meta.triggers || [],
|
|
75
|
+
hasEvals: fs.existsSync(path.join(skillDir, 'evals'))
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (skills.length > 0) {
|
|
80
|
+
result.push({
|
|
81
|
+
category: catKey,
|
|
82
|
+
...catInfo,
|
|
83
|
+
skills
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function displaySkills(skills, filterCategory) {
|
|
92
|
+
console.log(chalk.blue.bold('\n📋 PDD-Skills 技能列表\n'));
|
|
93
|
+
|
|
94
|
+
if (skills.length === 0) {
|
|
95
|
+
console.log(chalk.gray(' 暂无可用技能'));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let totalSkills = 0;
|
|
100
|
+
|
|
101
|
+
for (const cat of skills) {
|
|
102
|
+
console.log(chalk.cyan.bold(` ${cat.name} (${cat.category})`));
|
|
103
|
+
console.log(chalk.gray(` ${'─'.repeat(50)}`));
|
|
104
|
+
|
|
105
|
+
for (const skill of cat.skills) {
|
|
106
|
+
totalSkills++;
|
|
107
|
+
const statusIcon = skill.hasEvals ? chalk.green('✓') : chalk.gray('·');
|
|
108
|
+
const desc = skill.description
|
|
109
|
+
? skill.description.substring(0, 60) + (skill.description.length > 60 ? '...' : '')
|
|
110
|
+
: chalk.gray('(无描述)');
|
|
111
|
+
|
|
112
|
+
console.log(` ${statusIcon} ${chalk.white.bold(skill.name)}`);
|
|
113
|
+
console.log(` ${chalk.gray(desc)}`);
|
|
114
|
+
|
|
115
|
+
if (skill.triggers.length > 0) {
|
|
116
|
+
console.log(` ${chalk.dim('触发词:')} ${chalk.yellow(skill.triggers.slice(0, 3).join(', '))}${skill.triggers.length > 3 ? '...' : ''}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log('');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(chalk.gray(`${'─'.repeat(50)}`));
|
|
124
|
+
console.log(chalk.green(` 共 ${totalSkills} 个技能, ${skills.length} 个分类`));
|
|
125
|
+
|
|
126
|
+
if (!filterCategory) {
|
|
127
|
+
console.log(chalk.gray('\n 使用 pdd list -c <分类> 按分类筛选'));
|
|
128
|
+
console.log(chalk.gray(' 使用 pdd list --json 输出JSON格式'));
|
|
129
|
+
}
|
|
130
|
+
}
|