gunk-dev/the-valley

node.cue

source02d7adaf9d03main's published tip history
4.0 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 (.the-valley/README.md) are
4// for a reader, not a validator.
5//
6// The convention this file makes checkable is documented in
7// .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
17package 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 // (.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.
52 blocked_by: [...#Id]
53 }
54
55 if type == "bug" {
56 id: =~"^bd-"
57 status: "open" | "closed"
58 }
59
60 if type == "idea" {
61 id: =~"^ida-"
62 status: "raw" | "exploring" | "adopted" | "superseded"
63 }
64
65 if type == "decision" {
66 id: =~"^dcr-"
67 status: "proposed" | "decided" | "superseded"
68 }
69
70 // The other typed edge: the node ids this node replaces. Ideas and
71 // decisions carry it and no other type does, because those are the two
72 // status enums with a `superseded` value for the replaced node to land
73 // in — a bug is closed and an outcome is abandoned, and neither of
74 // those is supersession. Optional, unlike blocked_by: most nodes
75 // replace nothing, and there is no outcome-DAG reading of an empty
76 // list to preserve.
77 if type == "idea" || type == "decision" {
78 supersedes?: [...#SupersededId]
79 }
80}
81
82// A node id: a type prefix and a short hash of the slug. The hash is not
83// re-derived here — the convention names an example algorithm rather than
84// pinning one, so only the shape is checkable.
85#Id: =~"^(oc|bd|ida|dcr)-[0-9a-f]{7}$"
86
87// The id of a node something supersedes. Narrower than #Id, because only
88// the two types with a `superseded` status can be superseded: an edge
89// naming a bug or an outcome is wrong on shape, and saying so here is a
90// better error than the lint's later complaint about a status.
91#SupersededId: =~"^(ida|dcr)-[0-9a-f]{7}$"
92
93#Date: =~"^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
94
95// #Graph is a whole graph: every node's frontmatter, keyed by the node
96// file's path. The key is the path rather than the id so that a vet failure
97// names the file a reader has to open. The lint builds one document in this
98// shape and vets it in a single pass, which is why one run reports every
99// node's errors instead of stopping at the first bad file.
100#Graph: [string]: #Node
101
102// The directory each type's nodes live in, relative to the graph root. The
103// linter reads this table rather than carrying its own copy, so adding a
104// node type is an edit to this file alone.
105#Directories: {
106 outcome: "outcomes"
107 bug: "bugs"
108 idea: "ideas"
109 decision: "decisions"
110}