@revoengine/cli 1.0.25 → 1.0.27

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.
@@ -8,6 +8,7 @@ import { SERVICE_ACCOUNTS_DIRECTORY, buildServiceAccountsPlan, pullServiceAccoun
8
8
  import os from 'node:os';
9
9
  import path from 'node:path';
10
10
  import { RevoClient } from "./client.js";
11
+ import { planningSnapshot } from "./planning-snapshot.js";
11
12
  import { REVO_LOCK_FILE, readComponentLock } from "./component-lock.js";
12
13
  import { normalizeStableKeyValue } from "./resource-metadata.js";
13
14
  import { withHttpTraceContext } from "./http-trace.js";
@@ -17,10 +18,10 @@ import { REVO_METADATA_FILE, readProjectComponentIdentity, readProjectMetadata,
17
18
  import { DATABASE_SCHEMAS_DIRECTORY, buildDatabaseSchemasPlan, pullDatabaseSchemasToWorkspace, pushDatabaseSchemas, readWorkspaceDatabaseSchemas, } from "./resource-syncs/database-table-sync.js";
18
19
  import { DATABASE_VIEWS_DIRECTORY, buildDatabaseViewsPlan, pullDatabaseViewsToWorkspace, pushDatabaseViews, readWorkspaceDatabaseViews, } from "./resource-syncs/database-view-sync.js";
19
20
  import { ENDPOINTS_DIRECTORY, buildEndpointsPlan, pullEndpointsToWorkspace, pushEndpoints, } from "./resource-syncs/endpoint-sync.js";
20
- import { EVENTS_DIRECTORY, buildEventsPlan, pullEventsToWorkspace, pushEvents, } from "./resource-syncs/event-sync.js";
21
+ import { EVENTS_DIRECTORY, activateVerifiedEvents, buildEventsPlan, pullEventsToWorkspace, pushEvents, } from "./resource-syncs/event-sync.js";
21
22
  import { GROUPS_DIRECTORY, buildGroupsPlan, pullGroupsToWorkspace, pushGroups, } from "./resource-syncs/group-sync.js";
22
23
  import { JOB_TEMPLATES_DIRECTORY, buildJobTemplatesPlan, pullJobTemplatesToWorkspace, pushJobTemplates, } from "./resource-syncs/job-template-sync.js";
23
- import { SCHEDULES_DIRECTORY, buildSchedulesPlan, pullSchedulesToWorkspace, pushSchedules, } from "./resource-syncs/schedule-sync.js";
24
+ import { SCHEDULES_DIRECTORY, activateVerifiedSchedules, buildSchedulesPlan, pullSchedulesToWorkspace, pushSchedules, } from "./resource-syncs/schedule-sync.js";
24
25
  import { ROLE_GROUPS_DIRECTORY, buildRoleGroupsPlan, pullRoleGroupsToWorkspace, pushRoleGroups, } from "./resource-syncs/role-group-sync.js";
25
26
  const RESOURCE_ORDER = [
26
27
  'database-table',
@@ -61,7 +62,11 @@ function selectedResources(input) {
61
62
  const requested = new Set(input.resources?.length ? input.resources : RESOURCE_ORDER);
62
63
  return RESOURCE_ORDER.filter((resource) => requested.has(resource));
63
64
  }
64
- async function runMigrationStage(stage, resource, envName, operation) {
65
+ async function runMigrationStage(stage, resource, envName, operation, progress) {
66
+ const startedAt = Date.now();
67
+ const label = `${stage}: ${resource}`;
68
+ progress?.(`${label} started`);
69
+ const heartbeat = progress ? setInterval(() => progress(`${label} running (${Math.round((Date.now() - startedAt) / 1000)}s)`), 20000) : undefined;
65
70
  try {
66
71
  return await withHttpTraceContext({
67
72
  stage: stage.replace(' ', '-'),
@@ -73,6 +78,11 @@ async function runMigrationStage(stage, resource, envName, operation) {
73
78
  const message = error instanceof Error ? error.message : String(error);
74
79
  throw new Error(`Migration ${stage} failed for ${resource} in environment "${envName}": ${message}`, { cause: error });
75
80
  }
81
+ finally {
82
+ if (heartbeat)
83
+ clearInterval(heartbeat);
84
+ progress?.(`${label} finished (${((Date.now() - startedAt) / 1000).toFixed(1)}s)`);
85
+ }
76
86
  }
77
87
  function migrationPolicy(input) {
78
88
  return {
@@ -286,7 +296,7 @@ function summarizeEventPhase(plan) {
286
296
  .map((item) => `Event "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
287
297
  ...plan.items
288
298
  .filter((item) => item.status === 'activation-drift')
289
- .map((item) => `Event "${item.stableKey || item.name}" has activation drift; migration syncs its portable configuration but keeps activation as an explicit operational step.`),
299
+ .map((item) => `Event "${item.stableKey || item.name}" has activation drift; activation requires repository plan/deploy --activate or the dedicated events push --activate step.`),
290
300
  ])];
291
301
  const blockers = [...new Set(plan.blockers)];
292
302
  return {
@@ -585,10 +595,10 @@ function combinePlan(input) {
585
595
  input.endpoints = { ...input.endpoints, items: projectRepositoryItems(input.endpoints.items, endpointItemAction, (item) => item.stableKey ? lock.endpoints[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
586
596
  }
587
597
  if (input.schedules) {
588
- input.schedules = { ...input.schedules, items: projectRepositoryItems(input.schedules.items, scheduleItemAction, (item) => item.stableKey ? lock.schedules[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
598
+ input.schedules = { ...input.schedules, items: projectRepositoryItems(input.schedules.items, item => input.migrationInput.activateAutomations && item.status === 'activation-drift' && !item.blocked ? 'update' : scheduleItemAction(item), (item) => item.stableKey ? lock.schedules[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
589
599
  }
590
600
  if (input.events) {
591
- input.events = { ...input.events, items: projectRepositoryItems(input.events.items, eventItemAction, (item) => item.stableKey ? lock.events[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
601
+ input.events = { ...input.events, items: projectRepositoryItems(input.events.items, item => input.migrationInput.activateAutomations && item.status === 'activation-drift' && !item.blocked ? 'update' : eventItemAction(item), (item) => item.stableKey ? lock.events[item.stableKey]?.environments[environment]?.remoteHash : undefined) };
592
602
  }
593
603
  if (input.groups) {
594
604
  input.groups = { ...input.groups, items: projectRepositoryItems(input.groups.items, groupItemAction, baselineByKey(lock.groups)) };
@@ -701,7 +711,7 @@ function combinePlan(input) {
701
711
  from: input.migrationInput.from,
702
712
  to: input.migrationInput.to,
703
713
  resources: selectedResources(input.migrationInput),
704
- policy: { ...migrationPolicy(input.migrationInput), mode: 'upsert' },
714
+ policy: { ...migrationPolicy(input.migrationInput), mode: 'upsert', ...(input.migrationInput.activateAutomations ? { activateAutomations: true } : {}) },
705
715
  needsChanges: phases.some((phase) => phase.needsChanges),
706
716
  readyToMigrate: blockers.length === 0,
707
717
  verdict: phaseVerdict(blockers, warnings),
@@ -1042,13 +1052,14 @@ function projectedDatabaseRecords(pull) {
1042
1052
  }));
1043
1053
  }
1044
1054
  async function planWorkspace(input) {
1055
+ const planStage = (stage, resource, environment, operation) => runMigrationStage(stage, resource, environment, operation, input.onProgress);
1045
1056
  const resources = selectedResources(input);
1046
1057
  const stableKeyName = readProjectStableKeyName(input.cwd);
1047
- const client = resolveTargetClient(input);
1058
+ const client = planningSnapshot(resolveTargetClient(input));
1048
1059
  const environmentKey = targetKey(input);
1049
1060
  const environmentLabel = targetLabel(input);
1050
1061
  const databaseSchemas = resources.includes('database-table')
1051
- ? await runMigrationStage('target plan', 'database-table', environmentLabel, () => buildDatabaseSchemasPlan({
1062
+ ? await planStage('target plan', 'database-table', environmentLabel, () => buildDatabaseSchemasPlan({
1052
1063
  client,
1053
1064
  cwd: input.cwd,
1054
1065
  envName: environmentKey,
@@ -1064,7 +1075,7 @@ async function planWorkspace(input) {
1064
1075
  && Boolean(input.pulls.databaseSchemas)
1065
1076
  && schemaPhase?.needsChanges === true;
1066
1077
  const databaseViews = resources.includes('database-view')
1067
- ? await runMigrationStage('target plan', 'database-view', environmentLabel, () => buildDatabaseViewsPlan({
1078
+ ? await planStage('target plan', 'database-view', environmentLabel, () => buildDatabaseViewsPlan({
1068
1079
  client,
1069
1080
  cwd: input.cwd,
1070
1081
  envName: environmentKey,
@@ -1076,30 +1087,30 @@ async function planWorkspace(input) {
1076
1087
  }))
1077
1088
  : undefined;
1078
1089
  const components = resources.includes('component')
1079
- ? await runMigrationStage('target plan', 'component', environmentLabel, () => buildComponentPlan(componentCommandContext({
1090
+ ? await planStage('target plan', 'component', environmentLabel, () => buildComponentPlan(componentCommandContext({
1080
1091
  cwd: input.cwd,
1081
1092
  envName: componentTargetEnvironment(input),
1082
1093
  client,
1083
1094
  operation: 'plan',
1084
1095
  }), undefined, input.detailedDiff === true))
1085
1096
  : undefined;
1086
- const identities = await planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources });
1097
+ const identities = await runMigrationStage('identity plan', 'group', environmentLabel, () => planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources }), input.onProgress);
1087
1098
  if (input.prune && input.sourceMode !== 'workspace')
1088
1099
  throw new Error('Prune requires repository plan/deploy; named migration remains upsert-only.');
1089
- const prune = input.prune ? await buildWorkspacePrunePlan({ cwd: input.cwd, client, resources, captureTargets: true }) : undefined;
1100
+ const prune = input.prune ? await runMigrationStage('prune plan', 'component', environmentLabel, () => buildWorkspacePrunePlan({ cwd: input.cwd, client, resources, captureTargets: true }), input.onProgress) : undefined;
1090
1101
  const serviceAccounts = resources.includes('service-account')
1091
- ? await runMigrationStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
1102
+ ? await planStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
1092
1103
  projectedIdentities: identities?.projection })) : undefined;
1093
1104
  if (serviceAccounts && identities) {
1094
1105
  serviceAccounts.blockers.push(...identities.blockers);
1095
1106
  }
1096
1107
  const projected = { component: input.projectDependencies && components ? components.items.filter(item => !item.blocked && ['create', 'update'].includes(componentItemAction(item))).flatMap(item => item.stableKey ? [item.stableKey] : []) : [],
1097
1108
  'service-account': identities?.projection.serviceAccounts || [], group: identities?.projection.groups || [] };
1098
- const agentPlugins = resources.includes('agent-plugin') ? await runMigrationStage('target plan', 'agent-plugin', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent-plugin', projected })) : undefined;
1099
- const agents = resources.includes('agent') ? await runMigrationStage('target plan', 'agent', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent', projected: { ...projected,
1109
+ const agentPlugins = resources.includes('agent-plugin') ? await planStage('target plan', 'agent-plugin', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent-plugin', projected })) : undefined;
1110
+ const agents = resources.includes('agent') ? await planStage('target plan', 'agent', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent', projected: { ...projected,
1100
1111
  'agent-plugin': agentPlugins?.items.filter(item => !item.blocked && item.desiredHash).flatMap(item => item.stableKey ? [item.stableKey] : []) || [] } })) : undefined;
1101
1112
  const jobTemplates = resources.includes('job-template')
1102
- ? await runMigrationStage('target plan', 'job-template', environmentLabel, () => buildJobTemplatesPlan({
1113
+ ? await planStage('target plan', 'job-template', environmentLabel, () => buildJobTemplatesPlan({
1103
1114
  client,
1104
1115
  cwd: input.cwd,
1105
1116
  envName: environmentKey,
@@ -1112,7 +1123,7 @@ async function planWorkspace(input) {
1112
1123
  }))
1113
1124
  : undefined;
1114
1125
  const endpoints = resources.includes('endpoint')
1115
- ? await runMigrationStage('target plan', 'endpoint', environmentLabel, () => buildEndpointsPlan({
1126
+ ? await planStage('target plan', 'endpoint', environmentLabel, () => buildEndpointsPlan({
1116
1127
  client,
1117
1128
  cwd: input.cwd,
1118
1129
  envName: environmentKey,
@@ -1125,7 +1136,7 @@ async function planWorkspace(input) {
1125
1136
  }))
1126
1137
  : undefined;
1127
1138
  const schedules = resources.includes('schedule')
1128
- ? await runMigrationStage('target plan', 'schedule', environmentLabel, () => buildSchedulesPlan({
1139
+ ? await planStage('target plan', 'schedule', environmentLabel, () => buildSchedulesPlan({
1129
1140
  client,
1130
1141
  cwd: input.cwd,
1131
1142
  envName: environmentKey,
@@ -1139,7 +1150,7 @@ async function planWorkspace(input) {
1139
1150
  }))
1140
1151
  : undefined;
1141
1152
  const events = resources.includes('event')
1142
- ? await runMigrationStage('target plan', 'event', environmentLabel, () => buildEventsPlan({
1153
+ ? await planStage('target plan', 'event', environmentLabel, () => buildEventsPlan({
1143
1154
  client,
1144
1155
  cwd: input.cwd,
1145
1156
  envName: environmentKey,
@@ -1150,7 +1161,7 @@ async function planWorkspace(input) {
1150
1161
  }))
1151
1162
  : undefined;
1152
1163
  const groups = resources.includes('group')
1153
- ? await runMigrationStage('target plan', 'group', environmentLabel, () => buildGroupsPlan({
1164
+ ? await planStage('target plan', 'group', environmentLabel, () => buildGroupsPlan({
1154
1165
  client,
1155
1166
  cwd: input.cwd,
1156
1167
  envName: environmentKey,
@@ -1162,7 +1173,7 @@ async function planWorkspace(input) {
1162
1173
  groups.blockers.push(...identities.blockers);
1163
1174
  }
1164
1175
  const roleGroups = resources.includes('role-group')
1165
- ? await runMigrationStage('target plan', 'role-group', environmentLabel, () => buildRoleGroupsPlan({
1176
+ ? await planStage('target plan', 'role-group', environmentLabel, () => buildRoleGroupsPlan({
1166
1177
  client,
1167
1178
  cwd: input.cwd,
1168
1179
  envName: environmentKey,
@@ -1289,7 +1300,7 @@ export async function runMigration(input) {
1289
1300
  from: input.from,
1290
1301
  to: input.to,
1291
1302
  resources,
1292
- policy: { ...migrationPolicy(input), mode: 'upsert' },
1303
+ policy: { ...migrationPolicy(input), mode: 'upsert', ...(input.activateAutomations ? { activateAutomations: true } : {}) },
1293
1304
  sourcePull: pulls,
1294
1305
  plan: initialPlan,
1295
1306
  };
@@ -1297,9 +1308,12 @@ export async function runMigration(input) {
1297
1308
  return { ...base, verdict: 'blocked', results: [], phaseResults: {} };
1298
1309
  }
1299
1310
  const targetClient = resolveTargetClient(input);
1311
+ const deployStage = (resource, operation) => runMigrationStage('target deploy', resource, targetLabel(input), operation, input.onProgress);
1300
1312
  const environmentKey = targetKey(input);
1301
1313
  const phaseResults = {};
1302
1314
  const results = [];
1315
+ const pendingEvents = [];
1316
+ const pendingSchedules = [];
1303
1317
  let remainingPrune = initialPlan.prune;
1304
1318
  if (remainingPrune?.items.some((item) => item.beforeUpserts)) {
1305
1319
  const pruned = await applyWorkspacePrune({ cwd: input.cwd, client: targetClient,
@@ -1310,7 +1324,7 @@ export async function runMigration(input) {
1310
1324
  remainingPrune = { ...remainingPrune, items: remainingPrune.items.filter((item) => !item.beforeUpserts) };
1311
1325
  }
1312
1326
  if (resources.includes('database-table')) {
1313
- const pushed = await pushDatabaseSchemas({
1327
+ const pushed = await deployStage('database-table', () => pushDatabaseSchemas({
1314
1328
  client: targetClient,
1315
1329
  cwd: input.cwd,
1316
1330
  envName: environmentKey,
@@ -1319,17 +1333,17 @@ export async function runMigration(input) {
1319
1333
  prunePartitions: reviewedWorkspaceChanges && !input.prune,
1320
1334
  prunePartitionsConfirmed: reviewedWorkspaceChanges && !input.prune,
1321
1335
  migrationPolicy: migrationPolicy(input),
1322
- });
1336
+ }));
1323
1337
  phaseResults['database-table'] = pushed.results;
1324
1338
  results.push(...pushed.results);
1325
- const schemaVerification = await buildDatabaseSchemasPlan({
1339
+ const schemaVerification = await runMigrationStage('target plan', 'database-table', targetLabel(input), () => buildDatabaseSchemasPlan({
1326
1340
  client: targetClient,
1327
1341
  cwd: input.cwd,
1328
1342
  envName: environmentKey,
1329
1343
  stableKeyName,
1330
1344
  withStats: input.withStats,
1331
1345
  migrationPolicy: migrationPolicy(input),
1332
- });
1346
+ }), input.onProgress);
1333
1347
  const schemaPhase = applyWorkspaceDeploymentPolicy(input, summarizeSchemaPhase(schemaVerification), {
1334
1348
  databaseSchemas: schemaVerification,
1335
1349
  });
@@ -1353,13 +1367,13 @@ export async function runMigration(input) {
1353
1367
  }
1354
1368
  }
1355
1369
  if (resources.includes('database-view')) {
1356
- const liveViewPlan = await buildDatabaseViewsPlan({
1370
+ const liveViewPlan = await runMigrationStage('target plan', 'database-view', targetLabel(input), () => buildDatabaseViewsPlan({
1357
1371
  client: targetClient,
1358
1372
  cwd: input.cwd,
1359
1373
  envName: environmentKey,
1360
1374
  stableKeyName,
1361
1375
  migrationPolicy: viewMigrationPolicy(input),
1362
- });
1376
+ }), input.onProgress);
1363
1377
  const liveViewPhase = applyWorkspaceDeploymentPolicy(input, summarizeViewPhase(liveViewPlan), {
1364
1378
  databaseViews: liveViewPlan,
1365
1379
  });
@@ -1371,14 +1385,14 @@ export async function runMigration(input) {
1371
1385
  });
1372
1386
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1373
1387
  }
1374
- const pushed = await pushDatabaseViews({
1388
+ const pushed = await deployStage('database-view', () => pushDatabaseViews({
1375
1389
  client: targetClient,
1376
1390
  cwd: input.cwd,
1377
1391
  envName: environmentKey,
1378
1392
  stableKeyName,
1379
1393
  force: true,
1380
1394
  migrationPolicy: viewMigrationPolicy(input),
1381
- });
1395
+ }));
1382
1396
  phaseResults['database-view'] = pushed.results;
1383
1397
  results.push(...pushed.results);
1384
1398
  }
@@ -1398,13 +1412,13 @@ export async function runMigration(input) {
1398
1412
  });
1399
1413
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1400
1414
  }
1401
- const componentResults = await pushAllComponents(componentCommandContext({
1415
+ const componentResults = await deployStage('component', () => pushAllComponents(componentCommandContext({
1402
1416
  cwd: input.cwd,
1403
1417
  envName: componentTargetEnvironment(input),
1404
1418
  client: targetClient,
1405
1419
  operation: 'push',
1406
1420
  ...(input.reviewedPlan ? { reviewedComponents: initialPlan.components?.items } : {}),
1407
- }), { force: true, yes: true });
1421
+ }), { force: true, yes: true }));
1408
1422
  phaseResults.component = componentResults;
1409
1423
  results.push(...componentResults);
1410
1424
  if (!componentResultsAreComplete(componentResults)) {
@@ -1439,7 +1453,7 @@ export async function runMigration(input) {
1439
1453
  for (const node of identityRun.ordered) {
1440
1454
  const pushed = node.resource === 'service-account'
1441
1455
  ? await pushServiceAccounts({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] })
1442
- : await pushGroups({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] });
1456
+ : await deployStage('group', () => pushGroups({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, force: true, onlyStableKeys: [node.stableKey] }));
1443
1457
  const relevant = pushed.results.filter((item) => item.stableKey === node.stableKey);
1444
1458
  phaseResults[node.resource] = [...(phaseResults[node.resource] || []), ...relevant];
1445
1459
  results.push(...relevant);
@@ -1459,19 +1473,19 @@ export async function runMigration(input) {
1459
1473
  }
1460
1474
  for (const family of ['agent-plugin', 'agent'])
1461
1475
  if (resources.includes(family)) {
1462
- const pushed = await pushAgents({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, family, force: true });
1476
+ const pushed = await deployStage(family, () => pushAgents({ client: targetClient, cwd: input.cwd, envName: environmentKey, stableKeyName, family, force: true }));
1463
1477
  phaseResults[family] = pushed.results;
1464
1478
  results.push(...pushed.results);
1465
1479
  if (!resultsAreComplete(pushed.results))
1466
1480
  return { ...base, verdict: 'failed', results, phaseResults };
1467
1481
  }
1468
1482
  if (resources.includes('job-template')) {
1469
- const liveJobTemplatePlan = await buildJobTemplatesPlan({
1483
+ const liveJobTemplatePlan = await runMigrationStage('target plan', 'job-template', targetLabel(input), () => buildJobTemplatesPlan({
1470
1484
  client: targetClient,
1471
1485
  cwd: input.cwd,
1472
1486
  envName: environmentKey,
1473
1487
  stableKeyName,
1474
- });
1488
+ }), input.onProgress);
1475
1489
  const liveJobTemplatePhase = summarizeJobTemplatePhase(liveJobTemplatePlan);
1476
1490
  if (!liveJobTemplatePhase.readyToMigrate) {
1477
1491
  const verification = await planWorkspace({
@@ -1481,13 +1495,13 @@ export async function runMigration(input) {
1481
1495
  });
1482
1496
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1483
1497
  }
1484
- const pushed = await pushJobTemplates({
1498
+ const pushed = await deployStage('job-template', () => pushJobTemplates({
1485
1499
  client: targetClient,
1486
1500
  cwd: input.cwd,
1487
1501
  envName: environmentKey,
1488
1502
  stableKeyName,
1489
1503
  force: true,
1490
- });
1504
+ }));
1491
1505
  phaseResults['job-template'] = pushed.results;
1492
1506
  results.push(...pushed.results);
1493
1507
  if (!jobTemplateResultsAreComplete(pushed.results)) {
@@ -1500,13 +1514,13 @@ export async function runMigration(input) {
1500
1514
  }
1501
1515
  }
1502
1516
  if (resources.includes('endpoint')) {
1503
- const liveEndpointPlan = await buildEndpointsPlan({
1517
+ const liveEndpointPlan = await runMigrationStage('target plan', 'endpoint', targetLabel(input), () => buildEndpointsPlan({
1504
1518
  client: targetClient,
1505
1519
  cwd: input.cwd,
1506
1520
  envName: environmentKey,
1507
1521
  stableKeyName,
1508
1522
  includeDependencyBlockers: input.sourceMode === 'workspace',
1509
- });
1523
+ }), input.onProgress);
1510
1524
  const liveEndpointPhase = summarizeEndpointPhase(liveEndpointPlan);
1511
1525
  if (!liveEndpointPhase.readyToMigrate) {
1512
1526
  const verification = await planWorkspace({
@@ -1516,13 +1530,13 @@ export async function runMigration(input) {
1516
1530
  });
1517
1531
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1518
1532
  }
1519
- const pushed = await pushEndpoints({
1533
+ const pushed = await deployStage('endpoint', () => pushEndpoints({
1520
1534
  client: targetClient,
1521
1535
  cwd: input.cwd,
1522
1536
  envName: environmentKey,
1523
1537
  stableKeyName,
1524
1538
  force: true,
1525
- });
1539
+ }));
1526
1540
  phaseResults.endpoint = pushed.results;
1527
1541
  results.push(...pushed.results);
1528
1542
  if (!endpointResultsAreComplete(pushed.results)) {
@@ -1535,12 +1549,12 @@ export async function runMigration(input) {
1535
1549
  }
1536
1550
  }
1537
1551
  if (resources.includes('schedule')) {
1538
- const liveSchedulePlan = await buildSchedulesPlan({
1552
+ const liveSchedulePlan = await runMigrationStage('target plan', 'schedule', targetLabel(input), () => buildSchedulesPlan({
1539
1553
  client: targetClient,
1540
1554
  cwd: input.cwd,
1541
1555
  envName: environmentKey,
1542
1556
  stableKeyName,
1543
- });
1557
+ }), input.onProgress);
1544
1558
  const liveSchedulePhase = applyWorkspaceDeploymentPolicy(input, summarizeSchedulePhase(liveSchedulePlan), {
1545
1559
  schedules: liveSchedulePlan,
1546
1560
  });
@@ -1552,13 +1566,14 @@ export async function runMigration(input) {
1552
1566
  });
1553
1567
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1554
1568
  }
1555
- const pushed = await pushSchedules({
1569
+ const pushed = await deployStage('schedule', () => pushSchedules({
1556
1570
  client: targetClient,
1557
1571
  cwd: input.cwd,
1558
1572
  envName: environmentKey,
1559
1573
  stableKeyName,
1560
1574
  force: true,
1561
- });
1575
+ }));
1576
+ pendingSchedules.push(...pushed.verifiedActivationCandidates);
1562
1577
  phaseResults.schedule = pushed.results;
1563
1578
  results.push(...pushed.results);
1564
1579
  if (!scheduleResultsAreComplete(pushed.results)) {
@@ -1571,12 +1586,12 @@ export async function runMigration(input) {
1571
1586
  }
1572
1587
  }
1573
1588
  if (resources.includes('event')) {
1574
- const liveEventPlan = await buildEventsPlan({
1589
+ const liveEventPlan = await runMigrationStage('target plan', 'event', targetLabel(input), () => buildEventsPlan({
1575
1590
  client: targetClient,
1576
1591
  cwd: input.cwd,
1577
1592
  envName: environmentKey,
1578
1593
  stableKeyName,
1579
- });
1594
+ }), input.onProgress);
1580
1595
  const liveEventPhase = summarizeEventPhase(liveEventPlan);
1581
1596
  if (!liveEventPhase.readyToMigrate) {
1582
1597
  const verification = await planWorkspace({
@@ -1586,13 +1601,14 @@ export async function runMigration(input) {
1586
1601
  });
1587
1602
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1588
1603
  }
1589
- const pushed = await pushEvents({
1604
+ const pushed = await deployStage('event', () => pushEvents({
1590
1605
  client: targetClient,
1591
1606
  cwd: input.cwd,
1592
1607
  envName: environmentKey,
1593
1608
  stableKeyName,
1594
1609
  force: true,
1595
- });
1610
+ }));
1611
+ pendingEvents.push(...pushed.verifiedActivationCandidates);
1596
1612
  phaseResults.event = pushed.results;
1597
1613
  results.push(...pushed.results);
1598
1614
  if (!eventResultsAreComplete(pushed.results)) {
@@ -1605,12 +1621,12 @@ export async function runMigration(input) {
1605
1621
  }
1606
1622
  }
1607
1623
  if (resources.includes('group')) {
1608
- const liveGroupPlan = await buildGroupsPlan({
1624
+ const liveGroupPlan = await runMigrationStage('target plan', 'group', targetLabel(input), () => buildGroupsPlan({
1609
1625
  client: targetClient,
1610
1626
  cwd: input.cwd,
1611
1627
  envName: environmentKey,
1612
1628
  stableKeyName,
1613
- });
1629
+ }), input.onProgress);
1614
1630
  const liveGroupPhase = applyWorkspaceDeploymentPolicy(input, summarizeGroupPhase(liveGroupPlan), {
1615
1631
  groups: liveGroupPlan,
1616
1632
  });
@@ -1622,13 +1638,13 @@ export async function runMigration(input) {
1622
1638
  });
1623
1639
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1624
1640
  }
1625
- const pushed = await pushGroups({
1641
+ const pushed = await deployStage('group', () => pushGroups({
1626
1642
  client: targetClient,
1627
1643
  cwd: input.cwd,
1628
1644
  envName: environmentKey,
1629
1645
  stableKeyName,
1630
1646
  force: true,
1631
- });
1647
+ }));
1632
1648
  const groupRemaining = pushed.results.filter((item) => !(phaseResults.group || []).some((prior) => 'stableKey' in prior && prior.stableKey === item.stableKey));
1633
1649
  phaseResults.group = [...(phaseResults.group || []), ...groupRemaining];
1634
1650
  results.push(...groupRemaining);
@@ -1642,12 +1658,12 @@ export async function runMigration(input) {
1642
1658
  }
1643
1659
  }
1644
1660
  if (resources.includes('role-group')) {
1645
- const liveRoleGroupPlan = await buildRoleGroupsPlan({
1661
+ const liveRoleGroupPlan = await runMigrationStage('target plan', 'role-group', targetLabel(input), () => buildRoleGroupsPlan({
1646
1662
  client: targetClient,
1647
1663
  cwd: input.cwd,
1648
1664
  envName: environmentKey,
1649
1665
  stableKeyName,
1650
- });
1666
+ }), input.onProgress);
1651
1667
  const liveRoleGroupPhase = applyWorkspaceDeploymentPolicy(input, summarizeRoleGroupPhase(liveRoleGroupPlan), {
1652
1668
  roleGroups: liveRoleGroupPlan,
1653
1669
  });
@@ -1659,13 +1675,13 @@ export async function runMigration(input) {
1659
1675
  });
1660
1676
  return { ...base, verdict: 'failed', results, phaseResults, verification };
1661
1677
  }
1662
- const pushed = await pushRoleGroups({
1678
+ const pushed = await deployStage('role-group', () => pushRoleGroups({
1663
1679
  client: targetClient,
1664
1680
  cwd: input.cwd,
1665
1681
  envName: environmentKey,
1666
1682
  stableKeyName,
1667
1683
  force: true,
1668
- });
1684
+ }));
1669
1685
  phaseResults['role-group'] = pushed.results;
1670
1686
  results.push(...pushed.results);
1671
1687
  if (!resultsAreComplete(pushed.results)) {
@@ -1686,6 +1702,21 @@ export async function runMigration(input) {
1686
1702
  const pruneResults = await applyWorkspacePrune({ cwd: input.cwd, client: targetClient,
1687
1703
  resources, envName: environmentKey, plan: remainingPrune });
1688
1704
  results.push(...pruneResults);
1705
+ if (!resultsAreComplete(pruneResults))
1706
+ return { ...base, verdict: 'failed', results, phaseResults };
1707
+ }
1708
+ // Enable automation only after every definition write and obsolete consumer deletion succeeded.
1709
+ if (input.activateAutomations) {
1710
+ for (const [family, activate] of [
1711
+ ['event', () => activateVerifiedEvents({ client: targetClient, candidates: pendingEvents })],
1712
+ ['schedule', () => activateVerifiedSchedules({ client: targetClient, candidates: pendingSchedules })],
1713
+ ]) {
1714
+ const activated = await activate();
1715
+ results.push(...activated);
1716
+ phaseResults[family] = [...(phaseResults[family] || []), ...activated];
1717
+ if (!resultsAreComplete(activated))
1718
+ return { ...base, verdict: 'failed', results, phaseResults };
1719
+ }
1689
1720
  }
1690
1721
  const verification = await planWorkspace({
1691
1722
  ...input,
@@ -0,0 +1,2 @@
1
+ import type { RevoClient } from './client.ts';
2
+ export declare function planningSnapshot(client: RevoClient): RevoClient;
@@ -0,0 +1,29 @@
1
+ // Only one planning pass owns this cache. Mutation/readback uses the original
2
+ // client, and the next pass always starts empty. Never persist auth or row data.
3
+ export function planningSnapshot(client) {
4
+ const pending = new Map();
5
+ return new Proxy(client, {
6
+ get(target, property) {
7
+ const value = Reflect.get(target, property, target);
8
+ if (typeof value !== 'function')
9
+ return value;
10
+ if (typeof property !== 'string' || !/^(listAll|get)(Components?|ComponentSyncManifests|ComponentRuntime|ComponentSnapshotVersion|DatabaseSchemas?|DatabaseViews?ForSync|DatabaseView|Endpoints?|JobTemplates?|Schedules?|Events?|RoleGroups?|Groups?|ServiceAccounts?|Accounts?|Agents?|AgentPlugins?)$/.test(property)) {
11
+ return value.bind(target);
12
+ }
13
+ return async (...args) => {
14
+ // These detail methods accept transport timeout options only; they do not
15
+ // select different authoring state. Preserve semantic args for other methods.
16
+ const readArgs = ['getComponent', 'getEndpoint'].includes(property) ? args.slice(0, 1) : args;
17
+ const key = JSON.stringify([property, readArgs]);
18
+ let request = pending.get(key);
19
+ if (!request) {
20
+ request = Promise.resolve().then(() => value.apply(target, args));
21
+ pending.set(key, request);
22
+ request.catch(() => pending.delete(key));
23
+ }
24
+ // Planners annotate records. No consumer may mutate another's snapshot.
25
+ return structuredClone(await request);
26
+ };
27
+ },
28
+ });
29
+ }
@@ -1,3 +1,4 @@
1
+ import { loadComponentSources } from "../component-manifests.js";
1
2
  import { componentContentDigest, componentRevisionByDigest, isComponentDigest } from "../component-contract.js";
2
3
  import { executionPrincipalAvailable, portableExecutionPolicy, runtimeExecutionPolicyPayload, validPortableExecutionPolicy } from "./account-principal.js";
3
4
  import path from 'node:path';
@@ -245,20 +246,8 @@ async function loadRemoteEndpoints(client) {
245
246
  }, () => client.getEndpoint(endpointId, { timeoutMs: REMOTE_DETAIL_REQUEST_TIMEOUT_MS })));
246
247
  }, HTTP_REQUEST_CONCURRENCY);
247
248
  }
248
- async function loadRemoteComponents(client) {
249
- const { components } = await withHttpTraceContext({ dependency: 'component', operation: 'list' }, () => client.listAllComponents());
250
- return mapWithConcurrency(components, async (summary) => {
251
- const componentId = componentIdOf(summary);
252
- if (!componentId) {
253
- return summary;
254
- }
255
- return unwrapData(await withHttpTraceContext({
256
- dependency: 'component',
257
- operation: 'get',
258
- entityId: componentId,
259
- ...(typeof summary.name === 'string' ? { entityName: summary.name } : {}),
260
- }, () => client.getComponent(componentId, { timeoutMs: REMOTE_DETAIL_REQUEST_TIMEOUT_MS })));
261
- }, HTTP_REQUEST_CONCURRENCY);
249
+ async function loadRemoteComponents(client, cwd) {
250
+ return loadComponentSources(client, cwd);
262
251
  }
263
252
  async function componentBinding(input) {
264
253
  const component = input.componentsById.get(input.componentId);
@@ -358,7 +347,7 @@ export async function pullEndpointsToWorkspace(input) {
358
347
  const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Endpoint');
359
348
  const [records, components] = await Promise.all([
360
349
  loadRemoteEndpoints(input.client),
361
- loadRemoteComponents(input.client),
350
+ loadRemoteComponents(input.client, input.cwd),
362
351
  ]);
363
352
  const componentsById = new Map(components.map((component) => [componentIdOf(component), component]));
364
353
  const manifests = [];
@@ -761,7 +750,7 @@ export async function buildEndpointsPlan(input) {
761
750
  }
762
751
  const [targetEndpoints, targetComponents] = await Promise.all([
763
752
  loadRemoteEndpoints(input.client),
764
- loadRemoteComponents(input.client),
753
+ loadRemoteComponents(input.client, input.cwd),
765
754
  ]);
766
755
  const workspaceComponents = readWorkspaceComponents(input.cwd, input.stableKeyName);
767
756
  const targetComponentsByKey = targetComponentsByStableKey(targetComponents, input.stableKeyName);
@@ -1150,7 +1139,7 @@ function endpointWriteOptions(manifest, schemaComponent) {
1150
1139
  return Object.keys(options).length > 0 ? options : undefined;
1151
1140
  }
1152
1141
  async function resolveEndpointWritePayload(input) {
1153
- const targetComponents = await loadRemoteComponents(input.client);
1142
+ const targetComponents = await loadRemoteComponents(input.client, input.cwd);
1154
1143
  const targetByKey = targetComponentsByStableKey(targetComponents, input.stableKeyName);
1155
1144
  const workspaceComponents = input.workspaceComponents || readWorkspaceComponents(input.cwd, input.stableKeyName);
1156
1145
  const diagnostics = componentDependencyDiagnostics({
@@ -1239,7 +1228,7 @@ async function verifyEndpointWrite(input) {
1239
1228
  if (verifiedStableKey !== input.stableKey) {
1240
1229
  throw new Error(`written target is missing or changed ${input.stableKeyName}`);
1241
1230
  }
1242
- const targetComponents = await loadRemoteComponents(input.client);
1231
+ const targetComponents = await loadRemoteComponents(input.client, input.cwd);
1243
1232
  const componentsById = new Map(targetComponents.map((component) => [componentIdOf(component), component]));
1244
1233
  const verifiedManifest = await manifestFromRecord({
1245
1234
  includeExecutionPolicy: input.desiredManifest.executionPolicy !== undefined,
@@ -1297,6 +1286,7 @@ async function executeEndpointPushItem(input) {
1297
1286
  };
1298
1287
  const endpointId = await input.mutate(prepared);
1299
1288
  const remoteHash = await verifyEndpointWrite({
1289
+ cwd: input.cwd,
1300
1290
  client: input.client,
1301
1291
  endpointId,
1302
1292
  stableKey,
@@ -1372,7 +1362,7 @@ async function pushEndpointUpdate(input) {
1372
1362
  if (!targetId) {
1373
1363
  throw new Error('live target did not include endpointId');
1374
1364
  }
1375
- const targetComponents = await loadRemoteComponents(input.client);
1365
+ const targetComponents = await loadRemoteComponents(input.client, input.cwd);
1376
1366
  const targetManifest = await manifestFromRecord({
1377
1367
  includeExecutionPolicy: prepared.manifest.executionPolicy !== undefined,
1378
1368
  client: input.client,
@@ -1513,7 +1503,7 @@ export async function pushEndpoints(input) {
1513
1503
  if (endpointRevisionHash(target) !== item.targetRevisionHash) {
1514
1504
  throw new Error('deleted target changed after planning');
1515
1505
  }
1516
- const targetComponents = await loadRemoteComponents(input.client);
1506
+ const targetComponents = await loadRemoteComponents(input.client, input.cwd);
1517
1507
  const restoreBlockers = await activeDeletedEndpointRestoreBlockers({
1518
1508
  client: input.client,
1519
1509
  record: target,
@@ -847,6 +847,11 @@ export async function activateVerifiedEvents(input) {
847
847
  });
848
848
  continue;
849
849
  }
850
+ // Check the complete verified definition again before enabling its side effects.
851
+ await verifyEventWrite({ client: input.client, stableKeyName: candidate.stableKeyName,
852
+ manifest: candidate.manifest, eventId: candidate.eventId,
853
+ jobTemplateId: String(current.targetId || ''), expectedActive: current.active === true,
854
+ jobTemplatesById: jobTemplatesCache });
850
855
  if (candidate.manifest.active) {
851
856
  await input.client.activateEvent(candidate.eventId);
852
857
  }