@lesliechan721/aw 0.1.0-beta.7 → 0.1.0-beta.72

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 (726) 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 +199 -0
  5. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -0
  6. package/dist/authoring/scripts/add-skill.mjs +13 -27
  7. package/dist/authoring/scripts/add-skill.mjs.map +1 -1
  8. package/dist/authoring/scripts/init-plugin.mjs +74 -103
  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 +229 -8
  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 -126
  17. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
  18. package/dist/authoring/scripts/plugin-status.mjs +8 -11
  19. package/dist/authoring/scripts/plugin-status.mjs.map +1 -1
  20. package/dist/authoring/scripts/remove-plugin.mjs +3 -2
  21. package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
  22. package/dist/authoring/scripts/validate-plugin.mjs +527 -1673
  23. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
  24. package/dist/authoring/scripts/validate-skill.mjs +1 -1
  25. package/dist/native-runtime/reader-runtime.mjs +34 -0
  26. package/dist/native-runtime/reader.d.mts +6 -0
  27. package/dist/native-runtime/reader.mjs +11 -0
  28. package/dist/scripts/aw-skill-eval-materializer.d.ts +28 -0
  29. package/dist/scripts/aw-skill-eval-materializer.js +339 -0
  30. package/dist/scripts/aw-skill-eval-materializer.js.map +1 -0
  31. package/dist/scripts/bundle-plugins.d.ts +1 -0
  32. package/dist/scripts/bundle-plugins.js +27 -8
  33. package/dist/scripts/bundle-plugins.js.map +1 -1
  34. package/dist/scripts/plugin-staging.d.ts +8 -10
  35. package/dist/scripts/plugin-staging.js +19 -30
  36. package/dist/scripts/plugin-staging.js.map +1 -1
  37. package/dist/scripts/plugin-test-reporter.d.mts +2 -0
  38. package/dist/scripts/plugin-test-reporter.mjs +21 -0
  39. package/dist/scripts/plugin-test-reporter.mjs.map +1 -0
  40. package/dist/scripts/test-plugin-scripts.d.ts +5 -0
  41. package/dist/scripts/test-plugin-scripts.js +246 -108
  42. package/dist/scripts/test-plugin-scripts.js.map +1 -1
  43. package/dist/scripts/test-workers.d.mts +24 -0
  44. package/dist/scripts/test-workers.mjs +59 -0
  45. package/dist/scripts/test-workers.mjs.map +1 -0
  46. package/dist/src/adapters/helpers.d.ts +7 -0
  47. package/dist/src/adapters/helpers.js +2 -2
  48. package/dist/src/adapters/helpers.js.map +1 -1
  49. package/dist/src/authoring/workspace-commands.d.ts +20 -1
  50. package/dist/src/authoring/workspace-commands.js +28 -6
  51. package/dist/src/authoring/workspace-commands.js.map +1 -1
  52. package/dist/src/commands/aw-capabilities.d.ts +78 -0
  53. package/dist/src/commands/aw-capabilities.js +270 -0
  54. package/dist/src/commands/aw-capabilities.js.map +1 -0
  55. package/dist/src/commands/catalog-dev-source.d.ts +157 -0
  56. package/dist/src/commands/catalog-dev-source.js +725 -0
  57. package/dist/src/commands/catalog-dev-source.js.map +1 -0
  58. package/dist/src/commands/catalog-generation.d.ts +21 -0
  59. package/dist/src/commands/catalog-generation.js +9 -0
  60. package/dist/src/commands/catalog-generation.js.map +1 -0
  61. package/dist/src/commands/catalog-publication-inspection.d.ts +71 -30
  62. package/dist/src/commands/catalog-publication-inspection.js +475 -63
  63. package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
  64. package/dist/src/commands/catalog-publication-journal.d.ts +68 -0
  65. package/dist/src/commands/catalog-publication-journal.js +292 -0
  66. package/dist/src/commands/catalog-publication-journal.js.map +1 -0
  67. package/dist/src/commands/catalog-publication-target.d.ts +18 -0
  68. package/dist/src/commands/catalog-publication-target.js +95 -0
  69. package/dist/src/commands/catalog-publication-target.js.map +1 -0
  70. package/dist/src/commands/catalog-publish.d.ts +89 -15
  71. package/dist/src/commands/catalog-publish.js +736 -210
  72. package/dist/src/commands/catalog-publish.js.map +1 -1
  73. package/dist/src/commands/catalog-source.d.ts +64 -22
  74. package/dist/src/commands/catalog-source.js +327 -91
  75. package/dist/src/commands/catalog-source.js.map +1 -1
  76. package/dist/src/commands/catalog-status.d.ts +18 -22
  77. package/dist/src/commands/catalog-status.js +82 -116
  78. package/dist/src/commands/catalog-status.js.map +1 -1
  79. package/dist/src/commands/catalog-store.d.ts +104 -0
  80. package/dist/src/commands/catalog-store.js +685 -0
  81. package/dist/src/commands/catalog-store.js.map +1 -0
  82. package/dist/src/commands/catalog-workspace-resolution.d.ts +17 -0
  83. package/dist/src/commands/catalog-workspace-resolution.js +57 -0
  84. package/dist/src/commands/catalog-workspace-resolution.js.map +1 -0
  85. package/dist/src/commands/console.js +32 -20
  86. package/dist/src/commands/console.js.map +1 -1
  87. package/dist/src/commands/dependency-operation-plan.d.ts +52 -15
  88. package/dist/src/commands/dependency-operation-plan.js +289 -7
  89. package/dist/src/commands/dependency-operation-plan.js.map +1 -1
  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 +359 -0
  98. package/dist/src/commands/managed-commands.js.map +1 -0
  99. package/dist/src/commands/offline-cleanup-evidence.d.ts +67 -0
  100. package/dist/src/commands/offline-cleanup-evidence.js +181 -0
  101. package/dist/src/commands/offline-cleanup-evidence.js.map +1 -0
  102. package/dist/src/commands/operation-plan.d.ts +184 -0
  103. package/dist/src/commands/operation-plan.js +72 -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 +10 -17
  109. package/dist/src/commands/options.js +91 -38
  110. package/dist/src/commands/options.js.map +1 -1
  111. package/dist/src/commands/plugin-capabilities.js +85 -30
  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 +53 -0
  120. package/dist/src/commands/public-lifecycle-result.js +102 -0
  121. package/dist/src/commands/public-lifecycle-result.js.map +1 -0
  122. package/dist/src/commands/public-lifecycle.d.ts +26 -0
  123. package/dist/src/commands/public-lifecycle.js +469 -0
  124. package/dist/src/commands/public-lifecycle.js.map +1 -0
  125. package/dist/src/commands/public-plugin-query.d.ts +15 -0
  126. package/dist/src/commands/public-plugin-query.js +154 -0
  127. package/dist/src/commands/public-plugin-query.js.map +1 -0
  128. package/dist/src/commands/rebuild-command.d.ts +177 -29
  129. package/dist/src/commands/rebuild-command.js +4113 -745
  130. package/dist/src/commands/rebuild-command.js.map +1 -1
  131. package/dist/src/commands/rebuild-integration.d.ts +163 -22
  132. package/dist/src/commands/rebuild-integration.js +3553 -1456
  133. package/dist/src/commands/rebuild-integration.js.map +1 -1
  134. package/dist/src/commands/rebuild-operations.d.ts +60 -30
  135. package/dist/src/commands/rebuild-operations.js +266 -320
  136. package/dist/src/commands/rebuild-operations.js.map +1 -1
  137. package/dist/src/commands/reconcile-operation-plan.d.ts +28 -0
  138. package/dist/src/commands/reconcile-operation-plan.js +47 -0
  139. package/dist/src/commands/reconcile-operation-plan.js.map +1 -0
  140. package/dist/src/commands/review-inspection.d.ts +60 -0
  141. package/dist/src/commands/review-inspection.js +399 -0
  142. package/dist/src/commands/review-inspection.js.map +1 -0
  143. package/dist/src/commands/review-preparation.d.ts +49 -0
  144. package/dist/src/commands/review-preparation.js +437 -0
  145. package/dist/src/commands/review-preparation.js.map +1 -0
  146. package/dist/src/commands/runtime.d.ts +5 -5
  147. package/dist/src/commands/runtime.js +42 -54
  148. package/dist/src/commands/runtime.js.map +1 -1
  149. package/dist/src/commands/skill-eval.d.ts +41 -0
  150. package/dist/src/commands/skill-eval.js +406 -0
  151. package/dist/src/commands/skill-eval.js.map +1 -0
  152. package/dist/src/commands/status-v6.d.ts +317 -0
  153. package/dist/src/commands/status-v6.js +2970 -0
  154. package/dist/src/commands/status-v6.js.map +1 -0
  155. package/dist/src/commands/targets-command.d.ts +29 -0
  156. package/dist/src/commands/targets-command.js +131 -0
  157. package/dist/src/commands/targets-command.js.map +1 -0
  158. package/dist/src/commands/wizard.d.ts +8 -5
  159. package/dist/src/commands/wizard.js +6 -4
  160. package/dist/src/commands/wizard.js.map +1 -1
  161. package/dist/src/commands/write-commands.d.ts +9 -3
  162. package/dist/src/commands/write-commands.js +129 -30
  163. package/dist/src/commands/write-commands.js.map +1 -1
  164. package/dist/src/constants.d.ts +7 -2
  165. package/dist/src/constants.js +7 -2
  166. package/dist/src/constants.js.map +1 -1
  167. package/dist/src/eval/manifest-v1.d.ts +70 -0
  168. package/dist/src/eval/manifest-v1.js +358 -0
  169. package/dist/src/eval/manifest-v1.js.map +1 -0
  170. package/dist/src/generators/local-plugin.d.ts +7 -2
  171. package/dist/src/generators/local-plugin.js +377 -210
  172. package/dist/src/generators/local-plugin.js.map +1 -1
  173. package/dist/src/generators/permissions.d.ts +5 -2
  174. package/dist/src/generators/permissions.js +28 -15
  175. package/dist/src/generators/permissions.js.map +1 -1
  176. package/dist/src/index.d.ts +1 -27
  177. package/dist/src/index.js +1877 -1592
  178. package/dist/src/index.js.map +1 -1
  179. package/dist/src/intent/deployment-preferences.d.ts +63 -0
  180. package/dist/src/intent/deployment-preferences.js +170 -0
  181. package/dist/src/intent/deployment-preferences.js.map +1 -0
  182. package/dist/src/intent/diagnostics.d.ts +11 -0
  183. package/dist/src/intent/diagnostics.js +14 -0
  184. package/dist/src/intent/diagnostics.js.map +1 -0
  185. package/dist/src/intent/intent-codec.d.ts +19 -0
  186. package/dist/src/intent/intent-codec.js +117 -0
  187. package/dist/src/intent/intent-codec.js.map +1 -0
  188. package/dist/src/intent/intent-store.d.ts +43 -0
  189. package/dist/src/intent/intent-store.js +118 -0
  190. package/dist/src/intent/intent-store.js.map +1 -0
  191. package/dist/src/intent/scope-context.d.ts +33 -0
  192. package/dist/src/intent/scope-context.js +145 -0
  193. package/dist/src/intent/scope-context.js.map +1 -0
  194. package/dist/src/intent/work-context.d.ts +13 -0
  195. package/dist/src/intent/work-context.js +22 -0
  196. package/dist/src/intent/work-context.js.map +1 -0
  197. package/dist/src/output/command-receipt.d.ts +47 -46
  198. package/dist/src/output/command-receipt.js +284 -79
  199. package/dist/src/output/command-receipt.js.map +1 -1
  200. package/dist/src/output/model.d.ts +3 -44
  201. package/dist/src/output/model.js +1 -144
  202. package/dist/src/output/model.js.map +1 -1
  203. package/dist/src/output/public-result.d.ts +43 -0
  204. package/dist/src/output/public-result.js +139 -0
  205. package/dist/src/output/public-result.js.map +1 -0
  206. package/dist/src/output/rebuild-progress.js +15 -13
  207. package/dist/src/output/rebuild-progress.js.map +1 -1
  208. package/dist/src/output/receipt-projection.d.ts +7 -0
  209. package/dist/src/output/receipt-projection.js +575 -0
  210. package/dist/src/output/receipt-projection.js.map +1 -0
  211. package/dist/src/portable/commands.d.ts +59 -10
  212. package/dist/src/portable/commands.js +98 -302
  213. package/dist/src/portable/commands.js.map +1 -1
  214. package/dist/src/portable/historical-materialization.d.ts +22 -0
  215. package/dist/src/portable/historical-materialization.js +124 -0
  216. package/dist/src/portable/historical-materialization.js.map +1 -0
  217. package/dist/src/portable/materializer.d.ts +25 -4
  218. package/dist/src/portable/materializer.js +247 -68
  219. package/dist/src/portable/materializer.js.map +1 -1
  220. package/dist/src/portable/recovery-layout.d.ts +17 -0
  221. package/dist/src/portable/recovery-layout.js +55 -0
  222. package/dist/src/portable/recovery-layout.js.map +1 -0
  223. package/dist/src/portable/recovery.d.ts +143 -0
  224. package/dist/src/portable/recovery.js +339 -0
  225. package/dist/src/portable/recovery.js.map +1 -0
  226. package/dist/src/portable/writer.d.ts +64 -0
  227. package/dist/src/portable/writer.js +316 -0
  228. package/dist/src/portable/writer.js.map +1 -0
  229. package/dist/src/recovery/coordinator.d.ts +140 -0
  230. package/dist/src/recovery/coordinator.js +1200 -0
  231. package/dist/src/recovery/coordinator.js.map +1 -0
  232. package/dist/src/recovery/demand.d.ts +44 -0
  233. package/dist/src/recovery/demand.js +178 -0
  234. package/dist/src/recovery/demand.js.map +1 -0
  235. package/dist/src/recovery/joint-coordinator.d.ts +24 -0
  236. package/dist/src/recovery/joint-coordinator.js +797 -0
  237. package/dist/src/recovery/joint-coordinator.js.map +1 -0
  238. package/dist/src/recovery/joint-demand.d.ts +68 -0
  239. package/dist/src/recovery/joint-demand.js +166 -0
  240. package/dist/src/recovery/joint-demand.js.map +1 -0
  241. package/dist/src/recovery/performance.d.ts +4 -0
  242. package/dist/src/recovery/performance.js +26 -0
  243. package/dist/src/recovery/performance.js.map +1 -0
  244. package/dist/src/recovery/receipt.d.ts +81 -0
  245. package/dist/src/recovery/receipt.js +2 -0
  246. package/dist/src/recovery/receipt.js.map +1 -0
  247. package/dist/src/recovery/retirement.d.ts +47 -0
  248. package/dist/src/recovery/retirement.js +367 -0
  249. package/dist/src/recovery/retirement.js.map +1 -0
  250. package/dist/src/recovery/status.d.ts +108 -0
  251. package/dist/src/recovery/status.js +418 -0
  252. package/dist/src/recovery/status.js.map +1 -0
  253. package/dist/src/recovery/types.d.ts +86 -0
  254. package/dist/src/recovery/types.js +2 -0
  255. package/dist/src/recovery/types.js.map +1 -0
  256. package/dist/src/review/eval-source-input.d.ts +43 -0
  257. package/dist/src/review/eval-source-input.js +207 -0
  258. package/dist/src/review/eval-source-input.js.map +1 -0
  259. package/dist/src/review/review-profile.d.ts +19 -0
  260. package/dist/src/review/review-profile.js +270 -0
  261. package/dist/src/review/review-profile.js.map +1 -0
  262. package/dist/src/review/review-selection.d.ts +29 -0
  263. package/dist/src/review/review-selection.js +469 -0
  264. package/dist/src/review/review-selection.js.map +1 -0
  265. package/dist/src/review/review-types.d.ts +68 -0
  266. package/dist/src/review/review-types.js +16 -0
  267. package/dist/src/review/review-types.js.map +1 -0
  268. package/dist/src/review/skill-materialization.d.ts +27 -0
  269. package/dist/src/review/skill-materialization.js +228 -0
  270. package/dist/src/review/skill-materialization.js.map +1 -0
  271. package/dist/src/review/source-binding.d.ts +198 -0
  272. package/dist/src/review/source-binding.js +714 -0
  273. package/dist/src/review/source-binding.js.map +1 -0
  274. package/dist/src/tui/agent-management.d.ts +23 -0
  275. package/dist/src/tui/agent-management.js +217 -0
  276. package/dist/src/tui/agent-management.js.map +1 -0
  277. package/dist/src/tui/agent-settings.d.ts +44 -0
  278. package/dist/src/tui/agent-settings.js +98 -0
  279. package/dist/src/tui/agent-settings.js.map +1 -0
  280. package/dist/src/tui/catalog-freshness.d.ts +1 -0
  281. package/dist/src/tui/catalog-freshness.js +2 -0
  282. package/dist/src/tui/catalog-freshness.js.map +1 -0
  283. package/dist/src/tui/catalog-generation.d.ts +21 -0
  284. package/dist/src/tui/catalog-generation.js +156 -0
  285. package/dist/src/tui/catalog-generation.js.map +1 -0
  286. package/dist/src/tui/catalog-sources/projection.d.ts +4 -0
  287. package/dist/src/tui/catalog-sources/projection.js +17 -0
  288. package/dist/src/tui/catalog-sources/projection.js.map +1 -0
  289. package/dist/src/tui/catalog-sources/review.d.ts +3 -0
  290. package/dist/src/tui/catalog-sources/review.js +13 -0
  291. package/dist/src/tui/catalog-sources/review.js.map +1 -0
  292. package/dist/src/tui/catalog-sources/screens.d.ts +12 -0
  293. package/dist/src/tui/catalog-sources/screens.js +40 -0
  294. package/dist/src/tui/catalog-sources/screens.js.map +1 -0
  295. package/dist/src/tui/catalog-sources/session.d.ts +32 -0
  296. package/dist/src/tui/catalog-sources/session.js +300 -0
  297. package/dist/src/tui/catalog-sources/session.js.map +1 -0
  298. package/dist/src/tui/catalog-sources/types.d.ts +54 -0
  299. package/dist/src/tui/catalog-sources/types.js +2 -0
  300. package/dist/src/tui/catalog-sources/types.js.map +1 -0
  301. package/dist/src/tui/catalog-store-task.d.ts +16 -0
  302. package/dist/src/tui/catalog-store-task.js +19 -0
  303. package/dist/src/tui/catalog-store-task.js.map +1 -0
  304. package/dist/src/tui/clipboard.d.ts +13 -0
  305. package/dist/src/tui/clipboard.js +95 -0
  306. package/dist/src/tui/clipboard.js.map +1 -0
  307. package/dist/src/tui/components.d.ts +113 -3
  308. package/dist/src/tui/components.js +192 -36
  309. package/dist/src/tui/components.js.map +1 -1
  310. package/dist/src/tui/config-array-draft.d.ts +29 -0
  311. package/dist/src/tui/config-array-draft.js +48 -0
  312. package/dist/src/tui/config-array-draft.js.map +1 -0
  313. package/dist/src/tui/config-leaf-editor.d.ts +43 -0
  314. package/dist/src/tui/config-leaf-editor.js +224 -0
  315. package/dist/src/tui/config-leaf-editor.js.map +1 -0
  316. package/dist/src/tui/config-references.d.ts +38 -0
  317. package/dist/src/tui/config-references.js +82 -0
  318. package/dist/src/tui/config-references.js.map +1 -0
  319. package/dist/src/tui/config-value-presentation.d.ts +20 -0
  320. package/dist/src/tui/config-value-presentation.js +104 -0
  321. package/dist/src/tui/config-value-presentation.js.map +1 -0
  322. package/dist/src/tui/console-app-v4.d.ts +13 -4
  323. package/dist/src/tui/console-app-v4.js +9764 -1955
  324. package/dist/src/tui/console-app-v4.js.map +1 -1
  325. package/dist/src/tui/content-item-card.d.ts +13 -0
  326. package/dist/src/tui/content-item-card.js +51 -0
  327. package/dist/src/tui/content-item-card.js.map +1 -0
  328. package/dist/src/tui/controller-runtime.d.ts +11 -2
  329. package/dist/src/tui/controller-runtime.js +2223 -471
  330. package/dist/src/tui/controller-runtime.js.map +1 -1
  331. package/dist/src/tui/controller.d.ts +697 -66
  332. package/dist/src/tui/controller.js +3695 -778
  333. package/dist/src/tui/controller.js.map +1 -1
  334. package/dist/src/tui/dependency-graph-view.d.ts +39 -0
  335. package/dist/src/tui/dependency-graph-view.js +121 -0
  336. package/dist/src/tui/dependency-graph-view.js.map +1 -0
  337. package/dist/src/tui/dependency-graph.d.ts +81 -0
  338. package/dist/src/tui/dependency-graph.js +452 -0
  339. package/dist/src/tui/dependency-graph.js.map +1 -0
  340. package/dist/src/tui/diagnostic-projection.d.ts +23 -0
  341. package/dist/src/tui/diagnostic-projection.js +595 -0
  342. package/dist/src/tui/diagnostic-projection.js.map +1 -0
  343. package/dist/src/tui/diagnostics.d.ts +3 -3
  344. package/dist/src/tui/diagnostics.js +14 -2
  345. package/dist/src/tui/diagnostics.js.map +1 -1
  346. package/dist/src/tui/entity-cards.d.ts +55 -0
  347. package/dist/src/tui/entity-cards.js +298 -0
  348. package/dist/src/tui/entity-cards.js.map +1 -0
  349. package/dist/src/tui/glossary.d.ts +25 -0
  350. package/dist/src/tui/glossary.js +62 -0
  351. package/dist/src/tui/glossary.js.map +1 -0
  352. package/dist/src/tui/index.d.ts +6 -1
  353. package/dist/src/tui/index.js +5 -1
  354. package/dist/src/tui/index.js.map +1 -1
  355. package/dist/src/tui/input-display.d.ts +9 -0
  356. package/dist/src/tui/input-display.js +58 -0
  357. package/dist/src/tui/input-display.js.map +1 -0
  358. package/dist/src/tui/keys.d.ts +44 -0
  359. package/dist/src/tui/keys.js +43 -15
  360. package/dist/src/tui/keys.js.map +1 -1
  361. package/dist/src/tui/lifecycle-action-view.d.ts +6 -0
  362. package/dist/src/tui/lifecycle-action-view.js +36 -0
  363. package/dist/src/tui/lifecycle-action-view.js.map +1 -0
  364. package/dist/src/tui/model.d.ts +246 -35
  365. package/dist/src/tui/model.js +1514 -401
  366. package/dist/src/tui/model.js.map +1 -1
  367. package/dist/src/tui/operation-diagnostic-screens.d.ts +8 -0
  368. package/dist/src/tui/operation-diagnostic-screens.js +71 -0
  369. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
  370. package/dist/src/tui/operation-history.d.ts +81 -0
  371. package/dist/src/tui/operation-history.js +136 -0
  372. package/dist/src/tui/operation-history.js.map +1 -0
  373. package/dist/src/tui/operation-review-planner.d.ts +23 -0
  374. package/dist/src/tui/operation-review-planner.js +1341 -0
  375. package/dist/src/tui/operation-review-planner.js.map +1 -0
  376. package/dist/src/tui/plugin-content.d.ts +31 -0
  377. package/dist/src/tui/plugin-content.js +683 -0
  378. package/dist/src/tui/plugin-content.js.map +1 -0
  379. package/dist/src/tui/plugin-detail.d.ts +71 -0
  380. package/dist/src/tui/plugin-detail.js +252 -0
  381. package/dist/src/tui/plugin-detail.js.map +1 -0
  382. package/dist/src/tui/plugin-write-task.d.ts +69 -0
  383. package/dist/src/tui/plugin-write-task.js +286 -0
  384. package/dist/src/tui/plugin-write-task.js.map +1 -0
  385. package/dist/src/tui/prompt.js +4 -15
  386. package/dist/src/tui/prompt.js.map +1 -1
  387. package/dist/src/tui/query-header.d.ts +30 -0
  388. package/dist/src/tui/query-header.js +40 -0
  389. package/dist/src/tui/query-header.js.map +1 -0
  390. package/dist/src/tui/reader.d.ts +38 -0
  391. package/dist/src/tui/reader.js +49 -0
  392. package/dist/src/tui/reader.js.map +1 -0
  393. package/dist/src/tui/router.d.ts +194 -17
  394. package/dist/src/tui/router.js +338 -50
  395. package/dist/src/tui/router.js.map +1 -1
  396. package/dist/src/tui/scoped-flow.d.ts +45 -0
  397. package/dist/src/tui/scoped-flow.js +96 -0
  398. package/dist/src/tui/scoped-flow.js.map +1 -0
  399. package/dist/src/tui/scoped-inventory.d.ts +122 -0
  400. package/dist/src/tui/scoped-inventory.js +225 -0
  401. package/dist/src/tui/scoped-inventory.js.map +1 -0
  402. package/dist/src/tui/screen-registry.d.ts +701 -0
  403. package/dist/src/tui/screen-registry.js +226 -0
  404. package/dist/src/tui/screen-registry.js.map +1 -0
  405. package/dist/src/tui/session-console-app.d.ts +6 -0
  406. package/dist/src/tui/session-console-app.js +13 -0
  407. package/dist/src/tui/session-console-app.js.map +1 -0
  408. package/dist/src/tui/session-host.d.ts +45 -0
  409. package/dist/src/tui/session-host.js +219 -0
  410. package/dist/src/tui/session-host.js.map +1 -0
  411. package/dist/src/tui/source-detail-card.d.ts +29 -0
  412. package/dist/src/tui/source-detail-card.js +45 -0
  413. package/dist/src/tui/source-detail-card.js.map +1 -0
  414. package/dist/src/tui/source-ref-presets.d.ts +3 -0
  415. package/dist/src/tui/source-ref-presets.js +11 -0
  416. package/dist/src/tui/source-ref-presets.js.map +1 -0
  417. package/dist/src/tui/theme.d.ts +12 -0
  418. package/dist/src/tui/theme.js +12 -0
  419. package/dist/src/tui/theme.js.map +1 -1
  420. package/dist/src/tui/viewport.d.ts +1 -0
  421. package/dist/src/tui/viewport.js +23 -0
  422. package/dist/src/tui/viewport.js.map +1 -1
  423. package/dist/src/tui/views.js +31 -3
  424. package/dist/src/tui/views.js.map +1 -1
  425. package/dist/src/tui/wizard.js +37 -13
  426. package/dist/src/tui/wizard.js.map +1 -1
  427. package/dist/src/types.d.ts +268 -23
  428. package/dist/src/types.js +1 -0
  429. package/dist/src/types.js.map +1 -1
  430. package/dist/src/utils/agent-version.d.ts +7 -1
  431. package/dist/src/utils/agent-version.js +38 -7
  432. package/dist/src/utils/agent-version.js.map +1 -1
  433. package/dist/src/utils/artifact-plan.d.ts +8 -6
  434. package/dist/src/utils/artifact-plan.js +80 -19
  435. package/dist/src/utils/artifact-plan.js.map +1 -1
  436. package/dist/src/utils/artifact-renderer.d.ts +35 -11
  437. package/dist/src/utils/artifact-renderer.js +250 -227
  438. package/dist/src/utils/artifact-renderer.js.map +1 -1
  439. package/dist/src/utils/artifact-request.d.ts +33 -0
  440. package/dist/src/utils/artifact-request.js +100 -0
  441. package/dist/src/utils/artifact-request.js.map +1 -0
  442. package/dist/src/utils/artifact-sources.d.ts +6 -2
  443. package/dist/src/utils/artifact-sources.js +17 -0
  444. package/dist/src/utils/artifact-sources.js.map +1 -1
  445. package/dist/src/utils/aw-home-mutation-lock.d.ts +1 -0
  446. package/dist/src/utils/aw-home-mutation-lock.js +32 -4
  447. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  448. package/dist/src/utils/bundle-integrity.d.ts +0 -1
  449. package/dist/src/utils/bundle-integrity.js +0 -25
  450. package/dist/src/utils/bundle-integrity.js.map +1 -1
  451. package/dist/src/utils/bundle-layout.js +47 -45
  452. package/dist/src/utils/bundle-layout.js.map +1 -1
  453. package/dist/src/utils/catalog-capability-projection.d.ts +8 -0
  454. package/dist/src/utils/catalog-capability-projection.js +14 -0
  455. package/dist/src/utils/catalog-capability-projection.js.map +1 -0
  456. package/dist/src/utils/catalog-digests.d.ts +10 -0
  457. package/dist/src/utils/catalog-digests.js +59 -20
  458. package/dist/src/utils/catalog-digests.js.map +1 -1
  459. package/dist/src/utils/catalog-generation-control-snapshot.d.ts +11 -0
  460. package/dist/src/utils/catalog-generation-control-snapshot.js +45 -0
  461. package/dist/src/utils/catalog-generation-control-snapshot.js.map +1 -0
  462. package/dist/src/utils/catalog-generation-error.d.ts +16 -0
  463. package/dist/src/utils/catalog-generation-error.js +30 -0
  464. package/dist/src/utils/catalog-generation-error.js.map +1 -0
  465. package/dist/src/utils/catalog-generation-resolver.d.ts +44 -0
  466. package/dist/src/utils/catalog-generation-resolver.js +273 -0
  467. package/dist/src/utils/catalog-generation-resolver.js.map +1 -0
  468. package/dist/src/utils/catalog-generation-service.d.ts +183 -0
  469. package/dist/src/utils/catalog-generation-service.js +1281 -0
  470. package/dist/src/utils/catalog-generation-service.js.map +1 -0
  471. package/dist/src/utils/catalog-generation-state.d.ts +22 -0
  472. package/dist/src/utils/catalog-generation-state.js +192 -0
  473. package/dist/src/utils/catalog-generation-state.js.map +1 -0
  474. package/dist/src/utils/catalog-generation-store.d.ts +58 -0
  475. package/dist/src/utils/catalog-generation-store.js +452 -0
  476. package/dist/src/utils/catalog-generation-store.js.map +1 -0
  477. package/dist/src/utils/catalog-manifest-v7.d.ts +5 -0
  478. package/dist/src/utils/{catalog-manifest-v4.js → catalog-manifest-v7.js} +35 -43
  479. package/dist/src/utils/catalog-manifest-v7.js.map +1 -0
  480. package/dist/src/utils/catalog-operation-context.d.ts +20 -0
  481. package/dist/src/utils/catalog-operation-context.js +142 -0
  482. package/dist/src/utils/catalog-operation-context.js.map +1 -0
  483. package/dist/src/utils/catalog-public-error.d.ts +7 -3
  484. package/dist/src/utils/catalog-public-error.js +28 -8
  485. package/dist/src/utils/catalog-public-error.js.map +1 -1
  486. package/dist/src/utils/catalog-runtime-projection.d.ts +7 -3
  487. package/dist/src/utils/catalog-runtime-projection.js +5 -40
  488. package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
  489. package/dist/src/utils/catalog-snapshot.d.ts +5 -3
  490. package/dist/src/utils/catalog-snapshot.js +11 -3
  491. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  492. package/dist/src/utils/catalog-source-identity.d.ts +1 -0
  493. package/dist/src/utils/catalog-source-identity.js +21 -2
  494. package/dist/src/utils/catalog-source-identity.js.map +1 -1
  495. package/dist/src/utils/catalog-source-impact.d.ts +21 -0
  496. package/dist/src/utils/catalog-source-impact.js +344 -0
  497. package/dist/src/utils/catalog-source-impact.js.map +1 -0
  498. package/dist/src/utils/catalog-source-references.d.ts +8 -2
  499. package/dist/src/utils/catalog-source-references.js +200 -367
  500. package/dist/src/utils/catalog-source-references.js.map +1 -1
  501. package/dist/src/utils/catalog-sources.d.ts +15 -1
  502. package/dist/src/utils/catalog-sources.js +206 -27
  503. package/dist/src/utils/catalog-sources.js.map +1 -1
  504. package/dist/src/utils/claude-native-render-receipt.d.ts +14 -0
  505. package/dist/src/utils/claude-native-render-receipt.js +26 -0
  506. package/dist/src/utils/claude-native-render-receipt.js.map +1 -0
  507. package/dist/src/utils/claude-skills-root.d.ts +8 -0
  508. package/dist/src/utils/claude-skills-root.js +87 -0
  509. package/dist/src/utils/claude-skills-root.js.map +1 -0
  510. package/dist/src/utils/codex-config.d.ts +2 -0
  511. package/dist/src/utils/codex-config.js +26 -5
  512. package/dist/src/utils/codex-config.js.map +1 -1
  513. package/dist/src/utils/codex-executable-discovery.d.ts +26 -0
  514. package/dist/src/utils/codex-executable-discovery.js +397 -0
  515. package/dist/src/utils/codex-executable-discovery.js.map +1 -0
  516. package/dist/src/utils/codex-manager.d.ts +62 -0
  517. package/dist/src/utils/codex-manager.js +122 -0
  518. package/dist/src/utils/codex-manager.js.map +1 -0
  519. package/dist/src/utils/codex-marketplace-path.d.ts +5 -0
  520. package/dist/src/utils/codex-marketplace-path.js +45 -0
  521. package/dist/src/utils/codex-marketplace-path.js.map +1 -0
  522. package/dist/src/utils/codex-native-observation.d.ts +49 -0
  523. package/dist/src/utils/codex-native-observation.js +169 -0
  524. package/dist/src/utils/codex-native-observation.js.map +1 -0
  525. package/dist/src/utils/codex-native-render-receipt.d.ts +40 -0
  526. package/dist/src/utils/codex-native-render-receipt.js +205 -0
  527. package/dist/src/utils/codex-native-render-receipt.js.map +1 -0
  528. package/dist/src/utils/codex-reconciler.d.ts +123 -0
  529. package/dist/src/utils/codex-reconciler.js +322 -0
  530. package/dist/src/utils/codex-reconciler.js.map +1 -0
  531. package/dist/src/utils/codex-shared-native.d.ts +43 -0
  532. package/dist/src/utils/codex-shared-native.js +81 -0
  533. package/dist/src/utils/codex-shared-native.js.map +1 -0
  534. package/dist/src/utils/codex-skill-staging.d.ts +2 -0
  535. package/dist/src/utils/codex-skill-staging.js.map +1 -1
  536. package/dist/src/utils/codex-skills-root.d.ts +4 -0
  537. package/dist/src/utils/codex-skills-root.js +25 -0
  538. package/dist/src/utils/codex-skills-root.js.map +1 -0
  539. package/dist/src/utils/codex-surface-analysis.d.ts +46 -0
  540. package/dist/src/utils/codex-surface-analysis.js +249 -0
  541. package/dist/src/utils/codex-surface-analysis.js.map +1 -0
  542. package/dist/src/utils/dynamic-skill-tree.d.ts +5 -0
  543. package/dist/src/utils/dynamic-skill-tree.js +56 -7
  544. package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
  545. package/dist/src/utils/git-catalog-provider.d.ts +16 -0
  546. package/dist/src/utils/git-catalog-provider.js +177 -145
  547. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  548. package/dist/src/utils/local-marketplace.d.ts +39 -1
  549. package/dist/src/utils/local-marketplace.js +601 -84
  550. package/dist/src/utils/local-marketplace.js.map +1 -1
  551. package/dist/src/utils/managed-command-closure.d.ts +3 -0
  552. package/dist/src/utils/managed-command-closure.js +35 -0
  553. package/dist/src/utils/managed-command-closure.js.map +1 -0
  554. package/dist/src/utils/managed-command-evidence.d.ts +7 -0
  555. package/dist/src/utils/managed-command-evidence.js +86 -0
  556. package/dist/src/utils/managed-command-evidence.js.map +1 -0
  557. package/dist/src/utils/managed-command-materialization.d.ts +121 -0
  558. package/dist/src/utils/managed-command-materialization.js +369 -0
  559. package/dist/src/utils/managed-command-materialization.js.map +1 -0
  560. package/dist/src/utils/managed-command-runtime.d.ts +33 -0
  561. package/dist/src/utils/managed-command-runtime.js +121 -0
  562. package/dist/src/utils/managed-command-runtime.js.map +1 -0
  563. package/dist/src/utils/managed-command-store.d.ts +143 -0
  564. package/dist/src/utils/managed-command-store.js +654 -0
  565. package/dist/src/utils/managed-command-store.js.map +1 -0
  566. package/dist/src/utils/manifest.d.ts +1 -3
  567. package/dist/src/utils/manifest.js +1 -3
  568. package/dist/src/utils/manifest.js.map +1 -1
  569. package/dist/src/utils/multi-source-catalog.d.ts +3 -9
  570. package/dist/src/utils/multi-source-catalog.js +54 -110
  571. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  572. package/dist/src/utils/native-cli.d.ts +62 -7
  573. package/dist/src/utils/native-cli.js +449 -58
  574. package/dist/src/utils/native-cli.js.map +1 -1
  575. package/dist/src/utils/native-demand.d.ts +10 -0
  576. package/dist/src/utils/native-demand.js +4 -0
  577. package/dist/src/utils/native-demand.js.map +1 -0
  578. package/dist/src/utils/native-tool-context.d.ts +14 -0
  579. package/dist/src/utils/native-tool-context.js +38 -0
  580. package/dist/src/utils/native-tool-context.js.map +1 -0
  581. package/dist/src/utils/native-tool-review.d.ts +21 -0
  582. package/dist/src/utils/native-tool-review.js +102 -0
  583. package/dist/src/utils/native-tool-review.js.map +1 -0
  584. package/dist/src/utils/orphan-marketplace-cleanup.js +0 -4
  585. package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -1
  586. package/dist/src/utils/ownership.d.ts +88 -20
  587. package/dist/src/utils/ownership.js +187 -223
  588. package/dist/src/utils/ownership.js.map +1 -1
  589. package/dist/src/utils/path-catalog-provider.d.ts +1 -1
  590. package/dist/src/utils/path-catalog-provider.js +54 -65
  591. package/dist/src/utils/path-catalog-provider.js.map +1 -1
  592. package/dist/src/utils/paths.d.ts +0 -1
  593. package/dist/src/utils/paths.js +1 -2
  594. package/dist/src/utils/paths.js.map +1 -1
  595. package/dist/src/utils/platform-support.d.ts +1 -1
  596. package/dist/src/utils/platform-support.js +1 -1
  597. package/dist/src/utils/platform-support.js.map +1 -1
  598. package/dist/src/utils/plugin-config-impact.d.ts +58 -0
  599. package/dist/src/utils/plugin-config-impact.js +323 -0
  600. package/dist/src/utils/plugin-config-impact.js.map +1 -0
  601. package/dist/src/utils/plugin-config-references.d.ts +89 -0
  602. package/dist/src/utils/plugin-config-references.js +335 -0
  603. package/dist/src/utils/plugin-config-references.js.map +1 -0
  604. package/dist/src/utils/plugin-config-write.d.ts +109 -27
  605. package/dist/src/utils/plugin-config-write.js +1246 -368
  606. package/dist/src/utils/plugin-config-write.js.map +1 -1
  607. package/dist/src/utils/plugin-config.d.ts +189 -120
  608. package/dist/src/utils/plugin-config.js +926 -1270
  609. package/dist/src/utils/plugin-config.js.map +1 -1
  610. package/dist/src/utils/plugin-scripts.d.ts +75 -128
  611. package/dist/src/utils/plugin-scripts.js +556 -525
  612. package/dist/src/utils/plugin-scripts.js.map +1 -1
  613. package/dist/src/utils/process-lock.js +14 -5
  614. package/dist/src/utils/process-lock.js.map +1 -1
  615. package/dist/src/utils/process-tree.d.ts +2 -2
  616. package/dist/src/utils/process-tree.js +1 -1
  617. package/dist/src/utils/process-tree.js.map +1 -1
  618. package/dist/src/utils/project-boundary.d.ts +11 -13
  619. package/dist/src/utils/project-boundary.js +28 -34
  620. package/dist/src/utils/project-boundary.js.map +1 -1
  621. package/dist/src/utils/rendered-contract.js +18 -1
  622. package/dist/src/utils/rendered-contract.js.map +1 -1
  623. package/dist/src/utils/runtime-config.d.ts +20 -0
  624. package/dist/src/utils/runtime-config.js +77 -0
  625. package/dist/src/utils/runtime-config.js.map +1 -0
  626. package/dist/src/utils/runtime-skill-closure.d.ts +2 -2
  627. package/dist/src/utils/runtime-skill-closure.js +47 -6
  628. package/dist/src/utils/runtime-skill-closure.js.map +1 -1
  629. package/dist/src/utils/safe-fs.d.ts +21 -0
  630. package/dist/src/utils/safe-fs.js +111 -0
  631. package/dist/src/utils/safe-fs.js.map +1 -0
  632. package/dist/src/utils/safe-operation-diagnostic.d.ts +15 -0
  633. package/dist/src/utils/safe-operation-diagnostic.js +33 -0
  634. package/dist/src/utils/safe-operation-diagnostic.js.map +1 -0
  635. package/dist/src/utils/sensitive-content.d.ts +4 -0
  636. package/dist/src/utils/sensitive-content.js +36 -0
  637. package/dist/src/utils/sensitive-content.js.map +1 -0
  638. package/dist/src/utils/state-paths.d.ts +8 -3
  639. package/dist/src/utils/state-paths.js +51 -9
  640. package/dist/src/utils/state-paths.js.map +1 -1
  641. package/dist/src/utils/target-eligibility.d.ts +8 -2
  642. package/dist/src/utils/target-eligibility.js +17 -8
  643. package/dist/src/utils/target-eligibility.js.map +1 -1
  644. package/dist/src/utils/windows-claude-shim.d.ts +7 -0
  645. package/dist/src/utils/windows-claude-shim.js +10 -0
  646. package/dist/src/utils/windows-claude-shim.js.map +1 -0
  647. package/dist/src/utils/windows-npm-shim.d.ts +16 -0
  648. package/dist/src/utils/windows-npm-shim.js +138 -0
  649. package/dist/src/utils/windows-npm-shim.js.map +1 -0
  650. package/dist/vitest.config.js +101 -9
  651. package/dist/vitest.config.js.map +1 -1
  652. package/package.json +31 -21
  653. package/dist/authoring/scripts/check-plugin-versions.d.mts +0 -2
  654. package/dist/authoring/scripts/check-plugin-versions.mjs +0 -5
  655. package/dist/authoring/scripts/check-plugin-versions.mjs.map +0 -1
  656. package/dist/scripts/aw-skill-eval-engine.d.ts +0 -13
  657. package/dist/scripts/aw-skill-eval-engine.js +0 -31
  658. package/dist/scripts/aw-skill-eval-engine.js.map +0 -1
  659. package/dist/scripts/codex-eval-app-server.d.ts +0 -89
  660. package/dist/scripts/codex-eval-app-server.js +0 -1228
  661. package/dist/scripts/codex-eval-app-server.js.map +0 -1
  662. package/dist/scripts/codex-eval-isolation.d.ts +0 -61
  663. package/dist/scripts/codex-eval-isolation.js +0 -318
  664. package/dist/scripts/codex-eval-isolation.js.map +0 -1
  665. package/dist/scripts/codex-eval-process-management.d.ts +0 -8
  666. package/dist/scripts/codex-eval-process-management.js +0 -69
  667. package/dist/scripts/codex-eval-process-management.js.map +0 -1
  668. package/dist/scripts/codex-eval-process-tree.d.ts +0 -38
  669. package/dist/scripts/codex-eval-process-tree.js +0 -803
  670. package/dist/scripts/codex-eval-process-tree.js.map +0 -1
  671. package/dist/scripts/codex-eval-runtime-config.d.ts +0 -62
  672. package/dist/scripts/codex-eval-runtime-config.js +0 -843
  673. package/dist/scripts/codex-eval-runtime-config.js.map +0 -1
  674. package/dist/scripts/codex-trigger-eval.d.ts +0 -84
  675. package/dist/scripts/codex-trigger-eval.js +0 -968
  676. package/dist/scripts/codex-trigger-eval.js.map +0 -1
  677. package/dist/scripts/eval-plugin-skills-audited.d.ts +0 -6
  678. package/dist/scripts/eval-plugin-skills-audited.js +0 -261
  679. package/dist/scripts/eval-plugin-skills-audited.js.map +0 -1
  680. package/dist/scripts/eval-plugin-skills.d.ts +0 -45
  681. package/dist/scripts/eval-plugin-skills.js +0 -1586
  682. package/dist/scripts/eval-plugin-skills.js.map +0 -1
  683. package/dist/scripts/eval-run-layout.d.ts +0 -17
  684. package/dist/scripts/eval-run-layout.js +0 -26
  685. package/dist/scripts/eval-run-layout.js.map +0 -1
  686. package/dist/scripts/plugin-eval-contract.d.ts +0 -185
  687. package/dist/scripts/plugin-eval-contract.js +0 -695
  688. package/dist/scripts/plugin-eval-contract.js.map +0 -1
  689. package/dist/scripts/plugin-eval-materializer.d.ts +0 -13
  690. package/dist/scripts/plugin-eval-materializer.js +0 -421
  691. package/dist/scripts/plugin-eval-materializer.js.map +0 -1
  692. package/dist/scripts/skill-reporting.d.ts +0 -212
  693. package/dist/scripts/skill-reporting.js +0 -922
  694. package/dist/scripts/skill-reporting.js.map +0 -1
  695. package/dist/src/commands/review-publication.d.ts +0 -99
  696. package/dist/src/commands/review-publication.js +0 -904
  697. package/dist/src/commands/review-publication.js.map +0 -1
  698. package/dist/src/commands/status-v4.d.ts +0 -123
  699. package/dist/src/commands/status-v4.js +0 -905
  700. package/dist/src/commands/status-v4.js.map +0 -1
  701. package/dist/src/commands/status.d.ts +0 -93
  702. package/dist/src/commands/status.js +0 -442
  703. package/dist/src/commands/status.js.map +0 -1
  704. package/dist/src/portable/skills-cli.d.ts +0 -43
  705. package/dist/src/portable/skills-cli.js +0 -148
  706. package/dist/src/portable/skills-cli.js.map +0 -1
  707. package/dist/src/utils/active-marketplace-runtime-lock.d.ts +0 -12
  708. package/dist/src/utils/active-marketplace-runtime-lock.js +0 -133
  709. package/dist/src/utils/active-marketplace-runtime-lock.js.map +0 -1
  710. package/dist/src/utils/catalog-manifest-v3.d.ts +0 -2
  711. package/dist/src/utils/catalog-manifest-v3.js +0 -3
  712. package/dist/src/utils/catalog-manifest-v3.js.map +0 -1
  713. package/dist/src/utils/catalog-manifest-v4.d.ts +0 -5
  714. package/dist/src/utils/catalog-manifest-v4.js.map +0 -1
  715. package/dist/src/utils/catalog-source-cache.d.ts +0 -62
  716. package/dist/src/utils/catalog-source-cache.js +0 -296
  717. package/dist/src/utils/catalog-source-cache.js.map +0 -1
  718. package/dist/src/utils/codex-project-surface.d.ts +0 -3
  719. package/dist/src/utils/codex-project-surface.js +0 -49
  720. package/dist/src/utils/codex-project-surface.js.map +0 -1
  721. package/dist/src/utils/lifecycle-active-store.d.ts +0 -175
  722. package/dist/src/utils/lifecycle-active-store.js +0 -1276
  723. package/dist/src/utils/lifecycle-active-store.js.map +0 -1
  724. package/dist/src/utils/plugin-release.d.ts +0 -2
  725. package/dist/src/utils/plugin-release.js +0 -2
  726. package/dist/src/utils/plugin-release.js.map +0 -1
@@ -1,16 +1,92 @@
1
- import path from 'node:path';
2
- import { discoverRebuildTargetNames, inspectRebuildTarget, } from '../commands/rebuild-integration.js';
3
- import { reinstallWriteCommand } from '../commands/write-commands.js';
4
- import { createNoopDebugLogger } from '../output/debug-log.js';
5
- import { createNoopReporter } from '../output/reporter.js';
6
- import { getDefaultNativeCliRunner } from './native-cli.js';
7
- import { resolveAwHome } from './paths.js';
8
- import { hasCodexProjectManagedArtifacts } from './codex-project-surface.js';
9
- import { assertSafePluginConfigSegment, coercePluginConfigUpdates, collectProjectArtifactConfigBoundaryIssues, patchPluginConfigStore, readPluginConfigStore, resetPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolvePluginConfigSchemaAccess, summarizeEffectivePluginConfig, withPluginConfigTransactionLease, } from './plugin-config.js';
10
- import { assertProjectSharedConfigPathVisible, ensureProjectPrivateStateIgnore, } from './project-boundary.js';
11
- import { resolveClaudeProjectKey, resolveCodexProjectKey } from './paths.js';
12
- import { supportsPlatform } from './platform-support.js';
1
+ import { resolveWorkContext } from '../intent/work-context.js';
2
+ import { statusTargetHasLiveConfigConsumer } from '../commands/status-v6.js';
3
+ import { readDemand, demandNativeProjection } from '../recovery/demand.js';
4
+ import { createScopeContext } from '../intent/scope-context.js';
5
+ import { selectPluginConfigProfile, getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
6
+ import { flattenStatusTargets, statusCommandV8, } from '../commands/status-v6.js';
7
+ import { syncWriteCommand } from '../commands/write-commands.js';
8
+ import { CONFIG_MUTATION_RECEIPT_SCHEMA_VERSION, } from '../types.js';
9
+ import { getDefaultNativeCliRunner, prepareNativeCliExecution } from './native-cli.js';
10
+ import { assertPluginConfigMutationCandidate, assertSafePluginConfigSegment, coercePluginConfigUpdates, patchPluginConfigStore, PluginConfigSchemaResolutionError, readPluginConfigStore, readNamespacedPluginConfigStoreIdentity, resetPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolvePluginConfigStorePath, resolvePluginConfigSchemaAccess, summarizeEffectivePluginConfig, } from './plugin-config.js';
11
+ import { analyzePluginConfigMutationImpact, discoverPluginConfigManagedCommandPackages, pluginConfigTargetRenderScopes, pluginSharedNativeConfigTargets } from './plugin-config-impact.js';
12
+ import { collectPluginConfigReferenceEvidence, resolvePluginConfigReferencePlugins, resolvePluginConfigReferenceConsumers } from './plugin-config-references.js';
13
+ import { orderPluginMetasByDependencies, resolvePluginMetaDependencyClosure } from './plugin-dependencies.js';
14
+ import { assertManagedCommandPackageNativeToolsUnchanged, discoverInstalledPluginManagedCommandPackages, syncPluginManagedCommandPackage, } from './managed-command-materialization.js';
15
+ import { listManagedCommandPackages, managedCommandDiagnostic, readInstalledCommandProducer } from './managed-command-store.js';
16
+ import { collectSensitivePluginConfigValues, redactPluginScriptOutput, } from './plugin-scripts.js';
17
+ import { resolveClaudeProjectKey, resolveCodexProjectKey, resolveCliPackageRoot } from './paths.js';
18
+ import { readSafeOperationError } from './safe-operation-diagnostic.js';
13
19
  import { withAwHomeMutationLock, } from './aw-home-mutation-lock.js';
20
+ import fs from 'fs-extra';
21
+ import path from 'node:path';
22
+ import crypto from 'node:crypto';
23
+ export function buildConfigMutationReceipt(command, receipt) {
24
+ return {
25
+ ...receipt,
26
+ receiptSchemaVersion: CONFIG_MUTATION_RECEIPT_SCHEMA_VERSION,
27
+ command,
28
+ };
29
+ }
30
+ function publicConfigApplyTargetResult(result) {
31
+ return {
32
+ target: {
33
+ pluginName: result.target.pluginName,
34
+ ...(result.target.pluginId ? { pluginId: result.target.pluginId } : {}),
35
+ platform: result.target.platform,
36
+ scope: result.target.scope,
37
+ },
38
+ action: result.action,
39
+ state: result.state,
40
+ ...(result.message ? { message: result.message } : {}),
41
+ ...(result.errorCode ? { errorCode: result.errorCode } : {}),
42
+ ...(result.relation ? { relation: result.relation } : {}),
43
+ ...(result.requiredBy ? { requiredBy: result.requiredBy } : {}),
44
+ };
45
+ }
46
+ function publicConfigApplyResult(apply) {
47
+ if (apply.state === 'skipped')
48
+ return apply;
49
+ return {
50
+ ...apply,
51
+ targetResults: apply.targetResults.map(publicConfigApplyTargetResult),
52
+ };
53
+ }
54
+ export function configWriteStateForError(error) {
55
+ return error?.configWrite === 'failed'
56
+ ? 'failed'
57
+ : 'notStarted';
58
+ }
59
+ function markConfigWriteFailed(error) {
60
+ const failure = error instanceof Error ? error : new Error(String(error));
61
+ return Object.assign(failure, { configWrite: 'failed' });
62
+ }
63
+ function skippedApply(reason) {
64
+ return { state: 'skipped', reason, targetResults: [] };
65
+ }
66
+ function unavailableApply(reason, stage, targetResults = [], commandPackages = []) {
67
+ const messages = {
68
+ invalidConfig: 'The effective config is invalid for every visible target.',
69
+ schemaUnavailable: 'The config schema is unavailable after the config commit.',
70
+ sourceUnavailable: 'The plugin source is unavailable after the config commit.',
71
+ effectiveConfigUnavailable: 'The effective config cannot be read after the config commit.',
72
+ targetDiscoveryFailed: 'Visible config apply targets cannot be discovered after the config commit.',
73
+ };
74
+ return {
75
+ state: 'unavailable',
76
+ reason,
77
+ targetResults,
78
+ ...(commandPackages.length > 0 ? { commandResults: commandPackages.map((target) => ({
79
+ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
80
+ errors: [{ code: reason, message: messages[reason] }],
81
+ recoveryActions: [`aw command package sync ${target.producer.sourceId}/${target.producer.pluginName} ${target.packageKey} --scope ${target.producer.scope} --yes`,
82
+ `aw command package remove ${target.packageId} --yes`],
83
+ })) } : {}),
84
+ error: { stage, code: reason, message: messages[reason] },
85
+ };
86
+ }
87
+ function overallStateForApply(apply) {
88
+ return apply.state === 'succeeded' || apply.state === 'skipped' ? 'succeeded' : 'partial';
89
+ }
14
90
  function uniqueInOrder(values) {
15
91
  return [...new Set(values)];
16
92
  }
@@ -18,7 +94,7 @@ function collectRemovedConfigKeys(values) {
18
94
  return uniqueInOrder(Object.keys(values));
19
95
  }
20
96
  function targetKey(target) {
21
- return `${target.platform}:${target.scope}:${target.projectKey ?? '-'}`;
97
+ return `${target.pluginName}:${target.platform}:${target.scope}:${target.projectKey ?? '-'}`;
22
98
  }
23
99
  function dedupeTargets(targets) {
24
100
  const deduped = new Map();
@@ -44,154 +120,607 @@ async function createCandidateTarget(options) {
44
120
  async function discoverVisibleTargets(options) {
45
121
  const targets = [];
46
122
  const failures = [];
47
- const namedTargets = [];
48
- const scopes = options.scope === 'user' ? ['user', 'project'] : ['project'];
49
- for (const platform of ['codex', 'claude']) {
50
- for (const scope of scopes) {
51
- if (!supportsPlatform(options.plugin.manifest, platform))
52
- continue;
53
- if (platform === 'codex'
54
- && scope === 'project'
55
- && !hasCodexProjectManagedArtifacts(options.plugin))
123
+ const selector = options.plugin.pluginId ?? options.pluginName;
124
+ const consumers = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env,
125
+ plugins: options.rebuildRuntime?.referencePlugins });
126
+ const selectors = consumers.map((plugin) => plugin.pluginId ?? plugin.manifest.name);
127
+ const status = await statusCommandV8({
128
+ plugins: selectors.length ? selectors : [selector],
129
+ cwd: options.cwd,
130
+ env: options.env,
131
+ nativeCliRunner: options.nativeCliRunner,
132
+ ...(options.scope === 'project' ? { scope: 'project' } : {}),
133
+ ...(options.rebuildRuntime?.catalogOperationContext
134
+ ? { catalogOperationContext: options.rebuildRuntime.catalogOperationContext }
135
+ : {}),
136
+ });
137
+ for (const statusTarget of flattenStatusTargets(status.payload.targets)) {
138
+ if (!selectors.includes(statusTarget.pluginId ?? '')
139
+ && !consumers.some((plugin) => plugin.manifest.name === statusTarget.pluginName)
140
+ && statusTarget.pluginId !== selector && statusTarget.pluginName !== options.pluginName)
141
+ continue;
142
+ // A declaration alone is not a consumer. Config apply cannot install it.
143
+ if (!statusTargetHasLiveConfigConsumer(statusTarget))
144
+ continue;
145
+ if (options.scope === 'user' && statusTarget.scope !== 'user')
146
+ continue;
147
+ targets.push(await createCandidateTarget({
148
+ pluginName: statusTarget.pluginName,
149
+ platform: statusTarget.platform,
150
+ scope: statusTarget.scope,
151
+ cwd: options.cwd,
152
+ }));
153
+ }
154
+ return { targets: dedupeTargets(targets), failures };
155
+ }
156
+ async function reinstallVisibleTargets(options) {
157
+ const nativeCliRunner = options.nativeCliRunner ?? getDefaultNativeCliRunner();
158
+ const discovered = options.discovered ?? await resolveConfigApplyTargets(options);
159
+ const managedCommandProducerCache = options.rebuildRuntime?.managedCommandProducerCache
160
+ ?? new Map();
161
+ if (discovered.targets.some((target) => target.pluginName !== options.plugin.manifest.name)
162
+ || discovered.commandPackages?.some((target) => target.producer.pluginName !== options.plugin.manifest.name)) {
163
+ const plugins = discovered.plugins ?? await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
164
+ sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
165
+ env: options.env, plugins: options.rebuildRuntime?.referencePlugins });
166
+ const results = [...discovered.failures];
167
+ const commandResults = [];
168
+ const failed = new Set(discovered.failures.map(({ target }) => `${target.pluginName}\0${target.platform}\0${target.scope}`));
169
+ const failedPackages = new Set();
170
+ const errors = (discovered.commandDiscoveryErrors ?? []).map((error) => ({
171
+ stage: 'targetDiscovery', code: error.code, message: error.message,
172
+ }));
173
+ let partial = discovered.failures.length > 0 || errors.length > 0;
174
+ for (const plugin of orderPluginMetasByDependencies(plugins)) {
175
+ const targets = discovered.targets.filter((target) => target.pluginName === plugin.manifest.name);
176
+ const packages = (discovered.commandPackages ?? []).filter((target) => target.producer.pluginName === plugin.manifest.name);
177
+ if (!targets.length && !packages.length)
56
178
  continue;
57
- const target = await createCandidateTarget({
58
- pluginName: options.pluginName,
59
- platform,
60
- scope,
61
- cwd: options.cwd,
179
+ const dependencies = resolvePluginMetaDependencyClosure(plugins, [plugin.manifest.name])
180
+ .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.manifest.name);
181
+ const dependencyPackageFailed = (scope) => dependencies.some((dependency) => failedPackages.has(`${dependency}\0${scope}`) || (scope === 'project' && failedPackages.has(`${dependency}\0user`)));
182
+ const blocked = targets.filter((target) => dependencies.some((dependency) => failed.has(`${dependency}\0${target.platform}\0${target.scope}`)
183
+ || (target.scope === 'project' && failed.has(`${dependency}\0${target.platform}\0user`)))
184
+ || dependencyPackageFailed(target.scope));
185
+ if (blocked.length) {
186
+ partial = true;
187
+ for (const target of blocked)
188
+ failed.add(`${plugin.manifest.name}\0${target.platform}\0${target.scope}`);
189
+ results.push(...blocked.map((target) => ({ target, action: 'skipped',
190
+ state: 'skipped', errorCode: 'dependencyApplyFailed',
191
+ message: `A required provider failed. Run aw plugin sync ${plugin.pluginId ?? plugin.manifest.name} --context ${target.scope} --target ${target.platform} --yes.` })));
192
+ }
193
+ const blockedPackages = packages.filter((target) => {
194
+ const platforms = plugin.manifest.managedCommands?.packages.find((entry) => entry.key === target.packageKey
195
+ && entry.scope === target.producer.scope)?.platforms ?? ['codex', 'claude'];
196
+ return dependencyPackageFailed(target.producer.scope) || dependencies.some((dependency) => platforms.some((platform) => failed.has(`${dependency}\0${platform}\0${target.producer.scope}`)
197
+ || (target.producer.scope === 'project' && failed.has(`${dependency}\0${platform}\0user`))));
62
198
  });
199
+ for (const target of blockedPackages) {
200
+ partial = true;
201
+ failedPackages.add(`${plugin.manifest.name}\0${target.producer.scope}`);
202
+ commandResults.push({ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
203
+ errors: [{ code: 'dependencyApplyFailed', message: 'A required provider failed; the command package was not refreshed.' }],
204
+ recoveryActions: [`aw command package sync ${plugin.pluginId ?? plugin.manifest.name} ${target.packageKey} --scope ${target.producer.scope} --yes`] });
205
+ }
206
+ const available = targets.filter((target) => !blocked.includes(target));
207
+ const availablePackages = packages.filter((target) => !blockedPackages.includes(target));
208
+ if (!available.length && !availablePackages.length)
209
+ continue;
210
+ const own = plugin.manifest.name === options.plugin.manifest.name;
211
+ const result = await reinstallVisibleTargets({ ...options, plugin,
212
+ changedConfigKeys: own ? options.changedConfigKeys : [],
213
+ rebuildRuntime: { ...options.rebuildRuntime, referencePlugins: plugins, managedCommandProducerCache },
214
+ discovered: { targets: available, failures: [], commandPackages: availablePackages,
215
+ commandDiscoveryErrors: [] } });
216
+ if (result.state !== 'succeeded' && result.state !== 'skipped') {
217
+ partial = true;
218
+ for (const target of available) {
219
+ if (!('targetResults' in result) || !result.targetResults.some((entry) => targetKey(entry.target) === targetKey(target) && entry.state === 'completed')) {
220
+ failed.add(`${plugin.manifest.name}\0${target.platform}\0${target.scope}`);
221
+ }
222
+ }
223
+ }
224
+ if ('targetResults' in result)
225
+ results.push(...result.targetResults);
226
+ if ('commandResults' in result) {
227
+ commandResults.push(...result.commandResults ?? []);
228
+ for (const entry of result.commandResults ?? []) {
229
+ if (entry.state !== 'completed')
230
+ failedPackages.add(`${plugin.manifest.name}\0${entry.producer.scope}`);
231
+ }
232
+ }
233
+ if ('errors' in result)
234
+ errors.push(...result.errors ?? []);
235
+ }
236
+ return { state: partial ? 'partial' : 'succeeded', targetResults: results,
237
+ ...(commandResults.length ? { commandResults } : {}), ...(errors.length ? { errors } : {}) };
238
+ }
239
+ const contexts = new Map();
240
+ const demands = new Map();
241
+ const failedScopes = new Set();
242
+ try {
243
+ const targetResults = [...discovered.failures];
244
+ const commandResults = new Map();
245
+ let runtimeFailed = discovered.failures.length > 0
246
+ || (discovered.commandDiscoveryErrors?.length ?? 0) > 0;
247
+ let invalidTargets = 0;
248
+ let unavailableTargets = 0;
249
+ const errors = [];
250
+ for (const scope of new Set(discovered.targets.map((target) => target.scope))) {
251
+ try {
252
+ const context = await createScopeContext({ scope, cwd: options.cwd, env: options.env });
253
+ contexts.set(scope, context);
254
+ const demand = await readDemand({ scope, cwd: context.executionCwd, env: context.env });
255
+ demandNativeProjection(demand);
256
+ demands.set(scope, demand);
257
+ }
258
+ catch {
259
+ failedScopes.add(scope);
260
+ runtimeFailed = true;
261
+ for (const target of discovered.targets.filter((entry) => entry.scope === scope)) {
262
+ targetResults.push({ target, action: 'reinstall', state: 'failed', errorCode: 'configApplyContextUnavailable',
263
+ message: 'The target scope or its demand cannot be read safely.' });
264
+ }
265
+ errors.push({ stage: 'targetValidation', code: 'configApplyContextUnavailable',
266
+ message: 'A visible target scope or its demand cannot be read safely.' });
267
+ }
268
+ }
269
+ if ((discovered.commandDiscoveryErrors?.length ?? 0) > 0) {
270
+ errors.push(...discovered.commandDiscoveryErrors.map((error) => ({
271
+ stage: 'targetDiscovery', code: error.code, message: error.message,
272
+ })));
273
+ }
274
+ const reinstall = options.reinstallCommandImpl ?? syncWriteCommand;
275
+ if (options.plugin.sourceId && !options.plugin.pluginId) {
276
+ throw new Error(`Plugin "${options.plugin.manifest.name}" is missing its namespaced plugin ID.`);
277
+ }
278
+ const selector = options.plugin.sourceId
279
+ ? options.plugin.pluginId
280
+ : options.plugin.manifest.name;
281
+ const nativeFailures = [];
282
+ for (const target of discovered.commandPackages ?? []) {
283
+ try {
284
+ await assertManagedCommandPackageNativeToolsUnchanged({ plugin: options.plugin, producer: target.producer, env: options.env });
285
+ }
286
+ catch (error) {
287
+ nativeFailures.push({ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
288
+ errors: [managedCommandDiagnostic(error)],
289
+ recoveryActions: [`aw command package sync ${selector} ${target.packageKey} --scope ${target.producer.scope} --yes`] });
290
+ }
291
+ }
292
+ if (nativeFailures.length > 0) {
293
+ return { state: 'partial', commandResults: nativeFailures,
294
+ targetResults: [...targetResults, ...discovered.targets.map((target) => ({
295
+ target, action: 'reinstall', state: 'failed', errorCode: 'nativeToolSyncRequired',
296
+ message: 'Run a reviewed producer sync or package sync before configuration apply.',
297
+ }))] };
298
+ }
299
+ const sanitizeFailure = async (message, target) => {
300
+ let sensitiveValues = [];
63
301
  try {
64
- const names = await discoverRebuildTargetNames({
302
+ const effective = await resolveEffectivePluginConfig({
303
+ ...(options.plugin.sourceId ? {
304
+ sourceId: options.plugin.sourceId,
305
+ sourceIdentity: options.plugin.sourceIdentity,
306
+ logicalIdentity: options.plugin.catalogLogicalIdentity,
307
+ } : {}),
308
+ pluginName: options.plugin.manifest.name,
309
+ manifest: options.plugin.manifest,
310
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
311
+ targetScope: target.scope,
312
+ platform: target.platform ?? undefined,
65
313
  cwd: options.cwd,
66
314
  env: options.env,
67
- platform,
315
+ });
316
+ sensitiveValues = collectSensitivePluginConfigValues(options.plugin.manifest, effective.values, target.platform ?? undefined);
317
+ }
318
+ catch {
319
+ // Generic credential redaction and known config paths still apply.
320
+ }
321
+ let sanitized = redactPluginScriptOutput(message, sensitiveValues);
322
+ for (const privatePath of [target.projectKey, options.cwd]) {
323
+ if (privatePath)
324
+ sanitized = sanitized.split(privatePath).join('<project>');
325
+ }
326
+ for (const scope of ['user', 'project']) {
327
+ const configPath = resolvePluginConfigStorePath({
328
+ sourceId: options.plugin.sourceId,
329
+ pluginName: options.plugin.manifest.name,
68
330
  scope,
69
- nativeCliRunner: options.nativeCliRunner,
70
- nativeFailureMode: 'ignore',
71
- marketplaceName: options.plugin.marketplaceName,
72
- marketplaceRoot: options.plugin.sourceId
73
- ? path.join(resolveAwHome(options.env), 'marketplaces', options.plugin.sourceId)
74
- : undefined,
331
+ cwd: options.cwd,
332
+ env: options.env,
75
333
  });
76
- if (!names.includes(options.pluginName))
334
+ const safeTarget = `${scope}/plugin-config/${[
335
+ options.plugin.sourceId,
336
+ options.plugin.manifest.name,
337
+ 'config.json',
338
+ ].filter(Boolean).join('/')}`;
339
+ sanitized = sanitized.split(configPath).join(safeTarget);
340
+ }
341
+ return sanitized;
342
+ };
343
+ const sanitizeProjection = async (value, target, freeText = false) => {
344
+ if (typeof value === 'string')
345
+ return freeText ? sanitizeFailure(value, target) : value;
346
+ if (value === null || typeof value !== 'object')
347
+ return value;
348
+ if (Array.isArray(value)) {
349
+ return Promise.all(value.map((entry) => sanitizeProjection(entry, target, freeText)));
350
+ }
351
+ return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, entry]) => [
352
+ key,
353
+ await sanitizeProjection(entry, target, typeof entry === 'string'
354
+ ? /^(?:message|error|stack|stdout|stderr|output|warning)$/u.test(key)
355
+ : Array.isArray(entry) && /^(?:messages|warnings)$/u.test(key)),
356
+ ])));
357
+ };
358
+ const preApplyExecutionCache = new Map();
359
+ for (const target of discovered.targets) {
360
+ if (failedScopes.has(target.scope))
361
+ continue;
362
+ try {
363
+ const configs = await Promise.all(pluginConfigTargetRenderScopes(options.plugin, target).map((scope) => resolveEffectivePluginConfig({
364
+ ...(options.plugin.sourceId ? {
365
+ sourceId: options.plugin.sourceId,
366
+ sourceIdentity: options.plugin.sourceIdentity,
367
+ logicalIdentity: options.plugin.catalogLogicalIdentity,
368
+ } : {}),
369
+ pluginName: options.plugin.manifest.name,
370
+ manifest: options.plugin.manifest,
371
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
372
+ targetScope: scope,
373
+ platform: target.platform ?? undefined,
374
+ cwd: options.cwd,
375
+ env: options.env,
376
+ })));
377
+ if (configs.some((effective) => effective.issues.length > 0)) {
378
+ invalidTargets += 1;
379
+ targetResults.push({
380
+ target,
381
+ action: 'reinstall',
382
+ state: 'skipped',
383
+ errorCode: 'invalidConfig',
384
+ message: 'The effective config is invalid for this target.',
385
+ });
77
386
  continue;
78
- namedTargets.push(target);
387
+ }
388
+ }
389
+ catch {
390
+ runtimeFailed = true;
391
+ unavailableTargets += 1;
392
+ targetResults.push({
393
+ target,
394
+ action: 'reinstall',
395
+ state: 'failed',
396
+ errorCode: 'effectiveConfigUnavailable',
397
+ message: 'The effective config cannot be read for this target.',
398
+ });
399
+ errors.push({
400
+ stage: 'targetValidation',
401
+ code: 'effectiveConfigUnavailable',
402
+ message: 'The effective config cannot be read for a visible target.',
403
+ });
404
+ continue;
405
+ }
406
+ try {
407
+ const debugLogger = options.rebuildRuntime?.debugLogger;
408
+ const reporter = options.rebuildRuntime?.reporter;
409
+ const result = await reinstall([selector], {
410
+ cwd: contexts.get(target.scope).executionCwd,
411
+ platform: target.platform,
412
+ scope: target.scope,
413
+ ...(options.rebuildRuntime?.scriptTimeoutMs === undefined
414
+ ? {}
415
+ : { scriptTimeoutMs: options.rebuildRuntime.scriptTimeoutMs }),
416
+ }, {
417
+ ...options.rebuildRuntime,
418
+ env: contexts.get(target.scope).env,
419
+ nativeCliRunner,
420
+ executionInput: {
421
+ context: contexts.get(target.scope),
422
+ requirements: demandNativeProjection(demands.get(target.scope)),
423
+ selectedTargets: [{ pluginId: selector, platform: target.platform, scope: target.scope }],
424
+ preserveOtherObservedTargets: true,
425
+ },
426
+ preApplyConfirmed: options.preApplyConfirmed === true,
427
+ preApplyExecutionCache,
428
+ managedCommandProducerCache,
429
+ ...(debugLogger ? {
430
+ debugLogger: {
431
+ ...debugLogger,
432
+ log: async (value) => debugLogger.log(await sanitizeProjection(value, target)),
433
+ },
434
+ } : {}),
435
+ ...(reporter ? {
436
+ reporter: {
437
+ event: async (value) => reporter.event(await sanitizeProjection(value, target)),
438
+ notice: async (value) => reporter.notice(await sanitizeProjection(value, target)),
439
+ },
440
+ } : {}),
441
+ });
442
+ options.rebuildRuntime?.operationDiagnosticSink?.(result.rebuildResults);
443
+ for (const producer of result.commandResults ?? []) {
444
+ commandResults.set(getCommandPackageId(producer.producer), producer);
445
+ if (producer.state !== 'completed')
446
+ runtimeFailed = true;
447
+ }
448
+ if (result.overallState !== 'succeeded')
449
+ runtimeFailed = true;
450
+ targetResults.push(...await Promise.all(result.targetResults.map(async (entry) => ({
451
+ ...entry,
452
+ state: entry.action === 'skipped' ? 'skipped' : entry.state,
453
+ ...(entry.message ? { message: await sanitizeFailure(entry.message, entry.target) } : {}),
454
+ }))));
79
455
  }
80
456
  catch (error) {
81
- failures.push({
457
+ runtimeFailed = true;
458
+ const message = await sanitizeFailure(error instanceof Error ? error.message : String(error), target);
459
+ targetResults.push({
82
460
  target,
83
461
  action: 'reinstall',
84
462
  state: 'failed',
85
- message: error instanceof Error ? error.message : String(error),
463
+ message,
464
+ });
465
+ errors.push({
466
+ stage: 'apply',
467
+ code: 'targetApplyFailed',
468
+ message: 'A visible config apply target failed.',
86
469
  });
87
470
  }
88
471
  }
89
- }
90
- if (namedTargets.length === 0)
91
- return { targets, failures };
92
- const catalog = options.rebuildRuntime?.catalogResolution ?? {
93
- rootDir: options.plugin.sourceId
94
- ? path.resolve(options.plugin.rootDir, '..', '..')
95
- : options.plugin.rootDir,
96
- source: 'local',
97
- };
98
- for (const target of namedTargets) {
99
- try {
100
- const inspected = await inspectRebuildTarget({
101
- sourceId: options.plugin.sourceId,
102
- sourceIdentity: options.plugin.sourceIdentity,
103
- pluginId: options.plugin.pluginId,
104
- marketplaceName: options.plugin.marketplaceName,
105
- marketplaceRoot: options.plugin.sourceId
106
- ? path.join(resolveAwHome(options.env), 'marketplaces', options.plugin.sourceId)
107
- : undefined,
108
- plugin: options.plugin,
109
- platform: target.platform,
110
- scope: target.scope,
111
- cwd: options.cwd,
112
- catalog,
113
- context: {
114
- env: options.env,
115
- nativeCliRunner: options.nativeCliRunner,
116
- reporter: options.rebuildRuntime?.reporter ?? createNoopReporter(),
117
- debugLogger: options.rebuildRuntime?.debugLogger ?? createNoopDebugLogger(),
118
- },
472
+ for (const target of discovered.commandPackages ?? []) {
473
+ await options.rebuildRuntime?.reporter?.event({
474
+ type: 'managed-command:producer',
475
+ source: { plugin: options.plugin.manifest.name, scope: target.producer.scope },
476
+ data: { packageKey: target.packageKey, phase: 'start' },
119
477
  });
120
- if (inspected.inspection.state === 'present' || inspected.inspection.state === 'partial') {
121
- targets.push(target);
478
+ let result;
479
+ if (!target.declared) {
480
+ result = {
481
+ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
482
+ errors: [{ code: 'commandPackageDeclarationMissing',
483
+ message: 'The installed command package is no longer declared by this plugin.' }],
484
+ recoveryActions: [`aw command package remove ${target.packageId} --yes`],
485
+ };
122
486
  }
123
- }
124
- catch (error) {
125
- failures.push({
126
- target,
127
- action: 'reinstall',
128
- state: 'failed',
129
- message: error instanceof Error ? error.message : String(error),
487
+ else {
488
+ try {
489
+ result = await syncPluginManagedCommandPackage({
490
+ plugin: options.plugin, packageKey: target.packageKey, scope: target.producer.scope,
491
+ cwd: options.cwd, env: options.env, managedCommandProducerCache,
492
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
493
+ event: options.changedConfigKeys?.length ? 'refresh' : 'install',
494
+ changedConfigKeys: options.changedConfigKeys ?? [],
495
+ signal: options.rebuildRuntime?.signal,
496
+ scriptTimeoutMs: options.rebuildRuntime?.scriptTimeoutMs,
497
+ });
498
+ }
499
+ catch (error) {
500
+ if (options.rebuildRuntime?.signal?.aborted
501
+ || error instanceof Error && error.name === 'AbortError'
502
+ || readSafeOperationError(error))
503
+ throw error;
504
+ result = {
505
+ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
506
+ errors: [{ code: 'commandPackageApplyFailed', message: 'The managed command package could not be refreshed.' }],
507
+ recoveryActions: [`aw command package sync ${selector} ${target.packageKey} --scope ${target.producer.scope} --yes`,
508
+ `aw command package remove ${target.packageId} --yes`],
509
+ };
510
+ }
511
+ }
512
+ result = { ...result, errors: await Promise.all(result.errors.map(async (error) => ({
513
+ ...error, message: await sanitizeFailure(error.message, { scope: target.producer.scope,
514
+ ...(target.producer.projectRoot ? { projectKey: target.producer.projectRoot } : {}) }),
515
+ }))) };
516
+ commandResults.set(getCommandPackageId(result.producer), result);
517
+ await options.rebuildRuntime?.reporter?.event({
518
+ type: 'managed-command:producer',
519
+ source: { plugin: options.plugin.manifest.name, scope: target.producer.scope },
520
+ data: { packageKey: target.packageKey, phase: result.state === 'completed' ? 'success' : 'failure' },
130
521
  });
522
+ if (result.state !== 'completed')
523
+ runtimeFailed = true;
524
+ }
525
+ const commands = commandResults.size > 0 ? { commandResults: [...commandResults.values()] } : {};
526
+ const commandTargetCount = (discovered.commandPackages?.length ?? 0);
527
+ if (discovered.targets.length === 0 && discovered.failures.length === 0
528
+ && commandTargetCount === 0 && !runtimeFailed) {
529
+ return skippedApply('noVisibleTarget');
530
+ }
531
+ if (discovered.targets.length > 0 && invalidTargets === discovered.targets.length && commandTargetCount === 0) {
532
+ return { ...unavailableApply('invalidConfig', 'targetValidation', targetResults), ...commands };
533
+ }
534
+ if (discovered.targets.length > 0 && unavailableTargets === discovered.targets.length && commandTargetCount === 0) {
535
+ return { ...unavailableApply('effectiveConfigUnavailable', 'targetValidation', targetResults), ...commands };
131
536
  }
537
+ if (runtimeFailed
538
+ || invalidTargets > 0
539
+ || unavailableTargets > 0
540
+ || targetResults.some((entry) => entry.state === 'failed' || entry.state === 'skipped')) {
541
+ return {
542
+ state: 'partial',
543
+ targetResults,
544
+ ...commands,
545
+ ...(errors.length > 0 ? { errors } : {}),
546
+ };
547
+ }
548
+ return { state: 'succeeded', targetResults, ...commands };
549
+ }
550
+ finally {
551
+ await Promise.all([...contexts.values()].map((context) => context.dispose()));
132
552
  }
133
- return { targets: dedupeTargets(targets), failures };
134
553
  }
135
- async function reinstallVisibleTargets(options) {
136
- const nativeCliRunner = options.nativeCliRunner ?? getDefaultNativeCliRunner();
137
- const discovered = options.applyTargets === undefined
138
- ? await discoverVisibleTargets({
554
+ async function resolveConfigApplyTargets(options) {
555
+ const platformTargets = options.applyTargets !== undefined
556
+ ? { targets: dedupeTargets(options.applyTargets), failures: [] }
557
+ : await discoverVisibleTargets({
139
558
  pluginName: options.plugin.manifest.name,
140
559
  plugin: options.plugin,
141
560
  scope: options.scope,
142
561
  cwd: options.cwd,
143
562
  env: options.env,
144
- nativeCliRunner,
563
+ nativeCliRunner: options.nativeCliRunner ?? getDefaultNativeCliRunner(),
145
564
  rebuildRuntime: options.rebuildRuntime,
146
- })
147
- : { targets: dedupeTargets(options.applyTargets), failures: [] };
148
- const targetResults = [...discovered.failures];
149
- let runtimeFailed = discovered.failures.length > 0;
150
- const reinstall = options.reinstallCommandImpl ?? reinstallWriteCommand;
565
+ });
566
+ const commands = await discoverPluginConfigManagedCommandPackages({
567
+ plugin: options.plugin, scope: options.scope, cwd: options.cwd, env: options.env,
568
+ platformTargets: platformTargets.targets,
569
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
570
+ });
571
+ return { ...platformTargets, commandPackages: commands.packages, commandDiscoveryErrors: commands.errors };
572
+ }
573
+ async function configApplyHasValidSharedNativeTarget(options) {
574
+ const plugins = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env, plugins: options.plugins });
575
+ for (const plugin of plugins) {
576
+ for (const target of options.targets.filter((target) => target.pluginName === plugin.manifest.name)) {
577
+ const shared = pluginSharedNativeConfigTargets(plugin);
578
+ if (!shared.some((entry) => (entry.platform ?? 'codex') === target.platform))
579
+ continue;
580
+ const effective = await resolveEffectivePluginConfig({ sourceId: plugin.sourceId,
581
+ sourceIdentity: plugin.sourceIdentity, logicalIdentity: plugin.catalogLogicalIdentity,
582
+ manifest: plugin.manifest, platform: target.platform, targetScope: 'user',
583
+ cwd: options.cwd, env: options.env, referencePlugins: options.plugins });
584
+ if (!effective.issues.length)
585
+ return true;
586
+ }
587
+ }
588
+ return false;
589
+ }
590
+ export async function resolveConfigPreApplyAuthorization(options) {
591
+ const applyTargets = dedupeTargets(options.applyTargets);
592
+ if (applyTargets.some((target) => target.pluginName !== options.plugin.manifest.name)) {
593
+ const plugins = await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
594
+ sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
595
+ env: options.env, plugins: options.rebuildRuntime?.referencePlugins });
596
+ const results = await Promise.all(plugins.map((plugin) => resolveConfigPreApplyAuthorization({ ...options, plugin,
597
+ applyTargets: applyTargets.filter((target) => target.pluginName === plugin.manifest.name) })));
598
+ return { targets: results.flatMap((result) => result.targets),
599
+ availableApplyTargets: results.flatMap((result) => result.availableApplyTargets),
600
+ unavailableTargetResults: results.flatMap((result) => result.unavailableTargetResults) };
601
+ }
602
+ if (applyTargets.length === 0 || !pluginMayRunPreApply(options.plugin)) {
603
+ return { targets: [], availableApplyTargets: applyTargets, unavailableTargetResults: [] };
604
+ }
151
605
  if (options.plugin.sourceId && !options.plugin.pluginId) {
152
- throw new Error(`Plugin "${options.plugin.manifest.name}" is missing its namespaced plugin ID.`);
606
+ return {
607
+ targets: [],
608
+ availableApplyTargets: [],
609
+ unavailableTargetResults: applyTargets.map((target) => ({
610
+ target,
611
+ action: 'reinstall',
612
+ state: 'failed',
613
+ errorCode: 'sourceUnavailable',
614
+ message: 'The preApply authorization scope cannot be resolved for this target.',
615
+ })),
616
+ };
153
617
  }
154
618
  const selector = options.plugin.sourceId
155
619
  ? options.plugin.pluginId
156
620
  : options.plugin.manifest.name;
157
- for (const target of discovered.targets) {
621
+ const groups = new Map();
622
+ for (const target of applyTargets) {
623
+ const targets = groups.get(target.scope) ?? [];
624
+ targets.push(target);
625
+ groups.set(target.scope, targets);
626
+ }
627
+ const authorization = [];
628
+ const availableApplyTargets = [];
629
+ const unavailableTargetResults = [];
630
+ const resolveGroup = async (targets) => {
631
+ const platforms = new Set(targets.map((target) => target.platform));
632
+ const platform = platforms.size === 2 ? 'both' : [...platforms][0];
633
+ let context;
158
634
  try {
159
- const result = await reinstall([selector], {
160
- cwd: options.cwd,
161
- platform: target.platform,
162
- scope: target.scope,
635
+ context = await createScopeContext({ scope: targets[0].scope, cwd: options.cwd, env: options.env });
636
+ const demand = await readDemand({ scope: targets[0].scope,
637
+ cwd: context.executionCwd, env: context.env });
638
+ const preview = await (options.reinstallCommandImpl ?? syncWriteCommand)([selector], {
639
+ cwd: context.executionCwd,
640
+ platform,
641
+ scope: targets[0].scope,
163
642
  }, {
164
643
  ...options.rebuildRuntime,
165
- env: options.env,
166
- nativeCliRunner,
644
+ env: context.env,
645
+ nativeCliRunner: options.nativeCliRunner,
646
+ previewOperationPlan: true,
647
+ resolvePreApplyAuthorization: true,
648
+ executionInput: {
649
+ context, requirements: demandNativeProjection(demand),
650
+ selectedTargets: targets.map((target) => ({ pluginId: selector,
651
+ platform: target.platform, scope: target.scope })),
652
+ preserveOtherObservedTargets: true,
653
+ },
167
654
  });
168
- if (result.overallState === 'failed')
169
- runtimeFailed = true;
170
- targetResults.push(...result.targetResults);
655
+ if (preview.overallState !== 'succeeded' || !preview.preApplyAuthorization)
656
+ return false;
657
+ authorization.push(...preview.preApplyAuthorization);
658
+ availableApplyTargets.push(...targets);
659
+ return true;
171
660
  }
172
- catch (error) {
173
- runtimeFailed = true;
174
- targetResults.push({
661
+ catch {
662
+ return false;
663
+ }
664
+ finally {
665
+ await context?.dispose();
666
+ }
667
+ };
668
+ for (const targets of groups.values()) {
669
+ if (await resolveGroup(targets))
670
+ continue;
671
+ for (const target of targets) {
672
+ if (targets.length > 1 && await resolveGroup([target]))
673
+ continue;
674
+ unavailableTargetResults.push({
175
675
  target,
176
676
  action: 'reinstall',
177
677
  state: 'failed',
178
- message: error instanceof Error ? error.message : String(error),
678
+ errorCode: 'sourceUnavailable',
679
+ message: 'The preApply authorization scope cannot be resolved for this target.',
179
680
  });
180
681
  }
181
682
  }
182
- const overallState = runtimeFailed || targetResults.some((entry) => entry.state === 'failed')
183
- ? 'failed' : 'succeeded';
184
683
  return {
185
- overallState,
186
- targetResults,
187
- ...(discovered.targets.length === 0 && discovered.failures.length === 0
188
- ? { applySkippedReason: 'noVisibleTarget' }
189
- : {}),
684
+ targets: [...new Map(authorization.map((target) => [[
685
+ target.pluginId,
686
+ target.platform,
687
+ target.scope,
688
+ ].join('\0'), target])).values()],
689
+ availableApplyTargets: dedupeTargets(availableApplyTargets),
690
+ unavailableTargetResults,
190
691
  };
191
692
  }
693
+ function pluginMayRunPreApply(plugin) {
694
+ return plugin.manifest.scripts?.preApply !== undefined
695
+ || (plugin.manifest.dependencies?.length ?? 0) > 0;
696
+ }
697
+ function throwPreApplyAuthorizationRequired(targets) {
698
+ const plugins = [...new Set(targets.map((target) => target.pluginId))].join(', ');
699
+ const error = new Error(`preApplyAuthorizationRequired: Applying this config runs plugin preApply for ${plugins}. Re-run with --yes.`);
700
+ error.code = 'preApplyAuthorizationRequired';
701
+ throw error;
702
+ }
703
+ function preApplyAuthorizationIsConfirmed(options) {
704
+ if (options.confirmed !== true)
705
+ return false;
706
+ if (options.authorizedTargets === undefined)
707
+ return true;
708
+ const authorized = new Set(options.authorizedTargets.map((target) => [
709
+ target.pluginId,
710
+ target.sourceIdentity,
711
+ target.platform,
712
+ target.scope,
713
+ ].join('\0')));
714
+ return options.required.every((target) => authorized.has([
715
+ target.pluginId,
716
+ target.sourceIdentity,
717
+ target.platform,
718
+ target.scope,
719
+ ].join('\0')));
720
+ }
192
721
  function otherProjectsWarning(scope) {
193
722
  return scope === 'user'
194
- ? ['其它项目不会由本次命令扫描或更新。请在每个项目目录中运行对应的 aw reinstall 命令。']
723
+ ? ['其它项目不会由本次命令扫描或更新,可能需要在对应项目目录中运行 aw plugin sync --context project。']
195
724
  : [];
196
725
  }
197
726
  function buildReceiptFieldEntry(options) {
@@ -202,326 +731,673 @@ function buildReceiptFieldEntry(options) {
202
731
  reserved: options.reserved,
203
732
  action: options.action,
204
733
  scope: options.scope,
205
- ...(options.scope === 'project' ? { projectLayer: options.projectLayer } : {}),
206
734
  ...(options.valueState ? { valueState: options.valueState } : {}),
207
735
  };
208
736
  }
209
737
  export async function replayConfigRuntimeWrites(options) {
738
+ if (!options.awHomeMutationToken) {
739
+ await prepareNativeCliExecution({ env: options.env, runner: options.nativeCliRunner });
740
+ }
210
741
  return withAwHomeMutationLock({
211
742
  env: options.env,
212
743
  token: options.awHomeMutationToken,
213
744
  action: async (awHomeMutationToken) => {
214
- const applied = await reinstallVisibleTargets({
745
+ const env = options.env ?? process.env;
746
+ const rebuildRuntime = { ...options.rebuildRuntime, awHomeMutationToken };
747
+ let discovered;
748
+ try {
749
+ discovered = await resolveConfigApplyTargets({
750
+ plugin: options.plugin,
751
+ scope: options.scope,
752
+ cwd: options.cwd,
753
+ env,
754
+ applyTargets: options.applyTargets,
755
+ nativeCliRunner: options.nativeCliRunner,
756
+ rebuildRuntime,
757
+ });
758
+ }
759
+ catch {
760
+ const apply = unavailableApply('targetDiscoveryFailed', 'targetDiscovery');
761
+ return {
762
+ configWrite: 'succeeded',
763
+ overallState: 'partial',
764
+ apply: publicConfigApplyResult(apply),
765
+ otherProjectsMayRequireSync: false,
766
+ };
767
+ }
768
+ const preApplyAuthorization = await resolveConfigPreApplyAuthorization({
769
+ plugin: options.plugin,
770
+ scope: options.scope,
771
+ cwd: options.cwd,
772
+ env,
773
+ applyTargets: discovered.targets,
774
+ nativeCliRunner: options.nativeCliRunner,
775
+ rebuildRuntime,
776
+ reinstallCommandImpl: options.reinstallCommandImpl,
777
+ });
778
+ if (preApplyAuthorization.targets.length > 0 && !preApplyAuthorizationIsConfirmed({
779
+ required: preApplyAuthorization.targets,
780
+ confirmed: options.preApplyConfirmed,
781
+ authorizedTargets: options.preApplyAuthorizedTargets,
782
+ })) {
783
+ const apply = {
784
+ state: 'partial',
785
+ targetResults: preApplyAuthorization.targets.map((target) => ({
786
+ target: {
787
+ pluginName: target.pluginName,
788
+ pluginId: target.pluginId,
789
+ platform: target.platform,
790
+ scope: target.scope,
791
+ },
792
+ action: 'reinstall',
793
+ state: 'failed',
794
+ errorCode: 'preApplyAuthorizationRequired',
795
+ message: 'Running plugin preApply requires explicit authorization.',
796
+ })),
797
+ };
798
+ return {
799
+ configWrite: 'succeeded',
800
+ overallState: 'partial',
801
+ apply: publicConfigApplyResult(apply),
802
+ otherProjectsMayRequireSync: false,
803
+ };
804
+ }
805
+ discovered = {
806
+ ...discovered,
807
+ targets: preApplyAuthorization.availableApplyTargets,
808
+ failures: [...discovered.failures, ...preApplyAuthorization.unavailableTargetResults],
809
+ };
810
+ if (discovered.targets.length === 0
811
+ && preApplyAuthorization.unavailableTargetResults.length > 0
812
+ && (discovered.commandPackages?.length ?? 0) === 0) {
813
+ const apply = unavailableApply('sourceUnavailable', 'source', preApplyAuthorization.unavailableTargetResults);
814
+ return {
815
+ configWrite: 'succeeded',
816
+ overallState: 'partial',
817
+ apply: publicConfigApplyResult(apply),
818
+ otherProjectsMayRequireSync: false,
819
+ };
820
+ }
821
+ if (options.scope === 'user'
822
+ && options.sharedNativeApplyConfirmed !== true
823
+ && await configApplyHasValidSharedNativeTarget({
824
+ plugin: options.plugin,
825
+ targets: discovered.targets,
826
+ cwd: options.cwd,
827
+ env,
828
+ plugins: rebuildRuntime.referencePlugins,
829
+ })) {
830
+ throwSharedNativeApplyConfirmationRequired();
831
+ }
832
+ const apply = await reinstallVisibleTargets({
215
833
  plugin: options.plugin,
216
834
  scope: options.scope,
217
835
  cwd: options.cwd,
218
- env: options.env ?? process.env,
836
+ env,
219
837
  applyTargets: options.applyTargets,
220
838
  nativeCliRunner: options.nativeCliRunner,
221
839
  reinstallCommandImpl: options.reinstallCommandImpl,
222
- rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken },
840
+ rebuildRuntime,
841
+ discovered,
842
+ preApplyConfirmed: options.preApplyConfirmed,
223
843
  });
224
844
  return {
225
845
  configWrite: 'succeeded',
226
- overallState: applied.overallState,
227
- targetResults: applied.targetResults,
228
- ...(applied.applySkippedReason ? { applySkippedReason: applied.applySkippedReason } : {}),
229
- otherProjectsRequireReinstall: options.scope === 'user',
846
+ overallState: overallStateForApply(apply),
847
+ apply: publicConfigApplyResult(apply),
848
+ otherProjectsMayRequireSync: false,
230
849
  };
231
850
  },
232
851
  });
233
852
  }
234
- async function applyPluginConfigWriteUnlocked(options) {
235
- const requestedPluginName = options.pluginName ?? options.plugin?.manifest.name;
236
- if (!requestedPluginName)
237
- throw new Error('Plugin name is required for config write.');
238
- const pluginName = assertSafePluginConfigSegment(requestedPluginName);
239
- const configIdentity = options.plugin?.sourceId ? {
240
- sourceId: options.plugin.sourceId,
241
- sourceIdentity: options.plugin.sourceIdentity,
242
- } : {};
243
- const projectLayer = options.scope === 'project' ? (options.projectLayer ?? 'shared') : 'shared';
244
- const requestedUpdates = options.request.updates ?? {};
245
- const requestedRemoveKeys = uniqueInOrder(options.request.removeKeys ?? []);
246
- const duplicateKeys = requestedRemoveKeys.filter((key) => Object.hasOwn(requestedUpdates, key));
247
- if (duplicateKeys.length > 0) {
248
- throw new Error(`Config write cannot update and remove the same key: ${duplicateKeys.join(', ')}.`);
853
+ function configApplyRequestedTargets(plan) {
854
+ return plan.receipt.requestedTargets.filter((target) => !plan.receipt.targetResults.some((result) => result.pluginId === target.pluginId && result.agent === target.agent && result.scope === target.scope
855
+ && (result.satisfaction === 'unsupported' || result.satisfaction === 'excluded')));
856
+ }
857
+ async function prepareConfigApplyPackages(options, plugins, plan, referencePlugins) {
858
+ const env = options.env ?? process.env;
859
+ const context = options.context ?? options.scope;
860
+ const discoveries = [];
861
+ const scopes = context === 'project' ? ['user', 'project'] : ['user'];
862
+ const nativeTargets = configApplyRequestedTargets(plan).flatMap((target) => target.agent === 'codex' || target.agent === 'claude'
863
+ ? [{ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId, platform: target.agent, scope: target.scope }] : []);
864
+ for (const plugin of plugins) {
865
+ for (const scope of scopes) {
866
+ discoveries.push(await discoverInstalledPluginManagedCommandPackages({ plugin, scope, cwd: options.cwd, env,
867
+ platformTargets: nativeTargets.filter((target) => target.pluginId === (plugin.pluginId ?? plugin.manifest.name)
868
+ && (scope === 'user' || target.scope === 'project')) }));
869
+ }
249
870
  }
250
- const schemaAccess = await resolvePluginConfigSchemaAccess({
251
- pluginName,
252
- currentPlugin: options.plugin,
253
- currentPluginError: options.pluginError,
254
- scope: options.scope,
255
- projectLayer,
871
+ const packages = [...new Map(discoveries.flatMap((discovery) => discovery.packages).filter((target) => {
872
+ if (options.applyCommandPackages && !options.applyCommandPackages.includes(target.packageId))
873
+ return false;
874
+ if (options.platform)
875
+ return false;
876
+ if (!options.targets)
877
+ return true;
878
+ const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
879
+ const declaration = plugin?.manifest.managedCommands?.packages.find((entry) => entry.key === target.packageKey && entry.scope === target.producer.scope);
880
+ return declaration?.platforms.some((platform) => options.targets.includes(platform)) ?? false;
881
+ }).map((target) => [target.packageId, target])).values()];
882
+ const inventory = await listManagedCommandPackages(env);
883
+ const entries = await Promise.all(packages.map(async (target) => {
884
+ const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
885
+ const installed = inventory.packages.find((entry) => entry.id === target.packageId);
886
+ let recordDigest;
887
+ let blocker;
888
+ if (!target.installed || !installed) {
889
+ blocker = { code: 'configApplyRequiresExistingOutput', message: 'Configuration apply requires an existing command package. Run package sync first.' };
890
+ }
891
+ else if (!target.declared) {
892
+ blocker = { code: 'commandPackageDeclarationMissing', message: 'The installed command package is no longer declared by this plugin.' };
893
+ }
894
+ else {
895
+ try {
896
+ const record = await readInstalledCommandProducer(installed.resourceRoot);
897
+ recordDigest = `sha256:${crypto.createHash('sha256').update(JSON.stringify(record)).digest('hex')}`;
898
+ await assertManagedCommandPackageNativeToolsUnchanged({ plugin, producer: target.producer, env });
899
+ }
900
+ catch (error) {
901
+ blocker = managedCommandDiagnostic(error);
902
+ }
903
+ }
904
+ return { target, recordDigest, blocker };
905
+ }));
906
+ const errors = [...new Map(discoveries.flatMap((discovery) => discovery.errors).map((error) => [JSON.stringify(error), error])).values()];
907
+ const evidence = { packages: entries, errors };
908
+ const targets = [...new Map(entries.map(({ target }) => {
909
+ const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
910
+ const pluginId = plugin.pluginId ?? plugin.manifest.name;
911
+ const dependencies = resolvePluginMetaDependencyClosure(referencePlugins, [plugin.manifest.name])
912
+ .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.pluginId ?? entry.manifest.name);
913
+ return [`${pluginId}\0${target.producer.scope}`, { pluginId, scope: target.producer.scope, dependencies }];
914
+ })).values()];
915
+ const cache = plan.runtime.managedCommandProducerCache ??= new Map();
916
+ const hook = { targets, evidence,
917
+ blocked: (pluginId, scope, code) => {
918
+ const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
919
+ return entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope)
920
+ .map(({ target }) => ({
921
+ producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
922
+ errors: [{ code, message: 'A required provider failed; the command package was not refreshed.' }],
923
+ recoveryActions: [`aw command package sync ${pluginId} ${target.packageKey} --scope ${scope} --yes`],
924
+ }));
925
+ },
926
+ execute: async (pluginId, scope, token) => {
927
+ const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
928
+ const selected = entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope);
929
+ const results = [];
930
+ let executionContext;
931
+ try {
932
+ executionContext = await createScopeContext({ scope, cwd: options.cwd, env });
933
+ for (const { target, blocker } of selected) {
934
+ if (blocker) {
935
+ const result = { producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
936
+ errors: [blocker], recoveryActions: [target.declared
937
+ ? `aw command package sync ${pluginId} ${target.packageKey} --scope ${scope} --yes`
938
+ : `aw command package remove ${target.packageId} --yes`] };
939
+ cache.set(target.packageId, Promise.resolve(result));
940
+ results.push(result);
941
+ continue;
942
+ }
943
+ const applied = await reinstallVisibleTargets({ plugin, scope, cwd: executionContext.executionCwd, env: executionContext.env,
944
+ changedConfigKeys: [...target.refreshKeys],
945
+ rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken: token, referencePlugins, managedCommandProducerCache: cache },
946
+ discovered: { targets: [], failures: [], commandPackages: [target], commandDiscoveryErrors: [] } });
947
+ results.push(...('commandResults' in applied ? applied.commandResults ?? [] : []));
948
+ }
949
+ return results;
950
+ }
951
+ finally {
952
+ await executionContext?.dispose();
953
+ }
954
+ } };
955
+ return { packages, evidence, errors, hook };
956
+ }
957
+ /** Prepare the same existing-output plan used by apply, without saving config or output. */
958
+ export async function preparePluginConfigApply(options) {
959
+ const { prepareRecovery, describeRecoveryPlan } = await import('../recovery/coordinator.js');
960
+ const context = options.context ?? options.scope;
961
+ const referencePlugins = await resolvePluginConfigReferencePlugins({ sourceId: options.plugin.sourceId,
962
+ sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity,
963
+ env: options.env, plugins: options.rebuildRuntime?.referencePlugins });
964
+ const plugins = await resolvePluginConfigReferenceConsumers({ plugin: options.plugin, env: options.env,
965
+ plugins: referencePlugins });
966
+ const selectors = plugins.map((plugin) => plugin.pluginId ?? plugin.manifest.name);
967
+ const version = options.cliVersion
968
+ ?? (await fs.readJson(path.join(resolveCliPackageRoot(), 'package.json'))).version;
969
+ let exactTargets = options.applyTargets?.map((target) => ({
970
+ pluginId: target.pluginId ?? plugins.find((plugin) => plugin.manifest.name === target.pluginName)?.pluginId ?? target.pluginName,
971
+ agent: target.platform,
972
+ scope: target.scope,
973
+ }));
974
+ const retainedLegacyTargets = [];
975
+ if (exactTargets?.some((target) => target.agent === 'codex' || target.agent === 'claude')) {
976
+ const { readRecoveryStatus } = await import('../recovery/status.js');
977
+ const observed = await readRecoveryStatus({ context, cwd: options.cwd, env: options.env, cliVersion: version,
978
+ nativeCliRunner: options.nativeCliRunner ?? options.rebuildRuntime?.nativeCliRunner,
979
+ codexObservationSession: options.rebuildRuntime?.codexObservationSession });
980
+ const key = (target) => `${target.pluginId}\0${target.agent}\0${target.scope}`;
981
+ const live = new Set(observed.existingTargets?.map(key));
982
+ const owned = new Set(observed.ownedTargets?.map(key));
983
+ exactTargets = exactTargets.filter((target, index) => {
984
+ if ((target.agent === 'codex' || target.agent === 'claude') && owned.has(key(target)) && !live.has(key(target))) {
985
+ retainedLegacyTargets.push(options.applyTargets[index]);
986
+ return false;
987
+ }
988
+ return true;
989
+ });
990
+ }
991
+ const plan = await prepareRecovery('sync', selectors, {
992
+ scope: context,
993
+ context,
256
994
  cwd: options.cwd,
257
995
  env: options.env,
996
+ cliVersion: version,
997
+ existingOnly: true,
998
+ ...(exactTargets ? { exactTargets } : {}),
999
+ ...(options.targets ? { targets: options.targets } : options.platform ? { targets: [options.platform] } : {}),
1000
+ }, {
1001
+ ...options.rebuildRuntime,
1002
+ referencePlugins,
1003
+ nativeCliRunner: options.nativeCliRunner,
1004
+ awHomeMutationToken: options.awHomeMutationToken,
1005
+ preApplyConfirmed: options.preApplyConfirmed,
258
1006
  });
259
- const schemaPlugin = schemaAccess.plugin;
260
- const schema = schemaPlugin?.manifest.config?.schema;
261
- if (!schema || !schemaPlugin) {
262
- throw new Error(`configSchemaUnavailable: Plugin "${pluginName}" does not declare an AW config schema.`);
1007
+ try {
1008
+ plan.warnings.push(...retainedLegacyTargets.map((target) => `${target.pluginId ?? target.pluginName}/${target.platform}/${target.scope}:保留已停用的历史输出;配置 apply 不创建激活。`));
1009
+ const commands = await prepareConfigApplyPackages(options, plugins, plan, referencePlugins);
1010
+ plan.runtime.configApplyPackages = commands.hook;
1011
+ const profiles = configApplyRequestedTargets(plan).map((target) => ({
1012
+ pluginName: target.pluginId.split('/').at(-1), scope: target.scope, platform: target.agent,
1013
+ }));
1014
+ // A package has platform=null and always consumes the public common profile.
1015
+ profiles.push(...commands.packages.map((target) => ({ pluginName: target.producer.pluginName,
1016
+ scope: target.producer.scope, platform: undefined })));
1017
+ const references = await collectPluginConfigReferenceEvidence({ plugin: options.plugin, plugins: referencePlugins,
1018
+ profiles, cwd: options.cwd, env: options.env });
1019
+ const authorization = await resolveConfigPreApplyAuthorization({
1020
+ plugin: options.plugin, scope: context, cwd: options.cwd, env: options.env,
1021
+ applyTargets: configApplyRequestedTargets(plan).flatMap((target) => target.agent === 'codex' || target.agent === 'claude'
1022
+ ? [{ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId, platform: target.agent, scope: target.scope }] : []),
1023
+ nativeCliRunner: options.nativeCliRunner,
1024
+ rebuildRuntime: { ...plan.runtime, referencePlugins },
1025
+ });
1026
+ const portableAuthorization = (current) => [
1027
+ ...current.preApplyAuthorization ?? [],
1028
+ ...(current.joint?.children ?? []).flatMap(portableAuthorization),
1029
+ ];
1030
+ const preApplyAuthorization = [...new Map([...authorization.targets, ...portableAuthorization(plan)]
1031
+ .map((target) => [[target.pluginId, target.platform, target.scope].join('\0'), target])).values()];
1032
+ return { plan, retainedLegacyTargets, commandPackages: commands.packages, commandDiscoveryErrors: commands.errors,
1033
+ preApplyAuthorization,
1034
+ evidence: { recovery: describeRecoveryPlan(plan), references, commands: commands.evidence,
1035
+ preApplyAuthorization, retainedLegacyTargets } };
263
1036
  }
264
- for (const key of requestedRemoveKeys) {
265
- if (!schema[key])
266
- throw new Error(`Unknown config key "${key}".`);
1037
+ catch (error) {
1038
+ await disposePluginConfigApply(plan);
1039
+ throw error;
267
1040
  }
268
- const updates = await coercePluginConfigUpdates({ schema, updates: requestedUpdates, cwd: options.cwd });
269
- if (options.scope === 'project' && projectLayer === 'shared') {
270
- for (const key of Object.keys(updates)) {
271
- const field = schema[key];
272
- if (field.type === 'file' || field.type === 'directory') {
273
- throw new Error(`Config "${key}" is a ${field.type} value and cannot be written into project shared config. `
274
- + 'Use `--scope project --local` or user config instead.');
1041
+ }
1042
+ export async function disposePluginConfigApply(plan) {
1043
+ for (const child of plan.joint?.children ?? [])
1044
+ await disposePluginConfigApply(child);
1045
+ await plan.context.dispose();
1046
+ }
1047
+ export async function applyPluginConfig(options) {
1048
+ return withAwHomeMutationLock({ env: options.env, token: options.awHomeMutationToken, action: async (token) => {
1049
+ await options.reviewPreflight?.();
1050
+ let prepared;
1051
+ try {
1052
+ const { executeRecovery } = await import('../recovery/coordinator.js');
1053
+ prepared = await preparePluginConfigApply({ ...options, awHomeMutationToken: token });
1054
+ if (options.expectedEvidence !== undefined
1055
+ && JSON.stringify(options.expectedEvidence) !== JSON.stringify(prepared.evidence)) {
1056
+ throw Object.assign(new Error('operationPlanStale: Configuration apply inputs changed. Prepare a new Review.'), { code: 'operationPlanStale' });
1057
+ }
1058
+ const authorization = prepared.preApplyAuthorization;
1059
+ if (authorization.length && !preApplyAuthorizationIsConfirmed({ required: authorization,
1060
+ confirmed: options.preApplyConfirmed, authorizedTargets: options.preApplyAuthorizedTargets })) {
1061
+ throwPreApplyAuthorizationRequired(authorization);
1062
+ }
1063
+ if (options.sharedNativeApplyConfirmed !== true && await configApplyHasValidSharedNativeTarget({
1064
+ plugin: options.plugin, cwd: options.cwd, env: options.env, plugins: options.rebuildRuntime?.referencePlugins,
1065
+ targets: configApplyRequestedTargets(prepared.plan).flatMap((target) => target.agent === 'codex' || target.agent === 'claude'
1066
+ ? [{ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId, platform: target.agent, scope: target.scope }] : []),
1067
+ }))
1068
+ throwSharedNativeApplyConfirmationRequired();
1069
+ const discoveryErrors = prepared.commandDiscoveryErrors.map((error) => ({
1070
+ stage: 'targetDiscovery', code: error.code, message: error.message,
1071
+ }));
1072
+ const receipt = await executeRecovery(prepared.plan, {
1073
+ yes: options.sharedNativeApplyConfirmed === true || options.preApplyConfirmed === true,
1074
+ runtime: { ...options.rebuildRuntime, awHomeMutationToken: token, preApplyConfirmed: options.preApplyConfirmed },
1075
+ });
1076
+ const retainedLegacyTargets = prepared.retainedLegacyTargets.filter((target) => !receipt.targetResults.some((result) => (target.pluginId ? result.pluginId === target.pluginId : result.pluginId.split('/').at(-1) === target.pluginName)
1077
+ && result.agent === target.platform && result.scope === target.scope));
1078
+ prepared = undefined;
1079
+ const ok = receipt.ok && discoveryErrors.length === 0;
1080
+ const errors = [...discoveryErrors, ...receipt.blockers, ...receipt.errors].map((error) => ({
1081
+ stage: 'stage' in error ? error.stage : 'apply', code: error.code, message: error.message,
1082
+ }));
1083
+ const apply = {
1084
+ state: ok ? 'succeeded' : 'partial',
1085
+ targetResults: [...receipt.targetResults.filter((target) => target.satisfaction !== 'unsupported' && target.satisfaction !== 'excluded').map((target) => ({
1086
+ target: { pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId,
1087
+ platform: target.agent, scope: target.scope },
1088
+ action: 'refresh',
1089
+ state: target.execution === 'applied' || target.execution === 'no-op' ? 'completed'
1090
+ : target.execution === 'not-run' ? 'skipped' : 'failed',
1091
+ ...(target.blockers.length ? { errorCode: target.blockers[0].code,
1092
+ message: target.blockers.map((item) => item.message).join(' ') } : {}),
1093
+ })), ...retainedLegacyTargets.map((target) => ({
1094
+ target, action: 'refresh', state: 'skipped',
1095
+ message: 'The inactive legacy output was preserved. Configuration apply does not create an activation.',
1096
+ }))],
1097
+ commandResults: receipt.commandResults,
1098
+ ...(errors.length ? { errors } : {}),
1099
+ };
1100
+ return { configWrite: 'notStarted', overallState: ok ? 'succeeded' : 'partial', apply,
1101
+ otherProjectsMayRequireSync: true };
275
1102
  }
1103
+ catch (error) {
1104
+ if (options.rebuildRuntime?.signal?.aborted || error instanceof Error && error.name === 'AbortError'
1105
+ || readSafeOperationError(error))
1106
+ throw error;
1107
+ const apply = unavailableApply('targetDiscoveryFailed', 'targetDiscovery');
1108
+ const code = error?.code;
1109
+ if (typeof code === 'string')
1110
+ apply.error = { stage: 'apply', code,
1111
+ message: code === 'operationPlanStale' ? 'Configuration apply inputs changed. Prepare a new Review.'
1112
+ : 'The existing outputs cannot be refreshed with the current authorization.' };
1113
+ return { configWrite: 'notStarted', overallState: 'partial', apply, otherProjectsMayRequireSync: true };
1114
+ }
1115
+ finally {
1116
+ if (prepared)
1117
+ await disposePluginConfigApply(prepared.plan);
1118
+ }
1119
+ } });
1120
+ }
1121
+ function throwSharedNativeApplyConfirmationRequired() {
1122
+ const error = new Error('sharedNativeConfigApplyConfirmationRequired: Applying this user config changes a shared native artifact. Re-run with --yes.');
1123
+ error.code = 'sharedNativeConfigApplyConfirmationRequired';
1124
+ throw error;
1125
+ }
1126
+ async function applyPluginConfigWriteUnlocked(options) {
1127
+ const pluginName = assertSafePluginConfigSegment(options.pluginName ?? options.plugin?.manifest.name ?? '');
1128
+ const identity = options.plugin?.sourceId ? { sourceId: options.plugin.sourceId,
1129
+ sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity } : {};
1130
+ const requestedUpdates = options.request.updates ?? {};
1131
+ const removeKeys = uniqueInOrder(options.request.removeKeys ?? []);
1132
+ const duplicateKeys = removeKeys.filter((key) => Object.hasOwn(requestedUpdates, key));
1133
+ if (duplicateKeys.length)
1134
+ throw new Error(`Config write cannot update and remove the same key: ${duplicateKeys.join(', ')}.`);
1135
+ const schemaAccess = await resolvePluginConfigSchemaAccess({ pluginName, currentPlugin: options.plugin,
1136
+ currentPluginError: options.pluginError, scope: options.scope, platform: options.platform, cwd: options.cwd, env: options.env });
1137
+ const plugin = schemaAccess.plugin;
1138
+ const definition = plugin?.manifest.config ? selectPluginConfigProfile(plugin.manifest.config, options.platform) : undefined;
1139
+ if (!plugin || !definition)
1140
+ throw new PluginConfigSchemaResolutionError('configSchemaUnavailable', `Plugin "${pluginName}" does not declare an AW config schema.`);
1141
+ const updates = await coercePluginConfigUpdates({ schema: definition.fields, updates: requestedUpdates, cwd: options.cwd });
1142
+ const impact = await analyzePluginConfigMutationImpact({ plugin, scope: options.scope, platform: options.platform,
1143
+ cwd: options.cwd, env: options.env, visibleTargets: [], commandDiscovery: { packages: [], errors: [] },
1144
+ referencePlugins: options.rebuildRuntime?.referencePlugins, mutation: { kind: 'patch', updates, removeKeys } });
1145
+ await assertPluginConfigMutationCandidate({ ...identity, pluginName, manifest: plugin.manifest,
1146
+ scope: options.scope, platform: options.platform, cwd: options.cwd, env: options.env, updates, removeKeys,
1147
+ referencePlugins: options.rebuildRuntime?.referencePlugins });
1148
+ if (impact.referenceBlockers?.length)
1149
+ throw Object.assign(new Error(`configReferenceInUse: ${impact.referenceBlockers.join(' ')}`), { code: 'configReferenceInUse' });
1150
+ if (impact.storeChanged) {
1151
+ try {
1152
+ await patchPluginConfigStore({ ...identity, pluginName, scope: 'user', platform: options.platform,
1153
+ cwd: options.cwd, env: options.env, updates: Object.fromEntries(impact.updatedKeys.map((key) => [key, updates[key]])), removeKeys });
1154
+ }
1155
+ catch (error) {
1156
+ throw markConfigWriteFailed(error);
276
1157
  }
277
1158
  }
278
- const store = await readPluginConfigStore({
279
- ...configIdentity,
280
- pluginName,
281
- scope: options.scope,
282
- projectLayer,
283
- cwd: options.cwd,
284
- env: options.env,
285
- });
286
- const warnings = [];
287
- if (options.scope === 'project' && projectLayer === 'shared') {
288
- await assertProjectSharedConfigPathVisible({ cwd: options.cwd, targetPath: store.path });
1159
+ const warnings = [...impact.referenceWarnings ?? []];
1160
+ let effective;
1161
+ try {
1162
+ effective = summarizeEffectivePluginConfig(await resolveEffectivePluginConfig({ ...identity, pluginName,
1163
+ manifest: plugin.manifest, platform: options.platform, targetScope: options.scope, cwd: options.cwd, env: options.env,
1164
+ referencePlugins: options.rebuildRuntime?.referencePlugins }));
289
1165
  }
290
- if (options.scope === 'project' && projectLayer === 'local') {
291
- const ignore = await ensureProjectPrivateStateIgnore({ cwd: options.cwd, targetPath: store.path });
292
- if (ignore.warning)
293
- warnings.push(ignore.warning);
1166
+ catch {
1167
+ warnings.push('The saved configuration cannot be previewed. Check its schema and reference sources before applying it.');
294
1168
  }
295
- const removedKeys = requestedRemoveKeys.filter((key) => Object.hasOwn(store.values, key));
296
- const updatedKeys = Object.keys(updates);
297
- const changedKeys = [...updatedKeys, ...removedKeys];
298
- if (options.scope === 'project' && projectLayer === 'shared' && changedKeys.length > 0) {
299
- const nextValues = { ...store.values, ...updates };
300
- for (const key of requestedRemoveKeys)
301
- delete nextValues[key];
302
- const boundaryIssues = collectProjectArtifactConfigBoundaryIssues({
303
- schema,
304
- sharedEntries: nextValues,
305
- });
306
- if (boundaryIssues.length > 0) {
307
- throw new Error([...new Set(boundaryIssues.map((issue) => issue.message))].join(' '));
1169
+ if (impact.storeChanged)
1170
+ warnings.push(...otherProjectsWarning('user'));
1171
+ return { plugin: pluginName, scope: 'user', context: options.scope, platform: options.platform,
1172
+ ...(schemaAccess.schema ? { schema: schemaAccess.schema } : {}), updatedKeys: impact.updatedKeys,
1173
+ removedKeys: impact.removedKeys, staleRemovedKeys: impact.staleRemovedKeys, effective,
1174
+ configWrite: 'succeeded', overallState: 'succeeded',
1175
+ apply: skippedApply(impact.storeChanged ? 'notRequested' : 'noConfigChange'),
1176
+ otherProjectsMayRequireSync: impact.storeChanged, warnings };
1177
+ }
1178
+ async function prepareConfigMutationApplySelection(options) {
1179
+ if (options.apply !== true || !options.plugin)
1180
+ return undefined;
1181
+ let prepared;
1182
+ try {
1183
+ prepared = await preparePluginConfigApply({ ...options, plugin: options.plugin });
1184
+ const requestedTargets = configApplyRequestedTargets(prepared.plan);
1185
+ if (requestedTargets.some((target) => target.agent !== 'codex' && target.agent !== 'claude'))
1186
+ return undefined;
1187
+ const visibleTargets = requestedTargets.map((target) => ({
1188
+ pluginName: target.pluginId.split('/').at(-1), pluginId: target.pluginId,
1189
+ platform: target.agent, scope: target.scope,
1190
+ }));
1191
+ if (!visibleTargets.length && !prepared.commandPackages.length && !prepared.commandDiscoveryErrors.length) {
1192
+ if (prepared.plan.blockExecution || prepared.plan.receipt.blockers.length || prepared.plan.receipt.errors.length)
1193
+ return undefined;
1194
+ return { skipReason: 'noVisibleTarget' };
308
1195
  }
1196
+ const impact = await analyzePluginConfigMutationImpact({ plugin: options.plugin, scope: options.context ?? options.scope,
1197
+ platform: options.platform, cwd: options.cwd, env: options.env, visibleTargets,
1198
+ commandDiscovery: { packages: prepared.commandPackages, errors: prepared.commandDiscoveryErrors },
1199
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
1200
+ mutation: 'request' in options ? { kind: 'patch', ...options.request } : { kind: 'reset' } });
1201
+ return { applyTargets: impact.affectedTargets,
1202
+ applyCommandPackages: impact.affectedCommandPackages.map((target) => target.packageId),
1203
+ ...(impact.noEffectiveChange ? { skipReason: 'noEffectiveConfigChange' } : {}) };
309
1204
  }
310
- if (changedKeys.length > 0) {
311
- await patchPluginConfigStore({
312
- ...configIdentity,
313
- pluginName,
314
- scope: options.scope,
315
- projectLayer,
316
- cwd: options.cwd,
317
- env: options.env,
318
- updates,
319
- removeKeys: requestedRemoveKeys,
320
- });
1205
+ catch {
1206
+ // A failed output discovery must not prevent a valid configuration save.
1207
+ return undefined;
1208
+ }
1209
+ finally {
1210
+ if (prepared)
1211
+ await disposePluginConfigApply(prepared.plan);
321
1212
  }
322
- const effective = summarizeEffectivePluginConfig(await resolveEffectivePluginConfig({
323
- ...configIdentity,
324
- pluginName,
325
- manifest: schemaPlugin.manifest,
326
- cwd: options.cwd,
327
- env: options.env,
328
- }));
329
- const applied = changedKeys.length === 0
330
- ? {
331
- overallState: 'succeeded',
332
- targetResults: [],
333
- applySkippedReason: 'noConfigChange',
334
- }
335
- : await reinstallVisibleTargets({
336
- plugin: schemaPlugin,
337
- scope: options.scope,
338
- cwd: options.cwd,
339
- env: options.env ?? process.env,
340
- applyTargets: options.applyTargets,
341
- nativeCliRunner: options.nativeCliRunner,
342
- reinstallCommandImpl: options.reinstallCommandImpl,
343
- rebuildRuntime: options.rebuildRuntime,
344
- });
345
- const otherProjectsRequireReinstall = options.scope === 'user'
346
- && changedKeys.length > 0;
347
- if (otherProjectsRequireReinstall)
348
- warnings.push(...otherProjectsWarning(options.scope));
349
- return {
350
- plugin: pluginName,
351
- scope: options.scope,
352
- projectLayer,
353
- ...(schemaAccess.schema ? { schema: schemaAccess.schema } : {}),
354
- updatedKeys,
355
- removedKeys,
356
- effective,
357
- configWrite: 'succeeded',
358
- overallState: applied.overallState,
359
- targetResults: applied.targetResults,
360
- ...(applied.applySkippedReason ? { applySkippedReason: applied.applySkippedReason } : {}),
361
- otherProjectsRequireReinstall,
362
- warnings,
363
- };
364
1213
  }
365
1214
  export async function applyPluginConfigWrite(options) {
1215
+ if (options.context)
1216
+ await resolveWorkContext({ cwd: options.cwd, context: options.context });
366
1217
  const requestedPluginName = options.pluginName ?? options.plugin?.manifest.name;
367
1218
  if (!requestedPluginName)
368
1219
  throw new Error('Plugin name is required for config write.');
369
- const pluginName = assertSafePluginConfigSegment(requestedPluginName);
1220
+ assertSafePluginConfigSegment(requestedPluginName);
370
1221
  return withAwHomeMutationLock({
371
1222
  env: options.env,
372
1223
  token: options.awHomeMutationToken,
373
- action: (awHomeMutationToken) => withPluginConfigTransactionLease({
374
- ...(options.plugin?.sourceId ? { sourceId: options.plugin.sourceId } : {}),
375
- pluginName,
376
- scope: options.scope,
377
- projectLayer: options.scope === 'project' ? (options.projectLayer ?? 'shared') : 'shared',
378
- cwd: options.cwd,
379
- env: options.env,
380
- action: async () => {
381
- await options.reviewPreflight?.();
382
- return applyPluginConfigWriteUnlocked({
383
- ...options,
384
- awHomeMutationToken,
385
- rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken },
386
- });
387
- },
388
- }),
1224
+ action: async (awHomeMutationToken) => {
1225
+ await options.reviewPreflight?.();
1226
+ let configCommitted = false;
1227
+ try {
1228
+ const selection = await prepareConfigMutationApplySelection({ ...options, awHomeMutationToken });
1229
+ const saved = await applyPluginConfigWriteUnlocked({ ...options, scope: options.context ?? options.scope,
1230
+ apply: false, awHomeMutationToken, rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken } });
1231
+ configCommitted = true;
1232
+ if (options.apply !== true || !options.plugin)
1233
+ return saved;
1234
+ if (saved.apply.state === 'skipped' && saved.apply.reason === 'noConfigChange')
1235
+ return saved;
1236
+ if (selection?.skipReason)
1237
+ return { ...saved, apply: skippedApply(selection.skipReason) };
1238
+ const applied = await applyPluginConfig({ ...options, ...selection, plugin: options.plugin, awHomeMutationToken });
1239
+ return { ...saved, overallState: applied.overallState, apply: applied.apply };
1240
+ }
1241
+ catch (error) {
1242
+ let sensitiveValues = options.plugin
1243
+ ? collectSensitivePluginConfigValues(options.plugin.manifest, (options.request.updates ?? {}), options.platform)
1244
+ : [];
1245
+ if (options.plugin) {
1246
+ try {
1247
+ const effective = await resolveEffectivePluginConfig({
1248
+ ...(options.plugin.sourceId ? {
1249
+ sourceId: options.plugin.sourceId,
1250
+ sourceIdentity: options.plugin.sourceIdentity,
1251
+ logicalIdentity: options.plugin.catalogLogicalIdentity,
1252
+ } : {}),
1253
+ pluginName: options.plugin.manifest.name,
1254
+ manifest: options.plugin.manifest,
1255
+ referencePlugins: options.rebuildRuntime?.referencePlugins,
1256
+ targetScope: options.scope,
1257
+ platform: options.platform,
1258
+ cwd: options.cwd,
1259
+ env: options.env,
1260
+ });
1261
+ sensitiveValues = [
1262
+ ...sensitiveValues,
1263
+ ...collectSensitivePluginConfigValues(options.plugin.manifest, effective.values, options.platform),
1264
+ ];
1265
+ }
1266
+ catch {
1267
+ // Requested sensitive values and generic credential redaction remain available.
1268
+ }
1269
+ }
1270
+ let message = redactPluginScriptOutput(error instanceof Error ? error.message : String(error), sensitiveValues);
1271
+ message = message.split(options.cwd).join('<project>');
1272
+ for (const scope of ['user', 'project']) {
1273
+ const configPath = resolvePluginConfigStorePath({
1274
+ sourceId: options.plugin?.sourceId,
1275
+ pluginName: requestedPluginName,
1276
+ scope,
1277
+ cwd: options.cwd,
1278
+ env: options.env,
1279
+ });
1280
+ message = message.split(configPath).join(`${scope}/plugin-config/${[
1281
+ options.plugin?.sourceId,
1282
+ requestedPluginName,
1283
+ 'config.json',
1284
+ ].filter(Boolean).join('/')}`);
1285
+ }
1286
+ const safeError = new Error(message);
1287
+ const code = error.code;
1288
+ safeError.code = typeof code === 'string' ? code
1289
+ : message.startsWith('schemaVersionUnsupported:') ? 'schemaVersionUnsupported'
1290
+ : 'configApplyFailed';
1291
+ const configWrite = error.configWrite;
1292
+ if (configCommitted || configWrite === 'succeeded' || configWriteStateForError(error) === 'failed') {
1293
+ safeError.configWrite = configCommitted || configWrite === 'succeeded' ? 'succeeded' : 'failed';
1294
+ }
1295
+ if (error && typeof error === 'object' && 'operationDiagnostic' in error) {
1296
+ safeError.operationDiagnostic = error.operationDiagnostic;
1297
+ }
1298
+ throw safeError;
1299
+ }
1300
+ },
389
1301
  });
390
1302
  }
391
1303
  async function resetPluginConfigWithHelperUnlocked(options) {
392
1304
  const pluginName = assertSafePluginConfigSegment(options.pluginName);
393
- const projectLayer = options.scope === 'project' ? (options.projectLayer ?? 'shared') : 'shared';
394
- if (!options.plugin) {
395
- throw new Error(`sourceMissing: Plugin "${pluginName}" is unavailable; config reset was not applied.`);
1305
+ let identity = options.plugin?.sourceId ? { sourceId: options.plugin.sourceId,
1306
+ sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity }
1307
+ : { sourceId: options.sourceId, sourceIdentity: options.sourceIdentity, logicalIdentity: options.logicalIdentity };
1308
+ if (identity.sourceId && !identity.sourceIdentity) {
1309
+ try {
1310
+ const stored = await readNamespacedPluginConfigStoreIdentity({ sourceId: identity.sourceId, pluginName,
1311
+ scope: 'user', platform: options.platform, cwd: options.cwd, env: options.env });
1312
+ if (stored)
1313
+ identity = { ...identity, sourceIdentity: stored.binding.sourceIdentity };
1314
+ }
1315
+ catch { /* Reset remains available for unreadable identity metadata. */ }
396
1316
  }
397
- const schemaAccess = await resolvePluginConfigSchemaAccess({
398
- pluginName,
399
- currentPlugin: options.plugin,
400
- scope: options.scope,
401
- projectLayer,
402
- cwd: options.cwd,
403
- env: options.env,
404
- });
405
- if (!schemaAccess.plugin?.manifest.config?.schema) {
406
- throw new Error(`configSchemaUnavailable: Plugin "${pluginName}" does not declare an AW config schema.`);
1317
+ let removedKeys = [];
1318
+ try {
1319
+ const store = await readPluginConfigStore({ ...identity, pluginName, scope: 'user', platform: options.platform,
1320
+ cwd: options.cwd, env: options.env });
1321
+ removedKeys = collectRemovedConfigKeys(store.values);
407
1322
  }
408
- const configIdentity = options.plugin.sourceId ? {
409
- sourceId: options.plugin.sourceId,
410
- sourceIdentity: options.plugin.sourceIdentity,
411
- } : {};
412
- const store = await readPluginConfigStore({
413
- ...configIdentity,
414
- pluginName,
415
- scope: options.scope,
416
- projectLayer,
417
- cwd: options.cwd,
418
- env: options.env,
419
- });
420
- const removedKeys = collectRemovedConfigKeys(store.values);
1323
+ catch { /* Broken stores still have the path-based reset boundary. */ }
421
1324
  const warnings = [];
422
- if (options.scope === 'project' && projectLayer === 'shared' && store.exists) {
423
- await assertProjectSharedConfigPathVisible({ cwd: options.cwd, targetPath: store.path });
1325
+ if (options.plugin) {
1326
+ try {
1327
+ const impact = await analyzePluginConfigMutationImpact({ plugin: options.plugin, scope: options.scope,
1328
+ platform: options.platform, cwd: options.cwd, env: options.env, visibleTargets: [],
1329
+ commandDiscovery: { packages: [], errors: [] }, referencePlugins: options.rebuildRuntime?.referencePlugins,
1330
+ mutation: { kind: 'reset' } });
1331
+ warnings.push(...impact.referenceWarnings ?? [], ...impact.referenceBlockers ?? []);
1332
+ }
1333
+ catch {
1334
+ warnings.push('Configuration references could not be checked. Reset will still clear the selected layer.');
1335
+ }
424
1336
  }
425
- if (options.scope === 'project' && projectLayer === 'local') {
426
- const ignore = await ensureProjectPrivateStateIgnore({ cwd: options.cwd, targetPath: store.path });
427
- if (ignore.warning)
428
- warnings.push(ignore.warning);
1337
+ let reset;
1338
+ try {
1339
+ reset = await resetPluginConfigStore({ ...identity, pluginName, scope: 'user', platform: options.platform,
1340
+ cwd: options.cwd, env: options.env });
1341
+ }
1342
+ catch (error) {
1343
+ throw markConfigWriteFailed(error);
429
1344
  }
430
- const reset = await resetPluginConfigStore({
431
- ...configIdentity,
432
- pluginName,
433
- scope: options.scope,
434
- projectLayer,
435
- cwd: options.cwd,
436
- env: options.env,
437
- });
438
- let applied = {
439
- overallState: 'succeeded',
440
- targetResults: [],
441
- applySkippedReason: 'noConfigChange',
442
- };
443
1345
  let effective;
444
- if (schemaAccess.plugin) {
445
- if (schemaAccess.plugin.manifest.config?.schema) {
446
- effective = summarizeEffectivePluginConfig(await resolveEffectivePluginConfig({
447
- ...configIdentity,
448
- pluginName,
449
- manifest: schemaAccess.plugin.manifest,
450
- cwd: options.cwd,
451
- env: options.env,
452
- }));
1346
+ let schema;
1347
+ if (options.plugin) {
1348
+ try {
1349
+ schema = (await resolvePluginConfigSchemaAccess({ pluginName, currentPlugin: options.plugin,
1350
+ scope: options.scope, platform: options.platform, cwd: options.cwd, env: options.env })).schema;
1351
+ effective = summarizeEffectivePluginConfig(await resolveEffectivePluginConfig({ ...identity, pluginName,
1352
+ manifest: options.plugin.manifest, platform: options.platform, targetScope: options.scope, cwd: options.cwd,
1353
+ env: options.env, referencePlugins: options.rebuildRuntime?.referencePlugins }));
453
1354
  }
454
- if (reset.deleted) {
455
- applied = await reinstallVisibleTargets({
456
- plugin: schemaAccess.plugin,
457
- scope: options.scope,
458
- cwd: options.cwd,
459
- env: options.env ?? process.env,
460
- applyTargets: options.applyTargets,
461
- nativeCliRunner: options.nativeCliRunner,
462
- reinstallCommandImpl: options.reinstallCommandImpl,
463
- rebuildRuntime: options.rebuildRuntime,
464
- });
1355
+ catch {
1356
+ warnings.push('The cleared configuration cannot be previewed. Check its schema and references before applying it.');
465
1357
  }
466
1358
  }
467
- const otherProjectsRequireReinstall = Boolean(schemaAccess.plugin)
468
- && options.scope === 'user'
469
- && reset.deleted;
470
- if (otherProjectsRequireReinstall)
471
- warnings.push(...otherProjectsWarning(options.scope));
472
- return {
473
- plugin: pluginName,
474
- scope: options.scope,
475
- projectLayer,
476
- ...(schemaAccess.schema ? { schema: schemaAccess.schema } : {}),
477
- existed: reset.existed,
478
- deleted: reset.deleted,
479
- removedKeys,
480
- ...(effective ? { effective } : {}),
481
- configWrite: 'succeeded',
482
- overallState: applied.overallState,
483
- targetResults: applied.targetResults,
484
- ...(applied.applySkippedReason ? { applySkippedReason: applied.applySkippedReason } : {}),
485
- otherProjectsRequireReinstall,
486
- warnings,
487
- };
1359
+ if (reset.existed)
1360
+ warnings.push(...otherProjectsWarning('user'));
1361
+ return { plugin: pluginName, scope: 'user', context: options.scope, platform: options.platform, schema,
1362
+ existed: reset.existed, deleted: reset.deleted, resetDisposition: reset.resetDisposition,
1363
+ ...(reset.quarantineBasename ? { quarantineBasename: reset.quarantineBasename } : {}), removedKeys, effective,
1364
+ configWrite: 'succeeded', overallState: 'succeeded', apply: skippedApply(reset.existed ? 'notRequested' : 'noConfigChange'),
1365
+ otherProjectsMayRequireSync: reset.existed, warnings };
488
1366
  }
489
1367
  export async function resetPluginConfigWithHelper(options) {
490
- const pluginName = assertSafePluginConfigSegment(options.pluginName);
491
- if (!options.plugin) {
492
- throw new Error(`sourceMissing: Plugin "${pluginName}" is unavailable; config reset was not applied.`);
493
- }
494
- const sourceId = options.plugin.sourceId;
1368
+ if (options.context)
1369
+ await resolveWorkContext({ cwd: options.cwd, context: options.context });
1370
+ assertSafePluginConfigSegment(options.pluginName);
495
1371
  return withAwHomeMutationLock({
496
1372
  env: options.env,
497
1373
  token: options.awHomeMutationToken,
498
- action: (awHomeMutationToken) => withPluginConfigTransactionLease({
499
- ...(sourceId ? { sourceId } : {}),
500
- pluginName,
501
- scope: options.scope,
502
- projectLayer: options.scope === 'project' ? (options.projectLayer ?? 'shared') : 'shared',
503
- cwd: options.cwd,
504
- env: options.env,
505
- action: async () => {
506
- await options.reviewPreflight?.();
507
- return resetPluginConfigWithHelperUnlocked({
508
- ...options,
509
- awHomeMutationToken,
510
- rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken },
511
- });
512
- },
513
- }),
1374
+ action: async (awHomeMutationToken) => {
1375
+ await options.reviewPreflight?.();
1376
+ const selection = await prepareConfigMutationApplySelection({ ...options, awHomeMutationToken });
1377
+ const saved = await resetPluginConfigWithHelperUnlocked({ ...options, scope: options.context ?? options.scope,
1378
+ apply: false, awHomeMutationToken, rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken } });
1379
+ if (options.apply !== true)
1380
+ return saved;
1381
+ if (!options.plugin)
1382
+ return { ...saved, overallState: 'partial', apply: unavailableApply('sourceUnavailable', 'source') };
1383
+ if (saved.apply.state === 'skipped' && saved.apply.reason === 'noConfigChange')
1384
+ return saved;
1385
+ if (selection?.skipReason)
1386
+ return { ...saved, apply: skippedApply(selection.skipReason) };
1387
+ const applied = await applyPluginConfig({ ...options, ...selection, plugin: options.plugin, awHomeMutationToken });
1388
+ return { ...saved, overallState: applied.overallState, apply: applied.apply };
1389
+ },
514
1390
  });
515
1391
  }
516
1392
  export async function describeResetAffectedFields(options) {
517
- const projectLayer = options.scope === 'project' ? (options.projectLayer ?? 'shared') : 'shared';
518
1393
  try {
519
1394
  const resolved = await resolveConfigRead({
520
1395
  pluginName: options.pluginName,
521
1396
  plugin: options.plugin,
522
1397
  ...(options.pluginError ? { pluginError: options.pluginError } : {}),
523
1398
  scope: options.scope,
524
- projectLayer,
1399
+ context: options.context,
1400
+ platform: options.platform,
525
1401
  cwd: options.cwd,
526
1402
  env: options.env,
527
1403
  });
@@ -531,8 +1407,8 @@ export async function describeResetAffectedFields(options) {
531
1407
  kind: field.kind,
532
1408
  reserved: field.reserved,
533
1409
  action: 'reset',
534
- scope: options.scope,
535
- projectLayer,
1410
+ scope: 'user',
1411
+ platform: options.platform,
536
1412
  valueState: field.valueState,
537
1413
  }));
538
1414
  }
@@ -541,13 +1417,15 @@ export async function describeResetAffectedFields(options) {
541
1417
  ...(options.plugin?.sourceId ? {
542
1418
  sourceId: options.plugin.sourceId,
543
1419
  sourceIdentity: options.plugin.sourceIdentity,
1420
+ logicalIdentity: options.plugin.catalogLogicalIdentity,
544
1421
  } : options.sourceId ? {
545
1422
  sourceId: options.sourceId,
546
1423
  sourceIdentity: options.sourceIdentity,
1424
+ logicalIdentity: options.logicalIdentity,
547
1425
  } : {}),
548
1426
  pluginName: options.pluginName,
549
- scope: options.scope,
550
- projectLayer,
1427
+ scope: 'user',
1428
+ platform: options.platform,
551
1429
  cwd: options.cwd,
552
1430
  env: options.env,
553
1431
  });
@@ -557,8 +1435,8 @@ export async function describeResetAffectedFields(options) {
557
1435
  kind: 'manifest',
558
1436
  reserved: false,
559
1437
  action: 'reset',
560
- scope: options.scope,
561
- projectLayer,
1438
+ scope: 'user',
1439
+ platform: options.platform,
562
1440
  }));
563
1441
  }
564
1442
  }