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

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 +27 -0
  123. package/dist/src/commands/public-lifecycle.js +479 -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 +1880 -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 +149 -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 +144 -0
  230. package/dist/src/recovery/coordinator.js +1201 -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 +25 -0
  236. package/dist/src/recovery/joint-coordinator.js +931 -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 +109 -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 +9788 -1952
  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 +2224 -471
  330. package/dist/src/tui/controller-runtime.js.map +1 -1
  331. package/dist/src/tui/controller.d.ts +698 -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,20 +1,47 @@
1
1
  import crypto from 'node:crypto';
2
- import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { resolveWorkContext } from '../intent/work-context.js';
3
3
  import * as nodeFs from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import fs from 'fs-extra';
6
- import { assertTestReadablePath, assertTestWritablePath, } from './test-path-fence.js';
7
- import { markActiveMarketplaceDurableCommit, withActiveMarketplaceRuntimeLease, } from './active-marketplace-runtime-lock.js';
6
+ import { canonicalizePluginConfigValues, selectPluginConfigProfile, PLATFORM_TARGETS, formatPluginConfigIssue, getPluginConfigDependencyKeys, getPluginConfigDependencyFields, matchPluginConfigPreset, redactPluginConfigValue, stablePluginConfigStringify, validatePluginConfigCandidate, validatePluginConfigDocument, validatePluginConfigValue as validateCorePluginConfigValue, } from '@lesliechan721/aw-plugin-core/manifest';
8
7
  import { canonicalizePathThroughExistingAncestor, resolveAwHome, resolveRepoRootSync, } from './paths.js';
9
- import { acquireProcessLock } from './process-lock.js';
10
- const configCommitStorage = new AsyncLocalStorage();
11
- function markConfigDurableCommit() {
12
- let context = configCommitStorage.getStore();
13
- while (context) {
14
- context.durableCommit = true;
15
- context = context.parent;
8
+ import { assertRealFileParentWithinRoot, assertSafeFileMutationPath, atomicReplaceSafeFile, } from './safe-fs.js';
9
+ import { pluginConfigHasExternalReferences, resolvePluginConfigReferenceContext, } from './plugin-config-references.js';
10
+ export { resolvePluginConfigReferenceContext } from './plugin-config-references.js';
11
+ export function codexNativeRefreshKeys(manifest) {
12
+ return new Set((manifest.artifacts?.targets ?? []).flatMap((target) => target.platform === 'codex'
13
+ && target.target === 'codex.skill'
14
+ ? target.refreshKeys
15
+ : []));
16
+ }
17
+ function readPluginConfigBinding(value) {
18
+ return isRecord(value) && value.kind === 'source'
19
+ && typeof value.sourceIdentity === 'string'
20
+ && /^sha256:[0-9a-f]{64}$/u.test(value.sourceIdentity)
21
+ && Object.keys(value).every((key) => ['kind', 'sourceIdentity'].includes(key))
22
+ ? { kind: 'source', sourceIdentity: value.sourceIdentity } : null;
23
+ }
24
+ function readPluginConfigEnvelopeV6(value, _scope) {
25
+ if (!isRecord(value) || value.schemaVersion !== 6
26
+ || typeof value.sourceId !== 'string' || typeof value.pluginName !== 'string'
27
+ || !isRecord(value.common) || !isRecord(value.platforms)
28
+ || Object.keys(value).some((key) => !['schemaVersion', 'sourceId', 'pluginName', 'binding', 'common', 'platforms'].includes(key))
29
+ || Object.keys(value.platforms).some((key) => !PLATFORM_TARGETS.includes(key)))
30
+ return null;
31
+ const binding = readPluginConfigBinding(value.binding);
32
+ return binding ? { schemaVersion: 6, sourceId: value.sourceId, pluginName: value.pluginName,
33
+ binding, common: value.common,
34
+ platforms: value.platforms } : null;
35
+ }
36
+ export class PluginConfigResetError extends Error {
37
+ code;
38
+ osCode;
39
+ constructor(code, message, osCode) {
40
+ super(`${code}: ${message}`);
41
+ this.name = 'PluginConfigResetError';
42
+ this.code = code;
43
+ this.osCode = osCode;
16
44
  }
17
- markActiveMarketplaceDurableCommit();
18
45
  }
19
46
  export class PluginConfigSchemaResolutionError extends Error {
20
47
  code;
@@ -40,16 +67,12 @@ const CONFIG_DIR = 'plugin-config';
40
67
  const CONFIG_FILE = 'config.json';
41
68
  let atomicConfigBeforeRenameHookForTests;
42
69
  let atomicConfigAfterRenameHookForTests;
43
- let configFileLockBeforeReleaseHookForTests;
44
70
  export function setAtomicConfigBeforeRenameHookForTests(hook) {
45
71
  atomicConfigBeforeRenameHookForTests = hook;
46
72
  }
47
73
  export function setAtomicConfigAfterRenameHookForTests(hook) {
48
74
  atomicConfigAfterRenameHookForTests = hook;
49
75
  }
50
- export function setConfigFileLockBeforeReleaseHookForTests(hook) {
51
- configFileLockBeforeReleaseHookForTests = hook;
52
- }
53
76
  function assertConfigPathBoundary(allowedRoot, candidatePath) {
54
77
  const root = path.resolve(allowedRoot);
55
78
  const candidate = path.resolve(candidatePath);
@@ -113,179 +136,40 @@ async function inspectConfigInventoryStoreRoot(boundaryRoot, storeRoot) {
113
136
  }
114
137
  return true;
115
138
  }
116
- async function readConfigDirectoryIdentity(directoryPath) {
117
- const stats = await fs.lstat(directoryPath);
118
- if (stats.isSymbolicLink() || !stats.isDirectory()) {
119
- throw new Error(`Config parent must be a real directory: ${directoryPath}`);
120
- }
121
- return {
122
- dev: stats.dev,
123
- ino: stats.ino,
124
- realPath: await fs.realpath(directoryPath),
125
- };
126
- }
127
- function assertConfigDirectoryStable(label, before, after) {
128
- if (before.dev !== after.dev || before.ino !== after.ino || before.realPath !== after.realPath) {
129
- throw new Error(`${label} identity changed before atomic config replacement.`);
130
- }
131
- }
132
- function assertRealConfigBoundary(root, parent) {
133
- const relative = path.relative(root.realPath, parent.realPath);
134
- if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
135
- throw new Error('Config parent realpath escapes its allowed root.');
136
- }
137
- }
138
139
  async function prepareConfigFileParent(filePath, allowedRoot) {
139
140
  assertConfigPathBoundary(allowedRoot, filePath);
140
141
  await assertNoConfigSymlink(allowedRoot, filePath);
141
142
  await fs.ensureDir(path.dirname(filePath));
142
143
  await assertNoConfigSymlink(allowedRoot, filePath);
143
144
  }
144
- export function resolveConfigFileLockPath(filePath) {
145
- return path.join(path.dirname(filePath), `.${path.basename(filePath)}.aw.lock`);
146
- }
147
- async function releaseConfigFileLock(lease) {
148
- let lastError;
149
- for (let attempt = 1; attempt <= 3; attempt += 1) {
150
- try {
151
- await configFileLockBeforeReleaseHookForTests?.(lease.lockPath, attempt);
152
- await lease.release();
153
- return null;
154
- }
155
- catch (error) {
156
- lastError = error;
157
- if (attempt < 3) {
158
- await new Promise((resolve) => setTimeout(resolve, 10));
159
- }
160
- }
161
- }
162
- try {
163
- await lease.release();
164
- }
165
- catch {
166
- // Preserve the first release diagnostic. A final direct retry avoids a hook-created self-lock.
167
- }
168
- return lastError;
169
- }
170
- function emitConfigReleaseWarning(message) {
171
- try {
172
- process.emitWarning(message, { code: 'AW_CONFIG_LOCK_RELEASE_FAILED' });
173
- }
174
- catch {
175
- // Diagnostics cannot replace the primary action result or error.
176
- }
177
- }
178
- export async function withConfigFileLock(options) {
145
+ export async function withConfigFileMutation(options) {
179
146
  await prepareConfigFileParent(options.filePath, options.allowedRoot);
180
- const lockPath = resolveConfigFileLockPath(options.filePath);
181
- await assertNoConfigSymlink(options.allowedRoot, lockPath);
182
- const lease = await acquireProcessLock({ lockPath });
183
- let result;
184
- let actionError;
185
- let actionSucceeded = false;
186
- const commitContext = {
187
- parent: configCommitStorage.getStore(),
188
- durableCommit: false,
189
- };
190
- try {
191
- await assertNoConfigSymlink(options.allowedRoot, options.filePath);
192
- result = await configCommitStorage.run(commitContext, options.action);
193
- actionSucceeded = true;
194
- }
195
- catch (error) {
196
- actionError = error;
197
- }
198
- const releaseError = await releaseConfigFileLock(lease);
199
- if (!actionSucceeded) {
200
- if (releaseError) {
201
- emitConfigReleaseWarning('Config action failed, and its process lock release also failed.');
202
- }
203
- throw actionError;
204
- }
205
- if (releaseError) {
206
- if (commitContext.durableCommit) {
207
- emitConfigReleaseWarning('Config action completed successfully, but its process lock could not be released after 3 attempts. The committed result remains successful; the lock can require process exit or manual recovery before another update.');
208
- }
209
- else {
210
- throw releaseError;
211
- }
212
- }
213
- return result;
147
+ await assertNoConfigSymlink(options.allowedRoot, options.filePath);
148
+ return options.action();
214
149
  }
215
- export async function withPluginConfigTransactionLease(options) {
216
- const storePath = resolvePluginConfigStorePath({
150
+ export async function atomicReplaceConfigFile(options) {
151
+ await atomicReplaceSafeFile({
217
152
  ...options,
218
- ...(options.scope === 'project' ? { access: 'write' } : {}),
219
- });
220
- const allowedRoot = resolvePluginConfigAllowedRoot(options);
221
- return withConfigFileLock({
222
- filePath: `${storePath}.transaction`,
223
- allowedRoot,
224
- action: options.action,
153
+ label: 'Config path',
154
+ temporaryTag: 'tmp',
155
+ beforeRename: atomicConfigBeforeRenameHookForTests,
156
+ afterRename: async (targetPath) => {
157
+ await atomicConfigAfterRenameHookForTests?.(targetPath).catch(() => undefined);
158
+ },
225
159
  });
226
160
  }
227
- export async function atomicReplaceConfigFile(options) {
228
- await prepareConfigFileParent(options.filePath, options.allowedRoot);
229
- const rootPath = path.resolve(options.allowedRoot);
230
- const parentPath = path.dirname(path.resolve(options.filePath));
231
- const rootIdentity = await readConfigDirectoryIdentity(rootPath);
232
- const parentIdentity = await readConfigDirectoryIdentity(parentPath);
233
- assertRealConfigBoundary(rootIdentity, parentIdentity);
234
- const currentTarget = await lstatIfExists(options.filePath);
235
- if (currentTarget && (!currentTarget.isFile() || currentTarget.isSymbolicLink())) {
236
- throw new Error(`Config target must be a regular file: ${options.filePath}`);
237
- }
238
- const temporaryPath = path.join(parentPath, `.${path.basename(options.filePath)}.tmp-${process.pid}-${crypto.randomUUID()}`);
239
- assertConfigPathBoundary(options.allowedRoot, temporaryPath);
240
- let handle;
241
- try {
242
- handle = await nodeFs.open(temporaryPath, 'wx', options.mode ?? (currentTarget ? currentTarget.mode & 0o777 : 0o600));
243
- await handle.writeFile(options.content, 'utf8');
244
- await handle.sync();
245
- await handle.close();
246
- handle = undefined;
247
- await atomicConfigBeforeRenameHookForTests?.(options.filePath, temporaryPath);
248
- await assertNoConfigSymlink(options.allowedRoot, options.filePath);
249
- const currentRootIdentity = await readConfigDirectoryIdentity(rootPath);
250
- const currentParentIdentity = await readConfigDirectoryIdentity(parentPath);
251
- assertRealConfigBoundary(currentRootIdentity, currentParentIdentity);
252
- assertConfigDirectoryStable('Config allowed root', rootIdentity, currentRootIdentity);
253
- assertConfigDirectoryStable('Config parent', parentIdentity, currentParentIdentity);
254
- const targetBeforeRename = await lstatIfExists(options.filePath);
255
- if (targetBeforeRename && (!targetBeforeRename.isFile() || targetBeforeRename.isSymbolicLink())) {
256
- throw new Error(`Config target must be a regular file: ${options.filePath}`);
257
- }
258
- await nodeFs.rename(temporaryPath, options.filePath);
259
- markConfigDurableCommit();
260
- // rename is the commit point. Diagnostics and durability work after it are best effort,
261
- // because reporting failure here would leave the new generation on disk without giving
262
- // the caller a safe way to restore the old generation.
263
- await atomicConfigAfterRenameHookForTests?.(options.filePath).catch(() => undefined);
264
- await (async () => {
265
- const finalTarget = await fs.lstat(options.filePath);
266
- if (!finalTarget.isFile() || finalTarget.isSymbolicLink()) {
267
- throw new Error('Atomic config replacement produced an invalid target.');
268
- }
269
- if (await fs.readFile(options.filePath, 'utf8') !== options.content) {
270
- throw new Error('Atomic config replacement content differs from the committed content.');
271
- }
272
- })().catch(() => undefined);
273
- const directoryHandle = await nodeFs.open(parentPath, 'r').catch(() => null);
274
- await directoryHandle?.sync().catch(() => undefined);
275
- await directoryHandle?.close().catch(() => undefined);
276
- }
277
- finally {
278
- await handle?.close().catch(() => undefined);
279
- await nodeFs.rm(temporaryPath, { force: true }).catch(() => undefined);
280
- }
281
- }
282
161
  export async function atomicRemoveConfigFile(options) {
283
162
  await prepareConfigFileParent(options.filePath, options.allowedRoot);
284
- const rootPath = path.resolve(options.allowedRoot);
285
- const parentPath = path.dirname(path.resolve(options.filePath));
286
- const rootIdentity = await readConfigDirectoryIdentity(rootPath);
287
- const parentIdentity = await readConfigDirectoryIdentity(parentPath);
288
- assertRealConfigBoundary(rootIdentity, parentIdentity);
163
+ await assertSafeFileMutationPath({
164
+ filePath: options.filePath,
165
+ allowedRoot: options.allowedRoot,
166
+ label: 'Config path',
167
+ });
168
+ await assertRealFileParentWithinRoot({
169
+ filePath: options.filePath,
170
+ allowedRoot: options.allowedRoot,
171
+ label: 'Config path',
172
+ });
289
173
  const currentTarget = await lstatIfExists(options.filePath);
290
174
  if (!currentTarget)
291
175
  return false;
@@ -293,12 +177,16 @@ export async function atomicRemoveConfigFile(options) {
293
177
  throw new Error(`Config target must be a regular file: ${options.filePath}`);
294
178
  }
295
179
  await atomicConfigBeforeRenameHookForTests?.(options.filePath, options.filePath);
296
- await assertNoConfigSymlink(options.allowedRoot, options.filePath);
297
- const currentRootIdentity = await readConfigDirectoryIdentity(rootPath);
298
- const currentParentIdentity = await readConfigDirectoryIdentity(parentPath);
299
- assertRealConfigBoundary(currentRootIdentity, currentParentIdentity);
300
- assertConfigDirectoryStable('Config allowed root', rootIdentity, currentRootIdentity);
301
- assertConfigDirectoryStable('Config parent', parentIdentity, currentParentIdentity);
180
+ await assertSafeFileMutationPath({
181
+ filePath: options.filePath,
182
+ allowedRoot: options.allowedRoot,
183
+ label: 'Config path',
184
+ });
185
+ await assertRealFileParentWithinRoot({
186
+ filePath: options.filePath,
187
+ allowedRoot: options.allowedRoot,
188
+ label: 'Config path',
189
+ });
302
190
  const targetBeforeRemove = await lstatIfExists(options.filePath);
303
191
  if (!targetBeforeRemove)
304
192
  return false;
@@ -306,18 +194,22 @@ export async function atomicRemoveConfigFile(options) {
306
194
  throw new Error(`Config target must be a regular file: ${options.filePath}`);
307
195
  }
308
196
  await nodeFs.unlink(options.filePath);
309
- markConfigDurableCommit();
310
197
  await atomicConfigAfterRenameHookForTests?.(options.filePath).catch(() => undefined);
311
- const directoryHandle = await nodeFs.open(parentPath, 'r').catch(() => null);
312
- await directoryHandle?.sync().catch(() => undefined);
313
- await directoryHandle?.close().catch(() => undefined);
314
198
  return true;
315
199
  }
316
200
  function isRecord(value) {
317
201
  return typeof value === 'object' && value !== null && !Array.isArray(value);
318
202
  }
319
203
  function formatValue(value) {
320
- return typeof value === 'string' ? value : JSON.stringify(value);
204
+ if (typeof value === 'string')
205
+ return value;
206
+ if (typeof value === 'number' || typeof value === 'boolean') {
207
+ return stablePluginConfigStringify(value);
208
+ }
209
+ if (isRecord(value) || Array.isArray(value)) {
210
+ return stablePluginConfigStringify(value);
211
+ }
212
+ return JSON.stringify(value);
321
213
  }
322
214
  async function calculateConfigManifestDigest(filePath) {
323
215
  const hash = crypto.createHash('sha256');
@@ -332,16 +224,17 @@ async function calculateConfigSchemaManifestDigestForPlugin(plugin) {
332
224
  hash.update(JSON.stringify(plugin.manifest));
333
225
  return `sha256:${hash.digest('hex')}`;
334
226
  }
335
- function createConfigSchemaEvidenceFromCurrentCatalog(plugin, manifestDigest) {
227
+ function createConfigSchemaEvidenceFromCurrentCatalog(plugin, manifestDigest, platform) {
336
228
  return {
337
229
  source: 'currentCatalog',
338
- identity: createPluginConfigSchemaIdentity(plugin.manifest),
230
+ identity: createPluginConfigSchemaIdentity(plugin.manifest, platform),
231
+ platform,
339
232
  pluginVersion: plugin.manifest.version,
340
233
  manifestDigest,
341
234
  };
342
235
  }
343
236
  function getStoreEntries(values) {
344
- return { ...values };
237
+ return Object.fromEntries(Object.entries(values));
345
238
  }
346
239
  export function assertSafePluginConfigSegment(pluginName) {
347
240
  if (typeof pluginName !== 'string' || pluginName.trim() === '') {
@@ -363,116 +256,184 @@ export function resolveAwProjectRoot(cwd) {
363
256
  return path.resolve(resolveRepoRootSync(cwd));
364
257
  }
365
258
  function resolvePluginConfigAllowedRoot(options) {
366
- return options.scope === 'user'
367
- ? resolveAwHome(options.env)
368
- : path.join(resolveAwProjectRoot(options.cwd), '.agent-workflows');
259
+ return resolveAwHome(options.env);
369
260
  }
261
+ /** Scope selects source context. All config values belong to the user document. */
370
262
  export function resolvePluginConfigStorePath(options) {
371
263
  const pluginName = assertSafePluginConfigSegment(options.pluginName);
372
- const sourceId = options.sourceId === undefined
373
- ? undefined
374
- : assertSafePluginConfigSegment(options.sourceId);
375
- const root = options.scope === 'user'
376
- ? resolveAwHome(options.env)
377
- : path.join(resolveAwProjectRoot(options.cwd), '.agent-workflows');
378
- const configDir = options.scope === 'project' && options.projectLayer === 'local'
379
- ? 'plugin-config.local'
380
- : CONFIG_DIR;
381
- const filePath = path.join(root, configDir, ...(sourceId ? [sourceId] : []), pluginName, CONFIG_FILE);
382
- if (options.scope !== 'project') {
383
- return filePath;
384
- }
385
- if (options.access === 'read') {
386
- return assertTestReadablePath(filePath, options.projectLayer === 'local'
387
- ? 'project local plugin config store (.agent-workflows/plugin-config.local)'
388
- : 'project shared plugin config store (.agent-workflows/plugin-config)', '用 registerReadonlyFixtureRoot() 或 runWithRepositoryCwdAsReadOnly() 登记只读 project fixture 根;需要写入时改用 withSafeTestCwd() 或 registerWritableStateRoot()。');
389
- }
390
- if (options.access === 'write') {
391
- return assertTestWritablePath(filePath, options.projectLayer === 'local'
392
- ? 'project local plugin config store (.agent-workflows/plugin-config.local)'
393
- : 'project shared plugin config store (.agent-workflows/plugin-config)', '用 withSafeTestCwd() 切到测试可写 cwd,或通过 registerWritableStateRoot() 登记 project fixture 根。');
394
- }
395
- return filePath;
264
+ const sourceId = options.sourceId === undefined ? undefined : assertSafePluginConfigSegment(options.sourceId);
265
+ return path.join(resolveAwHome(options.env), CONFIG_DIR, ...(sourceId ? [sourceId] : []), pluginName, CONFIG_FILE);
396
266
  }
397
267
  export function resolvePluginConfigStoreTargets(options) {
398
- if (options.scope === 'user') {
399
- return [{
400
- storeKind: 'user',
401
- path: resolvePluginConfigStorePath(options),
402
- }];
403
- }
404
- return [
405
- {
406
- storeKind: 'projectShared',
407
- path: resolvePluginConfigStorePath({
408
- ...options,
409
- projectLayer: 'shared',
410
- }),
411
- projectLayer: 'shared',
412
- },
413
- {
414
- storeKind: 'projectLocal',
415
- path: resolvePluginConfigStorePath({
416
- ...options,
417
- projectLayer: 'local',
418
- }),
419
- projectLayer: 'local',
420
- },
421
- ];
268
+ return [{ storeKind: 'user', path: resolvePluginConfigStorePath(options) }];
269
+ }
270
+ function isPluginConfigScalar(value) {
271
+ if (typeof value === 'string' || typeof value === 'boolean')
272
+ return true;
273
+ return typeof value === 'number' && Number.isFinite(value);
274
+ }
275
+ function isPluginConfigObject(value) {
276
+ if (!isRecord(value))
277
+ return false;
278
+ return Object.values(value).every((property) => {
279
+ if (isPluginConfigScalar(property))
280
+ return true;
281
+ if (Array.isArray(property)) {
282
+ const elementType = typeof property[0];
283
+ return Object.keys(property).length === property.length
284
+ && property.every((item, index) => Object.hasOwn(property, index)
285
+ && typeof item === elementType
286
+ && isPluginConfigScalar(item));
287
+ }
288
+ return isRecord(property) && Object.values(property).every(isPluginConfigScalar);
289
+ });
422
290
  }
423
- async function readStoreFile(filePath) {
424
- const value = await fs.readJson(filePath);
425
- if (!isRecord(value)) {
426
- throw new Error(`Invalid plugin config store "${filePath}": expected a JSON object.`);
291
+ function isPluginConfigValue(value) {
292
+ if (isPluginConfigScalar(value))
293
+ return true;
294
+ if (Array.isArray(value)) {
295
+ if (Object.keys(value).length !== value.length)
296
+ return false;
297
+ const first = value[0];
298
+ const elementType = isRecord(first) ? 'object' : typeof first;
299
+ return value.every((item, index) => Object.hasOwn(value, index)
300
+ && (isRecord(item) ? 'object' : typeof item) === elementType
301
+ && (isPluginConfigScalar(item) || isPluginConfigObject(item)));
427
302
  }
428
- return value;
303
+ return isPluginConfigObject(value);
429
304
  }
430
- async function readNamespacedStoreFile(options) {
431
- const raw = await fs.readJson(options.filePath);
432
- if (!isRecord(raw) || raw.schemaVersion !== 2 || !isRecord(raw.values)) {
433
- throw new Error(`legacyStateUnsupported: invalid or legacy plugin config store "${options.filePath}".`);
305
+ function invalidStore(filePath, code, message, rawDigest) {
306
+ return {
307
+ path: filePath,
308
+ exists: true,
309
+ state: 'invalid',
310
+ values: {},
311
+ ...(rawDigest ? { rawDigest } : {}),
312
+ invalidCode: code,
313
+ issues: [message],
314
+ };
315
+ }
316
+ function readyStore(filePath, values, rawDigest) {
317
+ return {
318
+ path: filePath,
319
+ exists: true,
320
+ state: 'ready',
321
+ values: canonicalizePluginConfigValues(values),
322
+ ...(rawDigest ? { rawDigest } : {}),
323
+ issues: [],
324
+ };
325
+ }
326
+ export function assertReadyPluginConfigStore(store) {
327
+ if (store.state !== 'invalid')
328
+ return;
329
+ throw new Error(`${store.invalidCode}: Invalid plugin config store "${store.path}". ${store.issues.join(' ')}`);
330
+ }
331
+ async function parseStoreJson(filePath) {
332
+ const content = await fs.readFile(filePath);
333
+ const rawDigest = `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`;
334
+ try {
335
+ return {
336
+ state: 'parsed',
337
+ value: JSON.parse(content.toString('utf8')),
338
+ rawDigest,
339
+ };
434
340
  }
435
- if (raw.sourceId !== options.sourceId || raw.pluginName !== options.pluginName) {
436
- throw new Error('Plugin config target identity does not match its namespaced path.');
341
+ catch (error) {
342
+ if (error instanceof SyntaxError) {
343
+ return {
344
+ state: 'invalidJson',
345
+ store: invalidStore(filePath, 'invalidJson', 'The store is not valid JSON.', rawDigest),
346
+ };
347
+ }
348
+ throw error;
437
349
  }
438
- if (raw.sourceIdentity !== options.sourceIdentity) {
439
- throw new Error('sourceChanged: plugin config source identity does not match the configured source.');
350
+ }
351
+ function validateStoreValues(options) {
352
+ if (!isRecord(options.values)) {
353
+ return invalidStore(options.filePath, 'invalidValues', 'The values field must be an object.', options.rawDigest);
440
354
  }
441
- return raw.values;
355
+ const values = Object.create(null);
356
+ const issues = [];
357
+ for (const [key, value] of Object.entries(options.values)) {
358
+ if (!isPluginConfigValue(value)) {
359
+ issues.push(`Config "${key}" is not a supported config value.`);
360
+ continue;
361
+ }
362
+ values[key] = value;
363
+ }
364
+ return issues.length > 0
365
+ ? invalidStore(options.filePath, 'invalidValues', issues.join(' '), options.rawDigest)
366
+ : readyStore(options.filePath, values, options.rawDigest);
367
+ }
368
+ function documentStore(options) {
369
+ const common = validateStoreValues({ filePath: options.filePath, values: options.common, rawDigest: options.rawDigest });
370
+ if (common.state === 'invalid')
371
+ return common;
372
+ if (!isRecord(options.platforms) || Object.keys(options.platforms).some((key) => !PLATFORM_TARGETS.includes(key))) {
373
+ return invalidStore(options.filePath, 'invalidValues', 'The platforms field must contain known platform objects.', options.rawDigest);
374
+ }
375
+ const platforms = {};
376
+ for (const [platform, values] of Object.entries(options.platforms)) {
377
+ const store = validateStoreValues({ filePath: options.filePath, values, rawDigest: options.rawDigest });
378
+ if (store.state === 'invalid')
379
+ return store;
380
+ platforms[platform] = store.values;
381
+ }
382
+ return { ...common, common: common.values, platforms, ...(options.platform ? { platform: options.platform } : {}),
383
+ values: options.platform ? platforms[options.platform] ?? {} : common.values };
384
+ }
385
+ export function pluginConfigStoreForProfile(store, platform) {
386
+ return { ...store, platform, values: platform ? store.platforms?.[platform] ?? {} : store.common ?? store.values };
387
+ }
388
+ /** Replace one layer in memory without changing any other profile. */
389
+ export function replacePluginConfigStoreLayer(store, values, platform) {
390
+ const common = platform ? store.common ?? store.values : canonicalizePluginConfigValues(values);
391
+ const platforms = { ...store.platforms };
392
+ if (platform) {
393
+ if (Object.keys(values).length)
394
+ platforms[platform] = canonicalizePluginConfigValues(values);
395
+ else
396
+ delete platforms[platform];
397
+ }
398
+ const exists = Object.keys(common).length > 0 || Object.keys(platforms).length > 0;
399
+ return { ...store, common, platforms, platform, values: platform ? platforms[platform] ?? {} : common,
400
+ exists, state: exists ? 'ready' : 'missing', issues: [], rawDigest: undefined };
401
+ }
402
+ async function readStoreFile(filePath, platform) {
403
+ const parsed = await parseStoreJson(filePath);
404
+ if (parsed.state === 'invalidJson')
405
+ return parsed.store;
406
+ const raw = parsed.value;
407
+ if (!isRecord(raw) || raw.schemaVersion !== 6
408
+ || Object.keys(raw).some((key) => !['schemaVersion', 'common', 'platforms'].includes(key))) {
409
+ return invalidStore(filePath, 'schemaVersionUnsupported', 'Only plugin config store schemaVersion 6 is supported. Reset the old document, then save the required values.', parsed.rawDigest);
410
+ }
411
+ return documentStore({ filePath, common: raw.common, platforms: raw.platforms, rawDigest: parsed.rawDigest, platform });
412
+ }
413
+ async function readNamespacedStoreFile(options) {
414
+ const parsed = await parseStoreJson(options.filePath);
415
+ if (parsed.state === 'invalidJson')
416
+ return parsed.store;
417
+ const envelope = readPluginConfigEnvelopeV6(parsed.value);
418
+ if (!envelope)
419
+ return invalidStore(options.filePath, 'schemaVersionUnsupported', 'Only a valid plugin config store schemaVersion 6 is supported. Reset the old document, then save the required values.', parsed.rawDigest);
420
+ if (envelope.sourceId !== options.sourceId || envelope.pluginName !== options.pluginName
421
+ || !options.sourceIdentity || envelope.binding.sourceIdentity !== options.sourceIdentity) {
422
+ return invalidStore(options.filePath, 'identityMismatch', 'The user store is not bound to the requested source and plugin identity.', parsed.rawDigest);
423
+ }
424
+ return documentStore({ filePath: options.filePath, common: envelope.common, platforms: envelope.platforms,
425
+ rawDigest: parsed.rawDigest, platform: options.platform });
442
426
  }
443
427
  function namespacedConfigContent(options) {
428
+ const document = { schemaVersion: 6, common: canonicalizePluginConfigValues(options.common),
429
+ platforms: Object.fromEntries(Object.entries(options.platforms).sort(([a], [b]) => a.localeCompare(b, 'en'))
430
+ .map(([platform, values]) => [platform, canonicalizePluginConfigValues(values)])) };
444
431
  if (!options.sourceId)
445
- return `${JSON.stringify(options.values, null, 2)}\n`;
432
+ return `${JSON.stringify(document, null, 2)}\n`;
446
433
  if (!options.sourceIdentity)
447
- throw new Error('sourceIdentity is required for namespaced plugin config.');
448
- const envelope = {
449
- schemaVersion: 2,
450
- sourceId: options.sourceId,
451
- sourceIdentity: options.sourceIdentity,
452
- pluginName: options.pluginName,
453
- values: options.values,
454
- };
455
- return `${JSON.stringify(envelope, null, 2)}\n`;
456
- }
457
- async function assertNoLegacyConfigCoexistence(options) {
458
- if (!options.sourceId)
459
- return;
460
- const legacyPath = resolvePluginConfigStorePath({
461
- pluginName: options.pluginName,
462
- scope: options.scope,
463
- cwd: options.cwd,
464
- env: options.env,
465
- projectLayer: options.projectLayer,
466
- ...(options.scope === 'project' ? { access: 'read' } : {}),
467
- });
468
- if (await lstatIfExists(legacyPath)) {
469
- throw new Error('legacyStateUnsupported: legacy and namespaced plugin config stores cannot coexist.');
470
- }
471
- }
472
- async function withUserPluginConfigRuntimeLease(options, action) {
473
- return options.scope === 'user' || options.sourceId !== undefined
474
- ? withActiveMarketplaceRuntimeLease(options.env, action)
475
- : action();
434
+ throw new Error('sourceChanged: user plugin config requires a source identity.');
435
+ return `${JSON.stringify({ ...document, sourceId: options.sourceId, pluginName: options.pluginName,
436
+ binding: { kind: 'source', sourceIdentity: options.sourceIdentity } }, null, 2)}\n`;
476
437
  }
477
438
  export async function readPluginConfigStore(options) {
478
439
  const filePath = resolvePluginConfigStorePath({
@@ -481,14 +442,11 @@ export async function readPluginConfigStore(options) {
481
442
  });
482
443
  const allowedRoot = resolvePluginConfigAllowedRoot(options);
483
444
  if (options.sourceId) {
484
- if (!options.sourceIdentity)
485
- throw new Error('sourceIdentity is required for namespaced plugin config.');
486
445
  const legacyPath = resolvePluginConfigStorePath({
487
446
  pluginName: options.pluginName,
488
447
  scope: options.scope,
489
448
  cwd: options.cwd,
490
449
  env: options.env,
491
- projectLayer: options.projectLayer,
492
450
  ...(options.scope === 'project' ? { access: 'read' } : {}),
493
451
  });
494
452
  if (await inspectConfigReadTarget(allowedRoot, legacyPath)) {
@@ -499,21 +457,22 @@ export async function readPluginConfigStore(options) {
499
457
  return {
500
458
  path: filePath,
501
459
  exists: false,
460
+ state: 'missing',
502
461
  values: {},
462
+ issues: [],
503
463
  };
504
464
  }
505
- return {
506
- path: filePath,
507
- exists: true,
508
- values: options.sourceId
509
- ? await readNamespacedStoreFile({
510
- filePath,
511
- sourceId: options.sourceId,
512
- sourceIdentity: options.sourceIdentity,
513
- pluginName: options.pluginName,
514
- })
515
- : await readStoreFile(filePath),
516
- };
465
+ return options.sourceId
466
+ ? readNamespacedStoreFile({
467
+ filePath,
468
+ sourceId: options.sourceId,
469
+ scope: options.scope,
470
+ sourceIdentity: options.sourceIdentity,
471
+ logicalIdentity: options.logicalIdentity,
472
+ pluginName: options.pluginName,
473
+ platform: options.platform,
474
+ })
475
+ : readStoreFile(filePath, options.platform);
517
476
  }
518
477
  export async function readNamespacedPluginConfigStoreIdentity(options) {
519
478
  const filePath = resolvePluginConfigStorePath({
@@ -522,15 +481,21 @@ export async function readNamespacedPluginConfigStoreIdentity(options) {
522
481
  });
523
482
  if (!await inspectConfigReadTarget(resolvePluginConfigAllowedRoot(options), filePath))
524
483
  return null;
525
- const raw = await fs.readJson(filePath);
526
- if (!isRecord(raw) || raw.schemaVersion !== 2 || !isRecord(raw.values)
527
- || raw.sourceId !== options.sourceId || raw.pluginName !== options.pluginName
528
- || typeof raw.sourceIdentity !== 'string') {
529
- throw new Error('legacyStateUnsupported: invalid namespaced plugin config store.');
530
- }
484
+ const parsed = await parseStoreJson(filePath);
485
+ if (parsed.state === 'invalidJson') {
486
+ throw new Error(`${parsed.store.invalidCode}: invalid namespaced plugin config store.`);
487
+ }
488
+ const envelope = readPluginConfigEnvelopeV6(parsed.value, options.scope);
489
+ if (!envelope
490
+ || envelope.sourceId !== options.sourceId
491
+ || envelope.pluginName !== options.pluginName) {
492
+ throw new Error('schemaVersionUnsupported: invalid namespaced plugin config store.');
493
+ }
494
+ const store = documentStore({ filePath, common: envelope.common, platforms: envelope.platforms, platform: options.platform });
495
+ assertReadyPluginConfigStore(store);
531
496
  return {
532
- sourceIdentity: raw.sourceIdentity,
533
- store: { path: filePath, exists: true, values: raw.values },
497
+ binding: envelope.binding,
498
+ store,
534
499
  };
535
500
  }
536
501
  async function listConfigStoreDirectoryPluginNames(storeRoot) {
@@ -557,32 +522,75 @@ async function listConfigStoreDirectoryPluginNames(storeRoot) {
557
522
  return pluginNames;
558
523
  }
559
524
  export async function listPluginConfigStorePluginNames(options) {
560
- const projectRoot = resolveAwProjectRoot(options.cwd);
561
- const storeRoots = options.scope === 'user'
562
- ? [path.join(resolveAwHome(options.env), CONFIG_DIR)]
563
- : options.scope === 'project'
564
- ? [path.join(projectRoot, '.agent-workflows', options.projectLayer === 'local' ? 'plugin-config.local' : CONFIG_DIR)]
565
- : [
566
- path.join(resolveAwHome(options.env), CONFIG_DIR),
567
- path.join(projectRoot, '.agent-workflows', CONFIG_DIR),
568
- path.join(projectRoot, '.agent-workflows', 'plugin-config.local'),
569
- ];
525
+ const storeRoots = [path.join(resolveAwHome(options.env), CONFIG_DIR)];
570
526
  const pluginNames = (await Promise.all(storeRoots.map((storeRoot) => listConfigStoreDirectoryPluginNames(storeRoot)))).flat();
571
527
  return [...new Set(pluginNames)].sort((left, right) => left.localeCompare(right));
572
528
  }
529
+ export async function listNamespacedPluginConfigStoreIdentities(options) {
530
+ const boundaryRoot = resolveAwHome(options.env);
531
+ if (options.scope === 'user') {
532
+ await canonicalizePathThroughExistingAncestor(boundaryRoot);
533
+ }
534
+ else {
535
+ await fs.realpath(boundaryRoot);
536
+ }
537
+ const storeRoot = path.join(boundaryRoot, CONFIG_DIR);
538
+ if (!await inspectConfigInventoryStoreRoot(boundaryRoot, storeRoot))
539
+ return [];
540
+ const output = [];
541
+ for (const sourceEntry of await fs.readdir(storeRoot, { withFileTypes: true })) {
542
+ if (!sourceEntry.isDirectory() || sourceEntry.isSymbolicLink())
543
+ continue;
544
+ let sourceId;
545
+ try {
546
+ sourceId = assertSafePluginConfigSegment(sourceEntry.name);
547
+ }
548
+ catch {
549
+ continue;
550
+ }
551
+ const sourceRoot = path.join(storeRoot, sourceId);
552
+ let pluginEntries;
553
+ try {
554
+ await assertNoConfigSymlink(boundaryRoot, sourceRoot);
555
+ pluginEntries = await fs.readdir(sourceRoot, { withFileTypes: true });
556
+ }
557
+ catch {
558
+ continue;
559
+ }
560
+ for (const pluginEntry of pluginEntries) {
561
+ if (!pluginEntry.isDirectory() || pluginEntry.isSymbolicLink())
562
+ continue;
563
+ let pluginName;
564
+ try {
565
+ pluginName = assertSafePluginConfigSegment(pluginEntry.name);
566
+ await assertNoConfigSymlink(boundaryRoot, path.join(sourceRoot, pluginName));
567
+ }
568
+ catch {
569
+ continue;
570
+ }
571
+ let target;
572
+ try {
573
+ target = await lstatIfExists(path.join(sourceRoot, pluginName, CONFIG_FILE));
574
+ }
575
+ catch {
576
+ continue;
577
+ }
578
+ if (!target)
579
+ continue;
580
+ output.push({ sourceId, pluginName, pluginId: `${sourceId}/${pluginName}` });
581
+ }
582
+ }
583
+ return output.sort((left, right) => left.pluginId.localeCompare(right.pluginId));
584
+ }
573
585
  export async function listNamespacedPluginConfigStores(options) {
574
- const boundaryRoot = options.scope === 'user'
575
- ? resolveAwHome(options.env)
576
- : resolveAwProjectRoot(options.cwd);
586
+ const boundaryRoot = resolveAwHome(options.env);
577
587
  if (options.scope === 'user') {
578
588
  await canonicalizePathThroughExistingAncestor(boundaryRoot);
579
589
  }
580
590
  else {
581
591
  await fs.realpath(boundaryRoot);
582
592
  }
583
- const storeRoot = path.join(boundaryRoot, ...(options.scope === 'project' ? ['.agent-workflows'] : []), options.scope === 'project' && options.projectLayer === 'local'
584
- ? 'plugin-config.local'
585
- : CONFIG_DIR);
593
+ const storeRoot = path.join(boundaryRoot, CONFIG_DIR);
586
594
  const output = [];
587
595
  if (!await inspectConfigInventoryStoreRoot(boundaryRoot, storeRoot))
588
596
  return output;
@@ -604,380 +612,330 @@ export async function listNamespacedPluginConfigStores(options) {
604
612
  const filePath = path.join(storeRoot, sourceId, pluginName, CONFIG_FILE);
605
613
  if (!await inspectConfigReadTarget(storeRoot, filePath))
606
614
  continue;
607
- const raw = await fs.readJson(filePath);
608
- if (!isRecord(raw) || raw.schemaVersion !== 2 || !isRecord(raw.values)
609
- || raw.sourceId !== sourceId || raw.pluginName !== pluginName
610
- || typeof raw.sourceIdentity !== 'string') {
611
- throw new Error(`legacyStateUnsupported: invalid namespaced plugin config store "${filePath}".`);
615
+ const parsed = await parseStoreJson(filePath);
616
+ if (parsed.state === 'invalidJson') {
617
+ throw new Error(`${parsed.store.invalidCode}: invalid namespaced plugin config store "${filePath}".`);
618
+ }
619
+ const envelope = readPluginConfigEnvelopeV6(parsed.value, options.scope);
620
+ if (!envelope
621
+ || envelope.sourceId !== sourceId
622
+ || envelope.pluginName !== pluginName) {
623
+ throw new Error(`schemaVersionUnsupported: invalid namespaced plugin config store "${filePath}".`);
612
624
  }
625
+ const store = documentStore({ filePath, common: envelope.common, platforms: envelope.platforms });
626
+ assertReadyPluginConfigStore(store);
613
627
  output.push({
614
628
  sourceId,
615
- sourceIdentity: raw.sourceIdentity,
629
+ binding: envelope.binding,
616
630
  pluginName,
617
631
  pluginId: `${sourceId}/${pluginName}`,
618
- values: raw.values,
632
+ values: store.values,
619
633
  });
620
634
  }
621
635
  }
622
636
  return output.sort((left, right) => left.pluginId.localeCompare(right.pluginId));
623
637
  }
624
638
  export async function writePluginConfigStore(options) {
625
- await assertNoLegacyConfigCoexistence(options);
626
- const filePath = resolvePluginConfigStorePath({
627
- ...options,
628
- ...(options.scope === 'project' ? { access: 'write' } : {}),
629
- });
639
+ const current = await readPluginConfigStore(options);
640
+ assertReadyPluginConfigStore(current);
641
+ const validated = validateStoreValues({ filePath: current.path, values: options.values });
642
+ assertReadyPluginConfigStore(validated);
643
+ return commitPluginConfigLayer(options, current, validated.values);
644
+ }
645
+ async function commitPluginConfigLayer(options, current, values) {
646
+ const next = replacePluginConfigStoreLayer(current, values, options.platform);
630
647
  const allowedRoot = resolvePluginConfigAllowedRoot(options);
631
- await withUserPluginConfigRuntimeLease(options, async () => {
632
- await withConfigFileLock({
633
- filePath,
634
- allowedRoot,
635
- action: async () => atomicReplaceConfigFile({
636
- filePath,
637
- allowedRoot,
638
- content: namespacedConfigContent(options),
639
- mode: 0o600,
640
- }),
641
- });
642
- });
643
- return {
644
- pluginName: options.pluginName,
645
- scope: options.scope,
646
- path: filePath,
647
- };
648
+ await withConfigFileMutation({ filePath: current.path, allowedRoot, action: async () => {
649
+ if (!next.exists)
650
+ await atomicRemoveConfigFile({ filePath: current.path, allowedRoot });
651
+ else
652
+ await atomicReplaceConfigFile({ filePath: current.path, allowedRoot,
653
+ content: namespacedConfigContent({ ...options, common: next.common, platforms: next.platforms }), mode: 0o600 });
654
+ } });
655
+ return { pluginName: options.pluginName, scope: 'user', platform: options.platform, path: current.path, warnings: [] };
648
656
  }
649
657
  export async function patchPluginConfigStore(options) {
650
- await assertNoLegacyConfigCoexistence(options);
651
- const filePath = resolvePluginConfigStorePath({
652
- ...options,
653
- ...(options.scope === 'project' ? { access: 'write' } : {}),
654
- });
655
- const allowedRoot = resolvePluginConfigAllowedRoot(options);
658
+ await options.reviewPreflight?.();
659
+ const current = await readPluginConfigStore(options);
660
+ assertReadyPluginConfigStore(current);
656
661
  const removedKeys = options.removeKeys ?? [];
657
- await withUserPluginConfigRuntimeLease(options, async () => {
658
- await withConfigFileLock({
659
- filePath,
660
- allowedRoot,
661
- action: async () => {
662
- await options.reviewPreflight?.();
663
- const current = (await lstatIfExists(filePath))
664
- ? options.sourceId
665
- ? await readNamespacedStoreFile({
666
- filePath,
667
- sourceId: options.sourceId,
668
- sourceIdentity: options.sourceIdentity,
669
- pluginName: options.pluginName,
670
- })
671
- : await readStoreFile(filePath)
672
- : {};
673
- if (options.requireExistingRemoveKeys) {
674
- const missingKey = removedKeys.find((key) => !Object.hasOwn(current, key));
675
- if (missingKey)
676
- throw new Error(`Unknown config key "${missingKey}".`);
677
- }
678
- const next = { ...current };
679
- for (const key of removedKeys) {
680
- delete next[key];
681
- }
682
- for (const [key, value] of Object.entries(options.updates)) {
683
- next[key] = value;
684
- }
685
- await atomicReplaceConfigFile({
686
- filePath,
687
- allowedRoot,
688
- content: namespacedConfigContent({ ...options, values: next }),
689
- mode: 0o600,
690
- });
691
- },
692
- });
693
- });
694
- return {
695
- pluginName: options.pluginName,
696
- scope: options.scope,
697
- path: filePath,
698
- updatedKeys: Object.keys(options.updates),
699
- removedKeys,
700
- };
662
+ if (options.requireExistingRemoveKeys) {
663
+ const missing = removedKeys.find((key) => !Object.hasOwn(current.values, key));
664
+ if (missing)
665
+ throw new Error(`Unknown config key "${missing}".`);
666
+ }
667
+ const next = Object.assign(Object.create(null), current.values);
668
+ for (const key of removedKeys)
669
+ delete next[key];
670
+ for (const [key, value] of Object.entries(options.updates))
671
+ next[key] = value;
672
+ const validated = validateStoreValues({ filePath: current.path, values: next });
673
+ assertReadyPluginConfigStore(validated);
674
+ return { ...await commitPluginConfigLayer(options, current, validated.values), updatedKeys: Object.keys(options.updates), removedKeys };
701
675
  }
702
676
  export async function resetPluginConfigStore(options) {
703
- await assertNoLegacyConfigCoexistence(options);
704
- const filePath = resolvePluginConfigStorePath({
705
- ...options,
706
- ...(options.scope === 'project' ? { access: 'write' } : {}),
707
- });
708
- const allowedRoot = resolvePluginConfigAllowedRoot(options);
709
- const existed = await withUserPluginConfigRuntimeLease(options, async () => {
710
- return withConfigFileLock({
711
- filePath,
712
- allowedRoot,
713
- action: async () => {
714
- await options.reviewPreflight?.();
715
- const target = await lstatIfExists(filePath);
716
- if (!target)
717
- return false;
718
- if (!target.isFile() || target.isSymbolicLink()) {
719
- throw new Error(`Config target must be a regular file: ${filePath}`);
720
- }
721
- if (options.sourceId) {
722
- if (!options.sourceIdentity) {
723
- throw new Error('sourceIdentity is required for namespaced plugin config.');
724
- }
725
- await readNamespacedStoreFile({
726
- filePath,
727
- sourceId: options.sourceId,
728
- sourceIdentity: options.sourceIdentity,
729
- pluginName: options.pluginName,
730
- });
731
- }
732
- else {
733
- await readStoreFile(filePath);
734
- }
735
- return atomicRemoveConfigFile({ filePath, allowedRoot });
736
- },
737
- });
738
- });
739
- return {
740
- pluginName: options.pluginName,
741
- scope: options.scope,
742
- storeKind: options.scope === 'user'
743
- ? 'user'
744
- : options.projectLayer === 'local'
745
- ? 'projectLocal'
746
- : 'projectShared',
747
- path: filePath,
748
- existed,
749
- deleted: existed,
750
- };
677
+ return resetPluginConfigStoreTarget(options, false);
751
678
  }
752
- export async function resetPluginConfigStores(options) {
753
- await assertNoLegacyConfigCoexistence(options);
754
- const targets = resolvePluginConfigStoreTargets({
679
+ /** Delete the plugin's complete user document, including every platform profile. */
680
+ export async function deletePluginConfigStore(options) {
681
+ return resetPluginConfigStoreTarget(options, true);
682
+ }
683
+ async function resetPluginConfigStoreTarget(options, wholeDocument) {
684
+ const filePath = resolvePluginConfigStorePath({
755
685
  ...options,
756
686
  ...(options.scope === 'project' ? { access: 'write' } : {}),
757
687
  });
758
688
  const allowedRoot = resolvePluginConfigAllowedRoot(options);
759
- const receipts = [];
760
- await withUserPluginConfigRuntimeLease(options, async () => {
761
- const withTargetLocks = async (index, action) => {
762
- const target = targets[index];
763
- if (!target)
764
- return action();
765
- return withConfigFileLock({
766
- filePath: target.path,
767
- allowedRoot,
768
- action: () => withTargetLocks(index + 1, action),
769
- });
770
- };
771
- await withTargetLocks(0, async () => {
772
- const existing = [];
773
- for (const target of targets) {
774
- const stats = await lstatIfExists(target.path);
775
- existing.push(stats !== null);
776
- if (!stats)
777
- continue;
778
- if (!stats.isFile() || stats.isSymbolicLink()) {
779
- throw new Error(`Config target must be a regular file: ${target.path}`);
780
- }
781
- if (options.sourceId) {
782
- if (!options.sourceIdentity) {
783
- throw new Error('sourceIdentity is required for namespaced plugin config.');
784
- }
785
- await readNamespacedStoreFile({
786
- filePath: target.path,
787
- sourceId: options.sourceId,
788
- sourceIdentity: options.sourceIdentity,
789
- pluginName: options.pluginName,
790
- });
791
- }
792
- else {
793
- await readStoreFile(target.path);
794
- }
795
- }
796
- for (const [index, target] of targets.entries()) {
797
- const deleted = await atomicRemoveConfigFile({
798
- filePath: target.path,
799
- allowedRoot,
800
- });
801
- receipts.push({
689
+ const publicTarget = `${options.scope}/plugin-config/${[
690
+ options.sourceId,
691
+ options.pluginName,
692
+ CONFIG_FILE,
693
+ ].filter(Boolean).join('/')}`;
694
+ const { root, candidate } = assertConfigPathBoundary(allowedRoot, filePath);
695
+ let current = root;
696
+ try {
697
+ for (const segment of path.relative(root, path.dirname(candidate)).split(path.sep).filter(Boolean)) {
698
+ const stats = await lstatIfExists(current);
699
+ if (!stats) {
700
+ return {
802
701
  pluginName: options.pluginName,
803
- scope: options.scope,
804
- storeKind: target.storeKind,
805
- path: target.path,
806
- existed: existing[index],
807
- deleted,
808
- });
702
+ scope: 'user',
703
+ storeKind: 'user',
704
+ path: filePath,
705
+ existed: false,
706
+ deleted: false,
707
+ resetDisposition: 'absent',
708
+ };
809
709
  }
810
- });
811
- });
812
- return receipts;
813
- }
814
- function coercePrimitiveValue(key, field, value) {
815
- if (field.type === 'string') {
816
- if (typeof value !== 'string') {
817
- throw new Error(`Config "${key}" must be a string.`);
818
- }
819
- return value;
820
- }
821
- if (field.type === 'number') {
822
- const numberValue = typeof value === 'number'
823
- ? value
824
- : typeof value === 'string' && value.trim() !== ''
825
- ? Number(value)
826
- : Number.NaN;
827
- if (!Number.isFinite(numberValue)) {
828
- throw new Error(`Config "${key}" must be a number.`);
710
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
711
+ throw new PluginConfigResetError('configResetTargetUnsupported', `${publicTarget} has an unsafe ancestor. Repair it manually, then retry config reset.`);
712
+ }
713
+ current = path.join(current, segment);
829
714
  }
830
- if (field.min !== undefined && numberValue < field.min) {
831
- throw new Error(`Config "${key}" must be greater than or equal to ${field.min}.`);
715
+ const parentStats = await lstatIfExists(current);
716
+ if (!parentStats) {
717
+ return {
718
+ pluginName: options.pluginName,
719
+ scope: 'user',
720
+ storeKind: 'user',
721
+ path: filePath,
722
+ existed: false,
723
+ deleted: false,
724
+ resetDisposition: 'absent',
725
+ };
832
726
  }
833
- if (field.max !== undefined && numberValue > field.max) {
834
- throw new Error(`Config "${key}" must be less than or equal to ${field.max}.`);
727
+ if (parentStats.isSymbolicLink() || !parentStats.isDirectory()) {
728
+ throw new PluginConfigResetError('configResetTargetUnsupported', `${publicTarget} has an unsafe ancestor. Repair it manually, then retry config reset.`);
835
729
  }
836
- return numberValue;
837
- }
838
- if (field.type === 'boolean') {
839
- if (typeof value === 'boolean') {
840
- return value;
730
+ await options.reviewPreflight?.();
731
+ const target = await lstatIfExists(filePath);
732
+ if (!target) {
733
+ return {
734
+ pluginName: options.pluginName,
735
+ scope: 'user',
736
+ storeKind: 'user',
737
+ path: filePath,
738
+ existed: false,
739
+ deleted: false,
740
+ resetDisposition: 'absent',
741
+ };
841
742
  }
842
- if (typeof value === 'string') {
843
- const normalized = value.trim().toLowerCase();
844
- if (['true', '1', 'yes', 'y'].includes(normalized)) {
845
- return true;
743
+ let store;
744
+ if (target.isFile()) {
745
+ try {
746
+ store = await readPluginConfigStore(options);
846
747
  }
847
- if (['false', '0', 'no', 'n'].includes(normalized)) {
848
- return false;
748
+ catch {
749
+ // A broken document still has the schema-independent reset recovery below.
849
750
  }
850
751
  }
851
- throw new Error(`Config "${key}" must be a boolean.`);
852
- }
853
- if (field.type === 'enum') {
854
- if (typeof value !== 'string') {
855
- throw new Error(`Config "${key}" must be an enum string.`);
752
+ if (!wholeDocument && store && store.state !== 'invalid' && replacePluginConfigStoreLayer(store, {}, options.platform).exists) {
753
+ await commitPluginConfigLayer(options, store, {});
754
+ return { pluginName: options.pluginName, scope: 'user', platform: options.platform, storeKind: 'user',
755
+ path: filePath, existed: true, deleted: false, resetDisposition: 'clearedLayer' };
856
756
  }
857
- if (!field.values?.includes(value)) {
858
- throw new Error(`Config "${key}" must be one of: ${(field.values ?? []).join(', ')}.`);
757
+ if (target.isFile() || target.isSymbolicLink()) {
758
+ await assertNoConfigSymlink(allowedRoot, path.dirname(filePath));
759
+ await nodeFs.unlink(filePath);
760
+ return {
761
+ pluginName: options.pluginName,
762
+ scope: 'user',
763
+ storeKind: 'user',
764
+ path: filePath,
765
+ existed: true,
766
+ deleted: true,
767
+ resetDisposition: target.isSymbolicLink() ? 'unlinkedSymlink' : 'deletedFile',
768
+ };
859
769
  }
860
- return value;
861
- }
862
- if (field.type === 'file' || field.type === 'directory') {
863
- if (typeof value !== 'string' || value.trim() === '') {
864
- throw new Error(`Config "${key}" must be a path string.`);
770
+ if (target.isDirectory()) {
771
+ const timestamp = new Date().toISOString().replace(/[-:]/gu, '').replace(/\..*$/u, '');
772
+ const quarantineBasename = `config.broken-${timestamp}-${crypto.randomUUID()}.json`;
773
+ await assertNoConfigSymlink(allowedRoot, path.dirname(filePath));
774
+ await nodeFs.rename(filePath, path.join(path.dirname(filePath), quarantineBasename));
775
+ return {
776
+ pluginName: options.pluginName,
777
+ scope: 'user',
778
+ storeKind: 'user',
779
+ path: filePath,
780
+ existed: true,
781
+ deleted: true,
782
+ resetDisposition: 'quarantinedDirectory',
783
+ quarantineBasename,
784
+ };
865
785
  }
866
- return value;
786
+ throw new PluginConfigResetError('configResetTargetUnsupported', `${publicTarget} is a special filesystem node. Move it manually, then retry config reset.`);
867
787
  }
868
- throw new Error(`Config "${key}" has unsupported type "${field.type}".`);
869
- }
870
- async function resolvePathConfigValue(options) {
871
- if (options.field.type !== 'file' && options.field.type !== 'directory') {
872
- return String(options.value);
788
+ catch (error) {
789
+ if (error instanceof PluginConfigResetError)
790
+ throw error;
791
+ const osCode = error.code;
792
+ throw new PluginConfigResetError('configResetFailed', `Cannot reset ${publicTarget}${osCode ? ` (${osCode})` : ''}. Fix filesystem access, then retry config reset.`, osCode);
873
793
  }
874
- const rawPath = String(options.value);
875
- const resolvedPath = path.isAbsolute(rawPath)
876
- ? rawPath
877
- : path.resolve(options.projectRoot, rawPath);
878
- const realPath = await fs.realpath(resolvedPath);
879
- const stats = await fs.stat(realPath);
880
- if (options.field.type === 'file' && !stats.isFile()) {
881
- throw new Error(`Config "${options.key}" must point to an existing file.`);
882
- }
883
- if (options.field.type === 'directory' && !stats.isDirectory()) {
884
- throw new Error(`Config "${options.key}" must point to an existing directory.`);
885
- }
886
- return realPath;
887
794
  }
888
- export async function coercePluginConfigValue(options) {
889
- const primitive = coercePrimitiveValue(options.key, options.field, options.value);
890
- if (options.field.type === 'file' || options.field.type === 'directory') {
891
- return resolvePathConfigValue({
892
- key: options.key,
893
- field: options.field,
894
- value: primitive,
895
- projectRoot: options.projectRoot,
896
- });
795
+ export async function inspectPluginConfigResetTarget(options) {
796
+ const filePath = resolvePluginConfigStorePath({
797
+ ...options,
798
+ ...(options.scope === 'project' ? { access: 'write' } : {}),
799
+ });
800
+ const allowedRoot = resolvePluginConfigAllowedRoot(options);
801
+ const publicTarget = `${options.scope}/plugin-config/${[
802
+ options.sourceId,
803
+ options.pluginName,
804
+ CONFIG_FILE,
805
+ ].filter(Boolean).join('/')}`;
806
+ const { root, candidate } = assertConfigPathBoundary(allowedRoot, filePath);
807
+ let current = root;
808
+ for (const segment of path.relative(root, path.dirname(candidate)).split(path.sep).filter(Boolean)) {
809
+ const stats = await lstatIfExists(current);
810
+ if (!stats)
811
+ return resetTargetInspection('absent');
812
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
813
+ throw new PluginConfigResetError('configResetTargetUnsupported', `${publicTarget} has an unsafe ancestor. Repair it manually, then retry config reset.`);
814
+ }
815
+ current = path.join(current, segment);
897
816
  }
898
- return primitive;
817
+ const parentStats = await lstatIfExists(current);
818
+ if (!parentStats)
819
+ return resetTargetInspection('absent');
820
+ if (parentStats.isSymbolicLink() || !parentStats.isDirectory()) {
821
+ throw new PluginConfigResetError('configResetTargetUnsupported', `${publicTarget} has an unsafe ancestor. Repair it manually, then retry config reset.`);
822
+ }
823
+ const target = await lstatIfExists(filePath);
824
+ if (!target)
825
+ return resetTargetInspection('absent');
826
+ const kind = target.isSymbolicLink() ? 'symbolicLink'
827
+ : target.isFile() ? 'regularFile'
828
+ : target.isDirectory() ? 'directory'
829
+ : 'special';
830
+ return resetTargetInspection(kind, target);
831
+ }
832
+ function resetTargetInspection(kind, stats) {
833
+ const fingerprint = `sha256:${crypto.createHash('sha256').update(JSON.stringify({
834
+ kind,
835
+ ...(stats ? {
836
+ dev: stats.dev,
837
+ ino: stats.ino,
838
+ mode: stats.mode,
839
+ size: stats.size,
840
+ mtimeMs: stats.mtimeMs,
841
+ ctimeMs: stats.ctimeMs,
842
+ } : {}),
843
+ })).digest('hex')}`;
844
+ return {
845
+ exists: kind !== 'absent',
846
+ kind,
847
+ resettable: kind !== 'special',
848
+ fingerprint,
849
+ };
899
850
  }
900
- function redactValue(field, value) {
901
- return field.sensitive ? '[redacted]' : value;
851
+ export async function resetPluginConfigStores(options) {
852
+ return [await resetPluginConfigStore(options)];
902
853
  }
903
- function sourceForStoreLayer(scope, projectLayer = 'shared') {
904
- if (scope === 'user') {
905
- return 'user';
854
+ function coerceConfigValue(key, field, value) {
855
+ let coerced = value;
856
+ if (field.type === 'number' && typeof value === 'string' && value.trim() !== '') {
857
+ coerced = Number(value);
858
+ }
859
+ else if (field.type === 'boolean' && typeof value === 'string') {
860
+ const normalized = value.trim().toLowerCase();
861
+ if (['true', '1', 'yes', 'y'].includes(normalized))
862
+ coerced = true;
863
+ if (['false', '0', 'no', 'n'].includes(normalized))
864
+ coerced = false;
906
865
  }
907
- return projectLayer === 'local' ? 'projectLocal' : 'project';
866
+ const issues = validateCorePluginConfigValue(field, coerced, key);
867
+ if (issues.length > 0) {
868
+ throw new Error(formatPluginConfigIssue(issues[0]));
869
+ }
870
+ return coerced;
908
871
  }
909
- function isPathTypeField(field) {
910
- return field.type === 'file' || field.type === 'directory';
872
+ export async function coercePluginConfigValue(options) {
873
+ return coerceConfigValue(options.key, options.field, options.value);
874
+ }
875
+ function redactValue(field, value) {
876
+ return redactPluginConfigValue(field, value);
911
877
  }
912
878
  async function applyConfigLayer(options) {
913
879
  for (const [key, field] of Object.entries(options.schema)) {
914
880
  if (!Object.hasOwn(options.entries, key)) {
915
881
  continue;
916
882
  }
917
- try {
918
- const coerced = await coercePluginConfigValue({
919
- key,
920
- field,
921
- value: options.entries[key],
922
- projectRoot: options.projectRoot,
923
- });
924
- options.values[key] = coerced;
925
- options.redactedValues[key] = redactValue(field, coerced);
883
+ const value = options.entries[key];
884
+ const validationIssues = validateCorePluginConfigValue(field, value, key);
885
+ if (validationIssues.length === 0) {
886
+ const redactedValue = redactValue(field, value);
887
+ options.values[key] = value;
888
+ options.redactedValues[key] = redactedValue;
926
889
  options.sources[key] = options.source;
927
- options.invalidIssues.delete(key);
890
+ options.fieldStates[key] = {
891
+ effective: { value, redactedValue, source: options.source },
892
+ };
928
893
  }
929
- catch (error) {
894
+ else {
895
+ const fallback = options.fieldStates[key]?.effective;
930
896
  delete options.values[key];
931
897
  delete options.redactedValues[key];
932
898
  options.sources[key] = options.source;
933
- options.invalidIssues.set(key, {
899
+ const issues = validationIssues.map((issue) => ({
934
900
  type: 'invalid-config',
935
901
  key,
936
902
  source: options.source,
937
- message: error instanceof Error ? error.message : String(error),
938
- });
903
+ message: formatPluginConfigIssue(issue),
904
+ }));
905
+ options.fieldStates[key] = {
906
+ invalidOverride: { source: options.source, issues },
907
+ ...(fallback ? { fallback } : {}),
908
+ };
939
909
  }
940
910
  }
941
911
  }
942
912
  export async function resolveEffectivePluginConfig(options) {
913
+ const workContext = options.context ? await resolveWorkContext({ cwd: options.cwd, context: options.context }) : undefined;
943
914
  const pluginName = assertSafePluginConfigSegment(options.pluginName ?? options.manifest.name);
944
- const schema = options.manifest.config?.schema;
915
+ const user = await readPluginConfigStore({ ...options, pluginName, scope: 'user' });
916
+ assertReadyPluginConfigStore(user);
917
+ const references = !options.referenceContext && pluginConfigHasExternalReferences(options.manifest)
918
+ ? await resolvePluginConfigReferenceContext({ ...options, scope: options.context ?? options.targetScope ?? 'user', plugins: options.referencePlugins }) : undefined;
919
+ return resolveEffectivePluginConfigFromStores({ ...options, pluginName, projectRoot: workContext?.projectRoot ?? ((options.context ?? options.targetScope) === 'project' ? resolveAwProjectRoot(options.cwd) : ''),
920
+ referenceContext: options.referenceContext ?? references?.context, referenceEvidence: references?.evidence,
921
+ stores: { user } });
922
+ }
923
+ export async function resolveEffectivePluginConfigFromStores(options) {
924
+ const pluginName = assertSafePluginConfigSegment(options.pluginName ?? options.manifest.name);
925
+ const definition = options.manifest.config ? selectPluginConfigProfile(options.manifest.config, options.platform) : undefined;
926
+ const schema = definition?.fields;
945
927
  if (!schema) {
946
- throw new Error(`Plugin "${pluginName}" does not declare an AW config schema.`);
928
+ throw new PluginConfigSchemaResolutionError('configSchemaUnavailable', `Plugin "${pluginName}" does not declare an AW config schema.`);
947
929
  }
948
- const projectRoot = resolveAwProjectRoot(options.cwd);
949
- const [userStore, projectStore, projectLocalStore] = await Promise.all([
950
- readPluginConfigStore({
951
- sourceId: options.sourceId,
952
- sourceIdentity: options.sourceIdentity,
953
- pluginName,
954
- scope: 'user',
955
- cwd: options.cwd,
956
- env: options.env,
957
- }),
958
- readPluginConfigStore({
959
- sourceId: options.sourceId,
960
- sourceIdentity: options.sourceIdentity,
961
- pluginName,
962
- scope: 'project',
963
- cwd: options.cwd,
964
- env: options.env,
965
- }),
966
- readPluginConfigStore({
967
- sourceId: options.sourceId,
968
- sourceIdentity: options.sourceIdentity,
969
- pluginName,
970
- scope: 'project',
971
- cwd: options.cwd,
972
- env: options.env,
973
- projectLayer: 'local',
974
- }),
975
- ]);
930
+ const userStore = options.stores.user;
931
+ assertReadyPluginConfigStore(userStore);
976
932
  const values = {};
977
933
  const redactedValues = {};
978
934
  const sources = {};
979
- const invalidIssues = new Map();
935
+ const fieldStates = {};
980
936
  const ignoredUnknownKeys = [];
937
+ const unsupportedLayerOverrides = [];
938
+ const dangerousKeyIssues = [];
981
939
  const schemaKeys = new Set(Object.keys(schema));
982
940
  for (const key of schemaKeys) {
983
941
  sources[key] = 'missing';
@@ -990,43 +948,140 @@ export async function resolveEffectivePluginConfig(options) {
990
948
  values,
991
949
  redactedValues,
992
950
  sources,
993
- invalidIssues,
951
+ fieldStates,
994
952
  schema: { [key]: field },
995
953
  entries: { [key]: field.default },
996
954
  source: 'default',
997
- projectRoot,
998
955
  });
999
956
  }
1000
- for (const [scope, store, projectLayer] of [
1001
- ['user', userStore, 'shared'],
1002
- ['project', projectStore, 'shared'],
1003
- ['project', projectLocalStore, 'local'],
1004
- ]) {
1005
- const plainEntries = getStoreEntries(store.values);
957
+ const layers = [
958
+ { entries: userStore.common ?? userStore.values, source: 'common' },
959
+ ...(options.platform ? [{ entries: userStore.platforms?.[options.platform] ?? {}, source: 'platform' }] : []),
960
+ ];
961
+ for (const { entries, source } of layers) {
962
+ const plainEntries = getStoreEntries(entries);
963
+ const dangerousIssues = new Map(validatePluginConfigDocument(definition, plainEntries)
964
+ .filter((issue) => issue.code === 'dangerousKey').map((issue) => [issue.path.field, issue]));
1006
965
  for (const key of Object.keys(plainEntries)) {
1007
- if (!schemaKeys.has(key)) {
1008
- ignoredUnknownKeys.push({
1009
- scope,
1010
- projectLayer,
1011
- source: sourceForStoreLayer(scope, projectLayer),
1012
- key,
1013
- });
1014
- }
966
+ if (schemaKeys.has(key))
967
+ continue;
968
+ const dangerousIssue = dangerousIssues.get(key);
969
+ if (dangerousIssue)
970
+ dangerousKeyIssues.push({ type: 'invalid-config', code: dangerousIssue.code,
971
+ key, source, message: formatPluginConfigIssue(dangerousIssue) });
972
+ else
973
+ ignoredUnknownKeys.push({ scope: 'user', source, key });
1015
974
  }
1016
975
  await applyConfigLayer({
1017
976
  values,
1018
977
  redactedValues,
1019
978
  sources,
1020
- invalidIssues,
979
+ fieldStates,
1021
980
  schema,
1022
981
  entries: plainEntries,
1023
- source: sourceForStoreLayer(scope, projectLayer),
1024
- projectRoot,
982
+ source,
1025
983
  });
1026
984
  }
1027
- const issues = [...invalidIssues.values()];
985
+ const candidateValues = {};
1028
986
  for (const [key, field] of Object.entries(schema)) {
1029
- if (field.required && values[key] === undefined) {
987
+ const source = sources[key];
988
+ if (source === 'default')
989
+ candidateValues[key] = field.default;
990
+ if (source === 'common')
991
+ candidateValues[key] = ownStoreValue(userStore.common ?? userStore.values, key);
992
+ if (source === 'platform' && options.platform)
993
+ candidateValues[key] = ownStoreValue(userStore.platforms?.[options.platform] ?? {}, key);
994
+ }
995
+ const candidateIssues = validatePluginConfigCandidate(definition, candidateValues, undefined, options.referenceContext);
996
+ const referenceIssues = candidateIssues.filter((issue) => issue.code.startsWith('valueRef')
997
+ && (!issue.path.plugin || issue.path.plugin === pluginName));
998
+ const missingReferenceIssues = [];
999
+ for (const issue of referenceIssues) {
1000
+ const key = issue.path.field;
1001
+ const source = sources[key];
1002
+ const state = fieldStates[key];
1003
+ const configIssue = {
1004
+ type: 'invalid-config', code: issue.code, key, source,
1005
+ message: formatPluginConfigIssue(issue),
1006
+ };
1007
+ if (source === 'missing') {
1008
+ missingReferenceIssues.push(configIssue);
1009
+ continue;
1010
+ }
1011
+ delete values[key];
1012
+ delete redactedValues[key];
1013
+ fieldStates[key] = {
1014
+ invalidOverride: { source, issues: [...(state?.invalidOverride?.issues ?? []), configIssue] },
1015
+ ...(state?.fallback ? { fallback: state.fallback } : {}),
1016
+ };
1017
+ }
1018
+ // Provider errors stay private, while each field that reads them remains unusable.
1019
+ if (options.referenceContext) {
1020
+ for (const foreign of candidateIssues.filter((issue) => issue.code.startsWith('valueRef')
1021
+ && issue.path.plugin && issue.path.plugin !== pluginName)) {
1022
+ for (const key of schemaKeys) {
1023
+ let dependencies;
1024
+ try {
1025
+ dependencies = getPluginConfigDependencyFields(definition, [key], options.referenceContext);
1026
+ }
1027
+ catch {
1028
+ continue; // The local association issue already reports the invalid schema.
1029
+ }
1030
+ if (!dependencies.some((entry) => entry.plugin === foreign.path.plugin && entry.field === foreign.path.field))
1031
+ continue;
1032
+ const source = sources[key];
1033
+ const state = fieldStates[key];
1034
+ const configIssue = { type: 'invalid-config', code: 'valueRefSource', key, source,
1035
+ message: `Config "${key}" depends on invalid config "${foreign.path.plugin}/${foreign.path.field}". Fix the dependency before using this field.` };
1036
+ if (state?.invalidOverride?.issues.some((issue) => issue.code === configIssue.code && issue.message === configIssue.message))
1037
+ continue;
1038
+ delete values[key];
1039
+ delete redactedValues[key];
1040
+ if (source === 'missing')
1041
+ missingReferenceIssues.push(configIssue);
1042
+ else
1043
+ fieldStates[key] = { invalidOverride: { source, issues: [...(state?.invalidOverride?.issues ?? []), configIssue] },
1044
+ ...(state?.fallback ? { fallback: state.fallback } : {}) };
1045
+ }
1046
+ }
1047
+ }
1048
+ // Consumers must retain dependency failures after invalid source values are omitted.
1049
+ const invalidKeys = new Set([
1050
+ ...Object.entries(fieldStates).filter(([, state]) => state.invalidOverride !== undefined).map(([key]) => key),
1051
+ ...missingReferenceIssues.map((issue) => issue.key),
1052
+ ]);
1053
+ for (const key of schemaKeys) {
1054
+ if (invalidKeys.has(key))
1055
+ continue;
1056
+ const dependency = getPluginConfigDependencyKeys(definition, [key])
1057
+ .find((dependencyKey) => dependencyKey !== key && invalidKeys.has(dependencyKey));
1058
+ if (dependency === undefined)
1059
+ continue;
1060
+ const source = sources[key];
1061
+ const configIssue = {
1062
+ type: 'invalid-config', code: 'valueRefSource', key, source,
1063
+ message: `Config "${key}" depends on invalid config "${dependency}". Fix the dependency before using this field.`,
1064
+ };
1065
+ delete values[key];
1066
+ delete redactedValues[key];
1067
+ if (source === 'missing') {
1068
+ missingReferenceIssues.push(configIssue);
1069
+ }
1070
+ else {
1071
+ const state = fieldStates[key];
1072
+ fieldStates[key] = {
1073
+ invalidOverride: { source, issues: [configIssue] },
1074
+ ...(state?.fallback ? { fallback: state.fallback } : {}),
1075
+ };
1076
+ }
1077
+ }
1078
+ const issues = [
1079
+ ...Object.values(fieldStates).flatMap((state) => state.invalidOverride?.issues ?? []),
1080
+ ...dangerousKeyIssues,
1081
+ ...missingReferenceIssues,
1082
+ ];
1083
+ for (const [key, field] of Object.entries(schema)) {
1084
+ if (field.required && values[key] === undefined && !fieldStates[key]?.invalidOverride) {
1030
1085
  issues.push({
1031
1086
  type: 'missing-required',
1032
1087
  key,
@@ -1037,650 +1092,204 @@ export async function resolveEffectivePluginConfig(options) {
1037
1092
  }
1038
1093
  return {
1039
1094
  pluginName,
1040
- projectRoot,
1095
+ platform: options.platform,
1096
+ context: options.context ?? options.targetScope ?? 'user',
1097
+ definition: definition,
1098
+ projectRoot: options.projectRoot,
1041
1099
  values,
1042
1100
  redactedValues,
1043
1101
  sources,
1102
+ fieldStates,
1044
1103
  issues,
1104
+ unsupportedLayerOverrides,
1045
1105
  ignoredUnknownKeys,
1046
1106
  schema,
1047
1107
  stores: {
1048
1108
  user: userStore,
1049
- project: projectStore,
1050
- projectLocal: projectLocalStore,
1051
1109
  },
1110
+ ...(options.referenceContext ? { referenceContext: options.referenceContext } : {}),
1111
+ ...(options.referenceEvidence ? { referenceEvidence: options.referenceEvidence } : {}),
1052
1112
  };
1053
1113
  }
1114
+ function ownStoreValue(values, key) {
1115
+ return Object.hasOwn(values, key) ? values[key] : undefined;
1116
+ }
1117
+ /** Check cross-field relations before saving one complete layer candidate. */
1118
+ export async function assertPluginConfigMutationCandidate(options) {
1119
+ const user = await readPluginConfigStore({ ...options, scope: 'user' });
1120
+ assertReadyPluginConfigStore(user);
1121
+ const values = { ...user.values };
1122
+ for (const key of options.removeKeys)
1123
+ delete values[key];
1124
+ for (const [key, value] of Object.entries(options.updates))
1125
+ values[key] = value;
1126
+ const candidate = replacePluginConfigStoreLayer(user, values, options.platform);
1127
+ const profiles = options.platform ? [options.platform] : [undefined, ...PLATFORM_TARGETS];
1128
+ for (const platform of profiles) {
1129
+ const references = pluginConfigHasExternalReferences(options.manifest)
1130
+ ? await resolvePluginConfigReferenceContext({ ...options, platform, plugins: options.referencePlugins }) : undefined;
1131
+ const resolve = (store) => resolveEffectivePluginConfigFromStores({ ...options, platform,
1132
+ targetScope: options.scope, projectRoot: options.scope === 'project' ? resolveAwProjectRoot(options.cwd) : '', stores: { user: store }, referenceContext: references?.context });
1133
+ const [before, after] = await Promise.all([resolve(user), resolve(candidate)]);
1134
+ const existing = new Set(before.issues.map((issue) => `${issue.key}\0${issue.code}\0${issue.message}`));
1135
+ const editedKeys = new Set([...Object.keys(options.updates), ...options.removeKeys]);
1136
+ const issues = after.issues.filter((issue) => (editedKeys.has(issue.key) && Object.hasOwn(options.updates, issue.key))
1137
+ || !existing.has(`${issue.key}\0${issue.code}\0${issue.message}`));
1138
+ if (issues.length)
1139
+ throw Object.assign(new Error(`configReferenceInvalid: ${platform ?? 'common'}: ${issues.map((issue) => issue.message).join(' ')}`), { code: 'configReferenceInvalid' });
1140
+ }
1141
+ }
1054
1142
  export async function coercePluginConfigUpdates(options) {
1055
- const projectRoot = resolveAwProjectRoot(options.cwd);
1056
1143
  const output = {};
1057
1144
  for (const [key, value] of Object.entries(options.updates)) {
1058
1145
  const field = options.schema[key];
1059
1146
  if (!field) {
1060
1147
  throw new Error(`Unknown config key "${key}".`);
1061
1148
  }
1062
- output[key] = await coercePluginConfigValue({
1149
+ const coerced = await coercePluginConfigValue({
1063
1150
  key,
1064
1151
  field,
1065
1152
  value,
1066
- projectRoot,
1067
1153
  });
1154
+ output[key] = coerced;
1068
1155
  }
1069
1156
  return output;
1070
1157
  }
1071
- function createProjectArtifactBoundaryIssue(options) {
1072
- if (options.reason === 'pathTypeDefault') {
1073
- return {
1074
- key: options.key,
1075
- source: options.source,
1076
- reason: options.reason,
1077
- message: `Config "${options.key}" uses file/directory default value, ` +
1078
- 'which cannot participate in repo-visible project artifact truth.',
1079
- };
1080
- }
1081
- if (options.reason === 'pathTypeRequired') {
1082
- return {
1083
- key: options.key,
1084
- source: options.source,
1085
- reason: options.reason,
1086
- message: `Config "${options.key}" is a required file/directory key, ` +
1087
- 'which is not portable enough for repo-visible project artifacts.',
1088
- };
1089
- }
1090
- if (options.reason === 'sharedPathValue') {
1091
- return {
1092
- key: options.key,
1093
- source: options.source,
1094
- reason: options.reason,
1095
- message: `Config "${options.key}" is stored in project shared config as a file/directory path. ` +
1096
- 'Use user or project local config for machine-local paths.',
1097
- };
1098
- }
1099
- return {
1100
- key: options.key,
1101
- source: options.source,
1102
- reason: options.reason,
1103
- message: `Config "${options.key}" is declared as a refresh key for repo-visible project artifacts, ` +
1104
- 'but file/directory config is machine-local and cannot drive shared artifact refresh.',
1105
- };
1106
- }
1107
- export function collectProjectArtifactConfigBoundaryIssues(options) {
1108
- const issues = [];
1109
- const refreshKeySet = new Set(options.refreshKeys ?? []);
1110
- for (const [key, field] of Object.entries(options.schema)) {
1111
- if (!isPathTypeField(field)) {
1112
- continue;
1113
- }
1114
- if (field.default !== undefined) {
1115
- issues.push(createProjectArtifactBoundaryIssue({
1116
- key,
1117
- source: 'default',
1118
- reason: 'pathTypeDefault',
1119
- }));
1120
- }
1121
- if (field.required) {
1122
- issues.push(createProjectArtifactBoundaryIssue({
1123
- key,
1124
- source: 'missing',
1125
- reason: 'pathTypeRequired',
1126
- }));
1127
- }
1128
- if (options.sharedEntries && Object.hasOwn(options.sharedEntries, key)) {
1129
- issues.push(createProjectArtifactBoundaryIssue({
1130
- key,
1131
- source: 'project',
1132
- reason: 'sharedPathValue',
1133
- }));
1134
- }
1135
- if (refreshKeySet.has(key)) {
1136
- issues.push(createProjectArtifactBoundaryIssue({
1137
- key,
1138
- source: 'project',
1139
- reason: 'pathTypeRefreshKey',
1140
- }));
1141
- }
1142
- }
1143
- return issues;
1144
- }
1145
1158
  export async function resolveProjectArtifactRenderConfig(options) {
1146
- const pluginName = assertSafePluginConfigSegment(options.pluginName ?? options.manifest.name);
1147
- const schema = options.manifest.config?.schema;
1148
- const projectRoot = resolveAwProjectRoot(options.cwd);
1149
- const [userStore, projectStore, projectLocalStore] = await Promise.all([
1150
- readPluginConfigStore({
1151
- sourceId: options.sourceId,
1152
- sourceIdentity: options.sourceIdentity,
1153
- pluginName,
1154
- scope: 'user',
1155
- cwd: options.cwd,
1156
- env: options.env,
1157
- }),
1158
- readPluginConfigStore({
1159
- sourceId: options.sourceId,
1160
- sourceIdentity: options.sourceIdentity,
1161
- pluginName,
1162
- scope: 'project',
1163
- cwd: options.cwd,
1164
- env: options.env,
1165
- }),
1166
- readPluginConfigStore({
1167
- sourceId: options.sourceId,
1168
- sourceIdentity: options.sourceIdentity,
1169
- pluginName,
1170
- scope: 'project',
1171
- cwd: options.cwd,
1172
- env: options.env,
1173
- projectLayer: 'local',
1174
- }),
1175
- ]);
1176
- if (!schema) {
1159
+ if (!options.manifest.config?.fields) {
1160
+ const pluginName = assertSafePluginConfigSegment(options.pluginName ?? options.manifest.name);
1161
+ const [userStore] = await Promise.all([
1162
+ readPluginConfigStore({
1163
+ sourceId: options.sourceId,
1164
+ sourceIdentity: options.sourceIdentity,
1165
+ logicalIdentity: options.logicalIdentity,
1166
+ pluginName,
1167
+ scope: 'user',
1168
+ cwd: options.cwd,
1169
+ env: options.env,
1170
+ }),
1171
+ ]);
1172
+ assertReadyPluginConfigStore(userStore);
1177
1173
  return {
1178
1174
  pluginName,
1179
- projectRoot,
1175
+ projectRoot: resolveAwProjectRoot(options.cwd),
1180
1176
  values: {},
1181
1177
  sources: {},
1182
1178
  issues: [],
1179
+ unsupportedLayerOverrides: [],
1183
1180
  ignoredUnknownKeys: [],
1184
- boundaryIssues: [],
1185
1181
  schema: {},
1186
- stores: {
1187
- user: userStore,
1188
- project: projectStore,
1189
- projectLocal: projectLocalStore,
1190
- },
1182
+ stores: { user: userStore },
1191
1183
  };
1192
1184
  }
1193
- const values = {};
1194
- const sources = {};
1195
- const invalidIssues = new Map();
1196
- const ignoredUnknownKeys = [];
1197
- const schemaKeys = new Set(Object.keys(schema));
1198
- const boundaryIssues = collectProjectArtifactConfigBoundaryIssues({
1199
- schema,
1200
- sharedEntries: projectStore.values,
1201
- refreshKeys: options.refreshKeys,
1202
- });
1203
- for (const key of Object.keys(schema)) {
1204
- sources[key] = 'missing';
1205
- }
1206
- const projectPlainEntries = getStoreEntries(projectStore.values);
1207
- const userPlainEntries = getStoreEntries(userStore.values);
1208
- const projectLocalPlainEntries = getStoreEntries(projectLocalStore.values);
1209
- for (const key of Object.keys(projectPlainEntries)) {
1210
- if (!schemaKeys.has(key)) {
1211
- ignoredUnknownKeys.push({ scope: 'project', projectLayer: 'shared', source: 'project', key });
1212
- }
1213
- }
1214
- for (const key of Object.keys(userPlainEntries)) {
1215
- if (!schemaKeys.has(key)) {
1216
- ignoredUnknownKeys.push({ scope: 'user', projectLayer: 'shared', source: 'user', key });
1217
- }
1218
- }
1219
- for (const key of Object.keys(projectLocalPlainEntries)) {
1220
- if (!schemaKeys.has(key)) {
1221
- ignoredUnknownKeys.push({ scope: 'project', projectLayer: 'local', source: 'projectLocal', key });
1222
- }
1223
- }
1224
- for (const [key, field] of Object.entries(schema)) {
1225
- if (!isPathTypeField(field) && field.default !== undefined) {
1226
- await applyConfigLayer({
1227
- values,
1228
- redactedValues: {},
1229
- sources,
1230
- invalidIssues,
1231
- schema: { [key]: field },
1232
- entries: { [key]: field.default },
1233
- source: 'default',
1234
- projectRoot,
1235
- });
1236
- }
1237
- }
1238
- const sharedSchema = Object.fromEntries(Object.entries(schema).filter(([, field]) => !isPathTypeField(field)));
1239
- await applyConfigLayer({
1240
- values,
1241
- redactedValues: {},
1242
- sources,
1243
- invalidIssues,
1244
- schema: sharedSchema,
1245
- entries: projectPlainEntries,
1246
- source: 'project',
1247
- projectRoot,
1185
+ const effective = await resolveEffectivePluginConfig({
1186
+ ...options,
1187
+ targetScope: 'project',
1248
1188
  });
1249
- const issues = [
1250
- ...invalidIssues.values(),
1251
- ...boundaryIssues.map((issue) => ({
1252
- type: 'invalid-config',
1253
- key: issue.key,
1254
- source: issue.source,
1255
- message: issue.message,
1256
- })),
1257
- ];
1258
- for (const [key, field] of Object.entries(schema)) {
1259
- if (isPathTypeField(field)) {
1260
- continue;
1261
- }
1262
- if (field.required && values[key] === undefined) {
1263
- issues.push({
1264
- type: 'missing-required',
1265
- key,
1266
- source: sources[key],
1267
- message: `Config "${key}" is required.`,
1268
- });
1269
- }
1270
- }
1271
- return {
1272
- pluginName,
1273
- projectRoot,
1274
- values,
1275
- sources,
1276
- issues,
1277
- ignoredUnknownKeys,
1278
- boundaryIssues,
1279
- schema,
1280
- stores: {
1281
- user: userStore,
1282
- project: projectStore,
1283
- projectLocal: projectLocalStore,
1284
- },
1285
- };
1286
- }
1287
- export async function resolveProjectLocalPluginConfigView(options) {
1288
- const effective = await resolveEffectivePluginConfig(options);
1289
- const artifactConfig = await resolveProjectArtifactRenderConfig(options);
1290
- const values = {};
1291
- const redactedValues = {};
1292
- const sources = {};
1293
- const issues = [];
1294
- for (const [key, field] of Object.entries(effective.schema)) {
1295
- sources[key] = 'missing';
1296
- const localPlainEntries = getStoreEntries(effective.stores.projectLocal.values);
1297
- if (!Object.hasOwn(localPlainEntries, key)) {
1298
- continue;
1299
- }
1300
- sources[key] = 'projectLocal';
1301
- try {
1302
- const coerced = await coercePluginConfigValue({
1303
- key,
1304
- field,
1305
- value: localPlainEntries[key],
1306
- projectRoot: effective.projectRoot,
1307
- });
1308
- values[key] = coerced;
1309
- redactedValues[key] = redactValue(field, coerced);
1310
- }
1311
- catch (error) {
1312
- issues.push({
1313
- type: 'invalid-config',
1314
- key,
1315
- source: 'projectLocal',
1316
- message: error instanceof Error ? error.message : String(error),
1317
- });
1318
- }
1319
- }
1320
- return {
1321
- pluginName: effective.pluginName,
1322
- projectRoot: effective.projectRoot,
1323
- schema: effective.schema,
1324
- localStore: effective.stores.projectLocal,
1325
- values,
1326
- redactedValues,
1327
- sources,
1328
- issues,
1329
- ignoredUnknownKeys: effective.ignoredUnknownKeys.filter((entry) => entry.source === 'projectLocal'),
1330
- repoVisibleArtifactConfig: {
1331
- values: artifactConfig.values,
1332
- sources: artifactConfig.sources,
1333
- issues: artifactConfig.issues,
1334
- boundaryIssues: artifactConfig.boundaryIssues,
1335
- },
1336
- };
1337
- }
1338
- async function resolveRedactedLayerValue(options) {
1339
- try {
1340
- const coerced = await coercePluginConfigValue({
1341
- key: options.key,
1342
- field: options.field,
1343
- value: options.value,
1344
- projectRoot: options.projectRoot,
1345
- });
1346
- return {
1347
- value: redactValue(options.field, coerced),
1348
- };
1349
- }
1350
- catch (error) {
1351
- return {
1352
- issue: {
1353
- type: 'invalid-config',
1354
- key: options.key,
1355
- source: options.source,
1356
- message: error instanceof Error ? error.message : String(error),
1357
- },
1358
- };
1359
- }
1360
- }
1361
- export async function resolveProjectScopedPluginConfigView(options) {
1362
- const effective = await resolveEffectivePluginConfig(options);
1363
- const artifactConfig = await resolveProjectArtifactRenderConfig(options);
1364
- const entries = {};
1365
- for (const [key, field] of Object.entries(effective.schema)) {
1366
- const entry = {
1367
- key,
1368
- effectiveValue: effective.redactedValues[key],
1369
- effectiveSource: effective.sources[key] ?? 'missing',
1370
- repoVisibleArtifactValue: artifactConfig.values[key] === undefined
1371
- ? undefined
1372
- : redactValue(field, artifactConfig.values[key]),
1373
- repoVisibleArtifactSource: artifactConfig.sources[key] ?? 'missing',
1374
- repoVisibleArtifactUsesSharedTruth: true,
1375
- };
1376
- if (field.default !== undefined) {
1377
- const resolvedDefault = await resolveRedactedLayerValue({
1378
- key,
1379
- field,
1380
- projectRoot: effective.projectRoot,
1381
- source: 'default',
1382
- value: field.default,
1383
- });
1384
- if (resolvedDefault.value !== undefined) {
1385
- entry.defaultValue = resolvedDefault.value;
1386
- }
1387
- }
1388
- const userPlainEntries = getStoreEntries(effective.stores.user.values);
1389
- if (Object.hasOwn(userPlainEntries, key)) {
1390
- const resolvedUser = await resolveRedactedLayerValue({
1391
- key,
1392
- field,
1393
- projectRoot: effective.projectRoot,
1394
- source: 'user',
1395
- value: userPlainEntries[key],
1396
- });
1397
- if (resolvedUser.value !== undefined) {
1398
- entry.userValue = resolvedUser.value;
1399
- }
1400
- }
1401
- const projectPlainEntries = getStoreEntries(effective.stores.project.values);
1402
- if (Object.hasOwn(projectPlainEntries, key)) {
1403
- const resolvedProject = await resolveRedactedLayerValue({
1404
- key,
1405
- field,
1406
- projectRoot: effective.projectRoot,
1407
- source: 'project',
1408
- value: projectPlainEntries[key],
1409
- });
1410
- if (resolvedProject.value !== undefined) {
1411
- entry.projectSharedValue = resolvedProject.value;
1412
- }
1413
- }
1414
- const localPlainEntries = getStoreEntries(effective.stores.projectLocal.values);
1415
- if (Object.hasOwn(localPlainEntries, key)) {
1416
- const resolvedLocal = await resolveRedactedLayerValue({
1417
- key,
1418
- field,
1419
- projectRoot: effective.projectRoot,
1420
- source: 'projectLocal',
1421
- value: localPlainEntries[key],
1422
- });
1423
- if (resolvedLocal.value !== undefined) {
1424
- entry.projectLocalValue = resolvedLocal.value;
1425
- }
1426
- }
1427
- entries[key] = entry;
1428
- }
1429
1189
  return {
1430
1190
  pluginName: effective.pluginName,
1431
1191
  projectRoot: effective.projectRoot,
1432
- schema: effective.schema,
1433
- stores: effective.stores,
1434
- redactedValues: effective.redactedValues,
1192
+ values: effective.values,
1435
1193
  sources: effective.sources,
1436
- entries,
1437
1194
  issues: effective.issues,
1195
+ unsupportedLayerOverrides: effective.unsupportedLayerOverrides,
1438
1196
  ignoredUnknownKeys: effective.ignoredUnknownKeys,
1439
- repoVisibleArtifactConfig: {
1440
- values: artifactConfig.values,
1441
- sources: artifactConfig.sources,
1442
- issues: artifactConfig.issues,
1443
- boundaryIssues: artifactConfig.boundaryIssues,
1197
+ schema: effective.schema,
1198
+ stores: {
1199
+ user: effective.stores.user,
1444
1200
  },
1445
1201
  };
1446
1202
  }
1447
1203
  function toConfigSourceLayer(source) {
1448
- if (source === 'default') {
1449
- return 'default';
1450
- }
1451
- if (source === 'user') {
1452
- return 'user';
1453
- }
1454
- if (source === 'project') {
1455
- return 'project';
1456
- }
1457
- if (source === 'projectLocal') {
1458
- return 'local';
1459
- }
1460
- return null;
1204
+ return source === undefined || source === 'missing' ? null : source;
1205
+ }
1206
+ function configFieldProjection(options) {
1207
+ const source = options.source ?? 'missing';
1208
+ const issues = options.issues ?? [];
1209
+ const presetSensitive = options.field.sensitive === true
1210
+ || (options.field.type === 'object'
1211
+ && (Object.values(options.field.properties ?? {}).some((child) => child.sensitive === true)
1212
+ || (options.field.additionalProperties !== false
1213
+ && options.field.additionalProperties?.sensitive === true)));
1214
+ return {
1215
+ value: options.value === undefined ? null : redactValue(options.field, options.value),
1216
+ source,
1217
+ matchedPreset: options.value === undefined || presetSensitive
1218
+ ? null
1219
+ : matchPluginConfigPreset(options.field, options.value)?.id ?? null,
1220
+ valid: issues.length === 0,
1221
+ issues,
1222
+ };
1461
1223
  }
1462
1224
  async function buildManifestFieldEntries(options) {
1463
- const schema = options.plugin.manifest.config?.schema;
1464
- if (!schema) {
1465
- return [];
1466
- }
1467
- const projectRoot = resolveAwProjectRoot(options.cwd);
1468
- const [userStore, projectStore, projectLocalStore] = await Promise.all([
1469
- readPluginConfigStore({
1470
- sourceId: options.plugin.sourceId,
1471
- sourceIdentity: options.plugin.sourceIdentity,
1472
- pluginName: options.plugin.manifest.name,
1473
- scope: 'user',
1474
- cwd: options.cwd,
1475
- env: options.env,
1476
- }),
1477
- readPluginConfigStore({
1478
- sourceId: options.plugin.sourceId,
1479
- sourceIdentity: options.plugin.sourceIdentity,
1480
- pluginName: options.plugin.manifest.name,
1481
- scope: 'project',
1482
- projectLayer: 'shared',
1483
- cwd: options.cwd,
1484
- env: options.env,
1485
- }),
1486
- readPluginConfigStore({
1487
- sourceId: options.plugin.sourceId,
1488
- sourceIdentity: options.plugin.sourceIdentity,
1489
- pluginName: options.plugin.manifest.name,
1490
- scope: 'project',
1491
- projectLayer: 'local',
1492
- cwd: options.cwd,
1493
- env: options.env,
1494
- }),
1495
- ]);
1496
- const userPlainEntries = getStoreEntries(userStore.values);
1497
- const projectPlainEntries = getStoreEntries(projectStore.values);
1498
- const localPlainEntries = getStoreEntries(projectLocalStore.values);
1499
1225
  const effective = await resolveEffectivePluginConfig({
1500
1226
  sourceId: options.plugin.sourceId,
1501
1227
  sourceIdentity: options.plugin.sourceIdentity,
1502
- pluginName: options.plugin.manifest.name,
1228
+ logicalIdentity: options.plugin.catalogLogicalIdentity,
1503
1229
  manifest: options.plugin.manifest,
1230
+ platform: options.platform,
1231
+ targetScope: options.context ?? (options.scope === 'project' ? 'project' : 'user'),
1504
1232
  cwd: options.cwd,
1505
1233
  env: options.env,
1506
1234
  });
1507
- const effectiveFieldState = (key) => {
1508
- const field = schema[key];
1509
- const source = effective.sources[key];
1510
- const sourceLayer = toConfigSourceLayer(source);
1511
- if (source === undefined || source === 'missing') {
1512
- return { valueState: 'default', effectiveValue: null, sourceLayer: null };
1235
+ const stored = pluginConfigStoreForProfile(effective.stores.user, options.platform).values;
1236
+ const fields = await Promise.all(Object.entries(effective.schema).map(async ([key, field]) => {
1237
+ const state = effective.fieldStates[key];
1238
+ const source = effective.sources[key] ?? 'missing';
1239
+ const issues = effective.issues.filter((issue) => issue.key === key);
1240
+ const hasStored = Object.hasOwn(stored, key);
1241
+ const storedSourceLayer = options.platform ? 'platform' : 'common';
1242
+ let fallback;
1243
+ if (hasStored) {
1244
+ const inherited = { ...stored };
1245
+ delete inherited[key];
1246
+ const withoutOverride = await resolveEffectivePluginConfigFromStores({
1247
+ manifest: options.plugin.manifest,
1248
+ platform: options.platform,
1249
+ projectRoot: effective.projectRoot,
1250
+ stores: { user: replacePluginConfigStoreLayer(effective.stores.user, inherited, options.platform) },
1251
+ referenceContext: effective.referenceContext,
1252
+ });
1253
+ const fallbackIssues = withoutOverride.issues.filter((issue) => issue.key === key);
1254
+ const fallbackSource = withoutOverride.sources[key];
1255
+ fallback = fallbackSource === 'missing' || fallbackSource === undefined
1256
+ ? { state: 'missing' }
1257
+ : fallbackIssues.length
1258
+ ? { state: 'invalid', sourceLayer: fallbackSource, issues: fallbackIssues }
1259
+ : { state: 'valid', sourceLayer: fallbackSource, effectiveValue: withoutOverride.redactedValues[key] };
1513
1260
  }
1514
- const issue = effective.issues.find((entry) => entry.key === key && entry.source === source);
1515
1261
  return {
1516
- valueState: issue ? 'invalid' : source === 'default' ? 'default' : 'configured',
1517
- effectiveValue: issue
1518
- ? null
1519
- : isPathTypeField(field) && effective.redactedValues[key] !== undefined
1520
- ? '[redacted]'
1521
- : effective.redactedValues[key] ?? null,
1522
- sourceLayer,
1523
- };
1524
- };
1525
- const fields = [];
1526
- for (const [key, field] of Object.entries(schema)) {
1527
- const base = {
1528
1262
  key,
1529
1263
  title: field.title ?? key,
1530
1264
  kind: 'manifest',
1531
1265
  reserved: false,
1532
1266
  writable: true,
1533
- valueState: 'default',
1534
- effectiveValue: null,
1535
- sourceLayer: null,
1267
+ canSet: true,
1268
+ canUnset: hasStored,
1269
+ valueState: issues.length ? 'invalid' : source === 'default' || source === 'missing' ? 'default' : 'configured',
1270
+ effectiveValue: effective.redactedValues[key] ?? null,
1271
+ sourceLayer: toConfigSourceLayer(source),
1272
+ ...(hasStored ? { storedSourceLayer, ...(validateCorePluginConfigValue(field, stored[key], key).length
1273
+ ? {} : { storedValue: redactValue(field, stored[key]) }) } : {}),
1274
+ ...(state?.invalidOverride ? { invalidOverride: { sourceLayer: state.invalidOverride.source, issues: state.invalidOverride.issues } } : {}),
1275
+ ...(fallback ? { fallback } : {}),
1276
+ ...configFieldProjection({ field, value: effective.values[key], source, issues }),
1536
1277
  };
1537
- if (options.scope === 'user') {
1538
- if (Object.hasOwn(userPlainEntries, key)) {
1539
- try {
1540
- const value = await coercePluginConfigValue({
1541
- key,
1542
- field,
1543
- value: userPlainEntries[key],
1544
- projectRoot,
1545
- });
1546
- fields.push({
1547
- ...base,
1548
- valueState: 'configured',
1549
- effectiveValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1550
- sourceLayer: 'user',
1551
- storedValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1552
- storedSourceLayer: 'user',
1553
- });
1554
- }
1555
- catch {
1556
- fields.push({
1557
- ...base,
1558
- valueState: 'invalid',
1559
- sourceLayer: 'user',
1560
- storedSourceLayer: 'user',
1561
- });
1562
- }
1563
- continue;
1564
- }
1565
- if (field.default !== undefined) {
1566
- try {
1567
- const value = await coercePluginConfigValue({
1568
- key,
1569
- field,
1570
- value: field.default,
1571
- projectRoot,
1572
- });
1573
- fields.push({
1574
- ...base,
1575
- effectiveValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1576
- sourceLayer: 'default',
1577
- });
1578
- }
1579
- catch {
1580
- fields.push({
1581
- ...base,
1582
- valueState: 'invalid',
1583
- sourceLayer: 'default',
1584
- });
1585
- }
1586
- continue;
1587
- }
1588
- fields.push(base);
1589
- continue;
1590
- }
1591
- if (options.projectLayer === 'local') {
1592
- if (Object.hasOwn(localPlainEntries, key)) {
1593
- try {
1594
- const value = await coercePluginConfigValue({
1595
- key,
1596
- field,
1597
- value: localPlainEntries[key],
1598
- projectRoot,
1599
- });
1600
- fields.push({
1601
- ...base,
1602
- valueState: 'configured',
1603
- effectiveValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1604
- sourceLayer: 'local',
1605
- storedValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1606
- storedSourceLayer: 'local',
1607
- });
1608
- }
1609
- catch {
1610
- fields.push({
1611
- ...base,
1612
- valueState: 'invalid',
1613
- sourceLayer: 'local',
1614
- storedSourceLayer: 'local',
1615
- });
1616
- }
1617
- }
1618
- else {
1619
- fields.push(base);
1620
- }
1621
- continue;
1622
- }
1623
- let storedProjectValue;
1624
- if (options.scope === 'project' && Object.hasOwn(projectPlainEntries, key)) {
1625
- try {
1626
- const value = await coercePluginConfigValue({
1627
- key,
1628
- field,
1629
- value: projectPlainEntries[key],
1630
- projectRoot,
1631
- });
1632
- storedProjectValue = {
1633
- storedValue: isPathTypeField(field) ? '[redacted]' : redactValue(field, value),
1634
- storedSourceLayer: 'project',
1635
- };
1636
- }
1637
- catch {
1638
- storedProjectValue = { storedSourceLayer: 'project' };
1639
- }
1640
- }
1641
- fields.push({ ...base, ...effectiveFieldState(key), ...storedProjectValue });
1278
+ }));
1279
+ for (const key of Object.keys(stored).filter((key) => !Object.hasOwn(effective.schema, key)).sort()) {
1280
+ const source = options.platform ? 'platform' : 'common';
1281
+ fields.push({ key, title: key, kind: 'manifest', reserved: false, writable: false, canSet: false, canUnset: true,
1282
+ valueState: 'configured', effectiveValue: '[redacted]', sourceLayer: source, storedSourceLayer: source,
1283
+ value: '[redacted]', source, matchedPreset: null, valid: false, issues: [] });
1642
1284
  }
1643
1285
  return fields;
1644
1286
  }
1645
1287
  async function buildLegacyStoreFieldEntries(options) {
1646
- const locations = options.scope === 'effective'
1647
- ? [
1648
- { scope: 'user', projectLayer: 'shared', sourceLayer: 'user' },
1649
- { scope: 'project', projectLayer: 'shared', sourceLayer: 'project' },
1650
- { scope: 'project', projectLayer: 'local', sourceLayer: 'local' },
1651
- ]
1652
- : [{
1653
- scope: options.scope,
1654
- projectLayer: options.projectLayer,
1655
- sourceLayer: options.scope === 'user'
1656
- ? 'user'
1657
- : options.projectLayer === 'local' ? 'local' : 'project',
1658
- }];
1659
- const fields = new Map();
1660
- for (const location of locations) {
1661
- const store = await readPluginConfigStore({
1662
- sourceId: options.sourceId,
1663
- sourceIdentity: options.sourceIdentity,
1664
- pluginName: options.pluginName,
1665
- scope: location.scope,
1666
- ...(location.scope === 'project' ? { projectLayer: location.projectLayer } : {}),
1667
- cwd: options.cwd,
1668
- env: options.env,
1669
- });
1670
- for (const key of Object.keys(store.values)) {
1671
- fields.set(key, {
1672
- key,
1673
- title: key,
1674
- kind: 'manifest',
1675
- reserved: false,
1676
- writable: false,
1677
- valueState: 'configured',
1678
- effectiveValue: '[redacted]',
1679
- sourceLayer: location.sourceLayer,
1680
- });
1681
- }
1682
- }
1683
- return [...fields.values()].sort((left, right) => left.key.localeCompare(right.key));
1288
+ const store = await readPluginConfigStore({ ...options, scope: 'user' });
1289
+ const source = options.platform ? 'platform' : 'common';
1290
+ return Object.keys(store.values).sort().map((key) => ({ key, title: key, kind: 'manifest', reserved: false,
1291
+ writable: false, canSet: false, canUnset: true, valueState: 'configured', effectiveValue: '[redacted]',
1292
+ sourceLayer: source, value: '[redacted]', source, matchedPreset: null, valid: true, issues: [] }));
1684
1293
  }
1685
1294
  export async function resolvePluginConfigSchemaAccess(options) {
1686
1295
  const pluginName = assertSafePluginConfigSegment(options.pluginName);
@@ -1696,42 +1305,50 @@ export async function resolvePluginConfigSchemaAccess(options) {
1696
1305
  return {
1697
1306
  pluginName,
1698
1307
  plugin: options.currentPlugin,
1699
- schema: createConfigSchemaEvidenceFromCurrentCatalog(options.currentPlugin, await calculateConfigSchemaManifestDigestForPlugin(options.currentPlugin)),
1308
+ schema: createConfigSchemaEvidenceFromCurrentCatalog(options.currentPlugin, await calculateConfigSchemaManifestDigestForPlugin(options.currentPlugin), options.platform),
1700
1309
  };
1701
1310
  }
1702
1311
  export async function resolveConfigRead(options) {
1312
+ if (options.context)
1313
+ await resolveWorkContext({ cwd: options.cwd, context: options.context });
1703
1314
  const pluginName = assertSafePluginConfigSegment(options.pluginName);
1704
1315
  const schemaAccess = await resolvePluginConfigSchemaAccess({
1705
1316
  pluginName,
1706
1317
  currentPlugin: options.plugin,
1707
1318
  currentPluginError: options.pluginError,
1319
+ platform: options.platform,
1708
1320
  scope: options.scope,
1709
- projectLayer: options.projectLayer,
1710
1321
  cwd: options.cwd,
1711
1322
  env: options.env,
1712
1323
  });
1713
1324
  const manifestFields = schemaAccess.plugin
1714
1325
  ? await buildManifestFieldEntries({
1715
1326
  plugin: schemaAccess.plugin,
1327
+ context: options.context,
1328
+ platform: options.platform,
1716
1329
  scope: options.scope,
1717
- projectLayer: options.projectLayer,
1718
1330
  cwd: options.cwd,
1719
1331
  env: options.env,
1720
1332
  })
1721
1333
  : await buildLegacyStoreFieldEntries({
1722
1334
  sourceId: options.sourceId,
1723
1335
  sourceIdentity: options.sourceIdentity,
1336
+ logicalIdentity: options.logicalIdentity,
1724
1337
  pluginName,
1725
1338
  scope: options.scope,
1726
- projectLayer: options.projectLayer,
1339
+ platform: options.platform,
1727
1340
  cwd: options.cwd,
1728
1341
  env: options.env,
1729
1342
  });
1730
1343
  return {
1731
1344
  pluginName,
1345
+ platform: options.platform,
1346
+ context: options.context ?? 'user',
1732
1347
  scope: options.scope,
1733
- projectLayer: options.projectLayer,
1734
1348
  ...(schemaAccess.schema ? { schema: schemaAccess.schema } : {}),
1349
+ ...(schemaAccess.plugin?.manifest.config?.fields
1350
+ ? { fieldDefinitions: selectPluginConfigProfile(schemaAccess.plugin.manifest.config, options.platform).fields }
1351
+ : {}),
1735
1352
  fields: manifestFields,
1736
1353
  };
1737
1354
  }
@@ -1745,67 +1362,100 @@ export function summarizeEffectivePluginConfig(config) {
1745
1362
  return {
1746
1363
  values: config.redactedValues,
1747
1364
  sources: config.sources,
1365
+ fieldStates: Object.fromEntries(Object.entries(config.fieldStates).map(([key, state]) => [key, {
1366
+ ...(state.effective ? {
1367
+ effective: { value: state.effective.redactedValue, source: state.effective.source },
1368
+ } : {}),
1369
+ ...(state.invalidOverride ? { invalidOverride: state.invalidOverride } : {}),
1370
+ ...(state.fallback ? {
1371
+ fallback: { value: state.fallback.redactedValue, source: state.fallback.source },
1372
+ } : {}),
1373
+ }])),
1748
1374
  issues: config.issues,
1749
1375
  ignoredUnknownKeys: config.ignoredUnknownKeys,
1750
1376
  };
1751
1377
  }
1752
- export function createPluginConfigSchemaIdentity(manifest) {
1378
+ export function createPluginConfigSchemaIdentity(manifest, platform) {
1753
1379
  const hash = crypto
1754
1380
  .createHash('sha256')
1755
1381
  .update(JSON.stringify({
1756
1382
  name: manifest.name,
1757
1383
  version: manifest.version,
1758
- config: manifest.config ?? null,
1384
+ platform: platform ?? null,
1385
+ config: manifest.config ? selectPluginConfigProfile(manifest.config, platform) : null,
1759
1386
  }))
1760
1387
  .digest('hex');
1761
1388
  return `${manifest.name}:${hash}`;
1762
1389
  }
1390
+ function cliConfigPromptEnumValues(field) {
1391
+ if (!field.choices)
1392
+ return undefined;
1393
+ const values = field.choices.presets
1394
+ .map((preset) => preset.value);
1395
+ if (field.type !== 'boolean') {
1396
+ return field.choices.allowCustom ? undefined : values;
1397
+ }
1398
+ if (field.choices.allowCustom) {
1399
+ for (const value of [true, false]) {
1400
+ if (!values.includes(value))
1401
+ values.push(value);
1402
+ }
1403
+ }
1404
+ return values;
1405
+ }
1763
1406
  export function toCliConfigPromptSchema(schema) {
1764
1407
  const promptSchema = {};
1765
1408
  for (const [key, field] of Object.entries(schema)) {
1409
+ if (field.type === 'object' || field.type === 'array')
1410
+ continue;
1766
1411
  promptSchema[key] = {
1767
- type: field.type === 'enum' ? 'string' : field.type,
1412
+ type: field.type,
1768
1413
  label: field.title ?? key,
1769
1414
  description: field.description,
1770
1415
  required: field.required,
1771
1416
  sensitive: field.sensitive,
1772
1417
  default: field.default,
1773
- enum: field.type === 'enum' ? field.values : undefined,
1774
- min: field.min,
1775
- max: field.max,
1418
+ enum: cliConfigPromptEnumValues(field),
1419
+ min: field.type === 'number' ? field.validation?.minimum : undefined,
1420
+ max: field.type === 'number' ? field.validation?.maximum : undefined,
1776
1421
  };
1777
1422
  }
1778
1423
  return promptSchema;
1779
1424
  }
1780
1425
  export function createPluginConfigFormModel(options) {
1781
- const schema = options.manifest.config?.schema;
1426
+ const schema = options.effective.schema;
1782
1427
  if (!schema) {
1783
- throw new Error(`Plugin "${options.pluginName ?? options.manifest.name}" does not declare an AW config schema.`);
1428
+ throw new PluginConfigSchemaResolutionError('configSchemaUnavailable', `Plugin "${options.pluginName ?? options.manifest.name}" does not declare an AW config schema.`);
1784
1429
  }
1785
1430
  const requiredKeys = [...new Set(options.effective.issues
1786
1431
  .filter((issue) => issue.type === 'missing-required' || issue.type === 'invalid-config')
1787
1432
  .map((issue) => issue.key))];
1433
+ const fields = Object.entries(schema).flatMap(([key, field]) => {
1434
+ if (field.type === 'object' || field.type === 'array')
1435
+ return [];
1436
+ return [{
1437
+ key,
1438
+ type: field.type,
1439
+ label: field.title ?? key,
1440
+ description: field.description,
1441
+ required: field.required === true,
1442
+ sensitive: field.sensitive === true,
1443
+ defaultValue: field.default,
1444
+ enumValues: cliConfigPromptEnumValues(field),
1445
+ min: field.type === 'number' ? field.validation?.minimum : undefined,
1446
+ max: field.type === 'number' ? field.validation?.maximum : undefined,
1447
+ configured: options.effective.values[key] !== undefined,
1448
+ currentValue: field.sensitive
1449
+ ? undefined
1450
+ : options.effective.values[key],
1451
+ }];
1452
+ });
1788
1453
  return {
1789
1454
  pluginName: options.pluginName ?? options.manifest.name,
1790
- allowedScopes: options.allowedScopes ?? ['user', 'project'],
1791
- initialScope: options.initialScope,
1455
+ allowedScopes: ['user'],
1456
+ initialScope: 'user',
1792
1457
  requiredKeys,
1793
- fields: Object.entries(schema).map(([key, field]) => ({
1794
- key,
1795
- type: field.type,
1796
- label: field.title ?? key,
1797
- description: field.description,
1798
- required: field.required === true,
1799
- sensitive: field.sensitive === true,
1800
- defaultValue: field.default,
1801
- enumValues: field.type === 'enum' ? field.values : undefined,
1802
- min: field.min,
1803
- max: field.max,
1804
- configured: options.effective.values[key] !== undefined,
1805
- currentValue: field.sensitive || isPathTypeField(field)
1806
- ? undefined
1807
- : options.effective.values[key],
1808
- })),
1458
+ fields,
1809
1459
  };
1810
1460
  }
1811
1461
  export function toCliConfigPromptOptions(model) {
@@ -1824,7 +1474,7 @@ export function toCliConfigPromptOptions(model) {
1824
1474
  schema: Object.fromEntries(model.fields.map((field) => [
1825
1475
  field.key,
1826
1476
  {
1827
- type: field.type === 'enum' ? 'string' : field.type,
1477
+ type: field.type,
1828
1478
  label: field.label,
1829
1479
  description: field.description,
1830
1480
  required: field.required,
@@ -1842,13 +1492,17 @@ export function toCliConfigPromptOptions(model) {
1842
1492
  requiredKeys: [...model.requiredKeys],
1843
1493
  };
1844
1494
  }
1845
- function formatRequiredConfigSetCommands(pluginName, issues, defaultScope) {
1495
+ export function formatPluginConfigSetRecoveryCommand(pluginName, key, field, context, platform) {
1496
+ const command = `aw plugin config set ${pluginName} ${key} --context ${context}`
1497
+ + (platform ? ` --platform ${platform}` : '');
1498
+ return field.sensitive === true ? `${command} --value-stdin` : `${command} --value-json '<json>'`;
1499
+ }
1500
+ function formatRequiredConfigSetCommands(pluginName, issues, context, schema, platform) {
1846
1501
  const commands = new Set();
1847
1502
  for (const issue of issues) {
1848
- const scope = issue.source === 'user' || issue.source === 'project'
1849
- ? issue.source
1850
- : defaultScope;
1851
- commands.add(`aw config set ${pluginName} ${issue.key} <value> -s ${scope}`);
1503
+ const field = schema[issue.key];
1504
+ if (field)
1505
+ commands.add(formatPluginConfigSetRecoveryCommand(pluginName, issue.key, field, context, platform));
1852
1506
  }
1853
1507
  return [...commands].map((command) => `\`${command}\``).join(' 或 ');
1854
1508
  }
@@ -1861,21 +1515,23 @@ export async function preflightRequiredPluginConfigs(options) {
1861
1515
  };
1862
1516
  for (const target of options.targets) {
1863
1517
  const pluginName = target.pluginName ?? target.manifest.name;
1864
- const identity = target.schemaSourceIdentity ?? createPluginConfigSchemaIdentity(target.manifest);
1865
- const dedupeKey = `${pluginName}\0${identity}`;
1518
+ const identity = target.schemaSourceIdentity ?? createPluginConfigSchemaIdentity(target.manifest, target.platform);
1519
+ const dedupeKey = `${pluginName}\0${target.platform ?? 'common'}\0${identity}`;
1866
1520
  if (visited.has(dedupeKey)) {
1867
1521
  continue;
1868
1522
  }
1869
1523
  visited.add(dedupeKey);
1870
1524
  result.checked += 1;
1871
- if (!target.manifest.config?.schema) {
1525
+ if (!target.manifest.config?.fields) {
1872
1526
  continue;
1873
1527
  }
1874
- let effective = await resolveEffectivePluginConfig({
1528
+ const effective = await resolveEffectivePluginConfig({
1875
1529
  sourceId: target.sourceId,
1876
1530
  sourceIdentity: target.sourceIdentity,
1531
+ logicalIdentity: target.logicalIdentity,
1877
1532
  pluginName,
1878
1533
  manifest: target.manifest,
1534
+ platform: target.platform,
1879
1535
  cwd: options.cwd,
1880
1536
  env: options.context.env,
1881
1537
  });
@@ -1884,7 +1540,7 @@ export async function preflightRequiredPluginConfigs(options) {
1884
1540
  continue;
1885
1541
  }
1886
1542
  const details = blockingIssues.map((issue) => issue.key).join(', ');
1887
- const setCommands = formatRequiredConfigSetCommands(pluginName, blockingIssues, options.defaultScope);
1543
+ const setCommands = formatRequiredConfigSetCommands(target.sourceId ? `${target.sourceId}/${pluginName}` : pluginName, blockingIssues, options.defaultScope, effective.schema, target.platform);
1888
1544
  throw new Error(`${pluginName} requires valid AW config before install/upgrade: ${details}. ` +
1889
1545
  `Run ${setCommands}, or open \`aw\` to complete setup.`);
1890
1546
  }