@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,155 @@
|
|
|
1
|
+
import { byText, shortName, sortUnique, trustStatusOf } from "../ir.mjs";
|
|
2
|
+
function unhideableReason(input) {
|
|
3
|
+
if (input.name === input.target) return "该声明是目标定理";
|
|
4
|
+
const own = input.trust.own.get(input.name) ?? [];
|
|
5
|
+
if (own.some((d) => d.kind === "error")) return "含有失败步骤";
|
|
6
|
+
if (own.some((d) => d.kind === "sorry")) return "含有未证缺口(sorry)";
|
|
7
|
+
if (own.some((d) => d.kind === "native")) return "使用未经内核核验的原生计算";
|
|
8
|
+
if (
|
|
9
|
+
own.some((d) => d.kind === "axiom") ||
|
|
10
|
+
input.lemma.decl.kind === "axiom"
|
|
11
|
+
) {
|
|
12
|
+
return "是自定义公理或使用了自定义公理";
|
|
13
|
+
}
|
|
14
|
+
const below = input.trust.below.get(input.name) ?? [];
|
|
15
|
+
if (below.length > 0) return "依赖未证缺口或公理";
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
export function applyLemmaView(input) {
|
|
19
|
+
const { graph, trust, view } = input;
|
|
20
|
+
const labels = new Map();
|
|
21
|
+
const groups = new Map();
|
|
22
|
+
if (!view || (!view.lemma && !view.group)) {
|
|
23
|
+
return {
|
|
24
|
+
graph,
|
|
25
|
+
labels,
|
|
26
|
+
groups,
|
|
27
|
+
hiddenCount: 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const hidden = new Set();
|
|
31
|
+
const ordered = [
|
|
32
|
+
graph.target,
|
|
33
|
+
...[...graph.lemmas.keys()].filter((n) => n !== graph.target).sort(byText),
|
|
34
|
+
];
|
|
35
|
+
for (const name of ordered) {
|
|
36
|
+
const lemma = graph.lemmas.get(name);
|
|
37
|
+
if (!lemma) continue;
|
|
38
|
+
const info = {
|
|
39
|
+
name,
|
|
40
|
+
userName: lemma.decl.userName,
|
|
41
|
+
shortName: shortName(lemma.decl.userName),
|
|
42
|
+
kind: lemma.decl.kind,
|
|
43
|
+
module: lemma.decl.module,
|
|
44
|
+
line: lemma.decl.line,
|
|
45
|
+
doc: lemma.decl.doc,
|
|
46
|
+
statement: lemma.decl.statement,
|
|
47
|
+
isTarget: name === graph.target,
|
|
48
|
+
status: trustStatusOf({
|
|
49
|
+
own: trust.own.get(name) ?? [],
|
|
50
|
+
below: trust.below.get(name) ?? [],
|
|
51
|
+
}),
|
|
52
|
+
axioms: [...lemma.axioms],
|
|
53
|
+
library: [...lemma.library],
|
|
54
|
+
};
|
|
55
|
+
let groupFromLemma;
|
|
56
|
+
if (view.lemma) {
|
|
57
|
+
const answer = view.lemma(info);
|
|
58
|
+
if (answer?.hide) {
|
|
59
|
+
const reason = unhideableReason({
|
|
60
|
+
name,
|
|
61
|
+
lemma,
|
|
62
|
+
target: graph.target,
|
|
63
|
+
trust,
|
|
64
|
+
});
|
|
65
|
+
if (reason !== undefined) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`视图试图隐藏 ${lemma.decl.userName}(${reason})。视图仅可隐藏无疑点的辅助引理。`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
hidden.add(name);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (answer && !answer.hide) {
|
|
74
|
+
labels.set(name, answer.label);
|
|
75
|
+
groupFromLemma = answer.group;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (groupFromLemma !== undefined) {
|
|
79
|
+
groups.set(name, groupFromLemma);
|
|
80
|
+
} else if (view.group) {
|
|
81
|
+
const g = view.group(info);
|
|
82
|
+
if (g !== undefined) groups.set(name, g);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (hidden.size === 0) {
|
|
86
|
+
return {
|
|
87
|
+
graph,
|
|
88
|
+
labels,
|
|
89
|
+
groups,
|
|
90
|
+
hiddenCount: 0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const nextLemmas = new Map();
|
|
94
|
+
for (const name of ordered) {
|
|
95
|
+
if (hidden.has(name)) continue;
|
|
96
|
+
const lemma = graph.lemmas.get(name);
|
|
97
|
+
if (!lemma) continue;
|
|
98
|
+
const to = new Map();
|
|
99
|
+
const axioms = new Set(lemma.axioms);
|
|
100
|
+
const library = new Set(lemma.library);
|
|
101
|
+
const seenHidden = new Map();
|
|
102
|
+
const work = lemma.to.map((e) => ({
|
|
103
|
+
ref: e.name,
|
|
104
|
+
through: e.through,
|
|
105
|
+
}));
|
|
106
|
+
while (work.length > 0) {
|
|
107
|
+
const item = work.shift();
|
|
108
|
+
if (hidden.has(item.ref)) {
|
|
109
|
+
const prev = seenHidden.get(item.ref);
|
|
110
|
+
if (prev === "proof" || prev === item.through) continue;
|
|
111
|
+
seenHidden.set(item.ref, item.through);
|
|
112
|
+
const sub = graph.lemmas.get(item.ref);
|
|
113
|
+
if (!sub) continue;
|
|
114
|
+
for (const ax of sub.axioms) axioms.add(ax);
|
|
115
|
+
for (const lib of sub.library) library.add(lib);
|
|
116
|
+
for (const edge of sub.to) {
|
|
117
|
+
const nextThrough =
|
|
118
|
+
item.through === "definition" || edge.through === "definition"
|
|
119
|
+
? "definition"
|
|
120
|
+
: "proof";
|
|
121
|
+
work.push({
|
|
122
|
+
ref: edge.name,
|
|
123
|
+
through: nextThrough,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (item.ref === name) continue;
|
|
128
|
+
const prev = to.get(item.ref);
|
|
129
|
+
if (prev === undefined || item.through === "proof")
|
|
130
|
+
to.set(item.ref, item.through);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
nextLemmas.set(name, {
|
|
134
|
+
...lemma,
|
|
135
|
+
to: [...to.entries()]
|
|
136
|
+
.sort(([a], [b]) => byText(a, b))
|
|
137
|
+
.map(([edgeName, through]) => ({
|
|
138
|
+
name: edgeName,
|
|
139
|
+
through,
|
|
140
|
+
})),
|
|
141
|
+
axioms: sortUnique(axioms),
|
|
142
|
+
library: sortUnique(library),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
graph: {
|
|
147
|
+
target: graph.target,
|
|
148
|
+
lemmas: nextLemmas,
|
|
149
|
+
reducedEdges: graph.reducedEdges,
|
|
150
|
+
},
|
|
151
|
+
labels,
|
|
152
|
+
groups,
|
|
153
|
+
hiddenCount: hidden.size,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { buildLemmaChart } from "./backends/lemma-chart.mjs";
|
|
2
|
+
import { renderFlow } from "./backends/mermaid.mjs";
|
|
3
|
+
import { buildProofChart } from "./backends/proof-chart.mjs";
|
|
4
|
+
import { buildReport } from "./backends/report.mjs";
|
|
5
|
+
import { spanContainsPlace } from "./ir.mjs";
|
|
6
|
+
import { attribute } from "./passes/attribute.mjs";
|
|
7
|
+
import { buildBlocks } from "./passes/blocks.mjs";
|
|
8
|
+
import { budgetBlocks, budgetLemmas } from "./passes/budget.mjs";
|
|
9
|
+
import { checkAxioms, checkTree } from "./passes/check.mjs";
|
|
10
|
+
import { contract } from "./passes/contract.mjs";
|
|
11
|
+
import { foldSiblings } from "./passes/fold.mjs";
|
|
12
|
+
import { inlineBlocks } from "./passes/inline.mjs";
|
|
13
|
+
import { analyzeProofMarks } from "./passes/mark.mjs";
|
|
14
|
+
import { reduceLemmas } from "./passes/reduce.mjs";
|
|
15
|
+
import { analyzeTrust } from "./passes/trust.mjs";
|
|
16
|
+
import { applyLemmaView } from "./passes/view-lemmas.mjs";
|
|
17
|
+
function hasMarkInBlock(block, mark) {
|
|
18
|
+
if (block.marks.has(mark)) return true;
|
|
19
|
+
return block.into.some((child) => hasMarkInBlock(child, mark));
|
|
20
|
+
}
|
|
21
|
+
export function compileLean(facts, options = {}) {
|
|
22
|
+
const { view, tactics = false } = options;
|
|
23
|
+
const contracted = contract(facts);
|
|
24
|
+
checkAxioms({
|
|
25
|
+
facts,
|
|
26
|
+
graph: contracted,
|
|
27
|
+
});
|
|
28
|
+
const initialTrust = analyzeTrust(contracted);
|
|
29
|
+
const applied = applyLemmaView({
|
|
30
|
+
graph: contracted,
|
|
31
|
+
trust: initialTrust,
|
|
32
|
+
view,
|
|
33
|
+
});
|
|
34
|
+
if (applied.hiddenCount > 0)
|
|
35
|
+
checkAxioms({
|
|
36
|
+
facts,
|
|
37
|
+
graph: applied.graph,
|
|
38
|
+
});
|
|
39
|
+
const trust =
|
|
40
|
+
applied.hiddenCount > 0 ? analyzeTrust(applied.graph) : initialTrust;
|
|
41
|
+
const reduced = reduceLemmas({
|
|
42
|
+
graph: applied.graph,
|
|
43
|
+
trust,
|
|
44
|
+
});
|
|
45
|
+
checkAxioms({
|
|
46
|
+
facts,
|
|
47
|
+
graph: reduced,
|
|
48
|
+
});
|
|
49
|
+
const budgetedLemmas = budgetLemmas({
|
|
50
|
+
graph: reduced,
|
|
51
|
+
trust,
|
|
52
|
+
});
|
|
53
|
+
const lemmaFlow = buildLemmaChart({
|
|
54
|
+
budgeted: budgetedLemmas,
|
|
55
|
+
trust,
|
|
56
|
+
facts,
|
|
57
|
+
hiddenByView: applied.hiddenCount,
|
|
58
|
+
view,
|
|
59
|
+
viewLabels: applied.labels,
|
|
60
|
+
viewGroups: applied.groups,
|
|
61
|
+
});
|
|
62
|
+
const lemmasMmd = renderFlow(lemmaFlow);
|
|
63
|
+
let tree;
|
|
64
|
+
let allBlocks;
|
|
65
|
+
let budgetedProof;
|
|
66
|
+
let proofMmd;
|
|
67
|
+
let hasOpenGoals = false;
|
|
68
|
+
let hasProofFindings = false;
|
|
69
|
+
const hasErrors = facts.messages.some(
|
|
70
|
+
(m) => m.severity === "error" && spanContainsPlace(facts.targetSpan, m.at),
|
|
71
|
+
);
|
|
72
|
+
const targetHasDoubt =
|
|
73
|
+
trust.paths.length > 0 || (trust.below.get(facts.target)?.length ?? 0) > 0;
|
|
74
|
+
if (
|
|
75
|
+
facts.script &&
|
|
76
|
+
facts.script.roots.length > 0 &&
|
|
77
|
+
facts.script.steps.length > 0
|
|
78
|
+
) {
|
|
79
|
+
tree = attribute(facts.script);
|
|
80
|
+
checkTree({
|
|
81
|
+
script: facts.script,
|
|
82
|
+
tree,
|
|
83
|
+
});
|
|
84
|
+
const rawBlocks = buildBlocks(tree);
|
|
85
|
+
const { roots: marked, unattributedDoubt } = analyzeProofMarks({
|
|
86
|
+
roots: rawBlocks,
|
|
87
|
+
script: facts.script,
|
|
88
|
+
tree,
|
|
89
|
+
facts,
|
|
90
|
+
trust: initialTrust,
|
|
91
|
+
});
|
|
92
|
+
const inlined = inlineBlocks({
|
|
93
|
+
roots: marked,
|
|
94
|
+
script: facts.script,
|
|
95
|
+
});
|
|
96
|
+
allBlocks = foldSiblings({
|
|
97
|
+
roots: inlined,
|
|
98
|
+
script: facts.script,
|
|
99
|
+
});
|
|
100
|
+
budgetedProof = budgetBlocks({
|
|
101
|
+
roots: allBlocks,
|
|
102
|
+
});
|
|
103
|
+
hasOpenGoals = budgetedProof.roots.some((r) =>
|
|
104
|
+
hasMarkInBlock(r.block, "open"),
|
|
105
|
+
);
|
|
106
|
+
hasProofFindings = budgetedProof.roots.some(
|
|
107
|
+
(r) =>
|
|
108
|
+
hasMarkInBlock(r.block, "open") ||
|
|
109
|
+
hasMarkInBlock(r.block, "sorry") ||
|
|
110
|
+
hasMarkInBlock(r.block, "error") ||
|
|
111
|
+
hasMarkInBlock(r.block, "restsOn"),
|
|
112
|
+
);
|
|
113
|
+
const targetClean =
|
|
114
|
+
!targetHasDoubt && !hasErrors && !hasOpenGoals && !hasProofFindings;
|
|
115
|
+
const proofFlow = buildProofChart({
|
|
116
|
+
budgeted: budgetedProof,
|
|
117
|
+
script: facts.script,
|
|
118
|
+
facts,
|
|
119
|
+
graph: contracted,
|
|
120
|
+
targetClean,
|
|
121
|
+
allowProven: !unattributedDoubt,
|
|
122
|
+
tactics,
|
|
123
|
+
view,
|
|
124
|
+
});
|
|
125
|
+
proofMmd = renderFlow(proofFlow);
|
|
126
|
+
}
|
|
127
|
+
const reasons = [];
|
|
128
|
+
if (trust.paths.length > 0) {
|
|
129
|
+
reasons.push(
|
|
130
|
+
`${trust.paths.length} 条疑点依赖路径`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (hasOpenGoals) reasons.push("开放目标");
|
|
134
|
+
if (hasErrors) reasons.push("失败步骤");
|
|
135
|
+
if (hasProofFindings && reasons.length === 0)
|
|
136
|
+
reasons.push("未证步骤");
|
|
137
|
+
const verdict = {
|
|
138
|
+
clean: !targetHasDoubt && !hasErrors && !hasOpenGoals && !hasProofFindings,
|
|
139
|
+
reasons,
|
|
140
|
+
};
|
|
141
|
+
const report = buildReport({
|
|
142
|
+
facts,
|
|
143
|
+
graph: reduced,
|
|
144
|
+
budgetedLemmas,
|
|
145
|
+
trust,
|
|
146
|
+
verdict,
|
|
147
|
+
hiddenByView: applied.hiddenCount,
|
|
148
|
+
script: facts.script,
|
|
149
|
+
tree,
|
|
150
|
+
allBlocks,
|
|
151
|
+
budgetedBlocks: budgetedProof,
|
|
152
|
+
});
|
|
153
|
+
const exit = verdict.clean ? 0 : 1;
|
|
154
|
+
const files = new Map();
|
|
155
|
+
files.set("report.md", report);
|
|
156
|
+
files.set("lemmas.mmd", lemmasMmd);
|
|
157
|
+
if (proofMmd !== undefined) files.set("proof.mmd", proofMmd);
|
|
158
|
+
files.set("facts.json", JSON.stringify(facts, null, 2));
|
|
159
|
+
return {
|
|
160
|
+
report,
|
|
161
|
+
files,
|
|
162
|
+
exit,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { parseFacts } from "./frontends/facts.mjs";
|
|
8
|
+
import { SUPPORTED_LEAN } from "./ir.mjs";
|
|
9
|
+
|
|
10
|
+
const execute = promisify(execFile);
|
|
11
|
+
const EXTRACTOR_SHA256 = "61facbc8670af16694ce8ebdf46d1952f2cc17ccb21fcbdda7bb913f638a973e";
|
|
12
|
+
const lakefiles = ["lakefile.lean", "lakefile.toml"];
|
|
13
|
+
|
|
14
|
+
function findProject(file) {
|
|
15
|
+
const start = path.dirname(file);
|
|
16
|
+
let root, pin;
|
|
17
|
+
for (let dir = start; ; dir = path.dirname(dir)) {
|
|
18
|
+
const toolchain = path.join(dir, "lean-toolchain");
|
|
19
|
+
if (!pin && fs.existsSync(toolchain)) pin = toolchain;
|
|
20
|
+
if (!root && lakefiles.some(name => fs.existsSync(path.join(dir, name)))) root = dir;
|
|
21
|
+
if ((root && pin) || path.dirname(dir) === dir) return { root: root || start, lake: Boolean(root), pin };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function run(program, args, cwd, env) {
|
|
26
|
+
try {
|
|
27
|
+
const { stdout } = await execute(program, args, { cwd, env, windowsHide: true, maxBuffer: 64 * 1024 * 1024 });
|
|
28
|
+
return stdout.trim();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const details = error.stderr?.trim() || error.stdout?.trim() || error.message;
|
|
31
|
+
throw new Error(`无法执行 ${program} ${args[0]}(${error.code ?? error.signal})\n${details}`, { cause: error });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function copyExtractor(scratch) {
|
|
36
|
+
const configured = process.env.STATECHART_LEAN_EXTRACTOR;
|
|
37
|
+
if (!configured) throw new Error("请用 STATECHART_LEAN_EXTRACTOR 指定运行指南中固定版本的 Extract.lean。");
|
|
38
|
+
const bytes = fs.readFileSync(path.resolve(configured));
|
|
39
|
+
const digest = createHash("sha256").update(bytes).digest("hex");
|
|
40
|
+
if (digest !== EXTRACTOR_SHA256) throw new Error(`Lean 提取器 SHA-256 不符。预期 ${EXTRACTOR_SHA256},实际 ${digest}。`);
|
|
41
|
+
// 执行校验过的字节,避免本地工具文件在校验与使用之间发生变化。
|
|
42
|
+
const copy = path.join(scratch, "Extract.lean");
|
|
43
|
+
fs.writeFileSync(copy, bytes, { flag: "wx" });
|
|
44
|
+
return copy;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function resolveTools(project, cwd) {
|
|
48
|
+
if (project.pin) {
|
|
49
|
+
const entry = fs.readFileSync(project.pin, "utf8").split(/\r?\n/).map(l => l.trim()).find(l => l && !l.startsWith("#"));
|
|
50
|
+
const tag = entry?.split(":").at(-1)?.replace(/^v/, "");
|
|
51
|
+
if (`v${tag}` !== SUPPORTED_LEAN) throw new Error(`${project.pin} 指定 ${entry || "空版本"}。本工具需要 ${SUPPORTED_LEAN}。`);
|
|
52
|
+
}
|
|
53
|
+
const env = { ...process.env };
|
|
54
|
+
const bin = env.LEAN_SYSROOT ? path.resolve(env.LEAN_SYSROOT, "bin") : undefined;
|
|
55
|
+
const executable = name => bin ? path.join(bin, process.platform === "win32" ? name + ".exe" : name) : name;
|
|
56
|
+
if (bin) {
|
|
57
|
+
const key = Object.keys(env).find(k => process.platform === "win32" ? k.toUpperCase() === "PATH" : k === "PATH") || "PATH";
|
|
58
|
+
env[key] = [bin, env[key]].filter(Boolean).join(path.delimiter);
|
|
59
|
+
}
|
|
60
|
+
const lean = executable("lean");
|
|
61
|
+
const lake = executable("lake");
|
|
62
|
+
const version = await run(lean, ["--version"], cwd, env);
|
|
63
|
+
const actual = version.match(/\bversion\s+(\d+\.\d+\.\d+(?:-[\w.-]+)?)/i)?.[1];
|
|
64
|
+
if (`v${actual}` !== SUPPORTED_LEAN) throw new Error(`需要 Lean ${SUPPORTED_LEAN},实际为 ${version}。请核对 LEAN_SYSROOT 或 PATH。`);
|
|
65
|
+
const lakeVersion = await run(lake, ["--version"], cwd, env);
|
|
66
|
+
const paired = lakeVersion.match(/\bLean version\s+(\d+\.\d+\.\d+(?:-[\w.-]+)?)/i)?.[1];
|
|
67
|
+
if (!paired || `v${paired}` !== SUPPORTED_LEAN) throw new Error(`Lake 与 Lean ${SUPPORTED_LEAN} 不匹配:${lakeVersion}`);
|
|
68
|
+
return { lean, lake, lakeVersion, env };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isWithin(parent, candidate) {
|
|
72
|
+
const relative = path.relative(parent, candidate);
|
|
73
|
+
return relative === "" || (!path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(".." + path.sep));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function pathDependencies(root) {
|
|
77
|
+
const dependencies = new Set();
|
|
78
|
+
const manifest = path.join(root, "lake-manifest.json");
|
|
79
|
+
if (fs.existsSync(manifest)) {
|
|
80
|
+
const { packages } = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
81
|
+
for (const pkg of packages ?? []) {
|
|
82
|
+
if (pkg.type === "path" && typeof pkg.dir === "string") dependencies.add(pkg.dir);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 未生成清单的新工程也支持 Lake 的字面量本地依赖。其他配置交由 Lake 自己解析。
|
|
86
|
+
const toml = path.join(root, "lakefile.toml");
|
|
87
|
+
if (fs.existsSync(toml)) {
|
|
88
|
+
const config = fs.readFileSync(toml, "utf8");
|
|
89
|
+
for (const block of config.split(/^\s*\[\[require\]\]\s*(?:#.*)?$/m).slice(1)) {
|
|
90
|
+
const section = block.split(/^\s*\[/m, 1)[0];
|
|
91
|
+
const local = section.match(/^\s*path\s*=\s*["']([^"'\r\n]+)["']/m);
|
|
92
|
+
if (local) dependencies.add(local[1]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const lean = path.join(root, "lakefile.lean");
|
|
96
|
+
if (fs.existsSync(lean)) {
|
|
97
|
+
const config = fs.readFileSync(lean, "utf8");
|
|
98
|
+
for (const match of config.matchAll(/^\s*require\s+[^\n]+?\s+from\s+"([^"\r\n]+)"/gm)) dependencies.add(match[1]);
|
|
99
|
+
}
|
|
100
|
+
return dependencies;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function copyLakeProject(root, scratch) {
|
|
104
|
+
// 给每个源绝对路径对应一个副本,保留多包项目中 ../Dependency 的相对关系。
|
|
105
|
+
const workspace = path.join(scratch, "workspace");
|
|
106
|
+
const sourceVolume = path.parse(root).root;
|
|
107
|
+
const mirror = source => path.join(workspace, path.relative(sourceVolume, source));
|
|
108
|
+
const visited = new Set();
|
|
109
|
+
const copied = [];
|
|
110
|
+
function copyPackage(source) {
|
|
111
|
+
if (visited.has(source)) return;
|
|
112
|
+
visited.add(source);
|
|
113
|
+
if (isWithin(source, scratch)) throw new Error(`临时工作目录落在 Lake 源目录中,请将系统临时目录设在 ${source} 之外。`);
|
|
114
|
+
if (!fs.statSync(source, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`找不到 Lake 本地依赖目录 ${source}。`);
|
|
115
|
+
if (!lakefiles.some(name => fs.existsSync(path.join(source, name)))) throw new Error(`Lake 本地依赖目录缺少包配置:${source}`);
|
|
116
|
+
if (!copied.some(parent => isWithin(parent, source))) {
|
|
117
|
+
const destination = mirror(source);
|
|
118
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
119
|
+
fs.cpSync(source, destination, {
|
|
120
|
+
recursive: true, dereference: true, preserveTimestamps: true,
|
|
121
|
+
filter(file) {
|
|
122
|
+
const rel = path.relative(source, file).split(path.sep).join("/");
|
|
123
|
+
return ![".git", "temp/dev", "temp/system"].includes(rel);
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
copied.push(source);
|
|
127
|
+
}
|
|
128
|
+
for (const dir of pathDependencies(source)) {
|
|
129
|
+
if (path.isAbsolute(dir)) throw new Error(`Lake 本地依赖 ${dir} 使用绝对路径。请使用可在临时副本中解析的相对依赖路径。`);
|
|
130
|
+
copyPackage(path.resolve(source, dir));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
copyPackage(root);
|
|
134
|
+
return mirror(root);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function extractFacts(input, theorem) {
|
|
138
|
+
const file = fs.realpathSync(input);
|
|
139
|
+
const project = findProject(file);
|
|
140
|
+
const relativeFile = path.relative(project.root, file);
|
|
141
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), "lean-audit-"));
|
|
142
|
+
try {
|
|
143
|
+
const extractor = copyExtractor(scratch);
|
|
144
|
+
const cwd = project.lake ? copyLakeProject(project.root, scratch) : path.join(scratch, "source");
|
|
145
|
+
if (!project.lake) {
|
|
146
|
+
fs.mkdirSync(cwd);
|
|
147
|
+
fs.copyFileSync(file, path.join(cwd, relativeFile));
|
|
148
|
+
}
|
|
149
|
+
// 版本管理器会从工作目录向上查找 pin;临时副本也须继承原工程选定的版本。
|
|
150
|
+
const localPin = path.join(cwd, "lean-toolchain");
|
|
151
|
+
if (project.pin && !fs.existsSync(localPin)) fs.copyFileSync(project.pin, localPin);
|
|
152
|
+
const tools = await resolveTools(project, cwd);
|
|
153
|
+
const setup = project.lake
|
|
154
|
+
? await run(tools.lake, ["setup-file", relativeFile], cwd, tools.env)
|
|
155
|
+
: JSON.stringify({ name: path.basename(file, ".lean"), isModule: false, importArts: {}, dynlibs: [], plugins: [], options: {} });
|
|
156
|
+
const setupFile = path.join(scratch, "setup.json");
|
|
157
|
+
const factsFile = path.join(scratch, "facts.ndjson");
|
|
158
|
+
fs.writeFileSync(setupFile, setup);
|
|
159
|
+
await run(tools.lean, ["--run", extractor, setupFile, factsFile, relativeFile, theorem], cwd, tools.env);
|
|
160
|
+
const facts = parseFacts(fs.readFileSync(factsFile, "utf8"));
|
|
161
|
+
if (facts.lean !== SUPPORTED_LEAN || path.normalize(facts.file) !== path.normalize(relativeFile))
|
|
162
|
+
throw new Error(`事实与本轮编译器或文件不匹配:${facts.lean} / ${facts.file}`);
|
|
163
|
+
if (facts.target !== theorem && !facts.target.endsWith("." + theorem)) throw new Error(`事实中的定理 ${facts.target} 与请求 ${theorem} 不符。`);
|
|
164
|
+
return { facts, lakeVersion: tools.lakeVersion };
|
|
165
|
+
} finally {
|
|
166
|
+
fs.rmSync(scratch, { recursive: true, force: true });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
@@ -8,6 +8,7 @@ import { killGroup } from "./process-lifecycle.mjs";
|
|
|
8
8
|
import { messageOf } from "./run.mjs";
|
|
9
9
|
|
|
10
10
|
const USAGE = `用法:statechart SPEC.tla [--config FILE] [--view FILE] --out DIR
|
|
11
|
+
statechart FILE.lean THEOREM [--view FILE] [--tactics] --out DIR
|
|
11
12
|
|
|
12
13
|
使用 TLC 检查 SPEC.tla,并把状态图绘制为 Mermaid。超过 500 个状态时,只绘制
|
|
13
14
|
通向违规规则的路径;没有违规规则时,不生成 chart.mmd。
|
|
@@ -16,15 +17,20 @@ const USAGE = `用法:statechart SPEC.tla [--config FILE] [--view FILE] --out
|
|
|
16
17
|
group(vars)、colors 和 title。state() 返回字符串时生成平面图,
|
|
17
18
|
数组生成父状态,对象生成并行区域。默认显示各状态的值。
|
|
18
19
|
colors 为每个分组指定 blue、orange、purple、yellow、teal、tan 或 pink。
|
|
20
|
+
Lean 视图可导出 title、lemma、group、branch、caseLabel。
|
|
21
|
+
--tactics 在 Lean 证明树中显示原始 tactic。定理名支持完整名或唯一点分后缀。
|
|
19
22
|
--out DIR 写入 report.md、chart.mmd、tlc.out,以及每个违规时序属性和
|
|
20
23
|
图中未显示的违规规则的 tlc-RULE.out。指定目标项目 temp/dev/ 下的新目录或空目录。
|
|
21
24
|
退出码对应原样配置的 TLC 结果:全部规则成立为 0,规则被违反为 1,TLC 错误、
|
|
22
25
|
信号终止检查或命令无法运行为 2。SIGINT 和 SIGTERM 分别返回 130 和 143。
|
|
23
|
-
|
|
26
|
+
Lean 实跑写出 facts.json、report.md、lemmas.mmd,有 tactic 轨迹时还会写出 proof.mmd。
|
|
27
|
+
闭合且只依赖标准公理为 0,证明有发现为 1,输入或工具错误为 2。只有 0 和 1 发布结果。
|
|
28
|
+
TLC 需要本地 TLA2TOOLS 和 Java;Lean 需要 v4.34.1 与 STATECHART_LEAN_EXTRACTOR。
|
|
29
|
+
--help 显示帮助,启动器不联网安装工具。`;
|
|
24
30
|
|
|
25
|
-
let stop
|
|
26
|
-
const stopped = new Promise
|
|
27
|
-
for (const name of ["SIGINT", "SIGTERM"]
|
|
31
|
+
let stop;
|
|
32
|
+
const stopped = new Promise((resolve) => {
|
|
33
|
+
for (const name of ["SIGINT", "SIGTERM"])
|
|
28
34
|
process.on(name, () => {
|
|
29
35
|
stop ??= name;
|
|
30
36
|
resolve();
|
|
@@ -32,32 +38,49 @@ const stopped = new Promise ((resolve) => {
|
|
|
32
38
|
});
|
|
33
39
|
|
|
34
40
|
let flags;
|
|
35
|
-
let
|
|
41
|
+
let inputFile, mode, workerArgs;
|
|
36
42
|
try {
|
|
37
43
|
const args = parseArgs({
|
|
38
44
|
allowPositionals: true,
|
|
39
|
-
options: {
|
|
45
|
+
options: {
|
|
46
|
+
help: { type: "boolean" }, config: { type: "string" }, view: { type: "string" },
|
|
47
|
+
tactics: { type: "boolean" }, out: { type: "string" },
|
|
48
|
+
},
|
|
40
49
|
});
|
|
41
50
|
flags = args.values;
|
|
42
|
-
if (flags.help) { console.log(USAGE
|
|
43
|
-
[
|
|
44
|
-
|
|
51
|
+
if (flags.help) { console.log(USAGE); process.exit(0); }
|
|
52
|
+
[inputFile] = args.positionals;
|
|
53
|
+
const extension = path.extname(inputFile ?? "");
|
|
54
|
+
if (extension === ".lean") {
|
|
55
|
+
mode = "lean";
|
|
56
|
+
if (args.positionals.length !== 2 || !args.positionals[1].trim()) throw new Error("请提供 FILE.lean 和一个目标定理名。");
|
|
57
|
+
if (flags.config !== undefined) throw new Error("--config 只适用于 .tla 模型。");
|
|
58
|
+
workerArgs = [args.positionals[1], flags.tactics ? "1" : "0"];
|
|
59
|
+
} else if (extension === ".tla") {
|
|
60
|
+
mode = "tlc";
|
|
61
|
+
if (args.positionals.length !== 1) throw new Error("请提供一个 SPEC.tla。");
|
|
62
|
+
if (flags.tactics) throw new Error("--tactics 只适用于 .lean 定理。");
|
|
63
|
+
workerArgs = [flags.config ?? inputFile.replace(/\.tla$/, ".cfg")];
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error("主输入应为 .tla 模型或 .lean 定理文件。JavaScript 模型请使用自身的检查器。");
|
|
66
|
+
}
|
|
45
67
|
if (!flags.out) throw new Error("请用 --out DIR 指定本轮输出目录。");
|
|
68
|
+
if (!fs.statSync(inputFile, { throwIfNoEntry: false })?.isFile()) throw new Error(`找不到输入文件 ${inputFile}。`);
|
|
69
|
+
if (flags.view !== undefined && !fs.statSync(flags.view, { throwIfNoEntry: false })?.isFile()) throw new Error(`找不到视图文件 ${flags.view}。`);
|
|
46
70
|
} catch (error) {
|
|
47
71
|
console.error(`${messageOf(error)}\n\n${USAGE}`);
|
|
48
72
|
process.exit(2);
|
|
49
73
|
}
|
|
50
74
|
|
|
51
|
-
const codeOf = (error
|
|
75
|
+
const codeOf = (error) =>
|
|
52
76
|
error instanceof Error && "code" in error ? error.code : undefined;
|
|
53
77
|
|
|
54
78
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
throw new Error(`找不到 TLC 配置 ${configFile}。请传入 --config FILE。`);
|
|
79
|
+
if (mode === "tlc" && !fs.statSync(workerArgs[0], { throwIfNoEntry: false })?.isFile())
|
|
80
|
+
throw new Error(`找不到 TLC 配置 ${workerArgs[0]}。请传入 --config FILE。`);
|
|
58
81
|
const out = flags.out;
|
|
59
|
-
let entries
|
|
60
|
-
let dest
|
|
82
|
+
let entries = [];
|
|
83
|
+
let dest;
|
|
61
84
|
try {
|
|
62
85
|
entries = fs.readdirSync(out);
|
|
63
86
|
dest = fs.realpathSync(out);
|
|
@@ -83,9 +106,7 @@ try {
|
|
|
83
106
|
fs.mkdirSync(base, { recursive: true });
|
|
84
107
|
const stage = fs.mkdtempSync(path.join(base, `.${path.basename(dest)}.statechart-`));
|
|
85
108
|
const done = path.join(stage, "done");
|
|
86
|
-
let tmp
|
|
87
|
-
let janitor ;
|
|
88
|
-
let exitCode ;
|
|
109
|
+
let tmp, janitor, exitCode;
|
|
89
110
|
try {
|
|
90
111
|
tmp = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-"));
|
|
91
112
|
const runtime = process.execArgv;
|
|
@@ -94,9 +115,7 @@ try {
|
|
|
94
115
|
[
|
|
95
116
|
...runtime,
|
|
96
117
|
path.join(import.meta.dirname, "worker.mjs"),
|
|
97
|
-
stage,
|
|
98
|
-
specFile,
|
|
99
|
-
configFile,
|
|
118
|
+
mode, stage, path.resolve(out), inputFile, ...workerArgs,
|
|
100
119
|
...(flags.view ? [flags.view] : []),
|
|
101
120
|
],
|
|
102
121
|
{
|
|
@@ -114,7 +133,7 @@ try {
|
|
|
114
133
|
janitor.on("error", () => {});
|
|
115
134
|
const cleanupPipe = janitor.stdin;
|
|
116
135
|
cleanupPipe?.on("error", () => {});
|
|
117
|
-
const exited = new Promise
|
|
136
|
+
const exited = new Promise((resolve) =>
|
|
118
137
|
worker.once("error", () => resolve(2)).once("exit", (code) => {
|
|
119
138
|
cleanupPipe?.write("exited\n");
|
|
120
139
|
resolve(code ?? 2);
|
|
@@ -7,20 +7,46 @@ import { checkView } from "./frontends/view.mjs";
|
|
|
7
7
|
import { compile } from "./pipeline.mjs";
|
|
8
8
|
import { check, messageOf } from "./run.mjs";
|
|
9
9
|
|
|
10
|
-
const [stage,
|
|
10
|
+
const [mode, stage, output, input, ...args] = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
async function loadView(filename) {
|
|
13
|
+
return filename ? import(pathToFileURL(path.resolve(filename)).href) : {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function compileInput() {
|
|
17
|
+
if (mode === "tlc") {
|
|
18
|
+
const [config, viewFile] = args;
|
|
19
|
+
const view = checkView(await loadView(viewFile), inspect);
|
|
20
|
+
return compile(await check(input, config), view);
|
|
21
|
+
}
|
|
22
|
+
if (mode !== "lean") throw new Error(`未知检查模式 ${mode}`);
|
|
23
|
+
const [theorem, tactics, viewFile] = args;
|
|
24
|
+
const { checkLeanView } = await import("./lean/frontends/view.mjs");
|
|
25
|
+
const { compileLean } = await import("./lean/pipeline.mjs");
|
|
26
|
+
const { extractFacts } = await import("./lean/run.mjs");
|
|
27
|
+
const view = checkLeanView(await loadView(viewFile), inspect);
|
|
28
|
+
const { facts, lakeVersion } = await extractFacts(input, theorem);
|
|
29
|
+
const result = compileLean(facts, { view, tactics: tactics === "1" });
|
|
30
|
+
const command = ["node", path.join(import.meta.dirname, "statechart.mjs"), path.resolve(input), theorem];
|
|
31
|
+
if (viewFile) command.push("--view", path.resolve(viewFile));
|
|
32
|
+
if (tactics === "1") command.push("--tactics");
|
|
33
|
+
command.push("--out", output);
|
|
34
|
+
const receipt = [
|
|
35
|
+
"", "## 本次实跑", "", `源文件:${path.resolve(input)}`, `Lake:${lakeVersion}`, `退出码:${result.exit}`,
|
|
36
|
+
"", "执行参数如下。复跑时为 --out 指定新目录。", "", "```json", JSON.stringify(command), "```",
|
|
37
|
+
];
|
|
38
|
+
result.files.set("report.md", [result.report, ...receipt].join("\n"));
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
11
41
|
|
|
12
42
|
try {
|
|
13
|
-
const
|
|
14
|
-
viewFile ? await import(pathToFileURL(path.resolve(viewFile)).href) : {},
|
|
15
|
-
inspect,
|
|
16
|
-
);
|
|
17
|
-
const { files, exit } = compile(await check(specFile, configFile), view);
|
|
43
|
+
const { files, exit } = await compileInput();
|
|
18
44
|
const draft = path.join(stage, "draft");
|
|
19
45
|
fs.mkdirSync(draft);
|
|
20
46
|
for (const [name, parts] of files) {
|
|
21
47
|
const fd = fs.openSync(path.join(draft, name), "wx");
|
|
22
48
|
try {
|
|
23
|
-
for (const part of parts)
|
|
49
|
+
for (const part of typeof parts === "string" ? [parts] : parts)
|
|
24
50
|
fs.writeSync(fd, typeof part === "string" ? Buffer.from(part) : part);
|
|
25
51
|
fs.writeSync(fd, "\n");
|
|
26
52
|
} finally {
|