@quolu/lattice 0.52.0 → 0.52.2

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 (182) hide show
  1. package/LICENSE +147 -147
  2. package/README.ja.md +355 -355
  3. package/README.md +258 -258
  4. package/bin/lattice-mcp.mjs +0 -0
  5. package/bin/lattice-scripted-adapter.mjs +0 -0
  6. package/bin/lattice-scripted-worker.mjs +0 -0
  7. package/bin/lattice-work-order-adapter.mjs +0 -0
  8. package/bin/lattice.mjs +0 -0
  9. package/docs/bridge-setup.md +132 -132
  10. package/docs/schemas/lattice.executor_packet.v1.schema.json +57 -57
  11. package/docs/schemas/lattice.executor_receipt.v1.schema.json +66 -66
  12. package/docs/schemas/lattice.phase_todo_revision.v3.schema.json +360 -360
  13. package/docs/schemas/lattice.plan_create_input.v1.schema.json +56 -56
  14. package/docs/schemas/lattice.plan_create_input.v2.schema.json +72 -72
  15. package/docs/schemas/lattice.plan_create_input.v3.schema.json +81 -81
  16. package/docs/schemas/lattice.plan_create_input.v4.schema.json +85 -85
  17. package/docs/schemas/lattice.run_request.v1.schema.json +238 -238
  18. package/docs/schemas/lattice.runtime_adapter_capabilities.v2.schema.json +55 -55
  19. package/docs/schemas/lattice.runtime_adapter_registration_input.v1.schema.json +78 -78
  20. package/docs/schemas/lattice.runtime_adapter_registration_input.v2.schema.json +86 -86
  21. package/docs/schemas/lattice.todo_extraction.v2.schema.json +298 -298
  22. package/docs/schemas/lattice.todo_extraction.v3.schema.json +146 -146
  23. package/docs/schemas/lattice.todo_revision.v2.schema.json +260 -260
  24. package/docs/schemas/lattice.todo_revision_set.v3.schema.json +363 -363
  25. package/package.json +103 -103
  26. package/sensor/LICENSE +21 -21
  27. package/sensor/NOTICE +19 -19
  28. package/sensor/dist/bin/lattice-sensor.js +9 -9
  29. package/sensor/dist/db/index.js +24 -24
  30. package/sensor/dist/db/migrations.js +41 -41
  31. package/sensor/dist/db/queries.js +164 -164
  32. package/sensor/dist/db/schema.sql +205 -205
  33. package/sensor/dist/directory.js +5 -5
  34. package/sensor/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  35. package/sensor/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
  36. package/sensor/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
  37. package/sensor/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
  38. package/sensor/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  39. package/sensor/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
  40. package/sensor/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  41. package/sensor/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  42. package/sensor/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  43. package/sensor/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
  44. package/sensor/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  45. package/sensor/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  46. package/sensor/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  47. package/sensor/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  48. package/sensor/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  49. package/sensor/dist/mcp/liveness-watchdog.js +53 -53
  50. package/sensor/dist/mcp/server-instructions.js +95 -95
  51. package/sensor/package.json +56 -56
  52. package/src/artifact-contracts-v2.mjs +325 -325
  53. package/src/artifact-contracts.mjs +895 -895
  54. package/src/boundary-compiler.mjs +712 -712
  55. package/src/boundary-observation-compiler-v2.mjs +344 -344
  56. package/src/bounded-seam.mjs +230 -230
  57. package/src/bridge-address.mjs +107 -107
  58. package/src/bridge-cli.mjs +297 -297
  59. package/src/bridge-config.mjs +346 -346
  60. package/src/bridge-daemon.mjs +378 -378
  61. package/src/bridge-launch-agent.mjs +323 -323
  62. package/src/bridge-registrar.mjs +102 -102
  63. package/src/bridge-server.mjs +376 -376
  64. package/src/cli-help.mjs +308 -308
  65. package/src/cli-stdio.mjs +40 -40
  66. package/src/control-compiler.mjs +532 -532
  67. package/src/dag-chain.mjs +261 -261
  68. package/src/factory-diagnostics.mjs +188 -188
  69. package/src/hash-chain.mjs +76 -76
  70. package/src/hooks-cli.mjs +1057 -1053
  71. package/src/isolation-runner.mjs +409 -409
  72. package/src/node-version-guard.mjs +44 -44
  73. package/src/project-cli.mjs +697 -697
  74. package/src/project-identity.mjs +130 -130
  75. package/src/rc1-black-box-oracle.mjs +906 -906
  76. package/src/rc1-comparison.mjs +154 -154
  77. package/src/rc1-evidence-bundle.mjs +456 -456
  78. package/src/rc1-v4-campaign.mjs +708 -708
  79. package/src/rc1-v4-transform.mjs +467 -467
  80. package/src/rc1-v5-artifact-set.mjs +855 -855
  81. package/src/rc1-v5-behavior-evidence.mjs +594 -594
  82. package/src/rc1-v5-campaign.mjs +797 -797
  83. package/src/rc1-v5-transform.mjs +421 -421
  84. package/src/rc1-v6-artifact-set.mjs +807 -807
  85. package/src/rc1-v6-behavior-evidence.mjs +273 -273
  86. package/src/rc1-v6-campaign.mjs +623 -623
  87. package/src/rc1-v6-causal-binding.mjs +473 -473
  88. package/src/rc1-v6-measurement.mjs +313 -313
  89. package/src/rc2-artifact-set.mjs +1584 -1584
  90. package/src/rc2-campaign.mjs +1506 -1502
  91. package/src/rc2-delivery-policy-front-end.mjs +1079 -1079
  92. package/src/rc2-delivery-policy-oracle.mjs +134 -134
  93. package/src/rc2-delivery-policy-transform.mjs +1127 -1127
  94. package/src/rc2-rc1-transfer-front-end.mjs +511 -511
  95. package/src/rc3-actual-dogfood.mjs +652 -652
  96. package/src/rc3-dogfood-scaffold.mjs +315 -315
  97. package/src/rc3-scripted-campaign.mjs +1383 -1383
  98. package/src/rc4-stage1-dogfood.mjs +673 -673
  99. package/src/runtime-adapter-registry.mjs +524 -520
  100. package/src/runtime-cli.mjs +4588 -4584
  101. package/src/runtime-contracts.mjs +824 -824
  102. package/src/runtime-control-store.mjs +604 -600
  103. package/src/runtime-controller-protocol.mjs +587 -587
  104. package/src/runtime-decision-verifier.mjs +701 -701
  105. package/src/runtime-diff-observer.mjs +361 -361
  106. package/src/runtime-direct-os-observer.mjs +301 -301
  107. package/src/runtime-driver-state.mjs +166 -162
  108. package/src/runtime-engine.mjs +779 -779
  109. package/src/runtime-errors.mjs +356 -356
  110. package/src/runtime-event-store.mjs +189 -189
  111. package/src/runtime-front-end.mjs +925 -925
  112. package/src/runtime-gate-store.mjs +481 -477
  113. package/src/runtime-hold-recompile.mjs +916 -916
  114. package/src/runtime-io-sentinel.mjs +391 -391
  115. package/src/runtime-lifecycle-lock.mjs +294 -290
  116. package/src/runtime-managed-supervisor.mjs +1490 -1490
  117. package/src/runtime-multi-epoch-store.mjs +838 -834
  118. package/src/runtime-projection.mjs +269 -269
  119. package/src/runtime-pull-intake.mjs +1192 -1188
  120. package/src/runtime-scripted-adapter-controller.mjs +1160 -1156
  121. package/src/runtime-scripted-executor.mjs +163 -163
  122. package/src/runtime-scripted-worktree.mjs +104 -104
  123. package/src/runtime-seam-resolve.mjs +428 -428
  124. package/src/runtime-seam-treatment.mjs +173 -173
  125. package/src/runtime-socket-owner.mjs +125 -125
  126. package/src/runtime-work-order-contracts.mjs +91 -91
  127. package/src/runtime-work-order-controller.mjs +1171 -1167
  128. package/src/runtime-worktree-executor.mjs +199 -199
  129. package/src/schedulability-compiler-v2.mjs +303 -303
  130. package/src/schedulability-verifier-v2.mjs +317 -317
  131. package/src/seam-apply.mjs +549 -549
  132. package/src/seam-commit-shared.mjs +22 -22
  133. package/src/seam-commit-transform.mjs +81 -81
  134. package/src/seam-commit.mjs +18 -18
  135. package/src/seam-cost.mjs +322 -322
  136. package/src/seam-derivation.mjs +188 -188
  137. package/src/seam-gate.mjs +146 -146
  138. package/src/seam-proposal-contracts.mjs +446 -446
  139. package/src/seam-proposal-queries.mjs +521 -521
  140. package/src/seam-proposal.mjs +2011 -2011
  141. package/src/seam-ref.mjs +33 -33
  142. package/src/seam-rewrite.mjs +286 -286
  143. package/src/seam-transform.mjs +554 -554
  144. package/src/seam-verification.mjs +260 -260
  145. package/src/sensor-adapter.mjs +432 -432
  146. package/src/sensor-cli.mjs +139 -139
  147. package/src/sensor-diff.mjs +661 -661
  148. package/src/sensor-node-runtime.mjs +53 -53
  149. package/src/sensor-runtime.mjs +52 -52
  150. package/src/timestamp-contract.mjs +8 -8
  151. package/src/todo-audit-pending.mjs +91 -91
  152. package/src/todo-chain.mjs +178 -178
  153. package/src/todo-cli.mjs +3141 -3126
  154. package/src/todo-contracts.mjs +728 -728
  155. package/src/todo-dashboard-registry.mjs +573 -573
  156. package/src/todo-dispatch-shape.mjs +190 -190
  157. package/src/todo-gantt-html-independence.mjs +239 -239
  158. package/src/todo-gantt-html-shared.mjs +226 -226
  159. package/src/todo-gantt-html-style.mjs +131 -131
  160. package/src/todo-gantt-html.mjs +248 -248
  161. package/src/todo-gantt-layout.mjs +974 -974
  162. package/src/todo-gantt-live.mjs +361 -361
  163. package/src/todo-gantt-nested.mjs +263 -263
  164. package/src/todo-gantt-presentation.mjs +217 -217
  165. package/src/todo-gantt-scope.mjs +123 -123
  166. package/src/todo-gantt-svg.mjs +353 -353
  167. package/src/todo-independence-contracts.mjs +595 -595
  168. package/src/todo-independence-guidance.mjs +322 -322
  169. package/src/todo-independence.mjs +640 -640
  170. package/src/todo-markdown-renderer.mjs +260 -260
  171. package/src/todo-migration.mjs +448 -448
  172. package/src/todo-narrative-anchor.mjs +130 -130
  173. package/src/todo-note-store.mjs +629 -625
  174. package/src/todo-parallel-candidates.mjs +114 -114
  175. package/src/todo-revision.mjs +995 -995
  176. package/src/todo-split.mjs +472 -472
  177. package/src/todo-status.mjs +690 -690
  178. package/src/todo-store-git-transaction.mjs +418 -418
  179. package/src/todo-store.mjs +4322 -4314
  180. package/src/treatment-compiler.mjs +728 -728
  181. package/src/treatment-runner.mjs +656 -656
  182. package/src/witness-scaffold.mjs +180 -180
@@ -1,239 +1,239 @@
1
- import { DOCUMENT_STATUS, SEVERABILITY_LABEL, escapeHtmlAttribute, escapeHtmlText, foldIndex, planActivity, presentationLookup, refKey, renderPhaseProgress, renderRelationList, renderSeamProposalOverview, renderTaskIndex, statusMarkup, taskReference } from './todo-gantt-html-shared.mjs';
2
- import { renderTodoMarkdown } from './todo-markdown-renderer.mjs';
3
-
4
- function renderNoteContext(context) {
5
- if (context === null) {
6
- return '<section class="work-log"><h2>作業記録</h2><p class="note-warning">作業記録を読み取れません。概要の読取警告を確認してください。</p></section>';
7
- }
8
- if (context.notes.length === 0) {
9
- return '<section class="work-log"><h2>作業記録</h2><p>記録はありません。</p></section>';
10
- }
11
- const entries = context.notes.map((note) => {
12
- const rendered = renderTodoMarkdown(note.body);
13
- const filtering = rendered.discarded.length === 0 ? ''
14
- : '<p class="note-warning">安全上表示できない要素を除外しました。</p>';
15
- const correction = note.correction_state === 'superseded'
16
- ? `訂正済み(後継 ${note.superseded_by.slice(0, 12)}…)` : '現行';
17
- // UTCのまま埋め、閲覧者の現地時刻への変換はブラウザ側へ委ねる(title属性に原文を残す)。
18
- const stamp = `<time datetime="${escapeHtmlAttribute(note.recorded_at)}" title="${escapeHtmlAttribute(note.recorded_at)}" data-utc-stamp>${escapeHtmlText(note.recorded_at)}</time>`;
19
- return `<article class="work-log-entry"><header>${stamp}<span>${escapeHtmlText(correction)}</span></header><div class="work-log-body">${rendered.html}</div>${filtering}<p class="work-log-origin">来歴: ${escapeHtmlText(note.origin_plan_version)}/${escapeHtmlText(note.origin_task_id)}・記録者 ${escapeHtmlText(`${note.actor.host}/${note.actor.agent}`)}</p></article>`;
20
- }).join('');
21
- const overflow = context.overflow_count === 0 ? ''
22
- : `<p class="note-warning">ほか ${context.overflow_count}件は上限のため省略。全履歴: <code>${escapeHtmlText(context.full_history_command)}</code></p>`;
23
- return `<section class="work-log"><h2>作業記録</h2>${entries}${overflow}<p class="work-log-head">note head: <code>${escapeHtmlText(context.note_head_digest ?? 'none')}</code></p></section>`;
24
- }
25
-
26
- function renderDesignMemo(task) {
27
- if (typeof task.design_memo !== 'string') {
28
- return '<section class="design-memo"><h2>設計メモ</h2><p class="note-warning">未登録(legacy ToDo)</p></section>';
29
- }
30
- const rendered = renderTodoMarkdown(task.design_memo);
31
- const filtering = rendered.discarded.length === 0 ? ''
32
- : '<p class="note-warning">安全上表示できない要素を除外しました。</p>';
33
- return `<section class="design-memo"><h2>設計メモ</h2><div class="design-memo-body">${rendered.html}</div>${filtering}</section>`;
34
- }
35
-
36
- /**
37
- * 図の外が語るための独立性要約を、plan単位の投影から引ける形へ畳む(ADR 0129 Decision 3)。
38
- */
39
- export function summarizeIndependence(layout) {
40
- if (layout.independence === null) return null;
41
- const byPlan = new Map(layout.independence.plans.map((plan) => [plan.plan_key, plan]));
42
- return {
43
- plans: layout.independence.plans,
44
- byPlan,
45
- verifiedTaskCount: layout.independence.plans
46
- .reduce((total, plan) => total + plan.verified_task_count, 0),
47
- unknownTaskCount: layout.independence.plans
48
- .reduce((total, plan) => total + plan.unknown_task_ids.length, 0),
49
- serializePairCount: layout.independence.plans
50
- .reduce((total, plan) => total + plan.serialize_pairs.length, 0),
51
- };
52
- }
53
-
54
- /** 記録が無いときだけADR 0063の既定をそのまま述べる。 */
55
- export function dispatchBasis(summary) {
56
- if (summary === null) {
57
- return 'ready frontier全件が既定です。一部だけを直列着手する場合は理由が必要です。';
58
- }
59
- const parts = [`検証済み並列 ${summary.verifiedTaskCount}工程`];
60
- if (summary.serializePairCount > 0) parts.push(`要直列 ${summary.serializePairCount}組`);
61
- if (summary.unknownTaskCount > 0) parts.push(`未検査 ${summary.unknownTaskCount}工程`);
62
- return `${parts.join('、')}。未検査は依存線が無くても並列可の根拠になりません。`;
63
- }
64
-
65
- const COVERAGE_REASON = Object.freeze({
66
- missing: 'このplanには独立性の記録がまだありません。',
67
- stale: '記録はありますが、その後のdiffで失効しています。',
68
- superseded: '記録は旧plan versionのもので、現在のtopologyには読めません。',
69
- });
70
-
71
- /**
72
- * 未検査を黙って消さない。記録が無い状態こそ最も警告が要る(ADR 0127)。
73
- *
74
- * 枠ごと消すと「競合なし」と読まれる。判定していないことと、次の一手を必ず言う。
75
- */
76
- function unverifiedIndependence(planKey, coverage) {
77
- const reason = COVERAGE_REASON[coverage] ?? COVERAGE_REASON.missing;
78
- return `<p class="readiness-note"><strong>並列可否:</strong> 未検査です。競合が無いのではなく、まだ判定していません。${escapeHtmlText(reason)}宣言を書いて <code>lattice todo independence compile --plan ${escapeHtmlText(planKey)} --input &lt;ref&gt;</code> を通すと判定できます。</p>`;
79
- }
80
-
81
- function conflictItems(pairs) {
82
- return pairs.map((pair) => `<li>${escapeHtmlText(pair.other)} — ${escapeHtmlText(SEVERABILITY_LABEL[pair.severability] ?? pair.severability)}(資源 ${escapeHtmlText(pair.detail)})</li>`).join('');
83
- }
84
-
85
- /**
86
- * 作業中の工程は自分がready frontierに居ないため、conflictの相手側として現れる。
87
- * 「今これを動かしている間、何が同時に始められないか」がその工程での並列可否である。
88
- */
89
- function activeIndependence(plan, taskId) {
90
- const blocked = plan.conflicts_with_active
91
- .filter((entry) => entry.active_task_id === taskId)
92
- .map((entry) => ({
93
- other: entry.ready_task_id, severability: entry.severability, detail: entry.detail,
94
- }));
95
- if (blocked.length > 0) {
96
- return `<p class="readiness-note"><strong>並列可否:</strong> この工程が作業中のあいだ、次の着手候補は同時に始められません。</p><ul class="independence-conflicts">${conflictItems(blocked)}</ul>`;
97
- }
98
- if (plan.coverage !== 'verified') return unverifiedIndependence(plan.plan_key, plan.coverage);
99
- return '<p class="readiness-note"><strong>並列可否:</strong> 着手済のため同時着手の判定対象ではありません。現在の着手候補に、この工程と競合するものはありません。</p>';
100
- }
101
-
102
- /** 個別ToDoについて、競合相手と切断可能性を言葉で示す。 */
103
- export function renderIndependenceNote(ref, node, summary, status) {
104
- // 完了した工程は同時着手の判断材料ではない。ここだけは黙ってよい。
105
- if (status === 'done') return '';
106
- const plan = summary === null ? undefined : summary.byPlan.get(ref.plan_key);
107
- if (plan === undefined) return unverifiedIndependence(ref.plan_key, 'missing');
108
- const taskId = ref.task_id;
109
- const state = node?.visibility?.independence ?? null;
110
- if (state === null) {
111
- if (status === 'in-progress') return activeIndependence(plan, taskId);
112
- return '<p class="readiness-note"><strong>並列可否:</strong> まだ着手候補ではないため判定していません。前提工程が片付いて着手候補に入った時点で判定します。</p>';
113
- }
114
- if (state === 'verified') {
115
- return '<p class="readiness-note"><strong>並列可否:</strong> 独立検証済です。記録時点の宣言境界では他のready工程と干渉しません。</p>';
116
- }
117
- if (state === 'unknown') return unverifiedIndependence(plan.plan_key, plan.coverage);
118
- const pairs = [
119
- ...plan.serialize_pairs
120
- .filter((pair) => pair.task_ids.includes(taskId))
121
- .map((pair) => ({
122
- other: pair.task_ids.find((id) => id !== taskId),
123
- severability: pair.severability,
124
- detail: pair.detail,
125
- })),
126
- ...plan.conflicts_with_active
127
- .filter((entry) => entry.ready_task_id === taskId)
128
- .map((entry) => ({
129
- other: `${entry.active_task_id}(作業中)`,
130
- severability: entry.severability,
131
- detail: entry.detail,
132
- })),
133
- ];
134
- return `<p class="readiness-note"><strong>並列可否:</strong> 要直列です。</p><ul class="independence-conflicts">${conflictItems(pairs)}</ul>`;
135
- }
136
-
137
- export function renderRightPane(
138
- sections, layout, presentation, readModel, notesEnabled = false, noteWarnings = [], expandable = false,
139
- ) {
140
- const lookup = presentationLookup(presentation);
141
- const sectionByKey = new Map(sections.map((section) => [refKey(section.ref), section]));
142
- const semanticNodes = [...layout.nodes, ...(layout.hierarchy_nodes ?? [])];
143
- const nodeByKey = new Map(semanticNodes.map((node) => [refKey(node.ref), node]));
144
- const folds = foldIndex(layout);
145
- const incoming = new Map(sections.map((section) => [refKey(section.ref), []]));
146
- const outgoing = new Map(sections.map((section) => [refKey(section.ref), []]));
147
- const addRelation = (relations, ownerKey, ref, joinIds) => {
148
- const entries = relations.get(ownerKey);
149
- if (entries === undefined) return;
150
- let entry = entries.find((candidate) => refKey(candidate.ref) === refKey(ref));
151
- if (entry === undefined) {
152
- entry = { ref, joinIds: [] };
153
- entries.push(entry);
154
- }
155
- entry.joinIds = [...new Set([...entry.joinIds, ...joinIds])].sort();
156
- };
157
- // Premises and successors come from the FULL graph. `layout.edges` is the
158
- // drawn graph, where a fold unit's interior dependencies have been contracted
159
- // away — reading those here would tell a folded ToDo it has no premises.
160
- for (const edge of layout.full_edges ?? layout.edges) {
161
- addRelation(incoming, refKey(edge.to), edge.from, edge.join_ids);
162
- addRelation(outgoing, refKey(edge.from), edge.to, edge.join_ids);
163
- }
164
- const counts = { pending: 0, 'in-progress': 0, blocked: 0, done: 0 };
165
- for (const section of sections) counts[section.state.status] += 1;
166
- const active = sections.filter((section) => section.state.status === 'in-progress');
167
- const ready = semanticNodes.filter((node) => node.visibility.next_ready);
168
- const independenceSummary = summarizeIndependence(layout);
169
- const readyHeadline = ready.length > 1
170
- ? `<p class="readiness-note"><strong>同時dispatch推奨:</strong> ${ready.length}工程。${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`
171
- : ready.length === 1
172
- ? '<p class="readiness-note"><strong>着手候補:</strong> 1工程です。</p>'
173
- : '<p class="readiness-note">現在のready frontierは空です。</p>';
174
- // ready件数によらず、記録があるなら内訳を述べる。1件の時だけ黙ると、
175
- // その1件が未検査でも「候補が1つある」としか伝わらない。
176
- const independenceNote = independenceSummary === null || ready.length > 1 ? ''
177
- : `<p class="readiness-note"><strong>並列可否:</strong> ${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`;
178
- const dispatchSummary = `${readyHeadline}${independenceNote}`;
179
- const activeLinks = active.length === 0 ? '<p>作業中の工程はありません。</p>'
180
- : `<ul class="active-list">${active.map((section) => `<li><button type="button" data-select-node-key="${escapeHtmlAttribute(refKey(section.ref))}">${escapeHtmlText(taskReference(section, lookup))} — ${escapeHtmlText(section.task.title)}</button></li>`).join('')}</ul>`;
181
- const noteWarningMarkup = noteWarnings.length === 0 ? ''
182
- : `<section class="gantt-warning"><h2>作業記録の読取警告</h2><ul>${noteWarnings.map((warning) => `<li><code>${escapeHtmlText(warning.plan_key)}</code>: <strong>${escapeHtmlText(warning.code)}</strong> — ${escapeHtmlText(warning.message)}</li>`).join('')}</ul></section>`;
183
- const overview = `<section class="right-overview" data-right-panel="overview"><h1>工程を選択してください</h1><p>左の依存工程図から工程を選ぶと、題名・状態・前提・後続を表示します。</p><div class="status-summary"><span>☐ 未着手 ${counts.pending}</span><span>▶ 作業中 ${counts['in-progress']}</span><span>✅ 完了 ${counts.done}</span><span>⛔ ブロック中 ${counts.blocked}</span></div>${noteWarningMarkup}${dispatchSummary}${renderSeamProposalOverview(layout)}${renderPhaseProgress(readModel)}<h2>作業中</h2>${activeLinks}</section>`;
184
- const details = sections.map((section) => {
185
- const key = refKey(section.ref);
186
- const node = nodeByKey.get(key);
187
- const status = DOCUMENT_STATUS[section.state.status] ?? { mark: '?', label: '状態不明' };
188
- const lane = lookup.lanes.get(JSON.stringify([section.ref.plan_key, section.task.lane]));
189
- const category = lane === undefined ? section.task.lane : `${section.task.lane} — ${lane.name}`;
190
- const categoryDescription = lane === undefined ? '' : `<p class="category-description">${escapeHtmlText(lane.description)}</p>`;
191
- const blockedReason = section.state.status === 'blocked'
192
- ? `<p><strong>ブロック理由:</strong> ${escapeHtmlText(section.state.blocked_reason ?? '理由未記録')}</p>` : '';
193
- const sourceLine = section.anchorOutcome.origin_line === null ? '' : `:${section.anchorOutcome.origin_line}`;
194
- const sourceRef = section.narrativeRef ?? '参照なし';
195
- const anchorText = section.anchorOutcome.anchored
196
- ? `元plan: ${sourceRef}${sourceLine} — 行対応を確認済み`
197
- : `元plan: ${sourceRef}${sourceLine} — 行対応を確認できないため、本文位置との対応は表示していません`;
198
- const readiness = node?.visibility.next_ready
199
- ? `<p class="readiness-note">ready frontierの一員です。${ready.length > 1 ? '他のready工程と同時着手できるかは下の並列可否で判断してください。' : '現在の唯一の着手候補です。'}</p>`
200
- : incoming.get(key).length === 0 ? '<p class="readiness-note">登録済みの前提工程はありません。図だけではdispatch可否を判定しません。</p>' : '';
201
- const independenceNote = renderIndependenceNote(
202
- section.ref, node, independenceSummary, section.state.status,
203
- );
204
- // Say it plainly when the reader will not find this ToDo on the diagram.
205
- const foldedNote = !folds.has(key) ? ''
206
- : expandable
207
- ? '<p class="fold-note">完走済みのため既定の図には描いていません。左上の「完走済み」バッジを押すと、このページ内で表示できます。</p>'
208
- : '<p class="fold-note">完走済みのため図には描いていません。図に出すには動的dashboardを <code>lattice todo gantt serve --port &lt;port&gt; --scope all</code> で起動してください。</p>';
209
- const workLog = notesEnabled ? renderNoteContext(section.noteContext) : '';
210
- const designMemo = renderDesignMemo(section.task);
211
- return `<article class="task-detail" data-detail-key="${escapeHtmlAttribute(key)}" hidden><header><span class="detail-status status-${escapeHtmlAttribute(section.state.status)}">${escapeHtmlText(status.mark)} ${escapeHtmlText(status.label)}</span><span class="detail-reference">${escapeHtmlText(taskReference(section, lookup))}</span></header><h1>${escapeHtmlText(section.task.title)}</h1><p class="detail-category"><strong>カテゴリ:</strong> ${escapeHtmlText(category)}</p>${categoryDescription}<p><strong>正規ID:</strong> <code>${escapeHtmlText(`${section.ref.plan_key}/${section.task.task_id}`)}</code></p>${blockedReason}${readiness}${independenceNote}${foldedNote}${designMemo}<section><h2>前提工程</h2>${renderRelationList(incoming.get(key), sectionByKey, lookup, '登録済みの前提工程はありません。', folds)}</section><section><h2>後続工程</h2>${renderRelationList(outgoing.get(key), sectionByKey, lookup, '登録済みの後続工程はありません。', folds)}</section>${workLog}<p class="anchor-status">${escapeHtmlText(anchorText)}</p><details class="task-diagnostics"><summary>開発者向け診断</summary><dl><dt>canonical ref</dt><dd><code>${escapeHtmlText(`${section.ref.project_id}/${section.ref.plan_key}/${section.task.task_id}`)}</code></dd><dt>anchor</dt><dd>${escapeHtmlText(section.anchorOutcome.anchored ? 'verified' : section.anchorOutcome.reason)}</dd></dl></details></article>`;
212
- }).join('');
213
- const taskIndex = renderTaskIndex(sections, lookup, folds, planActivity(readModel));
214
- return `<div class="right-toolbar"><button type="button" data-show-overview>概要</button><button type="button" data-show-selected hidden>選択工程へ戻る</button><button type="button" data-show-task-index>全工程一覧</button></div><div class="right-content">${overview}<div data-right-panel="details" hidden>${details}</div><section class="task-index" data-right-panel="task-index" hidden><h1>全工程</h1><p>Latticeに登録された全工程を現在の状態とともに表示しています。planは動いているものを最終活動の新しい順で上に、完走したものを古い順で下にまとめ、plan内は登録順です。</p>${taskIndex}</section></div>`;
215
- }
216
-
217
- export function renderDiagramLegend(presentation, layout = null, expandable = false) {
218
- const categories = (presentation?.lanes ?? []).map((lane) => `<div class="category-entry"><dt><code>${escapeHtmlText(lane.lane)}</code> — ${escapeHtmlText(lane.name)}</dt><dd>${escapeHtmlText(lane.description)}</dd></div>`).join('');
219
- const categoryDetails = categories === '' ? '' : `<details class="category-legend"><summary>カテゴリ説明</summary><dl>${categories}</dl></details>`;
220
- const foldedCount = layout?.scope?.folded_task_count ?? 0;
221
- // The badge says what is missing from the diagram, so it is also the control
222
- // that brings it back — a reader who notices the count is exactly the reader
223
- // who wants to see it.
224
- const foldChip = foldedCount === 0 ? ''
225
- : expandable
226
- ? `<button type="button" class="fold-chip" data-toggle-expanded aria-expanded="false"><span data-toggle-label data-collapsed-label="完走済み ${foldedCount}件を非表示(押すと表示)" data-expanded-label="完走済み ${foldedCount}件を表示中(押すと非表示)">完走済み ${foldedCount}件を非表示(押すと表示)</span></button>`
227
- : `<span class="fold-chip">完走済み ${foldedCount}件を非表示</span>`;
228
- const foldNote = foldedCount === 0 ? ''
229
- : expandable
230
- ? '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。上のバッジを押すと外した工程も含めて描きます。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>'
231
- : '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。外した工程は右の「全工程」から辿れ、図に出すには動的dashboardを <code>lattice todo gantt serve --port &lt;port&gt; --scope all</code> で起動してください。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>';
232
- const independenceLegend = layout.independence === null ? ''
233
- : '<span>∥ 独立検証済</span><span>⛓ 要直列</span><span>? 未検査</span>';
234
- // 独立性の記録がある間は「全件同時dispatchが既定」と無条件に述べない(ADR 0129 Decision 3)。
235
- const dispatchSentence = layout.independence === null
236
- ? 'ready frontierは全件同時dispatchが既定です。未登録の資源・host制約によりsubsetだけを選ぶ場合は理由を記録します。'
237
- : '同時着手できるかはカードの並列可否で判断してください。未検査の工程は依存線が無くても並列可の根拠になりません。';
238
- return `<div class="diagram-legend" aria-label="工程図の凡例"><span>${statusMarkup('pending', ' 未着手')}</span><span>${statusMarkup('in-progress', ' 作業中')}</span><span>${statusMarkup('done', ' 完了')}</span><span>${statusMarkup('blocked', ' ブロック中')}</span><span>破線枠: ready frontier</span>${independenceLegend}<span>太線: 構造上の最長依存鎖</span><span>半円: 非接触の線交差</span><span>黒丸: 論理上の合流</span>${foldChip}${categoryDetails}${foldNote}<p>縦方向は時間ではなく、登録済み依存関係による工程段階です。${dispatchSentence}構造上の最長依存鎖は各工程を同じ重みとして数え、実時間・工数・納期を表しません。</p></div>`;
239
- }
1
+ import { DOCUMENT_STATUS, SEVERABILITY_LABEL, escapeHtmlAttribute, escapeHtmlText, foldIndex, planActivity, presentationLookup, refKey, renderPhaseProgress, renderRelationList, renderSeamProposalOverview, renderTaskIndex, statusMarkup, taskReference } from './todo-gantt-html-shared.mjs';
2
+ import { renderTodoMarkdown } from './todo-markdown-renderer.mjs';
3
+
4
+ function renderNoteContext(context) {
5
+ if (context === null) {
6
+ return '<section class="work-log"><h2>作業記録</h2><p class="note-warning">作業記録を読み取れません。概要の読取警告を確認してください。</p></section>';
7
+ }
8
+ if (context.notes.length === 0) {
9
+ return '<section class="work-log"><h2>作業記録</h2><p>記録はありません。</p></section>';
10
+ }
11
+ const entries = context.notes.map((note) => {
12
+ const rendered = renderTodoMarkdown(note.body);
13
+ const filtering = rendered.discarded.length === 0 ? ''
14
+ : '<p class="note-warning">安全上表示できない要素を除外しました。</p>';
15
+ const correction = note.correction_state === 'superseded'
16
+ ? `訂正済み(後継 ${note.superseded_by.slice(0, 12)}…)` : '現行';
17
+ // UTCのまま埋め、閲覧者の現地時刻への変換はブラウザ側へ委ねる(title属性に原文を残す)。
18
+ const stamp = `<time datetime="${escapeHtmlAttribute(note.recorded_at)}" title="${escapeHtmlAttribute(note.recorded_at)}" data-utc-stamp>${escapeHtmlText(note.recorded_at)}</time>`;
19
+ return `<article class="work-log-entry"><header>${stamp}<span>${escapeHtmlText(correction)}</span></header><div class="work-log-body">${rendered.html}</div>${filtering}<p class="work-log-origin">来歴: ${escapeHtmlText(note.origin_plan_version)}/${escapeHtmlText(note.origin_task_id)}・記録者 ${escapeHtmlText(`${note.actor.host}/${note.actor.agent}`)}</p></article>`;
20
+ }).join('');
21
+ const overflow = context.overflow_count === 0 ? ''
22
+ : `<p class="note-warning">ほか ${context.overflow_count}件は上限のため省略。全履歴: <code>${escapeHtmlText(context.full_history_command)}</code></p>`;
23
+ return `<section class="work-log"><h2>作業記録</h2>${entries}${overflow}<p class="work-log-head">note head: <code>${escapeHtmlText(context.note_head_digest ?? 'none')}</code></p></section>`;
24
+ }
25
+
26
+ function renderDesignMemo(task) {
27
+ if (typeof task.design_memo !== 'string') {
28
+ return '<section class="design-memo"><h2>設計メモ</h2><p class="note-warning">未登録(legacy ToDo)</p></section>';
29
+ }
30
+ const rendered = renderTodoMarkdown(task.design_memo);
31
+ const filtering = rendered.discarded.length === 0 ? ''
32
+ : '<p class="note-warning">安全上表示できない要素を除外しました。</p>';
33
+ return `<section class="design-memo"><h2>設計メモ</h2><div class="design-memo-body">${rendered.html}</div>${filtering}</section>`;
34
+ }
35
+
36
+ /**
37
+ * 図の外が語るための独立性要約を、plan単位の投影から引ける形へ畳む(ADR 0129 Decision 3)。
38
+ */
39
+ export function summarizeIndependence(layout) {
40
+ if (layout.independence === null) return null;
41
+ const byPlan = new Map(layout.independence.plans.map((plan) => [plan.plan_key, plan]));
42
+ return {
43
+ plans: layout.independence.plans,
44
+ byPlan,
45
+ verifiedTaskCount: layout.independence.plans
46
+ .reduce((total, plan) => total + plan.verified_task_count, 0),
47
+ unknownTaskCount: layout.independence.plans
48
+ .reduce((total, plan) => total + plan.unknown_task_ids.length, 0),
49
+ serializePairCount: layout.independence.plans
50
+ .reduce((total, plan) => total + plan.serialize_pairs.length, 0),
51
+ };
52
+ }
53
+
54
+ /** 記録が無いときだけADR 0063の既定をそのまま述べる。 */
55
+ export function dispatchBasis(summary) {
56
+ if (summary === null) {
57
+ return 'ready frontier全件が既定です。一部だけを直列着手する場合は理由が必要です。';
58
+ }
59
+ const parts = [`検証済み並列 ${summary.verifiedTaskCount}工程`];
60
+ if (summary.serializePairCount > 0) parts.push(`要直列 ${summary.serializePairCount}組`);
61
+ if (summary.unknownTaskCount > 0) parts.push(`未検査 ${summary.unknownTaskCount}工程`);
62
+ return `${parts.join('、')}。未検査は依存線が無くても並列可の根拠になりません。`;
63
+ }
64
+
65
+ const COVERAGE_REASON = Object.freeze({
66
+ missing: 'このplanには独立性の記録がまだありません。',
67
+ stale: '記録はありますが、その後のdiffで失効しています。',
68
+ superseded: '記録は旧plan versionのもので、現在のtopologyには読めません。',
69
+ });
70
+
71
+ /**
72
+ * 未検査を黙って消さない。記録が無い状態こそ最も警告が要る(ADR 0127)。
73
+ *
74
+ * 枠ごと消すと「競合なし」と読まれる。判定していないことと、次の一手を必ず言う。
75
+ */
76
+ function unverifiedIndependence(planKey, coverage) {
77
+ const reason = COVERAGE_REASON[coverage] ?? COVERAGE_REASON.missing;
78
+ return `<p class="readiness-note"><strong>並列可否:</strong> 未検査です。競合が無いのではなく、まだ判定していません。${escapeHtmlText(reason)}宣言を書いて <code>lattice todo independence compile --plan ${escapeHtmlText(planKey)} --input &lt;ref&gt;</code> を通すと判定できます。</p>`;
79
+ }
80
+
81
+ function conflictItems(pairs) {
82
+ return pairs.map((pair) => `<li>${escapeHtmlText(pair.other)} — ${escapeHtmlText(SEVERABILITY_LABEL[pair.severability] ?? pair.severability)}(資源 ${escapeHtmlText(pair.detail)})</li>`).join('');
83
+ }
84
+
85
+ /**
86
+ * 作業中の工程は自分がready frontierに居ないため、conflictの相手側として現れる。
87
+ * 「今これを動かしている間、何が同時に始められないか」がその工程での並列可否である。
88
+ */
89
+ function activeIndependence(plan, taskId) {
90
+ const blocked = plan.conflicts_with_active
91
+ .filter((entry) => entry.active_task_id === taskId)
92
+ .map((entry) => ({
93
+ other: entry.ready_task_id, severability: entry.severability, detail: entry.detail,
94
+ }));
95
+ if (blocked.length > 0) {
96
+ return `<p class="readiness-note"><strong>並列可否:</strong> この工程が作業中のあいだ、次の着手候補は同時に始められません。</p><ul class="independence-conflicts">${conflictItems(blocked)}</ul>`;
97
+ }
98
+ if (plan.coverage !== 'verified') return unverifiedIndependence(plan.plan_key, plan.coverage);
99
+ return '<p class="readiness-note"><strong>並列可否:</strong> 着手済のため同時着手の判定対象ではありません。現在の着手候補に、この工程と競合するものはありません。</p>';
100
+ }
101
+
102
+ /** 個別ToDoについて、競合相手と切断可能性を言葉で示す。 */
103
+ export function renderIndependenceNote(ref, node, summary, status) {
104
+ // 完了した工程は同時着手の判断材料ではない。ここだけは黙ってよい。
105
+ if (status === 'done') return '';
106
+ const plan = summary === null ? undefined : summary.byPlan.get(ref.plan_key);
107
+ if (plan === undefined) return unverifiedIndependence(ref.plan_key, 'missing');
108
+ const taskId = ref.task_id;
109
+ const state = node?.visibility?.independence ?? null;
110
+ if (state === null) {
111
+ if (status === 'in-progress') return activeIndependence(plan, taskId);
112
+ return '<p class="readiness-note"><strong>並列可否:</strong> まだ着手候補ではないため判定していません。前提工程が片付いて着手候補に入った時点で判定します。</p>';
113
+ }
114
+ if (state === 'verified') {
115
+ return '<p class="readiness-note"><strong>並列可否:</strong> 独立検証済です。記録時点の宣言境界では他のready工程と干渉しません。</p>';
116
+ }
117
+ if (state === 'unknown') return unverifiedIndependence(plan.plan_key, plan.coverage);
118
+ const pairs = [
119
+ ...plan.serialize_pairs
120
+ .filter((pair) => pair.task_ids.includes(taskId))
121
+ .map((pair) => ({
122
+ other: pair.task_ids.find((id) => id !== taskId),
123
+ severability: pair.severability,
124
+ detail: pair.detail,
125
+ })),
126
+ ...plan.conflicts_with_active
127
+ .filter((entry) => entry.ready_task_id === taskId)
128
+ .map((entry) => ({
129
+ other: `${entry.active_task_id}(作業中)`,
130
+ severability: entry.severability,
131
+ detail: entry.detail,
132
+ })),
133
+ ];
134
+ return `<p class="readiness-note"><strong>並列可否:</strong> 要直列です。</p><ul class="independence-conflicts">${conflictItems(pairs)}</ul>`;
135
+ }
136
+
137
+ export function renderRightPane(
138
+ sections, layout, presentation, readModel, notesEnabled = false, noteWarnings = [], expandable = false,
139
+ ) {
140
+ const lookup = presentationLookup(presentation);
141
+ const sectionByKey = new Map(sections.map((section) => [refKey(section.ref), section]));
142
+ const semanticNodes = [...layout.nodes, ...(layout.hierarchy_nodes ?? [])];
143
+ const nodeByKey = new Map(semanticNodes.map((node) => [refKey(node.ref), node]));
144
+ const folds = foldIndex(layout);
145
+ const incoming = new Map(sections.map((section) => [refKey(section.ref), []]));
146
+ const outgoing = new Map(sections.map((section) => [refKey(section.ref), []]));
147
+ const addRelation = (relations, ownerKey, ref, joinIds) => {
148
+ const entries = relations.get(ownerKey);
149
+ if (entries === undefined) return;
150
+ let entry = entries.find((candidate) => refKey(candidate.ref) === refKey(ref));
151
+ if (entry === undefined) {
152
+ entry = { ref, joinIds: [] };
153
+ entries.push(entry);
154
+ }
155
+ entry.joinIds = [...new Set([...entry.joinIds, ...joinIds])].sort();
156
+ };
157
+ // Premises and successors come from the FULL graph. `layout.edges` is the
158
+ // drawn graph, where a fold unit's interior dependencies have been contracted
159
+ // away — reading those here would tell a folded ToDo it has no premises.
160
+ for (const edge of layout.full_edges ?? layout.edges) {
161
+ addRelation(incoming, refKey(edge.to), edge.from, edge.join_ids);
162
+ addRelation(outgoing, refKey(edge.from), edge.to, edge.join_ids);
163
+ }
164
+ const counts = { pending: 0, 'in-progress': 0, blocked: 0, done: 0 };
165
+ for (const section of sections) counts[section.state.status] += 1;
166
+ const active = sections.filter((section) => section.state.status === 'in-progress');
167
+ const ready = semanticNodes.filter((node) => node.visibility.next_ready);
168
+ const independenceSummary = summarizeIndependence(layout);
169
+ const readyHeadline = ready.length > 1
170
+ ? `<p class="readiness-note"><strong>同時dispatch推奨:</strong> ${ready.length}工程。${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`
171
+ : ready.length === 1
172
+ ? '<p class="readiness-note"><strong>着手候補:</strong> 1工程です。</p>'
173
+ : '<p class="readiness-note">現在のready frontierは空です。</p>';
174
+ // ready件数によらず、記録があるなら内訳を述べる。1件の時だけ黙ると、
175
+ // その1件が未検査でも「候補が1つある」としか伝わらない。
176
+ const independenceNote = independenceSummary === null || ready.length > 1 ? ''
177
+ : `<p class="readiness-note"><strong>並列可否:</strong> ${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`;
178
+ const dispatchSummary = `${readyHeadline}${independenceNote}`;
179
+ const activeLinks = active.length === 0 ? '<p>作業中の工程はありません。</p>'
180
+ : `<ul class="active-list">${active.map((section) => `<li><button type="button" data-select-node-key="${escapeHtmlAttribute(refKey(section.ref))}">${escapeHtmlText(taskReference(section, lookup))} — ${escapeHtmlText(section.task.title)}</button></li>`).join('')}</ul>`;
181
+ const noteWarningMarkup = noteWarnings.length === 0 ? ''
182
+ : `<section class="gantt-warning"><h2>作業記録の読取警告</h2><ul>${noteWarnings.map((warning) => `<li><code>${escapeHtmlText(warning.plan_key)}</code>: <strong>${escapeHtmlText(warning.code)}</strong> — ${escapeHtmlText(warning.message)}</li>`).join('')}</ul></section>`;
183
+ const overview = `<section class="right-overview" data-right-panel="overview"><h1>工程を選択してください</h1><p>左の依存工程図から工程を選ぶと、題名・状態・前提・後続を表示します。</p><div class="status-summary"><span>☐ 未着手 ${counts.pending}</span><span>▶ 作業中 ${counts['in-progress']}</span><span>✅ 完了 ${counts.done}</span><span>⛔ ブロック中 ${counts.blocked}</span></div>${noteWarningMarkup}${dispatchSummary}${renderSeamProposalOverview(layout)}${renderPhaseProgress(readModel)}<h2>作業中</h2>${activeLinks}</section>`;
184
+ const details = sections.map((section) => {
185
+ const key = refKey(section.ref);
186
+ const node = nodeByKey.get(key);
187
+ const status = DOCUMENT_STATUS[section.state.status] ?? { mark: '?', label: '状態不明' };
188
+ const lane = lookup.lanes.get(JSON.stringify([section.ref.plan_key, section.task.lane]));
189
+ const category = lane === undefined ? section.task.lane : `${section.task.lane} — ${lane.name}`;
190
+ const categoryDescription = lane === undefined ? '' : `<p class="category-description">${escapeHtmlText(lane.description)}</p>`;
191
+ const blockedReason = section.state.status === 'blocked'
192
+ ? `<p><strong>ブロック理由:</strong> ${escapeHtmlText(section.state.blocked_reason ?? '理由未記録')}</p>` : '';
193
+ const sourceLine = section.anchorOutcome.origin_line === null ? '' : `:${section.anchorOutcome.origin_line}`;
194
+ const sourceRef = section.narrativeRef ?? '参照なし';
195
+ const anchorText = section.anchorOutcome.anchored
196
+ ? `元plan: ${sourceRef}${sourceLine} — 行対応を確認済み`
197
+ : `元plan: ${sourceRef}${sourceLine} — 行対応を確認できないため、本文位置との対応は表示していません`;
198
+ const readiness = node?.visibility.next_ready
199
+ ? `<p class="readiness-note">ready frontierの一員です。${ready.length > 1 ? '他のready工程と同時着手できるかは下の並列可否で判断してください。' : '現在の唯一の着手候補です。'}</p>`
200
+ : incoming.get(key).length === 0 ? '<p class="readiness-note">登録済みの前提工程はありません。図だけではdispatch可否を判定しません。</p>' : '';
201
+ const independenceNote = renderIndependenceNote(
202
+ section.ref, node, independenceSummary, section.state.status,
203
+ );
204
+ // Say it plainly when the reader will not find this ToDo on the diagram.
205
+ const foldedNote = !folds.has(key) ? ''
206
+ : expandable
207
+ ? '<p class="fold-note">完走済みのため既定の図には描いていません。左上の「完走済み」バッジを押すと、このページ内で表示できます。</p>'
208
+ : '<p class="fold-note">完走済みのため図には描いていません。図に出すには動的dashboardを <code>lattice todo gantt serve --port &lt;port&gt; --scope all</code> で起動してください。</p>';
209
+ const workLog = notesEnabled ? renderNoteContext(section.noteContext) : '';
210
+ const designMemo = renderDesignMemo(section.task);
211
+ return `<article class="task-detail" data-detail-key="${escapeHtmlAttribute(key)}" hidden><header><span class="detail-status status-${escapeHtmlAttribute(section.state.status)}">${escapeHtmlText(status.mark)} ${escapeHtmlText(status.label)}</span><span class="detail-reference">${escapeHtmlText(taskReference(section, lookup))}</span></header><h1>${escapeHtmlText(section.task.title)}</h1><p class="detail-category"><strong>カテゴリ:</strong> ${escapeHtmlText(category)}</p>${categoryDescription}<p><strong>正規ID:</strong> <code>${escapeHtmlText(`${section.ref.plan_key}/${section.task.task_id}`)}</code></p>${blockedReason}${readiness}${independenceNote}${foldedNote}${designMemo}<section><h2>前提工程</h2>${renderRelationList(incoming.get(key), sectionByKey, lookup, '登録済みの前提工程はありません。', folds)}</section><section><h2>後続工程</h2>${renderRelationList(outgoing.get(key), sectionByKey, lookup, '登録済みの後続工程はありません。', folds)}</section>${workLog}<p class="anchor-status">${escapeHtmlText(anchorText)}</p><details class="task-diagnostics"><summary>開発者向け診断</summary><dl><dt>canonical ref</dt><dd><code>${escapeHtmlText(`${section.ref.project_id}/${section.ref.plan_key}/${section.task.task_id}`)}</code></dd><dt>anchor</dt><dd>${escapeHtmlText(section.anchorOutcome.anchored ? 'verified' : section.anchorOutcome.reason)}</dd></dl></details></article>`;
212
+ }).join('');
213
+ const taskIndex = renderTaskIndex(sections, lookup, folds, planActivity(readModel));
214
+ return `<div class="right-toolbar"><button type="button" data-show-overview>概要</button><button type="button" data-show-selected hidden>選択工程へ戻る</button><button type="button" data-show-task-index>全工程一覧</button></div><div class="right-content">${overview}<div data-right-panel="details" hidden>${details}</div><section class="task-index" data-right-panel="task-index" hidden><h1>全工程</h1><p>Latticeに登録された全工程を現在の状態とともに表示しています。planは動いているものを最終活動の新しい順で上に、完走したものを古い順で下にまとめ、plan内は登録順です。</p>${taskIndex}</section></div>`;
215
+ }
216
+
217
+ export function renderDiagramLegend(presentation, layout = null, expandable = false) {
218
+ const categories = (presentation?.lanes ?? []).map((lane) => `<div class="category-entry"><dt><code>${escapeHtmlText(lane.lane)}</code> — ${escapeHtmlText(lane.name)}</dt><dd>${escapeHtmlText(lane.description)}</dd></div>`).join('');
219
+ const categoryDetails = categories === '' ? '' : `<details class="category-legend"><summary>カテゴリ説明</summary><dl>${categories}</dl></details>`;
220
+ const foldedCount = layout?.scope?.folded_task_count ?? 0;
221
+ // The badge says what is missing from the diagram, so it is also the control
222
+ // that brings it back — a reader who notices the count is exactly the reader
223
+ // who wants to see it.
224
+ const foldChip = foldedCount === 0 ? ''
225
+ : expandable
226
+ ? `<button type="button" class="fold-chip" data-toggle-expanded aria-expanded="false"><span data-toggle-label data-collapsed-label="完走済み ${foldedCount}件を非表示(押すと表示)" data-expanded-label="完走済み ${foldedCount}件を表示中(押すと非表示)">完走済み ${foldedCount}件を非表示(押すと表示)</span></button>`
227
+ : `<span class="fold-chip">完走済み ${foldedCount}件を非表示</span>`;
228
+ const foldNote = foldedCount === 0 ? ''
229
+ : expandable
230
+ ? '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。上のバッジを押すと外した工程も含めて描きます。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>'
231
+ : '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。外した工程は右の「全工程」から辿れ、図に出すには動的dashboardを <code>lattice todo gantt serve --port &lt;port&gt; --scope all</code> で起動してください。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>';
232
+ const independenceLegend = layout.independence === null ? ''
233
+ : '<span>∥ 独立検証済</span><span>⛓ 要直列</span><span>? 未検査</span>';
234
+ // 独立性の記録がある間は「全件同時dispatchが既定」と無条件に述べない(ADR 0129 Decision 3)。
235
+ const dispatchSentence = layout.independence === null
236
+ ? 'ready frontierは全件同時dispatchが既定です。未登録の資源・host制約によりsubsetだけを選ぶ場合は理由を記録します。'
237
+ : '同時着手できるかはカードの並列可否で判断してください。未検査の工程は依存線が無くても並列可の根拠になりません。';
238
+ return `<div class="diagram-legend" aria-label="工程図の凡例"><span>${statusMarkup('pending', ' 未着手')}</span><span>${statusMarkup('in-progress', ' 作業中')}</span><span>${statusMarkup('done', ' 完了')}</span><span>${statusMarkup('blocked', ' ブロック中')}</span><span>破線枠: ready frontier</span>${independenceLegend}<span>太線: 構造上の最長依存鎖</span><span>半円: 非接触の線交差</span><span>黒丸: 論理上の合流</span>${foldChip}${categoryDetails}${foldNote}<p>縦方向は時間ではなく、登録済み依存関係による工程段階です。${dispatchSentence}構造上の最長依存鎖は各工程を同じ重みとして数え、実時間・工数・納期を表しません。</p></div>`;
239
+ }