@zhivex-ai/harness 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +17 -5
- package/SECURITY.md +1 -1
- package/SUPPORT.md +2 -2
- package/benchmarks/README.md +26 -0
- package/contracts/engine-api.json +1557 -0
- package/contracts/public-api.json +114 -0
- package/contracts/stable-api-signatures.json +17 -17
- package/dist/acp-cli.js +37 -1090
- package/dist/application/agenda.d.ts +10 -0
- package/dist/application/approval-review.d.ts +61 -0
- package/dist/application/assistant/automation/scheduler.d.ts +21 -0
- package/dist/application/assistant/automation/summary.d.ts +29 -0
- package/dist/application/assistant/automation/time.d.ts +10 -0
- package/dist/application/assistant/calendar/calendar.d.ts +238 -0
- package/dist/application/assistant/calendar/connection.d.ts +50 -0
- package/dist/application/assistant/calendar/create-event.d.ts +75 -0
- package/dist/application/assistant/calendar/environment.d.ts +2 -0
- package/dist/application/assistant/calendar/http.d.ts +6 -0
- package/dist/application/assistant/calendar/oauth.d.ts +68 -0
- package/dist/application/assistant/calendar/store.d.ts +11 -0
- package/dist/application/assistant/calendar/tools.d.ts +78 -0
- package/dist/application/assistant/client.d.ts +10 -0
- package/dist/application/assistant/config.d.ts +9 -0
- package/dist/application/assistant/contracts.d.ts +77 -0
- package/dist/application/assistant/daily/service.d.ts +181 -0
- package/dist/application/assistant/doctor.d.ts +22 -0
- package/dist/application/assistant/evaluation.d.ts +81 -0
- package/dist/application/assistant/host.d.ts +399 -0
- package/dist/application/assistant/integrations/google.d.ts +117 -0
- package/dist/application/assistant/integrations/public-web.d.ts +16 -0
- package/dist/application/assistant/managed/secrets.d.ts +10 -0
- package/dist/application/assistant/managed/setup-state.d.ts +346 -0
- package/dist/application/assistant/managed/setup.d.ts +492 -0
- package/dist/application/assistant/microsoft/connection.d.ts +73 -0
- package/dist/application/assistant/microsoft/tools.d.ts +78 -0
- package/dist/application/assistant/modules/calendar.d.ts +3 -0
- package/dist/application/assistant/modules/catalog.d.ts +38 -0
- package/dist/application/assistant/modules/daily.d.ts +5 -0
- package/dist/application/assistant/modules/github.d.ts +5 -0
- package/dist/application/assistant/modules/google.d.ts +3 -0
- package/dist/application/assistant/modules/mcp.d.ts +11 -0
- package/dist/application/assistant/modules/microsoft.d.ts +3 -0
- package/dist/application/assistant/modules/module.d.ts +224 -0
- package/dist/application/assistant/modules/tools.d.ts +11 -0
- package/dist/application/assistant/modules/web.d.ts +7 -0
- package/dist/application/assistant/private-directory.d.ts +3 -0
- package/dist/application/assistant/proactive/service.d.ts +142 -0
- package/dist/application/assistant/providers/openai-compatible.d.ts +66 -0
- package/dist/application/assistant/providers/provider.d.ts +141 -0
- package/dist/application/assistant/providers/web-citations.d.ts +2 -0
- package/dist/application/assistant/runtime.d.ts +16 -0
- package/dist/application/assistant/task-metrics.d.ts +304 -0
- package/dist/application/assistant/telegram/api.d.ts +47 -0
- package/dist/application/assistant/telegram/bridge.d.ts +69 -0
- package/dist/application/assistant/telegram/store.d.ts +10 -0
- package/dist/application/automation.d.ts +5 -0
- package/dist/application/calendar-review.d.ts +5 -0
- package/dist/application/checkpoint-review.d.ts +30 -0
- package/dist/application/client.d.ts +18 -0
- package/dist/application/code/context.d.ts +5 -0
- package/dist/application/code/delivery.d.ts +6 -0
- package/dist/application/code/git-delivery.d.ts +54 -0
- package/dist/application/code/github-git-transport.d.ts +15 -0
- package/dist/application/code/github-pr-transport.d.ts +6 -0
- package/dist/application/code/host.d.ts +25 -0
- package/dist/application/code/pr-delivery.d.ts +79 -0
- package/dist/application/code/projects.d.ts +90 -0
- package/dist/application/code/remote-delivery.d.ts +80 -0
- package/dist/application/code/repository.d.ts +9 -0
- package/dist/application/code/worktrees.d.ts +123 -0
- package/dist/application/contracts.d.ts +288 -0
- package/dist/application/coordinator-client.d.ts +33 -0
- package/dist/application/coordinator-discovery.d.ts +17 -0
- package/dist/application/coordinator-launcher.d.ts +2 -0
- package/dist/application/coordinator.d.ts +27 -0
- package/dist/application/credential-process.d.ts +13 -0
- package/dist/application/host.d.ts +7 -0
- package/dist/application/management.d.ts +68 -0
- package/dist/application/notes.d.ts +5 -0
- package/dist/application/offline-migration.d.ts +16 -0
- package/dist/application/personal-state.d.ts +5 -0
- package/dist/application/review-channel.d.ts +23 -0
- package/dist/application/review-tickets.d.ts +29 -0
- package/dist/application/runtime-binding.d.ts +4 -0
- package/dist/application-cli-wfh08g41.js +184 -0
- package/dist/application-cli-z3f9pvcf.js +209 -0
- package/dist/approvals/auto-approve.d.ts +1 -1
- package/dist/arguments-75r85mvc.js +27 -0
- package/dist/arguments-x24bbqvd.js +22 -0
- package/dist/audit/index.js +16 -472
- package/dist/audit-pack-1gnych0m.js +93 -0
- package/dist/{audit-pack-y02n8zd0.js → audit-pack-h44kjkbj.js} +17 -11
- package/dist/calendar-2xw0rr7b.js +49 -0
- package/dist/cli/application-cli.d.ts +2 -0
- package/dist/cli/arguments.d.ts +14 -1
- package/dist/cli/auto-approve-setup.d.ts +13 -0
- package/dist/cli/configured-harness.d.ts +1 -2
- package/dist/cli/console/console-budget.d.ts +16 -2
- package/dist/cli/console/console-checkpoints.d.ts +12 -0
- package/dist/cli/console/console-commands.d.ts +3 -3
- package/dist/cli/console/console-compaction.d.ts +1 -1
- package/dist/cli/console/console-diff.d.ts +2 -0
- package/dist/cli/console/console-input.d.ts +29 -1
- package/dist/cli/console/console-navigation.d.ts +2 -2
- package/dist/cli/console/console-outcome.d.ts +10 -0
- package/dist/cli/console/console-presentation.d.ts +17 -2
- package/dist/cli/console/console-pricing.d.ts +14 -0
- package/dist/cli/console/console-reasoning.d.ts +1 -1
- package/dist/cli/console/console-recovery.d.ts +2 -0
- package/dist/cli/console/console-review.d.ts +34 -0
- package/dist/cli/console/console-run-policy.d.ts +5 -0
- package/dist/cli/console/console-run-view.d.ts +28 -0
- package/dist/cli/console/console-task.d.ts +30 -0
- package/dist/cli/console/console-welcome.d.ts +13 -3
- package/dist/cli/console/review-diff.d.ts +20 -0
- package/dist/cli/presentation.d.ts +8 -6
- package/dist/cli/service-checkpoints.d.ts +234 -0
- package/dist/cli/terminal/activity-history.d.ts +4 -2
- package/dist/cli/terminal/activity-stream.d.ts +33 -0
- package/dist/cli/terminal/file-diff.d.ts +11 -0
- package/dist/cli/terminal/terminal-theme.d.ts +9 -0
- package/dist/cli/terminal/terminal-ui.d.ts +44 -2
- package/dist/cli/terminal/tool-activity.d.ts +6 -2
- package/dist/{cli-entry-hdtfef27.js → cli-entry-68kqraj7.js} +95 -43
- package/dist/{cli-entry-j6jcb2jb.js → cli-entry-86rcbmwh.js} +294 -14
- package/dist/cli-entry-btkpb4h1.js +3627 -0
- package/dist/cli-entry-bxjbs6qq.js +200 -0
- package/dist/cli-entry-cpm89r9q.js +624 -0
- package/dist/{cli-entry-v5db3eb2.js → cli-entry-dksm56sj.js} +39 -297
- package/dist/{cli-entry-td04s0fa.js → cli-entry-eka68ttb.js} +3919 -4549
- package/dist/cli-entry-h7dcah4p.js +137 -0
- package/dist/cli-entry-kwk23ktq.js +33 -0
- package/dist/{cli-entry-ynahz9qc.js → cli-entry-vmce694z.js} +1251 -3139
- package/dist/cli-entry-wanv05db.js +1113 -0
- package/dist/{cli-zw18kdqx.js → cli-z7vhm1rk.js} +1767 -380
- package/dist/cli.js +8 -6
- package/dist/client/json-contracts.d.ts +153 -0
- package/dist/client/local-service.d.ts +7 -12
- package/dist/client/local-transport.d.ts +14 -0
- package/dist/client/protocol.d.ts +43 -1
- package/dist/compat/cli-options.d.ts +7 -1
- package/dist/compat/cli.d.ts +2 -0
- package/dist/compat/cli.js +4043 -0
- package/dist/compat/code-support.d.ts +3 -0
- package/dist/compat/code-support.js +50 -28
- package/dist/{config-r9fdhce6.js → config-hw78440t.js} +5 -5
- package/dist/{config-vyajmksy.js → config-v7s8hp37.js} +1 -1
- package/dist/context/adaptive-compaction.d.ts +1 -0
- package/dist/context/lossless-lines.d.ts +13 -0
- package/dist/context/numbered-read-lines.d.ts +15 -0
- package/dist/context/read-attempts.d.ts +21 -0
- package/dist/context/request-projection.d.ts +32 -4
- package/dist/context/scoped-context.d.ts +14 -0
- package/dist/context/working-read-replay.d.ts +12 -0
- package/dist/coordinator-client-nzysqxf0.js +10 -0
- package/dist/engine/acp.js +27 -21
- package/dist/engine/application-client.d.ts +11 -0
- package/dist/engine/application-client.js +18 -0
- package/dist/engine/application-protocol.d.ts +5 -0
- package/dist/engine/application-protocol.js +7 -0
- package/dist/engine/application.d.ts +43 -0
- package/dist/engine/application.js +206 -0
- package/dist/engine/assistant/automation/scheduler.d.ts +2 -0
- package/dist/engine/assistant/automation/scheduler.js +11 -0
- package/dist/engine/assistant/automation/summary.d.ts +3 -0
- package/dist/engine/assistant/automation/summary.js +8 -0
- package/dist/engine/assistant/automation/time.d.ts +5 -0
- package/dist/engine/assistant/automation/time.js +15 -0
- package/dist/engine/assistant/calendar/calendar.d.ts +5 -0
- package/dist/engine/assistant/calendar/calendar.js +12 -0
- package/dist/engine/assistant/calendar/connection.d.ts +2 -0
- package/dist/engine/assistant/calendar/connection.js +11 -0
- package/dist/engine/assistant/calendar/environment.d.ts +1 -0
- package/dist/engine/assistant/calendar/environment.js +7 -0
- package/dist/engine/assistant/calendar/http.d.ts +3 -0
- package/dist/engine/assistant/calendar/http.js +9 -0
- package/dist/engine/assistant/calendar/oauth.d.ts +5 -0
- package/dist/engine/assistant/calendar/oauth.js +12 -0
- package/dist/engine/assistant/calendar/store.d.ts +2 -0
- package/dist/engine/assistant/calendar/store.js +8 -0
- package/dist/engine/assistant/calendar/tools.d.ts +2 -0
- package/dist/engine/assistant/calendar/tools.js +46 -0
- package/dist/engine/assistant/client.d.ts +2 -0
- package/dist/engine/assistant/client.js +33 -0
- package/dist/engine/assistant/config.d.ts +1 -0
- package/dist/engine/assistant/config.js +102 -0
- package/dist/engine/assistant/contracts.d.ts +10 -0
- package/dist/engine/assistant/contracts.js +78 -0
- package/dist/engine/assistant/daily/service.d.ts +12 -0
- package/dist/engine/assistant/daily/service.js +27 -0
- package/dist/engine/assistant/doctor.d.ts +1 -0
- package/dist/engine/assistant/doctor.js +116 -0
- package/dist/engine/assistant/evaluation.d.ts +2 -0
- package/dist/engine/assistant/evaluation.js +76 -0
- package/dist/engine/assistant/host.d.ts +2 -0
- package/dist/engine/assistant/host.js +63 -0
- package/dist/engine/assistant/integrations/google.d.ts +9 -0
- package/dist/engine/assistant/integrations/google.js +30 -0
- package/dist/engine/assistant/integrations/public-web.d.ts +3 -0
- package/dist/engine/assistant/integrations/public-web.js +11 -0
- package/dist/engine/assistant/managed/secrets.d.ts +1 -0
- package/dist/engine/assistant/managed/secrets.js +0 -0
- package/dist/engine/assistant/managed/setup-state.d.ts +11 -0
- package/dist/engine/assistant/managed/setup-state.js +84 -0
- package/dist/engine/assistant/managed/setup.d.ts +3 -0
- package/dist/engine/assistant/managed/setup.js +85 -0
- package/dist/engine/assistant/microsoft/connection.d.ts +7 -0
- package/dist/engine/assistant/microsoft/connection.js +21 -0
- package/dist/engine/assistant/microsoft/tools.d.ts +8 -0
- package/dist/engine/assistant/microsoft/tools.js +30 -0
- package/dist/engine/assistant/modules/calendar.d.ts +1 -0
- package/dist/engine/assistant/modules/calendar.js +49 -0
- package/dist/engine/assistant/modules/catalog.d.ts +3 -0
- package/dist/engine/assistant/modules/catalog.js +67 -0
- package/dist/engine/assistant/modules/daily.d.ts +1 -0
- package/dist/engine/assistant/modules/daily.js +48 -0
- package/dist/engine/assistant/modules/github.d.ts +1 -0
- package/dist/engine/assistant/modules/github.js +43 -0
- package/dist/engine/assistant/modules/google.d.ts +1 -0
- package/dist/engine/assistant/modules/google.js +53 -0
- package/dist/engine/assistant/modules/mcp.d.ts +1 -0
- package/dist/engine/assistant/modules/mcp.js +42 -0
- package/dist/engine/assistant/modules/microsoft.d.ts +1 -0
- package/dist/engine/assistant/modules/microsoft.js +53 -0
- package/dist/engine/assistant/modules/module.d.ts +5 -0
- package/dist/engine/assistant/modules/module.js +42 -0
- package/dist/engine/assistant/modules/tools.d.ts +2 -0
- package/dist/engine/assistant/modules/tools.js +42 -0
- package/dist/engine/assistant/modules/web.d.ts +1 -0
- package/dist/engine/assistant/modules/web.js +45 -0
- package/dist/engine/assistant/private-directory.d.ts +1 -0
- package/dist/engine/assistant/private-directory.js +7 -0
- package/dist/engine/assistant/proactive/service.d.ts +6 -0
- package/dist/engine/assistant/proactive/service.js +16 -0
- package/dist/engine/assistant/providers/openai-compatible.d.ts +4 -0
- package/dist/engine/assistant/providers/openai-compatible.js +12 -0
- package/dist/engine/assistant/providers/provider.d.ts +7 -0
- package/dist/engine/assistant/providers/provider.js +54 -0
- package/dist/engine/assistant/providers/web-citations.d.ts +1 -0
- package/dist/engine/assistant/providers/web-citations.js +7 -0
- package/dist/engine/assistant/runtime.d.ts +2 -0
- package/dist/engine/assistant/runtime.js +73 -0
- package/dist/engine/assistant/task-metrics.d.ts +8 -0
- package/dist/engine/assistant/task-metrics.js +17 -0
- package/dist/engine/assistant/telegram/api.d.ts +5 -0
- package/dist/engine/assistant/telegram/api.js +11 -0
- package/dist/engine/assistant/telegram/bridge.d.ts +2 -0
- package/dist/engine/assistant/telegram/bridge.js +40 -0
- package/dist/engine/assistant/telegram/store.d.ts +2 -0
- package/dist/engine/assistant/telegram/store.js +8 -0
- package/dist/engine/client.js +26 -18
- package/dist/engine/desktop-providers-v1.js +4 -4
- package/dist/engine/desktop-state-v1.js +16 -13
- package/dist/engine/index.js +111 -159
- package/dist/engine/mcp-stdio-v1.js +13 -12
- package/dist/engine/models.js +65 -23
- package/dist/engine/protocol.js +10 -6
- package/dist/engine/service.js +32 -21
- package/dist/hostile-repository-demo.js +1822 -696
- package/dist/index-09rsdr2d.js +1744 -0
- package/dist/index-0csc5sc7.js +139 -0
- package/dist/{index-v86bh0eg.js → index-0dkty795.js} +8 -6
- package/dist/index-0kkgqvg7.js +0 -0
- package/dist/index-0mzz9axm.js +58 -0
- package/dist/index-1e69ar8r.js +38 -0
- package/dist/index-1z0xhkh9.js +18 -0
- package/dist/index-2cef1k92.js +356 -0
- package/dist/{index-k1a1xesg.js → index-2j0v1xwr.js} +17 -13
- package/dist/index-2jw9jd7h.js +116 -0
- package/dist/index-2n9qx4km.js +0 -0
- package/dist/index-3rvk23e8.js +877 -0
- package/dist/index-3wa4j0yk.js +71 -0
- package/dist/index-41q1k17x.js +210 -0
- package/dist/index-4vz4bqqw.js +33 -0
- package/dist/index-5jxm2wy5.js +123 -0
- package/dist/index-5rk6ss42.js +216 -0
- package/dist/index-5v1skxf7.js +1852 -0
- package/dist/{index-qz4fs9f9.js → index-6ehtssyz.js} +355 -332
- package/dist/index-76kpdbpw.js +80 -0
- package/dist/{index-r0q0r88h.js → index-7nbmhmw5.js} +10 -10
- package/dist/index-8mx0yrkz.js +31 -0
- package/dist/index-8tjev5ds.js +11 -0
- package/dist/index-91n5wr6s.js +163 -0
- package/dist/index-91trs3ew.js +151 -0
- package/dist/index-9y8p5vy5.js +222 -0
- package/dist/index-abxahprd.js +55 -0
- package/dist/index-aptyr511.js +84 -0
- package/dist/{index-8sm2a1wa.js → index-ay26xfxt.js} +28 -20
- package/dist/index-b4yed1s3.js +657 -0
- package/dist/index-bb7phvtg.js +23 -0
- package/dist/index-bk5tn9b8.js +236 -0
- package/dist/index-bw34861c.js +292 -0
- package/dist/index-c6fnjhgv.js +55 -0
- package/dist/{index-qfsrrnz6.js → index-cjevq9s8.js} +2 -2
- package/dist/{index-c39197wq.js → index-ctcwrkrc.js} +4 -4
- package/dist/{index-yx52bt4a.js → index-cztmcesv.js} +2 -2
- package/dist/index-dpbmxnrf.js +564 -0
- package/dist/index-ekxdcy36.js +134 -0
- package/dist/index-f8zpcsx3.js +289 -0
- package/dist/{index-6dxrbnxm.js → index-f970qtb4.js} +7 -143
- package/dist/index-fatcn6fp.js +2791 -0
- package/dist/index-fbzykqxy.js +105 -0
- package/dist/{index-1265j7t2.js → index-fwf274vc.js} +24 -14
- package/dist/index-fy4w0a7v.js +0 -0
- package/dist/index-gvva3e5x.js +76 -0
- package/dist/index-h7dcah4p.js +137 -0
- package/dist/index-hm9r120s.js +42 -0
- package/dist/index-j3d2tw97.js +328 -0
- package/dist/index-jfqj20x8.js +41 -0
- package/dist/{index-yp0jtaxp.js → index-k529a278.js} +6 -6
- package/dist/{index-bt2p8x7r.js → index-kbrf5bx7.js} +110 -106
- package/dist/index-kwk23ktq.js +33 -0
- package/dist/index-kz857p1j.js +557 -0
- package/dist/{index-tc2r2n8b.js → index-mkt5yrax.js} +31 -105
- package/dist/{index-tgt8gtq7.js → index-ndgnvjez.js} +18 -18
- package/dist/index-nemn4epv.js +43 -0
- package/dist/index-nkwy5bjr.js +1225 -0
- package/dist/index-nvvzr4ny.js +136 -0
- package/dist/index-pkspzsfs.js +78 -0
- package/dist/{index-fm84men1.js → index-px1tnqgt.js} +2 -2
- package/dist/index-q7qdw883.js +79 -0
- package/dist/{index-mzydbzp8.js → index-qvbg6tx1.js} +65 -23
- package/dist/index-r3mwr5fb.js +0 -0
- package/dist/index-rdr78m0k.js +91 -0
- package/dist/index-rtamqsfs.js +59 -0
- package/dist/index-s125ss45.js +38 -0
- package/dist/{index-h8r80xhk.js → index-sx1t6dnd.js} +4005 -2781
- package/dist/index-tar0ngkm.js +359 -0
- package/dist/index-tn58cr6w.js +471 -0
- package/dist/{index-v17e1xs8.js → index-v79s9bf9.js} +96 -23
- package/dist/index-vk3rq21m.js +17 -0
- package/dist/index-vmvnr28y.js +72 -0
- package/dist/index-vz629cg8.js +49 -0
- package/dist/{index-eps3c3g6.js → index-w292hdpz.js} +197 -960
- package/dist/{index-t6sjhxh8.js → index-w9eqg6p9.js} +24 -302
- package/dist/index-wj96kdw2.js +57 -0
- package/dist/index-wyck5yhd.js +141 -0
- package/dist/index-xvtk8pxs.js +674 -0
- package/dist/{index-bpc596v3.js → index-xwb691v9.js} +2 -2
- package/dist/index-ym69x168.js +518 -0
- package/dist/index-yprdjk9v.js +65 -0
- package/dist/index-z2a81ccr.js +35 -0
- package/dist/{index-3ah1f369.js → index-z69cqk74.js} +3 -3
- package/dist/index-zaakvmzq.js +62 -0
- package/dist/index-zk3m4mzg.js +232 -0
- package/dist/index-zx3wgvx4.js +218 -0
- package/dist/index.js +102 -83
- package/dist/persistence/migration-guard.d.ts +3 -0
- package/dist/runtime/harness.d.ts +2 -0
- package/dist/service-cli.js +130 -40
- package/dist/service-client-cli-2rzxy5mj.js +1166 -0
- package/dist/service-client-cli-5ne8q5ej.js +543 -0
- package/dist/tools/ooxml-zip.d.ts +21 -0
- package/dist/tools/presentations.d.ts +47 -0
- package/dist/tools/tabular-data.d.ts +114 -0
- package/dist/tools/workspace.d.ts +76 -0
- package/dist/verify-historical-migrations.js +1923 -797
- package/dist/workspace/workspace.d.ts +13 -1
- package/dist/zhx.js +8 -6
- package/docs/APPLICATION_MIGRATION.md +32 -0
- package/docs/CLI.md +166 -2
- package/docs/CODE_RELEASE.md +5 -3
- package/docs/CODE_WEB_TASKS.md +3 -114
- package/docs/CONTEXT_ENGINEERING.md +27 -0
- package/docs/ENGINE_API.md +1 -1
- package/docs/EXTENSIBILITY.md +1 -1
- package/docs/FIRST_USE.md +6 -6
- package/docs/INTERNAL_ARCHIVE.md +43 -0
- package/docs/LOCAL_SERVICE.md +1 -1
- package/docs/MODEL_CATALOG.md +14 -0
- package/docs/README.md +13 -2
- package/evaluations/representative-assembly-matrix.json +10 -1
- package/examples/README.md +3 -3
- package/examples/assistant/compatible-calendar.json +17 -0
- package/examples/assistant/composed-modules.json +23 -0
- package/examples/assistant/connected-tools.json +9 -0
- package/examples/assistant/daily-tools.json +6 -0
- package/examples/assistant/offline.mjs +24 -0
- package/fixtures/cli-compatibility/README.md +10 -0
- package/fixtures/cli-compatibility/inventory.json +7858 -0
- package/package.json +230 -28
- package/dist/cli/console/console-model-catalog.d.ts +0 -8
- package/dist/index-4gt045j0.js +0 -288
- package/dist/index-4jw3tvy8.js +0 -301
- package/dist/index-ebb5d4s3.js +0 -640
- package/dist/index-x9hv1a34.js +0 -274
- package/dist/service-client-cli-gtk26axb.js +0 -1251
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
syncPrivateDirectory
|
|
3
|
+
} from "./index-vk3rq21m.js";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/application/assistant/calendar/store.ts
|
|
6
|
+
import { DatabaseSync } from "node:sqlite";
|
|
7
|
+
import { constants } from "node:fs";
|
|
8
|
+
import { open, lstat, mkdir, unlink } from "node:fs/promises";
|
|
9
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
async function openCalendarStore(directory, encodedKey, recover = false) {
|
|
12
|
+
const key = Buffer.from(encodedKey, "base64");
|
|
13
|
+
if (key.length !== 32 || key.toString("base64") !== encodedKey)
|
|
14
|
+
throw new Error("CALENDAR_KEY_INVALID");
|
|
15
|
+
await mkdir(directory, { recursive: true, mode: 448 });
|
|
16
|
+
const root = await lstat(directory);
|
|
17
|
+
if (!root.isDirectory() || root.isSymbolicLink() || root.mode & 63 || root.uid !== process.getuid?.())
|
|
18
|
+
throw new Error("CALENDAR_STATE_UNSAFE");
|
|
19
|
+
const lockPath = path.join(directory, "calendar.lock");
|
|
20
|
+
if (recover) {
|
|
21
|
+
const guardPath = path.join(directory, "calendar.recovery");
|
|
22
|
+
const guard = await open(guardPath, "wx", 384);
|
|
23
|
+
await guard.close();
|
|
24
|
+
try {
|
|
25
|
+
try {
|
|
26
|
+
const handle = await open(lockPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
27
|
+
let pid;
|
|
28
|
+
try {
|
|
29
|
+
const stat = await handle.stat();
|
|
30
|
+
if (!stat.isFile() || stat.size > 1024 || stat.mode & 63 || stat.uid !== process.getuid?.())
|
|
31
|
+
throw new Error("CALENDAR_LOCK_UNSAFE");
|
|
32
|
+
pid = JSON.parse(await handle.readFile("utf8")).pid;
|
|
33
|
+
} finally {
|
|
34
|
+
await handle.close();
|
|
35
|
+
}
|
|
36
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
37
|
+
throw new Error("CALENDAR_LOCK_INVALID");
|
|
38
|
+
try {
|
|
39
|
+
process.kill(pid, 0);
|
|
40
|
+
throw new Error("CALENDAR_OWNER_ALIVE");
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error.code !== "ESRCH")
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
await unlink(lockPath);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error.code !== "ENOENT")
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
} finally {
|
|
51
|
+
await unlink(guardPath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const lock = await open(lockPath, "wx", 384);
|
|
55
|
+
try {
|
|
56
|
+
await lock.writeFile(JSON.stringify({ pid: process.pid }));
|
|
57
|
+
await lock.sync();
|
|
58
|
+
} finally {
|
|
59
|
+
await lock.close();
|
|
60
|
+
}
|
|
61
|
+
let db;
|
|
62
|
+
try {
|
|
63
|
+
const file = path.join(directory, "calendar.sqlite");
|
|
64
|
+
try {
|
|
65
|
+
const created = await open(file, "wx", 384);
|
|
66
|
+
await created.close();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (error.code !== "EEXIST")
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
for (const suffix of ["", "-journal", "-wal", "-shm"]) {
|
|
72
|
+
try {
|
|
73
|
+
const stat = await lstat(file + suffix);
|
|
74
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.mode & 63 || stat.uid !== process.getuid?.())
|
|
75
|
+
throw new Error("CALENDAR_DB_UNSAFE");
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.code !== "ENOENT")
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
db = new DatabaseSync(file);
|
|
82
|
+
db.exec(`PRAGMA journal_mode=DELETE; PRAGMA synchronous=FULL; PRAGMA secure_delete=ON;
|
|
83
|
+
CREATE TABLE IF NOT EXISTS meta(key TEXT PRIMARY KEY,value TEXT NOT NULL);
|
|
84
|
+
CREATE TABLE IF NOT EXISTS create_operations(id TEXT PRIMARY KEY, proposal TEXT NOT NULL, input_digest TEXT NOT NULL, status TEXT NOT NULL, result TEXT);
|
|
85
|
+
CREATE TABLE IF NOT EXISTS operations(id TEXT PRIMARY KEY, proposal TEXT NOT NULL, status TEXT NOT NULL, result TEXT);
|
|
86
|
+
CREATE UNIQUE INDEX IF NOT EXISTS single_active_event ON operations(json_extract(proposal,'$.connectionId'),json_extract(proposal,'$.eventId')) WHERE status IN ('dispatching','uncertain');`);
|
|
87
|
+
const database = db;
|
|
88
|
+
const get = (sql, ...args) => database.prepare(sql).get(...args);
|
|
89
|
+
const run = (sql, ...args) => database.prepare(sql).run(...args);
|
|
90
|
+
const meta = (name) => get("SELECT value FROM meta WHERE key=?", name)?.value;
|
|
91
|
+
const set = (name, value) => run("INSERT INTO meta VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value", name, value);
|
|
92
|
+
if (meta("schema") && meta("schema") !== "1")
|
|
93
|
+
throw new Error("CALENDAR_SCHEMA_UNSUPPORTED");
|
|
94
|
+
set("schema", "1");
|
|
95
|
+
run("UPDATE operations SET status='uncertain' WHERE status='dispatching'");
|
|
96
|
+
run("UPDATE create_operations SET status='uncertain' WHERE status='dispatching'");
|
|
97
|
+
const encrypt = (name, value) => {
|
|
98
|
+
const iv = randomBytes(12), cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
99
|
+
cipher.setAAD(Buffer.from(`assistant-calendar-v1:${name}`));
|
|
100
|
+
const data = Buffer.concat([cipher.update(JSON.stringify(value), "utf8"), cipher.final()]);
|
|
101
|
+
set(name, JSON.stringify({ iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), data: data.toString("base64") }));
|
|
102
|
+
};
|
|
103
|
+
const decrypt = (name) => {
|
|
104
|
+
const stored = meta(name);
|
|
105
|
+
if (!stored)
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
const value = JSON.parse(stored), decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(value.iv, "base64"));
|
|
109
|
+
decipher.setAAD(Buffer.from(`assistant-calendar-v1:${name}`));
|
|
110
|
+
decipher.setAuthTag(Buffer.from(value.tag, "base64"));
|
|
111
|
+
return JSON.parse(Buffer.concat([decipher.update(Buffer.from(value.data, "base64")), decipher.final()]).toString("utf8"));
|
|
112
|
+
} catch {
|
|
113
|
+
throw new Error("CALENDAR_CREDENTIAL_DECRYPT_FAILED");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (meta("keyCheck")) {
|
|
117
|
+
if (decrypt("keyCheck") !== "calendar")
|
|
118
|
+
throw new Error("CALENDAR_KEY_INVALID");
|
|
119
|
+
} else
|
|
120
|
+
encrypt("keyCheck", "calendar");
|
|
121
|
+
await syncPrivateDirectory(directory, "CALENDAR_STATE_UNSAFE", root);
|
|
122
|
+
let closed = false;
|
|
123
|
+
return { get, run, meta, set, encrypt, decrypt, async close() {
|
|
124
|
+
if (!closed) {
|
|
125
|
+
closed = true;
|
|
126
|
+
database.close();
|
|
127
|
+
key.fill(0);
|
|
128
|
+
await unlink(lockPath);
|
|
129
|
+
}
|
|
130
|
+
} };
|
|
131
|
+
} catch (error) {
|
|
132
|
+
db?.close();
|
|
133
|
+
key.fill(0);
|
|
134
|
+
await unlink(lockPath);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { openCalendarStore };
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withWorkspaceMutation
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-v79s9bf9.js";
|
|
4
4
|
import {
|
|
5
5
|
TERMINAL_SESSION_RUN_STATUSES
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-6ehtssyz.js";
|
|
7
7
|
import {
|
|
8
8
|
SqliteDatabase,
|
|
9
9
|
createEditProposal,
|
|
10
10
|
fileDigestSchema,
|
|
11
|
-
readRegularFileNoFollow,
|
|
12
|
-
statRegularFileNoFollow,
|
|
13
11
|
workspaceFilePathSchema
|
|
14
|
-
} from "./index-
|
|
12
|
+
} from "./index-f970qtb4.js";
|
|
13
|
+
import {
|
|
14
|
+
readRegularFileNoFollow,
|
|
15
|
+
statRegularFileNoFollow
|
|
16
|
+
} from "./index-h7dcah4p.js";
|
|
15
17
|
|
|
16
|
-
// src/persistence/workspace-checkpoints.ts
|
|
18
|
+
// packages/core/src/persistence/workspace-checkpoints.ts
|
|
17
19
|
import { createHash, randomUUID } from "node:crypto";
|
|
18
20
|
import path from "node:path";
|
|
19
21
|
import { z } from "zod";
|
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readHarnessLocalCredentials,
|
|
3
|
+
requestHarnessLocalService,
|
|
4
|
+
requestLocalServiceDocument
|
|
5
|
+
} from "./index-3wa4j0yk.js";
|
|
6
|
+
import {
|
|
7
|
+
harnessClientRequestSchema
|
|
8
|
+
} from "./index-76kpdbpw.js";
|
|
9
|
+
|
|
10
|
+
// packages/core/src/application/client.ts
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
async function connectApplication(credentialsPath) {
|
|
13
|
+
const credentials = await readHarnessLocalCredentials(credentialsPath);
|
|
14
|
+
const hello = await requestHarnessLocalService(credentials, "hello", { versions: [1] });
|
|
15
|
+
if (!hello.ok)
|
|
16
|
+
throw new Error(hello.error.code);
|
|
17
|
+
const clientId = randomUUID();
|
|
18
|
+
return {
|
|
19
|
+
projectId: hello.projectId,
|
|
20
|
+
capabilities: hello.capabilities,
|
|
21
|
+
review(sessionId, runId) {
|
|
22
|
+
return requestLocalServiceDocument(credentials, "review", { clientId, request: {
|
|
23
|
+
protocolVersion: 1,
|
|
24
|
+
requestId: `review_${randomUUID()}`,
|
|
25
|
+
connectionId: hello.connectionId,
|
|
26
|
+
command: { method: "run.get", projectId: hello.projectId, sessionId, runId, includeReview: true }
|
|
27
|
+
} });
|
|
28
|
+
},
|
|
29
|
+
decide(ticketId, approve) {
|
|
30
|
+
return requestLocalServiceDocument(credentials, "decision", {
|
|
31
|
+
protocolVersion: 1,
|
|
32
|
+
requestId: `decision_${randomUUID()}`,
|
|
33
|
+
connectionId: hello.connectionId,
|
|
34
|
+
projectId: hello.projectId,
|
|
35
|
+
clientId,
|
|
36
|
+
ticketId,
|
|
37
|
+
approve
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
async command(command) {
|
|
41
|
+
if (!command || typeof command !== "object" || Array.isArray(command) || "projectId" in command) {
|
|
42
|
+
throw new Error("APPLICATION_SCOPE_OVERRIDE");
|
|
43
|
+
}
|
|
44
|
+
const envelope = harnessClientRequestSchema.parse({
|
|
45
|
+
protocolVersion: 1,
|
|
46
|
+
requestId: `application_${randomUUID()}`,
|
|
47
|
+
connectionId: hello.connectionId,
|
|
48
|
+
command: { ...command, projectId: hello.projectId }
|
|
49
|
+
});
|
|
50
|
+
return requestHarnessLocalService(credentials, "command", envelope);
|
|
51
|
+
},
|
|
52
|
+
events(sessionId, after = 0) {
|
|
53
|
+
return requestHarnessLocalService(credentials, "events", { projectId: hello.projectId, sessionId, after });
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { connectApplication };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openCalendarConnection
|
|
3
|
+
} from "./index-8mx0yrkz.js";
|
|
4
|
+
import {
|
|
5
|
+
calendarApprovalDetails,
|
|
6
|
+
calendarEngineOptions
|
|
7
|
+
} from "./index-fbzykqxy.js";
|
|
8
|
+
import {
|
|
9
|
+
createCalendarService
|
|
10
|
+
} from "./index-2cef1k92.js";
|
|
11
|
+
|
|
12
|
+
// packages/core/src/application/assistant/modules/calendar.ts
|
|
13
|
+
function createCalendarModule(options) {
|
|
14
|
+
return { id: "calendar", version: options.allowCreate ? "2" : "1", async open(context) {
|
|
15
|
+
const connection = await openCalendarConnection(context.directory, context.ownerId, options, context.recover);
|
|
16
|
+
try {
|
|
17
|
+
const calendar = createCalendarService(connection.store, connection.oauth, options);
|
|
18
|
+
const engine = calendarEngineOptions(calendar, options.allowCreate);
|
|
19
|
+
return {
|
|
20
|
+
binding: calendar.binding + (options.allowCreate ? ":create-v1" : ""),
|
|
21
|
+
preserveProfile: true,
|
|
22
|
+
profile: engine.agentProfile,
|
|
23
|
+
mcpConfiguration: engine.mcpConfiguration,
|
|
24
|
+
mcpClients: engine.mcpClients,
|
|
25
|
+
reviewTools: ["calendar_write_apply", ...options.allowCreate ? ["calendar_write_create"] : []],
|
|
26
|
+
approvalDetails: calendarApprovalDetails(calendar),
|
|
27
|
+
...options.allowCreate ? { prepareCalendarCreation: (input) => calendar.creation.reference(calendar.creation.propose(input)) } : {},
|
|
28
|
+
agendaSource: { canCreate: options.allowCreate === true, binding: calendar.binding, calendarId: options.calendarId ?? "primary", list: calendar.list },
|
|
29
|
+
close: connection.close
|
|
30
|
+
};
|
|
31
|
+
} catch (error) {
|
|
32
|
+
await connection.close();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
} };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { createCalendarModule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/core/src/client/continuation.ts
|
|
2
|
+
function terminalContinuationMessages(messages) {
|
|
3
|
+
const recorded = new Set(messages.flatMap((message) => message.parts.flatMap((part) => part.type === "tool-result" ? [part.toolResult.toolCallId] : [])));
|
|
4
|
+
return messages.flatMap((message) => {
|
|
5
|
+
if (message.role !== "assistant")
|
|
6
|
+
return [message];
|
|
7
|
+
const missing = message.parts.filter((part) => part.type === "tool-call" && !recorded.has(part.toolCall.id));
|
|
8
|
+
if (!missing.length)
|
|
9
|
+
return [message];
|
|
10
|
+
return [message, { role: "tool", parts: missing.map((part) => {
|
|
11
|
+
if (part.type !== "tool-call")
|
|
12
|
+
throw new Error("INVALID_CONTINUATION");
|
|
13
|
+
return { type: "tool-result", toolResult: { toolCallId: part.toolCall.id, toolName: part.toolCall.name, isError: true, output: { status: "outcome_unknown", reason: "Previous run ended without a recorded tool result. Inspect current state before any new proposal; do not assume execution or success." } } };
|
|
14
|
+
}) }];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { terminalContinuationMessages };
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CalendarHttpError,
|
|
3
|
+
googleJson
|
|
4
|
+
} from "./index-hm9r120s.js";
|
|
5
|
+
|
|
6
|
+
// packages/core/src/application/assistant/calendar/create-event.ts
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var instant = z.string().datetime({ offset: true });
|
|
10
|
+
var eventFields = {
|
|
11
|
+
summary: z.string().trim().min(1).max(1000),
|
|
12
|
+
start: instant,
|
|
13
|
+
end: instant,
|
|
14
|
+
attendees: z.array(z.string().email().max(320).transform((value) => value.toLowerCase())).max(100).transform((values) => [...new Set(values)].sort())
|
|
15
|
+
};
|
|
16
|
+
var createEventInputSchema = z.strictObject({ requestId: z.string().uuid(), ...eventFields }).refine((value) => Date.parse(value.end) > Date.parse(value.start), "End must follow start");
|
|
17
|
+
var createEventProposalSchema = z.strictObject({
|
|
18
|
+
schemaVersion: z.literal(1),
|
|
19
|
+
kind: z.literal("create"),
|
|
20
|
+
operationId: z.string().uuid(),
|
|
21
|
+
eventId: z.string().regex(/^[0-9a-f]{32}$/),
|
|
22
|
+
connectionId: z.string(),
|
|
23
|
+
accountId: z.string(),
|
|
24
|
+
calendarId: z.string(),
|
|
25
|
+
...eventFields,
|
|
26
|
+
sendUpdates: z.literal("all"),
|
|
27
|
+
createdAt: z.number(),
|
|
28
|
+
expiresAt: z.number()
|
|
29
|
+
}).refine((value) => Date.parse(value.end) > Date.parse(value.start), "End must follow start");
|
|
30
|
+
var digest = (value) => "sha256:" + createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
31
|
+
var referenceSchema = z.strictObject({ operationId: z.string().uuid(), proposalDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/) });
|
|
32
|
+
var createdEventSchema = z.object({
|
|
33
|
+
id: z.string(),
|
|
34
|
+
etag: z.string(),
|
|
35
|
+
summary: z.string(),
|
|
36
|
+
status: z.string().optional(),
|
|
37
|
+
start: z.object({ dateTime: instant }),
|
|
38
|
+
end: z.object({ dateTime: instant }),
|
|
39
|
+
attendeesOmitted: z.boolean().optional(),
|
|
40
|
+
attendees: z.array(z.object({ email: z.string() })).max(200).default([]),
|
|
41
|
+
extendedProperties: z.object({ private: z.record(z.string(), z.string()).optional() }).optional()
|
|
42
|
+
});
|
|
43
|
+
function createCalendarCreation(store, binding, request, now = Date.now) {
|
|
44
|
+
const load = (id) => {
|
|
45
|
+
const row = store.get("SELECT proposal,input_digest,status,result FROM create_operations WHERE id=?", z.string().uuid().parse(id));
|
|
46
|
+
if (!row)
|
|
47
|
+
throw new Error("CALENDAR_CREATE_OPERATION_UNKNOWN");
|
|
48
|
+
const proposal = createEventProposalSchema.parse(JSON.parse(row.proposal));
|
|
49
|
+
if (proposal.connectionId !== binding.connectionId || proposal.accountId !== binding.accountId || proposal.calendarId !== binding.calendarId)
|
|
50
|
+
throw new Error("CALENDAR_CONNECTION_CHANGED");
|
|
51
|
+
return { row, proposal };
|
|
52
|
+
};
|
|
53
|
+
const reference = (proposal) => ({ operationId: proposal.operationId, proposalDigest: digest(createEventProposalSchema.parse(proposal)) });
|
|
54
|
+
const reviewReference = (raw) => {
|
|
55
|
+
const value = referenceSchema.parse(raw), { row, proposal } = load(value.operationId);
|
|
56
|
+
if (reference(proposal).proposalDigest !== value.proposalDigest)
|
|
57
|
+
throw new Error("CALENDAR_PROPOSAL_MISMATCH");
|
|
58
|
+
return { proposal, status: row.status };
|
|
59
|
+
};
|
|
60
|
+
const matches = (raw, proposal) => {
|
|
61
|
+
const result = createdEventSchema.safeParse(raw);
|
|
62
|
+
if (!result.success)
|
|
63
|
+
return false;
|
|
64
|
+
const event = result.data;
|
|
65
|
+
return event.id === proposal.eventId && event.status !== "cancelled" && !event.attendeesOmitted && event.extendedProperties?.private?.zhivexOperation === proposal.operationId && event.summary === proposal.summary && Date.parse(event.start.dateTime) === Date.parse(proposal.start) && Date.parse(event.end.dateTime) === Date.parse(proposal.end) && JSON.stringify([...new Set(event.attendees.map((item) => item.email.toLowerCase()))].sort()) === JSON.stringify(proposal.attendees);
|
|
66
|
+
};
|
|
67
|
+
const record = (id, status, extra = {}) => {
|
|
68
|
+
const result = { operationId: id, status, ...extra };
|
|
69
|
+
const changed = store.run("UPDATE create_operations SET status=?,result=? WHERE id=? AND status NOT IN ('confirmed','conflict','failed')", status, JSON.stringify(result), id);
|
|
70
|
+
return Number(changed.changes) === 1 ? result : JSON.parse(load(id).row.result);
|
|
71
|
+
};
|
|
72
|
+
const reconcile = async (id, signal) => {
|
|
73
|
+
const { row, proposal } = load(id);
|
|
74
|
+
if (["confirmed", "conflict", "failed"].includes(row.status))
|
|
75
|
+
return JSON.parse(row.result);
|
|
76
|
+
if (!["dispatching", "uncertain"].includes(row.status))
|
|
77
|
+
return { operationId: id, status: row.status };
|
|
78
|
+
try {
|
|
79
|
+
const event = await request("/" + proposal.eventId, {}, signal);
|
|
80
|
+
if (matches(event, proposal))
|
|
81
|
+
return record(id, "confirmed", { eventId: proposal.eventId, recovered: true, notifications: "requested_all_not_delivery_verified" });
|
|
82
|
+
} catch {}
|
|
83
|
+
return record(id, "uncertain", { eventId: proposal.eventId, action: "Inspect this event and operation. No automatic resend." });
|
|
84
|
+
};
|
|
85
|
+
const propose = (raw) => {
|
|
86
|
+
const input = createEventInputSchema.parse(raw), inputDigest = digest(input);
|
|
87
|
+
const existing = store.get("SELECT proposal,input_digest,status,result FROM create_operations WHERE id=?", input.requestId);
|
|
88
|
+
if (existing) {
|
|
89
|
+
const loaded = load(input.requestId);
|
|
90
|
+
if (existing.input_digest !== inputDigest)
|
|
91
|
+
throw new Error("CALENDAR_CREATE_REQUEST_REUSED");
|
|
92
|
+
return loaded.proposal;
|
|
93
|
+
}
|
|
94
|
+
const proposal = createEventProposalSchema.parse({
|
|
95
|
+
schemaVersion: 1,
|
|
96
|
+
kind: "create",
|
|
97
|
+
operationId: input.requestId,
|
|
98
|
+
eventId: input.requestId.replaceAll("-", ""),
|
|
99
|
+
...binding,
|
|
100
|
+
summary: input.summary,
|
|
101
|
+
start: input.start,
|
|
102
|
+
end: input.end,
|
|
103
|
+
attendees: input.attendees,
|
|
104
|
+
sendUpdates: "all",
|
|
105
|
+
createdAt: now(),
|
|
106
|
+
expiresAt: now() + 15 * 60000
|
|
107
|
+
});
|
|
108
|
+
store.run("INSERT INTO create_operations(id,proposal,input_digest,status) VALUES(?,?,?,'proposed')", proposal.operationId, JSON.stringify(proposal), inputDigest);
|
|
109
|
+
return proposal;
|
|
110
|
+
};
|
|
111
|
+
const apply = async (raw, signal) => {
|
|
112
|
+
const { proposal } = reviewReference(raw), { row } = load(proposal.operationId);
|
|
113
|
+
if (["confirmed", "conflict", "failed"].includes(row.status))
|
|
114
|
+
return JSON.parse(row.result);
|
|
115
|
+
if (["dispatching", "uncertain"].includes(row.status))
|
|
116
|
+
return reconcile(proposal.operationId, signal);
|
|
117
|
+
if (row.status !== "proposed")
|
|
118
|
+
throw new Error("CALENDAR_PROPOSAL_NOT_EXECUTABLE");
|
|
119
|
+
if (proposal.expiresAt <= now())
|
|
120
|
+
return record(proposal.operationId, "conflict", { reason: "proposal_expired" });
|
|
121
|
+
signal?.throwIfAborted();
|
|
122
|
+
const claimed = store.run("UPDATE create_operations SET status='dispatching' WHERE id=? AND status='proposed'", proposal.operationId);
|
|
123
|
+
if (Number(claimed.changes) !== 1)
|
|
124
|
+
return reconcile(proposal.operationId, signal);
|
|
125
|
+
try {
|
|
126
|
+
const event = await request("?sendUpdates=all", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({
|
|
127
|
+
id: proposal.eventId,
|
|
128
|
+
summary: proposal.summary,
|
|
129
|
+
start: { dateTime: proposal.start },
|
|
130
|
+
end: { dateTime: proposal.end },
|
|
131
|
+
attendees: proposal.attendees.map((email) => ({ email })),
|
|
132
|
+
extendedProperties: { private: { zhivexOperation: proposal.operationId } }
|
|
133
|
+
}) }, signal);
|
|
134
|
+
if (matches(event, proposal))
|
|
135
|
+
return record(proposal.operationId, "confirmed", { eventId: proposal.eventId, notifications: "requested_all_not_delivery_verified" });
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error instanceof CalendarHttpError && [400, 401, 403, 404, 429].includes(error.status))
|
|
138
|
+
return record(proposal.operationId, "failed", { reason: error.message });
|
|
139
|
+
}
|
|
140
|
+
record(proposal.operationId, "uncertain");
|
|
141
|
+
return reconcile(proposal.operationId, signal);
|
|
142
|
+
};
|
|
143
|
+
return { propose, reference, reviewReference, apply, reconcile };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// packages/core/src/application/assistant/calendar/calendar.ts
|
|
147
|
+
import { randomUUID, createHash as createHash2 } from "node:crypto";
|
|
148
|
+
import { z as z2 } from "zod";
|
|
149
|
+
var instant2 = z2.string().datetime({ offset: true });
|
|
150
|
+
var eventId = z2.string().regex(/^[A-Za-z0-9_-]{1,1024}$/);
|
|
151
|
+
var time = z2.object({ dateTime: instant2.optional(), date: z2.string().optional(), timeZone: z2.string().max(100).optional() });
|
|
152
|
+
var eventSchema = z2.object({
|
|
153
|
+
id: eventId,
|
|
154
|
+
etag: z2.string().min(1).max(256).regex(/^[^\r\n]+$/),
|
|
155
|
+
status: z2.string().optional(),
|
|
156
|
+
summary: z2.string().max(1000).default(""),
|
|
157
|
+
start: time,
|
|
158
|
+
end: time,
|
|
159
|
+
organizer: z2.object({ self: z2.boolean().optional(), email: z2.string().optional() }).optional(),
|
|
160
|
+
attendees: z2.array(z2.object({ email: z2.string().max(320), responseStatus: z2.string().optional(), self: z2.boolean().optional() })).max(200).default([]),
|
|
161
|
+
transparency: z2.string().optional(),
|
|
162
|
+
attendeesOmitted: z2.boolean().optional(),
|
|
163
|
+
recurringEventId: z2.string().optional(),
|
|
164
|
+
recurrence: z2.array(z2.string()).optional(),
|
|
165
|
+
eventType: z2.string().optional(),
|
|
166
|
+
extendedProperties: z2.object({ private: z2.record(z2.string(), z2.string()).optional() }).optional()
|
|
167
|
+
});
|
|
168
|
+
var changeSchema = z2.strictObject({ summary: z2.string().max(1000), start: instant2, end: instant2 }).refine((value) => Date.parse(value.start) < Date.parse(value.end), "End must follow start");
|
|
169
|
+
var proposalSchema = z2.strictObject({
|
|
170
|
+
schemaVersion: z2.literal(1),
|
|
171
|
+
operationId: z2.string().uuid(),
|
|
172
|
+
connectionId: z2.string(),
|
|
173
|
+
accountId: z2.string(),
|
|
174
|
+
calendarId: z2.string(),
|
|
175
|
+
eventId,
|
|
176
|
+
etag: z2.string(),
|
|
177
|
+
before: z2.strictObject({ summary: z2.string(), start: instant2, end: instant2, timeZone: z2.string().nullable() }),
|
|
178
|
+
after: changeSchema,
|
|
179
|
+
notifiedAttendees: z2.array(z2.string()),
|
|
180
|
+
sendUpdates: z2.literal("all"),
|
|
181
|
+
metadataChange: z2.literal("Record private zhivexOperation marker"),
|
|
182
|
+
createdAt: z2.number(),
|
|
183
|
+
expiresAt: z2.number()
|
|
184
|
+
});
|
|
185
|
+
var canonical = (value) => Array.isArray(value) ? `[${value.map(canonical).join(",")}]` : value && typeof value === "object" ? `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => JSON.stringify(k) + ":" + canonical(v)).join(",")}}` : JSON.stringify(value);
|
|
186
|
+
var modified = (event, proposal) => event.id === proposal.eventId && event.extendedProperties?.private?.zhivexOperation === proposal.operationId && event.summary === proposal.after.summary && Date.parse(event.start.dateTime ?? "") === Date.parse(proposal.after.start) && Date.parse(event.end.dateTime ?? "") === Date.parse(proposal.after.end);
|
|
187
|
+
function createCalendarService(store, oauth, options = {}) {
|
|
188
|
+
const calendarId = options.calendarId ?? "primary", fetcher = options.fetcher ?? fetch, now = options.now ?? Date.now;
|
|
189
|
+
if (!calendarId || calendarId.length > 320)
|
|
190
|
+
throw new Error("CALENDAR_ID_INVALID");
|
|
191
|
+
const credentials = oauth.credentials();
|
|
192
|
+
const binding = JSON.stringify({ connectionId: credentials.connectionId, calendarId });
|
|
193
|
+
const request = async (suffix, init = {}, signal) => {
|
|
194
|
+
const current = await oauth.freshCredentials();
|
|
195
|
+
if (current.connectionId !== credentials.connectionId)
|
|
196
|
+
throw new Error("CALENDAR_CONNECTION_CHANGED");
|
|
197
|
+
try {
|
|
198
|
+
return await googleJson(fetcher, `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events${suffix}`, { ...init, headers: { ...init.headers, authorization: `Bearer ${current.accessToken}` } }, signal);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof CalendarHttpError && error.status === 401)
|
|
201
|
+
store.set("reauthorize", "yes");
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const read = async (id, signal) => {
|
|
206
|
+
const expected = eventId.parse(id), event = eventSchema.parse(await request(`/${encodeURIComponent(expected)}`, {}, signal));
|
|
207
|
+
if (event.id !== expected)
|
|
208
|
+
throw new Error("CALENDAR_EVENT_ID_MISMATCH");
|
|
209
|
+
return event;
|
|
210
|
+
};
|
|
211
|
+
const load = (id) => {
|
|
212
|
+
const row = store.get("SELECT proposal,status,result FROM operations WHERE id=?", id);
|
|
213
|
+
if (!row)
|
|
214
|
+
throw new Error("CALENDAR_OPERATION_UNKNOWN");
|
|
215
|
+
const proposal = proposalSchema.parse(JSON.parse(row.proposal));
|
|
216
|
+
if (proposal.connectionId !== credentials.connectionId || proposal.accountId !== credentials.accountId || proposal.calendarId !== calendarId)
|
|
217
|
+
throw new Error("CALENDAR_CONNECTION_CHANGED");
|
|
218
|
+
return { row, proposal };
|
|
219
|
+
};
|
|
220
|
+
const record = (id, status, extra = {}) => {
|
|
221
|
+
const result = { operationId: id, status, ...extra };
|
|
222
|
+
const updated = store.run("UPDATE operations SET status=?, result=? WHERE id=? AND status NOT IN ('confirmed','conflict','failed')", status, JSON.stringify(result), id);
|
|
223
|
+
if (Number(updated.changes) !== 1)
|
|
224
|
+
return JSON.parse(load(id).row.result);
|
|
225
|
+
return result;
|
|
226
|
+
};
|
|
227
|
+
const reconcile = async (operationId, signal) => {
|
|
228
|
+
const { row, proposal } = load(z2.string().uuid().parse(operationId));
|
|
229
|
+
if (["confirmed", "conflict", "failed"].includes(row.status))
|
|
230
|
+
return JSON.parse(row.result);
|
|
231
|
+
if (!["dispatching", "uncertain"].includes(row.status))
|
|
232
|
+
return { operationId, status: row.status };
|
|
233
|
+
try {
|
|
234
|
+
const current = await read(proposal.eventId, signal);
|
|
235
|
+
if (modified(current, proposal))
|
|
236
|
+
return record(operationId, "confirmed", { etag: current.etag, recovered: true, notifications: "requested_all_not_delivery_verified" });
|
|
237
|
+
} catch {}
|
|
238
|
+
return record(operationId, "uncertain", { action: "No automatic resend. Inspect the event and operation locally." });
|
|
239
|
+
};
|
|
240
|
+
const reference = (proposal) => ({
|
|
241
|
+
operationId: proposal.operationId,
|
|
242
|
+
proposalDigest: "sha256:" + createHash2("sha256").update(canonical(proposal)).digest("hex")
|
|
243
|
+
});
|
|
244
|
+
const reviewReference = (input) => {
|
|
245
|
+
const parsed = z2.strictObject({ operationId: z2.string().uuid(), proposalDigest: z2.string().regex(/^sha256:[a-f0-9]{64}$/) }).parse(input);
|
|
246
|
+
const { row, proposal } = load(parsed.operationId);
|
|
247
|
+
if (reference(proposal).proposalDigest !== parsed.proposalDigest)
|
|
248
|
+
throw new Error("CALENDAR_PROPOSAL_MISMATCH");
|
|
249
|
+
return { proposal, status: row.status };
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
creation: createCalendarCreation(store, { connectionId: credentials.connectionId, accountId: credentials.accountId, calendarId }, request, now),
|
|
253
|
+
reference,
|
|
254
|
+
reviewReference,
|
|
255
|
+
binding,
|
|
256
|
+
connectionId: credentials.connectionId,
|
|
257
|
+
async list(input, signal) {
|
|
258
|
+
const parsed = z2.strictObject({ timeMin: instant2, timeMax: instant2, pageToken: z2.string().max(2048).optional() }).parse(input);
|
|
259
|
+
const span = Date.parse(parsed.timeMax) - Date.parse(parsed.timeMin);
|
|
260
|
+
if (span <= 0 || span > 90 * 86400000)
|
|
261
|
+
throw new Error("CALENDAR_RANGE_INVALID");
|
|
262
|
+
const query = new URLSearchParams({ timeMin: parsed.timeMin, timeMax: parsed.timeMax, maxResults: "100", singleEvents: "true", orderBy: "startTime", ...parsed.pageToken ? { pageToken: parsed.pageToken } : {} });
|
|
263
|
+
const page = await request(`?${query}`, {}, signal);
|
|
264
|
+
if (page.nextPageToken !== undefined && (typeof page.nextPageToken !== "string" || !page.nextPageToken || page.nextPageToken.length > 2048) || !Array.isArray(page.items) || page.items.length > 100)
|
|
265
|
+
throw new Error("CALENDAR_PAGE_INVALID");
|
|
266
|
+
return {
|
|
267
|
+
events: page.items.map((raw) => {
|
|
268
|
+
const event = eventSchema.parse(raw);
|
|
269
|
+
return { id: event.id, etag: event.etag, summary: event.summary, start: event.start, end: event.end, status: event.status, busy: event.transparency !== "transparent" && !event.attendees.some((a) => a.self && a.responseStatus === "declined") };
|
|
270
|
+
}),
|
|
271
|
+
nextPageToken: typeof page.nextPageToken === "string" ? page.nextPageToken : null,
|
|
272
|
+
complete: !page.nextPageToken
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
read,
|
|
276
|
+
reconcile,
|
|
277
|
+
async propose(id, change, signal) {
|
|
278
|
+
const after = changeSchema.parse(change), event = await read(id, signal);
|
|
279
|
+
if (event.status === "cancelled" || !event.organizer?.self || event.recurrence || event.recurringEventId || event.attendeesOmitted || !event.start.dateTime || !event.end.dateTime || event.eventType && event.eventType !== "default")
|
|
280
|
+
throw new Error("CALENDAR_EVENT_UNSUPPORTED");
|
|
281
|
+
if (store.get("SELECT id FROM operations WHERE json_extract(proposal,'$.eventId')=? AND json_extract(proposal,'$.connectionId')=? AND status IN ('dispatching','uncertain')", id, credentials.connectionId))
|
|
282
|
+
throw new Error("CALENDAR_EVENT_UNCERTAIN_RECONCILE_FIRST");
|
|
283
|
+
const proposal = {
|
|
284
|
+
schemaVersion: 1,
|
|
285
|
+
operationId: randomUUID(),
|
|
286
|
+
connectionId: credentials.connectionId,
|
|
287
|
+
accountId: credentials.accountId,
|
|
288
|
+
calendarId,
|
|
289
|
+
eventId: event.id,
|
|
290
|
+
etag: event.etag,
|
|
291
|
+
before: { summary: event.summary, start: event.start.dateTime, end: event.end.dateTime, timeZone: event.start.timeZone ?? null },
|
|
292
|
+
after,
|
|
293
|
+
notifiedAttendees: event.attendees.map((a) => a.email).sort(),
|
|
294
|
+
sendUpdates: "all",
|
|
295
|
+
metadataChange: "Record private zhivexOperation marker",
|
|
296
|
+
createdAt: now(),
|
|
297
|
+
expiresAt: now() + 15 * 60000
|
|
298
|
+
};
|
|
299
|
+
store.run("INSERT INTO operations(id,proposal,status) VALUES(?,?,'proposed')", proposal.operationId, canonical(proposal));
|
|
300
|
+
return proposal;
|
|
301
|
+
},
|
|
302
|
+
async apply(value, signal) {
|
|
303
|
+
const supplied = proposalSchema.parse(value);
|
|
304
|
+
const { row, proposal } = load(supplied.operationId);
|
|
305
|
+
if (canonical(supplied) !== canonical(proposal))
|
|
306
|
+
throw new Error("CALENDAR_PROPOSAL_MISMATCH");
|
|
307
|
+
if (row.status === "confirmed")
|
|
308
|
+
return JSON.parse(row.result);
|
|
309
|
+
if (["dispatching", "uncertain"].includes(row.status))
|
|
310
|
+
return reconcile(proposal.operationId, signal);
|
|
311
|
+
if (row.status !== "proposed")
|
|
312
|
+
throw new Error("CALENDAR_PROPOSAL_NOT_EXECUTABLE");
|
|
313
|
+
if (proposal.expiresAt <= now())
|
|
314
|
+
return record(proposal.operationId, "conflict", { reason: "proposal_expired" });
|
|
315
|
+
const current = await read(proposal.eventId, signal);
|
|
316
|
+
if (load(proposal.operationId).row.status !== "proposed")
|
|
317
|
+
return reconcile(proposal.operationId, signal);
|
|
318
|
+
if (current.etag !== proposal.etag)
|
|
319
|
+
return record(proposal.operationId, "conflict", { reason: "event_changed_new_approval_required" });
|
|
320
|
+
if (signal?.aborted)
|
|
321
|
+
throw new Error("CALENDAR_CANCELLED");
|
|
322
|
+
let claimed;
|
|
323
|
+
try {
|
|
324
|
+
claimed = store.run("UPDATE operations SET status='dispatching' WHERE id=? AND status='proposed'", proposal.operationId);
|
|
325
|
+
} catch {
|
|
326
|
+
throw new Error("CALENDAR_OPERATION_CLAIM_FAILED");
|
|
327
|
+
}
|
|
328
|
+
if (Number(claimed.changes) !== 1)
|
|
329
|
+
return reconcile(proposal.operationId, signal);
|
|
330
|
+
try {
|
|
331
|
+
const result = eventSchema.parse(await request(`/${encodeURIComponent(proposal.eventId)}?sendUpdates=all`, {
|
|
332
|
+
method: "PATCH",
|
|
333
|
+
headers: { "content-type": "application/json", "if-match": proposal.etag },
|
|
334
|
+
body: JSON.stringify({
|
|
335
|
+
summary: proposal.after.summary,
|
|
336
|
+
start: { dateTime: proposal.after.start, ...current.start.timeZone ? { timeZone: current.start.timeZone } : {} },
|
|
337
|
+
end: { dateTime: proposal.after.end, ...current.end.timeZone ? { timeZone: current.end.timeZone } : {} },
|
|
338
|
+
extendedProperties: { private: { ...current.extendedProperties?.private, zhivexOperation: proposal.operationId } }
|
|
339
|
+
})
|
|
340
|
+
}, signal));
|
|
341
|
+
if (!modified(result, proposal))
|
|
342
|
+
return record(proposal.operationId, "uncertain");
|
|
343
|
+
return record(proposal.operationId, "confirmed", { etag: result.etag, notifications: "requested_all_not_delivery_verified" });
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (error instanceof CalendarHttpError && error.status === 412)
|
|
346
|
+
return record(proposal.operationId, "conflict", { reason: "event_changed_new_approval_required" });
|
|
347
|
+
if (error instanceof CalendarHttpError && [400, 401, 403, 404, 429].includes(error.status))
|
|
348
|
+
return record(proposal.operationId, "failed", { reason: error.message });
|
|
349
|
+
record(proposal.operationId, "uncertain");
|
|
350
|
+
return reconcile(proposal.operationId, signal);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export { createEventInputSchema, createEventProposalSchema, changeSchema, proposalSchema, createCalendarService };
|