@agent-native/core 0.112.0 → 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 (490) hide show
  1. package/corpus/README.md +4 -2
  2. package/corpus/core/CHANGELOG.md +22 -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 +6 -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 +18 -10
  11. package/corpus/core/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  12. package/corpus/core/src/cli/code-agent-runs.ts +55 -62
  13. package/corpus/core/src/cli/codex-cli-participant.ts +496 -0
  14. package/corpus/core/src/cli/multi-frontier-runs.ts +1246 -135
  15. package/corpus/core/src/client/chat/ChatHistoryList.tsx +7 -404
  16. package/corpus/core/src/integrations/index.ts +10 -0
  17. package/corpus/core/src/integrations/slack-oauth.ts +1 -0
  18. package/corpus/core/src/integrations/webhook-delivery.ts +55 -0
  19. package/corpus/core/src/notifications/channels.ts +4 -10
  20. package/corpus/core/src/provider-api/actions/custom-provider-registration.ts +197 -0
  21. package/corpus/core/src/provider-api/actions/delete-staged-dataset.ts +3 -42
  22. package/corpus/core/src/provider-api/actions/list-staged-datasets.ts +3 -45
  23. package/corpus/core/src/provider-api/actions/provider-api-audit.ts +88 -0
  24. package/corpus/core/src/provider-api/actions/provider-api.ts +460 -0
  25. package/corpus/core/src/provider-api/actions/query-staged-dataset.ts +3 -140
  26. package/corpus/core/src/provider-api/actions/staged-datasets.ts +359 -0
  27. package/corpus/core/src/provider-api/gong.ts +108 -0
  28. package/corpus/core/src/scripts/docs/source-search.ts +2 -1
  29. package/corpus/core/src/server/google-oauth-credentials.ts +80 -3
  30. package/corpus/core/src/server/index.ts +6 -0
  31. package/corpus/core/src/styles/chat-history-list.css +1 -313
  32. package/corpus/core/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  33. package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  34. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  35. package/corpus/core/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  36. package/corpus/core/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  37. package/corpus/core/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  38. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  39. package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  40. package/corpus/core/src/templates/default/AGENTS.md +25 -18
  41. package/corpus/core/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  42. package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  43. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  44. package/corpus/core/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  45. package/corpus/core/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  46. package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  47. package/corpus/core/src/templates/headless/AGENTS.md +7 -0
  48. package/corpus/core/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  49. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  50. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  51. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  52. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  53. package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  54. package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -0
  55. package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -0
  56. package/corpus/templates/analytics/.agents/skills/actions/SKILL.md +32 -12
  57. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  58. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +11 -2
  59. package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  60. package/corpus/templates/analytics/actions/delete-staged-dataset.ts +3 -23
  61. package/corpus/templates/analytics/actions/list-staged-datasets.ts +3 -27
  62. package/corpus/templates/analytics/actions/provider-api-catalog.ts +16 -19
  63. package/corpus/templates/analytics/actions/provider-api-docs.ts +3 -5
  64. package/corpus/templates/analytics/actions/provider-api-request.ts +162 -185
  65. package/corpus/templates/analytics/actions/query-staged-dataset.ts +3 -47
  66. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +52 -161
  67. package/corpus/templates/assets/.agents/skills/actions/SKILL.md +32 -12
  68. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  69. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +11 -2
  70. package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  71. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +63 -160
  72. package/corpus/templates/brain/.agents/skills/actions/SKILL.md +32 -12
  73. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  74. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +11 -2
  75. package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  76. package/corpus/templates/brain/actions/_schemas.ts +13 -7
  77. package/corpus/templates/brain/actions/delete-staged-dataset.ts +3 -24
  78. package/corpus/templates/brain/actions/list-staged-datasets.ts +3 -28
  79. package/corpus/templates/brain/actions/provider-api-catalog.ts +5 -11
  80. package/corpus/templates/brain/actions/provider-api-docs.ts +3 -5
  81. package/corpus/templates/brain/actions/provider-api-request.ts +3 -37
  82. package/corpus/templates/brain/actions/query-staged-dataset.ts +3 -48
  83. package/corpus/templates/brain/actions/update-source.ts +5 -1
  84. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +48 -154
  85. package/corpus/templates/brain/app/lib/brain.ts +55 -0
  86. package/corpus/templates/brain/app/lib/ingest-handoff.ts +35 -0
  87. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-can-now-join-configured-public-channels-befo.md +6 -0
  88. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-continue-across-the-configured-number-of.md +6 -0
  89. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-start-with-a-safe-four-week-window-and-r.md +6 -0
  90. package/corpus/templates/brain/server/lib/connectors.ts +53 -2
  91. package/corpus/templates/brain/server/lib/slack-channel-membership.ts +44 -0
  92. package/corpus/templates/brain/shared/slack-source-config.ts +60 -0
  93. package/corpus/templates/calendar/.agents/skills/actions/SKILL.md +32 -12
  94. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  95. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +11 -2
  96. package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  97. package/corpus/templates/calendar/actions/delete-staged-dataset.ts +3 -24
  98. package/corpus/templates/calendar/actions/list-staged-datasets.ts +3 -28
  99. package/corpus/templates/calendar/actions/provider-api-catalog.ts +5 -11
  100. package/corpus/templates/calendar/actions/provider-api-docs.ts +3 -5
  101. package/corpus/templates/calendar/actions/provider-api-request.ts +3 -37
  102. package/corpus/templates/calendar/actions/query-staged-dataset.ts +3 -48
  103. package/corpus/templates/calendar/server/handlers/gong.ts +6 -61
  104. package/corpus/templates/calendar/server/handlers/google-auth.ts +10 -8
  105. package/corpus/templates/calendar/server/lib/google-calendar.ts +7 -45
  106. package/corpus/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  107. package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  108. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  109. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  110. package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  111. package/corpus/templates/chat/AGENTS.md +5 -2
  112. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  113. package/corpus/templates/clips/.agents/skills/actions/SKILL.md +32 -12
  114. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  115. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +11 -2
  116. package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  117. package/corpus/templates/clips/AGENTS.md +11 -0
  118. package/corpus/templates/clips/actions/export-to-brain.ts +505 -171
  119. package/corpus/templates/clips/changelog/2026-07-19-ready-clips-transcripts-can-be-backfilled-to-brain-for-a-bou.md +6 -0
  120. package/corpus/templates/clips/server/lib/calendar-event-meetings.ts +1 -1
  121. package/corpus/templates/clips/server/lib/google-calendar-client.ts +12 -22
  122. package/corpus/templates/clips/server/lib/google-calendar-oauth.ts +9 -6
  123. package/corpus/templates/clips/server/lib/slack-oauth.ts +12 -47
  124. package/corpus/templates/clips/server/routes/_agent-native/google/auth-url.get.ts +2 -6
  125. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +4 -4
  126. package/corpus/templates/content/.agents/skills/actions/SKILL.md +32 -12
  127. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  128. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +11 -2
  129. package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  130. package/corpus/templates/content/actions/delete-staged-dataset.ts +3 -24
  131. package/corpus/templates/content/actions/list-staged-datasets.ts +3 -28
  132. package/corpus/templates/content/actions/provider-api-catalog.ts +5 -11
  133. package/corpus/templates/content/actions/provider-api-docs.ts +3 -5
  134. package/corpus/templates/content/actions/provider-api-request.ts +3 -37
  135. package/corpus/templates/content/actions/query-staged-dataset.ts +3 -48
  136. package/corpus/templates/design/.agents/skills/actions/SKILL.md +32 -12
  137. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  138. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +11 -2
  139. package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  140. package/corpus/templates/design/actions/delete-staged-dataset.ts +4 -23
  141. package/corpus/templates/design/actions/list-staged-datasets.ts +4 -27
  142. package/corpus/templates/design/actions/provider-api-catalog.ts +15 -18
  143. package/corpus/templates/design/actions/provider-api-docs.ts +57 -48
  144. package/corpus/templates/design/actions/provider-api-request.ts +140 -164
  145. package/corpus/templates/design/actions/query-staged-dataset.ts +4 -47
  146. package/corpus/templates/dispatch/.agents/skills/actions/SKILL.md +32 -12
  147. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  148. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +11 -2
  149. package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  150. package/corpus/templates/dispatch/actions/delete-staged-dataset.ts +4 -23
  151. package/corpus/templates/dispatch/actions/list-staged-datasets.ts +4 -30
  152. package/corpus/templates/dispatch/actions/provider-api-catalog.ts +15 -18
  153. package/corpus/templates/dispatch/actions/provider-api-docs.ts +57 -48
  154. package/corpus/templates/dispatch/actions/provider-api-request.ts +138 -163
  155. package/corpus/templates/dispatch/actions/query-staged-dataset.ts +4 -47
  156. package/corpus/templates/forms/.agents/skills/actions/SKILL.md +32 -12
  157. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  158. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +11 -2
  159. package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  160. package/corpus/templates/forms/server/lib/integrations.ts +23 -22
  161. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  162. package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  163. package/corpus/templates/mail/.agents/skills/actions/SKILL.md +32 -12
  164. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  165. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +11 -2
  166. package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  167. package/corpus/templates/mail/actions/delete-staged-dataset.ts +4 -23
  168. package/corpus/templates/mail/actions/list-staged-datasets.ts +4 -27
  169. package/corpus/templates/mail/actions/provider-api-catalog.ts +15 -18
  170. package/corpus/templates/mail/actions/provider-api-docs.ts +57 -48
  171. package/corpus/templates/mail/actions/provider-api-request.ts +146 -173
  172. package/corpus/templates/mail/actions/query-staged-dataset.ts +4 -47
  173. package/corpus/templates/mail/server/handlers/gong.ts +6 -61
  174. package/corpus/templates/mail/server/lib/google-auth.ts +10 -13
  175. package/corpus/templates/plan/.agents/skills/actions/SKILL.md +32 -12
  176. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  177. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +11 -2
  178. package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  179. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +47 -156
  180. package/corpus/templates/slides/.agents/skills/actions/SKILL.md +32 -12
  181. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  182. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +11 -2
  183. package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  184. package/corpus/templates/slides/actions/delete-staged-dataset.ts +4 -23
  185. package/corpus/templates/slides/actions/list-staged-datasets.ts +4 -27
  186. package/corpus/templates/slides/actions/provider-api-catalog.ts +15 -18
  187. package/corpus/templates/slides/actions/provider-api-docs.ts +57 -48
  188. package/corpus/templates/slides/actions/provider-api-request.ts +145 -172
  189. package/corpus/templates/slides/actions/query-staged-dataset.ts +4 -47
  190. package/corpus/templates/slides/server/lib/google-docs-oauth.ts +11 -36
  191. package/corpus/templates/tasks/.agents/skills/actions/SKILL.md +32 -12
  192. package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +10 -0
  193. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  194. package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +11 -2
  195. package/corpus/templates/tasks/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  196. package/corpus/toolkit/CHANGELOG.md +125 -0
  197. package/corpus/toolkit/README.md +60 -0
  198. package/corpus/toolkit/export-snapshot.json +35 -0
  199. package/corpus/toolkit/migration-manifest.json +4 -0
  200. package/corpus/toolkit/package.json +281 -0
  201. package/corpus/toolkit/scripts/finalize-build.mjs +55 -0
  202. package/corpus/toolkit/src/app-shell/header-actions.tsx +84 -0
  203. package/corpus/toolkit/src/app-shell/index.ts +1 -0
  204. package/corpus/toolkit/src/chat-history/ChatHistoryList.tsx +469 -0
  205. package/corpus/toolkit/src/chat-history/index.ts +7 -0
  206. package/corpus/toolkit/src/chat-history.css +314 -0
  207. package/corpus/toolkit/src/collab-ui/AgentPresenceChip.tsx +69 -0
  208. package/corpus/toolkit/src/collab-ui/LiveCursorOverlay.tsx +241 -0
  209. package/corpus/toolkit/src/collab-ui/PresenceBar.tsx +346 -0
  210. package/corpus/toolkit/src/collab-ui/RecentEditHighlights.tsx +225 -0
  211. package/corpus/toolkit/src/collab-ui/RemoteSelectionRings.tsx +227 -0
  212. package/corpus/toolkit/src/collab-ui/agent-identity.ts +16 -0
  213. package/corpus/toolkit/src/collab-ui/index.ts +39 -0
  214. package/corpus/toolkit/src/collab-ui/lead-client.ts +32 -0
  215. package/corpus/toolkit/src/collab-ui/types.ts +96 -0
  216. package/corpus/toolkit/src/composer/AgentComposerFrame.tsx +59 -0
  217. package/corpus/toolkit/src/composer/ComposerPlusMenu.tsx +983 -0
  218. package/corpus/toolkit/src/composer/MentionPopover.tsx +412 -0
  219. package/corpus/toolkit/src/composer/PastedTextChip.tsx +150 -0
  220. package/corpus/toolkit/src/composer/PromptComposer.tsx +718 -0
  221. package/corpus/toolkit/src/composer/RealtimeVoiceMode.tsx +856 -0
  222. package/corpus/toolkit/src/composer/TiptapComposer.tsx +2936 -0
  223. package/corpus/toolkit/src/composer/VoiceButton.tsx +255 -0
  224. package/corpus/toolkit/src/composer/asset-picker-url.ts +80 -0
  225. package/corpus/toolkit/src/composer/attachment-accept.ts +71 -0
  226. package/corpus/toolkit/src/composer/draft-key.ts +7 -0
  227. package/corpus/toolkit/src/composer/extensions/FileReference.tsx +55 -0
  228. package/corpus/toolkit/src/composer/extensions/MentionReference.tsx +93 -0
  229. package/corpus/toolkit/src/composer/extensions/SkillReference.tsx +56 -0
  230. package/corpus/toolkit/src/composer/index.ts +79 -0
  231. package/corpus/toolkit/src/composer/pasted-text.ts +160 -0
  232. package/corpus/toolkit/src/composer/prompt-attachments.ts +93 -0
  233. package/corpus/toolkit/src/composer/realtime-voice-audio-level.ts +64 -0
  234. package/corpus/toolkit/src/composer/realtime-voice-transcript.ts +134 -0
  235. package/corpus/toolkit/src/composer/runtime-adapters.tsx +343 -0
  236. package/corpus/toolkit/src/composer/types.ts +66 -0
  237. package/corpus/toolkit/src/composer/use-file-search.ts +64 -0
  238. package/corpus/toolkit/src/composer/use-mention-search.ts +90 -0
  239. package/corpus/toolkit/src/composer/use-skills.ts +45 -0
  240. package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +2117 -0
  241. package/corpus/toolkit/src/composer/useVoiceDictation.ts +1191 -0
  242. package/corpus/toolkit/src/context-ui/ContextMeter.tsx +101 -0
  243. package/corpus/toolkit/src/context-ui/ContextSegmentRow.tsx +184 -0
  244. package/corpus/toolkit/src/context-ui/ContextTreemap.tsx +125 -0
  245. package/corpus/toolkit/src/context-ui/ContextXRayPanel.tsx +377 -0
  246. package/corpus/toolkit/src/context-ui/format.ts +42 -0
  247. package/corpus/toolkit/src/context-ui/index.ts +15 -0
  248. package/corpus/toolkit/src/context-ui/types.ts +43 -0
  249. package/corpus/toolkit/src/design-tweaks/index.ts +1 -0
  250. package/corpus/toolkit/src/design-tweaks/visual-style-controls.tsx +1084 -0
  251. package/corpus/toolkit/src/editor/BubbleToolbar.tsx +253 -0
  252. package/corpus/toolkit/src/editor/CodeBlockNode.tsx +254 -0
  253. package/corpus/toolkit/src/editor/DragHandle.ts +1437 -0
  254. package/corpus/toolkit/src/editor/ImageExtension.ts +306 -0
  255. package/corpus/toolkit/src/editor/RegistryBlockContext.tsx +107 -0
  256. package/corpus/toolkit/src/editor/RegistryBlockNode.tsx +652 -0
  257. package/corpus/toolkit/src/editor/RichMarkdownEditor.tsx +81 -0
  258. package/corpus/toolkit/src/editor/RunId.ts +61 -0
  259. package/corpus/toolkit/src/editor/SharedRichEditor.tsx +321 -0
  260. package/corpus/toolkit/src/editor/SlashCommandMenu.tsx +310 -0
  261. package/corpus/toolkit/src/editor/extensions.ts +402 -0
  262. package/corpus/toolkit/src/editor/gfmDoc.ts +92 -0
  263. package/corpus/toolkit/src/editor/index.ts +93 -0
  264. package/corpus/toolkit/src/editor/registrySlashCommands.ts +131 -0
  265. package/corpus/toolkit/src/editor/surgical-apply.ts +192 -0
  266. package/corpus/toolkit/src/editor/useCollabReconcile.ts +589 -0
  267. package/corpus/toolkit/src/editor.css +510 -0
  268. package/corpus/toolkit/src/hooks/index.ts +2 -0
  269. package/corpus/toolkit/src/hooks/use-mobile.tsx +21 -0
  270. package/corpus/toolkit/src/hooks/use-toast.ts +188 -0
  271. package/corpus/toolkit/src/index.ts +8 -0
  272. package/corpus/toolkit/src/onboarding/index.ts +1 -0
  273. package/corpus/toolkit/src/provider.tsx +47 -0
  274. package/corpus/toolkit/src/sharing/VisibilityBadge.tsx +37 -0
  275. package/corpus/toolkit/src/sharing/index.ts +4 -0
  276. package/corpus/toolkit/src/styles.css +21 -0
  277. package/corpus/toolkit/src/ui/accordion.tsx +56 -0
  278. package/corpus/toolkit/src/ui/alert-dialog.tsx +141 -0
  279. package/corpus/toolkit/src/ui/alert.tsx +59 -0
  280. package/corpus/toolkit/src/ui/aspect-ratio.tsx +5 -0
  281. package/corpus/toolkit/src/ui/avatar.tsx +48 -0
  282. package/corpus/toolkit/src/ui/badge.tsx +37 -0
  283. package/corpus/toolkit/src/ui/breadcrumb.tsx +115 -0
  284. package/corpus/toolkit/src/ui/button.tsx +78 -0
  285. package/corpus/toolkit/src/ui/calendar.tsx +214 -0
  286. package/corpus/toolkit/src/ui/card.tsx +86 -0
  287. package/corpus/toolkit/src/ui/carousel.tsx +260 -0
  288. package/corpus/toolkit/src/ui/chart.tsx +375 -0
  289. package/corpus/toolkit/src/ui/checkbox.tsx +28 -0
  290. package/corpus/toolkit/src/ui/collapsible.tsx +9 -0
  291. package/corpus/toolkit/src/ui/command.tsx +174 -0
  292. package/corpus/toolkit/src/ui/context-menu.tsx +202 -0
  293. package/corpus/toolkit/src/ui/date-picker.tsx +64 -0
  294. package/corpus/toolkit/src/ui/dialog.tsx +146 -0
  295. package/corpus/toolkit/src/ui/drawer.tsx +126 -0
  296. package/corpus/toolkit/src/ui/dropdown-menu.tsx +218 -0
  297. package/corpus/toolkit/src/ui/form.tsx +177 -0
  298. package/corpus/toolkit/src/ui/hover-card.tsx +27 -0
  299. package/corpus/toolkit/src/ui/index.ts +52 -0
  300. package/corpus/toolkit/src/ui/input-otp.tsx +69 -0
  301. package/corpus/toolkit/src/ui/input.tsx +22 -0
  302. package/corpus/toolkit/src/ui/label.tsx +24 -0
  303. package/corpus/toolkit/src/ui/logo.tsx +36 -0
  304. package/corpus/toolkit/src/ui/menubar.tsx +235 -0
  305. package/corpus/toolkit/src/ui/navigation-menu.tsx +128 -0
  306. package/corpus/toolkit/src/ui/pagination.tsx +121 -0
  307. package/corpus/toolkit/src/ui/popover.tsx +44 -0
  308. package/corpus/toolkit/src/ui/progress.tsx +26 -0
  309. package/corpus/toolkit/src/ui/radio-group.tsx +42 -0
  310. package/corpus/toolkit/src/ui/resizable.tsx +43 -0
  311. package/corpus/toolkit/src/ui/scroll-area.tsx +46 -0
  312. package/corpus/toolkit/src/ui/select.tsx +158 -0
  313. package/corpus/toolkit/src/ui/separator.tsx +29 -0
  314. package/corpus/toolkit/src/ui/sheet.tsx +160 -0
  315. package/corpus/toolkit/src/ui/sidebar.tsx +777 -0
  316. package/corpus/toolkit/src/ui/skeleton.tsx +18 -0
  317. package/corpus/toolkit/src/ui/slider.tsx +26 -0
  318. package/corpus/toolkit/src/ui/sonner.tsx +58 -0
  319. package/corpus/toolkit/src/ui/spinner.tsx +17 -0
  320. package/corpus/toolkit/src/ui/switch.tsx +27 -0
  321. package/corpus/toolkit/src/ui/table.tsx +117 -0
  322. package/corpus/toolkit/src/ui/tabs.tsx +53 -0
  323. package/corpus/toolkit/src/ui/textarea.tsx +23 -0
  324. package/corpus/toolkit/src/ui/toast.tsx +127 -0
  325. package/corpus/toolkit/src/ui/toaster.tsx +33 -0
  326. package/corpus/toolkit/src/ui/toggle-group.tsx +59 -0
  327. package/corpus/toolkit/src/ui/toggle.tsx +43 -0
  328. package/corpus/toolkit/src/ui/tooltip.tsx +53 -0
  329. package/corpus/toolkit/src/ui/use-toast.ts +3 -0
  330. package/corpus/toolkit/src/utils.ts +8 -0
  331. package/corpus/toolkit/tsconfig.json +23 -0
  332. package/dist/cli/atomic-json-file.d.ts +30 -0
  333. package/dist/cli/atomic-json-file.d.ts.map +1 -0
  334. package/dist/cli/atomic-json-file.js +240 -0
  335. package/dist/cli/atomic-json-file.js.map +1 -0
  336. package/dist/cli/claude-code-participant.d.ts +77 -0
  337. package/dist/cli/claude-code-participant.d.ts.map +1 -0
  338. package/dist/cli/claude-code-participant.js +355 -0
  339. package/dist/cli/claude-code-participant.js.map +1 -0
  340. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  341. package/dist/cli/code-agent-executor.js +18 -10
  342. package/dist/cli/code-agent-executor.js.map +1 -1
  343. package/dist/cli/code-agent-runs.concurrent-worker.d.ts +2 -0
  344. package/dist/cli/code-agent-runs.concurrent-worker.d.ts.map +1 -0
  345. package/dist/cli/code-agent-runs.concurrent-worker.js +32 -0
  346. package/dist/cli/code-agent-runs.concurrent-worker.js.map +1 -0
  347. package/dist/cli/code-agent-runs.d.ts.map +1 -1
  348. package/dist/cli/code-agent-runs.js +43 -56
  349. package/dist/cli/code-agent-runs.js.map +1 -1
  350. package/dist/cli/codex-cli-participant.d.ts +77 -0
  351. package/dist/cli/codex-cli-participant.d.ts.map +1 -0
  352. package/dist/cli/codex-cli-participant.js +354 -0
  353. package/dist/cli/codex-cli-participant.js.map +1 -0
  354. package/dist/cli/multi-frontier-runs.d.ts +115 -0
  355. package/dist/cli/multi-frontier-runs.d.ts.map +1 -1
  356. package/dist/cli/multi-frontier-runs.js +831 -113
  357. package/dist/cli/multi-frontier-runs.js.map +1 -1
  358. package/dist/client/chat/ChatHistoryList.d.ts +1 -87
  359. package/dist/client/chat/ChatHistoryList.d.ts.map +1 -1
  360. package/dist/client/chat/ChatHistoryList.js +1 -82
  361. package/dist/client/chat/ChatHistoryList.js.map +1 -1
  362. package/dist/integrations/index.d.ts +2 -1
  363. package/dist/integrations/index.d.ts.map +1 -1
  364. package/dist/integrations/index.js +2 -1
  365. package/dist/integrations/index.js.map +1 -1
  366. package/dist/integrations/slack-manifest.d.ts +1 -1
  367. package/dist/integrations/slack-oauth.d.ts +1 -1
  368. package/dist/integrations/slack-oauth.d.ts.map +1 -1
  369. package/dist/integrations/slack-oauth.js +1 -0
  370. package/dist/integrations/slack-oauth.js.map +1 -1
  371. package/dist/integrations/webhook-delivery.d.ts +23 -0
  372. package/dist/integrations/webhook-delivery.d.ts.map +1 -0
  373. package/dist/integrations/webhook-delivery.js +32 -0
  374. package/dist/integrations/webhook-delivery.js.map +1 -0
  375. package/dist/notifications/channels.d.ts.map +1 -1
  376. package/dist/notifications/channels.js +4 -9
  377. package/dist/notifications/channels.js.map +1 -1
  378. package/dist/notifications/routes.d.ts +3 -3
  379. package/dist/provider-api/actions/custom-provider-registration.d.ts +136 -0
  380. package/dist/provider-api/actions/custom-provider-registration.d.ts.map +1 -0
  381. package/dist/provider-api/actions/custom-provider-registration.js +154 -0
  382. package/dist/provider-api/actions/custom-provider-registration.js.map +1 -0
  383. package/dist/provider-api/actions/delete-staged-dataset.d.ts +1 -1
  384. package/dist/provider-api/actions/delete-staged-dataset.d.ts.map +1 -1
  385. package/dist/provider-api/actions/delete-staged-dataset.js +3 -34
  386. package/dist/provider-api/actions/delete-staged-dataset.js.map +1 -1
  387. package/dist/provider-api/actions/list-staged-datasets.d.ts +2 -3
  388. package/dist/provider-api/actions/list-staged-datasets.d.ts.map +1 -1
  389. package/dist/provider-api/actions/list-staged-datasets.js +3 -40
  390. package/dist/provider-api/actions/list-staged-datasets.js.map +1 -1
  391. package/dist/provider-api/actions/provider-api-audit.d.ts +7 -0
  392. package/dist/provider-api/actions/provider-api-audit.d.ts.map +1 -0
  393. package/dist/provider-api/actions/provider-api-audit.js +74 -0
  394. package/dist/provider-api/actions/provider-api-audit.js.map +1 -0
  395. package/dist/provider-api/actions/provider-api.d.ts +370 -0
  396. package/dist/provider-api/actions/provider-api.d.ts.map +1 -0
  397. package/dist/provider-api/actions/provider-api.js +280 -0
  398. package/dist/provider-api/actions/provider-api.js.map +1 -0
  399. package/dist/provider-api/actions/query-staged-dataset.d.ts +1 -1
  400. package/dist/provider-api/actions/query-staged-dataset.d.ts.map +1 -1
  401. package/dist/provider-api/actions/query-staged-dataset.js +3 -116
  402. package/dist/provider-api/actions/query-staged-dataset.js.map +1 -1
  403. package/dist/provider-api/actions/staged-datasets.d.ts +190 -0
  404. package/dist/provider-api/actions/staged-datasets.d.ts.map +1 -0
  405. package/dist/provider-api/actions/staged-datasets.js +210 -0
  406. package/dist/provider-api/actions/staged-datasets.js.map +1 -0
  407. package/dist/provider-api/gong.d.ts +44 -0
  408. package/dist/provider-api/gong.d.ts.map +1 -0
  409. package/dist/provider-api/gong.js +56 -0
  410. package/dist/provider-api/gong.js.map +1 -0
  411. package/dist/scripts/docs/source-search.d.ts +2 -1
  412. package/dist/scripts/docs/source-search.d.ts.map +1 -1
  413. package/dist/scripts/docs/source-search.js +2 -1
  414. package/dist/scripts/docs/source-search.js.map +1 -1
  415. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  416. package/dist/server/google-oauth-credentials.d.ts +35 -0
  417. package/dist/server/google-oauth-credentials.d.ts.map +1 -1
  418. package/dist/server/google-oauth-credentials.js +48 -2
  419. package/dist/server/google-oauth-credentials.js.map +1 -1
  420. package/dist/server/index.d.ts +1 -1
  421. package/dist/server/index.d.ts.map +1 -1
  422. package/dist/server/index.js +1 -1
  423. package/dist/server/index.js.map +1 -1
  424. package/dist/styles/chat-history-list.css +1 -313
  425. package/dist/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  426. package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  427. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  428. package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  429. package/dist/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  430. package/dist/templates/chat/AGENTS.md +5 -2
  431. package/dist/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  432. package/dist/templates/default/.agents/skills/actions/SKILL.md +32 -12
  433. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  434. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  435. package/dist/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  436. package/dist/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  437. package/dist/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  438. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  439. package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  440. package/dist/templates/default/AGENTS.md +25 -18
  441. package/dist/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  442. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  443. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  444. package/dist/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  445. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  446. package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  447. package/dist/templates/headless/AGENTS.md +7 -0
  448. package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  449. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  450. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  451. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  452. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  453. package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  454. package/dist/templates/workspace-core/AGENTS.md +4 -0
  455. package/dist/templates/workspace-root/AGENTS.md +4 -0
  456. package/docs/AGENTS.md +7 -0
  457. package/docs/content/integrations.mdx +63 -2
  458. package/docs/design/provider-integration-authority.md +117 -0
  459. package/package.json +7 -2
  460. package/src/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  461. package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +10 -0
  462. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  463. package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +11 -2
  464. package/src/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  465. package/src/templates/chat/AGENTS.md +5 -2
  466. package/src/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  467. package/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  468. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +10 -0
  469. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  470. package/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  471. package/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  472. package/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  473. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +11 -2
  474. package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  475. package/src/templates/default/AGENTS.md +25 -18
  476. package/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  477. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +10 -0
  478. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  479. package/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  480. package/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  481. package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  482. package/src/templates/headless/AGENTS.md +7 -0
  483. package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  484. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +10 -0
  485. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +6 -0
  486. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +102 -0
  487. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +11 -2
  488. package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  489. package/src/templates/workspace-core/AGENTS.md +4 -0
  490. package/src/templates/workspace-root/AGENTS.md +4 -0
@@ -0,0 +1,355 @@
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 CLAUDE_CODE_VERSION = "2.1.208";
7
+ const WATCHDOG_TOOLS = "Read,Glob,Grep";
8
+ const WATCHDOG_DENIED_TOOLS = "Edit,Write,NotebookEdit,Bash";
9
+ const DRIVER_TOOLS = "Read,Glob,Grep,Edit,Write";
10
+ const DEFAULT_MAX_EVENTS = 2_000;
11
+ const DEFAULT_MAX_STREAM_BYTES = 8 * 1024 * 1024;
12
+ const DEFAULT_MAX_STDERR_BYTES = 128 * 1024;
13
+ const DEFAULT_TIMEOUT_MS = 30 * 60 * 1_000;
14
+ const DEFAULT_TERMINATION_GRACE_MS = 2_000;
15
+ const DEFAULT_FORCE_SETTLE_MS = 250;
16
+ const MAX_ERROR_MESSAGE_LENGTH = 200;
17
+ const SAFE_ENVIRONMENT_KEYS = [
18
+ "PATH",
19
+ "HOME",
20
+ "LANG",
21
+ "LC_ALL",
22
+ "LC_CTYPE",
23
+ "TMPDIR",
24
+ "TMP",
25
+ "TEMP",
26
+ "TERM",
27
+ "NO_COLOR",
28
+ "FORCE_COLOR",
29
+ "USER",
30
+ "LOGNAME",
31
+ "SHELL",
32
+ // Claude Code uses this as its config root; HOME remains required for its
33
+ // default config and macOS Keychain-backed subscription login.
34
+ "CLAUDE_CONFIG_DIR",
35
+ ];
36
+ export class ClaudeCodeSubscriptionRequiredError extends Error {
37
+ constructor(message) {
38
+ super(message);
39
+ this.name = "ClaudeCodeSubscriptionRequiredError";
40
+ }
41
+ }
42
+ export async function readClaudeCodeSubscriptionStatus(options = {}) {
43
+ const execute = options.execute ?? execFile;
44
+ const { stdout } = await execute(resolveCommand(options.command, "claude"), ["auth", "status", "--json"], {
45
+ encoding: "utf8",
46
+ maxBuffer: 128 * 1024,
47
+ env: safeEnvironment(options.env ?? process.env),
48
+ });
49
+ const parsed = JSON.parse(stdout);
50
+ const status = asRecord(parsed);
51
+ if (!status || typeof status.loggedIn !== "boolean") {
52
+ throw new Error("Claude Code returned an invalid authentication status.");
53
+ }
54
+ return {
55
+ loggedIn: status.loggedIn,
56
+ authMethod: readString(status.authMethod),
57
+ apiProvider: readString(status.apiProvider),
58
+ subscriptionType: readString(status.subscriptionType),
59
+ };
60
+ }
61
+ export async function runClaudeCodeParticipant(options) {
62
+ validateInput(options);
63
+ const env = safeEnvironment(options.env ?? process.env);
64
+ const command = resolveCommand(options.command, "claude");
65
+ const subscription = await (options.preflight
66
+ ? options.preflight({ command, env })
67
+ : readClaudeCodeSubscriptionStatus({ command, env }));
68
+ assertClaudeCodeSubscription(subscription);
69
+ if (options.signal?.aborted)
70
+ throw createAbortError();
71
+ const args = buildClaudeCodeParticipantArgs(options);
72
+ const spawnProcess = options.spawnProcess ??
73
+ ((command, commandArgs, spawnOptions) => spawn(command, commandArgs, spawnOptions));
74
+ const child = spawnProcess(command, args, {
75
+ cwd: options.cwd,
76
+ env,
77
+ shell: false,
78
+ stdio: ["pipe", "pipe", "pipe"],
79
+ });
80
+ return collectClaudeCodeParticipantResult(child, options);
81
+ }
82
+ export function buildClaudeCodeParticipantArgs(options) {
83
+ const args = [
84
+ "--print",
85
+ "--input-format",
86
+ "text",
87
+ "--output-format",
88
+ "stream-json",
89
+ "--verbose",
90
+ "--no-chrome",
91
+ "--disable-slash-commands",
92
+ "--strict-mcp-config",
93
+ "--setting-sources",
94
+ "",
95
+ ];
96
+ if (options.role === "watchdog") {
97
+ args.push("--permission-mode", "plan", "--tools", WATCHDOG_TOOLS, "--disallowedTools", WATCHDOG_DENIED_TOOLS);
98
+ }
99
+ else {
100
+ args.push("--permission-mode", "acceptEdits", "--tools", DRIVER_TOOLS);
101
+ }
102
+ const model = readString(options.model);
103
+ if (model)
104
+ args.push("--model", model);
105
+ const sessionId = readString(options.session?.sessionId);
106
+ const resumeSessionId = readString(options.session?.resumeSessionId);
107
+ if (sessionId)
108
+ args.push("--session-id", sessionId);
109
+ if (resumeSessionId)
110
+ args.push("--resume", resumeSessionId);
111
+ if (options.session?.persist !== true)
112
+ args.push("--no-session-persistence");
113
+ return args;
114
+ }
115
+ function collectClaudeCodeParticipantResult(child, options) {
116
+ const maxEvents = boundedLimit(options.maxEvents, DEFAULT_MAX_EVENTS);
117
+ const maxStreamBytes = boundedLimit(options.maxStreamBytes, DEFAULT_MAX_STREAM_BYTES);
118
+ const maxStderrBytes = boundedLimit(options.maxStderrBytes, DEFAULT_MAX_STDERR_BYTES);
119
+ const timeoutMs = boundedDuration(options.timeoutMs, DEFAULT_TIMEOUT_MS);
120
+ const terminationGraceMs = boundedDuration(options.terminationGraceMs, DEFAULT_TERMINATION_GRACE_MS);
121
+ const forceSettleMs = boundedDuration(options.forceSettleMs, DEFAULT_FORCE_SETTLE_MS);
122
+ const decoder = new StringDecoder("utf8");
123
+ const stderrDecoder = new StringDecoder("utf8");
124
+ const events = [];
125
+ let pending = "";
126
+ let streamBytes = 0;
127
+ let stderr = "";
128
+ let stderrBytes = 0;
129
+ let stderrTruncated = false;
130
+ let fatalError;
131
+ return new Promise((resolve, reject) => {
132
+ let settled = false;
133
+ let terminationTimer;
134
+ let forceSettleTimer;
135
+ const timeoutTimer = setTimeout(() => {
136
+ stopWithError(new Error(`Claude Code timed out after ${timeoutMs}ms.`));
137
+ }, timeoutMs);
138
+ timeoutTimer.unref?.();
139
+ const cleanup = () => {
140
+ options.signal?.removeEventListener("abort", abort);
141
+ clearTimeout(timeoutTimer);
142
+ if (terminationTimer)
143
+ clearTimeout(terminationTimer);
144
+ if (forceSettleTimer)
145
+ clearTimeout(forceSettleTimer);
146
+ };
147
+ const finishError = (error) => {
148
+ if (settled)
149
+ return;
150
+ settled = true;
151
+ cleanup();
152
+ reject(safeError(error));
153
+ };
154
+ const stopWithError = (error) => {
155
+ if (fatalError)
156
+ return;
157
+ fatalError = error;
158
+ terminationTimer = setTimeout(() => {
159
+ if (settled)
160
+ return;
161
+ forceSettleTimer = setTimeout(() => {
162
+ finishError(fatalError ?? error);
163
+ }, forceSettleMs);
164
+ forceSettleTimer.unref?.();
165
+ child.kill("SIGKILL");
166
+ }, terminationGraceMs);
167
+ terminationTimer.unref?.();
168
+ child.kill("SIGTERM");
169
+ };
170
+ const abort = () => stopWithError(createAbortError());
171
+ const streamError = (error) => {
172
+ if (!settled)
173
+ stopWithError(error);
174
+ };
175
+ child.stdin.on("error", streamError);
176
+ child.stdout.on("error", streamError);
177
+ child.stderr.on("error", streamError);
178
+ if (options.signal) {
179
+ if (options.signal.aborted)
180
+ abort();
181
+ else
182
+ options.signal.addEventListener("abort", abort, { once: true });
183
+ }
184
+ child.stdout.on("data", (chunk) => {
185
+ if (fatalError)
186
+ return;
187
+ const bytes = Buffer.isBuffer(chunk)
188
+ ? chunk.length
189
+ : Buffer.byteLength(chunk);
190
+ streamBytes += bytes;
191
+ if (streamBytes > maxStreamBytes) {
192
+ stopWithError(new Error(`Claude Code stream exceeded ${maxStreamBytes} bytes.`));
193
+ return;
194
+ }
195
+ pending += decoder.write(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
196
+ try {
197
+ pending = consumeJsonLines(pending, events, maxEvents, options.onEvent);
198
+ }
199
+ catch (error) {
200
+ stopWithError(toError(error));
201
+ }
202
+ });
203
+ child.stderr.on("data", (chunk) => {
204
+ const encoded = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
205
+ const remaining = Math.max(0, maxStderrBytes - stderrBytes);
206
+ if (remaining === 0) {
207
+ stderrTruncated = true;
208
+ return;
209
+ }
210
+ stderr += stderrDecoder.write(encoded.subarray(0, remaining));
211
+ stderrBytes += Math.min(encoded.length, remaining);
212
+ if (encoded.length > remaining)
213
+ stderrTruncated = true;
214
+ });
215
+ child.once("error", finishError);
216
+ child.once("close", (exitCode, exitSignal) => {
217
+ if (settled)
218
+ return;
219
+ try {
220
+ pending += decoder.end();
221
+ stderr += stderrDecoder.end();
222
+ if (pending.trim()) {
223
+ consumeJsonLine(pending, events, maxEvents, options.onEvent);
224
+ }
225
+ }
226
+ catch (error) {
227
+ fatalError ??= toError(error);
228
+ }
229
+ if (fatalError) {
230
+ finishError(fatalError);
231
+ return;
232
+ }
233
+ if (exitCode !== 0) {
234
+ finishError(new Error(`Claude Code exited with ${exitSignal ?? exitCode ?? "unknown"}${stderr ? `: ${summarizeStderr(stderr)}` : ""}`));
235
+ return;
236
+ }
237
+ settled = true;
238
+ cleanup();
239
+ resolve({
240
+ exitCode: 0,
241
+ events,
242
+ stderr: sanitizeStderr(stderr),
243
+ stderrTruncated,
244
+ });
245
+ });
246
+ try {
247
+ child.stdin.end(options.prompt);
248
+ }
249
+ catch (error) {
250
+ stopWithError(toError(error));
251
+ }
252
+ });
253
+ }
254
+ function consumeJsonLines(value, events, maxEvents, onEvent) {
255
+ let start = 0;
256
+ let newline = value.indexOf("\n", start);
257
+ while (newline !== -1) {
258
+ consumeJsonLine(value.slice(start, newline), events, maxEvents, onEvent);
259
+ start = newline + 1;
260
+ newline = value.indexOf("\n", start);
261
+ }
262
+ return value.slice(start);
263
+ }
264
+ function consumeJsonLine(line, events, maxEvents, onEvent) {
265
+ const trimmed = line.trim();
266
+ if (!trimmed)
267
+ return;
268
+ if (events.length >= maxEvents) {
269
+ throw new Error(`Claude Code stream exceeded ${maxEvents} events.`);
270
+ }
271
+ const parsed = JSON.parse(trimmed);
272
+ const event = asRecord(parsed);
273
+ if (!event)
274
+ throw new Error("Claude Code emitted a non-object JSON event.");
275
+ events.push(event);
276
+ onEvent?.(event);
277
+ }
278
+ function assertClaudeCodeSubscription(status) {
279
+ if (!status.loggedIn ||
280
+ status.authMethod !== "claude.ai" ||
281
+ status.apiProvider !== "firstParty" ||
282
+ !readString(status.subscriptionType)) {
283
+ throw new ClaudeCodeSubscriptionRequiredError("Claude Code must be signed in with a Claude subscription. API-key and third-party provider fallback are disabled.");
284
+ }
285
+ }
286
+ function safeEnvironment(input) {
287
+ return Object.fromEntries(SAFE_ENVIRONMENT_KEYS.flatMap((key) => typeof input[key] === "string" ? [[key, input[key]]] : []));
288
+ }
289
+ function validateInput(options) {
290
+ if (!readString(options.prompt))
291
+ throw new Error("Claude Code prompt is required.");
292
+ if (!readString(options.cwd))
293
+ throw new Error("Claude Code cwd is required.");
294
+ if (options.session?.sessionId && options.session.resumeSessionId) {
295
+ throw new Error("Choose either a new Claude session id or a resume id.");
296
+ }
297
+ resolveCommand(options.command, "claude");
298
+ }
299
+ function boundedLimit(value, maximum) {
300
+ return Number.isSafeInteger(value) && (value ?? 0) > 0
301
+ ? Math.min(value, maximum)
302
+ : maximum;
303
+ }
304
+ function boundedDuration(value, fallback) {
305
+ return Number.isSafeInteger(value) && (value ?? 0) > 0
306
+ ? Math.min(value, DEFAULT_TIMEOUT_MS)
307
+ : fallback;
308
+ }
309
+ function resolveCommand(command, defaultCommand) {
310
+ const value = readString(command) ?? defaultCommand;
311
+ if (value === defaultCommand)
312
+ return value;
313
+ if (value.includes("\0") || !isAbsolute(value)) {
314
+ throw new Error("Claude Code command must be an absolute executable path.");
315
+ }
316
+ return value;
317
+ }
318
+ function createAbortError() {
319
+ const error = new Error("Claude Code participant was canceled.");
320
+ error.name = "AbortError";
321
+ return error;
322
+ }
323
+ function toError(value) {
324
+ return value instanceof Error ? value : new Error(String(value));
325
+ }
326
+ function safeError(error) {
327
+ const safe = new Error(summarizeStderr(error.message));
328
+ safe.name = error.name;
329
+ return safe;
330
+ }
331
+ function summarizeStderr(value) {
332
+ return sanitizeStderr(value)
333
+ .replace(/\s+/g, " ")
334
+ .trim()
335
+ .slice(0, MAX_ERROR_MESSAGE_LENGTH);
336
+ }
337
+ function sanitizeStderr(value) {
338
+ return value
339
+ .replace(/\bBearer\s+\S+/gi, "Bearer <redacted>")
340
+ .replace(/(["']?)([A-Za-z_]*(?:token|key|secret|password)[A-Za-z_]*)\1\s*([=:])\s*(?:"[^"]*"|'[^']*'|[^\s,;}\]]+)/gi, '$1$2$1$3"<redacted>"')
341
+ .replace(/\b(?:sk|rk)-[A-Za-z0-9_-]{8,}\b/g, "<redacted>");
342
+ }
343
+ function readString(value) {
344
+ if (typeof value !== "string")
345
+ return undefined;
346
+ const trimmed = value.trim();
347
+ return trimmed || undefined;
348
+ }
349
+ function asRecord(value) {
350
+ return value !== null && typeof value === "object" && !Array.isArray(value)
351
+ ? value
352
+ : undefined;
353
+ }
354
+ export const CLAUDE_CODE_PARTICIPANT_TESTED_VERSION = CLAUDE_CODE_VERSION;
355
+ //# sourceMappingURL=claude-code-participant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-code-participant.js","sourceRoot":"","sources":["../../src/cli/claude-code-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,mBAAmB,GAAG,SAAS,CAAC;AACtC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AACxC,MAAM,qBAAqB,GAAG,8BAA8B,CAAC;AAC7D,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,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,4BAA4B,GAAG,KAAK,CAAC;AAC3C,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAM,qBAAqB,GAAG;IAC5B,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,MAAM;IACN,UAAU;IACV,aA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ACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,sCAAsC,GAAG,mBAAmB,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 CLAUDE_CODE_VERSION = \"2.1.208\";\nconst WATCHDOG_TOOLS = \"Read,Glob,Grep\";\nconst WATCHDOG_DENIED_TOOLS = \"Edit,Write,NotebookEdit,Bash\";\nconst DRIVER_TOOLS = \"Read,Glob,Grep,Edit,Write\";\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 // Claude Code uses this as its config root; HOME remains required for its\n // default config and macOS Keychain-backed subscription login.\n \"CLAUDE_CONFIG_DIR\",\n] as const;\n\nexport type ClaudeCodeParticipantRole = \"watchdog\" | \"driver\";\n\nexport interface ClaudeCodeSubscriptionStatus {\n loggedIn: boolean;\n authMethod?: string;\n apiProvider?: string;\n subscriptionType?: string;\n}\n\nexport interface ClaudeCodeParticipantSession {\n sessionId?: string;\n resumeSessionId?: string;\n persist?: boolean;\n}\n\nexport interface ClaudeCodeParticipantEvent {\n [key: string]: unknown;\n}\n\nexport interface ClaudeCodeParticipantResult {\n exitCode: number;\n events: ClaudeCodeParticipantEvent[];\n stderr: string;\n stderrTruncated: boolean;\n}\n\nexport interface ClaudeCodeParticipantChild {\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 ClaudeCodeParticipantSpawnOptions {\n cwd: string;\n env: NodeJS.ProcessEnv;\n shell: false;\n stdio: [\"pipe\", \"pipe\", \"pipe\"];\n}\n\nexport type ClaudeCodeParticipantSpawn = (\n command: string,\n args: string[],\n options: ClaudeCodeParticipantSpawnOptions,\n) => ClaudeCodeParticipantChild;\n\nexport interface RunClaudeCodeParticipantOptions {\n role: ClaudeCodeParticipantRole;\n prompt: string;\n cwd: string;\n model?: string;\n session?: ClaudeCodeParticipantSession;\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: ClaudeCodeParticipantEvent) => void;\n preflight?: (\n context: ClaudeCodeParticipantPreflightContext,\n ) => Promise<ClaudeCodeSubscriptionStatus>;\n spawnProcess?: ClaudeCodeParticipantSpawn;\n}\n\nexport interface ClaudeCodeParticipantPreflightContext {\n command: string;\n env: NodeJS.ProcessEnv;\n}\n\nexport class ClaudeCodeSubscriptionRequiredError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ClaudeCodeSubscriptionRequiredError\";\n }\n}\n\nexport interface ClaudeCodeSubscriptionStatusOptions {\n command?: string;\n env?: NodeJS.ProcessEnv;\n execute?: typeof execFile;\n}\n\nexport async function readClaudeCodeSubscriptionStatus(\n options: ClaudeCodeSubscriptionStatusOptions = {},\n): Promise<ClaudeCodeSubscriptionStatus> {\n const execute = options.execute ?? execFile;\n const { stdout } = await execute(\n resolveCommand(options.command, \"claude\"),\n [\"auth\", \"status\", \"--json\"],\n {\n encoding: \"utf8\",\n maxBuffer: 128 * 1024,\n env: safeEnvironment(options.env ?? process.env),\n },\n );\n const parsed = JSON.parse(stdout) as unknown;\n const status = asRecord(parsed);\n if (!status || typeof status.loggedIn !== \"boolean\") {\n throw new Error(\"Claude Code returned an invalid authentication status.\");\n }\n return {\n loggedIn: status.loggedIn,\n authMethod: readString(status.authMethod),\n apiProvider: readString(status.apiProvider),\n subscriptionType: readString(status.subscriptionType),\n };\n}\n\nexport async function runClaudeCodeParticipant(\n options: RunClaudeCodeParticipantOptions,\n): Promise<ClaudeCodeParticipantResult> {\n validateInput(options);\n const env = safeEnvironment(options.env ?? process.env);\n const command = resolveCommand(options.command, \"claude\");\n const subscription = await (options.preflight\n ? options.preflight({ command, env })\n : readClaudeCodeSubscriptionStatus({ command, env }));\n assertClaudeCodeSubscription(subscription);\n if (options.signal?.aborted) throw createAbortError();\n\n const args = buildClaudeCodeParticipantArgs(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\n return collectClaudeCodeParticipantResult(child, options);\n}\n\nexport function buildClaudeCodeParticipantArgs(\n options: Pick<RunClaudeCodeParticipantOptions, \"role\" | \"model\" | \"session\">,\n): string[] {\n const args = [\n \"--print\",\n \"--input-format\",\n \"text\",\n \"--output-format\",\n \"stream-json\",\n \"--verbose\",\n \"--no-chrome\",\n \"--disable-slash-commands\",\n \"--strict-mcp-config\",\n \"--setting-sources\",\n \"\",\n ];\n\n if (options.role === \"watchdog\") {\n args.push(\n \"--permission-mode\",\n \"plan\",\n \"--tools\",\n WATCHDOG_TOOLS,\n \"--disallowedTools\",\n WATCHDOG_DENIED_TOOLS,\n );\n } else {\n args.push(\"--permission-mode\", \"acceptEdits\", \"--tools\", DRIVER_TOOLS);\n }\n\n const model = readString(options.model);\n if (model) args.push(\"--model\", model);\n const sessionId = readString(options.session?.sessionId);\n const resumeSessionId = readString(options.session?.resumeSessionId);\n if (sessionId) args.push(\"--session-id\", sessionId);\n if (resumeSessionId) args.push(\"--resume\", resumeSessionId);\n if (options.session?.persist !== true) args.push(\"--no-session-persistence\");\n return args;\n}\n\nfunction collectClaudeCodeParticipantResult(\n child: ClaudeCodeParticipantChild,\n options: RunClaudeCodeParticipantOptions,\n): Promise<ClaudeCodeParticipantResult> {\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: ClaudeCodeParticipantEvent[] = [];\n let pending = \"\";\n let streamBytes = 0;\n let stderr = \"\";\n let stderrBytes = 0;\n let stderrTruncated = false;\n let fatalError: Error | 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(`Claude Code 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\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(`Claude Code stream exceeded ${maxStreamBytes} bytes.`),\n );\n return;\n }\n pending += decoder.write(\n Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk),\n );\n try {\n pending = consumeJsonLines(pending, events, maxEvents, options.onEvent);\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()) {\n consumeJsonLine(pending, events, maxEvents, options.onEvent);\n }\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 `Claude Code 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 });\n });\n try {\n child.stdin.end(options.prompt);\n } catch (error) {\n stopWithError(toError(error));\n }\n });\n}\n\nfunction consumeJsonLines(\n value: string,\n events: ClaudeCodeParticipantEvent[],\n maxEvents: number,\n onEvent?: (event: ClaudeCodeParticipantEvent) => void,\n): string {\n let start = 0;\n let newline = value.indexOf(\"\\n\", start);\n while (newline !== -1) {\n consumeJsonLine(value.slice(start, newline), events, maxEvents, onEvent);\n start = newline + 1;\n newline = value.indexOf(\"\\n\", start);\n }\n return value.slice(start);\n}\n\nfunction consumeJsonLine(\n line: string,\n events: ClaudeCodeParticipantEvent[],\n maxEvents: number,\n onEvent?: (event: ClaudeCodeParticipantEvent) => void,\n): void {\n const trimmed = line.trim();\n if (!trimmed) return;\n if (events.length >= maxEvents) {\n throw new Error(`Claude Code stream exceeded ${maxEvents} events.`);\n }\n const parsed = JSON.parse(trimmed) as unknown;\n const event = asRecord(parsed);\n if (!event) throw new Error(\"Claude Code emitted a non-object JSON event.\");\n events.push(event);\n onEvent?.(event);\n}\n\nfunction assertClaudeCodeSubscription(\n status: ClaudeCodeSubscriptionStatus,\n): void {\n if (\n !status.loggedIn ||\n status.authMethod !== \"claude.ai\" ||\n status.apiProvider !== \"firstParty\" ||\n !readString(status.subscriptionType)\n ) {\n throw new ClaudeCodeSubscriptionRequiredError(\n \"Claude Code must be signed in with a Claude subscription. API-key and third-party provider fallback are disabled.\",\n );\n }\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: RunClaudeCodeParticipantOptions): void {\n if (!readString(options.prompt))\n throw new Error(\"Claude Code prompt is required.\");\n if (!readString(options.cwd)) throw new Error(\"Claude Code cwd is required.\");\n if (options.session?.sessionId && options.session.resumeSessionId) {\n throw new Error(\"Choose either a new Claude session id or a resume id.\");\n }\n resolveCommand(options.command, \"claude\");\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(\"Claude Code command must be an absolute executable path.\");\n }\n return value;\n}\n\nfunction createAbortError(): Error {\n const error = new Error(\"Claude Code 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): Record<string, unknown> | undefined {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nexport const CLAUDE_CODE_PARTICIPANT_TESTED_VERSION = CLAUDE_CODE_VERSION;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"code-agent-executor.d.ts","sourceRoot":"","sources":["../../src/cli/code-agent-executor.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EAEd,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,sCAAsC,CAAC;AAS9C,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAQL,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACxB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,WAAW,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC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jB;AAmED;;;;;;;;;GASG;AACH,wCAAwC;AACxC,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,uBAAuB,GACtC,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED,wCAAwC;AACxC,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED,wCAAwC;AACxC,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,uBAAuB,EACvC,qBAAqB,SAAK,EAC1B,WAAW,SAAK,GACf,MAAM,CA4DR;AAuFD,MAAM,MAAM,0BAA0B,GAClC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,MAAM,GACd,0BAA0B,CAuD5B;AA0FD,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,cAAc,GAAG,IAAI,GAC3B,IAAI,CAgBN"}
@@ -462,35 +462,43 @@ async function executeCodexCliRun(options) {
462
462
  signal: options.signal,
463
463
  });
464
464
  if (result.exitCode !== 0) {
465
+ const interrupted = options.signal?.aborted === true;
465
466
  const message = result.error ??
466
467
  result.stderr.trim() ??
467
468
  `Codex CLI exited with ${result.exitSignal ?? result.exitCode}.`;
468
- options.stdout?.write(`\nCodex CLI run failed: ${message}\n`);
469
+ const summary = interrupted
470
+ ? "Codex CLI run paused."
471
+ : `Codex CLI run failed: ${message}`;
472
+ options.stdout?.write(`\n${summary}\n`);
469
473
  appendCodeAgentTranscriptEvent({
470
474
  runId: options.run.id,
471
475
  kind: "status",
472
- message: `Codex CLI run failed: ${message}`,
476
+ message: summary,
473
477
  metadata: {
474
- status: "errored",
475
- phase: "error",
478
+ status: interrupted ? "paused" : "errored",
479
+ phase: interrupted ? "paused" : "error",
476
480
  engine: CODEX_CLI_ENGINE_NAME,
477
481
  exitCode: result.exitCode,
478
482
  exitSignal: result.exitSignal,
479
483
  },
480
484
  });
481
485
  return updateCodeAgentRunRecord(options.run.id, {
482
- status: options.signal?.aborted ? "paused" : "errored",
483
- phase: options.signal?.aborted ? "paused" : "error",
486
+ status: interrupted ? "paused" : "errored",
487
+ phase: interrupted ? "paused" : "error",
484
488
  progress: {
485
- label: options.signal?.aborted ? "Paused" : "Error",
489
+ label: interrupted ? "Paused" : "Error",
486
490
  completed: 0,
487
491
  total: 1,
488
- failed: options.signal?.aborted ? 0 : 1,
492
+ failed: interrupted ? 0 : 1,
489
493
  percent: 0,
490
494
  },
491
495
  metadata: {
492
- executionError: message,
493
- executionErroredAt: new Date().toISOString(),
496
+ ...(interrupted
497
+ ? { executionPausedAt: new Date().toISOString() }
498
+ : {
499
+ executionError: message,
500
+ executionErroredAt: new Date().toISOString(),
501
+ }),
494
502
  engine: CODEX_CLI_ENGINE_NAME,
495
503
  model: model ?? "codex-default",
496
504
  },