@lesliechan721/aw 0.1.0-beta.3

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 (429) hide show
  1. package/dist/authoring/assets/aw-config.d.mts +2 -0
  2. package/dist/authoring/assets/aw-config.mjs +556 -0
  3. package/dist/authoring/assets/aw-config.mjs.map +1 -0
  4. package/dist/authoring/scripts/add-skill.d.mts +2 -0
  5. package/dist/authoring/scripts/add-skill.mjs +355 -0
  6. package/dist/authoring/scripts/add-skill.mjs.map +1 -0
  7. package/dist/authoring/scripts/check-plugin-versions.d.mts +2 -0
  8. package/dist/authoring/scripts/check-plugin-versions.mjs +5 -0
  9. package/dist/authoring/scripts/check-plugin-versions.mjs.map +1 -0
  10. package/dist/authoring/scripts/init-plugin.d.mts +2 -0
  11. package/dist/authoring/scripts/init-plugin.mjs +512 -0
  12. package/dist/authoring/scripts/init-plugin.mjs.map +1 -0
  13. package/dist/authoring/scripts/lib/javascript-import-scanner.d.mts +4 -0
  14. package/dist/authoring/scripts/lib/javascript-import-scanner.mjs +261 -0
  15. package/dist/authoring/scripts/lib/javascript-import-scanner.mjs.map +1 -0
  16. package/dist/authoring/scripts/lib/plugin-root.d.mts +26 -0
  17. package/dist/authoring/scripts/lib/plugin-root.mjs +125 -0
  18. package/dist/authoring/scripts/lib/plugin-root.mjs.map +1 -0
  19. package/dist/authoring/scripts/lib/plugin-version-check.d.mts +55 -0
  20. package/dist/authoring/scripts/lib/plugin-version-check.mjs +777 -0
  21. package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -0
  22. package/dist/authoring/scripts/lib/semver.d.mts +9 -0
  23. package/dist/authoring/scripts/lib/semver.mjs +63 -0
  24. package/dist/authoring/scripts/lib/semver.mjs.map +1 -0
  25. package/dist/authoring/scripts/lib/skill-scaffold.d.mts +124 -0
  26. package/dist/authoring/scripts/lib/skill-scaffold.mjs +374 -0
  27. package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -0
  28. package/dist/authoring/scripts/plugin-status.d.mts +2 -0
  29. package/dist/authoring/scripts/plugin-status.mjs +96 -0
  30. package/dist/authoring/scripts/plugin-status.mjs.map +1 -0
  31. package/dist/authoring/scripts/validate-plugin.d.mts +2 -0
  32. package/dist/authoring/scripts/validate-plugin.mjs +4442 -0
  33. package/dist/authoring/scripts/validate-plugin.mjs.map +1 -0
  34. package/dist/authoring/scripts/validate-skill.d.mts +2 -0
  35. package/dist/authoring/scripts/validate-skill.mjs +126 -0
  36. package/dist/authoring/scripts/validate-skill.mjs.map +1 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +8 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/scripts/aw-skill-eval-engine.d.ts +13 -0
  41. package/dist/scripts/aw-skill-eval-engine.js +31 -0
  42. package/dist/scripts/aw-skill-eval-engine.js.map +1 -0
  43. package/dist/scripts/bundle-plugins.d.ts +18 -0
  44. package/dist/scripts/bundle-plugins.js +123 -0
  45. package/dist/scripts/bundle-plugins.js.map +1 -0
  46. package/dist/scripts/codex-eval-app-server.d.ts +89 -0
  47. package/dist/scripts/codex-eval-app-server.js +1228 -0
  48. package/dist/scripts/codex-eval-app-server.js.map +1 -0
  49. package/dist/scripts/codex-eval-isolation.d.ts +61 -0
  50. package/dist/scripts/codex-eval-isolation.js +318 -0
  51. package/dist/scripts/codex-eval-isolation.js.map +1 -0
  52. package/dist/scripts/codex-eval-process-management.d.ts +8 -0
  53. package/dist/scripts/codex-eval-process-management.js +69 -0
  54. package/dist/scripts/codex-eval-process-management.js.map +1 -0
  55. package/dist/scripts/codex-eval-process-tree.d.ts +38 -0
  56. package/dist/scripts/codex-eval-process-tree.js +803 -0
  57. package/dist/scripts/codex-eval-process-tree.js.map +1 -0
  58. package/dist/scripts/codex-eval-runtime-config.d.ts +62 -0
  59. package/dist/scripts/codex-eval-runtime-config.js +843 -0
  60. package/dist/scripts/codex-eval-runtime-config.js.map +1 -0
  61. package/dist/scripts/codex-trigger-eval.d.ts +84 -0
  62. package/dist/scripts/codex-trigger-eval.js +968 -0
  63. package/dist/scripts/codex-trigger-eval.js.map +1 -0
  64. package/dist/scripts/eval-plugin-skills-audited.d.ts +6 -0
  65. package/dist/scripts/eval-plugin-skills-audited.js +261 -0
  66. package/dist/scripts/eval-plugin-skills-audited.js.map +1 -0
  67. package/dist/scripts/eval-plugin-skills.d.ts +45 -0
  68. package/dist/scripts/eval-plugin-skills.js +1586 -0
  69. package/dist/scripts/eval-plugin-skills.js.map +1 -0
  70. package/dist/scripts/eval-run-layout.d.ts +17 -0
  71. package/dist/scripts/eval-run-layout.js +26 -0
  72. package/dist/scripts/eval-run-layout.js.map +1 -0
  73. package/dist/scripts/plugin-eval-contract.d.ts +185 -0
  74. package/dist/scripts/plugin-eval-contract.js +695 -0
  75. package/dist/scripts/plugin-eval-contract.js.map +1 -0
  76. package/dist/scripts/plugin-eval-materializer.d.ts +13 -0
  77. package/dist/scripts/plugin-eval-materializer.js +421 -0
  78. package/dist/scripts/plugin-eval-materializer.js.map +1 -0
  79. package/dist/scripts/plugin-staging.d.ts +43 -0
  80. package/dist/scripts/plugin-staging.js +196 -0
  81. package/dist/scripts/plugin-staging.js.map +1 -0
  82. package/dist/scripts/skill-reporting.d.ts +212 -0
  83. package/dist/scripts/skill-reporting.js +922 -0
  84. package/dist/scripts/skill-reporting.js.map +1 -0
  85. package/dist/scripts/test-plugin-scripts.d.ts +7 -0
  86. package/dist/scripts/test-plugin-scripts.js +674 -0
  87. package/dist/scripts/test-plugin-scripts.js.map +1 -0
  88. package/dist/src/adapters/helpers.d.ts +44 -0
  89. package/dist/src/adapters/helpers.js +95 -0
  90. package/dist/src/adapters/helpers.js.map +1 -0
  91. package/dist/src/authoring/workspace-commands.d.ts +46 -0
  92. package/dist/src/authoring/workspace-commands.js +133 -0
  93. package/dist/src/authoring/workspace-commands.js.map +1 -0
  94. package/dist/src/commands/catalog-publish.d.ts +33 -0
  95. package/dist/src/commands/catalog-publish.js +374 -0
  96. package/dist/src/commands/catalog-publish.js.map +1 -0
  97. package/dist/src/commands/catalog-source.d.ts +111 -0
  98. package/dist/src/commands/catalog-source.js +266 -0
  99. package/dist/src/commands/catalog-source.js.map +1 -0
  100. package/dist/src/commands/console.d.ts +3 -0
  101. package/dist/src/commands/console.js +44 -0
  102. package/dist/src/commands/console.js.map +1 -0
  103. package/dist/src/commands/dependency-operation-plan.d.ts +28 -0
  104. package/dist/src/commands/dependency-operation-plan.js +15 -0
  105. package/dist/src/commands/dependency-operation-plan.js.map +1 -0
  106. package/dist/src/commands/init.d.ts +31 -0
  107. package/dist/src/commands/init.js +63 -0
  108. package/dist/src/commands/init.js.map +1 -0
  109. package/dist/src/commands/options.d.ts +68 -0
  110. package/dist/src/commands/options.js +146 -0
  111. package/dist/src/commands/options.js.map +1 -0
  112. package/dist/src/commands/rebuild-command.d.ts +77 -0
  113. package/dist/src/commands/rebuild-command.js +1681 -0
  114. package/dist/src/commands/rebuild-command.js.map +1 -0
  115. package/dist/src/commands/rebuild-integration.d.ts +94 -0
  116. package/dist/src/commands/rebuild-integration.js +3289 -0
  117. package/dist/src/commands/rebuild-integration.js.map +1 -0
  118. package/dist/src/commands/rebuild-operations.d.ts +110 -0
  119. package/dist/src/commands/rebuild-operations.js +791 -0
  120. package/dist/src/commands/rebuild-operations.js.map +1 -0
  121. package/dist/src/commands/review-publication.d.ts +99 -0
  122. package/dist/src/commands/review-publication.js +904 -0
  123. package/dist/src/commands/review-publication.js.map +1 -0
  124. package/dist/src/commands/runtime.d.ts +176 -0
  125. package/dist/src/commands/runtime.js +746 -0
  126. package/dist/src/commands/runtime.js.map +1 -0
  127. package/dist/src/commands/status-v4.d.ts +102 -0
  128. package/dist/src/commands/status-v4.js +844 -0
  129. package/dist/src/commands/status-v4.js.map +1 -0
  130. package/dist/src/commands/status.d.ts +93 -0
  131. package/dist/src/commands/status.js +442 -0
  132. package/dist/src/commands/status.js.map +1 -0
  133. package/dist/src/commands/wizard.d.ts +57 -0
  134. package/dist/src/commands/wizard.js +58 -0
  135. package/dist/src/commands/wizard.js.map +1 -0
  136. package/dist/src/commands/write-commands.d.ts +7 -0
  137. package/dist/src/commands/write-commands.js +167 -0
  138. package/dist/src/commands/write-commands.js.map +1 -0
  139. package/dist/src/constants.d.ts +25 -0
  140. package/dist/src/constants.js +26 -0
  141. package/dist/src/constants.js.map +1 -0
  142. package/dist/src/generators/agents.d.ts +3 -0
  143. package/dist/src/generators/agents.js +46 -0
  144. package/dist/src/generators/agents.js.map +1 -0
  145. package/dist/src/generators/hooks.d.ts +15 -0
  146. package/dist/src/generators/hooks.js +76 -0
  147. package/dist/src/generators/hooks.js.map +1 -0
  148. package/dist/src/generators/instructions.d.ts +13 -0
  149. package/dist/src/generators/instructions.js +66 -0
  150. package/dist/src/generators/instructions.js.map +1 -0
  151. package/dist/src/generators/local-plugin.d.ts +53 -0
  152. package/dist/src/generators/local-plugin.js +1268 -0
  153. package/dist/src/generators/local-plugin.js.map +1 -0
  154. package/dist/src/generators/permissions.d.ts +10 -0
  155. package/dist/src/generators/permissions.js +37 -0
  156. package/dist/src/generators/permissions.js.map +1 -0
  157. package/dist/src/generators/shared.d.ts +2 -0
  158. package/dist/src/generators/shared.js +15 -0
  159. package/dist/src/generators/shared.js.map +1 -0
  160. package/dist/src/index.d.ts +35 -0
  161. package/dist/src/index.js +2344 -0
  162. package/dist/src/index.js.map +1 -0
  163. package/dist/src/output/command-receipt.d.ts +90 -0
  164. package/dist/src/output/command-receipt.js +129 -0
  165. package/dist/src/output/command-receipt.js.map +1 -0
  166. package/dist/src/output/debug-log.d.ts +4 -0
  167. package/dist/src/output/debug-log.js +97 -0
  168. package/dist/src/output/debug-log.js.map +1 -0
  169. package/dist/src/output/equivalent-command.d.ts +9 -0
  170. package/dist/src/output/equivalent-command.js +39 -0
  171. package/dist/src/output/equivalent-command.js.map +1 -0
  172. package/dist/src/output/model.d.ts +117 -0
  173. package/dist/src/output/model.js +145 -0
  174. package/dist/src/output/model.js.map +1 -0
  175. package/dist/src/output/rebuild-progress.d.ts +21 -0
  176. package/dist/src/output/rebuild-progress.js +138 -0
  177. package/dist/src/output/rebuild-progress.js.map +1 -0
  178. package/dist/src/output/redact.d.ts +3 -0
  179. package/dist/src/output/redact.js +39 -0
  180. package/dist/src/output/redact.js.map +1 -0
  181. package/dist/src/output/reporter.d.ts +9 -0
  182. package/dist/src/output/reporter.js +133 -0
  183. package/dist/src/output/reporter.js.map +1 -0
  184. package/dist/src/portable/commands.d.ts +120 -0
  185. package/dist/src/portable/commands.js +506 -0
  186. package/dist/src/portable/commands.js.map +1 -0
  187. package/dist/src/portable/materializer.d.ts +50 -0
  188. package/dist/src/portable/materializer.js +408 -0
  189. package/dist/src/portable/materializer.js.map +1 -0
  190. package/dist/src/portable/skills-cli.d.ts +43 -0
  191. package/dist/src/portable/skills-cli.js +148 -0
  192. package/dist/src/portable/skills-cli.js.map +1 -0
  193. package/dist/src/tui/components.d.ts +32 -0
  194. package/dist/src/tui/components.js +42 -0
  195. package/dist/src/tui/components.js.map +1 -0
  196. package/dist/src/tui/console-app-v4.d.ts +20 -0
  197. package/dist/src/tui/console-app-v4.js +2613 -0
  198. package/dist/src/tui/console-app-v4.js.map +1 -0
  199. package/dist/src/tui/controller-runtime.d.ts +11 -0
  200. package/dist/src/tui/controller-runtime.js +902 -0
  201. package/dist/src/tui/controller-runtime.js.map +1 -0
  202. package/dist/src/tui/controller.d.ts +367 -0
  203. package/dist/src/tui/controller.js +1724 -0
  204. package/dist/src/tui/controller.js.map +1 -0
  205. package/dist/src/tui/index.d.ts +13 -0
  206. package/dist/src/tui/index.js +14 -0
  207. package/dist/src/tui/index.js.map +1 -0
  208. package/dist/src/tui/keys.d.ts +12 -0
  209. package/dist/src/tui/keys.js +22 -0
  210. package/dist/src/tui/keys.js.map +1 -0
  211. package/dist/src/tui/layout.d.ts +12 -0
  212. package/dist/src/tui/layout.js +19 -0
  213. package/dist/src/tui/layout.js.map +1 -0
  214. package/dist/src/tui/model.d.ts +279 -0
  215. package/dist/src/tui/model.js +652 -0
  216. package/dist/src/tui/model.js.map +1 -0
  217. package/dist/src/tui/prompt.d.ts +8 -0
  218. package/dist/src/tui/prompt.js +242 -0
  219. package/dist/src/tui/prompt.js.map +1 -0
  220. package/dist/src/tui/router.d.ts +153 -0
  221. package/dist/src/tui/router.js +102 -0
  222. package/dist/src/tui/router.js.map +1 -0
  223. package/dist/src/tui/runner.d.ts +11 -0
  224. package/dist/src/tui/runner.js +71 -0
  225. package/dist/src/tui/runner.js.map +1 -0
  226. package/dist/src/tui/theme.d.ts +18 -0
  227. package/dist/src/tui/theme.js +20 -0
  228. package/dist/src/tui/theme.js.map +1 -0
  229. package/dist/src/tui/views.d.ts +57 -0
  230. package/dist/src/tui/views.js +173 -0
  231. package/dist/src/tui/views.js.map +1 -0
  232. package/dist/src/tui/wizard.d.ts +11 -0
  233. package/dist/src/tui/wizard.js +321 -0
  234. package/dist/src/tui/wizard.js.map +1 -0
  235. package/dist/src/types.d.ts +313 -0
  236. package/dist/src/types.js +33 -0
  237. package/dist/src/types.js.map +1 -0
  238. package/dist/src/utils/active-marketplace-runtime-lock.d.ts +12 -0
  239. package/dist/src/utils/active-marketplace-runtime-lock.js +133 -0
  240. package/dist/src/utils/active-marketplace-runtime-lock.js.map +1 -0
  241. package/dist/src/utils/agent-version.d.ts +13 -0
  242. package/dist/src/utils/agent-version.js +172 -0
  243. package/dist/src/utils/agent-version.js.map +1 -0
  244. package/dist/src/utils/artifact-plan.d.ts +26 -0
  245. package/dist/src/utils/artifact-plan.js +444 -0
  246. package/dist/src/utils/artifact-plan.js.map +1 -0
  247. package/dist/src/utils/artifact-renderer.d.ts +124 -0
  248. package/dist/src/utils/artifact-renderer.js +442 -0
  249. package/dist/src/utils/artifact-renderer.js.map +1 -0
  250. package/dist/src/utils/artifact-sources.d.ts +8 -0
  251. package/dist/src/utils/artifact-sources.js +10 -0
  252. package/dist/src/utils/artifact-sources.js.map +1 -0
  253. package/dist/src/utils/aw-home-mutation-lock.d.ts +10 -0
  254. package/dist/src/utils/aw-home-mutation-lock.js +55 -0
  255. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -0
  256. package/dist/src/utils/bundle-integrity.d.ts +3 -0
  257. package/dist/src/utils/bundle-integrity.js +88 -0
  258. package/dist/src/utils/bundle-integrity.js.map +1 -0
  259. package/dist/src/utils/bundle-layout.d.ts +4 -0
  260. package/dist/src/utils/bundle-layout.js +546 -0
  261. package/dist/src/utils/bundle-layout.js.map +1 -0
  262. package/dist/src/utils/catalog-digests.d.ts +8 -0
  263. package/dist/src/utils/catalog-digests.js +108 -0
  264. package/dist/src/utils/catalog-digests.js.map +1 -0
  265. package/dist/src/utils/catalog-manifest-v3.d.ts +2 -0
  266. package/dist/src/utils/catalog-manifest-v3.js +3 -0
  267. package/dist/src/utils/catalog-manifest-v3.js.map +1 -0
  268. package/dist/src/utils/catalog-manifest-v4.d.ts +5 -0
  269. package/dist/src/utils/catalog-manifest-v4.js +106 -0
  270. package/dist/src/utils/catalog-manifest-v4.js.map +1 -0
  271. package/dist/src/utils/catalog-public-error.d.ts +15 -0
  272. package/dist/src/utils/catalog-public-error.js +84 -0
  273. package/dist/src/utils/catalog-public-error.js.map +1 -0
  274. package/dist/src/utils/catalog-runtime-projection.d.ts +36 -0
  275. package/dist/src/utils/catalog-runtime-projection.js +172 -0
  276. package/dist/src/utils/catalog-runtime-projection.js.map +1 -0
  277. package/dist/src/utils/catalog-snapshot.d.ts +8 -0
  278. package/dist/src/utils/catalog-snapshot.js +12 -0
  279. package/dist/src/utils/catalog-snapshot.js.map +1 -0
  280. package/dist/src/utils/catalog-source-cache.d.ts +61 -0
  281. package/dist/src/utils/catalog-source-cache.js +276 -0
  282. package/dist/src/utils/catalog-source-cache.js.map +1 -0
  283. package/dist/src/utils/catalog-source-identity.d.ts +4 -0
  284. package/dist/src/utils/catalog-source-identity.js +118 -0
  285. package/dist/src/utils/catalog-source-identity.js.map +1 -0
  286. package/dist/src/utils/catalog-source-presentation.d.ts +1 -0
  287. package/dist/src/utils/catalog-source-presentation.js +32 -0
  288. package/dist/src/utils/catalog-source-presentation.js.map +1 -0
  289. package/dist/src/utils/catalog-source-references.d.ts +65 -0
  290. package/dist/src/utils/catalog-source-references.js +1418 -0
  291. package/dist/src/utils/catalog-source-references.js.map +1 -0
  292. package/dist/src/utils/catalog-sources.d.ts +39 -0
  293. package/dist/src/utils/catalog-sources.js +293 -0
  294. package/dist/src/utils/catalog-sources.js.map +1 -0
  295. package/dist/src/utils/codex-config.d.ts +124 -0
  296. package/dist/src/utils/codex-config.js +1011 -0
  297. package/dist/src/utils/codex-config.js.map +1 -0
  298. package/dist/src/utils/codex-project-surface.d.ts +3 -0
  299. package/dist/src/utils/codex-project-surface.js +49 -0
  300. package/dist/src/utils/codex-project-surface.js.map +1 -0
  301. package/dist/src/utils/codex-roles.d.ts +71 -0
  302. package/dist/src/utils/codex-roles.js +257 -0
  303. package/dist/src/utils/codex-roles.js.map +1 -0
  304. package/dist/src/utils/codex-skill-staging.d.ts +9 -0
  305. package/dist/src/utils/codex-skill-staging.js +8 -0
  306. package/dist/src/utils/codex-skill-staging.js.map +1 -0
  307. package/dist/src/utils/config-value.d.ts +3 -0
  308. package/dist/src/utils/config-value.js +23 -0
  309. package/dist/src/utils/config-value.js.map +1 -0
  310. package/dist/src/utils/dynamic-skill-tree.d.ts +32 -0
  311. package/dist/src/utils/dynamic-skill-tree.js +436 -0
  312. package/dist/src/utils/dynamic-skill-tree.js.map +1 -0
  313. package/dist/src/utils/file-rules.d.ts +1 -0
  314. package/dist/src/utils/file-rules.js +2 -0
  315. package/dist/src/utils/file-rules.js.map +1 -0
  316. package/dist/src/utils/git-catalog-provider.d.ts +7 -0
  317. package/dist/src/utils/git-catalog-provider.js +510 -0
  318. package/dist/src/utils/git-catalog-provider.js.map +1 -0
  319. package/dist/src/utils/hooks-contract.d.ts +1 -0
  320. package/dist/src/utils/hooks-contract.js +2 -0
  321. package/dist/src/utils/hooks-contract.js.map +1 -0
  322. package/dist/src/utils/json.d.ts +4 -0
  323. package/dist/src/utils/json.js +29 -0
  324. package/dist/src/utils/json.js.map +1 -0
  325. package/dist/src/utils/lifecycle-active-store.d.ts +175 -0
  326. package/dist/src/utils/lifecycle-active-store.js +1276 -0
  327. package/dist/src/utils/lifecycle-active-store.js.map +1 -0
  328. package/dist/src/utils/local-marketplace.d.ts +41 -0
  329. package/dist/src/utils/local-marketplace.js +317 -0
  330. package/dist/src/utils/local-marketplace.js.map +1 -0
  331. package/dist/src/utils/manifest.d.ts +14 -0
  332. package/dist/src/utils/manifest.js +36 -0
  333. package/dist/src/utils/manifest.js.map +1 -0
  334. package/dist/src/utils/marketplace.d.ts +3 -0
  335. package/dist/src/utils/marketplace.js +76 -0
  336. package/dist/src/utils/marketplace.js.map +1 -0
  337. package/dist/src/utils/multi-source-catalog.d.ts +72 -0
  338. package/dist/src/utils/multi-source-catalog.js +402 -0
  339. package/dist/src/utils/multi-source-catalog.js.map +1 -0
  340. package/dist/src/utils/native-cli.d.ts +75 -0
  341. package/dist/src/utils/native-cli.js +435 -0
  342. package/dist/src/utils/native-cli.js.map +1 -0
  343. package/dist/src/utils/orphan-marketplace-cleanup.d.ts +18 -0
  344. package/dist/src/utils/orphan-marketplace-cleanup.js +202 -0
  345. package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -0
  346. package/dist/src/utils/ownership.d.ts +130 -0
  347. package/dist/src/utils/ownership.js +766 -0
  348. package/dist/src/utils/ownership.js.map +1 -0
  349. package/dist/src/utils/path-catalog-provider.d.ts +7 -0
  350. package/dist/src/utils/path-catalog-provider.js +87 -0
  351. package/dist/src/utils/path-catalog-provider.js.map +1 -0
  352. package/dist/src/utils/paths.d.ts +41 -0
  353. package/dist/src/utils/paths.js +138 -0
  354. package/dist/src/utils/paths.js.map +1 -0
  355. package/dist/src/utils/platform-entries.d.ts +1 -0
  356. package/dist/src/utils/platform-entries.js +2 -0
  357. package/dist/src/utils/platform-entries.js.map +1 -0
  358. package/dist/src/utils/platform-support.d.ts +1 -0
  359. package/dist/src/utils/platform-support.js +2 -0
  360. package/dist/src/utils/platform-support.js.map +1 -0
  361. package/dist/src/utils/plugin-authoring-capabilities.d.ts +23 -0
  362. package/dist/src/utils/plugin-authoring-capabilities.js +37 -0
  363. package/dist/src/utils/plugin-authoring-capabilities.js.map +1 -0
  364. package/dist/src/utils/plugin-authoring-capabilities.json +92 -0
  365. package/dist/src/utils/plugin-config-write.d.ts +107 -0
  366. package/dist/src/utils/plugin-config-write.js +565 -0
  367. package/dist/src/utils/plugin-config-write.js.map +1 -0
  368. package/dist/src/utils/plugin-config.d.ts +396 -0
  369. package/dist/src/utils/plugin-config.js +1898 -0
  370. package/dist/src/utils/plugin-config.js.map +1 -0
  371. package/dist/src/utils/plugin-dependencies.d.ts +12 -0
  372. package/dist/src/utils/plugin-dependencies.js +162 -0
  373. package/dist/src/utils/plugin-dependencies.js.map +1 -0
  374. package/dist/src/utils/plugin-release.d.ts +2 -0
  375. package/dist/src/utils/plugin-release.js +2 -0
  376. package/dist/src/utils/plugin-release.js.map +1 -0
  377. package/dist/src/utils/plugin-script-contract.d.ts +1 -0
  378. package/dist/src/utils/plugin-script-contract.js +2 -0
  379. package/dist/src/utils/plugin-script-contract.js.map +1 -0
  380. package/dist/src/utils/plugin-scripts.d.ts +172 -0
  381. package/dist/src/utils/plugin-scripts.js +585 -0
  382. package/dist/src/utils/plugin-scripts.js.map +1 -0
  383. package/dist/src/utils/process-lock.d.ts +47 -0
  384. package/dist/src/utils/process-lock.js +532 -0
  385. package/dist/src/utils/process-lock.js.map +1 -0
  386. package/dist/src/utils/process-tree.d.ts +2 -0
  387. package/dist/src/utils/process-tree.js +2 -0
  388. package/dist/src/utils/process-tree.js.map +1 -0
  389. package/dist/src/utils/project-boundary.d.ts +21 -0
  390. package/dist/src/utils/project-boundary.js +95 -0
  391. package/dist/src/utils/project-boundary.js.map +1 -0
  392. package/dist/src/utils/rendered-contract.d.ts +8 -0
  393. package/dist/src/utils/rendered-contract.js +134 -0
  394. package/dist/src/utils/rendered-contract.js.map +1 -0
  395. package/dist/src/utils/runtime-skill-closure.d.ts +13 -0
  396. package/dist/src/utils/runtime-skill-closure.js +863 -0
  397. package/dist/src/utils/runtime-skill-closure.js.map +1 -0
  398. package/dist/src/utils/skill-authoring.d.ts +1 -0
  399. package/dist/src/utils/skill-authoring.js +2 -0
  400. package/dist/src/utils/skill-authoring.js.map +1 -0
  401. package/dist/src/utils/skill-frontmatter-capabilities.d.ts +201 -0
  402. package/dist/src/utils/skill-frontmatter-capabilities.js +5 -0
  403. package/dist/src/utils/skill-frontmatter-capabilities.js.map +1 -0
  404. package/dist/src/utils/skill-frontmatter-capabilities.json +200 -0
  405. package/dist/src/utils/skill-validation.d.ts +37 -0
  406. package/dist/src/utils/skill-validation.js +326 -0
  407. package/dist/src/utils/skill-validation.js.map +1 -0
  408. package/dist/src/utils/slash-commands.d.ts +1 -0
  409. package/dist/src/utils/slash-commands.js +2 -0
  410. package/dist/src/utils/slash-commands.js.map +1 -0
  411. package/dist/src/utils/state-paths.d.ts +13 -0
  412. package/dist/src/utils/state-paths.js +129 -0
  413. package/dist/src/utils/state-paths.js.map +1 -0
  414. package/dist/src/utils/target-eligibility.d.ts +7 -0
  415. package/dist/src/utils/target-eligibility.js +26 -0
  416. package/dist/src/utils/target-eligibility.js.map +1 -0
  417. package/dist/src/utils/target-order.d.ts +7 -0
  418. package/dist/src/utils/target-order.js +10 -0
  419. package/dist/src/utils/target-order.js.map +1 -0
  420. package/dist/src/utils/template-engine.d.ts +1 -0
  421. package/dist/src/utils/template-engine.js +2 -0
  422. package/dist/src/utils/template-engine.js.map +1 -0
  423. package/dist/src/utils/test-path-fence.d.ts +12 -0
  424. package/dist/src/utils/test-path-fence.js +31 -0
  425. package/dist/src/utils/test-path-fence.js.map +1 -0
  426. package/dist/vitest.config.d.ts +2 -0
  427. package/dist/vitest.config.js +16 -0
  428. package/dist/vitest.config.js.map +1 -0
  429. package/package.json +61 -0
@@ -0,0 +1,1011 @@
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ import { ParseError, parseTOML } from 'toml-eslint-parser';
4
+ import { atomicReplaceConfigFile, withConfigFileLock, } from './plugin-config.js';
5
+ const AW_MANAGED_PREFIX = '[[aw-managed:';
6
+ const MANAGED_INSTRUCTIONS_KIND = 'developer_instructions';
7
+ const MANAGED_BLOCK_START_RE = /^\[\[aw-managed:start plugin="([^"\n]+)" kind="developer_instructions"\]\]$/;
8
+ const MANAGED_BLOCK_END_RE = /^\[\[aw-managed:end plugin="([^"\n]+)"\]\]$/;
9
+ function detectNewline(content) {
10
+ return content.includes('\r\n') ? '\r\n' : '\n';
11
+ }
12
+ function parseTomlDocument(content) {
13
+ try {
14
+ const ast = parseTOML(content);
15
+ return {
16
+ content,
17
+ ast,
18
+ topLevel: ast.body[0],
19
+ newline: detectNewline(content),
20
+ };
21
+ }
22
+ catch (error) {
23
+ if (error instanceof ParseError) {
24
+ throw new Error(`Unable to parse Codex config TOML: ${error.message}`);
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+ function keySegments(key) {
30
+ return key.keys.map((segment) => segment.type === 'TOMLBare' ? segment.name : segment.value);
31
+ }
32
+ function isRecord(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
34
+ }
35
+ function isFiniteTomlNumber(value) {
36
+ return Number.isFinite(value);
37
+ }
38
+ function renderTomlKeySegment(segment) {
39
+ return /^[A-Za-z0-9_-]+$/.test(segment) ? segment : JSON.stringify(segment);
40
+ }
41
+ function renderTomlPath(segments) {
42
+ return segments.map((segment) => renderTomlKeySegment(segment)).join('.');
43
+ }
44
+ function isTopLevelKeyValue(entry, keyName) {
45
+ return entry.type === 'TOMLKeyValue' && keySegments(entry.key).join('.') === keyName;
46
+ }
47
+ function findTopLevelKeyValue(document, keyName) {
48
+ return document.topLevel.body.find((entry) => isTopLevelKeyValue(entry, keyName));
49
+ }
50
+ function findTopLevelTable(document, sectionType, sectionName) {
51
+ return document.topLevel.body.find((entry) => entry.type === 'TOMLTable' &&
52
+ keySegments(entry.key).length === 2 &&
53
+ keySegments(entry.key)[0] === sectionType &&
54
+ keySegments(entry.key)[1] === sectionName);
55
+ }
56
+ function findTableEntry(table, keyName) {
57
+ return table.body.find((entry) => keySegments(entry.key).join('.') === keyName);
58
+ }
59
+ function readScalarValue(node) {
60
+ if (node.type === 'TOMLValue' && node.kind === 'string') {
61
+ return node.value;
62
+ }
63
+ if (node.type === 'TOMLValue' && node.kind === 'boolean') {
64
+ return node.value;
65
+ }
66
+ return undefined;
67
+ }
68
+ function renderTomlLiteral(value, newline) {
69
+ if (typeof value === 'boolean') {
70
+ return value ? 'true' : 'false';
71
+ }
72
+ return renderTomlString(value, newline);
73
+ }
74
+ function renderTomlString(value, newline) {
75
+ if (value.includes('\n')) {
76
+ const escaped = value
77
+ .replace(/\\/g, '\\\\')
78
+ .replace(/"""/g, '\\"\\"\\"')
79
+ .replace(/\n/g, newline);
80
+ return `"""${newline}${escaped}"""`;
81
+ }
82
+ return JSON.stringify(value);
83
+ }
84
+ function renderTableHeader(sectionType, sectionName) {
85
+ const renderedName = /^[A-Za-z0-9_-]+$/.test(sectionName)
86
+ ? sectionName
87
+ : JSON.stringify(sectionName);
88
+ return `[${sectionType}.${renderedName}]`;
89
+ }
90
+ function renderCodexMcpTomlValue(value) {
91
+ if (typeof value === 'string') {
92
+ return JSON.stringify(value);
93
+ }
94
+ if (typeof value === 'boolean') {
95
+ return value ? 'true' : 'false';
96
+ }
97
+ if (typeof value === 'number') {
98
+ if (!isFiniteTomlNumber(value)) {
99
+ throw new Error('MCP value numbers must be finite.');
100
+ }
101
+ return Number.isInteger(value) ? String(value) : String(value);
102
+ }
103
+ if (Array.isArray(value)) {
104
+ return `[${value.map((entry) => renderCodexMcpTomlValue(entry)).join(', ')}]`;
105
+ }
106
+ const entries = Object.entries(value);
107
+ if (entries.length === 0) {
108
+ return '{}';
109
+ }
110
+ return `{ ${entries
111
+ .map(([key, entryValue]) => `${renderTomlKeySegment(key)} = ${renderCodexMcpTomlValue(entryValue)}`)
112
+ .join(', ')} }`;
113
+ }
114
+ function normalizeCodexMcpTomlValue(value, fieldPath) {
115
+ if (value === null) {
116
+ throw new Error(`Invalid ${fieldPath}: null cannot be represented in TOML.`);
117
+ }
118
+ if (typeof value === 'string' || typeof value === 'boolean') {
119
+ return value;
120
+ }
121
+ if (typeof value === 'number') {
122
+ if (!isFiniteTomlNumber(value)) {
123
+ throw new Error(`Invalid ${fieldPath}: number must be finite.`);
124
+ }
125
+ return value;
126
+ }
127
+ if (Array.isArray(value)) {
128
+ return value.map((entry, index) => normalizeCodexMcpTomlValue(entry, `${fieldPath}[${index}]`));
129
+ }
130
+ if (!isRecord(value)) {
131
+ throw new Error(`Invalid ${fieldPath}: expected a TOML-compatible JSON value.`);
132
+ }
133
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
134
+ key,
135
+ normalizeCodexMcpTomlValue(entryValue, `${fieldPath}.${key}`),
136
+ ]));
137
+ }
138
+ function renderCodexMcpServerContent(serverName, config, newline) {
139
+ const tables = [];
140
+ const visitTable = (tablePath, tableValue) => {
141
+ const scalarLines = [];
142
+ const childObjects = [];
143
+ for (const [key, value] of Object.entries(tableValue)) {
144
+ if (isRecord(value)) {
145
+ childObjects.push([key, value]);
146
+ continue;
147
+ }
148
+ scalarLines.push(`${renderTomlKeySegment(key)} = ${renderCodexMcpTomlValue(value)}`);
149
+ }
150
+ tables.push([
151
+ `[${renderTomlPath(tablePath)}]`,
152
+ ...scalarLines,
153
+ ].join(newline));
154
+ for (const [childKey, childValue] of childObjects) {
155
+ visitTable([...tablePath, childKey], childValue);
156
+ }
157
+ };
158
+ visitTable(['mcp_servers', serverName], config);
159
+ return `${tables.join(`${newline}${newline}`)}${newline}`;
160
+ }
161
+ function findTopLevelTablesWithPrefix(document, keyPrefix) {
162
+ return document.topLevel.body.filter((entry) => entry.type === 'TOMLTable' &&
163
+ keyPrefix.every((segment, index) => keySegments(entry.key)[index] === segment));
164
+ }
165
+ function readCodexMcpTomlValue(node, fieldPath) {
166
+ if (node.type === 'TOMLValue') {
167
+ if (node.kind === 'string' ||
168
+ node.kind === 'boolean' ||
169
+ node.kind === 'integer' ||
170
+ node.kind === 'float') {
171
+ return normalizeCodexMcpTomlValue(node.value, fieldPath);
172
+ }
173
+ throw new Error(`Unsupported TOML value kind at ${fieldPath}: ${node.kind}.`);
174
+ }
175
+ if (node.type === 'TOMLArray') {
176
+ return node.elements.map((entry, index) => readCodexMcpTomlValue(entry, `${fieldPath}[${index}]`));
177
+ }
178
+ if (node.type === 'TOMLInlineTable') {
179
+ const value = {};
180
+ for (const entry of node.body) {
181
+ assignCodexMcpObjectValue(value, keySegments(entry.key), readCodexMcpTomlValue(entry.value, `${fieldPath}.${keySegments(entry.key).join('.')}`), fieldPath);
182
+ }
183
+ return value;
184
+ }
185
+ const unsupportedNodeType = node.type ?? 'unknown';
186
+ throw new Error(`Unsupported TOML MCP value node at ${fieldPath}: ${unsupportedNodeType}.`);
187
+ }
188
+ function ensureCodexMcpObjectPath(root, segments, fieldPath) {
189
+ let current = root;
190
+ for (const segment of segments) {
191
+ const existing = current[segment];
192
+ if (existing === undefined) {
193
+ current[segment] = {};
194
+ current = current[segment];
195
+ continue;
196
+ }
197
+ if (!isRecord(existing)) {
198
+ throw new Error(`Cannot treat ${fieldPath} as a table because it is already a scalar value.`);
199
+ }
200
+ current = existing;
201
+ }
202
+ return current;
203
+ }
204
+ function assignCodexMcpObjectValue(root, keyPath, value, fieldPath) {
205
+ const parent = ensureCodexMcpObjectPath(root, keyPath.slice(0, -1), fieldPath);
206
+ const leafKey = keyPath.at(-1);
207
+ if (!leafKey) {
208
+ throw new Error(`Invalid empty MCP key path at ${fieldPath}.`);
209
+ }
210
+ const existing = parent[leafKey];
211
+ if (existing !== undefined && isRecord(existing)) {
212
+ throw new Error(`Cannot overwrite nested MCP table at ${fieldPath} with a scalar value.`);
213
+ }
214
+ parent[leafKey] = value;
215
+ }
216
+ function buildCodexMcpServerSnapshot(serverName, tables) {
217
+ try {
218
+ const value = {};
219
+ for (const table of tables) {
220
+ const tablePath = keySegments(table.key).slice(2);
221
+ const tableTarget = ensureCodexMcpObjectPath(value, tablePath, `mcpServers.${serverName}${tablePath.length > 0 ? `.${tablePath.join('.')}` : ''}`);
222
+ for (const entry of table.body) {
223
+ assignCodexMcpObjectValue(tableTarget, keySegments(entry.key), readCodexMcpTomlValue(entry.value, `mcpServers.${serverName}.${[...tablePath, ...keySegments(entry.key)].join('.')}`), `mcpServers.${serverName}.${[...tablePath, ...keySegments(entry.key)].join('.')}`);
224
+ }
225
+ }
226
+ return {
227
+ key: serverName,
228
+ value,
229
+ };
230
+ }
231
+ catch (error) {
232
+ return {
233
+ key: serverName,
234
+ parseError: error instanceof Error ? error.message : String(error),
235
+ };
236
+ }
237
+ }
238
+ function collectCodexMcpServerSnapshots(document) {
239
+ const groupedTables = new Map();
240
+ for (const table of findTopLevelTablesWithPrefix(document, ['mcp_servers'])) {
241
+ const segments = keySegments(table.key);
242
+ if (segments.length < 2) {
243
+ continue;
244
+ }
245
+ const serverName = segments[1];
246
+ const tables = groupedTables.get(serverName) ?? [];
247
+ tables.push(table);
248
+ groupedTables.set(serverName, tables);
249
+ }
250
+ return Object.fromEntries([...groupedTables.entries()].map(([serverName, tables]) => [
251
+ serverName,
252
+ buildCodexMcpServerSnapshot(serverName, tables),
253
+ ]));
254
+ }
255
+ function lineStart(content, index) {
256
+ let current = index;
257
+ while (current > 0 && content[current - 1] !== '\n') {
258
+ current -= 1;
259
+ }
260
+ return current;
261
+ }
262
+ function lineEndExclusive(content, index) {
263
+ let current = index;
264
+ while (current < content.length && content[current] !== '\n') {
265
+ current += 1;
266
+ }
267
+ if (current < content.length) {
268
+ current += 1;
269
+ }
270
+ return current;
271
+ }
272
+ function expandNodeRemovalRange(content, start, end) {
273
+ let removeStart = lineStart(content, start);
274
+ let removeEnd = lineEndExclusive(content, end);
275
+ if (removeEnd < content.length && content[removeEnd] === '\n') {
276
+ removeEnd += 1;
277
+ }
278
+ if (removeStart === 0) {
279
+ while (removeEnd < content.length && content[removeEnd] === '\n') {
280
+ removeEnd += 1;
281
+ }
282
+ }
283
+ return [removeStart, removeEnd];
284
+ }
285
+ function ensureTerminalNewline(content) {
286
+ if (content.length === 0) {
287
+ return '';
288
+ }
289
+ return content.endsWith('\n') ? content : `${content}\n`;
290
+ }
291
+ function applyPatches(content, patches) {
292
+ const sorted = [...patches].sort((left, right) => right.start - left.start);
293
+ let next = content;
294
+ for (const patch of sorted) {
295
+ next = `${next.slice(0, patch.start)}${patch.text}${next.slice(patch.end)}`;
296
+ }
297
+ return ensureTerminalNewline(next);
298
+ }
299
+ function buildSectionInsertText(document, sectionType, sectionName, orderedEntries) {
300
+ const lines = [
301
+ renderTableHeader(sectionType, sectionName),
302
+ ...orderedEntries.map(([key, value]) => `${key} = ${renderTomlLiteral(value, document.newline)}`),
303
+ ];
304
+ const sectionText = lines.join(document.newline);
305
+ if (document.content.length === 0) {
306
+ return `${sectionText}${document.newline}`;
307
+ }
308
+ const prefix = document.content.endsWith(`${document.newline}${document.newline}`)
309
+ ? ''
310
+ : document.content.endsWith(document.newline)
311
+ ? document.newline
312
+ : `${document.newline}${document.newline}`;
313
+ return `${prefix}${sectionText}${document.newline}`;
314
+ }
315
+ function buildMcpServerInsertText(document, tableText) {
316
+ if (document.content.length === 0) {
317
+ return tableText;
318
+ }
319
+ const prefix = document.content.endsWith(`${document.newline}${document.newline}`)
320
+ ? ''
321
+ : document.content.endsWith(document.newline)
322
+ ? document.newline
323
+ : `${document.newline}${document.newline}`;
324
+ return `${prefix}${tableText}`;
325
+ }
326
+ function upsertSectionEntries(content, sectionType, sectionName, orderedEntries) {
327
+ const document = parseTomlDocument(content);
328
+ const table = findTopLevelTable(document, sectionType, sectionName);
329
+ if (!table) {
330
+ return applyPatches(document.content, [
331
+ {
332
+ start: document.content.length,
333
+ end: document.content.length,
334
+ text: buildSectionInsertText(document, sectionType, sectionName, orderedEntries),
335
+ },
336
+ ]);
337
+ }
338
+ const patches = [];
339
+ const missingEntries = new Map(orderedEntries);
340
+ for (const [key, value] of orderedEntries) {
341
+ const entry = findTableEntry(table, key);
342
+ if (!entry) {
343
+ continue;
344
+ }
345
+ missingEntries.delete(key);
346
+ patches.push({
347
+ start: entry.value.range[0],
348
+ end: entry.value.range[1],
349
+ text: renderTomlLiteral(value, document.newline),
350
+ });
351
+ }
352
+ if (missingEntries.size > 0) {
353
+ const text = [
354
+ '',
355
+ ...[...missingEntries.entries()].map(([key, value]) => `${key} = ${renderTomlLiteral(value, document.newline)}`),
356
+ ].join(document.newline);
357
+ patches.push({
358
+ start: table.range[1],
359
+ end: table.range[1],
360
+ text,
361
+ });
362
+ }
363
+ return patches.length > 0 ? applyPatches(document.content, patches) : ensureTerminalNewline(content);
364
+ }
365
+ function removeSection(content, sectionType, sectionName) {
366
+ const document = parseTomlDocument(content);
367
+ const table = findTopLevelTable(document, sectionType, sectionName);
368
+ if (!table) {
369
+ return ensureTerminalNewline(content);
370
+ }
371
+ const [start, end] = expandNodeRemovalRange(document.content, table.range[0], table.range[1]);
372
+ return applyPatches(document.content, [{ start, end, text: '' }]);
373
+ }
374
+ function resolveTopLevelKeyInsertIndex(document) {
375
+ const topLevelKeyValues = document.topLevel.body.filter((entry) => entry.type === 'TOMLKeyValue');
376
+ const lastTopLevelKeyValue = topLevelKeyValues.at(-1);
377
+ if (lastTopLevelKeyValue) {
378
+ return lineEndExclusive(document.content, lastTopLevelKeyValue.range[1]);
379
+ }
380
+ const firstTable = document.topLevel.body.find((entry) => entry.type === 'TOMLTable');
381
+ if (firstTable) {
382
+ return lineStart(document.content, firstTable.range[0]);
383
+ }
384
+ return document.content.length;
385
+ }
386
+ function buildTopLevelAssignmentInsertText(document, assignment, index) {
387
+ if (document.content.length === 0) {
388
+ return `${assignment}${document.newline}`;
389
+ }
390
+ const before = document.content.slice(0, index);
391
+ const after = document.content.slice(index);
392
+ const needsLeadingBlank = before.length > 0 &&
393
+ !before.endsWith(`${document.newline}${document.newline}`) &&
394
+ !before.endsWith(document.newline);
395
+ const needsTrailingBlank = after.length > 0 &&
396
+ !after.startsWith(document.newline) &&
397
+ !after.startsWith(`${document.newline}${document.newline}`);
398
+ return `${needsLeadingBlank ? `${document.newline}${document.newline}` : ''}${assignment}${needsTrailingBlank ? `${document.newline}${document.newline}` : document.newline}`;
399
+ }
400
+ function splitValueLines(value) {
401
+ if (value.length === 0) {
402
+ return [];
403
+ }
404
+ const lines = [];
405
+ let start = 0;
406
+ for (let index = 0; index < value.length; index += 1) {
407
+ if (value[index] !== '\n') {
408
+ continue;
409
+ }
410
+ lines.push({
411
+ text: value.slice(start, index),
412
+ start,
413
+ endExclusive: index + 1,
414
+ });
415
+ start = index + 1;
416
+ }
417
+ lines.push({
418
+ text: value.slice(start),
419
+ start,
420
+ endExclusive: value.length,
421
+ });
422
+ return lines;
423
+ }
424
+ function parseManagedInstructionSegments(value) {
425
+ if (value.length === 0) {
426
+ return [{ type: 'text', value: '' }];
427
+ }
428
+ const lines = splitValueLines(value);
429
+ const segments = [];
430
+ const seenPlugins = new Set();
431
+ let textStart = 0;
432
+ for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
433
+ const startMatch = MANAGED_BLOCK_START_RE.exec(lines[lineIndex].text);
434
+ if (!startMatch) {
435
+ continue;
436
+ }
437
+ const pluginName = startMatch[1];
438
+ if (seenPlugins.has(pluginName)) {
439
+ throw new Error(`Codex developer_instructions contains duplicate aw-managed block for ${pluginName}.`);
440
+ }
441
+ let endIndex = lineIndex + 1;
442
+ for (; endIndex < lines.length; endIndex += 1) {
443
+ const endMatch = MANAGED_BLOCK_END_RE.exec(lines[endIndex].text);
444
+ if (endMatch && endMatch[1] === pluginName) {
445
+ break;
446
+ }
447
+ }
448
+ if (endIndex >= lines.length) {
449
+ throw new Error(`Codex developer_instructions contains an unterminated aw-managed block for ${pluginName}.`);
450
+ }
451
+ segments.push({
452
+ type: 'text',
453
+ value: value.slice(textStart, lines[lineIndex].start),
454
+ });
455
+ segments.push({
456
+ type: 'block',
457
+ pluginName,
458
+ value: value.slice(lines[lineIndex].endExclusive, lines[endIndex].start),
459
+ });
460
+ seenPlugins.add(pluginName);
461
+ textStart = lines[endIndex].endExclusive;
462
+ lineIndex = endIndex;
463
+ }
464
+ segments.push({
465
+ type: 'text',
466
+ value: value.slice(textStart),
467
+ });
468
+ return segments;
469
+ }
470
+ function renderManagedInstructionBlock(pluginName, value) {
471
+ const normalizedValue = value.replace(/\n+$/, '');
472
+ return [
473
+ `[[aw-managed:start plugin="${pluginName}" kind="${MANAGED_INSTRUCTIONS_KIND}"]]`,
474
+ normalizedValue,
475
+ `[[aw-managed:end plugin="${pluginName}"]]`,
476
+ ].join('\n') + '\n';
477
+ }
478
+ export function composeManagedDeveloperInstructionsBlock(pluginName, fragments) {
479
+ const seenArtifactIds = new Set();
480
+ const normalizedValues = [...fragments]
481
+ .map((fragment) => {
482
+ const artifactId = fragment.artifactId.trim();
483
+ if (!artifactId) {
484
+ throw new Error('Managed instruction fragments must declare a non-empty artifactId.');
485
+ }
486
+ if (seenArtifactIds.has(artifactId)) {
487
+ throw new Error(`Duplicate managed instruction fragment id: ${artifactId}.`);
488
+ }
489
+ seenArtifactIds.add(artifactId);
490
+ return {
491
+ artifactId,
492
+ value: fragment.value.trim(),
493
+ };
494
+ })
495
+ .sort((left, right) => left.artifactId.localeCompare(right.artifactId))
496
+ .map((fragment) => fragment.value)
497
+ .filter((value) => value.length > 0);
498
+ return {
499
+ pluginName,
500
+ value: normalizedValues.join('\n\n'),
501
+ };
502
+ }
503
+ function renderManagedInstructionSegments(segments) {
504
+ return segments
505
+ .map((segment) => segment.type === 'text'
506
+ ? segment.value
507
+ : renderManagedInstructionBlock(segment.pluginName, segment.value))
508
+ .join('');
509
+ }
510
+ function rejectSentinelPrefixedLines(value) {
511
+ if (/^\[\[aw-managed:/m.test(value)) {
512
+ throw new Error('Instruction content must not contain lines starting with [[aw-managed:.');
513
+ }
514
+ }
515
+ function appendManagedBlockToTail(existingText, blockText) {
516
+ if (existingText.length === 0) {
517
+ return blockText;
518
+ }
519
+ if (existingText.endsWith('\n\n')) {
520
+ return `${existingText}${blockText}`;
521
+ }
522
+ if (existingText.endsWith('\n')) {
523
+ return `${existingText}\n${blockText}`;
524
+ }
525
+ return `${existingText}\n\n${blockText}`;
526
+ }
527
+ function mergeTextAroundRemovedBlock(left, right) {
528
+ if (left.length === 0 && right.length === 0) {
529
+ return '';
530
+ }
531
+ if (left.length === 0) {
532
+ return right.replace(/^\n+/, '');
533
+ }
534
+ if (right.length === 0) {
535
+ return left.replace(/\n+$/, '');
536
+ }
537
+ return `${left.replace(/\n+$/, '')}\n\n${right.replace(/^\n+/, '')}`;
538
+ }
539
+ function upsertManagedInstructionsValue(currentValue, block) {
540
+ rejectSentinelPrefixedLines(block.value);
541
+ const segments = parseManagedInstructionSegments(currentValue ?? '');
542
+ const renderedBlock = renderManagedInstructionBlock(block.pluginName, block.value.trim());
543
+ const existingIndex = segments.findIndex((segment) => segment.type === 'block' && segment.pluginName === block.pluginName);
544
+ if (existingIndex >= 0) {
545
+ segments[existingIndex].value = block.value.trim();
546
+ return renderManagedInstructionSegments(segments);
547
+ }
548
+ const lastSegment = segments.at(-1);
549
+ if (!lastSegment || lastSegment.type !== 'text') {
550
+ return renderedBlock;
551
+ }
552
+ const previousSegment = segments.length >= 2 ? segments[segments.length - 2] : undefined;
553
+ lastSegment.value =
554
+ previousSegment?.type === 'block' && lastSegment.value.length === 0
555
+ ? `\n${renderedBlock}`
556
+ : appendManagedBlockToTail(lastSegment.value, renderedBlock);
557
+ return renderManagedInstructionSegments(segments);
558
+ }
559
+ function removeManagedInstructionsValue(currentValue, pluginName) {
560
+ if (currentValue === undefined) {
561
+ return undefined;
562
+ }
563
+ const segments = parseManagedInstructionSegments(currentValue);
564
+ const blockIndex = segments.findIndex((segment) => segment.type === 'block' && segment.pluginName === pluginName);
565
+ if (blockIndex < 0) {
566
+ return currentValue;
567
+ }
568
+ const leftText = blockIndex > 0 && segments[blockIndex - 1]?.type === 'text'
569
+ ? segments[blockIndex - 1].value
570
+ : '';
571
+ const rightText = blockIndex < segments.length - 1 && segments[blockIndex + 1]?.type === 'text'
572
+ ? segments[blockIndex + 1].value
573
+ : '';
574
+ const nextSegments = [...segments];
575
+ nextSegments.splice(Math.max(blockIndex - 1, 0), Math.min(3, nextSegments.length - Math.max(blockIndex - 1, 0)), {
576
+ type: 'text',
577
+ value: mergeTextAroundRemovedBlock(leftText, rightText),
578
+ });
579
+ const rendered = renderManagedInstructionSegments(nextSegments).trim();
580
+ return rendered === '' ? undefined : rendered;
581
+ }
582
+ function renderDeveloperInstructionsAssignment(value, newline) {
583
+ return `developer_instructions = ${renderTomlString(value, newline)}`;
584
+ }
585
+ export function parseCodexConfig(content) {
586
+ const document = parseTomlDocument(content);
587
+ const marketplaces = {};
588
+ const plugins = {};
589
+ const projects = {};
590
+ const agents = {};
591
+ const mcpServers = collectCodexMcpServerSnapshots(document);
592
+ for (const entry of document.topLevel.body) {
593
+ if (entry.type !== 'TOMLTable') {
594
+ continue;
595
+ }
596
+ const segments = keySegments(entry.key);
597
+ if (segments.length !== 2) {
598
+ continue;
599
+ }
600
+ const values = Object.fromEntries(entry.body
601
+ .map((item) => {
602
+ const scalarValue = readScalarValue(item.value);
603
+ return scalarValue === undefined
604
+ ? undefined
605
+ : [keySegments(item.key).join('.'), scalarValue];
606
+ })
607
+ .filter((item) => item !== undefined));
608
+ if (segments[0] === 'marketplaces') {
609
+ const source = typeof values.source === 'string' ? values.source : undefined;
610
+ marketplaces[segments[1]] = {
611
+ name: segments[1],
612
+ source,
613
+ sourceType: typeof values.source_type === 'string' ? values.source_type : undefined,
614
+ lastUpdated: typeof values.last_updated === 'string' ? values.last_updated : undefined,
615
+ sourcePointsToManifest: source !== undefined && /(?:^|[\\/])marketplace\.json$/i.test(source),
616
+ };
617
+ continue;
618
+ }
619
+ if (segments[0] === 'plugins') {
620
+ plugins[segments[1]] = {
621
+ name: segments[1],
622
+ enabled: typeof values.enabled === 'boolean' ? values.enabled : undefined,
623
+ };
624
+ continue;
625
+ }
626
+ if (segments[0] === 'projects') {
627
+ projects[segments[1]] = {
628
+ path: segments[1],
629
+ trustLevel: typeof values.trust_level === 'string' ? values.trust_level : undefined,
630
+ };
631
+ continue;
632
+ }
633
+ if (segments[0] === 'agents') {
634
+ agents[segments[1]] = {
635
+ key: segments[1],
636
+ description: typeof values.description === 'string' ? values.description : undefined,
637
+ configFile: typeof values.config_file === 'string' ? values.config_file : undefined,
638
+ };
639
+ }
640
+ }
641
+ const developerInstructionsEntry = findTopLevelKeyValue(document, 'developer_instructions');
642
+ const developerInstructionsValue = developerInstructionsEntry?.value.type === 'TOMLValue' &&
643
+ developerInstructionsEntry.value.kind === 'string'
644
+ ? developerInstructionsEntry.value.value
645
+ : undefined;
646
+ const managedBlocks = {};
647
+ if (developerInstructionsValue !== undefined) {
648
+ for (const segment of parseManagedInstructionSegments(developerInstructionsValue)) {
649
+ if (segment.type !== 'block') {
650
+ continue;
651
+ }
652
+ managedBlocks[segment.pluginName] = {
653
+ pluginName: segment.pluginName,
654
+ value: segment.value,
655
+ };
656
+ }
657
+ }
658
+ return {
659
+ marketplaces,
660
+ plugins,
661
+ projects,
662
+ agents,
663
+ mcpServers,
664
+ developerInstructions: {
665
+ defined: developerInstructionsValue !== undefined,
666
+ value: developerInstructionsValue,
667
+ managedBlocks,
668
+ },
669
+ };
670
+ }
671
+ export function upsertCodexMarketplace(content, name, config) {
672
+ return upsertSectionEntries(content, 'marketplaces', name, [
673
+ ['last_updated', config.lastUpdated ?? new Date().toISOString()],
674
+ ['source_type', config.sourceType],
675
+ ['source', config.source],
676
+ ]);
677
+ }
678
+ export function removeCodexMarketplace(content, name) {
679
+ return removeSection(content, 'marketplaces', name);
680
+ }
681
+ export function upsertCodexPluginEnabled(content, name, config) {
682
+ return upsertSectionEntries(content, 'plugins', name, [['enabled', config.enabled]]);
683
+ }
684
+ export function removeCodexPluginEnabled(content, name) {
685
+ return removeSection(content, 'plugins', name);
686
+ }
687
+ export function upsertCodexAgentRegistration(content, roleKey, config) {
688
+ const entries = [];
689
+ if (config.configFile !== undefined) {
690
+ entries.push(['config_file', config.configFile]);
691
+ }
692
+ if (config.description !== undefined) {
693
+ entries.push(['description', config.description]);
694
+ }
695
+ return upsertSectionEntries(content, 'agents', roleKey, entries);
696
+ }
697
+ export function removeCodexAgentRegistration(content, roleKey) {
698
+ return removeSection(content, 'agents', roleKey);
699
+ }
700
+ export function normalizeRenderedCodexMcpServers(value, fieldName = 'mcpServers') {
701
+ if (!isRecord(value)) {
702
+ throw new Error(`Invalid ${fieldName}: expected top-level "mcpServers" object.`);
703
+ }
704
+ return Object.fromEntries(Object.entries(value).map(([serverName, serverConfig]) => {
705
+ if (!isRecord(serverConfig)) {
706
+ throw new Error(`Invalid ${fieldName}.${serverName}: expected a server config object.`);
707
+ }
708
+ return [
709
+ serverName,
710
+ normalizeCodexMcpTomlValue(serverConfig, `${fieldName}.${serverName}`),
711
+ ];
712
+ }));
713
+ }
714
+ export function parseRenderedCodexMcpFileContent(content, fieldName = 'mcp file') {
715
+ if (!isRecord(content)) {
716
+ throw new Error(`Invalid ${fieldName}: expected a JSON object.`);
717
+ }
718
+ return normalizeRenderedCodexMcpServers(content.mcpServers, `${fieldName}.mcpServers`);
719
+ }
720
+ export function upsertCodexMcpServer(content, serverName, config) {
721
+ const normalizedConfig = normalizeCodexMcpTomlValue(config, `mcpServers.${serverName}`);
722
+ const document = parseTomlDocument(content);
723
+ const matchingTables = findTopLevelTablesWithPrefix(document, ['mcp_servers', serverName]);
724
+ const renderedContent = renderCodexMcpServerContent(serverName, normalizedConfig, document.newline);
725
+ if (matchingTables.length === 0) {
726
+ return applyPatches(document.content, [
727
+ {
728
+ start: document.content.length,
729
+ end: document.content.length,
730
+ text: buildMcpServerInsertText(document, renderedContent),
731
+ },
732
+ ]);
733
+ }
734
+ const patches = [];
735
+ const [firstStart, firstEnd] = expandNodeRemovalRange(document.content, matchingTables[0].range[0], matchingTables[0].range[1]);
736
+ patches.push({
737
+ start: firstStart,
738
+ end: firstEnd,
739
+ text: renderedContent,
740
+ });
741
+ for (const table of matchingTables.slice(1)) {
742
+ const [start, end] = expandNodeRemovalRange(document.content, table.range[0], table.range[1]);
743
+ patches.push({ start, end, text: '' });
744
+ }
745
+ return applyPatches(document.content, patches);
746
+ }
747
+ export function removeCodexMcpServer(content, serverName) {
748
+ const document = parseTomlDocument(content);
749
+ const matchingTables = findTopLevelTablesWithPrefix(document, ['mcp_servers', serverName]);
750
+ if (matchingTables.length === 0) {
751
+ return ensureTerminalNewline(content);
752
+ }
753
+ return applyPatches(document.content, matchingTables.map((table) => {
754
+ const [start, end] = expandNodeRemovalRange(document.content, table.range[0], table.range[1]);
755
+ return { start, end, text: '' };
756
+ }));
757
+ }
758
+ function stableCodexMcpValue(value) {
759
+ if (Array.isArray(value)) {
760
+ return JSON.stringify(value.map((entry) => JSON.parse(stableCodexMcpValue(entry))));
761
+ }
762
+ if (isRecord(value)) {
763
+ return JSON.stringify(Object.fromEntries(Object.keys(value)
764
+ .sort()
765
+ .map((key) => [
766
+ key,
767
+ JSON.parse(stableCodexMcpValue(value[key])),
768
+ ])));
769
+ }
770
+ return JSON.stringify(value);
771
+ }
772
+ export function resolveCodexMcpServerStatusSignal(options) {
773
+ if (!options.tracked && options.actual) {
774
+ return {
775
+ key: options.key,
776
+ tracked: false,
777
+ state: 'orphan',
778
+ reason: 'server exists in .codex/config.toml but current plugin has no AW ownership marker for it.',
779
+ };
780
+ }
781
+ if (!options.actual) {
782
+ return {
783
+ key: options.key,
784
+ tracked: options.tracked,
785
+ state: 'missing',
786
+ reason: 'server is missing from .codex/config.toml.',
787
+ };
788
+ }
789
+ if (options.actual.parseError) {
790
+ return {
791
+ key: options.key,
792
+ tracked: options.tracked,
793
+ state: 'drifted',
794
+ reason: options.actual.parseError,
795
+ };
796
+ }
797
+ if (options.expected === undefined) {
798
+ return {
799
+ key: options.key,
800
+ tracked: options.tracked,
801
+ state: 'visible',
802
+ };
803
+ }
804
+ if (!options.actual.value) {
805
+ return {
806
+ key: options.key,
807
+ tracked: options.tracked,
808
+ state: 'drifted',
809
+ reason: 'server exists but cannot be normalized to a comparable JSON subtree.',
810
+ };
811
+ }
812
+ return stableCodexMcpValue(options.actual.value) === stableCodexMcpValue(options.expected)
813
+ ? {
814
+ key: options.key,
815
+ tracked: options.tracked,
816
+ state: 'visible',
817
+ }
818
+ : {
819
+ key: options.key,
820
+ tracked: options.tracked,
821
+ state: 'drifted',
822
+ reason: 'current TOML subtree differs from rendered .mcp.json.',
823
+ };
824
+ }
825
+ export function upsertManagedDeveloperInstructions(content, block) {
826
+ const document = parseTomlDocument(content);
827
+ const currentEntry = findTopLevelKeyValue(document, 'developer_instructions');
828
+ const nextValue = upsertManagedInstructionsValue(currentEntry?.value.type === 'TOMLValue' && currentEntry.value.kind === 'string'
829
+ ? currentEntry.value.value
830
+ : undefined, block);
831
+ const renderedAssignment = renderDeveloperInstructionsAssignment(nextValue, document.newline);
832
+ if (currentEntry) {
833
+ return applyPatches(document.content, [
834
+ {
835
+ start: currentEntry.range[0],
836
+ end: currentEntry.range[1],
837
+ text: renderedAssignment,
838
+ },
839
+ ]);
840
+ }
841
+ const insertIndex = resolveTopLevelKeyInsertIndex(document);
842
+ return applyPatches(document.content, [
843
+ {
844
+ start: insertIndex,
845
+ end: insertIndex,
846
+ text: buildTopLevelAssignmentInsertText(document, renderedAssignment, insertIndex),
847
+ },
848
+ ]);
849
+ }
850
+ export function removeManagedDeveloperInstructions(content, pluginName) {
851
+ const document = parseTomlDocument(content);
852
+ const currentEntry = findTopLevelKeyValue(document, 'developer_instructions');
853
+ if (!currentEntry ||
854
+ currentEntry.value.type !== 'TOMLValue' ||
855
+ currentEntry.value.kind !== 'string') {
856
+ return ensureTerminalNewline(content);
857
+ }
858
+ const nextValue = removeManagedInstructionsValue(currentEntry.value.value, pluginName);
859
+ if (nextValue !== undefined) {
860
+ return applyPatches(document.content, [
861
+ {
862
+ start: currentEntry.range[0],
863
+ end: currentEntry.range[1],
864
+ text: renderDeveloperInstructionsAssignment(nextValue, document.newline),
865
+ },
866
+ ]);
867
+ }
868
+ const [start, end] = expandNodeRemovalRange(document.content, currentEntry.range[0], currentEntry.range[1]);
869
+ return applyPatches(document.content, [{ start, end, text: '' }]);
870
+ }
871
+ export async function readCodexConfigFile(configPath) {
872
+ const content = (await fs.pathExists(configPath))
873
+ ? await fs.readFile(configPath, 'utf8')
874
+ : '';
875
+ return {
876
+ content,
877
+ snapshot: parseCodexConfig(content),
878
+ };
879
+ }
880
+ export async function readRenderedCodexMcpServersFile(mcpPath) {
881
+ const content = await fs.readJson(mcpPath);
882
+ return parseRenderedCodexMcpFileContent(content, mcpPath);
883
+ }
884
+ export function applyCodexConfigTransaction(content, transaction) {
885
+ let next = content;
886
+ for (const serverName of [...new Set(transaction.removeMcpServers ?? [])]) {
887
+ next = removeCodexMcpServer(next, serverName);
888
+ }
889
+ for (const roleKey of [...new Set(transaction.removeAgentRegistrations ?? [])]) {
890
+ next = removeCodexAgentRegistration(next, roleKey);
891
+ }
892
+ for (const [serverName, serverConfig] of Object.entries(transaction.upsertMcpServers ?? {})) {
893
+ next = upsertCodexMcpServer(next, serverName, serverConfig);
894
+ }
895
+ for (const [roleKey, registration] of Object.entries(transaction.upsertAgentRegistrations ?? {})) {
896
+ next = upsertCodexAgentRegistration(next, roleKey, registration);
897
+ }
898
+ if (transaction.removeManagedInstructionPluginName) {
899
+ next = removeManagedDeveloperInstructions(next, transaction.removeManagedInstructionPluginName);
900
+ }
901
+ if (transaction.upsertManagedInstructionBlock) {
902
+ next = upsertManagedDeveloperInstructions(next, transaction.upsertManagedInstructionBlock);
903
+ }
904
+ return next;
905
+ }
906
+ async function replaceCodexConfigFile(configPath, content) {
907
+ await atomicReplaceConfigFile({
908
+ filePath: configPath,
909
+ allowedRoot: path.dirname(configPath),
910
+ content,
911
+ });
912
+ }
913
+ async function updateCodexConfigFile(configPath, update) {
914
+ return withConfigFileLock({
915
+ filePath: configPath,
916
+ allowedRoot: path.dirname(configPath),
917
+ action: async () => {
918
+ const current = (await fs.pathExists(configPath))
919
+ ? await fs.readFile(configPath, 'utf8')
920
+ : '';
921
+ const next = update(current);
922
+ await replaceCodexConfigFile(configPath, next);
923
+ return parseCodexConfig(next);
924
+ },
925
+ });
926
+ }
927
+ export async function applyCodexConfigTransactionFile(configPath, transaction) {
928
+ return withConfigFileLock({
929
+ filePath: configPath,
930
+ allowedRoot: path.dirname(configPath),
931
+ action: async () => {
932
+ const baselineExists = await fs.pathExists(configPath);
933
+ const baselineContent = baselineExists
934
+ ? await fs.readFile(configPath, 'utf8')
935
+ : null;
936
+ const baselineText = baselineContent ?? '';
937
+ const nextContent = applyCodexConfigTransaction(baselineText, transaction);
938
+ const baselineWithTerminalNewline = ensureTerminalNewline(baselineText);
939
+ const wrote = nextContent !== baselineWithTerminalNewline;
940
+ if (wrote) {
941
+ await replaceCodexConfigFile(configPath, nextContent);
942
+ }
943
+ return {
944
+ baselineContent,
945
+ content: nextContent,
946
+ snapshot: parseCodexConfig(nextContent),
947
+ wrote,
948
+ };
949
+ },
950
+ });
951
+ }
952
+ export async function applyConditionalCodexConfigTransactionFile(configPath, resolveTransaction) {
953
+ return withConfigFileLock({
954
+ filePath: configPath,
955
+ allowedRoot: path.dirname(configPath),
956
+ action: async () => {
957
+ const baselineExists = await fs.pathExists(configPath);
958
+ const baselineContent = baselineExists
959
+ ? await fs.readFile(configPath, 'utf8')
960
+ : null;
961
+ const baselineText = baselineContent ?? '';
962
+ const baselineSnapshot = parseCodexConfig(baselineText);
963
+ const transaction = await resolveTransaction(baselineSnapshot, baselineText);
964
+ if (!transaction) {
965
+ return {
966
+ baselineContent,
967
+ content: baselineText,
968
+ snapshot: baselineSnapshot,
969
+ wrote: false,
970
+ applied: false,
971
+ };
972
+ }
973
+ const nextContent = applyCodexConfigTransaction(baselineText, transaction);
974
+ const wrote = nextContent !== ensureTerminalNewline(baselineText);
975
+ if (wrote)
976
+ await replaceCodexConfigFile(configPath, nextContent);
977
+ return {
978
+ baselineContent,
979
+ content: nextContent,
980
+ snapshot: parseCodexConfig(nextContent),
981
+ wrote,
982
+ applied: true,
983
+ };
984
+ },
985
+ });
986
+ }
987
+ export async function upsertCodexMarketplaceFile(configPath, name, config) {
988
+ return updateCodexConfigFile(configPath, (current) => upsertCodexMarketplace(current, name, config));
989
+ }
990
+ export async function removeCodexMarketplaceFile(configPath, name) {
991
+ return updateCodexConfigFile(configPath, (current) => removeCodexMarketplace(current, name));
992
+ }
993
+ export async function upsertCodexPluginEnabledFile(configPath, name, config) {
994
+ return updateCodexConfigFile(configPath, (current) => upsertCodexPluginEnabled(current, name, config));
995
+ }
996
+ export async function removeCodexPluginEnabledFile(configPath, name) {
997
+ return updateCodexConfigFile(configPath, (current) => removeCodexPluginEnabled(current, name));
998
+ }
999
+ export async function upsertManagedDeveloperInstructionsFile(configPath, block) {
1000
+ return updateCodexConfigFile(configPath, (current) => upsertManagedDeveloperInstructions(current, block));
1001
+ }
1002
+ export async function removeManagedDeveloperInstructionsFile(configPath, pluginName) {
1003
+ return updateCodexConfigFile(configPath, (current) => removeManagedDeveloperInstructions(current, pluginName));
1004
+ }
1005
+ export function validateInstructionBodyForCodexConfig(value) {
1006
+ rejectSentinelPrefixedLines(value);
1007
+ }
1008
+ export function getAwManagedSentinelPrefix() {
1009
+ return AW_MANAGED_PREFIX;
1010
+ }
1011
+ //# sourceMappingURL=codex-config.js.map