@open-mercato/cezar 0.19.0-pr1908.4332 → 0.19.0-pr1908.4683

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 (608) hide show
  1. package/README.md +3 -2
  2. package/dist/agent-config/account-identity.js +3 -0
  3. package/dist/agent-config/account-identity.js.map +1 -1
  4. package/dist/agent-config/catalog.d.ts +7 -1
  5. package/dist/agent-config/catalog.js +174 -4
  6. package/dist/agent-config/catalog.js.map +1 -1
  7. package/dist/agent-config/model-settings/gemini.d.ts +8 -0
  8. package/dist/agent-config/model-settings/gemini.js +16 -0
  9. package/dist/agent-config/model-settings/gemini.js.map +1 -0
  10. package/dist/agent-config/model-settings/kimi.d.ts +7 -0
  11. package/dist/agent-config/model-settings/kimi.js +13 -0
  12. package/dist/agent-config/model-settings/kimi.js.map +1 -0
  13. package/dist/agent-config/model-settings/omp.d.ts +11 -0
  14. package/dist/agent-config/model-settings/omp.js +17 -0
  15. package/dist/agent-config/model-settings/omp.js.map +1 -0
  16. package/dist/agent-config/model-settings/shared.d.ts +6 -0
  17. package/dist/agent-config/model-settings/shared.js +17 -3
  18. package/dist/agent-config/model-settings/shared.js.map +1 -1
  19. package/dist/agent-config/models.js +6 -0
  20. package/dist/agent-config/models.js.map +1 -1
  21. package/dist/agent-config/validate.js +15 -0
  22. package/dist/agent-config/validate.js.map +1 -1
  23. package/dist/automations/automation-cli.d.ts +2 -0
  24. package/dist/automations/automation-cli.js +82 -2
  25. package/dist/automations/automation-cli.js.map +1 -1
  26. package/dist/automations/deferred-start.d.ts +5 -4
  27. package/dist/automations/deferred-start.js +5 -1
  28. package/dist/automations/deferred-start.js.map +1 -1
  29. package/dist/automations/paused-work.d.ts +24 -0
  30. package/dist/automations/paused-work.js +61 -0
  31. package/dist/automations/paused-work.js.map +1 -0
  32. package/dist/automations/pr-head.d.ts +3 -0
  33. package/dist/automations/pr-head.js +8 -4
  34. package/dist/automations/pr-head.js.map +1 -1
  35. package/dist/automations/prompts.js +1 -0
  36. package/dist/automations/prompts.js.map +1 -1
  37. package/dist/automations/store.d.ts +16 -0
  38. package/dist/automations/store.js +44 -0
  39. package/dist/automations/store.js.map +1 -1
  40. package/dist/automations/task-template.js +1 -0
  41. package/dist/automations/task-template.js.map +1 -1
  42. package/dist/automations/templates.js +1 -0
  43. package/dist/automations/templates.js.map +1 -1
  44. package/dist/automations/types.d.ts +24 -0
  45. package/dist/automations/types.js +2 -0
  46. package/dist/automations/types.js.map +1 -1
  47. package/dist/automations/validate-input.d.ts +188 -0
  48. package/dist/automations/validate-input.js +85 -0
  49. package/dist/automations/validate-input.js.map +1 -0
  50. package/dist/config.d.ts +12 -5
  51. package/dist/config.js +4 -12
  52. package/dist/config.js.map +1 -1
  53. package/dist/contract/agent-config.d.ts +9 -0
  54. package/dist/contract/agent-profiles.d.ts +74 -20
  55. package/dist/contract/agent.d.ts +12 -0
  56. package/dist/contract/artifacts.d.ts +138 -0
  57. package/dist/contract/assets.d.ts +83 -0
  58. package/dist/contract/automations.d.ts +158 -0
  59. package/dist/contract/dashboard-costs.d.ts +2 -0
  60. package/dist/contract/dashboard.d.ts +8 -0
  61. package/dist/contract/deferred-start.d.ts +33 -0
  62. package/dist/contract/dispatch.d.ts +9 -0
  63. package/dist/contract/events.d.ts +6 -0
  64. package/dist/contract/github.d.ts +13 -0
  65. package/dist/contract/health.d.ts +12 -0
  66. package/dist/contract/impact.d.ts +134 -0
  67. package/dist/contract/index.d.ts +6 -0
  68. package/dist/contract/index.js +2955 -2547
  69. package/dist/contract/managers.d.ts +79 -0
  70. package/dist/contract/runners.d.ts +15 -0
  71. package/dist/contract/runs.d.ts +292 -0
  72. package/dist/contract/skills.d.ts +67 -0
  73. package/dist/contract/telemetry.d.ts +5 -1
  74. package/dist/contract/transfer.d.ts +1932 -0
  75. package/dist/contract/workflows.d.ts +87 -0
  76. package/dist/contract/workspace-layouts.d.ts +6 -0
  77. package/dist/contract/workspace.d.ts +111 -37
  78. package/dist/core/agent-env.js +43 -1
  79. package/dist/core/agent-env.js.map +1 -1
  80. package/dist/core/agent-errors.d.ts +3 -0
  81. package/dist/core/agent-errors.js +13 -0
  82. package/dist/core/agent-errors.js.map +1 -1
  83. package/dist/core/agent-model-policy.d.ts +1 -1
  84. package/dist/core/agent-model-policy.js +1 -1
  85. package/dist/core/agent-model-policy.js.map +1 -1
  86. package/dist/core/agent-profiles.d.ts +19 -3
  87. package/dist/core/agent-profiles.js +27 -3
  88. package/dist/core/agent-profiles.js.map +1 -1
  89. package/dist/core/agent-runner.d.ts +44 -10
  90. package/dist/core/agent-runner.js +21 -7
  91. package/dist/core/agent-runner.js.map +1 -1
  92. package/dist/core/antigravity-runner.js +2 -1
  93. package/dist/core/antigravity-runner.js.map +1 -1
  94. package/dist/core/backend-detect.d.ts +3 -2
  95. package/dist/core/backend-detect.js +80 -1
  96. package/dist/core/backend-detect.js.map +1 -1
  97. package/dist/core/claude-cli-runner.js +30 -3
  98. package/dist/core/claude-cli-runner.js.map +1 -1
  99. package/dist/core/claude-model-catalog.d.ts +6 -1
  100. package/dist/core/claude-model-catalog.js +20 -0
  101. package/dist/core/claude-model-catalog.js.map +1 -1
  102. package/dist/core/claude-usage-status.d.ts +8 -0
  103. package/dist/core/claude-usage-status.js +48 -0
  104. package/dist/core/claude-usage-status.js.map +1 -0
  105. package/dist/core/codex-app-server-runner.d.ts +8 -0
  106. package/dist/core/codex-app-server-runner.js +84 -13
  107. package/dist/core/codex-app-server-runner.js.map +1 -1
  108. package/dist/core/codex-model-catalog.js +42 -0
  109. package/dist/core/codex-model-catalog.js.map +1 -1
  110. package/dist/core/codex-ui-mapper.d.ts +7 -0
  111. package/dist/core/codex-ui-mapper.js +12 -2
  112. package/dist/core/codex-ui-mapper.js.map +1 -1
  113. package/dist/core/copilot-acp-runner.js +5 -1
  114. package/dist/core/copilot-acp-runner.js.map +1 -1
  115. package/dist/core/cursor-agent-runner.js +5 -1
  116. package/dist/core/cursor-agent-runner.js.map +1 -1
  117. package/dist/core/gemini-acp-runner.d.ts +37 -0
  118. package/dist/core/gemini-acp-runner.js +537 -0
  119. package/dist/core/gemini-acp-runner.js.map +1 -0
  120. package/dist/core/gemini-credentials.d.ts +21 -0
  121. package/dist/core/gemini-credentials.js +80 -0
  122. package/dist/core/gemini-credentials.js.map +1 -0
  123. package/dist/core/gemini-sessions.d.ts +18 -0
  124. package/dist/core/gemini-sessions.js +41 -0
  125. package/dist/core/gemini-sessions.js.map +1 -0
  126. package/dist/core/gemini-ui-mapper.d.ts +30 -0
  127. package/dist/core/gemini-ui-mapper.js +80 -0
  128. package/dist/core/gemini-ui-mapper.js.map +1 -0
  129. package/dist/core/junie-runner.js +2 -1
  130. package/dist/core/junie-runner.js.map +1 -1
  131. package/dist/core/kimi-home.d.ts +7 -0
  132. package/dist/core/kimi-home.js +13 -0
  133. package/dist/core/kimi-home.js.map +1 -0
  134. package/dist/core/kimi-model-catalog.d.ts +17 -0
  135. package/dist/core/kimi-model-catalog.js +45 -0
  136. package/dist/core/kimi-model-catalog.js.map +1 -0
  137. package/dist/core/kimi-runner.d.ts +90 -0
  138. package/dist/core/kimi-runner.js +874 -0
  139. package/dist/core/kimi-runner.js.map +1 -0
  140. package/dist/core/kimi-ui-mapper.d.ts +71 -0
  141. package/dist/core/kimi-ui-mapper.js +399 -0
  142. package/dist/core/kimi-ui-mapper.js.map +1 -0
  143. package/dist/core/model-identity.js +11 -0
  144. package/dist/core/model-identity.js.map +1 -1
  145. package/dist/core/model-presets.js +10 -0
  146. package/dist/core/model-presets.js.map +1 -1
  147. package/dist/core/omp-rpc-runner.d.ts +41 -0
  148. package/dist/core/omp-rpc-runner.js +451 -0
  149. package/dist/core/omp-rpc-runner.js.map +1 -0
  150. package/dist/core/omp-ui-mapper.d.ts +56 -0
  151. package/dist/core/omp-ui-mapper.js +468 -0
  152. package/dist/core/omp-ui-mapper.js.map +1 -0
  153. package/dist/core/opencode-http.d.ts +2 -0
  154. package/dist/core/opencode-http.js +2 -2
  155. package/dist/core/opencode-http.js.map +1 -1
  156. package/dist/core/opencode-server-runner.d.ts +3 -1
  157. package/dist/core/opencode-server-runner.js +197 -25
  158. package/dist/core/opencode-server-runner.js.map +1 -1
  159. package/dist/core/opencode-v2-events.d.ts +11 -0
  160. package/dist/core/opencode-v2-events.js +105 -0
  161. package/dist/core/opencode-v2-events.js.map +1 -0
  162. package/dist/core/pi-runner.js +5 -1
  163. package/dist/core/pi-runner.js.map +1 -1
  164. package/dist/core/private-mcp.d.ts +1 -1
  165. package/dist/core/private-mcp.js +2 -2
  166. package/dist/core/private-mcp.js.map +1 -1
  167. package/dist/core/process-signals.d.ts +29 -0
  168. package/dist/core/process-signals.js +85 -0
  169. package/dist/core/process-signals.js.map +1 -0
  170. package/dist/core/provider-auth.d.ts +25 -2
  171. package/dist/core/provider-auth.js +132 -12
  172. package/dist/core/provider-auth.js.map +1 -1
  173. package/dist/core/runner-factory.d.ts +1 -0
  174. package/dist/core/runner-factory.js +38 -1
  175. package/dist/core/runner-factory.js.map +1 -1
  176. package/dist/core/runner-model-catalog.d.ts +8 -0
  177. package/dist/core/runner-model-catalog.js +3 -0
  178. package/dist/core/runner-model-catalog.js.map +1 -1
  179. package/dist/core/tool-display.js +2 -0
  180. package/dist/core/tool-display.js.map +1 -1
  181. package/dist/core/ui-events.d.ts +1 -1
  182. package/dist/core/usage-limit.d.ts +2 -2
  183. package/dist/core/usage-limit.js +5 -3
  184. package/dist/core/usage-limit.js.map +1 -1
  185. package/dist/data-gitignore.d.ts +1 -1
  186. package/dist/data-gitignore.js +1 -0
  187. package/dist/data-gitignore.js.map +1 -1
  188. package/dist/dispatch/engine.d.ts +4 -0
  189. package/dist/dispatch/engine.js +9 -0
  190. package/dist/dispatch/engine.js.map +1 -1
  191. package/dist/e2e-setup.d.ts +8 -3
  192. package/dist/e2e-setup.js +31 -16
  193. package/dist/e2e-setup.js.map +1 -1
  194. package/dist/handoff.d.ts +2 -2
  195. package/dist/handoff.js +5 -5
  196. package/dist/handoff.js.map +1 -1
  197. package/dist/impact/demo-review.json +781 -0
  198. package/dist/impact/diff.d.ts +21 -0
  199. package/dist/impact/diff.js +81 -0
  200. package/dist/impact/diff.js.map +1 -0
  201. package/dist/impact/evidence.d.ts +67 -0
  202. package/dist/impact/evidence.js +238 -0
  203. package/dist/impact/evidence.js.map +1 -0
  204. package/dist/impact/impact-cli.d.ts +12 -0
  205. package/dist/impact/impact-cli.js +141 -0
  206. package/dist/impact/impact-cli.js.map +1 -0
  207. package/dist/impact/launch.d.ts +46 -0
  208. package/dist/impact/launch.js +145 -0
  209. package/dist/impact/launch.js.map +1 -0
  210. package/dist/impact/model.d.ts +551 -0
  211. package/dist/impact/model.js +188 -0
  212. package/dist/impact/model.js.map +1 -0
  213. package/dist/impact/publish.d.ts +30 -0
  214. package/dist/impact/publish.js +119 -0
  215. package/dist/impact/publish.js.map +1 -0
  216. package/dist/impact/render.d.ts +41 -0
  217. package/dist/impact/render.js +109 -0
  218. package/dist/impact/render.js.map +1 -0
  219. package/dist/impact/template.html +670 -0
  220. package/dist/impact/validate.d.ts +25 -0
  221. package/dist/impact/validate.js +273 -0
  222. package/dist/impact/validate.js.map +1 -0
  223. package/dist/index.js +19 -4
  224. package/dist/index.js.map +1 -1
  225. package/dist/managers/engine.js +5 -2
  226. package/dist/managers/engine.js.map +1 -1
  227. package/dist/pack-check.d.ts +1 -0
  228. package/dist/pack-check.js +14 -0
  229. package/dist/pack-check.js.map +1 -1
  230. package/dist/paths.d.ts +6 -0
  231. package/dist/paths.js +19 -1
  232. package/dist/paths.js.map +1 -1
  233. package/dist/runs/agent-error-telemetry.js +7 -4
  234. package/dist/runs/agent-error-telemetry.js.map +1 -1
  235. package/dist/runs/agent-tmpdir.d.ts +25 -6
  236. package/dist/runs/agent-tmpdir.js +136 -25
  237. package/dist/runs/agent-tmpdir.js.map +1 -1
  238. package/dist/runs/artifacts.d.ts +52 -0
  239. package/dist/runs/artifacts.js +243 -0
  240. package/dist/runs/artifacts.js.map +1 -0
  241. package/dist/runs/event-history.d.ts +12 -0
  242. package/dist/runs/event-history.js +61 -0
  243. package/dist/runs/event-history.js.map +1 -1
  244. package/dist/runs/project-assets.d.ts +9 -0
  245. package/dist/runs/project-assets.js +57 -0
  246. package/dist/runs/project-assets.js.map +1 -0
  247. package/dist/runs/review-gate.d.ts +10 -0
  248. package/dist/runs/review-gate.js +12 -0
  249. package/dist/runs/review-gate.js.map +1 -1
  250. package/dist/runs/store.d.ts +70 -4
  251. package/dist/runs/store.js +139 -26
  252. package/dist/runs/store.js.map +1 -1
  253. package/dist/server/agent-setup.d.ts +1 -1
  254. package/dist/server/agent-setup.js +2 -1
  255. package/dist/server/agent-setup.js.map +1 -1
  256. package/dist/server/artifacts.d.ts +33 -0
  257. package/dist/server/artifacts.js +133 -0
  258. package/dist/server/artifacts.js.map +1 -0
  259. package/dist/server/dashboard.d.ts +5 -0
  260. package/dist/server/forge/github-assets.d.ts +7 -0
  261. package/dist/server/forge/github-assets.js +100 -0
  262. package/dist/server/forge/github-assets.js.map +1 -0
  263. package/dist/server/forge/github.d.ts +11 -0
  264. package/dist/server/forge/github.js +42 -0
  265. package/dist/server/forge/github.js.map +1 -1
  266. package/dist/server/open-in-app.js +3 -0
  267. package/dist/server/open-in-app.js.map +1 -1
  268. package/dist/server/provider-action-gate.js +12 -4
  269. package/dist/server/provider-action-gate.js.map +1 -1
  270. package/dist/server/server.d.ts +10012 -6701
  271. package/dist/server/server.js +353 -193
  272. package/dist/server/server.js.map +1 -1
  273. package/dist/server/star-count.d.ts +5 -5
  274. package/dist/server/star-count.js +5 -5
  275. package/dist/server/star-count.js.map +1 -1
  276. package/dist/server-install/steps.js +1 -0
  277. package/dist/server-install/steps.js.map +1 -1
  278. package/dist/skills-provision.js +7 -1
  279. package/dist/skills-provision.js.map +1 -1
  280. package/dist/skills.d.ts +10 -6
  281. package/dist/skills.js +11 -6
  282. package/dist/skills.js.map +1 -1
  283. package/dist/transfer/automations-file.d.ts +46 -0
  284. package/dist/transfer/automations-file.js +172 -0
  285. package/dist/transfer/automations-file.js.map +1 -0
  286. package/dist/transfer/config-bundle.d.ts +100 -0
  287. package/dist/transfer/config-bundle.js +430 -0
  288. package/dist/transfer/config-bundle.js.map +1 -0
  289. package/dist/webhooks/outbox.js +83 -63
  290. package/dist/webhooks/outbox.js.map +1 -1
  291. package/dist/workflows/graph.d.ts +27 -0
  292. package/dist/workflows/load.js +2 -2
  293. package/dist/workflows/load.js.map +1 -1
  294. package/dist/workflows/resume-fallback.d.ts +13 -6
  295. package/dist/workflows/resume-fallback.js +26 -6
  296. package/dist/workflows/resume-fallback.js.map +1 -1
  297. package/dist/workflows/run.d.ts +121 -10
  298. package/dist/workflows/run.js +363 -61
  299. package/dist/workflows/run.js.map +1 -1
  300. package/dist/workflows/templates.d.ts +27 -16
  301. package/dist/workflows/templates.js +17 -0
  302. package/dist/workflows/templates.js.map +1 -1
  303. package/dist/workflows/types.d.ts +21 -0
  304. package/dist/workflows/types.js +3 -1
  305. package/dist/workflows/types.js.map +1 -1
  306. package/dist/workspace/agent-accounts.d.ts +27 -15
  307. package/dist/workspace/agent-accounts.js +4 -14
  308. package/dist/workspace/agent-accounts.js.map +1 -1
  309. package/dist/workspace/agent-profiles.js +3 -0
  310. package/dist/workspace/agent-profiles.js.map +1 -1
  311. package/dist/workspace/config.d.ts +12 -6
  312. package/dist/workspace/config.js +3 -13
  313. package/dist/workspace/config.js.map +1 -1
  314. package/dist/workspace/dashboard-costs.d.ts +1 -0
  315. package/dist/workspace/dashboard-costs.js +1 -0
  316. package/dist/workspace/dashboard-costs.js.map +1 -1
  317. package/dist/workspace/dashboard-insights.d.ts +1 -0
  318. package/dist/workspace/dashboard-insights.js +5 -2
  319. package/dist/workspace/dashboard-insights.js.map +1 -1
  320. package/dist/workspace/dashboard-overview.js +2 -0
  321. package/dist/workspace/dashboard-overview.js.map +1 -1
  322. package/dist/workspace/dashboard.d.ts +1 -0
  323. package/package.json +5 -4
  324. package/scripts/check-pack.mjs +3 -2
  325. package/scripts/copy-assets.mjs +17 -0
  326. package/scripts/mock-claude.mjs +106 -1
  327. package/scripts/mock-gemini-acp.mjs +195 -0
  328. package/scripts/mock-kimi-acp.mjs +126 -0
  329. package/scripts/mock-omp-rpc.mjs +194 -0
  330. package/skills/change-impact/SKILL.md +117 -0
  331. package/skills/change-impact/references/analysis-contract.md +141 -0
  332. package/skills/change-impact/references/public-api.md +92 -0
  333. package/skills/change-impact/references/visual-contract.md +71 -0
  334. package/web/dist/assets/{active-forge-DEmP_h4r.js → active-forge-DO2AaQ-s.js} +1 -1
  335. package/web/dist/assets/agent-task-pickers-CZpw4vcZ.js +1 -0
  336. package/web/dist/assets/{alert-dialog-BZkKvKiu.js → alert-dialog-BihfE0uZ.js} +1 -1
  337. package/web/dist/assets/arrow-down-DACdHKjc.js +1 -0
  338. package/web/dist/assets/arrow-left-BtT8zuL0.js +1 -0
  339. package/web/dist/assets/arrow-up-BAPSgozC.js +1 -0
  340. package/web/dist/assets/ask-answer-Co3javaA.js +1 -0
  341. package/web/dist/assets/{ask-card-CfNUHYt9.js → ask-card-DLtNyMH_.js} +2 -2
  342. package/web/dist/assets/assets-view-CLCckPll.js +1 -0
  343. package/web/dist/assets/{automation-format-BPrWgGBz.js → automation-format-BXwiLf2G.js} +1 -1
  344. package/web/dist/assets/automations-route-JizzZrRf.js +1 -0
  345. package/web/dist/assets/blink-1oEUjxch.webp +0 -0
  346. package/web/dist/assets/blink-B4Y4PYCR.webp +0 -0
  347. package/web/dist/assets/blink-BpqW08tf.webp +0 -0
  348. package/web/dist/assets/blink-C380t2a5.webp +0 -0
  349. package/web/dist/assets/blink-CLn5VMYQ.webp +0 -0
  350. package/web/dist/assets/blink-Cn_tI5Yd.webp +0 -0
  351. package/web/dist/assets/blink-D4EaTnc2.webp +0 -0
  352. package/web/dist/assets/blink-DY4Sm5aw.webp +0 -0
  353. package/web/dist/assets/blink-mcM10OfP.webp +0 -0
  354. package/web/dist/assets/body-CXEwT_gR.webp +0 -0
  355. package/web/dist/assets/body-D-UrLURv.webp +0 -0
  356. package/web/dist/assets/body-D7Q8eJDv.webp +0 -0
  357. package/web/dist/assets/body-DdNSx4-d.webp +0 -0
  358. package/web/dist/assets/body-DlFNtp32.webp +0 -0
  359. package/web/dist/assets/body-EreQeu3g.webp +0 -0
  360. package/web/dist/assets/body-Goc64z5o.webp +0 -0
  361. package/web/dist/assets/body-_FLmHm_q.webp +0 -0
  362. package/web/dist/assets/body-v5xTmq5E.webp +0 -0
  363. package/web/dist/assets/{bot-qZRkHkDp.js → bot-Cm-PLA1M.js} +1 -1
  364. package/web/dist/assets/{button-BrxohNcK.js → button-BqkA8Ovk.js} +1 -1
  365. package/web/dist/assets/{centered-state-CSW_o4N7.js → centered-state-CquGIOsq.js} +1 -1
  366. package/web/dist/assets/check-B1z-_MCO.js +1 -0
  367. package/web/dist/assets/chevron-left-CDAxCC2p.js +1 -0
  368. package/web/dist/assets/chevron-right-DPaV033p.js +1 -0
  369. package/web/dist/assets/chunk-KS7C4IRE-DtL2Gzw3.js +3 -0
  370. package/web/dist/assets/{circle-alert-COKQc-87.js → circle-alert-B7VNkPC2.js} +1 -1
  371. package/web/dist/assets/circle-check-LWKCYKhA.js +1 -0
  372. package/web/dist/assets/{collapsible-BJ0sxcz9.js → collapsible-BuSDxSYs.js} +1 -1
  373. package/web/dist/assets/command-CfdVVS0V.js +1 -0
  374. package/web/dist/assets/{commit-list-HXZj01RO.js → commit-list-D5Nuv2HC.js} +1 -1
  375. package/web/dist/assets/compare-variants-BBOnUKfp.js +1 -0
  376. package/web/dist/assets/composer-BPIW4tmM.js +18 -0
  377. package/web/dist/assets/composer-attachments-DyC9yyGs.js +3 -0
  378. package/web/dist/assets/concerned-BIuYysOA.webp +0 -0
  379. package/web/dist/assets/concerned-BWTrkjRS.webp +0 -0
  380. package/web/dist/assets/concerned-BW_ywmzK.webp +0 -0
  381. package/web/dist/assets/concerned-CXQVACqJ.webp +0 -0
  382. package/web/dist/assets/concerned-DdsJa1t2.webp +0 -0
  383. package/web/dist/assets/concerned-Dlln-1nu.webp +0 -0
  384. package/web/dist/assets/concerned-DrSCYUQV.webp +0 -0
  385. package/web/dist/assets/concerned-TOjmS1qX.webp +0 -0
  386. package/web/dist/assets/concerned-tIx9dV3J.webp +0 -0
  387. package/web/dist/assets/dashboard-B_ytEQ_y.js +44 -0
  388. package/web/dist/assets/diff-BQScRHXz.js +3 -0
  389. package/web/dist/assets/diff-stat-CxDTnfya.js +1 -0
  390. package/web/dist/assets/diff-view-8m9Rnct7.js +13 -0
  391. package/web/dist/assets/{directional-usage-BtjgT5nc.js → directional-usage-BerE4wJK.js} +1 -1
  392. package/web/dist/assets/dist-Br4Ra_c5.js +1 -0
  393. package/web/dist/assets/{download-DH68Y5Vz.js → download-HBguClwD.js} +1 -1
  394. package/web/dist/assets/dropdown-menu-CDv5Teql.js +1 -0
  395. package/web/dist/assets/excited-8dK2gfAF.webp +0 -0
  396. package/web/dist/assets/excited-B-w6ozXs.webp +0 -0
  397. package/web/dist/assets/excited-B4Sch7Ub.webp +0 -0
  398. package/web/dist/assets/excited-BPQk8ECE.webp +0 -0
  399. package/web/dist/assets/excited-BRFi0cue.webp +0 -0
  400. package/web/dist/assets/excited-BvbUAHvw.webp +0 -0
  401. package/web/dist/assets/excited-CCH-VUDr.webp +0 -0
  402. package/web/dist/assets/excited-TMExhEMj.webp +0 -0
  403. package/web/dist/assets/excited-cSRbau5J.webp +0 -0
  404. package/web/dist/assets/{external-link-BVYdhpSK.js → external-link-Bclznsu3.js} +1 -1
  405. package/web/dist/assets/file-preview-DQ7iQhe0.js +2 -0
  406. package/web/dist/assets/{file-DYpKJvYs.js → file-rCLi_p-R.js} +1 -1
  407. package/web/dist/assets/file-tree-Bm38qEZP.js +1 -0
  408. package/web/dist/assets/focused-XMnI1Trp.webp +0 -0
  409. package/web/dist/assets/{folder-CeFUSrsO.js → folder-leteY9jH.js} +1 -1
  410. package/web/dist/assets/follow-up-engine-Q1EcpRpB.js +1 -0
  411. package/web/dist/assets/git-pull-request-CURFMFaU.js +1 -0
  412. package/web/dist/assets/{git-pull-request-draft-DL1VMp1L.js → git-pull-request-draft-BZgJrUou.js} +1 -1
  413. package/web/dist/assets/git-tab-loading-CF0flOMS.js +1 -0
  414. package/web/dist/assets/github-DcvXvc4J.js +1 -0
  415. package/web/dist/assets/happy-B7LJPne_.webp +0 -0
  416. package/web/dist/assets/happy-CCpAho8w.webp +0 -0
  417. package/web/dist/assets/happy-Ch9wxHii.webp +0 -0
  418. package/web/dist/assets/happy-CnoCjXOf.webp +0 -0
  419. package/web/dist/assets/happy-DVeEwiyo.webp +0 -0
  420. package/web/dist/assets/happy-URIT6hFl.webp +0 -0
  421. package/web/dist/assets/happy-ZufSdCLm.webp +0 -0
  422. package/web/dist/assets/happy-kfLwwDLp.webp +0 -0
  423. package/web/dist/assets/happy-nVffy2Sx.webp +0 -0
  424. package/web/dist/assets/{host-usage-o1rC0TiP.js → host-usage-CX8OXl8q.js} +1 -1
  425. package/web/dist/assets/icon-tooltip-BMkyRHLt.js +1 -0
  426. package/web/dist/assets/impact-control-Deh1F44q.js +1 -0
  427. package/web/dist/assets/impact-model-Dj6tIycu.js +1 -0
  428. package/web/dist/assets/index-DuW72uFI.js +33 -0
  429. package/web/dist/assets/index-jRkTI5kE.css +2 -0
  430. package/web/dist/assets/{input-BxjGaO_P.js → input-BO795Un9.js} +1 -1
  431. package/web/dist/assets/laptop-D2EKUOdE.webp +0 -0
  432. package/web/dist/assets/layers-YoqiEcNh.js +1 -0
  433. package/web/dist/assets/layout-cards-Cvq2XaJL.js +1 -0
  434. package/web/dist/assets/{layout-grid-C4d5rrDE.js → layout-grid-CSvbdC6i.js} +1 -1
  435. package/web/dist/assets/left-BBmAC9hS.webp +0 -0
  436. package/web/dist/assets/left-BUX98ijg.webp +0 -0
  437. package/web/dist/assets/left-CCrTs359.webp +0 -0
  438. package/web/dist/assets/left-CxWtAZHp.webp +0 -0
  439. package/web/dist/assets/left-DDCoVDRG.webp +0 -0
  440. package/web/dist/assets/left-DFGwPnRL.webp +0 -0
  441. package/web/dist/assets/left-D_qxT7z_.webp +0 -0
  442. package/web/dist/assets/left-QXVHT2zO.webp +0 -0
  443. package/web/dist/assets/left-S_rwAL-X.webp +0 -0
  444. package/web/dist/assets/leg-left-0EW5L4pu.webp +0 -0
  445. package/web/dist/assets/leg-left-BGo9dZbQ.webp +0 -0
  446. package/web/dist/assets/leg-left-BZ8ETYLj.webp +0 -0
  447. package/web/dist/assets/leg-left-BahG1x_b.webp +0 -0
  448. package/web/dist/assets/leg-left-C-DJQ3Pt.webp +0 -0
  449. package/web/dist/assets/leg-left-C6ZvH8fW.webp +0 -0
  450. package/web/dist/assets/leg-left-DsfFyCf7.webp +0 -0
  451. package/web/dist/assets/leg-left-Iq6VC-OZ.webp +0 -0
  452. package/web/dist/assets/leg-left-rVU9cV-d.webp +0 -0
  453. package/web/dist/assets/leg-right-2MnCGKHj.webp +0 -0
  454. package/web/dist/assets/leg-right-BCgv_Tjj.webp +0 -0
  455. package/web/dist/assets/leg-right-BOxKTHZ9.webp +0 -0
  456. package/web/dist/assets/leg-right-BeDSbUV7.webp +0 -0
  457. package/web/dist/assets/leg-right-BwrF93s6.webp +0 -0
  458. package/web/dist/assets/leg-right-CU-y_n5h.webp +0 -0
  459. package/web/dist/assets/leg-right-DKSfNi2y.webp +0 -0
  460. package/web/dist/assets/leg-right-Dq0ze2e4.webp +0 -0
  461. package/web/dist/assets/leg-right-t34e1CvD.webp +0 -0
  462. package/web/dist/assets/lib-BQXq3kEf.js +1 -0
  463. package/web/dist/assets/loader-circle-DjzuGw6j.js +1 -0
  464. package/web/dist/assets/manager-chat-C4QqN-w6.js +1 -0
  465. package/web/dist/assets/manager-index-BGNDfiIy.js +1 -0
  466. package/web/dist/assets/manager-new-Dek6H9Bg.js +2 -0
  467. package/web/dist/assets/managers-Dufza9IX.js +1 -0
  468. package/web/dist/assets/{markdown-Di8pirEb.js → markdown-CP2EQDsL.js} +1 -1
  469. package/web/dist/assets/{markdown-rDA5iFAU.js → markdown-YWy3FUHK.js} +2 -2
  470. package/web/dist/assets/mascot-picker-0_LGzV_f.js +1 -0
  471. package/web/dist/assets/{message-square-CstvkIHe.js → message-square-beq8DjLH.js} +1 -1
  472. package/web/dist/assets/new-task-form-BgMiEphZ.js +2 -0
  473. package/web/dist/assets/pencil-RUM53auZ.js +1 -0
  474. package/web/dist/assets/picker-pill-BO6YUs1F.js +1 -0
  475. package/web/dist/assets/play-Cj3p2Q5t.js +1 -0
  476. package/web/dist/assets/plus-Bdmhj8CR.js +1 -0
  477. package/web/dist/assets/portrait-BJ2e30PF.webp +0 -0
  478. package/web/dist/assets/portrait-BeDbYw8Z.webp +0 -0
  479. package/web/dist/assets/portrait-Bq7D7LzX.webp +0 -0
  480. package/web/dist/assets/portrait-C6HtaggP.webp +0 -0
  481. package/web/dist/assets/portrait-CcOzDXGs.webp +0 -0
  482. package/web/dist/assets/portrait-D44z6yep.webp +0 -0
  483. package/web/dist/assets/portrait-DHLQRy13.webp +0 -0
  484. package/web/dist/assets/portrait-DU3qlTxc.webp +0 -0
  485. package/web/dist/assets/portrait-q94U_uD6.webp +0 -0
  486. package/web/dist/assets/project-router-xmadY-N9.js +1 -0
  487. package/web/dist/assets/queries-ba5qZ3kd.js +1 -0
  488. package/web/dist/assets/reasoning-effort-pill-B8Z1RaXL.js +1 -0
  489. package/web/dist/assets/reference-chip-C9pVQk05.js +1 -0
  490. package/web/dist/assets/reference-conflict-action-DxUm18aD.js +1 -0
  491. package/web/dist/assets/repo-git-DFf8ZGZv.js +1 -0
  492. package/web/dist/assets/right-BFOa1Ihi.webp +0 -0
  493. package/web/dist/assets/right-BLsBZrK1.webp +0 -0
  494. package/web/dist/assets/right-BVU3rYuj.webp +0 -0
  495. package/web/dist/assets/right-BbES4jIG.webp +0 -0
  496. package/web/dist/assets/right-C2klSA-G.webp +0 -0
  497. package/web/dist/assets/right-Cte2BTL5.webp +0 -0
  498. package/web/dist/assets/right-Dz7jYN17.webp +0 -0
  499. package/web/dist/assets/right-W2oGaUHb.webp +0 -0
  500. package/web/dist/assets/right-XJjUU0AU.webp +0 -0
  501. package/web/dist/assets/run-actions-CLIUiXwS.js +1 -0
  502. package/web/dist/assets/{run-diff-CFHlmgGA.js → run-diff-CxS_a1EO.js} +2 -2
  503. package/web/dist/assets/{save-C4TDysfG.js → save-zfKVAo2Y.js} +1 -1
  504. package/web/dist/assets/{scroll-within-D3mqUngk.js → scroll-within-DhWf-4MN.js} +1 -1
  505. package/web/dist/assets/search-CCE2KMtX.js +1 -0
  506. package/web/dist/assets/{search-x-BkezzsKh.js → search-x-BxcYdvqm.js} +1 -1
  507. package/web/dist/assets/{settings-2-DIHmg7wZ.js → settings-2-B0yYRU0q.js} +1 -1
  508. package/web/dist/assets/sheet-DxqNqi5S.js +1 -0
  509. package/web/dist/assets/skills-BmQ9hZ2c.js +1 -0
  510. package/web/dist/assets/sortable.esm-Dj7Kk-Wk.js +5 -0
  511. package/web/dist/assets/square--LrBHma0.js +1 -0
  512. package/web/dist/assets/standing-C42GacCE.webp +0 -0
  513. package/web/dist/assets/standing-C5Tul1Nv.webp +0 -0
  514. package/web/dist/assets/standing-CUU2Jka6.webp +0 -0
  515. package/web/dist/assets/standing-Ca5nprIS.webp +0 -0
  516. package/web/dist/assets/standing-CgOaMKRT.webp +0 -0
  517. package/web/dist/assets/standing-ClF4PE2-.webp +0 -0
  518. package/web/dist/assets/standing-CoS9fBjb.webp +0 -0
  519. package/web/dist/assets/standing-DZrhVTuG.webp +0 -0
  520. package/web/dist/assets/standing-MhG0Chks.webp +0 -0
  521. package/web/dist/assets/status-dot-Dxb9pPsK.js +1 -0
  522. package/web/dist/assets/tabs-CmEFauE4.js +1 -0
  523. package/web/dist/assets/{tag-B56iP2zA.js → tag-TWBVKabJ.js} +1 -1
  524. package/web/dist/assets/task-commits-sdhrDSta.js +1 -0
  525. package/web/dist/assets/{task-graph-ZjFyDrAV.js → task-graph-DqXUw-PM.js} +1 -1
  526. package/web/dist/assets/task-notes-ur3eZYQs.js +1 -0
  527. package/web/dist/assets/task-workspace-BvamqKbw.js +28 -0
  528. package/web/dist/assets/terminal-CmRAOyqu.js +1 -0
  529. package/web/dist/assets/terminal-drawer-BiRjtnip.js +1 -0
  530. package/web/dist/assets/{terminal-pane-CeYi-FvS.js → terminal-pane-YnSc_Vhs.js} +2 -2
  531. package/web/dist/assets/{textarea-BXN4nZ0d.js → textarea-C58jseO-.js} +1 -1
  532. package/web/dist/assets/toaster-5ad4wwJ9.js +1 -0
  533. package/web/dist/assets/tooltip-45rfBiq8.js +1 -0
  534. package/web/dist/assets/tracker-CcyqVPEo.js +4 -0
  535. package/web/dist/assets/triangle-alert-C1mTIqxM.js +1 -0
  536. package/web/dist/assets/typing-left-BWPbVi7e.webp +0 -0
  537. package/web/dist/assets/typing-right-HDY0V90O.webp +0 -0
  538. package/web/dist/assets/{upload-D_kW6AjR.js → upload-C2gxSnMR.js} +1 -1
  539. package/web/dist/assets/use-now-DD2atNhs.js +1 -0
  540. package/web/dist/assets/utils-Br_dqwn-.js +60 -0
  541. package/web/dist/assets/{workflow-j8scU63W.js → workflow-WvO4bTRt.js} +1 -1
  542. package/web/dist/assets/workflow-graph-B2oESW5u.js +13 -0
  543. package/web/dist/assets/worktree-lifecycle-BxYvSKsA.js +1 -0
  544. package/web/dist/assets/{worktree-lifecycle-operation-mYB7KCpQ.js → worktree-lifecycle-operation-BRID04bW.js} +1 -1
  545. package/web/dist/assets/x-CZSnHsZ4.js +1 -0
  546. package/web/dist/assets/{zoomable-image-CW-pQ6ZO.js → zoomable-image-DCITEnK-.js} +1 -1
  547. package/web/dist/index.html +70 -60
  548. package/web/dist/assets/agent-task-pickers-8skJH9bS.js +0 -1
  549. package/web/dist/assets/arrow-down-cBTb_EjO.js +0 -1
  550. package/web/dist/assets/arrow-left-BvR1Oqhc.js +0 -1
  551. package/web/dist/assets/arrow-up-Cn0IS81u.js +0 -1
  552. package/web/dist/assets/ask-answer-Cfb0vEFv.js +0 -1
  553. package/web/dist/assets/automations-route-B4axw9eb.js +0 -1
  554. package/web/dist/assets/check-B5omShEO.js +0 -1
  555. package/web/dist/assets/chevron-left-D74_-PJ_.js +0 -1
  556. package/web/dist/assets/chevron-right-C3fLn_fF.js +0 -1
  557. package/web/dist/assets/circle-check-j6r9xbE5.js +0 -1
  558. package/web/dist/assets/compare-variants-CDrFR7P_.js +0 -1
  559. package/web/dist/assets/composer-GntpkeQD.js +0 -18
  560. package/web/dist/assets/composer-attachments-Xa-qW8Eq.js +0 -3
  561. package/web/dist/assets/dashboard-CJW-Xk7f.js +0 -44
  562. package/web/dist/assets/diff-RPASOQVF.js +0 -3
  563. package/web/dist/assets/diff-view-Ckaab4uQ.js +0 -13
  564. package/web/dist/assets/file-preview-DOSEbcqV.js +0 -2
  565. package/web/dist/assets/git-tab-loading-DhclV71X.js +0 -1
  566. package/web/dist/assets/git-toolbar-Bk-3i42V.js +0 -1
  567. package/web/dist/assets/github-TdBnzj-H.js +0 -1
  568. package/web/dist/assets/icon-tooltip-CUJLXOxf.js +0 -1
  569. package/web/dist/assets/index-CDhEdFaZ.js +0 -33
  570. package/web/dist/assets/index-Dk1VTlxY.css +0 -2
  571. package/web/dist/assets/layout-cards-BYOEsNbu.js +0 -1
  572. package/web/dist/assets/lib-D2__YoPr.js +0 -1
  573. package/web/dist/assets/loader-circle-DCpZCAyT.js +0 -1
  574. package/web/dist/assets/manager-chat-B1Taq3Eg.js +0 -1
  575. package/web/dist/assets/manager-index-COwisKDf.js +0 -1
  576. package/web/dist/assets/manager-new-BdJPiBs2.js +0 -2
  577. package/web/dist/assets/manager-pickers-CvYpd5cU.js +0 -1
  578. package/web/dist/assets/managers-CDiETPHi.js +0 -1
  579. package/web/dist/assets/pencil-DWtoOm2f.js +0 -1
  580. package/web/dist/assets/picker-pill-DQICTO2N.js +0 -1
  581. package/web/dist/assets/play-BYwEI1EA.js +0 -1
  582. package/web/dist/assets/plus-BPopgSYQ.js +0 -1
  583. package/web/dist/assets/popover-DzdYqnHw.js +0 -1
  584. package/web/dist/assets/project-router-CmpQcVZp.js +0 -1
  585. package/web/dist/assets/queries-DOHu2y2B.js +0 -1
  586. package/web/dist/assets/reference-chip-ty5g_OLC.js +0 -1
  587. package/web/dist/assets/reference-conflict-action-B2LrO-o3.js +0 -1
  588. package/web/dist/assets/repo-git-CyoBxHfP.js +0 -1
  589. package/web/dist/assets/sheet-7RYAcp_E.js +0 -1
  590. package/web/dist/assets/skills-BBqk5FoM.js +0 -1
  591. package/web/dist/assets/sortable.esm-O2daV3YI.js +0 -5
  592. package/web/dist/assets/square-BPbl10lx.js +0 -1
  593. package/web/dist/assets/status-dot-C_5ryAFi.js +0 -1
  594. package/web/dist/assets/tabs-EEnYYrJF.js +0 -1
  595. package/web/dist/assets/task-commits-DFalvqkF.js +0 -1
  596. package/web/dist/assets/task-notes-DRDKGsIw.js +0 -1
  597. package/web/dist/assets/task-workspace-D2ak5sTE.js +0 -28
  598. package/web/dist/assets/terminal-B-JX8x9P.js +0 -1
  599. package/web/dist/assets/terminal-drawer-S0cBMANF.js +0 -1
  600. package/web/dist/assets/toaster-DrFdGtNN.js +0 -3
  601. package/web/dist/assets/tooltip-p6YPEpXC.js +0 -1
  602. package/web/dist/assets/tracker-CFDEuaFt.js +0 -4
  603. package/web/dist/assets/triangle-alert-Crbc2knA.js +0 -1
  604. package/web/dist/assets/use-now-DQpgbshl.js +0 -1
  605. package/web/dist/assets/utils-Df_1kJEk.js +0 -60
  606. package/web/dist/assets/workflow-graph-Cye5SBdg.js +0 -13
  607. package/web/dist/assets/worktree-lifecycle-Da61xsLH.js +0 -1
  608. package/web/dist/assets/x-sQR-jRBj.js +0 -1
@@ -0,0 +1,874 @@
1
+ import { spawn as nodeSpawn } from 'node:child_process';
2
+ import { closeSync, existsSync, fstatSync, openSync, readdirSync, readSync, statSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { delimiter, dirname, join, resolve as resolvePath } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { assertReasoningEffortSupported, isSignalTerminationExit, prependSystemPrompt, trackChildExit } from './agent-runner.js';
7
+ import { buildChildEnv } from './agent-env.js';
8
+ import { EOF_KILL_GRACE_MS, EOF_TERM_GRACE_MS } from './claude-cli-runner.js';
9
+ import { disclaimedCommand } from './disclaim-spawn.js';
10
+ import { kimiHome } from './kimi-home.js';
11
+ import { readNdjson } from './ndjson.js';
12
+ import { acpMcpCapabilities, skippedServersNote, toAcpMcpServers } from './private-mcp.js';
13
+ import { costWeightedTokens } from './usage.js';
14
+ import { abortKimiTurn, createKimiUiState, kimiSessionStarted, kimiTurnStarted, mapKimiMessage, } from './kimi-ui-mapper.js';
15
+ const DEFAULT_TIMEOUT_MS = 30 * 60_000;
16
+ /** `initialize` / `session/new|resume` / `session/set_config_option` are handshakes: bounded,
17
+ * unlike a prompt (the run's own deadline owns a turn). */
18
+ const HANDSHAKE_TIMEOUT_MS = 90_000;
19
+ const AUTO_END_DELAY_MS = 250;
20
+ /**
21
+ * Kimi appends a turn's last `usage.record` around the moment it answers the prompt, so the reader
22
+ * polls until the log's own `turn.ended` marker shows the turn is fully written — bounded, since a
23
+ * missing marker must cost a turn its usage, never hang the session.
24
+ */
25
+ const USAGE_POLL_MS = 50;
26
+ const USAGE_SETTLE_MAX_MS = 2_000;
27
+ /**
28
+ * The tools cezar's `allowedTools` vocabulary names. Kimi uses the same names. Kimi's own tools
29
+ * (Agent, TodoList, FetchURL…) are outside that vocabulary and stay allowed, as every other
30
+ * backend treats them. Which of these can actually be DENIED is a different, smaller set — see
31
+ * `PERMISSION_GATED_TOOLS`.
32
+ */
33
+ const ALLOWLISTABLE_TOOLS = new Set(['Read', 'Edit', 'Write', 'Bash', 'Grep', 'Glob']);
34
+ /**
35
+ * Of those, the ones Kimi asks permission for in its `default` mode — the only point where cezar
36
+ * can say no. In the captured session (`__fixtures__/kimi/acp-session.ndjson`) Kimi prompted for
37
+ * `Bash` and ran `Edit` without asking; no `mode` it offers (`default`/`plan`/`auto`/`yolo`) is
38
+ * documented to make edits prompt, and none was verified to.
39
+ */
40
+ const PERMISSION_GATED_TOOLS = new Set(['Bash']);
41
+ /**
42
+ * `AgentRunner` over Kimi Code's Agent Client Protocol server (`kimi acp`): JSON-RPC 2.0,
43
+ * newline-delimited, over stdin/stdout — the transport Zed and the other ACP editors use.
44
+ * Contract: https://agentclientprotocol.com. The wire was captured from Kimi Code CLI 2.1.1
45
+ * (`agentInfo.version`; its bundled ACP agent is 0.39.1) — `__fixtures__/kimi/acp-session.ndjson`.
46
+ *
47
+ * One long-lived process per session: `session/new` (or `session/resume` for "Continue", falling
48
+ * back to a fresh session when Kimi no longer knows the id), then one `session/prompt` per turn —
49
+ * its RESPONSE is the end of the turn. ACP has no mid-turn steering, so a follow-up typed during a
50
+ * turn is queued and sent as the next turn. `session/cancel` interrupts. A prompt the agent never
51
+ * answers — it died, or cezar stopped it — is settled by the runner (`abortKimiTurn`), never left
52
+ * open and never reported as a clean turn.
53
+ *
54
+ * Kimi has no system-prompt channel over ACP, so `spec.systemPrompt` rides as a leading block of
55
+ * the opening message (`prependSystemPrompt`), as with codex and opencode. The model is chosen
56
+ * with `session/set_config_option`; an id Kimi does not offer fails the run loudly rather than
57
+ * running on the default. Private MCP servers ride ACP's `session/new|resume` `mcpServers`.
58
+ *
59
+ * Permissions: cezar's default permission mode is autonomous, so every `session/request_permission`
60
+ * is answered — approved, except `Bash` when the step's `allowedTools` leaves it out or a
61
+ * `bashAllowlist` narrows it (the prompt carries a truncated command, so a prefix check could not
62
+ * be trusted — fail closed, as pi does). That is the WHOLE of the enforcement: Kimi runs `Edit`,
63
+ * `Write`, `Read`, `Grep` and `Glob` without asking, so — like Codex and OpenCode — it cannot
64
+ * enforce `allowedTools` for them, and a step that excludes them gets a note saying so rather
65
+ * than a sandbox that is not there.
66
+ *
67
+ * Token usage is not on the ACP wire; Kimi writes it to its own session log. See
68
+ * `KimiUsageReader` and the header of `kimi-ui-mapper.ts`.
69
+ */
70
+ export class KimiRunner {
71
+ backend = 'kimi';
72
+ bin;
73
+ timeoutMs;
74
+ handshakeTimeoutMs;
75
+ lastSession = null;
76
+ constructor(opts = {}) {
77
+ this.bin = opts.bin ?? resolveKimiExecutable();
78
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
79
+ this.handshakeTimeoutMs = opts.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS;
80
+ }
81
+ run(spec, onEvent) {
82
+ return this.startSession(spec, onEvent, { autoEndAfterFirstTurn: true }).result;
83
+ }
84
+ async interrupt() {
85
+ this.lastSession?.interrupt();
86
+ }
87
+ startSession(spec, onEvent, opts = {}) {
88
+ assertReasoningEffortSupported('kimi', spec.reasoningEffort);
89
+ const session = new KimiSession(this.bin, spec.timeoutMs ?? this.timeoutMs, this.handshakeTimeoutMs, spec, onEvent, opts);
90
+ this.lastSession = session;
91
+ return session;
92
+ }
93
+ }
94
+ /**
95
+ * `CEZ_KIMI_BIN`, else the dry-run mock, else `kimi` — found on PATH or, failing that, where Kimi's
96
+ * installer puts it (`~/.kimi-code/bin/kimi`). The installer adds that directory to the user's
97
+ * shell profile only, so a cockpit started by launchd or a desktop session would otherwise
98
+ * report Kimi missing on a machine where it works in every terminal.
99
+ */
100
+ export function resolveKimiExecutable(env = process.env) {
101
+ if (env.CEZ_KIMI_BIN)
102
+ return env.CEZ_KIMI_BIN;
103
+ if (env.CEZ_DRY_RUN === '1')
104
+ return mockKimiPath();
105
+ if (onPath('kimi', env.PATH))
106
+ return 'kimi';
107
+ const installed = join(env.HOME ?? homedir(), '.kimi-code', 'bin', 'kimi');
108
+ return existsSync(installed) ? installed : 'kimi';
109
+ }
110
+ function onPath(bin, path) {
111
+ return (path ?? '').split(delimiter).some((dir) => dir !== '' && existsSync(join(dir, bin)));
112
+ }
113
+ class KimiSession {
114
+ bin;
115
+ limitMs;
116
+ handshakeTimeoutMs;
117
+ spec;
118
+ onEvent;
119
+ opts;
120
+ result;
121
+ child;
122
+ env;
123
+ hasExited;
124
+ exited;
125
+ nextId = 1;
126
+ pending = new Map();
127
+ /** Set once the agent's output is gone: every waiting request is rejected, every later one too. */
128
+ closedReason = null;
129
+ stdinOpen = true;
130
+ sessionId;
131
+ ready;
132
+ promptId;
133
+ /** True once the opening prompt has been sent; until then follow-ups queue behind it. */
134
+ opened = false;
135
+ imagesSupported = true;
136
+ queued = [];
137
+ uiState = createKimiUiState();
138
+ usage;
139
+ toolCalls = [];
140
+ announced = new Set();
141
+ textChunks = [];
142
+ /** Cost-weighted tokens of the live turn, and of the turns already completed. */
143
+ tokensUsed = 0;
144
+ runTokens = 0;
145
+ /** Turns Kimi itself answered — the only ones whose usage the session log can be expected to hold. */
146
+ turnsAnswered = 0;
147
+ lastStopReason = 'end_turn';
148
+ autoEndTimer;
149
+ timers = [];
150
+ stderr = [];
151
+ spawnFailed = null;
152
+ timedOut = false;
153
+ /** Set when cezar asked the session to close — an unanswered turn then ended because we said so. */
154
+ endRequested = false;
155
+ /** Set when WE signal the child, so its 143 is read as our teardown, not a Kimi failure. */
156
+ terminatedByCezar = false;
157
+ killEscalated = false;
158
+ constructor(bin, limitMs, handshakeTimeoutMs, spec, onEvent, opts) {
159
+ this.bin = bin;
160
+ this.limitMs = limitMs;
161
+ this.handshakeTimeoutMs = handshakeTimeoutMs;
162
+ this.spec = spec;
163
+ this.onEvent = onEvent;
164
+ this.opts = opts;
165
+ this.env = buildChildEnv({ backend: 'kimi', extraEnv: spec.env });
166
+ const [file, argv] = disclaimedCommand(bin, ['acp'], this.env);
167
+ this.child = nodeSpawn(file, argv, { cwd: spec.cwd, env: this.env });
168
+ this.hasExited = trackChildExit(this.child);
169
+ this.exited = waitForExit(this.child);
170
+ this.child.on('error', (err) => {
171
+ this.spawnFailed ??= kimiSpawnError(err, bin);
172
+ this.close('kimi acp failed to start');
173
+ });
174
+ this.child.stderr.setEncoding('utf8');
175
+ this.child.stderr.on('data', (chunk) => this.stderr.push(chunk));
176
+ if (limitMs > 0) {
177
+ const deadline = setTimeout(() => {
178
+ this.timedOut = true;
179
+ this.interrupt();
180
+ }, limitMs);
181
+ deadline.unref?.();
182
+ this.timers.push(deadline);
183
+ }
184
+ this.ready = this.bootstrap();
185
+ this.result = this.lifecycle();
186
+ }
187
+ get open() {
188
+ return this.stdinOpen;
189
+ }
190
+ get pid() {
191
+ return this.child.pid;
192
+ }
193
+ sendMessage(content) {
194
+ if (!this.stdinOpen)
195
+ return false;
196
+ if (this.autoEndTimer) {
197
+ clearTimeout(this.autoEndTimer);
198
+ this.autoEndTimer = undefined;
199
+ }
200
+ if (content.length === 0)
201
+ return true;
202
+ // ACP has no steering: a message typed mid-turn — or before the opening prompt has even gone
203
+ // out — becomes the next turn. Only one `session/prompt` is ever in flight.
204
+ if (this.promptId !== undefined || !this.opened) {
205
+ this.queued.push(content);
206
+ return true;
207
+ }
208
+ const blocks = this.toAcp(content);
209
+ if (blocks.length > 0)
210
+ this.prompt(blocks);
211
+ return true;
212
+ }
213
+ /** Graceful close: end input, then SIGTERM→SIGKILL for a CLI that ignores EOF. */
214
+ end() {
215
+ if (!this.stdinOpen)
216
+ return;
217
+ this.stdinOpen = false;
218
+ this.endRequested = true;
219
+ this.closeStdin();
220
+ this.after(EOF_TERM_GRACE_MS, () => this.escalate());
221
+ }
222
+ /** Hard stop: cancel the turn best-effort, then SIGTERM now and SIGKILL if it is ignored. */
223
+ interrupt() {
224
+ if (this.sessionId && this.promptId !== undefined) {
225
+ this.write({ jsonrpc: '2.0', method: 'session/cancel', params: { sessionId: this.sessionId } });
226
+ }
227
+ this.stdinOpen = false;
228
+ this.endRequested = true;
229
+ this.closeStdin();
230
+ this.escalate();
231
+ }
232
+ /** Cancel's escalation (`run.ts`, after its own grace): the process goes now. */
233
+ hardStop() {
234
+ this.interrupt();
235
+ this.signal('SIGKILL');
236
+ }
237
+ // ---- lifecycle ------------------------------------------------------------
238
+ async lifecycle() {
239
+ const reading = this.readLoop();
240
+ let sessionError;
241
+ try {
242
+ await this.ready;
243
+ }
244
+ catch (err) {
245
+ // A transport that closed mid-handshake is explained by the exit, read below — not by the
246
+ // "closed" rejection. Neither is a stop cezar asked for.
247
+ if (this.closedReason === null && !this.endRequested) {
248
+ sessionError = err instanceof Error ? err : new Error(String(err));
249
+ }
250
+ this.stdinOpen = false;
251
+ this.closeStdin();
252
+ this.escalate();
253
+ }
254
+ await reading;
255
+ const exitCode = await this.exited;
256
+ for (const timer of this.timers)
257
+ clearTimeout(timer);
258
+ if (this.autoEndTimer)
259
+ clearTimeout(this.autoEndTimer);
260
+ this.stdinOpen = false;
261
+ if (this.spawnFailed)
262
+ throw this.spawnFailed;
263
+ if (sessionError)
264
+ return this.failSession(sessionError.message);
265
+ const exitedBadly = exitCode !== 0 && exitCode !== null && !(this.terminatedByCezar && isSignalTerminationExit(exitCode));
266
+ if (this.promptId !== undefined) {
267
+ // Kimi went away with a prompt unanswered: no response will ever end that turn, so settle it.
268
+ this.promptId = undefined;
269
+ for (const record of this.usage?.read().records ?? [])
270
+ this.emitUi((state) => mapKimiMessage(record, state));
271
+ if (this.timedOut)
272
+ this.emitUi((state) => abortKimiTurn(state, 'timeout'));
273
+ else if (this.endRequested || this.terminatedByCezar)
274
+ this.emitUi((state) => abortKimiTurn(state, 'cancelled'));
275
+ else {
276
+ const message = exitedBadly
277
+ ? this.exitMessage(exitCode)
278
+ : `kimi acp exited${exitCode === null ? '' : ` with code ${exitCode}`} without answering the prompt`;
279
+ this.emitUi((state) => abortKimiTurn(state, 'error', message));
280
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: 'error' });
281
+ throw new Error(message);
282
+ }
283
+ }
284
+ const base = {
285
+ text: this.textChunks.join('\n').trim(),
286
+ toolCalls: this.toolCalls,
287
+ tokensUsed: this.runTokens + this.tokensUsed,
288
+ sessionId: this.sessionId ?? this.spec.sessionId,
289
+ };
290
+ if (this.timedOut) {
291
+ const mins = Math.round((this.limitMs / 60_000) * 10) / 10;
292
+ this.emit({ type: 'error', message: `kimi acp timed out after ${mins}m and was killed` });
293
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: 'timeout' });
294
+ this.emit({ type: 'done' });
295
+ return base;
296
+ }
297
+ if (exitedBadly)
298
+ return this.failSession(this.exitMessage(exitCode));
299
+ if (!this.sessionId && !this.endRequested)
300
+ return this.failSession('kimi acp exited before it started a session');
301
+ if (base.tokensUsed === 0 && this.turnsAnswered > 0) {
302
+ this.emit({ type: 'note', message: 'token usage not found in the kimi session log' });
303
+ }
304
+ const reason = this.turnsAnswered === 0 && this.endRequested ? 'cancelled' : this.lastStopReason;
305
+ this.opts.onUiEvent?.({ type: 'session.ended', reason });
306
+ this.emit({ type: 'done' });
307
+ return base;
308
+ }
309
+ /** The session could not start or keep going: said ONCE, on both streams, then thrown. */
310
+ failSession(message) {
311
+ this.opts.onUiEvent?.({ type: 'session.error', message, fatal: true });
312
+ this.emit({ type: 'error', message });
313
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: 'error' });
314
+ throw new Error(message);
315
+ }
316
+ exitMessage(exitCode) {
317
+ const detail = this.stderr.join('').trim().split('\n').slice(-3).join(' | ');
318
+ return `kimi acp exited with code ${exitCode}${detail ? ` — ${truncate(detail, 400)}` : ''}`;
319
+ }
320
+ async readLoop() {
321
+ try {
322
+ for await (const line of readNdjson(this.child.stdout)) {
323
+ let msg;
324
+ try {
325
+ msg = JSON.parse(line);
326
+ }
327
+ catch {
328
+ this.emit({ type: 'note', message: `kimi: skipped unparseable ACP line: ${truncate(line)}` });
329
+ continue;
330
+ }
331
+ await this.handle(msg);
332
+ }
333
+ }
334
+ catch {
335
+ // a destroyed stdout ends the read like EOF does; the exit explains why
336
+ }
337
+ finally {
338
+ this.close('kimi acp closed its output');
339
+ }
340
+ }
341
+ // ---- protocol -----------------------------------------------------------
342
+ async bootstrap() {
343
+ const handshake = { timeoutMs: this.handshakeTimeoutMs };
344
+ const init = await this.request('initialize', {
345
+ protocolVersion: 1,
346
+ // cezar serves no files or terminals: Kimi uses its own tools in `cwd`.
347
+ clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
348
+ }, handshake);
349
+ const caps = isRecord(init.agentCapabilities) ? init.agentCapabilities : {};
350
+ // Kimi 2.1.1 advertises images; an agent that says nothing is trusted, one that says no is not.
351
+ this.imagesSupported = !(isRecord(caps.promptCapabilities) && caps.promptCapabilities.image === false);
352
+ // Private MCP servers (spec 2026-10-07-private-project-mcp) ride ACP's per-session list.
353
+ const { mcpServers, skipped } = toAcpMcpServers(this.spec.mcpServers ?? [], acpMcpCapabilities(init));
354
+ if (skipped.length) {
355
+ this.emit({ type: 'note', message: skippedServersNote('kimi', skipped, 'the CLI did not advertise that MCP transport') });
356
+ }
357
+ this.noteUnenforceableTools();
358
+ const base = {
359
+ cwd: this.spec.cwd,
360
+ mcpServers,
361
+ ...(this.spec.additionalDirectories?.length ? { additionalDirectories: this.spec.additionalDirectories } : {}),
362
+ };
363
+ let configOptions;
364
+ if (this.spec.resume && this.spec.sessionId) {
365
+ try {
366
+ const res = await this.request('session/resume', { sessionId: this.spec.sessionId, ...base }, handshake);
367
+ this.sessionId = this.spec.sessionId;
368
+ configOptions = res.configOptions;
369
+ }
370
+ catch (err) {
371
+ if (this.closedReason !== null)
372
+ throw err;
373
+ // Kimi forgot the session (another home, a cleared log): Continue still runs, from scratch.
374
+ this.emit({
375
+ type: 'note',
376
+ message: `Kimi could not resume session ${this.spec.sessionId} (${err instanceof Error ? err.message : String(err)}) — starting a fresh session`,
377
+ });
378
+ }
379
+ }
380
+ if (!this.sessionId) {
381
+ const res = await this.request('session/new', base, handshake);
382
+ this.sessionId = typeof res.sessionId === 'string' ? res.sessionId : undefined;
383
+ configOptions = res.configOptions;
384
+ }
385
+ const sessionId = this.sessionId;
386
+ if (!sessionId)
387
+ throw new Error('kimi acp returned no session id');
388
+ this.emit({ type: 'session', sessionId });
389
+ const logHome = kimiHome(this.env);
390
+ this.usage = logHome ? new KimiUsageReader(logHome, sessionId) : undefined;
391
+ const model = this.spec.model?.trim();
392
+ if (model && selectValue(configOptions, 'model') !== model) {
393
+ const offered = selectOptions(configOptions, 'model');
394
+ if (offered.length > 0 && !offered.includes(model)) {
395
+ throw new Error(`kimi: model "${model}" is not offered by this Kimi account (available: ${offered.join(', ')})`);
396
+ }
397
+ const res = await this.request('session/set_config_option', { sessionId, configId: 'model', value: model }, handshake);
398
+ configOptions = res.configOptions ?? configOptions;
399
+ }
400
+ this.emitUi((state) => kimiSessionStarted(state, sessionId, configOptions));
401
+ this.prompt(this.toAcp([
402
+ ...(this.spec.images ?? []),
403
+ { type: 'text', text: prependSystemPrompt(this.spec.systemPrompt, this.spec.userPrompt) },
404
+ ]));
405
+ }
406
+ /** A step that excludes a tool Kimi never asks about must not look sandboxed. */
407
+ noteUnenforceableTools() {
408
+ const allowed = this.spec.allowedTools;
409
+ if (!allowed || allowed.length === 0)
410
+ return;
411
+ const unenforced = [...ALLOWLISTABLE_TOOLS].filter((tool) => !PERMISSION_GATED_TOOLS.has(tool) && !allowed.includes(tool));
412
+ if (unenforced.length === 0)
413
+ return;
414
+ this.emit({
415
+ type: 'note',
416
+ message: `kimi: allowedTools cannot keep ${unenforced.join(', ')} out — Kimi runs them without asking permission (only Bash can be denied)`,
417
+ });
418
+ }
419
+ /** Start one turn. Its response arrives in `handle`. */
420
+ prompt(prompt) {
421
+ if (!this.sessionId || !this.stdinOpen || this.closedReason !== null)
422
+ return;
423
+ this.opened = true;
424
+ this.emitUi((state) => kimiTurnStarted(state));
425
+ const id = this.nextId++;
426
+ this.promptId = id;
427
+ // Settled in `handle`, which must see the response BEFORE anything else does; a lost
428
+ // transport is settled by the lifecycle, which knows why the agent went away.
429
+ this.pending.set(id, { resolve: () => undefined, reject: () => undefined });
430
+ this.write({ jsonrpc: '2.0', id, method: 'session/prompt', params: { sessionId: this.sessionId, prompt } });
431
+ }
432
+ async handle(msg) {
433
+ // Agent → client request: a permission prompt, or something cezar does not serve.
434
+ if (typeof msg.method === 'string' && msg.id !== undefined) {
435
+ this.answerRequest(msg.id, msg.method, msg.params ?? {});
436
+ return;
437
+ }
438
+ if (typeof msg.id === 'number' && msg.id === this.promptId) {
439
+ // The turn is over. Its token usage lives in Kimi's session log, not on this wire: feed it
440
+ // to the mapper first, so `turn.completed` carries the turn's counts.
441
+ this.promptId = undefined;
442
+ this.pending.delete(msg.id);
443
+ this.turnsAnswered += 1;
444
+ for (const record of await this.usageRecords())
445
+ this.emitUi((state) => mapKimiMessage(record, state));
446
+ this.emitUi((state) => mapKimiMessage(msg, state));
447
+ this.afterTurn();
448
+ return;
449
+ }
450
+ // A handshake response settles its request — and only that: its error is the session's
451
+ // failure, reported once by the lifecycle, not a second time by the mapper.
452
+ if (msg.id !== undefined && msg.method === undefined) {
453
+ this.dispatchResponse(msg);
454
+ return;
455
+ }
456
+ this.emitUi((state) => mapKimiMessage(msg, state));
457
+ }
458
+ async usageRecords() {
459
+ if (!this.usage)
460
+ return [];
461
+ const records = [];
462
+ const deadline = Date.now() + USAGE_SETTLE_MAX_MS;
463
+ for (;;) {
464
+ const read = this.usage.read();
465
+ records.push(...read.records);
466
+ if (read.turnEnded || Date.now() >= deadline)
467
+ return records;
468
+ await new Promise((resolve) => setTimeout(resolve, USAGE_POLL_MS));
469
+ }
470
+ }
471
+ afterTurn() {
472
+ if (!this.stdinOpen)
473
+ return;
474
+ if (this.queued.length > 0) {
475
+ const blocks = this.toAcp(this.queued.splice(0).flat());
476
+ if (blocks.length > 0) {
477
+ this.prompt(blocks);
478
+ return;
479
+ }
480
+ }
481
+ if (this.opts.autoEndAfterFirstTurn && !this.autoEndTimer) {
482
+ this.autoEndTimer = setTimeout(() => this.end(), AUTO_END_DELAY_MS);
483
+ this.autoEndTimer.unref?.();
484
+ }
485
+ }
486
+ /** cezar content → ACP prompt blocks. Consecutive texts (queued follow-ups) merge into one. */
487
+ toAcp(content) {
488
+ const blocks = [];
489
+ let dropped = 0;
490
+ for (const block of content) {
491
+ if (block.type === 'image') {
492
+ if (this.imagesSupported)
493
+ blocks.push({ type: 'image', data: block.source.data, mimeType: block.source.media_type });
494
+ else
495
+ dropped += 1;
496
+ continue;
497
+ }
498
+ if (!block.text)
499
+ continue;
500
+ const last = blocks.at(-1);
501
+ if (last?.type === 'text')
502
+ last.text = `${last.text}\n\n${block.text}`;
503
+ else
504
+ blocks.push({ type: 'text', text: block.text });
505
+ }
506
+ if (dropped > 0)
507
+ this.emit({ type: 'note', message: `kimi does not accept images; dropped ${dropped}` });
508
+ return blocks;
509
+ }
510
+ answerRequest(id, method, params) {
511
+ if (method !== 'session/request_permission') {
512
+ this.write({ jsonrpc: '2.0', id, error: { code: -32601, message: `cezar does not serve ${method}` } });
513
+ return;
514
+ }
515
+ const options = Array.isArray(params.options) ? params.options.filter(isRecord) : [];
516
+ const toolCall = isRecord(params.toolCall) ? params.toolCall : {};
517
+ const tool = typeof toolCall.title === 'string' ? toolCall.title : '';
518
+ const denied = this.deniedReason(tool);
519
+ const pick = denied
520
+ ? options.find((o) => o.kind === 'reject_once') ?? options.find((o) => String(o.kind).startsWith('reject'))
521
+ : options.find((o) => o.kind === 'allow_once') ?? options.find((o) => String(o.kind).startsWith('allow'));
522
+ if (denied)
523
+ this.emit({ type: 'note', message: `kimi: denied ${tool} — ${denied}` });
524
+ const outcome = pick && typeof pick.optionId === 'string' ? { outcome: 'selected', optionId: pick.optionId } : { outcome: 'cancelled' };
525
+ this.write({ jsonrpc: '2.0', id, result: { outcome } });
526
+ }
527
+ deniedReason(tool) {
528
+ if (!ALLOWLISTABLE_TOOLS.has(tool))
529
+ return undefined;
530
+ const allowed = this.spec.allowedTools;
531
+ if (allowed && allowed.length > 0 && !allowed.includes(tool))
532
+ return 'not in this step\'s allowedTools';
533
+ if (tool === 'Bash' && this.spec.bashAllowlist && this.spec.bashAllowlist.length > 0) {
534
+ return 'Kimi cannot enforce a bashAllowlist prefix, so Bash is off for this step';
535
+ }
536
+ return undefined;
537
+ }
538
+ request(method, params, options = {}) {
539
+ if (this.closedReason !== null)
540
+ return Promise.reject(new Error(this.closedReason));
541
+ const id = this.nextId++;
542
+ const promise = new Promise((resolve, reject) => {
543
+ const entry = { resolve, reject };
544
+ if (options.timeoutMs && options.timeoutMs > 0) {
545
+ entry.timer = setTimeout(() => {
546
+ if (!this.pending.delete(id))
547
+ return;
548
+ reject(new Error(`kimi: ${method} got no answer within ${formatMs(options.timeoutMs)}`));
549
+ }, options.timeoutMs);
550
+ entry.timer.unref?.();
551
+ }
552
+ this.pending.set(id, entry);
553
+ });
554
+ this.write({ jsonrpc: '2.0', id, method, params });
555
+ return promise;
556
+ }
557
+ dispatchResponse(msg) {
558
+ if (typeof msg.id !== 'number')
559
+ return;
560
+ const pending = this.pending.get(msg.id);
561
+ if (!pending)
562
+ return;
563
+ this.pending.delete(msg.id);
564
+ if (pending.timer)
565
+ clearTimeout(pending.timer);
566
+ if (msg.error !== undefined)
567
+ pending.reject(new Error(`kimi: ${errorText(msg.error)}`));
568
+ else
569
+ pending.resolve(isRecord(msg.result) ? msg.result : {});
570
+ }
571
+ /** The agent's output is gone: nothing can answer a waiting request any more. Idempotent. */
572
+ close(reason) {
573
+ this.closedReason ??= reason;
574
+ for (const request of this.pending.values()) {
575
+ if (request.timer)
576
+ clearTimeout(request.timer);
577
+ request.reject(new Error(this.closedReason));
578
+ }
579
+ this.pending.clear();
580
+ }
581
+ write(message) {
582
+ if (this.child.stdin.destroyed || this.child.stdin.writableEnded)
583
+ return;
584
+ try {
585
+ this.child.stdin.write(`${JSON.stringify(message)}\n`);
586
+ }
587
+ catch {
588
+ // the read/exit path owns settlement
589
+ }
590
+ }
591
+ // ---- teardown -----------------------------------------------------------
592
+ closeStdin() {
593
+ try {
594
+ this.child.stdin.end();
595
+ }
596
+ catch {
597
+ // already gone
598
+ }
599
+ }
600
+ /** SIGTERM now, SIGKILL if that is ignored — once, however many paths ask. */
601
+ escalate() {
602
+ if (this.killEscalated)
603
+ return;
604
+ this.killEscalated = true;
605
+ this.signal('SIGTERM');
606
+ this.after(EOF_KILL_GRACE_MS, () => this.signal('SIGKILL'));
607
+ }
608
+ signal(sig) {
609
+ if (this.hasExited())
610
+ return;
611
+ this.terminatedByCezar = true;
612
+ try {
613
+ this.child.kill(sig);
614
+ }
615
+ catch {
616
+ // already gone
617
+ }
618
+ }
619
+ after(ms, fn) {
620
+ const timer = setTimeout(fn, ms);
621
+ timer.unref?.();
622
+ this.timers.push(timer);
623
+ }
624
+ // ---- emission -----------------------------------------------------------
625
+ emit(event) {
626
+ this.onEvent?.(event);
627
+ }
628
+ /** Map into v2, and derive the v1 stream from the same mapped events so the two cannot drift. */
629
+ emitUi(step) {
630
+ const mapped = step(this.uiState);
631
+ this.uiState = mapped.state;
632
+ for (const event of mapped.events) {
633
+ this.opts.onUiEvent?.(event);
634
+ this.emitV1(event);
635
+ }
636
+ }
637
+ emitV1(event) {
638
+ switch (event.type) {
639
+ case 'item.updated':
640
+ if (event.item.kind === 'tool' && event.item.input !== undefined)
641
+ this.announceTool(event.item);
642
+ return;
643
+ case 'item.completed':
644
+ if (event.item.kind === 'message' && event.item.text.trim()) {
645
+ this.textChunks.push(event.item.text);
646
+ this.emit({ type: 'text', text: event.item.text });
647
+ }
648
+ else if (event.item.kind === 'tool') {
649
+ this.announceTool(event.item);
650
+ this.emit({
651
+ type: 'tool-result',
652
+ toolCallId: event.item.id,
653
+ result: event.item.output ?? event.item.error ?? '',
654
+ isError: event.item.status === 'failed',
655
+ });
656
+ }
657
+ return;
658
+ case 'usage.updated': {
659
+ const u = event.usage;
660
+ this.tokensUsed = costWeightedTokens({
661
+ input_tokens: u.input,
662
+ output_tokens: u.output,
663
+ cache_read_input_tokens: u.cacheRead,
664
+ cache_creation_input_tokens: u.cacheWrite,
665
+ });
666
+ this.emit({ type: 'token-usage', tokensUsed: this.runTokens + this.tokensUsed });
667
+ return;
668
+ }
669
+ case 'turn.completed':
670
+ this.lastStopReason = event.stopReason;
671
+ this.runTokens += this.tokensUsed;
672
+ this.tokensUsed = 0;
673
+ this.emit({ type: 'turn-end' });
674
+ return;
675
+ case 'session.error':
676
+ this.emit({ type: 'error', message: event.message });
677
+ return;
678
+ default:
679
+ return;
680
+ }
681
+ }
682
+ announceTool(item) {
683
+ if (this.announced.has(item.id))
684
+ return;
685
+ this.announced.add(item.id);
686
+ this.toolCalls.push({ id: item.id, name: item.name, input: item.input });
687
+ this.emit({ type: 'tool-call', id: item.id, tool: item.name, input: item.input });
688
+ }
689
+ }
690
+ /**
691
+ * Reads new `usage.record` lines from Kimi's own session log:
692
+ * `<KIMI_CODE_HOME>/sessions/<workdir-key>/<sessionId>/agents/<agent>/wire.jsonl`, one file per
693
+ * agent (`main`, plus one per sub-agent — their tokens are spent on this run too). The workdir
694
+ * key is Kimi's private hash of the cwd, so the session dir is FOUND by its id rather than
695
+ * derived. Each file is read from where the last read stopped; on a resumed session the first
696
+ * read starts at the current end, so earlier turns are not billed again.
697
+ *
698
+ * Never throws: a missing or unreadable log means a turn without usage, not a failed run.
699
+ */
700
+ export class KimiUsageReader {
701
+ home;
702
+ sessionId;
703
+ sessionDir;
704
+ offsets = new Map();
705
+ primed = false;
706
+ constructor(home, sessionId) {
707
+ this.home = home;
708
+ this.sessionId = sessionId;
709
+ this.prime();
710
+ }
711
+ /** New usage records since the last read, and whether the main agent's turn has ended. */
712
+ read() {
713
+ const records = [];
714
+ let turnEnded = false;
715
+ try {
716
+ const dir = this.locate();
717
+ // No log at all (another home, a mock): nothing will arrive by waiting for it.
718
+ if (!dir)
719
+ return { records, turnEnded: true };
720
+ const agentsDir = join(dir, 'agents');
721
+ for (const agent of readdirSync(agentsDir)) {
722
+ const file = join(agentsDir, agent, 'wire.jsonl');
723
+ if (!existsSync(file))
724
+ continue;
725
+ const text = this.readNewLines(file);
726
+ if (!text)
727
+ continue;
728
+ for (const line of text.split('\n')) {
729
+ // Cheap prefilter (most lines are tool output); the decision is the parsed `type`.
730
+ if (!line.includes('usage.record') && !line.includes('turn.ended'))
731
+ continue;
732
+ let value;
733
+ try {
734
+ value = JSON.parse(line);
735
+ }
736
+ catch {
737
+ continue; // a torn line is skipped, never fatal
738
+ }
739
+ if (!isRecord(value))
740
+ continue;
741
+ if (value.type === 'usage.record')
742
+ records.push(value);
743
+ else if (value.type === 'turn.ended' && agent === 'main')
744
+ turnEnded = true;
745
+ }
746
+ }
747
+ }
748
+ catch {
749
+ // degrade: no usage for this turn
750
+ }
751
+ return { records, turnEnded };
752
+ }
753
+ /**
754
+ * The whole lines appended to `file` since the last read. Offsets are BYTES — what `stat`
755
+ * reports and what the file holds — and only from the offset is read, so a 50ms poll does not
756
+ * re-read a growing log, and a multi-byte character never shifts where the next read starts.
757
+ * A half-written trailing line is left for the next read.
758
+ */
759
+ readNewLines(file) {
760
+ let from = this.offsets.get(file) ?? 0;
761
+ const fd = openSync(file, 'r');
762
+ try {
763
+ const size = fstatSync(fd).size;
764
+ if (size < from)
765
+ from = 0; // rewritten from scratch: start over
766
+ if (size <= from)
767
+ return undefined;
768
+ const buffer = Buffer.alloc(size - from);
769
+ let filled = 0;
770
+ while (filled < buffer.length) {
771
+ const n = readSync(fd, buffer, filled, buffer.length - filled, from + filled);
772
+ if (n === 0)
773
+ break;
774
+ filled += n;
775
+ }
776
+ const end = buffer.subarray(0, filled).lastIndexOf(0x0a) + 1;
777
+ if (end === 0)
778
+ return undefined;
779
+ this.offsets.set(file, from + end);
780
+ return buffer.subarray(0, end).toString('utf8');
781
+ }
782
+ finally {
783
+ closeSync(fd);
784
+ }
785
+ }
786
+ /** Records what already exists, so a resumed session counts only its new turns. */
787
+ prime() {
788
+ if (this.primed)
789
+ return;
790
+ this.primed = true;
791
+ try {
792
+ const dir = this.locate();
793
+ if (!dir)
794
+ return;
795
+ const agentsDir = join(dir, 'agents');
796
+ for (const agent of readdirSync(agentsDir)) {
797
+ const file = join(agentsDir, agent, 'wire.jsonl');
798
+ if (existsSync(file))
799
+ this.offsets.set(file, statSync(file).size);
800
+ }
801
+ }
802
+ catch {
803
+ // nothing to prime
804
+ }
805
+ }
806
+ locate() {
807
+ if (this.sessionDir)
808
+ return this.sessionDir;
809
+ const sessions = join(this.home, 'sessions');
810
+ if (!existsSync(sessions))
811
+ return undefined;
812
+ for (const workdir of readdirSync(sessions)) {
813
+ const candidate = join(sessions, workdir, this.sessionId);
814
+ if (existsSync(candidate)) {
815
+ this.sessionDir = candidate;
816
+ return candidate;
817
+ }
818
+ }
819
+ return undefined;
820
+ }
821
+ }
822
+ function selectOptions(configOptions, id) {
823
+ if (!Array.isArray(configOptions))
824
+ return [];
825
+ const option = configOptions.find((o) => isRecord(o) && o.id === id);
826
+ if (!isRecord(option) || !Array.isArray(option.options))
827
+ return [];
828
+ return option.options.flatMap((o) => (isRecord(o) && typeof o.value === 'string' ? [o.value] : []));
829
+ }
830
+ function selectValue(configOptions, id) {
831
+ if (!Array.isArray(configOptions))
832
+ return undefined;
833
+ const option = configOptions.find((o) => isRecord(o) && o.id === id);
834
+ return isRecord(option) && typeof option.currentValue === 'string' ? option.currentValue : undefined;
835
+ }
836
+ /** Armed at spawn, so a `close` that fires before the lifecycle asks is never missed. */
837
+ function waitForExit(child) {
838
+ if (child.exitCode !== null)
839
+ return Promise.resolve(child.exitCode);
840
+ return new Promise((resolve) => {
841
+ child.once('close', (code) => resolve(code));
842
+ child.once('error', () => resolve(child.exitCode ?? null));
843
+ });
844
+ }
845
+ export function kimiSpawnError(error, bin) {
846
+ if (error?.code === 'ENOENT') {
847
+ return new Error(`\`${bin}\` not found on PATH — install Kimi Code and run \`kimi login\``);
848
+ }
849
+ return error instanceof Error ? error : new Error(String(error));
850
+ }
851
+ function errorText(error) {
852
+ if (isRecord(error) && typeof error.message === 'string') {
853
+ // An ACP internal error keeps its useful part in `data.details` ("Unknown sessionId: …").
854
+ const details = isRecord(error.data) && typeof error.data.details === 'string' ? error.data.details : undefined;
855
+ return details ? `${error.message}: ${details}` : error.message;
856
+ }
857
+ return typeof error === 'string' ? error : JSON.stringify(error);
858
+ }
859
+ /** Path to the bundled mock (`scripts/mock-kimi-acp.mjs`), for CEZ_DRY_RUN=1. */
860
+ function mockKimiPath() {
861
+ const here = dirname(fileURLToPath(import.meta.url));
862
+ // here = <pkg>/dist/core (built) or <pkg>/src/core (tsx dev).
863
+ return resolvePath(here, '..', '..', 'scripts', 'mock-kimi-acp.mjs');
864
+ }
865
+ function formatMs(ms) {
866
+ return ms < 1_000 ? `${ms}ms` : `${Math.round(ms / 1_000)}s`;
867
+ }
868
+ function truncate(value, max = 200) {
869
+ return value.length > max ? `${value.slice(0, max)}…` : value;
870
+ }
871
+ function isRecord(value) {
872
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
873
+ }
874
+ //# sourceMappingURL=kimi-runner.js.map