gunk-dev/the-valley

node.cue

source8c4ff6fd0e3bmain's published tip history
7.9 KiB
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
25package 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 changes?: [...#ChangeLink]
72 target?: #PrincipalName | #QualifiedId
73 }
74
75 if type == "outcome" {
76 id: =~"^oc-"
77 status: "open" | "in-progress" | "done" | "abandoned"
78
79 // One of the typed edges: the nodes this outcome waits on. Any
80 // node type may block an outcome or a bug. Outcomes and bugs are
81 // the types that carry it, so the field is rejected on every
82 // other type; an outcome always carries it, and a bug may. A
83 // blocker clears when its own status is terminal for its type:
84 // an idea at graduated, superseded or discarded; a decision at
85 // decided or superseded; a bug at closed; an outcome at done or
86 // abandoned (dcr-593d3d1). An entry is a node id in this graph,
87 // or, in the live graph, <project>:<id> for a node in another
88 // project's, which only the reader resolves.
89 blocked_by!: [...#Ref]
90 }
91
92 if type == "bug" {
93 id: =~"^bd-"
94 status: "open" | "closed"
95 blocked_by?: [...#Ref]
96 }
97
98 if type == "idea" {
99 id: =~"^ida-"
100 status: "raw" | "exploring" | "adopted" | "graduated" | "superseded" | "discarded"
101
102 // An idea is transitional (dcr-593d3d1): its terminal states are
103 // graduated, superseded and discarded, and `adopted` marks an idea
104 // accepted and awaiting graduation. A graduated idea names where
105 // its thinking now lives. That destination is its own field rather
106 // than a reuse of `supersedes`, because the two edges point in
107 // opposite directions — `supersedes` is carried by the surviving
108 // node and names the replaced one, while graduation is declared by
109 // the closing node and names its destination — and because the
110 // destination may be a design document, which has no node id for
111 // an id-typed edge to name. Required exactly when the status is
112 // `graduated`, and rejected otherwise, so a graduation cannot be
113 // half-declared.
114 if status == "graduated" {
115 graduated_into: #GraduationTarget
116 }
117 }
118
119 if type == "decision" {
120 id: =~"^dcr-"
121 status: "proposed" | "decided" | "superseded"
122 }
123
124 // The other typed edge: the node ids this node replaces. Ideas and
125 // decisions carry it and no other type does, because those are the two
126 // status enums with a `superseded` value for the replaced node to land
127 // in — a bug is closed and an outcome is abandoned, and neither of
128 // those is supersession. Optional, unlike blocked_by: most nodes
129 // replace nothing, and there is no outcome-DAG reading of an empty
130 // list to preserve.
131 if type == "idea" || type == "decision" {
132 supersedes?: [...#SupersededId]
133 }
134}
135
136// A node id: a type prefix and the first 7 hex characters of the SHA-256 of
137// the slug (archive/.the-valley/README.md). CUE cannot compute the hash, so only the
138// shape is checked here; the lint re-derives it for the nodes the rule
139// covers.
140#Id: =~"^(oc|bd|ida|dcr)-[0-9a-f]{7}$"
141
142// Where a graduated idea's thinking now lives: a decision node's id, or the
143// repo-root-relative path of a design document.
144#GraduationTarget: =~"^dcr-[0-9a-f]{7}$" | =~"^[a-zA-Z0-9._/-]+\\.md$"
145
146// The id of a node something supersedes. Narrower than #Id, because only
147// the two types with a `superseded` status can be superseded: an edge
148// naming a bug or an outcome is wrong on shape, and saying so here is a
149// better error than the lint's later complaint about a status.
150#SupersededId: =~"^(ida|dcr)-[0-9a-f]{7}$"
151
152#Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
153
154// A UTC time to the second, as a claim records it.
155#Timestamp: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
156
157// An outcome's id: what a parent edge names.
158#OutcomeId: =~"^oc-[0-9a-f]{7}$"
159
160// A node in another project's graph: the project's name, a colon, and the
161// node's id. Projects do not share an id space, so a reference that leaves
162// the graph names the project.
163#QualifiedId: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*:(oc|bd|ida|dcr)-[0-9a-f]{7}$"
164
165// What a blocked_by entry names: a node here, or one in another project.
166#Ref: #Id | #QualifiedId
167
168// A principal's name, as schema/valley.cue states it (#PrincipalName). A
169// project's name and a run's ID have the same shape.
170#PrincipalName: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$"
171
172// A change that does a node's work: a change on a valley host,
173// valley:<project>/<change ID>, or a pull request on GitHub.
174#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]*$"
175
176// #Graph is a whole graph: every node's frontmatter, keyed by the node
177// file's path. The key is the path rather than the id so that a vet failure
178// names the file a reader has to open. The lint builds one document in this
179// shape and vets it in a single pass, which is why one run reports every
180// node's errors instead of stopping at the first bad file.
181#Graph: [string]: #Node
182
183// The directory each type's nodes live in, relative to the graph root. The
184// linter reads this table rather than carrying its own copy, so adding a
185// node type is an edit to this file alone.
186#Directories: {
187 outcome: "outcomes"
188 bug: "bugs"
189 idea: "ideas"
190 decision: "decisions"
191}