@automaton-labs/aib 0.0.6 → 0.0.8

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