@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
|
@@ -1,5 +1,811 @@
|
|
|
1
|
-
"use strict";var X=exports&&exports.__createBinding||(Object.create?(function(e,t,o,n){n===void 0&&(n=o);var s=Object.getOwnPropertyDescriptor(t,o);(!s||("get"in s?!t.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,s)}):(function(e,t,o,n){n===void 0&&(n=o),e[n]=t[o]})),Q=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),Z=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(o){var n=[];for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(n[n.length]=s);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var o={};if(t!=null)for(var n=e(t),s=0;s<n.length;s++)n[s]!=="default"&&X(o,t,n[s]);return Q(o,t),o}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.isInspectCyclesRequest=ce,exports.runInspectCycles=le,exports.buildCyclesViewResponse=B,exports.appendCycleComponentText=Y;const ee=Z(require("node:path")),te=require("node:crypto"),ne=require("../config/local-config"),E=require("../config/path-display"),A=require("../shared/agent-text"),y=require("../shared/errors"),oe=require("./inspect-graph"),N=require("./session-workspace"),S=10,se=6,O=8,ie=5e3,re=12e4;function ce(e,t){if(e[0]==="cycles")return!0;if(!e.includes("--stdin")||!f(t))return!1;const o=U(t);return o.length>0&&o.some(n=>h(n.op)==="cycles")}function le(e,t,o){const n=(0,E.buildDisplayPathAliases)(e,(0,N.readEffectiveSessionPathAliases)(e)),l=ue(t,o).map(r=>ae(e,r,n)),i=l.length===1?l[0]:{results:l};return(0,A.attachAgentText)(i,I(i))}function ue(e,t){if(e[0]==="cycles")return[fe(e.slice(1))];if(!e.includes("--stdin")||!f(t))throw new y.CliError("INSPECT_CYCLES_SCOPE_REQUIRED","inspect cycles expects scope or files.");const o=U(t);if(o.some(n=>h(n.op)!=="cycles"))throw new y.CliError("INSPECT_CYCLES_MIXED_BATCH_UNSUPPORTED","inspect cycles --stdin expects only cycles requests.");return o.map((n,s)=>de(n,s))}function fe(e){const o=[...e.filter(n=>!n.startsWith("--")&&!Fe(e,n)),...C(e,"--scope"),...C(e,"--scopes")];return L({scopes:o,files:[...C(e,"--file"),...C(e,"--files")],detail:w(R(e,"--detail")),kind:M(R(e,"--kind")),exclude:[...C(e,"--exclude"),...C(e,"--excludes")],limit:q(R(e,"--limit"))??S})}function de(e,t){return L({scopes:a(e.scope)??a(e.scopes)??[],files:a(e.file)??a(e.files)??[],detail:w(e.detail),kind:M(e.kind),exclude:a(e.exclude)??a(e.excludes)??[],limit:q(e.limit)??S,index:t})}function L(e){if(e.scopes.length===0&&e.files.length===0){const t=e.index!==void 0?` at index ${e.index}`:"";throw new y.CliError("INSPECT_CYCLES_SCOPE_REQUIRED",`inspect cycles request${t} expects scope or files.`)}return{scopes:j(e.scopes),files:j(e.files),detail:e.detail,kind:e.kind,exclude:j(e.exclude),limit:e.limit}}function ae(e,t,o){const n=(0,ne.resolveLocalCliConfig)(e),s=t.scopes.length>0?t.scopes:t.files,l=t.files.map(p=>Le(e,p)),i=me();i({phase:"graph",completed:0,message:"building import graph"});const r=(0,oe.buildInspectGraphModel)(e,{scopes:s,depth:t.scopes.length>0?0:se,excludePatterns:[...n.config.inspect.graph.exclude,...t.exclude],symbolUsage:t.detail==="imports"});i({phase:"graph",completed:r.files.length,total:r.files.length,message:"import graph built"});const u=new Set(l),c=pe(r.edges,{onProgress:i}).filter(p=>(u.size===0||p.nodes.some(J=>u.has(J)))&&(t.kind===null||p.kind===t.kind)),d=ke(t,r.files.length,r.edges.length,u.size,c),m=Me(d),g=De(e,t,o),x={ok:!0,op:"cycles",version:1,createdAt:new Date().toISOString(),target:g,request:{scopes:t.scopes,files:t.files,detail:t.detail,...t.kind?{kind:t.kind}:{},limit:t.limit,exclude:t.exclude},componentCount:c.length,summary:V(c),analysis:d,timeoutHint:m,components:c.map(p=>Ee(p,o)),...t.exclude.length>0?{exclude:t.exclude}:{}},D=Ne(JSON.stringify(x),o);D&&(x.paths=D);const W=Oe(x),P=(0,N.saveSessionResultViewJson)(e,W,x),_=B(x,{detail:t.detail,offset:0,limit:t.limit});if(P){_.result=P.saved,_.resultFile=P.file;const p=I(_);if(p)return(0,A.attachAgentText)(_,p)}return _}function me(){return()=>{}}function pe(e,t={}){const o=new Map;for(const i of e){const r=o.get(i.from)??[];r.push(i),o.set(i.from,r)}for(const i of o.values())i.sort((r,u)=>r.to.localeCompare(u.to));const n=Array.from(new Set(e.flatMap(i=>[i.from,i.to]))).sort();t.onProgress?.({phase:"components",completed:0,total:n.length,message:"finding cyclic components"});const s=ge(n,o).filter(i=>i.length>1||ye(i[0]??"",o));t.onProgress?.({phase:"components",completed:n.length,total:n.length,message:`${s.length} cyclic components found`});const l=[];return s.forEach((i,r)=>{const u=Ce(i,o);if(t.onProgress?.({phase:"representatives",completed:r+1,total:s.length,message:"building representative cycles"}),u){const c=he(i,o);l.push({nodes:i,representative:u,kind:T(c),counts:be(c)})}}),l.sort(_e)}function he(e,t){const o=new Set(e);return e.flatMap(n=>(t.get(n)??[]).filter(s=>o.has(s.to)))}function ge(e,t){let o=0;const n=[],s=new Set,l=new Map,i=new Map,r=[];for(const c of e)l.has(c)||u(c);return r.map(c=>c.sort());function u(c){l.set(c,o),i.set(c,o),o+=1,n.push(c),s.add(c);for(const m of t.get(c)??[]){const g=m.to;l.has(g)?s.has(g)&&i.set(c,Math.min(i.get(c)??0,l.get(g)??0)):(u(g),i.set(c,Math.min(i.get(c)??0,i.get(g)??0)))}if(i.get(c)!==l.get(c))return;const d=[];for(;n.length>0;){const m=n.pop();if(s.delete(m),d.push(m),m===c)break}r.push(d)}}function ye(e,t){return(t.get(e)??[]).some(o=>o.to===e)}function Ce(e,t){const o=new Set(e);let n=null;for(const s of e){const l=(t.get(s)??[]).filter(i=>o.has(i.to));for(const i of l){if(i.to===s){n=F(n,{nodes:[s,s],edges:[i],kind:T([i])});continue}const r=xe(i.to,s,t,o);r&&(n=F(n,{nodes:[s,...r.nodes],edges:[i,...r.edges],kind:T([i,...r.edges])}))}}return n}function xe(e,t,o,n){const s=[{node:e,nodes:[e],edges:[]}],l=new Set([e]);for(let i=0;i<s.length;i+=1){const r=s[i];for(const u of o.get(r.node)??[])if(n.has(u.to)){if(u.to===t)return{nodes:[...r.nodes,t],edges:[...r.edges,u]};l.has(u.to)||(l.add(u.to),s.push({node:u.to,nodes:[...r.nodes,u.to],edges:[...r.edges,u]}))}}return null}function F(e,t){return e?t.nodes.length!==e.nodes.length?t.nodes.length<e.nodes.length?t:e:$(t.nodes)<$(e.nodes)?t:e:t}function _e(e,t){const o=v(e.kind)-v(t.kind);if(o!==0)return o;const n=t.nodes.length-e.nodes.length;return n!==0?n:$(e.representative.nodes).localeCompare($(t.representative.nodes))}function v(e){return e==="runtime"?0:e==="mixed"?1:2}function T(e){const t=new Set(e.map(H));return t.size===0||t.has("mixed")||t.has("runtime")&&t.has("type-only")?"mixed":t.has("runtime")?"runtime":"type-only"}function H(e){const t=e.symbols??[];if(t.length===0)return"runtime";let o=!1,n=!1;for(const s of t){if(typeof s=="string"){n=!0;continue}s.usage==="type"?o=!0:n=!0}return o&&n?"mixed":o?"type-only":"runtime"}function be(e){const t={runtime:0,"type-only":0,mixed:0};for(const o of e)t[H(o)]+=1;return t}function $(e){return e.join("\0")}function Ee(e,t){const o=e.nodes.map(s=>k(s,t)),n=Se(e.representative,t);return{kind:e.kind,files:o,fileCount:o.length,edgeCounts:e.counts,cycle:n,chain:h(n.chain)}}function Se(e,t){const o=e.nodes.map(n=>k(n,t));return{kind:e.kind,path:o,chain:o.join(" -> "),imports:e.edges.map(n=>$e(n,t))}}function $e(e,t){const o=k(e.from,t),n=k(e.to,t),s=Ie(e.symbols);return s?`${o} -> ${n}: ${s}`:`${o} -> ${n}`}function Ie(e){const t=(e??[]).map(n=>typeof n=="string"?n:n.name).filter(n=>n.length>0);if(t.length===0)return"";const o=t.slice(0,4);return t.length>o.length?`${o.join(" ")} + ${t.length-o.length} more`:o.join(" ")}function B(e,t={}){if(e.op!=="cycles")throw new y.CliError("INVALID_CYCLES_RESULT","Expected a cycles result artifact.");const o=t.detail??w(ve(e.request,"detail")),n=Array.isArray(e.components)?e.components.filter(f):[],s=t.kind?n.filter(m=>m.kind===t.kind):n,l=s.length,i=Math.max(0,t.offset??0),r=Math.max(1,t.limit??S),u=t.index!==void 0?[s[t.index-1]].filter(f):s.slice(i,i+r),c=t.index!==void 0?0:Math.max(0,l-i-u.length),d={ok:!0,op:"cycles",target:h(e.target)??"",detail:o,componentCount:l,summary:Ae(s),...f(e.analysis)?{analysis:e.analysis}:{},...f(e.timeoutHint)?{timeoutHint:e.timeoutHint}:{},components:u,offset:i,limit:r,...t.index!==void 0?{index:t.index}:{},...c>0?{hidden:c}:{},...t.resultHandle?{result:t.resultHandle}:{},...e.paths?{paths:e.paths}:{}};return(0,A.attachAgentText)(d,I(d))}function ke(e,t,o,n,s){const l=V(s),i=s.reduce((u,c)=>Math.max(u,c.nodes.length),0),r=s.reduce((u,c)=>u+c.representative.edges.length,0);return{fileCount:t,edgeCount:o,focusFileCount:n,scopeCount:e.scopes.length,detail:e.detail,componentCount:s.length,largestComponentFileCount:i,representativeEdgeCount:r,runtimeComponentCount:l.runtime,mixedComponentCount:l.mixed,typeOnlyComponentCount:l["type-only"]}}function Me(e){const t=b(e.fileCount),o=b(e.edgeCount),n=b(e.componentCount),s=b(e.largestComponentFileCount),l=b(e.representativeEdgeCount),i=h(e.detail)??"summary";return{recommendedTimeoutMs:Pe({fileCount:t,edgeCount:o,componentCount:n,largestComponentFileCount:s,representativeEdgeCount:l,detail:i}),fileCount:t,edgeCount:o,componentCount:n,detail:i,message:"If cycle analysis runs as a post-mutation phase, inspect progress with: aib execution status last"}}function Pe(e){const t=e.detail==="imports"?1.25:e.detail==="files"?1.1:1,o=Math.round((750+e.fileCount*1.5+e.edgeCount*1.25+e.componentCount*4+e.largestComponentFileCount*2+e.representativeEdgeCount*1.5)*t);return Math.min(re,Math.max(ie,o))}function V(e){const t={runtime:0,"type-only":0,mixed:0};for(const o of e)t[o.kind]+=1;return t}function Ae(e){const t={runtime:0,"type-only":0,mixed:0};for(const o of e){const n=M(o.kind);n&&(t[n]+=1)}return t}function Oe(e){return`res_${(0,te.createHash)("sha256").update(JSON.stringify({target:e.target,request:e.request,componentCount:e.componentCount,components:e.components})).digest("hex").slice(0,8)}`}function I(e){if(Array.isArray(e.results)){const i=e.results.filter(f).map(I).filter(r=>!!r);return i.length>0?i.join(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.isInspectCyclesRequest = isInspectCyclesRequest;
|
|
37
|
+
exports.runInspectCycles = runInspectCycles;
|
|
38
|
+
exports.buildCyclesViewResponse = buildCyclesViewResponse;
|
|
39
|
+
exports.formatCyclesResponse = formatCyclesResponse;
|
|
40
|
+
exports.appendCycleComponentText = appendCycleComponentText;
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const node_crypto_1 = require("node:crypto");
|
|
43
|
+
const local_config_1 = require("../config/local-config");
|
|
44
|
+
const path_display_1 = require("../config/path-display");
|
|
45
|
+
const agent_text_1 = require("../shared/agent-text");
|
|
46
|
+
const errors_1 = require("../shared/errors");
|
|
47
|
+
const inspect_graph_1 = require("./inspect-graph");
|
|
48
|
+
const session_workspace_1 = require("./session-workspace");
|
|
49
|
+
const DEFAULT_LIMIT = 10;
|
|
50
|
+
const FILE_NEIGHBOR_DEPTH = 6;
|
|
51
|
+
const TEXT_COMPONENT_FILE_LIMIT = 8;
|
|
52
|
+
const CYCLES_ESTIMATE_MIN_MS = 5_000;
|
|
53
|
+
const CYCLES_ESTIMATE_MAX_MS = 120_000;
|
|
54
|
+
function isInspectCyclesRequest(restArgs, stdinPayload) {
|
|
55
|
+
if (restArgs[0] === "cycles") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (!restArgs.includes("--stdin") || !isObject(stdinPayload)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const requests = expandCyclesPayloadRequests(stdinPayload);
|
|
62
|
+
return requests.length > 0 && requests.some((request) => readString(request.op) === "cycles");
|
|
63
|
+
}
|
|
64
|
+
function runInspectCycles(cwd, restArgs, stdinPayload) {
|
|
65
|
+
const aliases = (0, path_display_1.buildDisplayPathAliases)(cwd, (0, session_workspace_1.readEffectiveSessionPathAliases)(cwd));
|
|
66
|
+
const requests = buildCyclesRequests(restArgs, stdinPayload);
|
|
67
|
+
const results = requests.map((request) => runCyclesRequest(cwd, request, aliases));
|
|
68
|
+
const response = results.length === 1 ? results[0] : { results };
|
|
69
|
+
return (0, agent_text_1.attachAgentText)(response, formatCyclesResponse(response));
|
|
70
|
+
}
|
|
71
|
+
function buildCyclesRequests(restArgs, stdinPayload) {
|
|
72
|
+
if (restArgs[0] === "cycles") {
|
|
73
|
+
return [cyclesRequestFromArgs(restArgs.slice(1))];
|
|
74
|
+
}
|
|
75
|
+
if (!restArgs.includes("--stdin") || !isObject(stdinPayload)) {
|
|
76
|
+
throw new errors_1.CliError("INSPECT_CYCLES_SCOPE_REQUIRED", "inspect cycles expects scope or files.");
|
|
77
|
+
}
|
|
78
|
+
const rawRequests = expandCyclesPayloadRequests(stdinPayload);
|
|
79
|
+
if (rawRequests.some((request) => readString(request.op) !== "cycles")) {
|
|
80
|
+
throw new errors_1.CliError("INSPECT_CYCLES_MIXED_BATCH_UNSUPPORTED", "inspect cycles --stdin expects only cycles requests.");
|
|
81
|
+
}
|
|
82
|
+
return rawRequests.map((request, index) => cyclesRequestFromObject(request, index));
|
|
83
|
+
}
|
|
84
|
+
function cyclesRequestFromArgs(args) {
|
|
85
|
+
const positionals = args.filter((arg) => !arg.startsWith("--") && !isFlagValue(args, arg));
|
|
86
|
+
const scopes = [
|
|
87
|
+
...positionals,
|
|
88
|
+
...readFlagValues(args, "--scope"),
|
|
89
|
+
...readFlagValues(args, "--scopes")
|
|
90
|
+
];
|
|
91
|
+
return finalizeCyclesRequest({
|
|
92
|
+
scopes,
|
|
93
|
+
files: [
|
|
94
|
+
...readFlagValues(args, "--file"),
|
|
95
|
+
...readFlagValues(args, "--files")
|
|
96
|
+
],
|
|
97
|
+
detail: readCyclesDetail(readFlagValue(args, "--detail")),
|
|
98
|
+
kind: readCycleKind(readFlagValue(args, "--kind")),
|
|
99
|
+
exclude: [
|
|
100
|
+
...readFlagValues(args, "--exclude"),
|
|
101
|
+
...readFlagValues(args, "--excludes")
|
|
102
|
+
],
|
|
103
|
+
limit: readPositiveInteger(readFlagValue(args, "--limit")) ?? DEFAULT_LIMIT
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function cyclesRequestFromObject(raw, index) {
|
|
107
|
+
return finalizeCyclesRequest({
|
|
108
|
+
scopes: readStringArray(raw.scope) ?? readStringArray(raw.scopes) ?? [],
|
|
109
|
+
files: readStringArray(raw.file) ?? readStringArray(raw.files) ?? [],
|
|
110
|
+
detail: readCyclesDetail(raw.detail),
|
|
111
|
+
kind: readCycleKind(raw.kind),
|
|
112
|
+
exclude: readStringArray(raw.exclude) ?? readStringArray(raw.excludes) ?? [],
|
|
113
|
+
limit: readPositiveInteger(raw.limit) ?? DEFAULT_LIMIT,
|
|
114
|
+
index
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function finalizeCyclesRequest(input) {
|
|
118
|
+
if (input.scopes.length === 0 && input.files.length === 0) {
|
|
119
|
+
const suffix = input.index !== undefined ? ` at index ${input.index}` : "";
|
|
120
|
+
throw new errors_1.CliError("INSPECT_CYCLES_SCOPE_REQUIRED", `inspect cycles request${suffix} expects scope or files.`);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
scopes: uniqueSorted(input.scopes),
|
|
124
|
+
files: uniqueSorted(input.files),
|
|
125
|
+
detail: input.detail,
|
|
126
|
+
kind: input.kind,
|
|
127
|
+
exclude: uniqueSorted(input.exclude),
|
|
128
|
+
limit: input.limit
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function runCyclesRequest(cwd, request, aliases) {
|
|
132
|
+
const localConfig = (0, local_config_1.resolveLocalCliConfig)(cwd);
|
|
133
|
+
const graphScopes = request.scopes.length > 0 ? request.scopes : request.files;
|
|
134
|
+
const focusFiles = request.files.map((file) => toGraphPath(cwd, file));
|
|
135
|
+
const progress = createCycleProgressReporter();
|
|
136
|
+
progress({ phase: "graph", completed: 0, message: "building import graph" });
|
|
137
|
+
const model = (0, inspect_graph_1.buildInspectGraphModel)(cwd, {
|
|
138
|
+
scopes: graphScopes,
|
|
139
|
+
depth: request.scopes.length > 0 ? 0 : FILE_NEIGHBOR_DEPTH,
|
|
140
|
+
excludePatterns: [
|
|
141
|
+
...localConfig.config.inspect.graph.exclude,
|
|
142
|
+
...request.exclude
|
|
143
|
+
],
|
|
144
|
+
symbolUsage: request.detail === "imports"
|
|
145
|
+
});
|
|
146
|
+
progress({ phase: "graph", completed: model.files.length, total: model.files.length, message: "import graph built" });
|
|
147
|
+
const focusSet = new Set(focusFiles);
|
|
148
|
+
const components = findCyclicComponents(model.edges, {
|
|
149
|
+
onProgress: progress
|
|
150
|
+
}).filter((component) => (focusSet.size === 0 || component.nodes.some((node) => focusSet.has(node))) &&
|
|
151
|
+
(request.kind === null || component.kind === request.kind));
|
|
152
|
+
const analysis = buildCyclesAnalysis(request, model.files.length, model.edges.length, focusSet.size, components);
|
|
153
|
+
const timeoutHint = buildCyclesTimeoutHint(analysis);
|
|
154
|
+
const target = formatCyclesTarget(cwd, request, aliases);
|
|
155
|
+
const artifact = {
|
|
156
|
+
ok: true,
|
|
157
|
+
op: "cycles",
|
|
158
|
+
version: 1,
|
|
159
|
+
createdAt: new Date().toISOString(),
|
|
160
|
+
target,
|
|
161
|
+
request: {
|
|
162
|
+
scopes: request.scopes,
|
|
163
|
+
files: request.files,
|
|
164
|
+
detail: request.detail,
|
|
165
|
+
...(request.kind ? { kind: request.kind } : {}),
|
|
166
|
+
limit: request.limit,
|
|
167
|
+
exclude: request.exclude
|
|
168
|
+
},
|
|
169
|
+
componentCount: components.length,
|
|
170
|
+
summary: summarizeComponents(components),
|
|
171
|
+
analysis,
|
|
172
|
+
timeoutHint,
|
|
173
|
+
components: components.map((component) => formatComponent(component, aliases)),
|
|
174
|
+
...(request.exclude.length > 0 ? { exclude: request.exclude } : {})
|
|
175
|
+
};
|
|
176
|
+
const paths = usedAliasPayload(JSON.stringify(artifact), aliases);
|
|
177
|
+
if (paths) {
|
|
178
|
+
artifact.paths = paths;
|
|
179
|
+
}
|
|
180
|
+
const resultId = createResultId(artifact);
|
|
181
|
+
const saved = (0, session_workspace_1.saveSessionResultViewJson)(cwd, resultId, artifact);
|
|
182
|
+
const response = buildCyclesViewResponse(artifact, {
|
|
183
|
+
detail: request.detail,
|
|
184
|
+
offset: 0,
|
|
185
|
+
limit: request.limit
|
|
186
|
+
});
|
|
187
|
+
if (saved) {
|
|
188
|
+
response.result = saved.saved;
|
|
189
|
+
response.resultFile = saved.file;
|
|
190
|
+
const text = formatCyclesResponse(response);
|
|
191
|
+
if (text) {
|
|
192
|
+
return (0, agent_text_1.attachAgentText)(response, text);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return response;
|
|
196
|
+
}
|
|
197
|
+
function createCycleProgressReporter() {
|
|
198
|
+
return () => {
|
|
199
|
+
// Reserved for future stderr/execution progress without changing the analysis API again.
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function findCyclicComponents(edges, options = {}) {
|
|
203
|
+
const adjacency = new Map();
|
|
204
|
+
for (const edge of edges) {
|
|
205
|
+
const outgoing = adjacency.get(edge.from) ?? [];
|
|
206
|
+
outgoing.push(edge);
|
|
207
|
+
adjacency.set(edge.from, outgoing);
|
|
208
|
+
}
|
|
209
|
+
for (const outgoing of adjacency.values()) {
|
|
210
|
+
outgoing.sort((left, right) => left.to.localeCompare(right.to));
|
|
211
|
+
}
|
|
212
|
+
const nodes = Array.from(new Set(edges.flatMap((edge) => [edge.from, edge.to]))).sort();
|
|
213
|
+
options.onProgress?.({ phase: "components", completed: 0, total: nodes.length, message: "finding cyclic components" });
|
|
214
|
+
const stronglyConnected = findStronglyConnectedComponents(nodes, adjacency)
|
|
215
|
+
.filter((component) => component.length > 1 || hasSelfEdge(component[0] ?? "", adjacency));
|
|
216
|
+
options.onProgress?.({
|
|
217
|
+
phase: "components",
|
|
218
|
+
completed: nodes.length,
|
|
219
|
+
total: nodes.length,
|
|
220
|
+
message: `${stronglyConnected.length} cyclic components found`
|
|
221
|
+
});
|
|
222
|
+
const components = [];
|
|
223
|
+
stronglyConnected.forEach((component, index) => {
|
|
224
|
+
const representative = findRepresentativeCycle(component, adjacency);
|
|
225
|
+
options.onProgress?.({
|
|
226
|
+
phase: "representatives",
|
|
227
|
+
completed: index + 1,
|
|
228
|
+
total: stronglyConnected.length,
|
|
229
|
+
message: "building representative cycles"
|
|
230
|
+
});
|
|
231
|
+
if (representative) {
|
|
232
|
+
const internalEdges = collectInternalEdges(component, adjacency);
|
|
233
|
+
components.push({
|
|
234
|
+
nodes: component,
|
|
235
|
+
representative,
|
|
236
|
+
kind: classifyEdges(internalEdges),
|
|
237
|
+
counts: countEdgeKinds(internalEdges)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return components.sort(compareComponents);
|
|
242
|
+
}
|
|
243
|
+
function collectInternalEdges(component, adjacency) {
|
|
244
|
+
const componentSet = new Set(component);
|
|
245
|
+
return component.flatMap((node) => (adjacency.get(node) ?? []).filter((edge) => componentSet.has(edge.to)));
|
|
246
|
+
}
|
|
247
|
+
function findStronglyConnectedComponents(nodes, adjacency) {
|
|
248
|
+
let index = 0;
|
|
249
|
+
const stack = [];
|
|
250
|
+
const onStack = new Set();
|
|
251
|
+
const indexes = new Map();
|
|
252
|
+
const lowlinks = new Map();
|
|
253
|
+
const components = [];
|
|
254
|
+
for (const node of nodes) {
|
|
255
|
+
if (!indexes.has(node)) {
|
|
256
|
+
strongConnect(node);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return components.map((component) => component.sort());
|
|
260
|
+
function strongConnect(node) {
|
|
261
|
+
indexes.set(node, index);
|
|
262
|
+
lowlinks.set(node, index);
|
|
263
|
+
index += 1;
|
|
264
|
+
stack.push(node);
|
|
265
|
+
onStack.add(node);
|
|
266
|
+
for (const edge of adjacency.get(node) ?? []) {
|
|
267
|
+
const target = edge.to;
|
|
268
|
+
if (!indexes.has(target)) {
|
|
269
|
+
strongConnect(target);
|
|
270
|
+
lowlinks.set(node, Math.min(lowlinks.get(node) ?? 0, lowlinks.get(target) ?? 0));
|
|
271
|
+
}
|
|
272
|
+
else if (onStack.has(target)) {
|
|
273
|
+
lowlinks.set(node, Math.min(lowlinks.get(node) ?? 0, indexes.get(target) ?? 0));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (lowlinks.get(node) !== indexes.get(node)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const component = [];
|
|
280
|
+
while (stack.length > 0) {
|
|
281
|
+
const next = stack.pop();
|
|
282
|
+
onStack.delete(next);
|
|
283
|
+
component.push(next);
|
|
284
|
+
if (next === node) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
components.push(component);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function hasSelfEdge(node, adjacency) {
|
|
292
|
+
return (adjacency.get(node) ?? []).some((edge) => edge.to === node);
|
|
293
|
+
}
|
|
294
|
+
function findRepresentativeCycle(component, adjacency) {
|
|
295
|
+
const componentSet = new Set(component);
|
|
296
|
+
let best = null;
|
|
297
|
+
for (const start of component) {
|
|
298
|
+
const outgoing = (adjacency.get(start) ?? []).filter((edge) => componentSet.has(edge.to));
|
|
299
|
+
for (const firstEdge of outgoing) {
|
|
300
|
+
if (firstEdge.to === start) {
|
|
301
|
+
best = pickBetterCycle(best, { nodes: [start, start], edges: [firstEdge], kind: classifyEdges([firstEdge]) });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const path = findShortestPath(firstEdge.to, start, adjacency, componentSet);
|
|
305
|
+
if (!path) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
best = pickBetterCycle(best, {
|
|
309
|
+
nodes: [start, ...path.nodes],
|
|
310
|
+
edges: [firstEdge, ...path.edges],
|
|
311
|
+
kind: classifyEdges([firstEdge, ...path.edges])
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return best;
|
|
316
|
+
}
|
|
317
|
+
function findShortestPath(from, to, adjacency, allowed) {
|
|
318
|
+
const queue = [{ node: from, nodes: [from], edges: [] }];
|
|
319
|
+
const visited = new Set([from]);
|
|
320
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
321
|
+
const current = queue[index];
|
|
322
|
+
for (const edge of adjacency.get(current.node) ?? []) {
|
|
323
|
+
if (!allowed.has(edge.to)) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (edge.to === to) {
|
|
327
|
+
return {
|
|
328
|
+
nodes: [...current.nodes, to],
|
|
329
|
+
edges: [...current.edges, edge]
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (visited.has(edge.to)) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
visited.add(edge.to);
|
|
336
|
+
queue.push({
|
|
337
|
+
node: edge.to,
|
|
338
|
+
nodes: [...current.nodes, edge.to],
|
|
339
|
+
edges: [...current.edges, edge]
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
function pickBetterCycle(current, candidate) {
|
|
346
|
+
if (!current) {
|
|
347
|
+
return candidate;
|
|
348
|
+
}
|
|
349
|
+
if (candidate.nodes.length !== current.nodes.length) {
|
|
350
|
+
return candidate.nodes.length < current.nodes.length ? candidate : current;
|
|
351
|
+
}
|
|
352
|
+
return cycleKey(candidate.nodes) < cycleKey(current.nodes) ? candidate : current;
|
|
353
|
+
}
|
|
354
|
+
function compareComponents(left, right) {
|
|
355
|
+
const kindDelta = cycleKindRank(left.kind) - cycleKindRank(right.kind);
|
|
356
|
+
if (kindDelta !== 0) {
|
|
357
|
+
return kindDelta;
|
|
358
|
+
}
|
|
359
|
+
const sizeDelta = right.nodes.length - left.nodes.length;
|
|
360
|
+
if (sizeDelta !== 0) {
|
|
361
|
+
return sizeDelta;
|
|
362
|
+
}
|
|
363
|
+
return cycleKey(left.representative.nodes).localeCompare(cycleKey(right.representative.nodes));
|
|
364
|
+
}
|
|
365
|
+
function cycleKindRank(kind) {
|
|
366
|
+
if (kind === "runtime") {
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
if (kind === "mixed") {
|
|
370
|
+
return 1;
|
|
371
|
+
}
|
|
372
|
+
return 2;
|
|
373
|
+
}
|
|
374
|
+
function classifyEdges(edges) {
|
|
375
|
+
const kinds = new Set(edges.map(classifyEdge));
|
|
376
|
+
if (kinds.size === 0 || kinds.has("mixed") || (kinds.has("runtime") && kinds.has("type-only"))) {
|
|
377
|
+
return "mixed";
|
|
378
|
+
}
|
|
379
|
+
return kinds.has("runtime") ? "runtime" : "type-only";
|
|
380
|
+
}
|
|
381
|
+
function classifyEdge(edge) {
|
|
382
|
+
const symbols = edge.symbols ?? [];
|
|
383
|
+
if (symbols.length === 0) {
|
|
384
|
+
return "runtime";
|
|
385
|
+
}
|
|
386
|
+
let hasType = false;
|
|
387
|
+
let hasRuntime = false;
|
|
388
|
+
for (const symbol of symbols) {
|
|
389
|
+
if (typeof symbol === "string") {
|
|
390
|
+
hasRuntime = true;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (symbol.usage === "type") {
|
|
394
|
+
hasType = true;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
hasRuntime = true;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (hasType && hasRuntime) {
|
|
401
|
+
return "mixed";
|
|
402
|
+
}
|
|
403
|
+
return hasType ? "type-only" : "runtime";
|
|
404
|
+
}
|
|
405
|
+
function countEdgeKinds(edges) {
|
|
406
|
+
const counts = { runtime: 0, "type-only": 0, mixed: 0 };
|
|
407
|
+
for (const edge of edges) {
|
|
408
|
+
counts[classifyEdge(edge)] += 1;
|
|
409
|
+
}
|
|
410
|
+
return counts;
|
|
411
|
+
}
|
|
412
|
+
function cycleKey(nodes) {
|
|
413
|
+
return nodes.join("\u0000");
|
|
414
|
+
}
|
|
415
|
+
function formatComponent(component, aliases) {
|
|
416
|
+
const files = component.nodes.map((node) => compactGraphPath(node, aliases));
|
|
417
|
+
const cycle = formatCycle(component.representative, aliases);
|
|
418
|
+
return {
|
|
419
|
+
kind: component.kind,
|
|
420
|
+
files,
|
|
421
|
+
fileCount: files.length,
|
|
422
|
+
edgeCounts: component.counts,
|
|
423
|
+
cycle,
|
|
424
|
+
chain: readString(cycle.chain)
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function formatCycle(cycle, aliases) {
|
|
428
|
+
const pathValues = cycle.nodes.map((node) => compactGraphPath(node, aliases));
|
|
429
|
+
return {
|
|
430
|
+
kind: cycle.kind,
|
|
431
|
+
path: pathValues,
|
|
432
|
+
chain: pathValues.join(" -> "),
|
|
433
|
+
imports: cycle.edges.map((edge) => formatCycleImport(edge, aliases))
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function formatCycleImport(edge, aliases) {
|
|
437
|
+
const from = compactGraphPath(edge.from, aliases);
|
|
438
|
+
const to = compactGraphPath(edge.to, aliases);
|
|
439
|
+
const symbols = formatImportSymbols(edge.symbols);
|
|
440
|
+
return symbols
|
|
441
|
+
? `${from} -> ${to}: ${symbols}`
|
|
442
|
+
: `${from} -> ${to}`;
|
|
443
|
+
}
|
|
444
|
+
function formatImportSymbols(symbols) {
|
|
445
|
+
const names = (symbols ?? [])
|
|
446
|
+
.map((symbol) => typeof symbol === "string" ? symbol : symbol.name)
|
|
447
|
+
.filter((name) => name.length > 0);
|
|
448
|
+
if (names.length === 0) {
|
|
449
|
+
return "";
|
|
450
|
+
}
|
|
451
|
+
const visible = names.slice(0, 4);
|
|
452
|
+
return names.length > visible.length
|
|
453
|
+
? `${visible.join(" ")} + ${names.length - visible.length} more`
|
|
454
|
+
: visible.join(" ");
|
|
455
|
+
}
|
|
456
|
+
function buildCyclesViewResponse(artifact, options = {}) {
|
|
457
|
+
if (artifact.op !== "cycles") {
|
|
458
|
+
throw new errors_1.CliError("INVALID_CYCLES_RESULT", "Expected a cycles result artifact.");
|
|
459
|
+
}
|
|
460
|
+
const detail = options.detail ?? readCyclesDetail(readNestedString(artifact.request, "detail"));
|
|
461
|
+
const allComponents = Array.isArray(artifact.components) ? artifact.components.filter(isObject) : [];
|
|
462
|
+
const filteredComponents = options.kind
|
|
463
|
+
? allComponents.filter((component) => component.kind === options.kind)
|
|
464
|
+
: allComponents;
|
|
465
|
+
const total = filteredComponents.length;
|
|
466
|
+
const offset = Math.max(0, options.offset ?? 0);
|
|
467
|
+
const limit = Math.max(1, options.limit ?? DEFAULT_LIMIT);
|
|
468
|
+
const selectedComponents = options.index !== undefined
|
|
469
|
+
? [filteredComponents[options.index - 1]].filter(isObject)
|
|
470
|
+
: filteredComponents.slice(offset, offset + limit);
|
|
471
|
+
const hidden = options.index !== undefined ? 0 : Math.max(0, total - offset - selectedComponents.length);
|
|
472
|
+
const response = {
|
|
473
|
+
ok: true,
|
|
474
|
+
op: "cycles",
|
|
475
|
+
target: readString(artifact.target) ?? "",
|
|
476
|
+
detail,
|
|
477
|
+
componentCount: total,
|
|
478
|
+
summary: summarizeFormattedComponents(filteredComponents),
|
|
479
|
+
...(isObject(artifact.analysis) ? { analysis: artifact.analysis } : {}),
|
|
480
|
+
...(isObject(artifact.timeoutHint) ? { timeoutHint: artifact.timeoutHint } : {}),
|
|
481
|
+
components: selectedComponents,
|
|
482
|
+
offset,
|
|
483
|
+
limit,
|
|
484
|
+
...(options.index !== undefined ? { index: options.index } : {}),
|
|
485
|
+
...(hidden > 0 ? { hidden } : {}),
|
|
486
|
+
...(options.resultHandle ? { result: options.resultHandle } : {}),
|
|
487
|
+
...(artifact.paths ? { paths: artifact.paths } : {})
|
|
488
|
+
};
|
|
489
|
+
return (0, agent_text_1.attachAgentText)(response, formatCyclesResponse(response));
|
|
490
|
+
}
|
|
491
|
+
function buildCyclesAnalysis(request, fileCount, edgeCount, focusFileCount, components) {
|
|
492
|
+
const summary = summarizeComponents(components);
|
|
493
|
+
const largestComponentFileCount = components.reduce((max, component) => Math.max(max, component.nodes.length), 0);
|
|
494
|
+
const representativeEdgeCount = components.reduce((count, component) => count + component.representative.edges.length, 0);
|
|
495
|
+
return {
|
|
496
|
+
fileCount,
|
|
497
|
+
edgeCount,
|
|
498
|
+
focusFileCount,
|
|
499
|
+
scopeCount: request.scopes.length,
|
|
500
|
+
detail: request.detail,
|
|
501
|
+
componentCount: components.length,
|
|
502
|
+
largestComponentFileCount,
|
|
503
|
+
representativeEdgeCount,
|
|
504
|
+
runtimeComponentCount: summary.runtime,
|
|
505
|
+
mixedComponentCount: summary.mixed,
|
|
506
|
+
typeOnlyComponentCount: summary["type-only"]
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function buildCyclesTimeoutHint(analysis) {
|
|
510
|
+
const fileCount = readNumber(analysis.fileCount);
|
|
511
|
+
const edgeCount = readNumber(analysis.edgeCount);
|
|
512
|
+
const componentCount = readNumber(analysis.componentCount);
|
|
513
|
+
const largestComponentFileCount = readNumber(analysis.largestComponentFileCount);
|
|
514
|
+
const representativeEdgeCount = readNumber(analysis.representativeEdgeCount);
|
|
515
|
+
const detail = readString(analysis.detail) ?? "summary";
|
|
516
|
+
const recommendedTimeoutMs = estimateCyclesTimeoutMs({
|
|
517
|
+
fileCount,
|
|
518
|
+
edgeCount,
|
|
519
|
+
componentCount,
|
|
520
|
+
largestComponentFileCount,
|
|
521
|
+
representativeEdgeCount,
|
|
522
|
+
detail
|
|
523
|
+
});
|
|
524
|
+
return {
|
|
525
|
+
recommendedTimeoutMs,
|
|
526
|
+
fileCount,
|
|
527
|
+
edgeCount,
|
|
528
|
+
componentCount,
|
|
529
|
+
detail,
|
|
530
|
+
message: "If cycle analysis runs as a post-mutation phase, inspect progress with: aib execution status last"
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function estimateCyclesTimeoutMs(input) {
|
|
534
|
+
const detailCost = input.detail === "imports" ? 1.25 : input.detail === "files" ? 1.1 : 1;
|
|
535
|
+
const estimate = Math.round((750 +
|
|
536
|
+
input.fileCount * 1.5 +
|
|
537
|
+
input.edgeCount * 1.25 +
|
|
538
|
+
input.componentCount * 4 +
|
|
539
|
+
input.largestComponentFileCount * 2 +
|
|
540
|
+
input.representativeEdgeCount * 1.5) * detailCost);
|
|
541
|
+
return Math.min(CYCLES_ESTIMATE_MAX_MS, Math.max(CYCLES_ESTIMATE_MIN_MS, estimate));
|
|
542
|
+
}
|
|
543
|
+
function summarizeComponents(components) {
|
|
544
|
+
const summary = { runtime: 0, "type-only": 0, mixed: 0 };
|
|
545
|
+
for (const component of components) {
|
|
546
|
+
summary[component.kind] += 1;
|
|
547
|
+
}
|
|
548
|
+
return summary;
|
|
549
|
+
}
|
|
550
|
+
function summarizeFormattedComponents(components) {
|
|
551
|
+
const summary = { runtime: 0, "type-only": 0, mixed: 0 };
|
|
552
|
+
for (const component of components) {
|
|
553
|
+
const kind = readCycleKind(component.kind);
|
|
554
|
+
if (kind) {
|
|
555
|
+
summary[kind] += 1;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return summary;
|
|
559
|
+
}
|
|
560
|
+
function createResultId(artifact) {
|
|
561
|
+
const hash = (0, node_crypto_1.createHash)("sha256")
|
|
562
|
+
.update(JSON.stringify({
|
|
563
|
+
target: artifact.target,
|
|
564
|
+
request: artifact.request,
|
|
565
|
+
componentCount: artifact.componentCount,
|
|
566
|
+
components: artifact.components
|
|
567
|
+
}))
|
|
568
|
+
.digest("hex")
|
|
569
|
+
.slice(0, 8);
|
|
570
|
+
return `res_${hash}`;
|
|
571
|
+
}
|
|
572
|
+
function formatCyclesResponse(response) {
|
|
573
|
+
if (Array.isArray(response.results)) {
|
|
574
|
+
const chunks = response.results
|
|
575
|
+
.filter(isObject)
|
|
576
|
+
.map(formatCyclesResponse)
|
|
577
|
+
.filter((chunk) => Boolean(chunk));
|
|
578
|
+
return chunks.length > 0 ? chunks.join("\n\n") : null;
|
|
579
|
+
}
|
|
580
|
+
if (response.op !== "cycles") {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
const target = typeof response.target === "string" ? response.target : "";
|
|
584
|
+
const count = typeof response.componentCount === "number" ? response.componentCount : 0;
|
|
585
|
+
const lines = [`cycles ${target}`.trim()];
|
|
586
|
+
if (count === 0) {
|
|
587
|
+
lines.push(response.index ? "selected component not found" : "no cycles");
|
|
588
|
+
appendPaths(lines, response.paths);
|
|
589
|
+
return lines.join("\n");
|
|
590
|
+
}
|
|
591
|
+
lines.push(formatCyclesCountLine(count, response.summary), "");
|
|
592
|
+
if (!singleCycleKind(count, response.summary)) {
|
|
593
|
+
appendCycleSummary(lines, response.summary);
|
|
594
|
+
}
|
|
595
|
+
const components = Array.isArray(response.components) ? response.components.filter(isObject) : [];
|
|
596
|
+
components.forEach((component, index) => {
|
|
597
|
+
const files = readStringArray(component.files) ?? [];
|
|
598
|
+
const displayIndex = typeof response.index === "number"
|
|
599
|
+
? response.index
|
|
600
|
+
: (typeof response.offset === "number" ? response.offset : 0) + index + 1;
|
|
601
|
+
const prefix = count === 1 && components.length === 1 && !response.index ? "" : `${displayIndex}. `;
|
|
602
|
+
appendCycleComponentText(lines, component, {
|
|
603
|
+
detail: response.detail === "files" || response.detail === "imports" ? response.detail : "summary",
|
|
604
|
+
prefix,
|
|
605
|
+
indent: prefix ? " " : ""
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
if (typeof response.hidden === "number" && response.hidden > 0) {
|
|
609
|
+
lines.push(`+ ${response.hidden} more cyclic ${response.hidden === 1 ? "component" : "components"}`);
|
|
610
|
+
}
|
|
611
|
+
const resultHandle = readString(response.result);
|
|
612
|
+
if (resultHandle && typeof response.hidden === "number" && response.hidden > 0) {
|
|
613
|
+
const nextOffset = (typeof response.offset === "number" ? response.offset : 0) + components.length;
|
|
614
|
+
const limit = typeof response.limit === "number" ? response.limit : DEFAULT_LIMIT;
|
|
615
|
+
lines.push(`more: aib view ${resultHandle} --offset ${nextOffset} --limit ${limit}`);
|
|
616
|
+
}
|
|
617
|
+
appendPaths(lines, response.paths);
|
|
618
|
+
return lines.join("\n");
|
|
619
|
+
}
|
|
620
|
+
function appendCycleComponentText(lines, component, options = {}) {
|
|
621
|
+
const files = readStringArray(component.files) ?? [];
|
|
622
|
+
const kind = readCycleKind(component.kind) ?? "mixed";
|
|
623
|
+
const prefix = options.prefix ?? "";
|
|
624
|
+
const indent = options.indent ?? "";
|
|
625
|
+
lines.push(`${prefix}${kind}, ${files.length} ${files.length === 1 ? "file" : "files"}`);
|
|
626
|
+
if (options.detail === "files") {
|
|
627
|
+
for (const file of files.slice(0, TEXT_COMPONENT_FILE_LIMIT)) {
|
|
628
|
+
lines.push(`${indent}${file}`);
|
|
629
|
+
}
|
|
630
|
+
if (files.length > TEXT_COMPONENT_FILE_LIMIT) {
|
|
631
|
+
lines.push(`${indent}+ ${files.length - TEXT_COMPONENT_FILE_LIMIT} more files`);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const cycle = isObject(component.cycle) ? component.cycle : {};
|
|
635
|
+
const pathValues = readStringArray(cycle.path) ?? pathFromChain(readString(component.chain));
|
|
636
|
+
if (pathValues.length > 0) {
|
|
637
|
+
lines.push(`${indent}cycle:`);
|
|
638
|
+
appendCyclePath(lines, pathValues, indent);
|
|
639
|
+
}
|
|
640
|
+
if (options.detail === "imports") {
|
|
641
|
+
const imports = readStringArray(cycle.imports) ?? readStringArray(component.imports) ?? [];
|
|
642
|
+
if (imports.length > 0) {
|
|
643
|
+
lines.push(`${indent}imports:`);
|
|
644
|
+
for (const item of imports) {
|
|
645
|
+
lines.push(`${indent}${item}`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function formatCyclesCountLine(count, summary) {
|
|
651
|
+
const kind = singleCycleKind(count, summary);
|
|
652
|
+
if (kind) {
|
|
653
|
+
return `${count} ${kind} ${count === 1 ? "cycle" : "cycles"}`;
|
|
654
|
+
}
|
|
655
|
+
return `${count} cyclic ${count === 1 ? "component" : "components"}`;
|
|
656
|
+
}
|
|
657
|
+
function singleCycleKind(count, summary) {
|
|
658
|
+
if (!isObject(summary)) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const kinds = ["runtime", "mixed", "type-only"];
|
|
662
|
+
const matches = kinds.filter((kind) => summary[kind] === count);
|
|
663
|
+
return matches.length === 1 ? matches[0] : null;
|
|
664
|
+
}
|
|
665
|
+
function pathFromChain(chain) {
|
|
666
|
+
return chain ? chain.split(" -> ").filter((part) => part.trim().length > 0) : [];
|
|
667
|
+
}
|
|
668
|
+
function appendCyclePath(lines, pathValues, indent) {
|
|
669
|
+
if (pathValues.length > 4) {
|
|
670
|
+
lines.push(`${indent}${pathValues[0]}`);
|
|
671
|
+
for (const item of pathValues.slice(1)) {
|
|
672
|
+
lines.push(`${indent}-> ${item}`);
|
|
673
|
+
}
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
lines.push(`${indent}${pathValues.join(" -> ")}`);
|
|
677
|
+
}
|
|
678
|
+
function appendCycleSummary(lines, summary) {
|
|
679
|
+
if (!isObject(summary)) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const runtime = typeof summary.runtime === "number" ? summary.runtime : 0;
|
|
683
|
+
const mixed = typeof summary.mixed === "number" ? summary.mixed : 0;
|
|
684
|
+
const typeOnly = typeof summary["type-only"] === "number" ? summary["type-only"] : 0;
|
|
685
|
+
lines.push(`runtime ${runtime}, mixed ${mixed}, type-only ${typeOnly}`, "");
|
|
686
|
+
}
|
|
687
|
+
function appendPaths(lines, paths) {
|
|
688
|
+
if (!isObject(paths)) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const entries = Object.entries(paths)
|
|
692
|
+
.filter((entry) => typeof entry[1] === "string")
|
|
693
|
+
.sort(([left], [right]) => left.localeCompare(right));
|
|
694
|
+
if (entries.length === 0) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
lines.push("", "paths:");
|
|
698
|
+
for (const [token, prefix] of entries) {
|
|
699
|
+
lines.push(`${token} = ${prefix}`);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function formatCyclesTarget(cwd, request, aliases) {
|
|
703
|
+
const values = request.scopes.length > 0 ? request.scopes : request.files;
|
|
704
|
+
const compacted = values.map((value) => (0, path_display_1.compactDisplayPath)(cwd, value, aliases));
|
|
705
|
+
if (compacted.length === 1) {
|
|
706
|
+
return compacted[0];
|
|
707
|
+
}
|
|
708
|
+
return `[${compacted.join(",")}]`;
|
|
709
|
+
}
|
|
710
|
+
function compactGraphPath(pathValue, aliases) {
|
|
711
|
+
return (0, path_display_1.compactDisplayPath)("", pathValue, aliases);
|
|
712
|
+
}
|
|
713
|
+
function usedAliasPayload(serializedResponse, aliases) {
|
|
714
|
+
const payload = {};
|
|
715
|
+
for (const alias of aliases) {
|
|
716
|
+
if (serializedResponse.includes(alias.token)) {
|
|
717
|
+
payload[alias.token] = alias.prefix;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return Object.keys(payload).length > 0 ? payload : null;
|
|
721
|
+
}
|
|
722
|
+
function toGraphPath(cwd, filePath) {
|
|
723
|
+
return (0, path_display_1.toDisplayPath)(cwd, path.resolve(cwd, filePath));
|
|
724
|
+
}
|
|
725
|
+
function expandCyclesPayloadRequests(payload) {
|
|
726
|
+
if (!isObject(payload)) {
|
|
727
|
+
return [];
|
|
728
|
+
}
|
|
729
|
+
if (Array.isArray(payload.requests)) {
|
|
730
|
+
return payload.requests.filter(isObject);
|
|
731
|
+
}
|
|
732
|
+
return [payload];
|
|
733
|
+
}
|
|
734
|
+
function readFlagValue(args, flag) {
|
|
735
|
+
const index = args.indexOf(flag);
|
|
736
|
+
if (index < 0) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
const value = args[index + 1];
|
|
740
|
+
return value && !value.startsWith("--") ? value : null;
|
|
741
|
+
}
|
|
742
|
+
function readFlagValues(args, flag) {
|
|
743
|
+
const values = [];
|
|
744
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
745
|
+
if (args[index] !== flag) {
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
const value = args[index + 1];
|
|
749
|
+
if (value && !value.startsWith("--")) {
|
|
750
|
+
values.push(...splitList(value));
|
|
751
|
+
index += 1;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return values;
|
|
755
|
+
}
|
|
756
|
+
function isFlagValue(args, value) {
|
|
757
|
+
const index = args.indexOf(value);
|
|
758
|
+
return index > 0 && args[index - 1]?.startsWith("--") === true;
|
|
759
|
+
}
|
|
760
|
+
function readCyclesDetail(value) {
|
|
761
|
+
if (value === undefined || value === null || value === "summary" || value === "sum") {
|
|
762
|
+
return "summary";
|
|
763
|
+
}
|
|
764
|
+
if (value === "imports") {
|
|
765
|
+
return "imports";
|
|
766
|
+
}
|
|
767
|
+
if (value === "files") {
|
|
768
|
+
return "files";
|
|
769
|
+
}
|
|
770
|
+
throw new errors_1.CliError("INVALID_CYCLES_DETAIL", "inspect cycles detail expects summary, imports, or files.");
|
|
771
|
+
}
|
|
772
|
+
function readCycleKind(value) {
|
|
773
|
+
if (value === undefined || value === null || value === "") {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
if (value === "runtime" || value === "type-only" || value === "mixed") {
|
|
777
|
+
return value;
|
|
778
|
+
}
|
|
779
|
+
throw new errors_1.CliError("INVALID_CYCLES_KIND", "inspect cycles kind expects runtime, type-only, or mixed.");
|
|
780
|
+
}
|
|
781
|
+
function readPositiveInteger(value) {
|
|
782
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
783
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
|
784
|
+
}
|
|
785
|
+
function readNumber(value) {
|
|
786
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
787
|
+
}
|
|
788
|
+
function readString(value) {
|
|
789
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
790
|
+
}
|
|
791
|
+
function readNestedString(value, key) {
|
|
792
|
+
return isObject(value) ? readString(value[key]) : null;
|
|
793
|
+
}
|
|
794
|
+
function readStringArray(value) {
|
|
795
|
+
if (typeof value === "string" && value.length > 0) {
|
|
796
|
+
return splitList(value);
|
|
797
|
+
}
|
|
798
|
+
if (!Array.isArray(value)) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
return value.filter((item) => typeof item === "string" && item.length > 0);
|
|
802
|
+
}
|
|
803
|
+
function splitList(value) {
|
|
804
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
805
|
+
}
|
|
806
|
+
function uniqueSorted(items) {
|
|
807
|
+
return Array.from(new Set(items)).sort();
|
|
808
|
+
}
|
|
809
|
+
function isObject(value) {
|
|
810
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
811
|
+
}
|