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

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