@revoengine/cli 1.0.10 → 1.0.13

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.
Files changed (104) hide show
  1. package/README.md +314 -239
  2. package/dist/src/cli.js +126 -9
  3. package/dist/src/client.d.ts +373 -6
  4. package/dist/src/client.js +1005 -53
  5. package/dist/src/commands/auth.js +4 -2
  6. package/dist/src/commands/component.d.ts +67 -0
  7. package/dist/src/commands/component.js +555 -164
  8. package/dist/src/commands/database-tables.d.ts +2 -0
  9. package/dist/src/commands/database-tables.js +169 -0
  10. package/dist/src/commands/database-views.d.ts +2 -0
  11. package/dist/src/commands/database-views.js +126 -0
  12. package/dist/src/commands/endpoints.js +124 -0
  13. package/dist/src/commands/env.js +44 -24
  14. package/dist/src/commands/events.d.ts +2 -0
  15. package/dist/src/commands/events.js +144 -0
  16. package/dist/src/commands/groups.d.ts +2 -0
  17. package/dist/src/commands/groups.js +160 -0
  18. package/dist/src/commands/index.d.ts +9 -0
  19. package/dist/src/commands/index.js +9 -0
  20. package/dist/src/commands/job-templates.d.ts +2 -0
  21. package/dist/src/commands/job-templates.js +107 -0
  22. package/dist/src/commands/metadata.js +75 -10
  23. package/dist/src/commands/migrate.d.ts +6 -0
  24. package/dist/src/commands/migrate.js +658 -0
  25. package/dist/src/commands/project.js +10 -3
  26. package/dist/src/commands/role-groups.d.ts +2 -0
  27. package/dist/src/commands/role-groups.js +141 -0
  28. package/dist/src/commands/schedules.d.ts +2 -0
  29. package/dist/src/commands/schedules.js +140 -0
  30. package/dist/src/commands/terminal-browser.d.ts +16 -0
  31. package/dist/src/commands/terminal-browser.js +92 -0
  32. package/dist/src/commands/terminal-image.d.ts +7 -0
  33. package/dist/src/commands/terminal-image.js +40 -0
  34. package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
  35. package/dist/src/commands/terminal-patch-worker.js +24 -0
  36. package/dist/src/commands/terminal-patch.d.ts +2 -0
  37. package/dist/src/commands/terminal-patch.js +156 -0
  38. package/dist/src/commands/terminal-sandbox.d.ts +8 -0
  39. package/dist/src/commands/terminal-sandbox.js +87 -0
  40. package/dist/src/commands/terminal-service.d.ts +38 -0
  41. package/dist/src/commands/terminal-service.js +210 -0
  42. package/dist/src/commands/terminal.d.ts +49 -0
  43. package/dist/src/commands/terminal.js +826 -0
  44. package/dist/src/component-lock.d.ts +111 -3
  45. package/dist/src/component-lock.js +363 -15
  46. package/dist/src/config.d.ts +10 -2
  47. package/dist/src/config.js +49 -14
  48. package/dist/src/database-table-artifacts.d.ts +7 -0
  49. package/dist/src/database-table-artifacts.js +8 -0
  50. package/dist/src/diff-details.d.ts +8 -0
  51. package/dist/src/diff-details.js +152 -0
  52. package/dist/src/env-sync.d.ts +0 -3
  53. package/dist/src/env-sync.js +11 -25
  54. package/dist/src/http-trace.d.ts +94 -0
  55. package/dist/src/http-trace.js +226 -0
  56. package/dist/src/metadata-backfill.d.ts +18 -7
  57. package/dist/src/metadata-backfill.js +1002 -27
  58. package/dist/src/migration.d.ts +141 -0
  59. package/dist/src/migration.js +1632 -0
  60. package/dist/src/project.d.ts +2 -0
  61. package/dist/src/project.js +4 -17
  62. package/dist/src/prompt.js +10 -18
  63. package/dist/src/resource-inventory.d.ts +28 -0
  64. package/dist/src/resource-inventory.js +85 -0
  65. package/dist/src/resource-metadata.d.ts +1 -0
  66. package/dist/src/resource-metadata.js +3 -0
  67. package/dist/src/resource-syncs/database-table-sync.d.ts +127 -0
  68. package/dist/src/resource-syncs/database-table-sync.js +2374 -0
  69. package/dist/src/resource-syncs/database-view-sync.d.ts +146 -0
  70. package/dist/src/resource-syncs/database-view-sync.js +1405 -0
  71. package/dist/src/resource-syncs/endpoint-sync.d.ts +123 -0
  72. package/dist/src/resource-syncs/endpoint-sync.js +1563 -0
  73. package/dist/src/resource-syncs/event-sync.d.ts +126 -0
  74. package/dist/src/resource-syncs/event-sync.js +1046 -0
  75. package/dist/src/resource-syncs/group-sync.d.ts +93 -0
  76. package/dist/src/resource-syncs/group-sync.js +928 -0
  77. package/dist/src/resource-syncs/job-template-sync.d.ts +106 -0
  78. package/dist/src/resource-syncs/job-template-sync.js +843 -0
  79. package/dist/src/resource-syncs/role-group-sync.d.ts +90 -0
  80. package/dist/src/resource-syncs/role-group-sync.js +635 -0
  81. package/dist/src/resource-syncs/schedule-sync.d.ts +140 -0
  82. package/dist/src/resource-syncs/schedule-sync.js +1396 -0
  83. package/dist/src/resource-syncs/util.d.ts +22 -0
  84. package/dist/src/resource-syncs/util.js +118 -0
  85. package/dist/src/resource-target.d.ts +11 -0
  86. package/dist/src/resource-target.js +48 -0
  87. package/dist/src/runtime-view.d.ts +1 -0
  88. package/dist/src/runtime-view.js +6 -1
  89. package/dist/src/sync-output.d.ts +66 -0
  90. package/dist/src/sync-output.js +268 -0
  91. package/dist/src/tracked-resources.d.ts +1 -1
  92. package/dist/src/tracked-resources.js +28 -2
  93. package/dist/src/types.d.ts +227 -0
  94. package/dist/src/ui.d.ts +3 -0
  95. package/dist/src/ui.js +76 -18
  96. package/dist/src/utils.d.ts +4 -0
  97. package/dist/src/utils.js +81 -0
  98. package/dist/src/workspace-component.d.ts +2 -0
  99. package/dist/src/workspace-component.js +34 -0
  100. package/dist/src/workspace-diff.d.ts +25 -0
  101. package/dist/src/workspace-diff.js +75 -0
  102. package/dist/src/workspace-resource.d.ts +2 -0
  103. package/dist/src/workspace-resource.js +52 -0
  104. package/package.json +12 -4
@@ -0,0 +1,658 @@
1
+ import { DEFAULT_ENV_NAME } from "../config.js";
2
+ import { buildMigrationPlan, pullResourcesToWorkspace, runMigration, } from "../migration.js";
3
+ import { isInteractiveTerminal, promptConfirm } from "../prompt.js";
4
+ import { readProjectTrackedResources } from "../project.js";
5
+ import { resolveAuthenticatedInstance } from "../resource-target.js";
6
+ import { planDependencyHints, planListChanges, planValueChanges, printSyncPlan, printSyncStatus, printSyncSummary, printWorkspaceDiff } from "../sync-output.js";
7
+ import { shouldTrackResource } from "../tracked-resources.js";
8
+ import { readBoolFlag, readFlag, readValues } from "../utils.js";
9
+ import { buildWorkspaceDiff } from "../workspace-diff.js";
10
+ const RESOURCE_ALIASES = {
11
+ 'database-table': 'database-table',
12
+ 'database-tables': 'database-table',
13
+ 'database-schema': 'database-table',
14
+ 'database-schemas': 'database-table',
15
+ database: 'database-table',
16
+ 'database-view': 'database-view',
17
+ 'database-views': 'database-view',
18
+ dbview: 'database-view',
19
+ component: 'component',
20
+ components: 'component',
21
+ 'job-template': 'job-template',
22
+ 'job-templates': 'job-template',
23
+ jobtemplate: 'job-template',
24
+ jobtemplates: 'job-template',
25
+ endpoint: 'endpoint',
26
+ endpoints: 'endpoint',
27
+ schedule: 'schedule',
28
+ schedules: 'schedule',
29
+ event: 'event',
30
+ events: 'event',
31
+ group: 'group',
32
+ groups: 'group',
33
+ 'role-group': 'role-group',
34
+ 'role-groups': 'role-group',
35
+ rolegroup: 'role-group',
36
+ rolegroups: 'role-group',
37
+ };
38
+ const MIGRATION_RESOURCE_ORDER = [
39
+ 'database-table',
40
+ 'database-view',
41
+ 'component',
42
+ 'job-template',
43
+ 'endpoint',
44
+ 'schedule',
45
+ 'event',
46
+ 'group',
47
+ 'role-group',
48
+ ];
49
+ function readMigrationResources(context, commandLabel = 'Migration') {
50
+ const values = readValues(context.args, ['resources', 'resource'])
51
+ .flatMap((value) => value.split(','))
52
+ .map((value) => value.trim().toLowerCase())
53
+ .filter(Boolean);
54
+ let selected;
55
+ if (values.length === 0 || values.includes('all')) {
56
+ selected = [...MIGRATION_RESOURCE_ORDER];
57
+ }
58
+ else {
59
+ const resources = [];
60
+ for (const value of values) {
61
+ const resource = RESOURCE_ALIASES[value];
62
+ if (!resource) {
63
+ throw new Error(`${commandLabel} currently supports: database-table, database-view, component, job-template, endpoint, schedule, event, group, role-group, or all.`);
64
+ }
65
+ if (!resources.includes(resource)) {
66
+ resources.push(resource);
67
+ }
68
+ }
69
+ selected = MIGRATION_RESOURCE_ORDER.filter((resource) => resources.includes(resource));
70
+ }
71
+ if (readBoolFlag(context.args, ['skip-groups'])) {
72
+ selected = selected.filter((resource) => resource !== 'group' && resource !== 'role-group');
73
+ }
74
+ if (selected.length === 0) {
75
+ throw new Error(`${commandLabel} resource selection is empty after applying --skip-groups.`);
76
+ }
77
+ return selected;
78
+ }
79
+ function readMigrationInput(context) {
80
+ const from = readFlag(context.args, ['from']);
81
+ const to = readFlag(context.args, ['to']);
82
+ if (!from || !to) {
83
+ throw new Error('Migration requires --from <env> and --to <env>.');
84
+ }
85
+ if (from === DEFAULT_ENV_NAME || to === DEFAULT_ENV_NAME) {
86
+ throw new Error('Migration requires named environment profiles; "default" is not supported.');
87
+ }
88
+ if (from === to) {
89
+ throw new Error('Migration source and target must be different named environments.');
90
+ }
91
+ return {
92
+ cwd: context.cwd,
93
+ from,
94
+ to,
95
+ resources: readMigrationResources(context),
96
+ withStats: readBoolFlag(context.args, ['with-stats']),
97
+ allowDestructive: readBoolFlag(context.args, ['force', 'f']),
98
+ };
99
+ }
100
+ function printMigrationPlan(context, plan) {
101
+ const phaseLabel = plan.from === 'workspace' ? 'Deployment plan' : 'Migration';
102
+ context.println(`${phaseLabel} ${plan.from} -> ${plan.to}`);
103
+ context.println(`Resources: ${plan.resources.join(' -> ')}.`);
104
+ context.println(`Ready to ${plan.from === 'workspace' ? 'deploy' : 'migrate'}: ${plan.readyToMigrate ? 'yes' : 'no'}.`);
105
+ context.println(`Changes required: ${plan.needsChanges ? 'yes' : 'no'}; verdict: ${plan.verdict}.`);
106
+ 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}.`);
107
+ context.println(`Diagnostics: ${plan.warnings.length} warning(s), ${plan.blockers.length} blocker(s).`);
108
+ if (plan.sourcePull.mode === 'repository') {
109
+ context.println('Source snapshot: repository workspace (no remote source pull).');
110
+ }
111
+ else {
112
+ const pullLocation = plan.sourcePull.mode === 'temporary'
113
+ ? 'temporary workspace'
114
+ : 'configured workspace';
115
+ context.println(`Source snapshot: ${plan.sourcePull.pulled} pulled, ${plan.sourcePull.pruned} pruned, ${plan.sourcePull.skipped} skipped in ${pullLocation}.`);
116
+ }
117
+ for (const phase of plan.phases) {
118
+ const pull = plan.sourcePull.byResource[phase.resource];
119
+ if (pull) {
120
+ context.println(`Phase ${phase.order} source ${phase.resource}: ${pull.pulled} pulled, ${pull.pruned} pruned, ${pull.skipped} skipped.`);
121
+ }
122
+ if (phase.resource === 'database-table' && plan.databaseSchemas) {
123
+ printSyncPlan(context.println, {
124
+ title: `${phaseLabel} phase ${phase.order} / Database Table`,
125
+ environment: plan.to,
126
+ counts: phase.operations,
127
+ showHints: readBoolFlag(context.args, ['hints']),
128
+ items: plan.databaseSchemas.items.map((item) => ({
129
+ status: schemaItemActionLabel(item),
130
+ target: item.stableKey || item.name,
131
+ reason: item.reason,
132
+ changedFields: item.changedFields,
133
+ details: planValueChanges(item.changes || []),
134
+ hints: item.hints.length > 0 ? [{ label: 'hints', values: item.hints }] : undefined,
135
+ })),
136
+ warnings: phase.warnings,
137
+ blockers: phase.blockers,
138
+ });
139
+ }
140
+ if (phase.resource === 'database-view' && plan.databaseViews) {
141
+ printSyncPlan(context.println, {
142
+ title: `${phaseLabel} phase ${phase.order} / Database View`,
143
+ environment: plan.to,
144
+ counts: phase.operations,
145
+ showHints: readBoolFlag(context.args, ['hints']),
146
+ items: plan.databaseViews.items.map((item) => ({
147
+ status: viewItemActionLabel(item),
148
+ target: item.stableKey || item.name,
149
+ reason: item.reason,
150
+ changedFields: item.changedFields,
151
+ fieldChanges: item.fieldChanges,
152
+ details: [
153
+ ...(item.rawQueryDiff?.length ? [{ label: 'rawQuery diff', lines: item.rawQueryDiff }] : []),
154
+ ...(item.risks?.length ? [{ label: 'risks', values: item.risks }] : []),
155
+ ],
156
+ hints: item.scheduleDependencies?.length
157
+ ? [{ label: 'schedule dependencies', values: item.scheduleDependencies }]
158
+ : undefined,
159
+ })),
160
+ warnings: phase.warnings,
161
+ blockers: phase.blockers,
162
+ });
163
+ }
164
+ if (phase.resource === 'component' && plan.components) {
165
+ printSyncPlan(context.println, {
166
+ title: `${phaseLabel} phase ${phase.order} / Component`,
167
+ environment: plan.to,
168
+ counts: phase.operations,
169
+ showHints: readBoolFlag(context.args, ['hints']),
170
+ items: plan.components.items.map((item) => ({
171
+ status: componentItemActionLabel(item),
172
+ target: item.stableKey || item.path,
173
+ reason: item.reason,
174
+ changedFields: item.status === 'create' ? undefined : item.changedFields,
175
+ fieldChanges: item.status === 'create' ? undefined : item.fieldChanges,
176
+ details: item.status === 'create' ? undefined : [
177
+ ...(item.codeDiffs || []).map((code) => ({ label: `element ${code.element}`, lines: code.lines })),
178
+ ],
179
+ hints: item.status !== 'create' && item.componentType
180
+ ? [{ label: 'type', values: item.componentType }]
181
+ : undefined,
182
+ })),
183
+ warnings: phase.warnings,
184
+ blockers: phase.blockers,
185
+ });
186
+ }
187
+ if (phase.resource === 'job-template' && plan.jobTemplates) {
188
+ printSyncPlan(context.println, {
189
+ title: `${phaseLabel} phase ${phase.order} / Job Template`,
190
+ environment: plan.to,
191
+ counts: phase.operations,
192
+ showHints: readBoolFlag(context.args, ['hints']),
193
+ items: plan.jobTemplates.items.map((item) => ({
194
+ status: jobTemplateItemActionLabel(item),
195
+ target: item.stableKey || item.name,
196
+ reason: item.reason,
197
+ changedFields: item.changedFields,
198
+ fieldChanges: item.fieldChanges,
199
+ hints: [
200
+ ...(item.componentStableKey ? [{ label: 'component', values: item.componentStableKey }] : []),
201
+ ...(item.dependencyReadiness ? [{ label: 'dependency', values: item.dependencyReadiness }] : []),
202
+ ],
203
+ })),
204
+ warnings: phase.warnings,
205
+ blockers: phase.blockers,
206
+ });
207
+ }
208
+ if (phase.resource === 'endpoint' && plan.endpoints) {
209
+ printSyncPlan(context.println, {
210
+ title: `${phaseLabel} phase ${phase.order} / Endpoint`,
211
+ environment: plan.to,
212
+ counts: phase.operations,
213
+ showHints: readBoolFlag(context.args, ['hints']),
214
+ items: plan.endpoints.items.map((item) => ({
215
+ status: endpointItemActionLabel(item),
216
+ target: item.stableKey || item.name,
217
+ reason: item.reason,
218
+ changedFields: item.changedFields,
219
+ fieldChanges: item.fieldChanges,
220
+ hints: [
221
+ ...(item.details || []),
222
+ ...(item.dependencies || []).map((dependency) => ({
223
+ label: `${dependency.relation} dependency`,
224
+ values: `${dependency.stableKey} (${dependency.readiness})`,
225
+ })),
226
+ ...(item.routeDependencies?.length
227
+ ? [{ label: 'route waits for', values: item.routeDependencies.join(', ') }]
228
+ : []),
229
+ ],
230
+ })),
231
+ warnings: phase.warnings,
232
+ blockers: phase.blockers,
233
+ });
234
+ }
235
+ if (phase.resource === 'schedule' && plan.schedules) {
236
+ printSyncPlan(context.println, {
237
+ title: `${phaseLabel} phase ${phase.order} / Schedule`,
238
+ environment: plan.to,
239
+ counts: phase.operations,
240
+ showHints: readBoolFlag(context.args, ['hints']),
241
+ items: plan.schedules.items.map((item) => ({
242
+ status: scheduleItemActionLabel(item),
243
+ target: item.stableKey || item.name,
244
+ reason: item.reason,
245
+ changedFields: item.changedFields,
246
+ fieldChanges: item.fieldChanges,
247
+ hints: item.dependency ? planDependencyHints(item.dependency) : undefined,
248
+ })),
249
+ warnings: phase.warnings,
250
+ blockers: phase.blockers,
251
+ });
252
+ }
253
+ if (phase.resource === 'event' && plan.events) {
254
+ printSyncPlan(context.println, {
255
+ title: `${phaseLabel} phase ${phase.order} / Event`,
256
+ environment: plan.to,
257
+ counts: phase.operations,
258
+ showHints: readBoolFlag(context.args, ['hints']),
259
+ items: plan.events.items.map((item) => ({
260
+ status: eventItemActionLabel(item),
261
+ target: item.stableKey || item.name,
262
+ reason: item.reason,
263
+ changedFields: item.changedFields,
264
+ fieldChanges: item.fieldChanges,
265
+ hints: item.dependency
266
+ ? planDependencyHints({ ...item.dependency, resource: 'job-template' })
267
+ : undefined,
268
+ })),
269
+ warnings: phase.warnings,
270
+ blockers: phase.blockers,
271
+ });
272
+ }
273
+ if (phase.resource === 'group' && plan.groups) {
274
+ printSyncPlan(context.println, {
275
+ title: `${phaseLabel} phase ${phase.order} / Group`,
276
+ environment: plan.to,
277
+ counts: phase.operations,
278
+ showHints: readBoolFlag(context.args, ['hints']),
279
+ items: plan.groups.items.map((item) => ({
280
+ status: groupItemActionLabel(item),
281
+ target: item.stableKey || item.name,
282
+ reason: item.reason,
283
+ changedFields: item.changedFields,
284
+ fieldChanges: item.fieldChanges,
285
+ hints: item.ownerStableKey
286
+ ? [{ label: 'owner', values: item.ownerStableKey }]
287
+ : undefined,
288
+ })),
289
+ warnings: phase.warnings,
290
+ blockers: phase.blockers,
291
+ });
292
+ }
293
+ if (phase.resource === 'role-group' && plan.roleGroups) {
294
+ printSyncPlan(context.println, {
295
+ title: `${phaseLabel} phase ${phase.order} / Role Group`,
296
+ environment: plan.to,
297
+ counts: phase.operations,
298
+ showHints: readBoolFlag(context.args, ['hints']),
299
+ items: plan.roleGroups.items.map((item) => ({
300
+ status: roleGroupItemActionLabel(item),
301
+ target: item.stableKey || item.name,
302
+ reason: item.reason,
303
+ changedFields: item.changedFields,
304
+ fieldChanges: item.fieldChanges,
305
+ details: planListChanges('roles', item.rolesToRemove, item.rolesToAdd),
306
+ })),
307
+ warnings: phase.warnings,
308
+ blockers: phase.blockers,
309
+ });
310
+ }
311
+ }
312
+ }
313
+ function schemaItemActionLabel(item) {
314
+ if (item.status === 'missing-lock') {
315
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
316
+ }
317
+ if (item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'safe-update') {
318
+ return 'update';
319
+ }
320
+ if (item.status === 'reconciled') {
321
+ return 'adopt';
322
+ }
323
+ if (item.status === 'manual-schema-migration-required'
324
+ || item.status === 'access-policy-required'
325
+ || item.status === 'previously-deleted-partition'
326
+ || item.status === 'replacement-requires-two-phases'
327
+ || item.status === 'collision') {
328
+ return 'blocked';
329
+ }
330
+ if (item.status === 'orphan-root'
331
+ || item.status === 'orphan-partition'
332
+ || item.status === 'delete-partition'
333
+ || item.status === 'unmanaged') {
334
+ return 'excluded';
335
+ }
336
+ return item.status;
337
+ }
338
+ function viewItemActionLabel(item) {
339
+ if (item.status === 'collision' || (item.status === 'conflict' && item.reason)) {
340
+ return 'blocked';
341
+ }
342
+ if (item.status === 'missing-lock') {
343
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
344
+ }
345
+ if (item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'safe-update') {
346
+ return 'update';
347
+ }
348
+ if (item.status === 'orphan' || item.status === 'skipped') {
349
+ return 'excluded';
350
+ }
351
+ return item.status;
352
+ }
353
+ function componentItemActionLabel(item) {
354
+ if (item.status === 'clean' && item.lockHash === null && item.localHash !== null && item.localHash === item.remoteHash) {
355
+ return 'adopt';
356
+ }
357
+ if (item.status === 'local-changed' || item.status === 'remote-changed' || item.status === 'conflict' || item.status === 'missing-lock') {
358
+ return 'update';
359
+ }
360
+ if (item.status === 'safe-update') {
361
+ return 'excluded';
362
+ }
363
+ return item.status;
364
+ }
365
+ function jobTemplateItemActionLabel(item) {
366
+ if (item.status === 'collision' || (item.status === 'conflict' && !item.desiredHash)) {
367
+ return 'blocked';
368
+ }
369
+ if (item.status === 'missing-lock') {
370
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
371
+ }
372
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
373
+ return 'update';
374
+ }
375
+ if (item.status === 'orphan' || item.status === 'skipped') {
376
+ return 'excluded';
377
+ }
378
+ return item.status;
379
+ }
380
+ function endpointItemActionLabel(item) {
381
+ if (item.status === 'restore-blocked' || item.status === 'collision') {
382
+ return 'blocked';
383
+ }
384
+ if (item.status === 'restore' || item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
385
+ return 'update';
386
+ }
387
+ if (item.status === 'missing-lock') {
388
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
389
+ }
390
+ if (item.status === 'orphan' || item.status === 'skipped') {
391
+ return 'excluded';
392
+ }
393
+ return item.status;
394
+ }
395
+ function scheduleItemActionLabel(item) {
396
+ if (item.blocked === true || item.status === 'collision') {
397
+ return 'blocked';
398
+ }
399
+ if (item.status === 'missing-lock') {
400
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
401
+ }
402
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
403
+ return 'update';
404
+ }
405
+ if (item.status === 'orphan' || item.status === 'skipped') {
406
+ return 'excluded';
407
+ }
408
+ return item.status;
409
+ }
410
+ function eventItemActionLabel(item) {
411
+ if (item.blocked === true || item.status === 'collision') {
412
+ return 'blocked';
413
+ }
414
+ if (item.status === 'missing-lock') {
415
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
416
+ }
417
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
418
+ return 'update';
419
+ }
420
+ if (item.status === 'orphan' || item.status === 'skipped' || item.status === 'activation-drift') {
421
+ return 'excluded';
422
+ }
423
+ return item.status;
424
+ }
425
+ function groupItemActionLabel(item) {
426
+ if (item.status === 'collision'
427
+ || ((item.status === 'conflict' || item.status === 'missing-lock') && !item.currentHash)) {
428
+ return 'blocked';
429
+ }
430
+ if (item.status === 'missing-lock') {
431
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
432
+ }
433
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
434
+ return 'update';
435
+ }
436
+ if (item.status === 'manual-owner' || item.status === 'orphan' || item.status === 'skipped') {
437
+ return 'excluded';
438
+ }
439
+ return item.status;
440
+ }
441
+ function roleGroupItemActionLabel(item) {
442
+ if (item.status === 'collision' || (item.status === 'conflict' && !item.currentHash)) {
443
+ return 'blocked';
444
+ }
445
+ if (item.status === 'missing-lock') {
446
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
447
+ }
448
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
449
+ return 'update';
450
+ }
451
+ if (item.status === 'orphan' || item.status === 'skipped') {
452
+ return 'excluded';
453
+ }
454
+ return item.status;
455
+ }
456
+ async function confirmRun(context, from, to) {
457
+ if (readBoolFlag(context.args, ['yes', 'y'])) {
458
+ return;
459
+ }
460
+ if (!isInteractiveTerminal() || !await promptConfirm(`Run the ordered resource migration from "${from}" to "${to}"?`, false)) {
461
+ throw new Error('Migration run requires confirmation. Re-run with --yes or use an interactive terminal.');
462
+ }
463
+ }
464
+ async function readWorkspaceDeploymentInput(context) {
465
+ const authenticatedInstance = await resolveAuthenticatedInstance(context.client, 'target');
466
+ const trackedResources = readProjectTrackedResources(context.cwd);
467
+ const resources = MIGRATION_RESOURCE_ORDER.filter((resource) => shouldTrackResource(trackedResources, resource));
468
+ if (resources.length === 0) {
469
+ throw new Error('Deployment resource selection is empty in .revoengine/revo.json.');
470
+ }
471
+ return {
472
+ cwd: context.cwd,
473
+ from: 'workspace',
474
+ to: context.client.baseUrl,
475
+ resources,
476
+ withStats: readBoolFlag(context.args, ['with-stats']),
477
+ allowDestructive: readBoolFlag(context.args, ['force', 'f']),
478
+ sourceMode: 'workspace',
479
+ targetClient: context.client,
480
+ targetKey: `instance:${authenticatedInstance}`,
481
+ targetLabel: context.client.baseUrl,
482
+ };
483
+ }
484
+ async function handleMigrationRead(context, input, command) {
485
+ const plan = await buildMigrationPlan({
486
+ ...input,
487
+ detailedDiff: true,
488
+ ...(command === 'diff' ? { allowDestructive: true } : {}),
489
+ });
490
+ if (command === 'diff') {
491
+ const diff = buildWorkspaceDiff(plan);
492
+ if (readBoolFlag(context.args, ['json'])) {
493
+ context.print(diff);
494
+ }
495
+ else {
496
+ printWorkspaceDiff(context.println, diff);
497
+ }
498
+ return;
499
+ }
500
+ if (readBoolFlag(context.args, ['json'])) {
501
+ context.print({ ...plan, command });
502
+ }
503
+ else {
504
+ printMigrationPlan(context, plan);
505
+ }
506
+ if (plan.verdict === 'blocked') {
507
+ const label = input.sourceMode === 'workspace' ? `Deployment ${command}` : `Migration ${command}`;
508
+ throw new Error(`${label} is blocked by ${plan.blockers.length} issue(s).`);
509
+ }
510
+ if (command === 'plan' && input.sourceMode === 'workspace'
511
+ && readBoolFlag(context.args, ['strict']) && plan.needsChanges) {
512
+ throw new Error(`Deployment strict plan has pending changes: ${plan.operations.create} create, ${plan.operations.update} update.`);
513
+ }
514
+ if (command === 'verify' && plan.needsChanges) {
515
+ throw new Error('Migration verification failed: target still requires changes.');
516
+ }
517
+ }
518
+ export async function handleDiffCommand(context) {
519
+ if (readBoolFlag(context.args, ['force', 'f'])) {
520
+ throw new Error('Repository diff only compares content. Use revo plan --force to review force-gated deployment operations.');
521
+ }
522
+ await handleMigrationRead(context, await readWorkspaceDeploymentInput(context), 'diff');
523
+ }
524
+ export async function handlePlanCommand(context) {
525
+ if (readBoolFlag(context.args, ['changed']) || readFlag(context.args, ['base'])) {
526
+ throw new Error('Repository plan evaluates all tracked resources and dependencies; --changed and --base are supported only by component plan.');
527
+ }
528
+ if (readFlag(context.args, ['from']) || readFlag(context.args, ['to'])) {
529
+ throw new Error('Repository plan uses the configured runtime target. Use revo migrate plan for --from and --to.');
530
+ }
531
+ if (readValues(context.args, ['resources', 'resource']).length > 0) {
532
+ throw new Error('Repository plan uses .revoengine/revo.json trackedResources. Change the project configuration to select resources.');
533
+ }
534
+ await handleMigrationRead(context, await readWorkspaceDeploymentInput(context), 'plan');
535
+ }
536
+ function readPullResources(context) {
537
+ const all = readBoolFlag(context.args, ['all', 'a']);
538
+ const values = readValues(context.args, ['resources', 'resource']);
539
+ if (!all && values.length === 0) {
540
+ throw new Error('Repository pull requires --all or --resources <list>.');
541
+ }
542
+ if (all && values.length > 0) {
543
+ throw new Error('Repository pull accepts either --all or --resources <list>, not both.');
544
+ }
545
+ if (!all) {
546
+ return readMigrationResources(context, 'Repository pull');
547
+ }
548
+ const resources = [...MIGRATION_RESOURCE_ORDER];
549
+ return readBoolFlag(context.args, ['skip-groups'])
550
+ ? resources.filter((resource) => resource !== 'group' && resource !== 'role-group')
551
+ : resources;
552
+ }
553
+ async function confirmPull(context) {
554
+ if (readBoolFlag(context.args, ['yes', 'y'])) {
555
+ return;
556
+ }
557
+ if (!isInteractiveTerminal() || !await promptConfirm(`Pull resources from "${context.client.baseUrl}" into the repository workspace?`, false)) {
558
+ throw new Error('Repository pull requires confirmation. Re-run with --yes or use an interactive terminal.');
559
+ }
560
+ }
561
+ export async function handlePullCommand(context) {
562
+ const resources = readPullResources(context);
563
+ await confirmPull(context);
564
+ const authenticatedInstance = await resolveAuthenticatedInstance(context.client, 'source');
565
+ const force = readBoolFlag(context.args, ['force', 'f']);
566
+ const result = await pullResourcesToWorkspace({
567
+ cwd: context.cwd,
568
+ client: context.client,
569
+ sourceKey: `instance:${authenticatedInstance}`,
570
+ sourceLabel: context.client.baseUrl,
571
+ resources,
572
+ force,
573
+ pruneOrphans: force,
574
+ });
575
+ if (readBoolFlag(context.args, ['json'])) {
576
+ context.print(result);
577
+ return;
578
+ }
579
+ context.println(`Repository pull ${result.source} -> workspace`);
580
+ context.println(`Resources: ${result.resources.join(' -> ')}.`);
581
+ for (const resource of result.resources) {
582
+ const summary = result.summary.byResource[resource];
583
+ if (!summary) {
584
+ continue;
585
+ }
586
+ context.println(`${resource}: pulled ${summary.pulled}, pruned ${summary.pruned}, skipped ${summary.skipped}.`);
587
+ if (resource === 'job-template') {
588
+ for (const skipped of result.results.jobTemplates?.skipped || []) {
589
+ printSyncStatus(context.println, {
590
+ status: 'Skipped', direction: 'pull', targetPath: skipped.targetPath, reason: skipped.reason,
591
+ });
592
+ }
593
+ }
594
+ }
595
+ context.println(`Summary: pulled ${result.summary.pulled}, pruned ${result.summary.pruned}, skipped ${result.summary.skipped}.`);
596
+ }
597
+ async function confirmDeploy(context) {
598
+ if (readBoolFlag(context.args, ['yes', 'y'])) {
599
+ return;
600
+ }
601
+ if (!isInteractiveTerminal() || !await promptConfirm(`Deploy the tracked workspace to "${context.client.baseUrl}"?`, false)) {
602
+ throw new Error('Deployment requires confirmation. Re-run with --yes or use an interactive terminal.');
603
+ }
604
+ }
605
+ function printRunResult(context, result) {
606
+ printMigrationPlan(context, result.plan);
607
+ for (const item of result.results) {
608
+ printSyncStatus(context.println, {
609
+ status: item.status === 'deployed' ? 'Deployed' : item.status === 'write-unverified' ? 'Unverified' : item.status === 'failed' ? 'Failed' : 'Skipped',
610
+ direction: 'push',
611
+ targetPath: item.targetPath,
612
+ reason: ('error' in item ? item.error : undefined) || item.reason,
613
+ });
614
+ }
615
+ context.println(`Final verdict: ${result.verdict}.`);
616
+ }
617
+ export async function handleDeployCommand(context) {
618
+ await confirmDeploy(context);
619
+ const startedAt = Date.now();
620
+ const result = await runMigration({ ...await readWorkspaceDeploymentInput(context), detailedDiff: true });
621
+ if (readBoolFlag(context.args, ['json'])) {
622
+ context.print({ ...result, command: 'deploy' });
623
+ }
624
+ else {
625
+ printRunResult(context, result);
626
+ printSyncSummary(context.println, 'Deployed', result.results, Date.now() - startedAt);
627
+ }
628
+ if (result.verdict !== 'succeeded') {
629
+ throw new Error(`Deployment finished with verdict "${result.verdict}".`);
630
+ }
631
+ }
632
+ export async function handleMigrateCommand(context) {
633
+ const requestedSubcommand = context.args._[1] || 'plan';
634
+ const dryRun = readBoolFlag(context.args, ['dry-run']);
635
+ const subcommand = dryRun ? 'plan' : requestedSubcommand;
636
+ if (requestedSubcommand !== 'plan' && requestedSubcommand !== 'run' && requestedSubcommand !== 'verify') {
637
+ throw new Error('Unknown migrate command. Usage: revo migrate <plan|run|verify> --from <env> --to <env> [--resources database-table,database-view,component,job-template,endpoint,schedule,event,group,role-group] [--skip-groups] [--dry-run]');
638
+ }
639
+ const input = readMigrationInput(context);
640
+ const json = readBoolFlag(context.args, ['json']);
641
+ if (subcommand === 'plan' || subcommand === 'verify') {
642
+ await handleMigrationRead(context, input, subcommand);
643
+ return;
644
+ }
645
+ await confirmRun(context, input.from, input.to);
646
+ const startedAt = Date.now();
647
+ const result = await runMigration({ ...input, detailedDiff: true });
648
+ if (json) {
649
+ context.print(result);
650
+ }
651
+ else {
652
+ printRunResult(context, result);
653
+ printSyncSummary(context.println, 'Deployed', result.results, Date.now() - startedAt);
654
+ }
655
+ if (result.verdict !== 'succeeded') {
656
+ throw new Error(`Migration run finished with verdict "${result.verdict}".`);
657
+ }
658
+ }