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,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDD Visual Manager - Sparkline 迷你折线图组件 (VM-C012)
|
|
3
|
+
*
|
|
4
|
+
* 在终端中渲染轻量级的折线图/趋势图:
|
|
5
|
+
* - Unicode 块字符绘制
|
|
6
|
+
* - 支持单数据集和多数据集叠加
|
|
7
|
+
* - 自动缩放和归一化
|
|
8
|
+
* - 最小值/最大值/当前值标注
|
|
9
|
+
* - 多种填充样式
|
|
10
|
+
*
|
|
11
|
+
* 适合在有限空间内展示趋势数据。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { ANSI } from '../renderer.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sparkline 绘图字符集
|
|
18
|
+
*/
|
|
19
|
+
const SPARK_CHARS = {
|
|
20
|
+
// 块字符(从空到满,8级)
|
|
21
|
+
blocks: [' ', '▁', '�', '▃', '▄', '▅', '▆', '▇', '█'],
|
|
22
|
+
|
|
23
|
+
// 线条字符
|
|
24
|
+
lineHorizontal: '━',
|
|
25
|
+
lineVertical: '┃',
|
|
26
|
+
|
|
27
|
+
// 点字符
|
|
28
|
+
dot: '•',
|
|
29
|
+
solidDot: '●',
|
|
30
|
+
hollowDot: '○',
|
|
31
|
+
|
|
32
|
+
// 填充字符
|
|
33
|
+
fillFull: '█',
|
|
34
|
+
fillPartial: ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'],
|
|
35
|
+
fillEmpty: '░'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sparkline - 迷你折线图组件
|
|
40
|
+
*
|
|
41
|
+
* 用于在终端中展示趋势数据的轻量图表。
|
|
42
|
+
*/
|
|
43
|
+
class Sparkline {
|
|
44
|
+
/**
|
|
45
|
+
* 创建 Sparkline 实例
|
|
46
|
+
* @param {number[]} values - 数据值数组
|
|
47
|
+
* @param {number} width - 图表宽度(字符数)
|
|
48
|
+
* @param {number} height - 图表高度(行数)
|
|
49
|
+
* @param {Object} options - 配置选项
|
|
50
|
+
*/
|
|
51
|
+
constructor(values = [], width = 20, height = 4, options = {}) {
|
|
52
|
+
/** @type {number[]} 数据值 */
|
|
53
|
+
this.values = values.slice();
|
|
54
|
+
|
|
55
|
+
/** @type {number} 图表宽度 */
|
|
56
|
+
this.width = Math.max(3, width);
|
|
57
|
+
|
|
58
|
+
/** @type {number} 图表高度 */
|
|
59
|
+
this.height = Math.max(1, height);
|
|
60
|
+
|
|
61
|
+
/** @type {Object} 选项 */
|
|
62
|
+
this.options = {
|
|
63
|
+
min: null, // 手动指定最小值
|
|
64
|
+
max: null, // 手动指定最大值
|
|
65
|
+
label: '', // 标签文字
|
|
66
|
+
color: ANSI.CYAN, // 主色
|
|
67
|
+
secondaryColor: ANSI.MAGENTA, // 第二数据集颜色
|
|
68
|
+
fillChar: null, // 填充字符(null=使用块字符)
|
|
69
|
+
showDots: true, // 显示数据点
|
|
70
|
+
showMinMax: true, // 显示最值标注
|
|
71
|
+
fillArea: false, // 填充区域
|
|
72
|
+
...options
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// 计算数据范围
|
|
76
|
+
this._calcRange();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 计算数据范围
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
_calcRange() {
|
|
84
|
+
if (this.values.length === 0) {
|
|
85
|
+
this.dataMin = 0;
|
|
86
|
+
this.dataMax = 100;
|
|
87
|
+
this.dataRange = 100;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.dataMin = this.options.min !== null
|
|
92
|
+
? this.options.min
|
|
93
|
+
: Math.min(...this.values);
|
|
94
|
+
|
|
95
|
+
this.dataMax = this.options.max !== null
|
|
96
|
+
? this.options.max
|
|
97
|
+
: Math.max(...this.values);
|
|
98
|
+
|
|
99
|
+
// 防止除零
|
|
100
|
+
this.dataRange = this.dataMax - this.dataMin || 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 将数据值映射到高度级别
|
|
105
|
+
* @param {number} value - 数据值
|
|
106
|
+
* @returns {number} 高度级别 (0 到 height)
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
_mapToHeight(value) {
|
|
110
|
+
const normalized = (value - this.dataMin) / this.dataRange;
|
|
111
|
+
return Math.round(normalized * (this.height - 1));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 将数据值映射到块字符索引
|
|
116
|
+
* @param {number} value - 数据值
|
|
117
|
+
* @returns {number} 块字符索引 (0-8)
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
_mapToBlock(value) {
|
|
121
|
+
const normalized = (value - this.dataMin) / this.dataRange;
|
|
122
|
+
return Math.min(8, Math.max(0, Math.round(normalized * 8)));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 渲染 sparkline
|
|
127
|
+
* @returns {string} 格式化的 sparkline 字符串
|
|
128
|
+
*/
|
|
129
|
+
render() {
|
|
130
|
+
if (this.values.length === 0) {
|
|
131
|
+
return this.options.fillEmpty || SPARK_CHARS.fillEmpty.repeat(this.width);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
switch (this.height) {
|
|
135
|
+
case 1:
|
|
136
|
+
return this._renderInline();
|
|
137
|
+
default:
|
|
138
|
+
return this._renderMultiLine();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 渲染单行内联 sparkline
|
|
144
|
+
* 使用 ▁▂▃▄▅▆▇█ 字符在一行内显示趋势
|
|
145
|
+
* @returns {string}
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
_renderInline() {
|
|
149
|
+
const chars = this.options.fillChar || SPARK_CHARS.blocks;
|
|
150
|
+
const color = this.options.color;
|
|
151
|
+
|
|
152
|
+
let result = '';
|
|
153
|
+
for (const v of this.values) {
|
|
154
|
+
const idx = this._mapToBlock(v);
|
|
155
|
+
result += chars[idx];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 应用颜色
|
|
159
|
+
result = `${color}${result}${ANSI.RESET}`;
|
|
160
|
+
|
|
161
|
+
// 添加标签
|
|
162
|
+
if (this.options.label) {
|
|
163
|
+
result = `${this.options.label} ${result}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 添加最值标注
|
|
167
|
+
if (this.options.showMinMax && this.values.length > 0) {
|
|
168
|
+
const lastVal = this.values[this.values.length - 1];
|
|
169
|
+
result += ` ${lastVal}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 渲染多行 sparkline(真正的折线图效果)
|
|
177
|
+
* @returns {string}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
_renderMultiLine() {
|
|
181
|
+
const h = this.height;
|
|
182
|
+
const w = this.width;
|
|
183
|
+
const color = this.options.color;
|
|
184
|
+
|
|
185
|
+
// 创建画布(从上到下)
|
|
186
|
+
const canvas = [];
|
|
187
|
+
for (let row = 0; row < h; row++) {
|
|
188
|
+
canvas.push(new Array(w).fill(' '));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 绘制数据点和连线
|
|
192
|
+
const points = this.values.slice(0, w).map(v => this._mapToHeight(v));
|
|
193
|
+
|
|
194
|
+
for (let x = 0; x < points.length; x++) {
|
|
195
|
+
const y = points[x];
|
|
196
|
+
const canvasY = h - 1 - y; // 翻转 Y 轴
|
|
197
|
+
|
|
198
|
+
if (canvasY >= 0 && canvasY < h) {
|
|
199
|
+
// 绘制点
|
|
200
|
+
canvas[canvasY][x] = this.options.showDots ? SPARK_CHARS.solidDot : '█';
|
|
201
|
+
|
|
202
|
+
// 向下填充(如果启用区域填充)
|
|
203
|
+
if (this.options.fillArea) {
|
|
204
|
+
for (let fy = canvasY + 1; fy < h; fy++) {
|
|
205
|
+
canvas[fy][x] = this.options.fillChar || SPARK_CHARS.fillEmpty;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 绘制到下一个点的连线
|
|
210
|
+
if (x < points.length - 1) {
|
|
211
|
+
const nextY = points[x + 1];
|
|
212
|
+
const nextCanvasY = h - 1 - nextY;
|
|
213
|
+
|
|
214
|
+
// 垂直线连接
|
|
215
|
+
const minY = Math.min(canvasY, nextCanvasY);
|
|
216
|
+
const maxY = Math.max(canvasY, nextCanvasY);
|
|
217
|
+
for (let ly = minY; ly <= maxY; ly++) {
|
|
218
|
+
if (ly >= 0 && ly < h) {
|
|
219
|
+
if (canvas[ly][x + 1] === ' ') {
|
|
220
|
+
canvas[ly][x + 1] = SPARK_CHARS.lineVertical;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 组装输出
|
|
229
|
+
let output = '';
|
|
230
|
+
|
|
231
|
+
// Y轴最大值标签
|
|
232
|
+
if (this.options.showMinMax) {
|
|
233
|
+
output += `${String(this.dataMax).padStart(6)} ┃`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
for (let row = 0; row < h; row++) {
|
|
237
|
+
const line = canvas[row].join('');
|
|
238
|
+
output += `\n${color}${line}${ANSI.RESET}`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// X轴最小值标签
|
|
242
|
+
if (this.options.showMinMax) {
|
|
243
|
+
output += `\n${String(this.dataMin).padStart(6)} ┃`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 标签
|
|
247
|
+
if (this.options.label) {
|
|
248
|
+
output += `\n ${this.options.label}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return output.startsWith('\n') ? output.substring(1) : output;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 渲染多数据集叠加的 sparkline
|
|
256
|
+
* @param {{values: number[], color?: string, label?: string}[] datasets - 数据集数组
|
|
257
|
+
* @returns {string}
|
|
258
|
+
*/
|
|
259
|
+
renderMulti(datasets = []) {
|
|
260
|
+
if (!datasets || datasets.length === 0) {
|
|
261
|
+
return this.render();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 简化处理:将多个数据集在同一行用不同颜色显示
|
|
265
|
+
let result = '';
|
|
266
|
+
for (const ds of datasets) {
|
|
267
|
+
const dsColor = ds.color || this.options.secondaryColor;
|
|
268
|
+
const subSpark = new Sparkline(
|
|
269
|
+
ds.values || [],
|
|
270
|
+
this.width,
|
|
271
|
+
1,
|
|
272
|
+
{ ...this.options, color: dsColor, showMinMax: false }
|
|
273
|
+
);
|
|
274
|
+
result += subSpark.render() + ' ';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return result.trimEnd();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 更新数据并重新渲染
|
|
282
|
+
* @param {number[]} newValues - 新数据
|
|
283
|
+
* @returns {string}
|
|
284
|
+
*/
|
|
285
|
+
update(newValues) {
|
|
286
|
+
this.values = newValues.slice();
|
|
287
|
+
this._calcRange();
|
|
288
|
+
return this.render();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 创建简单的趋势箭头指示器
|
|
293
|
+
* @param {number} currentValue - 当前值
|
|
294
|
+
* @param {number} previousValue - 前一个值
|
|
295
|
+
* @returns {string} 带颜色的趋势指示
|
|
296
|
+
*/
|
|
297
|
+
static trend(currentValue, previousValue) {
|
|
298
|
+
if (previousValue === 0 || previousValue === undefined || previousValue === null) {
|
|
299
|
+
return `${ANSI.DIM}—${ANSI.RESET}`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const diff = currentValue - previousValue;
|
|
303
|
+
const pctChange = (diff / Math.abs(previousValue)) * 100;
|
|
304
|
+
|
|
305
|
+
if (diff > 0) {
|
|
306
|
+
return `${ANSI.GREEN}↑${Math.abs(pctChange).toFixed(1)}%${ANSI.RESET}`;
|
|
307
|
+
} else if (diff < 0) {
|
|
308
|
+
return `${ANSI.RED}↓${Math.abs(pctChange).toFixed(1)}%${ANSI.RESET}`;
|
|
309
|
+
}
|
|
310
|
+
return `${ANSI.DIM}→0%${ANSI.RESET}`;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* 快速创建 sparkline 的静态方法
|
|
315
|
+
* @param {number[]} values - 数据
|
|
316
|
+
* @param {number} width - 宽度
|
|
317
|
+
* @param {Object} opts - 选项
|
|
318
|
+
* @returns {string}
|
|
319
|
+
*/
|
|
320
|
+
static quick(values, width = 10, opts = {}) {
|
|
321
|
+
const sp = new Sparkline(values, width, 1, opts);
|
|
322
|
+
return sp.render();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export default Sparkline;
|
|
327
|
+
export { SPARK_CHARS };
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDD Visual Manager - 状态指示灯组件 (VM-C013)
|
|
3
|
+
*
|
|
4
|
+
* 提供可视化的状态指示:
|
|
5
|
+
* - 运行状态 (up/down/warn/unknown)
|
|
6
|
+
* - 带颜色编码的状态灯
|
|
7
|
+
* - 可选的闪烁动画效果
|
|
8
|
+
* - 紧凑型和详细型两种显示模式
|
|
9
|
+
*
|
|
10
|
+
* 使用 Unicode 圆形字符实现视觉效果。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { ANSI } from '../renderer.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 状态类型枚举
|
|
17
|
+
*/
|
|
18
|
+
export const StatusType = Object.freeze({
|
|
19
|
+
UP: 'up',
|
|
20
|
+
DOWN: 'down',
|
|
21
|
+
WARN: 'warn',
|
|
22
|
+
UNKNOWN: 'unknown',
|
|
23
|
+
PENDING: 'pending',
|
|
24
|
+
ERROR: 'error'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 状态对应的视觉配置
|
|
29
|
+
*/
|
|
30
|
+
const STATUS_CONFIG = {
|
|
31
|
+
up: {
|
|
32
|
+
char: '●',
|
|
33
|
+
color: ANSI.BRIGHT_GREEN,
|
|
34
|
+
altColor: ANSI.GREEN,
|
|
35
|
+
label: '运行中',
|
|
36
|
+
shortLabel: 'UP'
|
|
37
|
+
},
|
|
38
|
+
down: {
|
|
39
|
+
char: '●',
|
|
40
|
+
color: ANSI.BRIGHT_RED,
|
|
41
|
+
altColor: ANSI.RED,
|
|
42
|
+
label: '停止',
|
|
43
|
+
shortLabel: 'DOWN'
|
|
44
|
+
},
|
|
45
|
+
warn: {
|
|
46
|
+
char: '●',
|
|
47
|
+
color: ANSI.BRIGHT_YELLOW,
|
|
48
|
+
altColor: ANSI.YELLOW,
|
|
49
|
+
label: '警告',
|
|
50
|
+
shortLabel: 'WARN'
|
|
51
|
+
},
|
|
52
|
+
unknown: {
|
|
53
|
+
char: '○',
|
|
54
|
+
color: ANSI.DIM,
|
|
55
|
+
altColor: ANSI.DIM,
|
|
56
|
+
label: '未知',
|
|
57
|
+
shortLabel: '?'
|
|
58
|
+
},
|
|
59
|
+
pending: {
|
|
60
|
+
char: '◌',
|
|
61
|
+
color: ANSI.YELLOW,
|
|
62
|
+
altColor: ANSI.DIM,
|
|
63
|
+
label: '等待中',
|
|
64
|
+
shortLabel: '...'
|
|
65
|
+
},
|
|
66
|
+
error: {
|
|
67
|
+
char: '✖',
|
|
68
|
+
color: ANSI.BRIGHT_RED,
|
|
69
|
+
altColor: ANSI.RED,
|
|
70
|
+
label: '错误',
|
|
71
|
+
shortLabel: 'ERR'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* StatusLight - 状态指示灯组件
|
|
77
|
+
*
|
|
78
|
+
* 用于显示系统服务、任务等状态的直观指示器。
|
|
79
|
+
*/
|
|
80
|
+
class StatusLight {
|
|
81
|
+
/**
|
|
82
|
+
* 创建状态指示灯
|
|
83
|
+
* @param {string} status - 状态类型 (StatusType)
|
|
84
|
+
* @param {Object} options - 配置选项
|
|
85
|
+
*/
|
|
86
|
+
constructor(status = 'unknown', options = {}) {
|
|
87
|
+
/** @type {string} 当前状态 */
|
|
88
|
+
this.status = status;
|
|
89
|
+
|
|
90
|
+
/** @type {Object} 选项 */
|
|
91
|
+
this.options = {
|
|
92
|
+
showLabel: false, // 显示状态文字
|
|
93
|
+
detailed: false, // 详细模式(显示完整标签)
|
|
94
|
+
blink: false, // 闪烁效果
|
|
95
|
+
bold: true, // 加粗显示
|
|
96
|
+
suffix: '', // 后缀文字(如延迟时间)
|
|
97
|
+
prefix: '', // 前缀文字
|
|
98
|
+
...options
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// 闪烁动画状态
|
|
102
|
+
this._blinkState = true;
|
|
103
|
+
this._blinkTimer = null;
|
|
104
|
+
|
|
105
|
+
if (this.options.blink) {
|
|
106
|
+
this._startBlinking();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 获取当前状态的配置
|
|
112
|
+
* @returns {Object}
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
_getConfig() {
|
|
116
|
+
return STATUS_CONFIG[this.status] || STATUS_CONFIG.unknown;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 启动闪烁动画
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
_startBlinking() {
|
|
124
|
+
this._blinkTimer = setInterval(() => {
|
|
125
|
+
this._blinkState = !this._blinkState;
|
|
126
|
+
}, 500);
|
|
127
|
+
|
|
128
|
+
if (this._blinkTimer.unref) {
|
|
129
|
+
this._blinkTimer.unref();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 停止闪烁动画
|
|
135
|
+
*/
|
|
136
|
+
stopBlinking() {
|
|
137
|
+
if (this._blinkTimer) {
|
|
138
|
+
clearInterval(this._blinkTimer);
|
|
139
|
+
this._blinkTimer = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 更新状态
|
|
145
|
+
* @param {string} newStatus - 新状态
|
|
146
|
+
* @returns {StatusLight} this
|
|
147
|
+
*/
|
|
148
|
+
setStatus(newStatus) {
|
|
149
|
+
this.status = newStatus;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 渲染状态指示灯
|
|
155
|
+
* @returns {string} 格式化的状态指示字符串
|
|
156
|
+
*/
|
|
157
|
+
render() {
|
|
158
|
+
const config = this._getConfig();
|
|
159
|
+
const opts = this.options;
|
|
160
|
+
|
|
161
|
+
let output = '';
|
|
162
|
+
const color = this.options.blink && !this._blinkState
|
|
163
|
+
? config.altColor
|
|
164
|
+
: config.color;
|
|
165
|
+
|
|
166
|
+
// 前缀
|
|
167
|
+
if (opts.prefix) {
|
|
168
|
+
output += opts.prefix + ' ';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 状态灯字符
|
|
172
|
+
const style = opts.bold ? ANSI.BOLD : '';
|
|
173
|
+
output += `${style}${color}${config.char}${ANSI.RESET}`;
|
|
174
|
+
|
|
175
|
+
// 后缀(如响应时间)
|
|
176
|
+
if (opts.suffix) {
|
|
177
|
+
output += ` ${opts.suffix}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 标签
|
|
181
|
+
if (opts.showLabel || opts.detailed) {
|
|
182
|
+
const label = opts.detailed ? config.label : config.shortLabel;
|
|
183
|
+
output += ` ${color}${label}${ANSI.RESET}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return output;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 仅渲染图标(无任何额外信息)
|
|
191
|
+
* @returns {string}
|
|
192
|
+
*/
|
|
193
|
+
renderIcon() {
|
|
194
|
+
const config = this._getConfig();
|
|
195
|
+
const color = this.options.blink && !this._blinkState
|
|
196
|
+
? config.altColor
|
|
197
|
+
: config.color;
|
|
198
|
+
const style = this.options.bold ? ANSI.BOLD : '';
|
|
199
|
+
return `${style}${color}${config.char}${ANSI.RESET}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 渲染带背景色的状态灯(更醒目)
|
|
204
|
+
* @returns {string}
|
|
205
|
+
*/
|
|
206
|
+
renderProminent() {
|
|
207
|
+
const config = this._getConfig();
|
|
208
|
+
const bgMap = {
|
|
209
|
+
up: ANSI.BG_GREEN,
|
|
210
|
+
down: ANSI.BG_RED,
|
|
211
|
+
warn: ANSI.BG_YELLOW,
|
|
212
|
+
unknown: '',
|
|
213
|
+
pending: '',
|
|
214
|
+
error: ANSI.BG_RED
|
|
215
|
+
};
|
|
216
|
+
const bg = bgMap[this.status] || '';
|
|
217
|
+
return `${bg}${config.char} ${config.shortLabel}${ANSI.RESET}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 清理资源
|
|
222
|
+
*/
|
|
223
|
+
destroy() {
|
|
224
|
+
this.stopBlinking();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ============================================================
|
|
228
|
+
// 静态工厂方法
|
|
229
|
+
// ============================================================
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 创建"运行中"状态灯
|
|
233
|
+
* @param {Object} opts - 选项
|
|
234
|
+
* @returns {StatusLight}
|
|
235
|
+
*/
|
|
236
|
+
static up(opts = {}) {
|
|
237
|
+
return new StatusLight('up', opts);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 创建"停止"状态灯
|
|
242
|
+
* @param {Object} opts - 选项
|
|
243
|
+
* @returns {StatusLight}
|
|
244
|
+
*/
|
|
245
|
+
static down(opts = {}) {
|
|
246
|
+
return new StatusLight('down', opts);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 创建"警告"状态灯
|
|
251
|
+
* @param {Object} opts - 选项
|
|
252
|
+
* @returns {StatusLight}
|
|
253
|
+
*/
|
|
254
|
+
static warn(opts = {}) {
|
|
255
|
+
return new StatusLight('warn', opts);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 创建"未知"状态灯
|
|
260
|
+
* @param {Object} opts - 选项
|
|
261
|
+
* @returns {StatusLight}
|
|
262
|
+
*/
|
|
263
|
+
static unknown(opts = {}) {
|
|
264
|
+
return new StatusLight('unknown', opts);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 从布尔值创建状态灯
|
|
269
|
+
* @param {boolean} isHealthy - 是否健康
|
|
270
|
+
* @param {Object} opts - 选项
|
|
271
|
+
* @returns {StatusLight}
|
|
272
|
+
*/
|
|
273
|
+
static fromBoolean(isHealthy, opts = {}) {
|
|
274
|
+
return new StatusLight(isHealthy ? 'up' : 'down', opts);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 批量渲染多个状态灯(水平排列)
|
|
279
|
+
* @param {Array<{status: string, label?: string, suffix?: string}>} items - 状态项数组
|
|
280
|
+
* @param {string} separator - 分隔符
|
|
281
|
+
* @returns {string}
|
|
282
|
+
*/
|
|
283
|
+
static row(items, separator = ' ') {
|
|
284
|
+
return items.map(item => {
|
|
285
|
+
const light = new StatusLight(item.status, {
|
|
286
|
+
showLabel: !!item.label,
|
|
287
|
+
suffix: item.suffix || ''
|
|
288
|
+
});
|
|
289
|
+
return light.render();
|
|
290
|
+
}).join(separator);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export default StatusLight;
|