@ohos-ports/nx 23.2.1-beta.1 → 23.3.0-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 (351) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/init-local.js +7 -1
  3. package/dist/nx-cloud-internals.d.ts +1 -0
  4. package/dist/nx-cloud-internals.js +9 -0
  5. package/dist/plugins/package-json.js +1 -1
  6. package/dist/src/command-line/add/add.js +5 -1
  7. package/dist/src/command-line/affected/affected.js +70 -9
  8. package/dist/src/command-line/affected/command-object.js +1 -1
  9. package/dist/src/command-line/format/format.js +2 -18
  10. package/dist/src/command-line/graph/graph.d.ts +31 -0
  11. package/dist/src/command-line/graph/graph.js +113 -20
  12. package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +0 -3
  13. package/dist/src/command-line/init/implementation/add-nx-to-nest.js +0 -3
  14. package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +0 -3
  15. package/dist/src/command-line/init/implementation/angular/index.js +0 -3
  16. package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +0 -3
  17. package/dist/src/command-line/init/implementation/format.js +2 -3
  18. package/dist/src/command-line/init/implementation/utils.d.ts +0 -1
  19. package/dist/src/command-line/init/implementation/utils.js +6 -9
  20. package/dist/src/command-line/init/init-v2.js +0 -3
  21. package/dist/src/command-line/migrate/agentic/capture-generator-output.d.ts +25 -0
  22. package/dist/src/command-line/migrate/agentic/capture-generator-output.js +121 -5
  23. package/dist/src/command-line/migrate/agentic/close-agent-session.d.ts +21 -0
  24. package/dist/src/command-line/migrate/agentic/close-agent-session.js +126 -0
  25. package/dist/src/command-line/migrate/agentic/definitions.d.ts +24 -0
  26. package/dist/src/command-line/migrate/agentic/definitions.js +79 -20
  27. package/dist/src/command-line/migrate/agentic/format-command.d.ts +14 -0
  28. package/dist/src/command-line/migrate/agentic/format-command.js +44 -0
  29. package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +3 -3
  30. package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +3 -3
  31. package/dist/src/command-line/migrate/agentic/handoff.d.ts +50 -17
  32. package/dist/src/command-line/migrate/agentic/handoff.js +166 -24
  33. package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +23 -0
  34. package/dist/src/command-line/migrate/agentic/instruction-files.js +41 -0
  35. package/dist/src/command-line/migrate/agentic/master/invocations.d.ts +12 -0
  36. package/dist/src/command-line/migrate/agentic/master/invocations.js +54 -0
  37. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +16 -0
  38. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +175 -0
  39. package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +31 -0
  40. package/dist/src/command-line/migrate/agentic/master/spawn-master.js +222 -0
  41. package/dist/src/command-line/migrate/agentic/prompts/final-validation.d.ts +13 -0
  42. package/dist/src/command-line/migrate/agentic/prompts/final-validation.js +41 -0
  43. package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +17 -0
  44. package/dist/src/command-line/migrate/agentic/prompts/fragments.js +90 -0
  45. package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +4 -3
  46. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +25 -1
  47. package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +57 -34
  48. package/dist/src/command-line/migrate/agentic/run-step.js +28 -4
  49. package/dist/src/command-line/migrate/agentic/runner.d.ts +3 -15
  50. package/dist/src/command-line/migrate/agentic/runner.js +57 -239
  51. package/dist/src/command-line/migrate/agentic/terminal-repair.d.ts +1 -0
  52. package/dist/src/command-line/migrate/agentic/terminal-repair.js +27 -0
  53. package/dist/src/command-line/migrate/agentic/types.d.ts +23 -8
  54. package/dist/src/command-line/migrate/agentic/types.js +10 -7
  55. package/dist/src/command-line/migrate/agentic/windows-cmd.d.ts +33 -0
  56. package/dist/src/command-line/migrate/agentic/windows-cmd.js +88 -0
  57. package/dist/src/command-line/migrate/command-object.d.ts +2 -0
  58. package/dist/src/command-line/migrate/command-object.js +11 -1
  59. package/dist/src/command-line/migrate/deferred-output.d.ts +44 -0
  60. package/dist/src/command-line/migrate/deferred-output.js +92 -0
  61. package/dist/src/command-line/migrate/execute-migration.d.ts +9 -3
  62. package/dist/src/command-line/migrate/execute-migration.js +53 -16
  63. package/dist/src/command-line/migrate/migrate-analytics.d.ts +34 -9
  64. package/dist/src/command-line/migrate/migrate-analytics.js +71 -10
  65. package/dist/src/command-line/migrate/migrate-commits.d.ts +5 -4
  66. package/dist/src/command-line/migrate/migrate-commits.js +16 -6
  67. package/dist/src/command-line/migrate/migrate-config.d.ts +5 -2
  68. package/dist/src/command-line/migrate/migrate-config.js +19 -11
  69. package/dist/src/command-line/migrate/migrate-output.d.ts +3 -7
  70. package/dist/src/command-line/migrate/migrate-output.js +3 -7
  71. package/dist/src/command-line/migrate/migrate.d.ts +3 -0
  72. package/dist/src/command-line/migrate/migrate.js +183 -46
  73. package/dist/src/command-line/migrate/resolve-package-version.js +2 -19
  74. package/dist/src/command-line/migrate/run/agent-output.d.ts +11 -0
  75. package/dist/src/command-line/migrate/run/agent-output.js +21 -2
  76. package/dist/src/command-line/migrate/run/agent-work-payload.d.ts +37 -0
  77. package/dist/src/command-line/migrate/run/agent-work-payload.js +156 -0
  78. package/dist/src/command-line/migrate/run/atomic-write.d.ts +8 -0
  79. package/dist/src/command-line/migrate/run/atomic-write.js +17 -0
  80. package/dist/src/command-line/migrate/run/broker.d.ts +150 -0
  81. package/dist/src/command-line/migrate/run/broker.js +568 -0
  82. package/dist/src/command-line/migrate/run/clean-retry.d.ts +12 -0
  83. package/dist/src/command-line/migrate/run/clean-retry.js +99 -0
  84. package/dist/src/command-line/migrate/run/existing-run-report.d.ts +55 -0
  85. package/dist/src/command-line/migrate/run/existing-run-report.js +227 -0
  86. package/dist/src/command-line/migrate/run/give-up.d.ts +41 -0
  87. package/dist/src/command-line/migrate/run/give-up.js +148 -0
  88. package/dist/src/command-line/migrate/run/index.d.ts +9 -6
  89. package/dist/src/command-line/migrate/run/index.js +21 -2
  90. package/dist/src/command-line/migrate/run/issues.d.ts +127 -0
  91. package/dist/src/command-line/migrate/run/issues.js +1121 -0
  92. package/dist/src/command-line/migrate/run/orchestrator.d.ts +59 -1
  93. package/dist/src/command-line/migrate/run/orchestrator.js +1529 -457
  94. package/dist/src/command-line/migrate/run/run-id.d.ts +0 -8
  95. package/dist/src/command-line/migrate/run/run-id.js +0 -30
  96. package/dist/src/command-line/migrate/run/run-state.d.ts +77 -17
  97. package/dist/src/command-line/migrate/run/run-state.js +263 -32
  98. package/dist/src/command-line/migrate/run/runbook.d.ts +18 -0
  99. package/dist/src/command-line/migrate/run/runbook.js +118 -0
  100. package/dist/src/command-line/migrate/run/state-lock.d.ts +33 -2
  101. package/dist/src/command-line/migrate/run/state-lock.js +128 -2
  102. package/dist/src/command-line/migrate/run/state-machine.d.ts +50 -1
  103. package/dist/src/command-line/migrate/run/state-machine.js +339 -26
  104. package/dist/src/command-line/migrate/run/util.d.ts +3 -1
  105. package/dist/src/command-line/migrate/run/util.js +24 -3
  106. package/dist/src/command-line/migrate/run/worker.js +290 -129
  107. package/dist/src/command-line/migrate/step-actions.d.ts +1 -1
  108. package/dist/src/command-line/migrate/step-actions.js +7 -1
  109. package/dist/src/command-line/migrate/text.d.ts +6 -0
  110. package/dist/src/command-line/migrate/text.js +25 -0
  111. package/dist/src/command-line/migrate/version-skew-guard.js +2 -0
  112. package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +5 -11
  113. package/dist/src/command-line/release/publish.js +11 -8
  114. package/dist/src/command-line/release/utils/get-touched-projects-for-group.js +3 -3
  115. package/dist/src/command-line/release/utils/release-graph.js +1 -1
  116. package/dist/src/command-line/release/utils/remote-release-clients/github.js +5 -8
  117. package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +3 -3
  118. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +4 -2
  119. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +37 -3
  120. package/dist/src/command-line/release/version/version-actions.d.ts +3 -0
  121. package/dist/src/command-line/reset/reset.js +10 -4
  122. package/dist/src/command-line/run/run-one.js +5 -1
  123. package/dist/src/command-line/run-many/run-many.js +6 -12
  124. package/dist/src/command-line/show/command-object.js +1 -1
  125. package/dist/src/command-line/show/projects.js +52 -1
  126. package/dist/src/command-line/yargs-utils/shared-options.d.ts +5 -1
  127. package/dist/src/command-line/yargs-utils/shared-options.js +38 -4
  128. package/dist/src/config/task-graph.d.ts +1 -1
  129. package/dist/src/config/workspace-json-project-json.d.ts +23 -1
  130. package/dist/src/core/graph/main.js +1 -1
  131. package/dist/src/core/graph/runtime.js +1 -1
  132. package/dist/src/core/graph/styles.js +1 -1
  133. package/dist/src/daemon/client/client.d.ts +14 -8
  134. package/dist/src/daemon/client/client.js +41 -12
  135. package/dist/src/daemon/message-types/get-plugin-capabilities.d.ts +5 -0
  136. package/dist/src/daemon/message-types/get-plugin-capabilities.js +11 -0
  137. package/dist/src/daemon/message-types/run-tasks-execution-hooks.d.ts +3 -2
  138. package/dist/src/daemon/message-types/select-affected-tasks.d.ts +21 -0
  139. package/dist/src/daemon/message-types/select-affected-tasks.js +11 -0
  140. package/dist/src/daemon/message-types/ultracache-configuration-version.d.ts +8 -0
  141. package/dist/src/daemon/message-types/ultracache-configuration-version.js +2 -0
  142. package/dist/src/daemon/server/dotenv-graph-changes.d.ts +1 -1
  143. package/dist/src/daemon/server/dotenv-graph-changes.js +2 -2
  144. package/dist/src/daemon/server/handle-get-plugin-capabilities.d.ts +2 -0
  145. package/dist/src/daemon/server/handle-get-plugin-capabilities.js +13 -0
  146. package/dist/src/daemon/server/handle-hash-tasks.d.ts +10 -2
  147. package/dist/src/daemon/server/handle-hash-tasks.js +18 -3
  148. package/dist/src/daemon/server/handle-select-affected-tasks.d.ts +3 -0
  149. package/dist/src/daemon/server/handle-select-affected-tasks.js +26 -0
  150. package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +3 -2
  151. package/dist/src/daemon/server/{handle-outputs-changes.d.ts → handle-watch-events.d.ts} +4 -4
  152. package/dist/src/daemon/server/{handle-outputs-changes.js → handle-watch-events.js} +36 -37
  153. package/dist/src/daemon/server/outputs-tracking.d.ts +7 -19
  154. package/dist/src/daemon/server/outputs-tracking.js +7 -107
  155. package/dist/src/daemon/server/planning-context.d.ts +8 -0
  156. package/dist/src/daemon/server/planning-context.js +18 -0
  157. package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +22 -7
  158. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +104 -74
  159. package/dist/src/daemon/server/restart-checks.d.ts +22 -0
  160. package/dist/src/daemon/server/restart-checks.js +77 -0
  161. package/dist/src/daemon/server/server.d.ts +1 -0
  162. package/dist/src/daemon/server/server.js +54 -30
  163. package/dist/src/daemon/server/shutdown-utils.d.ts +0 -5
  164. package/dist/src/daemon/server/shutdown-utils.js +3 -26
  165. package/dist/src/daemon/server/ultracache-configuration-state.d.ts +7 -0
  166. package/dist/src/daemon/server/ultracache-configuration-state.js +36 -0
  167. package/dist/src/devkit-internals.d.ts +3 -1
  168. package/dist/src/devkit-internals.js +8 -3
  169. package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -1
  170. package/dist/src/executors/run-commands/run-commands.impl.js +19 -5
  171. package/dist/src/executors/run-commands/running-tasks.d.ts +5 -4
  172. package/dist/src/executors/run-commands/running-tasks.js +13 -13
  173. package/dist/src/hasher/create-task-hasher.d.ts +8 -1
  174. package/dist/src/hasher/create-task-hasher.js +13 -3
  175. package/dist/src/hasher/hash-plan-inspector.js +2 -2
  176. package/dist/src/hasher/hash-task.d.ts +2 -2
  177. package/dist/src/hasher/hash-task.js +28 -17
  178. package/dist/src/hasher/native-task-hasher-impl.d.ts +20 -4
  179. package/dist/src/hasher/native-task-hasher-impl.js +75 -9
  180. package/dist/src/hasher/task-hasher.d.ts +24 -7
  181. package/dist/src/hasher/task-hasher.js +27 -8
  182. package/dist/src/hasher/task-planning-context.d.ts +13 -0
  183. package/dist/src/hasher/task-planning-context.js +12 -0
  184. package/dist/src/native/index.d.ts +582 -21
  185. package/dist/src/native/index.js +3 -5
  186. package/dist/src/native/native-bindings.js +13 -1
  187. package/dist/src/native/nx.openharmony-arm64.node +0 -0
  188. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  189. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  190. package/dist/src/native/transform-objects.d.ts +11 -2
  191. package/dist/src/native/transform-objects.js +46 -0
  192. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +15 -8
  193. package/dist/src/nx-cloud/update-manager.d.ts +3 -0
  194. package/dist/src/nx-cloud/update-manager.js +19 -13
  195. package/dist/src/nx-cloud/utilities/client.d.ts +1 -1
  196. package/dist/src/nx-cloud/utilities/client.js +1 -1
  197. package/dist/src/nx-cloud/utilities/is-workspace-claimed.js +2 -1
  198. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.d.ts +5 -0
  199. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.js +16 -0
  200. package/dist/src/nx-cloud/utilities/url-shorten.js +17 -10
  201. package/dist/src/plugins/js/index.js +45 -64
  202. package/dist/src/plugins/js/lock-file/lock-file.d.ts +4 -4
  203. package/dist/src/plugins/js/lock-file/lock-file.js +6 -7
  204. package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -1
  205. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +2 -0
  206. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +22 -0
  207. package/dist/src/plugins/js/project-graph/affected/lock-file-changes.d.ts +10 -2
  208. package/dist/src/plugins/js/project-graph/affected/lock-file-changes.js +51 -29
  209. package/dist/src/plugins/js/project-graph/affected/npm-packages.d.ts +10 -2
  210. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +32 -11
  211. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +22 -18
  212. package/dist/src/plugins/js/utils/register.js +13 -4
  213. package/dist/src/plugins/package-json/create-nodes.d.ts +2 -2
  214. package/dist/src/plugins/package-json/create-nodes.js +13 -13
  215. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +14 -0
  216. package/dist/src/project-graph/affected/affected-project-graph.js +5 -18
  217. package/dist/src/project-graph/affected/affected-projects.d.ts +7 -0
  218. package/dist/src/project-graph/affected/affected-projects.js +42 -0
  219. package/dist/src/project-graph/affected/affected-reasons.d.ts +116 -0
  220. package/dist/src/project-graph/affected/affected-reasons.js +459 -0
  221. package/dist/src/project-graph/affected/affected-tasks.d.ts +103 -0
  222. package/dist/src/project-graph/affected/affected-tasks.js +386 -0
  223. package/dist/src/project-graph/affected/print-explanation.d.ts +11 -0
  224. package/dist/src/project-graph/affected/print-explanation.js +44 -0
  225. package/dist/src/project-graph/error-types.d.ts +5 -0
  226. package/dist/src/project-graph/error-types.js +44 -5
  227. package/dist/src/project-graph/file-utils.d.ts +2 -0
  228. package/dist/src/project-graph/file-utils.js +12 -3
  229. package/dist/src/project-graph/nx-deps-cache.d.ts +5 -2
  230. package/dist/src/project-graph/nx-deps-cache.js +4 -4
  231. package/dist/src/project-graph/plugins/get-plugins.d.ts +3 -1
  232. package/dist/src/project-graph/plugins/get-plugins.js +60 -82
  233. package/dist/src/project-graph/plugins/in-process-loader.d.ts +1 -1
  234. package/dist/src/project-graph/plugins/in-process-loader.js +1 -4
  235. package/dist/src/project-graph/plugins/isolation/index.d.ts +1 -1
  236. package/dist/src/project-graph/plugins/isolation/index.js +3 -1
  237. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +8 -0
  238. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +42 -6
  239. package/dist/src/project-graph/plugins/isolation/load-isolated-plugin.d.ts +10 -1
  240. package/dist/src/project-graph/plugins/isolation/load-isolated-plugin.js +67 -17
  241. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +3 -2
  242. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +5 -1
  243. package/dist/src/project-graph/plugins/loaded-nx-plugin.d.ts +5 -2
  244. package/dist/src/project-graph/plugins/loaded-nx-plugin.js +14 -1
  245. package/dist/src/project-graph/plugins/nx-plugin-capabilities.d.ts +6 -0
  246. package/dist/src/project-graph/plugins/nx-plugin-capabilities.js +28 -0
  247. package/dist/src/project-graph/plugins/task-results-stub.d.ts +50 -0
  248. package/dist/src/project-graph/plugins/task-results-stub.js +111 -0
  249. package/dist/src/project-graph/plugins/tasks-execution-hooks.d.ts +3 -2
  250. package/dist/src/project-graph/plugins/tasks-execution-hooks.js +14 -1
  251. package/dist/src/project-graph/project-graph.js +43 -42
  252. package/dist/src/project-graph/utils/project-configuration/target-merging.js +67 -0
  253. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +83 -0
  254. package/dist/src/project-graph/utils/project-configuration/utils.d.ts +1 -0
  255. package/dist/src/project-graph/utils/project-configuration/utils.js +1 -0
  256. package/dist/src/tasks-runner/batch/run-batch.js +15 -0
  257. package/dist/src/tasks-runner/cache.d.ts +37 -2
  258. package/dist/src/tasks-runner/cache.js +42 -1
  259. package/dist/src/tasks-runner/create-task-graph.d.ts +24 -1
  260. package/dist/src/tasks-runner/create-task-graph.js +57 -2
  261. package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
  262. package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
  263. package/dist/src/tasks-runner/forked-process-task-runner.js +11 -10
  264. package/dist/src/tasks-runner/init-tasks-runner.d.ts +7 -2
  265. package/dist/src/tasks-runner/init-tasks-runner.js +15 -7
  266. package/dist/src/tasks-runner/is-tui-enabled.js +4 -3
  267. package/dist/src/tasks-runner/life-cycle.d.ts +7 -0
  268. package/dist/src/tasks-runner/life-cycle.js +7 -0
  269. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.d.ts +35 -0
  270. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +146 -0
  271. package/dist/src/tasks-runner/prune-task-graph.d.ts +17 -0
  272. package/dist/src/tasks-runner/prune-task-graph.js +45 -0
  273. package/dist/src/tasks-runner/run-command.d.ts +41 -5
  274. package/dist/src/tasks-runner/run-command.js +98 -22
  275. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +93 -19
  276. package/dist/src/tasks-runner/running-tasks/batch-process.js +184 -88
  277. package/dist/src/tasks-runner/task-io-service.d.ts +11 -3
  278. package/dist/src/tasks-runner/task-io-service.js +14 -5
  279. package/dist/src/tasks-runner/task-orchestrator.d.ts +71 -4
  280. package/dist/src/tasks-runner/task-orchestrator.js +266 -66
  281. package/dist/src/tasks-runner/tasks-runner.d.ts +2 -0
  282. package/dist/src/tasks-runner/terminal-output-path.d.ts +11 -0
  283. package/dist/src/tasks-runner/terminal-output-path.js +18 -0
  284. package/dist/src/tasks-runner/utils.d.ts +5 -0
  285. package/dist/src/tasks-runner/utils.js +14 -2
  286. package/dist/src/ultracache/config.d.ts +21 -0
  287. package/dist/src/ultracache/config.js +29 -0
  288. package/dist/src/ultracache/fetch.d.ts +21 -0
  289. package/dist/src/ultracache/fetch.js +43 -0
  290. package/dist/src/ultracache/overrides.d.ts +17 -0
  291. package/dist/src/ultracache/overrides.js +61 -0
  292. package/dist/src/ultracache/report.d.ts +13 -0
  293. package/dist/src/ultracache/report.js +62 -0
  294. package/dist/src/ultracache/store.d.ts +41 -0
  295. package/dist/src/ultracache/store.js +158 -0
  296. package/dist/src/utils/ab-testing.d.ts +4 -1
  297. package/dist/src/utils/ab-testing.js +22 -19
  298. package/dist/src/utils/chunkify.d.ts +1 -7
  299. package/dist/src/utils/chunkify.js +2 -8
  300. package/dist/src/utils/command-line-utils.d.ts +20 -0
  301. package/dist/src/utils/command-line-utils.js +10 -3
  302. package/dist/src/utils/create-cli-options.d.ts +6 -0
  303. package/dist/src/utils/create-cli-options.js +29 -0
  304. package/dist/src/utils/db-connection.d.ts +2 -0
  305. package/dist/src/utils/db-connection.js +2 -0
  306. package/dist/src/utils/formatters/index.d.ts +6 -0
  307. package/dist/src/utils/formatters/index.js +5 -0
  308. package/dist/src/utils/formatters/prettier.d.ts +0 -8
  309. package/dist/src/utils/formatters/prettier.js +4 -26
  310. package/dist/src/utils/git-utils.d.ts +19 -0
  311. package/dist/src/utils/git-utils.js +97 -39
  312. package/dist/src/utils/handle-errors.js +5 -43
  313. package/dist/src/utils/http-client.d.ts +27 -0
  314. package/dist/src/utils/http-client.js +193 -0
  315. package/dist/src/utils/installed-nx-version.js +2 -48
  316. package/dist/src/utils/json-diff.d.ts +4 -2
  317. package/dist/src/utils/json-diff.js +6 -94
  318. package/dist/src/utils/min-release-age/packument.js +1 -1
  319. package/dist/src/utils/nx-cloud-utils.d.ts +2 -0
  320. package/dist/src/utils/nx-cloud-utils.js +6 -1
  321. package/dist/src/utils/output.d.ts +22 -3
  322. package/dist/src/utils/output.js +28 -5
  323. package/dist/src/utils/package-json.d.ts +25 -0
  324. package/dist/src/utils/package-json.js +49 -6
  325. package/dist/src/utils/package-manager.d.ts +6 -0
  326. package/dist/src/utils/package-manager.js +10 -0
  327. package/dist/src/utils/plugins/plugin-capabilities.js +7 -2
  328. package/dist/src/utils/project-graph-utils.d.ts +2 -0
  329. package/dist/src/utils/project-graph-utils.js +12 -0
  330. package/dist/src/utils/provenance.js +20 -4
  331. package/dist/src/utils/serialize-overrides-into-command-line.js +2 -4
  332. package/dist/src/utils/workspace-context.d.ts +51 -3
  333. package/dist/src/utils/workspace-context.js +174 -10
  334. package/package.json +31 -48
  335. package/readme-template.md +16 -0
  336. package/schemas/nx-schema.json +38 -0
  337. package/schemas/project-schema.json +35 -0
  338. package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +0 -9
  339. package/dist/src/daemon/server/file-watching/route-workspace-changes.js +0 -76
  340. package/dist/src/daemon/server/watcher.d.ts +0 -18
  341. package/dist/src/daemon/server/watcher.js +0 -126
  342. package/dist/src/nx-cloud/utilities/axios.d.ts +0 -4
  343. package/dist/src/nx-cloud/utilities/axios.js +0 -17
  344. package/dist/src/project-graph/affected/locators/project-glob-changes.d.ts +0 -2
  345. package/dist/src/project-graph/affected/locators/project-glob-changes.js +0 -47
  346. package/dist/src/project-graph/affected/locators/workspace-json-changes.d.ts +0 -4
  347. package/dist/src/project-graph/affected/locators/workspace-json-changes.js +0 -47
  348. package/dist/src/project-graph/affected/locators/workspace-projects.d.ts +0 -3
  349. package/dist/src/project-graph/affected/locators/workspace-projects.js +0 -74
  350. package/dist/src/utils/collapse-expanded-outputs.d.ts +0 -10
  351. package/dist/src/utils/collapse-expanded-outputs.js +0 -72
@@ -30,6 +30,7 @@ const tar_1 = require("../../utils/tar");
30
30
  const write_formatted_json_file_1 = require("../../utils/write-formatted-json-file");
31
31
  const shell_quoting_1 = require("../../utils/shell-quoting");
32
32
  const logger_1 = require("../../utils/logger");
33
+ const native_1 = require("../../native");
33
34
  const git_utils_1 = require("../../utils/git-utils");
34
35
  const package_json_1 = require("../../utils/package-json");
35
36
  const package_manager_1 = require("../../utils/package-manager");
@@ -709,13 +710,24 @@ async function parseTargetPackageAndVersion(args) {
709
710
  async function parseMigrationsOptions(options, fetch) {
710
711
  // A run recorded or reconciled via `--run-id` is driven by the outer agent;
711
712
  // spawning another agent from it would double-drive the run. Only the
712
- // explicit "on" values conflict; the nx.json default is ignored for
713
- // `--run-id` invocations instead.
713
+ // explicit "on" values conflict; the nx.json default is not applied to
714
+ // those invocations instead. The `--run-migrations` shape is the
715
+ // exception: there `--run-id` names the run a continue re-enters, or the
716
+ // one a `--start-fresh` replaces.
714
717
  if (options.runId !== undefined &&
715
718
  options.agentic !== undefined &&
716
- options.agentic !== false) {
719
+ options.agentic !== false &&
720
+ options.runMigrations === undefined) {
717
721
  throw new Error(`Error: '--agentic' cannot be combined with '--run-id'.`);
718
722
  }
723
+ if (options.startFresh === true) {
724
+ if (options.runMigrations === undefined) {
725
+ throw new Error(`Error: '--start-fresh' requires '--run-migrations'.`);
726
+ }
727
+ if (options.runId === undefined) {
728
+ throw new Error(`Error: '--start-fresh' requires '--run-id=<id>' naming the run to replace; the report prints it.`);
729
+ }
730
+ }
719
731
  if (options.runMigration !== undefined) {
720
732
  if (options.runMigration === '') {
721
733
  throw new Error(`Error: '--run-migration' requires a migration id, e.g. '--run-migration=@nx/js:my-migration'.`);
@@ -754,8 +766,16 @@ async function parseMigrationsOptions(options, fetch) {
754
766
  if (options.runId === '') {
755
767
  throw new Error(`Error: '--run-id' requires the id of the migrate run to record into.`);
756
768
  }
757
- if (options.runMigrations !== undefined) {
758
- throw new Error(`Error: '--run-id' (reconcile an orchestrated run) cannot be combined with '--run-migrations' (run the whole migrations file).`);
769
+ // With `--run-migrations`, `--run-id` continues the named run, which needs
770
+ // `--agentic`; a start-fresh names the run it replaces instead.
771
+ if (options.runMigrations !== undefined &&
772
+ options.startFresh !== true &&
773
+ (options.agentic === undefined || options.agentic === false)) {
774
+ throw new Error(`Error: '--run-id' (reconcile an orchestrated run) cannot be combined with '--run-migrations' (run the whole migrations file). To continue the run, pass '--agentic' (or '--agentic=<agent>') as well.`);
775
+ }
776
+ if (options.runMigrations !== undefined &&
777
+ options.stepAction !== undefined) {
778
+ throw new Error(`Error: '--step-action' cannot be combined with '--run-migrations'.`);
759
779
  }
760
780
  // A bare '--run-id' reconciles the run it names. Ungated, unlike init:
761
781
  // the id has to name a run directory that exists, and only a gated init
@@ -765,13 +785,15 @@ async function parseMigrationsOptions(options, fetch) {
765
785
  if (options.stepAction !== undefined && !(0, step_actions_1.isStepAction)(options.stepAction)) {
766
786
  throw new Error(`Error: '--step-action' must be one of ${step_actions_1.STEP_ACTIONS.join(', ')}.`);
767
787
  }
768
- return {
769
- type: 'orchestratorReconcile',
770
- runId: options.runId,
771
- ...(options.stepAction !== undefined
772
- ? { stepAction: options.stepAction }
773
- : {}),
774
- };
788
+ if (options.runMigrations === undefined) {
789
+ return {
790
+ type: 'orchestratorReconcile',
791
+ runId: options.runId,
792
+ ...(options.stepAction !== undefined
793
+ ? { stepAction: options.stepAction }
794
+ : {}),
795
+ };
796
+ }
775
797
  }
776
798
  if (options.stepAction !== undefined) {
777
799
  throw new Error(`Error: '--step-action' requires '--run-id'.`);
@@ -792,7 +814,10 @@ async function parseMigrationsOptions(options, fetch) {
792
814
  ifExists: options.ifExists,
793
815
  agentic: options.agentic,
794
816
  validate: options.validate,
817
+ finalValidation: options.finalValidation,
795
818
  interactive: options.interactive,
819
+ ...(options.runId !== undefined ? { runId: options.runId } : {}),
820
+ ...(options.startFresh === true ? { startFresh: true } : {}),
796
821
  };
797
822
  }
798
823
  assertOptionalIncludeFlagCompatibility(options);
@@ -1227,7 +1252,7 @@ async function getPackageMigrationsConfigFromRegistry(packageName, packageVersio
1227
1252
  if (!result) {
1228
1253
  return null;
1229
1254
  }
1230
- const json = JSON.parse(result);
1255
+ const json = (0, package_manager_1.parseRegistryViewJson)(result);
1231
1256
  if (!json['nx-migrations'] && !json['ng-update']) {
1232
1257
  const registry = new node_url_1.URL('dist' in json ? json.dist.tarball : json.tarball)
1233
1258
  .hostname;
@@ -2092,6 +2117,9 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
2092
2117
  retainedAtSuccess: (0, migrate_output_1.retainedMigrations)(outcomes).map((p) => `${p.package}: ${p.name}`),
2093
2118
  };
2094
2119
  }
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.`;
2122
+ }
2095
2123
  // nx is located at spawn time, after the gated pre-install, so the child runs
2096
2124
  // the bytes that install put in place.
2097
2125
  function handOffToLocalNx(args) {
@@ -2106,31 +2134,92 @@ function handOffToLocalNx(args) {
2106
2134
  return exitCode !== 0 ? exitCode : undefined;
2107
2135
  }
2108
2136
  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
+ }
2150
+ const isContinue = opts.runId !== undefined && opts.startFresh !== true;
2151
+ let continued;
2152
+ if (isContinue) {
2153
+ // Before the install: a concurrent start-fresh must not delete the run
2154
+ // this command is about to continue.
2155
+ const { holdRunToContinue } = require('./run');
2156
+ continued = holdRunToContinue(root, opts.runId);
2157
+ }
2158
+ else if (opts.startFresh === true) {
2159
+ // Before the install too: with no active run there is nothing to replace.
2160
+ const { activeRunToReplace } = require('./run');
2161
+ activeRunToReplace(root, opts.runId);
2162
+ }
2109
2163
  if (!shouldSkipInstall && !process.env.NX_MIGRATE_SKIP_INSTALL) {
2110
2164
  await (0, execute_migration_1.runInstall)();
2111
2165
  }
2112
2166
  if (!__dirname.startsWith(workspace_root_1.workspaceRoot)) {
2113
2167
  // we are running from a temp installation with nx latest, switch to running
2114
2168
  // from local installation
2169
+ if (isContinue) {
2170
+ // The child holds the run itself and refuses while this process does.
2171
+ const { releaseRunToHandOff } = require('./run');
2172
+ releaseRunToHandOff(root, opts.runId);
2173
+ }
2115
2174
  return handOffToLocalNx(args);
2116
2175
  }
2117
- const migrationsExists = (0, fileutils_1.fileExists)(opts.runMigrations);
2118
- if (opts.ifExists && !migrationsExists) {
2119
- output_1.output.log({
2120
- title: `Migrations file '${opts.runMigrations}' doesn't exist`,
2121
- });
2122
- return;
2176
+ let migrationsJson;
2177
+ if (isContinue) {
2178
+ // A continue runs the plan the run recorded, not whatever the workspace's
2179
+ // migrations file holds now (it may be gone, or belong to another plan).
2180
+ const { latestRound, runDir } = require('./run');
2181
+ const round = latestRound(continued);
2182
+ if (!round) {
2183
+ throw new Error(`Migrate run '${opts.runId}' records no plan.`);
2184
+ }
2185
+ migrationsJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(runDir(root, opts.runId), round.planSnapshot));
2123
2186
  }
2124
- else if (!opts.ifExists && !migrationsExists) {
2125
- throw new Error(`File '${opts.runMigrations}' doesn't exist, can't run migrations. Use flag --if-exists to run migrations only if the file exists`);
2187
+ else {
2188
+ const migrationsExists = (0, fileutils_1.fileExists)(opts.runMigrations);
2189
+ if (opts.ifExists && !migrationsExists) {
2190
+ output_1.output.log({
2191
+ title: `Migrations file '${opts.runMigrations}' doesn't exist`,
2192
+ });
2193
+ return;
2194
+ }
2195
+ else if (!opts.ifExists && !migrationsExists) {
2196
+ throw new Error(`File '${opts.runMigrations}' doesn't exist, can't run migrations. Use flag --if-exists to run migrations only if the file exists`);
2197
+ }
2198
+ migrationsJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, opts.runMigrations));
2126
2199
  }
2127
- const migrationsJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, opts.runMigrations));
2128
2200
  const migrations = migrationsJson.migrations;
2201
+ // Defer the nx package lookup until an orchestrated branch needs this payload.
2202
+ const orchestratorInitInput = (createCommits) => ({
2203
+ root,
2204
+ migrationsJson,
2205
+ migrationsPath: opts.runMigrations,
2206
+ createCommits,
2207
+ commitPrefix,
2208
+ // The flag only, never NX_MIGRATE_SKIP_INSTALL: the wrapper's local
2209
+ // re-exec sets that env var for its own hop, and it says nothing about
2210
+ // what the user asked for.
2211
+ skipInstall: shouldSkipInstall,
2212
+ installedNxVersion: (0, package_json_1.readModulePackageJson)('nx', (0, installation_directory_1.getNxRequirePaths)(root))
2213
+ .packageJson.version,
2214
+ validate: opts.validate,
2215
+ finalValidation: opts.finalValidation,
2216
+ });
2129
2217
  // An outer agent drives the loop, so hand off to the orchestrator instead of
2130
- // the classic loop: init either starts a fresh run or resumes an already-
2131
- // active one. `--run-id` reconciles are dispatched separately and never
2132
- // reach here.
2218
+ // the classic loop: init starts a fresh run or reports an already-active
2219
+ // one; `--run-id` continues that run. Bare `--run-id` reconciles are
2220
+ // dispatched separately and never reach here.
2133
2221
  if (process.env.NX_MIGRATE_ORCHESTRATOR === 'true' && (0, inception_1.isInsideAgent)()) {
2222
+ const { runOrchestratorInit, runOrchestratorResume } = require('./run');
2134
2223
  // Orchestrated runs are agent-driven, so commits default on exactly as they
2135
2224
  // do under `--agentic=enabled`; the orchestrator replaces `resolveAgentic`.
2136
2225
  const { effective: effectiveCreateCommits, warning: createCommitsWarning, error: createCommitsError, } = (0, migrate_commits_1.resolveCreateCommits)({
@@ -2145,26 +2234,50 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2145
2234
  if (createCommitsWarning) {
2146
2235
  output_1.output.warn({ title: createCommitsWarning });
2147
2236
  }
2148
- // The run commits on the user's behalf across many invocations, so the
2149
- // default-branch confirmation belongs here, once, before any of them.
2150
- if (effectiveCreateCommits &&
2151
- (0, safe_prompt_1.canPrompt)(opts.interactive) &&
2152
- !(await (0, migrate_commits_1.confirmMigrationCommitsOnDefaultBranch)(root, 'running migrations'))) {
2237
+ if (isContinue) {
2238
+ runOrchestratorResume({
2239
+ root,
2240
+ runId: opts.runId,
2241
+ policy: {
2242
+ createCommits: effectiveCreateCommits,
2243
+ skipInstall: shouldSkipInstall,
2244
+ },
2245
+ });
2153
2246
  return;
2154
2247
  }
2155
- const { packageJson: orchestratorNxPackageJson } = (0, package_json_1.readModulePackageJson)('nx', (0, installation_directory_1.getNxRequirePaths)(root));
2156
- const { runOrchestratorInit } = require('./run');
2157
- return await runOrchestratorInit({
2158
- root,
2159
- migrationsJson,
2160
- createCommits: effectiveCreateCommits,
2161
- commitPrefix,
2162
- // The flag only, never NX_MIGRATE_SKIP_INSTALL: the wrapper's local
2163
- // re-exec sets that env var for its own hop, and it says nothing about
2164
- // what the user asked for.
2165
- skipInstall: shouldSkipInstall,
2166
- installedNxVersion: orchestratorNxPackageJson.version,
2248
+ // The run commits on the user's behalf across many invocations and the
2249
+ // agent driving it cannot answer a terminal prompt, so a commit policy the
2250
+ // user never asked for stops the run on the default branch before any of
2251
+ // them. `--create-commits` or nx.json `migrate.createCommits` is that ask.
2252
+ // Asked by init only once it is about to start a run: an active run is
2253
+ // reported instead, and keeps its own policy.
2254
+ const refuseCommitsOnDefaultBranch = async () => {
2255
+ if (!effectiveCreateCommits || shouldCreateCommits !== undefined) {
2256
+ return true;
2257
+ }
2258
+ const defaultBranch = (0, migrate_commits_1.currentBranchIfDefault)(root);
2259
+ if (!defaultBranch) {
2260
+ return true;
2261
+ }
2262
+ output_1.output.log({
2263
+ title: `Not starting the run: you are on the default branch '${defaultBranch}' and nx migrate would create a commit for each migration on it.`,
2264
+ bodyLines: [
2265
+ 'Ask the user how to proceed, then either:',
2266
+ '- re-run with --create-commits to commit on this branch for this run,',
2267
+ '- set "migrate": { "createCommits": true } in nx.json to always allow it, then re-run,',
2268
+ '- or switch to another branch and re-run.',
2269
+ ],
2270
+ });
2271
+ return false;
2272
+ };
2273
+ const init = orchestratorInitInput(effectiveCreateCommits);
2274
+ await runOrchestratorInit({
2275
+ ...init,
2276
+ onExistingRun: opts.startFresh === true ? 'start-fresh' : 'report',
2277
+ ...(opts.startFresh === true ? { replaceRunId: opts.runId } : {}),
2278
+ confirmStart: refuseCommitsOnDefaultBranch,
2167
2279
  });
2280
+ return;
2168
2281
  }
2169
2282
  (0, migrate_analytics_1.reportMigrateRunStart)({
2170
2283
  createCommits: shouldCreateCommits ?? false,
@@ -2195,9 +2308,33 @@ async function runMigrations(root, opts, args, isVerbose, shouldCreateCommits, c
2195
2308
  if (createCommitsWarning) {
2196
2309
  output_1.output.warn({ title: createCommitsWarning });
2197
2310
  }
2198
- if (effectiveCreateCommits &&
2199
- (0, safe_prompt_1.canPrompt)(opts.interactive) &&
2200
- !(await (0, migrate_commits_1.confirmMigrationCommitsOnDefaultBranch)(root, 'running migrations'))) {
2311
+ // Asked only for a run this invocation starts: the master session hands it
2312
+ // to init, which asks once it is about to start one; a continued run keeps
2313
+ // the policy it was started with.
2314
+ const confirmNewRunCommits = async () => !effectiveCreateCommits ||
2315
+ !(0, safe_prompt_1.canPrompt)(opts.interactive) ||
2316
+ (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) {
2323
+ const init = orchestratorInitInput(effectiveCreateCommits);
2324
+ const { runMasterSession } = require('./agentic/master/run-master-session');
2325
+ return await runMasterSession({
2326
+ ...init,
2327
+ agent: agentic.selectedAgent,
2328
+ interactive: opts.interactive,
2329
+ runId: opts.runId,
2330
+ startFresh: opts.startFresh,
2331
+ confirmStart: confirmNewRunCommits,
2332
+ });
2333
+ }
2334
+ if (orchestratorFlag !== undefined) {
2335
+ throw new Error(orchestratorFlagNeedsOrchestrator(orchestratorFlag));
2336
+ }
2337
+ if (!(await confirmNewRunCommits())) {
2201
2338
  return;
2202
2339
  }
2203
2340
  const shouldRunValidation = resolveShouldRunValidation({
@@ -2412,7 +2549,7 @@ function stringifyCaught(e) {
2412
2549
  }
2413
2550
  }
2414
2551
  }
2415
- // A resolver-based lookup (including `resolvePackageJsonWithoutCachePollution`,
2552
+ // A resolver-based lookup (including `resolveWithoutCachePollution`,
2416
2553
  // which does defeat Node's package self-reference) is the wrong tool here:
2417
2554
  // resolvers fall back to NODE_PATH after the explicit paths, and NODE_PATH
2418
2555
  // names the temp installation when this runs there. The scan below reads its
@@ -15,6 +15,7 @@ const policy_1 = require("../../utils/min-release-age/policy");
15
15
  const pnpm_exclude_writer_1 = require("../../utils/min-release-age/pnpm-exclude-writer");
16
16
  const resolve_1 = require("../../utils/min-release-age/resolve");
17
17
  const safe_prompt_1 = require("./safe-prompt");
18
+ const text_1 = require("./text");
18
19
  /**
19
20
  * Whether nx migrate should resolve versions via the npm registry (fast) rather
20
21
  * than via a real package-manager install. Precedence, highest first:
@@ -195,7 +196,7 @@ async function handleViolation(packageName, error, policy) {
195
196
  // sorted newest-first, so the resolver's pick is the last entry. Mirror the
196
197
  // loose path: prompt for, exclude, and return that one version.
197
198
  const resolved = error.blocked[error.blocked.length - 1];
198
- const blockedLine = ` ${packageName}@${resolved.version} (published ${formatPublishAge(resolved.publishedAt)})`;
199
+ const blockedLine = ` ${packageName}@${resolved.version} (published ${(0, text_1.formatAge)(resolved.publishedAt)})`;
199
200
  // pnpm prompts once for the whole run; remember an approval for later picks.
200
201
  if (!strictApprovalGranted) {
201
202
  const approved = await (0, safe_prompt_1.migrateConfirm)({
@@ -225,21 +226,3 @@ async function handleViolation(packageName, error, policy) {
225
226
  ]);
226
227
  return resolved.version;
227
228
  }
228
- // Renders a registry ISO publish timestamp as a human age for the strict prompt
229
- // (e.g. "6 hours ago"), falling back to the raw value when it is not parseable.
230
- function formatPublishAge(publishedAt) {
231
- const elapsedMs = Date.now() - Date.parse(publishedAt);
232
- if (!Number.isFinite(elapsedMs) || elapsedMs < 0) {
233
- return publishedAt;
234
- }
235
- const minutes = Math.floor(elapsedMs / 60_000);
236
- if (minutes < 60) {
237
- return `${minutes} minute${minutes === 1 ? '' : 's'} ago`;
238
- }
239
- const hours = Math.floor(elapsedMs / 3_600_000);
240
- if (hours < 48) {
241
- return `${hours} hour${hours === 1 ? '' : 's'} ago`;
242
- }
243
- const days = Math.floor(elapsedMs / 86_400_000);
244
- return `${days} day${days === 1 ? '' : 's'} ago`;
245
- }
@@ -18,3 +18,14 @@ export declare function logToAgent(message: AgentMessage): void;
18
18
  export declare function warnToAgent(message: AgentMessage): void;
19
19
  export declare function emitStepBlock(runId: string, stepId: string, action: string, payload: object): void;
20
20
  export declare function emitPromptBlock(migrationId: string, payload: object): void;
21
+ export declare function emitStepPromptBlock(stepId: string, payload: object): void;
22
+ /**
23
+ * Markdown, not JSON: the block carries the runbook file's bytes, so the agent
24
+ * reads what a resume re-emits from disk. Every `<` opening or closing an
25
+ * `<nx_migrate_*>` tag is neutralized wherever it sits: a positional check
26
+ * (line starts plus a blank-character class) can be sidestepped by characters
27
+ * that render as nothing but match no enumerable class. The renderer never
28
+ * emits the literal sequence (runbook.spec pins that), so only tampered bytes
29
+ * change.
30
+ */
31
+ export declare function emitRunbookBlock(runId: string, content: string): void;
@@ -15,6 +15,8 @@ exports.logToAgent = logToAgent;
15
15
  exports.warnToAgent = warnToAgent;
16
16
  exports.emitStepBlock = emitStepBlock;
17
17
  exports.emitPromptBlock = emitPromptBlock;
18
+ exports.emitStepPromptBlock = emitStepPromptBlock;
19
+ exports.emitRunbookBlock = emitRunbookBlock;
18
20
  const output_1 = require("../../../utils/output");
19
21
  const print_dropped_agent_context_1 = require("../agentic/print-dropped-agent-context");
20
22
  const text_1 = require("../text");
@@ -47,11 +49,11 @@ function blockPayload(payload) {
47
49
  return JSON.stringify(payload, null, 2).replace(/</g, '\\u003c');
48
50
  }
49
51
  // A bare newline pair frames the block so adjacent stdout cannot run into it.
50
- function writeBlock(tag, attrs, json) {
52
+ function writeBlock(tag, attrs, body) {
51
53
  const attrText = attrs
52
54
  .map(([name, value]) => ` ${name}="${(0, print_dropped_agent_context_1.escapeXmlAttr)((0, text_1.singleLine)(value))}"`)
53
55
  .join('');
54
- process.stdout.write(`\n<${tag}${attrText}>\n${json}\n</${tag}>\n\n`);
56
+ process.stdout.write(`\n<${tag}${attrText}>\n${body}\n</${tag}>\n\n`);
55
57
  }
56
58
  function emitStepBlock(runId, stepId, action, payload) {
57
59
  writeBlock('nx_migrate_step', [
@@ -63,3 +65,20 @@ function emitStepBlock(runId, stepId, action, payload) {
63
65
  function emitPromptBlock(migrationId, payload) {
64
66
  writeBlock('nx_migrate_prompt', [['migration', migrationId]], blockPayload(payload));
65
67
  }
68
+ // For work that belongs to no migration (the final-validation step).
69
+ function emitStepPromptBlock(stepId, payload) {
70
+ writeBlock('nx_migrate_prompt', [['step', stepId]], blockPayload(payload));
71
+ }
72
+ /**
73
+ * Markdown, not JSON: the block carries the runbook file's bytes, so the agent
74
+ * reads what a resume re-emits from disk. Every `<` opening or closing an
75
+ * `<nx_migrate_*>` tag is neutralized wherever it sits: a positional check
76
+ * (line starts plus a blank-character class) can be sidestepped by characters
77
+ * that render as nothing but match no enumerable class. The renderer never
78
+ * emits the literal sequence (runbook.spec pins that), so only tampered bytes
79
+ * change.
80
+ */
81
+ function emitRunbookBlock(runId, content) {
82
+ const neutralized = content.replace(/<(?=\/?nx_migrate_)/gi, '\\u003c');
83
+ writeBlock('nx_migrate_runbook', [['run-id', runId]], neutralized);
84
+ }
@@ -0,0 +1,37 @@
1
+ import type { MigrateStepAwaitingKind } from './run-state';
2
+ export declare function agentWorkPayloadPath(runDirPath: string, stepId: string, attempt: number): string;
3
+ export interface ExpectedAgentWorkPayload {
4
+ migrationId: string;
5
+ kind: MigrateStepAwaitingKind;
6
+ promptPath?: string;
7
+ }
8
+ /**
9
+ * Failures propagate: the runbook promises a parked step's block is
10
+ * re-emitted, so a caller that cannot store the payload must fail the attempt
11
+ * rather than park.
12
+ */
13
+ export declare function persistAgentWorkPayload(filePath: string, payload: object): void;
14
+ /**
15
+ * The stored payload, or null when nothing usable is on disk: the file is
16
+ * missing (the park predates this mechanism), does not parse to a plain
17
+ * object, or does not match what the step awaits. Null is undifferentiated on
18
+ * purpose: every caller's remediation is the same freshly derived payload.
19
+ * The returned object is never re-emitted as text; both re-emission sites go
20
+ * back through the block writer's escaping, so a tampered file cannot break
21
+ * the framing.
22
+ */
23
+ export declare function readAgentWorkPayload(filePath: string, expected: ExpectedAgentWorkPayload): Record<string, unknown> | null;
24
+ /**
25
+ * Returns the newest payload from the current generator lineage, or null.
26
+ * `fromAttempt` excludes generator runs discarded by reset-backed retries; an
27
+ * absent boundary fails closed for states written by older Nx.
28
+ */
29
+ export declare function latestStoredAgentWorkPayload(runDirPath: string, stepId: string, beforeAttempt: number, fromAttempt: number | undefined, expected: ExpectedAgentWorkPayload): Record<string, unknown> | null;
30
+ /**
31
+ * Best effort per file: the callers run after the outcome or rearm is already
32
+ * decided, so an entry that cannot be removed (a permission failure, a
33
+ * directory planted at the path) is left to whole-run pruning rather than
34
+ * failing the reconcile. A planted directory is never re-handed either way:
35
+ * reading it fails, which the reader treats as no stored copy.
36
+ */
37
+ export declare function removeAgentWorkPayloads(runDirPath: string, stepId: string, throughAttempt: number): void;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ // Internal to run/: deliberately not re-exported from ./index.
3
+ //
4
+ // Persists each parked payload by step and attempt, so a reconcile can re-emit
5
+ // it after a compaction or restart without reusing payloads from discarded
6
+ // attempts.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.agentWorkPayloadPath = agentWorkPayloadPath;
9
+ exports.persistAgentWorkPayload = persistAgentWorkPayload;
10
+ exports.readAgentWorkPayload = readAgentWorkPayload;
11
+ exports.latestStoredAgentWorkPayload = latestStoredAgentWorkPayload;
12
+ exports.removeAgentWorkPayloads = removeAgentWorkPayloads;
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
15
+ const atomic_write_1 = require("./atomic-write");
16
+ const AGENT_WORK_DIR_NAME = 'agent-work';
17
+ // Both segments are Nx-issued (`step-<n>` and the attempt counter), so the
18
+ // name never carries untrusted path segments.
19
+ function agentWorkPayloadPath(runDirPath, stepId, attempt) {
20
+ return (0, path_1.join)(runDirPath, AGENT_WORK_DIR_NAME, `${stepId}-attempt-${attempt}.json`);
21
+ }
22
+ /**
23
+ * Failures propagate: the runbook promises a parked step's block is
24
+ * re-emitted, so a caller that cannot store the payload must fail the attempt
25
+ * rather than park.
26
+ */
27
+ function persistAgentWorkPayload(filePath, payload) {
28
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(filePath), { recursive: true });
29
+ (0, atomic_write_1.publishFileAtomically)(filePath, (tmpPath) => (0, fs_1.writeFileSync)(tmpPath, JSON.stringify(payload, null, 2)));
30
+ }
31
+ /**
32
+ * The stored payload, or null when nothing usable is on disk: the file is
33
+ * missing (the park predates this mechanism), does not parse to a plain
34
+ * object, or does not match what the step awaits. Null is undifferentiated on
35
+ * purpose: every caller's remediation is the same freshly derived payload.
36
+ * The returned object is never re-emitted as text; both re-emission sites go
37
+ * back through the block writer's escaping, so a tampered file cannot break
38
+ * the framing.
39
+ */
40
+ function readAgentWorkPayload(filePath, expected) {
41
+ let content;
42
+ try {
43
+ content = (0, fs_1.readFileSync)(filePath, 'utf-8');
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ let parsed;
49
+ try {
50
+ parsed = JSON.parse(content);
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
56
+ return null;
57
+ }
58
+ const payload = parsed;
59
+ if (payload.migrationId !== expected.migrationId) {
60
+ return null;
61
+ }
62
+ let matchesKind;
63
+ switch (expected.kind) {
64
+ case 'generator-validation':
65
+ matchesKind = payload.kind === 'generator-validation';
66
+ break;
67
+ case 'migration-prompt':
68
+ matchesKind =
69
+ payload.kind === undefined &&
70
+ expected.promptPath !== undefined &&
71
+ payload.prompt === expected.promptPath;
72
+ break;
73
+ case 'final-validation':
74
+ // Derived from run state at every dispense; nothing is stored.
75
+ throw new Error('The final validation pass stores no agent-work payload.');
76
+ default: {
77
+ const exhaustive = expected.kind;
78
+ throw new Error(`Unhandled awaiting kind '${exhaustive}'.`);
79
+ }
80
+ }
81
+ return matchesKind ? payload : null;
82
+ }
83
+ /**
84
+ * Returns the newest payload from the current generator lineage, or null.
85
+ * `fromAttempt` excludes generator runs discarded by reset-backed retries; an
86
+ * absent boundary fails closed for states written by older Nx.
87
+ */
88
+ function latestStoredAgentWorkPayload(runDirPath, stepId, beforeAttempt, fromAttempt, expected) {
89
+ if (fromAttempt === undefined) {
90
+ return null;
91
+ }
92
+ // Enumerated from disk rather than counted down from `beforeAttempt`:
93
+ // attempts are persisted numbers, and a loop spanning their range would
94
+ // let a tampered-but-valid counter drive that many synchronous reads.
95
+ const candidates = storedAttemptsForStep(runDirPath, stepId)
96
+ .filter((attempt) => attempt >= fromAttempt && attempt < beforeAttempt)
97
+ .sort((a, b) => b - a);
98
+ for (const attempt of candidates) {
99
+ const payload = readAgentWorkPayload(agentWorkPayloadPath(runDirPath, stepId, attempt), expected);
100
+ if (payload) {
101
+ return payload;
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+ // An unreadable directory reads as empty: the lookup falls back to a freshly
107
+ // derived payload, and removal is best effort. The `-attempt-` infix keeps
108
+ // `step-1` from matching `step-12`'s files.
109
+ function storedAttemptsForStep(runDirPath, stepId) {
110
+ let entries;
111
+ try {
112
+ entries = (0, fs_1.readdirSync)((0, path_1.join)(runDirPath, AGENT_WORK_DIR_NAME));
113
+ }
114
+ catch {
115
+ return [];
116
+ }
117
+ const prefix = `${stepId}-attempt-`;
118
+ const suffix = '.json';
119
+ const attempts = [];
120
+ for (const name of entries) {
121
+ if (!name.startsWith(prefix) || !name.endsWith(suffix)) {
122
+ continue;
123
+ }
124
+ const middle = name.slice(prefix.length, -suffix.length);
125
+ if (!/^[1-9]\d*$/.test(middle)) {
126
+ continue;
127
+ }
128
+ const attempt = Number(middle);
129
+ if (Number.isSafeInteger(attempt)) {
130
+ attempts.push(attempt);
131
+ }
132
+ }
133
+ return attempts;
134
+ }
135
+ /**
136
+ * Best effort per file: the callers run after the outcome or rearm is already
137
+ * decided, so an entry that cannot be removed (a permission failure, a
138
+ * directory planted at the path) is left to whole-run pruning rather than
139
+ * failing the reconcile. A planted directory is never re-handed either way:
140
+ * reading it fails, which the reader treats as no stored copy.
141
+ */
142
+ function removeAgentWorkPayloads(runDirPath, stepId, throughAttempt) {
143
+ // Enumerated for the same reason as the lookup: a tampered-but-valid attempt
144
+ // would otherwise drive that many synchronous removals.
145
+ for (const attempt of storedAttemptsForStep(runDirPath, stepId)) {
146
+ if (attempt > throughAttempt) {
147
+ continue;
148
+ }
149
+ try {
150
+ (0, fs_1.rmSync)(agentWorkPayloadPath(runDirPath, stepId, attempt), {
151
+ force: true,
152
+ });
153
+ }
154
+ catch { }
155
+ }
156
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Runs `write` against a unique sibling temp path, then renames it over
3
+ * `filePath`: a crash mid-write can only leave a stale temp file, never a
4
+ * half-written artifact, and rename replaces whatever sits at the destination
5
+ * without following it. The random suffix keeps concurrent writers apart; a
6
+ * pid would collide across PID namespaces sharing the workspace.
7
+ */
8
+ export declare function publishFileAtomically(filePath: string, write: (tmpPath: string) => void): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publishFileAtomically = publishFileAtomically;
4
+ const crypto_1 = require("crypto");
5
+ const fs_1 = require("fs");
6
+ /**
7
+ * Runs `write` against a unique sibling temp path, then renames it over
8
+ * `filePath`: a crash mid-write can only leave a stale temp file, never a
9
+ * half-written artifact, and rename replaces whatever sits at the destination
10
+ * without following it. The random suffix keeps concurrent writers apart; a
11
+ * pid would collide across PID namespaces sharing the workspace.
12
+ */
13
+ function publishFileAtomically(filePath, write) {
14
+ const tmpPath = `${filePath}~${(0, crypto_1.randomBytes)(4).toString('hex')}`;
15
+ write(tmpPath);
16
+ (0, fs_1.renameSync)(tmpPath, filePath);
17
+ }