@alumbwe/anvil 1.0.20 → 1.0.22
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/package.json +74 -70
- package/src/agents/bundled-agents.generated.ts +4 -4
- package/src/chat.tsx +1703 -1698
- package/src/cli-args.ts +134 -134
- package/src/components/status-bar.tsx +331 -313
- package/src/hooks/helpers/send-message.ts +663 -654
- package/src/hooks/use-send-message.ts +806 -773
- package/src/index.tsx +473 -473
- package/src/state/chat-store.ts +553 -544
- package/src/utils/create-run-config.ts +121 -121
- package/src/utils/format-compact-number.ts +37 -0
- package/vendor/@anvil/common/package.json +27 -0
- package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +846 -0
- package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +101 -0
- package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +1408 -0
- package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +258 -0
- package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +48 -0
- package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +282 -0
- package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +526 -0
- package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +68 -0
- package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +422 -0
- package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/env-process.test.ts +145 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +234 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +379 -0
- package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +807 -0
- package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +154 -0
- package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +246 -0
- package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +77 -0
- package/vendor/@anvil/common/src/__tests__/model-config.test.ts +89 -0
- package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +298 -0
- package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +116 -0
- package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +72 -0
- package/vendor/@anvil/common/src/__tests__/user-state.test.ts +30 -0
- package/vendor/@anvil/common/src/actions.ts +215 -0
- package/vendor/@anvil/common/src/analytics-core.ts +69 -0
- package/vendor/@anvil/common/src/analytics.ts +93 -0
- package/vendor/@anvil/common/src/api-keys/constants.ts +26 -0
- package/vendor/@anvil/common/src/browser-actions.ts +413 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +63 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +246 -0
- package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +106 -0
- package/vendor/@anvil/common/src/constants/agents.ts +99 -0
- package/vendor/@anvil/common/src/constants/analytics-events.ts +435 -0
- package/vendor/@anvil/common/src/constants/anthropic.ts +73 -0
- package/vendor/@anvil/common/src/constants/anvil-data-use.ts +81 -0
- package/vendor/@anvil/common/src/constants/anvil-errors.ts +7 -0
- package/vendor/@anvil/common/src/constants/anvil-gemini-thinker.ts +21 -0
- package/vendor/@anvil/common/src/constants/anvil-model-ids.ts +11 -0
- package/vendor/@anvil/common/src/constants/anvil-models.ts +2130 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding-gate.ts +55 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding.ts +307 -0
- package/vendor/@anvil/common/src/constants/anvil-referral-tiers.ts +87 -0
- package/vendor/@anvil/common/src/constants/anvil-signup-block.ts +68 -0
- package/vendor/@anvil/common/src/constants/anvil-spend-ceilings.ts +450 -0
- package/vendor/@anvil/common/src/constants/anvil-trust.ts +976 -0
- package/vendor/@anvil/common/src/constants/auth.ts +18 -0
- package/vendor/@anvil/common/src/constants/byok.ts +2 -0
- package/vendor/@anvil/common/src/constants/cf-worker-signals.ts +132 -0
- package/vendor/@anvil/common/src/constants/composio.ts +34 -0
- package/vendor/@anvil/common/src/constants/deepseek-direct.ts +55 -0
- package/vendor/@anvil/common/src/constants/feedback.ts +13 -0
- package/vendor/@anvil/common/src/constants/foreign-client-signals.ts +272 -0
- package/vendor/@anvil/common/src/constants/free-agents.ts +777 -0
- package/vendor/@anvil/common/src/constants/gemini.ts +15 -0
- package/vendor/@anvil/common/src/constants/grant-priorities.ts +13 -0
- package/vendor/@anvil/common/src/constants/hosts.ts +6 -0
- package/vendor/@anvil/common/src/constants/images.ts +51 -0
- package/vendor/@anvil/common/src/constants/index.ts +7 -0
- package/vendor/@anvil/common/src/constants/knowledge.ts +35 -0
- package/vendor/@anvil/common/src/constants/limits.ts +23 -0
- package/vendor/@anvil/common/src/constants/model-config.ts +277 -0
- package/vendor/@anvil/common/src/constants/openrouter-attribution.ts +8 -0
- package/vendor/@anvil/common/src/constants/paths.ts +69 -0
- package/vendor/@anvil/common/src/constants/provider-routes.ts +317 -0
- package/vendor/@anvil/common/src/constants/reasoning-effort.ts +79 -0
- package/vendor/@anvil/common/src/constants/skills.ts +60 -0
- package/vendor/@anvil/common/src/constants/subscription-plans.ts +49 -0
- package/vendor/@anvil/common/src/constants/ui.ts +25 -0
- package/vendor/@anvil/common/src/env-ci.ts +36 -0
- package/vendor/@anvil/common/src/env-process.ts +95 -0
- package/vendor/@anvil/common/src/env-schema.ts +95 -0
- package/vendor/@anvil/common/src/env.ts +24 -0
- package/vendor/@anvil/common/src/gravity-capi.ts +207 -0
- package/vendor/@anvil/common/src/mcp/client.ts +233 -0
- package/vendor/@anvil/common/src/old-constants.ts +10 -0
- package/vendor/@anvil/common/src/project-file-tree.ts +355 -0
- package/vendor/@anvil/common/src/reddit-capi.ts +254 -0
- package/vendor/@anvil/common/src/schemas/feedback.ts +52 -0
- package/vendor/@anvil/common/src/schemas/logs.ts +66 -0
- package/vendor/@anvil/common/src/templates/agent-validation.ts +392 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/LICENSE +202 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/README.md +294 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts +17 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts +78 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts +73 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/my-custom-agent.ts +40 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/package.json +6 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/README.md +65 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/example-skill/SKILL.md +29 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/agent-definition.ts +497 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/tools.ts +444 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/util-types.ts +178 -0
- package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +351 -0
- package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +169 -0
- package/vendor/@anvil/common/src/testing/errors.ts +33 -0
- package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +334 -0
- package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +6 -0
- package/vendor/@anvil/common/src/testing/index.ts +84 -0
- package/vendor/@anvil/common/src/testing/mock-modules.ts +53 -0
- package/vendor/@anvil/common/src/testing/mock-types.ts +123 -0
- package/vendor/@anvil/common/src/testing/mocks/analytics.ts +261 -0
- package/vendor/@anvil/common/src/testing/mocks/child-process.ts +93 -0
- package/vendor/@anvil/common/src/testing/mocks/crypto.ts +218 -0
- package/vendor/@anvil/common/src/testing/mocks/database.ts +337 -0
- package/vendor/@anvil/common/src/testing/mocks/fetch.ts +219 -0
- package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +166 -0
- package/vendor/@anvil/common/src/testing/mocks/index.ts +101 -0
- package/vendor/@anvil/common/src/testing/mocks/logger.ts +135 -0
- package/vendor/@anvil/common/src/testing/mocks/stream.ts +313 -0
- package/vendor/@anvil/common/src/testing/mocks/timers.ts +132 -0
- package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +127 -0
- package/vendor/@anvil/common/src/testing/setup.ts +282 -0
- package/vendor/@anvil/common/src/testing-env-ci.ts +15 -0
- package/vendor/@anvil/common/src/testing-env-process.ts +78 -0
- package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +34 -0
- package/vendor/@anvil/common/src/tools/compile-tool-definitions.ts +157 -0
- package/vendor/@anvil/common/src/tools/constants.ts +117 -0
- package/vendor/@anvil/common/src/tools/list.ts +190 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +213 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +47 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +65 -0
- package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +49 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-message.ts +39 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-subgoal.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/apply-patch.ts +110 -0
- package/vendor/@anvil/common/src/tools/params/tool/ask-user.ts +181 -0
- package/vendor/@anvil/common/src/tools/params/tool/browser-logs.ts +85 -0
- package/vendor/@anvil/common/src/tools/params/tool/cloud-plan-ready.ts +94 -0
- package/vendor/@anvil/common/src/tools/params/tool/code-search.ts +159 -0
- package/vendor/@anvil/common/src/tools/params/tool/composio.ts +131 -0
- package/vendor/@anvil/common/src/tools/params/tool/create-plan.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/end-turn.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/find-files.ts +60 -0
- package/vendor/@anvil/common/src/tools/params/tool/glob.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/gravity-index.ts +93 -0
- package/vendor/@anvil/common/src/tools/params/tool/list-directory.ts +58 -0
- package/vendor/@anvil/common/src/tools/params/tool/lookup-agent-info.ts +37 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-str-replace.ts +103 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-docs.ts +90 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-files.ts +109 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-subtree.ts +79 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-url.ts +81 -0
- package/vendor/@anvil/common/src/tools/params/tool/render-ui.ts +168 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-file-change-hooks.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-terminal-command.ts +211 -0
- package/vendor/@anvil/common/src/tools/params/tool/screenshot.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-messages.ts +44 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-output.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/skill.ts +59 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agent-inline.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agents.ts +154 -0
- package/vendor/@anvil/common/src/tools/params/tool/str-replace.ts +107 -0
- package/vendor/@anvil/common/src/tools/params/tool/suggest-followups.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/task-completed.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/think-deeply.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/update-subgoal.ts +89 -0
- package/vendor/@anvil/common/src/tools/params/tool/vision-analyze.ts +82 -0
- package/vendor/@anvil/common/src/tools/params/tool/web-search.ts +73 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-todos.ts +67 -0
- package/vendor/@anvil/common/src/tools/params/utils.ts +150 -0
- package/vendor/@anvil/common/src/tools/utils.ts +24 -0
- package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +20 -0
- package/vendor/@anvil/common/src/types/agent-template.ts +215 -0
- package/vendor/@anvil/common/src/types/anvil-session.ts +535 -0
- package/vendor/@anvil/common/src/types/anvil-streak.ts +6 -0
- package/vendor/@anvil/common/src/types/anvil-usage.ts +64 -0
- package/vendor/@anvil/common/src/types/api/agents/publish.ts +61 -0
- package/vendor/@anvil/common/src/types/bun-test.d.ts +5 -0
- package/vendor/@anvil/common/src/types/contracts/agent-runtime.ts +75 -0
- package/vendor/@anvil/common/src/types/contracts/analytics.ts +9 -0
- package/vendor/@anvil/common/src/types/contracts/bigquery.ts +55 -0
- package/vendor/@anvil/common/src/types/contracts/billing.ts +46 -0
- package/vendor/@anvil/common/src/types/contracts/client.ts +53 -0
- package/vendor/@anvil/common/src/types/contracts/database.ts +112 -0
- package/vendor/@anvil/common/src/types/contracts/env.ts +203 -0
- package/vendor/@anvil/common/src/types/contracts/llm.ts +191 -0
- package/vendor/@anvil/common/src/types/contracts/logger.ts +14 -0
- package/vendor/@anvil/common/src/types/contracts/logs.ts +34 -0
- package/vendor/@anvil/common/src/types/contracts/trace.ts +21 -0
- package/vendor/@anvil/common/src/types/dynamic-agent-template.ts +328 -0
- package/vendor/@anvil/common/src/types/filesystem.ts +10 -0
- package/vendor/@anvil/common/src/types/function-params.ts +33 -0
- package/vendor/@anvil/common/src/types/grant.ts +20 -0
- package/vendor/@anvil/common/src/types/gravity-index.ts +170 -0
- package/vendor/@anvil/common/src/types/json.ts +29 -0
- package/vendor/@anvil/common/src/types/mcp.ts +24 -0
- package/vendor/@anvil/common/src/types/messages/anvil-message.ts +58 -0
- package/vendor/@anvil/common/src/types/messages/content-part.ts +59 -0
- package/vendor/@anvil/common/src/types/messages/data-content.ts +14 -0
- package/vendor/@anvil/common/src/types/messages/provider-metadata.ts +13 -0
- package/vendor/@anvil/common/src/types/organization.ts +118 -0
- package/vendor/@anvil/common/src/types/print-mode.ts +121 -0
- package/vendor/@anvil/common/src/types/publisher.ts +67 -0
- package/vendor/@anvil/common/src/types/session-state.ts +149 -0
- package/vendor/@anvil/common/src/types/skill.ts +86 -0
- package/vendor/@anvil/common/src/types/source.ts +11 -0
- package/vendor/@anvil/common/src/types/spawn.ts +13 -0
- package/vendor/@anvil/common/src/types/subscription.ts +67 -0
- package/vendor/@anvil/common/src/types/usage.ts +16 -0
- package/vendor/@anvil/common/src/types/util.ts +3 -0
- package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +26 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +122 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +102 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +143 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +202 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +193 -0
- package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +140 -0
- package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +148 -0
- package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +115 -0
- package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +57 -0
- package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +774 -0
- package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +206 -0
- package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +173 -0
- package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +60 -0
- package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +31 -0
- package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +1252 -0
- package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +505 -0
- package/vendor/@anvil/common/src/util/__tests__/path.test.ts +22 -0
- package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +90 -0
- package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +325 -0
- package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +28 -0
- package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +130 -0
- package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +1008 -0
- package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +289 -0
- package/vendor/@anvil/common/src/util/__tests__/string.test.ts +239 -0
- package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +70 -0
- package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +108 -0
- package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +180 -0
- package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +24 -0
- package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +88 -0
- package/vendor/@anvil/common/src/util/ad-user-agent.ts +25 -0
- package/vendor/@anvil/common/src/util/agent-file-utils.ts +110 -0
- package/vendor/@anvil/common/src/util/agent-id-parsing.ts +136 -0
- package/vendor/@anvil/common/src/util/agent-name-normalization.ts +38 -0
- package/vendor/@anvil/common/src/util/agent-name-resolver.ts +86 -0
- package/vendor/@anvil/common/src/util/analytics-dispatcher.ts +82 -0
- package/vendor/@anvil/common/src/util/analytics-log.ts +78 -0
- package/vendor/@anvil/common/src/util/analytics-sampling.ts +255 -0
- package/vendor/@anvil/common/src/util/anvil-model-availability.ts +102 -0
- package/vendor/@anvil/common/src/util/anvil-privacy.ts +82 -0
- package/vendor/@anvil/common/src/util/anvil-streak-line.ts +103 -0
- package/vendor/@anvil/common/src/util/anvil-streak.ts +156 -0
- package/vendor/@anvil/common/src/util/anvil-usage-summary.ts +125 -0
- package/vendor/@anvil/common/src/util/array.ts +31 -0
- package/vendor/@anvil/common/src/util/axiom-only-log.ts +124 -0
- package/vendor/@anvil/common/src/util/cache-debug.ts +171 -0
- package/vendor/@anvil/common/src/util/client-user-agent.ts +114 -0
- package/vendor/@anvil/common/src/util/credentials.ts +26 -0
- package/vendor/@anvil/common/src/util/currency.ts +25 -0
- package/vendor/@anvil/common/src/util/dates.ts +81 -0
- package/vendor/@anvil/common/src/util/disposable-email.ts +277 -0
- package/vendor/@anvil/common/src/util/engagement-tracker.ts +129 -0
- package/vendor/@anvil/common/src/util/env-file-path.ts +40 -0
- package/vendor/@anvil/common/src/util/error.ts +562 -0
- package/vendor/@anvil/common/src/util/file-read-limits.ts +236 -0
- package/vendor/@anvil/common/src/util/file.ts +339 -0
- package/vendor/@anvil/common/src/util/format-code-search.ts +115 -0
- package/vendor/@anvil/common/src/util/lazy-response-ads.ts +92 -0
- package/vendor/@anvil/common/src/util/log-data.ts +57 -0
- package/vendor/@anvil/common/src/util/log-ingest.ts +58 -0
- package/vendor/@anvil/common/src/util/log-mirror.ts +34 -0
- package/vendor/@anvil/common/src/util/lru-cache.ts +67 -0
- package/vendor/@anvil/common/src/util/messages.ts +685 -0
- package/vendor/@anvil/common/src/util/min-heap.ts +87 -0
- package/vendor/@anvil/common/src/util/model-utils.ts +4 -0
- package/vendor/@anvil/common/src/util/object.ts +128 -0
- package/vendor/@anvil/common/src/util/partial-json-delta.ts +89 -0
- package/vendor/@anvil/common/src/util/path.ts +15 -0
- package/vendor/@anvil/common/src/util/project-ignore.ts +119 -0
- package/vendor/@anvil/common/src/util/promise.ts +73 -0
- package/vendor/@anvil/common/src/util/random.ts +15 -0
- package/vendor/@anvil/common/src/util/rate-limit.ts +56 -0
- package/vendor/@anvil/common/src/util/reddit-anvil-retention.ts +60 -0
- package/vendor/@anvil/common/src/util/reddit-capi-events.ts +36 -0
- package/vendor/@anvil/common/src/util/response-ad-positions.ts +54 -0
- package/vendor/@anvil/common/src/util/saxy.ts +741 -0
- package/vendor/@anvil/common/src/util/skills.test.ts +44 -0
- package/vendor/@anvil/common/src/util/skills.ts +36 -0
- package/vendor/@anvil/common/src/util/split-data.ts +259 -0
- package/vendor/@anvil/common/src/util/stop-sequence.ts +61 -0
- package/vendor/@anvil/common/src/util/string.ts +426 -0
- package/vendor/@anvil/common/src/util/system-info.ts +53 -0
- package/vendor/@anvil/common/src/util/thread-title.ts +46 -0
- package/vendor/@anvil/common/src/util/ttft-histogram.ts +73 -0
- package/vendor/@anvil/common/src/util/xml-parser.ts +27 -0
- package/vendor/@anvil/common/src/util/xml.ts +17 -0
- package/vendor/@anvil/common/src/util/zod-schema.ts +25 -0
- package/vendor/@anvil/common/src/util/zoned-time.ts +136 -0
- package/vendor/@anvil/common/src/utils/ask-user-bridge.ts +44 -0
- package/vendor/@anvil/sdk/dist/index.cjs +52297 -0
- package/vendor/@anvil/sdk/dist/index.cjs.map +440 -0
- package/vendor/@anvil/sdk/dist/index.d.ts +4277 -0
- package/vendor/@anvil/sdk/dist/index.mjs +52290 -0
- package/vendor/@anvil/sdk/dist/index.mjs.map +440 -0
- package/vendor/@anvil/sdk/dist/vendor/ai.cjs +30886 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-c-sharp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-cpp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-go.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-java.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-javascript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-python.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-ruby.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-rust.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-tsx.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-typescript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter.wasm +0 -0
- package/vendor/@anvil/sdk/package.json +21 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { AnalyticsEvent } from '@anvil/common/constants/analytics-events'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isFullTelemetryEnabled,
|
|
7
|
+
shouldTrackAnalyticsEvent,
|
|
8
|
+
summarizeAnalyticsValue,
|
|
9
|
+
} from '../analytics-sampling'
|
|
10
|
+
|
|
11
|
+
const ORIGINAL_ENV = {
|
|
12
|
+
ANVIL_FULL_TELEMETRY: process.env.ANVIL_FULL_TELEMETRY,
|
|
13
|
+
ANVIL_FULL_TELEMETRY_IDS: process.env.ANVIL_FULL_TELEMETRY_IDS,
|
|
14
|
+
ANVIL_FULL_TELEMETRY_USER_IDS:
|
|
15
|
+
process.env.ANVIL_FULL_TELEMETRY_USER_IDS,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function restoreEnv() {
|
|
19
|
+
for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
delete process.env[key]
|
|
22
|
+
} else {
|
|
23
|
+
process.env[key] = value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('analytics sampling', () => {
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
restoreEnv()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('always tracks core CLI lifecycle events', () => {
|
|
34
|
+
expect(
|
|
35
|
+
shouldTrackAnalyticsEvent({
|
|
36
|
+
event: AnalyticsEvent.APP_LAUNCHED,
|
|
37
|
+
distinctId: 'user-1',
|
|
38
|
+
}),
|
|
39
|
+
).toBe(true)
|
|
40
|
+
expect(
|
|
41
|
+
shouldTrackAnalyticsEvent({
|
|
42
|
+
event: AnalyticsEvent.USER_INPUT_COMPLETE,
|
|
43
|
+
distinctId: 'user-1',
|
|
44
|
+
}),
|
|
45
|
+
).toBe(true)
|
|
46
|
+
expect(
|
|
47
|
+
shouldTrackAnalyticsEvent({
|
|
48
|
+
event: AnalyticsEvent.TERMINAL_BROKER_SPAWN_FAILED,
|
|
49
|
+
distinctId: 'user-1',
|
|
50
|
+
}),
|
|
51
|
+
).toBe(true)
|
|
52
|
+
expect(
|
|
53
|
+
shouldTrackAnalyticsEvent({
|
|
54
|
+
event: AnalyticsEvent.TERMINAL_WATCHDOG_FAILED,
|
|
55
|
+
distinctId: 'user-1',
|
|
56
|
+
}),
|
|
57
|
+
).toBe(true)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('always tracks CLI error logs', () => {
|
|
61
|
+
expect(
|
|
62
|
+
shouldTrackAnalyticsEvent({
|
|
63
|
+
event: AnalyticsEvent.CLI_LOG,
|
|
64
|
+
distinctId: 'user-1',
|
|
65
|
+
properties: { level: 'error' },
|
|
66
|
+
}),
|
|
67
|
+
).toBe(true)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('samples high-volume events deterministically', () => {
|
|
71
|
+
const first = shouldTrackAnalyticsEvent({
|
|
72
|
+
event: AnalyticsEvent.TOOL_USE,
|
|
73
|
+
distinctId: 'user-1',
|
|
74
|
+
})
|
|
75
|
+
const second = shouldTrackAnalyticsEvent({
|
|
76
|
+
event: AnalyticsEvent.TOOL_USE,
|
|
77
|
+
distinctId: 'user-1',
|
|
78
|
+
})
|
|
79
|
+
const otherEvent = shouldTrackAnalyticsEvent({
|
|
80
|
+
event: AnalyticsEvent.AGENT_STEP,
|
|
81
|
+
distinctId: 'user-1',
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
expect(second).toBe(first)
|
|
85
|
+
expect(typeof otherEvent).toBe('boolean')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('samples inline ad slot demand instead of ingesting every slot', () => {
|
|
89
|
+
const decisions = Array.from({ length: 1_000 }, (_, i) =>
|
|
90
|
+
shouldTrackAnalyticsEvent({
|
|
91
|
+
event: AnalyticsEvent.CLI_INLINE_AD_SLOT_ELIGIBLE,
|
|
92
|
+
distinctId: `inline-ad-user-${i}`,
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
expect(decisions).toContain(true)
|
|
97
|
+
expect(decisions).toContain(false)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('honors full telemetry env flags and allowlists', () => {
|
|
101
|
+
process.env.ANVIL_FULL_TELEMETRY = 'true'
|
|
102
|
+
expect(
|
|
103
|
+
isFullTelemetryEnabled({
|
|
104
|
+
distinctId: 'anyone',
|
|
105
|
+
}),
|
|
106
|
+
).toBe(true)
|
|
107
|
+
|
|
108
|
+
delete process.env.ANVIL_FULL_TELEMETRY
|
|
109
|
+
process.env.ANVIL_FULL_TELEMETRY_IDS = 'user-2,person@example.com'
|
|
110
|
+
|
|
111
|
+
expect(
|
|
112
|
+
isFullTelemetryEnabled({
|
|
113
|
+
distinctId: 'user-2',
|
|
114
|
+
}),
|
|
115
|
+
).toBe(true)
|
|
116
|
+
expect(
|
|
117
|
+
isFullTelemetryEnabled({
|
|
118
|
+
properties: { userEmail: 'person@example.com' },
|
|
119
|
+
}),
|
|
120
|
+
).toBe(true)
|
|
121
|
+
expect(
|
|
122
|
+
isFullTelemetryEnabled({
|
|
123
|
+
distinctId: 'user-3',
|
|
124
|
+
}),
|
|
125
|
+
).toBe(false)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('summarizes values without retaining raw contents', () => {
|
|
129
|
+
expect(summarizeAnalyticsValue('secret text')).toEqual({
|
|
130
|
+
kind: 'string',
|
|
131
|
+
length: 11,
|
|
132
|
+
})
|
|
133
|
+
expect(summarizeAnalyticsValue(['a', 'b'])).toEqual({
|
|
134
|
+
kind: 'array',
|
|
135
|
+
length: 2,
|
|
136
|
+
})
|
|
137
|
+
expect(summarizeAnalyticsValue({ prompt: 'secret', count: 1 })).toEqual({
|
|
138
|
+
kind: 'object',
|
|
139
|
+
keyCount: 2,
|
|
140
|
+
keys: ['prompt', 'count'],
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
})
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
addDaysToDateKey,
|
|
5
|
+
calculateAnvilStreak,
|
|
6
|
+
getAnvilDailyStreakRewardPool,
|
|
7
|
+
getAnvilStreakGlmBonusUnits,
|
|
8
|
+
getAnvilUsageDateKey,
|
|
9
|
+
} from '../anvil-streak'
|
|
10
|
+
|
|
11
|
+
function usageDatesFrom(startDateKey: string, count: number): string[] {
|
|
12
|
+
return Array.from({ length: count }, (_, index) =>
|
|
13
|
+
addDaysToDateKey(startDateKey, index),
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('anvil streak helpers', () => {
|
|
18
|
+
test('formats usage dates in the Anvil reset timezone', () => {
|
|
19
|
+
expect(getAnvilUsageDateKey(new Date('2026-05-27T06:30:00.000Z'))).toBe(
|
|
20
|
+
'2026-05-26',
|
|
21
|
+
)
|
|
22
|
+
expect(getAnvilUsageDateKey(new Date('2026-05-27T08:30:00.000Z'))).toBe(
|
|
23
|
+
'2026-05-27',
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('adds days across month boundaries', () => {
|
|
28
|
+
expect(addDaysToDateKey('2026-03-01', -1)).toBe('2026-02-28')
|
|
29
|
+
expect(addDaysToDateKey('2024-03-01', -1)).toBe('2024-02-29')
|
|
30
|
+
expect(addDaysToDateKey('2026-12-31', 1)).toBe('2027-01-01')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('counts a streak that includes today', () => {
|
|
34
|
+
expect(
|
|
35
|
+
calculateAnvilStreak({
|
|
36
|
+
todayDateKey: '2026-05-27',
|
|
37
|
+
usageDates: ['2026-05-25', '2026-05-23', '2026-05-27', '2026-05-26'],
|
|
38
|
+
}),
|
|
39
|
+
).toEqual({
|
|
40
|
+
streak: 3,
|
|
41
|
+
todayUsed: true,
|
|
42
|
+
lastUsageDate: '2026-05-27',
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('keeps yesterday-anchored streaks alive before today is used', () => {
|
|
47
|
+
expect(
|
|
48
|
+
calculateAnvilStreak({
|
|
49
|
+
todayDateKey: '2026-05-27',
|
|
50
|
+
usageDates: ['2026-05-26', '2026-05-25', '2026-05-24'],
|
|
51
|
+
}),
|
|
52
|
+
).toEqual({
|
|
53
|
+
streak: 3,
|
|
54
|
+
todayUsed: false,
|
|
55
|
+
lastUsageDate: '2026-05-26',
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('returns zero after a missed full day', () => {
|
|
60
|
+
expect(
|
|
61
|
+
calculateAnvilStreak({
|
|
62
|
+
todayDateKey: '2026-05-27',
|
|
63
|
+
usageDates: ['2026-05-25', '2026-05-24'],
|
|
64
|
+
}),
|
|
65
|
+
).toEqual({
|
|
66
|
+
streak: 0,
|
|
67
|
+
todayUsed: false,
|
|
68
|
+
lastUsageDate: '2026-05-25',
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('anvil streak rewards', () => {
|
|
74
|
+
test('grants one weekly GLM session per completed 7 days, capped at 4', () => {
|
|
75
|
+
const expected: Array<[streak: number, units: number]> = [
|
|
76
|
+
[7, 1],
|
|
77
|
+
[8, 1],
|
|
78
|
+
[13, 1],
|
|
79
|
+
[14, 2],
|
|
80
|
+
[21, 3],
|
|
81
|
+
[28, 4],
|
|
82
|
+
[42, 4],
|
|
83
|
+
]
|
|
84
|
+
for (const [streak, units] of expected) {
|
|
85
|
+
expect(
|
|
86
|
+
getAnvilStreakGlmBonusUnits({
|
|
87
|
+
todayDateKey: addDaysToDateKey('2026-07-01', streak - 1),
|
|
88
|
+
usageDates: usageDatesFrom('2026-07-01', streak),
|
|
89
|
+
}),
|
|
90
|
+
).toBe(units)
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('returns zero for empty and six-day usage histories', () => {
|
|
95
|
+
expect(
|
|
96
|
+
getAnvilStreakGlmBonusUnits({
|
|
97
|
+
todayDateKey: '2026-07-13',
|
|
98
|
+
usageDates: [],
|
|
99
|
+
}),
|
|
100
|
+
).toBe(0)
|
|
101
|
+
expect(
|
|
102
|
+
getAnvilStreakGlmBonusUnits({
|
|
103
|
+
todayDateKey: '2026-07-13',
|
|
104
|
+
usageDates: usageDatesFrom('2026-07-07', 6),
|
|
105
|
+
}),
|
|
106
|
+
).toBe(0)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('a yesterday-anchored 28-day streak earns the max through the bounded window', () => {
|
|
110
|
+
// Mirrors the web quota query, which fetches only 28 days back from today:
|
|
111
|
+
// the oldest still-active max-tier streak (today unused) must be fully
|
|
112
|
+
// visible inside that window.
|
|
113
|
+
expect(
|
|
114
|
+
getAnvilStreakGlmBonusUnits({
|
|
115
|
+
todayDateKey: addDaysToDateKey('2026-07-01', 28),
|
|
116
|
+
usageDates: usageDatesFrom('2026-07-01', 28),
|
|
117
|
+
}),
|
|
118
|
+
).toBe(4)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('refills GLM before the first use of a new week while the streak is alive', () => {
|
|
122
|
+
expect(
|
|
123
|
+
getAnvilStreakGlmBonusUnits({
|
|
124
|
+
todayDateKey: '2026-07-13',
|
|
125
|
+
usageDates: usageDatesFrom('2026-07-06', 7),
|
|
126
|
+
}),
|
|
127
|
+
).toBe(1)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('removes the live GLM entitlement after a missed full day', () => {
|
|
131
|
+
expect(
|
|
132
|
+
getAnvilStreakGlmBonusUnits({
|
|
133
|
+
todayDateKey: '2026-07-14',
|
|
134
|
+
usageDates: usageDatesFrom('2026-07-06', 7),
|
|
135
|
+
}),
|
|
136
|
+
).toBe(0)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('full access persists only the daily premium bonus', () => {
|
|
140
|
+
expect(
|
|
141
|
+
getAnvilDailyStreakRewardPool({
|
|
142
|
+
streak: 7,
|
|
143
|
+
todayUsed: true,
|
|
144
|
+
accessTier: 'full',
|
|
145
|
+
}),
|
|
146
|
+
).toBe('premium')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('full access grants the daily premium bonus throughout the streak', () => {
|
|
150
|
+
expect(
|
|
151
|
+
getAnvilDailyStreakRewardPool({
|
|
152
|
+
streak: 8,
|
|
153
|
+
todayUsed: true,
|
|
154
|
+
accessTier: 'full',
|
|
155
|
+
}),
|
|
156
|
+
).toBe('premium')
|
|
157
|
+
expect(
|
|
158
|
+
getAnvilDailyStreakRewardPool({
|
|
159
|
+
streak: 13,
|
|
160
|
+
todayUsed: true,
|
|
161
|
+
accessTier: 'full',
|
|
162
|
+
}),
|
|
163
|
+
).toBe('premium')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('limited access grants the limited bonus every day at streak >= 7', () => {
|
|
167
|
+
// The threshold day and later days both grant the bonus.
|
|
168
|
+
expect(
|
|
169
|
+
getAnvilDailyStreakRewardPool({
|
|
170
|
+
streak: 14,
|
|
171
|
+
todayUsed: true,
|
|
172
|
+
accessTier: 'limited',
|
|
173
|
+
}),
|
|
174
|
+
).toBe('limited')
|
|
175
|
+
expect(
|
|
176
|
+
getAnvilDailyStreakRewardPool({
|
|
177
|
+
streak: 9,
|
|
178
|
+
todayUsed: true,
|
|
179
|
+
accessTier: 'limited',
|
|
180
|
+
}),
|
|
181
|
+
).toBe('limited')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('no daily reward below seven days or before today is used', () => {
|
|
185
|
+
expect(
|
|
186
|
+
getAnvilDailyStreakRewardPool({
|
|
187
|
+
streak: 6,
|
|
188
|
+
todayUsed: true,
|
|
189
|
+
accessTier: 'full',
|
|
190
|
+
}),
|
|
191
|
+
).toBeNull()
|
|
192
|
+
// Streak is at 7 only because yesterday anchored it; the user hasn't used
|
|
193
|
+
// Anvil today, so no bonus is earned yet.
|
|
194
|
+
expect(
|
|
195
|
+
getAnvilDailyStreakRewardPool({
|
|
196
|
+
streak: 7,
|
|
197
|
+
todayUsed: false,
|
|
198
|
+
accessTier: 'full',
|
|
199
|
+
}),
|
|
200
|
+
).toBeNull()
|
|
201
|
+
})
|
|
202
|
+
})
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildAnvilUsageGrid,
|
|
5
|
+
buildAnvilUsageSummary,
|
|
6
|
+
calculateLongestAnvilStreak,
|
|
7
|
+
} from '../anvil-usage-summary'
|
|
8
|
+
|
|
9
|
+
describe('calculateLongestAnvilStreak', () => {
|
|
10
|
+
it('finds the longest run rather than the most recent one', () => {
|
|
11
|
+
expect(
|
|
12
|
+
calculateLongestAnvilStreak([
|
|
13
|
+
'2026-08-01',
|
|
14
|
+
'2026-08-02',
|
|
15
|
+
'2026-08-03',
|
|
16
|
+
'2026-08-04',
|
|
17
|
+
// gap
|
|
18
|
+
'2026-08-10',
|
|
19
|
+
'2026-08-11',
|
|
20
|
+
]),
|
|
21
|
+
).toBe(4)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('does not extend a run across a gap, unlike the current streak', () => {
|
|
25
|
+
// The current streak deliberately survives "used yesterday, not yet today"
|
|
26
|
+
// because the day is not over. A historical run has no such grace.
|
|
27
|
+
expect(calculateLongestAnvilStreak(['2026-08-01', '2026-08-03'])).toBe(1)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('counts each day once when the input repeats or arrives unsorted', () => {
|
|
31
|
+
expect(
|
|
32
|
+
calculateLongestAnvilStreak([
|
|
33
|
+
'2026-08-03',
|
|
34
|
+
'2026-08-01',
|
|
35
|
+
'2026-08-02',
|
|
36
|
+
'2026-08-02',
|
|
37
|
+
]),
|
|
38
|
+
).toBe(3)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('is zero with no history', () => {
|
|
42
|
+
expect(calculateLongestAnvilStreak([])).toBe(0)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('handles a run across a month boundary', () => {
|
|
46
|
+
expect(
|
|
47
|
+
calculateLongestAnvilStreak([
|
|
48
|
+
'2026-07-30',
|
|
49
|
+
'2026-07-31',
|
|
50
|
+
'2026-08-01',
|
|
51
|
+
]),
|
|
52
|
+
).toBe(3)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('buildAnvilUsageSummary', () => {
|
|
57
|
+
const activeDates = ['2026-08-10', '2026-08-11', '2026-08-12']
|
|
58
|
+
|
|
59
|
+
it('reports the current and longest streak together', () => {
|
|
60
|
+
const summary = buildAnvilUsageSummary({
|
|
61
|
+
activeDates: [
|
|
62
|
+
// A four-day run that has since lapsed...
|
|
63
|
+
'2026-07-01',
|
|
64
|
+
'2026-07-02',
|
|
65
|
+
'2026-07-03',
|
|
66
|
+
'2026-07-04',
|
|
67
|
+
// ...and a shorter one running right now.
|
|
68
|
+
'2026-08-11',
|
|
69
|
+
'2026-08-12',
|
|
70
|
+
],
|
|
71
|
+
todayDateKey: '2026-08-12',
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(summary.streak.current).toBe(2)
|
|
75
|
+
expect(summary.streak.longest).toBe(4)
|
|
76
|
+
expect(summary.streak.todayUsed).toBe(true)
|
|
77
|
+
expect(summary.streak.lastUsageDate).toBe('2026-08-12')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('counts all-time active days regardless of the map window', () => {
|
|
81
|
+
const summary = buildAnvilUsageSummary({
|
|
82
|
+
activeDates,
|
|
83
|
+
todayDateKey: '2026-08-12',
|
|
84
|
+
windowDays: 2,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// The window covers 08-11 and 08-12; 08-10 falls outside it but still
|
|
88
|
+
// counts toward the account's history.
|
|
89
|
+
expect(summary.activeDates).toEqual(['2026-08-11', '2026-08-12'])
|
|
90
|
+
expect(summary.allTimeActiveDays).toBe(3)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('drops days after today rather than letting a fast clock inflate totals', () => {
|
|
94
|
+
const summary = buildAnvilUsageSummary({
|
|
95
|
+
activeDates: [...activeDates, '2026-08-13'],
|
|
96
|
+
todayDateKey: '2026-08-12',
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
expect(summary.allTimeActiveDays).toBe(3)
|
|
100
|
+
expect(summary.streak.lastUsageDate).toBe('2026-08-12')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('sorts and dedupes unordered input before walking the streak', () => {
|
|
104
|
+
const summary = buildAnvilUsageSummary({
|
|
105
|
+
activeDates: ['2026-08-12', '2026-08-10', '2026-08-11', '2026-08-11'],
|
|
106
|
+
todayDateKey: '2026-08-12',
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
expect(summary.streak.current).toBe(3)
|
|
110
|
+
expect(summary.activeDates).toEqual(activeDates)
|
|
111
|
+
expect(summary.allTimeActiveDays).toBe(3)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('carries a null recent window through rather than inventing zeros', () => {
|
|
115
|
+
// The token aggregate caps itself with a statement timeout; a timeout must
|
|
116
|
+
// read as "unknown" downstream, never as "you sent nothing".
|
|
117
|
+
const summary = buildAnvilUsageSummary({
|
|
118
|
+
activeDates,
|
|
119
|
+
todayDateKey: '2026-08-12',
|
|
120
|
+
recent: null,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
expect(summary.recent).toBeNull()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('passes the recent window through when it resolved', () => {
|
|
127
|
+
const summary = buildAnvilUsageSummary({
|
|
128
|
+
activeDates,
|
|
129
|
+
todayDateKey: '2026-08-12',
|
|
130
|
+
recent: {
|
|
131
|
+
days: 7,
|
|
132
|
+
messages: 12,
|
|
133
|
+
inputTokens: 300,
|
|
134
|
+
cacheReadTokens: 50,
|
|
135
|
+
outputTokens: 50,
|
|
136
|
+
totalTokens: 400,
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
expect(summary.recent?.messages).toBe(12)
|
|
141
|
+
expect(summary.recent?.totalTokens).toBe(400)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('buildAnvilUsageGrid', () => {
|
|
146
|
+
// 2026-08-12 is a Wednesday (weekday 3).
|
|
147
|
+
const todayDateKey = '2026-08-12'
|
|
148
|
+
const todayWeekday = 3
|
|
149
|
+
|
|
150
|
+
it('pads to whole weeks so every row is one weekday', () => {
|
|
151
|
+
const grid = buildAnvilUsageGrid({
|
|
152
|
+
activeDates: [],
|
|
153
|
+
todayDateKey,
|
|
154
|
+
windowDays: 365,
|
|
155
|
+
todayWeekday,
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
expect(grid.length % 7).toBe(0)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('places today at its own weekday in the final column', () => {
|
|
162
|
+
const grid = buildAnvilUsageGrid({
|
|
163
|
+
activeDates: [],
|
|
164
|
+
todayDateKey,
|
|
165
|
+
windowDays: 365,
|
|
166
|
+
todayWeekday,
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const lastColumn = grid.slice(grid.length - 7)
|
|
170
|
+
expect(lastColumn[todayWeekday]).toMatchObject({ date: todayDateKey })
|
|
171
|
+
// Everything after today in the final column is padding, not a quiet day —
|
|
172
|
+
// those dates have not happened yet.
|
|
173
|
+
expect(lastColumn.slice(todayWeekday + 1).every((cell) => cell === null)).toBe(
|
|
174
|
+
true,
|
|
175
|
+
)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('marks active days and fills the rest as quiet', () => {
|
|
179
|
+
const grid = buildAnvilUsageGrid({
|
|
180
|
+
activeDates: ['2026-08-11'],
|
|
181
|
+
todayDateKey,
|
|
182
|
+
windowDays: 3,
|
|
183
|
+
todayWeekday,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const cells = grid.filter((cell) => cell !== null)
|
|
187
|
+
expect(cells).toEqual([
|
|
188
|
+
{ date: '2026-08-10', active: false },
|
|
189
|
+
{ date: '2026-08-11', active: true },
|
|
190
|
+
{ date: '2026-08-12', active: false },
|
|
191
|
+
])
|
|
192
|
+
})
|
|
193
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
5
|
+
getAxiomOnlyLogEvent,
|
|
6
|
+
STREAM_RECOVERY_EVENT,
|
|
7
|
+
} from '../axiom-only-log'
|
|
8
|
+
|
|
9
|
+
describe('getAxiomOnlyLogEvent', () => {
|
|
10
|
+
test('sanitizes context-pruning metadata', () => {
|
|
11
|
+
expect(
|
|
12
|
+
getAxiomOnlyLogEvent({
|
|
13
|
+
axiomEvent: CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
14
|
+
trigger_reason: 'context_limit',
|
|
15
|
+
client_session_id: 'turn-123',
|
|
16
|
+
dropped_user_entry_count: 2,
|
|
17
|
+
live_user_prompt_text_preserved: true,
|
|
18
|
+
prompt: 'must not leave the client',
|
|
19
|
+
nested: { secret: true },
|
|
20
|
+
context_token_count: Number.POSITIVE_INFINITY,
|
|
21
|
+
}),
|
|
22
|
+
).toEqual({
|
|
23
|
+
event: CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
24
|
+
data: {
|
|
25
|
+
trigger_reason: 'context_limit',
|
|
26
|
+
client_session_id: 'turn-123',
|
|
27
|
+
dropped_user_entry_count: 2,
|
|
28
|
+
live_user_prompt_text_preserved: true,
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('does not treat arbitrary events as Axiom-only', () => {
|
|
34
|
+
expect(
|
|
35
|
+
getAxiomOnlyLogEvent({
|
|
36
|
+
axiomEvent: 'untrusted.event',
|
|
37
|
+
prompt: 'secret',
|
|
38
|
+
}),
|
|
39
|
+
).toBeNull()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('does not treat an Object.prototype property name as a registered event', () => {
|
|
43
|
+
// The event name is caller-supplied (any logger.*(data, msg) call sets
|
|
44
|
+
// `data.axiomEvent`). Guards against ever matching it with a lookup keyed
|
|
45
|
+
// on that name (e.g. a plain-object registry), where 'constructor' would
|
|
46
|
+
// resolve through the prototype chain and get treated as registered —
|
|
47
|
+
// shipping `{}` in place of the log's real payload. Must be rejected like
|
|
48
|
+
// any other unknown event, via both the data-field and event-param path.
|
|
49
|
+
for (const poisonEvent of [
|
|
50
|
+
'constructor',
|
|
51
|
+
'toString',
|
|
52
|
+
'hasOwnProperty',
|
|
53
|
+
'valueOf',
|
|
54
|
+
'__proto__',
|
|
55
|
+
]) {
|
|
56
|
+
expect(
|
|
57
|
+
getAxiomOnlyLogEvent({
|
|
58
|
+
axiomEvent: poisonEvent,
|
|
59
|
+
prompt: 'must not be silently dropped',
|
|
60
|
+
}),
|
|
61
|
+
).toBeNull()
|
|
62
|
+
expect(
|
|
63
|
+
getAxiomOnlyLogEvent({ prompt: 'must not be silently dropped' }, poisonEvent),
|
|
64
|
+
).toBeNull()
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('sanitizes the client wire format identified by its top-level event', () => {
|
|
69
|
+
expect(
|
|
70
|
+
getAxiomOnlyLogEvent(
|
|
71
|
+
{
|
|
72
|
+
dropped_user_entry_count: 2,
|
|
73
|
+
prompt: 'must not reach Axiom',
|
|
74
|
+
},
|
|
75
|
+
CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
76
|
+
),
|
|
77
|
+
).toEqual({
|
|
78
|
+
event: CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
79
|
+
data: { dropped_user_entry_count: 2 },
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('accepts an allowlisted top-level event with empty data', () => {
|
|
84
|
+
expect(getAxiomOnlyLogEvent(null, CONTEXT_PRUNING_COMPLETED_EVENT)).toEqual(
|
|
85
|
+
{
|
|
86
|
+
event: CONTEXT_PRUNING_COMPLETED_EVENT,
|
|
87
|
+
data: {},
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('sanitizes stream-recovery metadata', () => {
|
|
93
|
+
expect(
|
|
94
|
+
getAxiomOnlyLogEvent({
|
|
95
|
+
axiomEvent: STREAM_RECOVERY_EVENT,
|
|
96
|
+
metric: 'stream_recovery_detected',
|
|
97
|
+
source: 'stream-interrupted',
|
|
98
|
+
model: 'openrouter/anthropic/claude-sonnet-4.5',
|
|
99
|
+
agentId: 'base2',
|
|
100
|
+
runId: 'run-123',
|
|
101
|
+
userInputId: 'input-456',
|
|
102
|
+
finishReason: 'unknown',
|
|
103
|
+
hasYieldedContent: true,
|
|
104
|
+
consecutive: 2,
|
|
105
|
+
// Not in the allowlist: must not leak through.
|
|
106
|
+
userId: 'user-789',
|
|
107
|
+
message: 'must not leave the client',
|
|
108
|
+
messageHistory: [{ role: 'user', content: 'secret' }],
|
|
109
|
+
}),
|
|
110
|
+
).toEqual({
|
|
111
|
+
event: STREAM_RECOVERY_EVENT,
|
|
112
|
+
data: {
|
|
113
|
+
metric: 'stream_recovery_detected',
|
|
114
|
+
source: 'stream-interrupted',
|
|
115
|
+
model: 'openrouter/anthropic/claude-sonnet-4.5',
|
|
116
|
+
agentId: 'base2',
|
|
117
|
+
runId: 'run-123',
|
|
118
|
+
userInputId: 'input-456',
|
|
119
|
+
finishReason: 'unknown',
|
|
120
|
+
hasYieldedContent: true,
|
|
121
|
+
consecutive: 2,
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('drops a stream-recovery field with the wrong value type', () => {
|
|
127
|
+
// consecutive must be a number; a string value for it (or any other
|
|
128
|
+
// type mismatch) is dropped rather than coerced.
|
|
129
|
+
expect(
|
|
130
|
+
getAxiomOnlyLogEvent({
|
|
131
|
+
axiomEvent: STREAM_RECOVERY_EVENT,
|
|
132
|
+
metric: 'stream_recovery_rescued',
|
|
133
|
+
consecutive: '2',
|
|
134
|
+
}),
|
|
135
|
+
).toEqual({
|
|
136
|
+
event: STREAM_RECOVERY_EVENT,
|
|
137
|
+
data: { metric: 'stream_recovery_rescued' },
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})
|