@automaton-labs/aib 0.0.7 → 0.0.9
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 +21 -578
- package/config/agent-dx-policy.default.json +31 -0
- package/config/control-plane-client.default.json +3 -0
- package/dist/agent-dx/agent-dx.js +805 -0
- package/dist/agent-dx/presentation.js +32 -0
- package/dist/alias-advisor/analyze.js +982 -0
- package/dist/alias-advisor/exact-text-cost.js +74 -0
- package/dist/alias-advisor/lexical.js +240 -0
- package/dist/alias-advisor/model.js +2 -0
- package/dist/alias-advisor/path-identity.js +49 -0
- package/dist/alias-advisor/ranking.js +171 -0
- package/dist/alias-advisor/token-estimator.js +85 -0
- package/dist/bin/aib.js +5 -1
- package/dist/bin/cli.js +811 -4
- package/dist/commands/add-missing-imports-preview-cache.js +99 -2
- package/dist/commands/add-missing-imports.js +241 -2
- package/dist/commands/apply-module-plan.js +1319 -3
- package/dist/commands/background-command.js +378 -2
- package/dist/commands/captured-input.js +74 -1
- package/dist/commands/config-command.js +314 -2
- package/dist/commands/config-output.js +357 -10
- package/dist/commands/control-plane-command.js +183 -1
- package/dist/commands/declaration-command.js +1209 -7
- package/dist/commands/declaration-execution-cache.js +79 -1
- package/dist/commands/declaration-format.js +221 -1
- package/dist/commands/declaration-preview-cache.js +114 -2
- package/dist/commands/diagnostics-command.js +70 -3
- package/dist/commands/doctor.js +137 -3
- package/dist/commands/execution-command.js +117 -1
- package/dist/commands/exports-star-collapse-command.js +178 -0
- package/dist/commands/exports-star-command.js +252 -0
- package/dist/commands/exports-star-preview-cache.js +84 -0
- package/dist/commands/feedback-command.js +176 -3
- package/dist/commands/file-move-to-dir-execution-cache.js +92 -1
- package/dist/commands/file-move-to-dir-preview-cache.js +125 -2
- package/dist/commands/file-move-to-dir-worker.js +54 -0
- package/dist/commands/file-move-to-dir.js +1073 -5
- package/dist/commands/file-mutation-runtime.js +102 -1
- package/dist/commands/file-mutation-worker-apply.js +180 -0
- package/dist/commands/file-refactor-batch-execution-cache.js +90 -1
- package/dist/commands/file-refactor-batch-preview-cache.js +125 -2
- package/dist/commands/file-refactor-batch-worker.js +54 -0
- package/dist/commands/file-refactor-batch.js +1154 -5
- package/dist/commands/file-rename-execution-cache.js +92 -1
- package/dist/commands/file-rename-preview-cache.js +125 -2
- package/dist/commands/file-rename-worker.js +54 -0
- package/dist/commands/file-rename.js +1053 -5
- package/dist/commands/file-text-edit-executor.js +205 -0
- package/dist/commands/find-importers.js +52 -1
- package/dist/commands/find-unused-imports.js +55 -1
- package/dist/commands/generate-docs-command.js +244 -6
- package/dist/commands/help-command.js +460 -7
- package/dist/commands/import-specifier-policy.js +391 -0
- package/dist/commands/imports-command.js +68 -1
- package/dist/commands/imports-rebase.js +1138 -0
- package/dist/commands/init-skill-usage.js +92 -3
- package/dist/commands/init-workspace.js +30 -1
- package/dist/commands/inspect-alias-candidates.js +413 -0
- package/dist/commands/inspect-cycles.js +811 -5
- package/dist/commands/inspect-direct-usages.js +98 -0
- package/dist/commands/inspect-duplicates-format.js +229 -0
- package/dist/commands/inspect-format-primitives.js +127 -0
- package/dist/commands/inspect-format.js +1590 -18
- package/dist/commands/inspect-graph.js +1553 -9
- package/dist/commands/inspect-imports.js +339 -2
- package/dist/commands/inspect-mixed-format.js +524 -0
- package/dist/commands/inspect-module-plan-format.js +216 -0
- package/dist/commands/inspect-module-plan-serialization.js +402 -0
- package/dist/commands/inspect-reference-path-format.js +157 -0
- package/dist/commands/inspect-request-values.js +599 -0
- package/dist/commands/inspect-selector-kind.js +21 -0
- package/dist/commands/inspect-selector.js +50 -0
- package/dist/commands/inspect-symbol-format.js +90 -0
- package/dist/commands/inspect-topology.js +435 -0
- package/dist/commands/inspect-tree.js +827 -5
- package/dist/commands/inspect-usages-detail.js +793 -0
- package/dist/commands/inspect-usages-evidence.js +31 -0
- package/dist/commands/inspect-usages-format.js +367 -0
- package/dist/commands/inspect.js +1450 -16
- package/dist/commands/internal-command.js +64 -0
- package/dist/commands/json-file-input.js +60 -1
- package/dist/commands/module-plan-cache.js +156 -2
- package/dist/commands/module-plan-standalone.js +208 -0
- package/dist/commands/module-plan-timeout.js +77 -1
- package/dist/commands/move-preview-cache.js +101 -2
- package/dist/commands/mutate-aggregate-output.js +996 -0
- package/dist/commands/mutate-child-execution.js +374 -0
- package/dist/commands/mutate-command.js +1394 -0
- package/dist/commands/mutate-declaration-output.js +313 -0
- package/dist/commands/mutate-domain-adapters.js +638 -0
- package/dist/commands/mutate-execution-cache.js +114 -0
- package/dist/commands/mutate-execution-status.js +598 -0
- package/dist/commands/mutate-failure-output.js +531 -0
- package/dist/commands/mutate-file-view.js +151 -0
- package/dist/commands/mutate-object-output.js +91 -0
- package/dist/commands/mutate-output-values.js +97 -0
- package/dist/commands/mutate-preview-cache.js +86 -0
- package/dist/commands/mutate-response-replay.js +153 -0
- package/dist/commands/mutate-result-projection.js +818 -0
- package/dist/commands/mutation-eta.js +28 -0
- package/dist/commands/mutation-execution-cache.js +140 -3
- package/dist/commands/mutation-recovery-journal.js +195 -0
- package/dist/commands/normalize-imports.js +1120 -4
- package/dist/commands/object-pack-command.js +546 -0
- package/dist/commands/object-pack-preview-cache.js +88 -0
- package/dist/commands/observability-command.js +47 -3
- package/dist/commands/ota-command.js +403 -2
- package/dist/commands/print-config.js +10 -1
- package/dist/commands/quick-read.js +1113 -11
- package/dist/commands/refactor-batch-builder.js +265 -1
- package/dist/commands/refactor-batch-execution-cache.js +85 -1
- package/dist/commands/refactor-batch-preview-cache.js +96 -2
- package/dist/commands/refactor-batch.js +461 -4
- package/dist/commands/rename-entities.js +794 -4
- package/dist/commands/rename-execution-cache.js +49 -1
- package/dist/commands/rename-input.js +22 -1
- package/dist/commands/rename-polling-policy.js +68 -0
- package/dist/commands/rename-preview-cache.js +96 -2
- package/dist/commands/result-view.js +993 -7
- package/dist/commands/reveal-command.js +445 -5
- package/dist/commands/selector-suggestions.js +93 -0
- package/dist/commands/session-workspace.js +1836 -31
- package/dist/commands/shared.js +2 -1
- package/dist/commands/skills-command.js +315 -0
- package/dist/commands/sync-command.js +59 -2
- package/dist/commands/worker-command.js +173 -1
- package/dist/commands/workspace-cache.js +55 -1
- package/dist/config/defaults.js +26 -1
- package/dist/config/env-vars.js +77 -1
- package/dist/config/glob-match.js +44 -1
- package/dist/config/import-rules.js +165 -1
- package/dist/config/local-config.js +293 -3
- package/dist/config/mutation-comments.js +51 -1
- package/dist/config/path-aliases.js +165 -1
- package/dist/config/path-display.js +84 -1
- package/dist/config/product-storage.js +37 -1
- package/dist/config/request-env.js +21 -0
- package/dist/config/request-routing-context.js +23 -0
- package/dist/config/resolve-command-alias.js +74 -1
- package/dist/config/resolve.js +24 -1
- package/dist/config/tsconfig-discovery.js +113 -1
- package/dist/config/typescript-preferences.js +131 -0
- package/dist/config/workspace-root.js +310 -3
- package/dist/config/workspace-state.js +254 -1
- package/dist/content/content-bundle.js +88 -1
- package/dist/diagnostics/module-plan-timeline.js +75 -2
- package/dist/diagnostics/readiness-text.js +45 -8
- package/dist/dsl/aib-dsl.js +838 -1
- package/dist/dsl/declaration-dsl.js +264 -1
- package/dist/dsl/file-move-to-dir-dsl.js +123 -1
- package/dist/dsl/file-refactor-batch-dsl.js +203 -1
- package/dist/dsl/file-rename-dsl.js +135 -1
- package/dist/dsl/mutate-dsl.js +746 -0
- package/dist/help/bootstrap.bash.md +176 -341
- package/dist/help/bootstrap.md +175 -340
- package/dist/help/bootstrap.pwsh.md +176 -341
- package/dist/help/docs/basics.md +1 -1
- package/dist/help/docs/config-setup.import-normalize.md +65 -65
- package/dist/help/docs/config-setup.import-rules.md +6 -5
- package/dist/help/docs/first-setup.md +6 -5
- package/dist/help/docs/help-protocol.md +4 -3
- package/dist/help/docs/import.base.md +38 -0
- package/dist/help/docs/import.rebase.md +85 -0
- package/dist/help/docs/inspect.aliasCandidates.md +39 -0
- package/dist/help/docs/inspect.code.md +1 -7
- package/dist/help/docs/inspect.file.md +10 -19
- package/dist/help/docs/inspect.graph.md +3 -17
- package/dist/help/{dsl/docs/inspect.md → docs/inspect.shared.md} +13 -12
- package/dist/help/docs/modulePlan.md +24 -28
- package/dist/help/docs/move.md +19 -22
- package/dist/help/{dsl/topics/file.move.md → docs/moveToDir.md} +36 -34
- package/dist/help/docs/mutate.mixed.md +34 -0
- package/dist/help/docs/mutation.shared.md +55 -0
- package/dist/help/docs/patterns.md +3 -12
- package/dist/help/docs/qr.md +12 -6
- package/dist/help/docs/quick-map.md +36 -24
- package/dist/help/docs/recipe.file-layout.md +10 -10
- package/dist/help/docs/recipe.import-boundary.md +92 -0
- package/dist/help/docs/recipe.safe-artifact-probing.md +68 -0
- package/dist/help/docs/recipe.unfamiliar-area.md +64 -0
- package/dist/help/docs/recipes.md +20 -0
- package/dist/help/docs/rename.md +19 -27
- package/dist/help/docs/renameFile.md +36 -0
- package/dist/help/docs/rules.md +26 -0
- package/dist/help/dsl/bootstrap.bash.md +176 -341
- package/dist/help/dsl/bootstrap.md +175 -340
- package/dist/help/dsl/bootstrap.pwsh.md +176 -341
- package/dist/help/dsl/docs/basics.md +1 -1
- package/dist/help/dsl/docs/config-setup.import-normalize.md +65 -65
- package/dist/help/dsl/docs/config-setup.import-rules.md +6 -5
- package/dist/help/dsl/docs/first-setup.md +6 -5
- package/dist/help/dsl/docs/help-protocol.md +4 -3
- package/dist/help/dsl/docs/import.base.md +38 -0
- package/dist/help/dsl/docs/import.rebase.md +85 -0
- package/dist/help/dsl/docs/inspect.aliasCandidates.md +39 -0
- package/dist/help/dsl/docs/inspect.code.md +1 -7
- package/dist/help/dsl/docs/inspect.file.md +10 -19
- package/dist/help/dsl/docs/inspect.graph.md +3 -17
- package/dist/help/{docs/inspect.md → dsl/docs/inspect.shared.md} +13 -12
- package/dist/help/dsl/docs/modulePlan.md +24 -28
- package/dist/help/dsl/docs/move.md +19 -22
- package/dist/help/{topics/file.move.md → dsl/docs/moveToDir.md} +36 -34
- package/dist/help/dsl/docs/mutate.mixed.md +34 -0
- package/dist/help/dsl/docs/mutation.shared.md +55 -0
- package/dist/help/dsl/docs/patterns.md +3 -12
- package/dist/help/dsl/docs/qr.md +12 -6
- package/dist/help/dsl/docs/quick-map.md +36 -24
- package/dist/help/dsl/docs/recipe.file-layout.md +10 -10
- package/dist/help/dsl/docs/recipe.import-boundary.md +92 -0
- package/dist/help/dsl/docs/recipe.safe-artifact-probing.md +68 -0
- package/dist/help/dsl/docs/recipe.unfamiliar-area.md +64 -0
- package/dist/help/dsl/docs/recipes.md +20 -0
- package/dist/help/dsl/docs/rename.md +19 -27
- package/dist/help/dsl/docs/renameFile.md +36 -0
- package/dist/help/dsl/docs/rules.md +26 -0
- package/dist/help/dsl/full.md +175 -340
- package/dist/help/dsl/help-index.md +48 -43
- package/dist/help/dsl/snippets/agents.md +2 -2
- package/dist/help/dsl/tokens/qr.inline.examples.md +1 -1
- package/dist/help/dsl/topics/basics.md +1 -1
- package/dist/help/dsl/topics/config-setup.import-normalize.md +65 -65
- package/dist/help/dsl/topics/config-setup.import-rules.md +6 -5
- package/dist/help/dsl/topics/first-setup.md +6 -5
- package/dist/help/dsl/topics/help-protocol.md +4 -3
- package/dist/help/dsl/topics/import.base.md +36 -0
- package/dist/help/dsl/topics/import.rebase.md +83 -0
- package/dist/help/dsl/topics/inspect.aliasCandidates.md +37 -0
- package/dist/help/dsl/topics/inspect.code.md +1 -7
- package/dist/help/dsl/topics/inspect.file.md +10 -19
- package/dist/help/dsl/topics/inspect.graph.md +3 -17
- package/dist/help/dsl/topics/{inspect.md → inspect.shared.md} +13 -12
- package/dist/help/dsl/topics/modulePlan.md +21 -26
- package/dist/help/dsl/topics/move.md +17 -18
- package/dist/help/{docs/file.move.md → dsl/topics/moveToDir.md} +33 -35
- package/dist/help/dsl/topics/mutate.mixed.md +32 -0
- package/dist/help/dsl/topics/mutation.shared.md +53 -0
- package/dist/help/dsl/topics/patterns.md +3 -12
- package/dist/help/dsl/topics/qr.md +12 -6
- package/dist/help/dsl/topics/quick-map.md +36 -24
- package/dist/help/dsl/topics/recipe.file-layout.md +10 -10
- package/dist/help/dsl/topics/recipe.import-boundary.md +90 -0
- package/dist/help/dsl/topics/recipe.safe-artifact-probing.md +66 -0
- package/dist/help/dsl/topics/recipe.unfamiliar-area.md +62 -0
- package/dist/help/dsl/topics/recipes.md +18 -0
- package/dist/help/dsl/topics/rename.md +15 -15
- package/dist/help/dsl/topics/renameFile.md +34 -0
- package/dist/help/dsl/topics/rules.md +24 -0
- package/dist/help/full.md +175 -340
- package/dist/help/help-index.md +48 -43
- package/dist/help/help-meta.json +98 -48
- package/dist/help/index.md +52 -20
- package/dist/help/snippets/agents.md +2 -2
- package/dist/help/tokens/qr.inline.examples.md +1 -1
- package/dist/help/topics/basics.md +1 -1
- package/dist/help/topics/config-setup.import-normalize.md +65 -65
- package/dist/help/topics/config-setup.import-rules.md +6 -5
- package/dist/help/topics/first-setup.md +6 -5
- package/dist/help/topics/help-protocol.md +4 -3
- package/dist/help/topics/import.base.md +36 -0
- package/dist/help/topics/import.rebase.md +83 -0
- package/dist/help/topics/inspect.aliasCandidates.md +37 -0
- package/dist/help/topics/inspect.code.md +1 -7
- package/dist/help/topics/inspect.file.md +10 -19
- package/dist/help/topics/inspect.graph.md +3 -17
- package/dist/help/topics/{inspect.md → inspect.shared.md} +13 -12
- package/dist/help/topics/modulePlan.md +21 -26
- package/dist/help/topics/move.md +17 -18
- package/dist/help/{dsl/docs/file.move.md → topics/moveToDir.md} +33 -35
- package/dist/help/topics/mutate.mixed.md +32 -0
- package/dist/help/topics/mutation.shared.md +53 -0
- package/dist/help/topics/patterns.md +3 -12
- package/dist/help/topics/qr.md +12 -6
- package/dist/help/topics/quick-map.md +36 -24
- package/dist/help/topics/recipe.file-layout.md +10 -10
- package/dist/help/topics/recipe.import-boundary.md +90 -0
- package/dist/help/topics/recipe.safe-artifact-probing.md +66 -0
- package/dist/help/topics/recipe.unfamiliar-area.md +62 -0
- package/dist/help/topics/recipes.md +18 -0
- package/dist/help/topics/rename.md +15 -15
- package/dist/help/topics/renameFile.md +34 -0
- package/dist/help/topics/rules.md +24 -0
- package/dist/host/capabilities.js +56 -1
- package/dist/imports/standalone-import-analysis.js +602 -0
- package/dist/imports/standalone-import-model.js +2 -0
- package/dist/imports/standalone-import-process.js +66 -0
- package/dist/imports/standalone-import-worker.js +27 -0
- package/dist/imports/standalone-ts-project.js +147 -0
- package/dist/inspect/inspect-duplicates-service.js +526 -0
- package/dist/inspect/inspect-reverse-module-closure.js +338 -0
- package/dist/inspect/inspect-source-ranges.js +82 -0
- package/dist/inspect/inspect-source-shape.js +649 -0
- package/dist/inspect/standalone-inspect-analysis.js +319 -0
- package/dist/inspect/standalone-inspect-model.js +9 -0
- package/dist/inspect/standalone-inspect-process.js +55 -0
- package/dist/inspect/standalone-inspect-usages.js +274 -0
- package/dist/inspect/standalone-inspect-worker.js +13 -0
- package/dist/metrics/central-metrics.js +101 -2
- package/dist/mutation/concrete-edit-plan.js +157 -0
- package/dist/mutation/exports-star-collapse-preview.js +361 -0
- package/dist/mutation/exports-star-expand-apply.js +373 -0
- package/dist/mutation/exports-star-expand-preview.js +807 -0
- package/dist/mutation/file-impact-scan.js +182 -0
- package/dist/mutation/file-mutation-discovery.js +674 -0
- package/dist/mutation/file-mutation-eta.js +99 -0
- package/dist/mutation/file-mutation-standalone-apply.js +584 -0
- package/dist/mutation/file-mutation-standalone-planner.js +500 -0
- package/dist/mutation/file-mutation-tsserver-session.js +473 -0
- package/dist/mutation/mutation-estimate.js +45 -0
- package/dist/mutation/mutation-plan.js +467 -0
- package/dist/mutation/object-mutation-foundation.js +2 -0
- package/dist/mutation/object-mutation-partition.js +148 -0
- package/dist/mutation/object-pack-semantic-apply.js +507 -0
- package/dist/mutation/object-pack-semantic-preview.js +984 -0
- package/dist/mutation/object-unpack-semantic-preview.js +993 -0
- package/dist/mutation/package-manifest-impact.js +176 -0
- package/dist/mutation/rename-owner-worker-child.js +37 -0
- package/dist/mutation/rename-owner-worker.js +122 -0
- package/dist/mutation/runtime-cycle-query.js +66 -0
- package/dist/mutation/semantic-execution-progress.js +63 -0
- package/dist/mutation/semantic-export-index.js +474 -0
- package/dist/mutation/semantic-impact-scan.js +434 -0
- package/dist/mutation/semantic-model.js +2 -0
- package/dist/mutation/semantic-move-best-effort-planner.js +209 -0
- package/dist/mutation/semantic-move-config-worker-child.js +61 -0
- package/dist/mutation/semantic-move-config-worker.js +449 -0
- package/dist/mutation/semantic-move-declarations.js +94 -0
- package/dist/mutation/semantic-move-metrics.js +119 -0
- package/dist/mutation/semantic-move-model.js +2 -0
- package/dist/mutation/semantic-move-owner-authority.js +122 -0
- package/dist/mutation/semantic-move-owner-candidates.js +300 -0
- package/dist/mutation/semantic-move-owner-divergence-harness.js +474 -0
- package/dist/mutation/semantic-move-owner-divergence-runner.js +162 -0
- package/dist/mutation/semantic-move-plan-hash.js +56 -0
- package/dist/mutation/semantic-move-policy.js +360 -0
- package/dist/mutation/semantic-move-process.js +218 -0
- package/dist/mutation/semantic-move-provider-diagnostics.js +27 -0
- package/dist/mutation/semantic-move-standalone-engine.js +919 -0
- package/dist/mutation/semantic-move-standalone-planner.js +1553 -0
- package/dist/mutation/semantic-move-transaction.js +639 -0
- package/dist/mutation/semantic-mutation-engine.js +478 -0
- package/dist/mutation/semantic-mutation-runtime.js +521 -0
- package/dist/mutation/semantic-planner-retry.js +26 -0
- package/dist/mutation/semantic-program-roots.js +69 -0
- package/dist/mutation/semantic-rename-commonjs.js +229 -0
- package/dist/mutation/semantic-rename-config-worker-child.js +46 -0
- package/dist/mutation/semantic-rename-config-worker.js +498 -0
- package/dist/mutation/semantic-rename-locations.js +192 -0
- package/dist/mutation/semantic-rename-model.js +2 -0
- package/dist/mutation/semantic-rename-process.js +217 -0
- package/dist/mutation/semantic-rename-standalone-engine.js +302 -0
- package/dist/mutation/semantic-rename-standalone-planner.js +567 -0
- package/dist/mutation/semantic-rename-transaction.js +333 -0
- package/dist/mutation/semantic-unused-import-cleanup.js +248 -0
- package/dist/mutation/semantic-worker-retry.js +40 -0
- package/dist/mutation/semantic-workspace.js +804 -0
- package/dist/mutation/targeted-import-canonicalizer.js +359 -0
- package/dist/observability/config.js +206 -1
- package/dist/observability/context.js +59 -1
- package/dist/observability/failure-snapshot.js +124 -2
- package/dist/observability/recent.js +63 -2
- package/dist/payloads/read-stdin-json.js +212 -1
- package/dist/rg-wrapper/core.js +714 -6
- package/dist/rg-wrapper/options.js +125 -1
- package/dist/rtk-wrapper/core.js +144 -2
- package/dist/rtk-wrapper/git-safety.js +203 -0
- package/dist/rtk-wrapper/output-adapter.js +106 -0
- package/dist/runtime/buffered-process.js +114 -0
- package/dist/runtime/bundled-node.js +97 -1
- package/dist/runtime/command-lifecycle.js +2 -0
- package/dist/runtime/input-source.js +238 -1
- package/dist/runtime/node-cli-identity.js +37 -0
- package/dist/runtime/run-command.js +191 -1
- package/dist/selectors/parse-entities.js +84 -1
- package/dist/semantic/semantic-context-pool.js +830 -0
- package/dist/semantic/semantic-context-provider.js +416 -0
- package/dist/semantic/semantic-resident-admission.js +38 -0
- package/dist/semantic/semantic-worker-child.js +40 -0
- package/dist/semantic/semantic-worker-manager.js +460 -0
- package/dist/semantic/semantic-worker-protocol.js +2 -0
- package/dist/semantic/semantic-worker-runtime.js +38 -0
- package/dist/semantic/workspace-semantic-context-pools.js +136 -0
- package/dist/session/client.js +359 -1
- package/dist/session/daemon-state.js +185 -2
- package/dist/session/external-tool-coordinator.js +88 -0
- package/dist/session/external-tool-request.js +52 -0
- package/dist/session/lane-owner.js +116 -0
- package/dist/session/paths.js +71 -1
- package/dist/session/runtime-lifecycle.js +225 -0
- package/dist/session/runtime-shutdown.js +95 -0
- package/dist/session/server.js +1194 -7
- package/dist/session/session-health.js +27 -0
- package/dist/shared/agent-text.js +29 -1
- package/dist/shared/errors.js +496 -30
- package/dist/shared/event-loop.js +6 -1
- package/dist/shared/hints.js +37 -1
- package/dist/shared/metrics.js +43 -1
- package/dist/shared/presentation.js +69 -4
- package/dist/shared/stdin-examples.js +77 -1
- package/dist/shared/stdout.js +6 -2
- package/dist/shared/types.js +23 -1
- package/dist/tool-runtime/runtime-tools.js +120 -1
- package/dist/topology/availability.js +663 -0
- package/dist/topology/cache.js +130 -0
- package/dist/topology/candidates.js +372 -0
- package/dist/topology/core.js +903 -0
- package/dist/topology/dependency-snapshot.js +189 -0
- package/dist/topology/model.js +2 -0
- package/dist/topology/scope.js +100 -0
- package/dist/topology/ts-oracle-batch.js +529 -0
- package/dist/topology/ts-oracle-host.js +69 -0
- package/dist/topology/ts-oracle-model.js +2 -0
- package/dist/topology/ts-oracle.js +224 -0
- package/dist/topology/tsconfig-loader.js +105 -0
- package/dist/topology/workspace-project-index.js +542 -0
- package/dist/tracing/config.js +192 -2
- package/dist/tracing/failure-summary.js +100 -0
- package/dist/tracing/trace.js +318 -5
- package/dist/tsc-wrapper/core.js +697 -0
- package/dist/workers/control-plane/aib-control-plane-worker.cjs +32 -32
- package/dist/workers/control-plane/client-config.default.json +3 -3
- package/dist/workers/lexical-worker-child.js +27 -0
- package/dist/workers/lexical-worker-manager.js +394 -0
- package/dist/workers/lexical-worker-protocol.js +2 -0
- package/dist/workers/lexical-worker-runtime.js +25 -0
- package/dist/workers/owned-one-shot-process.js +115 -0
- package/dist/workers/product-storage.js +23 -1
- package/dist/workers/registry.js +241 -1
- package/package.json +8 -13
- package/scripts/postinstall.cjs +29 -29
- package/scripts/provision-runtime.cjs +411 -459
- package/dist/client/http-client.js +0 -1
- package/dist/client/transport-options.js +0 -1
- package/dist/client/websocket-client.js +0 -1
- package/dist/commands/entity-resolution.js +0 -1
- package/dist/commands/file-command.js +0 -1
- package/dist/commands/host-command.js +0 -1
- package/dist/commands/inspect-symbol-query.js +0 -1
- package/dist/commands/list-instances.js +0 -1
- package/dist/commands/module-plan-command.js +0 -1
- package/dist/commands/move-command.js +0 -1
- package/dist/commands/move-to-file.js +0 -2
- package/dist/commands/ping.js +0 -1
- package/dist/commands/refactor-command.js +0 -1
- package/dist/commands/rename-command.js +0 -1
- package/dist/commands/runtime-command.js +0 -4
- package/dist/commands/runtime-info.js +0 -1
- package/dist/commands/validate-module-plan.js +0 -2
- package/dist/compatibility/policy.js +0 -1
- package/dist/config/auto-start-ide.js +0 -1
- package/dist/discovery/registry.js +0 -1
- package/dist/discovery/select-instance.js +0 -1
- package/dist/help/docs/file.rename.md +0 -35
- package/dist/help/docs/mutation.md +0 -60
- package/dist/help/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/docs/file.rename.md +0 -35
- package/dist/help/dsl/docs/mutation.md +0 -60
- package/dist/help/dsl/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/topics/file.rename.md +0 -33
- package/dist/help/dsl/topics/mutation.md +0 -58
- package/dist/help/dsl/topics/refactor.batch.md +0 -33
- package/dist/help/topics/file.rename.md +0 -33
- package/dist/help/topics/mutation.md +0 -58
- package/dist/help/topics/refactor.batch.md +0 -33
- package/dist/ide-launch/common.cjs +0 -162
- package/dist/managed-host/extension-vsix-resolver.js +0 -1
- package/dist/managed-host/manage-serve-web-host.cjs +0 -141
- package/dist/managed-host/serve-web-autostart.js +0 -1
- package/dist/managed-host/serve-web-host.cjs +0 -2115
- package/dist/runtime/managed-runtime-provisioning.js +0 -1
- package/dist/shared/diagnostic-catalog.js +0 -1
- package/dist/shared/diagnostics.js +0 -1
- package/dist/shared/operations.js +0 -1
- package/dist/shared/protocol.js +0 -1
- package/dist/shared/routes.js +0 -1
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/runtimes/launcher/linux-x64/aib +0 -0
- package/runtimes/launcher/win-x64/aib.exe +0 -0
|
@@ -1,3 +1,1319 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
`)}async function ye(e,t,n,o="modulePlan.preview"){(0,h.recordModulePlanTimeline)(e,void 0,"modulePlan.preview.resolveInstance.start",{operation:o});const r=await(0,D.resolveCompatibleTargetInstance)(e,ue.CLI_COMMAND_IDS.modulePlan,n);(0,h.recordModulePlanTimeline)(e,void 0,"modulePlan.preview.resolveInstance.end",{operation:o});const s=await(0,D.fetchEffectiveConfig)(r.entry,n),i=Se(e,t),u=ct(e,t,i,s),f=(0,d.buildModulePlanId)(u),c=await Ze(e,u,n,r),m=(0,d.hashFile)(i),p=(0,d.buildModulePlanHash)(u,m,c),P={planId:f,planHash:p,createdAt:new Date().toISOString(),cwd:F.resolve(e),sourceFile:i,sourceHash:m,executable:c.ok!==!1,normalizedRequest:u,inspectPayload:{requests:[u]},previewDir:"",previewResult:c};(0,d.writeModulePlanRecord)(e,P);const g={...c.ok===!1?{ok:!1,code:"MODULE_PLAN_BLOCKED"}:{},operation:o,planId:f,executable:c.ok!==!1,summary:Ie(c,!1),...typeof c.moduleCount=="number"?{moduleCount:c.moduleCount}:{},...Array.isArray(c.targets)?{targets:c.targets}:{},...Array.isArray(c.blocking)&&c.blocking.length>0?{blocking:c.blocking}:{},next:c.ok===!1?"Fix the plan, then rerun modulePlan preview.":`aib modulePlan apply ${f}`};return(0,$.attachAgentText)(g,z(g))}function Xe(e,t,n){if(t==="pending")return[];try{const o=(0,d.readModulePlanRecord)(e,t);return he(e,Q(o.normalizedRequest),n)}catch{return[]}}async function Ze(e,t,n,o){const r=Q(t),s=a(t.sourceFile)??"",i=await et(e,o,s,r,n);if(i)return i;const u=[],f=[],c=[];for(const m of r){await(0,R.yieldToEventLoop)();const p=a(m.targetFile)??"",P=U(m);(0,h.recordModulePlanTimeline)(e,void 0,"modulePlan.preview.row.start",{target:(0,d.formatRelativePath)(e,p),entityCount:P.length});const g=await Pe(e,s,p,P,m,!1,n);(0,h.recordModulePlanTimeline)(e,void 0,"modulePlan.preview.row.end",{target:(0,d.formatRelativePath)(e,p),ok:g.ok!==!1});const l=Ce("preview",e,s,p,P,g);if(f.push(l),u.push({file:(0,d.formatRelativePath)(e,p),entities:P,...typeof l.summary=="string"?{summary:l.summary}:{}}),l.ok===!1){c.push(l);break}await(0,R.yieldToEventLoop)()}return{op:"modulePlan",ok:c.length===0,sourceFile:s,moduleCount:r.length,targets:u,rows:f,...c.length>0?{blocking:c}:{},cycles:"notChecked"}}async function et(e,t,n,o,r){const s=await(0,ie.postJson)(t.entry,se.EXTENSION_ROUTES.inspect,{requests:[{op:"file",sourceFile:n,includeRanges:!1}]},(0,D.extensionRequestOptions)(r)),i=Array.isArray(s.results)?s.results.find(y):null,u=Array.isArray(i?.symbols)?i.symbols.filter(y):[];if(u.length===0)return null;const f=[],c=[],m=[];for(const p of o){const P=a(p.targetFile)??"",g=U(p),l={target:(0,d.formatRelativePath)(e,P),entities:g,ok:!0,summary:P&&!O.existsSync(P)?"target will be created":"target ready"};for(const C of tt(p)){const w=u.filter(A=>nt(A,C));if(w.length===0){l.ok=!1,l.entity=C.raw,l.code="MODULE_PLAN_SYMBOL_NOT_FOUND",l.error=`Symbol not found: ${C.raw}`,l.source=(0,d.formatRelativePath)(e,n);break}if(!C.symbolKind&&w.length>1){l.ok=!1,l.entity=C.raw,l.code="MODULE_PLAN_SYMBOL_AMBIGUOUS",l.error=`Ambiguous symbol: ${C.raw}`,l.available=w.map(A=>`${a(A.kind)??"symbol"}:${a(A.name)??C.symbolName}`),l.source=(0,d.formatRelativePath)(e,n);break}}if(f.push(W(l)),c.push({file:(0,d.formatRelativePath)(e,P),entities:g,...typeof l.summary=="string"?{summary:l.summary}:{}}),l.ok===!1){m.push(W(l));break}}return m.length===0?null:{op:"modulePlan",ok:!1,sourceFile:n,moduleCount:o.length,targets:c,rows:f,blocking:m,cycles:"notChecked"}}function tt(e){return(Array.isArray(e.symbols)?e.symbols.filter(y):[]).map(n=>{const o=a(n.raw)??a(n.symbolName)??"",r=a(n.symbolName)??o,s=a(n.symbolKind)??void 0;return{raw:o,symbolName:r,...s?{symbolKind:s}:{}}})}function nt(e,t){return a(e.name)!==t.symbolName?!1:!t.symbolKind||a(e.kind)===t.symbolKind}async function J(e,t,n,o="modulePlan.apply",r,s){const i=(0,d.readModulePlanRecord)(e,t);if(i.executable===!1||i.previewResult.ok===!1)throw new k.CliError("APPLY_MODULE_PLAN_NOT_EXECUTABLE","Module plan has blocking move diagnostics. Fix the plan before applying.",{planId:t,next:"Fix the plan, then rerun modulePlan preview."});if((0,d.hashFile)(i.sourceFile)!==i.sourceHash)throw new k.CliError("APPLY_MODULE_PLAN_SOURCE_CHANGED","Source file changed after modulePlan preview. Rerun modulePlan preview.",{planId:t,sourceFile:(0,d.formatRelativePath)(e,i.sourceFile)});const f=Q(i.normalizedRequest),c=[],m=new Set,p=i.sourceFile,P=f.map(M=>a(M.targetFile)).filter(M=>!!M),g=Z([p,...P]),l=s??ot(e,i,o,f,r);(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.apply.start",{operation:o,rowCount:f.length,entityCount:l.entityCount});const C={executionId:l.executionId,planId:i.planId,parentOperation:o,sourceFile:(0,d.formatRelativePath)(e,p),rowCount:f.length,entityCount:l.entityCount},w=(0,fe.startCentralMetricSpan)({kind:"mutation.execution",operation:o,cwd:F.resolve(e),...C});I(e,l),(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.apply.execution.persisted"),await(0,R.yieldToEventLoop)(),(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.cycles.pre.start",{fileCount:g.length});const A=be(e,g);(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.cycles.pre.end",{componentCount:j(A.componentCount)??null});try{for(let b=0;b<f.length;b+=1){await(0,R.yieldToEventLoop)();const S=f[b],N=a(S.targetFile)??"",K=U(S),Fe=Mt(c.filter(L=>L.ok!==!1));(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.apply.row.start",{rowIndex:b,target:(0,d.formatRelativePath)(e,N),entityCount:K.length});const oe=await Pe(e,p,N,K,S,!0,n,{onProgress:L=>it(e,l,Fe,L,Array.from(m)),metricsContext:{...C,rowIndex:b,rowTargetFile:(0,d.formatRelativePath)(e,N)}}),q=Ce("execute",e,p,N,K,oe);c.push(q),(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.apply.row.end",{rowIndex:b,target:(0,d.formatRelativePath)(e,N),ok:q.ok!==!1});for(const L of x(oe.filesWritten))m.add((0,d.resolveCliFilePath)(e,L));if(rt(e,l,q,Array.from(m)),await(0,R.yieldToEventLoop)(),q.ok===!1)break}const M=c.every(b=>b.ok!==!1);if(M){l.phase="postMutation.cycles",I(e,l),(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.cycles.phase.persisted"),await(0,R.yieldToEventLoop)(),await at();const b=Z([...g,...Array.from(m)]);(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.cycles.post.start",{fileCount:b.length});const S=be(e,b);(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.cycles.post.end",{componentCount:j(S.componentCount)??null}),l.postMutation={cycles:st(A,S,new Set(_e(e,b)))}}l.status=M?"completed":"failed",M&&(l.phase="completed"),l.failedRows=c.filter(b=>b.ok===!1).length,l.filesWritten=Array.from(m).sort((b,S)=>b.localeCompare(S));const T=await Re(e,p,n);T&&(l.remainingSource=T),I(e,l),(0,h.recordModulePlanTimeline)(e,l.executionId,"modulePlan.apply.execution.final.persisted",{status:l.status,completedRows:l.completedRows,completedEntities:l.completedEntities})}catch(M){throw l.status="failed",l.error=M instanceof Error?M.message:String(M),l.filesWritten=Array.from(m).sort((T,b)=>T.localeCompare(b)),I(e,l),w.end({ok:!1,status:l.status,error:M instanceof Error?M.message:String(M),completedRows:l.completedRows,failedRows:l.failedRows,completedEntities:l.completedEntities,filesWrittenCount:l.filesWritten.length}),M}const v=c.every(M=>M.ok!==!1),ee=v?[]:he(e,f,c.length),te=v?[]:[...ge(c),...ee];Ee(e,l);const ne={...v?{}:{ok:!1,code:"MODULE_PLAN_APPLY_FAILED"},operation:o,applied:v,planId:i.planId,executionId:l.executionId,expectEmpty:i.normalizedRequest.expectEmpty===!0,summary:Ie({rows:[...c,...ee]},!0),rows:c,...te.length>0?{notRun:te}:{},remainingSource:await Re(e,p,n),...l.postMutation?{postMutation:l.postMutation}:{},...G(i.previewResult).length>0?{createdFiles:ke(G(i.previewResult),8)}:{},filesWritten:X(Array.from(m).sort((M,T)=>M.localeCompare(T)).map(M=>(0,d.formatRelativePath)(e,M))),...v?{}:{next:"Fix failed move row and rerun modulePlan preview."}};return w.end({ok:v,status:l.status,completedRows:l.completedRows,failedRows:l.failedRows,completedEntities:l.completedEntities,filesWrittenCount:l.filesWritten.length}),(0,fe.recordCentralMetric)({kind:"mutation.summary",operation:o,cwd:F.resolve(e),ok:v,status:l.status,executionId:l.executionId,planId:i.planId,rowCount:l.rowCount,completedRows:l.completedRows,failedRows:l.failedRows,entityCount:l.entityCount,completedEntities:l.completedEntities,filesWrittenCount:l.filesWritten.length}),(0,$.attachAgentText)(ne,z(ne))}function he(e,t,n){return t.slice(n).map(o=>W({target:(0,d.formatRelativePath)(e,a(o.targetFile)??""),entities:U(o)}))}function ge(e){return e.map(t=>W({target:a(t.target)??"",entities:x(t.notRunEntities)})).filter(t=>x(t.entities).length>0)}async function Pe(e,t,n,o,r,s,i,u={}){const f=await(0,Ue.runMoveToFile)(e,{sourceFile:t,targetFile:n,entities:o,execute:s},i,[],u);return f.ok!==!1,f}function ot(e,t,n,o,r){const s=new Date().toISOString(),i=r??(0,d.buildModulePlanExecutionId)(t.planId),u=we(o);return{executionId:i,planId:t.planId,operation:n,cwd:F.resolve(e),sourceFile:t.sourceFile,status:"running",phase:"mutation",startedAt:s,updatedAt:s,rowCount:o.length,completedRows:0,failedRows:0,entityCount:u,completedEntities:0,expectEmpty:t.normalizedRequest.expectEmpty===!0,filesWritten:[],rows:[],timeoutHint:ut(t.normalizedRequest),productStorageDir:(0,H.productStorageRoot)()}}function Me(e,t,n,o){const r=new Date().toISOString(),s=Array.isArray(o.modules)?o.modules.filter(y):[];return{executionId:t,planId:"pending",operation:n,cwd:F.resolve(e),sourceFile:o.sourceFile||o.file?Se(e,o):"",status:"running",phase:"mutation",startedAt:r,updatedAt:r,rowCount:s.length,completedRows:0,failedRows:0,entityCount:we(s),completedEntities:0,expectEmpty:o.expectEmpty===!0,filesWritten:[],rows:[],productStorageDir:(0,H.productStorageRoot)()}}function rt(e,t,n,o){t.rows.push(n),t.completedRows=t.rows.filter(r=>r.ok!==!1).length,t.failedRows=t.rows.filter(r=>r.ok===!1).length,t.completedEntities=dt(t.rows),t.filesWritten=o.sort((r,s)=>r.localeCompare(s)),n.ok===!1&&(t.status="failed"),I(e,t)}function it(e,t,n,o,r){t.completedEntities=n+o.completedEntities,t.filesWritten=Array.from(new Set([...r,...o.filesWritten.map(s=>(0,d.resolveCliFilePath)(e,s))])).sort((s,i)=>s.localeCompare(i)),o.ok||(t.status="failed"),I(e,t)}function I(e,t){(0,d.writeModulePlanExecutionStatus)(e,t),Ee(e,t)}function Ee(e,t){if(!(0,ae.sessionWorkspaceExists)(e))return null;try{return(0,ae.saveSessionOutputJson)(e,"execution",`modulePlan-${t.executionId}`,t)}catch{return null}}function be(e,t){const n=_e(e,t).filter(r=>O.existsSync((0,d.resolveCliFilePath)(e,r)));if(n.length===0)return{op:"cycles",componentCount:0,components:[]};const o=["cycles"];for(const r of n)o.push("--files",r);return o.push("--detail","imports","--limit","50"),(0,me.runInspectCycles)(e,o,void 0)}function st(e,t,n){const o=new Set(B(e).map(xe)),r=B(t).filter(s=>x(s.files).some(i=>n.has(i))&&!o.has(xe(s)));return{status:r.length>0?"new-or-changed":"none",detail:"imports",newOrChangedCount:r.length,preComponentCount:j(e.componentCount)??B(e).length,postComponentCount:j(t.componentCount)??B(t).length,components:r}}function B(e){return(Array.isArray(e.components)?e.components:[]).filter(y).map(t=>({kind:a(t.kind)??"mixed",files:x(t.files).sort(),chain:a(t.chain)??"",...y(t.cycle)?{cycle:t.cycle}:{},imports:lt(t)}))}function lt(e){const t=y(e.cycle)?e.cycle:{};return x(t.imports)}function xe(e){return`${a(e.kind)??"mixed"}:${x(e.files).sort().join("|")}`}function _e(e,t){return Z(t.map(n=>(0,d.formatRelativePath)(e,(0,d.resolveCliFilePath)(e,n))))}async function at(){const e=process.env[_.CLI_ENV.testPostMutationCyclesDelayMs],t=e?Number.parseInt(e,10):0;!Number.isFinite(t)||t<=0||await new Promise(n=>setTimeout(n,Math.min(t,6e4)))}function Y(e){const t=e.filesWritten.length,n=`${e.completedRows}/${e.rowCount}`,o=e.entityCount??0,r=e.completedEntities??0,s=o>0?`, ${Math.floor(r/o*100)}% entities`:"",i=e.status==="running"&&e.phase==="postMutation.cycles"?`${n} rows${s}`:`${e.status==="running"?"in progress":e.status}, ${n} rows${s}`;return t>0?`${i}, ${t} ${t===1?"file":"files"} written`:i}function ut(e){return(0,de.buildModulePlanTimeoutHintFromRequest)(e)??{recommendedTimeoutMs:9e4,rowCount:0,symbolCount:0,message:"If the calling agent times out, inspect progress with: aib execution status last"}}function ct(e,t,n,o){const r=t.modules??[];if(r.length===0)throw new k.CliError("MODULE_PLAN_MODULES_REQUIRED","modulePlan expects a non-empty modules array.");const s=r.map(i=>{const u=i.target??i.targetFile??i.file;if(!u)throw new k.CliError("MODULE_PLAN_TARGET_REQUIRED","Each module expects target.");const f=i.entities??i.symbols??[];if(f.length===0)throw new k.CliError("MODULE_PLAN_ENTITIES_REQUIRED","Each module expects a non-empty entities array.");return{targetFile:(0,d.resolveCliFilePath)(e,u),symbols:f.map(c=>ft(c,o))}});return{op:"modulePlan",sourceFile:n,...t.expectEmpty===!0?{expectEmpty:!0}:{},modules:s}}function ft(e,t){if(typeof e=="string"){const o=(0,ce.parseInspectSelector)(e,t);return{raw:e,symbolName:o.symbolName,...o.symbolKind?{symbolKind:o.symbolKind}:{}}}const n=a(e.entity)??a(e.selector)??a(e.raw);if(n){const o=(0,ce.parseInspectSelector)(n,t);return{raw:n,symbolName:o.symbolName,...o.symbolKind?{symbolKind:o.symbolKind}:{}}}return Ne(e)}function Ce(e,t,n,o,r,s){const i={target:(0,d.formatRelativePath)(t,o),entities:r,ok:s.ok!==!1,summary:typeof s.summary=="string"?s.summary:null};if(e==="preview"&&typeof s.previewId=="string"&&(i.movePreviewId=s.previewId),Array.isArray(s.files)&&(i.files=s.files),Array.isArray(s.filesWritten)&&(i.filesWritten=s.filesWritten),s.ok===!1){const u=pt(s),f=a(u?.entity)??r[0]??null,m=(Array.isArray(s.results)?s.results.filter(y):[]).filter(g=>g.ok!==!1).map(g=>a(g.entity)).filter(g=>!!g),p=f?r.indexOf(f):-1,P=p>=0?r.slice(p+1):[];i.appliedEntities=m,i.notRunEntities=P,i.entity=f,i.code=a(u?.code)??a(s.code)??"MOVE_TO_FILE_FAILED",i.error=yt(a(u?.error)??a(s.error)??"Move failed."),i.hint=mt(t,a(u?.code),a(u?.hint)),i.next=a(u?.next),i.source=(0,d.formatRelativePath)(t,n)}return W(i)}function dt(e){return e.reduce((t,n)=>n.ok===!1?t+x(n.appliedEntities).length:t+x(n.entities).length,0)}function mt(e,t,n){return n?t==="TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE"?(0,le.useSessionGuidance)(e,"modulePlan.tsMoveUnsupportedHint",n,(0,le.readSessionNumberPref)(e,"diagnostics.hintLimit",2))??null:n:null}function pt(e){return(Array.isArray(e.results)?e.results.filter(y):[]).find(n=>n.ok===!1)??null}function yt(e){return e.replace(/^TypeScript refactor failed: Debug Failure\. False expression: /,"")}function Ie(e,t){const n=Array.isArray(e.rows)?e.rows.filter(y):[],o=n.reduce((m,p)=>m+x(p.entities).length,0),r=n.filter(m=>m.ok===!1).length,s=n.length,i=t?G(e).length:n.filter(m=>Ae(m)).length,u=t?Array.from(new Set(n.flatMap(m=>x(m.filesWritten).filter(p=>!p.startsWith("+"))))).length:0;if(r>0)return`${o} ${o===1?"symbol":"symbols"}, ${r} blocked`;const f=`${o} ${o===1?"symbol":"symbols"}, ${s} ${s===1?"target":"targets"} ${t?"moved":"ready"}`,c=[];return t&&u>0&&c.push(`${u} ${u===1?"file":"files"} written`),i>0&&c.push(`${i} ${i===1?"file":"files"} ${t?"created":"will be created"}`),c.length>0?`${f}; ${c.join(", ")}`:f}function Ae(e){return typeof e.summary=="string"&&e.summary.includes("target will be created")}function G(e){return(Array.isArray(e.rows)?e.rows.filter(y):[]).filter(n=>Ae(n)).map(n=>a(n.target)).filter(n=>!!n)}function z(e){const t=[],n=a(e.operation)??"modulePlan",o=a(e.planId),r=a(e.executionId);if(n!=="execution.status"){const i=n==="modulePlan.apply"||n==="modulePlan.execute"?r??o:o;t.push(i?`${n} ${i}`:n)}e.executable===!1&&t.push("blocked"),typeof e.summary=="string"&&t.push(e.summary),n==="execution.status"&&e.status==="running"&&e.phase==="postMutation.cycles"&&(t.push("mutation completed"),t.push("checking cycles"));const s=n==="execution.status"&&e.status==="running"&&e.phase==="postMutation.cycles";if(Array.isArray(e.targets)&&e.targets.length>0){t.push("targets:");for(const i of e.targets.filter(y)){const u=a(i.file),f=x(i.entities);u&&t.push(`${u}: ${V(f,5)}`)}}if(!s&&Array.isArray(e.rows)&&e.rows.length>0){t.push("moves:");for(const i of e.rows.filter(y)){const u=a(i.target),f=i.ok===!1&&x(i.appliedEntities).length>0?x(i.appliedEntities):x(i.entities);if(u&&f.length>0&&t.push(`${u}: ${V(f,5)}`),i.ok===!1){const c=a(i.code),m=a(i.error);c&&t.push(`code: ${c}`),m&&t.push(m)}}}if(Array.isArray(e.notRun)&&e.notRun.length>0){t.push("not run:");for(const i of e.notRun.filter(y)){const u=a(i.target),f=x(i.entities);u&&t.push(`${u}: ${V(f,5)}`)}}if(y(e.remainingSource)){const i=x(e.remainingSource.symbols);i.length===0?e.remainingSource.hasNonDeclarationText===!0?(t.push("source has no declarations"),t.push("source file still has non-declaration text")):t.push("source is empty"):e.expectEmpty===!0&&(t.push("source still contains:"),t.push(V(i,15)))}if(Array.isArray(e.blocking)&&e.blocking.length>0&&ht(t,e.blocking.filter(y)),e.status!=="running"&&Array.isArray(e.filesWritten)&&e.filesWritten.length>0){t.push("filesWritten:");for(const i of e.filesWritten.filter(u=>typeof u=="string"))t.push(i)}return y(e.postMutation)&&y(e.postMutation.cycles)&>(t,e.postMutation.cycles),typeof e.next=="string"&&!(Array.isArray(e.blocking)&&e.blocking.length>0)&&t.push(`next: ${e.next}`),t.join(`
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.runApplyModulePlan = runApplyModulePlan;
|
|
40
|
+
exports.reviseCachedModulePlan = reviseCachedModulePlan;
|
|
41
|
+
exports.readCachedModulePlanExecution = readCachedModulePlanExecution;
|
|
42
|
+
exports.formatModulePlanText = formatModulePlanText;
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const fs = __importStar(require("node:fs"));
|
|
45
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
46
|
+
const zod_1 = require("zod");
|
|
47
|
+
const agent_text_1 = require("../shared/agent-text");
|
|
48
|
+
const errors_1 = require("../shared/errors");
|
|
49
|
+
const session_workspace_1 = require("./session-workspace");
|
|
50
|
+
const inspect_selector_1 = require("./inspect-selector");
|
|
51
|
+
const json_file_input_1 = require("./json-file-input");
|
|
52
|
+
const module_plan_cache_1 = require("./module-plan-cache");
|
|
53
|
+
const central_metrics_1 = require("../metrics/central-metrics");
|
|
54
|
+
const module_plan_timeout_1 = require("./module-plan-timeout");
|
|
55
|
+
const inspect_cycles_1 = require("./inspect-cycles");
|
|
56
|
+
const env_vars_1 = require("../config/env-vars");
|
|
57
|
+
const runtime_lifecycle_1 = require("../session/runtime-lifecycle");
|
|
58
|
+
const product_storage_1 = require("../config/product-storage");
|
|
59
|
+
const event_loop_1 = require("../shared/event-loop");
|
|
60
|
+
const module_plan_timeline_1 = require("../diagnostics/module-plan-timeline");
|
|
61
|
+
const resolve_1 = require("../config/resolve");
|
|
62
|
+
const import_rules_1 = require("../config/import-rules");
|
|
63
|
+
const mutation_comments_1 = require("../config/mutation-comments");
|
|
64
|
+
const semantic_move_standalone_engine_1 = require("../mutation/semantic-move-standalone-engine");
|
|
65
|
+
const semantic_move_metrics_1 = require("../mutation/semantic-move-metrics");
|
|
66
|
+
const semantic_move_declarations_1 = require("../mutation/semantic-move-declarations");
|
|
67
|
+
const module_plan_standalone_1 = require("./module-plan-standalone");
|
|
68
|
+
const ModuleSchema = zod_1.z.object({
|
|
69
|
+
targetFile: zod_1.z.string().min(1).optional(),
|
|
70
|
+
target: zod_1.z.string().min(1).optional(),
|
|
71
|
+
file: zod_1.z.string().min(1).optional(),
|
|
72
|
+
symbols: zod_1.z.array(zod_1.z.union([
|
|
73
|
+
zod_1.z.string().min(1),
|
|
74
|
+
zod_1.z.object({}).passthrough()
|
|
75
|
+
])).optional(),
|
|
76
|
+
entities: zod_1.z.array(zod_1.z.union([
|
|
77
|
+
zod_1.z.string().min(1),
|
|
78
|
+
zod_1.z.object({}).passthrough()
|
|
79
|
+
])).optional()
|
|
80
|
+
}).passthrough();
|
|
81
|
+
const ApplyModulePlanPayloadSchema = zod_1.z.object({
|
|
82
|
+
sourceFile: zod_1.z.string().min(1).optional(),
|
|
83
|
+
file: zod_1.z.string().min(1).optional(),
|
|
84
|
+
facadeFile: zod_1.z.string().min(1).optional(),
|
|
85
|
+
facade: zod_1.z.string().min(1).optional(),
|
|
86
|
+
modules: zod_1.z.array(ModuleSchema).optional(),
|
|
87
|
+
execute: zod_1.z.boolean().optional(),
|
|
88
|
+
planId: zod_1.z.string().min(1).optional()
|
|
89
|
+
}).passthrough();
|
|
90
|
+
async function runApplyModulePlan(cwd, restArgs, rawPayload, options = {}, modulePlanOptions = {}) {
|
|
91
|
+
const flagPlanId = readFlagValue(restArgs, "--plan");
|
|
92
|
+
const fromJson = readFlagValue(restArgs, "--from-json");
|
|
93
|
+
if (fromJson && rawPayload !== undefined) {
|
|
94
|
+
throw new errors_1.CliError("APPLY_MODULE_PLAN_INPUT_SOURCE_CONFLICT", "Use either modulePlan --stdin or modulePlan --from-json, not both.");
|
|
95
|
+
}
|
|
96
|
+
const inputPayload = fromJson ? (0, json_file_input_1.readJsonObjectFile)(cwd, fromJson, "INVALID_MODULE_PLAN_JSON_FILE") : rawPayload;
|
|
97
|
+
const execute = restArgs.includes("--execute") || payloadExecute(inputPayload);
|
|
98
|
+
const payload = inputPayload === undefined ? {} : ApplyModulePlanPayloadSchema.parse(inputPayload);
|
|
99
|
+
const payloadPlanId = typeof payload.planId === "string" ? payload.planId : undefined;
|
|
100
|
+
const planId = flagPlanId ?? payloadPlanId;
|
|
101
|
+
if (planId && inputPayload === undefined) {
|
|
102
|
+
return applyCachedModulePlan(cwd, planId, options, "modulePlan.apply", modulePlanOptions.executionId);
|
|
103
|
+
}
|
|
104
|
+
if (execute && planId) {
|
|
105
|
+
return applyCachedModulePlan(cwd, planId, options, "modulePlan.apply", modulePlanOptions.executionId);
|
|
106
|
+
}
|
|
107
|
+
if (execute && !planId) {
|
|
108
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.enter", { hasExecutionId: Boolean(modulePlanOptions.executionId) });
|
|
109
|
+
const syncWaitMs = readModulePlanSyncWaitMs();
|
|
110
|
+
if (modulePlanOptions.executionId && syncWaitMs > 0) {
|
|
111
|
+
const pendingExecution = createPendingModulePlanExecutionStatus(cwd, modulePlanOptions.executionId, "modulePlan.execute", payload);
|
|
112
|
+
pendingExecution.phase = "preview";
|
|
113
|
+
persistModulePlanExecution(cwd, pendingExecution);
|
|
114
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.pending.persisted", {
|
|
115
|
+
rowCount: pendingExecution.rowCount,
|
|
116
|
+
entityCount: pendingExecution.entityCount,
|
|
117
|
+
syncWaitMs
|
|
118
|
+
});
|
|
119
|
+
const startedAtMs = Date.now();
|
|
120
|
+
const backgroundEnv = captureModulePlanBackgroundEnv();
|
|
121
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.background.schedule");
|
|
122
|
+
const jobPromise = startModulePlanBackgroundJob(() => (0, product_storage_1.runWithProductStorageOverride)(backgroundEnv[env_vars_1.CLI_ENV.productStorageDir], () => withModulePlanBackgroundEnv(backgroundEnv, () => {
|
|
123
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.background.start");
|
|
124
|
+
return runModulePlanExecutePayload(cwd, payload, options, modulePlanOptions, pendingExecution);
|
|
125
|
+
})));
|
|
126
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.wait.start", { syncWaitMs });
|
|
127
|
+
const waitResult = await waitForModulePlanJob(jobPromise, syncWaitMs);
|
|
128
|
+
if (waitResult.status === "result") {
|
|
129
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.wait.result");
|
|
130
|
+
return waitResult.result;
|
|
131
|
+
}
|
|
132
|
+
jobPromise.catch(() => undefined);
|
|
133
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, modulePlanOptions.executionId, "modulePlan.execute.wait.deadline", {
|
|
134
|
+
elapsedMs: Date.now() - startedAtMs
|
|
135
|
+
});
|
|
136
|
+
return buildModulePlanStillRunningResponse(cwd, modulePlanOptions.executionId, "modulePlan.execute", Date.now() - startedAtMs);
|
|
137
|
+
}
|
|
138
|
+
return runModulePlanExecutePayload(cwd, payload, options, modulePlanOptions);
|
|
139
|
+
}
|
|
140
|
+
return previewModulePlan(cwd, payload, options);
|
|
141
|
+
}
|
|
142
|
+
async function runModulePlanExecutePayload(cwd, payload, options, modulePlanOptions, pendingExecution) {
|
|
143
|
+
const execution = pendingExecution ?? (modulePlanOptions.executionId
|
|
144
|
+
? createPendingModulePlanExecutionStatus(cwd, modulePlanOptions.executionId, "modulePlan.execute", payload)
|
|
145
|
+
: undefined);
|
|
146
|
+
if (execution) {
|
|
147
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.executePayload.start");
|
|
148
|
+
execution.phase = "preview";
|
|
149
|
+
persistModulePlanExecution(cwd, execution);
|
|
150
|
+
await (0, event_loop_1.yieldToEventLoop)();
|
|
151
|
+
}
|
|
152
|
+
let preview;
|
|
153
|
+
try {
|
|
154
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution?.executionId, "modulePlan.preview.start");
|
|
155
|
+
preview = await previewModulePlan(cwd, payload, options, "modulePlan.execute-preview");
|
|
156
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution?.executionId, "modulePlan.preview.end", {
|
|
157
|
+
ok: preview.ok !== false,
|
|
158
|
+
moduleCount: typeof preview.moduleCount === "number" ? preview.moduleCount : null
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (execution) {
|
|
163
|
+
execution.status = "failed";
|
|
164
|
+
execution.error = error instanceof Error ? error.message : String(error);
|
|
165
|
+
persistModulePlanExecution(cwd, execution);
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
if (preview.ok === false || typeof preview.planId !== "string") {
|
|
170
|
+
if (typeof preview.planId === "string" && (isRetryableModulePlanOverlapBlockedPreview(preview) || isNonRetryableModulePlanProviderLimitationBlockedPreview(preview))) {
|
|
171
|
+
const record = (0, module_plan_cache_1.readModulePlanRecord)(cwd, preview.planId);
|
|
172
|
+
const previewResult = {
|
|
173
|
+
...record.previewResult,
|
|
174
|
+
ok: true,
|
|
175
|
+
retryableBlocking: isRetryableModulePlanOverlapBlockedPreview(preview) && Array.isArray(record.previewResult.blocking) ? record.previewResult.blocking : [],
|
|
176
|
+
providerLimitationBlocking: isNonRetryableModulePlanProviderLimitationBlockedPreview(preview) && Array.isArray(record.previewResult.blocking) ? record.previewResult.blocking : []
|
|
177
|
+
};
|
|
178
|
+
delete previewResult.blocking;
|
|
179
|
+
(0, module_plan_cache_1.writeModulePlanRecord)(cwd, {
|
|
180
|
+
...record,
|
|
181
|
+
executable: true,
|
|
182
|
+
previewResult
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (execution) {
|
|
187
|
+
execution.status = "failed";
|
|
188
|
+
execution.planId = typeof preview.planId === "string" ? preview.planId : execution.planId;
|
|
189
|
+
execution.error = "modulePlan preview failed before execute.";
|
|
190
|
+
persistModulePlanExecution(cwd, execution);
|
|
191
|
+
}
|
|
192
|
+
return preview;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (preview.ok === false && typeof preview.planId === "string" && isRetryableModulePlanOverlapBlockedPreview(preview)) {
|
|
196
|
+
preview.ok = true;
|
|
197
|
+
delete preview.code;
|
|
198
|
+
preview.executable = true;
|
|
199
|
+
}
|
|
200
|
+
if (preview.ok === false && typeof preview.planId === "string" && isNonRetryableModulePlanProviderLimitationBlockedPreview(preview)) {
|
|
201
|
+
preview.ok = true;
|
|
202
|
+
delete preview.code;
|
|
203
|
+
preview.executable = true;
|
|
204
|
+
}
|
|
205
|
+
if (preview.ok === false || typeof preview.planId !== "string") {
|
|
206
|
+
if (execution) {
|
|
207
|
+
execution.status = "failed";
|
|
208
|
+
execution.planId = typeof preview.planId === "string" ? preview.planId : execution.planId;
|
|
209
|
+
execution.error = "modulePlan preview failed before execute.";
|
|
210
|
+
persistModulePlanExecution(cwd, execution);
|
|
211
|
+
}
|
|
212
|
+
return preview;
|
|
213
|
+
}
|
|
214
|
+
if (execution) {
|
|
215
|
+
execution.planId = preview.planId;
|
|
216
|
+
execution.phase = "mutation";
|
|
217
|
+
persistModulePlanExecution(cwd, execution);
|
|
218
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.mutation.phase.persisted", { planId: preview.planId });
|
|
219
|
+
await (0, event_loop_1.yieldToEventLoop)();
|
|
220
|
+
}
|
|
221
|
+
return applyCachedModulePlan(cwd, preview.planId, options, "modulePlan.execute", modulePlanOptions.executionId);
|
|
222
|
+
}
|
|
223
|
+
function isRetryableModulePlanOverlapBlockedPreview(preview) {
|
|
224
|
+
const blocking = Array.isArray(preview.blocking) ? preview.blocking.filter(isJsonObject) : [];
|
|
225
|
+
if (blocking.length === 0) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return blocking.every((row) => readString(row.code) === "TS_MOVE_TO_FILE_REFACTOR_FAILED" &&
|
|
229
|
+
/Changes overlap/i.test(readString(row.error) ?? ""));
|
|
230
|
+
}
|
|
231
|
+
function isNonRetryableModulePlanProviderLimitationBlockedPreview(preview) {
|
|
232
|
+
const blocking = Array.isArray(preview.blocking) ? preview.blocking.filter(isJsonObject) : [];
|
|
233
|
+
if (blocking.length === 0) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
return blocking.every((row) => {
|
|
237
|
+
const providerLimitations = Array.isArray(row.providerLimitations) ? row.providerLimitations.filter(isJsonObject) : [];
|
|
238
|
+
if (providerLimitations.length > 0) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return readString(row.code) === "TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE";
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function reviseCachedModulePlan(cwd, planId) {
|
|
245
|
+
const record = (0, module_plan_cache_1.readModulePlanRecord)(cwd, planId);
|
|
246
|
+
const response = {
|
|
247
|
+
operation: "modulePlan.revise",
|
|
248
|
+
fromPlanId: planId,
|
|
249
|
+
planId,
|
|
250
|
+
executable: record.executable !== false,
|
|
251
|
+
summary: record.executable === false
|
|
252
|
+
? "semantic module plan still has blocking move diagnostics"
|
|
253
|
+
: "semantic module plan already executable",
|
|
254
|
+
changes: [],
|
|
255
|
+
resolved: [],
|
|
256
|
+
remainingBlocking: collectBlockingRows(record.previewResult),
|
|
257
|
+
next: record.executable === false
|
|
258
|
+
? "Fix the plan manually, then rerun modulePlan preview."
|
|
259
|
+
: `aib modulePlan apply ${planId}`
|
|
260
|
+
};
|
|
261
|
+
if (record.executable === false) {
|
|
262
|
+
response.ok = false;
|
|
263
|
+
response.code = "MODULE_PLAN_REVISE_NOT_APPLICABLE";
|
|
264
|
+
}
|
|
265
|
+
return (0, agent_text_1.attachAgentText)(response, formatModulePlanText(response));
|
|
266
|
+
}
|
|
267
|
+
function readCachedModulePlanExecution(cwd, executionId) {
|
|
268
|
+
const status = (0, module_plan_cache_1.readModulePlanExecutionStatus)(cwd, executionId);
|
|
269
|
+
const rows = status.rows;
|
|
270
|
+
const futureNotRun = status.status === "failed"
|
|
271
|
+
? readNotRunRowsForExecution(cwd, status.planId, rows.length)
|
|
272
|
+
: [];
|
|
273
|
+
const notRun = [...compactNotRunEntitiesInRows(rows), ...futureNotRun];
|
|
274
|
+
const response = {
|
|
275
|
+
operation: "execution.status",
|
|
276
|
+
executionId: status.executionId,
|
|
277
|
+
planId: status.planId,
|
|
278
|
+
status: status.status,
|
|
279
|
+
summary: buildExecutionSummary(status),
|
|
280
|
+
progress: `${status.completedRows}/${status.rowCount}`,
|
|
281
|
+
entityProgress: `${status.completedEntities ?? 0}/${status.entityCount ?? 0}`,
|
|
282
|
+
filesWritten: summarizeWrittenFiles(status.filesWritten.map((file) => (0, module_plan_cache_1.formatRelativePath)(cwd, file)).sort((left, right) => left.localeCompare(right))),
|
|
283
|
+
rows,
|
|
284
|
+
...(notRun.length > 0 ? { notRun } : {}),
|
|
285
|
+
...(status.remainingSource ? { remainingSource: status.remainingSource } : {}),
|
|
286
|
+
...(status.phase ? { phase: status.phase } : {}),
|
|
287
|
+
...(status.postMutation ? { postMutation: status.postMutation } : {}),
|
|
288
|
+
updatedAt: status.updatedAt,
|
|
289
|
+
...(status.error ? { error: status.error } : {})
|
|
290
|
+
};
|
|
291
|
+
return (0, agent_text_1.attachAgentText)(response, formatModulePlanText(response));
|
|
292
|
+
}
|
|
293
|
+
function startModulePlanBackgroundJob(job) {
|
|
294
|
+
return (0, runtime_lifecycle_1.trackSessionBackgroundPromise)(new Promise((resolve, reject) => {
|
|
295
|
+
setImmediate(() => {
|
|
296
|
+
job().then(resolve, reject);
|
|
297
|
+
});
|
|
298
|
+
}), "module-plan-background");
|
|
299
|
+
}
|
|
300
|
+
function captureModulePlanBackgroundEnv() {
|
|
301
|
+
const keys = [
|
|
302
|
+
env_vars_1.CLI_ENV.productStorageDir,
|
|
303
|
+
env_vars_1.CLI_ENV.trace,
|
|
304
|
+
env_vars_1.CLI_ENV.traceDir,
|
|
305
|
+
env_vars_1.CLI_ENV.metrics,
|
|
306
|
+
env_vars_1.CLI_ENV.metricsDir,
|
|
307
|
+
env_vars_1.CLI_ENV.metricsTag,
|
|
308
|
+
env_vars_1.CLI_ENV.mutationImpactMetrics,
|
|
309
|
+
env_vars_1.CLI_ENV.mutationImpactStream,
|
|
310
|
+
env_vars_1.CLI_ENV.testMoveToFileFailEntity,
|
|
311
|
+
env_vars_1.CLI_ENV.testPostMutationCyclesDelayMs,
|
|
312
|
+
env_vars_1.CLI_ENV.modulePlanDebugTimeline
|
|
313
|
+
];
|
|
314
|
+
const env = {};
|
|
315
|
+
for (const key of keys) {
|
|
316
|
+
env[key] = process.env[key];
|
|
317
|
+
}
|
|
318
|
+
return env;
|
|
319
|
+
}
|
|
320
|
+
async function withModulePlanBackgroundEnv(env, callback) {
|
|
321
|
+
const previous = {};
|
|
322
|
+
for (const [key, value] of Object.entries(env)) {
|
|
323
|
+
previous[key] = process.env[key];
|
|
324
|
+
if (value === undefined) {
|
|
325
|
+
delete process.env[key];
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
process.env[key] = value;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
return await callback();
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
for (const [key, value] of Object.entries(previous)) {
|
|
336
|
+
if (value === undefined) {
|
|
337
|
+
delete process.env[key];
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
process.env[key] = value;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async function waitForModulePlanJob(jobPromise, deadlineMs) {
|
|
346
|
+
let timer = null;
|
|
347
|
+
try {
|
|
348
|
+
return await Promise.race([
|
|
349
|
+
jobPromise.then((result) => ({ status: "result", result })),
|
|
350
|
+
new Promise((resolve) => {
|
|
351
|
+
timer = setTimeout(() => resolve({ status: "deadline" }), deadlineMs);
|
|
352
|
+
})
|
|
353
|
+
]);
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
if (timer) {
|
|
357
|
+
clearTimeout(timer);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function readModulePlanSyncWaitMs() {
|
|
362
|
+
const raw = process.env[env_vars_1.CLI_ENV.modulePlanSyncWaitMs];
|
|
363
|
+
if (raw !== undefined) {
|
|
364
|
+
const parsed = Number.parseInt(raw, 10);
|
|
365
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
366
|
+
return 0;
|
|
367
|
+
}
|
|
368
|
+
return Math.min(parsed, 120_000);
|
|
369
|
+
}
|
|
370
|
+
return 120_000;
|
|
371
|
+
}
|
|
372
|
+
function buildModulePlanStillRunningResponse(cwd, executionId, operation, elapsedMs) {
|
|
373
|
+
const status = (0, module_plan_cache_1.readModulePlanExecutionStatus)(cwd, executionId);
|
|
374
|
+
const estimatedDurationMs = isJsonObject(status.timeoutHint) && typeof status.timeoutHint.estimatedDurationMs === "number"
|
|
375
|
+
? status.timeoutHint.estimatedDurationMs
|
|
376
|
+
: null;
|
|
377
|
+
const estimatedRemainingMs = estimatedDurationMs === null ? null : Math.max(0, estimatedDurationMs - elapsedMs);
|
|
378
|
+
const response = {
|
|
379
|
+
operation: "execution.status",
|
|
380
|
+
executionId: status.executionId,
|
|
381
|
+
planId: status.planId,
|
|
382
|
+
status: status.status,
|
|
383
|
+
...(status.phase ? { phase: status.phase } : {}),
|
|
384
|
+
summary: buildExecutionSummary(status),
|
|
385
|
+
progress: `${status.completedRows}/${status.rowCount}`,
|
|
386
|
+
entityProgress: `${status.completedEntities ?? 0}/${status.entityCount ?? 0}`,
|
|
387
|
+
expectEmpty: status.expectEmpty === true,
|
|
388
|
+
filesWritten: summarizeWrittenFiles(status.filesWritten.map((file) => (0, module_plan_cache_1.formatRelativePath)(cwd, file)).sort((left, right) => left.localeCompare(right))),
|
|
389
|
+
rows: status.rows,
|
|
390
|
+
updatedAt: status.updatedAt,
|
|
391
|
+
...(estimatedRemainingMs !== null ? { estimatedRemainingMs } : {})
|
|
392
|
+
};
|
|
393
|
+
return (0, agent_text_1.attachAgentText)(response, formatModulePlanStillRunningText(operation, status, estimatedRemainingMs));
|
|
394
|
+
}
|
|
395
|
+
function formatModulePlanStillRunningText(operation, status, estimatedRemainingMs) {
|
|
396
|
+
const lines = [
|
|
397
|
+
`${operation} ${status.executionId}`,
|
|
398
|
+
buildExecutionSummary(status)
|
|
399
|
+
];
|
|
400
|
+
if (status.phase === "preview") {
|
|
401
|
+
lines.push("previewing plan");
|
|
402
|
+
}
|
|
403
|
+
else if (status.phase === "mutation") {
|
|
404
|
+
lines.push("applying mutation");
|
|
405
|
+
}
|
|
406
|
+
else if (status.phase === "postMutation.cycles") {
|
|
407
|
+
lines.push("mutation completed");
|
|
408
|
+
lines.push("checking cycles");
|
|
409
|
+
}
|
|
410
|
+
if (estimatedRemainingMs !== null) {
|
|
411
|
+
lines.push(estimatedRemainingMs > 0
|
|
412
|
+
? `estimated remaining: ${(0, module_plan_timeout_1.formatModulePlanTimeoutEstimate)(Math.max(estimatedRemainingMs, 5_000))}`
|
|
413
|
+
: "estimated remaining: check status again soon");
|
|
414
|
+
}
|
|
415
|
+
return lines.join("\n");
|
|
416
|
+
}
|
|
417
|
+
async function previewModulePlan(cwd, payload, options, operation = "modulePlan.preview") {
|
|
418
|
+
const config = (0, resolve_1.resolveCliConfig)(null);
|
|
419
|
+
const sourceFile = readSourceFile(cwd, payload);
|
|
420
|
+
const normalizedRequest = buildNormalizedRequest(cwd, payload, sourceFile, config);
|
|
421
|
+
const planId = (0, module_plan_cache_1.buildModulePlanId)(normalizedRequest);
|
|
422
|
+
const previewResult = await runSemanticMovePreview(cwd, normalizedRequest, options, operation);
|
|
423
|
+
const sourceHash = (0, module_plan_cache_1.hashFile)(sourceFile);
|
|
424
|
+
const planHash = (0, module_plan_cache_1.buildModulePlanHash)(normalizedRequest, sourceHash, previewResult);
|
|
425
|
+
const record = {
|
|
426
|
+
planId,
|
|
427
|
+
planHash,
|
|
428
|
+
createdAt: new Date().toISOString(),
|
|
429
|
+
cwd: path.resolve(cwd),
|
|
430
|
+
sourceFile,
|
|
431
|
+
sourceHash,
|
|
432
|
+
executable: previewResult.ok !== false,
|
|
433
|
+
normalizedRequest,
|
|
434
|
+
inspectPayload: { requests: [normalizedRequest] },
|
|
435
|
+
previewDir: "",
|
|
436
|
+
previewResult
|
|
437
|
+
};
|
|
438
|
+
(0, module_plan_cache_1.writeModulePlanRecord)(cwd, record);
|
|
439
|
+
const response = {
|
|
440
|
+
...(previewResult.ok === false ? { ok: false, code: "MODULE_PLAN_BLOCKED" } : {}),
|
|
441
|
+
operation,
|
|
442
|
+
planId,
|
|
443
|
+
executable: previewResult.ok !== false,
|
|
444
|
+
summary: buildPlanSummary(previewResult, false),
|
|
445
|
+
...(typeof previewResult.moduleCount === "number" ? { moduleCount: previewResult.moduleCount } : {}),
|
|
446
|
+
...(Array.isArray(previewResult.targets) ? { targets: previewResult.targets } : {}),
|
|
447
|
+
...(Array.isArray(previewResult.blocking) && previewResult.blocking.length > 0 ? { blocking: previewResult.blocking } : {}),
|
|
448
|
+
next: previewResult.ok === false
|
|
449
|
+
? "Fix the plan, then rerun modulePlan preview."
|
|
450
|
+
: `aib modulePlan apply ${planId}`
|
|
451
|
+
};
|
|
452
|
+
return (0, agent_text_1.attachAgentText)(response, formatModulePlanText(response));
|
|
453
|
+
}
|
|
454
|
+
function readNotRunRowsForExecution(cwd, planId, completedRowCount) {
|
|
455
|
+
if (planId === "pending") {
|
|
456
|
+
return [];
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
const record = (0, module_plan_cache_1.readModulePlanRecord)(cwd, planId);
|
|
460
|
+
return compactNotRunRows(cwd, readNormalizedModules(record.normalizedRequest), completedRowCount);
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
return [];
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function runSemanticMovePreview(cwd, normalizedRequest, options, operation) {
|
|
467
|
+
const modules = readNormalizedModules(normalizedRequest);
|
|
468
|
+
const sourceFile = readString(normalizedRequest.sourceFile) ?? "";
|
|
469
|
+
const built = (0, module_plan_standalone_1.buildModulePlanMoveBatch)({
|
|
470
|
+
cwd,
|
|
471
|
+
request: normalizedRequest,
|
|
472
|
+
execute: false,
|
|
473
|
+
config: (0, resolve_1.resolveCliConfig)(null),
|
|
474
|
+
importRules: options.importRules ?? (0, import_rules_1.readConfigImportRules)(cwd),
|
|
475
|
+
mutationComments: options.mutationComments ?? (0, mutation_comments_1.readConfigMutationComments)(cwd)
|
|
476
|
+
});
|
|
477
|
+
const metrics = (0, semantic_move_metrics_1.createSemanticMovePhaseMetrics)({
|
|
478
|
+
enabled: options.metricsEnabled === true,
|
|
479
|
+
cwd,
|
|
480
|
+
operation,
|
|
481
|
+
...(options.semanticMoveMetricsExecutionId ? { executionId: options.semanticMoveMetricsExecutionId } : {})
|
|
482
|
+
});
|
|
483
|
+
const response = await (0, semantic_move_standalone_engine_1.runStandaloneSemanticMoveBatch)(cwd, built, undefined, undefined, metrics, options.semanticContextPool ? { semanticContextPool: options.semanticContextPool } : undefined);
|
|
484
|
+
const summarized = (0, module_plan_standalone_1.summarizeModulePlanMoveBatch)({ cwd, request: normalizedRequest, response, execute: false });
|
|
485
|
+
return {
|
|
486
|
+
op: "modulePlan",
|
|
487
|
+
ok: summarized.blocking.length === 0,
|
|
488
|
+
sourceFile,
|
|
489
|
+
moduleCount: modules.length,
|
|
490
|
+
targets: summarized.targets,
|
|
491
|
+
rows: summarized.rows,
|
|
492
|
+
...(summarized.declarationFailures.length > 0 ? { declarationFailures: summarized.declarationFailures } : {}),
|
|
493
|
+
...(summarized.missingEntities.length > 0 ? { missingEntities: summarized.missingEntities } : {}),
|
|
494
|
+
...(summarized.blocking.length > 0 ? { blocking: summarized.blocking } : {}),
|
|
495
|
+
cycles: "notChecked"
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
async function applyCachedModulePlan(cwd, planId, options, operation = "modulePlan.apply", executionIdOverride, pendingExecution) {
|
|
499
|
+
const record = (0, module_plan_cache_1.readModulePlanRecord)(cwd, planId);
|
|
500
|
+
if (record.executable === false || record.previewResult.ok === false) {
|
|
501
|
+
throw new errors_1.CliError("APPLY_MODULE_PLAN_NOT_EXECUTABLE", "Module plan has blocking move diagnostics. Fix the plan before applying.", {
|
|
502
|
+
planId,
|
|
503
|
+
next: "Fix the plan, then rerun modulePlan preview."
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
const currentSourceHash = (0, module_plan_cache_1.hashFile)(record.sourceFile);
|
|
507
|
+
if (currentSourceHash !== record.sourceHash) {
|
|
508
|
+
throw new errors_1.CliError("APPLY_MODULE_PLAN_SOURCE_CHANGED", "Source file changed after modulePlan preview. Rerun modulePlan preview.", {
|
|
509
|
+
planId,
|
|
510
|
+
sourceFile: (0, module_plan_cache_1.formatRelativePath)(cwd, record.sourceFile)
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
const modules = readNormalizedModules(record.normalizedRequest);
|
|
514
|
+
const rows = [];
|
|
515
|
+
const filesWritten = new Set();
|
|
516
|
+
let declarationFailures = [];
|
|
517
|
+
let missingEntities = [];
|
|
518
|
+
const sourceFile = record.sourceFile;
|
|
519
|
+
const plannedTargets = modules.map((module) => readString(module.targetFile)).filter((file) => Boolean(file));
|
|
520
|
+
const plannedTouchedFiles = uniqueStrings([sourceFile, ...plannedTargets]);
|
|
521
|
+
const execution = pendingExecution ?? createModulePlanExecutionStatus(cwd, record, operation, modules, executionIdOverride);
|
|
522
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.apply.start", {
|
|
523
|
+
operation,
|
|
524
|
+
rowCount: modules.length,
|
|
525
|
+
entityCount: execution.entityCount
|
|
526
|
+
});
|
|
527
|
+
const executionMetricContext = {
|
|
528
|
+
executionId: execution.executionId,
|
|
529
|
+
planId: record.planId,
|
|
530
|
+
parentOperation: operation,
|
|
531
|
+
sourceFile: (0, module_plan_cache_1.formatRelativePath)(cwd, sourceFile),
|
|
532
|
+
rowCount: modules.length,
|
|
533
|
+
entityCount: execution.entityCount
|
|
534
|
+
};
|
|
535
|
+
const span = (0, central_metrics_1.startCentralMetricSpan)({
|
|
536
|
+
kind: "mutation.execution",
|
|
537
|
+
operation,
|
|
538
|
+
cwd: path.resolve(cwd),
|
|
539
|
+
...executionMetricContext
|
|
540
|
+
});
|
|
541
|
+
persistModulePlanExecution(cwd, execution);
|
|
542
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.apply.execution.persisted");
|
|
543
|
+
await (0, event_loop_1.yieldToEventLoop)();
|
|
544
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.cycles.pre.start", { fileCount: plannedTouchedFiles.length });
|
|
545
|
+
const preMutationCycles = runPostMutationCyclesSnapshot(cwd, plannedTouchedFiles);
|
|
546
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.cycles.pre.end", {
|
|
547
|
+
componentCount: readNumber(preMutationCycles.componentCount) ?? null
|
|
548
|
+
});
|
|
549
|
+
try {
|
|
550
|
+
const built = (0, module_plan_standalone_1.buildModulePlanMoveBatch)({
|
|
551
|
+
cwd,
|
|
552
|
+
request: record.normalizedRequest,
|
|
553
|
+
execute: true,
|
|
554
|
+
config: (0, resolve_1.resolveCliConfig)(null),
|
|
555
|
+
importRules: options.importRules ?? (0, import_rules_1.readConfigImportRules)(cwd),
|
|
556
|
+
mutationComments: options.mutationComments ?? (0, mutation_comments_1.readConfigMutationComments)(cwd)
|
|
557
|
+
});
|
|
558
|
+
const metrics = (0, semantic_move_metrics_1.createSemanticMovePhaseMetrics)({
|
|
559
|
+
enabled: options.metricsEnabled === true,
|
|
560
|
+
cwd,
|
|
561
|
+
operation,
|
|
562
|
+
executionId: execution.executionId
|
|
563
|
+
});
|
|
564
|
+
let liveModuleOffset = 0;
|
|
565
|
+
const moveResponse = await (0, semantic_move_standalone_engine_1.runStandaloneSemanticMoveBatch)(cwd, built, {
|
|
566
|
+
beforeApply(writeSet) {
|
|
567
|
+
options.semanticMoveExecutionEvidence?.beforeApply(writeSet);
|
|
568
|
+
execution.phase = "mutation";
|
|
569
|
+
execution.plannedWriteSet = [...writeSet];
|
|
570
|
+
execution.potentiallyModifiedFiles = [...writeSet];
|
|
571
|
+
persistModulePlanExecution(cwd, execution);
|
|
572
|
+
},
|
|
573
|
+
afterProgress(progress) {
|
|
574
|
+
options.semanticMoveExecutionEvidence?.afterProgress?.(progress);
|
|
575
|
+
},
|
|
576
|
+
afterRoute(route) {
|
|
577
|
+
options.semanticMoveExecutionEvidence?.afterRoute?.(route);
|
|
578
|
+
const routeModules = [];
|
|
579
|
+
let rowCount = 0;
|
|
580
|
+
while (liveModuleOffset < modules.length && rowCount < route.requestedRowCount) {
|
|
581
|
+
const module = modules[liveModuleOffset++];
|
|
582
|
+
routeModules.push(module);
|
|
583
|
+
rowCount += readModuleEntities(module).length;
|
|
584
|
+
}
|
|
585
|
+
const partialRequest = { ...record.normalizedRequest, modules: routeModules };
|
|
586
|
+
const partial = (0, module_plan_standalone_1.summarizeModulePlanMoveBatch)({ cwd, request: partialRequest, response: route.result, execute: true });
|
|
587
|
+
rows.push(...partial.rows);
|
|
588
|
+
for (const file of partial.filesWritten)
|
|
589
|
+
filesWritten.add((0, module_plan_cache_1.resolveCliFilePath)(cwd, file));
|
|
590
|
+
execution.rows = [...rows];
|
|
591
|
+
execution.completedRows = rows.length;
|
|
592
|
+
execution.failedRows = rows.filter((row) => row.ok === false).length;
|
|
593
|
+
execution.completedEntities = countCompletedRowEntities(rows);
|
|
594
|
+
execution.filesWritten = Array.from(filesWritten).sort((left, right) => left.localeCompare(right));
|
|
595
|
+
persistModulePlanExecution(cwd, execution);
|
|
596
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.apply.route.end", {
|
|
597
|
+
routeIndex: route.index,
|
|
598
|
+
completedRows: execution.completedRows,
|
|
599
|
+
completedEntities: execution.completedEntities
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}, undefined, metrics, options.semanticContextPool ? { semanticContextPool: options.semanticContextPool } : undefined);
|
|
603
|
+
const summarized = (0, module_plan_standalone_1.summarizeModulePlanMoveBatch)({
|
|
604
|
+
cwd,
|
|
605
|
+
request: record.normalizedRequest,
|
|
606
|
+
response: moveResponse,
|
|
607
|
+
execute: true
|
|
608
|
+
});
|
|
609
|
+
rows.splice(0, rows.length, ...summarized.rows);
|
|
610
|
+
declarationFailures = summarized.declarationFailures;
|
|
611
|
+
missingEntities = summarized.missingEntities;
|
|
612
|
+
for (const file of summarized.filesWritten)
|
|
613
|
+
filesWritten.add((0, module_plan_cache_1.resolveCliFilePath)(cwd, file));
|
|
614
|
+
execution.potentiallyModifiedFiles = readStringArray(moveResponse.potentiallyModifiedFiles).map((file) => (0, module_plan_cache_1.resolveCliFilePath)(cwd, file));
|
|
615
|
+
const ok = rows.every((row) => row.ok !== false);
|
|
616
|
+
if (ok) {
|
|
617
|
+
execution.phase = "postMutation.cycles";
|
|
618
|
+
persistModulePlanExecution(cwd, execution);
|
|
619
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.cycles.phase.persisted");
|
|
620
|
+
await (0, event_loop_1.yieldToEventLoop)();
|
|
621
|
+
await maybeDelayPostMutationCycles();
|
|
622
|
+
const postMutationFocusFiles = uniqueStrings([...plannedTouchedFiles, ...Array.from(filesWritten)]);
|
|
623
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.cycles.post.start", { fileCount: postMutationFocusFiles.length });
|
|
624
|
+
const postMutationCycles = runPostMutationCyclesSnapshot(cwd, postMutationFocusFiles);
|
|
625
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.cycles.post.end", {
|
|
626
|
+
componentCount: readNumber(postMutationCycles.componentCount) ?? null
|
|
627
|
+
});
|
|
628
|
+
execution.postMutation = {
|
|
629
|
+
cycles: diffPostMutationCycles(preMutationCycles, postMutationCycles, new Set(formatCycleFocusFiles(cwd, postMutationFocusFiles)))
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
execution.status = ok ? "completed" : "failed";
|
|
633
|
+
if (ok) {
|
|
634
|
+
execution.phase = "completed";
|
|
635
|
+
}
|
|
636
|
+
execution.rows = [...rows];
|
|
637
|
+
execution.completedRows = rows.filter((row) => row.skipped !== true).length;
|
|
638
|
+
execution.failedRows = rows.filter((row) => row.ok === false && row.skipped !== true).length;
|
|
639
|
+
execution.completedEntities = countCompletedRowEntities(rows);
|
|
640
|
+
execution.filesWritten = Array.from(filesWritten).sort((left, right) => left.localeCompare(right));
|
|
641
|
+
const remainingSource = await readRemainingSourceSummary(cwd, sourceFile, options);
|
|
642
|
+
if (remainingSource) {
|
|
643
|
+
execution.remainingSource = remainingSource;
|
|
644
|
+
}
|
|
645
|
+
persistModulePlanExecution(cwd, execution);
|
|
646
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, execution.executionId, "modulePlan.apply.execution.final.persisted", {
|
|
647
|
+
status: execution.status,
|
|
648
|
+
completedRows: execution.completedRows,
|
|
649
|
+
completedEntities: execution.completedEntities
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
execution.status = "failed";
|
|
654
|
+
execution.error = error instanceof Error ? error.message : String(error);
|
|
655
|
+
execution.filesWritten = Array.from(filesWritten).sort((left, right) => left.localeCompare(right));
|
|
656
|
+
persistModulePlanExecution(cwd, execution);
|
|
657
|
+
span.end({
|
|
658
|
+
ok: false,
|
|
659
|
+
status: execution.status,
|
|
660
|
+
error: error instanceof Error ? error.message : String(error),
|
|
661
|
+
completedRows: execution.completedRows,
|
|
662
|
+
failedRows: execution.failedRows,
|
|
663
|
+
completedEntities: execution.completedEntities,
|
|
664
|
+
filesWrittenCount: execution.filesWritten.length
|
|
665
|
+
});
|
|
666
|
+
throw error;
|
|
667
|
+
}
|
|
668
|
+
const ok = rows.every((row) => row.ok !== false);
|
|
669
|
+
const futureNotRun = ok ? [] : compactNotRunRows(cwd, modules, rows.length);
|
|
670
|
+
const notRun = ok ? [] : [...compactNotRunEntitiesInRows(rows), ...futureNotRun];
|
|
671
|
+
maybeSaveExecutionStatus(cwd, execution);
|
|
672
|
+
const response = {
|
|
673
|
+
...(ok ? {} : { ok: false, code: "MODULE_PLAN_APPLY_FAILED" }),
|
|
674
|
+
operation,
|
|
675
|
+
applied: ok,
|
|
676
|
+
planId: record.planId,
|
|
677
|
+
executionId: execution.executionId,
|
|
678
|
+
expectEmpty: record.normalizedRequest.expectEmpty === true,
|
|
679
|
+
summary: buildPlanSummary({ rows: [...rows, ...futureNotRun] }, true),
|
|
680
|
+
rows,
|
|
681
|
+
...(declarationFailures.length > 0 ? { declarationFailures } : {}),
|
|
682
|
+
...(missingEntities.length > 0 ? { missingEntities } : {}),
|
|
683
|
+
...(notRun.length > 0 ? { notRun } : {}),
|
|
684
|
+
remainingSource: await readRemainingSourceSummary(cwd, sourceFile, options),
|
|
685
|
+
...(execution.postMutation ? { postMutation: execution.postMutation } : {}),
|
|
686
|
+
...(readCreatedTargets(record.previewResult).length > 0 ? { createdFiles: compactStringList(readCreatedTargets(record.previewResult), 8) } : {}),
|
|
687
|
+
filesWritten: summarizeWrittenFiles(Array.from(filesWritten).sort((left, right) => left.localeCompare(right)).map((file) => (0, module_plan_cache_1.formatRelativePath)(cwd, file))),
|
|
688
|
+
...(ok ? {} : { next: "Fix failed move row and rerun modulePlan preview." })
|
|
689
|
+
};
|
|
690
|
+
span.end({
|
|
691
|
+
ok,
|
|
692
|
+
status: execution.status,
|
|
693
|
+
completedRows: execution.completedRows,
|
|
694
|
+
failedRows: execution.failedRows,
|
|
695
|
+
completedEntities: execution.completedEntities,
|
|
696
|
+
filesWrittenCount: execution.filesWritten.length
|
|
697
|
+
});
|
|
698
|
+
(0, central_metrics_1.recordCentralMetric)({
|
|
699
|
+
kind: "mutation.summary",
|
|
700
|
+
operation,
|
|
701
|
+
cwd: path.resolve(cwd),
|
|
702
|
+
ok,
|
|
703
|
+
status: execution.status,
|
|
704
|
+
executionId: execution.executionId,
|
|
705
|
+
planId: record.planId,
|
|
706
|
+
rowCount: execution.rowCount,
|
|
707
|
+
completedRows: execution.completedRows,
|
|
708
|
+
failedRows: execution.failedRows,
|
|
709
|
+
entityCount: execution.entityCount,
|
|
710
|
+
completedEntities: execution.completedEntities,
|
|
711
|
+
filesWrittenCount: execution.filesWritten.length
|
|
712
|
+
});
|
|
713
|
+
return (0, agent_text_1.attachAgentText)(response, formatModulePlanText(response));
|
|
714
|
+
}
|
|
715
|
+
function compactNotRunRows(cwd, modules, startIndex) {
|
|
716
|
+
return modules.slice(startIndex).map((module) => compactObject({
|
|
717
|
+
target: (0, module_plan_cache_1.formatRelativePath)(cwd, readString(module.targetFile) ?? ""),
|
|
718
|
+
entities: readModuleEntities(module)
|
|
719
|
+
}));
|
|
720
|
+
}
|
|
721
|
+
function compactNotRunEntitiesInRows(rows) {
|
|
722
|
+
return rows
|
|
723
|
+
.map((row) => compactObject({
|
|
724
|
+
target: readString(row.target) ?? "",
|
|
725
|
+
entities: readStringArray(row.notRunEntities)
|
|
726
|
+
}))
|
|
727
|
+
.filter((row) => readStringArray(row.entities).length > 0);
|
|
728
|
+
}
|
|
729
|
+
function createModulePlanExecutionStatus(cwd, record, operation, modules, executionIdOverride) {
|
|
730
|
+
const now = new Date().toISOString();
|
|
731
|
+
const executionId = executionIdOverride ?? (0, module_plan_cache_1.buildModulePlanExecutionId)(record.planId);
|
|
732
|
+
const entityCount = countModuleEntities(modules);
|
|
733
|
+
return {
|
|
734
|
+
executionId,
|
|
735
|
+
planId: record.planId,
|
|
736
|
+
operation,
|
|
737
|
+
cwd: path.resolve(cwd),
|
|
738
|
+
sourceFile: record.sourceFile,
|
|
739
|
+
status: "running",
|
|
740
|
+
phase: "mutation",
|
|
741
|
+
startedAt: now,
|
|
742
|
+
updatedAt: now,
|
|
743
|
+
rowCount: modules.length,
|
|
744
|
+
completedRows: 0,
|
|
745
|
+
failedRows: 0,
|
|
746
|
+
entityCount,
|
|
747
|
+
completedEntities: 0,
|
|
748
|
+
expectEmpty: record.normalizedRequest.expectEmpty === true,
|
|
749
|
+
filesWritten: [],
|
|
750
|
+
rows: [],
|
|
751
|
+
timeoutHint: buildModulePlanTimeoutHint(record.normalizedRequest),
|
|
752
|
+
productStorageDir: (0, product_storage_1.productStorageRoot)()
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
function createPendingModulePlanExecutionStatus(cwd, executionId, operation, payload) {
|
|
756
|
+
const now = new Date().toISOString();
|
|
757
|
+
const rawModules = Array.isArray(payload.modules) ? payload.modules.filter(isJsonObject) : [];
|
|
758
|
+
return {
|
|
759
|
+
executionId,
|
|
760
|
+
planId: "pending",
|
|
761
|
+
operation,
|
|
762
|
+
cwd: path.resolve(cwd),
|
|
763
|
+
sourceFile: payload.sourceFile || payload.file ? readSourceFile(cwd, payload) : "",
|
|
764
|
+
status: "running",
|
|
765
|
+
phase: "mutation",
|
|
766
|
+
startedAt: now,
|
|
767
|
+
updatedAt: now,
|
|
768
|
+
rowCount: rawModules.length,
|
|
769
|
+
completedRows: 0,
|
|
770
|
+
failedRows: 0,
|
|
771
|
+
entityCount: countModuleEntities(rawModules),
|
|
772
|
+
completedEntities: 0,
|
|
773
|
+
expectEmpty: payload.expectEmpty === true,
|
|
774
|
+
filesWritten: [],
|
|
775
|
+
rows: [],
|
|
776
|
+
productStorageDir: (0, product_storage_1.productStorageRoot)()
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function persistModulePlanExecution(cwd, execution) {
|
|
780
|
+
(0, module_plan_cache_1.writeModulePlanExecutionStatus)(cwd, execution);
|
|
781
|
+
maybeSaveExecutionStatus(cwd, execution);
|
|
782
|
+
}
|
|
783
|
+
function maybeSaveExecutionStatus(cwd, execution) {
|
|
784
|
+
if (!(0, session_workspace_1.sessionWorkspaceExists)(cwd)) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
try {
|
|
788
|
+
return (0, session_workspace_1.saveSessionOutputJson)(cwd, "execution", `modulePlan-${execution.executionId}`, execution);
|
|
789
|
+
}
|
|
790
|
+
catch {
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function runPostMutationCyclesSnapshot(cwd, files) {
|
|
795
|
+
const existingFiles = formatCycleFocusFiles(cwd, files).filter((file) => fs.existsSync((0, module_plan_cache_1.resolveCliFilePath)(cwd, file)));
|
|
796
|
+
if (existingFiles.length === 0) {
|
|
797
|
+
return {
|
|
798
|
+
op: "cycles",
|
|
799
|
+
componentCount: 0,
|
|
800
|
+
components: []
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
const args = ["cycles"];
|
|
804
|
+
for (const file of existingFiles) {
|
|
805
|
+
args.push("--files", file);
|
|
806
|
+
}
|
|
807
|
+
args.push("--detail", "imports", "--limit", "50");
|
|
808
|
+
return (0, inspect_cycles_1.runInspectCycles)(cwd, args, undefined);
|
|
809
|
+
}
|
|
810
|
+
function diffPostMutationCycles(prePayload, postPayload, touchedFiles) {
|
|
811
|
+
const preKeys = new Set(readCycleComponents(prePayload).map(cycleComponentKey));
|
|
812
|
+
const newOrChanged = readCycleComponents(postPayload).filter((component) => readStringArray(component.files).some((file) => touchedFiles.has(file)) &&
|
|
813
|
+
!preKeys.has(cycleComponentKey(component)));
|
|
814
|
+
return {
|
|
815
|
+
status: newOrChanged.length > 0 ? "new-or-changed" : "none",
|
|
816
|
+
detail: "imports",
|
|
817
|
+
newOrChangedCount: newOrChanged.length,
|
|
818
|
+
preComponentCount: readNumber(prePayload.componentCount) ?? readCycleComponents(prePayload).length,
|
|
819
|
+
postComponentCount: readNumber(postPayload.componentCount) ?? readCycleComponents(postPayload).length,
|
|
820
|
+
components: newOrChanged
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
function readCycleComponents(payload) {
|
|
824
|
+
return (Array.isArray(payload.components) ? payload.components : [])
|
|
825
|
+
.filter(isJsonObject)
|
|
826
|
+
.map((component) => ({
|
|
827
|
+
kind: readString(component.kind) ?? "mixed",
|
|
828
|
+
files: readStringArray(component.files).sort(),
|
|
829
|
+
chain: readString(component.chain) ?? "",
|
|
830
|
+
...(isJsonObject(component.cycle) ? { cycle: component.cycle } : {}),
|
|
831
|
+
imports: readCycleImports(component)
|
|
832
|
+
}));
|
|
833
|
+
}
|
|
834
|
+
function readCycleImports(component) {
|
|
835
|
+
const cycle = isJsonObject(component.cycle) ? component.cycle : {};
|
|
836
|
+
return readStringArray(cycle.imports);
|
|
837
|
+
}
|
|
838
|
+
function cycleComponentKey(component) {
|
|
839
|
+
return `${readString(component.kind) ?? "mixed"}:${readStringArray(component.files).sort().join("|")}`;
|
|
840
|
+
}
|
|
841
|
+
function formatCycleFocusFiles(cwd, files) {
|
|
842
|
+
return uniqueStrings(files.map((file) => (0, module_plan_cache_1.formatRelativePath)(cwd, (0, module_plan_cache_1.resolveCliFilePath)(cwd, file))));
|
|
843
|
+
}
|
|
844
|
+
async function maybeDelayPostMutationCycles() {
|
|
845
|
+
const raw = process.env[env_vars_1.CLI_ENV.testPostMutationCyclesDelayMs];
|
|
846
|
+
const delayMs = raw ? Number.parseInt(raw, 10) : 0;
|
|
847
|
+
if (!Number.isFinite(delayMs) || delayMs <= 0) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(delayMs, 60_000)));
|
|
851
|
+
}
|
|
852
|
+
function buildExecutionSummary(status) {
|
|
853
|
+
const writtenCount = status.filesWritten.length;
|
|
854
|
+
const progress = `${status.completedRows}/${status.rowCount}`;
|
|
855
|
+
const entityCount = status.entityCount ?? 0;
|
|
856
|
+
const completedEntities = status.completedEntities ?? 0;
|
|
857
|
+
const entityProgress = entityCount > 0
|
|
858
|
+
? `, ${Math.floor((completedEntities / entityCount) * 100)}% entities`
|
|
859
|
+
: "";
|
|
860
|
+
const base = status.status === "running" && status.phase === "postMutation.cycles"
|
|
861
|
+
? `${progress} rows${entityProgress}`
|
|
862
|
+
: `${status.status === "running" ? "in progress" : status.status}, ${progress} rows${entityProgress}`;
|
|
863
|
+
return writtenCount > 0 ? `${base}, ${writtenCount} ${writtenCount === 1 ? "file" : "files"} written` : base;
|
|
864
|
+
}
|
|
865
|
+
function buildModulePlanTimeoutHint(request) {
|
|
866
|
+
return (0, module_plan_timeout_1.buildModulePlanTimeoutHintFromRequest)(request) ?? {
|
|
867
|
+
recommendedTimeoutMs: 90_000,
|
|
868
|
+
rowCount: 0,
|
|
869
|
+
symbolCount: 0,
|
|
870
|
+
message: "If the calling agent times out, inspect progress with: aib execution status last"
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
function buildNormalizedRequest(cwd, payload, sourceFile, config) {
|
|
874
|
+
const rawModules = payload.modules ?? [];
|
|
875
|
+
if (rawModules.length === 0) {
|
|
876
|
+
throw new errors_1.CliError("MODULE_PLAN_MODULES_REQUIRED", "modulePlan expects a non-empty modules array.");
|
|
877
|
+
}
|
|
878
|
+
const modules = rawModules.map((rawModule) => {
|
|
879
|
+
const targetFile = rawModule.target ?? rawModule.targetFile ?? rawModule.file;
|
|
880
|
+
if (!targetFile) {
|
|
881
|
+
throw new errors_1.CliError("MODULE_PLAN_TARGET_REQUIRED", "Each module expects target.");
|
|
882
|
+
}
|
|
883
|
+
const rawSymbols = rawModule.entities ?? rawModule.symbols ?? [];
|
|
884
|
+
if (rawSymbols.length === 0) {
|
|
885
|
+
throw new errors_1.CliError("MODULE_PLAN_ENTITIES_REQUIRED", "Each module expects a non-empty entities array.");
|
|
886
|
+
}
|
|
887
|
+
return {
|
|
888
|
+
targetFile: (0, module_plan_cache_1.resolveCliFilePath)(cwd, targetFile),
|
|
889
|
+
symbols: rawSymbols.map((rawSymbol) => parseModuleSymbol(rawSymbol, config))
|
|
890
|
+
};
|
|
891
|
+
});
|
|
892
|
+
return {
|
|
893
|
+
op: "modulePlan",
|
|
894
|
+
sourceFile,
|
|
895
|
+
...(payload.expectEmpty === true ? { expectEmpty: true } : {}),
|
|
896
|
+
modules
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
function parseModuleSymbol(rawSymbol, config) {
|
|
900
|
+
if (typeof rawSymbol === "string") {
|
|
901
|
+
const parsed = (0, inspect_selector_1.parseInspectSelector)(rawSymbol, config);
|
|
902
|
+
return {
|
|
903
|
+
raw: rawSymbol,
|
|
904
|
+
symbolName: parsed.symbolName,
|
|
905
|
+
...(parsed.symbolKind ? { symbolKind: parsed.symbolKind } : {})
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
const selector = readString(rawSymbol.entity) ?? readString(rawSymbol.selector) ?? readString(rawSymbol.raw);
|
|
909
|
+
if (selector) {
|
|
910
|
+
const parsed = (0, inspect_selector_1.parseInspectSelector)(selector, config);
|
|
911
|
+
return {
|
|
912
|
+
raw: selector,
|
|
913
|
+
symbolName: parsed.symbolName,
|
|
914
|
+
...(parsed.symbolKind ? { symbolKind: parsed.symbolKind } : {})
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return toJsonObject(rawSymbol);
|
|
918
|
+
}
|
|
919
|
+
function countCompletedRowEntities(rows) {
|
|
920
|
+
return rows.reduce((count, row) => {
|
|
921
|
+
if (row.ok === false) {
|
|
922
|
+
return count + readStringArray(row.appliedEntities).length;
|
|
923
|
+
}
|
|
924
|
+
return count + readStringArray(row.entities).length;
|
|
925
|
+
}, 0);
|
|
926
|
+
}
|
|
927
|
+
function buildPlanSummary(previewResult, applied) {
|
|
928
|
+
const rows = Array.isArray(previewResult.rows) ? previewResult.rows.filter(isJsonObject) : [];
|
|
929
|
+
const symbolCount = rows.reduce((count, row) => count + readStringArray(row.entities).length, 0);
|
|
930
|
+
const failedCount = rows.filter((row) => row.ok === false).length;
|
|
931
|
+
const appliedEntityCount = rows.reduce((count, row) => count + readStringArray(row.appliedEntities).length, 0);
|
|
932
|
+
const manualExtractionCount = rows.reduce((count, row) => count + readManualExtractionEntities(row).length, 0);
|
|
933
|
+
const nonManualFailedCount = rows.filter((row) => row.ok === false && readManualExtractionEntities(row).length === 0).length;
|
|
934
|
+
const targetCount = rows.length;
|
|
935
|
+
const createdCount = applied
|
|
936
|
+
? readCreatedTargets(previewResult).length
|
|
937
|
+
: rows.filter((row) => targetWillBeCreated(row)).length;
|
|
938
|
+
const writtenCount = applied
|
|
939
|
+
? Array.from(new Set(rows.flatMap((row) => readStringArray(row.filesWritten).filter((file) => !file.startsWith("+"))))).length
|
|
940
|
+
: 0;
|
|
941
|
+
if (failedCount > 0) {
|
|
942
|
+
const parts = [`${symbolCount} ${symbolCount === 1 ? "symbol" : "symbols"}`];
|
|
943
|
+
if (appliedEntityCount > 0) {
|
|
944
|
+
parts.push(`${appliedEntityCount} applied`);
|
|
945
|
+
}
|
|
946
|
+
if (manualExtractionCount > 0) {
|
|
947
|
+
parts.push(`${manualExtractionCount} manual extraction required`);
|
|
948
|
+
}
|
|
949
|
+
if (nonManualFailedCount > 0) {
|
|
950
|
+
parts.push(`${nonManualFailedCount} blocked`);
|
|
951
|
+
}
|
|
952
|
+
return parts.join(", ");
|
|
953
|
+
}
|
|
954
|
+
const base = `${symbolCount} ${symbolCount === 1 ? "symbol" : "symbols"}, ${targetCount} ${targetCount === 1 ? "target" : "targets"} ${applied ? "moved" : "ready"}`;
|
|
955
|
+
const details = [];
|
|
956
|
+
if (applied && writtenCount > 0) {
|
|
957
|
+
details.push(`${writtenCount} ${writtenCount === 1 ? "file" : "files"} written`);
|
|
958
|
+
}
|
|
959
|
+
if (createdCount > 0) {
|
|
960
|
+
details.push(`${createdCount} ${createdCount === 1 ? "file" : "files"} ${applied ? "created" : "will be created"}`);
|
|
961
|
+
}
|
|
962
|
+
return details.length > 0 ? `${base}; ${details.join(", ")}` : base;
|
|
963
|
+
}
|
|
964
|
+
function targetWillBeCreated(row) {
|
|
965
|
+
return typeof row.summary === "string" && row.summary.includes("target will be created");
|
|
966
|
+
}
|
|
967
|
+
function readCreatedTargets(previewResult) {
|
|
968
|
+
const rows = Array.isArray(previewResult.rows) ? previewResult.rows.filter(isJsonObject) : [];
|
|
969
|
+
return rows
|
|
970
|
+
.filter((row) => targetWillBeCreated(row))
|
|
971
|
+
.map((row) => readString(row.target))
|
|
972
|
+
.filter((file) => Boolean(file));
|
|
973
|
+
}
|
|
974
|
+
function formatModulePlanText(response) {
|
|
975
|
+
const lines = [];
|
|
976
|
+
const operation = readString(response.operation) ?? "modulePlan";
|
|
977
|
+
const planId = readString(response.planId);
|
|
978
|
+
const executionId = readString(response.executionId);
|
|
979
|
+
if (operation !== "execution.status") {
|
|
980
|
+
const headerId = operation === "modulePlan.apply" || operation === "modulePlan.execute"
|
|
981
|
+
? executionId ?? planId
|
|
982
|
+
: planId;
|
|
983
|
+
lines.push(headerId ? `${operation} ${headerId}` : operation);
|
|
984
|
+
}
|
|
985
|
+
if (response.executable === false) {
|
|
986
|
+
lines.push("blocked");
|
|
987
|
+
}
|
|
988
|
+
if (typeof response.summary === "string") {
|
|
989
|
+
lines.push(response.summary);
|
|
990
|
+
}
|
|
991
|
+
if (operation === "execution.status" && response.status === "running" && response.phase === "postMutation.cycles") {
|
|
992
|
+
lines.push("mutation completed");
|
|
993
|
+
lines.push("checking cycles");
|
|
994
|
+
}
|
|
995
|
+
const isCheckingPostMutationCycles = operation === "execution.status" &&
|
|
996
|
+
response.status === "running" &&
|
|
997
|
+
response.phase === "postMutation.cycles";
|
|
998
|
+
if (Array.isArray(response.targets) && response.targets.length > 0) {
|
|
999
|
+
lines.push("targets:");
|
|
1000
|
+
for (const target of response.targets.filter(isJsonObject)) {
|
|
1001
|
+
const file = readString(target.file);
|
|
1002
|
+
const entities = readStringArray(target.entities);
|
|
1003
|
+
if (file) {
|
|
1004
|
+
lines.push(`${file}: ${formatInlineList(entities, 5)}`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!isCheckingPostMutationCycles && Array.isArray(response.rows) && response.rows.length > 0) {
|
|
1009
|
+
const moveLines = [];
|
|
1010
|
+
const manualExtractionRows = [];
|
|
1011
|
+
const diagnosticRows = [];
|
|
1012
|
+
lines.push("moves:");
|
|
1013
|
+
for (const row of response.rows.filter(isJsonObject)) {
|
|
1014
|
+
const target = readString(row.target);
|
|
1015
|
+
const entities = row.ok === false ? readStringArray(row.appliedEntities) : readStringArray(row.entities);
|
|
1016
|
+
if (target && entities.length > 0) {
|
|
1017
|
+
moveLines.push(`${target}: ${formatInlineList(entities, 5)}`);
|
|
1018
|
+
}
|
|
1019
|
+
if (row.ok === false) {
|
|
1020
|
+
if (readManualExtractionEntities(row).length > 0) {
|
|
1021
|
+
manualExtractionRows.push(row);
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
diagnosticRows.push(row);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
if (moveLines.length > 0) {
|
|
1028
|
+
lines.push(...moveLines);
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
lines.pop();
|
|
1032
|
+
}
|
|
1033
|
+
appendModulePlanManualExtractionLines(lines, manualExtractionRows);
|
|
1034
|
+
for (const row of diagnosticRows) {
|
|
1035
|
+
const code = readString(row.code);
|
|
1036
|
+
const error = readString(row.error);
|
|
1037
|
+
if (code) {
|
|
1038
|
+
lines.push(`code: ${code}`);
|
|
1039
|
+
}
|
|
1040
|
+
if (error) {
|
|
1041
|
+
lines.push(error);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (Array.isArray(response.notRun) && response.notRun.length > 0) {
|
|
1046
|
+
lines.push("not run:");
|
|
1047
|
+
for (const row of response.notRun.filter(isJsonObject)) {
|
|
1048
|
+
const target = readString(row.target);
|
|
1049
|
+
const entities = readStringArray(row.entities);
|
|
1050
|
+
if (target) {
|
|
1051
|
+
lines.push(`${target}: ${formatInlineList(entities, 5)}`);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
if (isJsonObject(response.remainingSource)) {
|
|
1056
|
+
const remainingSymbols = readStringArray(response.remainingSource.symbols);
|
|
1057
|
+
if (remainingSymbols.length === 0) {
|
|
1058
|
+
if (response.remainingSource.hasNonDeclarationText === true) {
|
|
1059
|
+
lines.push("source has no declarations");
|
|
1060
|
+
lines.push("source file still has non-declaration text");
|
|
1061
|
+
}
|
|
1062
|
+
else {
|
|
1063
|
+
lines.push("source is empty");
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
else if (response.expectEmpty === true) {
|
|
1067
|
+
lines.push("source still contains:");
|
|
1068
|
+
lines.push(formatInlineList(remainingSymbols, 15));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (Array.isArray(response.blocking) && response.blocking.length > 0) {
|
|
1072
|
+
appendModulePlanBlockingText(lines, response.blocking.filter(isJsonObject));
|
|
1073
|
+
}
|
|
1074
|
+
if (response.status !== "running" && Array.isArray(response.filesWritten) && response.filesWritten.length > 0) {
|
|
1075
|
+
lines.push("filesWritten:");
|
|
1076
|
+
for (const file of response.filesWritten.filter((item) => typeof item === "string")) {
|
|
1077
|
+
lines.push(file);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
if (isJsonObject(response.postMutation) && isJsonObject(response.postMutation.cycles)) {
|
|
1081
|
+
appendPostMutationCyclesText(lines, response.postMutation.cycles);
|
|
1082
|
+
}
|
|
1083
|
+
if (typeof response.next === "string" &&
|
|
1084
|
+
!(Array.isArray(response.blocking) && response.blocking.length > 0) &&
|
|
1085
|
+
!lines.includes("manualExtractionRequired:")) {
|
|
1086
|
+
lines.push(`next: ${response.next}`);
|
|
1087
|
+
}
|
|
1088
|
+
return lines.join("\n");
|
|
1089
|
+
}
|
|
1090
|
+
function appendModulePlanBlockingText(lines, blocking) {
|
|
1091
|
+
const notFound = blocking
|
|
1092
|
+
.filter((row) => readString(row.code) === "MODULE_PLAN_SYMBOL_NOT_FOUND")
|
|
1093
|
+
.map((row) => readString(row.entity))
|
|
1094
|
+
.filter((entity) => Boolean(entity));
|
|
1095
|
+
const ambiguous = blocking
|
|
1096
|
+
.filter((row) => readString(row.code) === "MODULE_PLAN_SYMBOL_AMBIGUOUS")
|
|
1097
|
+
.map((row) => readString(row.entity))
|
|
1098
|
+
.filter((entity) => Boolean(entity));
|
|
1099
|
+
const selectorHandled = notFound.length + ambiguous.length;
|
|
1100
|
+
if (notFound.length > 0) {
|
|
1101
|
+
lines.push(`not found symbols: ${notFound.join(", ")}`);
|
|
1102
|
+
}
|
|
1103
|
+
if (ambiguous.length > 0) {
|
|
1104
|
+
lines.push(`ambiguous symbols: ${ambiguous.join(", ")}`);
|
|
1105
|
+
}
|
|
1106
|
+
const manualExtractionRows = blocking.filter((row) => readManualExtractionEntities(row).length > 0);
|
|
1107
|
+
appendModulePlanManualExtractionLines(lines, manualExtractionRows);
|
|
1108
|
+
const remaining = blocking.filter((row) => readString(row.code) !== "MODULE_PLAN_SYMBOL_NOT_FOUND" &&
|
|
1109
|
+
readString(row.code) !== "MODULE_PLAN_SYMBOL_AMBIGUOUS" &&
|
|
1110
|
+
readManualExtractionEntities(row).length === 0);
|
|
1111
|
+
if (selectorHandled > 0 && remaining.length === 0) {
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
if (manualExtractionRows.length > 0 && remaining.length === 0) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
lines.push("blocking:");
|
|
1118
|
+
for (const row of remaining.length > 0 ? remaining : blocking) {
|
|
1119
|
+
const target = readString(row.target);
|
|
1120
|
+
const entity = readString(row.entity);
|
|
1121
|
+
const code = readString(row.code);
|
|
1122
|
+
const error = readString(row.error);
|
|
1123
|
+
const hint = readString(row.hint);
|
|
1124
|
+
const next = readString(row.next);
|
|
1125
|
+
if (target) {
|
|
1126
|
+
lines.push(target);
|
|
1127
|
+
}
|
|
1128
|
+
if (entity || code) {
|
|
1129
|
+
lines.push([entity, code].filter(Boolean).join(": "));
|
|
1130
|
+
}
|
|
1131
|
+
if (error) {
|
|
1132
|
+
lines.push(error);
|
|
1133
|
+
}
|
|
1134
|
+
if (hint) {
|
|
1135
|
+
lines.push(`hint: ${hint}`);
|
|
1136
|
+
}
|
|
1137
|
+
if (next) {
|
|
1138
|
+
lines.push(`next: ${next}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
function appendModulePlanManualExtractionLines(lines, rows) {
|
|
1143
|
+
const grouped = new Map();
|
|
1144
|
+
for (const row of rows) {
|
|
1145
|
+
const target = readString(row.target);
|
|
1146
|
+
if (!target) {
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
const entities = readManualExtractionEntities(row);
|
|
1150
|
+
if (entities.length === 0) {
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
const list = grouped.get(target) ?? [];
|
|
1154
|
+
list.push(...entities);
|
|
1155
|
+
grouped.set(target, list);
|
|
1156
|
+
}
|
|
1157
|
+
if (grouped.size === 0) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
lines.push("manualExtractionRequired:");
|
|
1161
|
+
for (const [target, entities] of grouped) {
|
|
1162
|
+
lines.push(`${target}: ${formatInlineList(uniqueStringsInOrder(entities), 15)}`);
|
|
1163
|
+
}
|
|
1164
|
+
lines.push("reason: TypeScript move-to-file provider cannot produce edits for these symbols.");
|
|
1165
|
+
lines.push("next: use manual extraction for listed symbols");
|
|
1166
|
+
}
|
|
1167
|
+
function appendPostMutationCyclesText(lines, cycles) {
|
|
1168
|
+
lines.push("cycles:");
|
|
1169
|
+
const count = readNumber(cycles.newOrChangedCount) ?? 0;
|
|
1170
|
+
if (count === 0) {
|
|
1171
|
+
lines.push("no new/changed cycles involving touched files");
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
const components = Array.isArray(cycles.components) ? cycles.components.filter(isJsonObject) : [];
|
|
1175
|
+
lines.push(formatPostMutationCycleSummary(count, components));
|
|
1176
|
+
components.forEach((component, index) => {
|
|
1177
|
+
(0, inspect_cycles_1.appendCycleComponentText)(lines, component, {
|
|
1178
|
+
detail: "imports",
|
|
1179
|
+
prefix: components.length === 1 ? "" : `${index + 1}. `,
|
|
1180
|
+
indent: components.length === 1 ? "" : " "
|
|
1181
|
+
});
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
function formatPostMutationCycleSummary(count, components) {
|
|
1185
|
+
const kinds = components.map((component) => readString(component.kind) ?? "mixed");
|
|
1186
|
+
const uniqueKinds = Array.from(new Set(kinds));
|
|
1187
|
+
const kindText = uniqueKinds.length === 1 ? `${uniqueKinds[0]} ` : "";
|
|
1188
|
+
return `${count} new/changed ${kindText}${count === 1 ? "cycle" : "cycles"} involving touched files`;
|
|
1189
|
+
}
|
|
1190
|
+
function readNormalizedModules(request) {
|
|
1191
|
+
return Array.isArray(request.modules) ? request.modules.filter(isJsonObject) : [];
|
|
1192
|
+
}
|
|
1193
|
+
function countModuleEntities(modules) {
|
|
1194
|
+
return modules.reduce((count, module) => {
|
|
1195
|
+
const normalizedEntities = readModuleEntities(module);
|
|
1196
|
+
if (normalizedEntities.length > 0) {
|
|
1197
|
+
return count + normalizedEntities.length;
|
|
1198
|
+
}
|
|
1199
|
+
const rawEntities = Array.isArray(module.entities) ? module.entities : [];
|
|
1200
|
+
const rawSymbols = Array.isArray(module.symbols) ? module.symbols : [];
|
|
1201
|
+
return count + Math.max(rawEntities.length, rawSymbols.length);
|
|
1202
|
+
}, 0);
|
|
1203
|
+
}
|
|
1204
|
+
function countRowEntities(rows) {
|
|
1205
|
+
return rows.reduce((count, row) => count + readStringArray(row.entities).length, 0);
|
|
1206
|
+
}
|
|
1207
|
+
function readModuleEntities(module) {
|
|
1208
|
+
const symbols = Array.isArray(module.symbols) ? module.symbols.filter(isJsonObject) : [];
|
|
1209
|
+
return symbols
|
|
1210
|
+
.map((symbol) => readString(symbol.raw) ?? readString(symbol.selector) ?? readString(symbol.entity))
|
|
1211
|
+
.filter((value) => Boolean(value));
|
|
1212
|
+
}
|
|
1213
|
+
function readManualExtractionEntities(row) {
|
|
1214
|
+
const items = Array.isArray(row.manualExtractionRequired) ? row.manualExtractionRequired.filter(isJsonObject) : [];
|
|
1215
|
+
return items
|
|
1216
|
+
.map((item) => readString(item.entity))
|
|
1217
|
+
.filter((entity) => Boolean(entity));
|
|
1218
|
+
}
|
|
1219
|
+
function readSourceFile(cwd, payload) {
|
|
1220
|
+
const sourceFile = payload.sourceFile ?? payload.file;
|
|
1221
|
+
if (!sourceFile) {
|
|
1222
|
+
throw new errors_1.CliError("MODULE_PLAN_SOURCE_REQUIRED", "modulePlan expects sourceFile or file.");
|
|
1223
|
+
}
|
|
1224
|
+
return (0, module_plan_cache_1.resolveCliFilePath)(cwd, sourceFile);
|
|
1225
|
+
}
|
|
1226
|
+
function collectBlockingRows(previewResult) {
|
|
1227
|
+
return Array.isArray(previewResult.blocking) ? previewResult.blocking.filter(isJsonObject) : [];
|
|
1228
|
+
}
|
|
1229
|
+
function summarizeWrittenFiles(written) {
|
|
1230
|
+
return compactStringList(written, 15);
|
|
1231
|
+
}
|
|
1232
|
+
async function readRemainingSourceSummary(cwd, sourceFile, _options) {
|
|
1233
|
+
try {
|
|
1234
|
+
const text = fs.readFileSync(sourceFile, "utf8");
|
|
1235
|
+
const declarations = (0, semantic_move_declarations_1.collectSemanticMoveDeclarations)(sourceFile, text);
|
|
1236
|
+
const symbols = uniqueStringsInOrder(declarations.map((declaration) => declaration.name));
|
|
1237
|
+
return {
|
|
1238
|
+
file: (0, module_plan_cache_1.formatRelativePath)(cwd, sourceFile),
|
|
1239
|
+
symbols,
|
|
1240
|
+
hasNonDeclarationText: hasNonDeclarationSourceText(sourceFile, text)
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
catch {
|
|
1244
|
+
return null;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
function hasNonDeclarationSourceText(file, text) {
|
|
1248
|
+
const source = typescript_1.default.createSourceFile(file, text, typescript_1.default.ScriptTarget.Latest, true, file.endsWith("x") ? typescript_1.default.ScriptKind.TSX : typescript_1.default.ScriptKind.TS);
|
|
1249
|
+
const ranges = (0, semantic_move_declarations_1.collectSemanticMoveDeclarations)(file, text)
|
|
1250
|
+
.map((declaration) => ({ start: declaration.statementStart, end: declaration.statementEnd }))
|
|
1251
|
+
.filter((range, index, all) => index === 0 || range.start !== all[index - 1].start || range.end !== all[index - 1].end)
|
|
1252
|
+
.sort((left, right) => right.start - left.start);
|
|
1253
|
+
let remaining = source.getFullText();
|
|
1254
|
+
for (const range of ranges)
|
|
1255
|
+
remaining = `${remaining.slice(0, range.start)}${remaining.slice(range.end)}`;
|
|
1256
|
+
return remaining.trim().length > 0;
|
|
1257
|
+
}
|
|
1258
|
+
function compactStringList(items, limit) {
|
|
1259
|
+
const visible = items.slice(0, limit);
|
|
1260
|
+
const hidden = items.length - visible.length;
|
|
1261
|
+
return hidden > 0 ? [...visible, `+ ${hidden} more`] : visible;
|
|
1262
|
+
}
|
|
1263
|
+
function formatInlineList(items, limit) {
|
|
1264
|
+
const visible = items.slice(0, limit);
|
|
1265
|
+
const hidden = items.length - visible.length;
|
|
1266
|
+
return hidden > 0 ? `${visible.join(", ")}, +${hidden} more` : visible.join(", ");
|
|
1267
|
+
}
|
|
1268
|
+
function payloadExecute(rawPayload) {
|
|
1269
|
+
return Boolean(rawPayload && typeof rawPayload === "object" && !Array.isArray(rawPayload) && rawPayload.execute === true);
|
|
1270
|
+
}
|
|
1271
|
+
function readFlagValue(args, flag) {
|
|
1272
|
+
const index = args.indexOf(flag);
|
|
1273
|
+
if (index < 0) {
|
|
1274
|
+
return null;
|
|
1275
|
+
}
|
|
1276
|
+
const value = args[index + 1];
|
|
1277
|
+
return value && !value.startsWith("--") ? value : null;
|
|
1278
|
+
}
|
|
1279
|
+
function readString(value) {
|
|
1280
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : null;
|
|
1281
|
+
}
|
|
1282
|
+
function readNumber(value) {
|
|
1283
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1284
|
+
}
|
|
1285
|
+
function readStringArray(value) {
|
|
1286
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1287
|
+
}
|
|
1288
|
+
function uniqueStrings(values) {
|
|
1289
|
+
return Array.from(new Set(values)).sort((left, right) => left.localeCompare(right));
|
|
1290
|
+
}
|
|
1291
|
+
function uniqueStringsInOrder(values) {
|
|
1292
|
+
return Array.from(new Set(values));
|
|
1293
|
+
}
|
|
1294
|
+
function compactObject(input) {
|
|
1295
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => {
|
|
1296
|
+
if (value === null || value === undefined) {
|
|
1297
|
+
return false;
|
|
1298
|
+
}
|
|
1299
|
+
return !(Array.isArray(value) && value.length === 0);
|
|
1300
|
+
}));
|
|
1301
|
+
}
|
|
1302
|
+
function isJsonObject(value) {
|
|
1303
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1304
|
+
}
|
|
1305
|
+
function toJsonObject(value) {
|
|
1306
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toJsonValue(item)]));
|
|
1307
|
+
}
|
|
1308
|
+
function toJsonValue(value) {
|
|
1309
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1310
|
+
return value;
|
|
1311
|
+
}
|
|
1312
|
+
if (Array.isArray(value)) {
|
|
1313
|
+
return value.map((item) => toJsonValue(item));
|
|
1314
|
+
}
|
|
1315
|
+
if (value && typeof value === "object") {
|
|
1316
|
+
return toJsonObject(value);
|
|
1317
|
+
}
|
|
1318
|
+
return String(value);
|
|
1319
|
+
}
|