@quolu/lattice 0.85.5 → 0.86.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/bin/lattice.mjs CHANGED
@@ -140,7 +140,7 @@ if (help !== null) {
140
140
  } else if (args[0] === 'plan' && args[1] === 'revise') {
141
141
  const { matchFlagCommand } = await import('../src/todo-authoring-input.mjs');
142
142
  const spec = {
143
- known: ['input', 'dry-run', 'json'], required: ['input'], booleans: ['dry-run', 'json'],
143
+ known: ['plan', 'input', 'dry-run', 'json'], required: ['input'], booleans: ['dry-run', 'json'],
144
144
  };
145
145
  const flags = matchFlagCommand(args, ['plan', 'revise'], spec);
146
146
  if (flags === null || flags.json !== true) {
@@ -150,7 +150,7 @@ if (help !== null) {
150
150
  const { runPlanRevise } = await import('../src/plan-revise.mjs');
151
151
  const { projectCliFailure } = await import('../src/project-cli.mjs');
152
152
  try {
153
- process.exitCode = await runPlanRevise({ cwd: process.cwd(), inputRef: flags.input,
153
+ process.exitCode = await runPlanRevise({ cwd: process.cwd(), inputRef: flags.input, planKey: flags.plan,
154
154
  dryRun: flags['dry-run'] === true, stdout: process.stdout, env: process.env });
155
155
  } catch (error) {
156
156
  process.exitCode = projectCliFailure(process.stderr, error, { command: 'revise', flags });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quolu/lattice",
3
- "version": "0.85.5",
3
+ "version": "0.86.0",
4
4
  "description": "Schedulability compiler for multi-agent development: observe real code boundaries, refactor the conflicting seam, recompile the plan for parallel execution",
5
5
  "author": {
6
6
  "name": "Quo / クオ at kitepon.dev",
package/src/cli-help.mjs CHANGED
@@ -31,7 +31,8 @@ Commands:
31
31
  create --schema-version <1|2|3|4|5> --json
32
32
  create --template --json # 作者が書くkeyだけの最小のv5入力(そのままplan createが受理する)
33
33
  backchain --schema --json # 最終成果から必要な機能を逆算する入力契約
34
- revise --input <file> [--dry-run] [--json]
34
+ revise [--plan <key>] --input <file> [--dry-run] [--json]
35
+ # --planは任意。入力にplan_keyが無ければ補い、違えばplan_revise_plan_key_mismatchで断る
35
36
  # 改訂後の計画の全体を、plan createと同じ形で渡す(plan create --template --jsonから始められる)。
36
37
  # 継続方針を自分で書くなら {"schema":"lattice.plan_revise_input.v1","desired":<計画>,"continuity":[...]}
37
38
  revise --schema --json
@@ -121,6 +122,10 @@ Write commands:
121
122
  block --plan <key> --task <id> --reason <text>
122
123
  unblock --plan <key> --task <id>
123
124
  retire --plan <key> --task <id> --reason <text>
125
+ # 1件を閉じる。planは書き直さず、他のtaskの状態とjournalはそのまま
126
+ add --plan <key> --task <id> --title <text> [--phase <id>] [--lane <lane>] [--done-condition <text>]
127
+ [--design-memo <text>] [--after <id>[,<id>...]] [--before <id>[,<id>...]] [--reason <text>]
128
+ # 1件を足す(a39)。planの全体を書かずに軽量改訂で新plan_versionを作り、他のtaskはcarry
124
129
  done --plan <key> --task <id> [--evidence <file>] [--message <text>]
125
130
  # taskを閉じる。どちらも省略でき、両方なら本文がfileを名指す(A58)。--evidenceはdescriptor JSONでも証拠本文でもよい。repo内なら絶対path可。
126
131
  # 既にdoneなら何も足さずunchanged:trueで成功する(a12)
@@ -253,7 +258,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
253
258
  'plan show': 'plan show <plan_key> --json',
254
259
  'plan scope-review': 'plan scope-review --plan-input <plan-create-or-extraction.json> --review <scope-review.json> --json | --schema --json',
255
260
  'plan backchain': 'plan backchain --input <file> [--dry-run] [--json] | --schema --json',
256
- 'plan revise': 'plan revise --input <file> [--dry-run] [--json] | --schema --json\n\n'
261
+ 'plan revise': 'plan revise [--plan <key>] --input <file> [--dry-run] [--json] | --schema --json\n\n'
257
262
  + '--input: the whole desired plan in the same shape as `plan create` (start from `plan create --template --json`),\n'
258
263
  + 'or {"schema":"lattice.plan_revise_input.v1","desired":<that plan>,"continuity":[{task_id, policy: carry|reset|retire, reason}]}.\n'
259
264
  + 'Without continuity the machine computes carry/reset/retire. A plan_key with no active plan is made with `plan create`.',
@@ -325,6 +330,8 @@ const SUBCOMMAND_USAGE = Object.freeze({
325
330
  'todo block': 'todo block --plan <key> --task <id> --reason <text>',
326
331
  'todo unblock': 'todo unblock --plan <key> --task <id>',
327
332
  'todo retire': 'todo retire --plan <key> --task <id> --reason <text>',
333
+ 'todo add': 'todo add --plan <key> --task <id> --title <text> [--phase <id>] [--lane <lane>] [--done-condition <text>]'
334
+ + ' [--design-memo <text>] [--after <id>[,<id>...]] [--before <id>[,<id>...]] [--reason <text>]',
328
335
  'todo done': 'todo done --plan <key> --task <id> [--evidence <file>] [--message <text>] [--test-result <markdown-file>]',
329
336
  'todo reopen': 'todo reopen --plan <key> --task <id> --reason <text> [--override-reason <text>]',
330
337
  'todo evidence': 'todo evidence promote --plan <key> --task <id> --evidence <file>',
@@ -412,14 +412,31 @@ export async function applyPlanRevision({
412
412
  return result;
413
413
  }
414
414
 
415
- export async function runPlanRevise({ cwd, inputRef, stdout, dryRun = false, env = process.env }) {
415
+ /** a39: `--plan` names the plan as every todo write does; it fills a missing plan_key and must match a written one. */
416
+ export function applyPlanFlag(input, planKey) {
417
+ if (planKey === undefined || !isRecord(input)) return input;
418
+ const wrapped = !isBareCreateInput(input) && isRecord(input.desired);
419
+ const target = wrapped ? input.desired : input;
420
+ if (target.plan_key === undefined) return wrapped ? { ...input, desired: { ...target, plan_key: planKey } }
421
+ : { ...input, plan_key: planKey };
422
+ if (target.plan_key !== planKey) {
423
+ fail('plan_revise_plan_key_mismatch', wrapped ? '/desired/plan_key' : '/plan_key', {
424
+ expected: planKey, actual: target.plan_key,
425
+ next_action: `--plan is "${planKey}" but the input revises "${target.plan_key}": make them the same, or drop --plan (the input's plan_key names the plan).`,
426
+ });
427
+ }
428
+ return input;
429
+ }
430
+
431
+ export async function runPlanRevise({ cwd, inputRef, planKey, stdout, dryRun = false, env = process.env }) {
416
432
  let repoRoot;
417
433
  try {
418
434
  repoRoot = path.resolve(gitSync(['rev-parse', '--show-toplevel'], {
419
435
  cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
420
436
  }).replace(/\r?\n$/u, ''));
421
437
  } catch { throw new TodoStoreError('REPO_UNRESOLVED', 'git_toplevel_unresolved'); }
422
- const input = await readAuthoringJsonFile(repoRoot, inputRef, { invalidCode: 'INPUT_INVALID' });
438
+ const input = applyPlanFlag(
439
+ await readAuthoringJsonFile(repoRoot, inputRef, { invalidCode: 'INPUT_INVALID' }), planKey);
423
440
  const result = await applyPlanRevision({ repoRoot, input, env, dryRun });
424
441
  stdout.write(`${JSON.stringify(result)}\n`);
425
442
  return 0;
@@ -1002,6 +1002,8 @@ export async function runPlanShow({ cwd, planKey, stdout }) {
1002
1002
  phase_id: phaseInput ? task.phase_id : null,
1003
1003
  state: stateByTaskId.get(task.task_id).status,
1004
1004
  done_condition: task.done_condition ?? null,
1005
+ // a39: with design_memo, plan show holds every authored field a plan revise input needs.
1006
+ design_memo: task.design_memo ?? null,
1005
1007
  depends_on_count: dependsOnCount.get(task.task_id) ?? 0,
1006
1008
  }));
1007
1009
 
package/src/todo-cli.mjs CHANGED
@@ -292,7 +292,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
292
292
  'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
293
293
  'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
294
294
  'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
295
- 'retract', 'dependency',
295
+ 'retract', 'dependency', 'add',
296
296
  ]);
297
297
 
298
298
  function typedArgumentFailure(stderr, code, message, detail, context = {}) {
@@ -330,6 +330,10 @@ const TODO_FLAG_SPECS = Object.freeze({
330
330
  unblock: Object.freeze({ known: ['plan', 'task'], required: ['plan', 'task'] }),
331
331
  reopen: Object.freeze({ known: ['plan', 'task', 'reason', 'override-reason'], required: ['plan', 'task', 'reason'] }),
332
332
  'dependency connect': DEPENDENCY_FLAG_SPEC,
333
+ add: Object.freeze({
334
+ known: ['plan', 'task', 'title', 'phase', 'lane', 'done-condition', 'design-memo', 'after', 'before', 'reason'],
335
+ required: ['plan', 'task', 'title'],
336
+ }),
333
337
  'dependency disconnect': DEPENDENCY_FLAG_SPEC,
334
338
  // a23: the remaining writes whose refusal pointed only at --help.
335
339
  'phase review': PHASE_REASON_FLAG_SPEC,
@@ -1653,6 +1657,61 @@ async function dependencyRevision({
1653
1657
  return result;
1654
1658
  }
1655
1659
 
1660
+ /**
1661
+ * a39: 1件のtaskを、planを書き直さずに足す。dependency connectと同じ軽量改訂の道で、
1662
+ * 現行planから作ったdesiredへtaskと辺(after→新task、新task→before)を足して適用する。
1663
+ */
1664
+ async function addTask({ repoRoot, env, planKey, flags }) {
1665
+ const { applyPlanRevision, desiredFromPlan } = await import('./plan-revise.mjs');
1666
+ const store = await readTodoStore({ repoRoot });
1667
+ const member = store.members.find(({ plan }) => plan.plan_key === planKey);
1668
+ if (member === undefined) {
1669
+ throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, { plan_key: planKey });
1670
+ }
1671
+ const taskId = flags.task;
1672
+ const known = new Set(member.plan.tasks.map(({ task_id: id }) => id));
1673
+ if (known.has(taskId)) {
1674
+ throw new TodoStoreError('INPUT_INVALID', 'todo_add_task_exists', undefined, {
1675
+ plan_key: planKey, task_id: taskId, pointer: '--task',
1676
+ next_action: `${planKey}/${taskId} already exists: pick an unused --task id (see \`lattice plan show ${planKey} --json\`), or change the task with \`lattice plan revise --input <file>\`.`,
1677
+ });
1678
+ }
1679
+ const ids = (value) => (typeof value === 'string' ? value.split(',').map((id) => id.trim()).filter(Boolean) : []);
1680
+ const after = ids(flags.after);
1681
+ const before = ids(flags.before);
1682
+ for (const id of [...after, ...before]) {
1683
+ if (!known.has(id)) {
1684
+ throw new TodoStoreError('DEPENDENCY_INVALID', 'dependency_task_not_found', undefined, {
1685
+ ref: dependencyRef(store, planKey, id),
1686
+ });
1687
+ }
1688
+ }
1689
+ const task = { task_id: taskId, title: flags.title };
1690
+ for (const [flag, field] of [['phase', 'phase_id'], ['lane', 'lane'],
1691
+ ['done-condition', 'done_condition'], ['design-memo', 'design_memo']]) {
1692
+ if (typeof flags[flag] === 'string') task[field] = flags[flag];
1693
+ }
1694
+ const desired = desiredFromPlan(member.plan, { env });
1695
+ const ref = (id) => dependencyRef(store, planKey, id);
1696
+ desired.tasks = [...desired.tasks, task];
1697
+ desired.hard_dependencies = [...desired.hard_dependencies,
1698
+ ...after.map((id) => ({ from: ref(id), to: ref(taskId) })),
1699
+ ...before.map((id) => ({ from: ref(taskId), to: ref(id) }))];
1700
+ const reason = typeof flags.reason === 'string' ? flags.reason : null;
1701
+ const applied = await applyPlanRevision({
1702
+ repoRoot, env, input: { schema: 'lattice.plan_revise_input.v1', desired },
1703
+ notes: [{ task_id: taskId, body: `todo add ${taskId}${reason === null ? '' : `: ${reason}`}` }],
1704
+ });
1705
+ const result = {
1706
+ schema: 'lattice.todo_task_add_result.v1', project_id: store.project_id, plan_key: planKey,
1707
+ task_id: taskId, after, before, reason, actor: desired.actor,
1708
+ plan_version: applied.plan_version, revision_digest: applied.revision?.revision_digest ?? null,
1709
+ rebound_task_ids: applied.rebound_task_ids, result_digest: '',
1710
+ };
1711
+ result.result_digest = todoSelfDigest(result, 'result_digest');
1712
+ return result;
1713
+ }
1714
+
1656
1715
  const samePlanEdge = (member, fromTaskId, toTaskId) => member.plan.hard_dependencies.some((edge) => (
1657
1716
  edge.from.task_id === fromTaskId && edge.to.task_id === toTaskId));
1658
1717
 
@@ -4935,6 +4994,11 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
4935
4994
  kind: 'block', payload: { reason: flags.reason }, evidenceRef: null,
4936
4995
  }) });
4937
4996
  }
4997
+ } else if (argv[0] === 'add') {
4998
+ const flags = matchFlagCommand(argv, ['add'], TODO_FLAG_SPECS.add);
4999
+ if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)) {
5000
+ action = (repoRoot) => addTask({ repoRoot, env, planKey: flags.plan, flags });
5001
+ }
4938
5002
  } else if (argv[0] === 'retire') {
4939
5003
  // 恒久除去(2026-08-29オーナー裁定)。planの形は変えず、状態遷移として工程を閉じる。
4940
5004
  const flags = matchFlagCommand(argv, ['retire'], TODO_FLAG_SPECS.retire);