@warlock.js/grimoire 0.0.0-stage → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/esm/apps/check-apps.mjs +207 -0
- package/esm/apps/check-apps.mjs.map +1 -0
- package/esm/apps/index.mjs +4 -0
- package/esm/apps/match-apps.d.mts +12 -0
- package/esm/apps/match-apps.d.mts.map +1 -0
- package/esm/apps/match-apps.mjs +30 -0
- package/esm/apps/match-apps.mjs.map +1 -0
- package/esm/book/build.d.mts +14 -0
- package/esm/book/build.d.mts.map +1 -0
- package/esm/book/build.mjs +300 -0
- package/esm/book/build.mjs.map +1 -0
- package/esm/book/index.mjs +5 -0
- package/esm/book/io.mjs +162 -0
- package/esm/book/io.mjs.map +1 -0
- package/esm/book/normalize.mjs +71 -0
- package/esm/book/normalize.mjs.map +1 -0
- package/esm/book/render.mjs +262 -0
- package/esm/book/render.mjs.map +1 -0
- package/esm/book/write.d.mts +12 -0
- package/esm/book/write.d.mts.map +1 -0
- package/esm/book/write.mjs +90 -0
- package/esm/book/write.mjs.map +1 -0
- package/esm/bookmap/build.d.mts +21 -0
- package/esm/bookmap/build.d.mts.map +1 -0
- package/esm/bookmap/build.mjs +272 -0
- package/esm/bookmap/build.mjs.map +1 -0
- package/esm/bookmap/index.mjs +5 -0
- package/esm/bookmap/steps.mjs +137 -0
- package/esm/bookmap/steps.mjs.map +1 -0
- package/esm/bookmap/write.d.mts +19 -0
- package/esm/bookmap/write.d.mts.map +1 -0
- package/esm/bookmap/write.mjs +118 -0
- package/esm/bookmap/write.mjs.map +1 -0
- package/esm/check/check-grimoire.d.mts +7 -0
- package/esm/check/check-grimoire.d.mts.map +1 -0
- package/esm/check/check-grimoire.mjs +98 -0
- package/esm/check/check-grimoire.mjs.map +1 -0
- package/esm/check/format-check-report.d.mts +20 -0
- package/esm/check/format-check-report.d.mts.map +1 -0
- package/esm/check/format-check-report.mjs +55 -0
- package/esm/check/format-check-report.mjs.map +1 -0
- package/esm/check/index.mjs +4 -0
- package/esm/check/rules/book-notes.mjs +18 -0
- package/esm/check/rules/book-notes.mjs.map +1 -0
- package/esm/check/rules/criteria.mjs +48 -0
- package/esm/check/rules/criteria.mjs.map +1 -0
- package/esm/check/rules/links.mjs +196 -0
- package/esm/check/rules/links.mjs.map +1 -0
- package/esm/check/rules/lookup.mjs +41 -0
- package/esm/check/rules/lookup.mjs.map +1 -0
- package/esm/check/rules/source-files.mjs +119 -0
- package/esm/check/rules/source-files.mjs.map +1 -0
- package/esm/check/rules/versions.mjs +92 -0
- package/esm/check/rules/versions.mjs.map +1 -0
- package/esm/codes/codes.d.mts +182 -0
- package/esm/codes/codes.d.mts.map +1 -0
- package/esm/codes/codes.mjs +111 -0
- package/esm/codes/codes.mjs.map +1 -0
- package/esm/codes/index.d.mts +33 -0
- package/esm/codes/index.d.mts.map +1 -0
- package/esm/codes/index.mjs +63 -0
- package/esm/codes/index.mjs.map +1 -0
- package/esm/contracts/adapter.d.mts +209 -0
- package/esm/contracts/adapter.d.mts.map +1 -0
- package/esm/contracts/book.d.mts +233 -0
- package/esm/contracts/book.d.mts.map +1 -0
- package/esm/contracts/book.mjs +7 -0
- package/esm/contracts/book.mjs.map +1 -0
- package/esm/contracts/bookmap.d.mts +175 -0
- package/esm/contracts/bookmap.d.mts.map +1 -0
- package/esm/contracts/findings.d.mts +79 -0
- package/esm/contracts/findings.d.mts.map +1 -0
- package/esm/contracts/location.d.mts +22 -0
- package/esm/contracts/location.d.mts.map +1 -0
- package/esm/contracts/releases.d.mts +53 -0
- package/esm/contracts/releases.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +143 -0
- package/esm/contracts/scry.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +52 -0
- package/esm/contracts/snapshot.d.mts.map +1 -0
- package/esm/contracts/test-results.d.mts +63 -0
- package/esm/contracts/test-results.d.mts.map +1 -0
- package/esm/contracts/written.d.mts +363 -0
- package/esm/contracts/written.d.mts.map +1 -0
- package/esm/contracts/written.mjs +19 -0
- package/esm/contracts/written.mjs.map +1 -0
- package/esm/devtools/data.mjs +171 -0
- package/esm/devtools/data.mjs.map +1 -0
- package/esm/devtools/graphs.mjs +142 -0
- package/esm/devtools/graphs.mjs.map +1 -0
- package/esm/devtools/index.d.mts +35 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +102 -0
- package/esm/devtools/index.mjs.map +1 -0
- package/esm/devtools/site.d.mts +26 -0
- package/esm/devtools/site.d.mts.map +1 -0
- package/esm/devtools/site.mjs +190 -0
- package/esm/devtools/site.mjs.map +1 -0
- package/esm/devtools/snapshot-source.mjs +70 -0
- package/esm/devtools/snapshot-source.mjs.map +1 -0
- package/esm/front-matter/index.d.mts +33 -0
- package/esm/front-matter/index.d.mts.map +1 -0
- package/esm/front-matter/index.mjs +130 -0
- package/esm/front-matter/index.mjs.map +1 -0
- package/esm/graph/index.d.mts +15 -0
- package/esm/graph/index.d.mts.map +1 -0
- package/esm/graph/index.mjs +42 -0
- package/esm/graph/index.mjs.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.mjs +33 -0
- package/esm/ownership/index.d.mts +8 -0
- package/esm/ownership/index.d.mts.map +1 -0
- package/esm/ownership/index.mjs +137 -0
- package/esm/ownership/index.mjs.map +1 -0
- package/esm/paths/index.d.mts +58 -0
- package/esm/paths/index.d.mts.map +1 -0
- package/esm/paths/index.mjs +137 -0
- package/esm/paths/index.mjs.map +1 -0
- package/esm/proves/index.mjs +3 -0
- package/esm/proves/scan-proofs.d.mts +22 -0
- package/esm/proves/scan-proofs.d.mts.map +1 -0
- package/esm/proves/scan-proofs.mjs +214 -0
- package/esm/proves/scan-proofs.mjs.map +1 -0
- package/esm/releases/index.d.mts +29 -0
- package/esm/releases/index.d.mts.map +1 -0
- package/esm/releases/index.mjs +157 -0
- package/esm/releases/index.mjs.map +1 -0
- package/esm/scry/format.d.mts +14 -0
- package/esm/scry/format.d.mts.map +1 -0
- package/esm/scry/format.mjs +193 -0
- package/esm/scry/format.mjs.map +1 -0
- package/esm/scry/index.mjs +5 -0
- package/esm/scry/parse.d.mts +10 -0
- package/esm/scry/parse.d.mts.map +1 -0
- package/esm/scry/parse.mjs +108 -0
- package/esm/scry/parse.mjs.map +1 -0
- package/esm/scry/query.d.mts +11 -0
- package/esm/scry/query.d.mts.map +1 -0
- package/esm/scry/query.mjs +457 -0
- package/esm/scry/query.mjs.map +1 -0
- package/esm/tasks/index.mjs +116 -0
- package/esm/tasks/index.mjs.map +1 -0
- package/esm/test-results/criterion-status.d.mts +15 -0
- package/esm/test-results/criterion-status.d.mts.map +1 -0
- package/esm/test-results/criterion-status.mjs +17 -0
- package/esm/test-results/criterion-status.mjs.map +1 -0
- package/esm/test-results/index.d.mts +8 -0
- package/esm/test-results/index.d.mts.map +1 -0
- package/esm/test-results/index.mjs +124 -0
- package/esm/test-results/index.mjs.map +1 -0
- package/esm/vitest/index.d.mts +15 -0
- package/esm/vitest/index.d.mts.map +1 -0
- package/esm/vitest/index.mjs +146 -0
- package/esm/vitest/index.mjs.map +1 -0
- package/esm/warlock/actions.mjs +265 -0
- package/esm/warlock/actions.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts +28 -0
- package/esm/warlock/adapter.d.mts.map +1 -0
- package/esm/warlock/adapter.mjs +377 -0
- package/esm/warlock/adapter.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +15 -0
- package/esm/warlock/commands.d.mts.map +1 -0
- package/esm/warlock/commands.mjs +199 -0
- package/esm/warlock/commands.mjs.map +1 -0
- package/esm/warlock/index.d.mts +4 -0
- package/esm/warlock/index.mjs +5 -0
- package/esm/warlock/mcp-tools.mjs +247 -0
- package/esm/warlock/mcp-tools.mjs.map +1 -0
- package/esm/warlock/mobile-facts.d.mts +32 -0
- package/esm/warlock/mobile-facts.d.mts.map +1 -0
- package/esm/warlock/mobile-facts.mjs +185 -0
- package/esm/warlock/mobile-facts.mjs.map +1 -0
- package/esm/workspace/index.d.mts +11 -0
- package/esm/workspace/index.d.mts.map +1 -0
- package/esm/workspace/index.mjs +122 -0
- package/esm/workspace/index.mjs.map +1 -0
- package/esm/written/apps.mjs +227 -0
- package/esm/written/apps.mjs.map +1 -0
- package/esm/written/features.mjs +400 -0
- package/esm/written/features.mjs.map +1 -0
- package/esm/written/fields.mjs +173 -0
- package/esm/written/fields.mjs.map +1 -0
- package/esm/written/index.mjs +3 -0
- package/esm/written/lists.mjs +68 -0
- package/esm/written/lists.mjs.map +1 -0
- package/esm/written/markdown.mjs +173 -0
- package/esm/written/markdown.mjs.map +1 -0
- package/esm/written/parse-grimoire.d.mts +20 -0
- package/esm/written/parse-grimoire.d.mts.map +1 -0
- package/esm/written/parse-grimoire.mjs +552 -0
- package/esm/written/parse-grimoire.mjs.map +1 -0
- package/esm/written/sink.mjs +65 -0
- package/esm/written/sink.mjs.map +1 -0
- package/esm/written/tasks-releases.mjs +166 -0
- package/esm/written/tasks-releases.mjs.map +1 -0
- package/llms-full.txt +869 -0
- package/llms.txt +15 -0
- package/package.json +66 -4
- package/skills/backfill-a-grimoire/SKILL.md +128 -0
- package/skills/describe-an-app/SKILL.md +162 -0
- package/skills/document-a-file/SKILL.md +75 -0
- package/skills/index.md +26 -0
- package/skills/record-a-change/SKILL.md +139 -0
- package/skills/use-the-grimoire/SKILL.md +137 -0
- package/skills/write-a-feature/SKILL.md +168 -0
- package/ui/grimoire-static.js +136 -0
- package/ui/grimoire-view.js +1005 -0
- package/ui/grimoire.css +88 -0
|
@@ -0,0 +1,1005 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Grimoire tab: a browser ES module that the devtools dashboard loads
|
|
3
|
+
* (`panels/grimoire/view.js`) and that the static export inlines. It builds
|
|
4
|
+
* the DOM with the context's `el()` and `svg()` helpers and sets every string
|
|
5
|
+
* from the data as text, never as HTML. Hash links look like `#grimoire/flow/<feature>/<flow>`.
|
|
6
|
+
*
|
|
7
|
+
* Keep the last line as it is: the static export swaps it out to inline this file.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const NAV = [
|
|
11
|
+
["", "Home"],
|
|
12
|
+
["apps", "Apps"],
|
|
13
|
+
["tasks", "Tasks"],
|
|
14
|
+
["releases", "Releases"],
|
|
15
|
+
["check", "Check"],
|
|
16
|
+
["modules", "Modules"],
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const SVG_WIDTH = 720;
|
|
20
|
+
const SVG_HEIGHT = 440;
|
|
21
|
+
|
|
22
|
+
/** Decode one hash segment; a malformed escape stays as written. */
|
|
23
|
+
function decodeSegment(segment) {
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(segment);
|
|
26
|
+
} catch {
|
|
27
|
+
return segment;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The value of a located field (`{ value, at }`), or the field itself. */
|
|
32
|
+
function plain(field) {
|
|
33
|
+
return field !== null && typeof field === "object" && "value" in field ? field.value : field;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The hash route (without `#grimoire/`) of a search hit or graph node id, or `null`. */
|
|
37
|
+
function targetOf(type, id) {
|
|
38
|
+
const encode = encodeURIComponent;
|
|
39
|
+
|
|
40
|
+
switch (type) {
|
|
41
|
+
case "feature":
|
|
42
|
+
return `feature/${encode(id)}`;
|
|
43
|
+
case "flow": {
|
|
44
|
+
const [feature, flow] = id.split("/");
|
|
45
|
+
return `flow/${encode(feature ?? "")}/${encode(flow ?? "")}`;
|
|
46
|
+
}
|
|
47
|
+
case "page":
|
|
48
|
+
case "screen": {
|
|
49
|
+
const space = id.indexOf(" ");
|
|
50
|
+
return space < 0 ? null : `page/${encode(id.slice(0, space))}/${encode(id.slice(space + 1))}`;
|
|
51
|
+
}
|
|
52
|
+
case "block": {
|
|
53
|
+
const [app, page] = id.split("/");
|
|
54
|
+
return `page/${encode(app ?? "")}/${encode(page ?? "")}`;
|
|
55
|
+
}
|
|
56
|
+
case "route": {
|
|
57
|
+
const space = id.indexOf(" ");
|
|
58
|
+
return space < 0
|
|
59
|
+
? null
|
|
60
|
+
: `route/${encode(id.slice(0, space))}/${encode(id.slice(space + 1))}`;
|
|
61
|
+
}
|
|
62
|
+
case "file":
|
|
63
|
+
return `file/${encode(id)}`;
|
|
64
|
+
case "export":
|
|
65
|
+
return `file/${encode(id.split("#")[0] ?? id)}`;
|
|
66
|
+
case "task":
|
|
67
|
+
return `task/${encode(id)}`;
|
|
68
|
+
default:
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The target of a graph node id (`file:src/a.ts`, `feature:auth`, …). */
|
|
74
|
+
function nodeTarget(id) {
|
|
75
|
+
const colon = id.indexOf(":");
|
|
76
|
+
const type = id.slice(0, colon);
|
|
77
|
+
const rest = id.slice(colon + 1);
|
|
78
|
+
|
|
79
|
+
if (type === "file" || type === "feature" || type === "flow") return targetOf(type, rest);
|
|
80
|
+
// A layout has no view of its own: its blocks are listed on each page that uses it.
|
|
81
|
+
if (type === "page") {
|
|
82
|
+
const [app, page] = rest.split("/");
|
|
83
|
+
return `page/${encodeURIComponent(app ?? "")}/${encodeURIComponent(page ?? "")}`;
|
|
84
|
+
}
|
|
85
|
+
if (type === "block") return targetOf("block", rest);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Cut a long label from the front so the end of a path stays visible. */
|
|
90
|
+
function shorten(text, max = 26) {
|
|
91
|
+
return text.length > max ? `…${text.slice(text.length - max + 1)}` : text;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const NODE_COLOURS = {
|
|
95
|
+
center: "var(--accent)",
|
|
96
|
+
feature: "var(--good)",
|
|
97
|
+
flow: "var(--bar)",
|
|
98
|
+
app: "var(--warn)",
|
|
99
|
+
block: "var(--bar)",
|
|
100
|
+
layout: "var(--muted)",
|
|
101
|
+
module: "var(--accent)",
|
|
102
|
+
file: "var(--muted)",
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** Plain SVG for a graph answer: the centre node in the middle, the others on one or two rings. */
|
|
106
|
+
function graphView(ctx, graph, title) {
|
|
107
|
+
const { el, svg, empty, href } = ctx;
|
|
108
|
+
const card = el("section", { class: "card grimoire-graph" }, [el("h3", { text: title })]);
|
|
109
|
+
|
|
110
|
+
if (!graph.nodes.length) {
|
|
111
|
+
card.append(empty("Nothing to draw."));
|
|
112
|
+
return card;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const centre = graph.nodes.find((node) => node.type === "center");
|
|
116
|
+
const others = graph.nodes.filter((node) => node !== centre);
|
|
117
|
+
const place = new Map();
|
|
118
|
+
const middleX = SVG_WIDTH / 2;
|
|
119
|
+
const middleY = SVG_HEIGHT / 2;
|
|
120
|
+
|
|
121
|
+
if (centre) place.set(centre.id, [middleX, middleY]);
|
|
122
|
+
|
|
123
|
+
const inner = centre ? Math.min(others.length, 18) : 0;
|
|
124
|
+
const rings = centre ? [others.slice(0, inner), others.slice(inner)] : [others, []];
|
|
125
|
+
rings.forEach((ring, index) => {
|
|
126
|
+
const radiusX = centre ? (index === 0 ? 210 : 320) : 300;
|
|
127
|
+
const radiusY = centre ? (index === 0 ? 150 : 195) : 185;
|
|
128
|
+
ring.forEach((node, position) => {
|
|
129
|
+
const angle =
|
|
130
|
+
(position / Math.max(ring.length, 1)) * 2 * Math.PI - Math.PI / 2 + index * 0.15;
|
|
131
|
+
place.set(node.id, [
|
|
132
|
+
middleX + radiusX * Math.cos(angle),
|
|
133
|
+
middleY + radiusY * Math.sin(angle),
|
|
134
|
+
]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const canvas = svg("svg", {
|
|
139
|
+
viewBox: `0 0 ${SVG_WIDTH} ${SVG_HEIGHT}`,
|
|
140
|
+
class: "grimoire-svg",
|
|
141
|
+
role: "img",
|
|
142
|
+
"aria-label": title,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
for (const edge of graph.edges) {
|
|
146
|
+
const from = place.get(edge.from);
|
|
147
|
+
const to = place.get(edge.to);
|
|
148
|
+
if (!from || !to) continue;
|
|
149
|
+
canvas.append(
|
|
150
|
+
svg("line", {
|
|
151
|
+
x1: from[0].toFixed(1),
|
|
152
|
+
y1: from[1].toFixed(1),
|
|
153
|
+
x2: to[0].toFixed(1),
|
|
154
|
+
y2: to[1].toFixed(1),
|
|
155
|
+
stroke: "var(--line)",
|
|
156
|
+
"stroke-width": edge.weight ? String(Math.min(1 + Math.log2(edge.weight), 5)) : "1.2",
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
for (const node of graph.nodes) {
|
|
162
|
+
const at = place.get(node.id);
|
|
163
|
+
if (!at) continue;
|
|
164
|
+
const target = nodeTarget(node.id);
|
|
165
|
+
const circle = svg("circle", {
|
|
166
|
+
cx: at[0].toFixed(1),
|
|
167
|
+
cy: at[1].toFixed(1),
|
|
168
|
+
r: node.type === "center" ? "9" : "6",
|
|
169
|
+
fill: NODE_COLOURS[node.type] ?? "var(--muted)",
|
|
170
|
+
});
|
|
171
|
+
const label = svg("text", {
|
|
172
|
+
x: at[0].toFixed(1),
|
|
173
|
+
y: (at[1] + (node.type === "center" ? 24 : 18)).toFixed(1),
|
|
174
|
+
"text-anchor": "middle",
|
|
175
|
+
fill: "var(--text)",
|
|
176
|
+
"font-size": "11",
|
|
177
|
+
text: shorten(node.label),
|
|
178
|
+
});
|
|
179
|
+
const group = svg("g", {}, [svg("title", { text: node.label }), circle, label]);
|
|
180
|
+
canvas.append(target === null ? group : svg("a", { href: href(target) }, [group]));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
card.append(canvas);
|
|
184
|
+
return card;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** One section card with a heading. */
|
|
188
|
+
function section(ctx, title, children = []) {
|
|
189
|
+
return ctx.el("section", { class: "card detail" }, [ctx.el("h3", { text: title }), ...children]);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function link(ctx, text, target, attrs = {}) {
|
|
193
|
+
return ctx.el("a", { href: ctx.href(target), text, ...attrs });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function badge(ctx, text, tone = "") {
|
|
197
|
+
return ctx.el("span", { class: tone ? `badge ${tone}` : "badge", text });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function list(ctx, items) {
|
|
201
|
+
return ctx.el(
|
|
202
|
+
"ul",
|
|
203
|
+
{ class: "grimoire-list" },
|
|
204
|
+
items.map((item) => ctx.el("li", {}, item)),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function table(ctx, headings, rows) {
|
|
209
|
+
return ctx.el("table", { class: "grimoire-table" }, [
|
|
210
|
+
ctx.el("thead", {}, [
|
|
211
|
+
ctx.el(
|
|
212
|
+
"tr",
|
|
213
|
+
{},
|
|
214
|
+
headings.map((heading) => ctx.el("th", { text: heading })),
|
|
215
|
+
),
|
|
216
|
+
]),
|
|
217
|
+
ctx.el(
|
|
218
|
+
"tbody",
|
|
219
|
+
{},
|
|
220
|
+
rows.map((row) =>
|
|
221
|
+
ctx.el(
|
|
222
|
+
"tr",
|
|
223
|
+
{},
|
|
224
|
+
row.map((cell) => ctx.el("td", {}, cell)),
|
|
225
|
+
),
|
|
226
|
+
),
|
|
227
|
+
),
|
|
228
|
+
]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function statusTone(status) {
|
|
232
|
+
if (status === "shipped" || status === "passing" || status === "pass") return "good";
|
|
233
|
+
if (status === "retired" || status === "failing" || status === "fail" || status === "error")
|
|
234
|
+
return "bad";
|
|
235
|
+
return "";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** `<feature>/<flow>` as a link. */
|
|
239
|
+
function flowLink(ctx, ref) {
|
|
240
|
+
const target = targetOf("flow", ref);
|
|
241
|
+
return target === null ? ref : link(ctx, ref, target);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function fileLink(ctx, file) {
|
|
245
|
+
return link(ctx, file, `file/${encodeURIComponent(file)}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function fileList(ctx, files, limit = 12) {
|
|
249
|
+
if (!files.length) return ctx.el("span", { class: "muted", text: "none" });
|
|
250
|
+
const shown = files.slice(0, limit);
|
|
251
|
+
const items = shown.map((file) => [fileLink(ctx, file)]);
|
|
252
|
+
if (files.length > limit)
|
|
253
|
+
items.push([ctx.el("span", { class: "muted", text: `+${files.length - limit} more` })]);
|
|
254
|
+
return list(ctx, items);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ── Views ───────────────────────────────────────────────────────────────────
|
|
258
|
+
|
|
259
|
+
async function homeView(ctx) {
|
|
260
|
+
const data = await ctx.api("summary");
|
|
261
|
+
const { el } = ctx;
|
|
262
|
+
const out = el("div", { class: "grimoire-view" });
|
|
263
|
+
const cards = el("div", { class: "grimoire-cards" }, [
|
|
264
|
+
el("div", { class: "card" }, [
|
|
265
|
+
el("h3", { text: "Check" }),
|
|
266
|
+
link(ctx, `${data.counts.errors} errors, ${data.counts.warnings} warnings`, "check"),
|
|
267
|
+
el("p", { class: "muted", text: `${data.counts.expected} expected (proposed work)` }),
|
|
268
|
+
]),
|
|
269
|
+
el("div", { class: "card" }, [
|
|
270
|
+
el("h3", { text: "Tasks" }),
|
|
271
|
+
link(
|
|
272
|
+
ctx,
|
|
273
|
+
`${data.tasks.open.length - data.tasks.waiting.length} open, ${data.tasks.waiting.length} waiting`,
|
|
274
|
+
"tasks",
|
|
275
|
+
),
|
|
276
|
+
el("p", { class: "muted", text: `${data.tasks.done.length} done` }),
|
|
277
|
+
]),
|
|
278
|
+
el("div", { class: "card" }, [
|
|
279
|
+
el("h3", { text: "Book" }),
|
|
280
|
+
link(ctx, `${data.book.files} files in ${data.book.modules} modules`, "modules"),
|
|
281
|
+
el("p", { class: "muted", text: `routes: ${data.routes}` }),
|
|
282
|
+
]),
|
|
283
|
+
]);
|
|
284
|
+
out.append(cards);
|
|
285
|
+
|
|
286
|
+
if (data.routes === "stale" || data.routes === "missing") {
|
|
287
|
+
out.append(
|
|
288
|
+
el("p", {
|
|
289
|
+
class: "muted",
|
|
290
|
+
text: "The route facts are old or missing. Run warlock grimoire build to refresh them.",
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const features = data.features.features;
|
|
296
|
+
|
|
297
|
+
if (!features.length) {
|
|
298
|
+
out.append(
|
|
299
|
+
ctx.empty(
|
|
300
|
+
data.book.files
|
|
301
|
+
? `No features are written yet. The book below lists ${data.book.files} files; search it above, or open the module graph. Ask your agent to write the features (skill use-the-grimoire).`
|
|
302
|
+
: "The book is empty. Run warlock grimoire build.",
|
|
303
|
+
),
|
|
304
|
+
);
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
out.append(
|
|
309
|
+
section(ctx, "Features", [
|
|
310
|
+
table(
|
|
311
|
+
ctx,
|
|
312
|
+
["Feature", "Title", "Status", "Version", "Flows"],
|
|
313
|
+
features.map((item) => [
|
|
314
|
+
[link(ctx, item.id, `feature/${encodeURIComponent(item.id)}`)],
|
|
315
|
+
[item.title],
|
|
316
|
+
[badge(ctx, item.status, statusTone(item.status))],
|
|
317
|
+
[item.version],
|
|
318
|
+
[item.flows.map((flow) => flow.id).join(", ")],
|
|
319
|
+
]),
|
|
320
|
+
),
|
|
321
|
+
]),
|
|
322
|
+
);
|
|
323
|
+
return out;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function featureView(ctx, id) {
|
|
327
|
+
const [data, graph] = await Promise.all([
|
|
328
|
+
ctx.api(`features/${encodeURIComponent(id)}`),
|
|
329
|
+
ctx.api(`graph/feature/${encodeURIComponent(id)}`).catch(() => null),
|
|
330
|
+
]);
|
|
331
|
+
const { el } = ctx;
|
|
332
|
+
const readme = data.readme;
|
|
333
|
+
const out = el("div", { class: "grimoire-view" }, [
|
|
334
|
+
el("h2", { text: `${plain(readme.title)} (${plain(readme.id)})` }),
|
|
335
|
+
el("p", {}, [
|
|
336
|
+
badge(ctx, plain(readme.status), statusTone(plain(readme.status))),
|
|
337
|
+
` version ${plain(readme.version)}, updated ${plain(readme.updated)}`,
|
|
338
|
+
]),
|
|
339
|
+
]);
|
|
340
|
+
|
|
341
|
+
if (readme.summary) out.append(el("p", { text: readme.summary }));
|
|
342
|
+
|
|
343
|
+
out.append(
|
|
344
|
+
section(ctx, "Flows", [
|
|
345
|
+
data.flows.length
|
|
346
|
+
? table(
|
|
347
|
+
ctx,
|
|
348
|
+
["Flow", "Status", "Since", "Heading"],
|
|
349
|
+
data.flows.map((flow) => [
|
|
350
|
+
[
|
|
351
|
+
link(
|
|
352
|
+
ctx,
|
|
353
|
+
flow.id,
|
|
354
|
+
`flow/${encodeURIComponent(plain(readme.id))}/${encodeURIComponent(flow.id)}`,
|
|
355
|
+
),
|
|
356
|
+
],
|
|
357
|
+
[badge(ctx, flow.status, statusTone(flow.status))],
|
|
358
|
+
[flow.since],
|
|
359
|
+
[flow.heading ?? ""],
|
|
360
|
+
]),
|
|
361
|
+
)
|
|
362
|
+
: ctx.empty("This feature has no flows yet."),
|
|
363
|
+
]),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const map = data.bookmap;
|
|
367
|
+
out.append(
|
|
368
|
+
section(ctx, "Code", [
|
|
369
|
+
el("p", {
|
|
370
|
+
text: `${map.own.length} own files, ${map.borrowed.length} borrowed, ${map.routes.length} routes, ${map.unreached.length} not reached by any flow.`,
|
|
371
|
+
}),
|
|
372
|
+
el("h4", { text: "Routes" }),
|
|
373
|
+
map.routes.length
|
|
374
|
+
? list(
|
|
375
|
+
ctx,
|
|
376
|
+
map.routes.map((item) => [
|
|
377
|
+
link(
|
|
378
|
+
ctx,
|
|
379
|
+
`${item.method} ${item.path}`,
|
|
380
|
+
`route/${encodeURIComponent(item.method)}/${encodeURIComponent(item.path)}`,
|
|
381
|
+
),
|
|
382
|
+
" in ",
|
|
383
|
+
fileLink(ctx, item.file),
|
|
384
|
+
]),
|
|
385
|
+
)
|
|
386
|
+
: el("p", { class: "muted", text: "none" }),
|
|
387
|
+
el("h4", { text: "Pages and screens" }),
|
|
388
|
+
Object.keys(map.pages).length
|
|
389
|
+
? list(
|
|
390
|
+
ctx,
|
|
391
|
+
Object.entries(map.pages).flatMap(([app, pages]) =>
|
|
392
|
+
pages.map((item) => [
|
|
393
|
+
link(
|
|
394
|
+
ctx,
|
|
395
|
+
`${app} ${item.route}`,
|
|
396
|
+
`page/${encodeURIComponent(app)}/${encodeURIComponent(item.route)}`,
|
|
397
|
+
),
|
|
398
|
+
]),
|
|
399
|
+
),
|
|
400
|
+
)
|
|
401
|
+
: el("p", { class: "muted", text: "none" }),
|
|
402
|
+
el("h4", { text: "Files no flow reaches" }),
|
|
403
|
+
fileList(ctx, map.unreached),
|
|
404
|
+
]),
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
if (data.tasks.length) {
|
|
408
|
+
out.append(
|
|
409
|
+
section(ctx, "Open tasks", [
|
|
410
|
+
list(
|
|
411
|
+
ctx,
|
|
412
|
+
data.tasks.map((task) => [
|
|
413
|
+
link(ctx, task.id, `task/${encodeURIComponent(task.id)}`),
|
|
414
|
+
` ${task.title} `,
|
|
415
|
+
badge(ctx, task.status),
|
|
416
|
+
]),
|
|
417
|
+
),
|
|
418
|
+
]),
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
out.append(section(ctx, "Recent changes", [changesView(ctx, data.changes)]));
|
|
423
|
+
|
|
424
|
+
if (data.findings.length)
|
|
425
|
+
out.append(section(ctx, "Findings", [findingsView(ctx, data.findings)]));
|
|
426
|
+
if (graph) out.append(graphView(ctx, graph, "The feature and its neighbours"));
|
|
427
|
+
return out;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function changesView(ctx, changes) {
|
|
431
|
+
if (!changes.length) return ctx.empty("No changelog entries.");
|
|
432
|
+
return list(
|
|
433
|
+
ctx,
|
|
434
|
+
changes.map((change) => [
|
|
435
|
+
badge(ctx, change.word),
|
|
436
|
+
` ${plain(change.version)} `,
|
|
437
|
+
change.flow ? [flowLink(ctx, `${change.feature}/${change.flow}`), " "] : "",
|
|
438
|
+
change.text,
|
|
439
|
+
change.release
|
|
440
|
+
? ` (release ${change.release}${change.date ? `, ${change.date}` : ""})`
|
|
441
|
+
: " (not released)",
|
|
442
|
+
]),
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function findingsView(ctx, findings) {
|
|
447
|
+
return table(
|
|
448
|
+
ctx,
|
|
449
|
+
["Code", "Severity", "Message", "Where"],
|
|
450
|
+
findings.map((finding) => [
|
|
451
|
+
[finding.code],
|
|
452
|
+
[
|
|
453
|
+
badge(
|
|
454
|
+
ctx,
|
|
455
|
+
finding.expected ? `${finding.severity} (expected)` : finding.severity,
|
|
456
|
+
finding.severity === "error" && !finding.expected ? "bad" : "",
|
|
457
|
+
),
|
|
458
|
+
],
|
|
459
|
+
[finding.message],
|
|
460
|
+
[finding.at ? `${finding.at.file}:${finding.at.line}` : (finding.subject.file ?? "")],
|
|
461
|
+
]),
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
async function flowView(ctx, feature, flowId) {
|
|
466
|
+
const data = await ctx.api(`flows/${encodeURIComponent(feature)}/${encodeURIComponent(flowId)}`);
|
|
467
|
+
const { el } = ctx;
|
|
468
|
+
const flow = data.flow;
|
|
469
|
+
const map = data.bookmap;
|
|
470
|
+
const out = el("div", { class: "grimoire-view" }, [
|
|
471
|
+
el("h2", { text: `${plain(flow.heading) ?? plain(flow.id)} (${feature}/${flowId})` }),
|
|
472
|
+
el("p", {}, [
|
|
473
|
+
badge(ctx, plain(flow.status), statusTone(plain(flow.status))),
|
|
474
|
+
` since ${plain(flow.since)}, for ${plain(flow.who)}. `,
|
|
475
|
+
link(ctx, `Back to ${feature}`, `feature/${encodeURIComponent(feature)}`),
|
|
476
|
+
]),
|
|
477
|
+
]);
|
|
478
|
+
|
|
479
|
+
out.append(
|
|
480
|
+
section(ctx, "Steps", [
|
|
481
|
+
map.steps.length
|
|
482
|
+
? table(
|
|
483
|
+
ctx,
|
|
484
|
+
["#", "Type", "Target", "Found", "Files"],
|
|
485
|
+
map.steps.map((step) => [
|
|
486
|
+
[String(step.index)],
|
|
487
|
+
[step.type],
|
|
488
|
+
[
|
|
489
|
+
step.type === "route" && step.target.includes(" ")
|
|
490
|
+
? link(
|
|
491
|
+
ctx,
|
|
492
|
+
step.target,
|
|
493
|
+
`route/${encodeURIComponent(step.target.split(" ")[0])}/${encodeURIComponent(step.target.slice(step.target.indexOf(" ") + 1))}`,
|
|
494
|
+
)
|
|
495
|
+
: step.target,
|
|
496
|
+
],
|
|
497
|
+
[step.found === null ? "" : step.found ? "yes" : "no"],
|
|
498
|
+
[step.files.length ? fileList(ctx, step.files, 6) : ""],
|
|
499
|
+
]),
|
|
500
|
+
)
|
|
501
|
+
: ctx.empty("This flow has no steps."),
|
|
502
|
+
]),
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
out.append(
|
|
506
|
+
section(ctx, "Acceptance criteria", [
|
|
507
|
+
map.criteria.length
|
|
508
|
+
? table(
|
|
509
|
+
ctx,
|
|
510
|
+
["Id", "App", "Criterion", "Result", "Tests"],
|
|
511
|
+
map.criteria.map((criterion) => [
|
|
512
|
+
[criterion.id],
|
|
513
|
+
[criterion.app ?? "all"],
|
|
514
|
+
[criterion.text],
|
|
515
|
+
[badge(ctx, criterion.status, statusTone(criterion.status))],
|
|
516
|
+
[
|
|
517
|
+
criterion.tests.length
|
|
518
|
+
? list(
|
|
519
|
+
ctx,
|
|
520
|
+
criterion.tests.map((test) => [
|
|
521
|
+
fileLink(ctx, test.file),
|
|
522
|
+
`:${test.line} `,
|
|
523
|
+
test.name ?? "",
|
|
524
|
+
" ",
|
|
525
|
+
badge(
|
|
526
|
+
ctx,
|
|
527
|
+
test.stale ? `${test.result}, stale` : test.result,
|
|
528
|
+
statusTone(test.result),
|
|
529
|
+
),
|
|
530
|
+
]),
|
|
531
|
+
)
|
|
532
|
+
: el("span", { class: "muted", text: "no test" }),
|
|
533
|
+
],
|
|
534
|
+
]),
|
|
535
|
+
)
|
|
536
|
+
: ctx.empty("No criteria written."),
|
|
537
|
+
]),
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
out.append(
|
|
541
|
+
section(ctx, "Shown by", [
|
|
542
|
+
map.shownBy.length
|
|
543
|
+
? list(
|
|
544
|
+
ctx,
|
|
545
|
+
map.shownBy.map((shown) => [
|
|
546
|
+
shown.type === "layout"
|
|
547
|
+
? `${shown.app} layout ${shown.id}`
|
|
548
|
+
: link(
|
|
549
|
+
ctx,
|
|
550
|
+
`${shown.app} ${shown.type} ${shown.id}`,
|
|
551
|
+
`page/${encodeURIComponent(shown.app)}/${encodeURIComponent(shown.id)}`,
|
|
552
|
+
),
|
|
553
|
+
` as block ${shown.block}`,
|
|
554
|
+
]),
|
|
555
|
+
)
|
|
556
|
+
: ctx.empty("No app page shows this flow."),
|
|
557
|
+
]),
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
if (flow.cases.length) {
|
|
561
|
+
out.append(
|
|
562
|
+
section(ctx, "Cases", [
|
|
563
|
+
table(
|
|
564
|
+
ctx,
|
|
565
|
+
["Question", "Answer"],
|
|
566
|
+
flow.cases.map((item) => [
|
|
567
|
+
[item.question],
|
|
568
|
+
[item.doesNotApply ? `does not apply: ${item.answer}` : item.answer],
|
|
569
|
+
]),
|
|
570
|
+
),
|
|
571
|
+
]),
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (flow.unknowns.length) {
|
|
576
|
+
out.append(
|
|
577
|
+
section(ctx, "Unknowns", [
|
|
578
|
+
list(
|
|
579
|
+
ctx,
|
|
580
|
+
flow.unknowns.map((item) => [item.text]),
|
|
581
|
+
),
|
|
582
|
+
]),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
out.append(section(ctx, "History", [changesView(ctx, data.history)]));
|
|
587
|
+
if (data.findings.length)
|
|
588
|
+
out.append(section(ctx, "Findings", [findingsView(ctx, data.findings)]));
|
|
589
|
+
return out;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async function pageView(ctx, app, key) {
|
|
593
|
+
const path = `${encodeURIComponent(app)}/pages/${encodeURIComponent(key)}`;
|
|
594
|
+
const [data, graph] = await Promise.all([
|
|
595
|
+
ctx.api(`apps/${path}`),
|
|
596
|
+
ctx
|
|
597
|
+
.api(`graph/page?app=${encodeURIComponent(app)}&page=${encodeURIComponent(key)}`)
|
|
598
|
+
.catch(() => null),
|
|
599
|
+
]);
|
|
600
|
+
const { el } = ctx;
|
|
601
|
+
const page = data.page;
|
|
602
|
+
const out = el("div", { class: "grimoire-view" }, [
|
|
603
|
+
el("h2", {
|
|
604
|
+
text: `${plain(page.heading) ?? page.id} (${app} ${plain(page.route) ?? plain(page.screen) ?? page.id})`,
|
|
605
|
+
}),
|
|
606
|
+
]);
|
|
607
|
+
|
|
608
|
+
if (page.purpose) out.append(el("p", { text: page.purpose }));
|
|
609
|
+
|
|
610
|
+
const rows = [
|
|
611
|
+
...(data.layout ? data.layout.blocks.map((row) => ({ row, from: "layout" })) : []),
|
|
612
|
+
...page.blocks.map((row) => ({ row, from: "page" })),
|
|
613
|
+
];
|
|
614
|
+
out.append(
|
|
615
|
+
section(ctx, "Blocks", [
|
|
616
|
+
rows.length
|
|
617
|
+
? table(
|
|
618
|
+
ctx,
|
|
619
|
+
["Block", "From", "Flow", "Who", "Changes with"],
|
|
620
|
+
rows.map(({ row, from }) => [
|
|
621
|
+
[row.block],
|
|
622
|
+
[from],
|
|
623
|
+
[row.flow ? flowLink(ctx, row.flow) : ""],
|
|
624
|
+
[row.who.everyone ? "everyone" : row.who.conditions.join(", ")],
|
|
625
|
+
[
|
|
626
|
+
row.changesWith
|
|
627
|
+
.map((change) =>
|
|
628
|
+
change.condition ? `${change.condition}: ${change.text}` : change.text,
|
|
629
|
+
)
|
|
630
|
+
.join("; "),
|
|
631
|
+
],
|
|
632
|
+
]),
|
|
633
|
+
)
|
|
634
|
+
: ctx.empty("No blocks are written for this page."),
|
|
635
|
+
]),
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
if (page.blockFiles.length) {
|
|
639
|
+
out.append(
|
|
640
|
+
section(
|
|
641
|
+
ctx,
|
|
642
|
+
"Block details",
|
|
643
|
+
page.blockFiles.map((block) =>
|
|
644
|
+
el("div", {}, [
|
|
645
|
+
el("h4", { text: block.id }),
|
|
646
|
+
list(
|
|
647
|
+
ctx,
|
|
648
|
+
block.details.map((detail) => [`${detail.name}: ${detail.text}`]),
|
|
649
|
+
),
|
|
650
|
+
]),
|
|
651
|
+
),
|
|
652
|
+
),
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (data.book) {
|
|
657
|
+
out.append(
|
|
658
|
+
section(ctx, "In the code", [
|
|
659
|
+
el("p", {}, [fileLink(ctx, data.book.file)]),
|
|
660
|
+
data.book.layouts?.length
|
|
661
|
+
? el("p", {}, ["Layouts: ", fileList(ctx, data.book.layouts)])
|
|
662
|
+
: "",
|
|
663
|
+
data.book.requires?.length
|
|
664
|
+
? el("p", { text: `Requires: ${data.book.requires.join(", ")}` })
|
|
665
|
+
: "",
|
|
666
|
+
]),
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (graph) out.append(graphView(ctx, graph, "The page and its blocks"));
|
|
671
|
+
return out;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
async function appsView(ctx) {
|
|
675
|
+
const data = await ctx.api("apps");
|
|
676
|
+
if (!data.apps.length) return ctx.empty("No apps are written in grimoire/apps.");
|
|
677
|
+
return ctx.el(
|
|
678
|
+
"div",
|
|
679
|
+
{ class: "grimoire-view" },
|
|
680
|
+
data.apps.map((app) =>
|
|
681
|
+
section(ctx, `${app.id} (${app.type})`, [
|
|
682
|
+
ctx.el("p", { class: "muted", text: app.root }),
|
|
683
|
+
app.pages.length || app.screens.length
|
|
684
|
+
? list(
|
|
685
|
+
ctx,
|
|
686
|
+
[...app.pages, ...app.screens].map((id) => [
|
|
687
|
+
link(ctx, id, `page/${encodeURIComponent(app.id)}/${encodeURIComponent(id)}`),
|
|
688
|
+
]),
|
|
689
|
+
)
|
|
690
|
+
: ctx.empty("No pages written."),
|
|
691
|
+
]),
|
|
692
|
+
),
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
async function tasksView(ctx, only) {
|
|
697
|
+
const data = await ctx.api("tasks");
|
|
698
|
+
// `waiting` is the part of `open` that waits for the owner: each task shows in one group only.
|
|
699
|
+
const waiting = new Set(data.waiting.map((task) => task.id));
|
|
700
|
+
const groups = [
|
|
701
|
+
["Open", data.open.filter((task) => !waiting.has(task.id))],
|
|
702
|
+
["Waiting for approval", data.waiting],
|
|
703
|
+
["Done", data.done],
|
|
704
|
+
]
|
|
705
|
+
.map(([title, items]) => [title, only ? items.filter((task) => task.id === only) : items])
|
|
706
|
+
.filter(([, items]) => items.length);
|
|
707
|
+
|
|
708
|
+
if (!groups.length) {
|
|
709
|
+
return ctx.empty(only ? `No task ${only}.` : "No tasks are written in grimoire/tasks.");
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return ctx.el(
|
|
713
|
+
"div",
|
|
714
|
+
{ class: "grimoire-view" },
|
|
715
|
+
groups.map(([title, items]) =>
|
|
716
|
+
section(ctx, `${title} (${items.length})`, [
|
|
717
|
+
table(
|
|
718
|
+
ctx,
|
|
719
|
+
["Task", "Type", "Status", "Feature", "Title", "Decision needed"],
|
|
720
|
+
items.map((task) => [
|
|
721
|
+
[link(ctx, task.id, `task/${encodeURIComponent(task.id)}`)],
|
|
722
|
+
[task.type],
|
|
723
|
+
[badge(ctx, task.status)],
|
|
724
|
+
[
|
|
725
|
+
task.feature
|
|
726
|
+
? link(ctx, task.feature, `feature/${encodeURIComponent(task.feature)}`)
|
|
727
|
+
: "",
|
|
728
|
+
],
|
|
729
|
+
[task.title],
|
|
730
|
+
[task.decisionNeeded ?? ""],
|
|
731
|
+
]),
|
|
732
|
+
),
|
|
733
|
+
]),
|
|
734
|
+
),
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
async function releasesView(ctx) {
|
|
739
|
+
const data = await ctx.api("releases");
|
|
740
|
+
if (!data.releases.length) return ctx.empty("No releases are written in grimoire/releases.");
|
|
741
|
+
return section(ctx, "Releases", [
|
|
742
|
+
table(
|
|
743
|
+
ctx,
|
|
744
|
+
["Release", "Date", "File"],
|
|
745
|
+
data.releases.map((item) => [
|
|
746
|
+
[link(ctx, item.release, `release/${encodeURIComponent(item.release)}`)],
|
|
747
|
+
[item.date],
|
|
748
|
+
[item.file],
|
|
749
|
+
]),
|
|
750
|
+
),
|
|
751
|
+
]);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
async function releaseView(ctx, id) {
|
|
755
|
+
const data = await ctx.api(`releases/${encodeURIComponent(id)}`);
|
|
756
|
+
const entries = data.collected?.entries ?? [];
|
|
757
|
+
return ctx.el("div", { class: "grimoire-view" }, [
|
|
758
|
+
ctx.el("h2", { text: `Release ${plain(data.release)} (${plain(data.date)})` }),
|
|
759
|
+
data.brief ? ctx.el("p", { text: data.brief }) : "",
|
|
760
|
+
section(ctx, "Collected entries", [
|
|
761
|
+
entries.length
|
|
762
|
+
? list(
|
|
763
|
+
ctx,
|
|
764
|
+
entries.map((entry) => [
|
|
765
|
+
`${entry.feature} ${entry.version}: ${entry.text ?? JSON.stringify(entry)}`,
|
|
766
|
+
]),
|
|
767
|
+
)
|
|
768
|
+
: ctx.empty("Nothing is listed for this release."),
|
|
769
|
+
]),
|
|
770
|
+
]);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
async function checkView(ctx) {
|
|
774
|
+
const report = await ctx.api("check");
|
|
775
|
+
const { counts } = report;
|
|
776
|
+
return ctx.el("div", { class: "grimoire-view" }, [
|
|
777
|
+
ctx.el("h2", { text: report.ok ? "Check: no unexpected errors" : "Check: errors found" }),
|
|
778
|
+
ctx.el("p", {
|
|
779
|
+
class: "muted",
|
|
780
|
+
text: `${counts.errors} errors, ${counts.warnings} warnings, ${counts.expected} expected; routes ${report.routes}`,
|
|
781
|
+
}),
|
|
782
|
+
report.findings.length ? findingsView(ctx, report.findings) : ctx.empty("No findings."),
|
|
783
|
+
]);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
async function fileView(ctx, path) {
|
|
787
|
+
const [data, graph] = await Promise.all([
|
|
788
|
+
ctx.api(`file?path=${encodeURIComponent(path)}`),
|
|
789
|
+
ctx.api(`graph/file?path=${encodeURIComponent(path)}`).catch(() => null),
|
|
790
|
+
]);
|
|
791
|
+
const { el } = ctx;
|
|
792
|
+
const entry = data.entry;
|
|
793
|
+
const out = el("div", { class: "grimoire-view" }, [
|
|
794
|
+
el("h2", { text: entry.file }),
|
|
795
|
+
el("p", { class: "muted", text: `${entry.type} in ${entry.module}, ${entry.lines} lines` }),
|
|
796
|
+
]);
|
|
797
|
+
if (entry.about) out.append(el("p", { text: entry.about }));
|
|
798
|
+
|
|
799
|
+
const owner = [];
|
|
800
|
+
if (entry.feature)
|
|
801
|
+
owner.push(
|
|
802
|
+
"Owned by ",
|
|
803
|
+
link(ctx, entry.feature, `feature/${encodeURIComponent(entry.feature)}`),
|
|
804
|
+
". ",
|
|
805
|
+
);
|
|
806
|
+
if (entry.borrowedBy.length) owner.push("Borrowed by ", entry.borrowedBy.join(", "), ". ");
|
|
807
|
+
if (entry.flows.length)
|
|
808
|
+
owner.push("Used by flows: ", ...entry.flows.flatMap((flow) => [flowLink(ctx, flow), " "]));
|
|
809
|
+
if (owner.length) out.append(el("p", {}, owner));
|
|
810
|
+
|
|
811
|
+
out.append(
|
|
812
|
+
section(ctx, "Exports", [
|
|
813
|
+
entry.exports.length
|
|
814
|
+
? list(
|
|
815
|
+
ctx,
|
|
816
|
+
entry.exports.map((item) => [`${item.name}${item.about ? `: ${item.about}` : ""}`]),
|
|
817
|
+
)
|
|
818
|
+
: el("span", { class: "muted", text: "none" }),
|
|
819
|
+
]),
|
|
820
|
+
section(ctx, "Imports", [fileList(ctx, entry.imports, 20)]),
|
|
821
|
+
section(ctx, "Imported by", [fileList(ctx, entry.importedBy, 20)]),
|
|
822
|
+
);
|
|
823
|
+
|
|
824
|
+
if (entry.routes.length) {
|
|
825
|
+
out.append(
|
|
826
|
+
section(ctx, "Routes", [
|
|
827
|
+
list(
|
|
828
|
+
ctx,
|
|
829
|
+
entry.routes.map((item) => [
|
|
830
|
+
link(
|
|
831
|
+
ctx,
|
|
832
|
+
`${item.method} ${item.path}`,
|
|
833
|
+
`route/${encodeURIComponent(item.method)}/${encodeURIComponent(item.path)}`,
|
|
834
|
+
),
|
|
835
|
+
` (${item.via})`,
|
|
836
|
+
]),
|
|
837
|
+
),
|
|
838
|
+
]),
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
if (graph) out.append(graphView(ctx, graph, "The file and its neighbours"));
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
async function routeView(ctx, method, path) {
|
|
847
|
+
const data = await ctx.api(
|
|
848
|
+
`route?method=${encodeURIComponent(method)}&path=${encodeURIComponent(path)}`,
|
|
849
|
+
);
|
|
850
|
+
const { el } = ctx;
|
|
851
|
+
const found = data.route;
|
|
852
|
+
const out = el("div", { class: "grimoire-view" }, [
|
|
853
|
+
el("h2", { text: `${found.method} ${found.path}` }),
|
|
854
|
+
el("p", { class: "muted", text: found.description ?? found.handler }),
|
|
855
|
+
]);
|
|
856
|
+
if (found.handlerFile) out.append(el("p", {}, ["Handler: ", fileLink(ctx, found.handlerFile)]));
|
|
857
|
+
out.append(
|
|
858
|
+
section(ctx, "Files behind it", [fileList(ctx, data.files, 20)]),
|
|
859
|
+
section(ctx, "Flow steps", [
|
|
860
|
+
data.steps.length
|
|
861
|
+
? list(
|
|
862
|
+
ctx,
|
|
863
|
+
data.steps.map((step) => [flowLink(ctx, step.flow), ` step ${step.index}`]),
|
|
864
|
+
)
|
|
865
|
+
: el("span", { class: "muted", text: "none" }),
|
|
866
|
+
]),
|
|
867
|
+
);
|
|
868
|
+
return out;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
async function modulesView(ctx) {
|
|
872
|
+
const graph = await ctx.api("graph/modules");
|
|
873
|
+
return ctx.el("div", { class: "grimoire-view" }, [
|
|
874
|
+
ctx.el("h2", { text: "Module coupling" }),
|
|
875
|
+
ctx.el("p", {
|
|
876
|
+
class: "muted",
|
|
877
|
+
text: "Lines are imports between modules; thicker means more imports. The most connected modules are drawn.",
|
|
878
|
+
}),
|
|
879
|
+
graphView(ctx, graph, "Modules"),
|
|
880
|
+
]);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/** Pick the view for the hash route. */
|
|
884
|
+
async function body(ctx) {
|
|
885
|
+
const parts = ctx.route ? ctx.route.split("/").map(decodeSegment) : [];
|
|
886
|
+
const [type = "", first = "", second = ""] = parts;
|
|
887
|
+
|
|
888
|
+
switch (type) {
|
|
889
|
+
case "feature":
|
|
890
|
+
return featureView(ctx, first);
|
|
891
|
+
case "flow":
|
|
892
|
+
return flowView(ctx, first, second);
|
|
893
|
+
case "page":
|
|
894
|
+
return pageView(ctx, first, parts.slice(2).join("/"));
|
|
895
|
+
case "apps":
|
|
896
|
+
return appsView(ctx);
|
|
897
|
+
case "tasks":
|
|
898
|
+
return tasksView(ctx, "");
|
|
899
|
+
case "task":
|
|
900
|
+
return tasksView(ctx, first);
|
|
901
|
+
case "releases":
|
|
902
|
+
return releasesView(ctx);
|
|
903
|
+
case "release":
|
|
904
|
+
return releaseView(ctx, first);
|
|
905
|
+
case "check":
|
|
906
|
+
return checkView(ctx);
|
|
907
|
+
case "file":
|
|
908
|
+
return fileView(ctx, first);
|
|
909
|
+
case "route":
|
|
910
|
+
return routeView(ctx, first, parts.slice(2).join("/"));
|
|
911
|
+
case "modules":
|
|
912
|
+
return modulesView(ctx);
|
|
913
|
+
default:
|
|
914
|
+
return homeView(ctx);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/** The header: navigation and the one search box. Results appear under the box. */
|
|
919
|
+
function header(ctx) {
|
|
920
|
+
const { el } = ctx;
|
|
921
|
+
const results = el("div", { class: "grimoire-results" });
|
|
922
|
+
let token = 0;
|
|
923
|
+
let timer = null;
|
|
924
|
+
|
|
925
|
+
async function run(text) {
|
|
926
|
+
const mine = ++token;
|
|
927
|
+
results.replaceChildren?.();
|
|
928
|
+
if (!text.trim()) return;
|
|
929
|
+
try {
|
|
930
|
+
const answer = await ctx.api(`search?q=${encodeURIComponent(text.trim())}&limit=15`);
|
|
931
|
+
if (mine !== token) return;
|
|
932
|
+
results.replaceChildren?.();
|
|
933
|
+
if (!answer.hits.length) {
|
|
934
|
+
results.append(ctx.empty(`Nothing matches "${text.trim()}".`));
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
results.append(
|
|
938
|
+
list(
|
|
939
|
+
ctx,
|
|
940
|
+
answer.hits.map((hit) => {
|
|
941
|
+
const target = targetOf(hit.type, hit.id);
|
|
942
|
+
return [
|
|
943
|
+
badge(ctx, hit.type),
|
|
944
|
+
" ",
|
|
945
|
+
target === null ? hit.id : link(ctx, hit.id, target),
|
|
946
|
+
hit.detail ? el("span", { class: "muted", text: ` ${hit.detail}` }) : "",
|
|
947
|
+
];
|
|
948
|
+
}),
|
|
949
|
+
),
|
|
950
|
+
);
|
|
951
|
+
} catch (error) {
|
|
952
|
+
if (mine === token)
|
|
953
|
+
results.append(el("p", { class: "error", text: `Search failed: ${error.message}` }));
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
const input = el("input", {
|
|
958
|
+
type: "search",
|
|
959
|
+
class: "grimoire-search",
|
|
960
|
+
placeholder: "Search flows, blocks, routes, files and tasks",
|
|
961
|
+
"aria-label": "Search the Grimoire",
|
|
962
|
+
oninput: (event) => {
|
|
963
|
+
const text = event.target.value;
|
|
964
|
+
if (timer !== null) clearTimeout(timer);
|
|
965
|
+
timer = setTimeout(() => run(text), 150);
|
|
966
|
+
},
|
|
967
|
+
});
|
|
968
|
+
const nav = el(
|
|
969
|
+
"nav",
|
|
970
|
+
{ class: "grimoire-nav" },
|
|
971
|
+
NAV.map(([target, label]) => link(ctx, label, target)),
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
return { element: el("div", { class: "grimoire-header" }, [nav, input, results]), run, input };
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/** The context with `el()` flattening nested child lists and skipping empty ones. */
|
|
978
|
+
function withFlatChildren(context) {
|
|
979
|
+
const flat = (children) =>
|
|
980
|
+
Array.isArray(children)
|
|
981
|
+
? children
|
|
982
|
+
.flat(Infinity)
|
|
983
|
+
.filter((child) => child !== null && child !== undefined && child !== false)
|
|
984
|
+
: children;
|
|
985
|
+
return { ...context, el: (tag, attrs, children) => context.el(tag, attrs, flat(children)) };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
async function renderGrimoire(context) {
|
|
989
|
+
const ctx = withFlatChildren(context);
|
|
990
|
+
const { root, el } = ctx;
|
|
991
|
+
if (typeof ctx.asset === "function")
|
|
992
|
+
root.append(el("link", { rel: "stylesheet", href: ctx.asset("grimoire.css") }));
|
|
993
|
+
const top = header(ctx);
|
|
994
|
+
const content = el("div", { class: "grimoire-body" });
|
|
995
|
+
root.append(top.element, content);
|
|
996
|
+
|
|
997
|
+
try {
|
|
998
|
+
content.append(await body(ctx));
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
content.append(el("p", { class: "error", text: `Could not load this view: ${error.message}` }));
|
|
1001
|
+
}
|
|
1002
|
+
return root;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
export default renderGrimoire;
|