@alumbwe/anvil 1.0.41 → 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 (241) 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/entry.ts +5 -0
  5. package/src/index.tsx +27 -4
  6. package/src/login/plain-login.ts +60 -0
  7. package/src/login/supabase-auth.ts +346 -0
  8. package/src/pre-init/client-env.ts +17 -0
  9. package/src/utils/anvil-client.ts +4 -0
  10. package/src/utils/auth.ts +16 -4
  11. package/src/utils/client-env-defaults.ts +28 -0
  12. package/src/utils/config-dir.ts +1 -1
  13. package/vendor/@anvil/common/src/constants/deepseek-direct.ts +30 -1
  14. package/vendor/@anvil/common/src/util/project-ignore.ts +4 -3
  15. package/vendor/@anvil/sdk/dist/index.cjs +46 -10
  16. package/vendor/@anvil/sdk/dist/index.mjs +46 -10
  17. package/src/commands/__tests__/anvil-command-aliases.test.ts +0 -56
  18. package/src/commands/__tests__/bash-command.test.ts +0 -445
  19. package/src/commands/__tests__/command-args.test.ts +0 -349
  20. package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
  21. package/src/commands/__tests__/copy-conversation.test.ts +0 -226
  22. package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
  23. package/src/commands/__tests__/image.test.ts +0 -99
  24. package/src/commands/__tests__/init.test.ts +0 -456
  25. package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
  26. package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
  27. package/src/commands/__tests__/prompt-builders.test.ts +0 -28
  28. package/src/commands/__tests__/router-input.test.ts +0 -298
  29. package/src/components/__tests__/ad-banner.test.tsx +0 -83
  30. package/src/components/__tests__/anvil-landing-heading-row.test.tsx +0 -91
  31. package/src/components/__tests__/anvil-model-selector.test.tsx +0 -519
  32. package/src/components/__tests__/anvil-offer-invariants.test.ts +0 -54
  33. package/src/components/__tests__/anvil-takeover-prompt.test.tsx +0 -212
  34. package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
  35. package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
  36. package/src/components/__tests__/grid-layout.test.tsx +0 -1051
  37. package/src/components/__tests__/message-block.completion.test.tsx +0 -104
  38. package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
  39. package/src/components/__tests__/message-with-agents.test.tsx +0 -579
  40. package/src/components/__tests__/multiline-input.test.tsx +0 -1132
  41. package/src/components/__tests__/queue-panel.test.tsx +0 -398
  42. package/src/components/__tests__/selectable-list.test.ts +0 -232
  43. package/src/components/__tests__/status-bar.test.tsx +0 -44
  44. package/src/components/__tests__/status-indicator.test.tsx +0 -204
  45. package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
  46. package/src/components/__tests__/user-error-banner.test.tsx +0 -102
  47. package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
  48. package/src/components/ask-user/__tests__/validation.test.ts +0 -213
  49. package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
  50. package/src/components/tools/__tests__/code-search.test.tsx +0 -45
  51. package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
  52. package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
  53. package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
  54. package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
  55. package/src/data/slash-commands.test.ts +0 -24
  56. package/src/hooks/__tests__/holds-live-anvil-slot.test.ts +0 -49
  57. package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
  58. package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
  59. package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
  60. package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
  61. package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
  62. package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
  63. package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
  64. package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
  65. package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
  66. package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
  67. package/src/hooks/__tests__/use-input-history.test.ts +0 -699
  68. package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
  69. package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
  70. package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
  71. package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
  72. package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
  73. package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
  74. package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
  75. package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
  76. package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
  77. package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
  78. package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
  79. package/src/hooks/__tests__/use-timeout.test.ts +0 -330
  80. package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
  81. package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
  82. package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
  83. package/src/init/__tests__/init-direnv.test.ts +0 -526
  84. package/src/state/__tests__/chat-store-focus.test.ts +0 -22
  85. package/src/state/__tests__/feedback-store.test.ts +0 -257
  86. package/src/utils/__tests__/active-run.test.ts +0 -140
  87. package/src/utils/__tests__/activity-tracker.test.ts +0 -440
  88. package/src/utils/__tests__/agent-display.test.ts +0 -139
  89. package/src/utils/__tests__/analytics-client.test.ts +0 -262
  90. package/src/utils/__tests__/anonymous-id.test.ts +0 -74
  91. package/src/utils/__tests__/anvil-api.test.ts +0 -578
  92. package/src/utils/__tests__/anvil-instance-owner.test.ts +0 -69
  93. package/src/utils/__tests__/anvil-model-navigation.test.ts +0 -102
  94. package/src/utils/__tests__/anvil-premium-reset.test.ts +0 -79
  95. package/src/utils/__tests__/anvil-referral-cache.test.ts +0 -116
  96. package/src/utils/__tests__/anvil-session-api.test.ts +0 -215
  97. package/src/utils/__tests__/anvil-session-display.test.ts +0 -23
  98. package/src/utils/__tests__/anvil-streak-line.test.ts +0 -217
  99. package/src/utils/__tests__/arrays.test.ts +0 -264
  100. package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
  101. package/src/utils/__tests__/block-processor.test.ts +0 -810
  102. package/src/utils/__tests__/chat-history.test.ts +0 -203
  103. package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
  104. package/src/utils/__tests__/chat-meta.test.ts +0 -130
  105. package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
  106. package/src/utils/__tests__/clipboard.test.ts +0 -910
  107. package/src/utils/__tests__/code-search-summary.test.ts +0 -84
  108. package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
  109. package/src/utils/__tests__/error-handling.test.ts +0 -658
  110. package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
  111. package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
  112. package/src/utils/__tests__/feedback-submission.test.ts +0 -26
  113. package/src/utils/__tests__/fetch-usage.test.ts +0 -355
  114. package/src/utils/__tests__/fingerprint.test.ts +0 -144
  115. package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
  116. package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
  117. package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
  118. package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
  119. package/src/utils/__tests__/format-timeout.test.ts +0 -87
  120. package/src/utils/__tests__/image-dimensions.test.ts +0 -249
  121. package/src/utils/__tests__/image-processor.test.ts +0 -209
  122. package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
  123. package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
  124. package/src/utils/__tests__/layout-helpers.test.ts +0 -36
  125. package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
  126. package/src/utils/__tests__/log-shipper.test.ts +0 -53
  127. package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
  128. package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
  129. package/src/utils/__tests__/message-updater.test.ts +0 -645
  130. package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
  131. package/src/utils/__tests__/pending-attachments.test.ts +0 -277
  132. package/src/utils/__tests__/polling-backoff.test.ts +0 -51
  133. package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
  134. package/src/utils/__tests__/run-state-storage.test.ts +0 -919
  135. package/src/utils/__tests__/safe-json.test.ts +0 -77
  136. package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
  137. package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
  138. package/src/utils/__tests__/send-message-timer.test.ts +0 -64
  139. package/src/utils/__tests__/settings.test.ts +0 -99
  140. package/src/utils/__tests__/strings.test.ts +0 -192
  141. package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
  142. package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
  143. package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
  144. package/src/utils/__tests__/terminal-io.test.ts +0 -137
  145. package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
  146. package/src/utils/__tests__/text-layout.test.ts +0 -82
  147. package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
  148. package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
  149. package/src/utils/__tests__/trace-writer.test.ts +0 -223
  150. package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
  151. package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
  152. package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
  153. package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
  154. package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
  155. package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +0 -846
  156. package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +0 -101
  157. package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +0 -1408
  158. package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +0 -258
  159. package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +0 -48
  160. package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +0 -282
  161. package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +0 -526
  162. package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +0 -68
  163. package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +0 -132
  164. package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -422
  165. package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +0 -167
  166. package/vendor/@anvil/common/src/__tests__/env-process.test.ts +0 -145
  167. package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +0 -234
  168. package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +0 -379
  169. package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +0 -807
  170. package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +0 -154
  171. package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +0 -246
  172. package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +0 -77
  173. package/vendor/@anvil/common/src/__tests__/model-config.test.ts +0 -89
  174. package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +0 -298
  175. package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +0 -116
  176. package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +0 -167
  177. package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +0 -132
  178. package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +0 -72
  179. package/vendor/@anvil/common/src/__tests__/user-state.test.ts +0 -30
  180. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +0 -63
  181. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +0 -246
  182. package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +0 -106
  183. package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +0 -351
  184. package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +0 -169
  185. package/vendor/@anvil/common/src/testing/errors.ts +0 -33
  186. package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +0 -334
  187. package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +0 -6
  188. package/vendor/@anvil/common/src/testing/index.ts +0 -84
  189. package/vendor/@anvil/common/src/testing/mock-modules.ts +0 -53
  190. package/vendor/@anvil/common/src/testing/mock-types.ts +0 -123
  191. package/vendor/@anvil/common/src/testing/mocks/analytics.ts +0 -261
  192. package/vendor/@anvil/common/src/testing/mocks/child-process.ts +0 -93
  193. package/vendor/@anvil/common/src/testing/mocks/crypto.ts +0 -218
  194. package/vendor/@anvil/common/src/testing/mocks/database.ts +0 -337
  195. package/vendor/@anvil/common/src/testing/mocks/fetch.ts +0 -219
  196. package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +0 -166
  197. package/vendor/@anvil/common/src/testing/mocks/index.ts +0 -101
  198. package/vendor/@anvil/common/src/testing/mocks/logger.ts +0 -135
  199. package/vendor/@anvil/common/src/testing/mocks/stream.ts +0 -313
  200. package/vendor/@anvil/common/src/testing/mocks/timers.ts +0 -132
  201. package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +0 -127
  202. package/vendor/@anvil/common/src/testing/setup.ts +0 -282
  203. package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
  204. package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -213
  205. package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +0 -47
  206. package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +0 -65
  207. package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +0 -49
  208. package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
  209. package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +0 -26
  210. package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -122
  211. package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +0 -102
  212. package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +0 -143
  213. package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +0 -202
  214. package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +0 -193
  215. package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +0 -140
  216. package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +0 -148
  217. package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
  218. package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +0 -57
  219. package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +0 -774
  220. package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +0 -206
  221. package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +0 -173
  222. package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +0 -60
  223. package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +0 -31
  224. package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +0 -1252
  225. package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
  226. package/vendor/@anvil/common/src/util/__tests__/path.test.ts +0 -22
  227. package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +0 -90
  228. package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +0 -325
  229. package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +0 -28
  230. package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +0 -130
  231. package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +0 -1008
  232. package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +0 -289
  233. package/vendor/@anvil/common/src/util/__tests__/string.test.ts +0 -239
  234. package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +0 -70
  235. package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +0 -108
  236. package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +0 -180
  237. package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +0 -24
  238. package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +0 -88
  239. package/vendor/@anvil/common/src/util/skills.test.ts +0 -44
  240. package/vendor/@anvil/sdk/dist/index.cjs.map +0 -440
  241. package/vendor/@anvil/sdk/dist/index.mjs.map +0 -440
@@ -1,206 +0,0 @@
1
- import { describe, expect, it } from 'bun:test'
2
-
3
- import {
4
- extractApiErrorDetails,
5
- FETCH_IDLE_TIMEOUT_USER_MESSAGE,
6
- isFetchIdleTimeoutError,
7
- isTransientNetworkError,
8
- } from '../error'
9
-
10
- describe('extractApiErrorDetails', () => {
11
- it('extracts structured details from nested retry errors', () => {
12
- const apiError = new Error('Conflict') as Error & {
13
- statusCode: number
14
- responseBody: string
15
- }
16
- apiError.statusCode = 409
17
- apiError.responseBody = JSON.stringify({
18
- error: 'session_superseded',
19
- message:
20
- 'Another instance of anvil has taken over this session. Only one instance per account is allowed.',
21
- })
22
-
23
- const retryError = new Error(
24
- 'Failed after 4 attempts. Last error: Conflict',
25
- ) as Error & {
26
- lastError: unknown
27
- errors: unknown[]
28
- }
29
- retryError.name = 'AI_RetryError'
30
- retryError.lastError = apiError
31
- retryError.errors = [apiError]
32
-
33
- expect(extractApiErrorDetails(retryError)).toEqual({
34
- statusCode: 409,
35
- errorCode: 'session_superseded',
36
- message:
37
- 'Another instance of anvil has taken over this session. Only one instance per account is allowed.',
38
- })
39
- })
40
-
41
- it('extracts details from OpenAI-style nested error objects', () => {
42
- const apiError = new Error('Too Many Requests') as Error & {
43
- statusCode: number
44
- responseBody: string
45
- }
46
- apiError.statusCode = 429
47
- apiError.responseBody = JSON.stringify({
48
- error: {
49
- message: 'Model is at capacity. Please try again later.',
50
- code: null,
51
- type: 'rate_limit_error',
52
- },
53
- })
54
-
55
- expect(extractApiErrorDetails(apiError)).toEqual({
56
- statusCode: 429,
57
- errorCode: 'rate_limit_error',
58
- message: 'Model is at capacity. Please try again later.',
59
- })
60
- })
61
-
62
- it('prefers nested error code over type when both are strings', () => {
63
- const apiError = new Error('Too Many Requests') as Error & {
64
- statusCode: number
65
- responseBody: string
66
- }
67
- apiError.statusCode = 429
68
- apiError.responseBody = JSON.stringify({
69
- error: {
70
- message: 'Slow down.',
71
- code: 'rate_limited',
72
- type: 'rate_limit_error',
73
- },
74
- })
75
-
76
- expect(extractApiErrorDetails(apiError)).toEqual({
77
- statusCode: 429,
78
- errorCode: 'rate_limited',
79
- message: 'Slow down.',
80
- })
81
- })
82
-
83
- it('keeps top-level string fields when both shapes are present', () => {
84
- const apiError = new Error('Too Many Requests') as Error & {
85
- statusCode: number
86
- responseBody: string
87
- }
88
- apiError.statusCode = 429
89
- apiError.responseBody = JSON.stringify({
90
- error: 'free_mode_rate_limited',
91
- message: 'Free mode rate limit exceeded (1 minute limit).',
92
- })
93
-
94
- expect(extractApiErrorDetails(apiError)).toEqual({
95
- statusCode: 429,
96
- errorCode: 'free_mode_rate_limited',
97
- message: 'Free mode rate limit exceeded (1 minute limit).',
98
- })
99
- })
100
- })
101
-
102
- describe('isFetchIdleTimeoutError', () => {
103
- it('detects a DOMException-style TimeoutError by name', () => {
104
- const error = new Error('The operation timed out.')
105
- error.name = 'TimeoutError'
106
- expect(isFetchIdleTimeoutError(error)).toBe(true)
107
- })
108
-
109
- it('detects the Bun timeout message without the TimeoutError name', () => {
110
- expect(isFetchIdleTimeoutError(new Error('The operation timed out.'))).toBe(
111
- true,
112
- )
113
- })
114
-
115
- it('detects a timeout nested inside an AI SDK RetryError wrapper', () => {
116
- const timeoutError = new Error('The operation timed out.')
117
- timeoutError.name = 'TimeoutError'
118
- const retryError = new Error(
119
- 'Failed after 3 attempts.',
120
- ) as Error & { errors: unknown[] }
121
- retryError.errors = [timeoutError]
122
- expect(isFetchIdleTimeoutError(retryError)).toBe(true)
123
- })
124
-
125
- it('returns false for unrelated errors', () => {
126
- expect(isFetchIdleTimeoutError(new Error('Internal Server Error'))).toBe(
127
- false,
128
- )
129
- expect(isFetchIdleTimeoutError(undefined)).toBe(false)
130
- expect(isFetchIdleTimeoutError('The operation timed out.')).toBe(false)
131
- })
132
- })
133
-
134
- describe('FETCH_IDLE_TIMEOUT_USER_MESSAGE', () => {
135
- it('states the symptom without pinning the blame on the user', () => {
136
- expect(FETCH_IDLE_TIMEOUT_USER_MESSAGE).toContain(
137
- 'no data was received from the server for 5 minutes',
138
- )
139
- expect(FETCH_IDLE_TIMEOUT_USER_MESSAGE).toContain('slow model start')
140
- // A slow model start produces this error with nothing wrong on the user's
141
- // end, so the copy must not assert a cause it cannot know.
142
- expect(FETCH_IDLE_TIMEOUT_USER_MESSAGE).not.toContain('usually means')
143
- expect(FETCH_IDLE_TIMEOUT_USER_MESSAGE).not.toContain(
144
- 'rather than a server outage',
145
- )
146
- })
147
- })
148
-
149
- describe('isTransientNetworkError', () => {
150
- it('detects the Bun socket-close message', () => {
151
- expect(
152
- isTransientNetworkError(
153
- new Error(
154
- 'The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()',
155
- ),
156
- ),
157
- ).toBe(true)
158
- })
159
-
160
- it('detects transient network error codes', () => {
161
- const error = new Error('request failed') as Error & { code: string }
162
- error.code = 'ECONNRESET'
163
- expect(isTransientNetworkError(error)).toBe(true)
164
-
165
- const bunError = new Error('request failed') as Error & { code: string }
166
- bunError.code = 'ConnectionClosed'
167
- expect(isTransientNetworkError(bunError)).toBe(true)
168
- })
169
-
170
- it('detects the undici "fetch failed" TypeError', () => {
171
- expect(isTransientNetworkError(new TypeError('fetch failed'))).toBe(true)
172
- })
173
-
174
- it('detects a socket error nested inside an AI SDK RetryError wrapper', () => {
175
- const socketError = new Error(
176
- 'The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()',
177
- ) as Error & { code: string }
178
- socketError.code = 'ECONNRESET'
179
- const retryError = new Error('Failed after 3 attempts.') as Error & {
180
- errors: unknown[]
181
- }
182
- retryError.errors = [socketError]
183
- expect(isTransientNetworkError(retryError)).toBe(true)
184
- })
185
-
186
- it('detects a socket error in a cause chain', () => {
187
- const inner = new Error('read ECONNRESET') as Error & { code: string }
188
- inner.code = 'ECONNRESET'
189
- const outer = new Error('Cannot connect to API')
190
- ;(outer as Error & { cause: unknown }).cause = inner
191
- expect(isTransientNetworkError(outer)).toBe(true)
192
- })
193
-
194
- it('returns false for unrelated errors', () => {
195
- expect(isTransientNetworkError(new Error('Internal Server Error'))).toBe(
196
- false,
197
- )
198
- expect(isTransientNetworkError(undefined)).toBe(false)
199
- expect(isTransientNetworkError('fetch failed')).toBe(false)
200
- const serverError = new Error('Bad Request') as Error & {
201
- statusCode: number
202
- }
203
- serverError.statusCode = 400
204
- expect(isTransientNetworkError(serverError)).toBe(false)
205
- })
206
- })
@@ -1,173 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import {
4
- createFileReadLimiter,
5
- MAX_READ_FILE_CHARS,
6
- MAX_READ_FILE_LINES,
7
- MAX_READ_FILES_CHARS,
8
- MAX_READ_FILES_TOKENS,
9
- windowFileRead,
10
- } from '../file-read-limits'
11
-
12
- describe('createFileReadLimiter', () => {
13
- test('returns a small file unchanged', () => {
14
- const limiter = createFileReadLimiter()
15
-
16
- expect(limiter.limit('small file')).toBe('small file')
17
- })
18
-
19
- test('caps a single file at the per-file limit', () => {
20
- const limiter = createFileReadLimiter()
21
- const content = 'a'.repeat(MAX_READ_FILES_CHARS + 1)
22
- const result = limiter.limit(content)
23
-
24
- expect(result).toStartWith('a'.repeat(MAX_READ_FILES_CHARS))
25
- expect(result).toContain('character hard limit')
26
- expect(result).not.toContain('a'.repeat(MAX_READ_FILES_CHARS + 1))
27
- })
28
-
29
- test('does not split a surrogate pair at the character limit', () => {
30
- const limiter = createFileReadLimiter()
31
- const prefix = 'a'.repeat(MAX_READ_FILES_CHARS - 1)
32
- const result = limiter.limit(`${prefix}😀tail`)
33
-
34
- expect(result).toStartWith(`${prefix}\n\n[FILE_TOO_LARGE]`)
35
- expect(result).not.toContain('\ud83d')
36
- })
37
-
38
- test('shares one aggregate budget across files in request order', () => {
39
- const limiter = createFileReadLimiter()
40
- const first = limiter.limit('a'.repeat(60_000))
41
- const second = limiter.limit('b'.repeat(60_000))
42
- const third = limiter.limit('UNIQUE_THIRD_FILE_CONTENT')
43
-
44
- expect(first).toBe('a'.repeat(60_000))
45
- expect(second).toStartWith('b'.repeat(40_000))
46
- expect(second).not.toContain('b'.repeat(40_001))
47
- expect(second).toContain('combined read_files output')
48
- expect(third).not.toContain('UNIQUE_THIRD_FILE_CONTENT')
49
- expect(third).toContain('truncated after 0 characters')
50
- expect(60_000 + 40_000).toBe(MAX_READ_FILES_CHARS)
51
- })
52
-
53
- test('caps a token-dense file using an injected estimator', () => {
54
- const limiter = createFileReadLimiter({
55
- countTokens: (text) => text.length,
56
- })
57
- const result = limiter.limit('t'.repeat(25_000))
58
- const includedContent = result.split('\n\n[FILE_TOO_LARGE]')[0]
59
-
60
- expect(includedContent).toBe('t'.repeat(19 * 1_024))
61
- expect(includedContent.length).toBeLessThanOrEqual(MAX_READ_FILES_TOKENS)
62
- expect(result).toContain('estimated-token per-file limit')
63
- })
64
-
65
- test('does not split a surrogate pair at the token limit', () => {
66
- const limiter = createFileReadLimiter({
67
- countTokens: (text) => Array.from(text).length,
68
- })
69
- const result = limiter.limit('😀'.repeat(25_000))
70
- const includedContent = result.split('\n\n[FILE_TOO_LARGE]')[0]
71
- const lastCodeUnit = includedContent.charCodeAt(includedContent.length - 1)
72
-
73
- expect(Array.from(includedContent).length).toBeLessThanOrEqual(
74
- MAX_READ_FILES_TOKENS,
75
- )
76
- expect(lastCodeUnit < 0xd800 || lastCodeUnit > 0xdbff).toBe(true)
77
- })
78
-
79
- test('shares one token budget across files in request order', () => {
80
- const limiter = createFileReadLimiter({
81
- countTokens: (text) => text.length,
82
- })
83
- const first = limiter.limit('a'.repeat(12_000))
84
- const second = limiter.limit('b'.repeat(12_000))
85
- const thirdContent = 'UNIQUE_THIRD_FILE_CONTENT'
86
- const third = limiter.limit(thirdContent)
87
- const secondContent = second.split('\n\n[FILE_TOO_LARGE]')[0]
88
-
89
- expect(first).toBe('a'.repeat(12_000))
90
- expect(secondContent).toBe('b'.repeat(7 * 1_024))
91
- expect(second).toContain('combined read_files output')
92
- expect(second).toContain('estimated-token limit')
93
- expect(third).toBe(thirdContent)
94
- expect(first.length + secondContent.length + third.length).toBeLessThan(
95
- MAX_READ_FILES_TOKENS,
96
- )
97
- })
98
- })
99
-
100
- describe('windowFileRead', () => {
101
- test('returns a small file unchanged, including its trailing newline', () => {
102
- const content = 'a\nb\nc\n'
103
-
104
- expect(windowFileRead(content)).toBe(content)
105
- })
106
-
107
- test('does not count the trailing newline as an extra line', () => {
108
- const content =
109
- Array.from({ length: MAX_READ_FILE_LINES }, (_, i) => `line ${i + 1}`).join('\n') + '\n'
110
-
111
- expect(windowFileRead(content)).toBe(content)
112
- })
113
-
114
- test('caps an unwindowed read at the line limit and reports the true total', () => {
115
- const totalLines = MAX_READ_FILE_LINES + 500
116
- const content = Array.from({ length: totalLines }, (_, i) => `line ${i + 1}`).join('\n')
117
- const result = windowFileRead(content)
118
-
119
- expect(result).toContain(`showing lines 1-${MAX_READ_FILE_LINES} of ${totalLines}`)
120
- expect(result).toContain(`offset=${MAX_READ_FILE_LINES + 1} to continue`)
121
- expect(result).not.toContain(`line ${MAX_READ_FILE_LINES + 1}\n`)
122
- })
123
-
124
- test('returns the requested window with a footer', () => {
125
- const content = Array.from({ length: 100 }, (_, i) => `line ${i + 1}`).join('\n')
126
- const result = windowFileRead(content, 10, 5)
127
-
128
- expect(result).toContain('line 10')
129
- expect(result).toContain('line 14')
130
- expect(result).not.toContain('line 15\n')
131
- expect(result).toContain('showing lines 10-14 of 100')
132
- expect(result).toContain('offset=15 to continue')
133
- })
134
-
135
- test('omits the continue advice when the window reaches the end of the file', () => {
136
- const content = Array.from({ length: 100 }, (_, i) => `line ${i + 1}`).join('\n')
137
- const result = windowFileRead(content, 90, 20)
138
-
139
- expect(result).toContain('showing lines 90-100 of 100')
140
- expect(result).not.toContain('to continue')
141
- })
142
-
143
- test('reports an offset beyond the end of the file', () => {
144
- const content = 'a\nb\nc'
145
-
146
- expect(windowFileRead(content, 10)).toBe(
147
- '[read_files: 3 lines total; offset 10 is beyond the end of the file.]',
148
- )
149
- })
150
-
151
- test('clamps a requested limit to the line cap', () => {
152
- const totalLines = MAX_READ_FILE_LINES + 500
153
- const content = Array.from({ length: totalLines }, (_, i) => `line ${i + 1}`).join('\n')
154
- const result = windowFileRead(content, 1, totalLines)
155
-
156
- expect(result).toContain(`showing lines 1-${MAX_READ_FILE_LINES} of ${totalLines}`)
157
- })
158
-
159
- test('shortens a window that exceeds the char cap and says so', () => {
160
- const line = 'x'.repeat(1000)
161
- const totalLines = 100
162
- const content = Array.from({ length: totalLines }, () => line).join('\n')
163
- const result = windowFileRead(content, 1, totalLines)
164
-
165
- const match = result.match(/showing lines 1-(\d+) of 100/)
166
- expect(match).not.toBeNull()
167
- expect(Number(match![1])).toBeLessThan(totalLines)
168
- expect(result).toContain(
169
- `shortened to stay under ${MAX_READ_FILE_CHARS.toLocaleString()} characters`,
170
- )
171
- expect(result).toContain('to continue')
172
- })
173
- })
@@ -1,60 +0,0 @@
1
- import { describe, expect, it } from 'bun:test'
2
-
3
- import { formatCodeSearchOutput } from '../format-code-search'
4
-
5
- describe('formatCodeSearchOutput', () => {
6
- it('adds a match count and line labels', () => {
7
- const output = formatCodeSearchOutput(
8
- [
9
- 'src/a.ts:12:const alpha = true',
10
- 'src/a.ts:18:return alpha',
11
- 'src/b.ts:3:export const beta = false',
12
- ].join('\n'),
13
- { matchCount: 3 },
14
- )
15
-
16
- expect(output).toBe(
17
- [
18
- 'Found 3 matches',
19
- 'src/a.ts:',
20
- ' Line 12: const alpha = true',
21
- ' Line 18: return alpha',
22
- '',
23
- 'src/b.ts:',
24
- ' Line 3: export const beta = false',
25
- ].join('\n'),
26
- )
27
- })
28
-
29
- it('uses the provided match count instead of counting context lines', () => {
30
- const output = formatCodeSearchOutput(
31
- [
32
- 'src/a.ts:10:const before = true',
33
- 'src/a.ts:11:const match = true',
34
- 'src/a.ts:12:const after = true',
35
- ].join('\n'),
36
- { matchCount: 1 },
37
- )
38
-
39
- expect(output).toContain('Found 1 matches')
40
- expect(output).toContain(' Line 10: const before = true')
41
- expect(output).toContain(' Line 11: const match = true')
42
- expect(output).toContain(' Line 12: const after = true')
43
- })
44
-
45
- it('does not count native ripgrep context lines as matches', () => {
46
- const output = formatCodeSearchOutput(
47
- [
48
- 'src/a.ts-10-const before = true',
49
- 'src/a.ts:11:const match = true',
50
- 'src/a.ts-12-const after = true',
51
- ].join('\n'),
52
- )
53
-
54
- expect(output).toContain('Found 1 matches')
55
- })
56
-
57
- it('reports zero matches for empty output', () => {
58
- expect(formatCodeSearchOutput('')).toBe('Found 0 matches')
59
- })
60
- })
@@ -1,31 +0,0 @@
1
- import { describe, expect, it } from 'bun:test'
2
-
3
- import {
4
- AXIOM_MIRROR_DENYLIST,
5
- shouldMirrorAnalyticsEvent,
6
- } from '../log-mirror'
7
-
8
- describe('shouldMirrorAnalyticsEvent', () => {
9
- it('drops high-volume PostHog auto-events from the Axiom mirror', () => {
10
- for (const denied of AXIOM_MIRROR_DENYLIST) {
11
- expect(shouldMirrorAnalyticsEvent(denied)).toBe(false)
12
- }
13
- expect(shouldMirrorAnalyticsEvent('$snapshot')).toBe(false)
14
- expect(shouldMirrorAnalyticsEvent('$autocapture')).toBe(false)
15
- })
16
-
17
- it('keeps named product events and useful $ events', () => {
18
- expect(shouldMirrorAnalyticsEvent('cli.login')).toBe(true)
19
- expect(shouldMirrorAnalyticsEvent('cli.app_launched')).toBe(true)
20
- expect(shouldMirrorAnalyticsEvent('web.signup')).toBe(true)
21
- expect(shouldMirrorAnalyticsEvent('$pageview')).toBe(true)
22
- expect(shouldMirrorAnalyticsEvent('$identify')).toBe(true)
23
- expect(shouldMirrorAnalyticsEvent('$exception')).toBe(true)
24
- })
25
-
26
- it('treats empty/null event names as mirror-eligible (logs without an event)', () => {
27
- expect(shouldMirrorAnalyticsEvent(null)).toBe(true)
28
- expect(shouldMirrorAnalyticsEvent(undefined)).toBe(true)
29
- expect(shouldMirrorAnalyticsEvent('')).toBe(true)
30
- })
31
- })