@zhivex-ai/harness 1.6.3 → 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 (391) hide show
  1. package/CHANGELOG.md +16 -3
  2. package/README.md +17 -5
  3. package/SECURITY.md +1 -1
  4. package/SUPPORT.md +2 -2
  5. package/benchmarks/README.md +98 -0
  6. package/contracts/engine-api.json +1587 -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/arguments-75r85mvc.js +27 -0
  89. package/dist/arguments-x24bbqvd.js +22 -0
  90. package/dist/audit/index.js +16 -472
  91. package/dist/audit-pack-1gnych0m.js +93 -0
  92. package/dist/{audit-pack-s9n693by.js → audit-pack-h44kjkbj.js} +17 -11
  93. package/dist/calendar-2xw0rr7b.js +49 -0
  94. package/dist/cli/application-cli.d.ts +2 -0
  95. package/dist/cli/arguments.d.ts +14 -1
  96. package/dist/cli/auto-approve-setup.d.ts +13 -0
  97. package/dist/cli/configured-harness.d.ts +1 -2
  98. package/dist/cli/console/console-budget.d.ts +16 -2
  99. package/dist/cli/console/console-checkpoints.d.ts +12 -0
  100. package/dist/cli/console/console-commands.d.ts +3 -3
  101. package/dist/cli/console/console-compaction.d.ts +1 -1
  102. package/dist/cli/console/console-diff.d.ts +2 -0
  103. package/dist/cli/console/console-input.d.ts +29 -1
  104. package/dist/cli/console/console-navigation.d.ts +2 -2
  105. package/dist/cli/console/console-outcome.d.ts +10 -0
  106. package/dist/cli/console/console-presentation.d.ts +17 -2
  107. package/dist/cli/console/console-pricing.d.ts +14 -0
  108. package/dist/cli/console/console-reasoning.d.ts +1 -1
  109. package/dist/cli/console/console-recovery.d.ts +2 -0
  110. package/dist/cli/console/console-review.d.ts +34 -0
  111. package/dist/cli/console/console-run-policy.d.ts +5 -0
  112. package/dist/cli/console/console-run-view.d.ts +28 -0
  113. package/dist/cli/console/console-task.d.ts +30 -0
  114. package/dist/cli/console/console-welcome.d.ts +13 -3
  115. package/dist/cli/console/review-diff.d.ts +20 -0
  116. package/dist/cli/presentation.d.ts +8 -6
  117. package/dist/cli/service-checkpoints.d.ts +234 -0
  118. package/dist/cli/terminal/activity-history.d.ts +4 -2
  119. package/dist/cli/terminal/activity-stream.d.ts +33 -0
  120. package/dist/cli/terminal/file-diff.d.ts +11 -0
  121. package/dist/cli/terminal/terminal-theme.d.ts +9 -0
  122. package/dist/cli/terminal/terminal-ui.d.ts +44 -2
  123. package/dist/cli/terminal/tool-activity.d.ts +6 -2
  124. package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
  125. package/dist/{cli-entry-1epvek01.js → cli-entry-86rcbmwh.js} +294 -14
  126. package/dist/cli-entry-btkpb4h1.js +3627 -0
  127. package/dist/cli-entry-bxjbs6qq.js +200 -0
  128. package/dist/cli-entry-cpm89r9q.js +624 -0
  129. package/dist/{cli-entry-mbcq96nx.js → cli-entry-dksm56sj.js} +39 -293
  130. package/dist/{cli-entry-rsx0wpvs.js → cli-entry-eka68ttb.js} +4087 -4625
  131. package/dist/cli-entry-h7dcah4p.js +137 -0
  132. package/dist/cli-entry-kwk23ktq.js +33 -0
  133. package/dist/{cli-entry-nyzyvf24.js → cli-entry-vmce694z.js} +1286 -3142
  134. package/dist/cli-entry-wanv05db.js +1113 -0
  135. package/dist/{cli-yxvq8qf1.js → cli-z7vhm1rk.js} +1767 -380
  136. package/dist/cli.js +8 -6
  137. package/dist/client/json-contracts.d.ts +153 -0
  138. package/dist/client/local-service.d.ts +7 -12
  139. package/dist/client/local-transport.d.ts +14 -0
  140. package/dist/client/protocol.d.ts +43 -1
  141. package/dist/compat/cli-options.d.ts +7 -1
  142. package/dist/compat/cli.d.ts +2 -0
  143. package/dist/compat/cli.js +4043 -0
  144. package/dist/compat/code-support.d.ts +4 -0
  145. package/dist/compat/code-support.js +50 -28
  146. package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
  147. package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
  148. package/dist/context/adaptive-compaction.d.ts +1 -0
  149. package/dist/context/lossless-lines.d.ts +13 -0
  150. package/dist/context/numbered-read-lines.d.ts +15 -0
  151. package/dist/context/read-attempts.d.ts +21 -0
  152. package/dist/context/request-projection.d.ts +32 -4
  153. package/dist/context/scoped-context.d.ts +31 -5
  154. package/dist/context/working-read-replay.d.ts +12 -0
  155. package/dist/coordinator-client-nzysqxf0.js +10 -0
  156. package/dist/engine/acp.js +27 -21
  157. package/dist/engine/application-client.d.ts +11 -0
  158. package/dist/engine/application-client.js +18 -0
  159. package/dist/engine/application-protocol.d.ts +5 -0
  160. package/dist/engine/application-protocol.js +7 -0
  161. package/dist/engine/application.d.ts +43 -0
  162. package/dist/engine/application.js +206 -0
  163. package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
  164. package/dist/engine/assistant/automation/scheduler.js +11 -0
  165. package/dist/engine/assistant/automation/summary.d.ts +3 -0
  166. package/dist/engine/assistant/automation/summary.js +8 -0
  167. package/dist/engine/assistant/automation/time.d.ts +5 -0
  168. package/dist/engine/assistant/automation/time.js +15 -0
  169. package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
  170. package/dist/engine/assistant/calendar/calendar.js +12 -0
  171. package/dist/engine/assistant/calendar/connection.d.ts +2 -0
  172. package/dist/engine/assistant/calendar/connection.js +11 -0
  173. package/dist/engine/assistant/calendar/environment.d.ts +1 -0
  174. package/dist/engine/assistant/calendar/environment.js +7 -0
  175. package/dist/engine/assistant/calendar/http.d.ts +3 -0
  176. package/dist/engine/assistant/calendar/http.js +9 -0
  177. package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
  178. package/dist/engine/assistant/calendar/oauth.js +12 -0
  179. package/dist/engine/assistant/calendar/store.d.ts +2 -0
  180. package/dist/engine/assistant/calendar/store.js +8 -0
  181. package/dist/engine/assistant/calendar/tools.d.ts +2 -0
  182. package/dist/engine/assistant/calendar/tools.js +46 -0
  183. package/dist/engine/assistant/client.d.ts +2 -0
  184. package/dist/engine/assistant/client.js +33 -0
  185. package/dist/engine/assistant/config.d.ts +1 -0
  186. package/dist/engine/assistant/config.js +102 -0
  187. package/dist/engine/assistant/contracts.d.ts +10 -0
  188. package/dist/engine/assistant/contracts.js +78 -0
  189. package/dist/engine/assistant/daily/service.d.ts +12 -0
  190. package/dist/engine/assistant/daily/service.js +27 -0
  191. package/dist/engine/assistant/doctor.d.ts +1 -0
  192. package/dist/engine/assistant/doctor.js +116 -0
  193. package/dist/engine/assistant/evaluation.d.ts +2 -0
  194. package/dist/engine/assistant/evaluation.js +76 -0
  195. package/dist/engine/assistant/host.d.ts +2 -0
  196. package/dist/engine/assistant/host.js +63 -0
  197. package/dist/engine/assistant/integrations/google.d.ts +9 -0
  198. package/dist/engine/assistant/integrations/google.js +30 -0
  199. package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
  200. package/dist/engine/assistant/integrations/public-web.js +11 -0
  201. package/dist/engine/assistant/managed/secrets.d.ts +1 -0
  202. package/dist/engine/assistant/managed/secrets.js +0 -0
  203. package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
  204. package/dist/engine/assistant/managed/setup-state.js +84 -0
  205. package/dist/engine/assistant/managed/setup.d.ts +3 -0
  206. package/dist/engine/assistant/managed/setup.js +85 -0
  207. package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
  208. package/dist/engine/assistant/microsoft/connection.js +21 -0
  209. package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
  210. package/dist/engine/assistant/microsoft/tools.js +30 -0
  211. package/dist/engine/assistant/modules/calendar.d.ts +1 -0
  212. package/dist/engine/assistant/modules/calendar.js +49 -0
  213. package/dist/engine/assistant/modules/catalog.d.ts +3 -0
  214. package/dist/engine/assistant/modules/catalog.js +67 -0
  215. package/dist/engine/assistant/modules/daily.d.ts +1 -0
  216. package/dist/engine/assistant/modules/daily.js +48 -0
  217. package/dist/engine/assistant/modules/github.d.ts +1 -0
  218. package/dist/engine/assistant/modules/github.js +43 -0
  219. package/dist/engine/assistant/modules/google.d.ts +1 -0
  220. package/dist/engine/assistant/modules/google.js +53 -0
  221. package/dist/engine/assistant/modules/mcp.d.ts +1 -0
  222. package/dist/engine/assistant/modules/mcp.js +42 -0
  223. package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
  224. package/dist/engine/assistant/modules/microsoft.js +53 -0
  225. package/dist/engine/assistant/modules/module.d.ts +5 -0
  226. package/dist/engine/assistant/modules/module.js +42 -0
  227. package/dist/engine/assistant/modules/tools.d.ts +2 -0
  228. package/dist/engine/assistant/modules/tools.js +42 -0
  229. package/dist/engine/assistant/modules/web.d.ts +1 -0
  230. package/dist/engine/assistant/modules/web.js +45 -0
  231. package/dist/engine/assistant/private-directory.d.ts +1 -0
  232. package/dist/engine/assistant/private-directory.js +7 -0
  233. package/dist/engine/assistant/proactive/service.d.ts +6 -0
  234. package/dist/engine/assistant/proactive/service.js +16 -0
  235. package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
  236. package/dist/engine/assistant/providers/openai-compatible.js +12 -0
  237. package/dist/engine/assistant/providers/provider.d.ts +7 -0
  238. package/dist/engine/assistant/providers/provider.js +54 -0
  239. package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
  240. package/dist/engine/assistant/providers/web-citations.js +7 -0
  241. package/dist/engine/assistant/runtime.d.ts +2 -0
  242. package/dist/engine/assistant/runtime.js +73 -0
  243. package/dist/engine/assistant/task-metrics.d.ts +8 -0
  244. package/dist/engine/assistant/task-metrics.js +17 -0
  245. package/dist/engine/assistant/telegram/api.d.ts +5 -0
  246. package/dist/engine/assistant/telegram/api.js +11 -0
  247. package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
  248. package/dist/engine/assistant/telegram/bridge.js +40 -0
  249. package/dist/engine/assistant/telegram/store.d.ts +2 -0
  250. package/dist/engine/assistant/telegram/store.js +8 -0
  251. package/dist/engine/client.js +26 -18
  252. package/dist/engine/desktop-providers-v1.js +4 -4
  253. package/dist/engine/desktop-state-v1.js +16 -13
  254. package/dist/engine/index.d.ts +4 -0
  255. package/dist/engine/index.js +117 -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 +2329 -1096
  261. package/dist/index-09rsdr2d.js +1744 -0
  262. package/dist/index-0csc5sc7.js +139 -0
  263. package/dist/{index-4mn6m3bq.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-rgqzdgv6.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-fqqz1yt8.js → index-6ehtssyz.js} +369 -335
  280. package/dist/index-76kpdbpw.js +80 -0
  281. package/dist/{index-5nmm0642.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-hhrnrqfc.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-j466sekf.js → index-mkt5yrax.js} +31 -105
  316. package/dist/{index-nxmk6re7.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-vn91b9z1.js → index-sx1t6dnd.js} +3721 -2382
  329. package/dist/index-tar0ngkm.js +359 -0
  330. package/dist/index-tn58cr6w.js +471 -0
  331. package/dist/{index-w0m1nckc.js → index-v79s9bf9.js} +118 -45
  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-amjttjaj.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/agent-profile.d.ts +12 -0
  351. package/dist/runtime/harness.d.ts +13 -0
  352. package/dist/runtime/known-file-preload.d.ts +35 -0
  353. package/dist/service-cli.js +130 -40
  354. package/dist/service-client-cli-2rzxy5mj.js +1166 -0
  355. package/dist/service-client-cli-5ne8q5ej.js +543 -0
  356. package/dist/tools/ooxml-zip.d.ts +21 -0
  357. package/dist/tools/presentations.d.ts +47 -0
  358. package/dist/tools/tabular-data.d.ts +114 -0
  359. package/dist/tools/workspace.d.ts +76 -0
  360. package/dist/verify-historical-migrations.js +2249 -1016
  361. package/dist/workspace/workspace.d.ts +13 -1
  362. package/dist/zhx.js +8 -6
  363. package/docs/APPLICATION_MIGRATION.md +32 -0
  364. package/docs/CLI.md +166 -2
  365. package/docs/CODE_RELEASE.md +11 -5
  366. package/docs/CODE_WEB_TASKS.md +3 -114
  367. package/docs/CONTEXT_ENGINEERING.md +93 -0
  368. package/docs/ENGINE_API.md +9 -2
  369. package/docs/EXTENSIBILITY.md +1 -1
  370. package/docs/FIRST_USE.md +6 -6
  371. package/docs/INTERNAL_ARCHIVE.md +43 -0
  372. package/docs/LOCAL_SERVICE.md +1 -1
  373. package/docs/MODEL_CATALOG.md +14 -0
  374. package/docs/PROJECT_MEMORY.md +1 -1
  375. package/docs/README.md +23 -4
  376. package/evaluations/representative-assembly-matrix.json +19 -1
  377. package/examples/README.md +4 -4
  378. package/examples/assistant/compatible-calendar.json +17 -0
  379. package/examples/assistant/composed-modules.json +23 -0
  380. package/examples/assistant/connected-tools.json +9 -0
  381. package/examples/assistant/daily-tools.json +6 -0
  382. package/examples/assistant/offline.mjs +24 -0
  383. package/fixtures/cli-compatibility/README.md +10 -0
  384. package/fixtures/cli-compatibility/inventory.json +7858 -0
  385. package/package.json +232 -26
  386. package/dist/cli/console/console-model-catalog.d.ts +0 -8
  387. package/dist/index-2yyfg69h.js +0 -619
  388. package/dist/index-3wwfn5n6.js +0 -270
  389. package/dist/index-4gt045j0.js +0 -288
  390. package/dist/index-4jw3tvy8.js +0 -301
  391. package/dist/service-client-cli-xbj7j5kj.js +0 -1251
@@ -0,0 +1,1225 @@
1
+ import {
2
+ CLI_COMMAND_OPTION_CONTRACTS,
3
+ CLI_OPTION_DEFINITIONS,
4
+ parseHarnessModelRoute,
5
+ validateCliCommandOptions
6
+ } from "./index-ay26xfxt.js";
7
+ import {
8
+ HARNESS_REQUIRED_CAPABILITIES,
9
+ HARNESS_SUBAGENT_PROFILES,
10
+ PROVIDERS,
11
+ parseProvider,
12
+ providerAvailability,
13
+ reasoningEffortSchema
14
+ } from "./index-fwf274vc.js";
15
+ import {
16
+ FileChangedWhileReadingError,
17
+ FileSizeLimitError,
18
+ UnsafeFileTypeError,
19
+ readRegularFileNoFollow
20
+ } from "./index-h7dcah4p.js";
21
+ import {
22
+ HarnessConfigError,
23
+ HarnessError
24
+ } from "./index-xwb691v9.js";
25
+
26
+ // packages/core/src/cli/cli-help.ts
27
+ var usage = {
28
+ automations: "zhx automations status|apply - --yes [--application-directory <dir>] [--json] (apply reads reviewed {projectId, change: {action, expectedDigest, localTime?, timeZone?}} JSON; configure/resume enable future Telegram delivery; no immediate send)",
29
+ personal: "zhx personal tasks [offset]|reminders|notes [offset]|search-notes <query> [offset]|note <id> [--application-directory <dir>] [--json] (reads the active Assistant)",
30
+ agents: "zhx agents list|create <name>|tools -|start|select <id>|rename <id> <name>|model <id> <model>|discard --yes|delete <id> --yes",
31
+ connections: "zhx connections list|configure -|use <id> (configure reads provider JSON from stdin)",
32
+ projects: "zhx projects list|context|open <Git root> <connectionId>|select <id>|connection <id> <connectionId>",
33
+ application: "zhx application <status|start|stop> [--application-directory <dir>] [--json] [--yes]",
34
+ "memory:remember": 'zhx memory remember "content" [--source "provenance"]',
35
+ "memory:suggest": 'zhx memory suggest "content" [--source "provenance"]',
36
+ "memory:list": "zhx memory list",
37
+ "memory:read": "zhx memory read <id>",
38
+ "memory:update": 'zhx memory update <id> <revision> "content" [--source "provenance"]',
39
+ "memory:forget": "zhx memory forget <id> <revision>",
40
+ "memory:accept": "zhx memory accept <id> <reviewedRevision>",
41
+ "memory:clear": "zhx memory clear",
42
+ "memory:enable": "zhx memory enable",
43
+ "memory:disable": "zhx memory disable",
44
+ "memory:context": 'zhx memory context "query"',
45
+ "checkpoints:storage": "zhx checkpoints storage",
46
+ "checkpoints:prune-review": "zhx checkpoints prune-review <checkpoint:id|restore:id> [...]",
47
+ "checkpoints:prune-apply": "zhx checkpoints prune-apply <reviewedPlanId> <checkpoint:id|restore:id> [...]",
48
+ "checkpoints:list": "zhx checkpoints list <sessionId>",
49
+ "checkpoints:capture": "zhx checkpoints capture <sessionId> <turnId> <path> [paths...]",
50
+ "checkpoints:inspect": "zhx checkpoints inspect <checkpointId> [--session <source sessionId> --area code|--service <file>]",
51
+ "checkpoints:prepare": "zhx checkpoints prepare <checkpointId> [--session <source sessionId> --area code|--service <file>]",
52
+ "checkpoints:review": "zhx checkpoints review <operationId> [--session <source sessionId> --area code|--service <file>]",
53
+ "checkpoints:apply": "zhx checkpoints apply <operationId> <reviewedProposalId> [--session <source sessionId> --area code|--service <file>]",
54
+ "checkpoints:recover": "zhx checkpoints recover <operationId> <existingForkSessionId> [--session <source sessionId> --area code|--service <file>]",
55
+ init: "zhx init [--provider <id>] [--model <id>] [--profile <name>] [--update]",
56
+ run: 'zhx run [options] "task" | zhx run [options] -',
57
+ review: 'zhx review [options] "review task" | zhx review [options] -',
58
+ chat: "zhx [--continue | --session <id>]",
59
+ providers: "zhx providers [--json]",
60
+ policy: "zhx policy [options] [--json]",
61
+ doctor: "zhx doctor [options]",
62
+ resume: "zhx resume <runId> --approve|--deny",
63
+ "runs:list": "zhx runs list [options]",
64
+ "runs:inspect": "zhx runs inspect <runId>",
65
+ "runs:cancel": "zhx runs cancel <runId> [options]",
66
+ "runs:cleanup": "zhx runs cleanup --before <date> [options]",
67
+ "runs:export": "zhx runs export <runId>",
68
+ "runs:report": "zhx runs report <runId> [envelope.json] [--session <sessionId>] [--json]",
69
+ "sessions:list": "zhx sessions list [--search <text>]",
70
+ "sessions:inspect": "zhx sessions inspect <sessionId>",
71
+ "sessions:rename": 'zhx sessions rename <sessionId> "title"',
72
+ "sessions:fork": "zhx sessions fork <sessionId>",
73
+ "sessions:archive": "zhx sessions archive <sessionId>",
74
+ "changes:create": "zhx changes create <input.json> --patch <artifact>",
75
+ "changes:verify": "zhx changes verify <envelope.json> --patch <artifact> [options]",
76
+ "state:status": "zhx state status",
77
+ "state:export": "zhx state export <backup.json>",
78
+ "state:import": "zhx state import <backup.json> [--apply]",
79
+ "export-audit": "zhx export-audit <task-id> --out <directory> [--session <sessionId>]",
80
+ "verify-audit": "zhx verify-audit --out <directory>",
81
+ version: "zhx --version"
82
+ };
83
+ var shortCliHelp = (version) => `Zhivex Harness v${version}
84
+
85
+ Start in your project:
86
+ zhx Open the conversation (first-use setup if needed)
87
+ zhx --continue Reopen the latest conversation
88
+ zhx run "task" Run one task for a script or automation
89
+ zhx doctor Check local configuration
90
+
91
+ Inside the console, type / for common actions or /help for guidance.
92
+ zhx init Configure a provider/model profile explicitly
93
+ zhx <command> --help Show help for one command
94
+ zhx help all Show every command and advanced option
95
+ zhx --version Show the installed version
96
+
97
+ Requires Node >=22.13. The console guides API key setup; automation uses environment keys.
98
+ zhx chat and zhivex-harness remain supported aliases.`;
99
+ function resolveHelpTopic(parts, explicit) {
100
+ if (!explicit || !parts.length)
101
+ return;
102
+ const topic = parts.join(":");
103
+ if (topic === "all" || Object.hasOwn(usage, topic) || Object.keys(usage).some((key) => key.startsWith(`${topic}:`)))
104
+ return topic;
105
+ throw new Error(`Unknown help topic: ${parts.join(" ")}. Use zhx help all.`);
106
+ }
107
+ function formatCliHelp(topic, version, full) {
108
+ if (!topic)
109
+ return shortCliHelp(version);
110
+ if (topic === "all")
111
+ return full;
112
+ const contract = CLI_COMMAND_OPTION_CONTRACTS[topic];
113
+ if (!contract) {
114
+ if (topic === "export-audit" || topic === "verify-audit") {
115
+ return `Zhivex Harness — ${topic}
116
+
117
+ Usage: ${usage[topic]}
118
+
119
+ ` + `Experimental audit pack. Signs a directory with HMAC-SHA256.
120
+ ` + ` --out <directory> New directory for export, or the pack to verify
121
+ ` + ` --signing-key-file <path> Key file (overrides ZHIVEX_AUDIT_SIGNING_KEY)
122
+ ` + ` --session <id> Include the redacted activity journal (export only)
123
+ ` + ` --json Print the manifest or verification document
124
+
125
+ ` + `The key must be 32 to 4096 bytes and is not written into the pack.
126
+ ` + `See docs/AUDIT_PACK.md.
127
+ `;
128
+ }
129
+ return `Zhivex Harness — ${topic}
130
+
131
+ ` + Object.entries(usage).filter(([key]) => key.startsWith(`${topic}:`)).map(([, command]) => ` ${command}`).join(`
132
+ `) + `
133
+
134
+ Use zhx ${topic} <subcommand> --help for its options.`;
135
+ }
136
+ const descriptions = new Map;
137
+ for (const line of full.split(`
138
+ `)) {
139
+ const match = line.match(/^ (--[\w-]+)(?:\s|$)/);
140
+ if (match)
141
+ descriptions.set(match[1], line);
142
+ }
143
+ const extra = {
144
+ "--approve": " --approve Approve the pending batch",
145
+ "--deny": " --deny Deny the pending batch",
146
+ "--status": " --status <status> Filter by run status; repeatable",
147
+ "--limit": " --limit <n> Maximum number of results",
148
+ "--search": " --search <text> Literal conversation title or ID filter",
149
+ "--pricing-file": " --pricing-file <file.json> Operator-supplied price estimates",
150
+ "--tool-policy": " --tool-policy <absolute.json> Host-owned tool policy outside the repository",
151
+ "--usage-limit-usd": " --usage-limit-usd <amount> Per-run monetary limit; requires pricing",
152
+ "--version": " --version Show the installed version"
153
+ };
154
+ const examples = {
155
+ run: ['zhx run "Explain this repository"', 'zhx run --profile daily --json "Review the parser"', "git diff | zhx run -"],
156
+ review: ['zhx review "Review error handling"', "zhx review - < review-task.txt"],
157
+ init: ["zhx init --profile daily", "zhx init --profile daily --update --model <id>"],
158
+ doctor: ["zhx doctor --profile daily", "zhx doctor --workspace /path/to/project"]
159
+ };
160
+ const groups = new Map;
161
+ for (const name of contract.allowed) {
162
+ const group = name.startsWith("--oci-") || ["--execution", "--require-verified-delivery", "--allow-check", "--yes"].includes(name) ? "Execution and approvals" : /subagent|reviewer|parallel-reviews|^--route$/.test(name) ? "Specialist agents" : /cost|pricing|usage-limit|^--max-|^--timeout/.test(name) ? "Budgets and limits" : ["--state-dir", "--store", "--tenant", "--user", "--namespace", "--idempotency-key"].includes(name) ? "State and scope" : ["--mcp-config", "--context-config", "--no-project-context", "--require-capability"].includes(name) ? "Context and capabilities" : "Common options";
163
+ const lines = groups.get(group) ?? [];
164
+ lines.push(descriptions.get(name) ?? extra[name] ?? ` ${name}`);
165
+ groups.set(group, lines);
166
+ }
167
+ const sections = ["Common options", "Execution and approvals", "Budgets and limits", "Specialist agents", "Context and capabilities", "State and scope"].filter((group) => groups.has(group)).map((group) => `${group}:
168
+ ${groups.get(group).join(`
169
+ `)}`);
170
+ return `Zhivex Harness — ${topic.replace(":", " ")}
171
+
172
+ Usage: ${usage[topic]}
173
+ ` + (examples[topic] ? `
174
+ Examples:
175
+ ${examples[topic].map((example) => ` ${example}`).join(`
176
+ `)}
177
+ ` : "") + `
178
+ ${sections.join(`
179
+
180
+ `)}
181
+
182
+ Use zhx help all for the full reference and exit codes.`;
183
+ }
184
+
185
+ // packages/core/src/cli/arguments.ts
186
+ import { z as z2 } from "zod";
187
+
188
+ // packages/core/src/cli/cli-profiles.ts
189
+ import { constants as fsConstants } from "node:fs";
190
+ import { lstat, mkdir, open, unlink, rename } from "node:fs/promises";
191
+ import { randomUUID } from "node:crypto";
192
+ import os from "node:os";
193
+ import path from "node:path";
194
+ import { z } from "zod";
195
+ var CLI_PROFILE_SCHEMA_VERSION = 1;
196
+ var CLI_PROFILE_CONFIG_DIRECTORY_ENV = "ZHIVEX_HARNESS_CONFIG_DIR";
197
+ var MAX_CLI_PROFILE_BYTES = 16 * 1024;
198
+ var profileNamePattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
199
+ var cliProfileSchema = z.strictObject({
200
+ schemaVersion: z.literal(CLI_PROFILE_SCHEMA_VERSION),
201
+ provider: z.enum(PROVIDERS),
202
+ reasoningEffort: reasoningEffortSchema.optional(),
203
+ model: z.string().min(1).max(512).refine((value) => !/[\u0000-\u001f\u007f]/.test(value), "model must contain printable characters")
204
+ });
205
+ var absoluteDirectory = (value, source, pathApi = path) => {
206
+ if (!pathApi.isAbsolute(value)) {
207
+ throw new HarnessConfigError(`${source} must be an absolute path.`);
208
+ }
209
+ return pathApi.normalize(value);
210
+ };
211
+ var validateCliProfileName = (name) => {
212
+ if (!profileNamePattern.test(name)) {
213
+ throw new HarnessConfigError("Profile names must use 1-64 letters, digits, dot, underscore, or hyphen and start with a letter or digit.");
214
+ }
215
+ return name;
216
+ };
217
+ var resolveCliProfileConfigDirectory = (context = {}) => {
218
+ const env = context.env ?? process.env;
219
+ const platform = context.platform ?? process.platform;
220
+ const homeDirectory = context.homeDirectory ?? os.homedir();
221
+ const pathApi = platform === "win32" ? path.win32 : path;
222
+ const override = env[CLI_PROFILE_CONFIG_DIRECTORY_ENV]?.trim();
223
+ if (override) {
224
+ return absoluteDirectory(override, CLI_PROFILE_CONFIG_DIRECTORY_ENV, pathApi);
225
+ }
226
+ if (platform === "darwin") {
227
+ return pathApi.join(homeDirectory, "Library", "Application Support", "zhivex-harness");
228
+ }
229
+ if (platform === "win32") {
230
+ const appData = env.APPDATA?.trim();
231
+ if (!appData) {
232
+ throw new HarnessConfigError(`APPDATA is required to locate Zhivex Harness profiles on ${platform}.`);
233
+ }
234
+ return pathApi.join(absoluteDirectory(appData, "APPDATA", pathApi), "zhivex-harness");
235
+ }
236
+ const xdgConfigHome = env.XDG_CONFIG_HOME?.trim();
237
+ const configHome = xdgConfigHome ? absoluteDirectory(xdgConfigHome, "XDG_CONFIG_HOME", pathApi) : pathApi.join(homeDirectory, ".config");
238
+ return pathApi.join(configHome, "zhivex-harness");
239
+ };
240
+ var resolveCliProfilePath = (name, context = {}) => path.join(resolveCliProfileConfigDirectory(context), "profiles", `${validateCliProfileName(name)}.json`);
241
+ var validatePrivateDirectory = async (directory) => {
242
+ const directoryStat = await lstat(directory);
243
+ if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) {
244
+ throw new HarnessConfigError(`CLI profile directory must be a real directory: ${directory}`);
245
+ }
246
+ if ((directoryStat.mode & 18) !== 0) {
247
+ throw new HarnessConfigError(`CLI profile directory must not be writable by group or others: ${directory}`);
248
+ }
249
+ };
250
+ var ensurePrivateDirectory = async (directory) => {
251
+ try {
252
+ await validatePrivateDirectory(directory);
253
+ return;
254
+ } catch (error) {
255
+ if (error.code !== "ENOENT")
256
+ throw error;
257
+ }
258
+ await mkdir(directory, { recursive: true, mode: 448 });
259
+ await validatePrivateDirectory(directory);
260
+ };
261
+ var profileReadError = (profilePath, error) => {
262
+ if (error instanceof UnsafeFileTypeError) {
263
+ throw new HarnessConfigError(`CLI profile must be a regular non-linked file: ${profilePath}`);
264
+ }
265
+ if (error instanceof FileSizeLimitError) {
266
+ throw new HarnessConfigError(`CLI profile exceeds the ${MAX_CLI_PROFILE_BYTES}-byte limit: ${profilePath}`);
267
+ }
268
+ if (error instanceof FileChangedWhileReadingError) {
269
+ throw new HarnessConfigError(`CLI profile changed while it was being read: ${profilePath}`);
270
+ }
271
+ const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
272
+ if (code === "ENOENT") {
273
+ throw new HarnessConfigError(`CLI profile was not found: ${profilePath}. Create it with zhx init --profile <name>.`);
274
+ }
275
+ throw error;
276
+ };
277
+ var loadCliProfile = async (name, context = {}) => {
278
+ const profilePath = resolveCliProfilePath(name, context);
279
+ let file;
280
+ try {
281
+ await validatePrivateDirectory(resolveCliProfileConfigDirectory(context));
282
+ await validatePrivateDirectory(path.dirname(profilePath));
283
+ file = await readRegularFileNoFollow(profilePath, {
284
+ label: `CLI profile ${name}`,
285
+ maxBytes: MAX_CLI_PROFILE_BYTES,
286
+ requireSingleLink: true
287
+ });
288
+ } catch (error) {
289
+ return profileReadError(profilePath, error);
290
+ }
291
+ if ((file.stat.mode & 63) !== 0) {
292
+ throw new HarnessConfigError(`CLI profile permissions are too broad; expected owner-only access: ${profilePath}`);
293
+ }
294
+ let document;
295
+ try {
296
+ document = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(file.contents));
297
+ } catch {
298
+ throw new HarnessConfigError(`CLI profile is not valid UTF-8 JSON: ${profilePath}`);
299
+ }
300
+ const parsed = cliProfileSchema.safeParse(document);
301
+ if (!parsed.success) {
302
+ throw new HarnessConfigError(`CLI profile is invalid: ${parsed.error.issues[0]?.message ?? "schema mismatch"}`);
303
+ }
304
+ return parsed.data;
305
+ };
306
+ var createCliProfile = async (name, input, context = {}) => {
307
+ const parsed = cliProfileSchema.safeParse({
308
+ schemaVersion: CLI_PROFILE_SCHEMA_VERSION,
309
+ provider: input.provider,
310
+ model: input.model,
311
+ ...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {}
312
+ });
313
+ if (!parsed.success) {
314
+ throw new HarnessConfigError(`CLI profile is invalid: ${parsed.error.issues[0]?.message ?? "schema mismatch"}`);
315
+ }
316
+ const profile = parsed.data;
317
+ const profilePath = resolveCliProfilePath(name, context);
318
+ await ensurePrivateDirectory(resolveCliProfileConfigDirectory(context));
319
+ await ensurePrivateDirectory(path.dirname(profilePath));
320
+ let handle;
321
+ try {
322
+ handle = await open(profilePath, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_NOFOLLOW, 384);
323
+ } catch (error) {
324
+ if (error.code === "EEXIST") {
325
+ throw new HarnessConfigError(`CLI profile already exists: ${profilePath}. Use zhx init --profile ${name} --update, or choose another --profile name.`);
326
+ }
327
+ throw error;
328
+ }
329
+ let completed = false;
330
+ try {
331
+ await handle.chmod(384);
332
+ await handle.writeFile(`${JSON.stringify(profile, null, 2)}
333
+ `, "utf8");
334
+ await handle.sync();
335
+ const fileStat = await handle.stat();
336
+ if (!fileStat.isFile() || fileStat.nlink !== 1 || (fileStat.mode & 63) !== 0) {
337
+ throw new HarnessConfigError(`CLI profile could not be created safely: ${profilePath}`);
338
+ }
339
+ completed = true;
340
+ } finally {
341
+ try {
342
+ await handle.close();
343
+ } finally {
344
+ if (!completed)
345
+ await unlink(profilePath).catch(() => {
346
+ return;
347
+ });
348
+ }
349
+ }
350
+ return { path: profilePath, profile };
351
+ };
352
+ var updateCliProfile = async (name, input, context = {}) => {
353
+ await loadCliProfile(name, context);
354
+ const profilePath = resolveCliProfilePath(name, context);
355
+ const temporary = await createCliProfile(`update-${randomUUID()}`, input, context);
356
+ try {
357
+ await loadCliProfile(name, context);
358
+ await rename(temporary.path, profilePath);
359
+ return { path: profilePath, profile: temporary.profile };
360
+ } finally {
361
+ await unlink(temporary.path).catch((error) => {
362
+ if (error.code !== "ENOENT")
363
+ throw error;
364
+ });
365
+ }
366
+ };
367
+ var applyCliProfile = async (options, context = {}) => {
368
+ if (!options.profile)
369
+ return options;
370
+ const profile = await loadCliProfile(options.profile, context);
371
+ return {
372
+ provider: profile.provider,
373
+ model: profile.model,
374
+ ...profile.reasoningEffort && (!options.provider || options.provider === profile.provider) && (!options.model || options.model === profile.model) ? { reasoningEffort: profile.reasoningEffort } : {},
375
+ ...options
376
+ };
377
+ };
378
+ var resolveCliDefaults = async (options, context = {}) => {
379
+ const env = context.env ?? process.env;
380
+ if (options.profile || options.provider || options.model || env.ZHIVEX_HARNESS_PROVIDER || env.ZHIVEX_HARNESS_MODEL)
381
+ return options;
382
+ try {
383
+ await lstat(resolveCliProfilePath("default", context));
384
+ } catch (error) {
385
+ if (error.code !== "ENOENT")
386
+ throw error;
387
+ const configured = providerAvailability(env).filter((provider) => provider.configured);
388
+ return configured.length === 1 ? { ...options, provider: configured[0].id } : options;
389
+ }
390
+ return { ...options, profile: "default" };
391
+ };
392
+
393
+ // packages/core/src/cli/arguments.ts
394
+ var CLI_COMMANDS = ["automations", "personal", "agents", "connections", "projects", "application", "init", "run", "review", "chat", "providers", "doctor", "policy", "resume", "runs", "sessions", "checkpoints", "changes", "state", "memory", "export-audit", "verify-audit", "help", "version"];
395
+ var CLI_RUNS_COMMANDS = ["list", "inspect", "cancel", "cleanup", "export", "report"];
396
+ var CLI_SESSIONS_COMMANDS = ["list", "inspect", "rename", "fork", "archive"];
397
+ var CLI_CHANGES_COMMANDS = ["create", "verify"];
398
+ var CLI_STATE_COMMANDS = ["status", "export", "import"];
399
+ var COMMANDS = new Set(CLI_COMMANDS);
400
+ var RUNS_COMMANDS = new Set(CLI_RUNS_COMMANDS);
401
+ var SESSIONS_COMMANDS = new Set(CLI_SESSIONS_COMMANDS);
402
+ var CHANGES_COMMANDS = new Set(CLI_CHANGES_COMMANDS);
403
+ var STATE_COMMANDS = new Set(CLI_STATE_COMMANDS);
404
+ var CLI_TIMESTAMP_SCHEMA = z2.iso.datetime({ precision: 3 });
405
+ var RUN_STATUSES = new Set([
406
+ "queued",
407
+ "running",
408
+ "completed",
409
+ "suspended",
410
+ "waiting_approval",
411
+ "cancel_requested",
412
+ "failed",
413
+ "cancelled",
414
+ "timed_out"
415
+ ]);
416
+
417
+ class CliUsageError extends HarnessError {
418
+ constructor(message) {
419
+ super(message, { code: "CLI_USAGE_INVALID", category: "usage" });
420
+ this.name = "CliUsageError";
421
+ }
422
+ }
423
+ var optionValue = (argv, index, name) => {
424
+ const value = argv[index + 1];
425
+ if (!value || value.startsWith("-")) {
426
+ throw new CliUsageError(`Missing value for ${name}.`);
427
+ }
428
+ return value;
429
+ };
430
+ var parseCliArgs = (argv) => {
431
+ const booleanOptions = new Set(["--token-budget", "--no-token-budget", "--yes", "--approve", "--deny", "--json", "--jsonl", "--continue", "--cascade", "--final", "--apply", "--help", "--version", "--no-project-context", "--no-memory", "--update"]);
432
+ const separator = argv.indexOf("--");
433
+ argv = argv.flatMap((arg, index) => {
434
+ const equals = arg.indexOf("=");
435
+ const name = arg.slice(0, equals);
436
+ return (separator < 0 || index < separator) && equals > 0 && ((name in CLI_OPTION_DEFINITIONS) || ["--auto-approve", "--auto-approve-allow"].includes(name)) && !booleanOptions.has(name) ? [name, arg.slice(equals + 1)] : [arg];
437
+ });
438
+ let command = "run";
439
+ let commandWasExplicit = false;
440
+ const positional = [];
441
+ const options = {
442
+ command,
443
+ cascade: false,
444
+ final: false,
445
+ apply: false,
446
+ yes: false,
447
+ json: false,
448
+ jsonl: false,
449
+ continueSession: false,
450
+ implicitCommand: true
451
+ };
452
+ let positionalOnly = false;
453
+ const optionCounts = new Map;
454
+ const helpIndex = argv.findIndex((arg, index) => (arg === "--help" || arg === "-h") && (argv.indexOf("--") < 0 || index < argv.indexOf("--")));
455
+ if (helpIndex >= 0) {
456
+ const words = [];
457
+ for (let index = 0;index < argv.length && argv[index] !== "--"; index++) {
458
+ const arg = argv[index];
459
+ if (arg.startsWith("-")) {
460
+ if (arg in CLI_OPTION_DEFINITIONS && !booleanOptions.has(arg) && argv[index + 1] && !argv[index + 1].startsWith("-"))
461
+ index++;
462
+ } else
463
+ words.push(arg);
464
+ }
465
+ const first = words[0];
466
+ const parts = first === "help" ? words.slice(1) : first && COMMANDS.has(first) ? words.slice(0, ["runs", "sessions", "checkpoints", "changes", "state", "memory"].includes(first) ? 2 : 1) : [];
467
+ try {
468
+ const topic = resolveHelpTopic(parts, parts.length > 0);
469
+ return { ...options, command: "help", ...topic ? { helpTopic: topic } : {} };
470
+ } catch (error) {
471
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
472
+ }
473
+ }
474
+ for (let index = 0;index < argv.length; index += 1) {
475
+ const argument = argv[index];
476
+ if (!argument) {
477
+ continue;
478
+ }
479
+ if (positionalOnly) {
480
+ positional.push(argument);
481
+ continue;
482
+ }
483
+ if (argument === "--") {
484
+ positionalOnly = true;
485
+ continue;
486
+ }
487
+ const canonicalOption = argument === "-h" ? "--help" : argument === "-v" ? "--version" : argument;
488
+ if (canonicalOption in CLI_OPTION_DEFINITIONS) {
489
+ optionCounts.set(canonicalOption, (optionCounts.get(canonicalOption) ?? 0) + 1);
490
+ }
491
+ if (!commandWasExplicit && COMMANDS.has(argument)) {
492
+ command = argument;
493
+ options.command = command;
494
+ commandWasExplicit = true;
495
+ continue;
496
+ }
497
+ switch (argument) {
498
+ case "--no-memory":
499
+ options.projectMemory = false;
500
+ break;
501
+ case "--source":
502
+ options.memorySource = optionValue(argv, index, argument);
503
+ index += 1;
504
+ break;
505
+ case "--update":
506
+ options.updateProfile = true;
507
+ break;
508
+ case "-":
509
+ positional.push(argument);
510
+ break;
511
+ case "--profile":
512
+ try {
513
+ options.profile = validateCliProfileName(optionValue(argv, index, argument));
514
+ } catch (error) {
515
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
516
+ }
517
+ index += 1;
518
+ break;
519
+ case "--provider":
520
+ try {
521
+ options.provider = parseProvider(optionValue(argv, index, argument));
522
+ } catch (error) {
523
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
524
+ }
525
+ index += 1;
526
+ break;
527
+ case "--model":
528
+ options.model = optionValue(argv, index, argument);
529
+ index += 1;
530
+ break;
531
+ case "--route": {
532
+ const value = optionValue(argv, index, argument);
533
+ try {
534
+ parseHarnessModelRoute(value);
535
+ } catch (error) {
536
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
537
+ }
538
+ options.routes ??= [];
539
+ options.routes.push(value);
540
+ if (options.routes.length > HARNESS_SUBAGENT_PROFILES.length) {
541
+ throw new CliUsageError(`--route cannot be repeated more than ${HARNESS_SUBAGENT_PROFILES.length} times.`);
542
+ }
543
+ index += 1;
544
+ break;
545
+ }
546
+ case "--workspace":
547
+ options.workspace = optionValue(argv, index, argument);
548
+ index += 1;
549
+ break;
550
+ case "--state-dir":
551
+ options.stateDirectory = optionValue(argv, index, argument);
552
+ index += 1;
553
+ break;
554
+ case "--mcp-config":
555
+ options.mcpConfigPath = optionValue(argv, index, argument);
556
+ index += 1;
557
+ break;
558
+ case "--tool-policy":
559
+ options.toolPolicyFile = optionValue(argv, index, argument);
560
+ index += 1;
561
+ break;
562
+ case "--context-config":
563
+ options.contextConfigPath = optionValue(argv, index, argument);
564
+ index += 1;
565
+ break;
566
+ case "--token-budget":
567
+ options.unlimitedTokens = false;
568
+ break;
569
+ case "--no-token-budget":
570
+ options.unlimitedTokens = true;
571
+ break;
572
+ case "--no-project-context":
573
+ options.projectContext = false;
574
+ break;
575
+ case "--patch":
576
+ options.patchPath = optionValue(argv, index, argument);
577
+ index += 1;
578
+ break;
579
+ case "--preconditions":
580
+ options.preconditionsPath = optionValue(argv, index, argument);
581
+ index += 1;
582
+ break;
583
+ case "--now": {
584
+ const value = optionValue(argv, index, argument);
585
+ if (!CLI_TIMESTAMP_SCHEMA.safeParse(value).success) {
586
+ throw new CliUsageError("--now must be a millisecond-precision ISO-8601 UTC timestamp.");
587
+ }
588
+ options.verificationTime = value;
589
+ index += 1;
590
+ break;
591
+ }
592
+ case "--reasoning":
593
+ options.reasoningEffort = reasoningEffortSchema.parse(optionValue(argv, index, argument));
594
+ index += 1;
595
+ break;
596
+ case "--require-verified-delivery":
597
+ options.requireVerifiedDelivery = true;
598
+ break;
599
+ case "--execution":
600
+ options.executionBackend = optionValue(argv, index, argument);
601
+ index += 1;
602
+ break;
603
+ case "--oci-runtime":
604
+ options.ociRuntime = optionValue(argv, index, argument);
605
+ index += 1;
606
+ break;
607
+ case "--oci-image":
608
+ options.ociImage = optionValue(argv, index, argument);
609
+ index += 1;
610
+ break;
611
+ case "--oci-allow-command": {
612
+ const value = optionValue(argv, index, argument);
613
+ if (!/^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/.test(value)) {
614
+ throw new CliUsageError("--oci-allow-command requires a bare executable name.");
615
+ }
616
+ options.ociAllowedCommands ??= [];
617
+ options.ociAllowedCommands.push(value);
618
+ index += 1;
619
+ break;
620
+ }
621
+ case "--oci-shell":
622
+ options.ociShellMode = optionValue(argv, index, argument);
623
+ if (!["deny", "ask"].includes(options.ociShellMode)) {
624
+ throw new CliUsageError("--oci-shell must be deny or ask.");
625
+ }
626
+ index += 1;
627
+ break;
628
+ case "--store":
629
+ options.storeBackend = optionValue(argv, index, argument);
630
+ index += 1;
631
+ break;
632
+ case "--tenant":
633
+ options.tenantId = optionValue(argv, index, argument);
634
+ index += 1;
635
+ break;
636
+ case "--user":
637
+ options.userId = optionValue(argv, index, argument);
638
+ index += 1;
639
+ break;
640
+ case "--namespace":
641
+ options.namespace = optionValue(argv, index, argument);
642
+ index += 1;
643
+ break;
644
+ case "--idempotency-key":
645
+ options.idempotencyKey = optionValue(argv, index, argument);
646
+ if (options.idempotencyKey.length > 256) {
647
+ throw new CliUsageError("--idempotency-key cannot exceed 256 characters.");
648
+ }
649
+ index += 1;
650
+ break;
651
+ case "--max-steps": {
652
+ const value = optionValue(argv, index, argument);
653
+ options.maxSteps = Number(value);
654
+ if (!Number.isSafeInteger(options.maxSteps) || options.maxSteps < 1) {
655
+ throw new CliUsageError("--max-steps must be a positive safe integer.");
656
+ }
657
+ index += 1;
658
+ break;
659
+ }
660
+ case "--timeout-ms":
661
+ case "--max-tool-calls":
662
+ case "--max-tool-errors":
663
+ case "--context-tokens":
664
+ case "--max-input-tokens":
665
+ case "--max-output-tokens":
666
+ case "--max-total-tokens":
667
+ case "--subagent-max-steps":
668
+ case "--subagent-max-tool-calls":
669
+ case "--subagent-max-tool-errors":
670
+ case "--subagent-max-input-tokens":
671
+ case "--subagent-max-output-tokens":
672
+ case "--subagent-max-total-tokens":
673
+ case "--subagent-timeout-ms":
674
+ case "--max-parallel-reviews": {
675
+ const value = Number(optionValue(argv, index, argument));
676
+ if (!Number.isSafeInteger(value) || value < 0) {
677
+ throw new CliUsageError(`${argument} must be a non-negative integer.`);
678
+ }
679
+ if (argument === "--timeout-ms")
680
+ options.timeoutMs = value;
681
+ if (argument === "--max-tool-calls")
682
+ options.maxToolCalls = value;
683
+ if (argument === "--max-tool-errors")
684
+ options.maxToolErrors = value;
685
+ if (argument === "--context-tokens")
686
+ options.compactionMaxEstimatedInputTokens = value;
687
+ if (argument === "--max-input-tokens")
688
+ options.maxInputTokens = value;
689
+ if (argument === "--max-output-tokens")
690
+ options.maxOutputTokens = value;
691
+ if (argument === "--max-total-tokens")
692
+ options.maxTotalTokens = value;
693
+ if (argument === "--subagent-max-steps")
694
+ options.subagentMaxSteps = value;
695
+ if (argument === "--subagent-max-tool-calls")
696
+ options.subagentMaxToolCalls = value;
697
+ if (argument === "--subagent-max-tool-errors")
698
+ options.subagentMaxToolErrors = value;
699
+ if (argument === "--subagent-max-input-tokens")
700
+ options.subagentMaxInputTokens = value;
701
+ if (argument === "--subagent-max-output-tokens")
702
+ options.subagentMaxOutputTokens = value;
703
+ if (argument === "--subagent-max-total-tokens")
704
+ options.subagentMaxTotalTokens = value;
705
+ if (argument === "--subagent-timeout-ms")
706
+ options.subagentTimeoutMs = value;
707
+ if (argument === "--max-parallel-reviews")
708
+ options.maxParallelReviews = value;
709
+ index += 1;
710
+ break;
711
+ }
712
+ case "--oci-max-process-runtime-ms":
713
+ case "--oci-max-process-output-bytes":
714
+ case "--oci-max-memory-mb":
715
+ case "--oci-max-pids":
716
+ case "--oci-max-cpus":
717
+ case "--oci-max-workspace-bytes":
718
+ case "--oci-max-file-write-bytes":
719
+ case "--oci-tmpfs-mb": {
720
+ const value = Number(optionValue(argv, index, argument));
721
+ if (!Number.isSafeInteger(value) || value < 1) {
722
+ throw new CliUsageError(`${argument} must be a positive integer.`);
723
+ }
724
+ if (argument === "--oci-max-process-runtime-ms")
725
+ options.ociMaxProcessRuntimeMs = value;
726
+ if (argument === "--oci-max-process-output-bytes")
727
+ options.ociMaxProcessOutputBytes = value;
728
+ if (argument === "--oci-max-memory-mb")
729
+ options.ociMaxMemoryMb = value;
730
+ if (argument === "--oci-max-pids")
731
+ options.ociMaxPids = value;
732
+ if (argument === "--oci-max-cpus")
733
+ options.ociMaxCpus = value;
734
+ if (argument === "--oci-max-workspace-bytes")
735
+ options.ociMaxWorkspaceBytes = value;
736
+ if (argument === "--oci-max-file-write-bytes")
737
+ options.ociMaxFileWriteBytes = value;
738
+ if (argument === "--oci-tmpfs-mb")
739
+ options.ociTmpfsMb = value;
740
+ index += 1;
741
+ break;
742
+ }
743
+ case "--search":
744
+ options.sessionSearch = optionValue(argv, index, argument);
745
+ index += 1;
746
+ break;
747
+ case "--pricing-file":
748
+ options.pricingFile = optionValue(argv, index, argument);
749
+ index += 1;
750
+ break;
751
+ case "--compaction-model":
752
+ options.compactionModel = optionValue(argv, index, argument);
753
+ index += 1;
754
+ break;
755
+ case "--compaction-provider":
756
+ options.compactionProvider = parseProvider(optionValue(argv, index, argument));
757
+ index += 1;
758
+ break;
759
+ case "--usage-limit-usd": {
760
+ const value = Number(optionValue(argv, index, argument));
761
+ if (!Number.isFinite(value) || value <= 0)
762
+ throw new CliUsageError("--usage-limit-usd must be positive USD.");
763
+ options.usageLimitUsd = value;
764
+ index += 1;
765
+ break;
766
+ }
767
+ case "--max-cost-usd":
768
+ case "--input-cost-per-million":
769
+ case "--output-cost-per-million": {
770
+ const value = Number(optionValue(argv, index, argument));
771
+ if (!Number.isFinite(value) || value < 0) {
772
+ throw new CliUsageError(`${argument} must be a non-negative number.`);
773
+ }
774
+ if (argument === "--max-cost-usd")
775
+ options.maxCostUsd = value;
776
+ if (argument === "--input-cost-per-million")
777
+ options.inputCostPerMillion = value;
778
+ if (argument === "--output-cost-per-million")
779
+ options.outputCostPerMillion = value;
780
+ index += 1;
781
+ break;
782
+ }
783
+ case "--allow-check": {
784
+ const value = optionValue(argv, index, argument);
785
+ if (!/^[A-Za-z0-9][A-Za-z0-9:_-]{0,63}$/.test(value)) {
786
+ throw new CliUsageError("--allow-check must use 1-64 letters, digits, colon, underscore, or hyphen.");
787
+ }
788
+ options.allowedChecks ??= [];
789
+ options.allowedChecks.push(value);
790
+ if (options.allowedChecks.length > 50) {
791
+ throw new CliUsageError("--allow-check cannot be repeated more than 50 times.");
792
+ }
793
+ index += 1;
794
+ break;
795
+ }
796
+ case "--require-capability": {
797
+ const value = optionValue(argv, index, argument);
798
+ if (!HARNESS_REQUIRED_CAPABILITIES.includes(value)) {
799
+ throw new CliUsageError(`--require-capability must be one of: ${HARNESS_REQUIRED_CAPABILITIES.join(", ")}.`);
800
+ }
801
+ options.requiredCapabilities ??= [];
802
+ options.requiredCapabilities.push(value);
803
+ index += 1;
804
+ break;
805
+ }
806
+ case "--subagent": {
807
+ const value = optionValue(argv, index, argument);
808
+ if (!HARNESS_SUBAGENT_PROFILES.includes(value)) {
809
+ throw new CliUsageError(`--subagent must be one of: ${HARNESS_SUBAGENT_PROFILES.join(", ")}.`);
810
+ }
811
+ options.subagentProfiles ??= [];
812
+ options.subagentProfiles.push(value);
813
+ index += 1;
814
+ break;
815
+ }
816
+ case "--reviewer": {
817
+ const value = optionValue(argv, index, argument);
818
+ if (value !== "explorer" && value !== "reviewer") {
819
+ throw new CliUsageError("--reviewer must be explorer or reviewer.");
820
+ }
821
+ options.reviewers ??= [];
822
+ options.reviewers.push(value);
823
+ index += 1;
824
+ break;
825
+ }
826
+ case "--approval-mode": {
827
+ const mode = optionValue(argv, index, argument);
828
+ if (mode !== "ask" && mode !== "auto" && mode !== "restricted")
829
+ throw new CliUsageError("--approval-mode must be ask, auto or restricted.");
830
+ options.approvalMode = mode;
831
+ options.yes = mode === "auto";
832
+ index += 1;
833
+ break;
834
+ }
835
+ case "--auto-approve": {
836
+ const mode = optionValue(argv, index, argument);
837
+ if (mode !== "manual" && mode !== "auto-edits" && mode !== "auto-limits") {
838
+ throw new CliUsageError("--auto-approve must be manual, auto-edits, or auto-limits.");
839
+ }
840
+ options.autoApproveMode = mode;
841
+ index += 1;
842
+ break;
843
+ }
844
+ case "--auto-approve-allow": {
845
+ const name = optionValue(argv, index, argument);
846
+ options.autoApproveAllow ??= [];
847
+ options.autoApproveAllow.push(name);
848
+ index += 1;
849
+ break;
850
+ }
851
+ case "--yes":
852
+ options.yes = true;
853
+ break;
854
+ case "--approve":
855
+ if (options.approve === false) {
856
+ throw new CliUsageError("You cannot combine --approve and --deny.");
857
+ }
858
+ options.approve = true;
859
+ break;
860
+ case "--deny":
861
+ if (options.approve === true) {
862
+ throw new CliUsageError("You cannot combine --approve and --deny.");
863
+ }
864
+ options.approve = false;
865
+ break;
866
+ case "--json":
867
+ options.json = true;
868
+ break;
869
+ case "--jsonl":
870
+ options.jsonl = true;
871
+ break;
872
+ case "--application-directory":
873
+ options.applicationDirectory = optionValue(argv, index, argument);
874
+ index += 1;
875
+ break;
876
+ case "--area": {
877
+ const area = optionValue(argv, index, argument);
878
+ if (area !== "assistant" && area !== "code")
879
+ throw new CliUsageError("--area requires assistant or code.");
880
+ options.applicationArea = area;
881
+ index += 1;
882
+ break;
883
+ }
884
+ case "--service":
885
+ options.serviceFile = optionValue(argv, index, argument);
886
+ index += 1;
887
+ break;
888
+ case "--session":
889
+ options.sessionId = optionValue(argv, index, argument);
890
+ index += 1;
891
+ break;
892
+ case "--continue":
893
+ options.continueSession = true;
894
+ break;
895
+ case "--status": {
896
+ const value = optionValue(argv, index, argument);
897
+ if (!RUN_STATUSES.has(value)) {
898
+ throw new CliUsageError(`Unsupported run status: ${value}.`);
899
+ }
900
+ options.statuses ??= [];
901
+ options.statuses.push(value);
902
+ index += 1;
903
+ break;
904
+ }
905
+ case "--limit": {
906
+ const value = Number(optionValue(argv, index, argument));
907
+ if (!Number.isSafeInteger(value) || value < 1 || value > 1000) {
908
+ throw new CliUsageError("--limit must be an integer between 1 and 1000.");
909
+ }
910
+ options.limit = value;
911
+ index += 1;
912
+ break;
913
+ }
914
+ case "--cursor":
915
+ options.cursor = optionValue(argv, index, argument);
916
+ index += 1;
917
+ break;
918
+ case "--before": {
919
+ const value = optionValue(argv, index, argument);
920
+ const timestamp = /^\d+$/.test(value) ? Number(value) : Date.parse(value);
921
+ if (!Number.isFinite(timestamp) || timestamp < 0) {
922
+ throw new CliUsageError("--before must be an ISO-8601 date or millisecond timestamp.");
923
+ }
924
+ options.before = timestamp;
925
+ index += 1;
926
+ break;
927
+ }
928
+ case "--reason":
929
+ options.reason = optionValue(argv, index, argument);
930
+ if (options.reason.length > 500) {
931
+ throw new CliUsageError("--reason cannot exceed 500 characters.");
932
+ }
933
+ index += 1;
934
+ break;
935
+ case "--cascade":
936
+ options.cascade = true;
937
+ break;
938
+ case "--final":
939
+ options.final = true;
940
+ break;
941
+ case "--apply":
942
+ options.apply = true;
943
+ break;
944
+ case "--help":
945
+ case "-h":
946
+ options.command = "help";
947
+ break;
948
+ case "--version":
949
+ case "-v":
950
+ options.command = "version";
951
+ break;
952
+ case "--out":
953
+ options.auditOut = optionValue(argv, index, argument);
954
+ index += 1;
955
+ break;
956
+ case "--signing-key-file":
957
+ options.signingKeyFile = optionValue(argv, index, argument);
958
+ index += 1;
959
+ break;
960
+ default:
961
+ if (argument.startsWith("-")) {
962
+ throw new CliUsageError(`Unknown option: ${argument}`);
963
+ }
964
+ positional.push(argument);
965
+ }
966
+ }
967
+ if (options.command === "help") {
968
+ try {
969
+ validateCliCommandOptions("help", optionCounts);
970
+ const topic = resolveHelpTopic(command === "help" ? positional : [command, ...positional], commandWasExplicit);
971
+ if (topic)
972
+ options.helpTopic = topic;
973
+ } catch (error) {
974
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
975
+ }
976
+ return options;
977
+ }
978
+ options.implicitCommand = !commandWasExplicit;
979
+ if (options.json && options.jsonl) {
980
+ throw new CliUsageError("You cannot combine --json and --jsonl.");
981
+ }
982
+ if (options.sessionId && options.continueSession) {
983
+ throw new CliUsageError("You cannot combine --session and --continue.");
984
+ }
985
+ if (options.jsonl && options.command !== "run" && options.command !== "resume") {
986
+ throw new CliUsageError("--jsonl is supported by run and resume.");
987
+ }
988
+ if (options.command !== "changes" && (options.patchPath || options.preconditionsPath || options.verificationTime)) {
989
+ throw new CliUsageError("--patch, --preconditions, and --now are supported only by changes.");
990
+ }
991
+ if (options.command === "automations") {
992
+ const action = positional.shift();
993
+ if (action === "status" && positional.length === 0) {
994
+ if (options.yes)
995
+ throw new CliUsageError("automations status does not accept --yes.");
996
+ } else if (action === "apply" && positional.length === 1 && positional[0] === "-") {
997
+ if (!options.yes)
998
+ throw new CliUsageError("automations apply requires --yes and reviewed configuration JSON on stdin.");
999
+ } else
1000
+ throw new CliUsageError("automations requires status or apply - --yes.");
1001
+ if (options.applicationArea || options.serviceFile)
1002
+ throw new CliUsageError("automations uses the active Assistant in the application coordinator.");
1003
+ options.automationCommand = action;
1004
+ } else if (options.command === "personal") {
1005
+ const action = positional.shift();
1006
+ if (!["tasks", "reminders", "notes", "search-notes", "note"].includes(action ?? ""))
1007
+ throw new CliUsageError("personal requires tasks, reminders, notes, search-notes or note.");
1008
+ if (options.applicationArea || options.serviceFile)
1009
+ throw new CliUsageError("personal uses the active Assistant in the application coordinator.");
1010
+ if (action === "note") {
1011
+ if (positional.length !== 1 || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(positional[0]))
1012
+ throw new CliUsageError("personal note requires a note UUID.");
1013
+ options.personalNoteId = positional.shift();
1014
+ } else {
1015
+ if (action === "search-notes") {
1016
+ const query = positional.shift()?.trim();
1017
+ if (!query || query.length > 200)
1018
+ throw new CliUsageError("personal search-notes requires a query of 1 to 200 characters.");
1019
+ options.personalQuery = query;
1020
+ }
1021
+ if (positional.length > (action === "reminders" ? 0 : 1))
1022
+ throw new CliUsageError("Unexpected personal command arguments.");
1023
+ const offset = positional[0] ?? "0";
1024
+ if (!/^(0|[1-9][0-9]*)$/.test(offset) || Number(offset) > 1e4)
1025
+ throw new CliUsageError("Offset must be an integer between 0 and 10000.");
1026
+ options.personalOffset = Number(offset);
1027
+ }
1028
+ options.personalCommand = action;
1029
+ } else if (["agents", "connections", "projects"].includes(options.command)) {
1030
+ const commands = { agents: { list: 0, create: 1, tools: 1, start: 0, select: 1, rename: 2, model: 2, discard: 0, delete: 1 }, connections: { list: 0, configure: 1, use: 1 }, projects: { list: 0, context: 0, open: 2, select: 1, connection: 2 } };
1031
+ const action = positional.shift() ?? "";
1032
+ if (!(action in commands[options.command]) || positional.length !== commands[options.command][action])
1033
+ throw new CliUsageError(`Invalid ${options.command} action or arguments. See zhx help ${options.command}.`);
1034
+ if (options.command === "agents" && action === "tools" && positional[0] !== "-")
1035
+ throw new CliUsageError("agents tools requires - to read module JSON from stdin.");
1036
+ if (options.command === "connections" && action === "configure" && positional[0] !== "-")
1037
+ throw new CliUsageError("connections configure requires - to read provider JSON from stdin.");
1038
+ if (["discard", "delete"].includes(action) && !options.yes)
1039
+ throw new CliUsageError(`${options.command} ${action} requires --yes.`);
1040
+ if (options.applicationArea || options.serviceFile)
1041
+ throw new CliUsageError("Management commands use the application coordinator, not --area or --service.");
1042
+ options.managementAction = action;
1043
+ options.managementArgs = [...positional];
1044
+ } else if (options.command === "application") {
1045
+ const action = positional.shift();
1046
+ if (!["status", "start", "stop"].includes(action ?? "") || positional.length)
1047
+ throw new CliUsageError("application requires status, start, or stop.");
1048
+ options.applicationCommand = action;
1049
+ if (action === "stop" && !options.yes)
1050
+ throw new CliUsageError("application stop requires --yes to stop tasks and background services for all connected clients.");
1051
+ } else if (options.command === "resume") {
1052
+ const runId = positional.shift();
1053
+ if (runId) {
1054
+ options.runId = runId;
1055
+ }
1056
+ if (positional.length > 0) {
1057
+ throw new CliUsageError("resume accepts exactly one runId.");
1058
+ }
1059
+ } else if (options.command === "runs") {
1060
+ const runsCommand = positional.shift();
1061
+ if (!runsCommand || !RUNS_COMMANDS.has(runsCommand)) {
1062
+ throw new CliUsageError("runs requires one of: list, inspect, cancel, cleanup, export, report.");
1063
+ }
1064
+ options.runsCommand = runsCommand;
1065
+ if (runsCommand === "inspect" || runsCommand === "cancel" || runsCommand === "export" || runsCommand === "report") {
1066
+ const runId = positional.shift();
1067
+ if (!runId) {
1068
+ throw new CliUsageError(`runs ${runsCommand} requires a runId.`);
1069
+ }
1070
+ options.runId = runId;
1071
+ }
1072
+ if (runsCommand === "report" && positional.length)
1073
+ options.reportEnvelopePath = positional.shift();
1074
+ if (positional.length > 0) {
1075
+ throw new CliUsageError(`runs ${runsCommand} received unexpected positional arguments.`);
1076
+ }
1077
+ } else if (options.command === "sessions") {
1078
+ const sessionsCommand = positional.shift();
1079
+ if (!sessionsCommand || !SESSIONS_COMMANDS.has(sessionsCommand)) {
1080
+ throw new CliUsageError("sessions requires one of: list, inspect, rename, fork, archive.");
1081
+ }
1082
+ options.sessionsCommand = sessionsCommand;
1083
+ if (sessionsCommand !== "list") {
1084
+ const sessionId = positional.shift();
1085
+ if (!sessionId)
1086
+ throw new CliUsageError(`sessions ${sessionsCommand} requires a sessionId.`);
1087
+ options.sessionId = sessionId;
1088
+ }
1089
+ if (sessionsCommand === "rename") {
1090
+ const title = positional.join(" ").trim();
1091
+ if (!title)
1092
+ throw new CliUsageError("sessions rename requires a title.");
1093
+ options.sessionTitle = title;
1094
+ positional.length = 0;
1095
+ }
1096
+ if (positional.length > 0) {
1097
+ throw new CliUsageError(`sessions ${sessionsCommand} received unexpected positional arguments.`);
1098
+ }
1099
+ } else if (options.command === "checkpoints") {
1100
+ const command2 = positional.shift();
1101
+ const counts = { list: [1, 1], capture: [3, 22], inspect: [1, 1], prepare: [1, 1], review: [1, 1], apply: [2, 2], recover: [2, 2], storage: [0, 0], "prune-review": [1, 100], "prune-apply": [2, 101] };
1102
+ if (!command2 || !Object.hasOwn(counts, command2))
1103
+ throw new CliUsageError("checkpoints requires list, capture, inspect, prepare, review, apply, recover, storage, prune-review or prune-apply.");
1104
+ const [min, max] = counts[command2];
1105
+ if (positional.length < min || positional.length > max)
1106
+ throw new CliUsageError(`Invalid arguments for checkpoints ${command2}; use --help.`);
1107
+ options.checkpointsCommand = command2;
1108
+ options.checkpointArguments = positional.splice(0);
1109
+ } else if (options.command === "changes") {
1110
+ const changesCommand = positional.shift();
1111
+ if (!changesCommand || !CHANGES_COMMANDS.has(changesCommand)) {
1112
+ throw new CliUsageError("changes requires one of: create, verify.");
1113
+ }
1114
+ options.changesCommand = changesCommand;
1115
+ const artifactPath = positional.shift();
1116
+ if (!artifactPath) {
1117
+ throw new CliUsageError(`changes ${changesCommand} requires an input JSON file.`);
1118
+ }
1119
+ options.artifactPath = artifactPath;
1120
+ if (changesCommand === "create" && (options.preconditionsPath || options.verificationTime)) {
1121
+ throw new CliUsageError("--preconditions and --now are only supported by changes verify.");
1122
+ }
1123
+ if (positional.length > 0) {
1124
+ throw new CliUsageError(`changes ${changesCommand} received unexpected positional arguments.`);
1125
+ }
1126
+ } else if (options.command === "memory") {
1127
+ const subcommand = positional.shift();
1128
+ const counts = { remember: 1, list: 0, read: 1, update: 3, forget: 2, suggest: 1, accept: 2, clear: 0, enable: 0, disable: 0, context: 1 };
1129
+ if (!subcommand || !Object.hasOwn(counts, subcommand) || positional.length !== counts[subcommand])
1130
+ throw new CliUsageError("Invalid memory arguments. Use memory --help; quote content as one argument.");
1131
+ options.memoryCommand = subcommand;
1132
+ options.memoryArguments = positional.splice(0);
1133
+ } else if (options.command === "state") {
1134
+ const stateCommand = positional.shift();
1135
+ if (!stateCommand || !STATE_COMMANDS.has(stateCommand)) {
1136
+ throw new CliUsageError("state requires one of: status, export, import.");
1137
+ }
1138
+ options.stateCommand = stateCommand;
1139
+ if (stateCommand !== "status") {
1140
+ const backupPath = positional.shift();
1141
+ if (!backupPath)
1142
+ throw new CliUsageError(`state ${stateCommand} requires a backup JSON path.`);
1143
+ options.backupPath = backupPath;
1144
+ }
1145
+ if (positional.length > 0) {
1146
+ throw new CliUsageError(`state ${stateCommand} received unexpected positional arguments.`);
1147
+ }
1148
+ } else if (options.command === "export-audit" || options.command === "verify-audit") {
1149
+ const allowed = new Set(["--workspace", "--state-dir", "--store", "--tenant", "--user", "--namespace", "--json", ...options.command === "export-audit" ? ["--session"] : []]);
1150
+ for (const name of optionCounts.keys()) {
1151
+ if (!allowed.has(name))
1152
+ throw new CliUsageError(`${name} is not supported by ${options.command}.`);
1153
+ }
1154
+ if (!options.auditOut)
1155
+ throw new CliUsageError(`${options.command} requires --out <path>.`);
1156
+ if (options.command === "export-audit") {
1157
+ const taskId = positional.shift();
1158
+ if (!taskId)
1159
+ throw new CliUsageError("export-audit requires a task id.");
1160
+ options.runId = taskId;
1161
+ }
1162
+ if (positional.length > 0)
1163
+ throw new CliUsageError(`${options.command} received unexpected positional arguments.`);
1164
+ return options;
1165
+ } else if (options.command === "run" || options.command === "review") {
1166
+ if (positional.includes("-") && positional.length !== 1) {
1167
+ throw new CliUsageError("Use - alone to read the task from stdin, or provide a task argument.");
1168
+ }
1169
+ const prompt = positional.join(" ").trim();
1170
+ if (prompt) {
1171
+ options.prompt = prompt;
1172
+ }
1173
+ } else if (positional.length > 0) {
1174
+ throw new CliUsageError(`${options.command} does not accept positional arguments.`);
1175
+ }
1176
+ if (options.auditOut || options.signingKeyFile) {
1177
+ throw new CliUsageError("--out and --signing-key-file are supported only by export-audit and verify-audit.");
1178
+ }
1179
+ if (options.implicitCommand && options.command === "run" && !options.prompt && (options.continueSession || options.sessionId) && !options.json && !options.jsonl)
1180
+ options.command = "chat";
1181
+ const applicationMode = Boolean(options.applicationDirectory || options.applicationArea);
1182
+ if (applicationMode && options.serviceFile)
1183
+ throw new CliUsageError("Do not combine --service with application discovery.");
1184
+ if (options.applicationArea && options.command === "application")
1185
+ throw new CliUsageError("application lifecycle commands operate on the whole host, not one area.");
1186
+ if (applicationMode && !["application", "agents", "connections", "projects", "personal", "automations"].includes(options.command) && !["run", "resume", "chat", "policy", "sessions", "checkpoints"].includes(options.command))
1187
+ throw new CliUsageError("This command does not yet support application mode.");
1188
+ if (options.command === "checkpoints" && options.sessionId && !options.serviceFile && !applicationMode)
1189
+ throw new CliUsageError("--session for checkpoints requires --service or application mode.");
1190
+ if (options.command === "checkpoints" && (options.serviceFile || applicationMode)) {
1191
+ const retention = ["storage", "prune-review", "prune-apply"].includes(options.checkpointsCommand);
1192
+ if (retention && options.sessionId)
1193
+ throw new CliUsageError("Checkpoint retention operates on the selected project scope, not --session.");
1194
+ const positionalSession = ["list", "capture"].includes(options.checkpointsCommand);
1195
+ if (!retention && !positionalSession && !options.sessionId)
1196
+ throw new CliUsageError("Service checkpoint operations require --session <source sessionId>.");
1197
+ if (positionalSession && options.sessionId && options.sessionId !== options.checkpointArguments?.[0])
1198
+ throw new CliUsageError("The positional session and --session must match.");
1199
+ }
1200
+ if (options.serviceFile || applicationMode && !["application", "agents", "connections", "projects", "personal", "automations"].includes(options.command)) {
1201
+ const allowed = new Set(["--application-directory", "--area", "--service", "--session", "--idempotency-key", "--yes", "--json", "--jsonl", "--approve", "--deny", "--search", "--continue"]);
1202
+ for (const arg of optionCounts.keys())
1203
+ if (arg.startsWith("--") && !allowed.has(arg))
1204
+ throw new CliUsageError(`Service mode does not accept ${arg}; runtime configuration belongs to the service host.`);
1205
+ } else if (["run", "resume"].includes(options.command) && optionCounts.has("--session")) {
1206
+ throw new CliUsageError("--session for run/resume requires --service.");
1207
+ }
1208
+ if ((options.autoApproveMode || options.autoApproveAllow) && (options.serviceFile || applicationMode || !["chat", "run", "review", "resume"].includes(options.command)))
1209
+ throw new CliUsageError("Automatic edit policy belongs to direct terminal runs, not shared-host authority.");
1210
+ const commandKey = options.command === "checkpoints" ? `checkpoints:${options.checkpointsCommand}` : options.command === "runs" ? `runs:${options.runsCommand}` : options.command === "sessions" ? `sessions:${options.sessionsCommand}` : options.command === "changes" ? `changes:${options.changesCommand}` : options.command === "memory" ? `memory:${options.memoryCommand}` : options.command === "state" ? `state:${options.stateCommand}` : options.command;
1211
+ try {
1212
+ validateCliCommandOptions(commandKey, optionCounts);
1213
+ } catch (error) {
1214
+ throw new CliUsageError(error instanceof Error ? error.message : String(error));
1215
+ }
1216
+ if (options.command === "review") {
1217
+ const invalidRoute = options.routes?.map((route) => parseHarnessModelRoute(route)).find((route) => route.profile !== "explorer" && route.profile !== "reviewer");
1218
+ if (invalidRoute) {
1219
+ throw new CliUsageError(`review cannot route the unused ${invalidRoute.profile} profile; use explorer or reviewer.`);
1220
+ }
1221
+ }
1222
+ return options;
1223
+ };
1224
+
1225
+ export { shortCliHelp, formatCliHelp, loadCliProfile, createCliProfile, updateCliProfile, applyCliProfile, resolveCliDefaults, CLI_COMMANDS, CLI_RUNS_COMMANDS, CLI_SESSIONS_COMMANDS, CLI_CHANGES_COMMANDS, CLI_STATE_COMMANDS, CliUsageError, parseCliArgs };