@quolu/lattice 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/bounded-seam.mjs +86 -0
- package/src/cli-help.mjs +2 -0
- package/src/isolation-runner.mjs +45 -12
- package/src/runtime-contracts.mjs +5 -2
- package/src/runtime-hold-recompile.mjs +4 -1
- package/src/seam-apply.mjs +0 -0
- package/src/seam-derivation.mjs +188 -0
- package/src/seam-rewrite.mjs +182 -0
- package/src/seam-verification.mjs +201 -0
- package/src/todo-cli.mjs +99 -1
- package/src/todo-gantt-html-independence.mjs +157 -0
- package/src/todo-gantt-html-shared.mjs +196 -0
- package/src/todo-gantt-html-style.mjs +107 -0
- package/src/todo-gantt-html.mjs +3 -459
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 変換の受入判定(ADR 0137 Decision 4・ADR 0138)。
|
|
3
|
+
*
|
|
4
|
+
* 五条件をすべて満たしたときだけ採用する。1つでも欠けたら棄却であり、どれが欠けたかを残す。
|
|
5
|
+
* 「だいたい良さそう」で通す経路を作らない——外部挙動を変えうる変更を、便益の証明なしに
|
|
6
|
+
* 受け入れないための面である。
|
|
7
|
+
*
|
|
8
|
+
* 実行を伴う観測(focused test、再index)は呼び出し側が行い、ここは観測から判定だけを作る。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { compileSchedulabilityGraphV2 } from './schedulability-compiler-v2.mjs';
|
|
12
|
+
import { todoSelfDigest } from './todo-contracts.mjs';
|
|
13
|
+
|
|
14
|
+
const GRAPH_SCHEMA = 'lattice.normalized_boundary_graph.v2';
|
|
15
|
+
const EXPORT_NAMED = /^\s*export\s+(?:async\s+)?(?:function|class|const|let|var)\s+([A-Za-z_$][\w$]*)/u;
|
|
16
|
+
const EXPORT_LIST = /^\s*export\s*\{([^}]*)\}/u;
|
|
17
|
+
const compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
18
|
+
const sortedUnique = (values) => [...new Set(values)].sort(compareText);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* moduleが外へ出している名前を読む。
|
|
22
|
+
*
|
|
23
|
+
* 分割で外部の消費者が影響を受けるかは、原pathの公開面が変わったかで決まる。原pathが
|
|
24
|
+
* 同じ名前を同じだけ出し続けるなら、原pathをimportしている側は一行も変わらない
|
|
25
|
+
* (ADR 0137 Decision 3)。
|
|
26
|
+
*/
|
|
27
|
+
export function readExportSurface(text) {
|
|
28
|
+
if (typeof text !== 'string') return [];
|
|
29
|
+
const names = [];
|
|
30
|
+
for (const line of text.split('\n')) {
|
|
31
|
+
const named = EXPORT_NAMED.exec(line);
|
|
32
|
+
if (named) { names.push(named[1]); continue; }
|
|
33
|
+
const list = EXPORT_LIST.exec(line);
|
|
34
|
+
if (!list) continue;
|
|
35
|
+
for (const entry of list[1].split(',')) {
|
|
36
|
+
const parts = entry.split(/\s+as\s+/u).map((part) => part.trim());
|
|
37
|
+
const name = parts.length > 1 ? parts[1] : parts[0];
|
|
38
|
+
if (/^[A-Za-z_$][\w$]*$/u.test(name)) names.push(name);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return sortedUnique(names);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 外部挙動同等性を、原pathの公開面が保たれたかで判定する。
|
|
46
|
+
*
|
|
47
|
+
* 名前が欠ければ、その原pathをimportしている外部が壊れる。増えるだけなら既存の消費者は
|
|
48
|
+
* 影響を受けないので、欠落だけを違反とする。
|
|
49
|
+
*/
|
|
50
|
+
export function compareExportSurface({ before, after } = {}) {
|
|
51
|
+
const original = readExportSurface(before);
|
|
52
|
+
const residual = new Set(readExportSurface(after));
|
|
53
|
+
const missing = original.filter((name) => !residual.has(name));
|
|
54
|
+
return { preserved: missing.length === 0, missing };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 変換後のwitness setを作る。
|
|
59
|
+
*
|
|
60
|
+
* 所有面へ移ったtaskは、その新pathを所有し書き込む。宣言は移動先を指すよう写し、
|
|
61
|
+
* 中身の意味は変えない——ここで新しい所有を発明すると、判定が実態から外れる。
|
|
62
|
+
*/
|
|
63
|
+
export function buildPostTransformWitnessSet({ witnessSet, candidate, affectedTestsByPath } = {}) {
|
|
64
|
+
const owned = (candidate?.surfaces ?? []).filter(({ role }) => role === 'task_owned');
|
|
65
|
+
if (owned.length === 0) return { witnessSet: null, reasons: ['no_owned_surface'] };
|
|
66
|
+
const next = structuredClone(witnessSet);
|
|
67
|
+
const reasons = [];
|
|
68
|
+
for (const [index, surface] of owned.entries()) {
|
|
69
|
+
const taskId = surface.owner_task_ids[0];
|
|
70
|
+
const witness = next?.manual_witness?.[taskId];
|
|
71
|
+
if (witness === undefined) { reasons.push(`witness_missing:${taskId}`); continue; }
|
|
72
|
+
const affected = affectedTestsByPath?.[surface.path];
|
|
73
|
+
if (!Array.isArray(affected)) { reasons.push(`affected_tests_missing:${surface.path}`); continue; }
|
|
74
|
+
witness.owns = [{ kind: 'path', target: surface.path }];
|
|
75
|
+
witness.writes = [surface.path];
|
|
76
|
+
witness.affected_tests = sortedUnique(affected);
|
|
77
|
+
if (Array.isArray(witness.concern_anchors)) {
|
|
78
|
+
witness.concern_anchors = witness.concern_anchors
|
|
79
|
+
.filter((entry) => entry.within.target === candidate.source_path)
|
|
80
|
+
.map((entry) => ({ ...entry, within: { kind: 'path', target: surface.path } }));
|
|
81
|
+
}
|
|
82
|
+
// 宣言だけ移して観測の裏付けを旧pathに残すと、宣言と証拠が別の資源を指す。
|
|
83
|
+
// query setとprovenanceも移動先へ揃える。
|
|
84
|
+
const queryId = `seam-post-${String(index).padStart(3, '0')}`;
|
|
85
|
+
witness.sensor_provenance = {
|
|
86
|
+
queries: [{ query_id: queryId, expect: { kind: 'affected', path: surface.path } }],
|
|
87
|
+
};
|
|
88
|
+
if (Array.isArray(next.sensor_query_set?.queries)) {
|
|
89
|
+
next.sensor_query_set.queries = next.sensor_query_set.queries
|
|
90
|
+
.filter((query) => query.id !== queryId)
|
|
91
|
+
.concat([{ id: queryId, operation: 'affected', target: surface.path }]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (reasons.length > 0) return { witnessSet: null, reasons: sortedUnique(reasons) };
|
|
95
|
+
if (Array.isArray(next.sensor_query_set?.queries)) {
|
|
96
|
+
next.sensor_query_set.queries.sort((left, right) => compareText(left.id, right.id));
|
|
97
|
+
}
|
|
98
|
+
// 宣言を書き換えた以上、自己digestを取り直す。古いまま出すと契約が拒否する。
|
|
99
|
+
next.witness_set_digest = '';
|
|
100
|
+
next.witness_set_digest = todoSelfDigest(next, 'witness_set_digest');
|
|
101
|
+
return { witnessSet: next, reasons: [] };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 競合graphから最小実行段階数を求める。既存のschedulability compilerへ載せる。
|
|
106
|
+
*
|
|
107
|
+
* 独自の近似を持たない。変換前後を同じ規則で測らないと、改善したという主張が
|
|
108
|
+
* 測り方の差で出てしまう。
|
|
109
|
+
*/
|
|
110
|
+
export function measureWaveCount({ taskIds, conflictPairs, executors } = {}) {
|
|
111
|
+
const todos = sortedUnique(taskIds ?? []);
|
|
112
|
+
if (todos.length === 0) return { waves: null, reason: 'no_todos' };
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
const conflicts = [];
|
|
115
|
+
for (const pair of conflictPairs ?? []) {
|
|
116
|
+
const [left, right] = [...pair].sort(compareText);
|
|
117
|
+
if (left === right || !todos.includes(left) || !todos.includes(right)) continue;
|
|
118
|
+
const key = `${left}\u0000${right}`;
|
|
119
|
+
if (seen.has(key)) continue;
|
|
120
|
+
seen.add(key);
|
|
121
|
+
conflicts.push({ todo_ids: [left, right], resource_id: `pair-${conflicts.length}` });
|
|
122
|
+
}
|
|
123
|
+
const compiled = compileSchedulabilityGraphV2({
|
|
124
|
+
schema_version: GRAPH_SCHEMA,
|
|
125
|
+
todos,
|
|
126
|
+
conflicts,
|
|
127
|
+
precedences: [],
|
|
128
|
+
unknowns: [],
|
|
129
|
+
capacity: Number.isSafeInteger(executors) && executors >= 1 ? executors : 1,
|
|
130
|
+
});
|
|
131
|
+
if (compiled.outcome !== 'compiled') {
|
|
132
|
+
return { waves: null, reason: compiled.code ?? compiled.outcome };
|
|
133
|
+
}
|
|
134
|
+
return { waves: compiled.plan.minimum_feasible_waves, reason: null };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const CONDITIONS = Object.freeze([
|
|
138
|
+
'behavior_equivalent',
|
|
139
|
+
'focused_tests_passed',
|
|
140
|
+
'sensor_fresh',
|
|
141
|
+
'overlap_reduced',
|
|
142
|
+
'parallelism_improved',
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 五条件を判定する。1つでも欠けたら`rejected`で、欠けた条件を残す。
|
|
147
|
+
*
|
|
148
|
+
* @param {object} options
|
|
149
|
+
* @param {{preserved: boolean, missing: string[]}} options.exportSurface 公開面の比較
|
|
150
|
+
* @param {boolean} options.focusedTestsPassed 変換後worktreeでのfocused test結果
|
|
151
|
+
* @param {boolean} options.sensorFresh 変換後の再indexが新pathを収載したか
|
|
152
|
+
* @param {{targetResolved: boolean, before: number, after: number}} options.conflictPairs 競合対の増減
|
|
153
|
+
* @param {{before: number|null, after: number|null}} options.waves 実行段階数の増減
|
|
154
|
+
*/
|
|
155
|
+
export function evaluateSeamVerification(options = {}) {
|
|
156
|
+
const {
|
|
157
|
+
exportSurface, focusedTestsPassed, sensorFresh, conflictPairs, waves,
|
|
158
|
+
} = options;
|
|
159
|
+
const detail = {};
|
|
160
|
+
const failures = [];
|
|
161
|
+
|
|
162
|
+
detail.behavior_equivalent = exportSurface?.preserved === true;
|
|
163
|
+
if (!detail.behavior_equivalent) {
|
|
164
|
+
failures.push(`behavior_equivalent:${(exportSurface?.missing ?? []).join(',') || 'unknown'}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
detail.focused_tests_passed = focusedTestsPassed === true;
|
|
168
|
+
if (!detail.focused_tests_passed) failures.push('focused_tests_passed');
|
|
169
|
+
|
|
170
|
+
detail.sensor_fresh = sensorFresh === true;
|
|
171
|
+
if (!detail.sensor_fresh) failures.push('sensor_fresh');
|
|
172
|
+
|
|
173
|
+
// 対象競合が消えたことと、plan全体の競合対が増えていないことの両方を見る(ADR 0138)。
|
|
174
|
+
// componentだけを見ると、切った先で作った共有面が別の作業対の係争資源になっても通る。
|
|
175
|
+
const targetResolved = conflictPairs?.targetResolved === true;
|
|
176
|
+
const before = conflictPairs?.before;
|
|
177
|
+
const after = conflictPairs?.after;
|
|
178
|
+
const counted = Number.isSafeInteger(before) && Number.isSafeInteger(after);
|
|
179
|
+
detail.overlap_reduced = targetResolved && counted && after <= before;
|
|
180
|
+
if (!detail.overlap_reduced) {
|
|
181
|
+
failures.push(!targetResolved ? 'overlap_reduced:target_conflict_remains'
|
|
182
|
+
: !counted ? 'overlap_reduced:pair_count_unknown'
|
|
183
|
+
: `overlap_reduced:pairs_increased:${before}->${after}`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 競合が消えても波数が変わらないなら、その変換は並列化を解放していない。
|
|
187
|
+
const wavesBefore = waves?.before;
|
|
188
|
+
const wavesAfter = waves?.after;
|
|
189
|
+
const measured = Number.isSafeInteger(wavesBefore) && Number.isSafeInteger(wavesAfter);
|
|
190
|
+
detail.parallelism_improved = measured && wavesAfter < wavesBefore;
|
|
191
|
+
if (!detail.parallelism_improved) {
|
|
192
|
+
failures.push(measured ? `parallelism_improved:no_gain:${wavesBefore}->${wavesAfter}`
|
|
193
|
+
: 'parallelism_improved:waves_unknown');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
decision: failures.length === 0 ? 'accepted' : 'rejected',
|
|
198
|
+
conditions: Object.fromEntries(CONDITIONS.map((name) => [name, detail[name] === true])),
|
|
199
|
+
failures: sortedUnique(failures),
|
|
200
|
+
};
|
|
201
|
+
}
|
package/src/todo-cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
3
|
import {
|
|
4
|
-
lstat, mkdir, open, readFile, realpath, rename, rm,
|
|
4
|
+
lstat, mkdir, open, readFile, realpath, rename, rm, writeFile,
|
|
5
5
|
} from 'node:fs/promises';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { parseTree } from 'jsonc-parser';
|
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
validateSeamProposalProjection,
|
|
85
85
|
} from './seam-proposal-contracts.mjs';
|
|
86
86
|
import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
|
|
87
|
+
import { applySeamProposal } from './seam-apply.mjs';
|
|
87
88
|
import {
|
|
88
89
|
parseTodoSourceRef, todoLegacyReconciliationDigest, validatePhaseTodoRevision,
|
|
89
90
|
validateTodoRevision, validateTodoRevisionSet,
|
|
@@ -936,6 +937,91 @@ async function seamProposalCompile({ repoRoot, planKey }) {
|
|
|
936
937
|
return result;
|
|
937
938
|
}
|
|
938
939
|
|
|
940
|
+
/**
|
|
941
|
+
* 着地時に使うsurface名。提案が出すhash由来の仮名を、人が読む名前へ置き換える。
|
|
942
|
+
*
|
|
943
|
+
* 名前を付けるのは判断なので製品が発明しない(AGENTS.md「装置の境界」)。与えられた名前は
|
|
944
|
+
* 導出の入力として最初から使う——後から改名すると、生成済みのimport指定子が旧名を指す。
|
|
945
|
+
*/
|
|
946
|
+
async function readSeamPathNames(repoRoot, inputRef) {
|
|
947
|
+
const value = await readJsonInput(repoRoot, inputRef, {
|
|
948
|
+
validate: (candidate) => candidate !== null && typeof candidate === 'object'
|
|
949
|
+
&& !Array.isArray(candidate)
|
|
950
|
+
&& candidate.schema === 'lattice.seam_path_names.v1'
|
|
951
|
+
&& typeof candidate.names === 'object' && candidate.names !== null
|
|
952
|
+
&& !Array.isArray(candidate.names)
|
|
953
|
+
&& Object.entries(candidate.names)
|
|
954
|
+
.every(([key, target]) => isTodoIdentifier(key) && isTodoRef(target)),
|
|
955
|
+
invalidCode: 'SEAM_PATH_NAMES_INVALID',
|
|
956
|
+
});
|
|
957
|
+
return value.names;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* 記録済みseam提案を隔離worktreeで適用し、五条件で採否を決める(ADR 0137・0138)。
|
|
962
|
+
*
|
|
963
|
+
* 本repositoryは変更しない。採用された変換の着地は別入口が持つ——検証と着地を同じ操作に
|
|
964
|
+
* すると、五条件を満たさない変換が「途中まで着地した」状態を作りうる。
|
|
965
|
+
*/
|
|
966
|
+
async function seamProposalApply({ repoRoot, planKey, pathNames = {}, land = false }) {
|
|
967
|
+
const store = await readTodoStore({ repoRoot });
|
|
968
|
+
const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
|
|
969
|
+
if (!member) {
|
|
970
|
+
throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
|
|
971
|
+
}
|
|
972
|
+
const artifact = await readTodoSeamProposalArtifact({ repoRoot, store, planKey });
|
|
973
|
+
if (artifact === null) {
|
|
974
|
+
throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'seam_proposal_absent', undefined, {
|
|
975
|
+
plan_key: planKey, next_action: 'compile_seam_proposal',
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
const witnessSet = await readTodoWitnessSet({ repoRoot, planKey });
|
|
979
|
+
if (witnessSet === null) {
|
|
980
|
+
throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'witness_set_absent', undefined, {
|
|
981
|
+
plan_key: planKey, next_action: 'declare_witness_set_then_compile_independence',
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
const baseArtifact = await readTodoIndependenceArtifact({ repoRoot, store, planKey });
|
|
985
|
+
const { outcome: result, files } = await applySeamProposal({
|
|
986
|
+
repoRoot,
|
|
987
|
+
planKey,
|
|
988
|
+
pathNames,
|
|
989
|
+
sourceProposal: artifact,
|
|
990
|
+
witnessSet,
|
|
991
|
+
latticeBin: path.join(repoRoot, 'bin', 'lattice.mjs'),
|
|
992
|
+
sharedPathFor: (sourcePath) => sourcePath.replace(/(\.[^./]+)$/u, '.seam-shared$1'),
|
|
993
|
+
executors: witnessSet.capacity.executors,
|
|
994
|
+
compileIndependence: {
|
|
995
|
+
baseArtifact,
|
|
996
|
+
// 変換後のworktreeで、写した宣言と再indexした索引から実compileする。
|
|
997
|
+
// 仮想再compileの再実行では、実ソースで残余0である証拠にならない(ADR 0137 Decision 4)。
|
|
998
|
+
inWorktree: async ({ worktreePath, witnessSet: postWitness }) => compileTodoIndependence({
|
|
999
|
+
witnessSet: postWitness,
|
|
1000
|
+
plan: member.plan,
|
|
1001
|
+
baseSha: artifact.source_binding.base_sha,
|
|
1002
|
+
compiledAt: new Date().toISOString(),
|
|
1003
|
+
sensorEvidence: await collectWitnessSensorEvidence({
|
|
1004
|
+
cwd: worktreePath, witnessSet: postWitness,
|
|
1005
|
+
}),
|
|
1006
|
+
}),
|
|
1007
|
+
},
|
|
1008
|
+
});
|
|
1009
|
+
if (!land) return result;
|
|
1010
|
+
// 着地は採用された変換だけへ。検証と着地を同じ操作にしないのは、五条件を満たさない変換が
|
|
1011
|
+
// 途中まで着地した状態を作らないためである(ADR 0137)。
|
|
1012
|
+
if (result.decision !== 'accepted' || files === null) {
|
|
1013
|
+
return { ...result, landed: false, landed_paths: [] };
|
|
1014
|
+
}
|
|
1015
|
+
const landed = [];
|
|
1016
|
+
for (const [target, text] of Object.entries(files)) {
|
|
1017
|
+
const absolute = path.join(repoRoot, target);
|
|
1018
|
+
await mkdir(path.dirname(absolute), { recursive: true });
|
|
1019
|
+
await writeFile(absolute, text);
|
|
1020
|
+
landed.push(target);
|
|
1021
|
+
}
|
|
1022
|
+
return { ...result, landed: true, landed_paths: landed.sort() };
|
|
1023
|
+
}
|
|
1024
|
+
|
|
939
1025
|
function summarizeSeamProposalDecision(decision) {
|
|
940
1026
|
return {
|
|
941
1027
|
component_id: decision.component_id,
|
|
@@ -1637,6 +1723,18 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env
|
|
|
1637
1723
|
&& argv[1] === '--plan' && isTodoIdentifier(argv[2])
|
|
1638
1724
|
&& (argv.length === 3 || argv[3] === '--json')) {
|
|
1639
1725
|
action = (repoRoot) => independence({ repoRoot, requestedPlanKey: argv[2] });
|
|
1726
|
+
} else if (argv.length === 4 && argv[0] === 'seam-proposal' && argv[1] === 'apply'
|
|
1727
|
+
&& argv[2] === '--plan' && isTodoIdentifier(argv[3])) {
|
|
1728
|
+
action = (repoRoot) => seamProposalApply({ repoRoot, planKey: argv[3] });
|
|
1729
|
+
} else if (argv.length === 6 && argv[0] === 'seam-proposal' && argv[1] === 'land'
|
|
1730
|
+
&& argv[2] === '--plan' && isTodoIdentifier(argv[3])
|
|
1731
|
+
&& argv[4] === '--names' && isTodoRef(argv[5])) {
|
|
1732
|
+
action = async (repoRoot) => seamProposalApply({
|
|
1733
|
+
repoRoot,
|
|
1734
|
+
planKey: argv[3],
|
|
1735
|
+
pathNames: await readSeamPathNames(repoRoot, argv[5]),
|
|
1736
|
+
land: true,
|
|
1737
|
+
});
|
|
1640
1738
|
} else if (argv.length === 4 && argv[0] === 'seam-proposal' && argv[1] === 'compile'
|
|
1641
1739
|
&& argv[2] === '--plan' && isTodoIdentifier(argv[3])) {
|
|
1642
1740
|
action = (repoRoot) => seamProposalCompile({ repoRoot, planKey: argv[3] });
|
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 図の外が語るための独立性要約を、plan単位の投影から引ける形へ畳む(ADR 0129 Decision 3)。
|
|
5
|
+
*/
|
|
6
|
+
export function summarizeIndependence(layout) {
|
|
7
|
+
if (layout.independence === null) return null;
|
|
8
|
+
const byPlan = new Map(layout.independence.plans.map((plan) => [plan.plan_key, plan]));
|
|
9
|
+
return {
|
|
10
|
+
plans: layout.independence.plans,
|
|
11
|
+
byPlan,
|
|
12
|
+
verifiedTaskCount: layout.independence.plans
|
|
13
|
+
.reduce((total, plan) => total + plan.verified_task_count, 0),
|
|
14
|
+
unknownTaskCount: layout.independence.plans
|
|
15
|
+
.reduce((total, plan) => total + plan.unknown_task_ids.length, 0),
|
|
16
|
+
serializePairCount: layout.independence.plans
|
|
17
|
+
.reduce((total, plan) => total + plan.serialize_pairs.length, 0),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 記録が無いときだけADR 0063の既定をそのまま述べる。 */
|
|
22
|
+
export function dispatchBasis(summary) {
|
|
23
|
+
if (summary === null) {
|
|
24
|
+
return 'ready frontier全件が既定です。一部だけを直列着手する場合は理由が必要です。';
|
|
25
|
+
}
|
|
26
|
+
const parts = [`検証済み並列 ${summary.verifiedTaskCount}工程`];
|
|
27
|
+
if (summary.serializePairCount > 0) parts.push(`要直列 ${summary.serializePairCount}組`);
|
|
28
|
+
if (summary.unknownTaskCount > 0) parts.push(`未検査 ${summary.unknownTaskCount}工程`);
|
|
29
|
+
return `${parts.join('、')}。未検査は依存線が無くても並列可の根拠になりません。`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 個別ToDoについて、競合相手と切断可能性を言葉で示す。 */
|
|
33
|
+
export function renderIndependenceNote(ref, node, summary) {
|
|
34
|
+
if (summary === null || node === undefined) return '';
|
|
35
|
+
const plan = summary.byPlan.get(ref.plan_key);
|
|
36
|
+
if (plan === undefined) return '';
|
|
37
|
+
const taskId = ref.task_id;
|
|
38
|
+
const state = node.visibility.independence;
|
|
39
|
+
if (state === null) return '';
|
|
40
|
+
if (state === 'verified') {
|
|
41
|
+
return '<p class="readiness-note"><strong>並列可否:</strong> 独立検証済です。記録時点の宣言境界では他のready工程と干渉しません。</p>';
|
|
42
|
+
}
|
|
43
|
+
if (state === 'unknown') {
|
|
44
|
+
return '<p class="readiness-note"><strong>並列可否:</strong> 未検査です。競合が無いのではなく、まだ判定していません。</p>';
|
|
45
|
+
}
|
|
46
|
+
const pairs = [
|
|
47
|
+
...plan.serialize_pairs
|
|
48
|
+
.filter((pair) => pair.task_ids.includes(taskId))
|
|
49
|
+
.map((pair) => ({
|
|
50
|
+
other: pair.task_ids.find((id) => id !== taskId),
|
|
51
|
+
severability: pair.severability,
|
|
52
|
+
detail: pair.detail,
|
|
53
|
+
})),
|
|
54
|
+
...plan.conflicts_with_active
|
|
55
|
+
.filter((entry) => entry.ready_task_id === taskId)
|
|
56
|
+
.map((entry) => ({
|
|
57
|
+
other: `${entry.active_task_id}(作業中)`,
|
|
58
|
+
severability: entry.severability,
|
|
59
|
+
detail: entry.detail,
|
|
60
|
+
})),
|
|
61
|
+
];
|
|
62
|
+
const items = pairs.map((pair) => `<li>${escapeHtmlText(pair.other)} — ${escapeHtmlText(SEVERABILITY_LABEL[pair.severability] ?? pair.severability)}(資源 ${escapeHtmlText(pair.detail)})</li>`).join('');
|
|
63
|
+
return `<p class="readiness-note"><strong>並列可否:</strong> 要直列です。</p><ul class="independence-conflicts">${items}</ul>`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function renderRightPane(sections, layout, presentation, readModel) {
|
|
67
|
+
const lookup = presentationLookup(presentation);
|
|
68
|
+
const sectionByKey = new Map(sections.map((section) => [refKey(section.ref), section]));
|
|
69
|
+
const nodeByKey = new Map(layout.nodes.map((node) => [refKey(node.ref), node]));
|
|
70
|
+
const folds = foldIndex(layout);
|
|
71
|
+
const incoming = new Map(sections.map((section) => [refKey(section.ref), []]));
|
|
72
|
+
const outgoing = new Map(sections.map((section) => [refKey(section.ref), []]));
|
|
73
|
+
const addRelation = (relations, ownerKey, ref, joinIds) => {
|
|
74
|
+
const entries = relations.get(ownerKey);
|
|
75
|
+
if (entries === undefined) return;
|
|
76
|
+
let entry = entries.find((candidate) => refKey(candidate.ref) === refKey(ref));
|
|
77
|
+
if (entry === undefined) {
|
|
78
|
+
entry = { ref, joinIds: [] };
|
|
79
|
+
entries.push(entry);
|
|
80
|
+
}
|
|
81
|
+
entry.joinIds = [...new Set([...entry.joinIds, ...joinIds])].sort();
|
|
82
|
+
};
|
|
83
|
+
// Premises and successors come from the FULL graph. `layout.edges` is the
|
|
84
|
+
// drawn graph, where a fold unit's interior dependencies have been contracted
|
|
85
|
+
// away — reading those here would tell a folded ToDo it has no premises.
|
|
86
|
+
for (const edge of layout.full_edges ?? layout.edges) {
|
|
87
|
+
addRelation(incoming, refKey(edge.to), edge.from, edge.join_ids);
|
|
88
|
+
addRelation(outgoing, refKey(edge.from), edge.to, edge.join_ids);
|
|
89
|
+
}
|
|
90
|
+
const counts = { pending: 0, 'in-progress': 0, blocked: 0, done: 0 };
|
|
91
|
+
for (const section of sections) counts[section.state.status] += 1;
|
|
92
|
+
const active = sections.filter((section) => section.state.status === 'in-progress');
|
|
93
|
+
const ready = layout.nodes.filter((node) => node.visibility.next_ready);
|
|
94
|
+
const independenceSummary = summarizeIndependence(layout);
|
|
95
|
+
const readyHeadline = ready.length > 1
|
|
96
|
+
? `<p class="readiness-note"><strong>同時dispatch推奨:</strong> ${ready.length}工程。${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`
|
|
97
|
+
: ready.length === 1
|
|
98
|
+
? '<p class="readiness-note"><strong>着手候補:</strong> 1工程です。</p>'
|
|
99
|
+
: '<p class="readiness-note">現在のready frontierは空です。</p>';
|
|
100
|
+
// ready件数によらず、記録があるなら内訳を述べる。1件の時だけ黙ると、
|
|
101
|
+
// その1件が未検査でも「候補が1つある」としか伝わらない。
|
|
102
|
+
const independenceNote = independenceSummary === null || ready.length > 1 ? ''
|
|
103
|
+
: `<p class="readiness-note"><strong>並列可否:</strong> ${escapeHtmlText(dispatchBasis(independenceSummary))}</p>`;
|
|
104
|
+
const dispatchSummary = `${readyHeadline}${independenceNote}`;
|
|
105
|
+
const activeLinks = active.length === 0 ? '<p>作業中の工程はありません。</p>'
|
|
106
|
+
: `<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>`;
|
|
107
|
+
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>${dispatchSummary}${renderSeamProposalOverview(layout)}${renderPhaseProgress(readModel)}<h2>作業中</h2>${activeLinks}</section>`;
|
|
108
|
+
const details = sections.map((section) => {
|
|
109
|
+
const key = refKey(section.ref);
|
|
110
|
+
const node = nodeByKey.get(key);
|
|
111
|
+
const status = DOCUMENT_STATUS[section.state.status] ?? { mark: '?', label: '状態不明' };
|
|
112
|
+
const lane = lookup.lanes.get(JSON.stringify([section.ref.plan_key, section.task.lane]));
|
|
113
|
+
const category = lane === undefined ? section.task.lane : `${section.task.lane} — ${lane.name}`;
|
|
114
|
+
const categoryDescription = lane === undefined ? '' : `<p class="category-description">${escapeHtmlText(lane.description)}</p>`;
|
|
115
|
+
const blockedReason = section.state.status === 'blocked'
|
|
116
|
+
? `<p><strong>ブロック理由:</strong> ${escapeHtmlText(section.state.blocked_reason ?? '理由未記録')}</p>` : '';
|
|
117
|
+
const sourceLine = section.anchorOutcome.origin_line === null ? '' : `:${section.anchorOutcome.origin_line}`;
|
|
118
|
+
const sourceRef = section.narrativeRef ?? '参照なし';
|
|
119
|
+
const anchorText = section.anchorOutcome.anchored
|
|
120
|
+
? `元plan: ${sourceRef}${sourceLine} — 行対応を確認済み`
|
|
121
|
+
: `元plan: ${sourceRef}${sourceLine} — 行対応を確認できないため、本文位置との対応は表示していません`;
|
|
122
|
+
const readiness = node?.visibility.next_ready
|
|
123
|
+
? `<p class="readiness-note">ready frontierの一員です。${ready.length > 1 ? '他のready工程と同時着手できるかは下の並列可否で判断してください。' : '現在の唯一の着手候補です。'}</p>`
|
|
124
|
+
: incoming.get(key).length === 0 ? '<p class="readiness-note">登録済みの前提工程はありません。図だけではdispatch可否を判定しません。</p>' : '';
|
|
125
|
+
const independenceNote = renderIndependenceNote(section.ref, node, independenceSummary);
|
|
126
|
+
// Say it plainly when the reader will not find this ToDo on the diagram.
|
|
127
|
+
const foldedNote = !folds.has(key) ? ''
|
|
128
|
+
: '<p class="fold-note">完走済みのため図には描いていません。図に出すには <code>lattice todo gantt --scope all</code> を実行してください。</p>';
|
|
129
|
+
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}<section><h2>前提工程</h2>${renderRelationList(incoming.get(key), sectionByKey, lookup, '登録済みの前提工程はありません。', folds)}</section><section><h2>後続工程</h2>${renderRelationList(outgoing.get(key), sectionByKey, lookup, '登録済みの後続工程はありません。', folds)}</section><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>`;
|
|
130
|
+
}).join('');
|
|
131
|
+
const taskIndex = renderTaskIndex(sections, lookup, folds, planActivity(readModel));
|
|
132
|
+
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>`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function renderDiagramLegend(presentation, layout = null, expandable = false) {
|
|
136
|
+
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('');
|
|
137
|
+
const categoryDetails = categories === '' ? '' : `<details class="category-legend"><summary>カテゴリ説明</summary><dl>${categories}</dl></details>`;
|
|
138
|
+
const foldedCount = layout?.scope?.folded_task_count ?? 0;
|
|
139
|
+
// The badge says what is missing from the diagram, so it is also the control
|
|
140
|
+
// that brings it back — a reader who notices the count is exactly the reader
|
|
141
|
+
// who wants to see it.
|
|
142
|
+
const foldChip = foldedCount === 0 ? ''
|
|
143
|
+
: expandable
|
|
144
|
+
? `<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>`
|
|
145
|
+
: `<span class="fold-chip">完走済み ${foldedCount}件を非表示</span>`;
|
|
146
|
+
const foldNote = foldedCount === 0 ? ''
|
|
147
|
+
: expandable
|
|
148
|
+
? '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。上のバッジを押すと外した工程も含めて描きます。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>'
|
|
149
|
+
: '<p class="fold-note">後続に作業中・未着手が残っていない完了工程は図から外しています。生きた工程とその直接の前提工程は必ず描きます。外した工程は右の「全工程」から辿れ、図に出すには <code>lattice todo gantt --scope all</code> を実行してください。総数・進捗・最長依存鎖は外す前の全工程で数えています。</p>';
|
|
150
|
+
const independenceLegend = layout.independence === null ? ''
|
|
151
|
+
: '<span>∥ 独立検証済</span><span>⛓ 要直列</span><span>? 未検査</span>';
|
|
152
|
+
// 独立性の記録がある間は「全件同時dispatchが既定」と無条件に述べない(ADR 0129 Decision 3)。
|
|
153
|
+
const dispatchSentence = layout.independence === null
|
|
154
|
+
? 'ready frontierは全件同時dispatchが既定です。未登録の資源・host制約によりsubsetだけを選ぶ場合は理由を記録します。'
|
|
155
|
+
: '同時着手できるかはカードの並列可否で判断してください。未検査の工程は依存線が無くても並列可の根拠になりません。';
|
|
156
|
+
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>`;
|
|
157
|
+
}
|