| 1 | // The structured layer of a knowledge-graph node: what a node's YAML |
| 2 | // frontmatter must say. The prose body is not described here — it is prose, |
| 3 | // and the writing conventions that govern it (archive/.the-valley/README.md) are |
| 4 | // for a reader, not a validator. |
| 5 | // |
| 6 | // The convention this file makes checkable is documented in |
| 7 | // archive/.the-valley/README.md: one file per node, `<id>-<slug>.md`, in the |
| 8 | // directory its type names. The type table below carries the directory |
| 9 | // names so the linter and the schema agree on them by construction. |
| 10 | // |
| 11 | // Like the host and event schemas, this file is deliberately not Nix. The |
| 12 | // knowledge lint in this repo is one consumer; any other tool that reads a |
| 13 | // graph reads the same file. |
| 14 | // |
| 15 | // Validate one node's frontmatter: |
| 16 | // cue vet -c -d '#Node' schema/node.cue <frontmatter>.yaml |
| 17 | package knowledge |
| 18 | |
| 19 | // #Node is one node's frontmatter. The common fields are stated once and |
| 20 | // the per-type differences follow, because a node's type decides both its |
| 21 | // id prefix and the states it can be in. |
| 22 | #Node: { |
| 23 | // The node's type. It fixes the id prefix, the status enum, and the |
| 24 | // directory the file lives in. |
| 25 | type: "outcome" | "bug" | "idea" | "decision" |
| 26 | |
| 27 | // The node's own id, which is also the leading token of its filename. |
| 28 | id: #Id |
| 29 | |
| 30 | // The node's state. The values differ per type; see below. |
| 31 | status: string |
| 32 | |
| 33 | // A one-line human title. Free prose, but never empty — the title is |
| 34 | // how a node reads in a listing. |
| 35 | title: string & !="" |
| 36 | |
| 37 | // The date the node was created, as YYYY-MM-DD. |
| 38 | created: #Date |
| 39 | |
| 40 | // Where the content came from: a date and a venue, never a person |
| 41 | // (archive/.the-valley/README.md, disembodied voice). |
| 42 | source?: string |
| 43 | |
| 44 | if type == "outcome" { |
| 45 | id: =~"^oc-" |
| 46 | status: "open" | "in-progress" | "done" | "abandoned" |
| 47 | |
| 48 | // One of the two typed edges: the node ids this outcome waits |
| 49 | // on. Any node type may block an outcome. Only outcomes carry |
| 50 | // it, so the field is absent — and rejected — on every other |
| 51 | // type. A blocker clears when its own status is terminal for |
| 52 | // its type: an idea at graduated, superseded or discarded; a |
| 53 | // decision at decided or superseded; a bug at closed; an |
| 54 | // outcome at done or abandoned (dcr-593d3d1). |
| 55 | blocked_by: [...#Id] |
| 56 | } |
| 57 | |
| 58 | if type == "bug" { |
| 59 | id: =~"^bd-" |
| 60 | status: "open" | "closed" |
| 61 | } |
| 62 | |
| 63 | if type == "idea" { |
| 64 | id: =~"^ida-" |
| 65 | status: "raw" | "exploring" | "adopted" | "graduated" | "superseded" | "discarded" |
| 66 | |
| 67 | // An idea is transitional (dcr-593d3d1): its terminal states are |
| 68 | // graduated, superseded and discarded, and `adopted` marks an idea |
| 69 | // accepted and awaiting graduation. A graduated idea names where |
| 70 | // its thinking now lives. That destination is its own field rather |
| 71 | // than a reuse of `supersedes`, because the two edges point in |
| 72 | // opposite directions — `supersedes` is carried by the surviving |
| 73 | // node and names the replaced one, while graduation is declared by |
| 74 | // the closing node and names its destination — and because the |
| 75 | // destination may be a design document, which has no node id for |
| 76 | // an id-typed edge to name. Required exactly when the status is |
| 77 | // `graduated`, and rejected otherwise, so a graduation cannot be |
| 78 | // half-declared. |
| 79 | if status == "graduated" { |
| 80 | graduated_into: #GraduationTarget |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if type == "decision" { |
| 85 | id: =~"^dcr-" |
| 86 | status: "proposed" | "decided" | "superseded" |
| 87 | } |
| 88 | |
| 89 | // The other typed edge: the node ids this node replaces. Ideas and |
| 90 | // decisions carry it and no other type does, because those are the two |
| 91 | // status enums with a `superseded` value for the replaced node to land |
| 92 | // in — a bug is closed and an outcome is abandoned, and neither of |
| 93 | // those is supersession. Optional, unlike blocked_by: most nodes |
| 94 | // replace nothing, and there is no outcome-DAG reading of an empty |
| 95 | // list to preserve. |
| 96 | if type == "idea" || type == "decision" { |
| 97 | supersedes?: [...#SupersededId] |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // A node id: a type prefix and the first 7 hex characters of the SHA-256 of |
| 102 | // the slug (archive/.the-valley/README.md). CUE cannot compute the hash, so only the |
| 103 | // shape is checked here; the lint re-derives it for the nodes the rule |
| 104 | // covers. |
| 105 | #Id: =~"^(oc|bd|ida|dcr)-[0-9a-f]{7}$" |
| 106 | |
| 107 | // Where a graduated idea's thinking now lives: a decision node's id, or the |
| 108 | // repo-root-relative path of a design document. |
| 109 | #GraduationTarget: =~"^dcr-[0-9a-f]{7}$" | =~"^[a-zA-Z0-9._/-]+\\.md$" |
| 110 | |
| 111 | // The id of a node something supersedes. Narrower than #Id, because only |
| 112 | // the two types with a `superseded` status can be superseded: an edge |
| 113 | // naming a bug or an outcome is wrong on shape, and saying so here is a |
| 114 | // better error than the lint's later complaint about a status. |
| 115 | #SupersededId: =~"^(ida|dcr)-[0-9a-f]{7}$" |
| 116 | |
| 117 | #Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$" |
| 118 | |
| 119 | // #Graph is a whole graph: every node's frontmatter, keyed by the node |
| 120 | // file's path. The key is the path rather than the id so that a vet failure |
| 121 | // names the file a reader has to open. The lint builds one document in this |
| 122 | // shape and vets it in a single pass, which is why one run reports every |
| 123 | // node's errors instead of stopping at the first bad file. |
| 124 | #Graph: [string]: #Node |
| 125 | |
| 126 | // The directory each type's nodes live in, relative to the graph root. The |
| 127 | // linter reads this table rather than carrying its own copy, so adding a |
| 128 | // node type is an edit to this file alone. |
| 129 | #Directories: { |
| 130 | outcome: "outcomes" |
| 131 | bug: "bugs" |
| 132 | idea: "ideas" |
| 133 | decision: "decisions" |
| 134 | } |