@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
|
@@ -5,34 +5,301 @@ import {
|
|
|
5
5
|
taskAcceptanceOutcome,
|
|
6
6
|
taskCheckReceiptSchema,
|
|
7
7
|
workspaceFilePathSchema
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-f970qtb4.js";
|
|
9
9
|
import {
|
|
10
10
|
HarnessConfigError,
|
|
11
11
|
HarnessStateConflictError,
|
|
12
12
|
HarnessWorkspaceError
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-xwb691v9.js";
|
|
14
14
|
|
|
15
|
-
// src/
|
|
15
|
+
// packages/core/src/runtime/task-acceptance.ts
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
var identifier = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/);
|
|
19
|
+
var text = (maximum) => z.string().min(1).max(maximum).refine((value) => value.trim().length > 0 && !/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(value), "Text must be nonblank and contain no control characters.");
|
|
20
|
+
var exactPath = workspaceFilePathSchema.refine((value) => !/[\\*?\[\]{}\x00-\x1f\x7f]/.test(value), "Use an exact normalized file path, without globs or controls.");
|
|
21
|
+
var argv = z.array(z.string().max(8192).refine((value) => !value.includes("\x00"), "Arguments cannot contain NUL.")).max(256);
|
|
22
|
+
var command = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/).refine((value) => !["sh", "bash", "dash", "zsh", "fish", "cmd", "cmd.exe", "powershell", "pwsh"].includes(value.toLowerCase()), "Shell interpreters are not acceptance checks.");
|
|
23
|
+
var commonCheck = { id: identifier, command, args: argv, purpose: text(500) };
|
|
24
|
+
var check = z.discriminatedUnion("kind", [
|
|
25
|
+
z.strictObject({
|
|
26
|
+
...commonCheck,
|
|
27
|
+
kind: z.literal("package-script"),
|
|
28
|
+
script: identifier,
|
|
29
|
+
expectedScript: text(8192),
|
|
30
|
+
execution: z.strictObject({ backend: z.enum(["none", "oci"]), approval: z.literal("required") })
|
|
31
|
+
}),
|
|
32
|
+
z.strictObject({
|
|
33
|
+
...commonCheck,
|
|
34
|
+
kind: z.literal("argv"),
|
|
35
|
+
execution: z.strictObject({ backend: z.literal("oci"), approval: z.literal("required"), network: z.literal("none") })
|
|
36
|
+
})
|
|
37
|
+
]);
|
|
38
|
+
var taskAcceptanceContractSchema = z.strictObject({
|
|
39
|
+
schemaVersion: z.literal(1),
|
|
40
|
+
taskId: identifier,
|
|
41
|
+
allowedWritePaths: z.array(exactPath).max(256),
|
|
42
|
+
protectedFiles: z.array(exactPath).max(256),
|
|
43
|
+
requiredChecks: z.array(check).min(1).max(32),
|
|
44
|
+
humanReview: z.array(z.strictObject({ id: identifier, requirement: text(2000), status: z.literal("pending") })).max(32)
|
|
45
|
+
}).superRefine((contract, context) => {
|
|
46
|
+
const unique = (values, field) => {
|
|
47
|
+
if (new Set(values).size !== values.length)
|
|
48
|
+
context.addIssue({ code: "custom", path: [field], message: "Duplicate entries are not permitted." });
|
|
49
|
+
};
|
|
50
|
+
unique(contract.allowedWritePaths.map((p) => p.toLowerCase()), "allowedWritePaths");
|
|
51
|
+
unique(contract.protectedFiles.map((p) => p.toLowerCase()), "protectedFiles");
|
|
52
|
+
unique(contract.requiredChecks.map((c) => c.id), "requiredChecks");
|
|
53
|
+
unique(contract.humanReview.map((c) => c.id), "humanReview");
|
|
54
|
+
const overlaps = (a, b) => a === b || a.startsWith(b + "/") || b.startsWith(a + "/");
|
|
55
|
+
const writes = contract.allowedWritePaths.map((p) => p.toLowerCase());
|
|
56
|
+
if (writes.some((p, i) => writes.slice(i + 1).some((q) => overlaps(p, q)))) {
|
|
57
|
+
context.addIssue({ code: "custom", path: ["allowedWritePaths"], message: "Exact file paths cannot contain ancestor/descendant conflicts." });
|
|
58
|
+
}
|
|
59
|
+
if (writes.some((p) => contract.protectedFiles.some((q) => overlaps(p, q.toLowerCase())))) {
|
|
60
|
+
context.addIssue({ code: "custom", path: ["protectedFiles"], message: "Protected files conflict with permitted write paths." });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var MAX_TASK_ACCEPTANCE_BYTES = 64 * 1024;
|
|
64
|
+
function compileTaskAcceptanceContract(input) {
|
|
65
|
+
let bytes;
|
|
66
|
+
try {
|
|
67
|
+
bytes = Buffer.byteLength(JSON.stringify(input));
|
|
68
|
+
} catch {
|
|
69
|
+
throw new Error("TASK_ACCEPTANCE_INVALID: requirements must be JSON serializable.");
|
|
70
|
+
}
|
|
71
|
+
if (bytes > MAX_TASK_ACCEPTANCE_BYTES)
|
|
72
|
+
throw new Error("TASK_ACCEPTANCE_TOO_LARGE: requirements exceed 64 KiB.");
|
|
73
|
+
const parsed = taskAcceptanceContractSchema.safeParse(input);
|
|
74
|
+
if (!parsed.success)
|
|
75
|
+
throw new Error("TASK_ACCEPTANCE_INVALID: " + parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; "));
|
|
76
|
+
const sorted = (items) => items.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
77
|
+
const contract = {
|
|
78
|
+
schemaVersion: 1,
|
|
79
|
+
taskId: parsed.data.taskId,
|
|
80
|
+
allowedWritePaths: [...parsed.data.allowedWritePaths].sort(),
|
|
81
|
+
protectedFiles: [...parsed.data.protectedFiles].sort(),
|
|
82
|
+
requiredChecks: sorted(parsed.data.requiredChecks),
|
|
83
|
+
humanReview: sorted(parsed.data.humanReview)
|
|
84
|
+
};
|
|
85
|
+
return { contract, digest: `sha256:${createHash("sha256").update(JSON.stringify(contract)).digest("hex")}` };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// packages/core/src/runtime/task-acceptance-record.ts
|
|
89
|
+
import { z as z2 } from "zod";
|
|
90
|
+
import { serializeJsonValue } from "@zhivex-ai/core";
|
|
91
|
+
var TASK_ACCEPTANCE_KEY = "zhivexTaskAcceptanceV1";
|
|
92
|
+
var TASK_ACCEPTANCE_EVIDENCE_KEY = "zhivexTaskAcceptanceEvidenceV1";
|
|
93
|
+
var digest = z2.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
94
|
+
var revisionSchema = z2.strictObject({ revision: z2.number().int().min(1), digest, previousDigest: digest.nullable(), contract: taskAcceptanceContractSchema });
|
|
95
|
+
var ledgerSchema = z2.strictObject({ schemaVersion: z2.literal(1), revisions: z2.array(revisionSchema).min(1).max(16) });
|
|
96
|
+
function readTaskAcceptanceLedger(state) {
|
|
97
|
+
const raw = state.metadata?.[TASK_ACCEPTANCE_KEY];
|
|
98
|
+
if (raw === undefined)
|
|
99
|
+
return;
|
|
100
|
+
if (Buffer.byteLength(JSON.stringify(raw)) > 1024 * 1024)
|
|
101
|
+
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
102
|
+
const ledger = ledgerSchema.parse(raw);
|
|
103
|
+
for (let index = 0;index < ledger.revisions.length; index++) {
|
|
104
|
+
const row = ledger.revisions[index];
|
|
105
|
+
if (row.revision !== index + 1 || row.previousDigest !== (ledger.revisions[index - 1]?.digest ?? null) || compileTaskAcceptanceContract(row.contract).digest !== row.digest || row.contract.taskId !== ledger.revisions[0].contract.taskId) {
|
|
106
|
+
throw new Error("TASK_ACCEPTANCE_HISTORY_INVALID");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return ledger;
|
|
110
|
+
}
|
|
111
|
+
function nextTaskAcceptanceLedger(current, requirements) {
|
|
112
|
+
if (current)
|
|
113
|
+
current = readTaskAcceptanceLedger({ metadata: { [TASK_ACCEPTANCE_KEY]: serializeJsonValue(current) } });
|
|
114
|
+
const { contract, digest: digest2 } = compileTaskAcceptanceContract(requirements);
|
|
115
|
+
const previous = current?.revisions.at(-1);
|
|
116
|
+
if (previous && previous.contract.taskId !== contract.taskId)
|
|
117
|
+
throw new Error("TASK_ACCEPTANCE_TASK_ID_IMMUTABLE");
|
|
118
|
+
if (previous?.digest === digest2)
|
|
119
|
+
throw new Error("TASK_ACCEPTANCE_UNCHANGED");
|
|
120
|
+
if ((current?.revisions.length ?? 0) >= 16)
|
|
121
|
+
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
122
|
+
const next = { schemaVersion: 1, revisions: [...structuredClone(current?.revisions ?? []), {
|
|
123
|
+
revision: (previous?.revision ?? 0) + 1,
|
|
124
|
+
previousDigest: previous?.digest ?? null,
|
|
125
|
+
digest: digest2,
|
|
126
|
+
contract
|
|
127
|
+
}] };
|
|
128
|
+
if (Buffer.byteLength(JSON.stringify(next)) > 1024 * 1024)
|
|
129
|
+
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
130
|
+
return next;
|
|
131
|
+
}
|
|
132
|
+
async function persistTaskAcceptanceRevision(store, options) {
|
|
133
|
+
const state = await store.load(options.runId, options.scope);
|
|
134
|
+
if (!state || state.revision !== options.expectedRunRevision)
|
|
135
|
+
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
136
|
+
const current = readTaskAcceptanceLedger(state);
|
|
137
|
+
if ((current?.revisions.at(-1)?.revision ?? 0) !== options.expectedContractRevision)
|
|
138
|
+
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
139
|
+
const ledger = nextTaskAcceptanceLedger(current, options.requirements), latest = ledger.revisions.at(-1);
|
|
140
|
+
const prior = current?.revisions.at(-1);
|
|
141
|
+
const oldEvidence = state.metadata?.[TASK_ACCEPTANCE_EVIDENCE_KEY];
|
|
142
|
+
const sameFiles = prior && JSON.stringify([prior.contract.allowedWritePaths, prior.contract.protectedFiles]) === JSON.stringify([latest.contract.allowedWritePaths, latest.contract.protectedFiles]);
|
|
143
|
+
const previousChecks = z2.array(taskCheckReceiptSchema).max(32).safeParse(oldEvidence?.checks);
|
|
144
|
+
const checks = sameFiles && previousChecks.success ? previousChecks.data.filter((receipt) => receipt.contractDigest === prior.digest && receipt.contractRevision === prior.revision && JSON.stringify(prior.contract.requiredChecks.find((check2) => check2.id === receipt.checkId)) === JSON.stringify(latest.contract.requiredChecks.find((check2) => check2.id === receipt.checkId))).map((receipt) => ({ ...receipt, contractDigest: latest.digest, contractRevision: latest.revision })) : [];
|
|
145
|
+
await store.save({ ...state, metadata: {
|
|
146
|
+
...state.metadata,
|
|
147
|
+
[TASK_ACCEPTANCE_KEY]: serializeJsonValue(ledger),
|
|
148
|
+
[TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
149
|
+
schemaVersion: 1,
|
|
150
|
+
contractRevision: latest.revision,
|
|
151
|
+
contractDigest: latest.digest,
|
|
152
|
+
status: "pending",
|
|
153
|
+
checks,
|
|
154
|
+
humanReview: latest.contract.humanReview,
|
|
155
|
+
...sameFiles && oldEvidence?.delivery ? { delivery: oldEvidence.delivery } : {}
|
|
156
|
+
})
|
|
157
|
+
} }, { expectedRevision: options.expectedRunRevision });
|
|
158
|
+
return structuredClone(ledger);
|
|
159
|
+
}
|
|
160
|
+
function taskAcceptanceCheckpointStore(store, runId, ledger) {
|
|
161
|
+
const retained = serializeJsonValue(structuredClone(ledger));
|
|
162
|
+
const latest = ledger.revisions.at(-1);
|
|
163
|
+
const pending = { schemaVersion: 1, contractRevision: latest.revision, contractDigest: latest.digest, status: "pending", checks: [], humanReview: serializeJsonValue(latest.contract.humanReview) };
|
|
164
|
+
return new Proxy(store, { get(target, key) {
|
|
165
|
+
if (key === "save")
|
|
166
|
+
return async (...args) => {
|
|
167
|
+
const [state] = args;
|
|
168
|
+
if (state.runId === runId) {
|
|
169
|
+
const violation = taskAcceptanceDeliveryDiagnostic(latest.digest, latest.revision);
|
|
170
|
+
state.metadata = { ...state.metadata, [TASK_ACCEPTANCE_KEY]: structuredClone(retained), [TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
171
|
+
...structuredClone(pending),
|
|
172
|
+
...await taskAcceptanceOutcome(state, ledger),
|
|
173
|
+
checks: serializeJsonValue(taskAcceptanceChecks()?.snapshot() ?? []),
|
|
174
|
+
...violation ? { status: "failed", diagnostic: serializeJsonValue(violation) } : {}
|
|
175
|
+
}) };
|
|
176
|
+
}
|
|
177
|
+
return target.save(...args);
|
|
178
|
+
};
|
|
179
|
+
const value = Reflect.get(target, key, target);
|
|
180
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
181
|
+
} });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// packages/core/src/runtime/runtime-diagnostics.ts
|
|
185
|
+
import { z as z3 } from "zod";
|
|
186
|
+
import { createRedactionPolicy } from "@zhivex-ai/agents";
|
|
187
|
+
var count = z3.number().int().nonnegative().finite();
|
|
188
|
+
var digest2 = z3.string().regex(/^sha256:[a-f0-9]{64}$/).nullable();
|
|
189
|
+
var diagnosticsSchema = z3.object({
|
|
190
|
+
schemaVersion: z3.literal(2),
|
|
191
|
+
requireVerifiedDelivery: z3.boolean(),
|
|
192
|
+
budget: z3.object({
|
|
193
|
+
inputTokens: count,
|
|
194
|
+
outputTokens: count,
|
|
195
|
+
cachedInputTokens: count,
|
|
196
|
+
modelCalls: count,
|
|
197
|
+
usageComplete: z3.boolean(),
|
|
198
|
+
inFlight: z3.boolean(),
|
|
199
|
+
stopReason: z3.enum(["USAGE_UNAVAILABLE", "WORK_TOKEN_BUDGET", "INPUT_TOKEN_BUDGET", "OUTPUT_TOKEN_BUDGET"]).nullable(),
|
|
200
|
+
reservedInputTokens: count,
|
|
201
|
+
reservedOutputTokens: count,
|
|
202
|
+
predictedInputTokens: count,
|
|
203
|
+
outputCapApplied: z3.boolean().default(false)
|
|
204
|
+
}),
|
|
205
|
+
phase: z3.enum(["explore", "reproduce", "candidate", "verify", "recover", "delivered", "incomplete"]),
|
|
206
|
+
candidate: digest2,
|
|
207
|
+
revision: count,
|
|
208
|
+
checks: z3.array(z3.object({
|
|
209
|
+
commandId: z3.string().max(128),
|
|
210
|
+
purpose: z3.string().max(500),
|
|
211
|
+
argvDigest: digest2,
|
|
212
|
+
candidate: digest2,
|
|
213
|
+
exitCode: z3.number().int(),
|
|
214
|
+
verified: z3.boolean()
|
|
215
|
+
})).max(8),
|
|
216
|
+
contextMeasurements: z3.array(z3.object({
|
|
217
|
+
systemCharacters: count,
|
|
218
|
+
userCharacters: count,
|
|
219
|
+
assistantCharacters: count,
|
|
220
|
+
toolResultCharacters: count,
|
|
221
|
+
otherMessageCharacters: count,
|
|
222
|
+
toolDefinitionCharacters: count,
|
|
223
|
+
unmeasuredToolDefinitions: count
|
|
224
|
+
})).max(128),
|
|
225
|
+
modelTimings: z3.array(z3.object({ durationMs: z3.number().nonnegative().finite(), firstTokenMs: z3.number().nonnegative().finite().nullable(), completed: z3.boolean() })).max(128),
|
|
226
|
+
omittedContextMeasurements: count
|
|
227
|
+
});
|
|
228
|
+
var manifestSchema = z3.object({
|
|
229
|
+
schemaVersion: z3.literal(2),
|
|
230
|
+
policyVersion: z3.literal("assistant-v3-durable-closure"),
|
|
231
|
+
role: z3.string().max(128),
|
|
232
|
+
requireVerifiedDelivery: z3.boolean(),
|
|
233
|
+
backend: z3.enum(["none", "oci"]),
|
|
234
|
+
tools: z3.array(z3.string().max(128)).max(1024),
|
|
235
|
+
budget: z3.object({ unlimitedTokens: z3.boolean().optional(), unlimitedSteps: z3.boolean().optional(), unlimitedToolCalls: z3.boolean().optional(), maxSteps: count, maxToolCalls: count, maxToolErrors: count, maxInputTokens: count, maxOutputTokens: count, includeChildRuns: z3.boolean() }),
|
|
236
|
+
timeoutMs: count,
|
|
237
|
+
unlimitedDuration: z3.boolean().optional(),
|
|
238
|
+
closureController: z3.boolean(),
|
|
239
|
+
contextEnabled: z3.boolean()
|
|
240
|
+
});
|
|
241
|
+
var redact = createRedactionPolicy({ includeEmails: true });
|
|
242
|
+
var inspectRuntimeDiagnostics = (value) => {
|
|
243
|
+
const parsed = diagnosticsSchema.safeParse(value);
|
|
244
|
+
if (!parsed.success)
|
|
245
|
+
return null;
|
|
246
|
+
return { ...parsed.data, checks: parsed.data.checks.map((check2) => ({
|
|
247
|
+
...check2,
|
|
248
|
+
commandId: redact.redactText(check2.commandId),
|
|
249
|
+
purpose: redact.redactText(check2.purpose)
|
|
250
|
+
})) };
|
|
251
|
+
};
|
|
252
|
+
var inspectRuntimeManifest = (value) => {
|
|
253
|
+
const parsed = manifestSchema.safeParse(value);
|
|
254
|
+
if (!parsed.success)
|
|
255
|
+
return null;
|
|
256
|
+
return { ...parsed.data, role: redact.redactText(parsed.data.role), tools: parsed.data.tools.map((name) => redact.redactText(name)) };
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// packages/core/src/persistence/migration-guard.ts
|
|
16
260
|
import { lstat } from "node:fs/promises";
|
|
17
261
|
import path from "node:path";
|
|
262
|
+
var MIGRATION_MARKER = ".zhivex-migration.json";
|
|
263
|
+
async function assertNoApplicationMigration(directory) {
|
|
264
|
+
let current = path.resolve(directory);
|
|
265
|
+
for (;; ) {
|
|
266
|
+
try {
|
|
267
|
+
await lstat(path.join(current, MIGRATION_MARKER));
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (error.code !== "ENOENT")
|
|
270
|
+
throw error;
|
|
271
|
+
const parent = path.dirname(current);
|
|
272
|
+
if (parent === current)
|
|
273
|
+
return;
|
|
274
|
+
current = parent;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
throw new Error("APPLICATION_MIGRATION_RECOVERY_REQUIRED");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// packages/core/src/persistence/state-directory.ts
|
|
282
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
283
|
+
import path2 from "node:path";
|
|
18
284
|
var SENSITIVE_STATE_SEGMENTS = new Set([".git", ".env", ".npmrc", "dist", "node_modules", "src"]);
|
|
19
285
|
var isInside = (root, candidate) => {
|
|
20
|
-
const relative =
|
|
21
|
-
return relative === "" || !relative.startsWith(`..${
|
|
286
|
+
const relative = path2.relative(root, candidate);
|
|
287
|
+
return relative === "" || !relative.startsWith(`..${path2.sep}`) && relative !== ".." && !path2.isAbsolute(relative);
|
|
22
288
|
};
|
|
23
289
|
var validateStateDirectory = async (workspace, stateDirectory) => {
|
|
24
|
-
|
|
290
|
+
await assertNoApplicationMigration(stateDirectory);
|
|
291
|
+
if (stateDirectory === workspace || stateDirectory === path2.parse(stateDirectory).root) {
|
|
25
292
|
throw new HarnessWorkspaceError("The state directory cannot be the workspace or filesystem root.");
|
|
26
293
|
}
|
|
27
294
|
const insideWorkspace = isInside(workspace, stateDirectory);
|
|
28
|
-
const relativeSegments = insideWorkspace ?
|
|
295
|
+
const relativeSegments = insideWorkspace ? path2.relative(workspace, stateDirectory).split(path2.sep).filter(Boolean) : stateDirectory.slice(path2.parse(stateDirectory).root.length).split(path2.sep).filter(Boolean);
|
|
29
296
|
const sensitiveSegment = insideWorkspace ? relativeSegments.find((segment) => SENSITIVE_STATE_SEGMENTS.has(segment)) : undefined;
|
|
30
297
|
if (sensitiveSegment) {
|
|
31
298
|
throw new HarnessWorkspaceError(`The state directory is inside the protected workspace path: ${sensitiveSegment}.`);
|
|
32
299
|
}
|
|
33
300
|
if (!insideWorkspace) {
|
|
34
301
|
try {
|
|
35
|
-
const externalEntry = await
|
|
302
|
+
const externalEntry = await lstat2(stateDirectory);
|
|
36
303
|
if (externalEntry.isSymbolicLink()) {
|
|
37
304
|
throw new HarnessWorkspaceError(`The state directory must not be a symbolic link: ${stateDirectory}.`);
|
|
38
305
|
}
|
|
@@ -48,9 +315,9 @@ var validateStateDirectory = async (workspace, stateDirectory) => {
|
|
|
48
315
|
}
|
|
49
316
|
let current = workspace;
|
|
50
317
|
for (const segment of relativeSegments) {
|
|
51
|
-
current =
|
|
318
|
+
current = path2.join(current, segment);
|
|
52
319
|
try {
|
|
53
|
-
const entry = await
|
|
320
|
+
const entry = await lstat2(current);
|
|
54
321
|
if (entry.isSymbolicLink()) {
|
|
55
322
|
throw new HarnessWorkspaceError(`The state directory must not resolve through a symbolic link: ${current}.`);
|
|
56
323
|
}
|
|
@@ -66,29 +333,29 @@ var validateStateDirectory = async (workspace, stateDirectory) => {
|
|
|
66
333
|
}
|
|
67
334
|
};
|
|
68
335
|
|
|
69
|
-
// src/persistence/sessions.ts
|
|
70
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
71
|
-
import { chmod, lstat as
|
|
72
|
-
import
|
|
73
|
-
import { createRedactionPolicy } from "@zhivex-ai/agents";
|
|
336
|
+
// packages/core/src/persistence/sessions.ts
|
|
337
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
338
|
+
import { chmod, lstat as lstat4, mkdir, open as open2, realpath, stat } from "node:fs/promises";
|
|
339
|
+
import path4 from "node:path";
|
|
340
|
+
import { createRedactionPolicy as createRedactionPolicy2 } from "@zhivex-ai/agents";
|
|
74
341
|
|
|
75
|
-
// src/persistence/state-gitignore.ts
|
|
342
|
+
// packages/core/src/persistence/state-gitignore.ts
|
|
76
343
|
import { constants } from "node:fs";
|
|
77
|
-
import { lstat as
|
|
78
|
-
import
|
|
344
|
+
import { lstat as lstat3, open } from "node:fs/promises";
|
|
345
|
+
import path3 from "node:path";
|
|
79
346
|
var exclusion = `# Local Harness state; never commit sessions, runs, or database journals.
|
|
80
347
|
*
|
|
81
348
|
`;
|
|
82
349
|
var maximumExistingBytes = 65536;
|
|
83
350
|
var maximumProtectedBytes = maximumExistingBytes + Buffer.byteLength(exclusion) + 1;
|
|
84
351
|
async function protectStateFromGit(workspace, stateDirectory) {
|
|
85
|
-
const directory =
|
|
86
|
-
const filename =
|
|
352
|
+
const directory = path3.resolve(stateDirectory) === path3.join(workspace, ".zhivex-harness", "runs") ? path3.dirname(stateDirectory) : stateDirectory;
|
|
353
|
+
const filename = path3.join(directory, ".gitignore");
|
|
87
354
|
try {
|
|
88
355
|
const handle = await open(filename, constants.O_RDWR | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW, 384);
|
|
89
356
|
try {
|
|
90
357
|
const info = await handle.stat();
|
|
91
|
-
const entry = await
|
|
358
|
+
const entry = await lstat3(filename);
|
|
92
359
|
if (entry.isSymbolicLink() || entry.dev !== info.dev || entry.ino !== info.ino)
|
|
93
360
|
throw new Error;
|
|
94
361
|
if (!info.isFile() || info.nlink !== 1 || process.getuid && info.uid !== process.getuid() || info.size > maximumProtectedBytes)
|
|
@@ -105,7 +372,7 @@ async function protectStateFromGit(workspace, stateDirectory) {
|
|
|
105
372
|
`) ? `
|
|
106
373
|
` : ""}${exclusion}`);
|
|
107
374
|
}
|
|
108
|
-
const current = await
|
|
375
|
+
const current = await lstat3(filename);
|
|
109
376
|
if (current.isSymbolicLink() || current.dev !== info.dev || current.ino !== info.ino)
|
|
110
377
|
throw new Error;
|
|
111
378
|
} finally {
|
|
@@ -116,7 +383,7 @@ async function protectStateFromGit(workspace, stateDirectory) {
|
|
|
116
383
|
}
|
|
117
384
|
}
|
|
118
385
|
|
|
119
|
-
// src/persistence/sessions.ts
|
|
386
|
+
// packages/core/src/persistence/sessions.ts
|
|
120
387
|
var HARNESS_SESSION_INDEX_FILE = "operations.sqlite";
|
|
121
388
|
var HARNESS_SESSION_SCHEMA_VERSION = 1;
|
|
122
389
|
var SESSION_RUN_STATUSES = [
|
|
@@ -159,7 +426,7 @@ var STATUS_TRANSITIONS = {
|
|
|
159
426
|
cancelled: new Set(["cancelled"]),
|
|
160
427
|
timed_out: new Set(["timed_out"])
|
|
161
428
|
};
|
|
162
|
-
var metadataRedaction =
|
|
429
|
+
var metadataRedaction = createRedactionPolicy2({
|
|
163
430
|
includeEmails: true,
|
|
164
431
|
rules: [
|
|
165
432
|
{ name: "private-key", pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g },
|
|
@@ -215,30 +482,30 @@ var normalizeScope = (scope) => {
|
|
|
215
482
|
const namespace = scope.namespace === undefined ? "" : assertScopeSegment("scope.namespace", scope.namespace);
|
|
216
483
|
return `${tenantId}\x00${userId}\x00${namespace}`;
|
|
217
484
|
};
|
|
218
|
-
var stableKey = (kind, value) =>
|
|
485
|
+
var stableKey = (kind, value) => createHash2("sha256").update(kind).update("\x00").update(value).digest("hex");
|
|
219
486
|
var sessionId = () => `ses_${randomUUID()}`;
|
|
220
487
|
var turnId = () => `turn_${randomUUID()}`;
|
|
221
488
|
var ensurePrivateDatabase = async (workspace, stateDirectory) => {
|
|
222
|
-
const requestedStateDirectory =
|
|
489
|
+
const requestedStateDirectory = path4.resolve(stateDirectory);
|
|
223
490
|
await validateStateDirectory(workspace, requestedStateDirectory);
|
|
224
491
|
await mkdir(requestedStateDirectory, { recursive: true, mode: 448 });
|
|
225
|
-
const directoryEntry = await
|
|
492
|
+
const directoryEntry = await lstat4(requestedStateDirectory);
|
|
226
493
|
if (directoryEntry.isSymbolicLink() || !directoryEntry.isDirectory()) {
|
|
227
494
|
throw new HarnessWorkspaceError(`The session state directory must be a real directory: ${requestedStateDirectory}.`);
|
|
228
495
|
}
|
|
229
496
|
await chmod(requestedStateDirectory, 448);
|
|
230
497
|
const canonicalStateDirectory = await realpath(requestedStateDirectory);
|
|
231
498
|
await protectStateFromGit(workspace, canonicalStateDirectory);
|
|
232
|
-
const databasePath =
|
|
499
|
+
const databasePath = path4.join(canonicalStateDirectory, HARNESS_SESSION_INDEX_FILE);
|
|
233
500
|
let databaseEntry;
|
|
234
501
|
try {
|
|
235
502
|
const handle = await open2(databasePath, "wx", 384);
|
|
236
503
|
await handle.close();
|
|
237
|
-
databaseEntry = await
|
|
504
|
+
databaseEntry = await lstat4(databasePath);
|
|
238
505
|
} catch (error) {
|
|
239
506
|
if (error.code !== "EEXIST")
|
|
240
507
|
throw error;
|
|
241
|
-
databaseEntry = await
|
|
508
|
+
databaseEntry = await lstat4(databasePath);
|
|
242
509
|
}
|
|
243
510
|
if (databaseEntry.isSymbolicLink() || !databaseEntry.isFile()) {
|
|
244
511
|
throw new HarnessWorkspaceError(`The session SQLite path must be a real file: ${databasePath}.`);
|
|
@@ -262,7 +529,7 @@ var toRunReference = (row) => ({
|
|
|
262
529
|
var metadataSize = (input) => Object.values(input).reduce((total, value) => total + (typeof value === "string" ? byteLength(value) : 0), 0);
|
|
263
530
|
var isTerminal = (status) => TERMINAL_STATUSES.has(status);
|
|
264
531
|
var openCliSessionStore = async (options) => {
|
|
265
|
-
const workspace = await realpath(
|
|
532
|
+
const workspace = await realpath(path4.resolve(options.workspace));
|
|
266
533
|
const workspaceEntry = await stat(workspace);
|
|
267
534
|
if (!workspaceEntry.isDirectory()) {
|
|
268
535
|
throw new HarnessWorkspaceError(`The session workspace is not a directory: ${workspace}.`);
|
|
@@ -400,7 +667,7 @@ var openCliSessionStore = async (options) => {
|
|
|
400
667
|
`).run(candidateTurnId, sourceTurnId ?? null, candidateSessionId, sequence, runId, provider, model, role, status, createdAt, isTerminal(status) ? createdAt : null, entryBytes);
|
|
401
668
|
};
|
|
402
669
|
try {
|
|
403
|
-
const openedEntry = await
|
|
670
|
+
const openedEntry = await lstat4(databasePath);
|
|
404
671
|
if (openedEntry.isSymbolicLink() || !openedEntry.isFile() || openedEntry.dev !== databaseEntry.dev || openedEntry.ino !== databaseEntry.ino) {
|
|
405
672
|
throw new HarnessWorkspaceError(`The session SQLite path changed while it was being opened: ${databasePath}.`);
|
|
406
673
|
}
|
|
@@ -493,11 +760,11 @@ var openCliSessionStore = async (options) => {
|
|
|
493
760
|
WHERE workspace_key = ?1 AND scope_key = ?2 AND updated_at < ?3
|
|
494
761
|
AND (archived_at IS NOT NULL OR deleted_at IS NOT NULL)
|
|
495
762
|
`).run(workspaceKey, scopeKey, cutoff);
|
|
496
|
-
const
|
|
763
|
+
const count2 = database.query(`
|
|
497
764
|
SELECT COUNT(*) AS count FROM zhivex_cli_sessions
|
|
498
765
|
WHERE workspace_key = ?1 AND scope_key = ?2
|
|
499
766
|
`).get(workspaceKey, scopeKey)?.count ?? 0;
|
|
500
|
-
if (
|
|
767
|
+
if (count2 >= maxSessions) {
|
|
501
768
|
throw new HarnessStateConflictError(`Session limit reached for this workspace and scope (${maxSessions}). Archive and prune an older session.`);
|
|
502
769
|
}
|
|
503
770
|
const createdAt = now();
|
|
@@ -623,11 +890,11 @@ var openCliSessionStore = async (options) => {
|
|
|
623
890
|
throw new HarnessStateConflictError(`Run ${input.runId} is already immutably bound to ${existing.provider}/${existing.model} in this session.`);
|
|
624
891
|
}
|
|
625
892
|
assertNoActiveRun(candidateSessionId, "start another run in");
|
|
626
|
-
const
|
|
627
|
-
if (
|
|
893
|
+
const count2 = database.query("SELECT COUNT(*) AS count FROM zhivex_cli_session_runs WHERE session_id = ?1").get(candidateSessionId)?.count ?? 0;
|
|
894
|
+
if (count2 >= maxRuns) {
|
|
628
895
|
throw new HarnessStateConflictError(`Run-reference limit reached for session ${candidateSessionId} (${maxRuns}).`);
|
|
629
896
|
}
|
|
630
|
-
insertRun(candidateSessionId, input,
|
|
897
|
+
insertRun(candidateSessionId, input, count2);
|
|
631
898
|
const updatedAt = now();
|
|
632
899
|
assertTimestamp("now", updatedAt);
|
|
633
900
|
const activitySequence = nextActivitySequence();
|
|
@@ -703,11 +970,11 @@ var openCliSessionStore = async (options) => {
|
|
|
703
970
|
if (forkRuns.length > maxRuns) {
|
|
704
971
|
throw new HarnessStateConflictError(`Fork history exceeds the ${maxRuns}-run limit.`);
|
|
705
972
|
}
|
|
706
|
-
const
|
|
973
|
+
const count2 = database.query(`
|
|
707
974
|
SELECT COUNT(*) AS count FROM zhivex_cli_sessions
|
|
708
975
|
WHERE workspace_key = ?1 AND scope_key = ?2
|
|
709
976
|
`).get(workspaceKey, scopeKey)?.count ?? 0;
|
|
710
|
-
if (
|
|
977
|
+
if (count2 >= maxSessions) {
|
|
711
978
|
throw new HarnessStateConflictError(`Session limit reached for this workspace and scope (${maxSessions}).`);
|
|
712
979
|
}
|
|
713
980
|
const createdAt = now();
|
|
@@ -773,106 +1040,31 @@ var openCliSessionStore = async (options) => {
|
|
|
773
1040
|
};
|
|
774
1041
|
var openSessionStore = openCliSessionStore;
|
|
775
1042
|
|
|
776
|
-
// src/runtime/
|
|
777
|
-
import { z } from "zod";
|
|
778
|
-
import { createRedactionPolicy as createRedactionPolicy2 } from "@zhivex-ai/agents";
|
|
779
|
-
var count = z.number().int().nonnegative().finite();
|
|
780
|
-
var digest = z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable();
|
|
781
|
-
var diagnosticsSchema = z.object({
|
|
782
|
-
schemaVersion: z.literal(2),
|
|
783
|
-
requireVerifiedDelivery: z.boolean(),
|
|
784
|
-
budget: z.object({
|
|
785
|
-
inputTokens: count,
|
|
786
|
-
outputTokens: count,
|
|
787
|
-
cachedInputTokens: count,
|
|
788
|
-
modelCalls: count,
|
|
789
|
-
usageComplete: z.boolean(),
|
|
790
|
-
inFlight: z.boolean(),
|
|
791
|
-
stopReason: z.enum(["USAGE_UNAVAILABLE", "WORK_TOKEN_BUDGET", "INPUT_TOKEN_BUDGET", "OUTPUT_TOKEN_BUDGET"]).nullable(),
|
|
792
|
-
reservedInputTokens: count,
|
|
793
|
-
reservedOutputTokens: count,
|
|
794
|
-
predictedInputTokens: count,
|
|
795
|
-
outputCapApplied: z.boolean().default(false)
|
|
796
|
-
}),
|
|
797
|
-
phase: z.enum(["explore", "reproduce", "candidate", "verify", "recover", "delivered", "incomplete"]),
|
|
798
|
-
candidate: digest,
|
|
799
|
-
revision: count,
|
|
800
|
-
checks: z.array(z.object({
|
|
801
|
-
commandId: z.string().max(128),
|
|
802
|
-
purpose: z.string().max(500),
|
|
803
|
-
argvDigest: digest,
|
|
804
|
-
candidate: digest,
|
|
805
|
-
exitCode: z.number().int(),
|
|
806
|
-
verified: z.boolean()
|
|
807
|
-
})).max(8),
|
|
808
|
-
contextMeasurements: z.array(z.object({
|
|
809
|
-
systemCharacters: count,
|
|
810
|
-
userCharacters: count,
|
|
811
|
-
assistantCharacters: count,
|
|
812
|
-
toolResultCharacters: count,
|
|
813
|
-
otherMessageCharacters: count,
|
|
814
|
-
toolDefinitionCharacters: count,
|
|
815
|
-
unmeasuredToolDefinitions: count
|
|
816
|
-
})).max(128),
|
|
817
|
-
modelTimings: z.array(z.object({ durationMs: z.number().nonnegative().finite(), firstTokenMs: z.number().nonnegative().finite().nullable(), completed: z.boolean() })).max(128),
|
|
818
|
-
omittedContextMeasurements: count
|
|
819
|
-
});
|
|
820
|
-
var manifestSchema = z.object({
|
|
821
|
-
schemaVersion: z.literal(2),
|
|
822
|
-
policyVersion: z.literal("assistant-v3-durable-closure"),
|
|
823
|
-
role: z.string().max(128),
|
|
824
|
-
requireVerifiedDelivery: z.boolean(),
|
|
825
|
-
backend: z.enum(["none", "oci"]),
|
|
826
|
-
tools: z.array(z.string().max(128)).max(1024),
|
|
827
|
-
budget: z.object({ unlimitedTokens: z.boolean().optional(), unlimitedSteps: z.boolean().optional(), unlimitedToolCalls: z.boolean().optional(), maxSteps: count, maxToolCalls: count, maxToolErrors: count, maxInputTokens: count, maxOutputTokens: count, includeChildRuns: z.boolean() }),
|
|
828
|
-
timeoutMs: count,
|
|
829
|
-
unlimitedDuration: z.boolean().optional(),
|
|
830
|
-
closureController: z.boolean(),
|
|
831
|
-
contextEnabled: z.boolean()
|
|
832
|
-
});
|
|
833
|
-
var redact = createRedactionPolicy2({ includeEmails: true });
|
|
834
|
-
var inspectRuntimeDiagnostics = (value) => {
|
|
835
|
-
const parsed = diagnosticsSchema.safeParse(value);
|
|
836
|
-
if (!parsed.success)
|
|
837
|
-
return null;
|
|
838
|
-
return { ...parsed.data, checks: parsed.data.checks.map((check) => ({
|
|
839
|
-
...check,
|
|
840
|
-
commandId: redact.redactText(check.commandId),
|
|
841
|
-
purpose: redact.redactText(check.purpose)
|
|
842
|
-
})) };
|
|
843
|
-
};
|
|
844
|
-
var inspectRuntimeManifest = (value) => {
|
|
845
|
-
const parsed = manifestSchema.safeParse(value);
|
|
846
|
-
if (!parsed.success)
|
|
847
|
-
return null;
|
|
848
|
-
return { ...parsed.data, role: redact.redactText(parsed.data.role), tools: parsed.data.tools.map((name) => redact.redactText(name)) };
|
|
849
|
-
};
|
|
850
|
-
|
|
851
|
-
// src/runtime/usage-ledger.ts
|
|
1043
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
852
1044
|
import { ProviderToolCallError as ProviderToolCallError2 } from "@zhivex-ai/core/provider";
|
|
853
1045
|
|
|
854
|
-
// src/runtime/task-usage-context.ts
|
|
1046
|
+
// packages/core/src/runtime/task-usage-context.ts
|
|
855
1047
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
856
1048
|
var taskUsageAdmission = new AsyncLocalStorage;
|
|
857
1049
|
|
|
858
|
-
// src/runtime/usage-ledger.ts
|
|
1050
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
859
1051
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
860
1052
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
861
|
-
import { lstat as
|
|
862
|
-
import { z as
|
|
1053
|
+
import { lstat as lstat5 } from "node:fs/promises";
|
|
1054
|
+
import { z as z6 } from "zod";
|
|
863
1055
|
import { fingerprintAgentHarness, wrapLanguageModel } from "@zhivex-ai/core";
|
|
864
1056
|
|
|
865
|
-
// src/runtime/model-budget.ts
|
|
1057
|
+
// packages/core/src/runtime/model-budget.ts
|
|
866
1058
|
import { ProviderToolCallError } from "@zhivex-ai/core/provider";
|
|
867
|
-
import { z as
|
|
1059
|
+
import { z as z5 } from "zod";
|
|
868
1060
|
|
|
869
|
-
// src/context/context-metrics.ts
|
|
870
|
-
import { z as
|
|
1061
|
+
// packages/core/src/context/context-metrics.ts
|
|
1062
|
+
import { z as z4 } from "zod";
|
|
871
1063
|
var schemaJson = new WeakMap;
|
|
872
1064
|
var serializeSchema = (schema) => {
|
|
873
1065
|
let serialized = schemaJson.get(schema);
|
|
874
1066
|
if (serialized === undefined) {
|
|
875
|
-
serialized = JSON.stringify(
|
|
1067
|
+
serialized = JSON.stringify(z4.toJSONSchema(schema));
|
|
876
1068
|
schemaJson.set(schema, serialized);
|
|
877
1069
|
}
|
|
878
1070
|
return serialized;
|
|
@@ -920,15 +1112,15 @@ var measureContext = (input) => {
|
|
|
920
1112
|
return counts;
|
|
921
1113
|
};
|
|
922
1114
|
|
|
923
|
-
// src/runtime/model-budget.ts
|
|
1115
|
+
// packages/core/src/runtime/model-budget.ts
|
|
924
1116
|
var MODEL_BUDGET_KEY = "zhivexTransportBudget";
|
|
925
|
-
var savedBudget =
|
|
926
|
-
inputTokens:
|
|
927
|
-
outputTokens:
|
|
928
|
-
cachedInputTokens:
|
|
929
|
-
modelCalls:
|
|
930
|
-
usageComplete:
|
|
931
|
-
inFlight:
|
|
1117
|
+
var savedBudget = z5.object({
|
|
1118
|
+
inputTokens: z5.number().int().nonnegative(),
|
|
1119
|
+
outputTokens: z5.number().int().nonnegative(),
|
|
1120
|
+
cachedInputTokens: z5.number().int().nonnegative(),
|
|
1121
|
+
modelCalls: z5.number().int().nonnegative(),
|
|
1122
|
+
usageComplete: z5.boolean(),
|
|
1123
|
+
inFlight: z5.boolean().default(false)
|
|
932
1124
|
});
|
|
933
1125
|
var estimateRequestTokens = (input) => estimateContextTokens(measureContext(input));
|
|
934
1126
|
var workBudgetReached = (input, stats, limits) => stats.inputTokens + estimateRequestTokens(input) > limits.inputTokens - stats.reservedInputTokens || stats.outputTokens >= limits.outputTokens - stats.reservedOutputTokens;
|
|
@@ -1066,19 +1258,19 @@ var createModelBudget = (limits, options = {}) => {
|
|
|
1066
1258
|
} };
|
|
1067
1259
|
};
|
|
1068
1260
|
|
|
1069
|
-
// src/runtime/usage-ledger.ts
|
|
1261
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
1070
1262
|
var USAGE_LEDGER_KEY = "zhivexUsageLedger";
|
|
1071
|
-
var rate =
|
|
1072
|
-
var usagePricingSchema =
|
|
1073
|
-
schemaVersion:
|
|
1074
|
-
prices:
|
|
1075
|
-
provider:
|
|
1076
|
-
model:
|
|
1263
|
+
var rate = z6.number().finite().nonnegative();
|
|
1264
|
+
var usagePricingSchema = z6.strictObject({
|
|
1265
|
+
schemaVersion: z6.literal(1),
|
|
1266
|
+
prices: z6.array(z6.strictObject({
|
|
1267
|
+
provider: z6.string().min(1).max(128),
|
|
1268
|
+
model: z6.string().min(1).max(512),
|
|
1077
1269
|
inputUsdPerMillion: rate,
|
|
1078
1270
|
outputUsdPerMillion: rate,
|
|
1079
|
-
source:
|
|
1080
|
-
asOf:
|
|
1081
|
-
expiresAt:
|
|
1271
|
+
source: z6.string().min(1).max(1024),
|
|
1272
|
+
asOf: z6.iso.datetime(),
|
|
1273
|
+
expiresAt: z6.iso.datetime()
|
|
1082
1274
|
})).max(100)
|
|
1083
1275
|
}).superRefine((value, ctx) => {
|
|
1084
1276
|
const keys = new Set;
|
|
@@ -1090,28 +1282,28 @@ var usagePricingSchema = z4.strictObject({
|
|
|
1090
1282
|
keys.add(key);
|
|
1091
1283
|
}
|
|
1092
1284
|
});
|
|
1093
|
-
var summaryView =
|
|
1094
|
-
calls:
|
|
1285
|
+
var summaryView = z6.object({
|
|
1286
|
+
calls: z6.number().int().nonnegative(),
|
|
1095
1287
|
inputTokens: rate,
|
|
1096
1288
|
outputTokens: rate,
|
|
1097
|
-
usageComplete:
|
|
1289
|
+
usageComplete: z6.boolean(),
|
|
1098
1290
|
estimatedUsd: rate.nullable(),
|
|
1099
1291
|
limitUsd: rate.nullable()
|
|
1100
1292
|
});
|
|
1101
1293
|
var ledgerView = summaryView.extend({
|
|
1102
|
-
schemaVersion:
|
|
1103
|
-
runId:
|
|
1104
|
-
historicalUsageUnknown:
|
|
1105
|
-
costKind:
|
|
1106
|
-
routes:
|
|
1107
|
-
provider:
|
|
1108
|
-
model:
|
|
1109
|
-
calls:
|
|
1294
|
+
schemaVersion: z6.literal(1),
|
|
1295
|
+
runId: z6.string().max(256),
|
|
1296
|
+
historicalUsageUnknown: z6.boolean().optional(),
|
|
1297
|
+
costKind: z6.literal("estimate-not-invoice"),
|
|
1298
|
+
routes: z6.array(z6.object({
|
|
1299
|
+
provider: z6.string().max(128),
|
|
1300
|
+
model: z6.string().max(512),
|
|
1301
|
+
calls: z6.number().int().nonnegative(),
|
|
1110
1302
|
inputTokens: rate,
|
|
1111
1303
|
outputTokens: rate,
|
|
1112
|
-
unknownCalls:
|
|
1304
|
+
unknownCalls: z6.number().int().nonnegative(),
|
|
1113
1305
|
estimatedUsd: rate.nullable(),
|
|
1114
|
-
priceStatuses:
|
|
1306
|
+
priceStatuses: z6.array(z6.enum(["missing", "stale", "estimate"]))
|
|
1115
1307
|
})).max(100)
|
|
1116
1308
|
});
|
|
1117
1309
|
var inspectUsageLedger = (value) => {
|
|
@@ -1176,11 +1368,11 @@ class UsageLedger {
|
|
|
1176
1368
|
const key = `${sessions.workspaceKey}:${sessions.scopeKey}`;
|
|
1177
1369
|
const databasePath = sessions.databasePath;
|
|
1178
1370
|
sessions.close();
|
|
1179
|
-
const before = await
|
|
1371
|
+
const before = await lstat5(databasePath);
|
|
1180
1372
|
if (before.isSymbolicLink() || !before.isFile())
|
|
1181
1373
|
throw new Error("Usage database must be a regular private file.");
|
|
1182
1374
|
const database = new SqliteDatabase(databasePath, { create: false, strict: true });
|
|
1183
|
-
const after = await
|
|
1375
|
+
const after = await lstat5(databasePath);
|
|
1184
1376
|
if (after.isSymbolicLink() || !after.isFile() || before.dev !== after.dev || before.ino !== after.ino) {
|
|
1185
1377
|
database.close();
|
|
1186
1378
|
throw new Error("Usage database changed while opening.");
|
|
@@ -1442,181 +1634,12 @@ var assertTaskMonetaryReceipts = (ledger, runId, expected, allocations) => {
|
|
|
1442
1634
|
throw new Error("TASK_BUDGET_TOKEN_ALLOCATIONS_MISSING: restore complete task accounting; retained monetary receipts cannot replace missing token allocations.");
|
|
1443
1635
|
};
|
|
1444
1636
|
|
|
1445
|
-
// src/runtime/task-
|
|
1446
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
1447
|
-
import { z as z5 } from "zod";
|
|
1448
|
-
var identifier = z5.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/);
|
|
1449
|
-
var text = (maximum) => z5.string().min(1).max(maximum).refine((value) => value.trim().length > 0 && !/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(value), "Text must be nonblank and contain no control characters.");
|
|
1450
|
-
var exactPath = workspaceFilePathSchema.refine((value) => !/[\\*?\[\]{}\x00-\x1f\x7f]/.test(value), "Use an exact normalized file path, without globs or controls.");
|
|
1451
|
-
var argv = z5.array(z5.string().max(8192).refine((value) => !value.includes("\x00"), "Arguments cannot contain NUL.")).max(256);
|
|
1452
|
-
var command = z5.string().regex(/^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/).refine((value) => !["sh", "bash", "dash", "zsh", "fish", "cmd", "cmd.exe", "powershell", "pwsh"].includes(value.toLowerCase()), "Shell interpreters are not acceptance checks.");
|
|
1453
|
-
var commonCheck = { id: identifier, command, args: argv, purpose: text(500) };
|
|
1454
|
-
var check = z5.discriminatedUnion("kind", [
|
|
1455
|
-
z5.strictObject({
|
|
1456
|
-
...commonCheck,
|
|
1457
|
-
kind: z5.literal("package-script"),
|
|
1458
|
-
script: identifier,
|
|
1459
|
-
expectedScript: text(8192),
|
|
1460
|
-
execution: z5.strictObject({ backend: z5.enum(["none", "oci"]), approval: z5.literal("required") })
|
|
1461
|
-
}),
|
|
1462
|
-
z5.strictObject({
|
|
1463
|
-
...commonCheck,
|
|
1464
|
-
kind: z5.literal("argv"),
|
|
1465
|
-
execution: z5.strictObject({ backend: z5.literal("oci"), approval: z5.literal("required"), network: z5.literal("none") })
|
|
1466
|
-
})
|
|
1467
|
-
]);
|
|
1468
|
-
var taskAcceptanceContractSchema = z5.strictObject({
|
|
1469
|
-
schemaVersion: z5.literal(1),
|
|
1470
|
-
taskId: identifier,
|
|
1471
|
-
allowedWritePaths: z5.array(exactPath).max(256),
|
|
1472
|
-
protectedFiles: z5.array(exactPath).max(256),
|
|
1473
|
-
requiredChecks: z5.array(check).min(1).max(32),
|
|
1474
|
-
humanReview: z5.array(z5.strictObject({ id: identifier, requirement: text(2000), status: z5.literal("pending") })).max(32)
|
|
1475
|
-
}).superRefine((contract, context) => {
|
|
1476
|
-
const unique = (values, field) => {
|
|
1477
|
-
if (new Set(values).size !== values.length)
|
|
1478
|
-
context.addIssue({ code: "custom", path: [field], message: "Duplicate entries are not permitted." });
|
|
1479
|
-
};
|
|
1480
|
-
unique(contract.allowedWritePaths.map((p) => p.toLowerCase()), "allowedWritePaths");
|
|
1481
|
-
unique(contract.protectedFiles.map((p) => p.toLowerCase()), "protectedFiles");
|
|
1482
|
-
unique(contract.requiredChecks.map((c) => c.id), "requiredChecks");
|
|
1483
|
-
unique(contract.humanReview.map((c) => c.id), "humanReview");
|
|
1484
|
-
const overlaps = (a, b) => a === b || a.startsWith(b + "/") || b.startsWith(a + "/");
|
|
1485
|
-
const writes = contract.allowedWritePaths.map((p) => p.toLowerCase());
|
|
1486
|
-
if (writes.some((p, i) => writes.slice(i + 1).some((q) => overlaps(p, q)))) {
|
|
1487
|
-
context.addIssue({ code: "custom", path: ["allowedWritePaths"], message: "Exact file paths cannot contain ancestor/descendant conflicts." });
|
|
1488
|
-
}
|
|
1489
|
-
if (writes.some((p) => contract.protectedFiles.some((q) => overlaps(p, q.toLowerCase())))) {
|
|
1490
|
-
context.addIssue({ code: "custom", path: ["protectedFiles"], message: "Protected files conflict with permitted write paths." });
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
var MAX_TASK_ACCEPTANCE_BYTES = 64 * 1024;
|
|
1494
|
-
function compileTaskAcceptanceContract(input) {
|
|
1495
|
-
let bytes;
|
|
1496
|
-
try {
|
|
1497
|
-
bytes = Buffer.byteLength(JSON.stringify(input));
|
|
1498
|
-
} catch {
|
|
1499
|
-
throw new Error("TASK_ACCEPTANCE_INVALID: requirements must be JSON serializable.");
|
|
1500
|
-
}
|
|
1501
|
-
if (bytes > MAX_TASK_ACCEPTANCE_BYTES)
|
|
1502
|
-
throw new Error("TASK_ACCEPTANCE_TOO_LARGE: requirements exceed 64 KiB.");
|
|
1503
|
-
const parsed = taskAcceptanceContractSchema.safeParse(input);
|
|
1504
|
-
if (!parsed.success)
|
|
1505
|
-
throw new Error("TASK_ACCEPTANCE_INVALID: " + parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; "));
|
|
1506
|
-
const sorted = (items) => items.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
1507
|
-
const contract = {
|
|
1508
|
-
schemaVersion: 1,
|
|
1509
|
-
taskId: parsed.data.taskId,
|
|
1510
|
-
allowedWritePaths: [...parsed.data.allowedWritePaths].sort(),
|
|
1511
|
-
protectedFiles: [...parsed.data.protectedFiles].sort(),
|
|
1512
|
-
requiredChecks: sorted(parsed.data.requiredChecks),
|
|
1513
|
-
humanReview: sorted(parsed.data.humanReview)
|
|
1514
|
-
};
|
|
1515
|
-
return { contract, digest: `sha256:${createHash2("sha256").update(JSON.stringify(contract)).digest("hex")}` };
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
// src/runtime/task-acceptance-record.ts
|
|
1519
|
-
import { z as z6 } from "zod";
|
|
1520
|
-
import { serializeJsonValue } from "@zhivex-ai/core";
|
|
1521
|
-
var TASK_ACCEPTANCE_KEY = "zhivexTaskAcceptanceV1";
|
|
1522
|
-
var TASK_ACCEPTANCE_EVIDENCE_KEY = "zhivexTaskAcceptanceEvidenceV1";
|
|
1523
|
-
var digest2 = z6.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
1524
|
-
var revisionSchema = z6.strictObject({ revision: z6.number().int().min(1), digest: digest2, previousDigest: digest2.nullable(), contract: taskAcceptanceContractSchema });
|
|
1525
|
-
var ledgerSchema = z6.strictObject({ schemaVersion: z6.literal(1), revisions: z6.array(revisionSchema).min(1).max(16) });
|
|
1526
|
-
function readTaskAcceptanceLedger(state) {
|
|
1527
|
-
const raw = state.metadata?.[TASK_ACCEPTANCE_KEY];
|
|
1528
|
-
if (raw === undefined)
|
|
1529
|
-
return;
|
|
1530
|
-
if (Buffer.byteLength(JSON.stringify(raw)) > 1024 * 1024)
|
|
1531
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1532
|
-
const ledger = ledgerSchema.parse(raw);
|
|
1533
|
-
for (let index = 0;index < ledger.revisions.length; index++) {
|
|
1534
|
-
const row = ledger.revisions[index];
|
|
1535
|
-
if (row.revision !== index + 1 || row.previousDigest !== (ledger.revisions[index - 1]?.digest ?? null) || compileTaskAcceptanceContract(row.contract).digest !== row.digest || row.contract.taskId !== ledger.revisions[0].contract.taskId) {
|
|
1536
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_INVALID");
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return ledger;
|
|
1540
|
-
}
|
|
1541
|
-
function nextTaskAcceptanceLedger(current2, requirements) {
|
|
1542
|
-
if (current2)
|
|
1543
|
-
current2 = readTaskAcceptanceLedger({ metadata: { [TASK_ACCEPTANCE_KEY]: serializeJsonValue(current2) } });
|
|
1544
|
-
const { contract, digest: digest3 } = compileTaskAcceptanceContract(requirements);
|
|
1545
|
-
const previous = current2?.revisions.at(-1);
|
|
1546
|
-
if (previous && previous.contract.taskId !== contract.taskId)
|
|
1547
|
-
throw new Error("TASK_ACCEPTANCE_TASK_ID_IMMUTABLE");
|
|
1548
|
-
if (previous?.digest === digest3)
|
|
1549
|
-
throw new Error("TASK_ACCEPTANCE_UNCHANGED");
|
|
1550
|
-
if ((current2?.revisions.length ?? 0) >= 16)
|
|
1551
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1552
|
-
const next = { schemaVersion: 1, revisions: [...structuredClone(current2?.revisions ?? []), {
|
|
1553
|
-
revision: (previous?.revision ?? 0) + 1,
|
|
1554
|
-
previousDigest: previous?.digest ?? null,
|
|
1555
|
-
digest: digest3,
|
|
1556
|
-
contract
|
|
1557
|
-
}] };
|
|
1558
|
-
if (Buffer.byteLength(JSON.stringify(next)) > 1024 * 1024)
|
|
1559
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1560
|
-
return next;
|
|
1561
|
-
}
|
|
1562
|
-
async function persistTaskAcceptanceRevision(store, options) {
|
|
1563
|
-
const state = await store.load(options.runId, options.scope);
|
|
1564
|
-
if (!state || state.revision !== options.expectedRunRevision)
|
|
1565
|
-
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
1566
|
-
const current2 = readTaskAcceptanceLedger(state);
|
|
1567
|
-
if ((current2?.revisions.at(-1)?.revision ?? 0) !== options.expectedContractRevision)
|
|
1568
|
-
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
1569
|
-
const ledger = nextTaskAcceptanceLedger(current2, options.requirements), latest = ledger.revisions.at(-1);
|
|
1570
|
-
const prior = current2?.revisions.at(-1);
|
|
1571
|
-
const oldEvidence = state.metadata?.[TASK_ACCEPTANCE_EVIDENCE_KEY];
|
|
1572
|
-
const sameFiles = prior && JSON.stringify([prior.contract.allowedWritePaths, prior.contract.protectedFiles]) === JSON.stringify([latest.contract.allowedWritePaths, latest.contract.protectedFiles]);
|
|
1573
|
-
const previousChecks = z6.array(taskCheckReceiptSchema).max(32).safeParse(oldEvidence?.checks);
|
|
1574
|
-
const checks = sameFiles && previousChecks.success ? previousChecks.data.filter((receipt) => receipt.contractDigest === prior.digest && receipt.contractRevision === prior.revision && JSON.stringify(prior.contract.requiredChecks.find((check2) => check2.id === receipt.checkId)) === JSON.stringify(latest.contract.requiredChecks.find((check2) => check2.id === receipt.checkId))).map((receipt) => ({ ...receipt, contractDigest: latest.digest, contractRevision: latest.revision })) : [];
|
|
1575
|
-
await store.save({ ...state, metadata: {
|
|
1576
|
-
...state.metadata,
|
|
1577
|
-
[TASK_ACCEPTANCE_KEY]: serializeJsonValue(ledger),
|
|
1578
|
-
[TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
1579
|
-
schemaVersion: 1,
|
|
1580
|
-
contractRevision: latest.revision,
|
|
1581
|
-
contractDigest: latest.digest,
|
|
1582
|
-
status: "pending",
|
|
1583
|
-
checks,
|
|
1584
|
-
humanReview: latest.contract.humanReview,
|
|
1585
|
-
...sameFiles && oldEvidence?.delivery ? { delivery: oldEvidence.delivery } : {}
|
|
1586
|
-
})
|
|
1587
|
-
} }, { expectedRevision: options.expectedRunRevision });
|
|
1588
|
-
return structuredClone(ledger);
|
|
1589
|
-
}
|
|
1590
|
-
function taskAcceptanceCheckpointStore(store, runId, ledger) {
|
|
1591
|
-
const retained = serializeJsonValue(structuredClone(ledger));
|
|
1592
|
-
const latest = ledger.revisions.at(-1);
|
|
1593
|
-
const pending = { schemaVersion: 1, contractRevision: latest.revision, contractDigest: latest.digest, status: "pending", checks: [], humanReview: serializeJsonValue(latest.contract.humanReview) };
|
|
1594
|
-
return new Proxy(store, { get(target, key) {
|
|
1595
|
-
if (key === "save")
|
|
1596
|
-
return async (...args) => {
|
|
1597
|
-
const [state] = args;
|
|
1598
|
-
if (state.runId === runId) {
|
|
1599
|
-
const violation = taskAcceptanceDeliveryDiagnostic(latest.digest, latest.revision);
|
|
1600
|
-
state.metadata = { ...state.metadata, [TASK_ACCEPTANCE_KEY]: structuredClone(retained), [TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
1601
|
-
...structuredClone(pending),
|
|
1602
|
-
...await taskAcceptanceOutcome(state, ledger),
|
|
1603
|
-
checks: serializeJsonValue(taskAcceptanceChecks()?.snapshot() ?? []),
|
|
1604
|
-
...violation ? { status: "failed", diagnostic: serializeJsonValue(violation) } : {}
|
|
1605
|
-
}) };
|
|
1606
|
-
}
|
|
1607
|
-
return target.save(...args);
|
|
1608
|
-
};
|
|
1609
|
-
const value = Reflect.get(target, key, target);
|
|
1610
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
1611
|
-
} });
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
// src/runtime/task-budget.ts
|
|
1637
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1615
1638
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
1616
1639
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1617
1640
|
import { z as z7 } from "zod";
|
|
1618
1641
|
|
|
1619
|
-
// src/runtime/budget-ledger-scope.ts
|
|
1642
|
+
// packages/core/src/runtime/budget-ledger-scope.ts
|
|
1620
1643
|
var BUDGET_LEDGER_NAMESPACE = "__zhivex_budget__";
|
|
1621
1644
|
var BUDGET_OWNER_NAMESPACE_KEY = "budgetOwnerNamespace";
|
|
1622
1645
|
var isReservedBudgetNamespace = (namespace) => namespace === BUDGET_LEDGER_NAMESPACE || (namespace?.startsWith(`${BUDGET_LEDGER_NAMESPACE}:`) ?? false);
|
|
@@ -1687,7 +1710,7 @@ var bindBudgetLedgerStore = (primary, scope, budget = primary) => {
|
|
|
1687
1710
|
};
|
|
1688
1711
|
};
|
|
1689
1712
|
|
|
1690
|
-
// src/runtime/task-budget.ts
|
|
1713
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1691
1714
|
import {
|
|
1692
1715
|
createAgentBudgetCoordinator,
|
|
1693
1716
|
fingerprintAgentHarness as fingerprintAgentHarness2,
|
|
@@ -1695,7 +1718,7 @@ import {
|
|
|
1695
1718
|
} from "@zhivex-ai/core";
|
|
1696
1719
|
import { ProviderToolCallError as ProviderToolCallError3 } from "@zhivex-ai/core/provider";
|
|
1697
1720
|
|
|
1698
|
-
// src/runtime/runtime-instructions.ts
|
|
1721
|
+
// packages/core/src/runtime/runtime-instructions.ts
|
|
1699
1722
|
var withRuntimeInstruction = (messages, text2) => {
|
|
1700
1723
|
const firstConversation = messages.findIndex((message) => message.role !== "system");
|
|
1701
1724
|
const at = firstConversation === -1 ? messages.length : firstConversation;
|
|
@@ -1722,7 +1745,7 @@ var withFreshSystemInstructions = (input, hostInstructions) => {
|
|
|
1722
1745
|
`), messages: input.messages.slice(count2) };
|
|
1723
1746
|
};
|
|
1724
1747
|
|
|
1725
|
-
// src/runtime/task-budget.ts
|
|
1748
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1726
1749
|
var TASK_BUDGET_KEY = "zhivexTaskBudgetV1";
|
|
1727
1750
|
var TASK_BUDGET_ACCOUNT_KEY = "zhivexTaskBudgetAccountV1";
|
|
1728
1751
|
var token = z7.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
@@ -2352,4 +2375,4 @@ class TaskBudget {
|
|
|
2352
2375
|
}
|
|
2353
2376
|
}
|
|
2354
2377
|
|
|
2355
|
-
export {
|
|
2378
|
+
export { taskAcceptanceContractSchema, compileTaskAcceptanceContract, TASK_ACCEPTANCE_KEY, TASK_ACCEPTANCE_EVIDENCE_KEY, readTaskAcceptanceLedger, nextTaskAcceptanceLedger, persistTaskAcceptanceRevision, taskAcceptanceCheckpointStore, estimateContextTokens, measureContext, inspectRuntimeDiagnostics, inspectRuntimeManifest, protectStateFromGit, assertNoApplicationMigration, validateStateDirectory, HARNESS_SESSION_INDEX_FILE, HARNESS_SESSION_SCHEMA_VERSION, SESSION_RUN_STATUSES, TERMINAL_SESSION_RUN_STATUSES, ensurePrivateDatabase, openCliSessionStore, openSessionStore, MODEL_BUDGET_KEY, estimateRequestTokens, workBudgetReached, createModelBudget, USAGE_LEDGER_KEY, usagePricingSchema, inspectUsageLedger, formatUsageLedger, runUsageLedgerWithPolicy, UsageLedger, inspectTaskMonetaryUsage, BUDGET_LEDGER_NAMESPACE, BUDGET_OWNER_NAMESPACE_KEY, isReservedBudgetNamespace, budgetLedgerNamespace, budgetLedgerScope, bindBudgetLedgerStore, withRuntimeInstruction, withFreshSystemInstructions, TASK_BUDGET_KEY, TASK_BUDGET_ACCOUNT_KEY, inspectTaskBudgetSummary, assertTaskBudgetBackupLinks, TaskBudget };
|