@depup/nx 23.2.1-depup.7 → 23.3.0-depup.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.
- package/README.md +8 -19
- package/changes.json +10 -54
- package/dist/bin/init-local.js +7 -1
- package/dist/nx-cloud-internals.d.ts +1 -0
- package/dist/nx-cloud-internals.js +9 -0
- package/dist/plugins/package-json.js +1 -1
- package/dist/src/command-line/add/add.js +5 -1
- package/dist/src/command-line/affected/affected.js +70 -9
- package/dist/src/command-line/affected/command-object.js +1 -1
- package/dist/src/command-line/format/format.js +2 -18
- package/dist/src/command-line/graph/graph.d.ts +31 -0
- package/dist/src/command-line/graph/graph.js +113 -20
- package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +0 -3
- package/dist/src/command-line/init/implementation/add-nx-to-nest.js +0 -3
- package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +0 -3
- package/dist/src/command-line/init/implementation/angular/index.js +0 -3
- package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +0 -3
- package/dist/src/command-line/init/implementation/format.js +2 -3
- package/dist/src/command-line/init/implementation/utils.d.ts +0 -1
- package/dist/src/command-line/init/implementation/utils.js +6 -9
- package/dist/src/command-line/init/init-v2.js +0 -3
- package/dist/src/command-line/migrate/agentic/capture-generator-output.d.ts +25 -0
- package/dist/src/command-line/migrate/agentic/capture-generator-output.js +121 -5
- package/dist/src/command-line/migrate/agentic/close-agent-session.d.ts +21 -0
- package/dist/src/command-line/migrate/agentic/close-agent-session.js +126 -0
- package/dist/src/command-line/migrate/agentic/definitions.d.ts +24 -0
- package/dist/src/command-line/migrate/agentic/definitions.js +79 -20
- package/dist/src/command-line/migrate/agentic/format-command.d.ts +14 -0
- package/dist/src/command-line/migrate/agentic/format-command.js +44 -0
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +3 -3
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +3 -3
- package/dist/src/command-line/migrate/agentic/handoff.d.ts +50 -17
- package/dist/src/command-line/migrate/agentic/handoff.js +166 -24
- package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +23 -0
- package/dist/src/command-line/migrate/agentic/instruction-files.js +41 -0
- package/dist/src/command-line/migrate/agentic/master/invocations.d.ts +12 -0
- package/dist/src/command-line/migrate/agentic/master/invocations.js +54 -0
- package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +16 -0
- package/dist/src/command-line/migrate/agentic/master/run-master-session.js +175 -0
- package/dist/src/command-line/migrate/agentic/master/spawn-master.d.ts +31 -0
- package/dist/src/command-line/migrate/agentic/master/spawn-master.js +222 -0
- package/dist/src/command-line/migrate/agentic/prompts/final-validation.d.ts +13 -0
- package/dist/src/command-line/migrate/agentic/prompts/final-validation.js +41 -0
- package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +17 -0
- package/dist/src/command-line/migrate/agentic/prompts/fragments.js +90 -0
- package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +4 -3
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +25 -1
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +57 -34
- package/dist/src/command-line/migrate/agentic/run-step.js +28 -4
- package/dist/src/command-line/migrate/agentic/runner.d.ts +3 -15
- package/dist/src/command-line/migrate/agentic/runner.js +57 -239
- package/dist/src/command-line/migrate/agentic/terminal-repair.d.ts +1 -0
- package/dist/src/command-line/migrate/agentic/terminal-repair.js +27 -0
- package/dist/src/command-line/migrate/agentic/types.d.ts +23 -8
- package/dist/src/command-line/migrate/agentic/types.js +10 -7
- package/dist/src/command-line/migrate/agentic/windows-cmd.d.ts +33 -0
- package/dist/src/command-line/migrate/agentic/windows-cmd.js +88 -0
- package/dist/src/command-line/migrate/command-object.d.ts +2 -0
- package/dist/src/command-line/migrate/command-object.js +11 -1
- package/dist/src/command-line/migrate/deferred-output.d.ts +44 -0
- package/dist/src/command-line/migrate/deferred-output.js +92 -0
- package/dist/src/command-line/migrate/execute-migration.d.ts +9 -3
- package/dist/src/command-line/migrate/execute-migration.js +53 -16
- package/dist/src/command-line/migrate/migrate-analytics.d.ts +34 -9
- package/dist/src/command-line/migrate/migrate-analytics.js +71 -10
- package/dist/src/command-line/migrate/migrate-commits.d.ts +5 -4
- package/dist/src/command-line/migrate/migrate-commits.js +16 -6
- package/dist/src/command-line/migrate/migrate-config.d.ts +5 -2
- package/dist/src/command-line/migrate/migrate-config.js +19 -11
- package/dist/src/command-line/migrate/migrate-output.d.ts +3 -7
- package/dist/src/command-line/migrate/migrate-output.js +3 -7
- package/dist/src/command-line/migrate/migrate.d.ts +3 -0
- package/dist/src/command-line/migrate/migrate.js +183 -46
- package/dist/src/command-line/migrate/resolve-package-version.js +2 -19
- package/dist/src/command-line/migrate/run/agent-output.d.ts +11 -0
- package/dist/src/command-line/migrate/run/agent-output.js +21 -2
- package/dist/src/command-line/migrate/run/agent-work-payload.d.ts +37 -0
- package/dist/src/command-line/migrate/run/agent-work-payload.js +156 -0
- package/dist/src/command-line/migrate/run/atomic-write.d.ts +8 -0
- package/dist/src/command-line/migrate/run/atomic-write.js +17 -0
- package/dist/src/command-line/migrate/run/broker.d.ts +150 -0
- package/dist/src/command-line/migrate/run/broker.js +568 -0
- package/dist/src/command-line/migrate/run/clean-retry.d.ts +12 -0
- package/dist/src/command-line/migrate/run/clean-retry.js +99 -0
- package/dist/src/command-line/migrate/run/existing-run-report.d.ts +55 -0
- package/dist/src/command-line/migrate/run/existing-run-report.js +227 -0
- package/dist/src/command-line/migrate/run/give-up.d.ts +41 -0
- package/dist/src/command-line/migrate/run/give-up.js +148 -0
- package/dist/src/command-line/migrate/run/index.d.ts +9 -6
- package/dist/src/command-line/migrate/run/index.js +21 -2
- package/dist/src/command-line/migrate/run/issues.d.ts +127 -0
- package/dist/src/command-line/migrate/run/issues.js +1121 -0
- package/dist/src/command-line/migrate/run/orchestrator.d.ts +59 -1
- package/dist/src/command-line/migrate/run/orchestrator.js +1529 -457
- package/dist/src/command-line/migrate/run/run-id.d.ts +0 -8
- package/dist/src/command-line/migrate/run/run-id.js +0 -30
- package/dist/src/command-line/migrate/run/run-state.d.ts +77 -17
- package/dist/src/command-line/migrate/run/run-state.js +263 -32
- package/dist/src/command-line/migrate/run/runbook.d.ts +18 -0
- package/dist/src/command-line/migrate/run/runbook.js +118 -0
- package/dist/src/command-line/migrate/run/state-lock.d.ts +33 -2
- package/dist/src/command-line/migrate/run/state-lock.js +128 -2
- package/dist/src/command-line/migrate/run/state-machine.d.ts +50 -1
- package/dist/src/command-line/migrate/run/state-machine.js +339 -26
- package/dist/src/command-line/migrate/run/util.d.ts +3 -1
- package/dist/src/command-line/migrate/run/util.js +24 -3
- package/dist/src/command-line/migrate/run/worker.js +290 -129
- package/dist/src/command-line/migrate/step-actions.d.ts +1 -1
- package/dist/src/command-line/migrate/step-actions.js +7 -1
- package/dist/src/command-line/migrate/text.d.ts +6 -0
- package/dist/src/command-line/migrate/text.js +25 -0
- package/dist/src/command-line/migrate/version-skew-guard.js +2 -0
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +5 -11
- package/dist/src/command-line/release/publish.js +11 -8
- package/dist/src/command-line/release/utils/get-touched-projects-for-group.js +3 -3
- package/dist/src/command-line/release/utils/release-graph.js +1 -1
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +5 -8
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +3 -3
- package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +4 -2
- package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +37 -3
- package/dist/src/command-line/release/version/version-actions.d.ts +3 -0
- package/dist/src/command-line/reset/reset.js +10 -4
- package/dist/src/command-line/run/run-one.js +5 -1
- package/dist/src/command-line/run-many/run-many.js +6 -12
- package/dist/src/command-line/show/command-object.js +1 -1
- package/dist/src/command-line/show/projects.js +52 -1
- package/dist/src/command-line/yargs-utils/shared-options.d.ts +5 -1
- package/dist/src/command-line/yargs-utils/shared-options.js +38 -4
- package/dist/src/config/task-graph.d.ts +1 -1
- package/dist/src/config/workspace-json-project-json.d.ts +23 -1
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/runtime.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +14 -8
- package/dist/src/daemon/client/client.js +41 -12
- package/dist/src/daemon/message-types/get-plugin-capabilities.d.ts +5 -0
- package/dist/src/daemon/message-types/get-plugin-capabilities.js +11 -0
- package/dist/src/daemon/message-types/run-tasks-execution-hooks.d.ts +3 -2
- package/dist/src/daemon/message-types/select-affected-tasks.d.ts +21 -0
- package/dist/src/daemon/message-types/select-affected-tasks.js +11 -0
- package/dist/src/daemon/message-types/ultracache-configuration-version.d.ts +8 -0
- package/dist/src/daemon/message-types/ultracache-configuration-version.js +2 -0
- package/dist/src/daemon/server/dotenv-graph-changes.d.ts +1 -1
- package/dist/src/daemon/server/dotenv-graph-changes.js +2 -2
- package/dist/src/daemon/server/handle-get-plugin-capabilities.d.ts +2 -0
- package/dist/src/daemon/server/handle-get-plugin-capabilities.js +13 -0
- package/dist/src/daemon/server/handle-hash-tasks.d.ts +10 -2
- package/dist/src/daemon/server/handle-hash-tasks.js +18 -3
- package/dist/src/daemon/server/handle-select-affected-tasks.d.ts +3 -0
- package/dist/src/daemon/server/handle-select-affected-tasks.js +26 -0
- package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +3 -2
- package/dist/src/daemon/server/{handle-outputs-changes.d.ts → handle-watch-events.d.ts} +4 -4
- package/dist/src/daemon/server/{handle-outputs-changes.js → handle-watch-events.js} +36 -37
- package/dist/src/daemon/server/outputs-tracking.d.ts +7 -19
- package/dist/src/daemon/server/outputs-tracking.js +7 -107
- package/dist/src/daemon/server/planning-context.d.ts +8 -0
- package/dist/src/daemon/server/planning-context.js +18 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +22 -7
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +104 -74
- package/dist/src/daemon/server/restart-checks.d.ts +22 -0
- package/dist/src/daemon/server/restart-checks.js +77 -0
- package/dist/src/daemon/server/server.d.ts +1 -0
- package/dist/src/daemon/server/server.js +54 -30
- package/dist/src/daemon/server/shutdown-utils.d.ts +0 -5
- package/dist/src/daemon/server/shutdown-utils.js +3 -26
- package/dist/src/daemon/server/ultracache-configuration-state.d.ts +7 -0
- package/dist/src/daemon/server/ultracache-configuration-state.js +36 -0
- package/dist/src/devkit-internals.d.ts +3 -1
- package/dist/src/devkit-internals.js +8 -3
- package/dist/src/executors/run-commands/run-commands.impl.d.ts +2 -1
- package/dist/src/executors/run-commands/run-commands.impl.js +19 -5
- package/dist/src/executors/run-commands/running-tasks.d.ts +5 -4
- package/dist/src/executors/run-commands/running-tasks.js +13 -13
- package/dist/src/hasher/create-task-hasher.d.ts +8 -1
- package/dist/src/hasher/create-task-hasher.js +13 -3
- package/dist/src/hasher/hash-plan-inspector.js +2 -2
- package/dist/src/hasher/hash-task.d.ts +2 -2
- package/dist/src/hasher/hash-task.js +28 -17
- package/dist/src/hasher/native-task-hasher-impl.d.ts +20 -4
- package/dist/src/hasher/native-task-hasher-impl.js +75 -9
- package/dist/src/hasher/task-hasher.d.ts +24 -7
- package/dist/src/hasher/task-hasher.js +27 -8
- package/dist/src/hasher/task-planning-context.d.ts +13 -0
- package/dist/src/hasher/task-planning-context.js +12 -0
- package/dist/src/native/index.d.ts +582 -21
- package/dist/src/native/index.js +3 -3
- package/dist/src/native/native-bindings.js +13 -1
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/native/transform-objects.d.ts +11 -2
- package/dist/src/native/transform-objects.js +46 -0
- package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +15 -8
- package/dist/src/nx-cloud/update-manager.d.ts +3 -0
- package/dist/src/nx-cloud/update-manager.js +19 -13
- package/dist/src/nx-cloud/utilities/client.d.ts +1 -1
- package/dist/src/nx-cloud/utilities/client.js +1 -1
- package/dist/src/nx-cloud/utilities/is-workspace-claimed.js +2 -1
- package/dist/src/nx-cloud/utilities/nx-cloud-http-client.d.ts +5 -0
- package/dist/src/nx-cloud/utilities/nx-cloud-http-client.js +16 -0
- package/dist/src/nx-cloud/utilities/url-shorten.js +17 -10
- package/dist/src/plugins/js/index.js +45 -64
- package/dist/src/plugins/js/lock-file/lock-file.d.ts +4 -4
- package/dist/src/plugins/js/lock-file/lock-file.js +6 -7
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -1
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +2 -0
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +22 -0
- package/dist/src/plugins/js/project-graph/affected/lock-file-changes.d.ts +10 -2
- package/dist/src/plugins/js/project-graph/affected/lock-file-changes.js +51 -29
- package/dist/src/plugins/js/project-graph/affected/npm-packages.d.ts +10 -2
- package/dist/src/plugins/js/project-graph/affected/npm-packages.js +32 -11
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +22 -18
- package/dist/src/plugins/js/utils/register.js +13 -4
- package/dist/src/plugins/package-json/create-nodes.d.ts +2 -2
- package/dist/src/plugins/package-json/create-nodes.js +13 -13
- package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +14 -0
- package/dist/src/project-graph/affected/affected-project-graph.js +5 -18
- package/dist/src/project-graph/affected/affected-projects.d.ts +7 -0
- package/dist/src/project-graph/affected/affected-projects.js +42 -0
- package/dist/src/project-graph/affected/affected-reasons.d.ts +116 -0
- package/dist/src/project-graph/affected/affected-reasons.js +459 -0
- package/dist/src/project-graph/affected/affected-tasks.d.ts +103 -0
- package/dist/src/project-graph/affected/affected-tasks.js +386 -0
- package/dist/src/project-graph/affected/print-explanation.d.ts +11 -0
- package/dist/src/project-graph/affected/print-explanation.js +44 -0
- package/dist/src/project-graph/error-types.d.ts +5 -0
- package/dist/src/project-graph/error-types.js +44 -5
- package/dist/src/project-graph/file-utils.d.ts +2 -0
- package/dist/src/project-graph/file-utils.js +12 -3
- package/dist/src/project-graph/nx-deps-cache.d.ts +5 -2
- package/dist/src/project-graph/nx-deps-cache.js +4 -4
- package/dist/src/project-graph/plugins/get-plugins.d.ts +3 -1
- package/dist/src/project-graph/plugins/get-plugins.js +60 -82
- package/dist/src/project-graph/plugins/in-process-loader.d.ts +1 -1
- package/dist/src/project-graph/plugins/in-process-loader.js +1 -4
- package/dist/src/project-graph/plugins/isolation/index.d.ts +1 -1
- package/dist/src/project-graph/plugins/isolation/index.js +3 -1
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +8 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +42 -6
- package/dist/src/project-graph/plugins/isolation/load-isolated-plugin.d.ts +10 -1
- package/dist/src/project-graph/plugins/isolation/load-isolated-plugin.js +67 -17
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +3 -2
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +5 -1
- package/dist/src/project-graph/plugins/loaded-nx-plugin.d.ts +5 -2
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +14 -1
- package/dist/src/project-graph/plugins/nx-plugin-capabilities.d.ts +6 -0
- package/dist/src/project-graph/plugins/nx-plugin-capabilities.js +28 -0
- package/dist/src/project-graph/plugins/task-results-stub.d.ts +50 -0
- package/dist/src/project-graph/plugins/task-results-stub.js +111 -0
- package/dist/src/project-graph/plugins/tasks-execution-hooks.d.ts +3 -2
- package/dist/src/project-graph/plugins/tasks-execution-hooks.js +14 -1
- package/dist/src/project-graph/project-graph.js +43 -42
- package/dist/src/project-graph/utils/project-configuration/target-merging.js +67 -0
- package/dist/src/project-graph/utils/project-configuration/target-normalization.js +83 -0
- package/dist/src/project-graph/utils/project-configuration/utils.d.ts +1 -0
- package/dist/src/project-graph/utils/project-configuration/utils.js +1 -0
- package/dist/src/tasks-runner/batch/run-batch.js +15 -0
- package/dist/src/tasks-runner/cache.d.ts +37 -2
- package/dist/src/tasks-runner/cache.js +42 -1
- package/dist/src/tasks-runner/create-task-graph.d.ts +24 -1
- package/dist/src/tasks-runner/create-task-graph.js +57 -2
- package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
- package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
- package/dist/src/tasks-runner/forked-process-task-runner.js +11 -10
- package/dist/src/tasks-runner/init-tasks-runner.d.ts +7 -2
- package/dist/src/tasks-runner/init-tasks-runner.js +15 -7
- package/dist/src/tasks-runner/is-tui-enabled.js +4 -3
- package/dist/src/tasks-runner/life-cycle.d.ts +7 -0
- package/dist/src/tasks-runner/life-cycle.js +7 -0
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.d.ts +35 -0
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +146 -0
- package/dist/src/tasks-runner/prune-task-graph.d.ts +17 -0
- package/dist/src/tasks-runner/prune-task-graph.js +45 -0
- package/dist/src/tasks-runner/run-command.d.ts +41 -5
- package/dist/src/tasks-runner/run-command.js +98 -22
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +93 -19
- package/dist/src/tasks-runner/running-tasks/batch-process.js +184 -88
- package/dist/src/tasks-runner/task-io-service.d.ts +11 -3
- package/dist/src/tasks-runner/task-io-service.js +14 -5
- package/dist/src/tasks-runner/task-orchestrator.d.ts +71 -4
- package/dist/src/tasks-runner/task-orchestrator.js +266 -66
- package/dist/src/tasks-runner/tasks-runner.d.ts +2 -0
- package/dist/src/tasks-runner/terminal-output-path.d.ts +11 -0
- package/dist/src/tasks-runner/terminal-output-path.js +18 -0
- package/dist/src/tasks-runner/utils.d.ts +5 -0
- package/dist/src/tasks-runner/utils.js +14 -2
- package/dist/src/ultracache/config.d.ts +21 -0
- package/dist/src/ultracache/config.js +29 -0
- package/dist/src/ultracache/fetch.d.ts +21 -0
- package/dist/src/ultracache/fetch.js +43 -0
- package/dist/src/ultracache/overrides.d.ts +17 -0
- package/dist/src/ultracache/overrides.js +61 -0
- package/dist/src/ultracache/report.d.ts +13 -0
- package/dist/src/ultracache/report.js +62 -0
- package/dist/src/ultracache/store.d.ts +41 -0
- package/dist/src/ultracache/store.js +158 -0
- package/dist/src/utils/ab-testing.d.ts +4 -1
- package/dist/src/utils/ab-testing.js +22 -19
- package/dist/src/utils/chunkify.d.ts +1 -7
- package/dist/src/utils/chunkify.js +2 -8
- package/dist/src/utils/command-line-utils.d.ts +20 -0
- package/dist/src/utils/command-line-utils.js +10 -3
- package/dist/src/utils/create-cli-options.d.ts +6 -0
- package/dist/src/utils/create-cli-options.js +29 -0
- package/dist/src/utils/db-connection.d.ts +2 -0
- package/dist/src/utils/db-connection.js +2 -0
- package/dist/src/utils/formatters/index.d.ts +6 -0
- package/dist/src/utils/formatters/index.js +5 -0
- package/dist/src/utils/formatters/prettier.d.ts +0 -8
- package/dist/src/utils/formatters/prettier.js +4 -26
- package/dist/src/utils/git-utils.d.ts +19 -0
- package/dist/src/utils/git-utils.js +97 -39
- package/dist/src/utils/handle-errors.js +5 -43
- package/dist/src/utils/http-client.d.ts +27 -0
- package/dist/src/utils/http-client.js +193 -0
- package/dist/src/utils/installed-nx-version.js +2 -48
- package/dist/src/utils/json-diff.d.ts +4 -2
- package/dist/src/utils/json-diff.js +6 -94
- package/dist/src/utils/min-release-age/packument.js +1 -1
- package/dist/src/utils/nx-cloud-utils.d.ts +2 -0
- package/dist/src/utils/nx-cloud-utils.js +6 -1
- package/dist/src/utils/output.d.ts +22 -3
- package/dist/src/utils/output.js +28 -5
- package/dist/src/utils/package-json.d.ts +25 -0
- package/dist/src/utils/package-json.js +49 -6
- package/dist/src/utils/package-manager.d.ts +6 -0
- package/dist/src/utils/package-manager.js +10 -0
- package/dist/src/utils/plugins/plugin-capabilities.js +7 -2
- package/dist/src/utils/project-graph-utils.d.ts +2 -0
- package/dist/src/utils/project-graph-utils.js +12 -0
- package/dist/src/utils/provenance.js +20 -4
- package/dist/src/utils/serialize-overrides-into-command-line.js +2 -4
- package/dist/src/utils/workspace-context.d.ts +51 -3
- package/dist/src/utils/workspace-context.js +174 -10
- package/package.json +38 -100
- package/schemas/nx-schema.json +38 -0
- package/schemas/project-schema.json +35 -0
- package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +0 -9
- package/dist/src/daemon/server/file-watching/route-workspace-changes.js +0 -76
- package/dist/src/daemon/server/watcher.d.ts +0 -18
- package/dist/src/daemon/server/watcher.js +0 -126
- package/dist/src/nx-cloud/utilities/axios.d.ts +0 -4
- package/dist/src/nx-cloud/utilities/axios.js +0 -17
- package/dist/src/project-graph/affected/locators/project-glob-changes.d.ts +0 -2
- package/dist/src/project-graph/affected/locators/project-glob-changes.js +0 -47
- package/dist/src/project-graph/affected/locators/workspace-json-changes.d.ts +0 -4
- package/dist/src/project-graph/affected/locators/workspace-json-changes.js +0 -47
- package/dist/src/project-graph/affected/locators/workspace-projects.d.ts +0 -3
- package/dist/src/project-graph/affected/locators/workspace-projects.js +0 -74
- package/dist/src/utils/collapse-expanded-outputs.d.ts +0 -10
- package/dist/src/utils/collapse-expanded-outputs.js +0 -72
|
@@ -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<>:"
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runMasterSession = runMasterSession;
|
|
4
|
+
const output_1 = require("../../../../utils/output");
|
|
5
|
+
const migrate_analytics_1 = require("../../migrate-analytics");
|
|
6
|
+
const run_1 = require("../../run");
|
|
7
|
+
const safe_prompt_1 = require("../../safe-prompt");
|
|
8
|
+
const spawn_master_1 = require("./spawn-master");
|
|
9
|
+
/**
|
|
10
|
+
* Starts (or continues) an orchestrated run and hands it to one agent session
|
|
11
|
+
* that drives it through `--run-id` reconciles. Run state is the only
|
|
12
|
+
* authority on the outcome: the exit code follows what run.json says once the
|
|
13
|
+
* session ends, not what the agent process returned.
|
|
14
|
+
*/
|
|
15
|
+
async function runMasterSession(input) {
|
|
16
|
+
const { agent, interactive, runId: requestedRunId, startFresh, ...init } = input;
|
|
17
|
+
// The invocation's policy; an interactive continue adopts the run's recorded
|
|
18
|
+
// one instead, shown in the report and the choice, so resume, broker and
|
|
19
|
+
// the resume hint agree with the run.
|
|
20
|
+
let policy = {
|
|
21
|
+
createCommits: init.createCommits,
|
|
22
|
+
skipInstall: init.skipInstall,
|
|
23
|
+
};
|
|
24
|
+
const resume = (runId) => (0, run_1.runOrchestratorResume)({
|
|
25
|
+
root: init.root,
|
|
26
|
+
runId,
|
|
27
|
+
policy,
|
|
28
|
+
emitAgentInstructions: false,
|
|
29
|
+
});
|
|
30
|
+
// With `replaceRunId`, starts fresh over that run only; the consent covers
|
|
31
|
+
// the run the user saw, and any other active run is reported instead.
|
|
32
|
+
const start = (replaceRunId) => (0, run_1.runOrchestratorInit)({
|
|
33
|
+
...init,
|
|
34
|
+
emitAgentInstructions: false,
|
|
35
|
+
onExistingRun: replaceRunId === undefined ? 'report' : 'start-fresh',
|
|
36
|
+
replaceRunId,
|
|
37
|
+
});
|
|
38
|
+
let ready = requestedRunId !== undefined && !startFresh
|
|
39
|
+
? resume(requestedRunId)
|
|
40
|
+
: await start(startFresh ? requestedRunId : undefined);
|
|
41
|
+
if (ready.kind === 'existing-run' && (0, safe_prompt_1.canPrompt)(interactive)) {
|
|
42
|
+
const decision = await decideExistingRun(ready, init.root);
|
|
43
|
+
if (decision === 'abort') {
|
|
44
|
+
output_1.output.log({
|
|
45
|
+
title: `Leaving migrate run ${ready.runId} as it is. ${continueHint(init.root, agent.id, ready.runId, ready.facts.policy)}`,
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (decision === 'continue') {
|
|
50
|
+
policy = ready.facts.policy;
|
|
51
|
+
ready = resume(ready.runId);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
ready = await start(ready.runId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (ready.kind === 'existing-run') {
|
|
58
|
+
output_1.output.warn((0, run_1.renderExistingRunReport)(ready.facts, (0, run_1.renderExistingRunCommands)(init.root, ready.facts, init.migrationsPath, agent.id)));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (ready.kind === 'refused') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const { runId, runRoot, runbookPath, reconcileCommand } = ready;
|
|
65
|
+
const resumeHint = continueHint(init.root, agent.id, runId, policy);
|
|
66
|
+
output_1.output.log({
|
|
67
|
+
title: `Starting ${agent.displayName} to drive migrate run ${runId}.`,
|
|
68
|
+
});
|
|
69
|
+
const session = await (0, spawn_master_1.spawnMasterSession)({
|
|
70
|
+
agent,
|
|
71
|
+
runRoot,
|
|
72
|
+
runId,
|
|
73
|
+
runbookPath,
|
|
74
|
+
reconcileCommand,
|
|
75
|
+
policy,
|
|
76
|
+
});
|
|
77
|
+
if (session.kind === 'spawn-failed') {
|
|
78
|
+
output_1.output.error({
|
|
79
|
+
title: `Could not start ${agent.displayName}: ${session.error.message}`,
|
|
80
|
+
bodyLines: [`Migrate run ${runId} is still active. ${resumeHint}`],
|
|
81
|
+
});
|
|
82
|
+
(0, migrate_analytics_1.reportMigrateRunError)({ code: 'agentic', error: session.error });
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
if (session.kind === 'broker-failed') {
|
|
86
|
+
// The broker itself reads run.json, so its failure can mean the state is
|
|
87
|
+
// unreadable; the read below decides whether a resume is safe to offer.
|
|
88
|
+
output_1.output.error({
|
|
89
|
+
title: `Closed the ${agent.displayName} session: a step's request could not be answered (${session.error.message}).`,
|
|
90
|
+
});
|
|
91
|
+
(0, migrate_analytics_1.reportMigrateRunError)({ code: 'agentic', error: session.error });
|
|
92
|
+
}
|
|
93
|
+
let state;
|
|
94
|
+
try {
|
|
95
|
+
state = (0, run_1.readRunState)((0, run_1.runDir)(runRoot, runId));
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
// No resume hint: run discovery skips a directory whose run.json is
|
|
99
|
+
// missing, so a rerun could start a second run over the same plan.
|
|
100
|
+
output_1.output.error({
|
|
101
|
+
title: `Nx could not determine whether migrate run ${runId} completed.`,
|
|
102
|
+
bodyLines: [error instanceof Error ? error.message : String(error)],
|
|
103
|
+
});
|
|
104
|
+
return 1;
|
|
105
|
+
}
|
|
106
|
+
switch (state.status) {
|
|
107
|
+
case 'active':
|
|
108
|
+
(0, migrate_analytics_1.reportMigrateOrchestratorAbandoned)({
|
|
109
|
+
...(0, run_1.runTallies)(state),
|
|
110
|
+
agentUsed: agent.id,
|
|
111
|
+
});
|
|
112
|
+
output_1.output.warn({
|
|
113
|
+
title: `Migrate run ${runId} is still active. ${resumeHint}`,
|
|
114
|
+
});
|
|
115
|
+
return 1;
|
|
116
|
+
case 'completed': {
|
|
117
|
+
const tally = (0, run_1.tallySteps)(state);
|
|
118
|
+
const migrations = state.steps.filter((s) => s.kind === 'migration');
|
|
119
|
+
output_1.output.log({
|
|
120
|
+
title: `Migrate run ${runId} is complete.`,
|
|
121
|
+
bodyLines: (0, run_1.completionSummaryLines)(state),
|
|
122
|
+
});
|
|
123
|
+
for (const lines of (0, run_1.completionWarnings)(runRoot, runId, state)) {
|
|
124
|
+
output_1.output.warn({ title: lines[0], bodyLines: lines.slice(1) });
|
|
125
|
+
}
|
|
126
|
+
(0, migrate_analytics_1.reportMigrateRunComplete)({
|
|
127
|
+
agenticOutcome: 'enabled',
|
|
128
|
+
agentUsed: agent.id,
|
|
129
|
+
migrationCount: migrations.length,
|
|
130
|
+
// The printed tally counts the pass; this metric counts migrations.
|
|
131
|
+
appliedCount: migrations.filter((s) => s.status === 'succeeded').length,
|
|
132
|
+
});
|
|
133
|
+
if (tally.unresolved.length > 0 || (0, run_1.hasUnresolvedIssues)(state)) {
|
|
134
|
+
output_1.output.warn({
|
|
135
|
+
title: `Migrate run ${runId} left work unresolved; exiting with code 1.`,
|
|
136
|
+
});
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
default: {
|
|
142
|
+
const unhandled = state.status;
|
|
143
|
+
throw new Error(`Unhandled migrate run status: ${unhandled}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function continueHint(root, agentId, runId, policy) {
|
|
148
|
+
return `Run ${(0, run_1.renderContinueCommand)(root, runId, policy, agentId)}, with NX_MIGRATE_ORCHESTRATOR=true set in the environment, to continue it.`;
|
|
149
|
+
}
|
|
150
|
+
async function decideExistingRun(found, root) {
|
|
151
|
+
output_1.output.log((0, run_1.renderExistingRunReport)(found.facts));
|
|
152
|
+
// A held run leaves nothing to ask: continue would open a second session
|
|
153
|
+
// over the live one, and start fresh refuses. The continue's own gate
|
|
154
|
+
// throws the refusal; a holder gone since the report lets the prompt run.
|
|
155
|
+
if (found.facts.otherHolders === 'unknown' ||
|
|
156
|
+
found.facts.otherHolders.length > 0) {
|
|
157
|
+
(0, run_1.holdRunToContinue)(root, found.runId);
|
|
158
|
+
}
|
|
159
|
+
return (0, safe_prompt_1.migrateChoice)({
|
|
160
|
+
message: 'What do you want to do with the active migrate run?',
|
|
161
|
+
choices: [
|
|
162
|
+
{
|
|
163
|
+
value: 'continue',
|
|
164
|
+
label: 'Continue it',
|
|
165
|
+
hint: 'picks the run up where it stopped, keeping its recorded commit and install policy',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
value: 'start-fresh',
|
|
169
|
+
label: 'Start fresh',
|
|
170
|
+
hint: 'deletes the run record only; the whole plan runs again',
|
|
171
|
+
},
|
|
172
|
+
{ value: 'abort', label: 'Abort', hint: 'leaves the run as it is' },
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MigrateRunPolicy } from '../../run';
|
|
2
|
+
import type { DetectedInstalledAgent } from '../types';
|
|
3
|
+
export interface SpawnMasterSessionInput {
|
|
4
|
+
agent: DetectedInstalledAgent;
|
|
5
|
+
runRoot: string;
|
|
6
|
+
runId: string;
|
|
7
|
+
runbookPath: string;
|
|
8
|
+
reconcileCommand: string;
|
|
9
|
+
policy: MigrateRunPolicy;
|
|
10
|
+
sentinelPollIntervalMs?: number;
|
|
11
|
+
gracefulExitMs?: number;
|
|
12
|
+
forceKillWaitMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export type SpawnMasterSessionResult = {
|
|
15
|
+
kind: 'exited';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'spawn-failed';
|
|
18
|
+
error: Error;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'broker-failed';
|
|
21
|
+
error: Error;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Spawns the agent once, with the run's pinned invariant and bootstrap prompt,
|
|
25
|
+
* and waits for the session to end, closing it once the agent writes the
|
|
26
|
+
* session-complete sentinel. Meanwhile it answers the install and commit
|
|
27
|
+
* requests the steps the agent runs hand out of its sandbox. Every failure
|
|
28
|
+
* before the process starts is returned as `spawn-failed`; what the session
|
|
29
|
+
* did is read from run state by the caller, never from the exit code.
|
|
30
|
+
*/
|
|
31
|
+
export declare function spawnMasterSession(input: SpawnMasterSessionInput): Promise<SpawnMasterSessionResult>;
|