@desplega.ai/agent-swarm 2.8.1 → 2.8.3
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/dist/acp-adapter-xq6s2z6t.js +14 -0
- package/dist/{actions-pwjpn0j6.js → actions-ewz7bp4g.js} +20 -19
- package/dist/{amp-adapter-cq9jgj6x.js → amp-adapter-f25tqhnf.js} +3 -3
- package/dist/{app-cnfffgwg.js → app-mkptw0k7.js} +4 -4
- package/dist/{assistant-kpn317y1.js → assistant-c47rfe77.js} +23 -22
- package/dist/{boot-args-schema-pbbnhmc3.js → boot-args-schema-4vb0xsat.js} +1 -1
- package/dist/{boot-reembed-9m0ysxma.js → boot-reembed-1ghy2sab.js} +1 -1
- package/dist/{boot-reembed-majbn53m.js → boot-reembed-htr73hbs.js} +1 -1
- package/dist/{boot-scrub-sweep-app8g8ym.js → boot-scrub-sweep-yrytg42z.js} +4 -4
- package/dist/{boot-seeds-pbtmvcjm.js → boot-seeds-n2b3dx4e.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-jmfqgkqa.js} +2 -2
- package/dist/{claude-adapter-wn1g3qp5.js → claude-adapter-r33pqnzx.js} +8 -9
- package/dist/{claude-managed-adapter-jh6c523j.js → claude-managed-adapter-hddmxjyj.js} +4 -4
- package/dist/{claude-managed-setup-pd47nzch.js → claude-managed-setup-hfvry1bd.js} +5 -5
- package/dist/{claude-sdk-session-3a2a6589.js → claude-sdk-session-0hamqzc7.js} +10 -11
- package/dist/{cli-v1dv1r37.js → cli-0bcgyj5b.js} +74 -3
- package/dist/{cli-a3b239vq.js → cli-0vksaxvr.js} +2 -2
- package/dist/{cli-mrt48bx7.js → cli-15204js0.js} +1 -1
- package/dist/{cli-8aes17e4.js → cli-1m96dc36.js} +3 -3
- package/dist/{cli-2r0jcc3k.js → cli-2d0cghfn.js} +1 -1
- package/dist/{cli-wk18cm92.js → cli-4ax9mvvg.js} +4 -4
- package/dist/{cli-9wngrawf.js → cli-4dpkjc2e.js} +6 -6
- package/dist/{cli-x1wa213s.js → cli-4e1hfbpq.js} +5 -5
- package/dist/{cli-7349va39.js → cli-500c09j9.js} +921 -431
- package/dist/{cli-m4dqmnbp.js → cli-54qr8mcd.js} +2 -2
- package/dist/{cli-m88rpzkh.js → cli-5a7szzfh.js} +2 -2
- package/dist/{cli-bst1vp7e.js → cli-5y2fvw4z.js} +13 -5
- package/dist/{cli-vj75tyaw.js → cli-6yygkr0w.js} +7 -7
- package/dist/{cli-7b8sbmag.js → cli-7c5tgqhf.js} +5 -5
- package/dist/{cli-2gxeg5gr.js → cli-8476gtwf.js} +1 -1
- package/dist/{cli-yncmerje.js → cli-922z7gwm.js} +4 -4
- package/dist/{cli-jrzkw01m.js → cli-93t5s4zq.js} +2 -2
- package/dist/{cli-sn7rtnj4.js → cli-9zmb7ptc.js} +9 -9
- package/dist/{cli-tk7cjj8h.js → cli-am1ptset.js} +3 -3
- package/dist/{cli-cyhbbd1z.js → cli-awwptga4.js} +1 -1
- package/dist/{cli-89cqnasv.js → cli-bhsfbmk8.js} +19 -7
- package/dist/{cli-9vhebtjz.js → cli-bj6qhgte.js} +15 -32
- package/dist/{cli-g70vxtjh.js → cli-c0xjnr8z.js} +2 -2
- package/dist/{cli-vqptjbr7.js → cli-c3ng0mb4.js} +14 -14
- package/dist/{cli-re4raaj0.js → cli-c71n3bxq.js} +11 -6
- package/dist/{cli-7p1kvkck.js → cli-crpf163n.js} +25 -18
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-d3p5vwbk.js → cli-dpsfwh7n.js} +13 -21
- package/dist/{cli-xzm9vcfg.js → cli-dtdht77h.js} +2 -2
- package/dist/{cli-bb431xey.js → cli-e2w34h6z.js} +231 -68
- package/dist/{cli-eddnyg3t.js → cli-emekyyhr.js} +1 -1
- package/dist/{cli-d84byzn8.js → cli-f1kwb5fc.js} +109 -33
- package/dist/{cli-0jzra9ad.js → cli-gn9y6fn7.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-gpz1d0t2.js} +4 -4
- package/dist/{cli-7w69ne2f.js → cli-h9yy18gy.js} +239 -67
- package/dist/{cli-m5akxq8q.js → cli-j8cjdzan.js} +1 -1
- package/dist/{cli-m9s2qff2.js → cli-jg5txpm6.js} +187 -93
- package/dist/{cli-k26bkr9t.js → cli-k2rw11py.js} +3 -3
- package/dist/{cli-93k32c37.js → cli-k96cecs7.js} +377 -61
- package/dist/{cli-3vjhs18n.js → cli-kd56bmk4.js} +1 -1
- package/dist/{cli-k0615eh8.js → cli-kmemts3w.js} +13 -13
- package/dist/{cli-pcad4cb1.js → cli-knva3nmx.js} +2 -2
- package/dist/{cli-b085njxz.js → cli-kw44j53p.js} +15 -14
- package/dist/{cli-bsywb58a.js → cli-mdpbjnzq.js} +10 -10
- package/dist/{cli-syybb0p1.js → cli-me0r8gzr.js} +35 -76
- package/dist/{cli-4r05hnqa.js → cli-mwwmka77.js} +15 -15
- package/dist/{cli-1xh9a7hn.js → cli-n5t077me.js} +2 -2
- package/dist/{cli-rvhdmjvt.js → cli-nx2n3z6p.js} +1 -1
- package/dist/{cli-28fq781p.js → cli-pe4d96rb.js} +1 -1
- package/dist/{cli-3rkdne1h.js → cli-pxwtcgcp.js} +2 -2
- package/dist/{cli-zcsw143p.js → cli-qmqt520k.js} +2 -2
- package/dist/{cli-2zp0et3v.js → cli-qps8je6j.js} +70 -19
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-k93bq1wq.js → cli-rjvsf9qa.js} +5 -5
- package/dist/{cli-6mma83xa.js → cli-rqfvkx5t.js} +7 -7
- package/dist/{cli-dy32zecz.js → cli-s7zz734a.js} +1 -1
- package/dist/{cli-yn2bbre9.js → cli-s8p8hhty.js} +2 -2
- package/dist/{cli-vbh10fqa.js → cli-sdvcrq5x.js} +5 -5
- package/dist/{cli-b5rs97a6.js → cli-sg27rk2t.js} +5 -5
- package/dist/{cli-d6521kb5.js → cli-skmhsnqh.js} +1 -1
- package/dist/{cli-5mrq3ake.js → cli-t4dv07kr.js} +1 -1
- package/dist/{cli-hxpyc9sn.js → cli-t5ys4ebm.js} +3 -3
- package/dist/{cli-qmqk2yc2.js → cli-tas6ckky.js} +2 -2
- package/dist/{cli-p1w18yhx.js → cli-tf79ryyy.js} +1 -1
- package/dist/{cli-kc7v1nfv.js → cli-tnzebztn.js} +1 -1
- package/dist/{cli-gax7fk3t.js → cli-vx421edw.js} +3 -3
- package/dist/{cli-kchjb7qy.js → cli-x3ex5bqf.js} +1 -1
- package/dist/cli-yss07azk.js +142 -0
- package/dist/{cli-0ntbxyaa.js → cli-z8cvws4c.js} +363 -47
- package/dist/{cli-tacge1w0.js → cli-zdaypkq9.js} +146 -52
- package/dist/{cli-b8e9nb04.js → cli-zeaehgyd.js} +2 -2
- package/dist/{cli-jcpr5smb.js → cli-ztq5z4e1.js} +4 -4
- package/dist/cli.js +21 -21
- package/dist/{codex-adapter-nha71q3n.js → codex-adapter-2brxx5ta.js} +7 -8
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-c930c3ea.js} +2 -2
- package/dist/{codex-login-bcda78ge.js → codex-login-cbrs1h5w.js} +1 -1
- package/dist/{codex-session-runner-ak9x1k1h.js → codex-session-runner-y9anfj0r.js} +8 -9
- package/dist/{commands-f587qpq8.js → commands-wn9q06qr.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-fw608czd.js} +4 -4
- package/dist/{controllers-connect-k5sg9m9h.js → controllers-connect-63j5rdcm.js} +20 -20
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-6mb9jme8.js} +2 -2
- package/dist/{db-nzf8zb5z.js → db-0m6v5tq4.js} +3 -3
- package/dist/{db-amm8w15a.js → db-y4wfrzbm.js} +4 -2
- package/dist/{devin-adapter-xedz98zv.js → devin-adapter-r0yx3gv8.js} +1 -1
- package/dist/{dispatcher-89zrts8f.js → dispatcher-9tq2zzdj.js} +17 -17
- package/dist/{docker-866qpzt9.js → docker-j75atvpt.js} +2 -2
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-t09sv4tq.js} +2 -2
- package/dist/{e2b-s16txnpx.js → e2b-7s9dscap.js} +3 -3
- package/dist/{e2b-jkwfhbcv.js → e2b-a7vzs2vj.js} +3 -3
- package/dist/{easter-egg-3d-533knw22.js → easter-egg-3d-fbwvmwhe.js} +1 -1
- package/dist/{embedding-space-ezwenjmj.js → embedding-space-wh8de1t9.js} +6 -6
- package/dist/{embeddings-np74ht6g.js → embeddings-3hpbdtjr.js} +1 -1
- package/dist/{event-bus-e66gh7cc.js → event-bus-tr6h3gv8.js} +1 -1
- package/dist/{execute-b3mrb1mv.js → execute-4bdf8sdy.js} +1 -1
- package/dist/{external-channel-z46yx9d7.js → external-channel-ts2fwqh0.js} +2 -2
- package/dist/fx-adapter-1rnxnf56.js +17 -0
- package/dist/grok-adapter-efhmf1r8.js +17 -0
- package/dist/handlers-anrr3py9.js +32 -0
- package/dist/{heartbeat-dt9qw9c8.js → heartbeat-2ze5fzpc.js} +20 -20
- package/dist/{hook-8k6fbz9b.js → hook-ca54yd4s.js} +5 -5
- package/dist/{hook-jgcgygex.js → hook-gaehe2w5.js} +8 -8
- package/dist/{http-haw4r8ne.js → http-jfg8t2yk.js} +3839 -122
- package/dist/{index-tvfafeyy.js → index-3gv6sc4z.js} +1 -1
- package/dist/{index-tez78qj3.js → index-3yvzbhxd.js} +100 -23
- package/dist/index-8w2aznds.js +33 -0
- package/dist/{index-5gk12my8.js → index-csgrxedz.js} +1 -1
- package/dist/index-qnjvr362.js +37 -0
- package/dist/index-yzxd3sn9.js +32 -0
- package/dist/{keepalive-xn6s7rmg.js → keepalive-k2a3qe73.js} +4 -4
- package/dist/lead-zhxqbfdv.js +69 -0
- package/dist/{maintenance-vdts800b.js → maintenance-gb5sd5nc.js} +1 -1
- package/dist/{node-4c5jqxr3.js → node-7qsx5kvm.js} +1 -1
- package/dist/{oauth-refresh-sweep-094c8wfk.js → oauth-refresh-sweep-y7rm6bkb.js} +3 -3
- package/dist/{onboard-v99eh56m.js → onboard-jmc5qerv.js} +4 -4
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-7eade9ev.js} +6 -7
- package/dist/{otel-impl-q7yr9yp0.js → otel-impl-8j1xhxqd.js} +2 -2
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-yqmaf32x.js} +14 -13
- package/dist/{pricing-refresh-7dh2yase.js → pricing-refresh-1nj722h6.js} +2 -2
- package/dist/{rbac-roles-mdmc96p4.js → rbac-roles-b1mtr6dr.js} +3 -3
- package/dist/{rbac-roles-npbmdh77.js → rbac-roles-n1f3frk1.js} +2 -2
- package/dist/{render-v2-twhhwmms.js → render-v2-1gfpd8rj.js} +4 -4
- package/dist/{resume-5gsrjd5e.js → resume-w1s1eh5v.js} +7 -7
- package/dist/{runtime-1hv06jsn.js → runtime-84g5egsc.js} +1 -1
- package/dist/{session-access-m191x30x.js → session-access-y6z1txk4.js} +4 -4
- package/dist/{session-source-backfill-nt923ask.js → session-source-backfill-gxxwfh12.js} +3 -3
- package/dist/{setup-wv467afy.js → setup-r91gstyk.js} +1 -1
- package/dist/{virtual-modules-gazyapte.js → virtual-modules-cgnj6kme.js} +3 -3
- package/dist/{work-objects-8zkrpy13.js → work-objects-qcxzg61c.js} +20 -20
- package/dist/worker-7j2907g6.js +69 -0
- package/dist/{worker-follow-up-cecqszem.js → worker-follow-up-y2d2h7km.js} +19 -17
- package/dist/{x-2fyrt5pp.js → x-qhxq2ama.js} +2 -2
- package/openapi.json +2908 -351
- package/package.json +4 -4
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +53 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +40 -9
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- package/src/be/migrations/289_automation_savings_daily.sql +47 -0
- package/src/be/migrations/291_task_slack_participants.sql +4 -0
- package/src/be/migrations/293_savings_component_links.sql +58 -0
- package/src/be/migrations/296_automation_savings_daily_read_index.sql +6 -0
- package/src/be/model-profile-check.ts +53 -20
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +677 -0
- package/src/be/savings/model.ts +674 -0
- package/src/be/savings/read.ts +1500 -0
- package/src/be/savings/rollup.ts +571 -0
- package/src/be/scripts/run-credential.ts +15 -3
- package/src/be/scripts/typecheck.ts +91 -4
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- package/src/be/seed-scripts/catalog/dreaming-learnings.ts +10 -2
- package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +70 -4
- package/src/be/skill-parser.ts +19 -7
- package/src/be/swarm-config-guard.ts +8 -0
- package/src/be/users.ts +29 -2
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +258 -58
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +11 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +15 -1
- package/src/http/requested-by.ts +97 -1
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +849 -0
- package/src/http/scripts.ts +26 -15
- package/src/http/tasks.ts +89 -9
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- package/src/prompts/session-templates.ts +80 -3
- package/src/providers/acp-targets.ts +1 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-adapter.ts +0 -20
- package/src/providers/claude-flag-settings.ts +12 -10
- package/src/providers/codex-adapter.ts +12 -34
- package/src/providers/opencode-adapter.ts +34 -12
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- package/src/scheduler/scheduler.ts +20 -14
- package/src/scripts-runtime/ctx.ts +1 -1
- package/src/scripts-runtime/executors/quickjs-bundle.ts +1 -0
- package/src/scripts-runtime/executors/quickjs-prelude.ts +162 -2
- package/src/scripts-runtime/executors/quickjs-runner.ts +4 -1
- package/src/scripts-runtime/sdk-allowlist.ts +11 -1
- package/src/scripts-runtime/stdlib/fetch.ts +113 -15
- package/src/scripts-runtime/stdlib/index.ts +3 -1
- package/src/scripts-runtime/stdlib/retry.ts +174 -0
- package/src/scripts-runtime/swarm-sdk.ts +192 -17
- package/src/scripts-runtime/types/stdlib.d.ts +95 -4
- package/src/scripts-runtime/types/swarm-extension.d.ts +60 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +69 -2
- package/src/slack/actions.ts +1 -0
- package/src/slack/assistant.ts +2 -0
- package/src/slack/enrich.ts +144 -50
- package/src/slack/handlers.ts +37 -95
- package/src/slack/templates.ts +9 -0
- package/src/slack/thread-buffer.ts +45 -71
- package/src/slack/thread-participants.ts +187 -0
- package/src/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/base-prompt.test.ts +5 -4
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- package/src/tests/claude-adapter-binary.test.ts +7 -1
- package/src/tests/claude-adapter.test.ts +10 -64
- package/src/tests/claude-flag-settings.test.ts +15 -11
- package/src/tests/claude-hook-credentials.test.ts +0 -1
- package/src/tests/claude-sdk-lifecycle.test.ts +5 -1
- package/src/tests/codex-adapter.test.ts +28 -78
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/create-task-vcs-repo.test.ts +136 -0
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/deploy-guard.test.ts +154 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dreaming-learnings.test.ts +104 -0
- package/src/tests/extensions-pre-task.test.ts +4 -2
- package/src/tests/fetch-resolved-env.test.ts +47 -1
- package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/opencode-adapter.test.ts +53 -6
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/prompt-template-session.test.ts +17 -1
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/runner-requester-profile.test.ts +139 -1
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compound.test.ts +774 -0
- package/src/tests/savings-compute.test.ts +215 -0
- package/src/tests/savings-fleet-latency.test.ts +143 -0
- package/src/tests/savings-fleet-read.test.ts +195 -0
- package/src/tests/savings-fleet-scale.test.ts +222 -0
- package/src/tests/savings-model.test.ts +499 -0
- package/src/tests/savings-read.test.ts +367 -0
- package/src/tests/savings-rollup.test.ts +766 -0
- package/src/tests/savings-scripts.test.ts +611 -0
- package/src/tests/script-connections.test.ts +4 -0
- package/src/tests/script-executor-conformance.test.ts +444 -0
- package/src/tests/scripts-http.test.ts +55 -0
- package/src/tests/scripts-runtime-fetch.test.ts +2 -2
- package/src/tests/sdk-allowlist.test.ts +40 -0
- package/src/tests/secret-rules.test.ts +124 -1
- package/src/tests/secret-scrubber.test.ts +1 -1
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- package/src/tests/slack-dm-implicit-mention.test.ts +20 -1
- package/src/tests/slack-identity-resolution.test.ts +23 -0
- package/src/tests/slack-inbound-files.test.ts +2 -1
- package/src/tests/slack-thread-participants.test.ts +429 -0
- package/src/tests/tool-annotations.test.ts +30 -0
- package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +146 -33
- package/src/utils/constants.ts +2 -0
- package/src/utils/mcp-server-fetcher.test.ts +89 -0
- package/src/utils/mcp-server-fetcher.ts +13 -5
- package/src/utils/request-auth-context.ts +24 -0
- package/src/utils/secret-rules.generated.ts +1 -1
- package/src/utils/secret-scrubber.ts +154 -29
- package/src/workflows/executors/swarm-script.ts +23 -19
- package/templates/skills/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +5 -4
- package/templates/skills/swarm-scripts/content.md +5 -4
- package/templates/skills/work-on-task/SKILL.md +1 -1
- package/templates/skills/work-on-task/content.md +1 -1
- package/templates/workflows/dreaming/content.md +1 -1
- package/dist/acp-adapter-pdy3qsvg.js +0 -15
- package/dist/cli-4bd1rck6.js +0 -4
- package/dist/cli-jywyhqws.js +0 -104
- package/dist/fx-adapter-3q12snn6.js +0 -18
- package/dist/grok-adapter-ahb1w033.js +0 -18
- package/dist/handlers-vbww69re.js +0 -32
- package/dist/index-4xwaf5th.js +0 -32
- package/dist/index-f0hcrs8e.js +0 -33
- package/dist/index-s4ewdma4.js +0 -37
- package/dist/lead-6ygbfhbh.js +0 -70
- package/dist/worker-mz5z7kj0.js +0 -70
- package/src/providers/ctx-mode-env.ts +0 -10
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
allocateSchedule,
|
|
4
|
+
CURVE,
|
|
5
|
+
curve,
|
|
6
|
+
DEFAULT_OPS,
|
|
7
|
+
F_FOLLOWUP,
|
|
8
|
+
INLINE_OPS,
|
|
9
|
+
isEnabledOnlyRouter,
|
|
10
|
+
jobKey,
|
|
11
|
+
nodeOpsOf,
|
|
12
|
+
parseCalibration,
|
|
13
|
+
priceScript,
|
|
14
|
+
priceWorkflow,
|
|
15
|
+
R,
|
|
16
|
+
SAVINGS_TIERS,
|
|
17
|
+
type ScriptFacts,
|
|
18
|
+
splitByDay,
|
|
19
|
+
splitScriptByDay,
|
|
20
|
+
T0,
|
|
21
|
+
type WorkflowFacts,
|
|
22
|
+
} from "../be/savings/model";
|
|
23
|
+
|
|
24
|
+
const facts = (over: Partial<WorkflowFacts> = {}): WorkflowFacts => ({
|
|
25
|
+
runs: 1,
|
|
26
|
+
countedRuns: 1,
|
|
27
|
+
schedRuns: 0,
|
|
28
|
+
schedEffectRuns: 0,
|
|
29
|
+
eventRuns: 0,
|
|
30
|
+
effectRuns: 0,
|
|
31
|
+
effectOpsSum: 0,
|
|
32
|
+
opsSum: 0,
|
|
33
|
+
agentTasks: 0,
|
|
34
|
+
agentUsd: 0,
|
|
35
|
+
agentMs: 0,
|
|
36
|
+
followupUsd: 0,
|
|
37
|
+
childTaskUsd: 0,
|
|
38
|
+
childTaskMs: 0,
|
|
39
|
+
recordedLlmUsd: 0,
|
|
40
|
+
estimatedLlmUsd: 0,
|
|
41
|
+
computeSecs: 0,
|
|
42
|
+
...over,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const perRun = (ops: number) =>
|
|
46
|
+
SAVINGS_TIERS.map(
|
|
47
|
+
(tier) =>
|
|
48
|
+
priceWorkflow(facts({ opsSum: ops }), { tier, days: 30, band: "job" }).agentOnlyUsdPerRun,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// The report rounds its cells by hand (ultra pr-fix-loop: 3.03 vs 3.044), so allow 1.5 cents.
|
|
52
|
+
function expectReportRow(ops: number, row: number[]) {
|
|
53
|
+
perRun(ops).forEach((value, i) => {
|
|
54
|
+
expect(Math.abs(value - (row[i] as number))).toBeLessThan(0.015);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe("savings model", () => {
|
|
59
|
+
test("agent-only cost of one run matches the cost report table", () => {
|
|
60
|
+
// Report table "Agent-only cost of one run", smol/regular/smart/ultra.
|
|
61
|
+
expectReportRow(11, [0.12, 0.26, 0.41, 0.82]); // claude-code-changelog-watch
|
|
62
|
+
expectReportRow(100, [0.15, 0.78, 1.46, 3.03]); // pr-fix-loop
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("every tier curve has one point per turn up to TAU_MAX", () => {
|
|
66
|
+
for (const tier of SAVINGS_TIERS) {
|
|
67
|
+
expect(CURVE[tier].usd).toHaveLength(61);
|
|
68
|
+
expect(CURVE[tier].hrs).toHaveLength(61);
|
|
69
|
+
}
|
|
70
|
+
// Interpolates and clamps.
|
|
71
|
+
expect(curve(1.5, "smart", "usd")).toBeCloseTo((0.1746 + 0.2138) / 2, 6);
|
|
72
|
+
expect(curve(0, "smart", "usd")).toBe(0.1746);
|
|
73
|
+
expect(curve(500, "smart", "usd")).toBe(2.8086);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("schedule runs are capped at 24 a day, but effect runs always count", () => {
|
|
77
|
+
const priced = priceWorkflow(
|
|
78
|
+
facts({ runs: 1100, countedRuns: 1050, schedRuns: 1000, schedEffectRuns: 800, opsSum: 0 }),
|
|
79
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
80
|
+
);
|
|
81
|
+
// max(min(1000, 720), 800) + (1050 - 1000) non-schedule runs
|
|
82
|
+
expect(priced.substitutedRuns).toBe(850);
|
|
83
|
+
expect(priced.effectRuns).toBe(80);
|
|
84
|
+
expect(priced.enabledOnlyRuns).toBe(250);
|
|
85
|
+
expect(priced.capApplied).toBe(true);
|
|
86
|
+
|
|
87
|
+
const under = priceWorkflow(facts({ runs: 10, countedRuns: 10, schedRuns: 10 }), {
|
|
88
|
+
tier: "smart",
|
|
89
|
+
days: 30,
|
|
90
|
+
band: "job",
|
|
91
|
+
});
|
|
92
|
+
expect(under.substitutedRuns).toBe(10);
|
|
93
|
+
expect(under.capApplied).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("the band is wider for one job than for a fleet sum, and p50 is the point", () => {
|
|
97
|
+
const f = facts({ runs: 100, countedRuns: 100, opsSum: 100 * 40 });
|
|
98
|
+
const job = priceWorkflow(f, { tier: "smart", days: 30, band: "job" });
|
|
99
|
+
const fleet = priceWorkflow(f, { tier: "smart", days: 30, band: "fleet" });
|
|
100
|
+
expect(job.savingUsd.p50).toBeCloseTo(fleet.savingUsd.p50, 9);
|
|
101
|
+
expect(job.savingUsd.p50).toBeCloseTo(100 * job.agentOnlyUsdPerRun, 9);
|
|
102
|
+
expect(job.savingUsd.p10).toBeLessThan(fleet.savingUsd.p10);
|
|
103
|
+
expect(job.savingUsd.p90).toBeGreaterThan(fleet.savingUsd.p90);
|
|
104
|
+
expect(job.hoursSaved.p10).toBeLessThan(job.hoursSaved.p50);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("unowned task spend is kept on both sides and leaves the saving unchanged", () => {
|
|
108
|
+
const base = facts({ runs: 4, countedRuns: 4, opsSum: 40, agentUsd: 1, agentTasks: 1 });
|
|
109
|
+
const own = priceWorkflow(base, { tier: "smart", days: 30, band: "job" });
|
|
110
|
+
const withTasks = priceWorkflow(
|
|
111
|
+
{ ...base, childTaskUsd: 5, childTaskMs: 3_600_000 },
|
|
112
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
113
|
+
);
|
|
114
|
+
expect(withTasks.measuredUsd).toBeCloseTo(own.measuredUsd + 5, 6);
|
|
115
|
+
expect(withTasks.actualUsd).toBeCloseTo(own.actualUsd + 5, 6);
|
|
116
|
+
expect(withTasks.agentOnlyUsd.p50).toBeCloseTo(own.agentOnlyUsd.p50 + 5, 6);
|
|
117
|
+
for (const q of ["p10", "p50", "p90"] as const) {
|
|
118
|
+
expect(withTasks.savingUsd[q]).toBeCloseTo(own.savingUsd[q], 6);
|
|
119
|
+
}
|
|
120
|
+
expect(withTasks.hoursSaved.p50).toBeCloseTo(own.hoursSaved.p50, 6);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("kept agent spend appears on both sides; actual spend is per substituted run", () => {
|
|
124
|
+
const priced = priceWorkflow(
|
|
125
|
+
facts({
|
|
126
|
+
runs: 4,
|
|
127
|
+
countedRuns: 4,
|
|
128
|
+
opsSum: 40,
|
|
129
|
+
agentTasks: 2,
|
|
130
|
+
agentUsd: 8,
|
|
131
|
+
followupUsd: 2,
|
|
132
|
+
estimatedLlmUsd: 1,
|
|
133
|
+
agentMs: 7_200_000,
|
|
134
|
+
computeSecs: 3600,
|
|
135
|
+
}),
|
|
136
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
137
|
+
);
|
|
138
|
+
expect(priced.actualUsd).toBeCloseTo(11, 9);
|
|
139
|
+
// The $1 LLM estimate is not measured spend.
|
|
140
|
+
expect(priced.measuredUsd).toBeCloseTo(10, 9);
|
|
141
|
+
expect(priced.estimatedLlmUsd).toBeCloseTo(1, 9);
|
|
142
|
+
expect(priced.agentOnlyUsd.p50 - 10).toBeCloseTo(4 * priced.agentOnlyUsdPerRun, 9);
|
|
143
|
+
expect(priced.actualHours).toBeCloseTo(3, 9);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("measured spend is reported unscaled; the scaled estimate keeps the saving", () => {
|
|
147
|
+
// One $100 manual run and 999 skipped runs on one day.
|
|
148
|
+
const window = facts({ runs: 1000, countedRuns: 1, opsSum: 10, agentTasks: 1, agentUsd: 100 });
|
|
149
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 30, band: "job" });
|
|
150
|
+
expect(priced.substitutedRuns).toBe(1);
|
|
151
|
+
expect(priced.measuredUsd).toBe(100);
|
|
152
|
+
// The estimator's actual side is the scaled estimate, not the $100 measured.
|
|
153
|
+
expect(priced.actualUsd).toBeCloseTo(0.1, 9);
|
|
154
|
+
// Kept agent spend cancels: the saving is one substituted run at the unit cost.
|
|
155
|
+
expect(priced.savingUsd.p50).toBeCloseTo(priced.agentOnlyUsdPerRun, 9);
|
|
156
|
+
const [point] = splitByDay(window, [{ day: "2026-10-01", ...window }], {
|
|
157
|
+
tier: "smart",
|
|
158
|
+
days: 30,
|
|
159
|
+
});
|
|
160
|
+
expect(point?.measuredUsd).toBe(100);
|
|
161
|
+
expect(point?.actualUsd).toBeCloseTo(0.1, 9);
|
|
162
|
+
expect(point?.savingUsd).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("estimated LLM spend is reported apart from measured spend", () => {
|
|
166
|
+
// No recorded LLM cost: $5 is estimated from tokens and output size.
|
|
167
|
+
const window = facts({ runs: 1, countedRuns: 1, opsSum: 10, estimatedLlmUsd: 5 });
|
|
168
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 30, band: "job" });
|
|
169
|
+
expect(priced.measuredUsd).toBe(0);
|
|
170
|
+
expect(priced.estimatedLlmUsd).toBe(5);
|
|
171
|
+
// The saving still subtracts the estimate.
|
|
172
|
+
expect(priced.actualUsd).toBe(5);
|
|
173
|
+
expect(priced.savingUsd.p50).toBeCloseTo(priced.agentOnlyUsdPerRun - 5, 9);
|
|
174
|
+
const [point] = splitByDay(window, [{ day: "2026-10-01", ...window }], {
|
|
175
|
+
tier: "smart",
|
|
176
|
+
days: 30,
|
|
177
|
+
});
|
|
178
|
+
expect(point?.measuredUsd).toBe(0);
|
|
179
|
+
expect(point?.estimatedLlmUsd).toBe(5);
|
|
180
|
+
expect(point?.actualUsd).toBe(5);
|
|
181
|
+
expect(point?.savingUsd).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("recorded LLM cost replaces the token estimate", () => {
|
|
185
|
+
const priced = priceWorkflow(facts({ recordedLlmUsd: 2, estimatedLlmUsd: 5 }), {
|
|
186
|
+
tier: "smart",
|
|
187
|
+
days: 30,
|
|
188
|
+
band: "job",
|
|
189
|
+
});
|
|
190
|
+
expect(priced.actualUsd).toBe(2);
|
|
191
|
+
expect(priced.measuredUsd).toBe(2);
|
|
192
|
+
expect(priced.estimatedLlmUsd).toBe(0);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("a pure agent dispatcher substitutes nothing and pays no review", () => {
|
|
196
|
+
const priced = priceWorkflow(facts({ runs: 2, countedRuns: 2, agentTasks: 2, agentUsd: 4 }), {
|
|
197
|
+
tier: "smart",
|
|
198
|
+
days: 30,
|
|
199
|
+
band: "job",
|
|
200
|
+
});
|
|
201
|
+
expect(priced.agentOnlyUsdPerRun).toBe(0);
|
|
202
|
+
expect(priced.savingUsd.p50).toBe(0);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("node ops and job keys", () => {
|
|
206
|
+
const ops = nodeOpsOf(
|
|
207
|
+
{
|
|
208
|
+
nodes: [
|
|
209
|
+
{ id: "s", type: "script", config: { script: "await a(); await b()" } },
|
|
210
|
+
{ id: "bare", type: "script", config: { script: "echo hi" } },
|
|
211
|
+
{ id: "known", type: "swarm-script", config: { scriptName: "known" } },
|
|
212
|
+
{ id: "unknown", type: "swarm-script", config: { scriptName: "nope" } },
|
|
213
|
+
{ id: "n", type: "notify" },
|
|
214
|
+
{ id: "a", type: "agent-task" },
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
new Map([["known", 42]]),
|
|
218
|
+
);
|
|
219
|
+
expect(Object.fromEntries(ops)).toEqual({
|
|
220
|
+
s: 2,
|
|
221
|
+
bare: 1,
|
|
222
|
+
known: 42,
|
|
223
|
+
unknown: DEFAULT_OPS,
|
|
224
|
+
n: 1,
|
|
225
|
+
a: 0,
|
|
226
|
+
});
|
|
227
|
+
expect(jobKey("pr-fix-loop-retired-2026-10-28")).toBe("pr-fix-loop");
|
|
228
|
+
expect(jobKey("pr-fix-loop")).toBe("pr-fix-loop");
|
|
229
|
+
expect(F_FOLLOWUP).toBe(0.107);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("daily split sums to the window, and capped schedule runs spread pro rata", () => {
|
|
233
|
+
// 2 days of polling every 5 minutes (288 a day) against a 1-day cap of 24,
|
|
234
|
+
// plus one manual run with an agent task and a recorded LLM cost.
|
|
235
|
+
const day1 = facts({
|
|
236
|
+
runs: 288,
|
|
237
|
+
countedRuns: 288,
|
|
238
|
+
schedRuns: 288,
|
|
239
|
+
schedEffectRuns: 3,
|
|
240
|
+
opsSum: 288 * 5,
|
|
241
|
+
recordedLlmUsd: 0.4,
|
|
242
|
+
});
|
|
243
|
+
const day2 = facts({
|
|
244
|
+
runs: 145,
|
|
245
|
+
countedRuns: 145,
|
|
246
|
+
schedRuns: 144,
|
|
247
|
+
schedEffectRuns: 0,
|
|
248
|
+
opsSum: 145 * 5,
|
|
249
|
+
agentTasks: 1,
|
|
250
|
+
agentUsd: 2,
|
|
251
|
+
followupUsd: 0.1,
|
|
252
|
+
recordedLlmUsd: 0.2,
|
|
253
|
+
});
|
|
254
|
+
const window = facts({});
|
|
255
|
+
for (const k of Object.keys(window) as (keyof WorkflowFacts)[]) window[k] = day1[k] + day2[k];
|
|
256
|
+
const priced = priceWorkflow(window, { tier: "smart", days: 1, band: "job" });
|
|
257
|
+
expect(priced.capApplied).toBe(true);
|
|
258
|
+
const points = splitByDay(
|
|
259
|
+
window,
|
|
260
|
+
[
|
|
261
|
+
{ day: "2026-10-01", ...day1 },
|
|
262
|
+
{ day: "2026-10-02", ...day2 },
|
|
263
|
+
],
|
|
264
|
+
{ tier: "smart", days: 1 },
|
|
265
|
+
);
|
|
266
|
+
const sum = (key: "savingUsd" | "actualUsd" | "measuredUsd" | "estimatedLlmUsd") =>
|
|
267
|
+
points.reduce((s, p) => s + p[key], 0);
|
|
268
|
+
expect(sum("savingUsd")).toBeCloseTo(priced.savingUsd.p50, 9);
|
|
269
|
+
expect(sum("actualUsd")).toBeCloseTo(priced.actualUsd, 9);
|
|
270
|
+
expect(sum("measuredUsd")).toBeCloseTo(priced.measuredUsd, 9);
|
|
271
|
+
expect(sum("estimatedLlmUsd")).toBeCloseTo(priced.estimatedLlmUsd, 9);
|
|
272
|
+
// The 24 counted schedule runs split 288:144; the manual run stays on day 2.
|
|
273
|
+
const unit = priced.agentOnlyUsdPerRun;
|
|
274
|
+
const share = priced.substitutedRuns / window.runs;
|
|
275
|
+
expect(points[0]?.savingUsd).toBeCloseTo(16 * unit - 0.4 * share, 9);
|
|
276
|
+
expect(points[1]?.savingUsd).toBeCloseTo((8 + 1) * unit - 0.2 * share, 9);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("versions share the cap in order; effect runs always count", () => {
|
|
280
|
+
// 30 days: cap 720. v7 arithmetic: the live version takes the cap, the
|
|
281
|
+
// retired copy only adds effect runs above it.
|
|
282
|
+
const shares = allocateSchedule(
|
|
283
|
+
[
|
|
284
|
+
{ schedRuns: 1233, schedEffectRuns: 106 },
|
|
285
|
+
{ schedRuns: 1150, schedEffectRuns: 109 },
|
|
286
|
+
],
|
|
287
|
+
30,
|
|
288
|
+
);
|
|
289
|
+
expect(shares).toEqual([
|
|
290
|
+
{ vSched: 720, vCap: 720 },
|
|
291
|
+
{ vSched: 0, vCap: 0 },
|
|
292
|
+
]);
|
|
293
|
+
// Effect runs above the cap: the job total is max(min(sched, cap), effects).
|
|
294
|
+
const busy = allocateSchedule(
|
|
295
|
+
[
|
|
296
|
+
{ schedRuns: 1000, schedEffectRuns: 500 },
|
|
297
|
+
{ schedRuns: 1000, schedEffectRuns: 400 },
|
|
298
|
+
],
|
|
299
|
+
30,
|
|
300
|
+
);
|
|
301
|
+
expect(busy.reduce((s, v) => s + v.vSched, 0)).toBe(900);
|
|
302
|
+
const priced = priceWorkflow(
|
|
303
|
+
facts({ runs: 1150, countedRuns: 1150, schedRuns: 1150 }),
|
|
304
|
+
{ tier: "smart", days: 30, band: "job" },
|
|
305
|
+
shares[1],
|
|
306
|
+
);
|
|
307
|
+
expect(priced.substitutedRuns).toBe(0);
|
|
308
|
+
expect(priced.capApplied).toBe(true);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test("the enabled-only rule flips a high-volume event router, not a busy event workflow", () => {
|
|
312
|
+
const router = facts({
|
|
313
|
+
runs: 359_356,
|
|
314
|
+
countedRuns: 359_356,
|
|
315
|
+
eventRuns: 359_356,
|
|
316
|
+
effectRuns: 907,
|
|
317
|
+
effectOpsSum: 907,
|
|
318
|
+
opsSum: 718_712,
|
|
319
|
+
});
|
|
320
|
+
expect(isEnabledOnlyRouter(router, 30)).toBe(true);
|
|
321
|
+
const priced = priceWorkflow(router, { tier: "smart", days: 30, band: "job" });
|
|
322
|
+
expect(priced.enabledOnlyRule).toBe(true);
|
|
323
|
+
expect(priced.substitutedRuns).toBe(907);
|
|
324
|
+
expect(priced.enabledOnlyRuns).toBe(359_356 - 907);
|
|
325
|
+
expect(priced.actualUsd).toBe(0);
|
|
326
|
+
// One decision at the effect runs' own ops (1 per run) plus the review.
|
|
327
|
+
expect(priced.savingUsd.p50).toBeCloseTo(
|
|
328
|
+
907 * (1.02 * curve(2 + 0.2753, "smart", "usd") + F_FOLLOWUP),
|
|
329
|
+
6,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
// 41 event runs a day with no linked effect (an on-call poller): every run counts.
|
|
333
|
+
const oncall = facts({ runs: 1228, countedRuns: 1227, eventRuns: 1223, opsSum: 1228 * 12 });
|
|
334
|
+
expect(isEnabledOnlyRouter(oncall, 30)).toBe(false);
|
|
335
|
+
expect(priceWorkflow(oncall, { tier: "smart", days: 30, band: "job" }).substitutedRuns).toBe(
|
|
336
|
+
1227,
|
|
337
|
+
);
|
|
338
|
+
// Schedule-triggered high volume is the cap's job, not the rule's.
|
|
339
|
+
const poll = facts({ runs: 9000, countedRuns: 9000, schedRuns: 9000 });
|
|
340
|
+
expect(isEnabledOnlyRouter(poll, 30)).toBe(false);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("scripts", () => {
|
|
344
|
+
const script = (over: Partial<ScriptFacts> = {}): ScriptFacts => ({
|
|
345
|
+
runs: 0,
|
|
346
|
+
apiRuns: 0,
|
|
347
|
+
effectRuns: 0,
|
|
348
|
+
apiEffectRuns: 0,
|
|
349
|
+
opsSum: 0,
|
|
350
|
+
computeSecs: 0,
|
|
351
|
+
...over,
|
|
352
|
+
});
|
|
353
|
+
const p50 = (f: ScriptFacts, kind: "script-scheduled" | "script-agent-invoked") =>
|
|
354
|
+
Math.round(
|
|
355
|
+
priceScript(f, { tier: "smart", days: 30, band: "job", kind }).savingUsd.p50 * 100,
|
|
356
|
+
) / 100;
|
|
357
|
+
|
|
358
|
+
test("matches the v7 estimator run rows at smart over 30 days", () => {
|
|
359
|
+
// Scheduled and capped at 720 (client-seven-pct-page, 28 ops).
|
|
360
|
+
expect(p50(script({ runs: 1983, opsSum: 28 * 1983 }), "script-scheduled")).toBe(475.98);
|
|
361
|
+
// Scheduled, under the cap (github-insights-page-refresh, 30 ops).
|
|
362
|
+
expect(p50(script({ runs: 499, opsSum: 30 * 499 }), "script-scheduled")).toBe(338.85);
|
|
363
|
+
// Agent-invoked marginal turns, capped (dispatch-preflight, 48 ops).
|
|
364
|
+
expect(p50(script({ runs: 4164, opsSum: 48 * 4164 }), "script-agent-invoked")).toBe(378.15);
|
|
365
|
+
// Inline source at INLINE_OPS.
|
|
366
|
+
expect(p50(script({ runs: 15114, opsSum: INLINE_OPS * 15114 }), "script-agent-invoked")).toBe(
|
|
367
|
+
22.05,
|
|
368
|
+
);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test("agent-invoked runs are marginal turns with no bootstrap and no review", () => {
|
|
372
|
+
const f = script({ runs: 10, opsSum: 10 * 20 });
|
|
373
|
+
const tau = T0 + 0.2753 * 20;
|
|
374
|
+
const agent = priceScript(f, {
|
|
375
|
+
tier: "smart",
|
|
376
|
+
days: 30,
|
|
377
|
+
band: "job",
|
|
378
|
+
kind: "script-agent-invoked",
|
|
379
|
+
});
|
|
380
|
+
const sched = priceScript(f, {
|
|
381
|
+
tier: "smart",
|
|
382
|
+
days: 30,
|
|
383
|
+
band: "job",
|
|
384
|
+
kind: "script-scheduled",
|
|
385
|
+
});
|
|
386
|
+
expect(agent.agentOnlyUsdPerRun).toBeCloseTo(
|
|
387
|
+
R.p50 * (curve(tau, "smart", "usd") - curve(T0, "smart", "usd")),
|
|
388
|
+
9,
|
|
389
|
+
);
|
|
390
|
+
expect(sched.agentOnlyUsdPerRun).toBeCloseTo(
|
|
391
|
+
R.p50 * curve(tau, "smart", "usd") + F_FOLLOWUP,
|
|
392
|
+
9,
|
|
393
|
+
);
|
|
394
|
+
expect(agent.actualUsd).toBe(0);
|
|
395
|
+
expect(agent.substitutedRuns).toBe(10);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("API runs count only with an effect; non-API effect runs lift the cap", () => {
|
|
399
|
+
const priced = priceScript(
|
|
400
|
+
script({ runs: 1000, apiRuns: 100, apiEffectRuns: 4, effectRuns: 800, opsSum: 1000 * 10 }),
|
|
401
|
+
{ tier: "smart", days: 30, band: "job", kind: "script-scheduled" },
|
|
402
|
+
);
|
|
403
|
+
// max(min(900, 720), 800) non-API runs + 4 API effect runs.
|
|
404
|
+
expect(priced.substitutedRuns).toBe(804);
|
|
405
|
+
expect(priced.effectRuns).toBe(84);
|
|
406
|
+
expect(priced.enabledOnlyRuns).toBe(196);
|
|
407
|
+
expect(priced.capApplied).toBe(true);
|
|
408
|
+
const tau = T0 + 0.2753 * 10;
|
|
409
|
+
const unit = R.p50 * curve(tau, "smart", "usd") + F_FOLLOWUP;
|
|
410
|
+
expect(priced.savingUsd.p50).toBeCloseTo(804 * unit, 6);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test("script runs keep no agent active, so agent-hours saved never go negative", () => {
|
|
414
|
+
const cases: [ScriptFacts, "script-scheduled" | "script-agent-invoked"][] = [
|
|
415
|
+
// One API run with an effect that took 30 seconds.
|
|
416
|
+
[script({ runs: 1, apiRuns: 1, apiEffectRuns: 1, computeSecs: 30 }), "script-scheduled"],
|
|
417
|
+
[
|
|
418
|
+
script({ runs: 1, apiRuns: 1, apiEffectRuns: 1, computeSecs: 30 }),
|
|
419
|
+
"script-agent-invoked",
|
|
420
|
+
],
|
|
421
|
+
// Mixed API effect and non-API runs with long wall time.
|
|
422
|
+
[
|
|
423
|
+
script({ runs: 3, apiRuns: 1, apiEffectRuns: 1, computeSecs: 3 * 600 }),
|
|
424
|
+
"script-agent-invoked",
|
|
425
|
+
],
|
|
426
|
+
// An agent-invoked run with no ops adds no turns, so it saves no hours.
|
|
427
|
+
[script({ runs: 1, computeSecs: 30 }), "script-agent-invoked"],
|
|
428
|
+
];
|
|
429
|
+
for (const [f, kind] of cases) {
|
|
430
|
+
const priced = priceScript(f, { tier: "smart", days: 1, band: "job", kind });
|
|
431
|
+
expect(priced.actualHours).toBe(0);
|
|
432
|
+
expect(priced.hoursSaved).toEqual(priced.agentOnlyHours);
|
|
433
|
+
expect(priced.hoursSaved.p10).toBeGreaterThanOrEqual(0);
|
|
434
|
+
}
|
|
435
|
+
const api = priceScript(cases[0]?.[0] as ScriptFacts, {
|
|
436
|
+
tier: "smart",
|
|
437
|
+
days: 1,
|
|
438
|
+
band: "job",
|
|
439
|
+
kind: "script-scheduled",
|
|
440
|
+
});
|
|
441
|
+
expect(api.hoursSaved.p50).toBeCloseTo(R.p50 * curve(T0, "smart", "hrs"), 9);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test("daily split sums to the window saving", () => {
|
|
445
|
+
const days = [
|
|
446
|
+
{ day: "2026-10-01", ...script({ runs: 900, opsSum: 900 * 5 }) },
|
|
447
|
+
{ day: "2026-10-02", ...script({ runs: 100, apiRuns: 10, apiEffectRuns: 2, opsSum: 500 }) },
|
|
448
|
+
];
|
|
449
|
+
const f = script({ runs: 1000, apiRuns: 10, apiEffectRuns: 2, opsSum: 5000 });
|
|
450
|
+
const priced = priceScript(f, {
|
|
451
|
+
tier: "smart",
|
|
452
|
+
days: 30,
|
|
453
|
+
band: "job",
|
|
454
|
+
kind: "script-scheduled",
|
|
455
|
+
});
|
|
456
|
+
const split = splitScriptByDay(f, days, priced);
|
|
457
|
+
expect(split.reduce((s, d) => s + d.savingUsd, 0)).toBeCloseTo(priced.savingUsd.p50, 6);
|
|
458
|
+
expect(split.every((d) => d.actualUsd === 0)).toBe(true);
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
describe("calibration", () => {
|
|
464
|
+
const stored = (over: Record<string, unknown> = {}) =>
|
|
465
|
+
JSON.stringify({ calibratedAt: "2026-12-01", model: "claude-opus-5-5", curve: CURVE, ...over });
|
|
466
|
+
|
|
467
|
+
test("a stored curve parses as a deployment calibration", () => {
|
|
468
|
+
expect(parseCalibration(stored())).toMatchObject({
|
|
469
|
+
source: "deployment",
|
|
470
|
+
calibratedAt: "2026-12-01",
|
|
471
|
+
model: "claude-opus-5-5",
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test("a missing, malformed or wrongly shaped value is null, so callers use the shipped curve", () => {
|
|
476
|
+
expect(parseCalibration(null)).toBeNull();
|
|
477
|
+
expect(parseCalibration("not json")).toBeNull();
|
|
478
|
+
expect(parseCalibration(stored({ calibratedAt: "yesterday" }))).toBeNull();
|
|
479
|
+
const short = { ...CURVE, smart: { usd: CURVE.smart.usd.slice(1), hrs: CURVE.smart.hrs } };
|
|
480
|
+
expect(parseCalibration(stored({ curve: short }))).toBeNull();
|
|
481
|
+
const zero = { ...CURVE, smol: { usd: CURVE.smol.usd.map(() => 0), hrs: CURVE.smol.hrs } };
|
|
482
|
+
expect(parseCalibration(stored({ curve: zero }))).toBeNull();
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test("priceWorkflow uses the given curve and the shipped one by default", () => {
|
|
486
|
+
const doubled = Object.fromEntries(
|
|
487
|
+
SAVINGS_TIERS.map((t) => [t, { usd: CURVE[t].usd.map((v) => v * 2), hrs: CURVE[t].hrs }]),
|
|
488
|
+
) as typeof CURVE;
|
|
489
|
+
const f = facts({ opsSum: 10 });
|
|
490
|
+
const base = priceWorkflow(f, { tier: "smart", days: 30, band: "job" });
|
|
491
|
+
const same = priceWorkflow(f, { tier: "smart", days: 30, band: "job", curve: CURVE });
|
|
492
|
+
const twice = priceWorkflow(f, { tier: "smart", days: 30, band: "job", curve: doubled });
|
|
493
|
+
expect(same.agentOnlyUsdPerRun).toBe(base.agentOnlyUsdPerRun);
|
|
494
|
+
expect(twice.agentOnlyUsdPerRun - F_FOLLOWUP).toBeCloseTo(
|
|
495
|
+
2 * (base.agentOnlyUsdPerRun - F_FOLLOWUP),
|
|
496
|
+
6,
|
|
497
|
+
);
|
|
498
|
+
});
|
|
499
|
+
});
|