@quolu/lattice 0.103.0 → 0.105.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/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';
@@ -65,6 +65,7 @@ import {
65
65
  appendTodoStructureRealization,
66
66
  applyPhaseTodoRevision,
67
67
  applyTodoRevision,
68
+ compactTodoVersions,
68
69
  applyTodoRevisionSet,
69
70
  buildTodoPlan,
70
71
  createTodoStoreWriter,
@@ -170,7 +171,7 @@ import {
170
171
  } from './seam-proposal-contracts.mjs';
171
172
  import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
172
173
  import { collectSensorEvidence } from './sensor-adapter.mjs';
173
- import { newTodoNotices, projectTodoNotices, waitInEffect } from './todo-notices.mjs';
174
+ import { newTodoNotices, projectTodoNotices, waitInEffect, withTodoPriorityWaits } from './todo-notices.mjs';
174
175
  import {
175
176
  externalCycle, readTodoExternalChart, readTodoExternalTasks, withTodoExternalTasks,
176
177
  } from './todo-external.mjs';
@@ -314,7 +315,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
314
315
  'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
315
316
  'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
316
317
  'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
317
- 'retract', 'dependency', 'add', 'notice', 'wait', 'blockers',
318
+ 'retract', 'dependency', 'predecessor', 'connect', 'add', 'notice', 'wait', 'blockers', 'compact',
318
319
  ]);
319
320
 
320
321
  function typedArgumentFailure(stderr, code, message, detail, context = {}) {
@@ -338,6 +339,8 @@ const DEPENDENCY_FLAG_SPEC = Object.freeze({
338
339
  known: ['from-project', 'from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
339
340
  required: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
340
341
  });
342
+ const PREDECESSOR_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'after', 'reason'], required: ['plan', 'task', 'after', 'reason'] });
343
+ const CONNECT_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'to', 'reason'], required: ['plan', 'task', 'to', 'reason'] });
341
344
  // a18: one spec per write command is both its parser and the explanation of its refusal.
342
345
  const TODO_FLAG_SPECS = Object.freeze({
343
346
  start: Object.freeze({
@@ -357,6 +360,11 @@ const TODO_FLAG_SPECS = Object.freeze({
357
360
  required: ['plan', 'task', 'title'],
358
361
  }),
359
362
  'dependency disconnect': DEPENDENCY_FLAG_SPEC,
363
+ 'predecessor add': PREDECESSOR_FLAG_SPEC,
364
+ 'predecessor remove': PREDECESSOR_FLAG_SPEC,
365
+ 'connect condition add': CONNECT_FLAG_SPEC,
366
+ 'connect condition remove': CONNECT_FLAG_SPEC,
367
+ 'connect condition resolve': Object.freeze({ known: ['plan', 'task', 'to', 'message'], required: ['plan', 'task', 'to', 'message'] }),
360
368
  // a23: the remaining writes whose refusal pointed only at --help.
361
369
  'phase review': PHASE_REASON_FLAG_SPEC,
362
370
  'phase close-unaudited': PHASE_REASON_FLAG_SPEC,
@@ -377,6 +385,8 @@ const TODO_FLAG_SPECS = Object.freeze({
377
385
  'notice list': Object.freeze({ known: ['lane', 'include-acked', 'json'], required: [], booleans: ['include-acked', 'json'] }),
378
386
  'notice ack': Object.freeze({ known: ['lane', 'notice', 'json'], required: ['lane', 'notice'], booleans: ['json'] }),
379
387
  blockers: Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
388
+ compact: Object.freeze({ known: ['plan', 'limit', 'json'], required: [], booleans: ['json'] }),
389
+ 'connect priority': Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
380
390
  wait: Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
381
391
  'note list': Object.freeze({ known: ['plan', 'task', 'json'], required: ['plan'], booleans: ['json'] }),
382
392
  'phase status': Object.freeze({ known: ['plan', 'json'], required: ['plan'], booleans: ['json'] }),
@@ -388,10 +398,12 @@ const WITNESS_TEMPLATE_FLAG_SPEC = Object.freeze({
388
398
  // a28: command groups, their subcommands and the one a refusal shows as the example.
389
399
  const TODO_SUBCOMMANDS = Object.freeze({
390
400
  dependency: { names: ['connect', 'disconnect'], example: 'connect' },
401
+ predecessor: { names: ['add', 'remove'], example: 'add' },
402
+ connect: { names: ['condition', 'priority'], example: 'priority' },
391
403
  phase: { names: ['status', 'review', 'accept', 'reject', 'reopen', 'close-unaudited', 'baseline'], example: 'review' },
392
404
  evidence: { names: ['promote'], example: 'promote' },
393
405
  });
394
- const GROUP_COMMANDS = ['dependency', 'phase', 'evidence', 'independence', 'note', 'structure'];
406
+ const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', 'evidence', 'independence', 'note', 'structure'];
395
407
  const IDENTIFIER_FLAGS = ['plan', 'task', 'phase', 'from-plan', 'from-task', 'to-plan', 'to-task'];
396
408
  // The shared table is FLAG_PLACEHOLDER (cli-refusal-guidance, a27).
397
409
  const placeholder = (name) => FLAG_PLACEHOLDER[name] ?? `<${name}>`;
@@ -444,6 +456,13 @@ function explainMissingSubcommand(argv) {
444
456
  + ' (every command: `lattice todo --help`).' };
445
457
  }
446
458
  const group = TODO_SUBCOMMANDS[argv[0]];
459
+ if (argv[0] === 'connect' && argv[1] === 'condition' && !['add', 'remove', 'resolve'].includes(argv[2])) {
460
+ const missing = typeof argv[2] !== 'string' || argv[2].startsWith('--');
461
+ return { pointer: missing ? '<subcommand>' : argv[2], rule: missing ? 'subcommand_missing' : 'subcommand_unknown',
462
+ available_subcommands: ['add', 'remove', 'resolve'],
463
+ next_action: 'Name one of add, remove, resolve after `lattice todo connect condition`, e.g.'
464
+ + ' `lattice todo connect condition add --plan <plan> --task <id> --to task:<project>/<plan>/<task> --reason <text>`.' };
465
+ }
447
466
  if (group === undefined || group.names.includes(argv[1])) return null;
448
467
  const missing = typeof argv[1] !== 'string' || argv[1].startsWith('--');
449
468
  const head = [argv[0], group.example];
@@ -459,6 +478,7 @@ function explainArgumentRefusal(argv) {
459
478
  const missingSubcommand = explainMissingSubcommand(argv);
460
479
  if (missingSubcommand !== null) return missingSubcommand;
461
480
  const head = argv[0] === 'independence' && argv[1] === 'witness' ? argv.slice(0, 3)
481
+ : argv[0] === 'connect' && argv[1] === 'condition' ? argv.slice(0, 3)
462
482
  : GROUP_COMMANDS.includes(argv[0]) && typeof argv[1] === 'string' && !argv[1].startsWith('--')
463
483
  ? argv.slice(0, 2) : argv.slice(0, 1);
464
484
  // a32: `scaffold --template` is a read with its own flags.
@@ -532,6 +552,14 @@ function explainArgumentRefusal(argv) {
532
552
  return { pointer: `--${name}`, rule: 'flag_missing', next_action: `Give --${name} a non-empty <text>: \`${repairedCommand(head, spec, flags)}\`.` };
533
553
  }
534
554
  }
555
+ if (argv[0] === 'connect' && argv[1] === 'condition' && parseConditionTarget(flags.to, '') === null) {
556
+ return { pointer: '--to', rule: 'target_invalid', actual: flags.to,
557
+ next_action: 'Name the 接続先 as `task:<project>/<plan>/<task>` (a task on another chart) or `schedule:<id>` (a BellTeam schedule).' };
558
+ }
559
+ if (argv[0] === 'predecessor' && typeof flags.after === 'string' && parsePredecessorTarget(flags.after, '') === null) {
560
+ return { pointer: '--after', rule: 'target_invalid', actual: flags.after,
561
+ next_action: 'Name the 前工程 as `<plan>/<task>`, a task on this chart (task ids: `lattice plan show <plan> --json`).' };
562
+ }
535
563
  if (argv[0] === 'start' && flags.rebind === true && !(typeof flags.reason === 'string' && flags.reason.length > 0)) {
536
564
  return { pointer: '--reason', rule: 'flag_missing',
537
565
  next_action: `--rebind needs --reason <text>: \`${repairedCommand(head, { ...spec, required: [...spec.required, 'reason'] }, flags)}\`.` };
@@ -1069,6 +1097,15 @@ async function mutate({
1069
1097
  return result;
1070
1098
  }
1071
1099
 
1100
+ /** ブロック is the last resort; its result says what to use first (前工程: predecessor, 接続: connect condition). */
1101
+ const BLOCK_GUIDANCE = '待っているものが自分の工程表の工程なら todo predecessor add(前工程)、それ以外で名指しや確認ができるもの(別の工程表の工程、予定表の確認)は'
1102
+ + ' todo connect condition add(他条件に接続)を使う。ブロックは最後の手段(`lattice todo unblock`で外す)。';
1103
+ function withBlockGuidance(result) {
1104
+ const guided = { ...result, next_action: BLOCK_GUIDANCE, result_digest: '' };
1105
+ guided.result_digest = todoSelfDigest(guided, 'result_digest');
1106
+ return guided;
1107
+ }
1108
+
1072
1109
  /** retract-anyone: a reopened task is unstarted again; the redo records a start (from any seat). */
1073
1110
  async function reopenTask({ repoRoot, env, planKey, taskId, payload }) {
1074
1111
  const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload, evidenceRef: null });
@@ -1131,7 +1168,7 @@ async function unchangedTransition(store, { env, planKey, taskId, kind, dropped
1131
1168
  journal_head_digest: events.at(-1).event_digest, snapshot_digest: member.snapshot.snapshot_digest,
1132
1169
  status: state.status, advisory: null, unchanged: true,
1133
1170
  // a18: a repeated transition appends nothing, so say which given content was not recorded.
1134
- ...(notRecorded.length === 0 ? {} : {
1171
+ ...(notRecorded.length === 0 ? (kind === 'block' ? { next_action: BLOCK_GUIDANCE } : {}) : {
1135
1172
  not_recorded: notRecorded,
1136
1173
  next_action: `${planKey}/${state.task_id} ${NOT_RECORDED_NEXT[kind](`--plan ${planKey} --task ${state.task_id}`, notRecorded.join(', '))}`,
1137
1174
  }),
@@ -1413,12 +1450,25 @@ async function displayRead(repoRoot, env) {
1413
1450
  const display = await readTodoStoreForDisplay({ repoRoot });
1414
1451
  const externalTasks = display.store ? (await readTodoExternalTasks(display.store, env)).external_tasks : [];
1415
1452
  return { schema: 'lattice.todo_display_read_result.v1', ...display, external_tasks: externalTasks,
1416
- trees: display.store ? projectTodoTrees(display.store) : [] };
1453
+ trees: display.store ? projectTodoTrees(display.store) : [],
1454
+ connections: display.store ? await displayConnections(repoRoot, { ...display.store, external_tasks: externalTasks }) : [] };
1455
+ }
1456
+
1457
+ /** 接続: `[{plan_key, task_id, connections}]` for every task that has any (the one list: 他条件に接続 and 優先接続). */
1458
+ async function displayConnections(repoRoot, store) {
1459
+ // The display reads unverified members too and must not stop: an unreadable store shows no 接続.
1460
+ try {
1461
+ const full = await withTodoPriorityWaits(store, { repoRoot });
1462
+ const readiness = createTodoReadiness(full);
1463
+ return full.members.flatMap(({ plan }) => (plan.tasks ?? []).map((task) => ({ plan_key: plan.plan_key, task_id: task.task_id,
1464
+ connections: readiness.allConnections(readiness.key({ ...plan, task_id: task.task_id })) })))
1465
+ .filter(({ connections }) => connections.length > 0);
1466
+ } catch { return []; }
1417
1467
  }
1418
1468
 
1419
1469
  /** xchart: the Store plus its external predecessors' states; every readiness reader reads through this. */
1420
1470
  async function readTodoStoreForReadiness({ repoRoot, env = process.env }) {
1421
- return withTodoExternalTasks(await readTodoStore({ repoRoot }), env);
1471
+ return withTodoPriorityWaits(await withTodoExternalTasks(await readTodoStore({ repoRoot }), env), { repoRoot });
1422
1472
  }
1423
1473
 
1424
1474
  async function startTask({
@@ -1531,7 +1581,7 @@ function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
1531
1581
  if (advisory.conflicts_with_active.length > 0 && overrideReason === null) {
1532
1582
  const active = advisory.conflicts_with_active.map(({ active_task_id: id }) => id);
1533
1583
  refuse('enforced_conflict_with_active', { conflicts_with_active: advisory.conflicts_with_active,
1534
- next_action: `${taskId} overlaps in-progress ${active.join(', ')}: wait for it with \`lattice todo dependency connect --from-plan ${planKey} --from-task ${active[0]} --to-plan ${planKey} --to-task ${taskId} --reason <text>\`,`
1584
+ 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
1585
  + ` or start anyway with \`lattice todo start --plan ${planKey} --task ${taskId} --override-reason <text>\` (the reason is recorded).` });
1536
1586
  }
1537
1587
  }
@@ -2139,6 +2189,148 @@ async function dependencyDisconnectLedger({
2139
2189
  return result;
2140
2190
  }
2141
2191
 
2192
+ /** `dependency connect|disconnect` is an alias for one minor version: each run says which of the two commands replaces it. */
2193
+ function retiredDependencyCommand(stderr, operation, flags, result) {
2194
+ const edge = `--plan ${flags['to-plan']} --task ${flags['to-task']}`;
2195
+ const use = flags['from-project'] === undefined
2196
+ ? `lattice todo predecessor ${operation} ${edge} --after ${flags['from-plan']}/${flags['from-task']} --reason <text>`
2197
+ : `lattice todo connect condition ${operation} ${edge} --to task:${flags['from-project']}/${flags['from-plan']}/${flags['from-task']} --reason <text>`;
2198
+ stderr.write(`${JSON.stringify({ schema: 'lattice.todo_command_retired.v1', command: `todo dependency ${operation === 'add' ? 'connect' : 'disconnect'}`,
2199
+ still_works_until: 'the next minor version', use })}\n`);
2200
+ return result;
2201
+ }
2202
+
2203
+ // 前工程 (`todo predecessor`) and 他条件に接続 (`todo connect condition`) are two commands with disjoint targets
2204
+ // ([connect flow](../docs/architecture/dfd-connect.md)): each refuses the other's target and names the right command.
2205
+
2206
+ /** `<plan>/<task>` (this chart); `<project>/<plan>/<task>` or a `task:`/`schedule:` target are another chart or a schedule. */
2207
+ function parsePredecessorTarget(text, projectId) {
2208
+ if (typeof text !== 'string') return null;
2209
+ if (/^schedule:/u.test(text)) return { sameChart: false };
2210
+ const parts = text.replace(/^task:/u, '').split('/');
2211
+ if (parts.length < 2 || parts.length > 3 || !parts.every(isTodoIdentifier)) return null;
2212
+ const [owner, planKey, taskId] = parts.length === 3 ? parts : [projectId, ...parts];
2213
+ return { sameChart: owner === projectId, projectId: owner, planKey, taskId };
2214
+ }
2215
+
2216
+ /** `task:<project>/<plan>/<task>` or `schedule:<id>` (id: printable ASCII, no spaces, <= 128). null when malformed (exit 2, pointer --to). */
2217
+ function parseConditionTarget(text, projectId) {
2218
+ if (typeof text !== 'string') return null;
2219
+ if (text.startsWith('schedule:')) {
2220
+ const id = text.slice('schedule:'.length);
2221
+ return /^[!-~]{1,128}$/u.test(id) ? { kind: 'schedule', id, ref: id } : null;
2222
+ }
2223
+ const parts = text.startsWith('task:') ? text.slice('task:'.length).split('/') : [];
2224
+ if (parts.length !== 3 || !parts.every(isTodoIdentifier)) return null;
2225
+ const [owner, planKey, taskId] = parts;
2226
+ return { kind: 'task', projectId: owner, planKey, taskId, ref: `${owner}/${planKey}/${taskId}`, sameChart: owner === projectId };
2227
+ }
2228
+
2229
+ async function predecessorChange({ repoRoot, env, operation, planKey, taskId, after, reason }) {
2230
+ const store = await readTodoStore({ repoRoot });
2231
+ const target = parsePredecessorTarget(after, store.project_id);
2232
+ if (target === null) {
2233
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'predecessor_target_invalid', undefined, {
2234
+ after, next_action: 'Name the 前工程 as `<plan>/<task>`, a task on this chart (task ids: `lattice plan show <plan> --json`).' });
2235
+ }
2236
+ if (!target.sameChart) {
2237
+ throw new TodoStoreError('CONNECTION_INVALID', 'predecessor_target_not_same_chart', undefined, {
2238
+ after,
2239
+ next_action: `${after} is not a task on this chart, so it is a 接続, not a 前工程: \`lattice todo connect condition ${operation}`
2240
+ + ` --plan ${planKey} --task ${taskId} --to ${/^(task|schedule):/u.test(after) ? after : `task:${after}`} --reason <text>\`.`,
2241
+ });
2242
+ }
2243
+ const options = {
2244
+ repoRoot, env, fromProjectId: null, fromPlanKey: target.planKey, fromTaskId: target.taskId,
2245
+ toPlanKey: planKey, toTaskId: taskId, reason,
2246
+ };
2247
+ return operation === 'add' ? dependencyConnect(options) : dependencyDisconnect(options);
2248
+ }
2249
+
2250
+ function connectionResult(store, { operation, planKey, taskId, target, event = null, unchanged = false, reason = null, evidence = null, next_action = null }) {
2251
+ const result = {
2252
+ schema: unchanged ? 'lattice.todo_connection_unchanged_result.v1' : 'lattice.todo_connection_result.v1',
2253
+ project_id: store.project_id, operation, plan_key: planKey, task_id: taskId,
2254
+ to: { kind: target.kind, ref: target.ref },
2255
+ ...(reason === null ? {} : { reason }), ...(evidence === null ? {} : { evidence }),
2256
+ ...(event === null ? { unchanged: true } : {
2257
+ event_digest: event.event_digest, recorded_at: event.recorded_at, actor: event.actor }),
2258
+ next_action,
2259
+ result_digest: '',
2260
+ };
2261
+ result.result_digest = todoSelfDigest(result, 'result_digest');
2262
+ return result;
2263
+ }
2264
+
2265
+ /** 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). */
2266
+ function everConnected(member, taskId, target) {
2267
+ return (member.plan_scoped?.events ?? []).some((event) => event.kind === 'cross_plan_dependency'
2268
+ && event.payload?.to?.task_id === taskId && event.payload?.from?.project_id === target.projectId
2269
+ && event.payload?.from?.plan_key === target.planKey && event.payload?.from?.task_id === target.taskId);
2270
+ }
2271
+
2272
+ /**
2273
+ * `todo connect condition add|remove|resolve`: a task on another chart, or a BellTeam schedule, as a 接続.
2274
+ * Every write is idempotent (a retry after an unknown outcome is safe): add of an open identical 接続, resolve of a
2275
+ * settled one and remove with nothing open answer `unchanged: true`; only a target never added is refused.
2276
+ */
2277
+ async function connectCondition({ repoRoot, env, operation, planKey, taskId, to, reason = null, message = null }) {
2278
+ const store = await readTodoStoreForReadiness({ repoRoot, env });
2279
+ const target = parseConditionTarget(to, store.project_id);
2280
+ const refuse = (code, why, detail) => new TodoStoreError(code, why, undefined, { to, ...detail });
2281
+ if (target.kind === 'task' && target.sameChart) {
2282
+ throw refuse('CONNECTION_INVALID', 'condition_target_same_chart', {
2283
+ next_action: `${target.planKey}/${target.taskId} is on this chart, so it is a 前工程, not a 接続: \`lattice todo predecessor ${operation === 'remove' ? 'remove' : 'add'}`
2284
+ + ` --plan ${planKey} --task ${taskId} --after ${target.planKey}/${target.taskId} --reason <text>\`.` });
2285
+ }
2286
+ const member = store.members.find(({ plan }) => plan.plan_key === planKey);
2287
+ if (member === undefined) throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
2288
+ if (!member.plan.tasks.some(({ task_id: id }) => id === taskId)) {
2289
+ throw new TodoStoreError('TASK_NOT_FOUND', 'task_not_found', undefined, { requested_task_id: taskId });
2290
+ }
2291
+ const base = { operation, planKey, taskId, target };
2292
+ const addAgain = `lattice todo connect condition add --plan ${planKey} --task ${taskId} --to ${to} --reason <text>`;
2293
+ const notFound = () => refuse('CONNECTION_INVALID', 'connection_not_found', {
2294
+ 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).` });
2295
+ if (target.kind === 'task') {
2296
+ if (operation === 'resolve') {
2297
+ throw refuse('CONNECTION_INVALID', 'condition_task_target_settles_itself', {
2298
+ next_action: `A 接続 to a task settles when ${target.ref} is done or retired; only \`schedule:<id>\` is resolved by hand.` });
2299
+ }
2300
+ const edge = { repoRoot, env, fromProjectId: target.projectId, fromPlanKey: target.planKey, fromTaskId: target.taskId,
2301
+ toPlanKey: planKey, toTaskId: taskId, reason };
2302
+ if (operation === 'add') return dependencyConnect(edge);
2303
+ try {
2304
+ return await dependencyDisconnect(edge);
2305
+ } catch (error) {
2306
+ if (error?.code !== 'DEPENDENCY_NOT_FOUND') throw error;
2307
+ if (!everConnected(member, taskId, target)) throw notFound();
2308
+ return connectionResult(store, { ...base, unchanged: true, next_action: `${to} is already removed; nothing was recorded.` });
2309
+ }
2310
+ }
2311
+ // Store is idempotent (appendTodoEvent answers `unchanged`), so no pre-check; the newest entry for this ref names the target.
2312
+ const shown = listTodoConnections(store, planKey, taskId, { includeRemoved: true })
2313
+ .filter((entry) => entry.kind === 'schedule' && entry.ref === target.id)
2314
+ .sort((left, right) => (left.since < right.since ? 1 : left.since > right.since ? -1 : 0))[0] ?? null;
2315
+ if (operation !== 'add' && shown === null) throw notFound();
2316
+ const event = {
2317
+ add: { kind: 'connection_added', payload: { task_id: taskId, to: { kind: 'schedule', id: target.id }, reason } },
2318
+ remove: { kind: 'connection_removed', payload: { target_event_digest: shown?.event_digest, reason } },
2319
+ resolve: { kind: 'connection_resolved', payload: { target_event_digest: shown?.event_digest, evidence: message } },
2320
+ }[operation];
2321
+ const recorded = await appendTodoEvent({
2322
+ validateProspectiveEvent, repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
2323
+ event: { ...event, actor: resolveTodoActor(env) },
2324
+ });
2325
+ if (recorded.unchanged === true) {
2326
+ return connectionResult(store, { ...base, unchanged: true, next_action: `${to} is already ${{ add: 'connected', remove: 'removed', resolve: 'settled' }[operation]}; nothing was recorded.` });
2327
+ }
2328
+ return connectionResult(store, { ...base, event: recorded.event, reason, evidence: message,
2329
+ next_action: operation === 'add'
2330
+ ? `${planKey}/${taskId} cannot start until ${to} settles; the schedule's command settles it with \`lattice todo connect condition resolve\`.`
2331
+ : null });
2332
+ }
2333
+
2142
2334
  async function phaseStatus({ repoRoot, planKey }) {
2143
2335
  const store = await readTodoStore({ repoRoot });
2144
2336
  const [member] = selectMembers(store, planKey);
@@ -2790,7 +2982,8 @@ function taskPrerequisites(store, member, taskId) {
2790
2982
  const key = readiness.key({ ...member.plan, task_id: taskId });
2791
2983
  const { blocking } = readiness.prerequisites(key);
2792
2984
  return { ready: readiness.isReady(key), tasks: readiness.prerequisiteRefs(key).tasks,
2793
- blocking_tasks: blocking.blocking_tasks ?? [], blocking_phases: blocking.blocking_phases ?? [] };
2985
+ blocking_tasks: blocking.blocking_tasks ?? [], blocking_phases: blocking.blocking_phases ?? [],
2986
+ connections: readiness.allConnections(key) };
2794
2987
  }
2795
2988
 
2796
2989
  /**
@@ -4580,6 +4773,11 @@ export async function renderTodoGanttForProject({
4580
4773
  topology_digest: member.plan.topology_digest,
4581
4774
  journal_head_digest: member.journal.events.at(-1)?.event_digest ?? null,
4582
4775
  }));
4776
+ // One 接続 area per task: 他条件に接続 and 優先接続 from the single `connections` list (Store: listTodoConnections).
4777
+ const connections = store.members.flatMap(({ plan }) => plan.tasks.map(({ task_id: taskId }) => ({
4778
+ project_id: plan.project_id, plan_key: plan.plan_key, task_id: taskId,
4779
+ connections: listTodoConnections(store, plan.plan_key, taskId),
4780
+ }))).filter((entry) => entry.connections.length > 0);
4583
4781
  const metadata = {
4584
4782
  manifest_digest: store.manifest.manifest_digest,
4585
4783
  member_bindings: memberBindings,
@@ -4587,6 +4785,7 @@ export async function renderTodoGanttForProject({
4587
4785
  presentation_digest: presentation?.presentation_digest ?? null,
4588
4786
  layout_digest: digestTodoArtifact(layout),
4589
4787
  note_bindings_digest: digestTodoArtifact(notes.headBindings),
4788
+ connections_digest: digestTodoArtifact(connections),
4590
4789
  structure_projection_digest: structures?.projection_digest ?? null,
4591
4790
  renderer_version: TODO_GANTT_RENDERER_VERSION,
4592
4791
  project_display_name: identity.displayName,
@@ -4604,6 +4803,7 @@ export async function renderTodoGanttForProject({
4604
4803
  noteWarnings: notes.warnings,
4605
4804
  structurePresentation: structures,
4606
4805
  notices,
4806
+ connections,
4607
4807
  });
4608
4808
  return { store, metadata, memberBindings, rendered };
4609
4809
  }
@@ -4751,6 +4951,8 @@ function writesTodoStore(argv) {
4751
4951
  case 'seam-proposal': return ['compile', 'apply', 'land'].includes(second);
4752
4952
  case 'evidence': return second === 'promote';
4753
4953
  case 'dependency': return ['connect', 'disconnect'].includes(second);
4954
+ case 'predecessor': return ['add', 'remove'].includes(second);
4955
+ case 'connect': return second === 'condition' && ['add', 'remove', 'resolve'].includes(argv[2]);
4754
4956
  case 'phase': return second !== 'status';
4755
4957
  case 'start': case 'retract': case 'block': case 'unblock': case 'retire': case 'done':
4756
4958
  case 'reopen': case 'split': case 'revise': case 'revise-phase': case 'revise-set': case 'add':
@@ -4764,7 +4966,9 @@ function releasesTasks(argv) {
4764
4966
  const [command, second] = argv;
4765
4967
  return ['done', 'retire', 'unblock'].includes(command)
4766
4968
  || (command === 'phase' && ['accept', 'close-unaudited'].includes(second))
4767
- || (command === 'dependency' && second === 'disconnect');
4969
+ || (command === 'dependency' && second === 'disconnect')
4970
+ || (command === 'predecessor' && second === 'remove')
4971
+ || (command === 'connect' && second === 'condition' && ['remove', 'resolve'].includes(argv[2]));
4768
4972
  }
4769
4973
 
4770
4974
  /** `declared(planKey, taskId)`: whether an enforced plan's witness set records the task's row (unreadable = none). */
@@ -4934,10 +5138,10 @@ async function noticeAck({ repoRoot, env, lane, ids }) {
4934
5138
  }
4935
5139
 
4936
5140
  /**
4937
- * `todo wait` (wait-design): record that this agent stopped work and waits for T to become startable. A record, never a
4938
- * gate: an already startable or finished T is answered with a state and nothing is written.
5141
+ * `todo connect priority` (優先接続; `todo wait` is its alias for one minor version): record that this agent asks to be told the
5142
+ * 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
5143
  */
4940
- async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
5144
+ async function noticePriority({ repoRoot, env, planKey, taskId, reason, cancel }) {
4941
5145
  const view = await openNoticeView(repoRoot, env);
4942
5146
  const { store } = view;
4943
5147
  const member = store.members.find(({ plan }) => plan.plan_key === planKey);
@@ -4947,7 +5151,7 @@ async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
4947
5151
  throw new TodoStoreError('TASK_NOT_FOUND', 'task_not_found', undefined, { requested_task_id: taskId });
4948
5152
  }
4949
5153
  const { agent } = resolveTodoActor(env);
4950
- const base = { schema: 'lattice.todo_wait_result.v1', project_id: store.project_id, plan_key: planKey, task_id: taskId, agent };
5154
+ const base = { schema: 'lattice.todo_connect_priority_result.v1', project_id: store.project_id, plan_key: planKey, task_id: taskId, agent };
4951
5155
  let rest;
4952
5156
  if (cancel) {
4953
5157
  const { cancelled } = await cancelTodoNoticeWait({ repoRoot, planKey, taskId, agent });
@@ -4967,7 +5171,7 @@ async function noticeWait({ repoRoot, env, planKey, taskId, reason, cancel }) {
4967
5171
  repoRoot, planKey, taskId, agent, reason: reason ?? null, now,
4968
5172
  keep: (wait) => waitInEffect(store, { plan_key: planKey, ...wait }),
4969
5173
  });
4970
- rest = { state: 'waiting', since, reason: reason ?? null, notice: null, next_action: null };
5174
+ rest = { state: 'prioritized', since, reason: reason ?? null, notice: null, next_action: null };
4971
5175
  }
4972
5176
  }
4973
5177
  const result = { ...base, ...rest, result_digest: '' };
@@ -5370,15 +5574,31 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5370
5574
  if (isNoticeLane(flags.lane) && ids.length > 0 && ids.every((id) => /^[0-9a-f]{64}$/u.test(id))) {
5371
5575
  action = (repoRoot) => noticeAck({ repoRoot, env, lane: flags.lane, ids });
5372
5576
  }
5577
+ } else if (argv[0] === 'compact' && matchFlagCommand(argv, ['compact'], TODO_FLAG_SPECS.compact) !== null) {
5578
+ // b10: retained versions keep only their difference from the successor; this finishes the ones written before.
5579
+ const flags = matchFlagCommand(argv, ['compact'], TODO_FLAG_SPECS.compact);
5580
+ if ((flags.plan === undefined || isTodoIdentifier(flags.plan)) && (flags.limit === undefined || /^[1-9]\d{0,5}$/u.test(flags.limit))) {
5581
+ action = (repoRoot) => compactTodoVersions({ repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
5582
+ planKey: flags.plan, limit: flags.limit === undefined ? 40 : Number(flags.limit) });
5583
+ }
5373
5584
  } else if (argv[0] === 'blockers' && matchFlagCommand(argv, ['blockers'], TODO_FLAG_SPECS.blockers) !== null) {
5374
5585
  action = (repoRoot) => blockerList({ repoRoot });
5375
- } else if (argv[0] === 'wait' && matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait) !== null) {
5376
- const flags = matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait);
5586
+ } else if ((argv[0] === 'connect' && argv[1] === 'priority' || argv[0] === 'wait')
5587
+ && matchFlagCommand(argv, argv[0] === 'wait' ? ['wait'] : ['connect', 'priority'], TODO_FLAG_SPECS[argv[0] === 'wait' ? 'wait' : 'connect priority']) !== null) {
5588
+ const flags = matchFlagCommand(argv, argv[0] === 'wait' ? ['wait'] : ['connect', 'priority'], TODO_FLAG_SPECS[argv[0] === 'wait' ? 'wait' : 'connect priority']);
5377
5589
  const reasonOk = flags.reason === undefined
5378
5590
  || (typeof flags.reason === 'string' && flags.reason.length > 0 && flags.reason.length <= 1024 && !/\p{Cc}/u.test(flags.reason));
5379
5591
  if (isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task) && reasonOk && !(flags.cancel === true && flags.reason !== undefined)) {
5380
- action = (repoRoot) => noticeWait({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
5381
- reason: flags.reason ?? null, cancel: flags.cancel === true });
5592
+ action = async (repoRoot) => {
5593
+ const result = await noticePriority({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
5594
+ reason: flags.reason ?? null, cancel: flags.cancel === true });
5595
+ if (argv[0] === 'wait') {
5596
+ stderr.write(`${JSON.stringify({ schema: 'lattice.todo_command_retired.v1', command: 'todo wait',
5597
+ still_works_until: 'the next minor version',
5598
+ use: `lattice todo connect priority --plan ${flags.plan} --task ${flags.task}${flags.cancel === true ? ' --cancel' : ''}` })}\n`);
5599
+ }
5600
+ return result;
5601
+ };
5382
5602
  }
5383
5603
  } else if (argv[0] === 'note' && argv[1] === 'list' && readFlags(argv, ['note', 'list']) !== null) {
5384
5604
  const flags = readFlags(argv, ['note', 'list']);
@@ -5394,20 +5614,34 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5394
5614
  repoRoot, env, planKey: flags.plan, mode: flags.set, reason: flags.reason,
5395
5615
  });
5396
5616
  }
5617
+ } else if (argv[0] === 'predecessor' && ['add', 'remove'].includes(argv[1])
5618
+ && matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC) !== null
5619
+ && parsePredecessorTarget(matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC).after, '') !== null
5620
+ && ['plan', 'task'].every((name) => isTodoIdentifier(matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC)[name]))) {
5621
+ const flags = matchFlagCommand(argv, argv.slice(0, 2), PREDECESSOR_FLAG_SPEC);
5622
+ action = (repoRoot) => predecessorChange({ repoRoot, env, operation: argv[1], planKey: flags.plan, taskId: flags.task,
5623
+ after: flags.after, reason: flags.reason });
5624
+ } else if (argv[0] === 'connect' && argv[1] === 'condition' && ['add', 'remove', 'resolve'].includes(argv[2])
5625
+ && parseConditionTarget(matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')])?.to, '') !== null
5626
+ && matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')]) !== null
5627
+ && ['plan', 'task'].every((name) => isTodoIdentifier(matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')])[name]))) {
5628
+ const flags = matchFlagCommand(argv, argv.slice(0, 3), TODO_FLAG_SPECS[argv.slice(0, 3).join(' ')]);
5629
+ action = (repoRoot) => connectCondition({ repoRoot, env, operation: argv[2], planKey: flags.plan, taskId: flags.task,
5630
+ to: flags.to, reason: flags.reason ?? null, message: flags.message ?? null });
5397
5631
  } else if (argv[0] === 'dependency' && argv[1] === 'connect'
5398
5632
  && dependencyFlags(argv) !== null) {
5399
5633
  const flags = dependencyFlags(argv);
5400
- action = (repoRoot) => dependencyConnect({
5634
+ action = async (repoRoot) => retiredDependencyCommand(stderr, 'add', flags, await dependencyConnect({
5401
5635
  repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5402
5636
  toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
5403
- });
5637
+ }));
5404
5638
  } else if (argv[0] === 'dependency' && argv[1] === 'disconnect'
5405
5639
  && dependencyFlags(argv) !== null) {
5406
5640
  const flags = dependencyFlags(argv);
5407
- action = (repoRoot) => dependencyDisconnect({
5641
+ action = async (repoRoot) => retiredDependencyCommand(stderr, 'remove', flags, await dependencyDisconnect({
5408
5642
  repoRoot, env, fromProjectId: flags['from-project'] ?? null, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
5409
5643
  toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
5410
- });
5644
+ }));
5411
5645
  } else if (argv[0] === 'independence' && argv[1] === 'compile') {
5412
5646
  const flags = matchFlagCommand(argv, ['independence', 'compile'], TODO_FLAG_SPECS['independence compile']);
5413
5647
  if (flags !== null && isTodoIdentifier(flags.plan) && isAuthoringPathToken(flags.input)) {
@@ -5671,10 +5905,10 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5671
5905
  const flags = matchFlagCommand(argv, ['block'], TODO_FLAG_SPECS.block);
5672
5906
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
5673
5907
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
5674
- kind: 'block', dropped: reasonDropped(flags.reason), action: () => mutate({
5908
+ kind: 'block', dropped: reasonDropped(flags.reason), action: async () => withBlockGuidance(await mutate({
5675
5909
  repoRoot, env, planKey: flags.plan, taskId: flags.task,
5676
5910
  kind: 'block', payload: { reason: flags.reason }, evidenceRef: null,
5677
- }) });
5911
+ })) });
5678
5912
  }
5679
5913
  } else if (argv[0] === 'add') {
5680
5914
  const flags = matchFlagCommand(argv, ['add'], TODO_FLAG_SPECS.add);