@zhivex-ai/harness 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +17 -5
- package/SECURITY.md +1 -1
- package/SUPPORT.md +2 -2
- package/benchmarks/README.md +26 -0
- package/contracts/engine-api.json +1557 -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/approvals/auto-approve.d.ts +1 -1
- 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-y02n8zd0.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-j6jcb2jb.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-v5db3eb2.js → cli-entry-dksm56sj.js} +39 -297
- package/dist/{cli-entry-td04s0fa.js → cli-entry-eka68ttb.js} +3919 -4549
- package/dist/cli-entry-h7dcah4p.js +137 -0
- package/dist/cli-entry-kwk23ktq.js +33 -0
- package/dist/{cli-entry-ynahz9qc.js → cli-entry-vmce694z.js} +1251 -3139
- package/dist/cli-entry-wanv05db.js +1113 -0
- package/dist/{cli-zw18kdqx.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 +3 -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 +14 -0
- 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.js +111 -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 +1822 -696
- package/dist/index-09rsdr2d.js +1744 -0
- package/dist/index-0csc5sc7.js +139 -0
- package/dist/{index-v86bh0eg.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-k1a1xesg.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-qz4fs9f9.js → index-6ehtssyz.js} +355 -332
- package/dist/index-76kpdbpw.js +80 -0
- package/dist/{index-r0q0r88h.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-yp0jtaxp.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-tc2r2n8b.js → index-mkt5yrax.js} +31 -105
- package/dist/{index-tgt8gtq7.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-h8r80xhk.js → index-sx1t6dnd.js} +4005 -2781
- package/dist/index-tar0ngkm.js +359 -0
- package/dist/index-tn58cr6w.js +471 -0
- package/dist/{index-v17e1xs8.js → index-v79s9bf9.js} +96 -23
- 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-t6sjhxh8.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/harness.d.ts +2 -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 +1923 -797
- 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 +5 -3
- package/docs/CODE_WEB_TASKS.md +3 -114
- package/docs/CONTEXT_ENGINEERING.md +27 -0
- package/docs/ENGINE_API.md +1 -1
- 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/README.md +13 -2
- package/evaluations/representative-assembly-matrix.json +10 -1
- package/examples/README.md +3 -3
- 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 +230 -28
- package/dist/cli/console/console-model-catalog.d.ts +0 -8
- package/dist/index-4gt045j0.js +0 -288
- package/dist/index-4jw3tvy8.js +0 -301
- package/dist/index-ebb5d4s3.js +0 -640
- package/dist/index-x9hv1a34.js +0 -274
- package/dist/service-client-cli-gtk26axb.js +0 -1251
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SqliteDatabase
|
|
3
|
+
} from "./index-f970qtb4.js";
|
|
4
|
+
import {
|
|
5
|
+
readRegularFileNoFollow
|
|
6
|
+
} from "./index-h7dcah4p.js";
|
|
7
|
+
// packages/core/src/approvals/auto-approve.ts
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { lstat, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
var AUTO_APPROVE_MODES = ["manual", "auto-edits", "auto-limits"];
|
|
12
|
+
var EDIT_TOOLS = new Set([
|
|
13
|
+
"apply_patch",
|
|
14
|
+
"apply_reviewed_edits",
|
|
15
|
+
"apply_reviewed_replacement",
|
|
16
|
+
"verify_and_apply_reviewed_edits"
|
|
17
|
+
]);
|
|
18
|
+
var COMMAND_TOOLS = new Set([
|
|
19
|
+
"run_check",
|
|
20
|
+
"run_environment_command",
|
|
21
|
+
"run_environment_shell",
|
|
22
|
+
"run_environment_batch",
|
|
23
|
+
"apply_environment_patch",
|
|
24
|
+
"verify_and_apply_environment_patch"
|
|
25
|
+
]);
|
|
26
|
+
var NETWORK_BINARIES = new Set([
|
|
27
|
+
"curl",
|
|
28
|
+
"wget",
|
|
29
|
+
"ssh",
|
|
30
|
+
"scp",
|
|
31
|
+
"sftp",
|
|
32
|
+
"nc",
|
|
33
|
+
"ncat",
|
|
34
|
+
"netcat",
|
|
35
|
+
"telnet",
|
|
36
|
+
"ftp",
|
|
37
|
+
"ping",
|
|
38
|
+
"dig",
|
|
39
|
+
"nslookup",
|
|
40
|
+
"host",
|
|
41
|
+
"socat",
|
|
42
|
+
"rsync",
|
|
43
|
+
"aria2c",
|
|
44
|
+
"fetch"
|
|
45
|
+
]);
|
|
46
|
+
var NETWORK_TOOLS = new Set(["fetch", "web_fetch", "http_request", "browse_page", "net_request"]);
|
|
47
|
+
var DELETE_BINARIES = new Set(["rm", "rmdir", "unlink", "del"]);
|
|
48
|
+
var ALLOWLIST_NAME = /^[A-Za-z0-9._+-]+$/;
|
|
49
|
+
var SNAPSHOT_BYTES = 256 * 1024;
|
|
50
|
+
var approvalConfigPath = (rootDir) => path.join(rootDir, ".zhivex-harness", "approval.json");
|
|
51
|
+
var autoApprovalLogPath = (rootDir) => path.join(rootDir, ".zhivex-harness", "auto-approvals.jsonl");
|
|
52
|
+
var isAutoApproveMode = (value) => AUTO_APPROVE_MODES.includes(value);
|
|
53
|
+
var parseAllowlist = (entries) => {
|
|
54
|
+
const names = [];
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const name = entry.trim().toLowerCase();
|
|
57
|
+
if (!ALLOWLIST_NAME.test(name) || name.includes("*") || name.includes("/") || name.includes("\\")) {
|
|
58
|
+
throw new Error(`AUTO_APPROVE_ALLOWLIST_INVALID:${entry}`);
|
|
59
|
+
}
|
|
60
|
+
if (!names.includes(name))
|
|
61
|
+
names.push(name);
|
|
62
|
+
}
|
|
63
|
+
return names;
|
|
64
|
+
};
|
|
65
|
+
var parseApprovalConfig = (text) => {
|
|
66
|
+
let parsed;
|
|
67
|
+
try {
|
|
68
|
+
parsed = JSON.parse(text);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new Error("AUTO_APPROVE_CONFIG_INVALID");
|
|
71
|
+
}
|
|
72
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
73
|
+
throw new Error("AUTO_APPROVE_CONFIG_INVALID");
|
|
74
|
+
const record = parsed;
|
|
75
|
+
const keys = Object.keys(record).sort();
|
|
76
|
+
if (keys.some((key) => key !== "mode" && key !== "commandAllowlist"))
|
|
77
|
+
throw new Error("AUTO_APPROVE_CONFIG_INVALID");
|
|
78
|
+
const mode = record.mode ?? "manual";
|
|
79
|
+
if (typeof mode !== "string" || !isAutoApproveMode(mode))
|
|
80
|
+
throw new Error("AUTO_APPROVE_CONFIG_INVALID");
|
|
81
|
+
const list = record.commandAllowlist ?? [];
|
|
82
|
+
if (!Array.isArray(list) || list.some((item) => typeof item !== "string"))
|
|
83
|
+
throw new Error("AUTO_APPROVE_CONFIG_INVALID");
|
|
84
|
+
return { mode, commandAllowlist: parseAllowlist(list) };
|
|
85
|
+
};
|
|
86
|
+
var resolveAutoApprovePolicy = (input) => {
|
|
87
|
+
const mode = input.sessionMode ?? input.cliMode ?? input.file?.mode ?? "manual";
|
|
88
|
+
const listed = input.sessionAllow ?? (input.cliAllow && input.cliAllow.length ? input.cliAllow : input.file?.commandAllowlist ?? []);
|
|
89
|
+
return {
|
|
90
|
+
mode,
|
|
91
|
+
commandAllowlist: parseAllowlist(listed),
|
|
92
|
+
rootDir: input.rootDir,
|
|
93
|
+
...input.overLimit ? { overLimit: true } : {}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
var isInsideRoot = (rootDir, candidate) => {
|
|
97
|
+
if (!candidate || candidate.includes("\x00") || candidate.startsWith("~"))
|
|
98
|
+
return false;
|
|
99
|
+
const root = path.resolve(rootDir);
|
|
100
|
+
const resolved = path.resolve(root, candidate);
|
|
101
|
+
const relative = path.relative(root, resolved);
|
|
102
|
+
return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
|
|
103
|
+
};
|
|
104
|
+
var isSecretPath = (candidate) => {
|
|
105
|
+
const normalized = candidate.replaceAll("\\", "/");
|
|
106
|
+
const base = normalized.split("/").pop() ?? normalized;
|
|
107
|
+
if (/^\.env($|\.)/i.test(base))
|
|
108
|
+
return true;
|
|
109
|
+
if (/^(credentials|credentials\..+|\.npmrc|\.pypirc|\.netrc|id_rsa|id_ed25519)$/i.test(base))
|
|
110
|
+
return true;
|
|
111
|
+
if (/\.(pem|key)$/i.test(base))
|
|
112
|
+
return true;
|
|
113
|
+
if (normalized.split("/").some((segment) => /^(secrets?|credentials|\.secrets)$/i.test(segment)))
|
|
114
|
+
return true;
|
|
115
|
+
return /credential/i.test(base);
|
|
116
|
+
};
|
|
117
|
+
var tokenize = (command) => {
|
|
118
|
+
const tokens = [];
|
|
119
|
+
const pattern = /"([^"]*)"|'([^']*)'|(\S+)/g;
|
|
120
|
+
for (const match of command.matchAll(pattern))
|
|
121
|
+
tokens.push(match[1] ?? match[2] ?? match[3] ?? "");
|
|
122
|
+
while (tokens[0] && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0]))
|
|
123
|
+
tokens.shift();
|
|
124
|
+
return tokens;
|
|
125
|
+
};
|
|
126
|
+
var executable = (token) => (token.replaceAll("\\", "/").split("/").pop() ?? token).replace(/\.exe$/i, "").toLowerCase();
|
|
127
|
+
var inspectCommand = (command) => {
|
|
128
|
+
const tokens = tokenize(command.trim());
|
|
129
|
+
return { binary: executable(tokens[0] ?? ""), args: tokens.slice(1), raw: command };
|
|
130
|
+
};
|
|
131
|
+
var isGitPush = (command) => command.binary === "git" && command.args.some((arg) => arg === "push");
|
|
132
|
+
var isPackagePublish = (command) => {
|
|
133
|
+
const args = command.args.filter((arg) => !arg.startsWith("-"));
|
|
134
|
+
if (["npm", "pnpm", "yarn", "bun"].includes(command.binary) && args.includes("publish"))
|
|
135
|
+
return true;
|
|
136
|
+
if (command.binary === "yarn" && args[0] === "npm" && args.includes("publish"))
|
|
137
|
+
return true;
|
|
138
|
+
if (command.binary === "bun" && args[0] === "pm" && args.includes("publish"))
|
|
139
|
+
return true;
|
|
140
|
+
return command.binary === "cargo" && args.includes("publish");
|
|
141
|
+
};
|
|
142
|
+
var isNetworkCommand = (command) => NETWORK_BINARIES.has(command.binary) || /https?:\/\//i.test(command.raw) || /\b(ssh|scp|sftp):\/\//i.test(command.raw);
|
|
143
|
+
var pathTokens = (tokens) => tokens.filter((token) => token.startsWith("/") || token.startsWith("~") || token.includes("..") || token.startsWith("./"));
|
|
144
|
+
var commandAlwaysAsk = (command, rootDir) => {
|
|
145
|
+
if (isGitPush(command))
|
|
146
|
+
return "git-push";
|
|
147
|
+
if (isPackagePublish(command))
|
|
148
|
+
return "package-publish";
|
|
149
|
+
if (isNetworkCommand(command))
|
|
150
|
+
return "network";
|
|
151
|
+
const tokens = [command.binary, ...command.args];
|
|
152
|
+
for (const token of tokens)
|
|
153
|
+
if (isSecretPath(token))
|
|
154
|
+
return "secret";
|
|
155
|
+
for (const token of pathTokens(command.args)) {
|
|
156
|
+
if (!isInsideRoot(rootDir, token))
|
|
157
|
+
return DELETE_BINARIES.has(command.binary) ? "delete-outside" : "write-outside";
|
|
158
|
+
}
|
|
159
|
+
if (DELETE_BINARIES.has(command.binary)) {
|
|
160
|
+
for (const arg of command.args) {
|
|
161
|
+
if (arg.startsWith("-"))
|
|
162
|
+
continue;
|
|
163
|
+
if (!isInsideRoot(rootDir, arg))
|
|
164
|
+
return "delete-outside";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
};
|
|
169
|
+
var fileAlwaysAsk = (file, rootDir) => {
|
|
170
|
+
if (isSecretPath(file.path))
|
|
171
|
+
return "secret";
|
|
172
|
+
if (!isInsideRoot(rootDir, file.path))
|
|
173
|
+
return file.operation === "delete" ? "delete-outside" : "write-outside";
|
|
174
|
+
return;
|
|
175
|
+
};
|
|
176
|
+
var commandsAllowlisted = (commands, policy) => commands.every((command) => {
|
|
177
|
+
const inspected = inspectCommand(command);
|
|
178
|
+
return inspected.binary !== "" && policy.commandAllowlist.includes(inspected.binary);
|
|
179
|
+
});
|
|
180
|
+
var classifyApproval = (facts, policy) => {
|
|
181
|
+
if (policy.overLimit)
|
|
182
|
+
return { decision: "ask", reason: "over-limit" };
|
|
183
|
+
if (NETWORK_TOOLS.has(facts.name) || facts.name.includes("egress"))
|
|
184
|
+
return { decision: "ask", reason: "network" };
|
|
185
|
+
for (const file of facts.paths) {
|
|
186
|
+
const reason = fileAlwaysAsk(file, policy.rootDir);
|
|
187
|
+
if (reason)
|
|
188
|
+
return { decision: "ask", reason };
|
|
189
|
+
}
|
|
190
|
+
for (const command of facts.commands) {
|
|
191
|
+
const reason = commandAlwaysAsk(inspectCommand(command), policy.rootDir);
|
|
192
|
+
if (reason)
|
|
193
|
+
return { decision: "ask", reason };
|
|
194
|
+
}
|
|
195
|
+
if (policy.mode === "manual")
|
|
196
|
+
return { decision: "ask", reason: "manual" };
|
|
197
|
+
if (EDIT_TOOLS.has(facts.name)) {
|
|
198
|
+
if (!facts.paths.length)
|
|
199
|
+
return { decision: "ask", reason: "unproven-path" };
|
|
200
|
+
if (facts.commands.length) {
|
|
201
|
+
if (policy.mode !== "auto-limits" || !commandsAllowlisted(facts.commands, policy)) {
|
|
202
|
+
return { decision: "ask", reason: "not-allowlisted" };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { decision: "auto", reason: "edit-in-root" };
|
|
206
|
+
}
|
|
207
|
+
if (policy.mode === "auto-limits" && COMMAND_TOOLS.has(facts.name)) {
|
|
208
|
+
if (!facts.commands.length || !commandsAllowlisted(facts.commands, policy))
|
|
209
|
+
return { decision: "ask", reason: "not-allowlisted" };
|
|
210
|
+
return { decision: "auto", reason: "allowlisted-command" };
|
|
211
|
+
}
|
|
212
|
+
return { decision: "ask", reason: policy.mode === "auto-edits" ? "not-an-edit" : "not-allowlisted" };
|
|
213
|
+
};
|
|
214
|
+
var approvalFacts = (name, argumentsText) => {
|
|
215
|
+
let args = {};
|
|
216
|
+
try {
|
|
217
|
+
const parsed = JSON.parse(argumentsText);
|
|
218
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
219
|
+
args = parsed;
|
|
220
|
+
} catch {}
|
|
221
|
+
const paths = [];
|
|
222
|
+
const commands = [];
|
|
223
|
+
const pushPath = (value, operation) => {
|
|
224
|
+
if (typeof value === "string")
|
|
225
|
+
paths.push({ path: value, operation });
|
|
226
|
+
};
|
|
227
|
+
if (typeof args.path === "string") {
|
|
228
|
+
pushPath(args.path, args.content === null || args.newText === null ? "delete" : args.expectedDigest === null ? "create" : "update");
|
|
229
|
+
}
|
|
230
|
+
pushPath(args.source, "move");
|
|
231
|
+
pushPath(args.destination, "move");
|
|
232
|
+
if (Array.isArray(args.changes)) {
|
|
233
|
+
for (const change of args.changes) {
|
|
234
|
+
if (!change || typeof change !== "object")
|
|
235
|
+
continue;
|
|
236
|
+
const record = change;
|
|
237
|
+
if (typeof record.path !== "string")
|
|
238
|
+
continue;
|
|
239
|
+
paths.push({
|
|
240
|
+
path: record.path,
|
|
241
|
+
operation: record.content === null ? "delete" : record.expectedDigest === null ? "create" : "update"
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const pushCommand = (value) => {
|
|
246
|
+
if (typeof value === "string" && value.trim())
|
|
247
|
+
commands.push(value);
|
|
248
|
+
};
|
|
249
|
+
pushCommand(args.expectedScript);
|
|
250
|
+
pushCommand(args.script);
|
|
251
|
+
if (typeof args.command === "string") {
|
|
252
|
+
const extra = Array.isArray(args.args) ? args.args.filter((item) => typeof item === "string") : [];
|
|
253
|
+
commands.push([args.command, ...extra].join(" "));
|
|
254
|
+
}
|
|
255
|
+
if (Array.isArray(args.commands)) {
|
|
256
|
+
for (const entry of args.commands) {
|
|
257
|
+
if (typeof entry === "string")
|
|
258
|
+
commands.push(entry);
|
|
259
|
+
else if (entry && typeof entry === "object" && typeof entry.command === "string") {
|
|
260
|
+
const record = entry;
|
|
261
|
+
const extra = Array.isArray(record.args) ? record.args.filter((item) => typeof item === "string") : [];
|
|
262
|
+
commands.push([record.command, ...extra].join(" "));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (Array.isArray(args.checks)) {
|
|
267
|
+
for (const check of args.checks) {
|
|
268
|
+
if (check && typeof check === "object")
|
|
269
|
+
pushCommand(check.expectedScript);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return { name, paths, commands };
|
|
273
|
+
};
|
|
274
|
+
var decideBatch = (items, policy) => {
|
|
275
|
+
if (!items.length)
|
|
276
|
+
return { auto: false, reason: "manual" };
|
|
277
|
+
const results = items.map((item) => classifyApproval(approvalFacts(item.name ?? "unknown", item.arguments ?? "{}"), policy));
|
|
278
|
+
if (results.every((result) => result.decision === "auto"))
|
|
279
|
+
return { auto: true, results };
|
|
280
|
+
const blocking = results.find((result) => result.decision === "ask");
|
|
281
|
+
return { auto: false, reason: blocking && blocking.decision === "ask" ? blocking.reason : "manual" };
|
|
282
|
+
};
|
|
283
|
+
var snapshotText = (bytes) => {
|
|
284
|
+
if (bytes === null)
|
|
285
|
+
return { text: null, undoable: true };
|
|
286
|
+
if (bytes.byteLength > SNAPSHOT_BYTES || bytes.includes(0))
|
|
287
|
+
return { text: null, undoable: false };
|
|
288
|
+
const text = bytes.toString("utf8");
|
|
289
|
+
if (!bytes.equals(Buffer.from(text, "utf8")))
|
|
290
|
+
return { text: null, undoable: false };
|
|
291
|
+
return { text, undoable: true };
|
|
292
|
+
};
|
|
293
|
+
var buildSnapshots = (argumentsText, read) => {
|
|
294
|
+
let args = {};
|
|
295
|
+
try {
|
|
296
|
+
const parsed = JSON.parse(argumentsText);
|
|
297
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
298
|
+
args = parsed;
|
|
299
|
+
} catch {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
const snapshots = [];
|
|
303
|
+
if (typeof args.path === "string" && typeof args.oldText === "string" && typeof args.newText === "string") {
|
|
304
|
+
const current = read(args.path);
|
|
305
|
+
const after = current.undoable && current.text !== null && current.text.includes(args.oldText) ? current.text.replace(args.oldText, args.newText) : null;
|
|
306
|
+
snapshots.push({ path: args.path, before: current.text, after, undoable: current.undoable && after !== null });
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(args.changes)) {
|
|
309
|
+
for (const change of args.changes) {
|
|
310
|
+
if (!change || typeof change !== "object" || typeof change.path !== "string")
|
|
311
|
+
continue;
|
|
312
|
+
const record = change;
|
|
313
|
+
const current = read(record.path);
|
|
314
|
+
const after = typeof record.content === "string" ? record.content : record.content === null ? null : null;
|
|
315
|
+
const undoable = current.undoable && (typeof record.content === "string" || record.content === null);
|
|
316
|
+
snapshots.push({ path: record.path, before: current.undoable ? current.text : null, after, undoable });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return snapshots;
|
|
320
|
+
};
|
|
321
|
+
var planUndo = (entry, current) => {
|
|
322
|
+
if (!entry.snapshots.length || entry.snapshots.some((item) => !item.undoable)) {
|
|
323
|
+
return { ok: false, reason: "This auto-approval has no restorable snapshot." };
|
|
324
|
+
}
|
|
325
|
+
for (const snap of entry.snapshots) {
|
|
326
|
+
if (!current.has(snap.path))
|
|
327
|
+
return { ok: false, reason: "Current file contents are not available." };
|
|
328
|
+
if ((current.get(snap.path) ?? null) !== snap.after) {
|
|
329
|
+
return { ok: false, reason: "The file changed after the auto-approval, so it was not reverted." };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return { ok: true, writes: entry.snapshots.map((snap) => ({ path: snap.path, contents: snap.before })) };
|
|
333
|
+
};
|
|
334
|
+
var publicAutoApproval = (entry) => ({
|
|
335
|
+
id: entry.id,
|
|
336
|
+
name: entry.name,
|
|
337
|
+
mode: entry.mode,
|
|
338
|
+
reason: entry.reason,
|
|
339
|
+
timestamp: entry.timestamp,
|
|
340
|
+
paths: entry.snapshots.map((item) => item.path),
|
|
341
|
+
undoable: entry.snapshots.length > 0 && entry.snapshots.every((item) => item.undoable)
|
|
342
|
+
});
|
|
343
|
+
var safeLogFile = async (file) => {
|
|
344
|
+
try {
|
|
345
|
+
const info = await lstat(file);
|
|
346
|
+
if (info.isSymbolicLink() || !info.isFile())
|
|
347
|
+
throw new Error("AUTO_APPROVE_LOG_UNSAFE");
|
|
348
|
+
return true;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (error.code === "ENOENT")
|
|
351
|
+
return false;
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var readAutoApprovals = async (rootDir) => {
|
|
356
|
+
const file = autoApprovalLogPath(rootDir);
|
|
357
|
+
if (!await safeLogFile(file))
|
|
358
|
+
return [];
|
|
359
|
+
const text = await readFile(file, "utf8");
|
|
360
|
+
const entries = [];
|
|
361
|
+
for (const line of text.split(`
|
|
362
|
+
`)) {
|
|
363
|
+
if (!line.trim())
|
|
364
|
+
continue;
|
|
365
|
+
try {
|
|
366
|
+
entries.push(JSON.parse(line));
|
|
367
|
+
} catch {}
|
|
368
|
+
}
|
|
369
|
+
return entries;
|
|
370
|
+
};
|
|
371
|
+
var appendAutoApproval = async (rootDir, entry) => {
|
|
372
|
+
const directory = path.join(rootDir, ".zhivex-harness");
|
|
373
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
374
|
+
const file = autoApprovalLogPath(rootDir);
|
|
375
|
+
const exists = await safeLogFile(file);
|
|
376
|
+
const previous = exists ? await readFile(file, "utf8") : "";
|
|
377
|
+
const lines = [...previous.split(`
|
|
378
|
+
`).filter(Boolean), JSON.stringify(entry)].slice(-100);
|
|
379
|
+
await writeFile(file, `${lines.join(`
|
|
380
|
+
`)}
|
|
381
|
+
`, { mode: 384 });
|
|
382
|
+
};
|
|
383
|
+
var loadApprovalConfig = async (rootDir) => {
|
|
384
|
+
const file = approvalConfigPath(rootDir);
|
|
385
|
+
const exists = await safeLogFile(file);
|
|
386
|
+
if (!exists)
|
|
387
|
+
return { mode: "manual", commandAllowlist: [] };
|
|
388
|
+
return parseApprovalConfig(await readFile(file, "utf8"));
|
|
389
|
+
};
|
|
390
|
+
var writeApprovalConfig = async (rootDir, config) => {
|
|
391
|
+
const directory = path.join(rootDir, ".zhivex-harness");
|
|
392
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
393
|
+
const file = approvalConfigPath(rootDir);
|
|
394
|
+
await safeLogFile(file);
|
|
395
|
+
const stored = { mode: config.mode, commandAllowlist: parseAllowlist(config.commandAllowlist) };
|
|
396
|
+
await writeFile(file, `${JSON.stringify(stored, null, 2)}
|
|
397
|
+
`, { mode: 384 });
|
|
398
|
+
};
|
|
399
|
+
var createAutoApprovalEntry = (input) => ({
|
|
400
|
+
id: `auto_${randomUUID()}`,
|
|
401
|
+
approvalId: input.approvalId,
|
|
402
|
+
name: input.name,
|
|
403
|
+
mode: input.mode,
|
|
404
|
+
reason: input.reason,
|
|
405
|
+
timestamp: new Date().toISOString(),
|
|
406
|
+
snapshots: input.snapshots
|
|
407
|
+
});
|
|
408
|
+
var readCurrent = async (rootDir, relativePath) => {
|
|
409
|
+
if (!isInsideRoot(rootDir, relativePath))
|
|
410
|
+
return;
|
|
411
|
+
const full = path.resolve(rootDir, relativePath);
|
|
412
|
+
try {
|
|
413
|
+
const file = await readRegularFileNoFollow(full, { label: "Auto-approval snapshot", maxBytes: SNAPSHOT_BYTES });
|
|
414
|
+
const text = snapshotText(file.contents);
|
|
415
|
+
return text.undoable ? text.text : undefined;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
if (error.code === "ENOENT")
|
|
418
|
+
return null;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var readWorkspaceSnapshot = async (rootDir, relativePath) => {
|
|
423
|
+
const text = await readCurrent(rootDir, relativePath);
|
|
424
|
+
if (text === undefined)
|
|
425
|
+
return { text: null, undoable: false };
|
|
426
|
+
return { text, undoable: true };
|
|
427
|
+
};
|
|
428
|
+
var revertAutoApproval = async (rootDir, id) => {
|
|
429
|
+
const entries = await readAutoApprovals(rootDir);
|
|
430
|
+
const entry = entries.find((item) => item.id === id);
|
|
431
|
+
if (!entry)
|
|
432
|
+
return { ok: false, reason: "That auto-approval is not in the audit log." };
|
|
433
|
+
const current = new Map;
|
|
434
|
+
for (const snap of entry.snapshots) {
|
|
435
|
+
const text = await readCurrent(rootDir, snap.path);
|
|
436
|
+
if (text === undefined)
|
|
437
|
+
return { ok: false, reason: "A file in this auto-approval can no longer be read safely." };
|
|
438
|
+
current.set(snap.path, text);
|
|
439
|
+
}
|
|
440
|
+
const plan = planUndo(entry, current);
|
|
441
|
+
if (!plan.ok)
|
|
442
|
+
return plan;
|
|
443
|
+
for (const write of plan.writes) {
|
|
444
|
+
if (!isInsideRoot(rootDir, write.path))
|
|
445
|
+
return { ok: false, reason: "The snapshot path leaves the workspace." };
|
|
446
|
+
const full = path.resolve(rootDir, write.path);
|
|
447
|
+
if (write.contents === null)
|
|
448
|
+
await unlink(full).catch(() => {
|
|
449
|
+
return;
|
|
450
|
+
});
|
|
451
|
+
else
|
|
452
|
+
await writeFile(full, write.contents, "utf8");
|
|
453
|
+
}
|
|
454
|
+
return { ok: true, paths: plan.writes.map((write) => write.path) };
|
|
455
|
+
};
|
|
456
|
+
// packages/core/src/review/reveal-invisible.ts
|
|
457
|
+
var hex4 = (codePoint) => `\\u${codePoint.toString(16).padStart(4, "0")}`;
|
|
458
|
+
var hiddenEscape = (codePoint) => {
|
|
459
|
+
if (codePoint === 0)
|
|
460
|
+
return "\\0";
|
|
461
|
+
if (codePoint === 8203)
|
|
462
|
+
return "\\u200B";
|
|
463
|
+
if (codePoint === 8204)
|
|
464
|
+
return "\\u200C";
|
|
465
|
+
if (codePoint === 8205)
|
|
466
|
+
return "\\u200D";
|
|
467
|
+
if (codePoint === 8206)
|
|
468
|
+
return "\\u200E";
|
|
469
|
+
if (codePoint === 8207)
|
|
470
|
+
return "\\u200F";
|
|
471
|
+
if (codePoint === 65279)
|
|
472
|
+
return "\\uFEFF";
|
|
473
|
+
if (codePoint === 8288)
|
|
474
|
+
return "\\u2060";
|
|
475
|
+
if (codePoint === 173)
|
|
476
|
+
return "\\u00AD";
|
|
477
|
+
if (codePoint === 6158)
|
|
478
|
+
return "\\u180E";
|
|
479
|
+
if (codePoint === 1564)
|
|
480
|
+
return "\\u061C";
|
|
481
|
+
if (codePoint === 847)
|
|
482
|
+
return "\\u034F";
|
|
483
|
+
if (codePoint >= 8234 && codePoint <= 8238)
|
|
484
|
+
return hex4(codePoint);
|
|
485
|
+
if (codePoint >= 8294 && codePoint <= 8297)
|
|
486
|
+
return hex4(codePoint);
|
|
487
|
+
if (codePoint === 8232 || codePoint === 8233)
|
|
488
|
+
return hex4(codePoint);
|
|
489
|
+
if (codePoint < 32 && codePoint !== 13 || codePoint >= 127 && codePoint <= 159)
|
|
490
|
+
return hex4(codePoint);
|
|
491
|
+
if (codePoint === 917505 || codePoint >= 917536 && codePoint <= 917631)
|
|
492
|
+
return `\\u{${codePoint.toString(16)}}`;
|
|
493
|
+
return;
|
|
494
|
+
};
|
|
495
|
+
var revealInvisiblePieces = (line) => {
|
|
496
|
+
const pieces = [];
|
|
497
|
+
const push = (text, mark) => {
|
|
498
|
+
if (!text)
|
|
499
|
+
return;
|
|
500
|
+
const last = pieces.at(-1);
|
|
501
|
+
if (last && last.mark === mark)
|
|
502
|
+
last.text += text;
|
|
503
|
+
else
|
|
504
|
+
pieces.push({ text, mark });
|
|
505
|
+
};
|
|
506
|
+
const chars = [...line];
|
|
507
|
+
let trail = chars.length;
|
|
508
|
+
while (trail > 0 && (chars[trail - 1] === " " || chars[trail - 1] === "\t"))
|
|
509
|
+
trail -= 1;
|
|
510
|
+
let column = 0;
|
|
511
|
+
chars.forEach((char, index) => {
|
|
512
|
+
const inTrail = index >= trail;
|
|
513
|
+
if (char === `
|
|
514
|
+
`) {
|
|
515
|
+
push(`
|
|
516
|
+
`, false);
|
|
517
|
+
column = 0;
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (char === "\t") {
|
|
521
|
+
if (inTrail)
|
|
522
|
+
push("→", true);
|
|
523
|
+
else {
|
|
524
|
+
const width = 4 - column % 4;
|
|
525
|
+
push("→" + " ".repeat(width - 1), true);
|
|
526
|
+
column += width;
|
|
527
|
+
}
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (inTrail && char === " ") {
|
|
531
|
+
push("·", true);
|
|
532
|
+
column += 1;
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const escaped = hiddenEscape(char.codePointAt(0) ?? 0);
|
|
536
|
+
if (escaped) {
|
|
537
|
+
push(escaped, true);
|
|
538
|
+
column += escaped.length;
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
push(char, false);
|
|
542
|
+
column += 1;
|
|
543
|
+
});
|
|
544
|
+
return pieces;
|
|
545
|
+
};
|
|
546
|
+
var revealInvisible = (line) => revealInvisiblePieces(line).map((piece) => piece.text).join("");
|
|
547
|
+
var revealInvisibleText = (value) => value.split(`
|
|
548
|
+
`).map((line) => revealInvisible(line)).join(`
|
|
549
|
+
`);
|
|
550
|
+
|
|
551
|
+
// packages/core/src/compat/code-support.ts
|
|
552
|
+
var inspectCodeStateDatabase = (databasePath) => {
|
|
553
|
+
const database = new SqliteDatabase(databasePath, { create: false, readonly: true, strict: true });
|
|
554
|
+
try {
|
|
555
|
+
const integrity = database.query("PRAGMA quick_check").get()?.quick_check;
|
|
556
|
+
const tables = database.query("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => row.name);
|
|
557
|
+
const sessionVersion = tables.includes("zhivex_cli_session_schema") ? database.query("SELECT version FROM zhivex_cli_session_schema WHERE singleton = 1").get()?.version : undefined;
|
|
558
|
+
return { integrity, tables, sessionVersion };
|
|
559
|
+
} finally {
|
|
560
|
+
database.close(false);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
export { resolveAutoApprovePolicy, classifyApproval, approvalFacts, decideBatch, buildSnapshots, publicAutoApproval, readAutoApprovals, appendAutoApproval, loadApprovalConfig, writeApprovalConfig, createAutoApprovalEntry, readWorkspaceSnapshot, revertAutoApproval, revealInvisible, revealInvisibleText, inspectCodeStateDatabase };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
syncPrivateDirectory
|
|
3
|
+
} from "./index-vk3rq21m.js";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/application/assistant/telegram/store.ts
|
|
6
|
+
import { DatabaseSync } from "node:sqlite";
|
|
7
|
+
import { constants } from "node:fs";
|
|
8
|
+
import { lstat, open, unlink } from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
async function openTelegramStore(directory, recover = false) {
|
|
11
|
+
const directoryStat = await lstat(directory);
|
|
12
|
+
if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink() || directoryStat.mode & 63 || directoryStat.uid !== process.getuid?.())
|
|
13
|
+
throw new Error("TELEGRAM_STATE_UNSAFE");
|
|
14
|
+
const lockPath = path.join(directory, "telegram.lock");
|
|
15
|
+
const readPrivate = async (filename) => {
|
|
16
|
+
const file = await open(filename, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
17
|
+
try {
|
|
18
|
+
const s = await file.stat();
|
|
19
|
+
if (!s.isFile() || s.mode & 63 || s.uid !== process.getuid?.() || s.size > 4096)
|
|
20
|
+
throw new Error("TELEGRAM_STATE_UNSAFE");
|
|
21
|
+
return await file.readFile("utf8");
|
|
22
|
+
} finally {
|
|
23
|
+
await file.close();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (recover) {
|
|
27
|
+
const guardPath = path.join(directory, "telegram.recovery");
|
|
28
|
+
const guard = await open(guardPath, "wx", 384);
|
|
29
|
+
await guard.close();
|
|
30
|
+
try {
|
|
31
|
+
try {
|
|
32
|
+
const owner = JSON.parse(await readPrivate(lockPath));
|
|
33
|
+
if (!Number.isSafeInteger(owner.pid) || owner.pid <= 0)
|
|
34
|
+
throw new Error("TELEGRAM_LOCK_INVALID");
|
|
35
|
+
try {
|
|
36
|
+
process.kill(owner.pid, 0);
|
|
37
|
+
throw new Error("TELEGRAM_OWNER_ALIVE");
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== "ESRCH")
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
await unlink(lockPath);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error.code !== "ENOENT")
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
await unlink(guardPath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const lock = await open(lockPath, "wx", 384);
|
|
52
|
+
try {
|
|
53
|
+
await lock.writeFile(JSON.stringify({ pid: process.pid }));
|
|
54
|
+
await lock.sync();
|
|
55
|
+
} finally {
|
|
56
|
+
await lock.close();
|
|
57
|
+
}
|
|
58
|
+
let db;
|
|
59
|
+
try {
|
|
60
|
+
const filename = path.join(directory, "telegram.sqlite");
|
|
61
|
+
try {
|
|
62
|
+
const file = await open(filename, "wx", 384);
|
|
63
|
+
await file.close();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error.code !== "EEXIST")
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
for (const suffix of ["", "-journal", "-wal", "-shm"]) {
|
|
69
|
+
try {
|
|
70
|
+
const s = await lstat(filename + suffix);
|
|
71
|
+
if (!s.isFile() || s.isSymbolicLink() || s.mode & 63 || s.uid !== process.getuid?.())
|
|
72
|
+
throw new Error("TELEGRAM_DB_UNSAFE");
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error.code !== "ENOENT")
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
db = new DatabaseSync(filename);
|
|
79
|
+
db.exec(`PRAGMA journal_mode=DELETE; PRAGMA synchronous=FULL; PRAGMA busy_timeout=5000;
|
|
80
|
+
CREATE TABLE IF NOT EXISTS meta(key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
81
|
+
CREATE TABLE IF NOT EXISTS inbox(id INTEGER PRIMARY KEY, payload TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', intent TEXT);
|
|
82
|
+
CREATE TABLE IF NOT EXISTS outbox(id TEXT PRIMARY KEY, sequence INTEGER NOT NULL UNIQUE, payload TEXT NOT NULL,
|
|
83
|
+
status TEXT NOT NULL DEFAULT 'pending', attempts INTEGER NOT NULL DEFAULT 0, next_at INTEGER NOT NULL DEFAULT 0, message_id INTEGER);
|
|
84
|
+
CREATE TABLE IF NOT EXISTS reviews(token TEXT PRIMARY KEY, snapshot TEXT NOT NULL, delivery_id TEXT NOT NULL,
|
|
85
|
+
expires INTEGER NOT NULL, used INTEGER NOT NULL DEFAULT 0);`);
|
|
86
|
+
if (!db.prepare("PRAGMA table_info(outbox)").all().some((column) => column.name === "expires_at")) {
|
|
87
|
+
db.exec("ALTER TABLE outbox ADD COLUMN expires_at INTEGER");
|
|
88
|
+
}
|
|
89
|
+
const database = db;
|
|
90
|
+
const get = (sql, ...args) => database.prepare(sql).get(...args);
|
|
91
|
+
const all = (sql, ...args) => database.prepare(sql).all(...args);
|
|
92
|
+
const run = (sql, ...args) => database.prepare(sql).run(...args);
|
|
93
|
+
const transaction = (fn) => {
|
|
94
|
+
database.exec("BEGIN IMMEDIATE");
|
|
95
|
+
try {
|
|
96
|
+
const result = fn();
|
|
97
|
+
database.exec("COMMIT");
|
|
98
|
+
return result;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
database.exec("ROLLBACK");
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const meta = (key) => get("SELECT value FROM meta WHERE key=?", key)?.value;
|
|
105
|
+
const set = (key, value) => run("INSERT INTO meta VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value", key, value);
|
|
106
|
+
if (meta("schemaVersion") && meta("schemaVersion") !== "1")
|
|
107
|
+
throw new Error("TELEGRAM_SCHEMA_UNSUPPORTED");
|
|
108
|
+
set("schemaVersion", "1");
|
|
109
|
+
run("UPDATE outbox SET status='uncertain' WHERE status='sending'");
|
|
110
|
+
await syncPrivateDirectory(directory, "TELEGRAM_STATE_UNSAFE", directoryStat);
|
|
111
|
+
let closed = false;
|
|
112
|
+
return {
|
|
113
|
+
get,
|
|
114
|
+
all,
|
|
115
|
+
run,
|
|
116
|
+
transaction,
|
|
117
|
+
meta,
|
|
118
|
+
set,
|
|
119
|
+
async close() {
|
|
120
|
+
if (closed)
|
|
121
|
+
return;
|
|
122
|
+
closed = true;
|
|
123
|
+
database.close();
|
|
124
|
+
await unlink(lockPath);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
db?.close();
|
|
129
|
+
await unlink(lockPath);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { openTelegramStore };
|