@ohos-ports/nx 23.3.0-beta.2 → 24.0.2-beta.0

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 (294) hide show
  1. package/README.md +3 -6
  2. package/dist/bin/nx.js +2 -2
  3. package/dist/bin/post-install.js +5 -3
  4. package/dist/nx-cloud-internals.d.ts +1 -0
  5. package/dist/nx-cloud-internals.js +7 -1
  6. package/dist/src/adapter/ngcli-adapter.js +2 -2
  7. package/dist/src/ai/clone-ai-config-repo.js +49 -12
  8. package/dist/src/command-line/add/add.d.ts +2 -0
  9. package/dist/src/command-line/add/add.js +23 -5
  10. package/dist/src/command-line/affected/affected.js +2 -2
  11. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +0 -12
  12. package/dist/src/command-line/graph/graph.js +38 -10
  13. package/dist/src/command-line/init/command-object.js +0 -12
  14. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +21 -62
  15. package/dist/src/command-line/init/init-v2.js +0 -2
  16. package/dist/src/command-line/migrate/agentic/close-agent-session.d.ts +1 -1
  17. package/dist/src/command-line/migrate/agentic/close-agent-session.js +4 -3
  18. package/dist/src/command-line/migrate/agentic/definitions.d.ts +1 -3
  19. package/dist/src/command-line/migrate/agentic/definitions.js +5 -97
  20. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +7 -45
  21. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +9 -51
  22. package/dist/src/command-line/migrate/agentic/handoff.d.ts +1 -43
  23. package/dist/src/command-line/migrate/agentic/handoff.js +3 -119
  24. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +0 -21
  25. package/dist/src/command-line/migrate/agentic/instruction-files.js +6 -27
  26. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +19 -1
  27. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +88 -49
  28. package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +1 -0
  29. package/dist/src/command-line/migrate/agentic/master/spawn-master.js +86 -24
  30. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +2 -2
  31. package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +2 -2
  32. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +1 -12
  33. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +8 -17
  34. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.d.ts +0 -15
  35. package/dist/src/command-line/migrate/agentic/prompts/shared-rendering.js +3 -100
  36. package/dist/src/command-line/migrate/agentic/select.d.ts +12 -6
  37. package/dist/src/command-line/migrate/agentic/select.js +38 -8
  38. package/dist/src/command-line/migrate/agentic/types.d.ts +9 -68
  39. package/dist/src/command-line/migrate/agentic/types.js +6 -8
  40. package/dist/src/command-line/migrate/command-object.js +6 -10
  41. package/dist/src/command-line/migrate/execute-migration.d.ts +6 -6
  42. package/dist/src/command-line/migrate/execute-migration.js +25 -15
  43. package/dist/src/command-line/migrate/migrate-analytics.d.ts +18 -1
  44. package/dist/src/command-line/migrate/migrate-analytics.js +38 -0
  45. package/dist/src/command-line/migrate/migrate-commits.d.ts +29 -17
  46. package/dist/src/command-line/migrate/migrate-commits.js +86 -32
  47. package/dist/src/command-line/migrate/migrate-config.d.ts +6 -6
  48. package/dist/src/command-line/migrate/migrate-config.js +12 -6
  49. package/dist/src/command-line/migrate/migrate-output.d.ts +1 -6
  50. package/dist/src/command-line/migrate/migrate-output.js +1 -10
  51. package/dist/src/command-line/migrate/migrate.d.ts +6 -30
  52. package/dist/src/command-line/migrate/migrate.js +257 -255
  53. package/dist/src/command-line/migrate/resolve-package-version.d.ts +2 -4
  54. package/dist/src/command-line/migrate/resolve-package-version.js +2 -35
  55. package/dist/src/command-line/migrate/run/agent-output.d.ts +2 -0
  56. package/dist/src/command-line/migrate/run/agent-output.js +9 -0
  57. package/dist/src/command-line/migrate/run/broker.d.ts +14 -5
  58. package/dist/src/command-line/migrate/run/broker.js +69 -21
  59. package/dist/src/command-line/migrate/run/clean-retry.js +4 -2
  60. package/dist/src/command-line/migrate/run/existing-run-report.d.ts +1 -1
  61. package/dist/src/command-line/migrate/run/existing-run-report.js +7 -5
  62. package/dist/src/command-line/migrate/run/give-up.d.ts +4 -3
  63. package/dist/src/command-line/migrate/run/give-up.js +8 -5
  64. package/dist/src/command-line/migrate/run/index.d.ts +7 -5
  65. package/dist/src/command-line/migrate/run/index.js +16 -1
  66. package/dist/src/command-line/migrate/run/issues.js +7 -2
  67. package/dist/src/command-line/migrate/run/orchestrator.d.ts +61 -4
  68. package/dist/src/command-line/migrate/run/orchestrator.js +397 -133
  69. package/dist/src/command-line/migrate/run/run-state.d.ts +17 -1
  70. package/dist/src/command-line/migrate/run/run-state.js +41 -2
  71. package/dist/src/command-line/migrate/run/runbook.d.ts +1 -0
  72. package/dist/src/command-line/migrate/run/runbook.js +115 -18
  73. package/dist/src/command-line/migrate/run/state-lock.d.ts +29 -4
  74. package/dist/src/command-line/migrate/run/state-lock.js +102 -10
  75. package/dist/src/command-line/migrate/run/state-machine.js +4 -1
  76. package/dist/src/command-line/migrate/run/util.d.ts +7 -2
  77. package/dist/src/command-line/migrate/run/util.js +30 -3
  78. package/dist/src/command-line/migrate/run/worker.d.ts +1 -1
  79. package/dist/src/command-line/migrate/run/worker.js +252 -250
  80. package/dist/src/command-line/migrate/sort-migrations.d.ts +1 -7
  81. package/dist/src/command-line/migrate/sort-migrations.js +1 -12
  82. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +17 -12
  83. package/dist/src/command-line/release/changelog.js +9 -6
  84. package/dist/src/command-line/release/config/config.d.ts +1 -0
  85. package/dist/src/command-line/release/config/config.js +48 -9
  86. package/dist/src/command-line/release/release.js +2 -2
  87. package/dist/src/command-line/release/utils/git.js +8 -7
  88. package/dist/src/command-line/release/utils/interpolate-release-config.d.ts +6 -0
  89. package/dist/src/command-line/release/utils/interpolate-release-config.js +39 -0
  90. package/dist/src/command-line/release/utils/release-graph.d.ts +5 -0
  91. package/dist/src/command-line/release/utils/release-graph.js +1 -0
  92. package/dist/src/command-line/release/utils/remote-release-clients/github.js +5 -6
  93. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +5 -6
  94. package/dist/src/command-line/release/utils/resolve-changelog-renderer.js +2 -2
  95. package/dist/src/command-line/release/utils/shared.js +10 -10
  96. package/dist/src/command-line/release/utils/version-plan-utils.d.ts +3 -12
  97. package/dist/src/command-line/release/utils/version-plan-utils.js +33 -55
  98. package/dist/src/command-line/release/version/version-actions.js +2 -1
  99. package/dist/src/command-line/release/version.js +5 -2
  100. package/dist/src/command-line/reset/reset.js +58 -62
  101. package/dist/src/command-line/run/executor-utils.js +1 -0
  102. package/dist/src/command-line/run/run-one.d.ts +20 -1
  103. package/dist/src/command-line/run/run-one.js +153 -5
  104. package/dist/src/command-line/run/run.js +2 -1
  105. package/dist/src/command-line/show/projects.js +5 -3
  106. package/dist/src/command-line/show/show-target/info.d.ts +10 -1
  107. package/dist/src/command-line/show/show-target/info.js +100 -15
  108. package/dist/src/command-line/show/show-target/inputs.js +10 -2
  109. package/dist/src/command-line/show/show-target/utils.js +1 -0
  110. package/dist/src/command-line/watch/command-object.js +3 -22
  111. package/dist/src/command-line/watch/watch.d.ts +0 -7
  112. package/dist/src/command-line/watch/watch.js +1 -1
  113. package/dist/src/command-line/yargs-utils/shared-options.js +1 -1
  114. package/dist/src/config/misc-interfaces.d.ts +18 -0
  115. package/dist/src/config/nx-json.d.ts +22 -11
  116. package/dist/src/config/task-graph.d.ts +1 -1
  117. package/dist/src/config/workspace-json-project-json.d.ts +88 -0
  118. package/dist/src/core/graph/main.js +1 -1
  119. package/dist/src/core/graph/runtime.js +1 -1
  120. package/dist/src/core/graph/styles.css +1 -1
  121. package/dist/src/core/graph/styles.js +1 -1
  122. package/dist/src/daemon/client/client.d.ts +15 -0
  123. package/dist/src/daemon/client/client.js +181 -71
  124. package/dist/src/daemon/client/daemon-socket-messenger.d.ts +1 -1
  125. package/dist/src/daemon/client/daemon-socket-messenger.js +2 -2
  126. package/dist/src/daemon/server/client-socket-context.js +1 -1
  127. package/dist/src/daemon/server/handle-process-in-background.js +21 -9
  128. package/dist/src/daemon/server/handle-select-affected-tasks.d.ts +2 -1
  129. package/dist/src/daemon/server/handle-select-affected-tasks.js +21 -13
  130. package/dist/src/daemon/server/native-js-loader.d.ts +1 -0
  131. package/dist/src/daemon/server/native-js-loader.js +21 -0
  132. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +4 -8
  133. package/dist/src/daemon/server/server.d.ts +2 -1
  134. package/dist/src/daemon/server/server.js +17 -4
  135. package/dist/src/daemon/server/shutdown-utils.js +0 -3
  136. package/dist/src/daemon/server/start.d.ts +1 -0
  137. package/dist/src/daemon/server/start.js +2 -0
  138. package/dist/src/daemon/socket-utils.d.ts +11 -9
  139. package/dist/src/daemon/socket-utils.js +31 -61
  140. package/dist/src/daemon/tmp-dir.d.ts +19 -14
  141. package/dist/src/daemon/tmp-dir.js +142 -354
  142. package/dist/src/devkit-exports.d.ts +9 -1
  143. package/dist/src/devkit-exports.js +12 -1
  144. package/dist/src/devkit-internals.d.ts +6 -5
  145. package/dist/src/devkit-internals.js +13 -4
  146. package/dist/src/executors/run-commands/run-commands.impl.d.ts +4 -2
  147. package/dist/src/executors/run-commands/run-commands.impl.js +53 -27
  148. package/dist/src/executors/run-commands/running-tasks.d.ts +13 -4
  149. package/dist/src/executors/run-commands/running-tasks.js +148 -95
  150. package/dist/src/executors/run-commands/schema.json +1 -1
  151. package/dist/src/hasher/check-task-files.js +5 -8
  152. package/dist/src/hasher/file-hasher.js +9 -7
  153. package/dist/src/hasher/hash-task.js +4 -0
  154. package/dist/src/hasher/native-task-hasher-impl.js +3 -1
  155. package/dist/src/hasher/task-hasher.d.ts +2 -0
  156. package/dist/src/hasher/task-hasher.js +4 -1
  157. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +1 -2
  158. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +6 -11
  159. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +2 -2
  160. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.d.ts +4 -0
  161. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.js +15 -0
  162. package/dist/src/migrations/update-24-0-0/enable-legacy-affected.md +30 -0
  163. package/dist/src/migrations/update-24-0-0/find-custom-hashers.d.ts +3 -0
  164. package/dist/src/migrations/update-24-0-0/find-custom-hashers.js +100 -0
  165. package/dist/src/migrations/update-24-0-0/find-custom-hashers.md +63 -0
  166. package/dist/src/migrations/update-24-0-0/move-custom-hashers-to-inputs.md +146 -0
  167. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.d.ts +3 -0
  168. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.js +130 -0
  169. package/dist/src/migrations/update-24-0-0/rename-ultracache-ignore-options.md +62 -0
  170. package/dist/src/native/assert-supported-platform.js +1 -1
  171. package/dist/src/native/index.d.ts +238 -18
  172. package/dist/src/native/index.js +6 -1
  173. package/dist/src/native/native-bindings.js +15 -6
  174. package/dist/src/native/nx.openharmony-arm64.node +0 -0
  175. package/dist/src/native/nx.wasi-browser.js +1 -0
  176. package/dist/src/native/nx.wasi.cjs +1 -0
  177. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  178. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  179. package/dist/src/nx-cloud/update-manager.d.ts +14 -0
  180. package/dist/src/nx-cloud/update-manager.js +237 -50
  181. package/dist/src/plugins/js/lock-file/pnpm-parser.js +3 -4
  182. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +2 -2
  183. package/dist/src/plugins/js/lock-file/pruned-output.js +4 -4
  184. package/dist/src/plugins/js/utils/register.js +9 -4
  185. package/dist/src/project-graph/affected/affected-tasks.d.ts +9 -6
  186. package/dist/src/project-graph/affected/affected-tasks.js +31 -7
  187. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +7 -0
  188. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +49 -6
  189. package/dist/src/project-graph/utils/project-configuration/target-merging.js +1 -1
  190. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +12 -133
  191. package/dist/src/project-graph/utils/project-configuration-utils.js +2 -2
  192. package/dist/src/project-graph/utils/retrieve-workspace-files.js +27 -6
  193. package/dist/src/tasks-runner/create-task-graph.d.ts +8 -7
  194. package/dist/src/tasks-runner/create-task-graph.js +50 -27
  195. package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
  196. package/dist/src/tasks-runner/init-tasks-runner.js +116 -59
  197. package/dist/src/tasks-runner/life-cycle.d.ts +4 -1
  198. package/dist/src/tasks-runner/life-cycle.js +7 -0
  199. package/dist/src/tasks-runner/life-cycles/performance-analysis.d.ts +5 -2
  200. package/dist/src/tasks-runner/life-cycles/performance-analysis.js +13 -7
  201. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.d.ts +4 -3
  202. package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +9 -2
  203. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +5 -2
  204. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +4 -1
  205. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +5 -1
  206. package/dist/src/tasks-runner/pseudo-ipc.d.ts +1 -0
  207. package/dist/src/tasks-runner/pseudo-ipc.js +4 -0
  208. package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
  209. package/dist/src/tasks-runner/pseudo-terminal.js +2 -2
  210. package/dist/src/tasks-runner/readiness/executor-ready-signal.d.ts +7 -0
  211. package/dist/src/tasks-runner/readiness/executor-ready-signal.js +43 -0
  212. package/dist/src/tasks-runner/readiness/probes.d.ts +14 -0
  213. package/dist/src/tasks-runner/readiness/probes.js +101 -0
  214. package/dist/src/tasks-runner/readiness/ready-signal-server.d.ts +18 -0
  215. package/dist/src/tasks-runner/readiness/ready-signal-server.js +72 -0
  216. package/dist/src/tasks-runner/readiness/ready-signal.d.ts +33 -0
  217. package/dist/src/tasks-runner/readiness/ready-signal.js +92 -0
  218. package/dist/src/tasks-runner/readiness/ready-when.d.ts +84 -0
  219. package/dist/src/tasks-runner/readiness/ready-when.js +371 -0
  220. package/dist/src/tasks-runner/readiness/startup-host.d.ts +1 -0
  221. package/dist/src/tasks-runner/readiness/startup-host.js +32 -0
  222. package/dist/src/tasks-runner/run-command.d.ts +6 -2
  223. package/dist/src/tasks-runner/run-command.js +21 -31
  224. package/dist/src/tasks-runner/run-outcome.d.ts +16 -0
  225. package/dist/src/tasks-runner/run-outcome.js +39 -0
  226. package/dist/src/tasks-runner/running-tasks/batch-process.js +6 -0
  227. package/dist/src/tasks-runner/running-tasks/node-child-process.js +5 -4
  228. package/dist/src/tasks-runner/running-tasks/running-task.d.ts +1 -1
  229. package/dist/src/tasks-runner/task-env.d.ts +10 -0
  230. package/dist/src/tasks-runner/task-env.js +37 -5
  231. package/dist/src/tasks-runner/task-graph-utils.d.ts +9 -6
  232. package/dist/src/tasks-runner/task-graph-utils.js +17 -12
  233. package/dist/src/tasks-runner/task-orchestrator.d.ts +62 -18
  234. package/dist/src/tasks-runner/task-orchestrator.js +750 -150
  235. package/dist/src/tasks-runner/tasks-runner.d.ts +1 -1
  236. package/dist/src/tasks-runner/tasks-schedule.d.ts +18 -1
  237. package/dist/src/tasks-runner/tasks-schedule.js +63 -6
  238. package/dist/src/tasks-runner/tokens.d.ts +54 -0
  239. package/dist/src/tasks-runner/tokens.js +161 -0
  240. package/dist/src/tasks-runner/utils.d.ts +35 -6
  241. package/dist/src/tasks-runner/utils.js +149 -68
  242. package/dist/src/ultracache/ci-status.d.ts +24 -0
  243. package/dist/src/ultracache/ci-status.js +87 -0
  244. package/dist/src/ultracache/config.d.ts +3 -3
  245. package/dist/src/ultracache/config.js +4 -4
  246. package/dist/src/ultracache/fetch.d.ts +2 -0
  247. package/dist/src/ultracache/fetch.js +1 -0
  248. package/dist/src/ultracache/overrides.js +4 -0
  249. package/dist/src/utils/acknowledge-build-scripts.d.ts +34 -1
  250. package/dist/src/utils/acknowledge-build-scripts.js +171 -32
  251. package/dist/src/utils/child-process.js +2 -1
  252. package/dist/src/utils/find-matching-projects.js +9 -6
  253. package/dist/src/utils/git-utils.d.ts +12 -5
  254. package/dist/src/utils/git-utils.js +69 -11
  255. package/dist/src/utils/long-running-target.d.ts +1 -3
  256. package/dist/src/utils/long-running-target.js +1 -3
  257. package/dist/src/utils/output.d.ts +4 -3
  258. package/dist/src/utils/output.js +4 -3
  259. package/dist/src/utils/owned-private-dir.d.ts +1 -17
  260. package/dist/src/utils/owned-private-dir.js +10 -62
  261. package/dist/src/utils/package-manager.d.ts +8 -0
  262. package/dist/src/utils/package-manager.js +65 -8
  263. package/dist/src/utils/perf-hooks.d.ts +1 -0
  264. package/dist/src/utils/plugins/core-plugins.js +5 -1
  265. package/dist/src/utils/progress-topics.d.ts +1 -0
  266. package/dist/src/utils/progress-topics.js +1 -0
  267. package/dist/src/utils/safe-spawn.js +1 -5
  268. package/dist/src/utils/shell-quoting.d.ts +8 -1
  269. package/dist/src/utils/shell-quoting.js +12 -1
  270. package/dist/src/utils/spawn-without-terminal.d.ts +27 -0
  271. package/dist/src/utils/spawn-without-terminal.js +110 -0
  272. package/dist/src/utils/string-similarity.d.ts +38 -0
  273. package/dist/src/utils/string-similarity.js +108 -0
  274. package/migrations.json +20 -6
  275. package/package.json +15 -24
  276. package/schemas/migrations-schema.json +11 -0
  277. package/schemas/nx-schema.json +133 -11
  278. package/schemas/project-schema.json +114 -4
  279. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.d.ts +0 -56
  280. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +0 -67
  281. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.d.ts +0 -49
  282. package/dist/src/command-line/migrate/agentic/prompts/hybrid-prompt-migration.js +0 -53
  283. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.d.ts +0 -26
  284. package/dist/src/command-line/migrate/agentic/prompts/prompt-migration.js +0 -27
  285. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +0 -70
  286. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +0 -113
  287. package/dist/src/command-line/migrate/agentic/run-step.d.ts +0 -68
  288. package/dist/src/command-line/migrate/agentic/run-step.js +0 -148
  289. package/dist/src/command-line/migrate/agentic/runner.d.ts +0 -21
  290. package/dist/src/command-line/migrate/agentic/runner.js +0 -262
  291. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.d.ts +0 -9
  292. package/dist/src/migrations/update-23-0-0/consolidate-release-tag-config.js +0 -18
  293. package/dist/src/tasks-runner/legacy-depends-on-warning.d.ts +0 -18
  294. package/dist/src/tasks-runner/legacy-depends-on-warning.js +0 -109
@@ -13,7 +13,6 @@ exports.isRunPhaseInvocation = isRunPhaseInvocation;
13
13
  exports.migrate = migrate;
14
14
  exports.readLocalNxVersion = readLocalNxVersion;
15
15
  exports.runMigration = runMigration;
16
- exports.resolveMigrationForRun = resolveMigrationForRun;
17
16
  exports.nxCliPath = nxCliPath;
18
17
  const tslib_1 = require("tslib");
19
18
  const pc = tslib_1.__importStar(require("picocolors"));
@@ -37,6 +36,7 @@ const package_manager_1 = require("../../utils/package-manager");
37
36
  const errors_1 = require("../../utils/min-release-age/errors");
38
37
  const resolve_package_version_1 = require("./resolve-package-version");
39
38
  const handle_errors_1 = require("../../utils/handle-errors");
39
+ const exit_codes_1 = require("../../utils/exit-codes");
40
40
  const connect_to_nx_cloud_1 = require("../nx-cloud/connect/connect-to-nx-cloud");
41
41
  const output_1 = require("../../utils/output");
42
42
  const fs_1 = require("fs");
@@ -56,6 +56,7 @@ const multi_major_1 = require("./multi-major");
56
56
  const prompt_files_1 = require("./prompt-files");
57
57
  const command_object_1 = require("./command-object");
58
58
  const migrate_config_1 = require("./migrate-config");
59
+ const types_1 = require("./agentic/types");
59
60
  const migrate_commits_1 = require("./migrate-commits");
60
61
  const migrate_output_1 = require("./migrate-output");
61
62
  const migration_shape_1 = require("./migration-shape");
@@ -68,6 +69,7 @@ Object.defineProperty(exports, "normalizeVersion", { enumerable: true, get: func
68
69
  const execute_migration_1 = require("./execute-migration");
69
70
  const step_actions_1 = require("./step-actions");
70
71
  const sort_migrations_1 = require("./sort-migrations");
72
+ const text_1 = require("./text");
71
73
  const inception_1 = require("./agentic/inception");
72
74
  const version_skew_guard_1 = require("./version-skew-guard");
73
75
  const versions_1 = require("../../utils/versions");
@@ -88,20 +90,27 @@ function formatCommandFailure(command, error) {
88
90
  .trim();
89
91
  return [`Command failed: ${command}`, ...(details ? [details] : [])].join('\n');
90
92
  }
93
+ // Ctrl+C is left to the child. Killed by it, this process would hand the
94
+ // terminal back to the shell while the child still runs.
91
95
  function runOrReturnExitCode(run) {
96
+ const leaveSigintToChild = () => { };
97
+ process.on('SIGINT', leaveSigintToChild);
92
98
  try {
93
99
  run();
94
100
  return 0;
95
101
  }
96
102
  catch (e) {
97
- if (typeof e === 'object' &&
98
- e !== null &&
99
- 'status' in e &&
100
- typeof e.status === 'number') {
103
+ if (typeof e !== 'object' || e === null)
104
+ throw e;
105
+ if ('signal' in e && e.signal === 'SIGINT')
106
+ (0, exit_codes_1.exitAsInterrupted)();
107
+ if ('status' in e && typeof e.status === 'number')
101
108
  return e.status;
102
- }
103
109
  throw e;
104
110
  }
111
+ finally {
112
+ process.removeListener('SIGINT', leaveSigintToChild);
113
+ }
105
114
  }
106
115
  function cleanSemver(version) {
107
116
  return (0, semver_1.clean)(version) ?? (0, semver_1.coerce)(version);
@@ -144,8 +153,8 @@ class Migrator {
144
153
  addToPackageJson: false,
145
154
  });
146
155
  await this.applyPendingPackageJsonUpdates();
147
- this.applyIncludeFilter();
148
- const { migrations, promptContents } = await this.createMigrateJson();
156
+ const requiredPackageUpdates = this.applyIncludeFilter();
157
+ const { migrations, promptContents } = await this.createMigrateJson(requiredPackageUpdates);
149
158
  return {
150
159
  packageUpdates: this.packageUpdates,
151
160
  migrations,
@@ -153,17 +162,10 @@ class Migrator {
153
162
  minVersionWithSkippedUpdates: this.minVersionWithSkippedUpdates,
154
163
  };
155
164
  }
156
- async createMigrateJson() {
165
+ async createMigrateJson(requiredPackageUpdates) {
157
166
  const promptContents = {};
158
- const migrations = await Promise.all(Object.keys(this.packageUpdates).map(async (packageName) => {
159
- if (this.packageUpdates[packageName].ignoreMigrations) {
160
- return [];
161
- }
162
- const currentVersion = this.getPkgVersion(packageName);
163
- if (currentVersion === null)
164
- return [];
165
- const { version } = this.packageUpdates[packageName];
166
- const { generators: migrationEntries, resolvedPromptFiles } = await this.fetchMigrationConfig(packageName, version);
167
+ const collect = async (packageName, metadataVersion, fromVersion, toVersion) => {
168
+ const { generators: migrationEntries, resolvedPromptFiles } = await this.fetchMigrationConfig(packageName, metadataVersion);
167
169
  if (!migrationEntries)
168
170
  return [];
169
171
  if (resolvedPromptFiles) {
@@ -173,15 +175,34 @@ class Migrator {
173
175
  }
174
176
  return Object.entries(migrationEntries)
175
177
  .filter(([, migration]) => migration.version &&
176
- this.gt(migration.version, currentVersion) &&
177
- this.lte(migration.version, version) &&
178
- this.areMigrationRequirementsMet(packageName, migration))
178
+ this.gt(migration.version, fromVersion) &&
179
+ this.lte(migration.version, toVersion) &&
180
+ this.shouldCollectMigration(packageName, migration))
179
181
  .map(([migrationName, migration]) => ({
180
182
  ...migration,
181
183
  package: packageName,
182
184
  name: migrationName,
183
185
  }));
184
- }));
186
+ };
187
+ const migrations = await Promise.all([
188
+ ...Object.entries(this.packageUpdates).map(async ([packageName, { version, ignoreMigrations }]) => {
189
+ if (ignoreMigrations)
190
+ return [];
191
+ const currentVersion = this.getPkgVersion(packageName);
192
+ if (currentVersion === null)
193
+ return [];
194
+ return collect(packageName, version, currentVersion, version);
195
+ }),
196
+ // The optional pass keeps required packages at their installed version,
197
+ // and the runner resolves migrations from there. An older target caps the
198
+ // range.
199
+ ...Object.entries(requiredPackageUpdates).map(async ([packageName, { version, ignoreMigrations }]) => {
200
+ const installedVersion = this.getInstalledPackageVersion(packageName);
201
+ if (ignoreMigrations || !installedVersion)
202
+ return [];
203
+ return collect(packageName, installedVersion, '0.0.0', this.lt(version, installedVersion) ? version : installedVersion);
204
+ }),
205
+ ]);
185
206
  return { migrations: migrations.flat(), promptContents };
186
207
  }
187
208
  async buildPackageJsonUpdates(targetPackage, target) {
@@ -423,8 +444,9 @@ class Migrator {
423
444
  return false;
424
445
  }
425
446
  applyIncludeFilter() {
447
+ const requiredPackageUpdates = {};
426
448
  if (this.include !== 'optional') {
427
- return;
449
+ return requiredPackageUpdates;
428
450
  }
429
451
  // Cascade walks through the required packages so cross-plugin optional
430
452
  // deps (e.g. typescript managed by @nx/js but used by @nx/angular) get
@@ -432,9 +454,11 @@ class Migrator {
432
454
  // optional updates land in package.json.
433
455
  for (const name of Object.keys(this.packageUpdates)) {
434
456
  if (this.requiredPackages.has(name)) {
457
+ requiredPackageUpdates[name] = this.packageUpdates[name];
435
458
  delete this.packageUpdates[name];
436
459
  }
437
460
  }
461
+ return requiredPackageUpdates;
438
462
  }
439
463
  shouldApplyPackageUpdate(packageUpdate, packageName, dependencies) {
440
464
  return ((!packageUpdate.ifPackageInstalled ||
@@ -484,6 +508,35 @@ class Migrator {
484
508
  }));
485
509
  });
486
510
  }
511
+ shouldCollectMigration(packageName, migration) {
512
+ if (this.include === 'required') {
513
+ return (migration.optionalUpdate !== true &&
514
+ this.areMigrationRequirementsMet(packageName, migration));
515
+ }
516
+ if (this.include === 'optional' &&
517
+ this.requiredPackages.has(packageName)) {
518
+ // Every past migration of a required package is in range here. Collect
519
+ // only those that apply an optional update or were skipped.
520
+ return ((migration.optionalUpdate === true ||
521
+ this.wasMigrationSkipped(migration.requires)) &&
522
+ this.areRequirementsMetAfterUpdates(migration.requires));
523
+ }
524
+ return this.areMigrationRequirementsMet(packageName, migration);
525
+ }
526
+ // Counts only updates above the installed version. The optional walk also
527
+ // collects stale pins below it, which are never written.
528
+ areRequirementsMetAfterUpdates(requirements) {
529
+ return Object.entries(requirements ?? {}).every(([pkgName, versionRange]) => {
530
+ const installedVersion = this.getInstalledPackageVersion(pkgName);
531
+ const update = this.packageUpdates[pkgName];
532
+ const version = update &&
533
+ (!installedVersion || this.gt(update.version, installedVersion))
534
+ ? cleanSemver(update.version)
535
+ : installedVersion;
536
+ return (!!version &&
537
+ (0, semver_1.satisfies)(version, versionRange, { includePrerelease: true }));
538
+ });
539
+ }
487
540
  areMigrationRequirementsMet(packageName, migration) {
488
541
  if (!this.excludeAppliedMigrations) {
489
542
  return this.areRequirementsMet(migration.requires);
@@ -777,9 +830,7 @@ async function parseMigrationsOptions(options, fetch) {
777
830
  options.stepAction !== undefined) {
778
831
  throw new Error(`Error: '--step-action' cannot be combined with '--run-migrations'.`);
779
832
  }
780
- // A bare '--run-id' reconciles the run it names. Ungated, unlike init:
781
- // the id has to name a run directory that exists, and only a gated init
782
- // ever creates one.
833
+ // A bare '--run-id' reconciles the run it names.
783
834
  // yargs' choices already reject bad CLI values; this guards programmatic
784
835
  // callers, where silently dropping the action would reconcile without it.
785
836
  if (options.stepAction !== undefined && !(0, step_actions_1.isStepAction)(options.stepAction)) {
@@ -1752,23 +1803,12 @@ function formatSkippedPromptsNextStep(skipped) {
1752
1803
  ...skipped.map((m) => ` - ${m.prompt}`),
1753
1804
  ].join('\n');
1754
1805
  }
1755
- async function executeMigrations(root, migrations, isVerbose, shouldCreateCommits, commitPrefix, shouldSkipInstall = false, agentic, agenticHasDiffContext = false, shouldRunValidation = false) {
1806
+ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommits, commitPrefix, shouldSkipInstall = false,
1807
+ // An enabled agent drives the whole run from one session instead.
1808
+ agentic) {
1756
1809
  const changedDepInstaller = new execute_migration_1.ChangedDepInstaller(root, shouldSkipInstall);
1757
1810
  const migrationsWithNoChanges = [];
1758
- const sortedMigrations = (0, sort_migrations_1.sortMigrations)(migrations, {
1759
- hoistHandoffGitignore: agentic?.kind === 'enabled',
1760
- });
1761
- // Lazy-load the agentic chain so non-agentic runs don't pay its startup cost.
1762
- let agenticRun;
1763
- if (agentic?.kind === 'enabled' && sortedMigrations.length > 0) {
1764
- const { initRunDir, resolveAgenticRunId } = require('./agentic/handoff');
1765
- const { runAgenticPromptStep } = require('./agentic/run-step');
1766
- agenticRun = {
1767
- agentic,
1768
- runDir: initRunDir(root, resolveAgenticRunId(sortedMigrations)),
1769
- runStep: runAgenticPromptStep,
1770
- };
1771
- }
1811
+ const sortedMigrations = (0, sort_migrations_1.sortMigrations)(migrations);
1772
1812
  const printDroppedAgentContext = agentic?.kind === 'inside-agent'
1773
1813
  ? require('./agentic/print-dropped-agent-context').printDroppedAgentContextForOuterAgent
1774
1814
  : undefined;
@@ -1803,12 +1843,6 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1803
1843
  const pendingForCommitBody = () => outcomes
1804
1844
  .filter((o) => o.commit.kind === 'failed')
1805
1845
  .map((o) => ({ package: o.migration.package, name: o.migration.name }));
1806
- // True while at least one prior migration's commit has failed and its
1807
- // diff hasn't been absorbed yet. While true, the working tree carries
1808
- // prior-migration state, so the `hasDiffContext` flag in the hybrid-
1809
- // agentic and validation-agentic prompt branches is suppressed (the
1810
- // prompt-only-with-agentic branch doesn't use `hasDiffContext`).
1811
- const hasPendingCommitDebt = () => outcomes.some((o) => o.commit.kind === 'failed');
1812
1846
  // Single funnel for per-migration commit attempts. Returns the
1813
1847
  // `CommitState` to record on the migration's outcome. On `committed`,
1814
1848
  // back-annotates any prior failed-commit outcomes to `kind: 'absorbed'`
@@ -1841,8 +1875,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1841
1875
  return { kind: 'landed', sha: result.sha };
1842
1876
  }
1843
1877
  if (result.status === 'failed') {
1844
- // Diff is still in WT. Subsequent prompts cannot claim git-isolation
1845
- // until a later commit absorbs the backlog.
1878
+ // The diff stays in the working tree until a later commit absorbs it.
1846
1879
  return { kind: 'failed' };
1847
1880
  }
1848
1881
  // `no-changes` and `disabled` — no commit attempted, nothing to record
@@ -1875,89 +1908,36 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1875
1908
  // Content-sensitive so a dirty→dirty case (this migration mutating an
1876
1909
  // already-dirty shared file like `package.json`) doesn't collapse.
1877
1910
  const baselineWorkingTreeSnapshot = (0, git_utils_1.getUncommittedChangesSnapshot)(root);
1878
- // Tracks whether a failure originated in the agentic step so the error
1879
- // event classifies it as 'agentic' rather than 'migration_exec'.
1880
- let inAgenticStep = false;
1881
1911
  try {
1882
- // Read this migration's collection once and derive everything from it:
1883
- // the implementation context (passed to runNxOrAngularMigration) and the
1884
- // documentation path (passed to the agent). Read fresh per iteration so a
1885
- // prior migration's reinstall is reflected.
1886
- const { resolvedCollection, documentationPath } = resolveMigrationForRun(root, m, !!agenticRun);
1912
+ // Read fresh per migration so a prior migration's reinstall is reflected.
1913
+ const resolvedCollection = (0, migration_shape_1.isPromptOnlyMigration)(m)
1914
+ ? undefined
1915
+ : (0, execute_migration_1.readMigrationCollection)(m.package, root);
1887
1916
  let outcome;
1888
1917
  let commit = { kind: 'none' };
1889
- // Set when the migration returned `skipAgentic: true` and something was
1890
- // actually waived, so the end-of-run recaps can report it. A hybrid's
1891
- // prompt is owed in every agentic mode, so waiving it always counts; a
1892
- // generator-only migration only counts when validation would have run.
1918
+ // Set when a hybrid returned `skipAgentic: true`, so the end-of-run
1919
+ // recaps can report the waived prompt.
1893
1920
  let waivedAgenticStep = false;
1894
1921
  if ((0, migration_shape_1.isPromptOnlyMigration)(m)) {
1895
- if (agenticRun) {
1896
- inAgenticStep = true;
1897
- const stepResult = await agenticRun.runStep({
1898
- root,
1899
- migration: m,
1900
- agentic: agenticRun.agentic,
1901
- runDir: agenticRun.runDir,
1902
- installDepsIfChanged,
1903
- documentationPath,
1904
- });
1905
- inAgenticStep = false;
1906
- commit = await attemptMigrationCommit(m);
1907
- (0, migrate_output_1.logAgenticSuccessOutcome)(stepResult.ambiguous ? 'Marked complete by user' : 'Applied', commit.kind === 'landed' ? commit.sha : null, stepResult.summary);
1908
- outcome = 'applied';
1909
- }
1910
- else {
1911
- logger_1.logger.info(pc.dim(`↷ Skipped — ${skipReason}. Listed in next steps.`));
1912
- skippedPrompts.push(m);
1913
- notRunMigrationsCount++;
1914
- outcome = 'deferred';
1915
- }
1922
+ logger_1.logger.info(pc.dim(`↷ Skipped — ${skipReason}. Listed in next steps.`));
1923
+ skippedPrompts.push(m);
1924
+ notRunMigrationsCount++;
1925
+ outcome = 'deferred';
1916
1926
  }
1917
1927
  else if ((0, migration_shape_1.isHybridMigration)(m)) {
1918
- const { changes, nextSteps, agentContext, skipAgentic, logs, madeChanges, } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1919
- /* captureGeneratorOutput: */ !!agenticRun, resolvedCollection);
1928
+ const { nextSteps, agentContext, skipAgentic, madeChanges } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1929
+ /* captureGeneratorOutput: */ false, resolvedCollection);
1920
1930
  migrationEmittedNextSteps.push(...nextSteps);
1921
1931
  if (skipAgentic) {
1922
1932
  // The generator reported the prompt half unnecessary, so nothing is
1923
- // owed: no agent run, and no next-steps entry telling the user to
1924
- // run the prompt themselves. Runs in all three agentic modes.
1933
+ // owed: no next-steps entry telling anyone to run the prompt.
1925
1934
  (0, migrate_output_1.logWaivedAgenticStep)(m, agentContext);
1926
1935
  waivedAgenticStep = true;
1927
1936
  commit = await commitOrRecordNoChanges(m, madeChanges);
1928
1937
  outcome = madeChanges ? 'applied' : 'no-changes';
1929
1938
  }
1930
- else if (agenticRun) {
1931
- // Install any deps the deterministic phase added/bumped before the
1932
- // agent runs — the prompt half may depend on them being present in
1933
- // node_modules.
1934
- await installDepsIfChanged();
1935
- inAgenticStep = true;
1936
- const stepResult = await agenticRun.runStep({
1937
- root,
1938
- migration: m,
1939
- agentic: agenticRun.agentic,
1940
- runDir: agenticRun.runDir,
1941
- installDepsIfChanged,
1942
- documentationPath,
1943
- implContext: {
1944
- logs,
1945
- changes,
1946
- agentContext,
1947
- // When prior commits failed, the working tree carries their
1948
- // diff. The git-inspect path of the prompt would mislead the
1949
- // agent in that case; fall back to embedded `<files_changed>`.
1950
- hasDiffContext: agenticHasDiffContext && !hasPendingCommitDebt(),
1951
- },
1952
- });
1953
- inAgenticStep = false;
1954
- commit = await attemptMigrationCommit(m);
1955
- (0, migrate_output_1.logAgenticSuccessOutcome)(stepResult.ambiguous ? 'Marked complete by user' : 'Applied', commit.kind === 'landed' ? commit.sha : null, stepResult.summary);
1956
- outcome = 'applied';
1957
- }
1958
1939
  else {
1959
- // The inner prompt step doesn't run here (agentic disabled, or
1960
- // running inside an outer agent). Under `inside-agent`, surface the
1940
+ // The prompt half is deferred. Under `inside-agent`, surface the
1961
1941
  // generator-emitted `agentContext` to stdout so the outer driving
1962
1942
  // agent can ingest it. Under `disabled` the run is human-driven;
1963
1943
  // agent-targeted context would only add noise — drop.
@@ -1971,59 +1951,16 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1971
1951
  }
1972
1952
  }
1973
1953
  else {
1974
- // Defer commit until validation succeeds; failed validation leaves
1975
- // changes uncommitted in the working tree for the user to review.
1976
- const validationRun = agenticRun && shouldRunValidation ? agenticRun : undefined;
1977
- const { changes, nextSteps, agentContext, skipAgentic, logs, madeChanges, } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1978
- /* captureGeneratorOutput: */ !!validationRun, resolvedCollection);
1954
+ const { nextSteps, agentContext, madeChanges } = await (0, execute_migration_1.runNxOrAngularMigration)(root, m, isVerbose,
1955
+ /* captureGeneratorOutput: */ false, resolvedCollection);
1979
1956
  migrationEmittedNextSteps.push(...nextSteps);
1980
- // Whether a validation step was on the table at all. `skipAgentic`
1981
- // waives nothing when it wasn't, so the whole waived path hangs off
1982
- // this, not just the log line.
1983
- const validationApplies = !!validationRun && changes.length > 0;
1984
- const canRunValidation = validationApplies && !skipAgentic;
1985
- if (canRunValidation) {
1986
- // Install any deps the deterministic phase added/bumped before the
1987
- // validation agent runs — the agent may run tasks that need them.
1988
- await installDepsIfChanged();
1989
- inAgenticStep = true;
1990
- const stepResult = await validationRun.runStep({
1991
- root,
1992
- migration: m,
1993
- agentic: validationRun.agentic,
1994
- runDir: validationRun.runDir,
1995
- installDepsIfChanged,
1996
- documentationPath,
1997
- implContext: {
1998
- logs,
1999
- changes,
2000
- agentContext,
2001
- // See the hybrid agentic branch above for the rationale on
2002
- // why pending commit debt gates git-inspect context.
2003
- hasDiffContext: agenticHasDiffContext && !hasPendingCommitDebt(),
2004
- },
2005
- mode: 'generic-validation',
2006
- });
2007
- inAgenticStep = false;
2008
- commit = await attemptMigrationCommit(m);
2009
- (0, migrate_output_1.logAgenticSuccessOutcome)(stepResult.ambiguous
2010
- ? 'Marked complete by user'
2011
- : 'Validation passed', commit.kind === 'landed' ? commit.sha : null, stepResult.summary);
2012
- outcome = 'applied';
2013
- }
2014
- else {
2015
- if (skipAgentic && validationApplies) {
2016
- (0, migrate_output_1.logWaivedAgenticStep)(m, agentContext);
2017
- waivedAgenticStep = true;
2018
- }
2019
- else if (printDroppedAgentContext && agentContext.length > 0) {
2020
- // Inner validation step didn't run. Surface `agentContext` under
2021
- // `inside-agent` so the outer driving agent can ingest it.
2022
- printDroppedAgentContext({ migration: m, agentContext });
2023
- }
2024
- commit = await commitOrRecordNoChanges(m, madeChanges);
2025
- outcome = madeChanges ? 'applied' : 'no-changes';
1957
+ if (printDroppedAgentContext && agentContext.length > 0) {
1958
+ // Surface `agentContext` under `inside-agent` so the outer driving
1959
+ // agent can ingest it.
1960
+ printDroppedAgentContext({ migration: m, agentContext });
2026
1961
  }
1962
+ commit = await commitOrRecordNoChanges(m, madeChanges);
1963
+ outcome = madeChanges ? 'applied' : 'no-changes';
2027
1964
  }
2028
1965
  outcomes.push({
2029
1966
  migration: { package: m.package, name: m.name },
@@ -2053,9 +1990,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2053
1990
  (0, migrate_analytics_1.reportMigrateRunError)({
2054
1991
  code: e instanceof execute_migration_1.NpmPeerDepsInstallError
2055
1992
  ? 'npm_install'
2056
- : inAgenticStep
2057
- ? 'agentic'
2058
- : 'migration_exec',
1993
+ : 'migration_exec',
2059
1994
  migrationPackage: m.package,
2060
1995
  migrationName: m.name,
2061
1996
  migrationCount: totalMigrations,
@@ -2117,8 +2052,66 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2117
2052
  retainedAtSuccess: (0, migrate_output_1.retainedMigrations)(outcomes).map((p) => `${p.package}: ${p.name}`),
2118
2053
  };
2119
2054
  }
2120
- function orchestratorFlagNeedsOrchestrator(flag) {
2121
- return `'${flag}' acts on an orchestrated migrate run (NX_MIGRATE_ORCHESTRATOR=true with an enabled agent), and this invocation is not orchestrated.`;
2055
+ const CONTINUE_NEEDS_ORCHESTRATION = `'--run-id' continues an orchestrated migrate run, and this invocation is not orchestrated. Orchestration needs an enabled agent, or an AI agent running nx outside CI; --agentic=false and the WASM build turn it off.`;
2056
+ // The classic loop records no run, so it must not run over an active one. The
2057
+ // run is reported or asked about before the default-branch prompt; a start
2058
+ // fresh is checked there too, and the caller deletes the run only after it.
2059
+ async function settleActiveRunForClassic(root, opts, migrations) {
2060
+ const { activeRunForClassic, checkRunForStartFresh, isHeld, renderContinueCommand, renderExistingRunCommands, renderExistingRunReport, } = require('./run');
2061
+ const active = activeRunForClassic(root, migrations.map((m) => `${m.package}:${m.name}`));
2062
+ // With no active run left, the check refuses as init does: the run
2063
+ // completed after the pre-install check, so its plan already ran.
2064
+ if (opts.startFresh === true &&
2065
+ (active === null || active.runId === opts.runId)) {
2066
+ checkRunForStartFresh(root, opts.runId);
2067
+ return { kind: 'run', replaceRunId: opts.runId };
2068
+ }
2069
+ if (!active) {
2070
+ return { kind: 'run' };
2071
+ }
2072
+ const { runId, facts } = active;
2073
+ // Start fresh refuses while another process holds the run, so a held run
2074
+ // leaves nothing to ask; an agent cannot answer a prompt.
2075
+ const held = isHeld(facts.otherHolders);
2076
+ if (opts.startFresh !== true &&
2077
+ !held &&
2078
+ (0, safe_prompt_1.canPrompt)(opts.interactive) &&
2079
+ !(0, inception_1.isInsideAgent)()) {
2080
+ output_1.output.log(renderExistingRunReport(facts));
2081
+ const choice = await (0, safe_prompt_1.migrateChoice)({
2082
+ message: 'What do you want to do with the active migrate run?',
2083
+ choices: [
2084
+ {
2085
+ value: 'start-fresh',
2086
+ label: 'Start fresh',
2087
+ hint: 'deletes the run record, then runs the whole plan without an agent',
2088
+ },
2089
+ { value: 'abort', label: 'Abort', hint: 'leaves the run as it is' },
2090
+ ],
2091
+ });
2092
+ switch (choice) {
2093
+ case 'start-fresh':
2094
+ checkRunForStartFresh(root, runId);
2095
+ return { kind: 'run', replaceRunId: runId };
2096
+ case 'abort':
2097
+ output_1.output.log({
2098
+ title: `Leaving migrate run ${runId} as it is. To continue it with an agent, run ${renderContinueCommand(root, runId, facts.policy)}.`,
2099
+ });
2100
+ (0, migrate_analytics_1.reportMigrateRunStopped)('aborted');
2101
+ return { kind: 'stop', exitCode: undefined };
2102
+ default: {
2103
+ const unhandled = choice;
2104
+ throw new Error(`Unhandled choice: ${unhandled}`);
2105
+ }
2106
+ }
2107
+ }
2108
+ const report = renderExistingRunReport(facts, renderExistingRunCommands(root, facts, opts.runMigrations, opts.agentic === false ? false : undefined));
2109
+ if (native_1.IS_WASM) {
2110
+ report.bodyLines.push(`The WASM build can run neither command. Continue the run with the native nx binary, or make sure no nx migrate process is acting on it, remove ${types_1.MIGRATE_RUNS_RELATIVE_DIR}/${runId}, then run the plan again.`);
2111
+ }
2112
+ output_1.output.warn(report);
2113
+ (0, migrate_analytics_1.reportMigrateRunStopped)('existing_run');
2114
+ return { kind: 'stop', exitCode: 1 };
2122
2115
  }
2123
2116
  // nx is located at spawn time, after the gated pre-install, so the child runs
2124
2117
  // the bytes that install put in place.
@@ -2134,20 +2127,18 @@ function handOffToLocalNx(args) {
2134
2127
  return exitCode !== 0 ? exitCode : undefined;
2135
2128
  }
2136
2129
  async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, commitPrefix, shouldSkipInstall = false) {
2137
- // Both flags act on an orchestrated run: refuse them where none can run
2138
- // (an explicit --agentic=false outside an agent cannot reach one either),
2139
- // before the install and before --if-exists could return silently.
2140
- const orchestratorFlag = opts.startFresh === true
2141
- ? '--start-fresh'
2142
- : opts.runId !== undefined
2143
- ? '--run-id'
2144
- : undefined;
2145
- if (orchestratorFlag !== undefined &&
2146
- (process.env.NX_MIGRATE_ORCHESTRATOR !== 'true' ||
2147
- (opts.agentic === false && !(0, inception_1.isInsideAgent)()))) {
2148
- throw new Error(orchestratorFlagNeedsOrchestrator(orchestratorFlag));
2149
- }
2130
+ // The WASM build lacks the native locks a durable run relies on.
2131
+ const outerAgentDrivesRun = (0, inception_1.isInsideAgent)() && opts.agentic !== false && !(0, is_ci_1.isCI)() && !native_1.IS_WASM;
2150
2132
  const isContinue = opts.runId !== undefined && opts.startFresh !== true;
2133
+ // Refused before the install, and before --if-exists could return silently,
2134
+ // when neither the outer agent nor a master session (an agent enabled
2135
+ // outside one, off WASM) can continue the run. A start fresh may reach the
2136
+ // classic loop, which deletes the run's record and runs the plan.
2137
+ if (isContinue &&
2138
+ !outerAgentDrivesRun &&
2139
+ ((0, inception_1.isInsideAgent)() || opts.agentic === false || native_1.IS_WASM)) {
2140
+ throw new Error(CONTINUE_NEEDS_ORCHESTRATION);
2141
+ }
2151
2142
  let continued;
2152
2143
  if (isContinue) {
2153
2144
  // Before the install: a concurrent start-fresh must not delete the run
@@ -2160,8 +2151,42 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2160
2151
  const { activeRunToReplace } = require('./run');
2161
2152
  activeRunToReplace(root, opts.runId);
2162
2153
  }
2154
+ else {
2155
+ // Before the install as well: it would act on the in-progress edits of a
2156
+ // live run that init wouldn't report.
2157
+ const { refuseNewRunAlongsideLiveRun } = require('./run');
2158
+ refuseNewRunAlongsideLiveRun(root);
2159
+ }
2163
2160
  if (!shouldSkipInstall && !process.env.NX_MIGRATE_SKIP_INSTALL) {
2164
- await (0, execute_migration_1.runInstall)();
2161
+ // The run must resume while the cause of a step's failed install persists.
2162
+ const failedInstallSteps = continued?.steps.filter((s) => s.installFailed === true) ?? [];
2163
+ if (failedInstallSteps.length > 0) {
2164
+ const { pmInstallCommand, stepLabel, TERMINAL_STEP_STATUSES } = require('./run');
2165
+ // A settled step keeps its mark, but no step action can retry it.
2166
+ const settled = failedInstallSteps.filter((s) => TERMINAL_STEP_STATUSES.has(s.status));
2167
+ const retryable = failedInstallSteps.filter((s) => !settled.includes(s));
2168
+ const notCompleted = (steps) => `The dependency install of ${steps
2169
+ .map(stepLabel)
2170
+ .join(', ')} did not complete earlier in this run.`;
2171
+ output_1.output.warn({
2172
+ title: 'Skipping the dependency install',
2173
+ bodyLines: [
2174
+ ...(retryable.length > 0
2175
+ ? [
2176
+ `${notCompleted(retryable)} Retrying that step installs again; any other choice leaves the install to you.`,
2177
+ ]
2178
+ : []),
2179
+ ...(settled.length > 0
2180
+ ? [
2181
+ `${notCompleted(settled)} Run \`${pmInstallCommand(root)}\` once the cause of the failed install is fixed.`,
2182
+ ]
2183
+ : []),
2184
+ ].map(text_1.singleLine),
2185
+ });
2186
+ }
2187
+ else {
2188
+ await (0, execute_migration_1.runInstall)();
2189
+ }
2165
2190
  }
2166
2191
  if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
2167
2192
  // we are running from a temp installation with nx latest, switch to running
@@ -2214,11 +2239,19 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2214
2239
  validate: opts.validate,
2215
2240
  finalValidation: opts.finalValidation,
2216
2241
  });
2242
+ // Orchestration refuses ids it cannot dispense verbatim or resolve to one
2243
+ // step, so a new run with one falls back to the classic loop. A continue
2244
+ // has no classic fallback, since it runs the plan its run recorded, and a
2245
+ // start fresh still reaches init's refusal.
2246
+ const idProblems = isContinue || opts.startFresh === true
2247
+ ? []
2248
+ : require('./run').migrationIdProblems(migrations);
2249
+ const { dropUnsupportedAgent, idProblemLines, resolveAgentic } = require('./agentic/select');
2217
2250
  // An outer agent drives the loop, so hand off to the orchestrator instead of
2218
2251
  // the classic loop: init starts a fresh run or reports an already-active
2219
2252
  // one; `--run-id` continues that run. Bare `--run-id` reconciles are
2220
2253
  // dispatched separately and never reach here.
2221
- if (process.env.NX_MIGRATE_ORCHESTRATOR === 'true' && (0, inception_1.isInsideAgent)()) {
2254
+ if (outerAgentDrivesRun && idProblems.length === 0) {
2222
2255
  const { runOrchestratorInit, runOrchestratorResume } = require('./run');
2223
2256
  // Orchestrated runs are agent-driven, so commits default on exactly as they
2224
2257
  // do under `--agentic=enabled`; the orchestrator replaces `resolveAgentic`.
@@ -2279,11 +2312,19 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2279
2312
  });
2280
2313
  return;
2281
2314
  }
2315
+ if (outerAgentDrivesRun) {
2316
+ output_1.output.warn({
2317
+ title: 'Running the migrations without an orchestrated run: orchestrated runs need each migration id to be shell-safe (letters, digits and @/:._-) and listed once, and these are not:',
2318
+ bodyLines: [
2319
+ ...idProblemLines(idProblems),
2320
+ 'No run is recorded, so --run-id cannot continue this one. Prompt work is listed as next steps for the AI agent driving this run, and no validation runs.',
2321
+ ],
2322
+ });
2323
+ }
2282
2324
  (0, migrate_analytics_1.reportMigrateRunStart)({
2283
2325
  createCommits: shouldCreateCommits ?? false,
2284
2326
  migrationCount: migrations.length,
2285
2327
  });
2286
- const { resolveAgentic, resolveShouldRunValidation } = require('./agentic/select');
2287
2328
  let agentic;
2288
2329
  try {
2289
2330
  agentic = await resolveAgentic({
@@ -2296,7 +2337,9 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2296
2337
  (0, migrate_analytics_1.reportMigrateRunError)({ code: 'agentic', error: e });
2297
2338
  throw e;
2298
2339
  }
2299
- const { effective: effectiveCreateCommits, agenticHasDiffContext, warning: createCommitsWarning, error: createCommitsError, } = (0, migrate_commits_1.resolveCreateCommits)({
2340
+ // Resolved before the commit policy, which defaults on only for an agent.
2341
+ agentic = dropUnsupportedAgent(agentic, idProblems);
2342
+ const { effective: effectiveCreateCommits, warning: createCommitsWarning, error: createCommitsError, } = (0, migrate_commits_1.resolveCreateCommits)({
2300
2343
  createCommits: shouldCreateCommits,
2301
2344
  mode: agentic.kind,
2302
2345
  isGitRepo: (0, git_utils_1.isGitRepository)(root),
@@ -2314,12 +2357,8 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2314
2357
  const confirmNewRunCommits = async () => !effectiveCreateCommits ||
2315
2358
  !(0, safe_prompt_1.canPrompt)(opts.interactive) ||
2316
2359
  (0, migrate_commits_1.confirmMigrationCommitsOnDefaultBranch)(root, 'running migrations');
2317
- // Dark: with the env var set, the agent drives the whole run through the
2318
- // orchestrator from one session instead of being spawned per step. Not
2319
- // under WASM, where the broker has no native lock to detect a dead parent.
2320
- if (agentic.kind === 'enabled' &&
2321
- process.env.NX_MIGRATE_ORCHESTRATOR === 'true' &&
2322
- !native_1.IS_WASM) {
2360
+ // The agent drives the whole run through the orchestrator from one session.
2361
+ if (agentic.kind === 'enabled') {
2323
2362
  const init = orchestratorInitInput(effectiveCreateCommits);
2324
2363
  const { runMasterSession } = require('./agentic/master/run-master-session');
2325
2364
  return await runMasterSession({
@@ -2331,16 +2370,22 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2331
2370
  confirmStart: confirmNewRunCommits,
2332
2371
  });
2333
2372
  }
2334
- if (orchestratorFlag !== undefined) {
2335
- throw new Error(orchestratorFlagNeedsOrchestrator(orchestratorFlag));
2373
+ if (isContinue) {
2374
+ throw new Error(CONTINUE_NEEDS_ORCHESTRATION);
2375
+ }
2376
+ const classicGate = await settleActiveRunForClassic(root, opts, migrations);
2377
+ if (classicGate.kind === 'stop') {
2378
+ return classicGate.exitCode;
2336
2379
  }
2337
2380
  if (!(await confirmNewRunCommits())) {
2381
+ (0, migrate_analytics_1.reportMigrateRunStopped)('declined_commits');
2338
2382
  return;
2339
2383
  }
2340
- const shouldRunValidation = resolveShouldRunValidation({
2341
- validate: opts.validate,
2342
- agenticKind: agentic.kind,
2343
- });
2384
+ // After the prompt, so declining it keeps the run.
2385
+ if (classicGate.replaceRunId !== undefined) {
2386
+ const { deleteRunForStartFresh } = require('./run');
2387
+ deleteRunForStartFresh(root, classicGate.replaceRunId);
2388
+ }
2344
2389
  output_1.output.log({
2345
2390
  title: `Running migrations from '${opts.runMigrations}'` +
2346
2391
  (effectiveCreateCommits
@@ -2350,18 +2395,7 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2350
2395
  if (effectiveCreateCommits) {
2351
2396
  (0, migrate_commits_1.commitCheckpointBeforeMigrations)(root, commitPrefix);
2352
2397
  }
2353
- if (agentic.kind === 'enabled') {
2354
- const { applyAgenticHandoffGitignoreFallback } = require('./agentic/handoff-gitignore');
2355
- const { packageJson: nxPackageJson } = (0, package_json_1.readModulePackageJson)('nx', (0, installation_directory_1.getNxRequirePaths)(root));
2356
- await applyAgenticHandoffGitignoreFallback({
2357
- migrations,
2358
- installedNxVersion: nxPackageJson.version,
2359
- effectiveCreateCommits,
2360
- commitPrefix,
2361
- root,
2362
- });
2363
- }
2364
- const { migrationsWithNoChanges, skippedPromptsCount, notRunMigrationsCount, skippedPrompts, migrationEmittedNextSteps, committedShasCount, waivedAgenticStepsCount, retainedAtSuccess, } = await executeMigrations(root, migrations, isVerbose, effectiveCreateCommits, commitPrefix, shouldSkipInstall, agentic, agenticHasDiffContext, shouldRunValidation);
2398
+ const { migrationsWithNoChanges, skippedPromptsCount, notRunMigrationsCount, skippedPrompts, migrationEmittedNextSteps, committedShasCount, waivedAgenticStepsCount, retainedAtSuccess, } = await executeMigrations(root, migrations, isVerbose, effectiveCreateCommits, commitPrefix, shouldSkipInstall, agentic);
2365
2399
  const ranWithChangesCount = migrations.length - notRunMigrationsCount - migrationsWithNoChanges.length;
2366
2400
  // The "applied" tally counts fully-completed migrations — those that
2367
2401
  // left no deferred work behind. Hybrid migrations whose prompt half was
@@ -2391,9 +2425,13 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2391
2425
  ? 'Finished running migrations with uncommitted state retained'
2392
2426
  : 'Successfully finished running migrations';
2393
2427
  if (notRunMigrationsCount === migrations.length && migrations.length > 0) {
2428
+ // Under WASM or with ids orchestration refuses, an --agentic re-run lands
2429
+ // here again.
2394
2430
  const remediation = insideAgent
2395
2431
  ? 'The AI agent driving this run should apply each prompt — see next steps below.'
2396
- : 'Re-run with --agentic to apply them. See next steps below.';
2432
+ : native_1.IS_WASM || idProblems.length > 0
2433
+ ? 'Apply each prompt yourself. See next steps below.'
2434
+ : 'Re-run with --agentic to apply them. See next steps below.';
2397
2435
  output_1.output.warn({
2398
2436
  title: `No migrations from '${opts.runMigrations}' were applied — every entry is a prompt-only migration. ${remediation}`,
2399
2437
  bodyLines: tallyBody,
@@ -2449,7 +2487,6 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2449
2487
  }
2450
2488
  (0, migrate_analytics_1.reportMigrateRunComplete)({
2451
2489
  agenticOutcome: agentic.kind,
2452
- agentUsed: agentic.kind === 'enabled' ? agentic.selectedAgent.id : undefined,
2453
2490
  migrationCount: migrations.length,
2454
2491
  appliedCount,
2455
2492
  });
@@ -2727,6 +2764,10 @@ async function runSingleMigrationFromCli(root, opts, args, mergedArgs) {
2727
2764
  if (opts.runId === undefined &&
2728
2765
  !shouldSkipInstall &&
2729
2766
  !process.env.NX_MIGRATE_SKIP_INSTALL) {
2767
+ // The worker's refusals come after the install, which would act on the
2768
+ // in-progress edits of a run another process works on.
2769
+ const { checkRunsForSingleMigration } = require('./run');
2770
+ checkRunsForSingleMigration(root);
2730
2771
  await (0, execute_migration_1.runInstall)(undefined, 'pre-migration', (0, execute_migration_1.formatSingleMigrationRerunCommand)(opts.runMigration));
2731
2772
  }
2732
2773
  if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
@@ -2748,7 +2789,7 @@ async function runSingleMigrationFromCli(root, opts, args, mergedArgs) {
2748
2789
  // Lazy-load run/ so plain migrate and repair runs don't pay for the agentic
2749
2790
  // selection chain its barrel pulls in eagerly.
2750
2791
  const { runSingleMigrationWorker } = require('./run');
2751
- await runSingleMigrationWorker({
2792
+ return await runSingleMigrationWorker({
2752
2793
  root,
2753
2794
  runMigration: opts.runMigration,
2754
2795
  runId: opts.runId,
@@ -2834,45 +2875,6 @@ async function runMigration() {
2834
2875
  return runLocalMigrate();
2835
2876
  });
2836
2877
  }
2837
- /**
2838
- * Resolves a migration's collection once and derives everything the run loop
2839
- * needs from that single read: the implementation context (`collection` +
2840
- * `collectionPath`, handed to `runNxOrAngularMigration`) and, for agentic runs,
2841
- * the workspace-relative documentation path handed to the agent.
2842
- *
2843
- * Read fresh per migration (not cached across the loop) so a prior migration's
2844
- * reinstall is reflected, exactly as before. Error handling matches each field's
2845
- * role:
2846
- * - Migrations that run an implementation REQUIRE the collection; an unreadable
2847
- * collection throws and aborts that migration (caught by the run loop).
2848
- * - Prompt-only migrations don't run an implementation, so the collection is
2849
- * read only to resolve documentation - a failure there is non-fatal: the
2850
- * prompt still runs and the supplementary doc is skipped with a warning.
2851
- */
2852
- function resolveMigrationForRun(root, migration, resolveDocumentation) {
2853
- let resolvedCollection;
2854
- if (!(0, migration_shape_1.isPromptOnlyMigration)(migration)) {
2855
- resolvedCollection = (0, execute_migration_1.readMigrationCollection)(migration.package, root);
2856
- }
2857
- else if (resolveDocumentation && migration.documentation) {
2858
- try {
2859
- resolvedCollection = (0, execute_migration_1.readMigrationCollection)(migration.package, root);
2860
- }
2861
- catch {
2862
- // Non-fatal: documentation is supplementary; the warning below fires.
2863
- }
2864
- }
2865
- let documentationPath;
2866
- if (resolveDocumentation && migration.documentation) {
2867
- documentationPath = resolvedCollection
2868
- ? (0, execute_migration_1.resolveDocumentationFileToWorkspacePath)(root, (0, path_1.dirname)(resolvedCollection.collectionPath), migration.documentation)
2869
- : undefined;
2870
- if (!documentationPath) {
2871
- logger_1.logger.warn(`Could not resolve the "documentation" file "${migration.documentation}" declared for migration "${migration.package}: ${migration.name}". It will be skipped as additional context for the AI agent.`);
2872
- }
2873
- }
2874
- return { resolvedCollection, documentationPath };
2875
- }
2876
2878
  async function nxCliPath(nxWorkspaceRoot) {
2877
2879
  const version = process.env.NX_MIGRATE_CLI_VERSION || 'latest';
2878
2880
  const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';