@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
@@ -11,9 +11,9 @@ const logger_1 = require("../../../utils/logger");
11
11
  const types_1 = require("./types");
12
12
  /**
13
13
  * Both the agentic runner and the orchestrator write per-run scratch under
14
- * `.nx/migrate-runs/<run-id>/`: handoff files in both cases, plus the durable
15
- * run state and its plan snapshots for the orchestrator. The v23 migration
16
- * `23-0-0-add-migrate-runs-to-git-ignore` adds `.nx/migrate-runs` to
14
+ * `.nx/migrate-runs/<run-id>/`: handoff and prompt files in both cases, plus
15
+ * the durable run state and its plan snapshots for the orchestrator. The v23
16
+ * migration `23-0-0-add-migrate-runs-to-git-ignore` adds `.nx/migrate-runs` to
17
17
  * `.gitignore`; in its declared slot (typically late) earlier per-migration
18
18
  * commits would absorb the scratch into the user-visible diff.
19
19
  *
@@ -1,3 +1,4 @@
1
+ import { type BigIntStats } from 'fs';
1
2
  import { HandoffFile } from './types';
2
3
  /** Returns the run directory for a given workspace + run id (target version). */
3
4
  export declare function runDirPath(workspaceRoot: string, runId: string): string;
@@ -19,19 +20,17 @@ export declare function mkdirSafely(dir: string, purpose: string): void;
19
20
  * inspection.
20
21
  */
21
22
  export declare function initRunDir(workspaceRoot: string, runId: string): string;
22
- /**
23
- * Absolute path of the handoff file for a migration step within a run, under
24
- * the run directory's `handoffs/` subtree: the pre-authorized write scope
25
- * stops there, so a handoff placed anywhere else costs an approval prompt.
26
- * The package's scope (if any) becomes a real subdirectory so the package name
27
- * stays readable; two packages can ship a migration with the same name without
28
- * colliding because they land in different package subdirectories. Each
29
- * segment is sanitized so the path is always writable on every platform.
30
- */
23
+ export declare function truncateUtf8(value: string, maxBytes: number): string;
31
24
  export declare function stepHandoffPath(runDir: string, migration: {
32
25
  package: string;
33
26
  name: string;
34
27
  }): string;
28
+ /** Handoff path for a run step. No hash needed: step ids are unique within the run. */
29
+ export declare function runStepHandoffPath(runDir: string, stepId: string): string;
30
+ export declare function stepPromptsDir(runDir: string, migration: {
31
+ package: string;
32
+ name: string;
33
+ }): string;
35
34
  export type HandoffReadFailureReason = 'missing' | 'read-error' | 'parse-error' | 'shape-mismatch';
36
35
  export type HandoffReadResult = {
37
36
  ok: true;
@@ -42,19 +41,53 @@ export type HandoffReadResult = {
42
41
  detail?: string;
43
42
  };
44
43
  /**
45
- * Reads and validates a handoff file written by an agent. Returns a tagged
46
- * result so callers (the in-loop poller and the post-exit resolver) can
47
- * distinguish "file not yet written" from "file written but garbage" — the
48
- * latter is surfaced to the user instead of being collapsed into the same
49
- * generic ambiguous-outcome prompt.
44
+ * `lstat`, not `stat`: a symlink in the handoffs dir's place would send every
45
+ * handoff read and removal wherever it points.
46
+ */
47
+ export declare function handoffsDirState(handoffsDir: string): 'directory' | 'missing' | 'other';
48
+ /**
49
+ * Non-recursive mkdir: the run dir exists, and a symlink created after the
50
+ * missing-path check fails with EEXIST instead of being followed.
51
+ */
52
+ export declare function ensureRunSubdir(dir: string, notADirectory: () => Error): void;
53
+ /**
54
+ * Thrown by {@link readInspectedFile} when the opened descriptor is not the
55
+ * file the caller's lstat described: a symlink followed on Windows, or an
56
+ * atomic replacement between the lstat and the open.
57
+ */
58
+ export declare class FileReplacedDuringReadError extends Error {
59
+ }
60
+ /**
61
+ * Reads the file `stat` describes, refusing a symlink swapped in after the
62
+ * caller's lstat: O_NOFOLLOW fails the open with ELOOP, and O_NONBLOCK keeps a
63
+ * planted FIFO from blocking it. Windows has neither flag, so there the inode
64
+ * comparison is what catches a followed symlink. It does not guard against an
65
+ * unlink and recreate reusing the inode number. Read errors propagate: a file
66
+ * the agent cannot read must not pass.
67
+ */
68
+ export declare function readInspectedFile(filePath: string, stat: BigIntStats, replacedMessage: string): string;
69
+ /**
70
+ * Reads a file its owner publishes atomically (tmp + rename), with
71
+ * {@link readInspectedFile}'s refusal of a symlink or FIFO but tolerant of the
72
+ * publish: a rename swaps the inode between the lstat and the open, read as a
73
+ * replacement, so re-lstat and retry to read the new file. A pre-existing
74
+ * symlink or FIFO fails the isFile check before any open; a file that keeps
75
+ * changing past the retry budget is refused. Throws `notRegularMessage` for a
76
+ * non-regular file; ENOENT and ELOOP propagate.
77
+ */
78
+ export declare function readAtomicallyPublishedFile(filePath: string, notRegularMessage: string): string;
79
+ /**
80
+ * Splits "not written yet" from "written but garbage" so callers can surface a
81
+ * malformed handoff instead of collapsing it into the generic
82
+ * ambiguous-outcome prompt.
50
83
  */
51
- export declare function readHandoffWithReason(filePath: string): HandoffReadResult;
84
+ export declare function readHandoffWithReason(filePath: string, handoffsDir: string): HandoffReadResult;
52
85
  /**
53
86
  * Convenience wrapper preserving the original null-on-any-failure contract.
54
87
  * Used by the polling loop (`waitForValidHandoff`) where every failure mode
55
88
  * is "keep waiting" — the file may be missing, mid-write, or being rewritten.
56
89
  */
57
- export declare function readHandoff(filePath: string): HandoffFile | null;
90
+ export declare function readHandoff(filePath: string, handoffsDir: string): HandoffFile | null;
58
91
  /**
59
92
  * Polls for a valid handoff file. Resolves once `readHandoff` accepts the
60
93
  * file's contents. Used to detect when the agent has finished its work so the
@@ -63,7 +96,7 @@ export declare function readHandoff(filePath: string): HandoffFile | null;
63
96
  *
64
97
  * Rejects with the abort reason when `options.signal` is aborted.
65
98
  */
66
- export declare function waitForValidHandoff(handoffFilePath: string, options?: {
99
+ export declare function waitForValidHandoff(handoffFilePath: string, handoffsDir: string, options?: {
67
100
  intervalMs?: number;
68
101
  signal?: AbortSignal;
69
102
  }): Promise<void>;
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileReplacedDuringReadError = void 0;
3
4
  exports.runDirPath = runDirPath;
4
5
  exports.resolveAgenticRunId = resolveAgenticRunId;
5
6
  exports.mkdirSafely = mkdirSafely;
6
7
  exports.initRunDir = initRunDir;
8
+ exports.truncateUtf8 = truncateUtf8;
7
9
  exports.stepHandoffPath = stepHandoffPath;
10
+ exports.runStepHandoffPath = runStepHandoffPath;
11
+ exports.stepPromptsDir = stepPromptsDir;
12
+ exports.handoffsDirState = handoffsDirState;
13
+ exports.ensureRunSubdir = ensureRunSubdir;
14
+ exports.readInspectedFile = readInspectedFile;
15
+ exports.readAtomicallyPublishedFile = readAtomicallyPublishedFile;
8
16
  exports.readHandoffWithReason = readHandoffWithReason;
9
17
  exports.readHandoff = readHandoff;
10
18
  exports.waitForValidHandoff = waitForValidHandoff;
19
+ const crypto_1 = require("crypto");
11
20
  const fs_1 = require("fs");
12
21
  const path_1 = require("path");
13
22
  const semver_1 = require("semver");
@@ -56,14 +65,10 @@ function initRunDir(workspaceRoot, runId) {
56
65
  // a migration named `CON` would otherwise produce a `CON.json` that the
57
66
  // agent can't write to.
58
67
  const WINDOWS_RESERVED_NAMES = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
59
- /**
60
- * The bare `.` / `..` check must come first — otherwise a malformed migration
61
- * name of exactly `..` would let the handoff write escape the run directory.
62
- */
63
68
  function sanitizeSegment(value) {
64
69
  if (value === '.' || value === '..')
65
70
  return '_';
66
- let sanitized = value.replace(/[\x00-\x1f<>:"/\\|?*]/g, '_');
71
+ let sanitized = value.replace(/[\x00-\x1f<>:"/\\|?*+]/g, '_');
67
72
  // Windows forbids trailing dots/spaces on file/directory names.
68
73
  sanitized = sanitized.replace(/[. ]+$/, '');
69
74
  if (WINDOWS_RESERVED_NAMES.test(sanitized)) {
@@ -71,29 +76,166 @@ function sanitizeSegment(value) {
71
76
  }
72
77
  return sanitized || '_';
73
78
  }
79
+ const STEP_NAME_PREFIX_MAX_BYTES = 64;
80
+ // Truncates to a UTF-8 byte budget without splitting a code point.
81
+ function truncateUtf8(value, maxBytes) {
82
+ let out = '';
83
+ let used = 0;
84
+ for (const ch of value) {
85
+ const bytes = Buffer.byteLength(ch);
86
+ if (used + bytes > maxBytes)
87
+ break;
88
+ out += ch;
89
+ used += bytes;
90
+ }
91
+ return out;
92
+ }
74
93
  /**
75
- * Absolute path of the handoff file for a migration step within a run, under
76
- * the run directory's `handoffs/` subtree: the pre-authorized write scope
77
- * stops there, so a handoff placed anywhere else costs an approval prompt.
78
- * The package's scope (if any) becomes a real subdirectory so the package name
79
- * stays readable; two packages can ship a migration with the same name without
80
- * colliding because they land in different package subdirectories. Each
81
- * segment is sanitized so the path is always writable on every platform.
94
+ * The name a step's own files are keyed by, bounded to fit one path component.
95
+ * Sanitizing folds many characters to `_` and the prefix is cut to fit, so the
96
+ * SHA-256 of the raw package and name is what keeps two migrations apart.
82
97
  */
98
+ function stepStem(migration) {
99
+ const prefix = truncateUtf8([...migration.package.split('/'), migration.name]
100
+ .map(sanitizeSegment)
101
+ .join('+'), STEP_NAME_PREFIX_MAX_BYTES);
102
+ const hash = (0, crypto_1.createHash)('sha256')
103
+ .update(JSON.stringify([migration.package, migration.name]))
104
+ .digest('hex');
105
+ return `${prefix}-${hash}`;
106
+ }
83
107
  function stepHandoffPath(runDir, migration) {
84
- return (0, path_1.join)(runDir, types_1.HANDOFFS_DIR_NAME, ...migration.package.split('/').map(sanitizeSegment), `${sanitizeSegment(migration.name)}.json`);
108
+ return (0, path_1.join)(runDir, types_1.HANDOFFS_DIR_NAME, `${stepStem(migration)}.json`);
109
+ }
110
+ /** Handoff path for a run step. No hash needed: step ids are unique within the run. */
111
+ function runStepHandoffPath(runDir, stepId) {
112
+ return (0, path_1.join)(runDir, types_1.HANDOFFS_DIR_NAME, `${sanitizeSegment(stepId)}.json`);
113
+ }
114
+ function stepPromptsDir(runDir, migration) {
115
+ return (0, path_1.join)(runDir, types_1.PROMPTS_DIR_NAME, stepStem(migration));
116
+ }
117
+ /**
118
+ * `lstat`, not `stat`: a symlink in the handoffs dir's place would send every
119
+ * handoff read and removal wherever it points.
120
+ */
121
+ function handoffsDirState(handoffsDir) {
122
+ try {
123
+ return (0, fs_1.lstatSync)(handoffsDir).isDirectory() ? 'directory' : 'other';
124
+ }
125
+ catch (err) {
126
+ if (err?.code === 'ENOENT')
127
+ return 'missing';
128
+ throw err;
129
+ }
130
+ }
131
+ /**
132
+ * Non-recursive mkdir: the run dir exists, and a symlink created after the
133
+ * missing-path check fails with EEXIST instead of being followed.
134
+ */
135
+ function ensureRunSubdir(dir, notADirectory) {
136
+ const state = handoffsDirState(dir);
137
+ switch (state) {
138
+ case 'directory':
139
+ return;
140
+ case 'missing':
141
+ (0, fs_1.mkdirSync)(dir);
142
+ return;
143
+ case 'other':
144
+ throw notADirectory();
145
+ default: {
146
+ const unhandled = state;
147
+ throw new Error(`Unhandled directory state: ${unhandled}`);
148
+ }
149
+ }
85
150
  }
86
151
  /**
87
- * Reads and validates a handoff file written by an agent. Returns a tagged
88
- * result so callers (the in-loop poller and the post-exit resolver) can
89
- * distinguish "file not yet written" from "file written but garbage" — the
90
- * latter is surfaced to the user instead of being collapsed into the same
91
- * generic ambiguous-outcome prompt.
152
+ * Thrown by {@link readInspectedFile} when the opened descriptor is not the
153
+ * file the caller's lstat described: a symlink followed on Windows, or an
154
+ * atomic replacement between the lstat and the open.
92
155
  */
93
- function readHandoffWithReason(filePath) {
156
+ class FileReplacedDuringReadError extends Error {
157
+ }
158
+ exports.FileReplacedDuringReadError = FileReplacedDuringReadError;
159
+ /**
160
+ * Reads the file `stat` describes, refusing a symlink swapped in after the
161
+ * caller's lstat: O_NOFOLLOW fails the open with ELOOP, and O_NONBLOCK keeps a
162
+ * planted FIFO from blocking it. Windows has neither flag, so there the inode
163
+ * comparison is what catches a followed symlink. It does not guard against an
164
+ * unlink and recreate reusing the inode number. Read errors propagate: a file
165
+ * the agent cannot read must not pass.
166
+ */
167
+ function readInspectedFile(filePath, stat, replacedMessage) {
168
+ const fd = (0, fs_1.openSync)(filePath, fs_1.constants.O_RDONLY |
169
+ (fs_1.constants.O_NOFOLLOW ?? 0) |
170
+ (fs_1.constants.O_NONBLOCK ?? 0));
171
+ try {
172
+ const fdStat = (0, fs_1.fstatSync)(fd, { bigint: true });
173
+ if (!fdStat.isFile() ||
174
+ fdStat.dev !== stat.dev ||
175
+ fdStat.ino !== stat.ino) {
176
+ throw new FileReplacedDuringReadError(replacedMessage);
177
+ }
178
+ return (0, fs_1.readFileSync)(fd, 'utf-8');
179
+ }
180
+ finally {
181
+ (0, fs_1.closeSync)(fd);
182
+ }
183
+ }
184
+ const ATOMIC_READ_ATTEMPTS = 5;
185
+ /**
186
+ * Reads a file its owner publishes atomically (tmp + rename), with
187
+ * {@link readInspectedFile}'s refusal of a symlink or FIFO but tolerant of the
188
+ * publish: a rename swaps the inode between the lstat and the open, read as a
189
+ * replacement, so re-lstat and retry to read the new file. A pre-existing
190
+ * symlink or FIFO fails the isFile check before any open; a file that keeps
191
+ * changing past the retry budget is refused. Throws `notRegularMessage` for a
192
+ * non-regular file; ENOENT and ELOOP propagate.
193
+ */
194
+ function readAtomicallyPublishedFile(filePath, notRegularMessage) {
195
+ for (let attempt = 1;; attempt++) {
196
+ const stat = (0, fs_1.lstatSync)(filePath, { bigint: true });
197
+ if (!stat.isFile()) {
198
+ throw new Error(notRegularMessage);
199
+ }
200
+ try {
201
+ return readInspectedFile(filePath, stat, `${filePath} was replaced while being read.`);
202
+ }
203
+ catch (e) {
204
+ if (e instanceof FileReplacedDuringReadError &&
205
+ attempt < ATOMIC_READ_ATTEMPTS) {
206
+ continue;
207
+ }
208
+ throw e;
209
+ }
210
+ }
211
+ }
212
+ /**
213
+ * Splits "not written yet" from "written but garbage" so callers can surface a
214
+ * malformed handoff instead of collapsing it into the generic
215
+ * ambiguous-outcome prompt.
216
+ */
217
+ function readHandoffWithReason(filePath, handoffsDir) {
94
218
  let raw;
95
219
  try {
96
- raw = (0, fs_1.readFileSync)(filePath, 'utf-8');
220
+ switch (handoffsDirState(handoffsDir)) {
221
+ case 'missing':
222
+ return { ok: false, reason: 'missing' };
223
+ case 'other':
224
+ return {
225
+ ok: false,
226
+ reason: 'read-error',
227
+ detail: `${handoffsDir} is not a directory`,
228
+ };
229
+ }
230
+ const stat = (0, fs_1.lstatSync)(filePath, { bigint: true });
231
+ if (!stat.isFile()) {
232
+ return {
233
+ ok: false,
234
+ reason: 'read-error',
235
+ detail: `${filePath} is not a regular file`,
236
+ };
237
+ }
238
+ raw = readInspectedFile(filePath, stat, `${filePath} was replaced while being read`);
97
239
  }
98
240
  catch (err) {
99
241
  const code = err?.code;
@@ -148,8 +290,8 @@ function readHandoffWithReason(filePath) {
148
290
  * Used by the polling loop (`waitForValidHandoff`) where every failure mode
149
291
  * is "keep waiting" — the file may be missing, mid-write, or being rewritten.
150
292
  */
151
- function readHandoff(filePath) {
152
- const result = readHandoffWithReason(filePath);
293
+ function readHandoff(filePath, handoffsDir) {
294
+ const result = readHandoffWithReason(filePath, handoffsDir);
153
295
  return result.ok ? result.handoff : null;
154
296
  }
155
297
  /**
@@ -160,7 +302,7 @@ function readHandoff(filePath) {
160
302
  *
161
303
  * Rejects with the abort reason when `options.signal` is aborted.
162
304
  */
163
- function waitForValidHandoff(handoffFilePath, options = {}) {
305
+ function waitForValidHandoff(handoffFilePath, handoffsDir, options = {}) {
164
306
  const intervalMs = options.intervalMs ?? 500;
165
307
  const { signal } = options;
166
308
  return new Promise((resolve, reject) => {
@@ -180,7 +322,7 @@ function waitForValidHandoff(handoffFilePath, options = {}) {
180
322
  onAbort();
181
323
  return;
182
324
  }
183
- if (readHandoff(handoffFilePath) !== null) {
325
+ if (readHandoff(handoffFilePath, handoffsDir) !== null) {
184
326
  signal?.removeEventListener('abort', onAbort);
185
327
  resolve();
186
328
  return;
@@ -0,0 +1,23 @@
1
+ export interface StepInstructionFiles {
2
+ /** Absolute path: config loaders resolve it, not the agent from its cwd. */
3
+ systemPromptFilePath: string;
4
+ /** Single-line command-line text pointing the agent at its instructions. */
5
+ instructionsPointer: string;
6
+ }
7
+ export interface WriteStepInstructionFilesArgs {
8
+ workspaceRoot: string;
9
+ runDir: string;
10
+ migration: {
11
+ package: string;
12
+ name: string;
13
+ };
14
+ systemPrompt: string;
15
+ instructions: string;
16
+ }
17
+ /**
18
+ * Writes prompts as files on every platform to keep one delivery path.
19
+ * Windows npm shims cannot carry multi-line prompts within cmd.exe's limit.
20
+ */
21
+ export declare function writeStepInstructionFiles(args: WriteStepInstructionFilesArgs): StepInstructionFiles;
22
+ /** Writes `instructions.md` into an existing `promptsDir`; returns its path. */
23
+ export declare function writeInstructionsFile(workspaceRoot: string, promptsDir: string, instructions: string): string;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeStepInstructionFiles = writeStepInstructionFiles;
4
+ exports.writeInstructionsFile = writeInstructionsFile;
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const handoff_1 = require("./handoff");
8
+ /**
9
+ * Writes prompts as files on every platform to keep one delivery path.
10
+ * Windows npm shims cannot carry multi-line prompts within cmd.exe's limit.
11
+ */
12
+ function writeStepInstructionFiles(args) {
13
+ const { workspaceRoot, runDir, migration, systemPrompt, instructions } = args;
14
+ const promptsDir = (0, handoff_1.stepPromptsDir)(runDir, migration);
15
+ (0, handoff_1.mkdirSafely)(promptsDir, `prompt directory for ${migration.name}`);
16
+ const systemPromptFilePath = (0, path_1.join)(promptsDir, 'system.md');
17
+ writeStepFile(systemPromptFilePath, systemPrompt, 'system prompt');
18
+ const instructionsFilePath = writeInstructionsFile(workspaceRoot, promptsDir, instructions);
19
+ return {
20
+ systemPromptFilePath,
21
+ instructionsPointer: `Your instructions for this migration step are in the file ${instructionsFilePath} (path is relative to the workspace root). Read it in full, then follow it.`,
22
+ };
23
+ }
24
+ /** Writes `instructions.md` into an existing `promptsDir`; returns its path. */
25
+ function writeInstructionsFile(workspaceRoot, promptsDir, instructions) {
26
+ const absolutePath = (0, path_1.join)(promptsDir, 'instructions.md');
27
+ writeStepFile(absolutePath, instructions, 'instructions');
28
+ // Workspace-relative: the agent resolves this one itself with its cwd pinned
29
+ // to the workspace root. Forward slashes because it is read as prose out of
30
+ // the agent's prompt, where a `\` is an escape.
31
+ return (0, path_1.relative)(workspaceRoot, absolutePath).replace(/\\/g, '/');
32
+ }
33
+ function writeStepFile(filePath, contents, purpose) {
34
+ try {
35
+ (0, fs_1.writeFileSync)(filePath, contents, 'utf-8');
36
+ }
37
+ catch (err) {
38
+ const code = err?.code;
39
+ throw new Error(`Could not write the step's ${purpose} to ${filePath}${code ? ` (${code})` : ''}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
40
+ }
41
+ }
@@ -0,0 +1,12 @@
1
+ import type { AgentId, InvocationSpec } from '../types';
2
+ export interface MasterInvocationContext {
3
+ runId: string;
4
+ reconcileCommand: string;
5
+ /** Workspace-relative with forward slashes: prose the agent reads, not a shell path. */
6
+ runbookPath: string;
7
+ /** Same form as `runbookPath`; its existence closes the session. */
8
+ sentinelPath: string;
9
+ }
10
+ export declare function masterInvariant(ctx: MasterInvocationContext): string;
11
+ export declare function masterBootstrapPrompt(ctx: MasterInvocationContext): string;
12
+ export declare function buildMasterInvocation(agentId: AgentId, ctx: MasterInvocationContext): InvocationSpec;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.masterInvariant = masterInvariant;
4
+ exports.masterBootstrapPrompt = masterBootstrapPrompt;
5
+ exports.buildMasterInvocation = buildMasterInvocation;
6
+ const definitions_1 = require("../definitions");
7
+ // One line with no `%`: the Windows shim refuses line breaks and the pinned
8
+ // text is what its command-line budget is measured against.
9
+ function masterInvariant(ctx) {
10
+ return `You are driving Nx migrate run ${ctx.runId}. Its state lives on disk and is owned by nx migrate; never infer its progress from this conversation. Whenever you are unsure what to do, after a compaction or restart, and after you finish any piece of work, run \`${ctx.reconcileCommand}\` and follow the step block it returns. The run's contract is the runbook at ${ctx.runbookPath}; re-read it whenever a step block says so. When a step block reports the run complete, tell the user the outcome, then create the file ${ctx.sentinelPath} as your last action; nx closes this session once it exists.`;
11
+ }
12
+ function masterBootstrapPrompt(ctx) {
13
+ return `Read the runbook at ${ctx.runbookPath} in full, then run \`${ctx.reconcileCommand}\` and follow the step block it returns.`;
14
+ }
15
+ const OPENCODE_AGENT_NAME = 'nx-migrate';
16
+ // Keyed by agent id so a new agent fails to compile until it gets a builder.
17
+ const builders = {
18
+ 'claude-code': (ctx) => {
19
+ const allowedTools = (0, definitions_1.claudeCodeHandoffAllowedTools)(ctx.runId);
20
+ return {
21
+ // `--allowedTools` is variadic: the non-variadic flag between it and
22
+ // the positional prompt keeps the prompt from being read as a rule.
23
+ args: [
24
+ ...(allowedTools ? ['--allowedTools', allowedTools] : []),
25
+ '--append-system-prompt',
26
+ masterInvariant(ctx),
27
+ masterBootstrapPrompt(ctx),
28
+ ],
29
+ };
30
+ },
31
+ codex: (ctx) => ({
32
+ args: [
33
+ '-c',
34
+ `developer_instructions=${(0, definitions_1.encodeTomlString)(masterInvariant(ctx))}`,
35
+ masterBootstrapPrompt(ctx),
36
+ ],
37
+ }),
38
+ opencode: (ctx) => ({
39
+ args: [
40
+ '--agent',
41
+ OPENCODE_AGENT_NAME,
42
+ '--prompt',
43
+ masterBootstrapPrompt(ctx),
44
+ ],
45
+ env: {
46
+ OPENCODE_CONFIG_CONTENT: JSON.stringify({
47
+ agent: { [OPENCODE_AGENT_NAME]: { prompt: masterInvariant(ctx) } },
48
+ }),
49
+ },
50
+ }),
51
+ };
52
+ function buildMasterInvocation(agentId, ctx) {
53
+ return builders[agentId](ctx);
54
+ }
@@ -0,0 +1,16 @@
1
+ import { type RunOrchestratorInitInput } from '../../run';
2
+ import type { DetectedInstalledAgent } from '../types';
3
+ export interface RunMasterSessionInput extends Omit<RunOrchestratorInitInput, 'emitAgentInstructions' | 'onExistingRun'> {
4
+ agent: DetectedInstalledAgent;
5
+ interactive?: boolean;
6
+ runId?: string;
7
+ startFresh?: boolean;
8
+ confirmStart: () => Promise<boolean>;
9
+ }
10
+ /**
11
+ * Starts (or continues) an orchestrated run and hands it to one agent session
12
+ * that drives it through `--run-id` reconciles. Run state is the only
13
+ * authority on the outcome: the exit code follows what run.json says once the
14
+ * session ends, not what the agent process returned.
15
+ */
16
+ export declare function runMasterSession(input: RunMasterSessionInput): Promise<number | undefined>;