@iasiv5/dsh-skills 1.3.4 → 1.3.6
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 +1 -0
- package/package.json +3 -4
- package/skills/answer-me-with-html/SKILL.md +3 -3
- package/skills/answer-me-with-html/references/video.md +1 -0
- package/skills/answer-me-with-html/scripts/am.mjs +1671 -1131
- package/skills/code-review/results.tsv +6 -0
- package/skills/code-review/test-prompts.json +63 -10
- package/skills/darwin-skill/README.md +136 -121
- package/skills/darwin-skill/README_EN.md +138 -123
- package/skills/darwin-skill/SKILL.md +256 -421
- package/skills/darwin-skill/_archive/hero-2.0.gif +0 -0
- package/skills/darwin-skill/assets/banner-en.svg +1 -1
- package/skills/darwin-skill/assets/banner.svg +2 -2
- package/skills/darwin-skill/assets/chart-loop-en.html +2 -2
- package/skills/darwin-skill/assets/chart-loop-en.png +0 -0
- package/skills/darwin-skill/assets/chart-loop.html +2 -2
- package/skills/darwin-skill/assets/chart-loop.png +0 -0
- package/skills/darwin-skill/assets/chart-phases-en.html +12 -12
- package/skills/darwin-skill/assets/chart-phases-en.png +0 -0
- package/skills/darwin-skill/assets/chart-phases.html +13 -13
- package/skills/darwin-skill/assets/chart-phases.png +0 -0
- package/skills/darwin-skill/assets/darwin-3.0-launch.mp4 +0 -0
- package/skills/darwin-skill/assets/hero.gif +0 -0
- package/skills/darwin-skill/assets/result-card-example.png +0 -0
- package/skills/darwin-skill/docs/index.html +93 -357
- package/skills/darwin-skill/references/about-author.md +101 -0
- package/skills/darwin-skill/references/eval-protocol.md +156 -0
- package/skills/darwin-skill/references/skilllens-evidence.md +2 -1
- package/skills/darwin-skill/references/v3-evidence.md +114 -0
- package/skills/darwin-skill/scripts/darwin.py +400 -0
- package/skills/darwin-skill/scripts/screenshot.mjs +3 -2
- package/skills/darwin-skill/showcase.html +93 -357
- package/skills/darwin-skill/templates/result-card.html +36 -20
- package/skills/darwin-skill/templates/result-card.png +0 -0
- package/skills/darwin-skill/test-prompts.json +36 -12
- package/skills/docx/SKILL.md +5 -4
- package/skills/docx/scripts/office/helpers/__init__.py +22 -4
- package/skills/docx/scripts/office/helpers/pptx_chart.py +124 -11
- package/skills/docx/scripts/office/helpers/pptx_slide.py +43 -3
- package/skills/docx/scripts/office/soffice.py +85 -1
- package/skills/docx/scripts/office/validate.py +50 -7
- package/skills/docx/scripts/office/validators/base.py +16 -4
- package/skills/docx/scripts/office/validators/docx.py +59 -6
- package/skills/docx/scripts/office/validators/pptx.py +116 -8
- package/skills/docx/scripts/office/validators/redlining.py +292 -113
- package/skills/impeccable/SKILL.md +4 -2
- package/skills/impeccable/reference/adapt.md +1 -1
- package/skills/impeccable/reference/animate.md +17 -0
- package/skills/impeccable/reference/critique-rubric.md +496 -0
- package/skills/impeccable/reference/critique.md +12 -504
- package/skills/impeccable/reference/degraded/documenter.md +1 -1
- package/skills/impeccable/reference/degraded/motion-reviewer.md +29 -0
- package/skills/impeccable/reference/document.md +3 -1
- package/skills/impeccable/reference/foundations.md +44 -0
- package/skills/impeccable/reference/hooks.md +3 -3
- package/skills/impeccable/reference/live-setup.md +1 -1
- package/skills/impeccable/reference/live.md +26 -12
- package/skills/impeccable/reference/new-work-comp.md +24 -0
- package/skills/impeccable/reference/new-work-world.md +20 -0
- package/skills/impeccable/reference/new-work.md +6 -34
- package/skills/impeccable/reference/typeset.md +6 -0
- package/skills/impeccable/reference/visualize.md +1 -1
- package/skills/impeccable/scripts/VERSION +1 -1
- package/skills/impeccable/scripts/engine-checksums.txt +5 -5
- package/skills/impeccable/scripts/live-browser.js +51 -22
- package/skills/pdf/{forms.md → FORMS.md} +1 -1
- package/skills/pdf/{reference.md → REFERENCE.md} +3 -2
- package/skills/xlsx/SKILL.md +19 -14
- package/skills/xlsx/scripts/office/helpers/__init__.py +22 -4
- package/skills/xlsx/scripts/office/helpers/pptx_chart.py +124 -11
- package/skills/xlsx/scripts/office/helpers/pptx_slide.py +43 -3
- package/skills/xlsx/scripts/office/soffice.py +85 -1
- package/skills/xlsx/scripts/office/validate.py +50 -7
- package/skills/xlsx/scripts/office/validators/base.py +16 -4
- package/skills/xlsx/scripts/office/validators/docx.py +59 -6
- package/skills/xlsx/scripts/office/validators/pptx.py +116 -8
- package/skills/xlsx/scripts/office/validators/redlining.py +292 -113
- package/skills/xlsx/scripts/recalc.py +731 -136
- package/skills-manifest.json +1 -1
- /package/skills/darwin-skill/{assets → _archive}/chart-ratchet-en.html +0 -0
- /package/skills/darwin-skill/{assets → _archive}/chart-ratchet-en.png +0 -0
- /package/skills/darwin-skill/{assets → _archive}/chart-ratchet.html +0 -0
- /package/skills/darwin-skill/{assets → _archive}/chart-ratchet.png +0 -0
- /package/skills/darwin-skill/{templates → _archive}/result-card-dark.html +0 -0
- /package/skills/darwin-skill/{templates → _archive}/result-card-white.html +0 -0
|
@@ -271,7 +271,7 @@
|
|
|
271
271
|
}
|
|
272
272
|
.dims-grid {
|
|
273
273
|
display: grid;
|
|
274
|
-
grid-template-columns: repeat(
|
|
274
|
+
grid-template-columns: repeat(3, 1fr);
|
|
275
275
|
gap: 12px;
|
|
276
276
|
}
|
|
277
277
|
.dim-cell {
|
|
@@ -443,6 +443,14 @@
|
|
|
443
443
|
</style>
|
|
444
444
|
</head>
|
|
445
445
|
<body>
|
|
446
|
+
<!-- 达尔文3.0成果卡片。替换带 data-field 的元素文本,数字只能来自 results.tsv 和 darwin.py tally 的输出:
|
|
447
|
+
date / skill-name / skill-id / evidence(证据等级,如 E2 实跑验证)
|
|
448
|
+
score-before / score-after / score-delta(9维总分;同时把 .ring-progress 的 stroke-dashoffset 改成 534 × (1 − score-after/100) 取整)
|
|
449
|
+
top1-*:检查项通过(from、to 填通过率分数如 5/8,pct 填变化,story 填对裸跑增益的胜平负)
|
|
450
|
+
top2-*:SKILL.md 体积(from、to 填行数,pct 填变化,story 填保留与回滚的轮数、留出集结果)
|
|
451
|
+
九维度网格:每格 .dim-old-score 和 .dim-score 填该维度改前改后得分,.dim-arrow 填差值
|
|
452
|
+
improve-1/2/3:三条保留下来的改动,各带一句证据
|
|
453
|
+
-->
|
|
446
454
|
|
|
447
455
|
<div class="card">
|
|
448
456
|
|
|
@@ -482,7 +490,7 @@
|
|
|
482
490
|
</div>
|
|
483
491
|
<div class="hero-journey">
|
|
484
492
|
从 <strong data-field="score-before">72</strong> 分进化到 <strong>87</strong> 分<br>
|
|
485
|
-
<span style="color:#999;font-size:14px;" data-field="skill-id">huashu-proofreading</span>
|
|
493
|
+
<span style="color:#999;font-size:14px;"><span data-field="skill-id">huashu-proofreading</span> · <span data-field="evidence">E2 实跑验证</span></span>
|
|
486
494
|
</div>
|
|
487
495
|
<div class="delta-badge">
|
|
488
496
|
<span data-field="score-delta">+15</span>
|
|
@@ -494,32 +502,32 @@
|
|
|
494
502
|
<!-- 3. 最大突破区 -->
|
|
495
503
|
<div class="breakthrough-section">
|
|
496
504
|
<div class="breakthrough-card primary">
|
|
497
|
-
<div class="breakthrough-label"
|
|
498
|
-
<div class="breakthrough-dim" data-field="top1-name"
|
|
505
|
+
<div class="breakthrough-label">实测</div>
|
|
506
|
+
<div class="breakthrough-dim" data-field="top1-name">检查项通过</div>
|
|
499
507
|
<div class="breakthrough-score-row">
|
|
500
|
-
<span class="breakthrough-from" data-field="top1-from">5</span>
|
|
508
|
+
<span class="breakthrough-from" data-field="top1-from">5/8</span>
|
|
501
509
|
<span class="breakthrough-arrow">→</span>
|
|
502
|
-
<span class="breakthrough-to" data-field="top1-to">
|
|
510
|
+
<span class="breakthrough-to" data-field="top1-to">7/8</span>
|
|
503
511
|
</div>
|
|
504
|
-
<div class="breakthrough-pct" data-field="top1-pct">+
|
|
505
|
-
<div class="breakthrough-story" data-field="top1-story"
|
|
512
|
+
<div class="breakthrough-pct" data-field="top1-pct">+2 项</div>
|
|
513
|
+
<div class="breakthrough-story" data-field="top1-story">对裸模型实跑:2 胜 1 平 0 负</div>
|
|
506
514
|
</div>
|
|
507
515
|
<div class="breakthrough-card secondary">
|
|
508
|
-
<div class="breakthrough-label"
|
|
509
|
-
<div class="breakthrough-dim" data-field="top2-name"
|
|
516
|
+
<div class="breakthrough-label">体积</div>
|
|
517
|
+
<div class="breakthrough-dim" data-field="top2-name">SKILL.md 行数</div>
|
|
510
518
|
<div class="breakthrough-score-row">
|
|
511
|
-
<span class="breakthrough-from" data-field="top2-from">
|
|
519
|
+
<span class="breakthrough-from" data-field="top2-from">412</span>
|
|
512
520
|
<span class="breakthrough-arrow">→</span>
|
|
513
|
-
<span class="breakthrough-to" data-field="top2-to">
|
|
521
|
+
<span class="breakthrough-to" data-field="top2-to">356</span>
|
|
514
522
|
</div>
|
|
515
|
-
<div class="breakthrough-pct" data-field="top2-pct"
|
|
516
|
-
<div class="breakthrough-story" data-field="top2-story"
|
|
523
|
+
<div class="breakthrough-pct" data-field="top2-pct">−14%</div>
|
|
524
|
+
<div class="breakthrough-story" data-field="top2-story">保留 2 轮,回滚 1 轮;留出集 1 胜 1 平 0 负</div>
|
|
517
525
|
</div>
|
|
518
526
|
</div>
|
|
519
527
|
|
|
520
528
|
<!-- 4. 全维度速览 -->
|
|
521
529
|
<div class="dims-section">
|
|
522
|
-
<div class="dims-header"
|
|
530
|
+
<div class="dims-header">九维度全景</div>
|
|
523
531
|
<div class="dims-grid">
|
|
524
532
|
<div class="dim-cell warm">
|
|
525
533
|
<div class="dim-name">元数据</div>
|
|
@@ -538,7 +546,7 @@
|
|
|
538
546
|
<span class="dim-arrow up-big">+3</span>
|
|
539
547
|
</div>
|
|
540
548
|
<div class="dim-cell hot">
|
|
541
|
-
<div class="dim-name"
|
|
549
|
+
<div class="dim-name">失败模式</div>
|
|
542
550
|
<div class="dim-score-row">
|
|
543
551
|
<span class="dim-old-score">4</span>
|
|
544
552
|
<span class="dim-score">7</span>
|
|
@@ -554,7 +562,7 @@
|
|
|
554
562
|
<span class="dim-arrow up-small">+1</span>
|
|
555
563
|
</div>
|
|
556
564
|
<div class="dim-cell hot">
|
|
557
|
-
<div class="dim-name"
|
|
565
|
+
<div class="dim-name">具体性</div>
|
|
558
566
|
<div class="dim-score-row">
|
|
559
567
|
<span class="dim-old-score">5</span>
|
|
560
568
|
<span class="dim-score">9</span>
|
|
@@ -585,6 +593,14 @@
|
|
|
585
593
|
</div>
|
|
586
594
|
<span class="dim-arrow up-big">+3</span>
|
|
587
595
|
</div>
|
|
596
|
+
<div class="dim-cell">
|
|
597
|
+
<div class="dim-name">反例黑名单</div>
|
|
598
|
+
<div class="dim-score-row">
|
|
599
|
+
<span class="dim-old-score">6</span>
|
|
600
|
+
<span class="dim-score">7</span>
|
|
601
|
+
</div>
|
|
602
|
+
<span class="dim-arrow up-small">+1</span>
|
|
603
|
+
</div>
|
|
588
604
|
</div>
|
|
589
605
|
</div>
|
|
590
606
|
|
|
@@ -592,9 +608,9 @@
|
|
|
592
608
|
<div class="summary-section">
|
|
593
609
|
<div class="summary-header">关键改进</div>
|
|
594
610
|
<div class="summary-items">
|
|
595
|
-
<div class="summary-item" data-field="improve-1"
|
|
596
|
-
<div class="summary-item" data-field="improve-2"
|
|
597
|
-
<div class="summary-item" data-field="improve-3"
|
|
611
|
+
<div class="summary-item" data-field="improve-1">删掉两段裸模型本来就会的解释,dev-1 产出不再跑题</div>
|
|
612
|
+
<div class="summary-item" data-field="improve-2">把同一情境的两条路径合成一条,dev-2 少绕 9 次调用</div>
|
|
613
|
+
<div class="summary-item" data-field="improve-3">补上重试上限这条 agent 推断不出来的规则,检查项多过 2 条</div>
|
|
598
614
|
</div>
|
|
599
615
|
</div>
|
|
600
616
|
|
|
Binary file
|
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"id": 1,
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"id": "dev-1",
|
|
4
|
+
"split": "dev",
|
|
5
|
+
"source": "real",
|
|
6
|
+
"prompt": "优化所有skills。我大概装了80个。",
|
|
7
|
+
"checks": [
|
|
8
|
+
"回答里第一步是对全部skill跑体检脚本并给出排序表,而不是直接开始实跑",
|
|
9
|
+
"明确说不会对80个skill挨个实跑,让用户从中挑要进化的",
|
|
10
|
+
"给出进化一个skill大约需要多少次子agent"
|
|
11
|
+
]
|
|
7
12
|
},
|
|
8
13
|
{
|
|
9
|
-
"id": 2,
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
14
|
+
"id": "dev-2",
|
|
15
|
+
"split": "dev",
|
|
16
|
+
"source": "real",
|
|
17
|
+
"prompt": "第2轮盲评出来了:三位评委里两位投新版更好,第三位说新版第2步让agent运行的 scripts/sync.py 在skill目录里根本不存在。按多数留下新版吗?",
|
|
18
|
+
"checks": [
|
|
19
|
+
"没有按票数直接保留",
|
|
20
|
+
"下一步是先核实 scripts/sync.py 是否存在",
|
|
21
|
+
"说明指控成立就回滚或改正,以事实为准不看票数"
|
|
22
|
+
]
|
|
13
23
|
},
|
|
14
24
|
{
|
|
15
|
-
"id":
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
25
|
+
"id": "holdout-1",
|
|
26
|
+
"split": "holdout",
|
|
27
|
+
"source": "real",
|
|
28
|
+
"prompt": "我改了某个skill的一段话,三个评委读完两版SKILL.md都说新版更好,可以合并了吧?",
|
|
29
|
+
"checks": [
|
|
30
|
+
"指出读文档的投票不能决定留不留",
|
|
31
|
+
"给出下一步:用同一批测试让新旧两版各实跑一遍,盲评产出后再裁决"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "holdout-2",
|
|
36
|
+
"split": "holdout",
|
|
37
|
+
"source": "user",
|
|
38
|
+
"prompt": "这轮改动盲评结果是1胜1负,检查项没变,新版SKILL.md比旧版长了12%,留还是不留?",
|
|
39
|
+
"checks": [
|
|
40
|
+
"结论是回滚",
|
|
41
|
+
"理由是效果打平且没有变短"
|
|
42
|
+
]
|
|
19
43
|
}
|
|
20
44
|
]
|
package/skills/docx/SKILL.md
CHANGED
|
@@ -11,7 +11,7 @@ A `.docx` is a ZIP archive of XML files. Choose your approach by task:
|
|
|
11
11
|
| Task | Approach |
|
|
12
12
|
|---|---|
|
|
13
13
|
| **Create** a new document | Write a `docx` (npm) script — see gotchas below |
|
|
14
|
-
| **Edit** an existing document |
|
|
14
|
+
| **Edit** an existing document | unpack → edit `word/document.xml` → `zip` (docx-js cannot open existing files) |
|
|
15
15
|
| **Read** content | `pandoc -t markdown file.docx` |
|
|
16
16
|
|
|
17
17
|
> Script paths below are relative to this skill's directory.
|
|
@@ -28,6 +28,7 @@ A `.docx` is a ZIP archive of XML files. Choose your approach by task:
|
|
|
28
28
|
- **`ImageRun` requires `type:`** (`"png"`, `"jpg"`, …).
|
|
29
29
|
- **`PageBreak` must be inside a `Paragraph`.**
|
|
30
30
|
- **Never use `\n`** — use separate `Paragraph` elements.
|
|
31
|
+
- **Headings:** style every level you use (`title`, `heading1`, `heading2`…) in `styles.default`: `heading1: { run: { font: "Arial", size: 32, bold: true }, paragraph: { spacing: { before: 240, after: 120 }, keepNext: true } }`. Every level needs its own font (even with a document default), `before` and `after` (even if 0) and `keepNext`: the built-in styles set none of them.
|
|
31
32
|
- **TOC:** headings must use built-in `HeadingLevel.*`; custom heading styles need `outlineLevel` set or they won't appear.
|
|
32
33
|
- **Don't use a table as a horizontal rule** — use a paragraph bottom border instead.
|
|
33
34
|
- **Dot-leader / right-aligned-on-same-line:** use `PositionalTab` (`alignment: PositionalTabAlignment.RIGHT`, `leader: PositionalTabLeader.DOT`) inside a `TextRun`, not literal `.` or space padding.
|
|
@@ -37,6 +38,7 @@ A `.docx` is a ZIP archive of XML files. Choose your approach by task:
|
|
|
37
38
|
After writing a `.docx`, render it and look at it:
|
|
38
39
|
|
|
39
40
|
```bash
|
|
41
|
+
zip -d output.docx '*/' >/dev/null || true # drop the ZIP's folder entries: Word has refused a file that has them when opened through a cloud co-editing service
|
|
40
42
|
python scripts/office/soffice.py --headless --convert-to pdf output.docx
|
|
41
43
|
pdftoppm -jpeg -r 100 output.pdf page
|
|
42
44
|
ls page-*.jpg # then Read the images
|
|
@@ -49,11 +51,10 @@ ls page-*.jpg # then Read the images
|
|
|
49
51
|
Legacy `.doc` files must be converted first: `python scripts/office/soffice.py --headless --convert-to docx file.doc`.
|
|
50
52
|
|
|
51
53
|
```bash
|
|
52
|
-
|
|
53
|
-
find unpacked -type l -delete # strip symlink entries — docx from external parties is untrusted
|
|
54
|
+
python3 -c "import sys,zipfile; zipfile.ZipFile(sys.argv[1]).extractall('unpacked')" doc.docx # not unzip, which restores symlinks — docx from external parties is untrusted
|
|
54
55
|
python scripts/merge_runs.py unpacked/ # coalesce fragmented runs so text is findable
|
|
55
56
|
# edit unpacked/word/document.xml in place — do NOT reformat or pretty-print
|
|
56
|
-
(cd unpacked && rm -f ../out.docx && zip -
|
|
57
|
+
(cd unpacked && rm -f ../out.docx && zip -XrDy ../out.docx .)
|
|
57
58
|
python scripts/office/validate.py out.docx --original doc.docx # XSD checks; --auto-repair fixes common issues
|
|
58
59
|
# redlining? add --author "<the name you redlined under>" to check every edit is tracked
|
|
59
60
|
```
|
|
@@ -5,7 +5,7 @@ import stat
|
|
|
5
5
|
import tempfile
|
|
6
6
|
import urllib.parse
|
|
7
7
|
import zipfile
|
|
8
|
-
from pathlib import Path
|
|
8
|
+
from pathlib import Path, PureWindowsPath
|
|
9
9
|
|
|
10
10
|
OOXML_FAMILY = {
|
|
11
11
|
".docx": "docx",
|
|
@@ -21,16 +21,24 @@ _SCHEME_RE = re.compile(r"^[A-Za-z][A-Za-z0-9+.\-]*:")
|
|
|
21
21
|
SLIDE_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
def one_line(text: str, limit: int) -> str:
|
|
25
|
+
return "".join(c if c.isprintable() else c.encode("unicode_escape").decode() for c in text)[:limit]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def names_another_root(name: str) -> bool:
|
|
29
|
+
return bool(PureWindowsPath(name).anchor)
|
|
30
|
+
|
|
31
|
+
|
|
24
32
|
def opc_target(target: str, source_part: str, target_mode: str = "") -> str | None:
|
|
25
33
|
if not target:
|
|
26
34
|
return None
|
|
27
35
|
if target_mode.lower() == "external":
|
|
28
36
|
return None
|
|
37
|
+
target = urllib.parse.unquote(target)
|
|
38
|
+
|
|
29
39
|
if _SCHEME_RE.match(target):
|
|
30
40
|
return None
|
|
31
41
|
|
|
32
|
-
target = urllib.parse.unquote(target)
|
|
33
|
-
|
|
34
42
|
if "\\" in target:
|
|
35
43
|
raise ValueError(f"relationship target is not a POSIX part name: {target!r}")
|
|
36
44
|
|
|
@@ -52,12 +60,15 @@ def opc_target(target: str, source_part: str, target_mode: str = "") -> str | No
|
|
|
52
60
|
|
|
53
61
|
if not parts:
|
|
54
62
|
raise ValueError(f"relationship target resolves to nothing: {target!r}")
|
|
63
|
+
if names_another_root("/".join(parts)):
|
|
64
|
+
raise ValueError(f"relationship target is not a part name: {target!r}")
|
|
55
65
|
return "/".join(parts)
|
|
56
66
|
|
|
57
67
|
|
|
58
68
|
def rels_source_part(rels_file: Path, unpacked_dir: Path) -> str:
|
|
59
69
|
owner_dir = rels_file.parent.parent.relative_to(unpacked_dir)
|
|
60
|
-
|
|
70
|
+
part = posixpath.join(owner_dir.as_posix(), rels_file.name[: -len(".rels")])
|
|
71
|
+
return part.removeprefix("./")
|
|
61
72
|
|
|
62
73
|
|
|
63
74
|
def part_text(data: bytes) -> str:
|
|
@@ -76,12 +87,19 @@ def safe_extract(zf: zipfile.ZipFile, dest: Path) -> None:
|
|
|
76
87
|
for m in zf.infolist():
|
|
77
88
|
if stat.S_ISLNK(m.external_attr >> 16):
|
|
78
89
|
raise ValueError(f"symlink archive entry not allowed: {m.filename!r}")
|
|
90
|
+
if names_another_root(m.filename):
|
|
91
|
+
raise ValueError(f"unsafe archive entry: {m.filename!r}")
|
|
79
92
|
target = (dest / m.filename).resolve()
|
|
80
93
|
if not target.is_relative_to(dest):
|
|
81
94
|
raise ValueError(f"unsafe archive entry: {m.filename!r}")
|
|
82
95
|
zf.extract(m, dest)
|
|
83
96
|
|
|
84
97
|
|
|
98
|
+
def folder_entries(package: Path) -> list[str]:
|
|
99
|
+
with zipfile.ZipFile(package) as zf:
|
|
100
|
+
return [info.filename for info in zf.infolist() if info.is_dir()]
|
|
101
|
+
|
|
102
|
+
|
|
85
103
|
def rezip(src_dir: Path, out_path: Path) -> None:
|
|
86
104
|
files = sorted(p for p in src_dir.rglob("*") if p.is_file())
|
|
87
105
|
ct = src_dir / "[Content_Types].xml"
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
"""Find chart XML that PowerPoint refuses
|
|
1
|
+
"""Find chart XML that PowerPoint refuses or repairs.
|
|
2
2
|
|
|
3
|
-
Detection only:
|
|
4
|
-
|
|
3
|
+
Detection only: more than one repair is usually valid, and only the author knows
|
|
4
|
+
which was meant.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import html
|
|
10
11
|
import re
|
|
12
|
+
from collections import Counter
|
|
11
13
|
from typing import Mapping
|
|
12
14
|
|
|
15
|
+
from defusedxml import ElementTree
|
|
16
|
+
from defusedxml.common import DefusedXmlException
|
|
17
|
+
|
|
13
18
|
from . import part_text
|
|
14
19
|
|
|
15
20
|
|
|
@@ -19,8 +24,12 @@ _GROUPING_RE = re.compile(r"""<c:grouping\b[^>]*?\bval=["'](\w+)["']""")
|
|
|
19
24
|
_DLBL_POS_RE = re.compile(r"""<c:dLblPos\b[^>]*?\bval=["'](\w+)["']""")
|
|
20
25
|
|
|
21
26
|
def _strip_ext_lst(text: str) -> str:
|
|
27
|
+
return _strip_outermost(text, "c:extLst")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _strip_outermost(text: str, name: str) -> str:
|
|
22
31
|
out, cursor = [], 0
|
|
23
|
-
for lo, hi in
|
|
32
|
+
for lo, hi in _outermost_spans(text, name):
|
|
24
33
|
out.append(text[cursor:lo])
|
|
25
34
|
cursor = hi
|
|
26
35
|
out.append(text[cursor:])
|
|
@@ -139,18 +148,113 @@ def _check_chart_axis_references(part: str, xml: str) -> list[str]:
|
|
|
139
148
|
return problems
|
|
140
149
|
|
|
141
150
|
|
|
142
|
-
def
|
|
151
|
+
def _shown(value: str) -> str:
|
|
152
|
+
return '"' + repr(value[:20])[1:-1] + '"'
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
DECIMAL_SETTINGS = (
|
|
156
|
+
"crossesAt", "max", "min", "majorUnit", "minorUnit", "logBase",
|
|
157
|
+
"forward", "backward", "intercept", "x", "y", "w", "h",
|
|
158
|
+
"splitPos", "custUnit", "pictureStackUnit",
|
|
159
|
+
)
|
|
160
|
+
_DECIMAL_SETTING_RE = re.compile(
|
|
161
|
+
rf"""<c:({"|".join(DECIMAL_SETTINGS)})\b[^<>]*?\bval=["']([^"'<>]*)["']"""
|
|
162
|
+
)
|
|
163
|
+
_DECIMAL_RE = re.compile(
|
|
164
|
+
r"[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?"
|
|
165
|
+
r"|[+-]?(inf|infinity|nan(\(\w*\))?|\u221e|1\.#(inf|qnan|snan|ind)\d*)",
|
|
166
|
+
re.IGNORECASE,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _check_decimal_settings(part: str, xml: str) -> list[str]:
|
|
171
|
+
problems = []
|
|
172
|
+
for name, raw in sorted(set(_DECIMAL_SETTING_RE.findall(_strip_ext_lst(xml)))):
|
|
173
|
+
value = html.unescape(raw)
|
|
174
|
+
if _DECIMAL_RE.fullmatch(value.strip()):
|
|
175
|
+
continue
|
|
176
|
+
fix = "Fix: write a plain number, or remove the element"
|
|
177
|
+
if name == "crossesAt" and value.strip() == "autoZero":
|
|
178
|
+
fix = ("Fix: leave valAxisCrossesAt: 0 out of the pptxgenjs options, the axis "
|
|
179
|
+
"crosses at zero anyway. In the XML, write "
|
|
180
|
+
'<c:crosses val="autoZero"/> or a number')
|
|
181
|
+
problems.append(
|
|
182
|
+
f"{part}: <c:{name} val={_shown(value)}> is not a number, and PowerPoint "
|
|
183
|
+
f"will offer to repair the deck. {fix}"
|
|
184
|
+
)
|
|
185
|
+
return problems
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _local(tag: str) -> str:
|
|
189
|
+
return tag.rsplit("}", 1)[-1]
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _drawn_series(root) -> list:
|
|
193
|
+
found, to_visit = [], [root]
|
|
194
|
+
while to_visit:
|
|
195
|
+
for child in to_visit.pop():
|
|
196
|
+
name = _local(child.tag)
|
|
197
|
+
if name == "ser":
|
|
198
|
+
found.append(child)
|
|
199
|
+
elif name == "AlternateContent":
|
|
200
|
+
to_visit.extend(child[:1])
|
|
201
|
+
elif name != "extLst":
|
|
202
|
+
to_visit.append(child)
|
|
203
|
+
return found
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _check_series_order(part: str, xml: str) -> list[str]:
|
|
207
|
+
try:
|
|
208
|
+
root = ElementTree.fromstring(xml.encode("utf-8", "surrogateescape"))
|
|
209
|
+
except (ElementTree.ParseError, DefusedXmlException, LookupError, ValueError):
|
|
210
|
+
return []
|
|
211
|
+
orders = Counter()
|
|
212
|
+
for series in _drawn_series(root):
|
|
213
|
+
own = [c.get("val", "") for c in series if _local(c.tag) == "order"]
|
|
214
|
+
if own and own[0].isascii() and own[0].isdigit():
|
|
215
|
+
orders[own[0]] += 1
|
|
216
|
+
repeated = sorted((o for o, n in orders.items() if n > 1), key=lambda o: (len(o), o))
|
|
217
|
+
if not repeated:
|
|
218
|
+
return []
|
|
219
|
+
return [
|
|
220
|
+
f"{part}: two or more series share the <c:order> value {', '.join(o[:12] for o in repeated)}, "
|
|
221
|
+
f"and PowerPoint will offer to repair the deck. Fix: number <c:order> "
|
|
222
|
+
f"(and <c:idx>) 0, 1, 2... across every series in the chart, a combo "
|
|
223
|
+
f"chart's line series carrying on from its bars"
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
PRESET_DASHES = frozenset({
|
|
228
|
+
"solid", "dot", "dash", "lgDash", "dashDot", "lgDashDot", "lgDashDotDot",
|
|
229
|
+
"sysDash", "sysDot", "sysDashDot", "sysDashDotDot",
|
|
230
|
+
})
|
|
231
|
+
_PRESET_DASH_RE = re.compile(r"""<a:prstDash\b[^<>]*?\bval=["']([^"'<>]*)["']""")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _check_preset_dashes(part: str, xml: str) -> list[str]:
|
|
235
|
+
values = {html.unescape(v) for v in _PRESET_DASH_RE.findall(_strip_ext_lst(xml))}
|
|
236
|
+
return [
|
|
237
|
+
f"{part}: <a:prstDash val={_shown(value)}> is not a dash style, and PowerPoint "
|
|
238
|
+
f"will offer to repair the deck. Use one of {', '.join(sorted(PRESET_DASHES))}. "
|
|
239
|
+
f"In pptxgenjs, lineDash takes one such word for the whole chart, not an array"
|
|
240
|
+
for value in sorted(values)
|
|
241
|
+
if value.strip() not in PRESET_DASHES
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _outermost_spans(text: str, name: str) -> list[tuple[int, int]]:
|
|
143
246
|
spans: list[tuple[int, int]] = []
|
|
144
247
|
depth = 0
|
|
145
248
|
start = 0
|
|
146
|
-
for match in re.finditer(
|
|
249
|
+
for match in re.finditer(rf"<(/?){name}\b[^<>]*?(/?)>", text):
|
|
147
250
|
closing, self_closing = match.group(1), match.group(2)
|
|
148
251
|
if self_closing:
|
|
149
252
|
continue
|
|
150
253
|
if closing:
|
|
151
|
-
depth
|
|
152
|
-
|
|
153
|
-
|
|
254
|
+
if depth:
|
|
255
|
+
depth -= 1
|
|
256
|
+
if depth == 0:
|
|
257
|
+
spans.append((start, match.end()))
|
|
154
258
|
else:
|
|
155
259
|
if depth == 0:
|
|
156
260
|
start = match.start()
|
|
@@ -158,13 +262,22 @@ def _ext_lst_spans(text: str) -> list[tuple[int, int]]:
|
|
|
158
262
|
return spans
|
|
159
263
|
|
|
160
264
|
|
|
161
|
-
CHART_CHECKS = (
|
|
265
|
+
CHART_CHECKS = (
|
|
266
|
+
_check_stacked_label_positions,
|
|
267
|
+
_check_chart_axis_references,
|
|
268
|
+
_check_decimal_settings,
|
|
269
|
+
_check_series_order,
|
|
270
|
+
_check_preset_dashes,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
_COMMENT_OR_PI_RE = re.compile(r"<!--.*?(?:-->|\Z)|<\?(?!xml\s).*?(?:\?>|\Z)", re.DOTALL)
|
|
162
275
|
|
|
163
276
|
|
|
164
277
|
def find_chart_problems(files: Mapping[str, bytes]) -> list[str]:
|
|
165
278
|
problems: list[str] = []
|
|
166
279
|
for part in sorted(n for n in files if _CHART_PART_RE.fullmatch(n)):
|
|
167
|
-
xml = part_text(files[part])
|
|
280
|
+
xml = _strip_outermost(_COMMENT_OR_PI_RE.sub("", part_text(files[part])), "mc:Fallback")
|
|
168
281
|
for check in CHART_CHECKS:
|
|
169
282
|
problems.extend(check(part, xml))
|
|
170
283
|
return problems
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Find the slide-XML defects known or predicted to make PowerPoint refuse or repair the file.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
than a false alarm.
|
|
3
|
+
Schema errors are picked by a denylist over lxml's messages, so an unrecognised
|
|
4
|
+
error class is a miss rather than a false alarm. Animations that name a shape
|
|
5
|
+
the slide no longer has are found by reading the part.
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
|
|
@@ -43,6 +44,14 @@ FATAL_SLIDE_ERRORS: tuple[tuple[re.Pattern[str], str], ...] = (
|
|
|
43
44
|
re.compile(r"\}nvGrpSpPr': Missing child element"),
|
|
44
45
|
"a <p:nvGrpSpPr> with no children",
|
|
45
46
|
),
|
|
47
|
+
(
|
|
48
|
+
re.compile(r"\}(?:off|ext|chOff|chExt)', attribute '\w+': '-?(?:Infinity|NaN)'"),
|
|
49
|
+
"a position or size that is not a number (check the x, y, w, h you worked out)",
|
|
50
|
+
),
|
|
51
|
+
(
|
|
52
|
+
re.compile(r"\}prstDash', attribute 'val'"),
|
|
53
|
+
"an unknown line dash style (for line.dashType try dash, sysDash or solid)",
|
|
54
|
+
),
|
|
46
55
|
)
|
|
47
56
|
|
|
48
57
|
|
|
@@ -50,6 +59,37 @@ def is_schema_verdict(error: str) -> bool:
|
|
|
50
59
|
return error.startswith("Element ")
|
|
51
60
|
|
|
52
61
|
|
|
62
|
+
_PML = "{http://schemas.openxmlformats.org/presentationml/2006/main}"
|
|
63
|
+
_MC = "{http://schemas.openxmlformats.org/markup-compatibility/2006}"
|
|
64
|
+
|
|
65
|
+
_NAMES_A_SHAPE = frozenset({f"{_PML}spTgt", f"{_PML}bldP", f"{_PML}bldGraphic"})
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _shape_id(value: str | None) -> int | str | None:
|
|
69
|
+
text = (value or "").strip()
|
|
70
|
+
if text.isascii() and text.isdigit() and len(text) <= 18:
|
|
71
|
+
return int(text)
|
|
72
|
+
return text or None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def stranded_animation_targets(root) -> list[str]:
|
|
76
|
+
timing = root.find(f"{_PML}timing")
|
|
77
|
+
if timing is None:
|
|
78
|
+
timing = root.find(f"{_MC}AlternateContent/{_MC}Choice/{_PML}timing")
|
|
79
|
+
if timing is None:
|
|
80
|
+
return []
|
|
81
|
+
|
|
82
|
+
on_slide = {_shape_id(e.get("id")) for e in root.iter("{*}cNvPr")}
|
|
83
|
+
named = {_shape_id(e.get("spid")) for e in timing.iter(*_NAMES_A_SHAPE)} - {None}
|
|
84
|
+
stranded = named - on_slide
|
|
85
|
+
return [
|
|
86
|
+
f"<p:timing> animates shape id {spid if isinstance(spid, int) else repr(spid[:16])}, which is gone, so PowerPoint will "
|
|
87
|
+
f"offer to repair the deck. Fix: delete the slide's whole <p:timing> element "
|
|
88
|
+
f"(the slide loses its animations), or put the shape back"
|
|
89
|
+
for spid in sorted(stranded, key=str)
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
53
93
|
def fatal_slide_errors(errors: set[str]) -> list[str]:
|
|
54
94
|
out = []
|
|
55
95
|
for error in sorted(errors):
|
|
@@ -15,11 +15,16 @@ not be completed" and converts nothing. get_soffice_env() stays public for the
|
|
|
15
15
|
callers that build their own argv (they must pass -env:UserInstallation too).
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
18
20
|
import contextlib
|
|
19
21
|
import os
|
|
22
|
+
import re
|
|
23
|
+
import shutil
|
|
20
24
|
import socket
|
|
21
25
|
import subprocess
|
|
22
26
|
import tempfile
|
|
27
|
+
import zipfile
|
|
23
28
|
from collections.abc import Iterable
|
|
24
29
|
from pathlib import Path
|
|
25
30
|
|
|
@@ -43,12 +48,91 @@ def run_soffice(args: Iterable[str], **kwargs) -> subprocess.CompletedProcess:
|
|
|
43
48
|
tempfile.TemporaryDirectory(prefix="lo_profile_", ignore_cleanup_errors=True)
|
|
44
49
|
)
|
|
45
50
|
args = [f"-env:UserInstallation={Path(profile).as_uri()}"] + args
|
|
51
|
+
if _draws_the_document(args):
|
|
52
|
+
copies = Path(stack.enter_context(
|
|
53
|
+
tempfile.TemporaryDirectory(prefix="lo_input_", ignore_cleanup_errors=True)
|
|
54
|
+
))
|
|
55
|
+
args = [_without_outside_links(str(a), copies / str(i)) for i, a in enumerate(args)]
|
|
46
56
|
return subprocess.run(["soffice"] + args, env=get_soffice_env(), **kwargs)
|
|
47
57
|
|
|
48
58
|
|
|
49
59
|
|
|
50
60
|
_SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so"
|
|
51
61
|
|
|
62
|
+
_DRAWN_FORMATS = frozenset(
|
|
63
|
+
{"pdf", "png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff", "webp", "svg", "eps", "emf", "wmf"}
|
|
64
|
+
)
|
|
65
|
+
_WEB_OR_MAIL = re.compile(r"^(?:https?|mailto):", re.I)
|
|
66
|
+
_RELS_NS = "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
67
|
+
_NO_RELS = f'<Relationships xmlns="{_RELS_NS}"/>'.encode()
|
|
68
|
+
_MAX_RELS_BYTES = 32 * 1024 * 1024
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _draws_the_document(args: list) -> bool:
|
|
72
|
+
for flag, value in zip(args, args[1:]):
|
|
73
|
+
if str(flag) in ("--convert-to", "-convert-to"):
|
|
74
|
+
return str(value).split(":")[0].lower() in _DRAWN_FORMATS
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _cut_outside_links(rels: bytes) -> bytes | None:
|
|
79
|
+
from defusedxml import ElementTree
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
root = ElementTree.fromstring(rels)
|
|
83
|
+
except (ElementTree.ParseError, ValueError, LookupError):
|
|
84
|
+
return _NO_RELS
|
|
85
|
+
cut = False
|
|
86
|
+
for entry in root.iter():
|
|
87
|
+
if entry.get("TargetMode", "Internal") == "Internal":
|
|
88
|
+
continue
|
|
89
|
+
if _WEB_OR_MAIL.match(entry.get("Target", "")):
|
|
90
|
+
continue
|
|
91
|
+
entry.set("TargetMode", "External")
|
|
92
|
+
entry.set("Target", "about:blank")
|
|
93
|
+
cut = True
|
|
94
|
+
if not cut:
|
|
95
|
+
return None
|
|
96
|
+
for element in root.iter():
|
|
97
|
+
element.tag = element.tag.rsplit("}", 1)[-1]
|
|
98
|
+
root.set("xmlns", _RELS_NS)
|
|
99
|
+
return ElementTree.tostring(root)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _without_outside_links(arg: str, folder: Path) -> str:
|
|
103
|
+
|
|
104
|
+
if not os.path.isfile(arg) or not zipfile.is_zipfile(arg):
|
|
105
|
+
return arg
|
|
106
|
+
with open(arg, "rb") as file:
|
|
107
|
+
if file.read(4) != b"PK\x03\x04":
|
|
108
|
+
return arg
|
|
109
|
+
with zipfile.ZipFile(arg) as package:
|
|
110
|
+
cut = {}
|
|
111
|
+
for member in package.infolist():
|
|
112
|
+
if member.filename.lower().endswith(".rels"):
|
|
113
|
+
try:
|
|
114
|
+
data = package.read(member) if member.file_size <= _MAX_RELS_BYTES else None
|
|
115
|
+
except Exception:
|
|
116
|
+
data = None
|
|
117
|
+
rels = _NO_RELS if data is None else _cut_outside_links(data)
|
|
118
|
+
if rels is not None:
|
|
119
|
+
cut[member.filename] = rels
|
|
120
|
+
if not cut:
|
|
121
|
+
return arg
|
|
122
|
+
folder.mkdir()
|
|
123
|
+
copy = folder / Path(arg).name
|
|
124
|
+
with zipfile.ZipFile(copy, "w") as out:
|
|
125
|
+
for member in package.infolist():
|
|
126
|
+
entry = zipfile.ZipInfo(member.filename, member.date_time)
|
|
127
|
+
entry.compress_type = member.compress_type
|
|
128
|
+
if member.filename in cut:
|
|
129
|
+
entry.compress_type = zipfile.ZIP_DEFLATED
|
|
130
|
+
out.writestr(entry, cut[member.filename])
|
|
131
|
+
else:
|
|
132
|
+
with package.open(member) as source, out.open(entry, "w", force_zip64=True) as target:
|
|
133
|
+
shutil.copyfileobj(source, target)
|
|
134
|
+
return str(copy)
|
|
135
|
+
|
|
52
136
|
|
|
53
137
|
def _needs_shim() -> bool:
|
|
54
138
|
try:
|
|
@@ -64,7 +148,7 @@ def _ensure_shim() -> Path:
|
|
|
64
148
|
return _SHIM_SO
|
|
65
149
|
|
|
66
150
|
src = Path(tempfile.gettempdir()) / "lo_socket_shim.c"
|
|
67
|
-
src.write_text(_SHIM_SOURCE)
|
|
151
|
+
src.write_text(_SHIM_SOURCE, encoding="utf-8")
|
|
68
152
|
subprocess.run(
|
|
69
153
|
["gcc", "-shared", "-fPIC", "-o", str(_SHIM_SO), str(src), "-ldl"],
|
|
70
154
|
check=True,
|