--- type: types/type-spec.md name: type-spec description: Authoring and validation contract for path-valued Chemenu type specifications schema: types/type-spec.schema.yaml --- # Type spec A type-spec doc is the authoring and validation contract for one Chemenu artifact type. Artifact frontmatter stores the repo-relative path to this doc in `type:`, and this file serves several consumers differently: an author writing a new instance reads it for what to write, someone unfamiliar with the type reads it for what to expect from an instance before opening one, and the validator and the type-conformance reviewer read it to check conformance. ## Required Frontmatter - `type`: `types/type-spec.md`. The root type spec is self-referential and uses the same value. - `name`: short human-facing type name. This is also the type's logical "kind" - tooling resolves an instance's `type:` path to this `name` instead of hardcoding a type-path-to-kind mapping. - `description`: retrieval description for the type contract. - `schema`: repo-relative path to the `.schema.yaml` file that validates artifacts of this type, or `null` when the type has no schema. - `subtype_field` (optional): the frontmatter field name on instances of this type that carries a subtype/category (e.g. `entity_type`), or omitted if this type has no such field. ## Validation Contract Two systems check conformance to a type: - **The deterministic validator** checks the symbolic half: frontmatter fields, enums, path patterns, and syntactic body shape (required headings, section counts, date formats) — whatever the named `.schema.yaml` can statically specify. It parses structure; it never judges meaning. - **The type-conformance review gate** checks the semantic half: everything about an instance that is not mechanically checkable — a `description`'s routing quality, a title's claim-shape, whether the body's claims hold up — judged against this file's body, read as natural-language authoring instructions applied by an LLM reviewer. Do not restate a schema rule in body text. The validator already enforces it, so the restatement adds no protection — it only spends the reviewer's judgment re-confirming something already guaranteed, instead of on the properties only a reviewer can check. ## Writing Shape - Write the body as a **content contract**: checkable properties of a conforming instance, in a form the type-conformance gate can apply directly. Prefer "what a conforming instance contains or claims" over "how to produce one" — production process is invisible to the reviewer, so it belongs in a skill or instruction, linked rather than embedded. - State what the type is for and when an author should choose it over a neighboring type. - Document the frontmatter fields (required and optional) as a reference for authors; the schema is the sole source of truth for requiredness. - When `schema` is non-null and implies body structure beyond `type`/`name`/`description`, include a `## Template` an authoring agent can copy. ## The type layer `types/` is the repo's **global type surface**: one set of type-specs serving every collection under `kb/`. It is deliberately **not a collection** and carries no `COLLECTION.md` — there is no per-collection type surface, and `tools/wikitool docs verify` fails if a contract appears here. ### Who owns a type-spec `types/` holds two kinds of file, and the line between them is `root:` — already in the frontmatter before anyone drew it: | Type-spec | Describes | Owned by | Ships as | |---|---|---|---| | `root: kb` (`entity`, `concept`, `source`, `comparison`) | A page **this instance** writes | The instance | `types/.md.template` plus its `.schema.yaml.template`, adopted by a rename | | `root: repo` (`instruction`), no `base_dir` (`lint-report`), and `type-spec` itself | A stack artifact | The stack | Verbatim | A page type-spec's prose, its `## Template` body and its language are therefore the instance's to rewrite — an instance writing its pages in another language simply translates the file, and an upgrade does not take that back. Improvements to a shipped default reach it as an *offered* migration ([instructions/CONTRACT.md](../instructions/CONTRACT.md#instructionsmigrations)), never by overwriting. **What the stack still requires of the type layer is one line.** There must be a type-spec declaring `name: source` whose schema requires `raw_files:` — the whole `raw/` → `kb/` provenance path (`sources coverage`, `[^cite-id]` resolution, `kb/provenance.md`) asks `page.kind == "source"`, so without it nothing resolves. `docs verify` checks exactly that and nothing beyond it: not the directory, not the title prefix, not a word of the prose. Which collection is stack-required is *derived* from where that type writes rather than listed separately, so renaming it stays consistent instead of tripping a hardcoded name. **Quality goal:** a type-spec is the single source of truth for its type. No structural fact about a page type may be restated anywhere else — not in `AGENTS.md`, not in a skill, not in Python. Adding a type must require no code change. ### Anatomy of a type Each type is two files: | File | Owns | |------|------| | `types/.md` | The authoring contract: when to use the type, when not to, guidance, and the `## Template` block used to scaffold new pages | | `types/.schema.yaml` | The machine-checkable half: fields, types, enums, defaults, required-ness, `additionalProperties: false` | This file is the self-referential root contract that both are validated against. ### Placement frontmatter Beyond the required fields above, a type-spec declares where its instances are written. **Never choose a directory by hand** - `root` plus `base_dir` plus `layout` decide placement, and `tools/wikitool new` writes the file. | Field | Required | Use | |-------|----------|-----| | `base_dir` | Yes for instantiable types | Directory where instances are written, e.g. `entities`. Relative to the root named by `root:` | | `root` | No | Which root `base_dir` resolves against: `kb` (default, `config.KB_DIR`) or `repo` (`config.ROOT`) | | `layout` | No | Maps each subtype to its `dir` and index `title` | | `title_prefix` | No | Prepended to the page title, e.g. `Source - ` | | `page_ref_fields` | No | Fields whose entries are page titles, e.g. `[related, sources]`. `lint` checks they resolve; `rename`/`rm` rewrite them | `root: kb` is the default because it is what every knowledge type wants, and because keeping placement kb-relative is what lets a test point `config.KB_DIR` at a fixture and be certain nothing can write into the real `kb/`. `root: repo` is opt-in, for types whose artifacts are legitimately not knowledge: `instruction` is the worked example - an agent-directed procedure under `instructions/`, outside the `raw/` -> `kb/` provenance rules entirely. `layout` is what turns a subtype field into areas, and it is optional in both directions on purpose. Declaring one makes every instance land in a directory named by its subtype and gives that directory its index title; leaving it off keeps the collection flat, however many subtypes the schema allows. The choice is whether the split *helps* - the catalog shards per area, so areas are how a large collection stays readable, but a subtype whose values are lopsided produces one big area and a handful of splinters and is better left flat (`source` is the worked example, `concept` the opposite one). `wikitool lint` will say which case a collection is in once it grows past the shard threshold; a `dir:` must be a single path segment, because an area is as deep as a page goes. A type-spec **without `base_dir` is a contract only** and cannot be instantiated; `wikitool new ` refuses it. `lint-report` is the worked example: its artifacts are generated into `reports/`, so it describes a file format without owning a place anything writes to. ### Adding a type 1. Write `types/.md` with the frontmatter above and a `## Template` fenced block. 2. Write `types/.schema.yaml` declaring every field, with `additionalProperties: false`. 3. Confirm it is discovered: `tools/wikitool types list`, then `tools/wikitool types describe `. 4. Scaffold with `tools/wikitool new --name "..." --set field=value`. No Python change is needed at any step; `wikitool` discovers types by scanning this directory. ### Template variables The `## Template` block is filled from the page's own frontmatter, plus `{name}` and `{today}`. Filters render structured fields: `{entities|bullets}`, `{tags|join}`, `{entity_type|capitalize}`, `{entities|table_header}`, `{entities|table_sep}`, `{entities|table_cells}`. `{field|literal text}` falls back to the literal when the field is absent. **A template never contains a tool-owned region.** The links and footnotes regions are generated between markers by `xref` and `cite`, rendered from frontmatter, and re-rendered on every write - so scaffolding them would create a section an author is forbidden to edit and the tool would replace anyway. See `tools/chemenu/blocks.py`. ### Ownership boundary | Owned here | Owned by `kb/CONTRACT.md` | Owned by `kb/CONVENTIONS.md` and the collection contracts | |------------|--------------------------|-----------------------------------------------------------| | Frontmatter fields, enums, defaults, required-ness | Provenance and citation mechanics | Quality goal and tone | | Directory placement and title prefix | The confidence machinery | Naming conventions and the confidence rubric | | Body skeleton (template) | Linking mechanics and the orphan check | Relationship vocabulary | | When to use / not use this type | The prose/identifier rule | The KB language and its section-heading names | If a rule would be identical for every type *and* every instance, it belongs in `kb/CONTRACT.md`. If every instance would answer it differently, it belongs in `kb/CONVENTIONS.md`. If it is identical for every page in one collection, it belongs in that collection's `COLLECTION.md`. ### What does not belong here - Page instances. Nothing under `types/` is content. - A `COLLECTION.md`. `types/` is a framework surface, not a collection. - Anything already enforced by a `.schema.yaml` restated in prose as if it were separately authoritative. ## Template ````markdown --- type: types/type-spec.md name: {type-name} description: "{Retrieval description for this type contract}" schema: {types/{type-name}.schema.yaml or null} --- # {Type name} {What this type is for, and when to choose it over a neighboring type.} ## Frontmatter | Field | Required | Use | |---|---:|---| | `type` | Yes | `{this type spec's own repo path}` | | `name` | Yes | {short human-facing type name} | | `description` | Yes | {retrieval description for instances of this type} | | `schema` | Yes | {repo-relative path to schema.yaml or null} | ## Template ```markdown {a copyable frontmatter + body skeleton matching the schema} ``` ```` --- Relevant Notes: - This is the root type-spec that all other type-specs reference - Type-specs form the structural backbone of the wiki's type system - All validation flows through type-spec definitions