@quolu/lattice 0.109.0 → 0.110.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/package.json +1 -1
- package/src/cli-help.mjs +8 -0
- package/src/cli-refusal-guidance.mjs +3 -0
- package/src/function-split-verify.mjs +396 -0
- package/src/plan-backchain.mjs +18 -7
- package/src/plan-revise.mjs +14 -11
- package/src/project-cli.mjs +3 -0
- package/src/seam-apply.mjs +2 -2
- package/src/sensor-adapter.mjs +14 -7
- package/src/todo-cli.mjs +113 -10
- package/src/todo-contracts.mjs +56 -4
- package/src/todo-function-split.mjs +234 -0
- package/src/todo-gantt-html-independence.mjs +2 -2
- package/src/todo-gantt-html-shared.mjs +4 -1
- package/src/todo-gantt-html.mjs +4 -2
- package/src/todo-note-store.mjs +3 -2
- package/src/todo-revision.mjs +5 -5
- package/src/todo-split-labels.mjs +26 -0
- package/src/todo-split-start.mjs +100 -0
- package/src/todo-split-store.mjs +100 -0
- package/src/todo-store-view.mjs +3 -2
- package/src/todo-store.mjs +40 -25
- package/src/todo-version-compact.mjs +22 -13
- package/src/todo-version-memo.mjs +3 -2
package/src/todo-cli.mjs
CHANGED
|
@@ -204,6 +204,11 @@ import { dependencyNoteBody, todoAddNoteBody } from './todo-revision-note.mjs';
|
|
|
204
204
|
import { buildDeclarationRow, declaredPaths, proposeFromText, resolveDeclaredRanges } from './todo-declaration.mjs';
|
|
205
205
|
import { anchorsOf, claimsOf, judgeTask, neededAnchors, rangeIndex, relationView } from './todo-judgment.mjs';
|
|
206
206
|
import { readTodoRelationSummary, readTodoTaskRelations, transactTodoRelations } from './todo-relation-store.mjs';
|
|
207
|
+
import { planSplitHold, splitGuide } from './todo-split-start.mjs';
|
|
208
|
+
import { cutCost } from './function-split-verify.mjs';
|
|
209
|
+
import { reorganizeNotSplit, splitDoneGate, verifySplit } from './todo-function-split.mjs';
|
|
210
|
+
import { splitLabels, splitLabelsOf } from './todo-split-labels.mjs';
|
|
211
|
+
import { readTodoSplit } from './todo-split-store.mjs';
|
|
207
212
|
import { readTodoParallelCandidatesForStatus } from './todo-parallel-candidates.mjs';
|
|
208
213
|
import { commitTodoStoreMutation } from './todo-store-git-transaction.mjs';
|
|
209
214
|
import { repairTodoStoreWorktreeEol } from './todo-store-worktree-eol.mjs';
|
|
@@ -305,7 +310,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
|
|
|
305
310
|
'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
306
311
|
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
307
312
|
'unblock', 'retire', 'done', 'reopen', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
308
|
-
'retract', 'dependency', 'predecessor', 'connect', 'add', 'notice', 'wait', 'blockers', 'compact',
|
|
313
|
+
'retract', 'dependency', 'predecessor', 'connect', 'add', 'notice', 'wait', 'blockers', 'compact', 'function-split',
|
|
309
314
|
]);
|
|
310
315
|
|
|
311
316
|
function typedArgumentFailure(stderr, code, message, detail, context = {}) {
|
|
@@ -359,6 +364,8 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
359
364
|
'phase review': PHASE_REASON_FLAG_SPEC,
|
|
360
365
|
'phase close-unaudited': PHASE_REASON_FLAG_SPEC,
|
|
361
366
|
split: Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
367
|
+
'function-split verify': Object.freeze({ known: ['plan', 'task', 'commit', 'base', 'map'], required: ['plan', 'task', 'commit', 'map'] }),
|
|
368
|
+
'function-split decline': REASON_FLAG_SPEC,
|
|
362
369
|
note: NOTE_FLAG_SPEC,
|
|
363
370
|
// a28: the rest of the writes, and the reads whose --json is optional (their output is JSON either way).
|
|
364
371
|
'phase accept': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message'], required: ['plan', 'phase'] }),
|
|
@@ -390,7 +397,7 @@ const TODO_SUBCOMMANDS = Object.freeze({
|
|
|
390
397
|
connect: { names: ['condition', 'priority'], example: 'priority' },
|
|
391
398
|
phase: { names: ['status', 'review', 'accept', 'reject', 'reopen', 'close-unaudited', 'baseline'], example: 'review' },
|
|
392
399
|
});
|
|
393
|
-
const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', 'independence', 'note', 'structure'];
|
|
400
|
+
const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', 'independence', 'note', 'structure', 'function-split'];
|
|
394
401
|
const IDENTIFIER_FLAGS = ['plan', 'task', 'phase', 'from-plan', 'from-task', 'to-plan', 'to-task'];
|
|
395
402
|
// The shared table is FLAG_PLACEHOLDER (cli-refusal-guidance, a27).
|
|
396
403
|
const placeholder = (name) => FLAG_PLACEHOLDER[name] ?? `<${name}>`;
|
|
@@ -563,7 +570,7 @@ function supportsAtomicStoreCommit(argv) {
|
|
|
563
570
|
if (command === 'snapshot') return argv[1] === '--rebuild';
|
|
564
571
|
if (command === 'migrate') return !argv.includes('--dry-run') && !argv.includes('--schema');
|
|
565
572
|
if (['revise', 'split', 'revise-set', 'revise-phase', 'start', 'retract', 'block',
|
|
566
|
-
'unblock', 'retire', 'done', 'reopen', 'add'].includes(command)) return true;
|
|
573
|
+
'unblock', 'retire', 'done', 'reopen', 'add', 'function-split'].includes(command)) return true;
|
|
567
574
|
if (command === 'phase') return argv[1] !== 'status';
|
|
568
575
|
return false;
|
|
569
576
|
}
|
|
@@ -1278,6 +1285,7 @@ async function displayRead(repoRoot, env) {
|
|
|
1278
1285
|
const externalTasks = display.store ? (await readTodoExternalTasks(display.store, env)).external_tasks : [];
|
|
1279
1286
|
return { schema: 'lattice.todo_display_read_result.v1', ...display, external_tasks: externalTasks,
|
|
1280
1287
|
trees: display.store ? projectTodoTrees(display.store) : [],
|
|
1288
|
+
...(display.store && splitLabels(display.store).length > 0 ? { labels: splitLabels(display.store) } : {}),
|
|
1281
1289
|
connections: display.store ? await displayConnections(repoRoot, { ...display.store, external_tasks: externalTasks }) : [] };
|
|
1282
1290
|
}
|
|
1283
1291
|
|
|
@@ -1351,8 +1359,14 @@ async function startTask({
|
|
|
1351
1359
|
const startAdvice = await startAdvisory({
|
|
1352
1360
|
repoRoot, store, projection, planKey, taskId: resolvedTaskId,
|
|
1353
1361
|
});
|
|
1354
|
-
const
|
|
1362
|
+
const got = await readTaskRelations({ repoRoot, planKey, taskId: resolvedTaskId });
|
|
1363
|
+
const relations = relationsFrom(resolvedTaskId, got);
|
|
1355
1364
|
const advisory = relations === null ? startAdvice : { ...startAdvice, relations };
|
|
1365
|
+
// ADR 0205 §1: a held task never reaches the gates; --override-reason (witness or enforced) starts it as today.
|
|
1366
|
+
if (readyTask !== undefined) {
|
|
1367
|
+
const held = await holdForSplit({ repoRoot, env, member, planKey, taskId: resolvedTaskId, read: got.read ?? null, overrideReason });
|
|
1368
|
+
if (held !== null) return held;
|
|
1369
|
+
}
|
|
1356
1370
|
if (member.coordination?.mode === 'enforced' && !(await noCodeTask({ repoRoot, member, taskId: resolvedTaskId }))) {
|
|
1357
1371
|
enforcedStartGate({ advisory, planKey, taskId: resolvedTaskId, overrideReason });
|
|
1358
1372
|
}
|
|
@@ -1370,9 +1384,64 @@ async function startTask({
|
|
|
1370
1384
|
process.emitWarning(`todo start: backchain not used (${error.detail?.reason ?? error.message}: ${error.detail?.pointer ?? ''})`,
|
|
1371
1385
|
{ code: 'LATTICE_START_BACKCHAIN_UNUSABLE' });
|
|
1372
1386
|
}
|
|
1373
|
-
|
|
1387
|
+
const started = await mutate({ repoRoot, env, planKey, taskId: resolvedTaskId, kind: 'start',
|
|
1374
1388
|
payload: { override_reason: overrideReason }, advisory, noteContext,
|
|
1375
1389
|
structureContext, featureContext, externalTasks: store.external_tasks ?? [] });
|
|
1390
|
+
return withSplitGuide({ repoRoot, member, planKey, taskId: resolvedTaskId, started });
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* ADR 0205 §1 (b4): `todo start T` writes a function an in-progress task of another lane writes → add S (or join the open S on
|
|
1395
|
+
* that function) in one revision and keep T pending. null = start as today: no such overlap, no lane, override, a conversation
|
|
1396
|
+
* plan, or a plan a light revision cannot take (an unknown state is not dangerous: the warning names it, nothing is refused).
|
|
1397
|
+
*/
|
|
1398
|
+
async function holdForSplit({ repoRoot, env, member, planKey, taskId, read, overrideReason }) {
|
|
1399
|
+
if (overrideReason !== null || member.coordination?.mode === 'conversation') return null;
|
|
1400
|
+
const hold = planSplitHold({ member, taskId, read });
|
|
1401
|
+
if (hold === null) return null;
|
|
1402
|
+
const { applyPlanRevision, desiredFromPlan, lightRevisionExpresses } = await import('./plan-revise.mjs');
|
|
1403
|
+
const unsupported = (reason) => { process.emitWarning(`todo start: split not used (${reason})`, { code: 'LATTICE_START_SPLIT_UNSUPPORTED' }); return null; };
|
|
1404
|
+
if (!lightRevisionExpresses(member)) return unsupported('split_unsupported: the plan cannot take a light revision');
|
|
1405
|
+
const desired = desiredFromPlan(member.plan, { env });
|
|
1406
|
+
const ref = (id) => ({ project_id: member.plan.project_id, plan_key: planKey, task_id: id });
|
|
1407
|
+
desired.tasks = [...desired.tasks, ...hold.tasks];
|
|
1408
|
+
desired.hard_dependencies = [...desired.hard_dependencies, ...hold.edges.map(({ from, to }) => ({ from: ref(from), to: ref(to) }))];
|
|
1409
|
+
let applied;
|
|
1410
|
+
try {
|
|
1411
|
+
applied = await applyPlanRevision({ repoRoot, env, input: { schema: 'lattice.plan_revise_input.v1', desired },
|
|
1412
|
+
notes: hold.notes, splitMarks: hold.marks });
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
if (error?.detail?.reason === 'plan_revise_split_unsupported') {
|
|
1415
|
+
return unsupported('split_unsupported: the plan is bound to a feature chain');
|
|
1416
|
+
}
|
|
1417
|
+
throw error;
|
|
1418
|
+
}
|
|
1419
|
+
const lanes = hold.splits.map(({ task_id: id }) => [...hold.tasks, ...member.plan.tasks].find(({ task_id: other }) => other === id)?.lane);
|
|
1420
|
+
const result = { schema: 'lattice.todo_start_split_result.v1', project_id: member.plan.project_id, plan_key: planKey,
|
|
1421
|
+
plan_version: applied.plan_version, task_id: taskId, status: 'pending', splits: hold.splits,
|
|
1422
|
+
next_action: `wait: ${hold.splits.map(({ task_id: id }, index) => `${id} is in lane ${lanes[index]}`).join('; ')}; the chart offers ${taskId} again when every split it waits on is done or withdrawn.`,
|
|
1423
|
+
result_digest: '' };
|
|
1424
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
1425
|
+
return result;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/** What the function-split commands need from this module: retire a task, and declare a row again (resolved at HEAD). */
|
|
1429
|
+
const splitDeps = (repoRoot, planKey) => ({
|
|
1430
|
+
retire: (options) => retireTask(options),
|
|
1431
|
+
declareRow: ({ taskId, flags }) => declareTaskRow({ repoRoot, planKey, taskId, flags, observable: headResolves(repoRoot) }),
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
/** ADR 0205 §3: starting the split task S shows the worker its members, the size of the cut and what to do (no member rule exists). */
|
|
1435
|
+
async function withSplitGuide({ repoRoot, member, planKey, taskId, started }) {
|
|
1436
|
+
const mark = member.plan.tasks.find(({ task_id: id }) => id === taskId)?.function_split ?? null;
|
|
1437
|
+
if (mark === null || started.kind !== 'start') return started;
|
|
1438
|
+
const cost = await cutCost({ repoRoot, target: { path: mark.path, symbol: mark.symbol }, memberTaskIds: mark.members })
|
|
1439
|
+
.catch(() => ({ profile: null, reasons: ['cut_cost_failed'] }));
|
|
1440
|
+
const { result_digest: _digest, ...rest } = started;
|
|
1441
|
+
const result = { ...rest, function_split: { path: mark.path, symbol: mark.symbol, members: mark.members, cut_cost: cost,
|
|
1442
|
+
guide: splitGuide({ planKey, taskId, mark }) }, result_digest: '' };
|
|
1443
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
1444
|
+
return result;
|
|
1376
1445
|
}
|
|
1377
1446
|
|
|
1378
1447
|
/**
|
|
@@ -1382,16 +1451,25 @@ async function startTask({
|
|
|
1382
1451
|
* head_sha}`; an unreadable record is named, never refused: an unknown state is not dangerous.
|
|
1383
1452
|
*/
|
|
1384
1453
|
async function taskRelations({ repoRoot, planKey, taskId }) {
|
|
1454
|
+
return relationsFrom(taskId, await readTaskRelations({ repoRoot, planKey, taskId }));
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/** `{read}` (null = the plan has none) or `{unreadable}`: `todo start` keeps the raw read for the split check. */
|
|
1458
|
+
async function readTaskRelations({ repoRoot, planKey, taskId }) {
|
|
1385
1459
|
try {
|
|
1386
|
-
|
|
1387
|
-
if (read === null) return null;
|
|
1388
|
-
return { open: read.open.map((relation) => relationView(taskId, relation)),
|
|
1389
|
-
plan_relation_count: read.relation_count, unresolved_count: read.unresolved_count, head_sha: read.head_sha };
|
|
1460
|
+
return { read: await readTodoTaskRelations({ repoRoot, planKey, taskId }) };
|
|
1390
1461
|
} catch (error) {
|
|
1391
1462
|
return { unreadable: error?.detail?.reason ?? error?.code ?? 'relations_unreadable' };
|
|
1392
1463
|
}
|
|
1393
1464
|
}
|
|
1394
1465
|
|
|
1466
|
+
function relationsFrom(taskId, { read = null, unreadable = null }) {
|
|
1467
|
+
if (unreadable !== null) return { unreadable };
|
|
1468
|
+
if (read === null) return null;
|
|
1469
|
+
return { open: read.open.map((relation) => relationView(taskId, relation)),
|
|
1470
|
+
plan_relation_count: read.relation_count, unresolved_count: read.unresolved_count, head_sha: read.head_sha };
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1395
1473
|
/** declare-without-git: HEAD does not resolve (no commit) and the plan's witness set records this task's row. */
|
|
1396
1474
|
async function declaredWithoutHead({ repoRoot, planKey, taskId }) {
|
|
1397
1475
|
if (headResolves(repoRoot)) return false;
|
|
@@ -1418,7 +1496,9 @@ const declareCommand = (planKey, taskId) => `lattice todo independence witness d
|
|
|
1418
1496
|
* An unreadable chart meta means no lane is marked (the gates apply).
|
|
1419
1497
|
*/
|
|
1420
1498
|
async function noCodeTask({ repoRoot, member, taskId }) {
|
|
1421
|
-
const lane = member.plan.tasks.find(({ task_id: id }) => id === taskId)
|
|
1499
|
+
const { lane, function_split: split } = member.plan.tasks.find(({ task_id: id }) => id === taskId) ?? {};
|
|
1500
|
+
// ADR 0205 §3: a split task overlaps its own members by construction and carries no witness row.
|
|
1501
|
+
if (split) return true;
|
|
1422
1502
|
return (await readTodoChartMeta({ repoRoot }).catch(() => null))?.no_code_lanes?.includes(lane) ?? false;
|
|
1423
1503
|
}
|
|
1424
1504
|
|
|
@@ -2750,6 +2830,10 @@ async function todoDetail({ repoRoot, env, planKey, taskId }) {
|
|
|
2750
2830
|
repoRoot, plan: member.plan, taskId: task.task_id,
|
|
2751
2831
|
});
|
|
2752
2832
|
const relations = await taskRelations({ repoRoot, planKey, taskId: task.task_id });
|
|
2833
|
+
const labels = splitLabelsOf(member).filter(({ task_id: id }) => id === task.task_id).map(({ label }) => label);
|
|
2834
|
+
// the verify record is read by `todo show S` only (ADR 0205 §2); an unreadable one is named, never a refusal
|
|
2835
|
+
const splitRecord = task.function_split ? await readTodoSplit({ repoRoot, planKey, taskId: task.task_id })
|
|
2836
|
+
.catch((error) => ({ unreadable: error?.detail?.reason ?? error?.code ?? 'split_record_unreadable' })) : undefined;
|
|
2753
2837
|
const result = {
|
|
2754
2838
|
schema: featureContext === null ? 'lattice.todo_detail_result.v3' : 'lattice.todo_detail_result.v4',
|
|
2755
2839
|
project_id: store.project_id,
|
|
@@ -2762,6 +2846,8 @@ async function todoDetail({ repoRoot, env, planKey, taskId }) {
|
|
|
2762
2846
|
prerequisites: taskPrerequisites(store, member, task.task_id),
|
|
2763
2847
|
note_context: context,
|
|
2764
2848
|
...(relations === null ? {} : { relations }),
|
|
2849
|
+
...(labels.length === 0 ? {} : { labels }),
|
|
2850
|
+
...(splitRecord === undefined ? {} : { split_record: splitRecord }),
|
|
2765
2851
|
...(featureContext === null ? {} : { feature_context: featureContext }),
|
|
2766
2852
|
result_digest: '',
|
|
2767
2853
|
};
|
|
@@ -4855,6 +4941,7 @@ function writesTodoStore(argv) {
|
|
|
4855
4941
|
case 'phase': return second !== 'status';
|
|
4856
4942
|
case 'start': case 'retract': case 'block': case 'unblock': case 'retire': case 'done':
|
|
4857
4943
|
case 'reopen': case 'split': case 'revise': case 'revise-phase': case 'revise-set': case 'add':
|
|
4944
|
+
case 'function-split':
|
|
4858
4945
|
return true;
|
|
4859
4946
|
default: return false;
|
|
4860
4947
|
}
|
|
@@ -5617,6 +5704,21 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5617
5704
|
if (flags !== null && isTodoIdentifier(flags.plan) && isAuthoringPathToken(flags.input)) {
|
|
5618
5705
|
action = (repoRoot) => revise({ repoRoot, env, planKey: flags.plan, inputRef: flags.input });
|
|
5619
5706
|
}
|
|
5707
|
+
} else if (argv[0] === 'function-split' && argv[1] === 'verify') {
|
|
5708
|
+
const flags = matchFlagCommand(argv, ['function-split', 'verify'], TODO_FLAG_SPECS['function-split verify']);
|
|
5709
|
+
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
|
5710
|
+
&& ['commit', 'map'].every((name) => typeof flags[name] === 'string' && flags[name].length > 0)
|
|
5711
|
+
&& (flags.base === undefined || (typeof flags.base === 'string' && flags.base.length > 0))) {
|
|
5712
|
+
action = (repoRoot) => verifySplit({ repoRoot, env, planKey: flags.plan, taskId: flags.task, commit: flags.commit,
|
|
5713
|
+
base: flags.base, mapText: flags.map, deps: splitDeps(repoRoot, flags.plan) });
|
|
5714
|
+
}
|
|
5715
|
+
} else if (argv[0] === 'function-split' && argv[1] === 'decline') {
|
|
5716
|
+
const flags = matchFlagCommand(argv, ['function-split', 'decline'], TODO_FLAG_SPECS['function-split decline']);
|
|
5717
|
+
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
|
5718
|
+
&& typeof flags.reason === 'string' && flags.reason.length > 0) {
|
|
5719
|
+
action = (repoRoot) => reorganizeNotSplit({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5720
|
+
reason: flags.reason, deps: splitDeps(repoRoot, flags.plan) });
|
|
5721
|
+
}
|
|
5620
5722
|
} else if (argv[0] === 'split') {
|
|
5621
5723
|
const flags = matchFlagCommand(argv, ['split'], TODO_FLAG_SPECS.split);
|
|
5622
5724
|
if (flags !== null && isTodoIdentifier(flags.plan) && isAuthoringPathToken(flags.input)) {
|
|
@@ -5701,6 +5803,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5701
5803
|
action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5702
5804
|
kind: 'done', dropped: (recorded) => doneDropped({ repoRoot, flags, recorded }),
|
|
5703
5805
|
action: async () => {
|
|
5806
|
+
await splitDoneGate({ repoRoot, planKey: flags.plan, taskId: flags.task, deps: splitDeps(repoRoot, flags.plan) });
|
|
5704
5807
|
const result = await mutate({
|
|
5705
5808
|
repoRoot, env, planKey: flags.plan, taskId: flags.task, kind: 'done', payload: 'authored',
|
|
5706
5809
|
message: await doneMessage({ repoRoot, flags }),
|
package/src/todo-contracts.mjs
CHANGED
|
@@ -57,6 +57,10 @@ export const TODO_CHART_META_SCHEMA = 'lattice.chart_meta.v1';
|
|
|
57
57
|
export const TODO_RELATION_EVENT_SCHEMA = 'lattice.todo_relation_event.v1';
|
|
58
58
|
export const TODO_RELATION_SUMMARY_SCHEMA = 'lattice.todo_relation_summary.v1';
|
|
59
59
|
export const TODO_RELATION_SUMMARY_OPEN = 20;
|
|
60
|
+
/** ADR 0205 b2: the verify outcome of one split task, one file `.lattice/todo/splits/<plan_key>/<task_id>.json`; dfd-store-split. */
|
|
61
|
+
export const TODO_SPLIT_RECORD_SCHEMA = 'lattice.todo_split_record.v1';
|
|
62
|
+
export const TODO_SPLIT_CONDITIONS = Object.freeze(['behaviour', 'tests', 'fresh', 'overlap', 'parallel']);
|
|
63
|
+
export const TODO_SPLIT_MAX_MEMBERS = 64;
|
|
60
64
|
/**
|
|
61
65
|
* v2でnoteの`scope`とplan noteを載せる。v1のままでは`task_id`が identifier 必須・
|
|
62
66
|
* `full_history_command`が`--task <id>`込みの文字列と完全一致で、どちらもplan noteを表せない。
|
|
@@ -406,6 +410,25 @@ function taskV8(value) {
|
|
|
406
410
|
]) && taskV6(rest) && (doneCondition === null || isTodoDesignMemo(doneCondition));
|
|
407
411
|
}
|
|
408
412
|
|
|
413
|
+
const splitText = (value) => typeof value === 'string' && value.length > 0 && Buffer.byteLength(value, 'utf8') <= 1_024
|
|
414
|
+
&& !CONTROL.test(value);
|
|
415
|
+
|
|
416
|
+
/** ADR 0205 §2: the split mark. `members` are sorted unique task ids (start order is never stored); the range is a snapshot. */
|
|
417
|
+
const functionSplit = (value) => exactRecord(value, ['path', 'symbol', 'start_line', 'end_line', 'members'])
|
|
418
|
+
&& isTodoRef(value.path) && splitText(value.symbol)
|
|
419
|
+
&& Number.isSafeInteger(value.start_line) && value.start_line >= 1
|
|
420
|
+
&& Number.isSafeInteger(value.end_line) && value.end_line >= value.start_line
|
|
421
|
+
&& Array.isArray(value.members) && value.members.length >= 2 && value.members.length <= TODO_SPLIT_MAX_MEMBERS
|
|
422
|
+
&& value.members.every((id, index) => isTodoIdentifier(id) && (index === 0 || compareText(value.members[index - 1], id) < 0));
|
|
423
|
+
|
|
424
|
+
function taskV9(value) {
|
|
425
|
+
const { function_split: split, ...rest } = value ?? {};
|
|
426
|
+
return exactRecord(value, [
|
|
427
|
+
'task_id', 'title', 'lane', 'design_memo', 'narrative_ref', 'narrative_anchor',
|
|
428
|
+
'compile_binding', 'parent_task_id', 'phase_id', 'done_condition', 'function_split',
|
|
429
|
+
]) && taskV8(rest) && (split === null || functionSplit(split));
|
|
430
|
+
}
|
|
431
|
+
|
|
409
432
|
function phaseV1(value) {
|
|
410
433
|
return exactRecord(value, [
|
|
411
434
|
'phase_id', 'title', 'gate_policy', 'predecessor_phase_ids', 'required_evidence_slots',
|
|
@@ -476,14 +499,15 @@ export function explainTodoPlan(value) {
|
|
|
476
499
|
: ['lattice.todo_plan.v4', 'lattice.todo_plan.v5'].includes(value?.schema) ? taskV4
|
|
477
500
|
: value?.schema === 'lattice.todo_plan.v6' ? taskV5
|
|
478
501
|
: value?.schema === 'lattice.todo_plan.v7' ? taskV6
|
|
479
|
-
: value?.schema === 'lattice.todo_plan.v8' ? taskV8
|
|
502
|
+
: value?.schema === 'lattice.todo_plan.v8' ? taskV8
|
|
503
|
+
: value?.schema === 'lattice.todo_plan.v9' ? taskV9 : null;
|
|
480
504
|
const planKeys = [
|
|
481
505
|
'schema', 'project_id', 'plan_key', 'plan_version', 'predecessor_plan_digest',
|
|
482
506
|
'tasks', 'hard_dependencies', 'joins', 'topology_digest', 'plan_digest',
|
|
483
507
|
];
|
|
484
508
|
const phased = ['lattice.todo_plan.v4', 'lattice.todo_plan.v5', 'lattice.todo_plan.v7',
|
|
485
|
-
'lattice.todo_plan.v8'].includes(value?.schema);
|
|
486
|
-
const decoupled = ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8']
|
|
509
|
+
'lattice.todo_plan.v8', 'lattice.todo_plan.v9'].includes(value?.schema);
|
|
510
|
+
const decoupled = ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8', 'lattice.todo_plan.v9']
|
|
487
511
|
.includes(value?.schema);
|
|
488
512
|
if (phased) planKeys.push('phases');
|
|
489
513
|
if (decoupled) planKeys.push('phase_accept_dependencies');
|
|
@@ -499,6 +523,12 @@ export function explainTodoPlan(value) {
|
|
|
499
523
|
if (new Set(value.tasks.map(({ task_id }) => task_id)).size !== value.tasks.length) {
|
|
500
524
|
return reject('duplicate_task_id', '/tasks');
|
|
501
525
|
}
|
|
526
|
+
if (value.schema === 'lattice.todo_plan.v9') {
|
|
527
|
+
const ids = new Set(value.tasks.map(({ task_id: id }) => id));
|
|
528
|
+
const stray = value.tasks.findIndex(({ task_id: id, function_split: split }) => split !== null
|
|
529
|
+
&& (split.members.includes(id) || !split.members.every((member) => ids.has(member))));
|
|
530
|
+
if (stray >= 0) return reject('function_split_members_invalid', `/tasks/${stray}/function_split/members`);
|
|
531
|
+
}
|
|
502
532
|
if (!Array.isArray(value.hard_dependencies)) {
|
|
503
533
|
return reject('bounded_collection_violation', '/hard_dependencies');
|
|
504
534
|
}
|
|
@@ -516,7 +546,7 @@ export function explainTodoPlan(value) {
|
|
|
516
546
|
if (!isTodoDigest(value[field])) return reject('digest_invalid', `/${field}`);
|
|
517
547
|
}
|
|
518
548
|
if (['lattice.todo_plan.v3', 'lattice.todo_plan.v4', 'lattice.todo_plan.v5',
|
|
519
|
-
'lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(value.schema)
|
|
549
|
+
'lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8', 'lattice.todo_plan.v9'].includes(value.schema)
|
|
520
550
|
&& !validParentGraph(value.tasks)) return reject('parent_graph_invalid', '/tasks');
|
|
521
551
|
if (phased) {
|
|
522
552
|
if (!Array.isArray(value.phases) || value.phases.length === 0) return reject('bounded_collection_violation', '/phases');
|
|
@@ -968,3 +998,25 @@ export function validateTodoRelationSummary(value) {
|
|
|
968
998
|
&& relationSha(value.head_sha) && isStrictTodoTimestamp(value.computed_at);
|
|
969
999
|
} catch { return false; }
|
|
970
1000
|
}
|
|
1001
|
+
|
|
1002
|
+
const splitCondition = (value) => exactRecord(value, ['passed', 'detail']) && typeof value.passed === 'boolean'
|
|
1003
|
+
&& typeof value.detail === 'string' && Buffer.byteLength(value.detail, 'utf8') <= 2_048;
|
|
1004
|
+
const splitMapEntry = (value) => exactRecord(value, ['task_id', 'path', 'symbol'])
|
|
1005
|
+
&& isTodoIdentifier(value.task_id) && isTodoRef(value.path) && splitText(value.symbol);
|
|
1006
|
+
|
|
1007
|
+
/** ADR 0205 §2: `accepted` only when all five conditions passed; the map has at most one entry per task, sorted by task_id. */
|
|
1008
|
+
export function validateTodoSplitRecord(value) {
|
|
1009
|
+
try {
|
|
1010
|
+
return exactRecord(value, ['schema', 'plan_key', 'task_id', 'attempt', 'map', 'commit', 'base', 'outcome',
|
|
1011
|
+
'conditions', 'recorded_at', 'actor'])
|
|
1012
|
+
&& value.schema === TODO_SPLIT_RECORD_SCHEMA && isTodoIdentifier(value.plan_key) && isTodoIdentifier(value.task_id)
|
|
1013
|
+
&& Number.isSafeInteger(value.attempt) && value.attempt >= 1
|
|
1014
|
+
&& Array.isArray(value.map) && value.map.length <= TODO_SPLIT_MAX_MEMBERS && value.map.every(splitMapEntry)
|
|
1015
|
+
&& value.map.every((entry, index) => index === 0 || compareText(value.map[index - 1].task_id, entry.task_id) < 0)
|
|
1016
|
+
&& /^[0-9a-f]{40}$/u.test(value.commit) && /^[0-9a-f]{40}$/u.test(value.base)
|
|
1017
|
+
&& ['accepted', 'rejected'].includes(value.outcome)
|
|
1018
|
+
&& exactRecord(value.conditions, TODO_SPLIT_CONDITIONS) && TODO_SPLIT_CONDITIONS.every((key) => splitCondition(value.conditions[key]))
|
|
1019
|
+
&& (value.outcome === 'rejected' || TODO_SPLIT_CONDITIONS.every((key) => value.conditions[key].passed))
|
|
1020
|
+
&& isStrictTodoTimestamp(value.recorded_at) && actor(value.actor);
|
|
1021
|
+
} catch { return false; }
|
|
1022
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// ADR 0205 §3-§6 (b5): `todo function-split verify|decline`, the not-split reorganization, and the gate and rewrite of `todo done S`.
|
|
2
|
+
// todo-cli passes the pieces that live in it (`deps.declareRow`, `deps.retire`); nothing here touches the sensor or git except
|
|
3
|
+
// through Neve's `verifyFunctionSplit`.
|
|
4
|
+
|
|
5
|
+
import { resolveTodoActor } from './todo-authoring-input.mjs';
|
|
6
|
+
import { verifyFunctionSplit } from './function-split-verify.mjs';
|
|
7
|
+
import { measureWaveCount } from './seam-verification.mjs';
|
|
8
|
+
import { parseAnchor } from './sensor-resolve.mjs';
|
|
9
|
+
import { appendTodoNote } from './todo-note-store.mjs';
|
|
10
|
+
import { anchorsOf, claimsOf, judgeTask, rangeIndex } from './todo-judgment.mjs';
|
|
11
|
+
import { readTodoSplit, recordTodoSplit } from './todo-split-store.mjs';
|
|
12
|
+
import {
|
|
13
|
+
createTodoStoreWriter, readTodoStore, readTodoWitnessSet, TodoStoreError,
|
|
14
|
+
} from './todo-store.mjs';
|
|
15
|
+
|
|
16
|
+
const FINISHED = new Set(['done', 'retired']);
|
|
17
|
+
const CONDITIONS = ['behaviour', 'tests', 'fresh', 'overlap', 'parallel'];
|
|
18
|
+
const refuse = (reason, detail) => new TodoStoreError('TODO_TRANSITION_REFUSED', reason, undefined, detail);
|
|
19
|
+
// A record detail is bounded (2 KiB) by the Store contract; a longer cause is cut here, the full one is in the verify result.
|
|
20
|
+
const clip = (text) => (Buffer.byteLength(text, 'utf8') <= 2_000 ? text : `${Buffer.from(text, 'utf8').subarray(0, 1_990).toString('utf8')}...`);
|
|
21
|
+
|
|
22
|
+
/** `--map U=src/a.js#f,T=src/b.js#g` → `[{task_id, path, symbol}]` sorted by task id; members only, one entry each. */
|
|
23
|
+
export function parseSplitMap(text, members) {
|
|
24
|
+
const entries = [];
|
|
25
|
+
for (const item of String(text).split(',').map((part) => part.trim()).filter(Boolean)) {
|
|
26
|
+
const at = item.indexOf('=');
|
|
27
|
+
const anchor = at < 0 ? null : parseAnchor(item.slice(at + 1));
|
|
28
|
+
const taskId = at < 0 ? '' : item.slice(0, at);
|
|
29
|
+
if (anchor === null || !members.includes(taskId) || entries.some((entry) => entry.task_id === taskId)) {
|
|
30
|
+
throw new TodoStoreError('INPUT_INVALID', 'function_split_map_invalid', undefined, {
|
|
31
|
+
pointer: '--map', entry: item, members,
|
|
32
|
+
next_action: `--map takes one <task>=<path>#<function> per member of the split (${members.join(', ')}), comma separated.`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
entries.push({ task_id: taskId, path: anchor.path, symbol: anchor.symbol });
|
|
36
|
+
}
|
|
37
|
+
if (entries.length === 0) {
|
|
38
|
+
throw new TodoStoreError('INPUT_INVALID', 'function_split_map_invalid', undefined, { pointer: '--map', members,
|
|
39
|
+
next_action: '--map needs at least one entry; to make no cut run `lattice todo function-split decline`.' });
|
|
40
|
+
}
|
|
41
|
+
return entries.sort((left, right) => (left.task_id < right.task_id ? -1 : 1));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The split task S, its mark and the plan it lives in; refuses when it is not an unfinished split task. */
|
|
45
|
+
function splitTask(store, planKey, taskId) {
|
|
46
|
+
const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
|
|
47
|
+
const task = member?.plan.tasks.find(({ task_id: id }) => id === taskId);
|
|
48
|
+
const status = member?.tasks.find(({ task_id: id }) => id === taskId)?.status;
|
|
49
|
+
if (task === undefined) throw new TodoStoreError('TASK_NOT_FOUND', 'task_not_found', undefined, { requested_task_id: taskId });
|
|
50
|
+
if (!task.function_split) {
|
|
51
|
+
throw refuse('not_a_split_task', { plan_key: planKey, task_id: taskId, next_action: `${planKey}/${taskId} is not a function-split task (\`lattice todo status --json\` shows them).` });
|
|
52
|
+
}
|
|
53
|
+
return { member, task, mark: task.function_split, status };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** `row` with its write anchor on `from` replaced by `to`; null when it has none (already moved, or never on it). */
|
|
57
|
+
export function moveAnchor(row, from, to) {
|
|
58
|
+
const group = row.concern_anchors?.find(({ within }) => within.target === from.path);
|
|
59
|
+
if (group === undefined || !group.symbols.includes(from.symbol)) return null;
|
|
60
|
+
const groups = (row.concern_anchors ?? []).map((entry) => (entry === group
|
|
61
|
+
? { ...entry, symbols: entry.symbols.filter((symbol) => symbol !== from.symbol) } : entry));
|
|
62
|
+
const target = groups.find(({ within }) => within.target === to.path);
|
|
63
|
+
const moved = target === undefined
|
|
64
|
+
? [...groups, { within: { kind: 'path', target: to.path }, symbols: [to.symbol] }]
|
|
65
|
+
: groups.map((entry) => (entry === target ? { ...entry, symbols: [...new Set([...entry.symbols, to.symbol])].sort() } : entry));
|
|
66
|
+
const concern = moved.filter(({ symbols }) => symbols.length > 0);
|
|
67
|
+
const kept = new Set(concern.map(({ within }) => within.target));
|
|
68
|
+
return { ...row,
|
|
69
|
+
concern_anchors: concern,
|
|
70
|
+
// a file left with no anchor must not become a whole-file claim
|
|
71
|
+
owns: [...row.owns.filter(({ target: where }) => where !== from.path || kept.has(where)),
|
|
72
|
+
...(row.owns.some(({ target: where }) => where === to.path) ? [] : [{ kind: 'path', target: to.path }])] };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The `--owns/--reads/--writes` flags that declare `row` again (`declareTaskRow` takes flags). */
|
|
76
|
+
// shortcut: `creates` and `unknowns` of the old row are not expressible as flags and are dropped; add them if a split task ever needs them.
|
|
77
|
+
export function flagsOf(row) {
|
|
78
|
+
const tokens = (paths, anchors) => paths.flatMap((target) => {
|
|
79
|
+
const symbols = anchors?.find(({ within }) => within.target === target)?.symbols ?? [];
|
|
80
|
+
return symbols.length > 0 ? symbols.map((symbol) => `${target}#${symbol}`) : [target];
|
|
81
|
+
});
|
|
82
|
+
const owned = new Set(row.owns.map(({ target }) => target));
|
|
83
|
+
return { owns: tokens(row.owns.map(({ target }) => target), row.concern_anchors), reads: tokens(row.reads, row.read_anchors),
|
|
84
|
+
writes: row.writes.filter((target) => !owned.has(target)) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Overlap and parallel (ADR 0205 §4) over the mapped members, from Neve's ranges at the commit. */
|
|
88
|
+
function judgeMapped({ rows, lanes, ranges }) {
|
|
89
|
+
const ids = Object.keys(rows).sort();
|
|
90
|
+
const index = rangeIndex([...ranges.reduce((merged, row) => {
|
|
91
|
+
const key = `${row.path}\0${row.symbol}`;
|
|
92
|
+
const known = merged.get(key);
|
|
93
|
+
merged.set(key, known === undefined ? { ...row } : { ...known, start_line: Math.min(known.start_line, row.start_line), end_line: Math.max(known.end_line, row.end_line) });
|
|
94
|
+
return merged;
|
|
95
|
+
}, new Map()).values()]);
|
|
96
|
+
const pairs = ids.flatMap((left, at) => ids.slice(at + 1).map((right) => [left, right])).filter(([left, right]) => lanes.get(left) !== lanes.get(right));
|
|
97
|
+
const still = (only) => pairs.filter(([left, right]) => judgeTask({ taskId: left, rows: { [left]: rows[left], [right]: rows[right] }, ranges: index, only })
|
|
98
|
+
.relations.some(({ task_a: a, task_b: b }) => (a === left && b === right) || (a === right && b === left)));
|
|
99
|
+
const writing = still('ww');
|
|
100
|
+
const anyConflict = still(null);
|
|
101
|
+
// one executor per member: the waves then count only what the conflicts force (a single executor serializes everything)
|
|
102
|
+
const before = measureWaveCount({ taskIds: ids, conflictPairs: pairs, executors: ids.length });
|
|
103
|
+
const after = measureWaveCount({ taskIds: ids, conflictPairs: anyConflict, executors: ids.length });
|
|
104
|
+
return {
|
|
105
|
+
overlap: { passed: writing.length === 0, detail: writing.length === 0 ? 'ok' : clip(`still write the same lines: ${writing.map((pair) => pair.join('/')).join(', ')}`) },
|
|
106
|
+
parallel: before.waves !== null && after.waves !== null && after.waves < before.waves
|
|
107
|
+
? { passed: true, detail: `waves ${before.waves} -> ${after.waves}` }
|
|
108
|
+
: { passed: false, detail: clip(`waves ${before.waves ?? before.reason} -> ${after.waves ?? after.reason}: not lower`) },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* `todo function-split verify` (ADR 0205 §3-§4): Neve's checks on the worker's commit, then overlap and parallel, recorded on S.
|
|
114
|
+
* Input errors refuse and reorganize nothing. A rejected outcome is written first and then reorganized as not split.
|
|
115
|
+
*/
|
|
116
|
+
export async function verifySplit({ repoRoot, env, planKey, taskId, commit, base, mapText, deps }) {
|
|
117
|
+
const { member, mark, status } = splitTask(await readTodoStore({ repoRoot }), planKey, taskId);
|
|
118
|
+
if (FINISHED.has(status)) throw refuse('split_task_finished', { plan_key: planKey, task_id: taskId, status });
|
|
119
|
+
const map = parseSplitMap(mapText, mark.members);
|
|
120
|
+
const witness = await readTodoWitnessSet({ repoRoot, planKey }).catch(() => null);
|
|
121
|
+
const rowOf = (id) => witness?.plan_key === planKey ? witness.manual_witness[id] : undefined;
|
|
122
|
+
const anchors = map.flatMap(({ task_id: id }) => (rowOf(id) === undefined ? [] : anchorsOf(claimsOf(rowOf(id))).map((anchor) => ({ task_id: id, ...anchor }))));
|
|
123
|
+
const target = { path: mark.path, symbol: mark.symbol };
|
|
124
|
+
const answer = await verifyFunctionSplit({ repoRoot, commit, ...(base === undefined ? {} : { base }), target, map, anchors });
|
|
125
|
+
if (answer.error !== undefined) {
|
|
126
|
+
throw new TodoStoreError('INPUT_INVALID', `function_split_${answer.error.code}`, undefined, { ...answer.error, pointer: '--commit' });
|
|
127
|
+
}
|
|
128
|
+
const rows = {};
|
|
129
|
+
for (const entry of map) {
|
|
130
|
+
const row = rowOf(entry.task_id);
|
|
131
|
+
if (row !== undefined) rows[entry.task_id] = moveAnchor(row, target, entry) ?? row;
|
|
132
|
+
}
|
|
133
|
+
const lanes = new Map(member.plan.tasks.map(({ task_id: id, lane }) => [id, lane]));
|
|
134
|
+
const judged = judgeMapped({ rows, lanes, ranges: answer.ranges });
|
|
135
|
+
const conditions = {
|
|
136
|
+
behaviour: { passed: answer.behaviour.passed, detail: clip(answer.behaviour.detail) },
|
|
137
|
+
tests: { passed: answer.tests.passed, detail: clip(answer.tests.detail) },
|
|
138
|
+
fresh: { passed: answer.fresh.passed, detail: answer.fresh.passed ? 'ok' : clip(answer.fresh.detail ?? JSON.stringify(answer.fresh.unresolved)) },
|
|
139
|
+
...judged,
|
|
140
|
+
};
|
|
141
|
+
const outcome = CONDITIONS.every((name) => conditions[name].passed) ? 'accepted' : 'rejected';
|
|
142
|
+
await recordTodoSplit({ repoRoot, planKey, taskId, writer: createTodoStoreWriter({ caller: 'todo-splits' }), record: {
|
|
143
|
+
map, commit: answer.commit, base: answer.base, outcome, conditions, recorded_at: new Date().toISOString(), actor: resolveTodoActor(env) } });
|
|
144
|
+
const failed = CONDITIONS.filter((name) => !conditions[name].passed);
|
|
145
|
+
const result = { schema: 'lattice.todo_function_split_verify_result.v1', project_id: member.plan.project_id, plan_key: planKey,
|
|
146
|
+
task_id: taskId, outcome, commit: answer.commit, base: answer.base, conditions, tests_ran: answer.tests.ran, target: answer.target };
|
|
147
|
+
if (outcome === 'accepted') {
|
|
148
|
+
return { ...result, next_action: `open the PR with \`[skip ci]\` in the commit message, merge it, then \`lattice todo done --plan ${planKey} --task ${taskId} --message <what you merged>\`.` };
|
|
149
|
+
}
|
|
150
|
+
const reason = `verify rejected (${failed.join(', ')}): ${failed.map((name) => `${name}: ${conditions[name].detail}`).join(' | ')}`;
|
|
151
|
+
return { ...result, reorganized: await reorganizeNotSplit({ repoRoot, env, planKey, taskId, reason: clip(reason), deps }),
|
|
152
|
+
next_action: 'the split is withdrawn; the later tasks now wait for the one that started first.' };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Does `from` already reach `to` through the plan's hard dependencies? */
|
|
156
|
+
const reaches = (plan, from, to) => {
|
|
157
|
+
const seen = new Set();
|
|
158
|
+
const stack = [from];
|
|
159
|
+
while (stack.length > 0) {
|
|
160
|
+
const current = stack.pop();
|
|
161
|
+
if (current === to) return true;
|
|
162
|
+
if (seen.has(current)) continue;
|
|
163
|
+
seen.add(current);
|
|
164
|
+
for (const edge of plan.hard_dependencies) if (edge.from.task_id === current) stack.push(edge.to.task_id);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Not split (D6, D7): the member in progress that started first becomes the predecessor of the unfinished members that have
|
|
171
|
+
* not started, each member gets a note with the reason, then S is retired. The edges go first, so a crash leaves S open and
|
|
172
|
+
* the same command finishes the job; with no member in progress there is no edge and the next start detects again.
|
|
173
|
+
*/
|
|
174
|
+
export async function reorganizeNotSplit({ repoRoot, env, planKey, taskId, reason, deps }) {
|
|
175
|
+
const store = await readTodoStore({ repoRoot });
|
|
176
|
+
const { member, mark, status } = splitTask(store, planKey, taskId);
|
|
177
|
+
if (status === 'retired') return deps.retire({ repoRoot, env, planKey, taskId, reason });
|
|
178
|
+
if (status === 'done') throw refuse('split_task_finished', { plan_key: planKey, task_id: taskId, status });
|
|
179
|
+
const state = new Map(member.tasks.map((task) => [task.task_id, task]));
|
|
180
|
+
const open = mark.members.filter((id) => state.has(id) && !FINISHED.has(state.get(id).status));
|
|
181
|
+
const lead = open.filter((id) => state.get(id).status === 'in-progress')
|
|
182
|
+
.sort((left, right) => (state.get(left).started_at < state.get(right).started_at ? -1 : 1))[0];
|
|
183
|
+
const edges = lead === undefined ? [] : open.filter((id) => state.get(id).status !== 'in-progress' && !reaches(member.plan, lead, id))
|
|
184
|
+
.map((id) => ({ from: lead, to: id }));
|
|
185
|
+
let planVersion = member.plan.plan_version;
|
|
186
|
+
if (edges.length > 0) {
|
|
187
|
+
const { applyPlanRevision, desiredFromPlan } = await import('./plan-revise.mjs');
|
|
188
|
+
const desired = desiredFromPlan(member.plan, { env });
|
|
189
|
+
const ref = (id) => ({ project_id: member.plan.project_id, plan_key: planKey, task_id: id });
|
|
190
|
+
desired.hard_dependencies = [...desired.hard_dependencies, ...edges.map(({ from, to }) => ({ from: ref(from), to: ref(to) }))];
|
|
191
|
+
planVersion = (await applyPlanRevision({ repoRoot, env, input: { schema: 'lattice.plan_revise_input.v1', desired } })).plan_version;
|
|
192
|
+
}
|
|
193
|
+
const actor = resolveTodoActor(env);
|
|
194
|
+
for (const id of open) {
|
|
195
|
+
await appendTodoNote({ repoRoot, projectId: member.plan.project_id, planKey, planVersion, taskId: id, actor,
|
|
196
|
+
recordedAt: new Date().toISOString(), supersedes: null, eligibleSupersedes: [],
|
|
197
|
+
body: `function split ${taskId} on ${mark.path}#${mark.symbol} was not made: ${reason}${lead !== undefined && id !== lead && state.get(id).status !== 'in-progress' ? `; ${id} now waits for ${lead}` : ''}` });
|
|
198
|
+
}
|
|
199
|
+
const retired = await deps.retire({ repoRoot, env, planKey, taskId, reason });
|
|
200
|
+
return { schema: 'lattice.todo_function_split_decline_result.v1', project_id: member.plan.project_id, plan_key: planKey,
|
|
201
|
+
task_id: taskId, outcome: 'declined', reason, predecessor_edges: edges, retired: { kind: retired.kind, status: retired.status } };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The gate and the rewrite of `todo done S` (ADR 0205 §5): needs an accepted record, then each unfinished mapped member's
|
|
206
|
+
* write anchor on F becomes its mapped function through the ADR 0204 declaration path (resolved at the repository's HEAD, so
|
|
207
|
+
* relations are judged again and close where the overlap is gone). A row without the anchor is skipped: the rewrite is idempotent.
|
|
208
|
+
*/
|
|
209
|
+
export async function splitDoneGate({ repoRoot, planKey, taskId, deps }) {
|
|
210
|
+
// shortcut: one more Store read on every `todo done` to learn whether the task is a split task; read the mark from the done's own read if that cost shows.
|
|
211
|
+
const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
|
|
212
|
+
const mark = member?.plan.tasks.find(({ task_id: id }) => id === taskId)?.function_split;
|
|
213
|
+
if (!mark) return;
|
|
214
|
+
const record = await readTodoSplit({ repoRoot, planKey, taskId });
|
|
215
|
+
if (record === null || record.outcome !== 'accepted') {
|
|
216
|
+
throw refuse('split_not_accepted', { plan_key: planKey, task_id: taskId, outcome: record?.outcome ?? null,
|
|
217
|
+
next_action: `\`lattice todo function-split verify --plan ${planKey} --task ${taskId} --commit <sha> --map <task>=<path#function>,...\`, or \`lattice todo function-split decline --plan ${planKey} --task ${taskId} --reason <text>\`.` });
|
|
218
|
+
}
|
|
219
|
+
const witness = await readTodoWitnessSet({ repoRoot, planKey }).catch(() => null);
|
|
220
|
+
const status = new Map(member.tasks.map((task) => [task.task_id, task.status]));
|
|
221
|
+
const target = { path: mark.path, symbol: mark.symbol };
|
|
222
|
+
const unresolved = [];
|
|
223
|
+
for (const entry of record.map) {
|
|
224
|
+
const row = witness?.plan_key === planKey ? witness.manual_witness[entry.task_id] : undefined;
|
|
225
|
+
const moved = row === undefined || FINISHED.has(status.get(entry.task_id)) ? null : moveAnchor(row, target, entry);
|
|
226
|
+
if (moved === null) continue;
|
|
227
|
+
const written = await deps.declareRow({ taskId: entry.task_id, flags: flagsOf(moved) });
|
|
228
|
+
if (written.scaffolded === null) unresolved.push({ task_id: entry.task_id, path: entry.path, symbol: entry.symbol, ...written.declaration });
|
|
229
|
+
}
|
|
230
|
+
if (unresolved.length > 0) {
|
|
231
|
+
throw refuse('split_map_unresolved', { plan_key: planKey, task_id: taskId, unresolved,
|
|
232
|
+
next_action: 'The new functions are not in this repository yet: merge the split PR, sync the repository (`lattice chart repo sync`), then run `todo done` again.' });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOCUMENT_STATUS, SEVERABILITY_LABEL, escapeHtmlAttribute, escapeHtmlText, foldIndex, planActivity, presentationLookup, refKey, renderConnectionArea, renderPhaseProgress, renderRelationList, renderSeamProposalOverview, renderTaskIndex, statusMarkup, taskReference } from './todo-gantt-html-shared.mjs';
|
|
1
|
+
import { DOCUMENT_STATUS, SEVERABILITY_LABEL, escapeHtmlAttribute, escapeHtmlText, foldIndex, planActivity, presentationLookup, refKey, renderConnectionArea, renderPhaseProgress, renderRelationList, renderSeamProposalOverview, renderSplitLabel, renderTaskIndex, statusMarkup, taskReference } from './todo-gantt-html-shared.mjs';
|
|
2
2
|
import {
|
|
3
3
|
hasTodoStructurePresentation,
|
|
4
4
|
renderTodoStructureNoscript,
|
|
@@ -254,7 +254,7 @@ export function renderRightPane(
|
|
|
254
254
|
: '<p class="fold-note">完走済みのため図には描いていません。図に出すには動的dashboardを <code>lattice todo gantt serve --port <port> --scope all</code> で起動してください。</p>';
|
|
255
255
|
const workLog = notesEnabled ? renderNoteContext(section.noteContext, hostDisplayNames) : '';
|
|
256
256
|
const designMemo = renderDesignMemo(section.task) + renderDoneCondition(section.task);
|
|
257
|
-
return `<article class="task-detail" data-detail-key="${escapeHtmlAttribute(key)}" hidden><header><span class="detail-status status-${escapeHtmlAttribute(section.state.status)}">${escapeHtmlText(status.mark)} ${escapeHtmlText(status.label)}</span
|
|
257
|
+
return `<article class="task-detail" data-detail-key="${escapeHtmlAttribute(key)}" hidden><header><span class="detail-status status-${escapeHtmlAttribute(section.state.status)}">${escapeHtmlText(status.mark)} ${escapeHtmlText(status.label)}</span>${renderSplitLabel(section.splitLabel)}<span class="detail-reference">${escapeHtmlText(taskReference(section, lookup))}</span></header><h1>${escapeHtmlText(section.task.title)}</h1><p class="detail-category"><strong>カテゴリ:</strong> ${escapeHtmlText(category)}</p>${categoryDescription}<p><strong>正規ID:</strong> <code>${escapeHtmlText(`${section.ref.plan_key}/${section.task.task_id}`)}</code></p>${blockedReason}${renderConnectionArea(section.connections)}${readiness}${independenceNote}${foldedNote}${designMemo}<section><h2>前提工程</h2>${renderRelationList(incoming.get(key), sectionByKey, lookup, '登録済みの前提工程はありません。', folds)}</section><section><h2>後続工程</h2>${renderRelationList(outgoing.get(key), sectionByKey, lookup, '登録済みの後続工程はありません。', folds)}</section>${workLog}<p class="anchor-status">${escapeHtmlText(anchorText)}</p><details class="task-diagnostics"><summary>開発者向け診断</summary><dl><dt>canonical ref</dt><dd><code>${escapeHtmlText(`${section.ref.project_id}/${section.ref.plan_key}/${section.task.task_id}`)}</code></dd><dt>anchor</dt><dd>${escapeHtmlText(section.anchorOutcome.anchored ? 'verified' : section.anchorOutcome.reason)}</dd></dl></details></article>`;
|
|
258
258
|
}).join('');
|
|
259
259
|
const taskIndex = renderTaskIndex(sections, lookup, folds, planActivity(readModel));
|
|
260
260
|
const structureButton = hasTodoStructurePresentation(structurePresentation)
|
|
@@ -73,6 +73,9 @@ export function renderConnectionChips(connections = []) {
|
|
|
73
73
|
return `${open === 0 ? '' : `<span class="connection-chip">他条件に接続 ${open}</span>`}${priority === 0 ? '' : '<span class="connection-chip">優先接続</span>'}`;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** ADR 0205 §7: the 分割待ち / 関数分割 chip, drawn beside the status (which it never replaces). */
|
|
77
|
+
export const renderSplitLabel = (label) => (label === null || label === undefined ? '' : `<span class="connection-chip">${escapeHtmlText(label)}</span>`);
|
|
78
|
+
|
|
76
79
|
export function renderTaskIndexEntry(section, lookup) {
|
|
77
80
|
const key = refKey(section.ref);
|
|
78
81
|
const status = DOCUMENT_STATUS[section.state.status] ?? { mark: '?', label: '状態不明' };
|
|
@@ -81,7 +84,7 @@ export function renderTaskIndexEntry(section, lookup) {
|
|
|
81
84
|
// A ToDo the diagram does not draw keeps its row here — the index is the
|
|
82
85
|
// complete list — and it selects its own detail, which exists either way.
|
|
83
86
|
const selectKey = key;
|
|
84
|
-
return `<li><button type="button" data-select-node-key="${escapeHtmlAttribute(selectKey)}"><span class="task-index-status status-${escapeHtmlAttribute(section.state.status)}" role="img" aria-label="${escapeHtmlAttribute(status.label)}">${escapeHtmlText(status.mark)}</span
|
|
87
|
+
return `<li><button type="button" data-select-node-key="${escapeHtmlAttribute(selectKey)}"><span class="task-index-status status-${escapeHtmlAttribute(section.state.status)}" role="img" aria-label="${escapeHtmlAttribute(status.label)}">${escapeHtmlText(status.mark)}</span>${renderSplitLabel(section.splitLabel)}<span class="task-index-reference">${escapeHtmlText(taskReference(section, lookup))}</span><strong>${escapeHtmlText(section.task.title)}</strong>${blockedReason}${renderConnectionChips(section.connections)}</button></li>`;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
/** plan_key -> 最終活動時刻。journalの末尾eventが、そのplanが最後に動いた時点。 */
|