@lesliechan721/aw 0.1.0-beta.8 → 0.1.0-beta.81

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 (802) hide show
  1. package/dist/authoring/assets/aw-config.mjs +100 -501
  2. package/dist/authoring/assets/aw-config.mjs.map +1 -1
  3. package/dist/authoring/assets/aw-runtime-config.d.mts +13 -0
  4. package/dist/authoring/assets/aw-runtime-config.mjs +221 -0
  5. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -0
  6. package/dist/authoring/scripts/add-skill.mjs +17 -40
  7. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  8. package/dist/authoring/scripts/init-plugin.mjs +74 -98
  9. package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
  10. package/dist/authoring/scripts/lib/plugin-root.mjs +4 -4
  11. package/dist/authoring/scripts/lib/plugin-root.mjs.map +1 -1
  12. package/dist/authoring/scripts/lib/plugin-version-check.d.mts +1 -0
  13. package/dist/authoring/scripts/lib/plugin-version-check.mjs +230 -9
  14. package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
  15. package/dist/authoring/scripts/lib/skill-scaffold.d.mts +79 -92
  16. package/dist/authoring/scripts/lib/skill-scaffold.mjs +103 -127
  17. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  18. package/dist/authoring/scripts/remove-plugin.mjs +2 -2
  19. package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
  20. package/dist/authoring/scripts/validate-plugin.mjs +490 -2841
  21. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  22. package/dist/authoring/scripts/validate-skill.mjs +1 -1
  23. package/dist/native-runtime/reader-runtime.mjs +34 -0
  24. package/dist/native-runtime/reader.d.mts +6 -0
  25. package/dist/native-runtime/reader.mjs +11 -0
  26. package/dist/scripts/aw-skill-eval-materializer.d.ts +30 -0
  27. package/dist/scripts/aw-skill-eval-materializer.js +278 -0
  28. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -0
  29. package/dist/scripts/bundle-plugins.d.ts +1 -0
  30. package/dist/scripts/bundle-plugins.js +27 -8
  31. package/dist/scripts/bundle-plugins.js.map +1 -1
  32. package/dist/scripts/plugin-staging.d.ts +7 -8
  33. package/dist/scripts/plugin-staging.js +16 -15
  34. package/dist/scripts/plugin-staging.js.map +1 -1
  35. package/dist/scripts/plugin-test-reporter.d.mts +2 -0
  36. package/dist/scripts/plugin-test-reporter.mjs +21 -0
  37. package/dist/scripts/plugin-test-reporter.mjs.map +1 -0
  38. package/dist/scripts/test-plugin-scripts.d.ts +5 -0
  39. package/dist/scripts/test-plugin-scripts.js +273 -78
  40. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  41. package/dist/scripts/test-workers.d.mts +24 -0
  42. package/dist/scripts/test-workers.mjs +59 -0
  43. package/dist/scripts/test-workers.mjs.map +1 -0
  44. package/dist/src/adapters/helpers.d.ts +7 -0
  45. package/dist/src/adapters/helpers.js.map +1 -1
  46. package/dist/src/authoring/workspace-commands.d.ts +5 -1
  47. package/dist/src/authoring/workspace-commands.js +7 -2
  48. package/dist/src/authoring/workspace-commands.js.map +1 -1
  49. package/dist/src/commands/aw-capabilities.d.ts +2 -2
  50. package/dist/src/commands/aw-capabilities.js +41 -29
  51. package/dist/src/commands/aw-capabilities.js.map +1 -1
  52. package/dist/src/commands/catalog-dev-source.d.ts +58 -13
  53. package/dist/src/commands/catalog-dev-source.js +549 -305
  54. package/dist/src/commands/catalog-dev-source.js.map +1 -1
  55. package/dist/src/commands/catalog-generation.d.ts +14 -19
  56. package/dist/src/commands/catalog-generation.js +5 -10
  57. package/dist/src/commands/catalog-generation.js.map +1 -1
  58. package/dist/src/commands/catalog-publication-inspection.d.ts +70 -30
  59. package/dist/src/commands/catalog-publication-inspection.js +511 -91
  60. package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
  61. package/dist/src/commands/catalog-publication-journal.d.ts +68 -0
  62. package/dist/src/commands/catalog-publication-journal.js +292 -0
  63. package/dist/src/commands/catalog-publication-journal.js.map +1 -0
  64. package/dist/src/commands/catalog-publication-target.d.ts +2 -1
  65. package/dist/src/commands/catalog-publication-target.js +37 -2
  66. package/dist/src/commands/catalog-publication-target.js.map +1 -1
  67. package/dist/src/commands/catalog-publish.d.ts +82 -15
  68. package/dist/src/commands/catalog-publish.js +722 -219
  69. package/dist/src/commands/catalog-publish.js.map +1 -1
  70. package/dist/src/commands/catalog-source.d.ts +55 -35
  71. package/dist/src/commands/catalog-source.js +298 -148
  72. package/dist/src/commands/catalog-source.js.map +1 -1
  73. package/dist/src/commands/catalog-status.d.ts +6 -26
  74. package/dist/src/commands/catalog-status.js +9 -147
  75. package/dist/src/commands/catalog-status.js.map +1 -1
  76. package/dist/src/commands/catalog-store.d.ts +104 -0
  77. package/dist/src/commands/catalog-store.js +685 -0
  78. package/dist/src/commands/catalog-store.js.map +1 -0
  79. package/dist/src/commands/catalog-workspace-resolution.d.ts +17 -0
  80. package/dist/src/commands/catalog-workspace-resolution.js +57 -0
  81. package/dist/src/commands/catalog-workspace-resolution.js.map +1 -0
  82. package/dist/src/commands/console.js +32 -20
  83. package/dist/src/commands/console.js.map +1 -1
  84. package/dist/src/commands/dependency-operation-plan.d.ts +52 -15
  85. package/dist/src/commands/dependency-operation-plan.js +289 -7
  86. package/dist/src/commands/dependency-operation-plan.js.map +1 -1
  87. package/dist/src/commands/deployment-confirmation.d.ts +4 -0
  88. package/dist/src/commands/deployment-confirmation.js +20 -0
  89. package/dist/src/commands/deployment-confirmation.js.map +1 -0
  90. package/dist/src/commands/init.d.ts +5 -11
  91. package/dist/src/commands/init.js +30 -51
  92. package/dist/src/commands/init.js.map +1 -1
  93. package/dist/src/commands/intent-command.d.ts +32 -0
  94. package/dist/src/commands/intent-command.js +171 -0
  95. package/dist/src/commands/intent-command.js.map +1 -0
  96. package/dist/src/commands/managed-commands.d.ts +35 -0
  97. package/dist/src/commands/managed-commands.js +361 -0
  98. package/dist/src/commands/managed-commands.js.map +1 -0
  99. package/dist/src/commands/offline-cleanup-evidence.d.ts +46 -0
  100. package/dist/src/commands/offline-cleanup-evidence.js +158 -10
  101. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
  102. package/dist/src/commands/operation-plan.d.ts +190 -0
  103. package/dist/src/commands/operation-plan.js +99 -0
  104. package/dist/src/commands/operation-plan.js.map +1 -0
  105. package/dist/src/commands/operation-planner.d.ts +47 -0
  106. package/dist/src/commands/operation-planner.js +142 -0
  107. package/dist/src/commands/operation-planner.js.map +1 -0
  108. package/dist/src/commands/options.d.ts +16 -20
  109. package/dist/src/commands/options.js +94 -41
  110. package/dist/src/commands/options.js.map +1 -1
  111. package/dist/src/commands/plugin-capabilities.js +88 -45
  112. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  113. package/dist/src/commands/public-config-confirmation.d.ts +8 -0
  114. package/dist/src/commands/public-config-confirmation.js +56 -0
  115. package/dist/src/commands/public-config-confirmation.js.map +1 -0
  116. package/dist/src/commands/public-interruption.d.ts +9 -0
  117. package/dist/src/commands/public-interruption.js +23 -0
  118. package/dist/src/commands/public-interruption.js.map +1 -0
  119. package/dist/src/commands/public-lifecycle-result.d.ts +102 -0
  120. package/dist/src/commands/public-lifecycle-result.js +307 -0
  121. package/dist/src/commands/public-lifecycle-result.js.map +1 -0
  122. package/dist/src/commands/public-lifecycle.d.ts +28 -0
  123. package/dist/src/commands/public-lifecycle.js +492 -0
  124. package/dist/src/commands/public-lifecycle.js.map +1 -0
  125. package/dist/src/commands/public-plugin-query.d.ts +16 -0
  126. package/dist/src/commands/public-plugin-query.js +193 -0
  127. package/dist/src/commands/public-plugin-query.js.map +1 -0
  128. package/dist/src/commands/rebuild-command.d.ts +166 -28
  129. package/dist/src/commands/rebuild-command.js +3745 -813
  130. package/dist/src/commands/rebuild-command.js.map +1 -1
  131. package/dist/src/commands/rebuild-integration.d.ts +137 -25
  132. package/dist/src/commands/rebuild-integration.js +1343 -2535
  133. package/dist/src/commands/rebuild-integration.js.map +1 -1
  134. package/dist/src/commands/rebuild-operations.d.ts +73 -22
  135. package/dist/src/commands/rebuild-operations.js +313 -216
  136. package/dist/src/commands/rebuild-operations.js.map +1 -1
  137. package/dist/src/commands/rebuild-platform-integration.d.ts +62 -0
  138. package/dist/src/commands/rebuild-platform-integration.js +1317 -0
  139. package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
  140. package/dist/src/commands/reconcile-operation-plan.d.ts +28 -0
  141. package/dist/src/commands/reconcile-operation-plan.js +47 -0
  142. package/dist/src/commands/reconcile-operation-plan.js.map +1 -0
  143. package/dist/src/commands/review-inspection.d.ts +60 -0
  144. package/dist/src/commands/review-inspection.js +436 -0
  145. package/dist/src/commands/review-inspection.js.map +1 -0
  146. package/dist/src/commands/review-preparation.d.ts +51 -0
  147. package/dist/src/commands/review-preparation.js +400 -0
  148. package/dist/src/commands/review-preparation.js.map +1 -0
  149. package/dist/src/commands/runtime.d.ts +6 -6
  150. package/dist/src/commands/runtime.js +44 -24
  151. package/dist/src/commands/runtime.js.map +1 -1
  152. package/dist/src/commands/skill-eval.d.ts +41 -0
  153. package/dist/src/commands/skill-eval.js +407 -0
  154. package/dist/src/commands/skill-eval.js.map +1 -0
  155. package/dist/src/commands/status-v6.d.ts +319 -0
  156. package/dist/src/commands/status-v6.js +2979 -0
  157. package/dist/src/commands/status-v6.js.map +1 -0
  158. package/dist/src/commands/targets-command.d.ts +38 -0
  159. package/dist/src/commands/targets-command.js +182 -0
  160. package/dist/src/commands/targets-command.js.map +1 -0
  161. package/dist/src/commands/wizard.d.ts +8 -5
  162. package/dist/src/commands/wizard.js +7 -4
  163. package/dist/src/commands/wizard.js.map +1 -1
  164. package/dist/src/commands/write-commands.d.ts +9 -3
  165. package/dist/src/commands/write-commands.js +143 -85
  166. package/dist/src/commands/write-commands.js.map +1 -1
  167. package/dist/src/constants.d.ts +6 -6
  168. package/dist/src/constants.js +6 -6
  169. package/dist/src/constants.js.map +1 -1
  170. package/dist/src/eval/manifest-v1.d.ts +70 -0
  171. package/dist/src/eval/manifest-v1.js +358 -0
  172. package/dist/src/eval/manifest-v1.js.map +1 -0
  173. package/dist/src/generators/local-plugin.d.ts +7 -2
  174. package/dist/src/generators/local-plugin.js +313 -389
  175. package/dist/src/generators/local-plugin.js.map +1 -1
  176. package/dist/src/generators/permissions.d.ts +5 -2
  177. package/dist/src/generators/permissions.js +28 -15
  178. package/dist/src/generators/permissions.js.map +1 -1
  179. package/dist/src/index.d.ts +2 -31
  180. package/dist/src/index.js +1666 -1827
  181. package/dist/src/index.js.map +1 -1
  182. package/dist/src/intent/deployment-preferences.d.ts +63 -0
  183. package/dist/src/intent/deployment-preferences.js +170 -0
  184. package/dist/src/intent/deployment-preferences.js.map +1 -0
  185. package/dist/src/intent/diagnostics.d.ts +11 -0
  186. package/dist/src/intent/diagnostics.js +14 -0
  187. package/dist/src/intent/diagnostics.js.map +1 -0
  188. package/dist/src/intent/intent-codec.d.ts +19 -0
  189. package/dist/src/intent/intent-codec.js +117 -0
  190. package/dist/src/intent/intent-codec.js.map +1 -0
  191. package/dist/src/intent/intent-store.d.ts +43 -0
  192. package/dist/src/intent/intent-store.js +118 -0
  193. package/dist/src/intent/intent-store.js.map +1 -0
  194. package/dist/src/intent/scope-context.d.ts +33 -0
  195. package/dist/src/intent/scope-context.js +149 -0
  196. package/dist/src/intent/scope-context.js.map +1 -0
  197. package/dist/src/intent/work-context.d.ts +13 -0
  198. package/dist/src/intent/work-context.js +22 -0
  199. package/dist/src/intent/work-context.js.map +1 -0
  200. package/dist/src/output/command-receipt.d.ts +47 -46
  201. package/dist/src/output/command-receipt.js +286 -79
  202. package/dist/src/output/command-receipt.js.map +1 -1
  203. package/dist/src/output/model.d.ts +3 -11
  204. package/dist/src/output/native-consent.d.ts +2 -0
  205. package/dist/src/output/native-consent.js +5 -0
  206. package/dist/src/output/native-consent.js.map +1 -0
  207. package/dist/src/output/public-result.d.ts +49 -0
  208. package/dist/src/output/public-result.js +240 -0
  209. package/dist/src/output/public-result.js.map +1 -0
  210. package/dist/src/output/rebuild-progress.js +20 -15
  211. package/dist/src/output/rebuild-progress.js.map +1 -1
  212. package/dist/src/output/receipt-projection.d.ts +7 -0
  213. package/dist/src/output/receipt-projection.js +592 -0
  214. package/dist/src/output/receipt-projection.js.map +1 -0
  215. package/dist/src/platforms/capabilities.d.ts +12 -0
  216. package/dist/src/platforms/capabilities.js +205 -0
  217. package/dist/src/platforms/capabilities.js.map +1 -0
  218. package/dist/src/platforms/contracts.d.ts +358 -0
  219. package/dist/src/platforms/contracts.js +2 -0
  220. package/dist/src/platforms/contracts.js.map +1 -0
  221. package/dist/src/platforms/cursor-workspace-hook.d.ts +28 -0
  222. package/dist/src/platforms/cursor-workspace-hook.js +198 -0
  223. package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
  224. package/dist/src/platforms/discovery.d.ts +91 -0
  225. package/dist/src/platforms/discovery.js +653 -0
  226. package/dist/src/platforms/discovery.js.map +1 -0
  227. package/dist/src/platforms/gemini-activation.d.ts +36 -0
  228. package/dist/src/platforms/gemini-activation.js +331 -0
  229. package/dist/src/platforms/gemini-activation.js.map +1 -0
  230. package/dist/src/platforms/gemini-consent.d.ts +8 -0
  231. package/dist/src/platforms/gemini-consent.js +81 -0
  232. package/dist/src/platforms/gemini-consent.js.map +1 -0
  233. package/dist/src/platforms/identity.d.ts +4 -0
  234. package/dist/src/platforms/identity.js +22 -0
  235. package/dist/src/platforms/identity.js.map +1 -0
  236. package/dist/src/platforms/inspection-grok.d.ts +4 -0
  237. package/dist/src/platforms/inspection-grok.js +212 -0
  238. package/dist/src/platforms/inspection-grok.js.map +1 -0
  239. package/dist/src/platforms/inspection-native.d.ts +6 -0
  240. package/dist/src/platforms/inspection-native.js +406 -0
  241. package/dist/src/platforms/inspection-native.js.map +1 -0
  242. package/dist/src/platforms/inspection-opencode.d.ts +4 -0
  243. package/dist/src/platforms/inspection-opencode.js +98 -0
  244. package/dist/src/platforms/inspection-opencode.js.map +1 -0
  245. package/dist/src/platforms/inspection-pi.d.ts +3 -0
  246. package/dist/src/platforms/inspection-pi.js +282 -0
  247. package/dist/src/platforms/inspection-pi.js.map +1 -0
  248. package/dist/src/platforms/inspection-query.d.ts +12 -0
  249. package/dist/src/platforms/inspection-query.js +96 -0
  250. package/dist/src/platforms/inspection-query.js.map +1 -0
  251. package/dist/src/platforms/inspection.d.ts +17 -0
  252. package/dist/src/platforms/inspection.js +227 -0
  253. package/dist/src/platforms/inspection.js.map +1 -0
  254. package/dist/src/platforms/layout.d.ts +21 -0
  255. package/dist/src/platforms/layout.js +239 -0
  256. package/dist/src/platforms/layout.js.map +1 -0
  257. package/dist/src/platforms/lifecycle-native-services.d.ts +3 -0
  258. package/dist/src/platforms/lifecycle-native-services.js +147 -0
  259. package/dist/src/platforms/lifecycle-native-services.js.map +1 -0
  260. package/dist/src/platforms/lifecycle-native.d.ts +13 -0
  261. package/dist/src/platforms/lifecycle-native.js +283 -0
  262. package/dist/src/platforms/lifecycle-native.js.map +1 -0
  263. package/dist/src/platforms/lifecycle.d.ts +25 -0
  264. package/dist/src/platforms/lifecycle.js +494 -0
  265. package/dist/src/platforms/lifecycle.js.map +1 -0
  266. package/dist/src/platforms/managed-command-placement.d.ts +8 -0
  267. package/dist/src/platforms/managed-command-placement.js +79 -0
  268. package/dist/src/platforms/managed-command-placement.js.map +1 -0
  269. package/dist/src/platforms/projection-code-extension.d.ts +8 -0
  270. package/dist/src/platforms/projection-code-extension.js +121 -0
  271. package/dist/src/platforms/projection-code-extension.js.map +1 -0
  272. package/dist/src/platforms/projection-command-resources.d.ts +7 -0
  273. package/dist/src/platforms/projection-command-resources.js +74 -0
  274. package/dist/src/platforms/projection-command-resources.js.map +1 -0
  275. package/dist/src/platforms/projection-files.d.ts +27 -0
  276. package/dist/src/platforms/projection-files.js +111 -0
  277. package/dist/src/platforms/projection-files.js.map +1 -0
  278. package/dist/src/platforms/projection-marketplace.d.ts +19 -0
  279. package/dist/src/platforms/projection-marketplace.js +42 -0
  280. package/dist/src/platforms/projection-marketplace.js.map +1 -0
  281. package/dist/src/platforms/projection.d.ts +10 -0
  282. package/dist/src/platforms/projection.js +446 -0
  283. package/dist/src/platforms/projection.js.map +1 -0
  284. package/dist/src/platforms/registry.d.ts +4 -0
  285. package/dist/src/platforms/registry.js +30 -0
  286. package/dist/src/platforms/registry.js.map +1 -0
  287. package/dist/src/platforms/supplement-layout.d.ts +16 -0
  288. package/dist/src/platforms/supplement-layout.js +31 -0
  289. package/dist/src/platforms/supplement-layout.js.map +1 -0
  290. package/dist/src/platforms/supplement-state.d.ts +13 -0
  291. package/dist/src/platforms/supplement-state.js +82 -0
  292. package/dist/src/platforms/supplement-state.js.map +1 -0
  293. package/dist/src/portable/commands.d.ts +58 -11
  294. package/dist/src/portable/commands.js +94 -350
  295. package/dist/src/portable/commands.js.map +1 -1
  296. package/dist/src/portable/historical-materialization.d.ts +22 -0
  297. package/dist/src/portable/historical-materialization.js +124 -0
  298. package/dist/src/portable/historical-materialization.js.map +1 -0
  299. package/dist/src/portable/materializer.d.ts +24 -4
  300. package/dist/src/portable/materializer.js +189 -259
  301. package/dist/src/portable/materializer.js.map +1 -1
  302. package/dist/src/portable/recovery-layout.d.ts +17 -0
  303. package/dist/src/portable/recovery-layout.js +42 -0
  304. package/dist/src/portable/recovery-layout.js.map +1 -0
  305. package/dist/src/portable/recovery.d.ts +153 -0
  306. package/dist/src/portable/recovery.js +367 -0
  307. package/dist/src/portable/recovery.js.map +1 -0
  308. package/dist/src/portable/writer.d.ts +67 -0
  309. package/dist/src/portable/writer.js +321 -0
  310. package/dist/src/portable/writer.js.map +1 -0
  311. package/dist/src/recovery/coordinator.d.ts +141 -0
  312. package/dist/src/recovery/coordinator.js +1254 -0
  313. package/dist/src/recovery/coordinator.js.map +1 -0
  314. package/dist/src/recovery/demand.d.ts +51 -0
  315. package/dist/src/recovery/demand.js +159 -0
  316. package/dist/src/recovery/demand.js.map +1 -0
  317. package/dist/src/recovery/joint-coordinator.d.ts +25 -0
  318. package/dist/src/recovery/joint-coordinator.js +991 -0
  319. package/dist/src/recovery/joint-coordinator.js.map +1 -0
  320. package/dist/src/recovery/joint-demand.d.ts +50 -0
  321. package/dist/src/recovery/joint-demand.js +197 -0
  322. package/dist/src/recovery/joint-demand.js.map +1 -0
  323. package/dist/src/recovery/performance.d.ts +4 -0
  324. package/dist/src/recovery/performance.js +26 -0
  325. package/dist/src/recovery/performance.js.map +1 -0
  326. package/dist/src/recovery/receipt.d.ts +98 -0
  327. package/dist/src/recovery/receipt.js +2 -0
  328. package/dist/src/recovery/receipt.js.map +1 -0
  329. package/dist/src/recovery/retirement.d.ts +47 -0
  330. package/dist/src/recovery/retirement.js +469 -0
  331. package/dist/src/recovery/retirement.js.map +1 -0
  332. package/dist/src/recovery/status.d.ts +126 -0
  333. package/dist/src/recovery/status.js +1073 -0
  334. package/dist/src/recovery/status.js.map +1 -0
  335. package/dist/src/recovery/types.d.ts +85 -0
  336. package/dist/src/recovery/types.js +2 -0
  337. package/dist/src/recovery/types.js.map +1 -0
  338. package/dist/src/review/eval-source-input.d.ts +43 -0
  339. package/dist/src/review/eval-source-input.js +207 -0
  340. package/dist/src/review/eval-source-input.js.map +1 -0
  341. package/dist/src/review/platform-profile.d.ts +3 -0
  342. package/dist/src/review/platform-profile.js +14 -0
  343. package/dist/src/review/platform-profile.js.map +1 -0
  344. package/dist/src/review/review-profile.d.ts +20 -0
  345. package/dist/src/review/review-profile.js +276 -0
  346. package/dist/src/review/review-profile.js.map +1 -0
  347. package/dist/src/review/review-selection.d.ts +20 -0
  348. package/dist/src/review/review-selection.js +495 -0
  349. package/dist/src/review/review-selection.js.map +1 -0
  350. package/dist/src/review/review-types.d.ts +71 -0
  351. package/dist/src/review/review-types.js +16 -0
  352. package/dist/src/review/review-types.js.map +1 -0
  353. package/dist/src/review/skill-materialization.d.ts +62 -0
  354. package/dist/src/review/skill-materialization.js +205 -0
  355. package/dist/src/review/skill-materialization.js.map +1 -0
  356. package/dist/src/review/source-binding.d.ts +201 -0
  357. package/dist/src/review/source-binding.js +773 -0
  358. package/dist/src/review/source-binding.js.map +1 -0
  359. package/dist/src/tui/agent-management.d.ts +23 -0
  360. package/dist/src/tui/agent-management.js +319 -0
  361. package/dist/src/tui/agent-management.js.map +1 -0
  362. package/dist/src/tui/agent-settings.d.ts +47 -0
  363. package/dist/src/tui/agent-settings.js +97 -0
  364. package/dist/src/tui/agent-settings.js.map +1 -0
  365. package/dist/src/tui/catalog-freshness.d.ts +1 -0
  366. package/dist/src/tui/catalog-freshness.js +2 -0
  367. package/dist/src/tui/catalog-freshness.js.map +1 -0
  368. package/dist/src/tui/catalog-generation.d.ts +18 -53
  369. package/dist/src/tui/catalog-generation.js +136 -224
  370. package/dist/src/tui/catalog-generation.js.map +1 -1
  371. package/dist/src/tui/catalog-sources/projection.d.ts +4 -0
  372. package/dist/src/tui/catalog-sources/projection.js +17 -0
  373. package/dist/src/tui/catalog-sources/projection.js.map +1 -0
  374. package/dist/src/tui/catalog-sources/review.d.ts +3 -0
  375. package/dist/src/tui/catalog-sources/review.js +13 -0
  376. package/dist/src/tui/catalog-sources/review.js.map +1 -0
  377. package/dist/src/tui/catalog-sources/screens.d.ts +12 -0
  378. package/dist/src/tui/catalog-sources/screens.js +40 -0
  379. package/dist/src/tui/catalog-sources/screens.js.map +1 -0
  380. package/dist/src/tui/catalog-sources/session.d.ts +32 -0
  381. package/dist/src/tui/catalog-sources/session.js +300 -0
  382. package/dist/src/tui/catalog-sources/session.js.map +1 -0
  383. package/dist/src/tui/catalog-sources/types.d.ts +54 -0
  384. package/dist/src/tui/catalog-sources/types.js +2 -0
  385. package/dist/src/tui/catalog-sources/types.js.map +1 -0
  386. package/dist/src/tui/catalog-store-task.d.ts +16 -0
  387. package/dist/src/tui/catalog-store-task.js +19 -0
  388. package/dist/src/tui/catalog-store-task.js.map +1 -0
  389. package/dist/src/tui/clipboard.d.ts +13 -0
  390. package/dist/src/tui/clipboard.js +95 -0
  391. package/dist/src/tui/clipboard.js.map +1 -0
  392. package/dist/src/tui/components.d.ts +113 -3
  393. package/dist/src/tui/components.js +201 -36
  394. package/dist/src/tui/components.js.map +1 -1
  395. package/dist/src/tui/config-array-draft.d.ts +29 -0
  396. package/dist/src/tui/config-array-draft.js +48 -0
  397. package/dist/src/tui/config-array-draft.js.map +1 -0
  398. package/dist/src/tui/config-leaf-editor.d.ts +43 -0
  399. package/dist/src/tui/config-leaf-editor.js +224 -0
  400. package/dist/src/tui/config-leaf-editor.js.map +1 -0
  401. package/dist/src/tui/config-references.d.ts +38 -0
  402. package/dist/src/tui/config-references.js +82 -0
  403. package/dist/src/tui/config-references.js.map +1 -0
  404. package/dist/src/tui/config-value-presentation.d.ts +20 -0
  405. package/dist/src/tui/config-value-presentation.js +104 -0
  406. package/dist/src/tui/config-value-presentation.js.map +1 -0
  407. package/dist/src/tui/console-app-v4.d.ts +13 -4
  408. package/dist/src/tui/console-app-v4.js +9764 -2210
  409. package/dist/src/tui/console-app-v4.js.map +1 -1
  410. package/dist/src/tui/content-item-card.d.ts +13 -0
  411. package/dist/src/tui/content-item-card.js +51 -0
  412. package/dist/src/tui/content-item-card.js.map +1 -0
  413. package/dist/src/tui/controller-runtime.d.ts +7 -4
  414. package/dist/src/tui/controller-runtime.js +2064 -779
  415. package/dist/src/tui/controller-runtime.js.map +1 -1
  416. package/dist/src/tui/controller.d.ts +669 -106
  417. package/dist/src/tui/controller.js +3617 -971
  418. package/dist/src/tui/controller.js.map +1 -1
  419. package/dist/src/tui/dependency-graph-view.d.ts +39 -0
  420. package/dist/src/tui/dependency-graph-view.js +121 -0
  421. package/dist/src/tui/dependency-graph-view.js.map +1 -0
  422. package/dist/src/tui/dependency-graph.d.ts +81 -0
  423. package/dist/src/tui/dependency-graph.js +452 -0
  424. package/dist/src/tui/dependency-graph.js.map +1 -0
  425. package/dist/src/tui/deployment-view.d.ts +10 -0
  426. package/dist/src/tui/deployment-view.js +108 -0
  427. package/dist/src/tui/deployment-view.js.map +1 -0
  428. package/dist/src/tui/diagnostic-projection.d.ts +23 -0
  429. package/dist/src/tui/diagnostic-projection.js +595 -0
  430. package/dist/src/tui/diagnostic-projection.js.map +1 -0
  431. package/dist/src/tui/diagnostics.d.ts +6 -3
  432. package/dist/src/tui/diagnostics.js +14 -2
  433. package/dist/src/tui/diagnostics.js.map +1 -1
  434. package/dist/src/tui/entity-cards.d.ts +55 -0
  435. package/dist/src/tui/entity-cards.js +298 -0
  436. package/dist/src/tui/entity-cards.js.map +1 -0
  437. package/dist/src/tui/glossary.d.ts +25 -0
  438. package/dist/src/tui/glossary.js +72 -0
  439. package/dist/src/tui/glossary.js.map +1 -0
  440. package/dist/src/tui/index.d.ts +6 -2
  441. package/dist/src/tui/index.js +5 -2
  442. package/dist/src/tui/index.js.map +1 -1
  443. package/dist/src/tui/input-display.d.ts +1 -0
  444. package/dist/src/tui/input-display.js +23 -1
  445. package/dist/src/tui/input-display.js.map +1 -1
  446. package/dist/src/tui/keys.d.ts +44 -0
  447. package/dist/src/tui/keys.js +43 -15
  448. package/dist/src/tui/keys.js.map +1 -1
  449. package/dist/src/tui/lifecycle-action-view.d.ts +6 -0
  450. package/dist/src/tui/lifecycle-action-view.js +36 -0
  451. package/dist/src/tui/lifecycle-action-view.js.map +1 -0
  452. package/dist/src/tui/model.d.ts +243 -45
  453. package/dist/src/tui/model.js +1402 -415
  454. package/dist/src/tui/model.js.map +1 -1
  455. package/dist/src/tui/operation-diagnostic-screens.d.ts +8 -0
  456. package/dist/src/tui/operation-diagnostic-screens.js +72 -0
  457. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
  458. package/dist/src/tui/operation-history.d.ts +82 -0
  459. package/dist/src/tui/operation-history.js +136 -0
  460. package/dist/src/tui/operation-history.js.map +1 -0
  461. package/dist/src/tui/operation-review-planner.d.ts +28 -0
  462. package/dist/src/tui/operation-review-planner.js +1396 -0
  463. package/dist/src/tui/operation-review-planner.js.map +1 -0
  464. package/dist/src/tui/plugin-content.d.ts +33 -0
  465. package/dist/src/tui/plugin-content.js +245 -0
  466. package/dist/src/tui/plugin-content.js.map +1 -0
  467. package/dist/src/tui/plugin-detail.d.ts +72 -0
  468. package/dist/src/tui/plugin-detail.js +260 -0
  469. package/dist/src/tui/plugin-detail.js.map +1 -0
  470. package/dist/src/tui/plugin-write-task.d.ts +69 -0
  471. package/dist/src/tui/plugin-write-task.js +286 -0
  472. package/dist/src/tui/plugin-write-task.js.map +1 -0
  473. package/dist/src/tui/prompt.js +4 -15
  474. package/dist/src/tui/prompt.js.map +1 -1
  475. package/dist/src/tui/query-header.d.ts +30 -0
  476. package/dist/src/tui/query-header.js +40 -0
  477. package/dist/src/tui/query-header.js.map +1 -0
  478. package/dist/src/tui/reader.d.ts +38 -0
  479. package/dist/src/tui/reader.js +49 -0
  480. package/dist/src/tui/reader.js.map +1 -0
  481. package/dist/src/tui/router.d.ts +186 -35
  482. package/dist/src/tui/router.js +338 -50
  483. package/dist/src/tui/router.js.map +1 -1
  484. package/dist/src/tui/scoped-flow.d.ts +45 -0
  485. package/dist/src/tui/scoped-flow.js +96 -0
  486. package/dist/src/tui/scoped-flow.js.map +1 -0
  487. package/dist/src/tui/scoped-inventory.d.ts +126 -0
  488. package/dist/src/tui/scoped-inventory.js +258 -0
  489. package/dist/src/tui/scoped-inventory.js.map +1 -0
  490. package/dist/src/tui/screen-registry.d.ts +701 -0
  491. package/dist/src/tui/screen-registry.js +226 -0
  492. package/dist/src/tui/screen-registry.js.map +1 -0
  493. package/dist/src/tui/session-console-app.d.ts +6 -0
  494. package/dist/src/tui/session-console-app.js +13 -0
  495. package/dist/src/tui/session-console-app.js.map +1 -0
  496. package/dist/src/tui/session-host.d.ts +45 -0
  497. package/dist/src/tui/session-host.js +219 -0
  498. package/dist/src/tui/session-host.js.map +1 -0
  499. package/dist/src/tui/source-detail-card.d.ts +29 -0
  500. package/dist/src/tui/source-detail-card.js +45 -0
  501. package/dist/src/tui/source-detail-card.js.map +1 -0
  502. package/dist/src/tui/theme.d.ts +12 -0
  503. package/dist/src/tui/theme.js +12 -0
  504. package/dist/src/tui/theme.js.map +1 -1
  505. package/dist/src/tui/viewport.d.ts +1 -0
  506. package/dist/src/tui/viewport.js +23 -0
  507. package/dist/src/tui/viewport.js.map +1 -1
  508. package/dist/src/tui/wizard.js +37 -13
  509. package/dist/src/tui/wizard.js.map +1 -1
  510. package/dist/src/types.d.ts +220 -118
  511. package/dist/src/types.js +1 -0
  512. package/dist/src/types.js.map +1 -1
  513. package/dist/src/utils/agent-version.d.ts +13 -4
  514. package/dist/src/utils/agent-version.js +27 -4
  515. package/dist/src/utils/agent-version.js.map +1 -1
  516. package/dist/src/utils/artifact-plan.d.ts +33 -7
  517. package/dist/src/utils/artifact-plan.js +115 -430
  518. package/dist/src/utils/artifact-plan.js.map +1 -1
  519. package/dist/src/utils/artifact-renderer.d.ts +114 -83
  520. package/dist/src/utils/artifact-renderer.js +213 -364
  521. package/dist/src/utils/artifact-renderer.js.map +1 -1
  522. package/dist/src/utils/artifact-request.d.ts +44 -0
  523. package/dist/src/utils/artifact-request.js +80 -0
  524. package/dist/src/utils/artifact-request.js.map +1 -0
  525. package/dist/src/utils/artifact-sources.d.ts +6 -2
  526. package/dist/src/utils/artifact-sources.js +17 -0
  527. package/dist/src/utils/artifact-sources.js.map +1 -1
  528. package/dist/src/utils/bundle-layout.js +57 -173
  529. package/dist/src/utils/bundle-layout.js.map +1 -1
  530. package/dist/src/utils/catalog-capability-projection.d.ts +8 -0
  531. package/dist/src/utils/catalog-capability-projection.js +14 -0
  532. package/dist/src/utils/catalog-capability-projection.js.map +1 -0
  533. package/dist/src/utils/catalog-digests.d.ts +2 -2
  534. package/dist/src/utils/catalog-digests.js +7 -18
  535. package/dist/src/utils/catalog-digests.js.map +1 -1
  536. package/dist/src/utils/catalog-generation-control-snapshot.d.ts +11 -0
  537. package/dist/src/utils/catalog-generation-control-snapshot.js +45 -0
  538. package/dist/src/utils/catalog-generation-control-snapshot.js.map +1 -0
  539. package/dist/src/utils/catalog-generation-error.d.ts +5 -1
  540. package/dist/src/utils/catalog-generation-error.js +14 -0
  541. package/dist/src/utils/catalog-generation-error.js.map +1 -1
  542. package/dist/src/utils/catalog-generation-resolver.d.ts +36 -5
  543. package/dist/src/utils/catalog-generation-resolver.js +221 -77
  544. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  545. package/dist/src/utils/catalog-generation-service.d.ts +159 -28
  546. package/dist/src/utils/catalog-generation-service.js +1186 -525
  547. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  548. package/dist/src/utils/catalog-generation-state.d.ts +9 -0
  549. package/dist/src/utils/catalog-generation-state.js +97 -106
  550. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  551. package/dist/src/utils/catalog-generation-store.d.ts +38 -24
  552. package/dist/src/utils/catalog-generation-store.js +337 -272
  553. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  554. package/dist/src/utils/catalog-manifest-v7.d.ts +5 -0
  555. package/dist/src/utils/{catalog-manifest-v5.js → catalog-manifest-v7.js} +23 -35
  556. package/dist/src/utils/catalog-manifest-v7.js.map +1 -0
  557. package/dist/src/utils/catalog-operation-context.d.ts +6 -14
  558. package/dist/src/utils/catalog-operation-context.js +69 -169
  559. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  560. package/dist/src/utils/catalog-public-error.js +8 -4
  561. package/dist/src/utils/catalog-public-error.js.map +1 -1
  562. package/dist/src/utils/catalog-runtime-projection.d.ts +7 -3
  563. package/dist/src/utils/catalog-runtime-projection.js +5 -40
  564. package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
  565. package/dist/src/utils/catalog-snapshot.d.ts +2 -2
  566. package/dist/src/utils/catalog-source-impact.d.ts +21 -0
  567. package/dist/src/utils/catalog-source-impact.js +344 -0
  568. package/dist/src/utils/catalog-source-impact.js.map +1 -0
  569. package/dist/src/utils/catalog-source-references.d.ts +23 -2
  570. package/dist/src/utils/catalog-source-references.js +456 -382
  571. package/dist/src/utils/catalog-source-references.js.map +1 -1
  572. package/dist/src/utils/catalog-sources.d.ts +14 -1
  573. package/dist/src/utils/catalog-sources.js +178 -18
  574. package/dist/src/utils/catalog-sources.js.map +1 -1
  575. package/dist/src/utils/codex-config.d.ts +2 -0
  576. package/dist/src/utils/codex-config.js +22 -1
  577. package/dist/src/utils/codex-config.js.map +1 -1
  578. package/dist/src/utils/codex-executable-discovery.d.ts +28 -0
  579. package/dist/src/utils/codex-executable-discovery.js +431 -0
  580. package/dist/src/utils/codex-executable-discovery.js.map +1 -0
  581. package/dist/src/utils/codex-manager.d.ts +47 -18
  582. package/dist/src/utils/codex-manager.js +88 -622
  583. package/dist/src/utils/codex-manager.js.map +1 -1
  584. package/dist/src/utils/codex-marketplace-path.d.ts +5 -0
  585. package/dist/src/utils/codex-marketplace-path.js +45 -0
  586. package/dist/src/utils/codex-marketplace-path.js.map +1 -0
  587. package/dist/src/utils/codex-native-observation.d.ts +49 -0
  588. package/dist/src/utils/codex-native-observation.js +169 -0
  589. package/dist/src/utils/codex-native-observation.js.map +1 -0
  590. package/dist/src/utils/codex-reconciler.d.ts +123 -0
  591. package/dist/src/utils/codex-reconciler.js +322 -0
  592. package/dist/src/utils/codex-reconciler.js.map +1 -0
  593. package/dist/src/utils/codex-shared-native.d.ts +45 -0
  594. package/dist/src/utils/codex-shared-native.js +122 -0
  595. package/dist/src/utils/codex-shared-native.js.map +1 -0
  596. package/dist/src/utils/codex-skill-staging.d.ts +4 -3
  597. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  598. package/dist/src/utils/codex-skills-root.d.ts +4 -0
  599. package/dist/src/utils/codex-skills-root.js +25 -0
  600. package/dist/src/utils/codex-skills-root.js.map +1 -0
  601. package/dist/src/utils/codex-surface-analysis.d.ts +49 -0
  602. package/dist/src/utils/codex-surface-analysis.js +220 -0
  603. package/dist/src/utils/codex-surface-analysis.js.map +1 -0
  604. package/dist/src/utils/component-command-preparation.d.ts +34 -0
  605. package/dist/src/utils/component-command-preparation.js +228 -0
  606. package/dist/src/utils/component-command-preparation.js.map +1 -0
  607. package/dist/src/utils/component-resources.d.ts +51 -0
  608. package/dist/src/utils/component-resources.js +322 -0
  609. package/dist/src/utils/component-resources.js.map +1 -0
  610. package/dist/src/utils/dynamic-skill-tree.d.ts +18 -6
  611. package/dist/src/utils/dynamic-skill-tree.js +32 -9
  612. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  613. package/dist/src/utils/git-catalog-provider.d.ts +16 -0
  614. package/dist/src/utils/git-catalog-provider.js +167 -120
  615. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  616. package/dist/src/utils/inventory-recovery-diagnostic.d.ts +4 -0
  617. package/dist/src/utils/inventory-recovery-diagnostic.js +15 -0
  618. package/dist/src/utils/inventory-recovery-diagnostic.js.map +1 -0
  619. package/dist/src/utils/local-marketplace.d.ts +17 -12
  620. package/dist/src/utils/local-marketplace.js +85 -195
  621. package/dist/src/utils/local-marketplace.js.map +1 -1
  622. package/dist/src/utils/managed-command-closure.d.ts +3 -0
  623. package/dist/src/utils/managed-command-closure.js +35 -0
  624. package/dist/src/utils/managed-command-closure.js.map +1 -0
  625. package/dist/src/utils/managed-command-evidence.d.ts +7 -0
  626. package/dist/src/utils/managed-command-evidence.js +10 -0
  627. package/dist/src/utils/managed-command-evidence.js.map +1 -0
  628. package/dist/src/utils/managed-command-materialization.d.ts +124 -0
  629. package/dist/src/utils/managed-command-materialization.js +369 -0
  630. package/dist/src/utils/managed-command-materialization.js.map +1 -0
  631. package/dist/src/utils/managed-command-preparation.d.ts +67 -0
  632. package/dist/src/utils/managed-command-preparation.js +146 -0
  633. package/dist/src/utils/managed-command-preparation.js.map +1 -0
  634. package/dist/src/utils/managed-command-review.d.ts +26 -0
  635. package/dist/src/utils/managed-command-review.js +68 -0
  636. package/dist/src/utils/managed-command-review.js.map +1 -0
  637. package/dist/src/utils/managed-command-runtime.d.ts +33 -0
  638. package/dist/src/utils/managed-command-runtime.js +121 -0
  639. package/dist/src/utils/managed-command-runtime.js.map +1 -0
  640. package/dist/src/utils/managed-command-store.d.ts +143 -0
  641. package/dist/src/utils/managed-command-store.js +665 -0
  642. package/dist/src/utils/managed-command-store.js.map +1 -0
  643. package/dist/src/utils/manifest.d.ts +1 -3
  644. package/dist/src/utils/manifest.js +1 -3
  645. package/dist/src/utils/manifest.js.map +1 -1
  646. package/dist/src/utils/multi-source-catalog.d.ts +1 -10
  647. package/dist/src/utils/multi-source-catalog.js +9 -175
  648. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  649. package/dist/src/utils/native-cli.d.ts +74 -5
  650. package/dist/src/utils/native-cli.js +479 -31
  651. package/dist/src/utils/native-cli.js.map +1 -1
  652. package/dist/src/utils/native-demand.d.ts +29 -0
  653. package/dist/src/utils/native-demand.js +4 -0
  654. package/dist/src/utils/native-demand.js.map +1 -0
  655. package/dist/src/utils/native-tool-context.d.ts +14 -0
  656. package/dist/src/utils/native-tool-context.js +38 -0
  657. package/dist/src/utils/native-tool-context.js.map +1 -0
  658. package/dist/src/utils/native-tool-review.d.ts +18 -0
  659. package/dist/src/utils/native-tool-review.js +116 -0
  660. package/dist/src/utils/native-tool-review.js.map +1 -0
  661. package/dist/src/utils/orphan-marketplace-cleanup.js +0 -1
  662. package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -1
  663. package/dist/src/utils/ownership.d.ts +103 -21
  664. package/dist/src/utils/ownership.js +232 -210
  665. package/dist/src/utils/ownership.js.map +1 -1
  666. package/dist/src/utils/path-catalog-provider.d.ts +1 -1
  667. package/dist/src/utils/path-catalog-provider.js +47 -62
  668. package/dist/src/utils/path-catalog-provider.js.map +1 -1
  669. package/dist/src/utils/paths.d.ts +1 -2
  670. package/dist/src/utils/paths.js +5 -3
  671. package/dist/src/utils/paths.js.map +1 -1
  672. package/dist/src/utils/platform-empty-state.d.ts +45 -0
  673. package/dist/src/utils/platform-empty-state.js +159 -0
  674. package/dist/src/utils/platform-empty-state.js.map +1 -0
  675. package/dist/src/utils/platform-support.d.ts +1 -1
  676. package/dist/src/utils/platform-support.js +1 -1
  677. package/dist/src/utils/platform-support.js.map +1 -1
  678. package/dist/src/utils/plugin-config-impact.d.ts +64 -0
  679. package/dist/src/utils/plugin-config-impact.js +307 -0
  680. package/dist/src/utils/plugin-config-impact.js.map +1 -0
  681. package/dist/src/utils/plugin-config-references.d.ts +89 -0
  682. package/dist/src/utils/plugin-config-references.js +335 -0
  683. package/dist/src/utils/plugin-config-references.js.map +1 -0
  684. package/dist/src/utils/plugin-config-write.d.ts +109 -27
  685. package/dist/src/utils/plugin-config-write.js +1242 -348
  686. package/dist/src/utils/plugin-config-write.js.map +1 -1
  687. package/dist/src/utils/plugin-config.d.ts +187 -109
  688. package/dist/src/utils/plugin-config.js +916 -1147
  689. package/dist/src/utils/plugin-config.js.map +1 -1
  690. package/dist/src/utils/plugin-dependencies.d.ts +1 -1
  691. package/dist/src/utils/plugin-dependencies.js.map +1 -1
  692. package/dist/src/utils/plugin-scripts.d.ts +78 -127
  693. package/dist/src/utils/plugin-scripts.js +566 -524
  694. package/dist/src/utils/plugin-scripts.js.map +1 -1
  695. package/dist/src/utils/process-lock.js +14 -5
  696. package/dist/src/utils/process-lock.js.map +1 -1
  697. package/dist/src/utils/process-tree.d.ts +2 -2
  698. package/dist/src/utils/process-tree.js +1 -1
  699. package/dist/src/utils/process-tree.js.map +1 -1
  700. package/dist/src/utils/project-boundary.d.ts +11 -13
  701. package/dist/src/utils/project-boundary.js +28 -34
  702. package/dist/src/utils/project-boundary.js.map +1 -1
  703. package/dist/src/utils/rendered-contract.js +18 -1
  704. package/dist/src/utils/rendered-contract.js.map +1 -1
  705. package/dist/src/utils/runtime-config.d.ts +18 -0
  706. package/dist/src/utils/runtime-config.js +64 -0
  707. package/dist/src/utils/runtime-config.js.map +1 -0
  708. package/dist/src/utils/runtime-skill-closure.d.ts +2 -2
  709. package/dist/src/utils/runtime-skill-closure.js +47 -6
  710. package/dist/src/utils/runtime-skill-closure.js.map +1 -1
  711. package/dist/src/utils/safe-fs.d.ts +21 -0
  712. package/dist/src/utils/safe-fs.js +111 -0
  713. package/dist/src/utils/safe-fs.js.map +1 -0
  714. package/dist/src/utils/safe-operation-diagnostic.d.ts +15 -0
  715. package/dist/src/utils/safe-operation-diagnostic.js +33 -0
  716. package/dist/src/utils/safe-operation-diagnostic.js.map +1 -0
  717. package/dist/src/utils/sensitive-content.d.ts +4 -0
  718. package/dist/src/utils/sensitive-content.js +36 -0
  719. package/dist/src/utils/sensitive-content.js.map +1 -0
  720. package/dist/src/utils/state-paths.d.ts +8 -3
  721. package/dist/src/utils/state-paths.js +53 -16
  722. package/dist/src/utils/state-paths.js.map +1 -1
  723. package/dist/src/utils/target-eligibility.d.ts +4 -3
  724. package/dist/src/utils/target-eligibility.js +12 -6
  725. package/dist/src/utils/target-eligibility.js.map +1 -1
  726. package/dist/src/utils/windows-claude-shim.d.ts +7 -0
  727. package/dist/src/utils/windows-claude-shim.js +10 -0
  728. package/dist/src/utils/windows-claude-shim.js.map +1 -0
  729. package/dist/src/utils/windows-npm-shim.d.ts +16 -0
  730. package/dist/src/utils/windows-npm-shim.js +155 -0
  731. package/dist/src/utils/windows-npm-shim.js.map +1 -0
  732. package/dist/vitest.config.js +105 -9
  733. package/dist/vitest.config.js.map +1 -1
  734. package/package.json +30 -21
  735. package/dist/scripts/aw-skill-eval-engine.d.ts +0 -13
  736. package/dist/scripts/aw-skill-eval-engine.js +0 -31
  737. package/dist/scripts/aw-skill-eval-engine.js.map +0 -1
  738. package/dist/scripts/codex-eval-app-server.d.ts +0 -91
  739. package/dist/scripts/codex-eval-app-server.js +0 -1334
  740. package/dist/scripts/codex-eval-app-server.js.map +0 -1
  741. package/dist/scripts/codex-eval-isolation.d.ts +0 -61
  742. package/dist/scripts/codex-eval-isolation.js +0 -318
  743. package/dist/scripts/codex-eval-isolation.js.map +0 -1
  744. package/dist/scripts/codex-eval-process-management.d.ts +0 -8
  745. package/dist/scripts/codex-eval-process-management.js +0 -69
  746. package/dist/scripts/codex-eval-process-management.js.map +0 -1
  747. package/dist/scripts/codex-eval-process-tree.d.ts +0 -38
  748. package/dist/scripts/codex-eval-process-tree.js +0 -803
  749. package/dist/scripts/codex-eval-process-tree.js.map +0 -1
  750. package/dist/scripts/codex-eval-runtime-config.d.ts +0 -62
  751. package/dist/scripts/codex-eval-runtime-config.js +0 -843
  752. package/dist/scripts/codex-eval-runtime-config.js.map +0 -1
  753. package/dist/scripts/codex-trigger-eval.d.ts +0 -84
  754. package/dist/scripts/codex-trigger-eval.js +0 -968
  755. package/dist/scripts/codex-trigger-eval.js.map +0 -1
  756. package/dist/scripts/eval-plugin-skills-audited.d.ts +0 -6
  757. package/dist/scripts/eval-plugin-skills-audited.js +0 -261
  758. package/dist/scripts/eval-plugin-skills-audited.js.map +0 -1
  759. package/dist/scripts/eval-plugin-skills.d.ts +0 -45
  760. package/dist/scripts/eval-plugin-skills.js +0 -1589
  761. package/dist/scripts/eval-plugin-skills.js.map +0 -1
  762. package/dist/scripts/eval-run-layout.d.ts +0 -17
  763. package/dist/scripts/eval-run-layout.js +0 -26
  764. package/dist/scripts/eval-run-layout.js.map +0 -1
  765. package/dist/scripts/plugin-eval-contract.d.ts +0 -189
  766. package/dist/scripts/plugin-eval-contract.js +0 -745
  767. package/dist/scripts/plugin-eval-contract.js.map +0 -1
  768. package/dist/scripts/plugin-eval-materializer.d.ts +0 -13
  769. package/dist/scripts/plugin-eval-materializer.js +0 -421
  770. package/dist/scripts/plugin-eval-materializer.js.map +0 -1
  771. package/dist/scripts/skill-reporting.d.ts +0 -212
  772. package/dist/scripts/skill-reporting.js +0 -922
  773. package/dist/scripts/skill-reporting.js.map +0 -1
  774. package/dist/src/commands/catalog-context.d.ts +0 -52
  775. package/dist/src/commands/catalog-context.js +0 -156
  776. package/dist/src/commands/catalog-context.js.map +0 -1
  777. package/dist/src/commands/review-publication.d.ts +0 -99
  778. package/dist/src/commands/review-publication.js +0 -904
  779. package/dist/src/commands/review-publication.js.map +0 -1
  780. package/dist/src/commands/status-v5.d.ts +0 -169
  781. package/dist/src/commands/status-v5.js +0 -1135
  782. package/dist/src/commands/status-v5.js.map +0 -1
  783. package/dist/src/portable/skills-cli.d.ts +0 -43
  784. package/dist/src/portable/skills-cli.js +0 -148
  785. package/dist/src/portable/skills-cli.js.map +0 -1
  786. package/dist/src/utils/catalog-manifest-v5.d.ts +0 -5
  787. package/dist/src/utils/catalog-manifest-v5.js.map +0 -1
  788. package/dist/src/utils/catalog-source-cache.d.ts +0 -62
  789. package/dist/src/utils/catalog-source-cache.js +0 -321
  790. package/dist/src/utils/catalog-source-cache.js.map +0 -1
  791. package/dist/src/utils/codex-project-surface.d.ts +0 -3
  792. package/dist/src/utils/codex-project-surface.js +0 -49
  793. package/dist/src/utils/codex-project-surface.js.map +0 -1
  794. package/dist/src/utils/lifecycle-active-store.d.ts +0 -147
  795. package/dist/src/utils/lifecycle-active-store.js +0 -1064
  796. package/dist/src/utils/lifecycle-active-store.js.map +0 -1
  797. package/dist/src/utils/plugin-release.d.ts +0 -2
  798. package/dist/src/utils/plugin-release.js +0 -2
  799. package/dist/src/utils/plugin-release.js.map +0 -1
  800. package/dist/src/utils/slash-commands.d.ts +0 -1
  801. package/dist/src/utils/slash-commands.js +0 -2
  802. package/dist/src/utils/slash-commands.js.map +0 -1
@@ -0,0 +1,1254 @@
1
+ import { describeNativeToolClosure } from '../utils/native-tool-review.js';
2
+ import path from 'node:path';
3
+ import { CatalogSourceInventoryIncompleteError } from '../utils/catalog-source-references.js';
4
+ import { inventoryRecoveryDiagnostic } from '../utils/inventory-recovery-diagnostic.js';
5
+ import { getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
6
+ import { runRebuildCommand } from '../commands/rebuild-command.js';
7
+ import { buildRebuildReceiptJson } from '../output/command-receipt.js';
8
+ import { withAwHomeMutationLock } from '../utils/aw-home-mutation-lock.js';
9
+ import { createCodexNativeObservationSession } from '../utils/codex-native-observation.js';
10
+ import { bindNativeCliRunnerSignal, getDefaultNativeCliRunner, prepareNativeCliExecution } from '../utils/native-cli.js';
11
+ import { portableRecoveryLayout } from '../portable/recovery-layout.js';
12
+ import { canonicalizePathThroughExistingAncestor, resolveClaudeProjectKey, resolveCodexProjectKey } from '../utils/state-paths.js';
13
+ import { parsePluginId } from '../utils/multi-source-catalog.js';
14
+ import { activateCatalogSourceGeneration, probeCatalogSourceGeneration, } from '../utils/catalog-generation-service.js';
15
+ import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
16
+ import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
17
+ import { calculateCatalogSourceImpactDigest, inspectCatalogSourceImpact, } from '../utils/catalog-source-impact.js';
18
+ import { preparePortableRecovery, portablePreparationDiagnostic, preparePortableCleanup, inspectPortableRecovery, inspectPortableResidue, executePortableRecovery, } from '../portable/recovery.js';
19
+ import { addRequirements } from '../commands/intent-command.js';
20
+ import { readDemand, demandNativeProjection, resolveDelivery } from './demand.js';
21
+ import { selectAgents, writePreferences } from '../intent/deployment-preferences.js';
22
+ import { calculateIntentDigest } from '../intent/intent-codec.js';
23
+ import { observeIntent } from '../intent/intent-store.js';
24
+ import { assertNeutralAncestorChain, createScopeContext } from '../intent/scope-context.js';
25
+ import { prepareJointRecovery, executeJointRecovery } from './joint-coordinator.js';
26
+ import { createEmptyNativeDemandView } from '../utils/native-demand.js';
27
+ import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
28
+ import { runPreApplyScript } from '../utils/plugin-scripts.js';
29
+ import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
30
+ import { measureRecoveryPerformanceStage } from './performance.js';
31
+ import { disposePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
32
+ import { operationPlanNativeToolChanges } from '../commands/operation-plan.js';
33
+ function isPortableAgent(agent) {
34
+ return agent === 'generic';
35
+ }
36
+ function diagnostic(code) {
37
+ const messages = {
38
+ nativeToolAuthorizationRequired: '原生工具声明有变化,请使用 --yes 或确认当前 Review 后执行。',
39
+ localTargetsRequired: '已有需求,请先设置本机 Agent。',
40
+ deliveryUnsupported: '此插件没有适用于所选 Agent 的交付。',
41
+ operationReviewStale: '确认依据已改变,请重新检查并确认。',
42
+ syncPluginNotDesired: '所选插件尚未声明,请先运行 aw plugin install --only requirements。',
43
+ syncSelectionRequired: '请指定插件或使用 --all。',
44
+ invalidExactTargets: '精确重试目标不属于当前请求,请重新检查并选择。',
45
+ sourceRefreshFailed: '来源刷新失败,此来源的插件未恢复。',
46
+ sourceRefreshConfirmationRequired: '来源更新必须先单独确认,再重新准备插件恢复。',
47
+ artifactCollision: '多个交付占用相同输出位置,请先处理冲突。',
48
+ deliverySwitchCleanupRequired: '此目标仍有旧 Native 输出;请先清理旧交付,再恢复 Portable。',
49
+ deliverySwitchObservationFailed: '无法确认此目标是否仍有旧 Native 输出;请先恢复 Native 观察能力或人工核验。',
50
+ deliverySwitchPortableCleanupRequired: '此目标仍有旧 Portable 输出;请先核验并移开旧交付,再恢复 Native。',
51
+ deliverySwitchPortableObservationFailed: '无法确认此目标是否仍有旧 Portable 输出;请先核验 Portable 现场。',
52
+ 'backend-action-unsupported': '此后端尚不支持安全移除,请检查精确的 Portable 输出。',
53
+ };
54
+ return { code, message: messages[code] ?? `操作受阻:${code}。` };
55
+ }
56
+ function errorCode(error, fallback) {
57
+ const code = error?.code;
58
+ if (typeof code === 'string' && /^[A-Za-z][A-Za-z0-9-]*$/u.test(code))
59
+ return code;
60
+ const prefix = error instanceof Error ? error.message.split(':')[0] : '';
61
+ return /^[A-Za-z][A-Za-z0-9-]*$/u.test(prefix ?? '') ? prefix : fallback;
62
+ }
63
+ function intentEvidence(intent) {
64
+ return 'rawDigest' in intent ? `${intent.state}:${intent.rawDigest}` : intent.state;
65
+ }
66
+ function preferenceEvidence(demand) {
67
+ return 'rawDigest' in demand.preferences
68
+ ? `${demand.preferences.state}:${demand.preferences.rawDigest}` : demand.preferences.state;
69
+ }
70
+ function agentForPlatform(platform) {
71
+ return platform;
72
+ }
73
+ function pair(plan, pluginId, agent) {
74
+ return plan.receipt.targetResults.find((target) => target.pluginId === pluginId && target.agent === agent);
75
+ }
76
+ function block(target, code, detail = diagnostic(code)) {
77
+ if (!target.blockers.some((entry) => entry.code === code))
78
+ target.blockers.push(detail);
79
+ }
80
+ function completeReceipt(receipt) {
81
+ receipt.requestedTargets = receipt.targetResults.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
82
+ receipt.remainingTargets = receipt.targetResults.filter((target) => target.blockers.length > 0
83
+ || !['applied', 'no-op'].includes(target.execution))
84
+ .map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
85
+ receipt.ok = receipt.blockers.length === 0 && receipt.remainingTargets.length === 0
86
+ && (receipt.commandResults ?? []).every((result) => result.state === 'completed');
87
+ receipt.errors = [...receipt.blockers];
88
+ receipt.recoveryActions = [...new Set([
89
+ ...(receipt.commandResults ?? []).flatMap((result) => result.recoveryActions),
90
+ ...receipt.blockers.map((entry) => entry.code === 'localTargetsRequired'
91
+ ? `aw target set <target...>` : `aw plugin status --context ${receipt.scope} --json`),
92
+ ...receipt.remainingTargets.flatMap((target) => {
93
+ const result = receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
94
+ if (result?.recoveryActions?.length)
95
+ return result.recoveryActions;
96
+ return result?.blockers.some((entry) => entry.code === 'backend-action-unsupported' || entry.code === 'portableObservationFailed')
97
+ ? `检查 ${target.pluginId} 的 Portable 输出及 provider 关联;AW 不支持安全自动删除。`
98
+ : `aw plugin sync ${target.pluginId} --context ${receipt.scope} --target ${target.agent}`;
99
+ }),
100
+ ])];
101
+ return receipt;
102
+ }
103
+ function displayPortablePath(plan, physicalPath) {
104
+ if (plan.options.scope === 'user' || !plan.context.projectRoot)
105
+ return physicalPath;
106
+ const relative = path.relative(plan.context.projectRoot, physicalPath);
107
+ return relative && relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)
108
+ ? `项目根目录/${relative.split(path.sep).join('/')}` : physicalPath;
109
+ }
110
+ function portableRecoveryActions(plan, pluginId, targets) {
111
+ return [...new Set(targets.map((target) => {
112
+ const directory = displayPortablePath(plan, target.physicalPath);
113
+ const shared = target.agent === 'generic' || target.agent === 'antigravity'
114
+ ? '该目录可能同时被 Codex 和 Cursor 读取;移开前请确认对两者的影响。' : `该目录供 ${target.agent} 使用。`;
115
+ return `${pluginId}:请检查并备份目录 ${directory};确认归属后可自行移开。${shared}`
116
+ + (plan.command === 'cleanup' || plan.command === 'uninstall'
117
+ ? '无法证实该目录的安全删除边界;处理后重新检查状态。'
118
+ : `然后重试 aw plugin sync ${pluginId} --context ${plan.options.scope} --target ${target.agent}。`);
119
+ }))];
120
+ }
121
+ function selectRoots(demand, selectors, all) {
122
+ const roots = demand.roots?.map((root) => root.pluginId) ?? [];
123
+ if (all && selectors.length)
124
+ throw new Error('syncSelectorConflict');
125
+ if (all)
126
+ return roots;
127
+ if (!selectors.length)
128
+ return roots;
129
+ return [...new Set(selectors.map((selector) => {
130
+ const parsed = parsePluginId(selector);
131
+ const matches = roots.filter((id) => parsed.sourceId ? id === selector
132
+ : parsePluginId(id).pluginName === parsed.pluginName);
133
+ if (matches.length !== 1)
134
+ throw new Error('syncPluginNotDesired');
135
+ return matches[0];
136
+ }))];
137
+ }
138
+ function nativeGroupTargets(group) {
139
+ return group.targets ?? group.pluginIds.flatMap((pluginId) => (group.platform === 'both' ? ['codex', 'claude'] : [group.platform])
140
+ .map((platform) => ({ pluginId, platform })));
141
+ }
142
+ function nativeTargetSelection(targets) {
143
+ const platforms = new Set(targets.map((target) => target.platform));
144
+ return { pluginIds: [...new Set(targets.map((target) => target.pluginId))],
145
+ platform: platforms.size === 1 ? targets[0].platform : 'both', targets: [...targets] };
146
+ }
147
+ async function nativeOperation(plan, pluginIds, platform, preview, runtime = plan.runtime, command = plan.command, selectedTargets) {
148
+ if (!runtime.awHomeMutationToken) {
149
+ await prepareNativeCliExecution({ env: plan.context.env, runner: runtime.nativeCliRunner });
150
+ }
151
+ const rebuildCommand = command === 'install' ? 'sync' : command;
152
+ const requirements = command === 'cleanup' && (plan.demand.intent.state !== 'valid'
153
+ || plan.demand.preferences.state === 'invalid' || plan.demand.preferences.state === 'unreadable')
154
+ ? createEmptyNativeDemandView() : demandNativeProjection(plan.demand);
155
+ if (plan.options.sharedReferenceView)
156
+ requirements.sharedReferenceView = plan.options.sharedReferenceView;
157
+ const result = await runRebuildCommand({
158
+ command: rebuildCommand,
159
+ pluginNames: pluginIds,
160
+ commandOptions: {
161
+ cwd: plan.context.executionCwd, scope: plan.options.scope, platform,
162
+ yes: plan.options.yes,
163
+ scriptTimeoutMs: plan.options.scriptTimeoutMs,
164
+ ...(plan.options.dependencyScopeOverrides ? { dependencyScopeOverrides: plan.options.dependencyScopeOverrides } : {}),
165
+ ...(command === 'cleanup' || command === 'uninstall' ? { force: plan.options.force } : {}),
166
+ },
167
+ runtime: {
168
+ ...runtime,
169
+ preserveLegacyNativeSkills: plan.options.existingOnly === true,
170
+ nativeActivationOnlyTargets: plan.options.nativeActivationOnlyTargets,
171
+ nativePlannedRetirements: plan.options.nativePlannedRetirements,
172
+ ...(preview ? { nativeCliRunner: bindNativeCliRunnerSignal(runtime.nativeCliRunner ?? getDefaultNativeCliRunner(), runtime.signal) } : {}),
173
+ env: plan.options.env,
174
+ catalogOperationContext: plan.demand.catalogOperationContext,
175
+ previewOperationPlan: preview,
176
+ executionInput: {
177
+ context: plan.context,
178
+ requirements,
179
+ selectedTargets: (selectedTargets ?? nativeGroupTargets({ pluginIds, platform }))
180
+ .map((target) => ({ ...target, scope: plan.options.scope })),
181
+ preserveOtherObservedTargets: true,
182
+ },
183
+ },
184
+ });
185
+ if (preview)
186
+ runtime.signal?.throwIfAborted();
187
+ return result;
188
+ }
189
+ function nativeResults(plan, group, result, executed) {
190
+ for (const diagnostic of result.recoveryDiagnostics ?? []) {
191
+ if (!plan.receipt.blockers.some((entry) => JSON.stringify(entry) === JSON.stringify(diagnostic)))
192
+ plan.receipt.blockers.push(diagnostic);
193
+ }
194
+ if (executed && result.commandResults?.length) {
195
+ plan.receipt.commandResults = [...new Map([
196
+ ...(plan.receipt.commandResults ?? []), ...result.commandResults,
197
+ ].map((entry) => [getCommandPackageId(entry.producer), entry])).values()];
198
+ }
199
+ for (const { pluginId, platform } of nativeGroupTargets(group)) {
200
+ const agent = agentForPlatform(platform);
201
+ const target = pair(plan, pluginId, agent);
202
+ if (!target)
203
+ continue;
204
+ const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
205
+ target.backend = backend;
206
+ target.recoveryActions = backend.recoveryActions;
207
+ const backendTargets = result.targetResults.filter((entry) => entry.target.pluginId === pluginId
208
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope);
209
+ const deploymentPlans = new Map([
210
+ ...(group.preview.operationPlan?.deploymentPlans ?? []),
211
+ ...(result.operationPlan?.deploymentPlans ?? []),
212
+ ].filter((deployment) => deployment.binding.plugin.pluginId === pluginId
213
+ && deployment.binding.platform === platform && deployment.binding.scope.kind === plan.options.scope)
214
+ .map((deployment) => [deployment.binding.id, deployment]));
215
+ if (deploymentPlans.size)
216
+ target.deploymentPlans = [...deploymentPlans.values()];
217
+ const exclusions = [
218
+ ...(group.preview.deploymentExclusions ?? []),
219
+ ...(result.deploymentExclusions ?? []),
220
+ ...(group.preview.operationPlan?.deploymentExclusions ?? []),
221
+ ...(result.operationPlan?.deploymentExclusions ?? []),
222
+ ...result.rebuildResults.flatMap((entry) => entry.deploymentExclusions ?? []),
223
+ ].filter((entry) => entry.pluginId === pluginId && entry.platform === platform && entry.scope.kind === plan.options.scope);
224
+ if (exclusions.length)
225
+ target.deploymentExclusions = [...new Map(exclusions.map((entry) => [JSON.stringify([entry.pluginId, entry.platform, entry.scope, entry.productId, entry.reasonCode]), entry])).values()];
226
+ const dependencies = result.dependencyPlan?.targets.filter((entry) => entry.platform === platform && (entry.pluginId === pluginId || entry.requiredBy?.includes(pluginId))) ?? [];
227
+ const producers = (result.commandResults ?? []).filter((entry) => {
228
+ if (entry.producer.platform !== null && entry.producer.platform !== platform)
229
+ return false;
230
+ if (entry.producer.platform === null) {
231
+ // Package identity is shared by AW; its declaration defines the Native consumers.
232
+ const plugin = plan.demand.plugins.find((plugin) => plugin.sourceId === entry.producer.sourceId
233
+ && plugin.sourceIdentity === entry.producer.sourceIdentity
234
+ && plugin.manifest.name === entry.producer.pluginName);
235
+ const declaration = plugin?.manifest.managedCommands?.packages.find((declaration) => declaration.key === entry.producer.key && declaration.scope === entry.producer.scope);
236
+ if (!declaration?.platforms.includes(platform)
237
+ || entry.producer.scope === 'project' && entry.producer.projectRoot !== plan.context.projectRoot)
238
+ return false;
239
+ }
240
+ const producerPluginId = `${entry.producer.sourceId}/${entry.producer.pluginName}`;
241
+ return producerPluginId === pluginId
242
+ || dependencies.some((dependency) => dependency.pluginId === producerPluginId)
243
+ || result.targetResults.some((target) => target.target.pluginId === producerPluginId
244
+ && target.target.platform === platform && target.requiredBy?.includes(pluginId)
245
+ && target.target.scope === (result.dependencyPlan?.targets.find((dependency) => dependency.pluginId === producerPluginId && dependency.platform === platform)?.resolvedScope
246
+ ?? plan.options.scope));
247
+ });
248
+ for (const failure of backendTargets.filter((entry) => entry.state === 'failed')) {
249
+ block(target, failure.errorCode ?? 'nativeRecoveryFailed');
250
+ }
251
+ // Keep checked recovery locations even when preparation stops before execution.
252
+ const nativeDiagnostics = result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId
253
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope)
254
+ .flatMap((entry) => entry.deploymentReceipts ?? [])
255
+ .flatMap((entry) => [...entry.diagnostics, ...entry.effects.flatMap((effect) => effect.diagnostics)])
256
+ .filter((entry) => entry.detail);
257
+ for (const entry of nativeDiagnostics) {
258
+ const destination = entry.severity === 'error' ? target.blockers : (target.reasons ??= []);
259
+ const detail = { code: entry.code, message: entry.message, subject: entry.subject, detail: entry.detail };
260
+ if (!destination.some((previous) => JSON.stringify(previous) === JSON.stringify(detail)))
261
+ destination.push(detail);
262
+ }
263
+ for (const dependency of dependencies.filter((entry) => entry.action === 'block')) {
264
+ block(target, dependency.errorCode ?? 'dependencyNotReady');
265
+ }
266
+ for (const dependency of dependencies.filter((entry) => entry.pluginId !== pluginId)) {
267
+ for (const failure of result.targetResults.filter((entry) => entry.target.pluginId === dependency.pluginId
268
+ && entry.target.platform === dependency.platform && entry.target.scope === dependency.resolvedScope && entry.state === 'failed')) {
269
+ const code = failure.errorCode ?? 'dependencyNotReady';
270
+ block(target, code, { ...diagnostic(code), pluginId: dependency.pluginId });
271
+ }
272
+ }
273
+ if (executed) {
274
+ const deployments = result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId
275
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope)
276
+ .flatMap((entry) => entry.deploymentReceipts ?? []);
277
+ if (deployments.length)
278
+ target.deploymentReceipts = deployments.map((entry) => ({ ...entry,
279
+ products: deploymentPlans.get(entry.bindingId)?.binding.consumers ?? [],
280
+ }));
281
+ const commandFailures = producers.filter((entry) => entry.state !== 'completed');
282
+ for (const producer of commandFailures) {
283
+ for (const error of producer.errors)
284
+ block(target, error.code);
285
+ if (producer.errors.length === 0)
286
+ block(target, 'managedCommandRecoveryFailed');
287
+ }
288
+ const succeeded = commandFailures.length === 0 && backendTargets.length > 0
289
+ && backendTargets.every((entry) => entry.state === 'completed');
290
+ const effects = deployments.flatMap((entry) => entry.effects);
291
+ const changed = effects.some((effect) => effect.mutation !== 'none');
292
+ if (succeeded) {
293
+ const unchanged = deployments.length > 0 ? effects.every((effect) => effect.status === 'unchanged')
294
+ : backendTargets.every((entry) => entry.action === 'skipped');
295
+ target.execution = unchanged ? 'no-op' : 'applied';
296
+ }
297
+ else {
298
+ const blockedByDependency = !changed && backendTargets.length > 0
299
+ && backendTargets.every((entry) => entry.errorCode === 'dependencyInstallFailed')
300
+ && result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId && entry.target.platform === platform
301
+ && entry.target.scope === plan.options.scope).every((entry) => !entry.cleanupAttempted && entry.actions.length === 0);
302
+ target.execution = blockedByDependency ? 'not-run'
303
+ : changed || backendTargets.some((entry) => entry.state === 'completed') ? 'partial' : 'failed';
304
+ }
305
+ plan.receipt.outputsMayHaveChanged ||= changed;
306
+ if (succeeded && (plan.command === 'cleanup' || plan.command === 'uninstall')) {
307
+ const completed = result.rebuildResults.filter((entry) => entry.target.pluginId === pluginId
308
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope);
309
+ const footprints = result.nativeFootprints?.filter((entry) => entry.pluginId === pluginId
310
+ && entry.platform === platform && entry.scope === plan.options.scope);
311
+ const absent = completed.length > 0 && footprints !== undefined && footprints.length > 0
312
+ && footprints.every((entry) => !entry.shared)
313
+ && completed.every((entry) => entry.status === 'succeeded' && entry.cleanupAttempted
314
+ && entry.removed.length + entry.absent.length > 0 && entry.residual.length === 0
315
+ && entry.quarantined.length === 0 && entry.failures.length === 0);
316
+ target.observation = absent ? 'missing' : 'unknown';
317
+ target.content = absent ? 'absent' : 'unknown';
318
+ }
319
+ else {
320
+ target.observation = succeeded ? 'verified' : 'unknown';
321
+ target.content = succeeded ? 'satisfied' : 'unknown';
322
+ }
323
+ if (!succeeded && !target.blockers.length)
324
+ block(target, 'nativeRecoveryFailed');
325
+ }
326
+ }
327
+ }
328
+ /** All scopes share one final marketplace generation before Review is returned. */
329
+ export async function refreshRecoveryNativePreviews(plan) {
330
+ for (const group of plan.nativeGroups) {
331
+ group.preview = await nativeOperation(plan, group.pluginIds, group.platform, true, plan.runtime, group.command, nativeGroupTargets(group));
332
+ nativeResults(plan, group, group.preview, false);
333
+ }
334
+ completeReceipt(plan.receipt);
335
+ }
336
+ function portableRequiredBy(plan, prepared, target) {
337
+ return plan.portableGroups.filter((group) => group.logicalIdentity === prepared.logicalIdentity
338
+ && group.targets.some((entry) => entry.providerPluginId === target.providerPluginId
339
+ && entry.expectedDigest === target.expectedDigest && entry.physicalPath === target.physicalPath))
340
+ .map((group) => group.options.selector);
341
+ }
342
+ function portableResults(plan, prepared) {
343
+ for (const agent of prepared.options.agents) {
344
+ const target = pair(plan, prepared.options.selector, agent);
345
+ const observations = prepared.targets.filter((entry) => entry.agent === agent);
346
+ const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
347
+ if (gaps.length)
348
+ target.componentGaps = gaps;
349
+ target.content = observations.some((entry) => entry.observation === 'conflict') ? 'conflict'
350
+ : observations.some((entry) => entry.observation === 'unknown') ? 'unknown'
351
+ : observations.some((entry) => entry.observation === 'drifted') ? 'drifted'
352
+ : observations.some((entry) => entry.observation === 'absent') ? 'absent'
353
+ : observations.length || prepared.intentionalEmpty && gaps.length === 0 ? 'satisfied' : 'unknown';
354
+ if (gaps.length && target.content !== 'conflict')
355
+ target.content = 'unknown';
356
+ target.observation = target.content === 'satisfied' ? 'verified'
357
+ : target.content === 'absent' ? 'missing' : 'unknown';
358
+ for (const gap of gaps)
359
+ plan.changes.push(`组件未满足 · ${gap.providerPluginId} · ${gap.componentId ?? gap.id} · ${gap.reasonCode}`
360
+ + gap.requiredFeatures.map((requirement) => ` · ${requirement.feature}${requirement.values ? `: ${requirement.values.join(', ')}` : ''}`).join(''));
361
+ for (const code of [...prepared.globalBlockers, ...observations.flatMap((entry) => entry.blocker
362
+ && !(entry.disposition === 'retain' && entry.blocker === 'portableComponentsUnmet') ? [entry.blocker] : [])]) {
363
+ block(target, code, portablePreparationDiagnostic(prepared, diagnostic(code), agent));
364
+ }
365
+ target.backend = observations.map((entry) => ({ skill: entry.skill, providerPluginId: entry.providerPluginId,
366
+ requiredBy: portableRequiredBy(plan, prepared, entry), observation: entry.observation,
367
+ ownership: entry.ownership, associatedAgents: entry.associatedAgents }));
368
+ target.recoveryActions = portableRecoveryActions(plan, target.pluginId, observations.filter((entry) => ['conflict', 'unknown'].includes(entry.observation)));
369
+ }
370
+ }
371
+ function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
372
+ const target = pair(plan, prepared.options.selector, agent);
373
+ const contentOutcomes = outcomes.filter((entry) => entry.disposition !== 'remove');
374
+ const preparedTargets = prepared.targets.filter((entry) => entry.agent === agent);
375
+ const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
376
+ if (gaps.length)
377
+ target.componentGaps = gaps;
378
+ const intentionalEmpty = prepared.mode === 'deploy' && prepared.intentionalEmpty && gaps.length === 0 && prepared.blockers.length === 0
379
+ && globalBlockers.length === 0 && preparedTargets.every((entry) => entry.disposition === 'remove')
380
+ && outcomes.length === preparedTargets.length
381
+ && outcomes.every((entry) => entry.observation === 'absent' && entry.blockers.length === 0
382
+ && ['applied', 'no-op'].includes(entry.execution));
383
+ target.execution = (prepared.mode === 'cleanup' || intentionalEmpty) && outcomes.length === 0 && !globalBlockers.length ? 'no-op' : outcomes.length > 0 && outcomes.every((entry) => entry.execution === 'no-op') ? 'no-op'
384
+ : outcomes.length > 0 && outcomes.every((entry) => ['applied', 'no-op'].includes(entry.execution)) ? 'applied'
385
+ : outcomes.some((entry) => ['applied', 'no-op'].includes(entry.execution)) ? 'partial'
386
+ : outcomes.some((entry) => entry.execution === 'failed') ? 'failed' : 'not-run';
387
+ target.observation = contentOutcomes.length > 0 && contentOutcomes.every((entry) => entry.observation === 'satisfied')
388
+ && globalBlockers.length === 0 ? 'verified'
389
+ : globalBlockers.length === 0 && contentOutcomes.some((entry) => entry.observation === 'absent'
390
+ || entry.observation === 'drifted') && contentOutcomes.every((entry) => entry.observation !== 'unknown'
391
+ && entry.observation !== 'conflict') ? 'missing' : 'unknown';
392
+ target.content = contentOutcomes.some((entry) => entry.observation === 'conflict') ? 'conflict'
393
+ : contentOutcomes.some((entry) => entry.observation === 'unknown') ? 'unknown'
394
+ : contentOutcomes.some((entry) => entry.observation === 'drifted') ? 'drifted'
395
+ : contentOutcomes.some((entry) => entry.observation === 'absent') ? 'absent'
396
+ : contentOutcomes.length ? 'satisfied' : 'unknown';
397
+ if (prepared.mode === 'cleanup' && globalBlockers.length === 0
398
+ && outcomes.every((entry) => entry.observation === 'absent' && entry.blockers.length === 0)) {
399
+ target.observation = 'missing';
400
+ target.content = 'absent';
401
+ }
402
+ else if (intentionalEmpty) {
403
+ target.observation = 'verified';
404
+ target.content = 'satisfied';
405
+ }
406
+ if (gaps.length) {
407
+ if (target.execution === 'applied' || target.execution === 'no-op')
408
+ target.execution = 'partial';
409
+ if (target.content !== 'conflict')
410
+ target.content = 'unknown';
411
+ target.observation = 'unknown';
412
+ block(target, 'portableComponentsUnmet');
413
+ }
414
+ target.backend = outcomes.map((entry) => ({ skill: entry.skill, providerPluginId: entry.providerPluginId,
415
+ requiredBy: portableRequiredBy(plan, prepared, entry), observation: entry.observation,
416
+ ownership: entry.ownership, associatedAgents: entry.associatedAgents,
417
+ execution: entry.execution, blockers: entry.blockers }));
418
+ for (const code of [...globalBlockers, ...outcomes.flatMap((entry) => entry.blockers)])
419
+ block(target, code);
420
+ target.recoveryActions = portableRecoveryActions(plan, target.pluginId, outcomes.filter((entry) => ['conflict', 'unknown'].includes(entry.observation)));
421
+ }
422
+ function portablePluginClosure(plan, prepared) {
423
+ const { sourceId, pluginName } = parsePluginId(prepared.options.selector);
424
+ return resolvePluginMetaDependencyClosure(plan.demand.plugins.filter((plugin) => plugin.sourceId === sourceId), [pluginName])
425
+ .filter((plugin) => !prepared.options.excludedPluginIds?.includes(plugin.pluginId));
426
+ }
427
+ function preparePortablePreApplyAuthorization(plan) {
428
+ if (plan.command === 'cleanup' || plan.command === 'uninstall')
429
+ return;
430
+ const authorization = new Map();
431
+ for (const prepared of plan.portableGroups) {
432
+ for (const plugin of portablePluginClosure(plan, prepared)) {
433
+ if (!plugin.manifest.scripts?.preApply)
434
+ continue;
435
+ for (const platform of prepared.options.agents) {
436
+ if (pair(plan, prepared.options.selector, platform)?.blockers.length)
437
+ continue;
438
+ const target = {
439
+ pluginId: plugin.pluginId, pluginName: plugin.manifest.name,
440
+ sourceId: plugin.sourceId, sourceIdentity: plugin.sourceIdentity,
441
+ platform, scope: plan.options.scope,
442
+ relation: plugin.pluginId === prepared.options.selector ? 'requested'
443
+ : plan.demand.plugins.find((entry) => entry.pluginId === prepared.options.selector)?.manifest.dependencies?.includes(plugin.manifest.name)
444
+ ? 'direct' : 'transitive',
445
+ };
446
+ authorization.set([target.pluginId, target.platform, target.scope].join('\0'), target);
447
+ }
448
+ }
449
+ }
450
+ plan.preApplyAuthorization = [...authorization.values()];
451
+ plan.changes.push(...plan.preApplyAuthorization.map((target) => `运行插件 preApply 脚本:${target.pluginId} / ${target.platform} / ${target.scope}。`));
452
+ }
453
+ async function executePortablePreApply(plan, prepared, agent, runtime) {
454
+ if (prepared.mode === 'cleanup' || plan.command === 'cleanup' || plan.command === 'uninstall')
455
+ return;
456
+ const plugins = portablePluginClosure(plan, prepared);
457
+ const required = plan.preApplyAuthorization?.filter((target) => target.platform === agent
458
+ && plugins.some((plugin) => plugin.pluginId === target.pluginId)) ?? [];
459
+ return executePreApplyAuthorization(plan, required, runtime);
460
+ }
461
+ async function executePreApplyAuthorization(plan, required, runtime) {
462
+ if (!required.length)
463
+ return;
464
+ if (plan.options.yes !== true && runtime.preApplyConfirmed !== true)
465
+ return 'preApplyAuthorizationRequired';
466
+ const cache = runtime.preApplyExecutionCache ??= new Map();
467
+ for (const target of required) {
468
+ const plugin = plan.demand.plugins.find((entry) => entry.pluginId === target.pluginId);
469
+ if (!plugin || plugin.sourceIdentity !== target.sourceIdentity)
470
+ return 'sourceUnavailable';
471
+ const context = target.scope === plan.options.scope ? plan.context
472
+ : await createScopeContext({ scope: target.scope, cwd: plan.context.callerCwd, env: plan.options.env });
473
+ try {
474
+ const projectKey = target.scope !== 'project' ? '' : target.platform === 'codex'
475
+ ? await resolveCodexProjectKey(context.executionCwd) : target.platform === 'claude'
476
+ ? await resolveClaudeProjectKey(context.executionCwd) : context.projectKey;
477
+ const key = [target.sourceIdentity, target.pluginId, target.platform, target.scope, projectKey].join('\0');
478
+ let execution = cache.get(key);
479
+ if (!execution) {
480
+ execution = runPreApplyScript({ plugin, platform: target.platform, scope: target.scope,
481
+ cwd: context.executionCwd, context: { env: context.env, interruption: runtime.interruption },
482
+ referencePlugins: plan.demand.plugins, scriptTimeoutMs: plan.options.scriptTimeoutMs });
483
+ cache.set(key, execution);
484
+ }
485
+ await execution;
486
+ }
487
+ catch (error) {
488
+ runtime.signal?.throwIfAborted();
489
+ if (error instanceof Error && error.name === 'AbortError')
490
+ throw error;
491
+ const operationDiagnostic = readSafeOperationError(error);
492
+ const affected = pair(plan, target.pluginId, target.platform);
493
+ if (affected) {
494
+ affected.execution = 'failed';
495
+ block(affected, 'preApplyFailed');
496
+ if (affected.delivery?.kind === 'native') {
497
+ const identity = { pluginId: target.pluginId, pluginName: plugin.manifest.name, pluginVersion: plugin.manifest.version,
498
+ sourceId: plugin.sourceId, sourceIdentity: target.sourceIdentity, platform: affected.delivery.platform,
499
+ scope: target.scope, cwd: context.executionCwd };
500
+ const failure = { phase: 'preApply', message: operationDiagnostic?.safeMessage ?? 'The preApply script failed.',
501
+ ...(operationDiagnostic ? { operationDiagnostic } : {}) };
502
+ affected.backend = buildRebuildReceiptJson(plan.command, { platforms: [target.platform], plugins: [], warnings: [],
503
+ targetResults: [{ target: identity, action: 'install', state: 'failed', errorCode: 'preApplyFailed' }],
504
+ rebuildResults: [{ status: 'failed', command: plan.command, target: identity, actions: [{ name: 'preApply', status: 'failed' }],
505
+ cleanupAttempted: false, removed: [], absent: [], residual: [], quarantined: [], failures: [failure], error: failure }] });
506
+ }
507
+ }
508
+ return 'preApplyFailed';
509
+ }
510
+ finally {
511
+ if (context !== plan.context)
512
+ await context.dispose();
513
+ }
514
+ }
515
+ }
516
+ /** Run the reviewed replacement's hooks before any dependent old-output cleanup. */
517
+ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
518
+ if (plan.command === 'cleanup' || plan.command === 'uninstall')
519
+ return;
520
+ if (plan.receipt.nativeToolChanges?.length && plan.options.yes !== true)
521
+ return 'nativeToolAuthorizationRequired';
522
+ const target = pair(plan, pluginId, agent);
523
+ if (!target)
524
+ return 'preApplyTargetUnavailable';
525
+ if (target.blockers.length)
526
+ return target.blockers[0].code;
527
+ if (target.delivery?.kind === 'native') {
528
+ const platform = target.delivery.platform;
529
+ try {
530
+ const authorization = await nativeOperation(plan, [pluginId], platform, true, { ...runtime, resolvePreApplyAuthorization: true }, plan.command, [{ pluginId, platform }]);
531
+ if (authorization.overallState !== 'succeeded' || !authorization.preApplyAuthorization) {
532
+ return authorization.targetResults.find((result) => result.errorCode)?.errorCode ?? 'preApplyAuthorizationUnavailable';
533
+ }
534
+ const blocked = authorization.dependencyPlan?.targets.find((entry) => entry.action === 'block'
535
+ && (entry.pluginId === pluginId || entry.requiredBy.includes(pluginId)));
536
+ if (blocked)
537
+ return blocked.errorCode ?? 'nativePreparationFailed';
538
+ return executePreApplyAuthorization(plan, authorization.preApplyAuthorization, runtime);
539
+ }
540
+ catch (error) {
541
+ runtime.signal?.throwIfAborted();
542
+ if (error instanceof Error && error.name === 'AbortError')
543
+ throw error;
544
+ return readSafeOperationError(error)?.code ?? errorCode(error, 'nativePreparationFailed');
545
+ }
546
+ }
547
+ if (isPortableAgent(agent)) {
548
+ const prepared = plan.portableGroups.find((group) => group.options.selector === pluginId
549
+ && group.options.agents.includes(agent));
550
+ if (prepared)
551
+ return executePortablePreApply(plan, prepared, agent, runtime);
552
+ }
553
+ }
554
+ async function checkFootprints(plan) {
555
+ const footprints = [];
556
+ for (const [nativeGroup, group] of plan.nativeGroups.entries()) {
557
+ const actions = group.preview.operationPlan?.actions.filter((action) => (action.kind === 'writeOwnedArtifact' || action.kind === 'removeOwnedArtifact')
558
+ && !group.preview.nativeFootprints?.some((footprint) => footprint.path === action.path
559
+ && footprint.pluginId === action.pluginId && footprint.platform === action.platform)) ?? [];
560
+ for (const action of [...(group.preview.nativeFootprints ?? []), ...actions]) {
561
+ if (!('path' in action))
562
+ continue;
563
+ const consumers = group.preview.dependencyPlan?.targets.filter((target) => target.pluginId === action.pluginId)
564
+ .flatMap((target) => target.requiredBy ?? []) ?? [];
565
+ footprints.push({ path: await canonicalizePathThroughExistingAncestor(action.path),
566
+ pluginIds: group.pluginIds.filter((id) => id === action.pluginId || consumers.includes(id)),
567
+ agent: agentForPlatform(action.platform), identity: `native:${action.platform}:${action.pluginId}`,
568
+ sharedNative: 'shared' in action && action.shared,
569
+ ...('sharedMarketplace' in action && action.sharedMarketplace
570
+ ? { sharedMarketplaceSource: parsePluginId(action.pluginId).sourceId } : {}),
571
+ nativeGroup });
572
+ }
573
+ }
574
+ for (const prepared of plan.portableGroups) {
575
+ for (const target of prepared.targets)
576
+ footprints.push({
577
+ path: await canonicalizePathThroughExistingAncestor(target.physicalPath),
578
+ pluginIds: [prepared.options.selector], agent: target.agent,
579
+ identity: `agent-skills:${prepared.logicalIdentity}:${target.providerPluginId}:${target.expectedDigest}`,
580
+ });
581
+ }
582
+ for (let index = 0; index < footprints.length; index += 1) {
583
+ const left = footprints[index];
584
+ for (const right of footprints.slice(index + 1)) {
585
+ if (left.path !== right.path || left.identity === right.identity
586
+ || (left.nativeGroup !== undefined && left.nativeGroup === right.nativeGroup)
587
+ || (left.sharedMarketplaceSource !== undefined
588
+ && left.sharedMarketplaceSource === right.sharedMarketplaceSource)
589
+ || (left.sharedNative && right.sharedNative && left.agent === right.agent))
590
+ continue;
591
+ for (const footprint of [left, right]) {
592
+ for (const pluginId of footprint.pluginIds) {
593
+ const target = pair(plan, pluginId, footprint.agent);
594
+ if (target)
595
+ block(target, 'artifactCollision');
596
+ }
597
+ }
598
+ }
599
+ }
600
+ for (const prepared of plan.portableGroups) {
601
+ const layout = portableRecoveryLayout(plan.context);
602
+ plan.changes.push(`${prepared.options.selector}:AW 写入所选 Agent 的 owned Skill 目录;准备目录 ${layout.generationRoot}。`);
603
+ }
604
+ }
605
+ export async function prepareScopedRecovery(command, selectors, options, runtime = {}) {
606
+ runtime = { ...runtime, preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
607
+ options.signal?.throwIfAborted();
608
+ const context = await createScopeContext({ scope: options.scope, cwd: options.cwd, env: options.env });
609
+ try {
610
+ options.signal?.throwIfAborted();
611
+ options = { ...options, cwd: context.executionCwd, env: context.env };
612
+ let demand = options.demandOverride ?? await readDemand({ ...options, preferences: undefined });
613
+ const refreshFailures = new Map();
614
+ const sourceRefreshes = [];
615
+ if (options.refresh && command === 'sync') {
616
+ let selected = [];
617
+ try {
618
+ selected = selectRoots(demand, selectors, options.all ?? false);
619
+ }
620
+ catch { /* Selection below reports the invalid request without refreshing any source. */ }
621
+ if (selected.length > 0) {
622
+ const config = await readCatalogSourcesConfigSnapshot(options.env);
623
+ const generationState = await readCatalogGenerationState(options.env);
624
+ for (const sourceId of new Set(selected.map((id) => parsePluginId(id).sourceId))) {
625
+ try {
626
+ const source = config.config.sources.find((entry) => entry.id === sourceId);
627
+ const probe = await probeCatalogSourceGeneration({ sourceId, env: options.env,
628
+ cliVersion: options.cliVersion, signal: options.signal, runtime: runtime.catalogGenerationRuntime });
629
+ const previousActive = generationState.sources[sourceId]?.active ?? null;
630
+ const candidateChanged = !previousActive
631
+ || previousActive.sourceConfigFingerprint !== probe.candidate.sourceConfigFingerprint
632
+ || previousActive.sourceIdentity !== probe.candidate.sourceIdentity
633
+ || previousActive.logicalIdentity !== probe.candidate.logicalIdentity
634
+ || previousActive.requestedRef !== probe.candidate.requestedRef
635
+ || previousActive.manifestDigest !== probe.candidate.manifestDigest
636
+ || previousActive.snapshotDigest !== probe.candidate.snapshotDigest
637
+ || previousActive.resolvedCommit !== probe.candidate.resolvedCommit;
638
+ if (!candidateChanged)
639
+ continue;
640
+ const inspectImpact = runtime.catalogGenerationRuntime?.inspectSourceImpact
641
+ ?? inspectCatalogSourceImpact;
642
+ const impact = await inspectImpact({ sourceId, cwd: options.cwd, env: options.env,
643
+ sourcePrimary: source?.primary === true, mode: 'generation', candidateManifest: probe.manifest });
644
+ sourceRefreshes.push({ sourceId, candidate: probe.candidate, previousActive,
645
+ configDigest: config.digest, impact, impactDigest: calculateCatalogSourceImpactDigest(impact) });
646
+ }
647
+ catch (error) {
648
+ options.signal?.throwIfAborted();
649
+ if (error instanceof Error && error.name === 'AbortError')
650
+ throw error;
651
+ const code = errorCode(error, 'catalogGenerationRefreshFailed');
652
+ refreshFailures.set(sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
653
+ }
654
+ }
655
+ }
656
+ }
657
+ options.signal?.throwIfAborted();
658
+ const preparationRuntime = { ...runtime, signal: options.signal };
659
+ const originalIntent = intentEvidence(demand.intent);
660
+ const proposed = command === 'install'
661
+ ? await addRequirements({ ...options, selectors, dryRun: true, installSelectors: true }) : undefined;
662
+ if (proposed?.state && proposed.errors.length === 0) {
663
+ const rawBytes = Buffer.from(JSON.stringify(proposed.state));
664
+ demand = await readDemand({ ...options, preferences: undefined, intent: {
665
+ state: 'valid', value: proposed.state, rawBytes,
666
+ digest: calculateIntentDigest(proposed.state), rawDigest: originalIntent,
667
+ } });
668
+ }
669
+ const receipt = {
670
+ schemaVersion: 1, kind: 'aw-recovery', scope: options.scope, command, ok: false,
671
+ intent: { state: demand.intent.state, ...('digest' in demand.intent ? { digest: demand.intent.digest } : {}),
672
+ roots: demand.roots?.map((root) => root.pluginId) ?? null },
673
+ requestedRoots: [], requestedTargets: [], selection: { agents: [], origin: 'none', preferences: demand.preferences.state },
674
+ blockers: proposed?.errors ?? [], errors: [], targetResults: [], remainingTargets: [], recoveryActions: [],
675
+ declarationChanged: false, preferencesChanged: false, configChanged: false, outputsMayHaveChanged: false,
676
+ };
677
+ const { signal: _signal, ...executionOptions } = options;
678
+ const plan = { command, options: executionOptions, receipt, demand, context, originalIntent,
679
+ plannedImpact: { declaration: proposed?.changed === true, preferences: false, config: false, outputs: false },
680
+ preferencesEvidence: preferenceEvidence(demand), changes: [], warnings: [],
681
+ nativeGroups: [], portableGroups: [],
682
+ portableProtectionGroups: [], runtime,
683
+ portableResidues: [], sourceRefreshes,
684
+ sourceRefreshFailures: [...refreshFailures].map(([sourceId, code]) => ({ sourceId, code })),
685
+ blockExecution: false,
686
+ ...(proposed?.state && proposed.errors.length === 0 ? { declaration: proposed.roots } : {}),
687
+ };
688
+ if (proposed?.changed)
689
+ plan.changes.push(`保存 ${options.scope} 插件需求:${proposed.roots.join('、')}。`);
690
+ const preciseCleanup = (command === 'cleanup' || command === 'uninstall') && selectors.length > 0
691
+ && options.targets !== undefined;
692
+ try {
693
+ receipt.selection = selectAgents({ preferences: preciseCleanup ? { state: 'absent' } : demand.preferences,
694
+ targets: options.targets });
695
+ receipt.requestedRoots = preciseCleanup ? [...new Set(selectors.map((selector) => {
696
+ const parsed = parsePluginId(selector);
697
+ if (!parsed.sourceId)
698
+ throw new Error('cleanupPluginIdRequired');
699
+ return `${parsed.sourceId}/${parsed.pluginName}`;
700
+ }))] : selectRoots(demand, selectors, options.all ?? false);
701
+ }
702
+ catch (error) {
703
+ receipt.blockers.push(diagnostic(errorCode(error, 'projectSelectionInvalid')));
704
+ }
705
+ if (options.exactTargets && (options.exactTargets.length === 0 || options.exactTargets.some((target) => !receipt.requestedRoots.includes(target.pluginId) || !receipt.selection.agents.includes(target.agent)))) {
706
+ receipt.blockers.push(diagnostic('invalidExactTargets'));
707
+ }
708
+ if (!preciseCleanup) {
709
+ if (!['valid', 'absent'].includes(demand.intent.state))
710
+ receipt.blockers.push(diagnostic('pluginIntentStateInvalid'));
711
+ }
712
+ if (receipt.requestedRoots.length && !receipt.selection.agents.length)
713
+ receipt.blockers.push(diagnostic('localTargetsRequired'));
714
+ if (!preciseCleanup)
715
+ receipt.blockers.push(...demand.errors);
716
+ plan.blockExecution = Boolean(proposed?.errors.length)
717
+ || receipt.blockers.length > 0;
718
+ for (const [sourceId, code] of refreshFailures) {
719
+ receipt.blockers.push({ code, message: `${sourceId}:${diagnostic('sourceRefreshFailed').message}` });
720
+ }
721
+ for (const root of demand.roots ?? []) {
722
+ if (!receipt.requestedRoots.includes(root.pluginId) || preciseCleanup)
723
+ continue;
724
+ receipt.blockers.push(...root.blockers.map((code) => ({ ...diagnostic(code), message: `${root.pluginId}:${diagnostic(code).message}` })));
725
+ }
726
+ for (const pluginId of receipt.requestedRoots) {
727
+ const root = demand.roots?.find((entry) => entry.pluginId === pluginId);
728
+ const agents = receipt.selection.agents;
729
+ for (const agent of agents) {
730
+ if (options.exactTargets
731
+ && !options.exactTargets.some((target) => target.pluginId === pluginId && target.agent === agent))
732
+ continue;
733
+ const resolvedDelivery = root?.plugin ? resolveDelivery(root.plugin.manifest, agent, options.scope) ?? null : null;
734
+ const delivery = preciseCleanup ? isPortableAgent(agent)
735
+ ? { kind: 'agent-skills', provider: 'aw', agentId: 'generic' }
736
+ : { kind: 'native', platform: agent } : resolvedDelivery;
737
+ receipt.targetResults.push({ pluginId, agent, scope: options.scope, delivery, execution: 'not-run', observation: 'unknown',
738
+ blockers: [...(preciseCleanup ? [] : root?.blockers ?? []).map(diagnostic),
739
+ ...(refreshFailures.has(parsePluginId(pluginId).sourceId)
740
+ ? [diagnostic(refreshFailures.get(parsePluginId(pluginId).sourceId))] : []),
741
+ ...(!delivery ? [diagnostic(preciseCleanup ? 'backend-action-unsupported' : 'deliveryUnsupported')] : [])],
742
+ requiredBy: [pluginId] });
743
+ }
744
+ }
745
+ if (plan.blockExecution)
746
+ return { ...plan, receipt: completeReceipt(receipt) };
747
+ if (sourceRefreshes.length > 0) {
748
+ for (const refresh of sourceRefreshes) {
749
+ plan.changes.push(`刷新 Catalog 来源 ${refresh.sourceId},确认后激活已检查的候选 generation。`);
750
+ if (!refresh.impact.inventoryComplete) {
751
+ plan.warnings.push(`${refresh.sourceId}:来源影响清单不完整,需要明确确认。`);
752
+ }
753
+ else if (refresh.impact.affectedReferences.length > 0) {
754
+ plan.warnings.push(`${refresh.sourceId}:来源更新会影响 ${refresh.impact.affectedReferences.length} 个已知引用,需要明确确认。`);
755
+ }
756
+ }
757
+ return { ...plan, receipt: completeReceipt(receipt) };
758
+ }
759
+ const groups = new Map();
760
+ for (const target of receipt.targetResults) {
761
+ if (target.blockers.length || target.delivery?.kind !== 'native')
762
+ continue;
763
+ const command = plan.command;
764
+ const key = `${parsePluginId(target.pluginId).sourceId}\0${target.delivery.platform}\0${command}`;
765
+ const group = groups.get(key) ?? { command, targets: [] };
766
+ group.targets.push({ pluginId: target.pluginId, platform: target.delivery.platform });
767
+ groups.set(key, group);
768
+ }
769
+ for (const pending of groups.values()) {
770
+ const group = { ...nativeTargetSelection(pending.targets), command: pending.command };
771
+ if (group.targets.length === 0)
772
+ continue;
773
+ try {
774
+ const preview = await nativeOperation(plan, group.pluginIds, group.platform, true, preparationRuntime, group.command, group.targets);
775
+ options.signal?.throwIfAborted();
776
+ const nativeGroup = { ...group, preview };
777
+ plan.nativeGroups.push(nativeGroup);
778
+ nativeResults(plan, nativeGroup, preview, false);
779
+ plan.changes.push(...(preview.operationPlan?.changes ?? []));
780
+ const nativeToolChanges = preview.operationPlan ? operationPlanNativeToolChanges(preview.operationPlan) : [];
781
+ if (nativeToolChanges.length)
782
+ receipt.nativeToolChanges = [...(receipt.nativeToolChanges ?? []), ...nativeToolChanges];
783
+ for (const change of nativeToolChanges) {
784
+ for (const [verb, closure] of [['撤销', change.before], ['使用', change.after]]) {
785
+ if (closure)
786
+ plan.changes.push(...describeNativeToolClosure(closure).map((description) => `${verb}原生工具 · ${change.producer.sourceId}/${change.producer.pluginName} · ${change.producer.key} · ${description}`));
787
+ }
788
+ }
789
+ for (const override of preview.dependencyPlan?.scopeOverrides ?? []) {
790
+ if (options.dependencyScopeOverrides?.some((requested) => requested.pluginId === override.pluginId
791
+ && (!requested.platform || requested.platform === override.platform))) {
792
+ plan.changes.push(`推导的依赖提供位置:${override.pluginId}#${override.platform}=${override.scope}。`);
793
+ }
794
+ }
795
+ plan.warnings.push(...preview.warnings);
796
+ }
797
+ catch (error) {
798
+ options.signal?.throwIfAborted();
799
+ if (error instanceof Error && error.name === 'AbortError')
800
+ throw error;
801
+ if (error instanceof CatalogSourceInventoryIncompleteError) {
802
+ receipt.blockers.push(...error.inventory.errors.map(inventoryRecoveryDiagnostic));
803
+ }
804
+ for (const { pluginId, platform } of group.targets) {
805
+ block(pair(plan, pluginId, agentForPlatform(platform)), errorCode(error, 'nativePreparationFailed'));
806
+ }
807
+ }
808
+ }
809
+ for (const pluginId of receipt.requestedRoots) {
810
+ const agents = receipt.targetResults.filter((target) => target.pluginId === pluginId
811
+ && !target.blockers.length && target.delivery?.kind === 'agent-skills').map((target) => target.agent).filter(isPortableAgent);
812
+ if (!agents.length)
813
+ continue;
814
+ try {
815
+ const prepared = command === 'cleanup' || command === 'uninstall'
816
+ ? await preparePortableCleanup({ scope: options.scope, context, selector: pluginId, agents, force: options.force, signal: options.signal })
817
+ : await preparePortableRecovery({ scope: options.scope, context, selector: pluginId, agents,
818
+ env: options.env, cliVersion: options.cliVersion, signal: options.signal,
819
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds });
820
+ plan.portableGroups.push(prepared);
821
+ }
822
+ catch (error) {
823
+ options.signal?.throwIfAborted();
824
+ if (error instanceof Error && error.name === 'AbortError')
825
+ throw error;
826
+ for (const agent of agents)
827
+ block(pair(plan, pluginId, agent), errorCode(error, 'portablePreparationFailed'));
828
+ }
829
+ }
830
+ for (const prepared of plan.portableGroups)
831
+ portableResults(plan, prepared);
832
+ preparePortablePreApplyAuthorization(plan);
833
+ if (command !== 'cleanup' && command !== 'uninstall') {
834
+ // Complete scope demand protects copies contributed by unselected roots and their dependencies.
835
+ const desiredAgents = new Set([...receipt.selection.agents,
836
+ ...(demand.preferences.state === 'valid' ? demand.preferences.value.targets : [])]);
837
+ const retainedPortableTargets = [];
838
+ for (const root of demand.roots ?? []) {
839
+ const portableAgents = [...desiredAgents].filter(isPortableAgent).filter((agent) => root.plugin
840
+ && resolveDelivery(root.plugin.manifest, agent, options.scope)?.kind === 'agent-skills');
841
+ if (!portableAgents.length)
842
+ continue;
843
+ try {
844
+ const prepared = plan.portableGroups.find((group) => group.options.selector === root.pluginId
845
+ && portableAgents.every((agent) => group.options.agents.some((item) => item === agent)))
846
+ ?? await preparePortableRecovery({ scope: options.scope, context, selector: root.pluginId,
847
+ env: options.env, agents: portableAgents, cliVersion: options.cliVersion, signal: options.signal,
848
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds });
849
+ if (!prepared.globalBlockers.length) {
850
+ retainedPortableTargets.push(...prepared.targets.filter((target) => !target.blocker && ['satisfied', 'drifted'].includes(target.observation)));
851
+ if (!plan.portableGroups.includes(prepared))
852
+ plan.portableProtectionGroups.push(prepared);
853
+ }
854
+ }
855
+ catch (error) {
856
+ options.signal?.throwIfAborted();
857
+ if (error instanceof Error && error.name === 'AbortError')
858
+ throw error;
859
+ // Missing current Portable evidence cannot protect historical residue.
860
+ }
861
+ }
862
+ }
863
+ options.signal?.throwIfAborted();
864
+ await checkFootprints(plan);
865
+ options.signal?.throwIfAborted();
866
+ for (const prepared of [...plan.portableGroups, ...plan.portableProtectionGroups]) {
867
+ delete prepared.options.signal;
868
+ }
869
+ plan.plannedImpact.outputs = !plan.blockExecution && (plan.nativeGroups.some((group) => (group.preview.operationPlan?.actions.length ?? 0) > 0
870
+ && nativeGroupTargets(group).some(({ pluginId, platform }) => pair(plan, pluginId, agentForPlatform(platform))?.blockers.length === 0))
871
+ || (plan.portableGroups.some((group) => group.targets.some((target) => pair(plan, group.options.selector, target.agent)?.blockers.length === 0
872
+ && (group.mode === 'cleanup' || target.observation === 'absent' || target.observation === 'drifted'
873
+ || (command === 'reinstall' && target.observation === 'satisfied' && target.ownership === 'aw'))))));
874
+ completeReceipt(receipt);
875
+ return plan;
876
+ }
877
+ catch (error) {
878
+ await context.dispose();
879
+ throw error;
880
+ }
881
+ }
882
+ export async function activateRecoverySourcesAndReprepare(plan, execution = {}) {
883
+ if (plan.sourceRefreshes.length === 0)
884
+ return plan;
885
+ const runtime = { ...plan.runtime, ...execution.runtime };
886
+ const failures = new Map(plan.sourceRefreshFailures.map(({ sourceId, code }) => [sourceId, code]));
887
+ try {
888
+ for (const refresh of plan.sourceRefreshes) {
889
+ try {
890
+ await activateCatalogSourceGeneration({
891
+ sourceId: refresh.sourceId,
892
+ cliVersion: plan.options.cliVersion,
893
+ cwd: plan.options.cwd,
894
+ env: plan.options.env,
895
+ impactConfirmed: true,
896
+ expectedImpactDigest: refresh.impactDigest,
897
+ expectedCandidate: refresh.candidate,
898
+ expectedActive: refresh.previousActive,
899
+ expectedConfigDigest: refresh.configDigest,
900
+ runtime: runtime.catalogGenerationRuntime,
901
+ });
902
+ }
903
+ catch (error) {
904
+ const code = errorCode(error, 'catalogGenerationRefreshFailed');
905
+ failures.set(refresh.sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
906
+ }
907
+ }
908
+ const failedSourceIds = new Set(failures.keys());
909
+ const originalExactTargets = plan.options.exactTargets
910
+ ?? plan.receipt.targetResults.map(({ pluginId, agent }) => ({ pluginId, agent }));
911
+ const exactTargets = failures.size > 0
912
+ ? originalExactTargets.filter((target) => !failedSourceIds.has(parsePluginId(target.pluginId).sourceId))
913
+ : plan.options.exactTargets;
914
+ const next = await prepareRecovery(plan.command, plan.receipt.requestedRoots, {
915
+ ...plan.options,
916
+ all: false,
917
+ refresh: false,
918
+ ...(exactTargets ? { exactTargets } : {}),
919
+ }, { ...runtime, preparedArtifactRenderResults: new Map() });
920
+ if (failures.size === 0)
921
+ return next;
922
+ if (exactTargets?.length === 0) {
923
+ next.receipt.blockers = next.receipt.blockers.filter((entry) => entry.code !== 'invalidExactTargets');
924
+ next.blockExecution = true;
925
+ }
926
+ for (const [sourceId, code] of failures) {
927
+ next.receipt.blockers.push({ code, message: `${sourceId}:${diagnostic('sourceRefreshFailed').message}` });
928
+ }
929
+ for (const target of plan.receipt.targetResults) {
930
+ const sourceId = parsePluginId(target.pluginId).sourceId;
931
+ const code = failures.get(sourceId);
932
+ if (!code || next.receipt.targetResults.some((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent))
933
+ continue;
934
+ const failed = structuredClone(target);
935
+ block(failed, code);
936
+ next.receipt.targetResults.push(failed);
937
+ }
938
+ next.receipt = completeReceipt(next.receipt);
939
+ return next;
940
+ }
941
+ finally {
942
+ await plan.context.dispose();
943
+ }
944
+ }
945
+ export async function executeScopedRecovery(plan, execution = {}) {
946
+ if (plan.sourceRefreshes.length > 0) {
947
+ const receipt = structuredClone(plan.receipt);
948
+ receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
949
+ await plan.context.dispose();
950
+ return completeReceipt(receipt);
951
+ }
952
+ const receipt = structuredClone(plan.receipt);
953
+ plan = { ...plan, receipt, options: { ...plan.options, yes: execution.yes ?? plan.options.yes },
954
+ runtime: { ...plan.runtime, ...execution.runtime } };
955
+ try {
956
+ if (receipt.nativeToolChanges?.length && plan.options.yes !== true) {
957
+ receipt.blockers.push(diagnostic('nativeToolAuthorizationRequired'));
958
+ return completeReceipt(receipt);
959
+ }
960
+ const freshContext = await createScopeContext({ scope: plan.options.scope,
961
+ cwd: plan.context.callerCwd, env: plan.options.env });
962
+ const environmentStable = freshContext.awHome === plan.context.awHome
963
+ && freshContext.generationRoot === plan.context.generationRoot
964
+ && freshContext.projectKey === plan.context.projectKey
965
+ && JSON.stringify(freshContext.targetHomes) === JSON.stringify(plan.context.targetHomes);
966
+ await freshContext.dispose();
967
+ const executionCwdStable = plan.options.scope !== 'user'
968
+ || await assertNeutralAncestorChain(plan.context.executionCwd)
969
+ .then((value) => value === plan.context.executionCwd, () => false);
970
+ if (!environmentStable || !executionCwdStable) {
971
+ receipt.blockers.push(diagnostic('operationReviewStale'));
972
+ return completeReceipt(receipt);
973
+ }
974
+ return await withAwHomeMutationLock({ env: plan.options.env, token: plan.runtime.awHomeMutationToken,
975
+ action: async (token) => {
976
+ const actualIntent = await observeIntent(plan.options);
977
+ const current = await readDemand({ ...plan.options, preferences: undefined, ...(plan.declaration || plan.options.demandOverride ? { intent: plan.demand.intent } : {}) });
978
+ if (intentEvidence(actualIntent) !== plan.originalIntent || preferenceEvidence(current) !== plan.preferencesEvidence
979
+ || current.catalogOperationContext?.generationSetDigest !== plan.demand.catalogOperationContext?.generationSetDigest) {
980
+ receipt.blockers.push(diagnostic('operationReviewStale'));
981
+ return completeReceipt(receipt);
982
+ }
983
+ const previewManager = plan.nativeGroups.map((group) => group.preview.codexManagerPreview)
984
+ .find((entry) => entry?.state === 'system');
985
+ const session = plan.runtime.codexObservationSession ?? (plan.nativeGroups.length ? await createCodexNativeObservationSession({
986
+ exactCwd: plan.context.executionCwd, env: plan.context.env,
987
+ runner: plan.runtime.nativeCliRunner ?? getDefaultNativeCliRunner(),
988
+ manager: plan.runtime.codexManager ?? (previewManager?.state === 'system'
989
+ ? previewManager.manager : undefined),
990
+ }) : undefined);
991
+ const nativeRuntime = { ...plan.runtime, awHomeMutationToken: token,
992
+ managedCommandProducerCache: plan.runtime.managedCommandProducerCache
993
+ ?? new Map(),
994
+ ...(session ? { codexObservationSession: session } : {}) };
995
+ try {
996
+ // Freeze every backend before the first declaration or output write.
997
+ const executableNativeGroups = [];
998
+ for (const group of plan.nativeGroups) {
999
+ const targets = nativeGroupTargets(group);
1000
+ const executable = targets.filter(({ pluginId, platform }) => !pair(plan, pluginId, agentForPlatform(platform)).blockers.length);
1001
+ if (executable.length === 0)
1002
+ continue;
1003
+ const checked = await nativeOperation(plan, group.pluginIds, group.platform, true, nativeRuntime, group.command, targets);
1004
+ if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint) {
1005
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1006
+ return completeReceipt(receipt);
1007
+ }
1008
+ const selection = nativeTargetSelection(executable);
1009
+ const preview = executable.length === targets.length ? checked
1010
+ : await nativeOperation(plan, selection.pluginIds, selection.platform, true, nativeRuntime, group.command, executable);
1011
+ executableNativeGroups.push({ ...group, ...selection, preview });
1012
+ }
1013
+ for (const prepared of plan.portableGroups) {
1014
+ if (prepared.options.agents.every((agent) => pair(plan, prepared.options.selector, agent).blockers.length))
1015
+ continue;
1016
+ const checked = await inspectPortableRecovery(prepared.options);
1017
+ if (checked.evidenceDigest !== prepared.evidenceDigest) {
1018
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1019
+ return completeReceipt(receipt);
1020
+ }
1021
+ }
1022
+ for (const prepared of plan.portableProtectionGroups) {
1023
+ const checked = await inspectPortableRecovery(prepared.options);
1024
+ if (checked.evidenceDigest !== prepared.evidenceDigest) {
1025
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1026
+ return completeReceipt(receipt);
1027
+ }
1028
+ }
1029
+ for (const residue of plan.portableResidues) {
1030
+ const checked = await inspectPortableResidue({ scope: plan.options.scope, context: plan.context,
1031
+ selector: residue.pluginId, env: plan.options.env, agents: residue.agents.filter(isPortableAgent),
1032
+ retainedTargets: residue.retainedTargets }).catch(() => undefined);
1033
+ if (!checked || JSON.stringify(checked) !== JSON.stringify(residue.observation)) {
1034
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1035
+ return completeReceipt(receipt);
1036
+ }
1037
+ }
1038
+ if (plan.declaration) {
1039
+ const declared = await addRequirements({ ...plan.options, selectors: plan.declaration, token });
1040
+ receipt.declarationChanged = declared.changed;
1041
+ receipt.blockers.push(...declared.errors);
1042
+ plan.blockExecution ||= declared.errors.length > 0;
1043
+ const intent = await observeIntent(plan.options);
1044
+ receipt.intent = { ...receipt.intent, state: intent.state, ...('digest' in intent ? { digest: intent.digest } : {}) };
1045
+ }
1046
+ if (plan.blockExecution)
1047
+ return completeReceipt(receipt);
1048
+ if (plan.preferences) {
1049
+ try {
1050
+ const saved = await writePreferences({ ...plan.options, token }, plan.preferences);
1051
+ receipt.preferencesChanged = saved.changed;
1052
+ }
1053
+ catch (error) {
1054
+ receipt.blockers.push(diagnostic(errorCode(error, 'deploymentPreferencesWriteFailed')));
1055
+ return completeReceipt(receipt);
1056
+ }
1057
+ }
1058
+ for (const group of executableNativeGroups) {
1059
+ try {
1060
+ const result = await nativeOperation(plan, group.pluginIds, group.platform, false, { ...nativeRuntime,
1061
+ ...(group.preview.operationPlan
1062
+ ? { expectedPlanFingerprint: group.preview.operationPlan.planFingerprint } : {}) }, group.command, nativeGroupTargets(group));
1063
+ receipt.outputsMayHaveChanged ||= result.rebuildResults.some((result) => result.actions.some((action) => action.name === 'stale.cleanup' || action.name === 'native.write' || action.name === 'artifacts.write'
1064
+ || action.name === 'recovery.cleanup' || action.name === 'cleanup.owned'))
1065
+ || ((result.commandResults?.length ?? 0) > 0
1066
+ && result.operationPlan?.actions.some((action) => action.kind === 'syncManagedCommandPackage') === true);
1067
+ nativeResults(plan, group, result, true);
1068
+ }
1069
+ catch (error) {
1070
+ const code = errorCode(error, 'nativeRecoveryFailed');
1071
+ receipt.outputsMayHaveChanged ||= code !== 'preApplyAuthorizationRequired';
1072
+ for (const { pluginId, platform } of nativeGroupTargets(group)) {
1073
+ const target = pair(plan, pluginId, agentForPlatform(platform));
1074
+ target.execution = 'failed';
1075
+ block(target, code);
1076
+ }
1077
+ }
1078
+ }
1079
+ const completedFootprints = [];
1080
+ const failedFootprints = [];
1081
+ for (const prepared of plan.portableGroups) {
1082
+ const agents = [];
1083
+ for (const agent of prepared.options.agents) {
1084
+ if (pair(plan, prepared.options.selector, agent).blockers.length)
1085
+ continue;
1086
+ const outcomes = prepared.targets.filter((entry) => entry.agent === agent).map((entry) => {
1087
+ const failed = failedFootprints.find((failure) => failure.logicalIdentity === prepared.logicalIdentity
1088
+ && failure.outcome.physicalPath === entry.physicalPath && failure.outcome.expectedDigest === entry.expectedDigest
1089
+ && failure.outcome.providerPluginId === entry.providerPluginId);
1090
+ return failed ? { ...failed.outcome, agent } : { ...entry, execution: 'not-run', blockers: [] };
1091
+ });
1092
+ if (outcomes.some((entry) => entry.execution === 'failed')) {
1093
+ portableOutcomes(plan, prepared, agent, outcomes, []);
1094
+ continue;
1095
+ }
1096
+ const preApplyFailure = await executePortablePreApply(plan, prepared, agent, nativeRuntime);
1097
+ if (preApplyFailure) {
1098
+ const target = pair(plan, prepared.options.selector, agent);
1099
+ target.execution = 'failed';
1100
+ block(target, preApplyFailure);
1101
+ target.recoveryActions = [`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent} --yes`];
1102
+ continue;
1103
+ }
1104
+ agents.push(agent);
1105
+ }
1106
+ if (!agents.length)
1107
+ continue;
1108
+ const result = await executePortableRecovery({ prepared, token, authorizeUpdate: plan.options.yes,
1109
+ action: plan.command === 'install' ? 'sync' : plan.command, force: plan.options.force,
1110
+ targets: prepared.targets.filter((target) => agents.includes(target.agent)).map(({ skill, agent }) => ({ skill, agent })),
1111
+ completedFootprints });
1112
+ receipt.outputsMayHaveChanged ||= result.outputsMayHaveChanged;
1113
+ for (const agent of agents) {
1114
+ portableOutcomes(plan, prepared, agent, result.targets.filter((entry) => entry.agent === agent), result.globalBlockers);
1115
+ }
1116
+ failedFootprints.push(...result.targets.filter((target) => target.execution === 'failed')
1117
+ .map((outcome) => ({ logicalIdentity: prepared.logicalIdentity, outcome })));
1118
+ completedFootprints.push(...result.targets.filter((target) => target.observation === 'satisfied'
1119
+ && ['applied', 'no-op'].includes(target.execution) && target.blockers.length === 0)
1120
+ .map(({ physicalPath, expectedDigest, providerPluginId }) => ({ physicalPath, expectedDigest, providerPluginId,
1121
+ logicalIdentity: prepared.logicalIdentity })));
1122
+ }
1123
+ for (const { kind, pluginId, observation } of plan.portableResidues) {
1124
+ if (kind !== 'cleanup')
1125
+ continue;
1126
+ if (observation.state === 'absent')
1127
+ continue;
1128
+ const targets = receipt.targetResults.filter((target) => target.pluginId === pluginId
1129
+ && (observation.targets.some((entry) => entry.agent === target.agent)
1130
+ || (observation.unknownAgents?.some((item) => item === target.agent)
1131
+ ?? (observation.blockers.length > 0))));
1132
+ for (const target of targets) {
1133
+ block(target, isPortableAgent(target.agent) && observation.unknownAgents?.some((item) => item === target.agent)
1134
+ || !observation.targets.some((entry) => entry.agent === target.agent)
1135
+ ? 'portableObservationFailed' : 'backend-action-unsupported');
1136
+ if (target.execution === 'applied')
1137
+ target.execution = 'partial';
1138
+ target.backend = { ...(target.delivery?.kind === 'native' ? { native: target.backend } : { portable: target.backend }), portableRemaining: {
1139
+ state: observation.state, targets: observation.targets.map(({ skill, agent, physicalPath }) => ({ skill, agent, physicalPath: displayPortablePath(plan, physicalPath) })),
1140
+ } };
1141
+ target.recoveryActions = [...new Set([...(target.recoveryActions ?? []), ...portableRecoveryActions(plan, pluginId, observation.targets.filter((entry) => entry.agent === target.agent))])];
1142
+ }
1143
+ }
1144
+ if (receipt.declarationChanged) {
1145
+ const intent = await observeIntent(plan.options);
1146
+ receipt.intent = { state: intent.state, ...('digest' in intent ? { digest: intent.digest } : {}),
1147
+ roots: intent.state === 'valid' ? intent.value.roots.map((root) => root.pluginId) : null };
1148
+ }
1149
+ return completeReceipt(receipt);
1150
+ }
1151
+ finally {
1152
+ if (!plan.runtime.codexObservationSession)
1153
+ await session?.dispose();
1154
+ }
1155
+ } });
1156
+ }
1157
+ finally {
1158
+ await plan.context.dispose();
1159
+ }
1160
+ }
1161
+ export async function runRecovery(command, selectors, options, runtime = {}) {
1162
+ let plan = await prepareRecovery(command, selectors, options, runtime);
1163
+ if (plan.sourceRefreshes.length > 0) {
1164
+ if (options.yes !== true) {
1165
+ if (!options.interactive || !options.prompt?.confirm) {
1166
+ plan.receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
1167
+ await plan.context.dispose();
1168
+ return completeReceipt(plan.receipt);
1169
+ }
1170
+ const response = await options.prompt.confirm({ defaultValue: false, message: [
1171
+ `先更新来源:${plan.sourceRefreshes.map((entry) => entry.sourceId).join('、')}。`,
1172
+ ...plan.changes,
1173
+ ...plan.warnings,
1174
+ '确认后只激活已检查的来源候选;随后会基于新的 Active 重新准备插件恢复,并再次确认。',
1175
+ ].join('\n') });
1176
+ if (response.cancelled || response.value !== true) {
1177
+ plan.receipt.blockers.push(diagnostic('operationCancelled'));
1178
+ await plan.context.dispose();
1179
+ return completeReceipt(plan.receipt);
1180
+ }
1181
+ }
1182
+ plan = await activateRecoverySourcesAndReprepare(plan, { runtime });
1183
+ }
1184
+ if (options.interactive && options.yes !== true && options.prompt?.confirm
1185
+ && (plan.declaration || plan.receipt.targetResults.some((target) => target.blockers.length === 0))) {
1186
+ const response = await options.prompt.confirm({ defaultValue: false, message: [
1187
+ `${options.scope} 请求:${plan.receipt.requestedRoots.join('、')};Agent:${plan.receipt.selection.agents.join('、') || '未选择'}。`,
1188
+ ...plan.receipt.targetResults.map((target) => `${target.pluginId} / ${target.agent}:${target.blockers.length
1189
+ ? `受阻(${target.blockers.map((entry) => entry.code).join('、')})` : '可执行'}`),
1190
+ ...plan.changes, ...plan.warnings, ...plan.receipt.blockers.map((entry) => entry.message),
1191
+ '是否执行以上可处理变更及计划中的 preApply 脚本?',
1192
+ ].join('\n') });
1193
+ if (response.cancelled || response.value !== true) {
1194
+ plan.receipt.blockers.push(diagnostic('operationCancelled'));
1195
+ await plan.context.dispose();
1196
+ return completeReceipt(plan.receipt);
1197
+ }
1198
+ return executeRecovery(plan, { yes: true, runtime: { preApplyConfirmed: true } });
1199
+ }
1200
+ return executeRecovery(plan);
1201
+ }
1202
+ export async function prepareRecovery(command, selectors, options, runtime = {}) {
1203
+ const preparedResults = runtime.preparedArtifactRenderResults ?? new Map();
1204
+ runtime = { ...runtime, preparedArtifactRenderResults: preparedResults };
1205
+ return measureRecoveryPerformanceStage(runtime, 'recovery.plan', async () => {
1206
+ try {
1207
+ if (command === 'cleanup' && !options.scope)
1208
+ throw new Error('cleanupScopeRequired');
1209
+ const plan = command === 'cleanup'
1210
+ ? await prepareScopedRecovery(command, selectors, { ...options, scope: options.scope }, runtime)
1211
+ : await prepareJointRecovery(command, selectors, options, runtime);
1212
+ const dispose = plan.context.dispose;
1213
+ let disposed = false;
1214
+ plan.context.dispose = async () => {
1215
+ if (disposed)
1216
+ return;
1217
+ disposed = true;
1218
+ try {
1219
+ await dispose();
1220
+ }
1221
+ finally {
1222
+ await disposePreparedPlatformRebuildSession(preparedResults);
1223
+ }
1224
+ };
1225
+ return plan;
1226
+ }
1227
+ catch (error) {
1228
+ await disposePreparedPlatformRebuildSession(preparedResults);
1229
+ throw error;
1230
+ }
1231
+ });
1232
+ }
1233
+ export async function executeRecovery(plan, execution = {}) {
1234
+ return plan.joint ? executeJointRecovery(plan, execution) : executeScopedRecovery(plan, execution);
1235
+ }
1236
+ /** Review evidence uses existing backend fingerprints and observation digests; it is not stored state. */
1237
+ export function describeRecoveryPlan(plan) {
1238
+ const describe = (child) => ({ scope: child.options.scope, targets: child.receipt.requestedTargets,
1239
+ native: child.nativeGroups.map((group) => group.preview.operationPlan?.planFingerprint),
1240
+ preApplyAuthorization: child.preApplyAuthorization,
1241
+ nativeActivationOnlyTargets: child.options.nativeActivationOnlyTargets,
1242
+ nativePlannedRetirements: child.options.nativePlannedRetirements,
1243
+ portable: child.portableGroups.map((group) => group.evidenceDigest),
1244
+ protectedPortable: child.portableProtectionGroups.map((group) => group.evidenceDigest),
1245
+ residue: child.portableResidues, blockers: child.receipt.blockers,
1246
+ targetBlockers: child.receipt.targetResults.map((target) => target.blockers),
1247
+ environment: { homes: child.context.targetHomes, projectRoot: child.context.projectRoot, awHome: child.context.awHome },
1248
+ });
1249
+ return { inputs: plan.joint?.evidence ?? [plan.originalIntent, plan.preferencesEvidence],
1250
+ command: plan.command, dependencyCleanupTargets: plan.dependencyCleanupTargets,
1251
+ declaration: plan.joint?.declaration, packages: plan.runtime.configApplyPackages ? { targets: plan.runtime.configApplyPackages.targets, evidence: plan.runtime.configApplyPackages.evidence } : undefined, blockers: plan.receipt.blockers,
1252
+ children: (plan.joint?.children ?? [plan]).map(describe) };
1253
+ }
1254
+ //# sourceMappingURL=coordinator.js.map