softschema 0.9.0__tar.gz → 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. softschema-0.9.0/README.md → softschema-0.9.1/PKG-INFO +51 -0
  2. softschema-0.9.0/PKG-INFO → softschema-0.9.1/README.md +23 -28
  3. {softschema-0.9.0 → softschema-0.9.1}/docs/development.md +9 -5
  4. {softschema-0.9.0 → softschema-0.9.1}/docs/installation.md +34 -19
  5. {softschema-0.9.0 → softschema-0.9.1}/docs/softschema-guide.md +116 -20
  6. {softschema-0.9.0 → softschema-0.9.1}/docs/softschema-python-design.md +22 -11
  7. {softschema-0.9.0 → softschema-0.9.1}/docs/softschema-typescript-design.md +21 -6
  8. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/_portable.py +83 -20
  9. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/cli.py +59 -9
  10. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_c_parser.py +297 -1
  11. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_cli.py +0 -43
  12. softschema-0.9.1/packages/python/tests/test_doctor.py +231 -0
  13. {softschema-0.9.0 → softschema-0.9.1}/pyproject.toml +7 -5
  14. softschema-0.9.1/skills/softschema/SKILL.md +206 -0
  15. softschema-0.9.0/skills/softschema/SKILL.md +0 -161
  16. {softschema-0.9.0 → softschema-0.9.1}/.gitignore +0 -0
  17. {softschema-0.9.0 → softschema-0.9.1}/LICENSE +0 -0
  18. {softschema-0.9.0 → softschema-0.9.1}/docs/agent-repair.runbook.md +0 -0
  19. {softschema-0.9.0 → softschema-0.9.1}/docs/e2e-testing.runbook.md +0 -0
  20. {softschema-0.9.0 → softschema-0.9.1}/docs/publishing-npm.md +0 -0
  21. {softschema-0.9.0 → softschema-0.9.1}/docs/publishing.md +0 -0
  22. {softschema-0.9.0 → softschema-0.9.1}/docs/softschema-spec.md +0 -0
  23. {softschema-0.9.0 → softschema-0.9.1}/examples/__init__.py +0 -0
  24. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/README.md +0 -0
  25. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/__init__.py +0 -0
  26. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/host_integration.py +0 -0
  27. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/model.py +0 -0
  28. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/movie-page.schema.yaml +0 -0
  29. {softschema-0.9.0 → softschema-0.9.1}/examples/movie_page/spirited-away.md +0 -0
  30. {softschema-0.9.0 → softschema-0.9.1}/examples/parity/__init__.py +0 -0
  31. {softschema-0.9.0 → softschema-0.9.1}/examples/parity/model.py +0 -0
  32. {softschema-0.9.0 → softschema-0.9.1}/examples/parity/parity.schema.yaml +0 -0
  33. {softschema-0.9.0 → softschema-0.9.1}/packages/python/README.md +0 -0
  34. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/__init__.py +0 -0
  35. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/_identity.py +0 -0
  36. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/canonicalize.py +0 -0
  37. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/compile.py +0 -0
  38. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/conform.py +0 -0
  39. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/enforcement.py +0 -0
  40. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/errors.py +0 -0
  41. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/generate.py +0 -0
  42. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/models.py +0 -0
  43. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/pipeline.py +0 -0
  44. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/py.typed +0 -0
  45. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/registry.py +0 -0
  46. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/repair.py +0 -0
  47. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/schema_view.py +0 -0
  48. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/soft_field.py +0 -0
  49. {softschema-0.9.0 → softschema-0.9.1}/packages/python/src/softschema/validate.py +0 -0
  50. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/fixtures/execution_model.py +0 -0
  51. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_canonicalize.py +0 -0
  52. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_core.py +0 -0
  53. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_doc_topics_resolve.py +0 -0
  54. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_enforced_extras.py +0 -0
  55. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_enforcement_clarity.py +0 -0
  56. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_errors.py +0 -0
  57. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_generate.py +0 -0
  58. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_identity.py +0 -0
  59. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_json_fast_path.py +0 -0
  60. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_metadata_rules.py +0 -0
  61. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_movie_page_example.py +0 -0
  62. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_parity.py +0 -0
  63. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_repair_conform.py +0 -0
  64. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_schema_view.py +0 -0
  65. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_skill_mirror_drift.py +0 -0
  66. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_soft_field.py +0 -0
  67. {softschema-0.9.0 → softschema-0.9.1}/packages/python/tests/test_warning_codes.py +0 -0
  68. {softschema-0.9.0 → softschema-0.9.1}/packages/typescript/LICENSE +0 -0
  69. {softschema-0.9.0 → softschema-0.9.1}/packages/typescript/README.md +0 -0
  70. {softschema-0.9.0 → softschema-0.9.1}/tests/golden/README.md +0 -0
  71. {softschema-0.9.0 → softschema-0.9.1}/tests/vectors/README.md +0 -0
@@ -1,3 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: softschema
3
+ Version: 0.9.1
4
+ Summary: Gradual contracts for YAML data, with optional Markdown context
5
+ Project-URL: Homepage, https://github.com/jlevy/softschema
6
+ Project-URL: Repository, https://github.com/jlevy/softschema
7
+ Project-URL: Issues, https://github.com/jlevy/softschema/issues
8
+ Author: Joshua Levy
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: <4.0,>=3.11
22
+ Requires-Dist: frontmatter-format>=0.5.1
23
+ Requires-Dist: jsonschema>=4.20
24
+ Requires-Dist: pydantic>=2
25
+ Requires-Dist: ruamel-yaml!=0.19.0,>=0.18
26
+ Requires-Dist: strif>=3.1.0
27
+ Description-Content-Type: text/markdown
28
+
1
29
  # softschema
2
30
 
3
31
  `softschema` applies gradual contracts to YAML data.
@@ -347,6 +375,29 @@ so a document cannot silently redirect a host’s validation; a contract registe
347
375
  without a schema path lets self-describing documents bind themselves.
348
376
  See the [softschema Guide](docs/softschema-guide.md) for the full playbooks.
349
377
 
378
+ ## Performance
379
+
380
+ Write clean, readable YAML by default.
381
+ A document of tens of KB parses in milliseconds (up to about 50 ms in pure Python), and
382
+ starting the CLI (0.2–0.4 s installed, about 0.7 s through `uvx` and 1.3 s through
383
+ `npx`) costs more than reading the file.
384
+ The format matters only for megabytes parsed often, in a hot loop, CI over many files,
385
+ or a service:
386
+
387
+ | 1 MB of records | Python | TypeScript (Node or Bun) |
388
+ | --- | --- | --- |
389
+ | Block YAML | ~1 s with `ruamel.yaml.clib`, ~6 s without | ~0.7–1 s |
390
+ | JSON syntax (valid YAML) | ~75 ms | ~0.7–1 s |
391
+
392
+ Then, in order: write the data as JSON syntax (Python reads strict JSON with the
393
+ standard `json` module); keep tabs out of block YAML, which send a Python document from
394
+ the C parser to the slower pure one; in Python, install `ruamel.yaml.clib`, not
395
+ `ruamel.yaml[libyaml]` (`softschema doctor` should report `yaml parser: c-first`); and
396
+ validate many files in one process through the library rather than one CLI run per file.
397
+ Results are the same on every path; only speed changes.
398
+ The [guide](docs/softschema-guide.md#performance) has the measurements and exactly what
399
+ keeps a file on each fast path.
400
+
350
401
  ## Use as an Agent Skill
351
402
 
352
403
  Both packages ship the same [`SKILL.md`](https://agentskills.io) following the open
@@ -1,31 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: softschema
3
- Version: 0.9.0
4
- Summary: Gradual contracts for YAML data, with optional Markdown context
5
- Project-URL: Homepage, https://github.com/jlevy/softschema
6
- Project-URL: Repository, https://github.com/jlevy/softschema
7
- Project-URL: Issues, https://github.com/jlevy/softschema/issues
8
- Author: Joshua Levy
9
- License-Expression: MIT
10
- License-File: LICENSE
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Programming Language :: Python :: 3.14
20
- Classifier: Typing :: Typed
21
- Requires-Python: <4.0,>=3.11
22
- Requires-Dist: frontmatter-format>=0.5.0
23
- Requires-Dist: jsonschema>=4.20
24
- Requires-Dist: pydantic>=2
25
- Requires-Dist: ruamel-yaml>=0.18
26
- Requires-Dist: strif>=3.1.0
27
- Description-Content-Type: text/markdown
28
-
29
1
  # softschema
30
2
 
31
3
  `softschema` applies gradual contracts to YAML data.
@@ -375,6 +347,29 @@ so a document cannot silently redirect a host’s validation; a contract registe
375
347
  without a schema path lets self-describing documents bind themselves.
376
348
  See the [softschema Guide](docs/softschema-guide.md) for the full playbooks.
377
349
 
350
+ ## Performance
351
+
352
+ Write clean, readable YAML by default.
353
+ A document of tens of KB parses in milliseconds (up to about 50 ms in pure Python), and
354
+ starting the CLI (0.2–0.4 s installed, about 0.7 s through `uvx` and 1.3 s through
355
+ `npx`) costs more than reading the file.
356
+ The format matters only for megabytes parsed often, in a hot loop, CI over many files,
357
+ or a service:
358
+
359
+ | 1 MB of records | Python | TypeScript (Node or Bun) |
360
+ | --- | --- | --- |
361
+ | Block YAML | ~1 s with `ruamel.yaml.clib`, ~6 s without | ~0.7–1 s |
362
+ | JSON syntax (valid YAML) | ~75 ms | ~0.7–1 s |
363
+
364
+ Then, in order: write the data as JSON syntax (Python reads strict JSON with the
365
+ standard `json` module); keep tabs out of block YAML, which send a Python document from
366
+ the C parser to the slower pure one; in Python, install `ruamel.yaml.clib`, not
367
+ `ruamel.yaml[libyaml]` (`softschema doctor` should report `yaml parser: c-first`); and
368
+ validate many files in one process through the library rather than one CLI run per file.
369
+ Results are the same on every path; only speed changes.
370
+ The [guide](docs/softschema-guide.md#performance) has the measurements and exactly what
371
+ keeps a file on each fast path.
372
+
378
373
  ## Use as an Agent Skill
379
374
 
380
375
  Both packages ship the same [`SKILL.md`](https://agentskills.io) following the open
@@ -9,7 +9,7 @@ clean-environment checks CI cannot run—is codified in the
9
9
  Set up the repo (Python deps, Node tooling for hooks, and the git hooks themselves):
10
10
 
11
11
  ```bash
12
- make install # uv sync --all-extras + npm install (lefthook)
12
+ make install # uv sync --all-extras + npm install (lefthook) + bun install
13
13
  make hooks-install # install the lefthook pre-commit hooks
14
14
  ```
15
15
 
@@ -57,8 +57,9 @@ Hooks are managed by [lefthook](https://lefthook.dev) (`lefthook.yml`), installe
57
57
  `make hooks-install`. The `pre-commit` hook formats staged changes so commits stay
58
58
  clean:
59
59
 
60
- - **Markdown:** delegates to `make format` (pinned `flowmark-rs` and
61
- `softschema generate`); the single source of truth, the same command you run locally.
60
+ - **Markdown:** delegates to `make format` (pinned `flowmark-rs`, `softschema generate`,
61
+ and the skill-mirror install); the single source of truth, the same command you run
62
+ locally.
62
63
  - **Python:** `ruff format` and `ruff check --fix` on staged `*.py`.
63
64
  - **TypeScript:** `biome check --write` on staged files in `packages/typescript`.
64
65
 
@@ -247,7 +248,7 @@ The parity invariants, and where each is enforced:
247
248
  | Structurally equal JSON and exact stable human output | the shared golden corpus (run twice via `SOFTSCHEMA_IMPL`) |
248
249
  | Equal flag/command surface | per-impl and neutral golden scenarios |
249
250
  | Bundled docs/skill resolve from the package | the standalone test (`packages/typescript/test/standalone.test.ts`) |
250
- | Skill mirrors never go stale | the mirror drift test (`tests/test_skill_mirror_drift.py`) |
251
+ | Skill mirrors never go stale | the mirror drift tests (`packages/python/tests/test_skill_mirror_drift.py`, `packages/typescript/test/mirror-drift.test.ts`) |
251
252
 
252
253
  Semantic invariants that JSON Schema cannot express (Pydantic validators ↔ Zod
253
254
  refinements) are implementation-specific by design and tested per-language, not in the
@@ -270,7 +271,10 @@ through a different number of records, and normalizing the difference away would
270
271
  real information. Two cases ship today, both in the `engine_deviations` section of
271
272
  `tests/vectors/hardening.yaml`: `dependentSchemas` (ajv adds a closure record for a
272
273
  property that top-level `properties` already evaluated) and `anyOf` multiplicity (ajv
273
- reports each branch’s failure alongside the `anyOf`).
274
+ reports each branch’s failure alongside the `anyOf`). Execution and verdict differences
275
+ on degenerate schemas, such as a lone `if` or a `$dynamicRef` with no matching anchor,
276
+ are pinned the same way in the `engine_deviations` list of
277
+ `tests/vectors/validation-execution.yaml`; the spec lists them.
274
278
 
275
279
  The mechanism is deliberately not a tolerance.
276
280
  Each runtime asserts *its own* listed record set exactly, so:
@@ -36,25 +36,40 @@ npx softschema --help # resolves the local pinned copy
36
36
 
37
37
  ### Faster YAML Parsing in Python
38
38
 
39
- The Python implementation reads YAML with ruamel.yaml.
40
- Its C extension, `ruamel.yaml.clib`, is optional in ruamel.yaml 0.19, while the 0.18.x
41
- releases declare it as a dependency on CPython (0.18.10 below Python 3.13, 0.18.17 below
42
- 3.15), so an install that resolves to 0.18 gets it without asking.
43
- With the extension present, large YAML artifacts parse several times faster; a 0.19
44
- install adds it with `uv add --dev ruamel.yaml.clib`. Results do not change: softschema
45
- uses the C parser only where it reads a document exactly as the pure parser does, and
46
- the pure parser decides everything else.
47
- It also uses the C parser only for the libyaml build and ruamel releases it was checked
48
- against (libyaml 0.1.7 as bundled by `ruamel.yaml.clib` 0.2.8 through 0.2.15, with
49
- ruamel.yaml 0.18 and 0.19) and reads everything with the pure parser on any other
50
- combination. Install `ruamel.yaml.clib` itself (ruamel.yaml’s `oldlibyaml` extra), not
51
- the `libyaml` extra: that one installs `ruamel.yaml.clibz`, which ruamel.yaml 0.19 does
52
- not use, so softschema stays on the pure parser.
53
- A `uv tool install softschema` user adds the extension with `--with ruamel.yaml.clib`.
54
- `softschema.yaml_parser_mode()` returns `"c-first"` when the C parser is in use and
55
- `"pure"` otherwise, `softschema doctor` reports the same with the reason (not installed,
56
- another build or release, or turned off), and `SOFTSCHEMA_PURE_YAML=1` turns the C
57
- parser off.
39
+ The Python implementation reads YAML with ruamel.yaml, which can use an optional C
40
+ extension, `ruamel.yaml.clib`: a Cython wrapper around a lightly patched libyaml 0.1.7,
41
+ with prebuilt wheels for CPython 3.9–3.14 on Linux, macOS, and Windows.
42
+ ruamel.yaml 0.18 depended on it on CPython below a Python-version cap (below 3.13 for
43
+ 0.18.0–0.18.10, below 3.14 for 0.18.11–0.18.16, and below 3.15 for 0.18.17), so most
44
+ 0.18 releases install without it on Python 3.13 and 3.14. ruamel.yaml 0.19.0 depended on
45
+ `ruamel.yaml.clibz` instead, and since 0.19.1 the C extension is opt-in (the
46
+ `oldlibyaml` extra).
47
+ The newer `ruamel.yaml.clibz` is the same libyaml, compiled with Zig at install time and
48
+ published only as source; ruamel’s `YAML()` API does not use it, so it gives no speedup
49
+ here. softschema never reads with clibz, and requires ruamel.yaml 0.18 or later except
50
+ 0.19.0, the one release that builds clibz by default.
51
+
52
+ libyaml parses YAML 1.1 and pure ruamel YAML 1.2, so they disagree on some texts.
53
+ softschema gives libyaml only the texts on which the two were shown to agree, and reads
54
+ the rest, and anything libyaml rejects, with pure ruamel.
55
+ It uses libyaml only for clib’s libyaml 0.1.7 on ruamel.yaml 0.18–0.19, so results are
56
+ the same either way; only speed changes, several times faster on large documents (see
57
+ [Performance](softschema-guide.md#performance) in the guide).
58
+
59
+ To get the speedup, install `ruamel.yaml.clib` (`uv add ruamel.yaml.clib`, or
60
+ `--with ruamel.yaml.clib` for `uv tool install` and `uvx`), not `ruamel.yaml[libyaml]`:
61
+
62
+ ```bash
63
+ uv add ruamel.yaml.clib # in a project
64
+ uv tool install softschema --with ruamel.yaml.clib # persistent CLI
65
+ uvx --with ruamel.yaml.clib softschema@latest doctor # zero-install
66
+ ```
67
+
68
+ A bare `uvx softschema@latest` runs the pure parser.
69
+ `softschema.yaml_parser_mode()` returns `"c-first"` when libyaml is in use and `"pure"`
70
+ otherwise, `softschema doctor` reports the same with the reason (not installed, clibz
71
+ installed but unused, another build or release, or turned off), and
72
+ `SOFTSCHEMA_PURE_YAML=1` forces the pure parser.
58
73
 
59
74
  ## Zero-Install
60
75
 
@@ -289,8 +289,10 @@ Start with one document type, not a whole repository:
289
289
  3. **Move the consumed values into YAML frontmatter** under one envelope key (for
290
290
  example, `movie:` for a movie page, `incident:` for an incident review).
291
291
  4. **Add `softschema.contract`** with a stable contract ID.
292
- 5. **Pick a status.** Start with `status: soft` (no validation) or `status: permissive`
293
- (validate known fields under the bound model or schema’s authored extension policy).
292
+ 5. **Pick a status.** Start with `status: soft` (a named convention; nothing need be
293
+ bound yet) or `status: permissive` (validate known fields under the bound model or
294
+ schema’s authored extension policy).
295
+ A schema or model bound to the artifact checks the payload under either status.
294
296
  Save `enforced` for later.
295
297
  6. **Leave the body alone.** Headings, prose, and tables for human readers stay.
296
298
  7. **Validate at the boundary** (next playbook) and tighten over time.
@@ -450,6 +452,8 @@ Wire a Pydantic model to a contract and validate at file boundaries:
450
452
  classes when the structure is settled.
451
453
 
452
454
  ```python
455
+ from typing import Literal
456
+
453
457
  from pydantic import BaseModel, ConfigDict, Field
454
458
 
455
459
  class IncidentReview(BaseModel):
@@ -468,9 +472,9 @@ Wire a Pydantic model to a contract and validate at file boundaries:
468
472
  --out schemas/incident-review.v1.schema.yaml
469
473
  ```
470
474
 
471
- **Trust note:** `--model` imports and executes local Python code.
472
- Use it only with trusted models.
473
- For untrusted input, use `--schema` with a compiled JSON Schema instead.
475
+ **Trust note:** `compile`, like `validate --model`, imports and executes local Python
476
+ code. Use it only with trusted models.
477
+ For untrusted input, validate with `--schema` and a compiled JSON Schema instead.
474
478
 
475
479
  3. **Bind artifacts to their schema.** Add `schema:` (and `envelope:` when needed) to
476
480
  each artifact’s `softschema:` block so `softschema validate <doc>` works with no
@@ -628,9 +632,9 @@ Two checks belong in CI:
628
632
  --out schemas/incident-review.v1.schema.yaml --check
629
633
  ```
630
634
 
631
- **Trust note:** `--model` imports and executes local Python code.
632
- Use it only with trusted models.
633
- For untrusted input, use `--schema` with a compiled JSON Schema instead.
635
+ **Trust note:** `compile`, like `validate --model`, imports and executes local Python
636
+ code. Use it only with trusted models.
637
+ For untrusted input, validate with `--schema` and a compiled JSON Schema instead.
634
638
 
635
639
  - **Artifact validation.** When artifacts carry the full self-description quartet
636
640
  (`contract`, `schema`, `envelope`, `status`), validation needs no per-file flags.
@@ -797,10 +801,10 @@ The `format: date`, `format: date-time`, `format: time`, and `format: duration`
797
801
  in a compiled schema are annotations, not structural assertions.
798
802
  For schema-only lexical rejection, add a portable `pattern` explicitly.
799
803
  The compiler removes Zod’s intrinsic ISO date, datetime, time, and duration patterns so
800
- structurally corresponding Pydantic and Zod fields produce the same format-only sidecar;
801
- an authored Zod regex remains intact.
802
- The sidecar and its digest therefore describe structural parity, not equality of every
803
- semantic model option.
804
+ structurally corresponding Pydantic and Zod fields produce the same format-only compiled
805
+ schema; an authored Zod regex remains intact.
806
+ The compiled schema and its digest therefore describe structural parity, not equality of
807
+ every semantic model option.
804
808
  The validation result’s `values` mapping remains portable strings; host code that needs
805
809
  native date objects should construct its model explicitly from that mapping.
806
810
  See [Portable YAML Values](softschema-spec.md#portable-yaml-values) for the exact rule.
@@ -1070,6 +1074,85 @@ siblings decide what counts as declared, what Draft 2020-12 guarantees, and wher
1070
1074
  The [spec](softschema-spec.md#rejecting-undeclared-properties-under-enforced) states the
1071
1075
  normative rules and the support matrix.
1072
1076
 
1077
+ ## Performance
1078
+
1079
+ **Write clean, readable YAML by default.** At the sizes people read and edit, the format
1080
+ makes no practical difference: a 10 KB document parses in under 10 ms in TypeScript or
1081
+ in Python with the C parser (about 50 ms in pure Python), while starting the CLI takes
1082
+ 0.2–0.4 s for an installed command, about 0.7 s for `uvx`, and about 1.3 s for `npx`,
1083
+ with a warm cache.
1084
+
1085
+ **When to switch.** The format matters only for megabytes of structured data parsed
1086
+ often: in a hot loop, in CI over many files, or in a service.
1087
+ Parse times for the same records, on one machine:
1088
+
1089
+ | Document | Python, C-first | Python, pure | Python, JSON syntax | TypeScript (Node or Bun) |
1090
+ | --- | --- | --- | --- | --- |
1091
+ | 10 KB | ~8 ms | ~50 ms | under 1 ms | ~6–8 ms |
1092
+ | 100 KB | ~80 ms | ~0.5 s | ~6 ms | ~70 ms |
1093
+ | 1 MB | ~1 s | ~6 s | ~75 ms | ~0.7–1 s |
1094
+ | 10 MB | ~18 s | ~80 s | ~1 s | ~8–12 s |
1095
+
1096
+ Checking the schema adds a few tenths of a second per MB in Python and less in
1097
+ TypeScript. Below about 100 KB, a CLI run is mostly startup, except for block YAML in
1098
+ pure-Python mode. Past about 1 MB parsed more than occasionally, choose the format
1099
+ deliberately.
1100
+
1101
+ **How to switch, in order:**
1102
+
1103
+ 1. **Write the data as JSON syntax.** A JSON object is valid YAML, so a `.json` or
1104
+ `.yaml` file holding one is a pure-yaml artifact and validates the same way.
1105
+ Python reads it with the standard `json` module when ruamel would read the text
1106
+ identically: more than 10 times faster than block YAML with the C parser, and 80 to
1107
+ 100 times faster than without it.
1108
+ The text stays on that path when it is strict JSON (no comments, trailing commas,
1109
+ `NaN`, or `Infinity`) with an object or array root and only spaces and line breaks
1110
+ around it, has no duplicate or `<<` keys and no key longer than 128 characters, keeps
1111
+ each key on the line of its colon, writes non-ASCII characters raw or as `\uXXXX`
1112
+ escapes outside the surrogate range, and contains no `-0` followed by anything but a
1113
+ digit, `.`, or `e` (inside a string too), on ruamel.yaml 0.18 or 0.19. Python’s
1114
+ `json.dumps` escapes an emoji as a surrogate pair by default; pass
1115
+ `ensure_ascii=False`. A text that misses any of these still reads correctly, at YAML
1116
+ speed. TypeScript has no JSON path: the `yaml` package reads JSON syntax at about the
1117
+ speed of block YAML.
1118
+ 2. **Keep block YAML off the slow shapes.** With the C parser active, Python reads the
1119
+ whole document with the pure parser, 4 to 7 times slower, when it contains a tab
1120
+ anywhere (in a comment or a quoted string too; write `"\t"` instead), a line that
1121
+ starts with `%` or `...`, a colon right after a space or quote with no space after it
1122
+ (`x :y`, or JSON-style `{"a":1}` inside a YAML document), or a block scalar whose
1123
+ first line holds only spaces.
1124
+ Block style also reads about 30% faster than flow collections there.
1125
+ In TypeScript a tab costs about 60% extra, and style otherwise makes little
1126
+ difference.
1127
+ 3. **In Python, install the C extension.** ruamel.yaml’s optional `ruamel.yaml.clib`
1128
+ reads block YAML 4 to 7 times faster with identical results: softschema hands libyaml
1129
+ only the texts on which it was shown to agree with pure ruamel, and only for clib’s
1130
+ libyaml 0.1.7 on ruamel.yaml 0.18–0.19. Install `ruamel.yaml.clib`
1131
+ (`uv add ruamel.yaml.clib`, or `--with ruamel.yaml.clib` for `uv tool install` and
1132
+ `uvx`), not `ruamel.yaml[libyaml]`: its `ruamel.yaml.clibz` is not used by ruamel’s
1133
+ `YAML()` API, and softschema never reads with it.
1134
+ A bare `uvx softschema@latest` runs the pure parser.
1135
+ `softschema.yaml_parser_mode()` returns `"c-first"` when libyaml is in use and
1136
+ `"pure"` otherwise, `softschema doctor` prints the same with the reason, and
1137
+ `SOFTSCHEMA_PURE_YAML=1` forces the pure parser; [Installation](installation.md) has
1138
+ the details. frontmatter-format 0.5.1, which the Python package uses to write compiled
1139
+ schemas, reads YAML C-first the same way in its own readers, behind the same build
1140
+ gate (`FRONTMATTER_FORMAT_PURE_YAML=1` turns it off there); softschema validates with
1141
+ its own reader, so that switch does not affect validation.
1142
+ 4. **Batch files in one process.** `softschema validate` takes one path, so a loop that
1143
+ runs it per file pays process startup each time: 1,000 small files take several
1144
+ minutes that way and about a second through `validate_artifact` or `validateArtifact`
1145
+ in one process.
1146
+
1147
+ Frontmatter is read by the same parser, so a large frontmatter block costs the same per
1148
+ KB and JSON-syntax frontmatter gets the same Python fast path.
1149
+ Keep frontmatter small enough to read, and put bulk data in a standalone pure-yaml or
1150
+ JSON artifact.
1151
+
1152
+ **Measure it.** Time `softschema validate` on a representative file in both forms, check
1153
+ which parser Python uses with `softschema doctor` or `yaml_parser_mode()`, and compare
1154
+ with `SOFTSCHEMA_PURE_YAML=1` to see what the C parser saves.
1155
+
1073
1156
  ## Common Mistakes
1074
1157
 
1075
1158
  - **Parsing a Markdown body.** Body tables and prose exist for human readers.
@@ -1091,6 +1174,15 @@ normative rules and the support matrix.
1091
1174
  - **Adding a contract with no consumer.** A `soft` convention can precede validation,
1092
1175
  but it still coordinates a producer and a consumer.
1093
1176
  If nobody reads the YAML payload, a contract ID is decoration.
1177
+ - **Writing YAML only one engine reads.** Both implementations refuse text the Python
1178
+ and TypeScript YAML engines would read differently, so the refusal is loud rather than
1179
+ a silent difference: a number such as `1_000`, `0b101`, or `.5e3`, a raw control or
1180
+ line-separator character, a tab in a plain value, a glued flow indicator such as
1181
+ `[a:, b]`, and any directive but `%YAML 1.2`. Write core-form numbers (`1000`) or
1182
+ quote, escape characters inside double quotes (`"\N"`), and run `softschema repair`,
1183
+ which fixes the cases it can.
1184
+ The exact rules are in
1185
+ [Portable YAML Values](softschema-spec.md#portable-yaml-values).
1094
1186
  - **Formalizing fields no consumer needs.** Keep uncertain YAML values as extension
1095
1187
  fields until their meaning stabilizes.
1096
1188
  In a Markdown artifact, leave background, analysis, and caveats in the body unless a
@@ -1104,12 +1196,15 @@ The Python public surface:
1104
1196
 
1105
1197
  - `Contract`: maps a contract ID to a Pydantic model and optional compiled JSON Schema.
1106
1198
  - `Contracts`: host-owned mapping from contract IDs to contracts.
1107
- - `validate_artifact(path, contract_id=..., registry=...)`: validates a file at a
1108
- boundary; returns a structured `ArtifactValidationResult` with separate `structural`
1109
- and `semantic` reports.
1110
- - `validate_values(values, model=..., schema=...)`: validates a values dict produced by
1111
- any consumer (frontmatter, body-form runtime, structured-output adapter, hand-written
1112
- fixture).
1199
+ - `validate_artifact(path, contract_id=..., registry=..., require=...)`: validates a
1200
+ file at a boundary; returns a structured `ArtifactValidationResult` with separate
1201
+ `structural` and `semantic` reports, each with its `execution`. `require` names the
1202
+ checks that must complete.
1203
+ - `load_artifact(...)`: the same call for consuming code; it returns the payload values
1204
+ and raises `ArtifactInvalidError` on anything short of valid.
1205
+ - `validate_values(values, model=..., schema=..., require=...)`: validates a values dict
1206
+ produced by any consumer (frontmatter, body-form runtime, structured-output adapter,
1207
+ hand-written fixture).
1113
1208
  - `compile_model(model_cls, out_path, contract_id=..., schema_id=...)`: emits a
1114
1209
  deterministic JSON Schema YAML file.
1115
1210
  The required contract ID names the payload; the optional schema ID is a separate JSON
@@ -1118,8 +1213,9 @@ The Python public surface:
1118
1213
  The TypeScript package mirrors this surface (`validateArtifact`, `validateValues`,
1119
1214
  `compileSchema`) with Zod models; both CLIs expose the same commands.
1120
1215
 
1121
- The CLI mirrors the library: `softschema validate`, `softschema compile`,
1122
- `softschema inspect`, `softschema generate`, `softschema docs`, `softschema skill`.
1216
+ The CLI mirrors the library: `softschema validate`, `softschema repair`,
1217
+ `softschema compile`, `softschema inspect`, `softschema generate`, `softschema docs`,
1218
+ `softschema skill`, `softschema prime`, and `softschema doctor`.
1123
1219
 
1124
1220
  A host application typically registers complete contracts during startup and validates
1125
1221
  artifacts at file boundaries:
@@ -261,12 +261,15 @@ the comparison is rerun; that costs only speed.
261
261
 
262
262
  ruamel’s optional C extension (`ruamel.yaml.clib`) is libyaml, a YAML 1.1 scanner and
263
263
  parser; ruamel’s constructor and resolver stay in Python either way.
264
- softschema uses it when it is installed and is the libyaml build the guards below were
265
- derived for (`CHECKED_LIBYAML_VERSION`, on a ruamel release inside
266
- `CHECKED_RUAMEL_VERSIONS`), and pure ruamel stays the definition of every result:
267
- `yaml_parser_mode()` reports `"c-first"` then, and `"pure"` when the extension is
268
- absent, is another build, or `SOFTSCHEMA_PURE_YAML` is set to anything but empty or `0`;
269
- `softschema doctor` reports the same.
264
+ softschema uses it when ruamel’s `YAML()` parser comes from `ruamel.yaml.clib`
265
+ (`CHECKED_C_PARSER_MODULES`) and is the libyaml build the guards below were derived for
266
+ (`CHECKED_LIBYAML_VERSION`, on a ruamel release inside `CHECKED_RUAMEL_VERSIONS`), and
267
+ pure ruamel stays the definition of every result: `yaml_parser_mode()` reports
268
+ `"c-first"` then, and `"pure"` when the extension is absent, is another build (such as
269
+ `ruamel.yaml.clibz`, which bundles the same libyaml but is never admitted), runs on a
270
+ ruamel release outside the checked range, or `SOFTSCHEMA_PURE_YAML` is set to anything
271
+ but empty or `0`. `softschema doctor` reports the same with the reason from
272
+ `yaml_parser_reason()`, which also says when clibz is installed but unused.
270
273
  On ordinary documents libyaml reads exactly what pure ruamel reads, several times
271
274
  faster. Where the two differ, libyaml usually rejects what pure ruamel accepts (a URL
272
275
  inside a flow sequence, a reserved directive) or words the error differently, so any
@@ -437,8 +440,11 @@ directory under the user home.
437
440
  The project intentionally uses generated copies rather than symlinks because agent
438
441
  discovery paths and package registries do not share one portable symlink model.
439
442
  Full copies are also easier for users and agents to inspect after installation.
440
- The mirrors carry a `DO NOT EDIT` marker and source digest and are regenerated from the
441
- source skill; the drift test verifies the managed wrapper and source payload.
443
+ The mirrors carry a `DO NOT EDIT` marker after the skill’s frontmatter and are
444
+ regenerated from the source skill; the drift tests
445
+ (`packages/python/tests/test_skill_mirror_drift.py` and
446
+ `packages/typescript/test/mirror-drift.test.ts`) compare each committed mirror with the
447
+ install payload byte for byte.
442
448
 
443
449
  When adding another agent target, extend `SKILL_INSTALL_TARGETS`, regenerate from the
444
450
  source skill, and update the drift test for the new managed target.
@@ -471,13 +477,18 @@ emitted code that isn’t a `WarningCode` member fails CI.
471
477
 
472
478
  `StructuralResult.errors[*].kind` uses a separate `snake_case` namespace because errors
473
479
  are blocking, not advisory.
474
- The current first-release kinds:
480
+ The current kinds:
475
481
 
476
482
  | Kind | Meaning |
477
483
  | --- | --- |
478
484
  | `artifact_unreadable` | The artifact cannot be opened. |
479
485
  | `artifact_invalid_utf8` | The artifact is not valid UTF-8. |
480
- | `yaml_parse_error` | YAML or frontmatter could not be parsed. |
486
+ | `yaml_parse_error` | YAML or frontmatter could not be parsed, or uses a construct the two YAML engines read differently: a raw control or line-separator character, a tab in a plain scalar or block spacing, a glued flow indicator, an under-indented flow continuation line, an over-long implicit key, or a directive other than `%YAML 1.2` and `%TAG`. |
487
+ | `yaml_unsupported_scalar` | A plain scalar only one engine reads as a number (`1_000`, `0b101`, `-0x10`, `.5e3`), or a lone surrogate. |
488
+ | `yaml_duplicate_key`, `yaml_alias`, `yaml_merge_key`, `yaml_custom_tag`, `yaml_non_string_key` | A duplicate key, an anchor or alias, a `<<` merge key, an explicit tag, or a non-string key. |
489
+ | `yaml_limit` | More than 64 simultaneously open collections. |
490
+ | `number_out_of_range` | An integer outside the safe range (`abs < 2^53`), or a non-finite number. |
491
+ | `number_negative_zero` | A negative zero, integer or float. |
481
492
  | `no_frontmatter` | Frontmatter block is missing in a Markdown artifact. |
482
493
  | `frontmatter_not_mapping` | Frontmatter parsed but is not a mapping at the top level. |
483
494
  | `yaml_not_mapping` | Pure-YAML artifact root is not a mapping. |
@@ -489,7 +500,7 @@ The current first-release kinds:
489
500
  | `document_softschema_invalid` | `softschema:` metadata block is malformed (unknown keys, bad shape, invalid `contract`). |
490
501
  | `document_contract_mismatch` | Document’s `softschema.contract` does not match the registered contract’s `id` (enforced metadata mode). |
491
502
  | `schema_missing` | A compiled schema is bound (a `schema_path` or `softschema.schema`) but the file does not exist, is unreadable, or fails bounded resolution (absolute path or path escaping the document directory and working directory). |
492
- | `schema_invalid` | The bound file is not a valid compiled schema (for example a non-mapping YAML root). |
503
+ | `schema_invalid` | The bound file is not a valid compiled schema (for example a non-mapping YAML root). A `reason` names the class where one applies: `dialect`, `pattern`, `reference`, `resource_identity`, or `shared_subschema`. |
493
504
  | `enforcement_unsupported` | The schema is valid Draft 2020-12, but its topology is outside the checked enforced profile; `reason` and `schema_path` identify the boundary. |
494
505
  | `schema_violation` | A JSON Schema validation error (engine-neutral; see Engine-neutral structural errors above). |
495
506
  | `check_not_completed` | A layer named in `require` did not complete. It carries `layer` and `execution` and is appended after existing errors; a required semantic layer receives the same record in `SemanticResult.errors`. |
@@ -18,7 +18,7 @@ test; see the parity development process in [development.md](development.md).
18
18
  | Module | Purpose |
19
19
  | --- | --- |
20
20
  | `models` | `Contract`, status/profile unions, `SchemaMetadata`, `WarningCode`, `parseSchemaMetadata` |
21
- | `portable` | Bounded UTF-8 reading and portable YAML value decoding |
21
+ | `portable` | Strict UTF-8 reading and portable YAML value decoding |
22
22
  | `registry` | `Contracts`: resolve contracts by id |
23
23
  | `canonicalize` | The shared canonical JSON Schema profile (same rules as Python) |
24
24
  | `enforcement` | Checked enforced-profile analysis and offline schema-resource graph preparation |
@@ -31,7 +31,7 @@ test; see the parity development process in [development.md](development.md).
31
31
  | `conform` | `conformArtifact`: retype a scalar to the string its contract declares, reading both validation layers |
32
32
  | `repairValidate` | `repairAndValidateArtifact`: the escalating pass, writing once |
33
33
  | `generate` | `parseSections`/`regenerate`: deterministic generated Markdown sections |
34
- | `cli` | `commander` program: `validate`, `repair` (with `--dry-run`/`--check`), `compile`, `inspect`, `docs`, `generate`, `skill` |
34
+ | `cli` | `commander` program: `validate`, `repair` (with `--dry-run`/`--check`), `compile`, `inspect`, `docs`, `generate`, `prime`, `doctor`, `skill` |
35
35
 
36
36
  ## Idiomatic Zod Choices
37
37
 
@@ -55,6 +55,20 @@ portable domain. The configured parser already decodes implicit date- and
55
55
  timestamp-shaped scalars as strings, so softschema does not apply a separate lexical
56
56
  rejection or timestamp constructor.
57
57
 
58
+ Before parsing, `checkPortableText` rejects the raw characters the two engines read
59
+ differently, the same preflight Python runs, and `checkDirectives` admits only
60
+ `%YAML 1.2` and `%TAG`. The checks over the parsed tree then refuse what ruamel would
61
+ read differently or refuse: a tab in a plain scalar or block spacing, a glued flow
62
+ indicator, a number form outside the YAML 1.2 core schema, a long or multi-line implicit
63
+ flow-mapping key, spaces past an explicit block-scalar indentation indicator, an entry
64
+ the `yaml` package would compose with content left out, and nesting past 64 collections.
65
+ Duplicate keys are found in one pass with a set per mapping, with `uniqueKeys: false`
66
+ passed to the parser, because the `yaml` package’s own check compares each key with
67
+ every earlier key and is quadratic in a mapping’s width.
68
+ The `yaml` package is pure JavaScript, so the reader gives the same results under Node
69
+ and Bun at similar speed, and it has no separate JSON path: JSON-syntax text is parsed
70
+ as YAML like any other.
71
+
58
72
  Host-native JavaScript objects are outside the portable domain and are rejected when
59
73
  programmatic field metadata is checked.
60
74
  Arrays, plain objects, and null-prototype objects remain portable; values such as
@@ -142,8 +156,8 @@ matching `tuple[()]`. The compiler also drops `type: "string"` from a record’s
142
156
  schema, which every JSON key satisfies and Pydantic never emits there.
143
157
 
144
158
  Zod ISO datetime options such as offset, local-time, and precision affect semantic
145
- validation but are not represented in the canonical sidecar or `schema_sha256`. The
146
- digest proves structural parity; it does not prove identical semantic accept sets.
159
+ validation but are not represented in the canonical compiled schema or `schema_sha256`.
160
+ The digest proves structural parity; it does not prove identical semantic accept sets.
147
161
 
148
162
  Ajv runs with `validateFormats: false`, matching JSON Schema Draft 2020-12’s default
149
163
  Format-Annotation vocabulary and the Python runtime.
@@ -296,8 +310,9 @@ byte encoding is reserved for the compiled-schema digest.
296
310
 
297
311
  bun (runtime and package manager), `bunup` (build), `bun test` (unit), `biome` (lint and
298
312
  format), `tsc --noEmit` (types).
299
- Dependencies: `zod`, `yaml`, `commander`, `ajv` (`ajv/dist/2020`), and `atomically`. The
300
- shared `tests/golden/` corpus runs against this CLI via `SOFTSCHEMA_IMPL=ts`.
313
+ Dependencies: `zod` (`^4.6.6`), `yaml`, `commander`, `ajv` (`ajv/dist/2020`), and
314
+ `atomically`. The shared `tests/golden/` corpus runs against this CLI via
315
+ `SOFTSCHEMA_IMPL=ts`.
301
316
 
302
317
  ## Packaging
303
318