@zhivex-ai/harness 1.6.3 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -3
- package/README.md +17 -5
- package/SECURITY.md +1 -1
- package/SUPPORT.md +2 -2
- package/benchmarks/README.md +98 -0
- package/contracts/engine-api.json +1587 -0
- package/contracts/public-api.json +114 -0
- package/contracts/stable-api-signatures.json +17 -17
- package/dist/acp-cli.js +37 -1090
- package/dist/application/agenda.d.ts +10 -0
- package/dist/application/approval-review.d.ts +61 -0
- package/dist/application/assistant/automation/scheduler.d.ts +21 -0
- package/dist/application/assistant/automation/summary.d.ts +29 -0
- package/dist/application/assistant/automation/time.d.ts +10 -0
- package/dist/application/assistant/calendar/calendar.d.ts +238 -0
- package/dist/application/assistant/calendar/connection.d.ts +50 -0
- package/dist/application/assistant/calendar/create-event.d.ts +75 -0
- package/dist/application/assistant/calendar/environment.d.ts +2 -0
- package/dist/application/assistant/calendar/http.d.ts +6 -0
- package/dist/application/assistant/calendar/oauth.d.ts +68 -0
- package/dist/application/assistant/calendar/store.d.ts +11 -0
- package/dist/application/assistant/calendar/tools.d.ts +78 -0
- package/dist/application/assistant/client.d.ts +10 -0
- package/dist/application/assistant/config.d.ts +9 -0
- package/dist/application/assistant/contracts.d.ts +77 -0
- package/dist/application/assistant/daily/service.d.ts +181 -0
- package/dist/application/assistant/doctor.d.ts +22 -0
- package/dist/application/assistant/evaluation.d.ts +81 -0
- package/dist/application/assistant/host.d.ts +399 -0
- package/dist/application/assistant/integrations/google.d.ts +117 -0
- package/dist/application/assistant/integrations/public-web.d.ts +16 -0
- package/dist/application/assistant/managed/secrets.d.ts +10 -0
- package/dist/application/assistant/managed/setup-state.d.ts +346 -0
- package/dist/application/assistant/managed/setup.d.ts +492 -0
- package/dist/application/assistant/microsoft/connection.d.ts +73 -0
- package/dist/application/assistant/microsoft/tools.d.ts +78 -0
- package/dist/application/assistant/modules/calendar.d.ts +3 -0
- package/dist/application/assistant/modules/catalog.d.ts +38 -0
- package/dist/application/assistant/modules/daily.d.ts +5 -0
- package/dist/application/assistant/modules/github.d.ts +5 -0
- package/dist/application/assistant/modules/google.d.ts +3 -0
- package/dist/application/assistant/modules/mcp.d.ts +11 -0
- package/dist/application/assistant/modules/microsoft.d.ts +3 -0
- package/dist/application/assistant/modules/module.d.ts +224 -0
- package/dist/application/assistant/modules/tools.d.ts +11 -0
- package/dist/application/assistant/modules/web.d.ts +7 -0
- package/dist/application/assistant/private-directory.d.ts +3 -0
- package/dist/application/assistant/proactive/service.d.ts +142 -0
- package/dist/application/assistant/providers/openai-compatible.d.ts +66 -0
- package/dist/application/assistant/providers/provider.d.ts +141 -0
- package/dist/application/assistant/providers/web-citations.d.ts +2 -0
- package/dist/application/assistant/runtime.d.ts +16 -0
- package/dist/application/assistant/task-metrics.d.ts +304 -0
- package/dist/application/assistant/telegram/api.d.ts +47 -0
- package/dist/application/assistant/telegram/bridge.d.ts +69 -0
- package/dist/application/assistant/telegram/store.d.ts +10 -0
- package/dist/application/automation.d.ts +5 -0
- package/dist/application/calendar-review.d.ts +5 -0
- package/dist/application/checkpoint-review.d.ts +30 -0
- package/dist/application/client.d.ts +18 -0
- package/dist/application/code/context.d.ts +5 -0
- package/dist/application/code/delivery.d.ts +6 -0
- package/dist/application/code/git-delivery.d.ts +54 -0
- package/dist/application/code/github-git-transport.d.ts +15 -0
- package/dist/application/code/github-pr-transport.d.ts +6 -0
- package/dist/application/code/host.d.ts +25 -0
- package/dist/application/code/pr-delivery.d.ts +79 -0
- package/dist/application/code/projects.d.ts +90 -0
- package/dist/application/code/remote-delivery.d.ts +80 -0
- package/dist/application/code/repository.d.ts +9 -0
- package/dist/application/code/worktrees.d.ts +123 -0
- package/dist/application/contracts.d.ts +288 -0
- package/dist/application/coordinator-client.d.ts +33 -0
- package/dist/application/coordinator-discovery.d.ts +17 -0
- package/dist/application/coordinator-launcher.d.ts +2 -0
- package/dist/application/coordinator.d.ts +27 -0
- package/dist/application/credential-process.d.ts +13 -0
- package/dist/application/host.d.ts +7 -0
- package/dist/application/management.d.ts +68 -0
- package/dist/application/notes.d.ts +5 -0
- package/dist/application/offline-migration.d.ts +16 -0
- package/dist/application/personal-state.d.ts +5 -0
- package/dist/application/review-channel.d.ts +23 -0
- package/dist/application/review-tickets.d.ts +29 -0
- package/dist/application/runtime-binding.d.ts +4 -0
- package/dist/application-cli-wfh08g41.js +184 -0
- package/dist/application-cli-z3f9pvcf.js +209 -0
- package/dist/arguments-75r85mvc.js +27 -0
- package/dist/arguments-x24bbqvd.js +22 -0
- package/dist/audit/index.js +16 -472
- package/dist/audit-pack-1gnych0m.js +93 -0
- package/dist/{audit-pack-s9n693by.js → audit-pack-h44kjkbj.js} +17 -11
- package/dist/calendar-2xw0rr7b.js +49 -0
- package/dist/cli/application-cli.d.ts +2 -0
- package/dist/cli/arguments.d.ts +14 -1
- package/dist/cli/auto-approve-setup.d.ts +13 -0
- package/dist/cli/configured-harness.d.ts +1 -2
- package/dist/cli/console/console-budget.d.ts +16 -2
- package/dist/cli/console/console-checkpoints.d.ts +12 -0
- package/dist/cli/console/console-commands.d.ts +3 -3
- package/dist/cli/console/console-compaction.d.ts +1 -1
- package/dist/cli/console/console-diff.d.ts +2 -0
- package/dist/cli/console/console-input.d.ts +29 -1
- package/dist/cli/console/console-navigation.d.ts +2 -2
- package/dist/cli/console/console-outcome.d.ts +10 -0
- package/dist/cli/console/console-presentation.d.ts +17 -2
- package/dist/cli/console/console-pricing.d.ts +14 -0
- package/dist/cli/console/console-reasoning.d.ts +1 -1
- package/dist/cli/console/console-recovery.d.ts +2 -0
- package/dist/cli/console/console-review.d.ts +34 -0
- package/dist/cli/console/console-run-policy.d.ts +5 -0
- package/dist/cli/console/console-run-view.d.ts +28 -0
- package/dist/cli/console/console-task.d.ts +30 -0
- package/dist/cli/console/console-welcome.d.ts +13 -3
- package/dist/cli/console/review-diff.d.ts +20 -0
- package/dist/cli/presentation.d.ts +8 -6
- package/dist/cli/service-checkpoints.d.ts +234 -0
- package/dist/cli/terminal/activity-history.d.ts +4 -2
- package/dist/cli/terminal/activity-stream.d.ts +33 -0
- package/dist/cli/terminal/file-diff.d.ts +11 -0
- package/dist/cli/terminal/terminal-theme.d.ts +9 -0
- package/dist/cli/terminal/terminal-ui.d.ts +44 -2
- package/dist/cli/terminal/tool-activity.d.ts +6 -2
- package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
- package/dist/{cli-entry-1epvek01.js → cli-entry-86rcbmwh.js} +294 -14
- package/dist/cli-entry-btkpb4h1.js +3627 -0
- package/dist/cli-entry-bxjbs6qq.js +200 -0
- package/dist/cli-entry-cpm89r9q.js +624 -0
- package/dist/{cli-entry-mbcq96nx.js → cli-entry-dksm56sj.js} +39 -293
- package/dist/{cli-entry-rsx0wpvs.js → cli-entry-eka68ttb.js} +4087 -4625
- package/dist/cli-entry-h7dcah4p.js +137 -0
- package/dist/cli-entry-kwk23ktq.js +33 -0
- package/dist/{cli-entry-nyzyvf24.js → cli-entry-vmce694z.js} +1286 -3142
- package/dist/cli-entry-wanv05db.js +1113 -0
- package/dist/{cli-yxvq8qf1.js → cli-z7vhm1rk.js} +1767 -380
- package/dist/cli.js +8 -6
- package/dist/client/json-contracts.d.ts +153 -0
- package/dist/client/local-service.d.ts +7 -12
- package/dist/client/local-transport.d.ts +14 -0
- package/dist/client/protocol.d.ts +43 -1
- package/dist/compat/cli-options.d.ts +7 -1
- package/dist/compat/cli.d.ts +2 -0
- package/dist/compat/cli.js +4043 -0
- package/dist/compat/code-support.d.ts +4 -0
- package/dist/compat/code-support.js +50 -28
- package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
- package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
- package/dist/context/adaptive-compaction.d.ts +1 -0
- package/dist/context/lossless-lines.d.ts +13 -0
- package/dist/context/numbered-read-lines.d.ts +15 -0
- package/dist/context/read-attempts.d.ts +21 -0
- package/dist/context/request-projection.d.ts +32 -4
- package/dist/context/scoped-context.d.ts +31 -5
- package/dist/context/working-read-replay.d.ts +12 -0
- package/dist/coordinator-client-nzysqxf0.js +10 -0
- package/dist/engine/acp.js +27 -21
- package/dist/engine/application-client.d.ts +11 -0
- package/dist/engine/application-client.js +18 -0
- package/dist/engine/application-protocol.d.ts +5 -0
- package/dist/engine/application-protocol.js +7 -0
- package/dist/engine/application.d.ts +43 -0
- package/dist/engine/application.js +206 -0
- package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
- package/dist/engine/assistant/automation/scheduler.js +11 -0
- package/dist/engine/assistant/automation/summary.d.ts +3 -0
- package/dist/engine/assistant/automation/summary.js +8 -0
- package/dist/engine/assistant/automation/time.d.ts +5 -0
- package/dist/engine/assistant/automation/time.js +15 -0
- package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
- package/dist/engine/assistant/calendar/calendar.js +12 -0
- package/dist/engine/assistant/calendar/connection.d.ts +2 -0
- package/dist/engine/assistant/calendar/connection.js +11 -0
- package/dist/engine/assistant/calendar/environment.d.ts +1 -0
- package/dist/engine/assistant/calendar/environment.js +7 -0
- package/dist/engine/assistant/calendar/http.d.ts +3 -0
- package/dist/engine/assistant/calendar/http.js +9 -0
- package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
- package/dist/engine/assistant/calendar/oauth.js +12 -0
- package/dist/engine/assistant/calendar/store.d.ts +2 -0
- package/dist/engine/assistant/calendar/store.js +8 -0
- package/dist/engine/assistant/calendar/tools.d.ts +2 -0
- package/dist/engine/assistant/calendar/tools.js +46 -0
- package/dist/engine/assistant/client.d.ts +2 -0
- package/dist/engine/assistant/client.js +33 -0
- package/dist/engine/assistant/config.d.ts +1 -0
- package/dist/engine/assistant/config.js +102 -0
- package/dist/engine/assistant/contracts.d.ts +10 -0
- package/dist/engine/assistant/contracts.js +78 -0
- package/dist/engine/assistant/daily/service.d.ts +12 -0
- package/dist/engine/assistant/daily/service.js +27 -0
- package/dist/engine/assistant/doctor.d.ts +1 -0
- package/dist/engine/assistant/doctor.js +116 -0
- package/dist/engine/assistant/evaluation.d.ts +2 -0
- package/dist/engine/assistant/evaluation.js +76 -0
- package/dist/engine/assistant/host.d.ts +2 -0
- package/dist/engine/assistant/host.js +63 -0
- package/dist/engine/assistant/integrations/google.d.ts +9 -0
- package/dist/engine/assistant/integrations/google.js +30 -0
- package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
- package/dist/engine/assistant/integrations/public-web.js +11 -0
- package/dist/engine/assistant/managed/secrets.d.ts +1 -0
- package/dist/engine/assistant/managed/secrets.js +0 -0
- package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
- package/dist/engine/assistant/managed/setup-state.js +84 -0
- package/dist/engine/assistant/managed/setup.d.ts +3 -0
- package/dist/engine/assistant/managed/setup.js +85 -0
- package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
- package/dist/engine/assistant/microsoft/connection.js +21 -0
- package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
- package/dist/engine/assistant/microsoft/tools.js +30 -0
- package/dist/engine/assistant/modules/calendar.d.ts +1 -0
- package/dist/engine/assistant/modules/calendar.js +49 -0
- package/dist/engine/assistant/modules/catalog.d.ts +3 -0
- package/dist/engine/assistant/modules/catalog.js +67 -0
- package/dist/engine/assistant/modules/daily.d.ts +1 -0
- package/dist/engine/assistant/modules/daily.js +48 -0
- package/dist/engine/assistant/modules/github.d.ts +1 -0
- package/dist/engine/assistant/modules/github.js +43 -0
- package/dist/engine/assistant/modules/google.d.ts +1 -0
- package/dist/engine/assistant/modules/google.js +53 -0
- package/dist/engine/assistant/modules/mcp.d.ts +1 -0
- package/dist/engine/assistant/modules/mcp.js +42 -0
- package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
- package/dist/engine/assistant/modules/microsoft.js +53 -0
- package/dist/engine/assistant/modules/module.d.ts +5 -0
- package/dist/engine/assistant/modules/module.js +42 -0
- package/dist/engine/assistant/modules/tools.d.ts +2 -0
- package/dist/engine/assistant/modules/tools.js +42 -0
- package/dist/engine/assistant/modules/web.d.ts +1 -0
- package/dist/engine/assistant/modules/web.js +45 -0
- package/dist/engine/assistant/private-directory.d.ts +1 -0
- package/dist/engine/assistant/private-directory.js +7 -0
- package/dist/engine/assistant/proactive/service.d.ts +6 -0
- package/dist/engine/assistant/proactive/service.js +16 -0
- package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
- package/dist/engine/assistant/providers/openai-compatible.js +12 -0
- package/dist/engine/assistant/providers/provider.d.ts +7 -0
- package/dist/engine/assistant/providers/provider.js +54 -0
- package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
- package/dist/engine/assistant/providers/web-citations.js +7 -0
- package/dist/engine/assistant/runtime.d.ts +2 -0
- package/dist/engine/assistant/runtime.js +73 -0
- package/dist/engine/assistant/task-metrics.d.ts +8 -0
- package/dist/engine/assistant/task-metrics.js +17 -0
- package/dist/engine/assistant/telegram/api.d.ts +5 -0
- package/dist/engine/assistant/telegram/api.js +11 -0
- package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
- package/dist/engine/assistant/telegram/bridge.js +40 -0
- package/dist/engine/assistant/telegram/store.d.ts +2 -0
- package/dist/engine/assistant/telegram/store.js +8 -0
- package/dist/engine/client.js +26 -18
- package/dist/engine/desktop-providers-v1.js +4 -4
- package/dist/engine/desktop-state-v1.js +16 -13
- package/dist/engine/index.d.ts +4 -0
- package/dist/engine/index.js +117 -159
- package/dist/engine/mcp-stdio-v1.js +13 -12
- package/dist/engine/models.js +65 -23
- package/dist/engine/protocol.js +10 -6
- package/dist/engine/service.js +32 -21
- package/dist/hostile-repository-demo.js +2329 -1096
- package/dist/index-09rsdr2d.js +1744 -0
- package/dist/index-0csc5sc7.js +139 -0
- package/dist/{index-4mn6m3bq.js → index-0dkty795.js} +8 -6
- package/dist/index-0kkgqvg7.js +0 -0
- package/dist/index-0mzz9axm.js +58 -0
- package/dist/index-1e69ar8r.js +38 -0
- package/dist/index-1z0xhkh9.js +18 -0
- package/dist/index-2cef1k92.js +356 -0
- package/dist/{index-rgqzdgv6.js → index-2j0v1xwr.js} +17 -13
- package/dist/index-2jw9jd7h.js +116 -0
- package/dist/index-2n9qx4km.js +0 -0
- package/dist/index-3rvk23e8.js +877 -0
- package/dist/index-3wa4j0yk.js +71 -0
- package/dist/index-41q1k17x.js +210 -0
- package/dist/index-4vz4bqqw.js +33 -0
- package/dist/index-5jxm2wy5.js +123 -0
- package/dist/index-5rk6ss42.js +216 -0
- package/dist/index-5v1skxf7.js +1852 -0
- package/dist/{index-fqqz1yt8.js → index-6ehtssyz.js} +369 -335
- package/dist/index-76kpdbpw.js +80 -0
- package/dist/{index-5nmm0642.js → index-7nbmhmw5.js} +10 -10
- package/dist/index-8mx0yrkz.js +31 -0
- package/dist/index-8tjev5ds.js +11 -0
- package/dist/index-91n5wr6s.js +163 -0
- package/dist/index-91trs3ew.js +151 -0
- package/dist/index-9y8p5vy5.js +222 -0
- package/dist/index-abxahprd.js +55 -0
- package/dist/index-aptyr511.js +84 -0
- package/dist/{index-8sm2a1wa.js → index-ay26xfxt.js} +28 -20
- package/dist/index-b4yed1s3.js +657 -0
- package/dist/index-bb7phvtg.js +23 -0
- package/dist/index-bk5tn9b8.js +236 -0
- package/dist/index-bw34861c.js +292 -0
- package/dist/index-c6fnjhgv.js +55 -0
- package/dist/{index-qfsrrnz6.js → index-cjevq9s8.js} +2 -2
- package/dist/{index-c39197wq.js → index-ctcwrkrc.js} +4 -4
- package/dist/{index-yx52bt4a.js → index-cztmcesv.js} +2 -2
- package/dist/index-dpbmxnrf.js +564 -0
- package/dist/index-ekxdcy36.js +134 -0
- package/dist/index-f8zpcsx3.js +289 -0
- package/dist/{index-6dxrbnxm.js → index-f970qtb4.js} +7 -143
- package/dist/index-fatcn6fp.js +2791 -0
- package/dist/index-fbzykqxy.js +105 -0
- package/dist/{index-1265j7t2.js → index-fwf274vc.js} +24 -14
- package/dist/index-fy4w0a7v.js +0 -0
- package/dist/index-gvva3e5x.js +76 -0
- package/dist/index-h7dcah4p.js +137 -0
- package/dist/index-hm9r120s.js +42 -0
- package/dist/index-j3d2tw97.js +328 -0
- package/dist/index-jfqj20x8.js +41 -0
- package/dist/{index-hhrnrqfc.js → index-k529a278.js} +6 -6
- package/dist/{index-bt2p8x7r.js → index-kbrf5bx7.js} +110 -106
- package/dist/index-kwk23ktq.js +33 -0
- package/dist/index-kz857p1j.js +557 -0
- package/dist/{index-j466sekf.js → index-mkt5yrax.js} +31 -105
- package/dist/{index-nxmk6re7.js → index-ndgnvjez.js} +18 -18
- package/dist/index-nemn4epv.js +43 -0
- package/dist/index-nkwy5bjr.js +1225 -0
- package/dist/index-nvvzr4ny.js +136 -0
- package/dist/index-pkspzsfs.js +78 -0
- package/dist/{index-fm84men1.js → index-px1tnqgt.js} +2 -2
- package/dist/index-q7qdw883.js +79 -0
- package/dist/{index-mzydbzp8.js → index-qvbg6tx1.js} +65 -23
- package/dist/index-r3mwr5fb.js +0 -0
- package/dist/index-rdr78m0k.js +91 -0
- package/dist/index-rtamqsfs.js +59 -0
- package/dist/index-s125ss45.js +38 -0
- package/dist/{index-vn91b9z1.js → index-sx1t6dnd.js} +3721 -2382
- package/dist/index-tar0ngkm.js +359 -0
- package/dist/index-tn58cr6w.js +471 -0
- package/dist/{index-w0m1nckc.js → index-v79s9bf9.js} +118 -45
- package/dist/index-vk3rq21m.js +17 -0
- package/dist/index-vmvnr28y.js +72 -0
- package/dist/index-vz629cg8.js +49 -0
- package/dist/{index-eps3c3g6.js → index-w292hdpz.js} +197 -960
- package/dist/{index-amjttjaj.js → index-w9eqg6p9.js} +24 -302
- package/dist/index-wj96kdw2.js +57 -0
- package/dist/index-wyck5yhd.js +141 -0
- package/dist/index-xvtk8pxs.js +674 -0
- package/dist/{index-bpc596v3.js → index-xwb691v9.js} +2 -2
- package/dist/index-ym69x168.js +518 -0
- package/dist/index-yprdjk9v.js +65 -0
- package/dist/index-z2a81ccr.js +35 -0
- package/dist/{index-3ah1f369.js → index-z69cqk74.js} +3 -3
- package/dist/index-zaakvmzq.js +62 -0
- package/dist/index-zk3m4mzg.js +232 -0
- package/dist/index-zx3wgvx4.js +218 -0
- package/dist/index.js +102 -83
- package/dist/persistence/migration-guard.d.ts +3 -0
- package/dist/runtime/agent-profile.d.ts +12 -0
- package/dist/runtime/harness.d.ts +13 -0
- package/dist/runtime/known-file-preload.d.ts +35 -0
- package/dist/service-cli.js +130 -40
- package/dist/service-client-cli-2rzxy5mj.js +1166 -0
- package/dist/service-client-cli-5ne8q5ej.js +543 -0
- package/dist/tools/ooxml-zip.d.ts +21 -0
- package/dist/tools/presentations.d.ts +47 -0
- package/dist/tools/tabular-data.d.ts +114 -0
- package/dist/tools/workspace.d.ts +76 -0
- package/dist/verify-historical-migrations.js +2249 -1016
- package/dist/workspace/workspace.d.ts +13 -1
- package/dist/zhx.js +8 -6
- package/docs/APPLICATION_MIGRATION.md +32 -0
- package/docs/CLI.md +166 -2
- package/docs/CODE_RELEASE.md +11 -5
- package/docs/CODE_WEB_TASKS.md +3 -114
- package/docs/CONTEXT_ENGINEERING.md +93 -0
- package/docs/ENGINE_API.md +9 -2
- package/docs/EXTENSIBILITY.md +1 -1
- package/docs/FIRST_USE.md +6 -6
- package/docs/INTERNAL_ARCHIVE.md +43 -0
- package/docs/LOCAL_SERVICE.md +1 -1
- package/docs/MODEL_CATALOG.md +14 -0
- package/docs/PROJECT_MEMORY.md +1 -1
- package/docs/README.md +23 -4
- package/evaluations/representative-assembly-matrix.json +19 -1
- package/examples/README.md +4 -4
- package/examples/assistant/compatible-calendar.json +17 -0
- package/examples/assistant/composed-modules.json +23 -0
- package/examples/assistant/connected-tools.json +9 -0
- package/examples/assistant/daily-tools.json +6 -0
- package/examples/assistant/offline.mjs +24 -0
- package/fixtures/cli-compatibility/README.md +10 -0
- package/fixtures/cli-compatibility/inventory.json +7858 -0
- package/package.json +232 -26
- package/dist/cli/console/console-model-catalog.d.ts +0 -8
- package/dist/index-2yyfg69h.js +0 -619
- package/dist/index-3wwfn5n6.js +0 -270
- package/dist/index-4gt045j0.js +0 -288
- package/dist/index-4jw3tvy8.js +0 -301
- package/dist/service-client-cli-xbj7j5kj.js +0 -1251
|
@@ -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();
|
|
@@ -542,12 +809,23 @@ var openCliSessionStore = async (options) => {
|
|
|
542
809
|
ORDER BY activity_seq DESC
|
|
543
810
|
LIMIT ?3
|
|
544
811
|
`).all(workspaceKey, scopeKey, limit, search);
|
|
812
|
+
if (rows.length === 0)
|
|
813
|
+
return [];
|
|
814
|
+
const summaries = database.query(`
|
|
815
|
+
WITH totals AS (
|
|
816
|
+
SELECT session_id, COUNT(*) AS run_count, MAX(ordinal) AS latest_ordinal
|
|
817
|
+
FROM zhivex_cli_session_runs WHERE session_id IN (SELECT value FROM json_each(?))
|
|
818
|
+
GROUP BY session_id
|
|
819
|
+
)
|
|
820
|
+
SELECT r.*, totals.run_count FROM totals JOIN zhivex_cli_session_runs r
|
|
821
|
+
ON r.session_id=totals.session_id AND r.ordinal=totals.latest_ordinal
|
|
822
|
+
`).all(JSON.stringify(rows.map((row) => row.session_id)));
|
|
823
|
+
const bySession = new Map(summaries.map((row) => [row.session_id, row]));
|
|
545
824
|
return rows.map((row) => {
|
|
546
|
-
const latest =
|
|
547
|
-
const runCount = database.query("SELECT COUNT(*) AS count FROM zhivex_cli_session_runs WHERE session_id = ?1").get(row.session_id)?.count ?? 0;
|
|
825
|
+
const latest = bySession.get(row.session_id);
|
|
548
826
|
return {
|
|
549
827
|
...sessionBase(row),
|
|
550
|
-
runCount,
|
|
828
|
+
runCount: latest?.run_count ?? 0,
|
|
551
829
|
...latest ? { latestRun: toRunReference(latest) } : {}
|
|
552
830
|
};
|
|
553
831
|
});
|
|
@@ -612,11 +890,11 @@ var openCliSessionStore = async (options) => {
|
|
|
612
890
|
throw new HarnessStateConflictError(`Run ${input.runId} is already immutably bound to ${existing.provider}/${existing.model} in this session.`);
|
|
613
891
|
}
|
|
614
892
|
assertNoActiveRun(candidateSessionId, "start another run in");
|
|
615
|
-
const
|
|
616
|
-
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) {
|
|
617
895
|
throw new HarnessStateConflictError(`Run-reference limit reached for session ${candidateSessionId} (${maxRuns}).`);
|
|
618
896
|
}
|
|
619
|
-
insertRun(candidateSessionId, input,
|
|
897
|
+
insertRun(candidateSessionId, input, count2);
|
|
620
898
|
const updatedAt = now();
|
|
621
899
|
assertTimestamp("now", updatedAt);
|
|
622
900
|
const activitySequence = nextActivitySequence();
|
|
@@ -692,11 +970,11 @@ var openCliSessionStore = async (options) => {
|
|
|
692
970
|
if (forkRuns.length > maxRuns) {
|
|
693
971
|
throw new HarnessStateConflictError(`Fork history exceeds the ${maxRuns}-run limit.`);
|
|
694
972
|
}
|
|
695
|
-
const
|
|
973
|
+
const count2 = database.query(`
|
|
696
974
|
SELECT COUNT(*) AS count FROM zhivex_cli_sessions
|
|
697
975
|
WHERE workspace_key = ?1 AND scope_key = ?2
|
|
698
976
|
`).get(workspaceKey, scopeKey)?.count ?? 0;
|
|
699
|
-
if (
|
|
977
|
+
if (count2 >= maxSessions) {
|
|
700
978
|
throw new HarnessStateConflictError(`Session limit reached for this workspace and scope (${maxSessions}).`);
|
|
701
979
|
}
|
|
702
980
|
const createdAt = now();
|
|
@@ -762,106 +1040,31 @@ var openCliSessionStore = async (options) => {
|
|
|
762
1040
|
};
|
|
763
1041
|
var openSessionStore = openCliSessionStore;
|
|
764
1042
|
|
|
765
|
-
// src/runtime/
|
|
766
|
-
import { z } from "zod";
|
|
767
|
-
import { createRedactionPolicy as createRedactionPolicy2 } from "@zhivex-ai/agents";
|
|
768
|
-
var count = z.number().int().nonnegative().finite();
|
|
769
|
-
var digest = z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable();
|
|
770
|
-
var diagnosticsSchema = z.object({
|
|
771
|
-
schemaVersion: z.literal(2),
|
|
772
|
-
requireVerifiedDelivery: z.boolean(),
|
|
773
|
-
budget: z.object({
|
|
774
|
-
inputTokens: count,
|
|
775
|
-
outputTokens: count,
|
|
776
|
-
cachedInputTokens: count,
|
|
777
|
-
modelCalls: count,
|
|
778
|
-
usageComplete: z.boolean(),
|
|
779
|
-
inFlight: z.boolean(),
|
|
780
|
-
stopReason: z.enum(["USAGE_UNAVAILABLE", "WORK_TOKEN_BUDGET", "INPUT_TOKEN_BUDGET", "OUTPUT_TOKEN_BUDGET"]).nullable(),
|
|
781
|
-
reservedInputTokens: count,
|
|
782
|
-
reservedOutputTokens: count,
|
|
783
|
-
predictedInputTokens: count,
|
|
784
|
-
outputCapApplied: z.boolean().default(false)
|
|
785
|
-
}),
|
|
786
|
-
phase: z.enum(["explore", "reproduce", "candidate", "verify", "recover", "delivered", "incomplete"]),
|
|
787
|
-
candidate: digest,
|
|
788
|
-
revision: count,
|
|
789
|
-
checks: z.array(z.object({
|
|
790
|
-
commandId: z.string().max(128),
|
|
791
|
-
purpose: z.string().max(500),
|
|
792
|
-
argvDigest: digest,
|
|
793
|
-
candidate: digest,
|
|
794
|
-
exitCode: z.number().int(),
|
|
795
|
-
verified: z.boolean()
|
|
796
|
-
})).max(8),
|
|
797
|
-
contextMeasurements: z.array(z.object({
|
|
798
|
-
systemCharacters: count,
|
|
799
|
-
userCharacters: count,
|
|
800
|
-
assistantCharacters: count,
|
|
801
|
-
toolResultCharacters: count,
|
|
802
|
-
otherMessageCharacters: count,
|
|
803
|
-
toolDefinitionCharacters: count,
|
|
804
|
-
unmeasuredToolDefinitions: count
|
|
805
|
-
})).max(128),
|
|
806
|
-
modelTimings: z.array(z.object({ durationMs: z.number().nonnegative().finite(), firstTokenMs: z.number().nonnegative().finite().nullable(), completed: z.boolean() })).max(128),
|
|
807
|
-
omittedContextMeasurements: count
|
|
808
|
-
});
|
|
809
|
-
var manifestSchema = z.object({
|
|
810
|
-
schemaVersion: z.literal(2),
|
|
811
|
-
policyVersion: z.literal("assistant-v3-durable-closure"),
|
|
812
|
-
role: z.string().max(128),
|
|
813
|
-
requireVerifiedDelivery: z.boolean(),
|
|
814
|
-
backend: z.enum(["none", "oci"]),
|
|
815
|
-
tools: z.array(z.string().max(128)).max(1024),
|
|
816
|
-
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() }),
|
|
817
|
-
timeoutMs: count,
|
|
818
|
-
unlimitedDuration: z.boolean().optional(),
|
|
819
|
-
closureController: z.boolean(),
|
|
820
|
-
contextEnabled: z.boolean()
|
|
821
|
-
});
|
|
822
|
-
var redact = createRedactionPolicy2({ includeEmails: true });
|
|
823
|
-
var inspectRuntimeDiagnostics = (value) => {
|
|
824
|
-
const parsed = diagnosticsSchema.safeParse(value);
|
|
825
|
-
if (!parsed.success)
|
|
826
|
-
return null;
|
|
827
|
-
return { ...parsed.data, checks: parsed.data.checks.map((check) => ({
|
|
828
|
-
...check,
|
|
829
|
-
commandId: redact.redactText(check.commandId),
|
|
830
|
-
purpose: redact.redactText(check.purpose)
|
|
831
|
-
})) };
|
|
832
|
-
};
|
|
833
|
-
var inspectRuntimeManifest = (value) => {
|
|
834
|
-
const parsed = manifestSchema.safeParse(value);
|
|
835
|
-
if (!parsed.success)
|
|
836
|
-
return null;
|
|
837
|
-
return { ...parsed.data, role: redact.redactText(parsed.data.role), tools: parsed.data.tools.map((name) => redact.redactText(name)) };
|
|
838
|
-
};
|
|
839
|
-
|
|
840
|
-
// src/runtime/usage-ledger.ts
|
|
1043
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
841
1044
|
import { ProviderToolCallError as ProviderToolCallError2 } from "@zhivex-ai/core/provider";
|
|
842
1045
|
|
|
843
|
-
// src/runtime/task-usage-context.ts
|
|
1046
|
+
// packages/core/src/runtime/task-usage-context.ts
|
|
844
1047
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
845
1048
|
var taskUsageAdmission = new AsyncLocalStorage;
|
|
846
1049
|
|
|
847
|
-
// src/runtime/usage-ledger.ts
|
|
1050
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
848
1051
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
849
1052
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
850
|
-
import { lstat as
|
|
851
|
-
import { z as
|
|
1053
|
+
import { lstat as lstat5 } from "node:fs/promises";
|
|
1054
|
+
import { z as z6 } from "zod";
|
|
852
1055
|
import { fingerprintAgentHarness, wrapLanguageModel } from "@zhivex-ai/core";
|
|
853
1056
|
|
|
854
|
-
// src/runtime/model-budget.ts
|
|
1057
|
+
// packages/core/src/runtime/model-budget.ts
|
|
855
1058
|
import { ProviderToolCallError } from "@zhivex-ai/core/provider";
|
|
856
|
-
import { z as
|
|
1059
|
+
import { z as z5 } from "zod";
|
|
857
1060
|
|
|
858
|
-
// src/context/context-metrics.ts
|
|
859
|
-
import { z as
|
|
1061
|
+
// packages/core/src/context/context-metrics.ts
|
|
1062
|
+
import { z as z4 } from "zod";
|
|
860
1063
|
var schemaJson = new WeakMap;
|
|
861
1064
|
var serializeSchema = (schema) => {
|
|
862
1065
|
let serialized = schemaJson.get(schema);
|
|
863
1066
|
if (serialized === undefined) {
|
|
864
|
-
serialized = JSON.stringify(
|
|
1067
|
+
serialized = JSON.stringify(z4.toJSONSchema(schema));
|
|
865
1068
|
schemaJson.set(schema, serialized);
|
|
866
1069
|
}
|
|
867
1070
|
return serialized;
|
|
@@ -909,15 +1112,15 @@ var measureContext = (input) => {
|
|
|
909
1112
|
return counts;
|
|
910
1113
|
};
|
|
911
1114
|
|
|
912
|
-
// src/runtime/model-budget.ts
|
|
1115
|
+
// packages/core/src/runtime/model-budget.ts
|
|
913
1116
|
var MODEL_BUDGET_KEY = "zhivexTransportBudget";
|
|
914
|
-
var savedBudget =
|
|
915
|
-
inputTokens:
|
|
916
|
-
outputTokens:
|
|
917
|
-
cachedInputTokens:
|
|
918
|
-
modelCalls:
|
|
919
|
-
usageComplete:
|
|
920
|
-
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)
|
|
921
1124
|
});
|
|
922
1125
|
var estimateRequestTokens = (input) => estimateContextTokens(measureContext(input));
|
|
923
1126
|
var workBudgetReached = (input, stats, limits) => stats.inputTokens + estimateRequestTokens(input) > limits.inputTokens - stats.reservedInputTokens || stats.outputTokens >= limits.outputTokens - stats.reservedOutputTokens;
|
|
@@ -1055,19 +1258,19 @@ var createModelBudget = (limits, options = {}) => {
|
|
|
1055
1258
|
} };
|
|
1056
1259
|
};
|
|
1057
1260
|
|
|
1058
|
-
// src/runtime/usage-ledger.ts
|
|
1261
|
+
// packages/core/src/runtime/usage-ledger.ts
|
|
1059
1262
|
var USAGE_LEDGER_KEY = "zhivexUsageLedger";
|
|
1060
|
-
var rate =
|
|
1061
|
-
var usagePricingSchema =
|
|
1062
|
-
schemaVersion:
|
|
1063
|
-
prices:
|
|
1064
|
-
provider:
|
|
1065
|
-
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),
|
|
1066
1269
|
inputUsdPerMillion: rate,
|
|
1067
1270
|
outputUsdPerMillion: rate,
|
|
1068
|
-
source:
|
|
1069
|
-
asOf:
|
|
1070
|
-
expiresAt:
|
|
1271
|
+
source: z6.string().min(1).max(1024),
|
|
1272
|
+
asOf: z6.iso.datetime(),
|
|
1273
|
+
expiresAt: z6.iso.datetime()
|
|
1071
1274
|
})).max(100)
|
|
1072
1275
|
}).superRefine((value, ctx) => {
|
|
1073
1276
|
const keys = new Set;
|
|
@@ -1079,28 +1282,28 @@ var usagePricingSchema = z4.strictObject({
|
|
|
1079
1282
|
keys.add(key);
|
|
1080
1283
|
}
|
|
1081
1284
|
});
|
|
1082
|
-
var summaryView =
|
|
1083
|
-
calls:
|
|
1285
|
+
var summaryView = z6.object({
|
|
1286
|
+
calls: z6.number().int().nonnegative(),
|
|
1084
1287
|
inputTokens: rate,
|
|
1085
1288
|
outputTokens: rate,
|
|
1086
|
-
usageComplete:
|
|
1289
|
+
usageComplete: z6.boolean(),
|
|
1087
1290
|
estimatedUsd: rate.nullable(),
|
|
1088
1291
|
limitUsd: rate.nullable()
|
|
1089
1292
|
});
|
|
1090
1293
|
var ledgerView = summaryView.extend({
|
|
1091
|
-
schemaVersion:
|
|
1092
|
-
runId:
|
|
1093
|
-
historicalUsageUnknown:
|
|
1094
|
-
costKind:
|
|
1095
|
-
routes:
|
|
1096
|
-
provider:
|
|
1097
|
-
model:
|
|
1098
|
-
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(),
|
|
1099
1302
|
inputTokens: rate,
|
|
1100
1303
|
outputTokens: rate,
|
|
1101
|
-
unknownCalls:
|
|
1304
|
+
unknownCalls: z6.number().int().nonnegative(),
|
|
1102
1305
|
estimatedUsd: rate.nullable(),
|
|
1103
|
-
priceStatuses:
|
|
1306
|
+
priceStatuses: z6.array(z6.enum(["missing", "stale", "estimate"]))
|
|
1104
1307
|
})).max(100)
|
|
1105
1308
|
});
|
|
1106
1309
|
var inspectUsageLedger = (value) => {
|
|
@@ -1165,11 +1368,11 @@ class UsageLedger {
|
|
|
1165
1368
|
const key = `${sessions.workspaceKey}:${sessions.scopeKey}`;
|
|
1166
1369
|
const databasePath = sessions.databasePath;
|
|
1167
1370
|
sessions.close();
|
|
1168
|
-
const before = await
|
|
1371
|
+
const before = await lstat5(databasePath);
|
|
1169
1372
|
if (before.isSymbolicLink() || !before.isFile())
|
|
1170
1373
|
throw new Error("Usage database must be a regular private file.");
|
|
1171
1374
|
const database = new SqliteDatabase(databasePath, { create: false, strict: true });
|
|
1172
|
-
const after = await
|
|
1375
|
+
const after = await lstat5(databasePath);
|
|
1173
1376
|
if (after.isSymbolicLink() || !after.isFile() || before.dev !== after.dev || before.ino !== after.ino) {
|
|
1174
1377
|
database.close();
|
|
1175
1378
|
throw new Error("Usage database changed while opening.");
|
|
@@ -1431,181 +1634,12 @@ var assertTaskMonetaryReceipts = (ledger, runId, expected, allocations) => {
|
|
|
1431
1634
|
throw new Error("TASK_BUDGET_TOKEN_ALLOCATIONS_MISSING: restore complete task accounting; retained monetary receipts cannot replace missing token allocations.");
|
|
1432
1635
|
};
|
|
1433
1636
|
|
|
1434
|
-
// src/runtime/task-
|
|
1435
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
1436
|
-
import { z as z5 } from "zod";
|
|
1437
|
-
var identifier = z5.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/);
|
|
1438
|
-
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.");
|
|
1439
|
-
var exactPath = workspaceFilePathSchema.refine((value) => !/[\\*?\[\]{}\x00-\x1f\x7f]/.test(value), "Use an exact normalized file path, without globs or controls.");
|
|
1440
|
-
var argv = z5.array(z5.string().max(8192).refine((value) => !value.includes("\x00"), "Arguments cannot contain NUL.")).max(256);
|
|
1441
|
-
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.");
|
|
1442
|
-
var commonCheck = { id: identifier, command, args: argv, purpose: text(500) };
|
|
1443
|
-
var check = z5.discriminatedUnion("kind", [
|
|
1444
|
-
z5.strictObject({
|
|
1445
|
-
...commonCheck,
|
|
1446
|
-
kind: z5.literal("package-script"),
|
|
1447
|
-
script: identifier,
|
|
1448
|
-
expectedScript: text(8192),
|
|
1449
|
-
execution: z5.strictObject({ backend: z5.enum(["none", "oci"]), approval: z5.literal("required") })
|
|
1450
|
-
}),
|
|
1451
|
-
z5.strictObject({
|
|
1452
|
-
...commonCheck,
|
|
1453
|
-
kind: z5.literal("argv"),
|
|
1454
|
-
execution: z5.strictObject({ backend: z5.literal("oci"), approval: z5.literal("required"), network: z5.literal("none") })
|
|
1455
|
-
})
|
|
1456
|
-
]);
|
|
1457
|
-
var taskAcceptanceContractSchema = z5.strictObject({
|
|
1458
|
-
schemaVersion: z5.literal(1),
|
|
1459
|
-
taskId: identifier,
|
|
1460
|
-
allowedWritePaths: z5.array(exactPath).max(256),
|
|
1461
|
-
protectedFiles: z5.array(exactPath).max(256),
|
|
1462
|
-
requiredChecks: z5.array(check).min(1).max(32),
|
|
1463
|
-
humanReview: z5.array(z5.strictObject({ id: identifier, requirement: text(2000), status: z5.literal("pending") })).max(32)
|
|
1464
|
-
}).superRefine((contract, context) => {
|
|
1465
|
-
const unique = (values, field) => {
|
|
1466
|
-
if (new Set(values).size !== values.length)
|
|
1467
|
-
context.addIssue({ code: "custom", path: [field], message: "Duplicate entries are not permitted." });
|
|
1468
|
-
};
|
|
1469
|
-
unique(contract.allowedWritePaths.map((p) => p.toLowerCase()), "allowedWritePaths");
|
|
1470
|
-
unique(contract.protectedFiles.map((p) => p.toLowerCase()), "protectedFiles");
|
|
1471
|
-
unique(contract.requiredChecks.map((c) => c.id), "requiredChecks");
|
|
1472
|
-
unique(contract.humanReview.map((c) => c.id), "humanReview");
|
|
1473
|
-
const overlaps = (a, b) => a === b || a.startsWith(b + "/") || b.startsWith(a + "/");
|
|
1474
|
-
const writes = contract.allowedWritePaths.map((p) => p.toLowerCase());
|
|
1475
|
-
if (writes.some((p, i) => writes.slice(i + 1).some((q) => overlaps(p, q)))) {
|
|
1476
|
-
context.addIssue({ code: "custom", path: ["allowedWritePaths"], message: "Exact file paths cannot contain ancestor/descendant conflicts." });
|
|
1477
|
-
}
|
|
1478
|
-
if (writes.some((p) => contract.protectedFiles.some((q) => overlaps(p, q.toLowerCase())))) {
|
|
1479
|
-
context.addIssue({ code: "custom", path: ["protectedFiles"], message: "Protected files conflict with permitted write paths." });
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
var MAX_TASK_ACCEPTANCE_BYTES = 64 * 1024;
|
|
1483
|
-
function compileTaskAcceptanceContract(input) {
|
|
1484
|
-
let bytes;
|
|
1485
|
-
try {
|
|
1486
|
-
bytes = Buffer.byteLength(JSON.stringify(input));
|
|
1487
|
-
} catch {
|
|
1488
|
-
throw new Error("TASK_ACCEPTANCE_INVALID: requirements must be JSON serializable.");
|
|
1489
|
-
}
|
|
1490
|
-
if (bytes > MAX_TASK_ACCEPTANCE_BYTES)
|
|
1491
|
-
throw new Error("TASK_ACCEPTANCE_TOO_LARGE: requirements exceed 64 KiB.");
|
|
1492
|
-
const parsed = taskAcceptanceContractSchema.safeParse(input);
|
|
1493
|
-
if (!parsed.success)
|
|
1494
|
-
throw new Error("TASK_ACCEPTANCE_INVALID: " + parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; "));
|
|
1495
|
-
const sorted = (items) => items.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
1496
|
-
const contract = {
|
|
1497
|
-
schemaVersion: 1,
|
|
1498
|
-
taskId: parsed.data.taskId,
|
|
1499
|
-
allowedWritePaths: [...parsed.data.allowedWritePaths].sort(),
|
|
1500
|
-
protectedFiles: [...parsed.data.protectedFiles].sort(),
|
|
1501
|
-
requiredChecks: sorted(parsed.data.requiredChecks),
|
|
1502
|
-
humanReview: sorted(parsed.data.humanReview)
|
|
1503
|
-
};
|
|
1504
|
-
return { contract, digest: `sha256:${createHash2("sha256").update(JSON.stringify(contract)).digest("hex")}` };
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
// src/runtime/task-acceptance-record.ts
|
|
1508
|
-
import { z as z6 } from "zod";
|
|
1509
|
-
import { serializeJsonValue } from "@zhivex-ai/core";
|
|
1510
|
-
var TASK_ACCEPTANCE_KEY = "zhivexTaskAcceptanceV1";
|
|
1511
|
-
var TASK_ACCEPTANCE_EVIDENCE_KEY = "zhivexTaskAcceptanceEvidenceV1";
|
|
1512
|
-
var digest2 = z6.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
1513
|
-
var revisionSchema = z6.strictObject({ revision: z6.number().int().min(1), digest: digest2, previousDigest: digest2.nullable(), contract: taskAcceptanceContractSchema });
|
|
1514
|
-
var ledgerSchema = z6.strictObject({ schemaVersion: z6.literal(1), revisions: z6.array(revisionSchema).min(1).max(16) });
|
|
1515
|
-
function readTaskAcceptanceLedger(state) {
|
|
1516
|
-
const raw = state.metadata?.[TASK_ACCEPTANCE_KEY];
|
|
1517
|
-
if (raw === undefined)
|
|
1518
|
-
return;
|
|
1519
|
-
if (Buffer.byteLength(JSON.stringify(raw)) > 1024 * 1024)
|
|
1520
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1521
|
-
const ledger = ledgerSchema.parse(raw);
|
|
1522
|
-
for (let index = 0;index < ledger.revisions.length; index++) {
|
|
1523
|
-
const row = ledger.revisions[index];
|
|
1524
|
-
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) {
|
|
1525
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_INVALID");
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
return ledger;
|
|
1529
|
-
}
|
|
1530
|
-
function nextTaskAcceptanceLedger(current2, requirements) {
|
|
1531
|
-
if (current2)
|
|
1532
|
-
current2 = readTaskAcceptanceLedger({ metadata: { [TASK_ACCEPTANCE_KEY]: serializeJsonValue(current2) } });
|
|
1533
|
-
const { contract, digest: digest3 } = compileTaskAcceptanceContract(requirements);
|
|
1534
|
-
const previous = current2?.revisions.at(-1);
|
|
1535
|
-
if (previous && previous.contract.taskId !== contract.taskId)
|
|
1536
|
-
throw new Error("TASK_ACCEPTANCE_TASK_ID_IMMUTABLE");
|
|
1537
|
-
if (previous?.digest === digest3)
|
|
1538
|
-
throw new Error("TASK_ACCEPTANCE_UNCHANGED");
|
|
1539
|
-
if ((current2?.revisions.length ?? 0) >= 16)
|
|
1540
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1541
|
-
const next = { schemaVersion: 1, revisions: [...structuredClone(current2?.revisions ?? []), {
|
|
1542
|
-
revision: (previous?.revision ?? 0) + 1,
|
|
1543
|
-
previousDigest: previous?.digest ?? null,
|
|
1544
|
-
digest: digest3,
|
|
1545
|
-
contract
|
|
1546
|
-
}] };
|
|
1547
|
-
if (Buffer.byteLength(JSON.stringify(next)) > 1024 * 1024)
|
|
1548
|
-
throw new Error("TASK_ACCEPTANCE_HISTORY_CAPACITY");
|
|
1549
|
-
return next;
|
|
1550
|
-
}
|
|
1551
|
-
async function persistTaskAcceptanceRevision(store, options) {
|
|
1552
|
-
const state = await store.load(options.runId, options.scope);
|
|
1553
|
-
if (!state || state.revision !== options.expectedRunRevision)
|
|
1554
|
-
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
1555
|
-
const current2 = readTaskAcceptanceLedger(state);
|
|
1556
|
-
if ((current2?.revisions.at(-1)?.revision ?? 0) !== options.expectedContractRevision)
|
|
1557
|
-
throw new Error("TASK_ACCEPTANCE_REVISION_CONFLICT");
|
|
1558
|
-
const ledger = nextTaskAcceptanceLedger(current2, options.requirements), latest = ledger.revisions.at(-1);
|
|
1559
|
-
const prior = current2?.revisions.at(-1);
|
|
1560
|
-
const oldEvidence = state.metadata?.[TASK_ACCEPTANCE_EVIDENCE_KEY];
|
|
1561
|
-
const sameFiles = prior && JSON.stringify([prior.contract.allowedWritePaths, prior.contract.protectedFiles]) === JSON.stringify([latest.contract.allowedWritePaths, latest.contract.protectedFiles]);
|
|
1562
|
-
const previousChecks = z6.array(taskCheckReceiptSchema).max(32).safeParse(oldEvidence?.checks);
|
|
1563
|
-
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 })) : [];
|
|
1564
|
-
await store.save({ ...state, metadata: {
|
|
1565
|
-
...state.metadata,
|
|
1566
|
-
[TASK_ACCEPTANCE_KEY]: serializeJsonValue(ledger),
|
|
1567
|
-
[TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
1568
|
-
schemaVersion: 1,
|
|
1569
|
-
contractRevision: latest.revision,
|
|
1570
|
-
contractDigest: latest.digest,
|
|
1571
|
-
status: "pending",
|
|
1572
|
-
checks,
|
|
1573
|
-
humanReview: latest.contract.humanReview,
|
|
1574
|
-
...sameFiles && oldEvidence?.delivery ? { delivery: oldEvidence.delivery } : {}
|
|
1575
|
-
})
|
|
1576
|
-
} }, { expectedRevision: options.expectedRunRevision });
|
|
1577
|
-
return structuredClone(ledger);
|
|
1578
|
-
}
|
|
1579
|
-
function taskAcceptanceCheckpointStore(store, runId, ledger) {
|
|
1580
|
-
const retained = serializeJsonValue(structuredClone(ledger));
|
|
1581
|
-
const latest = ledger.revisions.at(-1);
|
|
1582
|
-
const pending = { schemaVersion: 1, contractRevision: latest.revision, contractDigest: latest.digest, status: "pending", checks: [], humanReview: serializeJsonValue(latest.contract.humanReview) };
|
|
1583
|
-
return new Proxy(store, { get(target, key) {
|
|
1584
|
-
if (key === "save")
|
|
1585
|
-
return async (...args) => {
|
|
1586
|
-
const [state] = args;
|
|
1587
|
-
if (state.runId === runId) {
|
|
1588
|
-
const violation = taskAcceptanceDeliveryDiagnostic(latest.digest, latest.revision);
|
|
1589
|
-
state.metadata = { ...state.metadata, [TASK_ACCEPTANCE_KEY]: structuredClone(retained), [TASK_ACCEPTANCE_EVIDENCE_KEY]: serializeJsonValue({
|
|
1590
|
-
...structuredClone(pending),
|
|
1591
|
-
...await taskAcceptanceOutcome(state, ledger),
|
|
1592
|
-
checks: serializeJsonValue(taskAcceptanceChecks()?.snapshot() ?? []),
|
|
1593
|
-
...violation ? { status: "failed", diagnostic: serializeJsonValue(violation) } : {}
|
|
1594
|
-
}) };
|
|
1595
|
-
}
|
|
1596
|
-
return target.save(...args);
|
|
1597
|
-
};
|
|
1598
|
-
const value = Reflect.get(target, key, target);
|
|
1599
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
1600
|
-
} });
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
// src/runtime/task-budget.ts
|
|
1637
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1604
1638
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
1605
1639
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1606
1640
|
import { z as z7 } from "zod";
|
|
1607
1641
|
|
|
1608
|
-
// src/runtime/budget-ledger-scope.ts
|
|
1642
|
+
// packages/core/src/runtime/budget-ledger-scope.ts
|
|
1609
1643
|
var BUDGET_LEDGER_NAMESPACE = "__zhivex_budget__";
|
|
1610
1644
|
var BUDGET_OWNER_NAMESPACE_KEY = "budgetOwnerNamespace";
|
|
1611
1645
|
var isReservedBudgetNamespace = (namespace) => namespace === BUDGET_LEDGER_NAMESPACE || (namespace?.startsWith(`${BUDGET_LEDGER_NAMESPACE}:`) ?? false);
|
|
@@ -1676,7 +1710,7 @@ var bindBudgetLedgerStore = (primary, scope, budget = primary) => {
|
|
|
1676
1710
|
};
|
|
1677
1711
|
};
|
|
1678
1712
|
|
|
1679
|
-
// src/runtime/task-budget.ts
|
|
1713
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1680
1714
|
import {
|
|
1681
1715
|
createAgentBudgetCoordinator,
|
|
1682
1716
|
fingerprintAgentHarness as fingerprintAgentHarness2,
|
|
@@ -1684,7 +1718,7 @@ import {
|
|
|
1684
1718
|
} from "@zhivex-ai/core";
|
|
1685
1719
|
import { ProviderToolCallError as ProviderToolCallError3 } from "@zhivex-ai/core/provider";
|
|
1686
1720
|
|
|
1687
|
-
// src/runtime/runtime-instructions.ts
|
|
1721
|
+
// packages/core/src/runtime/runtime-instructions.ts
|
|
1688
1722
|
var withRuntimeInstruction = (messages, text2) => {
|
|
1689
1723
|
const firstConversation = messages.findIndex((message) => message.role !== "system");
|
|
1690
1724
|
const at = firstConversation === -1 ? messages.length : firstConversation;
|
|
@@ -1711,7 +1745,7 @@ var withFreshSystemInstructions = (input, hostInstructions) => {
|
|
|
1711
1745
|
`), messages: input.messages.slice(count2) };
|
|
1712
1746
|
};
|
|
1713
1747
|
|
|
1714
|
-
// src/runtime/task-budget.ts
|
|
1748
|
+
// packages/core/src/runtime/task-budget.ts
|
|
1715
1749
|
var TASK_BUDGET_KEY = "zhivexTaskBudgetV1";
|
|
1716
1750
|
var TASK_BUDGET_ACCOUNT_KEY = "zhivexTaskBudgetAccountV1";
|
|
1717
1751
|
var token = z7.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
@@ -2341,4 +2375,4 @@ class TaskBudget {
|
|
|
2341
2375
|
}
|
|
2342
2376
|
}
|
|
2343
2377
|
|
|
2344
|
-
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 };
|