@quolu/lattice 0.83.0 → 0.84.1
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/README.ja.md +7 -6
- package/README.md +1 -1
- package/bin/lattice.mjs +29 -22
- package/docs/schemas/lattice.plan_create_input.v4.schema.json +5 -11
- package/docs/schemas/lattice.plan_create_input.v5.schema.json +37 -50
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +36 -12
- package/package.json +1 -1
- package/sensor/dist/mcp/daemon-paths.d.ts +6 -0
- package/sensor/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/sensor/dist/mcp/daemon-paths.js +7 -1
- package/sensor/dist/mcp/daemon-paths.js.map +1 -1
- package/src/cli-help.mjs +9 -7
- package/src/cli-refusal-guidance.mjs +354 -0
- package/src/dashboard-delivery.mjs +2 -1
- package/src/hooks-cli.mjs +30 -6
- package/src/plan-backchain.mjs +70 -33
- package/src/plan-revise.mjs +153 -52
- package/src/project-cli.mjs +279 -163
- package/src/runtime-cli.mjs +7 -11
- package/src/runtime-pull-intake.mjs +4 -2
- package/src/todo-authoring-input.mjs +167 -5
- package/src/todo-cli.mjs +416 -188
- package/src/todo-dashboard-registry.mjs +4 -2
- package/src/todo-gantt-display.mjs +1 -2
- package/src/todo-gantt-html-independence.mjs +2 -2
- package/src/todo-gantt-html-shared.mjs +14 -0
- package/src/todo-gantt-html.mjs +73 -54
- package/src/todo-gantt-layout.mjs +134 -27
- package/src/todo-independence-guidance.mjs +4 -26
- package/src/todo-readiness.mjs +57 -15
- package/src/todo-revision.mjs +147 -0
- package/src/todo-status.mjs +100 -57
- package/src/todo-store-view.mjs +2 -3
- package/src/todo-store.mjs +31 -292
package/src/todo-readiness.mjs
CHANGED
|
@@ -26,12 +26,15 @@ export function createTodoReadiness(store) {
|
|
|
26
26
|
const { plan } = member;
|
|
27
27
|
const states = new Map(member.tasks.map((state) => [state.task_id, state]));
|
|
28
28
|
const phaseStates = new Map((member.phases ?? []).map((phase) => [phase.phase_id, phase.status]));
|
|
29
|
-
for (const phase of member.phases ?? [])
|
|
29
|
+
for (const phase of member.phases ?? []) {
|
|
30
|
+
phases.set(phaseKey({ ...plan, ...phase }), { plan_key: plan.plan_key, phase_id: phase.phase_id, status: phase.status });
|
|
31
|
+
}
|
|
30
32
|
for (const task of plan.tasks) {
|
|
31
33
|
const key = taskKey({ ...plan, ...task });
|
|
32
34
|
nodes.set(key, {
|
|
33
35
|
status: states.get(task.task_id)?.status,
|
|
34
|
-
|
|
36
|
+
task_id: task.task_id,
|
|
37
|
+
// retiredは先行として完了扱い(u12/a13)。判定はStore replayと同じ一つの述語。
|
|
35
38
|
finished: isFinishedTodoTaskState(states.get(task.task_id)),
|
|
36
39
|
schema: plan.schema,
|
|
37
40
|
plan_key: plan.plan_key,
|
|
@@ -80,21 +83,36 @@ export function createTodoReadiness(store) {
|
|
|
80
83
|
// u03 A24: 消えた端点(Storeのendpoint_missing finding)は後続を止めない。Store replayも同じ規則。
|
|
81
84
|
const predecessors = [...(incoming.get(key) ?? [])].map((source) => nodes.get(source))
|
|
82
85
|
.filter((node) => node !== undefined);
|
|
83
|
-
const
|
|
84
|
-
const
|
|
86
|
+
const unfinished = predecessors.filter((node) => node.finished !== true);
|
|
87
|
+
const unreadyPhases = predecessors.filter((node) => !dependencyPhaseReady(node, nodes.get(key)));
|
|
88
|
+
const predecessorsDone = unfinished.length === 0;
|
|
89
|
+
const predecessorPhasesReady = unreadyPhases.length === 0;
|
|
85
90
|
const taskDependenciesDone = predecessorsDone && predecessorPhasesReady;
|
|
86
|
-
const
|
|
87
|
-
.
|
|
91
|
+
const unacceptedEdges = [...(acceptanceIncoming.get(key) ?? [])]
|
|
92
|
+
.map((source) => phases.get(source)).filter((phase) => phase !== undefined && phase.status !== 'accepted');
|
|
93
|
+
const phaseAcceptReady = unacceptedEdges.length === 0;
|
|
94
|
+
const cause = !phaseAcceptReady ? 'acceptance_edge'
|
|
95
|
+
: !predecessorsDone ? 'predecessor_unfinished'
|
|
96
|
+
: !predecessorPhasesReady ? 'acceptance_edge' : null;
|
|
97
|
+
const blockingPhases = !phaseAcceptReady ? unacceptedEdges
|
|
98
|
+
: unreadyPhases.map((node) => ({ plan_key: node.plan_key, phase_id: node.phase_id, status: node.phase_status }));
|
|
88
99
|
return {
|
|
89
100
|
taskDependenciesDone,
|
|
90
101
|
phaseAcceptReady,
|
|
91
102
|
dependenciesDone: taskDependenciesDone && phaseAcceptReady,
|
|
92
|
-
cause
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
cause,
|
|
104
|
+
// a12: a refusal names what blocks, not only why.
|
|
105
|
+
blocking: cause === 'predecessor_unfinished'
|
|
106
|
+
? { blocking_tasks: unfinished.map(({ plan_key, task_id, status }) => ({ plan_key, task_id, status })).sort(byRef) }
|
|
107
|
+
: cause === 'acceptance_edge'
|
|
108
|
+
? { blocking_phases: uniqueRefs(blockingPhases).map((phase) => ({ ...phase })).sort(byRef) } : {},
|
|
95
109
|
};
|
|
96
110
|
}
|
|
97
111
|
|
|
112
|
+
function ownPhaseStatus(key) {
|
|
113
|
+
return nodes.get(key)?.phase_status;
|
|
114
|
+
}
|
|
115
|
+
|
|
98
116
|
function ownPhaseReady(key) {
|
|
99
117
|
const node = nodes.get(key);
|
|
100
118
|
return node?.schema !== 'lattice.todo_plan.v4' || node.phase_status === 'active';
|
|
@@ -109,19 +127,35 @@ export function createTodoReadiness(store) {
|
|
|
109
127
|
status: (key) => nodes.get(key)?.status,
|
|
110
128
|
prerequisites,
|
|
111
129
|
ownPhaseReady,
|
|
130
|
+
ownPhaseStatus,
|
|
112
131
|
isReady: (key) => nodes.get(key)?.status === 'pending'
|
|
113
132
|
&& ownPhaseReady(key) && prerequisites(key).dependenciesDone,
|
|
114
133
|
startedSuccessor,
|
|
115
134
|
phaseHasStartedSuccessor: (member, phaseId) => member.plan.schema === 'lattice.todo_plan.v4'
|
|
116
135
|
? member.plan.tasks.filter(({ phase_id }) => phase_id === phaseId)
|
|
117
136
|
.some((task) => startedSuccessor(taskKey({ ...member.plan, ...task })))
|
|
137
|
+
// a12: same rule as Store replay, so this order refusal is not left to replay's STORE_INCONSISTENT.
|
|
138
|
+
|| (phases.get(phaseKey({ ...member.plan, phase_id: phaseId }))?.status === 'accepted'
|
|
139
|
+
&& member.plan.phases.some((phase) => phase.predecessor_phase_ids.includes(phaseId)
|
|
140
|
+
&& (phases.get(phaseKey({ ...member.plan, phase_id: phase.phase_id }))?.status !== 'locked'
|
|
141
|
+
|| member.plan.tasks.some((task) => task.phase_id === phase.phase_id
|
|
142
|
+
&& nodes.get(taskKey({ ...member.plan, ...task }))?.status !== 'pending'))))
|
|
118
143
|
: [...(acceptanceOutgoing.get(phaseKey({ ...member.plan, phase_id: phaseId })) ?? [])]
|
|
119
144
|
.some((key) => nodes.get(key)?.status !== 'pending'),
|
|
120
145
|
};
|
|
121
146
|
}
|
|
122
147
|
|
|
148
|
+
const refId = (ref) => `${ref.plan_key}\0${ref.task_id ?? ref.phase_id}`;
|
|
149
|
+
function byRef(left, right) {
|
|
150
|
+
return refId(left) < refId(right) ? -1 : refId(left) > refId(right) ? 1 : 0;
|
|
151
|
+
}
|
|
152
|
+
function uniqueRefs(refs) {
|
|
153
|
+
return [...new Map(refs.map((ref) => [refId(ref), ref])).values()];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// a12: an order or state rule is not an inconsistency; Store replay keeps STORE_INCONSISTENT for history.
|
|
123
157
|
function refused(reason, cause, detail = {}) {
|
|
124
|
-
return { ok: false, code: '
|
|
158
|
+
return { ok: false, code: 'TODO_TRANSITION_REFUSED', detail: { reason, cause, ...detail } };
|
|
125
159
|
}
|
|
126
160
|
|
|
127
161
|
/** Prospective policy only; Store retains historical replay, evidence and identity validation. */
|
|
@@ -133,10 +167,10 @@ export function validateProspectiveEvent({ store, member, event }) {
|
|
|
133
167
|
&& event.payload.start_mode !== 'rebind';
|
|
134
168
|
if (authoredStart && (!prerequisites.phaseAcceptReady
|
|
135
169
|
|| (!prerequisites.taskDependenciesDone && event.payload.override_reason === null))) {
|
|
136
|
-
return refused('invalid_start_transition', prerequisites.cause);
|
|
170
|
+
return refused('invalid_start_transition', prerequisites.cause, prerequisites.blocking);
|
|
137
171
|
}
|
|
138
172
|
if (event.kind === 'done' && event.payload.done_mode === 'authored' && !prerequisites.dependenciesDone) {
|
|
139
|
-
return refused('invalid_done_transition', prerequisites.cause);
|
|
173
|
+
return refused('invalid_done_transition', prerequisites.cause, prerequisites.blocking);
|
|
140
174
|
}
|
|
141
175
|
if (event.kind === 'reopen' && event.payload.override_reason === null && readiness.startedSuccessor(key)) {
|
|
142
176
|
return refused('reopen_has_started_successor', 'task_state', {
|
|
@@ -150,12 +184,20 @@ export function validateProspectiveEvent({ store, member, event }) {
|
|
|
150
184
|
// Keep merged refusal priority; replay still owns missing target/binding checks.
|
|
151
185
|
const status = readiness.status(key);
|
|
152
186
|
if (authoredStart && status !== undefined) {
|
|
153
|
-
if (status !== 'pending') return refused('invalid_start_transition', 'task_state');
|
|
154
|
-
if (!readiness.ownPhaseReady(key))
|
|
187
|
+
if (status !== 'pending') return refused('invalid_start_transition', 'task_state', { status });
|
|
188
|
+
if (!readiness.ownPhaseReady(key)) {
|
|
189
|
+
return refused('invalid_start_transition', 'phase_state', { phase_status: readiness.ownPhaseStatus(key) });
|
|
190
|
+
}
|
|
155
191
|
}
|
|
156
192
|
if (event.kind === 'done' && event.payload.done_mode === 'authored'
|
|
157
193
|
&& status !== undefined && status !== 'in-progress') {
|
|
158
|
-
return refused('invalid_done_transition', 'task_state');
|
|
194
|
+
return refused('invalid_done_transition', 'task_state', { status });
|
|
195
|
+
}
|
|
196
|
+
if (event.kind === 'block' && status !== undefined && status !== 'in-progress') {
|
|
197
|
+
return refused('invalid_block_transition', 'task_state', { status });
|
|
198
|
+
}
|
|
199
|
+
if (event.kind === 'unblock' && status !== undefined && status !== 'blocked') {
|
|
200
|
+
return refused('invalid_unblock_transition', 'task_state', { status });
|
|
159
201
|
}
|
|
160
202
|
return { ok: true };
|
|
161
203
|
}
|
package/src/todo-revision.mjs
CHANGED
|
@@ -1036,3 +1036,150 @@ export function validateTodoRevisionSet(value) {
|
|
|
1036
1036
|
&& value.revision_set_digest === todoSelfDigest(value, 'revision_set_digest');
|
|
1037
1037
|
} catch { return false; }
|
|
1038
1038
|
}
|
|
1039
|
+
|
|
1040
|
+
const PHASE_PREDECESSOR_SCHEMAS = new Set([
|
|
1041
|
+
'lattice.todo_plan.v4', 'lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8',
|
|
1042
|
+
]);
|
|
1043
|
+
const sourceKey = (entry) => `${entry.source_ref}\0${entry.source_digest}`;
|
|
1044
|
+
|
|
1045
|
+
/** v3: desired在庫が引き継がず・tombstoneにもしない先行の出所(Storeの黙殺検査と同じ判定)を、tombstoneへ足す。 */
|
|
1046
|
+
function completeSourceInventory(inventory, revision, predecessorInventory) {
|
|
1047
|
+
const desiredTombstoneKeys = new Set(inventory.excluded_tombstones.map(sourceKey));
|
|
1048
|
+
const activeRefs = new Set(inventory.active.map(({ source_ref: ref }) => ref));
|
|
1049
|
+
const tombstoneRefs = new Set(inventory.excluded_tombstones.map(({ source_ref: ref }) => ref));
|
|
1050
|
+
const added = [];
|
|
1051
|
+
const add = (entry, reason) => {
|
|
1052
|
+
if (activeRefs.has(entry.source_ref) || tombstoneRefs.has(entry.source_ref)) return;
|
|
1053
|
+
tombstoneRefs.add(entry.source_ref);
|
|
1054
|
+
added.push({ source_ref: entry.source_ref, source_digest: entry.source_digest, exclusion_reason: reason });
|
|
1055
|
+
};
|
|
1056
|
+
for (const entry of predecessorInventory.active) {
|
|
1057
|
+
const active = inventory.active.find(({ task_id: id }) => id === entry.task_id);
|
|
1058
|
+
const continued = active?.source_ref === entry.source_ref && active.source_digest === entry.source_digest;
|
|
1059
|
+
const relocated = revision.source_cutover_batch.operations.some((operation, index) => {
|
|
1060
|
+
if (operation.source_ref !== entry.source_ref || operation.source_digest !== entry.source_digest) return false;
|
|
1061
|
+
const archiveRef = todoCutoverArchiveSourceRef(revision.source_cutover_batch, index);
|
|
1062
|
+
return operation.disposition === 'active'
|
|
1063
|
+
? inventory.active.some((candidate) => candidate.task_id === operation.task_id
|
|
1064
|
+
&& candidate.source_ref === archiveRef && candidate.source_digest === operation.source_digest)
|
|
1065
|
+
: inventory.excluded_tombstones.some((candidate) => candidate.source_ref === archiveRef
|
|
1066
|
+
&& candidate.source_digest === operation.source_digest);
|
|
1067
|
+
});
|
|
1068
|
+
if (!continued && !relocated && !desiredTombstoneKeys.has(sourceKey(entry))) {
|
|
1069
|
+
add(entry, 'dropped from the desired source inventory (machine-completed)');
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
for (const entry of predecessorInventory.excluded_tombstones) {
|
|
1073
|
+
if (!desiredTombstoneKeys.has(sourceKey(entry))) add(entry, entry.exclusion_reason);
|
|
1074
|
+
}
|
|
1075
|
+
return added.length === 0 ? inventory : {
|
|
1076
|
+
...inventory,
|
|
1077
|
+
excluded_tombstones: [...inventory.excluded_tombstones, ...added]
|
|
1078
|
+
.sort((left, right) => compareText(left.source_ref, right.source_ref)),
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 補うphase行の方針。軽量改訂(compileLightPhaseMigration)と同じ規則: 定義が変わったか、
|
|
1084
|
+
* 終わっていない工程を迎える(新規・他Phaseから移る・reset)phaseはreset、それ以外はcarry。
|
|
1085
|
+
* 迎えた未完の工程を、記録済みの受入が覆っているように見せないため(u03p review)。
|
|
1086
|
+
*/
|
|
1087
|
+
function defaultPhaseCarry(member, desired, taskMigration) {
|
|
1088
|
+
const carried = new Set(['carry', 'carry_reconciled_metadata', 'acquire_phase']);
|
|
1089
|
+
const rowByTarget = new Map(taskMigration.map((row) => [row.to_task_id, row]));
|
|
1090
|
+
const previousById = new Map(member.plan.tasks.map((task) => [task.task_id, task]));
|
|
1091
|
+
const states = new Map((member.tasks ?? []).map(({ task_id: id, status }) => [id, status]));
|
|
1092
|
+
const definition = ({ title, gate_policy: gatePolicy, predecessor_phase_ids: predecessors,
|
|
1093
|
+
required_evidence_slots: slots }) => canonicalizeTodoArtifact({
|
|
1094
|
+
title, gate_policy: gatePolicy, predecessor_phase_ids: predecessors, required_evidence_slots: slots });
|
|
1095
|
+
return (phase) => {
|
|
1096
|
+
const next = desired.phases.find(({ phase_id: id }) => id === phase.phase_id);
|
|
1097
|
+
if (definition(phase) !== definition(next)) return false;
|
|
1098
|
+
return !desired.tasks.some((task) => {
|
|
1099
|
+
if (task.phase_id !== phase.phase_id) return false;
|
|
1100
|
+
const row = rowByTarget.get(task.task_id);
|
|
1101
|
+
const reset = row === undefined || !carried.has(row.state_policy);
|
|
1102
|
+
const previous = reset ? undefined : previousById.get(row.from_task_id);
|
|
1103
|
+
const arrives = reset || previous?.phase_id !== phase.phase_id;
|
|
1104
|
+
const state = reset ? 'pending' : states.get(row.from_task_id);
|
|
1105
|
+
return arrives && !['done', 'retired'].includes(state);
|
|
1106
|
+
});
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* revise-phaseの成果物を、新鮮な先行memberに対して機械が補う(u03p A40a/A41)。
|
|
1112
|
+
* 先行taskのtask_migration行が無ければ、desiredに同idがあればcarry(v5はcarry_reconciled_metadata)、
|
|
1113
|
+
* 無ければremoved。phase_migrationも同様(carry/removed、新しいphaseはreset)。v3は先行の出所のうち
|
|
1114
|
+
* desiredが引き継がず・tombstoneにもしないものをexcluded_tombstonesへ足す。足したものが無ければ入力のまま返す。
|
|
1115
|
+
* 補った時は、plan_version・desired_planのdigest・(v3)reconciliation・(v4)chain_digest・revision_digestを
|
|
1116
|
+
* 既存の関数で再計算する。buildPlanはStoreのbuildTodoPlan(循環importを避けて注入する)。
|
|
1117
|
+
*/
|
|
1118
|
+
export function completePhaseTodoRevision(revision, { member, predecessorInventory = null, buildPlan }) {
|
|
1119
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
1120
|
+
const version = /^lattice\.phase_todo_revision\.v([1-5])$/u.exec(revision?.schema ?? '')?.[1];
|
|
1121
|
+
if (version === undefined || !isRecord(revision.desired_plan) || !Array.isArray(revision.task_migration)
|
|
1122
|
+
|| !Array.isArray(revision.phase_migration) || !Array.isArray(revision.desired_plan.tasks)
|
|
1123
|
+
|| !Array.isArray(revision.desired_plan.phases)) return revision;
|
|
1124
|
+
try {
|
|
1125
|
+
const desired = revision.desired_plan;
|
|
1126
|
+
const desiredTaskIds = new Set(desired.tasks.map(({ task_id: id }) => id));
|
|
1127
|
+
const desiredPhaseIds = new Set(desired.phases.map(({ phase_id: id }) => id));
|
|
1128
|
+
// v3のruntime_task_migrationは証拠付きの行であり機械が作れない。task行は補わない。
|
|
1129
|
+
const taskRows = version === '3' ? [] : member.plan.tasks
|
|
1130
|
+
.filter(({ task_id: id }) => !revision.task_migration.some(({ from_task_id: from }) => from === id))
|
|
1131
|
+
.map(({ task_id: id }) => (desiredTaskIds.has(id)
|
|
1132
|
+
? { from_task_id: id, to_task_id: id,
|
|
1133
|
+
state_policy: version === '5' ? 'carry_reconciled_metadata' : 'carry' }
|
|
1134
|
+
: { from_task_id: id, to_task_id: 'removed', state_policy: 'removed' }));
|
|
1135
|
+
const predecessorPhases = PHASE_PREDECESSOR_SCHEMAS.has(member.plan.schema) ? member.plan.phases : [];
|
|
1136
|
+
const targeted = new Set(revision.phase_migration.map(({ to_phase_id: id }) => id));
|
|
1137
|
+
const keepsAcceptance = defaultPhaseCarry(member, desired, [...revision.task_migration, ...taskRows]);
|
|
1138
|
+
const phaseRows = [
|
|
1139
|
+
...predecessorPhases
|
|
1140
|
+
.filter(({ phase_id: id }) => !revision.phase_migration.some(({ from_phase_id: from }) => from === id))
|
|
1141
|
+
.map((phase) => (desiredPhaseIds.has(phase.phase_id)
|
|
1142
|
+
? { from_phase_id: phase.phase_id, to_phase_id: phase.phase_id,
|
|
1143
|
+
state_policy: keepsAcceptance(phase) ? 'carry' : 'reset' }
|
|
1144
|
+
: { from_phase_id: phase.phase_id, to_phase_id: 'removed', state_policy: 'removed' })),
|
|
1145
|
+
...[...desiredPhaseIds].filter((id) => !targeted.has(id)
|
|
1146
|
+
&& !predecessorPhases.some(({ phase_id: from }) => from === id && desiredPhaseIds.has(from)))
|
|
1147
|
+
.map((id) => ({ from_phase_id: null, to_phase_id: id, state_policy: 'reset' })),
|
|
1148
|
+
];
|
|
1149
|
+
const inventory = version === '3' && predecessorInventory !== null
|
|
1150
|
+
? completeSourceInventory(revision.source_inventory, revision, predecessorInventory) : null;
|
|
1151
|
+
if (taskRows.length === 0 && phaseRows.length === 0
|
|
1152
|
+
&& (inventory === null || inventory === revision.source_inventory)) return revision;
|
|
1153
|
+
|
|
1154
|
+
const byFrom = (left, right) => compareText(left.from_task_id, right.from_task_id);
|
|
1155
|
+
const phaseOrder = (left, right) => compareText(left.from_phase_id ?? '', right.from_phase_id ?? '')
|
|
1156
|
+
|| compareText(left.to_phase_id, right.to_phase_id);
|
|
1157
|
+
const taskMigration = [...revision.task_migration, ...taskRows].sort(byFrom);
|
|
1158
|
+
const phaseMigration = [...revision.phase_migration, ...phaseRows].sort(phaseOrder);
|
|
1159
|
+
const featureGraphDigest = version === '4' ? digestTodoArtifact({
|
|
1160
|
+
goal: revision.backchain.goal, features: revision.backchain.features, tasks: revision.backchain.tasks,
|
|
1161
|
+
}) : null;
|
|
1162
|
+
const planVersion = phaseTodoRevisionPlanVersion({
|
|
1163
|
+
projectId: revision.project_id, planKey: revision.plan_key, predecessor: revision.predecessor,
|
|
1164
|
+
desiredPlan: desired, taskMigration, phaseMigration, featureGraphDigest,
|
|
1165
|
+
});
|
|
1166
|
+
const next = { ...revision, task_migration: taskMigration, phase_migration: phaseMigration,
|
|
1167
|
+
desired_plan: buildPlan({ ...desired, plan_version: planVersion }) };
|
|
1168
|
+
if (version === '4') {
|
|
1169
|
+
next.backchain = { ...revision.backchain, plan_version: planVersion, chain_digest: '' };
|
|
1170
|
+
next.backchain.chain_digest = todoSelfDigest(next.backchain, 'chain_digest');
|
|
1171
|
+
}
|
|
1172
|
+
if (version === '3') {
|
|
1173
|
+
next.source_inventory = inventory;
|
|
1174
|
+
next.reconciliation = { ...revision.reconciliation,
|
|
1175
|
+
source_inventory_digest: todoSourceInventoryDigest(inventory),
|
|
1176
|
+
desired_plan_digest: next.desired_plan.plan_digest,
|
|
1177
|
+
task_migration_digest: todoTaskMigrationDigest(taskMigration),
|
|
1178
|
+
phase_migration_digest: digestTodoArtifact(phaseMigration),
|
|
1179
|
+
reconciliation_digest: '' };
|
|
1180
|
+
next.reconciliation.reconciliation_digest = todoSelfDigest(next.reconciliation, 'reconciliation_digest');
|
|
1181
|
+
}
|
|
1182
|
+
next.revision_digest = todoSelfDigest(next, 'revision_digest');
|
|
1183
|
+
return next;
|
|
1184
|
+
} catch { return revision; }
|
|
1185
|
+
}
|
package/src/todo-status.mjs
CHANGED
|
@@ -30,7 +30,8 @@ import {
|
|
|
30
30
|
* plan単位noteは工程に属する義務で、taskへ着手した人のcontextには届くが、**まだ誰も
|
|
31
31
|
* 着手していない工程の義務は、この欄が無いとどこにも出ない**。
|
|
32
32
|
*/
|
|
33
|
-
export const TODO_STATUS_SCHEMA = 'lattice.todo_status_result.
|
|
33
|
+
export const TODO_STATUS_SCHEMA = 'lattice.todo_status_result.v9';
|
|
34
|
+
/** v9 (u03 A77): `truncated: [{list, total, shown}]` records every cut of an output list. */
|
|
34
35
|
/** v8: cross_plan_findingsは件数だけ全数、本文は先頭からこの件数まで(statusを止めない)。 */
|
|
35
36
|
export const TODO_STATUS_FINDING_LIMIT = 32;
|
|
36
37
|
export const TODO_DISPATCH_FRONTIER_SCHEMA = 'lattice.todo_dispatch_frontier.v1';
|
|
@@ -75,6 +76,24 @@ function displayText(value, fallback, limit) {
|
|
|
75
76
|
return result.length > 0 ? result : fallback;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
/**
|
|
80
|
+
* 一覧が使う1工程の表示欄。`todo status`と`session-context`の`turn.own`が同じ文字列を返すための共有点。
|
|
81
|
+
* u12: done_conditionは1行・512文字までの表示用で、全文は`todo show`が返す。v7以前は欄が無くnull。
|
|
82
|
+
*/
|
|
83
|
+
export function todoStatusTaskDisplay(task) {
|
|
84
|
+
return {
|
|
85
|
+
label: displayText(task.title, task.task_id, TODO_STATUS_LABEL_LIMIT),
|
|
86
|
+
done_condition: typeof task.done_condition === 'string' && task.done_condition.trim().length > 0
|
|
87
|
+
? displayText(task.done_condition.replace(/[\u0000-\u001f\u007f]+/gu, ' ').trim(), '', TODO_STATUS_REASON_LIMIT)
|
|
88
|
+
: null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** `todo status`のblocked欄と同じ表示のblocked理由。 */
|
|
93
|
+
export function todoStatusBlockedReason(reason) {
|
|
94
|
+
return displayText(reason, 'blocked', TODO_STATUS_REASON_LIMIT);
|
|
95
|
+
}
|
|
96
|
+
|
|
78
97
|
function taskKey(projectId, planKey, taskId) {
|
|
79
98
|
return `${projectId}\0${planKey}\0${taskId}`;
|
|
80
99
|
}
|
|
@@ -338,7 +357,7 @@ export function validateTodoStatusResult(value) {
|
|
|
338
357
|
'schema', 'project_id', 'active_set', 'next_ready', 'dispatch_frontier',
|
|
339
358
|
'blocked', 'audit_pending', 'structure_finalization_pending', 'plan_notes',
|
|
340
359
|
'coordination', 'parallel_candidates', 'cross_plan_findings',
|
|
341
|
-
'member_heads', 'result_digest',
|
|
360
|
+
'member_heads', 'truncated', 'result_digest',
|
|
342
361
|
]) && value.schema === TODO_STATUS_SCHEMA && isTodoIdentifier(value.project_id)
|
|
343
362
|
&& boundedList(value.active_set, activeTaskEntry) && boundedList(value.next_ready, taskEntry)
|
|
344
363
|
&& dispatchFrontierEntry(value.dispatch_frontier, value.project_id, value.next_ready)
|
|
@@ -349,6 +368,9 @@ export function validateTodoStatusResult(value) {
|
|
|
349
368
|
&& boundedList(value.parallel_candidates, parallelCandidateEntry)
|
|
350
369
|
&& crossPlanFindings(value.cross_plan_findings)
|
|
351
370
|
&& boundedList(value.member_heads, memberHead)
|
|
371
|
+
&& Array.isArray(value.truncated) && value.truncated.every((entry) => exactRecord(entry, ['list', 'total', 'shown'])
|
|
372
|
+
&& typeof entry.list === 'string' && isNonNegativeSafeInteger(entry.total)
|
|
373
|
+
&& isNonNegativeSafeInteger(entry.shown) && entry.shown < entry.total)
|
|
352
374
|
&& isTodoDigest(value.result_digest)
|
|
353
375
|
&& value.result_digest === todoSelfDigest(value, 'result_digest');
|
|
354
376
|
} catch {
|
|
@@ -477,12 +499,7 @@ function buildTodoGraph(readModel) {
|
|
|
477
499
|
project_id: member.plan.project_id,
|
|
478
500
|
plan_key: member.plan.plan_key,
|
|
479
501
|
task_id: task.task_id,
|
|
480
|
-
|
|
481
|
-
// u12: 作成者が書いた終了条件。一覧は1行・512文字までの表示用で、全文は`todo show`が返す。
|
|
482
|
-
// v7以前は欄が無くnull。
|
|
483
|
-
done_condition: typeof task.done_condition === 'string' && task.done_condition.trim().length > 0
|
|
484
|
-
? displayText(task.done_condition.replace(/[\u0000-\u001f\u007f]+/gu, ' ').trim(), '', TODO_STATUS_REASON_LIMIT)
|
|
485
|
-
: null,
|
|
502
|
+
...todoStatusTaskDisplay(task),
|
|
486
503
|
status: state.status,
|
|
487
504
|
finished: isFinishedTodoTaskState(state),
|
|
488
505
|
blocked_reason: state.blocked_reason,
|
|
@@ -590,6 +607,16 @@ export function projectTodoStatus(readModel, options = undefined) {
|
|
|
590
607
|
const parallelCandidates = [...options.parallelCandidates];
|
|
591
608
|
const structureFinalizations = [...(options.structureFinalizations ?? [])];
|
|
592
609
|
|
|
610
|
+
// u03 A77: output callers get a bounded result that records each cut; dispatch-only callers
|
|
611
|
+
// (never printed) keep full lists and the list limit as before.
|
|
612
|
+
const output = options !== TODO_STATUS_DISPATCH_ONLY;
|
|
613
|
+
const truncated = new Map();
|
|
614
|
+
const cut = (name, value, limit) => {
|
|
615
|
+
if (value.length <= limit) return value;
|
|
616
|
+
const entry = truncated.get(name) ?? { list: name, total: 0, shown: 0 };
|
|
617
|
+
truncated.set(name, entry);
|
|
618
|
+
return value.slice(0, limit);
|
|
619
|
+
};
|
|
593
620
|
const activeSet = [];
|
|
594
621
|
const nextReady = [];
|
|
595
622
|
const blocked = [];
|
|
@@ -603,15 +630,20 @@ export function projectTodoStatus(readModel, options = undefined) {
|
|
|
603
630
|
return { plan_key: predecessor.plan_key, task_id: predecessor.task_id };
|
|
604
631
|
})
|
|
605
632
|
.sort(compareTaskEntries);
|
|
606
|
-
enforceListLimit('active_set.unmet_dependencies', unmetDependencies);
|
|
607
|
-
|
|
633
|
+
if (!output) enforceListLimit('active_set.unmet_dependencies', unmetDependencies);
|
|
634
|
+
const shownDependencies = cut('active_set.unmet_dependencies', unmetDependencies, TODO_STATUS_LIST_LIMIT);
|
|
635
|
+
if (shownDependencies !== unmetDependencies) {
|
|
636
|
+
const entry = truncated.get('active_set.unmet_dependencies');
|
|
637
|
+
entry.total += unmetDependencies.length; entry.shown += shownDependencies.length;
|
|
638
|
+
}
|
|
639
|
+
activeSet.push({ ...task, unmet_dependencies: shownDependencies });
|
|
608
640
|
}
|
|
609
641
|
if (isNodeReady(node, graph)) nextReady.push({ ...task, done_condition: node.done_condition });
|
|
610
642
|
if (node.status === 'blocked') {
|
|
611
643
|
blocked.push({
|
|
612
644
|
plan_key: node.plan_key,
|
|
613
645
|
task_id: node.task_id,
|
|
614
|
-
reason:
|
|
646
|
+
reason: todoStatusBlockedReason(node.blocked_reason),
|
|
615
647
|
});
|
|
616
648
|
}
|
|
617
649
|
}
|
|
@@ -619,53 +651,64 @@ export function projectTodoStatus(readModel, options = undefined) {
|
|
|
619
651
|
nextReady.sort(compareTaskEntries);
|
|
620
652
|
blocked.sort(compareTaskEntries);
|
|
621
653
|
memberHeads.sort((left, right) => left.plan_key < right.plan_key ? -1 : left.plan_key > right.plan_key ? 1 : 0);
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
['coordination', coordination], ['parallel_candidates', parallelCandidates],
|
|
627
|
-
['member_heads', memberHeads],
|
|
628
|
-
]) enforceListLimit(name, value);
|
|
629
|
-
|
|
630
|
-
const result = {
|
|
631
|
-
schema: TODO_STATUS_SCHEMA,
|
|
632
|
-
project_id: readModel.project_id,
|
|
633
|
-
active_set: activeSet,
|
|
634
|
-
next_ready: nextReady,
|
|
635
|
-
dispatch_frontier: dispatchFrontier(readModel.project_id, nextReady),
|
|
636
|
-
blocked,
|
|
637
|
-
// 監査待ちは`member.phases`だけから作った別の列で、dispatch(next_ready/dispatch_frontier)へは
|
|
638
|
-
// 影響しない。監査が進んでもfrontier_digestは動かない。
|
|
639
|
-
audit_pending: auditPending,
|
|
640
|
-
// 全task done後、構造finalizationが無い/古いplanだけを別列へ出す。監査状態と
|
|
641
|
-
// dispatch状態を混ぜず、terminal受理へ進めない理由と正規コマンドを同時に示す。
|
|
642
|
-
structure_finalization_pending: structureFinalizations,
|
|
643
|
-
// plan単位noteも同じく別の列である。noteの有無・件数はdispatchへ影響しないので、
|
|
644
|
-
// next_ready・dispatch_frontier・frontier_digestはnoteを書いても1バイトも動かない。
|
|
645
|
-
plan_notes: planNotes,
|
|
646
|
-
// 調整方式の宣言も同じく別の列である。宣言はdispatchを変えない——未宣言でもready
|
|
647
|
-
// frontierは通常どおり出る(ADR 0160・ob04のProtected behavior)。
|
|
648
|
-
coordination,
|
|
649
|
-
// 並列候補も別の列である。判定が進んでもdispatchは動かない——next_ready・
|
|
650
|
-
// dispatch_frontier・frontier_digestは判定状態を1バイトも含まない(ADR 0063・ob04)。
|
|
651
|
-
parallel_candidates: parallelCandidates,
|
|
652
|
-
// u03 A24/A25b/N6: 陳腐化・消えた越境参照はStoreのfindingで、dispatchを止めない。
|
|
653
|
-
// 一覧で上限に達してもstatusを拒否しないよう、本文は先頭から切り、件数は全数を返す。
|
|
654
|
-
cross_plan_findings: {
|
|
655
|
-
total: (readModel.cross_plan_findings ?? []).length,
|
|
656
|
-
entries: (readModel.cross_plan_findings ?? []).slice(0, TODO_STATUS_FINDING_LIMIT),
|
|
657
|
-
},
|
|
658
|
-
member_heads: memberHeads,
|
|
659
|
-
result_digest: '',
|
|
654
|
+
const lists = {
|
|
655
|
+
active_set: activeSet, next_ready: nextReady, blocked, audit_pending: auditPending,
|
|
656
|
+
structure_finalization_pending: structureFinalizations, plan_notes: planNotes,
|
|
657
|
+
coordination, parallel_candidates: parallelCandidates, member_heads: memberHeads,
|
|
660
658
|
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
659
|
+
const totals = Object.fromEntries(Object.entries(lists).map(([name, value]) => [name, value.length]));
|
|
660
|
+
for (const [name, value] of Object.entries(lists)) {
|
|
661
|
+
if (output) lists[name] = cut(name, value, TODO_STATUS_LIST_LIMIT);
|
|
662
|
+
else enforceListLimit(name, value);
|
|
663
|
+
}
|
|
664
|
+
const findings = readModel.cross_plan_findings ?? [];
|
|
665
|
+
const build = () => {
|
|
666
|
+
for (const [name, value] of Object.entries(lists)) {
|
|
667
|
+
if (value.length < totals[name]) truncated.set(name, { list: name, total: totals[name], shown: value.length });
|
|
668
|
+
}
|
|
669
|
+
const result = {
|
|
670
|
+
schema: TODO_STATUS_SCHEMA,
|
|
671
|
+
project_id: readModel.project_id,
|
|
672
|
+
active_set: lists.active_set,
|
|
673
|
+
next_ready: lists.next_ready,
|
|
674
|
+
dispatch_frontier: dispatchFrontier(readModel.project_id, lists.next_ready),
|
|
675
|
+
blocked: lists.blocked,
|
|
676
|
+
// 監査待ちは`member.phases`だけから作った別の列で、dispatch(next_ready/dispatch_frontier)へは
|
|
677
|
+
// 影響しない。監査が進んでもfrontier_digestは動かない。
|
|
678
|
+
audit_pending: lists.audit_pending,
|
|
679
|
+
// 全task done後、構造finalizationが無い/古いplanだけを別列へ出す。監査状態と
|
|
680
|
+
// dispatch状態を混ぜず、terminal受理へ進めない理由と正規コマンドを同時に示す。
|
|
681
|
+
structure_finalization_pending: lists.structure_finalization_pending,
|
|
682
|
+
// plan単位noteも同じく別の列である。noteの有無・件数はdispatchへ影響しないので、
|
|
683
|
+
// next_ready・dispatch_frontier・frontier_digestはnoteを書いても1バイトも動かない。
|
|
684
|
+
plan_notes: lists.plan_notes,
|
|
685
|
+
// 調整方式の宣言も同じく別の列である。宣言はdispatchを変えない——未宣言でもready
|
|
686
|
+
// frontierは通常どおり出る(ADR 0160・ob04のProtected behavior)。
|
|
687
|
+
coordination: lists.coordination,
|
|
688
|
+
// 並列候補も別の列である。判定が進んでもdispatchは動かない——next_ready・
|
|
689
|
+
// dispatch_frontier・frontier_digestは判定状態を1バイトも含まない(ADR 0063・ob04)。
|
|
690
|
+
parallel_candidates: lists.parallel_candidates,
|
|
691
|
+
// u03 A24/A25b/N6: 陳腐化・消えた越境参照はStoreのfindingで、dispatchを止めない。
|
|
692
|
+
// 一覧で上限に達してもstatusを拒否しないよう、本文は先頭から切り、件数は全数を返す。
|
|
693
|
+
cross_plan_findings: {
|
|
694
|
+
total: findings.length,
|
|
695
|
+
entries: findings.slice(0, TODO_STATUS_FINDING_LIMIT),
|
|
696
|
+
},
|
|
697
|
+
member_heads: lists.member_heads,
|
|
698
|
+
truncated: [...truncated.values()].sort((left, right) => left.list.localeCompare(right.list)),
|
|
699
|
+
result_digest: '',
|
|
700
|
+
};
|
|
701
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
702
|
+
if (!validateTodoStatusResult(result)) fail('TODO_STATUS_INVALID_RESULT', 'todo_status_result_invalid');
|
|
703
|
+
return result;
|
|
704
|
+
};
|
|
705
|
+
let result = build();
|
|
706
|
+
// Output only: halve the longest list until the result fits the capture limit (never refuse).
|
|
707
|
+
while (output && Buffer.byteLength(`${JSON.stringify(result)}\n`) > TODO_STATUS_CAPTURE_LIMIT) {
|
|
708
|
+
const [name, value] = Object.entries(lists).sort((left, right) => right[1].length - left[1].length)[0];
|
|
709
|
+
if (value.length === 0) break;
|
|
710
|
+
lists[name] = value.slice(0, Math.floor(value.length / 2));
|
|
711
|
+
result = build();
|
|
669
712
|
}
|
|
670
713
|
return result;
|
|
671
714
|
}
|
package/src/todo-store-view.mjs
CHANGED
|
@@ -18,10 +18,9 @@ export function isPhaseTodoPlanSchema(schema) {
|
|
|
18
18
|
return ['lattice.todo_plan.v4', 'lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(schema);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/** One finished-predecessor predicate for Store replay and readiness: done
|
|
21
|
+
/** One finished-predecessor predicate for Store replay and readiness: done or retired (a13: retire deletes the task, so its edges count as gone). */
|
|
22
22
|
export function isFinishedTodoTaskState(state) {
|
|
23
|
-
return state?.status === 'done'
|
|
24
|
-
|| (state?.status === 'retired' && (state.done_at !== null || state.imported === true));
|
|
23
|
+
return state?.status === 'done' || state?.status === 'retired';
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export function isDecoupledPhaseTodoPlanSchema(schema) {
|