gunk-dev/the-valley

node.cue

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