@@ -9,7 +9,9 @@ import type { ProjectConfig } from "../types/config.ts";
99import type { ExecutionPlan , PlannedAction } from "../types/plan.ts" ;
1010import type { ResourceAddress , StateFile } from "../types/state.ts" ;
1111import { addressKey } from "../types/state.ts" ;
12+ import { getResourceDeclaration } from "./declaration.ts" ;
1213import { computeResourceHash } from "./hasher.ts" ;
14+ import { buildReadinessBaseline , classifyReadinessImpact , diffReadinessBaseline } from "./plan-semantics.ts" ;
1315
1416export interface PlanOptions {
1517 providers ?: string [ ] ;
@@ -48,6 +50,7 @@ export async function buildPlan(
4850 action : "create" ,
4951 address,
5052 driftKind : "none" ,
53+ readinessImpact : "blocking" ,
5154 reason : "Resource does not exist in state" ,
5255 after : { content_hash : desiredHash } ,
5356 dependencies : deps ,
@@ -56,10 +59,13 @@ export async function buildPlan(
5659 ( existing . desired_hash ?? existing . content_hash ) !== desiredHash &&
5760 existing . drift_status === "drifted"
5861 ) {
62+ const changedPaths = collectChangedPaths ( address , config , existing , true ) ;
5963 actions . push ( {
6064 action : "update" ,
6165 address,
6266 driftKind : "both" ,
67+ readinessImpact : classifyReadinessImpact ( "update" , changedPaths ) ,
68+ changedPaths,
6369 reason : "Local config changed and remote drift detected" ,
6470 before : {
6571 content_hash : existing . desired_hash ?? existing . content_hash ,
@@ -70,20 +76,26 @@ export async function buildPlan(
7076 dependencies : deps ,
7177 } ) ;
7278 } else if ( ( existing . desired_hash ?? existing . content_hash ) !== desiredHash ) {
79+ const changedPaths = collectChangedPaths ( address , config , existing , false ) ;
7380 actions . push ( {
7481 action : "update" ,
7582 address,
7683 driftKind : "local" ,
84+ readinessImpact : classifyReadinessImpact ( "update" , changedPaths ) ,
85+ changedPaths,
7786 reason : "Local config changed" ,
7887 before : { content_hash : existing . desired_hash ?? existing . content_hash } ,
7988 after : { content_hash : desiredHash } ,
8089 dependencies : deps ,
8190 } ) ;
8291 } else if ( existing . drift_status === "drifted" ) {
92+ const changedPaths = existing . drift_paths ;
8393 actions . push ( {
8494 action : "update" ,
8595 address,
8696 driftKind : "remote" ,
97+ readinessImpact : classifyReadinessImpact ( "update" , changedPaths ) ,
98+ changedPaths,
8799 reason : "Remote drift detected" ,
88100 before : {
89101 content_hash : existing . desired_hash ?? existing . content_hash ,
@@ -98,6 +110,7 @@ export async function buildPlan(
98110 action : "no-op" ,
99111 address,
100112 driftKind : "none" ,
113+ readinessImpact : "none" ,
101114 reason :
102115 existing . drift_status === "unchecked"
103116 ? "No changes detected (remote content drift unchecked)"
@@ -116,6 +129,7 @@ export async function buildPlan(
116129 action : "delete" ,
117130 address : res . address ,
118131 driftKind : "none" ,
132+ readinessImpact : "blocking" ,
119133 reason : "Resource removed from configuration" ,
120134 before : { content_hash : res . desired_hash ?? res . content_hash } ,
121135 dependencies : [ ] ,
@@ -125,6 +139,21 @@ export async function buildPlan(
125139 return { actions, diagnostics : diagnostics . getAll ( ) } ;
126140}
127141
142+ function collectChangedPaths (
143+ address : ResourceAddress ,
144+ config : ProjectConfig ,
145+ existing : StateFile [ "resources" ] [ number ] ,
146+ includeRemote : boolean ,
147+ ) : string [ ] | undefined {
148+ const current = buildReadinessBaseline ( getResourceDeclaration ( address , config ) ) ;
149+ const localPaths = existing . desired_readiness_baseline
150+ ? diffReadinessBaseline ( existing . desired_readiness_baseline , current )
151+ : undefined ;
152+ if ( ! includeRemote ) return localPaths ;
153+ if ( ! localPaths && ! existing . drift_paths ) return undefined ;
154+ return [ ...new Set ( [ ...( localPaths ?? [ ] ) , ...( existing . drift_paths ?? [ ] ) ] ) ] . sort ( ) ;
155+ }
156+
128157function getDependencies ( address : ResourceAddress , graph : ReturnType < typeof buildDependencyGraph > ) : ResourceAddress [ ] {
129158 const key = addressKey ( address ) ;
130159 const depKeys = graph . edges . get ( key ) ?? new Set ( ) ;
0 commit comments