|
| 1 | +--- |
| 2 | +title: Kind files under `.mdsmith/kinds/` |
| 3 | +weight: 25 |
| 4 | +summary: >- |
| 5 | + Each file under `.mdsmith/kinds/` declares one |
| 6 | + kind. The basename is the kind name; the file body |
| 7 | + carries the full `KindBody` — schema, rules, |
| 8 | + `path-pattern:`, `extends:`. Sits alongside inline |
| 9 | + `kinds.<name>:` in `.mdsmith.yml`. |
| 10 | +--- |
| 11 | +# Kind files under `.mdsmith/kinds/` |
| 12 | + |
| 13 | +A **kind file** is a YAML file under |
| 14 | +`.mdsmith/kinds/` whose basename is the kind's name |
| 15 | +and whose body is the full kind definition. One file |
| 16 | +per kind, no nesting. The directory sits next to |
| 17 | +`.mdsmith.yml` at the workspace root. |
| 18 | + |
| 19 | +```text |
| 20 | +.mdsmith.yml # unchanged |
| 21 | +.mdsmith/ |
| 22 | + kinds/ |
| 23 | + audit-log.yaml |
| 24 | + secret-rotation.yaml |
| 25 | + architecture-doc.yaml |
| 26 | +``` |
| 27 | + |
| 28 | +Use kind files when the `kinds:` block has grown |
| 29 | +large. Each rule edit dirties the same |
| 30 | +`.mdsmith.yml` as every other config change. |
| 31 | +Splitting kinds into one file each isolates the |
| 32 | +history. The read path shortens too: open |
| 33 | +`audit-log.yaml` to see the whole `audit-log` |
| 34 | +kind. |
| 35 | + |
| 36 | +## File shape |
| 37 | + |
| 38 | +The file body matches the inline |
| 39 | +`kinds.<name>:` body. It accepts every |
| 40 | +[`KindBody`](../guides/file-kinds.md) key: |
| 41 | +`extends:`, `path-pattern:`, `categories:`, |
| 42 | +`schema:`, `rules:`. A key outside that set is |
| 43 | +a config error. |
| 44 | + |
| 45 | +```yaml |
| 46 | +# .mdsmith/kinds/audit-log.yaml |
| 47 | +schema: |
| 48 | + frontmatter: |
| 49 | + title: 'string & != ""' |
| 50 | + "summary?": 'string' |
| 51 | + audit-from: '=~"^[0-9a-f]{7,40}$"' |
| 52 | + filename: "architecture-audit.md" |
| 53 | + closed: false |
| 54 | + sections: |
| 55 | + - heading: null |
| 56 | + - heading: |
| 57 | + regex: '.+' |
| 58 | + repeat: { min: 0 } |
| 59 | +rules: |
| 60 | + max-file-length: |
| 61 | + max: 600 |
| 62 | +``` |
| 63 | +
|
| 64 | +## Basename rule |
| 65 | +
|
| 66 | +The kind's name is the basename minus extension. |
| 67 | +The basename must match `[a-z][a-z0-9-]*` — lower |
| 68 | +case, starting with a letter, with optional |
| 69 | +hyphen-separated segments. The rule applies only to |
| 70 | +filenames (OS case folding, path safety); inline |
| 71 | +`kinds.<name>:` keys stay unvalidated. |
| 72 | + |
| 73 | +Both `*.yaml` and `*.yml` are scanned. Two kind |
| 74 | +files with the same basename across the two |
| 75 | +extensions is a config error naming both files. |
| 76 | + |
| 77 | +Subdirectories under `.mdsmith/kinds/` are |
| 78 | +rejected. One kind per file, flat layout. |
| 79 | + |
| 80 | +## Composition with `.mdsmith.yml` |
| 81 | + |
| 82 | +`kinds.<name>:` blocks inside `.mdsmith.yml` |
| 83 | +remain a first-class source. A project can mix |
| 84 | +inline and file-defined kinds freely. |
| 85 | + |
| 86 | +The same kind name declared in **both** a file and |
| 87 | +inline is a config error naming both sources. The |
| 88 | +two sources do **not** merge — a merged kind would |
| 89 | +defeat the "read one file to know one kind" |
| 90 | +property kind files ship. |
| 91 | + |
| 92 | +`kind-assignment:`, `overrides:`, and `ignore:` are |
| 93 | +glob-keyed and stay in `.mdsmith.yml`. A |
| 94 | +kind-assignment entry references a kind by name — |
| 95 | +inline or file kind — with no extra wiring. |
| 96 | + |
| 97 | +## Schema sources |
| 98 | + |
| 99 | +A kind file accepts the same three schema sources |
| 100 | +as an inline kind, and they remain mutually |
| 101 | +exclusive (acceptance criterion #6 of plan 208): |
| 102 | + |
| 103 | +- inline `schema:` block |
| 104 | +- `rules.required-structure.schema:` path to a |
| 105 | + `proto.md` |
| 106 | +- legacy `rules.required-structure.inline-schema:` |
| 107 | + map |
| 108 | + |
| 109 | +Setting two on the same kind errors at config load |
| 110 | +with both source names. |
| 111 | + |
| 112 | +A schema shared across kinds is shared via |
| 113 | +`extends:` — the inheritance chain works |
| 114 | +seamlessly across sources. A file kind may extend |
| 115 | +an inline kind and the reverse. The cycle detector |
| 116 | +runs on the merged kinds map. |
| 117 | + |
| 118 | +## Audit |
| 119 | + |
| 120 | +`mdsmith kinds resolve <file>` prints the |
| 121 | +defining-source path next to each kind it |
| 122 | +reports. A mixed resolution shows the path each |
| 123 | +kind came from. You can jump straight to the |
| 124 | +right file: |
| 125 | + |
| 126 | +```text |
| 127 | +file: docs/audit.md |
| 128 | +effective kinds: |
| 129 | + - audit-log (from kind-assignment[3]: glob docs/**/*.md) defined-in .mdsmith/kinds/audit-log.yaml |
| 130 | +``` |
| 131 | + |
| 132 | +`mdsmith kinds show <name>` adds a `defined-in:` |
| 133 | +line to the body output, so the same info is |
| 134 | +available without going through a target file. |
| 135 | + |
| 136 | +The JSON shape (`--json`) carries a |
| 137 | +`source-path:` key on each kind body and on every |
| 138 | +resolved-kind entry so editor integrations can |
| 139 | +key off a stable field. |
0 commit comments