@quolu/lattice 0.82.0 → 0.84.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/README.ja.md +7 -6
- package/README.md +1 -1
- package/bin/lattice-bridge-supervisor.mjs +10 -0
- package/bin/lattice-dashboard.mjs +3 -18
- package/bin/lattice-mcp.mjs +6 -3
- package/bin/lattice.mjs +30 -23
- package/docs/schemas/lattice.plan_create_input.v4.schema.json +5 -11
- package/docs/schemas/lattice.plan_create_input.v5.schema.json +362 -0
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +38 -11
- package/package.json +2 -1
- package/sensor/dist/db/index.d.ts +1 -0
- package/sensor/dist/db/index.d.ts.map +1 -1
- package/sensor/dist/db/index.js +13 -0
- package/sensor/dist/db/index.js.map +1 -1
- package/sensor/dist/index.d.ts.map +1 -1
- package/sensor/dist/index.js +12 -2
- package/sensor/dist/index.js.map +1 -1
- package/sensor/dist/mcp/answer-freshness.js +1 -1
- package/sensor/dist/mcp/answer-freshness.js.map +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/sensor/dist/mcp/engine.d.ts +11 -0
- package/sensor/dist/mcp/engine.d.ts.map +1 -1
- package/sensor/dist/mcp/engine.js +83 -4
- package/sensor/dist/mcp/engine.js.map +1 -1
- package/sensor/dist/mcp/index-repair.d.ts +7 -0
- package/sensor/dist/mcp/index-repair.d.ts.map +1 -0
- package/sensor/dist/mcp/index-repair.js +93 -0
- package/sensor/dist/mcp/index-repair.js.map +1 -0
- package/sensor/dist/mcp/index.d.ts.map +1 -1
- package/sensor/dist/mcp/index.js +12 -7
- package/sensor/dist/mcp/index.js.map +1 -1
- package/sensor/dist/mcp/tools.d.ts +4 -0
- package/sensor/dist/mcp/tools.d.ts.map +1 -1
- package/sensor/dist/mcp/tools.js +29 -9
- package/sensor/dist/mcp/tools.js.map +1 -1
- package/src/bridge-hub-server.mjs +46 -9
- package/src/cli-help.mjs +10 -8
- package/src/cli-refusal-guidance.mjs +354 -0
- package/src/dashboard-delivery.mjs +2 -1
- package/src/dashboard-lifecycle-journal.mjs +42 -20
- package/src/hooks-cli.mjs +30 -6
- package/src/plan-backchain.mjs +95 -41
- package/src/plan-revise.mjs +274 -72
- package/src/project-cli.mjs +301 -163
- package/src/project-identity.mjs +14 -0
- package/src/runtime-cli.mjs +38 -29
- package/src/runtime-control-store.mjs +22 -1
- package/src/runtime-decision-verifier.mjs +27 -8
- package/src/runtime-engine.mjs +34 -5
- package/src/runtime-hold-recompile.mjs +19 -15
- package/src/runtime-kept-worktree.mjs +136 -0
- package/src/runtime-lifecycle-lock.mjs +118 -30
- package/src/runtime-managed-supervisor.mjs +10 -10
- package/src/runtime-pull-intake.mjs +90 -44
- package/src/store-lock.mjs +142 -57
- package/src/todo-authoring-input.mjs +211 -2
- package/src/todo-cli.mjs +554 -200
- package/src/todo-contracts.mjs +22 -6
- package/src/todo-dashboard-registry.mjs +35 -6
- package/src/todo-gantt-display.mjs +259 -0
- package/src/todo-gantt-html-independence.mjs +10 -3
- package/src/todo-gantt-html-shared.mjs +16 -1
- package/src/todo-gantt-html.mjs +74 -53
- package/src/todo-gantt-layout.mjs +137 -59
- package/src/todo-gantt-live.mjs +6 -3
- package/src/todo-independence-guidance.mjs +4 -26
- package/src/todo-note-store.mjs +6 -3
- package/src/todo-readiness.mjs +83 -20
- package/src/todo-revision.mjs +156 -8
- package/src/todo-split.mjs +6 -3
- package/src/todo-status.mjs +141 -54
- package/src/todo-store-cache.mjs +1 -1
- package/src/todo-store-view.mjs +20 -2
- package/src/todo-store.mjs +562 -444
package/src/todo-note-store.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { StoreLockError, withStoreLock } from './store-lock.mjs';
|
|
8
8
|
import { syncPublishedFile } from './fs-publish.mjs';
|
|
9
|
+
import { normalizeCheckoutEol } from './todo-store-view.mjs';
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
TODO_LIMITS,
|
|
@@ -88,7 +89,7 @@ async function readOptionalBounded(ref, { missing = false } = {}) {
|
|
|
88
89
|
if (!metadata.isFile() || metadata.size > TODO_LIMITS.journalSegmentBytes) {
|
|
89
90
|
fail('NOTE_LOG_CORRUPT', 'note_segment_invalid', { ref });
|
|
90
91
|
}
|
|
91
|
-
return await readFile(ref);
|
|
92
|
+
return normalizeCheckoutEol(await readFile(ref));
|
|
92
93
|
} catch (error) {
|
|
93
94
|
if (error instanceof TodoNoteStoreError) throw error;
|
|
94
95
|
if (missing && error?.code === 'ENOENT') return null;
|
|
@@ -263,7 +264,7 @@ export async function appendTodoNote(options = {}) {
|
|
|
263
264
|
const planScoped = options.taskId === null;
|
|
264
265
|
const scope = planScoped ? 'plan' : 'task';
|
|
265
266
|
const repoRoot = path.resolve(options.repoRoot);
|
|
266
|
-
return withNoteLock(repoRoot, async () => {
|
|
267
|
+
return withNoteLock(repoRoot, async (assertHeld) => {
|
|
267
268
|
// sequenceとprevious_digestはchainごとに独立。note系の起点は1(journal系の0ではない)。
|
|
268
269
|
const chain = await readTodoNoteEvents({ repoRoot, planKey: options.planKey, scope });
|
|
269
270
|
if (options.supersedes !== null) {
|
|
@@ -299,6 +300,8 @@ export async function appendTodoNote(options = {}) {
|
|
|
299
300
|
const paths = chainRefs(repoRoot, options.planKey, scope);
|
|
300
301
|
await ensureNoteDirectory(path.dirname(paths.active));
|
|
301
302
|
const eventBytes = canonicalLine(event);
|
|
303
|
+
// A holder that lost its lock while suspended must not overwrite the new owner's chain.
|
|
304
|
+
await assertHeld();
|
|
302
305
|
if (chain.active_bytes.length > 0
|
|
303
306
|
&& chain.active_bytes.length + eventBytes.length > TODO_LIMITS.journalSegmentBytes) {
|
|
304
307
|
const activeEvents = parseCanonicalSegment(chain.active_bytes, paths.active);
|
|
@@ -471,7 +474,7 @@ async function readCanonicalJson(ref, { missing = false } = {}) {
|
|
|
471
474
|
if (!metadata.isFile() || metadata.size > TODO_LIMITS.snapshotBytes) {
|
|
472
475
|
fail('NOTE_PROJECTION_INVALID', 'note_projection_artifact_invalid', { ref });
|
|
473
476
|
}
|
|
474
|
-
bytes = await readFile(ref);
|
|
477
|
+
bytes = normalizeCheckoutEol(await readFile(ref));
|
|
475
478
|
} catch (error) {
|
|
476
479
|
if (error instanceof TodoNoteStoreError) throw error;
|
|
477
480
|
if (missing && error?.code === 'ENOENT') return null;
|
package/src/todo-readiness.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDecoupledPhaseTodoPlanSchema,
|
|
3
|
+
isFinishedTodoTaskState,
|
|
3
4
|
isPhaseTodoPlanSchema,
|
|
4
5
|
projectTodoCrossPlanDependencies,
|
|
5
6
|
} from './todo-store-view.mjs';
|
|
7
|
+
import { TodoStoreError } from './todo-store.mjs';
|
|
6
8
|
|
|
7
9
|
function taskKey(ref) {
|
|
8
10
|
return `${ref.project_id}\0${ref.plan_key}\0${ref.task_id}`;
|
|
@@ -22,13 +24,18 @@ export function createTodoReadiness(store) {
|
|
|
22
24
|
const acceptanceOutgoing = new Map();
|
|
23
25
|
for (const member of store.members) {
|
|
24
26
|
const { plan } = member;
|
|
25
|
-
const states = new Map(member.tasks.map((state) => [state.task_id, state
|
|
27
|
+
const states = new Map(member.tasks.map((state) => [state.task_id, state]));
|
|
26
28
|
const phaseStates = new Map((member.phases ?? []).map((phase) => [phase.phase_id, phase.status]));
|
|
27
|
-
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
|
+
}
|
|
28
32
|
for (const task of plan.tasks) {
|
|
29
33
|
const key = taskKey({ ...plan, ...task });
|
|
30
34
|
nodes.set(key, {
|
|
31
|
-
status: states.get(task.task_id),
|
|
35
|
+
status: states.get(task.task_id)?.status,
|
|
36
|
+
task_id: task.task_id,
|
|
37
|
+
// retiredは先行として完了扱い(u12/a13)。判定はStore replayと同じ一つの述語。
|
|
38
|
+
finished: isFinishedTodoTaskState(states.get(task.task_id)),
|
|
32
39
|
schema: plan.schema,
|
|
33
40
|
plan_key: plan.plan_key,
|
|
34
41
|
phase_id: isPhaseTodoPlanSchema(plan.schema) ? task.phase_id : null,
|
|
@@ -46,12 +53,13 @@ export function createTodoReadiness(store) {
|
|
|
46
53
|
outgoing.get(source)?.add(target);
|
|
47
54
|
};
|
|
48
55
|
for (const member of store.members) {
|
|
49
|
-
|
|
50
|
-
for (const
|
|
56
|
+
// `?? []`: the display reads unverified members too and must not stop on a missing list (u01).
|
|
57
|
+
for (const edge of member.plan.hard_dependencies ?? []) connect(edge.from, edge.to);
|
|
58
|
+
for (const join of member.plan.joins ?? []) {
|
|
51
59
|
for (const after of join.after) connect(after, join.before);
|
|
52
60
|
}
|
|
53
61
|
if (isDecoupledPhaseTodoPlanSchema(member.plan.schema)) {
|
|
54
|
-
for (const edge of member.plan.phase_accept_dependencies) {
|
|
62
|
+
for (const edge of member.plan.phase_accept_dependencies ?? []) {
|
|
55
63
|
const source = phaseKey(edge.from);
|
|
56
64
|
const target = taskKey(edge.to);
|
|
57
65
|
acceptanceIncoming.get(target)?.add(source);
|
|
@@ -72,22 +80,39 @@ export function createTodoReadiness(store) {
|
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
function prerequisites(key) {
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
83
|
+
// u03 A24: 消えた端点(Storeのendpoint_missing finding)は後続を止めない。Store replayも同じ規則。
|
|
84
|
+
const predecessors = [...(incoming.get(key) ?? [])].map((source) => nodes.get(source))
|
|
85
|
+
.filter((node) => node !== undefined);
|
|
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;
|
|
78
90
|
const taskDependenciesDone = predecessorsDone && predecessorPhasesReady;
|
|
79
|
-
const
|
|
80
|
-
.
|
|
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 }));
|
|
81
99
|
return {
|
|
82
100
|
taskDependenciesDone,
|
|
83
101
|
phaseAcceptReady,
|
|
84
102
|
dependenciesDone: taskDependenciesDone && phaseAcceptReady,
|
|
85
|
-
cause
|
|
86
|
-
|
|
87
|
-
|
|
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) } : {},
|
|
88
109
|
};
|
|
89
110
|
}
|
|
90
111
|
|
|
112
|
+
function ownPhaseStatus(key) {
|
|
113
|
+
return nodes.get(key)?.phase_status;
|
|
114
|
+
}
|
|
115
|
+
|
|
91
116
|
function ownPhaseReady(key) {
|
|
92
117
|
const node = nodes.get(key);
|
|
93
118
|
return node?.schema !== 'lattice.todo_plan.v4' || node.phase_status === 'active';
|
|
@@ -102,19 +127,35 @@ export function createTodoReadiness(store) {
|
|
|
102
127
|
status: (key) => nodes.get(key)?.status,
|
|
103
128
|
prerequisites,
|
|
104
129
|
ownPhaseReady,
|
|
130
|
+
ownPhaseStatus,
|
|
105
131
|
isReady: (key) => nodes.get(key)?.status === 'pending'
|
|
106
132
|
&& ownPhaseReady(key) && prerequisites(key).dependenciesDone,
|
|
107
133
|
startedSuccessor,
|
|
108
134
|
phaseHasStartedSuccessor: (member, phaseId) => member.plan.schema === 'lattice.todo_plan.v4'
|
|
109
135
|
? member.plan.tasks.filter(({ phase_id }) => phase_id === phaseId)
|
|
110
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'))))
|
|
111
143
|
: [...(acceptanceOutgoing.get(phaseKey({ ...member.plan, phase_id: phaseId })) ?? [])]
|
|
112
144
|
.some((key) => nodes.get(key)?.status !== 'pending'),
|
|
113
145
|
};
|
|
114
146
|
}
|
|
115
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.
|
|
116
157
|
function refused(reason, cause, detail = {}) {
|
|
117
|
-
return { ok: false, code: '
|
|
158
|
+
return { ok: false, code: 'TODO_TRANSITION_REFUSED', detail: { reason, cause, ...detail } };
|
|
118
159
|
}
|
|
119
160
|
|
|
120
161
|
/** Prospective policy only; Store retains historical replay, evidence and identity validation. */
|
|
@@ -126,10 +167,10 @@ export function validateProspectiveEvent({ store, member, event }) {
|
|
|
126
167
|
&& event.payload.start_mode !== 'rebind';
|
|
127
168
|
if (authoredStart && (!prerequisites.phaseAcceptReady
|
|
128
169
|
|| (!prerequisites.taskDependenciesDone && event.payload.override_reason === null))) {
|
|
129
|
-
return refused('invalid_start_transition', prerequisites.cause);
|
|
170
|
+
return refused('invalid_start_transition', prerequisites.cause, prerequisites.blocking);
|
|
130
171
|
}
|
|
131
172
|
if (event.kind === 'done' && event.payload.done_mode === 'authored' && !prerequisites.dependenciesDone) {
|
|
132
|
-
return refused('invalid_done_transition', prerequisites.cause);
|
|
173
|
+
return refused('invalid_done_transition', prerequisites.cause, prerequisites.blocking);
|
|
133
174
|
}
|
|
134
175
|
if (event.kind === 'reopen' && event.payload.override_reason === null && readiness.startedSuccessor(key)) {
|
|
135
176
|
return refused('reopen_has_started_successor', 'task_state', {
|
|
@@ -143,12 +184,34 @@ export function validateProspectiveEvent({ store, member, event }) {
|
|
|
143
184
|
// Keep merged refusal priority; replay still owns missing target/binding checks.
|
|
144
185
|
const status = readiness.status(key);
|
|
145
186
|
if (authoredStart && status !== undefined) {
|
|
146
|
-
if (status !== 'pending') return refused('invalid_start_transition', 'task_state');
|
|
147
|
-
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
|
+
}
|
|
148
191
|
}
|
|
149
192
|
if (event.kind === 'done' && event.payload.done_mode === 'authored'
|
|
150
193
|
&& status !== undefined && status !== 'in-progress') {
|
|
151
|
-
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 });
|
|
152
201
|
}
|
|
153
202
|
return { ok: true };
|
|
154
203
|
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* `todo retire`はlock外で読んだ状態をprior_statusに入れる。append時にStore replayが
|
|
207
|
+
* prior_status不一致や不正遷移で拒否したなら、読込とappendの間に状態が変わった
|
|
208
|
+
* 再試行できる競合であり、破損ではない(u12)。それ以外のerrorはそのまま返す。
|
|
209
|
+
*/
|
|
210
|
+
export function retireStateConflict(error, { planKey, taskId, priorStatus }) {
|
|
211
|
+
if (!(error instanceof TodoStoreError)
|
|
212
|
+
|| !['retire_prior_status_mismatch', 'invalid_retire_transition'].includes(error.detail?.reason)) return error;
|
|
213
|
+
return new TodoStoreError('STORE_WRITE_CONFLICT', 'retire_state_changed', undefined, {
|
|
214
|
+
task_id: taskId, expected: { status: priorStatus },
|
|
215
|
+
next_action: `lattice todo retire --plan ${planKey} --task ${taskId} --reason <text>`,
|
|
216
|
+
});
|
|
217
|
+
}
|
package/src/todo-revision.mjs
CHANGED
|
@@ -69,14 +69,14 @@ export function phaseTodoRevisionPlanVersion({
|
|
|
69
69
|
}) {
|
|
70
70
|
const versionDigest = digestTodoArtifact({
|
|
71
71
|
schema: featureGraphDigest !== null ? 'lattice.phase_todo_revision_version.v3'
|
|
72
|
-
: ['lattice.todo_plan.v5', 'lattice.todo_plan.v7'].includes(desiredPlan.schema)
|
|
72
|
+
: ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(desiredPlan.schema)
|
|
73
73
|
? 'lattice.phase_todo_revision_version.v2' : 'lattice.phase_todo_revision_version.v1', project_id: projectId,
|
|
74
74
|
plan_key: planKey, predecessor, desired_topology: {
|
|
75
75
|
schema: desiredPlan.schema, project_id: desiredPlan.project_id,
|
|
76
76
|
plan_key: desiredPlan.plan_key, predecessor_plan_digest: desiredPlan.predecessor_plan_digest,
|
|
77
77
|
tasks: desiredPlan.tasks, phases: desiredPlan.phases,
|
|
78
78
|
hard_dependencies: desiredPlan.hard_dependencies, joins: desiredPlan.joins,
|
|
79
|
-
...(['lattice.todo_plan.v5', 'lattice.todo_plan.v7'].includes(desiredPlan.schema)
|
|
79
|
+
...(['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(desiredPlan.schema)
|
|
80
80
|
? { phase_accept_dependencies: desiredPlan.phase_accept_dependencies } : {}),
|
|
81
81
|
}, task_migration: taskMigration, phase_migration: phaseMigration,
|
|
82
82
|
...(featureGraphDigest === null ? {} : { feature_graph_digest: featureGraphDigest }),
|
|
@@ -303,9 +303,10 @@ export function validatePhaseTodoRevision(value) {
|
|
|
303
303
|
if (!isTodoIdentifier(value.project_id) || !isTodoIdentifier(value.plan_key)) return false;
|
|
304
304
|
if (!validPredecessor(value.predecessor) || !validateTodoPlan(value.desired_plan)
|
|
305
305
|
|| !(revisionV3
|
|
306
|
-
? ['lattice.todo_plan.v5', 'lattice.todo_plan.v7'].includes(value.desired_plan.schema)
|
|
307
|
-
:
|
|
308
|
-
|
|
306
|
+
? ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(value.desired_plan.schema)
|
|
307
|
+
: (revisionV4 || revisionV5)
|
|
308
|
+
? ['lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(value.desired_plan.schema)
|
|
309
|
+
: value.desired_plan.schema === (revisionV2 ? 'lattice.todo_plan.v5' : 'lattice.todo_plan.v4'))
|
|
309
310
|
|| value.desired_plan.project_id !== value.project_id
|
|
310
311
|
|| value.desired_plan.plan_key !== value.plan_key
|
|
311
312
|
|| value.desired_plan.predecessor_plan_digest !== value.predecessor.plan_digest
|
|
@@ -855,9 +856,9 @@ export function explainPhaseTodoRevision(value) {
|
|
|
855
856
|
const predecessorCheck = explainPredecessor(value.predecessor);
|
|
856
857
|
if (!predecessorCheck.valid) return predecessorCheck;
|
|
857
858
|
if (!validateTodoPlan(value.desired_plan)) return reject('desired_plan_invalid', '/desired_plan');
|
|
858
|
-
const expectedPlanSchemas = revisionV3 ? ['lattice.todo_plan.v5', 'lattice.todo_plan.v7']
|
|
859
|
-
:
|
|
860
|
-
:
|
|
859
|
+
const expectedPlanSchemas = revisionV3 ? ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8']
|
|
860
|
+
: (revisionV4 || revisionV5) ? ['lattice.todo_plan.v7', 'lattice.todo_plan.v8']
|
|
861
|
+
: [revisionV2 ? 'lattice.todo_plan.v5' : 'lattice.todo_plan.v4'];
|
|
861
862
|
if (!expectedPlanSchemas.includes(value.desired_plan.schema)) {
|
|
862
863
|
return reject('desired_plan_schema_mismatch', '/desired_plan/schema');
|
|
863
864
|
}
|
|
@@ -1035,3 +1036,150 @@ export function validateTodoRevisionSet(value) {
|
|
|
1035
1036
|
&& value.revision_set_digest === todoSelfDigest(value, 'revision_set_digest');
|
|
1036
1037
|
} catch { return false; }
|
|
1037
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-split.mjs
CHANGED
|
@@ -30,7 +30,9 @@ import {
|
|
|
30
30
|
} from './todo-revision.mjs';
|
|
31
31
|
|
|
32
32
|
const TODO_SPLIT_SCHEMA = 'lattice.todo_split.v1';
|
|
33
|
-
const SUPPORTED_PLAN_SCHEMAS = new Set(['lattice.todo_plan.v6', 'lattice.todo_plan.v7']);
|
|
33
|
+
const SUPPORTED_PLAN_SCHEMAS = new Set(['lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8']);
|
|
34
|
+
// v8 = v7 + task.done_condition。分割で生まれる子は終了条件を持たない(null)。
|
|
35
|
+
const isPhasedMemoPlan = (plan) => ['lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(plan.schema);
|
|
34
36
|
const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u;
|
|
35
37
|
|
|
36
38
|
export class TodoSplitError extends Error {
|
|
@@ -226,7 +228,7 @@ async function compileSourceCutover(repoRoot, proposal, {
|
|
|
226
228
|
|
|
227
229
|
function compileTasks(plan, proposal, archivedByTask) {
|
|
228
230
|
const residual = plan.tasks.find(({ task_id: taskId }) => taskId === proposal.task_id);
|
|
229
|
-
const phasePlan = plan
|
|
231
|
+
const phasePlan = isPhasedMemoPlan(plan);
|
|
230
232
|
const existing = plan.tasks.map((task) => {
|
|
231
233
|
const updated = task.task_id === proposal.task_id ? {
|
|
232
234
|
...task,
|
|
@@ -249,6 +251,7 @@ function compileTasks(plan, proposal, archivedByTask) {
|
|
|
249
251
|
compile_binding: null,
|
|
250
252
|
parent_task_id: proposal.task_id,
|
|
251
253
|
...(phasePlan ? { phase_id: residual.phase_id } : {}),
|
|
254
|
+
...(plan.schema === 'lattice.todo_plan.v8' ? { done_condition: null } : {}),
|
|
252
255
|
}));
|
|
253
256
|
return [...existing, ...children]
|
|
254
257
|
.sort((left, right) => left.task_id < right.task_id ? -1 : left.task_id > right.task_id ? 1 : 0);
|
|
@@ -329,7 +332,7 @@ export async function compileTodoSplit({ repoRoot, member, proposal }) {
|
|
|
329
332
|
plan_version: plan.plan_version,
|
|
330
333
|
};
|
|
331
334
|
const previousInventory = await existingSourceInventory(repoRoot, member);
|
|
332
|
-
const phasePlan = plan
|
|
335
|
+
const phasePlan = isPhasedMemoPlan(plan);
|
|
333
336
|
// phase revisionのgenesisではpredecessor inventoryがまだrevisionへ保存されていない。
|
|
334
337
|
// apply側は全既存sourceのarchive移送を差分として要求するため、既存taskも同じbatchへ載せる。
|
|
335
338
|
const cutoverExistingTasks = phasePlan && !previousInventory.inherited ? plan.tasks : [];
|