@open-mercato/cezar 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/README.md +3 -2
  2. package/dist/agent-config/catalog.d.ts +4 -0
  3. package/dist/agent-config/catalog.js +85 -3
  4. package/dist/agent-config/catalog.js.map +1 -1
  5. package/dist/agent-config/model-settings/copilot.d.ts +15 -0
  6. package/dist/agent-config/model-settings/copilot.js +25 -0
  7. package/dist/agent-config/model-settings/copilot.js.map +1 -0
  8. package/dist/agent-config/model-settings/junie.d.ts +12 -0
  9. package/dist/agent-config/model-settings/junie.js +18 -0
  10. package/dist/agent-config/model-settings/junie.js.map +1 -0
  11. package/dist/agent-config/models.js +4 -0
  12. package/dist/agent-config/models.js.map +1 -1
  13. package/dist/automations/prompts.d.ts +2 -2
  14. package/dist/automations/prompts.js +1 -1
  15. package/dist/automations/types.d.ts +12 -0
  16. package/dist/config.d.ts +4 -0
  17. package/dist/config.js +2 -0
  18. package/dist/config.js.map +1 -1
  19. package/dist/contract/agent-config.d.ts +4 -0
  20. package/dist/contract/agent-profiles.d.ts +30 -0
  21. package/dist/contract/automations.d.ts +32 -0
  22. package/dist/contract/dashboard-insights.d.ts +186 -0
  23. package/dist/contract/dashboard.d.ts +88 -0
  24. package/dist/contract/dispatch.d.ts +6 -0
  25. package/dist/contract/health.d.ts +8 -0
  26. package/dist/contract/index.d.ts +2 -0
  27. package/dist/contract/index.js +249 -72
  28. package/dist/contract/runs.d.ts +144 -0
  29. package/dist/contract/self-update.d.ts +111 -2
  30. package/dist/contract/skills.d.ts +19 -0
  31. package/dist/contract/star-count.d.ts +18 -0
  32. package/dist/contract/workflows.d.ts +12 -0
  33. package/dist/contract/workspace.d.ts +42 -2
  34. package/dist/core/acp-client.d.ts +99 -0
  35. package/dist/core/acp-client.js +198 -0
  36. package/dist/core/acp-client.js.map +1 -0
  37. package/dist/core/acp-ui-mapper.d.ts +95 -0
  38. package/dist/core/acp-ui-mapper.js +444 -0
  39. package/dist/core/acp-ui-mapper.js.map +1 -0
  40. package/dist/core/agent-env.js +10 -0
  41. package/dist/core/agent-env.js.map +1 -1
  42. package/dist/core/agent-profiles.d.ts +10 -0
  43. package/dist/core/agent-profiles.js +16 -0
  44. package/dist/core/agent-profiles.js.map +1 -1
  45. package/dist/core/agent-runner.d.ts +5 -3
  46. package/dist/core/agent-runner.js +5 -3
  47. package/dist/core/agent-runner.js.map +1 -1
  48. package/dist/core/backend-detect.d.ts +3 -3
  49. package/dist/core/backend-detect.js +61 -2
  50. package/dist/core/backend-detect.js.map +1 -1
  51. package/dist/core/claude-cli-runner.d.ts +5 -2
  52. package/dist/core/claude-cli-runner.js +11 -6
  53. package/dist/core/claude-cli-runner.js.map +1 -1
  54. package/dist/core/claude-ui-mapper.d.ts +14 -0
  55. package/dist/core/claude-ui-mapper.js +102 -11
  56. package/dist/core/claude-ui-mapper.js.map +1 -1
  57. package/dist/core/codex-app-server-transport.js +8 -4
  58. package/dist/core/codex-app-server-transport.js.map +1 -1
  59. package/dist/core/copilot-acp-runner.d.ts +60 -0
  60. package/dist/core/copilot-acp-runner.js +528 -0
  61. package/dist/core/copilot-acp-runner.js.map +1 -0
  62. package/dist/core/copilot-ui-mapper.d.ts +47 -0
  63. package/dist/core/copilot-ui-mapper.js +111 -0
  64. package/dist/core/copilot-ui-mapper.js.map +1 -0
  65. package/dist/core/cursor-agent-runner.js +4 -4
  66. package/dist/core/cursor-agent-runner.js.map +1 -1
  67. package/dist/core/disclaim-spawn.d.ts +9 -0
  68. package/dist/core/disclaim-spawn.js +53 -0
  69. package/dist/core/disclaim-spawn.js.map +1 -0
  70. package/dist/core/junie-acp-transport.d.ts +58 -0
  71. package/dist/core/junie-acp-transport.js +179 -0
  72. package/dist/core/junie-acp-transport.js.map +1 -0
  73. package/dist/core/junie-auth-probe.d.ts +12 -0
  74. package/dist/core/junie-auth-probe.js +30 -0
  75. package/dist/core/junie-auth-probe.js.map +1 -0
  76. package/dist/core/junie-model-catalog.d.ts +10 -0
  77. package/dist/core/junie-model-catalog.js +104 -0
  78. package/dist/core/junie-model-catalog.js.map +1 -0
  79. package/dist/core/junie-runner.d.ts +45 -0
  80. package/dist/core/junie-runner.js +533 -0
  81. package/dist/core/junie-runner.js.map +1 -0
  82. package/dist/core/junie-ui-mapper.d.ts +132 -0
  83. package/dist/core/junie-ui-mapper.js +459 -0
  84. package/dist/core/junie-ui-mapper.js.map +1 -0
  85. package/dist/core/model-identity.js +17 -0
  86. package/dist/core/model-identity.js.map +1 -1
  87. package/dist/core/model-presets.js +10 -0
  88. package/dist/core/model-presets.js.map +1 -1
  89. package/dist/core/opencode-server-runner.js +4 -4
  90. package/dist/core/opencode-server-runner.js.map +1 -1
  91. package/dist/core/pi-runner.js +4 -4
  92. package/dist/core/pi-runner.js.map +1 -1
  93. package/dist/core/provider-auth.d.ts +16 -2
  94. package/dist/core/provider-auth.js +113 -7
  95. package/dist/core/provider-auth.js.map +1 -1
  96. package/dist/core/runner-factory.js +6 -0
  97. package/dist/core/runner-factory.js.map +1 -1
  98. package/dist/core/runner-model-catalog.js +12 -8
  99. package/dist/core/runner-model-catalog.js.map +1 -1
  100. package/dist/core/tool-display.js +6 -1
  101. package/dist/core/tool-display.js.map +1 -1
  102. package/dist/core/ui-events.d.ts +6 -2
  103. package/dist/git-diff-base.js +23 -2
  104. package/dist/git-diff-base.js.map +1 -1
  105. package/dist/git-worktree.d.ts +21 -2
  106. package/dist/git-worktree.js +68 -5
  107. package/dist/git-worktree.js.map +1 -1
  108. package/dist/index.js +14 -4
  109. package/dist/index.js.map +1 -1
  110. package/dist/paths.js +2 -0
  111. package/dist/paths.js.map +1 -1
  112. package/dist/runs/event-history.js +3 -0
  113. package/dist/runs/event-history.js.map +1 -1
  114. package/dist/runs/store.d.ts +42 -3
  115. package/dist/runs/store.js +112 -6
  116. package/dist/runs/store.js.map +1 -1
  117. package/dist/self-update/checkouts.d.ts +53 -0
  118. package/dist/self-update/checkouts.js +268 -0
  119. package/dist/self-update/checkouts.js.map +1 -0
  120. package/dist/self-update/cli.d.ts +5 -3
  121. package/dist/self-update/cli.js +75 -8
  122. package/dist/self-update/cli.js.map +1 -1
  123. package/dist/self-update/layout.d.ts +33 -1
  124. package/dist/self-update/layout.js +102 -3
  125. package/dist/self-update/layout.js.map +1 -1
  126. package/dist/self-update/pulls.d.ts +40 -0
  127. package/dist/self-update/pulls.js +127 -0
  128. package/dist/self-update/pulls.js.map +1 -0
  129. package/dist/self-update/service.d.ts +26 -3
  130. package/dist/self-update/service.js +85 -9
  131. package/dist/self-update/service.js.map +1 -1
  132. package/dist/server/dashboard.d.ts +107 -0
  133. package/dist/server/dashboard.js +2 -1
  134. package/dist/server/dashboard.js.map +1 -1
  135. package/dist/server/forge/github.js +4 -1
  136. package/dist/server/forge/github.js.map +1 -1
  137. package/dist/server/fs-browse.d.ts +3 -1
  138. package/dist/server/fs-browse.js +27 -5
  139. package/dist/server/fs-browse.js.map +1 -1
  140. package/dist/server/open-in-app.js +2 -0
  141. package/dist/server/open-in-app.js.map +1 -1
  142. package/dist/server/provider-action-gate.js +5 -1
  143. package/dist/server/provider-action-gate.js.map +1 -1
  144. package/dist/server/server.d.ts +880 -511
  145. package/dist/server/server.js +40 -5
  146. package/dist/server/server.js.map +1 -1
  147. package/dist/server/star-count.d.ts +67 -0
  148. package/dist/server/star-count.js +186 -0
  149. package/dist/server/star-count.js.map +1 -0
  150. package/dist/skills-banner.d.ts +19 -0
  151. package/dist/skills-banner.js +24 -0
  152. package/dist/skills-banner.js.map +1 -1
  153. package/dist/workflows/run.d.ts +0 -2
  154. package/dist/workflows/run.js +45 -29
  155. package/dist/workflows/run.js.map +1 -1
  156. package/dist/workflows/types.d.ts +6 -0
  157. package/dist/workspace/agent-accounts.d.ts +9 -1
  158. package/dist/workspace/agent-accounts.js +2 -0
  159. package/dist/workspace/agent-accounts.js.map +1 -1
  160. package/dist/workspace/agent-profiles.d.ts +2 -2
  161. package/dist/workspace/agent-profiles.js +25 -6
  162. package/dist/workspace/agent-profiles.js.map +1 -1
  163. package/dist/workspace/config.d.ts +9 -1
  164. package/dist/workspace/config.js +10 -3
  165. package/dist/workspace/config.js.map +1 -1
  166. package/dist/workspace/dashboard-insights.d.ts +42 -0
  167. package/dist/workspace/dashboard-insights.js +220 -0
  168. package/dist/workspace/dashboard-insights.js.map +1 -0
  169. package/dist/workspace/dashboard.d.ts +71 -1
  170. package/dist/workspace/dashboard.js +14 -1
  171. package/dist/workspace/dashboard.js.map +1 -1
  172. package/dist/workspace/semaphore.d.ts +3 -0
  173. package/dist/workspace/semaphore.js +8 -1
  174. package/dist/workspace/semaphore.js.map +1 -1
  175. package/package.json +3 -3
  176. package/scripts/mock-claude.mjs +34 -1
  177. package/scripts/mock-copilot-acp.mjs +190 -0
  178. package/scripts/mock-junie-acp.mjs +208 -0
  179. package/web/dist/assets/agent-task-pickers-BeQi-UTm.js +1 -0
  180. package/web/dist/assets/alert-dialog-CnRAuqwb.js +1 -0
  181. package/web/dist/assets/arrow-down-Da0kNRNH.js +1 -0
  182. package/web/dist/assets/arrow-left-BIZHhBIP.js +1 -0
  183. package/web/dist/assets/automation-format-CfPmkcsg.js +1 -0
  184. package/web/dist/assets/automations-route-AMJbFP53.js +1 -0
  185. package/web/dist/assets/centered-state-3r2Kaar_.js +1 -0
  186. package/web/dist/assets/chevron-left-DLAUPC66.js +1 -0
  187. package/web/dist/assets/chevron-right-KVZcXiPL.js +1 -0
  188. package/web/dist/assets/{circle-x-C9UoMP1V.js → circle-x-C0Jm5Ppb.js} +1 -1
  189. package/web/dist/assets/collapsible-DG_SIWqU.js +1 -0
  190. package/web/dist/assets/command-Dfln3D4A.js +1 -0
  191. package/web/dist/assets/{commit-list-BSfPsVsu.js → commit-list-_RA72yB_.js} +1 -1
  192. package/web/dist/assets/compare-variants-D6Ji6od4.js +1 -0
  193. package/web/dist/assets/dashboard-B3-tPimG.js +44 -0
  194. package/web/dist/assets/dialog-CiDREdUK.js +1 -0
  195. package/web/dist/assets/{diff-I0xowULh.js → diff-CxdyRumG.js} +2 -2
  196. package/web/dist/assets/diff-controls-DqJMMV4z.js +1 -0
  197. package/web/dist/assets/{diff-stat-yKn7joEr.js → diff-stat-Hupj4hxh.js} +1 -1
  198. package/web/dist/assets/{diff-view-DjvMeW1M.js → diff-view-BBYT5k6c.js} +1 -1
  199. package/web/dist/assets/dist-BqMwqJFX.js +1 -0
  200. package/web/dist/assets/dist-DpiX6WjA.js +1 -0
  201. package/web/dist/assets/{download-BcgZ2yk4.js → download-BR7EN9gW.js} +1 -1
  202. package/web/dist/assets/dropdown-menu-Ci4HFML0.js +1 -0
  203. package/web/dist/assets/editable-title-DDtUgRKZ.js +1 -0
  204. package/web/dist/assets/{ellipsis-vertical-g4O4NlLV.js → ellipsis-vertical-DBklom4U.js} +1 -1
  205. package/web/dist/assets/facet-filter-CfI4QvOd.js +1 -0
  206. package/web/dist/assets/{file-wXNeZwi7.js → file-CZb7cKNH.js} +1 -1
  207. package/web/dist/assets/{file-text-DV1gE2L6.js → file-text-Dm6CrEGW.js} +1 -1
  208. package/web/dist/assets/{folder-wjVId5un.js → folder-zQj-FYOo.js} +1 -1
  209. package/web/dist/assets/{git-pull-request-BBEDdTLK.js → git-pull-request-AhwzJc7s.js} +1 -1
  210. package/web/dist/assets/git-toolbar-j7gKkhGL.js +1 -0
  211. package/web/dist/assets/github-De-DFy8s.js +1 -0
  212. package/web/dist/assets/{image-preview-u1f-wzxC.js → image-preview-Dd3NVB7N.js} +1 -1
  213. package/web/dist/assets/index-HS1hr5Sz.js +12 -0
  214. package/web/dist/assets/index-YwgrLyBj.css +2 -0
  215. package/web/dist/assets/loader-circle-sk4vKJKp.js +1 -0
  216. package/web/dist/assets/{markdown-Bnm47qUl.js → markdown-DjNR-1p8.js} +2 -2
  217. package/web/dist/assets/new-task-form-vLs2G1_z.js +1 -0
  218. package/web/dist/assets/picker-pill-VW-M1ZiV.js +1 -0
  219. package/web/dist/assets/{pill-7dm3vWF7.js → pill-CPl6sysj.js} +1 -1
  220. package/web/dist/assets/popover-CNGONAql.js +1 -0
  221. package/web/dist/assets/project-router-dCZQu1wQ.js +1 -0
  222. package/web/dist/assets/{prompt-templates-BMZ5q5H_.js → prompt-templates-jNjVTAws.js} +1 -1
  223. package/web/dist/assets/{refresh-cw-C69euZ2H.js → refresh-cw-BfkEydKA.js} +1 -1
  224. package/web/dist/assets/repo-git-BZWZ6_pR.js +1 -0
  225. package/web/dist/assets/{run-diff-CoNVGn23.js → run-diff-u_roDsAJ.js} +2 -2
  226. package/web/dist/assets/run-header-Br1yJR0m.js +1 -0
  227. package/web/dist/assets/{search-x-BNLFOxI6.js → search-x-CT0NTqK1.js} +1 -1
  228. package/web/dist/assets/segmented-IDD4ucht.js +1 -0
  229. package/web/dist/assets/skills-Dsi5YdLG.js +1 -0
  230. package/web/dist/assets/{sparkles-ChorK-gZ.js → sparkles-CvOeAoyJ.js} +1 -1
  231. package/web/dist/assets/{square-terminal-C7KCPznz.js → square-terminal-eSs8YYZe.js} +1 -1
  232. package/web/dist/assets/{tab-link-E5O2Cesc.js → tab-link-CPF6ORha.js} +1 -1
  233. package/web/dist/assets/task-changes-DIT9Y1rh.js +1 -0
  234. package/web/dist/assets/task-commits-B4VvdiHH.js +1 -0
  235. package/web/dist/assets/task-files-BMm9C0DW.js +2 -0
  236. package/web/dist/assets/task-thread-RXabJAt0.js +9 -0
  237. package/web/dist/assets/{textarea-DLAfWPb0.js → textarea-DtBqPhIs.js} +1 -1
  238. package/web/dist/assets/thread-loading-Dnxb6Ar-.js +1 -0
  239. package/web/dist/assets/toaster-CfRVb8vH.js +43 -0
  240. package/web/dist/assets/token-metrics-DldVlr6m.js +1 -0
  241. package/web/dist/assets/tooltip-_O50N3pt.js +1 -0
  242. package/web/dist/assets/tracker-J0fdcH1G.js +4 -0
  243. package/web/dist/assets/{trash-2-_vwSMdPG.js → trash-2-CUH7GOVh.js} +1 -1
  244. package/web/dist/assets/{triangle-alert-fBRUkB46.js → triangle-alert-D5K_zyD3.js} +1 -1
  245. package/web/dist/assets/{upload-B4OIpdyq.js → upload-D7_n-9cl.js} +1 -1
  246. package/web/dist/assets/{use-now-sqAvRMna.js → use-now-3lElDuTi.js} +1 -1
  247. package/web/dist/assets/utils-BXvEm7Ve.js +64 -0
  248. package/web/dist/assets/workflows-D-dx9c_0.js +7 -0
  249. package/web/dist/assets/x-kLybIvX4.js +1 -0
  250. package/web/dist/assets/{zoomable-image-X81SApIg.js → zoomable-image-CnyQ9wyw.js} +1 -1
  251. package/web/dist/index.html +38 -36
  252. package/web/dist/assets/agent-task-pickers-DQ1qvgrD.js +0 -1
  253. package/web/dist/assets/alert-dialog-B_2uU4Bg.js +0 -1
  254. package/web/dist/assets/arrow-down-DieVZxSE.js +0 -1
  255. package/web/dist/assets/arrow-left-C8M0efjn.js +0 -1
  256. package/web/dist/assets/automation-format-CzinzpHK.js +0 -1
  257. package/web/dist/assets/automations-route-DYHUjV9R.js +0 -1
  258. package/web/dist/assets/centered-state-DJLgwvA4.js +0 -43
  259. package/web/dist/assets/chevron-left-BhXrOEE3.js +0 -1
  260. package/web/dist/assets/chevron-right-B3Ta8VKK.js +0 -1
  261. package/web/dist/assets/collapsible-BcKvItwg.js +0 -1
  262. package/web/dist/assets/command-BvGGv2_u.js +0 -1
  263. package/web/dist/assets/compare-variants-DBvMYMs3.js +0 -1
  264. package/web/dist/assets/dashboard-CGaFh4RV.js +0 -44
  265. package/web/dist/assets/dialog-B6NgKh0-.js +0 -1
  266. package/web/dist/assets/diff-controls-DskkZqmD.js +0 -1
  267. package/web/dist/assets/dist-BvXEdcbG.js +0 -1
  268. package/web/dist/assets/dist-CTksUkKh.js +0 -1
  269. package/web/dist/assets/dropdown-menu-B7HeKCfN.js +0 -1
  270. package/web/dist/assets/editable-title-BHbHmSIK.js +0 -1
  271. package/web/dist/assets/facet-filter-DZ3wfvN9.js +0 -1
  272. package/web/dist/assets/git-toolbar-EZuX4Cuz.js +0 -1
  273. package/web/dist/assets/github-zcLRxv77.js +0 -1
  274. package/web/dist/assets/index-BrZhA4_u.css +0 -2
  275. package/web/dist/assets/index-CSNFuBvj.js +0 -12
  276. package/web/dist/assets/loader-circle-Cwgo6onL.js +0 -1
  277. package/web/dist/assets/new-task-form-CQODCzBP.js +0 -1
  278. package/web/dist/assets/picker-pill-DNB9ETjS.js +0 -1
  279. package/web/dist/assets/popover-BRq6QnwI.js +0 -1
  280. package/web/dist/assets/project-router-I8Pbsrxy.js +0 -1
  281. package/web/dist/assets/repo-git-G436Abni.js +0 -1
  282. package/web/dist/assets/run-header-CxdaA86t.js +0 -1
  283. package/web/dist/assets/skills-C_kBDesq.js +0 -1
  284. package/web/dist/assets/task-changes-Bhw4Ysvg.js +0 -1
  285. package/web/dist/assets/task-commits-DBuGXuGm.js +0 -1
  286. package/web/dist/assets/task-files-CYDbeffM.js +0 -2
  287. package/web/dist/assets/task-thread-RuxHMJgN.js +0 -9
  288. package/web/dist/assets/thread-loading-BAuVAbcA.js +0 -1
  289. package/web/dist/assets/token-metrics-rVl4kXe_.js +0 -1
  290. package/web/dist/assets/tooltip-Bdl8mQG8.js +0 -1
  291. package/web/dist/assets/tracker-DJ8JW59-.js +0 -4
  292. package/web/dist/assets/utils-DoBmOlX3.js +0 -64
  293. package/web/dist/assets/workflows-C54D7mlm.js +0 -7
  294. package/web/dist/assets/x-HXr9KZBr.js +0 -1
@@ -0,0 +1,528 @@
1
+ import { spawn as nodeSpawn } from 'node:child_process';
2
+ import { dirname, resolve as resolvePath } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { isSignalTerminationExit, prependSystemPrompt, trackChildExit, } from './agent-runner.js';
5
+ import { buildChildEnv } from './agent-env.js';
6
+ import { AcpClient } from './acp-client.js';
7
+ import { abortAcpTurn, endAcpReplay, mapAcpFrame } from './acp-ui-mapper.js';
8
+ import { EOF_KILL_GRACE_MS, EOF_TERM_GRACE_MS } from './claude-cli-runner.js';
9
+ import { COPILOT_AUTH_FAILURE_MESSAGE, copilotDialect, createCopilotUiState, isCopilotAuthFailure, } from './copilot-ui-mapper.js';
10
+ const DEFAULT_TIMEOUT_MS = 30 * 60_000;
11
+ /** `initialize` / `session/new` / `session/load` are handshakes: bounded, unlike a prompt. */
12
+ const HANDSHAKE_TIMEOUT_MS = 90_000;
13
+ /**
14
+ * How long to wait for the end of a `session/load` replay (`available_commands_update`) before
15
+ * prompting anyway. Whether Copilot replays a loaded session's history at all is **unverified**
16
+ * (no entitled credential was available — see `__fixtures__/copilot/README.md`), so this is a
17
+ * bound, not an expectation: an agent that never sends the marker costs one 5s wait on resume.
18
+ */
19
+ const REPLAY_WAIT_MS = 5_000;
20
+ const AUTO_END_DELAY_MS = 250;
21
+ /**
22
+ * GitHub Copilot CLI over the Agent Client Protocol (#582, spec
23
+ * `2026-09-19-runner-seam-native-backends` Phase 3): one long-lived `copilot --acp` child and one
24
+ * ACP session per cezar session. Follow-ups are further `session/prompt` calls on the same
25
+ * process; Continue resumes with `session/load`.
26
+ *
27
+ * The wire was verified against `@github/copilot` 1.0.88 — the record is
28
+ * `.ai/runs/2026-09-27-copilot-cli-runner/copilot-acp-notes.md` and the fixtures are
29
+ * `__fixtures__/copilot/`. Permissions are `auto` only (spec Q15): the child starts with
30
+ * `--allow-all-tools`, and a `session/request_permission` that still arrives is auto-approved with
31
+ * a note, so no request can park a run nothing is able to wake.
32
+ */
33
+ export class CopilotAcpRunner {
34
+ backend = 'copilot';
35
+ bin;
36
+ timeoutMs;
37
+ lastSession = null;
38
+ constructor(opts = {}) {
39
+ this.bin =
40
+ opts.bin ?? process.env.CEZ_COPILOT_BIN ?? (process.env.CEZ_DRY_RUN === '1' ? mockCopilotPath() : 'copilot');
41
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
42
+ }
43
+ run(spec, onEvent) {
44
+ return this.startSession(spec, onEvent, { autoEndAfterFirstTurn: true }).result;
45
+ }
46
+ async interrupt() {
47
+ this.lastSession?.interrupt();
48
+ }
49
+ startSession(spec, onEvent, opts = {}) {
50
+ const session = new CopilotAcpSession(this.bin, this.backend, spec, spec.timeoutMs ?? this.timeoutMs, onEvent, opts);
51
+ this.lastSession = session;
52
+ return session;
53
+ }
54
+ }
55
+ /**
56
+ * The CLI flags for one run. Every one is from `copilot --help` on 1.0.88 (see the notes):
57
+ *
58
+ * - `--acp` starts the ACP server on stdio. There is **no `--stdio` flag** — the spec's
59
+ * `copilot --acp --stdio` was wrong, and passing it makes the CLI exit on an unknown option.
60
+ * - `--allow-all-tools` is the `auto` permission mode (Q15). The **flag**, deliberately, not
61
+ * `COPILOT_ALLOW_ALL=true`: set to exactly `"true"` that variable *also* trusts the working
62
+ * directory, which loads its skills, plugins, MCP servers and hooks — including hooks that run
63
+ * shell commands. A cezar worktree is a checkout of someone else's branch; that is not a trust
64
+ * decision this runner gets to make.
65
+ * - `--no-auto-update` because a CLI that swaps itself out mid-task is not reproducible, and the
66
+ * download is not something a run should pay for.
67
+ * - `--add-dir` carries `AgentRunSpec.additionalDirectories`; the session cwd is the spawn cwd.
68
+ *
69
+ * `spec.allowedTools` / `spec.bashAllowlist` are NOT translated to `--allow-tool` / `--deny-tool`.
70
+ * Permission modes are out of scope for this phase (Q15), and a partial mapping would look like a
71
+ * sandbox while behaving like `--allow-all-tools`, which is worse than the honest version.
72
+ */
73
+ export function buildCopilotArgs(spec) {
74
+ const args = ['--acp', '--allow-all-tools', '--no-auto-update'];
75
+ if (spec.model)
76
+ args.push('--model', spec.model);
77
+ for (const dir of spec.additionalDirectories ?? [])
78
+ args.push('--add-dir', dir);
79
+ return args;
80
+ }
81
+ /** The per-run environment: `buildChildEnv`'s least-privilege set for this backend. Copilot's own
82
+ * `COPILOT_` family and the shared `gh` names are what `agent-env.ts` already allows it. */
83
+ export function buildCopilotEnv(backend, extraEnv) {
84
+ return buildChildEnv({ backend, extraEnv });
85
+ }
86
+ /**
87
+ * A cezar-authored line for an exit outside a prompt.
88
+ *
89
+ * Copilot's exit codes are **not documented and were not verified**, so — unlike the Gemini
90
+ * runner, which can name 41/52/55 — this reports the code and the tail of stderr rather than
91
+ * inventing meanings. The one case worth translating is an authentication failure, because that
92
+ * wording is what raises `provider-auth-required`.
93
+ */
94
+ export function copilotExitMessage(exitCode, stderr) {
95
+ if (isCopilotAuthFailure(stderr))
96
+ return COPILOT_AUTH_FAILURE_MESSAGE;
97
+ const detail = stderr.trim().split('\n').slice(-3).join(' | ');
98
+ return `Copilot CLI exited with code ${exitCode}${detail ? ` — ${truncate(detail, 400)}` : ''}`;
99
+ }
100
+ class CopilotAcpSession {
101
+ spec;
102
+ limitMs;
103
+ onEvent;
104
+ opts;
105
+ result;
106
+ pid;
107
+ child;
108
+ client;
109
+ hasExited;
110
+ ui = createCopilotUiState();
111
+ acpSessionId;
112
+ loadSupported = false;
113
+ imagesSupported = false;
114
+ isOpen = true;
115
+ turnInFlight = false;
116
+ turnsCompleted = 0;
117
+ queue = [];
118
+ terminatedByCezar = false;
119
+ timedOut = false;
120
+ failed = null;
121
+ replayDone = null;
122
+ textChunks = [];
123
+ toolCalls = [];
124
+ tokensUsed = 0;
125
+ stderr = [];
126
+ spawnError = null;
127
+ autoEndTimer;
128
+ timers = [];
129
+ constructor(bin, backend, spec, limitMs, onEvent, opts) {
130
+ this.spec = spec;
131
+ this.limitMs = limitMs;
132
+ this.onEvent = onEvent;
133
+ this.opts = opts;
134
+ this.child = nodeSpawn(bin, buildCopilotArgs(spec), { cwd: spec.cwd, env: buildCopilotEnv(backend, spec.env) });
135
+ this.pid = this.child.pid;
136
+ this.hasExited = trackChildExit(this.child);
137
+ this.child.on('error', (error) => {
138
+ this.spawnError =
139
+ error.code === 'ENOENT'
140
+ ? new Error(`\`${bin}\` not found on PATH — install GitHub Copilot CLI (npm i -g @github/copilot) and run \`copilot login\``)
141
+ : error;
142
+ });
143
+ this.child.stderr.setEncoding('utf8');
144
+ this.child.stderr.on('data', (chunk) => this.stderr.push(chunk));
145
+ this.client = new AcpClient(this.child.stdin, this.child.stdout, {
146
+ onFrame: (dir, frame) => this.onFrame(dir, frame),
147
+ onRequest: (request) => this.onRequest(request),
148
+ onUnparseable: (line) => this.emit({ type: 'note', message: `copilot: skipped unparseable ACP line: ${truncate(line, 200)}` }),
149
+ });
150
+ if (this.limitMs > 0) {
151
+ const deadline = setTimeout(() => {
152
+ this.timedOut = true;
153
+ this.interrupt();
154
+ }, this.limitMs);
155
+ deadline.unref?.();
156
+ this.timers.push(deadline);
157
+ }
158
+ this.result = this.lifecycle();
159
+ }
160
+ get open() {
161
+ return this.isOpen;
162
+ }
163
+ sendMessage(content) {
164
+ if (!this.isOpen || this.client.closed)
165
+ return false;
166
+ if (this.autoEndTimer) {
167
+ clearTimeout(this.autoEndTimer);
168
+ this.autoEndTimer = undefined;
169
+ }
170
+ // ACP has no steering: a message sent mid-turn waits for the turn to end, in order.
171
+ this.queue.push(this.toAcp(content));
172
+ this.pump();
173
+ return true;
174
+ }
175
+ end() {
176
+ if (!this.isOpen)
177
+ return;
178
+ this.isOpen = false;
179
+ this.terminate(false);
180
+ }
181
+ interrupt() {
182
+ if (this.acpSessionId && this.turnInFlight)
183
+ this.client.cancel(this.acpSessionId);
184
+ this.isOpen = false;
185
+ this.terminate(true);
186
+ }
187
+ // ---- lifecycle ------------------------------------------------------------------------
188
+ async lifecycle() {
189
+ const reading = this.client.run();
190
+ const exited = waitForExit(this.child);
191
+ try {
192
+ await this.bootstrap();
193
+ }
194
+ catch (error) {
195
+ // An agent that went away mid-handshake is explained by its exit, read below — not by the
196
+ // transport's "closed" rejection.
197
+ if (!this.spawnError && !this.client.closed)
198
+ this.fail(error instanceof Error ? error.message : String(error));
199
+ this.terminate(false);
200
+ }
201
+ await reading;
202
+ const exitCode = await exited;
203
+ for (const timer of this.timers)
204
+ clearTimeout(timer);
205
+ if (this.autoEndTimer)
206
+ clearTimeout(this.autoEndTimer);
207
+ this.isOpen = false;
208
+ if (this.spawnError)
209
+ throw this.spawnError;
210
+ if (this.turnInFlight) {
211
+ // The agent died with a prompt unanswered: the transport rejected it, the wire never will.
212
+ this.turnInFlight = false;
213
+ if (this.timedOut)
214
+ this.applyUi(abortAcpTurn(this.ui, copilotDialect, 'timeout'));
215
+ else if (this.terminatedByCezar)
216
+ this.applyUi(abortAcpTurn(this.ui, copilotDialect, 'cancelled'));
217
+ else {
218
+ const reason = copilotExitMessage(exitCode, this.stderrText());
219
+ this.applyUi(abortAcpTurn(this.ui, copilotDialect, 'error', reason));
220
+ this.fail(reason);
221
+ }
222
+ }
223
+ const summary = () => ({
224
+ text: this.textChunks.join('').trim(),
225
+ toolCalls: this.toolCalls,
226
+ tokensUsed: this.tokensUsed,
227
+ ...(this.acpSessionId ? { sessionId: this.acpSessionId } : {}),
228
+ });
229
+ if (this.timedOut) {
230
+ const minutes = Math.round((this.limitMs / 60_000) * 10) / 10;
231
+ this.emit({ type: 'error', message: `Copilot CLI timed out after ${minutes}m and was killed` });
232
+ this.emit({ type: 'done' });
233
+ return summary();
234
+ }
235
+ if (this.failed) {
236
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: 'error' });
237
+ this.emit({ type: 'done' });
238
+ return summary();
239
+ }
240
+ if (!this.acpSessionId && !this.terminatedByCezar && (exitCode === 0 || exitCode === null)) {
241
+ this.fail('Copilot CLI exited before it started a session');
242
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: 'error' });
243
+ this.emit({ type: 'done' });
244
+ return summary();
245
+ }
246
+ if (exitCode !== 0 && exitCode !== null) {
247
+ if (this.terminatedByCezar && (isSignalTerminationExit(exitCode) || exitCode === 1)) {
248
+ this.emit({ type: 'note', message: `Copilot CLI exited ${exitCode} after cezar stopped it` });
249
+ }
250
+ else if (!this.terminatedByCezar) {
251
+ const message = copilotExitMessage(exitCode, this.stderrText());
252
+ this.emit({ type: 'error', message });
253
+ throw new Error(message);
254
+ }
255
+ }
256
+ if (this.tokensUsed === 0 && this.turnsCompleted > 0) {
257
+ this.emit({ type: 'note', message: 'token usage not reported by Copilot CLI' });
258
+ }
259
+ this.opts.onUiEvent?.({ type: 'session.ended', reason: this.terminatedByCezar && this.turnsCompleted === 0 ? 'cancelled' : 'end_turn' });
260
+ this.emit({ type: 'done' });
261
+ return summary();
262
+ }
263
+ async bootstrap() {
264
+ const init = await this.client.initialize(HANDSHAKE_TIMEOUT_MS);
265
+ const caps = isRecord(init.agentCapabilities) ? init.agentCapabilities : {};
266
+ this.loadSupported = caps.loadSession === true;
267
+ this.imagesSupported = isRecord(caps.promptCapabilities) && caps.promptCapabilities.image === true;
268
+ let resumed = false;
269
+ if (this.spec.resume && this.spec.sessionId) {
270
+ if (this.loadSupported) {
271
+ const replayEnded = new Promise((resolve) => {
272
+ this.replayDone = resolve;
273
+ });
274
+ try {
275
+ await this.client.loadSession(this.spec.sessionId, this.spec.cwd, HANDSHAKE_TIMEOUT_MS);
276
+ this.acpSessionId = this.spec.sessionId;
277
+ resumed = true;
278
+ await Promise.race([replayEnded, delay(REPLAY_WAIT_MS)]);
279
+ this.ui = endAcpReplay(this.ui);
280
+ }
281
+ catch (error) {
282
+ this.replayDone = null;
283
+ this.ui = endAcpReplay(this.ui);
284
+ this.emit({
285
+ type: 'note',
286
+ message: `Copilot could not resume session ${this.spec.sessionId} (${error instanceof Error ? error.message : String(error)}) — starting a fresh session`,
287
+ });
288
+ }
289
+ }
290
+ else {
291
+ this.emit({ type: 'note', message: 'Copilot CLI does not advertise session/load — starting a fresh session' });
292
+ }
293
+ }
294
+ if (!this.acpSessionId) {
295
+ const created = await this.client.newSession(this.spec.cwd, HANDSHAKE_TIMEOUT_MS).catch((error) => {
296
+ const message = error instanceof Error ? error.message : String(error);
297
+ throw new Error(isCopilotAuthFailure(`${message}\n${this.stderrText()}`)
298
+ ? COPILOT_AUTH_FAILURE_MESSAGE
299
+ : `Copilot CLI could not start a session: ${message}`);
300
+ });
301
+ const id = typeof created.sessionId === 'string' ? created.sessionId : undefined;
302
+ if (!id)
303
+ throw new Error('Copilot CLI answered session/new without a sessionId');
304
+ this.acpSessionId = id;
305
+ }
306
+ else if (resumed && this.spec.model) {
307
+ // `--model` only reaches a session this process CREATED; a loaded one keeps the model it was
308
+ // saved with, so a run whose model changed between turns (#954) has to say so. Copilot's
309
+ // `session/load` result shape is unverified, so this asks unconditionally rather than
310
+ // comparing against a field that may not be there.
311
+ await this.client.setModel(this.acpSessionId, this.spec.model, HANDSHAKE_TIMEOUT_MS).catch((error) => {
312
+ this.emit({
313
+ type: 'note',
314
+ message: `Copilot kept its own model: session/set_model failed (${error instanceof Error ? error.message : String(error)})`,
315
+ });
316
+ });
317
+ }
318
+ this.emit({ type: 'session', sessionId: this.acpSessionId });
319
+ const first = [
320
+ ...(this.spec.images ?? []),
321
+ { type: 'text', text: prependSystemPrompt(this.spec.systemPrompt, this.spec.userPrompt) },
322
+ ];
323
+ this.queue.unshift(this.toAcp(first));
324
+ this.pump();
325
+ }
326
+ /** Send the next queued prompt when no turn is running. */
327
+ pump() {
328
+ if (this.turnInFlight || !this.acpSessionId || this.queue.length === 0 || this.client.closed)
329
+ return;
330
+ const prompt = this.queue.shift();
331
+ this.turnInFlight = true;
332
+ this.client.prompt(this.acpSessionId, prompt).then(() => this.turnEnded(),
333
+ // An error ANSWER ends the turn (the mapper already settled it); a lost transport does not —
334
+ // the lifecycle settles that one once it knows why the agent went away.
335
+ () => {
336
+ if (!this.client.closed)
337
+ this.turnEnded();
338
+ });
339
+ }
340
+ turnEnded() {
341
+ if (!this.turnInFlight)
342
+ return;
343
+ this.turnInFlight = false;
344
+ this.turnsCompleted += 1;
345
+ this.emit({ type: 'turn-end' });
346
+ if (this.queue.length > 0) {
347
+ this.pump();
348
+ return;
349
+ }
350
+ if (this.opts.autoEndAfterFirstTurn && this.isOpen && !this.autoEndTimer) {
351
+ this.autoEndTimer = setTimeout(() => this.end(), AUTO_END_DELAY_MS);
352
+ this.autoEndTimer.unref?.();
353
+ }
354
+ }
355
+ // ---- wire → events --------------------------------------------------------------------
356
+ onFrame(dir, frame) {
357
+ if (dir === 'in'
358
+ && this.replayDone
359
+ && isRecord(frame.params)
360
+ && isRecord(frame.params.update)
361
+ && frame.params.update.sessionUpdate === 'available_commands_update') {
362
+ const done = this.replayDone;
363
+ this.replayDone = null;
364
+ // Let the mapper see the marker first, then release the prompt.
365
+ queueMicrotask(done);
366
+ }
367
+ this.applyUi(mapAcpFrame({ dir, frame }, this.ui, copilotDialect));
368
+ }
369
+ applyUi(mapped) {
370
+ this.ui = mapped.state;
371
+ for (const event of mapped.events) {
372
+ this.opts.onUiEvent?.(event);
373
+ this.v1FromUi(event);
374
+ }
375
+ }
376
+ /** v1 derived from v2 (AGENT_PROTOCOL.md §2: every v1 event stays derivable from the v2 stream). */
377
+ v1FromUi(event) {
378
+ switch (event.type) {
379
+ case 'item.delta':
380
+ if (event.field === 'text') {
381
+ this.textChunks.push(event.delta);
382
+ this.emit({ type: 'text', text: event.delta });
383
+ }
384
+ return;
385
+ case 'item.started':
386
+ if (event.item.kind === 'tool') {
387
+ const input = event.item.input ?? { title: event.item.title };
388
+ this.toolCalls.push({ id: event.item.id, name: event.item.name, input });
389
+ this.emit({ type: 'tool-call', id: event.item.id, tool: event.item.name, input });
390
+ }
391
+ return;
392
+ case 'item.completed':
393
+ if (event.item.kind === 'tool') {
394
+ const failed = event.item.status === 'failed' || event.item.status === 'declined';
395
+ this.emit({
396
+ type: 'tool-result',
397
+ toolCallId: event.item.id,
398
+ result: (failed ? event.item.error : event.item.output) ?? '',
399
+ isError: failed,
400
+ });
401
+ }
402
+ return;
403
+ case 'image':
404
+ this.emit({ type: 'image', mediaType: event.mediaType, data: event.data });
405
+ return;
406
+ case 'usage.updated':
407
+ this.tokensUsed = event.usage.total;
408
+ this.emit({ type: 'token-usage', tokensUsed: this.tokensUsed });
409
+ return;
410
+ case 'session.error':
411
+ // A failed prompt or session is the step's failure. A failed resume is not (the bootstrap
412
+ // notes it and starts a fresh session).
413
+ if (event.fatal || this.turnInFlight)
414
+ this.fail(event.message);
415
+ return;
416
+ default:
417
+ return;
418
+ }
419
+ }
420
+ onRequest(request) {
421
+ if (request.method !== 'session/request_permission' || !isRecord(request.params)) {
422
+ return { error: { code: -32601, message: `Method not found: ${String(request.method)}` } };
423
+ }
424
+ const options = Array.isArray(request.params.options) ? request.params.options.filter(isRecord) : [];
425
+ const choice = options.find((o) => o.kind === 'allow_always') ?? options.find((o) => o.kind === 'allow_once') ?? options[0];
426
+ const title = isRecord(request.params.toolCall) && typeof request.params.toolCall.title === 'string'
427
+ ? request.params.toolCall.title
428
+ : 'a tool call';
429
+ if (!choice || typeof choice.optionId !== 'string') {
430
+ this.emit({ type: 'note', message: `Copilot asked permission for ${title} with no option cezar could pick; cancelled` });
431
+ return { result: { outcome: { outcome: 'cancelled' } } };
432
+ }
433
+ this.emit({
434
+ type: 'note',
435
+ message: `Copilot asked permission for ${title}; auto-approved (${String(choice.kind ?? choice.optionId)}) — cezar runs Copilot in auto mode`,
436
+ });
437
+ return { result: { outcome: { outcome: 'selected', optionId: choice.optionId } } };
438
+ }
439
+ // ---- helpers --------------------------------------------------------------------------
440
+ toAcp(content) {
441
+ const blocks = [];
442
+ let droppedImages = 0;
443
+ for (const block of content) {
444
+ if (block.type === 'text')
445
+ blocks.push({ type: 'text', text: block.text });
446
+ else if (this.imagesSupported || !this.acpSessionId) {
447
+ blocks.push({ type: 'image', data: block.source.data, mimeType: block.source.media_type });
448
+ }
449
+ else
450
+ droppedImages += 1;
451
+ }
452
+ if (droppedImages > 0)
453
+ this.emit({ type: 'note', message: `Copilot CLI does not accept images; dropped ${droppedImages}` });
454
+ return blocks;
455
+ }
456
+ fail(message) {
457
+ if (this.failed)
458
+ return;
459
+ this.failed = message;
460
+ this.emit({ type: 'error', message });
461
+ }
462
+ emit(event) {
463
+ this.onEvent?.(event);
464
+ }
465
+ stderrText() {
466
+ return this.stderr.join('');
467
+ }
468
+ /** Close stdin, then SIGTERM→SIGKILL for a CLI that ignores EOF (#703, #844). `hard` skips the
469
+ * EOF grace: cancel means now. */
470
+ terminate(hard) {
471
+ try {
472
+ this.child.stdin.end();
473
+ }
474
+ catch {
475
+ // already gone
476
+ }
477
+ const signal = (sig) => {
478
+ if (this.hasExited())
479
+ return;
480
+ this.terminatedByCezar = true;
481
+ this.child.kill(sig);
482
+ };
483
+ if (hard) {
484
+ this.terminatedByCezar = true;
485
+ signal('SIGTERM');
486
+ const kill = setTimeout(() => signal('SIGKILL'), EOF_KILL_GRACE_MS);
487
+ kill.unref?.();
488
+ this.timers.push(kill);
489
+ return;
490
+ }
491
+ const term = setTimeout(() => {
492
+ signal('SIGTERM');
493
+ const kill = setTimeout(() => signal('SIGKILL'), EOF_KILL_GRACE_MS);
494
+ kill.unref?.();
495
+ this.timers.push(kill);
496
+ }, EOF_TERM_GRACE_MS);
497
+ term.unref?.();
498
+ this.timers.push(term);
499
+ }
500
+ }
501
+ function waitForExit(child) {
502
+ if (child.exitCode !== null)
503
+ return Promise.resolve(child.exitCode);
504
+ return new Promise((resolve) => {
505
+ child.once('close', (code) => resolve(code));
506
+ child.once('error', () => resolve(child.exitCode ?? null));
507
+ });
508
+ }
509
+ function delay(ms) {
510
+ return new Promise((resolve) => {
511
+ const timer = setTimeout(resolve, ms);
512
+ timer.unref?.();
513
+ });
514
+ }
515
+ /** Path to the bundled mock (`scripts/mock-copilot-acp.mjs`), for CEZ_DRY_RUN=1. */
516
+ function mockCopilotPath() {
517
+ // Resolved like `mockPiPath`: `new URL().pathname` yields `/C:/…` on Windows, which spawn rejects.
518
+ const here = dirname(fileURLToPath(import.meta.url));
519
+ // here = <pkg>/dist/core (built) or <pkg>/src/core (tsx dev).
520
+ return resolvePath(here, '..', '..', 'scripts', 'mock-copilot-acp.mjs');
521
+ }
522
+ function truncate(value, max) {
523
+ return value.length > max ? `${value.slice(0, max)}…` : value;
524
+ }
525
+ function isRecord(value) {
526
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
527
+ }
528
+ //# sourceMappingURL=copilot-acp-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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AG,CAAC,CAAC,CAAC,KAAK,CAAC;AAChE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * GitHub Copilot CLI's ACP dialect (#582) — the per-runner mapper `AGENT_PROTOCOL.md` §9 step 4
3
+ * asks for, over the shared `acp-ui-mapper.ts`.
4
+ *
5
+ * Every rule here was read off `@github/copilot` 1.0.88: the handshake and the auth error from a
6
+ * live `copilot --acp` probe, the streaming frames from the CLI's own ACP bridge inside its
7
+ * bundle. The verification record — with the commands and the code sites — is
8
+ * `.ai/runs/2026-09-27-copilot-cli-runner/copilot-acp-notes.md`, and `__fixtures__/copilot/`
9
+ * cites it frame by frame.
10
+ *
11
+ * Three things make Copilot differ from the plain ACP reading:
12
+ * - it announces a **started** tool as `pending` and never sends `in_progress`;
13
+ * - it tags a delegated agent's tool calls with the delegating `task` call's id, which is real
14
+ * parent attribution — so the nesting cell of the parity matrix needs no substitute;
15
+ * - it carries **no tool name** on the wire, only a rendered title and an ACP kind.
16
+ */
17
+ import { type AcpDialect, type AcpUiMapperState, type AcpUiMapping } from './acp-ui-mapper.ts';
18
+ /**
19
+ * Copilot's own `_meta` namespace on `session/update` frames. Its only member is `agentId`, set
20
+ * exactly when the tool call belongs to a delegated agent, and equal to the `toolCallId` of the
21
+ * `task` call that spawned it.
22
+ */
23
+ export declare const COPILOT_META_KEY = "github.com/copilot";
24
+ /** What a user needs in order to run Copilot CLI. */
25
+ export declare const COPILOT_AUTH_HINT = "GitHub Copilot CLI needs a Copilot-entitled login \u2014 run `copilot login`, or export COPILOT_GITHUB_TOKEN (GH_TOKEN and GITHUB_TOKEN are also read, in that order).";
26
+ /** The run-time line for a rejected credential. "authentication failed" is what
27
+ * `isRuntimeProviderAuthFailure` keys on, so the server raises `provider-auth-required`. */
28
+ export declare const COPILOT_AUTH_FAILURE_MESSAGE = "Copilot CLI authentication failed \u2014 run `copilot login`, or set COPILOT_GITHUB_TOKEN (GH_TOKEN and GITHUB_TOKEN are read too, in that order).";
29
+ /** True for the Copilot auth failures cezar has seen on the wire (see the fixtures). */
30
+ export declare function isCopilotAuthFailure(text: string): boolean;
31
+ /**
32
+ * The tool's own name — a deliberate best-effort reconstruction.
33
+ *
34
+ * Copilot's ACP frames carry `title` (prose built by the CLI: "Editing src/app.ts") and the ACP
35
+ * `kind`, but never the tool name, and its `_meta` holds only `agentId`. Rather than guess a name
36
+ * from argument shapes that several tools share, only two are recovered — each keyed on an
37
+ * argument the CLI's own code proves is that tool's — and everything else reports the ACP kind.
38
+ * That costs nothing on screen: `upsertTool` prefers the wire `title` over anything derived from
39
+ * the name, so the name is used for `toolKindOf` and as a coarse label.
40
+ */
41
+ export declare function copilotToolName(update: Record<string, unknown>): string;
42
+ /** The delegating `task` call's id, for a tool call a subagent made. */
43
+ export declare function copilotParentItem(update: Record<string, unknown>): string | undefined;
44
+ export declare const copilotDialect: AcpDialect;
45
+ export type CopilotUiMapperState = AcpUiMapperState;
46
+ export declare function createCopilotUiState(): CopilotUiMapperState;
47
+ export declare function mapCopilotFrame(frame: unknown, state: CopilotUiMapperState): AcpUiMapping;