odforge 0.3.0__py3-none-any.whl

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 (66) hide show
  1. odforge/__init__.py +1 -0
  2. odforge/benchmark.py +287 -0
  3. odforge/check.py +416 -0
  4. odforge/cli.py +1027 -0
  5. odforge/components.py +270 -0
  6. odforge/critic.py +1260 -0
  7. odforge/docfonts.py +104 -0
  8. odforge/editor_api.py +33 -0
  9. odforge/editor_launch.py +134 -0
  10. odforge/editor_routes.py +131 -0
  11. odforge/extract.py +478 -0
  12. odforge/feedback.py +86 -0
  13. odforge/fontembed.py +166 -0
  14. odforge/ir.py +1181 -0
  15. odforge/layoutcheck.py +602 -0
  16. odforge/llm.py +1865 -0
  17. odforge/localguard.py +42 -0
  18. odforge/mcp_server.py +552 -0
  19. odforge/media.py +352 -0
  20. odforge/odpedit.py +1219 -0
  21. odforge/package.py +114 -0
  22. odforge/pagefacts.py +388 -0
  23. odforge/preview.py +104 -0
  24. odforge/references.py +153 -0
  25. odforge/render/__init__.py +40 -0
  26. odforge/render/odp.py +5687 -0
  27. odforge/render/ods.py +155 -0
  28. odforge/render/odt.py +223 -0
  29. odforge/scene.py +657 -0
  30. odforge/setup_agents.py +274 -0
  31. odforge/skills/odforge-design/SKILL.md +298 -0
  32. odforge/skills/odforge-design/themes/academic.md +52 -0
  33. odforge/skills/odforge-design/themes/clay.md +53 -0
  34. odforge/skills/odforge-design/themes/color-system.md +59 -0
  35. odforge/skills/odforge-design/themes/crimson.md +53 -0
  36. odforge/skills/odforge-design/themes/dark.md +53 -0
  37. odforge/skills/odforge-design/themes/forest.md +54 -0
  38. odforge/skills/odforge-design/themes/gold.md +53 -0
  39. odforge/skills/odforge-design/themes/minimal.md +53 -0
  40. odforge/skills/odforge-design/themes/navy.md +56 -0
  41. odforge/skills/odforge-design/themes/plum.md +53 -0
  42. odforge/skills/odforge-design/themes/sky.md +53 -0
  43. odforge/skills/odforge-design/themes/slate.md +53 -0
  44. odforge/skills/odforge-design/themes/teal.md +53 -0
  45. odforge/skills/odforge-design/themes/violet.md +56 -0
  46. odforge/templates.py +250 -0
  47. odforge/textmetrics.py +616 -0
  48. odforge/textutil.py +24 -0
  49. odforge/themes.py +886 -0
  50. odforge/validate.py +403 -0
  51. odforge/watch.py +266 -0
  52. odforge/webapi.py +2617 -0
  53. odforge/webui/assets/editor-CjpYXM1a.css +1 -0
  54. odforge/webui/assets/editor-DPToJGio.js +3 -0
  55. odforge/webui/assets/jsx-runtime-C7KMcVI_.js +8 -0
  56. odforge/webui/assets/main-BLOs7Hnk.js +7 -0
  57. odforge/webui/assets/main-D21yFVE6.css +1 -0
  58. odforge/webui/editor.html +14 -0
  59. odforge/webui/index.html +25 -0
  60. odforge/xmlsafe.py +46 -0
  61. odforge/zipguard.py +91 -0
  62. odforge-0.3.0.dist-info/METADATA +95 -0
  63. odforge-0.3.0.dist-info/RECORD +66 -0
  64. odforge-0.3.0.dist-info/WHEEL +4 -0
  65. odforge-0.3.0.dist-info/entry_points.txt +3 -0
  66. odforge-0.3.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,274 @@
1
+ """``odforge setup``: hook ODForge into the coding agents on this machine.
2
+
3
+ One command so nobody has to find interpreter paths or edit JSON by hand:
4
+
5
+ * registers the MCP server with Claude Code and Codex (user scope, so every
6
+ project sees it),
7
+ * links the ``odforge-design`` skill where those agents look for skills,
8
+ * makes ``odforge`` itself runnable from a plain shell when it is not yet, so an
9
+ agent can start ``odforge edit`` / ``odforge preview``.
10
+
11
+ Every step reports what it did; ``remove=True`` undoes them.
12
+
13
+ ``odforge init`` is the per-project counterpart (the open-slide model): it drops
14
+ AGENTS.md / CLAUDE.md, a copy of the skill and an ``.mcp.json`` into a folder, so
15
+ any agent opened there learns ODForge from files it reads anyway — nobody has to
16
+ point it at the README.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import json
22
+ import os
23
+ import shutil
24
+ import subprocess
25
+ import sys
26
+ from dataclasses import dataclass
27
+ from pathlib import Path
28
+ from typing import Callable, List, Optional
29
+
30
+ NAME = "odforge"
31
+ SKILL = "odforge-design"
32
+ # What a machine without a checkout runs: the PyPI package plus the extras the
33
+ # editor and CJK line breaking need. Shared with the Claude Code plugin manifest.
34
+ UVX_SPEC = "odforge[web,cjk]"
35
+
36
+
37
+ @dataclass
38
+ class Step:
39
+ label: str
40
+ ok: bool
41
+ detail: str
42
+
43
+
44
+ def _bin(name: str) -> Optional[Path]:
45
+ candidate = Path(sys.executable).parent / name
46
+ return candidate if candidate.exists() else None
47
+
48
+
49
+ def mcp_command() -> List[str]:
50
+ script = _bin("odforge-mcp")
51
+ return [str(script)] if script else [sys.executable, "-m", "odforge.mcp_server"]
52
+
53
+
54
+ def skill_source() -> Optional[Path]:
55
+ # Inside the package for a wheel install (force-included at build time); the
56
+ # repo's own skills/ for a source checkout, which is also the plugin's copy.
57
+ here = Path(__file__).resolve().parent
58
+ for path in (here / "skills" / SKILL, here.parents[1] / "skills" / SKILL):
59
+ if (path / "SKILL.md").is_file():
60
+ return path
61
+ return None
62
+
63
+
64
+ def portable_mcp_command() -> List[str]:
65
+ """An MCP command that survives being committed to git or copied to another machine.
66
+
67
+ ``mcp_command()`` names this interpreter's absolute path, which is right for a
68
+ per-user registration but breaks in a project file the moment the folder moves
69
+ or ``uvx`` garbage-collects its temporary environment.
70
+ """
71
+ if shutil.which("uvx"):
72
+ return ["uvx", "--from", UVX_SPEC, "odforge-mcp"]
73
+ return mcp_command()
74
+
75
+
76
+ def _run(args: List[str]) -> subprocess.CompletedProcess:
77
+ return subprocess.run(
78
+ args, capture_output=True, text=True, stdin=subprocess.DEVNULL, timeout=60
79
+ )
80
+
81
+
82
+ def _register(cli: str, add: List[str], remove: List[str], uninstall: bool) -> Step:
83
+ exe = shutil.which(cli)
84
+ if exe is None:
85
+ return Step(f"{cli} MCP", False, f"找不到 {cli},略過")
86
+ _run([exe, *remove]) # idempotent: replace an older registration
87
+ if uninstall:
88
+ return Step(f"{cli} MCP", True, "已移除")
89
+ proc = _run([exe, *add])
90
+ if proc.returncode != 0:
91
+ return Step(f"{cli} MCP", False, (proc.stderr or proc.stdout).strip()[:200])
92
+ return Step(f"{cli} MCP", True, "已註冊(" + " ".join(add[add.index("--") + 1 :]) + ")")
93
+
94
+
95
+ def _link(target: Path, source: Optional[Path], label: str, uninstall: bool) -> Step:
96
+ if uninstall:
97
+ if target.is_symlink():
98
+ target.unlink()
99
+ return Step(label, True, f"已移除 {target}")
100
+ return Step(label, True, "沒有需要移除的連結")
101
+ if source is None:
102
+ return Step(label, False, "找不到來源,略過")
103
+ if target.is_symlink():
104
+ target.unlink()
105
+ elif target.exists():
106
+ return Step(label, False, f"{target} 已存在且不是 ODForge 建立的連結,未覆蓋")
107
+ target.parent.mkdir(parents=True, exist_ok=True)
108
+ target.symlink_to(source)
109
+ return Step(label, True, f"{target} → {source}")
110
+
111
+
112
+ def ephemeral_install() -> bool:
113
+ """True when running from ``uvx``'s throwaway environment.
114
+
115
+ Registering paths inside it would work today and break whenever uv prunes its
116
+ cache, long after anyone remembers running setup.
117
+ """
118
+ return any(part.startswith("archive-v") for part in Path(sys.prefix).parts)
119
+
120
+
121
+ def setup(
122
+ remove: bool = False,
123
+ claude: bool = True,
124
+ codex: bool = True,
125
+ home: Optional[Path] = None,
126
+ which: Callable[[str], Optional[str]] = shutil.which,
127
+ ) -> List[Step]:
128
+ home = home or Path.home()
129
+ if ephemeral_install() and not remove:
130
+ return [
131
+ Step(
132
+ "安裝方式",
133
+ False,
134
+ f'uvx 的環境是暫時的,請改用 uv tool install "{UVX_SPEC}" 後再執行 odforge setup',
135
+ )
136
+ ]
137
+ steps: List[Step] = []
138
+ command = mcp_command()
139
+ if claude:
140
+ steps.append(
141
+ _register(
142
+ "claude",
143
+ ["mcp", "add", NAME, "--scope", "user", "--", *command],
144
+ ["mcp", "remove", NAME, "--scope", "user"],
145
+ remove,
146
+ )
147
+ )
148
+ steps.append(
149
+ _link(home / ".claude" / "skills" / SKILL, skill_source(), "Claude Code skill", remove)
150
+ )
151
+ if codex:
152
+ steps.append(
153
+ _register(
154
+ "codex", ["mcp", "add", NAME, "--", *command], ["mcp", "remove", NAME], remove
155
+ )
156
+ )
157
+ if (home / ".codex").is_dir():
158
+ steps.append(
159
+ _link(home / ".codex" / "skills" / SKILL, skill_source(), "Codex skill", remove)
160
+ )
161
+
162
+ # The skill tells agents to run `odforge edit`; make sure a shell can find it.
163
+ local_bin = home / ".local" / "bin"
164
+ target = local_bin / "odforge"
165
+ cli = _bin("odforge")
166
+ if remove:
167
+ if target.is_symlink() and cli and os.path.realpath(target) == os.path.realpath(cli):
168
+ target.unlink()
169
+ steps.append(Step("odforge 指令", True, f"已移除 {target}"))
170
+ elif which("odforge") is None and cli is not None:
171
+ if target.exists() or target.is_symlink():
172
+ steps.append(Step("odforge 指令", False, f"{target} 已存在,未覆蓋"))
173
+ else:
174
+ local_bin.mkdir(parents=True, exist_ok=True)
175
+ target.symlink_to(cli)
176
+ on_path = str(local_bin) in os.environ.get("PATH", "").split(os.pathsep)
177
+ note = "" if on_path else f";請把 {local_bin} 加進 PATH"
178
+ steps.append(Step("odforge 指令", True, f"{target} → {cli}{note}"))
179
+ return steps
180
+
181
+
182
+ # ---------------------------------------------------------------- odforge init
183
+
184
+ BEGIN = "<!-- odforge:begin -->"
185
+ END = "<!-- odforge:end -->"
186
+
187
+ AGENTS_BLOCK = f"""{BEGIN}
188
+ ## 簡報與 ODF 文件:用 ODForge
189
+
190
+ 這個資料夾裝好了 ODForge。使用者要做簡報、文件或試算表(尤其 .odp/.odt/.ods),
191
+ 或要看、改既有的 .odp 時:
192
+
193
+ 1. **先讀 skill**:`.claude/skills/{SKILL}/SKILL.md`(同一份也在 `.agents/skills/`)。
194
+ 裡面有訪談、大綱、IR 契約與主題規格,照著寫出來的簡報才不會跑版。
195
+ 2. **用 MCP 工具 `odforge`**(`forge_presentation`、`edit_odp`、`inspect_odf`…)產檔與修改,
196
+ 不要自己手寫 ODF XML。
197
+ 3. **在網頁裡來回修改**:產出後編輯器會自動在瀏覽器打開;接著呼叫 `wait_for_feedback`,
198
+ 照使用者的留言用 `edit_odp` 修改,直到回 `done`。
199
+ 4. **絕對不要叫使用者打開 LibreOffice**,它只在背景當渲染器。
200
+
201
+ 找不到 `odforge` MCP 工具時,請使用者在終端機執行
202
+ `uv tool install "odforge[web,cjk]" && odforge setup`,再開新對話。
203
+ {END}
204
+ """
205
+
206
+ CLAUDE_BLOCK = f"""{BEGIN}
207
+ @AGENTS.md
208
+ {END}
209
+ """
210
+
211
+
212
+ def _upsert_block(path: Path, block: str) -> Step:
213
+ """Write ODForge's marked block into ``path``, leaving everything else alone."""
214
+ if not path.exists():
215
+ path.write_text(block, encoding="utf-8")
216
+ return Step(path.name, True, f"已建立 {path}")
217
+ text = path.read_text(encoding="utf-8")
218
+ start, end = text.find(BEGIN), text.find(END)
219
+ if start != -1 and end > start:
220
+ new = text[:start] + block.rstrip("\n") + text[end + len(END) :]
221
+ verb = "已更新"
222
+ else:
223
+ new = text.rstrip("\n") + "\n\n" + block
224
+ verb = "已附加到"
225
+ if new == text:
226
+ return Step(path.name, True, "已是最新")
227
+ path.write_text(new, encoding="utf-8")
228
+ return Step(path.name, True, f"{verb} {path}")
229
+
230
+
231
+ def _copy_skill(target: Path, source: Optional[Path], label: str) -> Step:
232
+ if source is None:
233
+ return Step(label, False, "找不到 skill 來源,略過")
234
+ if target.is_symlink() or (target.exists() and not (target / "SKILL.md").is_file()):
235
+ return Step(label, False, f"{target} 已存在且不是 ODForge 的 skill,未覆蓋")
236
+ if target.exists():
237
+ shutil.rmtree(target)
238
+ target.parent.mkdir(parents=True, exist_ok=True)
239
+ # A copy, not a link: the folder must still work after it is zipped, pushed
240
+ # or opened on a machine where this interpreter does not exist.
241
+ shutil.copytree(source, target, ignore=shutil.ignore_patterns("__pycache__", ".DS_Store"))
242
+ return Step(label, True, f"已複製到 {target}")
243
+
244
+
245
+ def _write_mcp_json(path: Path, command: List[str]) -> Step:
246
+ data: dict = {}
247
+ if path.exists():
248
+ try:
249
+ data = json.loads(path.read_text(encoding="utf-8"))
250
+ except (OSError, ValueError) as exc:
251
+ return Step(".mcp.json", False, f"讀不懂既有的 {path}({exc}),未修改")
252
+ if not isinstance(data, dict):
253
+ return Step(".mcp.json", False, f"{path} 不是 JSON 物件,未修改")
254
+ servers = data.setdefault("mcpServers", {})
255
+ entry = {"command": command[0], "args": command[1:]}
256
+ if servers.get(NAME) == entry:
257
+ return Step(".mcp.json", True, "已是最新")
258
+ servers[NAME] = entry
259
+ path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
260
+ return Step(".mcp.json", True, f"已登記 {NAME} → {' '.join(command)}")
261
+
262
+
263
+ def init_project(directory: Path) -> List[Step]:
264
+ """Make ``directory`` a folder where any coding agent already knows ODForge."""
265
+ directory.mkdir(parents=True, exist_ok=True)
266
+ source = skill_source()
267
+ return [
268
+ _upsert_block(directory / "AGENTS.md", AGENTS_BLOCK),
269
+ # Claude Code reads CLAUDE.md, not AGENTS.md; importing keeps one source.
270
+ _upsert_block(directory / "CLAUDE.md", CLAUDE_BLOCK),
271
+ _copy_skill(directory / ".claude" / "skills" / SKILL, source, "Claude Code skill"),
272
+ _copy_skill(directory / ".agents" / "skills" / SKILL, source, "Codex skill"),
273
+ _write_mcp_json(directory / ".mcp.json", portable_mcp_command()),
274
+ ]
@@ -0,0 +1,298 @@
1
+ ---
2
+ name: odforge-design
3
+ description: 教外部 agent(Claude Code 等)用 ODForge 產出高品質簡報,並在網頁編輯器裡跟使用者來回修改(odforge edit 自動開網頁 + wait_for_feedback 回饋迴圈)。也涵蓋即時預覽(deck.json + odforge preview)、生成前訪談、page-role 大綱紀律、DesignSpec 設計欄位與對比度自檢、主題規格書,以及 MCP 的 inspect_odf + preview_odf 自查迴圈。當使用者要做簡報(尤其要 .odp/ODF 格式)、或要看/改既有的 .odp 時使用,即使他沒提到 ODForge。
4
+ ---
5
+
6
+ # odforge-design:用 ODForge 產出好簡報
7
+
8
+ ODForge 是一台**確定性渲染引擎**——你(agent)自己當內容作者,寫出 Document IR
9
+ (一個 JSON 物件)交給 MCP 工具,它渲染出原生 `.odp`/`.odt`/`.ods` 並驗證。
10
+ 引擎不會幫你想設計,好壞取決於你交出的 IR。這份 skill 教你交出好的 IR。
11
+
12
+ ## 首選工作流:做好、打開網頁、在網頁上來回修改
13
+
14
+ 使用者人在旁邊時一律走這條路。**互動在網頁裡發生,不在對話裡**:你開網頁給他,他在網頁上
15
+ 留言,你自動照著改。**絕對不要叫使用者打開 LibreOffice**——它只在背景當渲染器。
16
+
17
+ 1. **產出第一版**:照 ① 訪談、② 排大綱、③ 寫 IR,用 `forge_presentation` 輸出 `.odp`,
18
+ 用 `inspect_odf` 確認沒有跑版。(改既有檔案就跳過這步。)
19
+ 2. **網頁會自動打開**:`forge_presentation` 成功後會自己在使用者的瀏覽器打開 ODForge
20
+ 網頁編輯器,回傳結果裡有網址。(要看或改**既有**的 .odp 時,改呼叫 `open_editor(path)`。)
21
+ 不要另外叫使用者去開 LibreOffice 或任何程式。告訴使用者一句話就好:
22
+ 「網頁已經打開,可以直接拖、改字;想讓我改的地方用『留言』點出來,寫完按『交給 AI 修改』,
23
+ 全部滿意就按『完成』。」
24
+ 3. **在網頁的回饋迴圈裡等**:呼叫 `wait_for_feedback(path)`。
25
+ - 回 `feedback: ...`:逐則照留言改(`edit_odp`),**同一次呼叫裡**把處理好的留言用
26
+ `comment_delete` 刪掉(同一頁由大到小刪)。使用者在網頁上會即時看到你改。改完立刻再呼叫
27
+ `wait_for_feedback`。
28
+ - 回 `waiting: ...`:使用者還在看或還在寫,直接再呼叫一次,不要在對話裡催他。
29
+ - 回 `done: ...`:迴圈結束,用一兩句話回報這輪改了什麼。
30
+ 4. 做不到或需要使用者決定的留言不要刪;用 `comment_add` 在同一個物件回一則說明,網頁上看得到。
31
+
32
+ 使用者也可能在你等待的時候自己動手改;`edit_odp` 每次都是在最新的檔案上套用,不會蓋掉他的修改。
33
+
34
+ ### 另一條路:即時預覽(agent 寫 JSON)
35
+
36
+ 想從零反覆調整整份結構、頁數變動很大時,可以改寫一份 Presentation IR(`deck.json`),在背景執行
37
+ `odforge preview deck.json > /tmp/odforge-preview.log 2>&1 &`(也會自動開瀏覽器),之後每次存檔網頁就重新排版,
38
+ log 會印出每一版的跑版摘要。(shell 找不到 `odforge` 時——例如只裝了 Claude Code plugin——把指令換成
39
+ `uvx --from "odforge[web,cjk]" odforge preview ...`。)注意:這條路每次都從 JSON 重產 `.odp`,使用者在編輯器裡的手動修改
40
+ 會被蓋掉;結構定案後改用上面的流程。
41
+
42
+ 沒有人在看(批次產檔、使用者只要檔案)時,直接用下面的 MCP 工具即可。
43
+
44
+ ## MCP 工具(共 9 個)
45
+
46
+ | 工具 | 簽名 | 用途 |
47
+ | --- | --- | --- |
48
+ | `forge_presentation` | `(document: dict, out_path: str) -> str` | 渲染簡報 → `.odp` |
49
+ | `forge_text_document` | `(document: dict, out_path: str) -> str` | 渲染文件 → `.odt` |
50
+ | `forge_spreadsheet` | `(document: dict, out_path: str) -> str` | 渲染試算表 → `.ods` |
51
+ | `inspect_odf` | `(path: str) -> str` | 驗證既有 ODF 檔(結構/XML/soffice 三閘)|
52
+ | `preview_odf` | `(path: str, out_dir: str) -> str` | 每頁渲成 PNG,回傳路徑 JSON,供你**看圖**自查 |
53
+ | `outline_odp` | `(path: str) -> str` | 列出既有 .odp 每頁的元素代號、位置、文字 |
54
+ | `edit_odp` | `(path: str, ops: list) -> str` | 原地修改既有 .odp(改字、搬位置、增刪頁),不動其他內容 |
55
+ | `open_editor` | `(path: str) -> str` | 在使用者瀏覽器打開既有 .odp 的網頁編輯器(已開著就沿用) |
56
+ | `wait_for_feedback` | `(path: str, timeout_seconds: int = 50) -> str` | 等使用者在網頁上按「交給 AI 修改」,回傳那批留言;按「完成」時回 `done` |
57
+
58
+ 每個工具**只回字串、永不 raise**:失敗一律回 `"error: ..."`。呼叫後要讀回傳字串,
59
+ `"ok:"` 才算成功,`"error:"` 要修好再重來。
60
+
61
+ ---
62
+
63
+ ## ① 生成前訪談(先問,別急著產)
64
+
65
+ 動手前先跟使用者確認三件事。**不要套罐頭模板**——針對這個主題現想。
66
+ 使用者不在(或只丟一句話就要成品)時不要卡住:依下列預設直接做,交件時一句話說明你的假設。
67
+ 預設:10 分鐘 ≈ 10–13 頁;審查/報告類 → `report` 版式、`detailed` 密度;其他 → 依場合挑版式。
68
+
69
+ 1. **場合 → 版式(style)+配色(theme)**:先判斷場合,再挑一組構圖與配色。
70
+ 審查/計畫書/成果報告 → `passport`(白卡+右側深色重點面板,最接近正式審查簡報);
71
+ 顧問式匯報/議會 → `report`;口試/課堂 → `academic`;人文/設計 → `editorial`;
72
+ 演講/發表 → `keynote`(配暗底);品牌/作品集 → `zen`;一般教學 → `classic`。
73
+ 配色從 13 套內建主題挑最扣題的一套(④)。自訂 `design` 只在使用者有品牌色時才做,
74
+ 而且只換 accent——自調五色是生成簡報最常見的「看起來很業餘」來源。
75
+ 2. **頁數**:問清楚大概幾頁、時間多長。10 分鐘口頭簡報 ≈ 10–15 頁;別把一場演講塞
76
+ 進 40 頁。
77
+ 3. **mode 二分法**:`presenter`(講者型)還是 `detailed`(自讀型)?
78
+ - `presenter`:字少,但每條仍是完整觀點(≤20 字、每頁 ≤4 條)。
79
+ - `detailed`:文字完整,觀眾自己讀也懂(每條 15–40 字、每頁 3–6 條)。
80
+ 審查、提案、計畫書、報告這類「會被拿來讀、會被追問」的簡報一律用 `detailed`。
81
+ 注意:mode 是**你寫內容時的密度決定**,照上面的字數寫進 bullets/detail 即可,
82
+ **不必也不要寫進 IR**——`design` 一旦出現就必須帶完整的 palette 與 fonts。
83
+
84
+ 確認後再進大綱。
85
+
86
+ ---
87
+
88
+ ## ② page-role 大綱紀律(先排骨架,再填肉)
89
+
90
+ 先用版型(layout)排出整份簡報的節奏骨架,一頁一角色,再逐頁填內容。守這些規矩:
91
+
92
+ - **一頁一個想法,標題就是那個想法**:每頁 title 寫成一句完整結論(10–22 字),
93
+ 不是主題名詞。只讀標題就要能讀懂整份簡報(顧問業的 horizontal logic)。
94
+ - **`title` 開場**:第一頁一定是封面(`title` 版型)。
95
+ - **結構頁要省**:`agenda` 只在 ≥ 15 頁時放(項目不要自己編號,頁面會自動編);
96
+ `section` 分隔頁只在 ≥ 20 頁時用、最多 2 張(≥ 30 頁才可 3 張),並在 `kicker`
97
+ 寫「02 章節名」(classic/report/keynote/editorial/passport 的分隔頁大編號取自這裡;
98
+ academic 用上下夾線、zen 用小圓點,刻意不畫編號)。短簡報把章節名寫進該段第一頁的
99
+ `kicker`(「02 研究方法」)。目錄+分節+引言+大數字合計不超過全份約 18%;
100
+ big-fact 每 10 頁最多 1 張,quote 全份最多 1 張。
101
+ - **版面不要重複**:cards/process/timeline/metrics 任一種不超過全份約 1/5,
102
+ 其餘改用 table、chart、diagram、comparison。標題裡的數量(「三項」「五個建議」)
103
+ 必須等於該頁列出的項目數。以上工具都會以警告回報。
104
+ 一份 13 頁卻有 6 頁封面/目錄/分隔頁,是生成簡報看起來空洞的頭號原因。
105
+ - **優先用視覺版型**:步驟→`process`、時間→`timeline`、2–4 個數字→`metrics`、
106
+ 2–4 個並列觀點→`cards`、項目×屬性→`table`、數字+觀點→`dashboard`、
107
+ 架構/因果→`diagram`。`title-content` 整份最多 2 頁。
108
+ - **相鄰不同版型**:相鄰兩頁不用同一種 layout;同一 layout 不超過內容頁的三分之一。
109
+
110
+ ### 每張內容頁的四件套
111
+
112
+ 內容頁(title/section/closing/quote 以外)都要有:
113
+
114
+ - `kicker`:章節標籤,「兩位數編號+章節名」。
115
+ - `title`:一句結論。內頁一行約可放 24 字、封面約 17 字;超過會換行,
116
+ 多出一兩個字時引擎會自動微縮字級避免孤字。
117
+ - `subtitle`:標題下一行說明(15–40 字),交代脈絡或證據來源。
118
+ - `takeaway`:這頁的「所以呢」(≤30 字),畫成頁底結論帶(`passport` 是右側深色面板)。
119
+ **只放在真的有結論的頁**,約三分之一內容頁即可——每頁都放就不再有強調效果;
120
+ 而且要帶出標題沒說的新資訊(數字、影響、下一步),換句話重述標題的不如不放。
121
+
122
+ ### 實用字數(超過會縮字,再不行就以「…」截斷)
123
+
124
+ - cards(3 張並排):小標 ≤ 10 字,每句 children ≤ 22 字;4 張(2×2)可再長一些。
125
+ - process:4 步時每步 title ≤ 7 字、detail ≤ 18 字;5 步時 5 字 / 14 字。
126
+ - timeline:5 個事件時 title ≤ 6 字、detail ≤ 18 字;4 個時 8 字 / 24 字。
127
+ - metrics:value 含單位 ≤ 7 字(如「12,000」「≥ 90%」),label ≤ 10 字。
128
+ - chart:每個 label ≤ 5 字。diagram:節點 title ≤ 6 字、detail ≤ 10 字。table:≤ 5 欄,每格 ≤ 12 字。
129
+ - closing:每項 text ≤ 10 字(4 項時 ≤ 6 字),children 一句 ≤ 20 字。
130
+
131
+ 內容寫洞見而不是主題:「誤判率從 32% 降到 8%」勝過「降低誤判」。卡片、步驟、事件、
132
+ 指標的 `detail`/`children` 一律要填——只有小標的卡片就是「簡陋」的樣子。
133
+ - **`chart` 只配真數據**:有實際數字才用 chart,最多 8 條長條。沒有數據就別硬畫圖。
134
+ - **`closing` 收尾**:最後一頁用 closing(或 section)收束——結論/CTA/致謝/Q&A。
135
+
136
+ ### 19 種版型與必填欄位
137
+
138
+ | layout | 這頁的角色 | 必填/常用欄位 |
139
+ | --- | --- | --- |
140
+ | `title` | 封面 | `title`, `subtitle` |
141
+ | `cards` | 2–4 個並列觀點 | `bullets`:`{"text": 小標, "children": [1–2 句說明]}` |
142
+ | `process` | 步驟/方法 | `steps`:2–5 個 `{"title", "detail"}` |
143
+ | `timeline` | 時程/里程碑 | `events`:2–5 個 `{"label", "title", "detail"}` |
144
+ | `metrics` | 2–4 個關鍵數字 | `metrics`:`{"value", "label", "detail"}` |
145
+ | `dashboard` | 數字列+觀點卡 | `metrics`(2–4,detail 不會畫出)+ `bullets`(2–3 張卡,每張只放 1 條 ≤ 12 字的 children)|
146
+ | `table` | 項目 × 屬性比較 | `table`:`{"columns", "rows", "highlight"}`(≤6 列)|
147
+ | `comparison` | 對照(舊 vs 新)| `left`, `right`(各自第一項是欄標題)|
148
+ | `two-col` | 左右兩欄並列 | `left`, `right` |
149
+ | `diagram` | 架構/因果/層級 | `diagram`:`{"kind": "hub"\|"hierarchy", "nodes", "edges"}` |
150
+ | `chart` | 資料長條圖 | `chart`(必填 ChartSpec,真數據才用)|
151
+ | `big-fact` | 放大一個關鍵數字 | `title`(數字的意義), `fact`, `bullets`(一行註腳)|
152
+ | `quote` | 引述金句 | `quote`(必填非空), `attribution` |
153
+ | `image-focus` / `image-split` | 圖片為證據 | `image`(+ `bullets`)|
154
+ | `title-content` | 條列(整份最多 2 頁)| `bullets` |
155
+ | `agenda` | 議程(≥ 12 頁才用)| `bullets` |
156
+ | `section` | 章節分隔(≥ 20 頁才用)| `title`, `kicker`(「02 章節名」)|
157
+ | `closing` | 結尾 | `title`, `subtitle`, `bullets`(3–4 個下一步,含 children), `kicker`(選填,「結語」)|
158
+
159
+ ---
160
+
161
+ ## ③ IR 契約:把 document 寫對
162
+
163
+ ### Presentation(頂層)
164
+
165
+ ```json
166
+ {
167
+ "type": "presentation",
168
+ "title": "簡報標題",
169
+ "theme": "academic",
170
+ "design": { ... 見下方 DesignSpec,可省略 ... },
171
+ "style": "classic",
172
+ "branding": { "byline": "單位 · 講者 · 日期", "logo": "asset://logo",
173
+ "placement": "cover-closing" },
174
+ "slides": [ { ...Slide... }, ... ]
175
+ }
176
+ ```
177
+
178
+ - `theme`:`"academic"` | `"minimal"` | `"dark"` | `"teal"` | `"forest"` | `"navy"` |
179
+ `"violet"` | `"crimson"` | `"slate"` | `"gold"` | `"sky"` | `"plum"` | `"clay"`
180
+ (沒給 `design` 時就用這個內建主題;十三套的定位見 ④)。
181
+ - `style`:版式(構圖),與 `theme`/`design`(顏色)正交,可省略。每一套都照著一個
182
+ 公開慣例做:
183
+ `"classic"` 學院派(ODForge 原版:置中封面+點陣、標題左側色條、滿版分節頁)、
184
+ `"report"` 顧問報告(MBB 結構:左上 action title、標題下細線、頁尾出處與頁碼)、
185
+ `"academic"` 學術簡潔(Beamer metropolis:標題下 0.4pt 分隔線、底部進度條、
186
+ 分節頁上下夾線)、
187
+ `"keynote"` 舞台(滿版出血封面、文字錨在下三分之一、內頁只有大字)、
188
+ `"editorial"` 編輯風(Swiss:頂部通欄細線、粗標題橫貫中段、超大淡編號分節頁)、
189
+ `"zen"` 極簡(無線、無頁尾;標題落在上三分之一)。
190
+ 省略時使用該 `theme` 配對的預設版式。
191
+ - `slides`:至少 1 張。
192
+ - `branding`:封面署名與機構標誌,可省略。`byline` 原樣印在封面標題下方;
193
+ `logo` 只接受 `asset://<id>`(呼叫端上傳的圖),`placement` 是
194
+ `"cover"` | `"cover-closing"`(預設)| `"all"`。這是版面家具,不是投影片內容:
195
+ 不要把單位名稱或校徽再寫進任何一頁的 title / bullets。
196
+ - `forge_presentation` 會把 `type` 強制成 `"presentation"`,你標錯也會被更正。
197
+
198
+ ### Slide(每張投影片)
199
+
200
+ 欄位(依 layout 取用;用不到的留空即可):
201
+
202
+ - `layout`(必填,上表 19 選 1)
203
+ - `title`, `subtitle`, `fact`, `quote`, `attribution`, `kicker`(字串)
204
+ - `bullets`:字串陣列;也可以是巢狀 `{"text": "...", "children": ["...", ...]}`(一層)
205
+ - `left`, `right`:字串陣列(two-col/comparison 用)
206
+ - `chart`:ChartSpec(chart 版型必填)
207
+ - `notes`:講者備忘稿(任何版型都可加)
208
+
209
+ 交叉規則:`layout="chart"` 必須有 `chart`;`layout="quote"` 的 `quote` 必須非空。
210
+ 違反會回 `error:`。
211
+
212
+ ### ChartSpec(給 chart 版型)
213
+
214
+ ```json
215
+ { "labels": ["A","B","C"], "values": [10, 25, 40], "unit": "%", "highlight": 2 }
216
+ ```
217
+
218
+ - `labels` 與 `values` 等長,`values` 非負,最多 **8 條**(超過請拆成多張圖)。
219
+ - `highlight`(可省):要用強調色點亮的那條的索引(0 起算)。
220
+
221
+ ### DesignSpec(每份簡報客製設計,可省略)
222
+
223
+ 把 ① 訪談定案的美術方向落成 `design`。省略則用 `theme` 內建主題。
224
+
225
+ **配色心法(60-30-10)**:五個 palette token 就是一套 60-30-10——`bg` 是 60% 的底、
226
+ `surface`+`text`+`muted` 是 30% 的結構、`accent` 是那 10%(**全簡報唯一的彩色**,只點在
227
+ 一個關鍵字/標題底線/一條 highlight)。要自訂 palette、想懂配色配方與趨勢/色盲安全
228
+ 的圖表用色,讀 [themes/color-system.md](themes/color-system.md)。
229
+
230
+ ```json
231
+ "design": {
232
+ "palette": { "bg":"#RRGGBB", "surface":"#RRGGBB", "text":"#RRGGBB",
233
+ "muted":"#RRGGBB", "accent":"#RRGGBB" },
234
+ "fonts": { "display": "Noto Serif TC", "body": "Noto Sans TC" },
235
+ "scale": "standard",
236
+ "mode": "presenter"
237
+ }
238
+ ```
239
+
240
+ - `palette`:5 色,全部 `#RRGGBB` 六碼 hex。
241
+ - `fonts`:`display` 與 `body`,只能選 `FONT_WHITELIST` 內的
242
+ **Noto Sans TC / Noto Serif TC / 微軟正黑體 / 標楷體**(其他字型會被拒)。
243
+ - `scale`:`"compact"` | `"standard"` | `"display"`(字級密度,見主題規格書)。
244
+ - `mode`:`"presenter"` | `"detailed"`(① 的二分法;給下游提示,不改字級)。
245
+
246
+ ### 對比度自檢(palette 過不了就會被拒)
247
+
248
+ 調色盤送進去前,先自己算 WCAG 對比,全部要達標,否則 `forge_presentation` 回 `error:`:
249
+
250
+ - `text` / `bg` ≥ **4.5**
251
+ - `accent` / `bg` ≥ **3.0**
252
+ - `muted` / `bg` ≥ **3.0**
253
+
254
+ 暗底主題尤其容易踩雷:淺文字掉到中灰就糊。算不確定就把顏色再拉開一階。
255
+
256
+ ---
257
+
258
+ ## ④ 主題規格書(給 LLM 讀的鏡像)
259
+
260
+ 十三套內建美術方向的完整 hex 表、字級刻度、字型與每個版型的使用時機,寫在下面。
261
+ 九套淺底、四套暗底,挑最扣題的一套當 `theme`,或當自訂 `design` 的技術底:
262
+
263
+ - [themes/academic.md](themes/academic.md) — 學術藍+暖白,serif 標題,適合論文口試/研究報告。
264
+ - [themes/minimal.md](themes/minimal.md) — 暖灰單色+一點橘,克制留白,適合產品發表/pitch。
265
+ - [themes/teal.md](themes/teal.md) — 企業青綠(2026 年度色)+冷白,冷靜可信,適合企業/SaaS/ESG。
266
+ - [themes/forest.md](themes/forest.md) — 森綠+暖奶油,serif,editorial 質感,適合永續/生態/人文。
267
+ - [themes/navy.md](themes/navy.md) — 海軍藍+冷白,最通用的商務配色,適合正式簡報/投資人場。
268
+ - [themes/dark.md](themes/dark.md) — 深靛+亮青,暗底舞台感,適合技術分享/demo。
269
+ - [themes/violet.md](themes/violet.md) — 午夜紫+電光紫,暗底創意戲劇感,適合創意提案/設計敘事。
270
+ - [themes/crimson.md](themes/crimson.md) — 學院紅+暖白,serif,典禮與人文重量,適合校慶/系所評鑑。
271
+ - [themes/slate.md](themes/slate.md) — 石墨灰+柔和冷藍,暗底不刺眼,適合工程/資安/長時間技術場。
272
+ - [themes/gold.md](themes/gold.md) — 墨金,暗底最正式的一套,適合頒獎/成果發表/年度回顧。
273
+ - [themes/sky.md](themes/sky.md) — 天青+冷白,溫和好認,適合課堂教學/招生說明/公部門宣導。
274
+ - [themes/plum.md](themes/plum.md) — 梅紫+米白,serif,淺底最有個性,適合藝文/設計提案/展覽。
275
+ - [themes/clay.md](themes/clay.md) — 陶土橘+米色,土地與手作感,適合永續/地方創生/社區營造。
276
+
277
+ 配色方法論(60-30-10、配色配方、趨勢與色盲安全的圖表用色)另寫在
278
+ [themes/color-system.md](themes/color-system.md)。這些數值與 `odforge.themes.THEMES` /
279
+ `SCALES` 常數 lockstep(有測試防漂移)。要客製 `design` 時,可拿最接近的一套當技術底,
280
+ 再微調 palette。
281
+
282
+ ---
283
+
284
+ ## ⑤ 產出後必做:inspect_odf + preview_odf 自查迴圈
285
+
286
+ `forge_*` 回 `"ok:"` 只代表檔案結構有效,**不代表版面好看**。產完一定要兩步自查:
287
+
288
+ 1. **`inspect_odf(path)`**:確認結構/XML(有裝 LibreOffice 時還會跑 soffice 往返)
289
+ 全部 OK。任何 FAIL 都要修。
290
+ 2. **`preview_odf(path, out_dir)`**:把每頁渲成 PNG。成功回
291
+ `{"pages": [...png 路徑...], "count": N}`(JSON 字串,`json.loads` 後拿路徑)。
292
+ **實際把 PNG 讀進來看**:有沒有文字溢出、標題撞邊、條列爆框、對比不足、
293
+ 同版型連發太單調?看到問題就回去改 IR,重 forge、重 preview,直到畫面過關。
294
+ (若回 `"error: preview unavailable: ..."` 表示這台沒裝 LibreOffice,跳過視覺步驟,
295
+ 但仍以 `inspect_odf` 把關結構。)
296
+
297
+ 沒跑過 preview_odf 就交件,等於沒看過自己的簡報長怎樣。這一步是把 QA harness 的
298
+ 「看圖」能力交到你手上——用它。
@@ -0,0 +1,52 @@
1
+ # academic — 學術藍 + 暖白
2
+
3
+ 給 LLM 讀的規格書。這些數值是 `odforge.themes.THEMES["academic"]` 與
4
+ `SCALES["standard"]` 的鏡像,兩者以測試 lockstep 綁定,改一邊必須改另一邊。
5
+
6
+ **定位**:學術藍配暖白底、serif 標題撐場面。適合論文口試、研究報告、教學講義、
7
+ 政府與學會場合——任何需要沉穩、可信、耐讀氣質的簡報。
8
+
9
+ ## 調色盤(hex)
10
+
11
+ | token | hex | 說明 |
12
+ | --- | --- | --- |
13
+ | bg | #FBF9F4 | 頁面背景:暖白,不刺眼、久看不累 |
14
+ | surface | #EFEADD | 卡片/色塊底:比 bg 深一階的米色 |
15
+ | text | #1F2733 | 主要內文:近黑的深藍灰 |
16
+ | muted | #5B6470 | 次要文字:註解、attribution、caption |
17
+ | accent | #1A4B8C | 強調色:學術藍,用在標題底線、highlight 長條、關鍵字 |
18
+ | title_color | #1F2733 | 標題色:與 text 同(此主題不另外覆寫)|
19
+
20
+ 對比:text/bg、accent/bg、muted/bg 皆已通過 WCAG 門檻
21
+ (text/bg ≥ 4.5、accent/bg ≥ 3.0、muted/bg ≥ 3.0)。若你另外覆寫 DesignSpec
22
+ 調色盤,務必自行重算對比。
23
+
24
+ ## 字級刻度(pt,standard 密度)
25
+
26
+ | role | pt | 用途 |
27
+ | --- | --- | --- |
28
+ | display | 54 | 封面主標、big-fact 數字 |
29
+ | h1 | 28 | 內頁標題、section 分隔標題 |
30
+ | body | 18 | 條列與內文 |
31
+ | caption | 13 | 註解、資料來源、attribution |
32
+
33
+ ## 字型
34
+
35
+ - 標題(display):**Noto Serif TC** — serif 帶來學術份量。
36
+ - 內文(body):**Noto Sans TC** — sans 保持條列清爽好讀。
37
+ - 皆在 `FONT_WHITELIST` 內,CJK 覆蓋完整。
38
+
39
+ ## 各版型使用時機
40
+
41
+ | 版型 | 使用時機 |
42
+ | --- | --- |
43
+ | title | 封面:研究題目 + 作者/單位。serif 大標最能定調 |
44
+ | agenda | 大綱頁:口試/長報告開場,先給評審一張路線圖 |
45
+ | title-content | 主力內頁:研究背景、方法、每一條列即一個論點 |
46
+ | section | 章節分隔:進入「文獻回顧」「研究設計」等大段落時 |
47
+ | two-col | 並列說明:假設 vs 觀察、理論 vs 資料 |
48
+ | comparison | 對照表態:本研究 vs 既有做法,左右各一欄優劣 |
49
+ | big-fact | 關鍵數據:把核心發現放大成一個數字(如樣本數、顯著性)|
50
+ | quote | 引述:引用文獻原句或受訪者原話,attribution 標出處 |
51
+ | chart | 圖表:**只有真實數據**才用,最多 8 條長條,右欄放洞見 |
52
+ | closing | 結尾:結論一句話 + 致謝/Q&A |