@automaton-labs/aib 0.0.6 → 0.0.8
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 +36 -257
- 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 -2
- 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 -0
- package/dist/commands/captured-input.js +74 -2
- package/dist/commands/config-command.js +314 -2
- package/dist/commands/config-output.js +357 -10
- package/dist/commands/control-plane-command.js +183 -0
- package/dist/commands/declaration-command.js +1209 -0
- package/dist/commands/declaration-execution-cache.js +79 -0
- package/dist/commands/declaration-format.js +221 -0
- package/dist/commands/declaration-preview-cache.js +114 -0
- package/dist/commands/diagnostics-command.js +70 -3
- package/dist/commands/doctor.js +137 -2
- 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 -0
- package/dist/commands/file-move-to-dir-preview-cache.js +125 -0
- package/dist/commands/file-move-to-dir-worker.js +54 -0
- package/dist/commands/file-move-to-dir.js +1073 -0
- package/dist/commands/file-mutation-runtime.js +102 -0
- package/dist/commands/file-mutation-worker-apply.js +180 -0
- package/dist/commands/file-refactor-batch-execution-cache.js +90 -0
- package/dist/commands/file-refactor-batch-preview-cache.js +125 -0
- package/dist/commands/file-refactor-batch-worker.js +54 -0
- package/dist/commands/file-refactor-batch.js +1154 -0
- package/dist/commands/file-rename-execution-cache.js +92 -0
- package/dist/commands/file-rename-preview-cache.js +125 -0
- package/dist/commands/file-rename-worker.js +54 -0
- package/dist/commands/file-rename.js +1053 -0
- 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 -0
- 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 -6
- 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 -0
- 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 -0
- package/dist/dsl/file-move-to-dir-dsl.js +123 -0
- package/dist/dsl/file-refactor-batch-dsl.js +203 -0
- package/dist/dsl/file-rename-dsl.js +135 -0
- package/dist/dsl/mutate-dsl.js +746 -0
- package/dist/help/bootstrap.bash.md +742 -0
- package/dist/help/bootstrap.md +236 -437
- package/dist/help/bootstrap.pwsh.md +742 -0
- 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/dsl.md +4 -3
- 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 +5 -11
- package/dist/help/docs/inspect.deps.md +7 -7
- package/dist/help/docs/inspect.file.md +10 -18
- package/dist/help/docs/inspect.graph.md +6 -20
- package/dist/help/docs/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/docs/modulePlan.md +24 -28
- package/dist/help/docs/move.md +19 -22
- package/dist/help/docs/moveToDir.md +46 -0
- 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 -16
- package/dist/help/docs/qr.md +13 -22
- package/dist/help/docs/quick-map.md +36 -23
- package/dist/help/docs/recipe.file-layout.md +15 -0
- 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/rg.md +22 -0
- package/dist/help/docs/rules.md +26 -0
- package/dist/help/docs/selectors.md +3 -2
- package/dist/help/docs/session.md +1 -1
- package/dist/help/dsl/bootstrap.bash.md +742 -0
- package/dist/help/dsl/bootstrap.md +236 -437
- package/dist/help/dsl/bootstrap.pwsh.md +742 -0
- 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/dsl.md +4 -3
- 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 +5 -11
- package/dist/help/dsl/docs/inspect.deps.md +7 -7
- package/dist/help/dsl/docs/inspect.file.md +10 -18
- package/dist/help/dsl/docs/inspect.graph.md +6 -20
- package/dist/help/dsl/docs/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/dsl/docs/modulePlan.md +24 -28
- package/dist/help/dsl/docs/move.md +19 -22
- package/dist/help/dsl/docs/moveToDir.md +46 -0
- 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 -16
- package/dist/help/dsl/docs/qr.md +13 -22
- package/dist/help/dsl/docs/quick-map.md +36 -23
- package/dist/help/dsl/docs/recipe.file-layout.md +15 -0
- 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/rg.md +22 -0
- package/dist/help/dsl/docs/rules.md +26 -0
- package/dist/help/dsl/docs/selectors.md +3 -2
- package/dist/help/dsl/docs/session.md +1 -1
- package/dist/help/dsl/full.md +236 -437
- package/dist/help/dsl/help-index.md +49 -0
- package/dist/help/dsl/snippets/agents.md +2 -2
- package/dist/help/dsl/tokens/qr.inline.examples.md +2 -0
- package/dist/help/dsl/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- 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/dsl.md +4 -3
- 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 +5 -11
- package/dist/help/dsl/topics/inspect.deps.md +7 -7
- package/dist/help/dsl/topics/inspect.file.md +10 -18
- package/dist/help/dsl/topics/inspect.graph.md +6 -20
- package/dist/help/dsl/topics/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/dsl/topics/modulePlan.md +21 -26
- package/dist/help/dsl/topics/move.md +17 -18
- package/dist/help/dsl/topics/moveToDir.md +44 -0
- 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 -16
- package/dist/help/dsl/topics/qr.md +13 -22
- package/dist/help/dsl/topics/quick-map.md +36 -23
- package/dist/help/dsl/topics/recipe.file-layout.md +13 -0
- 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/rg.md +20 -0
- package/dist/help/dsl/topics/rules.md +24 -0
- package/dist/help/dsl/topics/selectors.md +3 -2
- package/dist/help/dsl/topics/session.md +1 -1
- package/dist/help/full.md +236 -437
- package/dist/help/help-index.md +49 -0
- package/dist/help/help-meta.json +114 -48
- package/dist/help/index.md +76 -87
- package/dist/help/snippets/agents.md +2 -2
- package/dist/help/tokens/qr.inline.examples.md +2 -0
- package/dist/help/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- 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/dsl.md +4 -3
- 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 +5 -11
- package/dist/help/topics/inspect.deps.md +7 -7
- package/dist/help/topics/inspect.file.md +10 -18
- package/dist/help/topics/inspect.graph.md +6 -20
- package/dist/help/topics/{inspect.md → inspect.shared.md} +18 -17
- package/dist/help/topics/modulePlan.md +21 -26
- package/dist/help/topics/move.md +17 -18
- package/dist/help/topics/moveToDir.md +44 -0
- 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 -16
- package/dist/help/topics/qr.md +13 -22
- package/dist/help/topics/quick-map.md +36 -23
- package/dist/help/topics/recipe.file-layout.md +13 -0
- 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/rg.md +20 -0
- package/dist/help/topics/rules.md +24 -0
- package/dist/help/topics/selectors.md +3 -2
- package/dist/help/topics/session.md +1 -1
- package/dist/host/capabilities.js +56 -0
- 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 +210 -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 -0
- package/dist/rg-wrapper/options.js +125 -0
- package/dist/rtk-wrapper/core.js +144 -0
- 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 -0
- 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 -8
- 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 -3
- package/dist/shared/stdout.js +6 -2
- package/dist/shared/types.js +23 -1
- package/dist/tool-runtime/runtime-tools.js +120 -0
- 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 +80 -0
- package/dist/workers/control-plane/client-config.default.json +3 -0
- 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 -0
- package/dist/workers/registry.js +241 -0
- package/package.json +8 -11
- package/runtimes/tools/rg/darwin-arm64/rg +0 -0
- package/runtimes/tools/rg/darwin-x64/rg +0 -0
- package/runtimes/tools/rg/linux-arm64/rg +0 -0
- package/runtimes/tools/rg/linux-x64/rg +0 -0
- package/runtimes/tools/rg/manifest.json +36 -0
- package/runtimes/tools/rg/win32-x64/rg.exe +0 -0
- package/runtimes/tools/rtk/darwin-arm64/rtk +0 -0
- package/runtimes/tools/rtk/darwin-x64/rtk +0 -0
- package/runtimes/tools/rtk/linux-arm64/rtk +0 -0
- package/runtimes/tools/rtk/linux-x64/rtk +0 -0
- package/runtimes/tools/rtk/manifest.json +36 -0
- package/runtimes/tools/rtk/win32-x64/rtk.exe +0 -0
- 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/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/mutation.md +0 -50
- package/dist/help/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/docs/mutation.md +0 -50
- package/dist/help/dsl/docs/refactor.batch.md +0 -44
- package/dist/help/dsl/topics/mutation.md +0 -48
- package/dist/help/dsl/topics/refactor.batch.md +0 -33
- package/dist/help/json/bootstrap.md +0 -1085
- package/dist/help/json/docs/basics.md +0 -15
- package/dist/help/json/docs/config-setup.aliases.md +0 -56
- package/dist/help/json/docs/config-setup.excludes.md +0 -45
- package/dist/help/json/docs/config-setup.import-normalize.md +0 -86
- package/dist/help/json/docs/config-setup.import-rules.md +0 -96
- package/dist/help/json/docs/config-setup.tsconfigs.md +0 -33
- package/dist/help/json/docs/dsl.md +0 -25
- package/dist/help/json/docs/first-setup.md +0 -292
- package/dist/help/json/docs/help-format.md +0 -9
- package/dist/help/json/docs/help-protocol.md +0 -26
- package/dist/help/json/docs/imports.normalize.md +0 -47
- package/dist/help/json/docs/inspect.code.md +0 -41
- package/dist/help/json/docs/inspect.cycles.md +0 -38
- package/dist/help/json/docs/inspect.deps.md +0 -46
- package/dist/help/json/docs/inspect.duplicates.md +0 -65
- package/dist/help/json/docs/inspect.exports.md +0 -40
- package/dist/help/json/docs/inspect.file.md +0 -38
- package/dist/help/json/docs/inspect.graph.md +0 -139
- package/dist/help/json/docs/inspect.imports.md +0 -15
- package/dist/help/json/docs/inspect.md +0 -88
- package/dist/help/json/docs/inspect.members.md +0 -32
- package/dist/help/json/docs/inspect.tree.md +0 -32
- package/dist/help/json/docs/inspect.usages.md +0 -61
- package/dist/help/json/docs/modulePlan.md +0 -73
- package/dist/help/json/docs/move.md +0 -56
- package/dist/help/json/docs/mutation.md +0 -65
- package/dist/help/json/docs/patterns.md +0 -76
- package/dist/help/json/docs/prefs.md +0 -40
- package/dist/help/json/docs/qr.md +0 -37
- package/dist/help/json/docs/quick-map.md +0 -30
- package/dist/help/json/docs/refactor.batch.md +0 -72
- package/dist/help/json/docs/rename.md +0 -47
- package/dist/help/json/docs/reveal.md +0 -30
- package/dist/help/json/docs/selectors.md +0 -23
- package/dist/help/json/docs/session.md +0 -77
- package/dist/help/json/docs/view.md +0 -30
- package/dist/help/json/full.md +0 -1085
- package/dist/help/json/snippets/agents.md +0 -14
- package/dist/help/json/topics/basics.md +0 -13
- package/dist/help/json/topics/config-setup.aliases.md +0 -54
- package/dist/help/json/topics/config-setup.excludes.md +0 -43
- package/dist/help/json/topics/config-setup.import-normalize.md +0 -84
- package/dist/help/json/topics/config-setup.import-rules.md +0 -94
- package/dist/help/json/topics/config-setup.tsconfigs.md +0 -31
- package/dist/help/json/topics/dsl.md +0 -23
- package/dist/help/json/topics/first-setup.md +0 -290
- package/dist/help/json/topics/help-format.md +0 -7
- package/dist/help/json/topics/help-protocol.md +0 -24
- package/dist/help/json/topics/imports.normalize.md +0 -45
- package/dist/help/json/topics/inspect.code.md +0 -39
- package/dist/help/json/topics/inspect.cycles.md +0 -36
- package/dist/help/json/topics/inspect.deps.md +0 -44
- package/dist/help/json/topics/inspect.duplicates.md +0 -37
- package/dist/help/json/topics/inspect.exports.md +0 -38
- package/dist/help/json/topics/inspect.file.md +0 -36
- package/dist/help/json/topics/inspect.graph.md +0 -137
- package/dist/help/json/topics/inspect.imports.md +0 -13
- package/dist/help/json/topics/inspect.md +0 -86
- package/dist/help/json/topics/inspect.members.md +0 -30
- package/dist/help/json/topics/inspect.tree.md +0 -22
- package/dist/help/json/topics/inspect.usages.md +0 -59
- package/dist/help/json/topics/modulePlan.md +0 -60
- package/dist/help/json/topics/move.md +0 -46
- package/dist/help/json/topics/mutation.md +0 -63
- package/dist/help/json/topics/patterns.md +0 -74
- package/dist/help/json/topics/prefs.md +0 -38
- package/dist/help/json/topics/qr.md +0 -35
- package/dist/help/json/topics/quick-map.md +0 -28
- package/dist/help/json/topics/refactor.batch.md +0 -61
- package/dist/help/json/topics/rename.md +0 -42
- package/dist/help/json/topics/reveal.md +0 -28
- package/dist/help/json/topics/selectors.md +0 -21
- package/dist/help/json/topics/session.md +0 -59
- package/dist/help/json/topics/view.md +0 -28
- package/dist/help/topics/mutation.md +0 -48
- 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 -1904
- 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
package/dist/session/server.js
CHANGED
|
@@ -1,8 +1,1194 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`)}class K{server;constructor(){this.server=ne.createServer((t,n)=>{this.handleRequest(t,n)})}async handleRequest(t,n){if(t.method==="GET"&&t.url==="/health"){E(n,200,{ok:!0,pid:process.pid});return}if(t.method==="POST"&&t.url==="/run")try{const r=await k(t),i=r?JSON.parse(r):{};if(typeof i.command!="string"||!Array.isArray(i.restArgs)||typeof i.cwd!="string")throw new g.CliError("INVALID_SESSION_REQUEST","Invalid session request payload.");const o=Pe(i.stdinInputSource),s={command:i.command,restArgs:i.restArgs.filter(p=>typeof p=="string"),cwd:i.cwd,stdinPayload:i.stdinPayload,metricsEnabled:i.metricsEnabled===!0};o!==void 0&&(s.stdinInputSource=o);const u=J(i.transport),f=Ie(i.env);u&&(s.transport=u),s.autoStartIde=(0,D.autoStartIdePolicyFromSession)(i.autoStartIde)??(0,D.resolveAutoStartIdePolicy)();const c=s.metricsEnabled?[]:void 0;c&&(s.metricsSpans=c),typeof i.instanceId=="string"&&(s.instanceId=i.instanceId),typeof i.sessionId=="string"&&(s.sessionId=i.sessionId),typeof i.modulePlanExecutionId=="string"&&(s.modulePlanExecutionId=i.modulePlanExecutionId),i.suppressModulePlanStreamStart===!0&&(s.suppressModulePlanStreamStart=!0);const I=(0,S.metricsNow)(),y=F(f,()=>(0,V.runCommand)(s)).then(p=>((0,S.recordSpan)(c,"session.runCommand",I),p),p=>{throw(0,S.recordSpan)(c,"session.runCommand",I),p}),l=$(s);if(l>0){const p=await W(s,y,l);if(p.status==="deadline"){y.catch(()=>{}),(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.deadline.output.start",{deadlineMs:l});const v=await j(s,l);(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.start",{mode:"deadline"}),E(n,200,v),(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.end",{mode:"deadline"});return}const P=p.result;(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.start",{mode:"result"}),E(n,200,c?(0,S.appendMetrics)(P,c):P),(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.end",{mode:"result"});return}const m=await y;(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.start",{mode:"no-deadline"}),E(n,200,c?(0,S.appendMetrics)(m,c):m),(0,d.recordModulePlanTimeline)(s.cwd,s.modulePlanExecutionId,"session.run.response.write.end",{mode:"no-deadline"});return}catch(r){E(n,500,(0,g.errorPayload)(r));return}if(t.method==="POST"&&t.url==="/cli"){let r=null,i=0,o=null;try{o=await X(t),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.request.parsed",{command:o.input.command,args:o.input.restArgs}),i=Date.now(),r=Y(o,i);const s=o.env,u=(0,S.metricsNow)();(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.runCommand.start");const f=F(s,()=>(0,V.runCommand)(o.input)).then(l=>((0,S.recordSpan)(o.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.runCommand.resolved"),l),l=>{throw(0,S.recordSpan)(o.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.runCommand.rejected",{error:l instanceof Error?l.message:String(l)}),l}),c=$(o.input);if(c>0){const l=await W(o.input,f,c);if(l.status==="deadline"){f.catch(()=>{}),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.deadline.output.start",{deadlineMs:c});const P=h(await j(o.input,c));M(r,o,P,0,i),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"deadline"}),E(n,200,P),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"deadline"});return}const m=l.result,p=h(o.spans?(0,S.appendMetrics)(m,o.spans):m);M(r,o,p,0,i),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"result"}),E(n,200,p),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"result"});return}const I=await f,y=h(o.spans?(0,S.appendMetrics)(I,o.spans):I);M(r,o,y,0,i),E(n,200,y);return}catch(s){const u=h((0,g.errorPayload)(s));M(r,o,u,1,i),E(n,500,u);return}}if(t.method==="POST"&&t.url==="/cli/stream"){let r=null,i=null,o=0,s=null;try{if(s=await X(t,{streamGate:!0}),!Q(s.input)){n.writeHead(204),n.end();return}z(n),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.request.parsed",{command:s.input.command,args:s.input.restArgs}),o=Date.now(),i=Y(s,o),r=we(n,s.input);const u=s.env,f=(0,S.metricsNow)();(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.runCommand.start");const c=F(u,()=>(0,V.runCommand)(s.input)).then(m=>((0,S.recordSpan)(s.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.runCommand.resolved"),m),m=>{throw(0,S.recordSpan)(s.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.runCommand.rejected",{error:m instanceof Error?m.message:String(m)}),m}),I=$(s.input);if(I>0){const m=await W(s.input,c,I);if(m.status==="deadline"){c.catch(()=>{}),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.deadline.output.start",{deadlineMs:I});const v=h(await j(s.input,I));M(i,s,v,0,o),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.response.write.start",{mode:"deadline"}),C(n,{type:"result",payload:v}),n.end(),(0,d.recordModulePlanTimeline)(s.input.cwd,s.input.modulePlanExecutionId,"session.cliStream.response.write.end",{mode:"deadline"});return}const p=m.result,P=h(s.spans?(0,S.appendMetrics)(p,s.spans):p);M(i,s,P,0,o),C(n,{type:"result",payload:P}),n.end();return}const y=await c,l=h(s.spans?(0,S.appendMetrics)(y,s.spans):y);M(i,s,l,0,o),C(n,{type:"result",payload:l}),n.end();return}catch(u){n.headersSent||z(n);const f=h((0,g.errorPayload)(u));M(i,s,f,1,o),C(n,{type:"error",payload:f}),n.end();return}finally{r&&clearInterval(r)}}E(n,404,{ok:!1,error:"Not found"})}async serve(){await new Promise((i,o)=>{this.server.once("error",o),this.server.listen(0,"127.0.0.1",()=>i())});const t=this.server.address();if(!t||typeof t=="string")throw new Error("Failed to determine aib session address.");me({pid:process.pid,host:"127.0.0.1",port:t.port,url:`http://127.0.0.1:${t.port}`,startedAt:new Date().toISOString()});let n=!1;const r=()=>{n||(n=!0,fe(),this.server.close(()=>{process.exit(0)}),setTimeout(()=>{process.exit(0)},1e3).unref())};process.on("SIGTERM",r),process.on("SIGINT",r),await new Promise(()=>{})}}exports.CliSessionServer=K;function Q(e){return e.command==="diagnostics"&&e.restArgs[0]==="timeout-stream"}function z(e){e.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"}),e.flushHeaders()}async function X(e,t={}){const n=await k(e),r=new URLSearchParams(n),i=r.get("command")??r.get("method")??"",o=r.get("cwd")??"",s=r.get("instanceId")??void 0,u=r.get("sessionId")??void 0,f=r.get("modulePlanExecutionId")??void 0,c=r.get("suppressModulePlanStreamStart")==="true",I=r.get("metricsEnabled")==="true",y=J(r.get("transport")),l=(0,D.autoStartIdePolicyFromSession)(r.get("autoStartIde"))??(0,D.resolveAutoStartIdePolicy)(),m=Ee(r.get("traceDir")),p=ge(r);if(!i.trim())throw new g.CliError("MISSING_COMMAND","Missing command.");if(!o.trim())throw new g.CliError("MISSING_CWD","Missing cwd.");const P=I?[]:void 0,v=(0,S.metricsNow)(),T=await(0,ae.resolveCanonicalCommandAlias)(i.trim(),o,s,l);(0,S.recordSpan)(P,"session.aliasResolution",v);const b=(0,R.stripStdinFormatFlags)(r.getAll("arg")),L=b.restArgs,w={command:T,restArgs:L,cwd:o,metricsEnabled:I,autoStartIde:l};if(y&&(w.transport=y),s&&(w.instanceId=s),u&&(w.sessionId=u),f&&(w.modulePlanExecutionId=f),c&&(w.suppressModulePlanStreamStart=!0),P&&(w.metricsSpans=P),t.streamGate===!0&&!Q(w))return{input:w,spans:P,...m!==void 0?{traceDir:m}:{},env:p};const q=Se(r.get("stdin"),T,L,b.format),_={command:T,restArgs:L,cwd:o,stdinPayload:pe(r.get("stdin"),T,L,b.format),metricsEnabled:I,autoStartIde:l};return q!==void 0&&(_.stdinInputSource=q),y&&(_.transport=y),s&&(_.instanceId=s),u&&(_.sessionId=u),f&&(_.modulePlanExecutionId=f),c&&(_.suppressModulePlanStreamStart=!0),P&&(_.metricsSpans=P),{input:_,spans:P,...m!==void 0?{traceDir:m}:{},env:p}}function ge(e){const t={},n=[[a.CLI_ENV.metrics,e.get("metrics")??""],[a.CLI_ENV.metricsDir,e.get("metricsDir")??""],[a.CLI_ENV.metricsTag,e.get("metricsTag")??""],[a.CLI_ENV.mutationImpactMetrics,e.get("mutationImpactMetrics")??""],[a.CLI_ENV.mutationImpactStream,e.get("mutationImpactStream")??""],[a.CLI_ENV.testMoveToFileFailEntity,e.get("testMoveToFileFailEntity")??""],[a.CLI_ENV.testPostMutationCyclesDelayMs,e.get("testPostMutationCyclesDelayMs")??""],[a.CLI_ENV.testRefactorBatchDelayMs,e.get("testRefactorBatchDelayMs")??""],[a.CLI_ENV.testRenameDelayMs,e.get("testRenameDelayMs")??""],[a.CLI_ENV.modulePlanSyncWaitMs,e.get("modulePlanSyncWaitMs")??""],[a.CLI_ENV.refactorBatchSyncWaitMs,e.get("refactorBatchSyncWaitMs")??""],[a.CLI_ENV.renameSyncWaitMs,e.get("renameSyncWaitMs")??""],[a.CLI_ENV.modulePlanDebugTimeline,e.get("modulePlanDebugTimeline")??""],[a.CLI_ENV.trace,e.get("trace")??""],[a.CLI_ENV.failureSnapshots,e.get("failureSnapshots")??""],[a.CLI_ENV.productStorageDir,e.get("productStorageDir")??""]];for(const[r,i]of n){const o=i.trim();o&&(t[r]=o)}return t}function Ee(e){if(e===null)return;const t=e.trim();return t||void 0}function Y(e,t){return e.traceDir?(0,ie.startTrace)({cwd:e.input.cwd,argv:[e.input.command,...e.input.restArgs],command:e.input.command,restArgs:e.input.restArgs,...e.input.stdinPayload!==void 0?{stdinPayload:e.input.stdinPayload}:{},...e.input.stdinInputSource!==void 0?{stdinSource:e.input.stdinInputSource}:{},traceDir:e.traceDir,startedAtMs:t}):null}function M(e,t,n,r,i){if(!e?.enabled||!t)return;const o=(0,U.createCliPresentationEnvelope)(n);e.complete({output:o.tracePayload,stdoutText:o.text?`${o.text.trimEnd()}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CliSessionServer = void 0;
|
|
37
|
+
exports.runSessionServerCli = runSessionServerCli;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const http = __importStar(require("node:http"));
|
|
40
|
+
const product_storage_1 = require("../config/product-storage");
|
|
41
|
+
const request_routing_context_1 = require("../config/request-routing-context");
|
|
42
|
+
const workspace_root_1 = require("../config/workspace-root");
|
|
43
|
+
const agent_text_1 = require("../shared/agent-text");
|
|
44
|
+
const event_loop_1 = require("../shared/event-loop");
|
|
45
|
+
const errors_1 = require("../shared/errors");
|
|
46
|
+
const metrics_1 = require("../shared/metrics");
|
|
47
|
+
const stdout_1 = require("../shared/stdout");
|
|
48
|
+
const presentation_1 = require("../shared/presentation");
|
|
49
|
+
const trace_1 = require("../tracing/trace");
|
|
50
|
+
const run_command_1 = require("../runtime/run-command");
|
|
51
|
+
const resolve_command_alias_1 = require("../config/resolve-command-alias");
|
|
52
|
+
const env_vars_1 = require("../config/env-vars");
|
|
53
|
+
const paths_1 = require("./paths");
|
|
54
|
+
const lane_owner_1 = require("./lane-owner");
|
|
55
|
+
const daemon_state_1 = require("./daemon-state");
|
|
56
|
+
const module_plan_cache_1 = require("../commands/module-plan-cache");
|
|
57
|
+
const execution_command_1 = require("../commands/execution-command");
|
|
58
|
+
const read_stdin_json_1 = require("../payloads/read-stdin-json");
|
|
59
|
+
const module_plan_timeout_1 = require("../commands/module-plan-timeout");
|
|
60
|
+
const module_plan_timeline_1 = require("../diagnostics/module-plan-timeline");
|
|
61
|
+
const mutation_execution_cache_1 = require("../commands/mutation-execution-cache");
|
|
62
|
+
const mutation_eta_1 = require("../commands/mutation-eta");
|
|
63
|
+
const core_1 = require("../rtk-wrapper/core");
|
|
64
|
+
const workspace_semantic_context_pools_1 = require("../semantic/workspace-semantic-context-pools");
|
|
65
|
+
const semantic_worker_manager_1 = require("../semantic/semantic-worker-manager");
|
|
66
|
+
const lexical_worker_manager_1 = require("../workers/lexical-worker-manager");
|
|
67
|
+
const external_tool_coordinator_1 = require("./external-tool-coordinator");
|
|
68
|
+
const runtime_lifecycle_1 = require("./runtime-lifecycle");
|
|
69
|
+
const runtime_shutdown_1 = require("./runtime-shutdown");
|
|
70
|
+
const session_health_1 = require("./session-health");
|
|
71
|
+
const external_tool_request_1 = require("./external-tool-request");
|
|
72
|
+
const MODULE_PLAN_HEARTBEAT_ENABLED = false;
|
|
73
|
+
const MODULE_PLAN_PROGRESS_STREAM_ENABLED = false;
|
|
74
|
+
function writeSessionInfo(info) {
|
|
75
|
+
fs.mkdirSync((0, paths_1.getSessionDir)(), { recursive: true });
|
|
76
|
+
atomicWriteText((0, paths_1.getSessionInfoPath)(), JSON.stringify(info, null, 2));
|
|
77
|
+
atomicWriteText((0, paths_1.getSessionUrlPath)(), `${info.url}\n`);
|
|
78
|
+
}
|
|
79
|
+
function removeSessionInfo(ownerPid = process.pid) {
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(fs.readFileSync((0, paths_1.getSessionInfoPath)(), "utf8"));
|
|
82
|
+
if (parsed.pid !== ownerPid)
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
fs.rmSync((0, paths_1.getSessionInfoPath)(), { force: true });
|
|
89
|
+
fs.rmSync((0, paths_1.getSessionUrlPath)(), { force: true });
|
|
90
|
+
}
|
|
91
|
+
function atomicWriteText(filePath, text) {
|
|
92
|
+
const tmpPath = `${filePath}.${process.pid}.tmp`;
|
|
93
|
+
fs.writeFileSync(tmpPath, text);
|
|
94
|
+
fs.renameSync(tmpPath, filePath);
|
|
95
|
+
}
|
|
96
|
+
async function collectRequestBody(request) {
|
|
97
|
+
const chunks = [];
|
|
98
|
+
for await (const chunk of request) {
|
|
99
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
100
|
+
}
|
|
101
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
102
|
+
}
|
|
103
|
+
function writeJson(response, statusCode, payload) {
|
|
104
|
+
const body = JSON.stringify(payload, null, 2);
|
|
105
|
+
response.writeHead(statusCode, {
|
|
106
|
+
"content-type": "application/json; charset=utf-8",
|
|
107
|
+
"content-length": Buffer.byteLength(body)
|
|
108
|
+
});
|
|
109
|
+
response.end(body);
|
|
110
|
+
}
|
|
111
|
+
function parseExecEnv(params) {
|
|
112
|
+
const allowed = new Set([
|
|
113
|
+
"NO_COLOR",
|
|
114
|
+
"CLICOLOR",
|
|
115
|
+
"CLICOLOR_FORCE",
|
|
116
|
+
"TERM",
|
|
117
|
+
"RG_CONFIG_PATH",
|
|
118
|
+
"RIPGREP_CONFIG_PATH",
|
|
119
|
+
"AIB_RG_TRIM_SPACES",
|
|
120
|
+
"AIB_RG_ALIASES",
|
|
121
|
+
env_vars_1.CLI_ENV.rgPath,
|
|
122
|
+
env_vars_1.CLI_ENV.rtkPath,
|
|
123
|
+
env_vars_1.CLI_ENV.tscPath,
|
|
124
|
+
env_vars_1.CLI_ENV.workspaceRoot,
|
|
125
|
+
env_vars_1.CLI_ENV.productStorageDir,
|
|
126
|
+
env_vars_1.CLI_ENV.helpShell
|
|
127
|
+
]);
|
|
128
|
+
const env = {};
|
|
129
|
+
for (const [key, value] of params.entries()) {
|
|
130
|
+
if (!key.startsWith("env.")) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const envName = key.slice("env.".length);
|
|
134
|
+
if (allowed.has(envName)) {
|
|
135
|
+
env[envName] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return env;
|
|
139
|
+
}
|
|
140
|
+
function writeStreamEvent(response, event) {
|
|
141
|
+
if (response.destroyed || response.writableEnded) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
response.write(`${JSON.stringify(event)}\n`);
|
|
145
|
+
const flushable = response;
|
|
146
|
+
if (typeof flushable.flush === "function") {
|
|
147
|
+
flushable.flush();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function parseCliStdinPayload(rawValue, command, restArgs, format) {
|
|
151
|
+
if (rawValue === null) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return (0, read_stdin_json_1.parseStdinPayload)(rawValue, {
|
|
155
|
+
command,
|
|
156
|
+
restArgs,
|
|
157
|
+
...(format !== undefined ? { format } : {})
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function parseCliStdinInputSource(rawValue, command, restArgs, format) {
|
|
161
|
+
if (rawValue === null) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
return (0, read_stdin_json_1.parseInputPayloadWithSource)(rawValue, {
|
|
165
|
+
command,
|
|
166
|
+
restArgs,
|
|
167
|
+
...(format !== undefined ? { format } : {})
|
|
168
|
+
}).source;
|
|
169
|
+
}
|
|
170
|
+
function parseSessionInputSource(rawValue) {
|
|
171
|
+
if (rawValue === undefined || rawValue === null) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
if (!rawValue || typeof rawValue !== "object" || Array.isArray(rawValue)) {
|
|
175
|
+
throw new errors_1.CliError("INVALID_SESSION_REQUEST", "Invalid stdin input source.");
|
|
176
|
+
}
|
|
177
|
+
const source = rawValue;
|
|
178
|
+
if ((source.format !== "json" && source.format !== "dsl") || typeof source.text !== "string") {
|
|
179
|
+
throw new errors_1.CliError("INVALID_SESSION_REQUEST", "Invalid stdin input source.");
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
format: source.format,
|
|
183
|
+
text: source.text
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function parseSessionEnv(rawValue) {
|
|
187
|
+
if (!rawValue || typeof rawValue !== "object" || Array.isArray(rawValue)) {
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
const allowed = new Set([
|
|
191
|
+
env_vars_1.CLI_ENV.workspaceRoot,
|
|
192
|
+
env_vars_1.CLI_ENV.helpShell,
|
|
193
|
+
env_vars_1.CLI_ENV.disableWatchers,
|
|
194
|
+
env_vars_1.CLI_ENV.trace,
|
|
195
|
+
env_vars_1.CLI_ENV.traceDir,
|
|
196
|
+
env_vars_1.CLI_ENV.failureSnapshots,
|
|
197
|
+
env_vars_1.CLI_ENV.productStorageDir,
|
|
198
|
+
env_vars_1.CLI_ENV.metrics,
|
|
199
|
+
env_vars_1.CLI_ENV.metricsDir,
|
|
200
|
+
env_vars_1.CLI_ENV.metricsTag,
|
|
201
|
+
env_vars_1.CLI_ENV.mutationImpactMetrics,
|
|
202
|
+
env_vars_1.CLI_ENV.mutationImpactStream,
|
|
203
|
+
env_vars_1.CLI_ENV.testMoveToFileFailEntity,
|
|
204
|
+
env_vars_1.CLI_ENV.testPostMutationCyclesDelayMs,
|
|
205
|
+
env_vars_1.CLI_ENV.testRefactorBatchDelayMs,
|
|
206
|
+
env_vars_1.CLI_ENV.testRenameDelayMs,
|
|
207
|
+
env_vars_1.CLI_ENV.testFileMoveToDirDelayMs,
|
|
208
|
+
env_vars_1.CLI_ENV.testFileMoveToDirRowDelayMs,
|
|
209
|
+
env_vars_1.CLI_ENV.testFileMoveToDirImportsDelayMs,
|
|
210
|
+
env_vars_1.CLI_ENV.testFileMoveToDirFailImports,
|
|
211
|
+
env_vars_1.CLI_ENV.testFileRenameDelayMs,
|
|
212
|
+
env_vars_1.CLI_ENV.testFileRenameRowDelayMs,
|
|
213
|
+
env_vars_1.CLI_ENV.testFileRenameImportsDelayMs,
|
|
214
|
+
env_vars_1.CLI_ENV.testFileRenameFailImports,
|
|
215
|
+
env_vars_1.CLI_ENV.testFileRefactorBatchDelayMs,
|
|
216
|
+
env_vars_1.CLI_ENV.testFileRefactorBatchRowDelayMs,
|
|
217
|
+
env_vars_1.CLI_ENV.testFileRefactorBatchImportsDelayMs,
|
|
218
|
+
env_vars_1.CLI_ENV.testFileRefactorBatchFailImports,
|
|
219
|
+
env_vars_1.CLI_ENV.testFileRefactorBatchCrashAfterFsMove,
|
|
220
|
+
env_vars_1.CLI_ENV.testMutateDelayMs,
|
|
221
|
+
env_vars_1.CLI_ENV.testInspectWorkerFailure,
|
|
222
|
+
env_vars_1.CLI_ENV.disableFileMutationImportPostProcess,
|
|
223
|
+
env_vars_1.CLI_ENV.disableFileMoveImportPostProcess,
|
|
224
|
+
env_vars_1.CLI_ENV.modulePlanSyncWaitMs,
|
|
225
|
+
env_vars_1.CLI_ENV.refactorBatchSyncWaitMs,
|
|
226
|
+
env_vars_1.CLI_ENV.renameSyncWaitMs,
|
|
227
|
+
env_vars_1.CLI_ENV.fileMoveToDirSyncWaitMs,
|
|
228
|
+
env_vars_1.CLI_ENV.fileRenameSyncWaitMs,
|
|
229
|
+
env_vars_1.CLI_ENV.fileRefactorBatchSyncWaitMs,
|
|
230
|
+
env_vars_1.CLI_ENV.mutateSyncWaitMs,
|
|
231
|
+
env_vars_1.CLI_ENV.modulePlanDebugTimeline,
|
|
232
|
+
env_vars_1.CLI_ENV.debugWorkspaceContext
|
|
233
|
+
]);
|
|
234
|
+
const env = {};
|
|
235
|
+
for (const [key, value] of Object.entries(rawValue)) {
|
|
236
|
+
if (allowed.has(key) && typeof value === "string") {
|
|
237
|
+
env[key] = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return env;
|
|
241
|
+
}
|
|
242
|
+
async function withLegacySessionEnv(env, fn) {
|
|
243
|
+
const entries = Object.entries(env);
|
|
244
|
+
if (entries.length === 0) {
|
|
245
|
+
return fn();
|
|
246
|
+
}
|
|
247
|
+
const previous = new Map();
|
|
248
|
+
for (const [key, value] of entries) {
|
|
249
|
+
previous.set(key, process.env[key]);
|
|
250
|
+
process.env[key] = value;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
return await fn();
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
for (const [key, value] of previous) {
|
|
257
|
+
if (value === undefined) {
|
|
258
|
+
delete process.env[key];
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
process.env[key] = value;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function withSessionRequestContext(cwd, env, fn) {
|
|
267
|
+
const legacyEnv = { ...env };
|
|
268
|
+
delete legacyEnv[env_vars_1.CLI_ENV.workspaceRoot];
|
|
269
|
+
delete legacyEnv[env_vars_1.CLI_ENV.productStorageDir];
|
|
270
|
+
return (0, request_routing_context_1.runWithRequestRoutingContext)(cwd, env, () => withLegacySessionEnv(legacyEnv, fn));
|
|
271
|
+
}
|
|
272
|
+
function writeInvokeModeHeader(response, mode) {
|
|
273
|
+
response.setHeader("x-aib-execution-mode", mode);
|
|
274
|
+
}
|
|
275
|
+
async function waitForSessionMutationDeadline(input, runPromise, deadlineMs) {
|
|
276
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, input.modulePlanExecutionId, "session.deadline.wait.start", { deadlineMs });
|
|
277
|
+
return (0, mutation_execution_cache_1.waitForMutationDeadline)(runPromise.then((result) => {
|
|
278
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, input.modulePlanExecutionId, "session.deadline.runPromise.resolved");
|
|
279
|
+
return result;
|
|
280
|
+
}), deadlineMs, () => (0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, input.modulePlanExecutionId, "session.deadline.timer.fired", { deadlineMs }));
|
|
281
|
+
}
|
|
282
|
+
function readSessionMutationSyncWaitMs(input) {
|
|
283
|
+
if (!isSessionModulePlanMutation(input)) {
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
return (0, mutation_execution_cache_1.readMutationSyncWaitMs)(process.env[env_vars_1.CLI_ENV.modulePlanSyncWaitMs], 120_000);
|
|
287
|
+
}
|
|
288
|
+
async function buildModulePlanInProgressOutput(input, elapsedMs) {
|
|
289
|
+
const executionId = input.modulePlanExecutionId ?? "last";
|
|
290
|
+
await (0, event_loop_1.yieldToEventLoop)();
|
|
291
|
+
let output;
|
|
292
|
+
try {
|
|
293
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, executionId, "session.inProgress.status.read.start", { elapsedMs });
|
|
294
|
+
output = (0, execution_command_1.runExecutionCommand)(input.cwd, ["status", executionId]);
|
|
295
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, executionId, "session.inProgress.status.read.end", {
|
|
296
|
+
status: typeof output.status === "string" ? output.status : null,
|
|
297
|
+
phase: typeof output.phase === "string" ? output.phase : null,
|
|
298
|
+
summary: typeof output.summary === "string" ? output.summary : null
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(input.cwd, executionId, "session.inProgress.status.read.failed", { elapsedMs });
|
|
303
|
+
output = {
|
|
304
|
+
operation: "execution.status",
|
|
305
|
+
executionId,
|
|
306
|
+
status: "running",
|
|
307
|
+
summary: "in progress"
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const estimate = estimateModulePlanTimeoutForStream(input);
|
|
311
|
+
const estimatedRemainingMs = estimate
|
|
312
|
+
? estimate.estimatedDurationMs - elapsedMs
|
|
313
|
+
: null;
|
|
314
|
+
const eta = estimatedRemainingMs !== null
|
|
315
|
+
? (0, mutation_eta_1.buildMutationEtaHint)(executionId, estimatedRemainingMs)
|
|
316
|
+
: null;
|
|
317
|
+
const text = formatModulePlanInProgressText(output, input, eta);
|
|
318
|
+
return (0, agent_text_1.attachAgentText)({
|
|
319
|
+
...output,
|
|
320
|
+
operation: output.operation ?? "execution.status",
|
|
321
|
+
executionId,
|
|
322
|
+
status: output.status ?? "running",
|
|
323
|
+
...(eta ? {
|
|
324
|
+
estimatedRemainingMs: eta.estimatedRemainingMs,
|
|
325
|
+
suggestedFirstCheckMs: eta.suggestedFirstCheckMs,
|
|
326
|
+
next: eta.next
|
|
327
|
+
} : {})
|
|
328
|
+
}, text);
|
|
329
|
+
}
|
|
330
|
+
function formatModulePlanInProgressText(output, input, eta) {
|
|
331
|
+
const executionId = typeof output.executionId === "string"
|
|
332
|
+
? output.executionId
|
|
333
|
+
: input.modulePlanExecutionId ?? "last";
|
|
334
|
+
const action = input.restArgs[0] ?? "execute";
|
|
335
|
+
const operation = input.command === "mutate" ? "mutate" : "modulePlan";
|
|
336
|
+
const lines = [
|
|
337
|
+
`${operation}.${action} ${executionId}`
|
|
338
|
+
];
|
|
339
|
+
if (typeof output.summary === "string" && output.summary.length > 0) {
|
|
340
|
+
lines.push(output.summary);
|
|
341
|
+
}
|
|
342
|
+
if (output.phase === "preview") {
|
|
343
|
+
lines.push("previewing plan");
|
|
344
|
+
}
|
|
345
|
+
if (output.phase === "mutation") {
|
|
346
|
+
lines.push("applying mutation");
|
|
347
|
+
}
|
|
348
|
+
if (output.phase === "postMutation.cycles") {
|
|
349
|
+
lines.push("mutation completed");
|
|
350
|
+
lines.push("checking cycles");
|
|
351
|
+
}
|
|
352
|
+
if (eta) {
|
|
353
|
+
lines.push(...(0, mutation_eta_1.formatMutationEtaLines)(eta));
|
|
354
|
+
}
|
|
355
|
+
return lines.join("\n");
|
|
356
|
+
}
|
|
357
|
+
class CliSessionServer {
|
|
358
|
+
server;
|
|
359
|
+
daemonId = `${process.pid}-${Date.now().toString(36)}`;
|
|
360
|
+
daemonStartedAt = new Date().toISOString();
|
|
361
|
+
daemonPackage = (0, daemon_state_1.currentCliDaemonPackage)();
|
|
362
|
+
runningExecutions = new Map();
|
|
363
|
+
semanticContextPools = new workspace_semantic_context_pools_1.WorkspaceSemanticContextPools();
|
|
364
|
+
semanticWorker;
|
|
365
|
+
lexicalWorker;
|
|
366
|
+
externalTools = new external_tool_coordinator_1.ExternalToolCoordinator({ timeoutMs: readExternalToolTimeoutMs() });
|
|
367
|
+
runtimeLifecycle;
|
|
368
|
+
drainTimeoutMs = (0, runtime_lifecycle_1.readSessionDrainTimeoutMs)();
|
|
369
|
+
activeInvokeCount = 0;
|
|
370
|
+
heartbeatTimer = null;
|
|
371
|
+
shutdownPromise = null;
|
|
372
|
+
laneLease = null;
|
|
373
|
+
stoppedPromise;
|
|
374
|
+
resolveStopped;
|
|
375
|
+
constructor() {
|
|
376
|
+
this.stoppedPromise = new Promise((resolve) => { this.resolveStopped = resolve; });
|
|
377
|
+
const semanticWorkerMode = (0, semantic_worker_manager_1.readSemanticWorkerSessionMode)();
|
|
378
|
+
this.semanticWorker = semanticWorkerMode === "off"
|
|
379
|
+
? null
|
|
380
|
+
: new semantic_worker_manager_1.SemanticWorkerManager({ executionMode: semanticWorkerMode, deadlineMs: (0, semantic_worker_manager_1.readSemanticWorkerDeadlineMs)() });
|
|
381
|
+
const lexicalWorkerMode = (0, lexical_worker_manager_1.readLexicalWorkerSessionMode)();
|
|
382
|
+
this.lexicalWorker = lexicalWorkerMode === "off"
|
|
383
|
+
? null
|
|
384
|
+
: new lexical_worker_manager_1.LexicalWorkerManager({ mode: lexicalWorkerMode, deadlineMs: (0, lexical_worker_manager_1.readLexicalWorkerDeadlineMs)() });
|
|
385
|
+
this.runtimeLifecycle = new runtime_lifecycle_1.SessionRuntimeLifecycle({
|
|
386
|
+
idleTtlMs: (0, runtime_lifecycle_1.readSessionIdleTtlMs)(),
|
|
387
|
+
onIdle: () => this.shutdown("idle-ttl"),
|
|
388
|
+
externalRetainers: () => this.ownedResourceRetainers()
|
|
389
|
+
});
|
|
390
|
+
this.server = http.createServer((request, response) => {
|
|
391
|
+
if (request.method === "GET" && request.url === "/health") {
|
|
392
|
+
void this.handleRequest(request, response);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
let finishRequest = null;
|
|
396
|
+
try {
|
|
397
|
+
finishRequest = this.runtimeLifecycle.beginRequest();
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
writeJson(response, 503, (0, errors_1.errorPayload)(error));
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
void (0, runtime_lifecycle_1.runWithSessionRuntimeLifecycle)(this.runtimeLifecycle, () => this.handleRequest(request, response))
|
|
404
|
+
.finally(() => finishRequest?.());
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
async handleRequest(request, response) {
|
|
408
|
+
if (request.method === "GET" && request.url === "/health") {
|
|
409
|
+
writeJson(response, 200, (0, session_health_1.buildSessionHealthPayload)(process.pid, this.runtimeLifecycle.state));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (request.method === "POST" && request.url === "/shutdown") {
|
|
413
|
+
writeJson(response, 202, {
|
|
414
|
+
ok: true,
|
|
415
|
+
accepted: true,
|
|
416
|
+
pid: process.pid
|
|
417
|
+
});
|
|
418
|
+
setImmediate(() => { void this.shutdown("session-stop"); });
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (request.method === "POST" && request.url === "/run") {
|
|
422
|
+
try {
|
|
423
|
+
const rawBody = await collectRequestBody(request);
|
|
424
|
+
const parsed = rawBody ? JSON.parse(rawBody) : {};
|
|
425
|
+
if (typeof parsed.command !== "string" ||
|
|
426
|
+
!Array.isArray(parsed.restArgs) ||
|
|
427
|
+
typeof parsed.cwd !== "string") {
|
|
428
|
+
throw new errors_1.CliError("INVALID_SESSION_REQUEST", "Invalid session request payload.");
|
|
429
|
+
}
|
|
430
|
+
const stdinInputSource = parseSessionInputSource(parsed.stdinInputSource);
|
|
431
|
+
const runCommandInput = {
|
|
432
|
+
command: parsed.command,
|
|
433
|
+
restArgs: parsed.restArgs.filter((item) => typeof item === "string"),
|
|
434
|
+
cwd: parsed.cwd,
|
|
435
|
+
stdinPayload: parsed.stdinPayload,
|
|
436
|
+
metricsEnabled: parsed.metricsEnabled === true
|
|
437
|
+
};
|
|
438
|
+
runCommandInput.lifecycle = this.lifecycleServices();
|
|
439
|
+
if (stdinInputSource !== undefined) {
|
|
440
|
+
runCommandInput.stdinInputSource = stdinInputSource;
|
|
441
|
+
}
|
|
442
|
+
const sessionEnv = parseSessionEnv(parsed.env);
|
|
443
|
+
const spans = runCommandInput.metricsEnabled ? [] : undefined;
|
|
444
|
+
if (spans) {
|
|
445
|
+
runCommandInput.metricsSpans = spans;
|
|
446
|
+
}
|
|
447
|
+
if (typeof parsed.sessionId === "string") {
|
|
448
|
+
runCommandInput.sessionId = parsed.sessionId;
|
|
449
|
+
}
|
|
450
|
+
if (typeof parsed.modulePlanExecutionId === "string") {
|
|
451
|
+
runCommandInput.modulePlanExecutionId = parsed.modulePlanExecutionId;
|
|
452
|
+
}
|
|
453
|
+
if (parsed.suppressModulePlanStreamStart === true) {
|
|
454
|
+
runCommandInput.suppressModulePlanStreamStart = true;
|
|
455
|
+
}
|
|
456
|
+
if (parsed.debugWorkspaceContext === true) {
|
|
457
|
+
runCommandInput.debugWorkspaceContext = true;
|
|
458
|
+
}
|
|
459
|
+
ensureSessionModulePlanExecutionId(runCommandInput);
|
|
460
|
+
const runStartedAt = (0, metrics_1.metricsNow)();
|
|
461
|
+
const finishInvocation = this.beginInvocation(runCommandInput);
|
|
462
|
+
const runPromise = withSessionRequestContext(runCommandInput.cwd, sessionEnv, () => (0, run_command_1.runCommand)(runCommandInput)).then((result) => {
|
|
463
|
+
(0, metrics_1.recordSpan)(spans, "session.runCommand", runStartedAt);
|
|
464
|
+
return result;
|
|
465
|
+
}, (error) => {
|
|
466
|
+
(0, metrics_1.recordSpan)(spans, "session.runCommand", runStartedAt);
|
|
467
|
+
throw error;
|
|
468
|
+
}).finally(finishInvocation);
|
|
469
|
+
const deadlineMs = readSessionMutationSyncWaitMs(runCommandInput);
|
|
470
|
+
if (deadlineMs > 0) {
|
|
471
|
+
const deadlineResult = await waitForSessionMutationDeadline(runCommandInput, runPromise, deadlineMs);
|
|
472
|
+
if (deadlineResult.status === "deadline") {
|
|
473
|
+
runPromise.catch(() => undefined);
|
|
474
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.deadline.output.start", { deadlineMs });
|
|
475
|
+
const output = await buildModulePlanInProgressOutput(runCommandInput, deadlineMs);
|
|
476
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.start", { mode: "deadline" });
|
|
477
|
+
writeJson(response, 200, output);
|
|
478
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.end", { mode: "deadline" });
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const result = deadlineResult.result;
|
|
482
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.start", { mode: "result" });
|
|
483
|
+
writeJson(response, 200, spans ? (0, metrics_1.appendMetrics)(result, spans) : result);
|
|
484
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.end", { mode: "result" });
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const result = await runPromise;
|
|
488
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.start", { mode: "no-deadline" });
|
|
489
|
+
writeJson(response, 200, spans ? (0, metrics_1.appendMetrics)(result, spans) : result);
|
|
490
|
+
(0, module_plan_timeline_1.recordModulePlanTimeline)(runCommandInput.cwd, runCommandInput.modulePlanExecutionId, "session.run.response.write.end", { mode: "no-deadline" });
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
writeJson(response, 500, (0, errors_1.errorPayload)(error));
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (request.method === "POST" && request.url === "/invoke") {
|
|
499
|
+
let progressTimer = null;
|
|
500
|
+
let trace = null;
|
|
501
|
+
let traceStartedAtMs = 0;
|
|
502
|
+
let invokeRequest = null;
|
|
503
|
+
try {
|
|
504
|
+
const rawBody = await collectRequestBody(request);
|
|
505
|
+
const rawParams = new URLSearchParams(rawBody);
|
|
506
|
+
const requestCwd = rawParams.get("cwd") ?? "";
|
|
507
|
+
invokeRequest = await (0, workspace_root_1.runWithWorkspaceRequestContext)(requestCwd, undefined, () => parseInvokeFormRequest(rawBody));
|
|
508
|
+
invokeRequest.input.lifecycle = this.lifecycleServices();
|
|
509
|
+
const mode = classifyInvokeMode(invokeRequest.input);
|
|
510
|
+
writeInvokeModeHeader(response, mode);
|
|
511
|
+
if (mode === "process") {
|
|
512
|
+
const finishInvocation = this.beginInvocation(invokeRequest.input);
|
|
513
|
+
const requestAbort = new AbortController();
|
|
514
|
+
const onResponseClose = () => {
|
|
515
|
+
if (!response.writableEnded)
|
|
516
|
+
requestAbort.abort("client-disconnected");
|
|
517
|
+
};
|
|
518
|
+
response.once("close", onResponseClose);
|
|
519
|
+
try {
|
|
520
|
+
const execRequest = buildExecRequestFromInvoke(invokeRequest);
|
|
521
|
+
(0, external_tool_request_1.assertExternalToolRequestContext)(execRequest);
|
|
522
|
+
const output = await this.externalTools.execute((signal) => (0, external_tool_request_1.runExternalToolRequest)(execRequest, signal), requestAbort.signal);
|
|
523
|
+
writeJson(response, 200, output);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
finally {
|
|
527
|
+
response.removeListener("close", onResponseClose);
|
|
528
|
+
finishInvocation();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (mode === "stream") {
|
|
532
|
+
writeCliStreamHeaders(response);
|
|
533
|
+
traceStartedAtMs = Date.now();
|
|
534
|
+
trace = startCliFormTrace(invokeRequest, traceStartedAtMs);
|
|
535
|
+
progressTimer = startCliProgressStream(response, invokeRequest.input);
|
|
536
|
+
const requestEnv = invokeRequest.env;
|
|
537
|
+
const runStartedAt = (0, metrics_1.metricsNow)();
|
|
538
|
+
const finishInvocation = this.beginInvocation(invokeRequest.input);
|
|
539
|
+
const runPromise = withSessionRequestContext(invokeRequest.input.cwd, requestEnv, () => (0, run_command_1.runCommand)(invokeRequest.input)).then((result) => {
|
|
540
|
+
(0, metrics_1.recordSpan)(invokeRequest.spans, "session.runCommand", runStartedAt);
|
|
541
|
+
return result;
|
|
542
|
+
}, (error) => {
|
|
543
|
+
(0, metrics_1.recordSpan)(invokeRequest.spans, "session.runCommand", runStartedAt);
|
|
544
|
+
throw error;
|
|
545
|
+
}).finally(finishInvocation);
|
|
546
|
+
const result = await runPromise;
|
|
547
|
+
const output = prepareCliPresentationPayload(invokeRequest.spans ? (0, metrics_1.appendMetrics)(result, invokeRequest.spans) : result);
|
|
548
|
+
completeCliFormTrace(trace, invokeRequest, output, 0, traceStartedAtMs);
|
|
549
|
+
writeStreamEvent(response, {
|
|
550
|
+
type: "result",
|
|
551
|
+
payload: output
|
|
552
|
+
});
|
|
553
|
+
response.end();
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
traceStartedAtMs = Date.now();
|
|
557
|
+
trace = startCliFormTrace(invokeRequest, traceStartedAtMs);
|
|
558
|
+
const requestEnv = invokeRequest.env;
|
|
559
|
+
const runStartedAt = (0, metrics_1.metricsNow)();
|
|
560
|
+
const finishInvocation = this.beginInvocation(invokeRequest.input);
|
|
561
|
+
const runPromise = withSessionRequestContext(invokeRequest.input.cwd, requestEnv, () => (0, run_command_1.runCommand)(invokeRequest.input)).then((result) => {
|
|
562
|
+
(0, metrics_1.recordSpan)(invokeRequest.spans, "session.runCommand", runStartedAt);
|
|
563
|
+
return result;
|
|
564
|
+
}, (error) => {
|
|
565
|
+
(0, metrics_1.recordSpan)(invokeRequest.spans, "session.runCommand", runStartedAt);
|
|
566
|
+
throw error;
|
|
567
|
+
}).finally(finishInvocation);
|
|
568
|
+
const deadlineMs = readSessionMutationSyncWaitMs(invokeRequest.input);
|
|
569
|
+
if (deadlineMs > 0) {
|
|
570
|
+
const deadlineResult = await waitForSessionMutationDeadline(invokeRequest.input, runPromise, deadlineMs);
|
|
571
|
+
if (deadlineResult.status === "deadline") {
|
|
572
|
+
runPromise.catch(() => undefined);
|
|
573
|
+
const output = prepareCliPresentationPayload(await buildModulePlanInProgressOutput(invokeRequest.input, deadlineMs));
|
|
574
|
+
completeCliFormTrace(trace, invokeRequest, output, 0, traceStartedAtMs);
|
|
575
|
+
writeJson(response, 200, output);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const result = deadlineResult.result;
|
|
579
|
+
const output = prepareCliPresentationPayload(invokeRequest.spans ? (0, metrics_1.appendMetrics)(result, invokeRequest.spans) : result);
|
|
580
|
+
completeCliFormTrace(trace, invokeRequest, output, 0, traceStartedAtMs);
|
|
581
|
+
writeJson(response, 200, output);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const result = await runPromise;
|
|
585
|
+
const output = prepareCliPresentationPayload(invokeRequest.spans ? (0, metrics_1.appendMetrics)(result, invokeRequest.spans) : result);
|
|
586
|
+
completeCliFormTrace(trace, invokeRequest, output, 0, traceStartedAtMs);
|
|
587
|
+
writeJson(response, 200, output);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
if (response.destroyed)
|
|
592
|
+
return;
|
|
593
|
+
const output = prepareCliPresentationPayload((0, errors_1.errorPayload)(error));
|
|
594
|
+
if (!response.headersSent) {
|
|
595
|
+
writeInvokeModeHeader(response, "structured");
|
|
596
|
+
writeJson(response, 500, output);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (response.getHeader("x-aib-execution-mode") === "stream") {
|
|
600
|
+
completeCliFormTrace(trace, invokeRequest, output, 1, traceStartedAtMs);
|
|
601
|
+
writeStreamEvent(response, {
|
|
602
|
+
type: "error",
|
|
603
|
+
payload: output
|
|
604
|
+
});
|
|
605
|
+
response.end();
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
completeCliFormTrace(trace, invokeRequest, output, 1, traceStartedAtMs);
|
|
609
|
+
writeJson(response, 500, output);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
finally {
|
|
613
|
+
if (progressTimer) {
|
|
614
|
+
clearInterval(progressTimer);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
writeJson(response, 404, {
|
|
619
|
+
ok: false,
|
|
620
|
+
error: "Not found"
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
async serve() {
|
|
624
|
+
const laneLease = (0, lane_owner_1.acquireSessionLaneLease)(this.daemonPackage.cliPath);
|
|
625
|
+
this.laneLease = laneLease;
|
|
626
|
+
try {
|
|
627
|
+
await new Promise((resolve, reject) => {
|
|
628
|
+
this.server.once("error", reject);
|
|
629
|
+
this.server.listen(0, "127.0.0.1", () => resolve());
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
laneLease.release();
|
|
634
|
+
throw error;
|
|
635
|
+
}
|
|
636
|
+
const address = this.server.address();
|
|
637
|
+
if (!address || typeof address === "string") {
|
|
638
|
+
laneLease.release();
|
|
639
|
+
this.laneLease = null;
|
|
640
|
+
throw new Error("Failed to determine aib session address.");
|
|
641
|
+
}
|
|
642
|
+
writeSessionInfo({
|
|
643
|
+
pid: process.pid,
|
|
644
|
+
host: "127.0.0.1",
|
|
645
|
+
port: address.port,
|
|
646
|
+
url: `http://127.0.0.1:${address.port}`,
|
|
647
|
+
startedAt: this.daemonStartedAt
|
|
648
|
+
});
|
|
649
|
+
this.writeDaemonState("running");
|
|
650
|
+
this.heartbeatTimer = setInterval(() => this.writeDaemonState("running"), 10_000);
|
|
651
|
+
this.heartbeatTimer.unref();
|
|
652
|
+
this.runtimeLifecycle.start();
|
|
653
|
+
const onSigterm = () => { void this.shutdown("SIGTERM"); };
|
|
654
|
+
const onSigint = () => { void this.shutdown("SIGINT"); };
|
|
655
|
+
process.once("SIGTERM", onSigterm);
|
|
656
|
+
process.once("SIGINT", onSigint);
|
|
657
|
+
await this.stoppedPromise;
|
|
658
|
+
process.removeListener("SIGTERM", onSigterm);
|
|
659
|
+
process.removeListener("SIGINT", onSigint);
|
|
660
|
+
}
|
|
661
|
+
beginInvocation(input) {
|
|
662
|
+
this.activeInvokeCount += 1;
|
|
663
|
+
const executionId = typeof input.modulePlanExecutionId === "string" ? input.modulePlanExecutionId : null;
|
|
664
|
+
if (executionId) {
|
|
665
|
+
this.runningExecutions.set(executionId, {
|
|
666
|
+
executionId,
|
|
667
|
+
command: `${input.command} ${input.restArgs.join(" ")}`.trim(),
|
|
668
|
+
startedAt: new Date().toISOString()
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
this.writeDaemonState("running");
|
|
672
|
+
let finished = false;
|
|
673
|
+
return () => {
|
|
674
|
+
if (finished) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
finished = true;
|
|
678
|
+
this.activeInvokeCount = Math.max(0, this.activeInvokeCount - 1);
|
|
679
|
+
if (executionId) {
|
|
680
|
+
this.runningExecutions.delete(executionId);
|
|
681
|
+
}
|
|
682
|
+
this.writeDaemonState("running");
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
lifecycleServices() {
|
|
686
|
+
return {
|
|
687
|
+
semanticContexts: {
|
|
688
|
+
forWorkspace: (workspaceRoot) => this.semanticContextPools.forWorkspace(workspaceRoot),
|
|
689
|
+
invalidateWorkspace: (workspaceRoot, change) => {
|
|
690
|
+
this.semanticContextPools.invalidateWorkspace(workspaceRoot, change);
|
|
691
|
+
this.semanticWorker?.invalidateWorkspace(workspaceRoot, change);
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
...(this.semanticWorker ? { semanticBoundaries: this.semanticWorker } : {}),
|
|
695
|
+
...(this.lexicalWorker ? { lexicalGraph: this.lexicalWorker } : {})
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
writeDaemonState(status) {
|
|
699
|
+
if (status === "running" && this.runtimeLifecycle.state.phase === "stopped")
|
|
700
|
+
return;
|
|
701
|
+
const runtime = this.runtimeLifecycle.state;
|
|
702
|
+
(0, daemon_state_1.tryWriteCliDaemonIdentity)((0, product_storage_1.productStorageRoot)(), {
|
|
703
|
+
schemaVersion: 1,
|
|
704
|
+
daemonId: this.daemonId,
|
|
705
|
+
pid: process.pid,
|
|
706
|
+
status,
|
|
707
|
+
startedAt: this.daemonStartedAt,
|
|
708
|
+
updatedAt: new Date().toISOString(),
|
|
709
|
+
heartbeatAt: new Date().toISOString(),
|
|
710
|
+
invokeProtocol: "http-session-v1",
|
|
711
|
+
supportedModes: ["structured", "process", "stream"],
|
|
712
|
+
activeInvokeCount: this.activeInvokeCount,
|
|
713
|
+
runningExecutions: Array.from(this.runningExecutions.values()),
|
|
714
|
+
lastActivityAt: runtime.lastActivityAt,
|
|
715
|
+
idleDeadlineAt: runtime.idleDeadlineAt,
|
|
716
|
+
idleTtlMs: runtime.idleTtlMs,
|
|
717
|
+
acceptingRequests: runtime.acceptingRequests,
|
|
718
|
+
idleRetainers: runtime.retainers,
|
|
719
|
+
shutdownReason: runtime.shutdownReason,
|
|
720
|
+
cliPath: this.daemonPackage.cliPath,
|
|
721
|
+
packageRoot: this.daemonPackage.packageRoot
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
ownedResourceRetainers() {
|
|
725
|
+
const retainers = [];
|
|
726
|
+
const external = this.externalTools.state;
|
|
727
|
+
if (external.active > 0)
|
|
728
|
+
retainers.push(`external-tools-active:${external.active}`);
|
|
729
|
+
if (external.queued > 0)
|
|
730
|
+
retainers.push(`external-tools-queued:${external.queued}`);
|
|
731
|
+
const semantic = this.semanticWorker?.state;
|
|
732
|
+
if (semantic?.active)
|
|
733
|
+
retainers.push("semantic-worker-active:1");
|
|
734
|
+
if ((semantic?.queued ?? 0) > 0)
|
|
735
|
+
retainers.push(`semantic-worker-queued:${semantic.queued}`);
|
|
736
|
+
const lexical = this.lexicalWorker?.state;
|
|
737
|
+
if (lexical?.active)
|
|
738
|
+
retainers.push("lexical-worker-active:1");
|
|
739
|
+
if ((lexical?.queued ?? 0) > 0)
|
|
740
|
+
retainers.push(`lexical-worker-queued:${lexical.queued}`);
|
|
741
|
+
const semanticLeases = this.semanticContextPools.state.workspaces.reduce((total, workspace) => total + workspace.pool.activeLeases, 0);
|
|
742
|
+
if (semanticLeases > 0)
|
|
743
|
+
retainers.push(`semantic-context-leases:${semanticLeases}`);
|
|
744
|
+
return retainers;
|
|
745
|
+
}
|
|
746
|
+
shutdown(reason) {
|
|
747
|
+
if (this.shutdownPromise)
|
|
748
|
+
return this.shutdownPromise;
|
|
749
|
+
this.runtimeLifecycle.beginShutdown(reason);
|
|
750
|
+
this.writeDaemonState("running");
|
|
751
|
+
const shutdownPromise = (0, runtime_shutdown_1.shutdownSessionRuntime)({
|
|
752
|
+
lifecycle: this.runtimeLifecycle,
|
|
753
|
+
drainTimeoutMs: this.drainTimeoutMs,
|
|
754
|
+
server: this.server,
|
|
755
|
+
shutdownResources: async () => {
|
|
756
|
+
await Promise.allSettled([
|
|
757
|
+
this.semanticWorker?.shutdown() ?? Promise.resolve(),
|
|
758
|
+
this.lexicalWorker?.shutdown() ?? Promise.resolve(),
|
|
759
|
+
this.externalTools.shutdown()
|
|
760
|
+
]);
|
|
761
|
+
this.semanticContextPools.dispose();
|
|
762
|
+
},
|
|
763
|
+
finalize: () => this.finalizeShutdown(false),
|
|
764
|
+
hardExit: () => this.finalizeShutdown(true)
|
|
765
|
+
}).then(() => undefined);
|
|
766
|
+
this.shutdownPromise = shutdownPromise;
|
|
767
|
+
return shutdownPromise;
|
|
768
|
+
}
|
|
769
|
+
finalizeShutdown(exitProcess) {
|
|
770
|
+
(0, runtime_shutdown_1.finalizeSessionRuntimeBestEffort)([
|
|
771
|
+
() => {
|
|
772
|
+
if (!this.heartbeatTimer)
|
|
773
|
+
return;
|
|
774
|
+
clearInterval(this.heartbeatTimer);
|
|
775
|
+
this.heartbeatTimer = null;
|
|
776
|
+
},
|
|
777
|
+
() => {
|
|
778
|
+
this.runtimeLifecycle.markStopped();
|
|
779
|
+
this.writeDaemonState("stopped");
|
|
780
|
+
},
|
|
781
|
+
() => removeSessionInfo(),
|
|
782
|
+
() => this.laneLease?.release()
|
|
783
|
+
], () => {
|
|
784
|
+
this.laneLease = null;
|
|
785
|
+
this.resolveStopped();
|
|
786
|
+
if (exitProcess)
|
|
787
|
+
process.exit(0);
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
exports.CliSessionServer = CliSessionServer;
|
|
792
|
+
function readExternalToolTimeoutMs() {
|
|
793
|
+
const raw = process.env[env_vars_1.CLI_ENV.externalToolTimeoutMs];
|
|
794
|
+
const parsed = raw ? Number.parseInt(raw, 10) : Number.NaN;
|
|
795
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 30 * 60_000;
|
|
796
|
+
}
|
|
797
|
+
function canRunViaCliStream(input) {
|
|
798
|
+
return input.command === "diagnostics" && input.restArgs[0] === "timeout-stream";
|
|
799
|
+
}
|
|
800
|
+
function writeCliStreamHeaders(response) {
|
|
801
|
+
response.writeHead(200, {
|
|
802
|
+
"content-type": "application/x-ndjson; charset=utf-8",
|
|
803
|
+
"cache-control": "no-cache",
|
|
804
|
+
"x-accel-buffering": "no"
|
|
805
|
+
});
|
|
806
|
+
response.flushHeaders();
|
|
807
|
+
}
|
|
808
|
+
async function parseInvokeFormRequest(rawBody) {
|
|
809
|
+
const params = new URLSearchParams(rawBody);
|
|
810
|
+
return {
|
|
811
|
+
...await parseCliFormParams(params, { invokeGate: true }),
|
|
812
|
+
params
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
async function parseCliFormParams(params, options = {}) {
|
|
816
|
+
const rawCommand = params.get("command") ?? params.get("method") ?? "";
|
|
817
|
+
const cwd = params.get("cwd") ?? "";
|
|
818
|
+
const sessionId = params.get("sessionId") ?? undefined;
|
|
819
|
+
const modulePlanExecutionId = params.get("modulePlanExecutionId") ?? undefined;
|
|
820
|
+
const suppressModulePlanStreamStart = params.get("suppressModulePlanStreamStart") === "true";
|
|
821
|
+
const metricsEnabled = params.get("metricsEnabled") === "true";
|
|
822
|
+
const traceDir = nonEmptyString(params.get("traceDir"));
|
|
823
|
+
const env = parseCliFormEnv(params);
|
|
824
|
+
if (!rawCommand.trim()) {
|
|
825
|
+
throw new errors_1.CliError("MISSING_COMMAND", "Missing command.");
|
|
826
|
+
}
|
|
827
|
+
if (!cwd.trim()) {
|
|
828
|
+
throw new errors_1.CliError("MISSING_CWD", "Missing cwd.");
|
|
829
|
+
}
|
|
830
|
+
const spans = metricsEnabled ? [] : undefined;
|
|
831
|
+
const aliasStartedAt = (0, metrics_1.metricsNow)();
|
|
832
|
+
const command = await (0, resolve_command_alias_1.resolveCanonicalCommandAlias)(rawCommand.trim(), cwd);
|
|
833
|
+
(0, metrics_1.recordSpan)(spans, "session.aliasResolution", aliasStartedAt);
|
|
834
|
+
const stdinFormat = (0, read_stdin_json_1.stripStdinFormatFlags)(params.getAll("arg"));
|
|
835
|
+
const restArgs = stdinFormat.restArgs;
|
|
836
|
+
const preliminaryInput = {
|
|
837
|
+
command,
|
|
838
|
+
restArgs,
|
|
839
|
+
cwd,
|
|
840
|
+
metricsEnabled
|
|
841
|
+
};
|
|
842
|
+
if (sessionId) {
|
|
843
|
+
preliminaryInput.sessionId = sessionId;
|
|
844
|
+
}
|
|
845
|
+
if (modulePlanExecutionId) {
|
|
846
|
+
preliminaryInput.modulePlanExecutionId = modulePlanExecutionId;
|
|
847
|
+
}
|
|
848
|
+
if (suppressModulePlanStreamStart) {
|
|
849
|
+
preliminaryInput.suppressModulePlanStreamStart = true;
|
|
850
|
+
}
|
|
851
|
+
if (spans) {
|
|
852
|
+
preliminaryInput.metricsSpans = spans;
|
|
853
|
+
}
|
|
854
|
+
if ((options.streamGate === true && !canRunViaCliStream(preliminaryInput)) ||
|
|
855
|
+
(options.invokeGate === true && classifyInvokeMode(preliminaryInput) === "process")) {
|
|
856
|
+
return {
|
|
857
|
+
input: preliminaryInput,
|
|
858
|
+
spans,
|
|
859
|
+
...(traceDir !== undefined ? { traceDir } : {}),
|
|
860
|
+
env
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
const stdinInputSource = parseCliStdinInputSource(params.get("stdin"), command, restArgs, stdinFormat.format);
|
|
864
|
+
const input = {
|
|
865
|
+
command,
|
|
866
|
+
restArgs,
|
|
867
|
+
cwd,
|
|
868
|
+
stdinPayload: parseCliStdinPayload(params.get("stdin"), command, restArgs, stdinFormat.format),
|
|
869
|
+
metricsEnabled
|
|
870
|
+
};
|
|
871
|
+
if (stdinInputSource !== undefined) {
|
|
872
|
+
input.stdinInputSource = stdinInputSource;
|
|
873
|
+
}
|
|
874
|
+
if (sessionId) {
|
|
875
|
+
input.sessionId = sessionId;
|
|
876
|
+
}
|
|
877
|
+
if (modulePlanExecutionId) {
|
|
878
|
+
input.modulePlanExecutionId = modulePlanExecutionId;
|
|
879
|
+
}
|
|
880
|
+
if (suppressModulePlanStreamStart) {
|
|
881
|
+
input.suppressModulePlanStreamStart = true;
|
|
882
|
+
}
|
|
883
|
+
if (spans) {
|
|
884
|
+
input.metricsSpans = spans;
|
|
885
|
+
}
|
|
886
|
+
return {
|
|
887
|
+
input,
|
|
888
|
+
spans,
|
|
889
|
+
...(traceDir !== undefined ? { traceDir } : {}),
|
|
890
|
+
env
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
function classifyInvokeMode(input) {
|
|
894
|
+
if (input.command === "rg" && input.restArgs[0] === "--") {
|
|
895
|
+
return "process";
|
|
896
|
+
}
|
|
897
|
+
if (input.command === "tsc" && input.restArgs[0] === "--") {
|
|
898
|
+
return "process";
|
|
899
|
+
}
|
|
900
|
+
if ((0, core_1.isRtkPassthroughCommand)(input.command) && input.restArgs[0] === "--") {
|
|
901
|
+
return "process";
|
|
902
|
+
}
|
|
903
|
+
if (canRunViaCliStream(input)) {
|
|
904
|
+
return "stream";
|
|
905
|
+
}
|
|
906
|
+
return "structured";
|
|
907
|
+
}
|
|
908
|
+
function buildExecRequestFromInvoke(request) {
|
|
909
|
+
const supported = ((request.input.command === "rg" || request.input.command === "tsc" || (0, core_1.isRtkPassthroughCommand)(request.input.command)) &&
|
|
910
|
+
request.input.restArgs[0] === "--");
|
|
911
|
+
if (!supported) {
|
|
912
|
+
throw new errors_1.CliError("UNSUPPORTED_INVOKE_PROCESS_COMMAND", `Unsupported process invocation: ${request.input.command}`, {
|
|
913
|
+
supported: ["rg --", "tsc --", ...core_1.RTK_PASSTHROUGH_COMMANDS.map((command) => `${command} --`)]
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
const execRequest = {
|
|
917
|
+
command: request.input.command,
|
|
918
|
+
restArgs: request.input.restArgs.slice(1),
|
|
919
|
+
cwd: request.input.cwd,
|
|
920
|
+
env: parseExecEnv(request.params)
|
|
921
|
+
};
|
|
922
|
+
if (request.params.has("stdin")) {
|
|
923
|
+
execRequest.stdinText = request.params.get("stdin") ?? "";
|
|
924
|
+
}
|
|
925
|
+
return execRequest;
|
|
926
|
+
}
|
|
927
|
+
function parseCliFormEnv(params) {
|
|
928
|
+
const env = {};
|
|
929
|
+
const entries = [
|
|
930
|
+
[env_vars_1.CLI_ENV.metrics, params.get("metrics") ?? ""],
|
|
931
|
+
[env_vars_1.CLI_ENV.metricsDir, params.get("metricsDir") ?? ""],
|
|
932
|
+
[env_vars_1.CLI_ENV.metricsTag, params.get("metricsTag") ?? ""],
|
|
933
|
+
[env_vars_1.CLI_ENV.mutationImpactMetrics, params.get("mutationImpactMetrics") ?? ""],
|
|
934
|
+
[env_vars_1.CLI_ENV.mutationImpactStream, params.get("mutationImpactStream") ?? ""],
|
|
935
|
+
[env_vars_1.CLI_ENV.testMoveToFileFailEntity, params.get("testMoveToFileFailEntity") ?? ""],
|
|
936
|
+
[env_vars_1.CLI_ENV.testPostMutationCyclesDelayMs, params.get("testPostMutationCyclesDelayMs") ?? ""],
|
|
937
|
+
[env_vars_1.CLI_ENV.testRefactorBatchDelayMs, params.get("testRefactorBatchDelayMs") ?? ""],
|
|
938
|
+
[env_vars_1.CLI_ENV.testRenameDelayMs, params.get("testRenameDelayMs") ?? ""],
|
|
939
|
+
[env_vars_1.CLI_ENV.testFileMoveToDirDelayMs, params.get("testFileMoveToDirDelayMs") ?? ""],
|
|
940
|
+
[env_vars_1.CLI_ENV.testFileMoveToDirRowDelayMs, params.get("testFileMoveToDirRowDelayMs") ?? ""],
|
|
941
|
+
[env_vars_1.CLI_ENV.testFileMoveToDirImportsDelayMs, params.get("testFileMoveToDirImportsDelayMs") ?? ""],
|
|
942
|
+
[env_vars_1.CLI_ENV.testFileMoveToDirFailImports, params.get("testFileMoveToDirFailImports") ?? ""],
|
|
943
|
+
[env_vars_1.CLI_ENV.testFileRenameDelayMs, params.get("testFileRenameDelayMs") ?? ""],
|
|
944
|
+
[env_vars_1.CLI_ENV.testFileRenameRowDelayMs, params.get("testFileRenameRowDelayMs") ?? ""],
|
|
945
|
+
[env_vars_1.CLI_ENV.testFileRenameImportsDelayMs, params.get("testFileRenameImportsDelayMs") ?? ""],
|
|
946
|
+
[env_vars_1.CLI_ENV.testFileRenameFailImports, params.get("testFileRenameFailImports") ?? ""],
|
|
947
|
+
[env_vars_1.CLI_ENV.testFileRefactorBatchDelayMs, params.get("testFileRefactorBatchDelayMs") ?? ""],
|
|
948
|
+
[env_vars_1.CLI_ENV.testFileRefactorBatchRowDelayMs, params.get("testFileRefactorBatchRowDelayMs") ?? ""],
|
|
949
|
+
[env_vars_1.CLI_ENV.testFileRefactorBatchImportsDelayMs, params.get("testFileRefactorBatchImportsDelayMs") ?? ""],
|
|
950
|
+
[env_vars_1.CLI_ENV.testFileRefactorBatchFailImports, params.get("testFileRefactorBatchFailImports") ?? ""],
|
|
951
|
+
[env_vars_1.CLI_ENV.testFileRefactorBatchCrashAfterFsMove, params.get("testFileRefactorBatchCrashAfterFsMove") ?? ""],
|
|
952
|
+
[env_vars_1.CLI_ENV.disableFileMutationImportPostProcess, params.get("disableFileMutationImportPostProcess") ?? ""],
|
|
953
|
+
[env_vars_1.CLI_ENV.disableFileMoveImportPostProcess, params.get("disableFileMoveImportPostProcess") ?? ""],
|
|
954
|
+
[env_vars_1.CLI_ENV.modulePlanSyncWaitMs, params.get("modulePlanSyncWaitMs") ?? ""],
|
|
955
|
+
[env_vars_1.CLI_ENV.refactorBatchSyncWaitMs, params.get("refactorBatchSyncWaitMs") ?? ""],
|
|
956
|
+
[env_vars_1.CLI_ENV.renameSyncWaitMs, params.get("renameSyncWaitMs") ?? ""],
|
|
957
|
+
[env_vars_1.CLI_ENV.fileMoveToDirSyncWaitMs, params.get("fileMoveToDirSyncWaitMs") ?? ""],
|
|
958
|
+
[env_vars_1.CLI_ENV.fileRenameSyncWaitMs, params.get("fileRenameSyncWaitMs") ?? ""],
|
|
959
|
+
[env_vars_1.CLI_ENV.fileRefactorBatchSyncWaitMs, params.get("fileRefactorBatchSyncWaitMs") ?? ""],
|
|
960
|
+
[env_vars_1.CLI_ENV.modulePlanDebugTimeline, params.get("modulePlanDebugTimeline") ?? ""],
|
|
961
|
+
[env_vars_1.CLI_ENV.trace, params.get("trace") ?? ""],
|
|
962
|
+
[env_vars_1.CLI_ENV.failureSnapshots, params.get("failureSnapshots") ?? ""],
|
|
963
|
+
[env_vars_1.CLI_ENV.productStorageDir, params.get("productStorageDir") ?? ""],
|
|
964
|
+
[env_vars_1.CLI_ENV.helpShell, params.get(`env.${env_vars_1.CLI_ENV.helpShell}`) ?? ""]
|
|
965
|
+
];
|
|
966
|
+
for (const [key, value] of entries) {
|
|
967
|
+
const trimmed = value.trim();
|
|
968
|
+
if (trimmed) {
|
|
969
|
+
env[key] = trimmed;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return env;
|
|
973
|
+
}
|
|
974
|
+
function nonEmptyString(value) {
|
|
975
|
+
if (value === null) {
|
|
976
|
+
return undefined;
|
|
977
|
+
}
|
|
978
|
+
const trimmed = value.trim();
|
|
979
|
+
return trimmed ? trimmed : undefined;
|
|
980
|
+
}
|
|
981
|
+
function startCliFormTrace(cliRequest, startedAtMs) {
|
|
982
|
+
if (!cliRequest.traceDir) {
|
|
983
|
+
return null;
|
|
984
|
+
}
|
|
985
|
+
return (0, trace_1.startTrace)({
|
|
986
|
+
cwd: cliRequest.input.cwd,
|
|
987
|
+
argv: [cliRequest.input.command, ...cliRequest.input.restArgs],
|
|
988
|
+
command: cliRequest.input.command,
|
|
989
|
+
restArgs: cliRequest.input.restArgs,
|
|
990
|
+
...(cliRequest.input.stdinPayload !== undefined ? { stdinPayload: cliRequest.input.stdinPayload } : {}),
|
|
991
|
+
...(cliRequest.input.stdinInputSource !== undefined ? { stdinSource: cliRequest.input.stdinInputSource } : {}),
|
|
992
|
+
traceDir: cliRequest.traceDir,
|
|
993
|
+
startedAtMs
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
function completeCliFormTrace(trace, cliRequest, output, exitCode, startedAtMs) {
|
|
997
|
+
if (!trace?.enabled || !cliRequest) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const envelope = (0, presentation_1.createCliPresentationEnvelope)(output);
|
|
1001
|
+
trace.complete({
|
|
1002
|
+
output: envelope.tracePayload,
|
|
1003
|
+
stdoutText: envelope.text ? `${envelope.text.trimEnd()}\n` : `${JSON.stringify(envelope.tracePayload, null, 2)}\n`,
|
|
1004
|
+
exitCode: output.ok === false ? 1 : exitCode,
|
|
1005
|
+
durationMs: Date.now() - startedAtMs
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
function prepareCliPresentationPayload(output) {
|
|
1009
|
+
return (0, presentation_1.createCliPresentationEnvelope)(output).payload;
|
|
1010
|
+
}
|
|
1011
|
+
function startCliProgressStream(response, input) {
|
|
1012
|
+
if (!shouldStreamModulePlanProgress(input)) {
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
const executionId = input.modulePlanExecutionId ?? (0, module_plan_cache_1.buildModulePlanExecutionId)();
|
|
1016
|
+
input.modulePlanExecutionId = executionId;
|
|
1017
|
+
const streamStartedAtMs = Date.now();
|
|
1018
|
+
const timeoutEstimate = estimateModulePlanTimeoutForStream(input);
|
|
1019
|
+
const estimatedLine = timeoutEstimate
|
|
1020
|
+
? `\nestimated: ${(0, module_plan_timeout_1.formatModulePlanTimeoutEstimate)(timeoutEstimate.estimatedDurationMs)}`
|
|
1021
|
+
: "";
|
|
1022
|
+
if (!input.suppressModulePlanStreamStart) {
|
|
1023
|
+
writeStreamEvent(response, {
|
|
1024
|
+
type: "start",
|
|
1025
|
+
text: `modulePlan.${input.restArgs[0] ?? "execute"} ${executionId}${estimatedLine}`,
|
|
1026
|
+
data: {
|
|
1027
|
+
operation: `modulePlan.${input.restArgs[0] ?? "execute"}`,
|
|
1028
|
+
executionId,
|
|
1029
|
+
...(timeoutEstimate ? {
|
|
1030
|
+
estimatedTimeoutMs: timeoutEstimate.recommendedTimeoutMs,
|
|
1031
|
+
estimatedDurationMs: timeoutEstimate.estimatedDurationMs,
|
|
1032
|
+
suggestedFirstCheckMs: timeoutEstimate.suggestedFirstCheckMs,
|
|
1033
|
+
rowCount: timeoutEstimate.rowCount,
|
|
1034
|
+
symbolCount: timeoutEstimate.symbolCount
|
|
1035
|
+
} : {})
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
if (!MODULE_PLAN_PROGRESS_STREAM_ENABLED) {
|
|
1040
|
+
return null;
|
|
1041
|
+
}
|
|
1042
|
+
let lastHeartbeatAtMs = streamStartedAtMs;
|
|
1043
|
+
return setInterval(() => {
|
|
1044
|
+
try {
|
|
1045
|
+
const status = (0, module_plan_cache_1.readModulePlanExecutionStatus)(input.cwd, executionId);
|
|
1046
|
+
const executionStartedAtMs = Date.parse(status.startedAt);
|
|
1047
|
+
if (Number.isFinite(executionStartedAtMs) && executionStartedAtMs + 1_000 < streamStartedAtMs) {
|
|
1048
|
+
lastHeartbeatAtMs = writeModulePlanHeartbeat(response, lastHeartbeatAtMs);
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const hasVisibleProgress = status.completedRows > 0 || status.failedRows > 0 || status.filesWritten.length > 0;
|
|
1052
|
+
if (!hasVisibleProgress) {
|
|
1053
|
+
lastHeartbeatAtMs = writeModulePlanHeartbeat(response, lastHeartbeatAtMs);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
writeStreamEvent(response, {
|
|
1057
|
+
type: "progress",
|
|
1058
|
+
text: `progress: ${status.completedRows}/${status.rowCount} rows${formatModulePlanEntityProgress(status.completedEntities, status.entityCount)}, ${status.filesWritten.length} files`,
|
|
1059
|
+
data: {
|
|
1060
|
+
operation: status.operation,
|
|
1061
|
+
executionId: status.executionId,
|
|
1062
|
+
status: status.status,
|
|
1063
|
+
completedRows: status.completedRows,
|
|
1064
|
+
failedRows: status.failedRows,
|
|
1065
|
+
rowCount: status.rowCount,
|
|
1066
|
+
completedEntities: status.completedEntities,
|
|
1067
|
+
entityCount: status.entityCount,
|
|
1068
|
+
filesWritten: status.filesWritten.length
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
catch {
|
|
1073
|
+
lastHeartbeatAtMs = writeModulePlanHeartbeat(response, lastHeartbeatAtMs);
|
|
1074
|
+
}
|
|
1075
|
+
}, 5_000);
|
|
1076
|
+
}
|
|
1077
|
+
function writeModulePlanHeartbeat(response, lastHeartbeatAtMs) {
|
|
1078
|
+
if (!MODULE_PLAN_HEARTBEAT_ENABLED) {
|
|
1079
|
+
return lastHeartbeatAtMs;
|
|
1080
|
+
}
|
|
1081
|
+
const now = Date.now();
|
|
1082
|
+
if (now - lastHeartbeatAtMs < 30_000) {
|
|
1083
|
+
return lastHeartbeatAtMs;
|
|
1084
|
+
}
|
|
1085
|
+
writeStreamEvent(response, {
|
|
1086
|
+
type: "progress",
|
|
1087
|
+
text: "modulePlan still running",
|
|
1088
|
+
data: {
|
|
1089
|
+
operation: "modulePlan",
|
|
1090
|
+
status: "running"
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
return now;
|
|
1094
|
+
}
|
|
1095
|
+
function formatModulePlanEntityProgress(completedEntities, entityCount) {
|
|
1096
|
+
if (!entityCount || entityCount <= 0) {
|
|
1097
|
+
return "";
|
|
1098
|
+
}
|
|
1099
|
+
const completed = completedEntities ?? 0;
|
|
1100
|
+
return `, ${Math.floor((completed / entityCount) * 100)}% entities`;
|
|
1101
|
+
}
|
|
1102
|
+
function shouldStreamModulePlanProgress(input) {
|
|
1103
|
+
return isSessionModulePlanMutation(input);
|
|
1104
|
+
}
|
|
1105
|
+
function estimateModulePlanTimeoutForStream(input) {
|
|
1106
|
+
const mutateModulePlanRequest = readSingleModulePlanMutateRequest(input);
|
|
1107
|
+
if (mutateModulePlanRequest) {
|
|
1108
|
+
return (0, module_plan_timeout_1.estimateModulePlanTimeoutFromRequest)(mutateModulePlanRequest);
|
|
1109
|
+
}
|
|
1110
|
+
const action = input.restArgs[0] ?? "";
|
|
1111
|
+
if (action === "execute") {
|
|
1112
|
+
return (0, module_plan_timeout_1.estimateModulePlanTimeoutFromRequest)(input.stdinPayload);
|
|
1113
|
+
}
|
|
1114
|
+
if (action !== "apply") {
|
|
1115
|
+
return null;
|
|
1116
|
+
}
|
|
1117
|
+
const planId = readModulePlanApplyPlanId(input.restArgs);
|
|
1118
|
+
if (!planId) {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
try {
|
|
1122
|
+
return (0, module_plan_timeout_1.estimateModulePlanTimeoutFromRequest)((0, module_plan_cache_1.readModulePlanRecord)(input.cwd, planId).normalizedRequest);
|
|
1123
|
+
}
|
|
1124
|
+
catch {
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
function ensureSessionModulePlanExecutionId(input) {
|
|
1129
|
+
if (input.modulePlanExecutionId || !isSessionModulePlanMutation(input)) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
input.modulePlanExecutionId = (0, module_plan_cache_1.buildModulePlanExecutionId)();
|
|
1133
|
+
}
|
|
1134
|
+
function isSessionModulePlanMutation(input) {
|
|
1135
|
+
if (input.command === "modulePlan") {
|
|
1136
|
+
const action = input.restArgs[0] ?? "";
|
|
1137
|
+
return action === "execute" || action === "apply";
|
|
1138
|
+
}
|
|
1139
|
+
return Boolean(readSingleModulePlanMutateRequest(input));
|
|
1140
|
+
}
|
|
1141
|
+
function readSingleModulePlanMutateRequest(input) {
|
|
1142
|
+
if (input.command !== "mutate" || input.restArgs[0] !== "execute") {
|
|
1143
|
+
return null;
|
|
1144
|
+
}
|
|
1145
|
+
if (!isJsonObject(input.stdinPayload)) {
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
const segments = Array.isArray(input.stdinPayload.segments) ? input.stdinPayload.segments.filter(isJsonObject) : [];
|
|
1149
|
+
if (segments.length !== 1 || segments[0]?.kind !== "modulePlan") {
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
const segment = segments[0];
|
|
1153
|
+
const sourceFile = typeof segment.sourceFile === "string" ? segment.sourceFile : null;
|
|
1154
|
+
const modules = Array.isArray(segment.modules) ? segment.modules.filter(isJsonObject) : [];
|
|
1155
|
+
if (!sourceFile || modules.length === 0) {
|
|
1156
|
+
return null;
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
sourceFile,
|
|
1160
|
+
modules: modules.map((module) => ({
|
|
1161
|
+
target: typeof module.targetFile === "string"
|
|
1162
|
+
? module.targetFile
|
|
1163
|
+
: typeof module.target === "string"
|
|
1164
|
+
? module.target
|
|
1165
|
+
: "",
|
|
1166
|
+
entities: readStringArray(module.symbols).length > 0 ? readStringArray(module.symbols) : readStringArray(module.entities)
|
|
1167
|
+
}))
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function readStringArray(value) {
|
|
1171
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1172
|
+
}
|
|
1173
|
+
function isJsonObject(value) {
|
|
1174
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1175
|
+
}
|
|
1176
|
+
function readModulePlanApplyPlanId(restArgs) {
|
|
1177
|
+
const flagIndex = restArgs.indexOf("--plan");
|
|
1178
|
+
if (flagIndex >= 0) {
|
|
1179
|
+
const value = restArgs[flagIndex + 1];
|
|
1180
|
+
return value && !value.startsWith("--") ? value : null;
|
|
1181
|
+
}
|
|
1182
|
+
const positional = restArgs.slice(1).find((arg) => !arg.startsWith("--"));
|
|
1183
|
+
return positional ?? null;
|
|
1184
|
+
}
|
|
1185
|
+
async function runSessionServerCli() {
|
|
1186
|
+
const command = process.argv[3] || "status";
|
|
1187
|
+
if (command !== "serve") {
|
|
1188
|
+
(0, stdout_1.printJson)((0, errors_1.errorPayload)(new errors_1.CliError("UNKNOWN_SESSION_COMMAND", `Unknown aib session command: ${command}`)));
|
|
1189
|
+
process.exitCode = 1;
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
const server = new CliSessionServer();
|
|
1193
|
+
await server.serve();
|
|
1194
|
+
}
|