@yutaura/live-spec 0.1.0 → 0.3.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.
Files changed (50) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +15 -2
  3. package/dist/check.d.ts +5 -0
  4. package/dist/check.js +40 -0
  5. package/dist/cli.js +116 -10
  6. package/dist/diff.d.ts +92 -2
  7. package/dist/diff.js +101 -64
  8. package/dist/ensure-scope.d.ts +9 -0
  9. package/dist/ensure-scope.js +81 -0
  10. package/dist/ensure.d.ts +4 -0
  11. package/dist/ensure.js +27 -2
  12. package/dist/evidence.d.ts +3 -0
  13. package/dist/evidence.js +46 -0
  14. package/dist/explore.d.ts +20 -1
  15. package/dist/explore.js +38 -12
  16. package/dist/generate.d.ts +7 -0
  17. package/dist/generate.js +18 -5
  18. package/dist/load.d.ts +11 -1
  19. package/dist/load.js +9 -0
  20. package/dist/model.d.ts +127 -0
  21. package/dist/model.js +40 -0
  22. package/dist/mutation.d.ts +3 -0
  23. package/dist/mutation.js +51 -0
  24. package/dist/omission.d.ts +6 -0
  25. package/dist/omission.js +235 -0
  26. package/dist/project-diff.d.ts +24 -0
  27. package/dist/project-diff.js +76 -0
  28. package/dist/render/diff-html.d.ts +2 -0
  29. package/dist/render/diff-html.js +148 -0
  30. package/dist/render/diff-markdown.d.ts +11 -0
  31. package/dist/render/diff-markdown.js +70 -0
  32. package/dist/render/ensures.d.ts +2 -0
  33. package/dist/render/ensures.js +21 -0
  34. package/dist/render/html.d.ts +1 -0
  35. package/dist/render/html.js +42 -10
  36. package/dist/render/layout.d.ts +2 -0
  37. package/dist/render/layout.js +1 -1
  38. package/dist/render/markdown.js +30 -3
  39. package/dist/render/review.d.ts +17 -0
  40. package/dist/render/review.js +17 -0
  41. package/dist/render/union.d.ts +23 -0
  42. package/dist/render/union.js +43 -0
  43. package/dist/spec-loader.d.ts +2 -0
  44. package/dist/spec-loader.js +24 -0
  45. package/dist/static.d.ts +7 -0
  46. package/dist/static.js +74 -0
  47. package/package.json +7 -1
  48. package/skills/live-spec-authoring/SKILL.md +59 -7
  49. package/skills/live-spec-from-code/SKILL.md +2 -0
  50. package/skills/live-spec-review/SKILL.md +16 -10
@@ -0,0 +1,148 @@
1
+ import { describeFinding, groupAvailability, whoOf } from "../diff.js";
2
+ import { STATUS_LABEL, summaryOf } from "./diff-markdown.js";
3
+ import { esc } from "./escape.js";
4
+ import { CSS } from "./html.js";
5
+ import { layout } from "./layout.js";
6
+ import { edgeLabel, unionGraph } from "./union.js";
7
+ import { surfaceToHtml } from "./wireframe.js";
8
+ export const renderDiffHtml = async (p) => {
9
+ const changed = p.objects.filter((o) => o.status !== "unchanged");
10
+ const unchanged = p.objects.filter((o) => o.status === "unchanged");
11
+ const sections = await Promise.all(changed.map((o, i) => objectSection(o, i)));
12
+ return `<!doctype html>
13
+ <html lang="ja">
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <meta name="viewport" content="width=device-width, initial-scale=1">
17
+ <title>仕様の差分 — ${esc(p.base)} → ${esc(p.head)}</title>
18
+ <style>${CSS}${DIFF_CSS}</style>
19
+ </head>
20
+ <body>
21
+ <header class="top">
22
+ <div>
23
+ <p class="eyebrow">仕様の差分</p>
24
+ <h1><code>${esc(p.base)}</code> → <code>${esc(p.head)}</code></h1>
25
+ <p class="lead">${changed.length === 0 ? "仕様の変化はありません。" : `${changed.length} 個のドメインオブジェクトが変わりました。`}${unchanged.length === 0 ? "" : `変化なし: ${esc(unchanged.map((o) => o.name).join(", "))}`}</p>
26
+ </div>
27
+ </header>
28
+ <main>
29
+ ${changed.length === 0
30
+ ? ""
31
+ : `<table class="decision summary"><thead><tr><th>ドメインオブジェクト</th><th>変化</th><th>操作</th><th>状態</th><th>遷移</th><th>できる/できない</th><th>検査結果</th></tr></thead><tbody>${changed
32
+ .map((o) => {
33
+ const s = summaryOf(o.diff);
34
+ return `<tr><td><a href="#obj-${esc(o.name)}">${esc(o.name)}</a></td><td><span class="badge ${o.status}">${STATUS_LABEL[o.status]}</span></td><td>${s.actions}</td><td>${s.states}</td><td>${s.transitions}</td><td>${s.availability}</td><td>${s.findings}</td></tr>`;
35
+ })
36
+ .join("")}</tbody></table>`}
37
+ ${sections.join("\n")}
38
+ </main>
39
+ </body>
40
+ </html>
41
+ `;
42
+ };
43
+ const objectSection = async (o, index) => {
44
+ const { nodes, edges } = unionGraph(o.before?.graph ?? null, o.after?.graph ?? null);
45
+ // 「どの状態からでも」にはまとめない。まとめると、一部の状態からだけ消えた遷移が見えなくなるため。
46
+ const l = await layout({
47
+ states: nodes.map((n) => ({ id: n.id, label: n.label, values: {}, initial: n.initial, terminal: false })),
48
+ transitions: edges.map((e) => ({ from: e.from, to: e.to, action: edgeLabel(e), actors: [] })),
49
+ availability: [],
50
+ findings: [],
51
+ surfaces: [],
52
+ decisions: [],
53
+ links: [],
54
+ questions: [],
55
+ scenarios: [],
56
+ }, { collapse: false });
57
+ const statusOfNode = new Map(nodes.map((n) => [n.id, n.status]));
58
+ const marker = `arrow-diff-${index}`;
59
+ const edgeSvg = l.edges
60
+ .map((e, i) => {
61
+ const d = e.points.map((pt, j) => `${j === 0 ? "M" : "L"}${pt.x},${pt.y}`).join(" ");
62
+ const lb = e.label;
63
+ return `<g class="edge diff-${edges[i].status}"><path d="${d}" marker-end="url(#${marker})"/><g class="edge-label"><rect x="${lb.x}" y="${lb.y}" width="${lb.width}" height="${lb.height}" rx="4"/><text x="${lb.x + lb.width / 2}" y="${lb.y + lb.height / 2}">${esc(e.action)}</text></g></g>`;
64
+ })
65
+ .join("");
66
+ const nodeSvg = l.nodes
67
+ .map((n) => `<g class="node diff-${statusOfNode.get(n.id)}"><rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" rx="10"/><text x="${n.x + n.width / 2}" y="${n.y + n.height / 2}">${esc(n.label)}</text></g>`)
68
+ .join("");
69
+ return `<section class="diff-object" id="obj-${esc(o.name)}">
70
+ <h2>${esc(o.name)} <span class="badge ${o.status}">${STATUS_LABEL[o.status]}</span></h2>
71
+ ${nodes.length === 0
72
+ ? ""
73
+ : `<div class="diagram"><svg viewBox="0 0 ${l.width} ${l.height}" width="${l.width}" height="${l.height}" role="img" aria-label="${esc(o.name)} の状態遷移図の差分"><defs><marker id="${marker}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z"/></marker></defs>${edgeSvg}${nodeSvg}</svg></div>
74
+ <p class="legend"><span class="sw added"></span>増えた <span class="sw removed"></span>消えた <span class="sw changed"></span>通れる人が変わった <span class="sw kept"></span>変わらない</p>`}
75
+ ${diffBody(o.diff)}
76
+ ${screens(o)}
77
+ </section>`;
78
+ };
79
+ const list = (title, items) => items.length === 0 ? "" : `<h3>${title}</h3><ul class="diff-list">${items.join("")}</ul>`;
80
+ const plus = (s) => `<li class="added">+ ${esc(s)}</li>`;
81
+ const minus = (s) => `<li class="removed">- ${esc(s)}</li>`;
82
+ const diffBody = (d) => {
83
+ const g = groupAvailability(d.availability);
84
+ return [
85
+ list("操作", [...d.actions.added.map(plus), ...d.actions.removed.map(minus)]),
86
+ list("状態", [...d.states.added.map(plus), ...d.states.removed.map(minus)]),
87
+ list("遷移", [...d.transitions.added.map(plus), ...d.transitions.removed.map(minus)]),
88
+ g.flipped.length === 0
89
+ ? ""
90
+ : `<h3>できる/できないの変化</h3><table class="decision"><thead><tr><th>状態</th><th>操作</th><th>登場人物</th><th>変更前</th><th>変更後</th></tr></thead><tbody>${g.flipped
91
+ .map((a) => `<tr><td>${esc(a.state)}</td><td>${esc(a.action)}</td><td>${esc(whoOf(a))}</td><td class="removed">${esc(a.before)}</td><td class="added">${esc(a.after)}</td></tr>`)
92
+ .join("")}</tbody></table>`,
93
+ g.reasonOnly.length === 0
94
+ ? ""
95
+ : `<details class="reason-only"><summary>できない理由の言い方だけが変わったもの(${g.reasonOnly.reduce((n, r) => n + r.count, 0)} 件)</summary><table class="decision"><thead><tr><th>操作</th><th>変更前</th><th>変更後</th><th>どの状態・誰</th></tr></thead><tbody>${g.reasonOnly
96
+ .map((r) => `<tr><td>${esc(r.action)}</td><td>${esc(r.before)}</td><td>${esc(r.after)}</td><td class="muted">${esc(r.cases.map((c) => `${c.state}・${whoOf(c)}`).join("、"))}</td></tr>`)
97
+ .join("")}</tbody></table></details>`,
98
+ list("シナリオ", [
99
+ ...d.scenarios.added.map(plus),
100
+ ...d.scenarios.removed.map(minus),
101
+ ...d.scenarios.changed.map((c) => `<li>${esc(c.name)}: ${c.before ? "通る" : "止まる"} → ${c.after ? "通る" : "止まる"}</li>`),
102
+ ]),
103
+ list("未決事項", [...d.questions.added.map(plus), ...d.questions.removed.map((q) => minus(`${q}(解決したか、取り下げた)`))]),
104
+ list("検査結果", [...d.findings.added.map((f) => plus(describeFinding(f))), ...d.findings.removed.map((f) => minus(describeFinding(f)))]),
105
+ ].join("");
106
+ };
107
+ // 画面が変わった「状態 × 見る人」ごとに、変更前と変更後を左右に並べる(文章の差分より、見比べるほうが早いため)。
108
+ const screens = (o) => {
109
+ if (o.diff.surfaces.length === 0)
110
+ return "";
111
+ const surfaceOf = (side, stateLabel, actor) => {
112
+ if (side === null)
113
+ return null;
114
+ const state = side.graph.states.find((s) => s.label === stateLabel);
115
+ const found = state === undefined ? undefined : side.graph.surfaces.find((x) => x.state === state.id && x.actor === actor);
116
+ return found === undefined ? null : surfaceToHtml(found.surface, []);
117
+ };
118
+ return `<h3>画面の変化</h3>${o.diff.surfaces
119
+ .map((s) => {
120
+ const b = surfaceOf(o.before, s.state, s.actor);
121
+ const a = surfaceOf(o.after, s.state, s.actor);
122
+ return `<h4>${esc(s.state)}(${esc(s.actor)} が見る画面)</h4><div class="before-after"><div><p class="eyebrow">変更前</p>${b ?? '<p class="muted">(画面なし)</p>'}</div><div><p class="eyebrow">変更後</p>${a ?? '<p class="muted">(画面なし)</p>'}</div></div>`;
123
+ })
124
+ .join("")}`;
125
+ };
126
+ const DIFF_CSS = `
127
+ .diff-object{margin:40px 0;padding-top:12px;border-top:1px solid var(--line)}
128
+ .diff-object h2{display:flex;align-items:center;gap:10px}
129
+ .diff-object h3{font-size:15px;margin:20px 0 6px}
130
+ .diff-object h4{font-size:14px;margin:14px 0 6px;color:var(--muted)}
131
+ .badge{font-size:12px;font-weight:600;padding:2px 10px;border-radius:999px;background:var(--chip)}
132
+ .badge.added{background:#1d7f48;color:#fff}.badge.removed{background:#b3261e;color:#fff}.badge.changed{background:var(--accent);color:#fff}
133
+ .node.diff-added rect{stroke:#1d7f48;stroke-width:2.2;fill:rgba(29,127,72,.15)}
134
+ .node.diff-removed rect{stroke:#b3261e;stroke-width:2;stroke-dasharray:5 3;fill:rgba(179,38,30,.10)}
135
+ .node.diff-removed text{text-decoration:line-through}
136
+ .edge.diff-added path{stroke:#1d7f48;stroke-width:2.2}.edge.diff-added .edge-label text{fill:#1d7f48;font-weight:600}
137
+ .edge.diff-changed path{stroke:#c58a00;stroke-width:2.2}.edge.diff-changed .edge-label text{fill:#c58a00;font-weight:600}
138
+ .sw.changed{border-color:#c58a00;background:rgba(197,138,0,.25)}
139
+ details.reason-only{margin:14px 0}details.reason-only summary{cursor:pointer;color:var(--muted);font-size:13.5px}
140
+ .edge.diff-removed path{stroke:#b3261e;stroke-width:1.8;stroke-dasharray:5 3}.edge.diff-removed .edge-label text{fill:#b3261e;text-decoration:line-through}
141
+ .legend{font-size:12.5px;color:var(--muted);display:flex;gap:6px;align-items:center}
142
+ .sw{display:inline-block;width:14px;height:10px;border-radius:3px;margin-left:10px;border:1.5px solid var(--fg)}
143
+ .sw.added{border-color:#1d7f48;background:rgba(29,127,72,.25)}.sw.removed{border-color:#b3261e;border-style:dashed}
144
+ .diff-list{list-style:none;padding:0;margin:0}.diff-list li{padding:3px 0}
145
+ .diff-list li.added,td.added{color:#1d7f48}.diff-list li.removed,td.removed{color:#b3261e}
146
+ .before-after{display:grid;grid-template-columns:1fr 1fr;gap:16px;max-width:900px}
147
+ table.summary a{color:var(--accent)}
148
+ `;
@@ -0,0 +1,11 @@
1
+ import { type ModelDiff } from "../diff.js";
2
+ import type { ObjectStatus, ProjectDiff } from "../project-diff.js";
3
+ export declare const STATUS_LABEL: Readonly<Record<ObjectStatus, string>>;
4
+ export declare const summaryOf: (d: ModelDiff) => {
5
+ actions: string;
6
+ states: string;
7
+ transitions: string;
8
+ availability: string;
9
+ findings: string;
10
+ };
11
+ export declare const renderDiffMarkdown: (p: ProjectDiff) => string;
@@ -0,0 +1,70 @@
1
+ import { groupAvailability, renderDiff } from "../diff.js";
2
+ import { edgeLabel, unionGraph } from "./union.js";
3
+ export const STATUS_LABEL = {
4
+ added: "追加",
5
+ removed: "削除",
6
+ changed: "変更",
7
+ unchanged: "変化なし",
8
+ };
9
+ const plusMinus = (d) => {
10
+ const parts = [d.added.length > 0 ? `+${d.added.length}` : "", d.removed.length > 0 ? `-${d.removed.length}` : ""].filter(Boolean);
11
+ return parts.length === 0 ? "" : parts.join(" ");
12
+ };
13
+ export const summaryOf = (d) => ({
14
+ actions: plusMinus(d.actions),
15
+ states: plusMinus(d.states),
16
+ transitions: plusMinus(d.transitions),
17
+ availability: (() => {
18
+ const g = groupAvailability(d.availability);
19
+ const reasons = g.reasonOnly.reduce((n, r) => n + r.count, 0);
20
+ return [g.flipped.length > 0 ? `${g.flipped.length} 件` : "", reasons > 0 ? `(理由の言い方 ${reasons} 件)` : ""].join("");
21
+ })(),
22
+ findings: plusMinus(d.findings),
23
+ });
24
+ // 図の線(遷移)は Mermaid の状態遷移図では色を変えられないので、ラベルに + / - を付けて示す。
25
+ const mermaidOf = (o) => {
26
+ const { nodes, edges } = unionGraph(o.before?.graph ?? null, o.after?.graph ?? null);
27
+ if (nodes.length === 0)
28
+ return [];
29
+ const mark = { added: " +", removed: " -", kept: "", changed: "" };
30
+ return [
31
+ "```mermaid",
32
+ "stateDiagram-v2",
33
+ " classDef added fill:#d9f7e5,stroke:#1d7f48,color:#0b3d22",
34
+ " classDef removed fill:#fde2e2,stroke:#b3261e,color:#5c1111,stroke-dasharray:4 3",
35
+ ...nodes.map((n) => ` state "${n.label}" as ${n.id}`),
36
+ ...nodes.filter((n) => n.initial).map((n) => ` [*] --> ${n.id}`),
37
+ ...edges.map((e) => ` ${e.from} --> ${e.to}: ${edgeLabel(e)}${mark[e.status]}`),
38
+ ...nodes.filter((n) => n.status !== "kept").map((n) => ` class ${n.id} ${n.status}`),
39
+ "```",
40
+ ];
41
+ };
42
+ export const renderDiffMarkdown = (p) => {
43
+ const changed = p.objects.filter((o) => o.status !== "unchanged");
44
+ const unchanged = p.objects.filter((o) => o.status === "unchanged");
45
+ return [
46
+ "# 仕様の差分",
47
+ "",
48
+ `\`${p.base}\` → \`${p.head}\``,
49
+ "",
50
+ ...(changed.length === 0
51
+ ? ["仕様の変化はありません。", ""]
52
+ : [
53
+ "| ドメインオブジェクト | 変化 | 操作 | 状態 | 遷移 | できる/できない | 検査結果 |",
54
+ "|---|---|---|---|---|---|---|",
55
+ ...changed.map((o) => {
56
+ const s = summaryOf(o.diff);
57
+ return `| [${o.name}](#${o.name}) | ${STATUS_LABEL[o.status]} | ${s.actions} | ${s.states} | ${s.transitions} | ${s.availability} | ${s.findings} |`;
58
+ }),
59
+ "",
60
+ ]),
61
+ ...(unchanged.length === 0 ? [] : [`変化なし: ${unchanged.map((o) => o.name).join(", ")}`, ""]),
62
+ ...changed.flatMap((o) => [
63
+ `## ${o.name}(${STATUS_LABEL[o.status]})`,
64
+ "",
65
+ ...mermaidOf(o),
66
+ "",
67
+ renderDiff(o.diff, { heading: false }),
68
+ ]),
69
+ ].join("\n");
70
+ };
@@ -0,0 +1,2 @@
1
+ import type { EnsureCheck } from "../model.js";
2
+ export declare const describeEnsure: (e: EnsureCheck, acknowledged?: boolean) => string;
@@ -0,0 +1,21 @@
1
+ const effectText = (e) => {
2
+ const first = e.effects[0];
3
+ if (first === undefined)
4
+ return `状態「${e.newStates.join("」「")}」に入れるようになる`;
5
+ const who = first.input === null ? first.actor : `${first.actor}(${first.input})`;
6
+ const rest = e.effects.length > 1 ? ` ほか ${e.effects.length - 1} 件` : "";
7
+ return `${who} が ${first.state} で実行できるようになる(${first.after.replace(/^✅ /, "")})${rest}`;
8
+ };
9
+ const effectOf = (e, acknowledged) => {
10
+ switch (e.verdict) {
11
+ case "caught":
12
+ return `外すと、${e.caughtBy.join("・")}が気づく`;
13
+ case "unguarded":
14
+ return `外すと、${effectText(e)}。気づくものがない${acknowledged ? "(確認済み)" : ""}`;
15
+ case "no-effect":
16
+ return e.narrowing ? "外しても振る舞いが変わらない(後の条件のために型を絞る条件)" : "外しても振る舞いが変わらない(ほかの条件と重なっている)";
17
+ }
18
+ };
19
+ // 理由の文と「実際に通るとき」を並べる理由: 理由の文は書き手の意図をもう一度書いたものなので、
20
+ // 実行して求めた事実と見比べると、状態の取り違えのような書き間違いが見える。
21
+ export const describeEnsure = (e, acknowledged = false) => `${e.verdict === "unguarded" && !acknowledged ? "⚠ " : ""}「${e.reason}」— 通るのは ${e.passes}。${effectOf(e, acknowledged)}`;
@@ -10,3 +10,4 @@ export interface ProjectOptions {
10
10
  export declare const renderHtml: (spec: Spec, graph: Graph) => Promise<string>;
11
11
  export declare const renderProjectHtml: (objects: ReadonlyArray<DomainObject>, options: ProjectOptions) => Promise<string>;
12
12
  export declare const renderErrorHtml: (name: string, error: unknown) => string;
13
+ export declare const CSS = "\n:root{--bg:#f6f5f1;--fg:#1c1c1e;--muted:#6e6d72;--line:#d9d6cd;--card:#fff;--node:#fff;--accent:#2b59e0;--accent-weak:#e5ebfc;--ok:#1d7f48;--warn:#b3501a;--chip:#efeee9}\n@media (prefers-color-scheme:dark){:root{--bg:#141416;--fg:#ececee;--muted:#9a99a0;--line:#34343a;--card:#1c1c20;--node:#1f1f24;--accent:#7f9dff;--accent-weak:#232b45;--ok:#5cc98b;--warn:#f0a46b;--chip:#2a2a30}}\n*{box-sizing:border-box}\nbody{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 system-ui,-apple-system,\"Hiragino Sans\",\"Noto Sans JP\",sans-serif}\ncode{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--chip);padding:1px 6px;border-radius:5px}\n.top{display:flex;justify-content:space-between;align-items:flex-end;gap:24px;padding:40px 40px 24px;border-bottom:1px solid var(--line)}\n.eyebrow{margin:0 0 4px;font-size:12px;letter-spacing:.08em;color:var(--muted)}\nh1{margin:0;font-size:32px;letter-spacing:-.01em}\n.lead{margin:8px 0 0;color:var(--muted);max-width:60ch}\n.stats{display:flex;gap:28px;margin:0}\n.stats div{text-align:right}.stats dt{font-size:12px;color:var(--muted)}.stats dd{margin:0;font-size:24px;font-weight:600}\n.stats .ok{color:var(--ok)}.stats .warn{color:var(--warn)}\nmain{padding:24px 40px 64px}\nh2{font-size:18px;margin:40px 0 16px}\n.board .hint{margin:0 0 10px}\n.diagram{background:var(--card);border:1px solid var(--line);border-radius:14px;overflow:auto;padding:8px}\n.diagram svg{display:block;max-width:100%;height:auto;margin:0 auto}\n.panel{position:fixed;top:16px;right:16px;width:400px;max-height:calc(100vh - 32px);overflow:auto;background:var(--card);border:1px solid var(--line);border-radius:14px;padding:20px;box-shadow:0 12px 40px rgba(0,0,0,.25);z-index:10}\n.panel[hidden]{display:none}\n.panel h2{margin:0 0 12px;font-size:20px}\n.panel h3{font-size:13px;color:var(--muted);margin:18px 0 6px;font-weight:600}\n.panel ul{list-style:none;margin:0;padding:0}\n.panel li{padding:6px 0;border-top:1px solid var(--line)}\n.panel li:first-child{border-top:0}\n.panel .sub{display:block;font-size:12px;color:var(--muted)}\n.panel .tag{display:inline-block;font-size:11px;padding:1px 8px;border-radius:999px;background:var(--chip);margin-right:6px}\n.panel button{margin-top:16px;font:inherit;font-size:13px;background:none;border:1px solid var(--line);color:var(--fg);border-radius:8px;padding:4px 12px;cursor:pointer}\n.hint{font-size:12px;color:var(--muted)}\n.site{position:sticky;top:0;z-index:5;display:flex;gap:24px;align-items:center;padding:10px 40px;background:var(--bg);border-bottom:1px solid var(--line)}\n.site-title{font-weight:700;color:var(--fg);text-decoration:none}\n.tabs{display:flex;gap:4px;flex-wrap:wrap}\n.tabs a{color:var(--muted);text-decoration:none;padding:4px 12px;border-radius:8px;font-size:14px}\n.tabs a:hover{color:var(--fg)}\n.tabs a[aria-current=\"page\"]{background:var(--accent-weak);color:var(--accent);font-weight:600}\n.page[hidden]{display:none}\n.object-card{display:block;color:var(--fg);text-decoration:none}\n.object-card h3{font-size:18px}\n.object-doc{color:var(--muted);margin:0 0 12px}\n.card .object-stats{display:flex;gap:20px;margin:0}\n.object-stats dt{font-size:12px;color:var(--muted)}.object-stats dd{margin:0;font-weight:600;font-size:18px}\n.object-stats .ok{color:var(--ok)}.object-stats .warn{color:var(--warn)}\n.toolbar{display:flex;gap:16px;align-items:center;margin:0 0 10px;font-size:13px}\n.modes{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden}\n.modes button{font:inherit;font-size:13px;background:none;border:0;color:var(--muted);padding:4px 12px;cursor:pointer}\n.modes button[aria-pressed=\"true\"]{background:var(--accent-weak);color:var(--accent);font-weight:600}\n.viewpoint{color:var(--muted)}.viewpoint select{font:inherit;font-size:13px;margin-left:4px}\n.board[data-mode=\"states\"] .diagram-wireflow,.board[data-mode=\"wireflow\"] .diagram-states{display:none}\n.board:not([data-mode=\"wireflow\"]) .viewpoint{display:none}\nsvg text.wf-node-label{text-anchor:start;font-weight:600;font-size:13px}\n.thumb-frame{width:100%;height:100%;overflow:hidden;pointer-events:none}\n.thumb-inner{transform:scale(0.6);transform-origin:0 0}\n.wf-group{margin:10px 0 16px}\n.wf-screen{border:1.5px solid var(--fg);border-radius:8px;background:var(--node);font-size:13px;overflow:hidden}\n.wf-title{border-bottom:1.5px solid var(--fg);padding:6px 10px;font-weight:600;display:flex;gap:6px;align-items:center}\n.wf-title::before{content:\"\";width:28px;height:6px;border-radius:3px;background:repeating-linear-gradient(90deg,var(--muted) 0 6px,transparent 6px 11px)}\n.wf-body{padding:10px;display:flex;flex-direction:column;gap:8px;align-items:flex-start}\n.wf-section{border:1px dashed var(--muted);border-radius:6px;padding:8px;align-self:stretch;display:flex;flex-direction:column;gap:6px;align-items:flex-start}\n.wf-section > .wf-label{font-size:11.5px;color:var(--muted)}\n.wf-heading{font-weight:600;font-size:14px}\n.wf-text{margin:0}\n.wf-field{display:flex;flex-direction:column;gap:2px;align-self:stretch;font-size:11.5px;color:var(--muted)}\n.wf-input{border:1.2px solid var(--muted);border-radius:4px;min-height:24px;padding:2px 6px;color:var(--fg);font-size:12.5px}\n.wf-button{border:1.5px solid var(--fg);border-radius:6px;padding:2px 12px;font-size:12.5px;font-weight:600}\n.wf-button.is-disabled{opacity:.4;border-style:dashed}\n.wf-button.is-invalid{border-color:var(--warn);color:var(--warn)}\n.wf-button.is-invalid::after{content:\" \u26A0\"}\n.wf-badge{border:1px solid var(--muted);border-radius:999px;padding:0 8px;font-size:11px;color:var(--muted)}\n.wf-list{margin:0;padding-left:18px;align-self:stretch}\n.wf-code{margin:0;align-self:stretch;background:var(--chip);border-radius:6px;padding:8px;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap}\n.wf-code[data-language=\"terminal\"]{background:#111;color:#e6e6e6}\nsvg text{font-size:13px;fill:var(--fg);text-anchor:middle;dominant-baseline:central}\nmarker path{fill:var(--muted)}\n.node{cursor:pointer;outline:none}\n.node rect{fill:var(--node);stroke:var(--fg);stroke-width:1.4}\n.node rect.inner{fill:none;stroke-width:1}\n.node:hover rect,.node:focus-visible rect{stroke:var(--accent)}\n.node.violation rect{stroke:var(--warn);stroke-width:2;stroke-dasharray:5 3}\n.panel .tag.warn{background:var(--warn);color:var(--bg)}\n.panel .violation{color:var(--warn);font-size:13px;margin:10px 0 0}\n.start{fill:var(--fg)}.start-line{stroke:var(--fg);stroke-width:1.4}\n.edge{cursor:pointer}\n.edge path{fill:none;stroke:var(--muted);stroke-width:1.3}\n.edge-label rect{fill:var(--card)}\n.edge-label text{font-size:11.5px;fill:var(--muted)}\n.edge:hover path{stroke:var(--accent)}.edge:hover .edge-label text{fill:var(--accent)}\n.is-dim{opacity:.18;transition:opacity .15s}\n.node.is-selected rect{stroke:var(--accent);stroke-width:2.2;fill:var(--accent-weak)}\n.edge.is-active path{stroke:var(--accent);stroke-width:2.2}\n.edge.is-active .edge-label text{fill:var(--accent);font-weight:600}\n.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:16px}\n.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px 20px;cursor:pointer;outline:none;min-width:0}\n.card:hover,.card:focus-visible{border-color:var(--accent)}\n.card.is-selected{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-weak)}\n.card h3{margin:0 0 12px;font-size:16px}\n.card dl{display:grid;grid-template-columns:5.5em minmax(0,1fr);gap:8px 12px;margin:0;font-size:14px}\n.card dt{color:var(--muted);font-size:12.5px;padding-top:2px}\n.card dd{margin:0;min-width:0;overflow-wrap:anywhere}\n.card ul{margin:0;padding:0;list-style:none}\n.card li+li{margin-top:6px}\n.chip,.state,.flow{display:inline-block;max-width:100%;font-size:12.5px;border-radius:6px;padding:0 7px;margin:0 4px 4px 0;background:var(--chip)}\n.flow{background:var(--accent-weak)}\n.questions{border:1px solid var(--warn);border-radius:14px;padding:4px 20px 12px;margin:0 0 20px;background:var(--card)}\n.questions h2{margin:14px 0 8px;color:var(--warn);font-size:16px}\n.questions ol{margin:0;padding-left:20px}\n.questions li{margin:6px 0}\n.questions .ask{font-weight:600}\n.questions .target{color:var(--muted);font-size:13px;margin-left:4px}\n.questions .note{display:block;color:var(--muted);font-size:13px}\n.questions.review.done{border-color:var(--line)}.questions.review.done h2{color:var(--muted)}.ensure.unguarded.acknowledged{color:var(--muted);font-weight:400;font-size:12.5px}\n.review-id{font-size:11.5px;color:var(--muted);margin-left:4px}.acknowledged{margin:8px 0 4px;font-size:13px}.acknowledged summary{cursor:pointer;color:var(--muted)}\n.ensure{font-size:12.5px;margin:2px 0;color:var(--muted)}.ensure.unguarded{color:var(--warn);font-weight:600;font-size:13px}\n.q-badge{display:inline-block;font-size:11px;font-weight:600;padding:1px 8px;border-radius:999px;background:var(--warn);color:var(--bg);vertical-align:middle}\n.card .ask{color:var(--warn);font-size:13px}\n.q-mark circle{fill:var(--warn)}\n.q-mark text{fill:var(--bg);font-size:11px;font-weight:700}\n.stats .warn,.object-stats .warn{color:var(--warn)}\n.links-section{margin:0 0 8px}\n.link-list{list-style:none;padding:0;margin:8px 0 0}\n.link-list li{padding:6px 0;border-top:1px solid var(--line)}\n.link-list li:first-child{border-top:0}\n.link-list .sub{display:block;color:var(--muted);font-size:13px}\n.link-list a,.card .flow a{color:var(--accent)}\n.relations{margin-bottom:12px}\n.rel-node rect{fill:var(--node);stroke:var(--fg);stroke-width:1.4}\n.rel-node:hover rect{stroke:var(--accent)}\n.any-node rect{fill:none;stroke:var(--muted);stroke-width:1.2;stroke-dasharray:4 3}\n.any-node text{fill:var(--muted);font-size:12px}\n.glossary dl{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:0}\n.glossary dt{font-weight:600}\n.glossary .kind{font-size:11px;color:var(--muted);font-weight:400;margin-left:4px}\n.glossary .sub{display:block;color:var(--muted);font-size:13px}\n.ev{display:block;font-size:13px}\ncode.evidence{font-size:12px}\ntable.decision{border-collapse:collapse;margin:8px 0 20px;background:var(--card);border:1px solid var(--line);border-radius:10px;overflow:hidden;font-size:14px}\ntable.decision th,table.decision td{padding:6px 14px;border-bottom:1px solid var(--line);text-align:left}\ntable.decision th{color:var(--muted);font-weight:600;font-size:12.5px}\ntable.decision td.result{font-weight:600}\ntable.decision tr.ng td.result{color:var(--warn)}\n.decisions h3{font-size:15px;margin:16px 0 4px}\n.scenario-card{margin-bottom:16px}\n.storyboard{display:flex;gap:14px;overflow-x:auto;list-style:none;margin:0;padding:0 0 6px;counter-reset:step}\n.storyboard li{flex:0 0 220px;counter-increment:step}\n.storyboard li::before{content:counter(step);display:inline-block;width:20px;height:20px;border-radius:50%;background:var(--accent-weak);color:var(--accent);font-size:12px;font-weight:700;text-align:center;line-height:20px;margin-bottom:4px}\n.storyboard li.failed::before{background:var(--warn);color:var(--bg)}\n.storyboard .step{margin:0 0 4px;font-size:13px;font-weight:600}\n.storyboard .flow{margin:0 0 8px;font-size:12px;display:inline-block}\n.storyboard .reason{margin:0;color:var(--warn);font-size:12.5px}\n.storyboard .frame{height:200px;overflow:hidden;border-radius:8px}\n.storyboard .frame-inner{width:366px;transform:scale(.6);transform-origin:0 0;pointer-events:none}\n.state.rest{background:none;border:1px dashed var(--line)}\n.reason{font-weight:600;margin-right:4px}\n.muted{color:var(--muted);font-size:13px;display:block}\n.findings ul{padding-left:20px}.findings li{color:var(--warn)}\n.ok-line{color:var(--ok)}\n@media (max-width:960px){.top{flex-direction:column;align-items:flex-start;padding:28px 20px 20px}main{padding:16px 20px 48px}.panel{left:16px;right:16px;width:auto;top:auto;bottom:16px;max-height:60vh}}\n@media print{.panel,.board .hint{display:none}.card{break-inside:avoid}}\n";
@@ -1,3 +1,5 @@
1
+ import { describeEnsure } from "./ensures.js";
2
+ import { REVIEW_LEAD, REVIEW_TITLE, reviewItems, unguardedId } from "./review.js";
1
3
  import { ANY } from "./collapse.js";
2
4
  import { esc } from "./escape.js";
3
5
  import { layout } from "./layout.js";
@@ -142,9 +144,11 @@ const renderPage = async ({ spec, graph }, index, objects, links) => {
142
144
  <ol class="storyboard">${s.steps
143
145
  .map((st) => {
144
146
  const shown = st.to === null ? undefined : graph.surfaces.find((x) => x.state === st.to && x.actor === st.actor);
145
- return `<li class="${st.ok ? "" : "failed"}"><p class="step">${esc(describeStep(spec, st))}</p>${st.ok
146
- ? `<p class="flow">${esc(labelOf(st.from ?? ""))} → ${esc(labelOf(st.to ?? ""))}</p>`
147
- : `<p class="reason">❌ ${esc(st.reason ?? "")}</p>`}${shown === undefined ? "" : `<div class="frame"><div class="frame-inner">${surfaceToHtml(shown.surface, notAllowed(st.to, [st.actor]))}</div></div>`}</li>`;
147
+ return `<li class="${st.ok ? "" : "failed"}"><p class="step">${esc(describeStep(spec, st))}</p>${st.ok && st.denied
148
+ ? `<p class="flow">断られる(${esc(st.reason ?? "")})</p>`
149
+ : st.ok
150
+ ? `<p class="flow">${esc(labelOf(st.from ?? ""))} → ${esc(labelOf(st.to ?? ""))}</p>`
151
+ : `<p class="reason">❌ ${esc(st.reason ?? "")}</p>`}${shown === undefined ? "" : `<div class="frame"><div class="frame-inner">${surfaceToHtml(shown.surface, notAllowed(st.to, [st.actor]))}</div></div>`}</li>`;
148
152
  })
149
153
  .join("")}</ol>
150
154
  </article>`;
@@ -198,6 +202,7 @@ const renderPage = async ({ spec, graph }, index, objects, links) => {
198
202
  .map((q) => `<li><span class="ask">${esc(q.ask)}</span><span class="target">${esc(questionTarget(spec, q, labelOf))}</span>${q.note === null ? "" : `<span class="note">${esc(q.note)}</span>`}</li>`)
199
203
  .join("")}</ol>
200
204
  </section>`}
205
+ ${reviewHtml(spec, graph)}
201
206
  <section class="board" aria-label="状態遷移図" data-mode="states">
202
207
  <p class="hint">状態をクリックすると、その状態でできること・できないことを表示します。矢印のラベルや操作カードをクリックすると、その操作の遷移を強調します。Esc で解除。</p>
203
208
  ${wl === null
@@ -219,7 +224,7 @@ const renderPage = async ({ spec, graph }, index, objects, links) => {
219
224
  <section class="actions">
220
225
  <h2>操作</h2>
221
226
  <div class="cards">
222
- ${actions.map((a) => actionCard(a, asksOf(a.name), linksOf(a.name), spec.evidence[a.name] ?? [])).join("\n ")}
227
+ ${actions.map((a) => actionCard(a, asksOf(a.name), linksOf(a.name), spec.evidence[a.name] ?? [], (graph.ensures ?? []).filter((e) => e.action === a.name), spec.reviewed)).join("\n ")}
223
228
  </div>
224
229
  </section>
225
230
  ${graph.decisions.length === 0
@@ -319,7 +324,23 @@ const edgeSvg = (e, markerId) => {
319
324
  const lb = e.label;
320
325
  return `<g class="edge" data-action="${esc(e.action)}" data-from="${esc(e.from)}" data-to="${esc(e.to)}"><path d="${d}" marker-end="url(#${markerId})"/><g class="edge-label"><rect x="${lb.x}" y="${lb.y}" width="${lb.width}" height="${lb.height}" rx="4"/><text x="${lb.x + lb.width / 2}" y="${lb.y + lb.height / 2}">${esc(e.action)}</text></g></g>`;
321
326
  };
322
- const actionCard = (a, asks, links, evidence) => {
327
+ // 確かめてほしい点の文は Markdown と共通なので、バッククォートで囲んだ部分を HTML ではコードとして出す。
328
+ const withCode = (text) => esc(text).replace(/`([^`]+)`/g, "<code>$1</code>");
329
+ const reviewHtml = (spec, graph) => {
330
+ const { pending, acknowledged } = reviewItems(spec, graph);
331
+ if (pending.length + acknowledged.length === 0)
332
+ return "";
333
+ return `<section class="questions review${pending.length === 0 ? " done" : ""}" aria-label="${REVIEW_TITLE}">
334
+ <h2>${REVIEW_TITLE}</h2>
335
+ ${pending.length === 0
336
+ ? '<p class="note">確かめてほしい点はありません。</p>'
337
+ : `<p class="note">${withCode(REVIEW_LEAD)}</p><ol>${pending.map((i) => `<li><span class="ask">${withCode(i.message)}</span> <code class="review-id">${esc(i.id)}</code></li>`).join("")}</ol>`}
338
+ ${acknowledged.length === 0
339
+ ? ""
340
+ : `<details class="acknowledged"><summary>確認済み(${acknowledged.length} 件)</summary><ul>${acknowledged.map((i) => `<li><code class="review-id">${esc(i.id)}</code> ${esc(i.note)}</li>`).join("")}</ul></details>`}
341
+ </section>`;
342
+ };
343
+ const actionCard = (a, asks, links, evidence, ensures, reviewed) => {
323
344
  const others = a.othersReasons.length === 0 ? "" : `<span class="muted">ほかの人は「${a.othersReasons.map(esc).join("」「")}」</span>`;
324
345
  const who = a.capable.length === 0
325
346
  ? '<span class="muted">なし(どの状態でも誰も実行できない)</span>'
@@ -347,6 +368,14 @@ const actionCard = (a, asks, links, evidence) => {
347
368
  })
348
369
  .join("")}</dd>`}
349
370
  ${links.length === 0 ? "" : `<dt>つながり</dt><dd>${links.map((l) => `<span class="flow">→ ${objectLink(l.to)}${l.action === null ? "" : ` の ${esc(l.action)}`}</span>`).join("")}<span class="muted">${esc(links.map((l) => l.label).join(" / "))}</span></dd>`}
371
+ ${ensures.length === 0
372
+ ? ""
373
+ : `<dt>条件</dt><dd><ul>${ensures
374
+ .map((e) => {
375
+ const acknowledged = reviewed[unguardedId(e)] !== undefined;
376
+ return `<li class="ensure ${e.verdict}${acknowledged ? " acknowledged" : ""}">${esc(describeEnsure(e, acknowledged))}</li>`;
377
+ })
378
+ .join("")}</ul></dd>`}
350
379
  ${asks.length === 0 ? "" : `<dt>未決</dt><dd><ul>${asks.map((q) => `<li class="ask">${esc(q)}</li>`).join("")}</ul></dd>`}
351
380
  </dl>
352
381
  </article>`;
@@ -357,7 +386,7 @@ const jsonForScript = (data) => JSON.stringify(data)
357
386
  .replace(/</g, "\\u003c")
358
387
  .replace(/\u{2028}/gu, "\\u2028")
359
388
  .replace(/\u{2029}/gu, "\\u2029");
360
- const CSS = `
389
+ export const CSS = `
361
390
  :root{--bg:#f6f5f1;--fg:#1c1c1e;--muted:#6e6d72;--line:#d9d6cd;--card:#fff;--node:#fff;--accent:#2b59e0;--accent-weak:#e5ebfc;--ok:#1d7f48;--warn:#b3501a;--chip:#efeee9}
362
391
  @media (prefers-color-scheme:dark){:root{--bg:#141416;--fg:#ececee;--muted:#9a99a0;--line:#34343a;--card:#1c1c20;--node:#1f1f24;--accent:#7f9dff;--accent-weak:#232b45;--ok:#5cc98b;--warn:#f0a46b;--chip:#2a2a30}}
363
392
  *{box-sizing:border-box}
@@ -448,16 +477,16 @@ marker path{fill:var(--muted)}
448
477
  .edge.is-active path{stroke:var(--accent);stroke-width:2.2}
449
478
  .edge.is-active .edge-label text{fill:var(--accent);font-weight:600}
450
479
  .cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:16px}
451
- .card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px 20px;cursor:pointer;outline:none}
480
+ .card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px 20px;cursor:pointer;outline:none;min-width:0}
452
481
  .card:hover,.card:focus-visible{border-color:var(--accent)}
453
482
  .card.is-selected{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-weak)}
454
483
  .card h3{margin:0 0 12px;font-size:16px}
455
- .card dl{display:grid;grid-template-columns:5.5em 1fr;gap:8px 12px;margin:0;font-size:14px}
484
+ .card dl{display:grid;grid-template-columns:5.5em minmax(0,1fr);gap:8px 12px;margin:0;font-size:14px}
456
485
  .card dt{color:var(--muted);font-size:12.5px;padding-top:2px}
457
- .card dd{margin:0}
486
+ .card dd{margin:0;min-width:0;overflow-wrap:anywhere}
458
487
  .card ul{margin:0;padding:0;list-style:none}
459
488
  .card li+li{margin-top:6px}
460
- .chip,.state,.flow{display:inline-block;font-size:12.5px;border-radius:6px;padding:0 7px;margin:0 4px 4px 0;background:var(--chip)}
489
+ .chip,.state,.flow{display:inline-block;max-width:100%;font-size:12.5px;border-radius:6px;padding:0 7px;margin:0 4px 4px 0;background:var(--chip)}
461
490
  .flow{background:var(--accent-weak)}
462
491
  .questions{border:1px solid var(--warn);border-radius:14px;padding:4px 20px 12px;margin:0 0 20px;background:var(--card)}
463
492
  .questions h2{margin:14px 0 8px;color:var(--warn);font-size:16px}
@@ -466,6 +495,9 @@ marker path{fill:var(--muted)}
466
495
  .questions .ask{font-weight:600}
467
496
  .questions .target{color:var(--muted);font-size:13px;margin-left:4px}
468
497
  .questions .note{display:block;color:var(--muted);font-size:13px}
498
+ .questions.review.done{border-color:var(--line)}.questions.review.done h2{color:var(--muted)}.ensure.unguarded.acknowledged{color:var(--muted);font-weight:400;font-size:12.5px}
499
+ .review-id{font-size:11.5px;color:var(--muted);margin-left:4px}.acknowledged{margin:8px 0 4px;font-size:13px}.acknowledged summary{cursor:pointer;color:var(--muted)}
500
+ .ensure{font-size:12.5px;margin:2px 0;color:var(--muted)}.ensure.unguarded{color:var(--warn);font-weight:600;font-size:13px}
469
501
  .q-badge{display:inline-block;font-size:11px;font-weight:600;padding:1px 8px;border-radius:999px;background:var(--warn);color:var(--bg);vertical-align:middle}
470
502
  .card .ask{color:var(--warn);font-size:13px}
471
503
  .q-mark circle{fill:var(--warn)}
@@ -33,5 +33,7 @@ export interface LayoutOptions {
33
33
  readonly width: number;
34
34
  readonly height: number;
35
35
  };
36
+ /** false にすると「どの状態からでも」にまとめない(差分の図で、消えた遷移まで見せるため) */
37
+ readonly collapse?: boolean;
36
38
  }
37
39
  export declare const layout: (graph: Graph, options?: LayoutOptions) => Promise<Layout>;
@@ -29,7 +29,7 @@ const ELK = ElkModule.default;
29
29
  export const layout = async (graph, options = {}) => {
30
30
  const elk = new ELK();
31
31
  // 自分自身に戻る遷移は描かない。ほぼすべての状態にあると、図が線で埋まって読めなくなるため。
32
- const transitions = collapseTransitions(graph).filter((t) => t.from !== t.to);
32
+ const transitions = (options.collapse === false ? graph.transitions : collapseTransitions(graph)).filter((t) => t.from !== t.to);
33
33
  const hasAny = transitions.some((t) => t.from === ANY);
34
34
  const nodeList = [
35
35
  ...(hasAny ? [{ id: ANY, label: ANY_LABEL, initial: false }] : []),
@@ -1,3 +1,5 @@
1
+ import { describeEnsure } from "./ensures.js";
2
+ import { REVIEW_LEAD, REVIEW_TITLE, reviewItems, unguardedId } from "./review.js";
1
3
  import { ANY, ANY_LABEL, collapseTransitions } from "./collapse.js";
2
4
  import { formatTransition, presentBlocked, summarizeActions, summarizeStates } from "./summary.js";
3
5
  import { surfaceToText } from "./wireframe.js";
@@ -47,6 +49,7 @@ export const renderMarkdown = (spec, graph, objects = [{ spec, graph }]) => {
47
49
  ]),
48
50
  "",
49
51
  ]),
52
+ ...reviewSection(spec, graph),
50
53
  "## 状態遷移図",
51
54
  "",
52
55
  "```mermaid",
@@ -68,6 +71,7 @@ export const renderMarkdown = (spec, graph, objects = [{ spec, graph }]) => {
68
71
  ...actionSection(a),
69
72
  ...((spec.evidence[a.name] ?? []).length === 0 ? [] : [`- **根拠**: ${spec.evidence[a.name].map(formatEvidence).join("、")}`]),
70
73
  ...graph.questions.filter((q) => q.action === a.name).map((q) => `- **未決**: ${q.ask}`),
74
+ ...ensureLines((graph.ensures ?? []).filter((e) => e.action === a.name), spec.reviewed),
71
75
  "",
72
76
  ]),
73
77
  ...(graph.links.length + incoming.length === 0
@@ -88,6 +92,19 @@ export const renderMarkdown = (spec, graph, objects = [{ spec, graph }]) => {
88
92
  "",
89
93
  ].join("\n");
90
94
  };
95
+ const ensureLines = (ensures, reviewed) => ensures.length === 0 ? [] : ["- **条件**:", ...ensures.map((e) => ` - ${describeEnsure(e, reviewed[unguardedId(e)] !== undefined)}`)];
96
+ const reviewSection = (spec, graph) => {
97
+ const { pending, acknowledged } = reviewItems(spec, graph);
98
+ if (pending.length + acknowledged.length === 0)
99
+ return [];
100
+ return [
101
+ `## ${REVIEW_TITLE}`,
102
+ "",
103
+ ...(pending.length === 0 ? ["確かめてほしい点はありません。"] : [REVIEW_LEAD, "", ...pending.map((i) => `- ${i.message}(\`${i.id}\`)`)]),
104
+ "",
105
+ ...(acknowledged.length === 0 ? [] : ["### 確認済み", "", ...acknowledged.map((i) => `- \`${i.id}\`: ${i.note}`), ""]),
106
+ ];
107
+ };
91
108
  const actionSection = (a) => {
92
109
  const heading = a.summary === null ? `### \`${a.name}\`` : `### ${a.summary}(\`${a.name}\`)`;
93
110
  if (a.capable.length === 0)
@@ -182,9 +199,11 @@ export const describeStep = (spec, step) => {
182
199
  const scenarioSection = (spec, s, labelOf) => [
183
200
  `### ${s.passed ? "✅" : "❌"} ${s.name}`,
184
201
  "",
185
- ...s.steps.map((step, i) => step.ok
186
- ? `${i + 1}. ${describeStep(spec, step)}: ${labelOf(step.from ?? "")} → ${labelOf(step.to ?? "")}`
187
- : `${i + 1}. ❌ ${describeStep(spec, step)}: ${step.reason}`),
202
+ ...s.steps.map((step, i) => step.ok && step.denied
203
+ ? `${i + 1}. ${describeStep(spec, step)}: 断られる(${step.reason})`
204
+ : step.ok
205
+ ? `${i + 1}. ${describeStep(spec, step)}: ${labelOf(step.from ?? "")} → ${labelOf(step.to ?? "")}`
206
+ : `${i + 1}. ❌ ${describeStep(spec, step)}: ${step.reason}`),
188
207
  ];
189
208
  export const formatEffect = (a) => a.effect.map((e) => `${e.field} → ${e.values.join(" / ")}`).join(", ");
190
209
  export const describeFinding = (f, labelOf) => {
@@ -205,6 +224,14 @@ export const describeFinding = (f, labelOf) => {
205
224
  return `操作 ${f.action} は 3 つ目以降の引数をとるが、inputs に例がないので実行していない`;
206
225
  case "unknown-inputs":
207
226
  return `inputs に書かれた ${f.action} という操作は存在しない`;
227
+ case "evidence-missing":
228
+ return `${f.action} の根拠「${f.evidence}」のファイルが見つからない(移動・改名されたか、起点が違う。別の場所のコードなら export const evidenceRoot を書く)`;
229
+ case "evidence-out-of-range":
230
+ return `${f.action} の根拠「${f.evidence}」の行が、ファイルの行数(${f.lines} 行)を超えている(コードが変わって行がずれた)`;
231
+ case "goal-unreachable":
232
+ return `目指す状態「${f.goal}」には、どの状態からもたどり着けない`;
233
+ case "reviewed-unmatched":
234
+ return `reviewed に書かれた ${f.id} は、確かめてほしい点のどれにも当たらない(ID の書き間違いか、もう出なくなった候補)`;
208
235
  case "surface-action-not-allowed":
209
236
  return `${labelOf(f.state)} で ${f.actor} に ${f.action} のボタンが見えているが、実行できない`;
210
237
  case "surface-action-missing":
@@ -0,0 +1,17 @@
1
+ import type { Spec } from "../load.js";
2
+ import type { EnsureCheck, Graph } from "../model.js";
3
+ export interface ReviewItem {
4
+ readonly id: string;
5
+ readonly message: string;
6
+ }
7
+ export declare const unguardedId: (e: Pick<EnsureCheck, "action" | "reason">) => string;
8
+ export declare const REVIEW_TITLE = "\u78BA\u304B\u3081\u3066\u307B\u3057\u3044\u70B9";
9
+ export declare const REVIEW_LEAD = "spec \u3092\u5B9F\u884C\u3057\u305F\u7D50\u679C\u304B\u3089\u3001\u6761\u4EF6\u306E\u66F8\u304D\u5FD8\u308C\u30FB\u66F8\u304D\u9593\u9055\u3044\u306E\u5019\u88DC\u3092\u6319\u3052\u3066\u3044\u307E\u3059\u3002\u76F4\u3059\u304B\u3001\u610F\u56F3\u3069\u304A\u308A\u306A\u3089 `export const reviewed = { \"ID\": \"\u7406\u7531\" }` \u306B\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\u3002";
10
+ export declare const reviewItems: (spec: Spec, graph: Graph) => {
11
+ pending: ReviewItem[];
12
+ acknowledged: {
13
+ id: string;
14
+ message: string;
15
+ note: string;
16
+ }[];
17
+ };
@@ -0,0 +1,17 @@
1
+ import { describeEnsure } from "./ensures.js";
2
+ export const unguardedId = (e) => `unguarded:${e.action}:${e.reason}`;
3
+ export const REVIEW_TITLE = "確かめてほしい点";
4
+ export const REVIEW_LEAD = "spec を実行した結果から、条件の書き忘れ・書き間違いの候補を挙げています。直すか、意図どおりなら `export const reviewed = { \"ID\": \"理由\" }` に書いてください。";
5
+ // 確認済みのものを消さずに残す理由: 「意図どおり」と判断した中身を、後から人が読めるようにするため。
6
+ export const reviewItems = (spec, graph) => {
7
+ const items = [
8
+ ...(graph.ensures ?? [])
9
+ .filter((e) => e.verdict === "unguarded")
10
+ .map((e) => ({ id: unguardedId(e), message: `\`${e.action}\` の${describeEnsure(e).replace(/^⚠ /, "")}` })),
11
+ ...(graph.omissions ?? []).map((h) => ({ id: h.id, message: h.message })),
12
+ ];
13
+ return {
14
+ pending: items.filter((i) => spec.reviewed[i.id] === undefined),
15
+ acknowledged: items.flatMap((i) => (spec.reviewed[i.id] === undefined ? [] : [{ ...i, note: spec.reviewed[i.id] }])),
16
+ };
17
+ };
@@ -0,0 +1,23 @@
1
+ import type { Graph } from "../model.js";
2
+ export type DiffStatus = "added" | "removed" | "kept";
3
+ export type EdgeStatus = DiffStatus | "changed";
4
+ export interface UnionNode {
5
+ readonly id: string;
6
+ readonly label: string;
7
+ readonly status: DiffStatus;
8
+ readonly initial: boolean;
9
+ }
10
+ export interface UnionEdge {
11
+ readonly from: string;
12
+ readonly to: string;
13
+ readonly action: string;
14
+ /** changed は、遷移はあるが通れる人が変わったもの */
15
+ readonly status: EdgeStatus;
16
+ readonly actorsAdded: ReadonlyArray<string>;
17
+ readonly actorsRemoved: ReadonlyArray<string>;
18
+ }
19
+ export declare const unionGraph: (before: Graph | null, after: Graph | null) => {
20
+ nodes: UnionNode[];
21
+ edges: UnionEdge[];
22
+ };
23
+ export declare const edgeLabel: (e: UnionEdge) => string;
@@ -0,0 +1,43 @@
1
+ // 状態は値で突き合わせる(ID は探索順で、名前は initial の書き順で変わりうる)。
2
+ // 自分自身に戻る遷移は、通常の図と同じく描かない。
3
+ export const unionGraph = (before, after) => {
4
+ const keyOf = (s) => JSON.stringify(s.values);
5
+ const labelsOf = (g) => new Map((g?.states ?? []).map((s) => [s.id, keyOf(s)]));
6
+ const lb = labelsOf(before);
7
+ const la = labelsOf(after);
8
+ const beforeKeys = new Set(lb.values());
9
+ const afterKeys = new Set(la.values());
10
+ const ordered = [...new Set([...afterKeys, ...beforeKeys])];
11
+ // 変更後の名前を優先する理由: レビューする人が読むのは変更後の spec なので。
12
+ const names = new Map([...(before?.states ?? []), ...(after?.states ?? [])].map((s) => [keyOf(s), s.label]));
13
+ const initialState = (after ?? before)?.states.find((s) => s.initial);
14
+ const initialKey = initialState === undefined ? undefined : keyOf(initialState);
15
+ const nodes = ordered.map((key, i) => ({
16
+ id: `n${i}`,
17
+ label: names.get(key) ?? key,
18
+ status: !beforeKeys.has(key) ? "added" : !afterKeys.has(key) ? "removed" : "kept",
19
+ initial: key === initialKey,
20
+ }));
21
+ const idOf = new Map(ordered.map((key, i) => [key, nodes[i].id]));
22
+ const actorsByKey = (g, labels) => {
23
+ const map = new Map();
24
+ for (const t of (g?.transitions ?? []).filter((t) => t.from !== t.to)) {
25
+ const key = JSON.stringify([labels.get(t.from), t.action, labels.get(t.to)]);
26
+ map.set(key, new Set([...(map.get(key) ?? []), ...t.actors]));
27
+ }
28
+ return map;
29
+ };
30
+ const kb = actorsByKey(before, lb);
31
+ const ka = actorsByKey(after, la);
32
+ const edges = [...new Set([...ka.keys(), ...kb.keys()])].map((key) => {
33
+ const [from, action, to] = JSON.parse(key);
34
+ const b = kb.get(key);
35
+ const a = ka.get(key);
36
+ const actorsAdded = b === undefined || a === undefined ? [] : [...a].filter((x) => !b.has(x));
37
+ const actorsRemoved = b === undefined || a === undefined ? [] : [...b].filter((x) => !a.has(x));
38
+ const status = b === undefined ? "added" : a === undefined ? "removed" : actorsAdded.length + actorsRemoved.length > 0 ? "changed" : "kept";
39
+ return { from: idOf.get(from), to: idOf.get(to), action, status, actorsAdded, actorsRemoved };
40
+ });
41
+ return { nodes, edges };
42
+ };
43
+ export const edgeLabel = (e) => [e.action, ...e.actorsAdded.map((a) => `+${a}`), ...e.actorsRemoved.map((a) => `-${a}`)].join(" ");
@@ -0,0 +1,2 @@
1
+ export declare const isSpecModuleUrl: (url: string) => boolean;
2
+ export declare const registerSpecLoader: () => void;