| 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 | // One schema covers both graphs: the archived one under archive/.the-valley/, |
| 12 | // and the live plan graph at refs/the-valley/knots, where each node is a |
| 13 | // knot. The live graph's own fields are optional here, because the archive |
| 14 | // predates them. For the live graph the Go module knot/ is the authority: |
| 15 | // it writes and reads one canonical form of this YAML, and it holds a knot |
| 16 | // to rules this schema does not state, such as who may create one. The |
| 17 | // knot-agree check holds the two to agreeing on every rule they share. |
| 18 | // |
| 19 | // Like the host and event schemas, this file is deliberately not Nix. The |
| 20 | // knowledge lint in this repo is one consumer; any other tool that reads a |
| 21 | // graph reads the same file. |
| 22 | // |
| 23 | // Validate one node's frontmatter: |
| 24 | // cue vet -c -d '#Node' schema/node.cue <frontmatter>.yaml |
| 25 | package knowledge |
| 26 | |
| 27 | // #Node is one node's frontmatter. The common fields are stated once and |
| 28 | // the per-type differences follow, because a node's type decides both its |
| 29 | // id prefix and the states it can be in. |
| 30 | #Node: { |
| 31 | // The node's type. It fixes the id prefix, the status enum, and the |
| 32 | // directory the file lives in. |
| 33 | type: "outcome" | "bug" | "idea" | "decision" |
| 34 | |
| 35 | // The node's own id, which is also the leading token of its filename. |
| 36 | id: #Id |
| 37 | |
| 38 | // The node's state. The values differ per type; see below. |
| 39 | status: string |
| 40 | |
| 41 | // A one-line human title. Free prose, but never empty — the title is |
| 42 | // how a node reads in a listing. |
| 43 | title: string & !="" |
| 44 | |
| 45 | // The date the node was created, as YYYY-MM-DD. |
| 46 | created: #Date |
| 47 | |
| 48 | // Where the content came from: a date and a venue, never a person |
| 49 | // (archive/.the-valley/README.md, disembodied voice). |
| 50 | source?: string |
| 51 | |
| 52 | // The live graph's fields. Every knot names the principal that created |
| 53 | // it, which the push hook checks is the principal pushing it. |
| 54 | created_by?: #PrincipalName |
| 55 | |
| 56 | // The outcome this node belongs to: a milestone, a work item, or a |
| 57 | // residual's work item. It names an outcome in the same graph; the |
| 58 | // lint resolves it. |
| 59 | parent?: #OutcomeId |
| 60 | |
| 61 | // The principal this node waits on. It names who is responsible, and |
| 62 | // grants nothing. |
| 63 | owner?: #PrincipalName |
| 64 | |
| 65 | // Outcomes and bugs are work. They can be claimed by a run, link the |
| 66 | // changes that do them, and name the project where the work lands |
| 67 | // when that is not this one. |
| 68 | if type == "outcome" || type == "bug" { |
| 69 | claimed_by?: #PrincipalName |
| 70 | claimed_at?: #Timestamp |
| 71 | target?: #PrincipalName | #QualifiedId |
| 72 | } |
| 73 | |
| 74 | // A decision links changes too: the change that records it in the |
| 75 | // source once it is decided. An idea links none. It graduates into a |
| 76 | // decision, and the decision is what crosses into the source. |
| 77 | if type == "outcome" || type == "bug" || type == "decision" { |
| 78 | changes?: [...#ChangeLink] |
| 79 | } |
| 80 | |
| 81 | if type == "outcome" { |
| 82 | id: =~"^oc-" |
| 83 | status: "open" | "in-progress" | "done" | "abandoned" |
| 84 | |
| 85 | // One of the typed edges: the nodes this outcome waits on. Any |
| 86 | // node type may block an outcome or a bug. Outcomes and bugs are |
| 87 | // the types that carry it, so the field is rejected on every |
| 88 | // other type; an outcome always carries it, and a bug may. A |
| 89 | // blocker clears when its own status is terminal for its type: |
| 90 | // an idea at graduated, superseded or discarded; a decision at |
| 91 | // decided or superseded; a bug at closed; an outcome at done or |
| 92 | // abandoned (dcr-593d3d1). An entry is a node id in this graph, |
| 93 | // or, in the live graph, <project>:<id> for a node in another |
| 94 | // project's, which only the reader resolves. |
| 95 | blocked_by!: [...#Ref] |
| 96 | } |
| 97 | |
| 98 | if type == "bug" { |
| 99 | id: =~"^bd-" |
| 100 | status: "open" | "closed" |
| 101 | blocked_by?: [...#Ref] |
| 102 | } |
| 103 | |
| 104 | if type == "idea" { |
| 105 | id: =~"^ida-" |
| 106 | status: "raw" | "exploring" | "adopted" | "graduated" | "superseded" | "discarded" |
| 107 | |
| 108 | // An idea is transitional (dcr-593d3d1): its terminal states are |
| 109 | // graduated, superseded and discarded, and `adopted` marks an idea |
| 110 | // accepted and awaiting graduation. A graduated idea names where |
| 111 | // its thinking now lives. That destination is its own field rather |
| 112 | // than a reuse of `supersedes`, because the two edges point in |
| 113 | // opposite directions — `supersedes` is carried by the surviving |
| 114 | // node and names the replaced one, while graduation is declared by |
| 115 | // the closing node and names its destination — and because the |
| 116 | // destination may be a design document, which has no node id for |
| 117 | // an id-typed edge to name. Required exactly when the status is |
| 118 | // `graduated`, and rejected otherwise, so a graduation cannot be |
| 119 | // half-declared. |
| 120 | if status == "graduated" { |
| 121 | graduated_into: #GraduationTarget |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if type == "decision" { |
| 126 | id: =~"^dcr-" |
| 127 | status: "proposed" | "decided" | "superseded" |
| 128 | } |
| 129 | |
| 130 | // The other typed edge: the node ids this node replaces. Ideas and |
| 131 | // decisions carry it and no other type does, because those are the two |
| 132 | // status enums with a `superseded` value for the replaced node to land |
| 133 | // in — a bug is closed and an outcome is abandoned, and neither of |
| 134 | // those is supersession. Optional, unlike blocked_by: most nodes |
| 135 | // replace nothing, and there is no outcome-DAG reading of an empty |
| 136 | // list to preserve. |
| 137 | if type == "idea" || type == "decision" { |
| 138 | supersedes?: [...#SupersededId] |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // A node id: a type prefix and the first 7 hex characters of the SHA-256 of |
| 143 | // the slug (archive/.the-valley/README.md). CUE cannot compute the hash, so only the |
| 144 | // shape is checked here; the lint re-derives it for the nodes the rule |
| 145 | // covers. |
| 146 | #Id: =~"^(oc|bd|ida|dcr)-[0-9a-f]{7}$" |
| 147 | |
| 148 | // Where a graduated idea's thinking now lives: a decision node's id, or the |
| 149 | // repo-root-relative path of a design document. |
| 150 | #GraduationTarget: =~"^dcr-[0-9a-f]{7}$" | =~"^[a-zA-Z0-9._/-]+\\.md$" |
| 151 | |
| 152 | // The id of a node something supersedes. Narrower than #Id, because only |
| 153 | // the two types with a `superseded` status can be superseded: an edge |
| 154 | // naming a bug or an outcome is wrong on shape, and saying so here is a |
| 155 | // better error than the lint's later complaint about a status. |
| 156 | #SupersededId: =~"^(ida|dcr)-[0-9a-f]{7}$" |
| 157 | |
| 158 | #Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$" |
| 159 | |
| 160 | // A UTC time to the second, as a claim records it. |
| 161 | #Timestamp: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" |
| 162 | |
| 163 | // An outcome's id: what a parent edge names. |
| 164 | #OutcomeId: =~"^oc-[0-9a-f]{7}$" |
| 165 | |
| 166 | // A node in another project's graph: the project's name, a colon, and the |
| 167 | // node's id. Projects do not share an id space, so a reference that leaves |
| 168 | // the graph names the project. |
| 169 | #QualifiedId: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*:(oc|bd|ida|dcr)-[0-9a-f]{7}$" |
| 170 | |
| 171 | // What a blocked_by entry names: a node here, or one in another project. |
| 172 | #Ref: #Id | #QualifiedId |
| 173 | |
| 174 | // A principal's name, as schema/valley.cue states it (#PrincipalName). A |
| 175 | // project's name and a run's ID have the same shape. |
| 176 | #PrincipalName: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" |
| 177 | |
| 178 | // A change that does a node's work: a change on a valley host, |
| 179 | // valley:<project>/<change ID>, or a pull request on GitHub. |
| 180 | #ChangeLink: =~"^valley:[a-zA-Z0-9][a-zA-Z0-9._-]*/[k-z]{32}$" | =~"^https://github\\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/pull/[1-9][0-9]*$" |
| 181 | |
| 182 | // #Graph is a whole graph: every node's frontmatter, keyed by the node |
| 183 | // file's path. The key is the path rather than the id so that a vet failure |
| 184 | // names the file a reader has to open. The lint builds one document in this |
| 185 | // shape and vets it in a single pass, which is why one run reports every |
| 186 | // node's errors instead of stopping at the first bad file. |
| 187 | #Graph: [string]: #Node |
| 188 | |
| 189 | // The directory each type's nodes live in, relative to the graph root. The |
| 190 | // linter reads this table rather than carrying its own copy, so adding a |
| 191 | // node type is an edit to this file alone. |
| 192 | #Directories: { |
| 193 | outcome: "outcomes" |
| 194 | bug: "bugs" |
| 195 | idea: "ideas" |
| 196 | decision: "decisions" |
| 197 | } |