@alumbwe/anvil 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/bin/anvil +2 -0
- package/bin/tree-sitter.wasm +0 -0
- package/package.json +67 -0
- package/src/__tests__/README.md +256 -0
- package/src/__tests__/bash-mode.test.ts +442 -0
- package/src/__tests__/cli-args.test.ts +181 -0
- package/src/__tests__/cli-harness.test.ts +52 -0
- package/src/__tests__/e2e/first-time-login.test.ts +173 -0
- package/src/__tests__/e2e/logout-relogin-flow.test.ts +110 -0
- package/src/__tests__/e2e/returning-user-auth.test.ts +113 -0
- package/src/__tests__/e2e-cli.test.ts +183 -0
- package/src/__tests__/helpers/launcher-disconnect-fixture.cjs +176 -0
- package/src/__tests__/helpers/mock-api-client.ts +64 -0
- package/src/__tests__/helpers/renderer-cleanup-fixture.tsx +89 -0
- package/src/__tests__/helpers/terminal-watchdog-fixture.ts +75 -0
- package/src/__tests__/home-directory-detection.test.ts +213 -0
- package/src/__tests__/integration/api-integration.test.ts +288 -0
- package/src/__tests__/integration/credentials-storage.test.ts +486 -0
- package/src/__tests__/integration/local-agents.test.ts +1187 -0
- package/src/__tests__/integration/login-flow-instrumentation.test.ts +134 -0
- package/src/__tests__/integration/login-polling-working.test.ts +285 -0
- package/src/__tests__/integration/queue-editing.test.tsx +261 -0
- package/src/__tests__/integration/usage-refresh-on-completion.test.ts +168 -0
- package/src/__tests__/integration-tmux.test.ts +188 -0
- package/src/__tests__/launcher-avx2-fallback.test.ts +630 -0
- package/src/__tests__/launcher-disconnect.test.ts +104 -0
- package/src/__tests__/mocks/hover-toggle-controller.ts +71 -0
- package/src/__tests__/open-tui-native-bundle.test.ts +378 -0
- package/src/__tests__/path-completion.test.ts +243 -0
- package/src/__tests__/project-files-chat-id.test.ts +34 -0
- package/src/__tests__/release/proxy-http-get.test.ts +667 -0
- package/src/__tests__/release/wrapper-safety.test.ts +412 -0
- package/src/__tests__/renderer-cleanup.test.ts +174 -0
- package/src/__tests__/rerender-perf.integration.test.ts +283 -0
- package/src/__tests__/terminal-reset-sequences.test.ts +36 -0
- package/src/__tests__/terminal-watchdog.test.ts +388 -0
- package/src/__tests__/test-utils.ts +271 -0
- package/src/__tests__/tmux-poc.ts +150 -0
- package/src/__tests__/unit/agent-mode-toggle.test.ts +137 -0
- package/src/__tests__/unit/copy-button.test.ts +157 -0
- package/src/__tests__/unit/create-run-config.test.ts +66 -0
- package/src/__tests__/unit/publish-confirmation.test.ts +70 -0
- package/src/__tests__/unit/segmented-control.test.ts +152 -0
- package/src/__tests__/utils/env.test.ts +169 -0
- package/src/__tests__/utils/project-picker.test.ts +39 -0
- package/src/agents/bundled-agents.generated.d.ts +14 -0
- package/src/agents/bundled-agents.generated.ts +3692 -0
- package/src/app.tsx +399 -0
- package/src/chat.tsx +1698 -0
- package/src/cli-args.ts +134 -0
- package/src/commands/__tests__/bash-command.test.ts +445 -0
- package/src/commands/__tests__/command-args.test.ts +349 -0
- package/src/commands/__tests__/copy-conversation-clipboard.test.ts +108 -0
- package/src/commands/__tests__/copy-conversation.test.ts +226 -0
- package/src/commands/__tests__/diagnostics-command.test.ts +35 -0
- package/src/commands/__tests__/freebuff-command-aliases.test.ts +56 -0
- package/src/commands/__tests__/image.test.ts +99 -0
- package/src/commands/__tests__/init.test.ts +456 -0
- package/src/commands/__tests__/new-command-rotates-chat.test.ts +91 -0
- package/src/commands/__tests__/process-diagnostics.test.ts +54 -0
- package/src/commands/__tests__/prompt-builders.test.ts +28 -0
- package/src/commands/__tests__/router-input.test.ts +298 -0
- package/src/commands/ads.ts +44 -0
- package/src/commands/command-registry.ts +726 -0
- package/src/commands/copy-conversation.ts +392 -0
- package/src/commands/help.ts +13 -0
- package/src/commands/image.ts +20 -0
- package/src/commands/init.ts +121 -0
- package/src/commands/process-diagnostics.ts +120 -0
- package/src/commands/prompt-builders.ts +100 -0
- package/src/commands/publish.ts +203 -0
- package/src/commands/router-utils.ts +80 -0
- package/src/commands/router.ts +487 -0
- package/src/commands/usage.ts +26 -0
- package/src/components/__tests__/ad-banner.test.tsx +83 -0
- package/src/components/__tests__/chat-input-bar.test.tsx +130 -0
- package/src/components/__tests__/freebuff-landing-heading-row.test.tsx +91 -0
- package/src/components/__tests__/freebuff-model-selector.test.tsx +519 -0
- package/src/components/__tests__/freebuff-offer-invariants.test.ts +54 -0
- package/src/components/__tests__/freebuff-takeover-prompt.test.tsx +212 -0
- package/src/components/__tests__/grid-layout.integration.test.tsx +304 -0
- package/src/components/__tests__/grid-layout.test.tsx +1051 -0
- package/src/components/__tests__/message-block.completion.test.tsx +104 -0
- package/src/components/__tests__/message-block.streaming.test.tsx +78 -0
- package/src/components/__tests__/message-with-agents.test.tsx +579 -0
- package/src/components/__tests__/multiline-input.test.tsx +1132 -0
- package/src/components/__tests__/queue-panel.test.tsx +398 -0
- package/src/components/__tests__/selectable-list.test.ts +232 -0
- package/src/components/__tests__/status-bar.test.tsx +44 -0
- package/src/components/__tests__/status-indicator.test.tsx +204 -0
- package/src/components/__tests__/terminal-thinking-orb.test.tsx +111 -0
- package/src/components/__tests__/user-error-banner.test.tsx +102 -0
- package/src/components/ad-banner.tsx +323 -0
- package/src/components/agent-checklist.tsx +350 -0
- package/src/components/agent-mode-toggle.tsx +241 -0
- package/src/components/anvil-mark.tsx +52 -0
- package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +432 -0
- package/src/components/ask-user/__tests__/validation.test.ts +213 -0
- package/src/components/ask-user/components/accordion-question.tsx +153 -0
- package/src/components/ask-user/components/custom-answer-input.tsx +66 -0
- package/src/components/ask-user/components/options-list.tsx +133 -0
- package/src/components/ask-user/components/question-header.tsx +80 -0
- package/src/components/ask-user/components/question-option.tsx +89 -0
- package/src/components/ask-user/constants.ts +38 -0
- package/src/components/ask-user/index.tsx +631 -0
- package/src/components/ask-user/utils/validation.ts +85 -0
- package/src/components/attachment-card.tsx +65 -0
- package/src/components/blocks/agent-block-grid.tsx +58 -0
- package/src/components/blocks/agent-branch-item.tsx +311 -0
- package/src/components/blocks/agent-branch-wrapper.tsx +493 -0
- package/src/components/blocks/agent-list-branch.tsx +77 -0
- package/src/components/blocks/ask-user-branch.tsx +81 -0
- package/src/components/blocks/block-helpers.ts +11 -0
- package/src/components/blocks/blocks-renderer.tsx +289 -0
- package/src/components/blocks/content-with-markdown.tsx +33 -0
- package/src/components/blocks/image-block.tsx +128 -0
- package/src/components/blocks/implementor-row.tsx +429 -0
- package/src/components/blocks/single-block.tsx +201 -0
- package/src/components/blocks/thinking-block.tsx +67 -0
- package/src/components/blocks/tool-block-group.tsx +57 -0
- package/src/components/blocks/tool-branch.tsx +206 -0
- package/src/components/blocks/user-content-copy.tsx +157 -0
- package/src/components/bottom-banner.tsx +136 -0
- package/src/components/build-mode-buttons.tsx +110 -0
- package/src/components/button.tsx +66 -0
- package/src/components/chat-header.tsx +77 -0
- package/src/components/chat-history-screen.tsx +413 -0
- package/src/components/chat-input-bar.tsx +523 -0
- package/src/components/clickable-title-box.tsx +66 -0
- package/src/components/clickable.tsx +119 -0
- package/src/components/collapse-button.tsx +34 -0
- package/src/components/copy-button.tsx +203 -0
- package/src/components/elapsed-timer.tsx +55 -0
- package/src/components/error-boundary.tsx +55 -0
- package/src/components/feedback-container.tsx +181 -0
- package/src/components/feedback-icon-button.tsx +89 -0
- package/src/components/feedback-input-mode.tsx +344 -0
- package/src/components/file-attachment-card.tsx +98 -0
- package/src/components/freebuff-active-session-summary.tsx +63 -0
- package/src/components/freebuff-landing-screen.tsx +865 -0
- package/src/components/freebuff-model-selector.tsx +1087 -0
- package/src/components/freebuff-referral-banner.tsx +604 -0
- package/src/components/freebuff-superseded-screen.tsx +62 -0
- package/src/components/grid-layout.tsx +80 -0
- package/src/components/help-banner.tsx +127 -0
- package/src/components/highlighted-text.tsx +52 -0
- package/src/components/image-card.tsx +167 -0
- package/src/components/image-thumbnail.tsx +114 -0
- package/src/components/input-cursor.tsx +77 -0
- package/src/components/input-mode-banner.tsx +57 -0
- package/src/components/load-previous-button.tsx +48 -0
- package/src/components/login-modal.tsx +475 -0
- package/src/components/message-block.tsx +346 -0
- package/src/components/message-footer.tsx +258 -0
- package/src/components/message-with-agents.tsx +506 -0
- package/src/components/mode-divider.tsx +43 -0
- package/src/components/multiline-input.tsx +1241 -0
- package/src/components/out-of-credits-banner.tsx +160 -0
- package/src/components/pending-attachments-banner.tsx +116 -0
- package/src/components/pending-bash-message.tsx +59 -0
- package/src/components/progress-bar.tsx +81 -0
- package/src/components/project-picker-screen.tsx +485 -0
- package/src/components/publish-confirmation.tsx +493 -0
- package/src/components/publish-container.tsx +687 -0
- package/src/components/queue-panel.tsx +310 -0
- package/src/components/raised-pill.tsx +95 -0
- package/src/components/renderers/plan-box.tsx +59 -0
- package/src/components/review-screen.tsx +112 -0
- package/src/components/scroll-to-bottom-button.tsx +34 -0
- package/src/components/segmented-control.tsx +187 -0
- package/src/components/selectable-list.tsx +248 -0
- package/src/components/selected-chips.tsx +80 -0
- package/src/components/separator.tsx +40 -0
- package/src/components/session-ended-banner.tsx +226 -0
- package/src/components/shimmer-text.tsx +248 -0
- package/src/components/status-bar.tsx +313 -0
- package/src/components/subscription-limit-banner.tsx +206 -0
- package/src/components/suggested-prompts.tsx +184 -0
- package/src/components/suggestion-menu.tsx +215 -0
- package/src/components/terminal-command-display.tsx +151 -0
- package/src/components/terminal-link.tsx +97 -0
- package/src/components/terminal-thinking-orb.tsx +95 -0
- package/src/components/text-attachment-card.tsx +77 -0
- package/src/components/thinking.tsx +109 -0
- package/src/components/tools/__tests__/apply-patch.test.tsx +84 -0
- package/src/components/tools/__tests__/code-search.test.tsx +45 -0
- package/src/components/tools/__tests__/gravity-index.test.ts +76 -0
- package/src/components/tools/__tests__/render-ui.test.tsx +92 -0
- package/src/components/tools/__tests__/run-terminal-command.test.ts +233 -0
- package/src/components/tools/apply-patch.tsx +95 -0
- package/src/components/tools/code-search.tsx +45 -0
- package/src/components/tools/composio.tsx +152 -0
- package/src/components/tools/diff-viewer.tsx +76 -0
- package/src/components/tools/glob.tsx +61 -0
- package/src/components/tools/gravity-index.tsx +77 -0
- package/src/components/tools/list-directory.tsx +61 -0
- package/src/components/tools/read-docs.tsx +37 -0
- package/src/components/tools/read-files.tsx +91 -0
- package/src/components/tools/read-subtree.tsx +44 -0
- package/src/components/tools/read-url.tsx +33 -0
- package/src/components/tools/registry.ts +126 -0
- package/src/components/tools/render-ui.tsx +122 -0
- package/src/components/tools/run-terminal-command.tsx +79 -0
- package/src/components/tools/skill.tsx +29 -0
- package/src/components/tools/str-replace.tsx +77 -0
- package/src/components/tools/suggest-followups.tsx +369 -0
- package/src/components/tools/task-completed.tsx +16 -0
- package/src/components/tools/tool-call-item.tsx +273 -0
- package/src/components/tools/types.ts +55 -0
- package/src/components/tools/web-search.tsx +33 -0
- package/src/components/tools/write-file.tsx +16 -0
- package/src/components/tools/write-todos.tsx +95 -0
- package/src/components/top-banner.tsx +178 -0
- package/src/components/usage-banner.tsx +244 -0
- package/src/components/user-error-banner.tsx +56 -0
- package/src/components/validation-error-popover.tsx +192 -0
- package/src/contexts/__tests__/chat-runtime-context.test.tsx +149 -0
- package/src/contexts/chat-runtime-context.tsx +240 -0
- package/src/data/slash-commands.test.ts +24 -0
- package/src/data/slash-commands.ts +249 -0
- package/src/entry.ts +12 -0
- package/src/hooks/__tests__/holds-live-freebuff-slot.test.ts +49 -0
- package/src/hooks/__tests__/session-fetch-signal.test.ts +63 -0
- package/src/hooks/__tests__/use-activity-query.test.ts +1000 -0
- package/src/hooks/__tests__/use-ask-user-bridge.test.ts +176 -0
- package/src/hooks/__tests__/use-auth-query.test.ts +21 -0
- package/src/hooks/__tests__/use-chat-input-remount.test.tsx +66 -0
- package/src/hooks/__tests__/use-clipboard.test.tsx +73 -0
- package/src/hooks/__tests__/use-connection-status.test.ts +112 -0
- package/src/hooks/__tests__/use-directory-browser.test.ts +203 -0
- package/src/hooks/__tests__/use-gravity-ad.test.ts +73 -0
- package/src/hooks/__tests__/use-grid-layout.test.ts +349 -0
- package/src/hooks/__tests__/use-input-history.test.ts +699 -0
- package/src/hooks/__tests__/use-message-queue-editing.test.tsx +209 -0
- package/src/hooks/__tests__/use-message-queue.test.tsx +71 -0
- package/src/hooks/__tests__/use-path-tab-completion.test.ts +315 -0
- package/src/hooks/__tests__/use-queue-controls.test.ts +68 -0
- package/src/hooks/__tests__/use-queue-ui.test.tsx +83 -0
- package/src/hooks/__tests__/use-searchable-list.test.ts +359 -0
- package/src/hooks/__tests__/use-send-message-timer.test.ts +146 -0
- package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +361 -0
- package/src/hooks/__tests__/use-suggestion-engine.test.ts +485 -0
- package/src/hooks/__tests__/use-terminal-focus.test.ts +66 -0
- package/src/hooks/__tests__/use-terminal-layout.test.ts +675 -0
- package/src/hooks/__tests__/use-timeout.test.ts +330 -0
- package/src/hooks/__tests__/use-usage-query.test.ts +502 -0
- package/src/hooks/__tests__/use-user-details-query.test.ts +195 -0
- package/src/hooks/helpers/__tests__/send-message.test.ts +1918 -0
- package/src/hooks/helpers/send-message.ts +654 -0
- package/src/hooks/stream-state.ts +83 -0
- package/src/hooks/use-activity-query.ts +668 -0
- package/src/hooks/use-agent-validation.ts +74 -0
- package/src/hooks/use-ask-user-bridge.ts +92 -0
- package/src/hooks/use-auth-query.ts +253 -0
- package/src/hooks/use-auth-state.ts +152 -0
- package/src/hooks/use-chat-input.ts +105 -0
- package/src/hooks/use-chat-keyboard.ts +321 -0
- package/src/hooks/use-chat-messages.ts +254 -0
- package/src/hooks/use-chat-state.ts +165 -0
- package/src/hooks/use-chat-streaming.ts +180 -0
- package/src/hooks/use-chat-ui.ts +131 -0
- package/src/hooks/use-clipboard.ts +151 -0
- package/src/hooks/use-connection-status.ts +142 -0
- package/src/hooks/use-directory-browser.ts +88 -0
- package/src/hooks/use-elapsed-time.ts +116 -0
- package/src/hooks/use-event.ts +34 -0
- package/src/hooks/use-exit-handler.ts +66 -0
- package/src/hooks/use-fetch-login-url.ts +65 -0
- package/src/hooks/use-fingerprint.ts +61 -0
- package/src/hooks/use-freebuff-ctrl-c-exit.ts +23 -0
- package/src/hooks/use-freebuff-session-progress.ts +34 -0
- package/src/hooks/use-freebuff-session.ts +806 -0
- package/src/hooks/use-freebuff-streak-query.ts +61 -0
- package/src/hooks/use-gravity-ad.ts +656 -0
- package/src/hooks/use-grid-layout.ts +73 -0
- package/src/hooks/use-input-history.ts +173 -0
- package/src/hooks/use-login-keyboard-handlers.ts +75 -0
- package/src/hooks/use-login-polling.ts +114 -0
- package/src/hooks/use-logo.tsx +161 -0
- package/src/hooks/use-message-queue.ts +387 -0
- package/src/hooks/use-now.ts +20 -0
- package/src/hooks/use-path-tab-completion.ts +88 -0
- package/src/hooks/use-publish-mutation.ts +60 -0
- package/src/hooks/use-queue-controls.ts +68 -0
- package/src/hooks/use-queue-ui.ts +74 -0
- package/src/hooks/use-scroll-management.ts +184 -0
- package/src/hooks/use-searchable-list.ts +98 -0
- package/src/hooks/use-send-message.ts +773 -0
- package/src/hooks/use-sheen-animation.tsx +88 -0
- package/src/hooks/use-subscription-query.ts +71 -0
- package/src/hooks/use-suggestion-engine.ts +783 -0
- package/src/hooks/use-terminal-breakpoints.ts +77 -0
- package/src/hooks/use-terminal-dimensions.ts +46 -0
- package/src/hooks/use-terminal-focus.ts +29 -0
- package/src/hooks/use-terminal-layout.ts +189 -0
- package/src/hooks/use-theme.tsx +140 -0
- package/src/hooks/use-timeout.ts +85 -0
- package/src/hooks/use-update-preference.ts +66 -0
- package/src/hooks/use-usage-monitor.ts +55 -0
- package/src/hooks/use-usage-query.ts +124 -0
- package/src/hooks/use-user-details-query.ts +93 -0
- package/src/hooks/use-why-did-you-update.ts +177 -0
- package/src/index.tsx +441 -0
- package/src/init/__tests__/init-direnv.test.ts +526 -0
- package/src/init/init-app.ts +34 -0
- package/src/init/init-direnv.ts +133 -0
- package/src/login/constants.ts +60 -0
- package/src/login/login-flow.ts +204 -0
- package/src/login/plain-login.ts +108 -0
- package/src/login/utils.ts +183 -0
- package/src/native/ripgrep.ts +80 -0
- package/src/polyfills/bun-strip-ansi.ts +12 -0
- package/src/pre-init/tree-sitter-wasm.ts +96 -0
- package/src/project-files.ts +102 -0
- package/src/smoke/terminal-command-broker.ts +439 -0
- package/src/state/__tests__/chat-store-focus.test.ts +22 -0
- package/src/state/__tests__/feedback-store.test.ts +257 -0
- package/src/state/chat-history-store.ts +30 -0
- package/src/state/chat-store.ts +544 -0
- package/src/state/feedback-store.ts +160 -0
- package/src/state/freebuff-model-store.ts +42 -0
- package/src/state/freebuff-session-store.ts +53 -0
- package/src/state/login-store.ts +150 -0
- package/src/state/message-block-store.ts +149 -0
- package/src/state/publish-store.ts +146 -0
- package/src/state/queue-panel-store.ts +26 -0
- package/src/state/review-store.ts +24 -0
- package/src/testing/env.ts +46 -0
- package/src/types/chat-state.ts +15 -0
- package/src/types/chat.ts +241 -0
- package/src/types/contracts/send-message.ts +12 -0
- package/src/types/env.ts +98 -0
- package/src/types/freebuff-session.ts +17 -0
- package/src/types/function-params.ts +28 -0
- package/src/types/react19-compat.d.ts +19 -0
- package/src/types/store.ts +111 -0
- package/src/types/theme-system.ts +144 -0
- package/src/types/utils.ts +3 -0
- package/src/utils/__tests__/active-run.test.ts +140 -0
- package/src/utils/__tests__/activity-tracker.test.ts +440 -0
- package/src/utils/__tests__/agent-display.test.ts +139 -0
- package/src/utils/__tests__/analytics-client.test.ts +262 -0
- package/src/utils/__tests__/anonymous-id.test.ts +74 -0
- package/src/utils/__tests__/anvil-api.test.ts +578 -0
- package/src/utils/__tests__/arrays.test.ts +264 -0
- package/src/utils/__tests__/bash-context-processor.test.ts +38 -0
- package/src/utils/__tests__/block-processor.test.ts +810 -0
- package/src/utils/__tests__/chat-history.test.ts +203 -0
- package/src/utils/__tests__/chat-input-key-intercept.test.ts +40 -0
- package/src/utils/__tests__/chat-meta.test.ts +130 -0
- package/src/utils/__tests__/clipboard-linux.test.ts +359 -0
- package/src/utils/__tests__/clipboard.test.ts +910 -0
- package/src/utils/__tests__/code-search-summary.test.ts +84 -0
- package/src/utils/__tests__/collapse-helpers.test.ts +1109 -0
- package/src/utils/__tests__/error-handling.test.ts +658 -0
- package/src/utils/__tests__/exit-cleanly.test.ts +110 -0
- package/src/utils/__tests__/feedback-helpers.test.ts +444 -0
- package/src/utils/__tests__/feedback-submission.test.ts +26 -0
- package/src/utils/__tests__/fetch-usage.test.ts +355 -0
- package/src/utils/__tests__/fingerprint.test.ts +144 -0
- package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +7 -0
- package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +3 -0
- package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +33 -0
- package/src/utils/__tests__/format-elapsed-time.test.ts +103 -0
- package/src/utils/__tests__/format-timeout.test.ts +87 -0
- package/src/utils/__tests__/freebuff-instance-owner.test.ts +69 -0
- package/src/utils/__tests__/freebuff-model-navigation.test.ts +102 -0
- package/src/utils/__tests__/freebuff-premium-reset.test.ts +79 -0
- package/src/utils/__tests__/freebuff-referral-cache.test.ts +116 -0
- package/src/utils/__tests__/freebuff-session-api.test.ts +215 -0
- package/src/utils/__tests__/freebuff-session-display.test.ts +23 -0
- package/src/utils/__tests__/freebuff-streak-line.test.ts +217 -0
- package/src/utils/__tests__/image-dimensions.test.ts +249 -0
- package/src/utils/__tests__/image-processor.test.ts +209 -0
- package/src/utils/__tests__/implementor-helpers.test.ts +1458 -0
- package/src/utils/__tests__/keyboard-actions.test.ts +660 -0
- package/src/utils/__tests__/layout-helpers.test.ts +36 -0
- package/src/utils/__tests__/lazy-response-ads.test.ts +167 -0
- package/src/utils/__tests__/log-shipper.test.ts +53 -0
- package/src/utils/__tests__/markdown-renderer.test.tsx +421 -0
- package/src/utils/__tests__/message-block-helpers.test.ts +1263 -0
- package/src/utils/__tests__/message-updater.test.ts +645 -0
- package/src/utils/__tests__/osc-timeout-scenarios.test.ts +172 -0
- package/src/utils/__tests__/pending-attachments.test.ts +277 -0
- package/src/utils/__tests__/polling-backoff.test.ts +51 -0
- package/src/utils/__tests__/queue-panel-actions.test.ts +148 -0
- package/src/utils/__tests__/run-state-storage.test.ts +919 -0
- package/src/utils/__tests__/safe-json.test.ts +77 -0
- package/src/utils/__tests__/sdk-event-handlers.test.ts +685 -0
- package/src/utils/__tests__/send-message-helpers.test.ts +1898 -0
- package/src/utils/__tests__/send-message-timer.test.ts +64 -0
- package/src/utils/__tests__/settings.test.ts +99 -0
- package/src/utils/__tests__/strings.test.ts +192 -0
- package/src/utils/__tests__/terminal-color-detection.test.ts +425 -0
- package/src/utils/__tests__/terminal-command-broker.test.ts +528 -0
- package/src/utils/__tests__/terminal-enter-detection.test.ts +77 -0
- package/src/utils/__tests__/terminal-io.test.ts +137 -0
- package/src/utils/__tests__/terminal-protocol-controller.test.ts +119 -0
- package/src/utils/__tests__/text-layout.test.ts +82 -0
- package/src/utils/__tests__/theme-platform-detection.test.ts +125 -0
- package/src/utils/__tests__/think-tag-parser.test.ts +159 -0
- package/src/utils/__tests__/trace-writer.test.ts +223 -0
- package/src/utils/__tests__/trim-chat-logs.test.ts +78 -0
- package/src/utils/__tests__/usage-banner-state.test.ts +298 -0
- package/src/utils/__tests__/validation-error-formatting.test.ts +126 -0
- package/src/utils/__tests__/windows-terminal-health.test.ts +101 -0
- package/src/utils/__tests__/write-file-atomic.test.ts +127 -0
- package/src/utils/active-run.ts +131 -0
- package/src/utils/activity-tracker.ts +66 -0
- package/src/utils/agent-display.ts +87 -0
- package/src/utils/agent-helpers.ts +27 -0
- package/src/utils/agent-id-utils.ts +14 -0
- package/src/utils/ai-message-id.ts +12 -0
- package/src/utils/analytics.ts +361 -0
- package/src/utils/anonymous-id.ts +87 -0
- package/src/utils/anvil-api.ts +612 -0
- package/src/utils/anvil-client.ts +217 -0
- package/src/utils/arrays.ts +117 -0
- package/src/utils/auth.ts +258 -0
- package/src/utils/bash-context-processor.ts +47 -0
- package/src/utils/bash-messages.ts +108 -0
- package/src/utils/block-margins.ts +35 -0
- package/src/utils/block-operations.ts +523 -0
- package/src/utils/block-processor.ts +213 -0
- package/src/utils/chat-history.ts +253 -0
- package/src/utils/chat-input-key-intercept.ts +52 -0
- package/src/utils/chat-meta.ts +90 -0
- package/src/utils/chat-scroll-accel.ts +151 -0
- package/src/utils/clipboard-image.ts +588 -0
- package/src/utils/clipboard.ts +397 -0
- package/src/utils/code-search-summary.ts +70 -0
- package/src/utils/collapse-helpers.ts +256 -0
- package/src/utils/config-dir.ts +24 -0
- package/src/utils/constants.ts +190 -0
- package/src/utils/create-event-handler-state.ts +73 -0
- package/src/utils/create-run-config.ts +121 -0
- package/src/utils/detect-shell.ts +116 -0
- package/src/utils/directory-browser.ts +72 -0
- package/src/utils/engagement.ts +55 -0
- package/src/utils/env.ts +92 -0
- package/src/utils/error-handling.ts +255 -0
- package/src/utils/error-messages.ts +62 -0
- package/src/utils/exit-cleanly.ts +86 -0
- package/src/utils/feedback-helpers.ts +103 -0
- package/src/utils/feedback-submission.ts +22 -0
- package/src/utils/fetch-usage.ts +76 -0
- package/src/utils/fingerprint.ts +245 -0
- package/src/utils/format-elapsed-time.ts +33 -0
- package/src/utils/format-session-units.ts +6 -0
- package/src/utils/format-timeout.ts +28 -0
- package/src/utils/format-validation-errors-for-message.ts +84 -0
- package/src/utils/freebuff-agent-selection.ts +33 -0
- package/src/utils/freebuff-instance-owner.ts +66 -0
- package/src/utils/freebuff-model-navigation.ts +50 -0
- package/src/utils/freebuff-premium-reset.ts +55 -0
- package/src/utils/freebuff-referral-cache.ts +51 -0
- package/src/utils/freebuff-session-api.ts +243 -0
- package/src/utils/freebuff-session-display.ts +21 -0
- package/src/utils/freebuff-streak-line.ts +93 -0
- package/src/utils/git.ts +17 -0
- package/src/utils/helpers.ts +47 -0
- package/src/utils/image-display.ts +67 -0
- package/src/utils/image-handler.ts +325 -0
- package/src/utils/image-processor.ts +133 -0
- package/src/utils/image-thumbnail.ts +78 -0
- package/src/utils/implementor-helpers.ts +787 -0
- package/src/utils/input-modes.ts +174 -0
- package/src/utils/keyboard-actions.ts +392 -0
- package/src/utils/keypad-keys.ts +47 -0
- package/src/utils/layout-helpers.ts +33 -0
- package/src/utils/lazy-response-ads.ts +1 -0
- package/src/utils/local-agent-registry.ts +474 -0
- package/src/utils/log-shipper.ts +126 -0
- package/src/utils/logger.ts +327 -0
- package/src/utils/markdown-renderer.tsx +1090 -0
- package/src/utils/math.ts +3 -0
- package/src/utils/message-block-helpers.ts +684 -0
- package/src/utils/message-history.ts +143 -0
- package/src/utils/message-tree-utils.ts +67 -0
- package/src/utils/message-updater.ts +279 -0
- package/src/utils/open-file.ts +146 -0
- package/src/utils/open-url.ts +63 -0
- package/src/utils/path-completion.ts +111 -0
- package/src/utils/path-helpers.ts +38 -0
- package/src/utils/pending-attachments.ts +360 -0
- package/src/utils/polling-backoff.ts +59 -0
- package/src/utils/project-picker.ts +12 -0
- package/src/utils/queue-panel-actions.ts +70 -0
- package/src/utils/recent-projects.ts +156 -0
- package/src/utils/renderer-cleanup.ts +233 -0
- package/src/utils/response-ad-positions.ts +1 -0
- package/src/utils/run-state-storage.ts +603 -0
- package/src/utils/safe-json.ts +153 -0
- package/src/utils/sdk-event-handlers.ts +571 -0
- package/src/utils/send-message-helpers.ts +210 -0
- package/src/utils/send-message-timer.ts +110 -0
- package/src/utils/settings.ts +226 -0
- package/src/utils/skill-registry.ts +94 -0
- package/src/utils/spawn-agent-matcher.ts +55 -0
- package/src/utils/status-indicator-state.ts +107 -0
- package/src/utils/stream-chunk-processor.ts +57 -0
- package/src/utils/strings.ts +271 -0
- package/src/utils/subscription.ts +31 -0
- package/src/utils/syntax-highlighter.tsx +19 -0
- package/src/utils/terminal-color-detection.ts +474 -0
- package/src/utils/terminal-command-broker.ts +467 -0
- package/src/utils/terminal-enter-detection.ts +63 -0
- package/src/utils/terminal-images.ts +229 -0
- package/src/utils/terminal-io.ts +85 -0
- package/src/utils/terminal-protocol-controller.ts +173 -0
- package/src/utils/terminal-reset-sequences.ts +33 -0
- package/src/utils/terminal-title.ts +84 -0
- package/src/utils/terminal-watchdog.ts +366 -0
- package/src/utils/text-layout.ts +149 -0
- package/src/utils/theme-config.ts +141 -0
- package/src/utils/theme-system.ts +1206 -0
- package/src/utils/think-tag-parser.ts +95 -0
- package/src/utils/time-format.ts +21 -0
- package/src/utils/trace-writer.ts +162 -0
- package/src/utils/ui-constants.ts +69 -0
- package/src/utils/update-checker.ts +110 -0
- package/src/utils/usage-banner-state.ts +146 -0
- package/src/utils/validation-error-formatting.ts +86 -0
- package/src/utils/validation-error-helpers.ts +19 -0
- package/src/utils/windows-terminal-health.ts +124 -0
- package/src/utils/word-wrap-utils.ts +53 -0
- package/src/utils/write-file-atomic.ts +54 -0
- package/src/utils/yield-to-event-loop.ts +9 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { describe, test, expect, mock } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import type { InputValue } from '../types/store'
|
|
4
|
+
import type { InputMode } from '../utils/input-modes'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tests for bash mode functionality in the CLI.
|
|
8
|
+
*
|
|
9
|
+
* Bash mode is entered when user types '!' and allows running terminal commands.
|
|
10
|
+
* The '!' is displayed in a green column but not stored in the input value.
|
|
11
|
+
*
|
|
12
|
+
* Key behaviors:
|
|
13
|
+
* 1. Typing '!' enters bash mode and clears input to ''
|
|
14
|
+
* 2. In bash mode, input is stored WITHOUT '!' prefix
|
|
15
|
+
* 3. Backspace at cursor position 0 exits bash mode (even with input)
|
|
16
|
+
* 4. Submission prepends '!' to the command
|
|
17
|
+
*
|
|
18
|
+
* Note: Tests for runBashCommand and /bash slash command are in
|
|
19
|
+
* cli/src/commands/__tests__/bash-command.test.ts
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
describe('bash-mode', () => {
|
|
23
|
+
describe('entering bash mode', () => {
|
|
24
|
+
test('typing exactly "!" enters bash mode and clears input', () => {
|
|
25
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
26
|
+
const setInputValue = mock((_value: Partial<InputValue>) => {})
|
|
27
|
+
|
|
28
|
+
// Simulate user typing '!'
|
|
29
|
+
const inputValue = {
|
|
30
|
+
text: '!',
|
|
31
|
+
cursorPosition: 1,
|
|
32
|
+
lastEditDueToNav: false,
|
|
33
|
+
}
|
|
34
|
+
const inputMode: InputMode = 'default'
|
|
35
|
+
|
|
36
|
+
// This simulates the handleInputChange logic
|
|
37
|
+
const userTypedBang = inputMode === 'default' && inputValue.text === '!'
|
|
38
|
+
|
|
39
|
+
if (userTypedBang) {
|
|
40
|
+
setInputMode('bash')
|
|
41
|
+
const newValue = {
|
|
42
|
+
text: '',
|
|
43
|
+
cursorPosition: 0,
|
|
44
|
+
lastEditDueToNav: inputValue.lastEditDueToNav,
|
|
45
|
+
}
|
|
46
|
+
setInputValue(newValue)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(setInputMode).toHaveBeenCalledWith('bash')
|
|
50
|
+
expect(setInputValue).toHaveBeenCalled()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('typing "!ls" does NOT enter bash mode (not exactly "!")', () => {
|
|
54
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
55
|
+
const setInputValue = mock((_value: Partial<InputValue>) => {})
|
|
56
|
+
|
|
57
|
+
// Simulate user typing '!ls'
|
|
58
|
+
const inputValue = {
|
|
59
|
+
text: '!ls',
|
|
60
|
+
cursorPosition: 3,
|
|
61
|
+
lastEditDueToNav: false,
|
|
62
|
+
}
|
|
63
|
+
const inputMode: InputMode = 'default'
|
|
64
|
+
|
|
65
|
+
const userTypedBang = inputMode === 'default' && inputValue.text === '!'
|
|
66
|
+
|
|
67
|
+
if (userTypedBang) {
|
|
68
|
+
setInputMode('bash')
|
|
69
|
+
const newValue = {
|
|
70
|
+
text: '',
|
|
71
|
+
cursorPosition: 0,
|
|
72
|
+
lastEditDueToNav: inputValue.lastEditDueToNav,
|
|
73
|
+
}
|
|
74
|
+
setInputValue(newValue)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
expect(setInputMode).not.toHaveBeenCalled()
|
|
78
|
+
expect(setInputValue).not.toHaveBeenCalled()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('typing "!" when already in bash mode does nothing special', () => {
|
|
82
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
83
|
+
const setInputValue = mock((_value: Partial<InputValue>) => {})
|
|
84
|
+
|
|
85
|
+
const inputValue = {
|
|
86
|
+
text: '!',
|
|
87
|
+
cursorPosition: 1,
|
|
88
|
+
lastEditDueToNav: false,
|
|
89
|
+
}
|
|
90
|
+
const inputMode = 'bash' as InputMode
|
|
91
|
+
|
|
92
|
+
const userTypedBang =
|
|
93
|
+
inputMode === ('default' as InputMode) && inputValue.text === '!'
|
|
94
|
+
|
|
95
|
+
if (userTypedBang) {
|
|
96
|
+
setInputMode('bash')
|
|
97
|
+
const newValue = {
|
|
98
|
+
text: '',
|
|
99
|
+
cursorPosition: 0,
|
|
100
|
+
lastEditDueToNav: inputValue.lastEditDueToNav,
|
|
101
|
+
}
|
|
102
|
+
setInputValue(newValue)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Should not trigger because already in bash mode
|
|
106
|
+
expect(setInputMode).not.toHaveBeenCalled()
|
|
107
|
+
expect(setInputValue).not.toHaveBeenCalled()
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
describe('exiting bash mode', () => {
|
|
112
|
+
test('backspace at cursor position 0 exits bash mode', () => {
|
|
113
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
114
|
+
|
|
115
|
+
// Simulate backspace key press in bash mode at cursor position 0
|
|
116
|
+
const inputMode: InputMode = 'bash'
|
|
117
|
+
const cursorPosition = 0
|
|
118
|
+
const key = { name: 'backspace' }
|
|
119
|
+
|
|
120
|
+
// This simulates the handleSuggestionMenuKey logic
|
|
121
|
+
if (
|
|
122
|
+
inputMode === 'bash' &&
|
|
123
|
+
cursorPosition === 0 &&
|
|
124
|
+
key.name === 'backspace'
|
|
125
|
+
) {
|
|
126
|
+
setInputMode('default')
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
expect(setInputMode).toHaveBeenCalledWith('default')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('backspace at cursor position 0 with non-empty input DOES exit bash mode', () => {
|
|
133
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
134
|
+
|
|
135
|
+
const inputMode: InputMode = 'bash'
|
|
136
|
+
const cursorPosition = 0
|
|
137
|
+
const key = { name: 'backspace' }
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
inputMode === 'bash' &&
|
|
141
|
+
cursorPosition === 0 &&
|
|
142
|
+
key.name === 'backspace'
|
|
143
|
+
) {
|
|
144
|
+
setInputMode('default')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Should exit even though input is not empty, because cursor is at position 0
|
|
148
|
+
expect(setInputMode).toHaveBeenCalledWith('default')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('backspace at cursor position > 0 does NOT exit bash mode', () => {
|
|
152
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
153
|
+
|
|
154
|
+
const inputMode: InputMode = 'bash'
|
|
155
|
+
const cursorPosition: number = 2
|
|
156
|
+
const key = { name: 'backspace' }
|
|
157
|
+
|
|
158
|
+
if (
|
|
159
|
+
inputMode === 'bash' &&
|
|
160
|
+
cursorPosition === 0 &&
|
|
161
|
+
key.name === 'backspace'
|
|
162
|
+
) {
|
|
163
|
+
setInputMode('default')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Should not exit because cursor is not at position 0
|
|
167
|
+
expect(setInputMode).not.toHaveBeenCalled()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('other keys at cursor position 0 do NOT exit bash mode', () => {
|
|
171
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
172
|
+
|
|
173
|
+
const inputMode: InputMode = 'bash'
|
|
174
|
+
const cursorPosition = 0
|
|
175
|
+
const key = { name: 'a' } // Regular key press
|
|
176
|
+
|
|
177
|
+
if (
|
|
178
|
+
inputMode === 'bash' &&
|
|
179
|
+
cursorPosition === 0 &&
|
|
180
|
+
key.name === 'backspace'
|
|
181
|
+
) {
|
|
182
|
+
setInputMode('default')
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Should not exit because key is not backspace
|
|
186
|
+
expect(setInputMode).not.toHaveBeenCalled()
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('backspace when NOT in bash mode does nothing to bash mode', () => {
|
|
190
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
191
|
+
|
|
192
|
+
const inputMode = 'default' as InputMode
|
|
193
|
+
const cursorPosition = 0
|
|
194
|
+
const key = { name: 'backspace' }
|
|
195
|
+
|
|
196
|
+
if (
|
|
197
|
+
inputMode === ('bash' as InputMode) &&
|
|
198
|
+
cursorPosition === 0 &&
|
|
199
|
+
key.name === 'backspace'
|
|
200
|
+
) {
|
|
201
|
+
setInputMode('default')
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Should not trigger because not in bash mode
|
|
205
|
+
expect(setInputMode).not.toHaveBeenCalled()
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('bash mode input storage', () => {
|
|
210
|
+
test('input value does NOT include "!" prefix while in bash mode', () => {
|
|
211
|
+
// When user types "ls" in bash mode, inputValue.text should be "ls", not "!ls"
|
|
212
|
+
const inputMode: InputMode = 'bash'
|
|
213
|
+
const inputValue = 'ls -la'
|
|
214
|
+
|
|
215
|
+
// The stored value should NOT have the '!' prefix
|
|
216
|
+
expect(inputValue).toBe('ls -la')
|
|
217
|
+
expect(inputValue).not.toContain('!')
|
|
218
|
+
expect(inputMode).toBe('bash')
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('normal mode input can contain "!" anywhere', () => {
|
|
222
|
+
const inputValue = 'fix this bug!'
|
|
223
|
+
|
|
224
|
+
// In normal mode, '!' is just a regular character
|
|
225
|
+
expect(inputValue).toContain('!')
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
describe('bash mode submission', () => {
|
|
230
|
+
test('submitting bash command prepends "!" to the stored value', () => {
|
|
231
|
+
const inputMode: InputMode = 'bash'
|
|
232
|
+
const trimmedInput = 'ls -la' // The stored value WITHOUT '!'
|
|
233
|
+
|
|
234
|
+
// Router logic prepends '!' when in bash mode
|
|
235
|
+
const commandWithBang =
|
|
236
|
+
inputMode === 'bash' ? '!' + trimmedInput : trimmedInput
|
|
237
|
+
|
|
238
|
+
expect(commandWithBang).toBe('!ls -la')
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('submission displays "!" in user message', () => {
|
|
242
|
+
const inputMode: InputMode = 'bash'
|
|
243
|
+
const trimmedInput = 'pwd'
|
|
244
|
+
const commandWithBang =
|
|
245
|
+
inputMode === 'bash' ? '!' + trimmedInput : trimmedInput
|
|
246
|
+
|
|
247
|
+
// The user message should show the command WITH '!'
|
|
248
|
+
const userMessage = { content: commandWithBang }
|
|
249
|
+
|
|
250
|
+
expect(userMessage.content).toBe('!pwd')
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('submission saves command WITH "!" to history', () => {
|
|
254
|
+
const saveToHistory = mock((_command: string) => {})
|
|
255
|
+
const trimmedInput = 'git status'
|
|
256
|
+
const commandWithBang = '!' + trimmedInput
|
|
257
|
+
|
|
258
|
+
// History should save the full command with '!'
|
|
259
|
+
saveToHistory(commandWithBang)
|
|
260
|
+
|
|
261
|
+
expect(saveToHistory).toHaveBeenCalledWith('!git status')
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
test('submission exits bash mode after running command', () => {
|
|
265
|
+
const setInputMode = mock((_mode: InputMode) => {})
|
|
266
|
+
|
|
267
|
+
// After submission, bash mode should be exited
|
|
268
|
+
setInputMode('default')
|
|
269
|
+
|
|
270
|
+
expect(setInputMode).toHaveBeenCalledWith('default')
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
test('terminal command receives value WITHOUT "!" prefix', () => {
|
|
274
|
+
const runTerminalCommand = mock((_params: Record<string, unknown>) =>
|
|
275
|
+
Promise.resolve([{ value: { stdout: 'output' } }]),
|
|
276
|
+
)
|
|
277
|
+
const trimmedInput = 'echo hello'
|
|
278
|
+
|
|
279
|
+
// The actual terminal command should NOT include the '!'
|
|
280
|
+
runTerminalCommand({
|
|
281
|
+
command: trimmedInput,
|
|
282
|
+
process_type: 'SYNC',
|
|
283
|
+
cwd: process.cwd(),
|
|
284
|
+
timeout_seconds: -1,
|
|
285
|
+
env: process.env,
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
expect(runTerminalCommand).toHaveBeenCalledWith(
|
|
289
|
+
expect.objectContaining({ command: 'echo hello' }),
|
|
290
|
+
)
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
describe('bash mode UI state', () => {
|
|
295
|
+
test('input mode is stored separately from input value', () => {
|
|
296
|
+
// The inputMode is independent of the input text
|
|
297
|
+
const state1: { inputMode: InputMode; inputValue: string } = {
|
|
298
|
+
inputMode: 'bash',
|
|
299
|
+
inputValue: 'ls',
|
|
300
|
+
}
|
|
301
|
+
const state2: { inputMode: InputMode; inputValue: string } = {
|
|
302
|
+
inputMode: 'default',
|
|
303
|
+
inputValue: 'hello',
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
expect(state1.inputMode).toBe('bash')
|
|
307
|
+
expect(state1.inputValue).not.toContain('!')
|
|
308
|
+
|
|
309
|
+
expect(state2.inputMode).toBe('default')
|
|
310
|
+
expect(state2.inputValue).not.toContain('!')
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('input width is adjusted in bash mode for "!" column', () => {
|
|
314
|
+
const baseInputWidth = 100
|
|
315
|
+
const inputModeValue: InputMode = 'bash'
|
|
316
|
+
|
|
317
|
+
// Width should be reduced by 2 to account for '!' and spacing
|
|
318
|
+
const adjustedInputWidth =
|
|
319
|
+
inputModeValue === 'bash' ? baseInputWidth - 2 : baseInputWidth
|
|
320
|
+
|
|
321
|
+
expect(adjustedInputWidth).toBe(98)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
test('input width is NOT adjusted when not in bash mode', () => {
|
|
325
|
+
const baseInputWidth = 100
|
|
326
|
+
const inputModeValue = 'default' as InputMode
|
|
327
|
+
|
|
328
|
+
const adjustedInputWidth =
|
|
329
|
+
inputModeValue === ('bash' as InputMode)
|
|
330
|
+
? baseInputWidth - 2
|
|
331
|
+
: baseInputWidth
|
|
332
|
+
|
|
333
|
+
expect(adjustedInputWidth).toBe(100)
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
test('placeholder changes in bash mode', () => {
|
|
337
|
+
const normalPlaceholder = 'Ask Buffy anything...'
|
|
338
|
+
const bashPlaceholder = 'enter bash command...'
|
|
339
|
+
const inputMode: InputMode = 'bash'
|
|
340
|
+
|
|
341
|
+
const effectivePlaceholder =
|
|
342
|
+
inputMode === 'bash' ? bashPlaceholder : normalPlaceholder
|
|
343
|
+
|
|
344
|
+
expect(effectivePlaceholder).toBe('enter bash command...')
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
test('placeholder is normal when not in bash mode', () => {
|
|
348
|
+
const normalPlaceholder = 'Ask Buffy anything...'
|
|
349
|
+
const bashPlaceholder = 'enter bash command...'
|
|
350
|
+
const inputMode = 'default' as InputMode
|
|
351
|
+
|
|
352
|
+
const effectivePlaceholder =
|
|
353
|
+
inputMode === ('bash' as InputMode)
|
|
354
|
+
? bashPlaceholder
|
|
355
|
+
: normalPlaceholder
|
|
356
|
+
|
|
357
|
+
expect(effectivePlaceholder).toBe('Ask Buffy anything...')
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
describe('edge cases', () => {
|
|
362
|
+
test('empty string is NOT the same as "!"', () => {
|
|
363
|
+
const inputMode: InputMode = 'default'
|
|
364
|
+
const inputValue: string = ''
|
|
365
|
+
const exclamation = '!'
|
|
366
|
+
const inputEqualsExclamation = inputValue === exclamation
|
|
367
|
+
|
|
368
|
+
expect(inputEqualsExclamation).toBe(false)
|
|
369
|
+
expect(inputMode).toBe('default')
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('whitespace around "!" prevents bash mode entry', () => {
|
|
373
|
+
const exclamation = '!'
|
|
374
|
+
const inputValue1: string = ' !'
|
|
375
|
+
const inputValue2: string = '! '
|
|
376
|
+
const inputValue3: string = ' ! '
|
|
377
|
+
|
|
378
|
+
const match1 = inputValue1 === exclamation
|
|
379
|
+
const match2 = inputValue2 === exclamation
|
|
380
|
+
const match3 = inputValue3 === exclamation
|
|
381
|
+
|
|
382
|
+
expect(match1).toBe(false)
|
|
383
|
+
expect(match2).toBe(false)
|
|
384
|
+
expect(match3).toBe(false)
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
test('multiple "!" characters do not enter bash mode', () => {
|
|
388
|
+
const inputValue: string = '!!'
|
|
389
|
+
const exclamation = '!'
|
|
390
|
+
const inputEqualsExclamation = inputValue === exclamation
|
|
391
|
+
|
|
392
|
+
expect(inputEqualsExclamation).toBe(false)
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
test('mode can be entered, exited, and re-entered', () => {
|
|
396
|
+
let inputMode: InputMode = 'default'
|
|
397
|
+
|
|
398
|
+
// Enter bash mode
|
|
399
|
+
inputMode = 'bash'
|
|
400
|
+
expect(inputMode).toBe('bash')
|
|
401
|
+
|
|
402
|
+
// Exit bash mode
|
|
403
|
+
inputMode = 'default'
|
|
404
|
+
expect(inputMode).toBe('default')
|
|
405
|
+
|
|
406
|
+
// Re-enter bash mode
|
|
407
|
+
inputMode = 'bash'
|
|
408
|
+
expect(inputMode).toBe('bash')
|
|
409
|
+
})
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
describe('integration with command router', () => {
|
|
413
|
+
test('bash mode commands are routed differently than normal prompts', () => {
|
|
414
|
+
const inputMode: InputMode = 'bash'
|
|
415
|
+
|
|
416
|
+
// In bash mode, commands should be handled by terminal execution
|
|
417
|
+
// Not by the LLM agent
|
|
418
|
+
expect(inputMode).toBe('bash')
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
test('normal commands starting with "!" are NOT bash commands', () => {
|
|
422
|
+
const inputMode = 'default' as InputMode
|
|
423
|
+
const inputValue = '!ls' // User typed this in normal mode
|
|
424
|
+
|
|
425
|
+
// This should be treated as a normal prompt, not a bash command
|
|
426
|
+
// because bash mode was not activated
|
|
427
|
+
expect(inputMode).toBe('default')
|
|
428
|
+
expect(inputValue).toBe('!ls')
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
test('bash mode takes precedence over slash commands', () => {
|
|
432
|
+
const inputMode = 'bash' as InputMode
|
|
433
|
+
const trimmedInput = '/help' // Looks like a slash command
|
|
434
|
+
|
|
435
|
+
// But in bash mode, it's just a bash command
|
|
436
|
+
if (inputMode === ('bash' as InputMode)) {
|
|
437
|
+
const commandWithBang = '!' + trimmedInput
|
|
438
|
+
expect(commandWithBang).toBe('!/help')
|
|
439
|
+
}
|
|
440
|
+
})
|
|
441
|
+
})
|
|
442
|
+
})
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach, afterEach } from 'bun:test'
|
|
2
|
+
import { Command } from 'commander'
|
|
3
|
+
|
|
4
|
+
import { parseArgs } from '../cli-args'
|
|
5
|
+
|
|
6
|
+
describe('CLI Argument Parsing', () => {
|
|
7
|
+
let originalArgv: string[]
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
originalArgv = process.argv
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
process.argv = originalArgv
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function parseTestArgs(args: string[]) {
|
|
18
|
+
process.argv = ['node', 'codecane', ...args]
|
|
19
|
+
|
|
20
|
+
const program = new Command()
|
|
21
|
+
program
|
|
22
|
+
.name('codecane')
|
|
23
|
+
.version('1.0.0', '-v, --version', 'Print the CLI version')
|
|
24
|
+
.option('--agent <agent-id>', 'Specify which agent to use')
|
|
25
|
+
.option('--clear-logs', 'Remove any existing CLI log files')
|
|
26
|
+
.argument('[prompt...]', 'Initial prompt to send')
|
|
27
|
+
.allowExcessArguments(true)
|
|
28
|
+
.exitOverride() // Prevent process.exit in tests
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
program.parse(process.argv)
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// Commander throws on --help, --version in exitOverride mode
|
|
34
|
+
if (error instanceof Error && error.message.includes('(outputHelp)')) {
|
|
35
|
+
return { help: true }
|
|
36
|
+
}
|
|
37
|
+
if (
|
|
38
|
+
error instanceof Error &&
|
|
39
|
+
(error.message.includes('(version)') || error.message.includes('1.0.0'))
|
|
40
|
+
) {
|
|
41
|
+
return { version: true }
|
|
42
|
+
}
|
|
43
|
+
throw error
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const options = program.opts()
|
|
47
|
+
const promptArgs = program.args
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
agent: options.agent,
|
|
51
|
+
clearLogs: options.clearLogs || false,
|
|
52
|
+
initialPrompt: promptArgs.length > 0 ? promptArgs.join(' ') : null,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test('parses --agent flag correctly', () => {
|
|
57
|
+
const result = parseTestArgs([
|
|
58
|
+
'--agent',
|
|
59
|
+
'file-picker',
|
|
60
|
+
'find all TypeScript files',
|
|
61
|
+
])
|
|
62
|
+
expect(result.agent).toBe('file-picker')
|
|
63
|
+
expect(result.initialPrompt).toBe('find all TypeScript files')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('parses --agent with full agent ID', () => {
|
|
67
|
+
const result = parseTestArgs([
|
|
68
|
+
'--agent',
|
|
69
|
+
'anvil/base-lite@1.0.0',
|
|
70
|
+
'hello',
|
|
71
|
+
])
|
|
72
|
+
expect(result.agent).toBe('anvil/base-lite@1.0.0')
|
|
73
|
+
expect(result.initialPrompt).toBe('hello')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('works without --agent flag (defaults to base)', () => {
|
|
77
|
+
const result = parseTestArgs(['create a new component'])
|
|
78
|
+
expect(result.agent).toBeUndefined()
|
|
79
|
+
expect(result.initialPrompt).toBe('create a new component')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('parses --clear-logs flag', () => {
|
|
83
|
+
const result = parseTestArgs(['--clear-logs', 'hello'])
|
|
84
|
+
expect(result.clearLogs).toBe(true)
|
|
85
|
+
expect(result.initialPrompt).toBe('hello')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('handles multiple flags together', () => {
|
|
89
|
+
const result = parseTestArgs([
|
|
90
|
+
'--agent',
|
|
91
|
+
'reviewer',
|
|
92
|
+
'--clear-logs',
|
|
93
|
+
'review my code',
|
|
94
|
+
])
|
|
95
|
+
expect(result.agent).toBe('reviewer')
|
|
96
|
+
expect(result.clearLogs).toBe(true)
|
|
97
|
+
expect(result.initialPrompt).toBe('review my code')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('handles prompt with no flags', () => {
|
|
101
|
+
const result = parseTestArgs(['this is a test prompt'])
|
|
102
|
+
expect(result.agent).toBeUndefined()
|
|
103
|
+
expect(result.clearLogs).toBe(false)
|
|
104
|
+
expect(result.initialPrompt).toBe('this is a test prompt')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('handles empty arguments', () => {
|
|
108
|
+
const result = parseTestArgs([])
|
|
109
|
+
expect(result.agent).toBeUndefined()
|
|
110
|
+
expect(result.clearLogs).toBe(false)
|
|
111
|
+
expect(result.initialPrompt).toBeNull()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('handles multi-word prompt', () => {
|
|
115
|
+
const result = parseTestArgs([
|
|
116
|
+
'--agent',
|
|
117
|
+
'base',
|
|
118
|
+
'fix the bug in auth.ts file',
|
|
119
|
+
])
|
|
120
|
+
expect(result.agent).toBe('base')
|
|
121
|
+
expect(result.initialPrompt).toBe('fix the bug in auth.ts file')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('handles --help flag', () => {
|
|
125
|
+
const result = parseTestArgs(['--help'])
|
|
126
|
+
expect(result.help).toBe(true)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('handles -h flag', () => {
|
|
130
|
+
const result = parseTestArgs(['-h'])
|
|
131
|
+
expect(result.help).toBe(true)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('handles --version flag', () => {
|
|
135
|
+
const result = parseTestArgs(['--version'])
|
|
136
|
+
expect(result.version).toBe(true)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('handles -v flag', () => {
|
|
140
|
+
const result = parseTestArgs(['-v'])
|
|
141
|
+
expect(result.version).toBe(true)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('Freebuff CLI Argument Parsing', () => {
|
|
146
|
+
test('accepts login as a command, not an unexpected argument', () => {
|
|
147
|
+
const result = parseArgs({
|
|
148
|
+
argv: ['node', 'freebuff', 'login'],
|
|
149
|
+
isFreebuff: true,
|
|
150
|
+
version: '1.0.0',
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
expect(result.initialPrompt).toBeNull()
|
|
154
|
+
expect(result.command).toBe('login')
|
|
155
|
+
expect(result.initialMode).toBe('LITE')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('allows cwd before the login command', () => {
|
|
159
|
+
const result = parseArgs({
|
|
160
|
+
argv: ['node', 'freebuff', '--cwd', '/tmp', 'login'],
|
|
161
|
+
isFreebuff: true,
|
|
162
|
+
version: '1.0.0',
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
expect(result.cwd).toBe('/tmp')
|
|
166
|
+
expect(result.command).toBe('login')
|
|
167
|
+
expect(result.initialPrompt).toBeNull()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('allows cwd after the login command', () => {
|
|
171
|
+
const result = parseArgs({
|
|
172
|
+
argv: ['node', 'freebuff', 'login', '--cwd', '/tmp'],
|
|
173
|
+
isFreebuff: true,
|
|
174
|
+
version: '1.0.0',
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
expect(result.cwd).toBe('/tmp')
|
|
178
|
+
expect(result.command).toBe('login')
|
|
179
|
+
expect(result.initialPrompt).toBeNull()
|
|
180
|
+
})
|
|
181
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { FREEBUFF_DEEPSEEK_V4_FLASH_MODEL_ID } from '@anvil/common/constants/freebuff-models'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AGENT_MODE_TO_ID,
|
|
6
|
+
AGENT_MODES,
|
|
7
|
+
CLI_HARNESS,
|
|
8
|
+
IS_FREEBUFF,
|
|
9
|
+
} from '../utils/constants'
|
|
10
|
+
import { getFreebuffCliAgentIdForModel } from '../utils/freebuff-agent-selection'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Which harness real CLI turns run.
|
|
14
|
+
*
|
|
15
|
+
* `CLI_HARNESS` routes Anvil DEFAULT and LITE plus every Freebuff picker
|
|
16
|
+
* model to base3 (docs/freebuff-base3-harness.md).
|
|
17
|
+
*
|
|
18
|
+
* The values below are written out rather than derived from `CLI_HARNESS`, and
|
|
19
|
+
* that is the entire point: an expectation computed from the constant would
|
|
20
|
+
* follow it and pass either way. Switching harness has to fail here and be
|
|
21
|
+
* updated deliberately, with the benchmark that justifies it.
|
|
22
|
+
*/
|
|
23
|
+
describe('CLI harness routing', () => {
|
|
24
|
+
test('DEFAULT, LITE, and Freebuff turns run base3', () => {
|
|
25
|
+
expect(CLI_HARNESS).toBe('base3')
|
|
26
|
+
expect(AGENT_MODE_TO_ID.DEFAULT).toBe('base3')
|
|
27
|
+
// Freebuff overrides LITE per selected model at send time
|
|
28
|
+
// (getAgentIdForMode); this constant is the non-runtime fallback, so it is
|
|
29
|
+
// the paid Anvil value that tracks the harness.
|
|
30
|
+
// IS_FREEBUFF is a build flag, not the harness — deriving from it is fine.
|
|
31
|
+
expect(AGENT_MODE_TO_ID.LITE).toBe(
|
|
32
|
+
IS_FREEBUFF ? 'base2-free' : 'base3-lite',
|
|
33
|
+
)
|
|
34
|
+
expect(
|
|
35
|
+
getFreebuffCliAgentIdForModel(FREEBUFF_DEEPSEEK_V4_FLASH_MODEL_ID),
|
|
36
|
+
).toBe('base3-free-deepseek-flash')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('MAX and PLAN never followed the harness switch', () => {
|
|
40
|
+
// MAX's multi-prompt editor and reviewer fan-out are what the mode is for,
|
|
41
|
+
// and PLAN's <PLAN> extraction is tuned against base2's plan-only prompt.
|
|
42
|
+
expect(AGENT_MODE_TO_ID.MAX).toBe('base2-max')
|
|
43
|
+
expect(AGENT_MODE_TO_ID.PLAN).toBe('base2-plan')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('every mode still resolves to an agent id', () => {
|
|
47
|
+
expect(AGENT_MODES).toEqual(['DEFAULT', 'LITE', 'MAX', 'PLAN'])
|
|
48
|
+
for (const mode of AGENT_MODES) {
|
|
49
|
+
expect(AGENT_MODE_TO_ID[mode]).toBeTruthy()
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|