@namewta/skills-hub 0.1.49 → 0.1.52

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 (254) hide show
  1. package/README.md +4 -1
  2. package/THIRD_PARTY_NOTICES.md +19 -7
  3. package/cli.mjs +2 -2
  4. package/install.mjs +11 -4
  5. package/package.json +1 -1
  6. package/scripts/persistence/home.md +1 -1
  7. package/skills/dev/dev-build/SKILL.md +2 -0
  8. package/skills/dev/dev-build/references/implement-request.md +7 -2
  9. package/skills/dev/dev-formal-verify/SKILL.md +2 -1
  10. package/skills/dev/dev-formal-verify/references/create-check.md +3 -1
  11. package/skills/dev/dev-formal-verify/references/example.md +1 -1
  12. package/skills/dev/dev-formal-verify/references/tool-choice.md +1 -1
  13. package/skills/dev/dev-help/references/capabilities.md +6 -6
  14. package/skills/dev/dev-help/references/guide-verification.md +7 -1
  15. package/skills/dev/dev-help/references/help-method.md +7 -1
  16. package/skills/dev/dev-issue/SKILL.md +1 -0
  17. package/skills/dev/dev-issue/references/github-operations.md +8 -0
  18. package/skills/dev/dev-plan/references/plan-template.md +1 -0
  19. package/skills/dev/dev-plan/references/vertical-slicing.md +2 -0
  20. package/skills/dev/dev-pr/references/pull-request-evidence.md +2 -0
  21. package/skills/dev/dev-review/references/host-parity.md +12 -0
  22. package/skills/dev/dev-review/references/review-baseline.md +2 -0
  23. package/skills/dev/dev-setup/references/formal-options.md +1 -1
  24. package/skills/dev/dev-statechart/SKILL.md +17 -19
  25. package/skills/dev/dev-statechart/agents/openai.yaml +3 -3
  26. package/skills/dev/dev-statechart/assets/theme.css +135 -0
  27. package/skills/dev/dev-statechart/references/lean-proof.md +47 -0
  28. package/skills/dev/dev-statechart/references/render.md +15 -83
  29. package/skills/dev/dev-statechart/references/runtime.md +21 -1
  30. package/skills/dev/dev-statechart/scripts/lean/backends/lemma-chart.mjs +285 -0
  31. package/skills/dev/dev-statechart/scripts/lean/backends/mermaid.mjs +174 -0
  32. package/skills/dev/dev-statechart/scripts/lean/backends/proof-chart.mjs +540 -0
  33. package/skills/dev/dev-statechart/scripts/lean/backends/report.mjs +242 -0
  34. package/skills/dev/dev-statechart/scripts/lean/frontends/facts.mjs +234 -0
  35. package/skills/dev/dev-statechart/scripts/lean/frontends/view.mjs +217 -0
  36. package/skills/dev/dev-statechart/scripts/lean/ir.mjs +226 -0
  37. package/skills/dev/dev-statechart/scripts/lean/passes/attribute.mjs +148 -0
  38. package/skills/dev/dev-statechart/scripts/lean/passes/blocks.mjs +32 -0
  39. package/skills/dev/dev-statechart/scripts/lean/passes/budget.mjs +167 -0
  40. package/skills/dev/dev-statechart/scripts/lean/passes/check.mjs +70 -0
  41. package/skills/dev/dev-statechart/scripts/lean/passes/contract.mjs +160 -0
  42. package/skills/dev/dev-statechart/scripts/lean/passes/fold.mjs +206 -0
  43. package/skills/dev/dev-statechart/scripts/lean/passes/inline.mjs +84 -0
  44. package/skills/dev/dev-statechart/scripts/lean/passes/mark.mjs +432 -0
  45. package/skills/dev/dev-statechart/scripts/lean/passes/reduce.mjs +73 -0
  46. package/skills/dev/dev-statechart/scripts/lean/passes/trust.mjs +111 -0
  47. package/skills/dev/dev-statechart/scripts/lean/passes/view-lemmas.mjs +155 -0
  48. package/skills/dev/dev-statechart/scripts/lean/pipeline.mjs +164 -0
  49. package/skills/dev/dev-statechart/scripts/lean/run.mjs +168 -0
  50. package/skills/dev/dev-statechart/scripts/statechart.mjs +42 -23
  51. package/skills/dev/dev-statechart/scripts/worker.mjs +33 -7
  52. package/skills/dev/dev-ui-design/SKILL.md +2 -2
  53. package/skills/dev/dev-ui-design/references/interaction-review.md +9 -0
  54. package/skills/dev/dev-verify/SKILL.md +1 -1
  55. package/skills/dev/dev-verify/references/evidence-storage.md +12 -0
  56. package/skills/dev/dev-workflow/SKILL.md +6 -6
  57. package/skills/dev/dev-workflow/references/method-handoffs.md +7 -1
  58. package/skills/dev/dev-writing/SKILL.md +2 -0
  59. package/skills/dev/dev-writing/references/library-docs.md +37 -0
  60. package/skills/home/home-doctor/references/diagnosis.md +2 -2
  61. package/skills/home/home-doctor/scripts/doctor.mjs +68 -38
  62. package/skills/home/home-project-changelog/SKILL.md +7 -7
  63. package/skills/home/home-project-changelog/assets/project-changelog.example.json +188 -0
  64. package/skills/home/home-project-changelog/assets/project-changelog.schema.json +156 -0
  65. package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
  66. package/skills/home/home-project-changelog/references/git-ranges.md +2 -2
  67. package/skills/home/home-project-changelog/references/schema.md +61 -0
  68. package/skills/home/home-project-changelog/references/tools.md +28 -22
  69. package/skills/home/home-project-changelog/references/workflow.md +12 -9
  70. package/skills/home/home-project-changelog/references/writing.md +5 -3
  71. package/skills/home/home-project-changelog/scripts/changelog.mjs +42 -38
  72. package/skills/home/home-project-changelog/scripts/contract.mjs +40 -3
  73. package/skills/home/home-project-changelog/scripts/legacy-markdown.mjs +116 -0
  74. package/skills/home/home-project-changelog/scripts/migrate.mjs +122 -0
  75. package/skills/home/home-project-changelog/scripts/revision.mjs +2 -196
  76. package/skills/home/home-project-changelog/scripts/storage.mjs +120 -125
  77. package/skills/home/home-project-changelog/scripts/summary.mjs +0 -60
  78. package/skills/home/home-route/SKILL.md +2 -2
  79. package/skills/home/home-route/references/routing.md +3 -1
  80. package/skills/home/home-route/scripts/route.mjs +79 -11
  81. package/skills/home/home-setup/SKILL.md +2 -1
  82. package/skills/home/home-setup/assets/repos.schema.json +10 -0
  83. package/skills/home/home-setup/references/registry.md +18 -1
  84. package/skills/home/home-setup/scripts/registry.mjs +67 -7
  85. package/skills/home/home-website/SKILL.md +13 -9
  86. package/skills/home/home-website/assets/website/scripts/inputs.mjs +143 -128
  87. package/skills/home/home-website/assets/website/scripts/render.mjs +8 -6
  88. package/skills/home/home-website/assets/website/scripts/site.mjs +21 -10
  89. package/skills/home/home-website/assets/website/site/public/home-assets/app.js +81 -34
  90. package/skills/home/home-website/assets/website/site/public/home-assets/site.css +92 -70
  91. package/skills/home/home-website/assets/website/site/templates/favicon.png +0 -0
  92. package/skills/home/home-website/assets/website/site/templates/layout.mjs +13 -10
  93. package/skills/home/home-website/assets/website/site/templates/ledger.mjs +51 -46
  94. package/skills/home/home-website/assets/website/site/templates/model.mjs +58 -14
  95. package/skills/home/home-website/assets/website/site/templates/pages.mjs +28 -30
  96. package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +3 -107
  97. package/skills/home/home-website/assets/website/site.config.json +1 -1
  98. package/skills/home/home-website/references/website.md +64 -46
  99. package/skills/home/home-website/scripts/activate.mjs +106 -0
  100. package/skills/home/home-website/scripts/init.mjs +98 -11
  101. package/skills/home/home-workflow/SKILL.md +6 -4
  102. package/skills/system/system-clash-proxy-config/SKILL.md +21 -0
  103. package/skills/system/system-clash-proxy-config/agents/openai.yaml +4 -0
  104. package/skills/system/system-clash-proxy-config/assets/clash-override.js +328 -0
  105. package/skills/system/{system-proxy → system-clash-proxy-config}/references/browser-privacy.md +2 -2
  106. package/skills/system/{system-config → system-clash-proxy-config}/references/changes.md +2 -2
  107. package/skills/system/{system-proxy → system-clash-proxy-config}/references/clash-verge.md +1 -1
  108. package/skills/system/{system-proxy → system-clash-proxy-config}/references/diagnosis.md +1 -1
  109. package/skills/system/system-clash-proxy-config/references/dns-workflow.md +42 -0
  110. package/skills/system/system-clash-proxy-config/references/egress-macos.md +31 -0
  111. package/skills/system/system-clash-proxy-config/references/egress-windows.md +37 -0
  112. package/skills/system/system-clash-proxy-config/references/egress.md +12 -0
  113. package/skills/system/{system-proxy → system-clash-proxy-config}/references/flclash.md +1 -1
  114. package/skills/system/{system-proxy → system-clash-proxy-config}/references/index.md +1 -1
  115. package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/linux-cutover.md +29 -0
  116. package/skills/system/system-clash-proxy-config/references/locale-workflow.md +9 -0
  117. package/skills/system/{system-proxy → system-clash-proxy-config}/references/mihomo.md +1 -25
  118. package/skills/system/system-clash-proxy-config/references/session.md +34 -0
  119. package/skills/system/system-clash-proxy-config/references/subscription.md +29 -0
  120. package/skills/system/{system-proxy → system-clash-proxy-config}/references/troubleshooting.md +7 -7
  121. package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/verification.md +2 -0
  122. package/skills/system/system-clash-proxy-config/scripts/prepare-session.mjs +155 -0
  123. package/skills/system/system-clash-proxy-config/scripts/run-session.mjs +138 -0
  124. package/skills/system/system-inspect/SKILL.md +1 -1
  125. package/skills/system/system-inspect/references/health-audit.md +1 -1
  126. package/upstream-skills/zh-archify/SKILL.md +11 -11
  127. package/upstream-skills/zh-archify/assets/template.html +6 -3
  128. package/upstream-skills/zh-archify/bin/archify.mjs +67 -4
  129. package/upstream-skills/zh-archify/modules/code-analysis/ARCHITECTURE.md +7 -1
  130. package/upstream-skills/zh-archify/modules/code-analysis/bin/analyze-run.mjs +2 -1
  131. package/upstream-skills/zh-archify/modules/code-analysis/bin/check.mjs +29 -15
  132. package/upstream-skills/zh-archify/modules/code-analysis/bin/drift.mjs +3 -3
  133. package/upstream-skills/zh-archify/modules/code-analysis/bin/prepare.mjs +5 -6
  134. package/upstream-skills/zh-archify/modules/code-analysis/bin/serve.mjs +66 -36
  135. package/upstream-skills/zh-archify/modules/code-analysis/bin/verify-change.mjs +43 -13
  136. package/upstream-skills/zh-archify/modules/code-analysis/docs/TECH-GUIDE.md +1 -1
  137. package/upstream-skills/zh-archify/modules/code-analysis/docs/USAGE.md +37 -4
  138. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/functions.mjs +7 -5
  139. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/index.mjs +4 -1
  140. package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/snapshot-host.mjs +9 -0
  141. package/upstream-skills/zh-archify/modules/code-analysis/lib/architecture-drift.mjs +28 -7
  142. package/upstream-skills/zh-archify/modules/code-analysis/lib/drift-capture.mjs +4 -3
  143. package/upstream-skills/zh-archify/modules/code-analysis/lib/git-sources.mjs +5 -3
  144. package/upstream-skills/zh-archify/modules/code-analysis/lib/output.mjs +272 -0
  145. package/upstream-skills/zh-archify/modules/code-analysis/lib/pull-request.mjs +34 -4
  146. package/upstream-skills/zh-archify/modules/code-analysis/lib/task.mjs +4 -2
  147. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-context.mjs +13 -1
  148. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-history.mjs +112 -0
  149. package/upstream-skills/zh-archify/modules/code-analysis/lib/verification.mjs +6 -2
  150. package/upstream-skills/zh-archify/modules/code-analysis/overlay/atlas.mjs +71 -5
  151. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.css +16 -2
  152. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.js +121 -5
  153. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas3d.js +38 -1
  154. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.css +14 -1
  155. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.js +187 -27
  156. package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/verification.js +1 -1
  157. package/upstream-skills/zh-archify/modules/code-analysis/overlay/i18n.mjs +9 -0
  158. package/upstream-skills/zh-archify/modules/code-analysis/overlay/inject.mjs +1 -1
  159. package/upstream-skills/zh-archify/modules/code-analysis/overlay/page.mjs +11 -6
  160. package/upstream-skills/zh-archify/modules/code-analysis/overlay/pull-request.mjs +1 -1
  161. package/upstream-skills/zh-archify/modules/code-analysis/schemas/ai-task.schema.json +1 -0
  162. package/upstream-skills/zh-archify/modules/code-analysis/test/atlas.test.mjs +88 -0
  163. package/upstream-skills/zh-archify/modules/code-analysis/test/duplicates.test.mjs +1 -1
  164. package/upstream-skills/zh-archify/modules/code-analysis/test/external-workflow.test.mjs +1 -1
  165. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.json +1 -0
  166. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.missing.json +1 -0
  167. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.json +1 -0
  168. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.valid.json +1 -0
  169. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.changed.json +1 -0
  170. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.json +1 -0
  171. package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/module-cycle.task.json +1 -0
  172. package/upstream-skills/zh-archify/modules/code-analysis/test/function-source-range.test.mjs +10 -0
  173. package/upstream-skills/zh-archify/modules/code-analysis/test/output-recovery.test.mjs +626 -0
  174. package/upstream-skills/zh-archify/modules/code-analysis/test/pull-request.test.mjs +98 -2
  175. package/upstream-skills/zh-archify/modules/code-analysis/test/review.test.mjs +37 -0
  176. package/upstream-skills/zh-archify/modules/code-analysis/test/source-panel.test.mjs +2 -1
  177. package/upstream-skills/zh-archify/modules/code-analysis/test/task.test.mjs +3 -2
  178. package/upstream-skills/zh-archify/modules/code-analysis/test/verification-history.test.mjs +216 -0
  179. package/upstream-skills/zh-archify/modules/code-analysis/test/verification.test.mjs +122 -0
  180. package/upstream-skills/zh-archify/package-lock.json +2 -2
  181. package/upstream-skills/zh-archify/package.json +1 -1
  182. package/upstream-skills/zh-archify/references/authoring-contract.md +2 -0
  183. package/upstream-skills/zh-archify/references/explainer-authoring.md +1 -1
  184. package/upstream-skills/zh-archify/renderers/architecture/render-architecture.mjs +1 -0
  185. package/upstream-skills/zh-archify/renderers/class/render-class.mjs +1 -0
  186. package/upstream-skills/zh-archify/renderers/dataflow/render-dataflow.mjs +2 -1
  187. package/upstream-skills/zh-archify/renderers/erd/render-erd.mjs +1 -0
  188. package/upstream-skills/zh-archify/renderers/lifecycle/render-lifecycle.mjs +4 -2
  189. package/upstream-skills/zh-archify/renderers/sequence/render-sequence.mjs +4 -2
  190. package/upstream-skills/zh-archify/renderers/shared/cli.mjs +7 -1
  191. package/upstream-skills/zh-archify/renderers/timeline/render-timeline.mjs +1 -0
  192. package/upstream-skills/zh-archify/renderers/tree/render-tree.mjs +1 -0
  193. package/upstream-skills/zh-archify/renderers/waterfall/render-waterfall.mjs +1 -0
  194. package/upstream-skills/zh-archify/renderers/workflow/render-workflow.mjs +3 -2
  195. package/upstream-skills/zh-archify/renderers/workflow/workflow-compiler.mjs +68 -7
  196. package/upstream-skills/zh-archify/skill-release.json +1 -1
  197. package/upstream-skills/zh-modern-web-guidance/SKILL.md +4 -11
  198. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-detection.md +20 -0
  199. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-model.md +22 -0
  200. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/prompt-api.md +22 -0
  201. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/summarizer.md +20 -0
  202. package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/translator.md +22 -0
  203. package/upstream-skills/zh-modern-web-guidance/guides/performance/custom-ml-model-inference.md +342 -0
  204. package/upstream-skills/zh-modern-web-guidance/guides/performance/data-parallel-computation.md +337 -0
  205. package/upstream-skills/zh-modern-web-guidance/guides/performance/improve-next-page-load-performance.md +4 -1
  206. package/upstream-skills/zh-modern-web-guidance/guides/performance/large-scene-rendering.md +350 -0
  207. package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/position-aware-tooltips.md +9 -0
  208. package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/viewport-aware-dropdowns.md +9 -0
  209. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/animate-to-from-top-layer.md +9 -0
  210. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/declarative-dialog-popover-control.md +9 -0
  211. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/interest-triggered-tooltips.md +9 -0
  212. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/scroll-target-on-load.md +29 -0
  213. package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/sortable-table.md +1 -0
  214. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/app-menus.md +9 -0
  215. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/context-menu.md +9 -0
  216. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/copy-button.md +9 -0
  217. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/dialog.md +10 -1
  218. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/hovercard.md +9 -0
  219. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/menu.md +9 -0
  220. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/navbar.md +9 -0
  221. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-app-tours.md +9 -0
  222. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-toast-notifications.md +9 -0
  223. package/upstream-skills/zh-modern-web-guidance/guides/ui-components/toolbar.md +9 -0
  224. package/upstream-skills/zh-modern-web-guidance/guides/user-experience/content-first-noise-reduction.md +9 -0
  225. package/upstream-skills/zh-modern-web-guidance/guides/user-experience/natural-interactions.md +9 -0
  226. package/upstream-skills/zh-modern-web-guidance/guides/webmcp/agentic-javascript-tools.md +27 -0
  227. package/skills/home/home-project-changelog/assets/project-changelog.md +0 -35
  228. package/skills/system/system-clash-tun-egress/SKILL.md +0 -22
  229. package/skills/system/system-clash-tun-egress/agents/openai.yaml +0 -4
  230. package/skills/system/system-config/SKILL.md +0 -37
  231. package/skills/system/system-config/agents/openai.yaml +0 -4
  232. package/skills/system/system-config/references/ai-cli-config.md +0 -75
  233. package/skills/system/system-config/references/ai-cli-optimization.md +0 -37
  234. package/skills/system/system-config/references/index.md +0 -12
  235. package/skills/system/system-config/references/locale-workflow.md +0 -33
  236. package/skills/system/system-config/references/locale.md +0 -50
  237. package/skills/system/system-proxy/SKILL.md +0 -40
  238. package/skills/system/system-proxy/agents/openai.yaml +0 -4
  239. package/skills/system/system-proxy/assets/protected-rules.yaml +0 -7
  240. package/skills/system/system-proxy/references/dns-workflow.md +0 -152
  241. /package/skills/system/{system-config → system-clash-proxy-config}/assets/configuration.md +0 -0
  242. /package/skills/system/{system-proxy → system-clash-proxy-config}/assets/network.md +0 -0
  243. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/acceptance.md +0 -0
  244. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-fields.md +0 -0
  245. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-misconceptions.md +0 -0
  246. /package/skills/system/{system-clash-tun-egress/references/troubleshooting.md → system-clash-proxy-config/references/egress-troubleshooting.md} +0 -0
  247. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-linux.md +0 -0
  248. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-macos.md +0 -0
  249. /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-windows.md +0 -0
  250. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/network-performance.md +0 -0
  251. /package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/nodes-and-dns.md +0 -0
  252. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platform-dns.md +0 -0
  253. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platforms.md +0 -0
  254. /package/skills/system/{system-proxy → system-clash-proxy-config}/references/tun-dns.md +0 -0
@@ -0,0 +1,174 @@
1
+ const SAFE_ASCII = /^[A-Za-z0-9 !'()+,\-./=?[\]{}:;_]$/;
2
+ const LEAN_MATH = /^[⊢∀∃∈∉∧∨¬→↔←≤≥≠⟨⟩·▸×…′─]$/;
3
+ const GREEK = /^[\u0391-\u03A9\u03B1-\u03C9]$/;
4
+ const SUB_SUPER =
5
+ /^[\u2080-\u208E\u2090-\u209C\u1D62-\u1D6A\u2070\u00B9\u00B2\u00B3\u2074-\u2079]$/;
6
+ const WHITE = /\p{White_Space}/u;
7
+ const PLACEHOLDER = /[fl°¶ß]/;
8
+ const isControl = (code) => code <= 0x1f || (code >= 0x7f && code <= 0x9f);
9
+ const DIRECTION = /(direction)\s+(?=LR|RL|TB|BT|TD)/gi;
10
+ const C4 = /C4(?=Container|Component|Dynamic|Deployment)/g;
11
+ function isSafeChar(ch) {
12
+ if (PLACEHOLDER.test(ch)) return false;
13
+ return (
14
+ SAFE_ASCII.test(ch) ||
15
+ LEAN_MATH.test(ch) ||
16
+ GREEK.test(ch) ||
17
+ /^\p{Script=Han}$/u.test(ch) ||
18
+ SUB_SUPER.test(ch)
19
+ );
20
+ }
21
+ export function encodeText(text) {
22
+ let out = "";
23
+ for (let i = 0; i < text.length; ) {
24
+ const code = text.codePointAt(i);
25
+ const width = code > 0xffff ? 2 : 1;
26
+ i += width;
27
+ if (code >= 0xd800 && code <= 0xdfff) {
28
+ out += "#65533;";
29
+ continue;
30
+ }
31
+ const ch = String.fromCodePoint(code);
32
+ if (ch === " ") {
33
+ out += " ";
34
+ } else if (WHITE.test(ch)) {
35
+ out += " ";
36
+ } else if (isControl(code)) {
37
+ continue;
38
+ } else if (isSafeChar(ch)) {
39
+ out += ch;
40
+ } else {
41
+ out += `#${code};`;
42
+ }
43
+ }
44
+ const normalized = out.replace(/ +/g, " ").trim();
45
+ if (!normalized) return "#32;";
46
+ return normalized
47
+ .replace(/\[(?=\[)/g, "#91;")
48
+ .replace(/\](?=\])/g, "#93;")
49
+ .replace(/-(?=-)/g, "#45;")
50
+ .replace(DIRECTION, "$1#32;")
51
+ .replace(C4, "C#52;");
52
+ }
53
+ export function encodeLines(lines) {
54
+ const encoded = lines.map(encodeText).filter((line) => line.length > 0);
55
+ if (encoded.length === 0) return "#32;";
56
+ return encoded.join("<br/>");
57
+ }
58
+ function encodeTitle(title) {
59
+ let out = "";
60
+ for (let i = 0; i < title.length; ) {
61
+ const code = title.codePointAt(i);
62
+ const width = code > 0xffff ? 2 : 1;
63
+ i += width;
64
+ if (code >= 0xd800 && code <= 0xdfff) continue;
65
+ const ch = String.fromCodePoint(code);
66
+ if (WHITE.test(ch)) out += " ";
67
+ else if (isControl(code) || PLACEHOLDER.test(ch)) continue;
68
+ else if (
69
+ ch === "<" ||
70
+ ch === ">" ||
71
+ ch === "&" ||
72
+ ch === '"' ||
73
+ ch === "\\"
74
+ )
75
+ out += " ";
76
+ else out += ch;
77
+ }
78
+ return out.replace(/ +/g, " ").trim();
79
+ }
80
+ function nodeDecl(node) {
81
+ const label = `"${encodeLines(node.lines)}"`;
82
+ const shape = node.shape;
83
+ switch (shape) {
84
+ case "box":
85
+ return `${node.id}[${label}]`;
86
+ case "round":
87
+ return `${node.id}(${label})`;
88
+ case "hexagon":
89
+ return `${node.id}{{${label}}}`;
90
+ case "circle":
91
+ return `${node.id}((${label}))`;
92
+ case "stub":
93
+ return `${node.id}([${label}])`;
94
+ default: {
95
+ const _exhaustive = shape;
96
+ return _exhaustive;
97
+ }
98
+ }
99
+ }
100
+ function edgeDecl(edge) {
101
+ const arrow = edge.thick ? "==>" : edge.dotted ? "-.->" : "-->";
102
+ if (edge.label === undefined) return `${edge.from} ${arrow} ${edge.to}`;
103
+ return `${edge.from} ${arrow}|"${encodeText(edge.label)}"| ${edge.to}`;
104
+ }
105
+ const CLASS_STYLES = {
106
+ target: "fill:#e8f2ff,stroke:#1680f3,stroke-width:2.5px,color:#0d4ea6",
107
+ goalRoot: "fill:#e8f2ff,stroke:#1680f3,stroke-width:2px,color:#0d4ea6",
108
+ subRoot: "fill:#eef2ff,stroke:#6366f1,stroke-width:2px,color:#3730a3",
109
+ termRoot: "fill:#f0fdfa,stroke:#0d9488,stroke-width:2px,color:#115e59",
110
+ closed: "fill:#e9f7ef,stroke:#229954,stroke-width:1.5px,color:#145a32",
111
+ sorry: "fill:#ffecee,stroke:#e72e3b,stroke-width:2.5px,color:#cd2834",
112
+ error: "fill:#ffecee,stroke:#e72e3b,stroke-width:2.5px,color:#cd2834",
113
+ open: "fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06",
114
+ axiom: "fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06",
115
+ native: "fill:#ffecee,stroke:#e72e3b,stroke-width:2.5px,color:#cd2834",
116
+ restsOn: "fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06",
117
+ doubtPath: "stroke:#e72e3b,stroke-width:2.5px",
118
+ folded: "fill:#f3ecff,stroke:#8b5cf6,stroke-width:1.5px,color:#5b21b6",
119
+ stub: "fill:#f4f4f5,stroke:#71717a,stroke-width:1.5px,stroke-dasharray:5 3,color:#52525b",
120
+ note: "fill:#fafafa,stroke:#d4d4d8,stroke-width:1px,color:#52525b",
121
+ };
122
+ export function renderFlowLines(flow) {
123
+ const lines = [];
124
+ if (flow.title) {
125
+ const safeTitle = encodeTitle(flow.title);
126
+ if (safeTitle)
127
+ lines.push("---", `title: ${JSON.stringify(safeTitle)}`, "---");
128
+ }
129
+ lines.push("flowchart TD");
130
+ const grouped = new Set();
131
+ const nodeById = new Map();
132
+ for (const node of flow.nodes) nodeById.set(node.id, node);
133
+ for (const [i, group] of flow.groups.entries()) {
134
+ const members = group.nodes.filter(
135
+ (id) => nodeById.has(id) && !grouped.has(id),
136
+ );
137
+ if (members.length === 0) continue;
138
+ lines.push(` subgraph g${i} ["${encodeText(group.title)}"]`);
139
+ for (const id of members) {
140
+ grouped.add(id);
141
+ lines.push(` ${nodeDecl(nodeById.get(id))}`);
142
+ }
143
+ lines.push(" end");
144
+ }
145
+ for (const node of flow.nodes) {
146
+ if (!grouped.has(node.id)) lines.push(` ${nodeDecl(node)}`);
147
+ }
148
+ for (const edge of flow.edges) lines.push(` ${edgeDecl(edge)}`);
149
+ const usedClasses = new Set();
150
+ const classAssignments = [];
151
+ for (const node of flow.nodes) {
152
+ for (const cls of node.classes) {
153
+ usedClasses.add(cls);
154
+ classAssignments.push(` class ${node.id} ${cls}`);
155
+ }
156
+ }
157
+ if (flow.legend.length > 0) {
158
+ lines.push(` subgraph lg ["图例"]`);
159
+ for (const [i, entry] of flow.legend.entries()) {
160
+ const lid = `lg${i}`;
161
+ lines.push(` ${lid}["${encodeText(entry.text)}"]`);
162
+ usedClasses.add(entry.cls);
163
+ classAssignments.push(` class ${lid} ${entry.cls}`);
164
+ }
165
+ lines.push(" end");
166
+ }
167
+ for (const cls of Object.keys(CLASS_STYLES)) {
168
+ if (usedClasses.has(cls))
169
+ lines.push(` classDef ${cls} ${CLASS_STYLES[cls]}`);
170
+ }
171
+ for (const line of classAssignments) lines.push(line);
172
+ return lines;
173
+ }
174
+ export const renderFlow = (flow) => renderFlowLines(flow).join("\n");
@@ -0,0 +1,540 @@
1
+ import {
2
+ BLOCK_HYPS,
3
+ BLOCK_LINES,
4
+ branchStatusOf,
5
+ byText,
6
+ clipLine,
7
+ hasSubtreeMark,
8
+ humanCaseTag,
9
+ isSyntheticNativeAx,
10
+ LINE_WIDTH,
11
+ shortName,
12
+ stripCasePrefix,
13
+ } from "../ir.mjs";
14
+ const hypSig = (h) =>
15
+ h.value !== undefined ? `${h.type} := ${h.value}` : h.type;
16
+ const isTypeBinder = (h) =>
17
+ h.type === "Type" ||
18
+ h.type.startsWith("Type ") ||
19
+ h.type === "Sort" ||
20
+ h.type.startsWith("Sort ");
21
+ const hypLine = (prefix, h) => {
22
+ const raw =
23
+ h.value !== undefined
24
+ ? `${prefix}${h.name} : ${h.type} := ${h.value}`
25
+ : `${prefix}${h.name} : ${h.type}`;
26
+ return clipLine(raw, LINE_WIDTH);
27
+ };
28
+ function newAssumptions(input) {
29
+ const { entryGoal, parentLastGoal, hyps } = input;
30
+ if (!parentLastGoal) return [];
31
+ const parentMap = new Map();
32
+ for (const hid of parentLastGoal.hyps) {
33
+ const h = hyps[hid];
34
+ if (h) parentMap.set(h.name, hypSig(h));
35
+ }
36
+ const added = [];
37
+ for (const hid of entryGoal.hyps) {
38
+ const h = hyps[hid];
39
+ if (!h || isTypeBinder(h)) continue;
40
+ const prev = parentMap.get(h.name);
41
+ if (prev === undefined || prev !== hypSig(h)) added.push(h);
42
+ }
43
+ return added;
44
+ }
45
+ function orderHypsForDisplay(hyps) {
46
+ const named = [];
47
+ const inaccessible = [];
48
+ for (const h of hyps) {
49
+ if (h.name.includes("✝")) inaccessible.push(h);
50
+ else named.push(h);
51
+ }
52
+ return [...named, ...inaccessible];
53
+ }
54
+ function midBoxAssumptions(input) {
55
+ const { entryGoal, lastGoal, entryAdded, hyps } = input;
56
+ if (!lastGoal || lastGoal.id === entryGoal.id) return [];
57
+ const entryAddedNames = new Set(entryAdded.map((h) => h.name));
58
+ const raw = newAssumptions({
59
+ entryGoal: lastGoal,
60
+ parentLastGoal: entryGoal,
61
+ hyps,
62
+ });
63
+ return orderHypsForDisplay(raw.filter((h) => !entryAddedNames.has(h.name)));
64
+ }
65
+ function tacticLines(block, stepById) {
66
+ const raw = [];
67
+ for (const sid of block.steps) {
68
+ const step = stepById.get(sid);
69
+ if (!step) continue;
70
+ const inl = block.inlined.get(sid)?.filter((t) => !step.text.includes(t));
71
+ const full =
72
+ inl && inl.length > 0 ? `${step.text} [${inl.join("; ")}]` : step.text;
73
+ raw.push(clipLine(full, LINE_WIDTH));
74
+ }
75
+ if (raw.length > BLOCK_LINES) {
76
+ const kept = raw.slice(0, BLOCK_LINES - 1);
77
+ kept.push(`… +${raw.length - (BLOCK_LINES - 1)} 个步骤`);
78
+ raw.length = 0;
79
+ raw.push(...kept);
80
+ }
81
+ if (block.errorLabel !== undefined) {
82
+ raw.push(clipLine(`错误:${block.errorLabel}`, LINE_WIDTH));
83
+ }
84
+ return raw;
85
+ }
86
+ function invokedLemmas(input) {
87
+ const targetUser =
88
+ input.graph.lemmas.get(input.graph.target)?.decl.userName ??
89
+ input.graph.target;
90
+ const dot = targetUser.indexOf(".");
91
+ const prefix = dot === -1 ? "" : targetUser.slice(0, dot + 1);
92
+ const collectFromSteps = (steps) => {
93
+ const found = new Set();
94
+ for (const sid of steps) {
95
+ const step = input.stepById.get(sid);
96
+ if (!step) continue;
97
+ for (const name of step.names) {
98
+ if (name === input.graph.target) continue;
99
+ if (isSyntheticNativeAx(name)) continue;
100
+ const lemma = input.graph.lemmas.get(name);
101
+ if (!lemma) continue;
102
+ const u = lemma.decl.userName;
103
+ const display =
104
+ prefix && u.startsWith(prefix) ? u.slice(prefix.length) : u;
105
+ found.add(display);
106
+ }
107
+ }
108
+ return found;
109
+ };
110
+ if (input.block.differentGoals && input.block.foldedEntries.length > 1) {
111
+ const sets = input.block.foldedEntries.map((e) =>
112
+ collectFromSteps(e.steps),
113
+ );
114
+ const common = [...sets[0]].filter((name) =>
115
+ sets.every((s) => s.has(name)),
116
+ );
117
+ return common.sort(byText);
118
+ }
119
+ return [...collectFromSteps(input.block.steps)].sort(byText);
120
+ }
121
+ function restsOnBadge(kinds) {
122
+ if (!kinds || kinds.size === 0) return "依赖未证缺口";
123
+ const parts = [];
124
+ if (kinds.has("sorry")) parts.push("未证缺口");
125
+ if (kinds.has("error")) parts.push("失败步骤");
126
+ if (kinds.has("axiom")) parts.push("自定义公理");
127
+ if (kinds.has("native")) parts.push("native_decide");
128
+ if (parts.length === 0) return "依赖未证缺口";
129
+ return `依赖${parts.join(" / ")}`;
130
+ }
131
+ function trustBadgeOf(block) {
132
+ if (block.marks.has("error")) {
133
+ return block.errorLabel
134
+ ? clipLine(`失败步骤: ${block.errorLabel}`, LINE_WIDTH)
135
+ : "失败步骤";
136
+ }
137
+ if (block.marks.has("sorry")) return "未证缺口(sorry)";
138
+ if (block.marks.has("open")) return "开放目标";
139
+ if (block.marks.has("restsOn")) return restsOnBadge(block.restsOnKinds);
140
+ return undefined;
141
+ }
142
+ export function buildProofChart(input) {
143
+ const {
144
+ budgeted,
145
+ script,
146
+ facts,
147
+ graph,
148
+ targetClean = true,
149
+ allowProven = true,
150
+ tactics = false,
151
+ view,
152
+ } = input;
153
+ const goalById = new Map();
154
+ for (const g of script.goals) goalById.set(g.id, g);
155
+ const stepById = new Map();
156
+ for (const s of script.steps) stepById.set(s.id, s);
157
+ const isPartial =
158
+ script.partial === true ||
159
+ budgeted.roots.some((r) => r.root.where === "term");
160
+ const nodes = [];
161
+ const edges = [];
162
+ const groups = [];
163
+ const usedClasses = new Set();
164
+ const usedRestsOnKinds = new Set();
165
+ let anyDifferentGoalFold = false;
166
+ let nextId = 0;
167
+ const emitBlock = (ctx) => {
168
+ const {
169
+ block,
170
+ stableId,
171
+ parentId,
172
+ parentLastGoal,
173
+ ancestorRawTags,
174
+ ancestorTainted,
175
+ depth,
176
+ isRoot,
177
+ rootWhere,
178
+ groupNodes,
179
+ } = ctx;
180
+ const id = `b${nextId++}`;
181
+ groupNodes.push(id);
182
+ const entryGoal = goalById.get(block.entry);
183
+ const lastGoal = goalById.get(block.last);
184
+ const status = branchStatusOf(block.marks);
185
+ const isLeaf = block.into.length === 0;
186
+ const blockAllowProven = allowProven && !ancestorTainted;
187
+ const rawPrimaryTag = block.tags[0];
188
+ const strippedPrimaryTag =
189
+ rawPrimaryTag !== undefined
190
+ ? stripCasePrefix({
191
+ rawTag: rawPrimaryTag,
192
+ ancestorTags: ancestorRawTags,
193
+ })
194
+ : undefined;
195
+ const humanPrimaryTag =
196
+ strippedPrimaryTag !== undefined
197
+ ? humanCaseTag(strippedPrimaryTag)
198
+ : undefined;
199
+ if (block.times > 1 && block.differentGoals) anyDifferentGoalFold = true;
200
+ if (block.marks.has("restsOn") && block.restsOnKinds) {
201
+ for (const k of block.restsOnKinds) usedRestsOnKinds.add(k);
202
+ }
203
+ const lines = [];
204
+ if (block.hidden) {
205
+ if (block.times > 1) lines.push(`×${block.times}`);
206
+ const suffix = targetClean && blockAllowProven ? ",均已证明" : "";
207
+ lines.push(
208
+ `${block.hidden.steps} 个步骤,${block.hidden.cases} 个分支${suffix}`,
209
+ );
210
+ usedClasses.add("stub");
211
+ nodes.push({
212
+ id,
213
+ lines,
214
+ shape: "stub",
215
+ classes: ["stub"],
216
+ });
217
+ } else {
218
+ const entryAdded =
219
+ entryGoal && !block.differentGoals
220
+ ? orderHypsForDisplay(
221
+ newAssumptions({
222
+ entryGoal,
223
+ parentLastGoal,
224
+ hyps: script.hyps,
225
+ }),
226
+ )
227
+ : [];
228
+ const midAdded =
229
+ entryGoal && !block.differentGoals
230
+ ? midBoxAssumptions({
231
+ entryGoal,
232
+ lastGoal,
233
+ entryAdded,
234
+ hyps: script.hyps,
235
+ })
236
+ : [];
237
+ const allAdded = [...entryAdded, ...midAdded];
238
+ const usedLemmas = invokedLemmas({
239
+ block,
240
+ stepById,
241
+ graph,
242
+ });
243
+ const rawStepTexts = block.steps
244
+ .map((sid) => stepById.get(sid)?.text)
245
+ .filter((t) => t !== undefined);
246
+ const branchView = view?.branch?.({
247
+ id: stableId,
248
+ goal: block.differentGoals ? "" : (entryGoal?.target ?? ""),
249
+ newHyps: allAdded.map((h) => ({
250
+ ...h,
251
+ })),
252
+ tactics: [...rawStepTexts],
253
+ lemmas: [...usedLemmas],
254
+ status,
255
+ caseTag: humanPrimaryTag,
256
+ rawCaseTag: rawPrimaryTag,
257
+ depth,
258
+ isRoot,
259
+ isLeaf,
260
+ times: block.times,
261
+ });
262
+ const badge = trustBadgeOf(block);
263
+ if (branchView !== undefined) {
264
+ if (block.times > 1) lines.push(`×${block.times}`);
265
+ lines.push(clipLine(branchView.label, 120));
266
+ if (branchView.detail !== undefined) {
267
+ lines.push("────────");
268
+ lines.push(clipLine(branchView.detail, 120));
269
+ }
270
+ if (badge !== undefined) lines.push(badge);
271
+ } else if (tactics) {
272
+ if (block.times > 1) {
273
+ const foldedTags = block.tags
274
+ .map((t) =>
275
+ humanCaseTag(
276
+ stripCasePrefix({
277
+ rawTag: t,
278
+ ancestorTags: ancestorRawTags,
279
+ }),
280
+ ),
281
+ )
282
+ .join(", ");
283
+ lines.push(
284
+ clipLine(
285
+ `×${block.times}${foldedTags ? ` (${foldedTags})` : ""}`,
286
+ LINE_WIDTH,
287
+ ),
288
+ );
289
+ }
290
+ const goalLines = [];
291
+ if (!block.differentGoals) {
292
+ const shownEntry = entryAdded
293
+ .slice(0, BLOCK_HYPS)
294
+ .map((h) => hypLine("+ ", h));
295
+ const remainingBudget = Math.max(0, BLOCK_HYPS - shownEntry.length);
296
+ const shownMid = midAdded
297
+ .slice(0, remainingBudget)
298
+ .map((h) => hypLine("+ ", h));
299
+ const omittedHyps =
300
+ allAdded.length - shownEntry.length - shownMid.length;
301
+ for (const hl of shownEntry) goalLines.push(hl);
302
+ if (
303
+ entryGoal &&
304
+ (!parentLastGoal || entryGoal.target !== parentLastGoal.target)
305
+ ) {
306
+ goalLines.push(clipLine(`⊢ ${entryGoal.target}`, LINE_WIDTH));
307
+ }
308
+ for (const hl of shownMid) goalLines.push(hl);
309
+ if (omittedHyps > 0) {
310
+ goalLines.push(
311
+ `另有 ${omittedHyps} 条假设`,
312
+ );
313
+ }
314
+ }
315
+ for (const gl of goalLines) lines.push(gl);
316
+ const tLines = tacticLines(block, stepById);
317
+ if (goalLines.length > 0 && tLines.length > 0) lines.push("────────");
318
+ for (const tl of tLines) lines.push(tl);
319
+ if (badge !== undefined) lines.push(badge);
320
+ if (lines.length === 0) lines.push("目标");
321
+ } else {
322
+ if (block.times > 1) {
323
+ const foldedTags = block.tags
324
+ .map((t) =>
325
+ humanCaseTag(
326
+ stripCasePrefix({
327
+ rawTag: t,
328
+ ancestorTags: ancestorRawTags,
329
+ }),
330
+ ),
331
+ )
332
+ .join(", ");
333
+ lines.push(
334
+ clipLine(
335
+ `×${block.times}${foldedTags ? ` (${foldedTags})` : ""}`,
336
+ LINE_WIDTH,
337
+ ),
338
+ );
339
+ }
340
+ const summaryLines = [];
341
+ if (usedLemmas.length > 0) {
342
+ const shown = usedLemmas.slice(0, 3).join(", ");
343
+ const extra =
344
+ usedLemmas.length > 3 ? ` (+${usedLemmas.length - 3})` : "";
345
+ summaryLines.push(clipLine(`使用 ${shown}${extra}`, LINE_WIDTH));
346
+ }
347
+ if (badge !== undefined) {
348
+ summaryLines.push(badge);
349
+ } else if (isLeaf && blockAllowProven) {
350
+ summaryLines.push("已证明");
351
+ }
352
+ const claimLines = [];
353
+ if (!block.differentGoals) {
354
+ const shownEntry = entryAdded
355
+ .slice(0, BLOCK_HYPS)
356
+ .map((h) => hypLine("+ ", h));
357
+ const remainingBudget = Math.max(0, BLOCK_HYPS - shownEntry.length);
358
+ const shownMid = midAdded
359
+ .slice(0, remainingBudget)
360
+ .map((h) => hypLine("+ ", h));
361
+ const omittedHyps =
362
+ allAdded.length - shownEntry.length - shownMid.length;
363
+ for (const hl of shownEntry) claimLines.push(hl);
364
+ if (
365
+ entryGoal &&
366
+ (isRoot ||
367
+ !parentLastGoal ||
368
+ entryGoal.target !== parentLastGoal.target ||
369
+ (shownEntry.length === 0 &&
370
+ shownMid.length === 0 &&
371
+ summaryLines.length === 0))
372
+ ) {
373
+ claimLines.push(clipLine(entryGoal.target, LINE_WIDTH));
374
+ }
375
+ for (const hl of shownMid) claimLines.push(hl);
376
+ if (omittedHyps > 0) {
377
+ claimLines.push(
378
+ `另有 ${omittedHyps} 条假设`,
379
+ );
380
+ }
381
+ }
382
+ for (const cl of claimLines) lines.push(cl);
383
+ if (
384
+ (claimLines.length > 0 || block.times > 1) &&
385
+ summaryLines.length > 0
386
+ ) {
387
+ lines.push("────────");
388
+ }
389
+ for (const sl of summaryLines) lines.push(sl);
390
+ if (lines.length === 0)
391
+ lines.push(
392
+ isLeaf ? (blockAllowProven ? "已证明" : "尚未核验") : "子分支",
393
+ );
394
+ }
395
+ const classes = [];
396
+ if (isRoot) {
397
+ if (rootWhere === "termination") classes.push("termRoot");
398
+ else
399
+ classes.push(
400
+ isPartial || rootWhere === "term" ? "subRoot" : "goalRoot",
401
+ );
402
+ }
403
+ if (block.marks.has("error")) classes.push("error");
404
+ else if (block.marks.has("sorry")) classes.push("sorry");
405
+ else if (block.marks.has("open")) classes.push("open");
406
+ else if (block.marks.has("restsOn")) classes.push("restsOn");
407
+ else if (block.times > 1) classes.push("folded");
408
+ else if (isLeaf && !isRoot && blockAllowProven) classes.push("closed");
409
+ for (const cls of classes) usedClasses.add(cls);
410
+ const shape =
411
+ block.marks.has("error") ||
412
+ block.marks.has("sorry") ||
413
+ block.marks.has("open")
414
+ ? "hexagon"
415
+ : isRoot || (isLeaf && block.marks.size === 0)
416
+ ? "round"
417
+ : "box";
418
+ nodes.push({
419
+ id,
420
+ lines,
421
+ shape,
422
+ classes,
423
+ });
424
+ }
425
+ if (parentId !== undefined) {
426
+ let edgeLabel;
427
+ if (block.tags.length > 0) {
428
+ const rendered = block.tags.map((rawTag) => {
429
+ const stripped = stripCasePrefix({
430
+ rawTag,
431
+ ancestorTags: ancestorRawTags,
432
+ });
433
+ const custom = view?.caseLabel?.(stripped, {
434
+ id: stableId,
435
+ rawTag,
436
+ parentTag: ancestorRawTags[ancestorRawTags.length - 1],
437
+ goal: entryGoal?.target ?? "",
438
+ status,
439
+ isLeaf,
440
+ });
441
+ return custom ?? humanCaseTag(stripped);
442
+ });
443
+ const hasCustom = view?.caseLabel !== undefined;
444
+ edgeLabel = clipLine(rendered.join(", "), hasCustom ? 64 : 36);
445
+ }
446
+ const thick = hasSubtreeMark(block) || block.errorLabel !== undefined;
447
+ edges.push({
448
+ from: parentId,
449
+ to: id,
450
+ label: edgeLabel,
451
+ dotted: false,
452
+ thick,
453
+ });
454
+ }
455
+ const nextAncestors =
456
+ rawPrimaryTag !== undefined
457
+ ? [...ancestorRawTags, rawPrimaryTag]
458
+ : ancestorRawTags;
459
+ const nextAncestorTainted =
460
+ ancestorTainted || block.marks.size > 0 || block.errorLabel !== undefined;
461
+ for (const [ci, child] of block.into.entries()) {
462
+ emitBlock({
463
+ block: child,
464
+ stableId: `${stableId}.${ci}`,
465
+ parentId: id,
466
+ parentLastGoal: lastGoal ?? entryGoal,
467
+ ancestorRawTags: nextAncestors,
468
+ ancestorTainted: nextAncestorTainted,
469
+ depth: depth + 1,
470
+ isRoot: false,
471
+ rootWhere,
472
+ groupNodes,
473
+ });
474
+ }
475
+ };
476
+ for (const [i, entry] of budgeted.roots.entries()) {
477
+ const groupNodes = [];
478
+ const rootStableId = budgeted.roots.length === 1 ? "root" : `root${i}`;
479
+ emitBlock({
480
+ block: entry.block,
481
+ stableId: rootStableId,
482
+ parentId: undefined,
483
+ parentLastGoal: undefined,
484
+ ancestorRawTags: [],
485
+ ancestorTainted: false,
486
+ depth: 0,
487
+ isRoot: true,
488
+ rootWhere: entry.root.where,
489
+ groupNodes,
490
+ });
491
+ if (budgeted.roots.length > 1) {
492
+ const title =
493
+ entry.root.where === "termination"
494
+ ? "终止性证明"
495
+ : entry.root.where === "term"
496
+ ? `子证明 ${i + 1}`
497
+ : `分支 ${i + 1}`;
498
+ groups.push({
499
+ title,
500
+ nodes: groupNodes,
501
+ });
502
+ }
503
+ }
504
+ const restsOnLegend = restsOnBadge(usedRestsOnKinds);
505
+ const foldedLegend = anyDifferentGoalFold
506
+ ? "已折叠的分支(步骤相同)"
507
+ : "重复的相同分支";
508
+ const legendSpecs = [
509
+ ["定理", "goalRoot"],
510
+ ["子证明根节点", "subRoot"],
511
+ ["终止性目标", "termRoot"],
512
+ ["已证明", "closed"],
513
+ ["未证缺口(sorry)", "sorry"],
514
+ ["失败步骤", "error"],
515
+ ["开放目标", "open"],
516
+ [restsOnLegend, "restsOn"],
517
+ [foldedLegend, "folded"],
518
+ ["已折叠的细节", "stub"],
519
+ ];
520
+ const legend = legendSpecs
521
+ .filter(([, cls]) => usedClasses.has(cls))
522
+ .map(([text, cls]) => ({
523
+ text,
524
+ cls,
525
+ }));
526
+ if (isPartial) {
527
+ legend.push({
528
+ text: "部分证明:图中省略项模式的部分",
529
+ cls: "note",
530
+ });
531
+ }
532
+ const defaultTitle = `${shortName(facts.target)} · 证明树`;
533
+ return {
534
+ title: view?.title?.proof ?? defaultTitle,
535
+ nodes,
536
+ edges,
537
+ groups,
538
+ legend,
539
+ };
540
+ }