@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.
- package/README.md +4 -1
- package/THIRD_PARTY_NOTICES.md +19 -7
- package/cli.mjs +2 -2
- package/install.mjs +11 -4
- package/package.json +1 -1
- package/scripts/persistence/home.md +1 -1
- package/skills/dev/dev-build/SKILL.md +2 -0
- package/skills/dev/dev-build/references/implement-request.md +7 -2
- package/skills/dev/dev-formal-verify/SKILL.md +2 -1
- package/skills/dev/dev-formal-verify/references/create-check.md +3 -1
- package/skills/dev/dev-formal-verify/references/example.md +1 -1
- package/skills/dev/dev-formal-verify/references/tool-choice.md +1 -1
- package/skills/dev/dev-help/references/capabilities.md +6 -6
- package/skills/dev/dev-help/references/guide-verification.md +7 -1
- package/skills/dev/dev-help/references/help-method.md +7 -1
- package/skills/dev/dev-issue/SKILL.md +1 -0
- package/skills/dev/dev-issue/references/github-operations.md +8 -0
- package/skills/dev/dev-plan/references/plan-template.md +1 -0
- package/skills/dev/dev-plan/references/vertical-slicing.md +2 -0
- package/skills/dev/dev-pr/references/pull-request-evidence.md +2 -0
- package/skills/dev/dev-review/references/host-parity.md +12 -0
- package/skills/dev/dev-review/references/review-baseline.md +2 -0
- package/skills/dev/dev-setup/references/formal-options.md +1 -1
- package/skills/dev/dev-statechart/SKILL.md +17 -19
- package/skills/dev/dev-statechart/agents/openai.yaml +3 -3
- package/skills/dev/dev-statechart/assets/theme.css +135 -0
- package/skills/dev/dev-statechart/references/lean-proof.md +47 -0
- package/skills/dev/dev-statechart/references/render.md +15 -83
- package/skills/dev/dev-statechart/references/runtime.md +21 -1
- package/skills/dev/dev-statechart/scripts/lean/backends/lemma-chart.mjs +285 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/mermaid.mjs +174 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/proof-chart.mjs +540 -0
- package/skills/dev/dev-statechart/scripts/lean/backends/report.mjs +242 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/facts.mjs +234 -0
- package/skills/dev/dev-statechart/scripts/lean/frontends/view.mjs +217 -0
- package/skills/dev/dev-statechart/scripts/lean/ir.mjs +226 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/attribute.mjs +148 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/blocks.mjs +32 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/budget.mjs +167 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/check.mjs +70 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/contract.mjs +160 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/fold.mjs +206 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/inline.mjs +84 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/mark.mjs +432 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/reduce.mjs +73 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/trust.mjs +111 -0
- package/skills/dev/dev-statechart/scripts/lean/passes/view-lemmas.mjs +155 -0
- package/skills/dev/dev-statechart/scripts/lean/pipeline.mjs +164 -0
- package/skills/dev/dev-statechart/scripts/lean/run.mjs +168 -0
- package/skills/dev/dev-statechart/scripts/statechart.mjs +42 -23
- package/skills/dev/dev-statechart/scripts/worker.mjs +33 -7
- package/skills/dev/dev-ui-design/SKILL.md +2 -2
- package/skills/dev/dev-ui-design/references/interaction-review.md +9 -0
- package/skills/dev/dev-verify/SKILL.md +1 -1
- package/skills/dev/dev-verify/references/evidence-storage.md +12 -0
- package/skills/dev/dev-workflow/SKILL.md +6 -6
- package/skills/dev/dev-workflow/references/method-handoffs.md +7 -1
- package/skills/dev/dev-writing/SKILL.md +2 -0
- package/skills/dev/dev-writing/references/library-docs.md +37 -0
- package/skills/home/home-doctor/references/diagnosis.md +2 -2
- package/skills/home/home-doctor/scripts/doctor.mjs +68 -38
- package/skills/home/home-project-changelog/SKILL.md +7 -7
- package/skills/home/home-project-changelog/assets/project-changelog.example.json +188 -0
- package/skills/home/home-project-changelog/assets/project-changelog.schema.json +156 -0
- package/skills/home/home-project-changelog/assets/worker-brief.md +1 -1
- package/skills/home/home-project-changelog/references/git-ranges.md +2 -2
- package/skills/home/home-project-changelog/references/schema.md +61 -0
- package/skills/home/home-project-changelog/references/tools.md +28 -22
- package/skills/home/home-project-changelog/references/workflow.md +12 -9
- package/skills/home/home-project-changelog/references/writing.md +5 -3
- package/skills/home/home-project-changelog/scripts/changelog.mjs +42 -38
- package/skills/home/home-project-changelog/scripts/contract.mjs +40 -3
- package/skills/home/home-project-changelog/scripts/legacy-markdown.mjs +116 -0
- package/skills/home/home-project-changelog/scripts/migrate.mjs +122 -0
- package/skills/home/home-project-changelog/scripts/revision.mjs +2 -196
- package/skills/home/home-project-changelog/scripts/storage.mjs +120 -125
- package/skills/home/home-project-changelog/scripts/summary.mjs +0 -60
- package/skills/home/home-route/SKILL.md +2 -2
- package/skills/home/home-route/references/routing.md +3 -1
- package/skills/home/home-route/scripts/route.mjs +79 -11
- package/skills/home/home-setup/SKILL.md +2 -1
- package/skills/home/home-setup/assets/repos.schema.json +10 -0
- package/skills/home/home-setup/references/registry.md +18 -1
- package/skills/home/home-setup/scripts/registry.mjs +67 -7
- package/skills/home/home-website/SKILL.md +13 -9
- package/skills/home/home-website/assets/website/scripts/inputs.mjs +143 -128
- package/skills/home/home-website/assets/website/scripts/render.mjs +8 -6
- package/skills/home/home-website/assets/website/scripts/site.mjs +21 -10
- package/skills/home/home-website/assets/website/site/public/home-assets/app.js +81 -34
- package/skills/home/home-website/assets/website/site/public/home-assets/site.css +92 -70
- package/skills/home/home-website/assets/website/site/templates/favicon.png +0 -0
- package/skills/home/home-website/assets/website/site/templates/layout.mjs +13 -10
- package/skills/home/home-website/assets/website/site/templates/ledger.mjs +51 -46
- package/skills/home/home-website/assets/website/site/templates/model.mjs +58 -14
- package/skills/home/home-website/assets/website/site/templates/pages.mjs +28 -30
- package/skills/home/home-website/assets/website/site/templates/project-logs.mjs +3 -107
- package/skills/home/home-website/assets/website/site.config.json +1 -1
- package/skills/home/home-website/references/website.md +64 -46
- package/skills/home/home-website/scripts/activate.mjs +106 -0
- package/skills/home/home-website/scripts/init.mjs +98 -11
- package/skills/home/home-workflow/SKILL.md +6 -4
- package/skills/system/system-clash-proxy-config/SKILL.md +21 -0
- package/skills/system/system-clash-proxy-config/agents/openai.yaml +4 -0
- package/skills/system/system-clash-proxy-config/assets/clash-override.js +328 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/browser-privacy.md +2 -2
- package/skills/system/{system-config → system-clash-proxy-config}/references/changes.md +2 -2
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/clash-verge.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/diagnosis.md +1 -1
- package/skills/system/system-clash-proxy-config/references/dns-workflow.md +42 -0
- package/skills/system/system-clash-proxy-config/references/egress-macos.md +31 -0
- package/skills/system/system-clash-proxy-config/references/egress-windows.md +37 -0
- package/skills/system/system-clash-proxy-config/references/egress.md +12 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/flclash.md +1 -1
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/index.md +1 -1
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/linux-cutover.md +29 -0
- package/skills/system/system-clash-proxy-config/references/locale-workflow.md +9 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/mihomo.md +1 -25
- package/skills/system/system-clash-proxy-config/references/session.md +34 -0
- package/skills/system/system-clash-proxy-config/references/subscription.md +29 -0
- package/skills/system/{system-proxy → system-clash-proxy-config}/references/troubleshooting.md +7 -7
- package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/verification.md +2 -0
- package/skills/system/system-clash-proxy-config/scripts/prepare-session.mjs +155 -0
- package/skills/system/system-clash-proxy-config/scripts/run-session.mjs +138 -0
- package/skills/system/system-inspect/SKILL.md +1 -1
- package/skills/system/system-inspect/references/health-audit.md +1 -1
- package/upstream-skills/zh-archify/SKILL.md +11 -11
- package/upstream-skills/zh-archify/assets/template.html +6 -3
- package/upstream-skills/zh-archify/bin/archify.mjs +67 -4
- package/upstream-skills/zh-archify/modules/code-analysis/ARCHITECTURE.md +7 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/analyze-run.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/bin/check.mjs +29 -15
- package/upstream-skills/zh-archify/modules/code-analysis/bin/drift.mjs +3 -3
- package/upstream-skills/zh-archify/modules/code-analysis/bin/prepare.mjs +5 -6
- package/upstream-skills/zh-archify/modules/code-analysis/bin/serve.mjs +66 -36
- package/upstream-skills/zh-archify/modules/code-analysis/bin/verify-change.mjs +43 -13
- package/upstream-skills/zh-archify/modules/code-analysis/docs/TECH-GUIDE.md +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/docs/USAGE.md +37 -4
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/functions.mjs +7 -5
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/index.mjs +4 -1
- package/upstream-skills/zh-archify/modules/code-analysis/extract/ts/snapshot-host.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/architecture-drift.mjs +28 -7
- package/upstream-skills/zh-archify/modules/code-analysis/lib/drift-capture.mjs +4 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/git-sources.mjs +5 -3
- package/upstream-skills/zh-archify/modules/code-analysis/lib/output.mjs +272 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/pull-request.mjs +34 -4
- package/upstream-skills/zh-archify/modules/code-analysis/lib/task.mjs +4 -2
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-context.mjs +13 -1
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification-history.mjs +112 -0
- package/upstream-skills/zh-archify/modules/code-analysis/lib/verification.mjs +6 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/atlas.mjs +71 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.css +16 -2
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas.js +121 -5
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/atlas3d.js +38 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.css +14 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/overlay.js +187 -27
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/client/verification.js +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/i18n.mjs +9 -0
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/inject.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/page.mjs +11 -6
- package/upstream-skills/zh-archify/modules/code-analysis/overlay/pull-request.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/schemas/ai-task.schema.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/atlas.test.mjs +88 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/duplicates.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/external-workflow.test.mjs +1 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/boundary.task.missing.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/complexity.task.valid.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.changed.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/import-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/fixtures/tasks/module-cycle.task.json +1 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/function-source-range.test.mjs +10 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/output-recovery.test.mjs +626 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/pull-request.test.mjs +98 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/review.test.mjs +37 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/source-panel.test.mjs +2 -1
- package/upstream-skills/zh-archify/modules/code-analysis/test/task.test.mjs +3 -2
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification-history.test.mjs +216 -0
- package/upstream-skills/zh-archify/modules/code-analysis/test/verification.test.mjs +122 -0
- package/upstream-skills/zh-archify/package-lock.json +2 -2
- package/upstream-skills/zh-archify/package.json +1 -1
- package/upstream-skills/zh-archify/references/authoring-contract.md +2 -0
- package/upstream-skills/zh-archify/references/explainer-authoring.md +1 -1
- package/upstream-skills/zh-archify/renderers/architecture/render-architecture.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/class/render-class.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/dataflow/render-dataflow.mjs +2 -1
- package/upstream-skills/zh-archify/renderers/erd/render-erd.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/lifecycle/render-lifecycle.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/sequence/render-sequence.mjs +4 -2
- package/upstream-skills/zh-archify/renderers/shared/cli.mjs +7 -1
- package/upstream-skills/zh-archify/renderers/timeline/render-timeline.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/tree/render-tree.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/waterfall/render-waterfall.mjs +1 -0
- package/upstream-skills/zh-archify/renderers/workflow/render-workflow.mjs +3 -2
- package/upstream-skills/zh-archify/renderers/workflow/workflow-compiler.mjs +68 -7
- package/upstream-skills/zh-archify/skill-release.json +1 -1
- package/upstream-skills/zh-modern-web-guidance/SKILL.md +4 -11
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-detection.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/language-model.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/prompt-api.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/summarizer.md +20 -0
- package/upstream-skills/zh-modern-web-guidance/guides/built-in-ai/translator.md +22 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/custom-ml-model-inference.md +342 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/data-parallel-computation.md +337 -0
- package/upstream-skills/zh-modern-web-guidance/guides/performance/improve-next-page-load-performance.md +4 -1
- package/upstream-skills/zh-modern-web-guidance/guides/performance/large-scene-rendering.md +350 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/position-aware-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-atoms/viewport-aware-dropdowns.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/animate-to-from-top-layer.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/declarative-dialog-popover-control.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/interest-triggered-tooltips.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/scroll-target-on-load.md +29 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-behaviors/sortable-table.md +1 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/app-menus.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/context-menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/copy-button.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/dialog.md +10 -1
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/hovercard.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/menu.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/navbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-app-tours.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/persistent-toast-notifications.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/ui-components/toolbar.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/content-first-noise-reduction.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/user-experience/natural-interactions.md +9 -0
- package/upstream-skills/zh-modern-web-guidance/guides/webmcp/agentic-javascript-tools.md +27 -0
- package/skills/home/home-project-changelog/assets/project-changelog.md +0 -35
- package/skills/system/system-clash-tun-egress/SKILL.md +0 -22
- package/skills/system/system-clash-tun-egress/agents/openai.yaml +0 -4
- package/skills/system/system-config/SKILL.md +0 -37
- package/skills/system/system-config/agents/openai.yaml +0 -4
- package/skills/system/system-config/references/ai-cli-config.md +0 -75
- package/skills/system/system-config/references/ai-cli-optimization.md +0 -37
- package/skills/system/system-config/references/index.md +0 -12
- package/skills/system/system-config/references/locale-workflow.md +0 -33
- package/skills/system/system-config/references/locale.md +0 -50
- package/skills/system/system-proxy/SKILL.md +0 -40
- package/skills/system/system-proxy/agents/openai.yaml +0 -4
- package/skills/system/system-proxy/assets/protected-rules.yaml +0 -7
- package/skills/system/system-proxy/references/dns-workflow.md +0 -152
- /package/skills/system/{system-config → system-clash-proxy-config}/assets/configuration.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/assets/network.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/acceptance.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-fields.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/dns-misconceptions.md +0 -0
- /package/skills/system/{system-clash-tun-egress/references/troubleshooting.md → system-clash-proxy-config/references/egress-troubleshooting.md} +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-linux.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-macos.md +0 -0
- /package/skills/system/{system-config → system-clash-proxy-config}/references/locale-windows.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/network-performance.md +0 -0
- /package/skills/system/{system-clash-tun-egress → system-clash-proxy-config}/references/nodes-and-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platform-dns.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/platforms.md +0 -0
- /package/skills/system/{system-proxy → system-clash-proxy-config}/references/tun-dns.md +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import {
|
|
2
|
+
branchStatusOf,
|
|
3
|
+
byText,
|
|
4
|
+
firstSentence,
|
|
5
|
+
formatDoubt,
|
|
6
|
+
humanCaseTag,
|
|
7
|
+
isNativeAxiom,
|
|
8
|
+
isStandardAxiom,
|
|
9
|
+
spanContainsPlace,
|
|
10
|
+
stripCasePrefix,
|
|
11
|
+
} from "../ir.mjs";
|
|
12
|
+
const STATUS_LABELS = { error: "失败步骤", sorry: "未证缺口(sorry)", open: "开放目标", restsOn: "依赖疑点", clean: "未发现此分支有疑点" };
|
|
13
|
+
const FINAL_LABELS = { assigned: "已赋值", open: "开放", gone: "已消失" };
|
|
14
|
+
const CLOSE_LABELS = { proof: "已证明", sorry: "由 sorry 闭合", error: "由错误占位闭合" };
|
|
15
|
+
const DECL_LABELS = { theorem: "定理", axiom: "公理", def: "定义", opaque: "不透明声明", inductive: "归纳类型", constructor: "构造子", recursor: "递归子", quot: "商类型" };
|
|
16
|
+
|
|
17
|
+
function collectAllEntries(block, stableId, ancestorTags, out) {
|
|
18
|
+
const entries =
|
|
19
|
+
block.foldedEntries.length > 0
|
|
20
|
+
? block.foldedEntries
|
|
21
|
+
: [
|
|
22
|
+
{
|
|
23
|
+
entry: block.entry,
|
|
24
|
+
last: block.last,
|
|
25
|
+
tag: block.tags[0],
|
|
26
|
+
steps: block.steps,
|
|
27
|
+
inlined: block.inlined,
|
|
28
|
+
errorLabel: block.errorLabel,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
for (const [idx, entry] of entries.entries()) {
|
|
32
|
+
const id = entries.length > 1 ? `${stableId}[${idx + 1}]` : stableId;
|
|
33
|
+
const caseTag =
|
|
34
|
+
entry.tag !== undefined
|
|
35
|
+
? humanCaseTag(
|
|
36
|
+
stripCasePrefix({
|
|
37
|
+
rawTag: entry.tag,
|
|
38
|
+
ancestorTags,
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
: undefined;
|
|
42
|
+
out.push({
|
|
43
|
+
id,
|
|
44
|
+
block,
|
|
45
|
+
entry,
|
|
46
|
+
caseTag,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const primaryTag = block.tags[0];
|
|
50
|
+
const nextAncestors =
|
|
51
|
+
primaryTag !== undefined ? [...ancestorTags, primaryTag] : ancestorTags;
|
|
52
|
+
for (const [i, child] of block.into.entries()) {
|
|
53
|
+
collectAllEntries(child, `${stableId}.${i}`, nextAncestors, out);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function buildReport(input) {
|
|
57
|
+
const {
|
|
58
|
+
facts,
|
|
59
|
+
graph,
|
|
60
|
+
budgetedLemmas,
|
|
61
|
+
trust,
|
|
62
|
+
verdict,
|
|
63
|
+
hiddenByView = 0,
|
|
64
|
+
script,
|
|
65
|
+
tree,
|
|
66
|
+
allBlocks,
|
|
67
|
+
budgetedBlocks,
|
|
68
|
+
} = input;
|
|
69
|
+
const lines = [];
|
|
70
|
+
lines.push(`# ${facts.target}`);
|
|
71
|
+
lines.push("");
|
|
72
|
+
const standardAxioms = facts.axioms.filter(isStandardAxiom).sort(byText);
|
|
73
|
+
const targetMessages = facts.messages.filter((m) =>
|
|
74
|
+
spanContainsPlace(facts.targetSpan, m.at),
|
|
75
|
+
);
|
|
76
|
+
if (verdict.clean) {
|
|
77
|
+
const axNote =
|
|
78
|
+
standardAxioms.length > 0
|
|
79
|
+
? `仅依赖标准公理(${standardAxioms.join("、")})`
|
|
80
|
+
: "不依赖公理";
|
|
81
|
+
lines.push(`核验通过。证明已闭合,${axNote}。`);
|
|
82
|
+
} else {
|
|
83
|
+
lines.push(`审计发现:${verdict.reasons.join("、")}。`);
|
|
84
|
+
}
|
|
85
|
+
lines.push("");
|
|
86
|
+
const metaParts = [
|
|
87
|
+
`文件:\`${facts.file}\``,
|
|
88
|
+
`模块:\`${facts.module}\``,
|
|
89
|
+
`Lean: \`${facts.lean}\``,
|
|
90
|
+
];
|
|
91
|
+
if (facts.package) metaParts.splice(2, 0, `包:\`${facts.package}\``);
|
|
92
|
+
lines.push(metaParts.join(" · "));
|
|
93
|
+
const span = facts.targetSpan;
|
|
94
|
+
lines.push(`目标范围:${span.line}:${span.column}–${span.endLine}:${span.endColumn}`);
|
|
95
|
+
const lemmaSummary = [
|
|
96
|
+
`引理:显示 ${budgetedLemmas.kept.size}/${budgetedLemmas.total} 个`,
|
|
97
|
+
];
|
|
98
|
+
if (hiddenByView > 0) {
|
|
99
|
+
lemmaSummary.push(
|
|
100
|
+
`视图隐藏 ${hiddenByView} 个辅助引理`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (budgetedLemmas.cut > 0)
|
|
104
|
+
lemmaSummary.push(`预算省略 ${budgetedLemmas.cut} 个引理`);
|
|
105
|
+
if (graph.reducedEdges > 0)
|
|
106
|
+
lemmaSummary.push(
|
|
107
|
+
`精简 ${graph.reducedEdges} 条传递边`,
|
|
108
|
+
);
|
|
109
|
+
if (budgetedBlocks) {
|
|
110
|
+
lemmaSummary.push(
|
|
111
|
+
`证明块:显示 ${budgetedBlocks.shownBlocks}/${budgetedBlocks.totalBlocks} 个`,
|
|
112
|
+
);
|
|
113
|
+
if (budgetedBlocks.hiddenBlocks > 0)
|
|
114
|
+
lemmaSummary.push(`预算折叠 ${budgetedBlocks.hiddenBlocks} 个证明块`);
|
|
115
|
+
}
|
|
116
|
+
lines.push(`${lemmaSummary.join(" · ")}。`);
|
|
117
|
+
const isPartial =
|
|
118
|
+
script !== undefined &&
|
|
119
|
+
(script.partial === true ||
|
|
120
|
+
(budgetedBlocks !== undefined &&
|
|
121
|
+
budgetedBlocks.roots.some((r) => r.root.where === "term")));
|
|
122
|
+
if (isPartial) {
|
|
123
|
+
lines.push(
|
|
124
|
+
"proof.mmd 只显示 tactic 子证明,项模式的部分没有证明树。",
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (trust.paths.length > 0) {
|
|
128
|
+
lines.push("");
|
|
129
|
+
lines.push("## 疑点依赖路径");
|
|
130
|
+
for (const [i, entry] of trust.paths.entries()) {
|
|
131
|
+
const chain = entry.path
|
|
132
|
+
.map((n) => graph.lemmas.get(n)?.decl.userName ?? n)
|
|
133
|
+
.join(" -> ");
|
|
134
|
+
lines.push(`${i + 1}. ${formatDoubt(entry.doubt)}: ${chain}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
lines.push("");
|
|
138
|
+
lines.push("## 公理");
|
|
139
|
+
if (facts.axioms.length === 0) {
|
|
140
|
+
lines.push("无。");
|
|
141
|
+
} else {
|
|
142
|
+
for (const ax of [...facts.axioms].sort(byText)) {
|
|
143
|
+
const tag =
|
|
144
|
+
ax === "sorryAx"
|
|
145
|
+
? "未证缺口(sorry)"
|
|
146
|
+
: isStandardAxiom(ax)
|
|
147
|
+
? "标准公理"
|
|
148
|
+
: isNativeAxiom(ax)
|
|
149
|
+
? "未经内核核验的原生计算"
|
|
150
|
+
: "自定义公理";
|
|
151
|
+
lines.push(`- \`${ax}\` (${tag})`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const reportRoots = allBlocks ?? budgetedBlocks?.roots;
|
|
155
|
+
if (script && reportRoots && reportRoots.length > 0) {
|
|
156
|
+
const goalById = new Map();
|
|
157
|
+
for (const g of script.goals) goalById.set(g.id, g);
|
|
158
|
+
const stepById = new Map();
|
|
159
|
+
for (const s of script.steps) stepById.set(s.id, s);
|
|
160
|
+
const entries = [];
|
|
161
|
+
for (const [i, r] of reportRoots.entries()) {
|
|
162
|
+
const rootId = reportRoots.length === 1 ? "root" : `root${i}`;
|
|
163
|
+
collectAllEntries(r.block, rootId, [], entries);
|
|
164
|
+
}
|
|
165
|
+
if (entries.length > 0) {
|
|
166
|
+
lines.push("");
|
|
167
|
+
lines.push("## 证明目标");
|
|
168
|
+
for (const item of entries) {
|
|
169
|
+
const g = goalById.get(item.entry.entry);
|
|
170
|
+
if (!g) continue;
|
|
171
|
+
const status = branchStatusOf(item.block.marks);
|
|
172
|
+
const tagPart = item.caseTag ? ` (${item.caseTag})` : "";
|
|
173
|
+
lines.push(
|
|
174
|
+
`- **${item.id}${tagPart}** (${STATUS_LABELS[status]},${FINAL_LABELS[g.final]}${g.closedBy ? `,${CLOSE_LABELS[g.closedBy]}` : ""})`,
|
|
175
|
+
);
|
|
176
|
+
for (const hid of g.hyps) {
|
|
177
|
+
const h = script.hyps[hid];
|
|
178
|
+
if (!h) continue;
|
|
179
|
+
const val = h.value !== undefined ? ` := ${h.value}` : "";
|
|
180
|
+
lines.push(` \`${h.name} : ${h.type}${val}\``);
|
|
181
|
+
}
|
|
182
|
+
lines.push(` \`⊢ ${g.target}\``);
|
|
183
|
+
if (item.entry.steps.length > 0) {
|
|
184
|
+
const stepTexts = item.entry.steps
|
|
185
|
+
.map((sid) => {
|
|
186
|
+
const s = stepById.get(sid);
|
|
187
|
+
if (!s) return undefined;
|
|
188
|
+
const inl = item.entry.inlined
|
|
189
|
+
.get(sid)
|
|
190
|
+
?.filter((t) => !s.text.includes(t));
|
|
191
|
+
return inl && inl.length > 0
|
|
192
|
+
? `${s.text} [${inl.join("; ")}]`
|
|
193
|
+
: s.text;
|
|
194
|
+
})
|
|
195
|
+
.filter((t) => t !== undefined);
|
|
196
|
+
if (stepTexts.length > 0) {
|
|
197
|
+
lines.push(
|
|
198
|
+
` tactic:${stepTexts.map((t) => `\`${t}\``).join("; ")}`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (item.entry.errorLabel !== undefined) {
|
|
203
|
+
lines.push(` 失败步骤:\`${item.entry.errorLabel}\``);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
lines.push("");
|
|
209
|
+
lines.push("## 引理");
|
|
210
|
+
const lemmaNames = [
|
|
211
|
+
graph.target,
|
|
212
|
+
...[...graph.lemmas.keys()].filter((n) => n !== graph.target).sort(byText),
|
|
213
|
+
];
|
|
214
|
+
for (const name of lemmaNames) {
|
|
215
|
+
const lemma = graph.lemmas.get(name);
|
|
216
|
+
if (!lemma) continue;
|
|
217
|
+
const loc = lemma.decl.line ? `:${lemma.decl.line}` : "";
|
|
218
|
+
const docPart = lemma.decl.doc ? ` — ${firstSentence(lemma.decl.doc)}` : "";
|
|
219
|
+
lines.push(
|
|
220
|
+
`- \`${lemma.decl.userName}\` (${DECL_LABELS[lemma.decl.kind]},${lemma.decl.module}${loc})${docPart}`,
|
|
221
|
+
);
|
|
222
|
+
if (lemma.decl.statement)
|
|
223
|
+
lines.push(` \`${lemma.decl.statement.replace(/\s+/g, " ").trim()}\``);
|
|
224
|
+
if (lemma.library.length > 0)
|
|
225
|
+
lines.push(` 库依赖:${lemma.library.join(", ")}`);
|
|
226
|
+
}
|
|
227
|
+
if (tree && tree.notes.length > 0) {
|
|
228
|
+
lines.push("");
|
|
229
|
+
lines.push("## 备注");
|
|
230
|
+
for (const note of tree.notes) lines.push(`- ${note}`);
|
|
231
|
+
}
|
|
232
|
+
if (targetMessages.length > 0) {
|
|
233
|
+
lines.push("");
|
|
234
|
+
lines.push("## 诊断");
|
|
235
|
+
for (const msg of targetMessages) {
|
|
236
|
+
lines.push(
|
|
237
|
+
`- ${msg.severity === "error" ? "错误" : "警告"} ${msg.at.line}:${msg.at.column}:${msg.text}`,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return lines.join("\n");
|
|
242
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { DECL_KINDS, FORMAT_VERSION } from "../ir.mjs";
|
|
2
|
+
const KIND_SET = new Set(DECL_KINDS);
|
|
3
|
+
const fail = (where, expected) => {
|
|
4
|
+
throw new Error(`Lean 事实的 JSON 无效,字段 ${where} 应为${expected}。`);
|
|
5
|
+
};
|
|
6
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7
|
+
const obj = (v, where) => (isObj(v) ? v : fail(where, "对象"));
|
|
8
|
+
const str = (v, where) => (typeof v === "string" ? v : fail(where, "字符串"));
|
|
9
|
+
const optStr = (v, where) =>
|
|
10
|
+
v === null || v === undefined ? undefined : str(v, where);
|
|
11
|
+
const bool = (v, where) =>
|
|
12
|
+
typeof v === "boolean" ? v : fail(where, "布尔值");
|
|
13
|
+
const int = (v, where) =>
|
|
14
|
+
typeof v === "number" && Number.isInteger(v) ? v : fail(where, "整数");
|
|
15
|
+
const optInt = (v, where) =>
|
|
16
|
+
v === null || v === undefined ? undefined : int(v, where);
|
|
17
|
+
const arr = (v, where) => (Array.isArray(v) ? v : fail(where, "数组"));
|
|
18
|
+
const strArr = (v, where) =>
|
|
19
|
+
arr(v, where).map((item, i) => str(item, `${where}[${i}]`));
|
|
20
|
+
const intArr = (v, where) =>
|
|
21
|
+
arr(v, where).map((item, i) => int(item, `${where}[${i}]`));
|
|
22
|
+
const declKind = (v, where) => {
|
|
23
|
+
const s = str(v, where);
|
|
24
|
+
if (!KIND_SET.has(s)) fail(where, `${DECL_KINDS.join("、")} 中的一种`);
|
|
25
|
+
return s;
|
|
26
|
+
};
|
|
27
|
+
const place = (v, where) => {
|
|
28
|
+
const o = obj(v, where);
|
|
29
|
+
return {
|
|
30
|
+
line: int(o.line, `${where}.line`),
|
|
31
|
+
column: int(o.column, `${where}.column`),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const optPlace = (v, where) =>
|
|
35
|
+
v === null || v === undefined ? undefined : place(v, where);
|
|
36
|
+
const span = (v, where) => {
|
|
37
|
+
const o = obj(v, where);
|
|
38
|
+
return {
|
|
39
|
+
line: int(o.line, `${where}.line`),
|
|
40
|
+
column: int(o.column, `${where}.column`),
|
|
41
|
+
endLine: int(o.endLine, `${where}.endLine`),
|
|
42
|
+
endColumn: int(o.endColumn, `${where}.endColumn`),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const sorryUse = (v, where) => {
|
|
46
|
+
const o = obj(v, where);
|
|
47
|
+
const owner = optStr(o.in, `${where}.in`);
|
|
48
|
+
return {
|
|
49
|
+
synthetic: bool(o.synthetic, `${where}.synthetic`),
|
|
50
|
+
at: optPlace(o.at, `${where}.at`),
|
|
51
|
+
...(owner !== undefined
|
|
52
|
+
? {
|
|
53
|
+
in: owner,
|
|
54
|
+
}
|
|
55
|
+
: {}),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const decl = (v, where) => {
|
|
59
|
+
const o = obj(v, where);
|
|
60
|
+
return {
|
|
61
|
+
name: str(o.name, `${where}.name`),
|
|
62
|
+
userName: str(o.userName, `${where}.userName`),
|
|
63
|
+
kind: declKind(o.kind, `${where}.kind`),
|
|
64
|
+
visible: bool(o.visible, `${where}.visible`),
|
|
65
|
+
isUserDef: bool(o.isUserDef, `${where}.isUserDef`),
|
|
66
|
+
module: str(o.module, `${where}.module`),
|
|
67
|
+
line: optInt(o.line, `${where}.line`),
|
|
68
|
+
doc: optStr(o.doc, `${where}.doc`),
|
|
69
|
+
statement: str(o.statement, `${where}.statement`),
|
|
70
|
+
group: strArr(o.group, `${where}.group`),
|
|
71
|
+
uses: strArr(o.uses, `${where}.uses`),
|
|
72
|
+
sorries: arr(o.sorries, `${where}.sorries`).map((item, i) =>
|
|
73
|
+
sorryUse(item, `${where}.sorries[${i}]`),
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const outside = (v, where) => {
|
|
78
|
+
const o = obj(v, where);
|
|
79
|
+
return {
|
|
80
|
+
name: str(o.name, `${where}.name`),
|
|
81
|
+
kind: declKind(o.kind, `${where}.kind`),
|
|
82
|
+
home: str(o.home, `${where}.home`),
|
|
83
|
+
axioms: strArr(o.axioms, `${where}.axioms`),
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const hyp = (v, where) => {
|
|
87
|
+
const o = obj(v, where);
|
|
88
|
+
return {
|
|
89
|
+
name: str(o.name, `${where}.name`),
|
|
90
|
+
type: str(o.type, `${where}.type`),
|
|
91
|
+
value: optStr(o.value, `${where}.value`),
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const goalFinal = (v, where) => {
|
|
95
|
+
const s = str(v, where);
|
|
96
|
+
if (s === "assigned" || s === "open" || s === "gone") return s;
|
|
97
|
+
return fail(where, "assigned、open 或 gone");
|
|
98
|
+
};
|
|
99
|
+
const goalClosedBy = (v, where) => {
|
|
100
|
+
if (v === null || v === undefined) return undefined;
|
|
101
|
+
const s = str(v, where);
|
|
102
|
+
if (s === "proof" || s === "sorry" || s === "error") return s;
|
|
103
|
+
return fail(where, "proof、sorry、error 或 null");
|
|
104
|
+
};
|
|
105
|
+
const goal = (v, where) => {
|
|
106
|
+
const o = obj(v, where);
|
|
107
|
+
return {
|
|
108
|
+
id: int(o.id, `${where}.id`),
|
|
109
|
+
tag: optStr(o.tag, `${where}.tag`),
|
|
110
|
+
hyps: intArr(o.hyps, `${where}.hyps`),
|
|
111
|
+
target: str(o.target, `${where}.target`),
|
|
112
|
+
final: goalFinal(o.final, `${where}.final`),
|
|
113
|
+
closedBy: goalClosedBy(o.closedBy, `${where}.closedBy`),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const step = (v, where) => {
|
|
117
|
+
const o = obj(v, where);
|
|
118
|
+
return {
|
|
119
|
+
id: int(o.id, `${where}.id`),
|
|
120
|
+
kind: str(o.kind, `${where}.kind`),
|
|
121
|
+
text: str(o.text, `${where}.text`),
|
|
122
|
+
span: span(o.span, `${where}.span`),
|
|
123
|
+
names: strArr(o.names, `${where}.names`),
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
const reachEntry = (v, where) => {
|
|
127
|
+
const pair = arr(v, where);
|
|
128
|
+
if (pair.length !== 2) fail(where, "[goalId, goalId[]] 二元组");
|
|
129
|
+
return [int(pair[0], `${where}[0]`), intArr(pair[1], `${where}[1]`)];
|
|
130
|
+
};
|
|
131
|
+
const event = (v, where) => {
|
|
132
|
+
const o = obj(v, where);
|
|
133
|
+
return {
|
|
134
|
+
step: int(o.step, `${where}.step`),
|
|
135
|
+
before: intArr(o.before, `${where}.before`),
|
|
136
|
+
after: intArr(o.after, `${where}.after`),
|
|
137
|
+
assigned: intArr(o.assigned, `${where}.assigned`),
|
|
138
|
+
declared: intArr(o.declared, `${where}.declared`),
|
|
139
|
+
reach: arr(o.reach, `${where}.reach`).map((item, i) =>
|
|
140
|
+
reachEntry(item, `${where}.reach[${i}]`),
|
|
141
|
+
),
|
|
142
|
+
children: arr(o.children, `${where}.children`).map((item, i) =>
|
|
143
|
+
event(item, `${where}.children[${i}]`),
|
|
144
|
+
),
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const root = (v, where) => {
|
|
148
|
+
const o = obj(v, where);
|
|
149
|
+
const w = str(o.where, `${where}.where`);
|
|
150
|
+
if (w === "body" || w === "term" || w === "termination") {
|
|
151
|
+
return {
|
|
152
|
+
goal: int(o.goal, `${where}.goal`),
|
|
153
|
+
where: w,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return fail(`${where}.where`, "body、term 或 termination");
|
|
157
|
+
};
|
|
158
|
+
const script = (v, where) => {
|
|
159
|
+
const o = obj(v, where);
|
|
160
|
+
const partial =
|
|
161
|
+
o.partial === undefined || o.partial === null
|
|
162
|
+
? false
|
|
163
|
+
: bool(o.partial, `${where}.partial`);
|
|
164
|
+
return {
|
|
165
|
+
bodyText: str(o.bodyText, `${where}.bodyText`),
|
|
166
|
+
roots: arr(o.roots, `${where}.roots`).map((item, i) =>
|
|
167
|
+
root(item, `${where}.roots[${i}]`),
|
|
168
|
+
),
|
|
169
|
+
goals: arr(o.goals, `${where}.goals`).map((item, i) =>
|
|
170
|
+
goal(item, `${where}.goals[${i}]`),
|
|
171
|
+
),
|
|
172
|
+
hyps: arr(o.hyps, `${where}.hyps`).map((item, i) =>
|
|
173
|
+
hyp(item, `${where}.hyps[${i}]`),
|
|
174
|
+
),
|
|
175
|
+
steps: arr(o.steps, `${where}.steps`).map((item, i) =>
|
|
176
|
+
step(item, `${where}.steps[${i}]`),
|
|
177
|
+
),
|
|
178
|
+
events: arr(o.events, `${where}.events`).map((item, i) =>
|
|
179
|
+
event(item, `${where}.events[${i}]`),
|
|
180
|
+
),
|
|
181
|
+
partial,
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
const message = (v, where) => {
|
|
185
|
+
const o = obj(v, where);
|
|
186
|
+
const sev = str(o.severity, `${where}.severity`);
|
|
187
|
+
if (sev === "error" || sev === "warning") {
|
|
188
|
+
return {
|
|
189
|
+
severity: sev,
|
|
190
|
+
at: place(o.at, `${where}.at`),
|
|
191
|
+
text: str(o.text, `${where}.text`),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return fail(`${where}.severity`, "error 或 warning");
|
|
195
|
+
};
|
|
196
|
+
export function readFacts(raw) {
|
|
197
|
+
const o = obj(raw, "root");
|
|
198
|
+
if (o.format !== FORMAT_VERSION) fail("format", `${FORMAT_VERSION}`);
|
|
199
|
+
return {
|
|
200
|
+
format: FORMAT_VERSION,
|
|
201
|
+
lean: str(o.lean, "lean"),
|
|
202
|
+
file: str(o.file, "file"),
|
|
203
|
+
module: str(o.module, "module"),
|
|
204
|
+
package: optStr(o.package, "package"),
|
|
205
|
+
target: str(o.target, "target"),
|
|
206
|
+
targetSpan: span(o.targetSpan, "targetSpan"),
|
|
207
|
+
axioms: strArr(o.axioms, "axioms"),
|
|
208
|
+
decls: arr(o.decls, "decls").map((item, i) => decl(item, `decls[${i}]`)),
|
|
209
|
+
outside: arr(o.outside, "outside").map((item, i) =>
|
|
210
|
+
outside(item, `outside[${i}]`),
|
|
211
|
+
),
|
|
212
|
+
script:
|
|
213
|
+
o.script === null || o.script === undefined
|
|
214
|
+
? undefined
|
|
215
|
+
: script(o.script, "script"),
|
|
216
|
+
messages: arr(o.messages, "messages").map((item, i) =>
|
|
217
|
+
message(item, `messages[${i}]`),
|
|
218
|
+
),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export function parseFacts(text) {
|
|
222
|
+
let parsed;
|
|
223
|
+
try {
|
|
224
|
+
parsed = JSON.parse(text);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`无法解析 Lean 事实 JSON:${error instanceof Error ? error.message : String(error)}`,
|
|
228
|
+
{
|
|
229
|
+
cause: error,
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
return readFacts(parsed);
|
|
234
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { inspect as inspectValue } from "node:util";
|
|
2
|
+
import { leanViewChecked } from "../ir.mjs";
|
|
3
|
+
const VIEW_EXPORTS = ["title", "lemma", "group", "branch", "caseLabel"];
|
|
4
|
+
const TITLE_KEYS = ["lemmas", "proof"];
|
|
5
|
+
const LEMMA_KEYS = ["label", "group", "hide"];
|
|
6
|
+
const BRANCH_KEYS = ["label", "detail"];
|
|
7
|
+
const isFunction = (v) => typeof v === "function";
|
|
8
|
+
const isPlainObject = (v) => {
|
|
9
|
+
if (typeof v !== "object" || v === null) return false;
|
|
10
|
+
const proto = Object.getPrototypeOf(v);
|
|
11
|
+
return proto === Object.prototype || proto === null;
|
|
12
|
+
};
|
|
13
|
+
const isValidLabel = (v) =>
|
|
14
|
+
typeof v === "string" &&
|
|
15
|
+
v.trim() !== "" &&
|
|
16
|
+
!/\bundefined\b|\bNaN\b|\[object Object\]/.test(v);
|
|
17
|
+
export function checkLeanView(view, inspect = inspectValue) {
|
|
18
|
+
const literal = (v) =>
|
|
19
|
+
typeof v === "string"
|
|
20
|
+
? JSON.stringify(v)
|
|
21
|
+
: inspect(v, {
|
|
22
|
+
breakLength: Infinity,
|
|
23
|
+
});
|
|
24
|
+
const extra = Object.keys(view).filter(
|
|
25
|
+
(name) => !VIEW_EXPORTS.includes(name),
|
|
26
|
+
);
|
|
27
|
+
if (extra.length > 0) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`不支持视图导出 ${extra.join("、")}。只允许导出 ${VIEW_EXPORTS.join("、")}。`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
let title;
|
|
33
|
+
const rawTitle = view.title;
|
|
34
|
+
if (rawTitle !== undefined) {
|
|
35
|
+
if (typeof rawTitle === "string") {
|
|
36
|
+
if (!isValidLabel(rawTitle)) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`视图的 title 必须是非空字符串,实际值为 ${literal(rawTitle)}。`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
title = {
|
|
42
|
+
lemmas: rawTitle,
|
|
43
|
+
proof: rawTitle,
|
|
44
|
+
};
|
|
45
|
+
} else if (isPlainObject(rawTitle)) {
|
|
46
|
+
const badKeys = Object.keys(rawTitle).filter(
|
|
47
|
+
(k) => !TITLE_KEYS.includes(k),
|
|
48
|
+
);
|
|
49
|
+
if (badKeys.length > 0) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`视图的 title 含有未知键 ${badKeys.join("、")}。只允许 ${TITLE_KEYS.join("、")}。`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const lemmas = rawTitle.lemmas;
|
|
55
|
+
const proof = rawTitle.proof;
|
|
56
|
+
if (lemmas !== undefined && !isValidLabel(lemmas)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`视图的 title.lemmas 必须是非空字符串,实际值为 ${literal(lemmas)}。`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (proof !== undefined && !isValidLabel(proof)) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`视图的 title.proof 必须是非空字符串,实际值为 ${literal(proof)}。`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
title = {
|
|
67
|
+
lemmas,
|
|
68
|
+
proof,
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"视图的 title 必须是字符串或普通对象 { lemmas?, proof? }。",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const wrong = [];
|
|
77
|
+
const pickFn = (name) => {
|
|
78
|
+
const v = view[name];
|
|
79
|
+
if (v === undefined || isFunction(v)) return v;
|
|
80
|
+
wrong.push(`${name} 必须是函数`);
|
|
81
|
+
return undefined;
|
|
82
|
+
};
|
|
83
|
+
const rawLemma = pickFn("lemma");
|
|
84
|
+
const rawGroup = pickFn("group");
|
|
85
|
+
const rawBranch = pickFn("branch");
|
|
86
|
+
const rawCaseLabel = pickFn("caseLabel");
|
|
87
|
+
if (wrong.length > 0) throw new Error(`视图导出无效:${wrong.join("、")}。`);
|
|
88
|
+
const lemma =
|
|
89
|
+
rawLemma &&
|
|
90
|
+
((info) => {
|
|
91
|
+
const res = rawLemma(info);
|
|
92
|
+
if (res === undefined) return undefined;
|
|
93
|
+
if (res === null)
|
|
94
|
+
return {
|
|
95
|
+
hide: true,
|
|
96
|
+
};
|
|
97
|
+
if (typeof res === "string") {
|
|
98
|
+
if (!isValidLabel(res)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`视图 lemma() 为 ${info.userName} 返回了 ${literal(res)}。应返回非空字符串、{ label, group?, hide? }、null 或 undefined。`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
hide: false,
|
|
105
|
+
label: res,
|
|
106
|
+
group: undefined,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (isPlainObject(res)) {
|
|
110
|
+
const badKeys = Object.keys(res).filter((k) => !LEMMA_KEYS.includes(k));
|
|
111
|
+
if (badKeys.length > 0) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`视图 lemma() 为 ${info.userName} 返回了未知键 ${badKeys.join("、")}。只允许 ${LEMMA_KEYS.join("、")}。`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (res.hide !== undefined && typeof res.hide !== "boolean") {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`视图 lemma() 为 ${info.userName} 返回的 hide 不是布尔值,实际值为 ${literal(res.hide)}。`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (res.hide === true)
|
|
122
|
+
return {
|
|
123
|
+
hide: true,
|
|
124
|
+
};
|
|
125
|
+
if (!isValidLabel(res.label)) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`视图 lemma() 为 ${info.userName} 返回了无效的 label ${literal(res.label)}。`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (res.group !== undefined && !isValidLabel(res.group)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`视图 lemma() 为 ${info.userName} 返回了无效的 group ${literal(res.group)}。`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
hide: false,
|
|
137
|
+
label: res.label,
|
|
138
|
+
group: res.group,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
throw new Error(
|
|
142
|
+
`视图 lemma() 为 ${info.userName} 返回了 ${literal(res)}。应返回非空字符串、{ label, group?, hide? }、null 或 undefined。`,
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
const group =
|
|
146
|
+
rawGroup &&
|
|
147
|
+
((info) => {
|
|
148
|
+
const res = rawGroup(info);
|
|
149
|
+
if (res === undefined || res === null) return res;
|
|
150
|
+
if (isValidLabel(res)) return res;
|
|
151
|
+
throw new Error(
|
|
152
|
+
`视图 group() 为 ${info.userName} 返回了 ${literal(res)}。应返回非空字符串、null 或 undefined。`,
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
const branch =
|
|
156
|
+
rawBranch &&
|
|
157
|
+
((info) => {
|
|
158
|
+
const res = rawBranch(info);
|
|
159
|
+
if (res === undefined) return undefined;
|
|
160
|
+
if (typeof res === "string") {
|
|
161
|
+
if (!isValidLabel(res)) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`视图 branch() 为 ${info.id} 返回了 ${literal(res)}。应返回非空字符串、{ label, detail? } 或 undefined。`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
label: res,
|
|
168
|
+
detail: undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (isPlainObject(res)) {
|
|
172
|
+
const badKeys = Object.keys(res).filter(
|
|
173
|
+
(k) => !BRANCH_KEYS.includes(k),
|
|
174
|
+
);
|
|
175
|
+
if (badKeys.length > 0) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`视图 branch() 为 ${info.id} 返回了未知键 ${badKeys.join("、")}。只允许 ${BRANCH_KEYS.join("、")}。`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (!isValidLabel(res.label)) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`视图 branch() 为 ${info.id} 返回了无效的 label ${literal(res.label)}。`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (res.detail !== undefined && !isValidLabel(res.detail)) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`视图 branch() 为 ${info.id} 返回了无效的 detail ${literal(res.detail)}。`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
label: res.label,
|
|
192
|
+
detail: res.detail,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
throw new Error(
|
|
196
|
+
`视图 branch() 为 ${info.id} 返回了 ${literal(res)}。应返回非空字符串、{ label, detail? } 或 undefined。`,
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
const caseLabel =
|
|
200
|
+
rawCaseLabel &&
|
|
201
|
+
((tag, info) => {
|
|
202
|
+
const res = rawCaseLabel(tag, info);
|
|
203
|
+
if (res === undefined) return undefined;
|
|
204
|
+
if (isValidLabel(res)) return res;
|
|
205
|
+
throw new Error(
|
|
206
|
+
`视图 caseLabel() 为 ${tag} 返回了 ${literal(res)}。应返回非空字符串或 undefined。`,
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
[leanViewChecked]: true,
|
|
211
|
+
title,
|
|
212
|
+
lemma,
|
|
213
|
+
group,
|
|
214
|
+
branch,
|
|
215
|
+
caseLabel,
|
|
216
|
+
};
|
|
217
|
+
}
|