@quolu/lattice 0.83.0 → 0.84.1

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.
@@ -3,11 +3,8 @@ import {
3
3
  isPhaseTodoPlanSchema,
4
4
  isPhaselessTodoPlanSchema,
5
5
  projectTodoCrossPlanDependencies,
6
- localTaskRef,
7
6
  normalizeCheckoutEol,
8
- removedTaskRef,
9
7
  isFinishedTodoTaskState,
10
- todoTaskCarrySemantics as taskSemantics,
11
8
  } from './todo-store-view.mjs';
12
9
  export {
13
10
  isDecoupledPhaseTodoPlanSchema,
@@ -788,20 +785,8 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
788
785
  if (state.status !== 'done' || doneDigest.get(event.task_id) !== event.payload.target_done_digest) {
789
786
  fail('STORE_INCONSISTENT', 'invalid_reopen_binding');
790
787
  }
791
- {
792
- // 暗黙のterminal-audit Phaseがaccepted/closed_unauditedの後にtaskだけを無警告でreopen
793
- // できると、監査済み(または監査なしで閉じた)まま(gantt上も畳まれたまま)裏で作業が
794
- // 再開する抜け道になり、ADR 0147/0148の「監査の記録なしに閉じたことにさせない」を
795
- // 潜脱する。v4/v5の既存Phaseと同じ規律を暗黙Phaseにも及ぼし、phase_reopenを先に
796
- // 通させる。closed_unauditedをここへ足さないと、ADR 0148で新設した状態だけが
797
- // このgateを素通りしてしまう。
798
- const phaseId = isPhaselessTodoPlanSchema(plan.schema)
799
- ? TERMINAL_AUDIT_PHASE_ID
800
- : plan.tasks.find(({ task_id }) => task_id === event.task_id).phase_id;
801
- if (['accepted', 'closed_unaudited'].includes(derivedPhaseStatus(plan, states, phaseStates, phaseId))) {
802
- fail('STORE_INCONSISTENT', 'task_reopen_requires_phase_reopen');
803
- }
804
- }
788
+ // u03 A15: reopening a task in an accepted/closed_unaudited phase is the user's change. The
789
+ // phase decision stays as recorded; Plan shows it as acceptance_stale (derived from the journal).
805
790
  const startedSuccessor = localSuccessors(plan, event.task_id).some((id) => states.get(id).status !== 'pending');
806
791
  if (startedSuccessor && event.payload.override_reason === null) fail('STORE_INCONSISTENT', 'reopen_has_started_successor');
807
792
  state.status = 'in-progress'; state.done_at = null; state.evidence = null; state.test_result = null;
@@ -1127,6 +1112,24 @@ function evidenceVerifier(manifest, repoRoot, hard, newEventDigest = null) {
1127
1112
  };
1128
1113
  }
1129
1114
 
1115
+ /**
1116
+ * Read-only (a12): the evidence blob is present with its recorded digest but no ref reaches it yet,
1117
+ * i.e. it is waiting for a commit (message evidence or an uncommitted file). Missing or changed
1118
+ * bytes are not "uncommitted" and stay evidence_unverified refusals.
1119
+ */
1120
+ export function isTodoEvidenceUncommitted({ repoRoot, store, evidence }) {
1121
+ if (!validateEvidenceDescriptor(evidence)) return false;
1122
+ const repoRef = store.manifest.repositories.find(({ repo_id: id }) => id === evidence.repo_id)?.path;
1123
+ if (repoRef === undefined) return false;
1124
+ const absoluteRepo = path.resolve(repoRoot, repoRef);
1125
+ try {
1126
+ return sha256Bytes(readEvidenceBlob(absoluteRepo, evidence.git_blob_oid)) === evidence.content_digest
1127
+ && !reachableObjects(absoluteRepo).has(evidence.git_blob_oid);
1128
+ } catch {
1129
+ return false;
1130
+ }
1131
+ }
1132
+
1130
1133
  function pinnedSourceLine(repoRoot, source, cache = null) {
1131
1134
  // commit の型検査と blob 読みを 1 回の cat-file --batch へまとめる(object ごとの git
1132
1135
  // 子起動はWindowsで可視コンソールを開き、起動コストだけで走査を桁で遅くする)。
@@ -3702,206 +3705,6 @@ export async function verifyPhaseTodoRevisionSources(options = {}) {
3702
3705
  return true;
3703
3706
  }
3704
3707
 
3705
- function removedTaskIdsFor(revision) {
3706
- return new Set(revision.task_migration
3707
- .filter(({ to_task_id, state_policy }) => to_task_id === 'removed' && state_policy === 'removed')
3708
- .map(({ from_task_id }) => from_task_id));
3709
- }
3710
-
3711
- function phaseV3CarrySemantics(plan, taskId, taskIdMap, phaseIdMap,
3712
- { reconciliationMetadata = false, includeDesignMemo = false, removedTaskIds = new Set() } = {}) {
3713
- const task = plan.tasks.find(({ task_id: id }) => id === taskId);
3714
- if (task === undefined) return null;
3715
- const mapTaskRef = (ref) => ref.project_id === plan.project_id && ref.plan_key === plan.plan_key
3716
- ? { ...ref, task_id: taskIdMap.get(ref.task_id) ?? ref.task_id } : ref;
3717
- const mapPhaseRef = (ref) => ref.project_id === plan.project_id && ref.plan_key === plan.plan_key
3718
- ? { ...ref, phase_id: phaseIdMap.get(ref.phase_id) ?? ref.phase_id } : ref;
3719
- // Phaseを持たない世代(todo_plan.v3)のtaskはphase_idを持たない。undefinedのまま
3720
- // canonicalizeするとJSON treeでないとしてTypeErrorになり、typedな拒否理由が失われる。
3721
- // nullへ正規化してcarry比較へ渡し、Phase割当ての獲得をcarry_semantics_changedとして拒否する。
3722
- const mappedPhaseId = phaseIdMap.get(task.phase_id) ?? task.phase_id ?? null;
3723
- const mappedTask = reconciliationMetadata ? {
3724
- task_id: taskIdMap.get(task.task_id) ?? task.task_id, title: task.title, lane: task.lane,
3725
- compile_binding: task.compile_binding,
3726
- phase_id: mappedPhaseId,
3727
- } : {
3728
- task_id: taskIdMap.get(task.task_id) ?? task.task_id,
3729
- title: task.title, lane: task.lane,
3730
- ...(includeDesignMemo ? { design_memo: task.design_memo } : {}),
3731
- narrative_ref: task.narrative_ref, narrative_anchor: task.narrative_anchor ?? null,
3732
- compile_binding: task.compile_binding,
3733
- phase_id: mappedPhaseId,
3734
- parent_task_id: task.parent_task_id === null ? null
3735
- : taskIdMap.get(task.parent_task_id) ?? task.parent_task_id,
3736
- };
3737
- const incoming = [];
3738
- const outgoing = [];
3739
- for (const edge of plan.hard_dependencies) {
3740
- if (removedTaskRef(edge.from, plan, removedTaskIds)
3741
- || removedTaskRef(edge.to, plan, removedTaskIds)) continue;
3742
- const mapped = { kind: 'hard', from: mapTaskRef(edge.from), to: mapTaskRef(edge.to) };
3743
- if (localTaskRef(edge.to, plan, taskId)) incoming.push(mapped);
3744
- if (localTaskRef(edge.from, plan, taskId)) outgoing.push(mapped);
3745
- }
3746
- for (const join of plan.joins) {
3747
- if (removedTaskRef(join.before, plan, removedTaskIds)) continue;
3748
- const to = mapTaskRef(join.before);
3749
- for (const after of join.after) {
3750
- if (removedTaskRef(after, plan, removedTaskIds)) continue;
3751
- const tuple = { kind: 'join', join_id: join.id, from: mapTaskRef(after), to };
3752
- if (localTaskRef(join.before, plan, taskId)) incoming.push(tuple);
3753
- if (localTaskRef(after, plan, taskId)) outgoing.push(tuple);
3754
- }
3755
- }
3756
- if (isDecoupledPhaseTodoPlanSchema(plan.schema)) for (const edge of plan.phase_accept_dependencies) {
3757
- if (localTaskRef(edge.to, plan, taskId)) incoming.push({ kind: 'phase_accept',
3758
- from: mapPhaseRef(edge.from), to: mapTaskRef(edge.to) });
3759
- }
3760
- const sort = (entries) => entries.map(canonicalizeTodoArtifact).sort();
3761
- return { task: mappedTask, incoming: sort(incoming), outgoing: sort(outgoing) };
3762
- }
3763
-
3764
- function validatePhaseV3Carry(previous, revision, migration, idMap, state) {
3765
- const reconciliationMetadata = migration.state_policy === 'carry_reconciled_metadata';
3766
- const predecessorTask = previous.plan.tasks.find(({ task_id }) => task_id === migration.from_task_id);
3767
- const includeDesignMemo = !reconciliationMetadata && typeof predecessorTask?.design_memo === 'string';
3768
- const removedTaskIds = removedTaskIdsFor(revision);
3769
- const phaseIdMap = new Map(revision.phase_migration
3770
- .filter(({ from_phase_id, to_phase_id }) => from_phase_id !== null && to_phase_id !== 'removed')
3771
- .map(({ from_phase_id, to_phase_id }) => [from_phase_id, to_phase_id]));
3772
- const before = phaseV3CarrySemantics(previous.plan, migration.from_task_id, idMap, phaseIdMap,
3773
- { reconciliationMetadata, includeDesignMemo, removedTaskIds });
3774
- const after = phaseV3CarrySemantics(revision.desired_plan, migration.to_task_id,
3775
- new Map(), new Map(),
3776
- { reconciliationMetadata, includeDesignMemo });
3777
- if (canonicalizeTodoArtifact(before.task) !== canonicalizeTodoArtifact(after.task)
3778
- || canonicalizeTodoArtifact(before.incoming) !== canonicalizeTodoArtifact(after.incoming)) {
3779
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3780
- }
3781
- const successorOutgoing = new Set(after.outgoing);
3782
- if (!before.outgoing.every((edge) => successorOutgoing.has(edge))) {
3783
- fail('REVISION_INVALID', 'carry_outgoing_edge_removed', { from_task_id: migration.from_task_id });
3784
- }
3785
- }
3786
-
3787
- function validateBackchainCarry(previous, revision, migration, idMap) {
3788
- const decision = revision.backchain.continuity?.find(({ task_id: id }) =>
3789
- id === migration.from_task_id);
3790
- if (decision?.policy === 'carry') return;
3791
- const reconciliationMetadata = migration.state_policy === 'carry_reconciled_metadata';
3792
- const predecessorTask = previous.plan.tasks.find(({ task_id }) => task_id === migration.from_task_id);
3793
- const phaseIdMap = new Map(revision.phase_migration
3794
- .filter(({ from_phase_id, to_phase_id }) => from_phase_id !== null && to_phase_id !== 'removed')
3795
- .map(({ from_phase_id, to_phase_id }) => [from_phase_id, to_phase_id]));
3796
- const before = phaseV3CarrySemantics(previous.plan, migration.from_task_id, idMap, phaseIdMap, {
3797
- reconciliationMetadata, includeDesignMemo: !reconciliationMetadata
3798
- && typeof predecessorTask?.design_memo === 'string',
3799
- removedTaskIds: removedTaskIdsFor(revision),
3800
- });
3801
- const after = phaseV3CarrySemantics(revision.desired_plan, migration.to_task_id,
3802
- new Map(), new Map(), {
3803
- reconciliationMetadata, includeDesignMemo: !reconciliationMetadata
3804
- && typeof predecessorTask?.design_memo === 'string',
3805
- });
3806
- // 利用先の増減は提供済み機能の意味を変えない。入力・提供機能の同一性は
3807
- // backchain契約で別に照合し、工程の入力辺と本体の意味だけをここで検査する。
3808
- if (canonicalizeTodoArtifact(before.task) !== canonicalizeTodoArtifact(after.task)
3809
- || canonicalizeTodoArtifact(before.incoming) !== canonicalizeTodoArtifact(after.incoming)) {
3810
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3811
- }
3812
- }
3813
-
3814
- function backchainTaskSignature(chain, taskId) {
3815
- const task = chain?.tasks?.find(({ task_id: id }) => id === taskId);
3816
- if (task === undefined) return null;
3817
- const featureIds = [...new Set([...task.requires_feature_ids, ...task.provides_feature_ids])].sort();
3818
- const byId = new Map(chain.features.map((feature) => [feature.feature_id, feature]));
3819
- return canonicalizeTodoArtifact({
3820
- requires_feature_ids: task.requires_feature_ids,
3821
- provides_feature_ids: task.provides_feature_ids,
3822
- features: featureIds.map((id) => byId.get(id)),
3823
- });
3824
- }
3825
-
3826
- async function assertBackchainCarryContracts(repoRoot, previous, revision) {
3827
- const decisions = new Map((revision.backchain.continuity ?? [])
3828
- .map((entry) => [entry.task_id, entry]));
3829
- for (const decision of decisions.values()) {
3830
- const migration = revision.task_migration.find(({ from_task_id: id }) => id === decision.task_id);
3831
- if (migration === undefined || (decision.policy === 'carry'
3832
- && !['carry', 'carry_reconciled_metadata'].includes(migration.state_policy))
3833
- || (decision.policy === 'reset' && migration.state_policy !== 'reset_pending')
3834
- || (decision.policy === 'retire' && migration.state_policy !== 'removed')) {
3835
- fail('REVISION_INVALID', 'backchain_continuity_mismatch', { task_id: decision.task_id });
3836
- }
3837
- }
3838
- const carried = revision.task_migration.filter(({ state_policy }) =>
3839
- ['carry', 'carry_reconciled_metadata', 'acquire_phase'].includes(state_policy));
3840
- if (carried.length === 0) return;
3841
- const oldRef = path.resolve(repoRoot, STORE_ROOT_REF, 'plans', previous.plan.plan_key,
3842
- previous.plan.plan_version, 'backchain.json');
3843
- const bytes = await exactFileOrNull(oldRef);
3844
- if (bytes === null) fail('REVISION_INVALID', 'backchain_predecessor_missing');
3845
- let binding;
3846
- try { binding = JSON.parse(decodeUtf8(bytes, 'REVISION_INVALID', 'backchain_predecessor_invalid')); }
3847
- catch { fail('REVISION_INVALID', 'backchain_predecessor_invalid'); }
3848
- if (binding?.schema !== 'lattice.plan_backchain_binding.v1'
3849
- || binding.plan_digest !== previous.plan.plan_digest
3850
- || binding.binding_digest !== todoSelfDigest(binding, 'binding_digest')) {
3851
- fail('REVISION_INVALID', 'backchain_predecessor_invalid');
3852
- }
3853
- for (const migration of carried) {
3854
- if (decisions.get(migration.from_task_id)?.policy === 'carry') continue;
3855
- if (backchainTaskSignature(binding.chain, migration.from_task_id)
3856
- !== backchainTaskSignature(revision.backchain, migration.to_task_id)) {
3857
- fail('REVISION_INVALID', 'backchain_carry_feature_changed', {
3858
- from_task_id: migration.from_task_id, to_task_id: migration.to_task_id,
3859
- });
3860
- }
3861
- }
3862
- }
3863
-
3864
- /**
3865
- * acquire_phase専用のcarry検証(ADR 0147裁定4)。既存carry/carry_reconciled_metadataの
3866
- * 分岐(validatePhaseV3Carry)には一切手を入れず、「Phase割当ての獲得だけ」を許す別分岐として
3867
- * 独立に置く——同じcarry比較へphase_idだけ除外する特例を混ぜると、以後の意味論比較すべてに
3868
- * 例外条件が混入する経路を開いてしまう(裁定4が名指しで禁じる形)。
3869
- *
3870
- * 獲得の定義: predecessor側がphase無し(phase_idがnullに正規化される)→successor側がphase有り、
3871
- * という向きだけを許す。既にphaseを持つtaskの付け替えは意味論の変更であり、acquire_phaseでは
3872
- * 許さない(carryへ回して従来どおりcarry_semantics_changedで拒否させる)。phase_id以外の
3873
- * 属性(title/lane/narrative_ref/narrative_anchor/compile_binding/parent_task_id)と
3874
- * 依存辺(incoming)は、phaseV3CarrySemanticsのtaskからphase_idだけを取り除いた上で
3875
- * carryと同じ完全一致を要求する。outgoingの扱い(successor側が上位集合であること)もcarryと同じ。
3876
- */
3877
- function validateAcquirePhaseCarry(previous, revision, migration, idMap) {
3878
- const phaseIdMap = new Map(revision.phase_migration
3879
- .filter(({ from_phase_id, to_phase_id }) => from_phase_id !== null && to_phase_id !== 'removed')
3880
- .map(({ from_phase_id, to_phase_id }) => [from_phase_id, to_phase_id]));
3881
- const predecessorTask = previous.plan.tasks.find(({ task_id }) => task_id === migration.from_task_id);
3882
- const includeDesignMemo = typeof predecessorTask?.design_memo === 'string';
3883
- const removedTaskIds = removedTaskIdsFor(revision);
3884
- const before = phaseV3CarrySemantics(previous.plan, migration.from_task_id, idMap, phaseIdMap,
3885
- { includeDesignMemo, removedTaskIds });
3886
- const after = phaseV3CarrySemantics(revision.desired_plan, migration.to_task_id, new Map(), new Map(),
3887
- { includeDesignMemo });
3888
- if (before.task.phase_id !== null) {
3889
- fail('REVISION_INVALID', 'acquire_phase_requires_unassigned_predecessor', { from_task_id: migration.from_task_id });
3890
- }
3891
- if (after.task.phase_id === null) {
3892
- fail('REVISION_INVALID', 'acquire_phase_requires_assigned_successor', { from_task_id: migration.from_task_id });
3893
- }
3894
- const stripPhase = ({ phase_id, ...rest }) => rest;
3895
- if (canonicalizeTodoArtifact(stripPhase(before.task)) !== canonicalizeTodoArtifact(stripPhase(after.task))
3896
- || canonicalizeTodoArtifact(before.incoming) !== canonicalizeTodoArtifact(after.incoming)) {
3897
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3898
- }
3899
- const successorOutgoing = new Set(after.outgoing);
3900
- if (!before.outgoing.every((edge) => successorOutgoing.has(edge))) {
3901
- fail('REVISION_INVALID', 'carry_outgoing_edge_removed', { from_task_id: migration.from_task_id });
3902
- }
3903
- }
3904
-
3905
3708
  function stateMigrationFor(previous, revision) {
3906
3709
  if (['lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(previous.plan.schema)
3907
3710
  && !['lattice.todo_plan.v6', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8']
@@ -3921,62 +3724,20 @@ function stateMigrationFor(previous, revision) {
3921
3724
  if (canonicalizeTodoArtifact([...oldIds].sort()) !== canonicalizeTodoArtifact([...migrationIds].sort())) {
3922
3725
  fail('REVISION_INVALID', 'predecessor_task_migration_incomplete');
3923
3726
  }
3924
- const idMap = new Map(revision.task_migration
3925
- .filter(({ to_task_id }) => to_task_id !== 'removed')
3926
- .map(({ from_task_id, to_task_id }) => [from_task_id, to_task_id]));
3927
- const removedTaskIds = removedTaskIdsFor(revision);
3928
3727
  const states = new Map(previous.tasks.map((state) => [state.task_id, state]));
3929
3728
  return revision.task_migration.map((migration) => {
3930
3729
  const carriesState = ['carry', 'carry_reconciled_metadata', 'acquire_phase'].includes(migration.state_policy);
3931
3730
  if (!carriesState) return { ...migration, state: null };
3932
- const reconciliationMetadata = migration.state_policy === 'carry_reconciled_metadata';
3933
3731
  const state = states.get(migration.from_task_id);
3934
3732
  if (!state) fail('STORE_INCONSISTENT', 'predecessor_task_state_missing');
3935
- if (migration.state_policy === 'acquire_phase') {
3936
- // acquire_phaseはv3 phase revision専用の獲得判定を持つ。v3以外(v1/v2 phase revisionや
3937
- // 平文todo_revision)ではtaskSemantics自体がphase_idを比較対象へ含めないため、carryと
3938
- // 同じ比較で意味論は保たれる——ここを別ロジックにする理由が無い(既知のv1/v2の緩さは
3939
- // ADR 0147の対象外であり、緩めも締めもしない)。
3940
- if (revision.schema === 'lattice.phase_todo_revision.v3') {
3941
- validateAcquirePhaseCarry(previous, revision, migration, idMap);
3942
- } else {
3943
- const predecessorTask = previous.plan.tasks
3944
- .find(({ task_id }) => task_id === migration.from_task_id);
3945
- const includeDesignMemo = typeof predecessorTask?.design_memo === 'string';
3946
- const before = taskSemantics(previous.plan, migration.from_task_id, idMap,
3947
- { includeDesignMemo, removedTaskIds });
3948
- const after = taskSemantics(revision.desired_plan, migration.to_task_id, new Map(),
3949
- { includeDesignMemo });
3950
- if (canonicalizeTodoArtifact(before) !== canonicalizeTodoArtifact(after)) {
3951
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3952
- }
3953
- }
3954
- } else if (revision.schema === 'lattice.phase_todo_revision.v5' && reconciliationMetadata) {
3955
- // u12 light carry: only the task_id mapping and compile_binding bind carried state.
3956
- const predecessorTask = previous.plan.tasks
3957
- .find(({ task_id }) => task_id === migration.from_task_id);
3958
- const desiredTask = revision.desired_plan.tasks
3959
- .find(({ task_id }) => task_id === migration.to_task_id);
3960
- if (!desiredTask || canonicalizeTodoArtifact(predecessorTask?.compile_binding)
3961
- !== canonicalizeTodoArtifact(desiredTask.compile_binding)) {
3962
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3963
- }
3964
- } else if (revision.schema === 'lattice.phase_todo_revision.v3') {
3965
- validatePhaseV3Carry(previous, revision, migration, idMap, state);
3966
- } else if (revision.schema === 'lattice.phase_todo_revision.v4') {
3967
- validateBackchainCarry(previous, revision, migration, idMap);
3968
- } else {
3969
- const predecessorTask = previous.plan.tasks
3970
- .find(({ task_id }) => task_id === migration.from_task_id);
3971
- const includeDesignMemo = !reconciliationMetadata
3972
- && typeof predecessorTask?.design_memo === 'string';
3973
- const before = taskSemantics(previous.plan, migration.from_task_id, idMap,
3974
- { reconciliationMetadata, includeDesignMemo, removedTaskIds });
3975
- const after = taskSemantics(revision.desired_plan, migration.to_task_id, new Map(),
3976
- { reconciliationMetadata, includeDesignMemo });
3977
- if (canonicalizeTodoArtifact(before) !== canonicalizeTodoArtifact(after)) {
3978
- fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3979
- }
3733
+ // u03 A38/A39: every schema uses the u12 light-carry rule. Authored fields, edges, joins and
3734
+ // phase assignment may change at any state; only the id mapping and compile_binding bind
3735
+ // carried state (the claim 1-4 impact binding must not carry onto another compiled spec).
3736
+ const predecessorTask = previous.plan.tasks.find(({ task_id }) => task_id === migration.from_task_id);
3737
+ const desiredTask = revision.desired_plan.tasks.find(({ task_id }) => task_id === migration.to_task_id);
3738
+ if (!desiredTask || canonicalizeTodoArtifact(predecessorTask?.compile_binding ?? null)
3739
+ !== canonicalizeTodoArtifact(desiredTask.compile_binding ?? null)) {
3740
+ fail('REVISION_INVALID', 'carry_semantics_changed', { from_task_id: migration.from_task_id });
3980
3741
  }
3981
3742
  return { ...migration, state: {
3982
3743
  status: state.status, started_at: state.started_at, done_at: state.done_at,
@@ -3995,12 +3756,6 @@ function phaseStateMigrationFor(previous, revision) {
3995
3756
  !== canonicalizeTodoArtifact(predecessorPhases.map(({ phase_id }) => phase_id).sort())) {
3996
3757
  fail('REVISION_INVALID', 'predecessor_phase_migration_incomplete');
3997
3758
  }
3998
- const idMap = new Map(revision.phase_migration
3999
- .filter(({ from_phase_id, to_phase_id }) => from_phase_id !== null && to_phase_id !== 'removed')
4000
- .map(({ from_phase_id, to_phase_id }) => [from_phase_id, to_phase_id]));
4001
- const taskIdMap = new Map(revision.task_migration
4002
- .filter(({ to_task_id }) => to_task_id !== 'removed')
4003
- .map(({ from_task_id, to_task_id }) => [from_task_id, to_task_id]));
4004
3759
  const previousStates = new Map((previous.snapshot.phases ?? []).map((state) => [state.phase_id, state]));
4005
3760
  return revision.phase_migration
4006
3761
  .filter(({ to_phase_id }) => to_phase_id !== 'removed')
@@ -4008,22 +3763,9 @@ function phaseStateMigrationFor(previous, revision) {
4008
3763
  if (migration.state_policy === 'reset') {
4009
3764
  return { phase_id: migration.to_phase_id, state_policy: 'reset', state: null };
4010
3765
  }
4011
- const before = predecessorPhases.find(({ phase_id }) => phase_id === migration.from_phase_id);
4012
3766
  const after = revision.desired_plan.phases.find(({ phase_id }) => phase_id === migration.to_phase_id);
4013
- const mappedBefore = { ...before, phase_id: migration.to_phase_id,
4014
- predecessor_phase_ids: before.predecessor_phase_ids.map((id) => idMap.get(id) ?? id).sort() };
4015
- const beforeTaskIds = previous.plan.tasks
4016
- .filter(({ phase_id }) => phase_id === migration.from_phase_id)
4017
- .map(({ task_id }) => taskIdMap.get(task_id) ?? 'removed').filter((id) => id !== 'removed').sort();
4018
- const afterTaskIds = revision.desired_plan.tasks
4019
- .filter(({ phase_id }) => phase_id === migration.to_phase_id).map(({ task_id }) => task_id).sort();
4020
- // u12 light carry (revision v5): Plan chose carry vs reset; Store checks only the id mapping.
4021
- if (revision.schema === 'lattice.phase_todo_revision.v5') {
4022
- if (!after) fail('REVISION_INVALID', 'phase_carry_semantics_changed', { from_phase_id: migration.from_phase_id });
4023
- } else if (canonicalizeTodoArtifact({ phase: mappedBefore, task_ids: beforeTaskIds })
4024
- !== canonicalizeTodoArtifact({ phase: after, task_ids: afterTaskIds })) {
4025
- fail('REVISION_INVALID', 'phase_carry_semantics_changed', { from_phase_id: migration.from_phase_id });
4026
- }
3767
+ // u12/u03 A38: the revision chose carry vs reset; Store checks only the id mapping.
3768
+ if (!after) fail('REVISION_INVALID', 'phase_carry_semantics_changed', { from_phase_id: migration.from_phase_id });
4027
3769
  const state = previousStates.get(migration.from_phase_id);
4028
3770
  if (state === undefined) fail('STORE_INCONSISTENT', 'predecessor_phase_state_missing');
4029
3771
  return { phase_id: migration.to_phase_id, state_policy: 'carry', state: {
@@ -4741,7 +4483,7 @@ async function cleanupPhaseV3Staging(transaction, staged) {
4741
4483
  await fsyncDirectory(transaction);
4742
4484
  }
4743
4485
 
4744
- async function predecessorSourceInventory(repoRoot, previous) {
4486
+ export async function predecessorSourceInventory(repoRoot, previous) {
4745
4487
  if (previous.revision?.source_inventory !== undefined) return previous.revision.source_inventory;
4746
4488
  const versionsRoot = path.join(repoRoot, STORE_ROOT_REF, 'plans', previous.plan.plan_key);
4747
4489
  const plansByDigest = new Map();
@@ -5085,9 +4827,6 @@ export async function applyPhaseTodoRevision(options = {}) {
5085
4827
  fail('STORE_WRITE_CONFLICT', 'stale_predecessor');
5086
4828
  }
5087
4829
  verifyPlanNarrativeAnchors(repoRoot, revision.desired_plan, previous.plan);
5088
- if (revision.schema === 'lattice.phase_todo_revision.v4') {
5089
- await assertBackchainCarryContracts(repoRoot, previous, revision);
5090
- }
5091
4830
  const stateMigration = stateMigrationFor(previous, revision);
5092
4831
  const phaseStateMigration = phaseStateMigrationFor(previous, revision);
5093
4832
  const prospective = store.members.map((member) => member === previous