@lesliechan721/aw 0.1.0-beta.84 → 0.1.0-beta.86

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 (339) hide show
  1. package/dist/authoring/assets/command-runtime-config.d.mts +9 -0
  2. package/dist/authoring/assets/command-runtime-config.mjs +106 -0
  3. package/dist/authoring/assets/command-runtime-config.mjs.map +1 -0
  4. package/dist/authoring/scripts/validate-plugin.mjs +17 -22
  5. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  6. package/dist/index.js +2 -6
  7. package/dist/index.js.map +1 -1
  8. package/dist/scripts/aw-skill-eval-materializer.d.ts +4 -0
  9. package/dist/scripts/aw-skill-eval-materializer.js +27 -0
  10. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
  11. package/dist/scripts/bundle-plugins.js +1 -1
  12. package/dist/scripts/bundle-plugins.js.map +1 -1
  13. package/dist/scripts/test-plugin-scripts.js +13 -2
  14. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  15. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  16. package/dist/src/commands/aw-capabilities.js +2 -2
  17. package/dist/src/commands/catalog-source.d.ts +2 -1
  18. package/dist/src/commands/catalog-source.js +8 -7
  19. package/dist/src/commands/catalog-source.js.map +1 -1
  20. package/dist/src/commands/deployment-confirmation.d.ts +8 -1
  21. package/dist/src/commands/deployment-confirmation.js +79 -11
  22. package/dist/src/commands/deployment-confirmation.js.map +1 -1
  23. package/dist/src/commands/lifecycle-command-package.d.ts +44 -0
  24. package/dist/src/commands/lifecycle-command-package.js +195 -0
  25. package/dist/src/commands/lifecycle-command-package.js.map +1 -0
  26. package/dist/src/commands/managed-commands.d.ts +6 -0
  27. package/dist/src/commands/managed-commands.js +203 -152
  28. package/dist/src/commands/managed-commands.js.map +1 -1
  29. package/dist/src/commands/operation-plan.d.ts +22 -21
  30. package/dist/src/commands/operation-plan.js +2 -5
  31. package/dist/src/commands/operation-plan.js.map +1 -1
  32. package/dist/src/commands/permission-batch.d.ts +5 -0
  33. package/dist/src/commands/permission-batch.js +80 -0
  34. package/dist/src/commands/permission-batch.js.map +1 -0
  35. package/dist/src/commands/plugin-capabilities.js +17 -13
  36. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  37. package/dist/src/commands/public-config-confirmation.d.ts +8 -2
  38. package/dist/src/commands/public-config-confirmation.js +22 -5
  39. package/dist/src/commands/public-config-confirmation.js.map +1 -1
  40. package/dist/src/commands/public-lifecycle-result.d.ts +7 -12
  41. package/dist/src/commands/public-lifecycle-result.js +136 -40
  42. package/dist/src/commands/public-lifecycle-result.js.map +1 -1
  43. package/dist/src/commands/public-lifecycle.js +49 -8
  44. package/dist/src/commands/public-lifecycle.js.map +1 -1
  45. package/dist/src/commands/public-plugin-query.js +21 -5
  46. package/dist/src/commands/public-plugin-query.js.map +1 -1
  47. package/dist/src/commands/rebuild-command.d.ts +4 -0
  48. package/dist/src/commands/rebuild-command.js +150 -48
  49. package/dist/src/commands/rebuild-command.js.map +1 -1
  50. package/dist/src/commands/rebuild-integration.d.ts +12 -3
  51. package/dist/src/commands/rebuild-integration.js +52 -164
  52. package/dist/src/commands/rebuild-integration.js.map +1 -1
  53. package/dist/src/commands/rebuild-operations.d.ts +2 -1
  54. package/dist/src/commands/rebuild-operations.js +7 -2
  55. package/dist/src/commands/rebuild-operations.js.map +1 -1
  56. package/dist/src/commands/rebuild-platform-integration.d.ts +12 -5
  57. package/dist/src/commands/rebuild-platform-integration.js +691 -186
  58. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  59. package/dist/src/commands/skill-eval.js +10 -1
  60. package/dist/src/commands/skill-eval.js.map +1 -1
  61. package/dist/src/generators/local-plugin.js +14 -15
  62. package/dist/src/generators/local-plugin.js.map +1 -1
  63. package/dist/src/generators/permissions.d.ts +18 -4
  64. package/dist/src/generators/permissions.js +76 -22
  65. package/dist/src/generators/permissions.js.map +1 -1
  66. package/dist/src/index.d.ts +1 -0
  67. package/dist/src/index.js +84 -44
  68. package/dist/src/index.js.map +1 -1
  69. package/dist/src/intent/scope-context.d.ts +4 -2
  70. package/dist/src/intent/scope-context.js +37 -7
  71. package/dist/src/intent/scope-context.js.map +1 -1
  72. package/dist/src/output/command-receipt.js +7 -8
  73. package/dist/src/output/command-receipt.js.map +1 -1
  74. package/dist/src/output/component-delivery.d.ts +28 -0
  75. package/dist/src/output/component-delivery.js +138 -0
  76. package/dist/src/output/component-delivery.js.map +1 -0
  77. package/dist/src/output/public-result.d.ts +17 -0
  78. package/dist/src/output/public-result.js +121 -25
  79. package/dist/src/output/public-result.js.map +1 -1
  80. package/dist/src/output/rebuild-progress.js +7 -4
  81. package/dist/src/output/rebuild-progress.js.map +1 -1
  82. package/dist/src/output/receipt-projection.js +51 -31
  83. package/dist/src/output/receipt-projection.js.map +1 -1
  84. package/dist/src/output/skill-invocation-notices.d.ts +2 -0
  85. package/dist/src/output/skill-invocation-notices.js +40 -4
  86. package/dist/src/output/skill-invocation-notices.js.map +1 -1
  87. package/dist/src/platforms/antigravity-permissions.d.ts +50 -0
  88. package/dist/src/platforms/antigravity-permissions.js +388 -0
  89. package/dist/src/platforms/antigravity-permissions.js.map +1 -0
  90. package/dist/src/platforms/capabilities.d.ts +4 -1
  91. package/dist/src/platforms/capabilities.js +93 -9
  92. package/dist/src/platforms/capabilities.js.map +1 -1
  93. package/dist/src/platforms/contracts.d.ts +46 -2
  94. package/dist/src/platforms/discovery.d.ts +13 -0
  95. package/dist/src/platforms/discovery.js +170 -30
  96. package/dist/src/platforms/discovery.js.map +1 -1
  97. package/dist/src/platforms/grok-permission-config.d.ts +22 -0
  98. package/dist/src/platforms/grok-permission-config.js +184 -0
  99. package/dist/src/platforms/grok-permission-config.js.map +1 -0
  100. package/dist/src/platforms/grok-permission-document.d.ts +4 -0
  101. package/dist/src/platforms/grok-permission-document.js +145 -0
  102. package/dist/src/platforms/grok-permission-document.js.map +1 -0
  103. package/dist/src/platforms/grok-permissions.d.ts +17 -0
  104. package/dist/src/platforms/grok-permissions.js +311 -0
  105. package/dist/src/platforms/grok-permissions.js.map +1 -0
  106. package/dist/src/platforms/host-permission-policy.d.ts +38 -0
  107. package/dist/src/platforms/host-permission-policy.js +86 -0
  108. package/dist/src/platforms/host-permission-policy.js.map +1 -0
  109. package/dist/src/platforms/inspection-grok.js +165 -11
  110. package/dist/src/platforms/inspection-grok.js.map +1 -1
  111. package/dist/src/platforms/inspection-native.js +53 -18
  112. package/dist/src/platforms/inspection-native.js.map +1 -1
  113. package/dist/src/platforms/inspection-pi.d.ts +7 -1
  114. package/dist/src/platforms/inspection-pi.js +295 -95
  115. package/dist/src/platforms/inspection-pi.js.map +1 -1
  116. package/dist/src/platforms/inspection-query.d.ts +4 -2
  117. package/dist/src/platforms/inspection-query.js +24 -8
  118. package/dist/src/platforms/inspection-query.js.map +1 -1
  119. package/dist/src/platforms/inspection.d.ts +4 -1
  120. package/dist/src/platforms/inspection.js +36 -4
  121. package/dist/src/platforms/inspection.js.map +1 -1
  122. package/dist/src/platforms/layout.d.ts +13 -0
  123. package/dist/src/platforms/layout.js +90 -12
  124. package/dist/src/platforms/layout.js.map +1 -1
  125. package/dist/src/platforms/lifecycle-native.d.ts +1 -0
  126. package/dist/src/platforms/lifecycle-native.js +25 -1
  127. package/dist/src/platforms/lifecycle-native.js.map +1 -1
  128. package/dist/src/platforms/lifecycle.d.ts +2 -0
  129. package/dist/src/platforms/lifecycle.js +98 -25
  130. package/dist/src/platforms/lifecycle.js.map +1 -1
  131. package/dist/src/platforms/opencode-permission-config.d.ts +13 -0
  132. package/dist/src/platforms/opencode-permission-config.js +253 -0
  133. package/dist/src/platforms/opencode-permission-config.js.map +1 -0
  134. package/dist/src/platforms/opencode-permissions.d.ts +39 -0
  135. package/dist/src/platforms/opencode-permissions.js +212 -0
  136. package/dist/src/platforms/opencode-permissions.js.map +1 -0
  137. package/dist/src/platforms/opencode-related-permissions.d.ts +40 -0
  138. package/dist/src/platforms/opencode-related-permissions.js +177 -0
  139. package/dist/src/platforms/opencode-related-permissions.js.map +1 -0
  140. package/dist/src/platforms/permission-ownership.d.ts +89 -0
  141. package/dist/src/platforms/permission-ownership.js +543 -0
  142. package/dist/src/platforms/permission-ownership.js.map +1 -0
  143. package/dist/src/platforms/permission-sidecar.d.ts +70 -0
  144. package/dist/src/platforms/permission-sidecar.js +215 -0
  145. package/dist/src/platforms/permission-sidecar.js.map +1 -0
  146. package/dist/src/platforms/projection-code-extension.js +2 -1
  147. package/dist/src/platforms/projection-code-extension.js.map +1 -1
  148. package/dist/src/platforms/projection.js +127 -29
  149. package/dist/src/platforms/projection.js.map +1 -1
  150. package/dist/src/platforms/supplement-layout.d.ts +5 -1
  151. package/dist/src/platforms/supplement-layout.js +23 -1
  152. package/dist/src/platforms/supplement-layout.js.map +1 -1
  153. package/dist/src/platforms/supplement-state.d.ts +1 -1
  154. package/dist/src/platforms/supplement-state.js +18 -7
  155. package/dist/src/platforms/supplement-state.js.map +1 -1
  156. package/dist/src/portable/commands.js +1 -1
  157. package/dist/src/portable/commands.js.map +1 -1
  158. package/dist/src/portable/materializer.d.ts +4 -0
  159. package/dist/src/portable/materializer.js +8 -1
  160. package/dist/src/portable/materializer.js.map +1 -1
  161. package/dist/src/portable/recovery.d.ts +2 -0
  162. package/dist/src/portable/recovery.js +45 -8
  163. package/dist/src/portable/recovery.js.map +1 -1
  164. package/dist/src/recovery/coordinator.d.ts +3 -1
  165. package/dist/src/recovery/coordinator.js +101 -37
  166. package/dist/src/recovery/coordinator.js.map +1 -1
  167. package/dist/src/recovery/install-concurrency.js +3 -2
  168. package/dist/src/recovery/install-concurrency.js.map +1 -1
  169. package/dist/src/recovery/joint-coordinator.d.ts +7 -0
  170. package/dist/src/recovery/joint-coordinator.js +270 -64
  171. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  172. package/dist/src/recovery/joint-demand.d.ts +14 -2
  173. package/dist/src/recovery/joint-demand.js +54 -7
  174. package/dist/src/recovery/joint-demand.js.map +1 -1
  175. package/dist/src/recovery/joint-install-execution.js +2 -1
  176. package/dist/src/recovery/joint-install-execution.js.map +1 -1
  177. package/dist/src/recovery/receipt.d.ts +15 -4
  178. package/dist/src/recovery/receipt.js +23 -0
  179. package/dist/src/recovery/receipt.js.map +1 -1
  180. package/dist/src/recovery/retirement.js +11 -17
  181. package/dist/src/recovery/retirement.js.map +1 -1
  182. package/dist/src/recovery/status.d.ts +20 -8
  183. package/dist/src/recovery/status.js +411 -91
  184. package/dist/src/recovery/status.js.map +1 -1
  185. package/dist/src/review/eval-source-input.d.ts +1 -0
  186. package/dist/src/review/eval-source-input.js +7 -1
  187. package/dist/src/review/eval-source-input.js.map +1 -1
  188. package/dist/src/review/platform-profile.js +2 -1
  189. package/dist/src/review/platform-profile.js.map +1 -1
  190. package/dist/src/review/review-selection.js +12 -5
  191. package/dist/src/review/review-selection.js.map +1 -1
  192. package/dist/src/review/skill-materialization.d.ts +2 -1
  193. package/dist/src/review/skill-materialization.js +45 -43
  194. package/dist/src/review/skill-materialization.js.map +1 -1
  195. package/dist/src/review/source-binding.js +5 -1
  196. package/dist/src/review/source-binding.js.map +1 -1
  197. package/dist/src/tui/console-app-v4.js +101 -57
  198. package/dist/src/tui/console-app-v4.js.map +1 -1
  199. package/dist/src/tui/controller-runtime.js +72 -7
  200. package/dist/src/tui/controller-runtime.js.map +1 -1
  201. package/dist/src/tui/controller.d.ts +6 -2
  202. package/dist/src/tui/controller.js +17 -4
  203. package/dist/src/tui/controller.js.map +1 -1
  204. package/dist/src/tui/deployment-view.d.ts +6 -3
  205. package/dist/src/tui/deployment-view.js +52 -10
  206. package/dist/src/tui/deployment-view.js.map +1 -1
  207. package/dist/src/tui/diagnostic-projection.d.ts +7 -1
  208. package/dist/src/tui/diagnostic-projection.js +55 -5
  209. package/dist/src/tui/diagnostic-projection.js.map +1 -1
  210. package/dist/src/tui/entity-cards.d.ts +2 -1
  211. package/dist/src/tui/entity-cards.js +34 -11
  212. package/dist/src/tui/entity-cards.js.map +1 -1
  213. package/dist/src/tui/glossary.js +5 -0
  214. package/dist/src/tui/glossary.js.map +1 -1
  215. package/dist/src/tui/model.js +2 -1
  216. package/dist/src/tui/model.js.map +1 -1
  217. package/dist/src/tui/operation-diagnostic-screens.js +3 -1
  218. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
  219. package/dist/src/tui/operation-history.d.ts +6 -0
  220. package/dist/src/tui/operation-history.js +20 -2
  221. package/dist/src/tui/operation-history.js.map +1 -1
  222. package/dist/src/tui/operation-review-planner.js +130 -70
  223. package/dist/src/tui/operation-review-planner.js.map +1 -1
  224. package/dist/src/tui/plugin-detail.d.ts +4 -1
  225. package/dist/src/tui/plugin-detail.js +9 -2
  226. package/dist/src/tui/plugin-detail.js.map +1 -1
  227. package/dist/src/tui/scoped-flow.js +34 -16
  228. package/dist/src/tui/scoped-flow.js.map +1 -1
  229. package/dist/src/tui/scoped-inventory.d.ts +6 -2
  230. package/dist/src/tui/scoped-inventory.js +29 -7
  231. package/dist/src/tui/scoped-inventory.js.map +1 -1
  232. package/dist/src/types.d.ts +10 -21
  233. package/dist/src/types.js.map +1 -1
  234. package/dist/src/utils/artifact-plan.d.ts +3 -36
  235. package/dist/src/utils/artifact-plan.js +16 -78
  236. package/dist/src/utils/artifact-plan.js.map +1 -1
  237. package/dist/src/utils/artifact-renderer.d.ts +1 -60
  238. package/dist/src/utils/artifact-renderer.js +31 -57
  239. package/dist/src/utils/artifact-renderer.js.map +1 -1
  240. package/dist/src/utils/artifact-request.d.ts +3 -26
  241. package/dist/src/utils/artifact-request.js +13 -36
  242. package/dist/src/utils/artifact-request.js.map +1 -1
  243. package/dist/src/utils/artifact-sources.d.ts +0 -8
  244. package/dist/src/utils/artifact-sources.js +0 -8
  245. package/dist/src/utils/artifact-sources.js.map +1 -1
  246. package/dist/src/utils/bundle-layout.js +2 -7
  247. package/dist/src/utils/bundle-layout.js.map +1 -1
  248. package/dist/src/utils/catalog-source-references.js +22 -3
  249. package/dist/src/utils/catalog-source-references.js.map +1 -1
  250. package/dist/src/utils/codex-native-observation.d.ts +6 -0
  251. package/dist/src/utils/codex-native-observation.js +32 -3
  252. package/dist/src/utils/codex-native-observation.js.map +1 -1
  253. package/dist/src/utils/component-command-preparation.d.ts +8 -11
  254. package/dist/src/utils/component-command-preparation.js +110 -210
  255. package/dist/src/utils/component-command-preparation.js.map +1 -1
  256. package/dist/src/utils/component-gap.d.ts +4 -0
  257. package/dist/src/utils/component-gap.js +20 -0
  258. package/dist/src/utils/component-gap.js.map +1 -0
  259. package/dist/src/utils/component-resources.js +2 -4
  260. package/dist/src/utils/component-resources.js.map +1 -1
  261. package/dist/src/utils/dynamic-skill-tree.js +2 -32
  262. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  263. package/dist/src/utils/managed-command-cli-review.d.ts +43 -0
  264. package/dist/src/utils/managed-command-cli-review.js +389 -0
  265. package/dist/src/utils/managed-command-cli-review.js.map +1 -0
  266. package/dist/src/utils/managed-command-closure.d.ts +14 -3
  267. package/dist/src/utils/managed-command-closure.js +144 -23
  268. package/dist/src/utils/managed-command-closure.js.map +1 -1
  269. package/dist/src/utils/managed-command-errors.d.ts +5 -0
  270. package/dist/src/utils/managed-command-errors.js +10 -0
  271. package/dist/src/utils/managed-command-errors.js.map +1 -0
  272. package/dist/src/utils/managed-command-materialization.d.ts +77 -113
  273. package/dist/src/utils/managed-command-materialization.js +324 -323
  274. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  275. package/dist/src/utils/managed-command-preparation.d.ts +28 -65
  276. package/dist/src/utils/managed-command-preparation.js +33 -140
  277. package/dist/src/utils/managed-command-preparation.js.map +1 -1
  278. package/dist/src/utils/managed-command-review.d.ts +11 -4
  279. package/dist/src/utils/managed-command-review.js +33 -21
  280. package/dist/src/utils/managed-command-review.js.map +1 -1
  281. package/dist/src/utils/managed-command-runtime.d.ts +1 -0
  282. package/dist/src/utils/managed-command-runtime.js +6 -3
  283. package/dist/src/utils/managed-command-runtime.js.map +1 -1
  284. package/dist/src/utils/managed-command-snapshots.d.ts +17 -0
  285. package/dist/src/utils/managed-command-snapshots.js +84 -0
  286. package/dist/src/utils/managed-command-snapshots.js.map +1 -0
  287. package/dist/src/utils/managed-command-store.d.ts +65 -78
  288. package/dist/src/utils/managed-command-store.js +446 -383
  289. package/dist/src/utils/managed-command-store.js.map +1 -1
  290. package/dist/src/utils/multi-source-catalog.d.ts +2 -0
  291. package/dist/src/utils/multi-source-catalog.js +3 -1
  292. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  293. package/dist/src/utils/native-cli-interruption.d.ts +8 -0
  294. package/dist/src/utils/native-cli-interruption.js +65 -0
  295. package/dist/src/utils/native-cli-interruption.js.map +1 -0
  296. package/dist/src/utils/native-cli.d.ts +5 -0
  297. package/dist/src/utils/native-cli.js +166 -53
  298. package/dist/src/utils/native-cli.js.map +1 -1
  299. package/dist/src/utils/native-tool-context.d.ts +6 -3
  300. package/dist/src/utils/native-tool-context.js +3 -1
  301. package/dist/src/utils/native-tool-context.js.map +1 -1
  302. package/dist/src/utils/native-tool-review.d.ts +2 -12
  303. package/dist/src/utils/native-tool-review.js +6 -108
  304. package/dist/src/utils/native-tool-review.js.map +1 -1
  305. package/dist/src/utils/ownership.d.ts +8 -0
  306. package/dist/src/utils/ownership.js +17 -3
  307. package/dist/src/utils/ownership.js.map +1 -1
  308. package/dist/src/utils/package-content.d.ts +7 -0
  309. package/dist/src/utils/package-content.js +70 -0
  310. package/dist/src/utils/package-content.js.map +1 -0
  311. package/dist/src/utils/platform-empty-state.d.ts +32 -6
  312. package/dist/src/utils/platform-empty-state.js +146 -75
  313. package/dist/src/utils/platform-empty-state.js.map +1 -1
  314. package/dist/src/utils/plugin-config-command-apply.d.ts +33 -0
  315. package/dist/src/utils/plugin-config-command-apply.js +134 -0
  316. package/dist/src/utils/plugin-config-command-apply.js.map +1 -0
  317. package/dist/src/utils/plugin-config-impact.d.ts +19 -9
  318. package/dist/src/utils/plugin-config-impact.js +56 -37
  319. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  320. package/dist/src/utils/plugin-config-write.d.ts +19 -19
  321. package/dist/src/utils/plugin-config-write.js +196 -770
  322. package/dist/src/utils/plugin-config-write.js.map +1 -1
  323. package/dist/src/utils/plugin-scripts.js +19 -8
  324. package/dist/src/utils/plugin-scripts.js.map +1 -1
  325. package/dist/src/utils/process-tree.d.ts +1 -1
  326. package/dist/src/utils/process-tree.js +1 -1
  327. package/dist/src/utils/process-tree.js.map +1 -1
  328. package/dist/src/utils/rendered-contract.js +12 -6
  329. package/dist/src/utils/rendered-contract.js.map +1 -1
  330. package/dist/src/utils/skill-invocation-warning.d.ts +8 -3
  331. package/dist/src/utils/skill-invocation-warning.js +27 -1
  332. package/dist/src/utils/skill-invocation-warning.js.map +1 -1
  333. package/package.json +4 -3
  334. package/dist/src/platforms/managed-command-placement.d.ts +0 -8
  335. package/dist/src/platforms/managed-command-placement.js +0 -79
  336. package/dist/src/platforms/managed-command-placement.js.map +0 -1
  337. package/dist/src/utils/managed-command-evidence.d.ts +0 -7
  338. package/dist/src/utils/managed-command-evidence.js +0 -10
  339. package/dist/src/utils/managed-command-evidence.js.map +0 -1
@@ -1,28 +1,30 @@
1
+ import { catalogGenerationErrorCode } from './catalog-generation-error.js';
2
+ import { CatalogPluginNotFoundError } from './multi-source-catalog.js';
1
3
  import { resolveWorkContext } from '../intent/work-context.js';
2
4
  import { RecoveryInterruptedError, recoveryInterruptionCode } from '../recovery/interruption.js';
3
5
  import { readDemand, demandNativeProjection } from '../recovery/demand.js';
4
6
  import { createScopeContext } from '../intent/scope-context.js';
5
7
  import { nativeDeploymentHasVerifiedComponentWrite } from '../commands/rebuild-platform-integration.js';
6
- import { selectPluginConfigProfile, NATIVE_PLATFORM_TARGETS, getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
7
- import { readScopedRecoveryStatus } from '../recovery/status.js';
8
+ import { projectDeploymentNotices, projectRelatedProjectPermissionFailures } from '../commands/public-lifecycle-result.js';
9
+ import { recoveryHostPermissionEffects } from '../commands/deployment-confirmation.js';
10
+ import { projectComponentDelivery } from '../output/component-delivery.js';
11
+ import { canonicalizeIdentityValue, selectPluginConfigProfile } from '@lesliechan721/aw-plugin-core/manifest';
8
12
  import { syncWriteCommand } from '../commands/write-commands.js';
9
13
  import { skillInvocationDiagnostics } from '../output/skill-invocation-notices.js';
10
14
  import { CONFIG_MUTATION_RECEIPT_SCHEMA_VERSION, } from '../types.js';
11
- import { getDefaultNativeCliRunner, prepareNativeCliExecution } from './native-cli.js';
12
15
  import { assertPluginConfigMutationCandidate, assertSafePluginConfigSegment, coercePluginConfigUpdates, patchPluginConfigStore, PluginConfigSchemaResolutionError, readPluginConfigStore, readNamespacedPluginConfigStoreIdentity, resetPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolvePluginConfigStorePath, resolvePluginConfigSchemaAccess, summarizeEffectivePluginConfig, } from './plugin-config.js';
13
- import { analyzePluginConfigMutationImpact, discoverPluginConfigManagedCommandPackages, pluginConfigTargetRenderScopes, pluginSharedNativeConfigRenderUnits } from './plugin-config-impact.js';
16
+ import { analyzePluginConfigMutationImpact, discoverPluginConfigManagedCommandPackages, pluginSharedNativeConfigRenderUnits } from './plugin-config-impact.js';
14
17
  import { collectPluginConfigReferenceEvidence, resolvePluginConfigReferencePlugins, resolvePluginConfigReferenceConsumers } from './plugin-config-references.js';
15
- import { orderPluginMetasByDependencies, resolvePluginMetaDependencyClosure } from './plugin-dependencies.js';
16
- import { assertManagedCommandPackageNativeToolsUnchanged, discoverInstalledPluginManagedCommandPackages, syncPluginManagedCommandPackage, } from './managed-command-materialization.js';
17
- import { captureManagedCommandPackageEvidence, listManagedCommandPackages, managedCommandDiagnostic } from './managed-command-store.js';
18
+ import { resolvePluginMetaDependencyClosure } from './plugin-dependencies.js';
19
+ import { publishPreparedManagedCommandPackage } from './managed-command-materialization.js';
20
+ import { ManagedCommandError, managedCommandDiagnostic } from './managed-command-store.js';
21
+ import { configPackageResult, inspectConfigCommandPackageReview, prepareConfigCommandPackages } from './plugin-config-command-apply.js';
18
22
  import { collectSensitivePluginConfigValues, redactPluginScriptOutput, } from './plugin-scripts.js';
19
- import { resolveClaudeProjectKey, resolveCodexProjectKey, resolveCliPackageRoot } from './paths.js';
20
- import { createProjectLocationKey, resolveRequiredCanonicalRepoRoot } from './state-paths.js';
23
+ import { resolveCliPackageRoot } from './paths.js';
21
24
  import { readSafeOperationError } from './safe-operation-diagnostic.js';
22
25
  import { withAwHomeMutationLock, } from './aw-home-mutation-lock.js';
23
26
  import fs from 'fs-extra';
24
27
  import path from 'node:path';
25
- import { parsePluginId } from './multi-source-catalog.js';
26
28
  export function buildConfigMutationReceipt(command, receipt) {
27
29
  return {
28
30
  ...receipt,
@@ -30,31 +32,6 @@ export function buildConfigMutationReceipt(command, receipt) {
30
32
  command,
31
33
  };
32
34
  }
33
- function publicConfigApplyTargetResult(result) {
34
- return {
35
- target: {
36
- pluginName: result.target.pluginName,
37
- ...(result.target.pluginId ? { pluginId: result.target.pluginId } : {}),
38
- platform: result.target.platform,
39
- scope: result.target.scope,
40
- },
41
- action: result.action,
42
- state: result.state,
43
- ...(result.partialDelivery ? { partialDelivery: true } : {}),
44
- ...(result.message ? { message: result.message } : {}),
45
- ...(result.errorCode ? { errorCode: result.errorCode } : {}),
46
- ...(result.relation ? { relation: result.relation } : {}),
47
- ...(result.requiredBy ? { requiredBy: result.requiredBy } : {}),
48
- };
49
- }
50
- function publicConfigApplyResult(apply) {
51
- if (apply.state === 'skipped')
52
- return apply;
53
- return {
54
- ...apply,
55
- targetResults: apply.targetResults.map(publicConfigApplyTargetResult),
56
- };
57
- }
58
35
  export function configWriteStateForError(error) {
59
36
  return error?.configWrite === 'failed'
60
37
  ? 'failed'
@@ -67,7 +44,18 @@ function markConfigWriteFailed(error) {
67
44
  function skippedApply(reason) {
68
45
  return { state: 'skipped', reason, targetResults: [] };
69
46
  }
70
- function unavailableApply(reason, stage, targetResults = [], commandPackages = []) {
47
+ export function configActiveAvailabilityError(error) {
48
+ if (error instanceof CatalogPluginNotFoundError)
49
+ return { code: 'pluginUnavailable',
50
+ message: 'The plugin is absent from the active catalog. Run aw source sync and check the selector.' };
51
+ if (['catalogGenerationUnavailable', 'catalogGenerationSourceMissing', 'catalogGenerationIdentityMismatch',
52
+ 'catalogGenerationStateInvalid', 'catalogGenerationMetadataInvalid'].includes(catalogGenerationErrorCode(error))) {
53
+ return { code: 'sourceActiveUnavailable',
54
+ message: 'The active catalog is unavailable. Run aw source sync, then retry configuration apply.' };
55
+ }
56
+ return undefined;
57
+ }
58
+ function unavailableApply(reason, stage) {
71
59
  const messages = {
72
60
  invalidConfig: 'The effective config is invalid for every visible target.',
73
61
  schemaUnavailable: 'The config schema is unavailable after the config commit.',
@@ -75,21 +63,7 @@ function unavailableApply(reason, stage, targetResults = [], commandPackages = [
75
63
  effectiveConfigUnavailable: 'The effective config cannot be read after the config commit.',
76
64
  targetDiscoveryFailed: 'Visible config apply targets cannot be discovered after the config commit.',
77
65
  };
78
- return {
79
- state: 'unavailable',
80
- reason,
81
- targetResults,
82
- ...(commandPackages.length > 0 ? { commandResults: commandPackages.map((target) => ({
83
- producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
84
- errors: [{ code: reason, message: messages[reason] }],
85
- recoveryActions: [`aw command package sync ${target.producer.sourceId}/${target.producer.pluginName} ${target.packageKey} --scope ${target.producer.scope} --yes`,
86
- `aw command package remove ${target.packageId} --yes`],
87
- })) } : {}),
88
- error: { stage, code: reason, message: messages[reason] },
89
- };
90
- }
91
- function overallStateForApply(apply) {
92
- return apply.state === 'succeeded' || apply.state === 'skipped' ? 'succeeded' : 'partial';
66
+ return { state: 'unavailable', reason, targetResults: [], error: { stage, code: reason, message: messages[reason] } };
93
67
  }
94
68
  function uniqueInOrder(values) {
95
69
  return [...new Set(values)];
@@ -106,466 +80,6 @@ function dedupeTargets(targets) {
106
80
  deduped.set(targetKey(target), target);
107
81
  return [...deduped.values()];
108
82
  }
109
- async function resolveProjectKey(platform, cwd) {
110
- return platform === 'codex' ? resolveCodexProjectKey(cwd)
111
- : platform === 'claude' ? resolveClaudeProjectKey(cwd)
112
- : createProjectLocationKey(await resolveRequiredCanonicalRepoRoot(cwd));
113
- }
114
- async function createCandidateTarget(options) {
115
- return {
116
- pluginName: options.pluginName,
117
- platform: options.platform,
118
- scope: options.scope,
119
- ...(options.scope === 'project'
120
- ? { projectKey: await resolveProjectKey(options.platform, options.cwd) }
121
- : {}),
122
- };
123
- }
124
- async function discoverVisibleTargets(options) {
125
- const targets = [];
126
- const failures = [];
127
- const selector = options.plugin.pluginId ?? options.pluginName;
128
- const consumers = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env,
129
- plugins: options.rebuildRuntime?.referencePlugins });
130
- const selectors = consumers.map((plugin) => plugin.pluginId ?? plugin.manifest.name);
131
- const status = await readScopedRecoveryStatus({ scope: options.scope,
132
- cwd: options.cwd, env: options.env,
133
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
134
- catalogOperationContext: options.rebuildRuntime?.catalogOperationContext,
135
- codexObservationSession: options.rebuildRuntime?.codexObservationSession,
136
- });
137
- for (const statusTarget of status.existingTargets ?? []) {
138
- if (statusTarget.agent === 'generic' || statusTarget.scope !== options.scope)
139
- continue;
140
- const identity = parsePluginId(statusTarget.pluginId);
141
- if (!selectors.includes(statusTarget.pluginId) && statusTarget.pluginId !== selector
142
- && !selectors.some((entry) => !entry.includes('/') && entry === identity.pluginName))
143
- continue;
144
- // Existing targets already require this scope's observed activation or owned directory.
145
- const plugin = consumers.find((entry) => entry.pluginId === statusTarget.pluginId);
146
- targets.push({ ...await createCandidateTarget({ pluginName: identity.pluginName,
147
- platform: statusTarget.agent, scope: statusTarget.scope, cwd: options.cwd }),
148
- pluginId: statusTarget.pluginId, sourceId: identity.sourceId,
149
- ...(plugin?.sourceIdentity ? { sourceIdentity: plugin.sourceIdentity } : {}),
150
- });
151
- }
152
- return { targets: dedupeTargets(targets), failures };
153
- }
154
- async function reinstallVisibleTargets(options) {
155
- const nativeCliRunner = options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner ?? getDefaultNativeCliRunner();
156
- const discovered = options.discovered ?? await resolveConfigApplyTargets(options);
157
- const managedCommandProducerCache = options.rebuildRuntime?.managedCommandProducerCache
158
- ?? new Map();
159
- if (discovered.targets.some((target) => target.pluginName !== options.plugin.manifest.name)
160
- || discovered.commandPackages?.some((target) => target.producer.pluginName !== options.plugin.manifest.name)) {
161
- const plugins = discovered.plugins ?? await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
162
- sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
163
- env: options.env, plugins: options.rebuildRuntime?.referencePlugins });
164
- const results = [...discovered.failures];
165
- const commandResults = [];
166
- const failed = new Set(discovered.failures.map(({ target }) => `${target.pluginName}\0${target.platform}\0${target.scope}`));
167
- const failedPackages = new Set();
168
- const errors = (discovered.commandDiscoveryErrors ?? []).map((error) => ({
169
- stage: 'targetDiscovery', code: error.code, message: error.message,
170
- }));
171
- let partial = discovered.failures.length > 0 || errors.length > 0;
172
- for (const plugin of orderPluginMetasByDependencies(plugins)) {
173
- const targets = discovered.targets.filter((target) => target.pluginName === plugin.manifest.name);
174
- const packages = (discovered.commandPackages ?? []).filter((target) => target.producer.pluginName === plugin.manifest.name);
175
- if (!targets.length && !packages.length)
176
- continue;
177
- const dependencies = resolvePluginMetaDependencyClosure(plugins, [plugin.manifest.name])
178
- .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.manifest.name);
179
- const dependencyPackageFailed = (scope) => dependencies.some((dependency) => failedPackages.has(`${dependency}\0${scope}`) || (scope === 'project' && failedPackages.has(`${dependency}\0user`)));
180
- const blocked = targets.filter((target) => dependencies.some((dependency) => failed.has(`${dependency}\0${target.platform}\0${target.scope}`)
181
- || (target.scope === 'project' && failed.has(`${dependency}\0${target.platform}\0user`)))
182
- || dependencyPackageFailed(target.scope));
183
- if (blocked.length) {
184
- partial = true;
185
- for (const target of blocked)
186
- failed.add(`${plugin.manifest.name}\0${target.platform}\0${target.scope}`);
187
- results.push(...blocked.map((target) => ({ target, action: 'skipped',
188
- state: 'skipped', errorCode: 'dependencyApplyFailed',
189
- message: `A required provider failed. Run aw plugin sync ${plugin.pluginId ?? plugin.manifest.name} --context ${target.scope} --target ${target.platform} --yes.` })));
190
- }
191
- const blockedPackages = packages.filter((target) => {
192
- const platforms = plugin.manifest.managedCommands?.packages.find((entry) => entry.key === target.packageKey
193
- && entry.scope === target.producer.scope)?.platforms ?? NATIVE_PLATFORM_TARGETS;
194
- return dependencyPackageFailed(target.producer.scope) || dependencies.some((dependency) => platforms.some((platform) => failed.has(`${dependency}\0${platform}\0${target.producer.scope}`)
195
- || (target.producer.scope === 'project' && failed.has(`${dependency}\0${platform}\0user`))));
196
- });
197
- for (const target of blockedPackages) {
198
- partial = true;
199
- failedPackages.add(`${plugin.manifest.name}\0${target.producer.scope}`);
200
- commandResults.push({ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
201
- errors: [{ code: 'dependencyApplyFailed', message: 'A required provider failed; the command package was not refreshed.' }],
202
- recoveryActions: [`aw command package sync ${plugin.pluginId ?? plugin.manifest.name} ${target.packageKey} --scope ${target.producer.scope} --yes`] });
203
- }
204
- const available = targets.filter((target) => !blocked.includes(target));
205
- const availablePackages = packages.filter((target) => !blockedPackages.includes(target));
206
- if (!available.length && !availablePackages.length)
207
- continue;
208
- const own = plugin.manifest.name === options.plugin.manifest.name;
209
- const result = await reinstallVisibleTargets({ ...options, plugin,
210
- changedConfigKeys: own ? options.changedConfigKeys : [],
211
- rebuildRuntime: { ...options.rebuildRuntime, referencePlugins: plugins, managedCommandProducerCache },
212
- discovered: { targets: available, failures: [], commandPackages: availablePackages,
213
- commandDiscoveryErrors: [] } });
214
- if (result.state !== 'succeeded' && result.state !== 'skipped') {
215
- partial = true;
216
- for (const target of available) {
217
- if (!('targetResults' in result) || !result.targetResults.some((entry) => targetKey(entry.target) === targetKey(target) && entry.state === 'completed')) {
218
- failed.add(`${plugin.manifest.name}\0${target.platform}\0${target.scope}`);
219
- }
220
- }
221
- }
222
- if ('targetResults' in result)
223
- results.push(...result.targetResults);
224
- if ('commandResults' in result) {
225
- commandResults.push(...result.commandResults ?? []);
226
- for (const entry of result.commandResults ?? []) {
227
- if (entry.state !== 'completed')
228
- failedPackages.add(`${plugin.manifest.name}\0${entry.producer.scope}`);
229
- }
230
- }
231
- if ('errors' in result)
232
- errors.push(...result.errors ?? []);
233
- }
234
- return { state: partial ? 'partial' : 'succeeded', targetResults: results,
235
- ...(commandResults.length ? { commandResults } : {}), ...(errors.length ? { errors } : {}) };
236
- }
237
- const contexts = new Map();
238
- const demands = new Map();
239
- const failedScopes = new Set();
240
- try {
241
- const targetResults = [...discovered.failures];
242
- const commandResults = new Map();
243
- let runtimeFailed = discovered.failures.length > 0
244
- || (discovered.commandDiscoveryErrors?.length ?? 0) > 0;
245
- let invalidTargets = 0;
246
- let unavailableTargets = 0;
247
- const errors = [];
248
- for (const scope of new Set(discovered.targets.map((target) => target.scope))) {
249
- try {
250
- const context = await createScopeContext({ scope, cwd: options.cwd, env: options.env });
251
- contexts.set(scope, context);
252
- const demand = await readDemand({ scope, cwd: context.executionCwd, env: context.env });
253
- demandNativeProjection(demand);
254
- demands.set(scope, demand);
255
- }
256
- catch {
257
- failedScopes.add(scope);
258
- runtimeFailed = true;
259
- for (const target of discovered.targets.filter((entry) => entry.scope === scope)) {
260
- targetResults.push({ target, action: 'reinstall', state: 'failed', errorCode: 'configApplyContextUnavailable',
261
- message: 'The target scope or its demand cannot be read safely.' });
262
- }
263
- errors.push({ stage: 'targetValidation', code: 'configApplyContextUnavailable',
264
- message: 'A visible target scope or its demand cannot be read safely.' });
265
- }
266
- }
267
- if ((discovered.commandDiscoveryErrors?.length ?? 0) > 0) {
268
- errors.push(...discovered.commandDiscoveryErrors.map((error) => ({
269
- stage: 'targetDiscovery', code: error.code, message: error.message,
270
- })));
271
- }
272
- const reinstall = options.reinstallCommandImpl ?? syncWriteCommand;
273
- if (options.plugin.sourceId && !options.plugin.pluginId) {
274
- throw new Error(`Plugin "${options.plugin.manifest.name}" is missing its namespaced plugin ID.`);
275
- }
276
- const selector = options.plugin.sourceId
277
- ? options.plugin.pluginId
278
- : options.plugin.manifest.name;
279
- const nativeFailures = [];
280
- for (const target of discovered.commandPackages ?? []) {
281
- try {
282
- await assertManagedCommandPackageNativeToolsUnchanged({ plugin: options.plugin, producer: target.producer, env: options.env });
283
- }
284
- catch (error) {
285
- nativeFailures.push({ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
286
- errors: [managedCommandDiagnostic(error)],
287
- recoveryActions: [`aw command package sync ${selector} ${target.packageKey} --scope ${target.producer.scope} --yes`] });
288
- }
289
- }
290
- if (nativeFailures.length > 0) {
291
- return { state: 'partial', commandResults: nativeFailures,
292
- targetResults: [...targetResults, ...discovered.targets.map((target) => ({
293
- target, action: 'reinstall', state: 'failed', errorCode: 'nativeToolSyncRequired',
294
- message: 'Run a reviewed producer sync or package sync before configuration apply.',
295
- }))] };
296
- }
297
- const sanitizeFailure = async (message, target) => {
298
- let sensitiveValues = [];
299
- try {
300
- const effective = await resolveEffectivePluginConfig({
301
- ...(options.plugin.sourceId ? {
302
- sourceId: options.plugin.sourceId,
303
- sourceIdentity: options.plugin.sourceIdentity,
304
- logicalIdentity: options.plugin.catalogLogicalIdentity,
305
- } : {}),
306
- pluginName: options.plugin.manifest.name,
307
- manifest: options.plugin.manifest,
308
- referencePlugins: options.rebuildRuntime?.referencePlugins,
309
- targetScope: target.scope,
310
- platform: target.platform ?? undefined,
311
- cwd: options.cwd,
312
- env: options.env,
313
- });
314
- sensitiveValues = collectSensitivePluginConfigValues(options.plugin.manifest, effective.values, target.platform ?? undefined);
315
- }
316
- catch {
317
- // Generic credential redaction and known config paths still apply.
318
- }
319
- let sanitized = redactPluginScriptOutput(message, sensitiveValues);
320
- for (const privatePath of [target.projectKey, options.cwd]) {
321
- if (privatePath)
322
- sanitized = sanitized.split(privatePath).join('<project>');
323
- }
324
- for (const scope of ['user', 'project']) {
325
- const configPath = resolvePluginConfigStorePath({
326
- sourceId: options.plugin.sourceId,
327
- pluginName: options.plugin.manifest.name,
328
- scope,
329
- cwd: options.cwd,
330
- env: options.env,
331
- });
332
- const safeTarget = `${scope}/plugin-config/${[
333
- options.plugin.sourceId,
334
- options.plugin.manifest.name,
335
- 'config.json',
336
- ].filter(Boolean).join('/')}`;
337
- sanitized = sanitized.split(configPath).join(safeTarget);
338
- }
339
- return sanitized;
340
- };
341
- const sanitizeProjection = async (value, target, freeText = false) => {
342
- if (typeof value === 'string')
343
- return freeText ? sanitizeFailure(value, target) : value;
344
- if (value === null || typeof value !== 'object')
345
- return value;
346
- if (Array.isArray(value)) {
347
- return Promise.all(value.map((entry) => sanitizeProjection(entry, target, freeText)));
348
- }
349
- return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, entry]) => [
350
- key,
351
- await sanitizeProjection(entry, target, typeof entry === 'string'
352
- ? /^(?:message|error|stack|stdout|stderr|output|warning)$/u.test(key)
353
- : Array.isArray(entry) && /^(?:messages|warnings)$/u.test(key)),
354
- ])));
355
- };
356
- const preApplyExecutionCache = new Map();
357
- for (const target of discovered.targets) {
358
- if (failedScopes.has(target.scope))
359
- continue;
360
- try {
361
- const configs = await Promise.all(pluginConfigTargetRenderScopes(options.plugin, target).map((scope) => resolveEffectivePluginConfig({
362
- ...(options.plugin.sourceId ? {
363
- sourceId: options.plugin.sourceId,
364
- sourceIdentity: options.plugin.sourceIdentity,
365
- logicalIdentity: options.plugin.catalogLogicalIdentity,
366
- } : {}),
367
- pluginName: options.plugin.manifest.name,
368
- manifest: options.plugin.manifest,
369
- referencePlugins: options.rebuildRuntime?.referencePlugins,
370
- targetScope: scope,
371
- platform: target.platform ?? undefined,
372
- cwd: options.cwd,
373
- env: options.env,
374
- })));
375
- if (configs.some((effective) => effective.issues.length > 0)) {
376
- invalidTargets += 1;
377
- targetResults.push({
378
- target,
379
- action: 'reinstall',
380
- state: 'skipped',
381
- errorCode: 'invalidConfig',
382
- message: 'The effective config is invalid for this target.',
383
- });
384
- continue;
385
- }
386
- }
387
- catch {
388
- runtimeFailed = true;
389
- unavailableTargets += 1;
390
- targetResults.push({
391
- target,
392
- action: 'reinstall',
393
- state: 'failed',
394
- errorCode: 'effectiveConfigUnavailable',
395
- message: 'The effective config cannot be read for this target.',
396
- });
397
- errors.push({
398
- stage: 'targetValidation',
399
- code: 'effectiveConfigUnavailable',
400
- message: 'The effective config cannot be read for a visible target.',
401
- });
402
- continue;
403
- }
404
- try {
405
- const debugLogger = options.rebuildRuntime?.debugLogger;
406
- const reporter = options.rebuildRuntime?.reporter;
407
- const result = await reinstall([selector], {
408
- cwd: contexts.get(target.scope).executionCwd,
409
- platform: target.platform,
410
- scope: target.scope,
411
- ...(options.rebuildRuntime?.scriptTimeoutMs === undefined
412
- ? {}
413
- : { scriptTimeoutMs: options.rebuildRuntime.scriptTimeoutMs }),
414
- }, {
415
- ...options.rebuildRuntime,
416
- env: contexts.get(target.scope).env,
417
- nativeCliRunner,
418
- executionInput: {
419
- context: contexts.get(target.scope),
420
- requirements: demandNativeProjection(demands.get(target.scope)),
421
- selectedTargets: [{ pluginId: selector, platform: target.platform, scope: target.scope }],
422
- preserveOtherObservedTargets: true,
423
- },
424
- preApplyConfirmed: options.preApplyConfirmed === true,
425
- preApplyExecutionCache,
426
- managedCommandProducerCache,
427
- ...(debugLogger ? {
428
- debugLogger: {
429
- ...debugLogger,
430
- log: async (value) => debugLogger.log(await sanitizeProjection(value, target)),
431
- },
432
- } : {}),
433
- ...(reporter ? {
434
- reporter: {
435
- event: async (value) => reporter.event(await sanitizeProjection(value, target)),
436
- notice: async (value) => reporter.notice(await sanitizeProjection(value, target)),
437
- },
438
- } : {}),
439
- });
440
- options.rebuildRuntime?.operationDiagnosticSink?.(result.rebuildResults);
441
- for (const producer of result.commandResults ?? []) {
442
- commandResults.set(getCommandPackageId(producer.producer), producer);
443
- if (producer.state !== 'completed')
444
- runtimeFailed = true;
445
- }
446
- if (result.overallState !== 'succeeded')
447
- runtimeFailed = true;
448
- targetResults.push(...await Promise.all(result.targetResults.map(async (entry) => ({
449
- ...entry,
450
- state: entry.action === 'skipped' ? 'skipped' : entry.state,
451
- ...(entry.message ? { message: await sanitizeFailure(entry.message, entry.target) } : {}),
452
- }))));
453
- }
454
- catch (error) {
455
- runtimeFailed = true;
456
- const message = await sanitizeFailure(error instanceof Error ? error.message : String(error), target);
457
- targetResults.push({
458
- target,
459
- action: 'reinstall',
460
- state: 'failed',
461
- message,
462
- });
463
- errors.push({
464
- stage: 'apply',
465
- code: 'targetApplyFailed',
466
- message: 'A visible config apply target failed.',
467
- });
468
- }
469
- }
470
- for (const target of discovered.commandPackages ?? []) {
471
- await options.rebuildRuntime?.reporter?.event({
472
- type: 'managed-command:producer',
473
- source: { plugin: options.plugin.manifest.name, scope: target.producer.scope },
474
- data: { packageKey: target.packageKey, phase: 'start' },
475
- });
476
- let result;
477
- if (!target.declared) {
478
- result = {
479
- producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
480
- errors: [{ code: 'commandPackageDeclarationMissing',
481
- message: 'The installed command package is no longer declared by this plugin.' }],
482
- recoveryActions: [`aw command package remove ${target.packageId} --yes`],
483
- };
484
- }
485
- else {
486
- try {
487
- result = await syncPluginManagedCommandPackage({
488
- plugin: options.plugin, packageKey: target.packageKey, scope: target.producer.scope,
489
- cwd: options.cwd, env: options.env, managedCommandProducerCache, expectedPackage: target.expectedPackage,
490
- referencePlugins: options.rebuildRuntime?.referencePlugins,
491
- event: options.changedConfigKeys?.length ? 'refresh' : 'install',
492
- changedConfigKeys: options.changedConfigKeys ?? [],
493
- signal: options.rebuildRuntime?.signal,
494
- scriptTimeoutMs: options.rebuildRuntime?.scriptTimeoutMs,
495
- });
496
- }
497
- catch (error) {
498
- if (recoveryInterruptionCode(error, options.rebuildRuntime?.signal) || readSafeOperationError(error))
499
- throw error;
500
- result = {
501
- producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
502
- errors: [{ code: 'commandPackageApplyFailed', message: 'The managed command package could not be refreshed.' }],
503
- recoveryActions: [`aw command package sync ${selector} ${target.packageKey} --scope ${target.producer.scope} --yes`,
504
- `aw command package remove ${target.packageId} --yes`],
505
- };
506
- }
507
- }
508
- result = { ...result, errors: await Promise.all(result.errors.map(async (error) => ({
509
- ...error, message: await sanitizeFailure(error.message, { scope: target.producer.scope,
510
- ...(target.producer.projectRoot ? { projectKey: target.producer.projectRoot } : {}) }),
511
- }))) };
512
- commandResults.set(getCommandPackageId(result.producer), result);
513
- await options.rebuildRuntime?.reporter?.event({
514
- type: 'managed-command:producer',
515
- source: { plugin: options.plugin.manifest.name, scope: target.producer.scope },
516
- data: { packageKey: target.packageKey, phase: result.state === 'completed' ? 'success' : 'failure' },
517
- });
518
- if (result.state !== 'completed')
519
- runtimeFailed = true;
520
- }
521
- const commands = commandResults.size > 0 ? { commandResults: [...commandResults.values()] } : {};
522
- const commandTargetCount = (discovered.commandPackages?.length ?? 0);
523
- if (discovered.targets.length === 0 && discovered.failures.length === 0
524
- && commandTargetCount === 0 && !runtimeFailed) {
525
- return skippedApply('noVisibleTarget');
526
- }
527
- if (discovered.targets.length > 0 && invalidTargets === discovered.targets.length && commandTargetCount === 0) {
528
- return { ...unavailableApply('invalidConfig', 'targetValidation', targetResults), ...commands };
529
- }
530
- if (discovered.targets.length > 0 && unavailableTargets === discovered.targets.length && commandTargetCount === 0) {
531
- return { ...unavailableApply('effectiveConfigUnavailable', 'targetValidation', targetResults), ...commands };
532
- }
533
- if (runtimeFailed
534
- || invalidTargets > 0
535
- || unavailableTargets > 0
536
- || targetResults.some((entry) => entry.state === 'failed' || entry.state === 'skipped')) {
537
- return {
538
- state: 'partial',
539
- targetResults,
540
- ...commands,
541
- ...(errors.length > 0 ? { errors } : {}),
542
- };
543
- }
544
- return { state: 'succeeded', targetResults, ...commands };
545
- }
546
- finally {
547
- await Promise.all([...contexts.values()].map((context) => context.dispose()));
548
- }
549
- }
550
- async function resolveConfigApplyTargets(options) {
551
- const platformTargets = options.applyTargets !== undefined
552
- ? { targets: dedupeTargets(options.applyTargets), failures: [] }
553
- : await discoverVisibleTargets({
554
- pluginName: options.plugin.manifest.name,
555
- plugin: options.plugin,
556
- scope: options.scope,
557
- cwd: options.cwd,
558
- env: options.env,
559
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner ?? getDefaultNativeCliRunner(),
560
- rebuildRuntime: options.rebuildRuntime,
561
- });
562
- const commands = await discoverPluginConfigManagedCommandPackages({
563
- plugin: options.plugin, scope: options.scope, cwd: options.cwd, env: options.env,
564
- platformTargets: platformTargets.targets,
565
- referencePlugins: options.rebuildRuntime?.referencePlugins,
566
- });
567
- return { ...platformTargets, commandPackages: commands.packages, commandDiscoveryErrors: commands.errors };
568
- }
569
83
  async function configApplyHasValidSharedNativeTarget(options) {
570
84
  const plugins = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env, plugins: options.plugins });
571
85
  for (const plugin of plugins) {
@@ -584,7 +98,8 @@ async function configApplyHasValidSharedNativeTarget(options) {
584
98
  return false;
585
99
  }
586
100
  export async function resolveConfigPreApplyAuthorization(options) {
587
- const applyTargets = dedupeTargets(options.applyTargets);
101
+ const applyTargets = dedupeTargets(options.applyTargets).filter((target) => !options.rebuildRuntime?.configApplyPackages?.targets.some((entry) => entry.blocker
102
+ && entry.pluginId === (target.pluginId ?? options.plugin.pluginId) && entry.platforms.includes(target.platform)));
588
103
  if (applyTargets.some((target) => target.pluginName !== options.plugin.manifest.name)) {
589
104
  const plugins = await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
590
105
  sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
@@ -731,121 +246,14 @@ function buildReceiptFieldEntry(options) {
731
246
  };
732
247
  }
733
248
  export async function replayConfigRuntimeWrites(options) {
734
- if (!options.awHomeMutationToken) {
735
- await prepareNativeCliExecution({ env: options.env, runner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner });
736
- }
737
- return withAwHomeMutationLock({
738
- env: options.env,
739
- token: options.awHomeMutationToken,
740
- action: async (awHomeMutationToken) => {
741
- const env = options.env ?? process.env;
742
- const rebuildRuntime = { ...options.rebuildRuntime, awHomeMutationToken };
743
- let discovered;
744
- try {
745
- discovered = await resolveConfigApplyTargets({
746
- plugin: options.plugin,
747
- scope: options.scope,
748
- cwd: options.cwd,
749
- env,
750
- applyTargets: options.applyTargets,
751
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
752
- rebuildRuntime,
753
- });
754
- }
755
- catch {
756
- const apply = unavailableApply('targetDiscoveryFailed', 'targetDiscovery');
757
- return {
758
- configWrite: 'succeeded',
759
- overallState: 'partial',
760
- apply: publicConfigApplyResult(apply),
761
- otherProjectsMayRequireSync: false,
762
- };
763
- }
764
- const preApplyAuthorization = await resolveConfigPreApplyAuthorization({
765
- plugin: options.plugin,
766
- scope: options.scope,
767
- cwd: options.cwd,
768
- env,
769
- applyTargets: discovered.targets,
770
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
771
- rebuildRuntime,
772
- reinstallCommandImpl: options.reinstallCommandImpl,
773
- });
774
- if (preApplyAuthorization.targets.length > 0 && !preApplyAuthorizationIsConfirmed({
775
- required: preApplyAuthorization.targets,
776
- confirmed: options.preApplyConfirmed,
777
- authorizedTargets: options.preApplyAuthorizedTargets,
778
- })) {
779
- const apply = {
780
- state: 'partial',
781
- targetResults: preApplyAuthorization.targets.map((target) => ({
782
- target: {
783
- pluginName: target.pluginName,
784
- pluginId: target.pluginId,
785
- platform: target.platform,
786
- scope: target.scope,
787
- },
788
- action: 'reinstall',
789
- state: 'failed',
790
- errorCode: 'preApplyAuthorizationRequired',
791
- message: 'Running plugin preApply requires explicit authorization.',
792
- })),
793
- };
794
- return {
795
- configWrite: 'succeeded',
796
- overallState: 'partial',
797
- apply: publicConfigApplyResult(apply),
798
- otherProjectsMayRequireSync: false,
799
- };
800
- }
801
- discovered = {
802
- ...discovered,
803
- targets: preApplyAuthorization.availableApplyTargets,
804
- failures: [...discovered.failures, ...preApplyAuthorization.unavailableTargetResults],
805
- };
806
- if (discovered.targets.length === 0
807
- && preApplyAuthorization.unavailableTargetResults.length > 0
808
- && (discovered.commandPackages?.length ?? 0) === 0) {
809
- const apply = unavailableApply('sourceUnavailable', 'source', preApplyAuthorization.unavailableTargetResults);
810
- return {
811
- configWrite: 'succeeded',
812
- overallState: 'partial',
813
- apply: publicConfigApplyResult(apply),
814
- otherProjectsMayRequireSync: false,
815
- };
816
- }
817
- if (options.scope === 'user'
818
- && options.sharedNativeApplyConfirmed !== true
819
- && await configApplyHasValidSharedNativeTarget({
820
- plugin: options.plugin,
821
- targets: discovered.targets,
822
- cwd: options.cwd,
823
- env,
824
- plugins: rebuildRuntime.referencePlugins,
825
- })) {
826
- throwSharedNativeApplyConfirmationRequired();
827
- }
828
- const apply = await reinstallVisibleTargets({
829
- plugin: options.plugin,
830
- scope: options.scope,
831
- cwd: options.cwd,
832
- env,
833
- applyTargets: options.applyTargets,
834
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
835
- reinstallCommandImpl: options.reinstallCommandImpl,
836
- rebuildRuntime,
837
- discovered,
838
- preApplyConfirmed: options.preApplyConfirmed,
839
- });
840
- return {
841
- configWrite: 'succeeded',
842
- overallState: overallStateForApply(apply),
843
- apply: publicConfigApplyResult(apply),
844
- otherProjectsMayRequireSync: false,
845
- };
846
- },
847
- });
848
- }
249
+ if (options.scope === 'user' && options.sharedNativeApplyConfirmed !== true && await configApplyHasValidSharedNativeTarget({
250
+ ...options, plugins: options.rebuildRuntime?.referencePlugins, targets: options.applyTargets ?? [],
251
+ }))
252
+ throwSharedNativeApplyConfirmationRequired();
253
+ const result = await applyPluginConfig(options);
254
+ return { ...result, configWrite: 'succeeded', otherProjectsMayRequireSync: false };
255
+ }
256
+ const commandCandidateCleanup = new WeakMap();
849
257
  function configApplyRequestedTargets(plan) {
850
258
  const targets = plan.joint
851
259
  ? plan.joint.children.filter((child) => child.command !== 'cleanup' && child.command !== 'uninstall')
@@ -854,115 +262,69 @@ function configApplyRequestedTargets(plan) {
854
262
  return targets.filter((target) => !plan.receipt.targetResults.some((result) => result.pluginId === target.pluginId && result.agent === target.agent && result.scope === target.scope
855
263
  && (result.satisfaction === 'unsupported' || result.satisfaction === 'excluded')));
856
264
  }
857
- async function prepareConfigApplyPackages(options, plugins, plan, referencePlugins) {
265
+ function configApplyPackageHook(options, entries, referencePlugins) {
858
266
  const env = options.env ?? process.env;
859
- const context = options.context ?? options.scope;
860
- const discoveries = [];
861
- const scopes = context === 'project' ? ['user', 'project'] : ['user'];
862
- const nativeTargets = configApplyRequestedTargets(plan).flatMap((target) => target.agent !== 'generic'
863
- ? [{ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId, platform: target.agent, scope: target.scope }] : []);
864
- for (const plugin of plugins) {
865
- for (const scope of scopes) {
866
- discoveries.push(await discoverInstalledPluginManagedCommandPackages({ plugin, scope, cwd: options.cwd, env,
867
- platformTargets: nativeTargets.filter((target) => target.pluginId === (plugin.pluginId ?? plugin.manifest.name)
868
- && (scope === 'user' || target.scope === 'project')) }));
869
- }
870
- }
871
- const packages = [...new Map(discoveries.flatMap((discovery) => discovery.packages).filter((target) => {
872
- if (options.applyCommandPackages && !options.applyCommandPackages.includes(target.packageId))
873
- return false;
874
- if (options.platform)
875
- return false;
876
- if (!options.targets)
877
- return true;
878
- const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
879
- const declaration = plugin?.manifest.managedCommands?.packages.find((entry) => entry.key === target.packageKey && entry.scope === target.producer.scope);
880
- return declaration?.platforms.some((platform) => options.targets.includes(platform)) ?? false;
881
- }).map((target) => [target.packageId, target])).values()];
882
- const inventory = await listManagedCommandPackages(env);
883
- const entries = await Promise.all(packages.map(async (target) => {
884
- const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
885
- const installed = inventory.packages.find((entry) => entry.id === target.packageId);
886
- let expectedPackage;
887
- let blocker;
888
- if (!target.installed || !installed) {
889
- blocker = { code: 'configApplyRequiresExistingOutput', message: 'Configuration apply requires an existing command package. Run package sync first.' };
890
- }
891
- else if (!target.declared) {
892
- blocker = { code: 'commandPackageDeclarationMissing', message: 'The installed command package is no longer declared by this plugin.' };
893
- }
894
- else {
895
- try {
896
- await assertManagedCommandPackageNativeToolsUnchanged({ plugin, producer: target.producer, env });
897
- expectedPackage = await captureManagedCommandPackageEvidence(installed, env);
898
- }
899
- catch (error) {
900
- blocker = managedCommandDiagnostic(error);
901
- }
902
- }
903
- return { target, expectedPackage, blocker };
267
+ const targets = entries.map(({ target, plugin, evidence }) => ({
268
+ pluginId: plugin.pluginId ?? plugin.manifest.name,
269
+ scope: 'user',
270
+ packageId: target.packageId,
271
+ platforms: evidence.review?.routeChanges.length || evidence.blocker
272
+ ? [...plugin.manifest.command?.platforms ?? target.runtimeConfigPlatforms] : [],
273
+ ...(evidence.blocker && ['nativeToolSyncRequired', 'configApplyVersionMismatch'].includes(evidence.blocker.code)
274
+ ? { blocker: evidence.blocker } : {}),
275
+ dependencies: resolvePluginMetaDependencyClosure(referencePlugins, [plugin.manifest.name])
276
+ .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.pluginId ?? entry.manifest.name),
904
277
  }));
905
- const errors = [...new Map(discoveries.flatMap((discovery) => discovery.errors).map((error) => [JSON.stringify(error), error])).values()];
906
- const evidence = { packages: entries, errors };
907
- const targets = entries.map(({ target }) => {
908
- const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
909
- const pluginId = plugin.pluginId ?? plugin.manifest.name;
910
- const dependencies = resolvePluginMetaDependencyClosure(referencePlugins, [plugin.manifest.name])
911
- .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.pluginId ?? entry.manifest.name);
912
- const declaration = plugin.manifest.managedCommands?.packages.find((item) => item.key === target.packageKey && item.scope === target.producer.scope);
913
- return { pluginId, scope: target.producer.scope, packageId: target.packageId, platforms: declaration?.platforms ?? [], dependencies };
914
- });
915
- const cache = plan.runtime.managedCommandProducerCache ??= new Map();
916
- const hook = { targets, evidence,
917
- blocked: (pluginId, scope, code, packageId) => {
918
- const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
919
- return entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope
920
- && (!packageId || target.packageId === packageId))
921
- .map(({ target }) => ({
922
- producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
923
- errors: [{ code, message: 'The command package refresh did not complete.' }],
924
- recoveryActions: [`aw command package sync ${pluginId} ${target.packageKey} --scope ${scope} --yes`],
925
- }));
926
- },
927
- execute: async (pluginId, scope, token, packageId) => {
928
- const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
929
- const selected = entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope
930
- && (!packageId || target.packageId === packageId));
278
+ const selected = (pluginId, packageId) => entries.filter(({ target, plugin }) => (plugin.pluginId ?? plugin.manifest.name) === pluginId && (!packageId || target.packageId === packageId));
279
+ return { targets, evidence: entries.map(({ evidence }) => evidence),
280
+ blocked: (pluginId, _scope, code, packageId) => selected(pluginId, packageId).map(({ target, candidate, evidence }) => configPackageResult(target, [evidence.blocker ?? { code, message: 'The command package refresh did not complete.' }], candidate)),
281
+ execute: async (pluginId, _scope, _token, packageId) => {
931
282
  const results = [];
932
- let executionContext;
933
- try {
934
- executionContext = await createScopeContext({ scope, cwd: options.cwd, env });
935
- for (const { target, expectedPackage, blocker } of selected) {
936
- if (blocker) {
937
- const result = { producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
938
- errors: [blocker], recoveryActions: [target.declared
939
- ? `aw command package sync ${pluginId} ${target.packageKey} --scope ${scope} --yes`
940
- : `aw command package remove ${target.packageId} --yes`] };
941
- cache.set(target.packageId, Promise.resolve(result));
942
- results.push(result);
943
- continue;
283
+ for (const { target, plugin, candidate, evidence } of selected(pluginId, packageId)) {
284
+ if (evidence.blocker || !candidate) {
285
+ results.push(configPackageResult(target, [evidence.blocker ?? {
286
+ code: 'commandPackageApplyFailed', message: 'The command package could not be prepared.',
287
+ }]));
288
+ continue;
289
+ }
290
+ try {
291
+ options.rebuildRuntime?.signal?.throwIfAborted();
292
+ if (canonicalizeIdentityValue(evidence.review) !== canonicalizeIdentityValue(await inspectConfigCommandPackageReview(options, target, candidate))) {
293
+ throw new ManagedCommandError('operationReviewStale', 'Permissions affecting the reviewed routes changed. Prepare a new Review.');
944
294
  }
945
- const applied = await reinstallVisibleTargets({ plugin, scope, cwd: executionContext.executionCwd, env: executionContext.env,
946
- changedConfigKeys: [...target.refreshKeys],
947
- rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken: token, referencePlugins, managedCommandProducerCache: cache },
948
- discovered: { targets: [], failures: [], commandPackages: [{ ...target, expectedPackage }], commandDiscoveryErrors: [] } });
949
- results.push(...('commandResults' in applied ? applied.commandResults ?? [] : []));
295
+ const published = await publishPreparedManagedCommandPackage({ plugin, candidate, cwd: options.cwd, env, referencePlugins });
296
+ results.push(configPackageResult(target, [], candidate, published));
297
+ }
298
+ catch (error) {
299
+ if (recoveryInterruptionCode(error, options.rebuildRuntime?.signal) || readSafeOperationError(error))
300
+ throw error;
301
+ results.push(configPackageResult(target, [managedCommandDiagnostic(error)], candidate));
950
302
  }
951
- return results;
952
- }
953
- finally {
954
- await executionContext?.dispose();
955
303
  }
956
- } };
957
- return { packages, evidence, errors, hook };
304
+ return results;
305
+ },
306
+ };
958
307
  }
959
308
  /** Prepare the same existing-output plan used by apply, without saving config or output. */
960
- export async function preparePluginConfigApply(options) {
309
+ export async function preparePluginConfigApply(options, { inspectOnly = false } = {}) {
961
310
  const { prepareRecovery, describeRecoveryPlan } = await import('../recovery/coordinator.js');
962
311
  const context = options.context ?? options.scope;
963
312
  const referencePlugins = await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
964
313
  sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
965
- env: options.env, plugins: options.rebuildRuntime?.referencePlugins });
314
+ env: options.env, plugins: options.rebuildRuntime?.referencePlugins,
315
+ operationContext: options.rebuildRuntime?.catalogOperationContext }).catch((error) => {
316
+ if (recoveryInterruptionCode(error, options.rebuildRuntime?.signal))
317
+ throw error;
318
+ throw Object.assign(new Error('The selected source has no usable Active Catalog.'), { code: 'sourceActiveUnavailable' });
319
+ });
320
+ if (options.plugin.sourceId) {
321
+ const activePlugin = referencePlugins.find((entry) => entry.manifest.name === options.plugin.manifest.name);
322
+ if (activePlugin)
323
+ options = { ...options, plugin: activePlugin };
324
+ else if (options.plugin.manifest.command) {
325
+ throw Object.assign(new Error('The plugin is unavailable in Active Catalog.'), { code: 'pluginUnavailable' });
326
+ }
327
+ }
966
328
  const plugins = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env,
967
329
  plugins: referencePlugins });
968
330
  const selectors = plugins.map((plugin) => plugin.pluginId ?? plugin.manifest.name);
@@ -990,33 +352,65 @@ export async function preparePluginConfigApply(options) {
990
352
  return true;
991
353
  });
992
354
  }
993
- const plan = await prepareRecovery('sync', selectors, {
994
- scope: context,
995
- context,
996
- cwd: options.cwd,
997
- env: options.env,
998
- signal: options.rebuildRuntime?.signal,
999
- cliVersion: version,
1000
- existingOnly: true,
1001
- ...(exactTargets ? { exactTargets } : {}),
1002
- ...(options.targets ? { targets: options.targets } : options.platform ? { targets: [options.platform] } : {}),
1003
- }, {
1004
- ...options.rebuildRuntime,
1005
- referencePlugins,
1006
- nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
1007
- awHomeMutationToken: options.awHomeMutationToken,
1008
- preApplyConfirmed: options.preApplyConfirmed,
355
+ const env = options.env ?? process.env;
356
+ const commands = await discoverPluginConfigManagedCommandPackages({ plugin: options.plugin, scope: context,
357
+ cwd: options.cwd, env, referencePlugins });
358
+ let selectedPackages = commands.packages.filter((target) => {
359
+ if (options.applyCommandPackages && !options.applyCommandPackages.includes(target.packageId))
360
+ return false;
361
+ const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
362
+ const platforms = plugin?.manifest.command?.platforms ?? target.runtimeConfigPlatforms;
363
+ if (options.platform)
364
+ return options.platform !== 'generic' && platforms.includes(options.platform) && target.runtimeConfigKeys.length > 0;
365
+ return (target.refreshKeys.length > 0 || target.runtimeConfigKeys.length > 0)
366
+ && (!options.targets || platforms.some((platform) => options.targets.includes(platform)));
1009
367
  });
368
+ if (options.mutation) {
369
+ const impact = await analyzePluginConfigMutationImpact({ ...options, scope: context, visibleTargets: [],
370
+ mutation: options.mutation, commandDiscovery: { ...commands, packages: selectedPackages }, referencePlugins });
371
+ selectedPackages = impact.affectedCommandPackages;
372
+ }
373
+ const entries = await prepareConfigCommandPackages(options, selectedPackages, plugins, referencePlugins, { inspectOnly });
374
+ const cleanup = () => Promise.all(entries.map(({ candidate }) => candidate?.cleanup()));
375
+ const packagePreparationCache = new Map();
376
+ for (const { target, candidate } of entries) {
377
+ if (candidate)
378
+ packagePreparationCache.set(target.packageId, Promise.resolve(candidate));
379
+ }
380
+ let plan;
1010
381
  try {
382
+ plan = await prepareRecovery('sync', selectors, {
383
+ scope: context,
384
+ context,
385
+ cwd: options.cwd,
386
+ env: options.env,
387
+ signal: options.rebuildRuntime?.signal,
388
+ cliVersion: version,
389
+ existingOnly: true,
390
+ ...(exactTargets ? { exactTargets } : {}),
391
+ ...(options.platform ? { targets: [options.platform] } : options.targets ? { targets: options.targets } : {}),
392
+ }, {
393
+ ...options.rebuildRuntime,
394
+ configApply: true,
395
+ packagePreparationCache,
396
+ configApplyPackages: configApplyPackageHook(options, entries, referencePlugins),
397
+ referencePlugins,
398
+ nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
399
+ awHomeMutationToken: options.awHomeMutationToken,
400
+ preApplyConfirmed: options.preApplyConfirmed,
401
+ });
402
+ commandCandidateCleanup.set(plan, cleanup);
1011
403
  plan.warnings.push(...retainedLegacyTargets.map((target) => `${target.pluginId ?? target.pluginName}/${target.platform}/${target.scope}:保留已停用的历史输出;配置 apply 不创建激活。`));
1012
- const commands = await prepareConfigApplyPackages(options, plugins, plan, referencePlugins);
1013
- plan.runtime.configApplyPackages = commands.hook;
1014
404
  const profiles = configApplyRequestedTargets(plan).map((target) => ({
1015
405
  pluginName: target.pluginId.split('/').at(-1), scope: target.scope, platform: target.agent,
1016
406
  }));
1017
- // A package has platform=null and always consumes the public common profile.
1018
- profiles.push(...commands.packages.map((target) => ({ pluginName: target.producer.pluginName,
1019
- scope: target.producer.scope, platform: undefined })));
407
+ for (const { target, candidate } of entries) {
408
+ for (const platform of candidate?.runtimeConfigEvidence.keys() ?? []) {
409
+ profiles.push({ pluginName: target.producer.pluginName, scope: 'user', platform });
410
+ }
411
+ if (candidate?.routeConfigEvidence)
412
+ profiles.push({ pluginName: target.producer.pluginName, scope: 'user' });
413
+ }
1020
414
  const references = await collectPluginConfigReferenceEvidence({ plugin: options.plugin, plugins: referencePlugins,
1021
415
  profiles, cwd: options.cwd, env: options.env });
1022
416
  const authorization = await resolveConfigPreApplyAuthorization({
@@ -1032,17 +426,25 @@ export async function preparePluginConfigApply(options) {
1032
426
  ];
1033
427
  const preApplyAuthorization = [...new Map([...authorization.targets, ...portableAuthorization(plan)]
1034
428
  .map((target) => [[target.pluginId, target.platform, target.scope].join('\0'), target])).values()];
429
+ const commandPackageEvidence = entries.map(({ evidence }) => evidence);
1035
430
  return { plan, retainedLegacyTargets, commandPackages: commands.packages, commandDiscoveryErrors: commands.errors,
431
+ commandPackageEvidence, commandPackageReviews: commandPackageEvidence.flatMap(({ review }) => review ? [review] : []),
1036
432
  preApplyAuthorization,
1037
- evidence: { recovery: describeRecoveryPlan(plan), references, commands: commands.evidence,
433
+ evidence: { recovery: describeRecoveryPlan(plan), references, commandPackageEvidence,
1038
434
  preApplyAuthorization, retainedLegacyTargets } };
1039
435
  }
1040
436
  catch (error) {
1041
- await disposePluginConfigApply(plan);
437
+ if (plan)
438
+ await disposePluginConfigApply(plan);
439
+ else
440
+ await cleanup();
1042
441
  throw error;
1043
442
  }
1044
443
  }
1045
444
  export async function disposePluginConfigApply(plan) {
445
+ const cleanup = commandCandidateCleanup.get(plan);
446
+ commandCandidateCleanup.delete(plan);
447
+ await cleanup?.();
1046
448
  for (const child of plan.joint?.children ?? [])
1047
449
  await disposePluginConfigApply(child);
1048
450
  await plan.context.dispose();
@@ -1088,10 +490,17 @@ export async function applyPluginConfig(options) {
1088
490
  let prepared;
1089
491
  try {
1090
492
  const { executeRecovery } = await import('../recovery/coordinator.js');
1091
- prepared = await preparePluginConfigApply({ ...options, awHomeMutationToken: token });
493
+ const expectedCommands = options.expectedCommandPackageEvidence
494
+ ?? options.expectedEvidence?.commandPackageEvidence;
495
+ prepared = await preparePluginConfigApply({ ...options, awHomeMutationToken: token,
496
+ expectedCommandPackageEvidence: expectedCommands });
1092
497
  if (options.expectedEvidence !== undefined
1093
498
  && JSON.stringify(options.expectedEvidence) !== JSON.stringify(prepared.evidence)) {
1094
- throw Object.assign(new Error('operationPlanStale: Configuration apply inputs changed. Prepare a new Review.'), { code: 'operationPlanStale' });
499
+ throw Object.assign(new Error('Configuration apply inputs changed. Prepare a new Review.'), { code: 'operationReviewStale' });
500
+ }
501
+ const authorizedEffects = new Set(options.expectedHostPermissionEffects?.map((effect) => JSON.stringify(effect)));
502
+ if (recoveryHostPermissionEffects(prepared.plan).some((effect) => !authorizedEffects.has(JSON.stringify(effect)))) {
503
+ throw Object.assign(new Error('Host permission effects changed after Review. Prepare a new Review.'), { code: 'operationReviewStale' });
1095
504
  }
1096
505
  const authorization = prepared.preApplyAuthorization;
1097
506
  if (authorization.length && !preApplyAuthorizationIsConfirmed({ required: authorization,
@@ -1119,12 +528,11 @@ export async function applyPluginConfig(options) {
1119
528
  });
1120
529
  const retainedLegacyTargets = prepared.retainedLegacyTargets.filter((target) => !receipt.targetResults.some((result) => (target.pluginId ? result.pluginId === target.pluginId : result.pluginId.split('/').at(-1) === target.pluginName)
1121
530
  && result.agent === target.platform && result.scope === target.scope));
1122
- prepared = undefined;
1123
531
  const ok = receipt.ok && discoveryErrors.length === 0;
1124
532
  const errors = [...discoveryErrors, ...receipt.blockers, ...receipt.errors].map((error) => ({
1125
533
  stage: 'stage' in error ? error.stage : 'apply', code: error.code, message: error.message,
1126
534
  }));
1127
- const diagnostics = skillInvocationDiagnostics(receipt.targetResults);
535
+ const diagnostics = [...projectDeploymentNotices(receipt.targetResults), ...projectRelatedProjectPermissionFailures(receipt.targetResults)];
1128
536
  const apply = {
1129
537
  state: ok ? 'succeeded' : 'partial',
1130
538
  targetResults: [...receipt.targetResults.filter((target) => target.satisfaction !== 'unsupported' && target.satisfaction !== 'excluded').map((target) => ({
@@ -1133,6 +541,7 @@ export async function applyPluginConfig(options) {
1133
541
  action: 'refresh',
1134
542
  state: target.execution === 'applied' || target.execution === 'no-op' ? 'completed'
1135
543
  : target.execution === 'not-run' ? 'skipped' : 'failed',
544
+ ...projectComponentDelivery(target),
1136
545
  ...(target.relation === 'root' ? { relation: 'requested' } : target.relation === 'dependency' ? { relation: 'dependency' } : {}),
1137
546
  ...(target.requiredBy.length ? { requiredBy: target.requiredBy } : {}),
1138
547
  ...(configApplyHasPartialDelivery(target) ? { partialDelivery: true } : {}),
@@ -1153,14 +562,20 @@ export async function applyPluginConfig(options) {
1153
562
  otherProjectsMayRequireSync: true };
1154
563
  }
1155
564
  catch (error) {
1156
- if (options.rebuildRuntime?.signal?.aborted || error instanceof Error && error.name === 'AbortError'
565
+ if (recoveryInterruptionCode(error, options.rebuildRuntime?.signal)
1157
566
  || readSafeOperationError(error))
1158
567
  throw error;
1159
568
  const apply = unavailableApply('targetDiscoveryFailed', 'targetDiscovery');
1160
569
  const code = error?.code;
570
+ if (code === 'sourceActiveUnavailable' || code === 'pluginUnavailable') {
571
+ return { configWrite: 'notStarted', overallState: 'partial', apply: {
572
+ ...unavailableApply('sourceUnavailable', 'source'),
573
+ error: { stage: 'source', code, message: error instanceof Error ? error.message : 'The Active Catalog plugin is unavailable.' },
574
+ }, otherProjectsMayRequireSync: true };
575
+ }
1161
576
  if (typeof code === 'string')
1162
577
  apply.error = { stage: 'apply', code,
1163
- message: code === 'operationPlanStale' ? 'Configuration apply inputs changed. Prepare a new Review.'
578
+ message: code === 'operationReviewStale' ? 'Configuration apply inputs changed. Prepare a new Review.'
1164
579
  : 'The existing outputs cannot be refreshed with the current authorization.' };
1165
580
  return { configWrite: 'notStarted', overallState: 'partial', apply, otherProjectsMayRequireSync: true };
1166
581
  }
@@ -1232,29 +647,37 @@ async function prepareConfigMutationApplySelection(options) {
1232
647
  return undefined;
1233
648
  let prepared;
1234
649
  try {
1235
- prepared = await preparePluginConfigApply({ ...options, plugin: options.plugin });
650
+ prepared = await preparePluginConfigApply({ ...options, plugin: options.plugin }, { inspectOnly: true });
1236
651
  const requestedTargets = configApplyRequestedTargets(prepared.plan);
1237
- if (requestedTargets.some((target) => target.agent === 'generic'))
1238
- return undefined;
1239
- const visibleTargets = requestedTargets.map((target) => ({
1240
- pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId,
1241
- platform: target.agent, scope: target.scope,
1242
- }));
1243
- if (!visibleTargets.length && !prepared.commandPackages.length && !prepared.commandDiscoveryErrors.length) {
1244
- if (prepared.plan.blockExecution || prepared.plan.receipt.blockers.length || prepared.plan.receipt.errors.length)
1245
- return undefined;
1246
- return { skipReason: 'noVisibleTarget' };
1247
- }
652
+ const hasGeneric = requestedTargets.some((target) => target.agent === 'generic');
653
+ const visibleTargets = requestedTargets.flatMap((target) => target.agent === 'generic' ? [] : [{
654
+ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId,
655
+ platform: target.agent, scope: target.scope,
656
+ }]);
1248
657
  const impact = await analyzePluginConfigMutationImpact({ plugin: options.plugin, scope: options.context ?? options.scope,
1249
658
  platform: options.platform, cwd: options.cwd, env: options.env, visibleTargets,
1250
659
  commandDiscovery: { packages: prepared.commandPackages, errors: prepared.commandDiscoveryErrors },
1251
660
  referencePlugins: options.rebuildRuntime?.referencePlugins,
1252
661
  mutation: 'request' in options ? { kind: 'patch', ...options.request } : { kind: 'reset' } });
1253
- return { applyTargets: impact.affectedTargets,
662
+ if (options.expectedCommandPackageEvidence) {
663
+ const referencePlugins = prepared.plan.runtime.referencePlugins ?? [];
664
+ const plugins = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env, plugins: referencePlugins });
665
+ const entries = await prepareConfigCommandPackages({ ...options, plugin: options.plugin,
666
+ mutation: 'request' in options ? { kind: 'patch', ...options.request } : { kind: 'reset' } }, impact.affectedCommandPackages, plugins, referencePlugins);
667
+ await Promise.all(entries.map(({ candidate }) => candidate?.cleanup()));
668
+ }
669
+ if (!hasGeneric && !visibleTargets.length && !prepared.commandPackages.length && !prepared.commandDiscoveryErrors.length) {
670
+ if (prepared.plan.blockExecution || prepared.plan.receipt.blockers.length || prepared.plan.receipt.errors.length)
671
+ return undefined;
672
+ return { skipReason: 'noVisibleTarget' };
673
+ }
674
+ return { applyTargets: hasGeneric ? undefined : impact.affectedTargets,
1254
675
  applyCommandPackages: impact.affectedCommandPackages.map((target) => target.packageId),
1255
- ...(impact.noEffectiveChange ? { skipReason: 'noEffectiveConfigChange' } : {}) };
676
+ ...(!hasGeneric && impact.noEffectiveChange ? { skipReason: 'noEffectiveConfigChange' } : {}) };
1256
677
  }
1257
- catch {
678
+ catch (error) {
679
+ if (error?.code === 'operationReviewStale' || recoveryInterruptionCode(error, options.rebuildRuntime?.signal))
680
+ throw error;
1258
681
  // A failed output discovery must not prevent a valid configuration save.
1259
682
  return undefined;
1260
683
  }
@@ -1436,8 +859,11 @@ export async function resetPluginConfigWithHelper(options) {
1436
859
  apply: false, awHomeMutationToken, rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken } });
1437
860
  if (options.apply !== true)
1438
861
  return saved;
1439
- if (!options.plugin)
1440
- return { ...saved, overallState: 'partial', apply: unavailableApply('sourceUnavailable', 'source') };
862
+ if (!options.plugin) {
863
+ const apply = unavailableApply('sourceUnavailable', 'source');
864
+ const cause = configActiveAvailabilityError(options.pluginError);
865
+ return { ...saved, overallState: 'partial', apply: cause ? { ...apply, error: { stage: 'source', ...cause } } : apply };
866
+ }
1441
867
  if (saved.apply.state === 'skipped' && saved.apply.reason === 'noConfigChange')
1442
868
  return saved;
1443
869
  if (selection?.skipReason)