feat(checker): cph-schema — 4 kind JSON Schemas + validation (WU-3)

Declarative JSON Schema per kind (segment/example/lemma/sop), embedded as real
.json artifacts (ADR-0006) and validated by a small hand-rolled interpreter
(properties/required/type/enum/additionalProperties + the `x-cph-content`
marker) — no jsonschema-crate churn for a one-optional-string scalar surface.
`x-cph-content: true` marks content fields (not in element.toml; require sibling
<field>.typ); everything else is an element.toml scalar. `validate(desc)` is
self-contained: UnknownKind for unknown kinds, MissingContentFile (path named in
message) for absent required .typ, SchemaViolation for bad scalars; lemma proof
optional ⇒ no diagnostic when absent. 8 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-22 01:33:40 +08:00
parent c17af60bb0
commit 752a5c661d
12 changed files with 661 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "cph:kind/example",
"title": "example",
"type": "object",
"properties": {
"problem": { "type": "string", "x-cph-content": true },
"solution": { "type": "string", "x-cph-content": true },
"source": { "type": "string" }
},
"required": ["problem", "solution"],
"additionalProperties": false
}
+12
View File
@@ -0,0 +1,12 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "cph:kind/lemma",
"title": "lemma",
"type": "object",
"properties": {
"stmt": { "type": "string", "x-cph-content": true },
"proof": { "type": "string", "x-cph-content": true }
},
"required": ["stmt"],
"additionalProperties": false
}
+11
View File
@@ -0,0 +1,11 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "cph:kind/segment",
"title": "segment",
"type": "object",
"properties": {
"textbook": { "type": "string", "x-cph-content": true }
},
"required": ["textbook"],
"additionalProperties": false
}
+11
View File
@@ -0,0 +1,11 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "cph:kind/sop",
"title": "sop",
"type": "object",
"properties": {
"sop": { "type": "string", "x-cph-content": true }
},
"required": ["sop"],
"additionalProperties": false
}