Files
curriculum-project-hub/spec/Spec/Courseware/Pipeline.lean
T
sjfhsjfh 09b026f598 feat(spec): backfill Export terminology + diagnostics/legality/pipeline (ADR-0009/0010)
Lift the business decisions the MVP made into the Lean master, per constitution
rule 5. lake build green (20 jobs), no sorry.

- Artifact.lean: `inductive Artifact | singleFile | fileTree` — product shape is
  part of a target's value (ADR-0009); it determines the assemble/reduce step.
- Render.lean reworked target-centric (ADR-0009, amends ADR-0005's matrix):
  `TargetSpec` carries `artifact` + a per-kind `renders` map (field visibility
  lives in this map); `RenderConfig.spec : TargetId → Option TargetSpec`; `covers`
  rewritten (target must exist AND its map covers the kind) — semantics continuous
  with ADR-0005 so renderIgnored still typechecks. `BuildStepForm` (declarative |
  shell) is a structural anchor for the build form (shell hatch = ADR-0005's
  medium-only category b) without replicating the schema.
- Diagnostic.lean extended: `DiagKind` (7 classes) + `DiagKind.severity` (six
  error, renderIgnored warning); `Oracle` makes external-facility verdicts
  (compiles/refsResolve/dataConforms/contentFilesPresent) an explicit
  implementation boundary; `Legal` = no error-level diagnostic (backfills
  ADR-0005's deferred full-legality), with renderIgnored deliberately excluded
  (it's a warning).
- Pipeline.lean: the 5 phases (load→structural→schema→compile→coverage) as
  structure — order + the compile gate (compile runs only on zero prior errors) +
  load halts the pipeline. Algorithms stay out of Lean (depth ceiling).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 08:36:29 +08:00

73 lines
2.9 KiB
Lean4

import Spec.Courseware.Diagnostic
/-!
# Pipeline —— checker 检查管线的阶段与序(ADR-0010)
checker 的 `check` 按**固定顺序**跑五个阶段,逐阶段收集诊断;`compile` 阶段有**门控**。
顺序与门控是契约——它决定用户看到哪些诊断(藏在缺文件背后的语法错,在文件补齐前不显示,
这是**有意**的)。每阶段的**算法**不进 Lean(宪法第 5 条深度上限):本模块只钉**阶段、序、
门控**,不形式化每步怎么算。
阶段与上游模块的对应:`load` ← `cph-model`;`structural` ← part 路径/未知 kind;`schema`
← `cph-schema`;`compile` ← `cph-typst`(模型外设施,见 `Diagnostic.Oracle`);`coverage`
← `Diagnostic.renderIgnored`。
-/
namespace Spec.Courseware
/--
检查管线的**阶段**(`PINNED` 5 阶段, ADR-0010)。
- `load` —— 解析 manifest + 各 element.toml。硬失败(无可解析 lesson)则**停**整条管线。
- `structural` —— part 路径存在、无 `..`、kind 已知、part 与 element kind 一致。此处已被
判缺的 part,在后续阶段**跳过**(不在同一根因上堆诊断)。
- `schema` —— 每个"存在且 kind 已知"的 part 的数据按其 kind schema 校验(标量 + content 文件)。
- `compile` —— 模型外设施阶段(typst 编译)。**门控:仅当 `load`/`structural`/`schema` 零
error 才跑**(否则在已知坏输入上编译只是噪声)。跑时对每个声明的 target 编译(ADR-0009)。
- `coverage` —— 语义型 warning 规则(`renderIgnored`);**不**受门控,总跑。
-/
inductive Phase where
| load
| structural
| schema
| compile
| coverage
deriving DecidableEq
/--
管线阶段的**执行序**(`PINNED`, ADR-0010)。`order p` 越小越先跑。
序是契约:`compile`(3)排在 `structural`(1)/`schema`(2)之后,正因前者门控于后者无 error。
`coverage`(4)排最后但不门控(见 `gated`)。
-/
def Phase.order : Phase Nat
| .load => 0
| .structural => 1
| .schema => 2
| .compile => 3
| .coverage => 4
/--
某阶段是否**受"前序零 error"门控**(`PINNED`, ADR-0010)。
唯 `compile` 受门控:前序(load/structural/schema)出任何 error 则跳过它——藏在结构/schema
错背后的编译错,在前者修好前不显示,这是有意的降噪。其余阶段不门控:`load` 是入口,
`structural`/`schema` 是门控的**依据**(自身得先跑),`coverage` 产 warning 故无条件跑。
-/
def Phase.gated : Phase Bool
| .compile => true
| _ => false
/--
管线在 `load` 硬失败时**停**(`PINNED`, ADR-0010)。
`load` 拿不到可解析的 lesson(`cph-model` 返回 `none`)时,没有 lesson 可喂给下游,
整条管线就此终止——这是唯一会"截断"后续所有阶段的情形(区别于 `compile` 的门控只跳过
自己)。
-/
def Phase.haltsPipelineOnFailure : Phase Bool
| .load => true
| _ => false
end Spec.Courseware