@automaton-labs/aib 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/README.md +21 -578
  2. package/config/agent-dx-policy.default.json +31 -0
  3. package/config/control-plane-client.default.json +3 -0
  4. package/dist/agent-dx/agent-dx.js +805 -0
  5. package/dist/agent-dx/presentation.js +32 -0
  6. package/dist/alias-advisor/analyze.js +982 -0
  7. package/dist/alias-advisor/exact-text-cost.js +74 -0
  8. package/dist/alias-advisor/lexical.js +240 -0
  9. package/dist/alias-advisor/model.js +2 -0
  10. package/dist/alias-advisor/path-identity.js +49 -0
  11. package/dist/alias-advisor/ranking.js +171 -0
  12. package/dist/alias-advisor/token-estimator.js +85 -0
  13. package/dist/bin/aib.js +5 -1
  14. package/dist/bin/cli.js +811 -4
  15. package/dist/commands/add-missing-imports-preview-cache.js +99 -2
  16. package/dist/commands/add-missing-imports.js +241 -2
  17. package/dist/commands/apply-module-plan.js +1319 -3
  18. package/dist/commands/background-command.js +378 -2
  19. package/dist/commands/captured-input.js +74 -1
  20. package/dist/commands/config-command.js +314 -2
  21. package/dist/commands/config-output.js +357 -10
  22. package/dist/commands/control-plane-command.js +183 -1
  23. package/dist/commands/declaration-command.js +1209 -7
  24. package/dist/commands/declaration-execution-cache.js +79 -1
  25. package/dist/commands/declaration-format.js +221 -1
  26. package/dist/commands/declaration-preview-cache.js +114 -2
  27. package/dist/commands/diagnostics-command.js +70 -3
  28. package/dist/commands/doctor.js +137 -3
  29. package/dist/commands/execution-command.js +117 -1
  30. package/dist/commands/exports-star-collapse-command.js +178 -0
  31. package/dist/commands/exports-star-command.js +252 -0
  32. package/dist/commands/exports-star-preview-cache.js +84 -0
  33. package/dist/commands/feedback-command.js +176 -3
  34. package/dist/commands/file-move-to-dir-execution-cache.js +92 -1
  35. package/dist/commands/file-move-to-dir-preview-cache.js +125 -2
  36. package/dist/commands/file-move-to-dir-worker.js +54 -0
  37. package/dist/commands/file-move-to-dir.js +1073 -5
  38. package/dist/commands/file-mutation-runtime.js +102 -1
  39. package/dist/commands/file-mutation-worker-apply.js +180 -0
  40. package/dist/commands/file-refactor-batch-execution-cache.js +90 -1
  41. package/dist/commands/file-refactor-batch-preview-cache.js +125 -2
  42. package/dist/commands/file-refactor-batch-worker.js +54 -0
  43. package/dist/commands/file-refactor-batch.js +1154 -5
  44. package/dist/commands/file-rename-execution-cache.js +92 -1
  45. package/dist/commands/file-rename-preview-cache.js +125 -2
  46. package/dist/commands/file-rename-worker.js +54 -0
  47. package/dist/commands/file-rename.js +1053 -5
  48. package/dist/commands/file-text-edit-executor.js +205 -0
  49. package/dist/commands/find-importers.js +52 -1
  50. package/dist/commands/find-unused-imports.js +55 -1
  51. package/dist/commands/generate-docs-command.js +244 -6
  52. package/dist/commands/help-command.js +460 -7
  53. package/dist/commands/import-specifier-policy.js +391 -0
  54. package/dist/commands/imports-command.js +68 -1
  55. package/dist/commands/imports-rebase.js +1138 -0
  56. package/dist/commands/init-skill-usage.js +92 -3
  57. package/dist/commands/init-workspace.js +30 -1
  58. package/dist/commands/inspect-alias-candidates.js +413 -0
  59. package/dist/commands/inspect-cycles.js +811 -5
  60. package/dist/commands/inspect-direct-usages.js +98 -0
  61. package/dist/commands/inspect-duplicates-format.js +229 -0
  62. package/dist/commands/inspect-format-primitives.js +127 -0
  63. package/dist/commands/inspect-format.js +1590 -18
  64. package/dist/commands/inspect-graph.js +1553 -9
  65. package/dist/commands/inspect-imports.js +339 -2
  66. package/dist/commands/inspect-mixed-format.js +524 -0
  67. package/dist/commands/inspect-module-plan-format.js +216 -0
  68. package/dist/commands/inspect-module-plan-serialization.js +402 -0
  69. package/dist/commands/inspect-reference-path-format.js +157 -0
  70. package/dist/commands/inspect-request-values.js +599 -0
  71. package/dist/commands/inspect-selector-kind.js +21 -0
  72. package/dist/commands/inspect-selector.js +50 -0
  73. package/dist/commands/inspect-symbol-format.js +90 -0
  74. package/dist/commands/inspect-topology.js +435 -0
  75. package/dist/commands/inspect-tree.js +827 -5
  76. package/dist/commands/inspect-usages-detail.js +793 -0
  77. package/dist/commands/inspect-usages-evidence.js +31 -0
  78. package/dist/commands/inspect-usages-format.js +367 -0
  79. package/dist/commands/inspect.js +1450 -16
  80. package/dist/commands/internal-command.js +64 -0
  81. package/dist/commands/json-file-input.js +60 -1
  82. package/dist/commands/module-plan-cache.js +156 -2
  83. package/dist/commands/module-plan-standalone.js +208 -0
  84. package/dist/commands/module-plan-timeout.js +77 -1
  85. package/dist/commands/move-preview-cache.js +101 -2
  86. package/dist/commands/mutate-aggregate-output.js +996 -0
  87. package/dist/commands/mutate-child-execution.js +374 -0
  88. package/dist/commands/mutate-command.js +1394 -0
  89. package/dist/commands/mutate-declaration-output.js +313 -0
  90. package/dist/commands/mutate-domain-adapters.js +638 -0
  91. package/dist/commands/mutate-execution-cache.js +114 -0
  92. package/dist/commands/mutate-execution-status.js +598 -0
  93. package/dist/commands/mutate-failure-output.js +531 -0
  94. package/dist/commands/mutate-file-view.js +151 -0
  95. package/dist/commands/mutate-object-output.js +91 -0
  96. package/dist/commands/mutate-output-values.js +97 -0
  97. package/dist/commands/mutate-preview-cache.js +86 -0
  98. package/dist/commands/mutate-response-replay.js +153 -0
  99. package/dist/commands/mutate-result-projection.js +818 -0
  100. package/dist/commands/mutation-eta.js +28 -0
  101. package/dist/commands/mutation-execution-cache.js +140 -3
  102. package/dist/commands/mutation-recovery-journal.js +195 -0
  103. package/dist/commands/normalize-imports.js +1120 -4
  104. package/dist/commands/object-pack-command.js +546 -0
  105. package/dist/commands/object-pack-preview-cache.js +88 -0
  106. package/dist/commands/observability-command.js +47 -3
  107. package/dist/commands/ota-command.js +403 -2
  108. package/dist/commands/print-config.js +10 -1
  109. package/dist/commands/quick-read.js +1113 -11
  110. package/dist/commands/refactor-batch-builder.js +265 -1
  111. package/dist/commands/refactor-batch-execution-cache.js +85 -1
  112. package/dist/commands/refactor-batch-preview-cache.js +96 -2
  113. package/dist/commands/refactor-batch.js +461 -4
  114. package/dist/commands/rename-entities.js +794 -4
  115. package/dist/commands/rename-execution-cache.js +49 -1
  116. package/dist/commands/rename-input.js +22 -1
  117. package/dist/commands/rename-polling-policy.js +68 -0
  118. package/dist/commands/rename-preview-cache.js +96 -2
  119. package/dist/commands/result-view.js +993 -7
  120. package/dist/commands/reveal-command.js +445 -5
  121. package/dist/commands/selector-suggestions.js +93 -0
  122. package/dist/commands/session-workspace.js +1836 -31
  123. package/dist/commands/shared.js +2 -1
  124. package/dist/commands/skills-command.js +315 -0
  125. package/dist/commands/sync-command.js +59 -2
  126. package/dist/commands/worker-command.js +173 -1
  127. package/dist/commands/workspace-cache.js +55 -1
  128. package/dist/config/defaults.js +26 -1
  129. package/dist/config/env-vars.js +77 -1
  130. package/dist/config/glob-match.js +44 -1
  131. package/dist/config/import-rules.js +165 -1
  132. package/dist/config/local-config.js +293 -3
  133. package/dist/config/mutation-comments.js +51 -1
  134. package/dist/config/path-aliases.js +165 -1
  135. package/dist/config/path-display.js +84 -1
  136. package/dist/config/product-storage.js +37 -1
  137. package/dist/config/request-env.js +21 -0
  138. package/dist/config/request-routing-context.js +23 -0
  139. package/dist/config/resolve-command-alias.js +74 -1
  140. package/dist/config/resolve.js +24 -1
  141. package/dist/config/tsconfig-discovery.js +113 -1
  142. package/dist/config/typescript-preferences.js +131 -0
  143. package/dist/config/workspace-root.js +310 -3
  144. package/dist/config/workspace-state.js +254 -1
  145. package/dist/content/content-bundle.js +88 -1
  146. package/dist/diagnostics/module-plan-timeline.js +75 -2
  147. package/dist/diagnostics/readiness-text.js +45 -8
  148. package/dist/dsl/aib-dsl.js +838 -1
  149. package/dist/dsl/declaration-dsl.js +264 -1
  150. package/dist/dsl/file-move-to-dir-dsl.js +123 -1
  151. package/dist/dsl/file-refactor-batch-dsl.js +203 -1
  152. package/dist/dsl/file-rename-dsl.js +135 -1
  153. package/dist/dsl/mutate-dsl.js +746 -0
  154. package/dist/help/bootstrap.bash.md +176 -341
  155. package/dist/help/bootstrap.md +175 -340
  156. package/dist/help/bootstrap.pwsh.md +176 -341
  157. package/dist/help/docs/basics.md +1 -1
  158. package/dist/help/docs/config-setup.import-normalize.md +65 -65
  159. package/dist/help/docs/config-setup.import-rules.md +6 -5
  160. package/dist/help/docs/first-setup.md +6 -5
  161. package/dist/help/docs/help-protocol.md +4 -3
  162. package/dist/help/docs/import.base.md +38 -0
  163. package/dist/help/docs/import.rebase.md +85 -0
  164. package/dist/help/docs/inspect.aliasCandidates.md +39 -0
  165. package/dist/help/docs/inspect.code.md +1 -7
  166. package/dist/help/docs/inspect.file.md +10 -19
  167. package/dist/help/docs/inspect.graph.md +3 -17
  168. package/dist/help/{dsl/docs/inspect.md → docs/inspect.shared.md} +13 -12
  169. package/dist/help/docs/modulePlan.md +24 -28
  170. package/dist/help/docs/move.md +19 -22
  171. package/dist/help/{dsl/topics/file.move.md → docs/moveToDir.md} +36 -34
  172. package/dist/help/docs/mutate.mixed.md +34 -0
  173. package/dist/help/docs/mutation.shared.md +55 -0
  174. package/dist/help/docs/patterns.md +3 -12
  175. package/dist/help/docs/qr.md +12 -6
  176. package/dist/help/docs/quick-map.md +36 -24
  177. package/dist/help/docs/recipe.file-layout.md +10 -10
  178. package/dist/help/docs/recipe.import-boundary.md +92 -0
  179. package/dist/help/docs/recipe.safe-artifact-probing.md +68 -0
  180. package/dist/help/docs/recipe.unfamiliar-area.md +64 -0
  181. package/dist/help/docs/recipes.md +20 -0
  182. package/dist/help/docs/rename.md +19 -27
  183. package/dist/help/docs/renameFile.md +36 -0
  184. package/dist/help/docs/rules.md +26 -0
  185. package/dist/help/dsl/bootstrap.bash.md +176 -341
  186. package/dist/help/dsl/bootstrap.md +175 -340
  187. package/dist/help/dsl/bootstrap.pwsh.md +176 -341
  188. package/dist/help/dsl/docs/basics.md +1 -1
  189. package/dist/help/dsl/docs/config-setup.import-normalize.md +65 -65
  190. package/dist/help/dsl/docs/config-setup.import-rules.md +6 -5
  191. package/dist/help/dsl/docs/first-setup.md +6 -5
  192. package/dist/help/dsl/docs/help-protocol.md +4 -3
  193. package/dist/help/dsl/docs/import.base.md +38 -0
  194. package/dist/help/dsl/docs/import.rebase.md +85 -0
  195. package/dist/help/dsl/docs/inspect.aliasCandidates.md +39 -0
  196. package/dist/help/dsl/docs/inspect.code.md +1 -7
  197. package/dist/help/dsl/docs/inspect.file.md +10 -19
  198. package/dist/help/dsl/docs/inspect.graph.md +3 -17
  199. package/dist/help/{docs/inspect.md → dsl/docs/inspect.shared.md} +13 -12
  200. package/dist/help/dsl/docs/modulePlan.md +24 -28
  201. package/dist/help/dsl/docs/move.md +19 -22
  202. package/dist/help/{topics/file.move.md → dsl/docs/moveToDir.md} +36 -34
  203. package/dist/help/dsl/docs/mutate.mixed.md +34 -0
  204. package/dist/help/dsl/docs/mutation.shared.md +55 -0
  205. package/dist/help/dsl/docs/patterns.md +3 -12
  206. package/dist/help/dsl/docs/qr.md +12 -6
  207. package/dist/help/dsl/docs/quick-map.md +36 -24
  208. package/dist/help/dsl/docs/recipe.file-layout.md +10 -10
  209. package/dist/help/dsl/docs/recipe.import-boundary.md +92 -0
  210. package/dist/help/dsl/docs/recipe.safe-artifact-probing.md +68 -0
  211. package/dist/help/dsl/docs/recipe.unfamiliar-area.md +64 -0
  212. package/dist/help/dsl/docs/recipes.md +20 -0
  213. package/dist/help/dsl/docs/rename.md +19 -27
  214. package/dist/help/dsl/docs/renameFile.md +36 -0
  215. package/dist/help/dsl/docs/rules.md +26 -0
  216. package/dist/help/dsl/full.md +175 -340
  217. package/dist/help/dsl/help-index.md +48 -43
  218. package/dist/help/dsl/snippets/agents.md +2 -2
  219. package/dist/help/dsl/tokens/qr.inline.examples.md +1 -1
  220. package/dist/help/dsl/topics/basics.md +1 -1
  221. package/dist/help/dsl/topics/config-setup.import-normalize.md +65 -65
  222. package/dist/help/dsl/topics/config-setup.import-rules.md +6 -5
  223. package/dist/help/dsl/topics/first-setup.md +6 -5
  224. package/dist/help/dsl/topics/help-protocol.md +4 -3
  225. package/dist/help/dsl/topics/import.base.md +36 -0
  226. package/dist/help/dsl/topics/import.rebase.md +83 -0
  227. package/dist/help/dsl/topics/inspect.aliasCandidates.md +37 -0
  228. package/dist/help/dsl/topics/inspect.code.md +1 -7
  229. package/dist/help/dsl/topics/inspect.file.md +10 -19
  230. package/dist/help/dsl/topics/inspect.graph.md +3 -17
  231. package/dist/help/dsl/topics/{inspect.md → inspect.shared.md} +13 -12
  232. package/dist/help/dsl/topics/modulePlan.md +21 -26
  233. package/dist/help/dsl/topics/move.md +17 -18
  234. package/dist/help/{docs/file.move.md → dsl/topics/moveToDir.md} +33 -35
  235. package/dist/help/dsl/topics/mutate.mixed.md +32 -0
  236. package/dist/help/dsl/topics/mutation.shared.md +53 -0
  237. package/dist/help/dsl/topics/patterns.md +3 -12
  238. package/dist/help/dsl/topics/qr.md +12 -6
  239. package/dist/help/dsl/topics/quick-map.md +36 -24
  240. package/dist/help/dsl/topics/recipe.file-layout.md +10 -10
  241. package/dist/help/dsl/topics/recipe.import-boundary.md +90 -0
  242. package/dist/help/dsl/topics/recipe.safe-artifact-probing.md +66 -0
  243. package/dist/help/dsl/topics/recipe.unfamiliar-area.md +62 -0
  244. package/dist/help/dsl/topics/recipes.md +18 -0
  245. package/dist/help/dsl/topics/rename.md +15 -15
  246. package/dist/help/dsl/topics/renameFile.md +34 -0
  247. package/dist/help/dsl/topics/rules.md +24 -0
  248. package/dist/help/full.md +175 -340
  249. package/dist/help/help-index.md +48 -43
  250. package/dist/help/help-meta.json +98 -48
  251. package/dist/help/index.md +52 -20
  252. package/dist/help/snippets/agents.md +2 -2
  253. package/dist/help/tokens/qr.inline.examples.md +1 -1
  254. package/dist/help/topics/basics.md +1 -1
  255. package/dist/help/topics/config-setup.import-normalize.md +65 -65
  256. package/dist/help/topics/config-setup.import-rules.md +6 -5
  257. package/dist/help/topics/first-setup.md +6 -5
  258. package/dist/help/topics/help-protocol.md +4 -3
  259. package/dist/help/topics/import.base.md +36 -0
  260. package/dist/help/topics/import.rebase.md +83 -0
  261. package/dist/help/topics/inspect.aliasCandidates.md +37 -0
  262. package/dist/help/topics/inspect.code.md +1 -7
  263. package/dist/help/topics/inspect.file.md +10 -19
  264. package/dist/help/topics/inspect.graph.md +3 -17
  265. package/dist/help/topics/{inspect.md → inspect.shared.md} +13 -12
  266. package/dist/help/topics/modulePlan.md +21 -26
  267. package/dist/help/topics/move.md +17 -18
  268. package/dist/help/{dsl/docs/file.move.md → topics/moveToDir.md} +33 -35
  269. package/dist/help/topics/mutate.mixed.md +32 -0
  270. package/dist/help/topics/mutation.shared.md +53 -0
  271. package/dist/help/topics/patterns.md +3 -12
  272. package/dist/help/topics/qr.md +12 -6
  273. package/dist/help/topics/quick-map.md +36 -24
  274. package/dist/help/topics/recipe.file-layout.md +10 -10
  275. package/dist/help/topics/recipe.import-boundary.md +90 -0
  276. package/dist/help/topics/recipe.safe-artifact-probing.md +66 -0
  277. package/dist/help/topics/recipe.unfamiliar-area.md +62 -0
  278. package/dist/help/topics/recipes.md +18 -0
  279. package/dist/help/topics/rename.md +15 -15
  280. package/dist/help/topics/renameFile.md +34 -0
  281. package/dist/help/topics/rules.md +24 -0
  282. package/dist/host/capabilities.js +56 -1
  283. package/dist/imports/standalone-import-analysis.js +602 -0
  284. package/dist/imports/standalone-import-model.js +2 -0
  285. package/dist/imports/standalone-import-process.js +66 -0
  286. package/dist/imports/standalone-import-worker.js +27 -0
  287. package/dist/imports/standalone-ts-project.js +147 -0
  288. package/dist/inspect/inspect-duplicates-service.js +526 -0
  289. package/dist/inspect/inspect-reverse-module-closure.js +338 -0
  290. package/dist/inspect/inspect-source-ranges.js +82 -0
  291. package/dist/inspect/inspect-source-shape.js +649 -0
  292. package/dist/inspect/standalone-inspect-analysis.js +319 -0
  293. package/dist/inspect/standalone-inspect-model.js +9 -0
  294. package/dist/inspect/standalone-inspect-process.js +55 -0
  295. package/dist/inspect/standalone-inspect-usages.js +274 -0
  296. package/dist/inspect/standalone-inspect-worker.js +13 -0
  297. package/dist/metrics/central-metrics.js +101 -2
  298. package/dist/mutation/concrete-edit-plan.js +157 -0
  299. package/dist/mutation/exports-star-collapse-preview.js +361 -0
  300. package/dist/mutation/exports-star-expand-apply.js +373 -0
  301. package/dist/mutation/exports-star-expand-preview.js +807 -0
  302. package/dist/mutation/file-impact-scan.js +182 -0
  303. package/dist/mutation/file-mutation-discovery.js +674 -0
  304. package/dist/mutation/file-mutation-eta.js +99 -0
  305. package/dist/mutation/file-mutation-standalone-apply.js +584 -0
  306. package/dist/mutation/file-mutation-standalone-planner.js +500 -0
  307. package/dist/mutation/file-mutation-tsserver-session.js +473 -0
  308. package/dist/mutation/mutation-estimate.js +45 -0
  309. package/dist/mutation/mutation-plan.js +467 -0
  310. package/dist/mutation/object-mutation-foundation.js +2 -0
  311. package/dist/mutation/object-mutation-partition.js +148 -0
  312. package/dist/mutation/object-pack-semantic-apply.js +507 -0
  313. package/dist/mutation/object-pack-semantic-preview.js +984 -0
  314. package/dist/mutation/object-unpack-semantic-preview.js +993 -0
  315. package/dist/mutation/package-manifest-impact.js +176 -0
  316. package/dist/mutation/rename-owner-worker-child.js +37 -0
  317. package/dist/mutation/rename-owner-worker.js +122 -0
  318. package/dist/mutation/runtime-cycle-query.js +66 -0
  319. package/dist/mutation/semantic-execution-progress.js +63 -0
  320. package/dist/mutation/semantic-export-index.js +474 -0
  321. package/dist/mutation/semantic-impact-scan.js +434 -0
  322. package/dist/mutation/semantic-model.js +2 -0
  323. package/dist/mutation/semantic-move-best-effort-planner.js +209 -0
  324. package/dist/mutation/semantic-move-config-worker-child.js +61 -0
  325. package/dist/mutation/semantic-move-config-worker.js +449 -0
  326. package/dist/mutation/semantic-move-declarations.js +94 -0
  327. package/dist/mutation/semantic-move-metrics.js +119 -0
  328. package/dist/mutation/semantic-move-model.js +2 -0
  329. package/dist/mutation/semantic-move-owner-authority.js +122 -0
  330. package/dist/mutation/semantic-move-owner-candidates.js +300 -0
  331. package/dist/mutation/semantic-move-owner-divergence-harness.js +474 -0
  332. package/dist/mutation/semantic-move-owner-divergence-runner.js +162 -0
  333. package/dist/mutation/semantic-move-plan-hash.js +56 -0
  334. package/dist/mutation/semantic-move-policy.js +360 -0
  335. package/dist/mutation/semantic-move-process.js +218 -0
  336. package/dist/mutation/semantic-move-provider-diagnostics.js +27 -0
  337. package/dist/mutation/semantic-move-standalone-engine.js +919 -0
  338. package/dist/mutation/semantic-move-standalone-planner.js +1553 -0
  339. package/dist/mutation/semantic-move-transaction.js +639 -0
  340. package/dist/mutation/semantic-mutation-engine.js +478 -0
  341. package/dist/mutation/semantic-mutation-runtime.js +521 -0
  342. package/dist/mutation/semantic-planner-retry.js +26 -0
  343. package/dist/mutation/semantic-program-roots.js +69 -0
  344. package/dist/mutation/semantic-rename-commonjs.js +229 -0
  345. package/dist/mutation/semantic-rename-config-worker-child.js +46 -0
  346. package/dist/mutation/semantic-rename-config-worker.js +498 -0
  347. package/dist/mutation/semantic-rename-locations.js +192 -0
  348. package/dist/mutation/semantic-rename-model.js +2 -0
  349. package/dist/mutation/semantic-rename-process.js +217 -0
  350. package/dist/mutation/semantic-rename-standalone-engine.js +302 -0
  351. package/dist/mutation/semantic-rename-standalone-planner.js +567 -0
  352. package/dist/mutation/semantic-rename-transaction.js +333 -0
  353. package/dist/mutation/semantic-unused-import-cleanup.js +248 -0
  354. package/dist/mutation/semantic-worker-retry.js +40 -0
  355. package/dist/mutation/semantic-workspace.js +804 -0
  356. package/dist/mutation/targeted-import-canonicalizer.js +359 -0
  357. package/dist/observability/config.js +206 -1
  358. package/dist/observability/context.js +59 -1
  359. package/dist/observability/failure-snapshot.js +124 -2
  360. package/dist/observability/recent.js +63 -2
  361. package/dist/payloads/read-stdin-json.js +212 -1
  362. package/dist/rg-wrapper/core.js +714 -6
  363. package/dist/rg-wrapper/options.js +125 -1
  364. package/dist/rtk-wrapper/core.js +144 -2
  365. package/dist/rtk-wrapper/git-safety.js +203 -0
  366. package/dist/rtk-wrapper/output-adapter.js +106 -0
  367. package/dist/runtime/buffered-process.js +114 -0
  368. package/dist/runtime/bundled-node.js +97 -1
  369. package/dist/runtime/command-lifecycle.js +2 -0
  370. package/dist/runtime/input-source.js +238 -1
  371. package/dist/runtime/node-cli-identity.js +37 -0
  372. package/dist/runtime/run-command.js +191 -1
  373. package/dist/selectors/parse-entities.js +84 -1
  374. package/dist/semantic/semantic-context-pool.js +830 -0
  375. package/dist/semantic/semantic-context-provider.js +416 -0
  376. package/dist/semantic/semantic-resident-admission.js +38 -0
  377. package/dist/semantic/semantic-worker-child.js +40 -0
  378. package/dist/semantic/semantic-worker-manager.js +460 -0
  379. package/dist/semantic/semantic-worker-protocol.js +2 -0
  380. package/dist/semantic/semantic-worker-runtime.js +38 -0
  381. package/dist/semantic/workspace-semantic-context-pools.js +136 -0
  382. package/dist/session/client.js +359 -1
  383. package/dist/session/daemon-state.js +185 -2
  384. package/dist/session/external-tool-coordinator.js +88 -0
  385. package/dist/session/external-tool-request.js +52 -0
  386. package/dist/session/lane-owner.js +116 -0
  387. package/dist/session/paths.js +71 -1
  388. package/dist/session/runtime-lifecycle.js +225 -0
  389. package/dist/session/runtime-shutdown.js +95 -0
  390. package/dist/session/server.js +1194 -7
  391. package/dist/session/session-health.js +27 -0
  392. package/dist/shared/agent-text.js +29 -1
  393. package/dist/shared/errors.js +496 -30
  394. package/dist/shared/event-loop.js +6 -1
  395. package/dist/shared/hints.js +37 -1
  396. package/dist/shared/metrics.js +43 -1
  397. package/dist/shared/presentation.js +69 -4
  398. package/dist/shared/stdin-examples.js +77 -1
  399. package/dist/shared/stdout.js +6 -2
  400. package/dist/shared/types.js +23 -1
  401. package/dist/tool-runtime/runtime-tools.js +120 -1
  402. package/dist/topology/availability.js +663 -0
  403. package/dist/topology/cache.js +130 -0
  404. package/dist/topology/candidates.js +372 -0
  405. package/dist/topology/core.js +903 -0
  406. package/dist/topology/dependency-snapshot.js +189 -0
  407. package/dist/topology/model.js +2 -0
  408. package/dist/topology/scope.js +100 -0
  409. package/dist/topology/ts-oracle-batch.js +529 -0
  410. package/dist/topology/ts-oracle-host.js +69 -0
  411. package/dist/topology/ts-oracle-model.js +2 -0
  412. package/dist/topology/ts-oracle.js +224 -0
  413. package/dist/topology/tsconfig-loader.js +105 -0
  414. package/dist/topology/workspace-project-index.js +542 -0
  415. package/dist/tracing/config.js +192 -2
  416. package/dist/tracing/failure-summary.js +100 -0
  417. package/dist/tracing/trace.js +318 -5
  418. package/dist/tsc-wrapper/core.js +697 -0
  419. package/dist/workers/control-plane/aib-control-plane-worker.cjs +32 -32
  420. package/dist/workers/control-plane/client-config.default.json +3 -3
  421. package/dist/workers/lexical-worker-child.js +27 -0
  422. package/dist/workers/lexical-worker-manager.js +394 -0
  423. package/dist/workers/lexical-worker-protocol.js +2 -0
  424. package/dist/workers/lexical-worker-runtime.js +25 -0
  425. package/dist/workers/owned-one-shot-process.js +115 -0
  426. package/dist/workers/product-storage.js +23 -1
  427. package/dist/workers/registry.js +241 -1
  428. package/package.json +8 -13
  429. package/scripts/postinstall.cjs +29 -29
  430. package/scripts/provision-runtime.cjs +411 -459
  431. package/dist/client/http-client.js +0 -1
  432. package/dist/client/transport-options.js +0 -1
  433. package/dist/client/websocket-client.js +0 -1
  434. package/dist/commands/entity-resolution.js +0 -1
  435. package/dist/commands/file-command.js +0 -1
  436. package/dist/commands/host-command.js +0 -1
  437. package/dist/commands/inspect-symbol-query.js +0 -1
  438. package/dist/commands/list-instances.js +0 -1
  439. package/dist/commands/module-plan-command.js +0 -1
  440. package/dist/commands/move-command.js +0 -1
  441. package/dist/commands/move-to-file.js +0 -2
  442. package/dist/commands/ping.js +0 -1
  443. package/dist/commands/refactor-command.js +0 -1
  444. package/dist/commands/rename-command.js +0 -1
  445. package/dist/commands/runtime-command.js +0 -4
  446. package/dist/commands/runtime-info.js +0 -1
  447. package/dist/commands/validate-module-plan.js +0 -2
  448. package/dist/compatibility/policy.js +0 -1
  449. package/dist/config/auto-start-ide.js +0 -1
  450. package/dist/discovery/registry.js +0 -1
  451. package/dist/discovery/select-instance.js +0 -1
  452. package/dist/help/docs/file.rename.md +0 -35
  453. package/dist/help/docs/mutation.md +0 -60
  454. package/dist/help/docs/refactor.batch.md +0 -44
  455. package/dist/help/dsl/docs/file.rename.md +0 -35
  456. package/dist/help/dsl/docs/mutation.md +0 -60
  457. package/dist/help/dsl/docs/refactor.batch.md +0 -44
  458. package/dist/help/dsl/topics/file.rename.md +0 -33
  459. package/dist/help/dsl/topics/mutation.md +0 -58
  460. package/dist/help/dsl/topics/refactor.batch.md +0 -33
  461. package/dist/help/topics/file.rename.md +0 -33
  462. package/dist/help/topics/mutation.md +0 -58
  463. package/dist/help/topics/refactor.batch.md +0 -33
  464. package/dist/ide-launch/common.cjs +0 -162
  465. package/dist/managed-host/extension-vsix-resolver.js +0 -1
  466. package/dist/managed-host/manage-serve-web-host.cjs +0 -141
  467. package/dist/managed-host/serve-web-autostart.js +0 -1
  468. package/dist/managed-host/serve-web-host.cjs +0 -2115
  469. package/dist/runtime/managed-runtime-provisioning.js +0 -1
  470. package/dist/shared/diagnostic-catalog.js +0 -1
  471. package/dist/shared/diagnostics.js +0 -1
  472. package/dist/shared/operations.js +0 -1
  473. package/dist/shared/protocol.js +0 -1
  474. package/dist/shared/routes.js +0 -1
  475. package/extension/vscode-refactor-bridge-extension.vsix +0 -0
  476. package/runtimes/launcher/linux-x64/aib +0 -0
  477. package/runtimes/launcher/win-x64/aib.exe +0 -0
@@ -1,18 +1,1590 @@
1
- "use strict";var at=exports&&exports.__createBinding||(Object.create?(function(e,n,t,r){r===void 0&&(r=t);var s=Object.getOwnPropertyDescriptor(n,t);(!s||("get"in s?!n.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,s)}):(function(e,n,t,r){r===void 0&&(r=t),e[r]=n[t]})),ut=exports&&exports.__setModuleDefault||(Object.create?(function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}):function(e,n){e.default=n}),ve=exports&&exports.__importStar||(function(){var e=function(n){return e=Object.getOwnPropertyNames||function(t){var r=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(r[r.length]=s);return r},e(n)};return function(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var r=e(n),s=0;s<r.length;s++)r[s]!=="default"&&at(t,n,r[s]);return ut(t,n),t}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseInspectSelector=St,exports.formatInspectResponse=Ct,exports.formatInspectMixedAgentText=Ft;const b=ve(require("node:path")),U=ve(require("node:fs")),lt=require("node:crypto"),$=require("./session-workspace"),xe=require("../shared/agent-text"),pt=require("../shared/types"),dt=require("./inspect-graph"),yt=require("./inspect-imports"),gt=require("./inspect-tree"),mt=require("./inspect-cycles"),ht=require("../config/path-display"),At=["class","interface","function","type","enum","namespace","variable","method","property","constructor","runtime","export"],vt=500,xt=500,K=10,R=12,$t=12,bt=8;function St(e,n){const t=e.trim();return t==="constructor"?{raw:t,symbolName:"constructor",symbolKind:"constructor"}:ye(t,n.selectorSeparator,n)??ye(t,":",n)??ye(t,"-",n)??{raw:t,symbolName:t,symbolKind:null}}function Ct(e,n,t){const r=Array.isArray(e.results)?e.results:[],s=It(t),i=mr(r,t),o=r.map((u,p)=>Fe(u,n,ee(s,p),i));Pt(r,o,s,i),kt(r,o,s,n,i),Ot(r,o,s,n);const f=o.filter(u=>l(u)&&u.ok===!1).length;if(s.bundleSave)return Mt(r,o,n,s,i,f);const a=f===0&&s.forceResults!==!0?_t(r,o,n,i,s):null;if(a)return z(a),(0,xe.attachAgentText)(a,be(r,a,s,i));const c={results:o};return i&&(c.file=i),(f>0||e.ok===!1)&&(c.ok=!1,c.summary={requestCount:o.length,failedCount:f}),z(c),(0,xe.attachAgentText)(c,be(r,c,s,i))}function z(e){if(Array.isArray(e)){for(const n of e)z(n);return}if(l(e)){for(const n of["symbols","exports","members"])ne(e,n);for(const n of Object.values(e))z(n)}}function kt(e,n,t,r,s){for(let i=0;i<n.length;i+=1){const o=e[i],f=n[i];if(!l(o)||!f||o.op!=="members"||g(o.hiddenMemberCount)<=0)continue;const a=fe(o.hiddenMembers,r,ee(t,i),"members").filter(m=>typeof m=="string"&&m!=="");if(a.length===0)continue;const c=typeof f.file=="string"?f.file:s??"",u=typeof f.entity=="string"?f.entity:N(o.entity,r),p=I({version:1,kind:"members",source:"inspect",file:c,entity:u,items:a.map(m=>I({text:m}))}),d=(0,$.saveSessionResultViewJson)(t.cwd,W(p),p);d&&(f.view=d.saved)}}function Ot(e,n,t,r){for(let s=0;s<n.length;s+=1){const i=e[s],o=n[s];if(!l(i)||!o||i.op!=="duplicates"||g(i.hiddenItemCount)<=0)continue;const f=Array.isArray(i.hiddenDuplicateItems)?i.hiddenDuplicateItems.filter(l):Array.isArray(i.hiddenItems)?i.hiddenItems.filter(l):[];if(f.length===0)continue;const a=tt(),c=typeof i.detail=="string"?i.detail:"locations",u=f.map(m=>{const h=je(m,r,ee(t,s),a);return I({name:typeof h.name=="string"?h.name:"",text:Ge(h,c).join(`
2
- `).trim()})}).filter(m=>typeof m.text=="string"&&m.text!=="");if(u.length===0)continue;const p=I({version:1,kind:"duplicates",source:"inspect",detail:c,target:typeof o.target=="string"?o.target:"",items:u}),d=(0,$.saveSessionResultViewJson)(t.cwd,W(p),p);d&&(o.view=d.saved)}}function ee(e,n){const t=e.toFiles?.[n],r=e.saves?.[n],s=e.shows?.[n],i=e.ranges?.[n],o=e.parentNames?.[n];if(t===void 0&&r===void 0&&s===void 0&&i===void 0&&o===void 0)return e;const f={...e};return delete f.toFiles,delete f.toFile,delete f.saves,delete f.save,delete f.shows,delete f.ranges,delete f.parentNames,delete f.parentName,t&&(f.toFile=t),r&&!e.sharedSaves?.has(r)&&(f.save=r),s!==void 0&&(f.show=s),i!==void 0&&(f.includeRanges=i),o&&(f.parentName=o),f}function It(e){if(!e.saves||e.saves.length<2)return e;const n=new Map;for(const r of e.saves)r&&n.set(r,(n.get(r)??0)+1);const t=new Set(Array.from(n.entries()).filter(([,r])=>r>1).map(([r])=>r));return t.size>0?{...e,sharedSaves:t}:e}function Mt(e,n,t,r,s,i){const o=r.bundleSave;if(!o)throw new Error("bundleSave is required for inspect bundle output.");const f={...r,maxCodeLines:Number.MAX_SAFE_INTEGER};delete f.toFile,delete f.toFiles,delete f.save,delete f.saves,delete f.bundleSave;const a=e.map((h,v)=>{const y=Fe(h,t,f,s),x=n[v]?.saved;return typeof x=="string"&&(y.saved=x),delete y.next,delete y.last,y}),c=Et(a,s),u=(0,$.saveSessionOutputJson)(r.cwd,"inspect",o,c),p={saved:u.saved,last:u.last,items:a.length},d=n.map(h=>typeof h.saved=="string"?h.saved:"").filter(h=>h!=="");d.length>0&&(p.savedRows=d),i>0&&(p.ok=!1,p.summary={requestCount:a.length,failedCount:i});const m=(0,$.useSessionGuidance)(r.cwd,"inspect.bundle.read",`Read bundle with: aib session read ${u.saved}`);return m&&(p.next=m),p}function Et(e,n){const t={source:"inspect.bundle"};n&&(t.file=n);const r=e.map(o=>({...o})),s=$e(r,"op"),i=$e(r,"parent");return s&&(t.op=s,te(r,"op")),i&&(t.parent=i,te(r,"parent")),n&&te(r,"file"),t.items=r,t}function $e(e,n){const t=e.map(s=>s[n]).filter(s=>typeof s=="string"&&s!=="");if(t.length!==e.length||t.length===0)return null;const[r]=t;return t.every(s=>s===r)?r??null:null}function te(e,n){for(const t of e)delete t[n]}function _t(e,n,t,r,s){if(e.length===0||n.length===0)return null;const i=e.filter(l);if(i.length!==e.length||i.some(a=>a.ok===!1))return null;const o=Array.from(new Set(i.map(a=>typeof a.op=="string"?a.op:"")));if(o.length!==1)return{results:n.map(a=>O(a,{omitOp:!1,commonFile:r}))};const f=o[0];if(f==="modulePlan")return null;if(f==="usages")return e.length===1?O(n[0],{omitOp:!0,omitFile:!0}):{results:n.map(a=>O(a,{omitOp:!0,commonFile:r}))};if(e.length===1)return O(n[0],{omitOp:!0,omitFile:!0});if(f==="dependencies"){if(r){const a={};for(const c of i){const u=pe(c.entity);if(!u)return null;a[u]=In(c,t)}return{file:r,deps:a}}return{results:n.map(a=>O(a,{omitOp:!0,commonFile:r}))}}if(f==="members"){if(r){const a={};for(const c of n){const u=typeof c.entity=="string"?c.entity:"";if(!u||!Array.isArray(c.members))return null;a[u]=Lt(c)}return{file:r,members:a}}return{results:n.map(a=>O(a,{omitOp:!0,commonFile:r}))}}if(f==="code"||f==="slice"){const a=n.map(d=>O(d,{omitOp:!0,commonFile:r})),c={items:a};r&&(c.file=r);const u=sn(f,e,s,t);if(u.length===1?c.saved=u[0].saved:u.length>1&&(c.saved=u.map(d=>d.saved)),u.length>0){const d=u.length===1?u[0].saved:"--stdin",m=(0,$.useSessionGuidance)(s.cwd,`inspect.${f}.read`,`Read saved artifact with: aib session read ${d}`);m&&(c.next=m)}if(Tt(a).length>1){for(const d of a)delete d.next;c.next="Read saved artifacts with: aib session read --stdin"}return c}return{results:n.map(a=>O(a,{omitOp:!0,commonFile:r}))}}function O(e,n){const t={...e};return n.omitOp?delete t.op:t.op==="dependencies"&&(t.op="deps"),(n.omitFile||typeof t.file=="string"&&t.file===n.commonFile)&&delete t.file,delete t.last,typeof t.entity=="string"&&(t.entity=Qe(t.entity)),typeof t.count=="number"&&t.count<=K&&typeof t.page!="string"&&typeof t.hint!="string"&&delete t.count,ne(t,"symbols"),ne(t,"exports"),t}function ne(e,n){Array.isArray(e[n])&&(e[n]=e[n].filter(t=>typeof t=="string").map(t=>V(t)))}function Lt(e){const n={};return typeof e.count=="number"&&e.count>K&&(n.count=e.count),Array.isArray(e.members)&&(n.members=e.members),typeof e.hint=="string"&&(n.hint=e.hint),typeof e.page=="string"&&(n.page=e.page),n}function Tt(e){return e.map(n=>typeof n.saved=="string"?n.saved:"").filter(n=>n!=="")}function Pt(e,n,t,r){const s=new Map;for(let c=0;c<n.length;c+=1){const u=n[c],p=e[c];if(!u||!l(p)||!G(u))continue;const d=typeof p.op=="string"?p.op:"code";if(d!=="code"&&d!=="slice")continue;const m=re(u,t,e,c),h=typeof u.file=="string"?u.file:r??"",v=[d,m,h,t.parentNames?.[c]??t.parentName??""].join("\0"),y=s.get(v)??[];y.push({raw:p,result:u,index:c}),s.set(v,y)}for(const c of s.values()){const u=c.map(({raw:h,result:v,index:y})=>{const x=typeof h.code=="string"?h.code:"",_=typeof v.rangeMeta=="string"?v.rangeMeta:typeof v.meta=="string"?v.meta:"",D=typeof v.file=="string"?v.file:r??"",F=typeof v.entity=="string"?v.entity:typeof h.entity=="string"?h.entity:"";return I({file:D,entity:F,meta:_,code:x,nonEmptyLines:typeof v.nonEmptyLines=="number"?v.nonEmptyLines:oe(x),lineCount:x===""?g(h.lineCount):x.split(/\r?\n/).length,parent:t.parentNames?.[y]??t.parentName})});if(u.length===0)continue;const p=I({version:1,kind:"code",source:"inspect",items:u}),d=W(p),m=(0,$.saveSessionResultViewJson)(t.cwd,d,p);if(m)for(const h of c)h.result.view=m.saved}if(new Set(Array.from(s.values()).flatMap(c=>c.map(u=>typeof u.result.view=="string"?u.result.view:"")).filter(c=>c!=="")).size<=1)return;const o=Array.from(s.values()).flatMap(c=>c.map(u=>Dt(u.raw,u.result,u.index,t,r))),f=I({version:1,kind:"code",source:"inspect",items:o}),a=(0,$.saveSessionResultViewJson)(t.cwd,W(f),f);if(a)for(const c of s.values())for(const u of c)u.result.viewAllCode=a.saved}function Dt(e,n,t,r,s){const i=typeof e.code=="string"?e.code:"",o=typeof n.rangeMeta=="string"?n.rangeMeta:typeof n.meta=="string"?n.meta:"",f=typeof n.file=="string"?n.file:s??"",a=typeof n.entity=="string"?n.entity:typeof e.entity=="string"?e.entity:"";return I({file:f,entity:a,meta:o,code:i,nonEmptyLines:typeof n.nonEmptyLines=="number"?n.nonEmptyLines:oe(i),lineCount:i===""?g(e.lineCount):i.split(/\r?\n/).length,parent:r.parentNames?.[t]??r.parentName})}function W(e){return`res_${(0,lt.createHash)("sha256").update(JSON.stringify(e)).digest("hex").slice(0,8)}`}function I(e){const n={};for(const[t,r]of Object.entries(e))r!==void 0&&r!==""&&(n[t]=r);return n}function be(e,n,t,r){if(k(e,"file"))return Pe(n,"symbols",r);if(k(e,"exports"))return Pe(n,"exports",r);if(k(e,"members"))return Rt(n,r);if(k(e,"dependencies"))return en(n,r);if(k(e,"modulePlan"))return Yt(n);if(k(e,"usages"))return Ne(n);if(k(e,"duplicates"))return Ue(n);if(k(e,"directoryFallback"))return Oe(n);if(!k(e,"code"))return Se(n,r);const s=nn(n);if(s.length!==e.length||s.length===0||s.some(y=>typeof y.code!="string"&&typeof y.meta!="string"&&!j(y)&&!G(y)&&!se(y)))return null;const i=[],o=n.saved,f=s.some((y,x)=>re(y,t,e,x)!=="");if(!f&&typeof o=="string")i.push(`// ${o}`);else if(!f&&Array.isArray(o))for(const y of o)typeof y=="string"&&i.push(`// ${y}`);let a="",c="",u="",p=[],d=[];const m=l(e[0])&&typeof e[0].op=="string"?e[0].op:"code",h=()=>{Te(i,d,m),d=[]},v=()=>{p.length!==0&&(h(),i.push("// code:"),i.push(`not found symbols: ${p.join(", ")}`),p=[])};return s.forEach((y,x)=>{const _=l(e[x])?e[x]:{},D=re(y,t,e,x);D&&D!==u&&(v(),h(),M(i),i.push(`// ${D}`),u=D,a="",c="");const F=rn(y,_,t,r);if(F&&F!==a&&(v(),h(),i.push(`// ${F}`),a=F,c=""),j(y)){p.push(...E(y));return}v();const B=t.parentNames?.[x]??t.parentName??"";if(B&&B!==c?(h(),i.push(`// ${B}:`),c=B):B||(c=""),G(y)){d.push(y);return}const me=t.ranges?.[x]??t.includeRanges;if(t.codeMeta!==!1&&me&&typeof y.meta=="string"&&y.meta!=="")i.push(`// ${y.meta}`);else if(t.codeMeta!==!1&&me){const he=typeof y.code=="string"?y.code:"",ct=he===""?g(_.lineCount):he.split(/\r?\n/).length,Ae=P(_.entity,ct);Ae&&i.push(`// ${Ae}`)}typeof y.code=="string"?i.push(y.code.trimEnd()):se(y)&&Le(i,y)}),h(),v(),ke(i,s,!1),i.length>0?i.join(`
3
- `):null}function re(e,n,t,r){if(typeof e.saved=="string"&&e.saved!=="")return e.saved;const s=n.saves?.[r];if(typeof s!="string"||s==="")return"";const i=l(t[r])?t[r]:{};return`aib:${typeof i.op=="string"&&i.op!==""?i.op==="dependencies"?"deps":i.op:"inspect"}:${s}`}function Ft(e,n=null){return Se(e,n)}function Se(e,n){if(!Array.isArray(e.results))return null;const t=[],r=Y(t);let s=[];const i=()=>{s.length!==0&&(M(t),t.push("// code:"),t.push(`not found symbols: ${s.join(", ")}`),s=[])},o=c=>{i(),M(t),r(typeof c.file=="string"?c.file:n??"")},f=e.results.filter(l),a=f.filter(c=>c.op==="runtimeFailure");a.length>0&&t.push("partial: runtime skipped");for(let c=0;c<f.length;c+=1){const u=f[c];if(!l(u))return null;const p=typeof u.op=="string"?u.op:"";if((p==="code"||p==="slice")&&j(u)){s.push(...E(u));continue}if(i(),p==="file")o(u),Ee(t,"file:",u.symbols),_e(t,u);else if(p==="exports")o(u),Ee(t,"exports:",u.exports);else if(p==="members")o(u),J(t,`members ${typeof u.entity=="string"?u.entity:""}`.trim(),u);else if(p==="deps"||p==="dependencies"){o(u);const d=[];for(;c<f.length;){const m=f[c],h=typeof m.op=="string"?m.op:"";if(h!=="deps"&&h!=="dependencies"){c-=1;break}d.push({entity:typeof m.entity=="string"?m.entity:"",missingSymbols:E(m),type:m.depsType,value:m.depsValue,unknown:m.depsUnknown}),c+=1}c>=f.length&&(c-=1),Z(t,d)}else if(p==="code"||p==="slice"){o(u);const d=[],m=typeof u.file=="string"?u.file:n??"";for(;c<f.length;){const h=f[c],v=typeof h.op=="string"?h.op:"",y=typeof h.file=="string"?h.file:n??"";if(v!==p||y!==m||j(h)){c-=1;break}d.push(h),c+=1}c>=f.length&&(c-=1),Xt(t,p,d)}else if(p==="graph")o(u),Gt(t,u);else if(p==="imports")(0,yt.appendImportsBlock)(t,u);else if(p==="tree")o(u),Ce(t,(0,gt.formatTreeResponse)(u));else if(p==="cycles")o(u),Ce(t,(0,mt.formatCyclesResponse)(u));else{if(p==="runtimeFailure")continue;if(p==="usages")o(u),Vt(t,u);else if(p==="duplicates")o(u),Jt(t,u);else if(p==="directoryFallback")o(u),Ht(t,u);else return null}}return i(),jt(t,a),ke(t,f,!0),t.length>0?t.join(`
4
- `):null}function Ce(e,n){n&&e.push(...n.split(/\r?\n/))}function jt(e,n){if(n.length!==0){M(e),e.push("runtime skipped:");for(const t of Nt(n))e.push(t);e.push(`skipped ops: ${Bt(n)}`)}}function Nt(e){return Array.from(new Set(e.map(n=>{const t=typeof n.code=="string"?n.code:"RUNTIME_INSPECT_FAILED",r=typeof n.error=="string"?n.error:"runtime-backed inspect failed";return`${t}: ${r}`})))}function Bt(e){const n=new Map;for(const t of e){const r=Ut(typeof t.requestedOp=="string"?t.requestedOp:"inspect");n.set(r,(n.get(r)??0)+1)}return Array.from(n.entries()).map(([t,r])=>r>1?`${t} x${r}`:t).join(", ")}function Ut(e){return e==="dependencies"?"deps":e}function ke(e,n,t){const r=Array.from(new Set(n.map(s=>typeof s.viewAllCode=="string"?s.viewAllCode:"").filter(s=>s!=="")));if(r.length!==0){if(M(e),t){e.push("view all:"),e.push(`code: ${r[0]}`);return}e.push(`view all code: ${r[0]}`)}}function Gt(e,n){const t=(0,dt.formatGraphAgentText)({...n,operation:"inspect.graph"});t&&(e.push("// graph:"),e.push(...t.split(/\r?\n/).filter(r=>r!=="inspect.graph")))}function Ht(e,n){const t=Oe(n);t&&e.push(...t.split(/\r?\n/))}function Oe(e){const n=qt(Array.isArray(e.lines)?e.lines.filter(i=>typeof i=="string").filter((i,o)=>o!==0||!i.startsWith("tree ")):[]);if(n.length===0)return null;const t=typeof e.directory=="string"?e.directory:"directory",r=Array.isArray(e.skippedOps)?e.skippedOps.filter(i=>typeof i=="string"):[],s=[`inspect expected file, got directory: ${t}`];return r.length>0&&(s.push(""),s.push("Skipped file-based operations:"),s.push(r.join(", "))),typeof e.command=="string"&&e.command!==""&&(s.push(""),s.push("Showing tree instead:"),s.push(e.command)),s.push(""),s.push(...n),s.join(`
5
- `)}function qt(e){let n=0;for(;n<e.length&&e[n]==="";)n+=1;return e.slice(n)}function Vt(e,n){const t=typeof n.detail=="string"?n.detail:"",r=t==="locations"||t==="code"?Kt(n):Ne(n);r&&e.push(...r.split(/\r?\n/))}function Kt(e){const n=typeof e.detail=="string"?e.detail:"detail";if(g(e.referenceCount)===0){const s=typeof e.target=="string"?e.target:"",i=typeof e.scopeLabel=="string"?e.scopeLabel:"project",o=[s?`usages ${s}`:"usages",`0 refs in ${i}`];return X(o,e),o.join(`
6
- `)}const t=[`usages ${n}`];X(t,e),n==="code"?Wt(t,e):zt(t,e),Ve(t,e,Array.isArray(e.items)?e.items.filter(l):[]);const r=typeof e.view=="string"?e.view:"";return r&&(M(t),t.push(`view: ${r}`)),t.join(`
7
- `).replace(/\n{3,}/g,`
8
-
9
- `).trimEnd()}function zt(e,n){const t=Array.isArray(n.items)?n.items.filter(l).filter(i=>g(i.referenceCount)>0):[];t.length>0&&M(e);const{ownerGroups:r,standalone:s}=ie(t);for(const[i,o]of r){e.push(""),e.push(`// ${i}:`);for(const f of o)e.push(...Ie(f,!1))}s.length>0&&r.length>0&&e.push("");for(const i of s)e.push(...Ie(i,!0))}function Ie(e,n){const t=typeof e.entity=="string"?e.entity:"",r=H(t),i=[`${n?t:r.name}: ${g(e.referenceCount)} refs`],o=Array.isArray(e.usedBy)?e.usedBy.filter(l):[];for(const f of o){const a=typeof f.file=="string"?f.file:"";a&&i.push(`${a}:`);const c=Array.isArray(f.locations)?f.locations.filter(l):[];for(const u of c){const p=typeof u.line=="number"?` l${u.line}`:"",d=typeof u.container=="string"?u.container:"";i.push(`${d}${p}`.trim())}}return typeof e.hidden=="string"&&i.push(e.hidden),i}function Wt(e,n){const t=Array.isArray(n.blocks)?n.blocks.filter(l):[];t.length>0&&M(e);const{ownerGroups:r,standalone:s}=ie(t);for(const[o,f]of r){e.push(`// ${o}:`);for(const[a,c]of Be(f,u=>H(typeof u.entity=="string"?u.entity:"").name)){a&&e.push(`// ${a}`);for(const u of c)e.push(...Me(u,!1,!1))}}s.length>0&&r.length>0&&e.push("");for(const[o,f]of Be(s,a=>typeof a.entity=="string"?a.entity:"")){o&&e.push(`// ${o}`);for(const a of f)e.push(...Me(a,!1,!1))}const i=Array.isArray(n.hiddenBlocks)?n.hiddenBlocks.filter(l):[];for(const o of i){const f=typeof o.entity=="string"?o.entity:"",a=typeof o.hidden=="string"?o.hidden:"";a&&e.push(f?`${f}: ${a}`:a)}}function Me(e,n,t=!0){const r=typeof e.entity=="string"?e.entity:"",s=H(r),i=n?r:s.name,o=[];t&&i&&o.push(`// ${i}`);const f=typeof e.file=="string"?e.file:"",a=typeof e.line=="number"?` l${e.line}`:"";if((f||a)&&o.push(`// ${f}${a}`.trim()),typeof e.code=="string")o.push(e.code.trimEnd());else if(l(e.omitted)){const c=typeof e.omitted.reason=="string"?e.omitted.reason:"omitted";o.push(`// ${c}`)}return o}function Jt(e,n){const t=Ue(n);t&&e.push(...t.split(/\r?\n/))}function Yt(e){const n=Array.isArray(e.results)?e.results.filter(l):l(e)?[e]:[];if(n.length===0)return null;const t=[];for(const r of n){const s=typeof r.operation=="string"?r.operation:"modulePlan.preview",i=typeof r.planId=="string"?r.planId:"";if(t.push(i?`${s} ${i}`:s),r.ok===!1&&typeof r.code=="string"&&t.push(`blocked: ${r.code}`),typeof r.summary=="string"&&t.push(r.summary),typeof r.integrity=="string"&&t.push(r.integrity),l(r.api)&&typeof r.api.status=="string"){const o=typeof r.api.before=="number"?r.api.before:null,f=typeof r.api.after=="number"?r.api.after:null;t.push(o!==null&&f!==null?`api: ${r.api.status} ${o}->${f}`:`api: ${r.api.status}`)}if(typeof r.cycles=="string"&&t.push(`cycles: ${r.cycles}`),Array.isArray(r.targets)&&r.targets.length>0){t.push("targets:");for(const o of r.targets.filter(l)){const f=typeof o.file=="string"?o.file:"",a=typeof o.summary=="string"?o.summary:"";f&&a&&t.push(`${f}: ${a}`)}}if(Array.isArray(r.blocking)&&r.blocking.length>0){t.push("blocking:");for(const o of r.blocking.filter(l)){const f=typeof o.code=="string"?o.code:"MODULE_PLAN_BLOCKING",a=Array.isArray(o.symbols)?o.symbols.filter(c=>typeof c=="string"):[];t.push(a.length>0?`${f}: ${a.join(", ")}`:f),Array.isArray(o.suggestedFixes)&&o.suggestedFixes.length>0&&t.push(`suggestedFixes: ${o.suggestedFixes.length}`)}}if(Array.isArray(r.remainingBlocking)&&r.remainingBlocking.length>0&&t.push(`remainingBlocking: ${r.remainingBlocking.length}`),Array.isArray(r.resolved)&&r.resolved.length>0&&t.push(`resolved: ${r.resolved.length}`),Array.isArray(r.changes)&&r.changes.length>0){t.push("changes:");for(const o of r.changes.filter(f=>typeof f=="string"))t.push(o)}l(r.preview)&&typeof r.preview.summary=="string"&&t.push(`preview: ${r.preview.summary}`),typeof r.next=="string"&&t.push(`next: ${r.next}`)}return t.join(`
10
- `)}function Ee(e,n,t){const r=L(t);if(e.push(n),r.length===0){e.push(n==="exports:"?"no exports":"no top-level declarations");return}for(const s of r)e.push(s)}function _e(e,n){n.hasNonDeclarationText===!0&&e.push("file has non-declaration text")}function Zt(e,n,t){const r=typeof t.entity=="string"?t.entity:"";if(e.push(`// ${[n,r].filter(s=>s!=="").join(" ")}:`),j(t)){e.push(`not found symbols: ${E(t).join(", ")}`);return}typeof t.meta=="string"&&t.meta!==""&&e.push(`// ${t.meta}`),typeof t.saved=="string"&&t.saved!==""&&e.push(`saved: ${t.saved}`),typeof t.code=="string"?e.push(t.code.trimEnd()):G(t)?Qt(e,t):se(t)&&Le(e,t)}function Xt(e,n,t){const r=[];for(const s of t){if(G(s)){r.push(s);continue}Zt(e,n,s)}Te(e,r,n)}function se(e){return typeof e.saved=="string"&&e.saved!==""}function Le(e,n){e.push(`saved: ${n.saved}`),typeof n.next=="string"&&n.next!==""&&e.push(`next: ${n.next}`)}function G(e){return e.reason==="CODE_TOO_LARGE_FOR_STDOUT"||e.reason==="SLICE_TOO_LARGE_FOR_STDOUT"}function Qt(e,n){const t=typeof n.reason=="string"?n.reason:"CODE_TOO_LARGE_FOR_STDOUT",r=wt(n)??t;e.push(`code omitted: ${r}`),typeof n.hint=="string"&&n.hint!==""&&e.push(`hint: ${n.hint}`)}function Te(e,n,t){if(n.length===0)return;const r=t==="slice"?"slice":"code",s=Array.from(new Set(n.map(f=>typeof f.limit=="number"?f.limit:null).filter(f=>f!==null))),i=s.length===1?`; limit ${s[0]} NEL`:"";e.push(`// ${r} omitted${i}`);for(const f of n){const a=typeof f.entity=="string"&&f.entity!==""?f.entity:"unknown",c=typeof f.meta=="string"?f.meta:typeof f.rangeMeta=="string"?f.rangeMeta:"",u=typeof f.nonEmptyLines=="number"&&f.nonEmptyLines>0?f.nonEmptyLines:typeof f.lineCount=="number"&&f.lineCount>0?f.lineCount:0,p=u>0?`${u} NEL`:"";e.push(`// ${[a,c,p].filter(d=>d!=="").join(" ")}`)}const o=Array.from(new Set(n.map(f=>typeof f.view=="string"?f.view:"").filter(f=>f!=="")));for(const f of o)e.push(`view: ${f}`)}function wt(e){const n=typeof e.hint=="string"?e.hint:"";return/^(?:Code|Slice) is ([^.]+)\./.exec(n)?.[1]??null}function Pe(e,n,t){const r=[],s=Y(r);if(Array.isArray(e.results))for(const i of e.results)l(i)&&De(r,s,i,n,t);else De(r,s,e,n,t);return r.length>0?r.join(`
11
- `):null}function De(e,n,t,r,s){n(typeof t.file=="string"?t.file:s??"");const i=L(t[r]).map(f=>V(f));if(i.length===0)e.push(`${r==="exports"?"exports":"file"}:`),e.push(r==="exports"?"no exports":"no top-level declarations");else for(const f of i)e.push(f);r==="symbols"&&_e(e,t),typeof t.summary=="string"&&e.push(`summary: ${t.summary}`);const o=L(t.reexports);o.length>0&&e.push(`reexports: ${o.join(", ")}`),typeof t.page=="string"&&e.push(`page: ${t.page}`),typeof t.hint=="string"&&e.push(`hint: ${t.hint}`)}function Rt(e,n){const t=[],r=Y(t);if(l(e.members)&&!Array.isArray(e.members)){r(typeof e.file=="string"?e.file:n??"");for(const[s,i]of Object.entries(e.members))l(i)&&J(t,s,i)}else if(Array.isArray(e.results))for(const s of e.results)l(s)&&(r(typeof s.file=="string"?s.file:n??""),J(t,typeof s.entity=="string"?s.entity:"",s));else r(typeof e.file=="string"?e.file:n??""),J(t,typeof e.entity=="string"?e.entity:"",e);return t.length>0?t.join(`
12
- `):null}function J(e,n,t){if(j(t)){e.push("members:"),e.push(`not found symbols: ${E(t).join(", ")}`);return}const r=L(t.members);if(!(!n&&r.length===0)){if(n&&e.push(`// ${n}:`),r.length===0){e.push("no members");return}typeof t.count=="number"&&e.push(`// count: ${t.count}`),typeof t.page=="string"&&e.push(`// page: ${t.page}`);for(const s of r)e.push(s);typeof t.view=="string"&&e.push(`view: ${t.view}`)}}function en(e,n){const t=[],r=Y(t);if(l(e.deps)){r(typeof e.file=="string"?e.file:n??"");const s=[];for(const[i,o]of Object.entries(e.deps))l(o)&&s.push({entity:i,type:o.type,value:o.value,unknown:o.unknown});Z(t,s)}else if(Array.isArray(e.results)){const s=[];for(const i of e.results)l(i)&&(r(typeof i.file=="string"?i.file:n??""),s.push({entity:typeof i.entity=="string"?i.entity:"",missingSymbols:E(i),type:i.depsType,value:i.depsValue,unknown:i.depsUnknown}));Z(t,s)}else r(typeof e.file=="string"?e.file:n??""),Z(t,[{entity:typeof e.entity=="string"?e.entity:"",missingSymbols:E(e),type:e.depsType,value:e.depsValue,unknown:e.depsUnknown}]);return t.length>0?t.join(`
13
- `):null}function M(e){e.length>0&&e[e.length-1]!==""&&e.push("")}function Y(e){let n="";return t=>{t&&t!==n&&(e.push(`// ${t}`),n=t)}}function Z(e,n){const t=[],r=[];let s=!1;for(const i of n){if(i.missingSymbols&&i.missingSymbols.length>0){r.push(...i.missingSymbols);continue}const o=L(i.type),f=L(i.value),a=L(i.unknown);if(o.length===0&&f.length===0&&a.length===0){i.entity&&t.push(i.entity);continue}s||(e.push("deps"),s=!0),tn(e,i.entity,{type:o,value:f,unknown:a})}t.length>0&&(s||(e.push("deps"),s=!0),e.push(`No deps for: ${t.join(", ")}`)),r.length>0&&(s||e.push("deps"),e.push(`not found symbols: ${r.join(", ")}`))}function tn(e,n,t){!n&&t.type.length===0&&t.value.length===0&&t.unknown.length===0||(n&&e.push(`${n}:`),t.type.length>0&&e.push(`type: ${t.type.join(", ")}`),t.value.length>0&&e.push(`value: ${t.value.join(", ")}`),t.unknown.length>0&&e.push(`unknown: ${t.unknown.join(", ")}`))}function L(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"&&n!==""):[]}function k(e,n){return e.length>0&&e.every(t=>l(t)&&t.op===n)}function nn(e){return Array.isArray(e.items)?e.items.filter(l):Array.isArray(e.results)?e.results.filter(l):[e]}function rn(e,n,t,r){return typeof e.file=="string"&&e.file!==""?e.file:r||(typeof n.sourceFile=="string"&&n.sourceFile!==""?A(n.sourceFile,t):"")}function sn(e,n,t,r){if(e!=="code"&&e!=="slice")return[];const s=on(t.saves,t.sharedSaves,n.length);return s.length===0?[]:s.map(i=>{const o=n.map((c,u)=>({rawResult:c,save:t.saves?.[u]??null,includeRanges:t.ranges?.[u]??t.includeRanges})).filter(c=>c.save===i&&l(c.rawResult)).map(c=>({rawResult:c.rawResult,includeRanges:c.includeRanges})).map(({rawResult:c,includeRanges:u})=>{const p=typeof c.code=="string"?c.code:"",d=N(c.entity,r),m=p===""?g(c.lineCount):p.split(/\r?\n/).length,h=t.codeMeta===!1||!u?"":P(c.entity,m),v=[d,h].filter(y=>y!=="").join(" ");return v?`// ${v}
14
- ${p}`:p}).filter(c=>c!==""),f=fn(n),a=(0,$.saveSessionOutputText)(t.cwd,e,i,o.join(`
15
-
16
- `),f);return{saved:a.saved,last:a.last}})}function on(e,n,t){return!e||!n||t<2||e.length<t?[]:Array.from(new Set(e.slice(0,t).filter(r=>typeof r=="string"&&r!==""&&n.has(r))))}function fn(e){for(const n of e)if(l(n)&&typeof n.sourceFile=="string")return b.extname(n.sourceFile)||".ts";return".ts"}function Fe(e,n,t,r){if(!l(e))return{ok:!1,code:"INVALID_INSPECT_RESULT",error:"Inspect result is not an object."};const s=typeof e.op=="string"?e.op:"unknown";if(e.ok===!1&&s!=="modulePlan")return ir(e,t,r);if(s==="file"){const i={...S(e,t,r),...we("count",g(e.symbolCount)),symbols:fe(e.symbols,n,t,"file")};return(e.hasNonDeclarationText===!0||Array.isArray(i.symbols)&&i.symbols.length===0&&Cn(e.sourceFile))&&(i.hasNonDeclarationText=!0),e.mode==="local"&&(i.mode="local",i.summary=wn(e),i.localDeclarationCount=g(e.localDeclarationCount),i.reexports=Ye(e.reexports)),i}return s==="exports"?{...S(e,t,r),...we("count",g(e.exportCount)),exports:kn(e.exports,n,t)}:s==="members"?{...S(e,t,r),entity:N(e.entity,n),...Qn(e,n,t)}:s==="code"?Sn(e,n,t,r):s==="dependencies"?{...S(e,t,r),entity:N(e.entity,n),...On(e,n,t)}:s==="modulePlan"?Mn(e,n,t,r):s==="usages"?cn(e,n,t,r):s==="duplicates"?an(e,n,t,r):s==="directoryFallback"?{...e}:s==="slice"?bn(e,n,t,r):{...S(e,t,r),warning:"Unknown inspect operation result."}}function cn(e,n,t,r){const s=typeof e.targetPath=="string"?A(e.targetPath,t):typeof e.sourceFile=="string"?A(e.sourceFile,t):r??"",i=Array.isArray(e.items)?e.items.filter(l):[],o=cr(fr(i,s,t)),f=pn(i),a=e.targetMode==="directory"&&e.queryMode!=="explicit",c={...S(e,t,r),target:o.compactPath(s),summary:typeof e.summary=="string"?e.summary:`${f.length} symbols`,referenceCount:g(e.referenceCount),itemCount:g(e.itemCount),fileCount:g(e.fileCount),scopeLabel:mn(e,t),targetMode:typeof e.targetMode=="string"?e.targetMode:"",queryMode:typeof e.queryMode=="string"?e.queryMode:""};if(delete c.file,e.excludeTarget===!0&&e.targetLocalUsagesHidden!==!0&&(c.scope="excluding target"),e.targetLocalUsagesHidden===!0&&(c.targetLocalUsagesHidden=!0),a){const p=yn(f,n,o,t);c.usedBy=p.usedBy,p.hiddenConsumers>0&&(c.hiddenConsumers=`+ ${p.hiddenConsumers} files`)}else{const p=f.slice(0,R);c.items=p.map(d=>dn(d,n,o,t,e.targetMode==="directory"))}const u=ur(o,c);if(u&&(c.paths=u),!a&&f.length>R&&(c.hidden=`+ ${f.length-R} symbols`),t.save){const p=(0,$.saveSessionOutputJson)(t.cwd,"usages",t.save,e);c.saved=p.saved;const d=(0,$.useSessionGuidance)(t.cwd,"inspect.usages.focus",`Expand saved usages with: aib inspect usages --from-file ${p.saved} --focus <name> --detail locations|code`);d&&(c.next=d)}return c}function an(e,n,t,r){const s=Array.isArray(e.targetPaths)?e.targetPaths.filter(c=>typeof c=="string").map(c=>A(c,t)):[],i=Array.isArray(e.items)?e.items.filter(l):[],o=tt(),f={...S(e,t,r),target:s.length===1?o.compactPath(s[0]):s.map(c=>o.compactPath(c)),summary:typeof e.summary=="string"?e.summary:`${i.length} names`,itemCount:g(e.itemCount),returnedItemCount:g(e.returnedItemCount),declarationCount:g(e.declarationCount),exactCopyCount:g(e.exactCopyCount),offset:g(e.offset),limit:g(e.limit),detail:typeof e.detail=="string"?e.detail:"locations",mode:typeof e.mode=="string"?e.mode:"both",items:i.map(c=>je(c,n,t,o))},a=g(e.hiddenItemCount);if(a>0&&(f.hidden=`+ ${a} names`),t.save){const c=(0,$.saveSessionOutputJson)(t.cwd,"duplicates",t.save,e);f.saved=c.saved;const u=(0,$.useSessionGuidance)(t.cwd,"inspect.duplicates.read",`Read saved duplicates with: aib session read ${c.saved}`);u&&(f.next=u)}return f}function je(e,n,t,r){const s=Array.isArray(e.variants)?e.variants.filter(l):[];return{name:typeof e.name=="string"?e.name:"",count:g(e.declarationCount),variants:g(e.variantCount),exactCopies:g(e.exactCopyCount),groups:s.map(i=>un(i,n,t,r))}}function un(e,n,t,r){const s=Array.isArray(e.declarations)?e.declarations.filter(l):[],i={count:g(e.count),declarations:s.map(o=>ln(o,n,t,r))};return typeof e.code=="string"&&(i.code=e.code),i}function ln(e,n,t,r){const s=l(e.symbol)?e.symbol:{},i=l(e.sameAs)?e.sameAs:null,o={file:typeof e.file=="string"?r.compactPath(A(e.file,t)):"",selector:T(s,n)},f=t.includeRanges?P(s):"";if(f&&(o.meta=f),i){const a=l(i.symbol)?i.symbol:{},c=typeof i.file=="string"?r.compactPath(A(i.file,t)):"",u=t.includeRanges?P(a):"";o.sameAs=[c,u].filter(p=>p!=="").join(" ")}return o}function pn(e){return[...e].sort((n,t)=>g(t.referenceCount)-g(n.referenceCount)||et(w(n.entity),w(t.entity)))}function dn(e,n,t,r,s=!1){const i={entity:w(e.entity),summary:typeof e.summary=="string"?e.summary:`${g(e.referenceCount)} refs, ${g(e.fileCount)} files`,usedBy:gn(e.usedBy,t,r)};return s&&typeof e.declaredIn=="string"&&(i.declaredIn=t.compactPath(A(e.declaredIn,r))),e.role==="member"&&(i.role="member"),i}function yn(e,n,t,r){const s=new Map;for(const f of e){const a=w(f.entity),c=Array.isArray(f.usedBy)?f.usedBy.filter(l):[];for(const u of c){const p=typeof u.file=="string"?u.file:"";if(!p)continue;const d=g(u.count),m=s.get(p)??{refs:0,symbols:new Map};m.refs+=d,m.symbols.set(a,(m.symbols.get(a)??0)+d),s.set(p,m)}}const i=Array.from(s.entries()).sort(([f,a],[c,u])=>u.refs-a.refs||f.localeCompare(c)),o=i.slice(0,$t).map(([f,a])=>{const c=Array.from(a.symbols.entries()).sort(([p,d],[m,h])=>h-d||et(p,m)),u=c.slice(0,bt).map(([p,d])=>d>1?`${p} x${d}`:p);return c.length>u.length&&u.push(`+ ${c.length-u.length} more`),{file:t.compactPath(A(f,r)),summary:`${a.refs} ${Re(a.refs,"ref")}`,symbols:u}});return{usedBy:o,hiddenConsumers:Math.max(0,i.length-o.length)}}function gn(e,n,t){if(!Array.isArray(e))return[];const r=e.filter(l).map(s=>{const i=typeof s.file=="string"?n.compactPath(A(s.file,t)):"",o=g(s.count);return i?`${i} x${o}`:""}).filter(s=>s!=="");return lr(r)}function mn(e,n){const t=Array.isArray(e.usageScopes)?e.usageScopes.filter(r=>typeof r=="string"&&r.trim()!==""):[];return t.length===0?"project":t.length===1?A(t[0],n):`${t.length} scopes`}function Ne(e){const n=Array.isArray(e.results)?e.results.filter(l):[e];if(n.length===0)return null;const t=[];for(const r of n){const s=typeof r.detail=="string"?r.detail:"locations";if(l(r.paths)&&Object.keys(r.paths).length>0){t.push("paths:");for(const[a,c]of Object.entries(r.paths))t.push(`${a} = ${String(c)}`)}const i=typeof r.target=="string"?r.target:"";if(t.push(i?`usages ${i}`:"usages"),g(r.referenceCount)===0){t.push(`0 refs in ${typeof r.scopeLabel=="string"?r.scopeLabel:"project"}`),X(t,r);const a=g(r.itemCount);(r.targetMode==="directory"||r.queryMode!=="explicit")&&a>0&&t.push(`symbols checked: ${a}`);continue}typeof r.summary=="string"&&t.push(r.summary),typeof r.scope=="string"&&t.push(r.scope),X(t,r);const o=Array.isArray(r.usedBy)?r.usedBy.filter(l):[];for(const a of o){const c=typeof a.file=="string"?a.file:"",u=typeof a.summary=="string"?a.summary:"",p=Array.isArray(a.symbols)?a.symbols.filter(d=>typeof d=="string"):[];t.push(`${c}: ${u}; ${p.join(", ")}`.trim())}typeof r.hiddenConsumers=="string"&&t.push(r.hiddenConsumers);const f=Array.isArray(r.items)?r.items.filter(l):[];t.push(...xn(f)),Ve(t,r,f),typeof r.hidden=="string"&&t.push(r.hidden),typeof r.view=="string"&&t.push(`view: ${r.view}`),typeof r.saved=="string"&&t.push(`saved: ${r.saved}`),typeof r.next=="string"&&t.push(`next: ${r.next}`)}return t.join(`
17
- `)}function X(e,n){n.targetLocalUsagesHidden===!0&&e.push("target-local usages hidden; use +includeTarget to show")}function Be(e,n){const t=new Map;for(const r of e){const s=n(r),i=t.get(s)??[];i.push(r),t.set(s,i)}return Array.from(t.entries())}function Ue(e){const n=Array.isArray(e.results)?e.results.filter(l):[e];if(n.length===0)return null;const t=[];for(const r of n){const s=typeof r.detail=="string"?r.detail:"locations",i=Array.isArray(r.target)?r.target.filter(a=>typeof a=="string").join(", "):typeof r.target=="string"?r.target:"",o=hn(r.paths,s,i);if(o.length>0){t.push("paths:");for(const[a,c]of o)t.push(`${a} = ${c}`)}t.push(i?`duplicates ${i}`:"duplicates"),typeof r.summary=="string"&&t.push(r.summary);const f=Array.isArray(r.items)?r.items.filter(l):[];if(f.length===0){t.push("no duplicates");continue}for(const a of f)An(t,a,s);typeof r.hidden=="string"&&t.push(r.hidden),typeof r.view=="string"&&t.push(`view: ${r.view}`),typeof r.saved=="string"&&t.push(`saved: ${r.saved}`),typeof r.next=="string"&&t.push(`next: ${r.next}`)}return t.join(`
18
- `)}function hn(e,n,t){if(!l(e))return[];const r=Object.entries(e).filter(s=>typeof s[1]=="string");return n!=="summary"?r:r.filter(([s])=>t.includes(s))}function An(e,n,t){e.push(...Ge(n,t))}function Ge(e,n){const t=[],r=typeof e.name=="string"?e.name:"",s=g(e.count),i=g(e.variants),o=g(e.exactCopies);if(n!=="summary"&&t.push(""),t.push(`${r} x${s}, ${i} ${Re(i,"variant")}${o>0?`, exact x${o}`:""}`),n==="summary")return t;const f=Array.isArray(e.groups)?e.groups.filter(l):[];if(n==="code"){let a=1;const c=[];for(const u of f){if(g(u.count)===1){c.push(u);continue}He(t,u,`variant#${a}`),a+=1}if(c.length>0){t.push("// single variants");for(const u of c)He(t,u,null)}return t}for(const a of f){const c=Array.isArray(a.declarations)?a.declarations.filter(l):[];t.push(...qe(c,!1))}return t}function He(e,n,t){const r=Array.isArray(n.declarations)?n.declarations.filter(l):[],s=g(n.count);t&&e.push(`// ${t} x${s}`);const i=qe(r,!1);for(const o of i)e.push(`// ${o}`);typeof n.code=="string"&&e.push(n.code.trimEnd())}function vn(e,n){const t=typeof e.file=="string"?e.file:"",r=typeof e.meta=="string"?e.meta:"",s=n&&typeof e.sameAs=="string"&&e.sameAs!==""?` same as ${e.sameAs}`:"";return[t,r].filter(i=>i!=="").join(" ")+s}function qe(e,n){const t=new Map,r=[];for(const i of e){const o=typeof i.file=="string"?de(i.file):"";if(!o)continue;const f=o.lastIndexOf("/");if(f<=0){r.push(vn(i,n));continue}const a=o.slice(0,f),c=o.slice(f+1),u=typeof i.meta=="string"&&i.meta!==""?` ${i.meta}`:"",p=n&&typeof i.sameAs=="string"&&i.sameAs!==""?` same as ${i.sameAs}`:"",d=t.get(a)??[];d.push(`${c}${u}${p}`),t.set(a,d)}return[...Array.from(t.entries()).flatMap(([i,o])=>o.length>1?[`${i}/: ${o.join(", ")}`]:[`${i}/${o[0]}`]),...r].sort()}function Ve(e,n,t){const r=t.filter(s=>(typeof s.summary=="string"?s.summary:"").startsWith("0 refs")).map(s=>typeof s.entity=="string"?s.entity:"").filter(s=>s!=="");if(r.length!==0){if(n.queryMode==="explicit"){e.push(`unused: ${q(r,2,"more")}`);return}n.targetMode==="file"&&e.push(`unused symbols: ${r.length}`)}}function xn(e){const n=[],t=e.filter(i=>!$n(i)),{ownerGroups:r,standalone:s}=ie(t);for(const[i,o]of r){n.length>0&&n.push(""),n.push(`// ${i}:`);for(const f of o)n.push(...Ke(f,!1))}s.length>0&&n.length>0&&n.push("");for(const i of s)n.push(...Ke(i,!0));return n}function $n(e){return typeof e.referenceCount=="number"?e.referenceCount===0:(typeof e.summary=="string"?e.summary:"").startsWith("0 refs")}function Ke(e,n){const t=typeof e.entity=="string"?e.entity:"",r=H(t),s=n?t:r.name,i=typeof e.declaredIn=="string"?` [${e.declaredIn}]`:"",o=typeof e.summary=="string"?e.summary:"",f=[`${s}${i}: ${o}`.trim()],a=Array.isArray(e.usedBy)?e.usedBy.filter(c=>typeof c=="string"):[];return f.push(...a),f}function ie(e){const n=new Map,t=[];for(const r of e){const s=typeof r.entity=="string"?r.entity:"",i=H(s);if(!i.owner){t.push(r);continue}const o=n.get(i.owner)??[];o.push(r),n.set(i.owner,o)}return{ownerGroups:Array.from(n.entries()),standalone:t}}function H(e){const n=e.lastIndexOf(".");return n<=0||n>=e.length-1?{owner:null,name:e}:{owner:e.slice(0,n),name:e.slice(n+1)}}function bn(e,n,t,r){const s=typeof e.code=="string"?e.code:"",i=s===""?g(e.lineCount):s.split(/\r?\n/).length,o={...S(e,t,r),entity:N(e.entity,n)},f=P(e.entity,i);if(t.includeRanges&&f&&(o.meta=f),t.toFile){const a=it(t.cwd,t.toFile,s);if(o.writtenTo=a,!t.show)return o}if(t.save){const a=ot(t.cwd,"slice",t.save,e,s);o.saved=a.saved;const c=(0,$.useSessionGuidance)(t.cwd,"inspect.slice.read",`Read saved artifact with: aib session read ${a.saved}`);if(c&&(o.next=c),!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 Sn(e,n,t,r){const s=typeof e.code=="string"?e.code:"",i=s===""?0:s.split(/\r?\n/).length,o=oe(s),f={...S(e,t,r),entity:N(e.entity,n)},a=P(e.entity,i);if(t.codeMeta!==!1&&t.includeRanges&&a&&(f.meta=a),t.toFile){const c=it(t.cwd,t.toFile,s);if(f.writtenTo=c,!t.show)return f}if(t.save){const c=ot(t.cwd,"code",t.save,e,s);f.saved=c.saved;const u=(0,$.useSessionGuidance)(t.cwd,"inspect.code.read",`Read saved artifact with: aib session read ${c.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,a&&(f.rangeMeta=a))),f}function oe(e){return e===""?0:e.split(/\r?\n/).filter(n=>n.trim()!=="").length}function Cn(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,n,t){const r={op:typeof e.op=="string"?e.op:"unknown"};if(typeof e.id=="string"&&(r.id=e.id),typeof e.sourceFile=="string"){const s=A(e.sourceFile,n);s!==t&&(r.file=s)}return r}function fe(e,n,t,r="generic"){return Array.isArray(e)?e.filter(l).map(s=>V(ae(s,n,t,r))):[]}function kn(e,n,t){if(!Array.isArray(e))return[];const r=e.filter(l);if(t.includeRanges)return r.map(f=>V(ae(f,n,t,"exports")));const s=[],i=new Map;for(const f of r){const a=V(ae(f,n,t,"exports")),c=typeof f.sourceModule=="string"?f.sourceModule:"";if(!c){s.push(a);continue}const u=er(f,a,c),p=i.get(c)??[];p.push(u),i.set(c,p)}if(i.size===0)return s;const o=[];s.length>0&&o.push(`local: ${s.join(", ")}`);for(const[f,a]of i.entries())o.push(`${f}: ${a.join(", ")}`);return o}function C(e,n){return Array.isArray(e)?e.filter(l).map(t=>T(t,n)).filter(t=>t!==""):[]}function On(e,n,t){const r=ze(e,n,t),s={};return r.type.length>0&&(s.depsType=r.type),r.value.length>0&&(s.depsValue=r.value),r.unknown.length>0&&(s.depsUnknown=r.unknown),s}function In(e,n){const t=ze(e,n),r={};return t.type.length>0&&(r.type=t.type),t.value.length>0&&(r.value=t.value),t.unknown.length>0&&(r.unknown=t.unknown),r}function ze(e,n,t){if(!(Array.isArray(e.typeOnlyDependencies)||Array.isArray(e.valueDependencies)||Array.isArray(e.unclassifiedDependencies))){const f=Q(e.dependencies,n,t);return{type:[],value:[],unknown:f}}const s=Q(e.typeOnlyDependencies,n,t),i=Q(e.valueDependencies,n,t),o=Q(e.unclassifiedDependencies,n,t);return{type:s,value:i,unknown:o}}function Mn(e,n,t,r){const s=e.ok===!1,i={...S(e,t,r)};if(!s){const a=jn(e.modules,n,t);a.length>0&&(i.targets=a,i.moduleCount=a.length),t.details===!0&&(i.modules=Fn(e.modules,n,t))}for(const a of["planId","executable","next"])e[a]!==void 0&&(i[a]=e[a]);if(s&&(i.ok=!1,i.code=typeof e.code=="string"?e.code:"MODULE_PLAN_BLOCKED"),l(e.api)&&(i.api=En(e.api,n)),l(e.boundary)&&(i.boundary=_n(e.boundary,n,t),s&&l(i.boundary))){const a=Ln(i.boundary);a.length>0&&(i.blocking=a,delete i.boundary)}const o=Dn(i.boundary);if(o.length>0?i.warnings=o:Array.isArray(e.warnings)&&e.warnings.length>0&&(i.warnings=e.warnings.filter(a=>typeof a=="string").map(a=>hr(a,t))),l(e.facade)){const a=Kn(e.facade,t);i.facade=s?Tn(a):a}const f=Zn(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=zn(e.preview,t,e)),Array.isArray(e.symbolErrors)&&e.symbolErrors.length>0&&(i.ok=!1,i.symbolErrors=e.symbolErrors),s){const a=Pn(i);a.length>0&&(i.affected=a),i.next||(i.next="Revise the plan, then rerun modulePlan preview.")}return i}function En(e,n){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 r=C(e.removed,n),s=C(e.added,n);return r.length>0&&(t.removed=r),s.length>0&&(t.added=s),t}function _n(e,n,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"?A(i.importerFile,t):"",source:typeof i.sourceFile=="string"?A(i.sourceFile,t):"",usage:typeof i.usageKind=="string"?i.usageKind:"unknown",symbols:C(i.symbols,n)},f=We(i.suggestedFixes,n,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 We(e,n,t){return Array.isArray(e)?e.filter(l).map(r=>{const s={kind:typeof r.kind=="string"?r.kind:"unknown"},i=T(r.symbol,n);if(i&&(s.symbol=i),typeof r.toFile=="string"&&(s.to=A(r.toFile,t)),typeof r.fromFile=="string"&&(s.from=A(r.fromFile,t)),typeof r.risk=="string"&&(s.risk=r.risk),typeof r.warning=="string"&&(s.warning=r.warning),l(r.saferAlternative)){const f=We([r.saferAlternative],n,t)[0];f&&(s.saferAlternative=f)}return s}).filter(r=>typeof r.symbol=="string"):[]}function Ln(e){return(Array.isArray(e.nonExportedImports)?e.nonExportedImports.filter(l):[]).map(t=>{const r={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&&(r.suggestedFixes=t.suggestedFixes),typeof t.hint=="string"&&(r.hint=t.hint),r})}function Tn(e){const n={};return typeof e.file=="string"&&(n.file=e.file),Array.isArray(e.exports)&&(n.exports=e.exports.length),n}function Pn(e){const n=new Set,t=Array.isArray(e.blocking)?e.blocking.filter(l):[];for(const r of t)typeof r.from=="string"&&r.from&&n.add(r.from),typeof r.source=="string"&&r.source&&n.add(r.source);return Array.from(n)}function Dn(e){return!l(e)||!Array.isArray(e.nonExportedImports)?[]:e.nonExportedImports.filter(l).map(n=>{const t=typeof n.from=="string"?n.from:"",r=typeof n.source=="string"?n.source:"",s=Array.isArray(n.symbols)?n.symbols.filter(i=>typeof i=="string"):[];return t&&r&&s.length>0?`${t} imports non-exported ${s.join(", ")} from ${r}`:""}).filter(n=>n!=="")}function Fn(e,n,t){if(!Array.isArray(e))return{};const r={};for(const s of e){if(!l(s)||typeof s.targetFile!="string")continue;const i=A(s.targetFile,t),o={owns:C(s.symbols,n)},f=Hn(s.imports,n,t);Object.keys(f).length>0&&(o.uses=f);const a=C(s.internalDependencies,n);a.length>0&&(o.internalDeps=a);const c=Vn(s.unassignedDependencies,n);Object.keys(c).length>0&&(o.unassigned=c),r[i]=o}return r}function jn(e,n,t){return Array.isArray(e)?e.filter(l).filter(r=>typeof r.targetFile=="string").map(r=>{const s={file:A(String(r.targetFile),t),summary:Nn(r,n,t)},i=Gn(r.unassignedDependencies);return i!==""&&(s.warning=`unassigned ${i}`),s}):[]}function Nn(e,n,t){const r=Je(e.symbols,n,!0),s=Je(e.symbols,n,!1),i=Bn(e.imports,n,t),o=C(e.internalDependencies,n).length,f=[`exports ${q(r,4)||"none"}`];return s.length>0&&f.push(`private ${q(s,3)}`),i!==""&&f.push(`imports ${i}`),o>0&&f.push(`internalDeps ${o}`),f.join("; ")}function Je(e,n,t){return Array.isArray(e)?e.filter(l).filter(r=>r.exported===!0===t).map(r=>T(r,n)).filter(r=>r!==""):[]}function Bn(e,n,t){if(!l(e))return"";const r=[],s={typeOnly:"type",value:"run",unclassified:"unclassified"};for(const i of["typeOnly","value","unclassified"]){const o=Un(e[i],n,t);o!==""&&r.push(`${s[i]} ${o}`)}return r.join("; ")}function Un(e,n,t){if(!Array.isArray(e))return"";const r=e.filter(l).filter(s=>typeof s.targetFile=="string").map(s=>{const i=A(String(s.targetFile),t),o=C(s.symbols,n).filter(f=>typeof f=="string");return`${i}: ${q(o,3)||"none"}`});return q(r,2,"more imports")}function Gn(e){if(!l(e))return"";const n=[];for(const t of["typeOnly","value","unclassified"]){const r=e[t];Array.isArray(r)&&r.length>0&&n.push(`${t} ${r.length}`)}return n.join("; ")}function q(e,n,t="more"){if(e.length===0)return"";const r=e.slice(0,n),s=e.length-r.length;return s>0?`${r.join(", ")}, +${s} ${t}`:r.join(", ")}function Hn(e,n,t){if(!l(e))return{};const r={},s={typeOnly:"type",value:"run",unclassified:"unclassified"};for(const i of["typeOnly","value","unclassified"]){const o=qn(e[i],n,t);Object.keys(o).length>0&&(r[s[i]]=o)}return r}function qn(e,n,t){if(!Array.isArray(e))return{};const r={};for(const s of e)!l(s)||typeof s.targetFile!="string"||(r[A(s.targetFile,t)]=C(s.symbols,n));return r}function Vn(e,n){if(!l(e))return{};const t={};for(const r of["typeOnly","value","unclassified"]){const s=C(e[r],n);s.length>0&&(t[r]=s)}return t}function Kn(e,n){const t={};return typeof e.file=="string"&&(t.file=A(e.file,n)),Array.isArray(e.exports)&&e.exports.length>0&&(t.exports=e.exports.filter(r=>typeof r=="string").map(r=>r.match(/from\s+"([^"]+)"/)?.[1]??r)),t}function zn(e,n,t){const r={};typeof e.dir=="string"&&(r.dir=A(e.dir,n));const s=[];let i=0,o=0,f=0;if(Array.isArray(e.files)){const c={};for(const u of e.files){if(!l(u)||typeof u.targetFile!="string"||typeof u.previewFile!="string")continue;i+=1;const p=A(u.targetFile,n),d=g(u.lineCount);c[A(u.targetFile,n)]={file:A(u.previewFile,n),lines:d},d>=vt&&s.push(`${p} ${d}l`)}Object.keys(c).length>0&&(r.files=c)}l(e.facade)&&typeof e.facade.previewFile=="string"&&(o=g(e.facade.lineCount),r.facade={file:A(e.facade.previewFile,n),lines:o}),l(e.patch)&&typeof e.patch.file=="string"&&(f=g(e.patch.lineCount),r.patch={file:A(e.patch.file,n),lines:f},f>=xt&&s.push(`patch ${f}l`)),r.summary=Wn(i,o,f,t),s.length>0&&(r.large=s);const a=Jn(t);return a.length>0&&(r.warnings=a),r.next=Yn(t,s.length>0),r}function Wn(e,n,t,r){const s=[`${e} ${e===1?"file":"files"}`];return n>0&&s.push(`facade ${n}l`),t>0&&s.push(`patch ${t}l`),s.push(ce(r)?"cycles detected":"cycles none"),s.join("; ")}function Jn(e){return ce(e)?["runtime cycles detected"]:[]}function Yn(e,n){return ce(e)?["fix module plan before applying","rerun modulePlan"]:[n?"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 ce(e){return Array.isArray(e.cycles)&&e.cycles.length>0}function Zn(e){const n=Array.isArray(e.modules)?e.modules.filter(l):[];if(n.length===0)return"";const t=n.reduce((o,f)=>o+(Array.isArray(f.symbols)?f.symbols.length:0),0),r=n.reduce((o,f)=>o+Xn(f.imports),0),s=l(e.facade)&&Array.isArray(e.facade.exports)?e.facade.exports.length:0,i=[`${t} declarations moved unchanged`,`${r} imports generated`];return s>0&&i.push(`facade exports ${s}`),i.join("; ")}function Xn(e){if(!l(e))return 0;let n=0;for(const t of["typeOnly","value","unclassified"]){const r=e[t];if(Array.isArray(r))for(const s of r)l(s)&&Array.isArray(s.symbols)&&(n+=s.symbols.length)}return n}function Q(e,n,t){return C(e,n)}function Qn(e,n,t){const r=g(e.memberCount),s=g(e.memberOffset),i=g(e.memberLimit),o=g(e.hiddenMemberCount),f=fe(e.members,n,t,"members"),a=f.length;o>0&&f.push(`+ ${o} hidden members`);const c={members:f};return o>0?(c.count=r,c.page=`${s}..${s+a-1} of ${r}`,c.hint="Use --all to list all members, --offset <n> --limit <n> to page, or inspect code <member> --parent <entity>."):r>K&&(c.count=r),s>0&&o===0&&(c.page=`${s}..${s+f.length-1} of ${r}`),c}function wn(e){const n=g(e.localDeclarationCount),t=Ye(e.reexports);return n===0&&t.length>0?`facade only; ${t.length} ${t.length===1?"re-export":"re-exports"}; 0 local declarations`:n===0?"0 local declarations":`${n} local ${n===1?"declaration":"declarations"}; ${t.length} ${t.length===1?"re-export":"re-exports"}`}function Ye(e){return Array.isArray(e)?e.filter(l).map(n=>typeof n.module=="string"?n.module:"").filter(n=>n!==""):[]}function ae(e,n,t,r){const s=T(e,n),i=typeof e.signature=="string"?e.signature:"",o=t.includeRanges?P(e):"",f=typeof e.sourceModule=="string"?`from ${e.sourceModule}`:"";return r==="file"||r==="exports"?Rn(e,s,i,o,f,r,n):r==="members"?rr(e,s,i,o):s==="constructor"?[o,f,i||s].filter(c=>c!=="").join(" "):[s,o,f,i].filter(c=>c!=="").join(" ")}function Rn(e,n,t,r,s,i,o){const f=typeof e.display=="string"?e.display:"";if(f)return[f,r].filter(y=>y!=="").join(" ");const a=le(e),c=typeof e.exportKind=="string"?e.exportKind:"",u=tr(e,o);if(c==="default"){const x=`${a}${i==="file"?"export default ":"default "}${u||n}${Xe(e,t)}`;return[x,r,ue(x,s)].filter(_=>_!=="").join(" ")}if(c==="exportEquals"){const y=`${a}export = ${u||n}`;return[y,r,ue(y,s)].filter(x=>x!=="").join(" ")}const p=i==="file"&&e.exported===!0?"export ":"",d=Xe(e,t),m=e.iife===!0?`${e.async===!0?" IIFE async":" IIFE"}`:"",h=nr(e),v=`${a}${p}${n}${d}${m}`;return[v,r,h,ue(v,s)].filter(y=>y!=="").join(" ")}function ue(e,n){return n?/\bfrom\s+["']?/.test(e)?"":n:""}function er(e,n,t){const r=typeof e.display=="string"?e.display:"",i=(r||n).match(/\bexport\s+\{\s*(.*?)\s*\}\s+from\s+/);return i?.[1]?i[1]:/^export\s+\*\s+from\s+/.test(r)?"*":e.exportKind==="default"?"default":n.replace(` from ${t}`,"")}function V(e){const n=e.match(/^(.*\bfrom\s+["']([^"']+)["'][^\r\n]*?)\s+from\s+([^\s]+)$/);if(!n)return e;const t=n[2]??"",r=n[3]??"";return Ze(t)===Ze(r)?n[1]??e:e}function Ze(e){return e.replace(/^["']|["']$/g,"")}function le(e){if(!Array.isArray(e.decorators))return"";const n=e.decorators.filter(t=>typeof t=="string"&&t.trim()!=="").join(" ");return n?`${n} `:""}function tr(e,n){return l(e.exportTarget)?T(e.exportTarget,n):""}function Xe(e,n){if(typeof e.overloadCount=="number"&&e.overloadCount>1)return"";const t=typeof e.name=="string"?e.name:"",r=typeof e.kind=="string"?ge(e.kind):null;if(!t||!n||r!=="function"&&r!=="method")return"";const s=n.indexOf(t);if(s<0)return"";const i=n.slice(s+t.length).trim();return i.startsWith("(")?i:""}function nr(e){const n=typeof e.overloadCount=="number"?e.overloadCount:0;return n>1?`overloads=${n}`:""}function rr(e,n,t,r){const s=typeof e.kind=="string"?ge(e.kind):null,i=typeof e.name=="string"?e.name:"";let o=`${le(e)}${t||Qe(n)}`.trim();if(s==="property"&&i){o=`${le(e)}${n}`.trim();const f=sr(t,i);f&&(o+=f)}return[o,r].filter(f=>f!=="").join(" ")}function sr(e,n){if(!e)return"";const t=e.indexOf(n);if(t<0)return"";const r=e.slice(t+n.length).trim();return r.startsWith(":")?r:""}function ir(e,n,t){const r=gr(e,["id","op","ok","code","error"]);if(typeof e.sourceFile=="string"){const s=A(e.sourceFile,n);s!==t&&(r.file=s)}if(e.code==="INSPECT_SYMBOL_NOT_FOUND"){const s=or(e);s&&(r.missingSymbols=[s])}return r}function j(e){return e.code==="INSPECT_SYMBOL_NOT_FOUND"&&E(e).length>0}function E(e){return Array.isArray(e.missingSymbols)?e.missingSymbols.filter(n=>typeof n=="string"&&n.length>0):[]}function or(e){const n=typeof e.error=="string"?e.error:"",t="Symbol not found:";if(!n.startsWith(t))return null;const r=n.slice(t.length).trim();if(!r)return null;const s=r.indexOf(":");return s>0?r.slice(s+1).trim():r}function T(e,n){if(!l(e))return"";if(typeof e.selector=="string"&&e.selector.trim()!=="")return e.selector;const t=typeof e.name=="string"?e.name:"",r=typeof e.kind=="string"?ge(e.kind):null;return t?r==="constructor"?"constructor":r?`${dr(r,n)}${yr(r,n)}${t}`:t:""}function N(e,n){return pe(e)||T(e,n)}function w(e){if(!l(e))return"";const n=Array.isArray(e.path)?e.path.filter(t=>typeof t=="string"&&t.trim()!==""):[];return n.length>0?n.join("."):pe(e)}function pe(e){return l(e)&&typeof e.name=="string"?e.name:""}function Qe(e){const n=e.indexOf("-");if(n>0&&n<=3)return e.slice(n+1);const t=e.indexOf(":");return t>0?e.slice(t+1):e}function we(e,n){return n>K?{[e]:n}:{}}function Re(e,n){return e===1?n:`${n}s`}function et(e,n){return e.localeCompare(n,void 0,{numeric:!0})}function fr(e,n,t){const r=new Set(n?[n]:[]);for(const s of e){typeof s.declaredIn=="string"&&r.add(A(s.declaredIn,t));const i=Array.isArray(s.usedBy)?s.usedBy.filter(l):[];for(const o of i)typeof o.file=="string"&&r.add(A(o.file,t))}return Array.from(r)}function cr(e){const n=ar(e.map(t=>t.replace(/\\/g,"/")));return nt(n)}function tt(){return nt([])}function nt(e){return{aliases:e,compactPath(n){const t=de(n),r=e.find(s=>t===s.prefix||t.startsWith(`${s.prefix}/`));return r?t===r.prefix?r.token:`${r.token}/${t.slice(r.prefix.length+1)}`:t}}}function ar(e){const n=new Map;for(const r of e){const s=de(r).split("/");for(let i=2;i<s.length;i+=1){const o=s.slice(0,i).join("/");o.length>=8&&n.set(o,(n.get(o)??0)+1)}}const t=new Set;return Array.from(n.entries()).map(([r,s])=>{const i=`<${b.basename(r)}>`;return{prefix:r,count:s,token:i,score:Math.max(0,r.length-i.length)*s}}).filter(r=>r.count>=2&&r.score>=12).sort((r,s)=>s.score-r.score||r.prefix.localeCompare(s.prefix)).filter(r=>t.has(r.token)?!1:(t.add(r.token),!0)).slice(0,6).sort((r,s)=>s.prefix.length-r.prefix.length).map(r=>({token:r.token,prefix:r.prefix}))}function ur(e,n){if(e.aliases.length===0)return null;const t=JSON.stringify(n),r={};for(const s of e.aliases)t.includes(s.token)&&(r[s.token]=s.prefix);return Object.keys(r).length>0?r:null}function lr(e){const n=new Map,t=[];for(const r of e){const s=r.startsWith("<")?r.indexOf(">"):-1;if(s<=0){t.push(r);continue}const i=r.indexOf("/",s);if(i<0){t.push(r);continue}const o=r.slice(0,i),f=r.slice(i+1),a=n.get(o)??[];a.push(f),n.set(o,a)}return[...Array.from(n.entries()).map(([r,s])=>s.length===1?`${r}/${s[0]}`:`${r}/: ${s.join(", ")}`),...t].sort()}function de(e){return e.replace(/\\/g,"/")}function ye(e,n,t){const r=e.indexOf(n);if(r<=0)return null;const s=e.slice(0,r).trim(),i=e.slice(r+n.length).trim();if(!s||!i)return null;const o=pr(s,t);return o?{raw:e,symbolName:i,symbolKind:o}:null}function pr(e,n){const t=e.toLowerCase();return rt(t)?t:Object.entries(n.entityKindAliases).find(([,s])=>s===e)?.[0]??null}function dr(e,n){return st(e)?n.entityKindAliases[e]:e}function yr(e,n){return st(e)?n.selectorSeparator:":"}function ge(e){const n=e.toLowerCase();return rt(n)?n:null}function rt(e){return At.includes(e)}function st(e){return pt.ENTITY_KIND_IDS.includes(e)}function gr(e,n){const t={};for(const r of n)e[r]!==void 0&&(t[r]=e[r]);return t}function mr(e,n){const t=e.filter(l).map(s=>typeof s.sourceFile=="string"?A(s.sourceFile,n):null).filter(s=>!!s),r=Array.from(new Set(t));return r.length===1?r[0]??null:null}function A(e,n){const t=b.isAbsolute(e)?e:b.resolve(n.cwd,e),r=b.relative(n.cwd,t),i=(r&&!r.startsWith("..")&&!b.isAbsolute(r)?r:e).replace(/\\/g,"/"),o=(0,ht.compactDisplayPathWithMatch)(n.cwd,t,n.displayPathAliases??[]);return o.alias&&n.pathAliasHints&&(n.pathAliasHints.some(a=>a.alias===o.alias.token&&a.original===i&&a.display===o.displayPath)||n.pathAliasHints.push({alias:o.alias.token,original:i,display:o.displayPath})),o.displayPath}function hr(e,n){const t=b.resolve(n.cwd),r=t.replace(/\\/g,"/");return e.replaceAll(`${t}\\`,"").replaceAll(`${r}/`,"").replace(/\\/g,"/")}function it(e,n,t){const r=b.isAbsolute(n)?n:b.resolve(e,n);return U.mkdirSync(b.dirname(r),{recursive:!0}),U.writeFileSync(r,t,"utf8"),b.relative(e,r).replace(/\\/g,"/")}function ot(e,n,t,r,s){const i=typeof r.sourceFile=="string"&&b.extname(r.sourceFile)||".ts",o=(0,$.saveSessionOutputText)(e,n,t,s,i);return{saved:o.saved,last:o.last}}function P(e,n){if(!l(e)||!l(e.range))return"";const t=ft(e.range,"start"),r=ft(e.range,"end");if(!t||!r)return"";const s=t.line+1,i=r.line+1;return s===i?`@${s}`:`@${s}..${i}`}function ft(e,n){const t=e[n];return!l(t)||typeof t.line!="number"?null:{line:t.line}}function g(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
+ }