@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,3 +1,8 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { normalizeStableKeyValue } from "../resource-metadata.js";
4
+ import { samePrunePlan } from "../workspace-prune.js";
5
+ import { schemaItemAction, viewItemAction, componentItemAction, jobTemplateItemAction, endpointItemAction, scheduleItemAction, eventItemAction, groupItemAction, roleGroupItemAction, } from "../migration-actions.js";
1
6
  import { DEFAULT_ENV_NAME } from "../config.js";
2
7
  import { buildMigrationPlan, pullResourcesToWorkspace, runMigration, } from "../migration.js";
3
8
  import { isInteractiveTerminal, promptConfirm } from "../prompt.js";
@@ -100,13 +105,20 @@ function readMigrationInput(context) {
100
105
  allowDestructive: readBoolFlag(context.args, ['force', 'f']),
101
106
  };
102
107
  }
108
+ function retainedPlanItems(plan, resource, items) {
109
+ const removed = new Set(plan.prune?.items.filter((item) => item.resource === resource).map((item) => normalizeStableKeyValue(item.stableKey)));
110
+ return items.filter((item) => !item.stableKey || !removed.has(normalizeStableKeyValue(item.stableKey)));
111
+ }
112
+ function baselineHints(item, existing = []) {
113
+ return [...(item.baselineAction ? [{ label: 'baseline', values: item.baselineAction }] : []), ...existing];
114
+ }
103
115
  function printMigrationPlan(context, plan) {
104
116
  const phaseLabel = plan.from === 'workspace' ? 'Deployment plan' : 'Migration';
105
117
  context.println(`${phaseLabel} ${plan.from} -> ${plan.to}`);
106
118
  context.println(`Resources: ${plan.resources.join(' -> ')}.`);
107
119
  context.println(`Ready to ${plan.from === 'workspace' ? 'deploy' : 'migrate'}: ${plan.readyToMigrate ? 'yes' : 'no'}.`);
108
120
  context.println(`Changes required: ${plan.needsChanges ? 'yes' : 'no'}; verdict: ${plan.verdict}.`);
109
- context.println(`Summary: create ${plan.operations.create}, update ${plan.operations.update}, adopt ${plan.operations.adopt}, unchanged ${plan.operations.noop}, excluded ${plan.operations.excluded}, blocked ${plan.operations.blocked}.`);
121
+ context.println(`Summary: create ${plan.operations.create}, update ${plan.operations.update}${plan.prune ? `, delete ${plan.operations.delete || 0}` : ''}, adopt ${plan.operations.adopt}, unchanged ${plan.operations.noop}, excluded ${plan.operations.excluded}, blocked ${plan.operations.blocked}.`);
110
122
  context.println(`Diagnostics: ${plan.warnings.length} warning(s), ${plan.blockers.length} blocker(s).`);
111
123
  if (plan.sourcePull.mode === 'repository') {
112
124
  context.println('Source snapshot: repository workspace (no remote source pull).');
@@ -131,13 +143,13 @@ function printMigrationPlan(context, plan) {
131
143
  environment: plan.to,
132
144
  counts: phase.operations,
133
145
  showHints: readBoolFlag(context.args, ['hints']),
134
- items: plan.databaseSchemas.items.map((item) => ({
135
- status: schemaItemActionLabel(item),
146
+ items: retainedPlanItems(plan, 'database-table', plan.databaseSchemas.items).map((item) => ({
147
+ status: migrationItemActionLabel(item, schemaItemAction(item)),
136
148
  target: item.stableKey || item.name,
137
149
  reason: item.reason,
138
150
  changedFields: item.changedFields,
139
151
  details: planValueChanges(item.changes || []),
140
- hints: item.hints.length > 0 ? [{ label: 'hints', values: item.hints }] : undefined,
152
+ hints: baselineHints(item, item.hints.length > 0 ? [{ label: 'hints', values: item.hints }] : undefined),
141
153
  })),
142
154
  warnings: phase.warnings,
143
155
  blockers: phase.blockers,
@@ -149,8 +161,8 @@ function printMigrationPlan(context, plan) {
149
161
  environment: plan.to,
150
162
  counts: phase.operations,
151
163
  showHints: readBoolFlag(context.args, ['hints']),
152
- items: plan.databaseViews.items.map((item) => ({
153
- status: viewItemActionLabel(item),
164
+ items: retainedPlanItems(plan, 'database-view', plan.databaseViews.items).map((item) => ({
165
+ status: migrationItemActionLabel(item, item.status === 'validation-failed' ? item.status : viewItemAction(item)),
154
166
  target: item.stableKey || item.name,
155
167
  reason: item.reason,
156
168
  changedFields: item.changedFields,
@@ -159,9 +171,9 @@ function printMigrationPlan(context, plan) {
159
171
  ...(item.rawQueryDiff?.length ? [{ label: 'rawQuery diff', lines: item.rawQueryDiff }] : []),
160
172
  ...(item.risks?.length ? [{ label: 'risks', values: item.risks }] : []),
161
173
  ],
162
- hints: item.scheduleDependencies?.length
174
+ hints: baselineHints(item, item.scheduleDependencies?.length
163
175
  ? [{ label: 'schedule dependencies', values: item.scheduleDependencies }]
164
- : undefined,
176
+ : undefined),
165
177
  })),
166
178
  warnings: phase.warnings,
167
179
  blockers: phase.blockers,
@@ -173,8 +185,8 @@ function printMigrationPlan(context, plan) {
173
185
  environment: plan.to,
174
186
  counts: phase.operations,
175
187
  showHints: readBoolFlag(context.args, ['hints']),
176
- items: plan.components.items.map((item) => ({
177
- status: componentItemActionLabel(item),
188
+ items: retainedPlanItems(plan, 'component', plan.components.items).map((item) => ({
189
+ status: migrationItemActionLabel(item, componentItemAction(item)),
178
190
  target: item.stableKey || item.path,
179
191
  reason: item.reason,
180
192
  changedFields: item.status === 'create' ? undefined : item.changedFields,
@@ -182,9 +194,9 @@ function printMigrationPlan(context, plan) {
182
194
  details: item.status === 'create' ? undefined : [
183
195
  ...(item.codeDiffs || []).map((code) => ({ label: `element ${code.element}`, lines: code.lines })),
184
196
  ],
185
- hints: item.status !== 'create' && item.componentType
197
+ hints: baselineHints(item, item.status !== 'create' && item.componentType
186
198
  ? [{ label: 'type', values: item.componentType }]
187
- : undefined,
199
+ : undefined),
188
200
  })),
189
201
  warnings: phase.warnings,
190
202
  blockers: phase.blockers,
@@ -192,7 +204,11 @@ function printMigrationPlan(context, plan) {
192
204
  }
193
205
  if (phase.resource === 'service-account' && plan.serviceAccounts) {
194
206
  printSyncPlan(context.println, { title: `${phaseLabel} phase ${phase.order} / Service Account`, environment: plan.to,
195
- counts: phase.operations, items: plan.serviceAccounts.items, warnings: phase.warnings, blockers: phase.blockers });
207
+ counts: phase.operations, showHints: readBoolFlag(context.args, ['hints']),
208
+ items: retainedPlanItems(plan, 'service-account', plan.serviceAccounts.items).map((item) => ({ ...item,
209
+ status: item.operation ?? item.status,
210
+ hints: baselineHints(item),
211
+ })), warnings: phase.warnings, blockers: phase.blockers });
196
212
  }
197
213
  if (phase.resource === 'job-template' && plan.jobTemplates) {
198
214
  printSyncPlan(context.println, {
@@ -200,16 +216,16 @@ function printMigrationPlan(context, plan) {
200
216
  environment: plan.to,
201
217
  counts: phase.operations,
202
218
  showHints: readBoolFlag(context.args, ['hints']),
203
- items: plan.jobTemplates.items.map((item) => ({
204
- status: jobTemplateItemActionLabel(item),
219
+ items: retainedPlanItems(plan, 'job-template', plan.jobTemplates.items).map((item) => ({
220
+ status: migrationItemActionLabel(item, jobTemplateItemAction(item)),
205
221
  target: item.stableKey || item.name,
206
222
  reason: item.reason,
207
223
  changedFields: item.changedFields,
208
224
  fieldChanges: item.fieldChanges,
209
- hints: [
225
+ hints: baselineHints(item, [
210
226
  ...(item.componentStableKey ? [{ label: 'component', values: item.componentStableKey }] : []),
211
227
  ...(item.dependencyReadiness ? [{ label: 'dependency', values: item.dependencyReadiness }] : []),
212
- ],
228
+ ]),
213
229
  })),
214
230
  warnings: phase.warnings,
215
231
  blockers: phase.blockers,
@@ -221,13 +237,13 @@ function printMigrationPlan(context, plan) {
221
237
  environment: plan.to,
222
238
  counts: phase.operations,
223
239
  showHints: readBoolFlag(context.args, ['hints']),
224
- items: plan.endpoints.items.map((item) => ({
225
- status: endpointItemActionLabel(item),
240
+ items: retainedPlanItems(plan, 'endpoint', plan.endpoints.items).map((item) => ({
241
+ status: migrationItemActionLabel(item, endpointItemAction(item)),
226
242
  target: item.stableKey || item.name,
227
243
  reason: item.reason,
228
244
  changedFields: item.changedFields,
229
245
  fieldChanges: item.fieldChanges,
230
- hints: [
246
+ hints: baselineHints(item, [
231
247
  ...(item.details || []),
232
248
  ...(item.dependencies || []).map((dependency) => ({
233
249
  label: `${dependency.relation} dependency`,
@@ -236,7 +252,7 @@ function printMigrationPlan(context, plan) {
236
252
  ...(item.routeDependencies?.length
237
253
  ? [{ label: 'route waits for', values: item.routeDependencies.join(', ') }]
238
254
  : []),
239
- ],
255
+ ]),
240
256
  })),
241
257
  warnings: phase.warnings,
242
258
  blockers: phase.blockers,
@@ -248,13 +264,13 @@ function printMigrationPlan(context, plan) {
248
264
  environment: plan.to,
249
265
  counts: phase.operations,
250
266
  showHints: readBoolFlag(context.args, ['hints']),
251
- items: plan.schedules.items.map((item) => ({
252
- status: scheduleItemActionLabel(item),
267
+ items: retainedPlanItems(plan, 'schedule', plan.schedules.items).map((item) => ({
268
+ status: migrationItemActionLabel(item, scheduleItemAction(item)),
253
269
  target: item.stableKey || item.name,
254
270
  reason: item.reason,
255
271
  changedFields: item.changedFields,
256
272
  fieldChanges: item.fieldChanges,
257
- hints: item.dependency ? planDependencyHints(item.dependency) : undefined,
273
+ hints: baselineHints(item, item.dependency ? planDependencyHints(item.dependency) : undefined),
258
274
  })),
259
275
  warnings: phase.warnings,
260
276
  blockers: phase.blockers,
@@ -266,15 +282,15 @@ function printMigrationPlan(context, plan) {
266
282
  environment: plan.to,
267
283
  counts: phase.operations,
268
284
  showHints: readBoolFlag(context.args, ['hints']),
269
- items: plan.events.items.map((item) => ({
270
- status: eventItemActionLabel(item),
285
+ items: retainedPlanItems(plan, 'event', plan.events.items).map((item) => ({
286
+ status: migrationItemActionLabel(item, eventItemAction(item)),
271
287
  target: item.stableKey || item.name,
272
288
  reason: item.reason,
273
289
  changedFields: item.changedFields,
274
290
  fieldChanges: item.fieldChanges,
275
- hints: item.dependency
291
+ hints: baselineHints(item, item.dependency
276
292
  ? planDependencyHints({ ...item.dependency, resource: 'job-template' })
277
- : undefined,
293
+ : undefined),
278
294
  })),
279
295
  warnings: phase.warnings,
280
296
  blockers: phase.blockers,
@@ -286,15 +302,15 @@ function printMigrationPlan(context, plan) {
286
302
  environment: plan.to,
287
303
  counts: phase.operations,
288
304
  showHints: readBoolFlag(context.args, ['hints']),
289
- items: plan.groups.items.map((item) => ({
290
- status: groupItemActionLabel(item),
305
+ items: retainedPlanItems(plan, 'group', plan.groups.items).map((item) => ({
306
+ status: migrationItemActionLabel(item, groupItemAction(item)),
291
307
  target: item.stableKey || item.name,
292
308
  reason: item.reason,
293
309
  changedFields: item.changedFields,
294
310
  fieldChanges: item.fieldChanges,
295
- hints: item.ownerStableKey
311
+ hints: baselineHints(item, item.ownerStableKey
296
312
  ? [{ label: 'owner', values: item.ownerStableKey }]
297
- : undefined,
313
+ : undefined),
298
314
  })),
299
315
  warnings: phase.warnings,
300
316
  blockers: phase.blockers,
@@ -306,162 +322,37 @@ function printMigrationPlan(context, plan) {
306
322
  environment: plan.to,
307
323
  counts: phase.operations,
308
324
  showHints: readBoolFlag(context.args, ['hints']),
309
- items: plan.roleGroups.items.map((item) => ({
310
- status: roleGroupItemActionLabel(item),
325
+ items: retainedPlanItems(plan, 'role-group', plan.roleGroups.items).map((item) => ({
326
+ status: migrationItemActionLabel(item, roleGroupItemAction(item)),
311
327
  target: item.stableKey || item.name,
312
328
  reason: item.reason,
313
329
  changedFields: item.changedFields,
314
330
  fieldChanges: item.fieldChanges,
315
331
  details: planListChanges('roles', item.rolesToRemove, item.rolesToAdd),
332
+ hints: baselineHints(item),
316
333
  })),
317
334
  warnings: phase.warnings,
318
335
  blockers: phase.blockers,
319
336
  });
320
337
  }
321
338
  }
322
- }
323
- function schemaItemActionLabel(item) {
324
- if (item.status === 'missing-lock') {
325
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
326
- }
327
- if (item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'safe-update') {
328
- return 'update';
329
- }
330
- if (item.status === 'reconciled') {
331
- return 'adopt';
332
- }
333
- if (item.status === 'manual-schema-migration-required'
334
- || item.status === 'access-policy-required'
335
- || item.status === 'previously-deleted-partition'
336
- || item.status === 'replacement-requires-two-phases'
337
- || item.status === 'collision') {
338
- return 'blocked';
339
- }
340
- if (item.status === 'orphan-root'
341
- || item.status === 'orphan-partition'
342
- || item.status === 'delete-partition'
343
- || item.status === 'unmanaged') {
344
- return 'excluded';
345
- }
346
- return item.status;
347
- }
348
- function viewItemActionLabel(item) {
349
- if (item.status === 'collision' || (item.status === 'conflict' && item.reason)) {
350
- return 'blocked';
351
- }
352
- if (item.status === 'missing-lock') {
353
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
354
- }
355
- if (item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'safe-update') {
356
- return 'update';
357
- }
358
- if (item.status === 'orphan' || item.status === 'skipped') {
359
- return 'excluded';
360
- }
361
- return item.status;
362
- }
363
- function componentItemActionLabel(item) {
364
- if (item.status === 'clean' && item.lockHash === null && item.localHash !== null && item.localHash === item.remoteHash) {
365
- return 'adopt';
366
- }
367
- if (item.status === 'local-changed' || item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'missing-lock') {
368
- return 'update';
369
- }
370
- if (item.status === 'safe-update') {
371
- return 'excluded';
372
- }
373
- return item.status;
374
- }
375
- function jobTemplateItemActionLabel(item) {
376
- if (item.status === 'collision' || (item.status === 'conflict' && !item.desiredHash)) {
377
- return 'blocked';
378
- }
379
- if (item.status === 'missing-lock') {
380
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
381
- }
382
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
383
- return 'update';
384
- }
385
- if (item.status === 'orphan' || item.status === 'skipped') {
386
- return 'excluded';
387
- }
388
- return item.status;
389
- }
390
- function endpointItemActionLabel(item) {
391
- if (item.status === 'restore-blocked' || item.status === 'collision') {
392
- return 'blocked';
393
- }
394
- if (item.status === 'restore' || item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
395
- return 'update';
396
- }
397
- if (item.status === 'missing-lock') {
398
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
399
- }
400
- if (item.status === 'orphan' || item.status === 'skipped') {
401
- return 'excluded';
402
- }
403
- return item.status;
404
- }
405
- function scheduleItemActionLabel(item) {
406
- if (item.blocked === true || item.status === 'collision') {
407
- return 'blocked';
408
- }
409
- if (item.status === 'missing-lock') {
410
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
411
- }
412
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
413
- return 'update';
414
- }
415
- if (item.status === 'orphan' || item.status === 'skipped') {
416
- return 'excluded';
417
- }
418
- return item.status;
419
- }
420
- function eventItemActionLabel(item) {
421
- if (item.blocked === true || item.status === 'collision') {
422
- return 'blocked';
423
- }
424
- if (item.status === 'missing-lock') {
425
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
426
- }
427
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
428
- return 'update';
429
- }
430
- if (item.status === 'orphan' || item.status === 'skipped' || item.status === 'activation-drift') {
431
- return 'excluded';
432
- }
433
- return item.status;
434
- }
435
- function groupItemActionLabel(item) {
436
- if (item.status === 'collision'
437
- || ((item.status === 'conflict' || item.status === 'missing-lock') && !item.currentHash)) {
438
- return 'blocked';
439
- }
440
- if (item.status === 'missing-lock') {
441
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
442
- }
443
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
444
- return 'update';
445
- }
446
- if (item.status === 'manual-owner' || item.status === 'orphan' || item.status === 'skipped') {
447
- return 'excluded';
339
+ if (plan.prune) {
340
+ for (const beforeUpserts of [true, false]) {
341
+ const items = plan.prune.items.filter((item) => Boolean(item.beforeUpserts) === beforeUpserts);
342
+ if (beforeUpserts && items.length === 0)
343
+ continue;
344
+ printSyncPlan(context.println, {
345
+ title: beforeUpserts ? 'Deletion before upserts to release conflicting names' : 'Deletion after verified upserts', environment: plan.to,
346
+ counts: { delete: items.length },
347
+ items: items.map((item) => ({ status: 'delete', target: `${item.resource}:${item.stableKey}`,
348
+ details: [{ label: 'target', values: item.targetId }, { label: 'name', values: item.name }] })),
349
+ blockers: plan.prune.blockers,
350
+ });
351
+ }
448
352
  }
449
- return item.status;
450
353
  }
451
- function roleGroupItemActionLabel(item) {
452
- if (item.status === 'collision' || (item.status === 'conflict' && !item.currentHash)) {
453
- return 'blocked';
454
- }
455
- if (item.status === 'missing-lock') {
456
- return item.desiredHash === item.currentHash ? 'adopt' : 'update';
457
- }
458
- if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
459
- return 'update';
460
- }
461
- if (item.status === 'orphan' || item.status === 'skipped') {
462
- return 'excluded';
463
- }
464
- return item.status;
354
+ function migrationItemActionLabel(item, legacyAction) {
355
+ return item.operation ?? (legacyAction === 'noop' ? item.status : legacyAction);
465
356
  }
466
357
  async function confirmRun(context, from, to) {
467
358
  if (readBoolFlag(context.args, ['yes', 'y'])) {
@@ -484,7 +375,8 @@ async function readWorkspaceDeploymentInput(context) {
484
375
  to: context.client.baseUrl,
485
376
  resources,
486
377
  withStats: readBoolFlag(context.args, ['with-stats']),
487
- allowDestructive: readBoolFlag(context.args, ['force', 'f']),
378
+ allowDestructive: readBoolFlag(context.args, ['force', 'f']) || readBoolFlag(context.args, ['prune']),
379
+ prune: readBoolFlag(context.args, ['prune']),
488
380
  sourceMode: 'workspace',
489
381
  targetClient: context.client,
490
382
  targetKey: `instance:${authenticatedInstance}`,
@@ -507,6 +399,12 @@ async function handleMigrationRead(context, input, command) {
507
399
  }
508
400
  return;
509
401
  }
402
+ const outputFile = readFlag(context.args, ['out']);
403
+ if (outputFile) {
404
+ if (command !== 'plan')
405
+ throw new Error('--out is supported by plan only.');
406
+ fs.writeFileSync(path.resolve(context.cwd, outputFile), `${JSON.stringify(plan, null, 2)}\n`, { mode: 0o600 });
407
+ }
510
408
  if (readBoolFlag(context.args, ['json'])) {
511
409
  context.print({ ...plan, command });
512
410
  }
@@ -519,13 +417,15 @@ async function handleMigrationRead(context, input, command) {
519
417
  }
520
418
  if (command === 'plan' && input.sourceMode === 'workspace'
521
419
  && readBoolFlag(context.args, ['strict']) && plan.needsChanges) {
522
- throw new Error(`Deployment strict plan has pending changes: ${plan.operations.create} create, ${plan.operations.update} update.`);
420
+ throw new Error(`Deployment strict plan has pending changes: ${plan.operations.create} create, ${plan.operations.update} update${plan.prune ? `, ${plan.operations.delete || 0} delete` : ''}.`);
523
421
  }
524
422
  if (command === 'verify' && plan.needsChanges) {
525
423
  throw new Error('Migration verification failed: target still requires changes.');
526
424
  }
527
425
  }
528
426
  export async function handleDiffCommand(context) {
427
+ if (readBoolFlag(context.args, ['prune']))
428
+ throw new Error('Review deletions with revo plan --prune; diff compares content only.');
529
429
  if (readBoolFlag(context.args, ['force', 'f'])) {
530
430
  throw new Error('Repository diff only compares content. Use revo plan --force to review force-gated deployment operations.');
531
431
  }
@@ -618,15 +518,16 @@ async function confirmDeploy(context) {
618
518
  if (readBoolFlag(context.args, ['yes', 'y'])) {
619
519
  return;
620
520
  }
621
- if (!isInteractiveTerminal() || !await promptConfirm(`Deploy the tracked workspace to "${context.client.baseUrl}"?`, false)) {
521
+ if (!isInteractiveTerminal() || !await promptConfirm(`Apply the displayed deployment plan to "${context.client.baseUrl}"${readBoolFlag(context.args, ['prune']) ? ', including all listed deletions' : ''}?`, false)) {
622
522
  throw new Error('Deployment requires confirmation. Re-run with --yes or use an interactive terminal.');
623
523
  }
624
524
  }
625
- function printRunResult(context, result) {
626
- printMigrationPlan(context, result.plan);
525
+ function printRunResult(context, result, showPlan = true) {
526
+ if (showPlan)
527
+ printMigrationPlan(context, result.plan);
627
528
  for (const item of result.results) {
628
529
  printSyncStatus(context.println, {
629
- status: item.status === 'deployed' ? 'Deployed' : item.status === 'write-unverified' ? 'Unverified' : item.status === 'failed' ? 'Failed' : 'Skipped',
530
+ status: item.status === 'deployed' ? 'Deployed' : item.status === 'pruned' ? 'Pruned' : item.status === 'write-unverified' ? 'Unverified' : item.status === 'failed' ? 'Failed' : 'Skipped',
630
531
  direction: 'push',
631
532
  targetPath: item.targetPath,
632
533
  reason: ('error' in item ? item.error : undefined) || item.reason,
@@ -635,14 +536,38 @@ function printRunResult(context, result) {
635
536
  context.println(`Final verdict: ${result.verdict}.`);
636
537
  }
637
538
  export async function handleDeployCommand(context) {
539
+ if (readBoolFlag(context.args, ['changed']) || readFlag(context.args, ['base']) || readValues(context.args, ['resources', 'resource']).length > 0) {
540
+ throw new Error('Repository deployment evaluates all tracked resources; select resources in .revoengine/revo.json.');
541
+ }
542
+ const input = { ...await readWorkspaceDeploymentInput(context), detailedDiff: true };
543
+ const preview = await buildMigrationPlan(input);
544
+ const reviewedFile = readFlag(context.args, ['reviewed-plan']);
545
+ if (reviewedFile) {
546
+ if (!input.prune)
547
+ throw new Error('--reviewed-plan requires --prune.');
548
+ const reviewed = JSON.parse(fs.readFileSync(path.resolve(context.cwd, reviewedFile), 'utf8'));
549
+ if (!reviewed.readyToMigrate || reviewed.schemaVersion !== 2 || reviewed.command !== 'plan'
550
+ || !reviewed.prune || !preview.prune || reviewed.pruneTargetKey !== preview.pruneTargetKey
551
+ || JSON.stringify(reviewed.resources) !== JSON.stringify(preview.resources)
552
+ || !samePrunePlan(reviewed.prune, preview.prune)) {
553
+ throw new Error('Reviewed deletion plan does not match this instance, resource scope or live target; run plan again.');
554
+ }
555
+ }
556
+ // Interactive confirmation must always expose the plan, including JSON mode.
557
+ if (!readBoolFlag(context.args, ['json']))
558
+ printMigrationPlan(context, preview);
559
+ else if (!readBoolFlag(context.args, ['yes', 'y']))
560
+ printMigrationPlan({ ...context, println: context.error }, preview);
561
+ if (!preview.readyToMigrate)
562
+ throw new Error(`Deployment plan is blocked by ${preview.blockers.length} issue(s).`);
638
563
  await confirmDeploy(context);
639
564
  const startedAt = Date.now();
640
- const result = await runMigration({ ...await readWorkspaceDeploymentInput(context), detailedDiff: true });
565
+ const result = await runMigration({ ...input, reviewedPrune: preview.prune });
641
566
  if (readBoolFlag(context.args, ['json'])) {
642
567
  context.print({ ...result, command: 'deploy' });
643
568
  }
644
569
  else {
645
- printRunResult(context, result);
570
+ printRunResult(context, result, false);
646
571
  printSyncSummary(context.println, 'Deployed', result.results, Date.now() - startedAt);
647
572
  }
648
573
  if (result.verdict !== 'succeeded') {
@@ -650,6 +575,8 @@ export async function handleDeployCommand(context) {
650
575
  }
651
576
  }
652
577
  export async function handleMigrateCommand(context) {
578
+ if (readBoolFlag(context.args, ['prune']))
579
+ throw new Error('Prune requires repository plan/deploy; named migration remains upsert-only.');
653
580
  const requestedSubcommand = context.args._[1] || 'plan';
654
581
  const dryRun = readBoolFlag(context.args, ['dry-run']);
655
582
  const subcommand = dryRun ? 'plan' : requestedSubcommand;
@@ -0,0 +1,44 @@
1
+ import type { MigrationOperations } from './migration.ts';
2
+ import type { ComponentPlanItem } from './commands/component.ts';
3
+ import type { DatabaseSchemaPlanItem, DatabaseSchemaPlanStatus } from './resource-syncs/database-table-sync.ts';
4
+ import type { DatabaseViewPlanItem } from './resource-syncs/database-view-sync.ts';
5
+ import type { JobTemplatePlanItem } from './resource-syncs/job-template-sync.ts';
6
+ import type { EndpointPlanItem } from './resource-syncs/endpoint-sync.ts';
7
+ import type { SchedulePlanItem } from './resource-syncs/schedule-sync.ts';
8
+ import type { EventPlanItem } from './resource-syncs/event-sync.ts';
9
+ import type { GroupPlanItem } from './resource-syncs/group-sync.ts';
10
+ import type { RoleGroupPlanItem } from './resource-syncs/role-group-sync.ts';
11
+ import type { ServiceAccountPlanItem } from './resource-syncs/service-account-sync.ts';
12
+ export declare const BLOCKING_SCHEMA_STATUSES: Set<DatabaseSchemaPlanStatus>;
13
+ export declare function schemaItemAction(item: DatabaseSchemaPlanItem): keyof MigrationOperations;
14
+ export declare function viewItemIsBlocked(item: DatabaseViewPlanItem): boolean;
15
+ export declare function viewItemAction(item: DatabaseViewPlanItem): keyof MigrationOperations;
16
+ export declare function componentItemAction(item: ComponentPlanItem): keyof MigrationOperations;
17
+ export declare function jobTemplateItemAction(item: JobTemplatePlanItem): keyof MigrationOperations;
18
+ export declare function endpointItemAction(item: EndpointPlanItem): keyof MigrationOperations;
19
+ export declare function scheduleItemAction(item: SchedulePlanItem): keyof MigrationOperations;
20
+ export declare function eventItemAction(item: EventPlanItem): keyof MigrationOperations;
21
+ export declare function groupItemAction(item: GroupPlanItem): keyof MigrationOperations;
22
+ export declare function roleGroupItemAction(item: RoleGroupPlanItem): keyof MigrationOperations;
23
+ export declare function serviceAccountItemAction(item: ServiceAccountPlanItem): keyof MigrationOperations;
24
+ export type RepositoryItemDecision = {
25
+ operation: keyof MigrationOperations;
26
+ baselineAction: 'adopt' | 'refresh' | 'none';
27
+ };
28
+ export type MigrationResourcePlan<T extends {
29
+ items: unknown[];
30
+ }> = Omit<T, 'items'> & {
31
+ items: Array<T['items'][number] & Partial<RepositoryItemDecision>>;
32
+ };
33
+ type ComparableRepositoryItem = {
34
+ status: string;
35
+ desiredHash?: string | null;
36
+ currentHash?: string | null;
37
+ localHash?: string | null;
38
+ remoteHash?: string | null;
39
+ };
40
+ export declare function projectRepositoryItems<T extends ComparableRepositoryItem>(items: T[], classify: (item: T) => keyof MigrationOperations, baselineHash: (item: T) => string | null | undefined): Array<T & RepositoryItemDecision>;
41
+ export declare function migrationItemOperation(item: {
42
+ status: string;
43
+ } & Partial<RepositoryItemDecision>, legacyAction: keyof MigrationOperations): keyof MigrationOperations;
44
+ export {};