stitchkit 0.128.0 → 0.130.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/agent-executor/acp/v1-connect.d.ts +87 -19
  3. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  4. package/dist/agent-executor/acp/v1-driver.d.ts +4 -2
  5. package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
  6. package/dist/agent-executor/acp/v1-handlers.d.ts +56 -0
  7. package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -0
  8. package/dist/agent-executor/acp/v1-map.d.ts +13 -2
  9. package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
  10. package/dist/agent-executor/acp/v1-permission.d.ts +44 -0
  11. package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -0
  12. package/dist/agent-executor/acp/v1-protocol.d.ts +63 -10
  13. package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
  14. package/dist/agent-executor/acp/v1-session.d.ts +34 -7
  15. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  16. package/dist/agent-executor/acp/v1-turn.d.ts +51 -13
  17. package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
  18. package/dist/agent-executor/claude/classify.d.ts +10 -0
  19. package/dist/agent-executor/claude/classify.d.ts.map +1 -1
  20. package/dist/agent-executor/claude/cli-driver.d.ts +4 -1
  21. package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
  22. package/dist/agent-executor/claude/events.d.ts +146 -0
  23. package/dist/agent-executor/claude/events.d.ts.map +1 -0
  24. package/dist/agent-executor/claude/limits.d.ts +7 -1
  25. package/dist/agent-executor/claude/limits.d.ts.map +1 -1
  26. package/dist/agent-executor/claude/protocol.d.ts +49 -9
  27. package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
  28. package/dist/agent-executor/claude/session.d.ts +2 -0
  29. package/dist/agent-executor/claude/session.d.ts.map +1 -1
  30. package/dist/agent-executor/claude/transcript.d.ts +2 -2
  31. package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
  32. package/dist/agent-executor/claude-sdk/controls.d.ts +28 -0
  33. package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -0
  34. package/dist/agent-executor/claude-sdk/driver.d.ts +208 -4
  35. package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
  36. package/dist/agent-executor/claude-sdk/probe.d.ts +29 -0
  37. package/dist/agent-executor/claude-sdk/probe.d.ts.map +1 -0
  38. package/dist/agent-executor/claude-sdk/query-loop.d.ts +94 -0
  39. package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -0
  40. package/dist/agent-executor/claude-sdk/query-options.d.ts +29 -0
  41. package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -0
  42. package/dist/agent-executor/claude-sdk/session.d.ts +5 -5
  43. package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
  44. package/dist/agent-executor/claude-sdk/turn-usage.d.ts +81 -0
  45. package/dist/agent-executor/claude-sdk/turn-usage.d.ts.map +1 -0
  46. package/dist/agent-executor/codex/classify.d.ts +4 -0
  47. package/dist/agent-executor/codex/classify.d.ts.map +1 -1
  48. package/dist/agent-executor/codex/connect.d.ts +46 -0
  49. package/dist/agent-executor/codex/connect.d.ts.map +1 -0
  50. package/dist/agent-executor/codex/control-client.d.ts +168 -0
  51. package/dist/agent-executor/codex/control-client.d.ts.map +1 -0
  52. package/dist/agent-executor/codex/driver.d.ts +71 -10
  53. package/dist/agent-executor/codex/driver.d.ts.map +1 -1
  54. package/dist/agent-executor/codex/handlers.d.ts +47 -0
  55. package/dist/agent-executor/codex/handlers.d.ts.map +1 -0
  56. package/dist/agent-executor/codex/limits.d.ts +11 -2
  57. package/dist/agent-executor/codex/limits.d.ts.map +1 -1
  58. package/dist/agent-executor/codex/protocol.d.ts +173 -4
  59. package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
  60. package/dist/agent-executor/codex/request-answers.d.ts +101 -0
  61. package/dist/agent-executor/codex/request-answers.d.ts.map +1 -0
  62. package/dist/agent-executor/codex/session-controls.d.ts +195 -0
  63. package/dist/agent-executor/codex/session-controls.d.ts.map +1 -0
  64. package/dist/agent-executor/codex/session.d.ts +55 -37
  65. package/dist/agent-executor/codex/session.d.ts.map +1 -1
  66. package/dist/agent-executor/codex/shared-server.d.ts +29 -0
  67. package/dist/agent-executor/codex/shared-server.d.ts.map +1 -0
  68. package/dist/agent-executor/codex/shared-thread.d.ts +46 -0
  69. package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -0
  70. package/dist/agent-executor/codex/thread-controls.d.ts +128 -0
  71. package/dist/agent-executor/codex/thread-controls.d.ts.map +1 -0
  72. package/dist/agent-executor/codex/turn-input.d.ts +30 -0
  73. package/dist/agent-executor/codex/turn-input.d.ts.map +1 -0
  74. package/dist/agent-executor/codex/unix-socket-target.d.ts +26 -0
  75. package/dist/agent-executor/codex/unix-socket-target.d.ts.map +1 -0
  76. package/dist/agent-executor/codex/unix-socket.d.ts +26 -0
  77. package/dist/agent-executor/codex/unix-socket.d.ts.map +1 -0
  78. package/dist/agent-executor/codex/ws-frame.d.ts +15 -0
  79. package/dist/agent-executor/codex/ws-frame.d.ts.map +1 -0
  80. package/dist/agent-executor/contract.d.ts +79 -0
  81. package/dist/agent-executor/contract.d.ts.map +1 -1
  82. package/dist/agent-executor/engine-process.d.ts +9 -0
  83. package/dist/agent-executor/engine-process.d.ts.map +1 -1
  84. package/dist/agent-executor/engine.d.ts +6 -2
  85. package/dist/agent-executor/engine.d.ts.map +1 -1
  86. package/dist/agent-executor/executor-contract.d.ts +54 -0
  87. package/dist/agent-executor/executor-contract.d.ts.map +1 -1
  88. package/dist/agent-executor/handoff-schemas.d.ts +407 -0
  89. package/dist/agent-executor/handoff-schemas.d.ts.map +1 -0
  90. package/dist/agent-executor/handoff.d.ts +12 -0
  91. package/dist/agent-executor/handoff.d.ts.map +1 -0
  92. package/dist/agent-executor/hello.d.ts +80 -0
  93. package/dist/agent-executor/hello.d.ts.map +1 -1
  94. package/dist/agent-executor/image-input.d.ts +22 -0
  95. package/dist/agent-executor/image-input.d.ts.map +1 -1
  96. package/dist/agent-executor/projection.d.ts +2 -2
  97. package/dist/agent-executor/projection.d.ts.map +1 -1
  98. package/dist/agent-executor/session-primitives.d.ts +10 -1
  99. package/dist/agent-executor/session-primitives.d.ts.map +1 -1
  100. package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
  101. package/dist/agent-executor/testing/replay-driver.d.ts +41 -0
  102. package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -0
  103. package/dist/agent-executor/testing/replay-gate.d.ts +11 -0
  104. package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -0
  105. package/dist/agent-executor/testing/replay-runner.d.ts +27 -0
  106. package/dist/agent-executor/testing/replay-runner.d.ts.map +1 -0
  107. package/dist/agent-executor/testing/replay-scenarios.d.ts +21 -0
  108. package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -0
  109. package/dist/agent-executor/testing/replay-transcript.d.ts +296 -0
  110. package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -0
  111. package/dist/agent-executor/vocabulary.d.ts +135 -0
  112. package/dist/agent-executor/vocabulary.d.ts.map +1 -1
  113. package/dist/agent-runtime/branch-observations.d.ts +5 -5
  114. package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -1
  115. package/dist/agent-runtime/sql-rows.d.ts +10 -10
  116. package/dist/agent-runtime/terminal-commit.d.ts +10 -10
  117. package/dist/entrypoints/agent-executor/acp.d.ts +4 -1
  118. package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
  119. package/dist/entrypoints/agent-executor/acp.js +852 -219
  120. package/dist/entrypoints/agent-executor/claude-sdk.d.ts +5 -1
  121. package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -1
  122. package/dist/entrypoints/agent-executor/claude-sdk.js +1075 -136
  123. package/dist/entrypoints/agent-executor/claude.js +48 -23
  124. package/dist/entrypoints/agent-executor/codex.d.ts +11 -0
  125. package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
  126. package/dist/entrypoints/agent-executor/codex.js +3067 -388
  127. package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
  128. package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
  129. package/dist/entrypoints/agent-executor/testing.js +1002 -2
  130. package/dist/entrypoints/agent-executor.d.ts +4 -2
  131. package/dist/entrypoints/agent-executor.d.ts.map +1 -1
  132. package/dist/entrypoints/agent-executor.js +416 -28
  133. package/dist/entrypoints/agent-runtime/browser.js +1 -1
  134. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
  135. package/dist/entrypoints/agent-runtime/harness.js +8 -8
  136. package/dist/entrypoints/agent-runtime/openrouter.js +2 -2
  137. package/dist/entrypoints/agent-runtime/postgres.js +6 -6
  138. package/dist/entrypoints/agent-runtime/realtime.js +4 -4
  139. package/dist/entrypoints/agent-runtime/sandbox.js +5 -5
  140. package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
  141. package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
  142. package/dist/entrypoints/agent-runtime/testing.js +5 -5
  143. package/dist/entrypoints/agent-runtime.js +21 -40
  144. package/dist/entrypoints/application/directory-inbox.js +2 -2
  145. package/dist/entrypoints/application/opentelemetry.js +2 -2
  146. package/dist/entrypoints/application.js +2 -2
  147. package/dist/entrypoints/cli/publish.js +3 -3
  148. package/dist/entrypoints/cli.js +8 -8
  149. package/dist/entrypoints/contract.js +2 -2
  150. package/dist/entrypoints/files/packaging.js +2 -2
  151. package/dist/entrypoints/files.js +7 -7
  152. package/dist/entrypoints/handler.js +4 -4
  153. package/dist/entrypoints/http.js +5 -5
  154. package/dist/entrypoints/index.js +7 -7
  155. package/dist/entrypoints/node.js +5 -5
  156. package/dist/entrypoints/observability.js +4 -4
  157. package/dist/entrypoints/primitives.js +2 -2
  158. package/dist/entrypoints/process.js +5 -5
  159. package/dist/entrypoints/react.js +1 -1
  160. package/dist/entrypoints/remote.js +2 -2
  161. package/dist/entrypoints/server.js +6 -6
  162. package/dist/entrypoints/service-host/macos.js +5 -5
  163. package/dist/entrypoints/service-host.js +7 -7
  164. package/dist/entrypoints/spend.js +1 -1
  165. package/dist/entrypoints/sync/postgres.js +1 -1
  166. package/dist/entrypoints/sync.js +2 -2
  167. package/dist/entrypoints/telegram.js +2 -2
  168. package/dist/entrypoints/testing.js +5 -5
  169. package/dist/entrypoints/tools/agent.js +5 -5
  170. package/dist/entrypoints/tools/connections.js +2 -2
  171. package/dist/entrypoints/tools/invoker.js +4 -4
  172. package/dist/entrypoints/tools/mcp.d.ts +1 -0
  173. package/dist/entrypoints/tools/mcp.d.ts.map +1 -1
  174. package/dist/entrypoints/tools/mcp.js +5 -5
  175. package/dist/entrypoints/tools/toolkit.js +8 -8
  176. package/dist/entrypoints/tools.js +12 -12
  177. package/dist/entrypoints/tracking/contract.js +1 -1
  178. package/dist/entrypoints/xlsx.js +1 -1
  179. package/dist/{index-prf6ayhf.js → index-13wmzpa6.js} +1 -1
  180. package/dist/{index-n7f89hjw.js → index-17qgm6xe.js} +3 -3
  181. package/dist/{index-wv8dqy7q.js → index-205456mf.js} +1 -1
  182. package/dist/{index-pwskmywy.js → index-21cfxc4z.js} +1 -1
  183. package/dist/{index-13dnv6d0.js → index-2s8sy57y.js} +37 -104
  184. package/dist/{index-d4svrknj.js → index-39c2hj6h.js} +2 -2
  185. package/dist/{index-sfzfd2m2.js → index-39rmc00v.js} +1 -1
  186. package/dist/{index-ky3ardqn.js → index-3fym4j8n.js} +1 -1
  187. package/dist/{index-c5gp2gh6.js → index-5tdc0q43.js} +1 -1
  188. package/dist/{index-3ypvpkwr.js → index-669374qc.js} +1 -1
  189. package/dist/{index-5jyjb4s0.js → index-80acsm27.js} +1 -1
  190. package/dist/{index-xmr47znh.js → index-827bgv33.js} +1 -1
  191. package/dist/{index-v1mxss62.js → index-93n6jwy0.js} +3 -3
  192. package/dist/{index-d54npte7.js → index-9kpxz49v.js} +2 -2
  193. package/dist/{index-xv9jb84s.js → index-9sfhje6y.js} +3 -3
  194. package/dist/{index-9y0afd5f.js → index-apf5g7y9.js} +1 -1
  195. package/dist/{index-bh4pmtr9.js → index-dbp6xemn.js} +78 -8
  196. package/dist/{index-g3e57qj6.js → index-dcsxj68j.js} +2 -2
  197. package/dist/{index-waa6t4zx.js → index-dnzxxf8a.js} +1 -1
  198. package/dist/{index-gf92hc87.js → index-fgahdc7s.js} +2 -2
  199. package/dist/{index-kzavdze2.js → index-gr0kxymw.js} +5 -1
  200. package/dist/{index-e06z0tkb.js → index-gya4hwh3.js} +2 -2
  201. package/dist/{index-gzny6zsw.js → index-hab790s6.js} +5 -5
  202. package/dist/{index-bz3gn6cs.js → index-j0ef04jw.js} +2 -2
  203. package/dist/{index-rhb33thr.js → index-jcge9tx3.js} +1 -1
  204. package/dist/{index-4qvyhn23.js → index-jrn3prgm.js} +1 -1
  205. package/dist/index-kne9g2c5.js +30 -0
  206. package/dist/{index-pn5b11ce.js → index-mkfhpk11.js} +1 -1
  207. package/dist/{index-1qwrczr1.js → index-mttkdm5a.js} +1 -1
  208. package/dist/{index-rxnyygke.js → index-n3bm7zqq.js} +1 -1
  209. package/dist/{index-6wp4dn9d.js → index-p06z7g7w.js} +3 -3
  210. package/dist/{index-kt6dh1n6.js → index-p16q492v.js} +1 -1
  211. package/dist/index-p1qmpq0p.js +1300 -0
  212. package/dist/{index-t7wa7k12.js → index-pp97q86a.js} +1 -1
  213. package/dist/{index-39n02e0q.js → index-psye60qn.js} +1 -1
  214. package/dist/{index-5ptwb6ka.js → index-pzhqydxb.js} +1 -1
  215. package/dist/{index-7kfcb576.js → index-qa2jjb65.js} +1 -1
  216. package/dist/{index-rzeezh79.js → index-qhjmmsm2.js} +2 -2
  217. package/dist/{index-7grgs8cx.js → index-qpzyahe3.js} +2 -2
  218. package/dist/{index-jfecdk1e.js → index-r97ppg0g.js} +2 -2
  219. package/dist/{index-bmaz3jzy.js → index-rjs94dny.js} +1 -1
  220. package/dist/{index-5v5vg85s.js → index-rxh3qy4x.js} +32 -5
  221. package/dist/{index-en8e5zsj.js → index-ryxb427v.js} +1 -1
  222. package/dist/{index-y065r8g5.js → index-sd4e5x5j.js} +7 -7
  223. package/dist/{index-g56ht6qf.js → index-t3qcac2a.js} +1 -1
  224. package/dist/{index-m18xm96h.js → index-v759mzed.js} +156 -6
  225. package/dist/{index-4j8efqr3.js → index-x2fb37t0.js} +2 -2
  226. package/dist/{index-cbhxhma2.js → index-x5ayy5bn.js} +1 -0
  227. package/dist/index-y0a4gt1s.js +142 -0
  228. package/dist/{index-wavv538x.js → index-ybdq8kk2.js} +3 -3
  229. package/dist/{index-4gk6k3zc.js → index-ycr4pk0z.js} +1 -1
  230. package/dist/{index-0tyt97nk.js → index-yrr3n391.js} +1 -1
  231. package/dist/{index-v37b2cd6.js → index-z20pdxeb.js} +2 -2
  232. package/dist/{index-8x22nprv.js → index-z9d74jmb.js} +3 -3
  233. package/dist/{index-3tnwtz38.js → index-zhshhxew.js} +1 -1
  234. package/dist/{index-hj1zq7mh.js → index-znd1b57f.js} +3 -3
  235. package/dist/internal/positive-integer.d.ts +2 -0
  236. package/dist/internal/positive-integer.d.ts.map +1 -1
  237. package/dist/internal/unix-socket.d.ts +7 -0
  238. package/dist/internal/unix-socket.d.ts.map +1 -1
  239. package/dist/tools/internal/rank-tools.d.ts +10 -0
  240. package/dist/tools/internal/rank-tools.d.ts.map +1 -0
  241. package/dist/tools/mcp/handler.d.ts +7 -3
  242. package/dist/tools/mcp/handler.d.ts.map +1 -1
  243. package/dist/tools/mcp/lazy-discovery.d.ts +47 -0
  244. package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -0
  245. package/dist/tools/mcp/mount.d.ts +7 -0
  246. package/dist/tools/mcp/mount.d.ts.map +1 -1
  247. package/dist/tools/mcp/register.d.ts +2 -2
  248. package/dist/tools/mcp/register.d.ts.map +1 -1
  249. package/llms/agent-executor-acp.txt +7 -8
  250. package/llms/agent-executor-claude-sdk.txt +15 -10
  251. package/llms/agent-executor-claude.txt +1 -1
  252. package/llms/agent-executor-codex.txt +13 -3
  253. package/llms/agent-executor-testing.txt +5 -1
  254. package/llms/agent-executor.txt +9 -8
  255. package/llms/stitchkit.txt +74 -74
  256. package/llms/tools-mcp.txt +3 -2
  257. package/llms/tools.txt +24 -0
  258. package/llms/{upgrading-0.128.0.txt → upgrading-0.128.0-0.130.0.txt} +58 -3
  259. package/llms/upgrading.txt +1 -1
  260. package/llms-full.txt +206 -107
  261. package/llms.txt +10 -10
  262. package/package.json +1 -1
  263. package/dist/index-0gqs8ght.js +0 -558
@@ -1,558 +0,0 @@
1
- import {
2
- PlanWindowSchema2,
3
- engineProfile
4
- } from "./index-bh4pmtr9.js";
5
- import {
6
- nonEmptyString,
7
- epochSecondsToIso,
8
- safeJsonValue,
9
- isSupportedImageMediaType
10
- } from "./index-13dnv6d0.js";
11
- import {
12
- errnoOf
13
- } from "./index-jj9228tt.js";
14
-
15
- // src/agent-executor/claude/protocol.ts
16
- import { z } from "zod";
17
- var TextBlock = z.looseObject({ type: z.literal("text"), text: z.string() });
18
- var ThinkingBlock = z.looseObject({
19
- type: z.literal("thinking"),
20
- thinking: z.string().optional()
21
- });
22
- var ToolUseBlock = z.looseObject({
23
- type: z.literal("tool_use"),
24
- id: z.string().min(1),
25
- name: z.string().min(1),
26
- input: z.json()
27
- });
28
- var ToolResultBlock = z.looseObject({
29
- type: z.literal("tool_result"),
30
- tool_use_id: z.string().min(1),
31
- content: z.json().optional(),
32
- is_error: z.boolean().optional()
33
- });
34
- var OtherBlock = z.looseObject({ type: z.string() });
35
- var ClaudeContentBlockSchema = z.union([
36
- TextBlock,
37
- ThinkingBlock,
38
- ToolUseBlock,
39
- ToolResultBlock,
40
- OtherBlock
41
- ]);
42
- var Usage = z.looseObject({
43
- input_tokens: z.int().nonnegative().optional(),
44
- output_tokens: z.int().nonnegative().optional(),
45
- cache_read_input_tokens: z.int().nonnegative().optional()
46
- });
47
- var ClaudeRecordSchema = z.discriminatedUnion("type", [
48
- z.looseObject({
49
- type: z.literal("system"),
50
- subtype: z.string(),
51
- session_id: z.string().optional(),
52
- model: z.string().optional()
53
- }),
54
- z.looseObject({
55
- type: z.literal("user"),
56
- uuid: z.string().optional(),
57
- isReplay: z.boolean().optional(),
58
- message: z.looseObject({
59
- content: z.union([z.string(), z.array(ClaudeContentBlockSchema)])
60
- })
61
- }),
62
- z.looseObject({
63
- type: z.literal("assistant"),
64
- message: z.looseObject({
65
- id: z.string().min(1),
66
- content: z.array(ClaudeContentBlockSchema)
67
- })
68
- }),
69
- z.looseObject({
70
- type: z.literal("stream_event"),
71
- api_message_id: z.string().optional(),
72
- event: z.looseObject({
73
- type: z.string(),
74
- index: z.int().nonnegative().optional(),
75
- delta: z.union([
76
- z.looseObject({ type: z.literal("text_delta"), text: z.string() }),
77
- z.looseObject({ type: z.literal("thinking_delta"), thinking: z.string() }),
78
- z.looseObject({ type: z.string().optional() })
79
- ]).optional(),
80
- message: z.looseObject({ id: z.string().optional() }).optional()
81
- })
82
- }),
83
- z.looseObject({
84
- type: z.literal("result"),
85
- subtype: z.string(),
86
- is_error: z.boolean(),
87
- session_id: z.string().optional(),
88
- terminal_reason: z.string().optional(),
89
- api_error_status: z.union([z.int(), z.string()]).nullable().optional(),
90
- result: z.string().optional(),
91
- total_cost_usd: z.number().nonnegative().optional(),
92
- usage: Usage.optional()
93
- }),
94
- z.looseObject({ type: z.literal("rate_limit_event"), rate_limit_info: z.looseObject({}) }),
95
- z.looseObject({
96
- type: z.literal("control_request"),
97
- request_id: z.string().min(1),
98
- request: z.looseObject({
99
- subtype: z.string(),
100
- tool_name: z.string().optional(),
101
- input: z.json().optional(),
102
- tool_use_id: z.string().optional()
103
- })
104
- }),
105
- z.looseObject({
106
- type: z.literal("control_response"),
107
- response: z.looseObject({ subtype: z.string(), request_id: z.string().optional() })
108
- }),
109
- z.looseObject({
110
- type: z.literal("command_lifecycle"),
111
- command_uuid: z.string().optional(),
112
- state: z.string()
113
- })
114
- ]);
115
- var ClaudeUnknownRecordSchema = z.looseObject({ type: z.string() });
116
- function claudeUserContent(parts) {
117
- if (parts.every((part) => part.type === "text")) {
118
- return parts.map((part) => part.text).join(`
119
- `);
120
- }
121
- return parts.map((part) => {
122
- if (part.type === "text")
123
- return { type: "text", text: part.text };
124
- if (!isSupportedImageMediaType(part.mediaType)) {
125
- throw new TypeError(`Unsupported Claude image media type: ${part.mediaType}`);
126
- }
127
- return {
128
- type: "image",
129
- source: { type: "base64", media_type: part.mediaType, data: part.base64 }
130
- };
131
- });
132
- }
133
- function claudeUserMessage(input) {
134
- return {
135
- type: "user",
136
- message: { role: "user", content: input.content },
137
- uuid: input.clientId,
138
- parent_tool_use_id: null,
139
- session_id: input.sessionId
140
- };
141
- }
142
- function claudePermissionResponse(requestId, decision) {
143
- return {
144
- type: "control_response",
145
- response: {
146
- subtype: "success",
147
- request_id: requestId,
148
- response: decision.behavior === "allow" ? { behavior: "allow", updatedInput: decision.input } : { behavior: "deny", message: decision.message }
149
- }
150
- };
151
- }
152
- function claudeControlError(requestId, error) {
153
- return {
154
- type: "control_response",
155
- response: { subtype: "error", request_id: requestId, error }
156
- };
157
- }
158
- function claudeInterrupt(requestId) {
159
- return { type: "control_request", request_id: requestId, request: { subtype: "interrupt" } };
160
- }
161
-
162
- // src/agent-executor/claude/classify.ts
163
- function newClaudeTurnState(turnId) {
164
- return { turnId, toolNames: new Map, interruptRequested: false };
165
- }
166
- var QUIET_SYSTEM = new Set([
167
- "hook_started",
168
- "hook_response",
169
- "status",
170
- "thinking_tokens",
171
- "compact_boundary",
172
- "api_retry"
173
- ]);
174
- var QUIET_STREAM = new Set([
175
- "message_start",
176
- "message_delta",
177
- "message_stop",
178
- "content_block_start",
179
- "content_block_stop"
180
- ]);
181
- function raw(type, subtype) {
182
- return { source: "claude", type: subtype === undefined ? type : `${type}/${subtype}` };
183
- }
184
- function unhandled(state, type, subtype) {
185
- return {
186
- kind: "unhandled",
187
- delta: {
188
- type: "error",
189
- turnId: state.turnId,
190
- itemId: `unhandled:${type}${subtype === undefined ? "" : `/${subtype}`}`,
191
- raw: raw(type, subtype),
192
- kind: "unhandled",
193
- message: `Claude record ${type}${subtype === undefined ? "" : `/${subtype}`} is not known to this driver`
194
- }
195
- };
196
- }
197
- function failureKind(status) {
198
- const code = Number(status);
199
- if (code === 401 || code === 403)
200
- return "authRequired";
201
- if (code === 429)
202
- return "rateLimited";
203
- return "restartRecommended";
204
- }
205
- function outcomeOf(record, state) {
206
- if (state.interruptRequested)
207
- return "interrupted";
208
- return record.is_error ? "failed" : "completed";
209
- }
210
- function classifyClaudeRecord(value, state) {
211
- const parsed = ClaudeRecordSchema.safeParse(value);
212
- if (!parsed.success) {
213
- const shape = ClaudeUnknownRecordSchema.safeParse(value);
214
- return unhandled(state, shape.success ? shape.data.type : "invalid");
215
- }
216
- const record = parsed.data;
217
- switch (record.type) {
218
- case "system":
219
- if (record.subtype === "init" && record.session_id !== undefined) {
220
- return {
221
- kind: "session",
222
- sessionId: record.session_id,
223
- ...record.model !== undefined && { model: record.model }
224
- };
225
- }
226
- return QUIET_SYSTEM.has(record.subtype) ? { kind: "ignore", reason: `system/${record.subtype}` } : unhandled(state, "system", record.subtype);
227
- case "user": {
228
- if (record.isReplay)
229
- return { kind: "ignore", reason: "the echo of the input" };
230
- const content = record.message.content;
231
- if (typeof content === "string")
232
- return { kind: "ignore", reason: "a note the CLI addressed to itself" };
233
- const deltas = [];
234
- content.forEach((block, index) => {
235
- if (block.type !== "tool_result" || !("tool_use_id" in block))
236
- return;
237
- const callId = nonEmptyString(block.tool_use_id) ?? `result-${index}`;
238
- deltas.push({
239
- type: "tool-result",
240
- turnId: state.turnId,
241
- itemId: `result:${callId}`,
242
- raw: raw("user", "tool_result"),
243
- callId,
244
- toolName: state.toolNames.get(callId) ?? "unknown",
245
- outcome: "is_error" in block && block.is_error === true ? "error" : "success",
246
- ..."content" in block && block.content !== undefined && {
247
- output: safeJsonValue(block.content)
248
- }
249
- });
250
- });
251
- return { kind: "deltas", deltas };
252
- }
253
- case "assistant": {
254
- const deltas = [];
255
- record.message.content.forEach((block, index) => {
256
- if (block.type !== "tool_use" || !("id" in block) || !("name" in block))
257
- return;
258
- const itemId = `${record.message.id}:${index}`;
259
- const callId = nonEmptyString(block.id) ?? itemId;
260
- const toolName = nonEmptyString(block.name) ?? "unknown";
261
- state.toolNames.set(callId, toolName);
262
- deltas.push({
263
- type: "tool-call",
264
- turnId: state.turnId,
265
- itemId,
266
- raw: raw("assistant", "tool_use"),
267
- callId,
268
- toolName,
269
- input: safeJsonValue("input" in block && block.input !== undefined ? block.input : null)
270
- });
271
- });
272
- return { kind: "deltas", deltas };
273
- }
274
- case "stream_event": {
275
- const event = record.event;
276
- if (event.type === "content_block_delta" && event.delta !== undefined) {
277
- const itemId = `${record.api_message_id ?? "message"}:${event.index ?? 0}`;
278
- const delta = event.delta;
279
- if (delta.type === "text_delta" && "text" in delta) {
280
- return {
281
- kind: "deltas",
282
- deltas: [
283
- {
284
- type: "text",
285
- turnId: state.turnId,
286
- itemId,
287
- raw: raw("stream_event", "text_delta"),
288
- text: String(delta.text)
289
- }
290
- ]
291
- };
292
- }
293
- if (delta.type === "thinking_delta" && "thinking" in delta) {
294
- return {
295
- kind: "deltas",
296
- deltas: [
297
- {
298
- type: "reasoning",
299
- turnId: state.turnId,
300
- itemId,
301
- raw: raw("stream_event", "thinking_delta"),
302
- text: String(delta.thinking)
303
- }
304
- ]
305
- };
306
- }
307
- return {
308
- kind: "ignore",
309
- reason: `stream_event/${delta.type}: arrives in the final message`
310
- };
311
- }
312
- return QUIET_STREAM.has(event.type) ? { kind: "ignore", reason: `stream_event/${event.type}` } : unhandled(state, "stream_event", event.type);
313
- }
314
- case "result": {
315
- const outcome = outcomeOf(record, state);
316
- const usage = record.usage;
317
- const deltas = [
318
- {
319
- type: "usage",
320
- turnId: state.turnId,
321
- itemId: "usage",
322
- raw: raw("result", record.subtype),
323
- ...usage?.input_tokens !== undefined && { inputTokens: usage.input_tokens },
324
- ...usage?.output_tokens !== undefined && { outputTokens: usage.output_tokens },
325
- ...usage?.cache_read_input_tokens !== undefined && {
326
- cachedInputTokens: usage.cache_read_input_tokens
327
- },
328
- ...record.total_cost_usd !== undefined && { costUsd: record.total_cost_usd }
329
- }
330
- ];
331
- if (outcome === "failed") {
332
- deltas.push({
333
- type: "error",
334
- turnId: state.turnId,
335
- itemId: "failure",
336
- raw: raw("result", record.subtype),
337
- kind: failureKind(record.api_error_status),
338
- message: record.result?.trim() || `Claude ended the turn with ${record.subtype}`
339
- });
340
- }
341
- deltas.push({
342
- type: "turn-end",
343
- turnId: state.turnId,
344
- itemId: "end",
345
- raw: raw("result", record.subtype),
346
- outcome
347
- });
348
- return { kind: "end", deltas, outcome };
349
- }
350
- case "rate_limit_event":
351
- return { kind: "limits", info: record.rate_limit_info };
352
- case "control_request": {
353
- const request = record.request;
354
- if (request.subtype !== "can_use_tool" || request.tool_name === undefined) {
355
- return {
356
- ...unhandled(state, "control_request", request.subtype),
357
- refuse: {
358
- requestId: record.request_id,
359
- message: `Claude control request ${request.subtype} is not known to this driver`
360
- }
361
- };
362
- }
363
- const callId = nonEmptyString(request.tool_use_id);
364
- return {
365
- kind: "request",
366
- input: request.input ?? null,
367
- delta: {
368
- type: "request",
369
- turnId: state.turnId,
370
- itemId: `request:${record.request_id}`,
371
- raw: raw("control_request", "can_use_tool"),
372
- interactionId: record.request_id,
373
- kind: "approval",
374
- toolName: nonEmptyString(request.tool_name) ?? "tool",
375
- ...callId !== undefined && { callId },
376
- ...request.input !== undefined && { input: request.input }
377
- }
378
- };
379
- }
380
- case "control_response":
381
- return { kind: "ignore", reason: "the answer to a request the executor sent" };
382
- case "command_lifecycle":
383
- return { kind: "ignore", reason: `the input's own lifecycle (${record.state})` };
384
- }
385
- }
386
-
387
- // src/agent-executor/claude/limits.ts
388
- import { z as z2 } from "zod";
389
- var ClaudeWindowSchema = z2.looseObject({
390
- utilization: z2.number().min(0),
391
- resetsAt: z2.number().positive().optional()
392
- });
393
- var ClaudeRateLimitInfoSchema = z2.looseObject({
394
- rateLimitType: z2.string().optional(),
395
- utilization: z2.number().min(0).optional(),
396
- resetsAt: z2.number().positive().optional(),
397
- unifiedWindows: z2.record(z2.string(), ClaudeWindowSchema).optional()
398
- });
399
- function claudePlanWindows2(info) {
400
- const parsed = ClaudeRateLimitInfoSchema.safeParse(info);
401
- if (!parsed.success)
402
- return [];
403
- const toWindow = (name, value) => {
404
- const resetsAt = epochSecondsToIso(value.resetsAt);
405
- return PlanWindowSchema2.parse({
406
- name,
407
- usedPercent: Math.min(100, value.utilization * 100),
408
- ...resetsAt !== undefined && { resetsAt }
409
- });
410
- };
411
- const { unifiedWindows, rateLimitType, utilization, resetsAt } = parsed.data;
412
- if (unifiedWindows !== undefined) {
413
- return Object.entries(unifiedWindows).flatMap(([name, value]) => nonEmptyString(name) !== undefined ? [toWindow(name, value)] : []);
414
- }
415
- const singleName = nonEmptyString(rateLimitType);
416
- if (singleName !== undefined && utilization !== undefined) {
417
- return [
418
- toWindow(singleName, { utilization, ...resetsAt !== undefined && { resetsAt } })
419
- ];
420
- }
421
- return [];
422
- }
423
-
424
- // src/agent-executor/claude/transcript.ts
425
- import { open } from "node:fs/promises";
426
- import { join } from "node:path";
427
- var SAFE_SESSION_ID = /^[A-Za-z0-9_-]+$/;
428
- function claudeTranscriptPath2(input) {
429
- if (!SAFE_SESSION_ID.test(input.sessionId)) {
430
- throw new TypeError(`Invalid Claude sessionId: ${input.sessionId}`);
431
- }
432
- return join(input.home, "projects", input.cwd.replace(/[^A-Za-z0-9-]/g, "-"), `${input.sessionId}.jsonl`);
433
- }
434
- var MAX_RECORD_BYTES = 16 * 1024 * 1024;
435
- var INITIAL_RECORD_BYTES = 64 * 1024;
436
- var READ_CHUNK_BYTES = 64 * 1024;
437
- var UTF8_STRICT = new TextDecoder("utf-8", { fatal: true });
438
- function classifyTranscriptLine(bytes, uuid) {
439
- const end = bytes.length > 0 && bytes[bytes.length - 1] === 13 ? bytes.length - 1 : bytes.length;
440
- if (end === 0)
441
- return "other";
442
- let record;
443
- try {
444
- record = JSON.parse(UTF8_STRICT.decode(bytes.subarray(0, end)));
445
- } catch {
446
- return "invalid";
447
- }
448
- if (typeof record !== "object" || record === null || Array.isArray(record))
449
- return "invalid";
450
- if (Reflect.get(record, "type") !== "user")
451
- return "other";
452
- const recordUuid = Reflect.get(record, "uuid");
453
- if (typeof recordUuid !== "string")
454
- return "invalid";
455
- return recordUuid === uuid ? "match" : "other";
456
- }
457
- async function claudeTranscriptHasUuid(path, uuid) {
458
- let handle;
459
- try {
460
- handle = await open(path, "r");
461
- } catch (error) {
462
- if (errnoOf(error) === "ENOENT")
463
- return false;
464
- throw error;
465
- }
466
- try {
467
- const chunk = new Uint8Array(READ_CHUNK_BYTES);
468
- let lineBuf = new Uint8Array(INITIAL_RECORD_BYTES);
469
- let lineLen = 0;
470
- let lineOverflow = false;
471
- let lineNumber = 1;
472
- let problem;
473
- const appendSlice = (src, start, end) => {
474
- if (lineOverflow || end <= start)
475
- return;
476
- const add = end - start;
477
- const needed = lineLen + add;
478
- if (needed > MAX_RECORD_BYTES) {
479
- lineOverflow = true;
480
- lineLen = 0;
481
- return;
482
- }
483
- if (needed > lineBuf.length) {
484
- let nextCap = lineBuf.length;
485
- while (nextCap < needed)
486
- nextCap = Math.min(MAX_RECORD_BYTES, nextCap * 2);
487
- const grown = new Uint8Array(nextCap);
488
- grown.set(lineBuf.subarray(0, lineLen));
489
- lineBuf = grown;
490
- }
491
- lineBuf.set(src.subarray(start, end), lineLen);
492
- lineLen = needed;
493
- };
494
- const finishLine = () => {
495
- const currentLine = lineNumber;
496
- lineNumber += 1;
497
- if (lineOverflow) {
498
- problem ??= `line ${currentLine} exceeds the ${MAX_RECORD_BYTES}-byte record limit`;
499
- lineOverflow = false;
500
- lineLen = 0;
501
- return false;
502
- }
503
- const verdict = classifyTranscriptLine(lineBuf.subarray(0, lineLen), uuid);
504
- lineLen = 0;
505
- if (verdict === "match")
506
- return true;
507
- if (verdict === "invalid") {
508
- problem ??= `line ${currentLine} could not be parsed as a valid transcript record`;
509
- }
510
- return false;
511
- };
512
- for (;; ) {
513
- const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
514
- if (bytesRead === 0)
515
- break;
516
- let start = 0;
517
- for (let i = 0;i < bytesRead; i += 1) {
518
- if (chunk[i] === 10) {
519
- appendSlice(chunk, start, i);
520
- if (finishLine())
521
- return true;
522
- start = i + 1;
523
- }
524
- }
525
- appendSlice(chunk, start, bytesRead);
526
- }
527
- if ((lineLen > 0 || lineOverflow) && finishLine())
528
- return true;
529
- if (problem !== undefined) {
530
- throw new Error(`Claude transcript ${path} could not prove absence of input: ${problem}`);
531
- }
532
- return false;
533
- } finally {
534
- await handle.close();
535
- }
536
- }
537
- async function claudeTranscriptExists(path) {
538
- let handle;
539
- try {
540
- handle = await open(path, "r");
541
- } catch (error) {
542
- if (errnoOf(error) === "ENOENT")
543
- return false;
544
- throw error;
545
- }
546
- await handle.close();
547
- return true;
548
- }
549
- async function findTranscriptInput(engine, input) {
550
- const profile = engineProfile(engine, input.profile);
551
- return claudeTranscriptHasUuid(claudeTranscriptPath2({
552
- home: profile.home,
553
- cwd: input.cwd,
554
- sessionId: input.nativeThreadId
555
- }), input.clientId);
556
- }
557
-
558
- export { claudeUserContent, claudeUserMessage, claudePermissionResponse, claudeControlError, claudeInterrupt, newClaudeTurnState, classifyClaudeRecord, claudePlanWindows2, claudeTranscriptPath2, claudeTranscriptExists, findTranscriptInput };