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,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDD 配置管理模块
|
|
3
|
+
* 管理项目配置的读取、写入和验证
|
|
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
|
+
// 默认配置
|
|
14
|
+
const DEFAULT_CONFIG = {
|
|
15
|
+
project: {
|
|
16
|
+
name: '',
|
|
17
|
+
version: '1.0.0',
|
|
18
|
+
description: ''
|
|
19
|
+
},
|
|
20
|
+
development: {
|
|
21
|
+
specDir: 'dev-specs',
|
|
22
|
+
outputDir: './generated',
|
|
23
|
+
codeDir: './src',
|
|
24
|
+
testDir: './tests'
|
|
25
|
+
},
|
|
26
|
+
linter: {
|
|
27
|
+
types: ['java', 'js', 'python', 'sql', 'prd', 'skill'],
|
|
28
|
+
strictMode: false,
|
|
29
|
+
failOnError: true
|
|
30
|
+
},
|
|
31
|
+
api: {
|
|
32
|
+
port: 3000,
|
|
33
|
+
host: 'localhost',
|
|
34
|
+
cors: false,
|
|
35
|
+
rateLimit: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
maxRequests: 100,
|
|
38
|
+
windowMs: 60000
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
report: {
|
|
42
|
+
defaultFormat: 'md',
|
|
43
|
+
includeStats: true,
|
|
44
|
+
includeCharts: false,
|
|
45
|
+
outputDir: './reports'
|
|
46
|
+
},
|
|
47
|
+
skills: {
|
|
48
|
+
autoUpdate: false,
|
|
49
|
+
categories: ['core', 'analysis', 'development', 'quality']
|
|
50
|
+
},
|
|
51
|
+
vm: {
|
|
52
|
+
port: 3001,
|
|
53
|
+
refreshInterval: 30,
|
|
54
|
+
theme: 'light',
|
|
55
|
+
autoOpen: true,
|
|
56
|
+
maxSSEConnections: 100,
|
|
57
|
+
tuiRefreshInterval: 5
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 配置文件路径
|
|
62
|
+
const CONFIG_FILE_PATHS = [
|
|
63
|
+
path.join(process.cwd(), 'config', 'config.yaml'),
|
|
64
|
+
path.join(process.cwd(), '.pddrc.yaml'),
|
|
65
|
+
path.join(process.cwd(), '.pddrc.json')
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取配置文件路径
|
|
70
|
+
* @returns {string|null} 找到的配置文件路径
|
|
71
|
+
*/
|
|
72
|
+
function findConfigFile() {
|
|
73
|
+
for (const configPath of CONFIG_FILE_PATHS) {
|
|
74
|
+
if (fs.existsSync(configPath)) {
|
|
75
|
+
return configPath;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 加载配置文件
|
|
83
|
+
* @param {string} configPath - 配置文件路径
|
|
84
|
+
* @returns {Object} 配置对象
|
|
85
|
+
*/
|
|
86
|
+
async function loadConfig(configPath) {
|
|
87
|
+
try {
|
|
88
|
+
if (!configPath || !fs.existsSync(configPath)) {
|
|
89
|
+
return { ...DEFAULT_CONFIG };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const content = await fs.promises.readFile(configPath, 'utf-8');
|
|
93
|
+
|
|
94
|
+
// 根据文件扩展名选择解析方式
|
|
95
|
+
if (configPath.endsWith('.json')) {
|
|
96
|
+
const userConfig = JSON.parse(content);
|
|
97
|
+
return deepMerge(DEFAULT_CONFIG, userConfig);
|
|
98
|
+
} else if (configPath.endsWith('.yaml') || configPath.endsWith('.yml')) {
|
|
99
|
+
// 使用yaml模块解析(如果可用)
|
|
100
|
+
try {
|
|
101
|
+
const yaml = await import('yaml');
|
|
102
|
+
const userConfig = yaml.parse(content);
|
|
103
|
+
return deepMerge(DEFAULT_CONFIG, userConfig);
|
|
104
|
+
} catch {
|
|
105
|
+
console.warn('警告: YAML解析失败,使用默认配置');
|
|
106
|
+
return { ...DEFAULT_CONFIG };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { ...DEFAULT_CONFIG };
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(`加载配置文件失败: ${error.message}`);
|
|
113
|
+
return { ...DEFAULT_CONFIG };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 保存配置到文件
|
|
119
|
+
* @param {Object} config - 配置对象
|
|
120
|
+
* @param {string} configPath - 配置文件路径
|
|
121
|
+
*/
|
|
122
|
+
async function saveConfig(config, configPath) {
|
|
123
|
+
try {
|
|
124
|
+
const dir = path.dirname(configPath);
|
|
125
|
+
if (!fs.existsSync(dir)) {
|
|
126
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let content;
|
|
130
|
+
if (configPath.endsWith('.json')) {
|
|
131
|
+
content = JSON.stringify(config, null, 2);
|
|
132
|
+
} else {
|
|
133
|
+
// 默认使用YAML格式
|
|
134
|
+
try {
|
|
135
|
+
const yaml = await import('yaml');
|
|
136
|
+
content = yaml.stringify(config);
|
|
137
|
+
} catch {
|
|
138
|
+
content = JSON.stringify(config, null, 2);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await fs.promises.writeFile(configPath, content, 'utf-8');
|
|
143
|
+
console.log(`✅ 配置已保存到: ${configPath}`);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error(`保存配置失败: ${error.message}`);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 深度合并对象
|
|
152
|
+
* @param {Object} target - 目标对象
|
|
153
|
+
* @param {Object} source - 源对象
|
|
154
|
+
* @returns {Object} 合并后的对象
|
|
155
|
+
*/
|
|
156
|
+
function deepMerge(target, source) {
|
|
157
|
+
const result = { ...target };
|
|
158
|
+
|
|
159
|
+
for (const key of Object.keys(source)) {
|
|
160
|
+
if (
|
|
161
|
+
source[key] &&
|
|
162
|
+
typeof source[key] === 'object' &&
|
|
163
|
+
!Array.isArray(source[key]) &&
|
|
164
|
+
target[key] &&
|
|
165
|
+
typeof target[key] === 'object' &&
|
|
166
|
+
!Array.isArray(target[key])
|
|
167
|
+
) {
|
|
168
|
+
result[key] = deepMerge(target[key], source[key]);
|
|
169
|
+
} else {
|
|
170
|
+
result[key] = source[key];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 设置配置项(支持点号路径)
|
|
179
|
+
* @param {Object} config - 配置对象
|
|
180
|
+
* @param {string} keyPath - 配置键路径(如 "api.port")
|
|
181
|
+
* @param {*} value - 配置值
|
|
182
|
+
*/
|
|
183
|
+
function setConfigValue(config, keyPath, value) {
|
|
184
|
+
const keys = keyPath.split('.');
|
|
185
|
+
let current = config;
|
|
186
|
+
|
|
187
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
188
|
+
if (!(keys[i] in current)) {
|
|
189
|
+
current[keys[i]] = {};
|
|
190
|
+
}
|
|
191
|
+
current = current[keys[i]];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 尝试转换值类型
|
|
195
|
+
const lastKey = keys[keys.length - 1];
|
|
196
|
+
current[lastKey] = parseValue(value);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 解析值类型
|
|
201
|
+
* @param {string} value - 字符串值
|
|
202
|
+
* @returns {*} 解析后的值
|
|
203
|
+
*/
|
|
204
|
+
function parseValue(value) {
|
|
205
|
+
if (value === 'true') return true;
|
|
206
|
+
if (value === 'false') return false;
|
|
207
|
+
if (value === 'null') return null;
|
|
208
|
+
if (!isNaN(Number(value)) && value !== '') return Number(value);
|
|
209
|
+
|
|
210
|
+
// 尝试解析JSON数组或对象
|
|
211
|
+
if ((value.startsWith('[') && value.endsWith(']')) ||
|
|
212
|
+
(value.startsWith('{') && value.endsWith('}'))) {
|
|
213
|
+
try {
|
|
214
|
+
return JSON.parse(value);
|
|
215
|
+
} catch {
|
|
216
|
+
// 不是有效的JSON,返回字符串
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 获取配置项(支持点号路径)
|
|
225
|
+
* @param {Object} config - 配置对象
|
|
226
|
+
* @param {string} keyPath - 配置键路径
|
|
227
|
+
* @returns {*} 配置值
|
|
228
|
+
*/
|
|
229
|
+
function getConfigValue(config, keyPath) {
|
|
230
|
+
const keys = keyPath.split('.');
|
|
231
|
+
let current = config;
|
|
232
|
+
|
|
233
|
+
for (const key of keys) {
|
|
234
|
+
if (current && typeof current === 'object' && key in current) {
|
|
235
|
+
current = current[key];
|
|
236
|
+
} else {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return current;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 格式化显示配置
|
|
246
|
+
* @param {Object} config - 配置对象
|
|
247
|
+
* @param {number} indent - 缩进级别
|
|
248
|
+
* @returns {string} 格式化后的配置字符串
|
|
249
|
+
*/
|
|
250
|
+
function formatConfig(config, indent = 0) {
|
|
251
|
+
const prefix = ' '.repeat(indent);
|
|
252
|
+
let output = '';
|
|
253
|
+
|
|
254
|
+
for (const [key, value] of Object.entries(config)) {
|
|
255
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
256
|
+
output += `${prefix}${chalk.cyan(key)}:\n`;
|
|
257
|
+
output += formatConfig(value, indent + 1);
|
|
258
|
+
} else {
|
|
259
|
+
const formattedValue = Array.isArray(value) ? value.join(', ') : String(value);
|
|
260
|
+
output += `${prefix}${chalk.cyan(key)}: ${chalk.green(formattedValue)}\n`;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return output;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 引入chalk用于彩色输出
|
|
268
|
+
let chalk;
|
|
269
|
+
try {
|
|
270
|
+
chalkModule = await import('chalk');
|
|
271
|
+
chalk = chalkModule.default;
|
|
272
|
+
} catch {
|
|
273
|
+
// 如果chalk不可用,使用简单的格式化
|
|
274
|
+
chalk = {
|
|
275
|
+
cyan: (s) => s,
|
|
276
|
+
green: (s) => s,
|
|
277
|
+
yellow: (s) => s,
|
|
278
|
+
red: (s) => s,
|
|
279
|
+
blue: (s) => s
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* CLI配置管理入口函数
|
|
285
|
+
* @param {Object} options - 命令行选项
|
|
286
|
+
*/
|
|
287
|
+
export async function configManager(options) {
|
|
288
|
+
const configPath = findConfigFile() || path.join(process.cwd(), 'config', 'config.yaml');
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
// 列出配置
|
|
292
|
+
if (options.list) {
|
|
293
|
+
console.log(chalk.blue('\n📋 当前PDD配置:\n'));
|
|
294
|
+
const config = await loadConfig(configPath);
|
|
295
|
+
console.log(formatConfig(config));
|
|
296
|
+
console.log(chalk.yellow(`\n配置文件位置: ${configPath}\n`));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 获取指定配置项
|
|
301
|
+
if (options.get) {
|
|
302
|
+
const config = await loadConfig(configPath);
|
|
303
|
+
const value = getConfigValue(config, options.get);
|
|
304
|
+
|
|
305
|
+
if (value !== undefined) {
|
|
306
|
+
if (typeof value === 'object') {
|
|
307
|
+
console.log(JSON.stringify(value, null, 2));
|
|
308
|
+
} else {
|
|
309
|
+
console.log(String(value));
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
console.log(chalk.red(`\n❌ 配置项 "${options.get}" 不存在\n`));
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 设置配置项
|
|
319
|
+
if (options.set) {
|
|
320
|
+
const [keyPath, ...valueParts] = options.set.split('=');
|
|
321
|
+
const value = valueParts.join('='); // 支持值中包含等号
|
|
322
|
+
|
|
323
|
+
if (!keyPath || value === undefined) {
|
|
324
|
+
console.log(chalk.red('\n❌ 格式错误: 请使用 -s key=value 格式\n'));
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const config = await loadConfig(configPath);
|
|
329
|
+
setConfigValue(config, keyPath, value);
|
|
330
|
+
await saveConfig(config, configPath);
|
|
331
|
+
console.log(chalk.green(`\n✅ 已设置 ${keyPath} = ${value}\n`));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 重置配置
|
|
336
|
+
if (options.reset) {
|
|
337
|
+
await saveConfig({ ...DEFAULT_CONFIG }, configPath);
|
|
338
|
+
console.log(chalk.green('\n✅ 配置已重置为默认值\n'));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 无参数时显示帮助信息
|
|
343
|
+
console.log(chalk.blue('\nPDD 配置管理\n'));
|
|
344
|
+
console.log('用法:');
|
|
345
|
+
console.log(' pdd config --list 列出所有配置');
|
|
346
|
+
console.log(' pdd config --get <key> 获取指定配置项');
|
|
347
|
+
console.log(' pdd config --set <key=value> 设置配置项');
|
|
348
|
+
console.log(' pdd config --reset 重置为默认配置\n');
|
|
349
|
+
console.log('示例:');
|
|
350
|
+
console.log(' pdd config --set api.port=8080');
|
|
351
|
+
console.log(' pdd config --get linter.types');
|
|
352
|
+
console.log(' pdd config --list\n');
|
|
353
|
+
|
|
354
|
+
} catch (error) {
|
|
355
|
+
console.error(chalk.red(`\n❌ 配置操作失败: ${error.message}\n`));
|
|
356
|
+
process.exit(1);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* 导出工具函数供其他模块使用
|
|
362
|
+
*/
|
|
363
|
+
export {
|
|
364
|
+
DEFAULT_CONFIG,
|
|
365
|
+
loadConfig,
|
|
366
|
+
saveConfig,
|
|
367
|
+
findConfigFile,
|
|
368
|
+
setConfigValue,
|
|
369
|
+
getConfigValue,
|
|
370
|
+
deepMerge
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export default configManager;
|