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

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