@shadowclone/skills 0.0.53 → 0.0.54
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/package.json +1 -1
- package/skills/guided-pr-review/SKILL.md +3 -1
- package/skills/guided-pr-review/assets/fonts/OFL.txt +93 -0
- package/skills/guided-pr-review/assets/fonts/montserrat.mjs +1 -0
- package/skills/guided-pr-review/assets/theme.mjs +26 -0
- package/skills/guided-pr-review/scripts/render.mjs +2 -1
- package/skills/plan-with-review-page/SKILL.md +54 -28
- package/skills/plan-with-review-page/assets/blocks.mjs +74 -0
- package/skills/plan-with-review-page/assets/fonts/OFL.txt +93 -0
- package/skills/plan-with-review-page/assets/fonts/montserrat.mjs +1 -0
- package/skills/plan-with-review-page/assets/markdown.mjs +107 -0
- package/skills/plan-with-review-page/assets/style.mjs +56 -0
- package/skills/plan-with-review-page/scripts/render.mjs +107 -0
- package/skills/shadowclone-projects/SKILL.md +40 -24
- package/skills/plan-with-review-page/assets/review-page.html +0 -197
- package/skills/plan-with-review-page/scripts/validate-page.mjs +0 -199
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>Plan review</title>
|
|
7
|
-
<style>
|
|
8
|
-
:root {
|
|
9
|
-
--page: #fbfaf7; --text: #1d1d1b; --muted: #66645f; --card: #ffffff; --line: #e2dfd8; --soft: #f3f1ec;
|
|
10
|
-
--done: #2f7d4f; --doing: #a8701c; --todo: #77756f; --blocked: #b5443b; --skipped: #6d5fa8;
|
|
11
|
-
}
|
|
12
|
-
@media (prefers-color-scheme: dark) {
|
|
13
|
-
:root {
|
|
14
|
-
--page: #161615; --text: #ecebe7; --muted: #a09e98; --card: #1f1f1d; --line: #34332f; --soft: #262624;
|
|
15
|
-
--done: #5fbf83; --doing: #e0a84a; --todo: #8f8c85; --blocked: #e57b72; --skipped: #a99be8;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
* { box-sizing: border-box; }
|
|
19
|
-
body { margin: 0; background: var(--page); color: var(--text); font: 15px/1.6 system-ui, sans-serif; }
|
|
20
|
-
main { max-width: 1000px; margin: 0 auto; padding: 32px 16px 64px; }
|
|
21
|
-
h1 { font-size: 25px; margin: 0 0 6px; } h2 { font-size: 18px; margin: 34px 0 10px; }
|
|
22
|
-
h3 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); } p { margin: 0 0 10px; } a { color: inherit; }
|
|
23
|
-
nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; margin: 14px 0 0; }
|
|
24
|
-
.meta, .note, .counts span { color: var(--muted); font-size: 13px; }
|
|
25
|
-
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
|
|
26
|
-
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
|
|
27
|
-
.counts b { display: block; font-size: 22px; } .scroll { overflow-x: auto; } ul { margin: 0; padding-left: 20px; }
|
|
28
|
-
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
29
|
-
th, td { text-align: left; vertical-align: top; padding: 7px 8px; border-bottom: 1px solid var(--line); }
|
|
30
|
-
tr:last-child td { border-bottom: 0; } th { color: var(--muted); font-weight: 600; }
|
|
31
|
-
code, pre { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
32
|
-
code { background: var(--soft); padding: 1px 4px; border-radius: 4px; } pre { white-space: pre-wrap; margin: 0; }
|
|
33
|
-
.status { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
|
|
34
|
-
.done, .approved { color: var(--done); } .doing, .draft, .in-progress { color: var(--doing); } .todo { color: var(--todo); }
|
|
35
|
-
.blocked { color: var(--blocked); } .skipped { color: var(--skipped); }
|
|
36
|
-
#diagram img { display: block; max-width: 100%; height: auto; margin-bottom: 10px; }
|
|
37
|
-
</style>
|
|
38
|
-
</head>
|
|
39
|
-
<body>
|
|
40
|
-
<main>
|
|
41
|
-
<h1 id="title"></h1>
|
|
42
|
-
<p><span id="status"></span></p>
|
|
43
|
-
<p id="summary"></p>
|
|
44
|
-
<p class="meta">Plan file: <code id="plan-path"></code>. Updated: <span id="updated"></span>.</p>
|
|
45
|
-
<nav id="contents"></nav>
|
|
46
|
-
<div class="counts" id="counts"></div>
|
|
47
|
-
<div id="sections"></div>
|
|
48
|
-
</main>
|
|
49
|
-
<script type="application/json" id="plan">
|
|
50
|
-
{
|
|
51
|
-
"title": "TEMPLATE: A short name for the change",
|
|
52
|
-
"status": "draft",
|
|
53
|
-
"summary": "TEMPLATE: Two or three sentences: what changes, why, and the result for the user.",
|
|
54
|
-
"planPath": "TEMPLATE: The absolute path of the plan file",
|
|
55
|
-
"updated": "TEMPLATE: The date and time of this update",
|
|
56
|
-
"problem": { "statement": "TEMPLATE: What is wrong or missing, as the user sees it.", "impact": "TEMPLATE: Who it affects, how often, and what it costs them." },
|
|
57
|
-
"evidence": [
|
|
58
|
-
{ "fact": "TEMPLATE: One thing that happened or that you observed.", "source": "TEMPLATE: A path:line, a command and its output, or a URL", "kind": "measured" }
|
|
59
|
-
],
|
|
60
|
-
"causes": [
|
|
61
|
-
{ "id": "C1", "cause": "TEMPLATE: Why the problem happens.", "origin": "TEMPLATE: The path:line where the behavior first goes wrong" }
|
|
62
|
-
],
|
|
63
|
-
"ruledOut": [
|
|
64
|
-
{ "cause": "TEMPLATE: A cause that you tested and rejected.", "reason": "TEMPLATE: The observation that ruled it out." }
|
|
65
|
-
],
|
|
66
|
-
"approach": "TEMPLATE: The fix in one short paragraph.",
|
|
67
|
-
"changes": [
|
|
68
|
-
{ "id": "F1", "change": "TEMPLATE: One change.", "files": ["TEMPLATE: path/to/file"], "addresses": ["C1"], "worksBecause": "TEMPLATE: Why this change removes the cause." }
|
|
69
|
-
],
|
|
70
|
-
"alternatives": [
|
|
71
|
-
{ "option": "TEMPLATE: Another way, or no change.", "tradeoff": "TEMPLATE: What it gives, what it costs, and why the plan does not use it.", "verdict": "rejected" }
|
|
72
|
-
],
|
|
73
|
-
"risks": [
|
|
74
|
-
{ "id": "R1", "risk": "TEMPLATE: What can go wrong after the change.", "mitigation": "TEMPLATE: How the plan prevents it or finds it early." }
|
|
75
|
-
],
|
|
76
|
-
"decisions": [
|
|
77
|
-
{ "question": "TEMPLATE: A decision.", "answer": "TEMPLATE: The answer.", "source": "user", "reason": "TEMPLATE: Why this answer." }
|
|
78
|
-
],
|
|
79
|
-
"open": [{ "question": "TEMPLATE: A question that is still open.", "blocks": "TEMPLATE: The step that waits for the answer." }],
|
|
80
|
-
"steps": [{ "status": "todo", "text": "TEMPLATE: One step.", "note": "" }],
|
|
81
|
-
"verification": [
|
|
82
|
-
{ "check": "TEMPLATE: A command or a manual check.", "expected": "TEMPLATE: The result that proves the fix.", "proves": ["C1"] }
|
|
83
|
-
],
|
|
84
|
-
"followUps": [],
|
|
85
|
-
"diagram": "flowchart LR\n Problem --> Cause --> Fix --> Check"
|
|
86
|
-
}
|
|
87
|
-
</script>
|
|
88
|
-
<script>
|
|
89
|
-
const plan = JSON.parse(document.getElementById("plan").textContent);
|
|
90
|
-
const element = (name, text, className) => {
|
|
91
|
-
const node = document.createElement(name);
|
|
92
|
-
if (text !== undefined) text.split("`").forEach((part, index) => node.append(index % 2 ? Object.assign(document.createElement("code"), { textContent: part }) : part));
|
|
93
|
-
if (className) node.className = className;
|
|
94
|
-
return node;
|
|
95
|
-
};
|
|
96
|
-
const badge = (status) => element("span", status, `status ${status.replace(" ", "-")}`);
|
|
97
|
-
const table = (headings, rows) => {
|
|
98
|
-
const node = element("table");
|
|
99
|
-
const head = element("tr");
|
|
100
|
-
headings.forEach((heading) => head.append(element("th", heading)));
|
|
101
|
-
node.append(head);
|
|
102
|
-
for (const cells of rows) {
|
|
103
|
-
const row = element("tr");
|
|
104
|
-
for (const cell of cells) {
|
|
105
|
-
const data = element("td", cell instanceof Node ? undefined : cell);
|
|
106
|
-
if (cell instanceof Node) data.append(cell);
|
|
107
|
-
row.append(data);
|
|
108
|
-
}
|
|
109
|
-
node.append(row);
|
|
110
|
-
}
|
|
111
|
-
return node;
|
|
112
|
-
};
|
|
113
|
-
const either = (items, render, text) => (items.length ? render(items) : element("p", text, "note"));
|
|
114
|
-
const bullets = (items) => {
|
|
115
|
-
const node = element("ul");
|
|
116
|
-
items.forEach((item) => node.append(element("li", item)));
|
|
117
|
-
return node;
|
|
118
|
-
};
|
|
119
|
-
const causeText = (id) => `${id}: ${plan.causes.find((cause) => cause.id === id)?.cause ?? plan.risks.find((risk) => risk.id === id)?.risk ?? "unknown id"}`;
|
|
120
|
-
const fixWorks = plan.causes.map((cause) => [
|
|
121
|
-
causeText(cause.id),
|
|
122
|
-
plan.changes.filter((change) => change.addresses.includes(cause.id)).map((change) => `${change.id}: ${change.worksBecause}`).join(" "),
|
|
123
|
-
plan.verification.filter((check) => check.proves.includes(cause.id)).map((check) => check.check).join(" "),
|
|
124
|
-
]);
|
|
125
|
-
const diagramSlot = element("div");
|
|
126
|
-
const sections = [
|
|
127
|
-
["problem", "The problem", () => [element("p", plan.problem.statement), element("p", plan.problem.impact)]],
|
|
128
|
-
["evidence", "What happened", () => [table(["Fact", "Source", "Kind"], plan.evidence.map((item) => [item.fact, item.source, item.kind]))]],
|
|
129
|
-
["causes", "Why it happened", () => [
|
|
130
|
-
table(["Id", "Cause", "Origin"], plan.causes.map((cause) => [cause.id, cause.cause, cause.origin])),
|
|
131
|
-
element("h3", "Causes ruled out"),
|
|
132
|
-
either(plan.ruledOut, (items) => table(["Cause", "Why it is not the cause"], items.map((item) => [item.cause, item.reason])), "None tested."),
|
|
133
|
-
]],
|
|
134
|
-
["fix", "The fix", () => [
|
|
135
|
-
element("p", plan.approach),
|
|
136
|
-
table(["Id", "Change", "Files", "Addresses"], plan.changes.map((change) => [change.id, change.change, change.files.join(", "), change.addresses.join(", ")])),
|
|
137
|
-
diagramSlot,
|
|
138
|
-
]],
|
|
139
|
-
["works", "Why the fix works", () => [table(["Cause", "How the fix removes it", "Check that proves it"], fixWorks)]],
|
|
140
|
-
["alternatives", "Alternatives considered", () => [table(["Option", "Trade-off", "Verdict"], plan.alternatives.map((item) => [item.option, item.tradeoff, item.verdict]))]],
|
|
141
|
-
["risks", "Risks", () => [table(["Id", "Risk", "Mitigation"], plan.risks.map((item) => [item.id, item.risk, item.mitigation]))]],
|
|
142
|
-
["decisions", "Decisions", () => [either(plan.decisions, (items) => table(["Question", "Answer", "Source", "Reason"], items.map((item) => [item.question, item.answer, item.source, item.reason])), "No decisions yet.")]],
|
|
143
|
-
["open", "Open questions", () => [either(plan.open, (items) => table(["Question", "What it blocks"], items.map((item) => [item.question, item.blocks])), "No open questions.")]],
|
|
144
|
-
["steps", "Steps", () => [table(["Status", "Step", "Note"], plan.steps.map((step) => [badge(step.status), step.text, step.note]))]],
|
|
145
|
-
["verification", "Verification", () => [table(["Check", "Expected result", "Proves"], plan.verification.map((check) => [check.check, check.expected, check.proves.map(causeText).join(" ")]))]],
|
|
146
|
-
["follow-ups", "Follow-ups", () => [either(plan.followUps, bullets, "None.")]],
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
document.title = plan.title;
|
|
150
|
-
document.getElementById("status").replaceWith(badge(plan.status));
|
|
151
|
-
const headerText = [["title", plan.title], ["summary", plan.summary], ["plan-path", plan.planPath], ["updated", plan.updated]];
|
|
152
|
-
headerText.forEach(([id, value]) => document.getElementById(id).append(element("span", value)));
|
|
153
|
-
|
|
154
|
-
const stepsLeft = plan.steps.filter((step) => !["done", "skipped"].includes(step.status)).length;
|
|
155
|
-
const counts = [[plan.causes.length, "causes"], [plan.steps.filter((step) => step.status === "done").length, "steps done"], [stepsLeft, "steps left"], [plan.open.length, "open questions"]];
|
|
156
|
-
for (const [count, label] of counts) {
|
|
157
|
-
const node = element("div", undefined, "card");
|
|
158
|
-
node.append(element("b", String(count)), element("span", label));
|
|
159
|
-
document.getElementById("counts").append(node);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (const [id, heading, render] of sections) {
|
|
163
|
-
const section = Object.assign(element("section"), { id });
|
|
164
|
-
const body = element("div", undefined, "card scroll");
|
|
165
|
-
body.append(...render());
|
|
166
|
-
section.append(element("h2", heading), body);
|
|
167
|
-
document.getElementById("sections").append(section);
|
|
168
|
-
document.getElementById("contents").append(Object.assign(element("a", heading), { href: `#${id}` }));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (plan.diagram) {
|
|
172
|
-
const figure = element("div");
|
|
173
|
-
const note = element("p", "The diagram shows as source text until the pinned Mermaid file loads.", "note");
|
|
174
|
-
figure.id = "diagram";
|
|
175
|
-
diagramSlot.append(element("h3", "Diagram"), figure, note, element("pre", plan.diagram));
|
|
176
|
-
|
|
177
|
-
const script = Object.assign(document.createElement("script"), {
|
|
178
|
-
src: "https://cdn.jsdelivr.net/npm/mermaid@12.1.0/dist/mermaid.min.js",
|
|
179
|
-
integrity: "sha384-EbBpjO7rlR6eqZEcG7GaPpyk9H9WrMyPWX4d3KvPYltgt8Z8l0z6R56B1qP40pR4",
|
|
180
|
-
crossOrigin: "anonymous",
|
|
181
|
-
});
|
|
182
|
-
script.onload = async () => {
|
|
183
|
-
const dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
184
|
-
window.mermaid.initialize({ startOnLoad: false, securityLevel: "strict", htmlLabels: false, flowchart: { htmlLabels: false }, theme: dark ? "dark" : "default" });
|
|
185
|
-
const { svg } = await window.mermaid.render("plan-diagram", plan.diagram);
|
|
186
|
-
const image = Object.assign(document.createElement("img"), { alt: "Plan diagram", src: `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}` });
|
|
187
|
-
figure.replaceChildren(image);
|
|
188
|
-
note.textContent = "Diagram source:";
|
|
189
|
-
};
|
|
190
|
-
script.onerror = () => {
|
|
191
|
-
note.textContent = "Mermaid did not load, so the diagram shows as source text.";
|
|
192
|
-
};
|
|
193
|
-
document.head.append(script);
|
|
194
|
-
}
|
|
195
|
-
</script>
|
|
196
|
-
</body>
|
|
197
|
-
</html>
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
const dashes = new RegExp(`[${String.fromCharCode(0x2013, 0x2014)}]`);
|
|
5
|
-
const mermaidUrl = "https://cdn.jsdelivr.net/npm/mermaid@12.1.0/dist/mermaid.min.js";
|
|
6
|
-
const mermaidIntegrity = "sha384-EbBpjO7rlR6eqZEcG7GaPpyk9H9WrMyPWX4d3KvPYltgt8Z8l0z6R56B1qP40pR4";
|
|
7
|
-
const planStatuses = ["draft", "approved", "in progress", "done"];
|
|
8
|
-
const requiredText = ["title", "summary", "planPath", "updated", "problem.statement", "problem.impact", "approach"];
|
|
9
|
-
const listRules = {
|
|
10
|
-
evidence: { minimum: 1, text: ["fact", "source"], choices: { kind: ["measured", "read", "inferred", "reported"] } },
|
|
11
|
-
causes: { minimum: 1, text: ["id", "cause", "origin"] },
|
|
12
|
-
ruledOut: { minimum: 0, text: ["cause", "reason"] },
|
|
13
|
-
changes: { minimum: 1, text: ["id", "change", "worksBecause"], lists: ["files", "addresses"] },
|
|
14
|
-
alternatives: { minimum: 1, text: ["option", "tradeoff"], choices: { verdict: ["rejected", "deferred"] } },
|
|
15
|
-
risks: { minimum: 1, text: ["id", "risk", "mitigation"] },
|
|
16
|
-
decisions: { minimum: 0, text: ["question", "answer", "reason"], choices: { source: ["user", "repository", "agent"] } },
|
|
17
|
-
open: { minimum: 0, text: ["question", "blocks"] },
|
|
18
|
-
steps: { minimum: 1, text: ["text"], choices: { status: ["todo", "doing", "done", "blocked", "skipped"] } },
|
|
19
|
-
verification: { minimum: 1, text: ["check", "expected"], lists: ["proves"] },
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function readPlan(html) {
|
|
23
|
-
const blocks = [
|
|
24
|
-
...html.matchAll(/<script type="application\/json" id="plan">([\s\S]*?)<\/script>/g),
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
if (blocks.length !== 1) {
|
|
28
|
-
return {
|
|
29
|
-
error: `found ${blocks.length} plan blocks, keep exactly one JSON block with the id plan`,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
return { plan: JSON.parse(blocks[0][1]) };
|
|
35
|
-
} catch (error) {
|
|
36
|
-
return { error: `the plan block is not valid JSON: ${error.message}` };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function textValues(value, at) {
|
|
41
|
-
if (typeof value === "string") {
|
|
42
|
-
return [[at, value]];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
return value.flatMap((entry, index) => textValues(entry, `${at}[${index}]`));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const entries = value !== null && typeof value === "object" ? Object.entries(value) : [];
|
|
50
|
-
|
|
51
|
-
return entries.flatMap(([key, entry]) => textValues(entry, at ? `${at}.${key}` : key));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const filled = (value) => typeof value === "string" && value.trim().length > 0;
|
|
55
|
-
const filledList = (value) => Array.isArray(value) && value.length > 0 && value.every(filled);
|
|
56
|
-
const entriesOf = (plan, name) => (Array.isArray(plan[name]) ? plan[name] : []);
|
|
57
|
-
|
|
58
|
-
function entryErrors({ name, rule, plan }) {
|
|
59
|
-
if (!Array.isArray(plan[name])) {
|
|
60
|
-
return [`${name} must be a list`];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (plan[name].length < rule.minimum) {
|
|
64
|
-
return [`${name} must list at least ${rule.minimum}`];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return plan[name].flatMap((entry, index) => [
|
|
68
|
-
...rule.text.filter((key) => !filled(entry?.[key])).map((key) => `${name}[${index}].${key} must be filled in`),
|
|
69
|
-
...(rule.lists ?? []).filter((key) => !filledList(entry?.[key])).map((key) => `${name}[${index}].${key} must list at least one value`),
|
|
70
|
-
...Object.entries(rule.choices ?? {})
|
|
71
|
-
.filter(([key, choices]) => !choices.includes(entry?.[key]))
|
|
72
|
-
.map(([key, choices]) => `${name}[${index}].${key} must be one of ${choices.join(", ")}`),
|
|
73
|
-
]);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function referenceErrors(plan) {
|
|
77
|
-
const causeIds = entriesOf(plan, "causes").map((cause) => cause?.id);
|
|
78
|
-
const knownIds = [...causeIds, ...entriesOf(plan, "risks").map((risk) => risk?.id)];
|
|
79
|
-
const errors = [];
|
|
80
|
-
|
|
81
|
-
for (const name of ["causes", "changes", "risks"]) {
|
|
82
|
-
const ids = entriesOf(plan, name).map((entry) => entry?.id);
|
|
83
|
-
const repeated = ids.filter((id, index) => filled(id) && ids.indexOf(id) !== index);
|
|
84
|
-
errors.push(...[...new Set(repeated)].map((id) => `${name} use the id ${id} more than once`));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (const [name, key] of [["changes", "addresses"], ["verification", "proves"]]) {
|
|
88
|
-
for (const [index, entry] of entriesOf(plan, name).entries()) {
|
|
89
|
-
const unknown = (Array.isArray(entry?.[key]) ? entry[key] : []).filter((id) => !knownIds.includes(id));
|
|
90
|
-
|
|
91
|
-
errors.push(...unknown.map((id) => `${name}[${index}].${key} names ${id}, which is not a cause or risk id`));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
for (const id of causeIds.filter(filled)) {
|
|
96
|
-
if (!entriesOf(plan, "changes").some((change) => change?.addresses?.includes?.(id))) {
|
|
97
|
-
errors.push(`cause ${id} has no change that addresses it`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!entriesOf(plan, "verification").some((check) => check?.proves?.includes?.(id))) {
|
|
101
|
-
errors.push(`cause ${id} has no check that proves the fix`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return errors;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function validate(html) {
|
|
109
|
-
const { plan, error } = readPlan(html);
|
|
110
|
-
|
|
111
|
-
if (error) {
|
|
112
|
-
return [error];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const errors = requiredText
|
|
116
|
-
.filter((at) => !filled(at.split(".").reduce((value, key) => value?.[key], plan)))
|
|
117
|
-
.map((at) => `${at} must be filled in`);
|
|
118
|
-
|
|
119
|
-
if (!planStatuses.includes(plan.status)) {
|
|
120
|
-
errors.push(`status must be one of ${planStatuses.join(", ")}`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (const [name, rule] of Object.entries(listRules)) {
|
|
124
|
-
errors.push(...entryErrors({ name, rule, plan }));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
for (const [index, step] of entriesOf(plan, "steps").entries()) {
|
|
128
|
-
if ((step?.status === "skipped" || step?.status === "blocked") && !filled(step.note)) {
|
|
129
|
-
errors.push(`steps[${index}] is ${step.status}, so its note must give the reason`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
errors.push(...referenceErrors(plan));
|
|
134
|
-
|
|
135
|
-
if (!Array.isArray(plan.followUps) || !plan.followUps.every(filled)) {
|
|
136
|
-
errors.push("followUps must be a list of one-line follow-ups, or empty");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (typeof plan.diagram !== "string") {
|
|
140
|
-
errors.push("diagram must be Mermaid source, or empty when there is no diagram");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
for (const [at, text] of textValues(plan, "")) {
|
|
144
|
-
if (text.startsWith("TEMPLATE:")) {
|
|
145
|
-
errors.push(`${at} still has template text, replace it`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (dashes.test(text)) {
|
|
149
|
-
errors.push(`${at} has an em or en dash, use a comma, a period, or parentheses`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
for (const [url] of html.matchAll(/https?:\/\/[^\s"'<>)]+/g)) {
|
|
154
|
-
if (url !== mermaidUrl) {
|
|
155
|
-
errors.push(`${url} loads from the network, keep the page self-contained`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (html.includes(mermaidUrl) && !html.includes(mermaidIntegrity)) {
|
|
160
|
-
errors.push("the Mermaid script must keep its pinned integrity hash");
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return errors;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async function main(files) {
|
|
167
|
-
if (files.length === 0) {
|
|
168
|
-
console.error("Usage: validate-page.mjs <page.html>...");
|
|
169
|
-
|
|
170
|
-
return 2;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let total = 0;
|
|
174
|
-
|
|
175
|
-
for (const file of files) {
|
|
176
|
-
let html;
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
html = await readFile(file, "utf8");
|
|
180
|
-
} catch (error) {
|
|
181
|
-
console.error(`${file}: cannot read the file (${error.code ?? error.message})`);
|
|
182
|
-
|
|
183
|
-
return 2;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
for (const message of validate(html)) {
|
|
187
|
-
console.log(`${file}: error ${message}`);
|
|
188
|
-
total += 1;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
193
|
-
|
|
194
|
-
console.log(`validate-page: ${plural(total, "error")} in ${plural(files.length, "file")}`);
|
|
195
|
-
|
|
196
|
-
return total > 0 ? 1 : 0;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
process.exitCode = await main(process.argv.slice(2));
|