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

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 (820) hide show
  1. package/dist/authoring/assets/aw-config.d.mts +1 -50
  2. package/dist/authoring/assets/aw-config.mjs +58 -928
  3. package/dist/authoring/assets/aw-config.mjs.map +1 -1
  4. package/dist/authoring/assets/aw-runtime-config.d.mts +13 -0
  5. package/dist/authoring/assets/aw-runtime-config.mjs +221 -0
  6. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -0
  7. package/dist/authoring/assets/command-runtime-config.d.mts +9 -0
  8. package/dist/authoring/assets/command-runtime-config.mjs +134 -0
  9. package/dist/authoring/assets/command-runtime-config.mjs.map +1 -0
  10. package/dist/authoring/scripts/add-skill.mjs +16 -39
  11. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  12. package/dist/authoring/scripts/init-plugin.mjs +43 -71
  13. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  14. package/dist/authoring/scripts/lib/plugin-root.mjs +4 -4
  15. package/dist/authoring/scripts/lib/plugin-root.mjs.map +1 -1
  16. package/dist/authoring/scripts/lib/plugin-version-check.d.mts +1 -0
  17. package/dist/authoring/scripts/lib/plugin-version-check.mjs +230 -9
  18. package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
  19. package/dist/authoring/scripts/lib/skill-scaffold.d.mts +3 -3
  20. package/dist/authoring/scripts/lib/skill-scaffold.mjs +5 -8
  21. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  22. package/dist/authoring/scripts/remove-plugin.mjs +1 -1
  23. package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
  24. package/dist/authoring/scripts/validate-plugin.mjs +408 -1748
  25. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  26. package/dist/authoring/scripts/validate-skill.mjs +1 -1
  27. package/dist/index.js +2 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/native-runtime/reader-runtime.mjs +34 -0
  30. package/dist/native-runtime/reader.d.mts +6 -0
  31. package/dist/native-runtime/reader.mjs +11 -0
  32. package/dist/scripts/aw-skill-eval-materializer.d.ts +11 -1
  33. package/dist/scripts/aw-skill-eval-materializer.js +119 -114
  34. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
  35. package/dist/scripts/bundle-plugins.js +32 -7
  36. package/dist/scripts/bundle-plugins.js.map +1 -1
  37. package/dist/scripts/plugin-staging.d.ts +1 -1
  38. package/dist/scripts/plugin-staging.js +5 -2
  39. package/dist/scripts/plugin-staging.js.map +1 -1
  40. package/dist/scripts/plugin-test-context-guard.d.mts +1 -0
  41. package/dist/scripts/plugin-test-context-guard.mjs +59 -0
  42. package/dist/scripts/plugin-test-context-guard.mjs.map +1 -0
  43. package/dist/scripts/plugin-test-reporter.d.mts +2 -0
  44. package/dist/scripts/plugin-test-reporter.mjs +21 -0
  45. package/dist/scripts/plugin-test-reporter.mjs.map +1 -0
  46. package/dist/scripts/test-plugin-scripts.d.ts +5 -0
  47. package/dist/scripts/test-plugin-scripts.js +343 -58
  48. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  49. package/dist/scripts/test-workers.d.mts +24 -0
  50. package/dist/scripts/test-workers.mjs +59 -0
  51. package/dist/scripts/test-workers.mjs.map +1 -0
  52. package/dist/src/adapters/helpers.d.ts +7 -0
  53. package/dist/src/adapters/helpers.js.map +1 -1
  54. package/dist/src/authoring/workspace-commands.d.ts +3 -0
  55. package/dist/src/authoring/workspace-commands.js +7 -2
  56. package/dist/src/authoring/workspace-commands.js.map +1 -1
  57. package/dist/src/commands/aw-capabilities.d.ts +1 -1
  58. package/dist/src/commands/aw-capabilities.js +48 -19
  59. package/dist/src/commands/aw-capabilities.js.map +1 -1
  60. package/dist/src/commands/catalog-dev-source.d.ts +40 -3
  61. package/dist/src/commands/catalog-dev-source.js +333 -42
  62. package/dist/src/commands/catalog-dev-source.js.map +1 -1
  63. package/dist/src/commands/catalog-generation.d.ts +5 -0
  64. package/dist/src/commands/catalog-generation.js.map +1 -1
  65. package/dist/src/commands/catalog-publication-inspection.d.ts +11 -3
  66. package/dist/src/commands/catalog-publication-inspection.js +211 -59
  67. package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
  68. package/dist/src/commands/catalog-publication-journal.d.ts +12 -0
  69. package/dist/src/commands/catalog-publication-journal.js +78 -1
  70. package/dist/src/commands/catalog-publication-journal.js.map +1 -1
  71. package/dist/src/commands/catalog-publish.d.ts +21 -1
  72. package/dist/src/commands/catalog-publish.js +133 -92
  73. package/dist/src/commands/catalog-publish.js.map +1 -1
  74. package/dist/src/commands/catalog-source.d.ts +25 -5
  75. package/dist/src/commands/catalog-source.js +153 -27
  76. package/dist/src/commands/catalog-source.js.map +1 -1
  77. package/dist/src/commands/catalog-status.js +2 -2
  78. package/dist/src/commands/catalog-status.js.map +1 -1
  79. package/dist/src/commands/catalog-store.d.ts +31 -7
  80. package/dist/src/commands/catalog-store.js +379 -42
  81. package/dist/src/commands/catalog-store.js.map +1 -1
  82. package/dist/src/commands/catalog-workspace-resolution.d.ts +4 -0
  83. package/dist/src/commands/catalog-workspace-resolution.js +18 -3
  84. package/dist/src/commands/catalog-workspace-resolution.js.map +1 -1
  85. package/dist/src/commands/console.js +33 -20
  86. package/dist/src/commands/console.js.map +1 -1
  87. package/dist/src/commands/dependency-operation-plan.d.ts +7 -0
  88. package/dist/src/commands/dependency-operation-plan.js +66 -30
  89. package/dist/src/commands/dependency-operation-plan.js.map +1 -1
  90. package/dist/src/commands/deployment-confirmation.d.ts +11 -0
  91. package/dist/src/commands/deployment-confirmation.js +101 -0
  92. package/dist/src/commands/deployment-confirmation.js.map +1 -0
  93. package/dist/src/commands/init.js +1 -1
  94. package/dist/src/commands/init.js.map +1 -1
  95. package/dist/src/commands/intent-command.d.ts +34 -0
  96. package/dist/src/commands/intent-command.js +174 -0
  97. package/dist/src/commands/intent-command.js.map +1 -0
  98. package/dist/src/commands/lifecycle-command-package.d.ts +45 -0
  99. package/dist/src/commands/lifecycle-command-package.js +199 -0
  100. package/dist/src/commands/lifecycle-command-package.js.map +1 -0
  101. package/dist/src/commands/managed-commands.d.ts +41 -0
  102. package/dist/src/commands/managed-commands.js +404 -0
  103. package/dist/src/commands/managed-commands.js.map +1 -0
  104. package/dist/src/commands/offline-cleanup-evidence.d.ts +12 -2
  105. package/dist/src/commands/offline-cleanup-evidence.js +57 -35
  106. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
  107. package/dist/src/commands/operation-plan.d.ts +72 -2
  108. package/dist/src/commands/operation-plan.js +54 -3
  109. package/dist/src/commands/operation-plan.js.map +1 -1
  110. package/dist/src/commands/operation-planner.d.ts +6 -5
  111. package/dist/src/commands/operation-planner.js +23 -20
  112. package/dist/src/commands/operation-planner.js.map +1 -1
  113. package/dist/src/commands/options.d.ts +11 -16
  114. package/dist/src/commands/options.js +31 -25
  115. package/dist/src/commands/options.js.map +1 -1
  116. package/dist/src/commands/permission-batch.d.ts +5 -0
  117. package/dist/src/commands/permission-batch.js +83 -0
  118. package/dist/src/commands/permission-batch.js.map +1 -0
  119. package/dist/src/commands/plugin-capabilities.js +128 -58
  120. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  121. package/dist/src/commands/public-config-confirmation.d.ts +14 -0
  122. package/dist/src/commands/public-config-confirmation.js +73 -0
  123. package/dist/src/commands/public-config-confirmation.js.map +1 -0
  124. package/dist/src/commands/public-interruption.d.ts +9 -0
  125. package/dist/src/commands/public-interruption.js +23 -0
  126. package/dist/src/commands/public-interruption.js.map +1 -0
  127. package/dist/src/commands/public-lifecycle-result.d.ts +106 -0
  128. package/dist/src/commands/public-lifecycle-result.js +536 -0
  129. package/dist/src/commands/public-lifecycle-result.js.map +1 -0
  130. package/dist/src/commands/public-lifecycle.d.ts +27 -0
  131. package/dist/src/commands/public-lifecycle.js +569 -0
  132. package/dist/src/commands/public-lifecycle.js.map +1 -0
  133. package/dist/src/commands/public-plugin-query.d.ts +16 -0
  134. package/dist/src/commands/public-plugin-query.js +231 -0
  135. package/dist/src/commands/public-plugin-query.js.map +1 -0
  136. package/dist/src/commands/rebuild-command.d.ts +177 -16
  137. package/dist/src/commands/rebuild-command.js +3370 -1559
  138. package/dist/src/commands/rebuild-command.js.map +1 -1
  139. package/dist/src/commands/rebuild-integration.d.ts +100 -55
  140. package/dist/src/commands/rebuild-integration.js +866 -3275
  141. package/dist/src/commands/rebuild-integration.js.map +1 -1
  142. package/dist/src/commands/rebuild-operations.d.ts +68 -13
  143. package/dist/src/commands/rebuild-operations.js +309 -120
  144. package/dist/src/commands/rebuild-operations.js.map +1 -1
  145. package/dist/src/commands/rebuild-platform-integration.d.ts +99 -0
  146. package/dist/src/commands/rebuild-platform-integration.js +2329 -0
  147. package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
  148. package/dist/src/commands/reconcile-operation-plan.d.ts +14 -9
  149. package/dist/src/commands/reconcile-operation-plan.js +26 -6
  150. package/dist/src/commands/reconcile-operation-plan.js.map +1 -1
  151. package/dist/src/commands/review-inspection.d.ts +60 -0
  152. package/dist/src/commands/review-inspection.js +437 -0
  153. package/dist/src/commands/review-inspection.js.map +1 -0
  154. package/dist/src/commands/review-preparation.d.ts +51 -0
  155. package/dist/src/commands/review-preparation.js +400 -0
  156. package/dist/src/commands/review-preparation.js.map +1 -0
  157. package/dist/src/commands/runtime.d.ts +5 -1
  158. package/dist/src/commands/runtime.js +41 -8
  159. package/dist/src/commands/runtime.js.map +1 -1
  160. package/dist/src/commands/skill-eval.d.ts +8 -0
  161. package/dist/src/commands/skill-eval.js +126 -73
  162. package/dist/src/commands/skill-eval.js.map +1 -1
  163. package/dist/src/commands/status-v6.d.ts +148 -35
  164. package/dist/src/commands/status-v6.js +1166 -307
  165. package/dist/src/commands/status-v6.js.map +1 -1
  166. package/dist/src/commands/targets-command.d.ts +38 -0
  167. package/dist/src/commands/targets-command.js +182 -0
  168. package/dist/src/commands/targets-command.js.map +1 -0
  169. package/dist/src/commands/wizard.d.ts +7 -3
  170. package/dist/src/commands/wizard.js +7 -4
  171. package/dist/src/commands/wizard.js.map +1 -1
  172. package/dist/src/commands/write-commands.d.ts +7 -1
  173. package/dist/src/commands/write-commands.js +129 -38
  174. package/dist/src/commands/write-commands.js.map +1 -1
  175. package/dist/src/constants.d.ts +2 -3
  176. package/dist/src/constants.js +2 -3
  177. package/dist/src/constants.js.map +1 -1
  178. package/dist/src/eval/manifest-v1.d.ts +6 -3
  179. package/dist/src/eval/manifest-v1.js +44 -33
  180. package/dist/src/eval/manifest-v1.js.map +1 -1
  181. package/dist/src/generators/local-plugin.d.ts +4 -2
  182. package/dist/src/generators/local-plugin.js +319 -353
  183. package/dist/src/generators/local-plugin.js.map +1 -1
  184. package/dist/src/generators/permissions.d.ts +20 -2
  185. package/dist/src/generators/permissions.js +82 -15
  186. package/dist/src/generators/permissions.js.map +1 -1
  187. package/dist/src/index.d.ts +2 -33
  188. package/dist/src/index.js +1575 -1919
  189. package/dist/src/index.js.map +1 -1
  190. package/dist/src/intent/deployment-preferences.d.ts +63 -0
  191. package/dist/src/intent/deployment-preferences.js +170 -0
  192. package/dist/src/intent/deployment-preferences.js.map +1 -0
  193. package/dist/src/intent/diagnostics.d.ts +11 -0
  194. package/dist/src/intent/diagnostics.js +14 -0
  195. package/dist/src/intent/diagnostics.js.map +1 -0
  196. package/dist/src/intent/intent-codec.d.ts +19 -0
  197. package/dist/src/intent/intent-codec.js +117 -0
  198. package/dist/src/intent/intent-codec.js.map +1 -0
  199. package/dist/src/intent/intent-store.d.ts +43 -0
  200. package/dist/src/intent/intent-store.js +118 -0
  201. package/dist/src/intent/intent-store.js.map +1 -0
  202. package/dist/src/intent/scope-context.d.ts +35 -0
  203. package/dist/src/intent/scope-context.js +179 -0
  204. package/dist/src/intent/scope-context.js.map +1 -0
  205. package/dist/src/intent/work-context.d.ts +13 -0
  206. package/dist/src/intent/work-context.js +22 -0
  207. package/dist/src/intent/work-context.js.map +1 -0
  208. package/dist/src/output/command-receipt.d.ts +6 -2
  209. package/dist/src/output/command-receipt.js +67 -32
  210. package/dist/src/output/command-receipt.js.map +1 -1
  211. package/dist/src/output/component-delivery.d.ts +28 -0
  212. package/dist/src/output/component-delivery.js +141 -0
  213. package/dist/src/output/component-delivery.js.map +1 -0
  214. package/dist/src/output/public-result.d.ts +69 -0
  215. package/dist/src/output/public-result.js +403 -0
  216. package/dist/src/output/public-result.js.map +1 -0
  217. package/dist/src/output/rebuild-progress.d.ts +3 -0
  218. package/dist/src/output/rebuild-progress.js +34 -9
  219. package/dist/src/output/rebuild-progress.js.map +1 -1
  220. package/dist/src/output/receipt-projection.d.ts +7 -0
  221. package/dist/src/output/receipt-projection.js +664 -0
  222. package/dist/src/output/receipt-projection.js.map +1 -0
  223. package/dist/src/output/skill-invocation-notices.d.ts +18 -0
  224. package/dist/src/output/skill-invocation-notices.js +84 -0
  225. package/dist/src/output/skill-invocation-notices.js.map +1 -0
  226. package/dist/src/platforms/antigravity-permissions.d.ts +50 -0
  227. package/dist/src/platforms/antigravity-permissions.js +388 -0
  228. package/dist/src/platforms/antigravity-permissions.js.map +1 -0
  229. package/dist/src/platforms/capabilities.d.ts +9 -0
  230. package/dist/src/platforms/capabilities.js +125 -0
  231. package/dist/src/platforms/capabilities.js.map +1 -0
  232. package/dist/src/platforms/contracts.d.ts +394 -0
  233. package/dist/src/platforms/contracts.js +2 -0
  234. package/dist/src/platforms/contracts.js.map +1 -0
  235. package/dist/src/platforms/cursor-workspace-hook.d.ts +28 -0
  236. package/dist/src/platforms/cursor-workspace-hook.js +198 -0
  237. package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
  238. package/dist/src/platforms/discovery.d.ts +100 -0
  239. package/dist/src/platforms/discovery.js +779 -0
  240. package/dist/src/platforms/discovery.js.map +1 -0
  241. package/dist/src/platforms/grok-permission-config.d.ts +23 -0
  242. package/dist/src/platforms/grok-permission-config.js +184 -0
  243. package/dist/src/platforms/grok-permission-config.js.map +1 -0
  244. package/dist/src/platforms/grok-permission-document.d.ts +4 -0
  245. package/dist/src/platforms/grok-permission-document.js +145 -0
  246. package/dist/src/platforms/grok-permission-document.js.map +1 -0
  247. package/dist/src/platforms/grok-permissions.d.ts +17 -0
  248. package/dist/src/platforms/grok-permissions.js +311 -0
  249. package/dist/src/platforms/grok-permissions.js.map +1 -0
  250. package/dist/src/platforms/host-permission-policy.d.ts +38 -0
  251. package/dist/src/platforms/host-permission-policy.js +86 -0
  252. package/dist/src/platforms/host-permission-policy.js.map +1 -0
  253. package/dist/src/platforms/identity.d.ts +4 -0
  254. package/dist/src/platforms/identity.js +22 -0
  255. package/dist/src/platforms/identity.js.map +1 -0
  256. package/dist/src/platforms/inspection-grok.d.ts +4 -0
  257. package/dist/src/platforms/inspection-grok.js +380 -0
  258. package/dist/src/platforms/inspection-grok.js.map +1 -0
  259. package/dist/src/platforms/inspection-native.d.ts +8 -0
  260. package/dist/src/platforms/inspection-native.js +584 -0
  261. package/dist/src/platforms/inspection-native.js.map +1 -0
  262. package/dist/src/platforms/inspection-opencode.d.ts +4 -0
  263. package/dist/src/platforms/inspection-opencode.js +98 -0
  264. package/dist/src/platforms/inspection-opencode.js.map +1 -0
  265. package/dist/src/platforms/inspection-pi.d.ts +9 -0
  266. package/dist/src/platforms/inspection-pi.js +490 -0
  267. package/dist/src/platforms/inspection-pi.js.map +1 -0
  268. package/dist/src/platforms/inspection-query.d.ts +26 -0
  269. package/dist/src/platforms/inspection-query.js +118 -0
  270. package/dist/src/platforms/inspection-query.js.map +1 -0
  271. package/dist/src/platforms/inspection.d.ts +20 -0
  272. package/dist/src/platforms/inspection.js +259 -0
  273. package/dist/src/platforms/inspection.js.map +1 -0
  274. package/dist/src/platforms/layout.d.ts +35 -0
  275. package/dist/src/platforms/layout.js +332 -0
  276. package/dist/src/platforms/layout.js.map +1 -0
  277. package/dist/src/platforms/lifecycle-native-services.d.ts +3 -0
  278. package/dist/src/platforms/lifecycle-native-services.js +213 -0
  279. package/dist/src/platforms/lifecycle-native-services.js.map +1 -0
  280. package/dist/src/platforms/lifecycle-native.d.ts +14 -0
  281. package/dist/src/platforms/lifecycle-native.js +234 -0
  282. package/dist/src/platforms/lifecycle-native.js.map +1 -0
  283. package/dist/src/platforms/lifecycle.d.ts +29 -0
  284. package/dist/src/platforms/lifecycle.js +688 -0
  285. package/dist/src/platforms/lifecycle.js.map +1 -0
  286. package/dist/src/platforms/opencode-permission-config.d.ts +13 -0
  287. package/dist/src/platforms/opencode-permission-config.js +253 -0
  288. package/dist/src/platforms/opencode-permission-config.js.map +1 -0
  289. package/dist/src/platforms/opencode-permissions.d.ts +39 -0
  290. package/dist/src/platforms/opencode-permissions.js +212 -0
  291. package/dist/src/platforms/opencode-permissions.js.map +1 -0
  292. package/dist/src/platforms/opencode-related-permissions.d.ts +40 -0
  293. package/dist/src/platforms/opencode-related-permissions.js +177 -0
  294. package/dist/src/platforms/opencode-related-permissions.js.map +1 -0
  295. package/dist/src/platforms/permission-ownership.d.ts +89 -0
  296. package/dist/src/platforms/permission-ownership.js +543 -0
  297. package/dist/src/platforms/permission-ownership.js.map +1 -0
  298. package/dist/src/platforms/permission-sidecar.d.ts +70 -0
  299. package/dist/src/platforms/permission-sidecar.js +215 -0
  300. package/dist/src/platforms/permission-sidecar.js.map +1 -0
  301. package/dist/src/platforms/projection-code-extension.d.ts +8 -0
  302. package/dist/src/platforms/projection-code-extension.js +126 -0
  303. package/dist/src/platforms/projection-code-extension.js.map +1 -0
  304. package/dist/src/platforms/projection-command-resources.d.ts +7 -0
  305. package/dist/src/platforms/projection-command-resources.js +74 -0
  306. package/dist/src/platforms/projection-command-resources.js.map +1 -0
  307. package/dist/src/platforms/projection-files.d.ts +28 -0
  308. package/dist/src/platforms/projection-files.js +113 -0
  309. package/dist/src/platforms/projection-files.js.map +1 -0
  310. package/dist/src/platforms/projection-marketplace.d.ts +19 -0
  311. package/dist/src/platforms/projection-marketplace.js +42 -0
  312. package/dist/src/platforms/projection-marketplace.js.map +1 -0
  313. package/dist/src/platforms/projection.d.ts +13 -0
  314. package/dist/src/platforms/projection.js +578 -0
  315. package/dist/src/platforms/projection.js.map +1 -0
  316. package/dist/src/platforms/read-only-retry-policy.d.ts +34 -0
  317. package/dist/src/platforms/read-only-retry-policy.js +70 -0
  318. package/dist/src/platforms/read-only-retry-policy.js.map +1 -0
  319. package/dist/src/platforms/registry.d.ts +4 -0
  320. package/dist/src/platforms/registry.js +30 -0
  321. package/dist/src/platforms/registry.js.map +1 -0
  322. package/dist/src/platforms/retirement-native.d.ts +6 -0
  323. package/dist/src/platforms/retirement-native.js +95 -0
  324. package/dist/src/platforms/retirement-native.js.map +1 -0
  325. package/dist/src/platforms/supplement-layout.d.ts +20 -0
  326. package/dist/src/platforms/supplement-layout.js +54 -0
  327. package/dist/src/platforms/supplement-layout.js.map +1 -0
  328. package/dist/src/platforms/supplement-state.d.ts +13 -0
  329. package/dist/src/platforms/supplement-state.js +93 -0
  330. package/dist/src/platforms/supplement-state.js.map +1 -0
  331. package/dist/src/portable/commands.d.ts +60 -11
  332. package/dist/src/portable/commands.js +88 -346
  333. package/dist/src/portable/commands.js.map +1 -1
  334. package/dist/src/portable/historical-materialization.d.ts +25 -0
  335. package/dist/src/portable/historical-materialization.js +148 -0
  336. package/dist/src/portable/historical-materialization.js.map +1 -0
  337. package/dist/src/portable/materializer.d.ts +46 -2
  338. package/dist/src/portable/materializer.js +262 -259
  339. package/dist/src/portable/materializer.js.map +1 -1
  340. package/dist/src/portable/recovery-layout.d.ts +17 -0
  341. package/dist/src/portable/recovery-layout.js +42 -0
  342. package/dist/src/portable/recovery-layout.js.map +1 -0
  343. package/dist/src/portable/recovery.d.ts +177 -0
  344. package/dist/src/portable/recovery.js +597 -0
  345. package/dist/src/portable/recovery.js.map +1 -0
  346. package/dist/src/portable/writer.d.ts +67 -0
  347. package/dist/src/portable/writer.js +321 -0
  348. package/dist/src/portable/writer.js.map +1 -0
  349. package/dist/src/recovery/coordinator.d.ts +175 -0
  350. package/dist/src/recovery/coordinator.js +1624 -0
  351. package/dist/src/recovery/coordinator.js.map +1 -0
  352. package/dist/src/recovery/demand.d.ts +53 -0
  353. package/dist/src/recovery/demand.js +189 -0
  354. package/dist/src/recovery/demand.js.map +1 -0
  355. package/dist/src/recovery/install-concurrency.d.ts +48 -0
  356. package/dist/src/recovery/install-concurrency.js +196 -0
  357. package/dist/src/recovery/install-concurrency.js.map +1 -0
  358. package/dist/src/recovery/interruption.d.ts +19 -0
  359. package/dist/src/recovery/interruption.js +43 -0
  360. package/dist/src/recovery/interruption.js.map +1 -0
  361. package/dist/src/recovery/joint-coordinator.d.ts +46 -0
  362. package/dist/src/recovery/joint-coordinator.js +1723 -0
  363. package/dist/src/recovery/joint-coordinator.js.map +1 -0
  364. package/dist/src/recovery/joint-demand.d.ts +72 -0
  365. package/dist/src/recovery/joint-demand.js +332 -0
  366. package/dist/src/recovery/joint-demand.js.map +1 -0
  367. package/dist/src/recovery/joint-install-execution.d.ts +19 -0
  368. package/dist/src/recovery/joint-install-execution.js +308 -0
  369. package/dist/src/recovery/joint-install-execution.js.map +1 -0
  370. package/dist/src/recovery/joint-install-native-rebase.d.ts +4 -0
  371. package/dist/src/recovery/joint-install-native-rebase.js +67 -0
  372. package/dist/src/recovery/joint-install-native-rebase.js.map +1 -0
  373. package/dist/src/recovery/performance.d.ts +4 -0
  374. package/dist/src/recovery/performance.js +26 -0
  375. package/dist/src/recovery/performance.js.map +1 -0
  376. package/dist/src/recovery/receipt.d.ts +131 -0
  377. package/dist/src/recovery/receipt.js +91 -0
  378. package/dist/src/recovery/receipt.js.map +1 -0
  379. package/dist/src/recovery/retirement.d.ts +47 -0
  380. package/dist/src/recovery/retirement.js +499 -0
  381. package/dist/src/recovery/retirement.js.map +1 -0
  382. package/dist/src/recovery/status.d.ts +143 -0
  383. package/dist/src/recovery/status.js +1528 -0
  384. package/dist/src/recovery/status.js.map +1 -0
  385. package/dist/src/recovery/types.d.ts +85 -0
  386. package/dist/src/recovery/types.js +2 -0
  387. package/dist/src/recovery/types.js.map +1 -0
  388. package/dist/src/review/eval-source-input.d.ts +44 -0
  389. package/dist/src/review/eval-source-input.js +213 -0
  390. package/dist/src/review/eval-source-input.js.map +1 -0
  391. package/dist/src/review/platform-profile.d.ts +5 -0
  392. package/dist/src/review/platform-profile.js +13 -0
  393. package/dist/src/review/platform-profile.js.map +1 -0
  394. package/dist/src/review/review-profile.d.ts +20 -0
  395. package/dist/src/review/review-profile.js +286 -0
  396. package/dist/src/review/review-profile.js.map +1 -0
  397. package/dist/src/review/review-selection.d.ts +20 -0
  398. package/dist/src/review/review-selection.js +502 -0
  399. package/dist/src/review/review-selection.js.map +1 -0
  400. package/dist/src/review/review-types.d.ts +71 -0
  401. package/dist/src/review/review-types.js +16 -0
  402. package/dist/src/review/review-types.js.map +1 -0
  403. package/dist/src/review/skill-materialization.d.ts +67 -0
  404. package/dist/src/review/skill-materialization.js +235 -0
  405. package/dist/src/review/skill-materialization.js.map +1 -0
  406. package/dist/src/review/source-binding.d.ts +203 -0
  407. package/dist/src/review/source-binding.js +791 -0
  408. package/dist/src/review/source-binding.js.map +1 -0
  409. package/dist/src/tui/agent-management.d.ts +23 -0
  410. package/dist/src/tui/agent-management.js +319 -0
  411. package/dist/src/tui/agent-management.js.map +1 -0
  412. package/dist/src/tui/agent-settings.d.ts +47 -0
  413. package/dist/src/tui/agent-settings.js +97 -0
  414. package/dist/src/tui/agent-settings.js.map +1 -0
  415. package/dist/src/tui/catalog-generation.d.ts +9 -0
  416. package/dist/src/tui/catalog-generation.js +96 -6
  417. package/dist/src/tui/catalog-generation.js.map +1 -1
  418. package/dist/src/tui/catalog-sources/projection.d.ts +2 -2
  419. package/dist/src/tui/catalog-sources/screens.js +19 -12
  420. package/dist/src/tui/catalog-sources/screens.js.map +1 -1
  421. package/dist/src/tui/catalog-sources/session.d.ts +11 -1
  422. package/dist/src/tui/catalog-sources/session.js +80 -5
  423. package/dist/src/tui/catalog-sources/session.js.map +1 -1
  424. package/dist/src/tui/catalog-sources/types.d.ts +15 -2
  425. package/dist/src/tui/catalog-store-task.d.ts +16 -0
  426. package/dist/src/tui/catalog-store-task.js +19 -0
  427. package/dist/src/tui/catalog-store-task.js.map +1 -0
  428. package/dist/src/tui/clipboard.d.ts +13 -0
  429. package/dist/src/tui/clipboard.js +95 -0
  430. package/dist/src/tui/clipboard.js.map +1 -0
  431. package/dist/src/tui/components.d.ts +113 -3
  432. package/dist/src/tui/components.js +201 -34
  433. package/dist/src/tui/components.js.map +1 -1
  434. package/dist/src/tui/config-array-draft.d.ts +30 -0
  435. package/dist/src/tui/config-array-draft.js +51 -0
  436. package/dist/src/tui/config-array-draft.js.map +1 -0
  437. package/dist/src/tui/config-leaf-editor.d.ts +44 -0
  438. package/dist/src/tui/config-leaf-editor.js +227 -0
  439. package/dist/src/tui/config-leaf-editor.js.map +1 -0
  440. package/dist/src/tui/config-object-suggestions.d.ts +15 -0
  441. package/dist/src/tui/config-object-suggestions.js +71 -0
  442. package/dist/src/tui/config-object-suggestions.js.map +1 -0
  443. package/dist/src/tui/config-references.d.ts +38 -0
  444. package/dist/src/tui/config-references.js +82 -0
  445. package/dist/src/tui/config-references.js.map +1 -0
  446. package/dist/src/tui/config-suggestions.d.ts +27 -0
  447. package/dist/src/tui/config-suggestions.js +62 -0
  448. package/dist/src/tui/config-suggestions.js.map +1 -0
  449. package/dist/src/tui/config-value-presentation.d.ts +23 -0
  450. package/dist/src/tui/config-value-presentation.js +151 -0
  451. package/dist/src/tui/config-value-presentation.js.map +1 -0
  452. package/dist/src/tui/console-app-v4.d.ts +14 -5
  453. package/dist/src/tui/console-app-v4.js +9779 -2488
  454. package/dist/src/tui/console-app-v4.js.map +1 -1
  455. package/dist/src/tui/content-item-card.d.ts +13 -0
  456. package/dist/src/tui/content-item-card.js +51 -0
  457. package/dist/src/tui/content-item-card.js.map +1 -0
  458. package/dist/src/tui/controller-runtime.d.ts +4 -3
  459. package/dist/src/tui/controller-runtime.js +1610 -590
  460. package/dist/src/tui/controller-runtime.js.map +1 -1
  461. package/dist/src/tui/controller.d.ts +583 -80
  462. package/dist/src/tui/controller.js +3362 -263
  463. package/dist/src/tui/controller.js.map +1 -1
  464. package/dist/src/tui/dependency-graph-view.d.ts +39 -0
  465. package/dist/src/tui/dependency-graph-view.js +121 -0
  466. package/dist/src/tui/dependency-graph-view.js.map +1 -0
  467. package/dist/src/tui/dependency-graph.d.ts +81 -0
  468. package/dist/src/tui/dependency-graph.js +452 -0
  469. package/dist/src/tui/dependency-graph.js.map +1 -0
  470. package/dist/src/tui/deployment-view.d.ts +14 -0
  471. package/dist/src/tui/deployment-view.js +175 -0
  472. package/dist/src/tui/deployment-view.js.map +1 -0
  473. package/dist/src/tui/diagnostic-projection.d.ts +31 -0
  474. package/dist/src/tui/diagnostic-projection.js +681 -0
  475. package/dist/src/tui/diagnostic-projection.js.map +1 -0
  476. package/dist/src/tui/diagnostics.d.ts +6 -2
  477. package/dist/src/tui/diagnostics.js +14 -2
  478. package/dist/src/tui/diagnostics.js.map +1 -1
  479. package/dist/src/tui/entity-cards.d.ts +56 -0
  480. package/dist/src/tui/entity-cards.js +327 -0
  481. package/dist/src/tui/entity-cards.js.map +1 -0
  482. package/dist/src/tui/glossary.d.ts +25 -0
  483. package/dist/src/tui/glossary.js +78 -0
  484. package/dist/src/tui/glossary.js.map +1 -0
  485. package/dist/src/tui/guided-setup.d.ts +25 -0
  486. package/dist/src/tui/guided-setup.js +101 -0
  487. package/dist/src/tui/guided-setup.js.map +1 -0
  488. package/dist/src/tui/index.d.ts +4 -1
  489. package/dist/src/tui/index.js +4 -1
  490. package/dist/src/tui/index.js.map +1 -1
  491. package/dist/src/tui/input-display.d.ts +1 -0
  492. package/dist/src/tui/input-display.js +23 -1
  493. package/dist/src/tui/input-display.js.map +1 -1
  494. package/dist/src/tui/keys.d.ts +44 -0
  495. package/dist/src/tui/keys.js +43 -15
  496. package/dist/src/tui/keys.js.map +1 -1
  497. package/dist/src/tui/lifecycle-action-view.d.ts +6 -0
  498. package/dist/src/tui/lifecycle-action-view.js +36 -0
  499. package/dist/src/tui/lifecycle-action-view.js.map +1 -0
  500. package/dist/src/tui/model.d.ts +141 -28
  501. package/dist/src/tui/model.js +968 -285
  502. package/dist/src/tui/model.js.map +1 -1
  503. package/dist/src/tui/operation-diagnostic-screens.d.ts +8 -0
  504. package/dist/src/tui/operation-diagnostic-screens.js +76 -0
  505. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
  506. package/dist/src/tui/operation-history.d.ts +91 -0
  507. package/dist/src/tui/operation-history.js +167 -0
  508. package/dist/src/tui/operation-history.js.map +1 -0
  509. package/dist/src/tui/operation-review-planner.d.ts +7 -0
  510. package/dist/src/tui/operation-review-planner.js +980 -146
  511. package/dist/src/tui/operation-review-planner.js.map +1 -1
  512. package/dist/src/tui/plugin-content.d.ts +33 -0
  513. package/dist/src/tui/plugin-content.js +245 -0
  514. package/dist/src/tui/plugin-content.js.map +1 -0
  515. package/dist/src/tui/plugin-detail.d.ts +75 -0
  516. package/dist/src/tui/plugin-detail.js +267 -0
  517. package/dist/src/tui/plugin-detail.js.map +1 -0
  518. package/dist/src/tui/plugin-write-task.d.ts +69 -0
  519. package/dist/src/tui/plugin-write-task.js +286 -0
  520. package/dist/src/tui/plugin-write-task.js.map +1 -0
  521. package/dist/src/tui/query-header.d.ts +30 -0
  522. package/dist/src/tui/query-header.js +40 -0
  523. package/dist/src/tui/query-header.js.map +1 -0
  524. package/dist/src/tui/reader.d.ts +38 -0
  525. package/dist/src/tui/reader.js +49 -0
  526. package/dist/src/tui/reader.js.map +1 -0
  527. package/dist/src/tui/router.d.ts +170 -39
  528. package/dist/src/tui/router.js +338 -50
  529. package/dist/src/tui/router.js.map +1 -1
  530. package/dist/src/tui/scoped-flow.d.ts +49 -0
  531. package/dist/src/tui/scoped-flow.js +212 -0
  532. package/dist/src/tui/scoped-flow.js.map +1 -0
  533. package/dist/src/tui/scoped-inventory.d.ts +139 -0
  534. package/dist/src/tui/scoped-inventory.js +295 -0
  535. package/dist/src/tui/scoped-inventory.js.map +1 -0
  536. package/dist/src/tui/screen-registry.d.ts +696 -0
  537. package/dist/src/tui/screen-registry.js +226 -0
  538. package/dist/src/tui/screen-registry.js.map +1 -0
  539. package/dist/src/tui/session-console-app.d.ts +8 -0
  540. package/dist/src/tui/session-console-app.js +24 -0
  541. package/dist/src/tui/session-console-app.js.map +1 -0
  542. package/dist/src/tui/session-host.d.ts +45 -0
  543. package/dist/src/tui/session-host.js +219 -0
  544. package/dist/src/tui/session-host.js.map +1 -0
  545. package/dist/src/tui/source-detail-card.d.ts +29 -0
  546. package/dist/src/tui/source-detail-card.js +45 -0
  547. package/dist/src/tui/source-detail-card.js.map +1 -0
  548. package/dist/src/tui/theme.d.ts +12 -0
  549. package/dist/src/tui/theme.js +12 -0
  550. package/dist/src/tui/theme.js.map +1 -1
  551. package/dist/src/tui/viewport.d.ts +1 -0
  552. package/dist/src/tui/viewport.js +23 -0
  553. package/dist/src/tui/viewport.js.map +1 -1
  554. package/dist/src/tui/wizard.js +26 -4
  555. package/dist/src/tui/wizard.js.map +1 -1
  556. package/dist/src/types.d.ts +105 -83
  557. package/dist/src/types.js +1 -1
  558. package/dist/src/types.js.map +1 -1
  559. package/dist/src/utils/agent-version.d.ts +10 -4
  560. package/dist/src/utils/agent-version.js +6 -8
  561. package/dist/src/utils/agent-version.js.map +1 -1
  562. package/dist/src/utils/artifact-plan.d.ts +18 -25
  563. package/dist/src/utils/artifact-plan.js +59 -445
  564. package/dist/src/utils/artifact-plan.js.map +1 -1
  565. package/dist/src/utils/artifact-renderer.d.ts +64 -90
  566. package/dist/src/utils/artifact-renderer.js +202 -303
  567. package/dist/src/utils/artifact-renderer.js.map +1 -1
  568. package/dist/src/utils/artifact-request.d.ts +19 -14
  569. package/dist/src/utils/artifact-request.js +51 -36
  570. package/dist/src/utils/artifact-request.js.map +1 -1
  571. package/dist/src/utils/artifact-sources.d.ts +4 -8
  572. package/dist/src/utils/artifact-sources.js +15 -6
  573. package/dist/src/utils/artifact-sources.js.map +1 -1
  574. package/dist/src/utils/aw-home-mutation-lock.js +2 -1
  575. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  576. package/dist/src/utils/bundle-layout.d.ts +2 -0
  577. package/dist/src/utils/bundle-layout.js +88 -158
  578. package/dist/src/utils/bundle-layout.js.map +1 -1
  579. package/dist/src/utils/catalog-capability-projection.d.ts +8 -0
  580. package/dist/src/utils/catalog-capability-projection.js +14 -0
  581. package/dist/src/utils/catalog-capability-projection.js.map +1 -0
  582. package/dist/src/utils/catalog-digests.d.ts +2 -12
  583. package/dist/src/utils/catalog-digests.js +7 -55
  584. package/dist/src/utils/catalog-digests.js.map +1 -1
  585. package/dist/src/utils/catalog-generation-resolver.d.ts +28 -4
  586. package/dist/src/utils/catalog-generation-resolver.js +146 -40
  587. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  588. package/dist/src/utils/catalog-generation-service.d.ts +24 -2
  589. package/dist/src/utils/catalog-generation-service.js +92 -48
  590. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  591. package/dist/src/utils/catalog-generation-state.js +1 -1
  592. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  593. package/dist/src/utils/catalog-generation-store.d.ts +4 -0
  594. package/dist/src/utils/catalog-generation-store.js +68 -10
  595. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  596. package/dist/src/utils/catalog-operation-context.d.ts +61 -4
  597. package/dist/src/utils/catalog-operation-context.js +225 -4
  598. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  599. package/dist/src/utils/catalog-public-error.js +4 -0
  600. package/dist/src/utils/catalog-public-error.js.map +1 -1
  601. package/dist/src/utils/catalog-runtime-projection.d.ts +4 -3
  602. package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
  603. package/dist/src/utils/catalog-snapshot.d.ts +3 -0
  604. package/dist/src/utils/catalog-snapshot.js +4 -1
  605. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  606. package/dist/src/utils/catalog-source-impact.d.ts +3 -2
  607. package/dist/src/utils/catalog-source-impact.js +142 -20
  608. package/dist/src/utils/catalog-source-impact.js.map +1 -1
  609. package/dist/src/utils/catalog-source-references.d.ts +57 -1
  610. package/dist/src/utils/catalog-source-references.js +755 -162
  611. package/dist/src/utils/catalog-source-references.js.map +1 -1
  612. package/dist/src/utils/catalog-sources.d.ts +1 -1
  613. package/dist/src/utils/catalog-sources.js +21 -5
  614. package/dist/src/utils/catalog-sources.js.map +1 -1
  615. package/dist/src/utils/codex-config.d.ts +3 -0
  616. package/dist/src/utils/codex-config.js +7 -0
  617. package/dist/src/utils/codex-config.js.map +1 -1
  618. package/dist/src/utils/codex-executable-discovery.d.ts +28 -0
  619. package/dist/src/utils/codex-executable-discovery.js +431 -0
  620. package/dist/src/utils/codex-executable-discovery.js.map +1 -0
  621. package/dist/src/utils/codex-manager.d.ts +23 -42
  622. package/dist/src/utils/codex-manager.js +79 -767
  623. package/dist/src/utils/codex-manager.js.map +1 -1
  624. package/dist/src/utils/codex-native-observation.d.ts +40 -1
  625. package/dist/src/utils/codex-native-observation.js +172 -0
  626. package/dist/src/utils/codex-native-observation.js.map +1 -1
  627. package/dist/src/utils/codex-reconciler.d.ts +2 -7
  628. package/dist/src/utils/codex-reconciler.js +33 -5
  629. package/dist/src/utils/codex-reconciler.js.map +1 -1
  630. package/dist/src/utils/codex-shared-native.d.ts +8 -26
  631. package/dist/src/utils/codex-shared-native.js +63 -83
  632. package/dist/src/utils/codex-shared-native.js.map +1 -1
  633. package/dist/src/utils/codex-skill-staging.d.ts +4 -3
  634. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  635. package/dist/src/utils/codex-skills-root.d.ts +4 -0
  636. package/dist/src/utils/codex-skills-root.js +29 -0
  637. package/dist/src/utils/codex-skills-root.js.map +1 -0
  638. package/dist/src/utils/codex-surface-analysis.d.ts +6 -2
  639. package/dist/src/utils/codex-surface-analysis.js +31 -56
  640. package/dist/src/utils/codex-surface-analysis.js.map +1 -1
  641. package/dist/src/utils/component-agent-binding.d.ts +17 -0
  642. package/dist/src/utils/component-agent-binding.js +119 -0
  643. package/dist/src/utils/component-agent-binding.js.map +1 -0
  644. package/dist/src/utils/component-command-preparation.d.ts +33 -0
  645. package/dist/src/utils/component-command-preparation.js +129 -0
  646. package/dist/src/utils/component-command-preparation.js.map +1 -0
  647. package/dist/src/utils/component-gap.d.ts +4 -0
  648. package/dist/src/utils/component-gap.js +16 -0
  649. package/dist/src/utils/component-gap.js.map +1 -0
  650. package/dist/src/utils/component-resources.d.ts +53 -0
  651. package/dist/src/utils/component-resources.js +340 -0
  652. package/dist/src/utils/component-resources.js.map +1 -0
  653. package/dist/src/utils/config-platforms.d.ts +21 -0
  654. package/dist/src/utils/config-platforms.js +51 -0
  655. package/dist/src/utils/config-platforms.js.map +1 -0
  656. package/dist/src/utils/dynamic-skill-tree.d.ts +18 -6
  657. package/dist/src/utils/dynamic-skill-tree.js +33 -40
  658. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  659. package/dist/src/utils/git-catalog-provider.d.ts +3 -0
  660. package/dist/src/utils/git-catalog-provider.js +49 -3
  661. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  662. package/dist/src/utils/inventory-recovery-diagnostic.d.ts +4 -0
  663. package/dist/src/utils/inventory-recovery-diagnostic.js +15 -0
  664. package/dist/src/utils/inventory-recovery-diagnostic.js.map +1 -0
  665. package/dist/src/utils/local-marketplace.d.ts +19 -12
  666. package/dist/src/utils/local-marketplace.js +97 -194
  667. package/dist/src/utils/local-marketplace.js.map +1 -1
  668. package/dist/src/utils/managed-command-cli-review.d.ts +53 -0
  669. package/dist/src/utils/managed-command-cli-review.js +431 -0
  670. package/dist/src/utils/managed-command-cli-review.js.map +1 -0
  671. package/dist/src/utils/managed-command-closure.d.ts +14 -0
  672. package/dist/src/utils/managed-command-closure.js +156 -0
  673. package/dist/src/utils/managed-command-closure.js.map +1 -0
  674. package/dist/src/utils/managed-command-errors.d.ts +5 -0
  675. package/dist/src/utils/managed-command-errors.js +10 -0
  676. package/dist/src/utils/managed-command-errors.js.map +1 -0
  677. package/dist/src/utils/managed-command-materialization.d.ts +90 -0
  678. package/dist/src/utils/managed-command-materialization.js +375 -0
  679. package/dist/src/utils/managed-command-materialization.js.map +1 -0
  680. package/dist/src/utils/managed-command-preparation.d.ts +30 -0
  681. package/dist/src/utils/managed-command-preparation.js +39 -0
  682. package/dist/src/utils/managed-command-preparation.js.map +1 -0
  683. package/dist/src/utils/managed-command-review.d.ts +33 -0
  684. package/dist/src/utils/managed-command-review.js +80 -0
  685. package/dist/src/utils/managed-command-review.js.map +1 -0
  686. package/dist/src/utils/managed-command-runtime.d.ts +36 -0
  687. package/dist/src/utils/managed-command-runtime.js +126 -0
  688. package/dist/src/utils/managed-command-runtime.js.map +1 -0
  689. package/dist/src/utils/managed-command-snapshots.d.ts +24 -0
  690. package/dist/src/utils/managed-command-snapshots.js +89 -0
  691. package/dist/src/utils/managed-command-snapshots.js.map +1 -0
  692. package/dist/src/utils/managed-command-store.d.ts +141 -0
  693. package/dist/src/utils/managed-command-store.js +839 -0
  694. package/dist/src/utils/managed-command-store.js.map +1 -0
  695. package/dist/src/utils/multi-source-catalog.d.ts +6 -1
  696. package/dist/src/utils/multi-source-catalog.js +9 -4
  697. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  698. package/dist/src/utils/native-cli-interruption.d.ts +8 -0
  699. package/dist/src/utils/native-cli-interruption.js +65 -0
  700. package/dist/src/utils/native-cli-interruption.js.map +1 -0
  701. package/dist/src/utils/native-cli.d.ts +37 -6
  702. package/dist/src/utils/native-cli.js +523 -60
  703. package/dist/src/utils/native-cli.js.map +1 -1
  704. package/dist/src/utils/native-demand.d.ts +29 -0
  705. package/dist/src/utils/native-demand.js +4 -0
  706. package/dist/src/utils/native-demand.js.map +1 -0
  707. package/dist/src/utils/native-tool-context.d.ts +17 -0
  708. package/dist/src/utils/native-tool-context.js +40 -0
  709. package/dist/src/utils/native-tool-context.js.map +1 -0
  710. package/dist/src/utils/native-tool-review.d.ts +8 -0
  711. package/dist/src/utils/native-tool-review.js +14 -0
  712. package/dist/src/utils/native-tool-review.js.map +1 -0
  713. package/dist/src/utils/ownership.d.ts +38 -3
  714. package/dist/src/utils/ownership.js +118 -11
  715. package/dist/src/utils/ownership.js.map +1 -1
  716. package/dist/src/utils/package-content.d.ts +7 -0
  717. package/dist/src/utils/package-content.js +70 -0
  718. package/dist/src/utils/package-content.js.map +1 -0
  719. package/dist/src/utils/path-catalog-provider.js +2 -0
  720. package/dist/src/utils/path-catalog-provider.js.map +1 -1
  721. package/dist/src/utils/paths.d.ts +1 -1
  722. package/dist/src/utils/paths.js +5 -2
  723. package/dist/src/utils/paths.js.map +1 -1
  724. package/dist/src/utils/platform-empty-state.d.ts +69 -0
  725. package/dist/src/utils/platform-empty-state.js +249 -0
  726. package/dist/src/utils/platform-empty-state.js.map +1 -0
  727. package/dist/src/utils/platform-support.d.ts +1 -1
  728. package/dist/src/utils/platform-support.js +1 -1
  729. package/dist/src/utils/platform-support.js.map +1 -1
  730. package/dist/src/utils/plugin-config-command-apply.d.ts +33 -0
  731. package/dist/src/utils/plugin-config-command-apply.js +142 -0
  732. package/dist/src/utils/plugin-config-command-apply.js.map +1 -0
  733. package/dist/src/utils/plugin-config-diagnostics.d.ts +16 -0
  734. package/dist/src/utils/plugin-config-diagnostics.js +44 -0
  735. package/dist/src/utils/plugin-config-diagnostics.js.map +1 -0
  736. package/dist/src/utils/plugin-config-impact.d.ts +76 -0
  737. package/dist/src/utils/plugin-config-impact.js +359 -0
  738. package/dist/src/utils/plugin-config-impact.js.map +1 -0
  739. package/dist/src/utils/plugin-config-references.d.ts +116 -0
  740. package/dist/src/utils/plugin-config-references.js +379 -0
  741. package/dist/src/utils/plugin-config-references.js.map +1 -0
  742. package/dist/src/utils/plugin-config-suggestion-runner.d.ts +83 -0
  743. package/dist/src/utils/plugin-config-suggestion-runner.js +308 -0
  744. package/dist/src/utils/plugin-config-suggestion-runner.js.map +1 -0
  745. package/dist/src/utils/plugin-config-suggestions.d.ts +50 -0
  746. package/dist/src/utils/plugin-config-suggestions.js +322 -0
  747. package/dist/src/utils/plugin-config-suggestions.js.map +1 -0
  748. package/dist/src/utils/plugin-config-write.d.ts +108 -19
  749. package/dist/src/utils/plugin-config-write.js +781 -568
  750. package/dist/src/utils/plugin-config-write.js.map +1 -1
  751. package/dist/src/utils/plugin-config.d.ts +122 -43
  752. package/dist/src/utils/plugin-config.js +574 -610
  753. package/dist/src/utils/plugin-config.js.map +1 -1
  754. package/dist/src/utils/plugin-dependencies.d.ts +1 -1
  755. package/dist/src/utils/plugin-dependencies.js.map +1 -1
  756. package/dist/src/utils/plugin-scripts.d.ts +41 -17
  757. package/dist/src/utils/plugin-scripts.js +586 -123
  758. package/dist/src/utils/plugin-scripts.js.map +1 -1
  759. package/dist/src/utils/process-lock.js +14 -5
  760. package/dist/src/utils/process-lock.js.map +1 -1
  761. package/dist/src/utils/process-tree.d.ts +2 -2
  762. package/dist/src/utils/process-tree.js +1 -1
  763. package/dist/src/utils/process-tree.js.map +1 -1
  764. package/dist/src/utils/project-boundary.d.ts +11 -1
  765. package/dist/src/utils/project-boundary.js +33 -11
  766. package/dist/src/utils/project-boundary.js.map +1 -1
  767. package/dist/src/utils/rendered-contract.js +24 -1
  768. package/dist/src/utils/rendered-contract.js.map +1 -1
  769. package/dist/src/utils/runtime-config.d.ts +18 -0
  770. package/dist/src/utils/runtime-config.js +64 -0
  771. package/dist/src/utils/runtime-config.js.map +1 -0
  772. package/dist/src/utils/runtime-skill-closure.d.ts +2 -2
  773. package/dist/src/utils/runtime-skill-closure.js +50 -7
  774. package/dist/src/utils/runtime-skill-closure.js.map +1 -1
  775. package/dist/src/utils/safe-operation-diagnostic.d.ts +15 -0
  776. package/dist/src/utils/safe-operation-diagnostic.js +33 -0
  777. package/dist/src/utils/safe-operation-diagnostic.js.map +1 -0
  778. package/dist/src/utils/sensitive-content.d.ts +4 -0
  779. package/dist/src/utils/sensitive-content.js +36 -0
  780. package/dist/src/utils/sensitive-content.js.map +1 -0
  781. package/dist/src/utils/skill-invocation-warning.d.ts +19 -0
  782. package/dist/src/utils/skill-invocation-warning.js +43 -0
  783. package/dist/src/utils/skill-invocation-warning.js.map +1 -0
  784. package/dist/src/utils/skill-validation.js +0 -5
  785. package/dist/src/utils/skill-validation.js.map +1 -1
  786. package/dist/src/utils/state-paths.d.ts +8 -3
  787. package/dist/src/utils/state-paths.js +53 -16
  788. package/dist/src/utils/state-paths.js.map +1 -1
  789. package/dist/src/utils/target-eligibility.d.ts +2 -2
  790. package/dist/src/utils/target-eligibility.js.map +1 -1
  791. package/dist/src/utils/windows-claude-shim.d.ts +7 -0
  792. package/dist/src/utils/windows-claude-shim.js +10 -0
  793. package/dist/src/utils/windows-claude-shim.js.map +1 -0
  794. package/dist/src/utils/windows-npm-shim.d.ts +16 -0
  795. package/dist/src/utils/windows-npm-shim.js +155 -0
  796. package/dist/src/utils/windows-npm-shim.js.map +1 -0
  797. package/dist/vitest.config.js +109 -9
  798. package/dist/vitest.config.js.map +1 -1
  799. package/package.json +20 -12
  800. package/dist/authoring/templates/aw-config-runtime.d.mts +0 -2
  801. package/dist/authoring/templates/aw-config-runtime.mjs +0 -407
  802. package/dist/authoring/templates/aw-config-runtime.mjs.map +0 -1
  803. package/dist/src/commands/review-publication.d.ts +0 -99
  804. package/dist/src/commands/review-publication.js +0 -904
  805. package/dist/src/commands/review-publication.js.map +0 -1
  806. package/dist/src/commands/sync-command.d.ts +0 -23
  807. package/dist/src/commands/sync-command.js +0 -242
  808. package/dist/src/commands/sync-command.js.map +0 -1
  809. package/dist/src/portable/skills-cli.d.ts +0 -43
  810. package/dist/src/portable/skills-cli.js +0 -148
  811. package/dist/src/portable/skills-cli.js.map +0 -1
  812. package/dist/src/utils/codex-native-render-receipt.d.ts +0 -40
  813. package/dist/src/utils/codex-native-render-receipt.js +0 -205
  814. package/dist/src/utils/codex-native-render-receipt.js.map +0 -1
  815. package/dist/src/utils/plugin-intent-state.d.ts +0 -34
  816. package/dist/src/utils/plugin-intent-state.js +0 -289
  817. package/dist/src/utils/plugin-intent-state.js.map +0 -1
  818. package/dist/src/utils/slash-commands.d.ts +0 -1
  819. package/dist/src/utils/slash-commands.js +0 -2
  820. package/dist/src/utils/slash-commands.js.map +0 -1
@@ -0,0 +1,1624 @@
1
+ import { describeNativeToolClosure } from '../utils/native-tool-review.js';
2
+ import path from 'node:path';
3
+ import { isDeliveryCapabilityGap } from '../utils/component-gap.js';
4
+ import { CatalogSourceInventoryIncompleteError } from '../utils/catalog-source-references.js';
5
+ import { inventoryRecoveryDiagnostic } from '../utils/inventory-recovery-diagnostic.js';
6
+ import { commandPackageProviderSatisfied } from '../commands/lifecycle-command-package.js';
7
+ import { runRebuildCommand } from '../commands/rebuild-command.js';
8
+ import { buildRebuildReceiptJson } from '../output/command-receipt.js';
9
+ import { withAwHomeMutationLock } from '../utils/aw-home-mutation-lock.js';
10
+ import { createCodexNativeObservationSession } from '../utils/codex-native-observation.js';
11
+ import { bindNativeCliRunnerSignal, getDefaultNativeCliRunner, prepareNativeCliExecution } from '../utils/native-cli.js';
12
+ import { portableRecoveryLayout } from '../portable/recovery-layout.js';
13
+ import { canonicalizePathThroughExistingAncestor, resolveClaudeProjectKey, resolveCodexProjectKey } from '../utils/state-paths.js';
14
+ import { parsePluginId } from '../utils/multi-source-catalog.js';
15
+ import { CatalogPreparationReadScope, catalogOperationBindingsMatch, recheckCatalogClosureForCommit, selectCatalogOperationContext } from '../utils/catalog-operation-context.js';
16
+ import { CatalogGenerationError } from '../utils/catalog-generation-error.js';
17
+ import { activateCatalogSourceGeneration, probeCatalogSourceGeneration, } from '../utils/catalog-generation-service.js';
18
+ import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
19
+ import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
20
+ import { calculateCatalogSourceImpactDigest, inspectCatalogSourceImpact, } from '../utils/catalog-source-impact.js';
21
+ import { preparePortableRecovery, portablePreparationDiagnostic, portableReviewMatches, unobservedPortableTarget, preparePortableCleanup, inspectPortableRecovery, inspectPortableResidue, executePortableRecovery, PortableInterruptedError, } from '../portable/recovery.js';
22
+ import { addRequirements } from '../commands/intent-command.js';
23
+ import { readDemand, demandNativeProjection, resolveDelivery } from './demand.js';
24
+ import { selectAgents, writePreferences } from '../intent/deployment-preferences.js';
25
+ import { calculateIntentDigest } from '../intent/intent-codec.js';
26
+ import { observeIntent } from '../intent/intent-store.js';
27
+ import { assertNeutralAncestorChain, createScopeContext } from '../intent/scope-context.js';
28
+ import { retainedOutputDiagnostic, scopeNativeComponentGaps, uniqueRecoveryComponentGaps } from './receipt.js';
29
+ import { prepareJointRecovery, executeJointRecovery } from './joint-coordinator.js';
30
+ import { createEmptyNativeDemandView } from '../utils/native-demand.js';
31
+ import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
32
+ import { runPreApplyScript } from '../utils/plugin-scripts.js';
33
+ import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
34
+ import { RebuildInterruptedError, RecoveryInterruptedError, recoveryInterruptionCode } from './interruption.js';
35
+ import { mapInstallReads } from './install-concurrency.js';
36
+ import { measureRecoveryPerformanceStage } from './performance.js';
37
+ import { disposePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
38
+ import { operationPlanNativeToolChanges } from '../commands/operation-plan.js';
39
+ function isPortableAgent(agent) {
40
+ return agent === 'generic';
41
+ }
42
+ function diagnostic(code) {
43
+ const messages = {
44
+ nativeToolAuthorizationRequired: '原生工具声明有变化,请使用 --yes 或确认当前 Review 后执行。',
45
+ localTargetsRequired: '已有需求,请先设置本机 Agent。',
46
+ deliveryUnsupported: '此插件没有适用于所选 Agent 的交付。',
47
+ operationReviewStale: '确认依据已改变,请重新检查并确认。',
48
+ syncPluginNotDesired: '所选插件尚未声明,请先运行 aw plugin install --only requirements。',
49
+ syncSelectionRequired: '请指定插件或使用 --all。',
50
+ invalidExactTargets: '精确重试目标不属于当前请求,请重新检查并选择。',
51
+ sourceRefreshFailed: '来源刷新失败,此来源的插件未恢复。',
52
+ sourceRefreshConfirmationRequired: '来源更新必须先单独确认,再重新准备插件恢复。',
53
+ artifactCollision: '多个交付占用相同输出位置,请先处理冲突。',
54
+ deliverySwitchCleanupRequired: '此目标仍有旧 Native 输出;请先清理旧交付,再恢复 Portable。',
55
+ deliverySwitchObservationFailed: '无法确认此目标是否仍有旧 Native 输出;请先恢复 Native 观察能力或人工核验。',
56
+ deliverySwitchPortableCleanupRequired: '此目标仍有旧 Portable 输出;请先核验并移开旧交付,再恢复 Native。',
57
+ deliverySwitchPortableObservationFailed: '无法确认此目标是否仍有旧 Portable 输出;请先核验 Portable 现场。',
58
+ 'backend-action-unsupported': '此后端尚不支持安全移除,请检查精确的 Portable 输出。',
59
+ };
60
+ return { code, message: messages[code] ?? `操作受阻:${code}。` };
61
+ }
62
+ export function errorCode(error, fallback) {
63
+ const code = error?.code;
64
+ if (typeof code === 'string' && /^[A-Za-z][A-Za-z0-9-]*$/u.test(code))
65
+ return code;
66
+ const prefix = error instanceof Error ? error.message.split(':')[0] : '';
67
+ return /^[A-Za-z][A-Za-z0-9-]*$/u.test(prefix ?? '') ? prefix : fallback;
68
+ }
69
+ function intentEvidence(intent) {
70
+ return 'rawDigest' in intent ? `${intent.state}:${intent.rawDigest}` : intent.state;
71
+ }
72
+ function preferenceEvidence(demand) {
73
+ return 'rawDigest' in demand.preferences
74
+ ? `${demand.preferences.state}:${demand.preferences.rawDigest}` : demand.preferences.state;
75
+ }
76
+ function agentForPlatform(platform) {
77
+ return platform;
78
+ }
79
+ function pair(plan, pluginId, agent) {
80
+ return plan.receipt.targetResults.find((target) => target.pluginId === pluginId && target.agent === agent);
81
+ }
82
+ function block(target, code, detail = diagnostic(code)) {
83
+ if (!target.blockers.some((entry) => entry.code === code))
84
+ target.blockers.push(detail);
85
+ }
86
+ function completeReceipt(receipt) {
87
+ receipt.requestedTargets = receipt.targetResults.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
88
+ receipt.remainingTargets = receipt.targetResults.filter((target) => target.blockers.length > 0
89
+ || !['applied', 'no-op'].includes(target.execution))
90
+ .map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
91
+ receipt.ok = receipt.blockers.length === 0 && receipt.remainingTargets.length === 0
92
+ && (receipt.commandResults ?? []).every((result) => result.state === 'completed');
93
+ receipt.errors = [...receipt.blockers];
94
+ receipt.recoveryActions = [...new Set([
95
+ ...(receipt.commandResults ?? []).flatMap((result) => result.recoveryActions),
96
+ ...receipt.blockers.map((entry) => entry.code === 'localTargetsRequired'
97
+ ? `aw target set <target...>` : `aw plugin status --context ${receipt.scope} --json`),
98
+ ...receipt.remainingTargets.flatMap((target) => {
99
+ const result = receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
100
+ if (result?.recoveryActions?.length)
101
+ return result.recoveryActions;
102
+ return result?.blockers.some((entry) => entry.code === 'backend-action-unsupported' || entry.code === 'portableObservationFailed')
103
+ ? `检查 ${target.pluginId} 的 Portable 输出及 provider 关联;AW 不支持安全自动删除。`
104
+ : `aw plugin sync ${target.pluginId} --context ${receipt.scope} --target ${target.agent}`;
105
+ }),
106
+ ])];
107
+ return receipt;
108
+ }
109
+ function displayPortablePath(plan, physicalPath) {
110
+ if (plan.options.scope === 'user' || !plan.context.projectRoot)
111
+ return physicalPath;
112
+ const relative = path.relative(plan.context.projectRoot, physicalPath);
113
+ return relative && relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)
114
+ ? `项目根目录/${relative.split(path.sep).join('/')}` : physicalPath;
115
+ }
116
+ function portableRecoveryActions(plan, pluginId, targets) {
117
+ return [...new Set(targets.map((target) => {
118
+ const directory = displayPortablePath(plan, target.physicalPath);
119
+ const shared = target.agent === 'generic' || target.agent === 'antigravity'
120
+ ? '该目录可能同时被 Codex 和 Cursor 读取;移开前请确认对两者的影响。' : `该目录供 ${target.agent} 使用。`;
121
+ return `${pluginId}:请检查并备份目录 ${directory};确认归属后可自行移开。${shared}`
122
+ + (plan.command === 'cleanup' || plan.command === 'uninstall'
123
+ ? '无法证实该目录的安全删除边界;处理后重新检查状态。'
124
+ : `然后重试 aw plugin sync ${pluginId} --context ${plan.options.scope} --target ${target.agent}。`);
125
+ }))];
126
+ }
127
+ function selectRoots(demand, selectors, all) {
128
+ const roots = demand.roots?.map((root) => root.pluginId) ?? [];
129
+ if (all && selectors.length)
130
+ throw new Error('syncSelectorConflict');
131
+ if (all)
132
+ return roots;
133
+ if (!selectors.length)
134
+ return roots;
135
+ return [...new Set(selectors.map((selector) => {
136
+ const parsed = parsePluginId(selector);
137
+ const matches = roots.filter((id) => parsed.sourceId ? id === selector
138
+ : parsePluginId(id).pluginName === parsed.pluginName);
139
+ if (matches.length !== 1)
140
+ throw new Error('syncPluginNotDesired');
141
+ return matches[0];
142
+ }))];
143
+ }
144
+ function nativeGroupTargets(group) {
145
+ return group.targets ?? group.pluginIds.flatMap((pluginId) => (group.platform === 'both' ? ['codex', 'claude'] : [group.platform])
146
+ .map((platform) => ({ pluginId, platform })));
147
+ }
148
+ function nativeTargetSelection(targets) {
149
+ const platforms = new Set(targets.map((target) => target.platform));
150
+ return { pluginIds: [...new Set(targets.map((target) => target.pluginId))],
151
+ platform: platforms.size === 1 ? targets[0].platform : 'both', targets: [...targets] };
152
+ }
153
+ // Rebuild accumulates one marketplace generation per platform across sources and scopes.
154
+ async function readNativeGroups(groups, read, signal) {
155
+ const lanes = new Map();
156
+ for (const group of groups) {
157
+ const key = group.command === 'install' || group.command === 'sync' ? group.platform : 'serial';
158
+ const lane = lanes.get(key) ?? [];
159
+ lane.push(group);
160
+ lanes.set(key, lane);
161
+ }
162
+ const results = new Map();
163
+ await mapInstallReads([...lanes.values()], async (lane) => {
164
+ for (const group of lane) {
165
+ signal?.throwIfAborted();
166
+ results.set(group, await read(group));
167
+ }
168
+ }, { signal });
169
+ return groups.map((group) => results.get(group));
170
+ }
171
+ async function nativeOperation(plan, pluginIds, platform, preview, runtime = plan.runtime, command = plan.command, selectedTargets, catalogReadScope) {
172
+ if (!runtime.awHomeMutationToken) {
173
+ await prepareNativeCliExecution({ env: plan.context.env, runner: runtime.nativeCliRunner });
174
+ }
175
+ const rebuildCommand = command === 'install' ? 'sync' : command;
176
+ const requirements = command === 'cleanup' && (plan.demand.intent.state !== 'valid'
177
+ || plan.demand.preferences.state === 'invalid' || plan.demand.preferences.state === 'unreadable')
178
+ ? createEmptyNativeDemandView() : demandNativeProjection(plan.demand);
179
+ if (plan.options.sharedReferenceView)
180
+ requirements.sharedReferenceView = plan.options.sharedReferenceView;
181
+ const result = await runRebuildCommand({
182
+ command: rebuildCommand,
183
+ pluginNames: pluginIds,
184
+ commandOptions: {
185
+ cwd: plan.context.executionCwd, scope: plan.options.scope, platform,
186
+ yes: plan.options.yes,
187
+ scriptTimeoutMs: plan.options.scriptTimeoutMs,
188
+ ...(plan.options.dependencyScopeOverrides ? { dependencyScopeOverrides: plan.options.dependencyScopeOverrides } : {}),
189
+ ...(command === 'cleanup' || command === 'uninstall' ? { force: plan.options.force } : {}),
190
+ },
191
+ runtime: {
192
+ ...runtime,
193
+ preserveLegacyNativeSkills: plan.options.existingOnly === true,
194
+ nativeActivationOnlyTargets: plan.options.nativeActivationOnlyTargets,
195
+ nativePlannedRetirements: plan.options.nativePlannedRetirements,
196
+ ordinaryNativeRemoval: command === 'cleanup' ? plan.options.ordinaryNativeRemoval : undefined,
197
+ ...(preview ? { nativeCliRunner: bindNativeCliRunnerSignal(runtime.nativeCliRunner ?? getDefaultNativeCliRunner(), runtime.signal) } : {}),
198
+ env: plan.options.env,
199
+ catalogOperationContext: plan.demand.catalogOperationContext,
200
+ catalogReadScope,
201
+ previewOperationPlan: preview,
202
+ executionInput: {
203
+ context: plan.context,
204
+ requirements,
205
+ selectedTargets: (selectedTargets ?? nativeGroupTargets({ pluginIds, platform }))
206
+ .map((target) => ({ ...target, scope: plan.options.scope })),
207
+ preserveOtherObservedTargets: true,
208
+ },
209
+ },
210
+ });
211
+ if (preview)
212
+ runtime.signal?.throwIfAborted();
213
+ return result;
214
+ }
215
+ function nativeResults(plan, group, result, executed) {
216
+ for (const diagnostic of result.recoveryDiagnostics ?? []) {
217
+ if (!plan.receipt.blockers.some((entry) => JSON.stringify(entry) === JSON.stringify(diagnostic)))
218
+ plan.receipt.blockers.push(diagnostic);
219
+ }
220
+ if (executed && result.commandResults?.length) {
221
+ plan.receipt.commandResults = [...new Map([
222
+ ...(plan.receipt.commandResults ?? []), ...result.commandResults,
223
+ ].map((entry) => [entry.packageId, entry])).values()];
224
+ }
225
+ const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
226
+ for (const { pluginId, platform } of nativeGroupTargets(group)) {
227
+ const agent = agentForPlatform(platform);
228
+ const target = pair(plan, pluginId, agent);
229
+ if (!target)
230
+ continue;
231
+ target.backend = backend;
232
+ const matchesTarget = (entry) => entry.target.pluginId === pluginId
233
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope;
234
+ const backendTargets = result.targetResults.filter(matchesTarget);
235
+ const rebuildTargets = result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId
236
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope);
237
+ const deploymentPlans = new Map([
238
+ ...(group.preview.operationPlan?.deploymentPlans ?? []),
239
+ ...(result.operationPlan?.deploymentPlans ?? []),
240
+ ].filter((deployment) => deployment.binding.plugin.pluginId === pluginId
241
+ && deployment.binding.platform === platform && deployment.binding.scope.kind === plan.options.scope)
242
+ .map((deployment) => [deployment.binding.id, deployment]));
243
+ if (deploymentPlans.size) {
244
+ target.deploymentPlans = [...deploymentPlans.values()];
245
+ const gaps = target.deploymentPlans.flatMap(({ expected, evidence }) => scopeNativeComponentGaps(expected.unmet, target, evidence.renderUnits));
246
+ if (gaps.length)
247
+ target.componentGaps = uniqueRecoveryComponentGaps(gaps);
248
+ }
249
+ const exclusions = [
250
+ ...(group.preview.deploymentExclusions ?? []),
251
+ ...(result.deploymentExclusions ?? []),
252
+ ...(group.preview.operationPlan?.deploymentExclusions ?? []),
253
+ ...(result.operationPlan?.deploymentExclusions ?? []),
254
+ ...result.rebuildResults.flatMap((entry) => entry.deploymentExclusions ?? []),
255
+ ].filter((entry) => entry.pluginId === pluginId && entry.platform === platform && entry.scope.kind === plan.options.scope);
256
+ if (exclusions.length)
257
+ target.deploymentExclusions = [...new Map(exclusions.map((entry) => [JSON.stringify([entry.pluginId, entry.platform, entry.scope, entry.productId, entry.reasonCode]), entry])).values()];
258
+ const dependencies = result.dependencyPlan?.targets.filter((entry) => entry.platform === platform && (entry.pluginId === pluginId || entry.requiredBy?.includes(pluginId))) ?? [];
259
+ const producers = (result.commandResults ?? []).filter((entry) => {
260
+ const producerPluginId = entry.selector;
261
+ const plugin = plan.demand.plugins.find((plugin) => plugin.pluginId === producerPluginId);
262
+ if (plugin && plugin.sourceIdentity !== entry.producer.sourceIdentity)
263
+ return false;
264
+ const declaration = plugin?.manifest.command;
265
+ if (!declaration?.platforms.includes(platform))
266
+ return false;
267
+ return producerPluginId === pluginId
268
+ || dependencies.some((dependency) => dependency.pluginId === producerPluginId)
269
+ || result.targetResults.some((target) => target.target.pluginId === producerPluginId
270
+ && target.target.platform === platform && target.requiredBy?.includes(pluginId)
271
+ && target.target.scope === (result.dependencyPlan?.targets.find((dependency) => dependency.pluginId === producerPluginId && dependency.platform === platform)?.resolvedScope
272
+ ?? plan.options.scope));
273
+ });
274
+ target.recoveryActions = backend.targetResults.length || backend.commandResults?.length
275
+ ? [...new Set([
276
+ ...backend.targetResults.filter(matchesTarget).flatMap((entry) => entry.recoveryActions),
277
+ ...producers.flatMap((producer) => producer.recoveryActions),
278
+ ])]
279
+ : backend.recoveryActions;
280
+ for (const dependency of dependencies.filter((entry) => entry.action === 'block' && entry.configDiagnostic)) {
281
+ const blocker = dependency.configDiagnostic;
282
+ if (!target.blockers.some((entry) => JSON.stringify(entry) === JSON.stringify(blocker)))
283
+ target.blockers.push(blocker);
284
+ }
285
+ for (const failure of backendTargets.filter((entry) => entry.state === 'failed')) {
286
+ block(target, failure.errorCode ?? 'nativeRecoveryFailed');
287
+ }
288
+ // Keep checked recovery locations even when preparation stops before execution.
289
+ const nativeDiagnostics = rebuildTargets
290
+ .flatMap((entry) => [...(entry.cleanupNotices ?? []), ...(entry.deploymentReceipts ?? []).flatMap((deployment) => [...deployment.diagnostics, ...deployment.effects.flatMap((effect) => effect.diagnostics)])])
291
+ .filter((entry) => entry.detail);
292
+ for (const entry of nativeDiagnostics) {
293
+ const destination = entry.severity === 'error' ? target.blockers : (target.reasons ??= []);
294
+ const detail = { code: entry.code, message: entry.message, subject: entry.subject, detail: entry.detail };
295
+ if (!destination.some((previous) => JSON.stringify(previous) === JSON.stringify(detail)))
296
+ destination.push(detail);
297
+ }
298
+ for (const dependency of dependencies.filter((entry) => entry.action === 'block')) {
299
+ block(target, dependency.errorCode ?? 'dependencyNotReady');
300
+ }
301
+ for (const dependency of dependencies.filter((entry) => entry.pluginId !== pluginId)) {
302
+ for (const failure of result.targetResults.filter((entry) => entry.target.pluginId === dependency.pluginId
303
+ && entry.target.platform === dependency.platform && entry.target.scope === dependency.resolvedScope && entry.state === 'failed')) {
304
+ const code = failure.errorCode ?? 'dependencyNotReady';
305
+ block(target, code, { ...diagnostic(code), pluginId: dependency.pluginId });
306
+ }
307
+ }
308
+ if (executed) {
309
+ const deployments = rebuildTargets.flatMap((entry) => entry.deploymentReceipts ?? []);
310
+ if (deployments.length)
311
+ target.deploymentReceipts = deployments.map((entry) => ({ ...entry,
312
+ products: deploymentPlans.get(entry.bindingId)?.binding.consumers ?? [],
313
+ }));
314
+ const commandFailures = producers.filter((entry) => !commandPackageProviderSatisfied(entry));
315
+ for (const producer of commandFailures) {
316
+ for (const error of producer.errors)
317
+ block(target, error.code);
318
+ if (producer.errors.length === 0)
319
+ block(target, 'managedCommandRecoveryFailed');
320
+ }
321
+ const succeeded = commandFailures.length === 0 && backendTargets.length > 0
322
+ && backendTargets.every((entry) => entry.state === 'completed');
323
+ const effects = deployments.flatMap((entry) => entry.effects);
324
+ const changed = effects.some((effect) => effect.mutation !== 'none')
325
+ || rebuildTargets.some((entry) => entry.cleanupMutation !== undefined);
326
+ if (succeeded) {
327
+ const unchanged = deployments.length > 0 ? effects.every((effect) => effect.status === 'unchanged')
328
+ : backendTargets.every((entry) => entry.action === 'skipped');
329
+ target.execution = unchanged ? 'no-op' : 'applied';
330
+ }
331
+ else {
332
+ const blockedByDependency = !changed && backendTargets.length > 0
333
+ && backendTargets.every((entry) => entry.errorCode === 'dependencyInstallFailed')
334
+ && result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId && entry.target.platform === platform
335
+ && entry.target.scope === plan.options.scope).every((entry) => !entry.cleanupAttempted && entry.actions.length === 0);
336
+ target.execution = blockedByDependency ? 'not-run'
337
+ : changed || backendTargets.some((entry) => entry.state === 'completed') ? 'partial' : 'failed';
338
+ }
339
+ plan.receipt.outputsMayHaveChanged ||= changed;
340
+ if (succeeded && (plan.command === 'cleanup' || plan.command === 'uninstall')) {
341
+ const completed = result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId
342
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope);
343
+ const footprints = result.nativeFootprints?.filter((entry) => entry.pluginId === pluginId
344
+ && entry.platform === platform && entry.scope === plan.options.scope);
345
+ const absent = completed.length > 0 && footprints !== undefined && footprints.length > 0
346
+ && footprints.every((entry) => !entry.shared)
347
+ && completed.every((entry) => entry.status === 'succeeded' && entry.cleanupAttempted
348
+ && entry.removed.length + entry.absent.length > 0 && entry.residual.length === 0
349
+ && entry.quarantined.length === 0 && entry.failures.length === 0);
350
+ target.observation = absent ? 'missing' : 'unknown';
351
+ target.content = absent ? 'absent' : 'unknown';
352
+ }
353
+ else {
354
+ target.observation = succeeded ? 'verified' : 'unknown';
355
+ target.content = succeeded ? 'satisfied' : 'unknown';
356
+ }
357
+ if (deployments.length && plan.command !== 'cleanup' && plan.command !== 'uninstall') {
358
+ const gaps = deployments.flatMap((entry) => scopeNativeComponentGaps(entry.unmet, target, deploymentPlans.get(entry.bindingId)?.evidence.renderUnits));
359
+ if (gaps.length)
360
+ target.componentGaps = uniqueRecoveryComponentGaps(gaps);
361
+ const installed = new Set(deployments.flatMap((entry) => {
362
+ const deployment = deploymentPlans.get(entry.bindingId);
363
+ if (!deployment)
364
+ return [];
365
+ const ids = new Set(deployment.expected.components.map(({ id }) => id));
366
+ if (!succeeded) {
367
+ const partial = new Set(deployment.effects.filter((effect) => (effect.kind === 'publish-package' || effect.kind === 'write-supplement')
368
+ && entry.effects.some((actual) => actual.id === effect.id && actual.status === 'applied' && actual.mutation === 'confirmed'))
369
+ .flatMap((effect) => effect.componentIds));
370
+ for (const id of ids)
371
+ if (!partial.has(id))
372
+ ids.delete(id);
373
+ }
374
+ for (const gap of entry.unmet)
375
+ if (!isDeliveryCapabilityGap(gap))
376
+ ids.delete(gap.componentId ?? gap.id);
377
+ return entry.after.components.filter(({ id, presence, reasonCodes }) => ids.has(id) && presence === 'present' && !reasonCodes.length).map(({ id }) => id);
378
+ }));
379
+ if (installed.size || succeeded && target.deploymentPlans?.every(({ expected }) => !expected.components.length)) {
380
+ target.installedComponentCount = installed.size;
381
+ target.installedComponentIds = [...installed];
382
+ }
383
+ if (succeeded && !target.blockers.length && gaps.every(isDeliveryCapabilityGap)) {
384
+ if (installed.size)
385
+ target.satisfaction = 'installed';
386
+ else if (gaps.length && target.deploymentPlans?.every(({ expected }) => !expected.components.length))
387
+ target.satisfaction = 'not-applicable';
388
+ }
389
+ }
390
+ if (!succeeded && !target.blockers.length)
391
+ block(target, 'nativeRecoveryFailed');
392
+ }
393
+ }
394
+ }
395
+ /** All scopes share one final marketplace generation before Review is returned. */
396
+ export async function refreshRecoveryNativePreviews(plan, catalogReadScope, signal = plan.runtime.signal) {
397
+ const previews = await readNativeGroups(plan.nativeGroups, (group) => nativeOperation(plan, group.pluginIds, group.platform, true, { ...plan.runtime, signal }, group.command, nativeGroupTargets(group), catalogReadScope), signal);
398
+ for (const [index, group] of plan.nativeGroups.entries()) {
399
+ group.preview = previews[index];
400
+ nativeResults(plan, group, group.preview, false);
401
+ }
402
+ completeReceipt(plan.receipt);
403
+ }
404
+ function portableRequiredBy(plan, prepared, target) {
405
+ return plan.portableGroups.filter((group) => group.logicalIdentity === prepared.logicalIdentity
406
+ && group.targets.some((entry) => entry.providerPluginId === target.providerPluginId
407
+ && entry.expectedDigest === target.expectedDigest && entry.physicalPath === target.physicalPath))
408
+ .map((group) => group.options.selector);
409
+ }
410
+ function portableResults(plan, prepared) {
411
+ for (const agent of prepared.options.agents) {
412
+ const target = pair(plan, prepared.options.selector, agent);
413
+ const observations = prepared.targets.filter((entry) => entry.agent === agent);
414
+ const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
415
+ if (gaps.length)
416
+ target.componentGaps = gaps;
417
+ const blockingGap = gaps.some((gap) => !isDeliveryCapabilityGap(gap));
418
+ target.content = observations.some((entry) => entry.observation === 'conflict') ? 'conflict'
419
+ : observations.some((entry) => entry.observation === 'unknown') ? 'unknown'
420
+ : observations.some((entry) => entry.observation === 'drifted') ? 'drifted'
421
+ : observations.some((entry) => entry.observation === 'absent') ? 'absent'
422
+ : observations.length || prepared.intentionalEmpty || gaps.length && !blockingGap && !prepared.blockers.length ? 'satisfied' : 'unknown';
423
+ if ((blockingGap || observations.some((entry) => entry.disposition === 'retain')) && target.content !== 'conflict')
424
+ target.content = 'unknown';
425
+ target.observation = target.content === 'satisfied' ? 'verified'
426
+ : target.content === 'absent' ? 'missing' : 'unknown';
427
+ for (const gap of gaps)
428
+ plan.changes.push(`组件未满足 · ${gap.providerPluginId} · ${gap.componentId ?? gap.id} · ${gap.reasonCode}`
429
+ + gap.requiredFeatures.map((requirement) => ` · ${requirement.feature}${requirement.values ? `: ${requirement.values.join(', ')}` : ''}`).join(''));
430
+ for (const code of [...prepared.globalBlockers, ...observations.flatMap((entry) => entry.blocker
431
+ && !(entry.disposition === 'retain' && entry.blocker === 'previousDeploymentRetained') ? [entry.blocker] : [])]) {
432
+ block(target, code, portablePreparationDiagnostic(prepared, diagnostic(code), agent));
433
+ }
434
+ const retained = observations.filter((entry) => entry.disposition === 'retain');
435
+ if (retained.length)
436
+ target.reasons = retained.map((entry) => retainedOutputDiagnostic(entry.providerPluginId, agent, target.scope, entry.physicalPath, `skill.${entry.skill}`));
437
+ const policyNotices = prepared.policyNotices?.filter((notice) => notice.subject?.target === agent);
438
+ if (policyNotices?.length)
439
+ (target.reasons ??= []).push(...policyNotices);
440
+ target.backend = observations.map((entry) => ({ skill: entry.skill, providerPluginId: entry.providerPluginId,
441
+ requiredBy: portableRequiredBy(plan, prepared, entry), observation: entry.observation,
442
+ ownership: entry.ownership, associatedAgents: entry.associatedAgents }));
443
+ target.recoveryActions = portableRecoveryActions(plan, target.pluginId, observations.filter((entry) => ['conflict', 'unknown'].includes(entry.observation)));
444
+ }
445
+ }
446
+ function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
447
+ const target = pair(plan, prepared.options.selector, agent);
448
+ const contentOutcomes = outcomes.filter((entry) => entry.disposition !== 'remove');
449
+ for (const entry of contentOutcomes) {
450
+ if (entry.invocationWarning && entry.disposition === 'write' && entry.observation === 'satisfied'
451
+ && (entry.execution === 'applied' || entry.execution === 'no-op') && !entry.blockers.length) {
452
+ (target.reasons ??= []).push(entry.invocationWarning);
453
+ }
454
+ }
455
+ const preparedTargets = prepared.targets.filter((entry) => entry.agent === agent);
456
+ const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
457
+ if (gaps.length)
458
+ target.componentGaps = gaps;
459
+ const blockingGap = gaps.some((gap) => !isDeliveryCapabilityGap(gap));
460
+ const completeEmpty = prepared.mode === 'deploy' && (prepared.intentionalEmpty || gaps.length > 0 && !blockingGap) && prepared.blockers.length === 0
461
+ && globalBlockers.length === 0 && preparedTargets.every((entry) => entry.disposition === 'remove')
462
+ && outcomes.length === preparedTargets.length
463
+ && outcomes.every((entry) => entry.observation === 'absent' && entry.blockers.length === 0
464
+ && ['applied', 'no-op'].includes(entry.execution));
465
+ target.execution = (prepared.mode === 'cleanup' || completeEmpty) && outcomes.length === 0 && !globalBlockers.length ? 'no-op' : outcomes.length > 0 && outcomes.every((entry) => entry.execution === 'no-op') ? 'no-op'
466
+ : outcomes.length > 0 && outcomes.every((entry) => ['applied', 'no-op'].includes(entry.execution)) ? 'applied'
467
+ : outcomes.some((entry) => ['applied', 'no-op'].includes(entry.execution)) ? 'partial'
468
+ : outcomes.some((entry) => entry.execution === 'failed') ? 'failed' : 'not-run';
469
+ target.observation = contentOutcomes.length > 0 && contentOutcomes.every((entry) => entry.observation === 'satisfied')
470
+ && globalBlockers.length === 0 ? 'verified'
471
+ : globalBlockers.length === 0 && contentOutcomes.some((entry) => entry.observation === 'absent'
472
+ || entry.observation === 'drifted') && contentOutcomes.every((entry) => entry.observation !== 'unknown'
473
+ && entry.observation !== 'conflict') ? 'missing' : 'unknown';
474
+ target.content = contentOutcomes.some((entry) => entry.observation === 'conflict') ? 'conflict'
475
+ : contentOutcomes.some((entry) => entry.observation === 'unknown') ? 'unknown'
476
+ : contentOutcomes.some((entry) => entry.observation === 'drifted') ? 'drifted'
477
+ : contentOutcomes.some((entry) => entry.observation === 'absent') ? 'absent'
478
+ : contentOutcomes.length ? 'satisfied' : 'unknown';
479
+ if (prepared.mode === 'cleanup' && globalBlockers.length === 0
480
+ && outcomes.every((entry) => entry.observation === 'absent' && entry.blockers.length === 0)) {
481
+ target.observation = 'missing';
482
+ target.content = 'absent';
483
+ }
484
+ else if (completeEmpty) {
485
+ target.observation = 'verified';
486
+ target.content = 'satisfied';
487
+ }
488
+ if (prepared.mode === 'deploy') {
489
+ const installed = contentOutcomes.filter((entry) => entry.providerPluginId === target.pluginId
490
+ && entry.disposition === 'write' && entry.observation === 'satisfied' && !entry.blockers.length);
491
+ if (installed.length || !globalBlockers.length && contentOutcomes.every((entry) => entry.disposition === 'retain' || entry.observation === 'satisfied' || entry.observation === 'absent')) {
492
+ target.installedComponentCount = installed.length;
493
+ if (installed.every((entry) => entry.componentId))
494
+ target.installedComponentIds = installed.map((entry) => entry.componentId);
495
+ }
496
+ if (target.content === 'satisfied' && !blockingGap && !globalBlockers.length && outcomes.every((entry) => !entry.blockers.length)
497
+ && (target.execution === 'applied' || target.execution === 'no-op')) {
498
+ if (installed.length)
499
+ target.satisfaction = 'installed';
500
+ else if (gaps.some((gap) => gap.providerPluginId === target.pluginId))
501
+ target.satisfaction = 'not-applicable';
502
+ }
503
+ }
504
+ if (blockingGap || contentOutcomes.some((entry) => entry.disposition === 'retain')) {
505
+ if (target.execution === 'applied' || target.execution === 'no-op')
506
+ target.execution = 'partial';
507
+ if (target.content !== 'conflict')
508
+ target.content = 'unknown';
509
+ target.observation = 'unknown';
510
+ if (blockingGap)
511
+ block(target, 'portableComponentsUnmet');
512
+ }
513
+ target.backend = outcomes.map((entry) => ({ skill: entry.skill, providerPluginId: entry.providerPluginId,
514
+ requiredBy: portableRequiredBy(plan, prepared, entry), observation: entry.observation,
515
+ ownership: entry.ownership, associatedAgents: entry.associatedAgents,
516
+ execution: entry.execution, blockers: entry.blockers }));
517
+ for (const code of [...globalBlockers, ...outcomes.flatMap((entry) => entry.blockers)])
518
+ block(target, code);
519
+ target.recoveryActions = portableRecoveryActions(plan, target.pluginId, outcomes.filter((entry) => entry.observation === 'conflict' || entry.observation === 'unknown' && !entry.blockers.includes('operationReviewStale')));
520
+ if (globalBlockers.includes('operationReviewStale') && prepared.mode !== 'cleanup') {
521
+ target.recoveryActions.push(`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent}`);
522
+ }
523
+ }
524
+ function portablePluginClosure(plan, prepared) {
525
+ const { sourceId, pluginName } = parsePluginId(prepared.options.selector);
526
+ return resolvePluginMetaDependencyClosure(plan.demand.plugins.filter((plugin) => plugin.sourceId === sourceId), [pluginName])
527
+ .filter((plugin) => !prepared.options.excludedPluginIds?.includes(plugin.pluginId));
528
+ }
529
+ function isHealthyPortableProvider(group) {
530
+ return !group.blockers.length && group.unmet.every(isDeliveryCapabilityGap)
531
+ && (group.intentionalEmpty || group.unmet.length > 0 || group.targets.length > 0)
532
+ && group.targets.every((target) => target.disposition === 'write' && target.ownership === 'aw'
533
+ && target.observation === 'satisfied' && target.installedDigest === target.expectedDigest);
534
+ }
535
+ function preparePortablePreApplyAuthorization(plan) {
536
+ if (plan.command === 'cleanup' || plan.command === 'uninstall')
537
+ return;
538
+ const authorization = new Map();
539
+ const verifiedProviders = new Set(plan.portableGroups.filter((group) => plan.options.inheritedPortableProviderIds?.includes(group.options.selector) && isHealthyPortableProvider(group))
540
+ .map((group) => group.options.selector));
541
+ for (const prepared of plan.portableGroups) {
542
+ for (const plugin of portablePluginClosure(plan, prepared)) {
543
+ if (!plugin.manifest.scripts?.preApply || verifiedProviders.has(plugin.pluginId))
544
+ continue;
545
+ for (const platform of prepared.options.agents) {
546
+ if (pair(plan, prepared.options.selector, platform)?.blockers.length)
547
+ continue;
548
+ const target = {
549
+ pluginId: plugin.pluginId, pluginName: plugin.manifest.name,
550
+ sourceId: plugin.sourceId, sourceIdentity: plugin.sourceIdentity,
551
+ platform, scope: plan.options.scope,
552
+ relation: plugin.pluginId === prepared.options.selector ? 'requested'
553
+ : plan.demand.plugins.find((entry) => entry.pluginId === prepared.options.selector)?.manifest.dependencies?.includes(plugin.manifest.name)
554
+ ? 'direct' : 'transitive',
555
+ };
556
+ authorization.set([target.pluginId, target.platform, target.scope].join('\0'), target);
557
+ }
558
+ }
559
+ }
560
+ plan.preApplyAuthorization = [...authorization.values()];
561
+ plan.changes.push(...plan.preApplyAuthorization.map((target) => `运行插件 preApply 脚本:${target.pluginId} / ${target.platform} / ${target.scope}。`));
562
+ }
563
+ async function executePortablePreApply(plan, prepared, agent, runtime) {
564
+ if (prepared.mode === 'cleanup' || plan.command === 'cleanup' || plan.command === 'uninstall')
565
+ return;
566
+ const plugins = portablePluginClosure(plan, prepared);
567
+ const required = plan.preApplyAuthorization?.filter((target) => target.platform === agent
568
+ && plugins.some((plugin) => plugin.pluginId === target.pluginId)) ?? [];
569
+ return executePreApplyAuthorization(plan, required, runtime);
570
+ }
571
+ async function executePreApplyAuthorization(plan, required, runtime) {
572
+ if (!required.length)
573
+ return;
574
+ if (plan.options.yes !== true && runtime.preApplyConfirmed !== true)
575
+ return 'preApplyAuthorizationRequired';
576
+ const cache = runtime.preApplyExecutionCache ??= new Map();
577
+ for (const target of required) {
578
+ runtime.signal?.throwIfAborted();
579
+ const plugin = plan.demand.plugins.find((entry) => entry.pluginId === target.pluginId);
580
+ if (!plugin || plugin.sourceIdentity !== target.sourceIdentity)
581
+ return 'sourceUnavailable';
582
+ const context = target.scope === plan.options.scope ? plan.context
583
+ : await createScopeContext({ scope: target.scope, cwd: plan.context.callerCwd, env: plan.options.env });
584
+ try {
585
+ const projectKey = target.scope !== 'project' ? '' : target.platform === 'codex'
586
+ ? await resolveCodexProjectKey(context.executionCwd) : target.platform === 'claude'
587
+ ? await resolveClaudeProjectKey(context.executionCwd) : context.projectKey;
588
+ const key = [target.sourceIdentity, target.pluginId, target.platform, target.scope, projectKey].join('\0');
589
+ let execution = cache.get(key);
590
+ if (!execution) {
591
+ execution = runPreApplyScript({ plugin, platform: target.platform, scope: target.scope,
592
+ cwd: context.executionCwd, context: { env: context.env, interruption: runtime.interruption },
593
+ referencePlugins: plan.demand.plugins, scriptTimeoutMs: plan.options.scriptTimeoutMs });
594
+ cache.set(key, execution);
595
+ }
596
+ await execution;
597
+ }
598
+ catch (error) {
599
+ const interrupted = recoveryInterruptionCode(error, runtime.signal);
600
+ if (interrupted) {
601
+ const affected = pair(plan, target.pluginId, target.platform);
602
+ if (affected) {
603
+ affected.execution = 'partial';
604
+ affected.observation = 'unknown';
605
+ affected.content = 'unknown';
606
+ block(affected, interrupted);
607
+ }
608
+ plan.receipt.outputsMayHaveChanged = true;
609
+ throw error;
610
+ }
611
+ const operationDiagnostic = readSafeOperationError(error);
612
+ const affected = pair(plan, target.pluginId, target.platform);
613
+ if (affected) {
614
+ affected.execution = 'failed';
615
+ block(affected, 'preApplyFailed');
616
+ if (affected.delivery?.kind === 'native') {
617
+ const identity = { pluginId: target.pluginId, pluginName: plugin.manifest.name, pluginVersion: plugin.manifest.version,
618
+ sourceId: plugin.sourceId, sourceIdentity: target.sourceIdentity, platform: affected.delivery.platform,
619
+ scope: target.scope, cwd: context.executionCwd };
620
+ const failure = { phase: 'preApply', message: operationDiagnostic?.safeMessage ?? 'The preApply script failed.',
621
+ ...(operationDiagnostic ? { operationDiagnostic } : {}) };
622
+ affected.backend = buildRebuildReceiptJson(plan.command, { platforms: [target.platform], plugins: [], warnings: [],
623
+ targetResults: [{ target: identity, action: 'install', state: 'failed', errorCode: 'preApplyFailed' }],
624
+ rebuildResults: [{ status: 'failed', command: plan.command, target: identity, actions: [{ name: 'preApply', status: 'failed' }],
625
+ cleanupAttempted: false, removed: [], absent: [], residual: [], quarantined: [], failures: [failure], error: failure }] });
626
+ }
627
+ }
628
+ return 'preApplyFailed';
629
+ }
630
+ finally {
631
+ if (context !== plan.context)
632
+ await context.dispose();
633
+ }
634
+ }
635
+ }
636
+ /** Run the reviewed replacement's hooks before any dependent old-output cleanup. */
637
+ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
638
+ if (plan.command === 'cleanup' || plan.command === 'uninstall')
639
+ return;
640
+ if (plan.receipt.nativeToolChanges?.length && plan.options.yes !== true)
641
+ return 'nativeToolAuthorizationRequired';
642
+ const target = pair(plan, pluginId, agent);
643
+ if (!target)
644
+ return 'preApplyTargetUnavailable';
645
+ if (target.blockers.length)
646
+ return target.blockers[0].code;
647
+ if (target.delivery?.kind === 'native') {
648
+ const platform = target.delivery.platform;
649
+ try {
650
+ const authorization = await nativeOperation(plan, [pluginId], platform, true, { ...runtime, resolvePreApplyAuthorization: true }, plan.command, [{ pluginId, platform }]);
651
+ if (authorization.overallState !== 'succeeded' || !authorization.preApplyAuthorization) {
652
+ return authorization.targetResults.find((result) => result.errorCode)?.errorCode ?? 'preApplyAuthorizationUnavailable';
653
+ }
654
+ const blocked = authorization.dependencyPlan?.targets.find((entry) => entry.action === 'block'
655
+ && (entry.pluginId === pluginId || entry.requiredBy.includes(pluginId)));
656
+ if (blocked)
657
+ return blocked.errorCode ?? 'nativePreparationFailed';
658
+ return executePreApplyAuthorization(plan, authorization.preApplyAuthorization, runtime);
659
+ }
660
+ catch (error) {
661
+ if (recoveryInterruptionCode(error, runtime.signal))
662
+ throw error;
663
+ return readSafeOperationError(error)?.code ?? errorCode(error, 'nativePreparationFailed');
664
+ }
665
+ }
666
+ if (isPortableAgent(agent)) {
667
+ const prepared = plan.portableGroups.find((group) => group.options.selector === pluginId
668
+ && group.options.agents.includes(agent));
669
+ if (prepared)
670
+ return executePortablePreApply(plan, prepared, agent, runtime);
671
+ }
672
+ }
673
+ export async function checkFootprints(plan) {
674
+ const footprints = [];
675
+ for (const [nativeGroup, group] of plan.nativeGroups.entries()) {
676
+ const actions = group.preview.operationPlan?.actions.filter((action) => (action.kind === 'writeOwnedArtifact' || action.kind === 'removeOwnedArtifact')
677
+ && !group.preview.nativeFootprints?.some((footprint) => footprint.path === action.path
678
+ && footprint.pluginId === action.pluginId && footprint.platform === action.platform)) ?? [];
679
+ for (const action of [...(group.preview.nativeFootprints ?? []), ...actions]) {
680
+ if (!('path' in action))
681
+ continue;
682
+ const consumers = group.preview.dependencyPlan?.targets.filter((target) => target.pluginId === action.pluginId)
683
+ .flatMap((target) => target.requiredBy ?? []) ?? [];
684
+ footprints.push({ path: action.path,
685
+ pluginIds: group.pluginIds.filter((id) => id === action.pluginId || consumers.includes(id)),
686
+ agent: agentForPlatform(action.platform), identity: `native:${action.platform}:${action.pluginId}`,
687
+ sharedNative: 'shared' in action && action.shared,
688
+ ...('sharedMarketplace' in action && action.sharedMarketplace
689
+ ? { sharedMarketplaceSource: parsePluginId(action.pluginId).sourceId } : {}),
690
+ nativeGroup });
691
+ }
692
+ }
693
+ for (const prepared of plan.portableGroups) {
694
+ for (const target of prepared.targets)
695
+ footprints.push({
696
+ path: target.physicalPath,
697
+ pluginIds: [prepared.options.selector], agent: target.agent,
698
+ identity: JSON.stringify(['agent-skills', prepared.logicalIdentity, target.providerPluginId, target.expectedDigest,
699
+ target.configDigest, target.disposition]),
700
+ });
701
+ }
702
+ const paths = [...new Set(footprints.map((entry) => entry.path))];
703
+ const canonical = new Map(await mapInstallReads(paths, async (value) => [value, await canonicalizePathThroughExistingAncestor(value)], { signal: plan.runtime.signal }));
704
+ for (const item of footprints)
705
+ item.path = canonical.get(item.path);
706
+ for (let index = 0; index < footprints.length; index += 1) {
707
+ const left = footprints[index];
708
+ for (const right of footprints.slice(index + 1)) {
709
+ const overlap = left.path === right.path || left.path.startsWith(right.path + path.sep) || right.path.startsWith(left.path + path.sep);
710
+ if (!overlap || left.identity === right.identity
711
+ || (left.nativeGroup !== undefined && left.nativeGroup === right.nativeGroup)
712
+ || (left.sharedMarketplaceSource !== undefined && left.agent === right.agent
713
+ && left.sharedMarketplaceSource === right.sharedMarketplaceSource)
714
+ || (left.sharedNative && right.sharedNative && left.agent === right.agent))
715
+ continue;
716
+ for (const footprint of [left, right]) {
717
+ for (const pluginId of footprint.pluginIds) {
718
+ const target = pair(plan, pluginId, footprint.agent);
719
+ if (target)
720
+ block(target, 'artifactCollision');
721
+ }
722
+ }
723
+ }
724
+ }
725
+ for (const prepared of plan.portableGroups) {
726
+ const layout = portableRecoveryLayout(plan.context);
727
+ plan.changes.push(`${prepared.options.selector}:AW 写入所选 Agent 的 owned Skill 目录;准备目录 ${layout.generationRoot}。`);
728
+ }
729
+ }
730
+ export async function prepareScopedRecovery(command, selectors, options, runtime = {}, { catalogReadScope = new CatalogPreparationReadScope(options), nativeObservationBatch, portableGenerations = new Map(), portableRenderResults = new Map() } = {}) {
731
+ runtime = { ...runtime, preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
732
+ options.signal?.throwIfAborted();
733
+ const context = await createScopeContext({ scope: options.scope, cwd: options.cwd, env: options.env });
734
+ try {
735
+ options.signal?.throwIfAborted();
736
+ options = { ...options, cwd: context.executionCwd, env: context.env };
737
+ let demand = options.demandOverride ?? await readDemand({ ...options, catalogReadScope, preferences: undefined });
738
+ const refreshFailures = new Map();
739
+ const sourceRefreshes = [];
740
+ if (options.refresh && command === 'sync') {
741
+ let selected = [];
742
+ try {
743
+ selected = selectRoots(demand, selectors, options.all ?? false);
744
+ }
745
+ catch { /* Selection below reports the invalid request without refreshing any source. */ }
746
+ if (selected.length > 0) {
747
+ const config = await readCatalogSourcesConfigSnapshot(options.env);
748
+ const generationState = await readCatalogGenerationState(options.env);
749
+ for (const sourceId of new Set(selected.map((id) => parsePluginId(id).sourceId))) {
750
+ try {
751
+ const source = config.config.sources.find((entry) => entry.id === sourceId);
752
+ const probe = await probeCatalogSourceGeneration({ sourceId, env: options.env,
753
+ cliVersion: options.cliVersion, signal: options.signal, runtime: runtime.catalogGenerationRuntime });
754
+ const previousActive = generationState.sources[sourceId]?.active ?? null;
755
+ const candidateChanged = !previousActive
756
+ || previousActive.sourceConfigFingerprint !== probe.candidate.sourceConfigFingerprint
757
+ || previousActive.sourceIdentity !== probe.candidate.sourceIdentity
758
+ || previousActive.logicalIdentity !== probe.candidate.logicalIdentity
759
+ || previousActive.requestedRef !== probe.candidate.requestedRef
760
+ || previousActive.manifestDigest !== probe.candidate.manifestDigest
761
+ || previousActive.snapshotDigest !== probe.candidate.snapshotDigest
762
+ || previousActive.resolvedCommit !== probe.candidate.resolvedCommit;
763
+ if (!candidateChanged)
764
+ continue;
765
+ const inspectImpact = runtime.catalogGenerationRuntime?.inspectSourceImpact
766
+ ?? inspectCatalogSourceImpact;
767
+ const impact = await inspectImpact({ sourceId, cwd: options.cwd, env: options.env,
768
+ sourcePrimary: source?.primary === true, mode: 'generation', candidateManifest: probe.manifest });
769
+ sourceRefreshes.push({ sourceId, candidate: probe.candidate, previousActive,
770
+ configDigest: config.digest, impact, impactDigest: calculateCatalogSourceImpactDigest(impact) });
771
+ }
772
+ catch (error) {
773
+ if (recoveryInterruptionCode(error, options.signal))
774
+ throw error;
775
+ const code = errorCode(error, 'catalogGenerationRefreshFailed');
776
+ refreshFailures.set(sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
777
+ }
778
+ }
779
+ }
780
+ }
781
+ options.signal?.throwIfAborted();
782
+ const originalIntent = intentEvidence(demand.intent);
783
+ const proposed = command === 'install'
784
+ ? await addRequirements({ ...options, catalogReadScope, selectors, dryRun: true, installSelectors: true }) : undefined;
785
+ if (proposed?.state && proposed.errors.length === 0) {
786
+ const rawBytes = Buffer.from(JSON.stringify(proposed.state));
787
+ demand = await readDemand({ ...options, catalogReadScope, preferences: undefined, intent: {
788
+ state: 'valid', value: proposed.state, rawBytes,
789
+ digest: calculateIntentDigest(proposed.state), rawDigest: originalIntent,
790
+ } });
791
+ }
792
+ const receipt = {
793
+ schemaVersion: 1, kind: 'aw-recovery', scope: options.scope, command, ok: false,
794
+ intent: { state: demand.intent.state, ...('digest' in demand.intent ? { digest: demand.intent.digest } : {}),
795
+ roots: demand.roots?.map((root) => root.pluginId) ?? null },
796
+ requestedRoots: [], requestedTargets: [], selection: { agents: [], origin: 'none', preferences: demand.preferences.state },
797
+ blockers: proposed?.errors ?? [], errors: [], targetResults: [], remainingTargets: [], recoveryActions: [],
798
+ declarationChanged: false, preferencesChanged: false, configChanged: false, outputsMayHaveChanged: false,
799
+ };
800
+ const { signal: _signal, ...executionOptions } = options;
801
+ const plan = { command, options: executionOptions, receipt, demand, context, originalIntent,
802
+ plannedImpact: { declaration: proposed?.changed === true, preferences: false, config: false, outputs: false },
803
+ preferencesEvidence: preferenceEvidence(demand), changes: [], warnings: [],
804
+ nativeGroups: [], portableGroups: [],
805
+ portableProtectionGroups: [], runtime,
806
+ portableResidues: [], sourceRefreshes,
807
+ sourceRefreshFailures: [...refreshFailures].map(([sourceId, code]) => ({ sourceId, code })),
808
+ blockExecution: false,
809
+ ...(proposed?.state && proposed.errors.length === 0 ? { declaration: proposed.roots } : {}),
810
+ };
811
+ if (proposed?.changed)
812
+ plan.changes.push(`保存 ${options.scope} 插件需求:${proposed.roots.join('、')}。`);
813
+ const preciseCleanup = (command === 'cleanup' || command === 'uninstall') && selectors.length > 0
814
+ && options.targets !== undefined;
815
+ try {
816
+ receipt.selection = selectAgents({ preferences: preciseCleanup ? { state: 'absent' } : demand.preferences,
817
+ targets: options.targets });
818
+ receipt.requestedRoots = preciseCleanup ? [...new Set(selectors.map((selector) => {
819
+ const parsed = parsePluginId(selector);
820
+ if (!parsed.sourceId)
821
+ throw new Error('cleanupPluginIdRequired');
822
+ return `${parsed.sourceId}/${parsed.pluginName}`;
823
+ }))] : selectRoots(demand, selectors, options.all ?? false);
824
+ }
825
+ catch (error) {
826
+ receipt.blockers.push(diagnostic(errorCode(error, 'projectSelectionInvalid')));
827
+ }
828
+ if (options.exactTargets && (options.exactTargets.length === 0 || options.exactTargets.some((target) => !receipt.requestedRoots.includes(target.pluginId) || !receipt.selection.agents.includes(target.agent)))) {
829
+ receipt.blockers.push(diagnostic('invalidExactTargets'));
830
+ }
831
+ if (!preciseCleanup) {
832
+ if (!['valid', 'absent'].includes(demand.intent.state))
833
+ receipt.blockers.push(diagnostic('pluginIntentStateInvalid'));
834
+ }
835
+ if (receipt.requestedRoots.length && !receipt.selection.agents.length)
836
+ receipt.blockers.push(diagnostic('localTargetsRequired'));
837
+ if (!preciseCleanup)
838
+ receipt.blockers.push(...demand.errors);
839
+ plan.blockExecution = Boolean(proposed?.errors.length)
840
+ || receipt.blockers.length > 0;
841
+ for (const [sourceId, code] of refreshFailures) {
842
+ receipt.blockers.push({ code, message: `${sourceId}:${diagnostic('sourceRefreshFailed').message}` });
843
+ }
844
+ for (const root of demand.roots ?? []) {
845
+ if (!receipt.requestedRoots.includes(root.pluginId) || preciseCleanup)
846
+ continue;
847
+ receipt.blockers.push(...root.blockers.map((code) => ({ ...diagnostic(code), message: `${root.pluginId}:${diagnostic(code).message}` })));
848
+ }
849
+ for (const pluginId of receipt.requestedRoots) {
850
+ const root = demand.roots?.find((entry) => entry.pluginId === pluginId);
851
+ const agents = receipt.selection.agents;
852
+ for (const agent of agents) {
853
+ if (options.exactTargets
854
+ && !options.exactTargets.some((target) => target.pluginId === pluginId && target.agent === agent))
855
+ continue;
856
+ const resolvedDelivery = root?.plugin ? resolveDelivery(root.plugin.manifest, agent, options.scope) ?? null : null;
857
+ const delivery = preciseCleanup ? isPortableAgent(agent)
858
+ ? { kind: 'agent-skills', provider: 'aw', agentId: 'generic' }
859
+ : { kind: 'native', platform: agent } : resolvedDelivery;
860
+ const configPackageBlocker = delivery?.kind === 'native' && options.existingOnly
861
+ ? runtime.configApplyPackages?.targets.find((target) => target.pluginId === pluginId
862
+ && target.platforms.includes(delivery.platform))?.blocker : undefined;
863
+ receipt.targetResults.push({ pluginId, agent, scope: options.scope, delivery, execution: 'not-run', observation: 'unknown',
864
+ blockers: [...(preciseCleanup ? [] : root?.blockers ?? []).map(diagnostic),
865
+ ...(configPackageBlocker ? [configPackageBlocker] : []),
866
+ ...(refreshFailures.has(parsePluginId(pluginId).sourceId)
867
+ ? [diagnostic(refreshFailures.get(parsePluginId(pluginId).sourceId))] : []),
868
+ ...(!delivery ? [diagnostic(preciseCleanup ? 'backend-action-unsupported' : 'deliveryUnsupported')] : [])],
869
+ requiredBy: [pluginId] });
870
+ }
871
+ }
872
+ if (plan.blockExecution)
873
+ return { ...plan, receipt: completeReceipt(receipt) };
874
+ if (sourceRefreshes.length > 0) {
875
+ for (const refresh of sourceRefreshes) {
876
+ plan.changes.push(`刷新 Catalog 来源 ${refresh.sourceId},确认后激活已检查的候选 generation。`);
877
+ if (!refresh.impact.inventoryComplete) {
878
+ plan.warnings.push(`${refresh.sourceId}:来源影响清单不完整,需要明确确认。`);
879
+ }
880
+ else if (refresh.impact.affectedReferences.length > 0) {
881
+ plan.warnings.push(`${refresh.sourceId}:来源更新会影响 ${refresh.impact.affectedReferences.length} 个已知引用,需要明确确认。`);
882
+ }
883
+ }
884
+ return { ...plan, receipt: completeReceipt(receipt) };
885
+ }
886
+ const groups = new Map();
887
+ for (const target of receipt.targetResults) {
888
+ if (target.blockers.length || target.delivery?.kind !== 'native')
889
+ continue;
890
+ const command = plan.command;
891
+ const key = `${parsePluginId(target.pluginId).sourceId}\0${target.delivery.platform}\0${command}`;
892
+ const group = groups.get(key) ?? { command, targets: [] };
893
+ group.targets.push({ pluginId: target.pluginId, platform: target.delivery.platform });
894
+ groups.set(key, group);
895
+ }
896
+ const preparationRuntime = { ...runtime, signal: options.signal, nativeObservationBatch };
897
+ const pendingGroups = [...groups.values()].map((pending) => ({
898
+ ...nativeTargetSelection(pending.targets), command: pending.command,
899
+ }));
900
+ const previews = await readNativeGroups(pendingGroups, async (group) => {
901
+ try {
902
+ const preview = await nativeOperation(plan, group.pluginIds, group.platform, true, preparationRuntime, group.command, group.targets, catalogReadScope);
903
+ return { ok: true, preview };
904
+ }
905
+ catch (error) {
906
+ if (recoveryInterruptionCode(error, options.signal))
907
+ throw error;
908
+ return { ok: false, error };
909
+ }
910
+ }, options.signal);
911
+ for (const [index, group] of pendingGroups.entries()) {
912
+ const result = previews[index];
913
+ if (result.ok) {
914
+ const { preview } = result;
915
+ const nativeGroup = { ...group, preview };
916
+ plan.nativeGroups.push(nativeGroup);
917
+ nativeResults(plan, nativeGroup, preview, false);
918
+ plan.changes.push(...(preview.operationPlan?.changes ?? []));
919
+ const nativeToolChanges = preview.operationPlan ? operationPlanNativeToolChanges(preview.operationPlan) : [];
920
+ if (nativeToolChanges.length)
921
+ receipt.nativeToolChanges = [...(receipt.nativeToolChanges ?? []), ...nativeToolChanges];
922
+ for (const change of nativeToolChanges) {
923
+ for (const [verb, closure] of [['撤销', change.before], ['使用', change.after]]) {
924
+ if (closure)
925
+ plan.changes.push(...describeNativeToolClosure(closure).map((description) => `${verb}原生工具 · ${change.producer.sourceId}/${change.producer.pluginName} · ${description}`));
926
+ }
927
+ }
928
+ for (const override of preview.dependencyPlan?.scopeOverrides ?? []) {
929
+ if (options.dependencyScopeOverrides?.some((requested) => requested.pluginId === override.pluginId
930
+ && (!requested.platform || requested.platform === override.platform))) {
931
+ plan.changes.push(`推导的依赖提供位置:${override.pluginId}#${override.platform}=${override.scope}。`);
932
+ }
933
+ }
934
+ plan.warnings.push(...preview.warnings);
935
+ }
936
+ else {
937
+ const { error } = result;
938
+ if (error instanceof CatalogSourceInventoryIncompleteError) {
939
+ receipt.blockers.push(...error.inventory.errors.map(inventoryRecoveryDiagnostic));
940
+ }
941
+ for (const { pluginId, platform } of group.targets) {
942
+ block(pair(plan, pluginId, agentForPlatform(platform)), errorCode(error, 'nativePreparationFailed'));
943
+ }
944
+ }
945
+ }
946
+ const portableReads = receipt.requestedRoots.flatMap((pluginId) => {
947
+ const agents = receipt.targetResults.filter((target) => target.pluginId === pluginId
948
+ && !target.blockers.length && target.delivery?.kind === 'agent-skills').map((target) => target.agent).filter(isPortableAgent);
949
+ return agents.length ? [{ pluginId, agents }] : [];
950
+ });
951
+ const preparedGroups = await mapInstallReads(portableReads, async ({ pluginId, agents }) => {
952
+ try {
953
+ const prepared = command === 'cleanup' || command === 'uninstall'
954
+ ? await preparePortableCleanup({ scope: options.scope, context, selector: pluginId, agents, force: options.force, signal: options.signal })
955
+ : await preparePortableRecovery({ scope: options.scope, context, selector: pluginId, agents,
956
+ env: options.env, cliVersion: options.cliVersion, signal: options.signal,
957
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope, portableGenerations, portableRenderResults);
958
+ return { ok: true, prepared };
959
+ }
960
+ catch (error) {
961
+ if (recoveryInterruptionCode(error, options.signal))
962
+ throw error;
963
+ return { ok: false, agents, pluginId, code: errorCode(error, 'portablePreparationFailed') };
964
+ }
965
+ }, { signal: options.signal });
966
+ for (const result of preparedGroups) {
967
+ if (result.ok)
968
+ plan.portableGroups.push(result.prepared);
969
+ else
970
+ for (const agent of result.agents)
971
+ block(pair(plan, result.pluginId, agent), result.code);
972
+ }
973
+ for (const prepared of plan.portableGroups)
974
+ portableResults(plan, prepared);
975
+ preparePortablePreApplyAuthorization(plan);
976
+ if (command !== 'cleanup' && command !== 'uninstall') {
977
+ // Complete scope demand protects copies contributed by unselected roots and their dependencies.
978
+ const desiredAgents = new Set([...receipt.selection.agents,
979
+ ...(demand.preferences.state === 'valid' ? demand.preferences.value.targets : [])]);
980
+ const protection = await mapInstallReads(demand.roots ?? [], async (root) => {
981
+ const portableAgents = [...desiredAgents].filter(isPortableAgent).filter((agent) => root.plugin
982
+ && resolveDelivery(root.plugin.manifest, agent, options.scope)?.kind === 'agent-skills');
983
+ if (!portableAgents.length || plan.portableGroups.some((group) => group.options.selector === root.pluginId
984
+ && portableAgents.every((agent) => group.options.agents.includes(agent))))
985
+ return;
986
+ try {
987
+ const prepared = await preparePortableRecovery({ scope: options.scope, context, selector: root.pluginId,
988
+ env: options.env, agents: portableAgents, cliVersion: options.cliVersion, signal: options.signal,
989
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope, portableGenerations, portableRenderResults);
990
+ if (!prepared.globalBlockers.length)
991
+ return prepared;
992
+ }
993
+ catch (error) {
994
+ if (recoveryInterruptionCode(error, options.signal))
995
+ throw error;
996
+ // Missing current Portable evidence cannot protect historical residue.
997
+ }
998
+ }, { signal: options.signal });
999
+ plan.portableProtectionGroups = protection.filter((prepared) => prepared !== undefined);
1000
+ }
1001
+ options.signal?.throwIfAborted();
1002
+ await checkFootprints(plan);
1003
+ options.signal?.throwIfAborted();
1004
+ for (const prepared of [...plan.portableGroups, ...plan.portableProtectionGroups]) {
1005
+ delete prepared.options.signal;
1006
+ }
1007
+ plan.plannedImpact.outputs = !plan.blockExecution && (plan.nativeGroups.some((group) => (group.preview.operationPlan?.actions.length ?? 0) > 0
1008
+ && nativeGroupTargets(group).some(({ pluginId, platform }) => pair(plan, pluginId, agentForPlatform(platform))?.blockers.length === 0))
1009
+ || (plan.portableGroups.some((group) => group.targets.some((target) => pair(plan, group.options.selector, target.agent)?.blockers.length === 0
1010
+ && (group.mode === 'cleanup' || target.observation === 'absent' || target.observation === 'drifted'
1011
+ || (command === 'reinstall' && target.observation === 'satisfied' && target.ownership === 'aw'))))));
1012
+ completeReceipt(receipt);
1013
+ return plan;
1014
+ }
1015
+ catch (error) {
1016
+ await context.dispose();
1017
+ throw error;
1018
+ }
1019
+ }
1020
+ export async function activateRecoverySourcesAndReprepare(plan, execution = {}) {
1021
+ if (plan.sourceRefreshes.length === 0)
1022
+ return plan;
1023
+ const runtime = { ...plan.runtime, ...execution.runtime };
1024
+ const failures = new Map(plan.sourceRefreshFailures.map(({ sourceId, code }) => [sourceId, code]));
1025
+ try {
1026
+ for (const refresh of plan.sourceRefreshes) {
1027
+ try {
1028
+ await activateCatalogSourceGeneration({
1029
+ sourceId: refresh.sourceId,
1030
+ cliVersion: plan.options.cliVersion,
1031
+ cwd: plan.options.cwd,
1032
+ env: plan.options.env,
1033
+ impactConfirmed: true,
1034
+ expectedImpactDigest: refresh.impactDigest,
1035
+ expectedCandidate: refresh.candidate,
1036
+ expectedActive: refresh.previousActive,
1037
+ expectedConfigDigest: refresh.configDigest,
1038
+ runtime: runtime.catalogGenerationRuntime,
1039
+ });
1040
+ }
1041
+ catch (error) {
1042
+ const code = errorCode(error, 'catalogGenerationRefreshFailed');
1043
+ failures.set(refresh.sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
1044
+ }
1045
+ }
1046
+ const failedSourceIds = new Set(failures.keys());
1047
+ const originalExactTargets = plan.options.exactTargets
1048
+ ?? plan.receipt.targetResults.map(({ pluginId, agent }) => ({ pluginId, agent }));
1049
+ const exactTargets = failures.size > 0
1050
+ ? originalExactTargets.filter((target) => !failedSourceIds.has(parsePluginId(target.pluginId).sourceId))
1051
+ : plan.options.exactTargets;
1052
+ const next = await prepareRecovery(plan.command, plan.receipt.requestedRoots, {
1053
+ ...plan.options,
1054
+ all: false,
1055
+ refresh: false,
1056
+ ...(exactTargets ? { exactTargets } : {}),
1057
+ }, { ...runtime, preparedArtifactRenderResults: new Map() });
1058
+ if (failures.size === 0)
1059
+ return next;
1060
+ if (exactTargets?.length === 0) {
1061
+ next.receipt.blockers = next.receipt.blockers.filter((entry) => entry.code !== 'invalidExactTargets');
1062
+ next.blockExecution = true;
1063
+ }
1064
+ for (const [sourceId, code] of failures) {
1065
+ next.receipt.blockers.push({ code, message: `${sourceId}:${diagnostic('sourceRefreshFailed').message}` });
1066
+ }
1067
+ for (const target of plan.receipt.targetResults) {
1068
+ const sourceId = parsePluginId(target.pluginId).sourceId;
1069
+ const code = failures.get(sourceId);
1070
+ if (!code || next.receipt.targetResults.some((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent))
1071
+ continue;
1072
+ const failed = structuredClone(target);
1073
+ block(failed, code);
1074
+ next.receipt.targetResults.push(failed);
1075
+ }
1076
+ next.receipt = completeReceipt(next.receipt);
1077
+ return next;
1078
+ }
1079
+ finally {
1080
+ await plan.context.dispose();
1081
+ }
1082
+ }
1083
+ export function catalogRecheckDiagnostic(error, signal, sourceId) {
1084
+ if (recoveryInterruptionCode(error, signal)) {
1085
+ if (error === undefined)
1086
+ signal?.throwIfAborted();
1087
+ throw error;
1088
+ }
1089
+ const reasonCode = error instanceof CatalogGenerationError ? error.code : 'catalogReadFailed';
1090
+ sourceId ??= error instanceof CatalogGenerationError ? error.sourceId : undefined;
1091
+ return { ...diagnostic('operationReviewStale'), ...(sourceId ? { subject: { sourceId } } : {}),
1092
+ detail: { reasonCode } };
1093
+ }
1094
+ /** Report a safety stop without discarding any recorded execution evidence. */
1095
+ export function blockScopedRecoveryBeforeExecution(receipt, blocker) {
1096
+ receipt.blockers.push(blocker);
1097
+ for (const target of receipt.targetResults) {
1098
+ if (target.execution !== 'not-run' || target.satisfaction === 'excluded' || target.satisfaction === 'unsupported')
1099
+ continue;
1100
+ block(target, blocker.code, blocker);
1101
+ target.observation = 'unknown';
1102
+ target.content = 'unknown';
1103
+ target.satisfaction = 'unknown';
1104
+ }
1105
+ return completeReceipt(receipt);
1106
+ }
1107
+ async function recheckPortableRecovery(plan, groups = plan.portableGroups, progress, readScope) {
1108
+ const executable = groups.filter(({ options }) => !options.agents.every((agent) => pair(plan, options.selector, agent)?.blockers.length));
1109
+ const providers = new Set(executable.flatMap((group) => plan.options.portableProviderChecks?.get(group.options.selector) ?? []));
1110
+ const inspections = [
1111
+ ...executable,
1112
+ ...plan.portableProtectionGroups,
1113
+ ...providers,
1114
+ ];
1115
+ if (!inspections.length)
1116
+ return;
1117
+ const useClosureRecheck = readScope === undefined;
1118
+ const fallbackScope = readScope ?? new CatalogPreparationReadScope({ env: plan.context.env, signal: plan.runtime.signal });
1119
+ const closurePluginsBySource = new Map();
1120
+ if (useClosureRecheck) {
1121
+ for (const prepared of inspections) {
1122
+ if (prepared.mode !== 'deploy' || !prepared.options.catalogOperationContext)
1123
+ continue;
1124
+ const parsed = parsePluginId(prepared.options.selector);
1125
+ if (!parsed.sourceId)
1126
+ continue;
1127
+ let set = closurePluginsBySource.get(parsed.sourceId);
1128
+ if (!set) {
1129
+ set = new Set();
1130
+ closurePluginsBySource.set(parsed.sourceId, set);
1131
+ }
1132
+ set.add(parsed.pluginName);
1133
+ }
1134
+ }
1135
+ const active = new Map();
1136
+ const problems = await mapInstallReads(inspections, async (prepared) => {
1137
+ let current;
1138
+ let effectiveScope = fallbackScope;
1139
+ const parsedSelector = parsePluginId(prepared.options.selector);
1140
+ const sourceId = parsedSelector.sourceId;
1141
+ const reviewed = prepared.options.catalogOperationContext;
1142
+ if (sourceId && reviewed && prepared.mode === 'deploy') {
1143
+ try {
1144
+ const original = selectCatalogOperationContext(reviewed, [sourceId]);
1145
+ let pending = active.get(sourceId);
1146
+ if (!pending) {
1147
+ pending = useClosureRecheck
1148
+ ? recheckCatalogClosureForCommit({
1149
+ env: plan.context.env,
1150
+ signal: plan.runtime.signal,
1151
+ sourceId,
1152
+ original,
1153
+ closurePluginNames: [...(closurePluginsBySource.get(sourceId) ?? [parsedSelector.pluginName])],
1154
+ }).then((result) => ({ current: result.current, scope: result.readScope }))
1155
+ : fallbackScope.resolve({ sourceIds: [sourceId] }, true).then((ctx) => ({ current: ctx, scope: fallbackScope }));
1156
+ active.set(sourceId, pending);
1157
+ }
1158
+ const resolved = await pending;
1159
+ current = resolved.current;
1160
+ effectiveScope = resolved.scope;
1161
+ if (!catalogOperationBindingsMatch(original, current)) {
1162
+ return diagnostic('operationReviewStale');
1163
+ }
1164
+ }
1165
+ catch (error) {
1166
+ return catalogRecheckDiagnostic(error, plan.runtime.signal, sourceId);
1167
+ }
1168
+ }
1169
+ const checked = await inspectPortableRecovery({ ...prepared.options, catalogOperationContext: current,
1170
+ signal: plan.runtime.signal }, effectiveScope);
1171
+ // The provider ran first. Its original missing state is never sufficient for a consumer.
1172
+ if (providers.has(prepared) && !isHealthyPortableProvider(checked)
1173
+ || !await portableReviewMatches(prepared, checked, progress?.completed))
1174
+ return diagnostic('operationReviewStale');
1175
+ }, { signal: plan.runtime.signal });
1176
+ return problems.find((problem) => problem !== undefined);
1177
+ }
1178
+ async function executeNativeGroup(plan, group, nativeRuntime) {
1179
+ const { receipt } = plan;
1180
+ const running = new Set();
1181
+ try {
1182
+ const result = await nativeOperation(plan, group.pluginIds, group.platform, false, { ...nativeRuntime, onInstallTargetState(identity, state) {
1183
+ const target = identity.scope === plan.options.scope && identity.pluginId
1184
+ ? pair(plan, identity.pluginId, identity.platform) : undefined;
1185
+ if (target && state === 'running')
1186
+ running.add(target);
1187
+ else if (target)
1188
+ running.delete(target);
1189
+ nativeRuntime.onInstallTargetState?.(identity, state);
1190
+ }, expectedPlanFingerprint: group.preview.operationPlan?.planFingerprint }, group.command, nativeGroupTargets(group));
1191
+ receipt.outputsMayHaveChanged ||= result.rebuildResults.some((result) => result.actions.some((action) => action.name === 'stale.cleanup' || action.name === 'native.write' || action.name === 'artifacts.write'
1192
+ || action.name === 'recovery.cleanup' || action.name === 'cleanup.owned'))
1193
+ || (result.commandResults ?? []).some(({ action, state }) => action !== 'unchanged' || state === 'partial');
1194
+ nativeResults(plan, group, result, true);
1195
+ }
1196
+ catch (error) {
1197
+ if (error instanceof RebuildInterruptedError) {
1198
+ const recorded = error.result;
1199
+ const targets = nativeGroupTargets(group).filter(({ pluginId, platform }) => recorded.targetResults.some((entry) => entry.target.pluginId === pluginId && entry.target.platform === platform));
1200
+ nativeResults(plan, { ...group, targets }, recorded, true);
1201
+ receipt.outputsMayHaveChanged ||= recorded.rebuildResults.some((entry) => entry.actions.length > 0 || entry.deploymentReceipts?.some((deployment) => deployment.effects.some((effect) => effect.mutation !== 'none')))
1202
+ || recorded.commandResults?.some((command) => command.state === 'completed') === true;
1203
+ }
1204
+ const interruption = recoveryInterruptionCode(error, nativeRuntime.signal);
1205
+ if (interruption) {
1206
+ for (const target of running) {
1207
+ target.execution = 'partial';
1208
+ target.observation = 'unknown';
1209
+ target.content = 'unknown';
1210
+ block(target, interruption);
1211
+ receipt.outputsMayHaveChanged = true;
1212
+ }
1213
+ throw error;
1214
+ }
1215
+ const code = errorCode(error, 'nativeRecoveryFailed');
1216
+ receipt.outputsMayHaveChanged ||= code !== 'preApplyAuthorizationRequired';
1217
+ for (const { pluginId, platform } of nativeGroupTargets(group)) {
1218
+ const target = pair(plan, pluginId, agentForPlatform(platform));
1219
+ target.execution = 'failed';
1220
+ block(target, code);
1221
+ }
1222
+ }
1223
+ }
1224
+ async function executePortableGroups(plan, groups, nativeRuntime, progress, jointChecked = false) {
1225
+ const { receipt } = plan;
1226
+ for (const prepared of groups) {
1227
+ let started = false;
1228
+ const onStart = () => {
1229
+ if (started)
1230
+ return;
1231
+ started = true;
1232
+ try {
1233
+ nativeRuntime.onInstallTargetState?.({ pluginId: prepared.options.selector,
1234
+ platform: 'generic', scope: plan.options.scope }, 'running');
1235
+ }
1236
+ catch { /* Display callbacks don't control execution. */ }
1237
+ };
1238
+ const providers = plan.options.portableProviderChecks?.get(prepared.options.selector);
1239
+ const checkPrewrite = jointChecked || providers?.length ? () => recheckPortableRecovery(plan, [prepared], progress) : undefined;
1240
+ const agents = [];
1241
+ for (const agent of prepared.options.agents) {
1242
+ if (pair(plan, prepared.options.selector, agent).blockers.length)
1243
+ continue;
1244
+ const outcomes = prepared.targets.filter((entry) => entry.agent === agent).map((entry) => {
1245
+ const failed = progress.failed.find((failure) => failure.logicalIdentity === prepared.logicalIdentity
1246
+ && failure.outcome.physicalPath === entry.physicalPath && failure.outcome.expectedDigest === entry.expectedDigest
1247
+ && failure.outcome.providerPluginId === entry.providerPluginId);
1248
+ return failed ? { ...failed.outcome, agent } : { ...entry, execution: 'not-run', blockers: [] };
1249
+ });
1250
+ if (outcomes.some((entry) => entry.execution === 'failed')) {
1251
+ portableOutcomes(plan, prepared, agent, outcomes, []);
1252
+ continue;
1253
+ }
1254
+ const hasScript = plan.preApplyAuthorization?.some((target) => target.platform === agent
1255
+ && portablePluginClosure(plan, prepared).some((plugin) => plugin.pluginId === target.pluginId));
1256
+ const preApply = async () => {
1257
+ onStart();
1258
+ const stale = await checkPrewrite?.();
1259
+ if (stale) {
1260
+ receipt.blockers.push(stale);
1261
+ return stale.code;
1262
+ }
1263
+ return executePortablePreApply(plan, prepared, agent, nativeRuntime);
1264
+ };
1265
+ const preApplyFailure = !hasScript ? undefined : nativeRuntime.installAdmission
1266
+ ? await nativeRuntime.installAdmission.run([{ kind: 'exclusive' }], preApply, nativeRuntime.signal) : await preApply();
1267
+ if (preApplyFailure) {
1268
+ const target = pair(plan, prepared.options.selector, agent);
1269
+ portableOutcomes(plan, prepared, agent, prepared.targets.filter((entry) => entry.agent === agent)
1270
+ .map((entry) => unobservedPortableTarget(entry, preApplyFailure)), [preApplyFailure]);
1271
+ if (preApplyFailure !== 'operationReviewStale')
1272
+ target.execution = 'failed';
1273
+ target.recoveryActions = [`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent}`
1274
+ + (preApplyFailure === 'operationReviewStale' ? '' : ' --yes')];
1275
+ continue;
1276
+ }
1277
+ agents.push(agent);
1278
+ }
1279
+ if (!agents.length)
1280
+ continue;
1281
+ let interruption;
1282
+ const result = await executePortableRecovery({ prepared, token: nativeRuntime.awHomeMutationToken, authorizeUpdate: plan.options.yes,
1283
+ action: plan.command === 'install' ? 'sync' : plan.command, force: plan.options.force,
1284
+ targets: prepared.targets.filter((target) => agents.includes(target.agent)).map(({ skill, agent }) => ({ skill, agent })),
1285
+ progress, checkPrewrite, readProviders: providers, onStart, admission: nativeRuntime.installAdmission, signal: nativeRuntime.signal }).catch((error) => {
1286
+ if (!(error instanceof PortableInterruptedError))
1287
+ throw error;
1288
+ interruption = error;
1289
+ return error.result;
1290
+ });
1291
+ if (result.reviewProblem)
1292
+ receipt.blockers.push(result.reviewProblem);
1293
+ receipt.outputsMayHaveChanged ||= result.outputsMayHaveChanged;
1294
+ for (const agent of agents) {
1295
+ portableOutcomes(plan, prepared, agent, result.targets.filter((entry) => entry.agent === agent), result.globalBlockers);
1296
+ if (interruption && result.outputsMayHaveChanged) {
1297
+ const target = pair(plan, prepared.options.selector, agent);
1298
+ if (target.execution === 'failed')
1299
+ target.execution = 'partial';
1300
+ }
1301
+ }
1302
+ if (interruption)
1303
+ throw interruption.cause;
1304
+ }
1305
+ }
1306
+ /** The joint coordinator holds the write lock and has checked this complete child against Review. */
1307
+ export async function executeCheckedScopedInstall(child, execution) {
1308
+ if (!execution.runtime.awHomeMutationToken || child.command !== 'sync' && child.command !== 'reinstall') {
1309
+ throw new Error('checkedScopedInstallUnavailable');
1310
+ }
1311
+ const selected = (pluginId) => !execution.pluginIds || execution.pluginIds.includes(pluginId);
1312
+ const receipt = structuredClone({ ...child.receipt,
1313
+ targetResults: child.receipt.targetResults.filter((target) => selected(target.pluginId)),
1314
+ requestedRoots: child.receipt.requestedRoots.filter(selected),
1315
+ });
1316
+ const plan = { ...child, receipt, runtime: { ...child.runtime, ...execution.runtime }, options: { ...child.options, yes: execution.yes ?? child.options.yes } };
1317
+ if (receipt.nativeToolChanges?.length && plan.options.yes !== true) {
1318
+ receipt.blockers.push(diagnostic('nativeToolAuthorizationRequired'));
1319
+ return completeReceipt(receipt);
1320
+ }
1321
+ if (plan.blockExecution)
1322
+ return completeReceipt(receipt);
1323
+ const runtime = plan.runtime;
1324
+ try {
1325
+ for (const group of plan.nativeGroups) {
1326
+ const targets = nativeGroupTargets(group);
1327
+ const blocked = new Map();
1328
+ for (const { pluginId, platform } of targets) {
1329
+ const code = pair(plan, pluginId, platform)?.blockers[0]?.code;
1330
+ if (code)
1331
+ blocked.set([pluginId, platform, plan.options.scope].join('\0'), code);
1332
+ }
1333
+ if (blocked.size === targets.length)
1334
+ continue;
1335
+ await executeNativeGroup(plan, group, { ...runtime, nativeInstallBlockers: blocked });
1336
+ }
1337
+ await executePortableGroups(plan, plan.portableGroups.filter((group) => selected(group.options.selector)), runtime, execution.portableProgress, true);
1338
+ return completeReceipt(receipt);
1339
+ }
1340
+ catch (error) {
1341
+ const code = recoveryInterruptionCode(error, runtime.signal);
1342
+ if (!code)
1343
+ throw error;
1344
+ receipt.blockers.push(diagnostic(code));
1345
+ throw new RecoveryInterruptedError(completeReceipt(receipt), error);
1346
+ }
1347
+ }
1348
+ export async function executeScopedRecovery(plan, execution = {}) {
1349
+ if (plan.sourceRefreshes.length > 0) {
1350
+ const receipt = structuredClone(plan.receipt);
1351
+ receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
1352
+ await plan.context.dispose();
1353
+ return completeReceipt(receipt);
1354
+ }
1355
+ const receipt = structuredClone(plan.receipt);
1356
+ plan = { ...plan, receipt, options: { ...plan.options, yes: execution.yes ?? plan.options.yes },
1357
+ runtime: { ...plan.runtime, ...execution.runtime } };
1358
+ try {
1359
+ if (receipt.nativeToolChanges?.length && plan.options.yes !== true) {
1360
+ receipt.blockers.push(diagnostic('nativeToolAuthorizationRequired'));
1361
+ return completeReceipt(receipt);
1362
+ }
1363
+ const freshContext = await createScopeContext({ scope: plan.options.scope,
1364
+ cwd: plan.context.callerCwd, env: plan.options.env });
1365
+ const environmentStable = freshContext.awHome === plan.context.awHome
1366
+ && freshContext.generationRoot === plan.context.generationRoot
1367
+ && freshContext.projectKey === plan.context.projectKey
1368
+ && JSON.stringify(freshContext.targetHomes) === JSON.stringify(plan.context.targetHomes);
1369
+ await freshContext.dispose();
1370
+ const executionCwdStable = plan.options.scope !== 'user'
1371
+ || await assertNeutralAncestorChain(plan.context.executionCwd)
1372
+ .then((value) => value === plan.context.executionCwd, () => false);
1373
+ if (!environmentStable || !executionCwdStable) {
1374
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1375
+ return completeReceipt(receipt);
1376
+ }
1377
+ return await withAwHomeMutationLock({ env: plan.options.env, token: plan.runtime.awHomeMutationToken,
1378
+ action: async (token) => {
1379
+ const catalogReadScope = new CatalogPreparationReadScope({ env: plan.context.env, signal: plan.runtime.signal });
1380
+ const reviewedCatalog = plan.options.catalogOperationContext;
1381
+ let catalogOperationContext = reviewedCatalog;
1382
+ if (plan.command !== 'cleanup' && reviewedCatalog) {
1383
+ try {
1384
+ catalogOperationContext = await catalogReadScope.rebind(reviewedCatalog);
1385
+ }
1386
+ catch (error) {
1387
+ return blockScopedRecoveryBeforeExecution(receipt, catalogRecheckDiagnostic(error, plan.runtime.signal));
1388
+ }
1389
+ }
1390
+ const [actualIntent, current] = await Promise.all([
1391
+ observeIntent(plan.options),
1392
+ readDemand({ ...plan.options, catalogReadScope, catalogOperationContext, signal: plan.runtime.signal, preferences: undefined,
1393
+ ...(plan.declaration || plan.options.demandOverride ? { intent: plan.demand.intent } : {}) }),
1394
+ ]);
1395
+ if (plan.command !== 'cleanup' && current.errors.some((entry) => entry.code === 'catalogReadFailed')) {
1396
+ return blockScopedRecoveryBeforeExecution(receipt, catalogRecheckDiagnostic(undefined, plan.runtime.signal));
1397
+ }
1398
+ const catalogStable = plan.command === 'cleanup'
1399
+ ? current.catalogOperationContext?.generationSetDigest === plan.demand.catalogOperationContext?.generationSetDigest
1400
+ : catalogOperationBindingsMatch(plan.demand.catalogOperationContext, current.catalogOperationContext);
1401
+ if (intentEvidence(actualIntent) !== plan.originalIntent || preferenceEvidence(current) !== plan.preferencesEvidence || !catalogStable) {
1402
+ return blockScopedRecoveryBeforeExecution(receipt, diagnostic('operationReviewStale'));
1403
+ }
1404
+ const previewManager = plan.nativeGroups.map((group) => group.preview.codexManagerPreview)
1405
+ .find((entry) => entry?.state === 'system');
1406
+ const session = plan.runtime.codexObservationSession ?? (plan.nativeGroups.length ? await createCodexNativeObservationSession({
1407
+ exactCwd: plan.context.executionCwd, env: plan.context.env,
1408
+ runner: plan.runtime.nativeCliRunner ?? getDefaultNativeCliRunner(),
1409
+ manager: plan.runtime.codexManager ?? (previewManager?.state === 'system'
1410
+ ? previewManager.manager : undefined),
1411
+ }) : undefined);
1412
+ const nativeRuntime = { ...plan.runtime, awHomeMutationToken: token,
1413
+ managedCommandProducerCache: plan.runtime.managedCommandProducerCache
1414
+ ?? new Map(),
1415
+ ...(session ? { codexObservationSession: session } : {}) };
1416
+ try {
1417
+ // The lock has supplied fresh, bound Active evidence. Reuse it only for
1418
+ // this recheck, not the subsequent writers or their prewrite checks.
1419
+ const checkedPlan = { ...plan, demand: { ...plan.demand, catalogOperationContext: current.catalogOperationContext } };
1420
+ // Freeze every backend before the first declaration or output write.
1421
+ const recheckedGroups = await readNativeGroups(plan.nativeGroups, async (group) => {
1422
+ const targets = nativeGroupTargets(group);
1423
+ const executable = targets.filter(({ pluginId, platform }) => !pair(plan, pluginId, agentForPlatform(platform)).blockers.length);
1424
+ if (!executable.length)
1425
+ return;
1426
+ const checked = await nativeOperation(checkedPlan, group.pluginIds, group.platform, true, nativeRuntime, group.command, targets, catalogReadScope);
1427
+ if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint)
1428
+ return 'stale';
1429
+ const selection = nativeTargetSelection(executable);
1430
+ const preview = executable.length === targets.length ? checked
1431
+ : await nativeOperation(checkedPlan, selection.pluginIds, selection.platform, true, nativeRuntime, group.command, executable, catalogReadScope);
1432
+ return { ...group, ...selection, preview };
1433
+ }, nativeRuntime.signal);
1434
+ if (recheckedGroups.includes('stale')) {
1435
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1436
+ return completeReceipt(receipt);
1437
+ }
1438
+ const executableNativeGroups = recheckedGroups.filter((group) => group !== undefined && group !== 'stale');
1439
+ const portableProgress = execution.portableProgress ?? { completed: [], failed: [] };
1440
+ const portableBlocker = await recheckPortableRecovery(plan, plan.portableGroups, portableProgress, catalogReadScope);
1441
+ if (portableBlocker) {
1442
+ receipt.blockers.push(portableBlocker);
1443
+ return completeReceipt(receipt);
1444
+ }
1445
+ for (const residue of plan.portableResidues) {
1446
+ const checked = await inspectPortableResidue({ scope: plan.options.scope, context: plan.context,
1447
+ selector: residue.pluginId, env: plan.options.env, agents: residue.agents.filter(isPortableAgent),
1448
+ retainedTargets: residue.retainedTargets }).catch(() => undefined);
1449
+ if (!checked || JSON.stringify(checked) !== JSON.stringify(residue.observation)) {
1450
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1451
+ return completeReceipt(receipt);
1452
+ }
1453
+ }
1454
+ if (plan.declaration) {
1455
+ const declared = await addRequirements({ ...plan.options, selectors: plan.declaration, token });
1456
+ receipt.declarationChanged = declared.changed;
1457
+ receipt.blockers.push(...declared.errors);
1458
+ plan.blockExecution ||= declared.errors.length > 0;
1459
+ const intent = await observeIntent(plan.options);
1460
+ receipt.intent = { ...receipt.intent, state: intent.state, ...('digest' in intent ? { digest: intent.digest } : {}) };
1461
+ }
1462
+ if (plan.blockExecution)
1463
+ return completeReceipt(receipt);
1464
+ if (plan.preferences) {
1465
+ try {
1466
+ const saved = await writePreferences({ ...plan.options, token }, plan.preferences);
1467
+ receipt.preferencesChanged = saved.changed;
1468
+ }
1469
+ catch (error) {
1470
+ receipt.blockers.push(diagnostic(errorCode(error, 'deploymentPreferencesWriteFailed')));
1471
+ return completeReceipt(receipt);
1472
+ }
1473
+ }
1474
+ for (const group of executableNativeGroups)
1475
+ await executeNativeGroup(plan, group, nativeRuntime);
1476
+ await executePortableGroups(plan, plan.portableGroups, nativeRuntime, portableProgress);
1477
+ for (const { kind, pluginId, observation } of plan.portableResidues) {
1478
+ if (kind !== 'cleanup')
1479
+ continue;
1480
+ if (observation.state === 'absent')
1481
+ continue;
1482
+ const targets = receipt.targetResults.filter((target) => target.pluginId === pluginId
1483
+ && (observation.targets.some((entry) => entry.agent === target.agent)
1484
+ || (observation.unknownAgents?.some((item) => item === target.agent)
1485
+ ?? (observation.blockers.length > 0))));
1486
+ for (const target of targets) {
1487
+ block(target, isPortableAgent(target.agent) && observation.unknownAgents?.some((item) => item === target.agent)
1488
+ || !observation.targets.some((entry) => entry.agent === target.agent)
1489
+ ? 'portableObservationFailed' : 'backend-action-unsupported');
1490
+ if (target.execution === 'applied')
1491
+ target.execution = 'partial';
1492
+ target.backend = { ...(target.delivery?.kind === 'native' ? { native: target.backend } : { portable: target.backend }), portableRemaining: {
1493
+ state: observation.state, targets: observation.targets.map(({ skill, agent, physicalPath }) => ({ skill, agent, physicalPath: displayPortablePath(plan, physicalPath) })),
1494
+ } };
1495
+ target.recoveryActions = [...new Set([...(target.recoveryActions ?? []), ...portableRecoveryActions(plan, pluginId, observation.targets.filter((entry) => entry.agent === target.agent))])];
1496
+ }
1497
+ }
1498
+ if (receipt.declarationChanged) {
1499
+ const intent = await observeIntent(plan.options);
1500
+ receipt.intent = { state: intent.state, ...('digest' in intent ? { digest: intent.digest } : {}),
1501
+ roots: intent.state === 'valid' ? intent.value.roots.map((root) => root.pluginId) : null };
1502
+ }
1503
+ return completeReceipt(receipt);
1504
+ }
1505
+ finally {
1506
+ if (!plan.runtime.codexObservationSession)
1507
+ await session?.dispose();
1508
+ }
1509
+ } });
1510
+ }
1511
+ catch (error) {
1512
+ const code = recoveryInterruptionCode(error, plan.runtime.signal);
1513
+ if (!code)
1514
+ throw error;
1515
+ receipt.blockers.push(diagnostic(code));
1516
+ for (const target of receipt.targetResults)
1517
+ if (target.execution === 'not-run')
1518
+ block(target, code);
1519
+ throw new RecoveryInterruptedError(completeReceipt(receipt), error);
1520
+ }
1521
+ finally {
1522
+ await plan.context.dispose();
1523
+ }
1524
+ }
1525
+ export async function runRecovery(command, selectors, options, runtime = {}) {
1526
+ let plan = await prepareRecovery(command, selectors, options, runtime);
1527
+ if (plan.sourceRefreshes.length > 0) {
1528
+ if (options.yes !== true) {
1529
+ if (!options.interactive || !options.prompt?.confirm) {
1530
+ plan.receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
1531
+ await plan.context.dispose();
1532
+ return completeReceipt(plan.receipt);
1533
+ }
1534
+ const response = await options.prompt.confirm({ defaultValue: false, message: [
1535
+ `先更新来源:${plan.sourceRefreshes.map((entry) => entry.sourceId).join('、')}。`,
1536
+ ...plan.changes,
1537
+ ...plan.warnings,
1538
+ '确认后只激活已检查的来源候选;随后会基于新的 Active 重新准备插件恢复,并再次确认。',
1539
+ ].join('\n') });
1540
+ if (response.cancelled || response.value !== true) {
1541
+ plan.receipt.blockers.push(diagnostic('operationCancelled'));
1542
+ await plan.context.dispose();
1543
+ return completeReceipt(plan.receipt);
1544
+ }
1545
+ }
1546
+ plan = await activateRecoverySourcesAndReprepare(plan, { runtime });
1547
+ }
1548
+ if (options.interactive && options.yes !== true && options.prompt?.confirm
1549
+ && (plan.declaration || plan.receipt.targetResults.some((target) => target.blockers.length === 0))) {
1550
+ const response = await options.prompt.confirm({ defaultValue: false, message: [
1551
+ `${options.scope} 请求:${plan.receipt.requestedRoots.join('、')};Agent:${plan.receipt.selection.agents.join('、') || '未选择'}。`,
1552
+ ...plan.receipt.targetResults.map((target) => `${target.pluginId} / ${target.agent}:${target.blockers.length
1553
+ ? `受阻(${target.blockers.map((entry) => entry.code).join('、')})` : '可执行'}`),
1554
+ ...plan.changes, ...plan.warnings, ...plan.receipt.blockers.map((entry) => entry.message),
1555
+ '是否执行以上可处理变更及计划中的 preApply 脚本?',
1556
+ ].join('\n') });
1557
+ if (response.cancelled || response.value !== true) {
1558
+ plan.receipt.blockers.push(diagnostic('operationCancelled'));
1559
+ await plan.context.dispose();
1560
+ return completeReceipt(plan.receipt);
1561
+ }
1562
+ return executeRecovery(plan, { yes: true, runtime: { preApplyConfirmed: true } });
1563
+ }
1564
+ return executeRecovery(plan);
1565
+ }
1566
+ export async function prepareRecovery(command, selectors, options, runtime = {}) {
1567
+ const preparedResults = runtime.preparedArtifactRenderResults ?? new Map();
1568
+ runtime = { ...runtime, preparedArtifactRenderResults: preparedResults };
1569
+ return measureRecoveryPerformanceStage(runtime, 'recovery.plan', async () => {
1570
+ try {
1571
+ if (command === 'cleanup' && !options.scope)
1572
+ throw new Error('cleanupScopeRequired');
1573
+ const plan = command === 'cleanup'
1574
+ ? await prepareScopedRecovery(command, selectors, { ...options, scope: options.scope }, runtime)
1575
+ : await prepareJointRecovery(command, selectors, options, runtime);
1576
+ const dispose = plan.context.dispose;
1577
+ let disposed = false;
1578
+ plan.context.dispose = async () => {
1579
+ if (disposed)
1580
+ return;
1581
+ disposed = true;
1582
+ try {
1583
+ await dispose();
1584
+ }
1585
+ finally {
1586
+ await disposePreparedPlatformRebuildSession(preparedResults);
1587
+ }
1588
+ };
1589
+ return plan;
1590
+ }
1591
+ catch (error) {
1592
+ await disposePreparedPlatformRebuildSession(preparedResults);
1593
+ throw error;
1594
+ }
1595
+ });
1596
+ }
1597
+ export async function executeRecovery(plan, execution = {}) {
1598
+ return plan.joint ? executeJointRecovery(plan, execution) : executeScopedRecovery(plan, execution);
1599
+ }
1600
+ /** Review evidence uses existing backend fingerprints and observation digests; it is not stored state. */
1601
+ export function describeRecoveryPlan(plan) {
1602
+ const describe = (child) => ({ scope: child.options.scope, targets: child.receipt.requestedTargets,
1603
+ native: child.nativeGroups.map((group) => group.preview.operationPlan?.planFingerprint),
1604
+ preApplyAuthorization: child.preApplyAuthorization,
1605
+ nativeActivationOnlyTargets: child.options.nativeActivationOnlyTargets,
1606
+ nativePlannedRetirements: child.options.nativePlannedRetirements,
1607
+ portable: child.portableGroups.map((group) => group.evidenceDigest),
1608
+ inheritedPortable: child.options.portableProviderChecks?.size
1609
+ ? [...child.options.portableProviderChecks].map(([root, providers]) => [root, providers.map((item) => item.evidenceDigest)]) : undefined,
1610
+ protectedPortable: child.portableProtectionGroups.map((group) => group.evidenceDigest),
1611
+ residue: child.portableResidues, blockers: child.receipt.blockers,
1612
+ targetBlockers: child.receipt.targetResults.map((target) => target.blockers),
1613
+ environment: { homes: child.context.targetHomes, projectRoot: child.context.projectRoot, awHome: child.context.awHome },
1614
+ });
1615
+ return { inputs: plan.joint?.evidence ?? [plan.originalIntent, plan.preferencesEvidence],
1616
+ catalog: plan.command === 'install' ? plan.demand.catalogOperationContext?.generationSetDigest : undefined,
1617
+ pendingUserSkills: plan.joint?.pendingUserSkills,
1618
+ providerRetirements: plan.joint ? [...plan.joint.providerRetirements] : undefined,
1619
+ command: plan.command, dependencyCleanupTargets: plan.dependencyCleanupTargets,
1620
+ declaration: plan.joint?.declaration, packages: plan.runtime.configApplyPackages ? { targets: plan.runtime.configApplyPackages.targets, evidence: plan.runtime.configApplyPackages.evidence } : undefined,
1621
+ portableCommandWithdrawals: plan.portableCommandWithdrawals, blockers: plan.receipt.blockers,
1622
+ children: (plan.joint?.children ?? [plan]).map(describe) };
1623
+ }
1624
+ //# sourceMappingURL=coordinator.js.map