@lesliechan721/aw 0.1.0-beta.73 → 0.1.0-beta.75

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 (370) hide show
  1. package/dist/authoring/assets/aw-runtime-config.mjs +65 -43
  2. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -1
  3. package/dist/authoring/scripts/add-skill.mjs +5 -14
  4. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  5. package/dist/authoring/scripts/init-plugin.mjs +4 -28
  6. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  7. package/dist/authoring/scripts/lib/plugin-version-check.mjs +2 -2
  8. package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
  9. package/dist/authoring/scripts/lib/skill-scaffold.mjs +0 -1
  10. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  11. package/dist/authoring/scripts/validate-plugin.mjs +234 -1422
  12. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  13. package/dist/scripts/aw-skill-eval-materializer.d.ts +2 -0
  14. package/dist/scripts/aw-skill-eval-materializer.js +19 -80
  15. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
  16. package/dist/scripts/bundle-plugins.js.map +1 -1
  17. package/dist/scripts/test-plugin-scripts.js +6 -8
  18. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  19. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  20. package/dist/src/commands/aw-capabilities.js +2 -2
  21. package/dist/src/commands/aw-capabilities.js.map +1 -1
  22. package/dist/src/commands/dependency-operation-plan.js +3 -3
  23. package/dist/src/commands/dependency-operation-plan.js.map +1 -1
  24. package/dist/src/commands/deployment-confirmation.d.ts +4 -0
  25. package/dist/src/commands/deployment-confirmation.js +20 -0
  26. package/dist/src/commands/deployment-confirmation.js.map +1 -0
  27. package/dist/src/commands/managed-commands.js +4 -2
  28. package/dist/src/commands/managed-commands.js.map +1 -1
  29. package/dist/src/commands/offline-cleanup-evidence.d.ts +3 -1
  30. package/dist/src/commands/offline-cleanup-evidence.js +9 -4
  31. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
  32. package/dist/src/commands/operation-plan.d.ts +6 -0
  33. package/dist/src/commands/operation-plan.js +29 -2
  34. package/dist/src/commands/operation-plan.js.map +1 -1
  35. package/dist/src/commands/options.d.ts +6 -2
  36. package/dist/src/commands/options.js +5 -4
  37. package/dist/src/commands/options.js.map +1 -1
  38. package/dist/src/commands/plugin-capabilities.js +29 -41
  39. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  40. package/dist/src/commands/public-config-confirmation.js +5 -5
  41. package/dist/src/commands/public-config-confirmation.js.map +1 -1
  42. package/dist/src/commands/public-lifecycle-result.d.ts +47 -0
  43. package/dist/src/commands/public-lifecycle-result.js +125 -4
  44. package/dist/src/commands/public-lifecycle-result.js.map +1 -1
  45. package/dist/src/commands/public-lifecycle.d.ts +1 -0
  46. package/dist/src/commands/public-lifecycle.js +15 -2
  47. package/dist/src/commands/public-lifecycle.js.map +1 -1
  48. package/dist/src/commands/public-plugin-query.d.ts +1 -0
  49. package/dist/src/commands/public-plugin-query.js +27 -8
  50. package/dist/src/commands/public-plugin-query.js.map +1 -1
  51. package/dist/src/commands/rebuild-command.d.ts +12 -11
  52. package/dist/src/commands/rebuild-command.js +531 -769
  53. package/dist/src/commands/rebuild-command.js.map +1 -1
  54. package/dist/src/commands/rebuild-integration.d.ts +21 -43
  55. package/dist/src/commands/rebuild-integration.js +306 -3600
  56. package/dist/src/commands/rebuild-integration.js.map +1 -1
  57. package/dist/src/commands/rebuild-operations.d.ts +13 -0
  58. package/dist/src/commands/rebuild-operations.js +60 -15
  59. package/dist/src/commands/rebuild-operations.js.map +1 -1
  60. package/dist/src/commands/rebuild-platform-integration.d.ts +60 -0
  61. package/dist/src/commands/rebuild-platform-integration.js +1264 -0
  62. package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
  63. package/dist/src/commands/review-inspection.js +41 -4
  64. package/dist/src/commands/review-inspection.js.map +1 -1
  65. package/dist/src/commands/review-preparation.d.ts +2 -0
  66. package/dist/src/commands/review-preparation.js +23 -60
  67. package/dist/src/commands/review-preparation.js.map +1 -1
  68. package/dist/src/commands/skill-eval.js +1 -0
  69. package/dist/src/commands/skill-eval.js.map +1 -1
  70. package/dist/src/commands/status-v6.d.ts +3 -1
  71. package/dist/src/commands/status-v6.js +24 -15
  72. package/dist/src/commands/status-v6.js.map +1 -1
  73. package/dist/src/commands/targets-command.d.ts +9 -0
  74. package/dist/src/commands/targets-command.js +57 -6
  75. package/dist/src/commands/targets-command.js.map +1 -1
  76. package/dist/src/commands/write-commands.js +43 -28
  77. package/dist/src/commands/write-commands.js.map +1 -1
  78. package/dist/src/constants.d.ts +2 -2
  79. package/dist/src/constants.js +2 -2
  80. package/dist/src/constants.js.map +1 -1
  81. package/dist/src/generators/local-plugin.js +59 -248
  82. package/dist/src/generators/local-plugin.js.map +1 -1
  83. package/dist/src/index.js +40 -14
  84. package/dist/src/index.js.map +1 -1
  85. package/dist/src/output/command-receipt.d.ts +1 -1
  86. package/dist/src/output/command-receipt.js +3 -1
  87. package/dist/src/output/command-receipt.js.map +1 -1
  88. package/dist/src/output/native-consent.d.ts +2 -0
  89. package/dist/src/output/native-consent.js +5 -0
  90. package/dist/src/output/native-consent.js.map +1 -0
  91. package/dist/src/output/public-result.js +72 -0
  92. package/dist/src/output/public-result.js.map +1 -1
  93. package/dist/src/output/rebuild-progress.js +5 -5
  94. package/dist/src/output/rebuild-progress.js.map +1 -1
  95. package/dist/src/output/receipt-projection.js +19 -2
  96. package/dist/src/output/receipt-projection.js.map +1 -1
  97. package/dist/src/platforms/capabilities.d.ts +10 -0
  98. package/dist/src/platforms/capabilities.js +158 -0
  99. package/dist/src/platforms/capabilities.js.map +1 -0
  100. package/dist/src/platforms/contracts.d.ts +351 -0
  101. package/dist/src/platforms/contracts.js +2 -0
  102. package/dist/src/platforms/contracts.js.map +1 -0
  103. package/dist/src/platforms/cursor-workspace-hook.d.ts +22 -0
  104. package/dist/src/platforms/cursor-workspace-hook.js +185 -0
  105. package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
  106. package/dist/src/platforms/discovery.d.ts +80 -0
  107. package/dist/src/platforms/discovery.js +604 -0
  108. package/dist/src/platforms/discovery.js.map +1 -0
  109. package/dist/src/platforms/gemini-activation.d.ts +36 -0
  110. package/dist/src/platforms/gemini-activation.js +331 -0
  111. package/dist/src/platforms/gemini-activation.js.map +1 -0
  112. package/dist/src/platforms/gemini-consent.d.ts +8 -0
  113. package/dist/src/platforms/gemini-consent.js +79 -0
  114. package/dist/src/platforms/gemini-consent.js.map +1 -0
  115. package/dist/src/platforms/identity.d.ts +4 -0
  116. package/dist/src/platforms/identity.js +22 -0
  117. package/dist/src/platforms/identity.js.map +1 -0
  118. package/dist/src/platforms/inspection-grok.d.ts +4 -0
  119. package/dist/src/platforms/inspection-grok.js +204 -0
  120. package/dist/src/platforms/inspection-grok.js.map +1 -0
  121. package/dist/src/platforms/inspection-native.d.ts +6 -0
  122. package/dist/src/platforms/inspection-native.js +401 -0
  123. package/dist/src/platforms/inspection-native.js.map +1 -0
  124. package/dist/src/platforms/inspection-opencode.d.ts +4 -0
  125. package/dist/src/platforms/inspection-opencode.js +97 -0
  126. package/dist/src/platforms/inspection-opencode.js.map +1 -0
  127. package/dist/src/platforms/inspection-pi.d.ts +3 -0
  128. package/dist/src/platforms/inspection-pi.js +287 -0
  129. package/dist/src/platforms/inspection-pi.js.map +1 -0
  130. package/dist/src/platforms/inspection-query.d.ts +5 -0
  131. package/dist/src/platforms/inspection-query.js +36 -0
  132. package/dist/src/platforms/inspection-query.js.map +1 -0
  133. package/dist/src/platforms/inspection.d.ts +13 -0
  134. package/dist/src/platforms/inspection.js +180 -0
  135. package/dist/src/platforms/inspection.js.map +1 -0
  136. package/dist/src/platforms/layout.d.ts +21 -0
  137. package/dist/src/platforms/layout.js +239 -0
  138. package/dist/src/platforms/layout.js.map +1 -0
  139. package/dist/src/platforms/lifecycle-native-services.d.ts +3 -0
  140. package/dist/src/platforms/lifecycle-native-services.js +147 -0
  141. package/dist/src/platforms/lifecycle-native-services.js.map +1 -0
  142. package/dist/src/platforms/lifecycle-native.d.ts +13 -0
  143. package/dist/src/platforms/lifecycle-native.js +276 -0
  144. package/dist/src/platforms/lifecycle-native.js.map +1 -0
  145. package/dist/src/platforms/lifecycle.d.ts +25 -0
  146. package/dist/src/platforms/lifecycle.js +470 -0
  147. package/dist/src/platforms/lifecycle.js.map +1 -0
  148. package/dist/src/platforms/managed-command-placement.d.ts +8 -0
  149. package/dist/src/platforms/managed-command-placement.js +79 -0
  150. package/dist/src/platforms/managed-command-placement.js.map +1 -0
  151. package/dist/src/platforms/projection-code-extension.d.ts +8 -0
  152. package/dist/src/platforms/projection-code-extension.js +121 -0
  153. package/dist/src/platforms/projection-code-extension.js.map +1 -0
  154. package/dist/src/platforms/projection-command-resources.d.ts +7 -0
  155. package/dist/src/platforms/projection-command-resources.js +74 -0
  156. package/dist/src/platforms/projection-command-resources.js.map +1 -0
  157. package/dist/src/platforms/projection-files.d.ts +27 -0
  158. package/dist/src/platforms/projection-files.js +111 -0
  159. package/dist/src/platforms/projection-files.js.map +1 -0
  160. package/dist/src/platforms/projection-marketplace.d.ts +19 -0
  161. package/dist/src/platforms/projection-marketplace.js +42 -0
  162. package/dist/src/platforms/projection-marketplace.js.map +1 -0
  163. package/dist/src/platforms/projection.d.ts +10 -0
  164. package/dist/src/platforms/projection.js +446 -0
  165. package/dist/src/platforms/projection.js.map +1 -0
  166. package/dist/src/platforms/registry.d.ts +4 -0
  167. package/dist/src/platforms/registry.js +30 -0
  168. package/dist/src/platforms/registry.js.map +1 -0
  169. package/dist/src/platforms/supplement-layout.d.ts +16 -0
  170. package/dist/src/platforms/supplement-layout.js +31 -0
  171. package/dist/src/platforms/supplement-layout.js.map +1 -0
  172. package/dist/src/portable/commands.d.ts +7 -5
  173. package/dist/src/portable/commands.js +6 -1
  174. package/dist/src/portable/commands.js.map +1 -1
  175. package/dist/src/portable/materializer.d.ts +8 -6
  176. package/dist/src/portable/materializer.js +47 -245
  177. package/dist/src/portable/materializer.js.map +1 -1
  178. package/dist/src/portable/recovery-layout.js +2 -15
  179. package/dist/src/portable/recovery-layout.js.map +1 -1
  180. package/dist/src/portable/recovery.d.ts +10 -1
  181. package/dist/src/portable/recovery.js +34 -8
  182. package/dist/src/portable/recovery.js.map +1 -1
  183. package/dist/src/recovery/coordinator.d.ts +4 -7
  184. package/dist/src/recovery/coordinator.js +151 -119
  185. package/dist/src/recovery/coordinator.js.map +1 -1
  186. package/dist/src/recovery/demand.d.ts +1 -1
  187. package/dist/src/recovery/demand.js +10 -42
  188. package/dist/src/recovery/demand.js.map +1 -1
  189. package/dist/src/recovery/joint-coordinator.js +112 -52
  190. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  191. package/dist/src/recovery/joint-demand.d.ts +4 -22
  192. package/dist/src/recovery/joint-demand.js +51 -40
  193. package/dist/src/recovery/joint-demand.js.map +1 -1
  194. package/dist/src/recovery/receipt.d.ts +23 -8
  195. package/dist/src/recovery/retirement.d.ts +1 -1
  196. package/dist/src/recovery/retirement.js +131 -29
  197. package/dist/src/recovery/retirement.js.map +1 -1
  198. package/dist/src/recovery/status.d.ts +13 -6
  199. package/dist/src/recovery/status.js +483 -79
  200. package/dist/src/recovery/status.js.map +1 -1
  201. package/dist/src/recovery/types.d.ts +3 -3
  202. package/dist/src/review/platform-profile.d.ts +3 -0
  203. package/dist/src/review/platform-profile.js +16 -0
  204. package/dist/src/review/platform-profile.js.map +1 -0
  205. package/dist/src/review/review-profile.d.ts +1 -0
  206. package/dist/src/review/review-profile.js +8 -2
  207. package/dist/src/review/review-profile.js.map +1 -1
  208. package/dist/src/review/review-selection.d.ts +2 -11
  209. package/dist/src/review/review-selection.js +97 -71
  210. package/dist/src/review/review-selection.js.map +1 -1
  211. package/dist/src/review/review-types.d.ts +3 -0
  212. package/dist/src/review/review-types.js.map +1 -1
  213. package/dist/src/review/skill-materialization.d.ts +44 -9
  214. package/dist/src/review/skill-materialization.js +112 -136
  215. package/dist/src/review/skill-materialization.js.map +1 -1
  216. package/dist/src/review/source-binding.d.ts +8 -5
  217. package/dist/src/review/source-binding.js +99 -41
  218. package/dist/src/review/source-binding.js.map +1 -1
  219. package/dist/src/tui/agent-management.js +112 -10
  220. package/dist/src/tui/agent-management.js.map +1 -1
  221. package/dist/src/tui/agent-settings.d.ts +3 -0
  222. package/dist/src/tui/agent-settings.js +10 -11
  223. package/dist/src/tui/agent-settings.js.map +1 -1
  224. package/dist/src/tui/console-app-v4.js +58 -20
  225. package/dist/src/tui/console-app-v4.js.map +1 -1
  226. package/dist/src/tui/content-item-card.js +2 -2
  227. package/dist/src/tui/content-item-card.js.map +1 -1
  228. package/dist/src/tui/controller-runtime.js +198 -152
  229. package/dist/src/tui/controller-runtime.js.map +1 -1
  230. package/dist/src/tui/controller.d.ts +5 -9
  231. package/dist/src/tui/controller.js +40 -18
  232. package/dist/src/tui/controller.js.map +1 -1
  233. package/dist/src/tui/deployment-view.d.ts +10 -0
  234. package/dist/src/tui/deployment-view.js +103 -0
  235. package/dist/src/tui/deployment-view.js.map +1 -0
  236. package/dist/src/tui/glossary.js +4 -4
  237. package/dist/src/tui/glossary.js.map +1 -1
  238. package/dist/src/tui/model.d.ts +5 -0
  239. package/dist/src/tui/model.js +73 -12
  240. package/dist/src/tui/model.js.map +1 -1
  241. package/dist/src/tui/operation-diagnostic-screens.js +2 -1
  242. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
  243. package/dist/src/tui/operation-history.d.ts +5 -4
  244. package/dist/src/tui/operation-history.js.map +1 -1
  245. package/dist/src/tui/operation-review-planner.d.ts +7 -2
  246. package/dist/src/tui/operation-review-planner.js +97 -42
  247. package/dist/src/tui/operation-review-planner.js.map +1 -1
  248. package/dist/src/tui/plugin-content.d.ts +5 -3
  249. package/dist/src/tui/plugin-content.js +70 -508
  250. package/dist/src/tui/plugin-content.js.map +1 -1
  251. package/dist/src/tui/plugin-detail.d.ts +3 -2
  252. package/dist/src/tui/plugin-detail.js +33 -25
  253. package/dist/src/tui/plugin-detail.js.map +1 -1
  254. package/dist/src/tui/scoped-inventory.d.ts +10 -6
  255. package/dist/src/tui/scoped-inventory.js +34 -1
  256. package/dist/src/tui/scoped-inventory.js.map +1 -1
  257. package/dist/src/types.d.ts +4 -63
  258. package/dist/src/types.js.map +1 -1
  259. package/dist/src/utils/agent-version.d.ts +10 -4
  260. package/dist/src/utils/agent-version.js.map +1 -1
  261. package/dist/src/utils/artifact-plan.d.ts +26 -2
  262. package/dist/src/utils/artifact-plan.js +113 -489
  263. package/dist/src/utils/artifact-plan.js.map +1 -1
  264. package/dist/src/utils/artifact-renderer.d.ts +100 -93
  265. package/dist/src/utils/artifact-renderer.js +173 -346
  266. package/dist/src/utils/artifact-renderer.js.map +1 -1
  267. package/dist/src/utils/artifact-request.d.ts +21 -11
  268. package/dist/src/utils/artifact-request.js +56 -80
  269. package/dist/src/utils/artifact-request.js.map +1 -1
  270. package/dist/src/utils/bundle-layout.js +30 -146
  271. package/dist/src/utils/bundle-layout.js.map +1 -1
  272. package/dist/src/utils/catalog-digests.d.ts +2 -12
  273. package/dist/src/utils/catalog-digests.js +0 -39
  274. package/dist/src/utils/catalog-digests.js.map +1 -1
  275. package/dist/src/utils/catalog-source-references.d.ts +7 -0
  276. package/dist/src/utils/catalog-source-references.js +234 -19
  277. package/dist/src/utils/catalog-source-references.js.map +1 -1
  278. package/dist/src/utils/codex-config-observation.d.ts +19 -0
  279. package/dist/src/utils/codex-config-observation.js +145 -0
  280. package/dist/src/utils/codex-config-observation.js.map +1 -0
  281. package/dist/src/utils/codex-executable-discovery.d.ts +2 -0
  282. package/dist/src/utils/codex-executable-discovery.js +47 -13
  283. package/dist/src/utils/codex-executable-discovery.js.map +1 -1
  284. package/dist/src/utils/codex-manager.js +1 -1
  285. package/dist/src/utils/codex-manager.js.map +1 -1
  286. package/dist/src/utils/codex-native-observation.d.ts +3 -0
  287. package/dist/src/utils/codex-native-observation.js +53 -0
  288. package/dist/src/utils/codex-native-observation.js.map +1 -1
  289. package/dist/src/utils/codex-shared-native.d.ts +3 -1
  290. package/dist/src/utils/codex-shared-native.js +46 -5
  291. package/dist/src/utils/codex-shared-native.js.map +1 -1
  292. package/dist/src/utils/codex-skill-staging.d.ts +4 -3
  293. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  294. package/dist/src/utils/codex-surface-analysis.d.ts +5 -2
  295. package/dist/src/utils/codex-surface-analysis.js +28 -57
  296. package/dist/src/utils/codex-surface-analysis.js.map +1 -1
  297. package/dist/src/utils/component-command-preparation.d.ts +34 -0
  298. package/dist/src/utils/component-command-preparation.js +228 -0
  299. package/dist/src/utils/component-command-preparation.js.map +1 -0
  300. package/dist/src/utils/component-resources.d.ts +43 -0
  301. package/dist/src/utils/component-resources.js +304 -0
  302. package/dist/src/utils/component-resources.js.map +1 -0
  303. package/dist/src/utils/dynamic-skill-tree.d.ts +17 -6
  304. package/dist/src/utils/dynamic-skill-tree.js +7 -3
  305. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  306. package/dist/src/utils/local-marketplace.d.ts +11 -44
  307. package/dist/src/utils/local-marketplace.js +11 -638
  308. package/dist/src/utils/local-marketplace.js.map +1 -1
  309. package/dist/src/utils/managed-command-evidence.d.ts +2 -2
  310. package/dist/src/utils/managed-command-evidence.js +5 -81
  311. package/dist/src/utils/managed-command-evidence.js.map +1 -1
  312. package/dist/src/utils/managed-command-materialization.d.ts +5 -2
  313. package/dist/src/utils/managed-command-materialization.js +35 -35
  314. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  315. package/dist/src/utils/managed-command-preparation.d.ts +67 -0
  316. package/dist/src/utils/managed-command-preparation.js +146 -0
  317. package/dist/src/utils/managed-command-preparation.js.map +1 -0
  318. package/dist/src/utils/managed-command-review.d.ts +26 -0
  319. package/dist/src/utils/managed-command-review.js +68 -0
  320. package/dist/src/utils/managed-command-review.js.map +1 -0
  321. package/dist/src/utils/managed-command-store.js +26 -15
  322. package/dist/src/utils/managed-command-store.js.map +1 -1
  323. package/dist/src/utils/native-cli.d.ts +23 -0
  324. package/dist/src/utils/native-cli.js +51 -2
  325. package/dist/src/utils/native-cli.js.map +1 -1
  326. package/dist/src/utils/native-demand.d.ts +20 -1
  327. package/dist/src/utils/native-demand.js.map +1 -1
  328. package/dist/src/utils/native-tool-review.d.ts +3 -6
  329. package/dist/src/utils/native-tool-review.js +25 -11
  330. package/dist/src/utils/native-tool-review.js.map +1 -1
  331. package/dist/src/utils/ownership.d.ts +26 -3
  332. package/dist/src/utils/ownership.js +95 -9
  333. package/dist/src/utils/ownership.js.map +1 -1
  334. package/dist/src/utils/paths.d.ts +1 -1
  335. package/dist/src/utils/paths.js +2 -0
  336. package/dist/src/utils/paths.js.map +1 -1
  337. package/dist/src/utils/platform-empty-state.d.ts +46 -0
  338. package/dist/src/utils/platform-empty-state.js +123 -0
  339. package/dist/src/utils/platform-empty-state.js.map +1 -0
  340. package/dist/src/utils/plugin-config-impact.d.ts +17 -11
  341. package/dist/src/utils/plugin-config-impact.js +46 -62
  342. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  343. package/dist/src/utils/plugin-config-write.js +52 -53
  344. package/dist/src/utils/plugin-config-write.js.map +1 -1
  345. package/dist/src/utils/plugin-config.d.ts +0 -2
  346. package/dist/src/utils/plugin-config.js +0 -6
  347. package/dist/src/utils/plugin-config.js.map +1 -1
  348. package/dist/src/utils/plugin-dependencies.d.ts +1 -1
  349. package/dist/src/utils/plugin-dependencies.js.map +1 -1
  350. package/dist/src/utils/plugin-scripts.d.ts +4 -0
  351. package/dist/src/utils/plugin-scripts.js +11 -0
  352. package/dist/src/utils/plugin-scripts.js.map +1 -1
  353. package/dist/src/utils/runtime-config.d.ts +5 -7
  354. package/dist/src/utils/runtime-config.js +12 -25
  355. package/dist/src/utils/runtime-config.js.map +1 -1
  356. package/dist/src/utils/windows-npm-shim.js +19 -2
  357. package/dist/src/utils/windows-npm-shim.js.map +1 -1
  358. package/package.json +3 -3
  359. package/dist/src/utils/claude-native-render-receipt.d.ts +0 -14
  360. package/dist/src/utils/claude-native-render-receipt.js +0 -26
  361. package/dist/src/utils/claude-native-render-receipt.js.map +0 -1
  362. package/dist/src/utils/claude-skills-root.d.ts +0 -8
  363. package/dist/src/utils/claude-skills-root.js +0 -87
  364. package/dist/src/utils/claude-skills-root.js.map +0 -1
  365. package/dist/src/utils/codex-native-render-receipt.d.ts +0 -40
  366. package/dist/src/utils/codex-native-render-receipt.js +0 -205
  367. package/dist/src/utils/codex-native-render-receipt.js.map +0 -1
  368. package/dist/src/utils/slash-commands.d.ts +0 -1
  369. package/dist/src/utils/slash-commands.js +0 -2
  370. package/dist/src/utils/slash-commands.js.map +0 -1
@@ -1,49 +1,46 @@
1
- import { withNativeToolRemovalImpact } from '../utils/native-tool-review.js';
2
1
  import crypto from 'node:crypto';
3
2
  import path from 'node:path';
3
+ import { withNativeToolRemovalImpact } from '../utils/native-tool-review.js';
4
4
  import fs from 'fs-extra';
5
- import { getCodexOperationRequirement, probeAgentVersion } from '../utils/agent-version.js';
6
- import { CodexManagerError, previewCodexManager, resolveCodexOperationConsumer, } from '../utils/codex-manager.js';
5
+ import { NATIVE_PLATFORM_TARGETS } from '@lesliechan721/aw-plugin-core/manifest';
6
+ import { getDeploymentLayout } from '../platforms/layout.js';
7
7
  import { createNoopDebugLogger } from '../output/debug-log.js';
8
8
  import { createNoopReporter } from '../output/reporter.js';
9
- import { getDefaultNativeCliRunner, } from '../utils/native-cli.js';
9
+ import { getCodexOperationRequirement, probeAgentVersion } from '../utils/agent-version.js';
10
+ import { resolveArtifactRenderConfig } from '../utils/artifact-renderer.js';
11
+ import { catalogGenerationErrorCode, isOfflineCleanupCatalogGenerationError, } from '../utils/catalog-generation-error.js';
12
+ import { resolveActiveCatalogGeneration, resolveActiveCatalogPluginShallow } from '../utils/catalog-generation-resolver.js';
13
+ import { resolveCatalogOperationContext, } from '../utils/catalog-operation-context.js';
14
+ import { sanitizeCatalogSourceErrorMessage } from '../utils/catalog-public-error.js';
15
+ import { validateCatalogSnapshotComplete, validateCatalogSnapshotPluginEntriesComplete, } from '../utils/catalog-snapshot.js';
16
+ import { assertCatalogSourceInventoryComplete, canonicalMarketplaceRegistrationNames, inventoryCatalogSourceReferences, offlineOwnedPathEvidence, } from '../utils/catalog-source-references.js';
17
+ import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
18
+ import { readCodexConfigFile } from '../utils/codex-config.js';
19
+ import { previewCodexManager, resolveCodexOperationConsumer, } from '../utils/codex-manager.js';
10
20
  import { createCodexNativeObservationSession } from '../utils/codex-native-observation.js';
11
- import { readPluginManifest } from '../utils/manifest.js';
12
- import { discoverRetainedManagedCommandPackages, retainedManagedCommandPackageResult } from '../utils/managed-command-materialization.js';
13
- import { resolveAwHome, resolveCodexPaths } from '../utils/paths.js';
14
- import { resolveCliPackageRoot } from '../utils/paths.js';
15
- import { supportsPlatform } from '../utils/platform-support.js';
16
- import { analyzeCodexSurface } from '../utils/codex-surface-analysis.js';
17
- import { buildGeneratedName } from '../generators/shared.js';
18
- import { createCodexReconcilePlan, } from '../utils/codex-reconciler.js';
19
- import { parseCodexConfig, readCodexConfigFile } from '../utils/codex-config.js';
20
21
  import { isCanonicalCodexMarketplaceRegistration } from '../utils/codex-shared-native.js';
21
- import { executeRebuildComponentCleanup, executeRebuildOperation, prepareRebuildOperation, } from './rebuild-operations.js';
22
- import { assertNoClaudeUnboundNativeNameCollision, CodexActivationPostcheckError, createRebuildIntegration, executeCodexReconcileActivations, inspectCodexPluginRegistrationLive, inspectCodexSharedNativeLive, hasPreparedStaticNativeCommandDrift, inspectNativeMarketplaceRegistrations, isNativeActivationOnlyTarget, postcheckCodexReconcileActivations, removeForceCleanupCodexRoleRegistration, } from './rebuild-integration.js';
23
- import { assertSafeNamespacedMarketplacePluginRoot, getNamespacedMarketplaceName, readStrictNamespacedMarketplaceRoot, } from '../utils/local-marketplace.js';
22
+ import { analyzeCodexSurface } from '../utils/codex-surface-analysis.js';
23
+ import { getNamespacedMarketplaceName, } from '../utils/local-marketplace.js';
24
+ import { discoverRetainedManagedCommandPackages, retainedManagedCommandPackageResult } from '../utils/managed-command-materialization.js';
25
+ import { assertStrictSemVer, checkAwCapabilitySupport, readPluginManifest } from '../utils/manifest.js';
24
26
  import { formatPluginId, parsePluginId, planPluginSelectorSourceIds, preflightDesiredArtifactCollisions, withResolvedMultiSourceCatalog, } from '../utils/multi-source-catalog.js';
25
- import { calculateCodexNativeRenderPayloadDigest, calculateCodexSharedNativePayloadDigest, } from '../utils/catalog-digests.js';
26
- import { resolveCatalogOperationContext, } from '../utils/catalog-operation-context.js';
27
- import { assertStrictSemVer } from '../utils/manifest.js';
28
- import { assertCatalogSourceInventoryComplete, canonicalMarketplaceRegistrationNames, inventoryCatalogSourceReferences, } from '../utils/catalog-source-references.js';
29
- import { sanitizeCatalogSourceErrorMessage } from '../utils/catalog-public-error.js';
30
- import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
31
- import { inspectPluginConfigResetTarget, readNamespacedPluginConfigStoreIdentity, resolvePluginConfigStorePath, resolveEffectivePluginConfig, } from '../utils/plugin-config.js';
32
- import { resolveArtifactRenderConfig } from '../utils/artifact-renderer.js';
33
- import { pluginConfigTargetRenderScopes } from '../utils/plugin-config-impact.js';
27
+ import { getDefaultNativeCliRunner, } from '../utils/native-cli.js';
34
28
  import { inspectOwnedComponents, parseOwnedTextHeader, readSkillOwnerMarker, SKILL_OWNER_MARKER, } from '../utils/ownership.js';
35
- import { resolveActiveCatalogGeneration, resolveActiveCatalogPluginShallow } from '../utils/catalog-generation-resolver.js';
36
- import { canonicalizePathThroughExistingAncestorSync, codexProjectConfigAliasesUserHome, getClaudeHome, getCodexHome, resolveRepoRootSync, } from '../utils/state-paths.js';
29
+ import { resolveAwHome, resolveCliPackageRoot, resolveCodexPaths } from '../utils/paths.js';
30
+ import { supportsPlatform } from '../utils/platform-support.js';
31
+ import { pluginConfigTargetRenderScopes } from '../utils/plugin-config-impact.js';
32
+ import { inspectPluginConfigResetTarget, readNamespacedPluginConfigStoreIdentity, resolveEffectivePluginConfig, resolvePluginConfigStorePath, } from '../utils/plugin-config.js';
37
33
  import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
38
- import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
39
- import { catalogGenerationErrorCode, isOfflineCleanupCatalogGenerationError, } from '../utils/catalog-generation-error.js';
40
- import { assertOperationPlanFingerprint, createOperationPlanConfigDigest, createOperationPlan, } from './operation-plan.js';
41
- import { validateCatalogSnapshotComplete, validateCatalogSnapshotPluginEntriesComplete, } from '../utils/catalog-snapshot.js';
34
+ import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
35
+ import { canonicalizePathThroughExistingAncestorSync, codexProjectConfigAliasesUserHome, getClaudeHome, getCodexHome, resolveRepoRootSync, } from '../utils/state-paths.js';
42
36
  import { AwCapabilityUnsupportedError, IMPLEMENTED_AW_CAPABILITIES, } from './aw-capabilities.js';
43
- import { checkAwCapabilitySupport } from '../utils/manifest.js';
44
37
  import { createDependencyPlacementPlan, } from './dependency-operation-plan.js';
45
- import { createReconcileOperationPlan, } from './reconcile-operation-plan.js';
46
38
  import { forceOfflineCleanupEvidence, intentOnlyOfflineCleanupEvidence, offlineCleanupEvidenceFromInventory, offlineCleanupEvidenceMatches, } from './offline-cleanup-evidence.js';
39
+ import { assertOperationPlanFingerprint, createOperationPlan, createOperationPlanConfigDigest, operationPlanNativeToolChanges, } from './operation-plan.js';
40
+ import { deploymentConfirmationEffects } from './deployment-confirmation.js';
41
+ import { assertNoClaudeUnboundNativeNameCollision, CodexActivationPostcheckError, createRebuildIntegration, disposePreparedPlatformRebuildSession, executeCodexReconcileActivations, inspectNativeMarketplaceRegistrations, isNativeActivationOnlyTarget, postcheckCodexReconcileActivations, removeForceCleanupCodexRoleRegistration } from './rebuild-integration.js';
42
+ import { executeRebuildOperation, prepareRebuildOperation } from './rebuild-operations.js';
43
+ import { createReconcileOperationPlan, } from './reconcile-operation-plan.js';
47
44
  async function measureCommandPerformanceStage(runtime, name, operation) {
48
45
  const startedAt = Date.now();
49
46
  let phase = 'success';
@@ -69,7 +66,7 @@ async function measureCommandPerformanceStage(runtime, name, operation) {
69
66
  }
70
67
  }
71
68
  function assertNativeToolChangeAuthorization(plan, options) {
72
- if (!plan.actions.some((action) => (action.nativeToolChanges?.length ?? 0) > 0)
69
+ if (operationPlanNativeToolChanges(plan).length === 0
73
70
  || options.commandOptions.yes === true)
74
71
  return;
75
72
  if (options.runtime?.preApplyConfirmed === true && options.runtime.expectedPlanFingerprint) {
@@ -123,37 +120,6 @@ function omitSelectedPluginConfigErrors(inventory, targets) {
123
120
  function selectedPlatforms(selection) {
124
121
  return selection === 'both' ? ['codex', 'claude'] : [selection];
125
122
  }
126
- async function selectedProjectCodexSkillReferences(options) {
127
- const skillsRoot = path.join(resolveRepoRootSync(options.cwd), '.agents', 'skills');
128
- const entries = await fs.readdir(skillsRoot, { withFileTypes: true }).catch((error) => {
129
- const code = error.code;
130
- if (code === 'ENOENT' || code === 'ENOTDIR')
131
- return [];
132
- throw error;
133
- });
134
- const references = [];
135
- for (const entry of entries) {
136
- if (!entry.isDirectory() || entry.isSymbolicLink())
137
- continue;
138
- const skillRoot = path.join(skillsRoot, entry.name);
139
- const marker = await readSkillOwnerMarker({ skillRoot, allowedRoot: skillsRoot }).catch(() => null);
140
- if (!marker?.sourceId
141
- || marker.pluginId !== `${marker.sourceId}/${marker.plugin}`
142
- || marker.platform !== 'codex'
143
- || marker.scope !== 'project')
144
- continue;
145
- references.push({
146
- kind: 'namespacedOwner',
147
- location: path.join(skillRoot, SKILL_OWNER_MARKER),
148
- sourceId: marker.sourceId,
149
- pluginName: marker.plugin,
150
- platform: marker.platform,
151
- scope: marker.scope,
152
- });
153
- }
154
- return references;
155
- }
156
- const cleanupProjectSkillsByInventory = new WeakMap();
157
123
  function selectCodexActivationPlans(plans, targetScopes, preservedActivations, originalUserActivations) {
158
124
  return plans.flatMap((plan) => {
159
125
  const includesScope = (pluginId, scope) => targetScopes.has(`${pluginId}\0${scope}`);
@@ -261,7 +227,7 @@ function createSyntheticPlugin(pluginName, env) {
261
227
  rootDir,
262
228
  manifestPath: path.join(rootDir, '.agents-plugin', 'plugin.json'),
263
229
  manifest: {
264
- schemaVersion: 3,
230
+ schemaVersion: 4,
265
231
  name: pluginName,
266
232
  version: '0.0.0',
267
233
  description: 'Cleanup-only target for a plugin missing from the current catalog.',
@@ -273,8 +239,15 @@ function createSyntheticPlugin(pluginName, env) {
273
239
  },
274
240
  };
275
241
  }
276
- function failedResult(command, identity, message, phase = 'preflight') {
242
+ function deploymentExclusionsFromError(error) {
243
+ if (!error || typeof error !== 'object')
244
+ return [];
245
+ const exclusions = error.deploymentExclusions;
246
+ return Array.isArray(exclusions) ? exclusions : [];
247
+ }
248
+ function failedResult(command, identity, message, phase = 'preflight', deploymentExclusions = []) {
277
249
  return {
250
+ ...(deploymentExclusions.length ? { deploymentExclusions } : {}),
278
251
  status: 'failed',
279
252
  command,
280
253
  target: identity,
@@ -341,6 +314,12 @@ async function resolveRequestedNames(options) {
341
314
  }
342
315
  async function runSingleSourceRebuildCommand(options) {
343
316
  const runtime = {
317
+ nativeConsent: options.runtime?.nativeConsent === true,
318
+ referencePlugins: options.runtime?.referencePlugins,
319
+ recoveryCandidates: options.runtime?.recoveryCandidates,
320
+ sharedReferenceView: options.runtime?.executionInput?.requirements.sharedReferenceView ?? options.runtime?.sharedReferenceView,
321
+ platformRebuildSession: options.runtime?.platformRebuildSession,
322
+ packagePreparationCache: options.runtime?.packagePreparationCache,
344
323
  preparedArtifactRenderResults: options.runtime?.preparedArtifactRenderResults,
345
324
  interruption: options.runtime?.interruption,
346
325
  signal: options.runtime?.signal,
@@ -517,7 +496,7 @@ async function runSingleSourceRebuildCommand(options) {
517
496
  });
518
497
  }
519
498
  catch (error) {
520
- result = error.result ?? failedResult(options.command, identity, error instanceof Error ? error.message : String(error), 'preflight');
499
+ result = error.result ?? failedResult(options.command, identity, error instanceof Error ? error.message : String(error), 'preflight', deploymentExclusionsFromError(error));
521
500
  }
522
501
  results.push(result);
523
502
  }
@@ -593,6 +572,8 @@ function mergeRebuildCommandResults(results) {
593
572
  plugins: [...new Set(results.flatMap((result) => result.plugins))],
594
573
  warnings: [...new Set(results.flatMap((result) => result.warnings))],
595
574
  rebuildResults,
575
+ deploymentExclusions: results.flatMap((result) => result.deploymentExclusions
576
+ ?? result.rebuildResults.flatMap((entry) => entry.deploymentExclusions ?? [])),
596
577
  targetResults: results.flatMap((result) => result.targetResults),
597
578
  ...(results.some((result) => result.commandResults?.length) ? { commandResults: results.flatMap((result) => result.commandResults ?? []) } : {}),
598
579
  overallState: rebuildResults.every((result) => result.status === 'succeeded')
@@ -616,6 +597,12 @@ function mergeRebuildCommandResults(results) {
616
597
  : {}),
617
598
  };
618
599
  }
600
+ function hasRebuildMutation(result) {
601
+ return result.removed.length > 0 || result.quarantined.length > 0
602
+ || (result.deploymentReceipts ?? []).some((receipt) => receipt.effects.some((effect) => effect.mutation === 'confirmed' || effect.status === 'unknown' && effect.mutation === 'possible'))
603
+ || result.actions.some((action) => action.status === 'succeeded'
604
+ && (action.name === 'native.write' || action.name === 'artifacts.write'));
605
+ }
619
606
  function reconcileOverallState(targetResults, plan, rebuildResults = []) {
620
607
  const failed = targetResults.some((result) => result.state === 'failed' || result.action === 'skipped');
621
608
  if (!failed)
@@ -630,11 +617,7 @@ function reconcileOverallState(targetResults, plan, rebuildResults = []) {
630
617
  const completedMutation = targetResults.some((result) => result.state === 'completed'
631
618
  && result.action !== 'keep'
632
619
  && result.action !== 'skipped');
633
- const observedMutation = rebuildResults.some((result) => result.actions.some((action) => action.status === 'succeeded'
634
- && (action.name === 'stale.cleanup'
635
- || action.name === 'native.write'
636
- || action.name === 'artifacts.write'
637
- || action.name === 'cleanup.owned')));
620
+ const observedMutation = rebuildResults.some(hasRebuildMutation);
638
621
  return completedRequested || completedMutation || observedMutation ? 'partial' : 'failed';
639
622
  }
640
623
  function createRebuildOperationPlan(options) {
@@ -669,6 +652,9 @@ function createRebuildOperationPlan(options) {
669
652
  ]),
670
653
  ];
671
654
  return createOperationPlan({
655
+ deploymentExclusions: options.deploymentExclusions,
656
+ nativeToolChanges: options.nativeToolChanges,
657
+ ...(options.deploymentPlans ? { deploymentPlans: options.deploymentPlans } : {}),
672
658
  intentChanges: [],
673
659
  actions,
674
660
  changes: options.dependencyPlan.targets.map((target) => [
@@ -703,8 +689,8 @@ function leaseSafeRebuildResult(result) {
703
689
  target: { ...entry.target, cwd: '.' },
704
690
  removed: entry.removed.map(projectPath),
705
691
  absent: entry.absent.map(projectPath),
706
- residual: entry.residual.map(projectPath),
707
- quarantined: entry.quarantined.map(projectPath),
692
+ residual: [...entry.residual],
693
+ quarantined: [...entry.quarantined],
708
694
  })),
709
695
  };
710
696
  }
@@ -859,6 +845,7 @@ function cleanupActionCoversLocation(evidence, location, env, cwd) {
859
845
  function cleanupLocatorPaths(component) {
860
846
  const locator = component.locator;
861
847
  switch (locator.kind) {
848
+ case 'cursor-workspace-hook': return [locator.hooksPath];
862
849
  case 'claude-permissions': return [locator.settingsPath];
863
850
  case 'codex-instruction': return [locator.configPath];
864
851
  case 'codex-activation': return [locator.configPath];
@@ -923,11 +910,10 @@ function resolveLiveCleanupTargets(options) {
923
910
  const matchesByTarget = new Map();
924
911
  for (const reference of visible.filter((entry) => entry.pluginName === parsed.pluginName
925
912
  && (parsed.sourceId === undefined || entry.sourceId === parsed.sourceId))) {
926
- const stableSourceIdentity = reference.sourceIdentity
927
- ?? options.references.find((entry) => entry.kind === 'namespacedMarketplace'
928
- && entry.sourceId === reference.sourceId
929
- && entry.sourceIdentity)?.sourceIdentity
930
- ?? 'unavailable';
913
+ const registeredSourceIdentity = options.references.find((entry) => entry.kind === 'namespacedMarketplace' && entry.sourceId === reference.sourceId && entry.sourceIdentity)?.sourceIdentity;
914
+ const stableSourceIdentity = reference.ownedComponent
915
+ ? reference.sourceIdentity ?? registeredSourceIdentity ?? 'unavailable'
916
+ : registeredSourceIdentity ?? reference.sourceIdentity ?? 'unavailable';
931
917
  const liveNames = new Set(options.references.flatMap((candidate) => candidate.sourceId === reference.sourceId
932
918
  && candidate.pluginName === reference.pluginName
933
919
  && candidate.platform === reference.platform
@@ -985,9 +971,49 @@ function resolveLiveCleanupTargets(options) {
985
971
  ].join('\0'), target])).values()],
986
972
  };
987
973
  }
974
+ function offlineCleanupKey(target) {
975
+ return [target.pluginId, target.sourceIdentity, target.platform, target.scope].join('\0');
976
+ }
977
+ function needsFrozenNativeRemoval(candidate) {
978
+ return !['opencode-directory', 'antigravity-directory', 'grok-directory'].includes(candidate.binding.route);
979
+ }
980
+ async function prepareOfflineNativeCleanup(options) {
981
+ const candidates = options.evidence.flatMap((target) => target.plan.actions.flatMap((action) => action.recoveryCandidate && needsFrozenNativeRemoval(action.recoveryCandidate) ? [action.recoveryCandidate] : []));
982
+ const context = { ...options.runtime, env: options.env,
983
+ nativeCliRunner: options.runtime?.nativeCliRunner ?? getDefaultNativeCliRunner(),
984
+ reporter: createNoopReporter(), debugLogger: createNoopDebugLogger(), recoveryCandidates: candidates,
985
+ sharedReferenceView: options.runtime?.executionInput?.requirements.sharedReferenceView ?? options.runtime?.sharedReferenceView };
986
+ const integration = createRebuildIntegration({ context });
987
+ const targets = new Map();
988
+ const deploymentExclusions = [];
989
+ const warnings = [];
990
+ for (const evidence of options.evidence) {
991
+ if (!candidates.some((candidate) => candidate.binding.plugin.sourceIdentity === evidence.sourceIdentity
992
+ && candidate.binding.plugin.pluginId === evidence.pluginId && candidate.binding.platform === evidence.platform
993
+ && candidate.binding.scope.kind === evidence.scope))
994
+ continue;
995
+ const plugin = createSyntheticPlugin(evidence.pluginName, options.env);
996
+ plugin.sourceId = evidence.sourceId;
997
+ plugin.sourceIdentity = evidence.sourceIdentity;
998
+ plugin.pluginId = evidence.pluginId;
999
+ try {
1000
+ const target = await integration.buildTarget({ sourceId: evidence.sourceId, sourceIdentity: evidence.sourceIdentity,
1001
+ pluginId: evidence.pluginId, plugin, platform: evidence.platform, scope: evidence.scope, cwd: options.cwd,
1002
+ command: 'cleanup', catalog: { rootDir: resolveAwHome(options.env), source: 'local' } });
1003
+ targets.set(offlineCleanupKey(evidence), target);
1004
+ deploymentExclusions.push(...target.deploymentExclusions ?? []);
1005
+ }
1006
+ catch (error) {
1007
+ deploymentExclusions.push(...deploymentExclusionsFromError(error));
1008
+ warnings.push(`nativeCleanupPreparationFailed: ${evidence.pluginId}:${evidence.platform}/${evidence.scope}: ${error instanceof Error ? error.message : String(error)}`);
1009
+ }
1010
+ }
1011
+ await integration.sealMarketplaceGenerations([...targets.values()]);
1012
+ return { integration, targets, warnings, deploymentExclusions };
1013
+ }
988
1014
  async function cleanupOfflineOwnedComponents(options) {
989
1015
  const results = [];
990
- const warnings = [];
1016
+ const warnings = [...options.nativePreparation?.warnings ?? []];
991
1017
  const nativeCliRunner = options.nativeCliRunner ?? getDefaultNativeCliRunner();
992
1018
  const codexManager = options.codexManager;
993
1019
  const context = {
@@ -1009,7 +1035,12 @@ async function cleanupOfflineOwnedComponents(options) {
1009
1035
  && candidate.sourceIdentity === target.sourceIdentity
1010
1036
  && candidate.platform === target.platform
1011
1037
  && candidate.scope === target.scope);
1012
- const activationAction = target.platform === 'codex'
1038
+ const nativeTarget = options.nativePreparation?.targets.get(offlineCleanupKey(target));
1039
+ const nativeComponents = nativeTarget?.ownedComponents ?? [];
1040
+ const nativeOwns = (component) => nativeComponents.some((item) => 'path' in component && 'path' in item ? component.path === item.path
1041
+ : component.kind === 'shared-config' && item.kind === 'shared-config'
1042
+ && JSON.stringify(component.locator) === JSON.stringify(item.locator));
1043
+ const activationAction = !nativeTarget && target.platform === 'codex'
1013
1044
  ? evidence?.plan.actions.find((action) => action.action === 'removeNativeRegistration'
1014
1045
  && action.activationScope === target.scope)
1015
1046
  : undefined;
@@ -1020,34 +1051,67 @@ async function cleanupOfflineOwnedComponents(options) {
1020
1051
  plugin.pluginId = target.pluginId;
1021
1052
  const marketplaceName = target.marketplaceName ?? 'aw';
1022
1053
  plugin.marketplaceName = marketplaceName;
1023
- const desired = await integration.buildTarget({
1024
- sourceId: target.sourceId,
1025
- sourceIdentity: target.sourceIdentity,
1026
- pluginId: target.pluginId,
1027
- marketplaceName,
1028
- marketplaceRoot: path.join(resolveAwHome(options.env), 'marketplaces', target.sourceId),
1029
- plugin,
1030
- platform: target.platform,
1031
- scope: target.scope,
1032
- cwd: options.cwd,
1033
- command: 'cleanup',
1034
- catalog: {
1035
- rootDir: resolveAwHome(options.env),
1036
- source: 'local',
1037
- catalogVersion: '0.0.0',
1038
- channel: 'beta',
1039
- },
1040
- includeNativeCleanupCandidate: false,
1041
- ...(activationAction
1042
- ? {
1043
- codexActivationCleanup: [{
1044
- codexPluginId: activationAction.target,
1045
- scope: activationAction.activationScope,
1046
- disposition: activationDisposition,
1047
- }],
1054
+ const components = [];
1055
+ const preservedOutputs = [];
1056
+ for (const action of evidence?.plan.actions ?? []) {
1057
+ if (action.action !== 'removeOwnedOutput')
1058
+ continue;
1059
+ let component = action.component;
1060
+ if (!component && action.owner && action.allowedRoot
1061
+ && (action.kind === 'skill-directory' || action.kind === 'owned-text-file' || action.kind === 'owned-directory')) {
1062
+ component = { kind: action.kind, path: action.target, allowedRoot: action.allowedRoot, identity: action.owner };
1063
+ }
1064
+ if (!component && path.basename(action.target) === SKILL_OWNER_MARKER) {
1065
+ const root = path.dirname(action.target);
1066
+ const marker = await readSkillOwnerMarker({ skillRoot: root, allowedRoot: path.dirname(root) });
1067
+ if (marker) {
1068
+ const { schemaVersion: _schema, nativeProjection: projection, ...identity } = marker;
1069
+ component = { kind: projection ? 'owned-directory' : 'skill-directory', path: root,
1070
+ allowedRoot: path.dirname(root), identity };
1048
1071
  }
1049
- : {}),
1050
- });
1072
+ }
1073
+ if (!component) {
1074
+ const parsed = await fs.readFile(action.target, 'utf8').then(parseOwnedTextHeader).catch(() => null);
1075
+ if (parsed)
1076
+ component = { kind: 'owned-text-file', path: action.target,
1077
+ allowedRoot: path.dirname(action.target), identity: parsed.identity };
1078
+ }
1079
+ if (!component) {
1080
+ preservedOutputs.push(action.target);
1081
+ continue;
1082
+ }
1083
+ if (nativeTarget && nativeOwns(component))
1084
+ continue;
1085
+ if (component.identity.sourceId !== target.sourceId || component.identity.pluginId !== target.pluginId
1086
+ || component.identity.platform !== target.platform || component.identity.scope !== target.scope
1087
+ || component.identity.sourceIdentity !== target.sourceIdentity) {
1088
+ throw new Error('operationReviewStale: cleanup owner identity changed.');
1089
+ }
1090
+ if ('path' in component && action.pathEvidence
1091
+ && await offlineOwnedPathEvidence(component.path) !== action.pathEvidence) {
1092
+ throw new Error('operationReviewStale: cleanup output bytes changed.');
1093
+ }
1094
+ // Registered native payloads require their route's verified unregistration.
1095
+ // This offline path can revoke only independently owned files and directory-loaded packages.
1096
+ if (component.kind === 'owned-directory'
1097
+ && ((action.recoveryCandidate && needsFrozenNativeRemoval(action.recoveryCandidate))
1098
+ || ['codex', 'claude', 'gemini', 'copilot', 'pi'].includes(target.platform)
1099
+ || path.relative(path.join(resolveAwHome(options.env), 'platforms'), component.path).split(path.sep)[0] !== '..')) {
1100
+ preservedOutputs.push(component.path);
1101
+ continue;
1102
+ }
1103
+ components.push(component);
1104
+ }
1105
+ if (activationAction)
1106
+ components.push({ kind: 'shared-config', label: activationAction.target,
1107
+ identity: { owner: 'agent-workflows', sourceId: target.sourceId, pluginId: target.pluginId,
1108
+ plugin: target.pluginName, platform: 'codex', scope: target.scope, artifactKey: 'activation' },
1109
+ locator: { kind: 'codex-activation', configPath: resolveCodexPaths(options.cwd, target.scope, options.env).configTomlPath,
1110
+ codexPluginId: activationAction.target, desired: true, disposition: activationDisposition } });
1111
+ const desired = { plugin, identity: { sourceId: target.sourceId, sourceIdentity: target.sourceIdentity,
1112
+ pluginId: target.pluginId, pluginName: target.pluginName, pluginVersion: '0.0.0', platform: target.platform,
1113
+ scope: target.scope, cwd: options.cwd }, ownedComponents: components, desiredOwnedComponents: components,
1114
+ requiresNative: false, writeNativeRequired: false, artifacts: [], operationActions: [], preApplySource: plugin };
1051
1115
  const sharedNativeComponent = (component) => component.kind === 'native-plugin'
1052
1116
  || (component.kind === 'shared-config'
1053
1117
  && component.identity.artifactKey.startsWith('marketplace-'));
@@ -1057,6 +1121,26 @@ async function cleanupOfflineOwnedComponents(options) {
1057
1121
  desired.desiredOwnedComponents = desired.desiredOwnedComponents?.filter((component) => !sharedNativeComponent(component));
1058
1122
  desired.optionalOwnedComponents = desired.optionalOwnedComponents?.filter((component) => !sharedNativeComponent(component));
1059
1123
  desired.operationActions = desired.operationActions?.filter((action) => action.kind !== 'removeNativeRegistration');
1124
+ // Recheck only reviewed supplement directories. Newly added files remain outside deletion authorization.
1125
+ const inspectedRoots = new Set();
1126
+ for (const component of [...desired.ownedComponents]) {
1127
+ if (component.kind !== 'owned-text-file' || inspectedRoots.has(component.allowedRoot))
1128
+ continue;
1129
+ inspectedRoots.add(component.allowedRoot);
1130
+ for (const entry of await fs.readdir(component.allowedRoot, { withFileTypes: true })) {
1131
+ if (!entry.isFile() || entry.isSymbolicLink())
1132
+ continue;
1133
+ const candidate = path.join(component.allowedRoot, entry.name);
1134
+ if (components.some((item) => 'path' in item && item.path === candidate))
1135
+ continue;
1136
+ const parsed = await fs.readFile(candidate, 'utf8').then(parseOwnedTextHeader).catch(() => null);
1137
+ if (parsed?.identity.sourceId === target.sourceId && parsed.identity.pluginId === target.pluginId
1138
+ && parsed.identity.sourceIdentity === target.sourceIdentity && parsed.identity.platform === target.platform
1139
+ && parsed.identity.scope === target.scope)
1140
+ desired.ownedComponents = [...desired.ownedComponents,
1141
+ { kind: 'owned-text-file', path: candidate, allowedRoot: component.allowedRoot, identity: parsed.identity }];
1142
+ }
1143
+ }
1060
1144
  const unplannedCandidates = evidence
1061
1145
  ? desired.ownedComponents.filter((component) => !cleanupComponentAuthorized(component, evidence))
1062
1146
  : [];
@@ -1088,16 +1172,41 @@ async function cleanupOfflineOwnedComponents(options) {
1088
1172
  return false;
1089
1173
  });
1090
1174
  }
1091
- const result = await (options.executeCleanupOperation ?? executeRebuildOperation)({
1175
+ const nativeResult = nativeTarget ? await (options.executeCleanupOperation ?? executeRebuildOperation)({
1176
+ command: 'cleanup', target: nativeTarget, driver: options.nativePreparation.integration.driver,
1177
+ }) : undefined;
1178
+ if (nativeResult?.status === 'failed' && nativeResult.error.phase === 'preflight') {
1179
+ results.push(nativeResult);
1180
+ continue;
1181
+ }
1182
+ let result = await (options.executeCleanupOperation ?? executeRebuildOperation)({
1092
1183
  command: 'cleanup',
1093
1184
  target: desired,
1094
1185
  driver: integration.driver,
1095
1186
  });
1096
- if (target.marketplaceIdentityUnresolved) {
1187
+ if (nativeResult) {
1188
+ const combined = { ...result, actions: [...nativeResult.actions, ...result.actions],
1189
+ cleanupAttempted: nativeResult.cleanupAttempted || result.cleanupAttempted,
1190
+ removed: [...nativeResult.removed, ...result.removed], absent: [...nativeResult.absent, ...result.absent],
1191
+ residual: [...nativeResult.residual, ...result.residual], quarantined: [...nativeResult.quarantined, ...result.quarantined],
1192
+ failures: [...nativeResult.failures, ...result.failures], deploymentReceipts: nativeResult.deploymentReceipts,
1193
+ deploymentExclusions: [...nativeResult.deploymentExclusions ?? [], ...result.deploymentExclusions ?? []] };
1194
+ result = nativeResult.status === 'failed' ? { ...combined, status: 'failed', error: nativeResult.error } : combined;
1195
+ }
1196
+ if (target.marketplaceIdentityUnresolved && !nativeTarget) {
1097
1197
  result.residual.push('nativeMarketplaceIdentityUnresolved');
1098
1198
  warnings.push(`nativeMarketplaceIdentityUnresolved: Preserved ambiguous native registration for ${target.pluginId} on ${target.platform}/${target.scope}.`);
1099
1199
  }
1100
1200
  let finalResult = result;
1201
+ if (preservedOutputs.length) {
1202
+ result.residual.push(...preservedOutputs);
1203
+ const message = 'nativeUnregistrationRequired: Preserved native output that requires its verified platform removal route.';
1204
+ warnings.push(message);
1205
+ if (result.status === 'succeeded') {
1206
+ finalResult = { ...result, status: 'failed', failures: [...result.failures, { phase: 'cleanup.owned', message }],
1207
+ error: { phase: 'cleanup.owned', message } };
1208
+ }
1209
+ }
1101
1210
  if (unplannedComponents.length > 0) {
1102
1211
  const message = 'operationPlanResidual: Newly discovered owned output was not included in the cleanup plan and was preserved.';
1103
1212
  result.residual = [...new Set([
@@ -1130,6 +1239,8 @@ async function cleanupOfflineOwnedComponents(options) {
1130
1239
  };
1131
1240
  }
1132
1241
  }
1242
+ if (!finalResult.deploymentExclusions?.length)
1243
+ finalResult.deploymentExclusions = options.nativePreparation?.deploymentExclusions.filter((entry) => entry.pluginId === target.pluginId && entry.platform === target.platform && entry.scope.kind === target.scope);
1133
1244
  results.push(finalResult);
1134
1245
  }
1135
1246
  catch (error) {
@@ -1159,7 +1270,8 @@ async function cleanupOfflineOwnedComponents(options) {
1159
1270
  rebuildResults: results,
1160
1271
  commandResults: context.commandResults ?? [],
1161
1272
  targetResults: results.map(toTargetResult),
1162
- overallState: results.every((result) => result.status === 'succeeded') ? 'succeeded' : 'failed',
1273
+ overallState: results.every((result) => result.status === 'succeeded') ? 'succeeded'
1274
+ : results.some((result) => result.status === 'succeeded' || hasRebuildMutation(result)) ? 'partial' : 'failed',
1163
1275
  receiptTargets: results.map((result) => ({
1164
1276
  pluginName: result.target.pluginName,
1165
1277
  pluginId: result.target.pluginId,
@@ -1183,10 +1295,24 @@ async function previewOfflineOwnedComponents(options) {
1183
1295
  await options.onPreviewStage?.('dependencyPlan');
1184
1296
  return preview;
1185
1297
  }
1186
- function createOfflineCleanupOperationPlan(evidence, requirements, warnings = [], retainedPackages = []) {
1298
+ function createOfflineCleanupOperationPlan(evidence, requirements, warnings = [], retainedPackages = [], nativePreparation) {
1299
+ const reviewedActions = (target) => target.plan.actions.filter((action) => {
1300
+ const prepared = nativePreparation?.targets.get(offlineCleanupKey(target));
1301
+ if (!prepared)
1302
+ return !action.recoveryCandidate || !needsFrozenNativeRemoval(action.recoveryCandidate);
1303
+ if (action.action === 'removeNativeRegistration')
1304
+ return false;
1305
+ const component = action.component;
1306
+ if (!component || !('path' in component) || !prepared.ownedComponents.some((item) => 'path' in item && item.path === component.path))
1307
+ return true;
1308
+ return prepared.platformDeployment?.plans.some((plan) => plan.effects.some((effect) => effect.kind === 'remove-owned' && effect.destination === component.path)) === true;
1309
+ });
1187
1310
  return createOperationPlan({
1311
+ deploymentExclusions: nativePreparation?.deploymentExclusions ?? [],
1312
+ nativeToolChanges: nativePreparation ? [...nativePreparation.targets.values()].flatMap((target) => target.nativeToolChanges ?? []) : [],
1313
+ ...(nativePreparation ? { deploymentPlans: [...nativePreparation.targets.values()].flatMap((target) => target.platformDeployment?.plans ?? []) } : {}),
1188
1314
  intentChanges: [],
1189
- actions: [...retainedPackages, ...evidence.flatMap((target) => target.plan.actions.flatMap((action) => action.action === 'removeOwnedOutput'
1315
+ actions: [...retainedPackages, ...evidence.flatMap((target) => reviewedActions(target).flatMap((action) => action.action === 'removeOwnedOutput'
1190
1316
  ? [{
1191
1317
  kind: 'removeOwnedArtifact',
1192
1318
  pluginId: target.pluginId,
@@ -1205,12 +1331,12 @@ function createOfflineCleanupOperationPlan(evidence, requirements, warnings = []
1205
1331
  enabled: false,
1206
1332
  }]
1207
1333
  : []))],
1208
- changes: evidence.flatMap((target) => target.plan.actions.flatMap((action) => action.action === 'removeOwnedOutput'
1334
+ changes: evidence.flatMap((target) => reviewedActions(target).flatMap((action) => action.action === 'removeOwnedOutput'
1209
1335
  ? [`${target.pluginId}:${target.platform}:${target.scope}:${action.action}:${action.target}`]
1210
1336
  : action.activationScope === target.scope
1211
1337
  ? [`${target.pluginId}:${target.platform}:${target.scope}:setActivation:false:${action.target}`]
1212
1338
  : [])),
1213
- warnings: [...warnings],
1339
+ warnings: [...warnings, ...nativePreparation?.warnings ?? []],
1214
1340
  evidence: {
1215
1341
  catalogDigests: evidence.map((target) => ({
1216
1342
  sourceId: target.sourceId,
@@ -1353,12 +1479,15 @@ async function buildLiveForceExclusiveCleanupPlan(options) {
1353
1479
  && reference.platform === target.platform
1354
1480
  && reference.scope === target.scope);
1355
1481
  for (const reference of references) {
1482
+ if (reference.ownedComponent?.kind === 'owned-directory')
1483
+ continue;
1356
1484
  if (path.basename(reference.location) === SKILL_OWNER_MARKER) {
1357
1485
  const skillRoot = path.dirname(reference.location);
1358
1486
  const allowedRoot = path.dirname(skillRoot);
1359
1487
  const marker = await readSkillOwnerMarker({ skillRoot, allowedRoot }).catch(() => null);
1360
- if (marker
1488
+ if (marker && !marker.nativeProjection
1361
1489
  && marker.sourceId === target.sourceId
1490
+ && marker.sourceIdentity === target.sourceIdentity
1362
1491
  && marker.pluginId === target.pluginId
1363
1492
  && marker.platform === target.platform
1364
1493
  && marker.scope === target.scope) {
@@ -1370,6 +1499,7 @@ async function buildLiveForceExclusiveCleanupPlan(options) {
1370
1499
  .then((content) => parseOwnedTextHeader(content))
1371
1500
  .catch(() => null);
1372
1501
  if (parsed
1502
+ && parsed.identity.sourceIdentity === target.sourceIdentity
1373
1503
  && parsed.identity.sourceId === target.sourceId
1374
1504
  && parsed.identity.pluginId === target.pluginId
1375
1505
  && parsed.identity.platform === target.platform
@@ -1460,26 +1590,6 @@ async function mergeForceCleanupPlans(...plans) {
1460
1590
  function removedCleanupDigest(value) {
1461
1591
  return `sha256:${crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex')}`;
1462
1592
  }
1463
- async function removedProjectionTreeFingerprint(root) {
1464
- const visit = async (location) => {
1465
- const stats = await fs.lstat(location).catch((error) => {
1466
- if (error.code === 'ENOENT')
1467
- return null;
1468
- throw error;
1469
- });
1470
- if (!stats)
1471
- return null;
1472
- if (stats.isSymbolicLink() || (!stats.isDirectory() && !stats.isFile())) {
1473
- return { kind: 'unsafe', mode: stats.mode, size: stats.size, mtimeMs: stats.mtimeMs };
1474
- }
1475
- if (stats.isFile()) {
1476
- return { kind: 'file', digest: `sha256:${crypto.createHash('sha256').update(await fs.readFile(location)).digest('hex')}` };
1477
- }
1478
- const entries = await fs.readdir(location);
1479
- return { kind: 'directory', entries: await Promise.all(entries.sort().map(async (name) => [name, await visit(path.join(location, name))])) };
1480
- };
1481
- return removedCleanupDigest(await visit(root));
1482
- }
1483
1593
  export async function inspectRemovedPluginConfig(options) {
1484
1594
  const inspection = await inspectPluginConfigResetTarget(options);
1485
1595
  if (inspection.kind !== 'regularFile')
@@ -1526,111 +1636,11 @@ export async function inspectRemovedPluginCleanup(options) {
1526
1636
  if (generation.manifest.entries.some((entry) => entry.name === parsed.pluginName))
1527
1637
  return null;
1528
1638
  const pluginId = formatPluginId(parsed);
1529
- const blockers = [];
1530
- const marketplaceRoot = path.join(resolveAwHome(options.env), 'marketplaces', parsed.sourceId);
1531
1639
  const relevant = options.inventory.references.filter((reference) => reference.sourceId === parsed.sourceId && reference.pluginName === parsed.pluginName);
1532
1640
  const ownershipConflict = relevant.some((reference) => reference.sourceIdentity !== undefined
1533
1641
  && reference.sourceIdentity !== generation.sourceIdentity);
1534
- if (ownershipConflict) {
1535
- blockers.push('removedPluginOwnershipConflict: live source identity differs from Active. Repair ownership evidence, then retry cleanup.');
1536
- }
1537
- let root = null;
1538
- try {
1539
- root = await readStrictNamespacedMarketplaceRoot({
1540
- rootDir: marketplaceRoot,
1541
- sourceId: parsed.sourceId,
1542
- sourceIdentity: generation.sourceIdentity,
1543
- });
1544
- if (root?.config.logicalIdentity && root.config.logicalIdentity !== generation.logicalIdentity) {
1545
- blockers.push('removedPluginMarketplaceIdentityConflict: marketplace logical identity differs from Active.');
1546
- }
1547
- }
1548
- catch (error) {
1549
- blockers.push(`removedPluginMarketplaceEvidenceUnavailable: ${error instanceof Error ? error.message : String(error)}`);
1550
- }
1551
- const registeredNames = canonicalMarketplaceRegistrationNames(options.inventory.references, parsed.sourceId);
1552
- const marketplaceName = root?.config.marketplaceName
1553
- ?? (registeredNames.length === 1 ? registeredNames[0] : undefined);
1554
- let registrationReadFailed = false;
1555
- const registration = root ? await inspectNativeMarketplaceRegistrations({
1556
- marketplaceName: root.config.marketplaceName,
1557
- marketplaceRoot,
1558
- cwd: options.cwd,
1559
- env: options.env,
1560
- }).catch((error) => {
1561
- registrationReadFailed = true;
1562
- blockers.push(`removedPluginMarketplaceRegistrationUnknown: ${error instanceof Error ? error.message : String(error)}`);
1563
- return null;
1564
- }) : null;
1565
- const projectionOwnershipVerified = Boolean(root
1566
- && !ownershipConflict
1567
- && (!root.config.logicalIdentity || root.config.logicalIdentity === generation.logicalIdentity));
1568
- const nativeOwnershipVerified = projectionOwnershipVerified
1569
- && registration?.codex === 'canonical';
1570
- let claudeNativeCleanupBlocked = registrationReadFailed;
1571
- if (registration?.claude === 'foreign') {
1572
- blockers.push('removedPluginClaudeOwnershipConflict: Claude marketplace registration is foreign.');
1573
- claudeNativeCleanupBlocked = true;
1574
- }
1575
- if (registration?.claude !== 'canonical' && relevant.some((reference) => reference.platform === 'claude' && reference.kind === 'namespacedMarketplace')) {
1576
- blockers.push('removedPluginClaudeOwnershipUnavailable: Claude native evidence exists without a canonical marketplace registration.');
1577
- claudeNativeCleanupBlocked = true;
1578
- }
1579
- const activationScopes = [];
1580
- if (marketplaceName) {
1581
- const inspectedPaths = new Set();
1582
- for (const scope of [options.scope]) {
1583
- const configPath = resolveCodexPaths(options.cwd, scope, options.env).configTomlPath;
1584
- if (inspectedPaths.has(path.resolve(configPath)))
1585
- continue;
1586
- inspectedPaths.add(path.resolve(configPath));
1587
- try {
1588
- const config = await readCodexConfigFile(configPath);
1589
- if (Object.hasOwn(config.snapshot.plugins, `${parsed.pluginName}@${marketplaceName}`)) {
1590
- activationScopes.push({
1591
- scope,
1592
- enabled: config.snapshot.plugins[`${parsed.pluginName}@${marketplaceName}`]?.enabled,
1593
- });
1594
- }
1595
- }
1596
- catch (error) {
1597
- blockers.push(`removedPluginActivationReadFailed: ${scope}: ${error instanceof Error ? error.message : String(error)}`);
1598
- }
1599
- }
1600
- }
1601
- let nativeState = 'unbound';
1602
- let nativeObservationFingerprint = removedCleanupDigest('unbound');
1603
- if (root) {
1604
- if (registration?.codex === 'foreign') {
1605
- blockers.push('removedPluginNativeOwnershipConflict: Codex marketplace registration is foreign.');
1606
- }
1607
- else {
1608
- const observed = await inspectCodexPluginRegistrationLive({
1609
- pluginId: `${parsed.pluginName}@${marketplaceName}`,
1610
- cwd: options.cwd,
1611
- env: options.env,
1612
- nativeCliRunner: options.nativeCliRunner,
1613
- manager: options.codexManager,
1614
- scope: options.scope,
1615
- });
1616
- nativeState = observed.observation.state === 'observed'
1617
- ? observed.observation.value === 'installed' ? 'installed' : 'absent'
1618
- : 'unknown';
1619
- nativeObservationFingerprint = removedCleanupDigest(observed.observation);
1620
- if (nativeState === 'unknown') {
1621
- blockers.push('removedPluginNativeObservationUnknown: official Codex list did not confirm installed or absent. Retry cleanup with a compatible Codex CLI.');
1622
- }
1623
- if (registration?.codex !== 'canonical'
1624
- && (nativeState === 'installed' || activationScopes.length > 0)) {
1625
- blockers.push('removedPluginNativeOwnershipUnavailable: native or activation evidence exists but canonical marketplace registration is missing.');
1626
- }
1627
- }
1628
- }
1629
- else if (options.inventory.references.some((reference) => reference.pluginName === parsed.pluginName
1630
- && reference.platform === 'codex'
1631
- && reference.marketplaceName)) {
1632
- blockers.push('removedPluginNativeOwnershipUnavailable: native evidence remains without a valid AW marketplace root.');
1633
- }
1642
+ const blockers = ownershipConflict
1643
+ ? ['removedPluginOwnershipConflict: live source identity differs from Active. Repair ownership evidence, then retry cleanup.'] : [];
1634
1644
  const configTargets = [];
1635
1645
  for (const scope of [options.scope]) {
1636
1646
  try {
@@ -1654,95 +1664,39 @@ export async function inspectRemovedPluginCleanup(options) {
1654
1664
  blockers.push(`removedPluginConfigTargetUnsafe: ${scope}: ${error instanceof Error ? error.message : String(error)}`);
1655
1665
  }
1656
1666
  }
1657
- const projectionRoot = path.join(marketplaceRoot, 'plugins', parsed.pluginName);
1658
- let projectionPathSafe = true;
1659
- if (root) {
1660
- try {
1661
- await assertSafeNamespacedMarketplacePluginRoot(marketplaceRoot, parsed.pluginName);
1662
- }
1663
- catch (error) {
1664
- projectionPathSafe = false;
1665
- blockers.push(`removedPluginMarketplaceProjectionUnsafe: ${error instanceof Error ? error.message : String(error)}`);
1666
- }
1667
- }
1668
- const projectionStats = root && projectionPathSafe ? await fs.lstat(projectionRoot).catch((error) => {
1669
- if (error.code === 'ENOENT')
1670
- return null;
1671
- throw error;
1672
- }) : null;
1673
- const projectionPresent = Boolean(root && (projectionStats
1674
- || [root.agentsManifest, root.claudeManifest].some((manifest) => manifest && Array.isArray(manifest.plugins) && manifest.plugins.some((entry) => entry !== null && typeof entry === 'object'
1675
- && entry.name === parsed.pluginName))));
1676
- const projectionFingerprint = removedCleanupDigest({
1677
- tree: root && projectionPathSafe ? await removedProjectionTreeFingerprint(projectionRoot) : 'unsafe',
1678
- agentsEntries: root && Array.isArray(root.agentsManifest.plugins)
1679
- ? root.agentsManifest.plugins.filter((entry) => entry !== null && typeof entry === 'object'
1680
- && entry.name === parsed.pluginName)
1681
- : null,
1682
- claudeEntries: root?.claudeManifest && Array.isArray(root.claudeManifest.plugins)
1683
- ? root.claudeManifest.plugins.filter((entry) => entry !== null && typeof entry === 'object'
1684
- && entry.name === parsed.pluginName)
1685
- : null,
1686
- });
1687
- const marketplaceEvidenceFingerprint = removedCleanupDigest({
1688
- config: root?.config ?? null,
1689
- registration,
1690
- marketplaceName,
1691
- });
1692
1667
  const evidence = [];
1693
- for (const platform of ['codex', 'claude']) {
1694
- for (const scope of [options.scope]) {
1695
- const base = offlineCleanupEvidenceFromInventory({
1696
- reason: 'bundleUnavailable',
1697
- pluginId,
1698
- pluginName: parsed.pluginName,
1699
- sourceId: parsed.sourceId,
1700
- sourceIdentity: generation.sourceIdentity,
1701
- platform,
1702
- scope,
1703
- inventory: options.inventory,
1704
- }) ?? intentOnlyOfflineCleanupEvidence({
1705
- pluginId,
1706
- pluginName: parsed.pluginName,
1707
- sourceId: parsed.sourceId,
1708
- sourceIdentity: generation.sourceIdentity,
1709
- platform,
1710
- scope,
1711
- });
1712
- const actions = base.plan.actions.filter((action) => action.action !== 'removeNativeRegistration'
1713
- || (platform === 'codex'
1714
- && nativeOwnershipVerified
1715
- && projectionPathSafe
1716
- && action.activationScope === scope));
1717
- const safeActions = ownershipConflict ? [] : actions;
1718
- const enrichedActions = await Promise.all(safeActions.map(async (action) => action.action === 'removeOwnedOutput'
1719
- ? { ...action, pathEvidence: await removedProjectionTreeFingerprint(action.target.split('#', 1)[0]) }
1720
- : action));
1721
- const plan = { ...base.plan, actions: enrichedActions };
1722
- evidence.push({ ...base, plan, planDigest: removedCleanupDigest(plan), targetFingerprint: removedCleanupDigest(plan) });
1668
+ for (const platform of NATIVE_PLATFORM_TARGETS) {
1669
+ const base = offlineCleanupEvidenceFromInventory({ reason: 'bundleUnavailable', pluginId,
1670
+ pluginName: parsed.pluginName, sourceId: parsed.sourceId, sourceIdentity: generation.sourceIdentity,
1671
+ platform, scope: options.scope, inventory: options.inventory });
1672
+ if (!base)
1673
+ continue;
1674
+ const actions = ownershipConflict ? [] : base.plan.actions.filter((action) => action.action !== 'removeNativeRegistration');
1675
+ const plan = { ...base.plan, actions };
1676
+ evidence.push({ ...base, plan, planDigest: removedCleanupDigest(plan), targetFingerprint: removedCleanupDigest(plan) });
1677
+ }
1678
+ const candidates = evidence.flatMap((entry) => entry.plan.actions.flatMap((action) => action.recoveryCandidate ? [action.recoveryCandidate] : []));
1679
+ for (const platform of NATIVE_PLATFORM_TARGETS) {
1680
+ if (relevant.some((reference) => reference.kind === 'namespacedMarketplace' && reference.platform === platform
1681
+ && reference.scope === options.scope) && !candidates.some((candidate) => candidate.binding.platform === platform)) {
1682
+ blockers.push(`removedPluginNativeOwnershipUnavailable: ${platform} registration remains without a verified physical package owner.`);
1723
1683
  }
1724
1684
  }
1685
+ const first = candidates[0];
1686
+ const firstLayout = first ? await getDeploymentLayout({ cwd: options.cwd, env: options.env }, first.binding) : undefined;
1725
1687
  return {
1726
- pluginId,
1727
- pluginName: parsed.pluginName,
1728
- sourceId: parsed.sourceId,
1729
- sourceIdentity: generation.sourceIdentity,
1730
- logicalIdentity: generation.logicalIdentity,
1688
+ pluginId, pluginName: parsed.pluginName, sourceId: parsed.sourceId,
1689
+ sourceIdentity: generation.sourceIdentity, logicalIdentity: generation.logicalIdentity,
1731
1690
  snapshotDigest: generation.snapshotDigest,
1732
- marketplaceRoot,
1733
- ...(marketplaceName ? { marketplaceName } : {}),
1734
- nativeOwnershipVerified: nativeOwnershipVerified && projectionPathSafe,
1735
- projectionOwnershipVerified: projectionOwnershipVerified && projectionPathSafe,
1736
- claudeNativeCleanupBlocked,
1737
- nativeState,
1738
- nativeObservationFingerprint,
1739
- marketplaceEvidenceFingerprint,
1740
- projectionFingerprint,
1741
- projectionPresent,
1742
- activationScopes,
1743
- configTargets,
1744
- evidence,
1745
- blockers,
1691
+ marketplaceRoot: firstLayout?.marketplaceRoot ?? path.join(resolveAwHome(options.env), 'platforms'),
1692
+ ...(firstLayout?.marketplaceName ? { marketplaceName: firstLayout.marketplaceName } : {}),
1693
+ nativeOwnershipVerified: candidates.length > 0 && !ownershipConflict,
1694
+ projectionOwnershipVerified: relevant.some((reference) => reference.ownedComponent) && !ownershipConflict,
1695
+ claudeNativeCleanupBlocked: false, nativeState: 'unbound',
1696
+ nativeObservationFingerprint: removedCleanupDigest(candidates),
1697
+ marketplaceEvidenceFingerprint: removedCleanupDigest(candidates.map((candidate) => candidate.physicalIdentity)),
1698
+ projectionFingerprint: removedCleanupDigest(evidence), projectionPresent: false, activationScopes: [],
1699
+ configTargets, evidence, blockers,
1746
1700
  };
1747
1701
  }
1748
1702
  export async function executeRemovedPluginOutputCleanup(options) {
@@ -1759,6 +1713,8 @@ export async function executeRemovedPluginOutputCleanup(options) {
1759
1713
  }));
1760
1714
  const withRetainedPackages = (result, operationPlan = createOfflineCleanupOperationPlan([], undefined, [], retainedActions)) => {
1761
1715
  result.operationPlan = operationPlan;
1716
+ if (operationPlan.deploymentExclusions?.length)
1717
+ result.deploymentExclusions = operationPlan.deploymentExclusions;
1762
1718
  const commandResults = [...new Map([
1763
1719
  ...retainedPackages.map(retainedManagedCommandPackageResult), ...(result.commandResults ?? []),
1764
1720
  ].map((entry) => [JSON.stringify(entry.producer), entry])).values()];
@@ -1808,7 +1764,9 @@ export async function executeRemovedPluginOutputCleanup(options) {
1808
1764
  ...(current.marketplaceName ? { marketplaceName: current.marketplaceName } : {}),
1809
1765
  nativeRegistration: entry.platform === 'codex',
1810
1766
  }));
1811
- const operationPlan = await withNativeToolRemovalImpact(createOfflineCleanupOperationPlan(evidence, undefined, [], retainedActions), options.context.env);
1767
+ const nativePreparation = await prepareOfflineNativeCleanup({ evidence, cwd: options.context.executionCwd,
1768
+ env: options.context.env, runtime: options.runtime });
1769
+ const operationPlan = await withNativeToolRemovalImpact(createOfflineCleanupOperationPlan(evidence, undefined, [], retainedActions, nativePreparation), options.context.env);
1812
1770
  if (options.runtime?.expectedPlanFingerprint) {
1813
1771
  assertOperationPlanFingerprint(options.runtime.expectedPlanFingerprint, operationPlan);
1814
1772
  }
@@ -1825,6 +1783,7 @@ export async function executeRemovedPluginOutputCleanup(options) {
1825
1783
  : await cleanupOfflineOwnedComponents({
1826
1784
  targets,
1827
1785
  evidence,
1786
+ nativePreparation,
1828
1787
  inventoryErrors: inventory.errors.filter((error) => !error.kind.startsWith('config')),
1829
1788
  cwd: options.context.executionCwd,
1830
1789
  env: options.context.env,
@@ -1835,12 +1794,7 @@ export async function executeRemovedPluginOutputCleanup(options) {
1835
1794
  removeObsoleteInstallationContracts: options.runtime?.removeObsoleteInstallationContracts,
1836
1795
  });
1837
1796
  withRetainedPackages(result, operationPlan);
1838
- const residual = [
1839
- ...current.blockers.filter((blocker) => !blocker.includes('Config')),
1840
- ...(current.nativeState === 'installed' || current.nativeState === 'unknown'
1841
- ? ['sharedNativePreserved: Codex package remains available to other scopes.'] : []),
1842
- ...(current.projectionPresent ? ['sharedMarketplaceProjectionPreserved'] : []),
1843
- ];
1797
+ const residual = current.blockers.filter((blocker) => !blocker.includes('Config'));
1844
1798
  if (residual.length > 0) {
1845
1799
  result.warnings.push(...residual);
1846
1800
  if (result.overallState === 'succeeded')
@@ -1885,39 +1839,15 @@ async function runRebuildCommandInSession(options) {
1885
1839
  env: runtimeEnv,
1886
1840
  scope: options.commandOptions.scope,
1887
1841
  });
1888
- if (options.command !== 'cleanup'
1889
- || options.commandOptions.scope !== 'project'
1890
- || !selectedPlatforms(options.commandOptions.platform).includes('codex'))
1891
- return inventory;
1892
- let projectSkills = cleanupProjectSkillsByInventory.get(inventory);
1893
- if (!projectSkills) {
1894
- projectSkills = await selectedProjectCodexSkillReferences({
1895
- cwd: options.commandOptions.cwd,
1896
- });
1897
- cleanupProjectSkillsByInventory.set(inventory, projectSkills);
1898
- }
1899
- const selectors = options.pluginNames.map(parsePluginId);
1900
- const selectedProjectSkills = options.all === true
1901
- ? projectSkills
1902
- : projectSkills.filter((reference) => selectors.some((selector) => selector.pluginName === reference.pluginName
1903
- && (selector.sourceId === undefined || selector.sourceId === reference.sourceId)));
1904
- return {
1905
- ...inventory,
1906
- references: [...new Map([...inventory.references, ...selectedProjectSkills].map((reference) => [[
1907
- reference.kind,
1908
- reference.location,
1909
- reference.sourceId ?? '',
1910
- reference.pluginName ?? '',
1911
- reference.platform ?? '',
1912
- reference.scope ?? '',
1913
- ].join('\0'), reference])).values()],
1914
- };
1842
+ return inventory;
1915
1843
  });
1916
1844
  return ordinaryInventory;
1917
1845
  };
1918
1846
  let requestedPluginNames = options.pluginNames;
1919
1847
  const cleanupForce = options.command === 'cleanup'
1920
1848
  && options.commandOptions.force === true;
1849
+ const uninstallForce = options.command === 'uninstall'
1850
+ && options.commandOptions.force === true;
1921
1851
  const cleanupRequirements = options.command === 'cleanup' ? executionInput.requirements : undefined;
1922
1852
  const expectedOfflineCleanup = options.runtime?.expectedOfflineCleanupEvidence;
1923
1853
  let cleanupInventory;
@@ -2046,9 +1976,10 @@ async function runRebuildCommandInSession(options) {
2046
1976
  scope: options.commandOptions.scope,
2047
1977
  }] : []);
2048
1978
  });
2049
- cleanupTargets = [...new Map([...damagedTargets, ...intentTargets, ...cleanupLiveTargets].map((target) => [
2050
- `${target.pluginId}\0${target.platform}\0${target.scope}`,
2051
- target,
1979
+ const liveLogicalKeys = new Set(cleanupLiveTargets.map((target) => `${target.pluginId}\0${target.platform}\0${target.scope}`));
1980
+ const targetsWithoutLiveEvidence = [...damagedTargets, ...intentTargets].filter((target) => !liveLogicalKeys.has(`${target.pluginId}\0${target.platform}\0${target.scope}`));
1981
+ cleanupTargets = [...new Map([...targetsWithoutLiveEvidence, ...cleanupLiveTargets].map((target) => [
1982
+ offlineCleanupKey(target), target,
2052
1983
  ])).values()].filter(selectedExecutionTarget);
2053
1984
  requestedPluginNames = [...new Set([
2054
1985
  ...requestedPluginNames,
@@ -2308,10 +2239,13 @@ async function runRebuildCommandInSession(options) {
2308
2239
  return value ? [value] : [];
2309
2240
  });
2310
2241
  evidence = cleanupTargets.map((target) => evidence.find((candidate) => candidate.pluginId === target.pluginId
2242
+ && candidate.sourceIdentity === target.sourceIdentity
2311
2243
  && candidate.platform === target.platform
2312
2244
  && candidate.scope === target.scope)
2313
2245
  ?? intentOnlyOfflineCleanupEvidence(target));
2314
- const operationPlan = await withNativeToolRemovalImpact(createOfflineCleanupOperationPlan(evidence, { scope: options.commandOptions.scope, view: cleanupRequirements }, [...cleanupInventoryWarnings(cleanupInventory, cleanupTargets), ...cleanupUnavailableWarnings], retainedPackageActions), runtimeEnv);
2246
+ const nativePreparation = await prepareOfflineNativeCleanup({ evidence, cwd: options.commandOptions.cwd,
2247
+ env: runtimeEnv, runtime: options.runtime });
2248
+ const operationPlan = await withNativeToolRemovalImpact(createOfflineCleanupOperationPlan(evidence, { scope: options.commandOptions.scope, view: cleanupRequirements }, [...cleanupInventoryWarnings(cleanupInventory, cleanupTargets), ...cleanupUnavailableWarnings], retainedPackageActions, nativePreparation), runtimeEnv);
2315
2249
  if (options.runtime?.expectedPlanFingerprint) {
2316
2250
  assertOperationPlanFingerprint(options.runtime.expectedPlanFingerprint, operationPlan);
2317
2251
  }
@@ -2330,6 +2264,7 @@ async function runRebuildCommandInSession(options) {
2330
2264
  const cleanupResult = await cleanupOfflineOwnedComponents({
2331
2265
  targets: cleanupLiveTargets,
2332
2266
  evidence,
2267
+ nativePreparation,
2333
2268
  cwd: options.commandOptions.cwd,
2334
2269
  env: runtimeEnv,
2335
2270
  inventoryErrors: cleanupInventory.errors,
@@ -2781,6 +2716,11 @@ async function runRebuildCommandInSession(options) {
2781
2716
  }
2782
2717
  }
2783
2718
  const executionContext = {
2719
+ nativeConsent: options.runtime?.nativeConsent === true,
2720
+ recoveryCandidates: options.runtime?.recoveryCandidates,
2721
+ sharedReferenceView: options.runtime?.executionInput?.requirements.sharedReferenceView ?? options.runtime?.sharedReferenceView,
2722
+ platformRebuildSession: options.runtime?.platformRebuildSession,
2723
+ packagePreparationCache: options.runtime?.packagePreparationCache,
2784
2724
  preparedArtifactRenderResults: options.runtime?.preparedArtifactRenderResults,
2785
2725
  interruption: options.runtime?.interruption,
2786
2726
  signal: options.runtime?.signal,
@@ -2800,49 +2740,10 @@ async function runRebuildCommandInSession(options) {
2800
2740
  nativeActivationOnlyTargets: options.runtime?.nativeActivationOnlyTargets,
2801
2741
  commandResults: options.runtime?.commandResults,
2802
2742
  };
2803
- let planningManagerPreview;
2804
- let planningManagerError;
2805
- const needsCodexObservation = executionSelections.some(({ entry, platform }) => platform === 'codex' && analyzeCodexSurface(entry.plugin.manifest).nativeKinds.length > 0);
2806
- if (needsCodexObservation && !executionContext.codexManager) {
2807
- const managerOptions = {
2808
- cwd: options.commandOptions.cwd,
2809
- env: runtimeEnv,
2810
- runner: executionContext.nativeCliRunner,
2811
- signal: options.runtime?.signal,
2812
- operationRequirement: getCodexOperationRequirement(options.commandOptions.scope),
2813
- };
2814
- try {
2815
- const useExecutionResolver = !options.runtime?.previewOperationPlan
2816
- && ['install', 'sync', 'reinstall'].includes(options.command);
2817
- if (useExecutionResolver && options.runtime?.codexManagerResolver) {
2818
- executionContext.codexManager = await options.runtime.codexManagerResolver(managerOptions);
2819
- }
2820
- else if (useExecutionResolver && options.runtime?.codexOperationConsumerResolver) {
2821
- executionContext.codexManager = (await options.runtime.codexOperationConsumerResolver(managerOptions)).manager;
2822
- }
2823
- else {
2824
- planningManagerPreview = await (options.runtime?.codexManagerPreviewer ?? previewCodexManager)(managerOptions);
2825
- if (planningManagerPreview.state === 'system') {
2826
- executionContext.codexManager = planningManagerPreview.manager;
2827
- }
2828
- else {
2829
- planningManagerError = new CodexManagerError(planningManagerPreview.code, planningManagerPreview.diagnostic);
2830
- }
2831
- }
2832
- }
2833
- catch (error) {
2834
- if (readSafeOperationError(error) || error instanceof Error && error.name === 'AbortError')
2835
- throw error;
2836
- planningManagerError = error;
2837
- }
2838
- // Never let an unselected PATH entry decide native state or target readiness.
2839
- executionContext.codexObservationSession?.setManager(executionContext.codexManager);
2840
- }
2841
2743
  const inspection = createRebuildIntegration({
2842
2744
  context: executionContext,
2843
2745
  scriptTimeoutMs: options.commandOptions.scriptTimeoutMs,
2844
2746
  });
2845
- let plannedCodexRegistrations = new Map();
2846
2747
  let plannedOwnedTextTargets = new Map();
2847
2748
  let plannedSkillMarkerTargets = new Map();
2848
2749
  const exactOwnedTextTargets = (plan) => {
@@ -2873,8 +2774,7 @@ async function runRebuildCommandInSession(options) {
2873
2774
  }
2874
2775
  return output;
2875
2776
  };
2876
- const createPlan = async (inventory, codexManager, planOptions) => {
2877
- plannedCodexRegistrations = new Map();
2777
+ const createPlan = async (inventory, _codexManager, planOptions) => {
2878
2778
  plannedOwnedTextTargets = new Map();
2879
2779
  plannedSkillMarkerTargets = new Map();
2880
2780
  assertWriteInventoryComplete(inventory);
@@ -2882,18 +2782,6 @@ async function runRebuildCommandInSession(options) {
2882
2782
  const placementNodes = [];
2883
2783
  const blockingTargets = new Map();
2884
2784
  const actualStates = new Map();
2885
- const loadPlacementCodexConfigs = async () => {
2886
- const user = await readCodexConfigFile(resolveCodexPaths(options.commandOptions.cwd, 'user', runtimeEnv).configTomlPath);
2887
- const project = options.commandOptions.scope === 'project'
2888
- ? await readCodexConfigFile(resolveCodexPaths(options.commandOptions.cwd, 'project', runtimeEnv).configTomlPath)
2889
- : { content: '', snapshot: parseCodexConfig('') };
2890
- return { user, project };
2891
- };
2892
- let placementCodexConfigs;
2893
- const readPlacementCodexConfigs = () => {
2894
- placementCodexConfigs ??= loadPlacementCodexConfigs();
2895
- return placementCodexConfigs;
2896
- };
2897
2785
  for (const [order, selection] of executionSelections.entries()) {
2898
2786
  const { entry, platform } = selection;
2899
2787
  const relation = executionInput.selectedTargets.some((target) => target.pluginId === entry.pluginId && target.platform === platform)
@@ -2952,9 +2840,14 @@ async function runRebuildCommandInSession(options) {
2952
2840
  nativeProbe: inspection.driver.probeNative,
2953
2841
  verifyHealth: true,
2954
2842
  });
2843
+ const supplementPhysicalKeys = new Set((await Promise.all((desired.platformObservations ?? [])
2844
+ .map(({ binding }) => getDeploymentLayout({ cwd: options.commandOptions.cwd, env: runtimeEnv }, binding))))
2845
+ .flatMap((layout) => layout.renderUnits.filter((unit) => unit.output === 'supplement'
2846
+ && unit.kinds.includes('agent') && unit.renderScope.kind === scope).map((unit) => unit.physicalKey)));
2955
2847
  if (result.state === 'error'
2956
- || result.components.some((component) => component.state === 'error'))
2957
- return result;
2848
+ || result.components.some((component) => component.state === 'error')) {
2849
+ return { ...result, platformObservations: desired.platformObservations ?? [], supplementPhysicalKeys };
2850
+ }
2958
2851
  const required = new Set(desired.desiredOwnedComponents ?? desired.ownedComponents);
2959
2852
  const optional = new Set(desired.optionalOwnedComponents ?? []);
2960
2853
  const presentRequired = [...required].every((component) => result.components.some((entry) => entry.component === component && entry.state === 'present'));
@@ -2969,69 +2862,70 @@ async function runRebuildCommandInSession(options) {
2969
2862
  : required.size > 0
2970
2863
  ? 'present'
2971
2864
  : hasAnyPresent ? 'present' : 'absent';
2972
- return { ...result, state };
2865
+ return { ...result, state, platformObservations: desired.platformObservations ?? [], supplementPhysicalKeys };
2973
2866
  };
2974
2867
  const otherScope = resolvedScope === 'user' ? 'project' : 'user';
2975
2868
  const [requestedInspection, otherInspection] = await Promise.all([
2976
2869
  inspectScope(resolvedScope),
2977
2870
  options.commandOptions.scope === 'user'
2978
- ? Promise.resolve({ state: 'partial', components: [], errors: [] })
2871
+ ? Promise.resolve({ state: 'partial', components: [], errors: [], platformObservations: [], supplementPhysicalKeys: new Set() })
2979
2872
  : platform === 'codex' && codexScopePathsAlias && resolvedScope === 'user'
2980
- ? Promise.resolve({ state: 'absent', components: [], errors: [] })
2873
+ ? Promise.resolve({ state: 'absent', components: [], errors: [], platformObservations: [], supplementPhysicalKeys: new Set() })
2981
2874
  : inspectScope(otherScope),
2982
2875
  ]);
2983
2876
  const surface = platform === 'codex'
2984
2877
  ? analyzeCodexSurface(entry.plugin.manifest)
2985
2878
  : undefined;
2986
- const codexPluginId = `${entry.plugin.manifest.name}@${marketplaceNameFor(entry, platform, resolvedScope)}`;
2987
- const codexRegistration = platform === 'codex'
2988
- && surface?.classification === 'native'
2989
- ? await inspectCodexPluginRegistrationLive({
2990
- pluginId: codexPluginId,
2991
- cwd: options.commandOptions.cwd,
2992
- env: runtimeEnv,
2993
- nativeCliRunner: executionContext.nativeCliRunner,
2994
- scope: codexObservationScopeByMarketplace.get(marketplaceNameFor(entry, platform, resolvedScope)) ?? 'both',
2995
- observationSession: executionContext.codexObservationSession,
2996
- ...(codexManager ? { manager: codexManager } : {}),
2997
- })
2998
- : undefined;
2999
- if (codexRegistration) {
3000
- plannedCodexRegistrations.set(codexPluginId, codexRegistration);
3001
- }
3002
- const placementActivationConfigs = codexRegistration
3003
- ? await readPlacementCodexConfigs()
3004
- : undefined;
3005
- const placementState = (inspected, scope) => {
2879
+ const conflictingCodexExtension = otherInspection.components.some(({ component, state }) => {
2880
+ if (state === 'absent' || component.kind === 'native-plugin'
2881
+ || component.identity.artifactKey.startsWith('activation-')
2882
+ || component.identity.artifactKey.startsWith('marketplace-'))
2883
+ return false;
2884
+ // Both activations inspect the same canonical user package. Its exact
2885
+ // physical owner is shared; scope-specific supplements remain separate.
2886
+ const sharedPackage = component.kind === 'owned-directory'
2887
+ && component.identity.scope === 'user'
2888
+ && component.identity.sourceIdentity === entry.source.sourceIdentity
2889
+ && component.identity.physicalKey !== undefined
2890
+ && requestedInspection.components.some(({ component: requested }) => requested.kind === 'owned-directory'
2891
+ && requested.path === component.path
2892
+ && requested.allowedRoot === component.allowedRoot
2893
+ && requested.identity.scope === 'user'
2894
+ && requested.identity.sourceIdentity === component.identity.sourceIdentity
2895
+ && requested.identity.pluginId === component.identity.pluginId
2896
+ && requested.identity.physicalKey === component.identity.physicalKey);
2897
+ const separateAgent = component.kind === 'owned-text-file'
2898
+ && component.identity.sourceIdentity === entry.source.sourceIdentity
2899
+ && component.identity.scope === otherScope
2900
+ && component.identity.physicalKey !== undefined
2901
+ && otherInspection.supplementPhysicalKeys.has(component.identity.physicalKey)
2902
+ && !requestedInspection.supplementPhysicalKeys.has(component.identity.physicalKey);
2903
+ return !sharedPackage && !separateAgent;
2904
+ });
2905
+ const placementState = (inspected) => {
3006
2906
  if (platform !== 'codex'
3007
- || surface?.classification !== 'native'
3008
2907
  || options.command === 'cleanup'
3009
2908
  || options.command === 'uninstall')
3010
2909
  return inspected.state;
3011
- if (!codexRegistration)
2910
+ const observed = inspected.platformObservations.map(({ observation }) => observation);
2911
+ if (!observed.length || inspected.state === 'error')
3012
2912
  return inspected.state;
3013
- if (codexRegistration.observation.state === 'failed')
2913
+ if (observed.some((observation) => observation.diagnostics.some((diagnostic) => diagnostic.code === 'nativeObservationFailed')))
3014
2914
  return 'error';
3015
- if (codexRegistration.observation.state === 'unobserved')
2915
+ if (observed.some((observation) => observation.package === 'unknown' || observation.registration === 'unknown'
2916
+ || observation.consumers.some((consumer) => consumer.activation === 'unknown')))
3016
2917
  return 'partial';
3017
- if (codexRegistration.observation.value === 'absent')
2918
+ if (observed.every((observation) => observation.package === 'absent' || observation.registration === 'absent'))
3018
2919
  return 'absent';
3019
- const configEnabled = placementActivationConfigs.user
3020
- .snapshot.plugins[codexPluginId]?.enabled === true
3021
- || (scope === 'project'
3022
- && placementActivationConfigs.project
3023
- .snapshot.plugins[codexPluginId]?.enabled === true);
3024
- return configEnabled
3025
- ? inspected.state
3026
- : 'partial';
2920
+ if (observed.some((observation) => observation.package === 'absent' || observation.registration === 'absent'
2921
+ || observation.package === 'present' && observation.packageVersion !== entry.plugin.manifest.version
2922
+ || observation.consumers.some((consumer) => consumer.activation !== 'enabled' || consumer.trust === 'required' || consumer.trust === 'blocked' || consumer.trust === 'unknown')
2923
+ || observation.components.some((component) => component.presence !== 'present' || component.reasonCodes.length > 0)))
2924
+ return 'partial';
2925
+ return inspected.state;
3027
2926
  };
3028
- const requestedPlacementState = placementState(requestedInspection, requestedScope);
3029
- let otherPlacementState = placementState(otherInspection, otherScope);
3030
- if (surface?.classification === 'native'
3031
- && requestedPlacementState === 'present'
3032
- && otherPlacementState === 'present') {
3033
- otherPlacementState = 'absent';
3034
- }
2927
+ const requestedPlacementState = placementState(requestedInspection);
2928
+ const otherPlacementState = placementState(otherInspection);
3035
2929
  actualStates.set(`${entry.pluginId}\0${platform}\0${requestedScope}`, requestedPlacementState);
3036
2930
  actualStates.set(`${entry.pluginId}\0${platform}\0${otherScope}`, otherPlacementState);
3037
2931
  const allowedScopes = platform === 'codex'
@@ -3061,6 +2955,7 @@ async function runRebuildCommandInSession(options) {
3061
2955
  let errorCode;
3062
2956
  if (!dependencyEnabled && platform === 'codex'
3063
2957
  && relation === 'requested'
2958
+ && !uninstallForce
3064
2959
  && codexDemandRootsFor(entry).some((root) => !selectedCodexRoot(root.pluginId))) {
3065
2960
  action = 'block';
3066
2961
  errorCode = 'dependencyStillRequired';
@@ -3073,10 +2968,7 @@ async function runRebuildCommandInSession(options) {
3073
2968
  && surface?.scopeOverlap === 'aw-owned-conflict'
3074
2969
  && options.command !== 'cleanup'
3075
2970
  && options.command !== 'uninstall'
3076
- && otherInspection.components.some((component) => component.state !== 'absent'
3077
- && component.component.kind !== 'native-plugin'
3078
- && !component.component.identity.artifactKey.startsWith('activation-')
3079
- && !component.component.identity.artifactKey.startsWith('marketplace-'))) {
2971
+ && conflictingCodexExtension) {
3080
2972
  action = 'block';
3081
2973
  errorCode = 'codexExtensionScopeConflict';
3082
2974
  }
@@ -3111,10 +3003,7 @@ async function runRebuildCommandInSession(options) {
3111
3003
  && !(requestedScope === 'project'
3112
3004
  && dependencyScopeOverride?.scope === 'project'
3113
3005
  && otherPlacementState === 'present')
3114
- && otherInspection.components.some((component) => component.state !== 'absent'
3115
- && component.component.kind !== 'native-plugin'
3116
- && !component.component.identity.artifactKey.startsWith('activation-')
3117
- && !component.component.identity.artifactKey.startsWith('marketplace-'))) {
3006
+ && conflictingCodexExtension) {
3118
3007
  action = 'block';
3119
3008
  errorCode = 'codexExtensionScopeConflict';
3120
3009
  }
@@ -3292,222 +3181,7 @@ async function runRebuildCommandInSession(options) {
3292
3181
  const isHealthyWiderDependency = (target) => target.relation === 'dependency'
3293
3182
  && target.resolvedScope !== options.commandOptions.scope
3294
3183
  && target.action === 'keep';
3295
- const createCodexPlans = async (plan, activationSupport = 'observed', codexManager) => {
3296
- const codexTargets = plan.targets.filter((target) => target.platform === 'codex');
3297
- const currentScope = options.commandOptions.scope;
3298
- const reconciledCodexTargetsByPlugin = new Map();
3299
- for (const target of codexTargets) {
3300
- if (!reconciledCodexTargetsByPlugin.has(target.pluginId)
3301
- || target.resolvedScope === 'user') {
3302
- reconciledCodexTargetsByPlugin.set(target.pluginId, target);
3303
- }
3304
- }
3305
- const reconciledCodexTargets = [...reconciledCodexTargetsByPlugin.values()];
3306
- if (reconciledCodexTargets.length === 0)
3307
- return [];
3308
- const desiredScopesForEntry = (entry) => {
3309
- const roots = codexDemandRootsFor(entry);
3310
- const protectedRoot = roots.some((root) => !selectedCodexRoot(root.pluginId));
3311
- const selectedForRemoval = selectedCodexRoot(entry.pluginId);
3312
- if ((options.command === 'cleanup' || options.command === 'uninstall')
3313
- && (roots.length === 0 || (selectedForRemoval && !protectedRoot)))
3314
- return [];
3315
- const planned = plan.targets.find((target) => target.pluginId === entry.pluginId && target.platform === 'codex');
3316
- return [planned?.resolvedScope ?? currentScope];
3317
- };
3318
- const intentScopesForEntry = (entry) => codexDemandRootsFor(entry).length > 0 ? [currentScope] : [];
3319
- const inspectBothScopes = currentScope === 'project';
3320
- const userConfig = await readCodexConfigFile(resolveCodexPaths(options.commandOptions.cwd, 'user', runtimeEnv).configTomlPath);
3321
- const projectConfig = currentScope === 'project'
3322
- ? await readCodexConfigFile(resolveCodexPaths(options.commandOptions.cwd, 'project', runtimeEnv).configTomlPath)
3323
- : { content: '', snapshot: parseCodexConfig('') };
3324
- const catalogClosure = [];
3325
- const liveEvidence = [];
3326
- const desiredScopesByPluginId = new Map();
3327
- const intentScopesByPluginId = new Map();
3328
- for (const planned of reconciledCodexTargets) {
3329
- const entry = available.find((candidate) => candidate.pluginId === planned.pluginId);
3330
- const marketplaceName = marketplaceNameFor(entry, 'codex', planned.resolvedScope);
3331
- const codexPluginId = `${entry.plugin.manifest.name}@${marketplaceName}`;
3332
- const desiredScopes = desiredScopesForEntry(entry);
3333
- const intentScopes = intentScopesForEntry(entry);
3334
- desiredScopesByPluginId.set(entry.pluginId, desiredScopes);
3335
- intentScopesByPluginId.set(entry.pluginId, intentScopes);
3336
- if (planned.resolvedScope === 'project'
3337
- || desiredScopes.includes('project')
3338
- || intentScopes.includes('project')
3339
- || Object.hasOwn(projectConfig.snapshot.plugins, codexPluginId)) {
3340
- codexObservationScopeByMarketplace.set(marketplaceName, 'both');
3341
- }
3342
- }
3343
- for (const planned of reconciledCodexTargets) {
3344
- const entry = available.find((candidate) => candidate.pluginId === planned.pluginId);
3345
- const activationOnly = isNativeActivationOnlyTarget(executionContext, {
3346
- pluginId: entry.pluginId, platform: 'codex', scope: planned.resolvedScope,
3347
- });
3348
- const declaredSurface = analyzeCodexSurface(entry.plugin.manifest);
3349
- const surface = activationOnly ? {
3350
- ...declaredSurface,
3351
- components: declaredSurface.components.filter((component) => component.owner === 'codex-native'),
3352
- extensionKinds: [],
3353
- classification: 'native',
3354
- deliveryOwner: 'codex-native',
3355
- scopeOverlap: 'native-compatible',
3356
- } : declaredSurface;
3357
- const marketplaceName = marketplaceNameFor(entry, 'codex', planned.resolvedScope);
3358
- const codexPluginId = `${entry.plugin.manifest.name}@${marketplaceName}`;
3359
- const hasNativeRenderTargets = (entry.plugin.manifest.artifacts?.targets ?? []).some((target) => target.platform === 'codex'
3360
- && target.target === 'codex.skill');
3361
- const staticContentDigest = hasNativeRenderTargets
3362
- ? undefined
3363
- : await calculateCodexSharedNativePayloadDigest(entry.plugin.rootDir);
3364
- const desiredScopes = desiredScopesByPluginId.get(entry.pluginId);
3365
- const intentScopes = intentScopesByPluginId.get(entry.pluginId);
3366
- const observationScope = codexObservationScopeByMarketplace.get(marketplaceName)
3367
- ?? 'user';
3368
- const plannedRegistration = plannedCodexRegistrations.get(codexPluginId);
3369
- const sharedInspection = surface.nativeKinds.length > 0
3370
- ? await inspectCodexSharedNativeLive({
3371
- pluginName: entry.plugin.manifest.name,
3372
- sourceId: entry.source.sourceId,
3373
- desiredVersion: entry.plugin.manifest.version,
3374
- ...(staticContentDigest ? { expectedPayloadDigest: staticContentDigest } : {}),
3375
- cwd: options.commandOptions.cwd,
3376
- env: runtimeEnv,
3377
- marketplaceName,
3378
- marketplaceRoot: path.join(resolveAwHome(runtimeEnv), 'marketplaces', entry.source.sourceId),
3379
- nativeCliRunner: executionContext.nativeCliRunner,
3380
- observationScope,
3381
- observationSession: executionContext.codexObservationSession,
3382
- ...(codexManager ? { manager: codexManager } : {}),
3383
- ...(plannedRegistration
3384
- && (observationScope === 'user' || plannedRegistration.observations.project)
3385
- ? { pluginRegistration: plannedRegistration }
3386
- : {}),
3387
- ...(hasNativeRenderTargets ? { nativeRenderPlugin: entry.plugin } : {}),
3388
- })
3389
- : undefined;
3390
- const contentDigest = sharedInspection?.expectedPayloadDigest
3391
- ?? staticContentDigest
3392
- ?? await calculateCodexNativeRenderPayloadDigest(entry.plugin.rootDir);
3393
- catalogClosure.push({
3394
- pluginId: entry.pluginId,
3395
- pluginName: entry.plugin.manifest.name,
3396
- codexPluginId,
3397
- version: entry.plugin.manifest.version,
3398
- payloadDigest: contentDigest,
3399
- relation: planned.relation,
3400
- resolvedScope: planned.resolvedScope,
3401
- desiredScopes,
3402
- intentScopes,
3403
- executionScopes: [...new Set(codexTargets.filter((target) => target.pluginId === entry.pluginId).map((target) => target.resolvedScope))],
3404
- surface,
3405
- });
3406
- let sharedNative = sharedInspection?.sharedNative
3407
- ?? { state: 'unobserved' };
3408
- if (activationOnly && sharedNative.state !== 'usable') {
3409
- if (options.runtime?.previewOperationPlan && sharedNative.state !== 'blocked') {
3410
- // The joint request can establish its User provider before this target executes.
3411
- sharedNative = { state: 'usable' };
3412
- }
3413
- else {
3414
- throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: the shared Native package must be current and owned before scope activation.');
3415
- }
3416
- }
3417
- if (!activationOnly && options.command === 'sync' && sharedNative.state === 'usable'
3418
- && await hasPreparedStaticNativeCommandDrift({ plugin: entry.plugin,
3419
- cwd: options.commandOptions.cwd, env: runtimeEnv, context: executionContext,
3420
- marketplaceRoot: path.join(resolveAwHome(runtimeEnv), 'marketplaces', entry.source.sourceId) })) {
3421
- sharedNative = { state: 'replaceable', reason: 'renderDrift', diagnostic: 'projectionRenderDrift', version: sharedNative.version };
3422
- }
3423
- const projectionEntries = [];
3424
- const extensions = [];
3425
- for (const scope of (inspectBothScopes
3426
- ? ['user', 'project']
3427
- : [currentScope])) {
3428
- const desired = await inspection.buildTarget({
3429
- sourceId: entry.source.sourceId,
3430
- sourceIdentity: entry.source.sourceIdentity,
3431
- pluginId: entry.pluginId,
3432
- marketplaceName,
3433
- marketplaceRoot: path.join(resolveAwHome(runtimeEnv), 'marketplaces', entry.source.sourceId),
3434
- plugin: entry.plugin,
3435
- platform: 'codex',
3436
- scope,
3437
- cwd: options.commandOptions.cwd,
3438
- command: options.command,
3439
- catalog: toCatalogResolution(entry.source),
3440
- readOnlyInspectionPlan: true,
3441
- });
3442
- const inspected = await inspectOwnedComponents({
3443
- components: desired.ownedComponents,
3444
- executor: inspection.driver.ownership,
3445
- nativeProbe: inspection.driver.probeNative,
3446
- verifyHealth: true,
3447
- });
3448
- const projected = inspected.components.filter((component) => component.component.kind !== 'native-plugin'
3449
- && !component.component.identity.artifactKey.startsWith('activation-')
3450
- && !component.component.identity.artifactKey.startsWith('marketplace-'));
3451
- projectionEntries.push(...projected.map((component) => ({
3452
- scope,
3453
- artifactKey: component.component.identity.artifactKey,
3454
- state: component.state,
3455
- collision: component.collision?.reason,
3456
- })));
3457
- for (const component of surface.components.filter((candidate) => candidate.owner === 'aw')) {
3458
- const artifactKeys = new Set();
3459
- if (component.key.startsWith('extensions.instructions:')) {
3460
- artifactKeys.add('developer-instructions');
3461
- }
3462
- else if ((component.key.startsWith('extensions.permissions:')
3463
- || component.key.startsWith('extensions.agents:')) && component.name) {
3464
- artifactKeys.add(buildGeneratedName(entry.plugin.manifest.name, component.name));
3465
- }
3466
- else if (component.key.startsWith('artifacts.targets:')) {
3467
- const targetId = component.key.slice('artifacts.targets:'.length);
3468
- const target = entry.plugin.manifest.artifacts?.targets?.find((candidate) => candidate.id === targetId);
3469
- const artifactKey = target?.target === 'codex.developerInstructionsBlock'
3470
- ? 'developer-instructions'
3471
- : target?.skillKey ?? target?.roleKey;
3472
- if (artifactKey)
3473
- artifactKeys.add(artifactKey);
3474
- }
3475
- const componentInspections = projected.filter((candidate) => artifactKeys.has(candidate.component.identity.artifactKey)
3476
- || (candidate.component.kind === 'shared-config'
3477
- && candidate.component.locator.kind === 'codex-role-registration'
3478
- && artifactKeys.has(candidate.component.locator.roleKey)));
3479
- const projectionState = componentInspections.some((candidate) => candidate.collision)
3480
- ? planned.action === 'block' ? 'absent' : 'foreign'
3481
- : componentInspections.length > 0
3482
- && componentInspections.every((candidate) => candidate.state === 'present')
3483
- ? 'present'
3484
- : componentInspections.some((candidate) => candidate.state !== 'absent')
3485
- ? 'drifted'
3486
- : 'absent';
3487
- extensions.push({ componentKey: component.key, scope, state: projectionState });
3488
- }
3489
- }
3490
- liveEvidence.push({
3491
- codexPluginId,
3492
- sharedNative,
3493
- activations: {
3494
- user: userConfig.snapshot.plugins[codexPluginId]?.enabled,
3495
- project: projectConfig?.snapshot.plugins[codexPluginId]?.enabled,
3496
- },
3497
- extensions,
3498
- projectionDigest: JSON.stringify(projectionEntries.sort((left, right) => `${left.scope}\0${left.artifactKey}`.localeCompare(`${right.scope}\0${right.artifactKey}`, 'en'))),
3499
- });
3500
- }
3501
- const codexPlan = createCodexReconcilePlan({
3502
- scope: currentScope,
3503
- cwd: options.commandOptions.cwd,
3504
- operation: options.command,
3505
- catalogClosure,
3506
- liveEvidence,
3507
- activationSupport,
3508
- });
3509
- return [codexPlan];
3510
- };
3184
+ const createCodexPlans = async (_plan, _activationSupport = 'observed', _codexManager) => [];
3511
3185
  const operationNeedsNativeCli = async (platform, plan) => {
3512
3186
  for (const { entry, platform: selectedPlatform } of executionSelections) {
3513
3187
  if (selectedPlatform !== platform)
@@ -3558,6 +3232,16 @@ async function runRebuildCommandInSession(options) {
3558
3232
  }
3559
3233
  return false;
3560
3234
  };
3235
+ const commandForTarget = (selection, plan) => {
3236
+ const planned = planTargetFor(plan, selection);
3237
+ const requested = selection.requestedMethod ?? options.command;
3238
+ if (planned.relation === 'dependency' && (planned.action === 'install' || planned.action === 'reinstall')) {
3239
+ // Repairing a missing scoped contribution does not authorize forcing a
3240
+ // shared package reinstall. Ensure compares the frozen package bytes.
3241
+ return planned.action === 'reinstall' && requested !== 'reinstall' ? 'install' : planned.action;
3242
+ }
3243
+ return requested;
3244
+ };
3561
3245
  const prepareRenderedTargets = async (plan, codexPlans, runTargetHook) => {
3562
3246
  const integration = createRebuildIntegration({
3563
3247
  context: executionContext,
@@ -3567,16 +3251,22 @@ async function runRebuildCommandInSession(options) {
3567
3251
  const preparedTargets = new Map();
3568
3252
  const preparedTargetErrors = new Map();
3569
3253
  const collisionSelections = [];
3254
+ await integration.resolvePlatformTargets(executionSelections.flatMap((selection) => {
3255
+ const planned = planTargetFor(plan, selection);
3256
+ if (planned.action === 'block')
3257
+ return [];
3258
+ return [{ sourceId: selection.entry.source.sourceId, sourceIdentity: selection.entry.source.sourceIdentity,
3259
+ pluginId: selection.entry.pluginId, plugin: selection.entry.plugin, platform: selection.platform,
3260
+ scope: planned.resolvedScope, cwd: options.commandOptions.cwd, command: commandForTarget(selection, plan),
3261
+ catalog: toCatalogResolution(selection.entry.source) }];
3262
+ }));
3570
3263
  for (const selection of executionSelections) {
3571
3264
  const { entry, platform } = selection;
3572
3265
  const planned = planTargetFor(plan, selection);
3573
3266
  const key = executionKey(selection, plan);
3574
3267
  if (planned.action === 'block')
3575
3268
  continue;
3576
- const buildCommand = planned.relation === 'dependency'
3577
- && (planned.action === 'install' || planned.action === 'reinstall')
3578
- ? planned.action
3579
- : selection.requestedMethod ?? options.command;
3269
+ const buildCommand = commandForTarget(selection, plan);
3580
3270
  const plannedNative = platform === 'codex'
3581
3271
  ? codexPlans.flatMap((codexPlan) => codexPlan.sharedNativeActions).find((action) => action.pluginId === entry.pluginId)
3582
3272
  : undefined;
@@ -3669,7 +3359,11 @@ async function runRebuildCommandInSession(options) {
3669
3359
  ? path.resolve(component.path)
3670
3360
  : component.kind === 'native-plugin'
3671
3361
  ? `native:${component.pluginId}`
3672
- : `shared:${component.label}`),
3362
+ : component.locator.kind === 'cursor-workspace-hook'
3363
+ ? `shared:cursor:${path.resolve(component.locator.hooksPath)}:${component.locator.ownerKey}`
3364
+ : component.locator.kind === 'claude-permissions'
3365
+ ? `shared:claude:${path.resolve(component.locator.settingsPath)}:${component.locator.ownerKey}`
3366
+ : `shared:${component.label}`),
3673
3367
  });
3674
3368
  }
3675
3369
  catch (error) {
@@ -3681,8 +3375,16 @@ async function runRebuildCommandInSession(options) {
3681
3375
  }
3682
3376
  }
3683
3377
  const collisions = preflightDesiredArtifactCollisions(collisionSelections);
3684
- if (collisions.length > 0) {
3685
- throw namespacedPreflightError(`artifactCollision: ${collisions.map((collision) => `${collision.targetKey} (${collision.pluginIds.join(', ')})`).join('; ')}`, preflightTargets);
3378
+ for (const collision of collisions) {
3379
+ const error = new Error(`artifactCollision: ${collision.targetKey} (${collision.pluginIds.join(', ')}).`);
3380
+ for (const [key, prepared] of preparedTargets) {
3381
+ const identity = prepared.target.identity;
3382
+ if (`${identity.platform}/${identity.scope}` !== collision.targetKey
3383
+ || !collision.pluginIds.includes(identity.pluginId ?? identity.pluginName))
3384
+ continue;
3385
+ preparedTargets.delete(key);
3386
+ preparedTargetErrors.set(key, error);
3387
+ }
3686
3388
  }
3687
3389
  const configTargets = new Map();
3688
3390
  if (options.command !== 'cleanup' && options.command !== 'uninstall') {
@@ -3724,8 +3426,12 @@ async function runRebuildCommandInSession(options) {
3724
3426
  effectiveValues: effective.values,
3725
3427
  });
3726
3428
  }));
3429
+ await integration.sealMarketplaceGenerations([...preparedTargets.values()].map(({ target }) => target));
3727
3430
  return {
3728
3431
  integration,
3432
+ deploymentPlans: [...preparedTargets.values()].flatMap(({ target }) => target.platformDeployment?.plans ?? []),
3433
+ deploymentExclusions: [...[...preparedTargets.values()].flatMap(({ target }) => target.deploymentExclusions ?? []),
3434
+ ...[...preparedTargetErrors.values()].flatMap(deploymentExclusionsFromError)],
3729
3435
  preparedTargets,
3730
3436
  preparedTargetErrors,
3731
3437
  targetActions: [...preparedTargets.values()].flatMap((prepared) => prepared.target.operationActions ?? []),
@@ -3770,11 +3476,35 @@ async function runRebuildCommandInSession(options) {
3770
3476
  const previewPreparation = await prepareRenderedTargets(initialPlan, initialCodexPlans, false);
3771
3477
  const preview = mergeRebuildCommandResults([]);
3772
3478
  preview.dependencyPlan = initialPlan;
3479
+ const blockedTargets = [...previewPreparation.preparedTargets.values()].flatMap(({ target }) => {
3480
+ const receipts = target.platformDeployment?.blockedReceipts ?? [];
3481
+ if (!receipts.length)
3482
+ return [];
3483
+ const diagnostics = receipts.flatMap((receipt) => receipt.diagnostics);
3484
+ const message = diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join('; ')
3485
+ || 'nativePreparationBlocked: The native deployment could not be prepared.';
3486
+ const result = failedResult(options.command, target.identity, message);
3487
+ result.deploymentReceipts = [...receipts];
3488
+ return [{ result, code: diagnostics[0]?.code ?? 'nativePreparationBlocked' }];
3489
+ });
3490
+ if (blockedTargets.length) {
3491
+ preview.rebuildResults = blockedTargets.map(({ result }) => result);
3492
+ preview.targetResults = blockedTargets.map(({ result, code }) => ({ ...toTargetResult(result), errorCode: code }));
3493
+ preview.overallState = 'failed';
3494
+ preview.platforms = [...new Set(blockedTargets.map(({ result }) => result.target.platform))];
3495
+ preview.receiptTargets = blockedTargets.map(({ result }) => ({
3496
+ pluginName: result.target.pluginName, pluginId: result.target.pluginId, sourceId: result.target.sourceId,
3497
+ platform: result.target.platform, scope: result.target.scope,
3498
+ }));
3499
+ }
3773
3500
  preview.nativeFootprints = preparedNativeFootprints([...previewPreparation.preparedTargets.values()].map((entry) => entry.target));
3774
3501
  preview.operationPlan = await withNativeToolRemovalImpact(createRebuildOperationPlan({
3775
3502
  dependencyPlan: initialPlan,
3776
3503
  codexPlans: initialCodexPlans,
3777
3504
  targetActions: previewPreparation.targetActions,
3505
+ deploymentPlans: previewPreparation.deploymentPlans,
3506
+ deploymentExclusions: previewPreparation.deploymentExclusions,
3507
+ nativeToolChanges: [...previewPreparation.preparedTargets.values()].flatMap((entry) => entry.target.nativeToolChanges ?? []),
3778
3508
  catalogSources: catalog.sources.flatMap((source) => source.resolution ? [source.resolution] : []),
3779
3509
  requirements,
3780
3510
  scope: options.commandOptions.scope,
@@ -3784,7 +3514,7 @@ async function runRebuildCommandInSession(options) {
3784
3514
  preview.codexReconcilePlans = initialCodexPlans;
3785
3515
  if (initialCodexPlans.some((plan) => plan.sharedNativeActions.some((action) => action.action === 'install' || action.action === 'replace' || action.action === 'repair')
3786
3516
  || plan.postcheck.plugins.length > 0)) {
3787
- preview.codexManagerPreview = planningManagerPreview ?? await (options.runtime.codexManagerPreviewer ?? previewCodexManager)({
3517
+ preview.codexManagerPreview = await (options.runtime.codexManagerPreviewer ?? previewCodexManager)({
3788
3518
  cwd: options.commandOptions.cwd,
3789
3519
  env: runtimeEnv,
3790
3520
  runner: options.runtime?.nativeCliRunner,
@@ -3844,6 +3574,9 @@ async function runRebuildCommandInSession(options) {
3844
3574
  dependencyPlan: lockedPlan,
3845
3575
  codexPlans: lockedCodexPlans,
3846
3576
  targetActions: lockedPreparation.targetActions,
3577
+ deploymentPlans: lockedPreparation.deploymentPlans,
3578
+ deploymentExclusions: lockedPreparation.deploymentExclusions,
3579
+ nativeToolChanges: [...lockedPreparation.preparedTargets.values()].flatMap((entry) => entry.target.nativeToolChanges ?? []),
3847
3580
  catalogSources: catalog.sources.flatMap((source) => source.resolution ? [source.resolution] : []),
3848
3581
  requirements,
3849
3582
  scope: options.commandOptions.scope,
@@ -3861,9 +3594,10 @@ async function runRebuildCommandInSession(options) {
3861
3594
  if (options.runtime?.directCli
3862
3595
  && options.commandOptions.yes !== true
3863
3596
  && lifecycleCommand) {
3864
- const sharedNativeImpact = lockedCodexPlans.some((plan) => plan.review.requiresConfirmation);
3597
+ const sharedNativeImpact = lockedCodexPlans.some((plan) => plan.review.requiresConfirmation)
3598
+ || (lockedOperationPlan.deploymentPlans ?? []).some((plan) => deploymentConfirmationEffects(plan).some((effect) => effect.impact === 'shared'));
3865
3599
  if (sharedNativeImpact) {
3866
- throw namespacedPreflightError('sharedNativeImpactAuthorizationRequired: Replacing or force-reinstalling shared Codex native state requires --yes.', preflightTargets);
3600
+ throw namespacedPreflightError('sharedNativeImpactAuthorizationRequired: Replacing or force-reinstalling shared native state requires --yes.', preflightTargets);
3867
3601
  }
3868
3602
  }
3869
3603
  const operationPreparations = new Map();
@@ -3876,11 +3610,7 @@ async function runRebuildCommandInSession(options) {
3876
3610
  scope: planned.resolvedScope,
3877
3611
  }))
3878
3612
  return 'install';
3879
- if (planned.relation === 'dependency'
3880
- && (planned.action === 'install' || planned.action === 'reinstall')) {
3881
- return planned.action;
3882
- }
3883
- return selection.requestedMethod ?? options.command;
3613
+ return commandForTarget(selection, lockedPlan);
3884
3614
  };
3885
3615
  const prepareLockedTargets = async (preparationOptions) => {
3886
3616
  const preparations = new Map();
@@ -3933,7 +3663,7 @@ async function runRebuildCommandInSession(options) {
3933
3663
  platform,
3934
3664
  scope: planned.resolvedScope,
3935
3665
  cwd: options.commandOptions.cwd,
3936
- }, message));
3666
+ }, message, 'preflight', deploymentExclusionsFromError(preparationError)));
3937
3667
  states.set(key, 'failed');
3938
3668
  continue;
3939
3669
  }
@@ -4008,8 +3738,6 @@ async function runRebuildCommandInSession(options) {
4008
3738
  if (executionContext.codexManager === undefined
4009
3739
  && nativePreparationKeys.size > 0) {
4010
3740
  try {
4011
- if (planningManagerError)
4012
- throw planningManagerError;
4013
3741
  if (options.runtime?.codexManagerResolver) {
4014
3742
  executionContext.codexManager = await options.runtime.codexManagerResolver({
4015
3743
  cwd: options.commandOptions.cwd,
@@ -4041,8 +3769,6 @@ async function runRebuildCommandInSession(options) {
4041
3769
  else if (executionContext.codexManager === undefined
4042
3770
  && activationPreparationKeys.size > 0) {
4043
3771
  try {
4044
- if (planningManagerError)
4045
- throw planningManagerError;
4046
3772
  const consumer = await (options.runtime?.codexOperationConsumerResolver ?? resolveCodexOperationConsumer)({
4047
3773
  cwd: options.commandOptions.cwd,
4048
3774
  env: runtimeEnv,
@@ -4097,6 +3823,9 @@ async function runRebuildCommandInSession(options) {
4097
3823
  dependencyPlan: lockedPlan,
4098
3824
  codexPlans: lockedCodexPlans,
4099
3825
  targetActions: lockedPreparation.targetActions,
3826
+ deploymentPlans: lockedPreparation.deploymentPlans,
3827
+ deploymentExclusions: lockedPreparation.deploymentExclusions,
3828
+ nativeToolChanges: [...lockedPreparation.preparedTargets.values()].flatMap((entry) => entry.target.nativeToolChanges ?? []),
4100
3829
  catalogSources: catalog.sources.flatMap((source) => source.resolution ? [source.resolution] : []),
4101
3830
  requirements,
4102
3831
  scope: options.commandOptions.scope,
@@ -4109,8 +3838,9 @@ async function runRebuildCommandInSession(options) {
4109
3838
  if (options.runtime?.directCli
4110
3839
  && options.commandOptions.yes !== true
4111
3840
  && lifecycleCommand
4112
- && lockedCodexPlans.some((plan) => plan.review.requiresConfirmation)) {
4113
- throw namespacedPreflightError('sharedNativeImpactAuthorizationRequired: Replacing or force-reinstalling shared Codex native state requires --yes.', preflightTargets);
3841
+ && (lockedCodexPlans.some((plan) => plan.review.requiresConfirmation)
3842
+ || (lockedOperationPlan.deploymentPlans ?? []).some((plan) => deploymentConfirmationEffects(plan).some((effect) => effect.impact === 'shared')))) {
3843
+ throw namespacedPreflightError('sharedNativeImpactAuthorizationRequired: Replacing or force-reinstalling shared native state requires --yes.', preflightTargets);
4114
3844
  }
4115
3845
  if (options.command !== 'cleanup'
4116
3846
  && options.command !== 'uninstall'
@@ -4179,18 +3909,54 @@ async function runRebuildCommandInSession(options) {
4179
3909
  }
4180
3910
  }
4181
3911
  }
3912
+ const failClaudeTargets = (error, pluginName) => {
3913
+ const message = error instanceof Error ? error.message : String(error);
3914
+ for (const selection of executionSelections) {
3915
+ if (selection.platform !== 'claude'
3916
+ || (pluginName !== undefined && selection.entry.plugin.manifest.name !== pluginName))
3917
+ continue;
3918
+ const planned = planTargetFor(lockedPlan, selection);
3919
+ if (planned.action === 'keep' || planned.action === 'block')
3920
+ continue;
3921
+ const key = executionKey(selection, lockedPlan);
3922
+ operationPreparations.delete(key);
3923
+ operationPreparationFailures.set(key, failedResult(options.command, {
3924
+ sourceId: selection.entry.source.sourceId,
3925
+ sourceIdentity: selection.entry.source.sourceIdentity,
3926
+ pluginId: selection.entry.pluginId,
3927
+ pluginName: selection.entry.plugin.manifest.name,
3928
+ pluginVersion: selection.entry.plugin.manifest.version,
3929
+ platform: 'claude',
3930
+ scope: planned.resolvedScope,
3931
+ cwd: options.commandOptions.cwd,
3932
+ }, message));
3933
+ }
3934
+ };
4182
3935
  for (const pluginName of new Set(lockedPlan.targets.flatMap((target) => target.platform === 'claude'
4183
- && (target.action === 'install'
4184
- || target.action === 'reinstall')
4185
- ? [target.pluginName]
4186
- : []))) {
4187
- await assertNoClaudeUnboundNativeNameCollision({
4188
- pluginName,
4189
- cwd: options.commandOptions.cwd,
4190
- env: runtimeEnv,
4191
- });
3936
+ && (target.action === 'install' || target.action === 'reinstall')
3937
+ ? [target.pluginName] : []))) {
3938
+ try {
3939
+ await assertNoClaudeUnboundNativeNameCollision({
3940
+ pluginName, cwd: options.commandOptions.cwd, env: runtimeEnv,
3941
+ });
3942
+ }
3943
+ catch (error) {
3944
+ executionContext.signal?.throwIfAborted();
3945
+ failClaudeTargets(error, pluginName);
3946
+ }
3947
+ }
3948
+ try {
3949
+ if (await operationNeedsNativeCli('claude', lockedPlan)) {
3950
+ await assertClaudeVersion({
3951
+ platforms: ['claude'], cwd: options.commandOptions.cwd,
3952
+ env: runtimeEnv, runtime: executionContext,
3953
+ });
3954
+ }
3955
+ }
3956
+ catch (error) {
3957
+ executionContext.signal?.throwIfAborted();
3958
+ failClaudeTargets(error);
4192
3959
  }
4193
- const claudeCliRequired = await operationNeedsNativeCli('claude', lockedPlan);
4194
3960
  const codexUserActivationDesired = new Set(lockedCodexPlans.flatMap((plan) => plan.activationActions.user.flatMap((action) => action.desired ? [action.codexPluginId] : [])));
4195
3961
  executionContext.codexUserActivationDesired = codexUserActivationDesired;
4196
3962
  const originalUserActivations = options.commandOptions.scope === 'project'
@@ -4198,17 +3964,11 @@ async function runRebuildCommandInSession(options) {
4198
3964
  ? new Map(Object.entries((await readCodexConfigFile(resolveCodexPaths(options.commandOptions.cwd, 'user', runtimeEnv).configTomlPath)).snapshot.plugins)
4199
3965
  .map(([pluginId, activation]) => [pluginId, activation.enabled === true]))
4200
3966
  : undefined;
4201
- await assertClaudeVersion({
4202
- platforms: claudeCliRequired ? ['claude'] : [],
4203
- cwd: options.commandOptions.cwd,
4204
- env: runtimeEnv,
4205
- runtime: executionContext,
4206
- });
4207
3967
  const preparedTargets = lockedPreparation.preparedTargets;
4208
3968
  const preparedTargetErrors = lockedPreparation.preparedTargetErrors;
4209
3969
  const removalRequiredConsumers = new Map();
4210
3970
  if ((options.command === 'cleanup' && !cleanupForce)
4211
- || options.command === 'uninstall'
3971
+ || (options.command === 'uninstall' && !uninstallForce)
4212
3972
  || options.command === 'sync') {
4213
3973
  const removalStateInventory = await readInventory({
4214
3974
  cwd: options.commandOptions.cwd,
@@ -4245,6 +4005,18 @@ async function runRebuildCommandInSession(options) {
4245
4005
  nativeProbe: inspection.driver.probeNative,
4246
4006
  verifyHealth: true,
4247
4007
  });
4008
+ const deployments = consumerTarget.platformObservations ?? [];
4009
+ if (deployments.length) {
4010
+ const declaredHere = options_.scope === options.commandOptions.scope && requirements.roots.some((root) => root.pluginId === options_.entry.pluginId && root.platforms.includes(options_.platform));
4011
+ const packageKeys = new Set(deployments.map(({ binding }) => binding.physicalKey));
4012
+ const scopedContribution = consumerInspection.components.some(({ component, state }) => state !== 'absent'
4013
+ && component.identity.scope === options_.scope && !packageKeys.has(component.identity.physicalKey ?? ''));
4014
+ const nativeConsumer = deployments.some(({ binding, observation }) => observation.registration !== 'absent'
4015
+ && (binding.platform === 'codex' && binding.scope.kind === 'project' && observation.configuration
4016
+ ? observation.configuration.activation !== 'absent' && observation.configuration.activation !== 'disabled'
4017
+ : observation.consumers.some((consumer) => consumer.activation !== 'disabled' && consumer.activation !== 'not-applicable')));
4018
+ return declaredHere || scopedContribution || nativeConsumer ? 'live' : 'absent';
4019
+ }
4248
4020
  return consumerInspection.state === 'absent' ? 'absent' : 'live';
4249
4021
  };
4250
4022
  const currentConsumerCandidates = [...new Map(removalStateInventory.references.flatMap((reference) => {
@@ -4254,6 +4026,11 @@ async function runRebuildCommandInSession(options) {
4254
4026
  || (reference.platform !== 'codex' && reference.platform !== 'claude')
4255
4027
  || (reference.scope !== 'user' && reference.scope !== 'project'))
4256
4028
  return [];
4029
+ // User writes use a neutral context. Other project registry records
4030
+ // retain shared payloads but do not authorize inspecting their files.
4031
+ if (reference.scope === 'project' && (executionInput.context.scope !== 'project'
4032
+ || reference.projectKey !== executionInput.context.projectRoot))
4033
+ return [];
4257
4034
  const entry = available.find((candidate) => candidate.source.sourceId === reference.sourceId
4258
4035
  && (reference.sourceIdentity === undefined
4259
4036
  || candidate.source.sourceIdentity === reference.sourceIdentity)
@@ -4527,34 +4304,7 @@ async function runRebuildCommandInSession(options) {
4527
4304
  }
4528
4305
  const actions = operationPreparations.get(key)?.actions
4529
4306
  ?? [];
4530
- const preparedTarget = preparedTargets.get(key)?.target;
4531
4307
  let result;
4532
- if (preparedTarget && executionContext.preserveLegacyNativeSkills !== true) {
4533
- const nativeSkillKeys = new Set((entry.plugin.manifest.artifacts?.targets ?? [])
4534
- .filter((target) => target.platform === 'codex'
4535
- && target.target === 'codex.skill')
4536
- .map((target) => target.skillKey));
4537
- const marketplaceRoot = preparedTarget.identity.marketplaceRoot;
4538
- const legacyNativeSkills = preparedTarget.ownedComponents.filter((component) => component.kind === 'skill-directory'
4539
- && nativeSkillKeys.has(component.identity.artifactKey)
4540
- && (!marketplaceRoot || path.relative(marketplaceRoot, component.path).startsWith('..')));
4541
- if (legacyNativeSkills.length > 0) {
4542
- result = await executeRebuildComponentCleanup({
4543
- command: requestedMethod,
4544
- target: preparedTarget,
4545
- driver: lockedPreparation.integration.driver,
4546
- components: legacyNativeSkills,
4547
- actions,
4548
- onActionEvent: (event) => emitRebuildActionEvent(executionContext, event),
4549
- ...(rebuildCommandTestHooks?.beforeActivationLegacyCleanupMutation ? {
4550
- beforeMutation: rebuildCommandTestHooks.beforeActivationLegacyCleanupMutation,
4551
- } : {}),
4552
- ...(rebuildCommandTestHooks?.afterActivationLegacyCleanupQuarantine ? {
4553
- afterQuarantine: rebuildCommandTestHooks.afterActivationLegacyCleanupQuarantine,
4554
- } : {}),
4555
- });
4556
- }
4557
- }
4558
4308
  result ??= {
4559
4309
  status: 'succeeded', command: requestedMethod, target: identity,
4560
4310
  actions,
@@ -4641,9 +4391,7 @@ async function runRebuildCommandInSession(options) {
4641
4391
  const executionResult = await runSingleSourceRebuildCommand({
4642
4392
  ...options,
4643
4393
  command: isNativeActivationOnlyTarget(executionContext, identity) ? 'install'
4644
- : planned.relation === 'dependency' && planned.action !== 'keep'
4645
- ? planned.action
4646
- : requestedMethod,
4394
+ : commandForTarget(selection, lockedPlan),
4647
4395
  pluginNames: [entry.plugin.manifest.name],
4648
4396
  all: false,
4649
4397
  commandOptions: { ...options.commandOptions, platform, scope: planned.resolvedScope },
@@ -4941,7 +4689,7 @@ async function runRebuildCommandInSession(options) {
4941
4689
  catch (error) {
4942
4690
  if (options.all && (liveTargets.length > 0 || legacyLiveTargets.length > 0)) {
4943
4691
  const projected = error;
4944
- error = namespacedPreflightError(error instanceof Error ? error.message : String(error), projected.namespacedTargets ?? liveTargets, projected.legacyTargets ?? legacyLiveTargets);
4692
+ error = Object.assign(namespacedPreflightError(error instanceof Error ? error.message : String(error), projected.namespacedTargets ?? liveTargets, projected.legacyTargets ?? legacyLiveTargets), { deploymentExclusions: deploymentExclusionsFromError(error) });
4945
4693
  }
4946
4694
  if (options.command !== 'uninstall')
4947
4695
  throw error;
@@ -4965,8 +4713,16 @@ export async function runRebuildCommand(options) {
4965
4713
  throw new Error('nativeExecutionInputRequired: Native execution requires an explicit scope context and complete demand.');
4966
4714
  }
4967
4715
  const commandResults = options.runtime?.commandResults ?? [];
4968
- options = { ...options, runtime: { ...options.runtime, commandResults, managedCommandProducerCache: options.runtime?.managedCommandProducerCache ?? new Map() } };
4716
+ const ownsPreparation = options.runtime?.preparedArtifactRenderResults === undefined
4717
+ && options.runtime?.platformRebuildSession === undefined;
4718
+ const renderResults = options.runtime?.preparedArtifactRenderResults ?? new Map();
4719
+ options = { ...options, runtime: { ...options.runtime, commandResults, preparedArtifactRenderResults: renderResults,
4720
+ managedCommandProducerCache: options.runtime?.managedCommandProducerCache ?? new Map() } };
4969
4721
  const withCommands = (result) => {
4722
+ const exclusions = result.operationPlan?.deploymentExclusions ?? result.deploymentExclusions
4723
+ ?? result.rebuildResults.flatMap((entry) => entry.deploymentExclusions ?? []);
4724
+ if (exclusions.length)
4725
+ result = { ...result, deploymentExclusions: exclusions };
4970
4726
  const byProducer = new Map();
4971
4727
  const retained = (result.operationPlan?.actions ?? []).flatMap((action) => action.kind === 'retainManagedCommandPackage' ? [retainedManagedCommandPackageResult(action)] : []);
4972
4728
  for (const entry of [...(result.commandResults ?? []), ...commandResults, ...retained]) {
@@ -4985,24 +4741,30 @@ export async function runRebuildCommand(options) {
4985
4741
  commandOptions: { ...options.commandOptions, cwd: executionInput.context.executionCwd },
4986
4742
  runtime: { ...options.runtime, env: executionInput.context.env },
4987
4743
  };
4988
- if (scopedOptions.runtime?.codexObservationSession) {
4989
- return withCommands(await runRebuildCommandInSession(scopedOptions));
4990
- }
4991
- const env = executionInput.context.env;
4992
- const session = await createCodexNativeObservationSession({
4993
- exactCwd: executionInput.context.executionCwd,
4994
- env,
4995
- runner: scopedOptions.runtime?.nativeCliRunner ?? getDefaultNativeCliRunner(),
4996
- manager: scopedOptions.runtime?.codexManager,
4997
- });
4998
4744
  try {
4999
- return withCommands(await runRebuildCommandInSession({
5000
- ...scopedOptions,
5001
- runtime: { ...scopedOptions.runtime, codexObservationSession: session },
5002
- }));
4745
+ if (scopedOptions.runtime?.codexObservationSession) {
4746
+ return withCommands(await runRebuildCommandInSession(scopedOptions));
4747
+ }
4748
+ const env = executionInput.context.env;
4749
+ const session = await createCodexNativeObservationSession({
4750
+ exactCwd: executionInput.context.executionCwd,
4751
+ env,
4752
+ runner: scopedOptions.runtime?.nativeCliRunner ?? getDefaultNativeCliRunner(),
4753
+ manager: scopedOptions.runtime?.codexManager,
4754
+ });
4755
+ try {
4756
+ return withCommands(await runRebuildCommandInSession({
4757
+ ...scopedOptions,
4758
+ runtime: { ...scopedOptions.runtime, codexObservationSession: session },
4759
+ }));
4760
+ }
4761
+ finally {
4762
+ await session.dispose();
4763
+ }
5003
4764
  }
5004
4765
  finally {
5005
- await session.dispose();
4766
+ if (ownsPreparation && !options.runtime?.previewOperationPlan)
4767
+ await disposePreparedPlatformRebuildSession(renderResults);
5006
4768
  }
5007
4769
  }
5008
4770
  export async function runRebuildTaskCommand(targets, options, runtime = {}) {