@automaton-labs/aib 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/README.md +21 -578
  2. package/config/agent-dx-policy.default.json +31 -0
  3. package/config/control-plane-client.default.json +3 -0
  4. package/dist/agent-dx/agent-dx.js +805 -0
  5. package/dist/agent-dx/presentation.js +32 -0
  6. package/dist/alias-advisor/analyze.js +982 -0
  7. package/dist/alias-advisor/exact-text-cost.js +74 -0
  8. package/dist/alias-advisor/lexical.js +240 -0
  9. package/dist/alias-advisor/model.js +2 -0
  10. package/dist/alias-advisor/path-identity.js +49 -0
  11. package/dist/alias-advisor/ranking.js +171 -0
  12. package/dist/alias-advisor/token-estimator.js +85 -0
  13. package/dist/bin/aib.js +5 -1
  14. package/dist/bin/cli.js +811 -4
  15. package/dist/commands/add-missing-imports-preview-cache.js +99 -2
  16. package/dist/commands/add-missing-imports.js +241 -2
  17. package/dist/commands/apply-module-plan.js +1319 -3
  18. package/dist/commands/background-command.js +378 -2
  19. package/dist/commands/captured-input.js +74 -1
  20. package/dist/commands/config-command.js +314 -2
  21. package/dist/commands/config-output.js +357 -10
  22. package/dist/commands/control-plane-command.js +183 -1
  23. package/dist/commands/declaration-command.js +1209 -7
  24. package/dist/commands/declaration-execution-cache.js +79 -1
  25. package/dist/commands/declaration-format.js +221 -1
  26. package/dist/commands/declaration-preview-cache.js +114 -2
  27. package/dist/commands/diagnostics-command.js +70 -3
  28. package/dist/commands/doctor.js +137 -3
  29. package/dist/commands/execution-command.js +117 -1
  30. package/dist/commands/exports-star-collapse-command.js +178 -0
  31. package/dist/commands/exports-star-command.js +252 -0
  32. package/dist/commands/exports-star-preview-cache.js +84 -0
  33. package/dist/commands/feedback-command.js +176 -3
  34. package/dist/commands/file-move-to-dir-execution-cache.js +92 -1
  35. package/dist/commands/file-move-to-dir-preview-cache.js +125 -2
  36. package/dist/commands/file-move-to-dir-worker.js +54 -0
  37. package/dist/commands/file-move-to-dir.js +1073 -5
  38. package/dist/commands/file-mutation-runtime.js +102 -1
  39. package/dist/commands/file-mutation-worker-apply.js +180 -0
  40. package/dist/commands/file-refactor-batch-execution-cache.js +90 -1
  41. package/dist/commands/file-refactor-batch-preview-cache.js +125 -2
  42. package/dist/commands/file-refactor-batch-worker.js +54 -0
  43. package/dist/commands/file-refactor-batch.js +1154 -5
  44. package/dist/commands/file-rename-execution-cache.js +92 -1
  45. package/dist/commands/file-rename-preview-cache.js +125 -2
  46. package/dist/commands/file-rename-worker.js +54 -0
  47. package/dist/commands/file-rename.js +1053 -5
  48. package/dist/commands/file-text-edit-executor.js +205 -0
  49. package/dist/commands/find-importers.js +52 -1
  50. package/dist/commands/find-unused-imports.js +55 -1
  51. package/dist/commands/generate-docs-command.js +244 -6
  52. package/dist/commands/help-command.js +460 -7
  53. package/dist/commands/import-specifier-policy.js +391 -0
  54. package/dist/commands/imports-command.js +68 -1
  55. package/dist/commands/imports-rebase.js +1138 -0
  56. package/dist/commands/init-skill-usage.js +92 -3
  57. package/dist/commands/init-workspace.js +30 -1
  58. package/dist/commands/inspect-alias-candidates.js +413 -0
  59. package/dist/commands/inspect-cycles.js +811 -5
  60. package/dist/commands/inspect-direct-usages.js +98 -0
  61. package/dist/commands/inspect-duplicates-format.js +229 -0
  62. package/dist/commands/inspect-format-primitives.js +127 -0
  63. package/dist/commands/inspect-format.js +1590 -18
  64. package/dist/commands/inspect-graph.js +1553 -9
  65. package/dist/commands/inspect-imports.js +339 -2
  66. package/dist/commands/inspect-mixed-format.js +524 -0
  67. package/dist/commands/inspect-module-plan-format.js +216 -0
  68. package/dist/commands/inspect-module-plan-serialization.js +402 -0
  69. package/dist/commands/inspect-reference-path-format.js +157 -0
  70. package/dist/commands/inspect-request-values.js +599 -0
  71. package/dist/commands/inspect-selector-kind.js +21 -0
  72. package/dist/commands/inspect-selector.js +50 -0
  73. package/dist/commands/inspect-symbol-format.js +90 -0
  74. package/dist/commands/inspect-topology.js +435 -0
  75. package/dist/commands/inspect-tree.js +827 -5
  76. package/dist/commands/inspect-usages-detail.js +793 -0
  77. package/dist/commands/inspect-usages-evidence.js +31 -0
  78. package/dist/commands/inspect-usages-format.js +367 -0
  79. package/dist/commands/inspect.js +1450 -16
  80. package/dist/commands/internal-command.js +64 -0
  81. package/dist/commands/json-file-input.js +60 -1
  82. package/dist/commands/module-plan-cache.js +156 -2
  83. package/dist/commands/module-plan-standalone.js +208 -0
  84. package/dist/commands/module-plan-timeout.js +77 -1
  85. package/dist/commands/move-preview-cache.js +101 -2
  86. package/dist/commands/mutate-aggregate-output.js +996 -0
  87. package/dist/commands/mutate-child-execution.js +374 -0
  88. package/dist/commands/mutate-command.js +1394 -0
  89. package/dist/commands/mutate-declaration-output.js +313 -0
  90. package/dist/commands/mutate-domain-adapters.js +638 -0
  91. package/dist/commands/mutate-execution-cache.js +114 -0
  92. package/dist/commands/mutate-execution-status.js +598 -0
  93. package/dist/commands/mutate-failure-output.js +531 -0
  94. package/dist/commands/mutate-file-view.js +151 -0
  95. package/dist/commands/mutate-object-output.js +91 -0
  96. package/dist/commands/mutate-output-values.js +97 -0
  97. package/dist/commands/mutate-preview-cache.js +86 -0
  98. package/dist/commands/mutate-response-replay.js +153 -0
  99. package/dist/commands/mutate-result-projection.js +818 -0
  100. package/dist/commands/mutation-eta.js +28 -0
  101. package/dist/commands/mutation-execution-cache.js +140 -3
  102. package/dist/commands/mutation-recovery-journal.js +195 -0
  103. package/dist/commands/normalize-imports.js +1120 -4
  104. package/dist/commands/object-pack-command.js +546 -0
  105. package/dist/commands/object-pack-preview-cache.js +88 -0
  106. package/dist/commands/observability-command.js +47 -3
  107. package/dist/commands/ota-command.js +403 -2
  108. package/dist/commands/print-config.js +10 -1
  109. package/dist/commands/quick-read.js +1113 -11
  110. package/dist/commands/refactor-batch-builder.js +265 -1
  111. package/dist/commands/refactor-batch-execution-cache.js +85 -1
  112. package/dist/commands/refactor-batch-preview-cache.js +96 -2
  113. package/dist/commands/refactor-batch.js +461 -4
  114. package/dist/commands/rename-entities.js +794 -4
  115. package/dist/commands/rename-execution-cache.js +49 -1
  116. package/dist/commands/rename-input.js +22 -1
  117. package/dist/commands/rename-polling-policy.js +68 -0
  118. package/dist/commands/rename-preview-cache.js +96 -2
  119. package/dist/commands/result-view.js +993 -7
  120. package/dist/commands/reveal-command.js +445 -5
  121. package/dist/commands/selector-suggestions.js +93 -0
  122. package/dist/commands/session-workspace.js +1836 -31
  123. package/dist/commands/shared.js +2 -1
  124. package/dist/commands/skills-command.js +315 -0
  125. package/dist/commands/sync-command.js +59 -2
  126. package/dist/commands/worker-command.js +173 -1
  127. package/dist/commands/workspace-cache.js +55 -1
  128. package/dist/config/defaults.js +26 -1
  129. package/dist/config/env-vars.js +77 -1
  130. package/dist/config/glob-match.js +44 -1
  131. package/dist/config/import-rules.js +165 -1
  132. package/dist/config/local-config.js +293 -3
  133. package/dist/config/mutation-comments.js +51 -1
  134. package/dist/config/path-aliases.js +165 -1
  135. package/dist/config/path-display.js +84 -1
  136. package/dist/config/product-storage.js +37 -1
  137. package/dist/config/request-env.js +21 -0
  138. package/dist/config/request-routing-context.js +23 -0
  139. package/dist/config/resolve-command-alias.js +74 -1
  140. package/dist/config/resolve.js +24 -1
  141. package/dist/config/tsconfig-discovery.js +113 -1
  142. package/dist/config/typescript-preferences.js +131 -0
  143. package/dist/config/workspace-root.js +310 -3
  144. package/dist/config/workspace-state.js +254 -1
  145. package/dist/content/content-bundle.js +88 -1
  146. package/dist/diagnostics/module-plan-timeline.js +75 -2
  147. package/dist/diagnostics/readiness-text.js +45 -8
  148. package/dist/dsl/aib-dsl.js +838 -1
  149. package/dist/dsl/declaration-dsl.js +264 -1
  150. package/dist/dsl/file-move-to-dir-dsl.js +123 -1
  151. package/dist/dsl/file-refactor-batch-dsl.js +203 -1
  152. package/dist/dsl/file-rename-dsl.js +135 -1
  153. package/dist/dsl/mutate-dsl.js +746 -0
  154. package/dist/help/bootstrap.bash.md +176 -341
  155. package/dist/help/bootstrap.md +175 -340
  156. package/dist/help/bootstrap.pwsh.md +176 -341
  157. package/dist/help/docs/basics.md +1 -1
  158. package/dist/help/docs/config-setup.import-normalize.md +65 -65
  159. package/dist/help/docs/config-setup.import-rules.md +6 -5
  160. package/dist/help/docs/first-setup.md +6 -5
  161. package/dist/help/docs/help-protocol.md +4 -3
  162. package/dist/help/docs/import.base.md +38 -0
  163. package/dist/help/docs/import.rebase.md +85 -0
  164. package/dist/help/docs/inspect.aliasCandidates.md +39 -0
  165. package/dist/help/docs/inspect.code.md +1 -7
  166. package/dist/help/docs/inspect.file.md +10 -19
  167. package/dist/help/docs/inspect.graph.md +3 -17
  168. package/dist/help/{dsl/docs/inspect.md → docs/inspect.shared.md} +13 -12
  169. package/dist/help/docs/modulePlan.md +24 -28
  170. package/dist/help/docs/move.md +19 -22
  171. package/dist/help/{dsl/topics/file.move.md → docs/moveToDir.md} +36 -34
  172. package/dist/help/docs/mutate.mixed.md +34 -0
  173. package/dist/help/docs/mutation.shared.md +55 -0
  174. package/dist/help/docs/patterns.md +3 -12
  175. package/dist/help/docs/qr.md +12 -6
  176. package/dist/help/docs/quick-map.md +36 -24
  177. package/dist/help/docs/recipe.file-layout.md +10 -10
  178. package/dist/help/docs/recipe.import-boundary.md +92 -0
  179. package/dist/help/docs/recipe.safe-artifact-probing.md +68 -0
  180. package/dist/help/docs/recipe.unfamiliar-area.md +64 -0
  181. package/dist/help/docs/recipes.md +20 -0
  182. package/dist/help/docs/rename.md +19 -27
  183. package/dist/help/docs/renameFile.md +36 -0
  184. package/dist/help/docs/rules.md +26 -0
  185. package/dist/help/dsl/bootstrap.bash.md +176 -341
  186. package/dist/help/dsl/bootstrap.md +175 -340
  187. package/dist/help/dsl/bootstrap.pwsh.md +176 -341
  188. package/dist/help/dsl/docs/basics.md +1 -1
  189. package/dist/help/dsl/docs/config-setup.import-normalize.md +65 -65
  190. package/dist/help/dsl/docs/config-setup.import-rules.md +6 -5
  191. package/dist/help/dsl/docs/first-setup.md +6 -5
  192. package/dist/help/dsl/docs/help-protocol.md +4 -3
  193. package/dist/help/dsl/docs/import.base.md +38 -0
  194. package/dist/help/dsl/docs/import.rebase.md +85 -0
  195. package/dist/help/dsl/docs/inspect.aliasCandidates.md +39 -0
  196. package/dist/help/dsl/docs/inspect.code.md +1 -7
  197. package/dist/help/dsl/docs/inspect.file.md +10 -19
  198. package/dist/help/dsl/docs/inspect.graph.md +3 -17
  199. package/dist/help/{docs/inspect.md → dsl/docs/inspect.shared.md} +13 -12
  200. package/dist/help/dsl/docs/modulePlan.md +24 -28
  201. package/dist/help/dsl/docs/move.md +19 -22
  202. package/dist/help/{topics/file.move.md → dsl/docs/moveToDir.md} +36 -34
  203. package/dist/help/dsl/docs/mutate.mixed.md +34 -0
  204. package/dist/help/dsl/docs/mutation.shared.md +55 -0
  205. package/dist/help/dsl/docs/patterns.md +3 -12
  206. package/dist/help/dsl/docs/qr.md +12 -6
  207. package/dist/help/dsl/docs/quick-map.md +36 -24
  208. package/dist/help/dsl/docs/recipe.file-layout.md +10 -10
  209. package/dist/help/dsl/docs/recipe.import-boundary.md +92 -0
  210. package/dist/help/dsl/docs/recipe.safe-artifact-probing.md +68 -0
  211. package/dist/help/dsl/docs/recipe.unfamiliar-area.md +64 -0
  212. package/dist/help/dsl/docs/recipes.md +20 -0
  213. package/dist/help/dsl/docs/rename.md +19 -27
  214. package/dist/help/dsl/docs/renameFile.md +36 -0
  215. package/dist/help/dsl/docs/rules.md +26 -0
  216. package/dist/help/dsl/full.md +175 -340
  217. package/dist/help/dsl/help-index.md +48 -43
  218. package/dist/help/dsl/snippets/agents.md +2 -2
  219. package/dist/help/dsl/tokens/qr.inline.examples.md +1 -1
  220. package/dist/help/dsl/topics/basics.md +1 -1
  221. package/dist/help/dsl/topics/config-setup.import-normalize.md +65 -65
  222. package/dist/help/dsl/topics/config-setup.import-rules.md +6 -5
  223. package/dist/help/dsl/topics/first-setup.md +6 -5
  224. package/dist/help/dsl/topics/help-protocol.md +4 -3
  225. package/dist/help/dsl/topics/import.base.md +36 -0
  226. package/dist/help/dsl/topics/import.rebase.md +83 -0
  227. package/dist/help/dsl/topics/inspect.aliasCandidates.md +37 -0
  228. package/dist/help/dsl/topics/inspect.code.md +1 -7
  229. package/dist/help/dsl/topics/inspect.file.md +10 -19
  230. package/dist/help/dsl/topics/inspect.graph.md +3 -17
  231. package/dist/help/dsl/topics/{inspect.md → inspect.shared.md} +13 -12
  232. package/dist/help/dsl/topics/modulePlan.md +21 -26
  233. package/dist/help/dsl/topics/move.md +17 -18
  234. package/dist/help/{docs/file.move.md → dsl/topics/moveToDir.md} +33 -35
  235. package/dist/help/dsl/topics/mutate.mixed.md +32 -0
  236. package/dist/help/dsl/topics/mutation.shared.md +53 -0
  237. package/dist/help/dsl/topics/patterns.md +3 -12
  238. package/dist/help/dsl/topics/qr.md +12 -6
  239. package/dist/help/dsl/topics/quick-map.md +36 -24
  240. package/dist/help/dsl/topics/recipe.file-layout.md +10 -10
  241. package/dist/help/dsl/topics/recipe.import-boundary.md +90 -0
  242. package/dist/help/dsl/topics/recipe.safe-artifact-probing.md +66 -0
  243. package/dist/help/dsl/topics/recipe.unfamiliar-area.md +62 -0
  244. package/dist/help/dsl/topics/recipes.md +18 -0
  245. package/dist/help/dsl/topics/rename.md +15 -15
  246. package/dist/help/dsl/topics/renameFile.md +34 -0
  247. package/dist/help/dsl/topics/rules.md +24 -0
  248. package/dist/help/full.md +175 -340
  249. package/dist/help/help-index.md +48 -43
  250. package/dist/help/help-meta.json +98 -48
  251. package/dist/help/index.md +52 -20
  252. package/dist/help/snippets/agents.md +2 -2
  253. package/dist/help/tokens/qr.inline.examples.md +1 -1
  254. package/dist/help/topics/basics.md +1 -1
  255. package/dist/help/topics/config-setup.import-normalize.md +65 -65
  256. package/dist/help/topics/config-setup.import-rules.md +6 -5
  257. package/dist/help/topics/first-setup.md +6 -5
  258. package/dist/help/topics/help-protocol.md +4 -3
  259. package/dist/help/topics/import.base.md +36 -0
  260. package/dist/help/topics/import.rebase.md +83 -0
  261. package/dist/help/topics/inspect.aliasCandidates.md +37 -0
  262. package/dist/help/topics/inspect.code.md +1 -7
  263. package/dist/help/topics/inspect.file.md +10 -19
  264. package/dist/help/topics/inspect.graph.md +3 -17
  265. package/dist/help/topics/{inspect.md → inspect.shared.md} +13 -12
  266. package/dist/help/topics/modulePlan.md +21 -26
  267. package/dist/help/topics/move.md +17 -18
  268. package/dist/help/{dsl/docs/file.move.md → topics/moveToDir.md} +33 -35
  269. package/dist/help/topics/mutate.mixed.md +32 -0
  270. package/dist/help/topics/mutation.shared.md +53 -0
  271. package/dist/help/topics/patterns.md +3 -12
  272. package/dist/help/topics/qr.md +12 -6
  273. package/dist/help/topics/quick-map.md +36 -24
  274. package/dist/help/topics/recipe.file-layout.md +10 -10
  275. package/dist/help/topics/recipe.import-boundary.md +90 -0
  276. package/dist/help/topics/recipe.safe-artifact-probing.md +66 -0
  277. package/dist/help/topics/recipe.unfamiliar-area.md +62 -0
  278. package/dist/help/topics/recipes.md +18 -0
  279. package/dist/help/topics/rename.md +15 -15
  280. package/dist/help/topics/renameFile.md +34 -0
  281. package/dist/help/topics/rules.md +24 -0
  282. package/dist/host/capabilities.js +56 -1
  283. package/dist/imports/standalone-import-analysis.js +602 -0
  284. package/dist/imports/standalone-import-model.js +2 -0
  285. package/dist/imports/standalone-import-process.js +66 -0
  286. package/dist/imports/standalone-import-worker.js +27 -0
  287. package/dist/imports/standalone-ts-project.js +147 -0
  288. package/dist/inspect/inspect-duplicates-service.js +526 -0
  289. package/dist/inspect/inspect-reverse-module-closure.js +338 -0
  290. package/dist/inspect/inspect-source-ranges.js +82 -0
  291. package/dist/inspect/inspect-source-shape.js +649 -0
  292. package/dist/inspect/standalone-inspect-analysis.js +319 -0
  293. package/dist/inspect/standalone-inspect-model.js +9 -0
  294. package/dist/inspect/standalone-inspect-process.js +55 -0
  295. package/dist/inspect/standalone-inspect-usages.js +274 -0
  296. package/dist/inspect/standalone-inspect-worker.js +13 -0
  297. package/dist/metrics/central-metrics.js +101 -2
  298. package/dist/mutation/concrete-edit-plan.js +157 -0
  299. package/dist/mutation/exports-star-collapse-preview.js +361 -0
  300. package/dist/mutation/exports-star-expand-apply.js +373 -0
  301. package/dist/mutation/exports-star-expand-preview.js +807 -0
  302. package/dist/mutation/file-impact-scan.js +182 -0
  303. package/dist/mutation/file-mutation-discovery.js +674 -0
  304. package/dist/mutation/file-mutation-eta.js +99 -0
  305. package/dist/mutation/file-mutation-standalone-apply.js +584 -0
  306. package/dist/mutation/file-mutation-standalone-planner.js +500 -0
  307. package/dist/mutation/file-mutation-tsserver-session.js +473 -0
  308. package/dist/mutation/mutation-estimate.js +45 -0
  309. package/dist/mutation/mutation-plan.js +467 -0
  310. package/dist/mutation/object-mutation-foundation.js +2 -0
  311. package/dist/mutation/object-mutation-partition.js +148 -0
  312. package/dist/mutation/object-pack-semantic-apply.js +507 -0
  313. package/dist/mutation/object-pack-semantic-preview.js +984 -0
  314. package/dist/mutation/object-unpack-semantic-preview.js +993 -0
  315. package/dist/mutation/package-manifest-impact.js +176 -0
  316. package/dist/mutation/rename-owner-worker-child.js +37 -0
  317. package/dist/mutation/rename-owner-worker.js +122 -0
  318. package/dist/mutation/runtime-cycle-query.js +66 -0
  319. package/dist/mutation/semantic-execution-progress.js +63 -0
  320. package/dist/mutation/semantic-export-index.js +474 -0
  321. package/dist/mutation/semantic-impact-scan.js +434 -0
  322. package/dist/mutation/semantic-model.js +2 -0
  323. package/dist/mutation/semantic-move-best-effort-planner.js +209 -0
  324. package/dist/mutation/semantic-move-config-worker-child.js +61 -0
  325. package/dist/mutation/semantic-move-config-worker.js +449 -0
  326. package/dist/mutation/semantic-move-declarations.js +94 -0
  327. package/dist/mutation/semantic-move-metrics.js +119 -0
  328. package/dist/mutation/semantic-move-model.js +2 -0
  329. package/dist/mutation/semantic-move-owner-authority.js +122 -0
  330. package/dist/mutation/semantic-move-owner-candidates.js +300 -0
  331. package/dist/mutation/semantic-move-owner-divergence-harness.js +474 -0
  332. package/dist/mutation/semantic-move-owner-divergence-runner.js +162 -0
  333. package/dist/mutation/semantic-move-plan-hash.js +56 -0
  334. package/dist/mutation/semantic-move-policy.js +360 -0
  335. package/dist/mutation/semantic-move-process.js +218 -0
  336. package/dist/mutation/semantic-move-provider-diagnostics.js +27 -0
  337. package/dist/mutation/semantic-move-standalone-engine.js +919 -0
  338. package/dist/mutation/semantic-move-standalone-planner.js +1553 -0
  339. package/dist/mutation/semantic-move-transaction.js +639 -0
  340. package/dist/mutation/semantic-mutation-engine.js +478 -0
  341. package/dist/mutation/semantic-mutation-runtime.js +521 -0
  342. package/dist/mutation/semantic-planner-retry.js +26 -0
  343. package/dist/mutation/semantic-program-roots.js +69 -0
  344. package/dist/mutation/semantic-rename-commonjs.js +229 -0
  345. package/dist/mutation/semantic-rename-config-worker-child.js +46 -0
  346. package/dist/mutation/semantic-rename-config-worker.js +498 -0
  347. package/dist/mutation/semantic-rename-locations.js +192 -0
  348. package/dist/mutation/semantic-rename-model.js +2 -0
  349. package/dist/mutation/semantic-rename-process.js +217 -0
  350. package/dist/mutation/semantic-rename-standalone-engine.js +302 -0
  351. package/dist/mutation/semantic-rename-standalone-planner.js +567 -0
  352. package/dist/mutation/semantic-rename-transaction.js +333 -0
  353. package/dist/mutation/semantic-unused-import-cleanup.js +248 -0
  354. package/dist/mutation/semantic-worker-retry.js +40 -0
  355. package/dist/mutation/semantic-workspace.js +804 -0
  356. package/dist/mutation/targeted-import-canonicalizer.js +359 -0
  357. package/dist/observability/config.js +206 -1
  358. package/dist/observability/context.js +59 -1
  359. package/dist/observability/failure-snapshot.js +124 -2
  360. package/dist/observability/recent.js +63 -2
  361. package/dist/payloads/read-stdin-json.js +212 -1
  362. package/dist/rg-wrapper/core.js +714 -6
  363. package/dist/rg-wrapper/options.js +125 -1
  364. package/dist/rtk-wrapper/core.js +144 -2
  365. package/dist/rtk-wrapper/git-safety.js +203 -0
  366. package/dist/rtk-wrapper/output-adapter.js +106 -0
  367. package/dist/runtime/buffered-process.js +114 -0
  368. package/dist/runtime/bundled-node.js +97 -1
  369. package/dist/runtime/command-lifecycle.js +2 -0
  370. package/dist/runtime/input-source.js +238 -1
  371. package/dist/runtime/node-cli-identity.js +37 -0
  372. package/dist/runtime/run-command.js +191 -1
  373. package/dist/selectors/parse-entities.js +84 -1
  374. package/dist/semantic/semantic-context-pool.js +830 -0
  375. package/dist/semantic/semantic-context-provider.js +416 -0
  376. package/dist/semantic/semantic-resident-admission.js +38 -0
  377. package/dist/semantic/semantic-worker-child.js +40 -0
  378. package/dist/semantic/semantic-worker-manager.js +460 -0
  379. package/dist/semantic/semantic-worker-protocol.js +2 -0
  380. package/dist/semantic/semantic-worker-runtime.js +38 -0
  381. package/dist/semantic/workspace-semantic-context-pools.js +136 -0
  382. package/dist/session/client.js +359 -1
  383. package/dist/session/daemon-state.js +185 -2
  384. package/dist/session/external-tool-coordinator.js +88 -0
  385. package/dist/session/external-tool-request.js +52 -0
  386. package/dist/session/lane-owner.js +116 -0
  387. package/dist/session/paths.js +71 -1
  388. package/dist/session/runtime-lifecycle.js +225 -0
  389. package/dist/session/runtime-shutdown.js +95 -0
  390. package/dist/session/server.js +1194 -7
  391. package/dist/session/session-health.js +27 -0
  392. package/dist/shared/agent-text.js +29 -1
  393. package/dist/shared/errors.js +496 -30
  394. package/dist/shared/event-loop.js +6 -1
  395. package/dist/shared/hints.js +37 -1
  396. package/dist/shared/metrics.js +43 -1
  397. package/dist/shared/presentation.js +69 -4
  398. package/dist/shared/stdin-examples.js +77 -1
  399. package/dist/shared/stdout.js +6 -2
  400. package/dist/shared/types.js +23 -1
  401. package/dist/tool-runtime/runtime-tools.js +120 -1
  402. package/dist/topology/availability.js +663 -0
  403. package/dist/topology/cache.js +130 -0
  404. package/dist/topology/candidates.js +372 -0
  405. package/dist/topology/core.js +903 -0
  406. package/dist/topology/dependency-snapshot.js +189 -0
  407. package/dist/topology/model.js +2 -0
  408. package/dist/topology/scope.js +100 -0
  409. package/dist/topology/ts-oracle-batch.js +529 -0
  410. package/dist/topology/ts-oracle-host.js +69 -0
  411. package/dist/topology/ts-oracle-model.js +2 -0
  412. package/dist/topology/ts-oracle.js +224 -0
  413. package/dist/topology/tsconfig-loader.js +105 -0
  414. package/dist/topology/workspace-project-index.js +542 -0
  415. package/dist/tracing/config.js +192 -2
  416. package/dist/tracing/failure-summary.js +100 -0
  417. package/dist/tracing/trace.js +318 -5
  418. package/dist/tsc-wrapper/core.js +697 -0
  419. package/dist/workers/control-plane/aib-control-plane-worker.cjs +32 -32
  420. package/dist/workers/control-plane/client-config.default.json +3 -3
  421. package/dist/workers/lexical-worker-child.js +27 -0
  422. package/dist/workers/lexical-worker-manager.js +394 -0
  423. package/dist/workers/lexical-worker-protocol.js +2 -0
  424. package/dist/workers/lexical-worker-runtime.js +25 -0
  425. package/dist/workers/owned-one-shot-process.js +115 -0
  426. package/dist/workers/product-storage.js +23 -1
  427. package/dist/workers/registry.js +241 -1
  428. package/package.json +8 -13
  429. package/scripts/postinstall.cjs +29 -29
  430. package/scripts/provision-runtime.cjs +411 -459
  431. package/dist/client/http-client.js +0 -1
  432. package/dist/client/transport-options.js +0 -1
  433. package/dist/client/websocket-client.js +0 -1
  434. package/dist/commands/entity-resolution.js +0 -1
  435. package/dist/commands/file-command.js +0 -1
  436. package/dist/commands/host-command.js +0 -1
  437. package/dist/commands/inspect-symbol-query.js +0 -1
  438. package/dist/commands/list-instances.js +0 -1
  439. package/dist/commands/module-plan-command.js +0 -1
  440. package/dist/commands/move-command.js +0 -1
  441. package/dist/commands/move-to-file.js +0 -2
  442. package/dist/commands/ping.js +0 -1
  443. package/dist/commands/refactor-command.js +0 -1
  444. package/dist/commands/rename-command.js +0 -1
  445. package/dist/commands/runtime-command.js +0 -4
  446. package/dist/commands/runtime-info.js +0 -1
  447. package/dist/commands/validate-module-plan.js +0 -2
  448. package/dist/compatibility/policy.js +0 -1
  449. package/dist/config/auto-start-ide.js +0 -1
  450. package/dist/discovery/registry.js +0 -1
  451. package/dist/discovery/select-instance.js +0 -1
  452. package/dist/help/docs/file.rename.md +0 -35
  453. package/dist/help/docs/mutation.md +0 -60
  454. package/dist/help/docs/refactor.batch.md +0 -44
  455. package/dist/help/dsl/docs/file.rename.md +0 -35
  456. package/dist/help/dsl/docs/mutation.md +0 -60
  457. package/dist/help/dsl/docs/refactor.batch.md +0 -44
  458. package/dist/help/dsl/topics/file.rename.md +0 -33
  459. package/dist/help/dsl/topics/mutation.md +0 -58
  460. package/dist/help/dsl/topics/refactor.batch.md +0 -33
  461. package/dist/help/topics/file.rename.md +0 -33
  462. package/dist/help/topics/mutation.md +0 -58
  463. package/dist/help/topics/refactor.batch.md +0 -33
  464. package/dist/ide-launch/common.cjs +0 -162
  465. package/dist/managed-host/extension-vsix-resolver.js +0 -1
  466. package/dist/managed-host/manage-serve-web-host.cjs +0 -141
  467. package/dist/managed-host/serve-web-autostart.js +0 -1
  468. package/dist/managed-host/serve-web-host.cjs +0 -2115
  469. package/dist/runtime/managed-runtime-provisioning.js +0 -1
  470. package/dist/shared/diagnostic-catalog.js +0 -1
  471. package/dist/shared/diagnostics.js +0 -1
  472. package/dist/shared/operations.js +0 -1
  473. package/dist/shared/protocol.js +0 -1
  474. package/dist/shared/routes.js +0 -1
  475. package/extension/vscode-refactor-bridge-extension.vsix +0 -0
  476. package/runtimes/launcher/linux-x64/aib +0 -0
  477. package/runtimes/launcher/win-x64/aib.exe +0 -0
@@ -0,0 +1,919 @@
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.runStandaloneSemanticMoveBatch = runStandaloneSemanticMoveBatch;
37
+ const path = __importStar(require("node:path"));
38
+ const workspace_root_1 = require("../config/workspace-root");
39
+ const types_1 = require("../shared/types");
40
+ const import_rules_1 = require("../config/import-rules");
41
+ const mutation_comments_1 = require("../config/mutation-comments");
42
+ const module_plan_timeline_1 = require("../diagnostics/module-plan-timeline");
43
+ const semantic_move_standalone_planner_1 = require("./semantic-move-standalone-planner");
44
+ const semantic_move_transaction_1 = require("./semantic-move-transaction");
45
+ const semantic_planner_retry_1 = require("./semantic-planner-retry");
46
+ const file_mutation_discovery_1 = require("./file-mutation-discovery");
47
+ const semantic_execution_progress_1 = require("./semantic-execution-progress");
48
+ async function runStandaloneSemanticMoveBatch(cwd, builtBatch, evidence, dependencies = {
49
+ plan: semantic_move_standalone_planner_1.planStandaloneSemanticMove,
50
+ apply: semantic_move_transaction_1.applyStandaloneSemanticMoveTransaction
51
+ }, metrics, internal) {
52
+ const startedAt = Date.now();
53
+ const metricStartedAt = internal?.suppressMetricsLifecycle ? undefined : metrics?.start();
54
+ let metricPlan;
55
+ let metricEntityCount = 0;
56
+ const finish = (response) => {
57
+ if (internal?.suppressMetricsLifecycle)
58
+ return response;
59
+ if (metricStartedAt !== undefined)
60
+ metrics?.end("operation.total", metricStartedAt);
61
+ const edits = metricPlan?.edits ?? [];
62
+ metrics?.finish({
63
+ ok: response.batchOk === true,
64
+ code: readString(response.code) ?? (response.batchOk === true ? "SEMANTIC_MOVE_PLAN_COMPLETE" : "SEMANTIC_MOVE_FAILED"),
65
+ entityCount: metricEntityCount,
66
+ ownerConfigCount: metricPlan?.discovery.ownerConfigCount ?? 0,
67
+ editFileCount: edits.length,
68
+ textChangeCount: edits.reduce((sum, edit) => sum + edit.textChanges.length, 0)
69
+ });
70
+ return response;
71
+ };
72
+ const observePlan = (plan) => {
73
+ metricPlan = plan;
74
+ internal?.onPlan?.(plan);
75
+ };
76
+ const parsed = parseMoveOperations(cwd, builtBatch.payload);
77
+ metricEntityCount = parsed.operations.length;
78
+ if (!parsed.ok)
79
+ return finish(failedBatch(parsed.operations, parsed.code, parsed.error, Date.now() - startedAt));
80
+ const operations = parsed.operations;
81
+ const progressTracker = internal?.progressTracker ?? (0, semantic_execution_progress_1.createSemanticExecutionProgressTracker)(builtBatch);
82
+ if (new Set(operations.map((item) => item.execute)).size !== 1) {
83
+ return finish(failedBatch(operations, "SEMANTIC_MOVE_EXECUTION_MODE_MISMATCH", "Every semantic move row must use the same execution mode.", Date.now() - startedAt));
84
+ }
85
+ if (operations[0].execute && !evidence) {
86
+ return finish(failedBatch(operations, "SEMANTIC_MOVE_EXECUTION_EVIDENCE_REQUIRED", "Standalone semantic move refuses writes without a durable owned execution write-set.", Date.now() - startedAt));
87
+ }
88
+ const routes = groupContiguousRoutes(operations);
89
+ if (routes.length > 1) {
90
+ return finish(await runStandaloneSemanticMoveRoutes({
91
+ cwd,
92
+ builtBatch,
93
+ operations,
94
+ routes,
95
+ evidence,
96
+ dependencies,
97
+ metrics,
98
+ observePlan,
99
+ internal,
100
+ progressTracker,
101
+ startedAt
102
+ }));
103
+ }
104
+ if (new Set(operations.map((item) => pathKey(item.sourceFile))).size !== 1 ||
105
+ new Set(operations.map((item) => pathKey(item.targetFile))).size !== 1) {
106
+ return finish(failedBatch(operations, "SEMANTIC_MOVE_MULTI_ROUTE_UNSUPPORTED", "One atomic standalone semantic move batch must use one exact source and target file.", Date.now() - startedAt));
107
+ }
108
+ if (new Set(operations.map((item) => `${item.symbolName}\0${item.symbolKind ?? "*"}`)).size !== operations.length) {
109
+ return finish(failedBatch(operations, "SEMANTIC_MOVE_ENTITY_DUPLICATE", "Semantic move entity names must be unique within one atomic group.", Date.now() - startedAt));
110
+ }
111
+ if (new Set(operations.map(policySignature)).size !== 1) {
112
+ return finish(failedBatch(operations, "SEMANTIC_MOVE_POLICY_MISMATCH", "Every semantic move row in one route must use the same import/comment policy.", Date.now() - startedAt));
113
+ }
114
+ const workspaceRoot = (0, workspace_root_1.resolveWorkspaceRoot)(cwd)?.root ?? path.resolve(cwd);
115
+ const computeWorkspaceFingerprint = internal?.semanticContextPool
116
+ ? (root) => internal.semanticContextPool.withWorkspaceProjectIndex((index) => (0, file_mutation_discovery_1.computeFileMutationWorkspaceFingerprintWithProjectIndex)(index, root))
117
+ : undefined;
118
+ let cumulativeDurableWriteSet = [];
119
+ const publishBeforeApply = (writeSet) => {
120
+ cumulativeDurableWriteSet = uniqueStrings([...cumulativeDurableWriteSet, ...writeSet]);
121
+ evidence.beforeApply(cumulativeDurableWriteSet);
122
+ };
123
+ const planOperations = async (selected) => (0, semantic_planner_retry_1.runSemanticPlannerWithRetry)(() => dependencies.plan({
124
+ workspaceRoot,
125
+ sourceFile: operations[0].sourceFile,
126
+ targetFile: operations[0].targetFile,
127
+ entities: selected.map((operation) => ({
128
+ id: operation.id,
129
+ name: operation.symbolName,
130
+ ...(operation.symbolKind ? { kind: operation.symbolKind } : {})
131
+ })),
132
+ importRules: operations[0].importRules,
133
+ mutationComments: operations[0].mutationComments,
134
+ ...(internal?.semanticContextPool ? { semanticContextPool: internal.semanticContextPool } : {}),
135
+ ...(metrics ? { metrics } : {})
136
+ }));
137
+ const plan = await planOperations(operations);
138
+ observePlan(plan);
139
+ if (!plan.complete) {
140
+ if (!isBestEffortPlanningFailure(plan.code)) {
141
+ return finish(failedBatch(operations, plan.code, plan.error ?? "Standalone semantic move planning failed.", Date.now() - startedAt, plan));
142
+ }
143
+ if (plan.code === "SEMANTIC_MOVE_ENTITIES_NOT_CONTIGUOUS") {
144
+ const contiguousRoutes = buildContiguousEntityRoutes(operations, plan.contiguousEntityGroups);
145
+ if (contiguousRoutes) {
146
+ return finish(await runStandaloneSemanticMoveRoutes({
147
+ cwd,
148
+ builtBatch,
149
+ operations,
150
+ routes: contiguousRoutes,
151
+ evidence,
152
+ dependencies,
153
+ metrics,
154
+ observePlan,
155
+ internal,
156
+ progressTracker,
157
+ startedAt
158
+ }));
159
+ }
160
+ }
161
+ const rows = new Array(operations.length);
162
+ const publishFinalRows = (indexes) => {
163
+ const progress = progressTracker.finalize(indexes.flatMap((index) => {
164
+ const row = rows[index];
165
+ return row ? [{ id: operations[index].id, failed: row.ok !== true }] : [];
166
+ }));
167
+ if (progress)
168
+ evidence?.afterProgress?.(progress);
169
+ };
170
+ let pending = operations.map((_, index) => index);
171
+ const overlapAttempts = new Map();
172
+ let totalAppliedFiles = [];
173
+ let totalTouchedFiles = [];
174
+ let totalEditCount = 0;
175
+ const maxPasses = Math.max(2, operations.length + 1);
176
+ for (let pass = 0; pending.length > 0 && pass < maxPasses; pass += 1) {
177
+ const deferred = [];
178
+ let completedThisPass = 0;
179
+ for (const index of pending) {
180
+ const operation = operations[index];
181
+ const itemPlan = await planOperations([operation]);
182
+ observePlan(itemPlan);
183
+ if (itemPlan.complete) {
184
+ if (!operation.execute) {
185
+ rows[index] = completedRow(operation, previewResponse(operation, itemPlan), itemPlan.totalMs);
186
+ publishFinalRows([index]);
187
+ completedThisPass += 1;
188
+ continue;
189
+ }
190
+ const applied = dependencies.apply({
191
+ workspaceRoot,
192
+ plan: itemPlan,
193
+ beforeApply: publishBeforeApply,
194
+ ...(computeWorkspaceFingerprint ? { computeWorkspaceFingerprint } : {}),
195
+ ...(metrics ? { metrics } : {})
196
+ });
197
+ if (!applied.ok) {
198
+ rows[index] = failedRow(operation, applied.code, applied.error, overlapAttempts.get(index) ?? 0, applied.potentiallyModifiedFiles);
199
+ publishFinalRows([index]);
200
+ return finish(bestEffortBatch(operations, rows, Date.now() - startedAt, {
201
+ code: applied.code,
202
+ error: applied.error,
203
+ rollback: applied.rollback,
204
+ potentiallyModifiedFiles: applied.potentiallyModifiedFiles,
205
+ ...(applied.rollbackErrors ? { rollbackErrors: applied.rollbackErrors } : {})
206
+ }));
207
+ }
208
+ totalAppliedFiles = uniqueStrings([...totalAppliedFiles, ...applied.savedFiles]);
209
+ totalTouchedFiles = uniqueStrings([...totalTouchedFiles, ...applied.touchedFiles]);
210
+ totalEditCount += applied.editCount;
211
+ rows[index] = completedRow(operation, {
212
+ ...previewResponse(operation, itemPlan),
213
+ execute: true,
214
+ applied: true,
215
+ applyMode: "standaloneSemanticMoveTransaction",
216
+ touchedFiles: applied.touchedFiles,
217
+ savedFiles: applied.savedFiles
218
+ }, itemPlan.totalMs);
219
+ const attemptedBeforeSuccess = overlapAttempts.get(index) ?? 0;
220
+ if (attemptedBeforeSuccess > 0) {
221
+ rows[index].deferredRetry = {
222
+ attemptedBeforeSuccess,
223
+ reason: "changesOverlap",
224
+ codes: ["TS_MOVE_TO_FILE_REFACTOR_FAILED"]
225
+ };
226
+ }
227
+ publishFinalRows([index]);
228
+ completedThisPass += 1;
229
+ continue;
230
+ }
231
+ if (itemPlan.code === "SEMANTIC_MOVE_PROVIDER_UNSUPPORTED") {
232
+ rows[index] = manualExtractionRow(operation, "TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE", "providerUnsupported", itemPlan.error);
233
+ publishFinalRows([index]);
234
+ continue;
235
+ }
236
+ if (itemPlan.code === "SEMANTIC_MOVE_OWNER_DIVERGENCE") {
237
+ internal?.onDivergence?.({
238
+ operationId: operation.id,
239
+ entity: operation.entity,
240
+ sourceFile: operation.sourceFile,
241
+ targetFile: operation.targetFile,
242
+ code: "SEMANTIC_MOVE_OWNER_DIVERGENCE",
243
+ evidence: itemPlan.divergences ?? []
244
+ });
245
+ rows[index] = manualExtractionRow(operation, itemPlan.code, "manualExtractionRequired", itemPlan.error);
246
+ publishFinalRows([index]);
247
+ continue;
248
+ }
249
+ if (itemPlan.code === "SEMANTIC_MOVE_CHANGES_OVERLAP") {
250
+ overlapAttempts.set(index, (overlapAttempts.get(index) ?? 0) + 1);
251
+ (0, module_plan_timeline_1.recordModulePlanTimeline)(cwd, undefined, "moveToFile.entity.end", {
252
+ entity: operation.entity,
253
+ deferred: true,
254
+ code: "TS_MOVE_TO_FILE_REFACTOR_FAILED",
255
+ error: "Changes overlap"
256
+ });
257
+ deferred.push(index);
258
+ continue;
259
+ }
260
+ if (isDeclarationLocalPlanningFailure(itemPlan.code)) {
261
+ rows[index] = declarationFailureRow(operation, itemPlan.code, itemPlan.error ?? "Standalone semantic move planning failed.", overlapAttempts.get(index) ?? 0, itemPlan);
262
+ publishFinalRows([index]);
263
+ continue;
264
+ }
265
+ rows[index] = failedRow(operation, itemPlan.code, itemPlan.error ?? "Standalone semantic move planning failed.", overlapAttempts.get(index) ?? 0);
266
+ publishFinalRows([index]);
267
+ return finish(bestEffortBatch(operations, rows, Date.now() - startedAt, {
268
+ code: itemPlan.code,
269
+ error: itemPlan.error ?? "Standalone semantic move planning failed.",
270
+ rollback: "not-needed",
271
+ potentiallyModifiedFiles: []
272
+ }));
273
+ }
274
+ if (deferred.length === 0)
275
+ break;
276
+ if (!operations[0].execute || completedThisPass === 0) {
277
+ for (const index of deferred) {
278
+ rows[index] = manualExtractionRow(operations[index], "TS_MOVE_TO_FILE_REFACTOR_FAILED", "changesOverlapAfterDeferredRetry", "Changes overlap", overlapAttempts.get(index) ?? 1);
279
+ publishFinalRows([index]);
280
+ }
281
+ break;
282
+ }
283
+ pending = deferred;
284
+ }
285
+ for (const [index, row] of rows.entries()) {
286
+ if (!row) {
287
+ rows[index] = failedRow(operations[index], "SEMANTIC_MOVE_RETRY_BUDGET_EXHAUSTED", "Semantic move retry budget was exhausted.", overlapAttempts.get(index) ?? 0);
288
+ publishFinalRows([index]);
289
+ }
290
+ }
291
+ return finish(bestEffortBatch(operations, rows, Date.now() - startedAt, {
292
+ savedFiles: totalAppliedFiles,
293
+ touchedFiles: totalTouchedFiles,
294
+ editCount: totalEditCount,
295
+ rollback: "not-needed",
296
+ potentiallyModifiedFiles: []
297
+ }));
298
+ }
299
+ if (!operations[0].execute) {
300
+ publishCompletedOperationProgress(progressTracker, operations, evidence, false);
301
+ return finish(completedBatch(operations, plan, null, Date.now() - startedAt));
302
+ }
303
+ const applied = dependencies.apply({
304
+ workspaceRoot,
305
+ plan,
306
+ beforeApply: publishBeforeApply,
307
+ ...(computeWorkspaceFingerprint ? { computeWorkspaceFingerprint } : {}),
308
+ ...(metrics ? { metrics } : {})
309
+ });
310
+ if (!applied.ok) {
311
+ publishCompletedOperationProgress(progressTracker, operations, evidence, true);
312
+ return finish(failedBatch(operations, applied.code, applied.error, Date.now() - startedAt, plan, {
313
+ rollback: applied.rollback,
314
+ potentiallyModifiedFiles: applied.potentiallyModifiedFiles,
315
+ ...(applied.rollbackErrors ? { rollbackErrors: applied.rollbackErrors } : {})
316
+ }));
317
+ }
318
+ publishCompletedOperationProgress(progressTracker, operations, evidence, false);
319
+ return finish(completedBatch(operations, plan, applied, Date.now() - startedAt));
320
+ }
321
+ function isBestEffortPlanningFailure(code) {
322
+ return [
323
+ "SEMANTIC_MOVE_PROVIDER_UNSUPPORTED",
324
+ "SEMANTIC_MOVE_OWNER_DIVERGENCE",
325
+ "SEMANTIC_MOVE_CHANGES_OVERLAP",
326
+ "SEMANTIC_MOVE_ENTITY_NOT_FOUND",
327
+ "SEMANTIC_MOVE_ENTITY_AMBIGUOUS",
328
+ "SEMANTIC_MOVE_ENTITIES_NOT_CONTIGUOUS",
329
+ "SEMANTIC_MOVE_REQUIRED_EDGE_UNCHANGED"
330
+ ].includes(code);
331
+ }
332
+ function isDeclarationLocalPlanningFailure(code) {
333
+ return code === "SEMANTIC_MOVE_ENTITY_NOT_FOUND" ||
334
+ code === "SEMANTIC_MOVE_ENTITY_AMBIGUOUS" ||
335
+ code === "SEMANTIC_MOVE_REQUIRED_EDGE_UNCHANGED";
336
+ }
337
+ function groupContiguousRoutes(operations) {
338
+ const routes = [];
339
+ for (const operation of operations) {
340
+ const key = [pathKey(operation.sourceFile), pathKey(operation.targetFile), policySignature(operation)].join("\0");
341
+ const current = routes[routes.length - 1];
342
+ if (current?.key === key)
343
+ current.operations.push(operation);
344
+ else
345
+ routes.push({ key, operations: [operation] });
346
+ }
347
+ return routes;
348
+ }
349
+ function buildContiguousEntityRoutes(operations, groups) {
350
+ if (!groups || groups.length < 2)
351
+ return null;
352
+ const byId = new Map(operations.map((operation) => [operation.id, operation]));
353
+ const seen = new Set();
354
+ const routes = [];
355
+ for (const [index, ids] of groups.entries()) {
356
+ const selected = [];
357
+ for (const id of ids) {
358
+ const operation = byId.get(id);
359
+ if (!operation || seen.has(id))
360
+ return null;
361
+ seen.add(id);
362
+ selected.push(operation);
363
+ }
364
+ if (selected.length === 0)
365
+ return null;
366
+ routes.push({ key: `contiguous:${index}`, operations: selected });
367
+ }
368
+ return seen.size === operations.length ? routes : null;
369
+ }
370
+ async function runStandaloneSemanticMoveRoutes(input) {
371
+ const rawOperations = Array.isArray(input.builtBatch.payload.operations) ? input.builtBatch.payload.operations : [];
372
+ const rowsByIndex = new Map();
373
+ const routeEvidence = [];
374
+ let cumulativeDurableWriteSet = [];
375
+ let savedFiles = [];
376
+ let touchedFiles = [];
377
+ let potentiallyModifiedFiles = [];
378
+ let editCount = 0;
379
+ let terminal = null;
380
+ const publishBeforeApply = input.evidence ? {
381
+ beforeApply(writeSet) {
382
+ cumulativeDurableWriteSet = uniqueStrings([...cumulativeDurableWriteSet, ...writeSet]);
383
+ input.evidence.beforeApply(cumulativeDurableWriteSet);
384
+ },
385
+ afterProgress(progress) {
386
+ input.evidence.afterProgress?.(progress);
387
+ }
388
+ } : undefined;
389
+ for (const [routeIndex, route] of input.routes.entries()) {
390
+ if (terminal)
391
+ break;
392
+ const routeStartedAt = Date.now();
393
+ const subBatch = {
394
+ payload: {
395
+ ...input.builtBatch.payload,
396
+ operations: route.operations.map((operation) => rawOperations[operation.index]).filter(isObject)
397
+ },
398
+ summary: input.builtBatch.summary
399
+ };
400
+ const result = await runStandaloneSemanticMoveBatch(input.cwd, subBatch, publishBeforeApply, input.dependencies, input.metrics, {
401
+ suppressMetricsLifecycle: true,
402
+ onPlan: input.observePlan,
403
+ progressTracker: input.progressTracker,
404
+ ...(input.internal?.semanticContextPool ? { semanticContextPool: input.internal.semanticContextPool } : {}),
405
+ ...(input.internal?.onDivergence ? { onDivergence: input.internal.onDivergence } : {})
406
+ });
407
+ const resultRows = Array.isArray(result.rows) ? result.rows.filter(isObject) : [];
408
+ for (const [rowIndex, operation] of route.operations.entries()) {
409
+ const row = resultRows[rowIndex];
410
+ rowsByIndex.set(operation.index, row ? { ...row, index: operation.index + 1 } : failedRow(operation, "SEMANTIC_MOVE_ROUTE_RESULT_MISSING", "Standalone semantic move route did not return evidence for this row.", 0));
411
+ }
412
+ savedFiles = uniqueStrings([...savedFiles, ...readStrings(result.savedFiles)]);
413
+ touchedFiles = uniqueStrings([...touchedFiles, ...readStrings(result.touchedFiles)]);
414
+ potentiallyModifiedFiles = uniqueStrings([...potentiallyModifiedFiles, ...readStrings(result.potentiallyModifiedFiles)]);
415
+ editCount += typeof result.editCount === "number" ? result.editCount : 0;
416
+ const routeTerminal = resultRows.some((row) => row.ok !== true && row.outcome !== "manualExtractionRequired" && !isObject(row.declarationFailure));
417
+ const routeHasDeclarationFailures = resultRows.some((row) => isObject(row.declarationFailure));
418
+ routeEvidence.push({
419
+ index: routeIndex + 1,
420
+ sourceFile: route.operations[0].sourceFile,
421
+ targetFile: route.operations[0].targetFile,
422
+ requestedRowCount: route.operations.length,
423
+ durationMs: Date.now() - routeStartedAt,
424
+ status: routeTerminal
425
+ ? "failed"
426
+ : result.batchOk === true
427
+ ? "completed"
428
+ : routeHasDeclarationFailures
429
+ ? "completedWithErrors"
430
+ : "completedWithManualExtraction",
431
+ ...(isObject(result.planner) ? { planner: result.planner } : {}),
432
+ ...(typeof result.code === "string" ? { code: result.code } : {})
433
+ });
434
+ input.evidence?.afterRoute?.({
435
+ index: routeIndex,
436
+ sourceFile: route.operations[0].sourceFile,
437
+ targetFile: route.operations[0].targetFile,
438
+ requestedRowCount: route.operations.length,
439
+ result
440
+ });
441
+ if (routeTerminal) {
442
+ terminal = {
443
+ code: readString(result.code) ?? "SEMANTIC_MOVE_ROUTE_FAILED",
444
+ error: readString(result.error) ?? "Standalone semantic move route failed.",
445
+ rollback: readString(result.rollback) ?? "not-needed",
446
+ ...(readStrings(result.rollbackErrors).length > 0 ? { rollbackErrors: readStrings(result.rollbackErrors) } : {})
447
+ };
448
+ }
449
+ }
450
+ for (const operation of input.operations) {
451
+ if (!rowsByIndex.has(operation.index)) {
452
+ rowsByIndex.set(operation.index, notAttemptedRow(operation));
453
+ }
454
+ }
455
+ const rows = input.operations.map((operation) => rowsByIndex.get(operation.index));
456
+ const failedRows = rows.filter((row) => row.ok === false && row.skipped !== true);
457
+ const passedRows = rows.filter((row) => row.ok === true);
458
+ const manualRows = rows.filter((row) => row.outcome === "manualExtractionRequired");
459
+ const declarationFailures = rows.map((row) => row.declarationFailure).filter(isObject);
460
+ const missingEntities = collectMissingEntities(declarationFailures);
461
+ const code = terminal?.code ?? (manualRows.length > 0 ? "SEMANTIC_MOVE_MANUAL_EXTRACTION_REQUIRED" : "SEMANTIC_MOVE_PLAN_COMPLETE");
462
+ return {
463
+ ok: true,
464
+ operation: "refactorBatch",
465
+ contract: {
466
+ version: 2,
467
+ execution: "sequential-routes",
468
+ continueOnError: true,
469
+ rollback: "verified-route-transactions",
470
+ transactional: false,
471
+ rowOutcomeValues: ["applied", "validated", "manualExtractionRequired", "failed", "skipped"]
472
+ },
473
+ execution: "sequential-routes",
474
+ continueOnError: true,
475
+ batchOk: failedRows.length === 0,
476
+ batchStatus: failedRows.length === 0 ? "completed" : "completedWithErrors",
477
+ requestedOperationCount: rows.length,
478
+ plannedOperationCount: rows.length,
479
+ attemptedRowCount: rows.filter((row) => row.attempted === true).length,
480
+ rowCount: rows.length,
481
+ passedRowCount: passedRows.length,
482
+ failedRowCount: failedRows.length,
483
+ skippedRowCount: rows.filter((row) => row.skipped === true).length,
484
+ durationMs: Date.now() - input.startedAt,
485
+ code,
486
+ ...(terminal ? { error: terminal.error } : {}),
487
+ guidance: failedRows.length === 0 ? null : {
488
+ hint: terminal
489
+ ? "Fix the failed route; earlier successful routes were preserved and later routes were not attempted."
490
+ : "Use manual extraction for listed symbols; successful independent routes were preserved."
491
+ },
492
+ providerLimitations: rows
493
+ .map((row) => isObject(row.response) ? row.response.providerLimitation : null)
494
+ .filter(isObject),
495
+ rows,
496
+ routes: routeEvidence,
497
+ ...(declarationFailures.length > 0 ? { declarationFailures } : {}),
498
+ ...(missingEntities.length > 0 ? { missingEntities } : {}),
499
+ savedFiles,
500
+ touchedFiles,
501
+ editCount,
502
+ rollback: terminal?.rollback ?? "not-needed",
503
+ potentiallyModifiedFiles,
504
+ ...(terminal?.rollbackErrors ? { rollbackErrors: terminal.rollbackErrors } : {})
505
+ };
506
+ }
507
+ function publishCompletedOperationProgress(tracker, operations, evidence, failed) {
508
+ const progress = tracker.finalize(operations.map((operation) => ({ id: operation.id, failed })));
509
+ if (progress)
510
+ evidence?.afterProgress?.(progress);
511
+ }
512
+ function previewResponse(operation, plan) {
513
+ return {
514
+ ok: true,
515
+ execute: false,
516
+ applied: false,
517
+ sourceFile: operation.sourceFile,
518
+ targetFile: operation.targetFile,
519
+ symbolName: operation.entity,
520
+ operationSummary: {
521
+ operation: "moveToFile",
522
+ editCount: plan.edits.reduce((sum, edit) => sum + edit.textChanges.length, 0),
523
+ changedFiles: plan.edits.map((edit) => path.normalize(edit.fileName))
524
+ }
525
+ };
526
+ }
527
+ function manualExtractionRow(operation, code, reason, error = "Manual extraction is required.", attemptedBeforeSuccess = 0) {
528
+ const response = {
529
+ ok: false,
530
+ code,
531
+ error,
532
+ execute: operation.execute,
533
+ applied: false,
534
+ ...(code === "TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE"
535
+ ? { providerLimitation: { kind: "typescript-move-to-file-unsupported", code, retryable: false, continueTail: true } }
536
+ : {}),
537
+ touchedFiles: [],
538
+ savedFiles: []
539
+ };
540
+ return {
541
+ ...completedRow(operation, response, 0),
542
+ outcome: "manualExtractionRequired",
543
+ ...(code === "TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE"
544
+ ? { providerLimitation: { kind: "typescript-move-to-file-unsupported", code, retryable: false, continueTail: true } }
545
+ : {}),
546
+ ...(attemptedBeforeSuccess > 0
547
+ ? { deferredRetry: { attemptedBeforeSuccess, reason: "changesOverlap", codes: [code] } }
548
+ : {}),
549
+ manualExtractionRequired: [{ entity: operation.entity, code, reason, retryable: false }]
550
+ };
551
+ }
552
+ function failedRow(operation, code, error, attemptedBeforeSuccess, potentiallyModifiedFiles = []) {
553
+ return {
554
+ ...completedRow(operation, {
555
+ ok: false,
556
+ code,
557
+ error,
558
+ execute: operation.execute,
559
+ applied: false,
560
+ touchedFiles: potentiallyModifiedFiles,
561
+ savedFiles: []
562
+ }, 0),
563
+ ...(attemptedBeforeSuccess > 0
564
+ ? { deferredRetry: { attemptedBeforeSuccess, reason: "changesOverlap", codes: [code] } }
565
+ : {})
566
+ };
567
+ }
568
+ function declarationFailureRow(operation, code, error, attemptedBeforeSuccess, plan) {
569
+ const ambiguity = plan?.ambiguities?.find((item) => item.entity === operation.symbolName);
570
+ const availableSelectors = ambiguity?.kinds.map((kind) => `${operation.selectorSyntax.aliases[kind]}${operation.selectorSyntax.separator}${operation.symbolName}`) ?? [];
571
+ return {
572
+ ...failedRow(operation, code, error, attemptedBeforeSuccess),
573
+ ...(availableSelectors.length > 0 ? { availableSelectors } : {}),
574
+ declarationFailure: {
575
+ entity: operation.entity,
576
+ sourceFile: operation.sourceFile,
577
+ targetFile: operation.targetFile,
578
+ phase: "planning",
579
+ code,
580
+ error,
581
+ ...(availableSelectors.length > 0 ? { availableSelectors } : {})
582
+ }
583
+ };
584
+ }
585
+ function notAttemptedRow(operation) {
586
+ const error = "Semantic move route was not attempted after a terminal failure.";
587
+ return {
588
+ index: operation.index + 1,
589
+ id: operation.id,
590
+ kind: operation.kind,
591
+ planned: true,
592
+ attempted: false,
593
+ skipped: true,
594
+ outcome: "skipped",
595
+ ok: false,
596
+ statusCode: 424,
597
+ durationMs: 0,
598
+ responseOk: false,
599
+ applied: false,
600
+ touchedFiles: [],
601
+ savedFiles: [],
602
+ error,
603
+ response: {
604
+ ok: false,
605
+ code: "SEMANTIC_MOVE_NOT_ATTEMPTED",
606
+ error,
607
+ execute: operation.execute,
608
+ applied: false,
609
+ touchedFiles: [],
610
+ savedFiles: []
611
+ }
612
+ };
613
+ }
614
+ function bestEffortBatch(operations, rawRows, durationMs, extra) {
615
+ const rows = rawRows.map((row, index) => row ?? failedRow(operations[index], "SEMANTIC_MOVE_NOT_ATTEMPTED", "Semantic move was not attempted after a terminal failure.", 0));
616
+ const failedRows = rows.filter((row) => row.ok === false);
617
+ const passedRows = rows.filter((row) => row.ok === true);
618
+ const providerLimitations = rows
619
+ .map((row) => isObject(row.response) ? row.response.providerLimitation : null)
620
+ .filter(isObject);
621
+ const declarationFailures = rows
622
+ .map((row) => row.declarationFailure)
623
+ .filter(isObject);
624
+ const missingEntities = collectMissingEntities(declarationFailures);
625
+ const batchOk = failedRows.length === 0;
626
+ const manualOnly = failedRows.length > 0 && failedRows.every((row) => row.outcome === "manualExtractionRequired");
627
+ const fallbackCode = manualOnly ? "SEMANTIC_MOVE_MANUAL_EXTRACTION_REQUIRED" : "SEMANTIC_MOVE_FAILED";
628
+ return {
629
+ ok: true,
630
+ operation: "refactorBatch",
631
+ contract: {
632
+ version: 2,
633
+ execution: "sequential-subgroups",
634
+ continueOnError: true,
635
+ rollback: "verified-subgroup-transactions",
636
+ transactional: false,
637
+ rowOutcomeValues: ["applied", "validated", "manualExtractionRequired", "failed"]
638
+ },
639
+ execution: "sequential-subgroups",
640
+ continueOnError: true,
641
+ batchOk,
642
+ batchStatus: batchOk ? "completed" : "completedWithErrors",
643
+ requestedOperationCount: rows.length,
644
+ plannedOperationCount: rows.length,
645
+ attemptedRowCount: rows.length,
646
+ rowCount: rows.length,
647
+ passedRowCount: passedRows.length,
648
+ failedRowCount: failedRows.length,
649
+ skippedRowCount: 0,
650
+ durationMs,
651
+ guidance: batchOk ? null : { hint: "Use manual extraction for listed symbols; successful independent moves were preserved." },
652
+ providerLimitations,
653
+ ...(declarationFailures.length > 0 ? { declarationFailures } : {}),
654
+ ...(missingEntities.length > 0 ? { missingEntities } : {}),
655
+ rows,
656
+ ...extra,
657
+ ...(!batchOk && typeof extra.code !== "string" ? { code: fallbackCode } : {})
658
+ };
659
+ }
660
+ function uniqueStrings(values) {
661
+ return [...new Set(values.map((value) => path.normalize(value)))];
662
+ }
663
+ function collectMissingEntities(failures) {
664
+ return failures.flatMap((failure) => {
665
+ if (failure.code !== "SEMANTIC_MOVE_ENTITY_NOT_FOUND")
666
+ return [];
667
+ const entity = readString(failure.entity);
668
+ const sourceFile = readString(failure.sourceFile);
669
+ const targetFile = readString(failure.targetFile);
670
+ return entity && sourceFile && targetFile ? [{ entity, sourceFile, targetFile }] : [];
671
+ });
672
+ }
673
+ function parseMoveOperations(cwd, payload) {
674
+ const rawOperations = Array.isArray(payload.operations) ? payload.operations : [];
675
+ const operations = [];
676
+ const workspaceRoot = (0, workspace_root_1.resolveWorkspaceRoot)(cwd)?.root ?? path.resolve(cwd);
677
+ const selectorSyntax = readSelectorSyntax(payload);
678
+ for (const [index, raw] of rawOperations.entries()) {
679
+ if (!isObject(raw) || raw.kind !== "moveRefactor" || !isObject(raw.body)) {
680
+ return {
681
+ ok: false,
682
+ operations: fallbackOperations(cwd, payload),
683
+ code: "SEMANTIC_MOVE_BATCH_MIXED_UNSUPPORTED",
684
+ error: "A batch containing semantic move cannot include IDE-owned semantic operations."
685
+ };
686
+ }
687
+ const id = readString(raw.id);
688
+ const sourceFile = readString(raw.body.sourceFile);
689
+ const targetFile = readString(raw.body.targetFile);
690
+ const symbolName = readString(raw.body.symbolName);
691
+ const symbolKind = readEntityKind(raw.body.symbolKind);
692
+ const entity = readString(raw.body.selector) ?? symbolName;
693
+ const invalidKind = raw.body.symbolKind !== null && raw.body.symbolKind !== undefined && !symbolKind;
694
+ if (!id || !sourceFile || !targetFile || !entity || !symbolName || invalidKind || readString(raw.body.parentName)) {
695
+ return {
696
+ ok: false,
697
+ operations: fallbackOperations(cwd, payload),
698
+ code: "SEMANTIC_MOVE_ROW_UNSUPPORTED",
699
+ error: "Standalone semantic move requires top-level symbolName/sourceFile/targetFile rows."
700
+ };
701
+ }
702
+ let importRules;
703
+ let mutationComments;
704
+ try {
705
+ importRules = (0, import_rules_1.normalizeImportRules)(workspaceRoot, raw.body.importRules);
706
+ mutationComments = (0, mutation_comments_1.normalizeMutationCommentsPolicy)(raw.body.mutationComments);
707
+ }
708
+ catch (error) {
709
+ return {
710
+ ok: false,
711
+ operations: fallbackOperations(cwd, payload),
712
+ code: "SEMANTIC_MOVE_POLICY_INVALID",
713
+ error: error instanceof Error ? error.message : String(error)
714
+ };
715
+ }
716
+ operations.push({
717
+ index,
718
+ id,
719
+ kind: "moveRefactor",
720
+ sourceFile: resolveInputPath(cwd, sourceFile),
721
+ targetFile: resolveInputPath(cwd, targetFile),
722
+ entity,
723
+ symbolName,
724
+ symbolKind,
725
+ selectorSyntax,
726
+ importRules,
727
+ mutationComments,
728
+ execute: raw.body.execute === true
729
+ });
730
+ }
731
+ if (operations.length === 0) {
732
+ return { ok: false, operations, code: "SEMANTIC_MOVE_ROWS_REQUIRED", error: "Standalone semantic move expects at least one move row." };
733
+ }
734
+ return { ok: true, operations };
735
+ }
736
+ function fallbackOperations(cwd, payload) {
737
+ const rawOperations = Array.isArray(payload.operations) ? payload.operations : [];
738
+ const workspaceRoot = (0, workspace_root_1.resolveWorkspaceRoot)(cwd)?.root ?? path.resolve(cwd);
739
+ const selectorSyntax = readSelectorSyntax(payload);
740
+ return rawOperations.map((raw, index) => {
741
+ const operation = isObject(raw) ? raw : {};
742
+ const body = isObject(operation.body) ? operation.body : {};
743
+ return {
744
+ index,
745
+ id: readString(operation.id) ?? `row-${index + 1}`,
746
+ kind: readString(operation.kind) ?? "operation",
747
+ sourceFile: resolveInputPath(cwd, readString(body.sourceFile) ?? cwd),
748
+ targetFile: resolveInputPath(cwd, readString(body.targetFile) ?? cwd),
749
+ entity: readString(body.symbolName) ?? "",
750
+ symbolName: readString(body.symbolName) ?? "",
751
+ symbolKind: readEntityKind(body.symbolKind),
752
+ selectorSyntax,
753
+ importRules: safeImportRules(workspaceRoot, body.importRules),
754
+ mutationComments: safeMutationComments(body.mutationComments),
755
+ execute: body.execute === true
756
+ };
757
+ });
758
+ }
759
+ function readSelectorSyntax(payload) {
760
+ const syntax = isObject(payload.selectorSyntax) ? payload.selectorSyntax : {};
761
+ const rawAliases = isObject(syntax.entityKindAliases) ? syntax.entityKindAliases : {};
762
+ const aliases = Object.fromEntries(types_1.ENTITY_KIND_IDS.map((kind) => [kind, readString(rawAliases[kind]) ?? kind]));
763
+ return {
764
+ separator: readString(syntax.separator) ?? "-",
765
+ aliases
766
+ };
767
+ }
768
+ function completedBatch(operations, plan, applied, durationMs) {
769
+ const execute = operations[0].execute;
770
+ const plannedFiles = plan.edits.map((edit) => path.normalize(edit.fileName));
771
+ const rows = operations.map((operation) => completedRow(operation, {
772
+ ok: true,
773
+ execute,
774
+ applied: execute,
775
+ sourceFile: operation.sourceFile,
776
+ targetFile: operation.targetFile,
777
+ symbolName: operation.entity,
778
+ operationSummary: {
779
+ operation: "moveToFile",
780
+ editCount: plan.edits.reduce((sum, edit) => sum + edit.textChanges.length, 0),
781
+ changedFiles: plannedFiles
782
+ },
783
+ ...(execute ? {
784
+ applyMode: "standaloneSemanticMoveTransaction",
785
+ touchedFiles: applied?.touchedFiles ?? plannedFiles,
786
+ savedFiles: applied?.savedFiles ?? plannedFiles
787
+ } : {})
788
+ }, durationMs / operations.length));
789
+ return batchEnvelope(rows, true, durationMs, {
790
+ code: "SEMANTIC_MOVE_PLAN_COMPLETE",
791
+ rollback: "not-needed",
792
+ potentiallyModifiedFiles: [],
793
+ planner: plannerEvidence(plan),
794
+ ...(applied ? { savedFiles: applied.savedFiles, touchedFiles: applied.touchedFiles, editCount: applied.editCount } : {})
795
+ });
796
+ }
797
+ function failedBatch(operations, code, error, durationMs, plan, evidence = {}) {
798
+ const potentiallyModifiedFiles = readStrings(evidence.potentiallyModifiedFiles);
799
+ const rows = operations.map((operation) => completedRow(operation, {
800
+ ok: false,
801
+ code,
802
+ error,
803
+ execute: operation.execute,
804
+ applied: false,
805
+ touchedFiles: potentiallyModifiedFiles,
806
+ savedFiles: []
807
+ }, operations.length > 0 ? durationMs / operations.length : durationMs));
808
+ return batchEnvelope(rows, false, durationMs, {
809
+ code,
810
+ error,
811
+ rollback: readString(evidence.rollback) ?? "not-needed",
812
+ potentiallyModifiedFiles,
813
+ ...(Array.isArray(evidence.rollbackErrors) ? { rollbackErrors: evidence.rollbackErrors } : {}),
814
+ ...(plan ? { planner: plannerEvidence(plan) } : {})
815
+ });
816
+ }
817
+ function completedRow(operation, response, durationMs) {
818
+ const ok = response.ok === true && (response.execute !== true || response.applied === true);
819
+ return {
820
+ index: operation.index + 1,
821
+ id: operation.id,
822
+ kind: operation.kind,
823
+ planned: true,
824
+ attempted: true,
825
+ outcome: ok ? (response.applied === true ? "applied" : "validated") : "failed",
826
+ ok,
827
+ statusCode: ok ? 200 : 400,
828
+ durationMs,
829
+ responseOk: ok,
830
+ applied: response.applied === true,
831
+ touchedFiles: readStrings(response.touchedFiles),
832
+ savedFiles: readStrings(response.savedFiles),
833
+ ...(typeof response.error === "string" ? { error: response.error } : {}),
834
+ response
835
+ };
836
+ }
837
+ function batchEnvelope(rows, ok, durationMs, extra) {
838
+ return {
839
+ ok: true,
840
+ operation: "refactorBatch",
841
+ contract: {
842
+ version: 2,
843
+ execution: "atomic",
844
+ continueOnError: false,
845
+ rollback: "verified-semantic-move-transaction",
846
+ transactional: true,
847
+ rowOutcomeValues: ["applied", "validated", "failed"]
848
+ },
849
+ execution: "atomic",
850
+ continueOnError: false,
851
+ batchOk: ok,
852
+ batchStatus: ok ? "completed" : "completedWithErrors",
853
+ requestedOperationCount: rows.length,
854
+ plannedOperationCount: rows.length,
855
+ attemptedRowCount: rows.length,
856
+ rowCount: rows.length,
857
+ passedRowCount: ok ? rows.length : 0,
858
+ failedRowCount: ok ? 0 : rows.length,
859
+ skippedRowCount: 0,
860
+ durationMs,
861
+ guidance: ok ? null : { hint: "Fix the standalone semantic move failure and rerun the complete group." },
862
+ providerLimitations: [],
863
+ rows,
864
+ ...extra
865
+ };
866
+ }
867
+ function plannerEvidence(plan) {
868
+ return {
869
+ code: plan.code,
870
+ sourceFile: plan.sourceFile,
871
+ targetFile: plan.targetFile,
872
+ workspaceRoot: plan.workspaceRoot,
873
+ snapshotHash: plan.snapshotHash,
874
+ planHash: plan.planHash,
875
+ totalMs: plan.totalMs,
876
+ discovery: plan.discovery,
877
+ configWorkers: plan.configWorkers
878
+ };
879
+ }
880
+ function resolveInputPath(cwd, value) {
881
+ return path.isAbsolute(value) ? path.resolve(value) : path.resolve(cwd, value);
882
+ }
883
+ function readString(value) {
884
+ return typeof value === "string" && value.length > 0 ? value : null;
885
+ }
886
+ function readEntityKind(value) {
887
+ return typeof value === "string" && types_1.ENTITY_KIND_IDS.includes(value)
888
+ ? value
889
+ : null;
890
+ }
891
+ function safeImportRules(workspaceRoot, value) {
892
+ try {
893
+ return (0, import_rules_1.normalizeImportRules)(workspaceRoot, value);
894
+ }
895
+ catch {
896
+ return [];
897
+ }
898
+ }
899
+ function safeMutationComments(value) {
900
+ try {
901
+ return (0, mutation_comments_1.normalizeMutationCommentsPolicy)(value);
902
+ }
903
+ catch {
904
+ return (0, mutation_comments_1.normalizeMutationCommentsPolicy)(undefined);
905
+ }
906
+ }
907
+ function policySignature(operation) {
908
+ return JSON.stringify({ importRules: operation.importRules, mutationComments: operation.mutationComments });
909
+ }
910
+ function readStrings(value) {
911
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
912
+ }
913
+ function isObject(value) {
914
+ return value !== null && typeof value === "object" && !Array.isArray(value);
915
+ }
916
+ function pathKey(value) {
917
+ const resolved = path.resolve(value);
918
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
919
+ }