@revoengine/cli 1.0.16 → 1.0.18

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.
@@ -1,10 +1,13 @@
1
+ import { projectRepositoryItems, migrationItemOperation, BLOCKING_SCHEMA_STATUSES, schemaItemAction, viewItemIsBlocked, viewItemAction, componentItemAction, jobTemplateItemAction, endpointItemAction, scheduleItemAction, eventItemAction, groupItemAction, roleGroupItemAction, serviceAccountItemAction, } from "./migration-actions.js";
1
2
  import fs from 'node:fs';
3
+ import { applyWorkspacePrune, buildWorkspacePrunePlan, samePrunePlan } from "./workspace-prune.js";
2
4
  import { planIdentityMigration } from "./resource-syncs/identity-migration.js";
3
5
  import { SERVICE_ACCOUNTS_DIRECTORY, buildServiceAccountsPlan, pullServiceAccountsToWorkspace, pushServiceAccounts } from "./resource-syncs/service-account-sync.js";
4
6
  import os from 'node:os';
5
7
  import path from 'node:path';
6
8
  import { RevoClient } from "./client.js";
7
9
  import { REVO_LOCK_FILE, readComponentLock } from "./component-lock.js";
10
+ import { normalizeStableKeyValue } from "./resource-metadata.js";
8
11
  import { withHttpTraceContext } from "./http-trace.js";
9
12
  import { buildComponentPlan, pullAllComponents, pushAllComponents, } from "./commands/component.js";
10
13
  import { resolveRuntimeConfig } from "./config.js";
@@ -29,13 +32,6 @@ const RESOURCE_ORDER = [
29
32
  'group',
30
33
  'role-group',
31
34
  ];
32
- const BLOCKING_SCHEMA_STATUSES = new Set([
33
- 'collision',
34
- 'manual-schema-migration-required',
35
- 'access-policy-required',
36
- 'previously-deleted-partition',
37
- 'replacement-requires-two-phases',
38
- ]);
39
35
  function selectedResources(input) {
40
36
  const requested = new Set(input.resources?.length ? input.resources : RESOURCE_ORDER);
41
37
  return RESOURCE_ORDER.filter((resource) => requested.has(resource));
@@ -68,186 +64,6 @@ function viewMigrationPolicy(input, deferPreview = false) {
68
64
  function emptyOperations() {
69
65
  return { noop: 0, create: 0, update: 0, adopt: 0, excluded: 0, blocked: 0 };
70
66
  }
71
- function schemaItemAction(item) {
72
- if (BLOCKING_SCHEMA_STATUSES.has(item.status)) {
73
- return 'blocked';
74
- }
75
- if (item.status === 'create') {
76
- return 'create';
77
- }
78
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
79
- return 'update';
80
- }
81
- if (item.status === 'missing-lock') {
82
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
83
- }
84
- if (item.status === 'reconciled') {
85
- return 'adopt';
86
- }
87
- if (item.status === 'orphan-root'
88
- || item.status === 'orphan-partition'
89
- || item.status === 'delete-partition'
90
- || item.status === 'unmanaged') {
91
- return 'excluded';
92
- }
93
- return 'noop';
94
- }
95
- function viewItemIsBlocked(item) {
96
- return item.status === 'collision'
97
- || item.status === 'validation-failed'
98
- || (item.status === 'conflict' && Boolean(item.reason));
99
- }
100
- function viewItemAction(item) {
101
- if (viewItemIsBlocked(item)) {
102
- return 'blocked';
103
- }
104
- if (item.status === 'create') {
105
- return 'create';
106
- }
107
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
108
- return 'update';
109
- }
110
- if (item.status === 'missing-lock') {
111
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
112
- }
113
- if (item.status === 'orphan' || item.status === 'skipped') {
114
- return 'excluded';
115
- }
116
- return 'noop';
117
- }
118
- function componentItemAction(item) {
119
- if (item.blocked === true || item.status === 'blocked') {
120
- return 'blocked';
121
- }
122
- if (item.status === 'clean'
123
- && item.lockHash === null
124
- && item.localHash !== null
125
- && item.localHash === item.remoteHash) {
126
- return 'adopt';
127
- }
128
- if (item.status === 'create') {
129
- return 'create';
130
- }
131
- if (item.status === 'local-changed'
132
- || item.status === 'remote-changed'
133
- || item.status === 'conflict'
134
- || item.status === 'missing-lock') {
135
- return 'update';
136
- }
137
- if (item.status === 'safe-update') {
138
- return 'excluded';
139
- }
140
- return 'noop';
141
- }
142
- function jobTemplateItemAction(item) {
143
- if (item.status === 'collision' || (item.status === 'conflict' && !item.desiredHash)) {
144
- return 'blocked';
145
- }
146
- if (item.status === 'create') {
147
- return 'create';
148
- }
149
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
150
- return 'update';
151
- }
152
- if (item.status === 'missing-lock') {
153
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
154
- }
155
- if (item.status === 'orphan' || item.status === 'skipped') {
156
- return 'excluded';
157
- }
158
- return 'noop';
159
- }
160
- function endpointItemAction(item) {
161
- if (item.status === 'restore-blocked' || item.status === 'collision') {
162
- return 'blocked';
163
- }
164
- if (item.status === 'create') {
165
- return 'create';
166
- }
167
- if (item.status === 'restore' || item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
168
- return 'update';
169
- }
170
- if (item.status === 'missing-lock') {
171
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
172
- }
173
- if (item.status === 'orphan' || item.status === 'skipped') {
174
- return 'excluded';
175
- }
176
- return 'noop';
177
- }
178
- function scheduleItemAction(item) {
179
- if (item.blocked === true || item.status === 'collision') {
180
- return 'blocked';
181
- }
182
- if (item.status === 'create') {
183
- return 'create';
184
- }
185
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
186
- return 'update';
187
- }
188
- if (item.status === 'missing-lock') {
189
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
190
- }
191
- if (item.status === 'orphan' || item.status === 'skipped') {
192
- return 'excluded';
193
- }
194
- return 'noop';
195
- }
196
- function eventItemAction(item) {
197
- if (item.blocked === true || item.status === 'collision') {
198
- return 'blocked';
199
- }
200
- if (item.status === 'create') {
201
- return 'create';
202
- }
203
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
204
- return 'update';
205
- }
206
- if (item.status === 'missing-lock') {
207
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
208
- }
209
- if (item.status === 'orphan' || item.status === 'skipped' || item.status === 'activation-drift') {
210
- return 'excluded';
211
- }
212
- return 'noop';
213
- }
214
- function groupItemAction(item) {
215
- if (item.status === 'collision'
216
- || ((item.status === 'conflict' || item.status === 'missing-lock') && !item.currentHash)) {
217
- return 'blocked';
218
- }
219
- if (item.status === 'create') {
220
- return 'create';
221
- }
222
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
223
- return 'update';
224
- }
225
- if (item.status === 'missing-lock') {
226
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
227
- }
228
- if (item.status === 'manual-owner' || item.status === 'orphan' || item.status === 'skipped') {
229
- return 'excluded';
230
- }
231
- return 'noop';
232
- }
233
- function roleGroupItemAction(item) {
234
- if (item.status === 'collision' || (item.status === 'conflict' && !item.currentHash)) {
235
- return 'blocked';
236
- }
237
- if (item.status === 'create') {
238
- return 'create';
239
- }
240
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
241
- return 'update';
242
- }
243
- if (item.status === 'missing-lock') {
244
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
245
- }
246
- if (item.status === 'orphan' || item.status === 'skipped') {
247
- return 'excluded';
248
- }
249
- return 'noop';
250
- }
251
67
  function phaseVerdict(blockers, warnings) {
252
68
  if (blockers.length > 0) {
253
69
  return 'blocked';
@@ -257,7 +73,7 @@ function phaseVerdict(blockers, warnings) {
257
73
  function summarizeSchemaPhase(plan) {
258
74
  const operations = emptyOperations();
259
75
  for (const item of plan.items) {
260
- operations[schemaItemAction(item)] += 1;
76
+ operations[migrationItemOperation(item, schemaItemAction(item))] += 1;
261
77
  }
262
78
  const itemBlockers = plan.items
263
79
  .filter((item) => BLOCKING_SCHEMA_STATUSES.has(item.status) && Boolean(item.desiredHash))
@@ -281,7 +97,7 @@ function summarizeSchemaPhase(plan) {
281
97
  function summarizeViewPhase(plan) {
282
98
  const operations = emptyOperations();
283
99
  for (const item of plan.items) {
284
- operations[viewItemAction(item)] += 1;
100
+ operations[migrationItemOperation(item, viewItemAction(item))] += 1;
285
101
  }
286
102
  const itemBlockers = plan.items.flatMap((item) => {
287
103
  const identity = item.stableKey || item.name;
@@ -317,7 +133,7 @@ function summarizeViewPhase(plan) {
317
133
  function summarizeComponentPhase(plan) {
318
134
  const operations = emptyOperations();
319
135
  for (const item of plan.items) {
320
- operations[componentItemAction(item)] += 1;
136
+ operations[migrationItemOperation(item, componentItemAction(item))] += 1;
321
137
  }
322
138
  const warnings = [...new Set([
323
139
  ...(plan.unmanaged.local > 0
@@ -333,7 +149,7 @@ function summarizeComponentPhase(plan) {
333
149
  .filter((item) => item.status === 'remote-changed' || item.status === 'conflict')
334
150
  .map((item) => `Component "${item.stableKey || item.componentName}" has target drift; source-wins migration will overwrite its portable definition.`),
335
151
  ...plan.items
336
- .filter((item) => item.status === 'missing-lock')
152
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, componentItemAction(item)) !== 'noop')
337
153
  .map((item) => `Component "${item.stableKey || item.componentName}" has no target lock baseline; source-wins migration will align and verify it.`),
338
154
  ])];
339
155
  const blockers = [...new Set(plan.blockers)];
@@ -351,7 +167,7 @@ function summarizeComponentPhase(plan) {
351
167
  function summarizeJobTemplatePhase(plan) {
352
168
  const operations = emptyOperations();
353
169
  for (const item of plan.items) {
354
- operations[jobTemplateItemAction(item)] += 1;
170
+ operations[migrationItemOperation(item, jobTemplateItemAction(item))] += 1;
355
171
  }
356
172
  const warnings = [...new Set([
357
173
  ...plan.warnings,
@@ -360,7 +176,7 @@ function summarizeJobTemplatePhase(plan) {
360
176
  .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.desiredHash)))
361
177
  .map((item) => `Job Template "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
362
178
  ...plan.items
363
- .filter((item) => item.status === 'missing-lock')
179
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, jobTemplateItemAction(item)) !== 'noop')
364
180
  .map((item) => `Job Template "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
365
181
  ])];
366
182
  const blockers = [...new Set(plan.blockers)];
@@ -378,7 +194,7 @@ function summarizeJobTemplatePhase(plan) {
378
194
  function summarizeEndpointPhase(plan) {
379
195
  const operations = emptyOperations();
380
196
  for (const item of plan.items) {
381
- operations[endpointItemAction(item)] += 1;
197
+ operations[migrationItemOperation(item, endpointItemAction(item))] += 1;
382
198
  }
383
199
  const warnings = [...new Set([
384
200
  ...plan.warnings,
@@ -387,7 +203,7 @@ function summarizeEndpointPhase(plan) {
387
203
  .filter((item) => item.status === 'remote-changed' || item.status === 'conflict')
388
204
  .map((item) => `Endpoint "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
389
205
  ...plan.items
390
- .filter((item) => item.status === 'missing-lock')
206
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, endpointItemAction(item)) !== 'noop')
391
207
  .map((item) => `Endpoint "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
392
208
  ])];
393
209
  const blockers = [...new Set(plan.blockers)];
@@ -405,7 +221,7 @@ function summarizeEndpointPhase(plan) {
405
221
  function summarizeSchedulePhase(plan) {
406
222
  const operations = emptyOperations();
407
223
  for (const item of plan.items) {
408
- operations[scheduleItemAction(item)] += 1;
224
+ operations[migrationItemOperation(item, scheduleItemAction(item))] += 1;
409
225
  }
410
226
  const warnings = [...new Set([
411
227
  ...plan.warnings,
@@ -414,7 +230,7 @@ function summarizeSchedulePhase(plan) {
414
230
  .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && item.blocked !== true))
415
231
  .map((item) => `Schedule "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
416
232
  ...plan.items
417
- .filter((item) => item.status === 'missing-lock')
233
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, scheduleItemAction(item)) !== 'noop')
418
234
  .map((item) => `Schedule "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
419
235
  ])];
420
236
  const blockers = [...new Set(plan.blockers)];
@@ -432,7 +248,7 @@ function summarizeSchedulePhase(plan) {
432
248
  function summarizeEventPhase(plan) {
433
249
  const operations = emptyOperations();
434
250
  for (const item of plan.items) {
435
- operations[eventItemAction(item)] += 1;
251
+ operations[migrationItemOperation(item, eventItemAction(item))] += 1;
436
252
  }
437
253
  const warnings = [...new Set([
438
254
  ...plan.warnings,
@@ -441,7 +257,7 @@ function summarizeEventPhase(plan) {
441
257
  .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && item.blocked !== true))
442
258
  .map((item) => `Event "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
443
259
  ...plan.items
444
- .filter((item) => item.status === 'missing-lock')
260
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, eventItemAction(item)) !== 'noop')
445
261
  .map((item) => `Event "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
446
262
  ...plan.items
447
263
  .filter((item) => item.status === 'activation-drift')
@@ -462,7 +278,7 @@ function summarizeEventPhase(plan) {
462
278
  function summarizeGroupPhase(plan) {
463
279
  const operations = emptyOperations();
464
280
  for (const item of plan.items) {
465
- operations[groupItemAction(item)] += 1;
281
+ operations[migrationItemOperation(item, groupItemAction(item))] += 1;
466
282
  }
467
283
  const warnings = [...new Set([
468
284
  ...plan.warnings,
@@ -474,7 +290,7 @@ function summarizeGroupPhase(plan) {
474
290
  .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.currentHash)))
475
291
  .map((item) => `Group "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
476
292
  ...plan.items
477
- .filter((item) => item.status === 'missing-lock' && Boolean(item.currentHash))
293
+ .filter((item) => item.status === 'missing-lock' && Boolean(item.currentHash) && migrationItemOperation(item, groupItemAction(item)) !== 'noop')
478
294
  .map((item) => `Group "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
479
295
  ])];
480
296
  const blockers = [...new Set(plan.blockers)];
@@ -489,16 +305,10 @@ function summarizeGroupPhase(plan) {
489
305
  blockers,
490
306
  };
491
307
  }
492
- function serviceAccountItemAction(item) {
493
- if (item.status === 'manual-owner') {
494
- return 'excluded';
495
- }
496
- return roleGroupItemAction({ ...item, status: item.status });
497
- }
498
308
  function summarizeServiceAccountPhase(plan) {
499
309
  const operations = emptyOperations();
500
310
  for (const item of plan.items) {
501
- operations[serviceAccountItemAction(item)] += 1;
311
+ operations[migrationItemOperation(item, serviceAccountItemAction(item))] += 1;
502
312
  }
503
313
  const warnings = [...plan.exclusions,
504
314
  ...plan.items.filter((item) => item.status === 'manual-owner').map((item) => `Service account "${item.stableKey}": ${item.reason}.`),
@@ -510,7 +320,7 @@ function summarizeServiceAccountPhase(plan) {
510
320
  function summarizeRoleGroupPhase(plan) {
511
321
  const operations = emptyOperations();
512
322
  for (const item of plan.items) {
513
- operations[roleGroupItemAction(item)] += 1;
323
+ operations[migrationItemOperation(item, roleGroupItemAction(item))] += 1;
514
324
  }
515
325
  const warnings = [...new Set([
516
326
  ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
@@ -521,7 +331,7 @@ function summarizeRoleGroupPhase(plan) {
521
331
  .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.currentHash)))
522
332
  .map((item) => `Role Group "${item.stableKey || item.name}" has target drift; the final source-wins phase will overwrite its portable definition and role assignments.`),
523
333
  ...plan.items
524
- .filter((item) => item.status === 'missing-lock')
334
+ .filter((item) => item.status === 'missing-lock' && migrationItemOperation(item, roleGroupItemAction(item)) !== 'noop')
525
335
  .map((item) => `Role Group "${item.stableKey || item.name}" has no target lock baseline; the final phase will align or adopt it.`),
526
336
  ])];
527
337
  const blockers = [...new Set(plan.blockers)];
@@ -617,10 +427,11 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
617
427
  }
618
428
  const gates = [];
619
429
  const forceOperations = [];
620
- if (phase.resource === 'database-table' && plans.databaseSchemas) {
430
+ if (phase.resource === 'database-table' && plans.databaseSchemas && !input.prune) {
621
431
  for (const item of plans.databaseSchemas.items.filter((candidate) => candidate.status === 'delete-partition')) {
622
432
  const operation = {
623
433
  from: 'excluded',
434
+ item,
624
435
  message: `Database partition "${item.stableKey || item.name}" was previously managed and removed from the repository; deletion requires --force.`,
625
436
  };
626
437
  gates.push(operation);
@@ -634,6 +445,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
634
445
  if ((action === 'create' || action === 'update') && (item.databaseViewStableKey || targetTypeTransition)) {
635
446
  gates.push({
636
447
  from: action,
448
+ item,
637
449
  message: targetTypeTransition
638
450
  ? `Schedule "${item.stableKey || item.name}" target type transition requires --force for repository deployment.`
639
451
  : `Materialized View Schedule "${item.stableKey || item.name}" requires --force for repository deployment.`,
@@ -647,6 +459,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
647
459
  if (action === 'create' || action === 'update') {
648
460
  gates.push({
649
461
  from: action,
462
+ item,
650
463
  message: `Group "${item.stableKey || item.name}" can change environment access and requires --force for repository deployment.`,
651
464
  });
652
465
  }
@@ -658,6 +471,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
658
471
  if (action === 'create' || action === 'update') {
659
472
  gates.push({
660
473
  from: action,
474
+ item,
661
475
  message: `Service Account "${item.stableKey || item.name}" can change environment access and requires --force for repository deployment.`,
662
476
  });
663
477
  }
@@ -669,6 +483,7 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
669
483
  if (action === 'create' || action === 'update') {
670
484
  gates.push({
671
485
  from: action,
486
+ item,
672
487
  message: `Role Group "${item.stableKey || item.name}" can change environment authorization and requires --force for repository deployment.`,
673
488
  });
674
489
  }
@@ -677,8 +492,11 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
677
492
  const operations = { ...phase.operations };
678
493
  if (input.allowDestructive === true) {
679
494
  for (const operation of forceOperations) {
680
- operations[operation.from] = Math.max(0, operations[operation.from] - 1);
495
+ operations[operation.from] = Math.max(0, (operations[operation.from] || 0) - 1);
681
496
  operations.update += 1;
497
+ if (operation.item.operation !== undefined) {
498
+ operation.item.operation = 'update';
499
+ }
682
500
  }
683
501
  return {
684
502
  ...phase,
@@ -690,8 +508,11 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
690
508
  return phase;
691
509
  }
692
510
  for (const gate of gates) {
693
- operations[gate.from] = Math.max(0, operations[gate.from] - 1);
511
+ operations[gate.from] = Math.max(0, (operations[gate.from] || 0) - 1);
694
512
  operations.blocked += 1;
513
+ if (gate.item.operation !== undefined) {
514
+ gate.item.operation = 'blocked';
515
+ }
695
516
  }
696
517
  const blockers = [...new Set([...phase.blockers, ...gates.map((gate) => gate.message)])];
697
518
  return {
@@ -704,6 +525,44 @@ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
704
525
  };
705
526
  }
706
527
  function combinePlan(input) {
528
+ if (input.migrationInput.sourceMode === 'workspace') {
529
+ const lock = readComponentLock(requireProject(input.migrationInput).projectRoot);
530
+ const environment = targetKey(input.migrationInput);
531
+ const baselineByKey = (entries, normalize = (key) => key) => {
532
+ const baselines = new Map(Object.values(entries).map((entry) => [normalize(entry.stableKey), entry.environments[environment]?.remoteHash]));
533
+ return (item) => item.stableKey ? baselines.get(normalize(item.stableKey)) : undefined;
534
+ };
535
+ if (input.databaseSchemas) {
536
+ input.databaseSchemas = { ...input.databaseSchemas, items: projectRepositoryItems(input.databaseSchemas.items, schemaItemAction, (item) => item.stableKey ? lock.databaseSchemas[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
537
+ }
538
+ if (input.databaseViews) {
539
+ input.databaseViews = { ...input.databaseViews, items: projectRepositoryItems(input.databaseViews.items, viewItemAction, (item) => item.stableKey ? lock.databaseViews[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
540
+ }
541
+ if (input.components) {
542
+ input.components = { ...input.components, items: projectRepositoryItems(input.components.items, componentItemAction, (item) => item.lockHash) };
543
+ }
544
+ if (input.serviceAccounts) {
545
+ input.serviceAccounts = { ...input.serviceAccounts, items: projectRepositoryItems(input.serviceAccounts.items, serviceAccountItemAction, baselineByKey(lock.serviceAccounts)) };
546
+ }
547
+ if (input.jobTemplates) {
548
+ input.jobTemplates = { ...input.jobTemplates, items: projectRepositoryItems(input.jobTemplates.items, jobTemplateItemAction, baselineByKey(lock.jobTemplates)) };
549
+ }
550
+ if (input.endpoints) {
551
+ input.endpoints = { ...input.endpoints, items: projectRepositoryItems(input.endpoints.items, endpointItemAction, (item) => item.stableKey ? lock.endpoints[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
552
+ }
553
+ if (input.schedules) {
554
+ input.schedules = { ...input.schedules, items: projectRepositoryItems(input.schedules.items, scheduleItemAction, (item) => item.stableKey ? lock.schedules[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
555
+ }
556
+ if (input.events) {
557
+ input.events = { ...input.events, items: projectRepositoryItems(input.events.items, eventItemAction, (item) => item.stableKey ? lock.events[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
558
+ }
559
+ if (input.groups) {
560
+ input.groups = { ...input.groups, items: projectRepositoryItems(input.groups.items, groupItemAction, baselineByKey(lock.groups)) };
561
+ }
562
+ if (input.roleGroups) {
563
+ input.roleGroups = { ...input.roleGroups, items: projectRepositoryItems(input.roleGroups.items, roleGroupItemAction, baselineByKey(lock.roleGroups, normalizeStableKeyValue)) };
564
+ }
565
+ }
707
566
  const phases = [
708
567
  ...(input.databaseSchemas ? [summarizeSchemaPhase(input.databaseSchemas)] : []),
709
568
  ...(input.databaseViews ? [summarizeViewPhase(input.databaseViews)] : []),
@@ -795,7 +654,7 @@ function combinePlan(input) {
795
654
  const operations = emptyOperations();
796
655
  for (const phase of phases) {
797
656
  for (const key of Object.keys(operations)) {
798
- operations[key] += phase.operations[key];
657
+ operations[key] = (operations[key] || 0) + (phase.operations[key] || 0);
799
658
  }
800
659
  }
801
660
  const warnings = [...new Set(phases.flatMap((phase) => phase.warnings))];
@@ -1177,6 +1036,9 @@ async function planWorkspace(input) {
1177
1036
  }), undefined, input.detailedDiff === true))
1178
1037
  : undefined;
1179
1038
  const identities = await planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources });
1039
+ if (input.prune && input.sourceMode !== 'workspace')
1040
+ throw new Error('Prune requires repository plan/deploy; named migration remains upsert-only.');
1041
+ const prune = input.prune ? await buildWorkspacePrunePlan({ cwd: input.cwd, client, resources }) : undefined;
1180
1042
  const serviceAccounts = resources.includes('service-account')
1181
1043
  ? await runMigrationStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
1182
1044
  projectedIdentities: identities?.projection })) : undefined;
@@ -1190,6 +1052,7 @@ async function planWorkspace(input) {
1190
1052
  envName: environmentKey,
1191
1053
  stableKeyName,
1192
1054
  projectedServiceAccounts: identities?.projection.serviceAccounts,
1055
+ pruneBeforeUpsertIds: prune?.items.filter((item) => item.resource === 'job-template' && item.beforeUpserts).map((item) => item.targetId),
1193
1056
  ...(input.projectDependencies === true && components
1194
1057
  ? { projectedComponents: projectedComponentDependencies(components) }
1195
1058
  : {}),
@@ -1201,6 +1064,7 @@ async function planWorkspace(input) {
1201
1064
  cwd: input.cwd,
1202
1065
  envName: environmentKey,
1203
1066
  stableKeyName,
1067
+ includeDependencyBlockers: input.sourceMode === 'workspace',
1204
1068
  ...(input.projectDependencies === true && components
1205
1069
  ? { projectedComponents: projectedComponentDependencies(components) }
1206
1070
  : {}),
@@ -1269,6 +1133,28 @@ async function planWorkspace(input) {
1269
1133
  if (identities) {
1270
1134
  combined.identityOrder = identities.ordered.map(({ resource, stableKey }) => ({ resource, stableKey }));
1271
1135
  }
1136
+ if (prune) {
1137
+ combined.prune = prune;
1138
+ combined.pruneTargetKey = environmentKey;
1139
+ combined.policy.mode = 'reconcile';
1140
+ combined.operations.delete = combined.prune.items.length;
1141
+ combined.operations.blocked += combined.prune.blockers.length;
1142
+ for (const phase of combined.phases) {
1143
+ const removed = Math.min(phase.operations.excluded, combined.prune.items.filter((item) => item.resource === phase.resource).length);
1144
+ phase.operations.excluded -= removed;
1145
+ combined.operations.excluded -= removed;
1146
+ phase.warnings = phase.warnings.filter((warning) => !/target-only/i.test(warning)
1147
+ || !prune.items.some((item) => item.resource === phase.resource && warning.includes(`"${item.stableKey}"`)));
1148
+ }
1149
+ combined.warnings = combined.warnings.filter((warning) => !/target-only/i.test(warning)
1150
+ || !prune.items.some((item) => warning.includes(`"${item.stableKey}"`)));
1151
+ if (combined.jobTemplates)
1152
+ combined.jobTemplates.exclusions = combined.jobTemplates.exclusions.filter((exclusion) => !exclusion.includes('target-only orphans'));
1153
+ combined.blockers = [...new Set([...combined.blockers, ...combined.prune.blockers])];
1154
+ combined.readyToMigrate = combined.blockers.length === 0;
1155
+ combined.needsChanges ||= combined.prune.items.length > 0;
1156
+ combined.verdict = phaseVerdict(combined.blockers, combined.warnings);
1157
+ }
1272
1158
  return combined;
1273
1159
  }
1274
1160
  export async function buildMigrationPlan(input) {
@@ -1298,7 +1184,7 @@ export async function buildMigrationPlan(input) {
1298
1184
  }
1299
1185
  }
1300
1186
  function resultsAreComplete(results) {
1301
- return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1187
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped' || result.status === 'pruned');
1302
1188
  }
1303
1189
  function componentResultsAreComplete(results) {
1304
1190
  return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
@@ -1330,6 +1216,11 @@ export async function runMigration(input) {
1330
1216
  sourcePullMode,
1331
1217
  projectDependencies: true,
1332
1218
  });
1219
+ if (input.reviewedPrune && (!initialPlan.prune || !samePrunePlan(input.reviewedPrune, initialPlan.prune))) {
1220
+ initialPlan.blockers.push('Deletion plan changed after confirmation; review the fresh plan before deploying.');
1221
+ initialPlan.readyToMigrate = false;
1222
+ initialPlan.verdict = 'blocked';
1223
+ }
1333
1224
  const base = {
1334
1225
  schemaVersion: 2,
1335
1226
  command: 'run',
@@ -1347,6 +1238,15 @@ export async function runMigration(input) {
1347
1238
  const environmentKey = targetKey(input);
1348
1239
  const phaseResults = {};
1349
1240
  const results = [];
1241
+ let remainingPrune = initialPlan.prune;
1242
+ if (remainingPrune?.items.some((item) => item.beforeUpserts)) {
1243
+ const pruned = await applyWorkspacePrune({ cwd: input.cwd, client: targetClient,
1244
+ resources, envName: environmentKey, plan: remainingPrune, beforeUpsertsOnly: true });
1245
+ results.push(...pruned);
1246
+ if (!resultsAreComplete(pruned))
1247
+ return { ...base, verdict: 'failed', results, phaseResults };
1248
+ remainingPrune = { ...remainingPrune, items: remainingPrune.items.filter((item) => !item.beforeUpserts) };
1249
+ }
1350
1250
  if (resources.includes('database-table')) {
1351
1251
  const pushed = await pushDatabaseSchemas({
1352
1252
  client: targetClient,
@@ -1354,8 +1254,8 @@ export async function runMigration(input) {
1354
1254
  envName: environmentKey,
1355
1255
  stableKeyName,
1356
1256
  force: true,
1357
- prunePartitions: reviewedWorkspaceChanges,
1358
- prunePartitionsConfirmed: reviewedWorkspaceChanges,
1257
+ prunePartitions: reviewedWorkspaceChanges && !input.prune,
1258
+ prunePartitionsConfirmed: reviewedWorkspaceChanges && !input.prune,
1359
1259
  migrationPolicy: migrationPolicy(input),
1360
1260
  });
1361
1261
  phaseResults['database-table'] = pushed.results;
@@ -1534,6 +1434,7 @@ export async function runMigration(input) {
1534
1434
  cwd: input.cwd,
1535
1435
  envName: environmentKey,
1536
1436
  stableKeyName,
1437
+ includeDependencyBlockers: input.sourceMode === 'workspace',
1537
1438
  });
1538
1439
  const liveEndpointPhase = summarizeEndpointPhase(liveEndpointPlan);
1539
1440
  if (!liveEndpointPhase.readyToMigrate) {
@@ -1705,6 +1606,16 @@ export async function runMigration(input) {
1705
1606
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1706
1607
  }
1707
1608
  }
1609
+ if (remainingPrune) {
1610
+ const fresh = await buildWorkspacePrunePlan({ cwd: input.cwd, client: targetClient, resources });
1611
+ if (!samePrunePlan(remainingPrune, fresh)) {
1612
+ results.push({ status: 'failed', targetPath: 'workspace prune', reason: 'Deletion plan changed during upserts; review a fresh plan.' });
1613
+ return { ...base, verdict: 'failed', results, phaseResults };
1614
+ }
1615
+ const pruneResults = await applyWorkspacePrune({ cwd: input.cwd, client: targetClient,
1616
+ resources, envName: environmentKey, plan: remainingPrune });
1617
+ results.push(...pruneResults);
1618
+ }
1708
1619
  const verification = await planWorkspace({
1709
1620
  ...input,
1710
1621
  pulls,
@@ -58,6 +58,7 @@ export type EndpointPlanItem = {
58
58
  values: string;
59
59
  }>;
60
60
  dependencies?: EndpointDependencyEdge[];
61
+ dependencyBlockers?: string[];
61
62
  routeDependencies?: string[];
62
63
  targetRevisionHash?: string;
63
64
  };
@@ -109,6 +110,7 @@ export declare function buildEndpointsPlan(input: {
109
110
  envName: string;
110
111
  stableKeyName: string;
111
112
  projectedComponents?: ProjectedEndpointComponentDependency[];
113
+ includeDependencyBlockers?: boolean;
112
114
  }): Promise<EndpointPlan>;
113
115
  export declare function pushEndpoints(input: {
114
116
  client: RevoClient;
@@ -930,6 +930,10 @@ export async function buildEndpointsPlan(input) {
930
930
  projectedComponents: projectedComponentsByKey,
931
931
  });
932
932
  warnings.push(...dependency.warnings);
933
+ // Repository operation classification needs item-level gates without changing legacy family statuses.
934
+ const dependencyBlockers = input.includeDependencyBlockers && dependency.blockers.length > 0
935
+ ? { dependencyBlockers: [...dependency.blockers] }
936
+ : {};
933
937
  const desiredHash = hashPortableEndpoint(desired);
934
938
  if (ambiguousTargetKeys.has(stableKey) || targetIssueKeys.has(stableKey)) {
935
939
  continue;
@@ -951,6 +955,7 @@ export async function buildEndpointsPlan(input) {
951
955
  const restoreBlocked = dependency.blockers.length > 0 || restoreSafety.length > 0;
952
956
  items.push({
953
957
  status: restoreBlocked ? 'restore-blocked' : 'restore',
958
+ ...dependencyBlockers,
954
959
  stableKey,
955
960
  name: desired.name,
956
961
  desiredHash,
@@ -979,6 +984,7 @@ export async function buildEndpointsPlan(input) {
979
984
  if (targets.length === 0) {
980
985
  items.push({
981
986
  status: 'create',
987
+ ...dependencyBlockers,
982
988
  stableKey,
983
989
  name: desired.name,
984
990
  desiredHash,
@@ -995,6 +1001,7 @@ export async function buildEndpointsPlan(input) {
995
1001
  const current = targets[0];
996
1002
  const baselineHash = lock.endpoints[stableKey]?.environments[input.envName]?.remoteHash;
997
1003
  const common = {
1004
+ ...dependencyBlockers,
998
1005
  stableKey,
999
1006
  name: desired.name,
1000
1007
  desiredHash,