@topmindspace/tms-skills 0.1.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +102 -0
  4. package/bin/tms-skills.js +160 -0
  5. package/package.json +48 -0
  6. package/top-ppt-html/README.md +254 -0
  7. package/top-ppt-html/SKILL.md +111 -0
  8. package/top-ppt-html/assets/examples/2026-09-09-architecture-graphite-dark.html +3926 -0
  9. package/top-ppt-html/assets/examples/2026-09-09-architecture-graphite-dark.model.json +168 -0
  10. package/top-ppt-html/assets/examples/2026-09-09-architecture-spectrum.html +3926 -0
  11. package/top-ppt-html/assets/examples/2026-09-09-architecture-spectrum.model.json +168 -0
  12. package/top-ppt-html/assets/examples/2026-09-09-presentation-apple-mono.html +4325 -0
  13. package/top-ppt-html/assets/examples/2026-09-09-presentation-apple-mono.model.json +321 -0
  14. package/top-ppt-html/assets/examples/2026-09-09-presentation-brand-red.html +4325 -0
  15. package/top-ppt-html/assets/examples/2026-09-09-presentation-brand-red.model.json +321 -0
  16. package/top-ppt-html/assets/examples/2026-09-09-presentation-business-blue.html +4325 -0
  17. package/top-ppt-html/assets/examples/2026-09-09-presentation-business-blue.model.json +321 -0
  18. package/top-ppt-html/assets/examples/2026-09-09-research-deep-teal.html +5527 -0
  19. package/top-ppt-html/assets/examples/2026-09-09-research-deep-teal.model.json +914 -0
  20. package/top-ppt-html/assets/examples/2026-09-09-research-indigo-violet.html +5527 -0
  21. package/top-ppt-html/assets/examples/2026-09-09-research-indigo-violet.model.json +914 -0
  22. package/top-ppt-html/assets/examples/2026-09-09-research-mckinsey.html +5527 -0
  23. package/top-ppt-html/assets/examples/2026-09-09-research-mckinsey.model.json +914 -0
  24. package/top-ppt-html/assets/examples/2026-09-09-research-warm-sand.html +5527 -0
  25. package/top-ppt-html/assets/examples/2026-09-09-research-warm-sand.model.json +914 -0
  26. package/top-ppt-html/assets/pptx-export.js +1944 -0
  27. package/top-ppt-html/assets/style-gallery.html +589 -0
  28. package/top-ppt-html/assets/templates/architecture.html +3728 -0
  29. package/top-ppt-html/assets/templates/engine.css +840 -0
  30. package/top-ppt-html/assets/templates/presentation.html +3738 -0
  31. package/top-ppt-html/assets/templates/research.html +4017 -0
  32. package/top-ppt-html/assets/templates/ui.js +520 -0
  33. package/top-ppt-html/assets/theme-overview-architecture.png +0 -0
  34. package/top-ppt-html/assets/theme-overview-presentation.png +0 -0
  35. package/top-ppt-html/assets/theme-overview-research.png +0 -0
  36. package/top-ppt-html/assets/theme-overview.png +0 -0
  37. package/top-ppt-html/evals/prompts.csv +15 -0
  38. package/top-ppt-html/evals/rubric.schema.json +25 -0
  39. package/top-ppt-html/evals/run_evals.py +220 -0
  40. package/top-ppt-html/evals/trace.example.json +16 -0
  41. package/top-ppt-html/package.json +35 -0
  42. package/top-ppt-html/references/charts-basic.md +624 -0
  43. package/top-ppt-html/references/charts-discipline.md +108 -0
  44. package/top-ppt-html/references/charts-extended.md +482 -0
  45. package/top-ppt-html/references/charts.md +28 -0
  46. package/top-ppt-html/references/components-atoms.md +624 -0
  47. package/top-ppt-html/references/components.md +30 -0
  48. package/top-ppt-html/references/content-rules.md +490 -0
  49. package/top-ppt-html/references/design-system-engine.md +235 -0
  50. package/top-ppt-html/references/design-system.md +478 -0
  51. package/top-ppt-html/references/failure-modes.md +214 -0
  52. package/top-ppt-html/references/high-fidelity.md +127 -0
  53. package/top-ppt-html/references/icons.md +397 -0
  54. package/top-ppt-html/references/industry-benchmark.md +105 -0
  55. package/top-ppt-html/references/infographics-stats.md +308 -0
  56. package/top-ppt-html/references/infographics-structure.md +226 -0
  57. package/top-ppt-html/references/infographics.md +43 -0
  58. package/top-ppt-html/references/layout-grammar.md +315 -0
  59. package/top-ppt-html/references/layouts-architecture.md +108 -0
  60. package/top-ppt-html/references/layouts-combo.md +600 -0
  61. package/top-ppt-html/references/layouts-research.md +160 -0
  62. package/top-ppt-html/references/modes.md +254 -0
  63. package/top-ppt-html/references/outline-design.md +275 -0
  64. package/top-ppt-html/references/playbook.md +266 -0
  65. package/top-ppt-html/references/pptx-export.md +209 -0
  66. package/top-ppt-html/references/reform-plan.md +252 -0
  67. package/top-ppt-html/references/styles.md +370 -0
  68. package/top-ppt-html/references/tech-design.md +138 -0
  69. package/top-ppt-html/scripts/audit_css.py +109 -0
  70. package/top-ppt-html/scripts/audit_docs.py +176 -0
  71. package/top-ppt-html/scripts/audit_skill.py +220 -0
  72. package/top-ppt-html/scripts/audit_styles.py +351 -0
  73. package/top-ppt-html/scripts/build_examples.py +2276 -0
  74. package/top-ppt-html/scripts/build_pptx.js +2380 -0
  75. package/top-ppt-html/scripts/capture_theme_overview.js +78 -0
  76. package/top-ppt-html/scripts/checks_html.py +127 -0
  77. package/top-ppt-html/scripts/cross_verify.py +294 -0
  78. package/top-ppt-html/scripts/env_probe.py +158 -0
  79. package/top-ppt-html/scripts/extract_model.py +210 -0
  80. package/top-ppt-html/scripts/extract_snippet.py +374 -0
  81. package/top-ppt-html/scripts/gen_channel_a.js +214 -0
  82. package/top-ppt-html/scripts/layout-constants.json +3377 -0
  83. package/top-ppt-html/scripts/layout_slots.json +830 -0
  84. package/top-ppt-html/scripts/lib_layout_regions.js +412 -0
  85. package/top-ppt-html/scripts/measure_height.py +178 -0
  86. package/top-ppt-html/scripts/model-schema.json +547 -0
  87. package/top-ppt-html/scripts/negative_tests.py +307 -0
  88. package/top-ppt-html/scripts/package_skill.py +291 -0
  89. package/top-ppt-html/scripts/prepare_images.py +341 -0
  90. package/top-ppt-html/scripts/probe_image_export.py +188 -0
  91. package/top-ppt-html/scripts/quality_gate.py +301 -0
  92. package/top-ppt-html/scripts/regression.py +308 -0
  93. package/top-ppt-html/scripts/render_compare.py +275 -0
  94. package/top-ppt-html/scripts/render_from_model.py +698 -0
  95. package/top-ppt-html/scripts/scaffold_report.py +1054 -0
  96. package/top-ppt-html/scripts/section-file-map.json +105 -0
  97. package/top-ppt-html/scripts/sync_runtime.py +662 -0
  98. package/top-ppt-html/scripts/validate_pptx.py +1510 -0
  99. package/top-ppt-html/scripts/validate_report.py +1456 -0
@@ -0,0 +1,307 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """TopPPT HTML · 门禁反向验证(故障注入)
4
+
5
+ 校验器最容易退化成「只会说 OK 的摆设」。本脚本往合格产物里**注入已知缺陷**,
6
+ 断言对应门禁必须报错——门禁抓不到即视为失败。
7
+
8
+ 覆盖:
9
+ N1 Exhibit 框漏编号(旧实现只校验已编号者的连续性 → 静默通过)
10
+ N2 参考资料两位数编号错配(旧正则 `ref-\\d` 两侧同时落空 → 静默通过)
11
+ N3 参考资料编号跳号
12
+ N4 PPTX 演讲者备注被剔离(dataTable=notes 声称数据入备注,不核对就只是一句承诺)
13
+ N5 模型图表数值篡改(cross_verify 数值核对)
14
+ N6 行动标题判断词鉴别力(正则本身)
15
+ N7 PPTX 字号越出比例尺
16
+ N8 data-chart 未登记类型(登记表白名单)
17
+ N9 图表多样性塌陷(全篇压成同型 → 不同类型数 < 模式下限)
18
+ N10 图片外链(零外链铁律)
19
+ N11 待核实有标色无图例(.tbd 必须配 .tbd-legend/.flagbar)
20
+ N12 模型 theme 与 data-theme 矛盾
21
+ N13 模型 mode 与 data-mode 矛盾
22
+ N14 内部锚点断裂(链接目标 id 不存在)
23
+
24
+ 用法: python scripts/negative_tests.py
25
+ """
26
+ from __future__ import annotations
27
+
28
+ import json
29
+ import re
30
+ import subprocess
31
+ import sys
32
+ import zipfile
33
+ from pathlib import Path
34
+
35
+ try:
36
+ sys.stdout.reconfigure(encoding='utf-8', errors='replace')
37
+ except Exception:
38
+ pass
39
+
40
+ ROOT = Path(__file__).resolve().parent.parent
41
+ OUT = ROOT / 'dist' / 'negtest'
42
+ PY = sys.executable
43
+
44
+
45
+ def run_validate(path: Path) -> tuple[int, str]:
46
+ r = subprocess.run([PY, str(ROOT / 'scripts' / 'validate_report.py'), str(path), '--strict'],
47
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
48
+ return r.returncode, (r.stdout or '') + (r.stderr or '')
49
+
50
+
51
+ def expect_fail(name: str, path: Path, keyword: str) -> bool:
52
+ code, out = run_validate(path)
53
+ # --strict 下 WARN 同样计失败(退出码 1),故 [WARN] 行也算「门禁抓到」
54
+ hit = [ln for ln in out.splitlines()
55
+ if keyword in ln and ('[FAIL]' in ln or '[WARN]' in ln)]
56
+ ok = code != 0 and bool(hit)
57
+ print(f' [{"OK" if ok else "FAIL"}] {name}')
58
+ if hit:
59
+ print(f' 抓到: {hit[0].strip()[:120]}')
60
+ elif not ok:
61
+ print(f' 门禁未触发(期望 FAIL 含「{keyword}」)')
62
+ return ok
63
+
64
+
65
+ def main() -> int:
66
+ base = ROOT / 'assets' / 'examples' / '2026-09-09-research-mckinsey.html'
67
+ if not base.exists():
68
+ print(f'SKIP:基准示例缺失 {base}')
69
+ return 0
70
+ txt = base.read_text(encoding='utf-8')
71
+ OUT.mkdir(parents=True, exist_ok=True)
72
+
73
+ code, out = run_validate(base)
74
+ if code != 0:
75
+ print('[FAIL] 基准示例本身未通过 strict,反向验证失去意义')
76
+ return 1
77
+ print('基准示例 strict 通过,开始故障注入:')
78
+
79
+ cases: list[tuple[str, str, str]] = []
80
+
81
+ # N1 抹掉一个 Exhibit 编号(框仍在)
82
+ cases.append(('N1 Exhibit 框漏编号',
83
+ txt.replace('class="exhibit__no"', 'class="exhibit__no--x"', 1),
84
+ 'Exhibit 框均已编号'))
85
+
86
+ # N2 参考资料改成两位数编号,与正文引用错配
87
+ cases.append(('N2 引用编号两位数错配',
88
+ re.sub(r'id="ref-1"', 'id="ref-10"', txt, count=1),
89
+ '双向对齐'))
90
+
91
+ # N3 编号跳号(两侧同时改,集合仍对齐,但 1..N 不连续)
92
+ t3 = txt.replace('ref-2"', 'ref-9"')
93
+ cases.append(('N3 参考资料编号跳号', t3, '编号连续'))
94
+
95
+ # N8 data-chart 用了登记表外的类型
96
+ cases.append(('N8 图表类型未登记',
97
+ txt.replace('data-chart="hbar"', 'data-chart="hbarx"', 1),
98
+ '登记表内'))
99
+
100
+ # N9 图表多样性塌陷(全部压成 bar → 不同类型数 1 < research 下限 6)
101
+ t9 = txt
102
+ for ct in ('hbar', 'donut', 'waterfall', 'sankey', 'treemap', 'boxplot',
103
+ 'network', 'marimekko', 'streamgraph', 'gantt', 'rose', 'candlestick'):
104
+ t9 = t9.replace(f'data-chart="{ct}"', 'data-chart="bar"')
105
+ cases.append(('N9 图表多样性塌陷', t9, '图表多样性'))
106
+
107
+ # N10 外链图片(零外链铁律)
108
+ cases.append(('N10 图片外链',
109
+ txt.replace('</body>',
110
+ '<img src="https://example.com/x.png" alt="外链注入"></body>', 1),
111
+ '图片源无外链'))
112
+
113
+ # N11 待核实有标色无图例(改名不得包含原串——校验是子串判断)
114
+ t11 = txt.replace('tbd-legend', 'tbd-leg').replace('flagbar', 'flag-bar')
115
+ cases.append(('N11 待核实无图例', t11, '待核实标注'))
116
+
117
+ # N12 模型 theme 与页面 data-theme 矛盾
118
+ cases.append(('N12 模型主题不一致',
119
+ txt.replace('"theme": "light"', '"theme": "dark"', 1),
120
+ 'data-theme 一致'))
121
+
122
+ # N13 模型 mode 与页面 data-mode 矛盾
123
+ cases.append(('N13 模型模式不一致',
124
+ txt.replace('"mode": "research"', '"mode": "presentation"', 1),
125
+ 'data-mode 一致'))
126
+
127
+ # N14 内部锚点断裂(链接目标 id 不存在)
128
+ cases.append(('N14 锚点断裂',
129
+ txt.replace('href="#s1"', 'href="#s404"'),
130
+ '锚点闭环'))
131
+
132
+ # N15 HTML 标签泄漏进可见文本(截图级:转义标签当字面量显示)
133
+ cases.append(('N15 标签泄漏',
134
+ txt.replace('</p>',
135
+ ' &lt;a class="cite" href="#ref-1"&gt;[1]&lt;/a&gt;。</p>', 1),
136
+ 'HTML_TAG_IN_TEXT'))
137
+
138
+ # N16 极偏 donut(0.5% vs 99.5% 应改 KPI,禁环图)
139
+ t16 = txt
140
+ if '"type": "donut"' in t16 or '"type":"donut"' in t16:
141
+ t16 = re.sub(
142
+ r'("type"\s*:\s*"donut"[\s\S]{0,200}?"values"\s*:\s*\[)[^\]]*(\])',
143
+ r'\g<1>0.5, 99.5\g<2>', t16, count=1)
144
+ cases.append(('N16 极偏 donut', t16, 'CHART_SKEW'))
145
+
146
+ # N17 模型字段夹带 HTML 标签(extract 净化 + validate 扫描 REPORT_MODEL)
147
+ t17 = re.sub(
148
+ r'("soWhat"\s*:\s*")',
149
+ r'\g<1><a class=\\"cite\\" href=\\"#ref-1\\">[1]</a> ',
150
+ txt, count=1)
151
+ if t17 == txt:
152
+ t17 = txt.replace(
153
+ '"footnote":',
154
+ '"footnote": "<strong>x</strong> ', 1)
155
+ cases.append(('N17 模型夹带标签', t17, 'HTML_TAG_IN_TEXT'))
156
+
157
+ ok = True
158
+ for name, content, keyword in cases:
159
+ if content == txt:
160
+ print(f' [SKIP] {name}(基准示例无对应结构)')
161
+ continue
162
+ p = OUT / (name.split()[0] + '.html')
163
+ p.write_text(content, encoding='utf-8')
164
+ ok = expect_fail(name, p, keyword) and ok
165
+
166
+ ok = _pptx_notes_case() and ok
167
+ ok = _chart_data_case() and ok
168
+ ok = _title_pattern_case() and ok
169
+ ok = _font_scale_case() and ok
170
+
171
+ print('反向验证通过:注入的缺陷都被门禁抓住。' if ok
172
+ else '反向验证失败:存在抓不到的缺陷,门禁有假阴性。')
173
+ return 0 if ok else 1
174
+
175
+
176
+ def _font_scale_case() -> bool:
177
+ """N7:往 PPTX 里塞一个比例尺外的字号 → FONT_SIZE_OFF_SCALE 必须报。"""
178
+ name = '2026-09-09-research-mckinsey'
179
+ src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
180
+ model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
181
+ if not src.exists() or not model.exists():
182
+ print(' [SKIP] N7 字号越出比例尺(需先跑 regression)')
183
+ return True
184
+ out = OUT / 'N7-off-scale.pptx'
185
+ patched = False
186
+ with zipfile.ZipFile(src) as zin, zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED) as zout:
187
+ for item in zin.infolist():
188
+ data = zin.read(item.filename)
189
+ if not patched and item.filename == 'ppt/slides/slide4.xml':
190
+ text = data.decode('utf-8')
191
+ new = re.sub(r'sz="\d+"', 'sz="1234"', text, count=1) # 12.34pt:任何档位都没有
192
+ if new != text:
193
+ data = new.encode('utf-8')
194
+ patched = True
195
+ zout.writestr(item, data)
196
+ if not patched:
197
+ print(' [SKIP] N7 字号越出比例尺(未找到可改写的 sz 属性)')
198
+ return True
199
+ report = OUT / 'N7.json'
200
+ subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(out),
201
+ '--strict', '--model=' + str(model), '--json-out', str(report)],
202
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
203
+ try:
204
+ data = json.loads(report.read_text(encoding='utf-8'))
205
+ except (OSError, json.JSONDecodeError):
206
+ print(' [FAIL] N7 字号越出比例尺:校验报告不可解析')
207
+ return False
208
+ codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
209
+ ok = 'FONT_SIZE_OFF_SCALE' in codes
210
+ print(f' [{"OK" if ok else "FAIL"}] N7 字号越出比例尺')
211
+ if not ok:
212
+ print(f' 门禁未触发(期望 FONT_SIZE_OFF_SCALE,实际 {sorted(codes)[:6]})')
213
+ return ok
214
+
215
+
216
+ def _title_pattern_case() -> bool:
217
+ """N6:主题词式长标题必须被判为「无判断信号」,结论句标题必须放行。"""
218
+ lc = json.loads((ROOT / 'scripts' / 'layout-constants.json').read_text(encoding='utf-8'))
219
+ pat = ((lc.get('contentQuality') or {}).get('researchTitle') or {}).get('judgmentPattern')
220
+ if not pat:
221
+ print(' [SKIP] N6 行动标题判断词(未配置 judgmentPattern)')
222
+ return True
223
+ topic = ['智能体平台的应用架构与技术选型说明', '关于数据治理需求的整体情况介绍',
224
+ '企业知识库建设的相关背景与范围', '平台能力地图与模块组成一览表',
225
+ '项目实施过程中的应急预案汇总', '面向未来的技术路线图规划说明']
226
+ claim = ['投入产出比在第 3 季度首次转正', '三成团队已把智能体纳入日常流程',
227
+ '数据质量是当前最大的落地瓶颈', '推理成本一年内下降 62%',
228
+ '从试点到规模化:关键卡在治理', '自建方案的总成本高于采购方案']
229
+ leaked = [t for t in topic if re.search(pat, t)]
230
+ hurt = [t for t in claim if not re.search(pat, t)]
231
+ ok = not leaked and not hurt
232
+ print(f' [{"OK" if ok else "FAIL"}] N6 行动标题判断词鉴别力'
233
+ f'(漏放主题词 {len(leaked)}/{len(topic)} · 误伤结论句 {len(hurt)}/{len(claim)})')
234
+ for t in (leaked + hurt)[:3]:
235
+ print(f' {t}')
236
+ return ok
237
+
238
+
239
+ def _chart_data_case() -> bool:
240
+ """N5:篡改模型里的图表数值 → cross_verify 的数值核对必须报不符。"""
241
+ name = '2026-09-09-research-mckinsey'
242
+ pptx = ROOT / 'dist' / 'regression' / f'{name}.pptx'
243
+ mp = ROOT / 'assets' / 'examples' / f'{name}.model.json'
244
+ if not pptx.exists() or not mp.exists():
245
+ print(' [SKIP] N5 图表数值篡改(需先跑 regression)')
246
+ return True
247
+ sys.path.insert(0, str(ROOT / 'scripts'))
248
+ try:
249
+ from pptx import Presentation # noqa: PLC0415
250
+ import cross_verify as CV # noqa: PLC0415
251
+ except ImportError:
252
+ print(' [SKIP] N5 图表数值篡改(python-pptx 未安装)')
253
+ return True
254
+ model = json.loads(mp.read_text(encoding='utf-8'))
255
+ touched = False
256
+ for sec in (model.get('sections') or []):
257
+ c = CV._model_chart(sec) if isinstance(sec, dict) else None
258
+ if c and isinstance(c.get('values'), list) and c['values']:
259
+ c['values'] = [(v + 777) if isinstance(v, (int, float)) else v for v in c['values']]
260
+ touched = True
261
+ break
262
+ if not touched:
263
+ print(' [SKIP] N5 图表数值篡改(基准模型无可改图表)')
264
+ return True
265
+ issues = CV.chart_data_verify(Presentation(str(pptx)), model, name)
266
+ ok = bool(issues)
267
+ print(f' [{"OK" if ok else "FAIL"}] N5 模型图表数值被篡改')
268
+ if ok:
269
+ print(f' 抓到: {issues[0][:120]}')
270
+ else:
271
+ print(' 门禁未触发(数值核对形同虚设)')
272
+ return ok
273
+
274
+
275
+ def _pptx_notes_case() -> bool:
276
+ """N4:剥离演讲者备注 → dataTable=notes 的图表数据不可追溯,必须被 strict 抓住。"""
277
+ name = '2026-09-09-research-mckinsey'
278
+ src = ROOT / 'dist' / 'regression' / f'{name}.pptx'
279
+ model = ROOT / 'assets' / 'examples' / f'{name}.model.json'
280
+ if not src.exists() or not model.exists():
281
+ print(' [SKIP] N4 备注剥离(需先跑 regression 生成 PPTX)')
282
+ return True
283
+ stripped = OUT / 'N4-no-notes.pptx'
284
+ with zipfile.ZipFile(src) as zin, zipfile.ZipFile(stripped, 'w', zipfile.ZIP_DEFLATED) as zout:
285
+ for item in zin.infolist():
286
+ if item.filename.startswith('ppt/notesSlides/'):
287
+ continue
288
+ zout.writestr(item, zin.read(item.filename))
289
+ report = OUT / 'N4.json'
290
+ subprocess.run([PY, str(ROOT / 'scripts' / 'validate_pptx.py'), str(stripped),
291
+ '--strict', '--model=' + str(model), '--json-out', str(report)],
292
+ capture_output=True, text=True, encoding='utf-8', errors='replace')
293
+ try:
294
+ data = json.loads(report.read_text(encoding='utf-8'))
295
+ except (OSError, json.JSONDecodeError):
296
+ print(' [FAIL] N4 备注剥离:校验报告不可解析')
297
+ return False
298
+ codes = {i.get('code') for i in (data.get('errors') or []) + (data.get('warnings') or [])}
299
+ ok = 'MODEL_CHART_NOTES_MISSING' in codes
300
+ print(f' [{"OK" if ok else "FAIL"}] N4 演讲者备注被剥离')
301
+ if not ok:
302
+ print(f' 门禁未触发(期望 MODEL_CHART_NOTES_MISSING,实际 {sorted(codes)[:6]})')
303
+ return ok
304
+
305
+
306
+ if __name__ == '__main__':
307
+ sys.exit(main())
@@ -0,0 +1,291 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """TopPPT HTML · 技能分发包打包器(发布前完整性校验 + 发布清单)
4
+
5
+ 用法:
6
+ python scripts/package_skill.py # 校验 → 打包 → 写发布清单
7
+ python scripts/package_skill.py --check # 只校验不打包(CI / 提交前自检)
8
+
9
+ 产物:
10
+ dist/top-ppt-html.zip 分发包(解压目录名 = 技能全名 top-ppt-html)
11
+ dist/top-ppt-html.manifest.json 发布清单(版本 / 条目 / 大小 / SHA-256),随包留档
12
+
13
+ ────────────────────────────────────────────────────────────────────────
14
+ 进包(= 技能运行与维护所需的最小完备集,缺一即校验失败)
15
+ ────────────────────────────────────────────────────────────────────────
16
+ SKILL.md 技能入口(frontmatter + 触发边界 + 工作流 + 铁律)
17
+ README.md 人类视角的简介 / 安装 / 开发 / 打包
18
+ package.json Node 依赖声明(pptxgenjs)与常用命令
19
+ assets/templates/ 三份模式模板 + engine.css / ui.js(公共片段注入源)
20
+ assets/examples/ 9 份示例 HTML + 9 份 REPORT_MODEL(复制起点 · 覆盖全部 9 风格)
21
+ assets/pptx-export.js PPTX 预览运行时(注入源)
22
+ assets/style-gallery.html 风格 × 模式 × 亮暗主题交互画廊
23
+ assets/theme-overview*.png 4 张主题参考图(六项问询辅助)
24
+ references/*.md 15 篇规范(playbook.md = 唯一常读入口 L1;其余 L2 按需加载)
25
+ scripts/ 生成 / 校验 / 回归 / 维护工具(py + js + json 单源)
26
+ scripts/extract_snippet.py L2 节级片段抽取(减少整读大规范)
27
+ scripts/layout_slots.json 页型布局 IR(高频页型语义槽位)
28
+
29
+ ────────────────────────────────────────────────────────────────────────
30
+ 不进包(构建产物 / 本地状态 / 缓存,与 .gitignore 口径一致)
31
+ ────────────────────────────────────────────────────────────────────────
32
+ dist/ 分发包与回归产物本身
33
+ report-assets/ prepare_images.py 的产出(片段 / 模型对象)
34
+ render-compare/ render_compare.py 的渲染对照产物
35
+ node_modules/ npm 依赖(安装期生成)
36
+ __pycache__/ Python 缓存
37
+ IDE / 智能体本地状态目录 IDE / 智能体本地状态(不入库、不分发)
38
+ scripts/_* 下划线开头的临时脚本(用后即删)
39
+
40
+ ────────────────────────────────────────────────────────────────────────
41
+ 发布前校验(任一不过 → 退出码 1,不产出 zip)
42
+ ────────────────────────────────────────────────────────────────────────
43
+ · SKILL.md frontmatter 含 name / description;name 与分发包目录名一致;
44
+ description 为单行双引号字符串且 ≤ 1024 字符(平台截断阈值)
45
+ · 15 篇 references、3 份模式模板 + engine.css / ui.js、9 组示例、4 张参考图齐全
46
+ · 关键脚本齐全(单源注入 / 审计 / 示例重建 / 回归 / 双校验器 / 精导 / 打包)
47
+ """
48
+ import fnmatch
49
+ import hashlib
50
+ import json
51
+ import re
52
+ import sys
53
+ import zipfile
54
+ from datetime import datetime, timezone
55
+ from pathlib import Path
56
+
57
+ try:
58
+ sys.stdout.reconfigure(encoding='utf-8', errors='replace')
59
+ except Exception:
60
+ pass
61
+
62
+ ROOT = Path(__file__).resolve().parent.parent
63
+ NAME = 'top-ppt-html' # 技能全名 = 分发包顶层目录名 = SKILL.md name
64
+ OUT = ROOT / 'dist' / f'{NAME}.zip'
65
+ MANIFEST = ROOT / 'dist' / f'{NAME}.manifest.json'
66
+ DESC_LIMIT = 1024
67
+ # 版本唯一事实源 = layout-constants.json `version`(v8.3 起 frontmatter 不携带非标 version 键,
68
+ # manifest 版本一律取 LC;frontmatter 若显式声明则以其为准——但不鼓励)
69
+ try:
70
+ VERSION = str(json.loads(
71
+ (ROOT / 'scripts' / 'layout-constants.json').read_text(encoding='utf-8')).get('version') or '0.0')
72
+ except (OSError, json.JSONDecodeError):
73
+ VERSION = '0.0'
74
+
75
+ # 进包清单(显式枚举,缺一即失败)
76
+ INCLUDE = [
77
+ 'SKILL.md',
78
+ 'README.md',
79
+ 'package.json',
80
+ 'assets/pptx-export.js',
81
+ 'assets/style-gallery.html',
82
+ 'assets/theme-overview.png',
83
+ 'assets/theme-overview-presentation.png',
84
+ 'assets/theme-overview-research.png',
85
+ 'assets/theme-overview-architecture.png',
86
+ 'assets/templates/*',
87
+ 'assets/examples/*',
88
+ 'references/*',
89
+ 'scripts/*',
90
+ 'evals/*',
91
+ ]
92
+
93
+ # 出包规则(命中即跳过;与 .gitignore 口径一致)
94
+ EXCLUDE = [
95
+ 'scripts/_*', # 临时脚本
96
+ 'scripts/__pycache__/*',
97
+ '**/__pycache__/*',
98
+ '**/node_modules/*',
99
+ '**/report-assets/*',
100
+ '**/render-compare/*',
101
+ '**/dist/*',
102
+ '**/.codebuddy/*',
103
+ '**/.h3caiwork/*',
104
+ '**/.playwright-mcp/*',
105
+ '**/.claude/*',
106
+ '**/.agents/*',
107
+ '**/.mimocode/*',
108
+ '**/OPTIMIZATION-PLAN.md',
109
+ ]
110
+
111
+ # 必须齐全的关键文件(发布门禁)
112
+ REQUIRED = [
113
+ 'SKILL.md', 'README.md', 'package.json',
114
+ 'assets/pptx-export.js', 'assets/style-gallery.html',
115
+ 'assets/theme-overview.png', 'assets/theme-overview-presentation.png',
116
+ 'assets/theme-overview-research.png', 'assets/theme-overview-architecture.png',
117
+ 'assets/templates/presentation.html', 'assets/templates/research.html',
118
+ 'assets/templates/architecture.html', 'assets/templates/engine.css',
119
+ 'assets/templates/ui.js',
120
+ 'references/playbook.md',
121
+ 'references/modes.md', 'references/outline-design.md', 'references/design-system.md',
122
+ 'references/styles.md', 'references/content-rules.md', 'references/components.md',
123
+ 'references/charts.md',
124
+ 'references/infographics.md', 'references/icons.md', 'references/pptx-export.md',
125
+ 'references/high-fidelity.md', 'references/failure-modes.md',
126
+ 'references/tech-design.md', 'references/industry-benchmark.md',
127
+ 'scripts/env_probe.py', 'scripts/audit_docs.py', 'scripts/audit_skill.py',
128
+ 'scripts/scaffold_report.py',
129
+ 'scripts/sync_runtime.py', 'scripts/audit_styles.py', 'scripts/build_examples.py',
130
+ 'scripts/regression.py', 'scripts/validate_report.py', 'scripts/validate_pptx.py',
131
+ 'scripts/extract_model.py', 'scripts/build_pptx.js', 'scripts/gen_channel_a.js',
132
+ 'scripts/cross_verify.py', 'scripts/prepare_images.py', 'scripts/probe_image_export.py',
133
+ 'scripts/render_compare.py', 'scripts/capture_theme_overview.js', 'scripts/package_skill.py',
134
+ 'scripts/layout-constants.json', 'scripts/model-schema.json', 'scripts/layout_slots.json',
135
+ 'scripts/lib_layout_regions.js', 'scripts/extract_snippet.py', 'scripts/quality_gate.py',
136
+ 'scripts/checks_html.py', 'scripts/section-file-map.json',
137
+ 'scripts/measure_height.py', 'scripts/audit_css.py', 'scripts/negative_tests.py',
138
+ 'references/components-atoms.md', 'references/layouts-research.md',
139
+ 'references/layouts-architecture.md', 'references/layouts-combo.md',
140
+ 'references/charts-basic.md', 'references/charts-extended.md', 'references/charts-discipline.md',
141
+ 'references/design-system-engine.md',
142
+ 'references/infographics-stats.md', 'references/infographics-structure.md',
143
+ 'evals/prompts.csv', 'evals/run_evals.py', 'evals/rubric.schema.json',
144
+ 'evals/trace.example.json',
145
+ ]
146
+
147
+ # 必须达到最小数量的集合(名称含日期,故按数量校验)
148
+ MIN_COUNTS = {
149
+ 'assets/examples/*.html': 9,
150
+ 'assets/examples/*.model.json': 9,
151
+ 'references/*.md': 15,
152
+ }
153
+
154
+
155
+ def picked(rel: str) -> bool:
156
+ return any(rel == p or _match(rel, p) for p in EXCLUDE)
157
+
158
+
159
+ def _match(rel: str, pat: str) -> bool:
160
+ if fnmatch.fnmatch(rel, pat):
161
+ return True
162
+ # '**/x/*' 需匹配任意深度
163
+ if pat.startswith('**/'):
164
+ tail = pat[3:]
165
+ return fnmatch.fnmatch(rel, tail) or fnmatch.fnmatch(rel, '*/' + tail)
166
+ return False
167
+
168
+
169
+ def check_skill_md():
170
+ """frontmatter 门禁:name / description 必需,name 与包名一致,description ≤ 上限。"""
171
+ p = ROOT / 'SKILL.md'
172
+ if not p.exists():
173
+ return None, ['缺少 SKILL.md']
174
+ txt = p.read_text(encoding='utf-8')
175
+ if not txt.startswith('---'):
176
+ return None, ['SKILL.md 未以 YAML frontmatter(---)开头']
177
+ m = re.match(r'^---\s*\n(.*?)\n---\s*\n', txt, re.S)
178
+ if not m:
179
+ return None, ['SKILL.md frontmatter 未正确闭合']
180
+ fm = m.group(1)
181
+ errs = []
182
+ name_m = re.search(r'^name:\s*(\S+)\s*$', fm, re.M)
183
+ if not name_m:
184
+ errs.append('frontmatter 缺 name')
185
+ elif name_m.group(1) != NAME:
186
+ errs.append(f'frontmatter name={name_m.group(1)!r} 与分发包目录名 {NAME!r} 不一致')
187
+ desc_m = re.search(r'^description:\s*"(.*)"\s*$', fm, re.M)
188
+ if not desc_m:
189
+ errs.append('frontmatter 缺 description(须为单行双引号字符串)')
190
+ desc = ''
191
+ else:
192
+ desc = desc_m.group(1)
193
+ if len(desc) > DESC_LIMIT:
194
+ errs.append(f'description {len(desc)} 字符 > {DESC_LIMIT}')
195
+ if '<' in desc or '>' in desc:
196
+ errs.append('description 含尖括号(部分平台会拒载)')
197
+ ver_m = re.search(r'^version:\s*"?([\w.\-]+)"?\s*$', fm, re.M)
198
+ return {'name': NAME, 'description_len': len(desc),
199
+ 'version': ver_m.group(1) if ver_m else VERSION}, errs
200
+
201
+
202
+ def collect():
203
+ seen, files = set(), []
204
+ for pat in INCLUDE:
205
+ for h in sorted(ROOT.glob(pat)):
206
+ if not h.is_file():
207
+ continue
208
+ rel = h.relative_to(ROOT).as_posix()
209
+ if rel in seen or picked(rel):
210
+ continue
211
+ seen.add(rel)
212
+ files.append((rel, h))
213
+ return files
214
+
215
+
216
+ def verify(files):
217
+ errs = []
218
+ have = {rel for rel, _ in files}
219
+ for rel in REQUIRED:
220
+ if rel not in have:
221
+ errs.append(f'缺必需文件: {rel}')
222
+ for pat, n in MIN_COUNTS.items():
223
+ got = len([r for r in have if _match(r, pat) or r == pat])
224
+ if got < n:
225
+ errs.append(f'{pat} 数量 {got} < {n}')
226
+ # 反向:不应出现的路径
227
+ for rel in have:
228
+ if rel.startswith('scripts/_') or '__pycache__' in rel or 'node_modules' in rel:
229
+ errs.append(f'不应进包: {rel}')
230
+ return errs
231
+
232
+
233
+ def main():
234
+ check_only = '--check' in sys.argv[1:]
235
+
236
+ files = collect()
237
+ if not files:
238
+ print('错误:未收集到任何文件')
239
+ return 1
240
+ errs = verify(files)
241
+ meta, fm_errs = check_skill_md()
242
+ errs += fm_errs
243
+
244
+ print('── 发布前校验 ──')
245
+ print(f' 技能名 {NAME} · 版本 {meta.get("version") if meta else "?"} · '
246
+ f'description {meta.get("description_len") if meta else "?"} 字符')
247
+ print(f' 进包文件 {len(files)} 个')
248
+ if errs:
249
+ print(' 校验失败:')
250
+ for e in errs:
251
+ print(f' ✗ {e}')
252
+ return 1
253
+ print(' 校验通过:必需文件齐全 · frontmatter 合规 · 无临时/缓存路径')
254
+
255
+ if check_only:
256
+ print('\n(--check 模式:仅校验,不打包)')
257
+ return 0
258
+
259
+ OUT.parent.mkdir(parents=True, exist_ok=True)
260
+ with zipfile.ZipFile(OUT, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as z:
261
+ for rel, h in files:
262
+ z.write(h, f'{NAME}/{rel}')
263
+
264
+ entries, total = [], 0
265
+ for rel, h in files:
266
+ raw = h.read_bytes()
267
+ total += len(raw)
268
+ entries.append({'path': rel, 'bytes': len(raw),
269
+ 'sha256': hashlib.sha256(raw).hexdigest()})
270
+ manifest = {
271
+ 'skill': NAME,
272
+ 'version': (meta or {}).get('version'),
273
+ 'descriptionLength': (meta or {}).get('description_len'),
274
+ 'builtAt': datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
275
+ 'zip': f'dist/{NAME}.zip',
276
+ 'entries': len(entries),
277
+ 'totalBytes': total,
278
+ 'zipBytes': OUT.stat().st_size,
279
+ 'files': entries,
280
+ }
281
+ MANIFEST.write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding='utf-8')
282
+
283
+ print(f'\n── 打包完成 ──')
284
+ print(f' {OUT}')
285
+ print(f' 条目 {len(entries)} 个 · 原始 {total/1024:.0f} KB · 压缩 {OUT.stat().st_size/1024:.0f} KB')
286
+ print(f' {MANIFEST}(版本 / 条目 / SHA-256,随包留档)')
287
+ return 0
288
+
289
+
290
+ if __name__ == '__main__':
291
+ sys.exit(main())