@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,18 +1,1590 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
`)}function on(e,r,t){if(!l(e))return[];const n=Object.entries(e).filter(s=>typeof s[1]=="string");return r!=="summary"?n:n.filter(([s])=>t.includes(s))}function fn(e,r,t){e.push(...je(r,t))}function je(e,r){const t=[],n=typeof e.name=="string"?e.name:"",s=y(e.count),i=y(e.variants),o=y(e.exactCopies);if(r!=="summary"&&t.push(""),t.push(`${n} x${s}, ${i} ${Ke(i,"variant")}${o>0?`, exact x${o}`:""}`),r==="summary")return t;const f=Array.isArray(e.groups)?e.groups.filter(l):[];if(r==="code")return f.forEach((c,a)=>cn(t,c,a+1)),t;for(const c of f){const u=(Array.isArray(c.declarations)?c.declarations.filter(l):[]).map(p=>Fe(p,!1));t.push(...ce(u))}return t}function cn(e,r,t){const n=Array.isArray(r.declarations)?r.declarations.filter(l):[],s=y(r.count);e.push(`// variant ${t} x${s}`);const i=ce(n.map(o=>Fe(o,!1)));i.length>0&&e.push(`// ${i.join(", ")}`),typeof r.code=="string"&&e.push(r.code.trimEnd())}function Fe(e,r){const t=typeof e.file=="string"?e.file:"",n=typeof e.meta=="string"?e.meta:"",s=r&&typeof e.sameAs=="string"&&e.sameAs!==""?` same as ${e.sameAs}`:"";return[t,n].filter(i=>i!=="").join(" ")+s}function Ne(e,r,t){const n=t.filter(s=>(typeof s.summary=="string"?s.summary:"").startsWith("0 refs")).map(s=>typeof s.entity=="string"?s.entity:"").filter(s=>s!=="");if(n.length!==0){if(r.queryMode==="explicit"){e.push(`unused: ${V(n,2,"more")}`);return}r.targetMode==="file"&&e.push(`unused symbols: ${n.length}`)}}function an(e){const r=[],t=e.filter(i=>!un(i)),{ownerGroups:n,standalone:s}=ne(t);for(const[i,o]of n){r.length>0&&r.push(""),r.push(`// ${i}:`);for(const f of o)r.push(...Be(f,!1))}s.length>0&&r.length>0&&r.push("");for(const i of s)r.push(...Be(i,!0));return r}function un(e){return typeof e.referenceCount=="number"?e.referenceCount===0:(typeof e.summary=="string"?e.summary:"").startsWith("0 refs")}function Be(e,r){const t=typeof e.entity=="string"?e.entity:"",n=H(t),s=r?t:n.name,i=typeof e.declaredIn=="string"?` [${e.declaredIn}]`:"",o=typeof e.summary=="string"?e.summary:"",f=[`${s}${i}: ${o}`.trim()],c=Array.isArray(e.usedBy)?e.usedBy.filter(a=>typeof a=="string"):[];return f.push(...c),f}function ne(e){const r=new Map,t=[];for(const n of e){const s=typeof n.entity=="string"?n.entity:"",i=H(s);if(!i.owner){t.push(n);continue}const o=r.get(i.owner)??[];o.push(n),r.set(i.owner,o)}return{ownerGroups:Array.from(r.entries()),standalone:t}}function H(e){const r=e.lastIndexOf(".");return r<=0||r>=e.length-1?{owner:null,name:e}:{owner:e.slice(0,r),name:e.slice(r+1)}}function ln(e,r,t,n){const s=typeof e.code=="string"?e.code:"",i=s===""?y(e.lineCount):s.split(/\r?\n/).length,o={...S(e,t,n),entity:F(e.entity,r)},f=L(e.entity,i);if(t.includeRanges&&f&&(o.meta=f),t.toFile){const c=et(t.cwd,t.toFile,s);if(o.writtenTo=c,!t.show)return o}if(t.save){const c=tt(t.cwd,"slice",t.save,e,s);o.saved=c.saved;const a=(0,x.useSessionGuidance)(t.cwd,"inspect.slice.read",`Read saved artifact with: aib session read ${c.saved}`);if(a&&(o.next=a),!t.show)return o}return t.show||i<=t.maxCodeLines?o.code=s:(o.reason="SLICE_TOO_LARGE_FOR_STDOUT",o.lineCount=i,o.limit=t.maxCodeLines,f&&(o.rangeMeta=f)),o}function pn(e,r,t,n){const s=typeof e.code=="string"?e.code:"",i=s===""?0:s.split(/\r?\n/).length,o=re(s),f={...S(e,t,n),entity:F(e.entity,r)},c=L(e.entity,i);if(t.codeMeta!==!1&&t.includeRanges&&c&&(f.meta=c),t.toFile){const a=et(t.cwd,t.toFile,s);if(f.writtenTo=a,!t.show)return f}if(t.save){const a=tt(t.cwd,"code",t.save,e,s);f.saved=a.saved;const u=(0,x.useSessionGuidance)(t.cwd,"inspect.code.read",`Read saved artifact with: aib session read ${a.saved}`);if(u&&(f.next=u),!t.show)return f}return t.show&&(o<=t.maxCodeLines?f.code=s:(f.reason="CODE_TOO_LARGE_FOR_STDOUT",f.nonEmptyLines=o,f.limit=t.maxCodeLines,c&&(f.rangeMeta=c))),f}function re(e){return e===""?0:e.split(/\r?\n/).filter(r=>r.trim()!=="").length}function dn(e){if(typeof e!="string"||e==="")return!1;try{return U.existsSync(e)&&U.statSync(e).isFile()&&U.readFileSync(e,"utf8").trim()!==""}catch{return!1}}function S(e,r,t){const n={op:typeof e.op=="string"?e.op:"unknown"};if(typeof e.id=="string"&&(n.id=e.id),typeof e.sourceFile=="string"){const s=h(e.sourceFile,r);s!==t&&(n.file=s)}return n}function se(e,r,t,n="generic"){return Array.isArray(e)?e.filter(l).map(s=>oe(s,r,t,n)):[]}function yn(e,r,t){if(!Array.isArray(e))return[];const n=e.filter(l);if(t.includeRanges)return n.map(f=>oe(f,r,t,"exports"));const s=[],i=new Map;for(const f of n){const c=oe(f,r,t,"exports"),a=typeof f.sourceModule=="string"?f.sourceModule:"";if(!a){s.push(c);continue}const u=c.replace(` from ${a}`,""),p=i.get(a)??[];p.push(u),i.set(a,p)}if(i.size===0)return s;const o=[];s.length>0&&o.push(`local: ${s.join(", ")}`);for(const[f,c]of i.entries())o.push(`${f}: ${c.join(", ")}`);return o}function k(e,r){return Array.isArray(e)?e.filter(l).map(t=>j(t,r)).filter(t=>t!==""):[]}function gn(e,r,t){const n=Ue(e,r,t),s={};return n.type.length>0&&(s.depsType=n.type),n.value.length>0&&(s.depsValue=n.value),n.unknown.length>0&&(s.depsUnknown=n.unknown),s}function mn(e,r){const t=Ue(e,r),n={};return t.type.length>0&&(n.type=t.type),t.value.length>0&&(n.value=t.value),t.unknown.length>0&&(n.unknown=t.unknown),n}function Ue(e,r,t){if(!(Array.isArray(e.typeOnlyDependencies)||Array.isArray(e.valueDependencies)||Array.isArray(e.unclassifiedDependencies))){const f=Z(e.dependencies,r,t);return{type:[],value:[],unknown:f}}const s=Z(e.typeOnlyDependencies,r,t),i=Z(e.valueDependencies,r,t),o=Z(e.unclassifiedDependencies,r,t);return{type:s,value:i,unknown:o}}function hn(e,r,t,n){const s=e.ok===!1,i={...S(e,t,n)};if(!s){const c=Cn(e.modules,r,t);c.length>0&&(i.targets=c,i.moduleCount=c.length),t.details===!0&&(i.modules=kn(e.modules,r,t))}for(const c of["planId","executable","next"])e[c]!==void 0&&(i[c]=e[c]);if(s&&(i.ok=!1,i.code=typeof e.code=="string"?e.code:"MODULE_PLAN_BLOCKED"),l(e.api)&&(i.api=An(e.api,r)),l(e.boundary)&&(i.boundary=vn(e.boundary,r,t),s&&l(i.boundary))){const c=bn(i.boundary);c.length>0&&(i.blocking=c,delete i.boundary)}const o=Sn(i.boundary);if(o.length>0?i.warnings=o:Array.isArray(e.warnings)&&e.warnings.length>0&&(i.warnings=e.warnings.filter(c=>typeof c=="string").map(c=>tr(c,t))),l(e.facade)){const c=Tn(e.facade,t);i.facade=s?xn(c):c}const f=Bn(e);if(f&&(i.integrity=f),Array.isArray(e.cycles)&&e.cycles.length>0?i.cycles=e.cycles:i.cycles="none",!s&&l(e.preview)&&(i.preview=Dn(e.preview,t,e)),Array.isArray(e.symbolErrors)&&e.symbolErrors.length>0&&(i.ok=!1,i.symbolErrors=e.symbolErrors),s){const c=$n(i);c.length>0&&(i.affected=c),i.next||(i.next="Revise the plan, then rerun modulePlan preview.")}return i}function An(e,r){const t={};typeof e.status=="string"&&(t.status=e.status),typeof e.before=="number"&&(t.before=e.before),typeof e.after=="number"&&(t.after=e.after);const n=k(e.removed,r),s=k(e.added,r);return n.length>0&&(t.removed=n),s.length>0&&(t.added=s),t}function vn(e,r,t){const s=(Array.isArray(e.nonExportedImports)?e.nonExportedImports:[]).filter(l).map(i=>{const o={code:typeof i.code=="string"?i.code:"MODULE_PLAN_BOUNDARY_WARNING",from:typeof i.importerFile=="string"?h(i.importerFile,t):"",source:typeof i.sourceFile=="string"?h(i.sourceFile,t):"",usage:typeof i.usageKind=="string"?i.usageKind:"unknown",symbols:k(i.symbols,r)},f=Ge(i.suggestedFixes,r,t);return f.length>0&&(o.suggestedFixes=f),typeof i.hint=="string"&&(o.hint=i.hint),o}).filter(i=>Array.isArray(i.symbols)&&i.symbols.length>0);return s.length>0?{nonExportedImports:s}:{}}function Ge(e,r,t){return Array.isArray(e)?e.filter(l).map(n=>{const s={kind:typeof n.kind=="string"?n.kind:"unknown"},i=j(n.symbol,r);if(i&&(s.symbol=i),typeof n.toFile=="string"&&(s.to=h(n.toFile,t)),typeof n.fromFile=="string"&&(s.from=h(n.fromFile,t)),typeof n.risk=="string"&&(s.risk=n.risk),typeof n.warning=="string"&&(s.warning=n.warning),l(n.saferAlternative)){const f=Ge([n.saferAlternative],r,t)[0];f&&(s.saferAlternative=f)}return s}).filter(n=>typeof n.symbol=="string"):[]}function bn(e){return(Array.isArray(e.nonExportedImports)?e.nonExportedImports.filter(l):[]).map(t=>{const n={code:t.code??"MODULE_PLAN_BOUNDARY_WARNING",from:t.from??"",source:t.source??"",usage:t.usage??"unknown",symbols:Array.isArray(t.symbols)?t.symbols:[]};return Array.isArray(t.suggestedFixes)&&t.suggestedFixes.length>0&&(n.suggestedFixes=t.suggestedFixes),typeof t.hint=="string"&&(n.hint=t.hint),n})}function xn(e){const r={};return typeof e.file=="string"&&(r.file=e.file),Array.isArray(e.exports)&&(r.exports=e.exports.length),r}function $n(e){const r=new Set,t=Array.isArray(e.blocking)?e.blocking.filter(l):[];for(const n of t)typeof n.from=="string"&&n.from&&r.add(n.from),typeof n.source=="string"&&n.source&&r.add(n.source);return Array.from(r)}function Sn(e){return!l(e)||!Array.isArray(e.nonExportedImports)?[]:e.nonExportedImports.filter(l).map(r=>{const t=typeof r.from=="string"?r.from:"",n=typeof r.source=="string"?r.source:"",s=Array.isArray(r.symbols)?r.symbols.filter(i=>typeof i=="string"):[];return t&&n&&s.length>0?`${t} imports non-exported ${s.join(", ")} from ${n}`:""}).filter(r=>r!=="")}function kn(e,r,t){if(!Array.isArray(e))return{};const n={};for(const s of e){if(!l(s)||typeof s.targetFile!="string")continue;const i=h(s.targetFile,t),o={owns:k(s.symbols,r)},f=_n(s.imports,r,t);Object.keys(f).length>0&&(o.uses=f);const c=k(s.internalDependencies,r);c.length>0&&(o.internalDeps=c);const a=Pn(s.unassignedDependencies,r);Object.keys(a).length>0&&(o.unassigned=a),n[i]=o}return n}function Cn(e,r,t){return Array.isArray(e)?e.filter(l).filter(n=>typeof n.targetFile=="string").map(n=>{const s={file:h(String(n.targetFile),t),summary:On(n,r,t)},i=En(n.unassignedDependencies);return i!==""&&(s.warning=`unassigned ${i}`),s}):[]}function On(e,r,t){const n=He(e.symbols,r,!0),s=He(e.symbols,r,!1),i=In(e.imports,r,t),o=k(e.internalDependencies,r).length,f=[`exports ${V(n,4)||"none"}`];return s.length>0&&f.push(`private ${V(s,3)}`),i!==""&&f.push(`imports ${i}`),o>0&&f.push(`internalDeps ${o}`),f.join("; ")}function He(e,r,t){return Array.isArray(e)?e.filter(l).filter(n=>n.exported===!0===t).map(n=>j(n,r)).filter(n=>n!==""):[]}function In(e,r,t){if(!l(e))return"";const n=[],s={typeOnly:"type",value:"run",unclassified:"unclassified"};for(const i of["typeOnly","value","unclassified"]){const o=Mn(e[i],r,t);o!==""&&n.push(`${s[i]} ${o}`)}return n.join("; ")}function Mn(e,r,t){if(!Array.isArray(e))return"";const n=e.filter(l).filter(s=>typeof s.targetFile=="string").map(s=>{const i=h(String(s.targetFile),t),o=k(s.symbols,r).filter(f=>typeof f=="string");return`${i}: ${V(o,3)||"none"}`});return V(n,2,"more imports")}function En(e){if(!l(e))return"";const r=[];for(const t of["typeOnly","value","unclassified"]){const n=e[t];Array.isArray(n)&&n.length>0&&r.push(`${t} ${n.length}`)}return r.join("; ")}function V(e,r,t="more"){if(e.length===0)return"";const n=e.slice(0,r),s=e.length-n.length;return s>0?`${n.join(", ")}, +${s} ${t}`:n.join(", ")}function _n(e,r,t){if(!l(e))return{};const n={},s={typeOnly:"type",value:"run",unclassified:"unclassified"};for(const i of["typeOnly","value","unclassified"]){const o=Ln(e[i],r,t);Object.keys(o).length>0&&(n[s[i]]=o)}return n}function Ln(e,r,t){if(!Array.isArray(e))return{};const n={};for(const s of e)!l(s)||typeof s.targetFile!="string"||(n[h(s.targetFile,t)]=k(s.symbols,r));return n}function Pn(e,r){if(!l(e))return{};const t={};for(const n of["typeOnly","value","unclassified"]){const s=k(e[n],r);s.length>0&&(t[n]=s)}return t}function Tn(e,r){const t={};return typeof e.file=="string"&&(t.file=h(e.file,r)),Array.isArray(e.exports)&&e.exports.length>0&&(t.exports=e.exports.filter(n=>typeof n=="string").map(n=>n.match(/from\s+"([^"]+)"/)?.[1]??n)),t}function Dn(e,r,t){const n={};typeof e.dir=="string"&&(n.dir=h(e.dir,r));const s=[];let i=0,o=0,f=0;if(Array.isArray(e.files)){const a={};for(const u of e.files){if(!l(u)||typeof u.targetFile!="string"||typeof u.previewFile!="string")continue;i+=1;const p=h(u.targetFile,r),d=y(u.lineCount);a[h(u.targetFile,r)]={file:h(u.previewFile,r),lines:d},d>=pt&&s.push(`${p} ${d}l`)}Object.keys(a).length>0&&(n.files=a)}l(e.facade)&&typeof e.facade.previewFile=="string"&&(o=y(e.facade.lineCount),n.facade={file:h(e.facade.previewFile,r),lines:o}),l(e.patch)&&typeof e.patch.file=="string"&&(f=y(e.patch.lineCount),n.patch={file:h(e.patch.file,r),lines:f},f>=dt&&s.push(`patch ${f}l`)),n.summary=jn(i,o,f,t),s.length>0&&(n.large=s);const c=Fn(t);return c.length>0&&(n.warnings=c),n.next=Nn(t,s.length>0),n}function jn(e,r,t,n){const s=[`${e} ${e===1?"file":"files"}`];return r>0&&s.push(`facade ${r}l`),t>0&&s.push(`patch ${t}l`),s.push(ie(n)?"cycles detected":"cycles none"),s.join("; ")}function Fn(e){return ie(e)?["runtime cycles detected"]:[]}function Nn(e,r){return ie(e)?["fix module plan before applying","rerun modulePlan"]:[r?"check summary/api/cycles/imports before reading large preview artifacts":"check summary/api/cycles/imports","read targeted preview artifacts only if a warning/check points there","use top-level next for apply/revise action"]}function ie(e){return Array.isArray(e.cycles)&&e.cycles.length>0}function Bn(e){const r=Array.isArray(e.modules)?e.modules.filter(l):[];if(r.length===0)return"";const t=r.reduce((o,f)=>o+(Array.isArray(f.symbols)?f.symbols.length:0),0),n=r.reduce((o,f)=>o+Un(f.imports),0),s=l(e.facade)&&Array.isArray(e.facade.exports)?e.facade.exports.length:0,i=[`${t} declarations moved unchanged`,`${n} imports generated`];return s>0&&i.push(`facade exports ${s}`),i.join("; ")}function Un(e){if(!l(e))return 0;let r=0;for(const t of["typeOnly","value","unclassified"]){const n=e[t];if(Array.isArray(n))for(const s of n)l(s)&&Array.isArray(s.symbols)&&(r+=s.symbols.length)}return r}function Z(e,r,t){return k(e,r)}function Gn(e,r,t){const n=y(e.memberCount),s=y(e.memberOffset),i=y(e.memberLimit),o=y(e.hiddenMemberCount),f=se(e.members,r,t,"members"),c=f.length;o>0&&f.push(`+ ${o} hidden members`);const a={members:f};return o>0?(a.count=n,a.page=`${s}..${s+c-1} of ${n}`,a.hint="Use --all to list all members, --offset <n> --limit <n> to page, or inspect code <member> --parent <entity>."):n>q&&(a.count=n),s>0&&o===0&&(a.page=`${s}..${s+f.length-1} of ${n}`),a}function Hn(e){const r=y(e.localDeclarationCount),t=Ve(e.reexports);return r===0&&t.length>0?`facade only; ${t.length} ${t.length===1?"re-export":"re-exports"}; 0 local declarations`:r===0?"0 local declarations":`${r} local ${r===1?"declaration":"declarations"}; ${t.length} ${t.length===1?"re-export":"re-exports"}`}function Ve(e){return Array.isArray(e)?e.filter(l).map(r=>typeof r.module=="string"?r.module:"").filter(r=>r!==""):[]}function oe(e,r,t,n){const s=j(e,r),i=typeof e.signature=="string"?e.signature:"",o=t.includeRanges?L(e):"",f=typeof e.sourceModule=="string"?`from ${e.sourceModule}`:"";return n==="file"||n==="exports"?Vn(e,s,i,o,f,n):n==="members"?Wn(e,s,i,o):s==="constructor"?[o,f,i||s].filter(a=>a!=="").join(" "):[s,o,f,i].filter(a=>a!=="").join(" ")}function Vn(e,r,t,n,s,i){const o=i==="file"&&e.exported===!0?"export ":"",f=qn(e,t);return[`${o}${r}${f}`,n,s].filter(a=>a!=="").join(" ")}function qn(e,r){const t=typeof e.name=="string"?e.name:"",n=typeof e.kind=="string"?le(e.kind):null;if(!t||!r||n!=="function"&&n!=="method")return"";const s=r.indexOf(t);if(s<0)return"";const i=r.slice(s+t.length).trim();return i.startsWith("(")?i:""}function Wn(e,r,t,n){const s=typeof e.kind=="string"?le(e.kind):null,i=typeof e.name=="string"?e.name:"";let o=t||qe(r);if(s==="property"&&i){o=r;const f=Kn(t,i);f&&(o+=f)}return[o,n].filter(f=>f!=="").join(" ")}function Kn(e,r){if(!e)return"";const t=e.indexOf(r);if(t<0)return"";const n=e.slice(t+r.length).trim();return n.startsWith(":")?n:""}function zn(e,r,t){const n=Rn(e,["id","op","ok","code","error"]);if(typeof e.sourceFile=="string"){const s=h(e.sourceFile,r);s!==t&&(n.file=s)}if(e.code==="INSPECT_SYMBOL_NOT_FOUND"){const s=Jn(e);s&&(n.missingSymbols=[s])}return n}function D(e){return e.code==="INSPECT_SYMBOL_NOT_FOUND"&&E(e).length>0}function E(e){return Array.isArray(e.missingSymbols)?e.missingSymbols.filter(r=>typeof r=="string"&&r.length>0):[]}function Jn(e){const r=typeof e.error=="string"?e.error:"",t="Symbol not found:";if(!r.startsWith(t))return null;const n=r.slice(t.length).trim();if(!n)return null;const s=n.indexOf(":");return s>0?n.slice(s+1).trim():n}function j(e,r){if(!l(e))return"";const t=typeof e.name=="string"?e.name:"",n=typeof e.kind=="string"?le(e.kind):null;return t?n==="constructor"?"constructor":n?`${Qn(n,r)}${wn(n,r)}${t}`:t:""}function F(e,r){return fe(e)||j(e,r)}function X(e){if(!l(e))return"";const r=Array.isArray(e.path)?e.path.filter(t=>typeof t=="string"&&t.trim()!==""):[];return r.length>0?r.join("."):fe(e)}function fe(e){return l(e)&&typeof e.name=="string"?e.name:""}function qe(e){const r=e.indexOf("-");if(r>0&&r<=3)return e.slice(r+1);const t=e.indexOf(":");return t>0?e.slice(t+1):e}function We(e,r){return r>q?{[e]:r}:{}}function Ke(e,r){return e===1?r:`${r}s`}function ze(e,r){return e.localeCompare(r,void 0,{numeric:!0})}function Yn(e,r,t){const n=new Set(r?[r]:[]);for(const s of e){typeof s.declaredIn=="string"&&n.add(h(s.declaredIn,t));const i=Array.isArray(s.usedBy)?s.usedBy.filter(l):[];for(const o of i)typeof o.file=="string"&&n.add(h(o.file,t))}return Array.from(n)}function Je(e,r,t){const n=new Set(r);for(const s of e){const i=Array.isArray(s.variants)?s.variants.filter(l):[];for(const o of i){const f=Array.isArray(o.declarations)?o.declarations.filter(l):[];for(const c of f){typeof c.file=="string"&&n.add(h(c.file,t));const a=l(c.sameAs)?c.sameAs:null;a&&typeof a.file=="string"&&n.add(h(a.file,t))}}}return Array.from(n)}function Zn(e){const r=Xe(e.map(t=>t.replace(/\\/g,"/")));return Ze(r)}function Ye(e,r){const t=e.map(s=>s.replace(/\\/g,"/")),n=Xe(t);for(const s of r.map(i=>ae(i)).filter(i=>i.includes("/"))){const i=`<${$.basename(s)}>`;n.some(o=>o.token===i||o.prefix===s)||t.some(o=>o===s||o.startsWith(`${s}/`))&&n.push({token:i,prefix:s})}return n.sort((s,i)=>i.prefix.length-s.prefix.length),Ze(n)}function Ze(e){return{aliases:e,compactPath(r){const t=ae(r),n=e.find(s=>t===s.prefix||t.startsWith(`${s.prefix}/`));return n?t===n.prefix?n.token:`${n.token}/${t.slice(n.prefix.length+1)}`:t}}}function Xe(e){const r=new Map;for(const n of e){const s=ae(n).split("/");for(let i=2;i<s.length;i+=1){const o=s.slice(0,i).join("/");o.length>=8&&r.set(o,(r.get(o)??0)+1)}}const t=new Set;return Array.from(r.entries()).map(([n,s])=>{const i=`<${$.basename(n)}>`;return{prefix:n,count:s,token:i,score:Math.max(0,n.length-i.length)*s}}).filter(n=>n.count>=2&&n.score>=12).sort((n,s)=>s.score-n.score||n.prefix.localeCompare(s.prefix)).filter(n=>t.has(n.token)?!1:(t.add(n.token),!0)).slice(0,6).sort((n,s)=>s.prefix.length-n.prefix.length).map(n=>({token:n.token,prefix:n.prefix}))}function Qe(e,r){if(e.aliases.length===0)return null;const t=JSON.stringify(r),n={};for(const s of e.aliases)t.includes(s.token)&&(n[s.token]=s.prefix);return Object.keys(n).length>0?n:null}function ce(e){const r=new Map,t=[];for(const n of e){const s=n.startsWith("<")?n.indexOf(">"):-1;if(s<=0){t.push(n);continue}const i=n.indexOf("/",s);if(i<0){t.push(n);continue}const o=n.slice(0,i),f=n.slice(i+1),c=r.get(o)??[];c.push(f),r.set(o,c)}return[...Array.from(r.entries()).map(([n,s])=>s.length===1?`${n}/${s[0]}`:`${n}/: ${s.join(", ")}`),...t].sort()}function ae(e){return e.replace(/\\/g,"/")}function ue(e,r,t){const n=e.indexOf(r);if(n<=0)return null;const s=e.slice(0,n).trim(),i=e.slice(n+r.length).trim();if(!s||!i)return null;const o=Xn(s,t);return o?{raw:e,symbolName:i,symbolKind:o}:null}function Xn(e,r){const t=e.toLowerCase();return we(t)?t:Object.entries(r.entityKindAliases).find(([,s])=>s===e)?.[0]??null}function Qn(e,r){return Re(e)?r.entityKindAliases[e]:e}function wn(e,r){return Re(e)?r.selectorSeparator:":"}function le(e){const r=e.toLowerCase();return we(r)?r:null}function we(e){return lt.includes(e)}function Re(e){return ft.ENTITY_KIND_IDS.includes(e)}function Rn(e,r){const t={};for(const n of r)e[n]!==void 0&&(t[n]=e[n]);return t}function er(e,r){const t=e.filter(l).map(s=>typeof s.sourceFile=="string"?h(s.sourceFile,r):null).filter(s=>!!s),n=Array.from(new Set(t));return n.length===1?n[0]??null:null}function h(e,r){const t=$.isAbsolute(e)?e:$.resolve(r.cwd,e),n=$.relative(r.cwd,t),i=(n&&!n.startsWith("..")&&!$.isAbsolute(n)?n:e).replace(/\\/g,"/"),o=(0,ut.compactDisplayPathWithMatch)(r.cwd,t,r.displayPathAliases??[]);return o.alias&&r.pathAliasHints&&(r.pathAliasHints.some(c=>c.alias===o.alias.token&&c.original===i&&c.display===o.displayPath)||r.pathAliasHints.push({alias:o.alias.token,original:i,display:o.displayPath})),o.displayPath}function tr(e,r){const t=$.resolve(r.cwd),n=t.replace(/\\/g,"/");return e.replaceAll(`${t}\\`,"").replaceAll(`${n}/`,"").replace(/\\/g,"/")}function et(e,r,t){const n=$.isAbsolute(r)?r:$.resolve(e,r);return U.mkdirSync($.dirname(n),{recursive:!0}),U.writeFileSync(n,t,"utf8"),$.relative(e,n).replace(/\\/g,"/")}function tt(e,r,t,n,s){const i=typeof n.sourceFile=="string"&&$.extname(n.sourceFile)||".ts",o=(0,x.saveSessionOutputText)(e,r,t,s,i);return{saved:o.saved,last:o.last}}function L(e,r){if(!l(e)||!l(e.range))return"";const t=nt(e.range,"start"),n=nt(e.range,"end");if(!t||!n)return"";const s=t.line+1,i=n.line+1;return`@${s}..${i}`}function nt(e,r){const t=e[r];return!l(t)||typeof t.line!="number"?null:{line:t.line}}function y(e){return typeof e=="number"?e:0}function l(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}
|
|
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.parseInspectSelector = void 0;
|
|
37
|
+
exports.formatInspectResponse = formatInspectResponse;
|
|
38
|
+
exports.formatInspectMixedAgentText = formatInspectMixedAgentText;
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const node_crypto_1 = require("node:crypto");
|
|
42
|
+
const session_workspace_1 = require("./session-workspace");
|
|
43
|
+
const agent_text_1 = require("../shared/agent-text");
|
|
44
|
+
const inspect_graph_1 = require("./inspect-graph");
|
|
45
|
+
const inspect_imports_1 = require("./inspect-imports");
|
|
46
|
+
const inspect_tree_1 = require("./inspect-tree");
|
|
47
|
+
const inspect_cycles_1 = require("./inspect-cycles");
|
|
48
|
+
const inspect_alias_candidates_1 = require("./inspect-alias-candidates");
|
|
49
|
+
const inspect_format_primitives_1 = require("./inspect-format-primitives");
|
|
50
|
+
const inspect_module_plan_format_1 = require("./inspect-module-plan-format");
|
|
51
|
+
const inspect_module_plan_serialization_1 = require("./inspect-module-plan-serialization");
|
|
52
|
+
const inspect_reference_path_format_1 = require("./inspect-reference-path-format");
|
|
53
|
+
const inspect_usages_format_1 = require("./inspect-usages-format");
|
|
54
|
+
const inspect_symbol_format_1 = require("./inspect-symbol-format");
|
|
55
|
+
const inspect_duplicates_format_1 = require("./inspect-duplicates-format");
|
|
56
|
+
const inspect_mixed_format_1 = require("./inspect-mixed-format");
|
|
57
|
+
var inspect_selector_1 = require("./inspect-selector");
|
|
58
|
+
Object.defineProperty(exports, "parseInspectSelector", { enumerable: true, get: function () { return inspect_selector_1.parseInspectSelector; } });
|
|
59
|
+
const INSPECT_COUNT_VISIBLE_THRESHOLD = 10;
|
|
60
|
+
function formatInspectResponse(payload, config, options) {
|
|
61
|
+
const rawResults = Array.isArray(payload.results) ? payload.results : [];
|
|
62
|
+
const formatOptions = withSharedInspectSaves(options);
|
|
63
|
+
const commonFile = commonSourceFile(rawResults, options);
|
|
64
|
+
const results = rawResults.map((result, index) => formatInspectResult(result, config, inspectResultOptions(formatOptions, index), commonFile));
|
|
65
|
+
attachCodeOmittedViewHandles(rawResults, results, formatOptions, commonFile);
|
|
66
|
+
attachMembersViewHandles(rawResults, results, formatOptions, config, commonFile);
|
|
67
|
+
attachDuplicatesViewHandles(rawResults, results, formatOptions, config);
|
|
68
|
+
const failedCount = results.filter((result) => (0, inspect_format_primitives_1.isObject)(result) && result.ok === false).length;
|
|
69
|
+
if (formatOptions.bundleSave) {
|
|
70
|
+
return formatInspectBundleResponse(rawResults, results, config, formatOptions, commonFile, failedCount);
|
|
71
|
+
}
|
|
72
|
+
const compact = failedCount === 0 && formatOptions.forceResults !== true
|
|
73
|
+
? compactSuccessfulInspectResponse(rawResults, results, config, commonFile, formatOptions)
|
|
74
|
+
: null;
|
|
75
|
+
if (compact) {
|
|
76
|
+
normalizeFormattedInspectLists(compact);
|
|
77
|
+
return (0, agent_text_1.attachAgentText)(compact, formatInspectAgentText(rawResults, compact, formatOptions, commonFile));
|
|
78
|
+
}
|
|
79
|
+
const response = {
|
|
80
|
+
results
|
|
81
|
+
};
|
|
82
|
+
if (commonFile) {
|
|
83
|
+
response.file = commonFile;
|
|
84
|
+
}
|
|
85
|
+
if (failedCount > 0 || payload.ok === false) {
|
|
86
|
+
response.ok = false;
|
|
87
|
+
response.summary = {
|
|
88
|
+
requestCount: results.length,
|
|
89
|
+
failedCount
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
normalizeFormattedInspectLists(response);
|
|
93
|
+
return (0, agent_text_1.attachAgentText)(response, formatInspectAgentText(rawResults, response, formatOptions, commonFile));
|
|
94
|
+
}
|
|
95
|
+
function normalizeFormattedInspectLists(value) {
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
for (const item of value) {
|
|
98
|
+
normalizeFormattedInspectLists(item);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!(0, inspect_format_primitives_1.isObject)(value)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const field of ["symbols", "exports", "members"]) {
|
|
106
|
+
normalizeTextArrayField(value, field);
|
|
107
|
+
}
|
|
108
|
+
for (const nested of Object.values(value)) {
|
|
109
|
+
normalizeFormattedInspectLists(nested);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function attachMembersViewHandles(rawResults, results, options, config, commonFile) {
|
|
113
|
+
for (let index = 0; index < results.length; index += 1) {
|
|
114
|
+
const raw = rawResults[index];
|
|
115
|
+
const result = results[index];
|
|
116
|
+
if (!(0, inspect_format_primitives_1.isObject)(raw) || !result || raw.op !== "members" || (0, inspect_format_primitives_1.numberOrZero)(raw.hiddenMemberCount) <= 0) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const hiddenMembers = formatSymbolsArray(raw.hiddenMembers, config, inspectResultOptions(options, index), "members")
|
|
120
|
+
.filter((item) => typeof item === "string" && item !== "");
|
|
121
|
+
if (hiddenMembers.length === 0) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const file = typeof result.file === "string" ? result.file : commonFile ?? "";
|
|
125
|
+
const entity = typeof result.entity === "string" ? result.entity : (0, inspect_symbol_format_1.formatEntityReference)(raw.entity, config);
|
|
126
|
+
const record = compactViewObject({
|
|
127
|
+
version: 1,
|
|
128
|
+
kind: "members",
|
|
129
|
+
source: "inspect",
|
|
130
|
+
file,
|
|
131
|
+
entity,
|
|
132
|
+
items: hiddenMembers.map((member) => compactViewObject({ text: member }))
|
|
133
|
+
});
|
|
134
|
+
const saved = (0, session_workspace_1.saveSessionResultViewJson)(options.cwd, createShortResultId(record), record);
|
|
135
|
+
if (saved) {
|
|
136
|
+
result.view = saved.saved;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function attachDuplicatesViewHandles(rawResults, results, options, config) {
|
|
141
|
+
for (let index = 0; index < results.length; index += 1) {
|
|
142
|
+
const raw = rawResults[index];
|
|
143
|
+
const result = results[index];
|
|
144
|
+
if (!(0, inspect_format_primitives_1.isObject)(raw) || !result || raw.op !== "duplicates" || (0, inspect_format_primitives_1.numberOrZero)(raw.hiddenItemCount) <= 0) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const hiddenItems = Array.isArray(raw.hiddenDuplicateItems)
|
|
148
|
+
? raw.hiddenDuplicateItems.filter(inspect_format_primitives_1.isObject)
|
|
149
|
+
: Array.isArray(raw.hiddenItems)
|
|
150
|
+
? raw.hiddenItems.filter(inspect_format_primitives_1.isObject)
|
|
151
|
+
: [];
|
|
152
|
+
if (hiddenItems.length === 0) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const formatter = (0, inspect_reference_path_format_1.createDuplicatePathFormatter)();
|
|
156
|
+
const detail = typeof raw.detail === "string" ? raw.detail : "locations";
|
|
157
|
+
const items = hiddenItems.map((item) => {
|
|
158
|
+
const formatted = (0, inspect_duplicates_format_1.formatDuplicateItem)(item, config, inspectResultOptions(options, index), formatter);
|
|
159
|
+
return compactViewObject({
|
|
160
|
+
name: typeof formatted.name === "string" ? formatted.name : "",
|
|
161
|
+
text: (0, inspect_duplicates_format_1.formatDuplicateItemTextBlock)(formatted, detail).join("\n").trim()
|
|
162
|
+
});
|
|
163
|
+
}).filter((item) => typeof item.text === "string" && item.text !== "");
|
|
164
|
+
if (items.length === 0) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const record = compactViewObject({
|
|
168
|
+
version: 1,
|
|
169
|
+
kind: "duplicates",
|
|
170
|
+
source: "inspect",
|
|
171
|
+
detail,
|
|
172
|
+
target: typeof result.target === "string" ? result.target : "",
|
|
173
|
+
items
|
|
174
|
+
});
|
|
175
|
+
const saved = (0, session_workspace_1.saveSessionResultViewJson)(options.cwd, createShortResultId(record), record);
|
|
176
|
+
if (saved) {
|
|
177
|
+
result.view = saved.saved;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function inspectResultOptions(options, index) {
|
|
182
|
+
const indexedToFile = options.toFiles?.[index];
|
|
183
|
+
const indexedSave = options.saves?.[index];
|
|
184
|
+
const indexedShow = options.shows?.[index];
|
|
185
|
+
const indexedRanges = options.ranges?.[index];
|
|
186
|
+
const indexedParentName = options.parentNames?.[index];
|
|
187
|
+
if (indexedToFile === undefined && indexedSave === undefined && indexedShow === undefined && indexedRanges === undefined && indexedParentName === undefined) {
|
|
188
|
+
return options;
|
|
189
|
+
}
|
|
190
|
+
const resultOptions = {
|
|
191
|
+
...options
|
|
192
|
+
};
|
|
193
|
+
delete resultOptions.toFiles;
|
|
194
|
+
delete resultOptions.toFile;
|
|
195
|
+
delete resultOptions.saves;
|
|
196
|
+
delete resultOptions.save;
|
|
197
|
+
delete resultOptions.shows;
|
|
198
|
+
delete resultOptions.ranges;
|
|
199
|
+
delete resultOptions.parentNames;
|
|
200
|
+
delete resultOptions.parentName;
|
|
201
|
+
if (indexedToFile) {
|
|
202
|
+
resultOptions.toFile = indexedToFile;
|
|
203
|
+
}
|
|
204
|
+
if (indexedSave && !options.sharedSaves?.has(indexedSave)) {
|
|
205
|
+
resultOptions.save = indexedSave;
|
|
206
|
+
}
|
|
207
|
+
if (indexedShow !== undefined) {
|
|
208
|
+
resultOptions.show = indexedShow;
|
|
209
|
+
}
|
|
210
|
+
if (indexedRanges !== undefined) {
|
|
211
|
+
resultOptions.includeRanges = indexedRanges;
|
|
212
|
+
}
|
|
213
|
+
if (indexedParentName) {
|
|
214
|
+
resultOptions.parentName = indexedParentName;
|
|
215
|
+
}
|
|
216
|
+
return resultOptions;
|
|
217
|
+
}
|
|
218
|
+
function withSharedInspectSaves(options) {
|
|
219
|
+
if (!options.saves || options.saves.length < 2) {
|
|
220
|
+
return options;
|
|
221
|
+
}
|
|
222
|
+
const counts = new Map();
|
|
223
|
+
for (const save of options.saves) {
|
|
224
|
+
if (!save) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
counts.set(save, (counts.get(save) ?? 0) + 1);
|
|
228
|
+
}
|
|
229
|
+
const sharedSaves = new Set(Array.from(counts.entries())
|
|
230
|
+
.filter(([, count]) => count > 1)
|
|
231
|
+
.map(([save]) => save));
|
|
232
|
+
return sharedSaves.size > 0
|
|
233
|
+
? { ...options, sharedSaves }
|
|
234
|
+
: options;
|
|
235
|
+
}
|
|
236
|
+
function formatInspectBundleResponse(rawResults, savedResults, config, options, commonFile, failedCount) {
|
|
237
|
+
const bundleSave = options.bundleSave;
|
|
238
|
+
if (!bundleSave) {
|
|
239
|
+
throw new Error("bundleSave is required for inspect bundle output.");
|
|
240
|
+
}
|
|
241
|
+
const bundleOptions = {
|
|
242
|
+
...options,
|
|
243
|
+
maxCodeLines: Number.MAX_SAFE_INTEGER
|
|
244
|
+
};
|
|
245
|
+
delete bundleOptions.toFile;
|
|
246
|
+
delete bundleOptions.toFiles;
|
|
247
|
+
delete bundleOptions.save;
|
|
248
|
+
delete bundleOptions.saves;
|
|
249
|
+
delete bundleOptions.bundleSave;
|
|
250
|
+
const items = rawResults.map((rawResult, index) => {
|
|
251
|
+
const item = formatInspectResult(rawResult, config, bundleOptions, commonFile);
|
|
252
|
+
const saved = savedResults[index]?.saved;
|
|
253
|
+
if (typeof saved === "string") {
|
|
254
|
+
item.saved = saved;
|
|
255
|
+
}
|
|
256
|
+
delete item.next;
|
|
257
|
+
delete item.last;
|
|
258
|
+
return item;
|
|
259
|
+
});
|
|
260
|
+
const content = compactInspectBundleContent(items, commonFile);
|
|
261
|
+
const saved = (0, session_workspace_1.saveSessionOutputJson)(options.cwd, "inspect", bundleSave, content);
|
|
262
|
+
const response = {
|
|
263
|
+
saved: saved.saved,
|
|
264
|
+
last: saved.last,
|
|
265
|
+
items: items.length
|
|
266
|
+
};
|
|
267
|
+
const savedRows = savedResults
|
|
268
|
+
.map((result) => typeof result.saved === "string" ? result.saved : "")
|
|
269
|
+
.filter((item) => item !== "");
|
|
270
|
+
if (savedRows.length > 0) {
|
|
271
|
+
response.savedRows = savedRows;
|
|
272
|
+
}
|
|
273
|
+
if (failedCount > 0) {
|
|
274
|
+
response.ok = false;
|
|
275
|
+
response.summary = {
|
|
276
|
+
requestCount: items.length,
|
|
277
|
+
failedCount
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const next = (0, session_workspace_1.useSessionGuidance)(options.cwd, "inspect.bundle.read", `Read bundle with: aib session read ${saved.saved}`);
|
|
281
|
+
if (next) {
|
|
282
|
+
response.next = next;
|
|
283
|
+
}
|
|
284
|
+
return response;
|
|
285
|
+
}
|
|
286
|
+
function compactInspectBundleContent(items, commonFile) {
|
|
287
|
+
const content = {
|
|
288
|
+
source: "inspect.bundle"
|
|
289
|
+
};
|
|
290
|
+
if (commonFile) {
|
|
291
|
+
content.file = commonFile;
|
|
292
|
+
}
|
|
293
|
+
const compactedItems = items.map((item) => ({ ...item }));
|
|
294
|
+
const commonOp = commonStringField(compactedItems, "op");
|
|
295
|
+
const commonParent = commonStringField(compactedItems, "parent");
|
|
296
|
+
if (commonOp) {
|
|
297
|
+
content.op = commonOp;
|
|
298
|
+
removeField(compactedItems, "op");
|
|
299
|
+
}
|
|
300
|
+
if (commonParent) {
|
|
301
|
+
content.parent = commonParent;
|
|
302
|
+
removeField(compactedItems, "parent");
|
|
303
|
+
}
|
|
304
|
+
if (commonFile) {
|
|
305
|
+
removeField(compactedItems, "file");
|
|
306
|
+
}
|
|
307
|
+
content.items = compactedItems;
|
|
308
|
+
return content;
|
|
309
|
+
}
|
|
310
|
+
function commonStringField(items, field) {
|
|
311
|
+
const values = items.map((item) => item[field]).filter((value) => typeof value === "string" && value !== "");
|
|
312
|
+
if (values.length !== items.length || values.length === 0) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
const [first] = values;
|
|
316
|
+
return values.every((value) => value === first) ? first ?? null : null;
|
|
317
|
+
}
|
|
318
|
+
function removeField(items, field) {
|
|
319
|
+
for (const item of items) {
|
|
320
|
+
delete item[field];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function compactSuccessfulInspectResponse(rawResults, results, config, commonFile, options) {
|
|
324
|
+
if (rawResults.length === 0 || results.length === 0) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
const objectResults = rawResults.filter(inspect_format_primitives_1.isObject);
|
|
328
|
+
if (objectResults.length !== rawResults.length || objectResults.some((result) => result.ok === false)) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
const ops = Array.from(new Set(objectResults.map((result) => typeof result.op === "string" ? result.op : "")));
|
|
332
|
+
if (ops.length !== 1) {
|
|
333
|
+
return {
|
|
334
|
+
results: results.map((result) => compactInspectItem(result, { omitOp: false, commonFile }))
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const op = ops[0];
|
|
338
|
+
if (op === "modulePlan") {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
if (op === "usages") {
|
|
342
|
+
return rawResults.length === 1
|
|
343
|
+
? compactInspectItem(results[0], { omitOp: true, omitFile: true })
|
|
344
|
+
: {
|
|
345
|
+
results: results.map((result) => compactInspectItem(result, { omitOp: true, commonFile }))
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (rawResults.length === 1) {
|
|
349
|
+
return compactInspectItem(results[0], { omitOp: true, omitFile: true });
|
|
350
|
+
}
|
|
351
|
+
if (op === "dependencies") {
|
|
352
|
+
if (commonFile) {
|
|
353
|
+
const deps = {};
|
|
354
|
+
for (const result of objectResults) {
|
|
355
|
+
const entity = (0, inspect_symbol_format_1.formatEntityName)(result.entity);
|
|
356
|
+
if (!entity) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
deps[entity] = formatGroupedDepsPayload(result, config);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
file: commonFile,
|
|
363
|
+
deps
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
results: results.map((result) => compactInspectItem(result, { omitOp: true, commonFile }))
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (op === "members") {
|
|
371
|
+
if (commonFile) {
|
|
372
|
+
const members = {};
|
|
373
|
+
for (const result of results) {
|
|
374
|
+
const entity = typeof result.entity === "string" ? result.entity : "";
|
|
375
|
+
if (!entity || !Array.isArray(result.members)) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
members[entity] = compactMembersPayload(result);
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
file: commonFile,
|
|
382
|
+
members
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
results: results.map((result) => compactInspectItem(result, { omitOp: true, commonFile }))
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (op === "code" || op === "slice") {
|
|
390
|
+
const items = results.map((result) => compactInspectItem(result, { omitOp: true, commonFile }));
|
|
391
|
+
const response = {
|
|
392
|
+
items
|
|
393
|
+
};
|
|
394
|
+
if (commonFile) {
|
|
395
|
+
response.file = commonFile;
|
|
396
|
+
}
|
|
397
|
+
const sharedSaves = saveSharedInspectOutputs(op, rawResults, options, config);
|
|
398
|
+
if (sharedSaves.length === 1) {
|
|
399
|
+
response.saved = sharedSaves[0].saved;
|
|
400
|
+
}
|
|
401
|
+
else if (sharedSaves.length > 1) {
|
|
402
|
+
response.saved = sharedSaves.map((saved) => saved.saved);
|
|
403
|
+
}
|
|
404
|
+
if (sharedSaves.length > 0) {
|
|
405
|
+
const readTarget = sharedSaves.length === 1 ? sharedSaves[0].saved : "--stdin";
|
|
406
|
+
const next = (0, session_workspace_1.useSessionGuidance)(options.cwd, `inspect.${op}.read`, `Read saved artifact with: aib session read ${readTarget}`);
|
|
407
|
+
if (next) {
|
|
408
|
+
response.next = next;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const savedHandles = collectSavedHandles(items);
|
|
412
|
+
if (savedHandles.length > 1) {
|
|
413
|
+
for (const item of items) {
|
|
414
|
+
delete item.next;
|
|
415
|
+
}
|
|
416
|
+
response.next = "Read saved artifacts with: aib session read --stdin";
|
|
417
|
+
}
|
|
418
|
+
return response;
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
results: results.map((result) => compactInspectItem(result, { omitOp: true, commonFile }))
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function compactInspectItem(result, options) {
|
|
425
|
+
const item = { ...result };
|
|
426
|
+
if (options.omitOp) {
|
|
427
|
+
delete item.op;
|
|
428
|
+
}
|
|
429
|
+
else if (item.op === "dependencies") {
|
|
430
|
+
item.op = "deps";
|
|
431
|
+
}
|
|
432
|
+
if (options.omitFile || (typeof item.file === "string" && item.file === options.commonFile)) {
|
|
433
|
+
delete item.file;
|
|
434
|
+
}
|
|
435
|
+
delete item.last;
|
|
436
|
+
if (typeof item.entity === "string") {
|
|
437
|
+
item.entity = stripSelectorPrefix(item.entity);
|
|
438
|
+
}
|
|
439
|
+
if (typeof item.count === "number" &&
|
|
440
|
+
item.count <= INSPECT_COUNT_VISIBLE_THRESHOLD &&
|
|
441
|
+
typeof item.page !== "string" &&
|
|
442
|
+
typeof item.hint !== "string") {
|
|
443
|
+
delete item.count;
|
|
444
|
+
}
|
|
445
|
+
normalizeTextArrayField(item, "symbols");
|
|
446
|
+
normalizeTextArrayField(item, "exports");
|
|
447
|
+
return item;
|
|
448
|
+
}
|
|
449
|
+
function normalizeTextArrayField(item, field) {
|
|
450
|
+
if (!Array.isArray(item[field])) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
item[field] = item[field]
|
|
454
|
+
.filter((value) => typeof value === "string")
|
|
455
|
+
.map((value) => (0, inspect_format_primitives_1.normalizeDuplicateSourceModuleSuffix)(value));
|
|
456
|
+
}
|
|
457
|
+
function compactMembersPayload(result) {
|
|
458
|
+
const payload = {};
|
|
459
|
+
if (typeof result.count === "number" && result.count > INSPECT_COUNT_VISIBLE_THRESHOLD) {
|
|
460
|
+
payload.count = result.count;
|
|
461
|
+
}
|
|
462
|
+
if (Array.isArray(result.members)) {
|
|
463
|
+
payload.members = result.members;
|
|
464
|
+
}
|
|
465
|
+
if (typeof result.hint === "string") {
|
|
466
|
+
payload.hint = result.hint;
|
|
467
|
+
}
|
|
468
|
+
if (typeof result.page === "string") {
|
|
469
|
+
payload.page = result.page;
|
|
470
|
+
}
|
|
471
|
+
return payload;
|
|
472
|
+
}
|
|
473
|
+
function collectSavedHandles(items) {
|
|
474
|
+
return items
|
|
475
|
+
.map((item) => typeof item.saved === "string" ? item.saved : "")
|
|
476
|
+
.filter((saved) => saved !== "");
|
|
477
|
+
}
|
|
478
|
+
function attachCodeOmittedViewHandles(rawResults, results, options, commonFile) {
|
|
479
|
+
const groups = new Map();
|
|
480
|
+
for (let index = 0; index < results.length; index += 1) {
|
|
481
|
+
const result = results[index];
|
|
482
|
+
const raw = rawResults[index];
|
|
483
|
+
if (!result || !(0, inspect_format_primitives_1.isObject)(raw) || !(0, inspect_mixed_format_1.isCodeOmittedFromStdoutResult)(result)) {
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const rawOp = typeof raw.op === "string" ? raw.op : "code";
|
|
487
|
+
if (rawOp !== "code" && rawOp !== "slice") {
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const saveHandle = savedHandleForInspectItem(result, options, rawResults, index);
|
|
491
|
+
const file = typeof result.file === "string" ? result.file : commonFile ?? "";
|
|
492
|
+
const key = [
|
|
493
|
+
rawOp,
|
|
494
|
+
saveHandle,
|
|
495
|
+
file,
|
|
496
|
+
options.parentNames?.[index] ?? options.parentName ?? ""
|
|
497
|
+
].join("\u0000");
|
|
498
|
+
const group = groups.get(key) ?? [];
|
|
499
|
+
group.push({ raw, result, index });
|
|
500
|
+
groups.set(key, group);
|
|
501
|
+
}
|
|
502
|
+
for (const group of groups.values()) {
|
|
503
|
+
const items = group.map(({ raw, result, index }) => {
|
|
504
|
+
const code = typeof raw.code === "string" ? raw.code : "";
|
|
505
|
+
const meta = typeof result.rangeMeta === "string"
|
|
506
|
+
? result.rangeMeta
|
|
507
|
+
: typeof result.meta === "string"
|
|
508
|
+
? result.meta
|
|
509
|
+
: "";
|
|
510
|
+
const file = typeof result.file === "string" ? result.file : commonFile ?? "";
|
|
511
|
+
const entity = typeof result.entity === "string"
|
|
512
|
+
? result.entity
|
|
513
|
+
: typeof raw.entity === "string"
|
|
514
|
+
? raw.entity
|
|
515
|
+
: "";
|
|
516
|
+
return compactViewObject({
|
|
517
|
+
file,
|
|
518
|
+
entity,
|
|
519
|
+
meta,
|
|
520
|
+
code,
|
|
521
|
+
nonEmptyLines: typeof result.nonEmptyLines === "number" ? result.nonEmptyLines : countNonEmptyLines(code),
|
|
522
|
+
lineCount: code === "" ? (0, inspect_format_primitives_1.numberOrZero)(raw.lineCount) : code.split(/\r?\n/).length,
|
|
523
|
+
parent: options.parentNames?.[index] ?? options.parentName
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
if (items.length === 0) {
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
const record = compactViewObject({
|
|
530
|
+
version: 1,
|
|
531
|
+
kind: "code",
|
|
532
|
+
source: "inspect",
|
|
533
|
+
items
|
|
534
|
+
});
|
|
535
|
+
const id = createShortResultId(record);
|
|
536
|
+
const saved = (0, session_workspace_1.saveSessionResultViewJson)(options.cwd, id, record);
|
|
537
|
+
if (!saved) {
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
for (const item of group) {
|
|
541
|
+
item.result.view = saved.saved;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const distinctViews = new Set(Array.from(groups.values())
|
|
545
|
+
.flatMap((group) => group.map((item) => typeof item.result.view === "string" ? item.result.view : ""))
|
|
546
|
+
.filter((view) => view !== ""));
|
|
547
|
+
if (distinctViews.size <= 1) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const allItems = Array.from(groups.values())
|
|
551
|
+
.flatMap((group) => group.map((item) => buildCodeViewItem(item.raw, item.result, item.index, options, commonFile)));
|
|
552
|
+
const record = compactViewObject({
|
|
553
|
+
version: 1,
|
|
554
|
+
kind: "code",
|
|
555
|
+
source: "inspect",
|
|
556
|
+
items: allItems
|
|
557
|
+
});
|
|
558
|
+
const saved = (0, session_workspace_1.saveSessionResultViewJson)(options.cwd, createShortResultId(record), record);
|
|
559
|
+
if (!saved) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
for (const group of groups.values()) {
|
|
563
|
+
for (const item of group) {
|
|
564
|
+
item.result.viewAllCode = saved.saved;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function buildCodeViewItem(raw, result, index, options, commonFile) {
|
|
569
|
+
const code = typeof raw.code === "string" ? raw.code : "";
|
|
570
|
+
const meta = typeof result.rangeMeta === "string"
|
|
571
|
+
? result.rangeMeta
|
|
572
|
+
: typeof result.meta === "string"
|
|
573
|
+
? result.meta
|
|
574
|
+
: "";
|
|
575
|
+
const file = typeof result.file === "string" ? result.file : commonFile ?? "";
|
|
576
|
+
const entity = typeof result.entity === "string"
|
|
577
|
+
? result.entity
|
|
578
|
+
: typeof raw.entity === "string"
|
|
579
|
+
? raw.entity
|
|
580
|
+
: "";
|
|
581
|
+
return compactViewObject({
|
|
582
|
+
file,
|
|
583
|
+
entity,
|
|
584
|
+
meta,
|
|
585
|
+
code,
|
|
586
|
+
nonEmptyLines: typeof result.nonEmptyLines === "number" ? result.nonEmptyLines : countNonEmptyLines(code),
|
|
587
|
+
lineCount: code === "" ? (0, inspect_format_primitives_1.numberOrZero)(raw.lineCount) : code.split(/\r?\n/).length,
|
|
588
|
+
parent: options.parentNames?.[index] ?? options.parentName
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function createShortResultId(record) {
|
|
592
|
+
return `res_${(0, node_crypto_1.createHash)("sha256").update(JSON.stringify(record)).digest("hex").slice(0, 8)}`;
|
|
593
|
+
}
|
|
594
|
+
function compactViewObject(value) {
|
|
595
|
+
const compacted = {};
|
|
596
|
+
for (const [key, item] of Object.entries(value)) {
|
|
597
|
+
if (item !== undefined && item !== "") {
|
|
598
|
+
compacted[key] = item;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return compacted;
|
|
602
|
+
}
|
|
603
|
+
function formatInspectAgentText(rawResults, response, options, commonFile) {
|
|
604
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "file")) {
|
|
605
|
+
return (0, inspect_mixed_format_1.formatSymbolListAgentText)(response, "symbols", commonFile);
|
|
606
|
+
}
|
|
607
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "exports")) {
|
|
608
|
+
return (0, inspect_mixed_format_1.formatSymbolListAgentText)(response, "exports", commonFile);
|
|
609
|
+
}
|
|
610
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "members")) {
|
|
611
|
+
return (0, inspect_mixed_format_1.formatMembersAgentText)(response, commonFile);
|
|
612
|
+
}
|
|
613
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "dependencies")) {
|
|
614
|
+
return (0, inspect_mixed_format_1.formatDepsAgentText)(response, commonFile);
|
|
615
|
+
}
|
|
616
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "modulePlan")) {
|
|
617
|
+
return (0, inspect_module_plan_format_1.formatModulePlanAgentText)(response);
|
|
618
|
+
}
|
|
619
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "usages")) {
|
|
620
|
+
return (0, inspect_usages_format_1.formatUsagesAgentText)(response);
|
|
621
|
+
}
|
|
622
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "duplicates")) {
|
|
623
|
+
return (0, inspect_duplicates_format_1.formatDuplicatesAgentText)(response);
|
|
624
|
+
}
|
|
625
|
+
if ((0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "directoryFallback")) {
|
|
626
|
+
return formatDirectoryFallbackAgentText(response);
|
|
627
|
+
}
|
|
628
|
+
if (!(0, inspect_mixed_format_1.isHomogeneousRawOp)(rawResults, "code")) {
|
|
629
|
+
return formatMixedInspectAgentText(response, commonFile);
|
|
630
|
+
}
|
|
631
|
+
const items = readCodeTextItems(response);
|
|
632
|
+
if (items.length !== rawResults.length || items.length === 0) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
if (items.some((item) => typeof item.code !== "string" &&
|
|
636
|
+
typeof item.meta !== "string" &&
|
|
637
|
+
!(0, inspect_format_primitives_1.isInspectSymbolNotFoundResult)(item) &&
|
|
638
|
+
!(0, inspect_mixed_format_1.isCodeOmittedFromStdoutResult)(item) &&
|
|
639
|
+
!(0, inspect_mixed_format_1.isSavedCodeResult)(item))) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
const lines = [];
|
|
643
|
+
const saved = response.saved;
|
|
644
|
+
const itemsHaveSavedHandles = items.some((item, index) => savedHandleForInspectItem(item, options, rawResults, index) !== "");
|
|
645
|
+
if (!itemsHaveSavedHandles && typeof saved === "string") {
|
|
646
|
+
lines.push(`// ${saved}`);
|
|
647
|
+
}
|
|
648
|
+
else if (!itemsHaveSavedHandles && Array.isArray(saved)) {
|
|
649
|
+
for (const handle of saved) {
|
|
650
|
+
if (typeof handle === "string") {
|
|
651
|
+
lines.push(`// ${handle}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
let currentFile = "";
|
|
656
|
+
let currentParent = "";
|
|
657
|
+
let currentSaved = "";
|
|
658
|
+
let pendingMissing = [];
|
|
659
|
+
let pendingOmitted = [];
|
|
660
|
+
const rawOp = (0, inspect_format_primitives_1.isObject)(rawResults[0]) && typeof rawResults[0].op === "string" ? rawResults[0].op : "code";
|
|
661
|
+
const flushOmitted = () => {
|
|
662
|
+
(0, inspect_mixed_format_1.appendCodeOmittedSummary)(lines, pendingOmitted, rawOp);
|
|
663
|
+
pendingOmitted = [];
|
|
664
|
+
};
|
|
665
|
+
const flushMissing = () => {
|
|
666
|
+
if (pendingMissing.length === 0) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
flushOmitted();
|
|
670
|
+
lines.push("// code:");
|
|
671
|
+
lines.push(`not found symbols: ${pendingMissing.join(", ")}`);
|
|
672
|
+
pendingMissing = [];
|
|
673
|
+
};
|
|
674
|
+
items.forEach((item, index) => {
|
|
675
|
+
const rawResult = (0, inspect_format_primitives_1.isObject)(rawResults[index]) ? rawResults[index] : {};
|
|
676
|
+
const itemSaved = savedHandleForInspectItem(item, options, rawResults, index);
|
|
677
|
+
if (itemSaved && itemSaved !== currentSaved) {
|
|
678
|
+
flushMissing();
|
|
679
|
+
flushOmitted();
|
|
680
|
+
(0, inspect_mixed_format_1.appendSectionBreak)(lines);
|
|
681
|
+
lines.push(`// ${itemSaved}`);
|
|
682
|
+
currentSaved = itemSaved;
|
|
683
|
+
currentFile = "";
|
|
684
|
+
currentParent = "";
|
|
685
|
+
}
|
|
686
|
+
const file = readTextItemFile(item, rawResult, options, commonFile);
|
|
687
|
+
if (file && file !== currentFile) {
|
|
688
|
+
flushMissing();
|
|
689
|
+
flushOmitted();
|
|
690
|
+
lines.push(`// ${file}`);
|
|
691
|
+
currentFile = file;
|
|
692
|
+
currentParent = "";
|
|
693
|
+
}
|
|
694
|
+
if ((0, inspect_format_primitives_1.isInspectSymbolNotFoundResult)(item)) {
|
|
695
|
+
pendingMissing.push(...(0, inspect_format_primitives_1.readNotFoundSymbols)(item));
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
flushMissing();
|
|
699
|
+
const parent = options.parentNames?.[index] ?? options.parentName ?? "";
|
|
700
|
+
if (parent && parent !== currentParent) {
|
|
701
|
+
flushOmitted();
|
|
702
|
+
lines.push(`// ${parent}:`);
|
|
703
|
+
currentParent = parent;
|
|
704
|
+
}
|
|
705
|
+
else if (!parent) {
|
|
706
|
+
currentParent = "";
|
|
707
|
+
}
|
|
708
|
+
if ((0, inspect_mixed_format_1.isCodeOmittedFromStdoutResult)(item)) {
|
|
709
|
+
pendingOmitted.push(item);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const itemIncludeRanges = options.ranges?.[index] ?? options.includeRanges;
|
|
713
|
+
if (options.codeMeta !== false && itemIncludeRanges && typeof item.meta === "string" && item.meta !== "") {
|
|
714
|
+
lines.push(`// ${item.meta}`);
|
|
715
|
+
}
|
|
716
|
+
else if (options.codeMeta !== false && itemIncludeRanges) {
|
|
717
|
+
const code = typeof item.code === "string" ? item.code : "";
|
|
718
|
+
const lineCount = code === "" ? (0, inspect_format_primitives_1.numberOrZero)(rawResult.lineCount) : code.split(/\r?\n/).length;
|
|
719
|
+
const meta = (0, inspect_symbol_format_1.formatMeta)(rawResult.entity, lineCount);
|
|
720
|
+
if (meta) {
|
|
721
|
+
lines.push(`// ${meta}`);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (typeof item.code === "string") {
|
|
725
|
+
lines.push(item.code.trimEnd());
|
|
726
|
+
}
|
|
727
|
+
else if ((0, inspect_mixed_format_1.isSavedCodeResult)(item)) {
|
|
728
|
+
(0, inspect_mixed_format_1.appendSavedCodeReference)(lines, item);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
flushOmitted();
|
|
732
|
+
flushMissing();
|
|
733
|
+
appendCodeViewAll(lines, items, false);
|
|
734
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
735
|
+
}
|
|
736
|
+
function savedHandleForInspectItem(item, options, rawResults, index) {
|
|
737
|
+
if (typeof item.saved === "string" && item.saved !== "") {
|
|
738
|
+
return item.saved;
|
|
739
|
+
}
|
|
740
|
+
const saveName = options.saves?.[index];
|
|
741
|
+
if (typeof saveName !== "string" || saveName === "") {
|
|
742
|
+
return "";
|
|
743
|
+
}
|
|
744
|
+
const rawResult = (0, inspect_format_primitives_1.isObject)(rawResults[index]) ? rawResults[index] : {};
|
|
745
|
+
const rawOp = typeof rawResult.op === "string" && rawResult.op !== ""
|
|
746
|
+
? rawResult.op === "dependencies" ? "deps" : rawResult.op
|
|
747
|
+
: "inspect";
|
|
748
|
+
return `aib:${rawOp}:${saveName}`;
|
|
749
|
+
}
|
|
750
|
+
function formatInspectMixedAgentText(response, commonFile = null) {
|
|
751
|
+
return formatMixedInspectAgentText(response, commonFile);
|
|
752
|
+
}
|
|
753
|
+
function formatMixedInspectAgentText(response, commonFile) {
|
|
754
|
+
if (!Array.isArray(response.results)) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const lines = [];
|
|
758
|
+
const appendFile = (0, inspect_mixed_format_1.createFileHeaderAppender)(lines);
|
|
759
|
+
let pendingCodeMissing = [];
|
|
760
|
+
const flushCodeMissing = () => {
|
|
761
|
+
if (pendingCodeMissing.length === 0) {
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
(0, inspect_mixed_format_1.appendSectionBreak)(lines);
|
|
765
|
+
lines.push("// code:");
|
|
766
|
+
lines.push(`not found symbols: ${pendingCodeMissing.join(", ")}`);
|
|
767
|
+
pendingCodeMissing = [];
|
|
768
|
+
};
|
|
769
|
+
const startSection = (item) => {
|
|
770
|
+
flushCodeMissing();
|
|
771
|
+
(0, inspect_mixed_format_1.appendSectionBreak)(lines);
|
|
772
|
+
appendFile(typeof item.file === "string" ? item.file : commonFile ?? "");
|
|
773
|
+
};
|
|
774
|
+
const results = response.results.filter(inspect_format_primitives_1.isObject);
|
|
775
|
+
const runtimeFailures = results.filter((item) => item.op === "runtimeFailure");
|
|
776
|
+
if (runtimeFailures.length > 0) {
|
|
777
|
+
lines.push("partial: runtime skipped");
|
|
778
|
+
}
|
|
779
|
+
for (let index = 0; index < results.length; index += 1) {
|
|
780
|
+
const item = results[index];
|
|
781
|
+
if (!(0, inspect_format_primitives_1.isObject)(item)) {
|
|
782
|
+
return null;
|
|
783
|
+
}
|
|
784
|
+
const op = typeof item.op === "string" ? item.op : "";
|
|
785
|
+
if ((op === "code" || op === "slice") && (0, inspect_format_primitives_1.isInspectSymbolNotFoundResult)(item)) {
|
|
786
|
+
pendingCodeMissing.push(...(0, inspect_format_primitives_1.readNotFoundSymbols)(item));
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
flushCodeMissing();
|
|
790
|
+
if (op === "file") {
|
|
791
|
+
startSection(item);
|
|
792
|
+
(0, inspect_mixed_format_1.appendMixedListSection)(lines, "file:", item.symbols);
|
|
793
|
+
(0, inspect_mixed_format_1.appendFileNonDeclarationText)(lines, item);
|
|
794
|
+
}
|
|
795
|
+
else if (op === "exports") {
|
|
796
|
+
startSection(item);
|
|
797
|
+
(0, inspect_mixed_format_1.appendMixedListSection)(lines, "exports:", item.exports);
|
|
798
|
+
}
|
|
799
|
+
else if (op === "members") {
|
|
800
|
+
startSection(item);
|
|
801
|
+
(0, inspect_mixed_format_1.appendMembersBlock)(lines, `members ${typeof item.entity === "string" ? item.entity : ""}`.trim(), item);
|
|
802
|
+
}
|
|
803
|
+
else if (op === "deps" || op === "dependencies") {
|
|
804
|
+
startSection(item);
|
|
805
|
+
const blocks = [];
|
|
806
|
+
while (index < results.length) {
|
|
807
|
+
const depsItem = results[index];
|
|
808
|
+
const depsOp = typeof depsItem.op === "string" ? depsItem.op : "";
|
|
809
|
+
if (depsOp !== "deps" && depsOp !== "dependencies") {
|
|
810
|
+
index -= 1;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
blocks.push({
|
|
814
|
+
entity: typeof depsItem.entity === "string" ? depsItem.entity : "",
|
|
815
|
+
missingSymbols: (0, inspect_format_primitives_1.readNotFoundSymbols)(depsItem),
|
|
816
|
+
type: depsItem.depsType,
|
|
817
|
+
value: depsItem.depsValue,
|
|
818
|
+
unknown: depsItem.depsUnknown
|
|
819
|
+
});
|
|
820
|
+
index += 1;
|
|
821
|
+
}
|
|
822
|
+
if (index >= results.length) {
|
|
823
|
+
index -= 1;
|
|
824
|
+
}
|
|
825
|
+
(0, inspect_mixed_format_1.appendDepsBlocks)(lines, blocks);
|
|
826
|
+
}
|
|
827
|
+
else if (op === "code" || op === "slice") {
|
|
828
|
+
startSection(item);
|
|
829
|
+
const codeItems = [];
|
|
830
|
+
const sectionFile = typeof item.file === "string" ? item.file : commonFile ?? "";
|
|
831
|
+
while (index < results.length) {
|
|
832
|
+
const codeItem = results[index];
|
|
833
|
+
const codeOp = typeof codeItem.op === "string" ? codeItem.op : "";
|
|
834
|
+
const codeFile = typeof codeItem.file === "string" ? codeItem.file : commonFile ?? "";
|
|
835
|
+
if (codeOp !== op || codeFile !== sectionFile || (0, inspect_format_primitives_1.isInspectSymbolNotFoundResult)(codeItem)) {
|
|
836
|
+
index -= 1;
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
codeItems.push(codeItem);
|
|
840
|
+
index += 1;
|
|
841
|
+
}
|
|
842
|
+
if (index >= results.length) {
|
|
843
|
+
index -= 1;
|
|
844
|
+
}
|
|
845
|
+
(0, inspect_mixed_format_1.appendCodeLikeMixedBlocks)(lines, op, codeItems);
|
|
846
|
+
}
|
|
847
|
+
else if (op === "graph") {
|
|
848
|
+
startSection(item);
|
|
849
|
+
appendGraphMixedBlock(lines, item);
|
|
850
|
+
}
|
|
851
|
+
else if (op === "imports") {
|
|
852
|
+
(0, inspect_imports_1.appendImportsBlock)(lines, item);
|
|
853
|
+
}
|
|
854
|
+
else if (op === "tree") {
|
|
855
|
+
startSection(item);
|
|
856
|
+
appendLocalInspectTextBlock(lines, (0, inspect_tree_1.formatTreeResponse)(item));
|
|
857
|
+
}
|
|
858
|
+
else if (op === "cycles") {
|
|
859
|
+
startSection(item);
|
|
860
|
+
appendLocalInspectTextBlock(lines, (0, inspect_cycles_1.formatCyclesResponse)(item));
|
|
861
|
+
}
|
|
862
|
+
else if (op === "aliasCandidates") {
|
|
863
|
+
startSection(item);
|
|
864
|
+
appendLocalInspectTextBlock(lines, (0, inspect_alias_candidates_1.formatAliasCandidatesResponse)(item));
|
|
865
|
+
}
|
|
866
|
+
else if (op === "runtimeFailure") {
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
else if (op === "usages") {
|
|
870
|
+
startSection(item);
|
|
871
|
+
(0, inspect_mixed_format_1.appendUsagesMixedBlock)(lines, item);
|
|
872
|
+
}
|
|
873
|
+
else if (op === "duplicates") {
|
|
874
|
+
startSection(item);
|
|
875
|
+
(0, inspect_mixed_format_1.appendDuplicatesMixedBlock)(lines, item);
|
|
876
|
+
}
|
|
877
|
+
else if (op === "directoryFallback") {
|
|
878
|
+
startSection(item);
|
|
879
|
+
appendDirectoryFallbackMixedBlock(lines, item);
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
flushCodeMissing();
|
|
886
|
+
appendRuntimeFailureSummary(lines, runtimeFailures);
|
|
887
|
+
appendCodeViewAll(lines, results, true);
|
|
888
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
889
|
+
}
|
|
890
|
+
function appendLocalInspectTextBlock(lines, text) {
|
|
891
|
+
if (!text) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
lines.push(...text.split(/\r?\n/));
|
|
895
|
+
}
|
|
896
|
+
function appendRuntimeFailureSummary(lines, items) {
|
|
897
|
+
if (items.length === 0) {
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
(0, inspect_mixed_format_1.appendSectionBreak)(lines);
|
|
901
|
+
lines.push("runtime skipped:");
|
|
902
|
+
for (const errorText of summarizeRuntimeFailureErrors(items)) {
|
|
903
|
+
lines.push(errorText);
|
|
904
|
+
}
|
|
905
|
+
lines.push(`skipped ops: ${summarizeRuntimeSkippedOps(items)}`);
|
|
906
|
+
}
|
|
907
|
+
function summarizeRuntimeFailureErrors(items) {
|
|
908
|
+
return Array.from(new Set(items.map((item) => {
|
|
909
|
+
const code = typeof item.code === "string" ? item.code : "RUNTIME_INSPECT_FAILED";
|
|
910
|
+
const error = typeof item.error === "string" ? item.error : "runtime-backed inspect failed";
|
|
911
|
+
return `${code}: ${error}`;
|
|
912
|
+
})));
|
|
913
|
+
}
|
|
914
|
+
function summarizeRuntimeSkippedOps(items) {
|
|
915
|
+
const counts = new Map();
|
|
916
|
+
for (const item of items) {
|
|
917
|
+
const op = normalizeRuntimeSkippedOp(typeof item.requestedOp === "string" ? item.requestedOp : "inspect");
|
|
918
|
+
counts.set(op, (counts.get(op) ?? 0) + 1);
|
|
919
|
+
}
|
|
920
|
+
return Array.from(counts.entries())
|
|
921
|
+
.map(([op, count]) => count > 1 ? `${op} x${count}` : op)
|
|
922
|
+
.join(", ");
|
|
923
|
+
}
|
|
924
|
+
function normalizeRuntimeSkippedOp(op) {
|
|
925
|
+
return op === "dependencies" ? "deps" : op;
|
|
926
|
+
}
|
|
927
|
+
function appendCodeViewAll(lines, items, mixed) {
|
|
928
|
+
const views = Array.from(new Set(items
|
|
929
|
+
.map((item) => typeof item.viewAllCode === "string" ? item.viewAllCode : "")
|
|
930
|
+
.filter((view) => view !== "")));
|
|
931
|
+
if (views.length === 0) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
(0, inspect_mixed_format_1.appendSectionBreak)(lines);
|
|
935
|
+
if (mixed) {
|
|
936
|
+
lines.push("view all:");
|
|
937
|
+
lines.push(`code: ${views[0]}`);
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
lines.push(`view all code: ${views[0]}`);
|
|
941
|
+
}
|
|
942
|
+
function appendGraphMixedBlock(lines, item) {
|
|
943
|
+
const text = (0, inspect_graph_1.formatGraphAgentText)({
|
|
944
|
+
...item,
|
|
945
|
+
operation: "inspect.graph"
|
|
946
|
+
});
|
|
947
|
+
if (!text) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
lines.push("// graph:");
|
|
951
|
+
lines.push(...text.split(/\r?\n/).filter((line) => line !== "inspect.graph"));
|
|
952
|
+
}
|
|
953
|
+
function appendDirectoryFallbackMixedBlock(lines, item) {
|
|
954
|
+
const text = formatDirectoryFallbackAgentText(item);
|
|
955
|
+
if (text) {
|
|
956
|
+
lines.push(...text.split(/\r?\n/));
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function formatDirectoryFallbackAgentText(response) {
|
|
960
|
+
const lines = stripLeadingBlankLines(Array.isArray(response.lines)
|
|
961
|
+
? response.lines
|
|
962
|
+
.filter((line) => typeof line === "string")
|
|
963
|
+
.filter((line, index) => index !== 0 || !line.startsWith("tree "))
|
|
964
|
+
: []);
|
|
965
|
+
if (lines.length === 0) {
|
|
966
|
+
return null;
|
|
967
|
+
}
|
|
968
|
+
const displayPath = typeof response.directory === "string" ? response.directory : "directory";
|
|
969
|
+
const ops = Array.isArray(response.skippedOps)
|
|
970
|
+
? response.skippedOps.filter((op) => typeof op === "string")
|
|
971
|
+
: [];
|
|
972
|
+
const text = [
|
|
973
|
+
`inspect expected file, got directory: ${displayPath}`
|
|
974
|
+
];
|
|
975
|
+
if (ops.length > 0) {
|
|
976
|
+
text.push("");
|
|
977
|
+
text.push("Skipped file-based operations:");
|
|
978
|
+
text.push(ops.join(", "));
|
|
979
|
+
}
|
|
980
|
+
if (typeof response.command === "string" && response.command !== "") {
|
|
981
|
+
text.push("");
|
|
982
|
+
text.push("Showing tree instead:");
|
|
983
|
+
text.push(response.command);
|
|
984
|
+
}
|
|
985
|
+
text.push("");
|
|
986
|
+
text.push(...lines);
|
|
987
|
+
return text.join("\n");
|
|
988
|
+
}
|
|
989
|
+
function stripLeadingBlankLines(lines) {
|
|
990
|
+
let index = 0;
|
|
991
|
+
while (index < lines.length && lines[index] === "") {
|
|
992
|
+
index += 1;
|
|
993
|
+
}
|
|
994
|
+
return lines.slice(index);
|
|
995
|
+
}
|
|
996
|
+
function readCodeTextItems(response) {
|
|
997
|
+
if (Array.isArray(response.items)) {
|
|
998
|
+
return response.items.filter(inspect_format_primitives_1.isObject);
|
|
999
|
+
}
|
|
1000
|
+
if (Array.isArray(response.results)) {
|
|
1001
|
+
return response.results.filter(inspect_format_primitives_1.isObject);
|
|
1002
|
+
}
|
|
1003
|
+
return [response];
|
|
1004
|
+
}
|
|
1005
|
+
function readTextItemFile(item, rawResult, options, commonFile) {
|
|
1006
|
+
if (typeof item.file === "string" && item.file !== "") {
|
|
1007
|
+
return item.file;
|
|
1008
|
+
}
|
|
1009
|
+
if (commonFile) {
|
|
1010
|
+
return commonFile;
|
|
1011
|
+
}
|
|
1012
|
+
if (typeof rawResult.sourceFile === "string" && rawResult.sourceFile !== "") {
|
|
1013
|
+
return (0, inspect_format_primitives_1.formatFilePath)(rawResult.sourceFile, options);
|
|
1014
|
+
}
|
|
1015
|
+
return "";
|
|
1016
|
+
}
|
|
1017
|
+
function saveSharedInspectOutputs(op, rawResults, options, config) {
|
|
1018
|
+
if (op !== "code" && op !== "slice") {
|
|
1019
|
+
return [];
|
|
1020
|
+
}
|
|
1021
|
+
const saveNames = sharedSaveNames(options.saves, options.sharedSaves, rawResults.length);
|
|
1022
|
+
if (saveNames.length === 0) {
|
|
1023
|
+
return [];
|
|
1024
|
+
}
|
|
1025
|
+
return saveNames.map((saveName) => {
|
|
1026
|
+
const parts = rawResults
|
|
1027
|
+
.map((rawResult, index) => ({ rawResult, save: options.saves?.[index] ?? null, includeRanges: options.ranges?.[index] ?? options.includeRanges }))
|
|
1028
|
+
.filter((item) => item.save === saveName && (0, inspect_format_primitives_1.isObject)(item.rawResult))
|
|
1029
|
+
.map((item) => ({ rawResult: item.rawResult, includeRanges: item.includeRanges }))
|
|
1030
|
+
.map(({ rawResult, includeRanges }) => {
|
|
1031
|
+
const code = typeof rawResult.code === "string" ? rawResult.code : "";
|
|
1032
|
+
const entity = (0, inspect_symbol_format_1.formatEntityReference)(rawResult.entity, config);
|
|
1033
|
+
const lineCount = code === "" ? (0, inspect_format_primitives_1.numberOrZero)(rawResult.lineCount) : code.split(/\r?\n/).length;
|
|
1034
|
+
const meta = options.codeMeta === false || !includeRanges ? "" : (0, inspect_symbol_format_1.formatMeta)(rawResult.entity, lineCount);
|
|
1035
|
+
const header = [entity, meta].filter((value) => value !== "").join(" ");
|
|
1036
|
+
return header ? `// ${header}\n${code}` : code;
|
|
1037
|
+
})
|
|
1038
|
+
.filter((part) => part !== "");
|
|
1039
|
+
const extension = firstInspectResultExtension(rawResults);
|
|
1040
|
+
const saved = (0, session_workspace_1.saveSessionOutputText)(options.cwd, op, saveName, parts.join("\n\n"), extension);
|
|
1041
|
+
return {
|
|
1042
|
+
saved: saved.saved,
|
|
1043
|
+
last: saved.last
|
|
1044
|
+
};
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
function sharedSaveNames(saves, sharedSaves, expectedLength) {
|
|
1048
|
+
if (!saves || !sharedSaves || expectedLength < 2 || saves.length < expectedLength) {
|
|
1049
|
+
return [];
|
|
1050
|
+
}
|
|
1051
|
+
return Array.from(new Set(saves.slice(0, expectedLength)
|
|
1052
|
+
.filter((save) => typeof save === "string" && save !== "" && sharedSaves.has(save))));
|
|
1053
|
+
}
|
|
1054
|
+
function firstInspectResultExtension(rawResults) {
|
|
1055
|
+
for (const rawResult of rawResults) {
|
|
1056
|
+
if ((0, inspect_format_primitives_1.isObject)(rawResult) && typeof rawResult.sourceFile === "string") {
|
|
1057
|
+
return path.extname(rawResult.sourceFile) || ".ts";
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return ".ts";
|
|
1061
|
+
}
|
|
1062
|
+
function formatInspectResult(rawResult, config, options, commonFile) {
|
|
1063
|
+
if (!(0, inspect_format_primitives_1.isObject)(rawResult)) {
|
|
1064
|
+
return {
|
|
1065
|
+
ok: false,
|
|
1066
|
+
code: "INVALID_INSPECT_RESULT",
|
|
1067
|
+
error: "Inspect result is not an object."
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
const op = typeof rawResult.op === "string" ? rawResult.op : "unknown";
|
|
1071
|
+
if (rawResult.ok === false && op !== "modulePlan") {
|
|
1072
|
+
return formatErrorResult(rawResult, options, commonFile);
|
|
1073
|
+
}
|
|
1074
|
+
if (op === "file") {
|
|
1075
|
+
const result = {
|
|
1076
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1077
|
+
...visibleCount("count", (0, inspect_format_primitives_1.numberOrZero)(rawResult.symbolCount)),
|
|
1078
|
+
symbols: formatSymbolsArray(rawResult.symbols, config, options, "file")
|
|
1079
|
+
};
|
|
1080
|
+
if (rawResult.hasNonDeclarationText === true ||
|
|
1081
|
+
(Array.isArray(result.symbols) && result.symbols.length === 0 && fileHasNonDeclarationText(rawResult.sourceFile))) {
|
|
1082
|
+
result.hasNonDeclarationText = true;
|
|
1083
|
+
}
|
|
1084
|
+
if (rawResult.mode === "local") {
|
|
1085
|
+
result.mode = "local";
|
|
1086
|
+
result.summary = formatLocalFileSummary(rawResult);
|
|
1087
|
+
result.localDeclarationCount = (0, inspect_format_primitives_1.numberOrZero)(rawResult.localDeclarationCount);
|
|
1088
|
+
result.reexports = formatReexports(rawResult.reexports);
|
|
1089
|
+
}
|
|
1090
|
+
return result;
|
|
1091
|
+
}
|
|
1092
|
+
if (op === "exports") {
|
|
1093
|
+
return {
|
|
1094
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1095
|
+
...visibleCount("count", (0, inspect_format_primitives_1.numberOrZero)(rawResult.exportCount)),
|
|
1096
|
+
exports: formatExportsArray(rawResult.exports, config, options)
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
if (op === "members") {
|
|
1100
|
+
return {
|
|
1101
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1102
|
+
entity: (0, inspect_symbol_format_1.formatEntityReference)(rawResult.entity, config),
|
|
1103
|
+
...formatMembersPayload(rawResult, config, options)
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
if (op === "code") {
|
|
1107
|
+
return formatCodeResult(rawResult, config, options, commonFile);
|
|
1108
|
+
}
|
|
1109
|
+
if (op === "dependencies") {
|
|
1110
|
+
return {
|
|
1111
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1112
|
+
entity: (0, inspect_symbol_format_1.formatEntityReference)(rawResult.entity, config),
|
|
1113
|
+
...formatDepsFields(rawResult, config, options)
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
if (op === "modulePlan") {
|
|
1117
|
+
return (0, inspect_module_plan_serialization_1.formatModulePlanResult)(rawResult, config, options, commonFile);
|
|
1118
|
+
}
|
|
1119
|
+
if (op === "usages") {
|
|
1120
|
+
return (0, inspect_usages_format_1.formatUsagesResult)(rawResult, config, options, commonFile);
|
|
1121
|
+
}
|
|
1122
|
+
if (op === "duplicates") {
|
|
1123
|
+
return (0, inspect_duplicates_format_1.formatDuplicatesResult)(rawResult, config, options, commonFile);
|
|
1124
|
+
}
|
|
1125
|
+
if (op === "directoryFallback") {
|
|
1126
|
+
return {
|
|
1127
|
+
...rawResult
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
if (op === "slice") {
|
|
1131
|
+
return formatSliceResult(rawResult, config, options, commonFile);
|
|
1132
|
+
}
|
|
1133
|
+
return {
|
|
1134
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1135
|
+
warning: "Unknown inspect operation result."
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function groupBy(items, keyOf) {
|
|
1139
|
+
const groups = new Map();
|
|
1140
|
+
for (const item of items) {
|
|
1141
|
+
const key = keyOf(item);
|
|
1142
|
+
const group = groups.get(key) ?? [];
|
|
1143
|
+
group.push(item);
|
|
1144
|
+
groups.set(key, group);
|
|
1145
|
+
}
|
|
1146
|
+
return Array.from(groups.entries());
|
|
1147
|
+
}
|
|
1148
|
+
function formatSliceResult(rawResult, config, options, commonFile) {
|
|
1149
|
+
const code = typeof rawResult.code === "string" ? rawResult.code : "";
|
|
1150
|
+
const lineCount = code === "" ? (0, inspect_format_primitives_1.numberOrZero)(rawResult.lineCount) : code.split(/\r?\n/).length;
|
|
1151
|
+
const result = {
|
|
1152
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1153
|
+
entity: (0, inspect_symbol_format_1.formatEntityReference)(rawResult.entity, config)
|
|
1154
|
+
};
|
|
1155
|
+
const meta = (0, inspect_symbol_format_1.formatMeta)(rawResult.entity, lineCount);
|
|
1156
|
+
if (options.includeRanges && meta) {
|
|
1157
|
+
result.meta = meta;
|
|
1158
|
+
}
|
|
1159
|
+
if (options.toFile) {
|
|
1160
|
+
const writtenTo = writeInspectOutputFile(options.cwd, options.toFile, code);
|
|
1161
|
+
result.writtenTo = writtenTo;
|
|
1162
|
+
if (!options.show) {
|
|
1163
|
+
return result;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
if (options.save) {
|
|
1167
|
+
const saved = saveInspectOutput(options.cwd, "slice", options.save, rawResult, code);
|
|
1168
|
+
result.saved = saved.saved;
|
|
1169
|
+
const next = (0, session_workspace_1.useSessionGuidance)(options.cwd, "inspect.slice.read", `Read saved artifact with: aib session read ${saved.saved}`);
|
|
1170
|
+
if (next) {
|
|
1171
|
+
result.next = next;
|
|
1172
|
+
}
|
|
1173
|
+
if (!options.show) {
|
|
1174
|
+
return result;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
if (options.show || lineCount <= options.maxCodeLines) {
|
|
1178
|
+
result.code = code;
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
result.reason = "SLICE_TOO_LARGE_FOR_STDOUT";
|
|
1182
|
+
result.lineCount = lineCount;
|
|
1183
|
+
result.limit = options.maxCodeLines;
|
|
1184
|
+
if (meta) {
|
|
1185
|
+
result.rangeMeta = meta;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return result;
|
|
1189
|
+
}
|
|
1190
|
+
function formatCodeResult(rawResult, config, options, commonFile) {
|
|
1191
|
+
const code = typeof rawResult.code === "string" ? rawResult.code : "";
|
|
1192
|
+
const lineCount = code === "" ? 0 : code.split(/\r?\n/).length;
|
|
1193
|
+
const nonEmptyLineCount = countNonEmptyLines(code);
|
|
1194
|
+
const result = {
|
|
1195
|
+
...(0, inspect_format_primitives_1.baseResult)(rawResult, options, commonFile),
|
|
1196
|
+
entity: (0, inspect_symbol_format_1.formatEntityReference)(rawResult.entity, config)
|
|
1197
|
+
};
|
|
1198
|
+
const meta = (0, inspect_symbol_format_1.formatMeta)(rawResult.entity, lineCount);
|
|
1199
|
+
if (options.codeMeta !== false && options.includeRanges && meta) {
|
|
1200
|
+
result.meta = meta;
|
|
1201
|
+
}
|
|
1202
|
+
if (options.toFile) {
|
|
1203
|
+
const writtenTo = writeInspectOutputFile(options.cwd, options.toFile, code);
|
|
1204
|
+
result.writtenTo = writtenTo;
|
|
1205
|
+
if (!options.show) {
|
|
1206
|
+
return result;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (options.save) {
|
|
1210
|
+
const saved = saveInspectOutput(options.cwd, "code", options.save, rawResult, code);
|
|
1211
|
+
result.saved = saved.saved;
|
|
1212
|
+
const next = (0, session_workspace_1.useSessionGuidance)(options.cwd, "inspect.code.read", `Read saved artifact with: aib session read ${saved.saved}`);
|
|
1213
|
+
if (next) {
|
|
1214
|
+
result.next = next;
|
|
1215
|
+
}
|
|
1216
|
+
if (!options.show) {
|
|
1217
|
+
return result;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
if (!options.show) {
|
|
1221
|
+
return result;
|
|
1222
|
+
}
|
|
1223
|
+
if (nonEmptyLineCount <= options.maxCodeLines) {
|
|
1224
|
+
result.code = code;
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
result.reason = "CODE_TOO_LARGE_FOR_STDOUT";
|
|
1228
|
+
result.nonEmptyLines = nonEmptyLineCount;
|
|
1229
|
+
result.limit = options.maxCodeLines;
|
|
1230
|
+
if (meta) {
|
|
1231
|
+
result.rangeMeta = meta;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return result;
|
|
1235
|
+
}
|
|
1236
|
+
function countNonEmptyLines(code) {
|
|
1237
|
+
if (code === "") {
|
|
1238
|
+
return 0;
|
|
1239
|
+
}
|
|
1240
|
+
return code.split(/\r?\n/).filter((line) => line.trim() !== "").length;
|
|
1241
|
+
}
|
|
1242
|
+
function fileHasNonDeclarationText(file) {
|
|
1243
|
+
if (typeof file !== "string" || file === "") {
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
try {
|
|
1247
|
+
return fs.existsSync(file) && fs.statSync(file).isFile() && fs.readFileSync(file, "utf8").trim() !== "";
|
|
1248
|
+
}
|
|
1249
|
+
catch {
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function formatSymbolsArray(rawSymbols, config, options, context = "generic") {
|
|
1254
|
+
if (!Array.isArray(rawSymbols)) {
|
|
1255
|
+
return [];
|
|
1256
|
+
}
|
|
1257
|
+
return rawSymbols
|
|
1258
|
+
.filter(inspect_format_primitives_1.isObject)
|
|
1259
|
+
.map((symbol) => (0, inspect_format_primitives_1.normalizeDuplicateSourceModuleSuffix)(formatSymbolLine(symbol, config, options, context)));
|
|
1260
|
+
}
|
|
1261
|
+
function formatExportsArray(rawSymbols, config, options) {
|
|
1262
|
+
if (!Array.isArray(rawSymbols)) {
|
|
1263
|
+
return [];
|
|
1264
|
+
}
|
|
1265
|
+
const symbols = rawSymbols.filter(inspect_format_primitives_1.isObject);
|
|
1266
|
+
if (options.includeRanges) {
|
|
1267
|
+
return symbols.map((symbol) => (0, inspect_format_primitives_1.normalizeDuplicateSourceModuleSuffix)(formatSymbolLine(symbol, config, options, "exports")));
|
|
1268
|
+
}
|
|
1269
|
+
const local = [];
|
|
1270
|
+
const bySource = new Map();
|
|
1271
|
+
for (const symbol of symbols) {
|
|
1272
|
+
const line = (0, inspect_format_primitives_1.normalizeDuplicateSourceModuleSuffix)(formatSymbolLine(symbol, config, options, "exports"));
|
|
1273
|
+
const sourceModule = typeof symbol.sourceModule === "string" ? symbol.sourceModule : "";
|
|
1274
|
+
if (!sourceModule) {
|
|
1275
|
+
local.push(line);
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
const sourceFreeLine = formatSourceExportEntry(symbol, line, sourceModule);
|
|
1279
|
+
const current = bySource.get(sourceModule) ?? [];
|
|
1280
|
+
current.push(sourceFreeLine);
|
|
1281
|
+
bySource.set(sourceModule, current);
|
|
1282
|
+
}
|
|
1283
|
+
if (bySource.size === 0) {
|
|
1284
|
+
return local;
|
|
1285
|
+
}
|
|
1286
|
+
const lines = [];
|
|
1287
|
+
if (local.length > 0) {
|
|
1288
|
+
lines.push(`local: ${local.join(", ")}`);
|
|
1289
|
+
}
|
|
1290
|
+
for (const [sourceModule, entries] of bySource.entries()) {
|
|
1291
|
+
lines.push(`${sourceModule}: ${entries.join(", ")}`);
|
|
1292
|
+
}
|
|
1293
|
+
return lines;
|
|
1294
|
+
}
|
|
1295
|
+
function formatDepsFields(rawResult, config, options) {
|
|
1296
|
+
const groups = formatDependencyGroups(rawResult, config, options);
|
|
1297
|
+
const payload = {};
|
|
1298
|
+
if (groups.type.length > 0) {
|
|
1299
|
+
payload.depsType = groups.type;
|
|
1300
|
+
}
|
|
1301
|
+
if (groups.value.length > 0) {
|
|
1302
|
+
payload.depsValue = groups.value;
|
|
1303
|
+
}
|
|
1304
|
+
if (groups.unknown.length > 0) {
|
|
1305
|
+
payload.depsUnknown = groups.unknown;
|
|
1306
|
+
}
|
|
1307
|
+
return payload;
|
|
1308
|
+
}
|
|
1309
|
+
function formatGroupedDepsPayload(rawResult, config) {
|
|
1310
|
+
const groups = formatDependencyGroups(rawResult, config);
|
|
1311
|
+
const payload = {};
|
|
1312
|
+
if (groups.type.length > 0) {
|
|
1313
|
+
payload.type = groups.type;
|
|
1314
|
+
}
|
|
1315
|
+
if (groups.value.length > 0) {
|
|
1316
|
+
payload.value = groups.value;
|
|
1317
|
+
}
|
|
1318
|
+
if (groups.unknown.length > 0) {
|
|
1319
|
+
payload.unknown = groups.unknown;
|
|
1320
|
+
}
|
|
1321
|
+
return payload;
|
|
1322
|
+
}
|
|
1323
|
+
function formatDependencyGroups(rawResult, config, options) {
|
|
1324
|
+
const hasGroupedDependencies = Array.isArray(rawResult.typeOnlyDependencies) ||
|
|
1325
|
+
Array.isArray(rawResult.valueDependencies) ||
|
|
1326
|
+
Array.isArray(rawResult.unclassifiedDependencies);
|
|
1327
|
+
if (!hasGroupedDependencies) {
|
|
1328
|
+
const fallback = formatDependencyReferences(rawResult.dependencies, config, options);
|
|
1329
|
+
return {
|
|
1330
|
+
type: [],
|
|
1331
|
+
value: [],
|
|
1332
|
+
unknown: fallback
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
const typeOnly = formatDependencyReferences(rawResult.typeOnlyDependencies, config, options);
|
|
1336
|
+
const value = formatDependencyReferences(rawResult.valueDependencies, config, options);
|
|
1337
|
+
const unclassified = formatDependencyReferences(rawResult.unclassifiedDependencies, config, options);
|
|
1338
|
+
return {
|
|
1339
|
+
type: typeOnly,
|
|
1340
|
+
value,
|
|
1341
|
+
unknown: unclassified
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function formatDependencyReferences(rawSymbols, config, _options) {
|
|
1345
|
+
return (0, inspect_symbol_format_1.formatSymbolReferencesArray)(rawSymbols, config);
|
|
1346
|
+
}
|
|
1347
|
+
function formatMembersPayload(rawResult, config, options) {
|
|
1348
|
+
const memberCount = (0, inspect_format_primitives_1.numberOrZero)(rawResult.memberCount);
|
|
1349
|
+
const offset = (0, inspect_format_primitives_1.numberOrZero)(rawResult.memberOffset);
|
|
1350
|
+
const limit = (0, inspect_format_primitives_1.numberOrZero)(rawResult.memberLimit);
|
|
1351
|
+
const hiddenMemberCount = (0, inspect_format_primitives_1.numberOrZero)(rawResult.hiddenMemberCount);
|
|
1352
|
+
const members = formatSymbolsArray(rawResult.members, config, options, "members");
|
|
1353
|
+
const visibleMemberCount = members.length;
|
|
1354
|
+
if (hiddenMemberCount > 0) {
|
|
1355
|
+
members.push(`+ ${hiddenMemberCount} hidden members`);
|
|
1356
|
+
}
|
|
1357
|
+
const payload = {
|
|
1358
|
+
members
|
|
1359
|
+
};
|
|
1360
|
+
if (hiddenMemberCount > 0) {
|
|
1361
|
+
payload.count = memberCount;
|
|
1362
|
+
payload.page = `${offset}..${offset + visibleMemberCount - 1} of ${memberCount}`;
|
|
1363
|
+
payload.hint = "Use --all to list all members, --offset <n> --limit <n> to page, or inspect code <member> --parent <entity>.";
|
|
1364
|
+
}
|
|
1365
|
+
else if (memberCount > INSPECT_COUNT_VISIBLE_THRESHOLD) {
|
|
1366
|
+
payload.count = memberCount;
|
|
1367
|
+
}
|
|
1368
|
+
if (offset > 0 && hiddenMemberCount === 0) {
|
|
1369
|
+
payload.page = `${offset}..${offset + members.length - 1} of ${memberCount}`;
|
|
1370
|
+
}
|
|
1371
|
+
return payload;
|
|
1372
|
+
}
|
|
1373
|
+
function formatLocalFileSummary(rawResult) {
|
|
1374
|
+
const declarationCount = (0, inspect_format_primitives_1.numberOrZero)(rawResult.localDeclarationCount);
|
|
1375
|
+
const reexports = formatReexports(rawResult.reexports);
|
|
1376
|
+
if (declarationCount === 0 && reexports.length > 0) {
|
|
1377
|
+
return `facade only; ${reexports.length} ${reexports.length === 1 ? "re-export" : "re-exports"}; 0 local declarations`;
|
|
1378
|
+
}
|
|
1379
|
+
if (declarationCount === 0) {
|
|
1380
|
+
return "0 local declarations";
|
|
1381
|
+
}
|
|
1382
|
+
return `${declarationCount} local ${declarationCount === 1 ? "declaration" : "declarations"}; ${reexports.length} ${reexports.length === 1 ? "re-export" : "re-exports"}`;
|
|
1383
|
+
}
|
|
1384
|
+
function formatReexports(rawReexports) {
|
|
1385
|
+
if (!Array.isArray(rawReexports)) {
|
|
1386
|
+
return [];
|
|
1387
|
+
}
|
|
1388
|
+
return rawReexports
|
|
1389
|
+
.filter(inspect_format_primitives_1.isObject)
|
|
1390
|
+
.map((item) => typeof item.module === "string" ? item.module : "")
|
|
1391
|
+
.filter((module) => module !== "");
|
|
1392
|
+
}
|
|
1393
|
+
function formatSymbolLine(symbol, config, options, context) {
|
|
1394
|
+
const selector = (0, inspect_symbol_format_1.formatSymbolReference)(symbol, config);
|
|
1395
|
+
const signature = typeof symbol.signature === "string" ? symbol.signature : "";
|
|
1396
|
+
const meta = options.includeRanges ? (0, inspect_symbol_format_1.formatMeta)(symbol) : "";
|
|
1397
|
+
const sourceModule = typeof symbol.sourceModule === "string" ? `from ${symbol.sourceModule}` : "";
|
|
1398
|
+
if (context === "file" || context === "exports") {
|
|
1399
|
+
return formatTopLevelSymbolLine(symbol, selector, signature, meta, sourceModule, context, config);
|
|
1400
|
+
}
|
|
1401
|
+
if (context === "members") {
|
|
1402
|
+
return formatMemberSymbolLine(symbol, selector, signature, meta);
|
|
1403
|
+
}
|
|
1404
|
+
if (selector === "constructor") {
|
|
1405
|
+
return [meta, sourceModule, signature || selector].filter((part) => part !== "").join(" ");
|
|
1406
|
+
}
|
|
1407
|
+
const parts = [selector, meta, sourceModule, signature].filter((part) => part !== "");
|
|
1408
|
+
return parts.join(" ");
|
|
1409
|
+
}
|
|
1410
|
+
function formatTopLevelSymbolLine(symbol, selector, signature, meta, sourceModule, context, config) {
|
|
1411
|
+
const display = typeof symbol.display === "string" ? symbol.display : "";
|
|
1412
|
+
if (display) {
|
|
1413
|
+
return [display, meta].filter((part) => part !== "").join(" ");
|
|
1414
|
+
}
|
|
1415
|
+
const decoratorPrefix = formatDecoratorPrefix(symbol);
|
|
1416
|
+
const exportKind = typeof symbol.exportKind === "string" ? symbol.exportKind : "";
|
|
1417
|
+
const exportTarget = formatExportTarget(symbol, config);
|
|
1418
|
+
if (exportKind === "default") {
|
|
1419
|
+
const prefix = context === "file" ? "export default " : "default ";
|
|
1420
|
+
const main = `${decoratorPrefix}${prefix}${exportTarget || selector}${formatTopLevelSignatureSuffix(symbol, signature)}`;
|
|
1421
|
+
return [main, meta, sourceModuleSuffix(main, sourceModule)].filter((part) => part !== "").join(" ");
|
|
1422
|
+
}
|
|
1423
|
+
if (exportKind === "exportEquals") {
|
|
1424
|
+
const main = `${decoratorPrefix}export = ${exportTarget || selector}`;
|
|
1425
|
+
return [main, meta, sourceModuleSuffix(main, sourceModule)].filter((part) => part !== "").join(" ");
|
|
1426
|
+
}
|
|
1427
|
+
const exportPrefix = context === "file" && symbol.exported === true ? "export " : "";
|
|
1428
|
+
const suffix = formatTopLevelSignatureSuffix(symbol, signature);
|
|
1429
|
+
const iifeSuffix = symbol.iife === true ? `${symbol.async === true ? " IIFE async" : " IIFE"}` : "";
|
|
1430
|
+
const overloadSuffix = formatOverloadSuffix(symbol);
|
|
1431
|
+
const main = `${decoratorPrefix}${exportPrefix}${selector}${suffix}${iifeSuffix}`;
|
|
1432
|
+
return [main, meta, overloadSuffix, sourceModuleSuffix(main, sourceModule)].filter((part) => part !== "").join(" ");
|
|
1433
|
+
}
|
|
1434
|
+
function sourceModuleSuffix(line, sourceModule) {
|
|
1435
|
+
if (!sourceModule) {
|
|
1436
|
+
return "";
|
|
1437
|
+
}
|
|
1438
|
+
return /\bfrom\s+["']?/.test(line) ? "" : sourceModule;
|
|
1439
|
+
}
|
|
1440
|
+
function formatSourceExportEntry(symbol, line, sourceModule) {
|
|
1441
|
+
const display = typeof symbol.display === "string" ? symbol.display : "";
|
|
1442
|
+
const exportLine = display || line;
|
|
1443
|
+
const namedExportMatch = exportLine.match(/\bexport\s+\{\s*(.*?)\s*\}\s+from\s+/);
|
|
1444
|
+
if (namedExportMatch?.[1]) {
|
|
1445
|
+
return namedExportMatch[1];
|
|
1446
|
+
}
|
|
1447
|
+
if (/^export\s+\*\s+from\s+/.test(display)) {
|
|
1448
|
+
return "*";
|
|
1449
|
+
}
|
|
1450
|
+
if (symbol.exportKind === "default") {
|
|
1451
|
+
return "default";
|
|
1452
|
+
}
|
|
1453
|
+
return line.replace(` from ${sourceModule}`, "");
|
|
1454
|
+
}
|
|
1455
|
+
function formatDecoratorPrefix(symbol) {
|
|
1456
|
+
if (!Array.isArray(symbol.decorators)) {
|
|
1457
|
+
return "";
|
|
1458
|
+
}
|
|
1459
|
+
const decorators = symbol.decorators
|
|
1460
|
+
.filter((item) => typeof item === "string" && item.trim() !== "")
|
|
1461
|
+
.join(" ");
|
|
1462
|
+
return decorators ? `${decorators} ` : "";
|
|
1463
|
+
}
|
|
1464
|
+
function formatExportTarget(symbol, config) {
|
|
1465
|
+
if (!(0, inspect_format_primitives_1.isObject)(symbol.exportTarget)) {
|
|
1466
|
+
return "";
|
|
1467
|
+
}
|
|
1468
|
+
return (0, inspect_symbol_format_1.formatSymbolReference)(symbol.exportTarget, config);
|
|
1469
|
+
}
|
|
1470
|
+
function formatTopLevelSignatureSuffix(symbol, signature) {
|
|
1471
|
+
if (typeof symbol.overloadCount === "number" && symbol.overloadCount > 1) {
|
|
1472
|
+
return "";
|
|
1473
|
+
}
|
|
1474
|
+
const name = typeof symbol.name === "string" ? symbol.name : "";
|
|
1475
|
+
const kind = typeof symbol.kind === "string" ? (0, inspect_symbol_format_1.normalizeKind)(symbol.kind) : null;
|
|
1476
|
+
if (!name || !signature) {
|
|
1477
|
+
return "";
|
|
1478
|
+
}
|
|
1479
|
+
if (kind !== "function" && kind !== "method") {
|
|
1480
|
+
return "";
|
|
1481
|
+
}
|
|
1482
|
+
const nameIndex = signature.indexOf(name);
|
|
1483
|
+
if (nameIndex < 0) {
|
|
1484
|
+
return "";
|
|
1485
|
+
}
|
|
1486
|
+
const suffix = signature.slice(nameIndex + name.length).trim();
|
|
1487
|
+
return suffix.startsWith("(") ? suffix : "";
|
|
1488
|
+
}
|
|
1489
|
+
function formatOverloadSuffix(symbol) {
|
|
1490
|
+
const overloadCount = typeof symbol.overloadCount === "number" ? symbol.overloadCount : 0;
|
|
1491
|
+
return overloadCount > 1 ? `overloads=${overloadCount}` : "";
|
|
1492
|
+
}
|
|
1493
|
+
function formatMemberSymbolLine(symbol, selector, signature, meta) {
|
|
1494
|
+
const kind = typeof symbol.kind === "string" ? (0, inspect_symbol_format_1.normalizeKind)(symbol.kind) : null;
|
|
1495
|
+
const name = typeof symbol.name === "string" ? symbol.name : "";
|
|
1496
|
+
let line = `${formatDecoratorPrefix(symbol)}${signature || stripSelectorPrefix(selector)}`.trim();
|
|
1497
|
+
if (kind === "property" && name) {
|
|
1498
|
+
line = `${formatDecoratorPrefix(symbol)}${selector}`.trim();
|
|
1499
|
+
const suffix = extractPropertySignatureSuffix(signature, name);
|
|
1500
|
+
if (suffix) {
|
|
1501
|
+
line += suffix;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
return [line, meta].filter((part) => part !== "").join(" ");
|
|
1505
|
+
}
|
|
1506
|
+
function extractPropertySignatureSuffix(signature, name) {
|
|
1507
|
+
if (!signature) {
|
|
1508
|
+
return "";
|
|
1509
|
+
}
|
|
1510
|
+
const nameIndex = signature.indexOf(name);
|
|
1511
|
+
if (nameIndex < 0) {
|
|
1512
|
+
return "";
|
|
1513
|
+
}
|
|
1514
|
+
const suffix = signature.slice(nameIndex + name.length).trim();
|
|
1515
|
+
return suffix.startsWith(":") ? suffix : "";
|
|
1516
|
+
}
|
|
1517
|
+
function formatErrorResult(rawResult, options, commonFile) {
|
|
1518
|
+
const result = pickFields(rawResult, ["id", "op", "ok", "code", "error"]);
|
|
1519
|
+
if (typeof rawResult.sourceFile === "string") {
|
|
1520
|
+
const file = (0, inspect_format_primitives_1.formatFilePath)(rawResult.sourceFile, options);
|
|
1521
|
+
if (file !== commonFile) {
|
|
1522
|
+
result.file = file;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
if (rawResult.code === "INSPECT_SYMBOL_NOT_FOUND") {
|
|
1526
|
+
const missing = readMissingSymbolFromError(rawResult);
|
|
1527
|
+
if (missing) {
|
|
1528
|
+
result.missingSymbols = [missing];
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return result;
|
|
1532
|
+
}
|
|
1533
|
+
function readMissingSymbolFromError(rawResult) {
|
|
1534
|
+
const error = typeof rawResult.error === "string" ? rawResult.error : "";
|
|
1535
|
+
const prefix = "Symbol not found:";
|
|
1536
|
+
if (!error.startsWith(prefix)) {
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
const value = error.slice(prefix.length).trim();
|
|
1540
|
+
if (!value) {
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
const kindSeparator = value.indexOf(":");
|
|
1544
|
+
return kindSeparator > 0 ? value.slice(kindSeparator + 1).trim() : value;
|
|
1545
|
+
}
|
|
1546
|
+
function stripSelectorPrefix(value) {
|
|
1547
|
+
const dashIndex = value.indexOf("-");
|
|
1548
|
+
if (dashIndex > 0 && dashIndex <= 3) {
|
|
1549
|
+
return value.slice(dashIndex + 1);
|
|
1550
|
+
}
|
|
1551
|
+
const colonIndex = value.indexOf(":");
|
|
1552
|
+
if (colonIndex > 0) {
|
|
1553
|
+
return value.slice(colonIndex + 1);
|
|
1554
|
+
}
|
|
1555
|
+
return value;
|
|
1556
|
+
}
|
|
1557
|
+
function visibleCount(field, count) {
|
|
1558
|
+
return count > INSPECT_COUNT_VISIBLE_THRESHOLD ? { [field]: count } : {};
|
|
1559
|
+
}
|
|
1560
|
+
function pickFields(source, fields) {
|
|
1561
|
+
const result = {};
|
|
1562
|
+
for (const field of fields) {
|
|
1563
|
+
if (source[field] !== undefined) {
|
|
1564
|
+
result[field] = source[field];
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return result;
|
|
1568
|
+
}
|
|
1569
|
+
function commonSourceFile(rawResults, options) {
|
|
1570
|
+
const files = rawResults
|
|
1571
|
+
.filter(inspect_format_primitives_1.isObject)
|
|
1572
|
+
.map((result) => typeof result.sourceFile === "string" ? (0, inspect_format_primitives_1.formatFilePath)(result.sourceFile, options) : null)
|
|
1573
|
+
.filter((value) => Boolean(value));
|
|
1574
|
+
const uniqueFiles = Array.from(new Set(files));
|
|
1575
|
+
return uniqueFiles.length === 1 ? uniqueFiles[0] ?? null : null;
|
|
1576
|
+
}
|
|
1577
|
+
function writeInspectOutputFile(cwd, targetPath, content) {
|
|
1578
|
+
const absolutePath = path.isAbsolute(targetPath) ? targetPath : path.resolve(cwd, targetPath);
|
|
1579
|
+
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
1580
|
+
fs.writeFileSync(absolutePath, content, "utf8");
|
|
1581
|
+
return path.relative(cwd, absolutePath).replace(/\\/g, "/");
|
|
1582
|
+
}
|
|
1583
|
+
function saveInspectOutput(cwd, kind, name, rawResult, content) {
|
|
1584
|
+
const extension = typeof rawResult.sourceFile === "string" ? path.extname(rawResult.sourceFile) || ".ts" : ".ts";
|
|
1585
|
+
const saved = (0, session_workspace_1.saveSessionOutputText)(cwd, kind, name, content, extension);
|
|
1586
|
+
return {
|
|
1587
|
+
saved: saved.saved,
|
|
1588
|
+
last: saved.last
|
|
1589
|
+
};
|
|
1590
|
+
}
|