@alumbwe/anvil 1.0.42 → 1.0.49

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.
Files changed (238) hide show
  1. package/bin/anvil.js +18 -0
  2. package/package.json +13 -6
  3. package/src/agents/bundled-agents.generated.ts +1 -1
  4. package/src/index.tsx +27 -4
  5. package/src/login/plain-login.ts +60 -0
  6. package/src/login/supabase-auth.ts +346 -0
  7. package/src/utils/anvil-client.ts +4 -0
  8. package/src/utils/auth.ts +16 -4
  9. package/src/utils/config-dir.ts +1 -1
  10. package/vendor/@anvil/common/src/constants/deepseek-direct.ts +30 -1
  11. package/vendor/@anvil/common/src/util/project-ignore.ts +4 -3
  12. package/vendor/@anvil/sdk/dist/index.cjs +46 -10
  13. package/vendor/@anvil/sdk/dist/index.mjs +46 -10
  14. package/src/commands/__tests__/anvil-command-aliases.test.ts +0 -56
  15. package/src/commands/__tests__/bash-command.test.ts +0 -445
  16. package/src/commands/__tests__/command-args.test.ts +0 -349
  17. package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
  18. package/src/commands/__tests__/copy-conversation.test.ts +0 -226
  19. package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
  20. package/src/commands/__tests__/image.test.ts +0 -99
  21. package/src/commands/__tests__/init.test.ts +0 -456
  22. package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
  23. package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
  24. package/src/commands/__tests__/prompt-builders.test.ts +0 -28
  25. package/src/commands/__tests__/router-input.test.ts +0 -298
  26. package/src/components/__tests__/ad-banner.test.tsx +0 -83
  27. package/src/components/__tests__/anvil-landing-heading-row.test.tsx +0 -91
  28. package/src/components/__tests__/anvil-model-selector.test.tsx +0 -519
  29. package/src/components/__tests__/anvil-offer-invariants.test.ts +0 -54
  30. package/src/components/__tests__/anvil-takeover-prompt.test.tsx +0 -212
  31. package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
  32. package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
  33. package/src/components/__tests__/grid-layout.test.tsx +0 -1051
  34. package/src/components/__tests__/message-block.completion.test.tsx +0 -104
  35. package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
  36. package/src/components/__tests__/message-with-agents.test.tsx +0 -579
  37. package/src/components/__tests__/multiline-input.test.tsx +0 -1132
  38. package/src/components/__tests__/queue-panel.test.tsx +0 -398
  39. package/src/components/__tests__/selectable-list.test.ts +0 -232
  40. package/src/components/__tests__/status-bar.test.tsx +0 -44
  41. package/src/components/__tests__/status-indicator.test.tsx +0 -204
  42. package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
  43. package/src/components/__tests__/user-error-banner.test.tsx +0 -102
  44. package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
  45. package/src/components/ask-user/__tests__/validation.test.ts +0 -213
  46. package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
  47. package/src/components/tools/__tests__/code-search.test.tsx +0 -45
  48. package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
  49. package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
  50. package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
  51. package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
  52. package/src/data/slash-commands.test.ts +0 -24
  53. package/src/hooks/__tests__/holds-live-anvil-slot.test.ts +0 -49
  54. package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
  55. package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
  56. package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
  57. package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
  58. package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
  59. package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
  60. package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
  61. package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
  62. package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
  63. package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
  64. package/src/hooks/__tests__/use-input-history.test.ts +0 -699
  65. package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
  66. package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
  67. package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
  68. package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
  69. package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
  70. package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
  71. package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
  72. package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
  73. package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
  74. package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
  75. package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
  76. package/src/hooks/__tests__/use-timeout.test.ts +0 -330
  77. package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
  78. package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
  79. package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
  80. package/src/init/__tests__/init-direnv.test.ts +0 -526
  81. package/src/state/__tests__/chat-store-focus.test.ts +0 -22
  82. package/src/state/__tests__/feedback-store.test.ts +0 -257
  83. package/src/utils/__tests__/active-run.test.ts +0 -140
  84. package/src/utils/__tests__/activity-tracker.test.ts +0 -440
  85. package/src/utils/__tests__/agent-display.test.ts +0 -139
  86. package/src/utils/__tests__/analytics-client.test.ts +0 -262
  87. package/src/utils/__tests__/anonymous-id.test.ts +0 -74
  88. package/src/utils/__tests__/anvil-api.test.ts +0 -578
  89. package/src/utils/__tests__/anvil-instance-owner.test.ts +0 -69
  90. package/src/utils/__tests__/anvil-model-navigation.test.ts +0 -102
  91. package/src/utils/__tests__/anvil-premium-reset.test.ts +0 -79
  92. package/src/utils/__tests__/anvil-referral-cache.test.ts +0 -116
  93. package/src/utils/__tests__/anvil-session-api.test.ts +0 -215
  94. package/src/utils/__tests__/anvil-session-display.test.ts +0 -23
  95. package/src/utils/__tests__/anvil-streak-line.test.ts +0 -217
  96. package/src/utils/__tests__/arrays.test.ts +0 -264
  97. package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
  98. package/src/utils/__tests__/block-processor.test.ts +0 -810
  99. package/src/utils/__tests__/chat-history.test.ts +0 -203
  100. package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
  101. package/src/utils/__tests__/chat-meta.test.ts +0 -130
  102. package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
  103. package/src/utils/__tests__/clipboard.test.ts +0 -910
  104. package/src/utils/__tests__/code-search-summary.test.ts +0 -84
  105. package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
  106. package/src/utils/__tests__/error-handling.test.ts +0 -658
  107. package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
  108. package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
  109. package/src/utils/__tests__/feedback-submission.test.ts +0 -26
  110. package/src/utils/__tests__/fetch-usage.test.ts +0 -355
  111. package/src/utils/__tests__/fingerprint.test.ts +0 -144
  112. package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
  113. package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
  114. package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
  115. package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
  116. package/src/utils/__tests__/format-timeout.test.ts +0 -87
  117. package/src/utils/__tests__/image-dimensions.test.ts +0 -249
  118. package/src/utils/__tests__/image-processor.test.ts +0 -209
  119. package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
  120. package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
  121. package/src/utils/__tests__/layout-helpers.test.ts +0 -36
  122. package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
  123. package/src/utils/__tests__/log-shipper.test.ts +0 -53
  124. package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
  125. package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
  126. package/src/utils/__tests__/message-updater.test.ts +0 -645
  127. package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
  128. package/src/utils/__tests__/pending-attachments.test.ts +0 -277
  129. package/src/utils/__tests__/polling-backoff.test.ts +0 -51
  130. package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
  131. package/src/utils/__tests__/run-state-storage.test.ts +0 -919
  132. package/src/utils/__tests__/safe-json.test.ts +0 -77
  133. package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
  134. package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
  135. package/src/utils/__tests__/send-message-timer.test.ts +0 -64
  136. package/src/utils/__tests__/settings.test.ts +0 -99
  137. package/src/utils/__tests__/strings.test.ts +0 -192
  138. package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
  139. package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
  140. package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
  141. package/src/utils/__tests__/terminal-io.test.ts +0 -137
  142. package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
  143. package/src/utils/__tests__/text-layout.test.ts +0 -82
  144. package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
  145. package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
  146. package/src/utils/__tests__/trace-writer.test.ts +0 -223
  147. package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
  148. package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
  149. package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
  150. package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
  151. package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
  152. package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +0 -846
  153. package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +0 -101
  154. package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +0 -1408
  155. package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +0 -258
  156. package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +0 -48
  157. package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +0 -282
  158. package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +0 -526
  159. package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +0 -68
  160. package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +0 -132
  161. package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -422
  162. package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +0 -167
  163. package/vendor/@anvil/common/src/__tests__/env-process.test.ts +0 -145
  164. package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +0 -234
  165. package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +0 -379
  166. package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +0 -807
  167. package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +0 -154
  168. package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +0 -246
  169. package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +0 -77
  170. package/vendor/@anvil/common/src/__tests__/model-config.test.ts +0 -89
  171. package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +0 -298
  172. package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +0 -116
  173. package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +0 -167
  174. package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +0 -132
  175. package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +0 -72
  176. package/vendor/@anvil/common/src/__tests__/user-state.test.ts +0 -30
  177. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +0 -63
  178. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +0 -246
  179. package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +0 -106
  180. package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +0 -351
  181. package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +0 -169
  182. package/vendor/@anvil/common/src/testing/errors.ts +0 -33
  183. package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +0 -334
  184. package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +0 -6
  185. package/vendor/@anvil/common/src/testing/index.ts +0 -84
  186. package/vendor/@anvil/common/src/testing/mock-modules.ts +0 -53
  187. package/vendor/@anvil/common/src/testing/mock-types.ts +0 -123
  188. package/vendor/@anvil/common/src/testing/mocks/analytics.ts +0 -261
  189. package/vendor/@anvil/common/src/testing/mocks/child-process.ts +0 -93
  190. package/vendor/@anvil/common/src/testing/mocks/crypto.ts +0 -218
  191. package/vendor/@anvil/common/src/testing/mocks/database.ts +0 -337
  192. package/vendor/@anvil/common/src/testing/mocks/fetch.ts +0 -219
  193. package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +0 -166
  194. package/vendor/@anvil/common/src/testing/mocks/index.ts +0 -101
  195. package/vendor/@anvil/common/src/testing/mocks/logger.ts +0 -135
  196. package/vendor/@anvil/common/src/testing/mocks/stream.ts +0 -313
  197. package/vendor/@anvil/common/src/testing/mocks/timers.ts +0 -132
  198. package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +0 -127
  199. package/vendor/@anvil/common/src/testing/setup.ts +0 -282
  200. package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
  201. package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -213
  202. package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +0 -47
  203. package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +0 -65
  204. package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +0 -49
  205. package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
  206. package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +0 -26
  207. package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -122
  208. package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +0 -102
  209. package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +0 -143
  210. package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +0 -202
  211. package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +0 -193
  212. package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +0 -140
  213. package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +0 -148
  214. package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
  215. package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +0 -57
  216. package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +0 -774
  217. package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +0 -206
  218. package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +0 -173
  219. package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +0 -60
  220. package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +0 -31
  221. package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +0 -1252
  222. package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
  223. package/vendor/@anvil/common/src/util/__tests__/path.test.ts +0 -22
  224. package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +0 -90
  225. package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +0 -325
  226. package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +0 -28
  227. package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +0 -130
  228. package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +0 -1008
  229. package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +0 -289
  230. package/vendor/@anvil/common/src/util/__tests__/string.test.ts +0 -239
  231. package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +0 -70
  232. package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +0 -108
  233. package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +0 -180
  234. package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +0 -24
  235. package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +0 -88
  236. package/vendor/@anvil/common/src/util/skills.test.ts +0 -44
  237. package/vendor/@anvil/sdk/dist/index.cjs.map +0 -440
  238. package/vendor/@anvil/sdk/dist/index.mjs.map +0 -440
@@ -1,379 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import {
4
- detectForeignAnvilClient,
5
- ANVIL_DOWNGRADE_MODEL_ID,
6
- ANVIL_SIGNATURE_TOOL_NAMES,
7
- GENERIC_TOOL_NAMES,
8
- resolveForeignClientDowngrade,
9
- } from '../constants/foreign-client-signals'
10
- import { toolNames } from '../tools/constants'
11
-
12
- function tools(...names: string[]) {
13
- return names.map((name) => ({ type: 'function', function: { name } }))
14
- }
15
-
16
- /** Toolsets observed on real anvil traffic over 24h of DeepSeek V4 Flash. */
17
- const ANVIL_TOOLSETS = [
18
- // CLI / desktop root agent
19
- tools(
20
- 'ask_user',
21
- 'basher',
22
- 'browser_use',
23
- 'code_reviewer_deepseek_flash',
24
- 'code_searcher',
25
- 'context_pruner',
26
- 'file_picker',
27
- 'glob',
28
- 'gravity_index',
29
- 'list_directory',
30
- 'read_files',
31
- 'read_subtree',
32
- ),
33
- // desktop thread agent
34
- tools(
35
- 'basher',
36
- 'browser_check',
37
- 'code_reviewer_deepseek_flash',
38
- 'code_searcher',
39
- 'context_pruner',
40
- 'end_turn',
41
- 'file_picker',
42
- 'glob',
43
- 'list_directory',
44
- 'preview_click',
45
- 'preview_evaluate',
46
- ),
47
- // chat surface
48
- tools(
49
- 'context_pruner',
50
- 'gravity_index',
51
- 'render_ui',
52
- 'researcher_web',
53
- 'spawn_agents',
54
- 'suggest_followups',
55
- 'thinker_gemini',
56
- ),
57
- // helper agent
58
- tools('add_message', 'read_files', 'run_terminal_command', 'set_output'),
59
- ]
60
-
61
- /** Toolsets observed proxying our free endpoint, by harness. */
62
- const FOREIGN_TOOLSETS: Array<[string, ReturnType<typeof tools>]> = [
63
- ['claude-code', tools('Bash', 'Edit', 'Glob', 'Grep', 'Read', 'Write')],
64
- [
65
- 'opencode',
66
- tools(
67
- 'ask',
68
- 'bash',
69
- 'edit',
70
- 'eval',
71
- 'glob',
72
- 'grep',
73
- 'hub',
74
- 'read',
75
- 'task',
76
- 'todo',
77
- 'web_search',
78
- 'write',
79
- ),
80
- ],
81
- [
82
- 'cline',
83
- tools(
84
- 'list_files',
85
- 'read_file',
86
- 'replace_in_file',
87
- 'search_files',
88
- 'write_file',
89
- ),
90
- ],
91
- [
92
- 'novel-farm',
93
- tools(
94
- 'check_consistency',
95
- 'commit_chapter',
96
- 'draft_chapter',
97
- 'edit_chapter',
98
- 'novel_context',
99
- 'plan_chapter',
100
- 'read_chapter',
101
- ),
102
- ],
103
- [
104
- 'pentest-harness',
105
- tools(
106
- 'analyze_target_graph',
107
- 'delegate_task',
108
- 'edit_source_code',
109
- 'execute_command',
110
- 'install_tool',
111
- 'python_execute',
112
- 'read_file',
113
- ),
114
- ],
115
- ]
116
-
117
- describe('detectForeignAnvilClient', () => {
118
- test('the signature is every non-generic tool we define', () => {
119
- // Derived, not hand-listed: a tool added to `toolNames` joins the signature
120
- // automatically. That is the rot that flagged researcher-web — a
121
- // hand-picked list simply never grew to cover it.
122
- const known = new Set<string>(toolNames)
123
- for (const name of known) {
124
- expect(ANVIL_SIGNATURE_TOOL_NAMES.has(name)).toBe(
125
- !GENERIC_TOOL_NAMES.has(name),
126
- )
127
- }
128
- // Every generic name must be one we actually define, or it is dead weight.
129
- for (const name of GENERIC_TOOL_NAMES) {
130
- expect(known.has(name)).toBe(true)
131
- }
132
- expect(ANVIL_SIGNATURE_TOOL_NAMES.size).toBeGreaterThan(20)
133
- })
134
-
135
- test('clears real anvil toolsets', () => {
136
- for (const toolset of ANVIL_TOOLSETS) {
137
- expect(detectForeignAnvilClient({ tools: toolset }).signal).toBeNull()
138
- }
139
- })
140
-
141
- test.each(FOREIGN_TOOLSETS)('flags %s', (_name, toolset) => {
142
- expect(detectForeignAnvilClient({ tools: toolset }).signal).toBe(
143
- 'foreign_toolset',
144
- )
145
- })
146
-
147
- test('sharing a few generic names does not launder a foreign harness', () => {
148
- // opencode sends `glob` and `web_search`, which we define — but both are
149
- // generic, so neither is in the signature and the overlap buys it nothing.
150
- expect(
151
- detectForeignAnvilClient({
152
- tools: tools('glob', 'web_search', 'bash', 'edit', 'write'),
153
- }).signal,
154
- ).toBe('foreign_toolset')
155
- })
156
-
157
- test('a toolset of only generic names is foreign', () => {
158
- // Measured over 30 days: 406 users on spoofed `base2-free-*` agent ids send
159
- // a bare `web_search` and nothing else. No agent we ship has a toolset of
160
- // only generic names — every single-tool agent of ours uses a distinctive
161
- // one (`run_terminal_command`, `spawn_agents`, `read_docs`, `set_output`).
162
- expect(
163
- detectForeignAnvilClient({ tools: tools('web_search') }).signal,
164
- ).toBe('foreign_toolset')
165
- expect(
166
- detectForeignAnvilClient({ tools: tools('glob', 'web_search') }).signal,
167
- ).toBe('foreign_toolset')
168
- })
169
-
170
- test('our toolset wins over sampling params', () => {
171
- // 16 users in one day sent our tools AND set params. Downgrading them is
172
- // the false positive this ordering exists to prevent.
173
- expect(
174
- detectForeignAnvilClient({
175
- tools: tools('ask_user', 'read_files'),
176
- temperature: 0.3,
177
- max_tokens: 32000,
178
- }).signal,
179
- ).toBeNull()
180
- })
181
-
182
- test('flags sampling params only when no tools are offered', () => {
183
- expect(detectForeignAnvilClient({ temperature: 0.7 }).signal).toBe(
184
- 'sampling_params',
185
- )
186
- expect(detectForeignAnvilClient({ top_p: 0.9 }).signal).toBe(
187
- 'sampling_params',
188
- )
189
- expect(detectForeignAnvilClient({ max_tokens: 4096 }).signal).toBe(
190
- 'sampling_params',
191
- )
192
- expect(
193
- detectForeignAnvilClient({ max_completion_tokens: 4096 }).signal,
194
- ).toBe('sampling_params')
195
- })
196
-
197
- test('clears a tool-free request that leaves sampling params unset', () => {
198
- // Our helper agents (chat titles, compaction) send no tools at all.
199
- expect(detectForeignAnvilClient({}).signal).toBeNull()
200
- expect(detectForeignAnvilClient({ tools: [] }).signal).toBeNull()
201
- })
202
-
203
- test('explicit nulls are not treated as set', () => {
204
- // Regression: this test used to pass `undefined` while claiming to cover
205
- // `null`, so it passed against a detector that flagged every explicit
206
- // null. A client that serializes its whole body sends `temperature: null`
207
- // rather than omitting the key, and that is unset.
208
- for (const body of [
209
- { temperature: null },
210
- { top_p: null },
211
- { max_tokens: null },
212
- { max_completion_tokens: null },
213
- { temperature: null, top_p: null, max_tokens: null },
214
- ]) {
215
- expect(detectForeignAnvilClient(body as never).signal).toBeNull()
216
- }
217
- expect(
218
- detectForeignAnvilClient({
219
- temperature: undefined,
220
- top_p: undefined,
221
- max_tokens: undefined,
222
- }).signal,
223
- ).toBeNull()
224
- })
225
-
226
- test('zero is a real choice and stays flagged', () => {
227
- // `!= null` must not swallow falsy-but-set values.
228
- expect(detectForeignAnvilClient({ temperature: 0 }).signal).toBe(
229
- 'sampling_params',
230
- )
231
- expect(detectForeignAnvilClient({ top_p: 0 }).signal).toBe(
232
- 'sampling_params',
233
- )
234
- })
235
-
236
- test('tolerates malformed tool entries without throwing', () => {
237
- for (const tools of [null, undefined, 'nope', [], [null], [{}], [{ function: {} }]]) {
238
- expect(() =>
239
- detectForeignAnvilClient({ tools } as never),
240
- ).not.toThrow()
241
- }
242
- // Tools present but unparseable read as "no tools offered", so the request
243
- // falls through to the param check rather than being flagged on a name
244
- // list we could not actually read.
245
- expect(detectForeignAnvilClient({ tools: [{}] }).signal).toBeNull()
246
- })
247
-
248
- test('truncates caller-controlled tool names before they reach logs', () => {
249
- const verdict = detectForeignAnvilClient({
250
- tools: [{ type: 'function', function: { name: 'x'.repeat(5000) } }],
251
- })
252
- expect(verdict.signal).toBe('foreign_toolset')
253
- expect(verdict.sampleToolNames[0]!.length).toBeLessThanOrEqual(64)
254
- })
255
-
256
- test('reports bounded evidence for the log line', () => {
257
- const verdict = detectForeignAnvilClient({
258
- tools: tools('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
259
- })
260
- expect(verdict.toolCount).toBe(10)
261
- expect(verdict.sampleToolNames).toHaveLength(8)
262
- })
263
-
264
- test.each([
265
- ['researcher-web', ['web_search', 'read_url']],
266
- ['researcher-docs', ['read_docs']],
267
- ['anvil-desktop-autorun', ['decide']],
268
- ['basher', ['run_terminal_command']],
269
- ['file-picker', ['spawn_agents']],
270
- ])('clears our own %s toolset', (_agent, names) => {
271
- // Backtested over 30 days against the signature alone: researcher-web was
272
- // flagged on 100% of 334,042 requests from 4,821 users, autorun on 100% of
273
- // 2,904 from 41. `web_search` cannot join the signature (opencode ships
274
- // it), so these clear by the every-tool-is-ours rule instead.
275
- expect(detectForeignAnvilClient({ tools: tools(...names) }).signal).toBeNull()
276
- })
277
-
278
- test('borrowing one distinctive name clears an otherwise foreign toolset', () => {
279
- // Known and accepted, not an oversight. `some` semantics are what let an
280
- // MCP user attach `ghidra__*` alongside our tools without being flagged,
281
- // and the cost is that a proxy declaring one of our names is cleared too.
282
- // Self-limiting: the borrowed name becomes a GENERIC_TOOL_NAMES candidate
283
- // the moment it shows up in the logs, and the proxy has to actually
284
- // implement the tool for its own loop to keep working.
285
- expect(
286
- detectForeignAnvilClient({ tools: tools('read_files', 'Bash') }).signal,
287
- ).toBeNull()
288
- })
289
-
290
- test('a root agent offering no tools is a bare completion proxy', () => {
291
- // Our roots always ship their toolset — that is what makes them agentic.
292
- // Measured over 7 days with assistant-response rows excluded, the desktop
293
- // roots send zero tool-free requests (0 of 683,151 for -v3, 0 of 294,823
294
- // for -worktree) and the CLI roots 0.30%/2.81%. All 18 users sampled across
295
- // that tail were non-coding automation.
296
- expect(detectForeignAnvilClient({}, true).signal).toBe(
297
- 'root_agent_no_tools',
298
- )
299
- // Sampling params do not change the verdict for a root.
300
- expect(detectForeignAnvilClient({ temperature: 0.7 }, true).signal).toBe(
301
- 'root_agent_no_tools',
302
- )
303
- })
304
-
305
- test('a root agent sending our tools is still ours', () => {
306
- // Evading root_agent_no_tools means sending our toolset, at which point the
307
- // toolset check applies instead — the same convergent property.
308
- expect(
309
- detectForeignAnvilClient({ tools: tools('ask_user') }, true).signal,
310
- ).toBeNull()
311
- expect(
312
- detectForeignAnvilClient({ tools: tools('Bash', 'Edit') }, true).signal,
313
- ).toBe('foreign_toolset')
314
- })
315
-
316
- test('a tool-free SUBagent is untouched', () => {
317
- // Our helper agents (chat titles, compaction, researcher-docs) legitimately
318
- // send no tools; only ROOT agents are agentic by definition. Defaulting
319
- // isRootAgent to false keeps every non-root caller on the old behaviour.
320
- expect(detectForeignAnvilClient({}).signal).toBeNull()
321
- expect(detectForeignAnvilClient({}, false).signal).toBeNull()
322
- })
323
-
324
- test('downgrade target is the free OpenRouter variant', () => {
325
- expect(ANVIL_DOWNGRADE_MODEL_ID).toBe('inclusionai/ling-3.0-tiny:free')
326
- expect(ANVIL_DOWNGRADE_MODEL_ID.endsWith(':free')).toBe(true)
327
- })
328
- })
329
-
330
- describe('resolveForeignClientDowngrade', () => {
331
- const foreign = { tools: tools('Bash', 'Edit') }
332
- const params = { max_completion_tokens: 977_725 }
333
- const ours = { tools: tools('ask_user', 'read_files') }
334
-
335
- test('always downgrades a foreign toolset', () => {
336
- // Third-party clients are a terms violation: Anvil funds free inference
337
- // with ads only our own clients render, so a proxied request takes the
338
- // cost and returns none of the revenue. There is no mode in which this is
339
- // served what it asked for.
340
- expect(resolveForeignClientDowngrade({ body: foreign })!.downgradeTo).toBe(
341
- ANVIL_DOWNGRADE_MODEL_ID,
342
- )
343
- })
344
-
345
- test('reports but never acts on a tool-free root agent', () => {
346
- // Deliberately report-only. The 30-day backtest found 3,729 users who mix
347
- // tool-free root requests into real agentic traffic, 999 of whose sessions
348
- // contain both — enforcing per-request swaps the model mid-session for real
349
- // coding runs. Only 417 users are pure proxies, and no run-length threshold
350
- // separates them (the MIXED cohort holds the longest tool-free run, 11,094,
351
- // vs 2,153 for the proxies). Flipping this to enforce needs an
352
- // account-level verdict, not a change here.
353
- const d = resolveForeignClientDowngrade({ body: {}, isRootAgent: true })!
354
- expect(d.signal).toBe('root_agent_no_tools')
355
- expect(d.downgradeTo).toBeNull()
356
- })
357
-
358
- test('leaves a tool-free non-root request alone', () => {
359
- expect(resolveForeignClientDowngrade({ body: {} })).toBeNull()
360
- })
361
-
362
- test('reports but never acts on the sampling-param signal', () => {
363
- const decision = resolveForeignClientDowngrade({ body: params })!
364
- expect(decision.signal).toBe('sampling_params')
365
- expect(decision.downgradeTo).toBeNull()
366
- })
367
-
368
- test('a anvil toolset is never reported', () => {
369
- expect(resolveForeignClientDowngrade({ body: ours })).toBeNull()
370
- })
371
-
372
- test('does not re-downgrade a request already on the downgrade model', () => {
373
- const decision = resolveForeignClientDowngrade({
374
- body: { ...foreign, model: ANVIL_DOWNGRADE_MODEL_ID },
375
- })!
376
- expect(decision.signal).toBe('foreign_toolset')
377
- expect(decision.downgradeTo).toBeNull()
378
- })
379
- })