@zvada/agent-server 0.3.18 → 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 (572) hide show
  1. package/AGENTS.md +11 -26
  2. package/CHANGELOG.md +1005 -1
  3. package/README.md +35 -39
  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 +452 -53
  381. package/docs/deploy.md +218 -47
  382. package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
  383. package/docs/feedback.md +116 -0
  384. package/docs/harnesses.md +212 -88
  385. package/docs/sync-history.md +29 -13
  386. package/docs/sync-integration.md +52 -66
  387. package/package.json +43 -25
  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 +604 -670
  395. package/src/client/connection.ts +371 -0
  396. package/src/client/history.ts +29 -52
  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 +58 -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 +9 -33
  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 +327 -498
  485. package/src/core/runtime/event-processor.ts +197 -70
  486. package/src/core/runtime/harness-clis.ts +61 -0
  487. package/src/core/runtime/harness-logins.ts +328 -0
  488. package/src/core/runtime/login-reads.ts +78 -0
  489. package/src/core/runtime/model-lists.ts +33 -48
  490. package/src/core/runtime/permission-policy.ts +113 -0
  491. package/src/core/runtime/request-broker.ts +204 -0
  492. package/src/core/runtime/steering.ts +112 -0
  493. package/src/core/runtime/turn-outcome.ts +30 -0
  494. package/src/core/runtime/turn.ts +360 -0
  495. package/src/core/utils/bounded.ts +12 -0
  496. package/src/core/utils/deadline.ts +38 -0
  497. package/src/core/utils/errors.ts +113 -21
  498. package/src/core/utils/is-record.ts +4 -0
  499. package/src/core/utils/loopback.ts +10 -0
  500. package/src/protocol/account.ts +104 -0
  501. package/src/protocol/auth.ts +199 -0
  502. package/src/protocol/canonical.ts +16 -0
  503. package/src/protocol/clis.ts +69 -0
  504. package/src/protocol/config.ts +60 -6
  505. package/src/protocol/conversation.ts +272 -0
  506. package/src/protocol/credentials.ts +145 -0
  507. package/src/protocol/errors.ts +78 -20
  508. package/src/protocol/execution.ts +5 -2
  509. package/src/protocol/factories.ts +55 -7
  510. package/src/protocol/guards.ts +55 -2
  511. package/src/protocol/harness.ts +56 -6
  512. package/src/protocol/history.ts +72 -64
  513. package/src/protocol/ids.ts +0 -12
  514. package/src/protocol/index.ts +9 -0
  515. package/src/protocol/lifecycle.ts +250 -79
  516. package/src/protocol/meta-keys.ts +17 -0
  517. package/src/protocol/meta.ts +3 -3
  518. package/src/protocol/models.ts +2 -43
  519. package/src/protocol/part-input.ts +2 -1
  520. package/src/protocol/parts.ts +12 -3
  521. package/src/protocol/reduce.ts +302 -413
  522. package/src/protocol/selectors.ts +1 -20
  523. package/src/protocol/seq-cursor.ts +14 -0
  524. package/src/protocol/stop-reasons.ts +1 -1
  525. package/src/protocol/thinking.ts +1 -30
  526. package/src/protocol/time.ts +2 -2
  527. package/src/protocol/tool-closure.ts +93 -0
  528. package/src/protocol/tool-state.ts +19 -4
  529. package/src/protocol/verify.ts +222 -92
  530. package/src/protocol/vocabulary.ts +21 -5
  531. package/src/protocol/wire-api.ts +232 -0
  532. package/src/protocol/wire.ts +351 -64
  533. package/src/server/acp/binding.ts +63 -103
  534. package/src/server/acp/session-records.ts +53 -0
  535. package/src/server/acp/translate.ts +129 -20
  536. package/src/server/agent-server.ts +223 -387
  537. package/src/server/bin.ts +280 -78
  538. package/src/server/feedback.ts +204 -14
  539. package/src/server/history.ts +116 -122
  540. package/src/server/index.ts +3 -8
  541. package/src/server/install.ts +107 -8
  542. package/src/server/open-parts.ts +95 -0
  543. package/src/server/routes.ts +391 -0
  544. package/src/server/secrets.ts +24 -0
  545. package/src/server/session-gate.ts +69 -0
  546. package/src/server/session-log.ts +14 -2
  547. package/src/server/session-store.ts +136 -72
  548. package/src/server/subscriptions.ts +232 -0
  549. package/src/server/transports.ts +125 -25
  550. package/src/server/wire-error.ts +31 -45
  551. package/src/sync/event-log.ts +31 -3
  552. package/src/sync/fit.ts +27 -11
  553. package/src/sync/history-reader.ts +10 -5
  554. package/src/sync/history-sqlite.ts +37 -42
  555. package/src/sync/history.ts +9 -15
  556. package/src/sync/index.ts +17 -5
  557. package/src/sync/journal-sqlite.ts +162 -76
  558. package/src/sync/journal.ts +91 -32
  559. package/src/sync/live-tails.ts +107 -0
  560. package/src/sync/projection.ts +35 -0
  561. package/src/sync/recovery.ts +80 -51
  562. package/src/sync/schema.ts +27 -6
  563. package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
  564. package/docs/rfds/0002-native-subagents.md +0 -197
  565. package/src/client/request.ts +0 -19
  566. package/src/core/agents/claude-code/generator-session.ts +0 -572
  567. package/src/core/agents/claude-code/session-manager.ts +0 -166
  568. package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
  569. package/src/core/agents/codex-items.ts +0 -149
  570. package/src/core/agents/codex-sdk/adapter.ts +0 -237
  571. package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
  572. package/src/core/agents/tool-meta.ts +0 -68
@@ -1,38 +1,38 @@
1
- import { randomBytes } from "node:crypto";
2
- import {
3
- type Stats,
4
- chmodSync,
5
- existsSync,
6
- lstatSync,
7
- mkdirSync,
8
- readFileSync,
9
- readdirSync,
10
- realpathSync,
11
- } from "node:fs";
12
- import { chmod, mkdir, readdir, rename, rm } from "node:fs/promises";
1
+ import { existsSync, lstatSync } from "node:fs";
13
2
  import { homedir } from "node:os";
14
- import { dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
15
- import { CliNotFoundError, CliProvisionError } from "../utils/errors.ts";
3
+ import { delimiter, dirname, join, resolve } from "node:path";
4
+ import { CliProvisionError } from "../utils/errors.ts";
5
+ import {
6
+ managedDirectory,
7
+ trustedBinary,
8
+ trustedBinaryIn,
9
+ trustedCacheDirectory,
10
+ } from "./cache-trust.ts";
11
+ import { markUsed, pruneCache } from "./cache-usage.ts";
12
+ import { type CliReleases, expectedBuild } from "./checksums.ts";
16
13
  import { extractTarGz } from "./extract.ts";
17
- import { DEFAULT_NPM_REGISTRY, downloadWithIntegrity, fetchDist } from "./npm.ts";
18
- import { type CliTool, DEFAULT_PINS } from "./pins.ts";
14
+ import { installBuild, noBinary } from "./install-build.ts";
19
15
  import {
20
- type PlatformInfo,
21
- claudePackageSuffix,
22
- codexPackageSuffix,
23
- detectPlatform,
24
- findOnPath,
25
- } from "./platform.ts";
16
+ DEFAULT_DOWNLOAD_TIMEOUTS,
17
+ DEFAULT_NPM_REGISTRY,
18
+ type DownloadTimeouts,
19
+ withoutSecrets,
20
+ } from "./npm.ts";
21
+ import { type PlatformInfo, detectPlatform } from "./platform.ts";
22
+ import { CLI_RELEASES } from "./releases.ts";
23
+ import { CLI_TOOLS, CLI_TOOL_SPECS, type CliTool, type ToolPackage, binaryIn } from "./tools.ts";
26
24
 
27
25
  /**
28
- * How CLIs are obtained (see DESIGN/README "CLI provisioning"):
29
- * - `auto` (default): explicit override → host install → managed cache →
30
- * download the pinned build. Zero-config everywhere, self-healing in bare
31
- * sandboxes, no download when the machine already has the CLI.
32
- * - `pinned`: override → managed cache → download. Never trusts host installs
33
- * — every process in a fleet runs the exact tested CLI build.
34
- * - `system`: override → host install only. Never downloads (air-gapped /
35
- * "my machine, my CLIs").
26
+ * How CLIs are obtained (see docs/deploy.md). Every mode starts with the
27
+ * operator's override, then the bundle folders:
28
+ * - `auto` (default): → host install (the build beside the installed Claude
29
+ * SDK, an installed `@openai/codex` package) → managed cache → download the
30
+ * pinned build. Zero-config everywhere, self-healing in bare sandboxes, no
31
+ * download when a lockfile already installed the CLI.
32
+ * - `pinned`: → managed cache → download. Never trusts host installs — every
33
+ * process in a fleet runs the exact tested CLI build.
34
+ * - `system`: → host install only (Codex's on `PATH` too; Claude's the SDK
35
+ * finds itself). Never downloads (air-gapped / "my machine, my CLIs").
36
36
  */
37
37
  export type ProvisionMode = "auto" | "pinned" | "system";
38
38
 
@@ -42,11 +42,16 @@ export interface ProvisionOptions {
42
42
  /**
43
43
  * Where managed CLIs live. Defaults to `$AGENT_SERVER_CACHE_DIR`, then
44
44
  * `$XDG_CACHE_HOME/agent-server/cli`, then `~/.cache/agent-server/cli`.
45
+ * A desktop app names a folder of its own, so removing it removes them.
45
46
  */
46
47
  cacheDir?: string;
47
48
  /** npm registry base URL. Defaults to `$AGENT_SERVER_NPM_REGISTRY`, then npmjs. */
48
49
  registry?: string;
49
- /** Version pins overriding this release's defaults (see `DEFAULT_PINS`). */
50
+ /**
51
+ * Version pins overriding this release's defaults (see `DEFAULT_PINS`). A
52
+ * product that bundles the Claude SDK sets `claude` to the SDK's version:
53
+ * nothing on disk says which one runs.
54
+ */
50
55
  pins?: Partial<Record<CliTool, string>>;
51
56
  /**
52
57
  * Explicit CLI paths — the operator escape hatch. Defaults to
@@ -54,6 +59,13 @@ export interface ProvisionOptions {
54
59
  * letting a remote client pick the spawned executable would be RCE.
55
60
  */
56
61
  overrides?: Partial<Record<CliTool, string>>;
62
+ /**
63
+ * Read-only folders in the cache's layout (`agent-server install --dir`):
64
+ * the builds an app bundle or an image ships, used in every mode when they
65
+ * hold the version this engine runs. Defaults to `$AGENT_SERVER_BUNDLE_DIR`
66
+ * (a path list). Operator-level, like the overrides: what they hold runs.
67
+ */
68
+ bundleDirs?: string[];
57
69
  /** Progress/diagnostic lines. Defaults to stderr. */
58
70
  log?: (line: string) => void;
59
71
  }
@@ -61,87 +73,73 @@ export interface ProvisionOptions {
61
73
  /** Where a resolved CLI came from — logged once so runs are diagnosable. */
62
74
  export interface ResolvedCli {
63
75
  path: string;
64
- source: "override" | "host" | "cache" | "downloaded";
76
+ source: "override" | "bundled" | "host" | "cache" | "downloaded";
65
77
  version?: string;
66
78
  }
67
79
 
80
+ /** A CLI found where it is: never `downloaded`, which only a resolve that fetched it says. */
81
+ type LocatedCli = ResolvedCli & { source: Exclude<ResolvedCli["source"], "downloaded"> };
82
+
83
+ /** Where one install is. */
84
+ export interface CliProgress {
85
+ tool: CliTool;
86
+ version: string;
87
+ /** `downloading`, then `verifying`, then `ready`; `failed` at any point. */
88
+ phase: "downloading" | "verifying" | "ready" | "failed";
89
+ receivedBytes: number;
90
+ /** The download's size, when the registry states it. */
91
+ totalBytes?: number;
92
+ /** Why it failed. */
93
+ error?: string;
94
+ }
95
+
96
+ /** Where a CLI is, found without installing anything. */
97
+ export type CliStatus =
98
+ | ({ state: "ready" } & LocatedCli)
99
+ /** `version` is what an install would fetch; absent where nothing installs (`system`). */
100
+ | { state: "missing"; version?: string }
101
+ | { state: "installing"; version: string; receivedBytes: number; totalBytes?: number }
102
+ | { state: "failed"; version?: string; error: string };
103
+
68
104
  /** Process/machine seams, injectable so the policy is testable offline. */
69
105
  export interface ProvisionerDeps {
70
106
  fetch?: typeof fetch;
71
107
  platform?: PlatformInfo;
72
108
  env?: Record<string, string | undefined>;
73
109
  extract?: (tgzPath: string, destDir: string) => Promise<void>;
74
- /** Replace host-install discovery (SDK sibling package / PATH scan). */
110
+ /** Replace host-install discovery (SDK sibling package, installed package, PATH in `system`). */
75
111
  hostResolve?: (tool: CliTool) => ResolvedCli | undefined;
112
+ /** The builds downloads must match (`releases.ts`). */
113
+ releases?: CliReleases;
114
+ timeouts?: DownloadTimeouts;
76
115
  }
77
116
 
78
- const OVERRIDE_ENV: Record<CliTool, string> = {
79
- claude: "CLAUDE_CLI_PATH",
80
- codex: "CODEX_CLI_PATH",
81
- };
82
-
83
- const MODES: readonly ProvisionMode[] = ["auto", "pinned", "system"];
84
-
85
- /** What to download for one tool on one platform. */
86
- interface ToolPackage {
87
- name: string;
88
- /** Exact version string the registry knows (codex encodes platform here). */
89
- registryVersion: string;
90
- /** Human/tool version (cache directory key). */
117
+ /** A tool's build for this platform at the version this engine runs, and where the cache keeps it. */
118
+ interface Build {
91
119
  version: string;
92
- suffix: string;
120
+ pkg: ToolPackage;
121
+ /** `<version>-<suffix>`, its folder under `<cache>/<tool>/`. */
122
+ entry: string;
93
123
  }
94
124
 
125
+ const MODES: readonly ProvisionMode[] = ["auto", "pinned", "system"];
126
+ /** A build this process keeps resolving is recorded as used again at most this often. */
127
+ const MARK_USED_EVERY_MS = 60 * 60 * 1000;
128
+
95
129
  function defaultLog(line: string): void {
96
130
  console.error(`[agent-server] ${line}`);
97
131
  }
98
132
 
99
- /**
100
- * Locate an installed package by walking `node_modules` upward from `fromDir`,
101
- * returning its real directory. Deliberately not `require.resolve`: ESM-only
102
- * packages (codex-sdk) have no require condition and none of these packages
103
- * export `./package.json`, so exports maps would veto perfectly good installs.
104
- * The realpath matters under isolated stores (bun): a package's own deps are
105
- * siblings of its *store* location, not of the symlink consumers see.
106
- */
107
- function findPackageDir(name: string, fromDir: string): string | undefined {
108
- let dir = fromDir;
109
- while (true) {
110
- const candidate = join(dir, "node_modules", ...name.split("/"));
111
- if (existsSync(join(candidate, "package.json"))) {
112
- try {
113
- return realpathSync(candidate);
114
- } catch {
115
- return undefined;
116
- }
117
- }
118
- const parent = dirname(dir);
119
- if (parent === dir) return undefined;
120
- dir = parent;
121
- }
122
- }
123
-
124
- /** Where this package lives on disk — the walk anchor. Virtual inside compiled
125
- * binaries ($bunfs), where every walk misses and pins take over. NOTE: this
126
- * must not mention `import.meta` — consumers bundle these sources to CJS,
127
- * where that token is a parse error (and older bundlers don't rewrite it). */
128
- function moduleDir(): string {
129
- // CJS bundle output: anchor at the bundle location.
130
- if (typeof __dirname !== "undefined") return __dirname;
131
- try {
132
- // Bun/ESM: resolve our own manifest through the module graph (Bun
133
- // provides `require` in ESM; "./package.json" is an explicit export).
134
- return dirname(require.resolve("@zvada/agent-server/package.json"));
135
- } catch {
136
- return process.cwd();
137
- }
133
+ function messageOf(error: unknown): string {
134
+ return error instanceof Error ? error.message : String(error);
138
135
  }
139
136
 
140
137
  /**
141
138
  * Resolves the native CLIs the harnesses spawn (`claude`, `codex`) and — in
142
139
  * managed modes — downloads the pinned builds from the npm registry into a
143
- * local cache, verified against the registry's sha512 integrity and installed
144
- * atomically (staging + rename), so concurrent processes converge on one copy.
140
+ * local cache, checked against this release's table of them (`releases.ts`)
141
+ * and installed atomically (`install-build.ts`), so concurrent processes
142
+ * converge on one copy. What differs per tool is its `CLI_TOOL_SPECS` entry.
145
143
  *
146
144
  * One instance per runtime; `resolve` is memoized per tool (a failure clears
147
145
  * the memo so a transient network error doesn't poison the process).
@@ -150,16 +148,30 @@ export class CliProvisioner {
150
148
  private readonly mode: ProvisionMode;
151
149
  private cacheDir: string;
152
150
  private readonly registry: string;
153
- /** Explicit pins only — see `versionFor` for the per-tool default chain. */
151
+ /** Explicit pins only; a tool's spec says its default. */
154
152
  private readonly pins: Partial<Record<CliTool, string>>;
155
153
  private readonly overrides: Partial<Record<CliTool, string>>;
154
+ private readonly bundleDirs: readonly string[];
156
155
  private readonly log: (line: string) => void;
157
156
  private readonly fetch: typeof fetch;
158
157
  private readonly platform: PlatformInfo;
159
158
  private readonly env: Record<string, string | undefined>;
160
159
  private readonly extract: (tgzPath: string, destDir: string) => Promise<void>;
161
160
  private readonly hostResolve: (tool: CliTool) => ResolvedCli | undefined;
161
+ private readonly releases: CliReleases;
162
+ private readonly timeouts: DownloadTimeouts;
162
163
  private readonly memo = new Map<CliTool, Promise<ResolvedCli | undefined>>();
164
+ /** The tools a resolve or install is working on now, by how many. */
165
+ private readonly resolving = new Map<CliTool, number>();
166
+ /** Each tool's download while it runs. */
167
+ private readonly downloads = new Map<CliTool, CliProgress>();
168
+ /** Each tool's last failure to resolve, until one succeeds. */
169
+ private readonly failures = new Map<CliTool, string>();
170
+ /** The cache entries this process runs (`<tool>/<entry>`), and when each use was last recorded. */
171
+ private readonly inUse = new Map<string, number>();
172
+ /** Lines said once per process, however often a status asks. */
173
+ private readonly said = new Set<string>();
174
+ private readonly observers = new Set<(progress: CliProgress) => void>();
163
175
 
164
176
  constructor(options: ProvisionOptions = {}, deps: ProvisionerDeps = {}) {
165
177
  this.env = deps.env ?? process.env;
@@ -172,11 +184,29 @@ export class CliProvisioner {
172
184
  this.registry = options.registry ?? this.env.AGENT_SERVER_NPM_REGISTRY ?? DEFAULT_NPM_REGISTRY;
173
185
  this.pins = options.pins ?? {};
174
186
  this.overrides = options.overrides ?? {};
187
+ this.bundleDirs = (
188
+ options.bundleDirs ??
189
+ this.env.AGENT_SERVER_BUNDLE_DIR?.split(delimiter) ??
190
+ []
191
+ )
192
+ .filter(Boolean)
193
+ .map((dir) => resolve(dir));
175
194
  this.log = options.log ?? defaultLog;
176
195
  this.fetch = deps.fetch ?? fetch;
177
196
  this.platform = deps.platform ?? detectPlatform();
178
197
  this.extract = deps.extract ?? extractTarGz;
179
- this.hostResolve = deps.hostResolve ?? ((tool) => this.defaultHostResolve(tool));
198
+ this.releases = deps.releases ?? CLI_RELEASES;
199
+ this.timeouts = deps.timeouts ?? DEFAULT_DOWNLOAD_TIMEOUTS;
200
+ this.hostResolve =
201
+ deps.hostResolve ??
202
+ ((tool) => {
203
+ const found = CLI_TOOL_SPECS[tool].hostInstall({
204
+ platform: this.platform,
205
+ env: this.env,
206
+ searchPath: this.mode === "system",
207
+ });
208
+ return found && { ...found, source: "host" };
209
+ });
180
210
  }
181
211
 
182
212
  /**
@@ -185,208 +215,169 @@ export class CliProvisioner {
185
215
  * finds its sibling platform package and has the clearest failure message.
186
216
  */
187
217
  resolve(tool: CliTool): Promise<ResolvedCli | undefined> {
218
+ return this.resolveMemo(tool, false);
219
+ }
220
+
221
+ /** Warm the managed cache with the pinned build (the `install` command). */
222
+ install(tool: CliTool): Promise<ResolvedCli> {
223
+ return this.working(tool, () => this.ensureInstalled(tool));
224
+ }
225
+
226
+ /** Every install's progress; returns an unsubscribe. */
227
+ observe(observer: (progress: CliProgress) => void): () => void {
228
+ this.observers.add(observer);
229
+ return () => this.observers.delete(observer);
230
+ }
231
+
232
+ /**
233
+ * Where `tool` is now, without installing it: ready, being installed,
234
+ * failed the last time it was resolved, or missing (with the version an
235
+ * install would fetch).
236
+ */
237
+ async status(tool: CliTool): Promise<CliStatus> {
238
+ try {
239
+ const found = this.locate(tool);
240
+ if (found) return { state: "ready", ...found };
241
+ } catch (error) {
242
+ return { state: "failed", error: messageOf(error) };
243
+ }
244
+ const { version } = this.build(tool);
245
+ const download = this.downloads.get(tool);
246
+ if (download || this.resolving.has(tool)) {
247
+ return {
248
+ state: "installing",
249
+ version,
250
+ receivedBytes: download?.receivedBytes ?? 0,
251
+ ...(download?.totalBytes !== undefined && { totalBytes: download.totalBytes }),
252
+ };
253
+ }
254
+ const failure = this.failures.get(tool);
255
+ // Where nothing installs (`system`), there is no version to name.
256
+ if (this.mode === "system")
257
+ return failure ? { state: "failed", error: failure } : { state: "missing" };
258
+ return failure ? { state: "failed", version, error: failure } : { state: "missing", version };
259
+ }
260
+
261
+ /**
262
+ * Remove cached builds no process used for 14 days, except what this one
263
+ * runs, and what dead installs left — and, as `install --prune` asks,
264
+ * builds written by an agent-server that records no use, by their age.
265
+ * Returns what it removed.
266
+ */
267
+ prune(): Promise<string[]> {
268
+ return pruneCache(this.ensureTrustedCacheRoot(), CLI_TOOLS, new Set(this.inUse.keys()), true);
269
+ }
270
+
271
+ private resolveMemo(tool: CliTool, again: boolean): Promise<ResolvedCli | undefined> {
188
272
  let pending = this.memo.get(tool);
189
273
  if (!pending) {
190
- pending = this.doResolve(tool).then((resolved) => {
274
+ pending = this.working(tool, () => this.resolveUncached(tool)).then((resolved) => {
191
275
  if (resolved)
192
276
  this.log(`${tool} CLI: ${resolved.path} (${resolved.source}${withVersion(resolved)})`);
193
277
  return resolved;
194
278
  });
195
279
  this.memo.set(tool, pending);
196
280
  }
197
- return pending
281
+ const memoized = pending;
282
+ return memoized
198
283
  .then((resolved) => {
199
284
  if (resolved?.source === "cache" || resolved?.source === "downloaded") {
200
285
  const root = this.ensureTrustedCacheRoot();
201
- if (!managedDirectory(root, dirname(resolved.path), false)) {
202
- throw new CliProvisionError(`Cached CLI disappeared: ${resolved.path}`);
286
+ if (
287
+ !managedDirectory(root, dirname(resolved.path), false) ||
288
+ !existsSync(resolved.path)
289
+ ) {
290
+ // Removed under this process (by hand, or a prune that took it
291
+ // for unused): resolved again, once, which installs it again.
292
+ if (this.memo.get(tool) === memoized) this.memo.delete(tool);
293
+ if (again) throw new CliProvisionError(`Cached CLI disappeared: ${resolved.path}`);
294
+ return this.resolveMemo(tool, true);
203
295
  }
204
296
  trustedBinary(resolved.path, lstatSync(resolved.path));
297
+ // A process that keeps running its build keeps it from a prune (hourly at most).
298
+ void this.used(tool, this.build(tool).entry, false).catch(() => {});
205
299
  }
206
300
  return resolved;
207
301
  })
208
302
  .catch((error) => {
209
- if (this.memo.get(tool) === pending) this.memo.delete(tool);
303
+ if (this.memo.get(tool) === memoized) this.memo.delete(tool);
210
304
  throw error;
211
305
  });
212
306
  }
213
307
 
214
- /** Warm the managed cache with the pinned build (the `install` command). */
215
- async install(tool: CliTool): Promise<ResolvedCli> {
308
+ /** Run a resolve or install of `tool`, saying meanwhile that it is installing, and recording how it ended. */
309
+ private async working<T>(tool: CliTool, work: () => Promise<T>): Promise<T> {
310
+ this.resolving.set(tool, (this.resolving.get(tool) ?? 0) + 1);
311
+ try {
312
+ const result = await work();
313
+ this.failures.delete(tool);
314
+ return result;
315
+ } catch (error) {
316
+ this.failures.set(tool, messageOf(error));
317
+ throw error;
318
+ } finally {
319
+ const left = (this.resolving.get(tool) ?? 1) - 1;
320
+ if (left) this.resolving.set(tool, left);
321
+ else this.resolving.delete(tool);
322
+ }
323
+ }
324
+
325
+ private async resolveUncached(tool: CliTool): Promise<ResolvedCli | undefined> {
326
+ const found = this.locate(tool);
327
+ if (found?.source === "cache") await this.used(tool, this.build(tool).entry, true);
328
+ if (found) return found;
329
+ if (this.mode === "system") {
330
+ const missing = CLI_TOOL_SPECS[tool].notOnHost?.();
331
+ if (missing) throw missing;
332
+ return undefined;
333
+ }
216
334
  return this.ensureInstalled(tool);
217
335
  }
218
336
 
219
- private async doResolve(tool: CliTool): Promise<ResolvedCli | undefined> {
220
- const override = this.overrides[tool] ?? this.env[OVERRIDE_ENV[tool]];
337
+ /** The build `tool` resolves to without a download, per the mode. */
338
+ private locate(tool: CliTool): LocatedCli | undefined {
339
+ const spec = CLI_TOOL_SPECS[tool];
340
+ const override = this.overrides[tool] ?? this.env[spec.overrideEnv];
221
341
  if (override) {
222
342
  if (!existsSync(override)) {
223
343
  throw new CliProvisionError(
224
344
  `${tool} CLI override points to a missing file: ${override} ` +
225
- `(from ${this.overrides[tool] ? "options.overrides" : `$${OVERRIDE_ENV[tool]}`})`,
345
+ `(from ${this.overrides[tool] ? "options.overrides" : `$${spec.overrideEnv}`})`,
226
346
  );
227
347
  }
228
348
  return { path: override, source: "override" };
229
349
  }
230
-
350
+ const build = this.build(tool);
351
+ // @ref LLP 0010#implementation-2026-10-31 — what an app or image ships, before the host's; the operator vouches for it
352
+ for (const dir of this.bundleDirs) {
353
+ // A regular file: a symlink could redirect the spawn.
354
+ const folder = join(dir, tool, build.entry);
355
+ const path = binaryIn(folder, spec.binaries);
356
+ if (path) return { path, source: "bundled", version: build.version };
357
+ if (existsSync(folder))
358
+ this.say(`${folder} holds no regular ${spec.binaries[0]}: passed over`);
359
+ }
231
360
  if (this.mode !== "pinned") {
232
361
  const host = this.hostResolve(tool);
233
- if (host) return host;
234
- if (this.mode === "system") {
235
- if (tool === "codex") {
236
- throw new CliNotFoundError(
237
- "codex",
238
- `install it, set $${OVERRIDE_ENV.codex}, or use provision mode "auto"`,
239
- );
240
- }
241
- return undefined;
242
- }
243
- }
244
-
245
- return this.ensureInstalled(tool);
246
- }
247
-
248
- /**
249
- * Host install discovery. Both tools prefer the JS SDK's own vendored
250
- * platform package (the lockfile-paired build the SDK would spawn itself);
251
- * codex additionally falls back to PATH for machines that installed the CLI
252
- * system-wide without the SDK (the app-server harness needs no SDK).
253
- */
254
- private defaultHostResolve(tool: CliTool): ResolvedCli | undefined {
255
- if (tool === "codex") {
256
- const vendored = this.codexVendoredOnDisk();
257
- if (vendored) return vendored;
258
- const path = findOnPath("codex", this.env, this.platform.platform);
259
- return path ? { path, source: "host" } : undefined;
260
- }
261
- const sdk = this.claudeSdkOnDisk();
262
- if (!sdk) return undefined;
263
- const suffix = claudePackageSuffix(this.platform);
264
- const platformDir = findPackageDir(`@anthropic-ai/claude-agent-sdk-${suffix}`, sdk.dir);
265
- if (!platformDir) return undefined;
266
- const path = join(platformDir, this.claudeBinaryName(sdk.dir, suffix));
267
- return existsSync(path) ? { path, source: "host", version: sdk.version } : undefined;
268
- }
269
-
270
- /**
271
- * The codex build vendored by `@openai/codex-sdk` (its `@openai/codex`
272
- * dependency ships `vendor/<target>/bin/codex`) — the same two-hop
273
- * resolution the SDK's own `findCodexPath` performs, so managed resolution
274
- * never shadows the pair the SDK was published against.
275
- */
276
- private codexVendoredOnDisk(): ResolvedCli | undefined {
277
- try {
278
- const sdkDir = findPackageDir("@openai/codex-sdk", moduleDir());
279
- if (!sdkDir) return undefined;
280
- const codexDir = findPackageDir("@openai/codex", sdkDir);
281
- if (!codexDir) return undefined;
282
- const suffix = codexPackageSuffix(this.platform);
283
- const platformDir = findPackageDir(`@openai/codex-${suffix}`, codexDir);
284
- if (!platformDir) return undefined;
285
- const vendorRoot = join(platformDir, "vendor");
286
- for (const entry of readdirSync(vendorRoot)) {
287
- const path = this.binaryIn("codex", join(vendorRoot, entry));
288
- if (path) {
289
- const raw = (
290
- JSON.parse(readFileSync(join(platformDir, "package.json"), "utf8")) as {
291
- version?: string;
292
- }
293
- ).version;
294
- const version = raw?.replace(`-${suffix}`, "");
295
- return { path, source: "host", ...(version ? { version } : {}) };
296
- }
297
- }
298
- return undefined;
299
- } catch {
300
- return undefined;
301
- }
302
- }
303
-
304
- /**
305
- * The installed Claude SDK, when resolvable on disk. Its version drives both
306
- * host resolution and the download pin, so the JS ↔ native-CLI pair can
307
- * never skew. Unresolvable inside compiled binaries — pins take over there.
308
- */
309
- private claudeSdkOnDisk(): { dir: string; version?: string } | undefined {
310
- try {
311
- const dir = findPackageDir("@anthropic-ai/claude-agent-sdk", moduleDir());
312
- if (!dir) return undefined;
313
- const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) as {
314
- version?: string;
315
- };
316
- return { dir, version: pkg.version };
317
- } catch {
318
- return undefined;
319
- }
320
- }
321
-
322
- /** Binary filename from the SDK's manifest (`claude` / `claude.exe`). */
323
- private claudeBinaryName(sdkDir: string, suffix: string): string {
324
- try {
325
- const manifest = JSON.parse(readFileSync(join(sdkDir, "manifest.json"), "utf8")) as {
326
- platforms?: Record<string, { binary?: string }>;
327
- };
328
- return manifest.platforms?.[suffix]?.binary ?? "claude";
329
- } catch {
330
- return "claude";
331
- }
332
- }
333
-
334
- /**
335
- * The version to download: an explicit pin always wins; claude then prefers
336
- * the on-disk SDK's version (the pair that actually runs) over the release
337
- * default, which only decides inside compiled binaries.
338
- *
339
- * Deliberately mode-independent: even `pinned` follows the installed SDK
340
- * for claude, because "deterministic" means the tested JS ↔ CLI *pair* —
341
- * downloading the release-default CLI under a newer installed SDK would
342
- * manufacture exactly the skew this module exists to prevent. Operators
343
- * who want byte-identical fleets pin explicitly (and align the SDK).
344
- */
345
- private versionFor(tool: CliTool): string {
346
- const explicit = this.pins[tool];
347
- if (explicit) return explicit;
348
- if (tool === "claude") return this.claudeSdkOnDisk()?.version ?? DEFAULT_PINS.claude;
349
- return DEFAULT_PINS.codex;
350
- }
351
-
352
- private packageFor(tool: CliTool): ToolPackage {
353
- const version = this.versionFor(tool);
354
- if (tool === "claude") {
355
- const suffix = claudePackageSuffix(this.platform);
356
- return {
357
- name: `@anthropic-ai/claude-agent-sdk-${suffix}`,
358
- registryVersion: version,
359
- version,
360
- suffix,
361
- };
362
+ if (host) return { ...host, source: "host" };
362
363
  }
363
- const suffix = codexPackageSuffix(this.platform);
364
- return { name: "@openai/codex", registryVersion: `${version}-${suffix}`, version, suffix };
364
+ if (this.mode === "system") return undefined;
365
+ const root = this.ensureTrustedCacheRoot();
366
+ const cached = trustedBinaryIn(root, join(root, tool, build.entry), spec.binaries);
367
+ return cached ? { path: cached, source: "cache", version: build.version } : undefined;
365
368
  }
366
369
 
367
- /**
368
- * First binary candidate under an installed directory. Regular files only
369
- * (lstat): a symlink here could redirect the spawn — and the post-install
370
- * `chmod` — at a path outside the tree we verified.
371
- */
372
- private binaryIn(tool: CliTool, dir: string, managedRoot?: string): string | undefined {
373
- const candidates =
374
- tool === "claude"
375
- ? ["claude", "claude.exe"]
376
- : [join("bin", "codex"), join("bin", "codex.exe")];
377
- for (const candidate of candidates) {
378
- const path = join(dir, candidate);
379
- if (managedRoot && !managedDirectory(managedRoot, dirname(path), false)) continue;
380
- let stat: Stats;
381
- try {
382
- stat = lstatSync(path);
383
- } catch {
384
- continue;
385
- }
386
- if (managedRoot) trustedBinary(path, stat);
387
- if (stat.isFile()) return path;
370
+ /** The build of `tool` this engine runs: an explicit pin, else the tool's default. */
371
+ private build(tool: CliTool): Build {
372
+ const spec = CLI_TOOL_SPECS[tool];
373
+ let version = this.pins[tool];
374
+ if (!version) {
375
+ const note = spec.defaultVersionNote?.();
376
+ if (note) this.say(note);
377
+ version = spec.defaultVersion();
388
378
  }
389
- return undefined;
379
+ const pkg = spec.package(this.platform, version);
380
+ return { version, pkg, entry: `${version}-${pkg.suffix}` };
390
381
  }
391
382
 
392
383
  /** Pin trusted aliases to their physical location and recheck on every use. */
@@ -395,72 +386,100 @@ export class CliProvisioner {
395
386
  return this.cacheDir;
396
387
  }
397
388
 
398
- /** The directory inside an extracted tarball that becomes the install. */
399
- private async payloadDir(tool: CliTool, extractedRoot: string): Promise<string> {
400
- if (tool === "claude") {
401
- const dir = join(extractedRoot, "package");
402
- if (existsSync(dir)) return dir;
403
- throw new CliProvisionError("claude tarball has no package/ directory");
404
- }
405
- // codex vendors per-target trees: package/vendor/<rust-triple>/bin/codex.
406
- // Install the whole tree — the CLI expects its vendored rg/zsh siblings.
407
- const vendor = join(extractedRoot, "package", "vendor");
408
- const entries = existsSync(vendor) ? await readdir(vendor) : [];
409
- for (const entry of entries) {
410
- const dir = join(vendor, entry);
411
- if (this.binaryIn(tool, dir)) return dir;
412
- }
413
- throw new CliProvisionError("codex tarball has no vendor/<target>/bin/codex");
414
- }
415
-
416
389
  private async ensureInstalled(tool: CliTool): Promise<ResolvedCli> {
390
+ const spec = CLI_TOOL_SPECS[tool];
417
391
  const root = this.ensureTrustedCacheRoot();
418
- const pkg = this.packageFor(tool);
419
- const dir = join(root, tool, `${pkg.version}-${pkg.suffix}`);
420
- const cached = this.binaryIn(tool, dir, root);
421
- if (cached) return { path: cached, source: "cache", version: pkg.version };
392
+ const build = this.build(tool);
393
+ const dir = join(root, tool, build.entry);
394
+ let path = trustedBinaryIn(root, dir, spec.binaries);
395
+ const downloaded = !path;
396
+ if (!path) {
397
+ await this.download(tool, build, root, dir);
398
+ path = trustedBinaryIn(root, dir, spec.binaries);
399
+ if (!path) throw noBinary(build.pkg);
400
+ }
401
+ await this.used(tool, build.entry, true);
402
+ // The cache grew: what no process used for a while goes. Best effort.
403
+ if (downloaded)
404
+ await pruneCache(root, CLI_TOOLS, new Set(this.inUse.keys()), false).catch(() => {});
405
+ return { path, source: downloaded ? "downloaded" : "cache", version: build.version };
406
+ }
422
407
 
423
- this.log(`downloading ${tool} ${pkg.version} (${pkg.suffix}) from ${this.registry}…`);
408
+ /** Download and install one build, reporting its progress to the observers and the log. */
409
+ private async download(tool: CliTool, build: Build, root: string, dir: string): Promise<void> {
410
+ const spec = CLI_TOOL_SPECS[tool];
411
+ const { version, pkg } = build;
412
+ let progress: CliProgress = { tool, version, phase: "downloading", receivedBytes: 0 };
413
+ const report = (next: Partial<CliProgress>) => {
414
+ progress = { ...progress, ...next };
415
+ this.downloads.set(tool, progress);
416
+ for (const observer of this.observers) {
417
+ try {
418
+ observer(progress);
419
+ } catch {
420
+ // A host's progress display must not fail the download.
421
+ }
422
+ }
423
+ };
424
424
  const startedAt = Date.now();
425
- const staging = join(
426
- root,
427
- ".tmp",
428
- `${tool}-${pkg.version}-${process.pid}-${randomBytes(4).toString("hex")}`,
429
- );
430
- managedDirectory(root, dirname(staging), true);
431
- await mkdir(staging, { mode: 0o700 });
432
425
  try {
433
- const dist = await fetchDist(this.registry, pkg.name, pkg.registryVersion, this.fetch);
434
- const tgz = join(staging, "package.tgz");
435
- const bytes = await downloadWithIntegrity(dist.tarball, tgz, dist.integrity, this.fetch);
436
- const extracted = join(staging, "x");
437
- await mkdir(extracted, { mode: 0o700 });
438
- await this.extract(tgz, extracted);
439
- const payload = await this.payloadDir(tool, extracted);
440
-
441
- this.ensureTrustedCacheRoot();
442
- managedDirectory(root, dirname(dir), true);
443
- try {
444
- await rename(payload, dir);
445
- } catch (error) {
446
- // Lost an install race with another process. The directory is
447
- // version-keyed, so the winner's tree is what we would have written.
448
- if (!this.binaryIn(tool, dir, root)) throw error;
449
- }
450
- const path = this.binaryIn(tool, dir, root);
451
- if (!path) {
452
- throw new CliProvisionError(`downloaded ${pkg.name}@${pkg.registryVersion} has no binary`);
453
- }
454
- await chmod(path, 0o755);
426
+ report({});
427
+ const expected = expectedBuild(tool, version, pkg.suffix, this.releases, spec.localBuild);
428
+ if (expected.source !== "release")
429
+ this.say(
430
+ `${tool} ${version} (${pkg.suffix}) is not pinned by this agent-server release: checked against ${
431
+ expected.source === "local" ? expected.vouchedBy : "the registry's checksum only"
432
+ }`,
433
+ );
434
+ this.log(
435
+ `downloading ${tool} ${version} (${pkg.suffix}) from ${withoutSecrets(this.registry)}…`,
436
+ );
437
+ const bytes = await installBuild({
438
+ spec,
439
+ pkg,
440
+ expected,
441
+ root,
442
+ dir,
443
+ registry: this.registry,
444
+ fetch: this.fetch,
445
+ timeouts: this.timeouts,
446
+ extract: this.extract,
447
+ onProgress: (phase, receivedBytes, totalBytes) =>
448
+ report({ phase, receivedBytes, totalBytes }),
449
+ });
455
450
  const seconds = ((Date.now() - startedAt) / 1000).toFixed(1);
456
- const mb = (bytes / 1024 / 1024).toFixed(0);
457
- this.log(`installed ${tool} ${pkg.version} → ${dir} (${mb} MB in ${seconds}s)`);
458
- return { path, source: "downloaded", version: pkg.version };
451
+ this.log(
452
+ `installed ${tool} ${version} → ${dir} (${(bytes / 1024 / 1024).toFixed(0)} MB in ${seconds}s)`,
453
+ );
454
+ report({ phase: "ready" });
455
+ } catch (error) {
456
+ report({ phase: "failed", error: messageOf(error) });
457
+ throw error;
459
458
  } finally {
460
- await rm(staging, { recursive: true, force: true });
459
+ this.downloads.delete(tool);
461
460
  }
462
461
  }
463
462
 
463
+ /**
464
+ * Record that this process runs a cached build, so no prune removes it:
465
+ * now when `now` (it was just found or installed, its record perhaps
466
+ * pruned with it), else at most hourly as it keeps resolving it.
467
+ */
468
+ private async used(tool: CliTool, entry: string, now: boolean): Promise<void> {
469
+ const key = `${tool}/${entry}`;
470
+ const recorded = this.inUse.get(key);
471
+ if (!now && recorded !== undefined && Date.now() - recorded < MARK_USED_EVERY_MS) return;
472
+ this.inUse.set(key, Date.now());
473
+ await markUsed(this.ensureTrustedCacheRoot(), tool, entry);
474
+ }
475
+
476
+ /** A line said once per process. */
477
+ private say(line: string): void {
478
+ if (this.said.has(line)) return;
479
+ this.said.add(line);
480
+ this.log(line);
481
+ }
482
+
464
483
  private modeFromEnv(): ProvisionMode {
465
484
  const raw = this.env.AGENT_SERVER_PROVISION;
466
485
  if (raw === undefined || raw === "") return "auto";
@@ -474,90 +493,3 @@ export class CliProvisioner {
474
493
  function withVersion(resolved: ResolvedCli): string {
475
494
  return resolved.version ? ` ${resolved.version}` : "";
476
495
  }
477
-
478
- function refuseCache(path: string, reason: string): never {
479
- throw new CliProvisionError(`Untrusted CLI cache path ${path}: ${reason} — refusing to use it`);
480
- }
481
-
482
- function trustedOwner(path: string, stat: Stats, ownOnly = false): void {
483
- if (typeof process.getuid !== "function") return;
484
- const uid = process.getuid();
485
- if (stat.uid !== uid && (ownOnly || stat.uid !== 0))
486
- refuseCache(path, `owned by uid ${stat.uid}, expected ${uid}${ownOnly ? "" : " or root"}`);
487
- }
488
-
489
- function privateDirectory(path: string, stat: Stats, allowSticky = false): void {
490
- if (!stat.isDirectory()) refuseCache(path, "not a directory (planted symlink?)");
491
- trustedOwner(path, stat);
492
- if (
493
- typeof process.getuid === "function" &&
494
- stat.mode & 0o022 &&
495
- !(allowSticky && stat.mode & 0o1000)
496
- ) {
497
- refuseCache(path, "writable by other users");
498
- }
499
- }
500
-
501
- function createDirectory(path: string): void {
502
- try {
503
- mkdirSync(path, { mode: 0o700 });
504
- } catch (error) {
505
- if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
506
- }
507
- }
508
-
509
- /** Check each parent before creating its child; trusted sticky parents permit /tmp. */
510
- function trustedCacheDirectory(path: string, ownLeaf: boolean): string {
511
- const root = parse(path).root;
512
- let current = root;
513
- privateDirectory(root, lstatSync(root), true);
514
- const components = relative(root, path).split(sep).filter(Boolean);
515
- if (ownLeaf && !components.length) refuseCache(path, "filesystem root cannot be a CLI cache");
516
- for (const [index, component] of components.entries()) {
517
- const candidate = join(current, component);
518
- createDirectory(candidate);
519
- const stat = lstatSync(candidate);
520
- const leaf = ownLeaf && index === components.length - 1;
521
- if (stat.isSymbolicLink() && !leaf) {
522
- trustedOwner(candidate, stat);
523
- current = trustedCacheDirectory(realpathSync(candidate), false);
524
- continue;
525
- }
526
- if (leaf) {
527
- if (!stat.isDirectory()) refuseCache(candidate, "not a directory (planted symlink?)");
528
- trustedOwner(candidate, stat, true);
529
- if (typeof process.getuid === "function" && (stat.mode & 0o777) !== 0o700)
530
- chmodSync(candidate, 0o700);
531
- } else privateDirectory(candidate, stat, true);
532
- current = candidate;
533
- }
534
- return current;
535
- }
536
-
537
- /** Managed descendants cannot be aliases or outsider-writable, even under a repaired root. */
538
- function managedDirectory(root: string, path: string, create: boolean): boolean {
539
- const rel = relative(root, path);
540
- if (isAbsolute(rel) || rel.split(sep).includes(".."))
541
- refuseCache(path, "outside the managed root");
542
- let current = root;
543
- for (const component of rel.split(sep).filter(Boolean)) {
544
- current = join(current, component);
545
- if (create) createDirectory(current);
546
- let stat: Stats;
547
- try {
548
- stat = lstatSync(current);
549
- } catch (error) {
550
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
551
- throw error;
552
- }
553
- privateDirectory(current, stat);
554
- }
555
- return true;
556
- }
557
-
558
- function trustedBinary(path: string, stat: Stats): void {
559
- if (!stat.isFile()) refuseCache(path, "not a regular executable file");
560
- trustedOwner(path, stat);
561
- if (typeof process.getuid === "function" && stat.mode & 0o022)
562
- refuseCache(path, "executable writable by other users");
563
- }