@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.
- package/CHANGELOG.md +16 -3
- package/README.md +17 -5
- package/SECURITY.md +1 -1
- package/SUPPORT.md +2 -2
- package/benchmarks/README.md +98 -0
- package/contracts/engine-api.json +1587 -0
- package/contracts/public-api.json +114 -0
- package/contracts/stable-api-signatures.json +17 -17
- package/dist/acp-cli.js +37 -1090
- package/dist/application/agenda.d.ts +10 -0
- package/dist/application/approval-review.d.ts +61 -0
- package/dist/application/assistant/automation/scheduler.d.ts +21 -0
- package/dist/application/assistant/automation/summary.d.ts +29 -0
- package/dist/application/assistant/automation/time.d.ts +10 -0
- package/dist/application/assistant/calendar/calendar.d.ts +238 -0
- package/dist/application/assistant/calendar/connection.d.ts +50 -0
- package/dist/application/assistant/calendar/create-event.d.ts +75 -0
- package/dist/application/assistant/calendar/environment.d.ts +2 -0
- package/dist/application/assistant/calendar/http.d.ts +6 -0
- package/dist/application/assistant/calendar/oauth.d.ts +68 -0
- package/dist/application/assistant/calendar/store.d.ts +11 -0
- package/dist/application/assistant/calendar/tools.d.ts +78 -0
- package/dist/application/assistant/client.d.ts +10 -0
- package/dist/application/assistant/config.d.ts +9 -0
- package/dist/application/assistant/contracts.d.ts +77 -0
- package/dist/application/assistant/daily/service.d.ts +181 -0
- package/dist/application/assistant/doctor.d.ts +22 -0
- package/dist/application/assistant/evaluation.d.ts +81 -0
- package/dist/application/assistant/host.d.ts +399 -0
- package/dist/application/assistant/integrations/google.d.ts +117 -0
- package/dist/application/assistant/integrations/public-web.d.ts +16 -0
- package/dist/application/assistant/managed/secrets.d.ts +10 -0
- package/dist/application/assistant/managed/setup-state.d.ts +346 -0
- package/dist/application/assistant/managed/setup.d.ts +492 -0
- package/dist/application/assistant/microsoft/connection.d.ts +73 -0
- package/dist/application/assistant/microsoft/tools.d.ts +78 -0
- package/dist/application/assistant/modules/calendar.d.ts +3 -0
- package/dist/application/assistant/modules/catalog.d.ts +38 -0
- package/dist/application/assistant/modules/daily.d.ts +5 -0
- package/dist/application/assistant/modules/github.d.ts +5 -0
- package/dist/application/assistant/modules/google.d.ts +3 -0
- package/dist/application/assistant/modules/mcp.d.ts +11 -0
- package/dist/application/assistant/modules/microsoft.d.ts +3 -0
- package/dist/application/assistant/modules/module.d.ts +224 -0
- package/dist/application/assistant/modules/tools.d.ts +11 -0
- package/dist/application/assistant/modules/web.d.ts +7 -0
- package/dist/application/assistant/private-directory.d.ts +3 -0
- package/dist/application/assistant/proactive/service.d.ts +142 -0
- package/dist/application/assistant/providers/openai-compatible.d.ts +66 -0
- package/dist/application/assistant/providers/provider.d.ts +141 -0
- package/dist/application/assistant/providers/web-citations.d.ts +2 -0
- package/dist/application/assistant/runtime.d.ts +16 -0
- package/dist/application/assistant/task-metrics.d.ts +304 -0
- package/dist/application/assistant/telegram/api.d.ts +47 -0
- package/dist/application/assistant/telegram/bridge.d.ts +69 -0
- package/dist/application/assistant/telegram/store.d.ts +10 -0
- package/dist/application/automation.d.ts +5 -0
- package/dist/application/calendar-review.d.ts +5 -0
- package/dist/application/checkpoint-review.d.ts +30 -0
- package/dist/application/client.d.ts +18 -0
- package/dist/application/code/context.d.ts +5 -0
- package/dist/application/code/delivery.d.ts +6 -0
- package/dist/application/code/git-delivery.d.ts +54 -0
- package/dist/application/code/github-git-transport.d.ts +15 -0
- package/dist/application/code/github-pr-transport.d.ts +6 -0
- package/dist/application/code/host.d.ts +25 -0
- package/dist/application/code/pr-delivery.d.ts +79 -0
- package/dist/application/code/projects.d.ts +90 -0
- package/dist/application/code/remote-delivery.d.ts +80 -0
- package/dist/application/code/repository.d.ts +9 -0
- package/dist/application/code/worktrees.d.ts +123 -0
- package/dist/application/contracts.d.ts +288 -0
- package/dist/application/coordinator-client.d.ts +33 -0
- package/dist/application/coordinator-discovery.d.ts +17 -0
- package/dist/application/coordinator-launcher.d.ts +2 -0
- package/dist/application/coordinator.d.ts +27 -0
- package/dist/application/credential-process.d.ts +13 -0
- package/dist/application/host.d.ts +7 -0
- package/dist/application/management.d.ts +68 -0
- package/dist/application/notes.d.ts +5 -0
- package/dist/application/offline-migration.d.ts +16 -0
- package/dist/application/personal-state.d.ts +5 -0
- package/dist/application/review-channel.d.ts +23 -0
- package/dist/application/review-tickets.d.ts +29 -0
- package/dist/application/runtime-binding.d.ts +4 -0
- package/dist/application-cli-wfh08g41.js +184 -0
- package/dist/application-cli-z3f9pvcf.js +209 -0
- package/dist/arguments-75r85mvc.js +27 -0
- package/dist/arguments-x24bbqvd.js +22 -0
- package/dist/audit/index.js +16 -472
- package/dist/audit-pack-1gnych0m.js +93 -0
- package/dist/{audit-pack-s9n693by.js → audit-pack-h44kjkbj.js} +17 -11
- package/dist/calendar-2xw0rr7b.js +49 -0
- package/dist/cli/application-cli.d.ts +2 -0
- package/dist/cli/arguments.d.ts +14 -1
- package/dist/cli/auto-approve-setup.d.ts +13 -0
- package/dist/cli/configured-harness.d.ts +1 -2
- package/dist/cli/console/console-budget.d.ts +16 -2
- package/dist/cli/console/console-checkpoints.d.ts +12 -0
- package/dist/cli/console/console-commands.d.ts +3 -3
- package/dist/cli/console/console-compaction.d.ts +1 -1
- package/dist/cli/console/console-diff.d.ts +2 -0
- package/dist/cli/console/console-input.d.ts +29 -1
- package/dist/cli/console/console-navigation.d.ts +2 -2
- package/dist/cli/console/console-outcome.d.ts +10 -0
- package/dist/cli/console/console-presentation.d.ts +17 -2
- package/dist/cli/console/console-pricing.d.ts +14 -0
- package/dist/cli/console/console-reasoning.d.ts +1 -1
- package/dist/cli/console/console-recovery.d.ts +2 -0
- package/dist/cli/console/console-review.d.ts +34 -0
- package/dist/cli/console/console-run-policy.d.ts +5 -0
- package/dist/cli/console/console-run-view.d.ts +28 -0
- package/dist/cli/console/console-task.d.ts +30 -0
- package/dist/cli/console/console-welcome.d.ts +13 -3
- package/dist/cli/console/review-diff.d.ts +20 -0
- package/dist/cli/presentation.d.ts +8 -6
- package/dist/cli/service-checkpoints.d.ts +234 -0
- package/dist/cli/terminal/activity-history.d.ts +4 -2
- package/dist/cli/terminal/activity-stream.d.ts +33 -0
- package/dist/cli/terminal/file-diff.d.ts +11 -0
- package/dist/cli/terminal/terminal-theme.d.ts +9 -0
- package/dist/cli/terminal/terminal-ui.d.ts +44 -2
- package/dist/cli/terminal/tool-activity.d.ts +6 -2
- package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
- package/dist/{cli-entry-1epvek01.js → cli-entry-86rcbmwh.js} +294 -14
- package/dist/cli-entry-btkpb4h1.js +3627 -0
- package/dist/cli-entry-bxjbs6qq.js +200 -0
- package/dist/cli-entry-cpm89r9q.js +624 -0
- package/dist/{cli-entry-mbcq96nx.js → cli-entry-dksm56sj.js} +39 -293
- package/dist/{cli-entry-rsx0wpvs.js → cli-entry-eka68ttb.js} +4087 -4625
- package/dist/cli-entry-h7dcah4p.js +137 -0
- package/dist/cli-entry-kwk23ktq.js +33 -0
- package/dist/{cli-entry-nyzyvf24.js → cli-entry-vmce694z.js} +1286 -3142
- package/dist/cli-entry-wanv05db.js +1113 -0
- package/dist/{cli-yxvq8qf1.js → cli-z7vhm1rk.js} +1767 -380
- package/dist/cli.js +8 -6
- package/dist/client/json-contracts.d.ts +153 -0
- package/dist/client/local-service.d.ts +7 -12
- package/dist/client/local-transport.d.ts +14 -0
- package/dist/client/protocol.d.ts +43 -1
- package/dist/compat/cli-options.d.ts +7 -1
- package/dist/compat/cli.d.ts +2 -0
- package/dist/compat/cli.js +4043 -0
- package/dist/compat/code-support.d.ts +4 -0
- package/dist/compat/code-support.js +50 -28
- package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
- package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
- package/dist/context/adaptive-compaction.d.ts +1 -0
- package/dist/context/lossless-lines.d.ts +13 -0
- package/dist/context/numbered-read-lines.d.ts +15 -0
- package/dist/context/read-attempts.d.ts +21 -0
- package/dist/context/request-projection.d.ts +32 -4
- package/dist/context/scoped-context.d.ts +31 -5
- package/dist/context/working-read-replay.d.ts +12 -0
- package/dist/coordinator-client-nzysqxf0.js +10 -0
- package/dist/engine/acp.js +27 -21
- package/dist/engine/application-client.d.ts +11 -0
- package/dist/engine/application-client.js +18 -0
- package/dist/engine/application-protocol.d.ts +5 -0
- package/dist/engine/application-protocol.js +7 -0
- package/dist/engine/application.d.ts +43 -0
- package/dist/engine/application.js +206 -0
- package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
- package/dist/engine/assistant/automation/scheduler.js +11 -0
- package/dist/engine/assistant/automation/summary.d.ts +3 -0
- package/dist/engine/assistant/automation/summary.js +8 -0
- package/dist/engine/assistant/automation/time.d.ts +5 -0
- package/dist/engine/assistant/automation/time.js +15 -0
- package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
- package/dist/engine/assistant/calendar/calendar.js +12 -0
- package/dist/engine/assistant/calendar/connection.d.ts +2 -0
- package/dist/engine/assistant/calendar/connection.js +11 -0
- package/dist/engine/assistant/calendar/environment.d.ts +1 -0
- package/dist/engine/assistant/calendar/environment.js +7 -0
- package/dist/engine/assistant/calendar/http.d.ts +3 -0
- package/dist/engine/assistant/calendar/http.js +9 -0
- package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
- package/dist/engine/assistant/calendar/oauth.js +12 -0
- package/dist/engine/assistant/calendar/store.d.ts +2 -0
- package/dist/engine/assistant/calendar/store.js +8 -0
- package/dist/engine/assistant/calendar/tools.d.ts +2 -0
- package/dist/engine/assistant/calendar/tools.js +46 -0
- package/dist/engine/assistant/client.d.ts +2 -0
- package/dist/engine/assistant/client.js +33 -0
- package/dist/engine/assistant/config.d.ts +1 -0
- package/dist/engine/assistant/config.js +102 -0
- package/dist/engine/assistant/contracts.d.ts +10 -0
- package/dist/engine/assistant/contracts.js +78 -0
- package/dist/engine/assistant/daily/service.d.ts +12 -0
- package/dist/engine/assistant/daily/service.js +27 -0
- package/dist/engine/assistant/doctor.d.ts +1 -0
- package/dist/engine/assistant/doctor.js +116 -0
- package/dist/engine/assistant/evaluation.d.ts +2 -0
- package/dist/engine/assistant/evaluation.js +76 -0
- package/dist/engine/assistant/host.d.ts +2 -0
- package/dist/engine/assistant/host.js +63 -0
- package/dist/engine/assistant/integrations/google.d.ts +9 -0
- package/dist/engine/assistant/integrations/google.js +30 -0
- package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
- package/dist/engine/assistant/integrations/public-web.js +11 -0
- package/dist/engine/assistant/managed/secrets.d.ts +1 -0
- package/dist/engine/assistant/managed/secrets.js +0 -0
- package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
- package/dist/engine/assistant/managed/setup-state.js +84 -0
- package/dist/engine/assistant/managed/setup.d.ts +3 -0
- package/dist/engine/assistant/managed/setup.js +85 -0
- package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
- package/dist/engine/assistant/microsoft/connection.js +21 -0
- package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
- package/dist/engine/assistant/microsoft/tools.js +30 -0
- package/dist/engine/assistant/modules/calendar.d.ts +1 -0
- package/dist/engine/assistant/modules/calendar.js +49 -0
- package/dist/engine/assistant/modules/catalog.d.ts +3 -0
- package/dist/engine/assistant/modules/catalog.js +67 -0
- package/dist/engine/assistant/modules/daily.d.ts +1 -0
- package/dist/engine/assistant/modules/daily.js +48 -0
- package/dist/engine/assistant/modules/github.d.ts +1 -0
- package/dist/engine/assistant/modules/github.js +43 -0
- package/dist/engine/assistant/modules/google.d.ts +1 -0
- package/dist/engine/assistant/modules/google.js +53 -0
- package/dist/engine/assistant/modules/mcp.d.ts +1 -0
- package/dist/engine/assistant/modules/mcp.js +42 -0
- package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
- package/dist/engine/assistant/modules/microsoft.js +53 -0
- package/dist/engine/assistant/modules/module.d.ts +5 -0
- package/dist/engine/assistant/modules/module.js +42 -0
- package/dist/engine/assistant/modules/tools.d.ts +2 -0
- package/dist/engine/assistant/modules/tools.js +42 -0
- package/dist/engine/assistant/modules/web.d.ts +1 -0
- package/dist/engine/assistant/modules/web.js +45 -0
- package/dist/engine/assistant/private-directory.d.ts +1 -0
- package/dist/engine/assistant/private-directory.js +7 -0
- package/dist/engine/assistant/proactive/service.d.ts +6 -0
- package/dist/engine/assistant/proactive/service.js +16 -0
- package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
- package/dist/engine/assistant/providers/openai-compatible.js +12 -0
- package/dist/engine/assistant/providers/provider.d.ts +7 -0
- package/dist/engine/assistant/providers/provider.js +54 -0
- package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
- package/dist/engine/assistant/providers/web-citations.js +7 -0
- package/dist/engine/assistant/runtime.d.ts +2 -0
- package/dist/engine/assistant/runtime.js +73 -0
- package/dist/engine/assistant/task-metrics.d.ts +8 -0
- package/dist/engine/assistant/task-metrics.js +17 -0
- package/dist/engine/assistant/telegram/api.d.ts +5 -0
- package/dist/engine/assistant/telegram/api.js +11 -0
- package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
- package/dist/engine/assistant/telegram/bridge.js +40 -0
- package/dist/engine/assistant/telegram/store.d.ts +2 -0
- package/dist/engine/assistant/telegram/store.js +8 -0
- package/dist/engine/client.js +26 -18
- package/dist/engine/desktop-providers-v1.js +4 -4
- package/dist/engine/desktop-state-v1.js +16 -13
- package/dist/engine/index.d.ts +4 -0
- package/dist/engine/index.js +117 -159
- package/dist/engine/mcp-stdio-v1.js +13 -12
- package/dist/engine/models.js +65 -23
- package/dist/engine/protocol.js +10 -6
- package/dist/engine/service.js +32 -21
- package/dist/hostile-repository-demo.js +2329 -1096
- package/dist/index-09rsdr2d.js +1744 -0
- package/dist/index-0csc5sc7.js +139 -0
- package/dist/{index-4mn6m3bq.js → index-0dkty795.js} +8 -6
- package/dist/index-0kkgqvg7.js +0 -0
- package/dist/index-0mzz9axm.js +58 -0
- package/dist/index-1e69ar8r.js +38 -0
- package/dist/index-1z0xhkh9.js +18 -0
- package/dist/index-2cef1k92.js +356 -0
- package/dist/{index-rgqzdgv6.js → index-2j0v1xwr.js} +17 -13
- package/dist/index-2jw9jd7h.js +116 -0
- package/dist/index-2n9qx4km.js +0 -0
- package/dist/index-3rvk23e8.js +877 -0
- package/dist/index-3wa4j0yk.js +71 -0
- package/dist/index-41q1k17x.js +210 -0
- package/dist/index-4vz4bqqw.js +33 -0
- package/dist/index-5jxm2wy5.js +123 -0
- package/dist/index-5rk6ss42.js +216 -0
- package/dist/index-5v1skxf7.js +1852 -0
- package/dist/{index-fqqz1yt8.js → index-6ehtssyz.js} +369 -335
- package/dist/index-76kpdbpw.js +80 -0
- package/dist/{index-5nmm0642.js → index-7nbmhmw5.js} +10 -10
- package/dist/index-8mx0yrkz.js +31 -0
- package/dist/index-8tjev5ds.js +11 -0
- package/dist/index-91n5wr6s.js +163 -0
- package/dist/index-91trs3ew.js +151 -0
- package/dist/index-9y8p5vy5.js +222 -0
- package/dist/index-abxahprd.js +55 -0
- package/dist/index-aptyr511.js +84 -0
- package/dist/{index-8sm2a1wa.js → index-ay26xfxt.js} +28 -20
- package/dist/index-b4yed1s3.js +657 -0
- package/dist/index-bb7phvtg.js +23 -0
- package/dist/index-bk5tn9b8.js +236 -0
- package/dist/index-bw34861c.js +292 -0
- package/dist/index-c6fnjhgv.js +55 -0
- package/dist/{index-qfsrrnz6.js → index-cjevq9s8.js} +2 -2
- package/dist/{index-c39197wq.js → index-ctcwrkrc.js} +4 -4
- package/dist/{index-yx52bt4a.js → index-cztmcesv.js} +2 -2
- package/dist/index-dpbmxnrf.js +564 -0
- package/dist/index-ekxdcy36.js +134 -0
- package/dist/index-f8zpcsx3.js +289 -0
- package/dist/{index-6dxrbnxm.js → index-f970qtb4.js} +7 -143
- package/dist/index-fatcn6fp.js +2791 -0
- package/dist/index-fbzykqxy.js +105 -0
- package/dist/{index-1265j7t2.js → index-fwf274vc.js} +24 -14
- package/dist/index-fy4w0a7v.js +0 -0
- package/dist/index-gvva3e5x.js +76 -0
- package/dist/index-h7dcah4p.js +137 -0
- package/dist/index-hm9r120s.js +42 -0
- package/dist/index-j3d2tw97.js +328 -0
- package/dist/index-jfqj20x8.js +41 -0
- package/dist/{index-hhrnrqfc.js → index-k529a278.js} +6 -6
- package/dist/{index-bt2p8x7r.js → index-kbrf5bx7.js} +110 -106
- package/dist/index-kwk23ktq.js +33 -0
- package/dist/index-kz857p1j.js +557 -0
- package/dist/{index-j466sekf.js → index-mkt5yrax.js} +31 -105
- package/dist/{index-nxmk6re7.js → index-ndgnvjez.js} +18 -18
- package/dist/index-nemn4epv.js +43 -0
- package/dist/index-nkwy5bjr.js +1225 -0
- package/dist/index-nvvzr4ny.js +136 -0
- package/dist/index-pkspzsfs.js +78 -0
- package/dist/{index-fm84men1.js → index-px1tnqgt.js} +2 -2
- package/dist/index-q7qdw883.js +79 -0
- package/dist/{index-mzydbzp8.js → index-qvbg6tx1.js} +65 -23
- package/dist/index-r3mwr5fb.js +0 -0
- package/dist/index-rdr78m0k.js +91 -0
- package/dist/index-rtamqsfs.js +59 -0
- package/dist/index-s125ss45.js +38 -0
- package/dist/{index-vn91b9z1.js → index-sx1t6dnd.js} +3721 -2382
- package/dist/index-tar0ngkm.js +359 -0
- package/dist/index-tn58cr6w.js +471 -0
- package/dist/{index-w0m1nckc.js → index-v79s9bf9.js} +118 -45
- package/dist/index-vk3rq21m.js +17 -0
- package/dist/index-vmvnr28y.js +72 -0
- package/dist/index-vz629cg8.js +49 -0
- package/dist/{index-eps3c3g6.js → index-w292hdpz.js} +197 -960
- package/dist/{index-amjttjaj.js → index-w9eqg6p9.js} +24 -302
- package/dist/index-wj96kdw2.js +57 -0
- package/dist/index-wyck5yhd.js +141 -0
- package/dist/index-xvtk8pxs.js +674 -0
- package/dist/{index-bpc596v3.js → index-xwb691v9.js} +2 -2
- package/dist/index-ym69x168.js +518 -0
- package/dist/index-yprdjk9v.js +65 -0
- package/dist/index-z2a81ccr.js +35 -0
- package/dist/{index-3ah1f369.js → index-z69cqk74.js} +3 -3
- package/dist/index-zaakvmzq.js +62 -0
- package/dist/index-zk3m4mzg.js +232 -0
- package/dist/index-zx3wgvx4.js +218 -0
- package/dist/index.js +102 -83
- package/dist/persistence/migration-guard.d.ts +3 -0
- package/dist/runtime/agent-profile.d.ts +12 -0
- package/dist/runtime/harness.d.ts +13 -0
- package/dist/runtime/known-file-preload.d.ts +35 -0
- package/dist/service-cli.js +130 -40
- package/dist/service-client-cli-2rzxy5mj.js +1166 -0
- package/dist/service-client-cli-5ne8q5ej.js +543 -0
- package/dist/tools/ooxml-zip.d.ts +21 -0
- package/dist/tools/presentations.d.ts +47 -0
- package/dist/tools/tabular-data.d.ts +114 -0
- package/dist/tools/workspace.d.ts +76 -0
- package/dist/verify-historical-migrations.js +2249 -1016
- package/dist/workspace/workspace.d.ts +13 -1
- package/dist/zhx.js +8 -6
- package/docs/APPLICATION_MIGRATION.md +32 -0
- package/docs/CLI.md +166 -2
- package/docs/CODE_RELEASE.md +11 -5
- package/docs/CODE_WEB_TASKS.md +3 -114
- package/docs/CONTEXT_ENGINEERING.md +93 -0
- package/docs/ENGINE_API.md +9 -2
- package/docs/EXTENSIBILITY.md +1 -1
- package/docs/FIRST_USE.md +6 -6
- package/docs/INTERNAL_ARCHIVE.md +43 -0
- package/docs/LOCAL_SERVICE.md +1 -1
- package/docs/MODEL_CATALOG.md +14 -0
- package/docs/PROJECT_MEMORY.md +1 -1
- package/docs/README.md +23 -4
- package/evaluations/representative-assembly-matrix.json +19 -1
- package/examples/README.md +4 -4
- package/examples/assistant/compatible-calendar.json +17 -0
- package/examples/assistant/composed-modules.json +23 -0
- package/examples/assistant/connected-tools.json +9 -0
- package/examples/assistant/daily-tools.json +6 -0
- package/examples/assistant/offline.mjs +24 -0
- package/fixtures/cli-compatibility/README.md +10 -0
- package/fixtures/cli-compatibility/inventory.json +7858 -0
- package/package.json +232 -26
- package/dist/cli/console/console-model-catalog.d.ts +0 -8
- package/dist/index-2yyfg69h.js +0 -619
- package/dist/index-3wwfn5n6.js +0 -270
- package/dist/index-4gt045j0.js +0 -288
- package/dist/index-4jw3tvy8.js +0 -301
- package/dist/service-client-cli-xbj7j5kj.js +0 -1251
|
@@ -0,0 +1,1852 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compactToolResult,
|
|
3
|
+
createConfiguredHarness
|
|
4
|
+
} from "./index-09rsdr2d.js";
|
|
5
|
+
import {
|
|
6
|
+
paintTerminal,
|
|
7
|
+
sanitizeTerminalText,
|
|
8
|
+
terminalCellWidth,
|
|
9
|
+
terminalSupportsColor,
|
|
10
|
+
terminalToneCode
|
|
11
|
+
} from "./index-3rvk23e8.js";
|
|
12
|
+
import {
|
|
13
|
+
revealInvisibleText
|
|
14
|
+
} from "./index-dpbmxnrf.js";
|
|
15
|
+
import {
|
|
16
|
+
loadModelCatalog
|
|
17
|
+
} from "./index-cjevq9s8.js";
|
|
18
|
+
import {
|
|
19
|
+
modelReasoningEfforts
|
|
20
|
+
} from "./index-fwf274vc.js";
|
|
21
|
+
import {
|
|
22
|
+
bundledModelCatalog,
|
|
23
|
+
catalogModels,
|
|
24
|
+
modelDescription
|
|
25
|
+
} from "./index-qvbg6tx1.js";
|
|
26
|
+
import {
|
|
27
|
+
createPolicyDecisionEvidence,
|
|
28
|
+
inspectHarnessPolicy,
|
|
29
|
+
observeHarnessPolicyDecisions
|
|
30
|
+
} from "./index-kbrf5bx7.js";
|
|
31
|
+
import {
|
|
32
|
+
usagePricingSchema
|
|
33
|
+
} from "./index-6ehtssyz.js";
|
|
34
|
+
import {
|
|
35
|
+
readRegularFileNoFollow
|
|
36
|
+
} from "./index-h7dcah4p.js";
|
|
37
|
+
|
|
38
|
+
// packages/core/src/cli/policy-decisions.ts
|
|
39
|
+
var formatPolicyDecision = (event) => sanitizeTerminalText(`Policy · ${event.toolName} · ${event.phase} · ${event.decision}${event.explicitReviewRequired ? " · explicit review required" : ""} · ${event.ruleIds.join(", ") || "baseline"}: ${event.reason}${event.reasonTruncated ? " [reason truncated]" : ""}`);
|
|
40
|
+
async function observeCliPolicy(options, tracker, work) {
|
|
41
|
+
const evidence = createPolicyDecisionEvidence();
|
|
42
|
+
try {
|
|
43
|
+
return await observeHarnessPolicyDecisions((event) => {
|
|
44
|
+
evidence.append(event);
|
|
45
|
+
if (options.jsonl)
|
|
46
|
+
process.stdout.write(JSON.stringify({ ...event, kind: "run-event", sequence: tracker.sequence = (tracker.sequence ?? 0) + 1 }) + `
|
|
47
|
+
`);
|
|
48
|
+
else if (!options.json)
|
|
49
|
+
process.stderr.write(formatPolicyDecision(event) + `
|
|
50
|
+
`);
|
|
51
|
+
}, work);
|
|
52
|
+
} finally {
|
|
53
|
+
tracker.policyEvidence = evidence.snapshot();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// packages/core/src/cli/console/console-commands.ts
|
|
58
|
+
var CONSOLE_COMMAND_CATALOG = [
|
|
59
|
+
["/menu", "Open navigation menu", true],
|
|
60
|
+
["/theme", "Choose light, dark or system terminal colors", true],
|
|
61
|
+
["/help", "Show commands; /help all shows everything", true],
|
|
62
|
+
["/connection", "Inspect credentials and optionally test selected model access", false],
|
|
63
|
+
["/credentials", "Manage provider keys in the system keychain or this session", false],
|
|
64
|
+
["/provider", "Select a provider", false],
|
|
65
|
+
["/model", "Select a model and reasoning effort", false],
|
|
66
|
+
["/reasoning", "Choose reasoning effort for the current model", false],
|
|
67
|
+
["/route", "Configure specialist model routes", false],
|
|
68
|
+
["/status", "Inspect the current session and run", true],
|
|
69
|
+
["/diff", "Review workspace changes", false],
|
|
70
|
+
["/task", "Define, review, keep or revise a bounded task", false],
|
|
71
|
+
["/checkpoint", "Capture, review and restore selected text files", false],
|
|
72
|
+
["/budget", "Set estimated USD policy for each next run", false],
|
|
73
|
+
["/pricing", "Inspect advisory model prices and their source", false],
|
|
74
|
+
["/review", "Review a task", false],
|
|
75
|
+
["/resume", "Reopen a conversation by session ID", true],
|
|
76
|
+
["/pending", "Inspect pending approvals", true],
|
|
77
|
+
["/approve", "Approve the pending actions", true],
|
|
78
|
+
["/deny", "Deny the pending actions", true],
|
|
79
|
+
["/approvals", "Change approval mode for this CLI session", false],
|
|
80
|
+
["/auto-approve", "Set Manual, Auto-edits, or Auto with limits for this session", false],
|
|
81
|
+
["/manual", "Drop auto-approve back to Manual for this session", true],
|
|
82
|
+
["/undo", "Revert the latest auto-approved file change", false],
|
|
83
|
+
["/continue", "Continue an interrupted task with retained results in a new run", false],
|
|
84
|
+
["/compact", "Compact conversation context", false],
|
|
85
|
+
["/compaction", "Choose a compaction model or inspect recommendations", false],
|
|
86
|
+
["/new", "Start a new conversation", true],
|
|
87
|
+
["/rename", "Rename the current conversation", true],
|
|
88
|
+
["/clear", "Clear conversation context", false],
|
|
89
|
+
["/exit", "Exit the console", true],
|
|
90
|
+
["/paste", "Compose a literal multiline draft", true],
|
|
91
|
+
["/activity", "Show recent activity; /activity clear resets it", true],
|
|
92
|
+
["/queue", "Inspect queued tasks; /queue clear discards them", true],
|
|
93
|
+
["/verbose", "Toggle full or compact activity details", false],
|
|
94
|
+
["/context", "Inspect project rules and selected context", false],
|
|
95
|
+
["/attach", "Attach a workspace file to the next request", false],
|
|
96
|
+
["/attachments", "List selected attachments", false],
|
|
97
|
+
["/detach", "Remove selected attachments", false],
|
|
98
|
+
["/sessions", "Find saved conversations", true],
|
|
99
|
+
["/limits", "Inspect or change the step limit for next turns", false],
|
|
100
|
+
["/usage", "Inspect transport usage", false],
|
|
101
|
+
["/cancel", "Cancel the active run", true]
|
|
102
|
+
];
|
|
103
|
+
var consoleCommands = (mode = "direct") => CONSOLE_COMMAND_CATALOG.filter(([name, , service]) => mode === "service" ? service : name !== "/cancel");
|
|
104
|
+
var everyday = new Set(["/theme", "/menu", "/help", "/model", "/new", "/sessions", "/attach", "/task", "/diff", "/exit"]);
|
|
105
|
+
var approvals = new Set(["/approvals", "/pending", "/approve", "/deny", "/auto-approve", "/manual", "/undo"]);
|
|
106
|
+
var searchConsoleCommands = (query, mode = "direct") => {
|
|
107
|
+
const search = query.replace(/^\//, "").toLowerCase();
|
|
108
|
+
return consoleCommands(mode).filter(([name, description]) => search ? name.slice(1).startsWith(search) || description.toLowerCase().includes(search) : everyday.has(name)).sort(([a], [b]) => Number(b.slice(1).startsWith(search)) - Number(a.slice(1).startsWith(search)));
|
|
109
|
+
};
|
|
110
|
+
var argumentsFor = {
|
|
111
|
+
"/theme": "[light|dark|system]",
|
|
112
|
+
"/task": "[start JSON|review|keep|revise text]",
|
|
113
|
+
"/limits": "[positive integer]",
|
|
114
|
+
"/budget": "[USD|off]",
|
|
115
|
+
"/checkpoint": "[capture|list|review|restore|retry]",
|
|
116
|
+
"/compaction": "[provider:model|off|recommend]",
|
|
117
|
+
"/approvals": "[ask|auto|restricted]",
|
|
118
|
+
"/auto-approve": "[manual|auto-edits|auto-limits|workspace <mode>]",
|
|
119
|
+
"/undo": "[audit id]",
|
|
120
|
+
"/provider": "[id]",
|
|
121
|
+
"/model": "[id]",
|
|
122
|
+
"/route": "[role=provider[:model] | clear [role]]",
|
|
123
|
+
"/review": "<task>",
|
|
124
|
+
"/resume": "[last|sessionId]",
|
|
125
|
+
"/new": "[title]",
|
|
126
|
+
"/rename": "<title>",
|
|
127
|
+
"/attach": "<path>",
|
|
128
|
+
"/detach": "[path]",
|
|
129
|
+
"/sessions": "[search]"
|
|
130
|
+
};
|
|
131
|
+
var formatConsoleHelp = (mode = "direct", all = false) => {
|
|
132
|
+
const commands = consoleCommands(mode);
|
|
133
|
+
const format = (names) => commands.filter(([name]) => names.has(name)).map(([name, description]) => {
|
|
134
|
+
const args = mode === "service" && name === "/new" ? "" : mode === "service" && name === "/resume" ? "[sessionId]" : name === "/help" ? "[all]" : argumentsFor[name] ?? "";
|
|
135
|
+
return `${`${name} ${args}`.trim().padEnd(28)} ${description}`;
|
|
136
|
+
}).join(`
|
|
137
|
+
`);
|
|
138
|
+
return `Everyday commands:
|
|
139
|
+
` + format(everyday) + `
|
|
140
|
+
|
|
141
|
+
Pending approvals (review the actions before deciding):
|
|
142
|
+
` + format(approvals) + (all ? `
|
|
143
|
+
|
|
144
|
+
Advanced commands:
|
|
145
|
+
` + format(new Set(commands.map(([name]) => name).filter((name) => !everyday.has(name) && !approvals.has(name)))) : `
|
|
146
|
+
|
|
147
|
+
Use /help all for advanced commands, or type / followed by a search term.`) + `
|
|
148
|
+
Up/Down selects, Tab inserts, Enter submits. Ctrl+R searches prompt history.
|
|
149
|
+
` + `? shows shortcuts; Alt+Enter inserts a newline. Bracketed paste stays literal.
|
|
150
|
+
` + `Ctrl+C discards input or stops the active operation.
|
|
151
|
+
` + (mode === "service" ? `Provider, model and tool policy are managed by the service host.
|
|
152
|
+
` : "");
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// packages/core/src/cli/console/console-input.ts
|
|
156
|
+
import { createInterface } from "node:readline";
|
|
157
|
+
import { PassThrough, Writable } from "node:stream";
|
|
158
|
+
import { StringDecoder } from "node:string_decoder";
|
|
159
|
+
|
|
160
|
+
// packages/core/src/cli/console/console-presentation.ts
|
|
161
|
+
var segments = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
162
|
+
var consoleLines = (text, width) => {
|
|
163
|
+
const result = [];
|
|
164
|
+
for (const source of sanitizeTerminalText(text).replace(/\t/g, " ").split(`
|
|
165
|
+
`)) {
|
|
166
|
+
let line = "", cells = 0;
|
|
167
|
+
for (const { segment } of segments.segment(source)) {
|
|
168
|
+
const size = terminalCellWidth(segment);
|
|
169
|
+
if (line && cells + size > Math.max(1, width)) {
|
|
170
|
+
result.push(line);
|
|
171
|
+
line = "";
|
|
172
|
+
cells = 0;
|
|
173
|
+
}
|
|
174
|
+
line += segment;
|
|
175
|
+
cells += size;
|
|
176
|
+
}
|
|
177
|
+
result.push(line);
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
};
|
|
181
|
+
var consoleLabel = (text, width) => {
|
|
182
|
+
if (width <= 0)
|
|
183
|
+
return "";
|
|
184
|
+
const safe = sanitizeTerminalText(text).replace(/[\r\n\t]/g, " ");
|
|
185
|
+
if (terminalCellWidth(safe) <= width)
|
|
186
|
+
return safe;
|
|
187
|
+
let value = "";
|
|
188
|
+
for (const { segment } of segments.segment(safe)) {
|
|
189
|
+
if (terminalCellWidth(value + segment) > width - 1)
|
|
190
|
+
break;
|
|
191
|
+
value += segment;
|
|
192
|
+
}
|
|
193
|
+
return value + "…";
|
|
194
|
+
};
|
|
195
|
+
var consoleWidth = (columns = 80) => Math.max(1, Math.min((columns || 80) - 1, 100));
|
|
196
|
+
var muted = (text, color) => paintTerminal(text, "muted", color);
|
|
197
|
+
var usd = (value) => typeof value === "number" ? `$${value.toFixed(6)}` : "unknown";
|
|
198
|
+
var money = (value) => `$${value.toFixed(6)}`;
|
|
199
|
+
var pendingDecision = (status) => status.startsWith("Waiting for your decision") || status.startsWith("approval pending");
|
|
200
|
+
var approvalPhrase = (input) => input.autoApproveMode === "auto-edits" ? "auto-edits · m for manual" : input.autoApproveMode === "auto-limits" ? "auto-limits · m for manual" : input.autoApproveMode === "manual" ? "manual approvals" : input.approvalMode === "restricted" ? "restricted approvals" : input.approvalMode === "auto" || input.automaticApprovals ? "auto approvals" : "ask before changes";
|
|
201
|
+
var consoleStatusParts = (input) => {
|
|
202
|
+
const runCap = input.runUsage?.limitUsd;
|
|
203
|
+
const nextCap = input.nextLimitUsd;
|
|
204
|
+
const hasRunCap = typeof runCap === "number";
|
|
205
|
+
const hasNextCap = typeof nextCap === "number";
|
|
206
|
+
const incomplete = Boolean(input.runUsage && !input.runUsage.usageComplete && (hasRunCap || hasNextCap));
|
|
207
|
+
const showRun = Boolean(input.runUsage && (hasRunCap || incomplete || hasNextCap && typeof input.runUsage.estimatedUsd === "number"));
|
|
208
|
+
const attachments = (input.attachments ?? 0) > 0 ? `${input.attachments} attached` : "";
|
|
209
|
+
return [
|
|
210
|
+
input.model,
|
|
211
|
+
approvalPhrase(input),
|
|
212
|
+
input.status,
|
|
213
|
+
...attachments ? [attachments] : [],
|
|
214
|
+
...showRun && input.runUsage ? [`Run est. ${usd(input.runUsage.estimatedUsd)}${input.runUsage.usageComplete ? "" : " INCOMPLETE"}${hasRunCap ? ` / ${money(runCap)} cap` : ""}`] : [],
|
|
215
|
+
...hasNextCap ? [`Next run cap ${money(nextCap)}`] : []
|
|
216
|
+
];
|
|
217
|
+
};
|
|
218
|
+
var consoleStatusText = (input) => consoleStatusParts(input).join(" · ");
|
|
219
|
+
var wrapClause = (text, width) => {
|
|
220
|
+
if (terminalCellWidth(text) <= width)
|
|
221
|
+
return [text];
|
|
222
|
+
const lines = [];
|
|
223
|
+
let current = "";
|
|
224
|
+
for (const word of text.split(" ")) {
|
|
225
|
+
if (terminalCellWidth(word) > width) {
|
|
226
|
+
if (current)
|
|
227
|
+
lines.push(current);
|
|
228
|
+
current = "";
|
|
229
|
+
lines.push(...consoleLines(word, width));
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const next = current ? `${current} ${word}` : word;
|
|
233
|
+
if (current && terminalCellWidth(next) > width) {
|
|
234
|
+
lines.push(current);
|
|
235
|
+
current = word;
|
|
236
|
+
} else
|
|
237
|
+
current = next;
|
|
238
|
+
}
|
|
239
|
+
if (current)
|
|
240
|
+
lines.push(current);
|
|
241
|
+
return lines.length ? lines : [""];
|
|
242
|
+
};
|
|
243
|
+
var packClauses = (parts, width) => {
|
|
244
|
+
const lines = [];
|
|
245
|
+
let current = "";
|
|
246
|
+
for (const part of parts) {
|
|
247
|
+
const next = current ? `${current} · ${part}` : part;
|
|
248
|
+
if (current && terminalCellWidth(next) > width) {
|
|
249
|
+
lines.push(...wrapClause(current, width));
|
|
250
|
+
current = part;
|
|
251
|
+
} else
|
|
252
|
+
current = next;
|
|
253
|
+
}
|
|
254
|
+
if (current)
|
|
255
|
+
lines.push(...wrapClause(current, width));
|
|
256
|
+
return lines;
|
|
257
|
+
};
|
|
258
|
+
var consoleStateLines = (input, columns = 80) => packClauses(consoleStatusParts(input), consoleWidth(columns));
|
|
259
|
+
var legacyStateLines = (input, columns = 80) => {
|
|
260
|
+
const width = consoleWidth(columns);
|
|
261
|
+
const policy = input.autoApproveMode ? approvalPhrase(input) : input.approvalMode === "restricted" ? "restricted approvals" : input.approvalMode === "auto" || input.automaticApprovals ? "auto approvals" : "review approvals";
|
|
262
|
+
const cap = (value) => typeof value === "number" ? money(value) : "none";
|
|
263
|
+
return [
|
|
264
|
+
...consoleLines(consoleLabel(`Model ${input.model}${input.reasoning ? ` · ${input.reasoning}` : ""}`, width * 2), width),
|
|
265
|
+
...input.runUsage ? consoleLines(`Run est. ${usd(input.runUsage.estimatedUsd)}${input.runUsage.usageComplete ? "" : " INCOMPLETE"} / ${cap(input.runUsage.limitUsd)} cap`, width) : ["Run: no usage recorded"],
|
|
266
|
+
...consoleLines(`Next run cap ${cap(input.nextLimitUsd)} · ${policy}`, width),
|
|
267
|
+
...consoleLines(`Context ~${input.contextTokens ?? 0} retained tokens* · ${input.attachments ?? 0} attached`, width)
|
|
268
|
+
];
|
|
269
|
+
};
|
|
270
|
+
var formatComposer = (input, columns = 80, color = terminalSupportsColor(Boolean(process.stdout.isTTY)), layout = "legacy") => {
|
|
271
|
+
const width = consoleWidth(columns);
|
|
272
|
+
const title = input.title ? muted(consoleLabel(input.title, width), color) + `
|
|
273
|
+
` : "";
|
|
274
|
+
if (layout === "focus")
|
|
275
|
+
return `
|
|
276
|
+
${title}${muted("─".repeat(width), color)}
|
|
277
|
+
`;
|
|
278
|
+
if (input.runUsage !== undefined || input.nextLimitUsd !== undefined || input.contextTokens !== undefined || input.autoApproveMode !== undefined) {
|
|
279
|
+
const status2 = consoleLabel(input.status, width);
|
|
280
|
+
const painted = color && pendingDecision(input.status) ? paintTerminal(status2, "pending", color) : status2;
|
|
281
|
+
return `
|
|
282
|
+
${title}${legacyStateLines(input, columns).map((line) => muted(line, color)).join(`
|
|
283
|
+
`)}
|
|
284
|
+
${painted}
|
|
285
|
+
${muted("─".repeat(width), color)}
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
const model = consoleLabel([input.model, input.reasoning ? `reasoning ${input.reasoning}` : undefined].filter(Boolean).join(" · "), width);
|
|
289
|
+
const policy = input.approvalMode === "restricted" ? "restricted approvals" : input.approvalMode === "auto" || input.automaticApprovals ? "auto approvals" : "review approvals";
|
|
290
|
+
const status = consoleLabel([input.status, policy, input.attachments ? `${input.attachments} attached` : undefined].filter(Boolean).join(" · "), width);
|
|
291
|
+
return `
|
|
292
|
+
${title}${muted(model, color)}
|
|
293
|
+
${color && pendingDecision(input.status) ? paintTerminal(status, "pending", color) : muted(status, color)}
|
|
294
|
+
${muted("─".repeat(width), color)}
|
|
295
|
+
`;
|
|
296
|
+
};
|
|
297
|
+
var formatComposerFooter = (columns = 80, color = false, focus) => {
|
|
298
|
+
const width = consoleWidth(columns);
|
|
299
|
+
const rule = muted("─".repeat(width), color);
|
|
300
|
+
if (!focus) {
|
|
301
|
+
const hints2 = width >= 65 ? "/ commands · Ctrl+R history · Alt+Enter newline · ? shortcuts" : width >= 40 ? "/ commands · Ctrl+R history · ? shortcuts" : "/ commands · ? help";
|
|
302
|
+
return [rule, muted(consoleLabel(hints2, width), color)];
|
|
303
|
+
}
|
|
304
|
+
const hints = width >= 32 ? "/ commands · ? shortcuts" : "?";
|
|
305
|
+
const text = consoleStatusText(focus);
|
|
306
|
+
const paint = (line) => color && pendingDecision(focus.status) ? paintTerminal(line, "pending", color) : muted(line, color);
|
|
307
|
+
const hintWidth = terminalCellWidth(hints);
|
|
308
|
+
if (terminalCellWidth(text) + 2 + hintWidth <= width) {
|
|
309
|
+
return [rule, `${paint(text)}${" ".repeat(width - terminalCellWidth(text) - hintWidth)}${muted(hints, color)}`];
|
|
310
|
+
}
|
|
311
|
+
return [rule, ...consoleStateLines(focus, columns).map(paint), muted(consoleLabel(hints, width), color)];
|
|
312
|
+
};
|
|
313
|
+
var formatComposerPlaceholder = (columns = 80, color = false) => muted(consoleLabel("Ask a question or describe a task", Math.max(0, consoleWidth(columns) - 2)), color);
|
|
314
|
+
var CONSOLE_SHORTCUTS = [
|
|
315
|
+
"Keyboard shortcuts",
|
|
316
|
+
"Enter Send task (history search only restores a draft)",
|
|
317
|
+
"Alt+Enter Insert a newline",
|
|
318
|
+
"Up / Down Move within multiline input; recall history at its edges",
|
|
319
|
+
"Ctrl+R Search this session's in-memory prompt history",
|
|
320
|
+
"Tab Insert selected command or history match",
|
|
321
|
+
"Esc Close command menu or cancel history search",
|
|
322
|
+
"Ctrl+C Discard draft or cancel the active operation",
|
|
323
|
+
"Ctrl+D Exit when the draft is empty",
|
|
324
|
+
"/menu Browse providers, models and conversations",
|
|
325
|
+
"/resume Choose a saved conversation",
|
|
326
|
+
"Credential source, retained-token estimates and run caps are on /status.",
|
|
327
|
+
"Context estimates cover retained messages only. They exclude request instructions and tools. Costs are estimates, not invoices.",
|
|
328
|
+
"While working: type a draft, Enter queues the next task, Up recalls the last queued task. Ctrl+C stops and clears the queue."
|
|
329
|
+
].join(`
|
|
330
|
+
`);
|
|
331
|
+
var chooseConsoleItem = async (title, items, io) => {
|
|
332
|
+
if (!items.length) {
|
|
333
|
+
io.write(`No matches.
|
|
334
|
+
`);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
let query = "";
|
|
338
|
+
for (;; ) {
|
|
339
|
+
const matches = items.filter((item) => `${item.label} ${item.detail ?? ""}`.toLowerCase().includes(query.toLowerCase()));
|
|
340
|
+
const visible = matches.slice(0, 12);
|
|
341
|
+
io.write(`
|
|
342
|
+
${sanitizeTerminalText(title)}
|
|
343
|
+
` + visible.map((item, i) => ` ${i + 1}. ${consoleLabel(item.label, 60)}${item.detail ? ` · ${consoleLabel(item.detail, 60)}` : ""}`).join(`
|
|
344
|
+
`) + `
|
|
345
|
+
${matches.length > 12 ? `${matches.length} matches; type a filter to narrow the list.
|
|
346
|
+
` : ""}`);
|
|
347
|
+
const answer = (await io.ask("Choose number, type a filter, or Enter to cancel: ")).trim();
|
|
348
|
+
if (!answer)
|
|
349
|
+
return;
|
|
350
|
+
if (/^[a-z]$/.test(answer)) {
|
|
351
|
+
const keyed = items.find((item) => item.key === answer);
|
|
352
|
+
if (keyed)
|
|
353
|
+
return keyed.value;
|
|
354
|
+
}
|
|
355
|
+
if (/^\d+$/.test(answer)) {
|
|
356
|
+
const selected = visible[Number(answer) - 1];
|
|
357
|
+
if (selected)
|
|
358
|
+
return selected.value;
|
|
359
|
+
io.write(`Choose a number from the visible list.
|
|
360
|
+
`);
|
|
361
|
+
} else
|
|
362
|
+
query = answer;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// packages/core/src/cli/console/console-review.ts
|
|
367
|
+
var fits = (text, width) => terminalCellWidth(text) <= width;
|
|
368
|
+
var hintFor = (width, selected) => {
|
|
369
|
+
const options = selected < 0 ? [
|
|
370
|
+
"No action highlighted · ↑↓ then a or r · n/p hunks · PgUp/PgDn",
|
|
371
|
+
"No action highlighted · a or r · PgUp/PgDn",
|
|
372
|
+
"a approve · r reject · PgUp/PgDn",
|
|
373
|
+
"PgUp/PgDn"
|
|
374
|
+
] : [
|
|
375
|
+
"↑↓ move · Enter confirms the highlight · n/p hunks · PgUp/PgDn",
|
|
376
|
+
"Enter confirms the highlight · PgUp/PgDn",
|
|
377
|
+
"n/p hunks · PgUp/PgDn",
|
|
378
|
+
"PgUp/PgDn"
|
|
379
|
+
];
|
|
380
|
+
return options.find((option) => fits(option, width)) ?? "PgUp/PgDn";
|
|
381
|
+
};
|
|
382
|
+
var headerLine = (right, width) => {
|
|
383
|
+
const left = "( Z ) Review changes";
|
|
384
|
+
const place = (value) => {
|
|
385
|
+
const gap = width - terminalCellWidth(left) - terminalCellWidth(value);
|
|
386
|
+
return gap >= 2 ? left + " ".repeat(gap) + value : undefined;
|
|
387
|
+
};
|
|
388
|
+
if (right) {
|
|
389
|
+
const full = place(right);
|
|
390
|
+
if (full)
|
|
391
|
+
return full;
|
|
392
|
+
const project = right.split(" · ")[0] ?? "";
|
|
393
|
+
const short = project && project !== right ? place(project) : undefined;
|
|
394
|
+
if (short)
|
|
395
|
+
return short;
|
|
396
|
+
}
|
|
397
|
+
return consoleLabel(left, width);
|
|
398
|
+
};
|
|
399
|
+
var wrapWords = (text, width) => {
|
|
400
|
+
const lines = [];
|
|
401
|
+
let line = "";
|
|
402
|
+
for (const word of text.split(" ")) {
|
|
403
|
+
const next = line ? `${line} ${word}` : word;
|
|
404
|
+
if (fits(next, width)) {
|
|
405
|
+
line = next;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (line)
|
|
409
|
+
lines.push(line);
|
|
410
|
+
if (fits(word, width))
|
|
411
|
+
line = word;
|
|
412
|
+
else {
|
|
413
|
+
const broken = consoleLines(word, width);
|
|
414
|
+
lines.push(...broken.slice(0, -1));
|
|
415
|
+
line = broken.at(-1) ?? "";
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (line)
|
|
419
|
+
lines.push(line);
|
|
420
|
+
return lines.length ? lines : [""];
|
|
421
|
+
};
|
|
422
|
+
var itemLines = (items, selected, width, details) => {
|
|
423
|
+
const lines = [];
|
|
424
|
+
for (const [index, item] of items.entries()) {
|
|
425
|
+
const mark = index === selected ? "> " : " ";
|
|
426
|
+
const key = item.key ? `${item.key} ` : "";
|
|
427
|
+
lines.push(...wrapWords(`${mark}${key}${item.label}`, width));
|
|
428
|
+
if (details && item.detail)
|
|
429
|
+
lines.push(...wrapWords(` ${item.detail}`, width));
|
|
430
|
+
}
|
|
431
|
+
return lines;
|
|
432
|
+
};
|
|
433
|
+
var reviewFrame = (review, items, selected, _query, offset, columns = 80, rows = 24, wrappedBody) => {
|
|
434
|
+
const width = consoleWidth(columns);
|
|
435
|
+
const banner = review.banner ? wrapWords(review.banner, width).slice(0, 2) : [];
|
|
436
|
+
const summary = review.summary ? wrapWords(review.summary, width).slice(0, 2) : [];
|
|
437
|
+
const files = review.fileList ? review.fileList.split(`
|
|
438
|
+
`).filter(Boolean).flatMap((line) => wrapWords(line, width)) : [];
|
|
439
|
+
const preface = [...banner, ...summary, ...files];
|
|
440
|
+
const body = wrappedBody ?? consoleLines(review.body, width);
|
|
441
|
+
const hint = hintFor(width, selected);
|
|
442
|
+
const title = consoleLabel(review.title, width);
|
|
443
|
+
const notice = review.notice ? consoleLabel(review.notice, width) : undefined;
|
|
444
|
+
let details = true;
|
|
445
|
+
let showNotice = Boolean(notice);
|
|
446
|
+
const footerOf = () => {
|
|
447
|
+
const decisions = itemLines(items, selected, width, details);
|
|
448
|
+
return [title, ...decisions.length ? decisions : [" No decisions"], hint, ...showNotice && notice ? [notice] : []];
|
|
449
|
+
};
|
|
450
|
+
let footer = footerOf();
|
|
451
|
+
while (footer.length > rows - 3 && (details || showNotice)) {
|
|
452
|
+
if (details)
|
|
453
|
+
details = false;
|
|
454
|
+
else
|
|
455
|
+
showNotice = false;
|
|
456
|
+
footer = footerOf();
|
|
457
|
+
}
|
|
458
|
+
const chrome = preface.length + footer.length + 2;
|
|
459
|
+
const capacity = Math.max(1, rows - chrome);
|
|
460
|
+
const start = Math.max(0, Math.min(offset, Math.max(0, body.length - capacity)));
|
|
461
|
+
const visible = body.slice(start, start + Math.min(capacity, body.length));
|
|
462
|
+
const remaining = Math.max(0, body.length - (start + visible.length));
|
|
463
|
+
const count = review.files ?? 0;
|
|
464
|
+
const fileLabel = count === 1 ? "1 file" : `${count} files`;
|
|
465
|
+
const marker = remaining > 0 ? `↓ ${remaining} more lines · n/p hunks · PgUp/PgDn` : count > 0 ? `End of changes · ${fileLabel}` : "End of changes";
|
|
466
|
+
const lines = [
|
|
467
|
+
headerLine(review.headerRight ?? "", width),
|
|
468
|
+
...preface,
|
|
469
|
+
...visible,
|
|
470
|
+
consoleLabel(marker, width),
|
|
471
|
+
...footer
|
|
472
|
+
];
|
|
473
|
+
const selectedRow = lines.findIndex((line) => line.startsWith("> "));
|
|
474
|
+
const decisionRow = lines.findIndex((line) => line.includes("Reject") || line.includes("Approve"));
|
|
475
|
+
return { lines, offset: start, capacity, filterRow: (selectedRow >= 0 ? selectedRow : Math.max(0, decisionRow)) + 1 };
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// packages/core/src/cli/console/console-input.ts
|
|
479
|
+
var CONSOLE_COMMANDS = consoleCommands().map(([name]) => name);
|
|
480
|
+
var MAX_CONSOLE_INPUT_BYTES = 64 * 1024;
|
|
481
|
+
var interrupted = () => Object.assign(new Error("Input interrupted."), { name: "AbortError" });
|
|
482
|
+
var incompleteTerminalSequence = (sequence) => {
|
|
483
|
+
if (sequence.length > 32)
|
|
484
|
+
return false;
|
|
485
|
+
if (sequence === "\x1B" || sequence === "\x1BO")
|
|
486
|
+
return true;
|
|
487
|
+
if (!sequence.startsWith("\x1B["))
|
|
488
|
+
return false;
|
|
489
|
+
const body = sequence.slice(2);
|
|
490
|
+
if (!body)
|
|
491
|
+
return true;
|
|
492
|
+
for (let index = 0;index < body.length - 1; index += 1) {
|
|
493
|
+
const code = body.charCodeAt(index);
|
|
494
|
+
if (code < 32 || code > 63)
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
const last = body.charCodeAt(body.length - 1);
|
|
498
|
+
return last < 64 || last > 126;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
class ConsoleInput {
|
|
502
|
+
input;
|
|
503
|
+
output;
|
|
504
|
+
terminal;
|
|
505
|
+
mode;
|
|
506
|
+
background = false;
|
|
507
|
+
backgroundDraft = "";
|
|
508
|
+
queued = [];
|
|
509
|
+
queueNotice = "";
|
|
510
|
+
queueEnabled = true;
|
|
511
|
+
hidden;
|
|
512
|
+
reader;
|
|
513
|
+
keyboard = new PassThrough;
|
|
514
|
+
display;
|
|
515
|
+
decoder = new StringDecoder("utf8");
|
|
516
|
+
escape = "";
|
|
517
|
+
clipboard;
|
|
518
|
+
clipboardBytes = 0;
|
|
519
|
+
clipboardAllowed = false;
|
|
520
|
+
draftWasPaste = false;
|
|
521
|
+
lastSubmissionWasPaste = false;
|
|
522
|
+
closed = false;
|
|
523
|
+
completeCommands = false;
|
|
524
|
+
history = [];
|
|
525
|
+
historyPosition = -1;
|
|
526
|
+
historyDraft = "";
|
|
527
|
+
historyDraftWasPaste = false;
|
|
528
|
+
pending;
|
|
529
|
+
focusState;
|
|
530
|
+
paste;
|
|
531
|
+
onInterrupt;
|
|
532
|
+
constructor(input, output, terminal = true, mode = "direct") {
|
|
533
|
+
this.input = input;
|
|
534
|
+
this.output = output;
|
|
535
|
+
this.terminal = terminal;
|
|
536
|
+
this.mode = mode;
|
|
537
|
+
const source = terminal ? this.keyboard : input;
|
|
538
|
+
this.display = new Writable({ write: (chunk, encoding, callback) => {
|
|
539
|
+
if (!this.reviewing && !(this.background && !this.pending))
|
|
540
|
+
output.write(chunk, encoding);
|
|
541
|
+
callback();
|
|
542
|
+
} });
|
|
543
|
+
Object.defineProperty(this.display, "columns", {
|
|
544
|
+
get: () => output.columns
|
|
545
|
+
});
|
|
546
|
+
Object.assign(this.keyboard, { isTTY: terminal, setRawMode: (enabled) => {
|
|
547
|
+
input.setRawMode?.(enabled);
|
|
548
|
+
} });
|
|
549
|
+
this.reader = createInterface({
|
|
550
|
+
input: source,
|
|
551
|
+
output: terminal ? this.display : output,
|
|
552
|
+
terminal,
|
|
553
|
+
historySize: 0,
|
|
554
|
+
completer: (line) => this.pending && this.completeCommands ? [consoleCommands(this.mode).map(([name]) => name).filter((name) => name.startsWith(line)), line] : [[], line]
|
|
555
|
+
});
|
|
556
|
+
this.reader.setPrompt("");
|
|
557
|
+
source.prependListener("keypress", this.onKeypress);
|
|
558
|
+
this.reader.on("line", (line) => {
|
|
559
|
+
if (this.background && !this.pending) {
|
|
560
|
+
if (line.trim() && Buffer.byteLength(line) <= MAX_CONSOLE_INPUT_BYTES) {
|
|
561
|
+
if (this.queued.length < 8 && this.queued.reduce((n, item) => n + Buffer.byteLength(item), 0) + Buffer.byteLength(line) <= 256 * 1024) {
|
|
562
|
+
this.queued.push(line);
|
|
563
|
+
this.backgroundDraft = "";
|
|
564
|
+
this.queueNotice = "";
|
|
565
|
+
} else {
|
|
566
|
+
this.backgroundDraft = line;
|
|
567
|
+
this.queueNotice = "Queue full; draft retained";
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
this.draftWasPaste = false;
|
|
571
|
+
queueMicrotask(() => {
|
|
572
|
+
if (this.background && this.backgroundDraft)
|
|
573
|
+
Object.assign(this.reader, { line: this.backgroundDraft, cursor: this.backgroundDraft.length });
|
|
574
|
+
});
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (this.paste) {
|
|
578
|
+
const paste = this.paste;
|
|
579
|
+
if (line === ".end") {
|
|
580
|
+
this.paste = undefined;
|
|
581
|
+
paste.resolve(paste.lines.join(`
|
|
582
|
+
`));
|
|
583
|
+
} else {
|
|
584
|
+
paste.bytes += Buffer.byteLength(line) + 1;
|
|
585
|
+
if (paste.bytes > MAX_CONSOLE_INPUT_BYTES) {
|
|
586
|
+
this.paste = undefined;
|
|
587
|
+
paste.reject(new Error("Multiline input exceeds 64 KiB; draft discarded."));
|
|
588
|
+
} else
|
|
589
|
+
paste.lines.push(line);
|
|
590
|
+
}
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const pending = this.pending;
|
|
594
|
+
this.pending = undefined;
|
|
595
|
+
this.lastSubmissionWasPaste = this.draftWasPaste;
|
|
596
|
+
this.draftWasPaste = false;
|
|
597
|
+
this.reader.setPrompt("");
|
|
598
|
+
if (Buffer.byteLength(line) > MAX_CONSOLE_INPUT_BYTES) {
|
|
599
|
+
pending?.reject(new Error("Input exceeds 64 KiB."));
|
|
600
|
+
} else
|
|
601
|
+
pending?.resolve(line);
|
|
602
|
+
});
|
|
603
|
+
this.reader.on("SIGINT", () => this.interrupt());
|
|
604
|
+
this.reader.on("close", () => {
|
|
605
|
+
this.finishSecret(false);
|
|
606
|
+
this.closed = true;
|
|
607
|
+
if (terminal) {
|
|
608
|
+
output.write("\x1B[?2004l");
|
|
609
|
+
input.off("data", this.onData);
|
|
610
|
+
input.off("end", this.onEnd);
|
|
611
|
+
output.off("resize", this.onResize);
|
|
612
|
+
input.pause();
|
|
613
|
+
}
|
|
614
|
+
this.interrupt();
|
|
615
|
+
});
|
|
616
|
+
if (terminal) {
|
|
617
|
+
output.write("\x1B[?2004h");
|
|
618
|
+
input.on("data", this.onData);
|
|
619
|
+
input.on("end", this.onEnd);
|
|
620
|
+
output.on("resize", this.onResize);
|
|
621
|
+
input.resume();
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
selection;
|
|
625
|
+
reviewing;
|
|
626
|
+
reviewOffset = 0;
|
|
627
|
+
reviewPage = 1;
|
|
628
|
+
reviewNotice;
|
|
629
|
+
reviewHunks = [];
|
|
630
|
+
manualRequest;
|
|
631
|
+
reviewWrapped;
|
|
632
|
+
reviewLinesDrawn = 0;
|
|
633
|
+
selectionMatches() {
|
|
634
|
+
const indexed = this.selection?.items.map((item, index) => ({ ...item, index })) ?? [];
|
|
635
|
+
if (this.reviewing)
|
|
636
|
+
return indexed;
|
|
637
|
+
const query = this.reader.line.toLowerCase();
|
|
638
|
+
return indexed.filter((item) => `${item.label} ${item.detail ?? ""}`.toLowerCase().includes(query));
|
|
639
|
+
}
|
|
640
|
+
finishSelection(accept) {
|
|
641
|
+
const selected = accept ? this.selectionMatches()[this.menuSelection] : undefined;
|
|
642
|
+
this.hideMenu();
|
|
643
|
+
const pending = this.pending;
|
|
644
|
+
this.pending = undefined;
|
|
645
|
+
this.draftWasPaste = false;
|
|
646
|
+
this.reader.setPrompt("");
|
|
647
|
+
this.output.write(`
|
|
648
|
+
`);
|
|
649
|
+
pending?.resolve(selected ? String(selected.index) : "");
|
|
650
|
+
}
|
|
651
|
+
async select(title, items) {
|
|
652
|
+
if (!items.length) {
|
|
653
|
+
this.output.write(`No matches.
|
|
654
|
+
`);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (!this.terminal || process.env.TERM === "dumb")
|
|
658
|
+
return chooseConsoleItem(title, items, {
|
|
659
|
+
write: (text) => {
|
|
660
|
+
this.output.write(text);
|
|
661
|
+
},
|
|
662
|
+
ask: (prompt) => this.question(prompt)
|
|
663
|
+
});
|
|
664
|
+
this.selection = { title, items };
|
|
665
|
+
if (!this.reviewing)
|
|
666
|
+
this.menuSelection = 0;
|
|
667
|
+
try {
|
|
668
|
+
if (!this.reviewing)
|
|
669
|
+
this.output.write(`
|
|
670
|
+
${sanitizeTerminalText(title)}
|
|
671
|
+
`);
|
|
672
|
+
const answer = this.question(this.reviewing ? "" : "Filter > ", true);
|
|
673
|
+
this.renderMenu();
|
|
674
|
+
const value = await answer;
|
|
675
|
+
return value === "" ? undefined : items[Number(value)]?.value;
|
|
676
|
+
} finally {
|
|
677
|
+
this.hideMenu();
|
|
678
|
+
this.selection = undefined;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
onManual(handler) {
|
|
682
|
+
this.manualRequest = handler;
|
|
683
|
+
}
|
|
684
|
+
async review(review, items) {
|
|
685
|
+
if (!this.terminal || process.env.TERM === "dumb" || (this.output.rows ?? 24) < 24 || (this.output.columns ?? 80) < 32) {
|
|
686
|
+
this.output.write(revealInvisibleText(review.body) + `
|
|
687
|
+
`);
|
|
688
|
+
return this.select(review.title, items);
|
|
689
|
+
}
|
|
690
|
+
this.hideMenu();
|
|
691
|
+
this.clearQueue();
|
|
692
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
693
|
+
this.reviewing = review;
|
|
694
|
+
this.reviewOffset = 0;
|
|
695
|
+
this.reviewHunks = [];
|
|
696
|
+
this.menuSelection = -1;
|
|
697
|
+
this.reviewNotice = undefined;
|
|
698
|
+
this.reviewWrapped = undefined;
|
|
699
|
+
this.reviewLinesDrawn = 0;
|
|
700
|
+
try {
|
|
701
|
+
return await this.select(review.title, items);
|
|
702
|
+
} finally {
|
|
703
|
+
this.eraseReview();
|
|
704
|
+
this.reviewing = undefined;
|
|
705
|
+
this.reviewWrapped = undefined;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
eraseReview() {
|
|
709
|
+
if (!this.reviewLinesDrawn)
|
|
710
|
+
return;
|
|
711
|
+
const up = this.reviewLinesDrawn - 1;
|
|
712
|
+
this.output.write((up > 0 ? `\x1B[${up}A` : "") + "\r\x1B[J");
|
|
713
|
+
this.reviewLinesDrawn = 0;
|
|
714
|
+
}
|
|
715
|
+
styleReviewLine(line) {
|
|
716
|
+
const gutter = line.length > 14 && line[13] === " " && (line[14] === "+" || line[14] === "-") ? line[14] : "";
|
|
717
|
+
const mark = line.startsWith("+") || line.startsWith("-") || line.startsWith("@@") ? line[0] : gutter;
|
|
718
|
+
const code = line.startsWith("( Z )") ? `1;${terminalToneCode("accent")}` : mark === "+" ? terminalToneCode("added") : mark === "-" ? terminalToneCode("removed") : mark === "@" || line.startsWith("@@") ? terminalToneCode("info") : line.startsWith("> ") || line.startsWith("Waiting for your decision") ? `1;${terminalToneCode("pending")}` : "";
|
|
719
|
+
const color = terminalSupportsColor(this.terminal);
|
|
720
|
+
return color && code ? `\x1B[${code}m${line}\x1B[0m` : line;
|
|
721
|
+
}
|
|
722
|
+
paintReview(lines) {
|
|
723
|
+
const screen = this.output.rows ?? 24;
|
|
724
|
+
const painted = lines.map((line) => this.styleReviewLine(line) + "\x1B[K");
|
|
725
|
+
const fills = lines.length >= screen;
|
|
726
|
+
if (this.reviewLinesDrawn === 0 && fills)
|
|
727
|
+
this.output.write("\x1B[H" + painted.join(`\r
|
|
728
|
+
`) + "\x1B[J");
|
|
729
|
+
else if (this.reviewLinesDrawn === 0)
|
|
730
|
+
this.output.write(painted.join(`\r
|
|
731
|
+
`));
|
|
732
|
+
else {
|
|
733
|
+
const up = this.reviewLinesDrawn - 1;
|
|
734
|
+
this.output.write((up > 0 ? `\x1B[${up}A` : "") + "\r" + painted.join(`\r
|
|
735
|
+
`) + "\x1B[J");
|
|
736
|
+
}
|
|
737
|
+
this.reviewLinesDrawn = lines.length;
|
|
738
|
+
}
|
|
739
|
+
taskPrompt = "";
|
|
740
|
+
shortcutsShown = false;
|
|
741
|
+
historySearch;
|
|
742
|
+
historyMatches() {
|
|
743
|
+
const query = this.reader.line.toLowerCase();
|
|
744
|
+
return this.history.filter((entry) => entry.text.toLowerCase().includes(query));
|
|
745
|
+
}
|
|
746
|
+
finishHistorySearch(accept) {
|
|
747
|
+
const saved = this.historySearch;
|
|
748
|
+
if (!saved)
|
|
749
|
+
return;
|
|
750
|
+
const selected = accept ? this.historyMatches()[this.menuSelection] : undefined;
|
|
751
|
+
this.hideMenu();
|
|
752
|
+
this.historySearch = undefined;
|
|
753
|
+
const line = selected?.text ?? saved.draft;
|
|
754
|
+
this.draftWasPaste = selected?.literal ?? saved.literal;
|
|
755
|
+
Object.assign(this.reader, { line, cursor: selected ? line.length : saved.cursor });
|
|
756
|
+
this.reader.setPrompt(this.taskPrompt);
|
|
757
|
+
this.reader.prompt(true);
|
|
758
|
+
this.menuDismissed = true;
|
|
759
|
+
}
|
|
760
|
+
menuVisible = false;
|
|
761
|
+
placeholderVisible = false;
|
|
762
|
+
focusComposer = false;
|
|
763
|
+
menuSelection = 0;
|
|
764
|
+
menuQuery = "";
|
|
765
|
+
menuDismissed = false;
|
|
766
|
+
escapeMenuTimer;
|
|
767
|
+
standaloneMenuEscape = false;
|
|
768
|
+
hideMenu() {
|
|
769
|
+
if (this.reviewing)
|
|
770
|
+
return;
|
|
771
|
+
if (this.placeholderVisible)
|
|
772
|
+
this.output.write("\x1B[K");
|
|
773
|
+
if (this.menuVisible) {
|
|
774
|
+
const { rows } = this.draftPosition();
|
|
775
|
+
this.output.write(`\x1B7${rows ? `\x1B[${rows}B` : ""}\r
|
|
776
|
+
\x1B[J\x1B8`);
|
|
777
|
+
}
|
|
778
|
+
this.menuVisible = false;
|
|
779
|
+
this.placeholderVisible = false;
|
|
780
|
+
}
|
|
781
|
+
draftPosition() {
|
|
782
|
+
const position = this.reader.getCursorPos();
|
|
783
|
+
const cursor = this.reader.cursor;
|
|
784
|
+
Object.assign(this.reader, { cursor: this.reader.line.length });
|
|
785
|
+
const end = this.reader.getCursorPos();
|
|
786
|
+
Object.assign(this.reader, { cursor });
|
|
787
|
+
return { column: position.cols, rows: Math.max(0, end.rows - position.rows) };
|
|
788
|
+
}
|
|
789
|
+
showOverlay(lines, placeholder) {
|
|
790
|
+
const { column, rows } = this.draftPosition();
|
|
791
|
+
const reserve = rows + lines.length;
|
|
792
|
+
const height = this.output.rows ?? 24;
|
|
793
|
+
if (reserve >= height)
|
|
794
|
+
return;
|
|
795
|
+
this.output.write(`
|
|
796
|
+
`.repeat(reserve) + `\x1B[${reserve}A\x1B[${column + 1}G`);
|
|
797
|
+
this.output.write("\x1B7" + (placeholder ?? "") + (rows ? `\x1B[${rows}B` : "") + lines.map((line) => `\r
|
|
798
|
+
` + line).join("") + "\x1B8");
|
|
799
|
+
this.menuVisible = true;
|
|
800
|
+
this.placeholderVisible = Boolean(placeholder);
|
|
801
|
+
}
|
|
802
|
+
renderFocus() {
|
|
803
|
+
if (!this.focusComposer || this.selection || this.historySearch)
|
|
804
|
+
return;
|
|
805
|
+
const rows = this.output.rows ?? 24;
|
|
806
|
+
if (rows < 6)
|
|
807
|
+
return;
|
|
808
|
+
const columns = this.output.columns ?? 80;
|
|
809
|
+
const color = terminalSupportsColor(this.terminal);
|
|
810
|
+
this.showOverlay(formatComposerFooter(columns, color, this.mode === "direct" ? this.focusState : undefined), !this.reader.line && columns >= 40 ? formatComposerPlaceholder(columns, color) : undefined);
|
|
811
|
+
}
|
|
812
|
+
renderMenu() {
|
|
813
|
+
if (this.reviewing && this.selection && this.pending) {
|
|
814
|
+
if (!this.reviewing && this.menuQuery !== this.reader.line) {
|
|
815
|
+
this.menuSelection = 0;
|
|
816
|
+
this.menuQuery = this.reader.line;
|
|
817
|
+
}
|
|
818
|
+
const matches2 = this.selectionMatches();
|
|
819
|
+
if (this.menuSelection >= matches2.length)
|
|
820
|
+
this.menuSelection = matches2.length ? matches2.length - 1 : -1;
|
|
821
|
+
const columns2 = this.output.columns ?? 80;
|
|
822
|
+
const width = consoleWidth(columns2);
|
|
823
|
+
let wrappedLines;
|
|
824
|
+
if (this.reviewing.layout) {
|
|
825
|
+
const laid = this.reviewing.layout(width);
|
|
826
|
+
this.reviewHunks = laid.hunks;
|
|
827
|
+
wrappedLines = laid.lines;
|
|
828
|
+
} else {
|
|
829
|
+
this.reviewHunks = [];
|
|
830
|
+
if (!this.reviewWrapped || this.reviewWrapped.columns !== columns2)
|
|
831
|
+
this.reviewWrapped = {
|
|
832
|
+
columns: columns2,
|
|
833
|
+
lines: consoleLines(this.reviewing.body, width)
|
|
834
|
+
};
|
|
835
|
+
wrappedLines = this.reviewWrapped.lines;
|
|
836
|
+
}
|
|
837
|
+
const frame = reviewFrame({ ...this.reviewing, ...this.reviewNotice ? { notice: this.reviewNotice } : {} }, matches2, this.menuSelection, this.reader.line, this.reviewOffset, columns2, this.output.rows ?? 24, wrappedLines);
|
|
838
|
+
this.reviewOffset = frame.offset;
|
|
839
|
+
this.reviewPage = frame.capacity;
|
|
840
|
+
this.paintReview(frame.lines);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
this.hideMenu();
|
|
844
|
+
const query = this.reader.line;
|
|
845
|
+
if (query !== this.menuQuery) {
|
|
846
|
+
this.menuQuery = query;
|
|
847
|
+
this.menuSelection = 0;
|
|
848
|
+
this.menuDismissed = false;
|
|
849
|
+
}
|
|
850
|
+
if (!this.terminal || process.env.TERM === "dumb" || !this.pending || !this.completeCommands)
|
|
851
|
+
return;
|
|
852
|
+
if (!this.selection && !this.historySearch && (this.draftWasPaste || this.menuDismissed || !/^\/[^\s]*$/.test(query))) {
|
|
853
|
+
this.renderFocus();
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
const matches = this.selection ? this.selectionMatches().map((item) => [item.label, item.detail ?? ""]) : this.historySearch ? this.historyMatches().map((entry) => [consoleLabel(entry.text, 64), ""]) : searchConsoleCommands(query, this.mode).map(([name, description]) => [name, description]);
|
|
857
|
+
if (!matches.length && !this.historySearch && !this.selection) {
|
|
858
|
+
this.renderFocus();
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.menuSelection = Math.max(0, Math.min(this.menuSelection, matches.length - 1));
|
|
862
|
+
const rows = this.output.rows ?? 24;
|
|
863
|
+
if (rows < 6)
|
|
864
|
+
return;
|
|
865
|
+
const pageSize = Math.min(5, rows - 4);
|
|
866
|
+
const start = Math.floor(this.menuSelection / pageSize) * pageSize;
|
|
867
|
+
const columns = Math.max(10, this.output.columns ?? 80);
|
|
868
|
+
const lines = matches.slice(start, start + pageSize).map(([name, description], i) => `${i + start === this.menuSelection ? ">" : " "} ${name.padEnd(14)} ${description}`.slice(0, columns - 1));
|
|
869
|
+
if (!matches.length)
|
|
870
|
+
lines.push(" No matches; edit the filter".slice(0, columns - 1));
|
|
871
|
+
lines.push((this.selection ? " ↑↓ navigate · Enter choose · Esc back" : this.historySearch ? " ↑↓ select · Enter restore · Esc cancel" : ` ${this.menuSelection + 1}/${matches.length} · ↑↓ select · Tab insert · Esc close`).slice(0, columns - 1));
|
|
872
|
+
this.showOverlay(lines);
|
|
873
|
+
}
|
|
874
|
+
onEnd = () => {
|
|
875
|
+
this.finishSecret(false);
|
|
876
|
+
this.keyboard.end();
|
|
877
|
+
};
|
|
878
|
+
onResize = () => {
|
|
879
|
+
if (this.pending || this.paste) {
|
|
880
|
+
this.hideMenu();
|
|
881
|
+
this.display.emit("resize");
|
|
882
|
+
this.renderMenu();
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
finishSecret(accept) {
|
|
886
|
+
const hidden = this.hidden;
|
|
887
|
+
if (!hidden)
|
|
888
|
+
return;
|
|
889
|
+
this.hidden = undefined;
|
|
890
|
+
this.output.write(`
|
|
891
|
+
`);
|
|
892
|
+
const value = hidden.value;
|
|
893
|
+
hidden.value = "";
|
|
894
|
+
if (accept)
|
|
895
|
+
hidden.resolve(value);
|
|
896
|
+
else
|
|
897
|
+
hidden.reject(interrupted());
|
|
898
|
+
}
|
|
899
|
+
secret(prompt) {
|
|
900
|
+
if (!this.terminal || this.closed || this.pending || this.paste || this.hidden) {
|
|
901
|
+
return Promise.reject(new Error("API key entry requires an idle interactive terminal."));
|
|
902
|
+
}
|
|
903
|
+
this.hideMenu();
|
|
904
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
905
|
+
this.escape = "";
|
|
906
|
+
this.output.write(prompt);
|
|
907
|
+
return new Promise((resolve, reject) => {
|
|
908
|
+
this.hidden = { value: "", escape: "", pasted: false, resolve, reject };
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
onData = (chunk) => {
|
|
912
|
+
if (this.hidden) {
|
|
913
|
+
const text2 = typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
914
|
+
for (const character of text2) {
|
|
915
|
+
const hidden = this.hidden;
|
|
916
|
+
if (!hidden)
|
|
917
|
+
break;
|
|
918
|
+
if (character === "\x03" || character === "\x04") {
|
|
919
|
+
this.finishSecret(false);
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
if (character === "\x1B" || hidden.escape) {
|
|
923
|
+
hidden.escape += character;
|
|
924
|
+
const marker = hidden.pasted ? "\x1B[201~" : "\x1B[200~";
|
|
925
|
+
if (!marker.startsWith(hidden.escape)) {
|
|
926
|
+
this.finishSecret(false);
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
if (hidden.escape === marker) {
|
|
930
|
+
hidden.pasted = !hidden.pasted;
|
|
931
|
+
hidden.escape = "";
|
|
932
|
+
}
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (!hidden.pasted && (character === "\r" || character === `
|
|
936
|
+
`)) {
|
|
937
|
+
this.finishSecret(true);
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
if (!hidden.pasted && (character === "" || character === "\b")) {
|
|
941
|
+
hidden.value = hidden.value.slice(0, -1);
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (!/^[\x21-\x7e]$/.test(character) || hidden.value.length >= 8192) {
|
|
945
|
+
this.finishSecret(false);
|
|
946
|
+
break;
|
|
947
|
+
}
|
|
948
|
+
hidden.value += character;
|
|
949
|
+
}
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
clearTimeout(this.escapeMenuTimer);
|
|
953
|
+
const text = typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
954
|
+
for (const character of text) {
|
|
955
|
+
if (this.standaloneMenuEscape) {
|
|
956
|
+
if (character !== "[")
|
|
957
|
+
this.escape = "";
|
|
958
|
+
this.standaloneMenuEscape = false;
|
|
959
|
+
}
|
|
960
|
+
if (character === "\x03") {
|
|
961
|
+
if (this.selection) {
|
|
962
|
+
this.escape = "";
|
|
963
|
+
this.finishSelection(false);
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
this.escape = "";
|
|
967
|
+
this.clipboard = undefined;
|
|
968
|
+
this.interrupt();
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
this.escape += character;
|
|
972
|
+
const marker = this.clipboard === undefined ? "\x1B[200~" : "\x1B[201~";
|
|
973
|
+
if (marker.startsWith(this.escape)) {
|
|
974
|
+
if (this.escape !== marker) {
|
|
975
|
+
if (this.escape === "\x1B" && (this.menuVisible || this.historySearch || this.selection)) {
|
|
976
|
+
this.escapeMenuTimer = setTimeout(() => {
|
|
977
|
+
if (this.escape !== "\x1B")
|
|
978
|
+
return;
|
|
979
|
+
if (this.selection)
|
|
980
|
+
this.finishSelection(false);
|
|
981
|
+
else if (this.historySearch)
|
|
982
|
+
this.finishHistorySearch(false);
|
|
983
|
+
this.hideMenu();
|
|
984
|
+
this.menuDismissed = true;
|
|
985
|
+
this.standaloneMenuEscape = true;
|
|
986
|
+
}, 100);
|
|
987
|
+
}
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
this.escape = "";
|
|
991
|
+
if (this.clipboard === undefined) {
|
|
992
|
+
this.hideMenu();
|
|
993
|
+
this.clipboard = "";
|
|
994
|
+
this.clipboardBytes = 0;
|
|
995
|
+
this.clipboardAllowed = Boolean(this.pending && this.completeCommands && !this.selection) || Boolean(this.paste) || this.background;
|
|
996
|
+
} else {
|
|
997
|
+
const clipboard = this.clipboard;
|
|
998
|
+
this.clipboard = undefined;
|
|
999
|
+
if (this.clipboardAllowed && this.clipboardBytes <= MAX_CONSOLE_INPUT_BYTES) {
|
|
1000
|
+
const safe = sanitizeTerminalText(clipboard.replace(/\r\n?/g, `
|
|
1001
|
+
`));
|
|
1002
|
+
if (this.paste) {
|
|
1003
|
+
if (this.paste.bytes + Buffer.byteLength(safe) + 1 <= MAX_CONSOLE_INPUT_BYTES) {
|
|
1004
|
+
this.paste.lines.push(safe);
|
|
1005
|
+
this.paste.bytes += Buffer.byteLength(safe) + 1;
|
|
1006
|
+
this.output.write(safe + `
|
|
1007
|
+
`);
|
|
1008
|
+
} else
|
|
1009
|
+
this.output.write(`
|
|
1010
|
+
Paste exceeds 64 KiB; clipboard discarded.
|
|
1011
|
+
`);
|
|
1012
|
+
} else if (this.pending && this.completeCommands || this.background) {
|
|
1013
|
+
this.insert(safe);
|
|
1014
|
+
this.draftWasPaste = true;
|
|
1015
|
+
}
|
|
1016
|
+
} else if (this.clipboardAllowed)
|
|
1017
|
+
this.output.write(`
|
|
1018
|
+
Paste exceeds 64 KiB; clipboard discarded.
|
|
1019
|
+
`);
|
|
1020
|
+
else if (this.reviewing)
|
|
1021
|
+
this.reviewNotice = "Paste ignored · fresh keys required";
|
|
1022
|
+
this.renderMenu();
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
if (incompleteTerminalSequence(this.escape))
|
|
1028
|
+
continue;
|
|
1029
|
+
const plain = this.escape;
|
|
1030
|
+
this.escape = "";
|
|
1031
|
+
if (this.clipboard !== undefined) {
|
|
1032
|
+
this.clipboardBytes += Buffer.byteLength(plain);
|
|
1033
|
+
if (this.clipboardAllowed && this.clipboardBytes <= MAX_CONSOLE_INPUT_BYTES)
|
|
1034
|
+
this.clipboard += plain;
|
|
1035
|
+
} else if (this.pending || this.paste || this.background) {
|
|
1036
|
+
this.reviewNotice = undefined;
|
|
1037
|
+
this.hideMenu();
|
|
1038
|
+
if (this.reviewing && plain.length === 1 && plain !== `
|
|
1039
|
+
` && plain !== "\r") {
|
|
1040
|
+
if ((plain === "n" || plain === "p") && this.reviewHunks.length) {
|
|
1041
|
+
const current = this.reviewOffset;
|
|
1042
|
+
const target = plain === "n" ? this.reviewHunks.find((hunk) => hunk > current) ?? this.reviewHunks[0] : [...this.reviewHunks].reverse().find((hunk) => hunk < current) ?? this.reviewHunks.at(-1);
|
|
1043
|
+
this.reviewOffset = target ?? 0;
|
|
1044
|
+
this.renderMenu();
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
if (plain === "m" && this.manualRequest) {
|
|
1048
|
+
this.manualRequest();
|
|
1049
|
+
this.reviewNotice = "Approvals are manual. This change still needs a decision.";
|
|
1050
|
+
this.renderMenu();
|
|
1051
|
+
continue;
|
|
1052
|
+
}
|
|
1053
|
+
if (/^[a-z]$/.test(plain)) {
|
|
1054
|
+
const index = this.selection?.items.findIndex((item) => item.key === plain) ?? -1;
|
|
1055
|
+
if (index >= 0) {
|
|
1056
|
+
this.menuSelection = index;
|
|
1057
|
+
this.finishSelection(true);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
this.renderMenu();
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
if (this.selection && !/[\u0000-\u001f\u007f]/.test(plain) && Buffer.byteLength(this.reader.line) + Buffer.byteLength(plain) > MAX_CONSOLE_INPUT_BYTES)
|
|
1064
|
+
continue;
|
|
1065
|
+
if (this.selection && (plain === `
|
|
1066
|
+
` || plain === "\r")) {
|
|
1067
|
+
if (this.reviewing && this.menuSelection < 0)
|
|
1068
|
+
this.reviewNotice = "Highlight an action with the arrow keys. Enter does not approve or reject yet.";
|
|
1069
|
+
else if (this.selectionMatches().length)
|
|
1070
|
+
this.finishSelection(true);
|
|
1071
|
+
} else if (plain === "?" && !this.selection && this.pending && this.completeCommands && !this.historySearch && !this.reader.line && !this.shortcutsShown) {
|
|
1072
|
+
this.shortcutsShown = true;
|
|
1073
|
+
this.output.write(`
|
|
1074
|
+
` + CONSOLE_SHORTCUTS + `
|
|
1075
|
+
`);
|
|
1076
|
+
this.reader.prompt(true);
|
|
1077
|
+
} else {
|
|
1078
|
+
const matches = this.pending && this.completeCommands && !this.historySearch && !this.draftWasPaste && !this.menuDismissed && /^\/[^\s]*$/.test(this.reader.line) ? searchConsoleCommands(this.reader.line, this.mode) : [];
|
|
1079
|
+
const selected = matches[this.menuSelection % Math.max(1, matches.length)]?.[0];
|
|
1080
|
+
if ((plain === `
|
|
1081
|
+
` || plain === "\r") && selected && selected !== this.reader.line) {
|
|
1082
|
+
Object.assign(this.reader, { line: selected + " ", cursor: selected.length + 1 });
|
|
1083
|
+
this.reader.prompt(true);
|
|
1084
|
+
} else
|
|
1085
|
+
this.keyboard.write(plain);
|
|
1086
|
+
}
|
|
1087
|
+
this.renderMenu();
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
insert(text) {
|
|
1092
|
+
const line = this.reader.line;
|
|
1093
|
+
if (Buffer.byteLength(line) + Buffer.byteLength(text) > MAX_CONSOLE_INPUT_BYTES) {
|
|
1094
|
+
this.output.write(`
|
|
1095
|
+
Input exceeds 64 KiB; insertion discarded.
|
|
1096
|
+
`);
|
|
1097
|
+
} else {
|
|
1098
|
+
const cursor = this.reader.cursor;
|
|
1099
|
+
Object.assign(this.reader, { line: line.slice(0, cursor) + text + line.slice(cursor), cursor: cursor + text.length });
|
|
1100
|
+
}
|
|
1101
|
+
this.reader.prompt(true);
|
|
1102
|
+
}
|
|
1103
|
+
onKeypress = (_text, key) => {
|
|
1104
|
+
if (this.background && !this.pending) {
|
|
1105
|
+
if (key.name === "up" && !this.reader.line && this.queued.length) {
|
|
1106
|
+
key.name = "console-queue";
|
|
1107
|
+
key.meta = true;
|
|
1108
|
+
const draft = this.queued.pop();
|
|
1109
|
+
Object.assign(this.reader, { line: draft, cursor: draft.length });
|
|
1110
|
+
} else if (key.meta && ["return", "enter"].includes(key.name ?? "")) {
|
|
1111
|
+
key.name = "console-newline";
|
|
1112
|
+
this.insert(`
|
|
1113
|
+
`);
|
|
1114
|
+
} else if (_text && !key.ctrl && !key.meta && Buffer.byteLength(this.reader.line) + Buffer.byteLength(_text) > MAX_CONSOLE_INPUT_BYTES) {
|
|
1115
|
+
key.name = "console-input-limit";
|
|
1116
|
+
key.meta = true;
|
|
1117
|
+
}
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
if (!this.pending || !this.completeCommands)
|
|
1121
|
+
return;
|
|
1122
|
+
if (this.selection) {
|
|
1123
|
+
if (this.reviewing && ["pageup", "pagedown"].includes(key.name ?? "")) {
|
|
1124
|
+
this.reviewOffset += key.name === "pageup" ? -this.reviewPage : this.reviewPage;
|
|
1125
|
+
key.name = "console-review";
|
|
1126
|
+
key.meta = true;
|
|
1127
|
+
} else if (["up", "down", "tab"].includes(key.name ?? "")) {
|
|
1128
|
+
const previous = key.name === "up";
|
|
1129
|
+
key.name = "console-select";
|
|
1130
|
+
key.meta = true;
|
|
1131
|
+
const count = Math.max(1, this.selectionMatches().length);
|
|
1132
|
+
if (this.reviewing && this.menuSelection < 0)
|
|
1133
|
+
this.menuSelection = previous ? count - 1 : 0;
|
|
1134
|
+
else
|
|
1135
|
+
this.menuSelection = (this.menuSelection + (previous ? -1 : 1) + count) % count;
|
|
1136
|
+
} else if (key.ctrl && key.name === "r") {
|
|
1137
|
+
key.name = "console-select";
|
|
1138
|
+
key.ctrl = false;
|
|
1139
|
+
key.meta = true;
|
|
1140
|
+
}
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
if (key.ctrl && key.name === "r") {
|
|
1144
|
+
key.name = "console-search";
|
|
1145
|
+
key.ctrl = false;
|
|
1146
|
+
key.meta = true;
|
|
1147
|
+
if (!this.historySearch) {
|
|
1148
|
+
this.historySearch = { draft: this.reader.line, cursor: this.reader.cursor, literal: this.draftWasPaste };
|
|
1149
|
+
this.draftWasPaste = false;
|
|
1150
|
+
this.menuSelection = 0;
|
|
1151
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
1152
|
+
this.reader.setPrompt("history > ");
|
|
1153
|
+
this.reader.prompt(true);
|
|
1154
|
+
} else
|
|
1155
|
+
this.menuSelection = (this.menuSelection + 1) % Math.max(1, this.historyMatches().length);
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
if (this.historySearch && ["return", "enter", "tab", "up", "down"].includes(key.name ?? "")) {
|
|
1159
|
+
const name = key.name;
|
|
1160
|
+
key.name = "console-search";
|
|
1161
|
+
key.meta = true;
|
|
1162
|
+
if (["return", "enter", "tab"].includes(name))
|
|
1163
|
+
this.finishHistorySearch(true);
|
|
1164
|
+
else {
|
|
1165
|
+
const count = Math.max(1, this.historyMatches().length);
|
|
1166
|
+
this.menuSelection = (this.menuSelection + (name === "up" ? -1 : 1) + count) % count;
|
|
1167
|
+
}
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
const menu = !this.historySearch && !this.draftWasPaste && !this.menuDismissed && /^\/[^\s]*$/.test(this.reader.line) ? searchConsoleCommands(this.reader.line, this.mode) : [];
|
|
1171
|
+
if (menu.length && ["up", "down", "tab", "escape"].includes(key.name ?? "")) {
|
|
1172
|
+
const name = key.name;
|
|
1173
|
+
key.name = "console-menu";
|
|
1174
|
+
key.meta = true;
|
|
1175
|
+
if (name === "escape")
|
|
1176
|
+
this.menuDismissed = true;
|
|
1177
|
+
else if (name === "tab") {
|
|
1178
|
+
const selected = menu[this.menuSelection % menu.length][0];
|
|
1179
|
+
Object.assign(this.reader, { line: selected + " ", cursor: selected.length + 1 });
|
|
1180
|
+
this.reader.prompt(true);
|
|
1181
|
+
} else
|
|
1182
|
+
this.menuSelection = (this.menuSelection + (name === "up" ? -1 : 1) + menu.length) % menu.length;
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
if (_text && !key.ctrl && !key.meta && !/[\u0000-\u001f\u007f]/.test(_text) && Buffer.byteLength(this.reader.line) + Buffer.byteLength(_text) > MAX_CONSOLE_INPUT_BYTES) {
|
|
1186
|
+
key.name = "console-input-limit";
|
|
1187
|
+
key.meta = true;
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
if (key.name === "up" || key.name === "down") {
|
|
1191
|
+
const previous = key.name === "up";
|
|
1192
|
+
const line = this.reader.line;
|
|
1193
|
+
const cursor = this.reader.cursor;
|
|
1194
|
+
const lineStart = line.lastIndexOf(`
|
|
1195
|
+
`, cursor - 1) + 1;
|
|
1196
|
+
const lineEnd = line.indexOf(`
|
|
1197
|
+
`, cursor);
|
|
1198
|
+
if (previous && lineStart > 0 || !previous && lineEnd >= 0) {
|
|
1199
|
+
key.name = "console-cursor";
|
|
1200
|
+
key.meta = true;
|
|
1201
|
+
const column = cursor - lineStart;
|
|
1202
|
+
const targetStart = previous ? line.lastIndexOf(`
|
|
1203
|
+
`, lineStart - 2) + 1 : lineEnd + 1;
|
|
1204
|
+
const targetEnd = line.indexOf(`
|
|
1205
|
+
`, targetStart);
|
|
1206
|
+
const target = Math.min(targetStart + column, targetEnd < 0 ? line.length : targetEnd);
|
|
1207
|
+
Object.assign(this.reader, { line, cursor: target });
|
|
1208
|
+
this.reader.prompt(true);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
key.name = "console-history";
|
|
1212
|
+
key.meta = true;
|
|
1213
|
+
if (this.historyPosition === -1) {
|
|
1214
|
+
this.historyDraft = this.reader.line;
|
|
1215
|
+
this.historyDraftWasPaste = this.draftWasPaste;
|
|
1216
|
+
}
|
|
1217
|
+
this.historyPosition = previous ? Math.min(this.history.length - 1, this.historyPosition + 1) : Math.max(-1, this.historyPosition - 1);
|
|
1218
|
+
const entry = this.history[this.historyPosition];
|
|
1219
|
+
const historyLine = entry?.text ?? this.historyDraft;
|
|
1220
|
+
this.draftWasPaste = entry?.literal ?? this.historyDraftWasPaste;
|
|
1221
|
+
Object.assign(this.reader, { line: historyLine, cursor: historyLine.length });
|
|
1222
|
+
this.reader.prompt(true);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
if (!key.meta || key.name !== "return" && key.name !== "enter")
|
|
1226
|
+
return;
|
|
1227
|
+
key.name = "console-newline";
|
|
1228
|
+
this.insert(`
|
|
1229
|
+
`);
|
|
1230
|
+
};
|
|
1231
|
+
rememberPrompt(prompt, literal = false) {
|
|
1232
|
+
if (!prompt.trim() || !literal && prompt.startsWith("/") || Buffer.byteLength(prompt) > MAX_CONSOLE_INPUT_BYTES)
|
|
1233
|
+
return;
|
|
1234
|
+
this.history = [{ text: prompt, literal }, ...this.history.filter((entry) => entry.text !== prompt)].slice(0, 100);
|
|
1235
|
+
while (this.history.reduce((bytes, entry) => bytes + Buffer.byteLength(entry.text), 0) > 256 * 1024)
|
|
1236
|
+
this.history.pop();
|
|
1237
|
+
}
|
|
1238
|
+
startBackground() {
|
|
1239
|
+
if (!this.terminal || this.closed || this.pending || this.hidden || this.paste)
|
|
1240
|
+
return;
|
|
1241
|
+
this.background = true;
|
|
1242
|
+
this.completeCommands = false;
|
|
1243
|
+
this.reader.setPrompt("");
|
|
1244
|
+
Object.assign(this.reader, { line: this.backgroundDraft, cursor: this.backgroundDraft.length });
|
|
1245
|
+
}
|
|
1246
|
+
stopBackground() {
|
|
1247
|
+
if (!this.background)
|
|
1248
|
+
return;
|
|
1249
|
+
this.backgroundDraft = this.reader.line;
|
|
1250
|
+
this.background = false;
|
|
1251
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
1252
|
+
this.clipboardAllowed = false;
|
|
1253
|
+
}
|
|
1254
|
+
get backgroundStatus() {
|
|
1255
|
+
const draft = this.background ? this.reader.line : this.backgroundDraft;
|
|
1256
|
+
return this.queueNotice || `${this.queued.length} queued${draft ? ` · draft: ${consoleLabel(draft, 80)}` : " · type to draft, Enter queues"}`;
|
|
1257
|
+
}
|
|
1258
|
+
queueSummary() {
|
|
1259
|
+
const lines = this.queued.map((text, index) => `${index + 1}. ${consoleLabel(text, 240)}`);
|
|
1260
|
+
if (this.backgroundDraft)
|
|
1261
|
+
lines.push(`Draft: ${consoleLabel(this.backgroundDraft, 240)}`);
|
|
1262
|
+
return lines.length ? lines.join(`
|
|
1263
|
+
`) + `
|
|
1264
|
+
` : `No queued tasks or draft.
|
|
1265
|
+
`;
|
|
1266
|
+
}
|
|
1267
|
+
setQueueEnabled(enabled) {
|
|
1268
|
+
this.queueEnabled = enabled;
|
|
1269
|
+
}
|
|
1270
|
+
clearQueue() {
|
|
1271
|
+
this.queued = [];
|
|
1272
|
+
this.backgroundDraft = "";
|
|
1273
|
+
this.queueNotice = "";
|
|
1274
|
+
}
|
|
1275
|
+
clearHistory() {
|
|
1276
|
+
this.clearQueue();
|
|
1277
|
+
this.history = [];
|
|
1278
|
+
this.historyPosition = -1;
|
|
1279
|
+
this.historyDraft = "";
|
|
1280
|
+
}
|
|
1281
|
+
interrupt() {
|
|
1282
|
+
this.finishSecret(false);
|
|
1283
|
+
clearTimeout(this.escapeMenuTimer);
|
|
1284
|
+
this.standaloneMenuEscape = false;
|
|
1285
|
+
this.historySearch = undefined;
|
|
1286
|
+
this.hideMenu();
|
|
1287
|
+
this.pending?.reject(interrupted());
|
|
1288
|
+
this.paste?.reject(interrupted());
|
|
1289
|
+
this.pending = undefined;
|
|
1290
|
+
this.paste = undefined;
|
|
1291
|
+
this.draftWasPaste = false;
|
|
1292
|
+
this.reader.setPrompt("");
|
|
1293
|
+
if (this.terminal)
|
|
1294
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
1295
|
+
if (this.background) {
|
|
1296
|
+
this.backgroundDraft = "";
|
|
1297
|
+
this.queued = [];
|
|
1298
|
+
this.queueNotice = "Queued messages cleared after interruption";
|
|
1299
|
+
}
|
|
1300
|
+
this.onInterrupt?.();
|
|
1301
|
+
}
|
|
1302
|
+
get isClosed() {
|
|
1303
|
+
return this.closed;
|
|
1304
|
+
}
|
|
1305
|
+
compose(input) {
|
|
1306
|
+
this.stopBackground();
|
|
1307
|
+
if (this.queueEnabled && this.queued.length && !this.closed && !this.pending && !this.hidden && !this.paste) {
|
|
1308
|
+
const queued = this.queued.shift();
|
|
1309
|
+
this.lastSubmissionWasPaste = true;
|
|
1310
|
+
this.output.write(`
|
|
1311
|
+
Queued task > ${sanitizeTerminalText(queued)}
|
|
1312
|
+
`);
|
|
1313
|
+
return Promise.resolve(queued);
|
|
1314
|
+
}
|
|
1315
|
+
if (this.closed)
|
|
1316
|
+
return Promise.reject(interrupted());
|
|
1317
|
+
if (this.pending || this.paste || this.hidden)
|
|
1318
|
+
return Promise.reject(new Error("A console question is already active."));
|
|
1319
|
+
const columns = this.output.columns ?? 80;
|
|
1320
|
+
const color = terminalSupportsColor(this.terminal);
|
|
1321
|
+
const focus = this.mode === "direct";
|
|
1322
|
+
this.focusState = focus ? input : undefined;
|
|
1323
|
+
this.output.write(formatComposer(input, columns, color, focus ? "focus" : "legacy"));
|
|
1324
|
+
if (!this.terminal || process.env.TERM === "dumb") {
|
|
1325
|
+
const footer = formatComposerFooter(columns, color, focus ? input : undefined);
|
|
1326
|
+
this.output.write(footer.slice(1).join(`
|
|
1327
|
+
`) + `
|
|
1328
|
+
`);
|
|
1329
|
+
}
|
|
1330
|
+
const answer = this.question(focus ? "> " : `
|
|
1331
|
+
> `, true, true);
|
|
1332
|
+
if (this.backgroundDraft) {
|
|
1333
|
+
const draft = this.backgroundDraft;
|
|
1334
|
+
this.backgroundDraft = "";
|
|
1335
|
+
this.draftWasPaste = true;
|
|
1336
|
+
this.insert(draft);
|
|
1337
|
+
this.renderMenu();
|
|
1338
|
+
}
|
|
1339
|
+
return answer;
|
|
1340
|
+
}
|
|
1341
|
+
question(prompt, completeCommands = false, focus = false) {
|
|
1342
|
+
this.stopBackground();
|
|
1343
|
+
if (this.closed)
|
|
1344
|
+
return Promise.reject(interrupted());
|
|
1345
|
+
if (this.pending || this.paste || this.hidden)
|
|
1346
|
+
return Promise.reject(new Error("A console question is already active."));
|
|
1347
|
+
clearTimeout(this.escapeMenuTimer);
|
|
1348
|
+
this.escape = "";
|
|
1349
|
+
this.standaloneMenuEscape = false;
|
|
1350
|
+
this.hideMenu();
|
|
1351
|
+
this.focusComposer = focus;
|
|
1352
|
+
this.menuDismissed = false;
|
|
1353
|
+
this.menuQuery = "";
|
|
1354
|
+
this.completeCommands = completeCommands;
|
|
1355
|
+
this.taskPrompt = prompt;
|
|
1356
|
+
this.historySearch = undefined;
|
|
1357
|
+
this.shortcutsShown = false;
|
|
1358
|
+
this.historyPosition = -1;
|
|
1359
|
+
this.historyDraft = "";
|
|
1360
|
+
if (this.terminal) {
|
|
1361
|
+
Object.assign(this.reader, { line: "", cursor: 0 });
|
|
1362
|
+
}
|
|
1363
|
+
return new Promise((resolve, reject) => {
|
|
1364
|
+
this.pending = { resolve, reject };
|
|
1365
|
+
if (this.terminal) {
|
|
1366
|
+
this.reader.setPrompt(prompt);
|
|
1367
|
+
this.reader.prompt();
|
|
1368
|
+
if (focus)
|
|
1369
|
+
this.renderMenu();
|
|
1370
|
+
} else
|
|
1371
|
+
this.output.write(prompt);
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
multiline() {
|
|
1375
|
+
if (this.closed)
|
|
1376
|
+
return Promise.reject(interrupted());
|
|
1377
|
+
if (this.pending || this.paste || this.hidden)
|
|
1378
|
+
return Promise.reject(new Error("A console question is already active."));
|
|
1379
|
+
return new Promise((resolve, reject) => {
|
|
1380
|
+
this.paste = { lines: [], bytes: 0, resolve, reject };
|
|
1381
|
+
this.reader.setPrompt("");
|
|
1382
|
+
this.output.write(`Paste text; finish with .end on its own line. Ctrl+C discards the draft.
|
|
1383
|
+
`);
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
close() {
|
|
1387
|
+
this.finishSecret(false);
|
|
1388
|
+
clearTimeout(this.escapeMenuTimer);
|
|
1389
|
+
this.hideMenu();
|
|
1390
|
+
(this.terminal ? this.keyboard : this.input).off("keypress", this.onKeypress);
|
|
1391
|
+
this.clearHistory();
|
|
1392
|
+
this.reader.close();
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// packages/core/src/cli/console/console-reasoning.ts
|
|
1397
|
+
var descriptions = {
|
|
1398
|
+
default: "Provider default; send no effort override",
|
|
1399
|
+
none: "Disable reasoning where supported",
|
|
1400
|
+
minimal: "Smallest reasoning effort",
|
|
1401
|
+
low: "Lighter reasoning for focused changes",
|
|
1402
|
+
medium: "Balance reasoning depth and latency",
|
|
1403
|
+
high: "Deeper reasoning for complex tasks",
|
|
1404
|
+
xhigh: "Extra reasoning; higher latency and token use",
|
|
1405
|
+
max: "Maximum supported reasoning effort"
|
|
1406
|
+
};
|
|
1407
|
+
var chooseReasoning = async (input, provider, model, current) => {
|
|
1408
|
+
const efforts = modelReasoningEfforts(provider, model);
|
|
1409
|
+
if (current && efforts.includes(current))
|
|
1410
|
+
efforts.sort((a, b) => Number(b === current) - Number(a === current));
|
|
1411
|
+
return input.select(`Zhivex / ${model} / Reasoning
|
|
1412
|
+
${efforts.length === 1 ? "No configurable levels declared by this adapter; provider default only" : "Higher effort can take longer and use more tokens"}`, efforts.map((value) => ({
|
|
1413
|
+
value,
|
|
1414
|
+
label: `${value}${value === (current ?? "default") ? " (current)" : ""}`,
|
|
1415
|
+
detail: descriptions[value]
|
|
1416
|
+
})));
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
// packages/core/src/cli/console/console-pricing.ts
|
|
1420
|
+
import path from "node:path";
|
|
1421
|
+
var catalogPrice = (model) => {
|
|
1422
|
+
const price = model?.pricing;
|
|
1423
|
+
return price ? `Estimated USD / 1M tokens: input $${price.inputPerMillionTokens}; output $${price.outputPerMillionTokens} · checked ${price.evidence.checkedAt}${price.maxInputTokens ? ` · input tier ≤${price.maxInputTokens}` : ""}` : "Price: unknown";
|
|
1424
|
+
};
|
|
1425
|
+
var handleConsoleBudget = async (command, context) => {
|
|
1426
|
+
if (command !== "/budget" && !command.startsWith("/budget ") && command !== "/pricing")
|
|
1427
|
+
return false;
|
|
1428
|
+
const write = context.write ?? ((text) => {
|
|
1429
|
+
process.stdout.write(text);
|
|
1430
|
+
});
|
|
1431
|
+
write(context.guidedTask ? `The current guided task retains one monetary policy across new turns, corrections, /continue and restarts. Changes here apply to future tasks. Estimates are not invoices or guaranteed financial caps.
|
|
1432
|
+
` : `Monetary policies are per RUN; every new turn, /continue and review group starts a new budget. Resuming a pending run retains its original policy. Estimates are not invoices or guaranteed financial caps.
|
|
1433
|
+
`);
|
|
1434
|
+
if (command === "/pricing") {
|
|
1435
|
+
const snapshot = await loadModelCatalog();
|
|
1436
|
+
const model = snapshot.catalog.providers.find((item) => item.id === context.provider)?.models.find((item) => item.id === context.model);
|
|
1437
|
+
write(`${sanitizeTerminalText(context.provider + "/" + context.model)} · ${catalogPrice(model)}
|
|
1438
|
+
`);
|
|
1439
|
+
if (model?.pricing)
|
|
1440
|
+
write(sanitizeTerminalText(`Scope: ${model.pricing.scope}
|
|
1441
|
+
Source: ${model.pricing.evidence.sourceUrl}
|
|
1442
|
+
`));
|
|
1443
|
+
write(`Catalog prices are advisory. Monetary execution limits use an explicit operator pricing file with validity dates for every active route.
|
|
1444
|
+
`);
|
|
1445
|
+
return true;
|
|
1446
|
+
}
|
|
1447
|
+
const policyScope = context.guidedTask ? "future task" : "new run";
|
|
1448
|
+
write(`${context.guidedTask ? "Future task" : "Next run"} estimated USD limit: ${context.options.usageLimitUsd ?? "off"}; pricing file: ${sanitizeTerminalText(context.options.pricingFile ?? "none")}
|
|
1449
|
+
`);
|
|
1450
|
+
if (await context.hasActiveTurn()) {
|
|
1451
|
+
write(`Finish or deny pending work before changing the next-run policy.
|
|
1452
|
+
`);
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
if (context.options.maxCostUsd !== undefined || process.env.ZHIVEX_HARNESS_MAX_COST_USD !== undefined) {
|
|
1456
|
+
write(`A legacy measured-cost policy is configured. Start a console without it before selecting the transport-ledger policy.
|
|
1457
|
+
`);
|
|
1458
|
+
return true;
|
|
1459
|
+
}
|
|
1460
|
+
const argument = command.slice("/budget".length).trim();
|
|
1461
|
+
const selected = argument || await context.input.select(context.guidedTask ? "Budget for future tasks" : "Budget for each next run", [
|
|
1462
|
+
{ value: "", label: "Keep current policy" },
|
|
1463
|
+
{ value: "set", label: "Set estimated USD limit and pricing file" },
|
|
1464
|
+
{ value: "off", label: "Disable monetary limit", detail: "Other step, tool, time and token limits still apply" }
|
|
1465
|
+
]);
|
|
1466
|
+
if (!selected)
|
|
1467
|
+
return true;
|
|
1468
|
+
if (selected === "off") {
|
|
1469
|
+
const next = { ...context.options };
|
|
1470
|
+
delete next.usageLimitUsd;
|
|
1471
|
+
await context.replaceOptions(next);
|
|
1472
|
+
write(context.guidedTask ? `Monetary limit disabled for future tasks; current task policy retained.
|
|
1473
|
+
` : `Monetary limit disabled for next runs.
|
|
1474
|
+
`);
|
|
1475
|
+
return true;
|
|
1476
|
+
}
|
|
1477
|
+
const amount = selected === "set" ? (await context.input.question(`Estimated USD limit per ${policyScope}: `)).trim() : selected;
|
|
1478
|
+
if (!/^\d+(?:\.\d+)?$/.test(amount) || !Number.isFinite(Number(amount)) || Number(amount) <= 0) {
|
|
1479
|
+
write(`Use a positive finite USD amount, or /budget off.
|
|
1480
|
+
`);
|
|
1481
|
+
return true;
|
|
1482
|
+
}
|
|
1483
|
+
const file = (await context.input.question(`Pricing JSON file${context.options.pricingFile ? ` (Enter keeps ${sanitizeTerminalText(context.options.pricingFile)})` : ""}: `)).trim() || context.options.pricingFile;
|
|
1484
|
+
if (!file) {
|
|
1485
|
+
write(`Pricing file required; policy unchanged.
|
|
1486
|
+
`);
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
const pricing = usagePricingSchema.parse(JSON.parse((await readRegularFileNoFollow(path.resolve(file), { maxBytes: 128 * 1024, label: "Usage pricing" })).contents.toString("utf8")));
|
|
1490
|
+
const price = pricing.prices.find((item) => item.provider === context.provider && item.model === context.model);
|
|
1491
|
+
if (!price || Date.parse(price.asOf) > Date.now() || Date.parse(price.expiresAt) <= Date.now()) {
|
|
1492
|
+
write(`Current model price is missing or stale; policy unchanged.
|
|
1493
|
+
`);
|
|
1494
|
+
return true;
|
|
1495
|
+
}
|
|
1496
|
+
write(sanitizeTerminalText(`Operator estimate: input $${price.inputUsdPerMillion}, output $${price.outputUsdPerMillion} / 1M tokens.
|
|
1497
|
+
Source: ${price.source}; valid ${price.asOf} through ${price.expiresAt}.
|
|
1498
|
+
`));
|
|
1499
|
+
write(`The engine reserves estimated requests using their explicit output cap, with a 2048-token fallback when none is supplied, and blocks missing/stale prices, uncertain usage or insufficient estimated budget. Other routes also require valid prices.
|
|
1500
|
+
`);
|
|
1501
|
+
if ((await context.input.question(`Type budget to apply $${amount} per ${policyScope}: `)).trim() !== "budget")
|
|
1502
|
+
return true;
|
|
1503
|
+
await context.replaceOptions({ ...context.options, pricingFile: path.resolve(file), usageLimitUsd: Number(amount) });
|
|
1504
|
+
write(`Estimated USD limit set: $${amount} per ${policyScope}.
|
|
1505
|
+
`);
|
|
1506
|
+
return true;
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
// packages/core/src/cli/console/console-navigation.ts
|
|
1510
|
+
var consoleModelChoices = (provider, defaultModel, current, catalog = bundledModelCatalog) => {
|
|
1511
|
+
const models = catalogModels(catalog, provider, current).sort((a, b) => Number(b.group === "primary") - Number(a.group === "primary"));
|
|
1512
|
+
return [...new Set([...models.map((m) => m.id), defaultModel])].map((model) => {
|
|
1513
|
+
const entry = models.find((m) => m.id === model);
|
|
1514
|
+
return {
|
|
1515
|
+
value: model,
|
|
1516
|
+
label: entry?.name ?? model,
|
|
1517
|
+
group: entry?.group ?? "other",
|
|
1518
|
+
detail: [
|
|
1519
|
+
entry?.name !== model ? model : "",
|
|
1520
|
+
model === current ? "Current" : "",
|
|
1521
|
+
model === defaultModel ? "Recommended default" : "",
|
|
1522
|
+
entry ? modelDescription(entry) : "Unverified",
|
|
1523
|
+
catalogPrice(entry)
|
|
1524
|
+
].filter(Boolean).join(" · ")
|
|
1525
|
+
};
|
|
1526
|
+
});
|
|
1527
|
+
};
|
|
1528
|
+
var navigateConsole = async (input, options) => {
|
|
1529
|
+
const snapshot = options.service ? undefined : await loadModelCatalog();
|
|
1530
|
+
let page = options.entry;
|
|
1531
|
+
let provider = options.current.provider;
|
|
1532
|
+
let modelParent = options.entry === "model" ? undefined : "provider";
|
|
1533
|
+
for (;; ) {
|
|
1534
|
+
if (page === "menu") {
|
|
1535
|
+
const action = await input.select("Zhivex / Menu", [
|
|
1536
|
+
...!options.service ? [
|
|
1537
|
+
{ value: "provider", label: "Providers", detail: "Browse providers and their models" },
|
|
1538
|
+
{ value: "model", label: "Models", detail: `Browse ${options.current.provider} models` },
|
|
1539
|
+
{ value: "/limits", label: "Execution limits", detail: "Steps available per turn" },
|
|
1540
|
+
{ value: "/budget", label: "Run budget", detail: "Estimated USD limit and operator pricing" },
|
|
1541
|
+
{ value: "/pricing", label: "Model pricing", detail: "Source and scope of advisory prices" },
|
|
1542
|
+
{ value: "/checkpoint", label: "Checkpoints", detail: "Capture, review and explicitly restore selected text files" },
|
|
1543
|
+
{ value: "/approvals", label: "Approval mode", detail: "Ask, auto, or restricted for this session" },
|
|
1544
|
+
{ value: "/connection", label: "Test connection", detail: "Optional small request to the selected model" },
|
|
1545
|
+
{ value: "/credentials", label: "Credentials", detail: "System keychain or temporary API keys" }
|
|
1546
|
+
] : [],
|
|
1547
|
+
{ value: "sessions", label: "Conversations", detail: "Find and resume a saved conversation" },
|
|
1548
|
+
{ value: "/status", label: "Status", detail: "Current session and runtime" },
|
|
1549
|
+
{ value: "/activity", label: "Activity history", detail: "Recent tools, approvals and applied files" },
|
|
1550
|
+
{ value: "/queue", label: "Queued tasks", detail: "Inspect tasks and unsent draft" },
|
|
1551
|
+
{ value: "/pending", label: "Pending approvals", detail: "Inspect pending actions" },
|
|
1552
|
+
...!options.service ? [
|
|
1553
|
+
{ value: "/context", label: "Project context", detail: "Rules, skills and attachments" },
|
|
1554
|
+
{ value: "/usage", label: "Usage", detail: "Transport usage and estimates" }
|
|
1555
|
+
] : [],
|
|
1556
|
+
{ value: "/help", label: "Help", detail: "All commands and keyboard shortcuts" }
|
|
1557
|
+
]);
|
|
1558
|
+
if (!action)
|
|
1559
|
+
return;
|
|
1560
|
+
if (action.startsWith("/"))
|
|
1561
|
+
return { command: action };
|
|
1562
|
+
page = action;
|
|
1563
|
+
if (page === "model") {
|
|
1564
|
+
provider = options.current.provider;
|
|
1565
|
+
modelParent = "menu";
|
|
1566
|
+
}
|
|
1567
|
+
} else if (page === "provider") {
|
|
1568
|
+
const selected = await input.select("Zhivex / Providers", options.providers.map((p) => ({
|
|
1569
|
+
value: p.id,
|
|
1570
|
+
label: p.name,
|
|
1571
|
+
detail: `${p.id} · ${p.configured ? "credential present" : "credential missing"}${p.support === "provisional" ? " · provisional" : ""}`
|
|
1572
|
+
})));
|
|
1573
|
+
if (!selected) {
|
|
1574
|
+
if (options.entry === "provider")
|
|
1575
|
+
return;
|
|
1576
|
+
page = "menu";
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
provider = selected;
|
|
1580
|
+
modelParent = "provider";
|
|
1581
|
+
page = "model";
|
|
1582
|
+
} else if (page === "sessions") {
|
|
1583
|
+
const selected = await input.select("Zhivex / Conversations", await options.sessions());
|
|
1584
|
+
if (selected)
|
|
1585
|
+
return { command: `/resume ${selected}` };
|
|
1586
|
+
page = "menu";
|
|
1587
|
+
} else {
|
|
1588
|
+
const descriptor = options.providers.find((p) => p.id === provider);
|
|
1589
|
+
if (!descriptor)
|
|
1590
|
+
return;
|
|
1591
|
+
const catalog = snapshot?.catalog ?? bundledModelCatalog;
|
|
1592
|
+
const defaultModel = catalog.providers.find((p) => p.id === provider)?.defaultModel ?? descriptor.defaultModel;
|
|
1593
|
+
const choices = consoleModelChoices(provider, defaultModel, options.current.provider === provider ? options.current.model : undefined, catalog);
|
|
1594
|
+
const primary = choices.filter((item) => item.group === "primary" || provider === options.current.provider && item.value === options.current.model);
|
|
1595
|
+
const others = choices.filter((item) => !primary.includes(item));
|
|
1596
|
+
let selected = await input.select(`Zhivex / Providers / ${descriptor.name} / Models
|
|
1597
|
+
Featured models · ${snapshot?.source ?? "bundled"}${snapshot?.stale ? " (offline fallback)" : ""} · account access is not checked`, [
|
|
1598
|
+
...primary.map((item) => ({ ...item, value: { kind: "model", id: item.value } })),
|
|
1599
|
+
...others.length ? [{ value: { kind: "other", id: "" }, label: "Other models…", detail: "Previous generations, snapshots and additional models" }] : [],
|
|
1600
|
+
{ value: { kind: "custom", id: "" }, label: "Custom model ID…", detail: "Enter a model absent from the local catalog" }
|
|
1601
|
+
]);
|
|
1602
|
+
if (!selected) {
|
|
1603
|
+
if (!modelParent)
|
|
1604
|
+
return;
|
|
1605
|
+
page = modelParent;
|
|
1606
|
+
continue;
|
|
1607
|
+
}
|
|
1608
|
+
if (selected.kind === "other") {
|
|
1609
|
+
selected = await input.select("Zhivex / Other models · account access is not checked", others.map((item) => ({ ...item, value: { kind: "model", id: item.value } })));
|
|
1610
|
+
if (!selected)
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
if (selected.kind === "custom") {
|
|
1614
|
+
let prompt = "Model ID (Enter to go back): ";
|
|
1615
|
+
for (;; ) {
|
|
1616
|
+
const model = (await input.question(prompt)).trim();
|
|
1617
|
+
if (!model)
|
|
1618
|
+
break;
|
|
1619
|
+
if (model.length <= 512 && !/[\u0000-\u001f\u007f]/.test(model)) {
|
|
1620
|
+
const reasoningEffort2 = await chooseReasoning(input, provider, model);
|
|
1621
|
+
if (reasoningEffort2)
|
|
1622
|
+
return { provider, model, reasoningEffort: reasoningEffort2 };
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
prompt = "Use 1–512 printable characters. Model ID (Enter to go back): ";
|
|
1626
|
+
}
|
|
1627
|
+
continue;
|
|
1628
|
+
}
|
|
1629
|
+
const reasoningEffort = await chooseReasoning(input, provider, selected.id, provider === options.current.provider && selected.id === options.current.model ? options.current.reasoningEffort : undefined);
|
|
1630
|
+
if (!reasoningEffort)
|
|
1631
|
+
continue;
|
|
1632
|
+
return { provider, model: selected.id, reasoningEffort };
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
// packages/core/src/cli/policy.ts
|
|
1638
|
+
function formatPolicyInspection(policy) {
|
|
1639
|
+
return [
|
|
1640
|
+
`Policy: ${policy.source} · ${policy.digest ?? "baseline"}`,
|
|
1641
|
+
`Explicit review: ${policy.explicitReviewRequired ? "required for approvals" : "not configured"}`,
|
|
1642
|
+
`Execution backend: ${policy.execution.activeBackend} (configured: ${policy.execution.configuredBackend})`,
|
|
1643
|
+
"Evidence: configuration only; no tool execution is certified by this query.",
|
|
1644
|
+
`Limits: ${policy.limits.maxSteps} steps, ${policy.limits.timeoutMs} ms`,
|
|
1645
|
+
"Tools:",
|
|
1646
|
+
...policy.tools.map((tool) => ` ${tool.name}: ${tool.requiresApproval ? "approval required" : "no baseline approval"}`),
|
|
1647
|
+
"Additional restrictions:",
|
|
1648
|
+
...policy.restrictions.map((rule) => ` ${rule.ruleId}: ${rule.decision} · ${rule.tools.join(", ")} · ${rule.reason}${rule.pathCount ? ` (${rule.pathCount} scoped paths omitted)` : ""}`)
|
|
1649
|
+
].map(sanitizeTerminalText).join(`
|
|
1650
|
+
`);
|
|
1651
|
+
}
|
|
1652
|
+
function printPolicyInspection(policy, json) {
|
|
1653
|
+
process.stdout.write((json ? JSON.stringify(policy, null, 2) : formatPolicyInspection(policy)) + `
|
|
1654
|
+
`);
|
|
1655
|
+
}
|
|
1656
|
+
async function inspectCliPolicy(options) {
|
|
1657
|
+
const { harness } = await createConfiguredHarness(options);
|
|
1658
|
+
try {
|
|
1659
|
+
printPolicyInspection(inspectHarnessPolicy(harness), options.json);
|
|
1660
|
+
} finally {
|
|
1661
|
+
await harness.close();
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// packages/core/src/cli/terminal/activity-history.ts
|
|
1666
|
+
import { createRedactionPolicy } from "@zhivex-ai/agents";
|
|
1667
|
+
var redaction = createRedactionPolicy({ includeEmails: true });
|
|
1668
|
+
var toolNames = new Set(["read_file", "read_files", "read_dependency", "search_files", "search_many", "list_files", "git_diff", "run_check", "run_environment_command", "propose_edits", "apply_patch", "apply_reviewed_edits", "apply_reviewed_replacement", "apply_environment_patch", "verify_and_apply_patch", "verify_and_apply_replacement", "move_file", "quarantine_file", "restore_file"]);
|
|
1669
|
+
var safeName = (name) => toolNames.has(name) ? name : "tool";
|
|
1670
|
+
var safePath = (path2) => redaction.redactText(sanitizeTerminalText(path2)).replace(/[\r\n\t]/g, " ").slice(0, 240);
|
|
1671
|
+
|
|
1672
|
+
class ActivityHistory {
|
|
1673
|
+
lines = [];
|
|
1674
|
+
started = Date.now();
|
|
1675
|
+
dropped = 0;
|
|
1676
|
+
clear() {
|
|
1677
|
+
this.lines = [];
|
|
1678
|
+
this.dropped = 0;
|
|
1679
|
+
this.started = Date.now();
|
|
1680
|
+
}
|
|
1681
|
+
add(text) {
|
|
1682
|
+
this.lines.push(`[${((Date.now() - this.started) / 1000).toFixed(1)}s] ${text.slice(0, 800)}`);
|
|
1683
|
+
if (this.lines.length > 200) {
|
|
1684
|
+
this.lines.shift();
|
|
1685
|
+
this.dropped++;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
observe(event, options = {}) {
|
|
1689
|
+
const includeTools = options.includeTools !== false;
|
|
1690
|
+
if (event.type === "agent-run-start")
|
|
1691
|
+
this.add("Run started / resumed");
|
|
1692
|
+
else if (event.type === "agent-step-start")
|
|
1693
|
+
this.add("Waiting for model response");
|
|
1694
|
+
else if (event.type === "agent-compaction")
|
|
1695
|
+
this.add("Updating context");
|
|
1696
|
+
else if (includeTools && event.type === "tool-call")
|
|
1697
|
+
this.add(`Preparing ${safeName(event.toolCall.name)}`);
|
|
1698
|
+
else if (includeTools && event.type === "tool-result")
|
|
1699
|
+
this.add(compactToolResult(event.toolResult, { includeSuccessEdits: true }) ?? `${event.toolResult.isError ? "Failed" : "Finished"} ${safeName(event.toolResult.toolName)}`);
|
|
1700
|
+
else if (event.type === "tool-approval-request")
|
|
1701
|
+
this.add(`Waiting for approval: ${safeName(event.approval.name)}`);
|
|
1702
|
+
else if (event.type === "agent-approval-resolved")
|
|
1703
|
+
this.add(event.approval.approve ? "Approval granted" : "Approval denied");
|
|
1704
|
+
else if (event.type === "agent-run-finish")
|
|
1705
|
+
this.add(`Run ${event.status}`);
|
|
1706
|
+
}
|
|
1707
|
+
observeService(event) {
|
|
1708
|
+
const name = typeof event.toolName === "string" ? safeName(event.toolName) : "tool";
|
|
1709
|
+
if (event.type === "tool-call")
|
|
1710
|
+
this.add(`Preparing ${name}`);
|
|
1711
|
+
else if (event.type === "tool-result")
|
|
1712
|
+
this.add(`${event.isError ? "Failed" : "Finished"} ${name}`);
|
|
1713
|
+
else if (event.type === "tool-approval-request")
|
|
1714
|
+
this.add(`Waiting for approval: ${name}`);
|
|
1715
|
+
else if (event.type === "agent-step-start")
|
|
1716
|
+
this.add("Waiting for model response");
|
|
1717
|
+
else if (event.type === "agent-compaction")
|
|
1718
|
+
this.add("Updating context");
|
|
1719
|
+
else if (event.type === "agent-run-start")
|
|
1720
|
+
this.add("Run started / resumed");
|
|
1721
|
+
else if (event.type === "agent-run-finish")
|
|
1722
|
+
this.add("Run stopped; inspect /status for outcome");
|
|
1723
|
+
}
|
|
1724
|
+
render() {
|
|
1725
|
+
return this.lines.length ? `Activity history · this console session${this.dropped ? ` · ${this.dropped} earlier entries omitted` : ""}
|
|
1726
|
+
${this.lines.join(`
|
|
1727
|
+
`)}
|
|
1728
|
+
` : `No activity recorded in this console session.
|
|
1729
|
+
`;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
var formatAppliedFiles = (entries, reviewHint = "/diff to review", presentation = "block") => {
|
|
1733
|
+
if (!entries.length)
|
|
1734
|
+
return "";
|
|
1735
|
+
if (presentation === "line") {
|
|
1736
|
+
const shown = entries.slice(0, 3).map((entry) => safePath(entry.path)).join(", ");
|
|
1737
|
+
const more = entries.length > 3 ? `, +${entries.length - 3} more` : "";
|
|
1738
|
+
return `✓ Applied ${entries.length} file change${entries.length === 1 ? "" : "s"} · ${shown}${more} · ${reviewHint}
|
|
1739
|
+
`;
|
|
1740
|
+
}
|
|
1741
|
+
const lines = entries.slice(0, 20).map((entry) => ` ${entry.operation} ${safePath(entry.path)}${entry.destination ? ` → ${safePath(entry.destination)}` : ""}`);
|
|
1742
|
+
if (entries.length > 20)
|
|
1743
|
+
lines.push(` … ${entries.length - 20} more files`);
|
|
1744
|
+
return `✓ Applied ${entries.length} file change${entries.length === 1 ? "" : "s"}
|
|
1745
|
+
${lines.join(`
|
|
1746
|
+
`)}
|
|
1747
|
+
${reviewHint} · verification reported separately
|
|
1748
|
+
`;
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
// packages/core/src/cli/console/console-welcome.ts
|
|
1752
|
+
var LOGO_PADDING = "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀";
|
|
1753
|
+
var ZHIVEX_TERMINAL_LOGO = [
|
|
1754
|
+
"⠀⠀⠀⠀⠀⠀⠀⣀⣤⣴⡶⠶⠶⠶⣦⣤⣀⠀⠀⠀⠀⠀⠀⠀",
|
|
1755
|
+
"⠀⠀⠀⠀⠀⣠⡾⠋⠉⠀⠀⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀",
|
|
1756
|
+
"⠀⠀⠀⢀⡾⠋⠀⠴⠿⠿⠿⠿⠿⠿⣿⣿⡿⠋⠙⣷⡀⠀⠀⠀",
|
|
1757
|
+
"⠀⠀⢀⣾⠁⠀⠀⠸⠿⠿⠿⠿⣿⡿⠟⠋⠀⠀⠀⠘⣷⡀⠀⠀",
|
|
1758
|
+
"⠀⠀⢸⡏⠀⠀⠀⠀⠀⠀⣠⣾⠟⠁⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀",
|
|
1759
|
+
"⠀⠀⢸⡇⠀⠀⠀⠀⢀⣾⠟⠁⠀⠀⠀⠀⠀⠀⣤⠀⢸⡇⠀⠀",
|
|
1760
|
+
"⠀⠀⠘⣷⡀⠀⠀⢠⣿⡏⠀⠀⠀⠀⠀⠀⢀⣾⡿⠀⣾⠃⠀⠀",
|
|
1761
|
+
"⠀⠀⠀⠈⠻⣿⡟⠁⠀⠀⠀⠀⠀⠀⠈⣿⣿⢀⣴⠟⠀⠀⠀⠀",
|
|
1762
|
+
"⠀⠀⠀⠀⠀⠈⠻⢶⣤⣀⡀⠀⠀⢀⣀⣤⡶⠟⠁⠀⠀⠀⠀⠀",
|
|
1763
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⠛⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀"
|
|
1764
|
+
].join(`
|
|
1765
|
+
`);
|
|
1766
|
+
var LEGACY_TERMINAL_LOGO = [LOGO_PADDING, ZHIVEX_TERMINAL_LOGO, LOGO_PADDING].join(`
|
|
1767
|
+
`);
|
|
1768
|
+
var projectLabel = (workspace) => {
|
|
1769
|
+
const home = process.env.HOME;
|
|
1770
|
+
const relative = home && (workspace === home || workspace.startsWith(`${home}/`)) ? `~${workspace.slice(home.length)}` : workspace;
|
|
1771
|
+
return sanitizeTerminalText(relative);
|
|
1772
|
+
};
|
|
1773
|
+
var formatLegacyWelcome = (input, options) => {
|
|
1774
|
+
const safe = sanitizeTerminalText;
|
|
1775
|
+
const color = options.color ?? terminalSupportsColor(Boolean(process.stdout.isTTY));
|
|
1776
|
+
const columns = options.columns ?? 80;
|
|
1777
|
+
const title = `Zhivex Harness ${safe(input.version)}`;
|
|
1778
|
+
const logo = columns < 48 || options.compact ? "( Z )" : LEGACY_TERMINAL_LOGO;
|
|
1779
|
+
const logoLines = logo.split(`
|
|
1780
|
+
`);
|
|
1781
|
+
const logoWidth = Math.max(...logoLines.map((line) => line.length));
|
|
1782
|
+
const titleBesideLogo = columns >= logoWidth + 3 + title.length;
|
|
1783
|
+
const context = [
|
|
1784
|
+
"Welcome to Zhivex. Type a message, or /help for commands.",
|
|
1785
|
+
`Project: ${safe(input.workspace)}`,
|
|
1786
|
+
input.service ? "Runtime: local service · managed by host" : `Model: ${safe(input.provider ?? "not configured")}/${safe(input.model ?? "not selected")}`,
|
|
1787
|
+
input.sessionId ? `Conversation: ${safe(input.sessionTitle || "new")} · session ${safe(input.sessionId)}` : "Conversation: new"
|
|
1788
|
+
];
|
|
1789
|
+
const right = [title, ...context];
|
|
1790
|
+
const titleRow = Math.max(0, Math.floor((logoLines.length - right.length) / 2));
|
|
1791
|
+
const header = logoLines.map((line, index) => {
|
|
1792
|
+
const mark = color ? `\x1B[${terminalToneCode("accent")}m${line}\x1B[0m` : line;
|
|
1793
|
+
const label = titleBesideLogo ? right[index - titleRow] : undefined;
|
|
1794
|
+
return label ? `${mark}${" ".repeat(logoWidth - line.length + 3)}${color ? index === titleRow ? "\x1B[1m" : `\x1B[${terminalToneCode("muted")}m` : ""}${consoleLabel(label, columns - logoWidth - 3)}${color ? "\x1B[0m" : ""}` : mark;
|
|
1795
|
+
}).join(`
|
|
1796
|
+
`);
|
|
1797
|
+
return [
|
|
1798
|
+
header,
|
|
1799
|
+
...titleBesideLogo ? logoLines.length === 1 ? context : [] : [title, ...context]
|
|
1800
|
+
].join(`
|
|
1801
|
+
`);
|
|
1802
|
+
};
|
|
1803
|
+
var formatCodeWelcome = (input, options) => {
|
|
1804
|
+
const safe = sanitizeTerminalText;
|
|
1805
|
+
const color = options.color ?? terminalSupportsColor(Boolean(process.stderr.isTTY));
|
|
1806
|
+
const columns = options.columns ?? (process.stderr.columns || process.stdout.columns || 80);
|
|
1807
|
+
const rows = options.rows ?? (process.stderr.rows || process.stdout.rows || 24);
|
|
1808
|
+
const tty = options.tty ?? Boolean(process.stderr.isTTY);
|
|
1809
|
+
const term = options.term ?? process.env.TERM;
|
|
1810
|
+
const version = safe(input.version);
|
|
1811
|
+
const title = `Zhivex Code ${version}`;
|
|
1812
|
+
const project = `${projectLabel(input.workspace)} · ${safe(input.provider ?? "not configured")}/${safe(input.model ?? "not selected")}`;
|
|
1813
|
+
if (options.restored)
|
|
1814
|
+
return `( Z ) ${title} · ${project}`;
|
|
1815
|
+
const welcome = "Welcome. What would you like to work on?";
|
|
1816
|
+
const policy = options.policy ?? "Zhivex asks before it changes files.";
|
|
1817
|
+
const showLogo = !options.compact && tty && term !== "dumb" && columns >= 48 && rows >= 24;
|
|
1818
|
+
if (!showLogo)
|
|
1819
|
+
return [`( Z ) ${title}`, project, welcome, policy].join(`
|
|
1820
|
+
`);
|
|
1821
|
+
const logoLines = ZHIVEX_TERMINAL_LOGO.split(`
|
|
1822
|
+
`);
|
|
1823
|
+
const logoWidth = Math.max(...logoLines.map((line) => line.length));
|
|
1824
|
+
const side = [title, project, "", welcome, policy];
|
|
1825
|
+
const room = Math.max(1, columns - logoWidth - 3);
|
|
1826
|
+
const paint = (label, index) => {
|
|
1827
|
+
const bounded = consoleLabel(label, room);
|
|
1828
|
+
if (!color || !bounded)
|
|
1829
|
+
return bounded;
|
|
1830
|
+
if (index === 0)
|
|
1831
|
+
return `\x1B[1mZhivex Code \x1B[0m\x1B[${terminalToneCode("muted")}m${version}\x1B[0m`;
|
|
1832
|
+
if (index === 1)
|
|
1833
|
+
return `\x1B[${terminalToneCode("muted")}m${bounded}\x1B[0m`;
|
|
1834
|
+
return bounded;
|
|
1835
|
+
};
|
|
1836
|
+
if (columns < logoWidth + 3 + title.length) {
|
|
1837
|
+
const stacked = side.map((label) => label ? consoleLabel(label, Math.max(1, columns)) : "");
|
|
1838
|
+
return [logoLines.map((line) => color ? `\x1B[${terminalToneCode("accent")}m${line}\x1B[0m` : line).join(`
|
|
1839
|
+
`), ...stacked].join(`
|
|
1840
|
+
`);
|
|
1841
|
+
}
|
|
1842
|
+
const titleRow = Math.max(0, Math.floor((logoLines.length - side.length) / 2));
|
|
1843
|
+
return logoLines.map((line, index) => {
|
|
1844
|
+
const mark = color ? `\x1B[${terminalToneCode("accent")}m${line}\x1B[0m` : line;
|
|
1845
|
+
const label = side[index - titleRow];
|
|
1846
|
+
return label ? `${mark}${" ".repeat(logoWidth - line.length + 3)}${paint(label, index - titleRow)}` : mark;
|
|
1847
|
+
}).join(`
|
|
1848
|
+
`);
|
|
1849
|
+
};
|
|
1850
|
+
var formatConsoleWelcome = (input, options = {}) => options.layout === "code" ? formatCodeWelcome(input, options) : formatLegacyWelcome(input, options);
|
|
1851
|
+
|
|
1852
|
+
export { formatPolicyDecision, observeCliPolicy, consoleLabel, consoleWidth, consoleStateLines, formatConsoleHelp, ConsoleInput, chooseReasoning, handleConsoleBudget, navigateConsole, printPolicyInspection, inspectCliPolicy, ActivityHistory, formatAppliedFiles, formatConsoleWelcome };
|