nx 23.2.0-beta.4 → 23.2.0-beta.6

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 (120) hide show
  1. package/dist/bin/nx.js +1 -0
  2. package/dist/src/command-line/affected/affected.js +1 -0
  3. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
  4. package/dist/src/command-line/init/init-v2.js +2 -2
  5. package/dist/src/command-line/migrate/agentic/definitions.js +2 -2
  6. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +15 -19
  7. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +19 -31
  8. package/dist/src/command-line/migrate/agentic/handoff.d.ts +4 -6
  9. package/dist/src/command-line/migrate/agentic/handoff.js +9 -8
  10. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +7 -12
  11. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +7 -0
  12. package/dist/src/command-line/migrate/agentic/run-step.d.ts +10 -0
  13. package/dist/src/command-line/migrate/agentic/select.d.ts +10 -2
  14. package/dist/src/command-line/migrate/agentic/select.js +10 -2
  15. package/dist/src/command-line/migrate/agentic/types.d.ts +17 -3
  16. package/dist/src/command-line/migrate/agentic/types.js +26 -0
  17. package/dist/src/command-line/migrate/command-object.d.ts +3 -0
  18. package/dist/src/command-line/migrate/command-object.js +6 -1
  19. package/dist/src/command-line/migrate/execute-migration.d.ts +14 -9
  20. package/dist/src/command-line/migrate/execute-migration.js +82 -18
  21. package/dist/src/command-line/migrate/migrate-analytics.d.ts +7 -0
  22. package/dist/src/command-line/migrate/migrate-analytics.js +14 -0
  23. package/dist/src/command-line/migrate/migrate-commits.d.ts +32 -8
  24. package/dist/src/command-line/migrate/migrate-commits.js +77 -9
  25. package/dist/src/command-line/migrate/migrate-config.d.ts +11 -12
  26. package/dist/src/command-line/migrate/migrate-config.js +14 -14
  27. package/dist/src/command-line/migrate/migrate-output.d.ts +45 -7
  28. package/dist/src/command-line/migrate/migrate-output.js +52 -8
  29. package/dist/src/command-line/migrate/migrate-ui-api.d.ts +2 -1
  30. package/dist/src/command-line/migrate/migrate-ui-api.js +16 -7
  31. package/dist/src/command-line/migrate/migrate.d.ts +17 -68
  32. package/dist/src/command-line/migrate/migrate.js +411 -229
  33. package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
  34. package/dist/src/command-line/migrate/run/index.d.ts +2 -0
  35. package/dist/src/command-line/migrate/run/index.js +5 -0
  36. package/dist/src/command-line/migrate/run/util.d.ts +1 -0
  37. package/dist/src/command-line/migrate/run/util.js +16 -0
  38. package/dist/src/command-line/migrate/run/worker.d.ts +15 -0
  39. package/dist/src/command-line/migrate/run/worker.js +419 -0
  40. package/dist/src/command-line/migrate/run-migration-process.js +6 -5
  41. package/dist/src/command-line/migrate/sort-migrations.d.ts +16 -0
  42. package/dist/src/command-line/migrate/sort-migrations.js +32 -0
  43. package/dist/src/command-line/migrate/version-skew-guard.d.ts +58 -0
  44. package/dist/src/command-line/migrate/version-skew-guard.js +155 -0
  45. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.d.ts +2 -0
  46. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +16 -0
  47. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.d.ts +4 -0
  48. package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.js +13 -0
  49. package/dist/src/command-line/nx-commands.js +26 -24
  50. package/dist/src/command-line/release/changelog.js +5 -0
  51. package/dist/src/command-line/release/utils/git.js +1 -1
  52. package/dist/src/command-line/release/utils/release-graph.d.ts +1 -0
  53. package/dist/src/command-line/release/utils/release-graph.js +15 -3
  54. package/dist/src/command-line/release/version/version-actions.d.ts +8 -0
  55. package/dist/src/command-line/release/version/version-actions.js +8 -0
  56. package/dist/src/command-line/release/version.js +9 -5
  57. package/dist/src/command-line/reset/reset.js +6 -1
  58. package/dist/src/command-line/run/run-one.js +1 -0
  59. package/dist/src/command-line/run-many/run-many.js +1 -0
  60. package/dist/src/config/misc-interfaces.d.ts +19 -7
  61. package/dist/src/core/graph/main.js +1 -1
  62. package/dist/src/core/graph/styles.js +1 -1
  63. package/dist/src/daemon/client/client.d.ts +45 -1
  64. package/dist/src/daemon/client/client.js +128 -32
  65. package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
  66. package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
  67. package/dist/src/daemon/message-types/daemon-message.js +25 -0
  68. package/dist/src/daemon/server/latest-nx.js +5 -2
  69. package/dist/src/daemon/server/server.js +22 -0
  70. package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
  71. package/dist/src/daemon/server/shutdown-utils.js +11 -4
  72. package/dist/src/daemon/socket-utils.d.ts +1 -0
  73. package/dist/src/daemon/socket-utils.js +24 -3
  74. package/dist/src/daemon/tmp-dir.d.ts +43 -3
  75. package/dist/src/daemon/tmp-dir.js +437 -15
  76. package/dist/src/devkit-internals.d.ts +92 -3
  77. package/dist/src/devkit-internals.js +189 -5
  78. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +5 -0
  79. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +9 -2
  80. package/dist/src/generators/tree.d.ts +4 -2
  81. package/dist/src/native/index.d.ts +10 -0
  82. package/dist/src/native/index.js +71 -28
  83. package/dist/src/native/native-bindings.js +1 -0
  84. package/dist/src/native/native-file-cache-location.d.ts +17 -1
  85. package/dist/src/native/native-file-cache-location.js +86 -12
  86. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  87. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  88. package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
  89. package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
  90. package/dist/src/nx-cloud/utilities/url-shorten.d.ts +1 -4
  91. package/dist/src/nx-cloud/utilities/url-shorten.js +9 -8
  92. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +14 -8
  93. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +2 -0
  94. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
  95. package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
  96. package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
  97. package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
  98. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
  99. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
  100. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
  101. package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
  102. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
  103. package/dist/src/project-graph/project-graph.js +20 -0
  104. package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +12 -0
  105. package/dist/src/tasks-runner/life-cycles/performance-report.js +62 -3
  106. package/dist/src/tasks-runner/run-command.js +4 -0
  107. package/dist/src/utils/assert-workspace-validity.js +7 -2
  108. package/dist/src/utils/child-process.d.ts +31 -1
  109. package/dist/src/utils/child-process.js +103 -0
  110. package/dist/src/utils/ignore.d.ts +128 -1
  111. package/dist/src/utils/ignore.js +182 -12
  112. package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
  113. package/dist/src/utils/nx-tmp-dir.js +40 -0
  114. package/dist/src/utils/owned-private-dir.d.ts +132 -0
  115. package/dist/src/utils/owned-private-dir.js +323 -0
  116. package/dist/src/utils/shell-quoting.d.ts +15 -0
  117. package/dist/src/utils/shell-quoting.js +35 -0
  118. package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
  119. package/dist/src/utils/wait-for-socket-connection.js +14 -8
  120. package/package.json +12 -12
package/dist/bin/nx.js CHANGED
@@ -209,6 +209,7 @@ function resolveNx(workspace) {
209
209
  function isNxCloudCommand(command) {
210
210
  const nxCloudCommands = [
211
211
  'start-ci-run',
212
+ 'start-nx-agents',
212
213
  'start-agent',
213
214
  'stop-all-agents',
214
215
  'complete-ci-run',
@@ -49,6 +49,7 @@ async function affected(command, args, extraTargetDependencies = {}, extraOption
49
49
  }
50
50
  else {
51
51
  const status = await (0, run_command_1.runCommand)(projectsWithTarget, projectGraph, { nxJson }, nxArgs, overrides, null, extraTargetDependencies, extraOptions);
52
+ await output_1.output.drain();
52
53
  process.exit(status);
53
54
  }
54
55
  break;
@@ -11,7 +11,7 @@ const constants_1 = require("../../ai/constants");
11
11
  const detect_ai_agent_1 = require("../../ai/detect-ai-agent");
12
12
  const utils_1 = require("../../ai/utils");
13
13
  const client_1 = require("../../daemon/client/client");
14
- const devkit_internals_1 = require("../../devkit-internals");
14
+ const package_json_1 = require("../../utils/package-json");
15
15
  const output_1 = require("../../utils/output");
16
16
  const package_manager_1 = require("../../utils/package-manager");
17
17
  const provenance_1 = require("../../utils/provenance");
@@ -44,7 +44,7 @@ async function configureAiAgentsHandler(args, inner = false) {
44
44
  let cleanup;
45
45
  try {
46
46
  await (0, provenance_1.ensurePackageHasProvenance)('nx', 'latest');
47
- const packageInstallResults = (0, devkit_internals_1.installPackageToTmp)('nx', 'latest', (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot));
47
+ const packageInstallResults = (0, package_json_1.installPackageToTmp)('nx', 'latest', (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot));
48
48
  cleanup = packageInstallResults.cleanup;
49
49
  let modulePath = require.resolve('nx/src/command-line/configure-ai-agents/configure-ai-agents.js', { paths: [packageInstallResults.tempDir] });
50
50
  const module = await (0, handle_import_1.handleImport)(modulePath);
@@ -11,6 +11,7 @@ const nx_json_1 = require("../../config/nx-json");
11
11
  const fileutils_1 = require("../../utils/fileutils");
12
12
  const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
13
13
  const output_1 = require("../../utils/output");
14
+ const package_json_1 = require("../../utils/package-json");
14
15
  const package_manager_1 = require("../../utils/package-manager");
15
16
  const versions_1 = require("../../utils/versions");
16
17
  const workspace_context_1 = require("../../utils/workspace-context");
@@ -26,7 +27,6 @@ const angular_1 = require("./implementation/angular");
26
27
  const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
27
28
  const utils_1 = require("./implementation/utils");
28
29
  const provenance_1 = require("../../utils/provenance");
29
- const devkit_internals_1 = require("../../devkit-internals");
30
30
  const handle_import_1 = require("../../utils/handle-import");
31
31
  const native_1 = require("../../native");
32
32
  const detect_ai_agent_1 = require("../../ai/detect-ai-agent");
@@ -43,7 +43,7 @@ async function initHandler(options, inner = false) {
43
43
  let cleanup;
44
44
  try {
45
45
  await (0, provenance_1.ensurePackageHasProvenance)('nx', 'latest');
46
- const packageInstallResults = (0, devkit_internals_1.installPackageToTmp)('nx', 'latest', (0, package_manager_2.detectPackageManager)(process.cwd()));
46
+ const packageInstallResults = (0, package_json_1.installPackageToTmp)('nx', 'latest', (0, package_manager_2.detectPackageManager)(process.cwd()));
47
47
  cleanup = packageInstallResults.cleanup;
48
48
  let modulePath = require.resolve('nx/src/command-line/init/init-v2.js', {
49
49
  paths: [packageInstallResults.tempDir],
@@ -4,7 +4,7 @@ exports.AGENT_DEFINITIONS = exports.opencodeDefinition = exports.codexDefinition
4
4
  exports.getAgentDefinition = getAgentDefinition;
5
5
  const os_1 = require("os");
6
6
  const path_1 = require("path");
7
- const handoff_1 = require("./handoff");
7
+ const types_1 = require("./types");
8
8
  // --- Claude Code ---------------------------------------------------------
9
9
  function claudeCodeWellKnownPaths() {
10
10
  if (process.platform === 'win32') {
@@ -18,7 +18,7 @@ function claudeCodeWellKnownPaths() {
18
18
  // ends with an approval prompt for nx's own handoff scratch. Prefix-less
19
19
  // patterns resolve against the session cwd (pinned to the workspace root
20
20
  // below); `Edit` covers corrections to an already-written handoff.
21
- const CLAUDE_CODE_HANDOFF_ALLOWED_TOOLS = `Write(${handoff_1.MIGRATE_RUNS_RELATIVE_DIR}/**),Edit(${handoff_1.MIGRATE_RUNS_RELATIVE_DIR}/**)`;
21
+ const CLAUDE_CODE_HANDOFF_ALLOWED_TOOLS = `Write(${types_1.MIGRATE_RUNS_RELATIVE_DIR}/**),Edit(${types_1.MIGRATE_RUNS_RELATIVE_DIR}/**)`;
22
22
  function claudeCodeBuildInteractive(ctx) {
23
23
  return {
24
24
  // `--allowedTools` is variadic (space/comma separated): a positional
@@ -1,31 +1,27 @@
1
- export declare function isHandoffGitignoreMigration(m: {
2
- package: string;
3
- name: string;
4
- }): boolean;
5
1
  /**
6
2
  * Under `--agentic`, the runner writes per-run scratch under
7
3
  * `.nx/migrate-runs/<run-id>/`. The v23 migration
8
4
  * `23-0-0-add-migrate-runs-to-git-ignore` adds `.nx/migrate-runs` to
9
- * `.gitignore`; without intervention it would run in its declared slot
10
- * (typically late), so earlier per-migration commits would absorb the
11
- * scratch into the user-visible diff.
5
+ * `.gitignore`; in its declared slot (typically late) earlier per-migration
6
+ * commits would absorb the scratch into the user-visible diff.
12
7
  *
13
8
  * Two paths cover the leak, with no overlap:
14
9
  *
15
- * 1. HOIST handled by the sort comparator in `executeMigrations`. When
16
- * the v23 migration is in the queue, it sorts to position 0 and runs
17
- * first via the normal migration runner (with its own log line and
18
- * commit). Fully traceable in `git log`.
10
+ * 1. HOIST: `sortMigrations`, which `executeMigrations` applies, sorts the
11
+ * v23 migration to position 0 when it is in the queue, so it runs first
12
+ * through the normal runner with its own log line and commit. A
13
+ * single-migration worker run needs no hoisting: the requested migration
14
+ * is the entire queue.
19
15
  *
20
- * 2. INLINE FALLBACK this function. When the migration is NOT in the
21
- * queue AND the highest target version is < v23 (intra-pre-v23
22
- * `--agentic` run), the migration won't run at all. Apply its body
23
- * inline against an `FsTree` and commit it as a standalone preflight
24
- * commit (or leave in the working tree under `--no-create-commits`).
16
+ * 2. INLINE FALLBACK, this function. When the migration is NOT in the queue
17
+ * AND the highest target version is < v23 (intra-pre-v23 `--agentic`
18
+ * run) it will never run, so apply its body inline against an `FsTree`
19
+ * and commit it as a standalone preflight commit (or leave it in the
20
+ * working tree under `--no-create-commits`).
25
21
  *
26
- * When the migration is not in the queue AND target >= v23, the user is
27
- * past v23 already. They had the entry historically; if it's gone, that's
28
- * a conscious removal we respect.
22
+ * Not in the queue AND target >= v23 means the user is already past v23. They
23
+ * had the entry historically; if it is gone, that is a conscious removal we
24
+ * respect.
29
25
  */
30
26
  export declare function applyAgenticHandoffGitignoreFallback({ migrations, installedNxVersion, effectiveCreateCommits, commitPrefix, root, }: {
31
27
  migrations: ReadonlyArray<{
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHandoffGitignoreMigration = isHandoffGitignoreMigration;
4
3
  exports.applyAgenticHandoffGitignoreFallback = applyAgenticHandoffGitignoreFallback;
5
4
  const tslib_1 = require("tslib");
6
5
  const semver_1 = require("semver");
@@ -9,47 +8,36 @@ const add_migrate_runs_to_git_ignore_1 = tslib_1.__importDefault(require("../../
9
8
  const tree_1 = require("../../../generators/tree");
10
9
  const git_utils_1 = require("../../../utils/git-utils");
11
10
  const logger_1 = require("../../../utils/logger");
12
- /**
13
- * Composite identity of the v23 migration that adds `.nx/migrate-runs` to
14
- * `.gitignore`. Hard-coded because the agentic preflight is a deliberate
15
- * one-off coupling: this exact migration owns the entry that keeps
16
- * `.nx/migrate-runs/<run-id>/...` scratch out of per-migration commits. If
17
- * the migration is ever renamed, this entry must move with it.
18
- */
19
- const HANDOFF_GITIGNORE_MIGRATION_PACKAGE = 'nx';
20
- const HANDOFF_GITIGNORE_MIGRATION_NAME = '23-0-0-add-migrate-runs-to-git-ignore';
21
- function isHandoffGitignoreMigration(m) {
22
- return (m.package === HANDOFF_GITIGNORE_MIGRATION_PACKAGE &&
23
- m.name === HANDOFF_GITIGNORE_MIGRATION_NAME);
24
- }
11
+ const types_1 = require("./types");
25
12
  /**
26
13
  * Under `--agentic`, the runner writes per-run scratch under
27
14
  * `.nx/migrate-runs/<run-id>/`. The v23 migration
28
15
  * `23-0-0-add-migrate-runs-to-git-ignore` adds `.nx/migrate-runs` to
29
- * `.gitignore`; without intervention it would run in its declared slot
30
- * (typically late), so earlier per-migration commits would absorb the
31
- * scratch into the user-visible diff.
16
+ * `.gitignore`; in its declared slot (typically late) earlier per-migration
17
+ * commits would absorb the scratch into the user-visible diff.
32
18
  *
33
19
  * Two paths cover the leak, with no overlap:
34
20
  *
35
- * 1. HOIST handled by the sort comparator in `executeMigrations`. When
36
- * the v23 migration is in the queue, it sorts to position 0 and runs
37
- * first via the normal migration runner (with its own log line and
38
- * commit). Fully traceable in `git log`.
21
+ * 1. HOIST: `sortMigrations`, which `executeMigrations` applies, sorts the
22
+ * v23 migration to position 0 when it is in the queue, so it runs first
23
+ * through the normal runner with its own log line and commit. A
24
+ * single-migration worker run needs no hoisting: the requested migration
25
+ * is the entire queue.
39
26
  *
40
- * 2. INLINE FALLBACK this function. When the migration is NOT in the
41
- * queue AND the highest target version is < v23 (intra-pre-v23
42
- * `--agentic` run), the migration won't run at all. Apply its body
43
- * inline against an `FsTree` and commit it as a standalone preflight
44
- * commit (or leave in the working tree under `--no-create-commits`).
27
+ * 2. INLINE FALLBACK, this function. When the migration is NOT in the queue
28
+ * AND the highest target version is < v23 (intra-pre-v23 `--agentic`
29
+ * run) it will never run, so apply its body inline against an `FsTree`
30
+ * and commit it as a standalone preflight commit (or leave it in the
31
+ * working tree under `--no-create-commits`).
45
32
  *
46
- * When the migration is not in the queue AND target >= v23, the user is
47
- * past v23 already. They had the entry historically; if it's gone, that's
48
- * a conscious removal we respect.
33
+ * Not in the queue AND target >= v23 means the user is already past v23. They
34
+ * had the entry historically; if it is gone, that is a conscious removal we
35
+ * respect.
49
36
  */
50
37
  async function applyAgenticHandoffGitignoreFallback({ migrations, installedNxVersion, effectiveCreateCommits, commitPrefix, root, }) {
51
- if (migrations.some(isHandoffGitignoreMigration)) {
52
- // The hoist path handles this via the sort comparator.
38
+ if (migrations.some(types_1.isHandoffGitignoreMigration)) {
39
+ // The queue runs it itself: hoisted to the front by the sort comparator
40
+ // in a full run, or as the single requested migration in a worker run.
53
41
  return;
54
42
  }
55
43
  if ((0, semver_1.major)(installedNxVersion) >= 23) {
@@ -1,12 +1,10 @@
1
1
  import { HandoffFile } from './types';
2
- /**
3
- * Workspace-relative directory holding all migrate-run scratch (handoff
4
- * files). Shared with the agent permission rules in `definitions.ts` so the
5
- * pre-authorized write scope can't drift from the actual layout.
6
- */
7
- export declare const MIGRATE_RUNS_RELATIVE_DIR = ".nx/migrate-runs";
8
2
  /** Returns the run directory for a given workspace + run id (target version). */
9
3
  export declare function runDirPath(workspaceRoot: string, runId: string): string;
4
+ /** The version-derived run id: the highest target version in the plan. */
5
+ export declare function resolveAgenticRunId(migrations: ReadonlyArray<{
6
+ version: string;
7
+ }>): string;
10
8
  /**
11
9
  * `mkdir -p` with a contextual error wrapper. Without this, the raw
12
10
  * ENOSPC/EACCES/EROFS surfaces with no indication of which directory the
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MIGRATE_RUNS_RELATIVE_DIR = void 0;
4
3
  exports.runDirPath = runDirPath;
4
+ exports.resolveAgenticRunId = resolveAgenticRunId;
5
5
  exports.mkdirSafely = mkdirSafely;
6
6
  exports.initRunDir = initRunDir;
7
7
  exports.stepHandoffPath = stepHandoffPath;
@@ -10,15 +10,16 @@ exports.readHandoff = readHandoff;
10
10
  exports.waitForValidHandoff = waitForValidHandoff;
11
11
  const fs_1 = require("fs");
12
12
  const path_1 = require("path");
13
- /**
14
- * Workspace-relative directory holding all migrate-run scratch (handoff
15
- * files). Shared with the agent permission rules in `definitions.ts` so the
16
- * pre-authorized write scope can't drift from the actual layout.
17
- */
18
- exports.MIGRATE_RUNS_RELATIVE_DIR = '.nx/migrate-runs';
13
+ const semver_1 = require("semver");
14
+ const version_utils_1 = require("../version-utils");
15
+ const types_1 = require("./types");
19
16
  /** Returns the run directory for a given workspace + run id (target version). */
20
17
  function runDirPath(workspaceRoot, runId) {
21
- return (0, path_1.join)(workspaceRoot, exports.MIGRATE_RUNS_RELATIVE_DIR, runId);
18
+ return (0, path_1.join)(workspaceRoot, types_1.MIGRATE_RUNS_RELATIVE_DIR, runId);
19
+ }
20
+ /** The version-derived run id: the highest target version in the plan. */
21
+ function resolveAgenticRunId(migrations) {
22
+ return (0, semver_1.rsort)(migrations.map((m) => (0, version_utils_1.normalizeVersion)(m.version)))[0];
22
23
  }
23
24
  /**
24
25
  * `mkdir -p` with a contextual error wrapper. Without this, the raw
@@ -1,15 +1,3 @@
1
- /**
2
- * Surfaces a migration's `agentContext` to stdout in an XML-tagged block so an
3
- * outer AI agent driving `nx migrate` can ingest the hints when no inner agent
4
- * step ran to consume them.
5
- *
6
- * Used only when `agentic.kind === 'inside-agent'`. Under `enabled`, the inner
7
- * step consumes `agentContext` via the prompt builders. Under `disabled` the
8
- * run is human-driven and printing agent-targeted context would only add noise.
9
- *
10
- * The label format is unambiguous so the outer agent can locate the block
11
- * within the mixed stdout stream (logger output, migration progress, etc.).
12
- */
13
1
  export interface DroppedAgentContextInput {
14
2
  migration: {
15
3
  package: string;
@@ -19,4 +7,11 @@ export interface DroppedAgentContextInput {
19
7
  agentContext: string[];
20
8
  }
21
9
  export declare function formatDroppedAgentContextForOuterAgent(input: DroppedAgentContextInput): string;
10
+ export declare function escapeXmlAttr(value: string): string;
11
+ /**
12
+ * Both the classic loop and the single-migration worker call this only under
13
+ * `agentic.kind === 'inside-agent'`. Under `enabled` the inner agent step
14
+ * consumes `agentContext` through the prompt builders; under `disabled` the
15
+ * run is human-driven and agent-targeted context is only noise.
16
+ */
22
17
  export declare function printDroppedAgentContextForOuterAgent(input: DroppedAgentContextInput): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatDroppedAgentContextForOuterAgent = formatDroppedAgentContextForOuterAgent;
4
+ exports.escapeXmlAttr = escapeXmlAttr;
4
5
  exports.printDroppedAgentContextForOuterAgent = printDroppedAgentContextForOuterAgent;
5
6
  const shared_rendering_1 = require("./prompts/shared-rendering");
6
7
  function formatDroppedAgentContextForOuterAgent(input) {
@@ -40,6 +41,12 @@ function escapeXmlAttr(value) {
40
41
  .replace(/"/g, '&quot;')
41
42
  .replace(/'/g, '&apos;');
42
43
  }
44
+ /**
45
+ * Both the classic loop and the single-migration worker call this only under
46
+ * `agentic.kind === 'inside-agent'`. Under `enabled` the inner agent step
47
+ * consumes `agentContext` through the prompt builders; under `disabled` the
48
+ * run is human-driven and agent-targeted context is only noise.
49
+ */
43
50
  function printDroppedAgentContextForOuterAgent(input) {
44
51
  const block = formatDroppedAgentContextForOuterAgent(input);
45
52
  if (block) {
@@ -22,6 +22,16 @@ export interface AgenticStepResult {
22
22
  */
23
23
  ambiguous: boolean;
24
24
  }
25
+ /**
26
+ * `runStep` travels in the context rather than being imported by its call
27
+ * sites, so this module loads only where the context is built, behind an
28
+ * agentic-enabled gate.
29
+ */
30
+ export interface AgenticRunContext {
31
+ agentic: EnabledResolvedAgentic;
32
+ runDir: string;
33
+ runStep: typeof runAgenticPromptStep;
34
+ }
25
35
  export interface RunAgenticPromptStepInput {
26
36
  root: string;
27
37
  migration: {
@@ -10,7 +10,15 @@ export interface ResolveAgenticInput {
10
10
  interactive?: boolean;
11
11
  }
12
12
  /**
13
- * Resolves the agentic state for a `--run-migrations` invocation. Runs once,
14
- * before the migration loop, and its result is cached for every entry.
13
+ * Callers resolve this once per run-phase invocation and reuse the result for
14
+ * every migration it covers.
15
15
  */
16
16
  export declare function resolveAgentic(input: ResolveAgenticInput): Promise<ResolvedAgentic>;
17
+ /**
18
+ * No warning when `--validate` is passed with the agentic flow off: validation
19
+ * requires an active agent session by definition.
20
+ */
21
+ export declare function resolveShouldRunValidation(args: {
22
+ validate: boolean | undefined;
23
+ agenticKind: ResolvedAgentic['kind'];
24
+ }): boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveAgentic = resolveAgentic;
4
+ exports.resolveShouldRunValidation = resolveShouldRunValidation;
4
5
  const tslib_1 = require("tslib");
5
6
  const fs_1 = require("fs");
6
7
  const jsonc_parser_1 = require("jsonc-parser");
@@ -18,8 +19,8 @@ const INSTALL_SUPPORTED_AGENTS_HINT = [
18
19
  ...definitions_1.AGENT_DEFINITIONS.map((def) => ` - ${def.displayName}`),
19
20
  ];
20
21
  /**
21
- * Resolves the agentic state for a `--run-migrations` invocation. Runs once,
22
- * before the migration loop, and its result is cached for every entry.
22
+ * Callers resolve this once per run-phase invocation and reuse the result for
23
+ * every migration it covers.
23
24
  */
24
25
  async function resolveAgentic(input) {
25
26
  if ((0, inception_1.isInsideAgent)()) {
@@ -57,6 +58,13 @@ async function resolveAgentic(input) {
57
58
  }
58
59
  return { kind: 'enabled', selectedAgent: selected };
59
60
  }
61
+ /**
62
+ * No warning when `--validate` is passed with the agentic flow off: validation
63
+ * requires an active agent session by definition.
64
+ */
65
+ function resolveShouldRunValidation(args) {
66
+ return args.validate !== false && args.agenticKind === 'enabled';
67
+ }
60
68
  async function resolveFlag(input, isInteractive, detected) {
61
69
  if (input.agentic === true) {
62
70
  if (!isInteractive) {
@@ -1,5 +1,18 @@
1
1
  import type { AgentId } from './cli-args';
2
2
  export type { AgentId };
3
+ /**
4
+ * Workspace-relative directory holding all migrate-run scratch (handoff
5
+ * files). Shared by the run-dir layout in `handoff.ts` and the agent
6
+ * permission rules in `definitions.ts` so the pre-authorized write scope
7
+ * can't drift from the actual layout. It lives here so `definitions.ts`,
8
+ * loaded whenever the agentic flow is resolved, doesn't pull in the handoff
9
+ * runtime for the path alone.
10
+ */
11
+ export declare const MIGRATE_RUNS_RELATIVE_DIR = ".nx/migrate-runs";
12
+ export declare function isHandoffGitignoreMigration(m: {
13
+ package: string;
14
+ name: string;
15
+ }): boolean;
3
16
  /**
4
17
  * A coding agent that was found on the user's machine, ready to be spawned.
5
18
  *
@@ -78,11 +91,12 @@ export type HandoffOutcome = {
78
91
  causeSummary?: string[];
79
92
  };
80
93
  /**
81
- * Result of the up-front resolution phase that runs once per `--run-migrations`
82
- * invocation, before the migration loop. Cached and consulted for every entry.
94
+ * Result of the up-front resolution phase, run once per run-phase invocation
95
+ * and applied to every migration it covers.
83
96
  *
84
97
  * - `inside-agent`: nx detected it is itself running inside another agent;
85
- * every agentic step is skipped and prompt migrations go to `nextSteps`.
98
+ * every agentic step is skipped and prompt migrations are surfaced for the
99
+ * outer agent to apply.
86
100
  * - `disabled`: the user opted out (explicit `--agentic=false`, declined the
87
101
  * up-front prompt, or non-TTY without the flag).
88
102
  * - `enabled`: the agentic flow runs and `selectedAgent` is the agent it
@@ -1,2 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIGRATE_RUNS_RELATIVE_DIR = void 0;
4
+ exports.isHandoffGitignoreMigration = isHandoffGitignoreMigration;
5
+ /**
6
+ * Workspace-relative directory holding all migrate-run scratch (handoff
7
+ * files). Shared by the run-dir layout in `handoff.ts` and the agent
8
+ * permission rules in `definitions.ts` so the pre-authorized write scope
9
+ * can't drift from the actual layout. It lives here so `definitions.ts`,
10
+ * loaded whenever the agentic flow is resolved, doesn't pull in the handoff
11
+ * runtime for the path alone.
12
+ */
13
+ exports.MIGRATE_RUNS_RELATIVE_DIR = '.nx/migrate-runs';
14
+ /**
15
+ * Composite identity of the v23 migration that adds `.nx/migrate-runs` to
16
+ * `.gitignore`. Hard-coded because the agentic preflight is a deliberate
17
+ * one-off coupling: this exact migration owns the entry that keeps
18
+ * `.nx/migrate-runs/<run-id>/...` scratch out of per-migration commits. If
19
+ * the migration is ever renamed, this entry must move with it. It lives here
20
+ * rather than in `handoff-gitignore.ts` so `sortMigrations`' hoist check
21
+ * doesn't load that module's migration-execution machinery.
22
+ */
23
+ const HANDOFF_GITIGNORE_MIGRATION_PACKAGE = 'nx';
24
+ const HANDOFF_GITIGNORE_MIGRATION_NAME = '23-0-0-add-migrate-runs-to-git-ignore';
25
+ function isHandoffGitignoreMigration(m) {
26
+ return (m.package === HANDOFF_GITIGNORE_MIGRATION_PACKAGE &&
27
+ m.name === HANDOFF_GITIGNORE_MIGRATION_NAME);
28
+ }
@@ -17,6 +17,7 @@ export type MultiMajorMode = (typeof MULTI_MAJOR_MODES)[number];
17
17
  export interface MigrateArgs {
18
18
  packageAndVersion?: string;
19
19
  runMigrations?: string;
20
+ runMigration?: string;
20
21
  include?: MigrateInclude;
21
22
  /**
22
23
  * nx.json `migrate.include` default. Consumed by `resolveInclude` only when the
@@ -30,6 +31,8 @@ export interface MigrateArgs {
30
31
  commitPrefix?: string;
31
32
  agentic?: AgenticArg;
32
33
  validate?: boolean;
34
+ ifExists?: boolean;
35
+ interactive?: boolean;
33
36
  [key: string]: any;
34
37
  }
35
38
  /**
@@ -10,7 +10,8 @@ exports.yargsMigrateCommand = {
10
10
  command: 'migrate [packageAndVersion]',
11
11
  describe: `Creates a migrations file or runs migrations from the migrations file.
12
12
  - Migrate packages and create migrations.json (e.g., nx migrate @nx/workspace@latest)
13
- - Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.`,
13
+ - Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.
14
+ - Run a single migration from migrations.json by id (e.g., nx migrate --run-migration=@nx/js:my-migration).`,
14
15
  builder: (yargs) => (0, documentation_1.linkToNxDevAndExamples)(withMigrationOptions(yargs), 'migrate'),
15
16
  handler: async () => process.exit(await (await (0, handle_import_1.handleImport)('./migrate.js', __dirname)).runMigration()),
16
17
  };
@@ -51,6 +52,10 @@ function withMigrationOptions(yargs) {
51
52
  .option('runMigrations', {
52
53
  describe: `Execute migrations from a file (when the file isn't provided, execute migrations from migrations.json).`,
53
54
  type: 'string',
55
+ })
56
+ .option('runMigration', {
57
+ describe: "Run a single migration from migrations.json by id. The id is '<package>:<name>'; a bare '<name>' is accepted when it matches exactly one migration. A name that contains ':' must use the full '<package>:<name>' form.",
58
+ type: 'string',
54
59
  })
55
60
  .option('ifExists', {
56
61
  describe: `Run migrations only if the migrations file exists, if not continues successfully.`,
@@ -6,7 +6,7 @@ interface PackageMigrationConfig extends NxMigrationsConfiguration {
6
6
  packageGroup: ArrayPackageGroup;
7
7
  }
8
8
  export declare function readPackageMigrationConfig(packageName: string, dir: string): PackageMigrationConfig;
9
- export declare function runInstall(nxWorkspaceRoot?: string, phase?: MigrationInstallPhase): Promise<void>;
9
+ export declare function runInstall(nxWorkspaceRoot?: string, phase?: MigrationInstallPhase, rerunCommand?: string): Promise<void>;
10
10
  export type MigrationInstallPhase = 'pre-migration' | 'post-migration';
11
11
  export declare class NpmPeerDepsInstallError extends Error {
12
12
  constructor();
@@ -19,13 +19,16 @@ export declare class NpmPeerDepsInstallError extends Error {
19
19
  * captured output.
20
20
  */
21
21
  export declare function isNpmPeerDepsError(stderr: string): boolean;
22
- export declare function logNpmPeerDepsError(phase: MigrationInstallPhase): void;
22
+ export declare function formatSingleMigrationRerunCommand(migrationId: string): string;
23
+ export declare function logNpmPeerDepsError(phase: MigrationInstallPhase, rerunCommand?: string): void;
24
+ export declare function logSkippedPostMigrationInstall(root: string): void;
23
25
  export declare class ChangedDepInstaller {
24
26
  private readonly root;
25
27
  private readonly shouldSkipInstall;
28
+ private readonly rerunCommand?;
26
29
  private initialDeps;
27
30
  private _skippedInstall;
28
- constructor(root: string, shouldSkipInstall?: boolean);
31
+ constructor(root: string, shouldSkipInstall?: boolean, rerunCommand?: string);
29
32
  get skippedInstall(): boolean;
30
33
  installDepsIfChanged(): Promise<void>;
31
34
  }
@@ -34,13 +37,11 @@ export declare function runNxOrAngularMigration(root: string, migration: {
34
37
  name: string;
35
38
  description?: string;
36
39
  version: string;
37
- }, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: {
38
- collection: MigrationsJson;
39
- collectionPath: string;
40
- }): Promise<{
40
+ }, isVerbose: boolean, captureGeneratorOutput?: boolean, resolvedCollection?: ResolvedMigrationCollection): Promise<{
41
41
  changes: FileChange[];
42
42
  nextSteps: string[];
43
43
  agentContext: string[];
44
+ skipAgentic: boolean;
44
45
  logs: string;
45
46
  madeChanges: boolean;
46
47
  }>;
@@ -49,17 +50,21 @@ export declare function runNxMigration(root: string, collectionPath: string, col
49
50
  changes: FileChange[];
50
51
  nextSteps: string[];
51
52
  agentContext: string[];
53
+ skipAgentic: boolean;
52
54
  logs: string;
53
55
  }>;
54
56
  export declare function parseMigrationReturn(value: unknown): {
55
57
  nextSteps: string[];
56
58
  agentContext: string[];
59
+ skipAgentic: boolean;
57
60
  };
58
61
  export declare function filterStrings(value: unknown): string[];
59
- export declare function readMigrationCollection(packageName: string, root: string): {
62
+ export interface ResolvedMigrationCollection {
60
63
  collection: MigrationsJson;
61
64
  collectionPath: string;
62
- };
65
+ }
66
+ export declare function readMigrationCollection(packageName: string, root: string): ResolvedMigrationCollection;
67
+ export declare function resolveDocumentationFileToWorkspacePath(root: string, migrationsDir: string, documentation: string): string | undefined;
63
68
  export declare function getImplementationPath(collection: MigrationsJson, collectionPath: string, name: string, migrationVersion?: string): {
64
69
  path: string;
65
70
  fnSymbol: string;