@lesliechan721/aw 0.1.0-beta.10 → 0.1.0-beta.101

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 (864) hide show
  1. package/dist/authoring/assets/aw-config.d.mts +1 -50
  2. package/dist/authoring/assets/aw-config.mjs +58 -928
  3. package/dist/authoring/assets/aw-config.mjs.map +1 -1
  4. package/dist/authoring/assets/aw-runtime-config.d.mts +13 -0
  5. package/dist/authoring/assets/aw-runtime-config.mjs +221 -0
  6. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -0
  7. package/dist/authoring/assets/command-runtime-config.d.mts +9 -0
  8. package/dist/authoring/assets/command-runtime-config.mjs +134 -0
  9. package/dist/authoring/assets/command-runtime-config.mjs.map +1 -0
  10. package/dist/authoring/scripts/add-skill.mjs +16 -39
  11. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  12. package/dist/authoring/scripts/init-plugin.mjs +43 -71
  13. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  14. package/dist/authoring/scripts/lib/plugin-root.mjs +4 -4
  15. package/dist/authoring/scripts/lib/plugin-root.mjs.map +1 -1
  16. package/dist/authoring/scripts/lib/plugin-version-check.d.mts +1 -0
  17. package/dist/authoring/scripts/lib/plugin-version-check.mjs +230 -9
  18. package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
  19. package/dist/authoring/scripts/lib/skill-scaffold.d.mts +3 -3
  20. package/dist/authoring/scripts/lib/skill-scaffold.mjs +5 -8
  21. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  22. package/dist/authoring/scripts/remove-plugin.mjs +1 -1
  23. package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
  24. package/dist/authoring/scripts/validate-plugin.mjs +408 -1748
  25. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  26. package/dist/authoring/scripts/validate-skill.mjs +1 -1
  27. package/dist/index.js +2 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/native-runtime/reader-runtime.mjs +34 -0
  30. package/dist/native-runtime/reader.d.mts +6 -0
  31. package/dist/native-runtime/reader.mjs +11 -0
  32. package/dist/scripts/aw-skill-eval-materializer.d.ts +11 -1
  33. package/dist/scripts/aw-skill-eval-materializer.js +119 -114
  34. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
  35. package/dist/scripts/bundle-plugins.js +32 -7
  36. package/dist/scripts/bundle-plugins.js.map +1 -1
  37. package/dist/scripts/plugin-staging.d.ts +1 -1
  38. package/dist/scripts/plugin-staging.js +5 -2
  39. package/dist/scripts/plugin-staging.js.map +1 -1
  40. package/dist/scripts/plugin-test-context-guard.d.mts +1 -0
  41. package/dist/scripts/plugin-test-context-guard.mjs +59 -0
  42. package/dist/scripts/plugin-test-context-guard.mjs.map +1 -0
  43. package/dist/scripts/plugin-test-reporter.d.mts +2 -0
  44. package/dist/scripts/plugin-test-reporter.mjs +21 -0
  45. package/dist/scripts/plugin-test-reporter.mjs.map +1 -0
  46. package/dist/scripts/test-plugin-scripts.d.ts +5 -0
  47. package/dist/scripts/test-plugin-scripts.js +343 -58
  48. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  49. package/dist/scripts/test-workers.d.mts +24 -0
  50. package/dist/scripts/test-workers.mjs +59 -0
  51. package/dist/scripts/test-workers.mjs.map +1 -0
  52. package/dist/src/adapters/helpers.d.ts +7 -0
  53. package/dist/src/adapters/helpers.js.map +1 -1
  54. package/dist/src/authoring/workspace-commands.d.ts +3 -0
  55. package/dist/src/authoring/workspace-commands.js +7 -2
  56. package/dist/src/authoring/workspace-commands.js.map +1 -1
  57. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  58. package/dist/src/commands/aw-capabilities.js +48 -19
  59. package/dist/src/commands/aw-capabilities.js.map +1 -1
  60. package/dist/src/commands/catalog-dev-source.d.ts +40 -3
  61. package/dist/src/commands/catalog-dev-source.js +333 -42
  62. package/dist/src/commands/catalog-dev-source.js.map +1 -1
  63. package/dist/src/commands/catalog-generation.d.ts +5 -0
  64. package/dist/src/commands/catalog-generation.js.map +1 -1
  65. package/dist/src/commands/catalog-publication-inspection.d.ts +11 -3
  66. package/dist/src/commands/catalog-publication-inspection.js +211 -59
  67. package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
  68. package/dist/src/commands/catalog-publication-journal.d.ts +12 -0
  69. package/dist/src/commands/catalog-publication-journal.js +78 -1
  70. package/dist/src/commands/catalog-publication-journal.js.map +1 -1
  71. package/dist/src/commands/catalog-publish.d.ts +21 -1
  72. package/dist/src/commands/catalog-publish.js +133 -92
  73. package/dist/src/commands/catalog-publish.js.map +1 -1
  74. package/dist/src/commands/catalog-source.d.ts +26 -5
  75. package/dist/src/commands/catalog-source.js +154 -27
  76. package/dist/src/commands/catalog-source.js.map +1 -1
  77. package/dist/src/commands/catalog-status.js +2 -2
  78. package/dist/src/commands/catalog-status.js.map +1 -1
  79. package/dist/src/commands/catalog-store.d.ts +35 -7
  80. package/dist/src/commands/catalog-store.js +469 -79
  81. package/dist/src/commands/catalog-store.js.map +1 -1
  82. package/dist/src/commands/catalog-workspace-resolution.d.ts +4 -0
  83. package/dist/src/commands/catalog-workspace-resolution.js +18 -3
  84. package/dist/src/commands/catalog-workspace-resolution.js.map +1 -1
  85. package/dist/src/commands/console.js +33 -20
  86. package/dist/src/commands/console.js.map +1 -1
  87. package/dist/src/commands/dependency-operation-plan.d.ts +7 -0
  88. package/dist/src/commands/dependency-operation-plan.js +66 -30
  89. package/dist/src/commands/dependency-operation-plan.js.map +1 -1
  90. package/dist/src/commands/deployment-confirmation.d.ts +11 -0
  91. package/dist/src/commands/deployment-confirmation.js +101 -0
  92. package/dist/src/commands/deployment-confirmation.js.map +1 -0
  93. package/dist/src/commands/init.js +1 -1
  94. package/dist/src/commands/init.js.map +1 -1
  95. package/dist/src/commands/intent-command.d.ts +35 -0
  96. package/dist/src/commands/intent-command.js +174 -0
  97. package/dist/src/commands/intent-command.js.map +1 -0
  98. package/dist/src/commands/lifecycle-command-package.d.ts +45 -0
  99. package/dist/src/commands/lifecycle-command-package.js +199 -0
  100. package/dist/src/commands/lifecycle-command-package.js.map +1 -0
  101. package/dist/src/commands/managed-commands.d.ts +41 -0
  102. package/dist/src/commands/managed-commands.js +408 -0
  103. package/dist/src/commands/managed-commands.js.map +1 -0
  104. package/dist/src/commands/offline-cleanup-evidence.d.ts +12 -2
  105. package/dist/src/commands/offline-cleanup-evidence.js +57 -35
  106. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
  107. package/dist/src/commands/operation-plan.d.ts +72 -2
  108. package/dist/src/commands/operation-plan.js +54 -3
  109. package/dist/src/commands/operation-plan.js.map +1 -1
  110. package/dist/src/commands/operation-planner.d.ts +6 -5
  111. package/dist/src/commands/operation-planner.js +23 -20
  112. package/dist/src/commands/operation-planner.js.map +1 -1
  113. package/dist/src/commands/options.d.ts +11 -16
  114. package/dist/src/commands/options.js +31 -25
  115. package/dist/src/commands/options.js.map +1 -1
  116. package/dist/src/commands/permission-batch.d.ts +5 -0
  117. package/dist/src/commands/permission-batch.js +83 -0
  118. package/dist/src/commands/permission-batch.js.map +1 -0
  119. package/dist/src/commands/plugin-capabilities.js +128 -58
  120. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  121. package/dist/src/commands/public-config-confirmation.d.ts +14 -0
  122. package/dist/src/commands/public-config-confirmation.js +73 -0
  123. package/dist/src/commands/public-config-confirmation.js.map +1 -0
  124. package/dist/src/commands/public-interruption.d.ts +9 -0
  125. package/dist/src/commands/public-interruption.js +23 -0
  126. package/dist/src/commands/public-interruption.js.map +1 -0
  127. package/dist/src/commands/public-lifecycle-result.d.ts +107 -0
  128. package/dist/src/commands/public-lifecycle-result.js +536 -0
  129. package/dist/src/commands/public-lifecycle-result.js.map +1 -0
  130. package/dist/src/commands/public-lifecycle.d.ts +28 -0
  131. package/dist/src/commands/public-lifecycle.js +633 -0
  132. package/dist/src/commands/public-lifecycle.js.map +1 -0
  133. package/dist/src/commands/public-plugin-query.d.ts +16 -0
  134. package/dist/src/commands/public-plugin-query.js +235 -0
  135. package/dist/src/commands/public-plugin-query.js.map +1 -0
  136. package/dist/src/commands/rebuild-command.d.ts +177 -16
  137. package/dist/src/commands/rebuild-command.js +3374 -1558
  138. package/dist/src/commands/rebuild-command.js.map +1 -1
  139. package/dist/src/commands/rebuild-integration.d.ts +100 -55
  140. package/dist/src/commands/rebuild-integration.js +866 -3275
  141. package/dist/src/commands/rebuild-integration.js.map +1 -1
  142. package/dist/src/commands/rebuild-operations.d.ts +68 -13
  143. package/dist/src/commands/rebuild-operations.js +309 -120
  144. package/dist/src/commands/rebuild-operations.js.map +1 -1
  145. package/dist/src/commands/rebuild-platform-integration.d.ts +99 -0
  146. package/dist/src/commands/rebuild-platform-integration.js +2329 -0
  147. package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
  148. package/dist/src/commands/reconcile-operation-plan.d.ts +14 -9
  149. package/dist/src/commands/reconcile-operation-plan.js +26 -6
  150. package/dist/src/commands/reconcile-operation-plan.js.map +1 -1
  151. package/dist/src/commands/review-inspection.d.ts +60 -0
  152. package/dist/src/commands/review-inspection.js +437 -0
  153. package/dist/src/commands/review-inspection.js.map +1 -0
  154. package/dist/src/commands/review-preparation.d.ts +51 -0
  155. package/dist/src/commands/review-preparation.js +400 -0
  156. package/dist/src/commands/review-preparation.js.map +1 -0
  157. package/dist/src/commands/runtime.d.ts +7 -1
  158. package/dist/src/commands/runtime.js +41 -8
  159. package/dist/src/commands/runtime.js.map +1 -1
  160. package/dist/src/commands/skill-eval.d.ts +8 -0
  161. package/dist/src/commands/skill-eval.js +126 -73
  162. package/dist/src/commands/skill-eval.js.map +1 -1
  163. package/dist/src/commands/status-v6.d.ts +148 -35
  164. package/dist/src/commands/status-v6.js +1166 -307
  165. package/dist/src/commands/status-v6.js.map +1 -1
  166. package/dist/src/commands/targets-command.d.ts +38 -0
  167. package/dist/src/commands/targets-command.js +210 -0
  168. package/dist/src/commands/targets-command.js.map +1 -0
  169. package/dist/src/commands/wizard.d.ts +7 -3
  170. package/dist/src/commands/wizard.js +7 -4
  171. package/dist/src/commands/wizard.js.map +1 -1
  172. package/dist/src/commands/write-commands.d.ts +7 -1
  173. package/dist/src/commands/write-commands.js +129 -38
  174. package/dist/src/commands/write-commands.js.map +1 -1
  175. package/dist/src/constants.d.ts +2 -3
  176. package/dist/src/constants.js +2 -3
  177. package/dist/src/constants.js.map +1 -1
  178. package/dist/src/eval/manifest-v1.d.ts +6 -3
  179. package/dist/src/eval/manifest-v1.js +44 -33
  180. package/dist/src/eval/manifest-v1.js.map +1 -1
  181. package/dist/src/generators/local-plugin.d.ts +4 -2
  182. package/dist/src/generators/local-plugin.js +319 -353
  183. package/dist/src/generators/local-plugin.js.map +1 -1
  184. package/dist/src/generators/permissions.d.ts +20 -2
  185. package/dist/src/generators/permissions.js +82 -15
  186. package/dist/src/generators/permissions.js.map +1 -1
  187. package/dist/src/index.d.ts +3 -34
  188. package/dist/src/index.js +1711 -1935
  189. package/dist/src/index.js.map +1 -1
  190. package/dist/src/intent/deployment-preferences.d.ts +63 -0
  191. package/dist/src/intent/deployment-preferences.js +170 -0
  192. package/dist/src/intent/deployment-preferences.js.map +1 -0
  193. package/dist/src/intent/diagnostics.d.ts +11 -0
  194. package/dist/src/intent/diagnostics.js +14 -0
  195. package/dist/src/intent/diagnostics.js.map +1 -0
  196. package/dist/src/intent/intent-codec.d.ts +19 -0
  197. package/dist/src/intent/intent-codec.js +117 -0
  198. package/dist/src/intent/intent-codec.js.map +1 -0
  199. package/dist/src/intent/intent-store.d.ts +43 -0
  200. package/dist/src/intent/intent-store.js +118 -0
  201. package/dist/src/intent/intent-store.js.map +1 -0
  202. package/dist/src/intent/scope-context.d.ts +35 -0
  203. package/dist/src/intent/scope-context.js +179 -0
  204. package/dist/src/intent/scope-context.js.map +1 -0
  205. package/dist/src/intent/work-context.d.ts +13 -0
  206. package/dist/src/intent/work-context.js +22 -0
  207. package/dist/src/intent/work-context.js.map +1 -0
  208. package/dist/src/output/cli-progress.d.ts +30 -0
  209. package/dist/src/output/cli-progress.js +424 -0
  210. package/dist/src/output/cli-progress.js.map +1 -0
  211. package/dist/src/output/command-receipt.d.ts +6 -2
  212. package/dist/src/output/command-receipt.js +67 -32
  213. package/dist/src/output/command-receipt.js.map +1 -1
  214. package/dist/src/output/component-delivery.d.ts +28 -0
  215. package/dist/src/output/component-delivery.js +141 -0
  216. package/dist/src/output/component-delivery.js.map +1 -0
  217. package/dist/src/output/model.d.ts +123 -1
  218. package/dist/src/output/model.js +45 -1
  219. package/dist/src/output/model.js.map +1 -1
  220. package/dist/src/output/public-command-ids.d.ts +8 -0
  221. package/dist/src/output/public-command-ids.js +38 -0
  222. package/dist/src/output/public-command-ids.js.map +1 -0
  223. package/dist/src/output/public-result.d.ts +71 -0
  224. package/dist/src/output/public-result.js +40 -0
  225. package/dist/src/output/public-result.js.map +1 -0
  226. package/dist/src/output/rebuild-progress.d.ts +3 -0
  227. package/dist/src/output/rebuild-progress.js +34 -9
  228. package/dist/src/output/rebuild-progress.js.map +1 -1
  229. package/dist/src/output/receipt-projection.d.ts +7 -0
  230. package/dist/src/output/receipt-projection.js +670 -0
  231. package/dist/src/output/receipt-projection.js.map +1 -0
  232. package/dist/src/output/render/document.d.ts +55 -0
  233. package/dist/src/output/render/document.js +176 -0
  234. package/dist/src/output/render/document.js.map +1 -0
  235. package/dist/src/output/render/shared.d.ts +18 -0
  236. package/dist/src/output/render/shared.js +245 -0
  237. package/dist/src/output/render/shared.js.map +1 -0
  238. package/dist/src/output/render/style.d.ts +45 -0
  239. package/dist/src/output/render/style.js +155 -0
  240. package/dist/src/output/render/style.js.map +1 -0
  241. package/dist/src/output/render/views/commands-self.d.ts +6 -0
  242. package/dist/src/output/render/views/commands-self.js +210 -0
  243. package/dist/src/output/render/views/commands-self.js.map +1 -0
  244. package/dist/src/output/render/views/config.d.ts +2 -0
  245. package/dist/src/output/render/views/config.js +203 -0
  246. package/dist/src/output/render/views/config.js.map +1 -0
  247. package/dist/src/output/render/views/dev.d.ts +2 -0
  248. package/dist/src/output/render/views/dev.js +278 -0
  249. package/dist/src/output/render/views/dev.js.map +1 -0
  250. package/dist/src/output/render/views/fallback.d.ts +2 -0
  251. package/dist/src/output/render/views/fallback.js +6 -0
  252. package/dist/src/output/render/views/fallback.js.map +1 -0
  253. package/dist/src/output/render/views/index.d.ts +3 -0
  254. package/dist/src/output/render/views/index.js +79 -0
  255. package/dist/src/output/render/views/index.js.map +1 -0
  256. package/dist/src/output/render/views/lifecycle.d.ts +5 -0
  257. package/dist/src/output/render/views/lifecycle.js +170 -0
  258. package/dist/src/output/render/views/lifecycle.js.map +1 -0
  259. package/dist/src/output/render/views/sources-cache.d.ts +3 -0
  260. package/dist/src/output/render/views/sources-cache.js +322 -0
  261. package/dist/src/output/render/views/sources-cache.js.map +1 -0
  262. package/dist/src/output/render/views/targets.d.ts +2 -0
  263. package/dist/src/output/render/views/targets.js +82 -0
  264. package/dist/src/output/render/views/targets.js.map +1 -0
  265. package/dist/src/output/skill-invocation-notices.d.ts +18 -0
  266. package/dist/src/output/skill-invocation-notices.js +84 -0
  267. package/dist/src/output/skill-invocation-notices.js.map +1 -0
  268. package/dist/src/platforms/antigravity-permissions.d.ts +50 -0
  269. package/dist/src/platforms/antigravity-permissions.js +388 -0
  270. package/dist/src/platforms/antigravity-permissions.js.map +1 -0
  271. package/dist/src/platforms/capabilities.d.ts +9 -0
  272. package/dist/src/platforms/capabilities.js +125 -0
  273. package/dist/src/platforms/capabilities.js.map +1 -0
  274. package/dist/src/platforms/contracts.d.ts +394 -0
  275. package/dist/src/platforms/contracts.js +2 -0
  276. package/dist/src/platforms/contracts.js.map +1 -0
  277. package/dist/src/platforms/cursor-workspace-hook.d.ts +28 -0
  278. package/dist/src/platforms/cursor-workspace-hook.js +198 -0
  279. package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
  280. package/dist/src/platforms/discovery.d.ts +100 -0
  281. package/dist/src/platforms/discovery.js +796 -0
  282. package/dist/src/platforms/discovery.js.map +1 -0
  283. package/dist/src/platforms/grok-permission-config.d.ts +23 -0
  284. package/dist/src/platforms/grok-permission-config.js +184 -0
  285. package/dist/src/platforms/grok-permission-config.js.map +1 -0
  286. package/dist/src/platforms/grok-permission-document.d.ts +4 -0
  287. package/dist/src/platforms/grok-permission-document.js +145 -0
  288. package/dist/src/platforms/grok-permission-document.js.map +1 -0
  289. package/dist/src/platforms/grok-permissions.d.ts +17 -0
  290. package/dist/src/platforms/grok-permissions.js +311 -0
  291. package/dist/src/platforms/grok-permissions.js.map +1 -0
  292. package/dist/src/platforms/host-permission-policy.d.ts +38 -0
  293. package/dist/src/platforms/host-permission-policy.js +86 -0
  294. package/dist/src/platforms/host-permission-policy.js.map +1 -0
  295. package/dist/src/platforms/identity.d.ts +4 -0
  296. package/dist/src/platforms/identity.js +22 -0
  297. package/dist/src/platforms/identity.js.map +1 -0
  298. package/dist/src/platforms/inspection-grok.d.ts +4 -0
  299. package/dist/src/platforms/inspection-grok.js +380 -0
  300. package/dist/src/platforms/inspection-grok.js.map +1 -0
  301. package/dist/src/platforms/inspection-native.d.ts +8 -0
  302. package/dist/src/platforms/inspection-native.js +584 -0
  303. package/dist/src/platforms/inspection-native.js.map +1 -0
  304. package/dist/src/platforms/inspection-opencode.d.ts +4 -0
  305. package/dist/src/platforms/inspection-opencode.js +98 -0
  306. package/dist/src/platforms/inspection-opencode.js.map +1 -0
  307. package/dist/src/platforms/inspection-pi.d.ts +9 -0
  308. package/dist/src/platforms/inspection-pi.js +490 -0
  309. package/dist/src/platforms/inspection-pi.js.map +1 -0
  310. package/dist/src/platforms/inspection-query.d.ts +26 -0
  311. package/dist/src/platforms/inspection-query.js +118 -0
  312. package/dist/src/platforms/inspection-query.js.map +1 -0
  313. package/dist/src/platforms/inspection.d.ts +20 -0
  314. package/dist/src/platforms/inspection.js +259 -0
  315. package/dist/src/platforms/inspection.js.map +1 -0
  316. package/dist/src/platforms/layout.d.ts +35 -0
  317. package/dist/src/platforms/layout.js +332 -0
  318. package/dist/src/platforms/layout.js.map +1 -0
  319. package/dist/src/platforms/lifecycle-native-services.d.ts +3 -0
  320. package/dist/src/platforms/lifecycle-native-services.js +213 -0
  321. package/dist/src/platforms/lifecycle-native-services.js.map +1 -0
  322. package/dist/src/platforms/lifecycle-native.d.ts +14 -0
  323. package/dist/src/platforms/lifecycle-native.js +234 -0
  324. package/dist/src/platforms/lifecycle-native.js.map +1 -0
  325. package/dist/src/platforms/lifecycle.d.ts +29 -0
  326. package/dist/src/platforms/lifecycle.js +688 -0
  327. package/dist/src/platforms/lifecycle.js.map +1 -0
  328. package/dist/src/platforms/opencode-permission-config.d.ts +13 -0
  329. package/dist/src/platforms/opencode-permission-config.js +253 -0
  330. package/dist/src/platforms/opencode-permission-config.js.map +1 -0
  331. package/dist/src/platforms/opencode-permissions.d.ts +39 -0
  332. package/dist/src/platforms/opencode-permissions.js +212 -0
  333. package/dist/src/platforms/opencode-permissions.js.map +1 -0
  334. package/dist/src/platforms/opencode-related-permissions.d.ts +40 -0
  335. package/dist/src/platforms/opencode-related-permissions.js +177 -0
  336. package/dist/src/platforms/opencode-related-permissions.js.map +1 -0
  337. package/dist/src/platforms/permission-ownership.d.ts +89 -0
  338. package/dist/src/platforms/permission-ownership.js +543 -0
  339. package/dist/src/platforms/permission-ownership.js.map +1 -0
  340. package/dist/src/platforms/permission-sidecar.d.ts +70 -0
  341. package/dist/src/platforms/permission-sidecar.js +215 -0
  342. package/dist/src/platforms/permission-sidecar.js.map +1 -0
  343. package/dist/src/platforms/projection-code-extension.d.ts +8 -0
  344. package/dist/src/platforms/projection-code-extension.js +126 -0
  345. package/dist/src/platforms/projection-code-extension.js.map +1 -0
  346. package/dist/src/platforms/projection-command-resources.d.ts +7 -0
  347. package/dist/src/platforms/projection-command-resources.js +74 -0
  348. package/dist/src/platforms/projection-command-resources.js.map +1 -0
  349. package/dist/src/platforms/projection-files.d.ts +28 -0
  350. package/dist/src/platforms/projection-files.js +113 -0
  351. package/dist/src/platforms/projection-files.js.map +1 -0
  352. package/dist/src/platforms/projection-marketplace.d.ts +19 -0
  353. package/dist/src/platforms/projection-marketplace.js +42 -0
  354. package/dist/src/platforms/projection-marketplace.js.map +1 -0
  355. package/dist/src/platforms/projection.d.ts +13 -0
  356. package/dist/src/platforms/projection.js +578 -0
  357. package/dist/src/platforms/projection.js.map +1 -0
  358. package/dist/src/platforms/read-only-retry-policy.d.ts +34 -0
  359. package/dist/src/platforms/read-only-retry-policy.js +70 -0
  360. package/dist/src/platforms/read-only-retry-policy.js.map +1 -0
  361. package/dist/src/platforms/registry.d.ts +4 -0
  362. package/dist/src/platforms/registry.js +30 -0
  363. package/dist/src/platforms/registry.js.map +1 -0
  364. package/dist/src/platforms/retirement-native.d.ts +6 -0
  365. package/dist/src/platforms/retirement-native.js +95 -0
  366. package/dist/src/platforms/retirement-native.js.map +1 -0
  367. package/dist/src/platforms/supplement-layout.d.ts +20 -0
  368. package/dist/src/platforms/supplement-layout.js +54 -0
  369. package/dist/src/platforms/supplement-layout.js.map +1 -0
  370. package/dist/src/platforms/supplement-state.d.ts +13 -0
  371. package/dist/src/platforms/supplement-state.js +93 -0
  372. package/dist/src/platforms/supplement-state.js.map +1 -0
  373. package/dist/src/portable/commands.d.ts +60 -11
  374. package/dist/src/portable/commands.js +88 -346
  375. package/dist/src/portable/commands.js.map +1 -1
  376. package/dist/src/portable/historical-materialization.d.ts +25 -0
  377. package/dist/src/portable/historical-materialization.js +148 -0
  378. package/dist/src/portable/historical-materialization.js.map +1 -0
  379. package/dist/src/portable/materializer.d.ts +46 -2
  380. package/dist/src/portable/materializer.js +262 -259
  381. package/dist/src/portable/materializer.js.map +1 -1
  382. package/dist/src/portable/recovery-layout.d.ts +17 -0
  383. package/dist/src/portable/recovery-layout.js +42 -0
  384. package/dist/src/portable/recovery-layout.js.map +1 -0
  385. package/dist/src/portable/recovery.d.ts +177 -0
  386. package/dist/src/portable/recovery.js +597 -0
  387. package/dist/src/portable/recovery.js.map +1 -0
  388. package/dist/src/portable/writer.d.ts +67 -0
  389. package/dist/src/portable/writer.js +321 -0
  390. package/dist/src/portable/writer.js.map +1 -0
  391. package/dist/src/recovery/coordinator.d.ts +175 -0
  392. package/dist/src/recovery/coordinator.js +1629 -0
  393. package/dist/src/recovery/coordinator.js.map +1 -0
  394. package/dist/src/recovery/demand.d.ts +53 -0
  395. package/dist/src/recovery/demand.js +189 -0
  396. package/dist/src/recovery/demand.js.map +1 -0
  397. package/dist/src/recovery/install-concurrency.d.ts +48 -0
  398. package/dist/src/recovery/install-concurrency.js +196 -0
  399. package/dist/src/recovery/install-concurrency.js.map +1 -0
  400. package/dist/src/recovery/interruption.d.ts +19 -0
  401. package/dist/src/recovery/interruption.js +43 -0
  402. package/dist/src/recovery/interruption.js.map +1 -0
  403. package/dist/src/recovery/joint-coordinator.d.ts +46 -0
  404. package/dist/src/recovery/joint-coordinator.js +1728 -0
  405. package/dist/src/recovery/joint-coordinator.js.map +1 -0
  406. package/dist/src/recovery/joint-demand.d.ts +72 -0
  407. package/dist/src/recovery/joint-demand.js +332 -0
  408. package/dist/src/recovery/joint-demand.js.map +1 -0
  409. package/dist/src/recovery/joint-install-execution.d.ts +19 -0
  410. package/dist/src/recovery/joint-install-execution.js +312 -0
  411. package/dist/src/recovery/joint-install-execution.js.map +1 -0
  412. package/dist/src/recovery/joint-install-native-rebase.d.ts +4 -0
  413. package/dist/src/recovery/joint-install-native-rebase.js +67 -0
  414. package/dist/src/recovery/joint-install-native-rebase.js.map +1 -0
  415. package/dist/src/recovery/performance.d.ts +4 -0
  416. package/dist/src/recovery/performance.js +26 -0
  417. package/dist/src/recovery/performance.js.map +1 -0
  418. package/dist/src/recovery/receipt.d.ts +131 -0
  419. package/dist/src/recovery/receipt.js +91 -0
  420. package/dist/src/recovery/receipt.js.map +1 -0
  421. package/dist/src/recovery/retirement.d.ts +47 -0
  422. package/dist/src/recovery/retirement.js +504 -0
  423. package/dist/src/recovery/retirement.js.map +1 -0
  424. package/dist/src/recovery/status.d.ts +143 -0
  425. package/dist/src/recovery/status.js +1528 -0
  426. package/dist/src/recovery/status.js.map +1 -0
  427. package/dist/src/recovery/types.d.ts +85 -0
  428. package/dist/src/recovery/types.js +2 -0
  429. package/dist/src/recovery/types.js.map +1 -0
  430. package/dist/src/review/eval-source-input.d.ts +44 -0
  431. package/dist/src/review/eval-source-input.js +213 -0
  432. package/dist/src/review/eval-source-input.js.map +1 -0
  433. package/dist/src/review/platform-profile.d.ts +5 -0
  434. package/dist/src/review/platform-profile.js +13 -0
  435. package/dist/src/review/platform-profile.js.map +1 -0
  436. package/dist/src/review/review-profile.d.ts +20 -0
  437. package/dist/src/review/review-profile.js +286 -0
  438. package/dist/src/review/review-profile.js.map +1 -0
  439. package/dist/src/review/review-selection.d.ts +20 -0
  440. package/dist/src/review/review-selection.js +502 -0
  441. package/dist/src/review/review-selection.js.map +1 -0
  442. package/dist/src/review/review-types.d.ts +71 -0
  443. package/dist/src/review/review-types.js +16 -0
  444. package/dist/src/review/review-types.js.map +1 -0
  445. package/dist/src/review/skill-materialization.d.ts +67 -0
  446. package/dist/src/review/skill-materialization.js +235 -0
  447. package/dist/src/review/skill-materialization.js.map +1 -0
  448. package/dist/src/review/source-binding.d.ts +203 -0
  449. package/dist/src/review/source-binding.js +791 -0
  450. package/dist/src/review/source-binding.js.map +1 -0
  451. package/dist/src/tui/agent-management.d.ts +23 -0
  452. package/dist/src/tui/agent-management.js +319 -0
  453. package/dist/src/tui/agent-management.js.map +1 -0
  454. package/dist/src/tui/agent-settings.d.ts +47 -0
  455. package/dist/src/tui/agent-settings.js +97 -0
  456. package/dist/src/tui/agent-settings.js.map +1 -0
  457. package/dist/src/tui/catalog-generation.d.ts +9 -0
  458. package/dist/src/tui/catalog-generation.js +96 -6
  459. package/dist/src/tui/catalog-generation.js.map +1 -1
  460. package/dist/src/tui/catalog-sources/projection.d.ts +2 -2
  461. package/dist/src/tui/catalog-sources/screens.js +19 -12
  462. package/dist/src/tui/catalog-sources/screens.js.map +1 -1
  463. package/dist/src/tui/catalog-sources/session.d.ts +11 -1
  464. package/dist/src/tui/catalog-sources/session.js +80 -5
  465. package/dist/src/tui/catalog-sources/session.js.map +1 -1
  466. package/dist/src/tui/catalog-sources/types.d.ts +15 -2
  467. package/dist/src/tui/catalog-store-task.d.ts +16 -0
  468. package/dist/src/tui/catalog-store-task.js +19 -0
  469. package/dist/src/tui/catalog-store-task.js.map +1 -0
  470. package/dist/src/tui/clipboard.d.ts +13 -0
  471. package/dist/src/tui/clipboard.js +95 -0
  472. package/dist/src/tui/clipboard.js.map +1 -0
  473. package/dist/src/tui/components.d.ts +113 -3
  474. package/dist/src/tui/components.js +201 -34
  475. package/dist/src/tui/components.js.map +1 -1
  476. package/dist/src/tui/config-array-draft.d.ts +30 -0
  477. package/dist/src/tui/config-array-draft.js +51 -0
  478. package/dist/src/tui/config-array-draft.js.map +1 -0
  479. package/dist/src/tui/config-leaf-editor.d.ts +44 -0
  480. package/dist/src/tui/config-leaf-editor.js +227 -0
  481. package/dist/src/tui/config-leaf-editor.js.map +1 -0
  482. package/dist/src/tui/config-object-suggestions.d.ts +15 -0
  483. package/dist/src/tui/config-object-suggestions.js +71 -0
  484. package/dist/src/tui/config-object-suggestions.js.map +1 -0
  485. package/dist/src/tui/config-references.d.ts +38 -0
  486. package/dist/src/tui/config-references.js +82 -0
  487. package/dist/src/tui/config-references.js.map +1 -0
  488. package/dist/src/tui/config-suggestions.d.ts +27 -0
  489. package/dist/src/tui/config-suggestions.js +62 -0
  490. package/dist/src/tui/config-suggestions.js.map +1 -0
  491. package/dist/src/tui/config-value-presentation.d.ts +23 -0
  492. package/dist/src/tui/config-value-presentation.js +151 -0
  493. package/dist/src/tui/config-value-presentation.js.map +1 -0
  494. package/dist/src/tui/console-app-v4.d.ts +14 -5
  495. package/dist/src/tui/console-app-v4.js +9779 -2488
  496. package/dist/src/tui/console-app-v4.js.map +1 -1
  497. package/dist/src/tui/content-item-card.d.ts +13 -0
  498. package/dist/src/tui/content-item-card.js +51 -0
  499. package/dist/src/tui/content-item-card.js.map +1 -0
  500. package/dist/src/tui/controller-runtime.d.ts +4 -3
  501. package/dist/src/tui/controller-runtime.js +1610 -590
  502. package/dist/src/tui/controller-runtime.js.map +1 -1
  503. package/dist/src/tui/controller.d.ts +583 -80
  504. package/dist/src/tui/controller.js +3362 -263
  505. package/dist/src/tui/controller.js.map +1 -1
  506. package/dist/src/tui/dependency-graph-view.d.ts +39 -0
  507. package/dist/src/tui/dependency-graph-view.js +121 -0
  508. package/dist/src/tui/dependency-graph-view.js.map +1 -0
  509. package/dist/src/tui/dependency-graph.d.ts +81 -0
  510. package/dist/src/tui/dependency-graph.js +452 -0
  511. package/dist/src/tui/dependency-graph.js.map +1 -0
  512. package/dist/src/tui/deployment-view.d.ts +14 -0
  513. package/dist/src/tui/deployment-view.js +175 -0
  514. package/dist/src/tui/deployment-view.js.map +1 -0
  515. package/dist/src/tui/diagnostic-projection.d.ts +31 -0
  516. package/dist/src/tui/diagnostic-projection.js +681 -0
  517. package/dist/src/tui/diagnostic-projection.js.map +1 -0
  518. package/dist/src/tui/diagnostics.d.ts +6 -2
  519. package/dist/src/tui/diagnostics.js +14 -2
  520. package/dist/src/tui/diagnostics.js.map +1 -1
  521. package/dist/src/tui/entity-cards.d.ts +56 -0
  522. package/dist/src/tui/entity-cards.js +327 -0
  523. package/dist/src/tui/entity-cards.js.map +1 -0
  524. package/dist/src/tui/glossary.d.ts +25 -0
  525. package/dist/src/tui/glossary.js +78 -0
  526. package/dist/src/tui/glossary.js.map +1 -0
  527. package/dist/src/tui/guided-setup.d.ts +25 -0
  528. package/dist/src/tui/guided-setup.js +101 -0
  529. package/dist/src/tui/guided-setup.js.map +1 -0
  530. package/dist/src/tui/index.d.ts +4 -1
  531. package/dist/src/tui/index.js +4 -1
  532. package/dist/src/tui/index.js.map +1 -1
  533. package/dist/src/tui/input-display.d.ts +1 -0
  534. package/dist/src/tui/input-display.js +23 -1
  535. package/dist/src/tui/input-display.js.map +1 -1
  536. package/dist/src/tui/keys.d.ts +44 -0
  537. package/dist/src/tui/keys.js +43 -15
  538. package/dist/src/tui/keys.js.map +1 -1
  539. package/dist/src/tui/lifecycle-action-view.d.ts +6 -0
  540. package/dist/src/tui/lifecycle-action-view.js +36 -0
  541. package/dist/src/tui/lifecycle-action-view.js.map +1 -0
  542. package/dist/src/tui/model.d.ts +141 -28
  543. package/dist/src/tui/model.js +968 -285
  544. package/dist/src/tui/model.js.map +1 -1
  545. package/dist/src/tui/operation-diagnostic-screens.d.ts +8 -0
  546. package/dist/src/tui/operation-diagnostic-screens.js +76 -0
  547. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
  548. package/dist/src/tui/operation-history.d.ts +91 -0
  549. package/dist/src/tui/operation-history.js +167 -0
  550. package/dist/src/tui/operation-history.js.map +1 -0
  551. package/dist/src/tui/operation-review-planner.d.ts +7 -0
  552. package/dist/src/tui/operation-review-planner.js +980 -146
  553. package/dist/src/tui/operation-review-planner.js.map +1 -1
  554. package/dist/src/tui/plugin-content.d.ts +33 -0
  555. package/dist/src/tui/plugin-content.js +245 -0
  556. package/dist/src/tui/plugin-content.js.map +1 -0
  557. package/dist/src/tui/plugin-detail.d.ts +75 -0
  558. package/dist/src/tui/plugin-detail.js +267 -0
  559. package/dist/src/tui/plugin-detail.js.map +1 -0
  560. package/dist/src/tui/plugin-write-task.d.ts +69 -0
  561. package/dist/src/tui/plugin-write-task.js +286 -0
  562. package/dist/src/tui/plugin-write-task.js.map +1 -0
  563. package/dist/src/tui/query-header.d.ts +30 -0
  564. package/dist/src/tui/query-header.js +40 -0
  565. package/dist/src/tui/query-header.js.map +1 -0
  566. package/dist/src/tui/reader.d.ts +38 -0
  567. package/dist/src/tui/reader.js +49 -0
  568. package/dist/src/tui/reader.js.map +1 -0
  569. package/dist/src/tui/router.d.ts +170 -39
  570. package/dist/src/tui/router.js +338 -50
  571. package/dist/src/tui/router.js.map +1 -1
  572. package/dist/src/tui/scoped-flow.d.ts +49 -0
  573. package/dist/src/tui/scoped-flow.js +212 -0
  574. package/dist/src/tui/scoped-flow.js.map +1 -0
  575. package/dist/src/tui/scoped-inventory.d.ts +139 -0
  576. package/dist/src/tui/scoped-inventory.js +295 -0
  577. package/dist/src/tui/scoped-inventory.js.map +1 -0
  578. package/dist/src/tui/screen-registry.d.ts +696 -0
  579. package/dist/src/tui/screen-registry.js +226 -0
  580. package/dist/src/tui/screen-registry.js.map +1 -0
  581. package/dist/src/tui/session-console-app.d.ts +8 -0
  582. package/dist/src/tui/session-console-app.js +24 -0
  583. package/dist/src/tui/session-console-app.js.map +1 -0
  584. package/dist/src/tui/session-host.d.ts +45 -0
  585. package/dist/src/tui/session-host.js +219 -0
  586. package/dist/src/tui/session-host.js.map +1 -0
  587. package/dist/src/tui/source-detail-card.d.ts +29 -0
  588. package/dist/src/tui/source-detail-card.js +45 -0
  589. package/dist/src/tui/source-detail-card.js.map +1 -0
  590. package/dist/src/tui/theme.d.ts +12 -0
  591. package/dist/src/tui/theme.js +12 -0
  592. package/dist/src/tui/theme.js.map +1 -1
  593. package/dist/src/tui/viewport.d.ts +1 -0
  594. package/dist/src/tui/viewport.js +23 -0
  595. package/dist/src/tui/viewport.js.map +1 -1
  596. package/dist/src/tui/wizard.js +26 -4
  597. package/dist/src/tui/wizard.js.map +1 -1
  598. package/dist/src/types.d.ts +105 -83
  599. package/dist/src/types.js +1 -1
  600. package/dist/src/types.js.map +1 -1
  601. package/dist/src/utils/agent-version.d.ts +10 -4
  602. package/dist/src/utils/agent-version.js +6 -8
  603. package/dist/src/utils/agent-version.js.map +1 -1
  604. package/dist/src/utils/artifact-plan.d.ts +18 -25
  605. package/dist/src/utils/artifact-plan.js +59 -445
  606. package/dist/src/utils/artifact-plan.js.map +1 -1
  607. package/dist/src/utils/artifact-renderer.d.ts +64 -90
  608. package/dist/src/utils/artifact-renderer.js +202 -303
  609. package/dist/src/utils/artifact-renderer.js.map +1 -1
  610. package/dist/src/utils/artifact-request.d.ts +19 -14
  611. package/dist/src/utils/artifact-request.js +51 -36
  612. package/dist/src/utils/artifact-request.js.map +1 -1
  613. package/dist/src/utils/artifact-sources.d.ts +4 -8
  614. package/dist/src/utils/artifact-sources.js +15 -6
  615. package/dist/src/utils/artifact-sources.js.map +1 -1
  616. package/dist/src/utils/aw-home-mutation-lock.d.ts +1 -0
  617. package/dist/src/utils/aw-home-mutation-lock.js +28 -6
  618. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  619. package/dist/src/utils/bundle-layout.d.ts +2 -0
  620. package/dist/src/utils/bundle-layout.js +88 -158
  621. package/dist/src/utils/bundle-layout.js.map +1 -1
  622. package/dist/src/utils/catalog-capability-projection.d.ts +8 -0
  623. package/dist/src/utils/catalog-capability-projection.js +14 -0
  624. package/dist/src/utils/catalog-capability-projection.js.map +1 -0
  625. package/dist/src/utils/catalog-digests.d.ts +2 -12
  626. package/dist/src/utils/catalog-digests.js +7 -55
  627. package/dist/src/utils/catalog-digests.js.map +1 -1
  628. package/dist/src/utils/catalog-generation-resolver.d.ts +28 -4
  629. package/dist/src/utils/catalog-generation-resolver.js +146 -40
  630. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  631. package/dist/src/utils/catalog-generation-service.d.ts +25 -2
  632. package/dist/src/utils/catalog-generation-service.js +99 -48
  633. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  634. package/dist/src/utils/catalog-generation-state.js +1 -1
  635. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  636. package/dist/src/utils/catalog-generation-store.d.ts +5 -0
  637. package/dist/src/utils/catalog-generation-store.js +69 -10
  638. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  639. package/dist/src/utils/catalog-operation-context.d.ts +61 -4
  640. package/dist/src/utils/catalog-operation-context.js +225 -4
  641. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  642. package/dist/src/utils/catalog-public-error.js +4 -0
  643. package/dist/src/utils/catalog-public-error.js.map +1 -1
  644. package/dist/src/utils/catalog-runtime-projection.d.ts +4 -3
  645. package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
  646. package/dist/src/utils/catalog-snapshot.d.ts +3 -0
  647. package/dist/src/utils/catalog-snapshot.js +4 -1
  648. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  649. package/dist/src/utils/catalog-source-impact.d.ts +3 -2
  650. package/dist/src/utils/catalog-source-impact.js +142 -20
  651. package/dist/src/utils/catalog-source-impact.js.map +1 -1
  652. package/dist/src/utils/catalog-source-references.d.ts +57 -1
  653. package/dist/src/utils/catalog-source-references.js +755 -162
  654. package/dist/src/utils/catalog-source-references.js.map +1 -1
  655. package/dist/src/utils/catalog-sources.d.ts +1 -1
  656. package/dist/src/utils/catalog-sources.js +21 -5
  657. package/dist/src/utils/catalog-sources.js.map +1 -1
  658. package/dist/src/utils/codex-config.d.ts +3 -0
  659. package/dist/src/utils/codex-config.js +7 -0
  660. package/dist/src/utils/codex-config.js.map +1 -1
  661. package/dist/src/utils/codex-executable-discovery.d.ts +28 -0
  662. package/dist/src/utils/codex-executable-discovery.js +431 -0
  663. package/dist/src/utils/codex-executable-discovery.js.map +1 -0
  664. package/dist/src/utils/codex-manager.d.ts +23 -42
  665. package/dist/src/utils/codex-manager.js +79 -767
  666. package/dist/src/utils/codex-manager.js.map +1 -1
  667. package/dist/src/utils/codex-native-observation.d.ts +40 -1
  668. package/dist/src/utils/codex-native-observation.js +172 -0
  669. package/dist/src/utils/codex-native-observation.js.map +1 -1
  670. package/dist/src/utils/codex-reconciler.d.ts +2 -7
  671. package/dist/src/utils/codex-reconciler.js +33 -5
  672. package/dist/src/utils/codex-reconciler.js.map +1 -1
  673. package/dist/src/utils/codex-shared-native.d.ts +8 -26
  674. package/dist/src/utils/codex-shared-native.js +63 -83
  675. package/dist/src/utils/codex-shared-native.js.map +1 -1
  676. package/dist/src/utils/codex-skill-staging.d.ts +4 -3
  677. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  678. package/dist/src/utils/codex-skills-root.d.ts +4 -0
  679. package/dist/src/utils/codex-skills-root.js +29 -0
  680. package/dist/src/utils/codex-skills-root.js.map +1 -0
  681. package/dist/src/utils/codex-surface-analysis.d.ts +6 -2
  682. package/dist/src/utils/codex-surface-analysis.js +31 -56
  683. package/dist/src/utils/codex-surface-analysis.js.map +1 -1
  684. package/dist/src/utils/component-agent-binding.d.ts +17 -0
  685. package/dist/src/utils/component-agent-binding.js +119 -0
  686. package/dist/src/utils/component-agent-binding.js.map +1 -0
  687. package/dist/src/utils/component-command-preparation.d.ts +33 -0
  688. package/dist/src/utils/component-command-preparation.js +129 -0
  689. package/dist/src/utils/component-command-preparation.js.map +1 -0
  690. package/dist/src/utils/component-gap.d.ts +4 -0
  691. package/dist/src/utils/component-gap.js +16 -0
  692. package/dist/src/utils/component-gap.js.map +1 -0
  693. package/dist/src/utils/component-resources.d.ts +53 -0
  694. package/dist/src/utils/component-resources.js +340 -0
  695. package/dist/src/utils/component-resources.js.map +1 -0
  696. package/dist/src/utils/config-platforms.d.ts +21 -0
  697. package/dist/src/utils/config-platforms.js +51 -0
  698. package/dist/src/utils/config-platforms.js.map +1 -0
  699. package/dist/src/utils/dynamic-skill-tree.d.ts +18 -6
  700. package/dist/src/utils/dynamic-skill-tree.js +33 -40
  701. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  702. package/dist/src/utils/git-catalog-provider.d.ts +3 -0
  703. package/dist/src/utils/git-catalog-provider.js +49 -3
  704. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  705. package/dist/src/utils/inventory-recovery-diagnostic.d.ts +4 -0
  706. package/dist/src/utils/inventory-recovery-diagnostic.js +15 -0
  707. package/dist/src/utils/inventory-recovery-diagnostic.js.map +1 -0
  708. package/dist/src/utils/local-marketplace.d.ts +19 -12
  709. package/dist/src/utils/local-marketplace.js +97 -194
  710. package/dist/src/utils/local-marketplace.js.map +1 -1
  711. package/dist/src/utils/managed-command-cli-review.d.ts +53 -0
  712. package/dist/src/utils/managed-command-cli-review.js +431 -0
  713. package/dist/src/utils/managed-command-cli-review.js.map +1 -0
  714. package/dist/src/utils/managed-command-closure.d.ts +14 -0
  715. package/dist/src/utils/managed-command-closure.js +156 -0
  716. package/dist/src/utils/managed-command-closure.js.map +1 -0
  717. package/dist/src/utils/managed-command-errors.d.ts +5 -0
  718. package/dist/src/utils/managed-command-errors.js +10 -0
  719. package/dist/src/utils/managed-command-errors.js.map +1 -0
  720. package/dist/src/utils/managed-command-materialization.d.ts +90 -0
  721. package/dist/src/utils/managed-command-materialization.js +375 -0
  722. package/dist/src/utils/managed-command-materialization.js.map +1 -0
  723. package/dist/src/utils/managed-command-preparation.d.ts +30 -0
  724. package/dist/src/utils/managed-command-preparation.js +39 -0
  725. package/dist/src/utils/managed-command-preparation.js.map +1 -0
  726. package/dist/src/utils/managed-command-review.d.ts +33 -0
  727. package/dist/src/utils/managed-command-review.js +80 -0
  728. package/dist/src/utils/managed-command-review.js.map +1 -0
  729. package/dist/src/utils/managed-command-runtime.d.ts +36 -0
  730. package/dist/src/utils/managed-command-runtime.js +126 -0
  731. package/dist/src/utils/managed-command-runtime.js.map +1 -0
  732. package/dist/src/utils/managed-command-snapshots.d.ts +24 -0
  733. package/dist/src/utils/managed-command-snapshots.js +89 -0
  734. package/dist/src/utils/managed-command-snapshots.js.map +1 -0
  735. package/dist/src/utils/managed-command-store.d.ts +141 -0
  736. package/dist/src/utils/managed-command-store.js +839 -0
  737. package/dist/src/utils/managed-command-store.js.map +1 -0
  738. package/dist/src/utils/multi-source-catalog.d.ts +6 -1
  739. package/dist/src/utils/multi-source-catalog.js +9 -4
  740. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  741. package/dist/src/utils/native-cli-interruption.d.ts +11 -0
  742. package/dist/src/utils/native-cli-interruption.js +106 -0
  743. package/dist/src/utils/native-cli-interruption.js.map +1 -0
  744. package/dist/src/utils/native-cli.d.ts +37 -6
  745. package/dist/src/utils/native-cli.js +523 -60
  746. package/dist/src/utils/native-cli.js.map +1 -1
  747. package/dist/src/utils/native-demand.d.ts +29 -0
  748. package/dist/src/utils/native-demand.js +4 -0
  749. package/dist/src/utils/native-demand.js.map +1 -0
  750. package/dist/src/utils/native-tool-context.d.ts +17 -0
  751. package/dist/src/utils/native-tool-context.js +40 -0
  752. package/dist/src/utils/native-tool-context.js.map +1 -0
  753. package/dist/src/utils/native-tool-review.d.ts +8 -0
  754. package/dist/src/utils/native-tool-review.js +14 -0
  755. package/dist/src/utils/native-tool-review.js.map +1 -0
  756. package/dist/src/utils/ownership.d.ts +38 -3
  757. package/dist/src/utils/ownership.js +118 -11
  758. package/dist/src/utils/ownership.js.map +1 -1
  759. package/dist/src/utils/package-content.d.ts +7 -0
  760. package/dist/src/utils/package-content.js +70 -0
  761. package/dist/src/utils/package-content.js.map +1 -0
  762. package/dist/src/utils/path-catalog-provider.js +2 -0
  763. package/dist/src/utils/path-catalog-provider.js.map +1 -1
  764. package/dist/src/utils/paths.d.ts +1 -1
  765. package/dist/src/utils/paths.js +5 -2
  766. package/dist/src/utils/paths.js.map +1 -1
  767. package/dist/src/utils/platform-empty-state.d.ts +69 -0
  768. package/dist/src/utils/platform-empty-state.js +249 -0
  769. package/dist/src/utils/platform-empty-state.js.map +1 -0
  770. package/dist/src/utils/platform-support.d.ts +1 -1
  771. package/dist/src/utils/platform-support.js +1 -1
  772. package/dist/src/utils/platform-support.js.map +1 -1
  773. package/dist/src/utils/plugin-config-command-apply.d.ts +33 -0
  774. package/dist/src/utils/plugin-config-command-apply.js +142 -0
  775. package/dist/src/utils/plugin-config-command-apply.js.map +1 -0
  776. package/dist/src/utils/plugin-config-diagnostics.d.ts +16 -0
  777. package/dist/src/utils/plugin-config-diagnostics.js +44 -0
  778. package/dist/src/utils/plugin-config-diagnostics.js.map +1 -0
  779. package/dist/src/utils/plugin-config-impact.d.ts +76 -0
  780. package/dist/src/utils/plugin-config-impact.js +359 -0
  781. package/dist/src/utils/plugin-config-impact.js.map +1 -0
  782. package/dist/src/utils/plugin-config-references.d.ts +116 -0
  783. package/dist/src/utils/plugin-config-references.js +379 -0
  784. package/dist/src/utils/plugin-config-references.js.map +1 -0
  785. package/dist/src/utils/plugin-config-suggestion-runner.d.ts +83 -0
  786. package/dist/src/utils/plugin-config-suggestion-runner.js +308 -0
  787. package/dist/src/utils/plugin-config-suggestion-runner.js.map +1 -0
  788. package/dist/src/utils/plugin-config-suggestions.d.ts +50 -0
  789. package/dist/src/utils/plugin-config-suggestions.js +322 -0
  790. package/dist/src/utils/plugin-config-suggestions.js.map +1 -0
  791. package/dist/src/utils/plugin-config-write.d.ts +108 -19
  792. package/dist/src/utils/plugin-config-write.js +781 -568
  793. package/dist/src/utils/plugin-config-write.js.map +1 -1
  794. package/dist/src/utils/plugin-config.d.ts +122 -43
  795. package/dist/src/utils/plugin-config.js +574 -610
  796. package/dist/src/utils/plugin-config.js.map +1 -1
  797. package/dist/src/utils/plugin-dependencies.d.ts +1 -1
  798. package/dist/src/utils/plugin-dependencies.js.map +1 -1
  799. package/dist/src/utils/plugin-scripts.d.ts +41 -17
  800. package/dist/src/utils/plugin-scripts.js +586 -123
  801. package/dist/src/utils/plugin-scripts.js.map +1 -1
  802. package/dist/src/utils/process-lock.d.ts +1 -0
  803. package/dist/src/utils/process-lock.js +22 -5
  804. package/dist/src/utils/process-lock.js.map +1 -1
  805. package/dist/src/utils/process-tree.d.ts +2 -2
  806. package/dist/src/utils/process-tree.js +1 -1
  807. package/dist/src/utils/process-tree.js.map +1 -1
  808. package/dist/src/utils/project-boundary.d.ts +11 -1
  809. package/dist/src/utils/project-boundary.js +33 -11
  810. package/dist/src/utils/project-boundary.js.map +1 -1
  811. package/dist/src/utils/rendered-contract.js +24 -1
  812. package/dist/src/utils/rendered-contract.js.map +1 -1
  813. package/dist/src/utils/runtime-config.d.ts +18 -0
  814. package/dist/src/utils/runtime-config.js +64 -0
  815. package/dist/src/utils/runtime-config.js.map +1 -0
  816. package/dist/src/utils/runtime-skill-closure.d.ts +2 -2
  817. package/dist/src/utils/runtime-skill-closure.js +50 -7
  818. package/dist/src/utils/runtime-skill-closure.js.map +1 -1
  819. package/dist/src/utils/safe-operation-diagnostic.d.ts +15 -0
  820. package/dist/src/utils/safe-operation-diagnostic.js +33 -0
  821. package/dist/src/utils/safe-operation-diagnostic.js.map +1 -0
  822. package/dist/src/utils/sensitive-content.d.ts +4 -0
  823. package/dist/src/utils/sensitive-content.js +36 -0
  824. package/dist/src/utils/sensitive-content.js.map +1 -0
  825. package/dist/src/utils/skill-invocation-warning.d.ts +19 -0
  826. package/dist/src/utils/skill-invocation-warning.js +43 -0
  827. package/dist/src/utils/skill-invocation-warning.js.map +1 -0
  828. package/dist/src/utils/skill-validation.js +0 -5
  829. package/dist/src/utils/skill-validation.js.map +1 -1
  830. package/dist/src/utils/state-paths.d.ts +8 -3
  831. package/dist/src/utils/state-paths.js +53 -16
  832. package/dist/src/utils/state-paths.js.map +1 -1
  833. package/dist/src/utils/target-eligibility.d.ts +2 -2
  834. package/dist/src/utils/target-eligibility.js.map +1 -1
  835. package/dist/src/utils/windows-claude-shim.d.ts +7 -0
  836. package/dist/src/utils/windows-claude-shim.js +10 -0
  837. package/dist/src/utils/windows-claude-shim.js.map +1 -0
  838. package/dist/src/utils/windows-npm-shim.d.ts +16 -0
  839. package/dist/src/utils/windows-npm-shim.js +155 -0
  840. package/dist/src/utils/windows-npm-shim.js.map +1 -0
  841. package/dist/vitest.config.js +109 -9
  842. package/dist/vitest.config.js.map +1 -1
  843. package/package.json +20 -12
  844. package/dist/authoring/templates/aw-config-runtime.d.mts +0 -2
  845. package/dist/authoring/templates/aw-config-runtime.mjs +0 -407
  846. package/dist/authoring/templates/aw-config-runtime.mjs.map +0 -1
  847. package/dist/src/commands/review-publication.d.ts +0 -99
  848. package/dist/src/commands/review-publication.js +0 -904
  849. package/dist/src/commands/review-publication.js.map +0 -1
  850. package/dist/src/commands/sync-command.d.ts +0 -23
  851. package/dist/src/commands/sync-command.js +0 -242
  852. package/dist/src/commands/sync-command.js.map +0 -1
  853. package/dist/src/portable/skills-cli.d.ts +0 -43
  854. package/dist/src/portable/skills-cli.js +0 -148
  855. package/dist/src/portable/skills-cli.js.map +0 -1
  856. package/dist/src/utils/codex-native-render-receipt.d.ts +0 -40
  857. package/dist/src/utils/codex-native-render-receipt.js +0 -205
  858. package/dist/src/utils/codex-native-render-receipt.js.map +0 -1
  859. package/dist/src/utils/plugin-intent-state.d.ts +0 -34
  860. package/dist/src/utils/plugin-intent-state.js +0 -289
  861. package/dist/src/utils/plugin-intent-state.js.map +0 -1
  862. package/dist/src/utils/slash-commands.d.ts +0 -1
  863. package/dist/src/utils/slash-commands.js +0 -2
  864. package/dist/src/utils/slash-commands.js.map +0 -1
@@ -0,0 +1,1728 @@
1
+ import { finalizePreparedPlatformRebuildSession, recordPreparedGrokProjectRetirement } from '../commands/rebuild-integration.js';
2
+ import { commandPackageProviderSatisfied, preparePortableCommandWithdrawal, publishLifecycleCommandPackage } from '../commands/lifecycle-command-package.js';
3
+ import { operationPlanNativeToolChanges } from '../commands/operation-plan.js';
4
+ import { addRequirements } from '../commands/intent-command.js';
5
+ import { createEmptyIntent, calculateIntentDigest, removeIntentRoot } from '../intent/intent-codec.js';
6
+ import { observeIntent, writeIntent, resolveIntentPath } from '../intent/intent-store.js';
7
+ import { describeStrongStateProblem } from '../intent/diagnostics.js';
8
+ import { observePreferences, normalizeAgents, writePreferences } from '../intent/deployment-preferences.js';
9
+ import { withNativeObservationBatch } from '../platforms/inspection-query.js';
10
+ import { createScopeContext } from '../intent/scope-context.js';
11
+ import { reportCliPhase } from '../output/model.js';
12
+ import { withAwHomeMutationLock } from '../utils/aw-home-mutation-lock.js';
13
+ import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
14
+ import { createCodexNativeObservationSession } from '../utils/codex-native-observation.js';
15
+ import { bindNativeCliRunnerSignal, getDefaultNativeCliRunner } from '../utils/native-cli.js';
16
+ import { analyzeCodexSurface } from '../utils/codex-surface-analysis.js';
17
+ import { CatalogPreparationReadScope, catalogOperationBinding, catalogOperationBindingsMatch, selectCatalogOperationContext } from '../utils/catalog-operation-context.js';
18
+ import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
19
+ import { CatalogGenerationError } from '../utils/catalog-generation-error.js';
20
+ import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
21
+ import { parsePluginId } from '../utils/multi-source-catalog.js';
22
+ import { readDemand, resolveDelivery } from './demand.js';
23
+ import { hasSharedUserPackage } from '../platforms/layout.js';
24
+ import { preparePortableRecovery } from '../portable/recovery.js';
25
+ import { canReuseProviderAcrossScopes, hasInheritableSkills, isInstalledSkillProvider, projectSkillCandidates, readJointDemand, deriveJointDemand, deriveSharedReferenceView, indexJointDependencies } from './joint-demand.js';
26
+ import { checkFootprints, prepareScopedRecovery, executeScopedRecovery, executeRecoveryPreApply, refreshRecoveryNativePreviews, describeRecoveryPlan, errorCode, catalogRecheckDiagnostic, blockScopedRecoveryBeforeExecution } from './coordinator.js';
27
+ import { isTargetObservationReadError, readScopedRecoveryStatus, readRecoveryStatus } from './status.js';
28
+ import { recoveryRetryDispositions, recoveryStatusContext, retriesFromRequestedRoots } from './receipt.js';
29
+ import { limitInstallNativeRunner, mapInstallReads } from './install-concurrency.js';
30
+ import { executeJointInstall } from './joint-install-execution.js';
31
+ import { RecoveryInterruptedError, recoveryInterruptionCode } from './interruption.js';
32
+ import { measureRecoveryPerformanceStage, recordRecoveryPerformanceStage } from './performance.js';
33
+ import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
34
+ import { isInstallConfigBlocked } from '../utils/plugin-config-diagnostics.js';
35
+ const diagnostic = (code, message = code) => ({ code, message });
36
+ function intentReceipt(observation) {
37
+ return { state: observation.state,
38
+ roots: observation.state === 'valid' ? observation.value.roots.map((root) => root.pluginId)
39
+ : observation.state === 'absent' ? [] : null,
40
+ ...('digest' in observation ? { digest: observation.digest } : {}),
41
+ };
42
+ }
43
+ function isInstallBatch(command) {
44
+ return command === 'install' || command === 'sync';
45
+ }
46
+ const observationEvidence = (value) => 'rawDigest' in value ? `${value.state}:${value.rawDigest}` : value.state;
47
+ function snapshotEvidence(snapshot) {
48
+ return JSON.stringify([observationEvidence(snapshot.user.intent),
49
+ snapshot.project ? observationEvidence(snapshot.project.intent) : null,
50
+ observationEvidence(snapshot.user.preferences), catalogOperationBinding(snapshot.user.catalogOperationContext),
51
+ catalogOperationBinding(snapshot.project?.catalogOperationContext)]);
52
+ }
53
+ function asObservation(value) {
54
+ const rawBytes = Buffer.from(JSON.stringify(value));
55
+ return { state: 'valid', value, digest: calculateIntentDigest(value), rawDigest: calculateIntentDigest(value), rawBytes };
56
+ }
57
+ function targetKey(target) {
58
+ return [target.pluginId, target.agent, target.scope].join('\0');
59
+ }
60
+ function matchesExactContribution(placement, contribution, exact, reaches) {
61
+ return placement.target === exact.agent && contribution.scope === exact.scope
62
+ && reaches(contribution.root, exact.pluginId) && reaches(exact.pluginId, placement.pluginId);
63
+ }
64
+ function useDeclaredRetryRoots(receipt) {
65
+ const configBlockedInstall = isInstallConfigBlocked(receipt);
66
+ const status = `aw plugin status --context ${recoveryStatusContext(receipt)} --json`;
67
+ const results = new Map(receipt.targetResults.map((target) => [targetKey(target), target]));
68
+ const pending = new Set(receipt.remainingTargets.map(targetKey));
69
+ const revise = (action) => {
70
+ if (/^aw plugin status --context (?:user|project) --json$/u.test(action))
71
+ return [status];
72
+ // Only rewrite the known command at the end of a backend action. Paths and instructions preceding it stay display text.
73
+ const match = /aw plugin sync (\S+) (?:--context (user|project) --target ([\w-]+)|--target ([\w-]+) --context (user|project))((?: --(?:rebuild|yes))*)([.。]?)$/u.exec(action);
74
+ if (!match)
75
+ return [action];
76
+ const prefix = action.slice(0, match.index);
77
+ if (prefix && !/(?:^|\s)run $|然后重试 $/iu.test(prefix))
78
+ return [action];
79
+ const context = prefix.replace(/(?:then run |run |然后重试 )$/iu, '').trimEnd();
80
+ if (configBlockedInstall)
81
+ return [context ? `${context} 修复配置后重新执行原安装请求。` : '修复配置后重新执行原安装请求。'];
82
+ const target = results.get([match[1], match[3] ?? match[4], match[2] ?? match[5]].join('\0'));
83
+ if (!target || !pending.has(targetKey(target)))
84
+ return context ? [context] : [];
85
+ const dispositions = recoveryRetryDispositions(receipt, [target]);
86
+ if (!dispositions.length)
87
+ return [context ? `${context} ${status}` : status];
88
+ return dispositions.map((root) => {
89
+ if (root.kind === 'exact-project') {
90
+ const exact = `请在 TUI 当前项目中选择 ${root.pluginId} 的 ${root.agent} 位置重新检查。`;
91
+ return context ? `${context} ${exact}` : exact;
92
+ }
93
+ const command = `aw plugin sync ${root.pluginId} --context ${root.scope} --target ${root.agent}${match[6]}`;
94
+ return prefix && prefix !== 'run ' ? `${prefix}${command}${match[7]}` : command;
95
+ });
96
+ };
97
+ for (const target of receipt.targetResults) {
98
+ if (target.recoveryActions)
99
+ target.recoveryActions = [...new Set(target.recoveryActions.flatMap(revise))];
100
+ }
101
+ receipt.recoveryActions = [...new Set(receipt.recoveryActions.flatMap(revise))];
102
+ }
103
+ function mergeReceipts(plan, receipts) {
104
+ const joint = plan.joint;
105
+ const receipt = structuredClone(plan.receipt);
106
+ receipt.targetResults = receipts.flatMap((item) => item.targetResults);
107
+ receipt.remainingTargets = receipts.flatMap((item) => item.remainingTargets);
108
+ const actions = receipts.flatMap((item) => item.recoveryActions);
109
+ const reviewedOrder = joint.targetOrder;
110
+ const byPosition = (a, b) => (reviewedOrder?.get(targetKey(a)) ?? Number.MAX_SAFE_INTEGER) - (reviewedOrder?.get(targetKey(b)) ?? Number.MAX_SAFE_INTEGER);
111
+ for (const target of receipt.targetResults) {
112
+ const placements = joint.demand.placements;
113
+ const activationOnly = joint.children.some((child) => child.options.nativeActivationOnlyTargets?.some((item) => item.pluginId === target.pluginId && item.platform === target.agent && item.scope === target.scope));
114
+ const placement = placements.find((item) => item.pluginId === target.pluginId && item.target === target.agent && item.scope === target.scope)
115
+ ?? (target.scope === 'project' && activationOnly ? placements.find((item) => item.pluginId === target.pluginId && item.target === target.agent && item.scope === 'user'
116
+ && item.contributions.some((contribution) => contribution.scope === target.scope)) : undefined);
117
+ if (placement) {
118
+ const contributions = placement.scope === target.scope ? placement.contributions
119
+ : placement.contributions.filter((item) => item.scope === target.scope);
120
+ const selectedContributions = retriesFromRequestedRoots(receipt)
121
+ ? contributions.filter((item) => joint.selectedContributions.get(placement)?.includes(item)) : contributions;
122
+ target.requiredBy = [...new Set(contributions.map((item) => item.root))];
123
+ target.providerScope = placement.scope;
124
+ if (plan.command !== 'uninstall' || placement.scope !== target.scope)
125
+ target.relation = selectedContributions.some((item) => item.root === target.pluginId && item.scope === target.scope) ? 'root' : 'dependency';
126
+ if (target.relation === 'dependency')
127
+ target.contributions = selectedContributions;
128
+ if (placement.scope !== target.scope) {
129
+ target.requirementScope = target.scope;
130
+ if (target.satisfaction === 'installed' && placement.scope === 'user')
131
+ target.satisfaction = 'inherited-user';
132
+ }
133
+ }
134
+ }
135
+ const executed = new Set(receipt.targetResults.map(targetKey));
136
+ const skipped = [];
137
+ for (const root of joint.unplacedRoots) {
138
+ const position = { pluginId: root.pluginId, agent: root.target, scope: root.scope };
139
+ if (executed.has(targetKey(position)))
140
+ continue;
141
+ const common = { ...position, relation: 'root', requiredBy: [root.pluginId], requirementScope: root.scope,
142
+ blockers: root.blockers, ...(root.reasons?.length ? { reasons: root.reasons } : {}) };
143
+ if (root.state === 'excluded' || root.state === 'unsupported') {
144
+ const results = plan.options.exactTargets ? receipt.targetResults : skipped;
145
+ results.push({ ...common, delivery: null, execution: 'no-op', observation: 'verified',
146
+ content: 'satisfied', satisfaction: root.state });
147
+ continue;
148
+ }
149
+ const plugin = joint.snapshot[root.scope]?.roots?.find((item) => item.pluginId === root.pluginId)?.plugin;
150
+ const delivery = plugin ? resolveDelivery(plugin.manifest, root.target, root.scope) ?? null : null;
151
+ const recoveryActions = [
152
+ ...root.blockers.filter((blocker) => blocker.code === 'dependencyExcluded' && blocker.pluginId)
153
+ .map((blocker) => `aw target include ${blocker.pluginId} --target ${root.target}`),
154
+ `aw plugin sync ${root.pluginId} --context ${root.scope} --target ${root.target}`,
155
+ ];
156
+ receipt.targetResults.push({ ...common, delivery, execution: 'not-run', observation: 'unknown',
157
+ content: 'unknown', satisfaction: 'unknown', recoveryActions });
158
+ receipt.remainingTargets.push({ ...position, delivery });
159
+ actions.push(...recoveryActions);
160
+ }
161
+ if (reviewedOrder)
162
+ receipt.targetResults.sort(byPosition);
163
+ receipt.targetResults.push(...skipped);
164
+ receipt.requestedTargets = receipt.targetResults.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
165
+ if (reviewedOrder)
166
+ receipt.remainingTargets.sort(byPosition);
167
+ receipt.errors = [...receipt.blockers, ...receipts.flatMap((item) => [...item.blockers, ...item.errors])];
168
+ receipt.outputsMayHaveChanged = receipts.some((item) => item.outputsMayHaveChanged);
169
+ receipt.commandResults = receipts.flatMap((item) => item.commandResults ?? []);
170
+ receipt.nativeToolChanges = receipts.flatMap((item) => item.nativeToolChanges ?? []);
171
+ if (plan.portableCommandWithdrawals?.length) {
172
+ receipt.nativeToolChanges = operationPlanNativeToolChanges({ actions: plan.portableCommandWithdrawals, nativeToolChanges: receipt.nativeToolChanges });
173
+ }
174
+ receipt.recoveryActions = [...new Set(actions)];
175
+ receipt.ok = receipt.blockers.length === 0 && receipts.every((item) => item.ok);
176
+ return receipt;
177
+ }
178
+ function finalStatusReadFailure(status, receipt) {
179
+ const completed = receipt.targetResults.filter((target) => target.delivery && target.observation === 'verified');
180
+ const strongStateError = status.errors.find((error) => error.code === 'deploymentPreferencesInvalid'
181
+ || error.code === 'pluginIntentStateInvalid' && (error.subject?.scope === receipt.scope
182
+ || completed.some((target) => target.scope === error.subject?.scope)));
183
+ if (strongStateError)
184
+ return strongStateError;
185
+ for (const { pluginId, scope, agent } of completed) {
186
+ const matches = (target) => target.pluginId === pluginId
187
+ && target.scope === scope && target.agent === agent;
188
+ const root = status.inventory?.find((item) => item.pluginId === pluginId && item.targetResults.some(matches));
189
+ const failure = root?.blockers.find((entry) => root.sourceState !== 'ready' || entry.code === 'pluginManifestUnavailable')
190
+ ?? root?.targetResults.find(matches)?.blockers.find((entry) => entry.code === 'pluginManifestUnavailable' || entry.code === 'jointDemandUnknown')
191
+ ?? status.observedTargets?.find(matches)?.blockers.find(isTargetObservationReadError);
192
+ if (failure)
193
+ return { ...failure, subject: { pluginId, scope, target: agent } };
194
+ }
195
+ return undefined;
196
+ }
197
+ function blockedBeforeDeployment(plan, blocker = diagnostic('operationReviewStale'), savedState) {
198
+ const receipt = structuredClone(plan.receipt);
199
+ receipt.ok = false;
200
+ receipt.blockers.push(blocker);
201
+ receipt.errors = [...receipt.blockers];
202
+ receipt.commandResults = [];
203
+ receipt.nativeToolChanges = [];
204
+ receipt.remainingTargets = [];
205
+ receipt.recoveryActions = savedState
206
+ ? [`aw plugin status --context ${recoveryStatusContext(receipt)} --json`,
207
+ `请核对当前${savedState === 'intent' ? '插件声明' : '本机 Agent 偏好'}。确认需要的范围后重新准备本次操作。`]
208
+ : ['确认依据已改变,请重新准备本次操作。'];
209
+ if (savedState)
210
+ receipt.unconfirmedSavedState = savedState;
211
+ receipt.targetResults = receipt.targetResults.map((target) => {
212
+ if (target.satisfaction === 'excluded' || target.satisfaction === 'unsupported')
213
+ return target;
214
+ const { pluginId, agent, scope, delivery, relation, requiredBy, requirementScope, providerScope } = target;
215
+ receipt.remainingTargets.push({ pluginId, agent, scope, delivery });
216
+ return { pluginId, agent, scope, delivery, relation, requiredBy, requirementScope, providerScope,
217
+ execution: 'not-run', observation: 'unknown', content: 'unknown', satisfaction: 'unknown', blockers: [blocker] };
218
+ });
219
+ return receipt;
220
+ }
221
+ async function readJointPreparation(options, locked = false, suppliedReads) {
222
+ // Reuse evidence for every read-only plan, including reinstall and uninstall.
223
+ // This is independent of whether execution can use the parallel install scheduler.
224
+ const catalogReadScope = (locked ? undefined : suppliedReads) ?? new CatalogPreparationReadScope(options);
225
+ if (locked && options.catalogOperationContext) {
226
+ // A caller may have reviewed a subset of sources. Rebind just those IDs under
227
+ // the lock so a changed or removed source makes the existing Review stale.
228
+ options = { ...options, catalogOperationContext: await catalogReadScope.rebind(options.catalogOperationContext) };
229
+ }
230
+ const manifestReads = new Map();
231
+ const snapshot = await readJointDemand({ ...options, catalogReadScope, manifestReads });
232
+ return { options, snapshot, catalogReadScope, manifestReads };
233
+ }
234
+ /** Complete requirements determine placement before execution selectors are applied. */
235
+ export async function prepareJointRecovery(command, selectors, options, runtime, preparation) {
236
+ const originalRunner = runtime.nativeCliRunner ?? getDefaultNativeCliRunner();
237
+ runtime = { ...runtime, invocationCwd: runtime.invocationCwd ?? options.cwd, ...(isInstallBatch(command) ? { nativeCliRunner: limitInstallNativeRunner(originalRunner) } : {}),
238
+ preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
239
+ const { snapshot, catalogReadScope, manifestReads } = preparation ?? await readJointPreparation(options, false, runtime.catalogReadScope);
240
+ const prepare = async (current) => {
241
+ const read = (nativeObservationBatch) => {
242
+ if (nativeObservationBatch && command === 'install' && !preparation && !current.awHomeMutationToken) {
243
+ nativeObservationBatch.initialInstallPreview = true;
244
+ }
245
+ return prepareJointRecoveryInSession(command, selectors, options, current, snapshot, { catalogReadScope, nativeObservationBatch }, manifestReads);
246
+ };
247
+ const plan = isInstallBatch(command)
248
+ ? await withNativeObservationBatch({ runner: current.nativeCliRunner, signal: options.signal }, read) : await read();
249
+ plan.joint.originalNativeRunner = originalRunner;
250
+ return plan;
251
+ };
252
+ if (runtime.codexObservationSession)
253
+ return prepare(runtime);
254
+ const observationContext = await createScopeContext({ ...options, scope: snapshot.context.context });
255
+ const executionRunner = runtime.nativeCliRunner ?? getDefaultNativeCliRunner();
256
+ let sessionRunner = bindNativeCliRunnerSignal(executionRunner, options.signal);
257
+ const session = await createCodexNativeObservationSession({ exactCwd: observationContext.executionCwd,
258
+ env: observationContext.env, runner: (invocation) => sessionRunner(invocation), manager: runtime.codexManager });
259
+ try {
260
+ const plan = await prepare({ ...runtime, codexObservationSession: session });
261
+ plan.joint.bindExecutionSignal = (signal) => { sessionRunner = bindNativeCliRunnerSignal(executionRunner, signal); };
262
+ const dispose = plan.context.dispose;
263
+ plan.context.dispose = async () => {
264
+ try {
265
+ await dispose();
266
+ }
267
+ finally {
268
+ try {
269
+ await session.dispose();
270
+ }
271
+ finally {
272
+ await observationContext.dispose();
273
+ }
274
+ }
275
+ };
276
+ return plan;
277
+ }
278
+ catch (error) {
279
+ try {
280
+ await session.dispose();
281
+ }
282
+ finally {
283
+ await observationContext.dispose();
284
+ }
285
+ throw error;
286
+ }
287
+ finally {
288
+ // The same observation session also serves confirmed writes, which cannot use preparation cancellation.
289
+ sessionRunner = bindNativeCliRunnerSignal(executionRunner, runtime.signal);
290
+ }
291
+ }
292
+ async function prepareJointRecoveryInSession(command, selectors, { checkInstallCatalog, ...options }, runtime, snapshot, { catalogReadScope, nativeObservationBatch }, manifestReads) {
293
+ // Status observes saved requirements, before projecting proposed declarations.
294
+ // Reuse them only within this preparation; execution reads them again under the lock.
295
+ const savedDemand = snapshot;
296
+ const initialNativeReads = { nativeCliRunner: nativeObservationBatch?.runner ?? runtime.nativeCliRunner,
297
+ discoveryCache: nativeObservationBatch?.discoveryCache, nativeQuerySession: nativeObservationBatch?.nativeQuerySession,
298
+ codexObservationSession: runtime.codexObservationSession };
299
+ let observedStatus;
300
+ const evidence = snapshotEvidence(snapshot);
301
+ const scope = options.scope ?? snapshot.context.context;
302
+ if (options.exactTargets && command !== 'uninstall') {
303
+ options = { ...options, exactTargets: options.exactTargets.map((entry) => ({ ...entry, scope: entry.scope ?? scope })) };
304
+ }
305
+ const observedIntent = (scope === 'project' ? snapshot.project : snapshot.user).intent;
306
+ if (options.existingOnly) {
307
+ // Existing owned deployments can be refreshed without converting them into declarations.
308
+ observedStatus = await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads }, savedDemand);
309
+ const installed = (observedStatus.existingTargets ?? []).filter((item) => selectors.some((selector) => selector === item.pluginId
310
+ || !selector.includes('/') && parsePluginId(item.pluginId).pluginName === selector)
311
+ && (!options.targets || options.targets.includes(item.agent)));
312
+ if (installed.length) {
313
+ const generations = await readCatalogGenerationState(options.env);
314
+ for (const currentScope of snapshot.context.scopes) {
315
+ const sourceDemand = currentScope === 'user' ? snapshot.user : snapshot.project;
316
+ if (sourceDemand.intent.state !== 'valid' && sourceDemand.intent.state !== 'absent')
317
+ continue;
318
+ const value = structuredClone(sourceDemand.intent.state === 'valid' ? sourceDemand.intent.value : createEmptyIntent());
319
+ for (const item of installed.filter((item) => item.scope === currentScope)) {
320
+ if (value.roots.some((root) => root.pluginId === item.pluginId))
321
+ continue;
322
+ const sourceId = parsePluginId(item.pluginId).sourceId;
323
+ const identity = generations.sources[sourceId]?.active?.logicalIdentity;
324
+ if (!identity)
325
+ continue;
326
+ value.sources[sourceId] = { logicalIdentity: identity };
327
+ value.roots.push({ pluginId: item.pluginId });
328
+ }
329
+ snapshot = { ...snapshot, [currentScope]: await readDemand({ ...options, catalogReadScope, manifestReads, preferences: undefined, scope: currentScope, intent: asObservation(value) }) };
330
+ }
331
+ if (snapshot.preferences)
332
+ snapshot.preferences = { ...snapshot.preferences,
333
+ targets: normalizeAgents([...snapshot.preferences.targets, ...installed.map((item) => item.agent)]) };
334
+ }
335
+ }
336
+ let previousDemand = deriveJointDemand(snapshot);
337
+ const previousCandidates = projectSkillCandidates(previousDemand);
338
+ if (command === 'uninstall' && previousCandidates.length) {
339
+ observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined }, savedDemand);
340
+ previousDemand = deriveJointDemand(snapshot, observedStatus.projectSkillProviders);
341
+ }
342
+ const previousUserProvided = (pluginId, target) => previousDemand.placements.some((item) => item.pluginId === pluginId && item.target === target && item.scope === 'user'
343
+ && item.contributions.some((entry) => entry.scope === 'project'));
344
+ const previousPlugins = [...new Map([...(snapshot.user.plugins), ...(snapshot.project?.plugins ?? [])]
345
+ .map((plugin) => [plugin.pluginId, plugin])).values()];
346
+ const dependencyClosures = new Map();
347
+ const dependencies = (pluginId) => {
348
+ if (!dependencyClosures.has(pluginId)) {
349
+ try {
350
+ const parsed = parsePluginId(pluginId);
351
+ const closure = resolvePluginMetaDependencyClosure(previousPlugins.filter((plugin) => plugin.sourceId === parsed.sourceId), [parsed.pluginName]);
352
+ dependencyClosures.set(pluginId, closure.filter((plugin) => plugin.pluginId !== pluginId).map((plugin) => plugin.pluginId));
353
+ }
354
+ catch {
355
+ dependencyClosures.set(pluginId, null);
356
+ }
357
+ }
358
+ return dependencyClosures.get(pluginId);
359
+ };
360
+ const original = scope === 'project' ? snapshot.project : snapshot.user;
361
+ const errors = [];
362
+ let declaration;
363
+ let requested = [...selectors];
364
+ if (command === 'install') {
365
+ if (!snapshot.preferences?.targets.length)
366
+ errors.push(diagnostic('targetsNotConfigured', '请先配置本机 Agent,再安装插件。'));
367
+ else {
368
+ const proposed = await addRequirements({ ...options, catalogReadScope, scope, selectors, token: runtime.awHomeMutationToken, dryRun: true, installSelectors: true });
369
+ options.signal?.throwIfAborted();
370
+ errors.push(...proposed.errors);
371
+ if (proposed.state && !proposed.errors.length) {
372
+ requested = proposed.roots;
373
+ if (proposed.changed)
374
+ declaration = { scope, value: proposed.state };
375
+ const demand = await readDemand({ ...options, catalogReadScope, manifestReads, preferences: undefined, scope, intent: asObservation(proposed.state) });
376
+ checkInstallCatalog?.(demand.catalogOperationContext, requested);
377
+ snapshot = { ...snapshot, [scope]: demand };
378
+ }
379
+ else if (checkInstallCatalog && catalogReadScope
380
+ && proposed.errors.some((error) => ['sourceMissing', 'sourceActiveUnavailable', 'pluginUnavailable', 'sourceIdentityConflict'].includes(error.code))) {
381
+ // The same error on the accepted generation remains an ordinary planner diagnostic.
382
+ const configSnapshot = await readCatalogSourcesConfigSnapshot(options.env);
383
+ const requestedSources = new Set(proposed.roots.map((root) => parsePluginId(root).sourceId));
384
+ const sourceIds = configSnapshot.config.sources.map((source) => source.id)
385
+ .filter((id) => requestedSources.has(id) || requestedSources.has(undefined));
386
+ checkInstallCatalog(await catalogReadScope.resolve({ configSnapshot, sourceIds }), proposed.roots);
387
+ }
388
+ }
389
+ }
390
+ else if (command === 'uninstall') {
391
+ const selectable = [...new Set([...(original.roots ?? []).map((root) => root.pluginId),
392
+ ...previousDemand.placements.filter((placement) => placement.scope === scope).map((placement) => placement.pluginId)])];
393
+ requested = selectors.flatMap((selector) => {
394
+ const parsed = parsePluginId(selector);
395
+ const matches = selectable.filter((id) => parsed.sourceId ? id === selector : parsePluginId(id).pluginName === parsed.pluginName);
396
+ if (matches.length !== 1)
397
+ errors.push(diagnostic('pluginIntentRootMissing'));
398
+ return matches.length === 1 ? matches : [selector];
399
+ });
400
+ try {
401
+ const sourceIds = new Set(requested.map((id) => parsePluginId(id).sourceId));
402
+ for (const sourceId of sourceIds) {
403
+ const source = original.catalogOperationContext?.catalog.sources.find((entry) => entry.sourceId === sourceId)?.resolution;
404
+ if (!source)
405
+ throw new Error('sourceActiveUnavailable');
406
+ await CatalogPreparationReadScope.validateEntries(catalogReadScope, source);
407
+ }
408
+ }
409
+ catch (error) {
410
+ options.signal?.throwIfAborted();
411
+ if (error instanceof Error && error.name === 'AbortError')
412
+ throw error;
413
+ errors.push(diagnostic('catalogSnapshotInvalid', '来源快照无法完整验证,未修改声明或输出。'));
414
+ }
415
+ if (original.intent.state !== 'valid' && original.intent.state !== 'absent')
416
+ errors.push(diagnostic('pluginIntentStateInvalid'));
417
+ else {
418
+ let value = original.intent.state === 'valid' ? original.intent.value : createEmptyIntent();
419
+ for (const pluginId of requested) {
420
+ if (value.roots.some((root) => root.pluginId === pluginId))
421
+ value = removeIntentRoot(value, pluginId);
422
+ }
423
+ if (!errors.length) {
424
+ if (original.intent.state === 'valid' && calculateIntentDigest(value) !== original.intent.digest)
425
+ declaration = { scope, value };
426
+ const demand = await readDemand({ ...options, catalogReadScope, manifestReads, preferences: undefined, scope, intent: asObservation(value) });
427
+ snapshot = { ...snapshot, [scope]: demand };
428
+ }
429
+ }
430
+ }
431
+ let demand = deriveJointDemand(snapshot);
432
+ const pendingUserSkills = [];
433
+ const candidates = projectSkillCandidates(demand).filter((item) => !options.targets || options.targets.includes(item.target));
434
+ if (candidates.length) {
435
+ observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined,
436
+ projectSkillProbes: candidates }, savedDemand);
437
+ const providers = observedStatus.projectSkillProviders?.map((provider) => {
438
+ if ((!provider.userNeedsRepair && !provider.userAbsent) || provider.projectCopy === 'blocked' || command !== 'sync' || options.existingOnly)
439
+ return provider;
440
+ // A joint sync can repair its selected, owned User package before the Project consumer runs.
441
+ const owned = observedStatus.observedTargets?.some((target) => target.pluginId === provider.pluginId && target.agent === provider.target
442
+ && target.scope === 'user' && target.content === 'drifted' && !target.blockers.length
443
+ && target.deploymentObservations?.every(({ after }) => after.ownership === 'aw'));
444
+ const selectedUserRoot = demand.placements.some((item) => item.scope === 'user' && item.pluginId === provider.pluginId
445
+ && item.target === provider.target && item.contributions.some((entry) => entry.scope === 'user'
446
+ && (!selectors.length || selectors.some((id) => id === entry.root || id === parsePluginId(entry.root).pluginName))
447
+ && (!options.exactTargets || options.exactTargets.some((exact) => exact.scope === 'user'
448
+ && exact.agent === item.target && exact.pluginId === entry.root))));
449
+ if (!selectedUserRoot || !owned && !provider.userAbsent)
450
+ return provider;
451
+ pendingUserSkills.push({ pluginId: provider.pluginId, target: provider.target, sourceIdentity: provider.sourceIdentity });
452
+ return { ...provider, userNeedsRepair: false, userAbsent: false };
453
+ });
454
+ demand = deriveJointDemand(snapshot, providers);
455
+ }
456
+ const rootIds = [...new Set([...(snapshot.user.roots ?? []), ...(snapshot.project?.roots ?? [])]
457
+ .map((root) => root.pluginId))];
458
+ if (command !== 'install' && command !== 'uninstall') {
459
+ requested = selectors.length ? selectors.flatMap((selector) => {
460
+ const parsed = parsePluginId(selector);
461
+ const matches = (options.existingOnly || options.allowDependencySelectors ? [...new Set([...rootIds, ...demand.placements.map((item) => item.pluginId)])] : rootIds).filter((id) => parsed.sourceId ? id === selector : parsePluginId(id).pluginName === parsed.pluginName);
462
+ if (matches.length !== 1 && !options.existingOnly)
463
+ errors.push(diagnostic('syncPluginNotDesired', `${selector} 未声明或名称不唯一。`));
464
+ return matches.length === 1 ? matches : [];
465
+ }) : rootIds;
466
+ }
467
+ const targets = options.targets ? normalizeAgents(options.targets) : snapshot.preferences?.targets ?? [];
468
+ const unplacedRoots = demand.roots.filter((root) => root.state !== 'required'
469
+ && requested.includes(root.pluginId) && targets.includes(root.target)
470
+ && (!options.exactTargets || options.exactTargets.some((exact) => exact.pluginId === root.pluginId
471
+ && exact.agent === root.target && (exact.scope ?? scope) === root.scope))
472
+ && (command !== 'uninstall' || root.state === 'excluded' || root.state === 'unsupported'));
473
+ // Global diagnostics gate shared preparation. A blocked install root cannot prevent
474
+ // an independent selected root from checking its Project activation.
475
+ const rootErrors = new Set(demand.roots.flatMap((root) => root.blockers));
476
+ errors.push(...demand.errors.filter((error) => command === 'uninstall' || !rootErrors.has(error)));
477
+ const explicitlyRemoves = (item) => item.scope === scope && requested.includes(item.pluginId) && (!options.exactTargets
478
+ || options.exactTargets.some((exact) => exact.pluginId === item.pluginId && exact.agent === item.agent
479
+ && (!exact.scope || exact.scope === item.scope)));
480
+ if (command === 'uninstall' && !options.force) {
481
+ for (const pluginId of requested) {
482
+ const consumers = demand.placements.filter((placement) => placement.pluginId === pluginId
483
+ && explicitlyRemoves({ pluginId, agent: placement.target, scope }))
484
+ .flatMap((placement) => placement.contributions.filter((item) => item.path.length > 1
485
+ && (placement.scope === scope || item.scope === scope)).map((item) => item.root));
486
+ if (consumers.length)
487
+ errors.push(diagnostic('dependencyStillRequired', `${pluginId} 仍被 ${[...new Set(consumers)].join('、')} 依赖。使用 --force 可强制移除所选输出。`));
488
+ }
489
+ }
490
+ const selectionDemand = command === 'uninstall' ? previousDemand : demand;
491
+ if (options.exactTargets && (!options.exactTargets.length && !options.existingOnly || options.exactTargets.some((exact) => !targets.includes(exact.agent) || !selectionDemand.roots.some((root) => root.pluginId === exact.pluginId
492
+ && requested.includes(root.pluginId) && root.target === exact.agent && (!exact.scope || root.scope === exact.scope))
493
+ && !selectionDemand.placements.some((placement) => placement.pluginId === exact.pluginId && placement.target === exact.agent
494
+ && (!exact.scope || placement.scope === exact.scope || placement.contributions.some((item) => item.scope === exact.scope))
495
+ && (requested.includes(placement.pluginId) || placement.contributions.some((item) => requested.includes(item.root))))))) {
496
+ errors.push(diagnostic('invalidExactTargets', '精确重试目标不属于当前请求,请重新检查并选择。'));
497
+ }
498
+ const dependencyGraph = indexJointDependencies(demand);
499
+ const { reaches } = dependencyGraph;
500
+ const requestedIds = new Set(requested);
501
+ const selectedContributions = new Map();
502
+ const selected = demand.placements.filter((placement) => {
503
+ if (!targets.includes(placement.target))
504
+ return false;
505
+ if (command === 'uninstall')
506
+ return (canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target))
507
+ && !(options.force && requestedIds.has(placement.pluginId))
508
+ && previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId && previous.target === placement.target
509
+ && previous.scope !== placement.scope && previous.contributions.some((item) => item.scope === scope && requestedIds.has(item.root))
510
+ && (!options.exactTargets || options.exactTargets.some((exact) => exact.agent === placement.target
511
+ && previous.contributions.some((item) => item.path.includes(exact.pluginId) && (!exact.scope || item.scope === exact.scope)))));
512
+ const contributions = placement.contributions.filter((item) => {
513
+ const selects = (pluginId) => !options.exactTargets || options.exactTargets.some((exact) => matchesExactContribution(placement, item, exact, reaches)
514
+ && (reaches(pluginId, exact.pluginId) || reaches(exact.pluginId, pluginId)));
515
+ if (requestedIds.has(item.root) || options.existingOnly && requestedIds.has(placement.pluginId))
516
+ return selects(item.root);
517
+ return options.allowDependencySelectors && requested.some((id) => reaches(item.root, id)
518
+ && reaches(id, placement.pluginId) && selects(id));
519
+ });
520
+ if (!contributions.length)
521
+ return false;
522
+ selectedContributions.set(placement, contributions);
523
+ return true;
524
+ });
525
+ const activationOnlyTargets = [];
526
+ if (snapshot.project && !errors.length) {
527
+ const sharedNative = selected.filter((item) => item.scope === 'user' && hasSharedUserPackage(item.target)
528
+ && (command === 'uninstall' ? item.contributions : selectedContributions.get(item))?.some((entry) => entry.scope === 'project'));
529
+ if (sharedNative.length) {
530
+ const expanded = { ...snapshot.project, roots: [...new Map(sharedNative.map((item) => [item.pluginId, {
531
+ pluginId: item.pluginId, sourceId: item.plugin.sourceId, sourceState: 'ready', blockers: [], plugin: item.plugin,
532
+ }])).values()], userProviders: Object.fromEntries(targets.map((target) => [target,
533
+ demand.placements.filter((item) => item.scope === 'user' && item.target === target).map((item) => item.pluginId)])) };
534
+ const observation = await readScopedRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, scope: 'project', demandOverride: expanded,
535
+ cwd: snapshot.context.projectRoot, targets: undefined });
536
+ for (const item of sharedNative) {
537
+ const addProjectActivation = () => {
538
+ const activation = { ...item, scope: 'project' };
539
+ selected.push(activation);
540
+ selectedContributions.set(activation, selectedContributions.get(item)?.filter((entry) => entry.scope === 'project') ?? []);
541
+ };
542
+ const actual = observation.inventory?.find((entry) => entry.pluginId === item.pluginId)?.targetResults
543
+ .find((entry) => entry.agent === item.target);
544
+ if (item.target === 'codex') {
545
+ const surface = analyzeCodexSurface(item.plugin.manifest);
546
+ const live = actual?.backend?.live;
547
+ const explicitlyDisabled = actual?.deploymentObservations?.some((observation) => observation.after.consumers.some((consumer) => consumer.activation === 'disabled'));
548
+ const userProvidesComponents = surface.components.every((component) => !component.scopes.includes('project') || component.scopes.includes('user'));
549
+ const retiringProjectComponents = live?.components?.some((component) => component.kind === 'ownership'
550
+ && component.key !== 'native' && !component.key.startsWith('activation-') && !component.key.startsWith('marketplace-')
551
+ && ['present', 'partial'].includes(component.state));
552
+ if (userProvidesComponents) {
553
+ if (!surface.nativeKinds.length || !explicitlyDisabled && !retiringProjectComponents)
554
+ continue;
555
+ activationOnlyTargets.push({ pluginId: item.pluginId, platform: 'codex', scope: 'project' });
556
+ addProjectActivation();
557
+ continue;
558
+ }
559
+ }
560
+ if (actual?.content !== 'satisfied') {
561
+ if (item.target !== 'generic')
562
+ activationOnlyTargets.push({ pluginId: item.pluginId, platform: item.target, scope: 'project' });
563
+ addProjectActivation();
564
+ }
565
+ }
566
+ }
567
+ }
568
+ const context = await createScopeContext({ ...options, scope });
569
+ if (command !== 'uninstall')
570
+ errors.push(...unplacedRoots.flatMap((root) => root.blockers));
571
+ const baseDemand = scope === 'project' ? snapshot.project : snapshot.user;
572
+ const rebuildsRequestedRoots = command === 'reinstall' && !options.allowDependencySelectors && !options.existingOnly;
573
+ const receipt = {
574
+ schemaVersion: 1, kind: 'aw-recovery', command, scope, ok: false,
575
+ intent: intentReceipt(observedIntent),
576
+ requestedRoots: requested, requestedTargets: [], remainingTargets: [], targetResults: [],
577
+ selection: { agents: targets, origin: options.targets ? 'argument' : targets.length ? 'preference' : 'none', preferences: snapshot.user.preferences.state },
578
+ blockers: errors, errors, recoveryActions: [], declarationChanged: false, preferencesChanged: false,
579
+ configChanged: false, outputsMayHaveChanged: false,
580
+ ...(rebuildsRequestedRoots ? { rebuildsRequestedRoots: true } : {}),
581
+ ...((isInstallBatch(command) || rebuildsRequestedRoots) && snapshot.context.scopes.includes('project') ? {
582
+ reviewedUserRoots: intentReceipt(options.existingOnly ? savedDemand.user.intent : snapshot.user.intent)
583
+ .roots?.filter((id) => requested.includes(id)) ?? null,
584
+ } : {}),
585
+ coverage: { scopes: snapshot.context.scopes, ...(snapshot.context.projectRoot ? { projectRoot: snapshot.context.projectRoot } : {}) },
586
+ };
587
+ const children = [];
588
+ const { signal: _signal, ...executionOptions } = options;
589
+ const joint = { snapshot, demand, unplacedRoots, removalDependencies: dependencyClosures, selectedContributions, children, originalOptions: executionOptions, pendingUserSkills, providerRetirements: new Set(),
590
+ selectors: [...selectors], declaration, evidence };
591
+ const plan = { command, options: { ...executionOptions, scope }, receipt, context, demand: baseDemand,
592
+ originalIntent: observationEvidence(original.intent), preferencesEvidence: observationEvidence(snapshot.user.preferences),
593
+ plannedImpact: { declaration: Boolean(declaration), preferences: false, config: false, outputs: false },
594
+ changes: declaration ? [`保存 ${scope} 插件需求。`] : [], warnings: [], nativeGroups: [],
595
+ portableGroups: [], portableProtectionGroups: [],
596
+ portableResidues: [], sourceRefreshes: [], sourceRefreshFailures: [], runtime, blockExecution: errors.some((error) => ['syncPluginNotDesired', 'pluginIntentRootMissing', 'pluginIntentStateInvalid', 'catalogSnapshotInvalid', 'installTargetSelectionUnsupported', 'invalidExactTargets', 'dependencyStillRequired'].includes(error.code)
597
+ || error.code === 'targetsNotConfigured' && !options.retireUnselectedTargets)
598
+ || !snapshot.preferences || snapshot.user.roots === null || snapshot.project?.roots === null, joint };
599
+ const dispose = context.dispose;
600
+ let portableUserContext;
601
+ context.dispose = async () => {
602
+ await Promise.all([...children.map((child) => child.context.dispose()), portableUserContext?.dispose()]);
603
+ await dispose();
604
+ };
605
+ if (plan.blockExecution)
606
+ return plan;
607
+ try {
608
+ const currentStatus = observedStatus ?? await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined }, savedDemand);
609
+ const sharedReferenceView = deriveSharedReferenceView(snapshot, demand, currentStatus);
610
+ const ownsOutput = (item) => currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId
611
+ && owned.agent === item.agent && owned.scope === item.scope) === true;
612
+ const liveTargets = currentStatus.existingTargets ?? [];
613
+ const liveConsumers = [...liveTargets, ...(currentStatus.retainedProjectPackages ?? [])];
614
+ const sameProvider = (consumer, provider) => consumer.agent === provider.agent && (consumer.scope === provider.scope
615
+ || provider.scope === 'user' && (canReuseProviderAcrossScopes(consumer.agent) || previousUserProvided(provider.pluginId, consumer.agent)));
616
+ const automaticRetirements = command === 'uninstall' && !options.keepDependencies && demand.complete
617
+ ? previousDemand.placements.filter((placement) => placement.scope === scope && targets.includes(placement.target)
618
+ && (placement.target !== 'generic' ? currentStatus.coverage.native : currentStatus.coverage.portable)
619
+ && !requested.includes(placement.pluginId)
620
+ && !(canReuseProviderAcrossScopes(placement.target) ? rootIds.includes(placement.pluginId)
621
+ : snapshot[placement.scope]?.roots?.some((root) => root.pluginId === placement.pluginId))
622
+ && placement.contributions.some((item) => explicitlyRemoves({ pluginId: item.root, agent: placement.target, scope: item.scope }))
623
+ && !demand.placements.some((item) => item.pluginId === placement.pluginId && item.target === placement.target
624
+ && (item.scope === placement.scope || canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target)))
625
+ && ownsOutput({ pluginId: placement.pluginId, agent: placement.target, scope: placement.scope })) : [];
626
+ // A live consumer can outlast its Intent or its Active catalog entry.
627
+ const retainedConsumerFor = (provider) => liveConsumers.find((consumer) => {
628
+ if (explicitlyRemoves(consumer) && ownsOutput(consumer) || automaticRetirements.some((item) => item.pluginId === consumer.pluginId && item.target === consumer.agent && item.scope === consumer.scope))
629
+ return false;
630
+ const sourceIdentity = consumer.nativePackage?.sourceIdentity;
631
+ const providerManifest = sourceIdentity && previousPlugins.find((plugin) => plugin.pluginId === provider.pluginId && plugin.sourceIdentity === sourceIdentity);
632
+ if (consumer.dependencies !== undefined && !providerManifest)
633
+ return false;
634
+ const liveNativeInheritance = provider.scope === 'user' && consumer.scope === 'project' && consumer.agent === provider.agent
635
+ && providerManifest && !canReuseProviderAcrossScopes(consumer.agent) && hasInheritableSkills(providerManifest)
636
+ && liveTargets.some((item) => item.pluginId === provider.pluginId && item.agent === provider.agent && item.scope === 'user'
637
+ && item.nativePackage?.sourceIdentity === sourceIdentity);
638
+ if (!sameProvider(consumer, provider) && !liveNativeInheritance)
639
+ return false;
640
+ const closure = consumer.dependencies === undefined ? dependencies(consumer.pluginId) : consumer.dependencies;
641
+ if (!closure?.includes(provider.pluginId) && !(closure === null
642
+ && parsePluginId(consumer.pluginId).sourceId === parsePluginId(provider.pluginId).sourceId))
643
+ return false;
644
+ if (liveNativeInheritance) {
645
+ const projectCopyReady = liveTargets.some((item) => item.pluginId === provider.pluginId
646
+ && item.agent === provider.agent && item.scope === 'project' && item.nativePackage?.sourceIdentity === sourceIdentity
647
+ && item.nativePackage?.skillsReady);
648
+ const stagedReplacement = selected.some((item) => item.pluginId === provider.pluginId
649
+ && item.target === provider.agent && item.scope === 'project' && item.plugin.sourceIdentity === sourceIdentity);
650
+ return !projectCopyReady && !stagedReplacement;
651
+ }
652
+ return !demand.placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.agent
653
+ && item.scope !== provider.scope && sameProvider(consumer, { pluginId: item.pluginId, agent: item.target, scope: item.scope }));
654
+ });
655
+ for (let index = automaticRetirements.length - 1; index >= 0; index--) {
656
+ const candidate = automaticRetirements[index];
657
+ if (retainedConsumerFor({ pluginId: candidate.pluginId, agent: candidate.target, scope: candidate.scope })) {
658
+ automaticRetirements.splice(index, 1);
659
+ }
660
+ }
661
+ if (command === 'uninstall' && !options.force) {
662
+ for (const root of demand.roots) {
663
+ if (root.state !== 'unknown' || !targets.includes(root.target)
664
+ || root.scope === scope && options.retiringCatalogRoots?.includes(root.pluginId))
665
+ continue;
666
+ for (const pluginId of requested) {
667
+ const provider = { pluginId, scope, agent: root.target };
668
+ if (root.pluginId === pluginId || !explicitlyRemoves(provider)
669
+ || !sameProvider({ scope: root.scope, agent: root.target }, provider))
670
+ continue;
671
+ if (root.dependencies.length ? !root.dependencies.includes(pluginId)
672
+ : parsePluginId(root.pluginId).sourceId !== parsePluginId(pluginId).sourceId)
673
+ continue;
674
+ // Generic Project roots have their own directory. Verify the saved
675
+ // declaration's complete closure and ownership again under the write lock.
676
+ if (scope === 'user' && root.scope === 'project' && root.target === 'generic'
677
+ && ownsOutput({ pluginId, agent: root.target, scope: 'project' })
678
+ && currentStatus.inventory?.some((item) => item.pluginId === pluginId && item.targetResults.some((target) => target.agent === root.target && target.scope === 'project' && target.providerScope === 'project'
679
+ && target.observation === 'verified' && target.content === 'satisfied' && !target.blockers.length)))
680
+ continue;
681
+ errors.push(diagnostic('dependencyStillRequired', `${pluginId} 仍被 ${root.pluginId} 依赖。使用 --force 可强制移除所选输出。`));
682
+ }
683
+ }
684
+ for (const pluginId of requested)
685
+ for (const agent of new Set(liveConsumers.map((consumer) => consumer.agent))) {
686
+ const provider = { pluginId, agent, scope };
687
+ const consumer = explicitlyRemoves(provider) ? retainedConsumerFor(provider) : undefined;
688
+ if (consumer)
689
+ errors.push(diagnostic('dependencyStillRequired', `${pluginId} 的移除无法保留 ${consumer.pluginId} 的现有依赖。`));
690
+ }
691
+ if (errors.some((error) => error.code === 'dependencyStillRequired')) {
692
+ plan.blockExecution = true;
693
+ return plan;
694
+ }
695
+ }
696
+ if (command === 'uninstall')
697
+ for (const replacement of selected) {
698
+ const old = currentStatus.ownedTargets?.find((item) => item.pluginId === replacement.pluginId
699
+ && item.agent === replacement.target && item.scope !== replacement.scope && retainedConsumerFor(item));
700
+ if (!old)
701
+ continue;
702
+ errors.push(diagnostic('dependencyStillRequired', `${old.pluginId} 的提供位置切换会破坏现存消费者的依赖。`));
703
+ plan.blockExecution = true;
704
+ return plan;
705
+ }
706
+ plan.dependencyCleanupTargets = automaticRetirements.map((item) => ({ pluginId: item.pluginId, agent: item.target, scope: item.scope }));
707
+ const nativeTargets = targets.filter((target) => target !== 'generic');
708
+ const batch = isInstallBatch(command);
709
+ const hasSelectedScripts = selected.some((item) => item.plugin.manifest.scripts?.preApply);
710
+ if (batch && nativeObservationBatch && [...demand.placements, ...selected].every(({ plugin }) => {
711
+ const { command, scripts } = plugin.manifest;
712
+ return command?.mode !== 'dynamic' && !scripts?.artifacts?.render && !scripts?.preApply && !scripts?.node?.build;
713
+ }))
714
+ nativeObservationBatch.scriptFreePlacement = true;
715
+ const portableGenerations = new Map();
716
+ const portableRenderResults = new Map();
717
+ const targetGroups = batch ? [...nativeTargets, ...targets.filter((target) => target === 'generic')].map((target) => [target])
718
+ : [...(nativeTargets.length ? [nativeTargets] : []), ...targets.filter((target) => target === 'generic').map((target) => [target])];
719
+ const inheritedScripts = command === 'sync' && !options.existingOnly ? new Set(selected.filter((item) => {
720
+ if (item.scope !== 'user' || !item.plugin.manifest.scripts?.preApply)
721
+ return false;
722
+ const contributions = selectedContributions.get(item);
723
+ return !contributions.some((entry) => entry.scope === 'user')
724
+ && contributions.some((entry) => entry.scope === 'project' && entry.root !== item.pluginId)
725
+ && !(requestedIds.has(item.pluginId) && (!options.exactTargets || options.exactTargets.some((exact) => exact.pluginId === item.pluginId && exact.agent === item.target && contributions.some((entry) => entry.scope === exact.scope))));
726
+ })) : new Set();
727
+ const preparedPlacements = selected.filter((item) => !(item.scope === 'user' && !canReuseProviderAcrossScopes(item.target)
728
+ && selectedContributions.get(item)?.every((entry) => entry.scope === 'project')
729
+ && currentStatus.observedTargets?.some((actual) => actual.pluginId === item.pluginId
730
+ && actual.agent === item.target && isInstalledSkillProvider(actual)))
731
+ && !(command === 'install' && scope === 'project' && item.scope === 'user'
732
+ && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
733
+ && observed.agent === item.target && observed.scope === 'user' && observed.content === 'satisfied'))
734
+ && !(hasSharedUserPackage(item.target) && inheritedScripts.has(item)
735
+ && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
736
+ && observed.agent === item.target && observed.scope === 'user' && observed.providerScope === 'user'
737
+ && observed.observation === 'verified' && observed.content === 'satisfied' && !observed.blockers.length)));
738
+ // Split provider and host groups must publish the same shared revision.
739
+ const commandPackagePlatforms = new Map();
740
+ for (const { pluginId, plugin, target, scope } of preparedPlacements) {
741
+ if (target === 'generic' || !plugin.manifest.command?.platforms.includes(target)
742
+ || activationOnlyTargets.some((entry) => entry.pluginId === pluginId && entry.platform === target && entry.scope === scope))
743
+ continue;
744
+ const platforms = commandPackagePlatforms.get(pluginId) ?? [];
745
+ if (!platforms.includes(target))
746
+ platforms.push(target);
747
+ commandPackagePlatforms.set(pluginId, platforms);
748
+ }
749
+ runtime = { ...runtime, commandPackagePlatforms, retainCommandPackages: command === 'uninstall' };
750
+ plan.runtime = runtime;
751
+ for (const currentScope of snapshot.context.scopes) {
752
+ const prepareGroup = async (groupTargets) => {
753
+ const inheritedPortableProviderIds = currentScope === 'user' && groupTargets.includes('generic')
754
+ ? [...inheritedScripts].filter((item) => item.target === 'generic').map((item) => item.pluginId) : [];
755
+ const placements = preparedPlacements.filter((item) => item.scope === currentScope && groupTargets.includes(item.target));
756
+ if (!placements.length)
757
+ return;
758
+ const sourceDemand = currentScope === 'project' ? snapshot.project : snapshot.user;
759
+ const childPlacements = [
760
+ ...demand.placements.filter((item) => item.scope === currentScope && groupTargets.includes(item.target)),
761
+ ...placements,
762
+ ];
763
+ const userProviders = demand.placements.filter((item) => item.scope === 'user' && groupTargets.includes(item.target)
764
+ && !childPlacements.some((project) => project.scope === 'project' && project.pluginId === item.pluginId && project.target === item.target));
765
+ const childDemand = { ...sourceDemand,
766
+ targetRequirements: childPlacements.map((item) => ({ pluginId: item.pluginId, target: item.target })),
767
+ userProviders: Object.fromEntries(groupTargets.map((target) => [target, userProviders
768
+ .filter((item) => item.target === target).map((item) => item.pluginId)])),
769
+ roots: [...new Map(childPlacements.map((item) => [item.pluginId, { pluginId: item.pluginId, sourceId: item.plugin.sourceId,
770
+ sourceState: 'ready', blockers: [], plugin: item.plugin }])).values()] };
771
+ const child = await prepareScopedRecovery(command === 'reinstall' ? 'reinstall' : 'sync', [...new Set(placements.map((item) => item.pluginId))], { ...options, scope: currentScope, targets: groupTargets, all: false,
772
+ sharedReferenceView, inheritedPortableProviderIds,
773
+ cwd: snapshot.context.projectRoot ?? options.cwd, demandOverride: childDemand,
774
+ exactTargets: placements.map((item) => ({ pluginId: item.pluginId, agent: item.target })),
775
+ nativeActivationOnlyTargets: activationOnlyTargets.filter((item) => item.scope === currentScope
776
+ && placements.some((placement) => placement.pluginId === item.pluginId && placement.target === item.platform)),
777
+ nativePlannedRetirements: command === 'uninstall' && currentScope === 'project'
778
+ ? placements.filter((item) => item.target === 'codex'
779
+ && currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId && owned.agent === item.target && owned.scope === 'user')
780
+ && !demand.placements.some((provider) => provider.pluginId === item.pluginId && provider.target === item.target && provider.scope === 'user'))
781
+ .map((item) => ({ pluginId: item.pluginId, platform: 'codex', scope: 'user' })) : [],
782
+ excludedPluginIds: currentScope === 'project' ? userProviders.map((item) => item.pluginId) : [],
783
+ dependencyScopeOverrides: currentScope === 'project'
784
+ ? userProviders.filter((provider) => provider.target !== 'generic'
785
+ && !placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.target))
786
+ .map((item) => ({ pluginId: item.pluginId, platform: item.target, scope: 'user' })) : [],
787
+ }, batch && groupTargets[0] !== 'generic'
788
+ ? { ...runtime, batchInstallPlatform: groupTargets[0] } : runtime, { catalogReadScope, portableGenerations, portableRenderResults, nativeObservationBatch: batch || children.length === 0 ? nativeObservationBatch : undefined });
789
+ // Track contexts as soon as acquired, including a sibling that finishes after cancellation.
790
+ children.push(child);
791
+ // Synthetic roots are only an execution projection, never persisted Intent.
792
+ child.originalIntent = observationEvidence(sourceDemand.intent);
793
+ if (options.existingOnly) {
794
+ const observed = await readScopedRecoveryStatus({ ...options, catalogReadScope, nativeCliRunner: runtime.nativeCliRunner, codexObservationSession: runtime.codexObservationSession, scope: currentScope,
795
+ cwd: snapshot.context.projectRoot ?? options.cwd, demandOverride: childDemand, targets: groupTargets });
796
+ for (const item of child.receipt.targetResults) {
797
+ if (!observed.existingTargets?.some((existing) => existing.pluginId === item.pluginId && existing.agent === item.agent && existing.scope === currentScope)) {
798
+ item.blockers.push(diagnostic('configApplyRequiresExistingOutput', '输出缺失或不可确认,请先运行 sync。'));
799
+ }
800
+ }
801
+ }
802
+ return child;
803
+ };
804
+ if (batch) {
805
+ const start = children.length;
806
+ const ordered = await mapInstallReads(targetGroups, prepareGroup, { signal: options.signal });
807
+ children.splice(start, children.length - start, ...ordered.filter((child) => child !== undefined));
808
+ }
809
+ else
810
+ for (const groupTargets of targetGroups)
811
+ await prepareGroup(groupTargets);
812
+ }
813
+ if (hasSelectedScripts && (batch || command === 'reinstall')) {
814
+ const projectPortable = children.find((child) => child.options.scope === 'project' && child.portableGroups.length);
815
+ const consumers = (projectPortable?.portableGroups ?? []).map((group) => ({ pluginId: group.options.selector,
816
+ providers: [...dependencyGraph.providers({ pluginId: group.options.selector, target: 'generic', scope: 'project' })]
817
+ .filter((item) => item.scope === 'user').map((item) => item.pluginId) }));
818
+ const required = [...new Set(consumers.flatMap((item) => item.providers))];
819
+ if (projectPortable && required.length) {
820
+ const userPortable = children.find((child) => child.options.scope === 'user' && child.options.targets?.includes('generic'));
821
+ const reviewed = new Map([...(userPortable?.portableProtectionGroups ?? []), ...(userPortable?.portableGroups ?? [])]
822
+ .map((group) => [group.options.selector, group]));
823
+ const providerContext = userPortable?.context ?? (portableUserContext = await createScopeContext({ ...options, scope: 'user' }));
824
+ // First Project install can reuse a healthy User provider without creating a User execution row.
825
+ await mapInstallReads(required.filter((id) => !reviewed.has(id)), async (selector) => {
826
+ const provider = await preparePortableRecovery({ scope: 'user', context: providerContext, selector, agents: ['generic'],
827
+ cliVersion: options.cliVersion, catalogOperationContext: snapshot.user.catalogOperationContext,
828
+ signal: options.signal }, catalogReadScope, portableGenerations, portableRenderResults);
829
+ delete provider.options.signal;
830
+ reviewed.set(selector, provider);
831
+ }, { signal: options.signal });
832
+ const checks = new Map();
833
+ for (const consumer of consumers)
834
+ if (consumer.providers.length) {
835
+ checks.set(consumer.pluginId, consumer.providers.map((id) => reviewed.get(id)));
836
+ }
837
+ projectPortable.options.portableProviderChecks = checks;
838
+ }
839
+ }
840
+ if (batch)
841
+ for (const currentScope of snapshot.context.scopes) {
842
+ const scoped = children.filter((child) => child.options.scope === currentScope);
843
+ if (scoped.length < 2)
844
+ continue;
845
+ const first = scoped[0];
846
+ await checkFootprints({ ...first, changes: [],
847
+ nativeGroups: scoped.flatMap((child) => child.nativeGroups),
848
+ portableGroups: scoped.flatMap((child) => child.portableGroups),
849
+ receipt: { ...first.receipt, targetResults: scoped.flatMap((child) => child.receipt.targetResults) },
850
+ });
851
+ }
852
+ const portableCandidates = children.flatMap((child) => child.portableGroups.flatMap((prepared) => prepared.targets
853
+ .filter((target) => target.disposition !== 'remove')
854
+ .map((target) => ({ child, prepared, target }))));
855
+ for (const [index, left] of portableCandidates.entries())
856
+ for (const right of portableCandidates.slice(index + 1)) {
857
+ if (left.child.options.scope === right.child.options.scope || left.target.agent !== right.target.agent
858
+ || left.target.skill !== right.target.skill)
859
+ continue;
860
+ if (left.target.providerPluginId === right.target.providerPluginId
861
+ && left.prepared.logicalIdentity !== '' && left.prepared.logicalIdentity === right.prepared.logicalIdentity
862
+ && left.target.physicalPath !== right.target.physicalPath
863
+ && [left, right].every((item) => item.target.observation === 'absent' || item.target.ownership === 'aw'))
864
+ continue;
865
+ const conflict = diagnostic('crossScopeSkillCollision', `${left.target.providerPluginId}@${left.child.options.scope} (${left.target.physicalPath}) 与 ${right.target.providerPluginId}@${right.child.options.scope} (${right.target.physicalPath}) 占用同一 Agent Skill 名。`);
866
+ for (const item of [left, right]) {
867
+ item.child.receipt.targetResults.find((target) => target.pluginId === item.prepared.options.selector && target.agent === item.target.agent)?.blockers.push(conflict);
868
+ }
869
+ plan.receipt.blockers.push(conflict);
870
+ }
871
+ // Retire this removal's orphaned dependencies, explicit exits and provider switches.
872
+ const requiredNativeActivation = (item) => {
873
+ const backend = item.backend;
874
+ const scopedExtensions = (backend?.live?.components ?? backend?.components ?? []).some((component) => component.kind === 'ownership' && component.key !== 'native'
875
+ && !component.key.startsWith('activation-') && !component.key.startsWith('marketplace-')
876
+ && ['present', 'partial'].includes(component.state));
877
+ if (item.scope !== 'project' || !item.agent || !['codex', 'claude', 'copilot'].includes(item.agent))
878
+ return false;
879
+ return demand.placements.some((placement) => {
880
+ if (placement.pluginId !== item.pluginId || placement.target !== item.agent)
881
+ return false;
882
+ if (item.agent === 'codex' && scopedExtensions) {
883
+ const surface = analyzeCodexSurface(placement.plugin.manifest);
884
+ if (surface.extensionKinds.length > 0 && surface.components.every((component) => !component.scopes.includes('project') || component.scopes.includes('user')))
885
+ return false;
886
+ }
887
+ return placement.contributions.some((contribution) => contribution.scope === 'project');
888
+ });
889
+ };
890
+ for (const candidate of portableCandidates)
891
+ for (const installed of currentStatus.extraObserved) {
892
+ const backend = installed.backend;
893
+ if (installed.scope === candidate.child.options.scope || installed.agent !== candidate.target.agent
894
+ || backend?.skill !== candidate.target.skill)
895
+ continue;
896
+ if (installed.pluginId === candidate.target.providerPluginId && backend.logicalIdentity === candidate.prepared.logicalIdentity)
897
+ continue;
898
+ const conflict = diagnostic('crossScopeSkillCollision', `${candidate.target.providerPluginId}@${candidate.child.options.scope} 与 ${installed.pluginId}@${installed.scope} 的 Skill ${candidate.target.skill} 来源不兼容。`);
899
+ candidate.child.receipt.targetResults.find((target) => target.pluginId === candidate.prepared.options.selector && target.agent === candidate.target.agent)?.blockers.push(conflict);
900
+ plan.receipt.blockers.push(conflict);
901
+ }
902
+ const retire = currentStatus.extraObserved.filter((item) => item.agent !== null && !requiredNativeActivation(item) && (options.retireUnselectedTargets && (!snapshot.preferences.targets.includes(item.agent)
903
+ || snapshot.preferences.exclusions.some((entry) => entry.plugin === item.pluginId && entry.target === item.agent))
904
+ || command === 'uninstall' && explicitlyRemoves(item)
905
+ || selected.some((placement) => canReuseProviderAcrossScopes(placement.target)
906
+ && placement.pluginId === item.pluginId && placement.target === item.agent && placement.scope !== item.scope
907
+ && (item.delivery?.kind !== 'agent-skills' || item.backend?.logicalIdentity === placement.plugin.catalogLogicalIdentity))));
908
+ if (scope === 'project')
909
+ for (const provider of currentStatus.projectSkillProviders ?? []) {
910
+ if (provider.target === 'generic' || provider.projectCopy !== 'owned' || !selected.some((placement) => placement.pluginId === provider.pluginId
911
+ && placement.target === provider.target && placement.scope === 'user'
912
+ && selectedContributions.get(placement)?.some((entry) => entry.scope === 'project')))
913
+ continue;
914
+ const position = { pluginId: provider.pluginId, agent: provider.target, scope: 'project' };
915
+ if (ownsOutput(position)) {
916
+ joint.providerRetirements.add(targetKey(position));
917
+ retire.push({ ...position, delivery: { kind: 'native', platform: provider.target }, observation: 'verified' });
918
+ }
919
+ }
920
+ for (const item of currentStatus.observedTargets ?? []) {
921
+ if (ownsOutput(item) && !requiredNativeActivation(item) && selected.some((placement) => (canReuseProviderAcrossScopes(placement.target)
922
+ || command === 'uninstall' && item.scope === scope && previousUserProvided(placement.pluginId, placement.target))
923
+ && placement.pluginId === item.pluginId
924
+ && placement.target === item.agent && placement.scope !== item.scope)
925
+ && !demand.placements.some((placement) => placement.pluginId === item.pluginId
926
+ && placement.target === item.agent && placement.scope === item.scope)) {
927
+ retire.push(item);
928
+ if (item.agent && !canReuseProviderAcrossScopes(item.agent))
929
+ joint.providerRetirements.add(targetKey(item));
930
+ }
931
+ }
932
+ // A removed declaration is still present in the observed snapshot, so include its exact old outputs.
933
+ if (command === 'uninstall')
934
+ for (const item of [
935
+ ...(currentStatus.observedTargets ?? []), ...currentStatus.extraObserved,
936
+ ]) {
937
+ const automatic = automaticRetirements.some((candidate) => candidate.pluginId === item.pluginId
938
+ && candidate.target === item.agent && candidate.scope === item.scope);
939
+ if (!automatic && !explicitlyRemoves(item)
940
+ || !ownsOutput(item) || !targets.includes(item.agent)
941
+ || !options.force && requiredNativeActivation(item)
942
+ || !options.force && demand.placements.some((placement) => placement.pluginId === item.pluginId
943
+ && placement.target === item.agent && placement.scope === item.scope))
944
+ continue;
945
+ retire.push(item);
946
+ }
947
+ const deploymentBlocked = children.some((child) => child.blockExecution
948
+ || child.receipt.targetResults.some((item) => item.blockers.length));
949
+ if (!plan.blockExecution && !deploymentBlocked) {
950
+ const cleanups = [];
951
+ const pendingRetirements = [...new Map(retire.map((entry) => [`${entry.pluginId}\0${entry.agent}\0${entry.scope}`, entry])).values()];
952
+ const orderedRetirements = [];
953
+ while (pendingRetirements.length) {
954
+ const ready = pendingRetirements.findIndex((candidate) => !pendingRetirements.some((consumer) => consumer !== candidate && consumer.agent === candidate.agent
955
+ && dependencies(consumer.pluginId)?.includes(candidate.pluginId)));
956
+ if (ready < 0)
957
+ throw new Error('dependencyGraphInvalid');
958
+ orderedRetirements.push(...pendingRetirements.splice(ready, 1));
959
+ }
960
+ for (const item of orderedRetirements) {
961
+ if (!item.agent)
962
+ continue;
963
+ dependencies(item.pluginId);
964
+ const cleanupDemand = item.scope === 'project' ? { ...snapshot.project,
965
+ userProviders: Object.fromEntries((snapshot.preferences?.targets ?? []).map((target) => [target,
966
+ demand.placements.filter((placement) => placement.scope === 'user' && placement.target === target)
967
+ .map((placement) => placement.pluginId)])), } : snapshot.user;
968
+ const automatic = automaticRetirements.some((candidate) => candidate.pluginId === item.pluginId
969
+ && candidate.target === item.agent && candidate.scope === item.scope);
970
+ // The scoped child must remain cleanup: its declaration and dependency ordering
971
+ // are owned by the joint remove. Only its exact, current Active native target
972
+ // may use normal removal rather than outputs-only package preservation.
973
+ const activePlugin = original.plugins.find((plugin) => plugin.pluginId === item.pluginId);
974
+ const ordinaryNativeRemoval = command === 'uninstall' && item.agent !== 'generic'
975
+ && hasSharedUserPackage(item.agent) && targets.includes(item.agent) && ownsOutput(item)
976
+ && (explicitlyRemoves(item) || automatic) && !joint.providerRetirements.has(targetKey({ ...item, agent: item.agent }))
977
+ && activePlugin && original.catalogOperationContext
978
+ ? { target: { pluginId: item.pluginId, platform: item.agent, scope: item.scope },
979
+ catalog: selectCatalogOperationContext(original.catalogOperationContext, [activePlugin.sourceId]) }
980
+ : undefined;
981
+ const cleanup = await prepareScopedRecovery('cleanup', [item.pluginId], { ...options,
982
+ ordinaryNativeRemoval, sharedReferenceView,
983
+ scope: item.scope, cwd: snapshot.context.projectRoot ?? options.cwd, targets: [item.agent], all: false,
984
+ // Ordinary remove's force bypasses dependencies, never ownership checks.
985
+ force: false, exactTargets: undefined, demandOverride: cleanupDemand }, runtime, { catalogReadScope });
986
+ if (automatic) {
987
+ for (const target of cleanup.receipt.targetResults) {
988
+ target.relation = 'dependency';
989
+ target.requiredBy = previousDemand.placements.find((candidate) => candidate.pluginId === item.pluginId
990
+ && candidate.target === item.agent && candidate.scope === item.scope)?.contributions.map((entry) => entry.root) ?? [];
991
+ }
992
+ }
993
+ cleanups.push(cleanup);
994
+ }
995
+ children.unshift(...cleanups);
996
+ }
997
+ if ((batch || command === 'reinstall' && options.exactTargets) && !children.some((child) => child.command === 'cleanup')) {
998
+ const order = new Map();
999
+ if (options.exactTargets) {
1000
+ // The caller ordered exact pairs. Insert their actual providers once, before the consuming pair.
1001
+ for (const exact of options.exactTargets) {
1002
+ for (const item of selected.filter((placement) => selectedContributions.get(placement)?.some((contribution) => matchesExactContribution(placement, contribution, exact, reaches)))) {
1003
+ const key = targetKey({ pluginId: item.pluginId, agent: item.target, scope: item.scope });
1004
+ if (!order.has(key))
1005
+ order.set(key, order.size);
1006
+ }
1007
+ const key = targetKey({ ...exact, scope: exact.scope ?? scope });
1008
+ if (!order.has(key))
1009
+ order.set(key, order.size);
1010
+ }
1011
+ }
1012
+ else {
1013
+ // Ordinary batches list each scope's Native roots across clients, then Portable roots.
1014
+ const deliveries = [nativeTargets, targets.filter((agent) => agent === 'generic')];
1015
+ for (const scope of snapshot.context.scopes)
1016
+ for (const agents of deliveries) {
1017
+ const roots = new Set(selected.filter((item) => item.scope === scope && agents.includes(item.target)).map((item) => item.pluginId));
1018
+ for (const root of unplacedRoots)
1019
+ if (root.scope === scope && agents.includes(root.target)
1020
+ && (root.state === 'blocked' || root.state === 'unknown'))
1021
+ roots.add(root.pluginId);
1022
+ for (const pluginId of roots)
1023
+ for (const agent of agents)
1024
+ order.set(targetKey({ pluginId, agent, scope }), order.size);
1025
+ }
1026
+ }
1027
+ joint.targetOrder = order;
1028
+ }
1029
+ // The first preview already seals every target in its native group. A lone
1030
+ // Copilot ensure group has no later sibling contribution to refresh here.
1031
+ const onlyChild = children.length === 1 ? children[0] : undefined;
1032
+ const onlyGroup = onlyChild?.nativeGroups.length === 1 ? onlyChild.nativeGroups[0] : undefined;
1033
+ const singleNativePreviewComplete = !plan.blockExecution && onlyChild !== undefined && !onlyChild.blockExecution
1034
+ && onlyChild.command === 'sync' && onlyGroup?.platform === 'copilot'
1035
+ && onlyGroup.command === 'sync'
1036
+ && onlyGroup.preview.operationPlan !== undefined
1037
+ && (onlyGroup.preview.operationPlan.deploymentPlans?.length ?? 0) > 0
1038
+ && onlyGroup.preview.operationPlan.deploymentPlans.every((deployment) => deployment.operation === 'ensure')
1039
+ && onlyChild.receipt.targetResults.length > 0
1040
+ && onlyChild.receipt.targetResults.every((target) => target.blockers.length === 0)
1041
+ && onlyChild.portableGroups.length === 0 && onlyChild.portableProtectionGroups.length === 0
1042
+ && onlyChild.portableResidues.length === 0;
1043
+ // Other scopes and groups can change shared descriptors, preApply actions
1044
+ // or retained packages. Refresh those previews before exposing Review.
1045
+ if (!singleNativePreviewComplete) {
1046
+ if (batch) {
1047
+ const nativeChildren = children.filter((child) => child.nativeGroups.length);
1048
+ const platforms = [...new Set(nativeChildren.map((child) => child.runtime.batchInstallPlatform))];
1049
+ await mapInstallReads(platforms, async (platform) => {
1050
+ const scoped = nativeChildren.filter((item) => item.runtime.batchInstallPlatform === platform);
1051
+ // One complete ensure plan owns this platform session. Its initial preview already sealed
1052
+ // every candidate; only another source or scope can contribute a later shared descriptor.
1053
+ const only = scoped.length === 1 ? scoped[0] : undefined;
1054
+ const preview = only?.nativeGroups.length === 1 ? only.nativeGroups[0].preview : undefined;
1055
+ if (platform && only && !only.blockExecution && only.receipt.targetResults.every((target) => target.blockers.length === 0)
1056
+ && preview?.operationPlan?.deploymentPlans?.length
1057
+ && preview.operationPlan.deploymentPlans.every((deployment) => deployment.operation === 'ensure'))
1058
+ return;
1059
+ for (const child of scoped)
1060
+ await refreshRecoveryNativePreviews(child, catalogReadScope, options.signal);
1061
+ }, { signal: options.signal });
1062
+ }
1063
+ else
1064
+ for (const child of children)
1065
+ await refreshRecoveryNativePreviews(child, catalogReadScope, options.signal);
1066
+ }
1067
+ const preparedNativeTargets = children.flatMap((child) => child.receipt.targetResults)
1068
+ .filter((target) => target.delivery?.kind === 'native');
1069
+ const failedProviders = new Map(preparedNativeTargets.filter((target) => target.blockers.length > 0)
1070
+ .map((target) => [targetKey(target), target]));
1071
+ if (failedProviders.size)
1072
+ for (const target of preparedNativeTargets) {
1073
+ for (const dependency of dependencyGraph.providers({ pluginId: target.pluginId, target: target.agent, scope: target.scope })) {
1074
+ const provider = failedProviders.get(targetKey({ ...dependency, agent: dependency.target }));
1075
+ if (!provider)
1076
+ continue;
1077
+ for (const blocker of provider.blockers)
1078
+ if (!target.blockers.some((entry) => entry.code === blocker.code && entry.pluginId === provider.pluginId)) {
1079
+ target.blockers.push({ ...blocker, pluginId: provider.pluginId });
1080
+ }
1081
+ }
1082
+ }
1083
+ if ((batch || command === 'reinstall') && !options.existingOnly) {
1084
+ const eligible = children.filter((child) => child.command !== 'cleanup').flatMap((child) => child.receipt.targetResults.filter((target) => target.agent === 'generic' && target.delivery?.kind === 'agent-skills'
1085
+ && !target.blockers.length));
1086
+ const eligiblePositions = new Set(eligible.map(targetKey));
1087
+ const candidates = [...new Map(preparedPlacements.filter((item) => item.target === 'generic'
1088
+ && !item.plugin.manifest.command && eligiblePositions.has(targetKey({ ...item, agent: item.target })))
1089
+ .map((item) => [item.pluginId, item.plugin])).entries()];
1090
+ const reviewCwd = snapshot.context.projectRoot ?? context.executionCwd;
1091
+ const prepared = await mapInstallReads(candidates, async ([pluginId, plugin]) => {
1092
+ try {
1093
+ return await preparePortableCommandWithdrawal(plugin, reviewCwd, context.env);
1094
+ }
1095
+ catch (error) {
1096
+ if (recoveryInterruptionCode(error, options.signal))
1097
+ throw error;
1098
+ for (const target of eligible.filter((item) => item.pluginId === pluginId)) {
1099
+ target.blockers.push(diagnostic(errorCode(error, 'commandPackagePreparationFailed')));
1100
+ }
1101
+ }
1102
+ }, { signal: options.signal });
1103
+ plan.portableCommandWithdrawals = prepared.filter((entry) => entry !== undefined);
1104
+ }
1105
+ finalizePreparedPlatformRebuildSession(runtime.preparedArtifactRenderResults);
1106
+ plan.sourceRefreshes = [...new Map(children.flatMap((child) => child.sourceRefreshes).map((item) => [item.sourceId, item])).values()];
1107
+ plan.sourceRefreshFailures = [...new Map(children.flatMap((child) => child.sourceRefreshFailures).map((item) => [item.sourceId, item])).values()];
1108
+ plan.changes.push(...children.flatMap((child) => child.changes));
1109
+ plan.warnings.push(...children.flatMap((child) => child.warnings));
1110
+ plan.plannedImpact.outputs = children.some((child) => child.plannedImpact.outputs);
1111
+ plan.receipt = mergeReceipts(plan, children.map((child) => child.receipt));
1112
+ if (isInstallConfigBlocked(plan.receipt)) {
1113
+ // Do not commit proposed requirements (or activate a first-install source)
1114
+ // when no selected deployment can proceed until configuration is repaired.
1115
+ plan.blockExecution = true;
1116
+ plan.plannedImpact.declaration = false;
1117
+ plan.plannedImpact.outputs = false;
1118
+ plan.changes = [];
1119
+ }
1120
+ if (retriesFromRequestedRoots(plan.receipt) && plan.receipt.remainingTargets.length)
1121
+ useDeclaredRetryRoots(plan.receipt);
1122
+ const observedManager = children.flatMap((child) => child.nativeGroups)
1123
+ .map((group) => group.preview.codexManagerPreview)
1124
+ .find((entry) => entry?.state === 'system');
1125
+ if (observedManager?.state === 'system') {
1126
+ runtime.codexObservationSession?.setManager(observedManager.manager);
1127
+ }
1128
+ return plan;
1129
+ }
1130
+ catch (error) {
1131
+ await context.dispose();
1132
+ throw error;
1133
+ }
1134
+ }
1135
+ export async function executeJointRecovery(plan, execution) {
1136
+ const joint = plan.joint;
1137
+ const performanceRuntime = { ...plan.runtime, ...execution.runtime };
1138
+ if (isInstallBatch(plan.command)) {
1139
+ const override = execution.runtime?.nativeCliRunner;
1140
+ if (!override || override === joint.originalNativeRunner || override === plan.runtime.nativeCliRunner) {
1141
+ performanceRuntime.nativeCliRunner = plan.runtime.nativeCliRunner;
1142
+ joint.bindExecutionSignal?.(performanceRuntime.signal);
1143
+ }
1144
+ else {
1145
+ performanceRuntime.nativeCliRunner = limitInstallNativeRunner(override);
1146
+ performanceRuntime.codexObservationSession = execution.runtime?.codexObservationSession;
1147
+ }
1148
+ }
1149
+ let lockedPlan;
1150
+ let completedReceipt;
1151
+ let lockWaitStartedAt;
1152
+ try {
1153
+ if (plan.portableCommandWithdrawals?.length && (execution.yes ?? plan.options.yes) !== true) {
1154
+ return blockedBeforeDeployment(plan, diagnostic('confirmationRequired'));
1155
+ }
1156
+ if (plan.sourceRefreshes.length) {
1157
+ plan.receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
1158
+ const receipt = mergeReceipts(plan, joint.children.map((child) => child.receipt));
1159
+ if (retriesFromRequestedRoots(receipt))
1160
+ useDeclaredRetryRoots(receipt);
1161
+ return receipt;
1162
+ }
1163
+ lockWaitStartedAt = performance.now();
1164
+ await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'start', lockWaitStartedAt);
1165
+ return await withAwHomeMutationLock({ env: plan.options.env, signal: performanceRuntime.signal, token: execution.runtime?.awHomeMutationToken ?? plan.runtime.awHomeMutationToken,
1166
+ onContention: (status) => {
1167
+ if (performanceRuntime?.directCli && performanceRuntime.reporter)
1168
+ reportCliPhase(performanceRuntime.reporter, 'wait-lock', status);
1169
+ },
1170
+ action: async (token) => {
1171
+ const acquiredAt = lockWaitStartedAt;
1172
+ lockWaitStartedAt = undefined;
1173
+ await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'success', acquiredAt);
1174
+ let preparation;
1175
+ try {
1176
+ preparation = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.demand', () => readJointPreparation({ ...joint.originalOptions, signal: performanceRuntime.signal }, true));
1177
+ }
1178
+ catch (error) {
1179
+ // A control-file failure during rebind is a known pre-write stop, not
1180
+ // an uncertain execution failure. Keep the original reviewed targets.
1181
+ if (!(error instanceof CatalogGenerationError))
1182
+ throw error;
1183
+ return blockedBeforeDeployment(plan, catalogRecheckDiagnostic(error, performanceRuntime.signal));
1184
+ }
1185
+ const actual = preparation.snapshot;
1186
+ const currentIntent = (plan.options.scope === 'project' ? actual.project : actual.user).intent;
1187
+ plan.receipt.intent = intentReceipt(currentIntent);
1188
+ if (currentIntent.state !== 'valid' && currentIntent.state !== 'absent') {
1189
+ plan.receipt.blockers.push(describeStrongStateProblem({ kind: 'intent', scope: plan.options.scope,
1190
+ state: currentIntent.state, filePath: await resolveIntentPath(plan.options) }));
1191
+ }
1192
+ if (snapshotEvidence(actual) !== joint.evidence)
1193
+ return blockedBeforeDeployment(plan);
1194
+ if (plan.blockExecution)
1195
+ return plan.receipt;
1196
+ // Recheck all backend candidates before any strong-state or output write.
1197
+ (execution.runtime?.codexObservationSession ?? plan.runtime.codexObservationSession)?.invalidate();
1198
+ const checked = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.recheck', () => prepareJointRecovery(plan.command, joint.selectors, preparation.options, { ...performanceRuntime, awHomeMutationToken: token }, preparation));
1199
+ const stable = !checked.blockExecution && JSON.stringify(describeRecoveryPlan(plan)) === JSON.stringify(describeRecoveryPlan(checked));
1200
+ lockedPlan = checked;
1201
+ const parallel = isInstallBatch(plan.command) && !joint.pendingUserSkills.length && !joint.children.some((child) => child.command === 'cleanup');
1202
+ const children = parallel ? checked.joint.children : joint.children;
1203
+ if (!stable)
1204
+ return blockedBeforeDeployment(plan);
1205
+ performanceRuntime.signal?.throwIfAborted();
1206
+ if (joint.originalOptions.preferences) {
1207
+ const saved = await writePreferences({ ...plan.options, scope: 'user', token }, joint.originalOptions.preferences);
1208
+ plan.receipt.preferencesChanged = saved.changed;
1209
+ const committed = await observePreferences({ ...plan.options, scope: 'user' });
1210
+ plan.receipt.selection.preferences = committed.state;
1211
+ if (committed.state !== 'valid') {
1212
+ return blockedBeforeDeployment(plan, diagnostic(committed.state === 'invalid'
1213
+ ? 'deploymentPreferencesInvalid' : 'deploymentPreferencesUnavailable'), 'preferences');
1214
+ }
1215
+ if (JSON.stringify(committed.value) !== JSON.stringify(saved.value)) {
1216
+ return blockedBeforeDeployment(plan, diagnostic('operationReviewStale'), 'preferences');
1217
+ }
1218
+ for (const child of children) {
1219
+ child.demand.preferences = committed;
1220
+ if (child.options.demandOverride)
1221
+ child.options.demandOverride.preferences = committed;
1222
+ child.preferencesEvidence = observationEvidence(committed);
1223
+ }
1224
+ }
1225
+ if (joint.declaration) {
1226
+ const saved = await writeIntent({ ...plan.options, scope: joint.declaration.scope, token }, joint.declaration.value);
1227
+ plan.receipt.declarationChanged = saved.changed;
1228
+ const committed = await observeIntent({ ...plan.options, scope: joint.declaration.scope });
1229
+ plan.receipt.intent = intentReceipt(committed);
1230
+ if (committed.state !== 'valid') {
1231
+ return blockedBeforeDeployment(plan, committed.state === 'absent'
1232
+ ? diagnostic('pluginIntentStateUnavailable', '保存后未找到插件声明,未执行输出变更。')
1233
+ : describeStrongStateProblem({ kind: 'intent', scope: joint.declaration.scope,
1234
+ state: committed.state, filePath: await resolveIntentPath({ ...plan.options, scope: joint.declaration.scope }) }), 'intent');
1235
+ }
1236
+ if (calculateIntentDigest(committed.value) !== calculateIntentDigest(saved.value)) {
1237
+ return blockedBeforeDeployment(plan, diagnostic('operationReviewStale'), 'intent');
1238
+ }
1239
+ }
1240
+ const results = joint.children.filter((child) => child.blockExecution
1241
+ && child.receipt.requestedTargets.length === 0).map((child) => child.receipt);
1242
+ const failedProviders = new Set();
1243
+ const failedPackages = new Set();
1244
+ const failedNodes = new Set();
1245
+ const packageResults = [];
1246
+ const runtime = { ...performanceRuntime, awHomeMutationToken: token,
1247
+ commandPackagePlatforms: checked.runtime.commandPackagePlatforms,
1248
+ retainCommandPackages: checked.runtime.retainCommandPackages };
1249
+ runtime.preApplyExecutionCache ??= new Map();
1250
+ runtime.managedCommandProducerCache ??= new Map();
1251
+ let interrupted;
1252
+ if (parallel) {
1253
+ const installed = await executeJointInstall({ children, demand: checked.joint.demand, runtime, token,
1254
+ yes: execution.yes ?? plan.options.yes, existingOnly: joint.originalOptions.existingOnly });
1255
+ interrupted = installed.interruption;
1256
+ results.push(...installed.receipts);
1257
+ packageResults.push(...installed.commands);
1258
+ plan.receipt.blockers.push(...installed.blockers);
1259
+ }
1260
+ else {
1261
+ try {
1262
+ const packages = runtime.configApplyPackages;
1263
+ const dependencyGraph = indexJointDependencies(joint.demand);
1264
+ const readCurrentProviders = (plugins, targets) => {
1265
+ const { cwd, env, cliVersion } = joint.originalOptions;
1266
+ return readRecoveryStatus({ cwd, env, cliVersion, context: joint.snapshot.context.context,
1267
+ expectedProjectRoot: joint.snapshot.context.projectRoot, plugins: [...new Set(plugins)], targets: [...new Set(targets)],
1268
+ nativeCliRunner: runtime.nativeCliRunner, signal: runtime.signal,
1269
+ catalogReadScope: new CatalogPreparationReadScope({ env, signal: runtime.signal }) });
1270
+ };
1271
+ const portableProgress = { completed: [], failed: [] };
1272
+ const failedCleanups = [];
1273
+ const executeChild = async (child, pluginIds, agent) => {
1274
+ runtime.signal?.throwIfAborted();
1275
+ const childRuntime = { ...runtime, batchInstallPlatform: child.runtime.batchInstallPlatform };
1276
+ const currentIntent = await observeIntent(child.options);
1277
+ if (!joint.originalOptions.existingOnly)
1278
+ child.demand.intent = currentIntent;
1279
+ const catalogReadScope = new CatalogPreparationReadScope({ env: child.context.env, signal: runtime.signal });
1280
+ const reviewedCatalog = child.demand.catalogOperationContext;
1281
+ let currentCatalog = reviewedCatalog;
1282
+ if (child.command !== 'cleanup' && reviewedCatalog) {
1283
+ const selected = (pluginId) => typeof pluginIds === 'string' ? pluginId === pluginIds : pluginIds.includes(pluginId);
1284
+ const stopChild = (blocker) => {
1285
+ const result = blockScopedRecoveryBeforeExecution(structuredClone({ ...child.receipt,
1286
+ requestedRoots: child.receipt.requestedRoots.filter(selected),
1287
+ targetResults: child.receipt.targetResults.filter((target) => selected(target.pluginId)
1288
+ && (agent !== 'generic' || target.agent === agent)),
1289
+ }), blocker);
1290
+ results.push(result);
1291
+ return result;
1292
+ };
1293
+ // A logical generation digest does not bind requestedRef or resolvedCommit.
1294
+ // Never replace the Review with fresh objects unless the full binding matches.
1295
+ try {
1296
+ const rebound = await catalogReadScope.rebind(reviewedCatalog);
1297
+ if (!catalogOperationBindingsMatch(reviewedCatalog, rebound)) {
1298
+ const unavailable = rebound.catalog.sources.find((source) => source.error
1299
+ && reviewedCatalog.catalog.sources.some((reviewed) => reviewed.sourceId === source.sourceId && reviewed.resolution));
1300
+ return stopChild(unavailable
1301
+ ? catalogRecheckDiagnostic(unavailable.error, runtime.signal, unavailable.sourceId)
1302
+ : diagnostic('operationReviewStale'));
1303
+ }
1304
+ currentCatalog = rebound;
1305
+ }
1306
+ catch (error) {
1307
+ return stopChild(catalogRecheckDiagnostic(error, runtime.signal));
1308
+ }
1309
+ }
1310
+ const fresh = await measureRecoveryPerformanceStage(runtime, 'recovery.child.plan', () => prepareScopedRecovery(child.command, typeof pluginIds === 'string' ? [pluginIds] : pluginIds, {
1311
+ ...child.options, signal: runtime.signal,
1312
+ ...(child.command !== 'cleanup' ? {
1313
+ catalogOperationContext: currentCatalog,
1314
+ ...(child.options.demandOverride ? { demandOverride: { ...child.options.demandOverride, catalogOperationContext: currentCatalog } } : {}),
1315
+ } : {}), targets: agent !== 'generic' ? child.options.targets : [agent], all: false,
1316
+ exactTargets: child.options.exactTargets?.filter((target) => (typeof pluginIds === 'string' ? [pluginIds] : pluginIds).includes(target.pluginId)),
1317
+ }, childRuntime, { catalogReadScope }));
1318
+ fresh.originalIntent = observationEvidence(currentIntent);
1319
+ for (const target of fresh.receipt.targetResults) {
1320
+ const reviewed = child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
1321
+ if (reviewed?.relation === 'dependency') {
1322
+ target.relation = 'dependency';
1323
+ target.requiredBy = [...reviewed.requiredBy];
1324
+ }
1325
+ // Native/provider observations are refreshed after preceding nodes.
1326
+ // Keep only joint constraints and an already failed script gate.
1327
+ target.blockers.push(...(reviewed?.blockers ?? []).filter((error) => reviewed?.execution === 'failed'
1328
+ || ['configApplyRequiresExistingOutput', 'crossScopeSkillCollision', 'targetPlacementConflict',
1329
+ 'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed', 'providerSwitchVerificationFailed', 'dependencyStillRequired'].includes(error.code)));
1330
+ if (reviewed?.execution === 'failed') {
1331
+ target.execution = 'failed';
1332
+ if (reviewed.backend)
1333
+ target.backend = reviewed.backend;
1334
+ }
1335
+ if (child.command !== 'cleanup' && failedCleanups.some((failed) => failed.agent === target.agent && (failed.pluginId === target.pluginId || joint.demand.roots.some((root) => root.pluginId === target.pluginId && root.target === target.agent && root.dependencies.includes(failed.pluginId))))) {
1336
+ target.blockers.push(diagnostic('providerSwitchCleanupFailed'));
1337
+ }
1338
+ const dependencies = [...dependencyGraph.providers({ pluginId: target.pluginId, target: target.agent, scope: target.scope })];
1339
+ if (failedPackages.has(`${target.pluginId}\0${target.scope}`) || failedPackages.has(`${target.pluginId}\0user`)
1340
+ || dependencies.some((item) => failedPackages.has(`${item.pluginId}\0${item.scope}`))) {
1341
+ target.blockers.push(diagnostic('commandPackageProviderNotSatisfied'));
1342
+ }
1343
+ const failedDependency = dependencies.find((placement) => failedProviders.has(`${placement.pluginId}\0${placement.target}\0${placement.scope}`));
1344
+ if (failedDependency) {
1345
+ target.blockers.push({ code: target.scope === 'project' && failedDependency.scope === 'user'
1346
+ ? 'userProviderNotSatisfied' : 'dependencyApplyFailed',
1347
+ pluginId: failedDependency.pluginId,
1348
+ message: `依赖提供者 ${failedDependency.pluginId}(${failedDependency.target}/${failedDependency.scope})未完成。` });
1349
+ }
1350
+ }
1351
+ if (child.command !== 'cleanup' && child.options.scope === 'project') {
1352
+ const required = joint.pendingUserSkills.filter((item) => fresh.receipt.targetResults.some((target) => target.agent === item.target && dependencyGraph.reaches(target.pluginId, item.pluginId)));
1353
+ if (required.length) {
1354
+ const verified = await readCurrentProviders(required.map((item) => item.pluginId), required.map((item) => item.target));
1355
+ for (const provider of required) {
1356
+ if (verified.projectSkillProviders?.some((item) => item.pluginId === provider.pluginId && item.target === provider.target
1357
+ && item.sourceIdentity === provider.sourceIdentity && !item.userAbsent && !item.userNeedsRepair && item.projectCopy !== 'blocked'))
1358
+ continue;
1359
+ for (const target of fresh.receipt.targetResults.filter((item) => item.agent === provider.target
1360
+ && dependencyGraph.reaches(item.pluginId, provider.pluginId)))
1361
+ target.blockers.push(diagnostic('userProviderNotSatisfied'));
1362
+ }
1363
+ }
1364
+ }
1365
+ const result = await measureRecoveryPerformanceStage(runtime, 'recovery.child.execute', () => executeScopedRecovery(fresh, { ...execution, runtime: childRuntime,
1366
+ ...(plan.command !== 'uninstall' && child.command !== 'cleanup' ? { portableProgress } : {}) }));
1367
+ if (joint.originalOptions.existingOnly)
1368
+ for (const target of result.targetResults) {
1369
+ if (!target.blockers.some((error) => error.code === 'dependencyInstallFailed'))
1370
+ continue;
1371
+ target.blockers = target.blockers.map((error) => error.code === 'dependencyInstallFailed'
1372
+ ? { ...error, code: 'dependencyApplyFailed', message: '依赖提供者未完成。请检查其执行结果。' }
1373
+ : error);
1374
+ if (target.execution === 'failed')
1375
+ target.execution = 'not-run';
1376
+ }
1377
+ results.push(result);
1378
+ return result;
1379
+ };
1380
+ // Provider changes can remove a working output. Complete the replacement's
1381
+ // authorization and scripts first, sharing the normal execution cache.
1382
+ const cleanups = joint.children.filter((child) => child.command === 'cleanup');
1383
+ const deferred = cleanups.filter((child) => child.receipt.requestedTargets.some((target) => joint.providerRetirements.has(targetKey(target))));
1384
+ const cleanupChildren = cleanups.filter((child) => !deferred.includes(child));
1385
+ const replacementFailures = new Set();
1386
+ for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
1387
+ for (const target of child.receipt.targetResults) {
1388
+ if (replacementFailures.has(`${target.pluginId}\0${target.agent}`)) {
1389
+ target.blockers.push(diagnostic('dependencyApplyFailed'));
1390
+ continue;
1391
+ }
1392
+ if (child.options.nativeActivationOnlyTargets?.some((item) => item.pluginId === target.pluginId
1393
+ && item.platform === target.agent && item.scope === target.scope))
1394
+ continue;
1395
+ if (!cleanupChildren.some((cleanup) => cleanup.receipt.requestedTargets.some((old) => old.pluginId === target.pluginId)))
1396
+ continue;
1397
+ const failure = target.blockers[0]?.code ?? await executeRecoveryPreApply({ ...child,
1398
+ options: { ...child.options, yes: execution.yes ?? plan.options.yes },
1399
+ }, target.pluginId, target.agent, runtime);
1400
+ if (!failure)
1401
+ continue;
1402
+ target.blockers.push(diagnostic(failure));
1403
+ if (failure !== 'preApplyAuthorizationRequired' && failure !== 'nativeToolAuthorizationRequired')
1404
+ target.execution = 'failed';
1405
+ replacementFailures.add(`${target.pluginId}\0${target.agent}`);
1406
+ failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
1407
+ failedNodes.add(`${target.pluginId}\0${target.scope}`);
1408
+ }
1409
+ }
1410
+ // Target exits can replace one Agent with another. Preserve the reviewed
1411
+ // old output when its corresponding replacement cannot run.
1412
+ const clean = async (child, verified = true, onSuccess) => {
1413
+ for (const target of child.receipt.requestedTargets) {
1414
+ if (!verified)
1415
+ child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
1416
+ .blockers.push(diagnostic('providerSwitchVerificationFailed', '替代位置尚未确认就绪,保留原输出。'));
1417
+ if ((plan.command === 'uninstall' || deferred.includes(child)) && failedCleanups.some((failed) => {
1418
+ if (failed.agent !== target.agent)
1419
+ return false;
1420
+ const required = joint.removalDependencies.get(failed.pluginId);
1421
+ return required?.includes(target.pluginId) || required === null
1422
+ && parsePluginId(failed.pluginId).sourceId === parsePluginId(target.pluginId).sourceId;
1423
+ })) {
1424
+ child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
1425
+ .blockers.push(diagnostic('dependencyStillRequired', '依赖者未完成删除,保留其依赖输出。'));
1426
+ }
1427
+ if ([...replacementFailures].some((failed) => failed.startsWith(`${target.pluginId}\0`)
1428
+ && (failed === `${target.pluginId}\0${target.agent}`
1429
+ || !joint.children.some((replacement) => replacement.command !== 'cleanup'
1430
+ && replacement.receipt.requestedTargets.some((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent))))) {
1431
+ child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
1432
+ .blockers.push(diagnostic('providerSwitchPreApplyFailed'));
1433
+ }
1434
+ const result = await executeChild(child, target.pluginId, target.agent);
1435
+ if (!result.ok)
1436
+ failedCleanups.push(...result.requestedTargets);
1437
+ else
1438
+ onSuccess?.(result);
1439
+ }
1440
+ };
1441
+ for (const child of cleanupChildren)
1442
+ await clean(child);
1443
+ const retireVerified = async (oldScope) => {
1444
+ const retiring = deferred.filter((child) => child.options.scope === oldScope);
1445
+ if (!retiring.length)
1446
+ return;
1447
+ const old = retiring.flatMap((child) => child.receipt.requestedTargets);
1448
+ const verified = await readCurrentProviders(old.map((item) => item.pluginId), old.map((item) => item.agent));
1449
+ for (const child of retiring) {
1450
+ const target = child.receipt.requestedTargets[0];
1451
+ const replacement = { ...target, scope: oldScope === 'user' ? 'project' : 'user' };
1452
+ const reviewedSource = joint.demand.placements.find((item) => item.pluginId === replacement.pluginId
1453
+ && item.scope === replacement.scope && item.target === replacement.agent)?.plugin.sourceIdentity;
1454
+ const confirmed = reviewedSource && !failedProviders.has(targetKey(replacement)) && (oldScope === 'project'
1455
+ ? verified.projectSkillProviders?.some((item) => item.pluginId === target.pluginId && item.target === target.agent
1456
+ && item.sourceIdentity === reviewedSource && !item.userAbsent && !item.userNeedsRepair && item.projectCopy === 'owned')
1457
+ : verified.observedTargets?.some((item) => targetKey(item) === targetKey(replacement)
1458
+ && item.observation === 'verified' && item.content === 'satisfied' && !item.blockers.length)
1459
+ && verified.existingTargets?.some((item) => targetKey(item) === targetKey(replacement)
1460
+ && item.nativePackage?.sourceIdentity === reviewedSource && item.nativePackage.skillsReady));
1461
+ await clean(child, Boolean(confirmed), (receipt) => {
1462
+ const projectRoot = joint.snapshot.context.projectRoot;
1463
+ if (!confirmed || !projectRoot || oldScope !== 'project' || target.agent !== 'grok' || !runtime.preparedArtifactRenderResults)
1464
+ return;
1465
+ const project = verified.extraObserved.find((item) => item.pluginId === target.pluginId && item.agent === 'grok' && item.scope === 'project')
1466
+ ?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-directory')?.after;
1467
+ const user = verified.observedTargets?.find((item) => targetKey(item) === targetKey(replacement))
1468
+ ?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-cli')?.after;
1469
+ const backend = receipt.targetResults.find((item) => targetKey(item) === targetKey(target))?.backend;
1470
+ const removed = backend?.command === 'cleanup' && backend.ok ? backend.targetResults.find(({ target: item }) => item.pluginId === target.pluginId && item.platform === 'grok' && item.scope === 'project')?.removed : undefined;
1471
+ const reviewedRemoval = child.nativeGroups.some(({ preview }) => preview.operationPlan?.actions.some((action) => action.kind === 'removeOwnedArtifact' && action.pluginId === target.pluginId && action.platform === 'grok'
1472
+ && action.scope === 'project' && action.path === project?.nativeIdentity?.sourceLocation));
1473
+ if (project && user && reviewedRemoval && removed?.length) {
1474
+ recordPreparedGrokProjectRetirement(runtime.preparedArtifactRenderResults, projectRoot, project, user, removed);
1475
+ }
1476
+ });
1477
+ }
1478
+ };
1479
+ let retiredProjectCopies = false;
1480
+ const nodes = new Map();
1481
+ const nodeFor = (pluginId, scope) => {
1482
+ const key = `${pluginId}\0${scope}`;
1483
+ let node = nodes.get(key);
1484
+ if (!node) {
1485
+ node = { pluginId, scope, targets: [], dependencies: new Set() };
1486
+ nodes.set(key, node);
1487
+ }
1488
+ return node;
1489
+ };
1490
+ for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
1491
+ for (const target of child.receipt.requestedTargets)
1492
+ nodeFor(target.pluginId, target.scope).targets.push({ child, agent: target.agent });
1493
+ }
1494
+ const consumesPackage = (node, target) => !target.blocker && node.targets.some(({ agent }) => agent !== 'generic' && target.platforms.includes(agent));
1495
+ for (const target of packages?.targets ?? []) {
1496
+ const sameScope = nodes.get(`${target.pluginId}\0${target.scope}`);
1497
+ const native = sameScope && consumesPackage(sameScope, target) ? sameScope
1498
+ : [...nodes.values()].find((node) => node.pluginId === target.pluginId && consumesPackage(node, target));
1499
+ const node = native ?? nodeFor(target.pluginId, target.scope);
1500
+ (node.packages ??= []).push(target);
1501
+ }
1502
+ for (const node of nodes.values()) {
1503
+ for (const { agent } of node.targets) {
1504
+ for (const provider of dependencyGraph.directProviders({ pluginId: node.pluginId, target: agent, scope: node.scope })) {
1505
+ node.dependencies.add(`${provider.pluginId}\0${provider.scope}`);
1506
+ }
1507
+ }
1508
+ if (node.scope === 'project' && node.targets.some(({ agent }) => ['codex', 'claude', 'copilot'].includes(agent))
1509
+ && nodes.has(`${node.pluginId}\0user`))
1510
+ node.dependencies.add(`${node.pluginId}\0user`);
1511
+ for (const dependency of node.packages?.flatMap((item) => item.dependencies) ?? []) {
1512
+ for (const provider of nodes.values())
1513
+ if (provider.pluginId === dependency)
1514
+ node.dependencies.add(`${dependency}\0${provider.scope}`);
1515
+ }
1516
+ }
1517
+ const pending = [...nodes.values()].sort((left, right) => left.scope === right.scope
1518
+ ? left.pluginId.localeCompare(right.pluginId) : left.scope === 'user' ? -1 : 1);
1519
+ const executedNativeChildren = new Set();
1520
+ const completedPackages = new Map();
1521
+ const recordPackages = (pluginId, scope, produced) => {
1522
+ const key = `${pluginId}\0${scope}`;
1523
+ completedPackages.set(key, produced);
1524
+ packageResults.push(...produced);
1525
+ if (!produced.every(commandPackageProviderSatisfied)) {
1526
+ failedPackages.add(key);
1527
+ failedNodes.add(key);
1528
+ }
1529
+ return produced;
1530
+ };
1531
+ const applyPackages = async (pluginId, scope) => {
1532
+ const key = `${pluginId}\0${scope}`;
1533
+ const previous = completedPackages.get(key);
1534
+ if (previous)
1535
+ return previous;
1536
+ return recordPackages(pluginId, scope, await packages.execute(pluginId, scope, token));
1537
+ };
1538
+ const blockPackages = (pluginId, scope, code) => completedPackages.get(`${pluginId}\0${scope}`)
1539
+ ?? recordPackages(pluginId, scope, packages?.blocked?.(pluginId, scope, code) ?? []);
1540
+ const nativePackages = (identity) => packages?.targets.filter((target) => target.pluginId === identity.pluginId
1541
+ && target.platforms.includes(identity.platform)
1542
+ && (target.scope === 'user' || target.scope === identity.scope)) ?? [];
1543
+ if (packages)
1544
+ runtime.nativeTargetExecution = {
1545
+ produces: (identity) => nativePackages(identity).length > 0,
1546
+ beforeApply: async (identity) => {
1547
+ const results = [];
1548
+ for (const target of nativePackages(identity))
1549
+ results.push(...await applyPackages(target.pluginId, target.scope));
1550
+ return results;
1551
+ },
1552
+ blocked: (identity, code) => nativePackages(identity).flatMap((target) => blockPackages(target.pluginId, target.scope, code === 'dependencyInstallFailed' ? 'dependencyApplyFailed' : code)),
1553
+ };
1554
+ while (pending.length) {
1555
+ runtime.signal?.throwIfAborted();
1556
+ const index = pending.findIndex((node) => {
1557
+ const groups = node.targets.filter(({ child, agent }) => agent !== 'generic' && !executedNativeChildren.has(child));
1558
+ const members = new Set([node, ...groups.flatMap(({ child }) => pending.filter((candidate) => candidate.targets.some((target) => target.child === child)))]);
1559
+ return [...members].every((member) => [...member.dependencies].every((key) => !pending.some((candidate) => !members.has(candidate) && `${candidate.pluginId}\0${candidate.scope}` === key)));
1560
+ });
1561
+ if (index < 0) {
1562
+ plan.receipt.blockers.push(diagnostic('dependencyContractInvalid'));
1563
+ break;
1564
+ }
1565
+ const node = pending.splice(index, 1)[0];
1566
+ if (node.scope === 'project' && !retiredProjectCopies) {
1567
+ await retireVerified('project');
1568
+ retiredProjectCopies = true;
1569
+ }
1570
+ const key = `${node.pluginId}\0${node.scope}`;
1571
+ const standalonePackages = node.packages?.filter((target) => !consumesPackage(node, target)) ?? [];
1572
+ if (standalonePackages.length && packages) {
1573
+ if (failedNodes.has(key) || [...node.dependencies].some((dependency) => failedNodes.has(dependency))) {
1574
+ failedPackages.add(key);
1575
+ failedNodes.add(key);
1576
+ for (const target of standalonePackages)
1577
+ blockPackages(target.pluginId, target.scope, 'dependencyApplyFailed');
1578
+ plan.receipt.blockers.push(diagnostic('commandPackageProviderNotSatisfied', node.pluginId));
1579
+ }
1580
+ else {
1581
+ try {
1582
+ const produced = [];
1583
+ for (const target of standalonePackages)
1584
+ produced.push(...await applyPackages(target.pluginId, target.scope));
1585
+ if (!produced.every(commandPackageProviderSatisfied)) {
1586
+ failedPackages.add(key);
1587
+ failedNodes.add(key);
1588
+ }
1589
+ }
1590
+ catch (error) {
1591
+ runtime.signal?.throwIfAborted();
1592
+ if (error instanceof Error && error.name === 'AbortError' || readSafeOperationError(error))
1593
+ throw error;
1594
+ failedPackages.add(key);
1595
+ failedNodes.add(key);
1596
+ plan.receipt.blockers.push(diagnostic('commandPackageApplyFailed', node.pluginId));
1597
+ }
1598
+ }
1599
+ }
1600
+ for (const { child, agent } of node.targets) {
1601
+ const native = agent !== 'generic';
1602
+ if (native && executedNativeChildren.has(child))
1603
+ continue;
1604
+ if (native)
1605
+ executedNativeChildren.add(child);
1606
+ const result = await executeChild(child, native ? child.receipt.requestedTargets.map((target) => target.pluginId) : node.pluginId, agent);
1607
+ for (const target of result.targetResults)
1608
+ if (target.blockers.length || !['applied', 'no-op'].includes(target.execution)) {
1609
+ failedNodes.add(`${target.pluginId}\0${target.scope}`);
1610
+ failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
1611
+ }
1612
+ }
1613
+ }
1614
+ if (!retiredProjectCopies)
1615
+ await retireVerified('project');
1616
+ await retireVerified('user');
1617
+ }
1618
+ catch (error) {
1619
+ const code = recoveryInterruptionCode(error, runtime.signal);
1620
+ if (!code)
1621
+ throw error;
1622
+ interrupted = error;
1623
+ if (error instanceof RecoveryInterruptedError)
1624
+ results.push(error.receipt);
1625
+ // Preserve settled child receipts. Replacement preApply runs before
1626
+ // child dispatch, so also retain its execution evidence and uncertainty.
1627
+ const reported = new Set(results.flatMap((result) => result.targetResults.map(targetKey)));
1628
+ for (const scope of ['user', 'project']) {
1629
+ const targetResults = plan.receipt.targetResults.filter((target) => target.scope === scope && !reported.has(targetKey(target)));
1630
+ if (!targetResults.length)
1631
+ continue;
1632
+ results.push(blockScopedRecoveryBeforeExecution(structuredClone({
1633
+ ...plan.receipt, scope, targetResults, commandResults: [], nativeToolChanges: [],
1634
+ outputsMayHaveChanged: joint.children.some((child) => child.receipt.scope === scope && child.receipt.outputsMayHaveChanged),
1635
+ }), diagnostic(code)));
1636
+ }
1637
+ }
1638
+ }
1639
+ const receipt = mergeReceipts(plan, results);
1640
+ completedReceipt = receipt;
1641
+ const commandResults = new Map([...packageResults, ...(receipt.commandResults ?? [])].map((result) => [result.packageId, result]));
1642
+ for (const action of plan.portableCommandWithdrawals ?? []) {
1643
+ if (interrupted || runtime.signal?.aborted)
1644
+ break;
1645
+ if (!receipt.targetResults.some((target) => target.pluginId === action.pluginId && target.agent === 'generic'
1646
+ && target.delivery?.kind === 'agent-skills' && !target.blockers.length && target.observation === 'verified'
1647
+ && ['applied', 'no-op'].includes(target.execution)))
1648
+ continue;
1649
+ const result = await runtime.managedCommandProducerCache.get(action.packageId)
1650
+ ?? await publishLifecycleCommandPackage(action, { cwd: joint.snapshot.context.projectRoot ?? plan.context.executionCwd }, { env: plan.context.env, reporter: runtime.reporter });
1651
+ commandResults.set(result.packageId, result);
1652
+ receipt.outputsMayHaveChanged ||= result.action === 'removed' || result.state === 'partial';
1653
+ }
1654
+ receipt.commandResults = [...commandResults.values()];
1655
+ receipt.recoveryActions = [...new Set([...receipt.recoveryActions,
1656
+ ...receipt.commandResults.flatMap((result) => result.recoveryActions)])];
1657
+ receipt.ok &&= failedPackages.size === 0 && receipt.commandResults.every((result) => result.state === 'completed');
1658
+ receipt.outputsMayHaveChanged ||= packageResults.some(({ action, state }) => action !== 'unchanged' || state === 'partial');
1659
+ receipt.errors.push(...results.flatMap((result) => result.targetResults.flatMap((target) => target.blockers)));
1660
+ if (!receipt.ok && retriesFromRequestedRoots(receipt))
1661
+ useDeclaredRetryRoots(receipt);
1662
+ if (interrupted)
1663
+ throw interrupted;
1664
+ runtime.signal?.throwIfAborted();
1665
+ const { cwd, scope, env, cliVersion } = joint.originalOptions;
1666
+ const context = joint.snapshot.context.context;
1667
+ let statusFailure;
1668
+ let statusFailureMessage = 'Could not read the final plugin status.';
1669
+ try {
1670
+ // The reviewed Catalog may still be readable after Active has moved. Bind the
1671
+ // final read to the current sources, once per binding across both scopes.
1672
+ const status = await measureRecoveryPerformanceStage(runtime, 'recovery.status', () => readRecoveryStatus({ cwd, scope, context, env, cliVersion, expectedProjectRoot: joint.snapshot.context.projectRoot,
1673
+ catalogReadScope: new CatalogPreparationReadScope({ env, signal: runtime.signal }), signal: runtime.signal,
1674
+ nativeCliRunner: runtime.nativeCliRunner, ...(isInstallBatch(plan.command) ? {} : { codexObservationSession: runtime.codexObservationSession }) }));
1675
+ receipt.allSatisfied = status.allSatisfied;
1676
+ receipt.inSync = status.inSync;
1677
+ statusFailure = finalStatusReadFailure(status, receipt);
1678
+ }
1679
+ catch (error) {
1680
+ const interruption = recoveryInterruptionCode(error, runtime.signal);
1681
+ if (runtime.signal?.aborted || interruption === 'operationInterrupted')
1682
+ throw error;
1683
+ // All writes have settled. A failed final query leaves its own cleanup
1684
+ // uncertain without invalidating the previously verified target receipts.
1685
+ if (interruption === 'processCleanupUnconfirmed') {
1686
+ statusFailureMessage = 'Could not read the final plugin status. The status query process cleanup could not be confirmed.';
1687
+ }
1688
+ receipt.allSatisfied = null;
1689
+ receipt.inSync = null;
1690
+ statusFailure = diagnostic(readSafeOperationError(error)?.code ?? errorCode(error, 'statusUnavailable'));
1691
+ }
1692
+ if (statusFailure) {
1693
+ receipt.ok = false;
1694
+ receipt.errors.push({ code: 'statusUnavailable', message: statusFailureMessage,
1695
+ subject: statusFailure.subject, detail: { reasonCode: statusFailure.code } });
1696
+ receipt.recoveryActions.push(`aw plugin status --context ${recoveryStatusContext(receipt)} --json`);
1697
+ }
1698
+ return receipt;
1699
+ } });
1700
+ }
1701
+ catch (error) {
1702
+ if (lockWaitStartedAt !== undefined) {
1703
+ await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'failure', lockWaitStartedAt);
1704
+ }
1705
+ const code = recoveryInterruptionCode(error, performanceRuntime.signal);
1706
+ if (code) {
1707
+ const receipt = completedReceipt ?? structuredClone(plan.receipt);
1708
+ receipt.ok = false;
1709
+ receipt.allSatisfied = null;
1710
+ receipt.inSync = null;
1711
+ if (!receipt.errors.some((entry) => entry.code === code))
1712
+ receipt.errors.push(diagnostic(code));
1713
+ receipt.remainingTargets = receipt.targetResults.filter((target) => target.blockers.length || !['applied', 'no-op'].includes(target.execution))
1714
+ .map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
1715
+ throw new RecoveryInterruptedError(receipt, error);
1716
+ }
1717
+ throw error;
1718
+ }
1719
+ finally {
1720
+ try {
1721
+ await lockedPlan?.context.dispose();
1722
+ }
1723
+ finally {
1724
+ await plan.context.dispose();
1725
+ }
1726
+ }
1727
+ }
1728
+ //# sourceMappingURL=joint-coordinator.js.map