@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,5 +1,6 @@
1
- import { getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
2
- import { finalizePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
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';
3
4
  import { addRequirements } from '../commands/intent-command.js';
4
5
  import { createEmptyIntent, calculateIntentDigest, removeIntentRoot } from '../intent/intent-codec.js';
5
6
  import { observeIntent, writeIntent, resolveIntentPath } from '../intent/intent-store.js';
@@ -20,7 +21,7 @@ import { parsePluginId } from '../utils/multi-source-catalog.js';
20
21
  import { readDemand, resolveDelivery } from './demand.js';
21
22
  import { hasSharedUserPackage } from '../platforms/layout.js';
22
23
  import { preparePortableRecovery } from '../portable/recovery.js';
23
- import { canReuseProviderAcrossScopes, readJointDemand, deriveJointDemand, deriveSharedReferenceView, indexJointDependencies } from './joint-demand.js';
24
+ import { canReuseProviderAcrossScopes, hasInheritableSkills, isInstalledSkillProvider, projectSkillCandidates, readJointDemand, deriveJointDemand, deriveSharedReferenceView, indexJointDependencies } from './joint-demand.js';
24
25
  import { checkFootprints, prepareScopedRecovery, executeScopedRecovery, executeRecoveryPreApply, refreshRecoveryNativePreviews, describeRecoveryPlan, errorCode } from './coordinator.js';
25
26
  import { isTargetObservationReadError, readScopedRecoveryStatus, readRecoveryStatus } from './status.js';
26
27
  import { recoveryRetryDispositions, recoveryStatusContext, retriesFromRequestedRoots } from './receipt.js';
@@ -119,8 +120,11 @@ function mergeReceipts(plan, receipts) {
119
120
  target.relation = selectedContributions.some((item) => item.root === target.pluginId && item.scope === target.scope) ? 'root' : 'dependency';
120
121
  if (target.relation === 'dependency')
121
122
  target.contributions = selectedContributions;
122
- if (placement.scope !== target.scope)
123
+ if (placement.scope !== target.scope) {
123
124
  target.requirementScope = target.scope;
125
+ if (target.satisfaction === 'installed' && placement.scope === 'user')
126
+ target.satisfaction = 'inherited-user';
127
+ }
124
128
  }
125
129
  }
126
130
  const executed = new Set(receipt.targetResults.map(targetKey));
@@ -159,6 +163,9 @@ function mergeReceipts(plan, receipts) {
159
163
  receipt.outputsMayHaveChanged = receipts.some((item) => item.outputsMayHaveChanged);
160
164
  receipt.commandResults = receipts.flatMap((item) => item.commandResults ?? []);
161
165
  receipt.nativeToolChanges = receipts.flatMap((item) => item.nativeToolChanges ?? []);
166
+ if (plan.portableCommandWithdrawals?.length) {
167
+ receipt.nativeToolChanges = operationPlanNativeToolChanges({ actions: plan.portableCommandWithdrawals, nativeToolChanges: receipt.nativeToolChanges });
168
+ }
162
169
  receipt.recoveryActions = [...new Set(actions)];
163
170
  receipt.ok = receipt.blockers.length === 0 && receipts.every((item) => item.ok);
164
171
  return receipt;
@@ -228,7 +235,7 @@ async function readJointPreparation(command, options, locked = false, suppliedRe
228
235
  /** Complete requirements determine placement before execution selectors are applied. */
229
236
  export async function prepareJointRecovery(command, selectors, options, runtime, preparation) {
230
237
  const originalRunner = runtime.nativeCliRunner ?? getDefaultNativeCliRunner();
231
- runtime = { ...runtime, ...(isInstallBatch(command) ? { nativeCliRunner: limitInstallNativeRunner(originalRunner) } : {}),
238
+ runtime = { ...runtime, invocationCwd: runtime.invocationCwd ?? options.cwd, ...(isInstallBatch(command) ? { nativeCliRunner: limitInstallNativeRunner(originalRunner) } : {}),
232
239
  preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
233
240
  const { snapshot, catalogReadScope, manifestReads } = preparation ?? await readJointPreparation(command, options, false, runtime.catalogReadScope);
234
241
  const prepare = async (current) => {
@@ -322,7 +329,14 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
322
329
  targets: normalizeAgents([...snapshot.preferences.targets, ...installed.map((item) => item.agent)]) };
323
330
  }
324
331
  }
325
- const previousDemand = deriveJointDemand(snapshot);
332
+ let previousDemand = deriveJointDemand(snapshot);
333
+ const previousCandidates = projectSkillCandidates(previousDemand);
334
+ if (command === 'uninstall' && previousCandidates.length) {
335
+ observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined }, savedDemand);
336
+ previousDemand = deriveJointDemand(snapshot, observedStatus.projectSkillProviders);
337
+ }
338
+ const previousUserProvided = (pluginId, target) => previousDemand.placements.some((item) => item.pluginId === pluginId && item.target === target && item.scope === 'user'
339
+ && item.contributions.some((entry) => entry.scope === 'project'));
326
340
  const previousPlugins = [...new Map([...(snapshot.user.plugins), ...(snapshot.project?.plugins ?? [])]
327
341
  .map((plugin) => [plugin.pluginId, plugin])).values()];
328
342
  const dependencyClosures = new Map();
@@ -410,7 +424,31 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
410
424
  }
411
425
  }
412
426
  }
413
- const demand = deriveJointDemand(snapshot);
427
+ let demand = deriveJointDemand(snapshot);
428
+ const pendingUserSkills = [];
429
+ const candidates = projectSkillCandidates(demand).filter((item) => !options.targets || options.targets.includes(item.target));
430
+ if (candidates.length) {
431
+ observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined,
432
+ projectSkillProbes: candidates }, savedDemand);
433
+ const providers = observedStatus.projectSkillProviders?.map((provider) => {
434
+ if ((!provider.userNeedsRepair && !provider.userAbsent) || provider.projectCopy === 'blocked' || command !== 'sync' || options.existingOnly)
435
+ return provider;
436
+ // A joint sync can repair its selected, owned User package before the Project consumer runs.
437
+ const owned = observedStatus.observedTargets?.some((target) => target.pluginId === provider.pluginId && target.agent === provider.target
438
+ && target.scope === 'user' && target.content === 'drifted' && !target.blockers.length
439
+ && target.deploymentObservations?.every(({ after }) => after.ownership === 'aw'));
440
+ const selectedUserRoot = demand.placements.some((item) => item.scope === 'user' && item.pluginId === provider.pluginId
441
+ && item.target === provider.target && item.contributions.some((entry) => entry.scope === 'user'
442
+ && (!selectors.length || selectors.some((id) => id === entry.root || id === parsePluginId(entry.root).pluginName))
443
+ && (!options.exactTargets || options.exactTargets.some((exact) => exact.scope === 'user'
444
+ && exact.agent === item.target && exact.pluginId === entry.root))));
445
+ if (!selectedUserRoot || !owned && !provider.userAbsent)
446
+ return provider;
447
+ pendingUserSkills.push({ pluginId: provider.pluginId, target: provider.target, sourceIdentity: provider.sourceIdentity });
448
+ return { ...provider, userNeedsRepair: false, userAbsent: false };
449
+ });
450
+ demand = deriveJointDemand(snapshot, providers);
451
+ }
414
452
  const rootIds = [...new Set([...(snapshot.user.roots ?? []), ...(snapshot.project?.roots ?? [])]
415
453
  .map((root) => root.pluginId))];
416
454
  if (command !== 'install' && command !== 'uninstall') {
@@ -461,7 +499,7 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
461
499
  if (!targets.includes(placement.target))
462
500
  return false;
463
501
  if (command === 'uninstall')
464
- return canReuseProviderAcrossScopes(placement.target)
502
+ return (canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target))
465
503
  && !(options.force && requestedIds.has(placement.pluginId))
466
504
  && previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId && previous.target === placement.target
467
505
  && previous.scope !== placement.scope && previous.contributions.some((item) => item.scope === scope && requestedIds.has(item.root))
@@ -544,7 +582,7 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
544
582
  };
545
583
  const children = [];
546
584
  const { signal: _signal, ...executionOptions } = options;
547
- const joint = { snapshot, demand, unplacedRoots, removalDependencies: dependencyClosures, selectedContributions, children, originalOptions: executionOptions,
585
+ const joint = { snapshot, demand, unplacedRoots, removalDependencies: dependencyClosures, selectedContributions, children, originalOptions: executionOptions, pendingUserSkills, providerRetirements: new Set(),
548
586
  selectors: [...selectors], declaration, evidence };
549
587
  const plan = { command, options: { ...executionOptions, scope }, receipt, context, demand: baseDemand,
550
588
  originalIntent: observationEvidence(original.intent), preferencesEvidence: observationEvidence(snapshot.user.preferences),
@@ -567,9 +605,10 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
567
605
  const sharedReferenceView = deriveSharedReferenceView(snapshot, demand, currentStatus);
568
606
  const ownsOutput = (item) => currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId
569
607
  && owned.agent === item.agent && owned.scope === item.scope) === true;
570
- const liveConsumers = currentStatus.existingTargets ?? [];
608
+ const liveTargets = currentStatus.existingTargets ?? [];
609
+ const liveConsumers = [...liveTargets, ...(currentStatus.retainedProjectPackages ?? [])];
571
610
  const sameProvider = (consumer, provider) => consumer.agent === provider.agent && (consumer.scope === provider.scope
572
- || provider.scope === 'user' && canReuseProviderAcrossScopes(consumer.agent));
611
+ || provider.scope === 'user' && (canReuseProviderAcrossScopes(consumer.agent) || previousUserProvided(provider.pluginId, consumer.agent)));
573
612
  const automaticRetirements = command === 'uninstall' && !options.keepDependencies && demand.complete
574
613
  ? previousDemand.placements.filter((placement) => placement.scope === scope && targets.includes(placement.target)
575
614
  && (placement.target !== 'generic' ? currentStatus.coverage.native : currentStatus.coverage.portable)
@@ -578,20 +617,36 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
578
617
  : snapshot[placement.scope]?.roots?.some((root) => root.pluginId === placement.pluginId))
579
618
  && placement.contributions.some((item) => explicitlyRemoves({ pluginId: item.root, agent: placement.target, scope: item.scope }))
580
619
  && !demand.placements.some((item) => item.pluginId === placement.pluginId && item.target === placement.target
581
- && (item.scope === placement.scope || canReuseProviderAcrossScopes(placement.target)))
620
+ && (item.scope === placement.scope || canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target)))
582
621
  && ownsOutput({ pluginId: placement.pluginId, agent: placement.target, scope: placement.scope })) : [];
583
622
  // A live consumer can outlast its Intent or its Active catalog entry.
584
623
  const retainedConsumerFor = (provider) => liveConsumers.find((consumer) => {
585
624
  if (explicitlyRemoves(consumer) && ownsOutput(consumer) || automaticRetirements.some((item) => item.pluginId === consumer.pluginId && item.target === consumer.agent && item.scope === consumer.scope))
586
625
  return false;
587
- if (!sameProvider(consumer, provider))
626
+ const sourceIdentity = consumer.nativePackage?.sourceIdentity;
627
+ const providerManifest = sourceIdentity && previousPlugins.find((plugin) => plugin.pluginId === provider.pluginId && plugin.sourceIdentity === sourceIdentity);
628
+ if (consumer.dependencies !== undefined && !providerManifest)
588
629
  return false;
589
- const closure = dependencies(consumer.pluginId);
630
+ const liveNativeInheritance = provider.scope === 'user' && consumer.scope === 'project' && consumer.agent === provider.agent
631
+ && providerManifest && !canReuseProviderAcrossScopes(consumer.agent) && hasInheritableSkills(providerManifest)
632
+ && liveTargets.some((item) => item.pluginId === provider.pluginId && item.agent === provider.agent && item.scope === 'user'
633
+ && item.nativePackage?.sourceIdentity === sourceIdentity);
634
+ if (!sameProvider(consumer, provider) && !liveNativeInheritance)
635
+ return false;
636
+ const closure = consumer.dependencies === undefined ? dependencies(consumer.pluginId) : consumer.dependencies;
590
637
  if (!closure?.includes(provider.pluginId) && !(closure === null
591
638
  && parsePluginId(consumer.pluginId).sourceId === parsePluginId(provider.pluginId).sourceId))
592
639
  return false;
640
+ if (liveNativeInheritance) {
641
+ const projectCopyReady = liveTargets.some((item) => item.pluginId === provider.pluginId
642
+ && item.agent === provider.agent && item.scope === 'project' && item.nativePackage?.sourceIdentity === sourceIdentity
643
+ && item.nativePackage?.skillsReady);
644
+ const stagedReplacement = selected.some((item) => item.pluginId === provider.pluginId
645
+ && item.target === provider.agent && item.scope === 'project' && item.plugin.sourceIdentity === sourceIdentity);
646
+ return !projectCopyReady && !stagedReplacement;
647
+ }
593
648
  return !demand.placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.agent
594
- && item.scope !== provider.scope && sameProvider(consumer, { agent: item.target, scope: item.scope }));
649
+ && item.scope !== provider.scope && sameProvider(consumer, { pluginId: item.pluginId, agent: item.target, scope: item.scope }));
595
650
  });
596
651
  for (let index = automaticRetirements.length - 1; index >= 0; index--) {
597
652
  const candidate = automaticRetirements[index];
@@ -648,29 +703,51 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
648
703
  const nativeTargets = targets.filter((target) => target !== 'generic');
649
704
  const batch = isInstallBatch(command);
650
705
  const hasSelectedScripts = selected.some((item) => item.plugin.manifest.scripts?.preApply);
706
+ if (batch && nativeObservationBatch && [...demand.placements, ...selected].every(({ plugin }) => {
707
+ const { command, scripts } = plugin.manifest;
708
+ return command?.mode !== 'dynamic' && !scripts?.artifacts?.render && !scripts?.preApply && !scripts?.node?.build;
709
+ }))
710
+ nativeObservationBatch.scriptFreePlacement = true;
651
711
  const portableGenerations = new Map();
652
712
  const targetGroups = batch ? [...nativeTargets, ...targets.filter((target) => target === 'generic')].map((target) => [target])
653
713
  : [...(nativeTargets.length ? [nativeTargets] : []), ...targets.filter((target) => target === 'generic').map((target) => [target])];
714
+ const inheritedScripts = command === 'sync' && !options.existingOnly ? new Set(selected.filter((item) => {
715
+ if (item.scope !== 'user' || !item.plugin.manifest.scripts?.preApply)
716
+ return false;
717
+ const contributions = selectedContributions.get(item);
718
+ return !contributions.some((entry) => entry.scope === 'user')
719
+ && contributions.some((entry) => entry.scope === 'project' && entry.root !== item.pluginId)
720
+ && !(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))));
721
+ })) : new Set();
722
+ const preparedPlacements = selected.filter((item) => !(item.scope === 'user' && !canReuseProviderAcrossScopes(item.target)
723
+ && selectedContributions.get(item)?.every((entry) => entry.scope === 'project')
724
+ && currentStatus.observedTargets?.some((actual) => actual.pluginId === item.pluginId
725
+ && actual.agent === item.target && isInstalledSkillProvider(actual)))
726
+ && !(command === 'install' && scope === 'project' && item.scope === 'user'
727
+ && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
728
+ && observed.agent === item.target && observed.scope === 'user' && observed.content === 'satisfied'))
729
+ && !(hasSharedUserPackage(item.target) && inheritedScripts.has(item)
730
+ && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
731
+ && observed.agent === item.target && observed.scope === 'user' && observed.providerScope === 'user'
732
+ && observed.observation === 'verified' && observed.content === 'satisfied' && !observed.blockers.length)));
733
+ // Split provider and host groups must publish the same shared revision.
734
+ const commandPackagePlatforms = new Map();
735
+ for (const { pluginId, plugin, target, scope } of preparedPlacements) {
736
+ if (target === 'generic' || !plugin.manifest.command?.platforms.includes(target)
737
+ || activationOnlyTargets.some((entry) => entry.pluginId === pluginId && entry.platform === target && entry.scope === scope))
738
+ continue;
739
+ const platforms = commandPackagePlatforms.get(pluginId) ?? [];
740
+ if (!platforms.includes(target))
741
+ platforms.push(target);
742
+ commandPackagePlatforms.set(pluginId, platforms);
743
+ }
744
+ runtime = { ...runtime, commandPackagePlatforms, retainCommandPackages: command === 'uninstall' };
745
+ plan.runtime = runtime;
654
746
  for (const currentScope of snapshot.context.scopes) {
655
747
  const prepareGroup = async (groupTargets) => {
656
- const inheritedScripts = currentScope === 'user' && command === 'sync' && !options.existingOnly
657
- ? selected.filter((item) => {
658
- if (item.scope !== 'user' || !groupTargets.includes(item.target) || !item.plugin.manifest.scripts?.preApply)
659
- return false;
660
- const contributions = selectedContributions.get(item);
661
- return !contributions.some((entry) => entry.scope === 'user')
662
- && contributions.some((entry) => entry.scope === 'project' && entry.root !== item.pluginId)
663
- && !(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))));
664
- }) : [];
665
- const inheritedPortableProviderIds = inheritedScripts.filter((item) => item.target === 'generic').map((item) => item.pluginId);
666
- const placements = selected.filter((item) => item.scope === currentScope && groupTargets.includes(item.target)
667
- && !(command === 'install' && scope === 'project' && currentScope === 'user'
668
- && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
669
- && observed.agent === item.target && observed.scope === 'user' && observed.content === 'satisfied'))
670
- && !(hasSharedUserPackage(item.target) && inheritedScripts.includes(item)
671
- && currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
672
- && observed.agent === item.target && observed.scope === 'user' && observed.providerScope === 'user'
673
- && observed.observation === 'verified' && observed.content === 'satisfied' && !observed.blockers.length)));
748
+ const inheritedPortableProviderIds = currentScope === 'user' && groupTargets.includes('generic')
749
+ ? [...inheritedScripts].filter((item) => item.target === 'generic').map((item) => item.pluginId) : [];
750
+ const placements = preparedPlacements.filter((item) => item.scope === currentScope && groupTargets.includes(item.target));
674
751
  if (!placements.length)
675
752
  return;
676
753
  const sourceDemand = currentScope === 'project' ? snapshot.project : snapshot.user;
@@ -823,13 +900,29 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
823
900
  || selected.some((placement) => canReuseProviderAcrossScopes(placement.target)
824
901
  && placement.pluginId === item.pluginId && placement.target === item.agent && placement.scope !== item.scope
825
902
  && (item.delivery?.kind !== 'agent-skills' || item.backend?.logicalIdentity === placement.plugin.catalogLogicalIdentity))));
903
+ if (scope === 'project')
904
+ for (const provider of currentStatus.projectSkillProviders ?? []) {
905
+ if (provider.target === 'generic' || provider.projectCopy !== 'owned' || !selected.some((placement) => placement.pluginId === provider.pluginId
906
+ && placement.target === provider.target && placement.scope === 'user'
907
+ && selectedContributions.get(placement)?.some((entry) => entry.scope === 'project')))
908
+ continue;
909
+ const position = { pluginId: provider.pluginId, agent: provider.target, scope: 'project' };
910
+ if (ownsOutput(position)) {
911
+ joint.providerRetirements.add(targetKey(position));
912
+ retire.push({ ...position, delivery: { kind: 'native', platform: provider.target }, observation: 'verified' });
913
+ }
914
+ }
826
915
  for (const item of currentStatus.observedTargets ?? []) {
827
- if (ownsOutput(item) && !requiredNativeActivation(item) && selected.some((placement) => canReuseProviderAcrossScopes(placement.target)
916
+ if (ownsOutput(item) && !requiredNativeActivation(item) && selected.some((placement) => (canReuseProviderAcrossScopes(placement.target)
917
+ || command === 'uninstall' && item.scope === scope && previousUserProvided(placement.pluginId, placement.target))
828
918
  && placement.pluginId === item.pluginId
829
919
  && placement.target === item.agent && placement.scope !== item.scope)
830
920
  && !demand.placements.some((placement) => placement.pluginId === item.pluginId
831
- && placement.target === item.agent && placement.scope === item.scope))
921
+ && placement.target === item.agent && placement.scope === item.scope)) {
832
922
  retire.push(item);
923
+ if (item.agent && !canReuseProviderAcrossScopes(item.agent))
924
+ joint.providerRetirements.add(targetKey(item));
925
+ }
833
926
  }
834
927
  // A removed declaration is still present in the observed snapshot, so include its exact old outputs.
835
928
  if (command === 'uninstall')
@@ -970,6 +1063,28 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
970
1063
  }
971
1064
  }
972
1065
  }
1066
+ if ((batch || command === 'reinstall') && !options.existingOnly) {
1067
+ const eligible = children.filter((child) => child.command !== 'cleanup').flatMap((child) => child.receipt.targetResults.filter((target) => target.agent === 'generic' && target.delivery?.kind === 'agent-skills'
1068
+ && !target.blockers.length));
1069
+ const eligiblePositions = new Set(eligible.map(targetKey));
1070
+ const candidates = [...new Map(preparedPlacements.filter((item) => item.target === 'generic'
1071
+ && !item.plugin.manifest.command && eligiblePositions.has(targetKey({ ...item, agent: item.target })))
1072
+ .map((item) => [item.pluginId, item.plugin])).entries()];
1073
+ const reviewCwd = snapshot.context.projectRoot ?? context.executionCwd;
1074
+ const prepared = await mapInstallReads(candidates, async ([pluginId, plugin]) => {
1075
+ try {
1076
+ return await preparePortableCommandWithdrawal(plugin, reviewCwd, context.env);
1077
+ }
1078
+ catch (error) {
1079
+ if (recoveryInterruptionCode(error, options.signal))
1080
+ throw error;
1081
+ for (const target of eligible.filter((item) => item.pluginId === pluginId)) {
1082
+ target.blockers.push(diagnostic(errorCode(error, 'commandPackagePreparationFailed')));
1083
+ }
1084
+ }
1085
+ }, { signal: options.signal });
1086
+ plan.portableCommandWithdrawals = prepared.filter((entry) => entry !== undefined);
1087
+ }
973
1088
  finalizePreparedPlatformRebuildSession(runtime.preparedArtifactRenderResults);
974
1089
  plan.sourceRefreshes = [...new Map(children.flatMap((child) => child.sourceRefreshes).map((item) => [item.sourceId, item])).values()];
975
1090
  plan.sourceRefreshFailures = [...new Map(children.flatMap((child) => child.sourceRefreshFailures).map((item) => [item.sourceId, item])).values()];
@@ -1010,6 +1125,9 @@ export async function executeJointRecovery(plan, execution) {
1010
1125
  let completedReceipt;
1011
1126
  let lockWaitStartedAt;
1012
1127
  try {
1128
+ if (plan.portableCommandWithdrawals?.length && (execution.yes ?? plan.options.yes) !== true) {
1129
+ return blockedBeforeDeployment(plan, diagnostic('confirmationRequired'));
1130
+ }
1013
1131
  if (plan.sourceRefreshes.length) {
1014
1132
  plan.receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
1015
1133
  const receipt = mergeReceipts(plan, joint.children.map((child) => child.receipt));
@@ -1041,7 +1159,7 @@ export async function executeJointRecovery(plan, execution) {
1041
1159
  const checked = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.recheck', () => prepareJointRecovery(plan.command, joint.selectors, preparation.options, { ...performanceRuntime, awHomeMutationToken: token }, preparation.catalogReadScope ? preparation : undefined));
1042
1160
  const stable = !checked.blockExecution && JSON.stringify(describeRecoveryPlan(plan)) === JSON.stringify(describeRecoveryPlan(checked));
1043
1161
  lockedPlan = checked;
1044
- const parallel = isInstallBatch(plan.command) && !joint.children.some((child) => child.command === 'cleanup');
1162
+ const parallel = isInstallBatch(plan.command) && !joint.pendingUserSkills.length && !joint.children.some((child) => child.command === 'cleanup');
1045
1163
  const children = parallel ? checked.joint.children : joint.children;
1046
1164
  if (!stable)
1047
1165
  return blockedBeforeDeployment(plan);
@@ -1086,7 +1204,9 @@ export async function executeJointRecovery(plan, execution) {
1086
1204
  const failedPackages = new Set();
1087
1205
  const failedNodes = new Set();
1088
1206
  const packageResults = [];
1089
- const runtime = { ...performanceRuntime, awHomeMutationToken: token };
1207
+ const runtime = { ...performanceRuntime, awHomeMutationToken: token,
1208
+ commandPackagePlatforms: checked.runtime.commandPackagePlatforms,
1209
+ retainCommandPackages: checked.runtime.retainCommandPackages };
1090
1210
  runtime.preApplyExecutionCache ??= new Map();
1091
1211
  runtime.managedCommandProducerCache ??= new Map();
1092
1212
  let interrupted;
@@ -1097,23 +1217,27 @@ export async function executeJointRecovery(plan, execution) {
1097
1217
  results.push(...installed.receipts);
1098
1218
  packageResults.push(...installed.commands);
1099
1219
  plan.receipt.blockers.push(...installed.blockers);
1100
- for (const result of installed.commands)
1101
- if (result.state !== 'completed')
1102
- failedPackages.add(getCommandPackageId(result.producer));
1103
1220
  }
1104
1221
  else {
1105
1222
  const packages = runtime.configApplyPackages;
1106
1223
  const dependencyGraph = indexJointDependencies(joint.demand);
1224
+ const readCurrentProviders = (plugins, targets) => {
1225
+ const { cwd, env, cliVersion } = joint.originalOptions;
1226
+ return readRecoveryStatus({ cwd, env, cliVersion, context: joint.snapshot.context.context,
1227
+ expectedProjectRoot: joint.snapshot.context.projectRoot, plugins: [...new Set(plugins)], targets: [...new Set(targets)],
1228
+ nativeCliRunner: runtime.nativeCliRunner, signal: runtime.signal });
1229
+ };
1107
1230
  const portableProgress = { completed: [], failed: [] };
1108
1231
  const failedCleanups = [];
1109
1232
  const executeChild = async (child, pluginIds, agent) => {
1233
+ const childRuntime = { ...runtime, batchInstallPlatform: child.runtime.batchInstallPlatform };
1110
1234
  const currentIntent = await observeIntent(child.options);
1111
1235
  if (!joint.originalOptions.existingOnly)
1112
1236
  child.demand.intent = currentIntent;
1113
1237
  const fresh = await measureRecoveryPerformanceStage(runtime, 'recovery.child.plan', () => prepareScopedRecovery(child.command, typeof pluginIds === 'string' ? [pluginIds] : pluginIds, {
1114
1238
  ...child.options, targets: agent !== 'generic' ? child.options.targets : [agent], all: false,
1115
1239
  exactTargets: child.options.exactTargets?.filter((target) => (typeof pluginIds === 'string' ? [pluginIds] : pluginIds).includes(target.pluginId)),
1116
- }, runtime));
1240
+ }, childRuntime));
1117
1241
  fresh.originalIntent = observationEvidence(currentIntent);
1118
1242
  for (const target of fresh.receipt.targetResults) {
1119
1243
  const reviewed = child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
@@ -1125,7 +1249,7 @@ export async function executeJointRecovery(plan, execution) {
1125
1249
  // Keep only joint constraints and an already failed script gate.
1126
1250
  target.blockers.push(...(reviewed?.blockers ?? []).filter((error) => reviewed?.execution === 'failed'
1127
1251
  || ['configApplyRequiresExistingOutput', 'crossScopeSkillCollision', 'targetPlacementConflict',
1128
- 'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed', 'dependencyStillRequired'].includes(error.code)));
1252
+ 'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed', 'providerSwitchVerificationFailed', 'dependencyStillRequired'].includes(error.code)));
1129
1253
  if (reviewed?.execution === 'failed') {
1130
1254
  target.execution = 'failed';
1131
1255
  if (reviewed.backend)
@@ -1147,7 +1271,21 @@ export async function executeJointRecovery(plan, execution) {
1147
1271
  message: `依赖提供者 ${failedDependency.pluginId}(${failedDependency.target}/${failedDependency.scope})未完成。` });
1148
1272
  }
1149
1273
  }
1150
- const result = await measureRecoveryPerformanceStage(runtime, 'recovery.child.execute', () => executeScopedRecovery(fresh, { ...execution, runtime,
1274
+ if (child.command !== 'cleanup' && child.options.scope === 'project') {
1275
+ const required = joint.pendingUserSkills.filter((item) => fresh.receipt.targetResults.some((target) => target.agent === item.target && dependencyGraph.reaches(target.pluginId, item.pluginId)));
1276
+ if (required.length) {
1277
+ const verified = await readCurrentProviders(required.map((item) => item.pluginId), required.map((item) => item.target));
1278
+ for (const provider of required) {
1279
+ if (verified.projectSkillProviders?.some((item) => item.pluginId === provider.pluginId && item.target === provider.target
1280
+ && item.sourceIdentity === provider.sourceIdentity && !item.userAbsent && !item.userNeedsRepair && item.projectCopy !== 'blocked'))
1281
+ continue;
1282
+ for (const target of fresh.receipt.targetResults.filter((item) => item.agent === provider.target
1283
+ && dependencyGraph.reaches(item.pluginId, provider.pluginId)))
1284
+ target.blockers.push(diagnostic('userProviderNotSatisfied'));
1285
+ }
1286
+ }
1287
+ }
1288
+ const result = await measureRecoveryPerformanceStage(runtime, 'recovery.child.execute', () => executeScopedRecovery(fresh, { ...execution, runtime: childRuntime,
1151
1289
  ...(plan.command !== 'uninstall' && child.command !== 'cleanup' ? { portableProgress } : {}) }));
1152
1290
  if (joint.originalOptions.existingOnly)
1153
1291
  for (const target of result.targetResults) {
@@ -1164,7 +1302,9 @@ export async function executeJointRecovery(plan, execution) {
1164
1302
  };
1165
1303
  // Provider changes can remove a working output. Complete the replacement's
1166
1304
  // authorization and scripts first, sharing the normal execution cache.
1167
- const cleanupChildren = joint.children.filter((child) => child.command === 'cleanup');
1305
+ const cleanups = joint.children.filter((child) => child.command === 'cleanup');
1306
+ const deferred = cleanups.filter((child) => child.receipt.requestedTargets.some((target) => joint.providerRetirements.has(targetKey(target))));
1307
+ const cleanupChildren = cleanups.filter((child) => !deferred.includes(child));
1168
1308
  const replacementFailures = new Set();
1169
1309
  for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
1170
1310
  for (const target of child.receipt.targetResults) {
@@ -1192,9 +1332,12 @@ export async function executeJointRecovery(plan, execution) {
1192
1332
  }
1193
1333
  // Target exits can replace one Agent with another. Preserve the reviewed
1194
1334
  // old output when its corresponding replacement cannot run.
1195
- for (const child of joint.children.filter((child) => child.command === 'cleanup')) {
1335
+ const clean = async (child, verified = true, onSuccess) => {
1196
1336
  for (const target of child.receipt.requestedTargets) {
1197
- if (plan.command === 'uninstall' && failedCleanups.some((failed) => {
1337
+ if (!verified)
1338
+ child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
1339
+ .blockers.push(diagnostic('providerSwitchVerificationFailed', '替代位置尚未确认就绪,保留原输出。'));
1340
+ if ((plan.command === 'uninstall' || deferred.includes(child)) && failedCleanups.some((failed) => {
1198
1341
  if (failed.agent !== target.agent)
1199
1342
  return false;
1200
1343
  const required = joint.removalDependencies.get(failed.pluginId);
@@ -1214,8 +1357,49 @@ export async function executeJointRecovery(plan, execution) {
1214
1357
  const result = await executeChild(child, target.pluginId, target.agent);
1215
1358
  if (!result.ok)
1216
1359
  failedCleanups.push(...result.requestedTargets);
1360
+ else
1361
+ onSuccess?.(result);
1217
1362
  }
1218
- }
1363
+ };
1364
+ for (const child of cleanupChildren)
1365
+ await clean(child);
1366
+ const retireVerified = async (oldScope) => {
1367
+ const retiring = deferred.filter((child) => child.options.scope === oldScope);
1368
+ if (!retiring.length)
1369
+ return;
1370
+ const old = retiring.flatMap((child) => child.receipt.requestedTargets);
1371
+ const verified = await readCurrentProviders(old.map((item) => item.pluginId), old.map((item) => item.agent));
1372
+ for (const child of retiring) {
1373
+ const target = child.receipt.requestedTargets[0];
1374
+ const replacement = { ...target, scope: oldScope === 'user' ? 'project' : 'user' };
1375
+ const reviewedSource = joint.demand.placements.find((item) => item.pluginId === replacement.pluginId
1376
+ && item.scope === replacement.scope && item.target === replacement.agent)?.plugin.sourceIdentity;
1377
+ const confirmed = reviewedSource && !failedProviders.has(targetKey(replacement)) && (oldScope === 'project'
1378
+ ? verified.projectSkillProviders?.some((item) => item.pluginId === target.pluginId && item.target === target.agent
1379
+ && item.sourceIdentity === reviewedSource && !item.userAbsent && !item.userNeedsRepair && item.projectCopy === 'owned')
1380
+ : verified.observedTargets?.some((item) => targetKey(item) === targetKey(replacement)
1381
+ && item.observation === 'verified' && item.content === 'satisfied' && !item.blockers.length)
1382
+ && verified.existingTargets?.some((item) => targetKey(item) === targetKey(replacement)
1383
+ && item.nativePackage?.sourceIdentity === reviewedSource && item.nativePackage.skillsReady));
1384
+ await clean(child, Boolean(confirmed), (receipt) => {
1385
+ const projectRoot = joint.snapshot.context.projectRoot;
1386
+ if (!confirmed || !projectRoot || oldScope !== 'project' || target.agent !== 'grok' || !runtime.preparedArtifactRenderResults)
1387
+ return;
1388
+ const project = verified.extraObserved.find((item) => item.pluginId === target.pluginId && item.agent === 'grok' && item.scope === 'project')
1389
+ ?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-directory')?.after;
1390
+ const user = verified.observedTargets?.find((item) => targetKey(item) === targetKey(replacement))
1391
+ ?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-cli')?.after;
1392
+ const backend = receipt.targetResults.find((item) => targetKey(item) === targetKey(target))?.backend;
1393
+ const removed = backend?.command === 'cleanup' && backend.ok ? backend.targetResults.find(({ target: item }) => item.pluginId === target.pluginId && item.platform === 'grok' && item.scope === 'project')?.removed : undefined;
1394
+ const reviewedRemoval = child.nativeGroups.some(({ preview }) => preview.operationPlan?.actions.some((action) => action.kind === 'removeOwnedArtifact' && action.pluginId === target.pluginId && action.platform === 'grok'
1395
+ && action.scope === 'project' && action.path === project?.nativeIdentity?.sourceLocation));
1396
+ if (project && user && reviewedRemoval && removed?.length) {
1397
+ recordPreparedGrokProjectRetirement(runtime.preparedArtifactRenderResults, projectRoot, project, user, removed);
1398
+ }
1399
+ });
1400
+ }
1401
+ };
1402
+ let retiredProjectCopies = false;
1219
1403
  const nodes = new Map();
1220
1404
  const nodeFor = (pluginId, scope) => {
1221
1405
  const key = `${pluginId}\0${scope}`;
@@ -1230,11 +1414,11 @@ export async function executeJointRecovery(plan, execution) {
1230
1414
  for (const target of child.receipt.requestedTargets)
1231
1415
  nodeFor(target.pluginId, target.scope).targets.push({ child, agent: target.agent });
1232
1416
  }
1233
- const hasNative = (node) => node.targets.some(({ agent }) => agent !== 'generic');
1417
+ const consumesPackage = (node, target) => !target.blocker && node.targets.some(({ agent }) => agent !== 'generic' && target.platforms.includes(agent));
1234
1418
  for (const target of packages?.targets ?? []) {
1235
1419
  const sameScope = nodes.get(`${target.pluginId}\0${target.scope}`);
1236
- const native = sameScope && hasNative(sameScope) ? sameScope
1237
- : [...nodes.values()].find((node) => node.pluginId === target.pluginId && hasNative(node));
1420
+ const native = sameScope && consumesPackage(sameScope, target) ? sameScope
1421
+ : [...nodes.values()].find((node) => node.pluginId === target.pluginId && consumesPackage(node, target));
1238
1422
  const node = native ?? nodeFor(target.pluginId, target.scope);
1239
1423
  (node.packages ??= []).push(target);
1240
1424
  }
@@ -1261,7 +1445,7 @@ export async function executeJointRecovery(plan, execution) {
1261
1445
  const key = `${pluginId}\0${scope}`;
1262
1446
  completedPackages.set(key, produced);
1263
1447
  packageResults.push(...produced);
1264
- if (produced.some((result) => result.state !== 'completed')) {
1448
+ if (!produced.every(commandPackageProviderSatisfied)) {
1265
1449
  failedPackages.add(key);
1266
1450
  failedNodes.add(key);
1267
1451
  }
@@ -1276,17 +1460,19 @@ export async function executeJointRecovery(plan, execution) {
1276
1460
  };
1277
1461
  const blockPackages = (pluginId, scope, code) => completedPackages.get(`${pluginId}\0${scope}`)
1278
1462
  ?? recordPackages(pluginId, scope, packages?.blocked?.(pluginId, scope, code) ?? []);
1463
+ const nativePackages = (identity) => packages?.targets.filter((target) => target.pluginId === identity.pluginId
1464
+ && target.platforms.includes(identity.platform)
1465
+ && (target.scope === 'user' || target.scope === identity.scope)) ?? [];
1279
1466
  if (packages)
1280
1467
  runtime.nativeTargetExecution = {
1468
+ produces: (identity) => nativePackages(identity).length > 0,
1281
1469
  beforeApply: async (identity) => {
1282
1470
  const results = [];
1283
- for (const target of packages.targets.filter((target) => target.pluginId === identity.pluginId
1284
- && (target.scope === 'user' || target.scope === identity.scope)))
1471
+ for (const target of nativePackages(identity))
1285
1472
  results.push(...await applyPackages(target.pluginId, target.scope));
1286
1473
  return results;
1287
1474
  },
1288
- blocked: (identity, code) => packages.targets.filter((target) => target.pluginId === identity.pluginId
1289
- && (target.scope === 'user' || target.scope === identity.scope)).flatMap((target) => blockPackages(target.pluginId, target.scope, code === 'dependencyInstallFailed' ? 'dependencyApplyFailed' : code)),
1475
+ blocked: (identity, code) => nativePackages(identity).flatMap((target) => blockPackages(target.pluginId, target.scope, code === 'dependencyInstallFailed' ? 'dependencyApplyFailed' : code)),
1290
1476
  };
1291
1477
  while (pending.length) {
1292
1478
  const index = pending.findIndex((node) => {
@@ -1299,21 +1485,26 @@ export async function executeJointRecovery(plan, execution) {
1299
1485
  break;
1300
1486
  }
1301
1487
  const node = pending.splice(index, 1)[0];
1488
+ if (node.scope === 'project' && !retiredProjectCopies) {
1489
+ await retireVerified('project');
1490
+ retiredProjectCopies = true;
1491
+ }
1302
1492
  const key = `${node.pluginId}\0${node.scope}`;
1303
- if (node.packages?.length && packages && !hasNative(node)) {
1493
+ const standalonePackages = node.packages?.filter((target) => !consumesPackage(node, target)) ?? [];
1494
+ if (standalonePackages.length && packages) {
1304
1495
  if (failedNodes.has(key) || [...node.dependencies].some((dependency) => failedNodes.has(dependency))) {
1305
1496
  failedPackages.add(key);
1306
1497
  failedNodes.add(key);
1307
- for (const target of node.packages)
1498
+ for (const target of standalonePackages)
1308
1499
  blockPackages(target.pluginId, target.scope, 'dependencyApplyFailed');
1309
1500
  plan.receipt.blockers.push(diagnostic('commandPackageProviderNotSatisfied', node.pluginId));
1310
1501
  }
1311
1502
  else {
1312
1503
  try {
1313
1504
  const produced = [];
1314
- for (const target of node.packages)
1505
+ for (const target of standalonePackages)
1315
1506
  produced.push(...await applyPackages(target.pluginId, target.scope));
1316
- if (produced.some((result) => result.state !== 'completed')) {
1507
+ if (!produced.every(commandPackageProviderSatisfied)) {
1317
1508
  failedPackages.add(key);
1318
1509
  failedNodes.add(key);
1319
1510
  }
@@ -1342,18 +1533,33 @@ export async function executeJointRecovery(plan, execution) {
1342
1533
  }
1343
1534
  }
1344
1535
  }
1536
+ if (!retiredProjectCopies)
1537
+ await retireVerified('project');
1538
+ await retireVerified('user');
1345
1539
  }
1346
1540
  const receipt = mergeReceipts(plan, results);
1347
- receipt.commandResults = [...new Map([...packageResults, ...(receipt.commandResults ?? [])]
1348
- .map((result) => [getCommandPackageId(result.producer), result])).values()];
1541
+ completedReceipt = receipt;
1542
+ const commandResults = new Map([...packageResults, ...(receipt.commandResults ?? [])].map((result) => [result.packageId, result]));
1543
+ for (const action of plan.portableCommandWithdrawals ?? []) {
1544
+ if (interrupted || runtime.signal?.aborted)
1545
+ break;
1546
+ if (!receipt.targetResults.some((target) => target.pluginId === action.pluginId && target.agent === 'generic'
1547
+ && target.delivery?.kind === 'agent-skills' && !target.blockers.length && target.observation === 'verified'
1548
+ && ['applied', 'no-op'].includes(target.execution)))
1549
+ continue;
1550
+ const result = await runtime.managedCommandProducerCache.get(action.packageId)
1551
+ ?? await publishLifecycleCommandPackage(action, { cwd: joint.snapshot.context.projectRoot ?? plan.context.executionCwd }, { env: plan.context.env, reporter: runtime.reporter });
1552
+ commandResults.set(result.packageId, result);
1553
+ receipt.outputsMayHaveChanged ||= result.action === 'removed' || result.state === 'partial';
1554
+ }
1555
+ receipt.commandResults = [...commandResults.values()];
1349
1556
  receipt.recoveryActions = [...new Set([...receipt.recoveryActions,
1350
1557
  ...receipt.commandResults.flatMap((result) => result.recoveryActions)])];
1351
- receipt.ok &&= failedPackages.size === 0;
1352
- receipt.outputsMayHaveChanged ||= packageResults.some((result) => result.state === 'completed');
1558
+ receipt.ok &&= failedPackages.size === 0 && receipt.commandResults.every((result) => result.state === 'completed');
1559
+ receipt.outputsMayHaveChanged ||= packageResults.some(({ action, state }) => action !== 'unchanged' || state === 'partial');
1353
1560
  receipt.errors.push(...results.flatMap((result) => result.targetResults.flatMap((target) => target.blockers)));
1354
1561
  if (!receipt.ok && retriesFromRequestedRoots(receipt))
1355
1562
  useDeclaredRetryRoots(receipt);
1356
- completedReceipt = receipt;
1357
1563
  if (interrupted)
1358
1564
  throw interrupted;
1359
1565
  runtime.signal?.throwIfAborted();