@quolu/lattice 0.103.0 → 0.104.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.md +17 -0
- package/package.json +1 -1
- package/src/cli-help.mjs +47 -8
- package/src/cli-refusal-guidance.mjs +18 -3
- package/src/project-cli.mjs +2 -1
- package/src/todo-cli.mjs +250 -25
- package/src/todo-contracts.mjs +34 -17
- package/src/todo-gantt-html-independence.mjs +2 -2
- package/src/todo-gantt-html-shared.mjs +30 -1
- package/src/todo-gantt-html-style.mjs +1 -0
- package/src/todo-gantt-html.mjs +7 -4
- package/src/todo-gantt-layout.mjs +2 -0
- package/src/todo-independence-guidance.mjs +2 -2
- package/src/todo-migration.mjs +5 -6
- package/src/todo-note-store.mjs +1 -1
- package/src/todo-notice-store.mjs +2 -2
- package/src/todo-notices.mjs +12 -1
- package/src/todo-readiness.mjs +53 -7
- package/src/todo-revision.mjs +12 -13
- package/src/todo-status.mjs +46 -7
- package/src/todo-store-view.mjs +59 -0
- package/src/todo-store.mjs +44 -5
package/src/todo-cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTodoReadiness, retireStateConflict, validateProspectiveEvent } from './todo-readiness.mjs';
|
|
1
|
+
import { createTodoReadiness, listTodoConnections, retireStateConflict, validateProspectiveEvent } from './todo-readiness.mjs';
|
|
2
2
|
import { cliCommandKind } from './cli-command-kind.mjs';
|
|
3
3
|
import { cliFailureClass } from './cli-failure-class.mjs';
|
|
4
4
|
import { ENFORCED_DONE_MESSAGE, FLAG_PLACEHOLDER, publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
|
|
@@ -170,7 +170,7 @@ import {
|
|
|
170
170
|
} from './seam-proposal-contracts.mjs';
|
|
171
171
|
import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
|
|
172
172
|
import { collectSensorEvidence } from './sensor-adapter.mjs';
|
|
173
|
-
import { newTodoNotices, projectTodoNotices, waitInEffect } from './todo-notices.mjs';
|
|
173
|
+
import { newTodoNotices, projectTodoNotices, waitInEffect, withTodoPriorityWaits } from './todo-notices.mjs';
|
|
174
174
|
import {
|
|
175
175
|
externalCycle, readTodoExternalChart, readTodoExternalTasks, withTodoExternalTasks,
|
|
176
176
|
} from './todo-external.mjs';
|
|
@@ -314,7 +314,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
|
|
|
314
314
|
'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
315
315
|
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
316
316
|
'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
317
|
-
'retract', 'dependency', 'add', 'notice', 'wait', 'blockers',
|
|
317
|
+
'retract', 'dependency', 'predecessor', 'connect', 'add', 'notice', 'wait', 'blockers',
|
|
318
318
|
]);
|
|
319
319
|
|
|
320
320
|
function typedArgumentFailure(stderr, code, message, detail, context = {}) {
|
|
@@ -338,6 +338,8 @@ const DEPENDENCY_FLAG_SPEC = Object.freeze({
|
|
|
338
338
|
known: ['from-project', 'from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
|
|
339
339
|
required: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
|
|
340
340
|
});
|
|
341
|
+
const PREDECESSOR_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'after', 'reason'], required: ['plan', 'task', 'after', 'reason'] });
|
|
342
|
+
const CONNECT_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'to', 'reason'], required: ['plan', 'task', 'to', 'reason'] });
|
|
341
343
|
// a18: one spec per write command is both its parser and the explanation of its refusal.
|
|
342
344
|
const TODO_FLAG_SPECS = Object.freeze({
|
|
343
345
|
start: Object.freeze({
|
|
@@ -357,6 +359,11 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
357
359
|
required: ['plan', 'task', 'title'],
|
|
358
360
|
}),
|
|
359
361
|
'dependency disconnect': DEPENDENCY_FLAG_SPEC,
|
|
362
|
+
'predecessor add': PREDECESSOR_FLAG_SPEC,
|
|
363
|
+
'predecessor remove': PREDECESSOR_FLAG_SPEC,
|
|
364
|
+
'connect condition add': CONNECT_FLAG_SPEC,
|
|
365
|
+
'connect condition remove': CONNECT_FLAG_SPEC,
|
|
366
|
+
'connect condition resolve': Object.freeze({ known: ['plan', 'task', 'to', 'message'], required: ['plan', 'task', 'to', 'message'] }),
|
|
360
367
|
// a23: the remaining writes whose refusal pointed only at --help.
|
|
361
368
|
'phase review': PHASE_REASON_FLAG_SPEC,
|
|
362
369
|
'phase close-unaudited': PHASE_REASON_FLAG_SPEC,
|
|
@@ -377,6 +384,7 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
377
384
|
'notice list': Object.freeze({ known: ['lane', 'include-acked', 'json'], required: [], booleans: ['include-acked', 'json'] }),
|
|
378
385
|
'notice ack': Object.freeze({ known: ['lane', 'notice', 'json'], required: ['lane', 'notice'], booleans: ['json'] }),
|
|
379
386
|
blockers: Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
|
|
387
|
+
'connect priority': Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
|
|
380
388
|
wait: Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
|
|
381
389
|
'note list': Object.freeze({ known: ['plan', 'task', 'json'], required: ['plan'], booleans: ['json'] }),
|
|
382
390
|
'phase status': Object.freeze({ known: ['plan', 'json'], required: ['plan'], booleans: ['json'] }),
|
|
@@ -388,10 +396,12 @@ const WITNESS_TEMPLATE_FLAG_SPEC = Object.freeze({
|
|
|
388
396
|
// a28: command groups, their subcommands and the one a refusal shows as the example.
|
|
389
397
|
const TODO_SUBCOMMANDS = Object.freeze({
|
|
390
398
|
dependency: { names: ['connect', 'disconnect'], example: 'connect' },
|
|
399
|
+
predecessor: { names: ['add', 'remove'], example: 'add' },
|
|
400
|
+
connect: { names: ['condition', 'priority'], example: 'priority' },
|
|
391
401
|
phase: { names: ['status', 'review', 'accept', 'reject', 'reopen', 'close-unaudited', 'baseline'], example: 'review' },
|
|
392
402
|
evidence: { names: ['promote'], example: 'promote' },
|
|
393
403
|
});
|
|
394
|
-
const GROUP_COMMANDS = ['dependency', 'phase', 'evidence', 'independence', 'note', 'structure'];
|
|
404
|
+
const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', 'evidence', 'independence', 'note', 'structure'];
|
|
395
405
|
const IDENTIFIER_FLAGS = ['plan', 'task', 'phase', 'from-plan', 'from-task', 'to-plan', 'to-task'];
|
|
396
406
|
// The shared table is FLAG_PLACEHOLDER (cli-refusal-guidance, a27).
|
|
397
407
|
const placeholder = (name) => FLAG_PLACEHOLDER[name] ?? `<${name}>`;
|
|
@@ -444,6 +454,13 @@ function explainMissingSubcommand(argv) {
|
|
|
444
454
|
+ ' (every command: `lattice todo --help`).' };
|
|
445
455
|
}
|
|
446
456
|
const group = TODO_SUBCOMMANDS[argv[0]];
|
|
457
|
+
if (argv[0] === 'connect' && argv[1] === 'condition' && !['add', 'remove', 'resolve'].includes(argv[2])) {
|
|
458
|
+
const missing = typeof argv[2] !== 'string' || argv[2].startsWith('--');
|
|
459
|
+
return { pointer: missing ? '<subcommand>' : argv[2], rule: missing ? 'subcommand_missing' : 'subcommand_unknown',
|
|
460
|
+
available_subcommands: ['add', 'remove', 'resolve'],
|
|
461
|
+
next_action: 'Name one of add, remove, resolve after `lattice todo connect condition`, e.g.'
|
|
462
|
+
+ ' `lattice todo connect condition add --plan <plan> --task <id> --to task:<project>/<plan>/<task> --reason <text>`.' };
|
|
463
|
+
}
|
|
447
464
|
if (group === undefined || group.names.includes(argv[1])) return null;
|
|
448
465
|
const missing = typeof argv[1] !== 'string' || argv[1].startsWith('--');
|
|
449
466
|
const head = [argv[0], group.example];
|
|
@@ -459,6 +476,7 @@ function explainArgumentRefusal(argv) {
|
|
|
459
476
|
const missingSubcommand = explainMissingSubcommand(argv);
|
|
460
477
|
if (missingSubcommand !== null) return missingSubcommand;
|
|
461
478
|
const head = argv[0] === 'independence' && argv[1] === 'witness' ? argv.slice(0, 3)
|
|
479
|
+
: argv[0] === 'connect' && argv[1] === 'condition' ? argv.slice(0, 3)
|
|
462
480
|
: GROUP_COMMANDS.includes(argv[0]) && typeof argv[1] === 'string' && !argv[1].startsWith('--')
|
|
463
481
|
? argv.slice(0, 2) : argv.slice(0, 1);
|
|
464
482
|
// a32: `scaffold --template` is a read with its own flags.
|
|
@@ -532,6 +550,14 @@ function explainArgumentRefusal(argv) {
|
|
|
532
550
|
return { pointer: `--${name}`, rule: 'flag_missing', next_action: `Give --${name} a non-empty <text>: \`${repairedCommand(head, spec, flags)}\`.` };
|
|
533
551
|
}
|
|
534
552
|
}
|
|
553
|
+
if (argv[0] === 'connect' && argv[1] === 'condition' && parseConditionTarget(flags.to, '') === null) {
|
|
554
|
+
return { pointer: '--to', rule: 'target_invalid', actual: flags.to,
|
|
555
|
+
next_action: 'Name the 接続先 as `task:<project>/<plan>/<task>` (a task on another chart) or `schedule:<id>` (a BellTeam schedule).' };
|
|
556
|
+
}
|
|
557
|
+
if (argv[0] === 'predecessor' && typeof flags.after === 'string' && parsePredecessorTarget(flags.after, '') === null) {
|
|
558
|
+
return { pointer: '--after', rule: 'target_invalid', actual: flags.after,
|
|
559
|
+
next_action: 'Name the 前工程 as `<plan>/<task>`, a task on this chart (task ids: `lattice plan show <plan> --json`).' };
|
|
560
|
+
}
|
|
535
561
|
if (argv[0] === 'start' && flags.rebind === true && !(typeof flags.reason === 'string' && flags.reason.length > 0)) {
|
|
536
562
|
return { pointer: '--reason', rule: 'flag_missing',
|
|
537
563
|
next_action: `--rebind needs --reason <text>: \`${repairedCommand(head, { ...spec, required: [...spec.required, 'reason'] }, flags)}\`.` };
|
|
@@ -1069,6 +1095,15 @@ async function mutate({
|
|
|
1069
1095
|
return result;
|
|
1070
1096
|
}
|
|
1071
1097
|
|
|
1098
|
+
/** ブロック is the last resort; its result says what to use first (前工程: predecessor, 接続: connect condition). */
|
|
1099
|
+
const BLOCK_GUIDANCE = '待っているものが自分の工程表の工程なら todo predecessor add(前工程)、それ以外で名指しや確認ができるもの(別の工程表の工程、予定表の確認)は'
|
|
1100
|
+
+ ' todo connect condition add(他条件に接続)を使う。ブロックは最後の手段(`lattice todo unblock`で外す)。';
|
|
1101
|
+
function withBlockGuidance(result) {
|
|
1102
|
+
const guided = { ...result, next_action: BLOCK_GUIDANCE, result_digest: '' };
|
|
1103
|
+
guided.result_digest = todoSelfDigest(guided, 'result_digest');
|
|
1104
|
+
return guided;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1072
1107
|
/** retract-anyone: a reopened task is unstarted again; the redo records a start (from any seat). */
|
|
1073
1108
|
async function reopenTask({ repoRoot, env, planKey, taskId, payload }) {
|
|
1074
1109
|
const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload, evidenceRef: null });
|
|
@@ -1131,7 +1166,7 @@ async function unchangedTransition(store, { env, planKey, taskId, kind, dropped
|
|
|
1131
1166
|
journal_head_digest: events.at(-1).event_digest, snapshot_digest: member.snapshot.snapshot_digest,
|
|
1132
1167
|
status: state.status, advisory: null, unchanged: true,
|
|
1133
1168
|
// a18: a repeated transition appends nothing, so say which given content was not recorded.
|
|
1134
|
-
...(notRecorded.length === 0 ? {} : {
|
|
1169
|
+
...(notRecorded.length === 0 ? (kind === 'block' ? { next_action: BLOCK_GUIDANCE } : {}) : {
|
|
1135
1170
|
not_recorded: notRecorded,
|
|
1136
1171
|
next_action: `${planKey}/${state.task_id} ${NOT_RECORDED_NEXT[kind](`--plan ${planKey} --task ${state.task_id}`, notRecorded.join(', '))}`,
|
|
1137
1172
|
}),
|
|
@@ -1413,12 +1448,25 @@ async function displayRead(repoRoot, env) {
|
|
|
1413
1448
|
const display = await readTodoStoreForDisplay({ repoRoot });
|
|
1414
1449
|
const externalTasks = display.store ? (await readTodoExternalTasks(display.store, env)).external_tasks : [];
|
|
1415
1450
|
return { schema: 'lattice.todo_display_read_result.v1', ...display, external_tasks: externalTasks,
|
|
1416
|
-
trees: display.store ? projectTodoTrees(display.store) : []
|
|
1451
|
+
trees: display.store ? projectTodoTrees(display.store) : [],
|
|
1452
|
+
connections: display.store ? await displayConnections(repoRoot, { ...display.store, external_tasks: externalTasks }) : [] };
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
/** 接続: `[{plan_key, task_id, connections}]` for every task that has any (the one list: 他条件に接続 and 優先接続). */
|
|
1456
|
+
async function displayConnections(repoRoot, store) {
|
|
1457
|
+
// The display reads unverified members too and must not stop: an unreadable store shows no 接続.
|
|
1458
|
+
try {
|
|
1459
|
+
const full = await withTodoPriorityWaits(store, { repoRoot });
|
|
1460
|
+
const readiness = createTodoReadiness(full);
|
|
1461
|
+
return full.members.flatMap(({ plan }) => (plan.tasks ?? []).map((task) => ({ plan_key: plan.plan_key, task_id: task.task_id,
|
|
1462
|
+
connections: readiness.allConnections(readiness.key({ ...plan, task_id: task.task_id })) })))
|
|
1463
|
+
.filter(({ connections }) => connections.length > 0);
|
|
1464
|
+
} catch { return []; }
|
|
1417
1465
|
}
|
|
1418
1466
|
|
|
1419
1467
|
/** xchart: the Store plus its external predecessors' states; every readiness reader reads through this. */
|
|
1420
1468
|
async function readTodoStoreForReadiness({ repoRoot, env = process.env }) {
|
|
1421
|
-
return withTodoExternalTasks(await readTodoStore({ repoRoot }), env);
|
|
1469
|
+
return withTodoPriorityWaits(await withTodoExternalTasks(await readTodoStore({ repoRoot }), env), { repoRoot });
|
|
1422
1470
|
}
|
|
1423
1471
|
|
|
1424
1472
|
async function startTask({
|
|
@@ -1531,7 +1579,7 @@ function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
|
|
|
1531
1579
|
if (advisory.conflicts_with_active.length > 0 && overrideReason === null) {
|
|
1532
1580
|
const active = advisory.conflicts_with_active.map(({ active_task_id: id }) => id);
|
|
1533
1581
|
refuse('enforced_conflict_with_active', { conflicts_with_active: advisory.conflicts_with_active,
|
|
1534
|
-
next_action: `${taskId} overlaps in-progress ${active.join(', ')}:
|
|
1582
|
+
next_action: `${taskId} overlaps in-progress ${active.join(', ')}: make it a 前工程 with \`lattice todo predecessor add --plan ${planKey} --task ${taskId} --after ${planKey}/${active[0]} --reason <text>\`,`
|
|
1535
1583
|
+ ` or start anyway with \`lattice todo start --plan ${planKey} --task ${taskId} --override-reason <text>\` (the reason is recorded).` });
|
|
1536
1584
|
}
|
|
1537
1585
|
}
|
|
@@ -2139,6 +2187,148 @@ async function dependencyDisconnectLedger({
|
|
|
2139
2187
|
return result;
|
|
2140
2188
|
}
|
|
2141
2189
|
|
|
2190
|
+
/** `dependency connect|disconnect` is an alias for one minor version: each run says which of the two commands replaces it. */
|
|
2191
|
+
function retiredDependencyCommand(stderr, operation, flags, result) {
|
|
2192
|
+
const edge = `--plan ${flags['to-plan']} --task ${flags['to-task']}`;
|
|
2193
|
+
const use = flags['from-project'] === undefined
|
|
2194
|
+
? `lattice todo predecessor ${operation} ${edge} --after ${flags['from-plan']}/${flags['from-task']} --reason <text>`
|
|
2195
|
+
: `lattice todo connect condition ${operation} ${edge} --to task:${flags['from-project']}/${flags['from-plan']}/${flags['from-task']} --reason <text>`;
|
|
2196
|
+
stderr.write(`${JSON.stringify({ schema: 'lattice.todo_command_retired.v1', command: `todo dependency ${operation === 'add' ? 'connect' : 'disconnect'}`,
|
|
2197
|
+
still_works_until: 'the next minor version', use })}\n`);
|
|
2198
|
+
return result;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
// 前工程 (`todo predecessor`) and 他条件に接続 (`todo connect condition`) are two commands with disjoint targets
|
|
2202
|
+
// ([connect flow](../docs/architecture/dfd-connect.md)): each refuses the other's target and names the right command.
|
|
2203
|
+
|
|
2204
|
+
/** `<plan>/<task>` (this chart); `<project>/<plan>/<task>` or a `task:`/`schedule:` target are another chart or a schedule. */
|
|
2205
|
+
function parsePredecessorTarget(text, projectId) {
|
|
2206
|
+
if (typeof text !== 'string') return null;
|
|
2207
|
+
if (/^schedule:/u.test(text)) return { sameChart: false };
|
|
2208
|
+
const parts = text.replace(/^task:/u, '').split('/');
|
|
2209
|
+
if (parts.length < 2 || parts.length > 3 || !parts.every(isTodoIdentifier)) return null;
|
|
2210
|
+
const [owner, planKey, taskId] = parts.length === 3 ? parts : [projectId, ...parts];
|
|
2211
|
+
return { sameChart: owner === projectId, projectId: owner, planKey, taskId };
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/** `task:<project>/<plan>/<task>` or `schedule:<id>` (id: printable ASCII, no spaces, <= 128). null when malformed (exit 2, pointer --to). */
|
|
2215
|
+
function parseConditionTarget(text, projectId) {
|
|
2216
|
+
if (typeof text !== 'string') return null;
|
|
2217
|
+
if (text.startsWith('schedule:')) {
|
|
2218
|
+
const id = text.slice('schedule:'.length);
|
|
2219
|
+
return /^[!-~]{1,128}$/u.test(id) ? { kind: 'schedule', id, ref: id } : null;
|
|
2220
|
+
}
|
|
2221
|
+
const parts = text.startsWith('task:') ? text.slice('task:'.length).split('/') : [];
|
|
2222
|
+
if (parts.length !== 3 || !parts.every(isTodoIdentifier)) return null;
|
|
2223
|
+
const [owner, planKey, taskId] = parts;
|
|
2224
|
+
return { kind: 'task', projectId: owner, planKey, taskId, ref: `${owner}/${planKey}/${taskId}`, sameChart: owner === projectId };
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
async function predecessorChange({ repoRoot, env, operation, planKey, taskId, after, reason }) {
|
|
2228
|
+
const store = await readTodoStore({ repoRoot });
|
|
2229
|
+
const target = parsePredecessorTarget(after, store.project_id);
|
|
2230
|
+
if (target === null) {
|
|
2231
|
+
throw new TodoStoreError('DEPENDENCY_INVALID', 'predecessor_target_invalid', undefined, {
|
|
2232
|
+
after, next_action: 'Name the 前工程 as `<plan>/<task>`, a task on this chart (task ids: `lattice plan show <plan> --json`).' });
|
|
2233
|
+
}
|
|
2234
|
+
if (!target.sameChart) {
|
|
2235
|
+
throw new TodoStoreError('CONNECTION_INVALID', 'predecessor_target_not_same_chart', undefined, {
|
|
2236
|
+
after,
|
|
2237
|
+
next_action: `${after} is not a task on this chart, so it is a 接続, not a 前工程: \`lattice todo connect condition ${operation}`
|
|
2238
|
+
+ ` --plan ${planKey} --task ${taskId} --to ${/^(task|schedule):/u.test(after) ? after : `task:${after}`} --reason <text>\`.`,
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
const options = {
|
|
2242
|
+
repoRoot, env, fromProjectId: null, fromPlanKey: target.planKey, fromTaskId: target.taskId,
|
|
2243
|
+
toPlanKey: planKey, toTaskId: taskId, reason,
|
|
2244
|
+
};
|
|
2245
|
+
return operation === 'add' ? dependencyConnect(options) : dependencyDisconnect(options);
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
function connectionResult(store, { operation, planKey, taskId, target, event = null, unchanged = false, reason = null, evidence = null, next_action = null }) {
|
|
2249
|
+
const result = {
|
|
2250
|
+
schema: unchanged ? 'lattice.todo_connection_unchanged_result.v1' : 'lattice.todo_connection_result.v1',
|
|
2251
|
+
project_id: store.project_id, operation, plan_key: planKey, task_id: taskId,
|
|
2252
|
+
to: { kind: target.kind, ref: target.ref },
|
|
2253
|
+
...(reason === null ? {} : { reason }), ...(evidence === null ? {} : { evidence }),
|
|
2254
|
+
...(event === null ? { unchanged: true } : {
|
|
2255
|
+
event_digest: event.event_digest, recorded_at: event.recorded_at, actor: event.actor }),
|
|
2256
|
+
next_action,
|
|
2257
|
+
result_digest: '',
|
|
2258
|
+
};
|
|
2259
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
2260
|
+
return result;
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
/** Whether this plan's chain ever recorded a cross-chart edge to the target (a removed edge is not listed; a retried remove stays safe). */
|
|
2264
|
+
function everConnected(member, taskId, target) {
|
|
2265
|
+
return (member.plan_scoped?.events ?? []).some((event) => event.kind === 'cross_plan_dependency'
|
|
2266
|
+
&& event.payload?.to?.task_id === taskId && event.payload?.from?.project_id === target.projectId
|
|
2267
|
+
&& event.payload?.from?.plan_key === target.planKey && event.payload?.from?.task_id === target.taskId);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* `todo connect condition add|remove|resolve`: a task on another chart, or a BellTeam schedule, as a 接続.
|
|
2272
|
+
* Every write is idempotent (a retry after an unknown outcome is safe): add of an open identical 接続, resolve of a
|
|
2273
|
+
* settled one and remove with nothing open answer `unchanged: true`; only a target never added is refused.
|
|
2274
|
+
*/
|
|
2275
|
+
async function connectCondition({ repoRoot, env, operation, planKey, taskId, to, reason = null, message = null }) {
|
|
2276
|
+
const store = await readTodoStoreForReadiness({ repoRoot, env });
|
|
2277
|
+
const target = parseConditionTarget(to, store.project_id);
|
|
2278
|
+
const refuse = (code, why, detail) => new TodoStoreError(code, why, undefined, { to, ...detail });
|
|
2279
|
+
if (target.kind === 'task' && target.sameChart) {
|
|
2280
|
+
throw refuse('CONNECTION_INVALID', 'condition_target_same_chart', {
|
|
2281
|
+
next_action: `${target.planKey}/${target.taskId} is on this chart, so it is a 前工程, not a 接続: \`lattice todo predecessor ${operation === 'remove' ? 'remove' : 'add'}`
|
|
2282
|
+
+ ` --plan ${planKey} --task ${taskId} --after ${target.planKey}/${target.taskId} --reason <text>\`.` });
|
|
2283
|
+
}
|
|
2284
|
+
const member = store.members.find(({ plan }) => plan.plan_key === planKey);
|
|
2285
|
+
if (member === undefined) throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
|
|
2286
|
+
if (!member.plan.tasks.some(({ task_id: id }) => id === taskId)) {
|
|
2287
|
+
throw new TodoStoreError('TASK_NOT_FOUND', 'task_not_found', undefined, { requested_task_id: taskId });
|
|
2288
|
+
}
|
|
2289
|
+
const base = { operation, planKey, taskId, target };
|
|
2290
|
+
const addAgain = `lattice todo connect condition add --plan ${planKey} --task ${taskId} --to ${to} --reason <text>`;
|
|
2291
|
+
const notFound = () => refuse('CONNECTION_INVALID', 'connection_not_found', {
|
|
2292
|
+
next_action: `${planKey}/${taskId} has no 接続 to ${to}; add it with \`${addAgain}\` (list them with \`lattice todo show --plan ${planKey} --task ${taskId} --json\`, prerequisites.connections).` });
|
|
2293
|
+
if (target.kind === 'task') {
|
|
2294
|
+
if (operation === 'resolve') {
|
|
2295
|
+
throw refuse('CONNECTION_INVALID', 'condition_task_target_settles_itself', {
|
|
2296
|
+
next_action: `A 接続 to a task settles when ${target.ref} is done or retired; only \`schedule:<id>\` is resolved by hand.` });
|
|
2297
|
+
}
|
|
2298
|
+
const edge = { repoRoot, env, fromProjectId: target.projectId, fromPlanKey: target.planKey, fromTaskId: target.taskId,
|
|
2299
|
+
toPlanKey: planKey, toTaskId: taskId, reason };
|
|
2300
|
+
if (operation === 'add') return dependencyConnect(edge);
|
|
2301
|
+
try {
|
|
2302
|
+
return await dependencyDisconnect(edge);
|
|
2303
|
+
} catch (error) {
|
|
2304
|
+
if (error?.code !== 'DEPENDENCY_NOT_FOUND') throw error;
|
|
2305
|
+
if (!everConnected(member, taskId, target)) throw notFound();
|
|
2306
|
+
return connectionResult(store, { ...base, unchanged: true, next_action: `${to} is already removed; nothing was recorded.` });
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
// Store is idempotent (appendTodoEvent answers `unchanged`), so no pre-check; the newest entry for this ref names the target.
|
|
2310
|
+
const shown = listTodoConnections(store, planKey, taskId, { includeRemoved: true })
|
|
2311
|
+
.filter((entry) => entry.kind === 'schedule' && entry.ref === target.id)
|
|
2312
|
+
.sort((left, right) => (left.since < right.since ? 1 : left.since > right.since ? -1 : 0))[0] ?? null;
|
|
2313
|
+
if (operation !== 'add' && shown === null) throw notFound();
|
|
2314
|
+
const event = {
|
|
2315
|
+
add: { kind: 'connection_added', payload: { task_id: taskId, to: { kind: 'schedule', id: target.id }, reason } },
|
|
2316
|
+
remove: { kind: 'connection_removed', payload: { target_event_digest: shown?.event_digest, reason } },
|
|
2317
|
+
resolve: { kind: 'connection_resolved', payload: { target_event_digest: shown?.event_digest, evidence: message } },
|
|
2318
|
+
}[operation];
|
|
2319
|
+
const recorded = await appendTodoEvent({
|
|
2320
|
+
validateProspectiveEvent, repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
|
|
2321
|
+
event: { ...event, actor: resolveTodoActor(env) },
|
|
2322
|
+
});
|
|
2323
|
+
if (recorded.unchanged === true) {
|
|
2324
|
+
return connectionResult(store, { ...base, unchanged: true, next_action: `${to} is already ${{ add: 'connected', remove: 'removed', resolve: 'settled' }[operation]}; nothing was recorded.` });
|
|
2325
|
+
}
|
|
2326
|
+
return connectionResult(store, { ...base, event: recorded.event, reason, evidence: message,
|
|
2327
|
+
next_action: operation === 'add'
|
|
2328
|
+
? `${planKey}/${taskId} cannot start until ${to} settles; the schedule's command settles it with \`lattice todo connect condition resolve\`.`
|
|
2329
|
+
: null });
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2142
2332
|
async function phaseStatus({ repoRoot, planKey }) {
|
|
2143
2333
|
const store = await readTodoStore({ repoRoot });
|
|
2144
2334
|
const [member] = selectMembers(store, planKey);
|
|
@@ -2790,7 +2980,8 @@ function taskPrerequisites(store, member, taskId) {
|
|
|
2790
2980
|
const key = readiness.key({ ...member.plan, task_id: taskId });
|
|
2791
2981
|
const { blocking } = readiness.prerequisites(key);
|
|
2792
2982
|
return { ready: readiness.isReady(key), tasks: readiness.prerequisiteRefs(key).tasks,
|
|
2793
|
-
blocking_tasks: blocking.blocking_tasks ?? [], blocking_phases: blocking.blocking_phases ?? []
|
|
2983
|
+
blocking_tasks: blocking.blocking_tasks ?? [], blocking_phases: blocking.blocking_phases ?? [],
|
|
2984
|
+
connections: readiness.allConnections(key) };
|
|
2794
2985
|
}
|
|
2795
2986
|
|
|
2796
2987
|
/**
|
|
@@ -4580,6 +4771,11 @@ export async function renderTodoGanttForProject({
|
|
|
4580
4771
|
topology_digest: member.plan.topology_digest,
|
|
4581
4772
|
journal_head_digest: member.journal.events.at(-1)?.event_digest ?? null,
|
|
4582
4773
|
}));
|
|
4774
|
+
// One 接続 area per task: 他条件に接続 and 優先接続 from the single `connections` list (Store: listTodoConnections).
|
|
4775
|
+
const connections = store.members.flatMap(({ plan }) => plan.tasks.map(({ task_id: taskId }) => ({
|
|
4776
|
+
project_id: plan.project_id, plan_key: plan.plan_key, task_id: taskId,
|
|
4777
|
+
connections: listTodoConnections(store, plan.plan_key, taskId),
|
|
4778
|
+
}))).filter((entry) => entry.connections.length > 0);
|
|
4583
4779
|
const metadata = {
|
|
4584
4780
|
manifest_digest: store.manifest.manifest_digest,
|
|
4585
4781
|
member_bindings: memberBindings,
|
|
@@ -4587,6 +4783,7 @@ export async function renderTodoGanttForProject({
|
|
|
4587
4783
|
presentation_digest: presentation?.presentation_digest ?? null,
|
|
4588
4784
|
layout_digest: digestTodoArtifact(layout),
|
|
4589
4785
|
note_bindings_digest: digestTodoArtifact(notes.headBindings),
|
|
4786
|
+
connections_digest: digestTodoArtifact(connections),
|
|
4590
4787
|
structure_projection_digest: structures?.projection_digest ?? null,
|
|
4591
4788
|
renderer_version: TODO_GANTT_RENDERER_VERSION,
|
|
4592
4789
|
project_display_name: identity.displayName,
|
|
@@ -4604,6 +4801,7 @@ export async function renderTodoGanttForProject({
|
|
|
4604
4801
|
noteWarnings: notes.warnings,
|
|
4605
4802
|
structurePresentation: structures,
|
|
4606
4803
|
notices,
|
|
4804
|
+
connections,
|
|
4607
4805
|
});
|
|
4608
4806
|
return { store, metadata, memberBindings, rendered };
|
|
4609
4807
|
}
|
|
@@ -4751,6 +4949,8 @@ function writesTodoStore(argv) {
|
|
|
4751
4949
|
case 'seam-proposal': return ['compile', 'apply', 'land'].includes(second);
|
|
4752
4950
|
case 'evidence': return second === 'promote';
|
|
4753
4951
|
case 'dependency': return ['connect', 'disconnect'].includes(second);
|
|
4952
|
+
case 'predecessor': return ['add', 'remove'].includes(second);
|
|
4953
|
+
case 'connect': return second === 'condition' && ['add', 'remove', 'resolve'].includes(argv[2]);
|
|
4754
4954
|
case 'phase': return second !== 'status';
|
|
4755
4955
|
case 'start': case 'retract': case 'block': case 'unblock': case 'retire': case 'done':
|
|
4756
4956
|
case 'reopen': case 'split': case 'revise': case 'revise-phase': case 'revise-set': case 'add':
|
|
@@ -4764,7 +4964,9 @@ function releasesTasks(argv) {
|
|
|
4764
4964
|
const [command, second] = argv;
|
|
4765
4965
|
return ['done', 'retire', 'unblock'].includes(command)
|
|
4766
4966
|
|| (command === 'phase' && ['accept', 'close-unaudited'].includes(second))
|
|
4767
|
-
|| (command === 'dependency' && second === 'disconnect')
|
|
4967
|
+
|| (command === 'dependency' && second === 'disconnect')
|
|
4968
|
+
|| (command === 'predecessor' && second === 'remove')
|
|
4969
|
+
|| (command === 'connect' && second === 'condition' && ['remove', 'resolve'].includes(argv[2]));
|
|
4768
4970
|
}
|
|
4769
4971
|
|
|
4770
4972
|
/** `declared(planKey, taskId)`: whether an enforced plan's witness set records the task's row (unreadable = none). */
|
|
@@ -4934,10 +5136,10 @@ async function noticeAck({ repoRoot, env, lane, ids }) {
|
|
|
4934
5136
|
}
|
|
4935
5137
|
|
|
4936
5138
|
/**
|
|
4937
|
-
* `todo
|
|
4938
|
-
* gate: an already startable or finished T is answered with a state and nothing is written.
|
|
5139
|
+
* `todo connect priority` (優先接続; `todo wait` is its alias for one minor version): record that this agent asks to be told the
|
|
5140
|
+
* moment T can start. A record, never a gate: an already startable or finished T is answered with a state and nothing is written.
|
|
4939
5141
|
*/
|
|
4940
|
-
async function
|
|
5142
|
+
async function noticePriority({ repoRoot, env, planKey, taskId, reason, cancel }) {
|
|
4941
5143
|
const view = await openNoticeView(repoRoot, env);
|
|
4942
5144
|
const { store } = view;
|
|
4943
5145
|
const member = store.members.find(({ plan }) => plan.plan_key === planKey);
|
|
@@ -4947,7 +5149,7 @@ async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
|
|
|
4947
5149
|
throw new TodoStoreError('TASK_NOT_FOUND', 'task_not_found', undefined, { requested_task_id: taskId });
|
|
4948
5150
|
}
|
|
4949
5151
|
const { agent } = resolveTodoActor(env);
|
|
4950
|
-
const base = { schema: 'lattice.
|
|
5152
|
+
const base = { schema: 'lattice.todo_connect_priority_result.v1', project_id: store.project_id, plan_key: planKey, task_id: taskId, agent };
|
|
4951
5153
|
let rest;
|
|
4952
5154
|
if (cancel) {
|
|
4953
5155
|
const { cancelled } = await cancelTodoNoticeWait({ repoRoot, planKey, taskId, agent });
|
|
@@ -4967,7 +5169,7 @@ async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
|
|
|
4967
5169
|
repoRoot, planKey, taskId, agent, reason: reason ?? null, now,
|
|
4968
5170
|
keep: (wait) => waitInEffect(store, { plan_key: planKey, ...wait }),
|
|
4969
5171
|
});
|
|
4970
|
-
rest = { state: '
|
|
5172
|
+
rest = { state: 'prioritized', since, reason: reason ?? null, notice: null, next_action: null };
|
|
4971
5173
|
}
|
|
4972
5174
|
}
|
|
4973
5175
|
const result = { ...base, ...rest, result_digest: '' };
|
|
@@ -5372,13 +5574,22 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5372
5574
|
}
|
|
5373
5575
|
} else if (argv[0] === 'blockers' && matchFlagCommand(argv, ['blockers'], TODO_FLAG_SPECS.blockers) !== null) {
|
|
5374
5576
|
action = (repoRoot) => blockerList({ repoRoot });
|
|
5375
|
-
} else if (argv[0] === '
|
|
5376
|
-
|
|
5577
|
+
} else if ((argv[0] === 'connect' && argv[1] === 'priority' || argv[0] === 'wait')
|
|
5578
|
+
&& matchFlagCommand(argv, argv[0] === 'wait' ? ['wait'] : ['connect', 'priority'], TODO_FLAG_SPECS[argv[0] === 'wait' ? 'wait' : 'connect priority']) !== null) {
|
|
5579
|
+
const flags = matchFlagCommand(argv, argv[0] === 'wait' ? ['wait'] : ['connect', 'priority'], TODO_FLAG_SPECS[argv[0] === 'wait' ? 'wait' : 'connect priority']);
|
|
5377
5580
|
const reasonOk = flags.reason === undefined
|
|
5378
5581
|
|| (typeof flags.reason === 'string' && flags.reason.length > 0 && flags.reason.length <= 1024 && !/\p{Cc}/u.test(flags.reason));
|
|
5379
5582
|
if (isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task) && reasonOk && !(flags.cancel === true && flags.reason !== undefined)) {
|
|
5380
|
-
action = (repoRoot) =>
|
|
5381
|
-
|
|
5583
|
+
action = async (repoRoot) => {
|
|
5584
|
+
const result = await noticePriority({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5585
|
+
reason: flags.reason ?? null, cancel: flags.cancel === true });
|
|
5586
|
+
if (argv[0] === 'wait') {
|
|
5587
|
+
stderr.write(`${JSON.stringify({ schema: 'lattice.todo_command_retired.v1', command: 'todo wait',
|
|
5588
|
+
still_works_until: 'the next minor version',
|
|
5589
|
+
use: `lattice todo connect priority --plan ${flags.plan} --task ${flags.task}${flags.cancel === true ? ' --cancel' : ''}` })}\n`);
|
|
5590
|
+
}
|
|
5591
|
+
return result;
|
|
5592
|
+
};
|
|
5382
5593
|
}
|
|
5383
5594
|
} else if (argv[0] === 'note' && argv[1] === 'list' && readFlags(argv, ['note', 'list']) !== null) {
|
|
5384
5595
|
const flags = readFlags(argv, ['note', 'list']);
|
|
@@ -5394,20 +5605,34 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5394
5605
|
repoRoot, env, planKey: flags.plan, mode: flags.set, reason: flags.reason,
|
|
5395
5606
|
});
|
|
5396
5607
|
}
|
|
5608
|
+
} else if (argv[0] === 'predecessor' && ['add', 'remove'].includes(argv[1])
|
|
5609
|
+
&& matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC) !== null
|
|
5610
|
+
&& parsePredecessorTarget(matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC).after, '') !== null
|
|
5611
|
+
&& ['plan', 'task'].every((name) => isTodoIdentifier(matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC)[name]))) {
|
|
5612
|
+
const flags = matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC);
|
|
5613
|
+
action = (repoRoot) => predecessorChange({ repoRoot, env, operation: argv[1], planKey: flags.plan, taskId: flags.task,
|
|
5614
|
+
after: flags.after, reason: flags.reason });
|
|
5615
|
+
} else if (argv[0] === 'connect' && argv[1] === 'condition' && ['add', 'remove', 'resolve'].includes(argv[2])
|
|
5616
|
+
&& parseConditionTarget(matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')])?.to, '') !== null
|
|
5617
|
+
&& matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')]) !== null
|
|
5618
|
+
&& ['plan', 'task'].every((name) => isTodoIdentifier(matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')])[name]))) {
|
|
5619
|
+
const flags = matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')]);
|
|
5620
|
+
action = (repoRoot) => connectCondition({ repoRoot, env, operation: argv[2], planKey: flags.plan, taskId: flags.task,
|
|
5621
|
+
to: flags.to, reason: flags.reason ?? null, message: flags.message ?? null });
|
|
5397
5622
|
} else if (argv[0] === 'dependency' && argv[1] === 'connect'
|
|
5398
5623
|
&& dependencyFlags(argv) !== null) {
|
|
5399
5624
|
const flags = dependencyFlags(argv);
|
|
5400
|
-
action = (repoRoot) => dependencyConnect({
|
|
5625
|
+
action = async (repoRoot) => retiredDependencyCommand(stderr, 'add', flags, await dependencyConnect({
|
|
5401
5626
|
repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
|
|
5402
5627
|
toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
|
|
5403
|
-
});
|
|
5628
|
+
}));
|
|
5404
5629
|
} else if (argv[0] === 'dependency' && argv[1] === 'disconnect'
|
|
5405
5630
|
&& dependencyFlags(argv) !== null) {
|
|
5406
5631
|
const flags = dependencyFlags(argv);
|
|
5407
|
-
action = (repoRoot) => dependencyDisconnect({
|
|
5632
|
+
action = async (repoRoot) => retiredDependencyCommand(stderr, 'remove', flags, await dependencyDisconnect({
|
|
5408
5633
|
repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
|
|
5409
5634
|
toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
|
|
5410
|
-
});
|
|
5635
|
+
}));
|
|
5411
5636
|
} else if (argv[0] === 'independence' && argv[1] === 'compile') {
|
|
5412
5637
|
const flags = matchFlagCommand(argv, ['independence', 'compile'], TODO_FLAG_SPECS['independence compile']);
|
|
5413
5638
|
if (flags !== null && isTodoIdentifier(flags.plan) && isAuthoringPathToken(flags.input)) {
|
|
@@ -5671,10 +5896,10 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5671
5896
|
const flags = matchFlagCommand(argv, ['block'], TODO_FLAG_SPECS.block);
|
|
5672
5897
|
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
|
|
5673
5898
|
action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5674
|
-
kind: 'block', dropped: reasonDropped(flags.reason), action: () => mutate({
|
|
5899
|
+
kind: 'block', dropped: reasonDropped(flags.reason), action: async () => withBlockGuidance(await mutate({
|
|
5675
5900
|
repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5676
5901
|
kind: 'block', payload: { reason: flags.reason }, evidenceRef: null,
|
|
5677
|
-
}) });
|
|
5902
|
+
})) });
|
|
5678
5903
|
}
|
|
5679
5904
|
} else if (argv[0] === 'add') {
|
|
5680
5905
|
const flags = matchFlagCommand(argv, ['add'], TODO_FLAG_SPECS.add);
|
package/src/todo-contracts.mjs
CHANGED
|
@@ -19,13 +19,20 @@ export const TODO_EVENT_KINDS = Object.freeze([
|
|
|
19
19
|
// 誤って張った接続の除去(connectの対・2026-08-29オーナー裁定系)。対象eventのdigestを指す
|
|
20
20
|
// tombstoneとして積み、projectionが両方を読んで線を消す。歴史は書き換えない。
|
|
21
21
|
'cross_plan_dependency_removed',
|
|
22
|
+
// 接続(他条件に接続): a task waits on a BellTeam schedule outside its own chart. Plan-scoped like the
|
|
23
|
+
// dependency ledger; removed/resolved point at the connection_added digest and each add has at most one end.
|
|
24
|
+
'connection_added', 'connection_removed', 'connection_resolved',
|
|
22
25
|
]);
|
|
23
26
|
|
|
24
27
|
/** planへ帰属し、taskにもPhaseにも属さないevent kind。 */
|
|
25
28
|
export const TODO_PLAN_SCOPED_EVENT_KINDS = Object.freeze([
|
|
26
29
|
'coordination_mode', 'cross_plan_dependency', 'cross_plan_dependency_removed',
|
|
30
|
+
'connection_added', 'connection_removed', 'connection_resolved',
|
|
27
31
|
]);
|
|
28
32
|
|
|
33
|
+
/** The schedule id is opaque to Lattice: printable ASCII without spaces. */
|
|
34
|
+
export const TODO_CONNECTION_SCHEDULE_ID = /^[!-~]{1,128}$/u;
|
|
35
|
+
|
|
29
36
|
/** 調整方式。witness=独立性を宣言し検証して並列する/conversation=会話で調整する。 */
|
|
30
37
|
// ADR 0200: `enforced` is witness coordination plus the gates that stop skipped steps.
|
|
31
38
|
export const TODO_COORDINATION_MODES = Object.freeze(['witness', 'conversation', 'enforced']);
|
|
@@ -52,9 +59,9 @@ export const TODO_CHART_META_SCHEMA = 'lattice.chart_meta.v1';
|
|
|
52
59
|
*/
|
|
53
60
|
export const TODO_NOTE_CONTEXT_SCHEMA = 'lattice.todo_note_context.v2';
|
|
54
61
|
export const TODO_LIMITS = Object.freeze({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
// ADR 0201: no count caps on a plan's tasks, edges, joins or phases; its size is bounded by bytes (snapshotBytes).
|
|
63
|
+
// The note context keeps its own entry count next to noteContextBytes.
|
|
64
|
+
noteContextEntries: 512,
|
|
58
65
|
journalSegmentBytes: 1_048_576,
|
|
59
66
|
snapshotBytes: 8_388_608,
|
|
60
67
|
narrativeSectionBytes: 262_144,
|
|
@@ -210,7 +217,7 @@ export function validateTodoNoteContext(value) {
|
|
|
210
217
|
]) || value.schema !== TODO_NOTE_CONTEXT_SCHEMA
|
|
211
218
|
|| !isTodoIdentifier(value.project_id) || !isTodoIdentifier(value.plan_key)
|
|
212
219
|
|| !isTodoIdentifier(value.task_id) || !Array.isArray(value.notes)
|
|
213
|
-
|| value.notes.length > TODO_LIMITS.
|
|
220
|
+
|| value.notes.length > TODO_LIMITS.noteContextEntries || !value.notes.every(noteContextEntry)
|
|
214
221
|
|| !(value.note_head_digest === null || isTodoDigest(value.note_head_digest))
|
|
215
222
|
|| !(value.plan_note_head_digest === null || isTodoDigest(value.plan_note_head_digest))
|
|
216
223
|
|| !isNonNegativeSafeInteger(value.overflow_count)
|
|
@@ -479,25 +486,24 @@ export function explainTodoPlan(value) {
|
|
|
479
486
|
if (!isTodoIdentifier(value[field])) return reject('identifier_invalid', `/${field}`);
|
|
480
487
|
}
|
|
481
488
|
if (!nullableDigest(value.predecessor_plan_digest)) return reject('digest_invalid', '/predecessor_plan_digest');
|
|
482
|
-
if (!Array.isArray(value.tasks) || value.tasks.length === 0
|
|
483
|
-
|| value.tasks.length > TODO_LIMITS.tasksPerPlan) return reject('bounded_collection_violation', '/tasks');
|
|
489
|
+
if (!Array.isArray(value.tasks) || value.tasks.length === 0) return reject('bounded_collection_violation', '/tasks');
|
|
484
490
|
const invalidTask = value.tasks.findIndex((task) => !taskValidator(task));
|
|
485
491
|
if (invalidTask >= 0) return reject('task_shape_invalid', `/tasks/${invalidTask}`);
|
|
486
492
|
if (new Set(value.tasks.map(({ task_id }) => task_id)).size !== value.tasks.length) {
|
|
487
493
|
return reject('duplicate_task_id', '/tasks');
|
|
488
494
|
}
|
|
489
|
-
if (!Array.isArray(value.hard_dependencies)
|
|
495
|
+
if (!Array.isArray(value.hard_dependencies)) {
|
|
490
496
|
return reject('bounded_collection_violation', '/hard_dependencies');
|
|
491
497
|
}
|
|
492
498
|
const invalidEdge = value.hard_dependencies.findIndex((edge) => !exactRecord(edge, ['from', 'to'])
|
|
493
499
|
|| !nodeRef(edge.from) || !nodeRef(edge.to));
|
|
494
500
|
if (invalidEdge >= 0) return reject('edge_shape_invalid', `/hard_dependencies/${invalidEdge}`);
|
|
495
|
-
if (!Array.isArray(value.joins)
|
|
501
|
+
if (!Array.isArray(value.joins)) {
|
|
496
502
|
return reject('bounded_collection_violation', '/joins');
|
|
497
503
|
}
|
|
498
504
|
const invalidJoin = value.joins.findIndex((join) => !exactRecord(join, ['id', 'after', 'before'])
|
|
499
505
|
|| !isTodoIdentifier(join.id) || !Array.isArray(join.after) || join.after.length === 0
|
|
500
|
-
||
|
|
506
|
+
|| !join.after.every(nodeRef) || !nodeRef(join.before));
|
|
501
507
|
if (invalidJoin >= 0) return reject('join_shape_invalid', `/joins/${invalidJoin}`);
|
|
502
508
|
for (const field of ['topology_digest', 'plan_digest']) {
|
|
503
509
|
if (!isTodoDigest(value[field])) return reject('digest_invalid', `/${field}`);
|
|
@@ -506,8 +512,7 @@ export function explainTodoPlan(value) {
|
|
|
506
512
|
'lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(value.schema)
|
|
507
513
|
&& !validParentGraph(value.tasks)) return reject('parent_graph_invalid', '/tasks');
|
|
508
514
|
if (phased) {
|
|
509
|
-
if (!Array.isArray(value.phases) || value.phases.length === 0
|
|
510
|
-
|| value.phases.length > TODO_LIMITS.tasksPerPlan) return reject('bounded_collection_violation', '/phases');
|
|
515
|
+
if (!Array.isArray(value.phases) || value.phases.length === 0) return reject('bounded_collection_violation', '/phases');
|
|
511
516
|
const invalidPhase = value.phases.findIndex((phase) => !phaseV1(phase));
|
|
512
517
|
if (invalidPhase >= 0) return reject('phase_shape_invalid', `/phases/${invalidPhase}`);
|
|
513
518
|
const order = explainTodoOrder(value.phases, (phase) => phase.phase_id, '/phases');
|
|
@@ -517,8 +522,7 @@ export function explainTodoPlan(value) {
|
|
|
517
522
|
if (!validPhaseGraph(value.phases)) return reject('phase_graph_invalid', '/phases');
|
|
518
523
|
}
|
|
519
524
|
if (decoupled) {
|
|
520
|
-
if (!Array.isArray(value.phase_accept_dependencies)
|
|
521
|
-
|| value.phase_accept_dependencies.length > TODO_LIMITS.edgesPerPlan) {
|
|
525
|
+
if (!Array.isArray(value.phase_accept_dependencies)) {
|
|
522
526
|
return reject('bounded_collection_violation', '/phase_accept_dependencies');
|
|
523
527
|
}
|
|
524
528
|
const invalid = value.phase_accept_dependencies.findIndex((edge) => !exactRecord(edge, ['from', 'to'])
|
|
@@ -567,7 +571,6 @@ function validPayload(event) {
|
|
|
567
571
|
])) && (payload.historical_import === undefined || payload.historical_import === true)
|
|
568
572
|
&& isTodoDigest(payload.plan_digest) && isTodoDigest(payload.topology_digest)
|
|
569
573
|
&& nullableDigest(payload.predecessor_plan_digest) && Array.isArray(payload.task_migration)
|
|
570
|
-
&& payload.task_migration.length <= TODO_LIMITS.tasksPerPlan
|
|
571
574
|
&& payload.task_migration.every((entry) => exactRecord(entry, ['from_task_id', 'to_task_id'])
|
|
572
575
|
&& isTodoIdentifier(entry.from_task_id) && (entry.to_task_id === 'removed' || isTodoIdentifier(entry.to_task_id)));
|
|
573
576
|
if (event.kind === 'start' && payload?.start_mode === 'historical_import') {
|
|
@@ -595,6 +598,20 @@ function validPayload(event) {
|
|
|
595
598
|
&& isTodoDigest(payload.target_event_digest)
|
|
596
599
|
&& nullableText(payload.reason) && payload.reason !== null;
|
|
597
600
|
}
|
|
601
|
+
if (event.kind === 'connection_added') {
|
|
602
|
+
return exactRecord(payload, ['task_id', 'to', 'reason']) && isTodoIdentifier(payload.task_id)
|
|
603
|
+
&& exactRecord(payload.to, ['kind', 'id']) && payload.to.kind === 'schedule'
|
|
604
|
+
&& typeof payload.to.id === 'string' && TODO_CONNECTION_SCHEDULE_ID.test(payload.to.id)
|
|
605
|
+
&& nullableText(payload.reason) && payload.reason !== null;
|
|
606
|
+
}
|
|
607
|
+
if (event.kind === 'connection_removed') {
|
|
608
|
+
return exactRecord(payload, ['target_event_digest', 'reason']) && isTodoDigest(payload.target_event_digest)
|
|
609
|
+
&& nullableText(payload.reason) && payload.reason !== null;
|
|
610
|
+
}
|
|
611
|
+
if (event.kind === 'connection_resolved') {
|
|
612
|
+
return exactRecord(payload, ['target_event_digest', 'evidence']) && isTodoDigest(payload.target_event_digest)
|
|
613
|
+
&& nullableText(payload.evidence) && payload.evidence !== null;
|
|
614
|
+
}
|
|
598
615
|
// rebind: plan改訂でcarryされたin-progress ToDoへ、現plan_versionの明示的start束縛を積み直す
|
|
599
616
|
// (runtime intakeはliteral startだけを束縛に使い、carryを推定しない。ADR 0191)
|
|
600
617
|
if (event.kind === 'start' && payload?.start_mode === 'rebind') {
|
|
@@ -699,7 +716,7 @@ function validCarriedState(value) {
|
|
|
699
716
|
}
|
|
700
717
|
|
|
701
718
|
function validStateMigration(value) {
|
|
702
|
-
return Array.isArray(value)
|
|
719
|
+
return Array.isArray(value)
|
|
703
720
|
&& value.every((entry) => exactRecord(entry, [
|
|
704
721
|
'from_task_id', 'to_task_id', 'state_policy', 'state',
|
|
705
722
|
]) && isTodoIdentifier(entry.from_task_id)
|
|
@@ -715,7 +732,7 @@ function validStateMigration(value) {
|
|
|
715
732
|
}
|
|
716
733
|
|
|
717
734
|
function validPhaseStateMigration(value) {
|
|
718
|
-
return Array.isArray(value)
|
|
735
|
+
return Array.isArray(value)
|
|
719
736
|
&& value.every((entry) => exactRecord(entry, ['phase_id', 'state_policy', 'state'])
|
|
720
737
|
&& isTodoIdentifier(entry.phase_id) && ['carry', 'reset'].includes(entry.state_policy)
|
|
721
738
|
&& (entry.state_policy === 'reset' ? entry.state === null
|
|
@@ -824,7 +841,7 @@ export function validateTodoSnapshot(value) {
|
|
|
824
841
|
&& value.projection_version === (v1 ? 1 : v2 ? 2 : v3 ? 3 : 4)
|
|
825
842
|
&& isNonNegativeSafeInteger(value.through_sequence)
|
|
826
843
|
&& isTodoDigest(value.journal_head_digest) && Array.isArray(value.tasks)
|
|
827
|
-
&& value.tasks.length > 0
|
|
844
|
+
&& value.tasks.length > 0
|
|
828
845
|
&& value.tasks.every((entry) => exactRecord(entry, [
|
|
829
846
|
'task_id', 'status', 'started_at', 'done_at', 'blocked_reason', 'evidence', 'evidence_unverified', 'imported',
|
|
830
847
|
...(resultAware ? ['test_result'] : []),
|