@wwkit/harness 1.0.46 → 1.0.48

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.
Files changed (119) hide show
  1. package/package.json +3 -4
  2. package/skills/pea/SKILL.md +14 -4
  3. package/skills/pea/references/tpl-prd/epic.md +7 -2
  4. package/skills/peago/SKILL.md +10 -2
  5. package/skills/peago/references/cleancode/languages/py-ut.md +88 -0
  6. package/skills/peago/references/cleancode/languages/py.md +222 -0
  7. package/skills/{blame-cleancode/references → peago/references/cleancode}/report_template.md +45 -12
  8. package/skills/peago/references/cleancode/rules-ut.md +133 -0
  9. package/skills/peago/references/cleancode/rules.md +477 -0
  10. package/skills/peago/references/cleancode/spec.md +204 -0
  11. package/skills/peago/references/lint/spec.md +160 -0
  12. package/skills/peago/references/test/languages/js.md +74 -0
  13. package/skills/peago/references/test/languages/py.md +68 -0
  14. package/skills/peago/references/test/spec.md +201 -0
  15. package/skills/peago/references/translate/scripts/check-paragraphs.js +71 -0
  16. package/skills/peago/references/translate/scripts/check-structure.js +118 -0
  17. package/skills/peago/references/translate/scripts/chunk-bilingual.js +123 -0
  18. package/skills/peago/references/translate/scripts/chunk-text.js +150 -0
  19. package/skills/peago/references/translate/scripts/clean-text.js +121 -0
  20. package/skills/peago/references/translate/scripts/count-terms.js +54 -0
  21. package/skills/peago/references/translate/scripts/extract-vision.js +267 -0
  22. package/skills/peago/references/translate/scripts/md-to-docx.js +381 -0
  23. package/skills/peago/references/translate/scripts/merge-format.js +110 -0
  24. package/skills/peago/references/translate/scripts/merge-pages.js +202 -0
  25. package/skills/peago/references/translate/scripts/merge-result.js +113 -0
  26. package/skills/peago/references/translate/scripts/verify-chunk.js +200 -0
  27. package/skills/peago/references/translate/spec.md +14 -6
  28. package/skills/better-class/SKILL.md +0 -48
  29. package/skills/better-class/references/planning_spec.md +0 -91
  30. package/skills/better-class/references/report-template.md +0 -65
  31. package/skills/better-class/references/sprint_for_eo.md +0 -83
  32. package/skills/better-class/references/sprint_for_report.md +0 -22
  33. package/skills/better-class/references/subagent-prompt.md +0 -47
  34. package/skills/better-class/references/workflow.md +0 -75
  35. package/skills/better-class/scripts/check-syntax.js +0 -112
  36. package/skills/better-class/scripts/check_input_vars.js +0 -52
  37. package/skills/better-class/scripts/init.js +0 -88
  38. package/skills/better-class/scripts/resolve_run_vars.js +0 -96
  39. package/skills/better-class/scripts/run-tests.js +0 -108
  40. package/skills/better-cleancode/SKILL.md +0 -157
  41. package/skills/better-ut/SKILL.md +0 -236
  42. package/skills/blame-class/SKILL.md +0 -78
  43. package/skills/blame-class/references/report_template.md +0 -98
  44. package/skills/blame-class/references/rules.md +0 -40
  45. package/skills/blame-cleancode/SKILL.md +0 -105
  46. package/skills/blame-cleancode/plan.md +0 -1408
  47. package/skills/blame-cleancode/references/rules.md +0 -630
  48. package/skills/blame-ut/SKILL.md +0 -113
  49. package/skills/blame-ut/references/report_template.md +0 -102
  50. package/skills/blame-ut/references/rules.md +0 -197
  51. package/skills/convert-files/SKILL.md +0 -37
  52. package/skills/convert-files/package.json +0 -11
  53. package/skills/convert-files/references/sprint_for_conversion.md +0 -17
  54. package/skills/convert-files/scripts/check_input_vars.js +0 -54
  55. package/skills/convert-files/scripts/convert.js +0 -331
  56. package/skills/convert-files/scripts/init.js +0 -75
  57. package/skills/convert-files/scripts/resolve_run_vars.js +0 -124
  58. package/skills/create-ppt/SKILL.md +0 -47
  59. package/skills/create-ppt/package.json +0 -9
  60. package/skills/create-ppt/references/ppt-styles.md +0 -287
  61. package/skills/create-ppt/references/sprint_for_ppt_generation.md +0 -81
  62. package/skills/create-ppt/references/sprint_for_source_discovery.md +0 -18
  63. package/skills/create-ppt/scripts/check_input_vars.js +0 -57
  64. package/skills/create-ppt/scripts/find-source-files.js +0 -98
  65. package/skills/create-ppt/scripts/init.js +0 -96
  66. package/skills/create-ppt/scripts/md-to-pptx.js +0 -579
  67. package/skills/create-ppt/scripts/resolve_run_vars.js +0 -91
  68. package/skills/jstest/SKILL.md +0 -561
  69. package/skills/jstest/references/case-create.md +0 -327
  70. package/skills/jstest/references/case-fix.md +0 -273
  71. package/skills/jstest/references/config.md +0 -148
  72. package/skills/jstest/references/coverage-analyze.md +0 -247
  73. package/skills/jstest/references/env-ensure.md +0 -210
  74. package/skills/jstest/references/execute.md +0 -168
  75. package/skills/jstest/references/sample.md +0 -166
  76. package/skills/jstest/references/scoring-rules.md +0 -75
  77. package/skills/jstest/references/suitability-check.md +0 -232
  78. package/skills/jstest/references/test-standards.md +0 -288
  79. package/skills/lint/SKILL.md +0 -440
  80. package/skills/lint/references/ai-fix.md +0 -138
  81. package/skills/lint/references/config-setup.md +0 -103
  82. package/skills/lint/references/config.md +0 -65
  83. package/skills/lint/references/env-ensure.md +0 -89
  84. package/skills/lint/references/language-detect.md +0 -76
  85. package/skills/lint/references/rules-analyze.md +0 -126
  86. package/skills/lint/references/suitability-check.md +0 -82
  87. package/skills/lint/references/tool-fix.md +0 -91
  88. package/skills/peago/references/extract/baseline.md +0 -17
  89. package/skills/peago/references/extract/spec.md +0 -117
  90. package/skills/pytest/SKILL.md +0 -556
  91. package/skills/pytest/references/case-create.md +0 -325
  92. package/skills/pytest/references/case-fix.md +0 -272
  93. package/skills/pytest/references/config.md +0 -145
  94. package/skills/pytest/references/coverage-analyze.md +0 -224
  95. package/skills/pytest/references/env-ensure.md +0 -196
  96. package/skills/pytest/references/execute.md +0 -153
  97. package/skills/pytest/references/sample.md +0 -160
  98. package/skills/pytest/references/scoring-rules.md +0 -57
  99. package/skills/pytest/references/suitability-check.md +0 -221
  100. package/skills/pytest/references/test-standards.md +0 -244
  101. package/skills/query/SKILL.md +0 -72
  102. package/skills/step-extract/SKILL.md +0 -205
  103. /package/skills/{lint/references → peago/references/lint}/languages/js.md +0 -0
  104. /package/skills/{lint/references → peago/references/lint}/languages/py.md +0 -0
  105. /package/skills/{lint/references → peago/references/lint/scripts}/detect-language.js +0 -0
  106. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/Calculator.js +0 -0
  107. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/ConfigManager.js +0 -0
  108. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/FileProcessor.js +0 -0
  109. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/OrderService.js +0 -0
  110. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/TokenGenerator.js +0 -0
  111. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/UserService.js +0 -0
  112. /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/index.js +0 -0
  113. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/Calculator.py +0 -0
  114. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/ConfigManager.py +0 -0
  115. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/FileProcessor.py +0 -0
  116. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/OrderService.py +0 -0
  117. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/TokenGenerator.py +0 -0
  118. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/UserService.py +0 -0
  119. /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/__init__.py +0 -0
@@ -1,579 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * md-to-pptx.js — Markdown 转 PPTX 脚本(ESM,自包含)
4
- *
5
- * 将 slide 结构的 .md 文件转换为 .pptx,输出到指定目录。
6
- * 使用 pptxgenjs,无需浏览器。
7
- *
8
- * 解析规则(与 ppt-styles.md 约定一致):
9
- * - `---` (独立行) → slide 分隔符
10
- * - `# title` → slide 标题(第一个 slide 的 H1 为标题页标题)
11
- * - `## subtitle` → slide 副标题 / 内容页标题
12
- * - `### header` → slide 内小节标题
13
- * - `- text` / ` - text` → 项目符号(支持嵌套)
14
- * - `1. text` → 有序列表
15
- * - `| a | b |` → 表格
16
- * - ```lang ... ``` → 代码块
17
- * - `> text` → 引用 / 分析
18
- * - `<n/total>` → 页码标记(解析时忽略,生成时自动添加)
19
- * - `**bold**` / `*italic*` → 加粗 / 斜体(保留为纯文本标记)
20
- *
21
- * 用法:node md-to-pptx.js <md_file> <output_dir>
22
- * stdout: OK: pptx <input> -> <output> (bytes=N)
23
- * 退出码:0 成功 / 2 参数错误 / 3 依赖缺失 / 4 转换失败
24
- */
25
-
26
- import { readFileSync, writeFileSync, existsSync, statSync, mkdirSync } from 'fs'
27
- import { join, basename, dirname } from 'path'
28
- import { createRequire } from 'module'
29
-
30
- const require = createRequire(import.meta.url)
31
-
32
- // ── CLI 输出模板 ──
33
- const USAGE_TEMPLATE = `ERROR: usage: node md-to-pptx.js <md_file> <output_dir>
34
- md_file: markdown file path to convert
35
- output_dir: pptx output directory (auto-created if not exists)`
36
-
37
- const OK_TEMPLATE = 'OK: pptx ${mdFile} -> ${pptxFile} (bytes=${bytes}, slides=${slideCount})'
38
- const NOT_FOUND_TEMPLATE = 'ERROR: md 文件不存在: ${mdFile}'
39
- const DEP_MISSING_TEMPLATE = 'ERROR: pptxgenjs 依赖缺失,请运行 npm install (in skills/create-ppt)'
40
- const CONVERT_FAIL_TEMPLATE = 'ERROR: 转换失败 ${mdFile}: ${error}'
41
-
42
- const render = (template, data) => template.replace(/\$\{(\w+)\}/g, (_, key) => data[key] ?? '')
43
-
44
- // ── 常量 ──
45
- const SLIDE_SEPARATOR = /^---\s*$/
46
- const H1_RE = /^#\s+(.+)$/
47
- const H2_RE = /^##\s+(.+)$/
48
- const H3_RE = /^###\s+(.+)$/
49
- const BULLET_RE = /^(\s*)-\s+(.+)$/
50
- const ORDERED_RE = /^\d+\.\s+(.+)$/
51
- const TABLE_ROW_RE = /^\|(.+)\|$/
52
- const TABLE_SEP_RE = /^\|[\s:|-]+\|$/
53
- const CODE_FENCE_RE = /^```(\w*)\s*$/
54
- const BLOCKQUOTE_RE = /^>\s?(.*)$/
55
- const PAGE_NUM_RE = /^<(\d+)\/(\d+)>\s*$/
56
- const BOLD_RE = /\*\*(.+?)\*\*/g
57
- const ITALIC_RE = /\*(.+?)\*/g
58
-
59
- /**
60
- * 去除 markdown 强调标记,保留纯文本。
61
- * `**bold**` → `bold`, `*italic*` → `italic`
62
- * @param {string} text
63
- * @returns {string}
64
- */
65
- export function stripEmphasis(text) {
66
- return text.replace(BOLD_RE, '$1').replace(ITALIC_RE, '$1')
67
- }
68
-
69
- /**
70
- * 解析表格行(不含首尾 `|`)为单元格数组。
71
- * @param {string} row - `| a | b | c |` 格式
72
- * @returns {string[]} - `['a', 'b', 'c']`
73
- */
74
- export function parseTableRow(row) {
75
- return row.split('|').map((c) => c.trim()).filter(Boolean)
76
- }
77
-
78
- /**
79
- * 将 markdown 文本解析为 slide 对象数组。
80
- *
81
- * 每个 slide 对象结构:
82
- * ```
83
- * {
84
- * title: string | null, // H1 或 H2 标题
85
- * subtitle: string | null, // H2(当 H1 已作为 title 时)
86
- * elements: Array< // slide 内容元素,按出现顺序
87
- * | { type: 'heading', text: string } // ### 小节标题
88
- * | { type: 'bullets', items: Bullet[] } // 项目符号列表
89
- * | { type: 'ordered', items: string[] } // 有序列表
90
- * | { type: 'table', headers: string[], rows: string[][] } // 表格
91
- * | { type: 'code', lang: string, content: string } // 代码块
92
- * | { type: 'blockquote', text: string } // 引用
93
- * | { type: 'paragraph', text: string } // 普通段落
94
- * >
95
- * }
96
- * ```
97
- * Bullet 结构:`{ text: string, level: number }`(level 0=一级, 1=二级)
98
- *
99
- * @param {string} markdown - 原始 markdown 文本
100
- * @returns {object[]} slide 对象数组
101
- */
102
- export function parseSlides(markdown) {
103
- const lines = markdown.split('\n')
104
- const slides = []
105
- let current = newSlide()
106
- let i = 0
107
-
108
- while (i < lines.length) {
109
- const line = lines[i]
110
-
111
- // slide 分隔符
112
- if (SLIDE_SEPARATOR.test(line)) {
113
- if (hasContent(current)) slides.push(current)
114
- current = newSlide()
115
- i++
116
- continue
117
- }
118
-
119
- // 页码标记 — 忽略
120
- if (PAGE_NUM_RE.test(line)) {
121
- i++
122
- continue
123
- }
124
-
125
- // H1 — 标题
126
- const h1 = line.match(H1_RE)
127
- if (h1) {
128
- current.title = stripEmphasis(h1[1].trim())
129
- i++
130
- continue
131
- }
132
-
133
- // H2 — 副标题 / 内容页标题
134
- const h2 = line.match(H2_RE)
135
- if (h2) {
136
- if (!current.title) {
137
- current.title = stripEmphasis(h2[1].trim())
138
- } else if (!current.subtitle) {
139
- current.subtitle = stripEmphasis(h2[1].trim())
140
- } else {
141
- // 多个 H2,作为 heading 元素
142
- current.elements.push({ type: 'heading', text: stripEmphasis(h2[1].trim()) })
143
- }
144
- i++
145
- continue
146
- }
147
-
148
- // H3 — 小节标题
149
- const h3 = line.match(H3_RE)
150
- if (h3) {
151
- current.elements.push({ type: 'heading', text: stripEmphasis(h3[1].trim()) })
152
- i++
153
- continue
154
- }
155
-
156
- // 代码块
157
- const codeFence = line.match(CODE_FENCE_RE)
158
- if (codeFence) {
159
- const lang = codeFence[1] || ''
160
- const codeLines = []
161
- i++
162
- while (i < lines.length && !CODE_FENCE_RE.test(lines[i])) {
163
- codeLines.push(lines[i])
164
- i++
165
- }
166
- // 跳过闭合 ```
167
- if (i < lines.length) i++
168
- current.elements.push({ type: 'code', lang, content: codeLines.join('\n') })
169
- continue
170
- }
171
-
172
- // 表格
173
- if (TABLE_ROW_RE.test(line)) {
174
- const tableLines = []
175
- while (i < lines.length && TABLE_ROW_RE.test(lines[i])) {
176
- tableLines.push(lines[i])
177
- i++
178
- }
179
- const parsed = parseTableLines(tableLines)
180
- if (parsed) current.elements.push(parsed)
181
- continue
182
- }
183
-
184
- // 项目符号列表
185
- const bulletMatch = line.match(BULLET_RE)
186
- if (bulletMatch) {
187
- const items = []
188
- while (i < lines.length) {
189
- const bm = lines[i].match(BULLET_RE)
190
- if (!bm) break
191
- const indent = bm[1].length
192
- const level = Math.floor(indent / 2)
193
- items.push({ text: stripEmphasis(bm[2].trim()), level })
194
- i++
195
- }
196
- current.elements.push({ type: 'bullets', items })
197
- continue
198
- }
199
-
200
- // 有序列表
201
- if (ORDERED_RE.test(line)) {
202
- const items = []
203
- while (i < lines.length) {
204
- const om = lines[i].match(ORDERED_RE)
205
- if (!om) break
206
- items.push(stripEmphasis(om[1].trim()))
207
- i++
208
- }
209
- current.elements.push({ type: 'ordered', items })
210
- continue
211
- }
212
-
213
- // 引用
214
- const bq = line.match(BLOCKQUOTE_RE)
215
- if (bq) {
216
- const bqLines = []
217
- while (i < lines.length) {
218
- const bqm = lines[i].match(BLOCKQUOTE_RE)
219
- if (!bqm) break
220
- bqLines.push(bqm[1])
221
- i++
222
- }
223
- current.elements.push({ type: 'blockquote', text: stripEmphasis(bqLines.join(' ').trim()) })
224
- continue
225
- }
226
-
227
- // 空行 — 跳过
228
- if (line.trim() === '') {
229
- i++
230
- continue
231
- }
232
-
233
- // 普通段落
234
- current.elements.push({ type: 'paragraph', text: stripEmphasis(line.trim()) })
235
- i++
236
- }
237
-
238
- if (hasContent(current)) slides.push(current)
239
- return slides
240
- }
241
-
242
- /**
243
- * 创建空 slide 对象。
244
- * @returns {{title: null, subtitle: null, elements: []}}
245
- */
246
- function newSlide() {
247
- return { title: null, subtitle: null, elements: [] }
248
- }
249
-
250
- /**
251
- * 判断 slide 是否有内容。
252
- * @param {object} slide
253
- * @returns {boolean}
254
- */
255
- function hasContent(slide) {
256
- return slide.title !== null || slide.subtitle !== null || slide.elements.length > 0
257
- }
258
-
259
- /**
260
- * 解析表格行文本数组为 table 元素。
261
- * @param {string[]} tableLines - `| a | b |` 格式的行数组
262
- * @returns {{type: 'table', headers: string[], rows: string[][]} | null}
263
- */
264
- function parseTableLines(tableLines) {
265
- if (tableLines.length < 2) return null
266
- const rows = tableLines.map((l) => parseTableRow(l.match(TABLE_ROW_RE)[1]))
267
- // 第一行为表头,第二行是分隔行(|---|---|),跳过
268
- let dataStart = 1
269
- if (TABLE_SEP_RE.test(tableLines[1])) dataStart = 2
270
- const headers = rows[0]
271
- const dataRows = rows.slice(dataStart)
272
- return { type: 'table', headers, rows: dataRows }
273
- }
274
-
275
- // ── PPTX 构建 ──
276
-
277
- // 高度估算常量(用于 yPos 跟踪和溢出警告,针对 CJK 文本调优)
278
- const HEADING_H = 0.6
279
- const BULLET_ITEM_H = 0.5 // CJK 文本会换行
280
- const TABLE_ROW_H = 0.5 // CJK 文本会换行
281
- const CODE_LINE_H = 0.2 // fontSize 11 每行约 0.2"
282
- const BLOCKQUOTE_H = 0.65
283
- const PARAGRAPH_H = 0.6
284
- const CONTENT_TOP = 2.0 // 内容页内容起始 y
285
- const CONTENT_BOTTOM = 7.0 // 内容页内容结束 y(页码在 7.0")
286
- const TITLE_PAGE_CONTENT_TOP = 4.8 // 标题页内容起始 y(标题+副标题之后)
287
- const MIN_REMAINING = 0.3 // 放置元素所需的最小剩余高度
288
-
289
- /**
290
- * 加载 pptxgenjs。
291
- * @returns {Function} pptxgenjs 构造函数
292
- * @throws {Error} 依赖不可用时抛出
293
- */
294
- function loadPptxGenJS() {
295
- try {
296
- const PptxGenJS = require('pptxgenjs')
297
- return PptxGenJS
298
- } catch {
299
- throw new Error(DEP_MISSING_TEMPLATE)
300
- }
301
- }
302
-
303
- /**
304
- * 估算元素所需高度(英寸),用于 yPos 跟踪和溢出检测。
305
- * @param {object} el - parseSlides 返回的 slide 元素
306
- * @returns {number}
307
- */
308
- function estimateElementHeight(el) {
309
- switch (el.type) {
310
- case 'heading':
311
- return HEADING_H
312
- case 'bullets':
313
- return Math.max(0.5, el.items.length * BULLET_ITEM_H) + 0.15
314
- case 'ordered':
315
- return Math.max(0.5, el.items.length * BULLET_ITEM_H) + 0.15
316
- case 'table':
317
- return Math.max(0.5, (el.rows.length + 1) * TABLE_ROW_H) + 0.2
318
- case 'code': {
319
- const lineCount = el.content.split('\n').length
320
- return lineCount * CODE_LINE_H + 0.2
321
- }
322
- case 'blockquote':
323
- return BLOCKQUOTE_H
324
- case 'paragraph':
325
- return PARAGRAPH_H
326
- default:
327
- return 0.5
328
- }
329
- }
330
-
331
- /**
332
- * 将 slide 对象数组构建为 .pptx 文件。
333
- *
334
- * 策略:
335
- * - 1:1 映射:一个 md slide block → 一张 pptx 幻灯片(不自动拆分)
336
- * - 表格/文本/列表/代码:放不下时记录警告,不拆分不丢弃(内容保留在 XML 中)
337
- * - 不使用 pptxgenjs autoPage:同幻灯片多表格时会破坏内部状态(issue #1472)
338
- * - 分页的智能应在 skill 生成 md 阶段(capacity rules + height budget)完成
339
- *
340
- * @param {object[]} slides - parseSlides 返回的 slide 数组
341
- * @param {string} outputPath - 输出 .pptx 文件路径
342
- * @returns {Promise<{outputPath: string, bytes: number, slideCount: number, warnings: string[]}>}
343
- */
344
- export async function buildPptx(slides, outputPath) {
345
- const PptxGenJS = loadPptxGenJS()
346
- const pptx = new PptxGenJS()
347
-
348
- pptx.defineLayout({ name: 'CUSTOM', width: 13.33, height: 7.5 })
349
- pptx.layout = 'CUSTOM'
350
-
351
- const total = slides.length
352
- const leftMargin = 0.8
353
- const contentW = 11.73
354
- const warnings = []
355
-
356
- for (let idx = 0; idx < slides.length; idx++) {
357
- const slide = slides[idx]
358
- const slideNum = idx + 1
359
- const s = pptx.addSlide()
360
-
361
- const titleText = slide.title || ''
362
- const subtitleText = slide.subtitle || ''
363
-
364
- if (idx === 0 && titleText) {
365
- // 标题页
366
- s.addText(titleText, {
367
- x: 0.5, y: 2.0, w: 12.33, h: 1.5,
368
- fontSize: 36, bold: true, align: 'center', color: '333333',
369
- })
370
- if (subtitleText) {
371
- s.addText(subtitleText, {
372
- x: 0.5, y: 3.8, w: 12.33, h: 0.8,
373
- fontSize: 20, align: 'center', color: '666666',
374
- })
375
- }
376
- // 标题页元素(如有)放在副标题下方
377
- let yPos = TITLE_PAGE_CONTENT_TOP
378
-
379
- for (const el of slide.elements) {
380
- const remainingH = CONTENT_BOTTOM - yPos
381
- if (remainingH < MIN_REMAINING) {
382
- warnings.push(`Slide ${slideNum} "${titleText}": ${el.type} element may overflow (remaining ${remainingH.toFixed(1)}")`)
383
- }
384
- yPos = placeElementOnSlide(s, el, yPos, leftMargin, contentW, remainingH)
385
- }
386
- } else {
387
- // 内容页
388
- if (titleText) {
389
- s.addText(titleText, {
390
- x: 0.5, y: 0.3, w: 12.33, h: 0.8,
391
- fontSize: 28, bold: true, color: '333333',
392
- })
393
- }
394
- if (subtitleText) {
395
- s.addText(subtitleText, {
396
- x: 0.5, y: 1.1, w: 12.33, h: 0.6,
397
- fontSize: 18, color: '666666',
398
- })
399
- }
400
-
401
- // 内容元素
402
- let yPos = CONTENT_TOP
403
-
404
- for (const el of slide.elements) {
405
- const remainingH = CONTENT_BOTTOM - yPos
406
- const elH = estimateElementHeight(el)
407
-
408
- if (remainingH < MIN_REMAINING) {
409
- warnings.push(`Slide ${slideNum} "${titleText}": ${el.type} element may overflow (remaining ${remainingH.toFixed(1)}", needs ~${elH.toFixed(1)}")`)
410
- }
411
-
412
- yPos = placeElementOnSlide(s, el, yPos, leftMargin, contentW, remainingH)
413
- }
414
- }
415
-
416
- // 页码
417
- s.addText(`${slideNum}/${total}`, {
418
- x: 11.5, y: 7.0, w: 1.5, h: 0.3,
419
- fontSize: 10, align: 'right', color: 'AAAAAA',
420
- })
421
- }
422
-
423
- // 写入文件
424
- mkdirSync(dirname(outputPath), { recursive: true })
425
- await pptx.writeFile({ fileName: outputPath })
426
- const bytes = statSync(outputPath).size
427
- return { outputPath, bytes, slideCount: total, warnings }
428
- }
429
-
430
- /**
431
- * 在幻灯片上放置单个元素,返回新的 y 位置。
432
- * 所有元素按估算高度放置,溢出时由调用方记录警告。
433
- *
434
- * @param {object} s - pptxgenjs slide 对象
435
- * @param {object} el - slide 元素
436
- * @param {number} yPos - 当前 y 位置
437
- * @param {number} leftMargin - 左边距
438
- * @param {number} contentW - 内容宽度
439
- * @param {number} remainingH - 剩余高度
440
- * @returns {number} 放置后的新 y 位置
441
- */
442
- function placeElementOnSlide(s, el, yPos, leftMargin, contentW, remainingH) {
443
- switch (el.type) {
444
- case 'heading': {
445
- s.addText(el.text, {
446
- x: leftMargin, y: yPos, w: contentW, h: 0.5,
447
- fontSize: 18, bold: true, color: '444444',
448
- })
449
- return yPos + HEADING_H
450
- }
451
- case 'bullets': {
452
- const bulletTexts = el.items.map((item) => ({
453
- text: item.text,
454
- options: { bullet: { indent: item.level * 20 }, fontSize: 14 },
455
- }))
456
- const estH = Math.max(0.5, bulletTexts.length * BULLET_ITEM_H)
457
- s.addText(bulletTexts, {
458
- x: leftMargin, y: yPos, w: contentW, h: Math.min(estH, remainingH),
459
- valign: 'top',
460
- })
461
- return yPos + estH + 0.15
462
- }
463
- case 'ordered': {
464
- const orderedTexts = el.items.map((item, i) => ({
465
- text: `${i + 1}. ${item}`,
466
- options: { fontSize: 14 },
467
- }))
468
- const estH = Math.max(0.5, orderedTexts.length * BULLET_ITEM_H)
469
- s.addText(orderedTexts, {
470
- x: leftMargin, y: yPos, w: contentW, h: Math.min(estH, remainingH),
471
- valign: 'top',
472
- })
473
- return yPos + estH + 0.15
474
- }
475
- case 'table': {
476
- const tableRows = [
477
- el.headers.map((h) => ({ text: h, options: { bold: true, fill: '4472C4', color: 'FFFFFF' } })),
478
- ...el.rows.map((row) => row.map((cell) => ({ text: cell }))),
479
- ]
480
- const colW = contentW / el.headers.length
481
- // 不使用 autoPage:pptxgenjs autoPage 在同幻灯片多表格时会破坏内部状态(issue #1472)
482
- // 表格分页的智能应在 skill 生成 md 阶段(capacity rules)完成
483
- s.addTable(tableRows, {
484
- x: leftMargin, y: yPos, w: contentW,
485
- colW: Array(el.headers.length).fill(colW),
486
- border: { type: 'solid', pt: 1, color: 'CCCCCC' },
487
- fontSize: 12,
488
- })
489
- const estH = Math.max(0.5, (el.rows.length + 1) * TABLE_ROW_H)
490
- return yPos + estH + 0.2
491
- }
492
- case 'code': {
493
- const codeLines = el.content.split('\n')
494
- const estH = codeLines.length * CODE_LINE_H
495
- s.addText(el.content, {
496
- x: leftMargin, y: yPos, w: contentW,
497
- h: Math.min(estH, remainingH),
498
- fontSize: 11, fontFace: 'Courier New',
499
- color: '333333', fill: 'F5F5F5',
500
- valign: 'top',
501
- })
502
- return yPos + Math.min(estH, remainingH) + 0.2
503
- }
504
- case 'blockquote': {
505
- s.addText(el.text, {
506
- x: leftMargin + 0.3, y: yPos, w: contentW - 0.3,
507
- h: 0.5, fontSize: 13, italic: true, color: '888888',
508
- fill: 'EEEEEE',
509
- })
510
- return yPos + BLOCKQUOTE_H
511
- }
512
- case 'paragraph': {
513
- s.addText(el.text, {
514
- x: leftMargin, y: yPos, w: contentW, h: 0.5,
515
- fontSize: 14, color: '333333',
516
- })
517
- return yPos + PARAGRAPH_H
518
- }
519
- default:
520
- return yPos
521
- }
522
- }
523
-
524
- /**
525
- * 将 markdown 文件转换为 pptx 文件。
526
- * @param {string} mdFile - 输入 .md 文件路径
527
- * @param {string} outputDir - 输出目录
528
- * @returns {Promise<{mdFile: string, pptxFile: string, bytes: number, slideCount: number, warnings: string[]}>}
529
- */
530
- export async function mdToPptx(mdFile, outputDir) {
531
- if (!existsSync(mdFile) || !statSync(mdFile).isFile()) {
532
- throw new Error(render(NOT_FOUND_TEMPLATE, { mdFile }))
533
- }
534
-
535
- const markdown = readFileSync(mdFile, 'utf-8')
536
- const slides = parseSlides(markdown)
537
-
538
- if (slides.length === 0) {
539
- throw new Error(`ERROR: 未解析到 slide 内容: ${mdFile}`)
540
- }
541
-
542
- const pptxBasename = basename(mdFile, '.md') + '.pptx'
543
- const pptxFile = join(outputDir, pptxBasename)
544
-
545
- const result = await buildPptx(slides, pptxFile)
546
- return { mdFile, pptxFile: result.outputPath, bytes: result.bytes, slideCount: result.slideCount, warnings: result.warnings }
547
- }
548
-
549
- // ── CLI 入口 ──
550
- const isMain = import.meta.url === `file://${process.argv[1]}`
551
- if (isMain) {
552
- const mdFile = process.argv[2]
553
- const outputDir = process.argv[3]
554
-
555
- if (!mdFile || !outputDir) {
556
- console.error(USAGE_TEMPLATE)
557
- process.exit(2)
558
- }
559
-
560
- mdToPptx(mdFile, outputDir)
561
- .then((result) => {
562
- console.log(render(OK_TEMPLATE, result))
563
- if (result.warnings?.length > 0) {
564
- console.error(`WARNING: ${result.warnings.length} element(s) exceed slide capacity:`)
565
- for (const w of result.warnings) {
566
- console.error(` - ${w}`)
567
- }
568
- }
569
- process.exit(0)
570
- })
571
- .catch((e) => {
572
- if (e.message.includes('pptxgenjs') || e.code === 'ERR_MODULE_NOT_FOUND' || e.message.includes('Cannot find')) {
573
- console.error(DEP_MISSING_TEMPLATE)
574
- process.exit(3)
575
- }
576
- console.error(render(CONVERT_FAIL_TEMPLATE, { mdFile, error: e.message }))
577
- process.exit(4)
578
- })
579
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * resolve_run_vars.js — Output the Run variable table.
3
- *
4
- * Input: argv[2] = skill_data_dir (system variable), argv[3] = input_path, argv[4] = skill_name (system variable)
5
- * Tolerant: input_path as file → source_dir = parent directory; as directory → source_dir = the directory itself
6
- * Validation: skill_data_dir exists and is a directory + input_path exists + is file or directory
7
- * Invalid: print specific error + "请立即按短路规则处理"
8
- * Valid: compute source_dir / run_name / run_dir / output_dir (= resolveOutputDir(input_path, skill_name) → source_dir/skill_name)
9
- */
10
-
11
- import { existsSync, statSync } from 'fs'
12
- import { dirname, basename, join } from 'path'
13
- import { render, resolveOutputDir } from '../../shared/scripts/utils.js'
14
-
15
- const INVALID_OUTPUT_TEMPLATE = 'INVALID: ${error}'
16
-
17
- const RUN_VARS_OUTPUT_TEMPLATE = `OK: Run 变量已解析
18
-
19
- ## Run 变量表
20
-
21
- | 变量 | 值 | 说明 |
22
- |---|---|---|
23
- | \`source_dir\` | \${source_dir} | 源目录路径(input_path 为文件时取所在目录) |
24
- | \`run_name\` | \${run_name} | 源目录名(断点续跑标识) |
25
- | \`run_dir\` | \${run_dir} | 本次执行数据目录 |
26
- | \`output_dir\` | \${output_dir} | 最终产物输出目录(source_dir/skill_name) |`
27
-
28
- /**
29
- * Validate skill_data_dir + input_path, compute run variables (pure function).
30
- * @param {string} skillDataDir — absolute skill data directory (from resolve_system_vars.js)
31
- * @param {string} inputPath — source file or directory path
32
- * @param {string} skillName — skill name (from system variable {{skill_name}})
33
- * @returns {{source_dir: string, run_name: string, run_dir: string, output_dir: string} | {error: string}}
34
- */
35
- export function resolveRunVars(skillDataDir, inputPath, skillName) {
36
- if (!skillDataDir) {
37
- return { error: '系统变量 skill_data_dir 未提供,请立即按短路规则处理' }
38
- }
39
- if (!existsSync(skillDataDir) || !statSync(skillDataDir).isDirectory()) {
40
- return { error: `系统变量 skill_data_dir 非法:${skillDataDir},请立即按短路规则处理` }
41
- }
42
- if (!inputPath) {
43
- return { error: 'input_path 未提供,请立即按短路规则处理' }
44
- }
45
- if (!existsSync(inputPath)) {
46
- return { error: `input_path 不存在:${inputPath},请立即按短路规则处理` }
47
- }
48
- let sourceDir
49
- if (statSync(inputPath).isFile()) {
50
- sourceDir = dirname(inputPath)
51
- } else if (statSync(inputPath).isDirectory()) {
52
- sourceDir = inputPath
53
- } else {
54
- return { error: `input_path 不是文件也不是目录:${inputPath},请立即按短路规则处理` }
55
- }
56
- const runName = basename(sourceDir)
57
- // output_dir = source_dir / skill_name
58
- const outputDir = resolveOutputDir(inputPath, skillName)
59
- const runDir = join(skillDataDir, runName)
60
- return {
61
- source_dir: sourceDir,
62
- run_name: runName,
63
- run_dir: runDir,
64
- output_dir: outputDir,
65
- }
66
- }
67
-
68
- /**
69
- * Render Run variables as a Markdown string (for init.js to reuse the template).
70
- * @param {{source_dir: string, run_name: string, run_dir: string, output_dir: string}} vars
71
- * @returns {string}
72
- */
73
- export function formatRunVars(vars) {
74
- return render(RUN_VARS_OUTPUT_TEMPLATE, vars)
75
- }
76
-
77
- const isMain = import.meta.url === `file://${process.argv[1]}`
78
- if (isMain) {
79
- const skillDataDir = process.argv[2]
80
- const inputPath = process.argv[3]
81
- const skillName = process.argv[4]
82
-
83
- const result = resolveRunVars(skillDataDir, inputPath, skillName)
84
-
85
- if (result.error) {
86
- console.log(render(INVALID_OUTPUT_TEMPLATE, { error: result.error }))
87
- process.exit(0)
88
- }
89
-
90
- console.log(render(RUN_VARS_OUTPUT_TEMPLATE, result))
91
- }