nx 23.3.0-beta.7 → 23.3.0-beta.8

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 (115) hide show
  1. package/README.md +1 -1
  2. package/dist/nx-cloud-internals.d.ts +1 -1
  3. package/dist/nx-cloud-internals.js +4 -4
  4. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +6 -2
  5. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +88 -14
  6. package/dist/src/command-line/migrate/command-object.d.ts +1 -0
  7. package/dist/src/command-line/migrate/command-object.js +6 -1
  8. package/dist/src/command-line/migrate/migrate-analytics.d.ts +34 -9
  9. package/dist/src/command-line/migrate/migrate-analytics.js +71 -10
  10. package/dist/src/command-line/migrate/migrate-config.d.ts +5 -2
  11. package/dist/src/command-line/migrate/migrate-config.js +19 -11
  12. package/dist/src/command-line/migrate/migrate.d.ts +2 -0
  13. package/dist/src/command-line/migrate/migrate.js +152 -45
  14. package/dist/src/command-line/migrate/resolve-package-version.js +2 -19
  15. package/dist/src/command-line/migrate/run/broker.d.ts +14 -2
  16. package/dist/src/command-line/migrate/run/broker.js +95 -34
  17. package/dist/src/command-line/migrate/run/existing-run-report.d.ts +55 -0
  18. package/dist/src/command-line/migrate/run/existing-run-report.js +225 -0
  19. package/dist/src/command-line/migrate/run/give-up.d.ts +41 -0
  20. package/dist/src/command-line/migrate/run/give-up.js +148 -0
  21. package/dist/src/command-line/migrate/run/index.d.ts +6 -4
  22. package/dist/src/command-line/migrate/run/index.js +15 -2
  23. package/dist/src/command-line/migrate/run/issues.d.ts +14 -0
  24. package/dist/src/command-line/migrate/run/issues.js +59 -0
  25. package/dist/src/command-line/migrate/run/orchestrator.d.ts +40 -1
  26. package/dist/src/command-line/migrate/run/orchestrator.js +509 -160
  27. package/dist/src/command-line/migrate/run/run-id.d.ts +0 -8
  28. package/dist/src/command-line/migrate/run/run-id.js +0 -30
  29. package/dist/src/command-line/migrate/run/run-state.d.ts +11 -9
  30. package/dist/src/command-line/migrate/run/run-state.js +25 -12
  31. package/dist/src/command-line/migrate/run/runbook.js +9 -4
  32. package/dist/src/command-line/migrate/run/state-lock.d.ts +31 -0
  33. package/dist/src/command-line/migrate/run/state-lock.js +126 -0
  34. package/dist/src/command-line/migrate/run/state-machine.d.ts +15 -0
  35. package/dist/src/command-line/migrate/run/state-machine.js +137 -10
  36. package/dist/src/command-line/migrate/run/util.d.ts +1 -0
  37. package/dist/src/command-line/migrate/run/util.js +21 -0
  38. package/dist/src/command-line/migrate/run/worker.js +3 -0
  39. package/dist/src/command-line/migrate/step-actions.d.ts +1 -1
  40. package/dist/src/command-line/migrate/step-actions.js +7 -1
  41. package/dist/src/command-line/migrate/text.d.ts +6 -0
  42. package/dist/src/command-line/migrate/text.js +25 -0
  43. package/dist/src/command-line/release/utils/release-graph.js +1 -1
  44. package/dist/src/command-line/release/utils/remote-release-clients/github.js +2 -5
  45. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +2 -2
  46. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +4 -5
  47. package/dist/src/command-line/release/version/version-actions.d.ts +3 -0
  48. package/dist/src/command-line/reset/reset.js +3 -0
  49. package/dist/src/config/task-graph.d.ts +1 -1
  50. package/dist/src/config/workspace-json-project-json.d.ts +4 -4
  51. package/dist/src/daemon/client/client.d.ts +3 -3
  52. package/dist/src/daemon/client/client.js +4 -4
  53. package/dist/src/daemon/message-types/ultracache-configuration-version.d.ts +8 -0
  54. package/dist/src/daemon/server/handle-hash-tasks.d.ts +2 -2
  55. package/dist/src/daemon/server/handle-hash-tasks.js +3 -3
  56. package/dist/src/daemon/server/handle-select-affected-tasks.js +4 -2
  57. package/dist/src/daemon/server/ultracache-configuration-state.d.ts +7 -0
  58. package/dist/src/daemon/server/{io-snapshots-state.js → ultracache-configuration-state.js} +5 -4
  59. package/dist/src/hasher/create-task-hasher.d.ts +3 -3
  60. package/dist/src/hasher/create-task-hasher.js +6 -6
  61. package/dist/src/hasher/hash-task.d.ts +2 -2
  62. package/dist/src/hasher/hash-task.js +5 -5
  63. package/dist/src/hasher/native-task-hasher-impl.d.ts +7 -7
  64. package/dist/src/hasher/native-task-hasher-impl.js +19 -19
  65. package/dist/src/hasher/task-hasher.d.ts +14 -14
  66. package/dist/src/hasher/task-hasher.js +13 -13
  67. package/dist/src/native/index.d.ts +95 -102
  68. package/dist/src/native/native-bindings.js +4 -5
  69. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  70. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  71. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +15 -8
  72. package/dist/src/nx-cloud/update-manager.d.ts +3 -3
  73. package/dist/src/nx-cloud/update-manager.js +19 -13
  74. package/dist/src/nx-cloud/utilities/is-workspace-claimed.js +2 -1
  75. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.d.ts +5 -0
  76. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.js +16 -0
  77. package/dist/src/nx-cloud/utilities/url-shorten.js +17 -10
  78. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +22 -18
  79. package/dist/src/project-graph/affected/affected-tasks.d.ts +11 -10
  80. package/dist/src/project-graph/affected/affected-tasks.js +16 -20
  81. package/dist/src/tasks-runner/init-tasks-runner.d.ts +5 -5
  82. package/dist/src/tasks-runner/init-tasks-runner.js +8 -15
  83. package/dist/src/tasks-runner/run-command.d.ts +7 -7
  84. package/dist/src/tasks-runner/run-command.js +18 -23
  85. package/dist/src/ultracache/config.d.ts +21 -0
  86. package/dist/src/ultracache/config.js +29 -0
  87. package/dist/src/ultracache/fetch.d.ts +21 -0
  88. package/dist/src/{io-snapshots → ultracache}/fetch.js +9 -9
  89. package/dist/src/ultracache/overrides.d.ts +17 -0
  90. package/dist/src/{io-snapshots → ultracache}/overrides.js +14 -13
  91. package/dist/src/ultracache/report.d.ts +13 -0
  92. package/dist/src/{io-snapshots → ultracache}/report.js +15 -21
  93. package/dist/src/ultracache/store.d.ts +40 -0
  94. package/dist/src/{io-snapshots → ultracache}/store.js +45 -45
  95. package/dist/src/utils/ab-testing.js +11 -12
  96. package/dist/src/utils/db-connection.d.ts +1 -0
  97. package/dist/src/utils/db-connection.js +1 -0
  98. package/dist/src/utils/git-utils.d.ts +7 -0
  99. package/dist/src/utils/git-utils.js +21 -9
  100. package/dist/src/utils/http-client.d.ts +27 -0
  101. package/dist/src/utils/http-client.js +193 -0
  102. package/package.json +12 -38
  103. package/dist/src/daemon/message-types/io-snapshot-version.d.ts +0 -5
  104. package/dist/src/daemon/server/io-snapshots-state.d.ts +0 -7
  105. package/dist/src/io-snapshots/config.d.ts +0 -23
  106. package/dist/src/io-snapshots/config.js +0 -32
  107. package/dist/src/io-snapshots/fetch.d.ts +0 -21
  108. package/dist/src/io-snapshots/outputs.d.ts +0 -12
  109. package/dist/src/io-snapshots/outputs.js +0 -33
  110. package/dist/src/io-snapshots/overrides.d.ts +0 -17
  111. package/dist/src/io-snapshots/report.d.ts +0 -13
  112. package/dist/src/io-snapshots/store.d.ts +0 -37
  113. package/dist/src/nx-cloud/utilities/axios.d.ts +0 -4
  114. package/dist/src/nx-cloud/utilities/axios.js +0 -17
  115. /package/dist/src/daemon/message-types/{io-snapshot-version.js → ultracache-configuration-version.js} +0 -0
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](<>)
13
13
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
14
14
  [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
15
- [![Nx Sandboxing](https://staging.nx.app/workspaces/62d013ea0852fe0a2df74438/sandbox-badge.svg)](https://nx.dev/docs/features/ci-features/sandboxing)
15
+ [![Hours saved](https://img.shields.io/endpoint?url=https%3A%2F%2Fstaging.nx.app%2Fnx-cloud%2Fbadge%2F62d013ea0852fe0a2df74438%2Fhours-saved.json)](https://nx.dev/nx-cloud)
16
16
 
17
17
  </div>
18
18
 
@@ -1 +1 @@
1
- export { importIoSnapshots, openIoSnapshots } from './src/io-snapshots/store';
1
+ export { importUltracacheConfigurations, openUltracacheConfigurations, } from './src/ultracache/store';
@@ -3,7 +3,7 @@
3
3
  // a public API. The client probes these exports to tell what this nx supports,
4
4
  // so keep them stable.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.openIoSnapshots = exports.importIoSnapshots = void 0;
7
- var store_1 = require("./src/io-snapshots/store");
8
- Object.defineProperty(exports, "importIoSnapshots", { enumerable: true, get: function () { return store_1.importIoSnapshots; } });
9
- Object.defineProperty(exports, "openIoSnapshots", { enumerable: true, get: function () { return store_1.openIoSnapshots; } });
6
+ exports.openUltracacheConfigurations = exports.importUltracacheConfigurations = void 0;
7
+ var store_1 = require("./src/ultracache/store");
8
+ Object.defineProperty(exports, "importUltracacheConfigurations", { enumerable: true, get: function () { return store_1.importUltracacheConfigurations; } });
9
+ Object.defineProperty(exports, "openUltracacheConfigurations", { enumerable: true, get: function () { return store_1.openUltracacheConfigurations; } });
@@ -1,10 +1,14 @@
1
1
  import { type RunOrchestratorInitInput } from '../../run';
2
2
  import type { DetectedInstalledAgent } from '../types';
3
- export interface RunMasterSessionInput extends Omit<RunOrchestratorInitInput, 'emitAgentInstructions'> {
3
+ export interface RunMasterSessionInput extends Omit<RunOrchestratorInitInput, 'emitAgentInstructions' | 'onExistingRun'> {
4
4
  agent: DetectedInstalledAgent;
5
+ interactive?: boolean;
6
+ runId?: string;
7
+ startFresh?: boolean;
8
+ confirmStart: () => Promise<boolean>;
5
9
  }
6
10
  /**
7
- * Starts (or resumes) an orchestrated run and hands it to one agent session
11
+ * Starts (or continues) an orchestrated run and hands it to one agent session
8
12
  * that drives it through `--run-id` reconciles. Run state is the only
9
13
  * authority on the outcome: the exit code follows what run.json says once the
10
14
  * session ends, not what the agent process returned.
@@ -4,26 +4,65 @@ exports.runMasterSession = runMasterSession;
4
4
  const output_1 = require("../../../../utils/output");
5
5
  const migrate_analytics_1 = require("../../migrate-analytics");
6
6
  const run_1 = require("../../run");
7
+ const safe_prompt_1 = require("../../safe-prompt");
7
8
  const spawn_master_1 = require("./spawn-master");
8
9
  /**
9
- * Starts (or resumes) an orchestrated run and hands it to one agent session
10
+ * Starts (or continues) an orchestrated run and hands it to one agent session
10
11
  * that drives it through `--run-id` reconciles. Run state is the only
11
12
  * authority on the outcome: the exit code follows what run.json says once the
12
13
  * session ends, not what the agent process returned.
13
14
  */
14
15
  async function runMasterSession(input) {
15
- const { agent, ...init } = input;
16
- const ready = await (0, run_1.runOrchestratorInit)({
16
+ const { agent, interactive, runId: requestedRunId, startFresh, ...init } = input;
17
+ // The invocation's policy; an interactive continue adopts the run's recorded
18
+ // one instead, shown in the report and the choice, so resume, broker and
19
+ // the resume hint agree with the run.
20
+ let policy = {
21
+ createCommits: init.createCommits,
22
+ skipInstall: init.skipInstall,
23
+ };
24
+ const resume = (runId) => (0, run_1.runOrchestratorResume)({
25
+ root: init.root,
26
+ runId,
27
+ policy,
28
+ emitAgentInstructions: false,
29
+ });
30
+ // With `replaceRunId`, starts fresh over that run only; the consent covers
31
+ // the run the user saw, and any other active run is reported instead.
32
+ const start = (replaceRunId) => (0, run_1.runOrchestratorInit)({
17
33
  ...init,
18
34
  emitAgentInstructions: false,
35
+ onExistingRun: replaceRunId === undefined ? 'report' : 'start-fresh',
36
+ replaceRunId,
19
37
  });
38
+ let ready = requestedRunId !== undefined && !startFresh
39
+ ? resume(requestedRunId)
40
+ : await start(startFresh ? requestedRunId : undefined);
41
+ if (ready.kind === 'existing-run' && (0, safe_prompt_1.canPrompt)(interactive)) {
42
+ const decision = await decideExistingRun(ready, init.root);
43
+ if (decision === 'abort') {
44
+ output_1.output.log({
45
+ title: `Leaving migrate run ${ready.runId} as it is. ${continueHint(init.root, agent.id, ready.runId, ready.facts.policy)}`,
46
+ });
47
+ return;
48
+ }
49
+ if (decision === 'continue') {
50
+ policy = ready.facts.policy;
51
+ ready = resume(ready.runId);
52
+ }
53
+ else {
54
+ ready = await start(ready.runId);
55
+ }
56
+ }
57
+ if (ready.kind === 'existing-run') {
58
+ output_1.output.warn((0, run_1.renderExistingRunReport)(ready.facts, (0, run_1.renderExistingRunCommands)(init.root, ready.facts, init.migrationsPath, agent.id)));
59
+ return 1;
60
+ }
20
61
  if (ready.kind === 'refused') {
21
62
  return;
22
63
  }
23
64
  const { runId, runRoot, runbookPath, reconcileCommand } = ready;
24
- // Not rendered: the gate env var and the migrations path would have to be
25
- // reproduced, and the same command carries both.
26
- const resumeHint = 'Run the same nx migrate command again to resume it.';
65
+ const resumeHint = continueHint(init.root, agent.id, runId, policy);
27
66
  output_1.output.log({
28
67
  title: `Starting ${agent.displayName} to drive migrate run ${runId}.`,
29
68
  });
@@ -33,10 +72,7 @@ async function runMasterSession(input) {
33
72
  runId,
34
73
  runbookPath,
35
74
  reconcileCommand,
36
- policy: {
37
- createCommits: init.createCommits,
38
- skipInstall: init.skipInstall,
39
- },
75
+ policy,
40
76
  });
41
77
  if (session.kind === 'spawn-failed') {
42
78
  output_1.output.error({
@@ -69,16 +105,19 @@ async function runMasterSession(input) {
69
105
  }
70
106
  switch (state.status) {
71
107
  case 'active':
108
+ (0, migrate_analytics_1.reportMigrateOrchestratorAbandoned)({
109
+ ...(0, run_1.runTallies)(state),
110
+ agentUsed: agent.id,
111
+ });
72
112
  output_1.output.warn({
73
113
  title: `Migrate run ${runId} is still active. ${resumeHint}`,
74
114
  });
75
115
  return 1;
76
116
  case 'completed': {
77
- const applied = state.steps.filter((s) => s.status === 'succeeded').length;
78
- const skipped = state.steps.filter((s) => s.status === 'skipped').length;
117
+ const tally = (0, run_1.tallySteps)(state);
79
118
  output_1.output.log({
80
119
  title: `Migrate run ${runId} is complete.`,
81
- bodyLines: [` applied: ${applied}`, ` skipped: ${skipped}`],
120
+ bodyLines: (0, run_1.completionSummaryLines)(state),
82
121
  });
83
122
  for (const lines of (0, run_1.completionWarnings)(runRoot, runId, state)) {
84
123
  output_1.output.warn({ title: lines[0], bodyLines: lines.slice(1) });
@@ -87,8 +126,14 @@ async function runMasterSession(input) {
87
126
  agenticOutcome: 'enabled',
88
127
  agentUsed: agent.id,
89
128
  migrationCount: state.steps.length,
90
- appliedCount: applied,
129
+ appliedCount: tally.applied + tally.adopted,
91
130
  });
131
+ if (tally.unresolved.length > 0 || (0, run_1.hasUnresolvedIssues)(state)) {
132
+ output_1.output.warn({
133
+ title: `Migrate run ${runId} left work unresolved; exiting with code 1.`,
134
+ });
135
+ return 1;
136
+ }
92
137
  return;
93
138
  }
94
139
  default: {
@@ -97,3 +142,32 @@ async function runMasterSession(input) {
97
142
  }
98
143
  }
99
144
  }
145
+ function continueHint(root, agentId, runId, policy) {
146
+ return `Run ${(0, run_1.renderContinueCommand)(root, runId, policy, agentId)}, with NX_MIGRATE_ORCHESTRATOR=true set in the environment, to continue it.`;
147
+ }
148
+ async function decideExistingRun(found, root) {
149
+ output_1.output.log((0, run_1.renderExistingRunReport)(found.facts));
150
+ // A held run leaves nothing to ask: continue would open a second session
151
+ // over the live one, and start fresh refuses. The continue's own gate
152
+ // throws the refusal; a holder gone since the report lets the prompt run.
153
+ if (found.facts.otherHolders === 'unknown' ||
154
+ found.facts.otherHolders.length > 0) {
155
+ (0, run_1.holdRunToContinue)(root, found.runId);
156
+ }
157
+ return (0, safe_prompt_1.migrateChoice)({
158
+ message: 'What do you want to do with the active migrate run?',
159
+ choices: [
160
+ {
161
+ value: 'continue',
162
+ label: 'Continue it',
163
+ hint: 'picks the run up where it stopped, keeping its recorded commit and install policy',
164
+ },
165
+ {
166
+ value: 'start-fresh',
167
+ label: 'Start fresh',
168
+ hint: 'deletes the run record only; the whole plan runs again',
169
+ },
170
+ { value: 'abort', label: 'Abort', hint: 'leaves the run as it is' },
171
+ ],
172
+ });
173
+ }
@@ -21,6 +21,7 @@ export interface MigrateArgs {
21
21
  runMigration?: string;
22
22
  runId?: string;
23
23
  stepAction?: StepAction;
24
+ startFresh?: boolean;
24
25
  include?: MigrateInclude;
25
26
  /**
26
27
  * nx.json `migrate.include` default. Consumed by `resolveInclude` only when the
@@ -60,7 +60,7 @@ function withMigrationOptions(yargs) {
60
60
  })
61
61
  .option('runId', {
62
62
  // Hidden with the orchestrator itself.
63
- describe: 'The orchestrated migrate run to record a single migration into, or to reconcile when given without --run-migration.',
63
+ describe: 'The orchestrated migrate run to record a single migration into, to continue with --run-migrations, or to reconcile when given alone.',
64
64
  type: 'string',
65
65
  hidden: true,
66
66
  })
@@ -69,6 +69,11 @@ function withMigrationOptions(yargs) {
69
69
  choices: step_actions_1.STEP_ACTIONS,
70
70
  type: 'string',
71
71
  hidden: true,
72
+ })
73
+ .option('startFresh', {
74
+ describe: 'With --run-migrations and --run-id=<id> under the orchestrator: delete the record of the active migrate run the id names and start a new run over the whole plan. Migrations the deleted run applied stay applied.',
75
+ type: 'boolean',
76
+ hidden: true,
72
77
  })
73
78
  .option('ifExists', {
74
79
  describe: `Run migrations only if the migrations file exists, if not continues successfully.`,
@@ -72,23 +72,48 @@ export declare function reportMigrateOrchestratorInit(opts: {
72
72
  createCommits: boolean;
73
73
  }): void;
74
74
  /**
75
- * One event per orchestrator dispense. The `action` (dispense case) is a
76
- * closed enum carried on a reused dimension, read conditioned on the event
77
- * name (the same multiplexing pattern as {@link reportMigratePrompt});
78
- * `attempt` rides the migration-count dimension.
75
+ * One event per dispense response, repeated on every reconcile until the
76
+ * step moves. The `action` (dispense case) is a closed enum carried on a
77
+ * reused dimension, read conditioned on the event name (the same
78
+ * multiplexing pattern as {@link reportMigratePrompt}); `attempt` rides the
79
+ * migration-count dimension and `ordinal` (the run's dispense count) the
80
+ * task-count one.
79
81
  */
80
82
  export declare function reportMigrateOrchestratorDispense(opts: {
81
83
  action: string;
82
84
  attempt: number;
85
+ ordinal?: number;
83
86
  }): void;
84
- /**
85
- * Terminal funnel event. The two step tallies and the total dispense count
86
- * ride reused numeric dimensions, read conditioned on the event name.
87
- */
88
- export declare function reportMigrateOrchestratorComplete(opts: {
87
+ /** Once per durable dispense transition. */
88
+ export declare function reportMigrateOrchestratorStepDispensed(opts: {
89
+ attempt: number;
90
+ ordinal: number;
91
+ }): void;
92
+ export interface MigrateOrchestratorTallies {
89
93
  completed: number;
90
94
  skipped: number;
95
+ unresolved: number;
91
96
  dispenseCount: number;
97
+ }
98
+ export declare function reportMigrateOrchestratorComplete(opts: MigrateOrchestratorTallies): void;
99
+ /** The agent session nx spawned ended with the run still active. */
100
+ export declare function reportMigrateOrchestratorAbandoned(opts: MigrateOrchestratorTallies & {
101
+ agentUsed: string;
102
+ }): void;
103
+ /**
104
+ * An explicit continue (`--run-migrations --run-id`, or "continue" at the
105
+ * master prompt) took up an active run; every resume reports. A bare
106
+ * `--run-id` reconcile is not a resume: nothing in run state marks the first
107
+ * call after a lost session.
108
+ */
109
+ export declare function reportMigrateOrchestratorResume(opts: MigrateOrchestratorTallies): void;
110
+ /**
111
+ * An invocation found an active run and started nothing. `activity` says
112
+ * whether another nx migrate process held the run; 'unknown' where nx cannot
113
+ * tell.
114
+ */
115
+ export declare function reportMigrateOrchestratorExistingRun(opts: MigrateOrchestratorTallies & {
116
+ activity: 'idle' | 'held' | 'unknown';
92
117
  }): void;
93
118
  /**
94
119
  * Counts invocations, not completions: emitted as soon as the migration id
@@ -13,7 +13,11 @@ exports.reportMigrateRunComplete = reportMigrateRunComplete;
13
13
  exports.reportMigrateRunError = reportMigrateRunError;
14
14
  exports.reportMigrateOrchestratorInit = reportMigrateOrchestratorInit;
15
15
  exports.reportMigrateOrchestratorDispense = reportMigrateOrchestratorDispense;
16
+ exports.reportMigrateOrchestratorStepDispensed = reportMigrateOrchestratorStepDispensed;
16
17
  exports.reportMigrateOrchestratorComplete = reportMigrateOrchestratorComplete;
18
+ exports.reportMigrateOrchestratorAbandoned = reportMigrateOrchestratorAbandoned;
19
+ exports.reportMigrateOrchestratorResume = reportMigrateOrchestratorResume;
20
+ exports.reportMigrateOrchestratorExistingRun = reportMigrateOrchestratorExistingRun;
17
21
  exports.reportMigrateSingleMigrationInvocation = reportMigrateSingleMigrationInvocation;
18
22
  exports.computeMajorsCrossed = computeMajorsCrossed;
19
23
  exports.safeReport = safeReport;
@@ -195,10 +199,12 @@ function reportMigrateOrchestratorInit(opts) {
195
199
  });
196
200
  }
197
201
  /**
198
- * One event per orchestrator dispense. The `action` (dispense case) is a
199
- * closed enum carried on a reused dimension, read conditioned on the event
200
- * name (the same multiplexing pattern as {@link reportMigratePrompt});
201
- * `attempt` rides the migration-count dimension.
202
+ * One event per dispense response, repeated on every reconcile until the
203
+ * step moves. The `action` (dispense case) is a closed enum carried on a
204
+ * reused dimension, read conditioned on the event name (the same
205
+ * multiplexing pattern as {@link reportMigratePrompt}); `attempt` rides the
206
+ * migration-count dimension and `ordinal` (the run's dispense count) the
207
+ * task-count one.
202
208
  */
203
209
  function reportMigrateOrchestratorDispense(opts) {
204
210
  safeReport(() => {
@@ -207,21 +213,76 @@ function reportMigrateOrchestratorDispense(opts) {
207
213
  (0, analytics_1.reportEvent)('migrate_orchestrator_dispense', {
208
214
  [analytics_1.customDimensions.promptChoice]: opts.action,
209
215
  [analytics_1.customDimensions.migrationCount]: opts.attempt,
216
+ [analytics_1.customDimensions.taskCount]: opts.ordinal,
217
+ });
218
+ });
219
+ }
220
+ /** Once per durable dispense transition. */
221
+ function reportMigrateOrchestratorStepDispensed(opts) {
222
+ safeReport(() => {
223
+ if (!analytics_1.customDimensions)
224
+ return;
225
+ (0, analytics_1.reportEvent)('migrate_orchestrator_step_dispensed', {
226
+ [analytics_1.customDimensions.migrationCount]: opts.attempt,
227
+ [analytics_1.customDimensions.taskCount]: opts.ordinal,
210
228
  });
211
229
  });
212
230
  }
213
231
  /**
214
- * Terminal funnel event. The two step tallies and the total dispense count
215
- * ride reused numeric dimensions, read conditioned on the event name.
232
+ * The three step tallies and the total dispense count ride reused numeric
233
+ * dimensions, read conditioned on the event name.
216
234
  */
235
+ function orchestratorTallyParams(tallies) {
236
+ return {
237
+ [analytics_1.customDimensions.appliedCount]: tallies.completed,
238
+ [analytics_1.customDimensions.taskCount]: tallies.skipped,
239
+ [analytics_1.customDimensions.majorsCrossed]: tallies.unresolved,
240
+ [analytics_1.customDimensions.migrationCount]: tallies.dispenseCount,
241
+ };
242
+ }
217
243
  function reportMigrateOrchestratorComplete(opts) {
218
244
  safeReport(() => {
219
245
  if (!analytics_1.customDimensions)
220
246
  return;
221
- (0, analytics_1.reportEvent)('migrate_orchestrator_complete', {
222
- [analytics_1.customDimensions.appliedCount]: opts.completed,
223
- [analytics_1.customDimensions.taskCount]: opts.skipped,
224
- [analytics_1.customDimensions.migrationCount]: opts.dispenseCount,
247
+ (0, analytics_1.reportEvent)('migrate_orchestrator_complete', orchestratorTallyParams(opts));
248
+ });
249
+ }
250
+ /** The agent session nx spawned ended with the run still active. */
251
+ function reportMigrateOrchestratorAbandoned(opts) {
252
+ safeReport(() => {
253
+ if (!analytics_1.customDimensions)
254
+ return;
255
+ (0, analytics_1.reportEvent)('migrate_orchestrator_abandoned', {
256
+ ...orchestratorTallyParams(opts),
257
+ [analytics_1.customDimensions.agentUsed]: opts.agentUsed,
258
+ });
259
+ });
260
+ }
261
+ /**
262
+ * An explicit continue (`--run-migrations --run-id`, or "continue" at the
263
+ * master prompt) took up an active run; every resume reports. A bare
264
+ * `--run-id` reconcile is not a resume: nothing in run state marks the first
265
+ * call after a lost session.
266
+ */
267
+ function reportMigrateOrchestratorResume(opts) {
268
+ safeReport(() => {
269
+ if (!analytics_1.customDimensions)
270
+ return;
271
+ (0, analytics_1.reportEvent)('migrate_orchestrator_resume', orchestratorTallyParams(opts));
272
+ });
273
+ }
274
+ /**
275
+ * An invocation found an active run and started nothing. `activity` says
276
+ * whether another nx migrate process held the run; 'unknown' where nx cannot
277
+ * tell.
278
+ */
279
+ function reportMigrateOrchestratorExistingRun(opts) {
280
+ safeReport(() => {
281
+ if (!analytics_1.customDimensions)
282
+ return;
283
+ (0, analytics_1.reportEvent)('migrate_orchestrator_existing_run', {
284
+ ...orchestratorTallyParams(opts),
285
+ [analytics_1.customDimensions.promptChoice]: opts.activity,
225
286
  });
226
287
  });
227
288
  }
@@ -10,8 +10,11 @@ import { type MigrateArgs } from './command-object';
10
10
  * `parseMigrationsOptions`: `include` and `multiMajorMode` in the generate
11
11
  * phase only; `createCommits` / `commitPrefix` and `agentic` / `validate` when
12
12
  * running the whole migrations file or a standalone single migration. A
13
- * `--run-id` invocation takes none of them: a recorded run takes its commit
14
- * config from run.json and is driven by the outer agent.
13
+ * `--run-id` reconcile or recorded worker takes none of them: a recorded run
14
+ * takes its commit config from run.json and is driven by the outer agent. A
15
+ * `--run-migrations --run-id` continue takes `agentic` only, to select the
16
+ * agent of the new session. A `--start-fresh` starts a new run and takes all
17
+ * four.
15
18
  *
16
19
  * `include` is carried as `includeFromConfig` so it is never mistaken for an
17
20
  * explicit `--include`: `resolveInclude` applies it only when the resolved
@@ -15,8 +15,11 @@ const MULTI_MAJOR_MODE_ENV = 'NX_MULTI_MAJOR_MODE';
15
15
  * `parseMigrationsOptions`: `include` and `multiMajorMode` in the generate
16
16
  * phase only; `createCommits` / `commitPrefix` and `agentic` / `validate` when
17
17
  * running the whole migrations file or a standalone single migration. A
18
- * `--run-id` invocation takes none of them: a recorded run takes its commit
19
- * config from run.json and is driven by the outer agent.
18
+ * `--run-id` reconcile or recorded worker takes none of them: a recorded run
19
+ * takes its commit config from run.json and is driven by the outer agent. A
20
+ * `--run-migrations --run-id` continue takes `agentic` only, to select the
21
+ * agent of the new session. A `--start-fresh` starts a new run and takes all
22
+ * four.
20
23
  *
21
24
  * `include` is carried as `includeFromConfig` so it is never mistaken for an
22
25
  * explicit `--include`: `resolveInclude` applies it only when the resolved
@@ -33,11 +36,12 @@ function applyNxJsonMigrateDefaults(args, migrateConfig, env = process.env) {
33
36
  // A bare `--run-id` (orchestrated reconcile) must never take the
34
37
  // generate-options overlay, which would leak `include` etc. from nx.json.
35
38
  const isSingleMigration = merged.runMigration !== undefined || merged.runId !== undefined;
36
- // Both overlays are for an invocation that decides these options for
37
- // itself, which a `--run-id` invocation never does: the recorded worker and
38
- // the reconcile both read the commit config from run.json, and overlaying
39
- // `agentic` would trip the `--agentic`/`--run-id` parse conflict.
40
- if ((isRunMigrations || isSingleMigration) && merged.runId === undefined) {
39
+ // These overlays are for an invocation that decides the options for itself,
40
+ // which a `--run-id` invocation only does when it starts fresh: the recorded
41
+ // worker and the reconcile both read the commit config from run.json.
42
+ const startsRun = (isRunMigrations || isSingleMigration) &&
43
+ (merged.runId === undefined || merged.startFresh === true);
44
+ if (startsRun) {
41
45
  if (merged.createCommits === undefined &&
42
46
  migrateConfig.createCommits !== undefined) {
43
47
  assertType(migrateConfig.createCommits, 'boolean', 'createCommits');
@@ -52,15 +56,19 @@ function applyNxJsonMigrateDefaults(args, migrateConfig, env = process.env) {
52
56
  assertType(migrateConfig.commitPrefix, 'string', 'commitPrefix');
53
57
  merged.commitPrefix = migrateConfig.commitPrefix;
54
58
  }
55
- if (merged.agentic === undefined && migrateConfig.agentic !== undefined) {
56
- assertValidAgentic(migrateConfig.agentic);
57
- merged.agentic = (0, cli_args_1.coerceAgenticArg)(migrateConfig.agentic);
58
- }
59
59
  if (merged.validate === undefined && migrateConfig.validate !== undefined) {
60
60
  assertType(migrateConfig.validate, 'boolean', 'validate');
61
61
  merged.validate = migrateConfig.validate;
62
62
  }
63
63
  }
64
+ // A continue takes `agentic` too; the reconcile and the worker must not:
65
+ // there it trips the `--agentic`/`--run-id` parse conflict.
66
+ if ((startsRun || isRunMigrations) &&
67
+ merged.agentic === undefined &&
68
+ migrateConfig.agentic !== undefined) {
69
+ assertValidAgentic(migrateConfig.agentic);
70
+ merged.agentic = (0, cli_args_1.coerceAgenticArg)(migrateConfig.agentic);
71
+ }
64
72
  if (!isRunMigrations && !isSingleMigration) {
65
73
  if (merged.include === undefined && migrateConfig.include !== undefined) {
66
74
  assertOneOf(migrateConfig.include, command_object_1.MIGRATE_INCLUDE_VALUES, 'include');
@@ -171,6 +171,8 @@ type RunMigrations = {
171
171
  agentic: AgenticArg;
172
172
  validate?: boolean;
173
173
  interactive?: boolean;
174
+ runId?: string;
175
+ startFresh?: boolean;
174
176
  };
175
177
  type RunSingleMigration = {
176
178
  type: 'runSingleMigration';