@quolu/lattice 0.87.0 → 0.88.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.
@@ -2,8 +2,8 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://github.com/kitepon/Lattice/blob/main/docs/schemas/lattice.plan_create_input.v4.schema.json",
4
4
  "title": "lattice.plan_create_input.v4",
5
- "description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is recorded as `NO_PLAN`. After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. actor, recorded_at, input_digest and tasks[].design_memo may be omitted: the machine fills the seat actor, the current time and NO_PLAN, recomputes input_digest and sorts every list into canonical order.",
6
- "$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank becomes NO_PLAN), and input_digest (recomputed). tasks, hard_dependencies, joins, phases and phase_accept_dependencies are sorted into canonical order and exact duplicates dropped before validation.",
5
+ "description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is refused at its pointer (write `NO_PLAN` yourself when you have no plan). After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. actor, recorded_at and input_digest may be omitted: the machine fills the seat actor and the current time, recomputes input_digest and sorts every list into canonical order.",
6
+ "$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank is refused; NO_PLAN only when written), and input_digest (recomputed). tasks, hard_dependencies, joins, phases and phase_accept_dependencies are sorted into canonical order and exact duplicates dropped before validation.",
7
7
  "type": "object",
8
8
  "additionalProperties": false,
9
9
  "required": [
@@ -151,7 +151,8 @@
151
151
  "narrative_anchor",
152
152
  "compile_binding",
153
153
  "parent_task_id",
154
- "phase_id"
154
+ "phase_id",
155
+ "design_memo"
155
156
  ],
156
157
  "properties": {
157
158
  "task_id": {
@@ -2,8 +2,8 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://github.com/kitepon/Lattice/blob/main/docs/schemas/lattice.plan_create_input.v5.schema.json",
4
4
  "title": "lattice.plan_create_input.v5",
5
- "description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is recorded as `NO_PLAN`. After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. v5 adds the per-task authored `done_condition`: plain text (or null when the author states none) that Lattice records and shows but never evaluates, never assigns and never records as done. Builds lattice.todo_plan.v8. The author writes intent: ids, titles, phases and edges (see `lattice plan create --template --json`). Every key whose value is constant or null may be omitted and the machine fills it: schema (this version), project_id (the store's project id; with no store yet, the repository directory name as a lower-case identifier; a different value is refused as project_id_mismatch), plan_version (v1; `lattice plan revise` uses the active plan's), actor (the seat actor), recorded_at (the current time; an ISO-8601 date-time with an explicit zone is normalised to UTC milliseconds), input_digest (recomputed), tasks[].design_memo (NO_PLAN), tasks[].lane (main), tasks[].narrative_ref, narrative_anchor, compile_binding, parent_task_id and done_condition (null), phases[].gate_policy (heavy), phases[].predecessor_phase_ids ([]), phases[].required_evidence_slots ([\"acceptance\"]), hard_dependencies, joins and phase_accept_dependencies ([]), and project_id/plan_key of an edge reference (this input's own). Every list is sorted into canonical order. A refusal lists every problem at once in detail.problems. Edge direction: from is the prerequisite; to starts after from is done.",
6
- "$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank becomes NO_PLAN), and input_digest (recomputed). v5 additionally accepts hard_dependencies, joins, each joins[].after, phase_accept_dependencies, phases, phases[].predecessor_phase_ids and phases[].required_evidence_slots in any order or with exact duplicates: they are sorted into canonical order and de-duplicated before validation. tasks are sorted by task_id. Entries with the same key but different content are still refused.",
5
+ "description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is refused at its pointer (write `NO_PLAN` yourself when you have no plan). After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. v5 adds the per-task authored `done_condition`: plain text (or null when the author states none) that Lattice records and shows but never evaluates, never assigns and never records as done. Builds lattice.todo_plan.v8. The author writes intent: ids, titles, phases and edges (see `lattice plan create --template --json`). Every key whose value is constant or null may be omitted and the machine fills it: schema (this version), project_id (the store's project id; with no store yet, the repository directory name as a lower-case identifier; a different value is refused as project_id_mismatch), plan_version (v1; `lattice plan revise` uses the active plan's), actor (the seat actor), recorded_at (the current time; an ISO-8601 date-time with an explicit zone is normalised to UTC milliseconds), input_digest (recomputed), tasks[].lane (main), tasks[].narrative_ref, narrative_anchor, compile_binding, parent_task_id and done_condition (null), phases[].gate_policy (heavy), phases[].predecessor_phase_ids ([]), phases[].required_evidence_slots ([\"acceptance\"]), hard_dependencies, joins and phase_accept_dependencies ([]), and project_id/plan_key of an edge reference (this input's own). Every list is sorted into canonical order. A refusal lists every problem at once in detail.problems. Edge direction: from is the prerequisite; to starts after from is done.",
6
+ "$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank is refused; NO_PLAN only when written), and input_digest (recomputed). v5 additionally accepts hard_dependencies, joins, each joins[].after, phase_accept_dependencies, phases, phases[].predecessor_phase_ids and phases[].required_evidence_slots in any order or with exact duplicates: they are sorted into canonical order and de-duplicated before validation. tasks are sorted by task_id. Entries with the same key but different content are still refused.",
7
7
  "type": "object",
8
8
  "additionalProperties": false,
9
9
  "required": [
@@ -139,7 +139,8 @@
139
139
  "required": [
140
140
  "task_id",
141
141
  "title",
142
- "phase_id"
142
+ "phase_id",
143
+ "design_memo"
143
144
  ],
144
145
  "properties": {
145
146
  "task_id": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quolu/lattice",
3
- "version": "0.87.0",
3
+ "version": "0.88.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
@@ -29,7 +29,7 @@ Commands:
29
29
  # 結果へdispatch_shapeを載せる。--serialization-reviewedは互換のため受理するだけで門ではない
30
30
  create --schema --json # 既定は最新版(v5)のJSON Schemaを返す
31
31
  create --schema-version <1|2|3|4|5> --json
32
- create --template --json # 作者が書くkeyだけの最小のv5入力(そのままplan createが受理する)
32
+ create --template --json # 作者が書くkeyだけの最小のv5入力(各taskの設計メモを書けばplan createが受理する)
33
33
  backchain --schema --json # 最終成果から必要な機能を逆算する入力契約
34
34
  revise [--plan <key>] --input <file> [--dry-run] [--json]
35
35
  # --planは任意。入力にplan_keyが無ければ補い、違えばplan_revise_plan_key_mismatchで断る
@@ -137,7 +137,8 @@ Write commands:
137
137
  dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
138
138
  dependency disconnect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
139
139
  # 開発中に発見した依存を明示接続する。同一plan内の辺はplan本体を軽い改訂で書き換え(plan_versionが変わる)、plan跨ぎは台帳に積む。依存の自動推定は行わない
140
- independence mode --plan <key> --set <witness|conversation> --reason <text>
140
+ independence mode --plan <key> --set <witness|conversation|enforced> --reason <text>
141
+ # enforced = witness+未宣言・古い宣言・衝突・参照なしdone・heavy段階の監査なし閉じを止める(ADR 0200)
141
142
  # このplanの調整方式(witness検証で並列するか、会話で調整するか)を記録する
142
143
  independence compile --plan <key> --input <file> # witness setとsensorから並列可否を記録する
143
144
  independence compile --schema --json # compileが読むwitness set(lattice.todo_witness_set.v5)のJSON Schema
@@ -302,11 +303,11 @@ const SUBCOMMAND_USAGE = Object.freeze({
302
303
  'todo display': 'todo display read [--json] | source [--json] # host表示用の読取。不整合でも断らずstateで返す',
303
304
  'todo display read': 'todo display read [--json] # lattice.todo_display_read_result.v1(state: verified|unverified|last_verified|unavailable)',
304
305
  'todo display source': 'todo display source [--json] # lattice.todo_store_display_source.v1(安い変更検知。変わった時だけreadする)',
305
- 'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation> --reason <text>'
306
+ 'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation|enforced> --reason <text>'
306
307
  + ' | compile --plan <key> --input <file> | compile --schema --json | witness migrate --plan <key>'
307
308
  + ' | witness scaffold --template --plan <key> [--json] | witness scaffold --schema --json | witness scaffold --plan <key> --input <draft>'
308
309
  + ' | witness declare --plan <key> --task <id> [--owns <path>[,<path>...]] [--reads ...] [--writes ...]',
309
- 'todo independence mode': 'todo independence mode --plan <key> --set <witness|conversation> --reason <text>',
310
+ 'todo independence mode': 'todo independence mode --plan <key> --set <witness|conversation|enforced> --reason <text>',
310
311
  'todo structure': 'todo structure --schema --json | [--plan <key>] --json | input --plan <key> --input <file> [--dry-run --json] | compile --plan <key> --input <file> | realize --plan <key> --task <id> (--planned|--realized <actual-structure.json>) [--commit <HEAD|sha>]... | realize --plan <key> --task <id> --input <full-realization.json> | finalize --plan <key> --json',
311
312
  'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
312
313
  'todo seam-proposal': 'todo seam-proposal [--plan <key>] [--json] | compile --plan <key>',
@@ -325,7 +325,8 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
325
325
  reason: 'structure_finalization_pending' }
326
326
  : todo.audit_pending.length > 0
327
327
  ? { command: todo.audit_pending[0].phase_status === 'gate_ready'
328
- ? `lattice todo phase close-unaudited --plan ${todo.audit_pending[0].plan_key} --phase ${todo.audit_pending[0].phase_id} --reason <text>`
328
+ // close-unaudited when offered; an enforced heavy phase offers only review (ADR 0200).
329
+ ? todo.audit_pending[0].next_commands.at(-1)
329
330
  : `lattice todo phase status --plan ${todo.audit_pending[0].plan_key}`,
330
331
  reason: 'audit_pending' }
331
332
  : { command: 'lattice todo status', reason: 'no_ready_task' };
@@ -922,7 +923,8 @@ export async function runPlanCreateSchema({ stdout, version = 5 }) {
922
923
  * `plan create --template --json`(a11・a17)。作者が書くkeyだけの最小のv5入力を出す。
923
924
  * 機械が決めるkey(project_id・plan_version・actor・recorded_at・input_digest・定数のkey・辺のproject_id/plan_key)は載せない。
924
925
  * plan_keyだけは、git repo内ならrepo root名から導いた値、repo外なら'main'。
925
- * 決定的で、storeを読まない。id・題名を書き換えれば`plan create`がそのまま受理する。
926
+ * 決定的で、storeを読まない。id・題名を書き換え、各taskの設計メモを書けば`plan create`が受理する。
927
+ * 設計メモは空のまま出す: Latticeは自分でNO_PLANを書かず、写しただけの入力は欄名と促しで断られる。
926
928
  */
927
929
  export const PLAN_CREATE_TEMPLATE = Object.freeze({
928
930
  schema: DONE_CONDITION_CREATE_INPUT_SCHEMA,
@@ -932,9 +934,10 @@ export const PLAN_CREATE_TEMPLATE = Object.freeze({
932
934
  { phase_id: 'p2', title: 'Second phase' },
933
935
  ],
934
936
  tasks: [
935
- { task_id: 't1', title: 'First task', phase_id: 'p1', design_memo: 'NO_PLAN' },
936
- { task_id: 't2', title: 'Second task', phase_id: 'p1' },
937
- { task_id: 't3', title: 'Third task', phase_id: 'p2' },
937
+ // The author writes each memo (or NO_PLAN); Lattice never writes one (memo-no-fabrication).
938
+ { task_id: 't1', title: 'First task', phase_id: 'p1', design_memo: '' },
939
+ { task_id: 't2', title: 'Second task', phase_id: 'p1', design_memo: '' },
940
+ { task_id: 't3', title: 'Third task', phase_id: 'p2', design_memo: '' },
938
941
  ],
939
942
  // from is the prerequisite; to starts after from is done.
940
943
  hard_dependencies: [{ from: { task_id: 't1' }, to: { task_id: 't3' } }],
@@ -39,15 +39,17 @@ export function isAuditPendingPhaseStatus(status) {
39
39
  * 呼ぶ前に`isAuditPendingPhaseStatus`で絞ること。
40
40
  *
41
41
  * `slotCount`は必須evidence slotの数。1つなら`--evidence`で足り、複数なら`--input`が要る。
42
+ * `auditRequired`(`phaseAuditRequired`)ならclose-unauditedを案内しない(ADR 0200 gate 5が断る)。
42
43
  *
43
44
  * @returns {string[]} 実行可能なコマンド行(1つ以上)
44
45
  */
45
- export function auditPendingNextCommands(planKey, phaseId, status, slotCount = 1) {
46
+ export function auditPendingNextCommands(planKey, phaseId, status, slotCount = 1, { auditRequired = false } = {}) {
46
47
  const target = `--plan ${planKey} --phase ${phaseId}`;
47
48
  if (status === 'gate_ready') {
48
49
  return [
49
50
  `lattice todo phase review ${target} --reason <text>`,
50
- `lattice todo phase close-unaudited ${target} --reason <text>`,
51
+ // ADR 0200 gate 5 refuses close-unaudited here, so it is not offered.
52
+ ...(auditRequired ? [] : [`lattice todo phase close-unaudited ${target} --reason <text>`]),
51
53
  ];
52
54
  }
53
55
  if (status === 'reviewing') {
@@ -65,6 +67,11 @@ export function auditPendingNextCommands(planKey, phaseId, status, slotCount = 1
65
67
  throw error;
66
68
  }
67
69
 
70
+ /** ADR 0200 gate 5: an `enforced` plan keeps the audit its author required for a `heavy` phase. */
71
+ export function phaseAuditRequired(member, gatePolicy) {
72
+ return member?.coordination?.mode === 'enforced' && gatePolicy === 'heavy';
73
+ }
74
+
68
75
  /**
69
76
  * store read model(`lattice.todo_store_read.v1`)の中の監査待ちPhaseを列挙する。
70
77
  *
@@ -197,8 +197,9 @@ export function repairAuthoringArtifact(value) {
197
197
 
198
198
  /**
199
199
  * 機械が出せる事実を作成入力へ補う(u03p A81/A80)。AIは意図(tasks・依存)だけを書く:
200
- * actorは席の解決値、recorded_atは現在時刻、v4/v5の空の設計メモはNO_PLAN、配列は正準順、
201
- * input_digestは再計算。作成入力でない値と、レコードでない値はそのまま返す。
200
+ * actorは席の解決値、recorded_atは現在時刻、配列は正準順、
201
+ * input_digestは再計算。欠けた設計メモは補わず、validatorが欄名で断る(ADR 0181 8)。
202
+ * 作成入力でない値と、レコードでない値はそのまま返す。
202
203
  */
203
204
  export const DEFAULT_EVIDENCE_SLOT = 'acceptance';
204
205
  export const DEFAULT_CREATE_INPUT_SCHEMA = 'lattice.plan_create_input.v5';
@@ -279,10 +280,6 @@ export function completeCreateInput(value, { env, now, projectId, planVersion })
279
280
  if (next.schema === DEFAULT_CREATE_INPUT_SCHEMA && filled.done_condition === undefined) {
280
281
  filled.done_condition = null;
281
282
  }
282
- if (memoInput && (absent(filled.design_memo)
283
- || (typeof filled.design_memo === 'string' && filled.design_memo.trim() === ''))) {
284
- filled.design_memo = 'NO_PLAN';
285
- }
286
283
  return filled;
287
284
  });
288
285
  if (phaseInput) {
package/src/todo-cli.mjs CHANGED
@@ -3,7 +3,7 @@ import { cliCommandKind } from './cli-command-kind.mjs';
3
3
  import { cliFailureClass } from './cli-failure-class.mjs';
4
4
  import { FLAG_PLACEHOLDER, publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
5
5
  import { readTaskBackchainContext } from './plan-backchain.mjs';
6
- import { auditPendingNextCommands } from './todo-audit-pending.mjs';
6
+ import { auditPendingNextCommands, phaseAuditRequired } from './todo-audit-pending.mjs';
7
7
  import { gitSync } from './git-process.mjs';
8
8
  import { createHash } from 'node:crypto';
9
9
  import {
@@ -858,10 +858,13 @@ async function readStructureSetDraft(repoRoot, inputRef) {
858
858
  * gate_readyの次の一歩を1行で言う(ADR 0148裁定8・a22)。全taskが終わった席には、軽い出口
859
859
  * (監査せず閉じるclose-unaudited)を先に、監査する道(review→accept)を後に示す。経緯の説明は載せない。
860
860
  */
861
- function auditGateGuidance(planKey, phaseId) {
861
+ function auditGateGuidance(planKey, phaseId, auditRequired = false) {
862
862
  const target = `--plan ${planKey} --phase ${phaseId}`;
863
+ const audit = `lattice todo phase review ${target} --reason <text> → accept ${target} --evidence <file>`;
864
+ // ADR 0200 gate 5: an enforced plan's heavy phase refuses close-unaudited, so only the audit is offered.
865
+ if (auditRequired) return `全ToDoがdone。このplanはenforcedでheavyの段階なので監査する: ${audit}`;
863
866
  return `全ToDoがdone。監査せず閉じるなら: lattice todo phase close-unaudited ${target} --reason <text>`
864
- + `(監査するなら lattice todo phase review ${target} --reason <text> → accept ${target} --evidence <file>)`;
867
+ + `(監査するなら ${audit})`;
865
868
  }
866
869
 
867
870
  /** a36: reviewing and rejected phases say their next command too (the same lines as audit_pending). */
@@ -1389,6 +1392,9 @@ async function startTask({
1389
1392
  const advisory = await startAdvisory({
1390
1393
  repoRoot, store, projection, planKey, taskId: resolvedTaskId,
1391
1394
  });
1395
+ if (member.coordination?.mode === 'enforced') {
1396
+ enforcedStartGate({ advisory, planKey, taskId: resolvedTaskId, overrideReason });
1397
+ }
1392
1398
  const structureContext = await startStructureContext({
1393
1399
  repoRoot, store, planKey, taskId: resolvedTaskId,
1394
1400
  });
@@ -1408,6 +1414,47 @@ async function startTask({
1408
1414
  structureContext, featureContext });
1409
1415
  }
1410
1416
 
1417
+ const declareCommand = (planKey, taskId) => `lattice todo independence witness declare --plan ${planKey} --task ${taskId}`
1418
+ + ' --owns <path>[,<path>...] [--reads <path>,...] [--writes <path>,...]';
1419
+
1420
+ /** ADR 0200 gates 1–3: an enforced plan does not start undeclared, stale or conflicting work. Reads the advisory only. */
1421
+ function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
1422
+ const unknown = (kind) => advisory.self_unknowns.some((entry) => entry.kind === kind);
1423
+ const refuse = (reason, detail) => {
1424
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', reason, undefined, { plan_key: planKey, task_id: taskId, ...detail });
1425
+ };
1426
+ if (advisory.coverage === 'missing' || unknown('witness_missing')) {
1427
+ refuse('enforced_witness_undeclared', { next_action: `Declare the files ${taskId} touches, then start again: \`${declareCommand(planKey, taskId)}\`.` });
1428
+ }
1429
+ if (advisory.drift_intersecting === true || unknown('record_stale')) {
1430
+ refuse('enforced_witness_stale', { next_action: `Main changed under ${taskId}'s declared files since the check: declare them again (it recompiles), then start: \`${declareCommand(planKey, taskId)}\`.` });
1431
+ }
1432
+ if (advisory.conflicts_with_active.length > 0 && overrideReason === null) {
1433
+ const active = advisory.conflicts_with_active.map(({ active_task_id: id }) => id);
1434
+ refuse('enforced_conflict_with_active', { conflicts_with_active: advisory.conflicts_with_active,
1435
+ 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>\`,`
1436
+ + ` or start anyway with \`lattice todo start --plan ${planKey} --task ${taskId} --override-reason <text>\` (the reason is recorded).` });
1437
+ }
1438
+ }
1439
+
1440
+ /** ADR 0200 gate 4: done on an enforced plan names the change: evidence, an http(s) URL, or a commit in HEAD. */
1441
+ async function enforcedDoneGate({ repoRoot, planKey, flags }) {
1442
+ const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
1443
+ if (member?.coordination?.mode !== 'enforced' || flags.evidence !== undefined) return;
1444
+ const message = typeof flags.message === 'string' ? flags.message : '';
1445
+ if (/https?:\/\/\S+/u.test(message)) return;
1446
+ for (const token of message.match(/\b[0-9a-f]{7,40}\b/gu) ?? []) {
1447
+ try {
1448
+ gitSync(['merge-base', '--is-ancestor', token, 'HEAD'], { cwd: repoRoot, stdio: 'ignore' });
1449
+ return;
1450
+ } catch { /* not a commit in HEAD; try the next token */ }
1451
+ }
1452
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_done_reference_missing', undefined, {
1453
+ plan_key: planKey, task_id: flags.task,
1454
+ next_action: `Name the adopted change: \`lattice todo done --plan ${planKey} --task ${flags.task} --message "<PR URL or merged commit sha>"\` (a sha must be in HEAD).`,
1455
+ });
1456
+ }
1457
+
1411
1458
  // plan改訂でcarryされたin-progress ToDoの再束縛入口(ADR 0191)。task状態・開始時刻は
1412
1459
  // 変えず、現plan_version・現actorのstart束縛だけをjournalへ積む。runtime intakeは
1413
1460
  // literal startだけを束縛に使いcarryを推定しないため、改訂を跨いだ進行中工程の
@@ -1567,6 +1614,19 @@ async function phaseDecisionFromEvidence({ repoRoot, env, planKey, phaseId, outc
1567
1614
  }
1568
1615
 
1569
1616
  async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload }) {
1617
+ if (kind === 'phase_close_unaudited') {
1618
+ // ADR 0200 gate 5: an enforced plan keeps the audit its author required for a heavy phase.
1619
+ const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
1620
+ const phase = member === undefined ? undefined
1621
+ : todoPhaseDefinitions(member.plan).find(({ phase_id: id }) => id === phaseId);
1622
+ if (phaseAuditRequired(member, phase?.gate_policy)) {
1623
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_heavy_phase_unaudited', undefined, {
1624
+ plan_key: planKey, phase_id: phaseId,
1625
+ next_action: `Audit it: \`lattice todo phase review --plan ${planKey} --phase ${phaseId} --reason <text>\` then \`lattice todo phase accept --plan ${planKey} --phase ${phaseId} --evidence <file>\`;`
1626
+ + ' or revise the phase to a non-heavy gate_policy with `lattice plan revise` (recorded).',
1627
+ });
1628
+ }
1629
+ }
1570
1630
  const { event, snapshot, phases } = await appendTodoEvent({
1571
1631
  validateProspectiveEvent,
1572
1632
  repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
@@ -1679,6 +1739,15 @@ async function addTask({ repoRoot, env, planKey, flags }) {
1679
1739
  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>\`.`,
1680
1740
  });
1681
1741
  }
1742
+ // The same design-memo rule as plan create, named by the flag: a missing memo is not recorded as NO_PLAN.
1743
+ const memo = explainTodoDesignMemo(flags['design-memo']);
1744
+ if (!memo.valid) {
1745
+ throw new TodoStoreError('DESIGN_MEMO_REQUIRED', 'todo_add_design_memo_required', undefined, {
1746
+ plan_key: planKey, task_id: taskId, pointer: '--design-memo', violation_kind: memo.reason,
1747
+ expected: memo.expected, actual: memo.actual, prompt: TODO_DESIGN_MEMO_PROMPT,
1748
+ next_action: `lattice todo add --plan ${planKey} --task ${taskId} --title <text> --design-memo <Markdown, or NO_PLAN>`,
1749
+ });
1750
+ }
1682
1751
  const ids = (value) => (typeof value === 'string' ? value.split(',').map((id) => id.trim()).filter(Boolean) : []);
1683
1752
  const after = ids(flags.after);
1684
1753
  const before = ids(flags.before);
@@ -1907,7 +1976,8 @@ async function phaseStatus({ repoRoot, planKey }) {
1907
1976
  ? staleAcceptanceGuidance(member.plan.plan_key, phase.phase_id)
1908
1977
  : phase.status === 'gate_ready'
1909
1978
  ? [
1910
- auditGateGuidance(member.plan.plan_key, phase.phase_id),
1979
+ auditGateGuidance(member.plan.plan_key, phase.phase_id, phaseAuditRequired(member,
1980
+ todoPhaseDefinitions(member.plan).find(({ phase_id: id }) => id === phase.phase_id)?.gate_policy)),
1911
1981
  ...(structureFinalization.required && structureFinalization.status !== 'fresh'
1912
1982
  ? [`構造finalizationが${structureFinalization.status}です。先に lattice todo structure finalize --plan ${member.plan.plan_key} --json を実行してください。`]
1913
1983
  : []),
@@ -2096,7 +2166,7 @@ async function migrate({ repoRoot, inputRef }) {
2096
2166
  coordination_guidance: imported.connectionOnly === true ? null : {
2097
2167
  mode: null,
2098
2168
  modes: [...TODO_COORDINATION_MODES],
2099
- next_action: `lattice todo independence mode --plan ${imported.plan.plan_key} --set <witness|conversation> --reason <text>`,
2169
+ next_action: `lattice todo independence mode --plan ${imported.plan.plan_key} --set <witness|conversation|enforced> --reason <text>`,
2100
2170
  },
2101
2171
  companion,
2102
2172
  result_digest: '',
@@ -5033,11 +5103,14 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5033
5103
  && (flags['test-result'] === undefined || isAuthoringPathToken(flags['test-result']))) {
5034
5104
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
5035
5105
  kind: 'done', dropped: (recorded) => doneDropped({ repoRoot, flags, recorded }),
5036
- action: async () => mutate({
5037
- repoRoot, env, planKey: flags.plan, taskId: flags.task, kind: 'done', payload: 'authored',
5038
- ...await doneEvidenceInput({ repoRoot, flags }),
5039
- testResultRef: flags['test-result'] ?? null,
5040
- }) });
5106
+ action: async () => {
5107
+ await enforcedDoneGate({ repoRoot, planKey: flags.plan, flags });
5108
+ return mutate({
5109
+ repoRoot, env, planKey: flags.plan, taskId: flags.task, kind: 'done', payload: 'authored',
5110
+ ...await doneEvidenceInput({ repoRoot, flags }),
5111
+ testResultRef: flags['test-result'] ?? null,
5112
+ });
5113
+ } });
5041
5114
  }
5042
5115
  }
5043
5116
  if (action === null && argv[0] === 'retract') {
@@ -27,7 +27,8 @@ export const TODO_PLAN_SCOPED_EVENT_KINDS = Object.freeze([
27
27
  ]);
28
28
 
29
29
  /** 調整方式。witness=独立性を宣言し検証して並列する/conversation=会話で調整する。 */
30
- export const TODO_COORDINATION_MODES = Object.freeze(['witness', 'conversation']);
30
+ // ADR 0200: `enforced` is witness coordination plus the gates that stop skipped steps.
31
+ export const TODO_COORDINATION_MODES = Object.freeze(['witness', 'conversation', 'enforced']);
31
32
  export const TODO_NOTE_EVENT_SCHEMA = 'lattice.todo_note_event.v1';
32
33
  /**
33
34
  * plan単位のnote event。工程レベルの義務(順序制約・一度きりの観測が在ること)は特定のtaskに
@@ -1,3 +1,5 @@
1
+ import { TODO_COORDINATION_MODES } from './todo-contracts.mjs';
2
+
1
3
  /**
2
4
  * 並列可否の案内(ADR 0130)。
3
5
  *
@@ -72,7 +74,7 @@ const CATALOG = Object.freeze({
72
74
  }),
73
75
  coordination_mode_undeclared: Object.freeze({
74
76
  message: 'このplanは調整方式をまだ選んでいない。witness検証で並列するか、会話で調整するかが決まっていない。',
75
- next_action: 'lattice todo independence mode --plan <key> --set <witness|conversation> --reason <text>',
77
+ next_action: 'lattice todo independence mode --plan <key> --set <witness|conversation|enforced> --reason <text>',
76
78
  }),
77
79
  coordination_conversation: Object.freeze({
78
80
  message: 'このplanは会話調整を選んでいる。並列可否は宣言と判定ではなく、卓の合意が持つ。',
@@ -192,7 +194,7 @@ export function todoIndependenceGuidance(code, { severability = null, planKey =
192
194
  }
193
195
 
194
196
  export function pullIntakeReadinessGuidance({ coordinationMode = null, ready, planKey = null }) {
195
- if (![null, 'witness', 'conversation'].includes(coordinationMode)
197
+ if (!(coordinationMode === null || TODO_COORDINATION_MODES.includes(coordinationMode))
196
198
  || typeof ready !== 'boolean') {
197
199
  throw new TypeError('pull intake readiness input is invalid');
198
200
  }
@@ -4,6 +4,7 @@ import {
4
4
  AUDIT_PENDING_PHASE_STATUSES,
5
5
  auditPendingNextCommands,
6
6
  isAuditPendingPhaseStatus,
7
+ phaseAuditRequired,
7
8
  } from './todo-audit-pending.mjs';
8
9
  import {
9
10
  TODO_COORDINATION_MODES,
@@ -414,7 +415,8 @@ function collectAuditPending(member, sink) {
414
415
  implicit,
415
416
  required_evidence_slots: [...definition.required_evidence_slots],
416
417
  next_commands: auditPendingNextCommands(member.plan.plan_key, phase.phase_id, phase.status,
417
- definition.required_evidence_slots.length),
418
+ definition.required_evidence_slots.length,
419
+ { auditRequired: phaseAuditRequired(member, definition.gate_policy) }),
418
420
  });
419
421
  }
420
422
  }