@quolu/lattice 0.84.1 → 0.85.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
@@ -69,6 +69,7 @@ import {
69
69
  TodoStoreError,
70
70
  isPhaselessTodoPlanSchema,
71
71
  isTodoEvidenceUncommitted,
72
+ isUninitializedTodoStore,
72
73
  projectTodoCrossPlanDependencies,
73
74
  TERMINAL_AUDIT_PHASE_ID,
74
75
  todoPhaseDefinitions,
@@ -274,6 +275,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
274
275
  'status', 'show', 'note', 'bindings', 'independence', 'structure', 'seam-profile', 'seam-proposal',
275
276
  'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
276
277
  'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
278
+ 'retract', 'dependency',
277
279
  ]);
278
280
 
279
281
  function typedArgumentFailure(stderr, code, message, detail, context = {}) {
@@ -290,15 +292,74 @@ const DONE_FLAG_SPEC = Object.freeze({
290
292
  required: ['plan', 'task'],
291
293
  });
292
294
 
293
- /** `todo done`のargument拒否を、直すflagと規則で名指す。他のcommandは従来どおり(空)。 */
295
+ const REASON_FLAG_SPEC = Object.freeze({ known: ['plan', 'task', 'reason'], required: ['plan', 'task', 'reason'] });
296
+ const DEPENDENCY_FLAG_SPEC = Object.freeze({
297
+ known: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
298
+ required: ['from-plan', 'from-task', 'to-plan', 'to-task', 'reason'],
299
+ });
300
+ // a18: one spec per write command is both its parser and the explanation of its refusal.
301
+ const TODO_FLAG_SPECS = Object.freeze({
302
+ start: Object.freeze({
303
+ known: ['plan', 'task', 'parallel-frontier', 'override-reason', 'serial-confirmed', 'rebind', 'reason'],
304
+ required: ['plan', 'task'],
305
+ booleans: ['parallel-frontier', 'serial-confirmed', 'rebind'],
306
+ }),
307
+ done: DONE_FLAG_SPEC,
308
+ block: REASON_FLAG_SPEC,
309
+ retire: REASON_FLAG_SPEC,
310
+ retract: REASON_FLAG_SPEC,
311
+ unblock: Object.freeze({ known: ['plan', 'task'], required: ['plan', 'task'] }),
312
+ reopen: Object.freeze({ known: ['plan', 'task', 'reason', 'override-reason'], required: ['plan', 'task', 'reason'] }),
313
+ 'dependency connect': DEPENDENCY_FLAG_SPEC,
314
+ 'dependency disconnect': DEPENDENCY_FLAG_SPEC,
315
+ });
316
+ const IDENTIFIER_FLAGS = ['plan', 'task', 'from-plan', 'from-task', 'to-plan', 'to-task'];
317
+ const FLAG_PLACEHOLDER = { reason: '<text>', 'override-reason': '<text>', message: '<text>',
318
+ evidence: '<file>', 'test-result': '<file>' };
319
+ const shellWord = (value) => (/^[\w./:@-]+$/u.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`);
320
+
321
+ /** The command again, with the flags given and a placeholder for each missing required flag. */
322
+ function repairedCommand(head, spec, flags) {
323
+ const words = ['lattice', 'todo', ...head];
324
+ for (const name of spec.known) {
325
+ if (typeof flags[name] === 'string' && flags[name].length > 0) words.push(`--${name}`, shellWord(flags[name]));
326
+ else if (flags[name] === true && spec.booleans?.includes(name)) words.push(`--${name}`);
327
+ else if (spec.required.includes(name)) words.push(`--${name}`, FLAG_PLACEHOLDER[name] ?? `<${name}>`);
328
+ }
329
+ return words.join(' ');
330
+ }
331
+
332
+ /** `dependency connect|disconnect` flags by name (order-free), or null. */
333
+ function dependencyFlags(argv) {
334
+ const flags = matchFlagCommand(argv, argv.slice(0, 2), DEPENDENCY_FLAG_SPEC);
335
+ return flags !== null && IDENTIFIER_FLAGS.slice(2).every((name) => isTodoIdentifier(flags[name])) ? flags : null;
336
+ }
337
+
338
+ /** A todo write's argument refusal names the flag, the rule and the command to run instead. */
294
339
  function explainArgumentRefusal(argv) {
295
- if (argv[0] !== 'done') return {};
296
- const flagFailure = explainFlagCommand(argv, ['done'], DONE_FLAG_SPEC);
340
+ const head = argv[0] === 'dependency' ? argv.slice(0, 2) : argv.slice(0, 1);
341
+ const spec = TODO_FLAG_SPECS[head.join(' ')];
342
+ if (spec === undefined) return {};
343
+ const { flags } = parseFlagMap(argv.slice(head.length));
344
+ const flagFailure = explainFlagCommand(argv, head, spec);
345
+ if (flagFailure?.rule === 'flag_missing') {
346
+ return { ...flagFailure, next_action: `Add ${flagFailure.pointer} ${FLAG_PLACEHOLDER[flagFailure.pointer.slice(2)] ?? '<value>'}: \`${repairedCommand(head, spec, flags)}\`.` };
347
+ }
297
348
  if (flagFailure !== null) return flagFailure;
298
- const { flags } = parseFlagMap(argv.slice(1));
299
- for (const name of ['plan', 'task']) {
349
+ for (const name of IDENTIFIER_FLAGS.filter((key) => spec.known.includes(key))) {
300
350
  if (!isTodoIdentifier(flags[name])) return { pointer: `--${name}`, rule: 'identifier_invalid', actual: flags[name] };
301
351
  }
352
+ for (const name of ['override-reason', 'reason']) {
353
+ if (spec.known.includes(name) && flags[name] !== undefined
354
+ && !(typeof flags[name] === 'string' && flags[name].length > 0)) {
355
+ return { pointer: `--${name}`, rule: 'flag_missing', next_action: `Give --${name} a non-empty <text>: \`${repairedCommand(head, spec, flags)}\`.` };
356
+ }
357
+ }
358
+ if (argv[0] === 'start' && flags.rebind === true && !(typeof flags.reason === 'string' && flags.reason.length > 0)) {
359
+ return { pointer: '--reason', rule: 'flag_missing',
360
+ next_action: `--rebind needs --reason <text>: \`${repairedCommand(head, { ...spec, required: [...spec.required, 'reason'] }, flags)}\`.` };
361
+ }
362
+ if (argv[0] !== 'done') return {};
302
363
  const hasMessage = typeof flags.message === 'string' && flags.message.length > 0;
303
364
  if (flags.message !== undefined && !hasMessage) return { pointer: '--message', rule: 'flag_missing' };
304
365
  if (flags.evidence !== undefined && !isAuthoringPathToken(flags.evidence)) {
@@ -344,7 +405,9 @@ function resolveRepoRoot(cwd) {
344
405
  stdio: ['ignore', 'pipe', 'ignore'],
345
406
  }).replace(/\r?\n$/u, ''));
346
407
  } catch {
347
- throw new TodoStoreError('REPO_UNRESOLVED', 'git_toplevel_unresolved', 'cwdのgit toplevelを解決できない');
408
+ throw new TodoStoreError('REPO_UNRESOLVED', 'git_toplevel_unresolved', 'cwdのgit toplevelを解決できない', {
409
+ next_action: 'cd into the project repository, or run `git init` there first',
410
+ });
348
411
  }
349
412
  }
350
413
 
@@ -696,9 +759,9 @@ function reopenAdvisory(plan, phases, taskId) {
696
759
  async function mutate({
697
760
  repoRoot, env, planKey, taskId, kind, payload, evidenceRef, evidenceMessage = null,
698
761
  advisory = null, noteContext = null, structureContext = null, featureContext = null,
699
- testResultRef = null,
762
+ testResultRef = null, actor: carriedActor = null,
700
763
  }) {
701
- const actor = resolveTodoActor(env);
764
+ const actor = carriedActor ?? resolveTodoActor(env);
702
765
  const evidence = evidenceRef === null && evidenceMessage === null
703
766
  ? null
704
767
  : await resolveDoneEvidence({
@@ -789,7 +852,7 @@ const UNCHANGED_WHEN = {
789
852
  };
790
853
 
791
854
  /** Unchanged result, or null when the transition must go to the append path. */
792
- function unchangedTransition(store, { env, planKey, taskId, kind }) {
855
+ function unchangedTransition(store, { env, planKey, taskId, kind, notRecorded = [] }) {
793
856
  const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
794
857
  const matches = member?.tasks.filter(({ task_id: current }) => current.toLowerCase() === taskId.toLowerCase()) ?? [];
795
858
  // Unknown or ambiguous plan/task: the append path keeps Store's refusal.
@@ -805,7 +868,15 @@ function unchangedTransition(store, { env, planKey, taskId, kind }) {
805
868
  project_id: member.plan.project_id, plan_key: planKey, plan_version: member.plan.plan_version,
806
869
  task_id: state.task_id, kind, sequence: shown.sequence, event_digest: shown.event_digest,
807
870
  journal_head_digest: events.at(-1).event_digest, snapshot_digest: member.snapshot.snapshot_digest,
808
- status: state.status, advisory: null, unchanged: true, result_digest: '',
871
+ status: state.status, advisory: null, unchanged: true,
872
+ // a18: a repeated done appends nothing, so say which given content was not recorded.
873
+ ...(notRecorded.length === 0 ? {} : {
874
+ not_recorded: notRecorded,
875
+ next_action: `${planKey}/${state.task_id} was already done; ${notRecorded.join(', ')} not recorded.`
876
+ + ` Keep the text with \`lattice todo note --plan ${planKey} --task ${state.task_id} --message <text>\`,`
877
+ + ` or replace the record: \`lattice todo reopen --plan ${planKey} --task ${state.task_id} --reason <text>\`, then start and done again.`,
878
+ }),
879
+ result_digest: '',
809
880
  };
810
881
  result.result_digest = todoSelfDigest(result, 'result_digest');
811
882
  return result;
@@ -817,6 +888,26 @@ async function mutateUnlessUnchanged(options) {
817
888
  return unchangedTransition(store, options) ?? options.action();
818
889
  }
819
890
 
891
+ /** a18: the live tasks with an edge (plan, join or ledger) from the task being retired, sorted. */
892
+ function retireDependents(store, member, taskId) {
893
+ const planKey = member.plan.plan_key;
894
+ const fromIt = (ref) => ref.plan_key === planKey && ref.task_id === taskId;
895
+ const targets = [
896
+ ...member.plan.hard_dependencies.filter((edge) => fromIt(edge.from)).map((edge) => edge.to),
897
+ ...member.plan.joins.filter((join) => join.after.some(fromIt)).map((join) => join.before),
898
+ ...projectTodoCrossPlanDependencies(store.members).filter((edge) => fromIt(edge.from)).map((edge) => edge.to),
899
+ ];
900
+ const byKey = new Map();
901
+ for (const ref of targets) {
902
+ const status = store.members.find(({ plan }) => plan.plan_key === ref.plan_key)
903
+ ?.tasks.find(({ task_id: id }) => id === ref.task_id)?.status;
904
+ if (status !== undefined && status !== 'retired') {
905
+ byKey.set(`${ref.plan_key}\0${ref.task_id}`, { plan_key: ref.plan_key, task_id: ref.task_id, status });
906
+ }
907
+ }
908
+ return [...byKey.entries()].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)).map(([, task]) => task);
909
+ }
910
+
820
911
  async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
821
912
  const store = await readTodoStore({ repoRoot });
822
913
  const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
@@ -826,13 +917,22 @@ async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
826
917
  return mutate({ repoRoot, env, planKey, taskId, kind: 'retire', payload: { reason }, evidenceRef: null });
827
918
  }
828
919
  if (state.status === 'retired') return unchangedTransition(store, { env, planKey, taskId, kind: 'retire' });
920
+ const dependents = retireDependents(store, member, taskId);
829
921
  const append = async () => {
922
+ let result;
830
923
  try {
831
- return await mutate({ repoRoot, env, planKey, taskId, kind: 'retire',
924
+ result = await mutate({ repoRoot, env, planKey, taskId, kind: 'retire',
832
925
  payload: { reason, prior_status: state.status }, evidenceRef: null });
833
926
  } catch (error) {
834
927
  throw retireStateConflict(error, { planKey, taskId, priorStatus: state.status });
835
928
  }
929
+ const { result_digest: _replaced, ...recorded } = result;
930
+ const named = { ...recorded, dependents, ...(dependents.length === 0 ? {} : {
931
+ next_action: `${dependents.map((task) => `${task.plan_key}/${task.task_id} (${task.status})`).join(', ')}`
932
+ + ` no longer wait on ${planKey}/${taskId}; see \`lattice todo status --json\`.`,
933
+ }), result_digest: '' };
934
+ named.result_digest = todoSelfDigest(named, 'result_digest');
935
+ return named;
836
936
  };
837
937
  if (state.status !== 'in-progress') return append();
838
938
  // Runtime binds an intake to the latest literal start and ignores later done/reopen, so the
@@ -935,7 +1035,7 @@ async function startAdvisory({ repoRoot, store, projection, planKey, taskId }) {
935
1035
  .filter((task) => task.plan_key === planKey).map(({ task_id: id }) => id),
936
1036
  self_unknowns: [{ kind: 'witness_missing', ref: unusable ?? 'no_independence_record' }],
937
1037
  guidance: selectIndependenceGuidance({
938
- coverage: 'missing', taskDeclared: false, taskStale: false, coordinationMode,
1038
+ coverage: 'missing', taskDeclared: false, taskStale: false, coordinationMode, planKey,
939
1039
  }),
940
1040
  };
941
1041
  }
@@ -984,7 +1084,7 @@ async function startAdvisory({ repoRoot, store, projection, planKey, taskId }) {
984
1084
  conflictWithActive: conflictsWithActive[0]?.severability ?? null,
985
1085
  conflictBetweenReady: readyConflict?.severability ?? null,
986
1086
  verdictsAbsent: selfUnknowns.some(({ kind }) => kind === 'plan_verdicts_absent'),
987
- coordinationMode,
1087
+ coordinationMode, planKey,
988
1088
  }),
989
1089
  };
990
1090
  }
@@ -1066,7 +1166,8 @@ async function startTask({
1066
1166
  // literal startだけを束縛に使いcarryを推定しないため、改訂を跨いだ進行中工程の
1067
1167
  // 再開はこの入口だけが正規経路になる。advisory・independence gateは初回startで
1068
1168
  // 済んでいるため再適用しない。
1069
- export async function rebindStart({ repoRoot, env, planKey, taskId, reason }) {
1169
+ // actor: 改訂が運ぶstartの記録者。渡せば現在の席でなくその記録者でrebind startを積む(a16)。
1170
+ export async function rebindStart({ repoRoot, env, planKey, taskId, reason, actor = null }) {
1070
1171
  const store = await readTodoStore({ repoRoot });
1071
1172
  const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
1072
1173
  if (member === undefined) throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active');
@@ -1098,7 +1199,7 @@ export async function rebindStart({ repoRoot, env, planKey, taskId, reason }) {
1098
1199
  }
1099
1200
  return mutate({
1100
1201
  repoRoot, env, planKey, taskId, kind: 'start',
1101
- payload: { start_mode: 'rebind', reason }, evidenceRef: null, noteContext,
1202
+ payload: { start_mode: 'rebind', reason }, evidenceRef: null, noteContext, actor,
1102
1203
  });
1103
1204
  }
1104
1205
 
@@ -1287,11 +1388,21 @@ async function dependencyRevision({
1287
1388
  ? [...desired.hard_dependencies, { from, to }]
1288
1389
  : desired.hard_dependencies.filter((edge) => !(edge.from.task_id === fromTaskId
1289
1390
  && edge.to.task_id === toTaskId));
1290
- const applied = await applyPlanRevision({
1291
- repoRoot, env, input: { schema: 'lattice.plan_revise_input.v1', desired },
1292
- notes: [{ task_id: fromTaskId,
1293
- body: `dependency ${operation} ${fromTaskId}→${toTaskId}: ${reason}` }],
1294
- });
1391
+ let applied;
1392
+ try {
1393
+ applied = await applyPlanRevision({
1394
+ repoRoot, env, input: { schema: 'lattice.plan_revise_input.v1', desired },
1395
+ notes: [{ task_id: fromTaskId,
1396
+ body: `dependency ${operation} ${fromTaskId}→${toTaskId}: ${reason}` }],
1397
+ });
1398
+ } catch (error) {
1399
+ // a18: the new edge closes a cycle; nothing stored is inconsistent, so name the edge and the path.
1400
+ if (operation === 'connect' && error instanceof TodoStoreError && error.detail?.reason === 'merged_cycle') {
1401
+ throw new TodoStoreError('DEPENDENCY_CYCLE', 'dependency_cycle', undefined, {
1402
+ from, to, cycle: error.detail.cycle ?? null });
1403
+ }
1404
+ throw error;
1405
+ }
1295
1406
  const result = {
1296
1407
  schema: 'lattice.todo_dependency_revision_result.v1', project_id: store.project_id,
1297
1408
  plan_key: planKey, operation, from, to, reason, actor: desired.actor,
@@ -1418,11 +1529,20 @@ async function dependencyDisconnectLedger({
1418
1529
  && dependency.to.plan_key === toPlanKey && dependency.to.task_id === toTaskId
1419
1530
  ));
1420
1531
  if (live.length === 0) {
1421
- throw new TodoStoreError('DEPENDENCY_INVALID', 'cross_plan_dependency_not_found', undefined, {
1422
- from: { plan_key: fromPlanKey, task_id: fromTaskId },
1423
- to: { plan_key: toPlanKey, task_id: toTaskId },
1424
- ...(fromPlanKey === toPlanKey ? { next_action: `lattice plan show ${fromPlanKey} --json` } : {}),
1425
- });
1532
+ const from = { plan_key: fromPlanKey, task_id: fromTaskId };
1533
+ const to = { plan_key: toPlanKey, task_id: toTaskId };
1534
+ if (fromPlanKey === toPlanKey) {
1535
+ const member = store.members.find(({ plan }) => plan.plan_key === toPlanKey);
1536
+ const predecessors = (member?.plan.hard_dependencies ?? [])
1537
+ .filter((edge) => edge.to.task_id === toTaskId).map((edge) => edge.from.task_id).sort();
1538
+ throw new TodoStoreError('DEPENDENCY_NOT_FOUND', 'dependency_not_found', undefined, {
1539
+ from, to, predecessors,
1540
+ next_action: `${toPlanKey} has no dependency ${fromTaskId} -> ${toTaskId}`
1541
+ + ` (${toTaskId} depends on ${predecessors.length === 0 ? 'nothing in this plan' : predecessors.join(', ')});`
1542
+ + ` see \`lattice plan show ${toPlanKey} --json\`.`,
1543
+ });
1544
+ }
1545
+ throw new TodoStoreError('DEPENDENCY_NOT_FOUND', 'cross_plan_dependency_not_found', undefined, { from, to });
1426
1546
  }
1427
1547
  const [target] = live;
1428
1548
  const owner = store.members.find((member) => (member.plan_scoped?.events ?? [])
@@ -2017,6 +2137,17 @@ async function splitTodo({ repoRoot, env, planKey, inputRef }) {
2017
2137
  }
2018
2138
 
2019
2139
  async function status({ repoRoot }) {
2140
+ // No plan yet is an empty project, not a broken store: answer zero plans and how to make one.
2141
+ if (await isUninitializedTodoStore({ repoRoot })) {
2142
+ const result = {
2143
+ schema: 'lattice.todo_status_uninitialized.v1',
2144
+ plan_count: 0,
2145
+ next_actions: ['lattice plan create --template --json', 'lattice plan create --input <file>'],
2146
+ result_digest: '',
2147
+ };
2148
+ result.result_digest = todoSelfDigest(result, 'result_digest');
2149
+ return result;
2150
+ }
2020
2151
  const store = await readTodoStore({ repoRoot });
2021
2152
  const result = projectTodoStatus(store, {
2022
2153
  planNotes: await readTodoPlanNotesForStatus({ repoRoot, store }),
@@ -2853,7 +2984,7 @@ async function independenceCompile({ repoRoot, planKey, inputRef }) {
2853
2984
  {
2854
2985
  plan_key: planKey,
2855
2986
  missing_task_ids: missingReady,
2856
- next_action: 'add_task_to_witness_set_then_compile',
2987
+ next_action: independenceCompileCommand(planKey),
2857
2988
  },
2858
2989
  );
2859
2990
  }
@@ -3021,7 +3152,7 @@ async function independence({ repoRoot, requestedPlanKey }) {
3021
3152
  conflictBetweenReady: projected.frontier.serialize_pairs[0]?.severability ?? null,
3022
3153
  // 案内の正本は1つ(ADR 0130 Decision 1)。着手する人と読みに来た人が同じ状況について
3023
3154
  // 違う文言を受け取らないよう、調整方式もここへ渡す。
3024
- coordinationMode: member?.coordination?.mode ?? null,
3155
+ coordinationMode: member?.coordination?.mode ?? null, planKey,
3025
3156
  verdictsAbsent: projected.frontier.unknown
3026
3157
  .some(({ unknowns }) => unknowns.some(({ kind }) => kind === 'plan_verdicts_absent')),
3027
3158
  }),
@@ -3085,6 +3216,8 @@ async function seamProfile({ repoRoot, planKey, filePath }) {
3085
3216
  return profile;
3086
3217
  }
3087
3218
 
3219
+ const independenceCompileCommand = (planKey, input = '<file>') => `lattice todo independence compile --plan ${planKey} --input ${input}`;
3220
+
3088
3221
  async function seamProposalCompile({ repoRoot, planKey }) {
3089
3222
  const currentBaseSha = currentHeadSha(repoRoot);
3090
3223
  const store = await readTodoStore({ repoRoot });
@@ -3100,31 +3233,31 @@ async function seamProposalCompile({ repoRoot, planKey }) {
3100
3233
  'SEAM_PROPOSAL_COMPILE_UNAVAILABLE',
3101
3234
  independenceArtifact === null ? 'independence_artifact_absent' : 'independence_artifact_superseded',
3102
3235
  undefined,
3103
- { next_action: 'compile_independence' },
3236
+ { next_action: independenceCompileCommand(planKey) },
3104
3237
  );
3105
3238
  }
3106
3239
  if (independenceArtifact.outcome !== 'compiled') {
3107
3240
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'independence_outcome_not_compiled', undefined, {
3108
3241
  outcome: independenceArtifact.outcome,
3109
- next_action: 'recompile_independence',
3242
+ next_action: independenceCompileCommand(planKey),
3110
3243
  });
3111
3244
  }
3112
3245
  if (independenceArtifact.base_sha !== currentBaseSha) {
3113
3246
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'independence_artifact_stale', undefined, {
3114
3247
  independence_base_sha: independenceArtifact.base_sha,
3115
3248
  current_base_sha: currentBaseSha,
3116
- next_action: 'recompile_independence',
3249
+ next_action: independenceCompileCommand(planKey),
3117
3250
  });
3118
3251
  }
3119
3252
  const witnessSet = await readTodoWitnessSet({ repoRoot, planKey });
3120
3253
  if (witnessSet === null) {
3121
3254
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'witness_set_absent', undefined, {
3122
- next_action: 'declare_witness_set_then_compile_independence',
3255
+ next_action: independenceCompileCommand(planKey),
3123
3256
  });
3124
3257
  }
3125
3258
  if (witnessSet.witness_set_digest !== independenceArtifact.witness_set_digest) {
3126
3259
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'witness_set_changed', undefined, {
3127
- next_action: 'recompile_independence',
3260
+ next_action: independenceCompileCommand(planKey),
3128
3261
  });
3129
3262
  }
3130
3263
 
@@ -3221,7 +3354,7 @@ async function witnessScaffold({ repoRoot, planKey, inputRef }) {
3221
3354
  observed_paths: paths,
3222
3355
  task_count: Object.keys(witnessSet.manual_witness).length,
3223
3356
  witness_set_digest: witnessSet.witness_set_digest,
3224
- next_action: 'compile_independence',
3357
+ next_action: independenceCompileCommand(planKey, ref),
3225
3358
  };
3226
3359
  }
3227
3360
 
@@ -3265,13 +3398,13 @@ async function seamProposalApply({ repoRoot, planKey, pathNames = {}, land = fal
3265
3398
  const artifact = await readTodoSeamProposalArtifact({ repoRoot, store, planKey });
3266
3399
  if (artifact === null) {
3267
3400
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'seam_proposal_absent', undefined, {
3268
- plan_key: planKey, next_action: 'compile_seam_proposal',
3401
+ plan_key: planKey, next_action: `lattice todo seam-proposal compile --plan ${planKey}`,
3269
3402
  });
3270
3403
  }
3271
3404
  const witnessSet = await readTodoWitnessSet({ repoRoot, planKey });
3272
3405
  if (witnessSet === null) {
3273
3406
  throw new TodoStoreError('SEAM_PROPOSAL_COMPILE_UNAVAILABLE', 'witness_set_absent', undefined, {
3274
- plan_key: planKey, next_action: 'declare_witness_set_then_compile_independence',
3407
+ plan_key: planKey, next_action: independenceCompileCommand(planKey),
3275
3408
  });
3276
3409
  }
3277
3410
  const baseArtifact = await readTodoIndependenceArtifact({ repoRoot, store, planKey });
@@ -3401,6 +3534,7 @@ async function seamProposal({ repoRoot, requestedPlanKey }) {
3401
3534
  guidance: selectSeamProposalGuidance({
3402
3535
  coverage,
3403
3536
  unknownKinds: components.flatMap(({ unknowns }) => unknowns.map(({ kind }) => kind)),
3537
+ planKey,
3404
3538
  }),
3405
3539
  component_count: artifact === null ? null : components.length,
3406
3540
  conflict_resource_count: artifact === null ? null : components
@@ -3636,7 +3770,7 @@ async function seamProposalsForGantt({ repoRoot, store }) {
3636
3770
  plan_key: planKey,
3637
3771
  coverage: 'superseded',
3638
3772
  unreadable_reason: `${error.code}:${error.detail?.reason ?? error.message}`,
3639
- guidance: selectSeamProposalGuidance({ coverage: 'superseded' }),
3773
+ guidance: selectSeamProposalGuidance({ coverage: 'superseded', planKey }),
3640
3774
  component_count: null,
3641
3775
  conflict_resource_count: null,
3642
3776
  components: [],
@@ -3649,7 +3783,7 @@ async function seamProposalsForGantt({ repoRoot, store }) {
3649
3783
  plan_key: planKey,
3650
3784
  coverage: 'missing',
3651
3785
  unreadable_reason: null,
3652
- guidance: selectSeamProposalGuidance({ coverage: 'missing' }),
3786
+ guidance: selectSeamProposalGuidance({ coverage: 'missing', planKey }),
3653
3787
  component_count: null,
3654
3788
  conflict_resource_count: null,
3655
3789
  components: [],
@@ -3685,7 +3819,7 @@ async function seamProposalsForGantt({ repoRoot, store }) {
3685
3819
  plan_key: planKey,
3686
3820
  coverage,
3687
3821
  unreadable_reason: unreadableReason,
3688
- guidance: selectSeamProposalGuidance({ coverage }),
3822
+ guidance: selectSeamProposalGuidance({ coverage, planKey }),
3689
3823
  component_count: components.length,
3690
3824
  conflict_resource_count: components
3691
3825
  .reduce((count, component) => count + component.conflicts.length, 0),
@@ -4045,9 +4179,9 @@ async function verify({ repoRoot, requestedPlanKey }) {
4045
4179
  meaning: 'source_inventory_verification_state',
4046
4180
  lifecycle_blocked: false,
4047
4181
  dashboard_visibility_blocked: false,
4048
- schema_command: reconciled ? null : 'lattice todo revise --schema --json',
4049
- next_action: reconciled ? null
4050
- : `lattice todo revise --plan ${member.descriptor.plan_key} --input <revision.json>`,
4182
+ // 席の経路は軽い改訂(plan revise)。反映後のplanはreconciledになる。
4183
+ schema_command: reconciled ? null : 'lattice plan revise --schema --json',
4184
+ next_action: reconciled ? null : 'lattice plan revise --input <revision.json> --json',
4051
4185
  },
4052
4186
  };
4053
4187
  });
@@ -4078,6 +4212,21 @@ async function verify({ repoRoot, requestedPlanKey }) {
4078
4212
  return result;
4079
4213
  }
4080
4214
 
4215
+ // `todo verify`の人間向け1行。--jsonと同じresultから導く(verifyは不整合を例外で拒否するので、
4216
+ // ここへ届くのは検証が通った結果だけ。注意が要るのはsnapshot古さとcommit前の証拠)。
4217
+ function verifyVerdictLine(result) {
4218
+ const members = result.verified_members.map((member) => `${member.plan_key} ${member.reconciliation_state}${
4219
+ member.reconciliation_state === 'reconciled' ? '' : ', lifecycle not blocked'}`);
4220
+ const notes = [];
4221
+ if (result.snapshot_stale) notes.push('snapshot stale');
4222
+ if (result.uncommitted_evidence.length > 0) {
4223
+ notes.push(`${result.uncommitted_evidence.length} uncommitted evidence (commit it, then rerun)`);
4224
+ }
4225
+ const count = result.verified_members.length;
4226
+ return `todo verify: ${notes.length === 0 ? 'ok' : 'attention'}, ${count} plan${count === 1 ? '' : 's'} verified`
4227
+ + `${notes.map((note) => `, ${note}`).join('')} (${members.join('; ')})`;
4228
+ }
4229
+
4081
4230
  async function rebuildSnapshot({ repoRoot, planKey }) {
4082
4231
  // Read first so every typed validation failure happens before the rebuild writer is entered.
4083
4232
  const store = await readTodoStore({ repoRoot });
@@ -4175,6 +4324,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4175
4324
 
4176
4325
  const automatedStructureRealize = parseAutomatedStructureRealizeArgs(argv);
4177
4326
  let action = null;
4327
+ let plainVerify = false; // a19: `todo verify`は--jsonが無ければ1行の判定だけを返す
4178
4328
  if (argv.length === 2 && argv[0] === 'repair-eol' && argv[1] === '--json') {
4179
4329
  // 壊れたstoreを読めない時の入口なので、dashboard所有権pre-hookを通さない。
4180
4330
  action = (repoRoot) => repairStoreEol({ repoRoot });
@@ -4241,25 +4391,19 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4241
4391
  action = (repoRoot) => independenceMode({
4242
4392
  repoRoot, env, planKey: argv[3], mode: argv[5], reason: argv[7],
4243
4393
  });
4244
- } else if (argv.length === 12 && argv[0] === 'dependency' && argv[1] === 'connect'
4245
- && argv[2] === '--from-plan' && isTodoIdentifier(argv[3])
4246
- && argv[4] === '--from-task' && isTodoIdentifier(argv[5])
4247
- && argv[6] === '--to-plan' && isTodoIdentifier(argv[7])
4248
- && argv[8] === '--to-task' && isTodoIdentifier(argv[9])
4249
- && argv[10] === '--reason' && argv[11].length > 0) {
4394
+ } else if (argv[0] === 'dependency' && argv[1] === 'connect'
4395
+ && dependencyFlags(argv) !== null) {
4396
+ const flags = dependencyFlags(argv);
4250
4397
  action = (repoRoot) => dependencyConnect({
4251
- repoRoot, env, fromPlanKey: argv[3], fromTaskId: argv[5],
4252
- toPlanKey: argv[7], toTaskId: argv[9], reason: argv[11],
4398
+ repoRoot, env, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
4399
+ toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
4253
4400
  });
4254
- } else if (argv.length === 12 && argv[0] === 'dependency' && argv[1] === 'disconnect'
4255
- && argv[2] === '--from-plan' && isTodoIdentifier(argv[3])
4256
- && argv[4] === '--from-task' && isTodoIdentifier(argv[5])
4257
- && argv[6] === '--to-plan' && isTodoIdentifier(argv[7])
4258
- && argv[8] === '--to-task' && isTodoIdentifier(argv[9])
4259
- && argv[10] === '--reason' && argv[11].length > 0) {
4401
+ } else if (argv[0] === 'dependency' && argv[1] === 'disconnect'
4402
+ && dependencyFlags(argv) !== null) {
4403
+ const flags = dependencyFlags(argv);
4260
4404
  action = (repoRoot) => dependencyDisconnect({
4261
- repoRoot, env, fromPlanKey: argv[3], fromTaskId: argv[5],
4262
- toPlanKey: argv[7], toTaskId: argv[9], reason: argv[11],
4405
+ repoRoot, env, fromPlanKey: flags['from-plan'], fromTaskId: flags['from-task'],
4406
+ toPlanKey: flags['to-plan'], toTaskId: flags['to-task'], reason: flags.reason,
4263
4407
  });
4264
4408
  } else if (argv[0] === 'independence' && argv[1] === 'compile') {
4265
4409
  const flags = matchFlagCommand(argv, ['independence', 'compile'], {
@@ -4353,10 +4497,12 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4353
4497
  action = (repoRoot) => seamProposal({ repoRoot, requestedPlanKey: argv[2] });
4354
4498
  } else if ((argv.length === 1 && argv[0] === 'verify')
4355
4499
  || (argv.length === 2 && argv[0] === 'verify' && argv[1] === '--json')) {
4500
+ plainVerify = argv.length === 1;
4356
4501
  action = (repoRoot) => verify({ repoRoot, requestedPlanKey: null });
4357
4502
  } else if ((argv.length === 3 || argv.length === 4) && argv[0] === 'verify'
4358
4503
  && argv[1] === '--plan' && isTodoIdentifier(argv[2])
4359
4504
  && (argv.length === 3 || argv[3] === '--json')) {
4505
+ plainVerify = argv.length === 3;
4360
4506
  action = (repoRoot) => verify({ repoRoot, requestedPlanKey: argv[2] });
4361
4507
  } else if (argv.length === 4 && argv[0] === 'snapshot' && argv[1] === '--rebuild'
4362
4508
  && argv[2] === '--plan' && isTodoIdentifier(argv[3])) {
@@ -4465,11 +4611,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4465
4611
  const exceptPlanKeys = parseBaselineExceptFlags(argv.slice(4));
4466
4612
  action = (repoRoot) => phaseBaseline({ repoRoot, env, reason: argv[3], exceptPlanKeys });
4467
4613
  } else if (argv[0] === 'start') {
4468
- const flags = matchFlagCommand(argv, ['start'], {
4469
- known: ['plan', 'task', 'parallel-frontier', 'override-reason', 'serial-confirmed', 'rebind', 'reason'],
4470
- required: ['plan', 'task'],
4471
- booleans: ['parallel-frontier', 'serial-confirmed', 'rebind'],
4472
- });
4614
+ const flags = matchFlagCommand(argv, ['start'], TODO_FLAG_SPECS.start);
4473
4615
  if (flags !== null && flags.rebind === true) {
4474
4616
  if (isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
4475
4617
  && typeof flags.reason === 'string' && flags.reason.length > 0) {
@@ -4494,7 +4636,9 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4494
4636
  && (flags.evidence === undefined || hasEvidence)
4495
4637
  && (flags['test-result'] === undefined || isAuthoringPathToken(flags['test-result']))) {
4496
4638
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
4497
- kind: 'done', action: async () => {
4639
+ kind: 'done', notRecorded: ['message', 'evidence', 'test-result']
4640
+ .filter((name) => flags[name] !== undefined).map((name) => `--${name}`),
4641
+ action: async () => {
4498
4642
  let evidenceMessage = hasMessage ? flags.message : null;
4499
4643
  if (hasEvidence && hasMessage) {
4500
4644
  // The message is the record; it names the resolved file so nothing given is lost.
@@ -4518,18 +4662,14 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4518
4662
  }
4519
4663
  }
4520
4664
  if (action === null && argv[0] === 'retract') {
4521
- const flags = matchFlagCommand(argv, ['retract'], {
4522
- known: ['plan', 'task', 'reason'], required: ['plan', 'task', 'reason'],
4523
- });
4665
+ const flags = matchFlagCommand(argv, ['retract'], TODO_FLAG_SPECS.retract);
4524
4666
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
4525
4667
  action = (repoRoot) => retractStart({
4526
4668
  repoRoot, env, planKey: flags.plan, taskId: flags.task, reason: flags.reason,
4527
4669
  });
4528
4670
  }
4529
4671
  } else if (argv[0] === 'block') {
4530
- const flags = matchFlagCommand(argv, ['block'], {
4531
- known: ['plan', 'task', 'reason'], required: ['plan', 'task', 'reason'],
4532
- });
4672
+ const flags = matchFlagCommand(argv, ['block'], TODO_FLAG_SPECS.block);
4533
4673
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
4534
4674
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
4535
4675
  kind: 'block', action: () => mutate({
@@ -4539,18 +4679,14 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4539
4679
  }
4540
4680
  } else if (argv[0] === 'retire') {
4541
4681
  // 恒久除去(2026-08-29オーナー裁定)。planの形は変えず、状態遷移として工程を閉じる。
4542
- const flags = matchFlagCommand(argv, ['retire'], {
4543
- known: ['plan', 'task', 'reason'], required: ['plan', 'task', 'reason'],
4544
- });
4682
+ const flags = matchFlagCommand(argv, ['retire'], TODO_FLAG_SPECS.retire);
4545
4683
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
4546
4684
  action = (repoRoot) => retireTask({
4547
4685
  repoRoot, env, planKey: flags.plan, taskId: flags.task, reason: flags.reason,
4548
4686
  });
4549
4687
  }
4550
4688
  } else if (argv[0] === 'unblock') {
4551
- const flags = matchFlagCommand(argv, ['unblock'], {
4552
- known: ['plan', 'task'], required: ['plan', 'task'],
4553
- });
4689
+ const flags = matchFlagCommand(argv, ['unblock'], TODO_FLAG_SPECS.unblock);
4554
4690
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
4555
4691
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
4556
4692
  kind: 'unblock', action: () => mutate({
@@ -4570,10 +4706,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4570
4706
  });
4571
4707
  }
4572
4708
  } else if (argv[0] === 'reopen') {
4573
- const flags = matchFlagCommand(argv, ['reopen'], {
4574
- known: ['plan', 'task', 'reason', 'override-reason'],
4575
- required: ['plan', 'task', 'reason'],
4576
- });
4709
+ const flags = matchFlagCommand(argv, ['reopen'], TODO_FLAG_SPECS.reopen);
4577
4710
  if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
4578
4711
  && (flags['override-reason'] === undefined
4579
4712
  || (typeof flags['override-reason'] === 'string' && flags['override-reason'].length > 0))) {
@@ -4628,7 +4761,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4628
4761
  const result = atomicCommit
4629
4762
  ? await commitTodoStoreMutation({ repoRoot, argv, action, env })
4630
4763
  : await action(repoRoot);
4631
- if (result !== null) stdout.write(`${JSON.stringify(result)}\n`);
4764
+ if (result !== null) stdout.write(`${plainVerify ? verifyVerdictLine(result) : JSON.stringify(result)}\n`);
4632
4765
  return 0;
4633
4766
  } catch (error) {
4634
4767
  if (error instanceof TodoStoreError || (typeof error?.code === 'string'
@@ -510,10 +510,13 @@ function activeConflictEntry(value) {
510
510
  * 案内。単一正本のcatalogが返した形をそのまま載せる(ADR 0130 Decision 1・2)。
511
511
  * 面ごとに文言を組み立て直さないため、ここではshapeだけを検査する。
512
512
  */
513
+ // next_actionは実在コマンド(`lattice ...`)か'none'(a19)。
514
+ const commandOrNone = (value) => value === 'none' || (boundedText(value) && value.startsWith('lattice '));
515
+
513
516
  function guidanceEntry(value) {
514
517
  return exactRecord(value, ['code', 'message', 'next_action'])
515
518
  && TODO_INDEPENDENCE_GUIDANCE_CODES.includes(value.code)
516
- && boundedText(value.message) && isTodoIdentifier(value.next_action);
519
+ && boundedText(value.message) && commandOrNone(value.next_action);
517
520
  }
518
521
 
519
522
  /**