@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,35 +0,0 @@
1
- import { describe, expect, mock, test } from 'bun:test'
2
-
3
- import { findCommand } from '../command-registry'
4
-
5
- import type { RouterParams } from '../command-registry'
6
- import type { ChatMessage } from '../../types/chat'
7
-
8
- describe('/diagnostics command', () => {
9
- test('adds runtime process diagnostics to the chat', () => {
10
- const command = findCommand('diagnostics')
11
- expect(command).toBeDefined()
12
-
13
- let messages: ChatMessage[] = []
14
- const saveToHistory = mock(() => {})
15
- const setInputValue = mock(() => {})
16
- command!.handler(
17
- {
18
- inputValue: '/diagnostics',
19
- setMessages: (update: Parameters<RouterParams['setMessages']>[0]) => {
20
- messages = typeof update === 'function' ? update(messages) : update
21
- },
22
- saveToHistory,
23
- setInputValue,
24
- } as unknown as RouterParams,
25
- '',
26
- )
27
-
28
- const output = messages.at(-1)?.content ?? ''
29
- expect(output).toContain('process diagnostics')
30
- expect(output).toContain(`Platform: ${process.platform} ${process.arch}`)
31
- expect(output).toContain(`CLI binary: PID ${process.pid}`)
32
- expect(saveToHistory).toHaveBeenCalledWith('/diagnostics')
33
- expect(setInputValue).toHaveBeenCalled()
34
- })
35
- })
@@ -1,99 +0,0 @@
1
- import { describe, test, expect } from 'bun:test'
2
-
3
- /**
4
- * Tests for the handleImageCommand argument parsing behavior.
5
- *
6
- * These tests verify the parsing logic independently of the actual
7
- * validateAndAddImage implementation by testing the parsing function directly.
8
- */
9
-
10
- // Extract the parsing logic that handleImageCommand uses
11
- // New simplified implementation: split on whitespace
12
- function parseImageCommandArgs(args: string): {
13
- imagePath: string | null
14
- message: string
15
- } {
16
- const [imagePath, ...rest] = args.trim().split(/\s+/)
17
-
18
- if (!imagePath) {
19
- return { imagePath: null, message: '' }
20
- }
21
-
22
- return { imagePath, message: rest.join(' ') }
23
- }
24
-
25
- describe('handleImageCommand parsing', () => {
26
- describe('argument parsing', () => {
27
- test('parses image path only', () => {
28
- const result = parseImageCommandArgs('./screenshot.png')
29
- expect(result.imagePath).toBe('./screenshot.png')
30
- expect(result.message).toBe('')
31
- })
32
-
33
- test('parses image path with message', () => {
34
- const result = parseImageCommandArgs(
35
- './screenshot.png please analyze this',
36
- )
37
- expect(result.imagePath).toBe('./screenshot.png')
38
- expect(result.message).toBe('please analyze this')
39
- })
40
-
41
- test('parses image path with multi-word message', () => {
42
- const result = parseImageCommandArgs(
43
- './image.jpg what is in this picture?',
44
- )
45
- expect(result.imagePath).toBe('./image.jpg')
46
- expect(result.message).toBe('what is in this picture?')
47
- })
48
-
49
- test('handles absolute paths with message', () => {
50
- const result = parseImageCommandArgs('/path/to/file.png describe the UI')
51
- expect(result.imagePath).toBe('/path/to/file.png')
52
- expect(result.message).toBe('describe the UI')
53
- })
54
-
55
- test('trims whitespace from input', () => {
56
- const result = parseImageCommandArgs(' ./image.png ')
57
- expect(result.imagePath).toBe('./image.png')
58
- expect(result.message).toBe('')
59
- })
60
-
61
- test('handles multiple spaces between path and message', () => {
62
- const result = parseImageCommandArgs('./image.png hello world')
63
- expect(result.imagePath).toBe('./image.png')
64
- // The regex only captures content after the first whitespace group
65
- expect(result.message).toBe('hello world')
66
- })
67
- })
68
-
69
- describe('invalid input handling', () => {
70
- test('returns null imagePath for empty input', () => {
71
- const result = parseImageCommandArgs('')
72
- expect(result.imagePath).toBeNull()
73
- expect(result.message).toBe('')
74
- })
75
-
76
- test('returns null imagePath for whitespace-only input', () => {
77
- const result = parseImageCommandArgs(' ')
78
- expect(result.imagePath).toBeNull()
79
- expect(result.message).toBe('')
80
- })
81
- })
82
-
83
- describe('edge cases', () => {
84
- test('handles filenames with extensions', () => {
85
- const result = parseImageCommandArgs('image.jpeg')
86
- expect(result.imagePath).toBe('image.jpeg')
87
- })
88
-
89
- test('handles relative paths', () => {
90
- const result = parseImageCommandArgs('../screenshots/test.png')
91
- expect(result.imagePath).toBe('../screenshots/test.png')
92
- })
93
-
94
- test('handles tilde paths', () => {
95
- const result = parseImageCommandArgs('~/Downloads/image.png')
96
- expect(result.imagePath).toBe('~/Downloads/image.png')
97
- })
98
- })
99
- })
@@ -1,456 +0,0 @@
1
- import * as fs from 'fs'
2
- import path from 'path'
3
-
4
- import {
5
- describe,
6
- test,
7
- expect,
8
- beforeEach,
9
- afterEach,
10
- mock,
11
- spyOn,
12
- } from 'bun:test'
13
-
14
- import * as projectFiles from '../../project-files'
15
- import { handleInitializationFlowLocally } from '../init'
16
-
17
- import type { ChatMessage } from '../../types/chat'
18
-
19
- /** Helper to extract text content from ChatMessages returned by getSystemMessage */
20
- const getMessageText = (messages: ChatMessage[]): string => {
21
- return messages
22
- .map((m) => {
23
- // ChatMessage has content as a string, not an array
24
- if (typeof m.content === 'string') {
25
- return m.content
26
- }
27
- return ''
28
- })
29
- .join('')
30
- }
31
-
32
- describe('handleInitializationFlowLocally', () => {
33
- const TEST_PROJECT_ROOT = '/test/project'
34
- const KNOWLEDGE_FILE_NAME = 'AGENTS.md'
35
-
36
- let existsSyncSpy: ReturnType<typeof spyOn>
37
- let writeFileSyncSpy: ReturnType<typeof spyOn>
38
- let mkdirSyncSpy: ReturnType<typeof spyOn>
39
- let getProjectRootSpy: ReturnType<typeof spyOn>
40
-
41
- beforeEach(() => {
42
- // Mock getProjectRoot
43
- getProjectRootSpy = spyOn(projectFiles, 'getProjectRoot').mockReturnValue(
44
- TEST_PROJECT_ROOT,
45
- )
46
-
47
- // Mock fs functions
48
- existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(false)
49
- writeFileSyncSpy = spyOn(fs, 'writeFileSync').mockImplementation(() => {})
50
- mkdirSyncSpy = spyOn(fs, 'mkdirSync').mockImplementation(() => undefined)
51
- })
52
-
53
- afterEach(() => {
54
- mock.restore()
55
- })
56
-
57
- describe('knowledge file creation', () => {
58
- test('creates AGENTS.md when it does not exist', () => {
59
- existsSyncSpy.mockImplementation((_p: string) => false)
60
-
61
- const { postUserMessage } = handleInitializationFlowLocally()
62
-
63
- expect(writeFileSyncSpy).toHaveBeenCalledWith(
64
- path.join(TEST_PROJECT_ROOT, KNOWLEDGE_FILE_NAME),
65
- expect.stringContaining('# Project knowledge'),
66
- )
67
-
68
- // Check message indicates creation
69
- const messages = postUserMessage([])
70
- expect(messages.length).toBeGreaterThan(0)
71
- expect(getMessageText(messages)).toContain('✅ Created `AGENTS.md`')
72
- })
73
-
74
- test('skips AGENTS.md creation when it already exists', () => {
75
- existsSyncSpy.mockImplementation((p: unknown) =>
76
- p === path.join(TEST_PROJECT_ROOT, KNOWLEDGE_FILE_NAME),
77
- )
78
-
79
- const { postUserMessage } = handleInitializationFlowLocally()
80
-
81
- // writeFileSync should not be called for knowledge.md
82
- const knowledgeWriteCalls = writeFileSyncSpy.mock.calls.filter(
83
- (call: unknown[]) => call[0] === path.join(TEST_PROJECT_ROOT, KNOWLEDGE_FILE_NAME),
84
- )
85
- expect(knowledgeWriteCalls.length).toBe(0)
86
-
87
- // Check message indicates file already exists
88
- const messages = postUserMessage([])
89
- expect(getMessageText(messages)).toContain('📋 `AGENTS.md` already exists')
90
- })
91
- })
92
-
93
- describe('.agents directory creation', () => {
94
- test('creates .agents directory when it does not exist', () => {
95
- existsSyncSpy.mockReturnValue(false)
96
-
97
- const { postUserMessage } = handleInitializationFlowLocally()
98
-
99
- expect(mkdirSyncSpy).toHaveBeenCalledWith(
100
- path.join(TEST_PROJECT_ROOT, '.agents'),
101
- { recursive: true },
102
- )
103
-
104
- const messages = postUserMessage([])
105
- expect(getMessageText(messages)).toContain('✅ Created `.agents/`')
106
- })
107
-
108
- test('skips .agents directory creation when it already exists', () => {
109
- existsSyncSpy.mockImplementation((p: unknown) =>
110
- p === path.join(TEST_PROJECT_ROOT, '.agents'),
111
- )
112
-
113
- const { postUserMessage } = handleInitializationFlowLocally()
114
-
115
- // mkdirSync should not be called for .agents directory
116
- const agentsDirCalls = mkdirSyncSpy.mock.calls.filter(
117
- (call: unknown[]) => call[0] === path.join(TEST_PROJECT_ROOT, '.agents'),
118
- )
119
- expect(agentsDirCalls.length).toBe(0)
120
-
121
- const messages = postUserMessage([])
122
- expect(getMessageText(messages)).toContain('📋 `.agents/` already exists')
123
- })
124
- })
125
-
126
- describe('.agents/types directory creation', () => {
127
- test('creates .agents/types directory when it does not exist', () => {
128
- existsSyncSpy.mockReturnValue(false)
129
-
130
- const { postUserMessage } = handleInitializationFlowLocally()
131
-
132
- expect(mkdirSyncSpy).toHaveBeenCalledWith(
133
- path.join(TEST_PROJECT_ROOT, '.agents', 'types'),
134
- { recursive: true },
135
- )
136
-
137
- const messages = postUserMessage([])
138
- expect(getMessageText(messages)).toContain('✅ Created `.agents/types/`')
139
- })
140
-
141
- test('skips .agents/types directory creation when it already exists', () => {
142
- existsSyncSpy.mockImplementation((p: unknown) => {
143
- // .agents exists, .agents/types exists
144
- return (
145
- p === path.join(TEST_PROJECT_ROOT, '.agents') ||
146
- p === path.join(TEST_PROJECT_ROOT, '.agents', 'types')
147
- )
148
- })
149
-
150
- const { postUserMessage } = handleInitializationFlowLocally()
151
-
152
- // mkdirSync should not be called for .agents/types directory
153
- const typesDirCalls = mkdirSyncSpy.mock.calls.filter(
154
- (call: unknown[]) => call[0] === path.join(TEST_PROJECT_ROOT, '.agents', 'types'),
155
- )
156
- expect(typesDirCalls.length).toBe(0)
157
-
158
- const messages = postUserMessage([])
159
- expect(getMessageText(messages)).toContain('📋 `.agents/types/` already exists')
160
- })
161
- })
162
-
163
- describe('type file copying', () => {
164
- test('copies type files when they do not exist', () => {
165
- existsSyncSpy.mockReturnValue(false)
166
-
167
- const { postUserMessage } = handleInitializationFlowLocally()
168
-
169
- // Check that writeFileSync was called for type files
170
- const typeFiles = ['agent-definition.ts', 'tools.ts', 'util-types.ts']
171
- for (const fileName of typeFiles) {
172
- const fileCalls = writeFileSyncSpy.mock.calls.filter((call: unknown[]) =>
173
- (call[0] as string).endsWith(fileName),
174
- )
175
- expect(fileCalls.length).toBe(1)
176
- }
177
-
178
- const messages = postUserMessage([])
179
- const messageContent = getMessageText(messages)
180
-
181
- // Should have success messages for copied files
182
- expect(messageContent).toContain('`.agents/types/agent-definition.ts`')
183
- expect(messageContent).toContain('`.agents/types/tools.ts`')
184
- expect(messageContent).toContain('`.agents/types/util-types.ts`')
185
- })
186
-
187
- test('skips type files that already exist', () => {
188
- const typesDir = path.join(TEST_PROJECT_ROOT, '.agents', 'types')
189
- existsSyncSpy.mockImplementation((p: unknown) => {
190
- // Only agent-definition.ts exists
191
- return p === path.join(typesDir, 'agent-definition.ts')
192
- })
193
-
194
- const { postUserMessage } = handleInitializationFlowLocally()
195
-
196
- // agent-definition.ts should NOT be written
197
- const agentDefCalls = writeFileSyncSpy.mock.calls.filter(
198
- (call: unknown[]) => (call[0] as string).endsWith('agent-definition.ts'),
199
- )
200
- expect(agentDefCalls.length).toBe(0)
201
-
202
- // tools.ts and util-types.ts should be written
203
- const toolsCalls = writeFileSyncSpy.mock.calls.filter((call: unknown[]) =>
204
- (call[0] as string).endsWith('tools.ts'),
205
- )
206
- expect(toolsCalls.length).toBe(1)
207
-
208
- const utilTypesCalls = writeFileSyncSpy.mock.calls.filter((call: unknown[]) =>
209
- (call[0] as string).endsWith('util-types.ts'),
210
- )
211
- expect(utilTypesCalls.length).toBe(1)
212
-
213
- const messages = postUserMessage([])
214
- expect(getMessageText(messages)).toContain(
215
- '📋 `.agents/types/agent-definition.ts` already exists',
216
- )
217
- })
218
- })
219
-
220
- describe('message accumulation', () => {
221
- test('returns multiple messages for all operations', () => {
222
- existsSyncSpy.mockReturnValue(false)
223
-
224
- const { postUserMessage } = handleInitializationFlowLocally()
225
-
226
- const messages = postUserMessage([])
227
-
228
- // Should have messages for:
229
- // 1. AGENTS.md creation
230
- // 2. .agents/ creation
231
- // 3. .agents/types/ creation
232
- // 4-6. Three type file copies
233
- expect(messages.length).toBeGreaterThanOrEqual(6)
234
- })
235
-
236
- test('preserves previous messages in postUserMessage', () => {
237
- existsSyncSpy.mockReturnValue(false)
238
-
239
- const { postUserMessage } = handleInitializationFlowLocally()
240
-
241
- // ChatMessage has content as a string, not an array
242
- const previousMessages: ChatMessage[] = [
243
- {
244
- id: 'user-123',
245
- variant: 'user',
246
- content: 'Previous message',
247
- timestamp: '2024-01-01T00:00:00Z',
248
- },
249
- ]
250
-
251
- const messages = postUserMessage(previousMessages)
252
-
253
- // First message should be the previous one
254
- expect(messages[0]).toEqual(previousMessages[0])
255
- // Should have additional messages
256
- expect(messages.length).toBeGreaterThan(1)
257
- })
258
- })
259
-
260
- describe('error handling', () => {
261
- test('handles writeFileSync errors for type files gracefully', () => {
262
- existsSyncSpy.mockReturnValue(false)
263
- writeFileSyncSpy.mockImplementation((p: unknown) => {
264
- if ((p as string).endsWith('tools.ts')) {
265
- throw new Error('Permission denied')
266
- }
267
- })
268
-
269
- const { postUserMessage } = handleInitializationFlowLocally()
270
-
271
- const messages = postUserMessage([])
272
- const messageContent = getMessageText(messages)
273
-
274
- // Should have error message for tools.ts
275
- expect(messageContent).toContain('⚠️ Failed to copy `.agents/types/tools.ts`')
276
- expect(messageContent).toContain('Permission denied')
277
- })
278
-
279
- test('handles writeFileSync errors for AGENTS.md gracefully', () => {
280
- existsSyncSpy.mockReturnValue(false)
281
- writeFileSyncSpy.mockImplementation((p: unknown) => {
282
- if ((p as string).endsWith(KNOWLEDGE_FILE_NAME)) {
283
- throw new Error('Disk full')
284
- }
285
- })
286
-
287
- // The function should throw when the AGENTS.md write fails
288
- // since it is not wrapped in try-catch
289
- expect(() => handleInitializationFlowLocally()).toThrow('Disk full')
290
- })
291
-
292
- test('handles mkdirSync errors for .agents directory gracefully', () => {
293
- existsSyncSpy.mockReturnValue(false)
294
- mkdirSyncSpy.mockImplementation((p: unknown) => {
295
- if ((p as string).endsWith('.agents')) {
296
- throw new Error('Cannot create directory')
297
- }
298
- return undefined
299
- })
300
-
301
- // The function should throw when .agents directory creation fails
302
- // since mkdirSync is not wrapped in try-catch
303
- expect(() => handleInitializationFlowLocally()).toThrow('Cannot create directory')
304
- })
305
-
306
- test('handles mkdirSync errors for .agents/types directory gracefully', () => {
307
- existsSyncSpy.mockImplementation((p: unknown) => {
308
- // .agents exists but .agents/types doesn't
309
- return p === path.join(TEST_PROJECT_ROOT, '.agents')
310
- })
311
- mkdirSyncSpy.mockImplementation((p: unknown) => {
312
- if ((p as string).endsWith('types')) {
313
- throw new Error('Permission denied for types dir')
314
- }
315
- return undefined
316
- })
317
-
318
- // The function should throw when .agents/types directory creation fails
319
- expect(() => handleInitializationFlowLocally()).toThrow('Permission denied for types dir')
320
- })
321
-
322
- test('continues copying other files when one type file fails', () => {
323
- existsSyncSpy.mockReturnValue(false)
324
- writeFileSyncSpy.mockImplementation((p: unknown) => {
325
- // Only fail for agent-definition.ts
326
- if ((p as string).endsWith('agent-definition.ts')) {
327
- throw new Error('File locked')
328
- }
329
- })
330
-
331
- const { postUserMessage } = handleInitializationFlowLocally()
332
- const messages = postUserMessage([])
333
- const messageContent = getMessageText(messages)
334
-
335
- // Should have error for agent-definition.ts
336
- expect(messageContent).toContain('⚠️ Failed to copy `.agents/types/agent-definition.ts`')
337
- expect(messageContent).toContain('File locked')
338
-
339
- // But should still succeed for tools.ts and util-types.ts
340
- expect(messageContent).toContain('✅ Copied `.agents/types/tools.ts`')
341
- expect(messageContent).toContain('✅ Copied `.agents/types/util-types.ts`')
342
- })
343
-
344
- test('handles non-Error exceptions in type file copying', () => {
345
- existsSyncSpy.mockReturnValue(false)
346
- writeFileSyncSpy.mockImplementation((p: unknown) => {
347
- if ((p as string).endsWith('util-types.ts')) {
348
- // Throw a non-Error value
349
- throw 'string error'
350
- }
351
- })
352
-
353
- const { postUserMessage } = handleInitializationFlowLocally()
354
- const messages = postUserMessage([])
355
- const messageContent = getMessageText(messages)
356
-
357
- // Should handle non-Error exceptions gracefully
358
- expect(messageContent).toContain('⚠️ Failed to copy `.agents/types/util-types.ts`')
359
- expect(messageContent).toContain('string error')
360
- })
361
-
362
- test('handles null/undefined exceptions in type file copying', () => {
363
- existsSyncSpy.mockReturnValue(false)
364
- writeFileSyncSpy.mockImplementation((p: unknown) => {
365
- if ((p as string).endsWith('tools.ts')) {
366
- // Throw null
367
- throw null
368
- }
369
- })
370
-
371
- const { postUserMessage } = handleInitializationFlowLocally()
372
- const messages = postUserMessage([])
373
- const messageContent = getMessageText(messages)
374
-
375
- // Should handle null exceptions with 'Unknown' fallback
376
- expect(messageContent).toContain('⚠️ Failed to copy `.agents/types/tools.ts`')
377
- expect(messageContent).toContain('Unknown')
378
- })
379
- })
380
-
381
- describe('integration scenarios', () => {
382
- test('handles partial initialization state correctly', () => {
383
- const agentsDir = path.join(TEST_PROJECT_ROOT, '.agents')
384
- const typesDir = path.join(agentsDir, 'types')
385
-
386
- // Scenario: AGENTS.md exists, .agents exists, but .agents/types and type files don't exist
387
- existsSyncSpy.mockImplementation((p: unknown) => {
388
- return (
389
- p === path.join(TEST_PROJECT_ROOT, KNOWLEDGE_FILE_NAME) ||
390
- p === agentsDir
391
- )
392
- })
393
-
394
- const { postUserMessage } = handleInitializationFlowLocally()
395
-
396
- // Should NOT create AGENTS.md
397
- const knowledgeWriteCalls = writeFileSyncSpy.mock.calls.filter(
398
- (call: unknown[]) => call[0] === path.join(TEST_PROJECT_ROOT, KNOWLEDGE_FILE_NAME),
399
- )
400
- expect(knowledgeWriteCalls.length).toBe(0)
401
-
402
- // Should NOT create .agents directory
403
- const agentsDirCalls = mkdirSyncSpy.mock.calls.filter(
404
- (call: unknown[]) => call[0] === agentsDir,
405
- )
406
- expect(agentsDirCalls.length).toBe(0)
407
-
408
- // Should create .agents/types directory
409
- const typesDirCalls = mkdirSyncSpy.mock.calls.filter(
410
- (call: unknown[]) => call[0] === typesDir,
411
- )
412
- expect(typesDirCalls.length).toBe(1)
413
-
414
- // Should copy type files
415
- const typeFileCalls = writeFileSyncSpy.mock.calls.filter((call: unknown[]) =>
416
- (call[0] as string).startsWith(typesDir),
417
- )
418
- expect(typeFileCalls.length).toBe(3)
419
-
420
- const messages = postUserMessage([])
421
- const messageContent = getMessageText(messages)
422
-
423
- expect(messageContent).toContain('📋 `AGENTS.md` already exists')
424
- expect(messageContent).toContain('📋 `.agents/` already exists')
425
- expect(messageContent).toContain('✅ Created `.agents/types/`')
426
- })
427
-
428
- test('handles fully initialized project correctly', () => {
429
- // Everything exists
430
- existsSyncSpy.mockReturnValue(true)
431
-
432
- const { postUserMessage } = handleInitializationFlowLocally()
433
-
434
- // Nothing should be created
435
- expect(writeFileSyncSpy).not.toHaveBeenCalled()
436
- expect(mkdirSyncSpy).not.toHaveBeenCalled()
437
-
438
- const messages = postUserMessage([])
439
- const messageContent = getMessageText(messages)
440
-
441
- // All messages should indicate existing files
442
- expect(messageContent).toContain('📋 `AGENTS.md` already exists')
443
- expect(messageContent).toContain('📋 `.agents/` already exists')
444
- expect(messageContent).toContain('📋 `.agents/types/` already exists')
445
- expect(messageContent).toContain(
446
- '📋 `.agents/types/agent-definition.ts` already exists',
447
- )
448
- expect(messageContent).toContain(
449
- '📋 `.agents/types/tools.ts` already exists',
450
- )
451
- expect(messageContent).toContain(
452
- '📋 `.agents/types/util-types.ts` already exists',
453
- )
454
- })
455
- })
456
- })
@@ -1,91 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- describe('/new command', () => {
4
- test('rotates the chat id so the previous chat is not overwritten', () => {
5
- const commandRegistryUrl = new URL(
6
- '../command-registry.ts',
7
- import.meta.url,
8
- ).href
9
- const projectFilesUrl = new URL('../../project-files.ts', import.meta.url)
10
- .href
11
- const activeRunUrl = new URL('../../utils/active-run.ts', import.meta.url)
12
- .href
13
-
14
- const result = Bun.spawnSync({
15
- cmd: [
16
- 'bun',
17
- '--eval',
18
- `
19
- import { findCommand } from ${JSON.stringify(commandRegistryUrl)}
20
- import { getCurrentChatId, setCurrentChatId } from ${JSON.stringify(projectFilesUrl)}
21
- import { registerActiveRun } from ${JSON.stringify(activeRunUrl)}
22
-
23
- setCurrentChatId('previous-chat-id')
24
-
25
- // Simulate an in-flight run: record which chat was current when the
26
- // abort fired.
27
- let abortedAtChatId = null
28
- let stopReason = null
29
- registerActiveRun('run-1', (reason) => {
30
- abortedAtChatId = getCurrentChatId()
31
- stopReason = reason
32
- })
33
-
34
- const newCommand = findCommand('new')
35
- if (!newCommand) throw new Error('new command missing')
36
-
37
- const noop = () => {}
38
- newCommand.handler(
39
- {
40
- setMessages: noop,
41
- clearMessages: noop,
42
- saveToHistory: noop,
43
- inputValue: '/new',
44
- setInputValue: noop,
45
- setCanProcessQueue: noop,
46
- },
47
- '',
48
- )
49
-
50
- if (getCurrentChatId() === 'previous-chat-id') {
51
- throw new Error(
52
- '/new did not rotate the chat id — the next save would overwrite the previous chat',
53
- )
54
- }
55
-
56
- if (abortedAtChatId === null) {
57
- throw new Error(
58
- '/new did not abort the in-flight run — an orphaned run would keep checkpointing across the chat switch',
59
- )
60
- }
61
- if (abortedAtChatId !== 'previous-chat-id') {
62
- throw new Error(
63
- '/new aborted the run only after rotating the chat id — late writes could land in the new chat',
64
- )
65
- }
66
- if (stopReason !== 'new-chat') {
67
- throw new Error('/new did not use the new-chat cancellation policy')
68
- }
69
- `,
70
- ],
71
- cwd: process.cwd(),
72
- env: {
73
- ...process.env,
74
- NODE_ENV: 'test',
75
- NEXT_PUBLIC_CB_ENVIRONMENT: 'test',
76
- NEXT_PUBLIC_ANVIL_APP_URL: 'https://app.codebuff.test',
77
- NEXT_PUBLIC_SUPPORT_EMAIL: 'support@codebuff.test',
78
- NEXT_PUBLIC_POSTHOG_API_KEY: 'phc_test_key',
79
- NEXT_PUBLIC_POSTHOG_HOST_URL: 'https://posthog.codebuff.test',
80
- NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: 'pk_test_123',
81
- NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL: 'https://stripe.codebuff.test',
82
- NEXT_PUBLIC_WEB_PORT: '3000',
83
- },
84
- stderr: 'pipe',
85
- stdout: 'pipe',
86
- })
87
-
88
- const stderr = new TextDecoder().decode(result.stderr)
89
- expect(result.exitCode, stderr).toBe(0)
90
- })
91
- })