workos 0.19.0 → 0.20.2

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 (681) hide show
  1. package/README.md +4 -646
  2. package/bin/workos.js +44 -0
  3. package/package.json +18 -99
  4. package/LICENSE +0 -47
  5. package/dist/bin.d.ts +0 -2
  6. package/dist/bin.js +0 -1790
  7. package/dist/bin.js.map +0 -1
  8. package/dist/cli.config.d.ts +0 -88
  9. package/dist/cli.config.js +0 -110
  10. package/dist/cli.config.js.map +0 -1
  11. package/dist/commands/api/catalog.d.ts +0 -23
  12. package/dist/commands/api/catalog.js +0 -97
  13. package/dist/commands/api/catalog.js.map +0 -1
  14. package/dist/commands/api/format.d.ts +0 -5
  15. package/dist/commands/api/format.js +0 -46
  16. package/dist/commands/api/format.js.map +0 -1
  17. package/dist/commands/api/index.d.ts +0 -15
  18. package/dist/commands/api/index.js +0 -213
  19. package/dist/commands/api/index.js.map +0 -1
  20. package/dist/commands/api/interactive.d.ts +0 -3
  21. package/dist/commands/api/interactive.js +0 -133
  22. package/dist/commands/api/interactive.js.map +0 -1
  23. package/dist/commands/api/request.d.ts +0 -14
  24. package/dist/commands/api/request.js +0 -38
  25. package/dist/commands/api/request.js.map +0 -1
  26. package/dist/commands/api-key-mgmt.d.ts +0 -16
  27. package/dist/commands/api-key-mgmt.js +0 -96
  28. package/dist/commands/api-key-mgmt.js.map +0 -1
  29. package/dist/commands/audit-log.d.ts +0 -26
  30. package/dist/commands/audit-log.js +0 -155
  31. package/dist/commands/audit-log.js.map +0 -1
  32. package/dist/commands/auth-status.d.ts +0 -1
  33. package/dist/commands/auth-status.js +0 -57
  34. package/dist/commands/auth-status.js.map +0 -1
  35. package/dist/commands/claim.d.ts +0 -11
  36. package/dist/commands/claim.js +0 -143
  37. package/dist/commands/claim.js.map +0 -1
  38. package/dist/commands/config.d.ts +0 -3
  39. package/dist/commands/config.js +0 -54
  40. package/dist/commands/config.js.map +0 -1
  41. package/dist/commands/connection.d.ts +0 -13
  42. package/dist/commands/connection.js +0 -96
  43. package/dist/commands/connection.js.map +0 -1
  44. package/dist/commands/debug-sso.d.ts +0 -1
  45. package/dist/commands/debug-sso.js +0 -78
  46. package/dist/commands/debug-sso.js.map +0 -1
  47. package/dist/commands/debug-sync.d.ts +0 -1
  48. package/dist/commands/debug-sync.js +0 -102
  49. package/dist/commands/debug-sync.js.map +0 -1
  50. package/dist/commands/debug.d.ts +0 -28
  51. package/dist/commands/debug.js +0 -406
  52. package/dist/commands/debug.js.map +0 -1
  53. package/dist/commands/dev.d.ts +0 -22
  54. package/dist/commands/dev.js +0 -145
  55. package/dist/commands/dev.js.map +0 -1
  56. package/dist/commands/directory.d.ts +0 -27
  57. package/dist/commands/directory.js +0 -176
  58. package/dist/commands/directory.js.map +0 -1
  59. package/dist/commands/doctor.d.ts +0 -12
  60. package/dist/commands/doctor.js +0 -41
  61. package/dist/commands/doctor.js.map +0 -1
  62. package/dist/commands/emulate.d.ts +0 -7
  63. package/dist/commands/emulate.js +0 -69
  64. package/dist/commands/emulate.js.map +0 -1
  65. package/dist/commands/env.d.ts +0 -19
  66. package/dist/commands/env.js +0 -303
  67. package/dist/commands/env.js.map +0 -1
  68. package/dist/commands/event.d.ts +0 -9
  69. package/dist/commands/event.js +0 -43
  70. package/dist/commands/event.js.map +0 -1
  71. package/dist/commands/feature-flag.d.ts +0 -12
  72. package/dist/commands/feature-flag.js +0 -96
  73. package/dist/commands/feature-flag.js.map +0 -1
  74. package/dist/commands/install-skill.d.ts +0 -85
  75. package/dist/commands/install-skill.js +0 -332
  76. package/dist/commands/install-skill.js.map +0 -1
  77. package/dist/commands/install.d.ts +0 -6
  78. package/dist/commands/install.js +0 -51
  79. package/dist/commands/install.js.map +0 -1
  80. package/dist/commands/invitation.d.ts +0 -19
  81. package/dist/commands/invitation.js +0 -94
  82. package/dist/commands/invitation.js.map +0 -1
  83. package/dist/commands/list-skills.d.ts +0 -4
  84. package/dist/commands/list-skills.js +0 -52
  85. package/dist/commands/list-skills.js.map +0 -1
  86. package/dist/commands/login.d.ts +0 -32
  87. package/dist/commands/login.js +0 -239
  88. package/dist/commands/login.js.map +0 -1
  89. package/dist/commands/logout.d.ts +0 -1
  90. package/dist/commands/logout.js +0 -17
  91. package/dist/commands/logout.js.map +0 -1
  92. package/dist/commands/mcp.d.ts +0 -14
  93. package/dist/commands/mcp.js +0 -99
  94. package/dist/commands/mcp.js.map +0 -1
  95. package/dist/commands/membership.d.ts +0 -20
  96. package/dist/commands/membership.js +0 -129
  97. package/dist/commands/membership.js.map +0 -1
  98. package/dist/commands/migrations.d.ts +0 -2
  99. package/dist/commands/migrations.js +0 -50
  100. package/dist/commands/migrations.js.map +0 -1
  101. package/dist/commands/onboard-user.d.ts +0 -7
  102. package/dist/commands/onboard-user.js +0 -61
  103. package/dist/commands/onboard-user.js.map +0 -1
  104. package/dist/commands/org-domain.d.ts +0 -4
  105. package/dist/commands/org-domain.js +0 -45
  106. package/dist/commands/org-domain.js.map +0 -1
  107. package/dist/commands/organization.d.ts +0 -14
  108. package/dist/commands/organization.js +0 -103
  109. package/dist/commands/organization.js.map +0 -1
  110. package/dist/commands/permission.d.ts +0 -20
  111. package/dist/commands/permission.js +0 -93
  112. package/dist/commands/permission.js.map +0 -1
  113. package/dist/commands/portal.d.ts +0 -7
  114. package/dist/commands/portal.js +0 -26
  115. package/dist/commands/portal.js.map +0 -1
  116. package/dist/commands/role.d.ts +0 -17
  117. package/dist/commands/role.js +0 -122
  118. package/dist/commands/role.js.map +0 -1
  119. package/dist/commands/seed.d.ts +0 -6
  120. package/dist/commands/seed.js +0 -298
  121. package/dist/commands/seed.js.map +0 -1
  122. package/dist/commands/session.d.ts +0 -8
  123. package/dist/commands/session.js +0 -63
  124. package/dist/commands/session.js.map +0 -1
  125. package/dist/commands/setup-org.d.ts +0 -6
  126. package/dist/commands/setup-org.js +0 -99
  127. package/dist/commands/setup-org.js.map +0 -1
  128. package/dist/commands/setup.d.ts +0 -50
  129. package/dist/commands/setup.js +0 -237
  130. package/dist/commands/setup.js.map +0 -1
  131. package/dist/commands/telemetry.d.ts +0 -3
  132. package/dist/commands/telemetry.js +0 -88
  133. package/dist/commands/telemetry.js.map +0 -1
  134. package/dist/commands/uninstall-skill.d.ts +0 -11
  135. package/dist/commands/uninstall-skill.js +0 -117
  136. package/dist/commands/uninstall-skill.js.map +0 -1
  137. package/dist/commands/user.d.ts +0 -19
  138. package/dist/commands/user.js +0 -92
  139. package/dist/commands/user.js.map +0 -1
  140. package/dist/commands/vault-run.d.ts +0 -13
  141. package/dist/commands/vault-run.js +0 -195
  142. package/dist/commands/vault-run.js.map +0 -1
  143. package/dist/commands/vault.d.ts +0 -25
  144. package/dist/commands/vault.js +0 -153
  145. package/dist/commands/vault.js.map +0 -1
  146. package/dist/commands/verify-login.d.ts +0 -25
  147. package/dist/commands/verify-login.js +0 -158
  148. package/dist/commands/verify-login.js.map +0 -1
  149. package/dist/commands/webhook.d.ts +0 -3
  150. package/dist/commands/webhook.js +0 -92
  151. package/dist/commands/webhook.js.map +0 -1
  152. package/dist/craft-pre-release.sh +0 -10
  153. package/dist/dashboard/components/AnimatedLogo.d.ts +0 -8
  154. package/dist/dashboard/components/AnimatedLogo.js +0 -16
  155. package/dist/dashboard/components/AnimatedLogo.js.map +0 -1
  156. package/dist/dashboard/components/CompletionView.d.ts +0 -13
  157. package/dist/dashboard/components/CompletionView.js +0 -25
  158. package/dist/dashboard/components/CompletionView.js.map +0 -1
  159. package/dist/dashboard/components/ConfirmPrompt.d.ts +0 -9
  160. package/dist/dashboard/components/ConfirmPrompt.js +0 -25
  161. package/dist/dashboard/components/ConfirmPrompt.js.map +0 -1
  162. package/dist/dashboard/components/CredentialsForm.d.ts +0 -10
  163. package/dist/dashboard/components/CredentialsForm.js +0 -47
  164. package/dist/dashboard/components/CredentialsForm.js.map +0 -1
  165. package/dist/dashboard/components/Dashboard.d.ts +0 -3
  166. package/dist/dashboard/components/Dashboard.js +0 -100
  167. package/dist/dashboard/components/Dashboard.js.map +0 -1
  168. package/dist/dashboard/components/DashboardLayout.d.ts +0 -24
  169. package/dist/dashboard/components/DashboardLayout.js +0 -25
  170. package/dist/dashboard/components/DashboardLayout.js.map +0 -1
  171. package/dist/dashboard/components/DiffPanel.d.ts +0 -9
  172. package/dist/dashboard/components/DiffPanel.js +0 -136
  173. package/dist/dashboard/components/DiffPanel.js.map +0 -1
  174. package/dist/dashboard/components/InlinePrompt.d.ts +0 -8
  175. package/dist/dashboard/components/InlinePrompt.js +0 -19
  176. package/dist/dashboard/components/InlinePrompt.js.map +0 -1
  177. package/dist/dashboard/components/OutputPanel.d.ts +0 -10
  178. package/dist/dashboard/components/OutputPanel.js +0 -100
  179. package/dist/dashboard/components/OutputPanel.js.map +0 -1
  180. package/dist/dashboard/components/Panel.d.ts +0 -12
  181. package/dist/dashboard/components/Panel.js +0 -6
  182. package/dist/dashboard/components/Panel.js.map +0 -1
  183. package/dist/dashboard/components/TextInput.d.ts +0 -13
  184. package/dist/dashboard/components/TextInput.js +0 -57
  185. package/dist/dashboard/components/TextInput.js.map +0 -1
  186. package/dist/dashboard/components/WelcomeArt.d.ts +0 -2
  187. package/dist/dashboard/components/WelcomeArt.js +0 -9
  188. package/dist/dashboard/components/WelcomeArt.js.map +0 -1
  189. package/dist/dashboard/hooks/useAnimation.d.ts +0 -7
  190. package/dist/dashboard/hooks/useAnimation.js +0 -24
  191. package/dist/dashboard/hooks/useAnimation.js.map +0 -1
  192. package/dist/dashboard/hooks/useKeyboard.d.ts +0 -8
  193. package/dist/dashboard/hooks/useKeyboard.js +0 -18
  194. package/dist/dashboard/hooks/useKeyboard.js.map +0 -1
  195. package/dist/dashboard/hooks/useTerminalSize.d.ts +0 -8
  196. package/dist/dashboard/hooks/useTerminalSize.js +0 -23
  197. package/dist/dashboard/hooks/useTerminalSize.js.map +0 -1
  198. package/dist/dashboard/index.d.ts +0 -6
  199. package/dist/dashboard/index.js +0 -36
  200. package/dist/dashboard/index.js.map +0 -1
  201. package/dist/dashboard/lib/diff-utils.d.ts +0 -21
  202. package/dist/dashboard/lib/diff-utils.js +0 -271
  203. package/dist/dashboard/lib/diff-utils.js.map +0 -1
  204. package/dist/dashboard/lib/logo-frames.d.ts +0 -20
  205. package/dist/dashboard/lib/logo-frames.js +0 -109
  206. package/dist/dashboard/lib/logo-frames.js.map +0 -1
  207. package/dist/dashboard/lib/welcome-art.d.ts +0 -1
  208. package/dist/dashboard/lib/welcome-art.js +0 -5
  209. package/dist/dashboard/lib/welcome-art.js.map +0 -1
  210. package/dist/dashboard/types.d.ts +0 -5
  211. package/dist/dashboard/types.js +0 -2
  212. package/dist/dashboard/types.js.map +0 -1
  213. package/dist/doctor/agent-prompt.d.ts +0 -10
  214. package/dist/doctor/agent-prompt.js +0 -190
  215. package/dist/doctor/agent-prompt.js.map +0 -1
  216. package/dist/doctor/checks/ai-analysis.d.ts +0 -9
  217. package/dist/doctor/checks/ai-analysis.js +0 -124
  218. package/dist/doctor/checks/ai-analysis.js.map +0 -1
  219. package/dist/doctor/checks/auth-patterns.d.ts +0 -2
  220. package/dist/doctor/checks/auth-patterns.js +0 -569
  221. package/dist/doctor/checks/auth-patterns.js.map +0 -1
  222. package/dist/doctor/checks/connectivity.d.ts +0 -2
  223. package/dist/doctor/checks/connectivity.js +0 -35
  224. package/dist/doctor/checks/connectivity.js.map +0 -1
  225. package/dist/doctor/checks/dashboard.d.ts +0 -3
  226. package/dist/doctor/checks/dashboard.js +0 -123
  227. package/dist/doctor/checks/dashboard.js.map +0 -1
  228. package/dist/doctor/checks/environment.d.ts +0 -2
  229. package/dist/doctor/checks/environment.js +0 -86
  230. package/dist/doctor/checks/environment.js.map +0 -1
  231. package/dist/doctor/checks/framework.d.ts +0 -2
  232. package/dist/doctor/checks/framework.js +0 -94
  233. package/dist/doctor/checks/framework.js.map +0 -1
  234. package/dist/doctor/checks/host-execution.d.ts +0 -2
  235. package/dist/doctor/checks/host-execution.js +0 -21
  236. package/dist/doctor/checks/host-execution.js.map +0 -1
  237. package/dist/doctor/checks/language.d.ts +0 -6
  238. package/dist/doctor/checks/language.js +0 -104
  239. package/dist/doctor/checks/language.js.map +0 -1
  240. package/dist/doctor/checks/mcp.d.ts +0 -15
  241. package/dist/doctor/checks/mcp.js +0 -34
  242. package/dist/doctor/checks/mcp.js.map +0 -1
  243. package/dist/doctor/checks/runtime.d.ts +0 -2
  244. package/dist/doctor/checks/runtime.js +0 -20
  245. package/dist/doctor/checks/runtime.js.map +0 -1
  246. package/dist/doctor/checks/sdk.d.ts +0 -2
  247. package/dist/doctor/checks/sdk.js +0 -192
  248. package/dist/doctor/checks/sdk.js.map +0 -1
  249. package/dist/doctor/checks/skills.d.ts +0 -9
  250. package/dist/doctor/checks/skills.js +0 -84
  251. package/dist/doctor/checks/skills.js.map +0 -1
  252. package/dist/doctor/clipboard.d.ts +0 -1
  253. package/dist/doctor/clipboard.js +0 -43
  254. package/dist/doctor/clipboard.js.map +0 -1
  255. package/dist/doctor/index.d.ts +0 -26
  256. package/dist/doctor/index.js +0 -182
  257. package/dist/doctor/index.js.map +0 -1
  258. package/dist/doctor/issues.d.ts +0 -63
  259. package/dist/doctor/issues.js +0 -199
  260. package/dist/doctor/issues.js.map +0 -1
  261. package/dist/doctor/json-output.d.ts +0 -2
  262. package/dist/doctor/json-output.js +0 -4
  263. package/dist/doctor/json-output.js.map +0 -1
  264. package/dist/doctor/output.d.ts +0 -7
  265. package/dist/doctor/output.js +0 -289
  266. package/dist/doctor/output.js.map +0 -1
  267. package/dist/doctor/types.d.ts +0 -203
  268. package/dist/doctor/types.js +0 -2
  269. package/dist/doctor/types.js.map +0 -1
  270. package/dist/integrations/dotnet/index.d.ts +0 -8
  271. package/dist/integrations/dotnet/index.js +0 -170
  272. package/dist/integrations/dotnet/index.js.map +0 -1
  273. package/dist/integrations/elixir/index.d.ts +0 -8
  274. package/dist/integrations/elixir/index.js +0 -146
  275. package/dist/integrations/elixir/index.js.map +0 -1
  276. package/dist/integrations/go/index.d.ts +0 -11
  277. package/dist/integrations/go/index.js +0 -212
  278. package/dist/integrations/go/index.js.map +0 -1
  279. package/dist/integrations/kotlin/index.d.ts +0 -4
  280. package/dist/integrations/kotlin/index.js +0 -78
  281. package/dist/integrations/kotlin/index.js.map +0 -1
  282. package/dist/integrations/nextjs/index.d.ts +0 -4
  283. package/dist/integrations/nextjs/index.js +0 -93
  284. package/dist/integrations/nextjs/index.js.map +0 -1
  285. package/dist/integrations/nextjs/utils.d.ts +0 -8
  286. package/dist/integrations/nextjs/utils.js +0 -68
  287. package/dist/integrations/nextjs/utils.js.map +0 -1
  288. package/dist/integrations/node/index.d.ts +0 -4
  289. package/dist/integrations/node/index.js +0 -52
  290. package/dist/integrations/node/index.js.map +0 -1
  291. package/dist/integrations/php/index.d.ts +0 -4
  292. package/dist/integrations/php/index.js +0 -51
  293. package/dist/integrations/php/index.js.map +0 -1
  294. package/dist/integrations/php-laravel/index.d.ts +0 -4
  295. package/dist/integrations/php-laravel/index.js +0 -51
  296. package/dist/integrations/php-laravel/index.js.map +0 -1
  297. package/dist/integrations/python/index.d.ts +0 -9
  298. package/dist/integrations/python/index.js +0 -249
  299. package/dist/integrations/python/index.js.map +0 -1
  300. package/dist/integrations/react/index.d.ts +0 -4
  301. package/dist/integrations/react/index.js +0 -49
  302. package/dist/integrations/react/index.js.map +0 -1
  303. package/dist/integrations/react-router/index.d.ts +0 -4
  304. package/dist/integrations/react-router/index.js +0 -94
  305. package/dist/integrations/react-router/index.js.map +0 -1
  306. package/dist/integrations/react-router/utils.d.ts +0 -10
  307. package/dist/integrations/react-router/utils.js +0 -162
  308. package/dist/integrations/react-router/utils.js.map +0 -1
  309. package/dist/integrations/ruby/index.d.ts +0 -8
  310. package/dist/integrations/ruby/index.js +0 -137
  311. package/dist/integrations/ruby/index.js.map +0 -1
  312. package/dist/integrations/sveltekit/index.d.ts +0 -4
  313. package/dist/integrations/sveltekit/index.js +0 -50
  314. package/dist/integrations/sveltekit/index.js.map +0 -1
  315. package/dist/integrations/tanstack-start/index.d.ts +0 -4
  316. package/dist/integrations/tanstack-start/index.js +0 -51
  317. package/dist/integrations/tanstack-start/index.js.map +0 -1
  318. package/dist/integrations/vanilla-js/index.d.ts +0 -4
  319. package/dist/integrations/vanilla-js/index.js +0 -49
  320. package/dist/integrations/vanilla-js/index.js.map +0 -1
  321. package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.d.ts +0 -7
  322. package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.js +0 -12
  323. package/dist/lib/__test-helpers__/mock-unclaimed-env-api-error.js.map +0 -1
  324. package/dist/lib/adapters/cli-adapter.d.ts +0 -113
  325. package/dist/lib/adapters/cli-adapter.js +0 -641
  326. package/dist/lib/adapters/cli-adapter.js.map +0 -1
  327. package/dist/lib/adapters/dashboard-adapter.d.ts +0 -34
  328. package/dist/lib/adapters/dashboard-adapter.js +0 -121
  329. package/dist/lib/adapters/dashboard-adapter.js.map +0 -1
  330. package/dist/lib/adapters/headless-adapter.d.ts +0 -80
  331. package/dist/lib/adapters/headless-adapter.js +0 -347
  332. package/dist/lib/adapters/headless-adapter.js.map +0 -1
  333. package/dist/lib/adapters/index.d.ts +0 -4
  334. package/dist/lib/adapters/index.js +0 -4
  335. package/dist/lib/adapters/index.js.map +0 -1
  336. package/dist/lib/adapters/types.d.ts +0 -41
  337. package/dist/lib/adapters/types.js +0 -2
  338. package/dist/lib/adapters/types.js.map +0 -1
  339. package/dist/lib/agent-interface.d.ts +0 -84
  340. package/dist/lib/agent-interface.js +0 -840
  341. package/dist/lib/agent-interface.js.map +0 -1
  342. package/dist/lib/agent-runner.d.ts +0 -9
  343. package/dist/lib/agent-runner.js +0 -261
  344. package/dist/lib/agent-runner.js.map +0 -1
  345. package/dist/lib/ai-content.d.ts +0 -14
  346. package/dist/lib/ai-content.js +0 -131
  347. package/dist/lib/ai-content.js.map +0 -1
  348. package/dist/lib/api-error-handler.d.ts +0 -18
  349. package/dist/lib/api-error-handler.js +0 -76
  350. package/dist/lib/api-error-handler.js.map +0 -1
  351. package/dist/lib/api-key.d.ts +0 -14
  352. package/dist/lib/api-key.js +0 -37
  353. package/dist/lib/api-key.js.map +0 -1
  354. package/dist/lib/api.d.ts +0 -25
  355. package/dist/lib/api.js +0 -120
  356. package/dist/lib/api.js.map +0 -1
  357. package/dist/lib/background-refresh.d.ts +0 -29
  358. package/dist/lib/background-refresh.js +0 -95
  359. package/dist/lib/background-refresh.js.map +0 -1
  360. package/dist/lib/command-aliases.d.ts +0 -8
  361. package/dist/lib/command-aliases.js +0 -12
  362. package/dist/lib/command-aliases.js.map +0 -1
  363. package/dist/lib/completion-data.d.ts +0 -33
  364. package/dist/lib/completion-data.js +0 -33
  365. package/dist/lib/completion-data.js.map +0 -1
  366. package/dist/lib/config-store.d.ts +0 -63
  367. package/dist/lib/config-store.js +0 -293
  368. package/dist/lib/config-store.js.map +0 -1
  369. package/dist/lib/config.d.ts +0 -34
  370. package/dist/lib/config.js +0 -37
  371. package/dist/lib/config.js.map +0 -1
  372. package/dist/lib/constants.d.ts +0 -51
  373. package/dist/lib/constants.js +0 -50
  374. package/dist/lib/constants.js.map +0 -1
  375. package/dist/lib/credential-discovery.d.ts +0 -42
  376. package/dist/lib/credential-discovery.js +0 -100
  377. package/dist/lib/credential-discovery.js.map +0 -1
  378. package/dist/lib/credential-proxy.d.ts +0 -45
  379. package/dist/lib/credential-proxy.js +0 -364
  380. package/dist/lib/credential-proxy.js.map +0 -1
  381. package/dist/lib/credential-store.d.ts +0 -32
  382. package/dist/lib/credential-store.js +0 -236
  383. package/dist/lib/credential-store.js.map +0 -1
  384. package/dist/lib/credentials.d.ts +0 -13
  385. package/dist/lib/credentials.js +0 -34
  386. package/dist/lib/credentials.js.map +0 -1
  387. package/dist/lib/dev-command.d.ts +0 -26
  388. package/dist/lib/dev-command.js +0 -129
  389. package/dist/lib/dev-command.js.map +0 -1
  390. package/dist/lib/device-auth.d.ts +0 -48
  391. package/dist/lib/device-auth.js +0 -176
  392. package/dist/lib/device-auth.js.map +0 -1
  393. package/dist/lib/device-id.d.ts +0 -25
  394. package/dist/lib/device-id.js +0 -102
  395. package/dist/lib/device-id.js.map +0 -1
  396. package/dist/lib/ensure-auth.d.ts +0 -12
  397. package/dist/lib/ensure-auth.js +0 -111
  398. package/dist/lib/ensure-auth.js.map +0 -1
  399. package/dist/lib/env-writer.d.ts +0 -25
  400. package/dist/lib/env-writer.js +0 -90
  401. package/dist/lib/env-writer.js.map +0 -1
  402. package/dist/lib/events.d.ts +0 -248
  403. package/dist/lib/events.js +0 -19
  404. package/dist/lib/events.js.map +0 -1
  405. package/dist/lib/framework-config.d.ts +0 -133
  406. package/dist/lib/framework-config.js +0 -11
  407. package/dist/lib/framework-config.js.map +0 -1
  408. package/dist/lib/helper-functions.d.ts +0 -1
  409. package/dist/lib/helper-functions.js +0 -2
  410. package/dist/lib/helper-functions.js.map +0 -1
  411. package/dist/lib/host-probe.d.ts +0 -28
  412. package/dist/lib/host-probe.js +0 -154
  413. package/dist/lib/host-probe.js.map +0 -1
  414. package/dist/lib/installer-core.d.ts +0 -569
  415. package/dist/lib/installer-core.js +0 -1134
  416. package/dist/lib/installer-core.js.map +0 -1
  417. package/dist/lib/installer-core.types.d.ts +0 -162
  418. package/dist/lib/installer-core.types.js +0 -2
  419. package/dist/lib/installer-core.types.js.map +0 -1
  420. package/dist/lib/mcp-clients.d.ts +0 -45
  421. package/dist/lib/mcp-clients.js +0 -297
  422. package/dist/lib/mcp-clients.js.map +0 -1
  423. package/dist/lib/port-detection.d.ts +0 -7
  424. package/dist/lib/port-detection.js +0 -244
  425. package/dist/lib/port-detection.js.map +0 -1
  426. package/dist/lib/post-install.d.ts +0 -8
  427. package/dist/lib/post-install.js +0 -51
  428. package/dist/lib/post-install.js.map +0 -1
  429. package/dist/lib/preferences.d.ts +0 -143
  430. package/dist/lib/preferences.js +0 -227
  431. package/dist/lib/preferences.js.map +0 -1
  432. package/dist/lib/progress-tracker.d.ts +0 -22
  433. package/dist/lib/progress-tracker.js +0 -47
  434. package/dist/lib/progress-tracker.js.map +0 -1
  435. package/dist/lib/registry.d.ts +0 -42
  436. package/dist/lib/registry.js +0 -96
  437. package/dist/lib/registry.js.map +0 -1
  438. package/dist/lib/resolve-install-credentials.d.ts +0 -11
  439. package/dist/lib/resolve-install-credentials.js +0 -53
  440. package/dist/lib/resolve-install-credentials.js.map +0 -1
  441. package/dist/lib/run-with-core.d.ts +0 -7
  442. package/dist/lib/run-with-core.js +0 -559
  443. package/dist/lib/run-with-core.js.map +0 -1
  444. package/dist/lib/safe-tools.d.ts +0 -2
  445. package/dist/lib/safe-tools.js +0 -212
  446. package/dist/lib/safe-tools.js.map +0 -1
  447. package/dist/lib/scaffold/index.d.ts +0 -1
  448. package/dist/lib/scaffold/index.js +0 -2
  449. package/dist/lib/scaffold/index.js.map +0 -1
  450. package/dist/lib/scaffold/scaffold.d.ts +0 -66
  451. package/dist/lib/scaffold/scaffold.js +0 -156
  452. package/dist/lib/scaffold/scaffold.js.map +0 -1
  453. package/dist/lib/settings.d.ts +0 -60
  454. package/dist/lib/settings.js +0 -31
  455. package/dist/lib/settings.js.map +0 -1
  456. package/dist/lib/staging-api.d.ts +0 -22
  457. package/dist/lib/staging-api.js +0 -74
  458. package/dist/lib/staging-api.js.map +0 -1
  459. package/dist/lib/startup-notice-gate.d.ts +0 -21
  460. package/dist/lib/startup-notice-gate.js +0 -29
  461. package/dist/lib/startup-notice-gate.js.map +0 -1
  462. package/dist/lib/telemetry-notice.d.ts +0 -25
  463. package/dist/lib/telemetry-notice.js +0 -58
  464. package/dist/lib/telemetry-notice.js.map +0 -1
  465. package/dist/lib/token-refresh-client.d.ts +0 -23
  466. package/dist/lib/token-refresh-client.js +0 -89
  467. package/dist/lib/token-refresh-client.js.map +0 -1
  468. package/dist/lib/token-refresh.d.ts +0 -12
  469. package/dist/lib/token-refresh.js +0 -27
  470. package/dist/lib/token-refresh.js.map +0 -1
  471. package/dist/lib/unclaimed-env-api.d.ts +0 -42
  472. package/dist/lib/unclaimed-env-api.js +0 -139
  473. package/dist/lib/unclaimed-env-api.js.map +0 -1
  474. package/dist/lib/unclaimed-env-provision.d.ts +0 -24
  475. package/dist/lib/unclaimed-env-provision.js +0 -80
  476. package/dist/lib/unclaimed-env-provision.js.map +0 -1
  477. package/dist/lib/unclaimed-warning.d.ts +0 -15
  478. package/dist/lib/unclaimed-warning.js +0 -78
  479. package/dist/lib/unclaimed-warning.js.map +0 -1
  480. package/dist/lib/validation/build-validator.d.ts +0 -21
  481. package/dist/lib/validation/build-validator.js +0 -153
  482. package/dist/lib/validation/build-validator.js.map +0 -1
  483. package/dist/lib/validation/index.d.ts +0 -4
  484. package/dist/lib/validation/index.js +0 -4
  485. package/dist/lib/validation/index.js.map +0 -1
  486. package/dist/lib/validation/quick-checks.d.ts +0 -19
  487. package/dist/lib/validation/quick-checks.js +0 -192
  488. package/dist/lib/validation/quick-checks.js.map +0 -1
  489. package/dist/lib/validation/security-checks.d.ts +0 -35
  490. package/dist/lib/validation/security-checks.js +0 -106
  491. package/dist/lib/validation/security-checks.js.map +0 -1
  492. package/dist/lib/validation/types.d.ts +0 -56
  493. package/dist/lib/validation/types.js +0 -2
  494. package/dist/lib/validation/types.js.map +0 -1
  495. package/dist/lib/validation/validator.d.ts +0 -13
  496. package/dist/lib/validation/validator.js +0 -711
  497. package/dist/lib/validation/validator.js.map +0 -1
  498. package/dist/lib/version-check.d.ts +0 -6
  499. package/dist/lib/version-check.js +0 -46
  500. package/dist/lib/version-check.js.map +0 -1
  501. package/dist/lib/workos-api.d.ts +0 -30
  502. package/dist/lib/workos-api.js +0 -69
  503. package/dist/lib/workos-api.js.map +0 -1
  504. package/dist/lib/workos-client.d.ts +0 -58
  505. package/dist/lib/workos-client.js +0 -140
  506. package/dist/lib/workos-client.js.map +0 -1
  507. package/dist/lib/workos-management.d.ts +0 -32
  508. package/dist/lib/workos-management.js +0 -149
  509. package/dist/lib/workos-management.js.map +0 -1
  510. package/dist/nextjs/nextjs-installer-agent.d.ts +0 -5
  511. package/dist/nextjs/nextjs-installer-agent.js +0 -6
  512. package/dist/nextjs/nextjs-installer-agent.js.map +0 -1
  513. package/dist/nextjs/utils.d.ts +0 -4
  514. package/dist/nextjs/utils.js +0 -5
  515. package/dist/nextjs/utils.js.map +0 -1
  516. package/dist/react/react-installer-agent.d.ts +0 -4
  517. package/dist/react/react-installer-agent.js +0 -5
  518. package/dist/react/react-installer-agent.js.map +0 -1
  519. package/dist/react-router/react-router-installer-agent.d.ts +0 -4
  520. package/dist/react-router/react-router-installer-agent.js +0 -5
  521. package/dist/react-router/react-router-installer-agent.js.map +0 -1
  522. package/dist/react-router/utils.d.ts +0 -4
  523. package/dist/react-router/utils.js +0 -5
  524. package/dist/react-router/utils.js.map +0 -1
  525. package/dist/run.d.ts +0 -33
  526. package/dist/run.js +0 -58
  527. package/dist/run.js.map +0 -1
  528. package/dist/smoke-test.ts +0 -881
  529. package/dist/steps/add-or-update-environment-variables.d.ts +0 -10
  530. package/dist/steps/add-or-update-environment-variables.js +0 -155
  531. package/dist/steps/add-or-update-environment-variables.js.map +0 -1
  532. package/dist/steps/index.d.ts +0 -3
  533. package/dist/steps/index.js +0 -4
  534. package/dist/steps/index.js.map +0 -1
  535. package/dist/steps/run-prettier.d.ts +0 -5
  536. package/dist/steps/run-prettier.js +0 -50
  537. package/dist/steps/run-prettier.js.map +0 -1
  538. package/dist/steps/upload-environment-variables/EnvironmentProvider.d.ts +0 -8
  539. package/dist/steps/upload-environment-variables/EnvironmentProvider.js +0 -7
  540. package/dist/steps/upload-environment-variables/EnvironmentProvider.js.map +0 -1
  541. package/dist/steps/upload-environment-variables/index.d.ts +0 -6
  542. package/dist/steps/upload-environment-variables/index.js +0 -69
  543. package/dist/steps/upload-environment-variables/index.js.map +0 -1
  544. package/dist/steps/upload-environment-variables/providers/vercel.d.ts +0 -14
  545. package/dist/steps/upload-environment-variables/providers/vercel.js +0 -107
  546. package/dist/steps/upload-environment-variables/providers/vercel.js.map +0 -1
  547. package/dist/tanstack-start/tanstack-start-installer-agent.d.ts +0 -4
  548. package/dist/tanstack-start/tanstack-start-installer-agent.js +0 -5
  549. package/dist/tanstack-start/tanstack-start-installer-agent.js.map +0 -1
  550. package/dist/telemetry.d.ts +0 -2
  551. package/dist/telemetry.js +0 -29
  552. package/dist/telemetry.js.map +0 -1
  553. package/dist/test/force-insecure-storage.d.ts +0 -1
  554. package/dist/test/force-insecure-storage.js +0 -9
  555. package/dist/test/force-insecure-storage.js.map +0 -1
  556. package/dist/test/setup.d.ts +0 -1
  557. package/dist/test/setup.js +0 -38
  558. package/dist/test/setup.js.map +0 -1
  559. package/dist/utils/analytics.d.ts +0 -66
  560. package/dist/utils/analytics.js +0 -330
  561. package/dist/utils/analytics.js.map +0 -1
  562. package/dist/utils/bash.d.ts +0 -2
  563. package/dist/utils/bash.js +0 -17
  564. package/dist/utils/bash.js.map +0 -1
  565. package/dist/utils/box.d.ts +0 -9
  566. package/dist/utils/box.js +0 -15
  567. package/dist/utils/box.js.map +0 -1
  568. package/dist/utils/cli-exit.d.ts +0 -15
  569. package/dist/utils/cli-exit.js +0 -11
  570. package/dist/utils/cli-exit.js.map +0 -1
  571. package/dist/utils/cli-symbols.d.ts +0 -44
  572. package/dist/utils/cli-symbols.js +0 -58
  573. package/dist/utils/cli-symbols.js.map +0 -1
  574. package/dist/utils/command-invocation.d.ts +0 -10
  575. package/dist/utils/command-invocation.js +0 -26
  576. package/dist/utils/command-invocation.js.map +0 -1
  577. package/dist/utils/command-telemetry.d.ts +0 -17
  578. package/dist/utils/command-telemetry.js +0 -67
  579. package/dist/utils/command-telemetry.js.map +0 -1
  580. package/dist/utils/crash-reporter.d.ts +0 -13
  581. package/dist/utils/crash-reporter.js +0 -91
  582. package/dist/utils/crash-reporter.js.map +0 -1
  583. package/dist/utils/debug.d.ts +0 -9
  584. package/dist/utils/debug.js +0 -105
  585. package/dist/utils/debug.js.map +0 -1
  586. package/dist/utils/env-parser.d.ts +0 -5
  587. package/dist/utils/env-parser.js +0 -18
  588. package/dist/utils/env-parser.js.map +0 -1
  589. package/dist/utils/environment.d.ts +0 -10
  590. package/dist/utils/environment.js +0 -69
  591. package/dist/utils/environment.js.map +0 -1
  592. package/dist/utils/errors.d.ts +0 -3
  593. package/dist/utils/errors.js +0 -7
  594. package/dist/utils/errors.js.map +0 -1
  595. package/dist/utils/exec-file.d.ts +0 -15
  596. package/dist/utils/exec-file.js +0 -39
  597. package/dist/utils/exec-file.js.map +0 -1
  598. package/dist/utils/exit-codes.d.ts +0 -31
  599. package/dist/utils/exit-codes.js +0 -69
  600. package/dist/utils/exit-codes.js.map +0 -1
  601. package/dist/utils/git-utils.d.ts +0 -23
  602. package/dist/utils/git-utils.js +0 -86
  603. package/dist/utils/git-utils.js.map +0 -1
  604. package/dist/utils/help-json.d.ts +0 -58
  605. package/dist/utils/help-json.js +0 -1577
  606. package/dist/utils/help-json.js.map +0 -1
  607. package/dist/utils/interaction-mode.d.ts +0 -25
  608. package/dist/utils/interaction-mode.js +0 -99
  609. package/dist/utils/interaction-mode.js.map +0 -1
  610. package/dist/utils/lock-art.d.ts +0 -4
  611. package/dist/utils/lock-art.js +0 -73
  612. package/dist/utils/lock-art.js.map +0 -1
  613. package/dist/utils/logging.d.ts +0 -9
  614. package/dist/utils/logging.js +0 -36
  615. package/dist/utils/logging.js.map +0 -1
  616. package/dist/utils/ndjson.d.ts +0 -16
  617. package/dist/utils/ndjson.js +0 -18
  618. package/dist/utils/ndjson.js.map +0 -1
  619. package/dist/utils/output.d.ts +0 -60
  620. package/dist/utils/output.js +0 -124
  621. package/dist/utils/output.js.map +0 -1
  622. package/dist/utils/package-json.d.ts +0 -26
  623. package/dist/utils/package-json.js +0 -32
  624. package/dist/utils/package-json.js.map +0 -1
  625. package/dist/utils/package-manager.d.ts +0 -21
  626. package/dist/utils/package-manager.js +0 -166
  627. package/dist/utils/package-manager.js.map +0 -1
  628. package/dist/utils/paths.d.ts +0 -5
  629. package/dist/utils/paths.js +0 -18
  630. package/dist/utils/paths.js.map +0 -1
  631. package/dist/utils/platform.d.ts +0 -8
  632. package/dist/utils/platform.js +0 -7
  633. package/dist/utils/platform.js.map +0 -1
  634. package/dist/utils/recovery-hints.d.ts +0 -42
  635. package/dist/utils/recovery-hints.js +0 -92
  636. package/dist/utils/recovery-hints.js.map +0 -1
  637. package/dist/utils/redact.d.ts +0 -5
  638. package/dist/utils/redact.js +0 -29
  639. package/dist/utils/redact.js.map +0 -1
  640. package/dist/utils/register-subcommand.d.ts +0 -10
  641. package/dist/utils/register-subcommand.js +0 -33
  642. package/dist/utils/register-subcommand.js.map +0 -1
  643. package/dist/utils/semver.d.ts +0 -10
  644. package/dist/utils/semver.js +0 -43
  645. package/dist/utils/semver.js.map +0 -1
  646. package/dist/utils/string.d.ts +0 -1
  647. package/dist/utils/string.js +0 -6
  648. package/dist/utils/string.js.map +0 -1
  649. package/dist/utils/summary-box.d.ts +0 -25
  650. package/dist/utils/summary-box.js +0 -211
  651. package/dist/utils/summary-box.js.map +0 -1
  652. package/dist/utils/table.d.ts +0 -5
  653. package/dist/utils/table.js +0 -18
  654. package/dist/utils/table.js.map +0 -1
  655. package/dist/utils/telemetry-client.d.ts +0 -43
  656. package/dist/utils/telemetry-client.js +0 -171
  657. package/dist/utils/telemetry-client.js.map +0 -1
  658. package/dist/utils/telemetry-store-forward.d.ts +0 -11
  659. package/dist/utils/telemetry-store-forward.js +0 -94
  660. package/dist/utils/telemetry-store-forward.js.map +0 -1
  661. package/dist/utils/telemetry-types.d.ts +0 -100
  662. package/dist/utils/telemetry-types.js +0 -6
  663. package/dist/utils/telemetry-types.js.map +0 -1
  664. package/dist/utils/types.d.ts +0 -123
  665. package/dist/utils/types.js +0 -2
  666. package/dist/utils/types.js.map +0 -1
  667. package/dist/utils/ui-utils.d.ts +0 -97
  668. package/dist/utils/ui-utils.js +0 -449
  669. package/dist/utils/ui-utils.js.map +0 -1
  670. package/dist/utils/ui.d.ts +0 -148
  671. package/dist/utils/ui.js +0 -368
  672. package/dist/utils/ui.js.map +0 -1
  673. package/dist/utils/urls.d.ts +0 -13
  674. package/dist/utils/urls.js +0 -14
  675. package/dist/utils/urls.js.map +0 -1
  676. package/dist/utils/vendor/is-unicorn-supported.d.ts +0 -1
  677. package/dist/utils/vendor/is-unicorn-supported.js +0 -21
  678. package/dist/utils/vendor/is-unicorn-supported.js.map +0 -1
  679. package/dist/vanilla-js/vanilla-js-installer-agent.d.ts +0 -4
  680. package/dist/vanilla-js/vanilla-js-installer-agent.js +0 -5
  681. package/dist/vanilla-js/vanilla-js-installer-agent.js.map +0 -1
@@ -1,840 +0,0 @@
1
- /**
2
- * Shared agent interface for WorkOS wizards
3
- * Uses Claude Agent SDK directly with WorkOS MCP server
4
- */
5
- import { dirname } from 'path';
6
- import { getSkillsDir as getSkillsPackageDir } from '@workos/skills';
7
- import { debug, logInfo, logWarn, logError, initLogFile, getLogFilePath } from '../utils/debug.js';
8
- import { analytics } from '../utils/analytics.js';
9
- import { INSTALLER_INTERACTION_EVENT_NAME } from './constants.js';
10
- import { LINTING_TOOLS } from './safe-tools.js';
11
- import { formatWorkOSCommand } from '../utils/command-invocation.js';
12
- import { getConfig } from './settings.js';
13
- import { getLlmGatewayUrl } from '../utils/urls.js';
14
- import { getCredentials, hasCredentials } from './credentials.js';
15
- import { ensureValidToken } from './token-refresh.js';
16
- import { startCredentialProxy, startClaimTokenProxy } from './credential-proxy.js';
17
- import { getActiveEnvironment, isUnclaimedEnvironment } from './config-store.js';
18
- import { getAuthkitDomain, getCliAuthClientId } from './settings.js';
19
- // File content cache for computing edit diffs
20
- const fileContentCache = new Map();
21
- // Track pending Read operations by tool_use_id
22
- const pendingReads = new Map();
23
- // Track tool start times by tool_use_id for telemetry
24
- const pendingToolCalls = new Map();
25
- // Module-level variable to track proxy handle for cleanup
26
- let activeProxyHandle = null;
27
- // Dynamic import cache for ESM module
28
- let _sdkModule = null;
29
- async function getSDKModule() {
30
- if (!_sdkModule) {
31
- _sdkModule = await import('@anthropic-ai/claude-agent-sdk');
32
- }
33
- return _sdkModule;
34
- }
35
- export const AgentSignals = {
36
- /** Signal emitted when the agent reports progress to the user */
37
- STATUS: '[STATUS]',
38
- /** Signal emitted when the agent cannot access the WorkOS MCP server */
39
- ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',
40
- /** Signal emitted when the agent cannot access the setup resource */
41
- ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',
42
- };
43
- /** Internal prefix used to tag service-unavailability errors from handleSDKMessage */
44
- const SERVICE_UNAVAILABLE_PREFIX = '__SERVICE_UNAVAILABLE__';
45
- /** Internal prefix used to tag rate-limit errors from handleSDKMessage */
46
- const RATE_LIMITED_PREFIX = '__RATE_LIMITED__';
47
- /**
48
- * Error types that can be returned from agent execution.
49
- * These correspond to the error signals that the agent emits.
50
- */
51
- export var AgentErrorType;
52
- (function (AgentErrorType) {
53
- /** Agent could not access the WorkOS MCP server */
54
- AgentErrorType["MCP_MISSING"] = "INSTALLER_MCP_MISSING";
55
- /** Agent could not access the setup resource */
56
- AgentErrorType["RESOURCE_MISSING"] = "INSTALLER_RESOURCE_MISSING";
57
- /** Agent execution failed (API error, auth error, etc.) */
58
- AgentErrorType["EXECUTION_ERROR"] = "INSTALLER_EXECUTION_ERROR";
59
- /** AI service is unavailable (API 500, outage, etc.) */
60
- AgentErrorType["SERVICE_UNAVAILABLE"] = "INSTALLER_SERVICE_UNAVAILABLE";
61
- })(AgentErrorType || (AgentErrorType = {}));
62
- /**
63
- * Package managers that can be used to run commands.
64
- * Includes JS and non-JS ecosystem package managers for multi-SDK support.
65
- */
66
- const PACKAGE_MANAGERS = [
67
- // JavaScript
68
- 'npm',
69
- 'pnpm',
70
- 'yarn',
71
- 'bun',
72
- 'npx',
73
- 'pnpx',
74
- 'bunx',
75
- // Python
76
- 'pip',
77
- 'pip3',
78
- 'poetry',
79
- 'uv',
80
- 'pipx',
81
- 'python',
82
- 'python3',
83
- // Ruby
84
- 'gem',
85
- 'bundle',
86
- 'bundler',
87
- 'ruby',
88
- // PHP
89
- 'composer',
90
- 'php',
91
- // Go
92
- 'go',
93
- // .NET
94
- 'dotnet',
95
- 'nuget',
96
- // Elixir
97
- 'mix',
98
- 'hex',
99
- 'elixir',
100
- // Kotlin/Java
101
- 'gradle',
102
- 'gradlew',
103
- './gradlew',
104
- 'mvn',
105
- ];
106
- /**
107
- * Safe scripts/commands that can be run with any package manager.
108
- * Uses startsWith matching, so 'build' matches 'build', 'build:prod', etc.
109
- * Note: Linting tools are in LINTING_TOOLS and checked separately.
110
- */
111
- const SAFE_SCRIPTS = [
112
- // Package installation
113
- 'install',
114
- 'add',
115
- 'ci',
116
- // Build
117
- 'build',
118
- // Type checking (various naming conventions)
119
- 'tsc',
120
- 'typecheck',
121
- 'type-check',
122
- 'check-types',
123
- 'types',
124
- // Linting/formatting script names (actual tools are in LINTING_TOOLS)
125
- 'lint',
126
- 'format',
127
- // Common cross-language commands
128
- 'check',
129
- 'test',
130
- 'run',
131
- 'serve',
132
- 'dev',
133
- 'start',
134
- 'compile',
135
- 'vet',
136
- // Python-specific
137
- 'manage.py',
138
- 'pytest',
139
- // Ruby-specific
140
- 'rspec',
141
- 'rake',
142
- 'routes',
143
- // PHP-specific
144
- 'artisan',
145
- 'phpunit',
146
- // Elixir-specific
147
- 'deps.get',
148
- 'credo',
149
- 'dialyzer',
150
- // .NET-specific
151
- 'restore',
152
- ];
153
- /**
154
- * Dangerous shell operators that could allow command injection.
155
- * Note: We handle `2>&1` and `| tail/head` separately as safe patterns.
156
- */
157
- const DANGEROUS_OPERATORS = /[;`$()]/;
158
- /**
159
- * Check if command is an allowed package manager command.
160
- * Matches: <pkg-manager> [run|exec] <safe-script> [args...]
161
- */
162
- function matchesAllowedPrefix(command) {
163
- const parts = command.split(/\s+/);
164
- if (parts.length === 0 || !PACKAGE_MANAGERS.includes(parts[0])) {
165
- return false;
166
- }
167
- // Skip 'run' or 'exec' if present
168
- let scriptIndex = 1;
169
- if (parts[scriptIndex] === 'run' || parts[scriptIndex] === 'exec') {
170
- scriptIndex++;
171
- }
172
- // Get the script/command portion (may include args)
173
- const scriptPart = parts.slice(scriptIndex).join(' ');
174
- // Check if script starts with any safe script name or linting tool
175
- return (SAFE_SCRIPTS.some((safe) => scriptPart.startsWith(safe)) ||
176
- LINTING_TOOLS.some((tool) => scriptPart.startsWith(tool)));
177
- }
178
- /**
179
- * Permission hook that allows only safe commands.
180
- * - Package manager install commands
181
- * - Build/typecheck/lint commands for verification
182
- * - Piping to tail/head for output limiting is allowed
183
- * - Stderr redirection (2>&1) is allowed
184
- */
185
- export function installerCanUseTool(toolName, input) {
186
- // Allow all non-Bash tools
187
- if (toolName !== 'Bash') {
188
- return { behavior: 'allow', updatedInput: input };
189
- }
190
- const command = (typeof input.command === 'string' ? input.command : '').trim();
191
- // Block definitely dangerous operators: ; ` $ ( )
192
- if (DANGEROUS_OPERATORS.test(command)) {
193
- logWarn(`Denying bash command with dangerous operators: ${command}`);
194
- debug(`Denying bash command with dangerous operators: ${command}`);
195
- analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
196
- action: 'bash command denied',
197
- reason: 'dangerous operators',
198
- command,
199
- });
200
- return {
201
- behavior: 'deny',
202
- message: `Bash command not allowed. Shell operators like ; \` $ ( ) are not permitted.`,
203
- };
204
- }
205
- // Normalize: remove safe stderr redirection (2>&1, 2>&2, etc.)
206
- const normalized = command.replace(/\s*\d*>&\d+\s*/g, ' ').trim();
207
- // Check for pipe to tail/head (safe output limiting)
208
- const pipeMatch = normalized.match(/^(.+?)\s*\|\s*(tail|head)(\s+\S+)*\s*$/);
209
- if (pipeMatch) {
210
- const baseCommand = pipeMatch[1].trim();
211
- // Block if base command has pipes or & (multiple chaining)
212
- if (/[|&]/.test(baseCommand)) {
213
- logWarn(`Denying bash command with multiple pipes: ${command}`);
214
- debug(`Denying bash command with multiple pipes: ${command}`);
215
- analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
216
- action: 'bash command denied',
217
- reason: 'multiple pipes',
218
- command,
219
- });
220
- return {
221
- behavior: 'deny',
222
- message: `Bash command not allowed. Only single pipe to tail/head is permitted.`,
223
- };
224
- }
225
- if (matchesAllowedPrefix(baseCommand)) {
226
- logInfo(`Allowing bash command with output limiter: ${command}`);
227
- debug(`Allowing bash command with output limiter: ${command}`);
228
- return { behavior: 'allow', updatedInput: input };
229
- }
230
- }
231
- // Block remaining pipes and & (not covered by tail/head case above)
232
- if (/[|&]/.test(normalized)) {
233
- logWarn(`Denying bash command with pipe/&: ${command}`);
234
- debug(`Denying bash command with pipe/&: ${command}`);
235
- analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
236
- action: 'bash command denied',
237
- reason: 'disallowed pipe',
238
- command,
239
- });
240
- return {
241
- behavior: 'deny',
242
- message: `Bash command not allowed. Pipes are only permitted with tail/head for output limiting.`,
243
- };
244
- }
245
- // Check if command starts with any allowed prefix
246
- if (matchesAllowedPrefix(normalized)) {
247
- logInfo(`Allowing bash command: ${command}`);
248
- debug(`Allowing bash command: ${command}`);
249
- return { behavior: 'allow', updatedInput: input };
250
- }
251
- logWarn(`Denying bash command: ${command}`);
252
- debug(`Denying bash command: ${command}`);
253
- analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
254
- action: 'bash command denied',
255
- reason: 'not in allowlist',
256
- command,
257
- });
258
- return {
259
- behavior: 'deny',
260
- message: `Bash command not allowed. Only install, build, typecheck, lint, and formatting commands are permitted.`,
261
- };
262
- }
263
- /**
264
- * Initialize agent configuration for the LLM gateway
265
- */
266
- export async function initializeAgent(config, options) {
267
- // Initialize log file for this run
268
- initLogFile();
269
- logInfo('Agent initialization starting');
270
- logInfo('Install directory:', options.installDir);
271
- // Emit status event for adapters to render
272
- options.emitter?.emit('status', { message: 'Initializing Claude agent...' });
273
- try {
274
- let authMode;
275
- // Build SDK env without mutating process.env
276
- const sdkEnv = {
277
- ...process.env,
278
- // Disable experimental betas (like input_examples) that the LLM gateway doesn't support
279
- CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: 'true',
280
- // Disable SDK telemetry - our gateway doesn't proxy /api/event_logging/batch
281
- CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 'true',
282
- };
283
- // Placeholder bearer token for the Claude Agent SDK. The SDK's CLI
284
- // subprocess runs a local auth-source check at startup and exits with
285
- // "Not logged in · Please run /login" if no credentials are present in
286
- // its environment — even when a proxy is handling auth upstream. Setting
287
- // this token puts the SDK in custom-backend mode so it skips that check;
288
- // the credential proxy rewrites the Authorization header with the real
289
- // WorkOS token before forwarding upstream.
290
- const PROXY_PLACEHOLDER_TOKEN = 'workos-cli-proxy-placeholder';
291
- if (options.direct) {
292
- // Direct mode: use user's Anthropic API key, skip gateway
293
- if (!process.env.ANTHROPIC_API_KEY) {
294
- throw new Error('Direct mode requires ANTHROPIC_API_KEY environment variable.\n' +
295
- 'Set it with: export ANTHROPIC_API_KEY=sk-ant-...\n' +
296
- 'Get your key at: https://console.anthropic.com/settings/keys');
297
- }
298
- // SDK defaults to api.anthropic.com when no base URL set
299
- delete sdkEnv.ANTHROPIC_BASE_URL;
300
- delete sdkEnv.ANTHROPIC_AUTH_TOKEN;
301
- authMode = 'direct:api.anthropic.com';
302
- logInfo('Direct mode: using ANTHROPIC_API_KEY, bypassing llm-gateway');
303
- // Set analytics tag for direct mode
304
- analytics.setTag('api_mode', 'direct');
305
- }
306
- else {
307
- // Gateway mode (existing behavior)
308
- const gatewayUrl = getLlmGatewayUrl();
309
- // Check for unclaimed environment — use claim token auth
310
- const activeEnv = getActiveEnvironment();
311
- if (activeEnv && isUnclaimedEnvironment(activeEnv)) {
312
- activeProxyHandle = await startClaimTokenProxy({
313
- upstreamUrl: gatewayUrl,
314
- claimToken: activeEnv.claimToken,
315
- clientId: activeEnv.clientId,
316
- });
317
- sdkEnv.ANTHROPIC_BASE_URL = activeProxyHandle.url;
318
- // Prevent the user's personal Anthropic key (if any) from being sent
319
- // to the WorkOS gateway; auth is injected by the claim-token proxy.
320
- delete sdkEnv.ANTHROPIC_API_KEY;
321
- sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
322
- authMode = `claim-token-proxy:${activeProxyHandle.url}→${gatewayUrl}`;
323
- logInfo(`[agent-interface] Using claim token proxy for unclaimed environment`);
324
- }
325
- else if (!options.skipAuth && !options.local) {
326
- // Check/refresh authentication for production (unless skipping auth)
327
- if (!hasCredentials()) {
328
- throw new Error(`Not authenticated. Run \`${formatWorkOSCommand('auth login')}\` to authenticate.`);
329
- }
330
- const creds = getCredentials();
331
- if (!creds) {
332
- throw new Error(`Not authenticated. Run \`${formatWorkOSCommand('auth login')}\` to authenticate.`);
333
- }
334
- // Check if we have refresh token capability and proxy is not disabled
335
- if (creds.refreshToken && process.env.WORKOS_DISABLE_PROXY !== '1') {
336
- // Start credential proxy with lazy refresh
337
- logInfo('[agent-interface] Starting credential proxy with lazy refresh...');
338
- const appConfig = getConfig();
339
- activeProxyHandle = await startCredentialProxy({
340
- upstreamUrl: gatewayUrl,
341
- refresh: {
342
- authkitDomain: getAuthkitDomain(),
343
- clientId: getCliAuthClientId(),
344
- refreshThresholdMs: appConfig.proxy.refreshThresholdMs,
345
- onRefreshSuccess: () => {
346
- options.emitter?.emit('status', { message: 'Session extended' });
347
- },
348
- onRefreshExpired: () => {
349
- logError('[agent-interface] Session expired, refresh token invalid');
350
- options.emitter?.emit('error', {
351
- message: `Session expired. Run \`${formatWorkOSCommand('auth login')}\` to re-authenticate.`,
352
- });
353
- },
354
- },
355
- });
356
- // Point SDK at proxy instead of direct gateway
357
- sdkEnv.ANTHROPIC_BASE_URL = activeProxyHandle.url;
358
- logInfo(`[agent-interface] Using credential proxy at ${activeProxyHandle.url}`);
359
- // Prevent the user's personal Anthropic key (if any) from being
360
- // sent to the WorkOS gateway; the credential proxy rewrites the
361
- // Authorization header with the real WorkOS token.
362
- delete sdkEnv.ANTHROPIC_API_KEY;
363
- sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
364
- authMode = `proxy:${activeProxyHandle.url}→${gatewayUrl}`;
365
- }
366
- else {
367
- // No refresh token OR proxy disabled - fall back to old behavior (5 min limit)
368
- if (!creds.refreshToken) {
369
- logWarn('[agent-interface] No refresh token available, session limited to 5 minutes');
370
- logWarn(`[agent-interface] Run \`${formatWorkOSCommand('auth login')}\` to enable extended sessions`);
371
- options.emitter?.emit('status', {
372
- message: `Note: Run \`${formatWorkOSCommand('auth login')}\` to enable extended sessions`,
373
- });
374
- }
375
- else {
376
- logWarn('[agent-interface] Proxy disabled via WORKOS_DISABLE_PROXY');
377
- }
378
- const refreshResult = await ensureValidToken();
379
- if (!refreshResult.success) {
380
- throw new Error(refreshResult.error || 'Authentication failed');
381
- }
382
- sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
383
- // Prevent the user's personal Anthropic key (if any) from being
384
- // forwarded to the WorkOS gateway as an x-api-key header alongside
385
- // the WorkOS access token we set below.
386
- delete sdkEnv.ANTHROPIC_API_KEY;
387
- sdkEnv.ANTHROPIC_AUTH_TOKEN = creds.accessToken;
388
- authMode = options.local ? `local-gateway:${gatewayUrl}` : `workos-gateway:${gatewayUrl}`;
389
- logInfo('Sending access token to gateway (legacy mode)');
390
- }
391
- }
392
- else if (options.skipAuth) {
393
- // Skip auth mode - direct to gateway without a real token. The SDK's
394
- // local auth-source check would otherwise fail with "Not logged in",
395
- // so seed a placeholder bearer; the gateway is expected to accept
396
- // unauthenticated requests here and ignore the placeholder value.
397
- sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
398
- delete sdkEnv.ANTHROPIC_API_KEY;
399
- sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
400
- authMode = `skip-auth:${gatewayUrl}`;
401
- logInfo('Skipping auth - placeholder bearer sent to gateway');
402
- }
403
- else {
404
- // Local mode without auth - same rationale as skip-auth above.
405
- sdkEnv.ANTHROPIC_BASE_URL = gatewayUrl;
406
- delete sdkEnv.ANTHROPIC_API_KEY;
407
- sdkEnv.ANTHROPIC_AUTH_TOKEN = PROXY_PLACEHOLDER_TOKEN;
408
- authMode = `local-gateway:${gatewayUrl}`;
409
- logInfo('Local mode - placeholder bearer sent to gateway');
410
- }
411
- logInfo('Configured LLM gateway:', sdkEnv.ANTHROPIC_BASE_URL);
412
- // Set analytics tag for gateway mode
413
- analytics.setTag('api_mode', activeProxyHandle ? 'gateway-proxy' : 'gateway');
414
- }
415
- // Configure WorkOS MCP docs server for accessing WorkOS documentation
416
- const agentRunConfig = {
417
- workingDirectory: config.workingDirectory,
418
- mcpServers: {
419
- workos: {
420
- command: 'npx',
421
- args: ['-y', '@workos/mcp-docs-server'],
422
- },
423
- },
424
- model: getConfig().model,
425
- // Empty on purpose. A tool listed here is auto-approved BEFORE `canUseTool`
426
- // (installerCanUseTool) runs, which both defeats the Bash safety gate and
427
- // triggers the SDK's CLAUDE_SDK_CAN_USE_TOOL_SHADOWED warning. Leaving this
428
- // empty routes every tool call through canUseTool so the gate is
429
- // authoritative. Tool *availability* comes from the `tools` preset below,
430
- // not from this list.
431
- allowedTools: [],
432
- sdkEnv,
433
- };
434
- const configInfo = { workingDirectory: agentRunConfig.workingDirectory, authMode, useMcp: false };
435
- logInfo('Agent config:', configInfo);
436
- debug('Agent config:', configInfo);
437
- // Emit status events for adapters to render
438
- const currentLogPath = getLogFilePath();
439
- if (currentLogPath) {
440
- options.emitter?.emit('status', { message: `Verbose logs: ${currentLogPath}` });
441
- }
442
- options.emitter?.emit('status', { message: "Agent initialized. Let's get cooking!" });
443
- return agentRunConfig;
444
- }
445
- catch (error) {
446
- // Clean up proxy if initialization fails
447
- if (activeProxyHandle) {
448
- logInfo('[agent-interface] Cleaning up proxy after init error');
449
- await activeProxyHandle.stop();
450
- activeProxyHandle = null;
451
- }
452
- logError('Agent initialization error:', error);
453
- throw error;
454
- }
455
- }
456
- /**
457
- * Execute an agent with the provided prompt and options
458
- * Handles the full lifecycle via event emissions - adapters handle UI rendering.
459
- *
460
- * @returns An object containing any error detected in the agent's output
461
- */
462
- export async function runAgent(agentConfig, prompt, options, config, emitter, retryConfig, onMessage) {
463
- const { spinnerMessage = 'Setting up WorkOS AuthKit...' } = config ?? {};
464
- const { query } = await getSDKModule();
465
- // Emit progress for adapters to handle (e.g., CLI adapter starts spinner)
466
- emitter?.emit('agent:progress', { step: 'Starting', detail: 'This may take a few minutes. Grab some coffee!' });
467
- emitter?.emit('agent:progress', { step: spinnerMessage });
468
- logInfo('Starting agent run');
469
- logInfo('Prompt:', prompt);
470
- const startTime = Date.now();
471
- const collectedText = [];
472
- try {
473
- let retryCount = 0;
474
- const maxRetries = retryConfig?.maxRetries ?? 0;
475
- // Turn completion signals — resolveCurrentTurn is called when a 'result'
476
- // message arrives; the prompt generator awaits currentTurnDone between turns.
477
- let resolveCurrentTurn;
478
- let currentTurnDone;
479
- // Set by the message loop when a fatal SDK error is detected (e.g. service
480
- // unavailability). The prompt stream checks this before yielding retry
481
- // prompts so we fail fast instead of burning minutes on hopeless retries.
482
- let abortRetries = false;
483
- function resetTurnSignal() {
484
- currentTurnDone = new Promise((resolve) => {
485
- resolveCurrentTurn = resolve;
486
- });
487
- }
488
- resetTurnSignal();
489
- const createPromptStream = async function* () {
490
- yield {
491
- type: 'user',
492
- session_id: '',
493
- message: { role: 'user', content: prompt },
494
- parent_tool_use_id: null,
495
- };
496
- if (retryConfig && maxRetries > 0) {
497
- while (retryCount < maxRetries) {
498
- await currentTurnDone;
499
- // Don't send correction prompts when the service itself is down
500
- if (abortRetries) {
501
- logInfo('Skipping validation retries due to service error');
502
- break;
503
- }
504
- emitter?.emit('validation:retry:start', { attempt: retryCount + 1 });
505
- let validationPrompt;
506
- try {
507
- validationPrompt = await retryConfig.validateAndFormat(agentConfig.workingDirectory);
508
- }
509
- catch (err) {
510
- // Don't block on validation bugs — treat as passed
511
- logError('validateAndFormat threw:', err);
512
- validationPrompt = null;
513
- }
514
- emitter?.emit('validation:retry:complete', {
515
- attempt: retryCount + 1,
516
- passed: validationPrompt === null,
517
- });
518
- if (validationPrompt === null)
519
- break;
520
- retryCount++;
521
- emitter?.emit('agent:retry', { attempt: retryCount, maxRetries });
522
- resetTurnSignal();
523
- yield {
524
- type: 'user',
525
- session_id: '',
526
- message: { role: 'user', content: validationPrompt },
527
- parent_tool_use_id: null,
528
- };
529
- }
530
- }
531
- await currentTurnDone;
532
- };
533
- // Load plugin from @workos/skills package
534
- const pluginPath = dirname(getSkillsPackageDir());
535
- logInfo('Loading plugin from:', pluginPath);
536
- const response = query({
537
- prompt: createPromptStream(),
538
- options: {
539
- model: agentConfig.model,
540
- cwd: agentConfig.workingDirectory,
541
- permissionMode: 'acceptEdits',
542
- mcpServers: agentConfig.mcpServers,
543
- env: agentConfig.sdkEnv,
544
- canUseTool: (toolName, input) => {
545
- logInfo('canUseTool called:', { toolName, input });
546
- const result = installerCanUseTool(toolName, input);
547
- logInfo('canUseTool result:', result);
548
- return Promise.resolve(result);
549
- },
550
- tools: { type: 'preset', preset: 'claude_code' },
551
- allowedTools: agentConfig.allowedTools,
552
- plugins: [{ type: 'local', path: pluginPath }],
553
- // Capture stderr from CLI subprocess for debugging
554
- stderr: (data) => {
555
- logInfo('CLI stderr:', data);
556
- if (options.debug) {
557
- debug('CLI stderr:', data);
558
- }
559
- },
560
- },
561
- });
562
- // Process the async generator
563
- let sdkError;
564
- for await (const message of response) {
565
- const messageError = handleSDKMessage(message, options, collectedText, emitter);
566
- if (messageError) {
567
- sdkError = messageError;
568
- // Signal the prompt stream to stop yielding retry prompts
569
- abortRetries = true;
570
- }
571
- if (message.type === 'result') {
572
- resolveCurrentTurn();
573
- }
574
- try {
575
- onMessage?.(message);
576
- }
577
- catch {
578
- /* non-critical */
579
- }
580
- }
581
- const durationMs = Date.now() - startTime;
582
- const outputText = collectedText.join('\n');
583
- // Check for SDK errors first (e.g., API errors, auth failures)
584
- // Return error type + message - caller decides whether to throw or emit events
585
- if (sdkError) {
586
- if (sdkError.startsWith(SERVICE_UNAVAILABLE_PREFIX)) {
587
- const detail = sdkError.slice(SERVICE_UNAVAILABLE_PREFIX.length);
588
- logError('AI service unavailable:', detail);
589
- return {
590
- error: AgentErrorType.SERVICE_UNAVAILABLE,
591
- errorMessage: 'The AI service is temporarily unavailable. Please try again in a few minutes.',
592
- };
593
- }
594
- if (sdkError.startsWith(RATE_LIMITED_PREFIX)) {
595
- const detail = sdkError.slice(RATE_LIMITED_PREFIX.length);
596
- logError('AI service rate-limited:', detail);
597
- return {
598
- error: AgentErrorType.SERVICE_UNAVAILABLE,
599
- errorMessage: 'The AI service is currently rate-limited. Please wait a minute and try again.',
600
- };
601
- }
602
- logError('Agent SDK error:', sdkError);
603
- return { error: AgentErrorType.EXECUTION_ERROR, errorMessage: sdkError };
604
- }
605
- // Check for error markers in the agent's output
606
- if (outputText.includes(AgentSignals.ERROR_MCP_MISSING)) {
607
- logError('Agent error: MCP_MISSING');
608
- return { error: AgentErrorType.MCP_MISSING, errorMessage: 'Could not access WorkOS MCP server' };
609
- }
610
- if (outputText.includes(AgentSignals.ERROR_RESOURCE_MISSING)) {
611
- logError('Agent error: RESOURCE_MISSING');
612
- return { error: AgentErrorType.RESOURCE_MISSING, errorMessage: 'Could not access setup resource' };
613
- }
614
- logInfo(`Agent run completed in ${Math.round(durationMs / 1000)}s (${retryCount} retries)`);
615
- analytics.capture(INSTALLER_INTERACTION_EVENT_NAME, {
616
- action: 'agent integration completed',
617
- duration_ms: durationMs,
618
- duration_seconds: Math.round(durationMs / 1000),
619
- retry_count: retryCount,
620
- max_retries: maxRetries,
621
- passed_after_retry: retryCount > 0,
622
- });
623
- // Don't emit agent:success here - let the state machine handle lifecycle events
624
- return { retryCount };
625
- }
626
- catch (error) {
627
- // Don't emit events here - just log and re-throw for state machine to handle
628
- logError('Agent run failed:', error);
629
- debug('Full error:', error);
630
- throw error;
631
- }
632
- finally {
633
- // Always clean up proxy when agent run completes
634
- if (activeProxyHandle) {
635
- logInfo('[agent-interface] Stopping credential proxy');
636
- analytics.capture('installer.proxy', {
637
- action: 'stop',
638
- port: activeProxyHandle.port,
639
- });
640
- await activeProxyHandle.stop();
641
- activeProxyHandle = null;
642
- }
643
- }
644
- }
645
- /**
646
- * Handle SDK messages and emit events for adapters to render.
647
- * @returns Error message if this was an error result, undefined otherwise
648
- */
649
- function handleSDKMessage(message, options, collectedText, emitter) {
650
- logInfo(`SDK Message: ${message.type}`, JSON.stringify(message, null, 2));
651
- switch (message.type) {
652
- case 'assistant': {
653
- // Extract usage data from Anthropic API response for telemetry
654
- const usage = message.message?.usage;
655
- if (usage) {
656
- const inputTokens = usage.input_tokens ?? 0;
657
- const outputTokens = usage.output_tokens ?? 0;
658
- const model = message.message?.model ?? 'unknown';
659
- analytics.llmRequest(model, inputTokens, outputTokens);
660
- analytics.incrementAgentIterations();
661
- }
662
- // Extract text content from assistant messages
663
- const content = message.message?.content;
664
- if (Array.isArray(content)) {
665
- for (const block of content) {
666
- if (block.type === 'text' && typeof block.text === 'string') {
667
- collectedText.push(block.text);
668
- // Emit output event for dashboard
669
- emitter?.emit('output', { text: block.text });
670
- // Check for [STATUS] markers and emit progress events
671
- const statusRegex = new RegExp(`^.*${AgentSignals.STATUS.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*(.+?)$`, 'm');
672
- const statusMatch = block.text.match(statusRegex);
673
- if (statusMatch) {
674
- const statusText = statusMatch[1].trim();
675
- // Emit progress event - adapters handle spinner updates
676
- emitter?.emit('agent:progress', { step: statusText });
677
- emitter?.emit('status', { message: statusText });
678
- }
679
- }
680
- // Check for tool_use blocks (Write/Edit operations)
681
- if (block.type === 'tool_use') {
682
- const toolName = block.name;
683
- const toolUseId = block.id;
684
- const input = block.input;
685
- // Log tool usage for debugging
686
- logInfo(`Tool use: ${toolName}`);
687
- // Track tool start time for telemetry
688
- if (toolUseId) {
689
- pendingToolCalls.set(toolUseId, { toolName, startTime: Date.now() });
690
- }
691
- // Emit file:write event for Write tool
692
- if (toolName === 'Write' && input) {
693
- const filePath = input.file_path;
694
- const fileContent = input.content;
695
- if (filePath && fileContent) {
696
- emitter?.emit('file:write', { path: filePath, content: fileContent });
697
- }
698
- }
699
- // Emit file:edit event for Edit tool
700
- if (toolName === 'Edit' && input) {
701
- const filePath = input.file_path;
702
- const oldString = input.old_string;
703
- const newString = input.new_string;
704
- if (filePath && oldString !== undefined && newString !== undefined) {
705
- // Emit the actual strings being replaced, not reconstructed full file
706
- emitter?.emit('file:edit', {
707
- path: filePath,
708
- oldContent: oldString,
709
- newContent: newString,
710
- });
711
- }
712
- }
713
- // Surface Bash commands (post-permission: this branch only fires for
714
- // tool calls that were actually allowed, unlike the canUseTool closure).
715
- if (toolName === 'Bash' && input) {
716
- const command = input.command;
717
- if (command) {
718
- emitter?.emit('agent:tool', { kind: 'command', detail: command });
719
- }
720
- }
721
- // Track Read operations for caching file content later
722
- if (toolName === 'Read' && input && block.id) {
723
- const filePath = input.file_path;
724
- if (filePath) {
725
- pendingReads.set(block.id, filePath);
726
- }
727
- }
728
- }
729
- }
730
- }
731
- break;
732
- }
733
- case 'user': {
734
- // User messages contain tool results
735
- const content = message.message?.content;
736
- if (Array.isArray(content)) {
737
- for (const block of content) {
738
- // Tool results contain file content from Read operations
739
- if (block.type === 'tool_result' && block.tool_use_id) {
740
- const toolUseId = block.tool_use_id;
741
- // Emit telemetry for completed tool call
742
- const pendingTool = pendingToolCalls.get(toolUseId);
743
- if (pendingTool) {
744
- const durationMs = Date.now() - pendingTool.startTime;
745
- // Check if tool result indicates error (is_error field or error in content)
746
- const isError = block.is_error === true;
747
- analytics.toolCalled(pendingTool.toolName, durationMs, !isError);
748
- pendingToolCalls.delete(toolUseId);
749
- }
750
- const filePath = pendingReads.get(toolUseId);
751
- if (filePath) {
752
- // Extract content from the tool result
753
- let resultContent = '';
754
- if (typeof block.content === 'string') {
755
- resultContent = block.content;
756
- }
757
- else if (Array.isArray(block.content)) {
758
- // Content might be array of text blocks
759
- for (const item of block.content) {
760
- if (item.type === 'text' && item.text) {
761
- resultContent += item.text;
762
- }
763
- }
764
- }
765
- if (resultContent) {
766
- fileContentCache.set(filePath, resultContent);
767
- }
768
- pendingReads.delete(toolUseId);
769
- }
770
- }
771
- }
772
- }
773
- break;
774
- }
775
- case 'result': {
776
- // The SDK may return subtype 'success' with is_error: true when API
777
- // retries are exhausted (e.g., persistent 500s). Check is_error first.
778
- const isResultError = message.is_error === true;
779
- if (isResultError) {
780
- const resultText = typeof message.result === 'string' ? message.result : '';
781
- logError('Agent result marked as error:', resultText);
782
- // Detect rate limiting (429) — check before 5xx so it gets distinct messaging
783
- if (/\b429\b/.test(resultText) || /rate.limit/i.test(resultText)) {
784
- return `${RATE_LIMITED_PREFIX}${resultText}`;
785
- }
786
- // Detect service unavailability (API 500, upstream outage)
787
- if (/\b50[0-9]\b/.test(resultText) || /server_error|internal_error|overloaded/.test(resultText)) {
788
- return `${SERVICE_UNAVAILABLE_PREFIX}${resultText}`;
789
- }
790
- return resultText || 'Agent execution failed';
791
- }
792
- if (message.subtype === 'success') {
793
- logInfo('Agent completed successfully');
794
- if (typeof message.result === 'string') {
795
- collectedText.push(message.result);
796
- }
797
- }
798
- else {
799
- // Error result
800
- logError('Agent error result:', message.subtype);
801
- if (message.errors && message.errors.length > 0) {
802
- for (const err of message.errors) {
803
- logError('ERROR:', err);
804
- // Emit error event - adapters handle rendering
805
- emitter?.emit('error', { message: err });
806
- }
807
- // Return the first error message
808
- return message.errors[0];
809
- }
810
- // Return generic error if subtype indicates failure but no errors array
811
- return `Agent execution failed: ${message.subtype}`;
812
- }
813
- break;
814
- }
815
- case 'system': {
816
- if (message.subtype === 'init') {
817
- logInfo('Agent session initialized', {
818
- model: message.model,
819
- tools: message.tools?.length,
820
- mcpServers: message.mcp_servers,
821
- });
822
- }
823
- break;
824
- }
825
- default:
826
- // Log other message types for debugging
827
- if (options.debug) {
828
- debug(`Unhandled message type: ${message.type}`);
829
- }
830
- break;
831
- }
832
- return undefined;
833
- }
834
- /**
835
- * Get the active proxy handle (for testing/debugging).
836
- */
837
- export function getActiveProxyHandle() {
838
- return activeProxyHandle;
839
- }
840
- //# sourceMappingURL=agent-interface.js.map