@zvada/agent-server 0.3.17 → 0.3.19

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 (578) hide show
  1. package/AGENTS.md +11 -26
  2. package/CHANGELOG.md +1060 -0
  3. package/README.md +50 -26
  4. package/dist/types/accounts/chatgpt.d.ts +34 -0
  5. package/dist/types/accounts/chatgpt.d.ts.map +1 -0
  6. package/dist/types/accounts/check.d.ts +24 -0
  7. package/dist/types/accounts/check.d.ts.map +1 -0
  8. package/dist/types/accounts/claude.d.ts +21 -0
  9. package/dist/types/accounts/claude.d.ts.map +1 -0
  10. package/dist/types/accounts/endpoint.d.ts +50 -0
  11. package/dist/types/accounts/endpoint.d.ts.map +1 -0
  12. package/dist/types/accounts/http.d.ts +38 -0
  13. package/dist/types/accounts/http.d.ts.map +1 -0
  14. package/dist/types/accounts/index.d.ts +6 -0
  15. package/dist/types/accounts/index.d.ts.map +1 -0
  16. package/dist/types/client/client.d.ts +272 -0
  17. package/dist/types/client/client.d.ts.map +1 -0
  18. package/dist/types/client/connection.d.ts +160 -0
  19. package/dist/types/client/connection.d.ts.map +1 -0
  20. package/dist/types/client/history.d.ts +8 -0
  21. package/dist/types/client/history.d.ts.map +1 -0
  22. package/dist/types/client/index.d.ts +5 -0
  23. package/dist/types/client/index.d.ts.map +1 -0
  24. package/dist/types/client/listeners.d.ts +8 -0
  25. package/dist/types/client/listeners.d.ts.map +1 -0
  26. package/dist/types/client/logins.d.ts +35 -0
  27. package/dist/types/client/logins.d.ts.map +1 -0
  28. package/dist/types/client/rpc.d.ts +46 -0
  29. package/dist/types/client/rpc.d.ts.map +1 -0
  30. package/dist/types/client/streams.d.ts +150 -0
  31. package/dist/types/client/streams.d.ts.map +1 -0
  32. package/dist/types/client/transports.d.ts +35 -0
  33. package/dist/types/client/transports.d.ts.map +1 -0
  34. package/dist/types/client/turns.d.ts +81 -0
  35. package/dist/types/client/turns.d.ts.map +1 -0
  36. package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
  37. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
  38. package/dist/types/core/agents/acp/adapter.d.ts +39 -0
  39. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
  40. package/dist/types/core/agents/acp/client.d.ts +90 -0
  41. package/dist/types/core/agents/acp/client.d.ts.map +1 -0
  42. package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
  43. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
  44. package/dist/types/core/agents/acp/mappings.d.ts +46 -0
  45. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
  46. package/dist/types/core/agents/acp/requests.d.ts +26 -0
  47. package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
  48. package/dist/types/core/agents/attachments.d.ts +11 -0
  49. package/dist/types/core/agents/attachments.d.ts.map +1 -0
  50. package/dist/types/core/agents/base.d.ts +227 -0
  51. package/dist/types/core/agents/base.d.ts.map +1 -0
  52. package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
  53. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
  54. package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
  55. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
  56. package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
  57. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
  58. package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
  59. package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
  60. package/dist/types/core/agents/claude-code/events.d.ts +42 -0
  61. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
  62. package/dist/types/core/agents/claude-code/login.d.ts +61 -0
  63. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
  64. package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
  65. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
  66. package/dist/types/core/agents/claude-code/models.d.ts +30 -0
  67. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
  68. package/dist/types/core/agents/claude-code/options.d.ts +183 -0
  69. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
  70. package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
  71. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
  72. package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
  73. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
  74. package/dist/types/core/agents/claude-code/session.d.ts +148 -0
  75. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
  76. package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
  77. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
  78. package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
  79. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
  80. package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
  81. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
  82. package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
  83. package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
  84. package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
  85. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
  86. package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
  87. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
  88. package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
  89. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
  90. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
  91. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
  92. package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
  93. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
  94. package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
  95. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
  96. package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
  97. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
  98. package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
  99. package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
  100. package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
  101. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
  102. package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
  103. package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
  104. package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
  105. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
  106. package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
  107. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
  108. package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
  109. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
  110. package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
  111. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
  112. package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
  113. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
  114. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
  115. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
  116. package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
  117. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
  118. package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
  119. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
  120. package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
  121. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
  122. package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
  123. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
  124. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
  125. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
  126. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
  127. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
  128. package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
  129. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
  130. package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
  131. package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
  132. package/dist/types/core/agents/credentials.d.ts +28 -0
  133. package/dist/types/core/agents/credentials.d.ts.map +1 -0
  134. package/dist/types/core/agents/elicitation.d.ts +37 -0
  135. package/dist/types/core/agents/elicitation.d.ts.map +1 -0
  136. package/dist/types/core/agents/inherit-config.d.ts +18 -0
  137. package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
  138. package/dist/types/core/agents/login.d.ts +67 -0
  139. package/dist/types/core/agents/login.d.ts.map +1 -0
  140. package/dist/types/core/agents/mcp-config.d.ts +57 -0
  141. package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
  142. package/dist/types/core/agents/plan.d.ts +16 -0
  143. package/dist/types/core/agents/plan.d.ts.map +1 -0
  144. package/dist/types/core/agents/registry.d.ts +30 -0
  145. package/dist/types/core/agents/registry.d.ts.map +1 -0
  146. package/dist/types/core/agents/session-agent.d.ts +48 -0
  147. package/dist/types/core/agents/session-agent.d.ts.map +1 -0
  148. package/dist/types/core/agents/session-pool.d.ts +41 -0
  149. package/dist/types/core/agents/session-pool.d.ts.map +1 -0
  150. package/dist/types/core/agents/stderr-tail.d.ts +28 -0
  151. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
  152. package/dist/types/core/agents/thinking-levels.d.ts +4 -0
  153. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
  154. package/dist/types/core/agents/types.d.ts +124 -0
  155. package/dist/types/core/agents/types.d.ts.map +1 -0
  156. package/dist/types/core/diagnostics.d.ts +36 -0
  157. package/dist/types/core/diagnostics.d.ts.map +1 -0
  158. package/dist/types/core/index.d.ts +29 -0
  159. package/dist/types/core/index.d.ts.map +1 -0
  160. package/dist/types/core/presets.d.ts +80 -0
  161. package/dist/types/core/presets.d.ts.map +1 -0
  162. package/dist/types/core/processes/identity.d.ts +31 -0
  163. package/dist/types/core/processes/identity.d.ts.map +1 -0
  164. package/dist/types/core/processes/lifeline.d.ts +47 -0
  165. package/dist/types/core/processes/lifeline.d.ts.map +1 -0
  166. package/dist/types/core/processes/native-processes.d.ts +130 -0
  167. package/dist/types/core/processes/native-processes.d.ts.map +1 -0
  168. package/dist/types/core/processes/process-table.d.ts +43 -0
  169. package/dist/types/core/processes/process-table.d.ts.map +1 -0
  170. package/dist/types/core/provision/cache-trust.d.ts +13 -0
  171. package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
  172. package/dist/types/core/provision/cache-usage.d.ts +14 -0
  173. package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
  174. package/dist/types/core/provision/checksums.d.ts +46 -0
  175. package/dist/types/core/provision/checksums.d.ts.map +1 -0
  176. package/dist/types/core/provision/extract.d.ts +7 -0
  177. package/dist/types/core/provision/extract.d.ts.map +1 -0
  178. package/dist/types/core/provision/index.d.ts +5 -0
  179. package/dist/types/core/provision/index.d.ts.map +1 -0
  180. package/dist/types/core/provision/install-build.d.ts +36 -0
  181. package/dist/types/core/provision/install-build.d.ts.map +1 -0
  182. package/dist/types/core/provision/npm.d.ts +40 -0
  183. package/dist/types/core/provision/npm.d.ts.map +1 -0
  184. package/dist/types/core/provision/pins.d.ts +24 -0
  185. package/dist/types/core/provision/pins.d.ts.map +1 -0
  186. package/dist/types/core/provision/platform.d.ts +28 -0
  187. package/dist/types/core/provision/platform.d.ts.map +1 -0
  188. package/dist/types/core/provision/provisioner.d.ts +189 -0
  189. package/dist/types/core/provision/provisioner.d.ts.map +1 -0
  190. package/dist/types/core/provision/releases.d.ts +8 -0
  191. package/dist/types/core/provision/releases.d.ts.map +1 -0
  192. package/dist/types/core/provision/tools.d.ts +81 -0
  193. package/dist/types/core/provision/tools.d.ts.map +1 -0
  194. package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
  195. package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
  196. package/dist/types/core/proxy/api-key-store.d.ts +37 -0
  197. package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
  198. package/dist/types/core/proxy/index.d.ts +3 -0
  199. package/dist/types/core/proxy/index.d.ts.map +1 -0
  200. package/dist/types/core/proxy/loopback.d.ts +14 -0
  201. package/dist/types/core/proxy/loopback.d.ts.map +1 -0
  202. package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
  203. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
  204. package/dist/types/core/runtime/event-processor.d.ts +87 -0
  205. package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
  206. package/dist/types/core/runtime/event-sink.d.ts +44 -0
  207. package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
  208. package/dist/types/core/runtime/harness-clis.d.ts +10 -0
  209. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
  210. package/dist/types/core/runtime/harness-logins.d.ts +68 -0
  211. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
  212. package/dist/types/core/runtime/login-reads.d.ts +28 -0
  213. package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
  214. package/dist/types/core/runtime/model-lists.d.ts +37 -0
  215. package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
  216. package/dist/types/core/runtime/permission-policy.d.ts +61 -0
  217. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
  218. package/dist/types/core/runtime/request-broker.d.ts +49 -0
  219. package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
  220. package/dist/types/core/runtime/steering.d.ts +38 -0
  221. package/dist/types/core/runtime/steering.d.ts.map +1 -0
  222. package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
  223. package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
  224. package/dist/types/core/runtime/turn.d.ts +121 -0
  225. package/dist/types/core/runtime/turn.d.ts.map +1 -0
  226. package/dist/types/core/utils/bounded.d.ts +6 -0
  227. package/dist/types/core/utils/bounded.d.ts.map +1 -0
  228. package/dist/types/core/utils/deadline.d.ts +14 -0
  229. package/dist/types/core/utils/deadline.d.ts.map +1 -0
  230. package/dist/types/core/utils/errors.d.ts +104 -0
  231. package/dist/types/core/utils/errors.d.ts.map +1 -0
  232. package/dist/types/core/utils/is-record.d.ts +3 -0
  233. package/dist/types/core/utils/is-record.d.ts.map +1 -0
  234. package/dist/types/core/utils/loopback.d.ts +6 -0
  235. package/dist/types/core/utils/loopback.d.ts.map +1 -0
  236. package/dist/types/index.d.ts +2 -0
  237. package/dist/types/index.d.ts.map +1 -0
  238. package/dist/types/protocol/account.d.ts +26 -0
  239. package/dist/types/protocol/account.d.ts.map +1 -0
  240. package/dist/types/protocol/async-queue.d.ts +21 -0
  241. package/dist/types/protocol/async-queue.d.ts.map +1 -0
  242. package/dist/types/protocol/auth.d.ts +228 -0
  243. package/dist/types/protocol/auth.d.ts.map +1 -0
  244. package/dist/types/protocol/canonical.d.ts +9 -0
  245. package/dist/types/protocol/canonical.d.ts.map +1 -0
  246. package/dist/types/protocol/clis.d.ts +74 -0
  247. package/dist/types/protocol/clis.d.ts.map +1 -0
  248. package/dist/types/protocol/config.d.ts +200 -0
  249. package/dist/types/protocol/config.d.ts.map +1 -0
  250. package/dist/types/protocol/conversation.d.ts +942 -0
  251. package/dist/types/protocol/conversation.d.ts.map +1 -0
  252. package/dist/types/protocol/credentials.d.ts +145 -0
  253. package/dist/types/protocol/credentials.d.ts.map +1 -0
  254. package/dist/types/protocol/errors.d.ts +36 -0
  255. package/dist/types/protocol/errors.d.ts.map +1 -0
  256. package/dist/types/protocol/execution.d.ts +28 -0
  257. package/dist/types/protocol/execution.d.ts.map +1 -0
  258. package/dist/types/protocol/factories.d.ts +94 -0
  259. package/dist/types/protocol/factories.d.ts.map +1 -0
  260. package/dist/types/protocol/guards.d.ts +55 -0
  261. package/dist/types/protocol/guards.d.ts.map +1 -0
  262. package/dist/types/protocol/harness.d.ts +70 -0
  263. package/dist/types/protocol/harness.d.ts.map +1 -0
  264. package/dist/types/protocol/history.d.ts +318 -0
  265. package/dist/types/protocol/history.d.ts.map +1 -0
  266. package/dist/types/protocol/ids.d.ts +9 -0
  267. package/dist/types/protocol/ids.d.ts.map +1 -0
  268. package/dist/types/protocol/index.d.ts +35 -0
  269. package/dist/types/protocol/index.d.ts.map +1 -0
  270. package/dist/types/protocol/lifecycle.d.ts +1190 -0
  271. package/dist/types/protocol/lifecycle.d.ts.map +1 -0
  272. package/dist/types/protocol/meta-keys.d.ts +17 -0
  273. package/dist/types/protocol/meta-keys.d.ts.map +1 -0
  274. package/dist/types/protocol/meta.d.ts +13 -0
  275. package/dist/types/protocol/meta.d.ts.map +1 -0
  276. package/dist/types/protocol/model-catalog.d.ts +11 -0
  277. package/dist/types/protocol/model-catalog.d.ts.map +1 -0
  278. package/dist/types/protocol/models.d.ts +107 -0
  279. package/dist/types/protocol/models.d.ts.map +1 -0
  280. package/dist/types/protocol/part-input.d.ts +101 -0
  281. package/dist/types/protocol/part-input.d.ts.map +1 -0
  282. package/dist/types/protocol/parts.d.ts +357 -0
  283. package/dist/types/protocol/parts.d.ts.map +1 -0
  284. package/dist/types/protocol/reduce.d.ts +26 -0
  285. package/dist/types/protocol/reduce.d.ts.map +1 -0
  286. package/dist/types/protocol/selectors.d.ts +64 -0
  287. package/dist/types/protocol/selectors.d.ts.map +1 -0
  288. package/dist/types/protocol/seq-cursor.d.ts +66 -0
  289. package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
  290. package/dist/types/protocol/stop-reasons.d.ts +33 -0
  291. package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
  292. package/dist/types/protocol/thinking.d.ts +28 -0
  293. package/dist/types/protocol/thinking.d.ts.map +1 -0
  294. package/dist/types/protocol/time.d.ts +21 -0
  295. package/dist/types/protocol/time.d.ts.map +1 -0
  296. package/dist/types/protocol/tokens.d.ts +29 -0
  297. package/dist/types/protocol/tokens.d.ts.map +1 -0
  298. package/dist/types/protocol/tool-closure.d.ts +25 -0
  299. package/dist/types/protocol/tool-closure.d.ts.map +1 -0
  300. package/dist/types/protocol/tool-state.d.ts +209 -0
  301. package/dist/types/protocol/tool-state.d.ts.map +1 -0
  302. package/dist/types/protocol/verify.d.ts +52 -0
  303. package/dist/types/protocol/verify.d.ts.map +1 -0
  304. package/dist/types/protocol/vocabulary.d.ts +19 -0
  305. package/dist/types/protocol/vocabulary.d.ts.map +1 -0
  306. package/dist/types/protocol/wire-api.d.ts +1983 -0
  307. package/dist/types/protocol/wire-api.d.ts.map +1 -0
  308. package/dist/types/protocol/wire.d.ts +1758 -0
  309. package/dist/types/protocol/wire.d.ts.map +1 -0
  310. package/dist/types/server/acp/binding.d.ts +33 -0
  311. package/dist/types/server/acp/binding.d.ts.map +1 -0
  312. package/dist/types/server/acp/session-records.d.ts +17 -0
  313. package/dist/types/server/acp/session-records.d.ts.map +1 -0
  314. package/dist/types/server/acp/translate.d.ts +48 -0
  315. package/dist/types/server/acp/translate.d.ts.map +1 -0
  316. package/dist/types/server/agent-server.d.ts +121 -0
  317. package/dist/types/server/agent-server.d.ts.map +1 -0
  318. package/dist/types/server/feedback.d.ts +37 -0
  319. package/dist/types/server/feedback.d.ts.map +1 -0
  320. package/dist/types/server/history.d.ts +15 -0
  321. package/dist/types/server/history.d.ts.map +1 -0
  322. package/dist/types/server/index.d.ts +7 -0
  323. package/dist/types/server/index.d.ts.map +1 -0
  324. package/dist/types/server/install.d.ts +42 -0
  325. package/dist/types/server/install.d.ts.map +1 -0
  326. package/dist/types/server/open-parts.d.ts +27 -0
  327. package/dist/types/server/open-parts.d.ts.map +1 -0
  328. package/dist/types/server/routes.d.ts +61 -0
  329. package/dist/types/server/routes.d.ts.map +1 -0
  330. package/dist/types/server/secrets.d.ts +11 -0
  331. package/dist/types/server/secrets.d.ts.map +1 -0
  332. package/dist/types/server/session-gate.d.ts +32 -0
  333. package/dist/types/server/session-gate.d.ts.map +1 -0
  334. package/dist/types/server/session-log.d.ts +39 -0
  335. package/dist/types/server/session-log.d.ts.map +1 -0
  336. package/dist/types/server/session-store.d.ts +119 -0
  337. package/dist/types/server/session-store.d.ts.map +1 -0
  338. package/dist/types/server/subscriptions.d.ts +74 -0
  339. package/dist/types/server/subscriptions.d.ts.map +1 -0
  340. package/dist/types/server/transports.d.ts +74 -0
  341. package/dist/types/server/transports.d.ts.map +1 -0
  342. package/dist/types/server/wire-error.d.ts +9 -0
  343. package/dist/types/server/wire-error.d.ts.map +1 -0
  344. package/dist/types/sync/event-log.d.ts +45 -0
  345. package/dist/types/sync/event-log.d.ts.map +1 -0
  346. package/dist/types/sync/fit.d.ts +40 -0
  347. package/dist/types/sync/fit.d.ts.map +1 -0
  348. package/dist/types/sync/history-reader.d.ts +8 -0
  349. package/dist/types/sync/history-reader.d.ts.map +1 -0
  350. package/dist/types/sync/history-sqlite.d.ts +37 -0
  351. package/dist/types/sync/history-sqlite.d.ts.map +1 -0
  352. package/dist/types/sync/history.d.ts +70 -0
  353. package/dist/types/sync/history.d.ts.map +1 -0
  354. package/dist/types/sync/index.d.ts +4 -0
  355. package/dist/types/sync/index.d.ts.map +1 -0
  356. package/dist/types/sync/journal-sqlite.d.ts +51 -0
  357. package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
  358. package/dist/types/sync/journal.d.ts +107 -0
  359. package/dist/types/sync/journal.d.ts.map +1 -0
  360. package/dist/types/sync/live-tails.d.ts +30 -0
  361. package/dist/types/sync/live-tails.d.ts.map +1 -0
  362. package/dist/types/sync/node-sqlite.d.ts +7 -0
  363. package/dist/types/sync/node-sqlite.d.ts.map +1 -0
  364. package/dist/types/sync/projection.d.ts +10 -0
  365. package/dist/types/sync/projection.d.ts.map +1 -0
  366. package/dist/types/sync/recovery.d.ts +25 -0
  367. package/dist/types/sync/recovery.d.ts.map +1 -0
  368. package/dist/types/sync/retry.d.ts +25 -0
  369. package/dist/types/sync/retry.d.ts.map +1 -0
  370. package/dist/types/sync/schema.d.ts +4 -0
  371. package/dist/types/sync/schema.d.ts.map +1 -0
  372. package/dist/types/sync/sql.d.ts +38 -0
  373. package/dist/types/sync/sql.d.ts.map +1 -0
  374. package/dist/types/sync/sqlite-file.d.ts +9 -0
  375. package/dist/types/sync/sqlite-file.d.ts.map +1 -0
  376. package/dist/types/sync/sqlite.d.ts +6 -0
  377. package/dist/types/sync/sqlite.d.ts.map +1 -0
  378. package/dist/types/sync/worker.d.ts +63 -0
  379. package/dist/types/sync/worker.d.ts.map +1 -0
  380. package/docs/consuming.md +460 -54
  381. package/docs/deploy.md +218 -47
  382. package/docs/durable-sessions.md +195 -0
  383. package/docs/feedback.md +116 -0
  384. package/docs/harnesses.md +219 -87
  385. package/docs/sync-history.md +197 -0
  386. package/docs/sync-integration.md +119 -0
  387. package/package.json +53 -23
  388. package/src/accounts/chatgpt.ts +194 -0
  389. package/src/accounts/check.ts +112 -0
  390. package/src/accounts/claude.ts +111 -0
  391. package/src/accounts/endpoint.ts +151 -0
  392. package/src/accounts/http.ts +97 -0
  393. package/src/accounts/index.ts +19 -0
  394. package/src/client/client.ts +641 -602
  395. package/src/client/connection.ts +371 -0
  396. package/src/client/history.ts +65 -0
  397. package/src/client/index.ts +11 -2
  398. package/src/client/listeners.ts +20 -0
  399. package/src/client/logins.ts +105 -0
  400. package/src/client/rpc.ts +144 -0
  401. package/src/client/streams.ts +488 -0
  402. package/src/client/transports.ts +62 -8
  403. package/src/client/turns.ts +171 -0
  404. package/src/core/agents/acp/acp-agent.ts +94 -118
  405. package/src/core/agents/acp/adapter.ts +20 -9
  406. package/src/core/agents/acp/client.ts +125 -47
  407. package/src/core/agents/acp/known-agents.ts +36 -4
  408. package/src/core/agents/acp/mappings.ts +64 -18
  409. package/src/core/agents/acp/requests.ts +125 -0
  410. package/src/core/agents/attachments.ts +18 -0
  411. package/src/core/agents/base.ts +120 -42
  412. package/src/core/agents/claude-code/adapter.ts +177 -238
  413. package/src/core/agents/claude-code/approvals.ts +270 -0
  414. package/src/core/agents/claude-code/claude-agent.ts +175 -158
  415. package/src/core/agents/claude-code/credentials.ts +171 -0
  416. package/src/core/agents/claude-code/events.ts +55 -0
  417. package/src/core/agents/claude-code/login.ts +269 -0
  418. package/src/core/agents/claude-code/mcp.ts +206 -0
  419. package/src/core/agents/claude-code/models.ts +15 -9
  420. package/src/core/agents/claude-code/options.ts +326 -39
  421. package/src/core/agents/claude-code/outcome.ts +209 -0
  422. package/src/core/agents/claude-code/session-pool.ts +136 -0
  423. package/src/core/agents/claude-code/session.ts +513 -0
  424. package/src/core/agents/claude-code/spawn.ts +144 -0
  425. package/src/core/agents/claude-code/spend.ts +160 -0
  426. package/src/core/agents/claude-code/tools.ts +47 -0
  427. package/src/core/agents/claude-code/turn-usage.ts +135 -0
  428. package/src/core/agents/claude-code/turn.ts +232 -0
  429. package/src/core/agents/codex-app-server/adapter.ts +314 -117
  430. package/src/core/agents/codex-app-server/client.ts +186 -84
  431. package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
  432. package/src/core/agents/codex-app-server/commands.ts +228 -0
  433. package/src/core/agents/codex-app-server/credentials.ts +126 -0
  434. package/src/core/agents/codex-app-server/effort.ts +29 -0
  435. package/src/core/agents/codex-app-server/events.ts +47 -0
  436. package/src/core/agents/codex-app-server/homes.ts +64 -0
  437. package/src/core/agents/codex-app-server/input.ts +60 -0
  438. package/src/core/agents/codex-app-server/items.ts +149 -0
  439. package/src/core/agents/codex-app-server/login.ts +180 -0
  440. package/src/core/agents/codex-app-server/mcp.ts +182 -37
  441. package/src/core/agents/codex-app-server/models.ts +99 -46
  442. package/src/core/agents/codex-app-server/options.ts +146 -0
  443. package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
  444. package/src/core/agents/codex-app-server/protocol.ts +117 -0
  445. package/src/core/agents/codex-app-server/requests.ts +332 -0
  446. package/src/core/agents/codex-app-server/session.ts +285 -0
  447. package/src/core/agents/codex-app-server/subagents.ts +108 -42
  448. package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
  449. package/src/core/agents/codex-app-server/turn-items.ts +88 -0
  450. package/src/core/agents/codex-app-server/turn.ts +463 -0
  451. package/src/core/agents/config-fingerprint.ts +7 -14
  452. package/src/core/agents/credentials.ts +98 -0
  453. package/src/core/agents/elicitation.ts +75 -0
  454. package/src/core/agents/inherit-config.ts +21 -0
  455. package/src/core/agents/login.ts +116 -0
  456. package/src/core/agents/mcp-config.ts +112 -8
  457. package/src/core/agents/plan.ts +25 -0
  458. package/src/core/agents/registry.ts +21 -4
  459. package/src/core/agents/session-agent.ts +96 -4
  460. package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
  461. package/src/core/agents/stderr-tail.ts +75 -0
  462. package/src/core/agents/types.ts +40 -5
  463. package/src/core/index.ts +60 -48
  464. package/src/core/presets.ts +100 -39
  465. package/src/core/processes/identity.ts +113 -0
  466. package/src/core/processes/lifeline.ts +170 -0
  467. package/src/core/processes/native-processes.ts +379 -0
  468. package/src/core/processes/process-table.ts +174 -0
  469. package/src/core/provision/cache-trust.ts +121 -0
  470. package/src/core/provision/cache-usage.ts +69 -0
  471. package/src/core/provision/checksums.ts +64 -0
  472. package/src/core/provision/extract.ts +11 -2
  473. package/src/core/provision/index.ts +4 -1
  474. package/src/core/provision/install-build.ts +136 -0
  475. package/src/core/provision/npm.ts +112 -17
  476. package/src/core/provision/pins.ts +11 -34
  477. package/src/core/provision/platform.ts +12 -1
  478. package/src/core/provision/provisioner.ts +329 -397
  479. package/src/core/provision/releases.ts +86 -0
  480. package/src/core/provision/tools.ts +329 -0
  481. package/src/core/proxy/anthropic-proxy.ts +55 -25
  482. package/src/core/proxy/api-key-store.ts +2 -12
  483. package/src/core/proxy/loopback.ts +106 -0
  484. package/src/core/runtime/agent-runtime.ts +340 -481
  485. package/src/core/runtime/event-processor.ts +207 -75
  486. package/src/core/runtime/event-sink.ts +45 -2
  487. package/src/core/runtime/harness-clis.ts +61 -0
  488. package/src/core/runtime/harness-logins.ts +328 -0
  489. package/src/core/runtime/login-reads.ts +78 -0
  490. package/src/core/runtime/model-lists.ts +57 -57
  491. package/src/core/runtime/permission-policy.ts +113 -0
  492. package/src/core/runtime/request-broker.ts +204 -0
  493. package/src/core/runtime/steering.ts +112 -0
  494. package/src/core/runtime/turn-outcome.ts +30 -0
  495. package/src/core/runtime/turn.ts +360 -0
  496. package/src/core/utils/bounded.ts +12 -0
  497. package/src/core/utils/deadline.ts +38 -0
  498. package/src/core/utils/errors.ts +113 -21
  499. package/src/core/utils/is-record.ts +4 -0
  500. package/src/core/utils/loopback.ts +10 -0
  501. package/src/protocol/account.ts +104 -0
  502. package/src/protocol/auth.ts +199 -0
  503. package/src/protocol/canonical.ts +16 -0
  504. package/src/protocol/clis.ts +69 -0
  505. package/src/protocol/config.ts +60 -6
  506. package/src/protocol/conversation.ts +272 -0
  507. package/src/protocol/credentials.ts +145 -0
  508. package/src/protocol/errors.ts +78 -20
  509. package/src/protocol/execution.ts +5 -2
  510. package/src/protocol/factories.ts +55 -7
  511. package/src/protocol/guards.ts +55 -2
  512. package/src/protocol/harness.ts +56 -6
  513. package/src/protocol/history.ts +275 -0
  514. package/src/protocol/ids.ts +4 -17
  515. package/src/protocol/index.ts +10 -0
  516. package/src/protocol/lifecycle.ts +250 -79
  517. package/src/protocol/meta-keys.ts +17 -0
  518. package/src/protocol/meta.ts +3 -3
  519. package/src/protocol/models.ts +2 -43
  520. package/src/protocol/part-input.ts +2 -1
  521. package/src/protocol/parts.ts +12 -3
  522. package/src/protocol/reduce.ts +302 -413
  523. package/src/protocol/selectors.ts +1 -20
  524. package/src/protocol/seq-cursor.ts +14 -0
  525. package/src/protocol/stop-reasons.ts +1 -1
  526. package/src/protocol/thinking.ts +1 -30
  527. package/src/protocol/time.ts +2 -2
  528. package/src/protocol/tool-closure.ts +93 -0
  529. package/src/protocol/tool-state.ts +19 -4
  530. package/src/protocol/verify.ts +222 -92
  531. package/src/protocol/vocabulary.ts +21 -5
  532. package/src/protocol/wire-api.ts +232 -0
  533. package/src/protocol/wire.ts +425 -57
  534. package/src/server/acp/binding.ts +63 -103
  535. package/src/server/acp/session-records.ts +53 -0
  536. package/src/server/acp/translate.ts +129 -20
  537. package/src/server/agent-server.ts +275 -366
  538. package/src/server/bin.ts +295 -72
  539. package/src/server/feedback.ts +204 -14
  540. package/src/server/history.ts +160 -0
  541. package/src/server/index.ts +4 -8
  542. package/src/server/install.ts +107 -8
  543. package/src/server/open-parts.ts +95 -0
  544. package/src/server/routes.ts +391 -0
  545. package/src/server/secrets.ts +24 -0
  546. package/src/server/session-gate.ts +69 -0
  547. package/src/server/session-log.ts +14 -2
  548. package/src/server/session-store.ts +289 -0
  549. package/src/server/subscriptions.ts +232 -0
  550. package/src/server/transports.ts +125 -25
  551. package/src/server/wire-error.ts +38 -0
  552. package/src/sync/event-log.ts +160 -0
  553. package/src/sync/fit.ts +140 -0
  554. package/src/sync/history-reader.ts +57 -0
  555. package/src/sync/history-sqlite.ts +339 -0
  556. package/src/sync/history.ts +220 -0
  557. package/src/sync/index.ts +18 -0
  558. package/src/sync/journal-sqlite.ts +439 -0
  559. package/src/sync/journal.ts +132 -0
  560. package/src/sync/live-tails.ts +107 -0
  561. package/src/sync/node-sqlite.ts +20 -0
  562. package/src/sync/projection.ts +35 -0
  563. package/src/sync/recovery.ts +141 -0
  564. package/src/sync/retry.ts +49 -0
  565. package/src/sync/schema.ts +77 -0
  566. package/src/sync/sql.ts +106 -0
  567. package/src/sync/sqlite-file.ts +38 -0
  568. package/src/sync/sqlite.ts +21 -0
  569. package/src/sync/worker.ts +259 -0
  570. package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
  571. package/docs/rfds/0002-native-subagents.md +0 -197
  572. package/src/core/agents/claude-code/generator-session.ts +0 -572
  573. package/src/core/agents/claude-code/session-manager.ts +0 -166
  574. package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
  575. package/src/core/agents/codex-items.ts +0 -149
  576. package/src/core/agents/codex-sdk/adapter.ts +0 -237
  577. package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
  578. package/src/core/agents/tool-meta.ts +0 -68
@@ -0,0 +1,135 @@
1
+ import { onAbort } from "../../utils/deadline.ts";
2
+ import type { PermissionDecision } from "../base.ts";
3
+ import { PLAN_OPTIONS, PLAN_TITLE, approvedPlanMode } from "../plan.ts";
4
+ import type { CodexConnection } from "./client.ts";
5
+ import { CODEX_PLAN_DECIDED, type CodexPlanDecided, type CodexRawEvent } from "./events.ts";
6
+ import { textInput } from "./input.ts";
7
+ import { CODEX_TOOL_KINDS } from "./items.ts";
8
+ import { mapSandbox } from "./options.ts";
9
+ import { type ThreadSettings, inCollaborationMode } from "./thread-settings.ts";
10
+ import type { CodexTurn, NativeTurn } from "./turn.ts";
11
+
12
+ /**
13
+ * Codex's built-in permission profile for the workspace-write sandbox (0.160).
14
+ * A turn switches a running thread to it, keeping the thread's writable roots.
15
+ */
16
+ const WORKSPACE_PROFILE = ":workspace";
17
+
18
+ /** What Codex's TUI sends to implement the plan it showed (0.160). */
19
+ const IMPLEMENT_THE_PLAN = "Implement the plan.";
20
+
21
+ /** Codex's turn that carries out the user's answer to its plan. */
22
+ export interface NextTurn {
23
+ params: Record<string, unknown>;
24
+ settings: ThreadSettings;
25
+ /** The thread's sandbox once it runs. */
26
+ sandbox: string;
27
+ }
28
+
29
+ /** Codex exited while the user decided on its plan: nothing can carry the answer out. */
30
+ function exitedBeforeAnswer(client: CodexConnection): Error {
31
+ return client.exitError ?? new Error("codex app-server exited before its plan was answered");
32
+ }
33
+
34
+ // @ref LLP 0001#d4--permission-requests-are-first-class-protocol — Codex's plan, put to the user like Claude's
35
+ /**
36
+ * Codex ends its Plan-mode turn with the plan and asks nothing; its TUI then
37
+ * asks whether to implement it, as the engine does here. The answer runs as
38
+ * Codex's next turn, within this one, which this returns; nothing when the
39
+ * turn ends here. A turn that does not go on once Codex's ends (a managed
40
+ * one), or has nobody to ask, presents the plan as written.
41
+ */
42
+ export async function* askPlan(
43
+ turn: CodexTurn,
44
+ native: NativeTurn,
45
+ ): AsyncGenerator<CodexRawEvent, NextTurn | undefined> {
46
+ const offered = native.plan;
47
+ const completed = native.outcome === "completed";
48
+ // Cancelled with a plan on the table: the turn was cancelled, not done.
49
+ if (offered && completed && turn.signal.aborted) throw new Error("turn aborted");
50
+ if (!offered || !completed || turn.signal.aborted) return undefined;
51
+ const decided = (decision: Omit<CodexPlanDecided, "itemId">): CodexRawEvent => ({
52
+ method: CODEX_PLAN_DECIDED,
53
+ params: { itemId: offered.itemId, ...decision },
54
+ });
55
+ const handler = turn.asksAboutPlans ? turn.scope.onPermissionRequest : undefined;
56
+ if (!handler) {
57
+ yield decided({ decision: "presented" });
58
+ return undefined;
59
+ }
60
+ const { session } = turn;
61
+ const { client } = session;
62
+ // Steers sent while the user decides wait for Codex's next turn.
63
+ turn.steering.hold();
64
+ if (client.closed) throw exitedBeforeAnswer(client);
65
+ // The question ends with the turn, or with Codex.
66
+ const asking = new AbortController();
67
+ const stopAsking = () => asking.abort();
68
+ const offAbort = onAbort(turn.signal, stopAsking);
69
+ const offClose = client.onClose(stopAsking);
70
+ let decision: PermissionDecision;
71
+ try {
72
+ decision = await handler(
73
+ {
74
+ toolCallId: offered.itemId,
75
+ toolName: "plan",
76
+ kind: CODEX_TOOL_KINDS.plan,
77
+ title: PLAN_TITLE,
78
+ rawInput: { plan: offered.text },
79
+ },
80
+ { signal: asking.signal, options: PLAN_OPTIONS },
81
+ );
82
+ } finally {
83
+ offAbort();
84
+ offClose();
85
+ }
86
+ if (turn.signal.aborted) throw new Error("turn aborted");
87
+ if (client.closed) throw exitedBeforeAnswer(client);
88
+ // What finished while the question was open, before its answer.
89
+ yield* turn.commands.drainLate();
90
+ let input: string;
91
+ let sandbox = session.sandbox;
92
+ const params: Record<string, unknown> = { threadId: session.threadId };
93
+ if (decision.decision === "allow") {
94
+ turn.scope.mode = approvedPlanMode(decision.optionId);
95
+ yield decided({ decision: "approved", permissionMode: turn.scope.mode });
96
+ // An edited plan is the plan approved: Codex implements that one.
97
+ const edited = decision.updatedInput?.plan;
98
+ input =
99
+ typeof edited === "string" && edited !== offered.text
100
+ ? `Implement this plan:\n\n${edited}`
101
+ : IMPLEMENT_THE_PLAN;
102
+ // Auto-accepted edits need the workspace-write sandbox; Codex switches a
103
+ // running thread to it for this turn and the next.
104
+ if (mapSandbox(turn.scope.mode) !== session.sandbox) {
105
+ params.permissions = WORKSPACE_PROFILE;
106
+ sandbox = mapSandbox(turn.scope.mode);
107
+ }
108
+ } else if (decision.decision === "cancel") {
109
+ // Nobody answered (or the client cancelled): the turn ends cancelled, as
110
+ // a Claude plan's does, not as a wish to keep planning. What the plan
111
+ // turn left running was left on purpose and keeps running: not
112
+ // cancelled, its outcome unknown.
113
+ yield* turn.endCancelled();
114
+ yield decided({ decision: "cancelled" });
115
+ return undefined;
116
+ } else {
117
+ const message = decision.message;
118
+ yield decided({ decision: "kept_planning", ...(message && { message }) });
119
+ // Nothing said: the user tells the agent what to change in their next turn.
120
+ if (!message) return undefined;
121
+ input = message;
122
+ }
123
+ // What finished while the answer streamed, before the next turn's events:
124
+ // shown before the abort's check, as nothing from that check to the next
125
+ // turn's start may pause for a cancel to slip past.
126
+ yield* turn.commands.drainLate();
127
+ // A cancel while the stream took the answer: nothing more runs.
128
+ if (turn.signal.aborted) throw new Error("turn aborted");
129
+ const mode = inCollaborationMode(session.thread.settings, turn.scope.mode);
130
+ return {
131
+ params: { ...params, ...mode.params, input: [textInput(input)] },
132
+ settings: mode.next,
133
+ sandbox,
134
+ };
135
+ }
@@ -0,0 +1,117 @@
1
+ import { isRecord } from "../../utils/is-record.ts";
2
+
3
+ /**
4
+ * What the harness reads of Codex's app-server protocol (v2), as of the pinned
5
+ * CLI: the decoders below check what it relies on. Codex sends more.
6
+ */
7
+
8
+ /** A JSON-RPC notification Codex sends (server → client, no id). */
9
+ export interface CodexNotification {
10
+ method: string;
11
+ params: Record<string, unknown> & { threadId?: string; turnId?: string };
12
+ }
13
+
14
+ /** One edit of a file change. Its `kind` is a string before 0.160, `{type, move_path}` from it. */
15
+ export interface CodexFileChange {
16
+ path: string;
17
+ kind?: string | { type?: string; move_path?: string | null };
18
+ diff?: string;
19
+ }
20
+
21
+ /**
22
+ * One of a thread's items (`ThreadItem`). Every field but `type` and `id`
23
+ * belongs to some item types only.
24
+ */
25
+ export interface CodexItem {
26
+ type: string;
27
+ id: string;
28
+ /** An `agentMessage`'s, a `reasoning`'s or a `plan`'s text. */
29
+ text?: string;
30
+ /** A `commandExecution`: what it runs, in which of Codex's processes, and how it ended. */
31
+ command?: string | string[];
32
+ processId?: string | null;
33
+ /**
34
+ * Who started it. A poll of, or input to, a process an earlier turn
35
+ * started is `unifiedExecInteraction`; the user's own command `userShell`.
36
+ */
37
+ source?: string;
38
+ aggregatedOutput?: string | null;
39
+ exitCode?: number | null;
40
+ status?: string;
41
+ /** A `fileChange`'s edits. */
42
+ changes?: CodexFileChange[];
43
+ /** An `mcpToolCall`. */
44
+ server?: string;
45
+ tool?: string;
46
+ arguments?: unknown;
47
+ result?: unknown;
48
+ error?: { message?: string } | string;
49
+ /** A `webSearch`. */
50
+ query?: string;
51
+ /** A `collabAgentToolCall`: a sub-agent spawned, messaged or waited on. */
52
+ receiverThreadIds?: string[];
53
+ prompt?: string | null;
54
+ model?: string | null;
55
+ agentsStates?: Record<string, { status: string; message?: string | null }>;
56
+ /** A `subAgentActivity`: what a sub-agent's thread did. */
57
+ agentThreadId?: string;
58
+ agentPath?: string;
59
+ kind?: "started" | "interacted" | "interrupted" | "completed";
60
+ /** A `userMessage`'s client id: a steer's id (`turn/steer`'s `clientUserMessageId`). */
61
+ clientId?: string | null;
62
+ }
63
+
64
+ /** A turn as `turn/started` and `turn/completed` name it (`Turn`). */
65
+ export interface CodexTurnInfo {
66
+ id?: string;
67
+ /** `completed`, `interrupted` (stopped: a cancel, or an approval answered cancel), `failed`. */
68
+ status?: string;
69
+ /** Why it failed: Codex's words, and its typed code (`codexErrorInfo`). */
70
+ error?: { message?: string; codexErrorInfo?: unknown };
71
+ }
72
+
73
+ /** What `thread/start` and `thread/resume` answer. */
74
+ export interface CodexThreadOpened {
75
+ thread?: { id?: string };
76
+ model?: unknown;
77
+ reasoningEffort?: unknown;
78
+ collaborationMode?: { mode?: unknown } | null;
79
+ }
80
+
81
+ /** An item names its type and id; the rest is Codex's, as each type has it. */
82
+ function isItem(value: unknown): value is CodexItem {
83
+ return isRecord(value) && typeof value.type === "string" && typeof value.id === "string";
84
+ }
85
+
86
+ /** The item a notification carries (`item/started`, `item/completed`), when it names its type and id. */
87
+ export function codexItem(n: CodexNotification): CodexItem | undefined {
88
+ const { item } = n.params;
89
+ return isItem(item) ? item : undefined;
90
+ }
91
+
92
+ /** The turn a notification names (`turn/started`, `turn/completed`). */
93
+ export function codexTurn(n: CodexNotification): CodexTurnInfo | undefined {
94
+ const { turn } = n.params;
95
+ if (!isRecord(turn)) return undefined;
96
+ const { error } = turn;
97
+ return {
98
+ ...(typeof turn.id === "string" && { id: turn.id }),
99
+ ...(typeof turn.status === "string" && { status: turn.status }),
100
+ ...(isRecord(error) && {
101
+ error: {
102
+ ...(typeof error.message === "string" && { message: error.message }),
103
+ codexErrorInfo: error.codexErrorInfo,
104
+ },
105
+ }),
106
+ };
107
+ }
108
+
109
+ /** Whether a notification ends Codex's turn: its completion, or an error Codex will not retry. */
110
+ export function endsNativeTurn(n: CodexNotification): boolean {
111
+ return n.method === "turn/completed" || (n.method === "error" && n.params.willRetry !== true);
112
+ }
113
+
114
+ /** An `error` Codex retries what failed after: the turn goes on, and more is to come. */
115
+ export function retrying(n: CodexNotification): boolean {
116
+ return n.method === "error" && n.params.willRetry === true;
117
+ }
@@ -0,0 +1,332 @@
1
+ import {
2
+ type PermissionMode,
3
+ type PermissionToolCall,
4
+ generateUUIDv7,
5
+ } from "../../../protocol/index.ts";
6
+ import { isRecord } from "../../utils/is-record.ts";
7
+ import type { ElicitationRequestHandler, PermissionRequestHandler } from "../base.ts";
8
+ import {
9
+ NO_ANSWERS,
10
+ inputReply,
11
+ inputRequest,
12
+ questionRequest,
13
+ unanswered,
14
+ } from "../elicitation.ts";
15
+ import { type CodexAuth, refreshTokens } from "./credentials.ts";
16
+ import { CODEX_TOOL_KINDS } from "./items.ts";
17
+ import type { CodexSession } from "./session.ts";
18
+ import type { CodexTurnSubagents } from "./subagents.ts";
19
+ import type { TurnItems } from "./turn-items.ts";
20
+
21
+ /**
22
+ * What Codex's requests need of the turn that has the session: set when a
23
+ * turn takes it, cleared when it ends, so no request answers for another.
24
+ */
25
+ export interface CodexTurnScope {
26
+ /** Credentials belong only to the current turn. */
27
+ auth?: CodexAuth;
28
+ onPermissionRequest?: PermissionRequestHandler;
29
+ /** Present when the turn's client answers questions and MCP input. */
30
+ onElicitationRequest?: ElicitationRequestHandler;
31
+ signal: AbortSignal;
32
+ /** The threads the turn's managed sub-agents run in. */
33
+ subagents?: CodexTurnSubagents;
34
+ items: TurnItems;
35
+ /** The mode the turn runs in now: its own, until the user approves a plan. */
36
+ mode: PermissionMode;
37
+ }
38
+
39
+ /** One question of Codex's request_user_input. */
40
+ interface CodexQuestion {
41
+ id: string;
42
+ question: string;
43
+ header?: string;
44
+ isOther?: boolean;
45
+ isSecret?: boolean;
46
+ options?: Array<{ label: string; description?: string }> | null;
47
+ }
48
+
49
+ /**
50
+ * What became of a request put to the turn that had the session when Codex
51
+ * asked. `refused`: it could not be asked (no turn, a cancelled one, nobody to
52
+ * answer, another thread's); `stale`: the turn changed while it was asked.
53
+ */
54
+ type Asked<T> = { refused: true } | { stale: true } | { answer: T };
55
+
56
+ /** Whether the thread a request comes from is the session's, or one its turn's sub-agents run in. */
57
+ async function owns(
58
+ session: CodexSession,
59
+ turn: CodexTurnScope,
60
+ thread: unknown,
61
+ ): Promise<boolean> {
62
+ if (!thread || thread === session.threadId) return true;
63
+ return Boolean(
64
+ typeof thread === "string" &&
65
+ turn.subagents &&
66
+ (await turn.subagents.owns(thread).catch(() => false)),
67
+ );
68
+ }
69
+
70
+ /** Ask the turn that has the session now, through its broker for `kind`. */
71
+ async function askCurrentTurn<K extends "onPermissionRequest" | "onElicitationRequest", T>(
72
+ session: CodexSession,
73
+ params: Record<string, unknown>,
74
+ kind: K,
75
+ ask: (handler: NonNullable<CodexTurnScope[K]>, turn: CodexTurnScope) => Promise<T>,
76
+ ): Promise<Asked<T>> {
77
+ const turn = session.turn;
78
+ const handler = turn?.[kind];
79
+ if (!turn || !handler || turn.signal.aborted || !(await owns(session, turn, params.threadId)))
80
+ return { refused: true };
81
+ // Ownership can take a thread/read round-trip: the turn may have ended.
82
+ if (session.turn !== turn || turn.signal.aborted) return { refused: true };
83
+ const answer = await ask(handler, turn);
84
+ return session.turn !== turn || turn.signal.aborted ? { stale: true } : { answer };
85
+ }
86
+
87
+ /**
88
+ * Answer Codex's requests (server → client) for the turn that has the session.
89
+ * A request it cannot answer gets a refusal in its own shape, never a hang.
90
+ */
91
+ export function bindServerRequests(session: CodexSession): void {
92
+ session.client.setRequestHandler(async (method, params) => {
93
+ switch (method) {
94
+ case "account/chatgptAuthTokens/refresh":
95
+ return refreshTokens(session, params);
96
+ case "mcpServer/elicitation/request":
97
+ return isMcpToolConsent(params)
98
+ ? answerConsent(session, params)
99
+ : answerMcpElicitation(session, params);
100
+ case "item/tool/requestUserInput":
101
+ return answerQuestions(session, params);
102
+ case "item/commandExecution/requestApproval":
103
+ case "item/fileChange/requestApproval":
104
+ return answerApproval(session, method, params);
105
+ default:
106
+ // Other server requests have their own response shapes. Sending them
107
+ // to the approval broker can leave a turn waiting forever.
108
+ throw new Error(`Unsupported Codex server request: ${method}`);
109
+ }
110
+ });
111
+ }
112
+
113
+ /** Codex asks consent for an MCP tool call as an MCP elicitation of this kind. */
114
+ function isMcpToolConsent(params: Record<string, unknown>): boolean {
115
+ return isRecord(params._meta) && params._meta.codex_approval_kind === "mcp_tool_call";
116
+ }
117
+
118
+ /** An MCP elicitation's reply: Codex takes explicit nulls. */
119
+ const elicitationReply = (action: string, content: unknown = null) => ({
120
+ action,
121
+ content,
122
+ _meta: null,
123
+ });
124
+
125
+ /**
126
+ * Codex's consent for an MCP tool call is a tool approval like any other, so
127
+ * the engine broker answers it. It cannot carry edited arguments: what was
128
+ * approved is what runs, and an edited approval declines.
129
+ */
130
+ async function answerConsent(session: CodexSession, params: Record<string, unknown>) {
131
+ const asked = await askCurrentTurn(session, params, "onPermissionRequest", (handler, turn) =>
132
+ handler(mcpConsentToolCall(params, turn.items)),
133
+ );
134
+ if (!("answer" in asked)) return elicitationReply("decline");
135
+ const decision = asked.answer;
136
+ if (decision.decision === "cancel") return elicitationReply("cancel");
137
+ return decision.decision === "allow" && decision.updatedInput === undefined
138
+ ? elicitationReply("accept")
139
+ : elicitationReply("decline");
140
+ }
141
+
142
+ /**
143
+ * The consent names its server and arguments, not its call: link it to the
144
+ * started call it is for, so the approval points at that tool part.
145
+ */
146
+ function mcpConsentToolCall(params: Record<string, unknown>, items: TurnItems): PermissionToolCall {
147
+ const meta = isRecord(params._meta) ? params._meta : {};
148
+ const server = typeof params.serverName === "string" ? params.serverName : "mcp";
149
+ const message = typeof params.message === "string" ? params.message : undefined;
150
+ const named = message?.match(/tool "([^"]+)"/)?.[1];
151
+ const call = items.consentedCall(
152
+ server,
153
+ typeof params.threadId === "string" ? params.threadId : undefined,
154
+ named,
155
+ JSON.stringify(meta.tool_params ?? {}),
156
+ );
157
+ // The arguments are the tool's input, as a Claude MCP approval's are: a
158
+ // client previews them there.
159
+ const input = meta.tool_params ?? call?.arguments ?? {};
160
+ return {
161
+ toolCallId: call?.id ?? generateUUIDv7(),
162
+ toolName: `${server}.${call?.tool ?? named ?? "tool"}`,
163
+ kind: CODEX_TOOL_KINDS.mcp,
164
+ ...(message && { title: message }),
165
+ rawInput: isRecord(input) ? input : { arguments: input },
166
+ };
167
+ }
168
+
169
+ /**
170
+ * An MCP server's own request for input (a form, or a URL to visit), asked
171
+ * through the engine's elicitation broker; declined when nobody can answer,
172
+ * so the server sees a refusal and not a protocol error.
173
+ */
174
+ async function answerMcpElicitation(session: CodexSession, params: Record<string, unknown>) {
175
+ const mode = params.mode;
176
+ // OpenAI's own modes carry their own schemas: not ours to render.
177
+ if (mode !== "form" && mode !== "url") return elicitationReply("decline");
178
+ const serverName = typeof params.serverName === "string" ? params.serverName : undefined;
179
+ const asked = await askCurrentTurn(session, params, "onElicitationRequest", (handler, turn) =>
180
+ handler(
181
+ inputRequest({
182
+ mode,
183
+ message: typeof params.message === "string" ? params.message : "",
184
+ serverName,
185
+ toolCallId: turn.items.callOf(serverName)?.id,
186
+ requestedSchema: isRecord(params.requestedSchema) ? params.requestedSchema : undefined,
187
+ url: typeof params.url === "string" ? params.url : undefined,
188
+ elicitationId: typeof params.elicitationId === "string" ? params.elicitationId : undefined,
189
+ }),
190
+ { signal: turn.signal },
191
+ ),
192
+ );
193
+ if ("refused" in asked) return elicitationReply("decline");
194
+ if ("stale" in asked) return elicitationReply("cancel");
195
+ const answer = inputReply(asked.answer);
196
+ return elicitationReply(answer.action, answer.content ?? null);
197
+ }
198
+
199
+ /**
200
+ * Codex's request_user_input (its plan mode asks this way), asked through
201
+ * the engine's elicitation broker. A refusal goes back as an error: Codex
202
+ * then asks in plain text instead of asking again.
203
+ */
204
+ async function answerQuestions(session: CodexSession, params: Record<string, unknown>) {
205
+ const asked = (Array.isArray(params.questions) ? params.questions : []) as CodexQuestion[];
206
+ const questions = asked
207
+ .filter((q) => typeof q.id === "string" && typeof q.question === "string")
208
+ .map((q) => ({
209
+ id: q.id,
210
+ question: q.question,
211
+ ...(q.header && { header: q.header }),
212
+ ...(q.options?.length && {
213
+ options: q.options.map((o) => ({
214
+ label: o.label,
215
+ ...(o.description && { description: o.description }),
216
+ })),
217
+ }),
218
+ ...(q.isOther && { allowOther: true }),
219
+ ...(q.isSecret && { secret: true }),
220
+ }));
221
+ const outcome = await askCurrentTurn(session, params, "onElicitationRequest", (handler, turn) =>
222
+ handler(
223
+ questionRequest(questions, typeof params.itemId === "string" ? params.itemId : undefined),
224
+ { signal: turn.signal },
225
+ ),
226
+ );
227
+ if ("refused" in outcome) throw new Error(NO_ANSWERS);
228
+ if ("stale" in outcome) throw new Error("The turn ended before the user answered.");
229
+ const answer = outcome.answer;
230
+ if (answer.action !== "accept") throw new Error(unanswered(answer.action));
231
+ const content = answer.content ?? {};
232
+ return {
233
+ answers: Object.fromEntries(
234
+ questions.map((q) => {
235
+ const value = content[q.id];
236
+ const answers = Array.isArray(value)
237
+ ? value.map(String)
238
+ : value === undefined
239
+ ? []
240
+ : [String(value)];
241
+ return [q.id, { answers }];
242
+ }),
243
+ ),
244
+ };
245
+ }
246
+
247
+ /**
248
+ * A command or file change Codex asks to run, through the engine broker.
249
+ * Codex's reply is a bare verdict, with no slot for an edited input: what was
250
+ * approved is what runs, so an edited approval declines (only claude-code's
251
+ * `canUseTool` can execute an edit).
252
+ */
253
+ async function answerApproval(
254
+ session: CodexSession,
255
+ method: "item/commandExecution/requestApproval" | "item/fileChange/requestApproval",
256
+ params: Record<string, unknown>,
257
+ ) {
258
+ const decline = { decision: "decline" };
259
+ // A plan turn changes no files.
260
+ if (method === "item/fileChange/requestApproval" && session.turn?.mode === "plan") return decline;
261
+ const always = codexAlways(method, params);
262
+ const asked = await askCurrentTurn(session, params, "onPermissionRequest", (handler, turn) =>
263
+ handler(approvalToolCall(method, params, turn.items), { always }),
264
+ );
265
+ if (!("answer" in asked)) return decline;
266
+ const decision = asked.answer;
267
+ if (decision.decision === "cancel") return { decision: "cancel" };
268
+ if (decision.decision !== "allow" || decision.updatedInput !== undefined) return decline;
269
+ return {
270
+ decision: decision.optionId === "allow_always" && always ? "acceptForSession" : "accept",
271
+ };
272
+ }
273
+
274
+ /** Codex's approval request as the engine's PermissionToolCall. */
275
+ function approvalToolCall(
276
+ method: "item/commandExecution/requestApproval" | "item/fileChange/requestApproval",
277
+ params: Record<string, unknown>,
278
+ items: TurnItems,
279
+ ): PermissionToolCall {
280
+ const id = typeof params.itemId === "string" ? params.itemId : "approval";
281
+ const reason = typeof params.reason === "string" ? params.reason : undefined;
282
+ if (method === "item/commandExecution/requestApproval") {
283
+ const command = typeof params.command === "string" ? params.command : "";
284
+ return {
285
+ toolCallId: id,
286
+ toolName: "shell",
287
+ kind: "execute",
288
+ ...(reason && { title: reason }),
289
+ rawInput: { command, ...(params.cwd ? { cwd: params.cwd } : {}) },
290
+ };
291
+ }
292
+ // A file-change request names its item, not the edits: those arrived on the
293
+ // item, which Codex starts before it asks. The approval shows them.
294
+ const changes = items.changesOf(id);
295
+ const grantRoot = typeof params.grantRoot === "string" ? params.grantRoot : undefined;
296
+ return {
297
+ toolCallId: id,
298
+ toolName: "apply_patch",
299
+ kind: "edit",
300
+ ...(reason && { title: reason }),
301
+ ...(changes.length && { locations: changes.map((change) => ({ path: change.path })) }),
302
+ rawInput: { changes, ...(grantRoot && { grantRoot }) },
303
+ };
304
+ }
305
+
306
+ /**
307
+ * What "always" covers for a Codex approval: Codex keeps it itself, for the
308
+ * session (`acceptForSession`). For a plain command that is this exact
309
+ * command ("don't ask again for this command"); for a file change, these
310
+ * files. A network approval's "always" opens a host, and one with extra
311
+ * permissions or a write root grants those, so they offer none. Codex 0.160
312
+ * lists `acceptWithExecpolicyAmendment` for a command instead: a prefix rule
313
+ * it writes to the user's own rules, which an engine must not, so the session
314
+ * approval (which it honors though unlisted) is the one taken.
315
+ */
316
+ export function codexAlways(
317
+ method: string,
318
+ params: Record<string, unknown>,
319
+ ): { rule: string } | null {
320
+ if (method === "item/commandExecution/requestApproval") {
321
+ const plain =
322
+ typeof params.command === "string" &&
323
+ params.command.length > 0 &&
324
+ (params.kind === undefined || params.kind === "command") &&
325
+ !params.networkApprovalContext &&
326
+ !params.additionalPermissions;
327
+ return plain ? { rule: params.command as string } : null;
328
+ }
329
+ if (method === "item/fileChange/requestApproval")
330
+ return params.grantRoot ? null : { rule: "changes to these files" };
331
+ return null;
332
+ }