@zhivex-ai/harness 1.7.0 → 1.8.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 (388) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +17 -5
  3. package/SECURITY.md +1 -1
  4. package/SUPPORT.md +2 -2
  5. package/benchmarks/README.md +26 -0
  6. package/contracts/engine-api.json +1557 -0
  7. package/contracts/public-api.json +114 -0
  8. package/contracts/stable-api-signatures.json +17 -17
  9. package/dist/acp-cli.js +37 -1090
  10. package/dist/application/agenda.d.ts +10 -0
  11. package/dist/application/approval-review.d.ts +61 -0
  12. package/dist/application/assistant/automation/scheduler.d.ts +21 -0
  13. package/dist/application/assistant/automation/summary.d.ts +29 -0
  14. package/dist/application/assistant/automation/time.d.ts +10 -0
  15. package/dist/application/assistant/calendar/calendar.d.ts +238 -0
  16. package/dist/application/assistant/calendar/connection.d.ts +50 -0
  17. package/dist/application/assistant/calendar/create-event.d.ts +75 -0
  18. package/dist/application/assistant/calendar/environment.d.ts +2 -0
  19. package/dist/application/assistant/calendar/http.d.ts +6 -0
  20. package/dist/application/assistant/calendar/oauth.d.ts +68 -0
  21. package/dist/application/assistant/calendar/store.d.ts +11 -0
  22. package/dist/application/assistant/calendar/tools.d.ts +78 -0
  23. package/dist/application/assistant/client.d.ts +10 -0
  24. package/dist/application/assistant/config.d.ts +9 -0
  25. package/dist/application/assistant/contracts.d.ts +77 -0
  26. package/dist/application/assistant/daily/service.d.ts +181 -0
  27. package/dist/application/assistant/doctor.d.ts +22 -0
  28. package/dist/application/assistant/evaluation.d.ts +81 -0
  29. package/dist/application/assistant/host.d.ts +399 -0
  30. package/dist/application/assistant/integrations/google.d.ts +117 -0
  31. package/dist/application/assistant/integrations/public-web.d.ts +16 -0
  32. package/dist/application/assistant/managed/secrets.d.ts +10 -0
  33. package/dist/application/assistant/managed/setup-state.d.ts +346 -0
  34. package/dist/application/assistant/managed/setup.d.ts +492 -0
  35. package/dist/application/assistant/microsoft/connection.d.ts +73 -0
  36. package/dist/application/assistant/microsoft/tools.d.ts +78 -0
  37. package/dist/application/assistant/modules/calendar.d.ts +3 -0
  38. package/dist/application/assistant/modules/catalog.d.ts +38 -0
  39. package/dist/application/assistant/modules/daily.d.ts +5 -0
  40. package/dist/application/assistant/modules/github.d.ts +5 -0
  41. package/dist/application/assistant/modules/google.d.ts +3 -0
  42. package/dist/application/assistant/modules/mcp.d.ts +11 -0
  43. package/dist/application/assistant/modules/microsoft.d.ts +3 -0
  44. package/dist/application/assistant/modules/module.d.ts +224 -0
  45. package/dist/application/assistant/modules/tools.d.ts +11 -0
  46. package/dist/application/assistant/modules/web.d.ts +7 -0
  47. package/dist/application/assistant/private-directory.d.ts +3 -0
  48. package/dist/application/assistant/proactive/service.d.ts +142 -0
  49. package/dist/application/assistant/providers/openai-compatible.d.ts +66 -0
  50. package/dist/application/assistant/providers/provider.d.ts +141 -0
  51. package/dist/application/assistant/providers/web-citations.d.ts +2 -0
  52. package/dist/application/assistant/runtime.d.ts +16 -0
  53. package/dist/application/assistant/task-metrics.d.ts +304 -0
  54. package/dist/application/assistant/telegram/api.d.ts +47 -0
  55. package/dist/application/assistant/telegram/bridge.d.ts +69 -0
  56. package/dist/application/assistant/telegram/store.d.ts +10 -0
  57. package/dist/application/automation.d.ts +5 -0
  58. package/dist/application/calendar-review.d.ts +5 -0
  59. package/dist/application/checkpoint-review.d.ts +30 -0
  60. package/dist/application/client.d.ts +18 -0
  61. package/dist/application/code/context.d.ts +5 -0
  62. package/dist/application/code/delivery.d.ts +6 -0
  63. package/dist/application/code/git-delivery.d.ts +54 -0
  64. package/dist/application/code/github-git-transport.d.ts +15 -0
  65. package/dist/application/code/github-pr-transport.d.ts +6 -0
  66. package/dist/application/code/host.d.ts +25 -0
  67. package/dist/application/code/pr-delivery.d.ts +79 -0
  68. package/dist/application/code/projects.d.ts +90 -0
  69. package/dist/application/code/remote-delivery.d.ts +80 -0
  70. package/dist/application/code/repository.d.ts +9 -0
  71. package/dist/application/code/worktrees.d.ts +123 -0
  72. package/dist/application/contracts.d.ts +288 -0
  73. package/dist/application/coordinator-client.d.ts +33 -0
  74. package/dist/application/coordinator-discovery.d.ts +17 -0
  75. package/dist/application/coordinator-launcher.d.ts +2 -0
  76. package/dist/application/coordinator.d.ts +27 -0
  77. package/dist/application/credential-process.d.ts +13 -0
  78. package/dist/application/host.d.ts +7 -0
  79. package/dist/application/management.d.ts +68 -0
  80. package/dist/application/notes.d.ts +5 -0
  81. package/dist/application/offline-migration.d.ts +16 -0
  82. package/dist/application/personal-state.d.ts +5 -0
  83. package/dist/application/review-channel.d.ts +23 -0
  84. package/dist/application/review-tickets.d.ts +29 -0
  85. package/dist/application/runtime-binding.d.ts +4 -0
  86. package/dist/application-cli-wfh08g41.js +184 -0
  87. package/dist/application-cli-z3f9pvcf.js +209 -0
  88. package/dist/approvals/auto-approve.d.ts +1 -1
  89. package/dist/arguments-75r85mvc.js +27 -0
  90. package/dist/arguments-x24bbqvd.js +22 -0
  91. package/dist/audit/index.js +16 -472
  92. package/dist/audit-pack-1gnych0m.js +93 -0
  93. package/dist/{audit-pack-y02n8zd0.js → audit-pack-h44kjkbj.js} +17 -11
  94. package/dist/calendar-2xw0rr7b.js +49 -0
  95. package/dist/cli/application-cli.d.ts +2 -0
  96. package/dist/cli/arguments.d.ts +14 -1
  97. package/dist/cli/auto-approve-setup.d.ts +13 -0
  98. package/dist/cli/configured-harness.d.ts +1 -2
  99. package/dist/cli/console/console-budget.d.ts +16 -2
  100. package/dist/cli/console/console-checkpoints.d.ts +12 -0
  101. package/dist/cli/console/console-commands.d.ts +3 -3
  102. package/dist/cli/console/console-compaction.d.ts +1 -1
  103. package/dist/cli/console/console-diff.d.ts +2 -0
  104. package/dist/cli/console/console-input.d.ts +29 -1
  105. package/dist/cli/console/console-navigation.d.ts +2 -2
  106. package/dist/cli/console/console-outcome.d.ts +10 -0
  107. package/dist/cli/console/console-presentation.d.ts +17 -2
  108. package/dist/cli/console/console-pricing.d.ts +14 -0
  109. package/dist/cli/console/console-reasoning.d.ts +1 -1
  110. package/dist/cli/console/console-recovery.d.ts +2 -0
  111. package/dist/cli/console/console-review.d.ts +34 -0
  112. package/dist/cli/console/console-run-policy.d.ts +5 -0
  113. package/dist/cli/console/console-run-view.d.ts +28 -0
  114. package/dist/cli/console/console-task.d.ts +30 -0
  115. package/dist/cli/console/console-welcome.d.ts +13 -3
  116. package/dist/cli/console/review-diff.d.ts +20 -0
  117. package/dist/cli/presentation.d.ts +8 -6
  118. package/dist/cli/service-checkpoints.d.ts +234 -0
  119. package/dist/cli/terminal/activity-history.d.ts +4 -2
  120. package/dist/cli/terminal/activity-stream.d.ts +33 -0
  121. package/dist/cli/terminal/file-diff.d.ts +11 -0
  122. package/dist/cli/terminal/terminal-theme.d.ts +9 -0
  123. package/dist/cli/terminal/terminal-ui.d.ts +44 -2
  124. package/dist/cli/terminal/tool-activity.d.ts +6 -2
  125. package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
  126. package/dist/{cli-entry-j6jcb2jb.js → cli-entry-86rcbmwh.js} +294 -14
  127. package/dist/cli-entry-btkpb4h1.js +3627 -0
  128. package/dist/cli-entry-bxjbs6qq.js +200 -0
  129. package/dist/cli-entry-cpm89r9q.js +624 -0
  130. package/dist/{cli-entry-v5db3eb2.js → cli-entry-dksm56sj.js} +39 -297
  131. package/dist/{cli-entry-td04s0fa.js → cli-entry-eka68ttb.js} +3919 -4549
  132. package/dist/cli-entry-h7dcah4p.js +137 -0
  133. package/dist/cli-entry-kwk23ktq.js +33 -0
  134. package/dist/{cli-entry-ynahz9qc.js → cli-entry-vmce694z.js} +1251 -3139
  135. package/dist/cli-entry-wanv05db.js +1113 -0
  136. package/dist/{cli-zw18kdqx.js → cli-z7vhm1rk.js} +1767 -380
  137. package/dist/cli.js +8 -6
  138. package/dist/client/json-contracts.d.ts +153 -0
  139. package/dist/client/local-service.d.ts +7 -12
  140. package/dist/client/local-transport.d.ts +14 -0
  141. package/dist/client/protocol.d.ts +43 -1
  142. package/dist/compat/cli-options.d.ts +7 -1
  143. package/dist/compat/cli.d.ts +2 -0
  144. package/dist/compat/cli.js +4043 -0
  145. package/dist/compat/code-support.d.ts +3 -0
  146. package/dist/compat/code-support.js +50 -28
  147. package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
  148. package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
  149. package/dist/context/adaptive-compaction.d.ts +1 -0
  150. package/dist/context/lossless-lines.d.ts +13 -0
  151. package/dist/context/numbered-read-lines.d.ts +15 -0
  152. package/dist/context/read-attempts.d.ts +21 -0
  153. package/dist/context/request-projection.d.ts +32 -4
  154. package/dist/context/scoped-context.d.ts +14 -0
  155. package/dist/context/working-read-replay.d.ts +12 -0
  156. package/dist/coordinator-client-nzysqxf0.js +10 -0
  157. package/dist/engine/acp.js +27 -21
  158. package/dist/engine/application-client.d.ts +11 -0
  159. package/dist/engine/application-client.js +18 -0
  160. package/dist/engine/application-protocol.d.ts +5 -0
  161. package/dist/engine/application-protocol.js +7 -0
  162. package/dist/engine/application.d.ts +43 -0
  163. package/dist/engine/application.js +206 -0
  164. package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
  165. package/dist/engine/assistant/automation/scheduler.js +11 -0
  166. package/dist/engine/assistant/automation/summary.d.ts +3 -0
  167. package/dist/engine/assistant/automation/summary.js +8 -0
  168. package/dist/engine/assistant/automation/time.d.ts +5 -0
  169. package/dist/engine/assistant/automation/time.js +15 -0
  170. package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
  171. package/dist/engine/assistant/calendar/calendar.js +12 -0
  172. package/dist/engine/assistant/calendar/connection.d.ts +2 -0
  173. package/dist/engine/assistant/calendar/connection.js +11 -0
  174. package/dist/engine/assistant/calendar/environment.d.ts +1 -0
  175. package/dist/engine/assistant/calendar/environment.js +7 -0
  176. package/dist/engine/assistant/calendar/http.d.ts +3 -0
  177. package/dist/engine/assistant/calendar/http.js +9 -0
  178. package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
  179. package/dist/engine/assistant/calendar/oauth.js +12 -0
  180. package/dist/engine/assistant/calendar/store.d.ts +2 -0
  181. package/dist/engine/assistant/calendar/store.js +8 -0
  182. package/dist/engine/assistant/calendar/tools.d.ts +2 -0
  183. package/dist/engine/assistant/calendar/tools.js +46 -0
  184. package/dist/engine/assistant/client.d.ts +2 -0
  185. package/dist/engine/assistant/client.js +33 -0
  186. package/dist/engine/assistant/config.d.ts +1 -0
  187. package/dist/engine/assistant/config.js +102 -0
  188. package/dist/engine/assistant/contracts.d.ts +10 -0
  189. package/dist/engine/assistant/contracts.js +78 -0
  190. package/dist/engine/assistant/daily/service.d.ts +12 -0
  191. package/dist/engine/assistant/daily/service.js +27 -0
  192. package/dist/engine/assistant/doctor.d.ts +1 -0
  193. package/dist/engine/assistant/doctor.js +116 -0
  194. package/dist/engine/assistant/evaluation.d.ts +2 -0
  195. package/dist/engine/assistant/evaluation.js +76 -0
  196. package/dist/engine/assistant/host.d.ts +2 -0
  197. package/dist/engine/assistant/host.js +63 -0
  198. package/dist/engine/assistant/integrations/google.d.ts +9 -0
  199. package/dist/engine/assistant/integrations/google.js +30 -0
  200. package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
  201. package/dist/engine/assistant/integrations/public-web.js +11 -0
  202. package/dist/engine/assistant/managed/secrets.d.ts +1 -0
  203. package/dist/engine/assistant/managed/secrets.js +0 -0
  204. package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
  205. package/dist/engine/assistant/managed/setup-state.js +84 -0
  206. package/dist/engine/assistant/managed/setup.d.ts +3 -0
  207. package/dist/engine/assistant/managed/setup.js +85 -0
  208. package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
  209. package/dist/engine/assistant/microsoft/connection.js +21 -0
  210. package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
  211. package/dist/engine/assistant/microsoft/tools.js +30 -0
  212. package/dist/engine/assistant/modules/calendar.d.ts +1 -0
  213. package/dist/engine/assistant/modules/calendar.js +49 -0
  214. package/dist/engine/assistant/modules/catalog.d.ts +3 -0
  215. package/dist/engine/assistant/modules/catalog.js +67 -0
  216. package/dist/engine/assistant/modules/daily.d.ts +1 -0
  217. package/dist/engine/assistant/modules/daily.js +48 -0
  218. package/dist/engine/assistant/modules/github.d.ts +1 -0
  219. package/dist/engine/assistant/modules/github.js +43 -0
  220. package/dist/engine/assistant/modules/google.d.ts +1 -0
  221. package/dist/engine/assistant/modules/google.js +53 -0
  222. package/dist/engine/assistant/modules/mcp.d.ts +1 -0
  223. package/dist/engine/assistant/modules/mcp.js +42 -0
  224. package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
  225. package/dist/engine/assistant/modules/microsoft.js +53 -0
  226. package/dist/engine/assistant/modules/module.d.ts +5 -0
  227. package/dist/engine/assistant/modules/module.js +42 -0
  228. package/dist/engine/assistant/modules/tools.d.ts +2 -0
  229. package/dist/engine/assistant/modules/tools.js +42 -0
  230. package/dist/engine/assistant/modules/web.d.ts +1 -0
  231. package/dist/engine/assistant/modules/web.js +45 -0
  232. package/dist/engine/assistant/private-directory.d.ts +1 -0
  233. package/dist/engine/assistant/private-directory.js +7 -0
  234. package/dist/engine/assistant/proactive/service.d.ts +6 -0
  235. package/dist/engine/assistant/proactive/service.js +16 -0
  236. package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
  237. package/dist/engine/assistant/providers/openai-compatible.js +12 -0
  238. package/dist/engine/assistant/providers/provider.d.ts +7 -0
  239. package/dist/engine/assistant/providers/provider.js +54 -0
  240. package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
  241. package/dist/engine/assistant/providers/web-citations.js +7 -0
  242. package/dist/engine/assistant/runtime.d.ts +2 -0
  243. package/dist/engine/assistant/runtime.js +73 -0
  244. package/dist/engine/assistant/task-metrics.d.ts +8 -0
  245. package/dist/engine/assistant/task-metrics.js +17 -0
  246. package/dist/engine/assistant/telegram/api.d.ts +5 -0
  247. package/dist/engine/assistant/telegram/api.js +11 -0
  248. package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
  249. package/dist/engine/assistant/telegram/bridge.js +40 -0
  250. package/dist/engine/assistant/telegram/store.d.ts +2 -0
  251. package/dist/engine/assistant/telegram/store.js +8 -0
  252. package/dist/engine/client.js +26 -18
  253. package/dist/engine/desktop-providers-v1.js +4 -4
  254. package/dist/engine/desktop-state-v1.js +16 -13
  255. package/dist/engine/index.js +111 -159
  256. package/dist/engine/mcp-stdio-v1.js +13 -12
  257. package/dist/engine/models.js +65 -23
  258. package/dist/engine/protocol.js +10 -6
  259. package/dist/engine/service.js +32 -21
  260. package/dist/hostile-repository-demo.js +1822 -696
  261. package/dist/index-09rsdr2d.js +1744 -0
  262. package/dist/index-0csc5sc7.js +139 -0
  263. package/dist/{index-v86bh0eg.js → index-0dkty795.js} +8 -6
  264. package/dist/index-0kkgqvg7.js +0 -0
  265. package/dist/index-0mzz9axm.js +58 -0
  266. package/dist/index-1e69ar8r.js +38 -0
  267. package/dist/index-1z0xhkh9.js +18 -0
  268. package/dist/index-2cef1k92.js +356 -0
  269. package/dist/{index-k1a1xesg.js → index-2j0v1xwr.js} +17 -13
  270. package/dist/index-2jw9jd7h.js +116 -0
  271. package/dist/index-2n9qx4km.js +0 -0
  272. package/dist/index-3rvk23e8.js +877 -0
  273. package/dist/index-3wa4j0yk.js +71 -0
  274. package/dist/index-41q1k17x.js +210 -0
  275. package/dist/index-4vz4bqqw.js +33 -0
  276. package/dist/index-5jxm2wy5.js +123 -0
  277. package/dist/index-5rk6ss42.js +216 -0
  278. package/dist/index-5v1skxf7.js +1852 -0
  279. package/dist/{index-qz4fs9f9.js → index-6ehtssyz.js} +355 -332
  280. package/dist/index-76kpdbpw.js +80 -0
  281. package/dist/{index-r0q0r88h.js → index-7nbmhmw5.js} +10 -10
  282. package/dist/index-8mx0yrkz.js +31 -0
  283. package/dist/index-8tjev5ds.js +11 -0
  284. package/dist/index-91n5wr6s.js +163 -0
  285. package/dist/index-91trs3ew.js +151 -0
  286. package/dist/index-9y8p5vy5.js +222 -0
  287. package/dist/index-abxahprd.js +55 -0
  288. package/dist/index-aptyr511.js +84 -0
  289. package/dist/{index-8sm2a1wa.js → index-ay26xfxt.js} +28 -20
  290. package/dist/index-b4yed1s3.js +657 -0
  291. package/dist/index-bb7phvtg.js +23 -0
  292. package/dist/index-bk5tn9b8.js +236 -0
  293. package/dist/index-bw34861c.js +292 -0
  294. package/dist/index-c6fnjhgv.js +55 -0
  295. package/dist/{index-qfsrrnz6.js → index-cjevq9s8.js} +2 -2
  296. package/dist/{index-c39197wq.js → index-ctcwrkrc.js} +4 -4
  297. package/dist/{index-yx52bt4a.js → index-cztmcesv.js} +2 -2
  298. package/dist/index-dpbmxnrf.js +564 -0
  299. package/dist/index-ekxdcy36.js +134 -0
  300. package/dist/index-f8zpcsx3.js +289 -0
  301. package/dist/{index-6dxrbnxm.js → index-f970qtb4.js} +7 -143
  302. package/dist/index-fatcn6fp.js +2791 -0
  303. package/dist/index-fbzykqxy.js +105 -0
  304. package/dist/{index-1265j7t2.js → index-fwf274vc.js} +24 -14
  305. package/dist/index-fy4w0a7v.js +0 -0
  306. package/dist/index-gvva3e5x.js +76 -0
  307. package/dist/index-h7dcah4p.js +137 -0
  308. package/dist/index-hm9r120s.js +42 -0
  309. package/dist/index-j3d2tw97.js +328 -0
  310. package/dist/index-jfqj20x8.js +41 -0
  311. package/dist/{index-yp0jtaxp.js → index-k529a278.js} +6 -6
  312. package/dist/{index-bt2p8x7r.js → index-kbrf5bx7.js} +110 -106
  313. package/dist/index-kwk23ktq.js +33 -0
  314. package/dist/index-kz857p1j.js +557 -0
  315. package/dist/{index-tc2r2n8b.js → index-mkt5yrax.js} +31 -105
  316. package/dist/{index-tgt8gtq7.js → index-ndgnvjez.js} +18 -18
  317. package/dist/index-nemn4epv.js +43 -0
  318. package/dist/index-nkwy5bjr.js +1225 -0
  319. package/dist/index-nvvzr4ny.js +136 -0
  320. package/dist/index-pkspzsfs.js +78 -0
  321. package/dist/{index-fm84men1.js → index-px1tnqgt.js} +2 -2
  322. package/dist/index-q7qdw883.js +79 -0
  323. package/dist/{index-mzydbzp8.js → index-qvbg6tx1.js} +65 -23
  324. package/dist/index-r3mwr5fb.js +0 -0
  325. package/dist/index-rdr78m0k.js +91 -0
  326. package/dist/index-rtamqsfs.js +59 -0
  327. package/dist/index-s125ss45.js +38 -0
  328. package/dist/{index-h8r80xhk.js → index-sx1t6dnd.js} +4005 -2781
  329. package/dist/index-tar0ngkm.js +359 -0
  330. package/dist/index-tn58cr6w.js +471 -0
  331. package/dist/{index-v17e1xs8.js → index-v79s9bf9.js} +96 -23
  332. package/dist/index-vk3rq21m.js +17 -0
  333. package/dist/index-vmvnr28y.js +72 -0
  334. package/dist/index-vz629cg8.js +49 -0
  335. package/dist/{index-eps3c3g6.js → index-w292hdpz.js} +197 -960
  336. package/dist/{index-t6sjhxh8.js → index-w9eqg6p9.js} +24 -302
  337. package/dist/index-wj96kdw2.js +57 -0
  338. package/dist/index-wyck5yhd.js +141 -0
  339. package/dist/index-xvtk8pxs.js +674 -0
  340. package/dist/{index-bpc596v3.js → index-xwb691v9.js} +2 -2
  341. package/dist/index-ym69x168.js +518 -0
  342. package/dist/index-yprdjk9v.js +65 -0
  343. package/dist/index-z2a81ccr.js +35 -0
  344. package/dist/{index-3ah1f369.js → index-z69cqk74.js} +3 -3
  345. package/dist/index-zaakvmzq.js +62 -0
  346. package/dist/index-zk3m4mzg.js +232 -0
  347. package/dist/index-zx3wgvx4.js +218 -0
  348. package/dist/index.js +102 -83
  349. package/dist/persistence/migration-guard.d.ts +3 -0
  350. package/dist/runtime/harness.d.ts +2 -0
  351. package/dist/service-cli.js +130 -40
  352. package/dist/service-client-cli-2rzxy5mj.js +1166 -0
  353. package/dist/service-client-cli-5ne8q5ej.js +543 -0
  354. package/dist/tools/ooxml-zip.d.ts +21 -0
  355. package/dist/tools/presentations.d.ts +47 -0
  356. package/dist/tools/tabular-data.d.ts +114 -0
  357. package/dist/tools/workspace.d.ts +76 -0
  358. package/dist/verify-historical-migrations.js +1923 -797
  359. package/dist/workspace/workspace.d.ts +13 -1
  360. package/dist/zhx.js +8 -6
  361. package/docs/APPLICATION_MIGRATION.md +32 -0
  362. package/docs/CLI.md +166 -2
  363. package/docs/CODE_RELEASE.md +5 -3
  364. package/docs/CODE_WEB_TASKS.md +3 -114
  365. package/docs/CONTEXT_ENGINEERING.md +27 -0
  366. package/docs/ENGINE_API.md +1 -1
  367. package/docs/EXTENSIBILITY.md +1 -1
  368. package/docs/FIRST_USE.md +6 -6
  369. package/docs/INTERNAL_ARCHIVE.md +43 -0
  370. package/docs/LOCAL_SERVICE.md +1 -1
  371. package/docs/MODEL_CATALOG.md +14 -0
  372. package/docs/README.md +13 -2
  373. package/evaluations/representative-assembly-matrix.json +10 -1
  374. package/examples/README.md +3 -3
  375. package/examples/assistant/compatible-calendar.json +17 -0
  376. package/examples/assistant/composed-modules.json +23 -0
  377. package/examples/assistant/connected-tools.json +9 -0
  378. package/examples/assistant/daily-tools.json +6 -0
  379. package/examples/assistant/offline.mjs +24 -0
  380. package/fixtures/cli-compatibility/README.md +10 -0
  381. package/fixtures/cli-compatibility/inventory.json +7858 -0
  382. package/package.json +230 -28
  383. package/dist/cli/console/console-model-catalog.d.ts +0 -8
  384. package/dist/index-4gt045j0.js +0 -288
  385. package/dist/index-4jw3tvy8.js +0 -301
  386. package/dist/index-ebb5d4s3.js +0 -640
  387. package/dist/index-x9hv1a34.js +0 -274
  388. package/dist/service-client-cli-gtk26axb.js +0 -1251
@@ -0,0 +1,877 @@
1
+ import {
2
+ appendAutoApproval,
3
+ approvalFacts,
4
+ buildSnapshots,
5
+ classifyApproval,
6
+ createAutoApprovalEntry,
7
+ revealInvisible
8
+ } from "./index-dpbmxnrf.js";
9
+
10
+ // packages/core/src/cli/terminal/terminal-theme.ts
11
+ var palettes = {
12
+ light: { muted: 59, accent: 160, added: 22, removed: 124, info: 25, pending: 94 },
13
+ dark: { muted: 250, accent: 203, added: 120, removed: 210, info: 117, pending: 222 }
14
+ };
15
+ var sessionTheme;
16
+ function terminalThemeChoice(env = process.env) {
17
+ const choice = sessionTheme ?? env.ZHIVEX_THEME;
18
+ return choice === "light" || choice === "dark" ? choice : "system";
19
+ }
20
+ function resolveTerminalTheme(choice, env = process.env) {
21
+ if (choice !== "system")
22
+ return choice;
23
+ const raw = env.COLORFGBG?.split(";").at(-1);
24
+ if (raw && /^\d+$/.test(raw)) {
25
+ const background = Number(raw);
26
+ if (background === 7 || background === 15 || background >= 250 && background <= 255)
27
+ return "light";
28
+ }
29
+ return "dark";
30
+ }
31
+ function terminalToneCode(tone, env = process.env) {
32
+ return `38;5;${palettes[resolveTerminalTheme(terminalThemeChoice(env), env)][tone]}`;
33
+ }
34
+ function paintTerminal(text, tone, color) {
35
+ return color ? `\x1B[${terminalToneCode(tone)}m${text}\x1B[0m` : text;
36
+ }
37
+ function terminalThemeCommand(command) {
38
+ const value = command.slice("/theme".length).trim();
39
+ if (value && value !== "light" && value !== "dark" && value !== "system")
40
+ return `Usage: /theme light|dark|system
41
+ `;
42
+ if (value === "light" || value === "dark" || value === "system")
43
+ sessionTheme = value;
44
+ const choice = terminalThemeChoice();
45
+ return `Appearance: ${choice} (${resolveTerminalTheme(choice)} palette). Terminal background is unchanged.
46
+ ` + `Use /theme light|dark|system. Set ZHIVEX_THEME for future launches; system reads COLORFGBG, defaulting to dark.
47
+ `;
48
+ }
49
+
50
+ // packages/core/src/cli/terminal/session-grants.ts
51
+ function checkApprovalGrant(approval, workspace) {
52
+ if (approval.kind !== "local-tool" || approval.name !== "run_check")
53
+ return;
54
+ try {
55
+ const args = JSON.parse(approval.arguments);
56
+ if (!args || typeof args !== "object" || Array.isArray(args))
57
+ return;
58
+ const value = args;
59
+ if (Object.keys(value).sort().join(",") !== "check,expectedScript" || typeof value.check !== "string" || typeof value.expectedScript !== "string" || !value.expectedScript.trim())
60
+ return;
61
+ return JSON.stringify([workspace, approval.provider, approval.childAgentId ?? "", approval.name, value.check, value.expectedScript]);
62
+ } catch {
63
+ return;
64
+ }
65
+ }
66
+
67
+ // packages/core/src/cli/terminal/terminal-table.ts
68
+ var segments = new Intl.Segmenter(undefined, { granularity: "grapheme" });
69
+ var graphemes = (value) => [...segments.segment(value)].map((item) => item.segment);
70
+ var terminalCellWidth = (value) => graphemes(value).reduce((width, part) => {
71
+ if (/^[\p{Mark}\u200d\ufe0f]+$/u.test(part))
72
+ return width;
73
+ const code = part.codePointAt(0);
74
+ const wide = /\p{Extended_Pictographic}|\p{Regional_Indicator}|\u20e3/u.test(part) || code >= 4352 && (code <= 4447 || code === 9001 || code === 9002 || code >= 11904 && code <= 42191 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65040 && code <= 65135 || code >= 65281 && code <= 65376 || code >= 65504 && code <= 65510 || code >= 131072);
75
+ return width + (wide ? 2 : 1);
76
+ }, 0);
77
+ function tableCells(line) {
78
+ let text = line.trim();
79
+ if (text.startsWith("|"))
80
+ text = text.slice(1);
81
+ const cells = [];
82
+ let cell = "", ticks = 0;
83
+ for (let i = 0;i < text.length; i++) {
84
+ const char = text[i];
85
+ if (char === "\\" && text[i + 1] === "|") {
86
+ cell += "|";
87
+ i++;
88
+ continue;
89
+ }
90
+ if (char === "`") {
91
+ let count = 1;
92
+ while (text[i + count] === "`")
93
+ count++;
94
+ ticks = ticks === count ? 0 : ticks || count;
95
+ cell += "`".repeat(count);
96
+ i += count - 1;
97
+ continue;
98
+ }
99
+ if (char === "|" && !ticks) {
100
+ cells.push(cell.trim());
101
+ cell = "";
102
+ } else
103
+ cell += char;
104
+ }
105
+ if (cell.trim() || !text.endsWith("|"))
106
+ cells.push(cell.trim());
107
+ return cells;
108
+ }
109
+ var isTableSeparator = (line, columns) => {
110
+ const cells = tableCells(line);
111
+ return cells.length === columns && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
112
+ };
113
+ var plainCell = (value) => value.replace(/(`+)(.*?)\1/g, "$2").replace(/\*\*(.+?)\*\*/g, "$1").replace(/\s+/g, " ").trim();
114
+ function wrap(value, width) {
115
+ const lines = [];
116
+ let line = "", used = 0;
117
+ for (const word of value.split(" ")) {
118
+ const size = terminalCellWidth(word);
119
+ if (line && used + 1 + size > width) {
120
+ lines.push(line);
121
+ line = "";
122
+ used = 0;
123
+ }
124
+ if (line) {
125
+ line += " ";
126
+ used++;
127
+ }
128
+ for (const part of graphemes(word)) {
129
+ const size2 = terminalCellWidth(part);
130
+ if (line && used + size2 > width) {
131
+ lines.push(line);
132
+ line = "";
133
+ used = 0;
134
+ }
135
+ line += part;
136
+ used += size2;
137
+ }
138
+ }
139
+ if (line || !lines.length)
140
+ lines.push(line);
141
+ return lines;
142
+ }
143
+ function renderTerminalTable(lines, columns, color) {
144
+ const rows = [lines[0], ...lines.slice(2)].map((line) => tableCells(line).map(plainCell));
145
+ const count = rows[0].length;
146
+ const width = Math.max(4, Math.min(240, Number.isFinite(columns) ? Math.floor(columns) - 1 : 79));
147
+ const bold = (value) => color ? `\x1B[1m${value}\x1B[0m` : value;
148
+ if (width < count * 7 + 1) {
149
+ if (rows.length === 1)
150
+ return rows[0].map((cell) => bold(wrap(cell, width).join(`
151
+ `))).join(`
152
+ `) + `
153
+ `;
154
+ return rows.slice(1).map((row) => row.map((cell, i) => [bold(wrap(rows[0][i] + ":", width).join(`
155
+ `)), ...wrap(cell, width)].join(`
156
+ `)).join(`
157
+ `)).join(`
158
+
159
+ `) + `
160
+ `;
161
+ }
162
+ const desired = Array.from({ length: count }, (_, i) => Math.max(4, ...rows.map((row) => terminalCellWidth(row[i] ?? ""))));
163
+ const widths = Array(count).fill(4);
164
+ let remaining = width - 7 * count - 1;
165
+ while (remaining-- > 0) {
166
+ let smallest = -1;
167
+ for (let i = 0;i < count; i++)
168
+ if (widths[i] < desired[i] && (smallest < 0 || widths[i] < widths[smallest]))
169
+ smallest = i;
170
+ if (smallest < 0)
171
+ break;
172
+ widths[smallest]++;
173
+ }
174
+ const align = tableCells(lines[1]).map((cell) => cell.endsWith(":") ? cell.startsWith(":") ? "center" : "right" : "left");
175
+ const border = (left, mid, right) => left + widths.map((size) => "─".repeat(size + 2)).join(mid) + right;
176
+ const rendered = [border("┌", "┬", "┐")];
177
+ rows.forEach((row, index) => {
178
+ const cells = widths.map((size, i) => wrap(row[i] ?? "", size));
179
+ for (let line = 0;line < Math.max(...cells.map((cell) => cell.length)); line++) {
180
+ rendered.push("│ " + cells.map((cell, i) => {
181
+ const text = cell[line] ?? "", spare = widths[i] - terminalCellWidth(text);
182
+ const left = align[i] === "right" ? spare : align[i] === "center" ? Math.floor(spare / 2) : 0;
183
+ const padded = " ".repeat(left) + text + " ".repeat(spare - left);
184
+ return index === 0 ? bold(padded) : padded;
185
+ }).join(" │ ") + " │");
186
+ }
187
+ if (index === 0)
188
+ rendered.push(border("├", "┼", "┤"));
189
+ });
190
+ rendered.push(border("└", "┴", "┘"));
191
+ return rendered.join(`
192
+ `) + `
193
+ `;
194
+ }
195
+
196
+ // packages/core/src/cli/console/review-diff.ts
197
+ var segments2 = new Intl.Segmenter(undefined, { granularity: "grapheme" });
198
+ var tokensOf = (value) => {
199
+ const tokens = [];
200
+ const pattern = /\s+|\S+/g;
201
+ for (const match of value.matchAll(pattern)) {
202
+ const text = match[0];
203
+ tokens.push({ text, start: match.index ?? 0, end: (match.index ?? 0) + text.length });
204
+ }
205
+ return tokens;
206
+ };
207
+ var markWordChanges = (before, after) => {
208
+ const oldTokens = tokensOf(before);
209
+ const newTokens = tokensOf(after);
210
+ const rows = oldTokens.length + 1;
211
+ const cols = newTokens.length + 1;
212
+ const scores = Array.from({ length: rows }, () => Array(cols).fill(0));
213
+ for (let row2 = oldTokens.length - 1;row2 >= 0; row2 -= 1) {
214
+ for (let col2 = newTokens.length - 1;col2 >= 0; col2 -= 1) {
215
+ const current = scores[row2];
216
+ const next = scores[row2 + 1];
217
+ if (!current || !next)
218
+ continue;
219
+ current[col2] = oldTokens[row2]?.text === newTokens[col2]?.text ? (next[col2 + 1] ?? 0) + 1 : Math.max(next[col2] ?? 0, current[col2 + 1] ?? 0);
220
+ }
221
+ }
222
+ const oldChanged = new Set;
223
+ const newChanged = new Set;
224
+ let row = 0;
225
+ let col = 0;
226
+ while (row < oldTokens.length && col < newTokens.length) {
227
+ if (oldTokens[row]?.text === newTokens[col]?.text) {
228
+ row += 1;
229
+ col += 1;
230
+ continue;
231
+ }
232
+ const down = scores[row + 1]?.[col] ?? 0;
233
+ const right = scores[row]?.[col + 1] ?? 0;
234
+ if (down >= right) {
235
+ oldChanged.add(row);
236
+ row += 1;
237
+ } else {
238
+ newChanged.add(col);
239
+ col += 1;
240
+ }
241
+ }
242
+ while (row < oldTokens.length) {
243
+ oldChanged.add(row);
244
+ row += 1;
245
+ }
246
+ while (col < newTokens.length) {
247
+ newChanged.add(col);
248
+ col += 1;
249
+ }
250
+ return { before: wrapChanged(before, oldTokens, oldChanged), after: wrapChanged(after, newTokens, newChanged) };
251
+ };
252
+ var wrapChanged = (value, tokens, changed) => {
253
+ let cursor = 0;
254
+ let text = "";
255
+ tokens.forEach((token, index) => {
256
+ text += value.slice(cursor, token.start);
257
+ const meaningful = changed.has(index) && token.text.trim().length > 0;
258
+ text += meaningful ? `«${token.text}»` : token.text;
259
+ cursor = token.end;
260
+ });
261
+ return text + value.slice(cursor);
262
+ };
263
+ var wrapCode = (gutter, code, width) => {
264
+ const indent = /^(\s*)/.exec(code)?.[1] ?? "";
265
+ const budget = Math.max(1, width - terminalCellWidth(gutter));
266
+ if (terminalCellWidth(code) <= budget)
267
+ return [gutter + code];
268
+ const parts = [];
269
+ let line = "";
270
+ let cells = 0;
271
+ let first = true;
272
+ let open = false;
273
+ for (const { segment } of segments2.segment(code)) {
274
+ const size = terminalCellWidth(segment);
275
+ const limit = first ? budget : Math.max(1, budget - terminalCellWidth(indent));
276
+ const closer = open && segment === "»";
277
+ if (line && cells + size > limit && !closer) {
278
+ if (line.endsWith("«")) {
279
+ const kept = line.slice(0, -1);
280
+ if (kept)
281
+ parts.push(kept);
282
+ line = "«";
283
+ cells = terminalCellWidth("«");
284
+ } else {
285
+ if (open)
286
+ line += "»";
287
+ parts.push(line);
288
+ line = open ? "«" : "";
289
+ cells = line ? terminalCellWidth(line) : 0;
290
+ }
291
+ first = false;
292
+ }
293
+ if (segment === "«")
294
+ open = true;
295
+ else if (segment === "»")
296
+ open = false;
297
+ line += segment;
298
+ cells += size;
299
+ }
300
+ if (line)
301
+ parts.push(line);
302
+ const pad = " ".repeat(terminalCellWidth(gutter));
303
+ return parts.map((part, index) => index === 0 ? gutter + part : pad + indent + part);
304
+ };
305
+ var gutterFor = (oldNo, newNo, mark) => `${oldNo === null ? " " : String(oldNo).padStart(6, " ")} ${newNo === null ? " " : String(newNo).padStart(6, " ")} ${mark}`;
306
+ var renderReviewedDiff = (diff, width) => {
307
+ const source = diff.split(`
308
+ `).map((line) => revealInvisible(line));
309
+ const lines = [];
310
+ const hunks = [];
311
+ let oldNo = 0;
312
+ let newNo = 0;
313
+ let inHunk = false;
314
+ const removed = [];
315
+ const added = [];
316
+ const emitChange = () => {
317
+ const pairs = Math.min(removed.length, added.length);
318
+ for (let index = 0;index < pairs; index += 1) {
319
+ const marked = markWordChanges(removed[index] ?? "", added[index] ?? "");
320
+ lines.push(...wrapCode(gutterFor(oldNo, null, "-"), marked.before, width));
321
+ oldNo += 1;
322
+ lines.push(...wrapCode(gutterFor(null, newNo, "+"), marked.after, width));
323
+ newNo += 1;
324
+ }
325
+ for (const text of removed.slice(pairs)) {
326
+ lines.push(...wrapCode(gutterFor(oldNo, null, "-"), text, width));
327
+ oldNo += 1;
328
+ }
329
+ for (const text of added.slice(pairs)) {
330
+ lines.push(...wrapCode(gutterFor(null, newNo, "+"), text, width));
331
+ newNo += 1;
332
+ }
333
+ removed.length = 0;
334
+ added.length = 0;
335
+ };
336
+ for (const raw of source) {
337
+ if (!raw)
338
+ continue;
339
+ const boundary = raw.startsWith("··· ") || raw.startsWith("--- ") || raw.startsWith("+++ ") || raw.startsWith("Reviewed file diff") || raw.startsWith("File diff") || raw.startsWith("\\ No newline");
340
+ const hunk = /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/.exec(raw);
341
+ if (boundary || hunk || !raw.startsWith("-") && !raw.startsWith("+") && inHunk && raw.startsWith(" "))
342
+ emitChange();
343
+ if (boundary) {
344
+ lines.push(raw);
345
+ continue;
346
+ }
347
+ if (hunk) {
348
+ inHunk = true;
349
+ oldNo = Number(hunk[1]);
350
+ newNo = Number(hunk[3]);
351
+ hunks.push(lines.length);
352
+ lines.push(raw);
353
+ continue;
354
+ }
355
+ if (!inHunk) {
356
+ lines.push(raw);
357
+ continue;
358
+ }
359
+ const mark = raw[0];
360
+ const text = raw.slice(1);
361
+ if (mark === "-") {
362
+ if (added.length)
363
+ emitChange();
364
+ removed.push(text);
365
+ } else if (mark === "+")
366
+ added.push(text);
367
+ else if (mark === " ") {
368
+ lines.push(...wrapCode(gutterFor(oldNo, newNo, " "), text, width));
369
+ oldNo += 1;
370
+ newNo += 1;
371
+ } else
372
+ lines.push(raw);
373
+ }
374
+ emitChange();
375
+ return { lines, hunks };
376
+ };
377
+ var statedIntent = (argumentsText) => {
378
+ try {
379
+ const parsed = JSON.parse(argumentsText);
380
+ if (!parsed || typeof parsed !== "object")
381
+ return;
382
+ const record = parsed;
383
+ for (const key of ["intent", "reason", "summary", "description"]) {
384
+ const value = record[key];
385
+ if (typeof value === "string" && value.trim())
386
+ return sanitizeTerminalText(value.trim().split(`
387
+ `).slice(0, 2).join(" ")).slice(0, 220);
388
+ }
389
+ } catch {
390
+ return;
391
+ }
392
+ };
393
+ var changeSummary = (approval, diffBody) => {
394
+ const intent = statedIntent(approval.arguments);
395
+ const added = diffBody.split(`
396
+ `).filter((line) => line.startsWith("+") && !line.startsWith("+++")).map((line) => line.slice(1)).join(`
397
+ `);
398
+ let file = "";
399
+ try {
400
+ const parsed = JSON.parse(approval.arguments);
401
+ const record = parsed;
402
+ if (typeof record?.path === "string")
403
+ file = record.path;
404
+ else if (typeof record?.changes?.[0]?.path === "string")
405
+ file = record.changes[0].path;
406
+ } catch {}
407
+ if (!file)
408
+ file = /^\+\+\+ (.+)$/m.exec(diffBody)?.[1]?.replace(/^"|"$/g, "") ?? "";
409
+ const safeFile = file ? sanitizeTerminalText(file) : "";
410
+ if (intent)
411
+ return safeFile ? `${intent} (${safeFile})` : intent;
412
+ const thrown = /throw new ([A-Za-z0-9_]+)(?:\((["'])([^"']*)\2\))?/.exec(added);
413
+ if (thrown && safeFile)
414
+ return `Update ${safeFile}. ${thrown[3] ? thrown[3] : `Throw ${thrown[1]}`}.`;
415
+ if (approval.name === "run_check" || approval.name.startsWith("run_environment_")) {
416
+ return "Run the command shown below. It does not run until you approve.";
417
+ }
418
+ if (safeFile)
419
+ return `Update ${safeFile}. Review the highlighted edits. Nothing is written until you approve.`;
420
+ return "Review this change. Nothing is written until you approve.";
421
+ };
422
+
423
+ // packages/core/src/cli/terminal/terminal-ui.ts
424
+ var DEFAULT_APPROVAL_SUMMARY_CHARACTERS = 1200;
425
+ var EXACT_REVIEW_TOOLS = new Set([
426
+ "apply_patch",
427
+ "apply_reviewed_edits",
428
+ "apply_reviewed_replacement",
429
+ "verify_and_apply_reviewed_edits",
430
+ "move_file",
431
+ "quarantine_file",
432
+ "restore_file",
433
+ "run_check",
434
+ "run_environment_command",
435
+ "run_environment_batch",
436
+ "run_environment_shell",
437
+ "apply_environment_patch",
438
+ "verify_and_apply_environment_patch"
439
+ ]);
440
+ var TERMINAL_CONTROL_CHARACTERS = /[\u0000-\u0008\u000b\u000c\u000d\u000e-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/gu;
441
+ var escapeCodePoint = (character) => {
442
+ const codePoint = character.codePointAt(0) ?? 0;
443
+ return codePoint <= 65535 ? `\\u${codePoint.toString(16).padStart(4, "0")}` : `\\u{${codePoint.toString(16)}}`;
444
+ };
445
+ var sanitizeTerminalText = (value) => value.replace(TERMINAL_CONTROL_CHARACTERS, escapeCodePoint);
446
+ var readableApprovalArguments = (argumentsText) => {
447
+ try {
448
+ return sanitizeTerminalText(JSON.stringify(JSON.parse(argumentsText), null, 2));
449
+ } catch {
450
+ return sanitizeTerminalText(argumentsText);
451
+ }
452
+ };
453
+ var boundedText = (value, maximumCharacters) => {
454
+ if (value.length <= maximumCharacters) {
455
+ return { text: value, omitted: 0 };
456
+ }
457
+ return {
458
+ text: `${value.slice(0, maximumCharacters)}…`,
459
+ omitted: value.length - maximumCharacters
460
+ };
461
+ };
462
+ var formatApproval = (approval, options = {}) => {
463
+ const detail = options.detail ?? "summary";
464
+ const maximumCharacters = options.maxSummaryCharacters ?? DEFAULT_APPROVAL_SUMMARY_CHARACTERS;
465
+ if (!Number.isSafeInteger(maximumCharacters) || maximumCharacters < 1) {
466
+ throw new Error("Approval summary length must be a positive safe integer.");
467
+ }
468
+ const completePayload = readableApprovalArguments(approval.arguments);
469
+ const shouldShowComplete = detail === "full" || EXACT_REVIEW_TOOLS.has(approval.name);
470
+ const payload = shouldShowComplete ? { text: completePayload, omitted: 0 } : boundedText(completePayload, maximumCharacters);
471
+ const identity = [
472
+ detail === "full" && approval.id ? `approval ${sanitizeTerminalText(approval.id)}` : undefined,
473
+ detail === "full" && approval.inputDigest ? `input ${sanitizeTerminalText(approval.inputDigest)}` : undefined,
474
+ approval.serverLabel ? `server ${sanitizeTerminalText(approval.serverLabel)}` : undefined,
475
+ approval.childAgentId ? `child ${sanitizeTerminalText(approval.childAgentId)}` : undefined
476
+ ].filter((value) => value !== undefined);
477
+ const header = `[${sanitizeTerminalText(approval.kind ?? "provider")}] ` + `${sanitizeTerminalText(approval.name)}` + (identity.length > 0 ? ` · ${identity.join(" · ")}` : "");
478
+ const omissionNotice = payload.omitted > 0 ? `
479
+ [${payload.omitted} characters omitted; press v to view the complete payload]` : "";
480
+ const scope = [];
481
+ if (EXACT_REVIEW_TOOLS.has(approval.name)) {
482
+ try {
483
+ const args = JSON.parse(approval.arguments);
484
+ if (Array.isArray(args.changes))
485
+ for (const change of args.changes) {
486
+ if (typeof change?.path === "string")
487
+ scope.push(`${change.expectedDigest === null ? "ADD" : "MODIFY"} ${change.path}`);
488
+ }
489
+ if (approval.name === "quarantine_file" && typeof args.path === "string")
490
+ scope.push(`REMOVE (recoverable quarantine) ${args.path}`);
491
+ if (approval.name === "move_file")
492
+ scope.push(`MOVE ${args.source} -> ${args.destination}`);
493
+ if (approval.name.includes("verify_and_apply"))
494
+ scope.push("Verification: pending; approval authorizes the checks and conditional application, not a successful result.");
495
+ } catch {}
496
+ }
497
+ if (detail === "summary" && approval.kind === "local-tool" && approval.name === "run_check") {
498
+ try {
499
+ const args = JSON.parse(approval.arguments);
500
+ if (typeof args.check === "string" && typeof args.expectedScript === "string" && Object.keys(args).every((key) => ["check", "expectedScript"].includes(key))) {
501
+ return `Run check: ${sanitizeTerminalText(args.check)}${identity.length ? ` · ${identity.join(" · ")}` : ""}
502
+
503
+ ${sanitizeTerminalText(args.expectedScript)}
504
+ `;
505
+ }
506
+ } catch {}
507
+ }
508
+ return `${header}
509
+ ${scope.map(sanitizeTerminalText).map((line) => `${line}
510
+ `).join("")}${payload.text}${omissionNotice}`;
511
+ };
512
+ var promptEnded = (error) => {
513
+ if (!error || typeof error !== "object")
514
+ return false;
515
+ const candidate = error;
516
+ return candidate.name === "AbortError" || candidate.code === "ABORT_ERR" || candidate.code === "ERR_USE_AFTER_CLOSE";
517
+ };
518
+ var normalizedDecision = (answer) => answer.trim().toLowerCase();
519
+ var STALE_DIFF = "File diff unavailable: preconditions";
520
+ var OVERSIZED_DIFF = "File diff unavailable: exceeds terminal preview limit";
521
+ var FILE_EDIT_TOOLS = new Set([
522
+ "apply_patch",
523
+ "apply_reviewed_edits",
524
+ "apply_reviewed_replacement",
525
+ "verify_and_apply_reviewed_edits",
526
+ "apply_environment_patch",
527
+ "verify_and_apply_environment_patch"
528
+ ]);
529
+ var approvalFiles = (approval) => {
530
+ try {
531
+ const args = JSON.parse(approval.arguments);
532
+ if (Array.isArray(args.changes)) {
533
+ return args.changes.flatMap((change) => {
534
+ if (!change || typeof change !== "object")
535
+ return [];
536
+ const record = change;
537
+ if (typeof record.path !== "string")
538
+ return [];
539
+ const op = record.expectedDigest === null ? "add" : record.content === null ? "delete" : "modify";
540
+ return [{ path: record.path, op }];
541
+ });
542
+ }
543
+ if (FILE_EDIT_TOOLS.has(approval.name) && typeof args.path === "string" && args.path) {
544
+ return [{ path: args.path, op: "modify" }];
545
+ }
546
+ return [];
547
+ } catch {
548
+ return [];
549
+ }
550
+ };
551
+ var diffStats = (diff) => ({
552
+ added: diff.split(`
553
+ `).filter((line) => line.startsWith("+") && !line.startsWith("+++")).length,
554
+ removed: diff.split(`
555
+ `).filter((line) => line.startsWith("-") && !line.startsWith("---")).length
556
+ });
557
+ var fileSummary = (approval, diffBody) => {
558
+ const files = approvalFiles(approval);
559
+ if (!files.length)
560
+ return { files, text: "" };
561
+ const chunks = diffBody.split(/\n(?=--- )/);
562
+ const lines = files.map((file, index) => {
563
+ const stats = diffStats(chunks[index] ?? diffBody);
564
+ return `${sanitizeTerminalText(file.path)} ${file.op} +${stats.added} −${stats.removed}`;
565
+ });
566
+ return { files, text: `${lines.join(`
567
+ `)}
568
+ ` };
569
+ };
570
+ var resolveTerminalApprovals = async (approvals, options) => {
571
+ if (options.requireCompleteReview && approvals.reduce((bytes, approval) => bytes + Buffer.byteLength(approval.arguments), 0) > 256 * 1024) {
572
+ options.write(`Explicit review exceeds the complete payload limit; approvals remain pending.
573
+ `);
574
+ return;
575
+ }
576
+ const responses = [];
577
+ const pendingAudit = [];
578
+ const staged = new Set(options.sessionGrants);
579
+ for (let index = 0;index < approvals.length; index += 1) {
580
+ const approval = approvals[index];
581
+ const grant = !options.requireCompleteReview && options.sessionGrants && options.workspace ? checkApprovalGrant(approval, options.workspace) : undefined;
582
+ if (grant && staged.has(grant)) {
583
+ options.onDecisionOrigin?.("automatic");
584
+ responses.push({ provider: approval.provider, approvalRequestId: approval.id, approve: true, reason: "Exact check approved for this CLI session." });
585
+ continue;
586
+ }
587
+ const policy = options.requireCompleteReview ? undefined : options.autoApprove?.();
588
+ if (policy && policy.mode !== "manual") {
589
+ const facts = approvalFacts(approval.name, approval.arguments);
590
+ const classified = classifyApproval(facts, policy);
591
+ if (classified.decision === "auto") {
592
+ const reads = new Map;
593
+ if (options.readText) {
594
+ for (const file of facts.paths)
595
+ reads.set(file.path, await options.readText(file.path));
596
+ }
597
+ const snapshots = buildSnapshots(approval.arguments, (relative) => reads.get(relative) ?? { text: null, undoable: false });
598
+ responses.push({
599
+ provider: approval.provider,
600
+ approvalRequestId: approval.id,
601
+ approve: true,
602
+ reason: `Auto-approved (${policy.mode}): ${classified.reason}.`
603
+ });
604
+ options.onDecisionOrigin?.("automatic");
605
+ pendingAudit.push({ approval, reason: classified.reason, mode: policy.mode, snapshots });
606
+ continue;
607
+ }
608
+ }
609
+ let diff = await options.fileDiff?.(approval);
610
+ let compactDiff = diff;
611
+ let full = false;
612
+ if (!options.review)
613
+ options.write(`
614
+ Approval required ${index + 1}/${approvals.length}:
615
+ ` + `${formatApproval(approval, {
616
+ detail: options.requireCompleteReview ? "full" : "summary",
617
+ ...options.maxSummaryCharacters !== undefined ? { maxSummaryCharacters: options.maxSummaryCharacters } : {}
618
+ })}
619
+ `);
620
+ if (diff && !options.review)
621
+ options.write(`
622
+ ${diff}
623
+ `);
624
+ if (options.workspace && !options.review)
625
+ options.write(`Workspace: ${sanitizeTerminalText(options.workspace)}
626
+ `);
627
+ let technical = false;
628
+ for (;; ) {
629
+ let answer;
630
+ try {
631
+ const stale = Boolean(diff?.startsWith(STALE_DIFF));
632
+ const files = approvalFiles(approval);
633
+ const commandReview = approval.name === "run_check" || approval.name === "run_environment_command" || approval.name === "run_environment_shell";
634
+ const approveLabel = commandReview ? "Approve this command" : "Approve this change";
635
+ const rejectDetail = commandReview ? "This command does not run." : "This change is not applied.";
636
+ const approveDetail = commandReview ? "Run only this command, once." : "Apply only the change shown above, once.";
637
+ const items = [
638
+ { value: "n", key: "r", label: "Reject", detail: rejectDetail },
639
+ ...!stale ? [{ value: "y", key: "a", label: approveLabel, detail: approveDetail }] : [],
640
+ ...grant ? [{ value: "s", key: "s", label: "Allow this exact check for this session", detail: "Changing the script requires approval again." }] : [],
641
+ { value: "full", key: "f", label: full ? "Show compact diff" : "Show full diff", detail: full ? "Return to the changed lines." : "Show unchanged lines around this change." },
642
+ { value: "v", key: "d", label: technical ? "Back to review" : "View payload", detail: "Show the exact request the engine will check." },
643
+ ...stale ? [{ value: "l", key: "l", label: "Reload review" }] : [],
644
+ { value: "q", key: "Esc", label: "Decide later", detail: "Leave it pending. Nothing is applied. /pending opens this review again." }
645
+ ];
646
+ const trustedDiff = approval.kind === "local-tool" && diff?.startsWith("Reviewed file diff · ");
647
+ const diffBody = diff?.replace(/^Reviewed file diff · [^\n]+\n/, "") ?? "";
648
+ const summary = fileSummary(approval, diffBody);
649
+ const checkSummary = approval.kind === "local-tool" && approval.name === "run_check" ? formatApproval(approval, { detail: "summary" }) : undefined;
650
+ const conditional = approval.name.startsWith("verify_and_apply_");
651
+ const restored = options.restored && !technical ? `● Restored: this conversation was waiting for your decision.
652
+ ` : "";
653
+ const staleBody = `▲ This review is out of date
654
+ A file may have been edited after the change was proposed.
655
+ A file may have been moved, deleted, or can't be read.
656
+ The proposed change may not be valid for this workspace.
657
+ Nothing has been applied.
658
+ `;
659
+ const primary = stale ? staleBody : diff?.startsWith(OVERSIZED_DIFF) ? `This change is too large to preview here.
660
+ ${formatApproval(approval, { detail: "full" })}
661
+ ` : trustedDiff ? `${conditional ? `Checks pending · conditional apply
662
+ ` : ""}${summary.text}${diffBody}
663
+ ` + (conditional ? formatApproval(approval, { detail: "full" }) : "") : checkSummary?.startsWith("Run check: ") ? checkSummary : `${formatApproval(approval, { detail: "full" })}${diff ? `
664
+ ${diff}` : ""}`;
665
+ const body = technical ? `${formatApproval(approval, { detail: "full" })}${diff ? `
666
+ ${diff}` : ""}${options.workspace ? `
667
+ Workspace: ${sanitizeTerminalText(options.workspace)}` : ""}` : `${restored}${primary}`;
668
+ const position = approvals.length > 1 ? ` · ${index + 1} of ${approvals.length}` : "";
669
+ const summaryText = changeSummary(approval, diffBody);
670
+ const received = options.review ? await options.review({
671
+ title: `Waiting for your decision${position}${technical ? " · details" : ""}`,
672
+ summary: summaryText,
673
+ ...summary.text ? { fileList: summary.text.trim() } : {},
674
+ body,
675
+ ...!technical && trustedDiff ? {
676
+ layout: (width) => renderReviewedDiff(diffBody, width),
677
+ ...restored ? { banner: restored.trimEnd() } : {}
678
+ } : {},
679
+ ...options.projectLabel ? { headerRight: options.projectLabel } : {},
680
+ files: files.length
681
+ }, items) : options.select ? await options.select("Waiting for your decision", items) : await options.ask(`Approve? [y]es/${grant ? "[s]ession/" : ""}[n]o/[v]iew/[q]uit (default: no) `);
682
+ if (typeof received !== "string")
683
+ return;
684
+ answer = normalizedDecision(received);
685
+ } catch (error) {
686
+ if (promptEnded(error))
687
+ return;
688
+ throw error;
689
+ }
690
+ if (answer === "l" || answer === "reload") {
691
+ diff = await options.fileDiff?.(approval);
692
+ compactDiff = diff;
693
+ full = false;
694
+ continue;
695
+ }
696
+ if (answer === "full") {
697
+ full = !full;
698
+ if (full && options.fileDiffFull)
699
+ diff = await options.fileDiffFull(approval) ?? compactDiff;
700
+ else
701
+ diff = compactDiff;
702
+ continue;
703
+ }
704
+ if (answer === "v" || answer === "view" || answer === "d") {
705
+ if (options.review)
706
+ technical = !technical;
707
+ else
708
+ options.write(`
709
+ Complete approval payload:
710
+ ${formatApproval(approval, { detail: "full" })}
711
+ `);
712
+ continue;
713
+ }
714
+ if (answer === "q" || answer === "quit") {
715
+ return;
716
+ }
717
+ if (answer === "y" || answer === "yes" || answer === "s" && grant) {
718
+ if (answer === "s" && grant)
719
+ staged.add(grant);
720
+ options.onDecisionOrigin?.("interactive");
721
+ responses.push({
722
+ provider: approval.provider,
723
+ approvalRequestId: approval.id,
724
+ approve: true,
725
+ reason: options.approvedReason ?? "Approved interactively."
726
+ });
727
+ break;
728
+ }
729
+ if (answer === "" || answer === "n" || answer === "no") {
730
+ options.onDecisionOrigin?.("interactive");
731
+ responses.push({
732
+ provider: approval.provider,
733
+ approvalRequestId: approval.id,
734
+ approve: false,
735
+ reason: options.deniedReason ?? "Denied by the operator."
736
+ });
737
+ break;
738
+ }
739
+ options.write(`Choose y, n, v, or q.
740
+ `);
741
+ }
742
+ }
743
+ for (const key of staged)
744
+ options.sessionGrants?.add(key);
745
+ if (options.auditRoot) {
746
+ for (const item of pendingAudit) {
747
+ await appendAutoApproval(options.auditRoot, createAutoApprovalEntry({
748
+ approvalId: item.approval.id,
749
+ name: item.approval.name,
750
+ mode: item.mode,
751
+ reason: item.reason,
752
+ snapshots: item.snapshots
753
+ }));
754
+ }
755
+ }
756
+ return responses;
757
+ };
758
+ var terminalSupportsColor = (isTTY, env = process.env) => isTTY && !Object.prototype.hasOwnProperty.call(env, "NO_COLOR") && env.TERM !== "dumb" && env.FORCE_COLOR !== "0";
759
+ var verificationReceipt = (name, output) => {
760
+ if (!output || typeof output !== "object")
761
+ return;
762
+ const value = output;
763
+ const receipt = name === "run_check" || name === "run_environment_command" ? value : name.startsWith("verify_and_apply_") && value.verification && typeof value.verification === "object" ? value.verification : undefined;
764
+ if (!receipt || !Number.isSafeInteger(receipt.exitCode))
765
+ return;
766
+ const command = receipt.command;
767
+ const prefix = Array.isArray(command) ? JSON.stringify(command.slice(0, -1)) : "";
768
+ const supported = [
769
+ '["bun","--no-env-file","run"]',
770
+ '["npm","--ignore-scripts","run"]',
771
+ '["pnpm","--ignore-scripts","run"]',
772
+ '["yarn","run"]'
773
+ ];
774
+ const last = Array.isArray(command) ? command.at(-1) : undefined;
775
+ const check = name === "run_check" && supported.includes(prefix) && typeof last === "string" && /^[A-Za-z0-9:_-]{1,100}$/.test(last) ? last : undefined;
776
+ return { exitCode: receipt.exitCode, timedOut: receipt.timedOut === true, check };
777
+ };
778
+ var verificationReceipts = (results) => results.flatMap((result) => {
779
+ const receipt = verificationReceipt(result.toolName, result.output);
780
+ return receipt ? [{ ...receipt, failed: Boolean(result.isError) || receipt.timedOut || receipt.exitCode !== 0 }] : [];
781
+ });
782
+ var verificationCounts = (results) => {
783
+ const receipts = verificationReceipts(results);
784
+ const failed = receipts.filter((receipt) => receipt.failed).length;
785
+ return { total: receipts.length, passed: receipts.length - failed, failed };
786
+ };
787
+ var formatVerificationSummary = (results) => {
788
+ const counts = verificationCounts(results);
789
+ if (!counts.total)
790
+ return "Verification: no check receipts recorded; completion does not certify checks.";
791
+ return `Verification receipts: ${counts.passed} passed, ${counts.failed} failed/timed out. Only recorded commands are covered.`;
792
+ };
793
+ var activityTones = { 31: "removed", 32: "added", 33: "pending", 36: "info", 90: "muted" };
794
+ var paint = (text, code, color) => paintTerminal(text, activityTones[code] ?? "muted", color);
795
+ var terminalRunFailure = (error) => {
796
+ const message = error instanceof Error ? error.message : error && typeof error === "object" && ("message" in error) && typeof error.message === "string" ? error.message : "";
797
+ const provider = /^(Meta|Qwen|OpenAI|Gemini) request failed with status ([45]\d{2})(?: \((previous response unavailable|context length exceeded|tools rejected|input rejected|output token limit rejected|previous response rejected|reason unavailable)\))?\.$/.exec(message);
798
+ if (provider)
799
+ return `${provider[1]} request failed · HTTP ${provider[2]}${provider[3] ? ` · ${provider[3]}` : ""}`;
800
+ const budget = /^Agent budget exceeded including child runs: (maxInputTokens|maxOutputTokens|maxTotalTokens|maxToolCalls|maxToolErrors|maxSteps) limit (\d+), actual (\d+)\.$/.exec(message);
801
+ if (budget)
802
+ return `budget exceeded · ${budget[1]} · ${budget[3]} / ${budget[2]}`;
803
+ const denied = /^Tool "(read_file|read_files|list_files|search_files|search_many)" failed: The path is protected by the harness policy: (node_modules|\.git|\.zhivex-harness|dist|coverage|\.next|\.turbo)$/.exec(message);
804
+ if (denied)
805
+ return `read denied · protected path ${denied[2]}`;
806
+ if (message === "Agent compaction result still exceeds maxEstimatedInputTokens." || message === "Agent compaction cannot satisfy its limits without removing protected messages.") {
807
+ return "context could not fit after compaction · retained messages exceed the input limit";
808
+ }
809
+ const streamOverflow = /^Stream replay buffer exceeded its limit of (\d+) events\.$/.exec(message);
810
+ if (streamOverflow)
811
+ return `event replay limit reached · ${streamOverflow[1]} events`;
812
+ const stateOverflow = /^Agent run state is (\d+) bytes and exceeds maxStateBytes=(\d+)\. Offload large tool outputs to artifacts or raise the explicit limit\.$/.exec(message);
813
+ if (stateOverflow)
814
+ return `durable state limit reached · ${stateOverflow[1]} / ${stateOverflow[2]} bytes · inspect /status before /continue`;
815
+ if (/^Tool is not registered \(sha256:[a-f0-9]{64}\)\.$/.test(message)) {
816
+ return "requested tool is not registered · use an available tool with its exact name";
817
+ }
818
+ const cap = /^(maxInputTokens|maxOutputTokens|maxTotalTokens) budget (exceeded|exhausted)$/.exec(message);
819
+ if (cap)
820
+ return `budget ${cap[2]} · ${cap[1]}`;
821
+ if (message === "Agent exhausted maxSteps before reaching a terminal response.") {
822
+ return "step limit reached before a final response";
823
+ }
824
+ return "run failed · cause unavailable (inspect run diagnostics)";
825
+ };
826
+ var formatTerminalEvent = (event, options = {}) => {
827
+ const color = options.color ?? false;
828
+ switch (event.type) {
829
+ case "text-delta":
830
+ return;
831
+ case "tool-call":
832
+ return `${paint("↳", 36, color)} tool · ${sanitizeTerminalText(event.toolCall.name)}`;
833
+ case "tool-result": {
834
+ const receipt = verificationReceipt(event.toolResult.toolName, event.toolResult.output);
835
+ if (receipt) {
836
+ const failed = event.toolResult.isError || receipt.timedOut || receipt.exitCode !== 0;
837
+ return `${paint(failed ? "✗" : "✓", failed ? 31 : 32, color)} check · ${receipt.check ?? sanitizeTerminalText(event.toolResult.toolName)} · exit ${receipt.exitCode}${receipt.timedOut ? " · timed out" : ""}`;
838
+ }
839
+ return event.toolResult.isError ? `${paint("✗", 31, color)} tool · ${sanitizeTerminalText(event.toolResult.toolName)} · error` : `${paint("✓", 32, color)} tool · ${sanitizeTerminalText(event.toolResult.toolName)}`;
840
+ }
841
+ case "tool-approval-request":
842
+ case "agent-approval-request":
843
+ return `${paint("!", 33, color)} approval · ` + `${sanitizeTerminalText(event.approval.kind ?? "provider")} · ` + sanitizeTerminalText(event.approval.name);
844
+ case "agent-approval-resolved":
845
+ return event.approval.approve ? `${paint("✓", 32, color)} approval · approved` : `${paint("✗", 31, color)} approval · denied`;
846
+ case "provider-data":
847
+ return `${paint("·", 90, color)} provider · ${sanitizeTerminalText(event.provider)}`;
848
+ case "image-generation":
849
+ return `${paint("·", 36, color)} image · ${sanitizeTerminalText(event.provider)}` + (event.partial ? " · partial" : " · complete");
850
+ case "finish":
851
+ return `${paint("·", 90, color)} model stream` + (event.finishReason ? ` · ${sanitizeTerminalText(event.finishReason)}` : " · finished");
852
+ case "error":
853
+ return `${paint("✗", 31, color)} ${terminalRunFailure(event.error)}`;
854
+ case "agent-run-start":
855
+ return `${paint("●", 36, color)} run · step ${event.currentStep}/${event.maxSteps}`;
856
+ case "agent-step-start":
857
+ return `${paint("●", 36, color)} step ${event.stepIndex + 1}`;
858
+ case "agent-step-finish":
859
+ return `${paint(event.step.status === "failed" ? "✗" : "✓", event.step.status === "failed" ? 31 : 32, color)} ` + `step ${event.step.index + 1} · ${sanitizeTerminalText(event.step.status)} · ` + `${event.step.toolResults.length} tool${event.step.toolResults.length === 1 ? "" : "s"}`;
860
+ case "agent-compaction":
861
+ return `${paint("↺", 36, color)} context · ${event.compaction.messageCountBefore} → ` + `${event.compaction.messageCountAfter} messages`;
862
+ case "agent-run-finish":
863
+ if (event.status === "failed") {
864
+ const cause = terminalRunFailure(event.state.error);
865
+ return `${paint("✗", 31, color)} ${cause}` + (cause === "step limit reached before a final response" ? ` (${event.state.currentStep}/${event.state.maxSteps}). Session retained; use /limits to adjust the next turn, then ask to continue.` : "");
866
+ }
867
+ return `${paint(event.status === "completed" ? "✓" : "●", event.status === "completed" ? 32 : 33, color)} ` + `run · ${sanitizeTerminalText(event.status)} · ` + `${sanitizeTerminalText(event.state.provider)}/${sanitizeTerminalText(event.state.modelId)}`;
868
+ }
869
+ };
870
+ var formatTerminalHeader = (input, options = {}) => {
871
+ const color = options.color ?? false;
872
+ const title = input.sessionTitle ? ` · ${sanitizeTerminalText(input.sessionTitle)}` : "";
873
+ return `${paint(`Zhivex Harness ${sanitizeTerminalText(input.version)}`, 36, color)} · ` + `${sanitizeTerminalText(input.provider)}/${sanitizeTerminalText(input.model)}
874
+ ` + `session ${sanitizeTerminalText(input.sessionId)}${title}`;
875
+ };
876
+
877
+ export { terminalToneCode, paintTerminal, terminalThemeCommand, terminalCellWidth, tableCells, isTableSeparator, renderTerminalTable, DEFAULT_APPROVAL_SUMMARY_CHARACTERS, sanitizeTerminalText, formatApproval, resolveTerminalApprovals, terminalSupportsColor, verificationCounts, formatVerificationSummary, terminalRunFailure, formatTerminalEvent, formatTerminalHeader };