@shadowclone/skills 0.0.45 → 0.0.46
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
CHANGED
|
@@ -95,6 +95,8 @@ th { color: var(--muted); font-size: 12px; }
|
|
|
95
95
|
.note, .finding { margin: 12px 16px; padding: 14px; border-left: 3px solid var(--accent); border-radius: 6px; background: #211b31; font-size: 13px; }
|
|
96
96
|
.finding { background: #171d29; border-color: #879fc4; }
|
|
97
97
|
.note-meta { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 11px; }
|
|
98
|
+
.note-meta > span { min-width: 0; overflow-wrap: anywhere; }
|
|
99
|
+
.note-meta > strong, .note-meta > span:last-child { flex: none; }
|
|
98
100
|
.note blockquote, .finding blockquote { margin: 8px 0; padding-left: 10px; color: var(--muted); border-left: 1px solid var(--border); white-space: pre-wrap; }
|
|
99
101
|
.note-actions { display: flex; gap: 8px; margin-top: 8px; }
|
|
100
102
|
.note-actions button { padding: 2px 8px; font-size: 11px; }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: plan-with-review-page
|
|
3
|
-
description: 'Use before a change that touches many files, needs many steps, or has open design choices. Also use it when the user says "plan this first", "make a plan", "think this through", or "do not code yet". Explores the code read-only, asks the open decisions with the recommended option first, and writes one plan. Builds a self-contained HTML review page from a template, and checks the page with a validator. Not for checking finished work (use `verify-and-review`).'
|
|
3
|
+
description: 'Use before a change that touches many files, needs many steps, or has open design choices. Also use it when the user says "plan this first", "make a plan", "think this through", or "do not code yet". Explores the code read-only, finds the cause, asks the open decisions with the recommended option first, and writes one plan. The plan explains the problem, the evidence, the cause, the fix and why it works, the alternatives, the risks, and the decisions. Builds a self-contained HTML review page from a template, and checks the page with a validator. Not for checking finished work (use `verify-and-review`).'
|
|
4
4
|
metadata:
|
|
5
5
|
shadowclone-category: workflow
|
|
6
6
|
shadowclone-section: workflow
|
|
@@ -12,23 +12,27 @@ metadata:
|
|
|
12
12
|
|
|
13
13
|
A change touches many files, needs many steps, or has a design choice that belongs to the user. An approved plan stops work in the wrong direction. A small and clear change does not need this skill.
|
|
14
14
|
|
|
15
|
+
The plan is the reference for the person who approves the work. That person may not have read the conversation, so the plan alone must let them judge the change.
|
|
16
|
+
|
|
15
17
|
## Gates
|
|
16
18
|
|
|
17
19
|
1. Are you read-only until the user approves? Before approval, write only the plan file and the review page.
|
|
18
20
|
2. Did you read the code, the documents, and the history before you asked? Never ask what the code can answer.
|
|
19
|
-
3. Did you ask in rounds until no decision was open? Each round has at most 4 questions, each with 2 to 4 options and the recommended option first.
|
|
20
|
-
4.
|
|
21
|
-
5.
|
|
22
|
-
6.
|
|
21
|
+
3. Did you ask in rounds until no decision was open? Each risky choice, such as a skip, a block, a fallback, or a default, belongs in a round. Each round has at most 4 questions, each with 2 to 4 options and the recommended option first.
|
|
22
|
+
4. Can a reader who missed the conversation judge the change from the plan alone? The plan gives the problem, the evidence, the cause, the fix, why it works, and the alternatives.
|
|
23
|
+
5. Does each cause have a change that removes it and a check that proves the fix?
|
|
24
|
+
6. Is there one plan file for this conversation, and does its page pass `scripts/validate-page.mjs` with 0 errors?
|
|
23
25
|
|
|
24
26
|
## Process
|
|
25
27
|
|
|
26
28
|
### Explore
|
|
27
29
|
|
|
28
30
|
1. Read the code that the request touches, and the instructions of the repository for that code.
|
|
29
|
-
2.
|
|
30
|
-
3. For a
|
|
31
|
-
4.
|
|
31
|
+
2. Reproduce or observe the problem. Record each fact with its source: a `path:line`, a command and its output, or a URL. Label each fact as measured, read, inferred, or reported.
|
|
32
|
+
3. Find each cause: the first place where the behavior goes wrong, with its `path:line`. For a new feature, a cause is a limit of the current design that blocks the feature.
|
|
33
|
+
4. Record each cause that you tested and rejected, with the observation that ruled it out.
|
|
34
|
+
5. Find the functions and patterns that the change can use again. For a broad search, use a read-only subagent if the host has one.
|
|
35
|
+
6. Stop when you can name the causes, the change, its tests, and what users would see break. Write each follow-up as one line in the plan. Do not research a follow-up first.
|
|
32
36
|
|
|
33
37
|
### Ask
|
|
34
38
|
|
|
@@ -40,25 +44,36 @@ A change touches many files, needs many steps, or has a design choice that belon
|
|
|
40
44
|
### Write
|
|
41
45
|
|
|
42
46
|
1. Put the plan at `/tmp/agent-artifacts/<repo>/<date>-<slug>/plan.md`. If the sandbox blocks `/tmp`, use the temporary folder of the agent. If the host gives a plan file path, use it for the plan and keep the review page in `/tmp/agent-artifacts/`.
|
|
43
|
-
2. Write
|
|
47
|
+
2. Write for a reader who was not in the conversation. Define each project term the first time you use it. Use these sections in this order, in the plan file and on the page:
|
|
48
|
+
- **Summary and status:** what changes, why, and the result, in two or three sentences. The status is draft, approved, in progress, or done.
|
|
49
|
+
- **The problem:** what is wrong or missing as the user sees it. Give its impact: who it affects, how often, and the cost.
|
|
50
|
+
- **What happened:** the facts, each with its source and its label.
|
|
51
|
+
- **Why it happened:** each cause with an id such as `C1` and its origin. Add each cause that you ruled out, with the reason.
|
|
52
|
+
- **The fix:** the approach, then each change with an id such as `F1`, its files, and the causes or risks that it addresses. Say why each change works. For a change that repeats across many files, describe the pattern once and list a few example paths.
|
|
53
|
+
- **Why the fix works:** the page builds this table from the causes, the changes, and the checks.
|
|
54
|
+
- **Alternatives considered:** each other option, including no change. Say what it gives, what it costs, and why the plan does not use it.
|
|
55
|
+
- **Risks:** each risk with an id such as `R1`. Say what can go wrong after the change, and how the plan prevents it or finds it early. A change can exist only to limit a risk.
|
|
56
|
+
- **Decisions:** each question, its answer, its reason, and its source. The source is user, repository, or agent. An agent decision is a default that the user can change.
|
|
57
|
+
- **Open questions:** each question, and the step that waits for its answer.
|
|
58
|
+
- **Steps, verification, and follow-ups:** the steps in order, and each check with the result that proves the fix and the causes that it proves. Then write one line for each follow-up.
|
|
44
59
|
3. Copy `assets/review-page.html` to the same folder as `index.html`. Edit only the JSON block with the id `plan`, and replace each value that starts with `TEMPLATE:`.
|
|
45
60
|
4. Add Mermaid source in `diagram` when the change has more than two parts. The page shows the source as text, and draws it when the pinned Mermaid file loads.
|
|
46
61
|
5. Run `node scripts/validate-page.mjs <page>`. If Node is not available, run the script with `bun`. Fix each error.
|
|
47
|
-
6. Give the user both paths, the
|
|
62
|
+
6. Give the user both paths, the summary, the main risk, and the open questions. If the host has a plan approval step, use it. If not, ask "Do you approve this plan?" Wait for approval in this conversation.
|
|
48
63
|
|
|
49
64
|
### Execute
|
|
50
65
|
|
|
51
66
|
1. Do the steps in order. After each step, update its status in the page and in the plan.
|
|
52
|
-
2. If a fact changes a decision, stop. Update the plan, and ask again.
|
|
67
|
+
2. If a fact changes a decision or a cause, stop. Update the plan, and ask again.
|
|
53
68
|
3. Keep a step that you skip in the list, with the status `skipped` and the reason in its note.
|
|
54
69
|
|
|
55
70
|
## Example
|
|
56
71
|
|
|
57
|
-
**Situation:** The user asks for a sync command
|
|
58
|
-
**Easy route:**
|
|
59
|
-
**Hidden cost:** The plan hides a choice that deletes the work of the user. The
|
|
60
|
-
**Best route:**
|
|
61
|
-
**Evidence:** The
|
|
72
|
+
**Situation:** The user asks for a fix to a sync command. Sync replaced installed skills, and some installed copies contained edits that the user made.
|
|
73
|
+
**Easy route:** Write four steps: read the sync code, add a check, add a test, and open a pull request.
|
|
74
|
+
**Hidden cost:** The reviewer cannot tell why sync replaced the edits, or whether the check removes that cause. The plan also hides a choice that deletes the work of the user. The reviewer approves a guess.
|
|
75
|
+
**Best route:** Write the cause `C1` with its `path:line`: sync compares the file name and not the fingerprint. Link the change `F1` to `C1`, and name the test that proves it. List the rejected alternative "always save a backup" with its trade-off. Ask whether to keep and list edited copies (recommended) or to replace them and save a backup.
|
|
76
|
+
**Evidence:** The "Why the fix works" table shows `C1`, the change `F1`, and the test that proves the fix. The decision table shows "Edited copies: keep and list" with the source "user". The validator printed "validate-page: 0 errors in 1 file".
|
|
62
77
|
|
|
63
78
|
## Guardrails
|
|
64
79
|
|
|
@@ -66,11 +81,13 @@ A change touches many files, needs many steps, or has a design choice that belon
|
|
|
66
81
|
- Never commit the plan or the review page to a repository.
|
|
67
82
|
- Keep the review page self-contained. Do not add scripts, styles, or fonts from the network.
|
|
68
83
|
- Do not open a decision again unless a new fact changes it.
|
|
69
|
-
-
|
|
84
|
+
- Make the plan complete first. Keep it easy to scan with tables, short sentences, and one idea in each sentence.
|
|
85
|
+
- Keep the label of each fact true. Do not present an inference as a measurement.
|
|
70
86
|
|
|
71
87
|
## Completion
|
|
72
88
|
|
|
73
89
|
- The plan path and the review page path.
|
|
74
90
|
- The validator command and its result line.
|
|
75
91
|
- Each question round, with the recommended option first in each question.
|
|
92
|
+
- Each cause, the change that addresses it, and the check that proves the fix.
|
|
76
93
|
- Each step with its status, and each skipped step with its reason.
|
|
@@ -6,152 +6,189 @@
|
|
|
6
6
|
<title>Plan review</title>
|
|
7
7
|
<style>
|
|
8
8
|
:root {
|
|
9
|
-
--page: #fbfaf7; --text: #1d1d1b; --muted: #66645f; --card: #ffffff; --line: #e2dfd8;
|
|
9
|
+
--page: #fbfaf7; --text: #1d1d1b; --muted: #66645f; --card: #ffffff; --line: #e2dfd8; --soft: #f3f1ec;
|
|
10
10
|
--done: #2f7d4f; --doing: #a8701c; --todo: #77756f; --blocked: #b5443b; --skipped: #6d5fa8;
|
|
11
11
|
}
|
|
12
12
|
@media (prefers-color-scheme: dark) {
|
|
13
13
|
:root {
|
|
14
|
-
--page: #161615; --text: #ecebe7; --muted: #a09e98; --card: #1f1f1d; --line: #34332f;
|
|
14
|
+
--page: #161615; --text: #ecebe7; --muted: #a09e98; --card: #1f1f1d; --line: #34332f; --soft: #262624;
|
|
15
15
|
--done: #5fbf83; --doing: #e0a84a; --todo: #8f8c85; --blocked: #e57b72; --skipped: #a99be8;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
* { box-sizing: border-box; }
|
|
19
|
-
body { margin: 0; background: var(--page); color: var(--text); font: 15px/1.
|
|
20
|
-
main { max-width:
|
|
21
|
-
h1 { font-size:
|
|
22
|
-
|
|
23
|
-
|
|
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; }
|
|
24
25
|
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
|
|
25
|
-
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(
|
|
26
|
-
.counts b { display: block; font-size: 22px; }
|
|
27
|
-
.counts span { color: var(--muted); font-size: 13px; }
|
|
28
|
-
ol.steps { list-style: none; margin: 0; padding: 0; }
|
|
29
|
-
ol.steps li { display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
|
|
30
|
-
ol.steps li:last-child { border-bottom: 0; }
|
|
31
|
-
.status { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
|
|
32
|
-
.done { color: var(--done); } .doing { color: var(--doing); } .todo { color: var(--todo); }
|
|
33
|
-
.blocked { color: var(--blocked); } .skipped { color: var(--skipped); }
|
|
34
|
-
.note { display: block; color: var(--muted); font-size: 13px; }
|
|
35
|
-
.scroll { overflow-x: auto; }
|
|
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; }
|
|
36
28
|
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
37
29
|
th, td { text-align: left; vertical-align: top; padding: 7px 8px; border-bottom: 1px solid var(--line); }
|
|
38
|
-
th { color: var(--muted); font-weight: 600; }
|
|
39
|
-
code, pre { font:
|
|
40
|
-
pre { white-space: pre-wrap; margin: 0; }
|
|
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); }
|
|
41
36
|
#diagram img { display: block; max-width: 100%; height: auto; margin-bottom: 10px; }
|
|
42
37
|
</style>
|
|
43
38
|
</head>
|
|
44
39
|
<body>
|
|
45
40
|
<main>
|
|
46
41
|
<h1 id="title"></h1>
|
|
47
|
-
<p id="
|
|
42
|
+
<p><span id="status"></span></p>
|
|
43
|
+
<p id="summary"></p>
|
|
48
44
|
<p class="meta">Plan file: <code id="plan-path"></code>. Updated: <span id="updated"></span>.</p>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
<div class="card"><b id="count-open">0</b><span>open questions</span></div>
|
|
53
|
-
</div>
|
|
54
|
-
<section id="diagram-section" hidden>
|
|
55
|
-
<h2>Diagram</h2>
|
|
56
|
-
<div class="card scroll">
|
|
57
|
-
<div id="diagram"></div>
|
|
58
|
-
<p class="note" id="diagram-note">The diagram shows as source text until the pinned Mermaid file loads.</p>
|
|
59
|
-
<pre id="diagram-source"></pre>
|
|
60
|
-
</div>
|
|
61
|
-
</section>
|
|
62
|
-
<h2>Steps</h2>
|
|
63
|
-
<div class="card"><ol class="steps" id="steps"></ol></div>
|
|
64
|
-
<h2>Decisions</h2>
|
|
65
|
-
<div class="card scroll">
|
|
66
|
-
<table>
|
|
67
|
-
<thead><tr><th>Question</th><th>Answer</th><th>Source</th></tr></thead>
|
|
68
|
-
<tbody id="decisions"></tbody>
|
|
69
|
-
</table>
|
|
70
|
-
</div>
|
|
71
|
-
<h2>Open questions</h2>
|
|
72
|
-
<div class="card"><ul id="open"></ul></div>
|
|
45
|
+
<nav id="contents"></nav>
|
|
46
|
+
<div class="counts" id="counts"></div>
|
|
47
|
+
<div id="sections"></div>
|
|
73
48
|
</main>
|
|
74
49
|
<script type="application/json" id="plan">
|
|
75
50
|
{
|
|
76
51
|
"title": "TEMPLATE: A short name for the change",
|
|
77
|
-
"
|
|
52
|
+
"status": "draft",
|
|
53
|
+
"summary": "TEMPLATE: Two or three sentences: what changes, why, and the result for the user.",
|
|
78
54
|
"planPath": "TEMPLATE: The absolute path of the plan file",
|
|
79
55
|
"updated": "TEMPLATE: The date and time of this update",
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
{ "
|
|
83
|
-
|
|
84
|
-
|
|
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." }
|
|
85
75
|
],
|
|
86
76
|
"decisions": [
|
|
87
|
-
{ "question": "TEMPLATE: A decision
|
|
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"] }
|
|
88
83
|
],
|
|
89
|
-
"
|
|
90
|
-
"diagram": "flowchart LR\n
|
|
84
|
+
"followUps": [],
|
|
85
|
+
"diagram": "flowchart LR\n Problem --> Cause --> Fix --> Check"
|
|
91
86
|
}
|
|
92
87
|
</script>
|
|
93
88
|
<script>
|
|
94
89
|
const plan = JSON.parse(document.getElementById("plan").textContent);
|
|
95
90
|
const element = (name, text, className) => {
|
|
96
91
|
const node = document.createElement(name);
|
|
97
|
-
node.textContent
|
|
92
|
+
if (text !== undefined) text.split("`").forEach((part, index) => node.append(index % 2 ? Object.assign(document.createElement("code"), { textContent: part }) : part));
|
|
98
93
|
if (className) node.className = className;
|
|
99
94
|
return node;
|
|
100
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
|
+
];
|
|
101
148
|
|
|
102
149
|
document.title = plan.title;
|
|
103
|
-
document.getElementById("
|
|
104
|
-
|
|
105
|
-
document.getElementById("
|
|
106
|
-
document.getElementById("updated").textContent = plan.updated;
|
|
107
|
-
document.getElementById("count-done").textContent = plan.steps.filter((step) => step.status === "done").length;
|
|
108
|
-
document.getElementById("count-left").textContent = plan.steps.filter((step) => step.status !== "done" && step.status !== "skipped").length;
|
|
109
|
-
document.getElementById("count-open").textContent = plan.open.length;
|
|
110
|
-
|
|
111
|
-
for (const step of plan.steps) {
|
|
112
|
-
const item = document.createElement("li");
|
|
113
|
-
const body = element("div", step.text);
|
|
114
|
-
if (step.note) body.append(element("span", step.note, "note"));
|
|
115
|
-
item.append(element("span", step.status, `status ${step.status}`), body);
|
|
116
|
-
document.getElementById("steps").append(item);
|
|
117
|
-
}
|
|
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)));
|
|
118
153
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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);
|
|
123
160
|
}
|
|
124
161
|
|
|
125
|
-
for (const
|
|
126
|
-
|
|
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}` }));
|
|
127
169
|
}
|
|
128
170
|
|
|
129
171
|
if (plan.diagram) {
|
|
130
|
-
|
|
131
|
-
|
|
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));
|
|
132
176
|
|
|
133
|
-
const script = document.createElement("script")
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
});
|
|
137
182
|
script.onload = async () => {
|
|
138
183
|
const dark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
139
|
-
window.mermaid.initialize({
|
|
140
|
-
startOnLoad: false,
|
|
141
|
-
securityLevel: "strict",
|
|
142
|
-
htmlLabels: false,
|
|
143
|
-
flowchart: { htmlLabels: false },
|
|
144
|
-
theme: dark ? "dark" : "default",
|
|
145
|
-
});
|
|
184
|
+
window.mermaid.initialize({ startOnLoad: false, securityLevel: "strict", htmlLabels: false, flowchart: { htmlLabels: false }, theme: dark ? "dark" : "default" });
|
|
146
185
|
const { svg } = await window.mermaid.render("plan-diagram", plan.diagram);
|
|
147
|
-
const image = document.createElement("img");
|
|
148
|
-
image
|
|
149
|
-
|
|
150
|
-
document.getElementById("diagram").replaceChildren(image);
|
|
151
|
-
document.getElementById("diagram-note").textContent = "Diagram source:";
|
|
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:";
|
|
152
189
|
};
|
|
153
190
|
script.onerror = () => {
|
|
154
|
-
|
|
191
|
+
note.textContent = "Mermaid did not load, so the diagram shows as source text.";
|
|
155
192
|
};
|
|
156
193
|
document.head.append(script);
|
|
157
194
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
|
|
4
|
-
const statuses = ["todo", "doing", "done", "blocked", "skipped"];
|
|
5
4
|
const dashes = new RegExp(`[${String.fromCharCode(0x2013, 0x2014)}]`);
|
|
6
5
|
const mermaidUrl = "https://cdn.jsdelivr.net/npm/mermaid@12.1.0/dist/mermaid.min.js";
|
|
7
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
|
+
};
|
|
8
21
|
|
|
9
22
|
function readPlan(html) {
|
|
10
23
|
const blocks = [
|
|
@@ -33,66 +46,94 @@ function textValues(value, at) {
|
|
|
33
46
|
return value.flatMap((entry, index) => textValues(entry, `${at}[${index}]`));
|
|
34
47
|
}
|
|
35
48
|
|
|
36
|
-
|
|
37
|
-
return Object.entries(value).flatMap(([key, entry]) =>
|
|
38
|
-
textValues(entry, at ? `${at}.${key}` : key),
|
|
39
|
-
);
|
|
40
|
-
}
|
|
49
|
+
const entries = value !== null && typeof value === "object" ? Object.entries(value) : [];
|
|
41
50
|
|
|
42
|
-
return [];
|
|
51
|
+
return entries.flatMap(([key, entry]) => textValues(entry, at ? `${at}.${key}` : key));
|
|
43
52
|
}
|
|
44
53
|
|
|
45
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] : []);
|
|
46
57
|
|
|
47
|
-
function
|
|
48
|
-
|
|
58
|
+
function entryErrors({ name, rule, plan }) {
|
|
59
|
+
if (!Array.isArray(plan[name])) {
|
|
60
|
+
return [`${name} must be a list`];
|
|
61
|
+
}
|
|
49
62
|
|
|
50
|
-
if (
|
|
51
|
-
return [
|
|
63
|
+
if (plan[name].length < rule.minimum) {
|
|
64
|
+
return [`${name} must list at least ${rule.minimum}`];
|
|
52
65
|
}
|
|
53
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)];
|
|
54
79
|
const errors = [];
|
|
55
|
-
const steps = Array.isArray(plan.steps) ? plan.steps : [];
|
|
56
|
-
const decisions = Array.isArray(plan.decisions) ? plan.decisions : [];
|
|
57
80
|
|
|
58
|
-
for (const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
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`));
|
|
62
85
|
}
|
|
63
86
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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));
|
|
67
90
|
|
|
68
|
-
|
|
69
|
-
if (!statuses.includes(step?.status)) {
|
|
70
|
-
errors.push(`steps[${index}].status must be one of ${statuses.join(", ")}`);
|
|
91
|
+
errors.push(...unknown.map((id) => `${name}[${index}].${key} names ${id}, which is not a cause or risk id`));
|
|
71
92
|
}
|
|
93
|
+
}
|
|
72
94
|
|
|
73
|
-
|
|
74
|
-
|
|
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`);
|
|
75
98
|
}
|
|
76
99
|
|
|
77
|
-
if ((
|
|
78
|
-
errors.push(`
|
|
100
|
+
if (!entriesOf(plan, "verification").some((check) => check?.proves?.includes?.(id))) {
|
|
101
|
+
errors.push(`cause ${id} has no check that proves the fix`);
|
|
79
102
|
}
|
|
80
103
|
}
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
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 }));
|
|
84
125
|
}
|
|
85
126
|
|
|
86
|
-
for (const [index,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
errors.push(`decisions[${index}].${key} must be filled in`);
|
|
90
|
-
}
|
|
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`);
|
|
91
130
|
}
|
|
92
131
|
}
|
|
93
132
|
|
|
94
|
-
|
|
95
|
-
|
|
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");
|
|
96
137
|
}
|
|
97
138
|
|
|
98
139
|
if (typeof plan.diagram !== "string") {
|