@lesliechan721/aw 0.1.0-beta.9 → 0.1.0-beta.91

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