@agent-native/core 0.111.4 → 0.113.0

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 (574) hide show
  1. package/corpus/README.md +4 -2
  2. package/corpus/core/CHANGELOG.md +34 -0
  3. package/corpus/core/docs/AGENTS.md +7 -0
  4. package/corpus/core/docs/content/integrations.mdx +63 -2
  5. package/corpus/core/docs/design/provider-integration-authority.md +117 -0
  6. package/corpus/core/package.json +8 -1
  7. package/corpus/core/scripts/materialize-source-corpus.mjs +9 -2
  8. package/corpus/core/src/cli/atomic-json-file.ts +324 -0
  9. package/corpus/core/src/cli/claude-code-participant.ts +515 -0
  10. package/corpus/core/src/cli/code-agent-executor.ts +35 -15
  11. package/corpus/core/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  12. package/corpus/core/src/cli/code-agent-runs.ts +70 -36
  13. package/corpus/core/src/cli/codex-cli-participant.ts +496 -0
  14. package/corpus/core/src/cli/multi-frontier-runs.ts +1952 -0
  15. package/corpus/core/src/client/chat/ChatHistoryList.tsx +7 -404
  16. package/corpus/core/src/coding-tools/index.ts +27 -8
  17. package/corpus/core/src/embeddings/index.ts +233 -0
  18. package/corpus/core/src/index.ts +2 -0
  19. package/corpus/core/src/integrations/index.ts +10 -0
  20. package/corpus/core/src/integrations/slack-oauth.ts +1 -0
  21. package/corpus/core/src/integrations/webhook-delivery.ts +55 -0
  22. package/corpus/core/src/notifications/channels.ts +4 -10
  23. package/corpus/core/src/provider-api/actions/custom-provider-registration.ts +197 -0
  24. package/corpus/core/src/provider-api/actions/delete-staged-dataset.ts +3 -42
  25. package/corpus/core/src/provider-api/actions/list-staged-datasets.ts +3 -45
  26. package/corpus/core/src/provider-api/actions/provider-api-audit.ts +88 -0
  27. package/corpus/core/src/provider-api/actions/provider-api.ts +460 -0
  28. package/corpus/core/src/provider-api/actions/query-staged-dataset.ts +3 -140
  29. package/corpus/core/src/provider-api/actions/staged-datasets.ts +359 -0
  30. package/corpus/core/src/provider-api/gong.ts +108 -0
  31. package/corpus/core/src/scripts/docs/source-search.ts +2 -1
  32. package/corpus/core/src/search/index.ts +413 -0
  33. package/corpus/core/src/server/google-oauth-credentials.ts +80 -3
  34. package/corpus/core/src/server/index.ts +6 -0
  35. package/corpus/core/src/styles/chat-history-list.css +1 -313
  36. package/corpus/core/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  37. package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  38. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  39. package/corpus/core/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  40. package/corpus/core/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  41. package/corpus/core/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  42. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  43. package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  44. package/corpus/core/src/templates/default/AGENTS.md +25 -18
  45. package/corpus/core/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  46. package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  47. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  48. package/corpus/core/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  49. package/corpus/core/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  50. package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  51. package/corpus/core/src/templates/headless/AGENTS.md +7 -0
  52. package/corpus/core/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  53. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  54. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  55. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  56. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  57. package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  58. package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -0
  59. package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -0
  60. package/corpus/templates/analytics/.agents/skills/actions/SKILL.md +32 -12
  61. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  62. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +11 -2
  63. package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  64. package/corpus/templates/analytics/actions/delete-staged-dataset.ts +3 -23
  65. package/corpus/templates/analytics/actions/list-staged-datasets.ts +3 -27
  66. package/corpus/templates/analytics/actions/provider-api-catalog.ts +16 -19
  67. package/corpus/templates/analytics/actions/provider-api-docs.ts +3 -5
  68. package/corpus/templates/analytics/actions/provider-api-request.ts +162 -185
  69. package/corpus/templates/analytics/actions/query-staged-dataset.ts +3 -47
  70. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +52 -161
  71. package/corpus/templates/assets/.agents/skills/actions/SKILL.md +32 -12
  72. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  73. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +11 -2
  74. package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  75. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +63 -160
  76. package/corpus/templates/brain/.agents/skills/actions/SKILL.md +32 -12
  77. package/corpus/templates/brain/.agents/skills/brain/RUNBOOK.md +48 -5
  78. package/corpus/templates/brain/.agents/skills/brain/SKILL.md +46 -14
  79. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  80. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +11 -2
  81. package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  82. package/corpus/templates/brain/README.md +34 -3
  83. package/corpus/templates/brain/actions/_schemas.ts +13 -7
  84. package/corpus/templates/brain/actions/approve-proposal.ts +2 -0
  85. package/corpus/templates/brain/actions/claim-distillation.ts +24 -27
  86. package/corpus/templates/brain/actions/create-source.ts +1 -1
  87. package/corpus/templates/brain/actions/delete-staged-dataset.ts +3 -24
  88. package/corpus/templates/brain/actions/get-knowledge.ts +6 -2
  89. package/corpus/templates/brain/actions/get-pilot-report.ts +44 -8
  90. package/corpus/templates/brain/actions/import-capture.ts +21 -9
  91. package/corpus/templates/brain/actions/import-transcript.ts +42 -14
  92. package/corpus/templates/brain/actions/list-captures.ts +10 -1
  93. package/corpus/templates/brain/actions/list-distillation-queue.ts +39 -14
  94. package/corpus/templates/brain/actions/list-projects.ts +51 -0
  95. package/corpus/templates/brain/actions/list-proposals.ts +80 -4
  96. package/corpus/templates/brain/actions/list-sources.ts +17 -3
  97. package/corpus/templates/brain/actions/list-staged-datasets.ts +3 -28
  98. package/corpus/templates/brain/actions/manage-project.ts +118 -0
  99. package/corpus/templates/brain/actions/mark-capture-distilled.ts +68 -20
  100. package/corpus/templates/brain/actions/navigate.ts +1 -0
  101. package/corpus/templates/brain/actions/provider-api-catalog.ts +5 -11
  102. package/corpus/templates/brain/actions/provider-api-docs.ts +3 -5
  103. package/corpus/templates/brain/actions/provider-api-request.ts +3 -37
  104. package/corpus/templates/brain/actions/query-staged-dataset.ts +3 -48
  105. package/corpus/templates/brain/actions/reject-proposal.ts +6 -1
  106. package/corpus/templates/brain/actions/resanitize-captures.ts +159 -33
  107. package/corpus/templates/brain/actions/review-proposal.ts +2 -0
  108. package/corpus/templates/brain/actions/search-everything.ts +10 -1
  109. package/corpus/templates/brain/actions/search-knowledge.ts +1 -1
  110. package/corpus/templates/brain/actions/set-settings.ts +36 -1
  111. package/corpus/templates/brain/actions/update-proposal.ts +2 -0
  112. package/corpus/templates/brain/actions/update-source.ts +5 -1
  113. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +48 -154
  114. package/corpus/templates/brain/app/hooks/use-distillation-bridge.ts +18 -9
  115. package/corpus/templates/brain/app/hooks/use-navigation-state.ts +3 -0
  116. package/corpus/templates/brain/app/i18n-data.ts +731 -2
  117. package/corpus/templates/brain/app/lib/brain.ts +88 -1
  118. package/corpus/templates/brain/app/lib/ingest-handoff.ts +35 -0
  119. package/corpus/templates/brain/app/routes/ops.tsx +47 -0
  120. package/corpus/templates/brain/app/routes/review.tsx +41 -2
  121. package/corpus/templates/brain/app/routes/search.tsx +33 -2
  122. package/corpus/templates/brain/app/routes/settings.tsx +158 -0
  123. package/corpus/templates/brain/app/routes/sources.tsx +31 -0
  124. package/corpus/templates/brain/changelog/2026-07-19-added-private-source-safe-semantic-search.md +6 -0
  125. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-can-now-join-configured-public-channels-befo.md +6 -0
  126. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-continue-across-the-configured-number-of.md +6 -0
  127. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-start-with-a-safe-four-week-window-and-r.md +6 -0
  128. package/corpus/templates/brain/jobs/process-ingest-queue.ts +270 -36
  129. package/corpus/templates/brain/package.json +1 -0
  130. package/corpus/templates/brain/server/db/index.ts +18 -0
  131. package/corpus/templates/brain/server/db/schema.ts +197 -1
  132. package/corpus/templates/brain/server/jobs/distillation-queue.ts +12 -5
  133. package/corpus/templates/brain/server/lib/audiences.ts +708 -0
  134. package/corpus/templates/brain/server/lib/brain-health.ts +251 -38
  135. package/corpus/templates/brain/server/lib/brain.ts +877 -50
  136. package/corpus/templates/brain/server/lib/capture-sanitization.ts +217 -53
  137. package/corpus/templates/brain/server/lib/connectors.ts +609 -72
  138. package/corpus/templates/brain/server/lib/demo.ts +17 -4
  139. package/corpus/templates/brain/server/lib/hybrid-search.ts +363 -0
  140. package/corpus/templates/brain/server/lib/ingest-queue.ts +104 -0
  141. package/corpus/templates/brain/server/lib/privacy-readiness.ts +24 -0
  142. package/corpus/templates/brain/server/lib/search-index-contracts.ts +72 -0
  143. package/corpus/templates/brain/server/lib/search-index.ts +714 -0
  144. package/corpus/templates/brain/server/lib/search.ts +120 -4
  145. package/corpus/templates/brain/server/lib/sensitivity-policy.ts +174 -0
  146. package/corpus/templates/brain/server/lib/slack-channel-membership.ts +44 -0
  147. package/corpus/templates/brain/server/lib/slack-events.ts +281 -0
  148. package/corpus/templates/brain/server/onboarding.ts +29 -0
  149. package/corpus/templates/brain/server/plugins/db.ts +204 -0
  150. package/corpus/templates/brain/server/register-secrets.ts +46 -0
  151. package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +36 -16
  152. package/corpus/templates/brain/server/routes/api/_agent-native/brain/slack-events.post.ts +28 -0
  153. package/corpus/templates/brain/shared/slack-source-config.ts +60 -0
  154. package/corpus/templates/brain/shared/types.ts +10 -0
  155. package/corpus/templates/calendar/.agents/skills/actions/SKILL.md +32 -12
  156. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  157. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +11 -2
  158. package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  159. package/corpus/templates/calendar/actions/delete-staged-dataset.ts +3 -24
  160. package/corpus/templates/calendar/actions/list-staged-datasets.ts +3 -28
  161. package/corpus/templates/calendar/actions/provider-api-catalog.ts +5 -11
  162. package/corpus/templates/calendar/actions/provider-api-docs.ts +3 -5
  163. package/corpus/templates/calendar/actions/provider-api-request.ts +3 -37
  164. package/corpus/templates/calendar/actions/query-staged-dataset.ts +3 -48
  165. package/corpus/templates/calendar/server/handlers/gong.ts +6 -61
  166. package/corpus/templates/calendar/server/handlers/google-auth.ts +10 -8
  167. package/corpus/templates/calendar/server/lib/google-calendar.ts +7 -45
  168. package/corpus/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  169. package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  170. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  171. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  172. package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  173. package/corpus/templates/chat/AGENTS.md +5 -2
  174. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  175. package/corpus/templates/clips/.agents/skills/actions/SKILL.md +32 -12
  176. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  177. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +11 -2
  178. package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  179. package/corpus/templates/clips/AGENTS.md +11 -0
  180. package/corpus/templates/clips/actions/export-to-brain.ts +505 -171
  181. package/corpus/templates/clips/changelog/2026-07-19-ready-clips-transcripts-can-be-backfilled-to-brain-for-a-bou.md +6 -0
  182. package/corpus/templates/clips/server/lib/calendar-event-meetings.ts +1 -1
  183. package/corpus/templates/clips/server/lib/google-calendar-client.ts +12 -22
  184. package/corpus/templates/clips/server/lib/google-calendar-oauth.ts +9 -6
  185. package/corpus/templates/clips/server/lib/slack-oauth.ts +12 -47
  186. package/corpus/templates/clips/server/routes/_agent-native/google/auth-url.get.ts +2 -6
  187. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +4 -4
  188. package/corpus/templates/content/.agents/skills/actions/SKILL.md +32 -12
  189. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  190. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +11 -2
  191. package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  192. package/corpus/templates/content/actions/delete-staged-dataset.ts +3 -24
  193. package/corpus/templates/content/actions/list-staged-datasets.ts +3 -28
  194. package/corpus/templates/content/actions/provider-api-catalog.ts +5 -11
  195. package/corpus/templates/content/actions/provider-api-docs.ts +3 -5
  196. package/corpus/templates/content/actions/provider-api-request.ts +3 -37
  197. package/corpus/templates/content/actions/query-staged-dataset.ts +3 -48
  198. package/corpus/templates/design/.agents/skills/actions/SKILL.md +32 -12
  199. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  200. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +11 -2
  201. package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  202. package/corpus/templates/design/actions/delete-staged-dataset.ts +4 -23
  203. package/corpus/templates/design/actions/list-staged-datasets.ts +4 -27
  204. package/corpus/templates/design/actions/provider-api-catalog.ts +15 -18
  205. package/corpus/templates/design/actions/provider-api-docs.ts +57 -48
  206. package/corpus/templates/design/actions/provider-api-request.ts +140 -164
  207. package/corpus/templates/design/actions/query-staged-dataset.ts +4 -47
  208. package/corpus/templates/dispatch/.agents/skills/actions/SKILL.md +32 -12
  209. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  210. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +11 -2
  211. package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  212. package/corpus/templates/dispatch/actions/delete-staged-dataset.ts +4 -23
  213. package/corpus/templates/dispatch/actions/list-staged-datasets.ts +4 -30
  214. package/corpus/templates/dispatch/actions/provider-api-catalog.ts +15 -18
  215. package/corpus/templates/dispatch/actions/provider-api-docs.ts +57 -48
  216. package/corpus/templates/dispatch/actions/provider-api-request.ts +138 -163
  217. package/corpus/templates/dispatch/actions/query-staged-dataset.ts +4 -47
  218. package/corpus/templates/forms/.agents/skills/actions/SKILL.md +32 -12
  219. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  220. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +11 -2
  221. package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  222. package/corpus/templates/forms/server/lib/integrations.ts +23 -22
  223. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  224. package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  225. package/corpus/templates/mail/.agents/skills/actions/SKILL.md +32 -12
  226. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  227. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +11 -2
  228. package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  229. package/corpus/templates/mail/actions/delete-staged-dataset.ts +4 -23
  230. package/corpus/templates/mail/actions/list-staged-datasets.ts +4 -27
  231. package/corpus/templates/mail/actions/provider-api-catalog.ts +15 -18
  232. package/corpus/templates/mail/actions/provider-api-docs.ts +57 -48
  233. package/corpus/templates/mail/actions/provider-api-request.ts +146 -173
  234. package/corpus/templates/mail/actions/query-staged-dataset.ts +4 -47
  235. package/corpus/templates/mail/server/handlers/gong.ts +6 -61
  236. package/corpus/templates/mail/server/lib/google-auth.ts +10 -13
  237. package/corpus/templates/plan/.agents/skills/actions/SKILL.md +32 -12
  238. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  239. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +11 -2
  240. package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  241. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +47 -156
  242. package/corpus/templates/slides/.agents/skills/actions/SKILL.md +32 -12
  243. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  244. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +11 -2
  245. package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  246. package/corpus/templates/slides/actions/delete-staged-dataset.ts +4 -23
  247. package/corpus/templates/slides/actions/list-staged-datasets.ts +4 -27
  248. package/corpus/templates/slides/actions/provider-api-catalog.ts +15 -18
  249. package/corpus/templates/slides/actions/provider-api-docs.ts +57 -48
  250. package/corpus/templates/slides/actions/provider-api-request.ts +145 -172
  251. package/corpus/templates/slides/actions/query-staged-dataset.ts +4 -47
  252. package/corpus/templates/slides/server/lib/google-docs-oauth.ts +11 -36
  253. package/corpus/templates/tasks/.agents/skills/actions/SKILL.md +32 -12
  254. package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +10 -0
  255. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  256. package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +11 -2
  257. package/corpus/templates/tasks/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  258. package/corpus/toolkit/CHANGELOG.md +125 -0
  259. package/corpus/toolkit/README.md +60 -0
  260. package/corpus/toolkit/export-snapshot.json +35 -0
  261. package/corpus/toolkit/migration-manifest.json +4 -0
  262. package/corpus/toolkit/package.json +281 -0
  263. package/corpus/toolkit/scripts/finalize-build.mjs +55 -0
  264. package/corpus/toolkit/src/app-shell/header-actions.tsx +84 -0
  265. package/corpus/toolkit/src/app-shell/index.ts +1 -0
  266. package/corpus/toolkit/src/chat-history/ChatHistoryList.tsx +469 -0
  267. package/corpus/toolkit/src/chat-history/index.ts +7 -0
  268. package/corpus/toolkit/src/chat-history.css +314 -0
  269. package/corpus/toolkit/src/collab-ui/AgentPresenceChip.tsx +69 -0
  270. package/corpus/toolkit/src/collab-ui/LiveCursorOverlay.tsx +241 -0
  271. package/corpus/toolkit/src/collab-ui/PresenceBar.tsx +346 -0
  272. package/corpus/toolkit/src/collab-ui/RecentEditHighlights.tsx +225 -0
  273. package/corpus/toolkit/src/collab-ui/RemoteSelectionRings.tsx +227 -0
  274. package/corpus/toolkit/src/collab-ui/agent-identity.ts +16 -0
  275. package/corpus/toolkit/src/collab-ui/index.ts +39 -0
  276. package/corpus/toolkit/src/collab-ui/lead-client.ts +32 -0
  277. package/corpus/toolkit/src/collab-ui/types.ts +96 -0
  278. package/corpus/toolkit/src/composer/AgentComposerFrame.tsx +59 -0
  279. package/corpus/toolkit/src/composer/ComposerPlusMenu.tsx +983 -0
  280. package/corpus/toolkit/src/composer/MentionPopover.tsx +412 -0
  281. package/corpus/toolkit/src/composer/PastedTextChip.tsx +150 -0
  282. package/corpus/toolkit/src/composer/PromptComposer.tsx +718 -0
  283. package/corpus/toolkit/src/composer/RealtimeVoiceMode.tsx +856 -0
  284. package/corpus/toolkit/src/composer/TiptapComposer.tsx +2936 -0
  285. package/corpus/toolkit/src/composer/VoiceButton.tsx +255 -0
  286. package/corpus/toolkit/src/composer/asset-picker-url.ts +80 -0
  287. package/corpus/toolkit/src/composer/attachment-accept.ts +71 -0
  288. package/corpus/toolkit/src/composer/draft-key.ts +7 -0
  289. package/corpus/toolkit/src/composer/extensions/FileReference.tsx +55 -0
  290. package/corpus/toolkit/src/composer/extensions/MentionReference.tsx +93 -0
  291. package/corpus/toolkit/src/composer/extensions/SkillReference.tsx +56 -0
  292. package/corpus/toolkit/src/composer/index.ts +79 -0
  293. package/corpus/toolkit/src/composer/pasted-text.ts +160 -0
  294. package/corpus/toolkit/src/composer/prompt-attachments.ts +93 -0
  295. package/corpus/toolkit/src/composer/realtime-voice-audio-level.ts +64 -0
  296. package/corpus/toolkit/src/composer/realtime-voice-transcript.ts +134 -0
  297. package/corpus/toolkit/src/composer/runtime-adapters.tsx +343 -0
  298. package/corpus/toolkit/src/composer/types.ts +66 -0
  299. package/corpus/toolkit/src/composer/use-file-search.ts +64 -0
  300. package/corpus/toolkit/src/composer/use-mention-search.ts +90 -0
  301. package/corpus/toolkit/src/composer/use-skills.ts +45 -0
  302. package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +2117 -0
  303. package/corpus/toolkit/src/composer/useVoiceDictation.ts +1191 -0
  304. package/corpus/toolkit/src/context-ui/ContextMeter.tsx +101 -0
  305. package/corpus/toolkit/src/context-ui/ContextSegmentRow.tsx +184 -0
  306. package/corpus/toolkit/src/context-ui/ContextTreemap.tsx +125 -0
  307. package/corpus/toolkit/src/context-ui/ContextXRayPanel.tsx +377 -0
  308. package/corpus/toolkit/src/context-ui/format.ts +42 -0
  309. package/corpus/toolkit/src/context-ui/index.ts +15 -0
  310. package/corpus/toolkit/src/context-ui/types.ts +43 -0
  311. package/corpus/toolkit/src/design-tweaks/index.ts +1 -0
  312. package/corpus/toolkit/src/design-tweaks/visual-style-controls.tsx +1084 -0
  313. package/corpus/toolkit/src/editor/BubbleToolbar.tsx +253 -0
  314. package/corpus/toolkit/src/editor/CodeBlockNode.tsx +254 -0
  315. package/corpus/toolkit/src/editor/DragHandle.ts +1437 -0
  316. package/corpus/toolkit/src/editor/ImageExtension.ts +306 -0
  317. package/corpus/toolkit/src/editor/RegistryBlockContext.tsx +107 -0
  318. package/corpus/toolkit/src/editor/RegistryBlockNode.tsx +652 -0
  319. package/corpus/toolkit/src/editor/RichMarkdownEditor.tsx +81 -0
  320. package/corpus/toolkit/src/editor/RunId.ts +61 -0
  321. package/corpus/toolkit/src/editor/SharedRichEditor.tsx +321 -0
  322. package/corpus/toolkit/src/editor/SlashCommandMenu.tsx +310 -0
  323. package/corpus/toolkit/src/editor/extensions.ts +402 -0
  324. package/corpus/toolkit/src/editor/gfmDoc.ts +92 -0
  325. package/corpus/toolkit/src/editor/index.ts +93 -0
  326. package/corpus/toolkit/src/editor/registrySlashCommands.ts +131 -0
  327. package/corpus/toolkit/src/editor/surgical-apply.ts +192 -0
  328. package/corpus/toolkit/src/editor/useCollabReconcile.ts +589 -0
  329. package/corpus/toolkit/src/editor.css +510 -0
  330. package/corpus/toolkit/src/hooks/index.ts +2 -0
  331. package/corpus/toolkit/src/hooks/use-mobile.tsx +21 -0
  332. package/corpus/toolkit/src/hooks/use-toast.ts +188 -0
  333. package/corpus/toolkit/src/index.ts +8 -0
  334. package/corpus/toolkit/src/onboarding/index.ts +1 -0
  335. package/corpus/toolkit/src/provider.tsx +47 -0
  336. package/corpus/toolkit/src/sharing/VisibilityBadge.tsx +37 -0
  337. package/corpus/toolkit/src/sharing/index.ts +4 -0
  338. package/corpus/toolkit/src/styles.css +21 -0
  339. package/corpus/toolkit/src/ui/accordion.tsx +56 -0
  340. package/corpus/toolkit/src/ui/alert-dialog.tsx +141 -0
  341. package/corpus/toolkit/src/ui/alert.tsx +59 -0
  342. package/corpus/toolkit/src/ui/aspect-ratio.tsx +5 -0
  343. package/corpus/toolkit/src/ui/avatar.tsx +48 -0
  344. package/corpus/toolkit/src/ui/badge.tsx +37 -0
  345. package/corpus/toolkit/src/ui/breadcrumb.tsx +115 -0
  346. package/corpus/toolkit/src/ui/button.tsx +78 -0
  347. package/corpus/toolkit/src/ui/calendar.tsx +214 -0
  348. package/corpus/toolkit/src/ui/card.tsx +86 -0
  349. package/corpus/toolkit/src/ui/carousel.tsx +260 -0
  350. package/corpus/toolkit/src/ui/chart.tsx +375 -0
  351. package/corpus/toolkit/src/ui/checkbox.tsx +28 -0
  352. package/corpus/toolkit/src/ui/collapsible.tsx +9 -0
  353. package/corpus/toolkit/src/ui/command.tsx +174 -0
  354. package/corpus/toolkit/src/ui/context-menu.tsx +202 -0
  355. package/corpus/toolkit/src/ui/date-picker.tsx +64 -0
  356. package/corpus/toolkit/src/ui/dialog.tsx +146 -0
  357. package/corpus/toolkit/src/ui/drawer.tsx +126 -0
  358. package/corpus/toolkit/src/ui/dropdown-menu.tsx +218 -0
  359. package/corpus/toolkit/src/ui/form.tsx +177 -0
  360. package/corpus/toolkit/src/ui/hover-card.tsx +27 -0
  361. package/corpus/toolkit/src/ui/index.ts +52 -0
  362. package/corpus/toolkit/src/ui/input-otp.tsx +69 -0
  363. package/corpus/toolkit/src/ui/input.tsx +22 -0
  364. package/corpus/toolkit/src/ui/label.tsx +24 -0
  365. package/corpus/toolkit/src/ui/logo.tsx +36 -0
  366. package/corpus/toolkit/src/ui/menubar.tsx +235 -0
  367. package/corpus/toolkit/src/ui/navigation-menu.tsx +128 -0
  368. package/corpus/toolkit/src/ui/pagination.tsx +121 -0
  369. package/corpus/toolkit/src/ui/popover.tsx +44 -0
  370. package/corpus/toolkit/src/ui/progress.tsx +26 -0
  371. package/corpus/toolkit/src/ui/radio-group.tsx +42 -0
  372. package/corpus/toolkit/src/ui/resizable.tsx +43 -0
  373. package/corpus/toolkit/src/ui/scroll-area.tsx +46 -0
  374. package/corpus/toolkit/src/ui/select.tsx +158 -0
  375. package/corpus/toolkit/src/ui/separator.tsx +29 -0
  376. package/corpus/toolkit/src/ui/sheet.tsx +160 -0
  377. package/corpus/toolkit/src/ui/sidebar.tsx +777 -0
  378. package/corpus/toolkit/src/ui/skeleton.tsx +18 -0
  379. package/corpus/toolkit/src/ui/slider.tsx +26 -0
  380. package/corpus/toolkit/src/ui/sonner.tsx +58 -0
  381. package/corpus/toolkit/src/ui/spinner.tsx +17 -0
  382. package/corpus/toolkit/src/ui/switch.tsx +27 -0
  383. package/corpus/toolkit/src/ui/table.tsx +117 -0
  384. package/corpus/toolkit/src/ui/tabs.tsx +53 -0
  385. package/corpus/toolkit/src/ui/textarea.tsx +23 -0
  386. package/corpus/toolkit/src/ui/toast.tsx +127 -0
  387. package/corpus/toolkit/src/ui/toaster.tsx +33 -0
  388. package/corpus/toolkit/src/ui/toggle-group.tsx +59 -0
  389. package/corpus/toolkit/src/ui/toggle.tsx +43 -0
  390. package/corpus/toolkit/src/ui/tooltip.tsx +53 -0
  391. package/corpus/toolkit/src/ui/use-toast.ts +3 -0
  392. package/corpus/toolkit/src/utils.ts +8 -0
  393. package/corpus/toolkit/tsconfig.json +23 -0
  394. package/dist/cli/atomic-json-file.d.ts +30 -0
  395. package/dist/cli/atomic-json-file.d.ts.map +1 -0
  396. package/dist/cli/atomic-json-file.js +240 -0
  397. package/dist/cli/atomic-json-file.js.map +1 -0
  398. package/dist/cli/claude-code-participant.d.ts +77 -0
  399. package/dist/cli/claude-code-participant.d.ts.map +1 -0
  400. package/dist/cli/claude-code-participant.js +355 -0
  401. package/dist/cli/claude-code-participant.js.map +1 -0
  402. package/dist/cli/code-agent-executor.d.ts +8 -9
  403. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  404. package/dist/cli/code-agent-executor.js +27 -13
  405. package/dist/cli/code-agent-executor.js.map +1 -1
  406. package/dist/cli/code-agent-runs.concurrent-worker.d.ts +2 -0
  407. package/dist/cli/code-agent-runs.concurrent-worker.d.ts.map +1 -0
  408. package/dist/cli/code-agent-runs.concurrent-worker.js +32 -0
  409. package/dist/cli/code-agent-runs.concurrent-worker.js.map +1 -0
  410. package/dist/cli/code-agent-runs.d.ts +5 -0
  411. package/dist/cli/code-agent-runs.d.ts.map +1 -1
  412. package/dist/cli/code-agent-runs.js +51 -33
  413. package/dist/cli/code-agent-runs.js.map +1 -1
  414. package/dist/cli/codex-cli-participant.d.ts +77 -0
  415. package/dist/cli/codex-cli-participant.d.ts.map +1 -0
  416. package/dist/cli/codex-cli-participant.js +354 -0
  417. package/dist/cli/codex-cli-participant.js.map +1 -0
  418. package/dist/cli/multi-frontier-runs.d.ts +246 -0
  419. package/dist/cli/multi-frontier-runs.d.ts.map +1 -0
  420. package/dist/cli/multi-frontier-runs.js +1247 -0
  421. package/dist/cli/multi-frontier-runs.js.map +1 -0
  422. package/dist/client/chat/ChatHistoryList.d.ts +1 -87
  423. package/dist/client/chat/ChatHistoryList.d.ts.map +1 -1
  424. package/dist/client/chat/ChatHistoryList.js +1 -82
  425. package/dist/client/chat/ChatHistoryList.js.map +1 -1
  426. package/dist/coding-tools/index.d.ts +1 -0
  427. package/dist/coding-tools/index.d.ts.map +1 -1
  428. package/dist/coding-tools/index.js +25 -7
  429. package/dist/coding-tools/index.js.map +1 -1
  430. package/dist/collab/awareness.d.ts +2 -2
  431. package/dist/collab/awareness.d.ts.map +1 -1
  432. package/dist/embeddings/index.d.ts +24 -0
  433. package/dist/embeddings/index.d.ts.map +1 -0
  434. package/dist/embeddings/index.js +172 -0
  435. package/dist/embeddings/index.js.map +1 -0
  436. package/dist/index.d.ts +2 -0
  437. package/dist/index.d.ts.map +1 -1
  438. package/dist/index.js +2 -0
  439. package/dist/index.js.map +1 -1
  440. package/dist/integrations/index.d.ts +2 -1
  441. package/dist/integrations/index.d.ts.map +1 -1
  442. package/dist/integrations/index.js +2 -1
  443. package/dist/integrations/index.js.map +1 -1
  444. package/dist/integrations/slack-manifest.d.ts +1 -1
  445. package/dist/integrations/slack-oauth.d.ts +1 -1
  446. package/dist/integrations/slack-oauth.d.ts.map +1 -1
  447. package/dist/integrations/slack-oauth.js +1 -0
  448. package/dist/integrations/slack-oauth.js.map +1 -1
  449. package/dist/integrations/webhook-delivery.d.ts +23 -0
  450. package/dist/integrations/webhook-delivery.d.ts.map +1 -0
  451. package/dist/integrations/webhook-delivery.js +32 -0
  452. package/dist/integrations/webhook-delivery.js.map +1 -0
  453. package/dist/notifications/channels.d.ts.map +1 -1
  454. package/dist/notifications/channels.js +4 -9
  455. package/dist/notifications/channels.js.map +1 -1
  456. package/dist/notifications/routes.d.ts +3 -3
  457. package/dist/progress/routes.d.ts +1 -1
  458. package/dist/provider-api/actions/custom-provider-registration.d.ts +136 -0
  459. package/dist/provider-api/actions/custom-provider-registration.d.ts.map +1 -0
  460. package/dist/provider-api/actions/custom-provider-registration.js +154 -0
  461. package/dist/provider-api/actions/custom-provider-registration.js.map +1 -0
  462. package/dist/provider-api/actions/delete-staged-dataset.d.ts +1 -1
  463. package/dist/provider-api/actions/delete-staged-dataset.d.ts.map +1 -1
  464. package/dist/provider-api/actions/delete-staged-dataset.js +3 -34
  465. package/dist/provider-api/actions/delete-staged-dataset.js.map +1 -1
  466. package/dist/provider-api/actions/list-staged-datasets.d.ts +2 -3
  467. package/dist/provider-api/actions/list-staged-datasets.d.ts.map +1 -1
  468. package/dist/provider-api/actions/list-staged-datasets.js +3 -40
  469. package/dist/provider-api/actions/list-staged-datasets.js.map +1 -1
  470. package/dist/provider-api/actions/provider-api-audit.d.ts +7 -0
  471. package/dist/provider-api/actions/provider-api-audit.d.ts.map +1 -0
  472. package/dist/provider-api/actions/provider-api-audit.js +74 -0
  473. package/dist/provider-api/actions/provider-api-audit.js.map +1 -0
  474. package/dist/provider-api/actions/provider-api.d.ts +370 -0
  475. package/dist/provider-api/actions/provider-api.d.ts.map +1 -0
  476. package/dist/provider-api/actions/provider-api.js +280 -0
  477. package/dist/provider-api/actions/provider-api.js.map +1 -0
  478. package/dist/provider-api/actions/query-staged-dataset.d.ts +1 -1
  479. package/dist/provider-api/actions/query-staged-dataset.d.ts.map +1 -1
  480. package/dist/provider-api/actions/query-staged-dataset.js +3 -116
  481. package/dist/provider-api/actions/query-staged-dataset.js.map +1 -1
  482. package/dist/provider-api/actions/staged-datasets.d.ts +190 -0
  483. package/dist/provider-api/actions/staged-datasets.d.ts.map +1 -0
  484. package/dist/provider-api/actions/staged-datasets.js +210 -0
  485. package/dist/provider-api/actions/staged-datasets.js.map +1 -0
  486. package/dist/provider-api/gong.d.ts +44 -0
  487. package/dist/provider-api/gong.d.ts.map +1 -0
  488. package/dist/provider-api/gong.js +56 -0
  489. package/dist/provider-api/gong.js.map +1 -0
  490. package/dist/resources/handlers.d.ts +1 -1
  491. package/dist/scripts/docs/source-search.d.ts +2 -1
  492. package/dist/scripts/docs/source-search.d.ts.map +1 -1
  493. package/dist/scripts/docs/source-search.js +2 -1
  494. package/dist/scripts/docs/source-search.js.map +1 -1
  495. package/dist/search/index.d.ts +88 -0
  496. package/dist/search/index.d.ts.map +1 -0
  497. package/dist/search/index.js +267 -0
  498. package/dist/search/index.js.map +1 -0
  499. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  500. package/dist/server/google-oauth-credentials.d.ts +35 -0
  501. package/dist/server/google-oauth-credentials.d.ts.map +1 -1
  502. package/dist/server/google-oauth-credentials.js +48 -2
  503. package/dist/server/google-oauth-credentials.js.map +1 -1
  504. package/dist/server/index.d.ts +1 -1
  505. package/dist/server/index.d.ts.map +1 -1
  506. package/dist/server/index.js +1 -1
  507. package/dist/server/index.js.map +1 -1
  508. package/dist/styles/chat-history-list.css +1 -313
  509. package/dist/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  510. package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  511. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  512. package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  513. package/dist/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  514. package/dist/templates/chat/AGENTS.md +5 -2
  515. package/dist/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  516. package/dist/templates/default/.agents/skills/actions/SKILL.md +32 -12
  517. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  518. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  519. package/dist/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  520. package/dist/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  521. package/dist/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  522. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  523. package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  524. package/dist/templates/default/AGENTS.md +25 -18
  525. package/dist/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  526. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  527. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  528. package/dist/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  529. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  530. package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  531. package/dist/templates/headless/AGENTS.md +7 -0
  532. package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  533. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  534. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  535. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  536. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  537. package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  538. package/dist/templates/workspace-core/AGENTS.md +4 -0
  539. package/dist/templates/workspace-root/AGENTS.md +4 -0
  540. package/docs/AGENTS.md +7 -0
  541. package/docs/content/integrations.mdx +63 -2
  542. package/docs/design/provider-integration-authority.md +117 -0
  543. package/package.json +9 -2
  544. package/src/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  545. package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  546. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  547. package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  548. package/src/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  549. package/src/templates/chat/AGENTS.md +5 -2
  550. package/src/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  551. package/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  552. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  553. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  554. package/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  555. package/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  556. package/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  557. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  558. package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  559. package/src/templates/default/AGENTS.md +25 -18
  560. package/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  561. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  562. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  563. package/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  564. package/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  565. package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  566. package/src/templates/headless/AGENTS.md +7 -0
  567. package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  568. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  569. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  570. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  571. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  572. package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  573. package/src/templates/workspace-core/AGENTS.md +4 -0
  574. package/src/templates/workspace-root/AGENTS.md +4 -0
@@ -0,0 +1,354 @@
1
+ import { execFile as execFileCallback, spawn } from "node:child_process";
2
+ import { isAbsolute } from "node:path";
3
+ import { StringDecoder } from "node:string_decoder";
4
+ import { promisify } from "node:util";
5
+ const execFile = promisify(execFileCallback);
6
+ const CODEX_CLI_VERSION = "0.144.3";
7
+ const DEFAULT_MAX_EVENTS = 2_000;
8
+ const DEFAULT_MAX_STREAM_BYTES = 8 * 1024 * 1024;
9
+ const DEFAULT_MAX_STDERR_BYTES = 128 * 1024;
10
+ const DEFAULT_TIMEOUT_MS = 30 * 60 * 1_000;
11
+ const DEFAULT_TERMINATION_GRACE_MS = 2_000;
12
+ const DEFAULT_FORCE_SETTLE_MS = 250;
13
+ const MAX_ERROR_MESSAGE_LENGTH = 200;
14
+ const SAFE_ENVIRONMENT_KEYS = [
15
+ "PATH",
16
+ "HOME",
17
+ "LANG",
18
+ "LC_ALL",
19
+ "LC_CTYPE",
20
+ "TMPDIR",
21
+ "TMP",
22
+ "TEMP",
23
+ "TERM",
24
+ "NO_COLOR",
25
+ "FORCE_COLOR",
26
+ "USER",
27
+ "LOGNAME",
28
+ "SHELL",
29
+ // Codex reads its subscription session from this config root (or HOME/.codex).
30
+ "CODEX_HOME",
31
+ ];
32
+ export class CodexCliSubscriptionRequiredError extends Error {
33
+ constructor() {
34
+ super("Codex CLI must be signed in with a ChatGPT subscription. API-key fallback is disabled.");
35
+ this.name = "CodexCliSubscriptionRequiredError";
36
+ }
37
+ }
38
+ export async function readCodexCliSubscriptionStatus(options = {}) {
39
+ try {
40
+ const execute = options.execute ?? execFile;
41
+ const { stdout, stderr } = await execute(resolveCommand(options.command, "codex"), ["login", "status"], {
42
+ encoding: "utf8",
43
+ maxBuffer: 128 * 1024,
44
+ timeout: 3_000,
45
+ windowsHide: true,
46
+ env: safeEnvironment(options.env ?? process.env),
47
+ });
48
+ const output = `${stdout}\n${stderr}`;
49
+ return {
50
+ loggedIn: /logged in using/i.test(output),
51
+ authMode: /logged in using\s+chatgpt/i.test(output)
52
+ ? "ChatGPT"
53
+ : /logged in using\s+(?:an?\s+)?api key/i.test(output)
54
+ ? "API key"
55
+ : "unknown",
56
+ };
57
+ }
58
+ catch {
59
+ return { loggedIn: false };
60
+ }
61
+ }
62
+ export async function runCodexCliParticipant(options) {
63
+ validateInput(options);
64
+ const env = safeEnvironment(options.env ?? process.env);
65
+ const command = resolveCommand(options.command, "codex");
66
+ const subscription = await (options.preflight
67
+ ? options.preflight({ command, env })
68
+ : readCodexCliSubscriptionStatus({ command, env }));
69
+ if (!subscription.loggedIn || subscription.authMode !== "ChatGPT") {
70
+ throw new CodexCliSubscriptionRequiredError();
71
+ }
72
+ if (options.signal?.aborted)
73
+ throw createAbortError();
74
+ const args = buildCodexCliParticipantArgs(options);
75
+ const spawnProcess = options.spawnProcess ??
76
+ ((command, commandArgs, spawnOptions) => spawn(command, commandArgs, spawnOptions));
77
+ const child = spawnProcess(command, args, {
78
+ cwd: options.cwd,
79
+ env,
80
+ shell: false,
81
+ stdio: ["pipe", "pipe", "pipe"],
82
+ });
83
+ return collectCodexCliParticipantResult(child, options);
84
+ }
85
+ export function buildCodexCliParticipantArgs(options) {
86
+ const sandbox = options.role === "driver" && options.allowWorkspaceWrite === true
87
+ ? "workspace-write"
88
+ : "read-only";
89
+ const args = [
90
+ "--ask-for-approval",
91
+ "never",
92
+ "--sandbox",
93
+ sandbox,
94
+ "--cd",
95
+ options.cwd,
96
+ "exec",
97
+ ];
98
+ const resumeSessionId = readString(options.session?.resumeSessionId);
99
+ if (resumeSessionId)
100
+ args.push("resume");
101
+ args.push("--json", "--skip-git-repo-check", "--ignore-user-config");
102
+ const model = readString(options.model);
103
+ if (model)
104
+ args.push("--model", model);
105
+ if (resumeSessionId)
106
+ args.push("--", resumeSessionId, "-");
107
+ else
108
+ args.push("-");
109
+ return args;
110
+ }
111
+ function collectCodexCliParticipantResult(child, options) {
112
+ const maxEvents = boundedLimit(options.maxEvents, DEFAULT_MAX_EVENTS);
113
+ const maxStreamBytes = boundedLimit(options.maxStreamBytes, DEFAULT_MAX_STREAM_BYTES);
114
+ const maxStderrBytes = boundedLimit(options.maxStderrBytes, DEFAULT_MAX_STDERR_BYTES);
115
+ const timeoutMs = boundedDuration(options.timeoutMs, DEFAULT_TIMEOUT_MS);
116
+ const terminationGraceMs = boundedDuration(options.terminationGraceMs, DEFAULT_TERMINATION_GRACE_MS);
117
+ const forceSettleMs = boundedDuration(options.forceSettleMs, DEFAULT_FORCE_SETTLE_MS);
118
+ const decoder = new StringDecoder("utf8");
119
+ const stderrDecoder = new StringDecoder("utf8");
120
+ const events = [];
121
+ let pending = "";
122
+ let streamBytes = 0;
123
+ let stderr = "";
124
+ let stderrBytes = 0;
125
+ let stderrTruncated = false;
126
+ let fatalError;
127
+ let resumeSessionId;
128
+ return new Promise((resolve, reject) => {
129
+ let settled = false;
130
+ let terminationTimer;
131
+ let forceSettleTimer;
132
+ const timeoutTimer = setTimeout(() => {
133
+ stopWithError(new Error(`Codex CLI timed out after ${timeoutMs}ms.`));
134
+ }, timeoutMs);
135
+ timeoutTimer.unref?.();
136
+ const cleanup = () => {
137
+ options.signal?.removeEventListener("abort", abort);
138
+ clearTimeout(timeoutTimer);
139
+ if (terminationTimer)
140
+ clearTimeout(terminationTimer);
141
+ if (forceSettleTimer)
142
+ clearTimeout(forceSettleTimer);
143
+ };
144
+ const finishError = (error) => {
145
+ if (settled)
146
+ return;
147
+ settled = true;
148
+ cleanup();
149
+ reject(safeError(error));
150
+ };
151
+ const stopWithError = (error) => {
152
+ if (fatalError)
153
+ return;
154
+ fatalError = error;
155
+ terminationTimer = setTimeout(() => {
156
+ if (settled)
157
+ return;
158
+ forceSettleTimer = setTimeout(() => {
159
+ finishError(fatalError ?? error);
160
+ }, forceSettleMs);
161
+ forceSettleTimer.unref?.();
162
+ child.kill("SIGKILL");
163
+ }, terminationGraceMs);
164
+ terminationTimer.unref?.();
165
+ child.kill("SIGTERM");
166
+ };
167
+ const abort = () => stopWithError(createAbortError());
168
+ const streamError = (error) => {
169
+ if (!settled)
170
+ stopWithError(error);
171
+ };
172
+ const consume = (line) => {
173
+ const event = consumeJsonLine(line, events, maxEvents, options.onEvent);
174
+ const threadId = readString(event?.thread_id);
175
+ if (event?.type === "thread.started" && threadId) {
176
+ resumeSessionId = threadId;
177
+ }
178
+ };
179
+ child.stdin.on("error", streamError);
180
+ child.stdout.on("error", streamError);
181
+ child.stderr.on("error", streamError);
182
+ if (options.signal) {
183
+ if (options.signal.aborted)
184
+ abort();
185
+ else
186
+ options.signal.addEventListener("abort", abort, { once: true });
187
+ }
188
+ child.stdout.on("data", (chunk) => {
189
+ if (fatalError)
190
+ return;
191
+ const bytes = Buffer.isBuffer(chunk)
192
+ ? chunk.length
193
+ : Buffer.byteLength(chunk);
194
+ streamBytes += bytes;
195
+ if (streamBytes > maxStreamBytes) {
196
+ stopWithError(new Error(`Codex CLI stream exceeded ${maxStreamBytes} bytes.`));
197
+ return;
198
+ }
199
+ pending += decoder.write(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
200
+ try {
201
+ let newline = pending.indexOf("\n");
202
+ while (newline !== -1) {
203
+ consume(pending.slice(0, newline));
204
+ pending = pending.slice(newline + 1);
205
+ newline = pending.indexOf("\n");
206
+ }
207
+ }
208
+ catch (error) {
209
+ stopWithError(toError(error));
210
+ }
211
+ });
212
+ child.stderr.on("data", (chunk) => {
213
+ const encoded = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
214
+ const remaining = Math.max(0, maxStderrBytes - stderrBytes);
215
+ if (remaining === 0) {
216
+ stderrTruncated = true;
217
+ return;
218
+ }
219
+ stderr += stderrDecoder.write(encoded.subarray(0, remaining));
220
+ stderrBytes += Math.min(encoded.length, remaining);
221
+ if (encoded.length > remaining)
222
+ stderrTruncated = true;
223
+ });
224
+ child.once("error", finishError);
225
+ child.once("close", (exitCode, exitSignal) => {
226
+ if (settled)
227
+ return;
228
+ try {
229
+ pending += decoder.end();
230
+ stderr += stderrDecoder.end();
231
+ if (pending.trim())
232
+ consume(pending);
233
+ }
234
+ catch (error) {
235
+ fatalError ??= toError(error);
236
+ }
237
+ if (fatalError) {
238
+ finishError(fatalError);
239
+ return;
240
+ }
241
+ if (exitCode !== 0) {
242
+ finishError(new Error(`Codex CLI exited with ${exitSignal ?? exitCode ?? "unknown"}${stderr ? `: ${summarizeStderr(stderr)}` : ""}`));
243
+ return;
244
+ }
245
+ settled = true;
246
+ cleanup();
247
+ resolve({
248
+ exitCode: 0,
249
+ events,
250
+ stderr: sanitizeStderr(stderr),
251
+ stderrTruncated,
252
+ ...(resumeSessionId ? { resumeSessionId } : {}),
253
+ });
254
+ });
255
+ try {
256
+ child.stdin.end(options.prompt);
257
+ }
258
+ catch (error) {
259
+ stopWithError(toError(error));
260
+ }
261
+ });
262
+ }
263
+ function consumeJsonLine(line, events, maxEvents, onEvent) {
264
+ const trimmed = line.trim();
265
+ if (!trimmed)
266
+ return undefined;
267
+ if (events.length >= maxEvents) {
268
+ throw new Error(`Codex CLI stream exceeded ${maxEvents} events.`);
269
+ }
270
+ const parsed = JSON.parse(trimmed);
271
+ const event = asRecord(parsed);
272
+ if (!event)
273
+ throw new Error("Codex CLI emitted a non-object JSON event.");
274
+ events.push(event);
275
+ onEvent?.(event);
276
+ return event;
277
+ }
278
+ function safeEnvironment(input) {
279
+ return Object.fromEntries(SAFE_ENVIRONMENT_KEYS.flatMap((key) => typeof input[key] === "string" ? [[key, input[key]]] : []));
280
+ }
281
+ function validateInput(options) {
282
+ if (!readString(options.prompt))
283
+ throw new Error("Codex CLI prompt is required.");
284
+ if (!readString(options.cwd))
285
+ throw new Error("Codex CLI cwd is required.");
286
+ if (options.allowWorkspaceWrite && options.role !== "driver") {
287
+ throw new Error("Only a Codex driver can receive workspace-write access.");
288
+ }
289
+ const model = readString(options.model);
290
+ if (model?.startsWith("-"))
291
+ throw new Error("Codex CLI model is invalid.");
292
+ const resumeSessionId = readString(options.session?.resumeSessionId);
293
+ if (resumeSessionId?.includes("\0")) {
294
+ throw new Error("Codex CLI resume state is invalid.");
295
+ }
296
+ resolveCommand(options.command, "codex");
297
+ }
298
+ function boundedLimit(value, maximum) {
299
+ return Number.isSafeInteger(value) && (value ?? 0) > 0
300
+ ? Math.min(value, maximum)
301
+ : maximum;
302
+ }
303
+ function boundedDuration(value, fallback) {
304
+ return Number.isSafeInteger(value) && (value ?? 0) > 0
305
+ ? Math.min(value, DEFAULT_TIMEOUT_MS)
306
+ : fallback;
307
+ }
308
+ function resolveCommand(command, defaultCommand) {
309
+ const value = readString(command) ?? defaultCommand;
310
+ if (value === defaultCommand)
311
+ return value;
312
+ if (value.includes("\0") || !isAbsolute(value)) {
313
+ throw new Error("Codex CLI command must be an absolute executable path.");
314
+ }
315
+ return value;
316
+ }
317
+ function createAbortError() {
318
+ const error = new Error("Codex CLI participant was canceled.");
319
+ error.name = "AbortError";
320
+ return error;
321
+ }
322
+ function toError(value) {
323
+ return value instanceof Error ? value : new Error(String(value));
324
+ }
325
+ function safeError(error) {
326
+ const safe = new Error(summarizeStderr(error.message));
327
+ safe.name = error.name;
328
+ return safe;
329
+ }
330
+ function summarizeStderr(value) {
331
+ return sanitizeStderr(value)
332
+ .replace(/\s+/g, " ")
333
+ .trim()
334
+ .slice(0, MAX_ERROR_MESSAGE_LENGTH);
335
+ }
336
+ function sanitizeStderr(value) {
337
+ return value
338
+ .replace(/\bBearer\s+\S+/gi, "Bearer <redacted>")
339
+ .replace(/(["']?)([A-Za-z_]*(?:token|key|secret|password)[A-Za-z_]*)\1\s*([=:])\s*(?:"[^"]*"|'[^']*'|[^\s,;}\]]+)/gi, '$1$2$1$3"<redacted>"')
340
+ .replace(/\b(?:sk|rk)-[A-Za-z0-9_-]{8,}\b/g, "<redacted>");
341
+ }
342
+ function readString(value) {
343
+ if (typeof value !== "string")
344
+ return undefined;
345
+ const trimmed = value.trim();
346
+ return trimmed || undefined;
347
+ }
348
+ function asRecord(value) {
349
+ return value !== null && typeof value === "object" && !Array.isArray(value)
350
+ ? value
351
+ : undefined;
352
+ }
353
+ export const CODEX_CLI_PARTICIPANT_TESTED_VERSION = CODEX_CLI_VERSION;
354
+ //# sourceMappingURL=codex-cli-participant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-cli-participant.js","sourceRoot":"","sources":["../../src/cli/codex-cli-participant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAE7C,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACjD,MAAM,wBAAwB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC5C,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;AAC3C,MAAM,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AC;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,IAAI,SAAS,CAAC;AAC9B,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAkC;QACrC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,oCAAoC,GAAG,iBAAiB,CAAC","sourcesContent":["import { execFile as execFileCallback, spawn } from \"node:child_process\";\nimport { isAbsolute } from \"node:path\";\nimport type { Readable, Writable } from \"node:stream\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { promisify } from \"node:util\";\n\nconst execFile = promisify(execFileCallback);\n\nconst CODEX_CLI_VERSION = \"0.144.3\";\nconst DEFAULT_MAX_EVENTS = 2_000;\nconst DEFAULT_MAX_STREAM_BYTES = 8 * 1024 * 1024;\nconst DEFAULT_MAX_STDERR_BYTES = 128 * 1024;\nconst DEFAULT_TIMEOUT_MS = 30 * 60 * 1_000;\nconst DEFAULT_TERMINATION_GRACE_MS = 2_000;\nconst DEFAULT_FORCE_SETTLE_MS = 250;\nconst MAX_ERROR_MESSAGE_LENGTH = 200;\n\nconst SAFE_ENVIRONMENT_KEYS = [\n \"PATH\",\n \"HOME\",\n \"LANG\",\n \"LC_ALL\",\n \"LC_CTYPE\",\n \"TMPDIR\",\n \"TMP\",\n \"TEMP\",\n \"TERM\",\n \"NO_COLOR\",\n \"FORCE_COLOR\",\n \"USER\",\n \"LOGNAME\",\n \"SHELL\",\n // Codex reads its subscription session from this config root (or HOME/.codex).\n \"CODEX_HOME\",\n] as const;\n\nexport type CodexCliParticipantRole = \"planning\" | \"watchdog\" | \"driver\";\n\nexport interface CodexCliSubscriptionStatus {\n loggedIn: boolean;\n authMode?: \"ChatGPT\" | \"API key\" | \"unknown\";\n}\n\nexport interface CodexCliParticipantSession {\n /** Codex owns and interprets this value; Agent Native only persists it. */\n resumeSessionId?: string;\n}\n\nexport interface CodexCliParticipantEvent {\n [key: string]: unknown;\n}\n\nexport interface CodexCliParticipantResult {\n exitCode: number;\n events: CodexCliParticipantEvent[];\n stderr: string;\n stderrTruncated: boolean;\n resumeSessionId?: string;\n}\n\nexport interface CodexCliParticipantChild {\n stdin: Writable;\n stdout: Readable;\n stderr: Readable;\n kill(signal?: NodeJS.Signals): boolean;\n once(event: \"error\", listener: (error: Error) => void): unknown;\n once(\n event: \"close\",\n listener: (code: number | null, signal: NodeJS.Signals | null) => void,\n ): unknown;\n}\n\nexport interface CodexCliParticipantSpawnOptions {\n cwd: string;\n env: NodeJS.ProcessEnv;\n shell: false;\n stdio: [\"pipe\", \"pipe\", \"pipe\"];\n}\n\nexport type CodexCliParticipantSpawn = (\n command: string,\n args: string[],\n options: CodexCliParticipantSpawnOptions,\n) => CodexCliParticipantChild;\n\nexport interface RunCodexCliParticipantOptions {\n role: CodexCliParticipantRole;\n prompt: string;\n cwd: string;\n model?: string;\n session?: CodexCliParticipantSession;\n /** Drivers remain read-only unless this explicit capability is true. */\n allowWorkspaceWrite?: boolean;\n /** Either the fixed CLI name or an absolute executable path for packaged apps. */\n command?: string;\n signal?: AbortSignal;\n env?: NodeJS.ProcessEnv;\n maxEvents?: number;\n maxStreamBytes?: number;\n maxStderrBytes?: number;\n timeoutMs?: number;\n terminationGraceMs?: number;\n forceSettleMs?: number;\n onEvent?: (event: CodexCliParticipantEvent) => void;\n preflight?: (\n context: CodexCliParticipantPreflightContext,\n ) => Promise<CodexCliSubscriptionStatus>;\n spawnProcess?: CodexCliParticipantSpawn;\n}\n\nexport interface CodexCliParticipantPreflightContext {\n command: string;\n env: NodeJS.ProcessEnv;\n}\n\nexport class CodexCliSubscriptionRequiredError extends Error {\n constructor() {\n super(\n \"Codex CLI must be signed in with a ChatGPT subscription. API-key fallback is disabled.\",\n );\n this.name = \"CodexCliSubscriptionRequiredError\";\n }\n}\n\nexport interface CodexCliSubscriptionStatusOptions {\n command?: string;\n env?: NodeJS.ProcessEnv;\n execute?: typeof execFile;\n}\n\nexport async function readCodexCliSubscriptionStatus(\n options: CodexCliSubscriptionStatusOptions = {},\n): Promise<CodexCliSubscriptionStatus> {\n try {\n const execute = options.execute ?? execFile;\n const { stdout, stderr } = await execute(\n resolveCommand(options.command, \"codex\"),\n [\"login\", \"status\"],\n {\n encoding: \"utf8\",\n maxBuffer: 128 * 1024,\n timeout: 3_000,\n windowsHide: true,\n env: safeEnvironment(options.env ?? process.env),\n },\n );\n const output = `${stdout}\\n${stderr}`;\n return {\n loggedIn: /logged in using/i.test(output),\n authMode: /logged in using\\s+chatgpt/i.test(output)\n ? \"ChatGPT\"\n : /logged in using\\s+(?:an?\\s+)?api key/i.test(output)\n ? \"API key\"\n : \"unknown\",\n };\n } catch {\n return { loggedIn: false };\n }\n}\n\nexport async function runCodexCliParticipant(\n options: RunCodexCliParticipantOptions,\n): Promise<CodexCliParticipantResult> {\n validateInput(options);\n const env = safeEnvironment(options.env ?? process.env);\n const command = resolveCommand(options.command, \"codex\");\n const subscription = await (options.preflight\n ? options.preflight({ command, env })\n : readCodexCliSubscriptionStatus({ command, env }));\n if (!subscription.loggedIn || subscription.authMode !== \"ChatGPT\") {\n throw new CodexCliSubscriptionRequiredError();\n }\n if (options.signal?.aborted) throw createAbortError();\n\n const args = buildCodexCliParticipantArgs(options);\n const spawnProcess =\n options.spawnProcess ??\n ((command, commandArgs, spawnOptions) =>\n spawn(command, commandArgs, spawnOptions));\n const child = spawnProcess(command, args, {\n cwd: options.cwd,\n env,\n shell: false,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n });\n return collectCodexCliParticipantResult(child, options);\n}\n\nexport function buildCodexCliParticipantArgs(\n options: Pick<\n RunCodexCliParticipantOptions,\n \"role\" | \"cwd\" | \"model\" | \"session\" | \"allowWorkspaceWrite\"\n >,\n): string[] {\n const sandbox =\n options.role === \"driver\" && options.allowWorkspaceWrite === true\n ? \"workspace-write\"\n : \"read-only\";\n const args = [\n \"--ask-for-approval\",\n \"never\",\n \"--sandbox\",\n sandbox,\n \"--cd\",\n options.cwd,\n \"exec\",\n ];\n const resumeSessionId = readString(options.session?.resumeSessionId);\n if (resumeSessionId) args.push(\"resume\");\n args.push(\"--json\", \"--skip-git-repo-check\", \"--ignore-user-config\");\n\n const model = readString(options.model);\n if (model) args.push(\"--model\", model);\n if (resumeSessionId) args.push(\"--\", resumeSessionId, \"-\");\n else args.push(\"-\");\n return args;\n}\n\nfunction collectCodexCliParticipantResult(\n child: CodexCliParticipantChild,\n options: RunCodexCliParticipantOptions,\n): Promise<CodexCliParticipantResult> {\n const maxEvents = boundedLimit(options.maxEvents, DEFAULT_MAX_EVENTS);\n const maxStreamBytes = boundedLimit(\n options.maxStreamBytes,\n DEFAULT_MAX_STREAM_BYTES,\n );\n const maxStderrBytes = boundedLimit(\n options.maxStderrBytes,\n DEFAULT_MAX_STDERR_BYTES,\n );\n const timeoutMs = boundedDuration(options.timeoutMs, DEFAULT_TIMEOUT_MS);\n const terminationGraceMs = boundedDuration(\n options.terminationGraceMs,\n DEFAULT_TERMINATION_GRACE_MS,\n );\n const forceSettleMs = boundedDuration(\n options.forceSettleMs,\n DEFAULT_FORCE_SETTLE_MS,\n );\n const decoder = new StringDecoder(\"utf8\");\n const stderrDecoder = new StringDecoder(\"utf8\");\n const events: CodexCliParticipantEvent[] = [];\n let pending = \"\";\n let streamBytes = 0;\n let stderr = \"\";\n let stderrBytes = 0;\n let stderrTruncated = false;\n let fatalError: Error | undefined;\n let resumeSessionId: string | undefined;\n\n return new Promise((resolve, reject) => {\n let settled = false;\n let terminationTimer: NodeJS.Timeout | undefined;\n let forceSettleTimer: NodeJS.Timeout | undefined;\n const timeoutTimer = setTimeout(() => {\n stopWithError(new Error(`Codex CLI timed out after ${timeoutMs}ms.`));\n }, timeoutMs);\n timeoutTimer.unref?.();\n const cleanup = () => {\n options.signal?.removeEventListener(\"abort\", abort);\n clearTimeout(timeoutTimer);\n if (terminationTimer) clearTimeout(terminationTimer);\n if (forceSettleTimer) clearTimeout(forceSettleTimer);\n };\n const finishError = (error: Error) => {\n if (settled) return;\n settled = true;\n cleanup();\n reject(safeError(error));\n };\n const stopWithError = (error: Error) => {\n if (fatalError) return;\n fatalError = error;\n terminationTimer = setTimeout(() => {\n if (settled) return;\n forceSettleTimer = setTimeout(() => {\n finishError(fatalError ?? error);\n }, forceSettleMs);\n forceSettleTimer.unref?.();\n child.kill(\"SIGKILL\");\n }, terminationGraceMs);\n terminationTimer.unref?.();\n child.kill(\"SIGTERM\");\n };\n const abort = () => stopWithError(createAbortError());\n const streamError = (error: Error) => {\n if (!settled) stopWithError(error);\n };\n const consume = (line: string) => {\n const event = consumeJsonLine(line, events, maxEvents, options.onEvent);\n const threadId = readString(event?.thread_id);\n if (event?.type === \"thread.started\" && threadId) {\n resumeSessionId = threadId;\n }\n };\n\n child.stdin.on(\"error\", streamError);\n child.stdout.on(\"error\", streamError);\n child.stderr.on(\"error\", streamError);\n\n if (options.signal) {\n if (options.signal.aborted) abort();\n else options.signal.addEventListener(\"abort\", abort, { once: true });\n }\n\n child.stdout.on(\"data\", (chunk: Buffer | string) => {\n if (fatalError) return;\n const bytes = Buffer.isBuffer(chunk)\n ? chunk.length\n : Buffer.byteLength(chunk);\n streamBytes += bytes;\n if (streamBytes > maxStreamBytes) {\n stopWithError(\n new Error(`Codex CLI stream exceeded ${maxStreamBytes} bytes.`),\n );\n return;\n }\n pending += decoder.write(\n Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk),\n );\n try {\n let newline = pending.indexOf(\"\\n\");\n while (newline !== -1) {\n consume(pending.slice(0, newline));\n pending = pending.slice(newline + 1);\n newline = pending.indexOf(\"\\n\");\n }\n } catch (error) {\n stopWithError(toError(error));\n }\n });\n child.stderr.on(\"data\", (chunk: Buffer | string) => {\n const encoded = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n const remaining = Math.max(0, maxStderrBytes - stderrBytes);\n if (remaining === 0) {\n stderrTruncated = true;\n return;\n }\n stderr += stderrDecoder.write(encoded.subarray(0, remaining));\n stderrBytes += Math.min(encoded.length, remaining);\n if (encoded.length > remaining) stderrTruncated = true;\n });\n child.once(\"error\", finishError);\n child.once(\"close\", (exitCode, exitSignal) => {\n if (settled) return;\n try {\n pending += decoder.end();\n stderr += stderrDecoder.end();\n if (pending.trim()) consume(pending);\n } catch (error) {\n fatalError ??= toError(error);\n }\n if (fatalError) {\n finishError(fatalError);\n return;\n }\n if (exitCode !== 0) {\n finishError(\n new Error(\n `Codex CLI exited with ${exitSignal ?? exitCode ?? \"unknown\"}${stderr ? `: ${summarizeStderr(stderr)}` : \"\"}`,\n ),\n );\n return;\n }\n settled = true;\n cleanup();\n resolve({\n exitCode: 0,\n events,\n stderr: sanitizeStderr(stderr),\n stderrTruncated,\n ...(resumeSessionId ? { resumeSessionId } : {}),\n });\n });\n try {\n child.stdin.end(options.prompt);\n } catch (error) {\n stopWithError(toError(error));\n }\n });\n}\n\nfunction consumeJsonLine(\n line: string,\n events: CodexCliParticipantEvent[],\n maxEvents: number,\n onEvent?: (event: CodexCliParticipantEvent) => void,\n): CodexCliParticipantEvent | undefined {\n const trimmed = line.trim();\n if (!trimmed) return undefined;\n if (events.length >= maxEvents) {\n throw new Error(`Codex CLI stream exceeded ${maxEvents} events.`);\n }\n const parsed = JSON.parse(trimmed) as unknown;\n const event = asRecord(parsed);\n if (!event) throw new Error(\"Codex CLI emitted a non-object JSON event.\");\n events.push(event);\n onEvent?.(event);\n return event;\n}\n\nfunction safeEnvironment(input: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n return Object.fromEntries(\n SAFE_ENVIRONMENT_KEYS.flatMap((key) =>\n typeof input[key] === \"string\" ? [[key, input[key]]] : [],\n ),\n );\n}\n\nfunction validateInput(options: RunCodexCliParticipantOptions): void {\n if (!readString(options.prompt))\n throw new Error(\"Codex CLI prompt is required.\");\n if (!readString(options.cwd)) throw new Error(\"Codex CLI cwd is required.\");\n if (options.allowWorkspaceWrite && options.role !== \"driver\") {\n throw new Error(\"Only a Codex driver can receive workspace-write access.\");\n }\n const model = readString(options.model);\n if (model?.startsWith(\"-\")) throw new Error(\"Codex CLI model is invalid.\");\n const resumeSessionId = readString(options.session?.resumeSessionId);\n if (resumeSessionId?.includes(\"\\0\")) {\n throw new Error(\"Codex CLI resume state is invalid.\");\n }\n resolveCommand(options.command, \"codex\");\n}\n\nfunction boundedLimit(value: number | undefined, maximum: number): number {\n return Number.isSafeInteger(value) && (value ?? 0) > 0\n ? Math.min(value as number, maximum)\n : maximum;\n}\n\nfunction boundedDuration(value: number | undefined, fallback: number): number {\n return Number.isSafeInteger(value) && (value ?? 0) > 0\n ? Math.min(value as number, DEFAULT_TIMEOUT_MS)\n : fallback;\n}\n\nfunction resolveCommand(\n command: string | undefined,\n defaultCommand: string,\n): string {\n const value = readString(command) ?? defaultCommand;\n if (value === defaultCommand) return value;\n if (value.includes(\"\\0\") || !isAbsolute(value)) {\n throw new Error(\"Codex CLI command must be an absolute executable path.\");\n }\n return value;\n}\n\nfunction createAbortError(): Error {\n const error = new Error(\"Codex CLI participant was canceled.\");\n error.name = \"AbortError\";\n return error;\n}\n\nfunction toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value));\n}\n\nfunction safeError(error: Error): Error {\n const safe = new Error(summarizeStderr(error.message));\n safe.name = error.name;\n return safe;\n}\n\nfunction summarizeStderr(value: string): string {\n return sanitizeStderr(value)\n .replace(/\\s+/g, \" \")\n .trim()\n .slice(0, MAX_ERROR_MESSAGE_LENGTH);\n}\n\nfunction sanitizeStderr(value: string): string {\n return value\n .replace(/\\bBearer\\s+\\S+/gi, \"Bearer <redacted>\")\n .replace(\n /([\"']?)([A-Za-z_]*(?:token|key|secret|password)[A-Za-z_]*)\\1\\s*([=:])\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s,;}\\]]+)/gi,\n '$1$2$1$3\"<redacted>\"',\n )\n .replace(/\\b(?:sk|rk)-[A-Za-z0-9_-]{8,}\\b/g, \"<redacted>\");\n}\n\nfunction readString(value: unknown): string | undefined {\n if (typeof value !== \"string\") return undefined;\n const trimmed = value.trim();\n return trimmed || undefined;\n}\n\nfunction asRecord(value: unknown): CodexCliParticipantEvent | undefined {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? (value as CodexCliParticipantEvent)\n : undefined;\n}\n\nexport const CODEX_CLI_PARTICIPANT_TESTED_VERSION = CODEX_CLI_VERSION;\n"]}
@@ -0,0 +1,246 @@
1
+ export type MultiFrontierPhase = "proposing" | "cross_review" | "converging" | "awaiting_go" | "implementing" | "checkpoint_review" | "paused" | "completed" | "failed" | "canceled";
2
+ export type MultiFrontierParticipantRole = "driver" | "watchdog";
3
+ export type MultiFrontierParticipantPermission = "read_only" | "workspace_write";
4
+ export type MultiFrontierParticipantStatus = "idle" | "running" | "waiting" | "failed" | "completed";
5
+ export type MultiFrontierApprovalState = "not_required" | "pending" | "approved" | "rejected";
6
+ export type MultiFrontierRecoveryReason = "main_process_restarted" | "driver_crashed" | "watchdog_crashed" | "app_quit" | "canceled";
7
+ export interface MultiFrontierParticipantState {
8
+ participantId: string;
9
+ provider: string;
10
+ runtime: string;
11
+ model?: string;
12
+ capabilities?: string[];
13
+ sessionRef?: string;
14
+ role: MultiFrontierParticipantRole;
15
+ permission: MultiFrontierParticipantPermission;
16
+ status: MultiFrontierParticipantStatus;
17
+ }
18
+ export interface MultiFrontierDriverLease {
19
+ participantId: string;
20
+ generation: number;
21
+ leaseState: "inactive" | "active" | "revoked";
22
+ }
23
+ export interface MultiFrontierApproval {
24
+ state: MultiFrontierApprovalState;
25
+ proposalId?: string;
26
+ reviewPacketId?: string;
27
+ }
28
+ export interface MultiFrontierRecovery {
29
+ reason: MultiFrontierRecoveryReason;
30
+ recoveredAt: string;
31
+ resumablePhase: MultiFrontierPhase;
32
+ checkpointId?: string;
33
+ }
34
+ /**
35
+ * The durable state contract shared by the main process and every participant.
36
+ * Only the main-process coordinator writes it through this module.
37
+ */
38
+ export interface MultiFrontierRunState {
39
+ schemaVersion: 1;
40
+ collaborationId: string;
41
+ /** Opaque local workspace handle; never a filesystem path. */
42
+ workspaceId?: string;
43
+ phase: MultiFrontierPhase;
44
+ participants: MultiFrontierParticipantState[];
45
+ driver: MultiFrontierDriverLease | null;
46
+ approval: MultiFrontierApproval;
47
+ checkpointIds: string[];
48
+ round: number;
49
+ proposalIds: string[];
50
+ reviewIds: string[];
51
+ /** Opt-in policy; explicit GO remains the durable default. */
52
+ autoContinueAfterAgreement: boolean;
53
+ recovery?: MultiFrontierRecovery;
54
+ }
55
+ export interface CreateMultiFrontierRunInput {
56
+ collaborationId: string;
57
+ workspaceId?: string;
58
+ phase?: MultiFrontierPhase;
59
+ participants: MultiFrontierParticipantState[];
60
+ approval?: MultiFrontierApproval;
61
+ checkpointIds?: string[];
62
+ autoContinueAfterAgreement?: boolean;
63
+ }
64
+ export interface RecoverMultiFrontierRunInput {
65
+ now: string;
66
+ reason: MultiFrontierRecoveryReason;
67
+ }
68
+ export interface MultiFrontierParticipantEvent {
69
+ participantId: string;
70
+ generation?: number;
71
+ permission: MultiFrontierParticipantPermission;
72
+ }
73
+ export interface PersistedMultiFrontierParticipantEvent extends MultiFrontierParticipantEvent {
74
+ schemaVersion: 1;
75
+ id: string;
76
+ collaborationId: string;
77
+ createdAt: string;
78
+ status?: MultiFrontierParticipantStatus;
79
+ }
80
+ export type MultiFrontierArtifactKind = "proposal" | "review" | "checkpoint";
81
+ export interface MultiFrontierArtifactTestSummary {
82
+ name: string;
83
+ status: "passed" | "failed" | "skipped";
84
+ summary?: string;
85
+ }
86
+ /** A bounded, redacted projection used only for Desktop orchestrator recovery. */
87
+ export interface MultiFrontierOrchestrationArtifact {
88
+ id: string;
89
+ kind: "proposal" | "cross_review" | "revision" | "synthesis" | "checkpoint" | "watchdog_review" | "finding_disposition" | "completion";
90
+ round: number;
91
+ participantId?: string;
92
+ text: string;
93
+ attribution: {
94
+ participantIds: string[];
95
+ sourceArtifactIds: string[];
96
+ };
97
+ supersedesArtifactId?: string;
98
+ metadata?: Record<string, unknown>;
99
+ }
100
+ /**
101
+ * A deliberately narrow coordination record. Full diffs, transcripts, and
102
+ * provider payloads stay in their owning runtime rather than this durable
103
+ * cross-provider index.
104
+ */
105
+ export interface PersistedMultiFrontierArtifact {
106
+ schemaVersion: 1;
107
+ id: string;
108
+ collaborationId: string;
109
+ kind: MultiFrontierArtifactKind;
110
+ createdAt: string;
111
+ participantId?: string;
112
+ title: string;
113
+ summary: string;
114
+ supersedesArtifactId?: string;
115
+ contentHash?: string;
116
+ fileRefs?: string[];
117
+ testSummary?: MultiFrontierArtifactTestSummary[];
118
+ orchestration?: MultiFrontierOrchestrationArtifact;
119
+ }
120
+ export interface AppendMultiFrontierArtifactInput {
121
+ id: string;
122
+ collaborationId: string;
123
+ kind: MultiFrontierArtifactKind;
124
+ createdAt?: string;
125
+ participantId?: string;
126
+ title: string;
127
+ summary: string;
128
+ supersedesArtifactId?: string;
129
+ contentHash?: string;
130
+ fileRefs?: string[];
131
+ testSummary?: MultiFrontierArtifactTestSummary[];
132
+ orchestration?: MultiFrontierOrchestrationArtifact;
133
+ }
134
+ export interface MultiFrontierParticipantEventRetention {
135
+ schemaVersion: 1;
136
+ retainedEventCount: number;
137
+ retainedByteCount: number;
138
+ droppedEventCount: number;
139
+ droppedByteCount: number;
140
+ truncated: boolean;
141
+ replay: {
142
+ requiresSnapshot: boolean;
143
+ firstRetainedEventId?: string;
144
+ };
145
+ }
146
+ export interface MultiFrontierParticipantEventRetentionLimits {
147
+ maxEventCount: number;
148
+ maxBytes: number;
149
+ }
150
+ export interface AppendMultiFrontierParticipantEventInput extends MultiFrontierParticipantEvent {
151
+ id: string;
152
+ collaborationId: string;
153
+ createdAt?: string;
154
+ status?: MultiFrontierParticipantStatus;
155
+ }
156
+ export interface MultiFrontierStoredRun extends MultiFrontierRunState {
157
+ createdAt: string;
158
+ updatedAt: string;
159
+ }
160
+ /**
161
+ * The desktop main-process coordinator is the sole caller of this transition
162
+ * boundary. Its callback receives a detached snapshot, never renderer input.
163
+ */
164
+ export type MultiFrontierCoordinatorTransition = (current: MultiFrontierStoredRun) => MultiFrontierRunState | MultiFrontierStoredRun | null;
165
+ export type AppendMultiFrontierParticipantEventResult = {
166
+ accepted: true;
167
+ deduplicated: boolean;
168
+ event: PersistedMultiFrontierParticipantEvent;
169
+ run: MultiFrontierStoredRun;
170
+ } | {
171
+ accepted: false;
172
+ reason: "missing-run" | "stale-driver" | "missing-participant" | "event-conflict" | "terminal-participant";
173
+ run: MultiFrontierStoredRun | null;
174
+ };
175
+ export type AppendMultiFrontierArtifactResult = {
176
+ accepted: true;
177
+ deduplicated: boolean;
178
+ artifact: PersistedMultiFrontierArtifact;
179
+ run: MultiFrontierStoredRun;
180
+ } | {
181
+ accepted: false;
182
+ reason: "missing-run" | "artifact-conflict" | "missing-participant" | "missing-superseded-artifact" | "artifact-limit-reached";
183
+ run: MultiFrontierStoredRun | null;
184
+ };
185
+ export declare const MAX_MULTI_FRONTIER_ARTIFACTS_PER_RUN = 200;
186
+ export declare const DEFAULT_MULTI_FRONTIER_PARTICIPANT_EVENT_RETENTION: MultiFrontierParticipantEventRetentionLimits;
187
+ /** All multi-frontier state stays alongside the existing local Code store. */
188
+ export declare function multiFrontierRunsStoreRoot(): string;
189
+ export declare function multiFrontierRunsDir(): string;
190
+ export declare function multiFrontierParticipantEventsDir(): string;
191
+ export declare function multiFrontierArtifactsDir(): string;
192
+ export declare function createMultiFrontierRun(input: CreateMultiFrontierRunInput): MultiFrontierStoredRun;
193
+ export declare function getMultiFrontierRun(collaborationId: string): MultiFrontierStoredRun | null;
194
+ export declare function listMultiFrontierRuns(): MultiFrontierStoredRun[];
195
+ /**
196
+ * Recovery never resumes a native participant automatically. Any in-flight
197
+ * driver lease is revoked and requires an explicit, newly fenced activation.
198
+ */
199
+ export declare function recoverMultiFrontierRun(state: MultiFrontierRunState, input: RecoverMultiFrontierRunInput): MultiFrontierRunState;
200
+ /** Persist the recovery decision made by the main-process coordinator. */
201
+ export declare function recoverStoredMultiFrontierRun(collaborationId: string, input: RecoverMultiFrontierRunInput): MultiFrontierStoredRun | null;
202
+ /**
203
+ * Applies one durable coordinator-owned state transition under the run lock.
204
+ * A state-shaped result retains proposal and review references by default;
205
+ * returning a full stored record is the explicit escape hatch for a
206
+ * coordinator operation that intentionally changes those references.
207
+ */
208
+ export declare function transitionStoredMultiFrontierRun(collaborationId: string, updatedAt: string, transition: MultiFrontierCoordinatorTransition): MultiFrontierStoredRun | null;
209
+ /**
210
+ * Coordinators must call this before applying a participant event. Write
211
+ * events are accepted only from the active driver generation.
212
+ */
213
+ export declare function canApplyMultiFrontierParticipantEvent(state: MultiFrontierRunState, event: MultiFrontierParticipantEvent): boolean;
214
+ /**
215
+ * Explicitly restores a write lease after recovery. The generation increments
216
+ * so an event from the interrupted process can never regain write authority.
217
+ */
218
+ export declare function reactivateMultiFrontierDriver(state: MultiFrontierRunState, participantId: string): MultiFrontierRunState | null;
219
+ /** Assign the first explicit write lease for an implementing run. */
220
+ export declare function activateMultiFrontierDriver(state: MultiFrontierRunState, participantId: string): MultiFrontierRunState | null;
221
+ /** Persist the first explicit driver activation from the main-process coordinator. */
222
+ export declare function activateStoredMultiFrontierDriver(collaborationId: string, participantId: string, now?: string): MultiFrontierStoredRun | null;
223
+ /** Persist an explicit driver reactivation after the human-approved resume. */
224
+ export declare function reactivateStoredMultiFrontierDriver(collaborationId: string, participantId: string, now?: string): MultiFrontierStoredRun | null;
225
+ /**
226
+ * Appends an idempotent participant event after the coordinator has fenced it.
227
+ * The event journal is diagnostic; state is mutated only through this guarded
228
+ * coordinator entry point.
229
+ */
230
+ export declare function appendMultiFrontierParticipantEvent(input: AppendMultiFrontierParticipantEventInput): AppendMultiFrontierParticipantEventResult;
231
+ /**
232
+ * Appends a bounded proposal, review, or checkpoint index record. The
233
+ * coordinator owns both the artifact and its run-state reference under one
234
+ * run lock, so a reader never observes a durable reference without its record.
235
+ */
236
+ export declare function appendMultiFrontierArtifact(input: AppendMultiFrontierArtifactInput): AppendMultiFrontierArtifactResult;
237
+ export declare function getMultiFrontierArtifact(collaborationId: string, artifactId: string): PersistedMultiFrontierArtifact | null;
238
+ export declare function listMultiFrontierArtifacts(collaborationId: string): PersistedMultiFrontierArtifact[];
239
+ export declare function listMultiFrontierParticipantEvents(collaborationId: string): PersistedMultiFrontierParticipantEvent[];
240
+ export declare function getMultiFrontierParticipantEventRetention(collaborationId: string): MultiFrontierParticipantEventRetention | null;
241
+ /**
242
+ * Coordinator maintenance for a bounded event journal. It deliberately keeps
243
+ * the newest contiguous tail and a replay marker instead of deleting run state.
244
+ */
245
+ export declare function compactMultiFrontierParticipantEvents(collaborationId: string, limits?: MultiFrontierParticipantEventRetentionLimits): MultiFrontierParticipantEventRetention | null;
246
+ //# sourceMappingURL=multi-frontier-runs.d.ts.map