@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/plan-backchain.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
readTodoStore, TodoStoreError,
|
|
12
12
|
} from './todo-store.mjs';
|
|
13
13
|
import { gitSync } from './git-process.mjs';
|
|
14
|
-
import { readAuthoringJsonFile } from './todo-authoring-input.mjs';
|
|
14
|
+
import { completeCreateInput, readAuthoringJsonFile } from './todo-authoring-input.mjs';
|
|
15
15
|
import {
|
|
16
16
|
explainPhaseTodoRevision, phaseTodoRevisionPlanVersion, validatePhaseTodoRevision,
|
|
17
17
|
} from './todo-revision.mjs';
|
|
@@ -101,9 +101,12 @@ export function validatePlanBackchain(chain, authoring) {
|
|
|
101
101
|
if (features.has(feature.feature_id)) fail('feature_duplicate', `/features/${index}/feature_id`);
|
|
102
102
|
features.set(feature.feature_id, feature);
|
|
103
103
|
}
|
|
104
|
+
// 意味の検査(u03p A85)は止めずにfindingsへ集める。形・digest・同一性の検査だけが拒否する。
|
|
105
|
+
const found = [];
|
|
106
|
+
const finding = (reason, pointer, detail = {}) => found.push({ reason, pointer, ...detail });
|
|
104
107
|
for (const [index, feature] of chain.features.entries()) {
|
|
105
108
|
for (const id of feature.requires_feature_ids) {
|
|
106
|
-
if (!features.has(id))
|
|
109
|
+
if (!features.has(id)) finding('required_feature_missing', `/features/${index}/requires_feature_ids`, {
|
|
107
110
|
feature_id: feature.feature_id, required_feature_id: id,
|
|
108
111
|
});
|
|
109
112
|
}
|
|
@@ -111,33 +114,44 @@ export function validatePlanBackchain(chain, authoring) {
|
|
|
111
114
|
const authored = registeredTasks(authoring);
|
|
112
115
|
if (chain.project_id !== authoring.project_id || chain.plan_key !== authoring.plan_key
|
|
113
116
|
|| chain.plan_version !== authoring.plan_version) fail('authoring_identity_mismatch', '/authoring_ref');
|
|
114
|
-
if (!Array.isArray(chain.tasks)
|
|
115
|
-
fail('task_coverage_missing', '/tasks');
|
|
116
|
-
}
|
|
117
|
+
if (!Array.isArray(chain.tasks)) fail('tasks_invalid', '/tasks');
|
|
117
118
|
const authoredIds = new Set(authored.map(({ task_id: id }) => id));
|
|
118
119
|
const taskMap = new Map();
|
|
119
120
|
for (const [index, task] of chain.tasks.entries()) {
|
|
120
121
|
if (!exactRecord(task, ['task_id', 'requires_feature_ids', 'provides_feature_ids'])
|
|
121
|
-
|| !isTodoIdentifier(task.task_id) || !
|
|
122
|
-
|| !identifiers(task.
|
|
123
|
-
|| !identifiers(task.provides_feature_ids, { nonempty: true })) {
|
|
122
|
+
|| !isTodoIdentifier(task.task_id) || !identifiers(task.requires_feature_ids)
|
|
123
|
+
|| !identifiers(task.provides_feature_ids)) {
|
|
124
124
|
fail('task_invalid', `/tasks/${index}`);
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
126
|
+
if (!authoredIds.has(task.task_id)) {
|
|
127
|
+
finding('task_invalid', `/tasks/${index}`, { task_id: task.task_id, cause: 'task_not_authored' });
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (task.provides_feature_ids.length === 0) {
|
|
131
|
+
finding('task_invalid', `/tasks/${index}`, { task_id: task.task_id, cause: 'provides_empty' });
|
|
132
|
+
}
|
|
133
|
+
if (taskMap.has(task.task_id)) {
|
|
134
|
+
finding('task_duplicate', `/tasks/${index}/task_id`, { task_id: task.task_id });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
127
137
|
taskMap.set(task.task_id, task);
|
|
128
138
|
}
|
|
139
|
+
for (const id of [...authoredIds].filter((candidate) => !taskMap.has(candidate))) {
|
|
140
|
+
finding('task_coverage_missing', '/tasks', { task_id: id });
|
|
141
|
+
}
|
|
129
142
|
for (const [index, task] of chain.tasks.entries()) {
|
|
143
|
+
if (taskMap.get(task.task_id) !== task) continue;
|
|
130
144
|
for (const id of task.provides_feature_ids) {
|
|
131
145
|
const feature = features.get(id);
|
|
132
146
|
if (feature?.provider.kind !== 'task' || feature.provider.task_id !== task.task_id) {
|
|
133
|
-
|
|
147
|
+
finding('task_output_provider_mismatch', `/tasks/${index}/provides_feature_ids`, { feature_id: id });
|
|
134
148
|
}
|
|
135
149
|
}
|
|
136
150
|
const supplied = new Set(task.provides_feature_ids);
|
|
137
151
|
const needed = [...new Set(task.provides_feature_ids.flatMap((id) =>
|
|
138
|
-
features.get(id)
|
|
152
|
+
(features.get(id)?.requires_feature_ids ?? []).filter((required) => !supplied.has(required))))];
|
|
139
153
|
if (needed.some((id) => !task.requires_feature_ids.includes(id))) {
|
|
140
|
-
|
|
154
|
+
finding('task_inputs_incomplete', `/tasks/${index}/requires_feature_ids`, {
|
|
141
155
|
expected: needed.sort(), actual: task.requires_feature_ids,
|
|
142
156
|
});
|
|
143
157
|
}
|
|
@@ -146,7 +160,7 @@ export function validatePlanBackchain(chain, authoring) {
|
|
|
146
160
|
if (feature.provider.kind !== 'task') continue;
|
|
147
161
|
const task = taskMap.get(feature.provider.task_id);
|
|
148
162
|
if (task === undefined || !task.provides_feature_ids.includes(feature.feature_id)) {
|
|
149
|
-
|
|
163
|
+
finding('feature_provider_missing', `/features/${feature.feature_id}/provider`, {
|
|
150
164
|
feature_id: feature.feature_id,
|
|
151
165
|
});
|
|
152
166
|
}
|
|
@@ -154,42 +168,61 @@ export function validatePlanBackchain(chain, authoring) {
|
|
|
154
168
|
const reached = new Set();
|
|
155
169
|
const visiting = new Set();
|
|
156
170
|
const visit = (id) => {
|
|
157
|
-
if (!features.has(id))
|
|
158
|
-
|
|
171
|
+
if (!features.has(id)) {
|
|
172
|
+
finding('required_feature_missing', '/goal/required_feature_ids', { feature_id: id });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (visiting.has(id)) {
|
|
176
|
+
finding('feature_cycle', `/features/${id}/requires_feature_ids`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
159
179
|
if (reached.has(id)) return;
|
|
160
180
|
visiting.add(id);
|
|
161
181
|
const feature = features.get(id);
|
|
162
182
|
for (const required of feature.requires_feature_ids) visit(required);
|
|
163
183
|
if (feature.provider.kind === 'task') {
|
|
164
|
-
for (const required of taskMap.get(feature.provider.task_id)
|
|
184
|
+
for (const required of taskMap.get(feature.provider.task_id)?.requires_feature_ids ?? []) visit(required);
|
|
165
185
|
}
|
|
166
186
|
visiting.delete(id);
|
|
167
187
|
reached.add(id);
|
|
168
188
|
};
|
|
169
189
|
for (const id of chain.goal.required_feature_ids) visit(id);
|
|
170
190
|
if (reached.size !== features.size) {
|
|
171
|
-
|
|
191
|
+
finding('orphan_feature', '/features', {
|
|
172
192
|
feature_ids: [...features.keys()].filter((id) => !reached.has(id)).sort(),
|
|
173
193
|
});
|
|
174
194
|
}
|
|
175
195
|
const edges = new Set(authoring.hard_dependencies.map(({ from, to }) =>
|
|
176
196
|
`${from.project_id}/${from.plan_key}/${from.task_id}->${to.project_id}/${to.plan_key}/${to.task_id}`));
|
|
177
197
|
for (const [index, task] of chain.tasks.entries()) {
|
|
198
|
+
if (taskMap.get(task.task_id) !== task) continue;
|
|
178
199
|
for (const id of task.requires_feature_ids) {
|
|
179
200
|
const feature = features.get(id);
|
|
180
|
-
if (feature === undefined)
|
|
181
|
-
feature_id: id
|
|
182
|
-
|
|
201
|
+
if (feature === undefined) {
|
|
202
|
+
finding('task_input_missing', `/tasks/${index}/requires_feature_ids`, { feature_id: id });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
183
205
|
if (feature.provider.kind !== 'task') continue;
|
|
184
206
|
const sourceId = feature.provider.task_id;
|
|
185
|
-
if (sourceId === task.task_id)
|
|
207
|
+
if (sourceId === task.task_id) {
|
|
208
|
+
finding('task_requires_own_output', `/tasks/${index}/requires_feature_ids`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
186
211
|
const edge = `${chain.project_id}/${chain.plan_key}/${sourceId}->${chain.project_id}/${chain.plan_key}/${task.task_id}`;
|
|
187
|
-
if (!edges.has(edge))
|
|
212
|
+
if (!edges.has(edge)) finding('dependency_missing', `/tasks/${index}/requires_feature_ids`, {
|
|
188
213
|
feature_id: id, from_task_id: sourceId, to_task_id: task.task_id,
|
|
189
214
|
});
|
|
190
215
|
}
|
|
191
216
|
}
|
|
192
|
-
return { features, tasks: taskMap };
|
|
217
|
+
return { features, tasks: taskMap, findings: sortFindings(found) };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 決定的な順序(pointer, reason, 正準JSON)で並べ、同一の指摘は1件にする。 */
|
|
221
|
+
function sortFindings(list) {
|
|
222
|
+
const keyed = new Map(list.map((entry) => [canonicalizeTodoArtifact(entry), entry]));
|
|
223
|
+
return [...keyed.entries()].sort(([left, a], [right, b]) =>
|
|
224
|
+
a.pointer.localeCompare(b.pointer) || a.reason.localeCompare(b.reason)
|
|
225
|
+
|| (left < right ? -1 : left > right ? 1 : 0)).map(([, entry]) => entry);
|
|
193
226
|
}
|
|
194
227
|
|
|
195
228
|
/** 作業者に下流の用途まで渡す。文の生成は入力済みの定義を転記するだけ。 */
|
|
@@ -204,6 +237,7 @@ export function backchainTaskMemo(chain, taskId) {
|
|
|
204
237
|
'必要とする機能:',
|
|
205
238
|
...task.requires_feature_ids.map((id) => {
|
|
206
239
|
const feature = features.get(id);
|
|
240
|
+
if (feature === undefined) return `- ${id}: (機能の定義が無い)`;
|
|
207
241
|
const provider = feature.provider.kind === 'task'
|
|
208
242
|
? `工程 ${feature.provider.task_id}`
|
|
209
243
|
: feature.provider.kind === 'existing'
|
|
@@ -214,6 +248,7 @@ export function backchainTaskMemo(chain, taskId) {
|
|
|
214
248
|
'作る機能:',
|
|
215
249
|
...task.provides_feature_ids.map((id) => {
|
|
216
250
|
const feature = features.get(id);
|
|
251
|
+
if (feature === undefined) return `- ${id}: (機能の定義が無い)`;
|
|
217
252
|
const consumers = chain.tasks.filter((other) => other.requires_feature_ids.includes(id))
|
|
218
253
|
.map(({ task_id: consumerId }) => consumerId).sort();
|
|
219
254
|
return `- ${id}: ${feature.capability}。受入条件: ${feature.acceptance}。後続: ${consumers.join(', ') || '最終成果'}`;
|
|
@@ -290,13 +325,13 @@ export async function readTaskBackchainContext({ repoRoot, plan, taskId }) {
|
|
|
290
325
|
const downstream = chain.tasks.filter((other) => other.task_id !== taskId
|
|
291
326
|
&& other.requires_feature_ids.some((id) => task.provides_feature_ids.includes(id)))
|
|
292
327
|
.map(({ task_id: id }) => id).sort();
|
|
293
|
-
const required = task.requires_feature_ids.map((id) => features.get(id));
|
|
328
|
+
const required = task.requires_feature_ids.map((id) => features.get(id)).filter(Boolean);
|
|
294
329
|
return {
|
|
295
330
|
schema: 'lattice.todo_feature_context.v1',
|
|
296
331
|
plan_key: chain.plan_key, plan_version: chain.plan_version,
|
|
297
332
|
goal: chain.goal,
|
|
298
333
|
requires: required,
|
|
299
|
-
provides: task.provides_feature_ids.map((id) => features.get(id)),
|
|
334
|
+
provides: task.provides_feature_ids.map((id) => features.get(id)).filter(Boolean),
|
|
300
335
|
downstream_task_ids: downstream,
|
|
301
336
|
unknown_feature_ids: required.filter(({ provider }) => provider.kind === 'unknown')
|
|
302
337
|
.map(({ feature_id: id }) => id),
|
|
@@ -380,7 +415,7 @@ function taskSignature(chain, taskId) {
|
|
|
380
415
|
return canonicalizeTodoArtifact({
|
|
381
416
|
requires_feature_ids: task.requires_feature_ids,
|
|
382
417
|
provides_feature_ids: task.provides_feature_ids,
|
|
383
|
-
features: ids.map((id) => byId.get(id)),
|
|
418
|
+
features: ids.map((id) => byId.get(id) ?? null),
|
|
384
419
|
});
|
|
385
420
|
}
|
|
386
421
|
|
|
@@ -449,7 +484,7 @@ export function compilePhaseMigration(previousPlan, desiredSeed, taskMigration)
|
|
|
449
484
|
];
|
|
450
485
|
}
|
|
451
486
|
|
|
452
|
-
async function compileBackchainRevision({ repoRoot, member, chain, authoring }) {
|
|
487
|
+
export async function compileBackchainRevision({ repoRoot, member, chain, authoring }) {
|
|
453
488
|
if (!['lattice.todo_plan.v7', DONE_CONDITION_PLAN_SCHEMA].includes(member.plan.schema)) {
|
|
454
489
|
fail('predecessor_plan_schema_unsupported', '/plan_key', {
|
|
455
490
|
actual: member.plan.schema, next_action: 'author_a_new_backchain_plan',
|
|
@@ -474,7 +509,7 @@ async function compileBackchainRevision({ repoRoot, member, chain, authoring })
|
|
|
474
509
|
const successorChain = { ...chain, plan_version: version, chain_digest: '' };
|
|
475
510
|
successorChain.chain_digest = todoSelfDigest(successorChain, 'chain_digest');
|
|
476
511
|
const desiredPlan = buildTodoPlan({ ...seed, plan_version: version });
|
|
477
|
-
validatePlanBackchain(successorChain, {
|
|
512
|
+
const { findings } = validatePlanBackchain(successorChain, {
|
|
478
513
|
schema: CREATE_SCHEMA, project_id: desiredPlan.project_id,
|
|
479
514
|
plan_key: desiredPlan.plan_key, plan_version: desiredPlan.plan_version,
|
|
480
515
|
tasks: desiredPlan.tasks, hard_dependencies: desiredPlan.hard_dependencies,
|
|
@@ -489,7 +524,7 @@ async function compileBackchainRevision({ repoRoot, member, chain, authoring })
|
|
|
489
524
|
if (!validatePhaseTodoRevision(revision)) {
|
|
490
525
|
fail('revision_invalid', '/revision', { diagnosis: explainPhaseTodoRevision(revision) });
|
|
491
526
|
}
|
|
492
|
-
return revision;
|
|
527
|
+
return { revision, findings };
|
|
493
528
|
}
|
|
494
529
|
|
|
495
530
|
async function activeIntentUnchanged({ repoRoot, member, chain, authoring }) {
|
|
@@ -538,10 +573,10 @@ export async function rebindCarriedWork({ repoRoot, planKey, env,
|
|
|
538
573
|
export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false, env = process.env }) {
|
|
539
574
|
const repoRoot = gitRoot(cwd);
|
|
540
575
|
const chain = await readAuthoringJsonFile(repoRoot, inputRef, { invalidCode: 'PLAN_BACKCHAIN_INVALID' });
|
|
541
|
-
const authoring = await readAuthoringJsonFile(repoRoot, chain.authoring_ref, {
|
|
576
|
+
const authoring = completeCreateInput(await readAuthoringJsonFile(repoRoot, chain.authoring_ref, {
|
|
542
577
|
invalidCode: 'PLAN_BACKCHAIN_INVALID',
|
|
543
|
-
});
|
|
544
|
-
validatePlanBackchain(chain, authoring);
|
|
578
|
+
}), { env, now: new Date() });
|
|
579
|
+
const { findings: featureChainFindings } = validatePlanBackchain(chain, authoring);
|
|
545
580
|
await verifyExistingFeatureReferences(repoRoot, chain);
|
|
546
581
|
let member = null;
|
|
547
582
|
let store = null;
|
|
@@ -560,7 +595,7 @@ export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false,
|
|
|
560
595
|
repoRoot, member, chain, authoring,
|
|
561
596
|
});
|
|
562
597
|
const revision = member === null || unchanged ? null
|
|
563
|
-
: await compileBackchainRevision({ repoRoot, member, chain, authoring });
|
|
598
|
+
: (await compileBackchainRevision({ repoRoot, member, chain, authoring })).revision;
|
|
564
599
|
const amended = revision === null ? attachBackchainMemos(chain, authoring) : null;
|
|
565
600
|
if (!unchanged && revision === null) {
|
|
566
601
|
try { buildTodoPlan({ ...planSeed(amended, null), plan_version: chain.plan_version }); }
|
|
@@ -578,6 +613,7 @@ export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false,
|
|
|
578
613
|
operation: unchanged ? 'unchanged' : revision !== null ? 'revise'
|
|
579
614
|
: store === null ? 'create' : 'add',
|
|
580
615
|
task_migration: revision?.task_migration ?? null,
|
|
616
|
+
feature_chain_findings: featureChainFindings,
|
|
581
617
|
result_digest: '',
|
|
582
618
|
};
|
|
583
619
|
checked.result_digest = todoSelfDigest(checked, 'result_digest');
|
|
@@ -633,6 +669,7 @@ export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false,
|
|
|
633
669
|
unknown_feature_ids: unknownFeatureIds,
|
|
634
670
|
chain_digest: effectiveChain.chain_digest, authoring_result: created,
|
|
635
671
|
rebound_task_ids: reboundTaskIds,
|
|
672
|
+
feature_chain_findings: featureChainFindings,
|
|
636
673
|
operation: unchanged ? 'unchanged' : revision !== null ? 'revise'
|
|
637
674
|
: store === null ? 'create' : 'add',
|
|
638
675
|
journal_head_digest: finalMember.journal.events.at(-1).event_digest,
|
package/src/plan-revise.mjs
CHANGED
|
@@ -3,9 +3,11 @@ import path from 'node:path';
|
|
|
3
3
|
|
|
4
4
|
import { canonicalizeTodoArtifact, exactRecord, isTodoIdentifier, todoSelfDigest } from './todo-contracts.mjs';
|
|
5
5
|
import { gitSync } from './git-process.mjs';
|
|
6
|
-
import { readAuthoringJsonFile,
|
|
6
|
+
import { completeCreateInput, readAuthoringJsonFile, resolveTodoActor } from './todo-authoring-input.mjs';
|
|
7
7
|
import { validatePlanCreateInput } from './project-cli.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
compileBackchainRevision, planSeed, readPlanBackchainBinding, rebindCarriedWork,
|
|
10
|
+
} from './plan-backchain.mjs';
|
|
9
11
|
import {
|
|
10
12
|
applyPhaseTodoRevision, buildTodoPlan, createTodoStoreWriter, readTodoStore, TodoStoreError,
|
|
11
13
|
} from './todo-store.mjs';
|
|
@@ -136,11 +138,43 @@ async function appendRevisionHistoryNotes({ repoRoot, revision, notes, actor })
|
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 継続方針の算出(u03p N5)。先行planの全taskについて、desiredに在れば作成者の carry/reset
|
|
145
|
+
* (無ければcarry)、無ければretire。desiredの在不在が優先され、読めない入力だけを拒否する。
|
|
146
|
+
*/
|
|
147
|
+
function computeContinuity(member, input, desiredIds) {
|
|
148
|
+
const entries = input.continuity ?? [];
|
|
149
|
+
if (!Array.isArray(entries)) fail('plan_revise_continuity_invalid', '/continuity');
|
|
150
|
+
const oldIds = new Set(member.plan.tasks.map(({ task_id }) => task_id));
|
|
151
|
+
const decisions = new Map();
|
|
152
|
+
for (const [index, entry] of entries.entries()) {
|
|
153
|
+
if (!isRecord(entry) || !Object.keys(entry).every((key) => ['task_id', 'policy', 'reason'].includes(key))
|
|
154
|
+
|| !isTodoIdentifier(entry.task_id) || !['carry', 'reset', 'retire'].includes(entry.policy)
|
|
155
|
+
|| (entry.reason !== undefined && (typeof entry.reason !== 'string' || entry.reason.trim().length === 0))
|
|
156
|
+
|| !oldIds.has(entry.task_id) || decisions.has(entry.task_id)) {
|
|
157
|
+
fail('plan_revise_continuity_invalid', `/continuity/${index}`);
|
|
158
|
+
}
|
|
159
|
+
decisions.set(entry.task_id, entry);
|
|
160
|
+
}
|
|
161
|
+
return member.plan.tasks.map(({ task_id: taskId }) => {
|
|
162
|
+
const entry = decisions.get(taskId);
|
|
163
|
+
const policy = !desiredIds.has(taskId) ? 'retire'
|
|
164
|
+
: entry === undefined || entry.policy === 'retire' ? 'carry' : entry.policy;
|
|
165
|
+
return { task_id: taskId, policy,
|
|
166
|
+
reason: entry?.policy === policy && entry.reason !== undefined ? entry.reason : `computed ${policy}` };
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 入力の検査と補完。desired(補完済み)と算出した継続方針を返す。 */
|
|
171
|
+
export function resolvePlanRevision({ member, input, env = process.env, now = new Date() }) {
|
|
172
|
+
if (!exactRecord(input, ['schema', 'desired', 'continuity'])
|
|
173
|
+
&& !exactRecord(input, ['schema', 'desired'])) {
|
|
141
174
|
fail('plan_revise_schema_invalid', '/', { expected: INPUT_SCHEMA });
|
|
142
175
|
}
|
|
143
|
-
|
|
176
|
+
if (input.schema !== INPUT_SCHEMA) fail('plan_revise_schema_invalid', '/', { expected: INPUT_SCHEMA });
|
|
177
|
+
const desired = completeCreateInput(input.desired, { env, now });
|
|
144
178
|
try { validatePlanCreateInput(desired); }
|
|
145
179
|
catch (error) {
|
|
146
180
|
if (typeof error?.detail?.pointer === 'string') {
|
|
@@ -148,6 +182,13 @@ export function compilePlanRevision({ member, input }) {
|
|
|
148
182
|
}
|
|
149
183
|
throw error;
|
|
150
184
|
}
|
|
185
|
+
// 軽量改訂は設計メモを持つ現行plan(v7/v8)の後継を作る。v1〜v3入力は新規作成だけに使える。
|
|
186
|
+
if (!['lattice.plan_create_input.v4', 'lattice.plan_create_input.v5'].includes(desired.schema)) {
|
|
187
|
+
fail('plan_revise_desired_schema_unsupported', '/desired/schema', {
|
|
188
|
+
accepted: ['lattice.plan_create_input.v4', 'lattice.plan_create_input.v5'],
|
|
189
|
+
actual: desired.schema, next_action: 'lattice plan create --schema-version 5 --json',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
151
192
|
if (member === undefined) fail('plan_not_active', '/desired/plan_key');
|
|
152
193
|
if (member.plan.schema === 'lattice.todo_plan.v6'
|
|
153
194
|
|| member.journal.events[0].schema === 'lattice.todo_event.v2'
|
|
@@ -162,32 +203,21 @@ export function compilePlanRevision({ member, input }) {
|
|
|
162
203
|
if (desired.project_id !== member.plan.project_id || desired.plan_key !== member.plan.plan_key) {
|
|
163
204
|
fail('plan_revise_identity_mismatch', '/desired/plan_key');
|
|
164
205
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const desiredIds = new Set(desired.tasks.map(({ task_id }) => task_id));
|
|
182
|
-
const taskMigration = member.plan.tasks.map(({ task_id: id }) => {
|
|
183
|
-
const policy = decisions.get(id);
|
|
184
|
-
if ((policy === 'retire') === desiredIds.has(id)) {
|
|
185
|
-
fail('plan_revise_removed_task_mismatch', '/continuity', { task_id: id });
|
|
186
|
-
}
|
|
187
|
-
return { from_task_id: id, to_task_id: policy === 'retire' ? 'removed' : id,
|
|
188
|
-
state_policy: policy === 'retire' ? 'removed'
|
|
189
|
-
: policy === 'carry' ? 'carry_reconciled_metadata' : 'reset_pending' };
|
|
190
|
-
});
|
|
206
|
+
const continuity = computeContinuity(member, input,
|
|
207
|
+
new Set(desired.tasks.map(({ task_id }) => task_id)));
|
|
208
|
+
return { desired, continuity };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function compilePlanRevision({ member, input, env, now }) {
|
|
212
|
+
const { desired, continuity } = resolvePlanRevision({ member, input, env, now });
|
|
213
|
+
return compileLightRevision({ member, desired, continuity });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function compileLightRevision({ member, desired, continuity }) {
|
|
217
|
+
const taskMigration = continuity.map(({ task_id: id, policy }) => ({
|
|
218
|
+
from_task_id: id, to_task_id: policy === 'retire' ? 'removed' : id,
|
|
219
|
+
state_policy: policy === 'retire' ? 'removed'
|
|
220
|
+
: policy === 'carry' ? 'carry_reconciled_metadata' : 'reset_pending' }));
|
|
191
221
|
const predecessor = {
|
|
192
222
|
plan_digest: member.plan.plan_digest,
|
|
193
223
|
journal_head_digest: member.journal.events.at(-1).event_digest,
|
|
@@ -210,32 +240,88 @@ export function compilePlanRevision({ member, input }) {
|
|
|
210
240
|
return revision;
|
|
211
241
|
}
|
|
212
242
|
|
|
243
|
+
/**
|
|
244
|
+
* backchain束縛plan(u03p N3): 束縛済みの機能連鎖を後継の元にする。tasksはdesiredの各taskに1件
|
|
245
|
+
* (残るtaskは連鎖の項目を保ち、新しいtaskは空の項目)、continuityは算出値。目標と機能は変えない。
|
|
246
|
+
*/
|
|
247
|
+
function successorBackchain(chain, desired, continuity) {
|
|
248
|
+
const entries = new Map(chain.tasks.map((entry) => [entry.task_id, entry]));
|
|
249
|
+
const successor = { ...chain, continuity,
|
|
250
|
+
tasks: desired.tasks.map(({ task_id: taskId }) => entries.get(taskId)
|
|
251
|
+
?? { task_id: taskId, requires_feature_ids: [], provides_feature_ids: [] }),
|
|
252
|
+
chain_digest: '' };
|
|
253
|
+
successor.chain_digest = todoSelfDigest(successor, 'chain_digest');
|
|
254
|
+
return successor;
|
|
255
|
+
}
|
|
256
|
+
|
|
213
257
|
export async function planReviseSchema() {
|
|
214
258
|
return JSON.parse(await readFile(new URL('../docs/schemas/lattice.plan_revise_input.v1.schema.json', import.meta.url)));
|
|
215
259
|
}
|
|
216
260
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
261
|
+
/**
|
|
262
|
+
* 軽量改訂でそのまま表せるmemberか(a14)。resolvePlanRevisionと作成入力の検査が断る形
|
|
263
|
+
* (v7/v8以外・源泉束縛・旧event・compile_binding付きtask)ならfalse。書く前の判定にだけ使う。
|
|
264
|
+
*/
|
|
265
|
+
export function lightRevisionExpresses(member) {
|
|
266
|
+
return ['lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(member.plan.schema)
|
|
267
|
+
&& member.journal.events[0]?.schema !== 'lattice.todo_event.v2'
|
|
268
|
+
&& member.plan.tasks.every((task) => task.narrative_anchor === null && task.compile_binding === null);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 現行plan(v7/v8)をそのまま作成入力にする(a14)。辺の追加・削除など、planの一部だけを変える
|
|
273
|
+
* 軽量改訂の「いまの姿」を作る。v8はcreate v5、v7はcreate v4。continuityは付けない(全taskがcarry)。
|
|
274
|
+
* 源泉束縛planと旧schemaは `plan revise` と同じ理由で拒否する。
|
|
275
|
+
*/
|
|
276
|
+
export function desiredFromPlan(plan, { env = process.env, now = new Date() } = {}) {
|
|
277
|
+
if (plan.schema === 'lattice.todo_plan.v6' || plan.tasks.some((task) => task.narrative_anchor !== null)) {
|
|
278
|
+
fail('plan_revise_requires_source_revision', '/desired/tasks', {
|
|
279
|
+
next_action: `lattice todo revise-phase --plan ${plan.plan_key} --input <phase-revision.json>`,
|
|
231
280
|
});
|
|
232
281
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
282
|
+
if (!['lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(plan.schema)) {
|
|
283
|
+
fail('predecessor_plan_schema_unsupported', '/desired/plan_key');
|
|
284
|
+
}
|
|
285
|
+
const edge = ({ from, to }) => ({
|
|
286
|
+
from: { project_id: from.project_id, plan_key: from.plan_key, task_id: from.task_id },
|
|
287
|
+
to: { project_id: to.project_id, plan_key: to.plan_key, task_id: to.task_id } });
|
|
288
|
+
return {
|
|
289
|
+
schema: plan.schema === 'lattice.todo_plan.v8'
|
|
290
|
+
? 'lattice.plan_create_input.v5' : 'lattice.plan_create_input.v4',
|
|
291
|
+
project_id: plan.project_id, plan_key: plan.plan_key, plan_version: plan.plan_version,
|
|
292
|
+
actor: resolveTodoActor(env), recorded_at: now.toISOString(),
|
|
293
|
+
tasks: plan.tasks, phases: plan.phases,
|
|
294
|
+
hard_dependencies: plan.hard_dependencies.map(edge), joins: plan.joins,
|
|
295
|
+
phase_accept_dependencies: plan.phase_accept_dependencies,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 軽量改訂の適用。入力(`plan_revise_input.v1`)を補完・検査し、算出した継続方針で改訂を作り、
|
|
301
|
+
* 公開→履歴note→作業中taskの結び直しまで行って、結果artifactを返す(印字はしない)。
|
|
302
|
+
* notes: 履歴noteへ足す plan scope の追加note([{task_id, body}])。公開後に改訂noteと同じ経路で追記する。
|
|
303
|
+
*/
|
|
304
|
+
export async function applyPlanRevision({
|
|
305
|
+
repoRoot, input, env = process.env, dryRun = false, notes: extraNotes = [],
|
|
306
|
+
}) {
|
|
307
|
+
const store = await readTodoStore({ repoRoot });
|
|
308
|
+
const member = store.members.find(({ plan }) => plan.plan_key === input?.desired?.plan_key);
|
|
309
|
+
const { desired, continuity } = resolvePlanRevision({ member, input, env, now: new Date() });
|
|
310
|
+
// 集合の並びは正準化済みなので、同じ内容の別の並びは「変更なし」になる。
|
|
311
|
+
const unchanged = continuity.every(({ policy }) => policy === 'carry')
|
|
236
312
|
&& canonicalizeTodoArtifact(planSeed(desired, null, member.plan))
|
|
237
313
|
=== canonicalizeTodoArtifact(planSeed(member.plan, null));
|
|
238
|
-
|
|
314
|
+
const binding = await readPlanBackchainBinding({ repoRoot, plan: member.plan });
|
|
315
|
+
let revision;
|
|
316
|
+
let featureChainFindings = null;
|
|
317
|
+
if (binding !== null && !unchanged) {
|
|
318
|
+
({ revision, findings: featureChainFindings } = await compileBackchainRevision({
|
|
319
|
+
repoRoot, member, authoring: desired,
|
|
320
|
+
chain: successorBackchain(binding.chain, desired, continuity) }));
|
|
321
|
+
} else {
|
|
322
|
+
revision = compileLightRevision({ member, desired, continuity });
|
|
323
|
+
if (!unchanged && !validatePhaseTodoRevision(revision)) fail('plan_revise_artifact_invalid', '/');
|
|
324
|
+
}
|
|
239
325
|
let applied = null;
|
|
240
326
|
let reboundTaskIds = [];
|
|
241
327
|
if (!dryRun) {
|
|
@@ -245,8 +331,9 @@ export async function runPlanRevise({ cwd, inputRef, stdout, dryRun = false, env
|
|
|
245
331
|
actor: desired.actor, recordedAt: desired.recorded_at,
|
|
246
332
|
});
|
|
247
333
|
await appendRevisionHistoryNotes({ repoRoot, revision, actor: desired.actor,
|
|
248
|
-
notes: planRevisionHistoryNotes({ previousPlan: member.plan,
|
|
249
|
-
successorPlan: revision.desired_plan, continuity
|
|
334
|
+
notes: [...planRevisionHistoryNotes({ previousPlan: member.plan,
|
|
335
|
+
successorPlan: revision.desired_plan, continuity }),
|
|
336
|
+
...extraNotes.map(({ task_id: taskId, body: text }) => ({ scope: 'plan', task_id: taskId, body: text }))] });
|
|
250
337
|
}
|
|
251
338
|
try {
|
|
252
339
|
reboundTaskIds = await rebindCarriedWork({ repoRoot, planKey: revision.plan_key, env,
|
|
@@ -268,9 +355,23 @@ export async function runPlanRevise({ cwd, inputRef, stdout, dryRun = false, env
|
|
|
268
355
|
project_id: revision.project_id, plan_key: revision.plan_key,
|
|
269
356
|
plan_version: unchanged ? member.plan.plan_version : revision.desired_plan.plan_version,
|
|
270
357
|
dry_run: dryRun, revision: unchanged ? null : revision, applied,
|
|
271
|
-
continuity
|
|
358
|
+
continuity, rebound_task_ids: reboundTaskIds,
|
|
359
|
+
...(featureChainFindings === null ? {} : { feature_chain_findings: featureChainFindings }),
|
|
360
|
+
result_digest: '',
|
|
272
361
|
};
|
|
273
362
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export async function runPlanRevise({ cwd, inputRef, stdout, dryRun = false, env = process.env }) {
|
|
367
|
+
let repoRoot;
|
|
368
|
+
try {
|
|
369
|
+
repoRoot = path.resolve(gitSync(['rev-parse', '--show-toplevel'], {
|
|
370
|
+
cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
|
|
371
|
+
}).replace(/\r?\n$/u, ''));
|
|
372
|
+
} catch { throw new TodoStoreError('REPO_UNRESOLVED', 'git_toplevel_unresolved'); }
|
|
373
|
+
const input = await readAuthoringJsonFile(repoRoot, inputRef, { invalidCode: 'INPUT_INVALID' });
|
|
374
|
+
const result = await applyPlanRevision({ repoRoot, input, env, dryRun });
|
|
274
375
|
stdout.write(`${JSON.stringify(result)}\n`);
|
|
275
376
|
return 0;
|
|
276
377
|
}
|