@quolu/lattice 0.87.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -156,12 +156,15 @@ lattice bridge status --json
156
156
  ## Release
157
157
 
158
158
  Latticeのreleaseはこのrepoから行います。`package.json`と`CHANGELOG.md`を更新し、製品gateを通し、
159
- release commitを既定branchへ着地・pushしてから、同じ版をregistryへ公開して実installを確認します。
160
- `prepublishOnly`はdirty treeとremote既定branchへ未着地のcommitを拒否します。
159
+ release commitを既定branchへ着地・pushします。そのpushでCIが成功すると`publish.yml`が自動で起動し、
160
+ 試験済みの同じ木を検査の再実行なしで公開します(registryに未公開で`latest`より新しい版だけ)。
161
+ その後、同じ版の実installを確認します。`prepublishOnly`はdirty treeとremote既定branchへ未着地のcommitを
162
+ 拒否します。`gh workflow run publish.yml`は、`main`先頭のCIが成功済みの時の手動再試行です。
161
163
 
162
164
  ```bash
163
165
  npm run ci
164
166
  npm run verify:release-commit
167
+ # 公開はCI成功後に自動で始まる。次は手動の再試行
165
168
  gh workflow run publish.yml --repo kitepon/Lattice --ref main
166
169
  npm install -g @quolu/lattice@<version>
167
170
  lattice --version
package/README.md CHANGED
@@ -324,13 +324,17 @@ AI登録の診断は`lattice setup status --json`。`--host <AI>`で対象を限
324
324
  ## Release
325
325
 
326
326
  Maintainers release Lattice from this repository. Update `package.json` and `CHANGELOG.md`, pass the
327
- product gate, land and push the release commit on the default branch, then publish and verify that
328
- same version from the registry. `prepublishOnly` rejects a dirty tree or a commit not landed on the
329
- remote default branch.
327
+ product gate, land and push the release commit on the default branch. When `CI` succeeds on that
328
+ push, `publish.yml` publishes the same tree without re-running the suite (only a version that is not on
329
+ the registry and newer than `latest`); then verify that version from the registry. `prepublishOnly`
330
+ rejects a dirty tree or a commit not landed on the remote default branch. `gh workflow run publish.yml`
331
+ remains the manual retry once `CI` is green on the `main` tip
332
+ ([flow](https://github.com/kitepon/Lattice/blob/main/docs/architecture/dfd-release-publish.md)).
330
333
 
331
334
  ```bash
332
335
  npm run ci
333
336
  npm run verify:release-commit
337
+ # publication starts by itself after CI; this is the manual retry
334
338
  gh workflow run publish.yml --repo kitepon/Lattice --ref main
335
339
  npm install -g @quolu/lattice@<version>
336
340
  lattice setup --json
@@ -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.89.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>',
@@ -24,6 +24,11 @@ const run = (ctx, ...tail) => ['lattice', ctx.family ?? 'todo', ctx.command, ...
24
24
  const schemaCommand = (ctx) => run(ctx, '--schema', '--json');
25
25
  const showTask = (detail, ctx) => `lattice todo show --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)} --json`;
26
26
  const startTask = (detail, ctx) => `lattice todo start --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)}`;
27
+ // The --message an enforced plan's done gate (ADR 0200 gate 4) accepts; the gate's own next_action uses it too.
28
+ export const ENFORCED_DONE_MESSAGE = '"<PR URL or merged commit sha>"';
29
+ // A done hint that the done gate accepts: on an enforced plan (ctx.enforcedPlans) it names the change, else `rest`.
30
+ const doneCommand = (planKey, taskId, ctx, rest = '') => `lattice todo done --plan ${planKey} --task ${taskId}${
31
+ strings(ctx.enforcedPlans).includes(planKey) ? ` --message ${ENFORCED_DONE_MESSAGE}` : rest}`;
27
32
  // a12: name the blocking task (seat contract), falling back to the refused task's own detail.
28
33
  const blocker = (detail) => (Array.isArray(detail.blocking_tasks) ? detail.blocking_tasks.find(record) : undefined);
29
34
  // a18: the step that moves the blocker on depends on its status (a pending one is started first).
@@ -35,7 +40,7 @@ const unfinishedFirst = (detail, ctx) => {
35
40
  return ({
36
41
  pending: `Start ${name} first with \`lattice todo start ${on}\`, then record done on it`,
37
42
  blocked: `Unblock ${name} with \`lattice todo unblock ${on}\`, then record done on it`,
38
- })[first.status] ?? `Record done on ${name} first with \`lattice todo done ${on} --message <text>\` (see \`lattice todo show ${on} --json\`)`;
43
+ })[first.status] ?? `Record done on ${name} first with \`${doneCommand(first.plan_key, first.task_id, ctx, ' --message <text>')}\` (see \`lattice todo show ${on} --json\`)`;
39
44
  };
40
45
  // a36: a start without LATTICE_SEAT_ID is recorded under the OS user; after the seat sets its id that
41
46
  // start looks like another seat's. Say so and give the seat contract's one-time fix.
@@ -46,7 +51,7 @@ const inProgressHolder = (detail, ctx, on) => {
46
51
  return `It is in-progress under '${holder}', the name a start gets without LATTICE_SEAT_ID: most likely this seat's own`
47
52
  + ` start from before it set LATTICE_SEAT_ID. One-time fix (seat contract): with LATTICE_SEAT_ID unset, undo that start`
48
53
  + ` with \`lattice todo retract ${on} --reason <text>\` and start it again here, or finish it there first with`
49
- + ` \`lattice todo done ${on} --message <text>\`.`;
54
+ + ` \`${doneCommand(planOf(detail, ctx), taskOf(detail, ctx), ctx, ' --message <text>')}\`.`;
50
55
  }
51
56
  return `It is already in-progress under ${holder === null ? 'another seat' : `seat '${holder}'`}; see \`${showTask(detail, ctx)}\`.`
52
57
  + ` To move it to this seat run \`lattice todo start ${on} --rebind --reason <text>\`.`;
@@ -228,11 +233,12 @@ const REGISTRY = {
228
233
  // a32: only a done task can be reopened; say the state and the step that fits it.
229
234
  repair: (detail, ctx) => {
230
235
  const on = `--plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)}`;
236
+ const done = doneCommand(planOf(detail, ctx), taskOf(detail, ctx), ctx);
231
237
  return `Only a done task can be reopened; ${planOf(detail, ctx)}/${taskOf(detail, ctx)} is ${detail.status ?? 'not done'}. ` + ({
232
238
  // a35: retract undoes only an authored start; a reopened task has none.
233
239
  'in-progress': detail.opened_by === 'start'
234
- ? `It is still open: finish it with \`lattice todo done ${on}\`, or undo the start with \`lattice todo retract ${on} --reason <text>\`.`
235
- : `It is still open${openedByText(detail)}: finish it with \`lattice todo done ${on}\`.`,
240
+ ? `It is still open: finish it with \`${done}\`, or undo the start with \`lattice todo retract ${on} --reason <text>\`.`
241
+ : `It is still open${openedByText(detail)}: finish it with \`${done}\`.`,
236
242
  pending: `It has not started: run \`lattice todo start ${on}\`.`,
237
243
  blocked: `It is blocked: resume it with \`lattice todo unblock ${on}\`.`,
238
244
  retired: `Retire is permanent, so it stays closed; see \`${showTask(detail, ctx)}\`.`,
@@ -265,7 +271,7 @@ const REGISTRY = {
265
271
  // a35: say why there is nothing to retract and the step that closes the task instead.
266
272
  repair: (detail, ctx) => `retract undoes only a start recorded by \`lattice todo start\`; `
267
273
  + `${planOf(detail, ctx)}/${taskOf(detail, ctx)} is in progress${openedByText(detail)}, so there is no start to undo. `
268
- + `Finish it with \`lattice todo done --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)}\`.`,
274
+ + `Finish it with \`${doneCommand(planOf(detail, ctx), taskOf(detail, ctx), ctx)}\`.`,
269
275
  },
270
276
  reopen_has_started_successor: {
271
277
  repair: (detail, ctx) => `A successor of ${taskOf(detail, ctx)} has already started: to reopen it anyway run \`lattice todo reopen --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)} --reason <text> --override-reason <text>\`.`,
@@ -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
@@ -1,9 +1,9 @@
1
1
  import { 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
- import { FLAG_PLACEHOLDER, publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
4
+ import { ENFORCED_DONE_MESSAGE, 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 {
@@ -265,6 +265,16 @@ function guidanceContext(argv, env = {}) {
265
265
  };
266
266
  }
267
267
 
268
+ /** Enforced plans, so a refusal's done hint names the change their done gate needs; none when the store is unreadable. */
269
+ async function enforcedPlanKeys(cwd) {
270
+ try {
271
+ const { members } = await readTodoStore({ repoRoot: resolveRepoRoot(cwd) });
272
+ return members.filter((member) => member.coordination?.mode === 'enforced').map(({ descriptor }) => descriptor.plan_key);
273
+ } catch {
274
+ return [];
275
+ }
276
+ }
277
+
268
278
  /**
269
279
  * An error that reached here is, by definition, one none of the typed
270
280
  * TodoStoreError/TypeError branches recognized — the one case where the
@@ -858,10 +868,13 @@ async function readStructureSetDraft(repoRoot, inputRef) {
858
868
  * gate_readyの次の一歩を1行で言う(ADR 0148裁定8・a22)。全taskが終わった席には、軽い出口
859
869
  * (監査せず閉じるclose-unaudited)を先に、監査する道(review→accept)を後に示す。経緯の説明は載せない。
860
870
  */
861
- function auditGateGuidance(planKey, phaseId) {
871
+ function auditGateGuidance(planKey, phaseId, auditRequired = false) {
862
872
  const target = `--plan ${planKey} --phase ${phaseId}`;
873
+ const audit = `lattice todo phase review ${target} --reason <text> → accept ${target} --evidence <file>`;
874
+ // ADR 0200 gate 5: an enforced plan's heavy phase refuses close-unaudited, so only the audit is offered.
875
+ if (auditRequired) return `全ToDoがdone。このplanはenforcedでheavyの段階なので監査する: ${audit}`;
863
876
  return `全ToDoがdone。監査せず閉じるなら: lattice todo phase close-unaudited ${target} --reason <text>`
864
- + `(監査するなら lattice todo phase review ${target} --reason <text> → accept ${target} --evidence <file>)`;
877
+ + `(監査するなら ${audit})`;
865
878
  }
866
879
 
867
880
  /** a36: reviewing and rejected phases say their next command too (the same lines as audit_pending). */
@@ -1389,6 +1402,9 @@ async function startTask({
1389
1402
  const advisory = await startAdvisory({
1390
1403
  repoRoot, store, projection, planKey, taskId: resolvedTaskId,
1391
1404
  });
1405
+ if (member.coordination?.mode === 'enforced') {
1406
+ enforcedStartGate({ advisory, planKey, taskId: resolvedTaskId, overrideReason });
1407
+ }
1392
1408
  const structureContext = await startStructureContext({
1393
1409
  repoRoot, store, planKey, taskId: resolvedTaskId,
1394
1410
  });
@@ -1408,6 +1424,47 @@ async function startTask({
1408
1424
  structureContext, featureContext });
1409
1425
  }
1410
1426
 
1427
+ const declareCommand = (planKey, taskId) => `lattice todo independence witness declare --plan ${planKey} --task ${taskId}`
1428
+ + ' --owns <path>[,<path>...] [--reads <path>,...] [--writes <path>,...]';
1429
+
1430
+ /** ADR 0200 gates 1–3: an enforced plan does not start undeclared, stale or conflicting work. Reads the advisory only. */
1431
+ function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
1432
+ const unknown = (kind) => advisory.self_unknowns.some((entry) => entry.kind === kind);
1433
+ const refuse = (reason, detail) => {
1434
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', reason, undefined, { plan_key: planKey, task_id: taskId, ...detail });
1435
+ };
1436
+ if (advisory.coverage === 'missing' || unknown('witness_missing')) {
1437
+ refuse('enforced_witness_undeclared', { next_action: `Declare the files ${taskId} touches, then start again: \`${declareCommand(planKey, taskId)}\`.` });
1438
+ }
1439
+ if (advisory.drift_intersecting === true || unknown('record_stale')) {
1440
+ 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)}\`.` });
1441
+ }
1442
+ if (advisory.conflicts_with_active.length > 0 && overrideReason === null) {
1443
+ const active = advisory.conflicts_with_active.map(({ active_task_id: id }) => id);
1444
+ refuse('enforced_conflict_with_active', { conflicts_with_active: advisory.conflicts_with_active,
1445
+ 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>\`,`
1446
+ + ` or start anyway with \`lattice todo start --plan ${planKey} --task ${taskId} --override-reason <text>\` (the reason is recorded).` });
1447
+ }
1448
+ }
1449
+
1450
+ /** ADR 0200 gate 4: done on an enforced plan names the change: evidence, an http(s) URL, or a commit in HEAD. */
1451
+ async function enforcedDoneGate({ repoRoot, planKey, flags }) {
1452
+ const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
1453
+ if (member?.coordination?.mode !== 'enforced' || flags.evidence !== undefined) return;
1454
+ const message = typeof flags.message === 'string' ? flags.message : '';
1455
+ if (/https?:\/\/\S+/u.test(message)) return;
1456
+ for (const token of message.match(/\b[0-9a-f]{7,40}\b/gu) ?? []) {
1457
+ try {
1458
+ gitSync(['merge-base', '--is-ancestor', token, 'HEAD'], { cwd: repoRoot, stdio: 'ignore' });
1459
+ return;
1460
+ } catch { /* not a commit in HEAD; try the next token */ }
1461
+ }
1462
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_done_reference_missing', undefined, {
1463
+ plan_key: planKey, task_id: flags.task,
1464
+ next_action: `Name the adopted change: \`lattice todo done --plan ${planKey} --task ${flags.task} --message ${ENFORCED_DONE_MESSAGE}\` (a sha must be in HEAD).`,
1465
+ });
1466
+ }
1467
+
1411
1468
  // plan改訂でcarryされたin-progress ToDoの再束縛入口(ADR 0191)。task状態・開始時刻は
1412
1469
  // 変えず、現plan_version・現actorのstart束縛だけをjournalへ積む。runtime intakeは
1413
1470
  // literal startだけを束縛に使いcarryを推定しないため、改訂を跨いだ進行中工程の
@@ -1567,6 +1624,19 @@ async function phaseDecisionFromEvidence({ repoRoot, env, planKey, phaseId, outc
1567
1624
  }
1568
1625
 
1569
1626
  async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload }) {
1627
+ if (kind === 'phase_close_unaudited') {
1628
+ // ADR 0200 gate 5: an enforced plan keeps the audit its author required for a heavy phase.
1629
+ const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
1630
+ const phase = member === undefined ? undefined
1631
+ : todoPhaseDefinitions(member.plan).find(({ phase_id: id }) => id === phaseId);
1632
+ if (phaseAuditRequired(member, phase?.gate_policy)) {
1633
+ throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_heavy_phase_unaudited', undefined, {
1634
+ plan_key: planKey, phase_id: phaseId,
1635
+ 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>\`;`
1636
+ + ' or revise the phase to a non-heavy gate_policy with `lattice plan revise` (recorded).',
1637
+ });
1638
+ }
1639
+ }
1570
1640
  const { event, snapshot, phases } = await appendTodoEvent({
1571
1641
  validateProspectiveEvent,
1572
1642
  repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), planKey,
@@ -1679,6 +1749,15 @@ async function addTask({ repoRoot, env, planKey, flags }) {
1679
1749
  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
1750
  });
1681
1751
  }
1752
+ // The same design-memo rule as plan create, named by the flag: a missing memo is not recorded as NO_PLAN.
1753
+ const memo = explainTodoDesignMemo(flags['design-memo']);
1754
+ if (!memo.valid) {
1755
+ throw new TodoStoreError('DESIGN_MEMO_REQUIRED', 'todo_add_design_memo_required', undefined, {
1756
+ plan_key: planKey, task_id: taskId, pointer: '--design-memo', violation_kind: memo.reason,
1757
+ expected: memo.expected, actual: memo.actual, prompt: TODO_DESIGN_MEMO_PROMPT,
1758
+ next_action: `lattice todo add --plan ${planKey} --task ${taskId} --title <text> --design-memo <Markdown, or NO_PLAN>`,
1759
+ });
1760
+ }
1682
1761
  const ids = (value) => (typeof value === 'string' ? value.split(',').map((id) => id.trim()).filter(Boolean) : []);
1683
1762
  const after = ids(flags.after);
1684
1763
  const before = ids(flags.before);
@@ -1907,7 +1986,8 @@ async function phaseStatus({ repoRoot, planKey }) {
1907
1986
  ? staleAcceptanceGuidance(member.plan.plan_key, phase.phase_id)
1908
1987
  : phase.status === 'gate_ready'
1909
1988
  ? [
1910
- auditGateGuidance(member.plan.plan_key, phase.phase_id),
1989
+ auditGateGuidance(member.plan.plan_key, phase.phase_id, phaseAuditRequired(member,
1990
+ todoPhaseDefinitions(member.plan).find(({ phase_id: id }) => id === phase.phase_id)?.gate_policy)),
1911
1991
  ...(structureFinalization.required && structureFinalization.status !== 'fresh'
1912
1992
  ? [`構造finalizationが${structureFinalization.status}です。先に lattice todo structure finalize --plan ${member.plan.plan_key} --json を実行してください。`]
1913
1993
  : []),
@@ -2096,7 +2176,7 @@ async function migrate({ repoRoot, inputRef }) {
2096
2176
  coordination_guidance: imported.connectionOnly === true ? null : {
2097
2177
  mode: null,
2098
2178
  modes: [...TODO_COORDINATION_MODES],
2099
- next_action: `lattice todo independence mode --plan ${imported.plan.plan_key} --set <witness|conversation> --reason <text>`,
2179
+ next_action: `lattice todo independence mode --plan ${imported.plan.plan_key} --set <witness|conversation|enforced> --reason <text>`,
2100
2180
  },
2101
2181
  companion,
2102
2182
  result_digest: '',
@@ -5033,11 +5113,14 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5033
5113
  && (flags['test-result'] === undefined || isAuthoringPathToken(flags['test-result']))) {
5034
5114
  action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
5035
5115
  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
- }) });
5116
+ action: async () => {
5117
+ await enforcedDoneGate({ repoRoot, planKey: flags.plan, flags });
5118
+ return mutate({
5119
+ repoRoot, env, planKey: flags.plan, taskId: flags.task, kind: 'done', payload: 'authored',
5120
+ ...await doneEvidenceInput({ repoRoot, flags }),
5121
+ testResultRef: flags['test-result'] ?? null,
5122
+ });
5123
+ } });
5041
5124
  }
5042
5125
  }
5043
5126
  if (action === null && argv[0] === 'retract') {
@@ -5146,7 +5229,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
5146
5229
  } catch (error) {
5147
5230
  if (error instanceof TodoStoreError || (typeof error?.code === 'string'
5148
5231
  && error.detail !== null && typeof error.detail === 'object')) {
5149
- return typedFailure(stderr, error, guidanceContext(argv, env));
5232
+ return typedFailure(stderr, error, { ...guidanceContext(argv, env), enforcedPlans: await enforcedPlanKeys(cwd) });
5150
5233
  }
5151
5234
  // 漏れた`fetch failed`もTypeErrorで届く。呼び出し側の契約違反と答えず、内部故障として観測口へ渡す。
5152
5235
  if (error instanceof TypeError && cliFailureClass(error) !== 'transport') {
@@ -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
  }
@@ -24,6 +24,7 @@ import {
24
24
  import path from 'node:path';
25
25
  import {
26
26
  TODO_COORDINATION_MODES,
27
+ TODO_EVENT_KINDS,
27
28
  TODO_LIMITS,
28
29
  TODO_PLAN_SCOPED_EVENT_KINDS,
29
30
  canonicalizeTodoArtifact,
@@ -62,6 +63,7 @@ import {
62
63
  collectTodoStructureGitProvenance,
63
64
  } from './todo-structure-git-adapter.mjs';
64
65
  import { sha256Bytes, verifyLinearHashChain } from './hash-chain.mjs';
66
+ import packageJson from '../package.json' with { type: 'json' };
65
67
  import { gitCatFileBatch, gitSync } from './git-process.mjs';
66
68
  import { matchesTodoSourceLineDigest } from './todo-source-line-eol.mjs';
67
69
  import {
@@ -111,17 +113,55 @@ function fail(code, reason, detail) {
111
113
  throw new TodoStoreError(code, reason, reason, detail);
112
114
  }
113
115
 
116
+ const upgradeAction = (what) => `${what} was written by a newer Lattice than ${packageJson.version}. The record is`
117
+ + ` not corrupt: do not repair or delete it. Upgrade Lattice on this host to a version newer than`
118
+ + ` ${packageJson.version}, then run the command again.`;
119
+
114
120
  function rejectUnsupportedRevisionSchema(value, { family, supportedSchemas }) {
115
121
  const schema = value?.schema;
116
122
  if (typeof schema === 'string'
117
123
  && new RegExp(`^lattice\\.${family}\\.v[1-9]\\d*$`, 'u').test(schema)
118
124
  && !supportedSchemas.includes(schema)) {
119
125
  fail('UNSUPPORTED_SCHEMA', 'unsupported_revision_schema', {
120
- schema, supported_schemas: [...supportedSchemas],
126
+ schema, supported_schemas: [...supportedSchemas], next_action: upgradeAction(`Schema ${schema}`),
121
127
  });
122
128
  }
123
129
  }
124
130
 
131
+ // Reader registration (newer-value-says-upgrade): the newest schema of each Store record family this
132
+ // reader knows. Bump it in the same diff that teaches the validator a new version.
133
+ export const NEWEST_KNOWN_TODO_SCHEMA = Object.freeze({ todo_event: 4, todo_plan: 8, todo_manifest: 2 });
134
+ const NEWER_SCHEMA_FAMILY = new Map([[validateTodoPlan, 'todo_plan'], [validateTodoManifest, 'todo_manifest']]);
135
+ const vocabularyWord = (value) => typeof value === 'string' && /^[a-z][a-z0-9_-]{0,63}$/u.test(value);
136
+
137
+ function newerSchema(value, family) {
138
+ const match = typeof value?.schema === 'string' ? value.schema.match(/^lattice\.([a-z_]+)\.v([1-9]\d{0,5})$/u) : null;
139
+ return match !== null && match[1] === family && Number(match[2]) > NEWEST_KNOWN_TODO_SCHEMA[family]
140
+ ? { pointer: '/schema', value: value.schema } : null;
141
+ }
142
+
143
+ // An event this reader cannot validate is "newer", not corrupt, when it names a higher event schema, or
144
+ // when it is intact (its own digest matches: the bytes are what a writer wrote) and names an event kind
145
+ // or coordination mode this reader does not know. Everything else stays STORE_CORRUPT.
146
+ function newerEventValue(event) {
147
+ const schema = newerSchema(event, 'todo_event');
148
+ if (schema !== null) return schema;
149
+ let intact = false;
150
+ try { intact = isTodoDigest(event?.event_digest) && event.event_digest === todoSelfDigest(event, 'event_digest'); } catch { /* not intact */ }
151
+ if (!intact) return null;
152
+ if (vocabularyWord(event.kind) && !TODO_EVENT_KINDS.includes(event.kind)) return { pointer: '/kind', value: event.kind };
153
+ const mode = event.kind === 'coordination_mode' ? event.payload?.mode : undefined;
154
+ return vocabularyWord(mode) && !TODO_COORDINATION_MODES.includes(mode) ? { pointer: '/payload/mode', value: mode } : null;
155
+ }
156
+
157
+ function failNewer({ pointer, value }, ref) {
158
+ fail('UNSUPPORTED_SCHEMA', 'newer_lattice_value', {
159
+ ...(ref === null ? {} : { ref }), pointer, value, reader_version: packageJson.version,
160
+ required_version: `>${packageJson.version}`,
161
+ next_action: upgradeAction(`The value '${value}' at ${pointer}${ref === null ? '' : ` in ${ref}`}`),
162
+ });
163
+ }
164
+
125
165
  function requireWriter(writer, caller) {
126
166
  if (!exactRecord(writer, ['schema', 'caller']) || writer.schema !== 'lattice.todo_store_writer.v1'
127
167
  || writer.caller !== caller) throw new TypeError(`writer capability for ${caller} required`);
@@ -169,7 +209,11 @@ function parseCanonicalJsonLine(bytes, { code, reason, maxBytes, validate, ref =
169
209
  let expected;
170
210
  try { expected = `${canonicalizeTodoArtifact(value)}\n`; } catch { fail(code, reason, detail); }
171
211
  if (text !== expected) fail(code, 'non_canonical_or_duplicate_key', detail);
172
- if (!validate(value)) fail(code, 'schema_invalid', detail);
212
+ if (!validate(value)) {
213
+ const newer = NEWER_SCHEMA_FAMILY.has(validate) ? newerSchema(value, NEWER_SCHEMA_FAMILY.get(validate)) : null;
214
+ if (newer !== null) failNewer(newer, ref);
215
+ fail(code, 'schema_invalid', detail);
216
+ }
173
217
  return value;
174
218
  }
175
219
 
@@ -208,7 +252,11 @@ function parseJournalSegment(bytes, ref = null) {
208
252
  let canonical;
209
253
  try { canonical = canonicalizeTodoArtifact(event); } catch { fail('STORE_CORRUPT', 'journal_schema_invalid'); }
210
254
  if (line !== canonical) fail('STORE_CORRUPT', 'journal_non_canonical_or_duplicate_key');
211
- if (!validateTodoEvent(event)) fail('STORE_CORRUPT', 'journal_schema_invalid');
255
+ if (!validateTodoEvent(event)) {
256
+ const newer = newerEventValue(event);
257
+ if (newer !== null) failNewer(newer, ref);
258
+ fail('STORE_CORRUPT', 'journal_schema_invalid');
259
+ }
212
260
  return event;
213
261
  });
214
262
  }