@alumbwe/anvil 1.0.0 → 1.0.2
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/bin/anvil.js +2 -0
- package/dist/bundled.js +79559 -0
- package/dist/bundled.js.map +581 -0
- package/package.json +7 -4
- package/bin/anvil +0 -2
- package/src/__tests__/README.md +0 -256
- package/src/__tests__/bash-mode.test.ts +0 -442
- package/src/__tests__/cli-args.test.ts +0 -181
- package/src/__tests__/cli-harness.test.ts +0 -52
- package/src/__tests__/e2e/first-time-login.test.ts +0 -173
- package/src/__tests__/e2e/logout-relogin-flow.test.ts +0 -110
- package/src/__tests__/e2e/returning-user-auth.test.ts +0 -113
- package/src/__tests__/e2e-cli.test.ts +0 -183
- package/src/__tests__/helpers/launcher-disconnect-fixture.cjs +0 -176
- package/src/__tests__/helpers/mock-api-client.ts +0 -64
- package/src/__tests__/helpers/renderer-cleanup-fixture.tsx +0 -89
- package/src/__tests__/helpers/terminal-watchdog-fixture.ts +0 -75
- package/src/__tests__/home-directory-detection.test.ts +0 -213
- package/src/__tests__/integration/api-integration.test.ts +0 -288
- package/src/__tests__/integration/credentials-storage.test.ts +0 -486
- package/src/__tests__/integration/local-agents.test.ts +0 -1187
- package/src/__tests__/integration/login-flow-instrumentation.test.ts +0 -134
- package/src/__tests__/integration/login-polling-working.test.ts +0 -285
- package/src/__tests__/integration/queue-editing.test.tsx +0 -261
- package/src/__tests__/integration/usage-refresh-on-completion.test.ts +0 -168
- package/src/__tests__/integration-tmux.test.ts +0 -188
- package/src/__tests__/launcher-avx2-fallback.test.ts +0 -630
- package/src/__tests__/launcher-disconnect.test.ts +0 -104
- package/src/__tests__/mocks/hover-toggle-controller.ts +0 -71
- package/src/__tests__/open-tui-native-bundle.test.ts +0 -378
- package/src/__tests__/path-completion.test.ts +0 -243
- package/src/__tests__/project-files-chat-id.test.ts +0 -34
- package/src/__tests__/release/proxy-http-get.test.ts +0 -667
- package/src/__tests__/release/wrapper-safety.test.ts +0 -412
- package/src/__tests__/renderer-cleanup.test.ts +0 -174
- package/src/__tests__/rerender-perf.integration.test.ts +0 -283
- package/src/__tests__/terminal-reset-sequences.test.ts +0 -36
- package/src/__tests__/terminal-watchdog.test.ts +0 -388
- package/src/__tests__/test-utils.ts +0 -271
- package/src/__tests__/tmux-poc.ts +0 -150
- package/src/__tests__/unit/agent-mode-toggle.test.ts +0 -137
- package/src/__tests__/unit/copy-button.test.ts +0 -157
- package/src/__tests__/unit/create-run-config.test.ts +0 -66
- package/src/__tests__/unit/publish-confirmation.test.ts +0 -70
- package/src/__tests__/unit/segmented-control.test.ts +0 -152
- package/src/__tests__/utils/env.test.ts +0 -169
- package/src/__tests__/utils/project-picker.test.ts +0 -39
- package/src/agents/bundled-agents.generated.d.ts +0 -14
- package/src/agents/bundled-agents.generated.ts +0 -3692
- package/src/app.tsx +0 -399
- package/src/chat.tsx +0 -1698
- package/src/cli-args.ts +0 -134
- package/src/commands/__tests__/bash-command.test.ts +0 -445
- package/src/commands/__tests__/command-args.test.ts +0 -349
- package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
- package/src/commands/__tests__/copy-conversation.test.ts +0 -226
- package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
- package/src/commands/__tests__/freebuff-command-aliases.test.ts +0 -56
- package/src/commands/__tests__/image.test.ts +0 -99
- package/src/commands/__tests__/init.test.ts +0 -456
- package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
- package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
- package/src/commands/__tests__/prompt-builders.test.ts +0 -28
- package/src/commands/__tests__/router-input.test.ts +0 -298
- package/src/commands/ads.ts +0 -44
- package/src/commands/command-registry.ts +0 -726
- package/src/commands/copy-conversation.ts +0 -392
- package/src/commands/help.ts +0 -13
- package/src/commands/image.ts +0 -20
- package/src/commands/init.ts +0 -121
- package/src/commands/process-diagnostics.ts +0 -120
- package/src/commands/prompt-builders.ts +0 -100
- package/src/commands/publish.ts +0 -203
- package/src/commands/router-utils.ts +0 -80
- package/src/commands/router.ts +0 -487
- package/src/commands/usage.ts +0 -26
- package/src/components/__tests__/ad-banner.test.tsx +0 -83
- package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
- package/src/components/__tests__/freebuff-landing-heading-row.test.tsx +0 -91
- package/src/components/__tests__/freebuff-model-selector.test.tsx +0 -519
- package/src/components/__tests__/freebuff-offer-invariants.test.ts +0 -54
- package/src/components/__tests__/freebuff-takeover-prompt.test.tsx +0 -212
- package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
- package/src/components/__tests__/grid-layout.test.tsx +0 -1051
- package/src/components/__tests__/message-block.completion.test.tsx +0 -104
- package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
- package/src/components/__tests__/message-with-agents.test.tsx +0 -579
- package/src/components/__tests__/multiline-input.test.tsx +0 -1132
- package/src/components/__tests__/queue-panel.test.tsx +0 -398
- package/src/components/__tests__/selectable-list.test.ts +0 -232
- package/src/components/__tests__/status-bar.test.tsx +0 -44
- package/src/components/__tests__/status-indicator.test.tsx +0 -204
- package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
- package/src/components/__tests__/user-error-banner.test.tsx +0 -102
- package/src/components/ad-banner.tsx +0 -323
- package/src/components/agent-checklist.tsx +0 -350
- package/src/components/agent-mode-toggle.tsx +0 -241
- package/src/components/anvil-mark.tsx +0 -52
- package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
- package/src/components/ask-user/__tests__/validation.test.ts +0 -213
- package/src/components/ask-user/components/accordion-question.tsx +0 -153
- package/src/components/ask-user/components/custom-answer-input.tsx +0 -66
- package/src/components/ask-user/components/options-list.tsx +0 -133
- package/src/components/ask-user/components/question-header.tsx +0 -80
- package/src/components/ask-user/components/question-option.tsx +0 -89
- package/src/components/ask-user/constants.ts +0 -38
- package/src/components/ask-user/index.tsx +0 -631
- package/src/components/ask-user/utils/validation.ts +0 -85
- package/src/components/attachment-card.tsx +0 -65
- package/src/components/blocks/agent-block-grid.tsx +0 -58
- package/src/components/blocks/agent-branch-item.tsx +0 -311
- package/src/components/blocks/agent-branch-wrapper.tsx +0 -493
- package/src/components/blocks/agent-list-branch.tsx +0 -77
- package/src/components/blocks/ask-user-branch.tsx +0 -81
- package/src/components/blocks/block-helpers.ts +0 -11
- package/src/components/blocks/blocks-renderer.tsx +0 -289
- package/src/components/blocks/content-with-markdown.tsx +0 -33
- package/src/components/blocks/image-block.tsx +0 -128
- package/src/components/blocks/implementor-row.tsx +0 -429
- package/src/components/blocks/single-block.tsx +0 -201
- package/src/components/blocks/thinking-block.tsx +0 -67
- package/src/components/blocks/tool-block-group.tsx +0 -57
- package/src/components/blocks/tool-branch.tsx +0 -206
- package/src/components/blocks/user-content-copy.tsx +0 -157
- package/src/components/bottom-banner.tsx +0 -136
- package/src/components/build-mode-buttons.tsx +0 -110
- package/src/components/button.tsx +0 -66
- package/src/components/chat-header.tsx +0 -77
- package/src/components/chat-history-screen.tsx +0 -413
- package/src/components/chat-input-bar.tsx +0 -523
- package/src/components/clickable-title-box.tsx +0 -66
- package/src/components/clickable.tsx +0 -119
- package/src/components/collapse-button.tsx +0 -34
- package/src/components/copy-button.tsx +0 -203
- package/src/components/elapsed-timer.tsx +0 -55
- package/src/components/error-boundary.tsx +0 -55
- package/src/components/feedback-container.tsx +0 -181
- package/src/components/feedback-icon-button.tsx +0 -89
- package/src/components/feedback-input-mode.tsx +0 -344
- package/src/components/file-attachment-card.tsx +0 -98
- package/src/components/freebuff-active-session-summary.tsx +0 -63
- package/src/components/freebuff-landing-screen.tsx +0 -865
- package/src/components/freebuff-model-selector.tsx +0 -1087
- package/src/components/freebuff-referral-banner.tsx +0 -604
- package/src/components/freebuff-superseded-screen.tsx +0 -62
- package/src/components/grid-layout.tsx +0 -80
- package/src/components/help-banner.tsx +0 -127
- package/src/components/highlighted-text.tsx +0 -52
- package/src/components/image-card.tsx +0 -167
- package/src/components/image-thumbnail.tsx +0 -114
- package/src/components/input-cursor.tsx +0 -77
- package/src/components/input-mode-banner.tsx +0 -57
- package/src/components/load-previous-button.tsx +0 -48
- package/src/components/login-modal.tsx +0 -475
- package/src/components/message-block.tsx +0 -346
- package/src/components/message-footer.tsx +0 -258
- package/src/components/message-with-agents.tsx +0 -506
- package/src/components/mode-divider.tsx +0 -43
- package/src/components/multiline-input.tsx +0 -1241
- package/src/components/out-of-credits-banner.tsx +0 -160
- package/src/components/pending-attachments-banner.tsx +0 -116
- package/src/components/pending-bash-message.tsx +0 -59
- package/src/components/progress-bar.tsx +0 -81
- package/src/components/project-picker-screen.tsx +0 -485
- package/src/components/publish-confirmation.tsx +0 -493
- package/src/components/publish-container.tsx +0 -687
- package/src/components/queue-panel.tsx +0 -310
- package/src/components/raised-pill.tsx +0 -95
- package/src/components/renderers/plan-box.tsx +0 -59
- package/src/components/review-screen.tsx +0 -112
- package/src/components/scroll-to-bottom-button.tsx +0 -34
- package/src/components/segmented-control.tsx +0 -187
- package/src/components/selectable-list.tsx +0 -248
- package/src/components/selected-chips.tsx +0 -80
- package/src/components/separator.tsx +0 -40
- package/src/components/session-ended-banner.tsx +0 -226
- package/src/components/shimmer-text.tsx +0 -248
- package/src/components/status-bar.tsx +0 -313
- package/src/components/subscription-limit-banner.tsx +0 -206
- package/src/components/suggested-prompts.tsx +0 -184
- package/src/components/suggestion-menu.tsx +0 -215
- package/src/components/terminal-command-display.tsx +0 -151
- package/src/components/terminal-link.tsx +0 -97
- package/src/components/terminal-thinking-orb.tsx +0 -95
- package/src/components/text-attachment-card.tsx +0 -77
- package/src/components/thinking.tsx +0 -109
- package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
- package/src/components/tools/__tests__/code-search.test.tsx +0 -45
- package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
- package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
- package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
- package/src/components/tools/apply-patch.tsx +0 -95
- package/src/components/tools/code-search.tsx +0 -45
- package/src/components/tools/composio.tsx +0 -152
- package/src/components/tools/diff-viewer.tsx +0 -76
- package/src/components/tools/glob.tsx +0 -61
- package/src/components/tools/gravity-index.tsx +0 -77
- package/src/components/tools/list-directory.tsx +0 -61
- package/src/components/tools/read-docs.tsx +0 -37
- package/src/components/tools/read-files.tsx +0 -91
- package/src/components/tools/read-subtree.tsx +0 -44
- package/src/components/tools/read-url.tsx +0 -33
- package/src/components/tools/registry.ts +0 -126
- package/src/components/tools/render-ui.tsx +0 -122
- package/src/components/tools/run-terminal-command.tsx +0 -79
- package/src/components/tools/skill.tsx +0 -29
- package/src/components/tools/str-replace.tsx +0 -77
- package/src/components/tools/suggest-followups.tsx +0 -369
- package/src/components/tools/task-completed.tsx +0 -16
- package/src/components/tools/tool-call-item.tsx +0 -273
- package/src/components/tools/types.ts +0 -55
- package/src/components/tools/web-search.tsx +0 -33
- package/src/components/tools/write-file.tsx +0 -16
- package/src/components/tools/write-todos.tsx +0 -95
- package/src/components/top-banner.tsx +0 -178
- package/src/components/usage-banner.tsx +0 -244
- package/src/components/user-error-banner.tsx +0 -56
- package/src/components/validation-error-popover.tsx +0 -192
- package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
- package/src/contexts/chat-runtime-context.tsx +0 -240
- package/src/data/slash-commands.test.ts +0 -24
- package/src/data/slash-commands.ts +0 -249
- package/src/entry.ts +0 -12
- package/src/hooks/__tests__/holds-live-freebuff-slot.test.ts +0 -49
- package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
- package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
- package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
- package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
- package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
- package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
- package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
- package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
- package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
- package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
- package/src/hooks/__tests__/use-input-history.test.ts +0 -699
- package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
- package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
- package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
- package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
- package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
- package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
- package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
- package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
- package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
- package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
- package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
- package/src/hooks/__tests__/use-timeout.test.ts +0 -330
- package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
- package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
- package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
- package/src/hooks/helpers/send-message.ts +0 -654
- package/src/hooks/stream-state.ts +0 -83
- package/src/hooks/use-activity-query.ts +0 -668
- package/src/hooks/use-agent-validation.ts +0 -74
- package/src/hooks/use-ask-user-bridge.ts +0 -92
- package/src/hooks/use-auth-query.ts +0 -253
- package/src/hooks/use-auth-state.ts +0 -152
- package/src/hooks/use-chat-input.ts +0 -105
- package/src/hooks/use-chat-keyboard.ts +0 -321
- package/src/hooks/use-chat-messages.ts +0 -254
- package/src/hooks/use-chat-state.ts +0 -165
- package/src/hooks/use-chat-streaming.ts +0 -180
- package/src/hooks/use-chat-ui.ts +0 -131
- package/src/hooks/use-clipboard.ts +0 -151
- package/src/hooks/use-connection-status.ts +0 -142
- package/src/hooks/use-directory-browser.ts +0 -88
- package/src/hooks/use-elapsed-time.ts +0 -116
- package/src/hooks/use-event.ts +0 -34
- package/src/hooks/use-exit-handler.ts +0 -66
- package/src/hooks/use-fetch-login-url.ts +0 -65
- package/src/hooks/use-fingerprint.ts +0 -61
- package/src/hooks/use-freebuff-ctrl-c-exit.ts +0 -23
- package/src/hooks/use-freebuff-session-progress.ts +0 -34
- package/src/hooks/use-freebuff-session.ts +0 -806
- package/src/hooks/use-freebuff-streak-query.ts +0 -61
- package/src/hooks/use-gravity-ad.ts +0 -656
- package/src/hooks/use-grid-layout.ts +0 -73
- package/src/hooks/use-input-history.ts +0 -173
- package/src/hooks/use-login-keyboard-handlers.ts +0 -75
- package/src/hooks/use-login-polling.ts +0 -114
- package/src/hooks/use-logo.tsx +0 -161
- package/src/hooks/use-message-queue.ts +0 -387
- package/src/hooks/use-now.ts +0 -20
- package/src/hooks/use-path-tab-completion.ts +0 -88
- package/src/hooks/use-publish-mutation.ts +0 -60
- package/src/hooks/use-queue-controls.ts +0 -68
- package/src/hooks/use-queue-ui.ts +0 -74
- package/src/hooks/use-scroll-management.ts +0 -184
- package/src/hooks/use-searchable-list.ts +0 -98
- package/src/hooks/use-send-message.ts +0 -773
- package/src/hooks/use-sheen-animation.tsx +0 -88
- package/src/hooks/use-subscription-query.ts +0 -71
- package/src/hooks/use-suggestion-engine.ts +0 -783
- package/src/hooks/use-terminal-breakpoints.ts +0 -77
- package/src/hooks/use-terminal-dimensions.ts +0 -46
- package/src/hooks/use-terminal-focus.ts +0 -29
- package/src/hooks/use-terminal-layout.ts +0 -189
- package/src/hooks/use-theme.tsx +0 -140
- package/src/hooks/use-timeout.ts +0 -85
- package/src/hooks/use-update-preference.ts +0 -66
- package/src/hooks/use-usage-monitor.ts +0 -55
- package/src/hooks/use-usage-query.ts +0 -124
- package/src/hooks/use-user-details-query.ts +0 -93
- package/src/hooks/use-why-did-you-update.ts +0 -177
- package/src/index.tsx +0 -441
- package/src/init/__tests__/init-direnv.test.ts +0 -526
- package/src/init/init-app.ts +0 -34
- package/src/init/init-direnv.ts +0 -133
- package/src/login/constants.ts +0 -60
- package/src/login/login-flow.ts +0 -204
- package/src/login/plain-login.ts +0 -108
- package/src/login/utils.ts +0 -183
- package/src/native/ripgrep.ts +0 -80
- package/src/polyfills/bun-strip-ansi.ts +0 -12
- package/src/pre-init/tree-sitter-wasm.ts +0 -96
- package/src/project-files.ts +0 -102
- package/src/smoke/terminal-command-broker.ts +0 -439
- package/src/state/__tests__/chat-store-focus.test.ts +0 -22
- package/src/state/__tests__/feedback-store.test.ts +0 -257
- package/src/state/chat-history-store.ts +0 -30
- package/src/state/chat-store.ts +0 -544
- package/src/state/feedback-store.ts +0 -160
- package/src/state/freebuff-model-store.ts +0 -42
- package/src/state/freebuff-session-store.ts +0 -53
- package/src/state/login-store.ts +0 -150
- package/src/state/message-block-store.ts +0 -149
- package/src/state/publish-store.ts +0 -146
- package/src/state/queue-panel-store.ts +0 -26
- package/src/state/review-store.ts +0 -24
- package/src/testing/env.ts +0 -46
- package/src/types/chat-state.ts +0 -15
- package/src/types/chat.ts +0 -241
- package/src/types/contracts/send-message.ts +0 -12
- package/src/types/env.ts +0 -98
- package/src/types/freebuff-session.ts +0 -17
- package/src/types/function-params.ts +0 -28
- package/src/types/react19-compat.d.ts +0 -19
- package/src/types/store.ts +0 -111
- package/src/types/theme-system.ts +0 -144
- package/src/types/utils.ts +0 -3
- package/src/utils/__tests__/active-run.test.ts +0 -140
- package/src/utils/__tests__/activity-tracker.test.ts +0 -440
- package/src/utils/__tests__/agent-display.test.ts +0 -139
- package/src/utils/__tests__/analytics-client.test.ts +0 -262
- package/src/utils/__tests__/anonymous-id.test.ts +0 -74
- package/src/utils/__tests__/anvil-api.test.ts +0 -578
- package/src/utils/__tests__/arrays.test.ts +0 -264
- package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
- package/src/utils/__tests__/block-processor.test.ts +0 -810
- package/src/utils/__tests__/chat-history.test.ts +0 -203
- package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
- package/src/utils/__tests__/chat-meta.test.ts +0 -130
- package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
- package/src/utils/__tests__/clipboard.test.ts +0 -910
- package/src/utils/__tests__/code-search-summary.test.ts +0 -84
- package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
- package/src/utils/__tests__/error-handling.test.ts +0 -658
- package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
- package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
- package/src/utils/__tests__/feedback-submission.test.ts +0 -26
- package/src/utils/__tests__/fetch-usage.test.ts +0 -355
- package/src/utils/__tests__/fingerprint.test.ts +0 -144
- package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
- package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
- package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
- package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
- package/src/utils/__tests__/format-timeout.test.ts +0 -87
- package/src/utils/__tests__/freebuff-instance-owner.test.ts +0 -69
- package/src/utils/__tests__/freebuff-model-navigation.test.ts +0 -102
- package/src/utils/__tests__/freebuff-premium-reset.test.ts +0 -79
- package/src/utils/__tests__/freebuff-referral-cache.test.ts +0 -116
- package/src/utils/__tests__/freebuff-session-api.test.ts +0 -215
- package/src/utils/__tests__/freebuff-session-display.test.ts +0 -23
- package/src/utils/__tests__/freebuff-streak-line.test.ts +0 -217
- package/src/utils/__tests__/image-dimensions.test.ts +0 -249
- package/src/utils/__tests__/image-processor.test.ts +0 -209
- package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
- package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
- package/src/utils/__tests__/layout-helpers.test.ts +0 -36
- package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
- package/src/utils/__tests__/log-shipper.test.ts +0 -53
- package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
- package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
- package/src/utils/__tests__/message-updater.test.ts +0 -645
- package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
- package/src/utils/__tests__/pending-attachments.test.ts +0 -277
- package/src/utils/__tests__/polling-backoff.test.ts +0 -51
- package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
- package/src/utils/__tests__/run-state-storage.test.ts +0 -919
- package/src/utils/__tests__/safe-json.test.ts +0 -77
- package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
- package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
- package/src/utils/__tests__/send-message-timer.test.ts +0 -64
- package/src/utils/__tests__/settings.test.ts +0 -99
- package/src/utils/__tests__/strings.test.ts +0 -192
- package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
- package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
- package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
- package/src/utils/__tests__/terminal-io.test.ts +0 -137
- package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
- package/src/utils/__tests__/text-layout.test.ts +0 -82
- package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
- package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
- package/src/utils/__tests__/trace-writer.test.ts +0 -223
- package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
- package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
- package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
- package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
- package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
- package/src/utils/active-run.ts +0 -131
- package/src/utils/activity-tracker.ts +0 -66
- package/src/utils/agent-display.ts +0 -87
- package/src/utils/agent-helpers.ts +0 -27
- package/src/utils/agent-id-utils.ts +0 -14
- package/src/utils/ai-message-id.ts +0 -12
- package/src/utils/analytics.ts +0 -361
- package/src/utils/anonymous-id.ts +0 -87
- package/src/utils/anvil-api.ts +0 -612
- package/src/utils/anvil-client.ts +0 -217
- package/src/utils/arrays.ts +0 -117
- package/src/utils/auth.ts +0 -258
- package/src/utils/bash-context-processor.ts +0 -47
- package/src/utils/bash-messages.ts +0 -108
- package/src/utils/block-margins.ts +0 -35
- package/src/utils/block-operations.ts +0 -523
- package/src/utils/block-processor.ts +0 -213
- package/src/utils/chat-history.ts +0 -253
- package/src/utils/chat-input-key-intercept.ts +0 -52
- package/src/utils/chat-meta.ts +0 -90
- package/src/utils/chat-scroll-accel.ts +0 -151
- package/src/utils/clipboard-image.ts +0 -588
- package/src/utils/clipboard.ts +0 -397
- package/src/utils/code-search-summary.ts +0 -70
- package/src/utils/collapse-helpers.ts +0 -256
- package/src/utils/config-dir.ts +0 -24
- package/src/utils/constants.ts +0 -190
- package/src/utils/create-event-handler-state.ts +0 -73
- package/src/utils/create-run-config.ts +0 -121
- package/src/utils/detect-shell.ts +0 -116
- package/src/utils/directory-browser.ts +0 -72
- package/src/utils/engagement.ts +0 -55
- package/src/utils/env.ts +0 -92
- package/src/utils/error-handling.ts +0 -255
- package/src/utils/error-messages.ts +0 -62
- package/src/utils/exit-cleanly.ts +0 -86
- package/src/utils/feedback-helpers.ts +0 -103
- package/src/utils/feedback-submission.ts +0 -22
- package/src/utils/fetch-usage.ts +0 -76
- package/src/utils/fingerprint.ts +0 -245
- package/src/utils/format-elapsed-time.ts +0 -33
- package/src/utils/format-session-units.ts +0 -6
- package/src/utils/format-timeout.ts +0 -28
- package/src/utils/format-validation-errors-for-message.ts +0 -84
- package/src/utils/freebuff-agent-selection.ts +0 -33
- package/src/utils/freebuff-instance-owner.ts +0 -66
- package/src/utils/freebuff-model-navigation.ts +0 -50
- package/src/utils/freebuff-premium-reset.ts +0 -55
- package/src/utils/freebuff-referral-cache.ts +0 -51
- package/src/utils/freebuff-session-api.ts +0 -243
- package/src/utils/freebuff-session-display.ts +0 -21
- package/src/utils/freebuff-streak-line.ts +0 -93
- package/src/utils/git.ts +0 -17
- package/src/utils/helpers.ts +0 -47
- package/src/utils/image-display.ts +0 -67
- package/src/utils/image-handler.ts +0 -325
- package/src/utils/image-processor.ts +0 -133
- package/src/utils/image-thumbnail.ts +0 -78
- package/src/utils/implementor-helpers.ts +0 -787
- package/src/utils/input-modes.ts +0 -174
- package/src/utils/keyboard-actions.ts +0 -392
- package/src/utils/keypad-keys.ts +0 -47
- package/src/utils/layout-helpers.ts +0 -33
- package/src/utils/lazy-response-ads.ts +0 -1
- package/src/utils/local-agent-registry.ts +0 -474
- package/src/utils/log-shipper.ts +0 -126
- package/src/utils/logger.ts +0 -327
- package/src/utils/markdown-renderer.tsx +0 -1090
- package/src/utils/math.ts +0 -3
- package/src/utils/message-block-helpers.ts +0 -684
- package/src/utils/message-history.ts +0 -143
- package/src/utils/message-tree-utils.ts +0 -67
- package/src/utils/message-updater.ts +0 -279
- package/src/utils/open-file.ts +0 -146
- package/src/utils/open-url.ts +0 -63
- package/src/utils/path-completion.ts +0 -111
- package/src/utils/path-helpers.ts +0 -38
- package/src/utils/pending-attachments.ts +0 -360
- package/src/utils/polling-backoff.ts +0 -59
- package/src/utils/project-picker.ts +0 -12
- package/src/utils/queue-panel-actions.ts +0 -70
- package/src/utils/recent-projects.ts +0 -156
- package/src/utils/renderer-cleanup.ts +0 -233
- package/src/utils/response-ad-positions.ts +0 -1
- package/src/utils/run-state-storage.ts +0 -603
- package/src/utils/safe-json.ts +0 -153
- package/src/utils/sdk-event-handlers.ts +0 -571
- package/src/utils/send-message-helpers.ts +0 -210
- package/src/utils/send-message-timer.ts +0 -110
- package/src/utils/settings.ts +0 -226
- package/src/utils/skill-registry.ts +0 -94
- package/src/utils/spawn-agent-matcher.ts +0 -55
- package/src/utils/status-indicator-state.ts +0 -107
- package/src/utils/stream-chunk-processor.ts +0 -57
- package/src/utils/strings.ts +0 -271
- package/src/utils/subscription.ts +0 -31
- package/src/utils/syntax-highlighter.tsx +0 -19
- package/src/utils/terminal-color-detection.ts +0 -474
- package/src/utils/terminal-command-broker.ts +0 -467
- package/src/utils/terminal-enter-detection.ts +0 -63
- package/src/utils/terminal-images.ts +0 -229
- package/src/utils/terminal-io.ts +0 -85
- package/src/utils/terminal-protocol-controller.ts +0 -173
- package/src/utils/terminal-reset-sequences.ts +0 -33
- package/src/utils/terminal-title.ts +0 -84
- package/src/utils/terminal-watchdog.ts +0 -366
- package/src/utils/text-layout.ts +0 -149
- package/src/utils/theme-config.ts +0 -141
- package/src/utils/theme-system.ts +0 -1206
- package/src/utils/think-tag-parser.ts +0 -95
- package/src/utils/time-format.ts +0 -21
- package/src/utils/trace-writer.ts +0 -162
- package/src/utils/ui-constants.ts +0 -69
- package/src/utils/update-checker.ts +0 -110
- package/src/utils/usage-banner-state.ts +0 -146
- package/src/utils/validation-error-formatting.ts +0 -86
- package/src/utils/validation-error-helpers.ts +0 -19
- package/src/utils/windows-terminal-health.ts +0 -124
- package/src/utils/word-wrap-utils.ts +0 -53
- package/src/utils/write-file-atomic.ts +0 -54
- package/src/utils/yield-to-event-loop.ts +0 -9
|
@@ -1,1263 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getAgentBaseName,
|
|
5
|
-
extractPlanFromBuffer,
|
|
6
|
-
autoCollapseBlocks,
|
|
7
|
-
extractSpawnAgentResultContent,
|
|
8
|
-
appendInterruptionNotice,
|
|
9
|
-
createAgentBlock,
|
|
10
|
-
updateBlocksRecursively,
|
|
11
|
-
nestBlockUnderParent,
|
|
12
|
-
extractBlockById,
|
|
13
|
-
transformAskUserBlocks,
|
|
14
|
-
updateToolBlockWithOutput,
|
|
15
|
-
scrubPlanTags,
|
|
16
|
-
scrubPlanTagsInBlocks,
|
|
17
|
-
insertPlanBlock,
|
|
18
|
-
moveSpawnAgentBlock,
|
|
19
|
-
stripHiddenAgentBlocks,
|
|
20
|
-
} from '../message-block-helpers'
|
|
21
|
-
|
|
22
|
-
import type {
|
|
23
|
-
ContentBlock,
|
|
24
|
-
AgentContentBlock,
|
|
25
|
-
AskUserContentBlock,
|
|
26
|
-
TextContentBlock,
|
|
27
|
-
ToolContentBlock,
|
|
28
|
-
} from '../../types/chat'
|
|
29
|
-
|
|
30
|
-
describe('stripHiddenAgentBlocks', () => {
|
|
31
|
-
const agentBlock = (
|
|
32
|
-
agentType: string,
|
|
33
|
-
blocks?: ContentBlock[],
|
|
34
|
-
): AgentContentBlock => ({
|
|
35
|
-
type: 'agent',
|
|
36
|
-
agentId: `id-${agentType}`,
|
|
37
|
-
agentName: agentType,
|
|
38
|
-
agentType,
|
|
39
|
-
content: '',
|
|
40
|
-
status: 'complete',
|
|
41
|
-
...(blocks ? { blocks } : {}),
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('removes context-pruner blocks (bundled and qualified ids)', () => {
|
|
45
|
-
const blocks: ContentBlock[] = [
|
|
46
|
-
agentBlock('context-pruner'),
|
|
47
|
-
agentBlock('anvil/context-pruner@1.0.0'),
|
|
48
|
-
agentBlock('file-picker'),
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
const result = stripHiddenAgentBlocks(blocks)
|
|
52
|
-
|
|
53
|
-
expect(result).toHaveLength(1)
|
|
54
|
-
expect((result[0] as AgentContentBlock).agentType).toBe('file-picker')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('removes hidden blocks nested under other agents', () => {
|
|
58
|
-
const blocks: ContentBlock[] = [
|
|
59
|
-
agentBlock('base2', [
|
|
60
|
-
agentBlock('context-pruner'),
|
|
61
|
-
agentBlock('file-picker'),
|
|
62
|
-
]),
|
|
63
|
-
]
|
|
64
|
-
|
|
65
|
-
const result = stripHiddenAgentBlocks(blocks)
|
|
66
|
-
|
|
67
|
-
const children = (result[0] as AgentContentBlock).blocks!
|
|
68
|
-
expect(children).toHaveLength(1)
|
|
69
|
-
expect((children[0] as AgentContentBlock).agentType).toBe('file-picker')
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('returns the same array when nothing is hidden', () => {
|
|
73
|
-
const blocks: ContentBlock[] = [
|
|
74
|
-
agentBlock('file-picker'),
|
|
75
|
-
{ type: 'text', content: 'hello' },
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
expect(stripHiddenAgentBlocks(blocks)).toBe(blocks)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
test('tolerates corrupted persisted shapes without throwing', () => {
|
|
82
|
-
const corruptedEntries = [
|
|
83
|
-
null,
|
|
84
|
-
{ type: 'agent', agentId: 'a1', status: 'complete' }, // missing agentType
|
|
85
|
-
{ ...agentBlock('base2'), blocks: 'not-an-array' },
|
|
86
|
-
] as unknown as ContentBlock[]
|
|
87
|
-
|
|
88
|
-
expect(stripHiddenAgentBlocks(corruptedEntries)).toBe(corruptedEntries)
|
|
89
|
-
expect(
|
|
90
|
-
stripHiddenAgentBlocks('not-an-array' as unknown as ContentBlock[]),
|
|
91
|
-
).toBe('not-an-array' as unknown as ContentBlock[])
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe('getAgentBaseName', () => {
|
|
96
|
-
test('extracts base name from scoped versioned name', () => {
|
|
97
|
-
expect(getAgentBaseName('anvil/file-picker@0.0.2')).toBe('file-picker')
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
test('extracts base name from simple versioned name', () => {
|
|
101
|
-
expect(getAgentBaseName('file-picker@1.0.0')).toBe('file-picker')
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('returns simple name unchanged', () => {
|
|
105
|
-
expect(getAgentBaseName('file-picker')).toBe('file-picker')
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
test('normalizes direct tool aliases to canonical agent names', () => {
|
|
109
|
-
expect(getAgentBaseName('code_reviewer_lite')).toBe('code-reviewer-lite')
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
test('handles scoped name without version', () => {
|
|
113
|
-
expect(getAgentBaseName('anvil/file-picker')).toBe('file-picker')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
test('handles empty string', () => {
|
|
117
|
-
expect(getAgentBaseName('')).toBe('')
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
test('handles name with multiple slashes', () => {
|
|
121
|
-
expect(getAgentBaseName('@scope/sub/agent@1.0.0')).toBe('agent')
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
describe('extractPlanFromBuffer', () => {
|
|
126
|
-
test('extracts plan content between tags', () => {
|
|
127
|
-
const buffer = 'Some text <PLAN>This is the plan</PLAN> more text'
|
|
128
|
-
expect(extractPlanFromBuffer(buffer)).toBe('This is the plan')
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('trims whitespace from extracted plan', () => {
|
|
132
|
-
const buffer = '<PLAN> \n Plan with whitespace \n </PLAN>'
|
|
133
|
-
expect(extractPlanFromBuffer(buffer)).toBe('Plan with whitespace')
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test('returns null when no opening tag', () => {
|
|
137
|
-
const buffer = 'This is the plan</PLAN>'
|
|
138
|
-
expect(extractPlanFromBuffer(buffer)).toBeNull()
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
test('returns null when no closing tag', () => {
|
|
142
|
-
const buffer = '<PLAN>This is the plan'
|
|
143
|
-
expect(extractPlanFromBuffer(buffer)).toBeNull()
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
test('returns null when tags are in wrong order', () => {
|
|
147
|
-
const buffer = '</PLAN>content<PLAN>'
|
|
148
|
-
expect(extractPlanFromBuffer(buffer)).toBeNull()
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test('returns null for empty buffer', () => {
|
|
152
|
-
expect(extractPlanFromBuffer('')).toBeNull()
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('handles multiline plan content', () => {
|
|
156
|
-
const buffer =
|
|
157
|
-
'<PLAN>\n1. First step\n2. Second step\n3. Third step\n</PLAN>'
|
|
158
|
-
expect(extractPlanFromBuffer(buffer)).toBe(
|
|
159
|
-
'1. First step\n2. Second step\n3. Third step',
|
|
160
|
-
)
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
describe('scrubPlanTags helpers', () => {
|
|
165
|
-
test('removes plan tags from text', () => {
|
|
166
|
-
expect(scrubPlanTags('<PLAN>Plan</PLAN> trailing')).toBe(' trailing')
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
test('scrubs plan tags inside text blocks and removes empties', () => {
|
|
170
|
-
const blocks: ContentBlock[] = [
|
|
171
|
-
{ type: 'text', content: '<PLAN>Plan</PLAN>' },
|
|
172
|
-
{ type: 'text', content: 'Keep me' },
|
|
173
|
-
{ type: 'tool', toolCallId: 'id', toolName: 'read_files', input: {} },
|
|
174
|
-
]
|
|
175
|
-
const result = scrubPlanTagsInBlocks(blocks)
|
|
176
|
-
expect(result).toHaveLength(2)
|
|
177
|
-
expect(result[0]).toEqual({ type: 'text', content: 'Keep me' })
|
|
178
|
-
expect(result[1].type).toBe('tool')
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('inserts plan block after scrubbing', () => {
|
|
182
|
-
const blocks: ContentBlock[] = [
|
|
183
|
-
{ type: 'text', content: 'Intro <PLAN>secret</PLAN>' },
|
|
184
|
-
]
|
|
185
|
-
const result = insertPlanBlock(blocks, 'Plan body')
|
|
186
|
-
expect(result).toHaveLength(2)
|
|
187
|
-
expect(result[0]).toEqual({ type: 'text', content: 'Intro ' })
|
|
188
|
-
expect(result[1]).toEqual({ type: 'plan', content: 'Plan body' })
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
describe('autoCollapseBlocks', () => {
|
|
193
|
-
test('collapses text blocks with thinkingId', () => {
|
|
194
|
-
const blocks: ContentBlock[] = [
|
|
195
|
-
{ type: 'text', content: 'thinking', thinkingId: 'think-1' },
|
|
196
|
-
]
|
|
197
|
-
const result = autoCollapseBlocks(blocks)
|
|
198
|
-
expect(result[0]).toHaveProperty('thinkingCollapseState', 'hidden')
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test('preserves user-opened text blocks', () => {
|
|
202
|
-
const blocks: ContentBlock[] = [
|
|
203
|
-
{
|
|
204
|
-
type: 'text',
|
|
205
|
-
content: 'thinking',
|
|
206
|
-
thinkingId: 'think-1',
|
|
207
|
-
userOpened: true,
|
|
208
|
-
},
|
|
209
|
-
]
|
|
210
|
-
const result = autoCollapseBlocks(blocks)
|
|
211
|
-
expect(result[0]).not.toHaveProperty('isCollapsed')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test('collapses agent blocks', () => {
|
|
215
|
-
const blocks: ContentBlock[] = [
|
|
216
|
-
{
|
|
217
|
-
type: 'agent',
|
|
218
|
-
agentId: 'agent-1',
|
|
219
|
-
agentName: 'Test Agent',
|
|
220
|
-
agentType: 'test',
|
|
221
|
-
content: '',
|
|
222
|
-
status: 'complete',
|
|
223
|
-
blocks: [],
|
|
224
|
-
initialPrompt: '',
|
|
225
|
-
},
|
|
226
|
-
]
|
|
227
|
-
const result = autoCollapseBlocks(blocks)
|
|
228
|
-
expect(result[0]).toHaveProperty('isCollapsed', true)
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
test('recursively collapses nested agent blocks', () => {
|
|
232
|
-
const blocks: ContentBlock[] = [
|
|
233
|
-
{
|
|
234
|
-
type: 'agent',
|
|
235
|
-
agentId: 'parent',
|
|
236
|
-
agentName: 'Parent',
|
|
237
|
-
agentType: 'parent',
|
|
238
|
-
content: '',
|
|
239
|
-
status: 'complete',
|
|
240
|
-
blocks: [
|
|
241
|
-
{
|
|
242
|
-
type: 'agent',
|
|
243
|
-
agentId: 'child',
|
|
244
|
-
agentName: 'Child',
|
|
245
|
-
agentType: 'child',
|
|
246
|
-
content: '',
|
|
247
|
-
status: 'complete',
|
|
248
|
-
blocks: [],
|
|
249
|
-
initialPrompt: '',
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
-
initialPrompt: '',
|
|
253
|
-
},
|
|
254
|
-
]
|
|
255
|
-
const result = autoCollapseBlocks(blocks)
|
|
256
|
-
expect(result[0]).toHaveProperty('isCollapsed', true)
|
|
257
|
-
expect((result[0] as AgentContentBlock).blocks![0]).toHaveProperty(
|
|
258
|
-
'isCollapsed',
|
|
259
|
-
true,
|
|
260
|
-
)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('collapses tool blocks', () => {
|
|
264
|
-
const blocks: ContentBlock[] = [
|
|
265
|
-
{
|
|
266
|
-
type: 'tool',
|
|
267
|
-
toolCallId: 'tool-1',
|
|
268
|
-
toolName: 'read_files',
|
|
269
|
-
input: {},
|
|
270
|
-
},
|
|
271
|
-
]
|
|
272
|
-
const result = autoCollapseBlocks(blocks)
|
|
273
|
-
expect(result[0]).toHaveProperty('isCollapsed', true)
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
test('preserves user-opened tool blocks', () => {
|
|
277
|
-
const blocks: ContentBlock[] = [
|
|
278
|
-
{
|
|
279
|
-
type: 'tool',
|
|
280
|
-
toolCallId: 'tool-1',
|
|
281
|
-
toolName: 'read_files',
|
|
282
|
-
input: {},
|
|
283
|
-
userOpened: true,
|
|
284
|
-
},
|
|
285
|
-
]
|
|
286
|
-
const result = autoCollapseBlocks(blocks)
|
|
287
|
-
expect(result[0]).not.toHaveProperty('isCollapsed')
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
test('leaves regular text blocks unchanged', () => {
|
|
291
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
292
|
-
const result = autoCollapseBlocks(blocks)
|
|
293
|
-
expect(result[0]).toEqual({ type: 'text', content: 'Hello' })
|
|
294
|
-
})
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
describe('extractSpawnAgentResultContent', () => {
|
|
298
|
-
test('returns string value directly', () => {
|
|
299
|
-
const result = extractSpawnAgentResultContent('Simple result')
|
|
300
|
-
expect(result).toEqual({ content: 'Simple result', hasError: false })
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
test('extracts error message', () => {
|
|
304
|
-
const result = extractSpawnAgentResultContent({
|
|
305
|
-
errorMessage: 'Something went wrong',
|
|
306
|
-
})
|
|
307
|
-
expect(result).toEqual({
|
|
308
|
-
content: 'Something went wrong',
|
|
309
|
-
hasError: true,
|
|
310
|
-
})
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
test('extracts nested value string', () => {
|
|
314
|
-
const result = extractSpawnAgentResultContent({
|
|
315
|
-
type: 'lastMessage',
|
|
316
|
-
value: 'Nested value',
|
|
317
|
-
})
|
|
318
|
-
expect(result).toEqual({ content: 'Nested value', hasError: false })
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
test('extracts message field', () => {
|
|
322
|
-
const result = extractSpawnAgentResultContent({
|
|
323
|
-
message: 'Message content',
|
|
324
|
-
})
|
|
325
|
-
expect(result).toEqual({ content: 'Message content', hasError: false })
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
test('falls back to formatted output for unknown structure', () => {
|
|
329
|
-
const result = extractSpawnAgentResultContent({ unknownField: 123 })
|
|
330
|
-
expect(result.hasError).toBe(false)
|
|
331
|
-
expect(result.content).toContain('unknownField')
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
test('handles null value', () => {
|
|
335
|
-
const result = extractSpawnAgentResultContent(null)
|
|
336
|
-
expect(result.hasError).toBe(false)
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
test('handles undefined value', () => {
|
|
340
|
-
const result = extractSpawnAgentResultContent(undefined)
|
|
341
|
-
expect(result.hasError).toBe(false)
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
test('extracts text from lastMessage output mode with Message array', () => {
|
|
345
|
-
// This is the format returned by agents with outputMode: 'last_message'
|
|
346
|
-
const result = extractSpawnAgentResultContent({
|
|
347
|
-
type: 'lastMessage',
|
|
348
|
-
value: [
|
|
349
|
-
{
|
|
350
|
-
role: 'assistant',
|
|
351
|
-
content: [
|
|
352
|
-
{ type: 'text', text: 'Here are the research findings:' },
|
|
353
|
-
{ type: 'text', text: ' Important information found.' },
|
|
354
|
-
],
|
|
355
|
-
},
|
|
356
|
-
],
|
|
357
|
-
})
|
|
358
|
-
expect(result).toEqual({
|
|
359
|
-
content: 'Here are the research findings: Important information found.',
|
|
360
|
-
hasError: false,
|
|
361
|
-
})
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
test('extracts text from multiple assistant messages in lastMessage output', () => {
|
|
365
|
-
const result = extractSpawnAgentResultContent({
|
|
366
|
-
type: 'lastMessage',
|
|
367
|
-
value: [
|
|
368
|
-
{
|
|
369
|
-
role: 'assistant',
|
|
370
|
-
content: [{ type: 'text', text: 'First message' }],
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
role: 'tool',
|
|
374
|
-
content: [{ type: 'json', value: {} }],
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
role: 'assistant',
|
|
378
|
-
content: [{ type: 'text', text: 'Second message' }],
|
|
379
|
-
},
|
|
380
|
-
],
|
|
381
|
-
})
|
|
382
|
-
expect(result).toEqual({
|
|
383
|
-
content: 'First message\nSecond message',
|
|
384
|
-
hasError: false,
|
|
385
|
-
})
|
|
386
|
-
})
|
|
387
|
-
|
|
388
|
-
test('handles lastMessage with empty content array', () => {
|
|
389
|
-
const result = extractSpawnAgentResultContent({
|
|
390
|
-
type: 'lastMessage',
|
|
391
|
-
value: [
|
|
392
|
-
{
|
|
393
|
-
role: 'assistant',
|
|
394
|
-
content: [],
|
|
395
|
-
},
|
|
396
|
-
],
|
|
397
|
-
})
|
|
398
|
-
expect(result).toEqual({ content: '', hasError: false })
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
test('handles lastMessage with no assistant messages', () => {
|
|
402
|
-
const result = extractSpawnAgentResultContent({
|
|
403
|
-
type: 'lastMessage',
|
|
404
|
-
value: [
|
|
405
|
-
{
|
|
406
|
-
role: 'tool',
|
|
407
|
-
content: [{ type: 'json', value: {} }],
|
|
408
|
-
},
|
|
409
|
-
],
|
|
410
|
-
})
|
|
411
|
-
expect(result).toEqual({ content: '', hasError: false })
|
|
412
|
-
})
|
|
413
|
-
|
|
414
|
-
test('handles allMessages output mode', () => {
|
|
415
|
-
const result = extractSpawnAgentResultContent({
|
|
416
|
-
type: 'allMessages',
|
|
417
|
-
value: [
|
|
418
|
-
{
|
|
419
|
-
role: 'assistant',
|
|
420
|
-
content: [{ type: 'text', text: 'First response' }],
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
role: 'user',
|
|
424
|
-
content: [{ type: 'text', text: 'Follow up' }],
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
role: 'assistant',
|
|
428
|
-
content: [{ type: 'text', text: 'Second response' }],
|
|
429
|
-
},
|
|
430
|
-
],
|
|
431
|
-
})
|
|
432
|
-
expect(result).toEqual({
|
|
433
|
-
content: 'First response\nSecond response',
|
|
434
|
-
hasError: false,
|
|
435
|
-
})
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
test('handles structuredOutput with message field', () => {
|
|
439
|
-
const result = extractSpawnAgentResultContent({
|
|
440
|
-
type: 'structuredOutput',
|
|
441
|
-
value: { message: 'Structured output message' },
|
|
442
|
-
})
|
|
443
|
-
expect(result).toEqual({
|
|
444
|
-
content: 'Structured output message',
|
|
445
|
-
hasError: false,
|
|
446
|
-
})
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
test('uses an empty structuredOutput message as no display content', () => {
|
|
450
|
-
const result = extractSpawnAgentResultContent({
|
|
451
|
-
type: 'structuredOutput',
|
|
452
|
-
value: {
|
|
453
|
-
message: '',
|
|
454
|
-
results: [
|
|
455
|
-
{
|
|
456
|
-
stdout: 'Found 1 match\n./file.ts:\nLine 1: needle',
|
|
457
|
-
message: 'Exit code: 0',
|
|
458
|
-
},
|
|
459
|
-
],
|
|
460
|
-
},
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
expect(result).toEqual({ content: '', hasError: false })
|
|
464
|
-
})
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
describe('appendInterruptionNotice', () => {
|
|
468
|
-
test('appends to last text block', () => {
|
|
469
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
470
|
-
const result = appendInterruptionNotice(blocks)
|
|
471
|
-
expect(result).toHaveLength(1)
|
|
472
|
-
expect(result[0]).toEqual({
|
|
473
|
-
type: 'text',
|
|
474
|
-
content: 'Hello\n\n[response interrupted]',
|
|
475
|
-
})
|
|
476
|
-
})
|
|
477
|
-
|
|
478
|
-
test('preserves text block fields when appending', () => {
|
|
479
|
-
const blocks: ContentBlock[] = [
|
|
480
|
-
{
|
|
481
|
-
type: 'text',
|
|
482
|
-
content: 'Hello',
|
|
483
|
-
color: 'blue',
|
|
484
|
-
status: 'running',
|
|
485
|
-
thinkingId: 'think-1',
|
|
486
|
-
userOpened: true,
|
|
487
|
-
thinkingCollapseState: 'hidden',
|
|
488
|
-
},
|
|
489
|
-
]
|
|
490
|
-
const result = appendInterruptionNotice(blocks)
|
|
491
|
-
expect(result[0]).toMatchObject({
|
|
492
|
-
color: 'blue',
|
|
493
|
-
status: 'running',
|
|
494
|
-
thinkingId: 'think-1',
|
|
495
|
-
userOpened: true,
|
|
496
|
-
thinkingCollapseState: 'hidden',
|
|
497
|
-
content: 'Hello\n\n[response interrupted]',
|
|
498
|
-
})
|
|
499
|
-
})
|
|
500
|
-
|
|
501
|
-
test('adds new block when last is not text', () => {
|
|
502
|
-
const blocks: ContentBlock[] = [
|
|
503
|
-
{
|
|
504
|
-
type: 'tool',
|
|
505
|
-
toolCallId: 'tool-1',
|
|
506
|
-
toolName: 'read_files',
|
|
507
|
-
input: {},
|
|
508
|
-
},
|
|
509
|
-
]
|
|
510
|
-
const result = appendInterruptionNotice(blocks)
|
|
511
|
-
expect(result).toHaveLength(2)
|
|
512
|
-
expect(result[1]).toEqual({
|
|
513
|
-
type: 'text',
|
|
514
|
-
content: '[response interrupted]',
|
|
515
|
-
})
|
|
516
|
-
})
|
|
517
|
-
|
|
518
|
-
test('adds notice to empty blocks array', () => {
|
|
519
|
-
const result = appendInterruptionNotice([])
|
|
520
|
-
expect(result).toHaveLength(1)
|
|
521
|
-
expect(result[0]).toEqual({
|
|
522
|
-
type: 'text',
|
|
523
|
-
content: '[response interrupted]',
|
|
524
|
-
})
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
test('preserves other blocks when appending to text', () => {
|
|
528
|
-
const blocks: ContentBlock[] = [
|
|
529
|
-
{
|
|
530
|
-
type: 'tool',
|
|
531
|
-
toolCallId: 'tool-1',
|
|
532
|
-
toolName: 'read_files',
|
|
533
|
-
input: {},
|
|
534
|
-
},
|
|
535
|
-
{ type: 'text', content: 'Some response' },
|
|
536
|
-
]
|
|
537
|
-
const result = appendInterruptionNotice(blocks)
|
|
538
|
-
expect(result).toHaveLength(2)
|
|
539
|
-
expect(result[0].type).toBe('tool')
|
|
540
|
-
expect(result[1]).toEqual({
|
|
541
|
-
type: 'text',
|
|
542
|
-
content: 'Some response\n\n[response interrupted]',
|
|
543
|
-
})
|
|
544
|
-
})
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
describe('createAgentBlock', () => {
|
|
548
|
-
test('creates basic agent block with required fields', () => {
|
|
549
|
-
const block = createAgentBlock({
|
|
550
|
-
agentId: 'agent-123',
|
|
551
|
-
agentType: 'file-picker',
|
|
552
|
-
})
|
|
553
|
-
expect(block.type).toBe('agent')
|
|
554
|
-
expect(block.agentId).toBe('agent-123')
|
|
555
|
-
expect(block.agentName).toBe('file-picker')
|
|
556
|
-
expect(block.agentType).toBe('file-picker')
|
|
557
|
-
expect(block.content).toBe('')
|
|
558
|
-
expect(block.status).toBe('running')
|
|
559
|
-
expect(block.blocks).toEqual([])
|
|
560
|
-
expect(block.initialPrompt).toBe('')
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
test('includes prompt when provided', () => {
|
|
564
|
-
const block = createAgentBlock({
|
|
565
|
-
agentId: 'agent-123',
|
|
566
|
-
agentType: 'file-picker',
|
|
567
|
-
prompt: 'Find relevant files',
|
|
568
|
-
})
|
|
569
|
-
expect(block.initialPrompt).toBe('Find relevant files')
|
|
570
|
-
})
|
|
571
|
-
|
|
572
|
-
test('includes params when provided', () => {
|
|
573
|
-
const block = createAgentBlock({
|
|
574
|
-
agentId: 'agent-123',
|
|
575
|
-
agentType: 'file-picker',
|
|
576
|
-
params: { directories: ['src'] },
|
|
577
|
-
})
|
|
578
|
-
expect(block.params).toEqual({ directories: ['src'] })
|
|
579
|
-
})
|
|
580
|
-
|
|
581
|
-
test('uses fallback values for empty agentType', () => {
|
|
582
|
-
const block = createAgentBlock({
|
|
583
|
-
agentId: 'agent-123',
|
|
584
|
-
agentType: '',
|
|
585
|
-
})
|
|
586
|
-
expect(block.agentName).toBe('Agent')
|
|
587
|
-
expect(block.agentType).toBe('unknown')
|
|
588
|
-
})
|
|
589
|
-
})
|
|
590
|
-
|
|
591
|
-
describe('updateBlocksRecursively', () => {
|
|
592
|
-
test('updates target block at top level', () => {
|
|
593
|
-
const blocks: ContentBlock[] = [
|
|
594
|
-
{
|
|
595
|
-
type: 'agent',
|
|
596
|
-
agentId: 'agent-1',
|
|
597
|
-
agentName: 'Test',
|
|
598
|
-
agentType: 'test',
|
|
599
|
-
content: '',
|
|
600
|
-
status: 'running',
|
|
601
|
-
blocks: [],
|
|
602
|
-
initialPrompt: '',
|
|
603
|
-
},
|
|
604
|
-
]
|
|
605
|
-
const result = updateBlocksRecursively(blocks, 'agent-1', (block) => ({
|
|
606
|
-
...block,
|
|
607
|
-
status: 'complete' as const,
|
|
608
|
-
}))
|
|
609
|
-
expect((result[0] as AgentContentBlock).status).toBe('complete')
|
|
610
|
-
})
|
|
611
|
-
|
|
612
|
-
test('updates nested block', () => {
|
|
613
|
-
const blocks: ContentBlock[] = [
|
|
614
|
-
{
|
|
615
|
-
type: 'agent',
|
|
616
|
-
agentId: 'parent',
|
|
617
|
-
agentName: 'Parent',
|
|
618
|
-
agentType: 'parent',
|
|
619
|
-
content: '',
|
|
620
|
-
status: 'running',
|
|
621
|
-
blocks: [
|
|
622
|
-
{
|
|
623
|
-
type: 'agent',
|
|
624
|
-
agentId: 'child',
|
|
625
|
-
agentName: 'Child',
|
|
626
|
-
agentType: 'child',
|
|
627
|
-
content: '',
|
|
628
|
-
status: 'running',
|
|
629
|
-
blocks: [],
|
|
630
|
-
initialPrompt: '',
|
|
631
|
-
},
|
|
632
|
-
],
|
|
633
|
-
initialPrompt: '',
|
|
634
|
-
},
|
|
635
|
-
]
|
|
636
|
-
const result = updateBlocksRecursively(blocks, 'child', (block) => ({
|
|
637
|
-
...block,
|
|
638
|
-
status: 'complete' as const,
|
|
639
|
-
}))
|
|
640
|
-
expect((result[0] as AgentContentBlock).blocks![0]).toMatchObject({
|
|
641
|
-
status: 'complete',
|
|
642
|
-
})
|
|
643
|
-
})
|
|
644
|
-
|
|
645
|
-
test('returns original array if target not found', () => {
|
|
646
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
647
|
-
const result = updateBlocksRecursively(
|
|
648
|
-
blocks,
|
|
649
|
-
'nonexistent',
|
|
650
|
-
(block) => block,
|
|
651
|
-
)
|
|
652
|
-
expect(result).toBe(blocks)
|
|
653
|
-
})
|
|
654
|
-
|
|
655
|
-
test('handles deeply nested blocks', () => {
|
|
656
|
-
const blocks: ContentBlock[] = [
|
|
657
|
-
{
|
|
658
|
-
type: 'agent',
|
|
659
|
-
agentId: 'level-1',
|
|
660
|
-
agentName: 'L1',
|
|
661
|
-
agentType: 'l1',
|
|
662
|
-
content: '',
|
|
663
|
-
status: 'running',
|
|
664
|
-
blocks: [
|
|
665
|
-
{
|
|
666
|
-
type: 'agent',
|
|
667
|
-
agentId: 'level-2',
|
|
668
|
-
agentName: 'L2',
|
|
669
|
-
agentType: 'l2',
|
|
670
|
-
content: '',
|
|
671
|
-
status: 'running',
|
|
672
|
-
blocks: [
|
|
673
|
-
{
|
|
674
|
-
type: 'agent',
|
|
675
|
-
agentId: 'level-3',
|
|
676
|
-
agentName: 'L3',
|
|
677
|
-
agentType: 'l3',
|
|
678
|
-
content: '',
|
|
679
|
-
status: 'running',
|
|
680
|
-
blocks: [],
|
|
681
|
-
initialPrompt: '',
|
|
682
|
-
},
|
|
683
|
-
],
|
|
684
|
-
initialPrompt: '',
|
|
685
|
-
},
|
|
686
|
-
],
|
|
687
|
-
initialPrompt: '',
|
|
688
|
-
},
|
|
689
|
-
]
|
|
690
|
-
const result = updateBlocksRecursively(blocks, 'level-3', (block) => ({
|
|
691
|
-
...block,
|
|
692
|
-
content: 'updated',
|
|
693
|
-
}))
|
|
694
|
-
const level1 = result[0] as AgentContentBlock
|
|
695
|
-
const level2 = level1.blocks![0] as AgentContentBlock
|
|
696
|
-
const level3 = level2.blocks![0] as AgentContentBlock
|
|
697
|
-
expect(level3.content).toBe('updated')
|
|
698
|
-
})
|
|
699
|
-
})
|
|
700
|
-
|
|
701
|
-
describe('nestBlockUnderParent', () => {
|
|
702
|
-
test('nests block under existing parent', () => {
|
|
703
|
-
const blocks: ContentBlock[] = [
|
|
704
|
-
{
|
|
705
|
-
type: 'agent',
|
|
706
|
-
agentId: 'parent',
|
|
707
|
-
agentName: 'Parent',
|
|
708
|
-
agentType: 'parent',
|
|
709
|
-
content: '',
|
|
710
|
-
status: 'running',
|
|
711
|
-
blocks: [],
|
|
712
|
-
initialPrompt: '',
|
|
713
|
-
},
|
|
714
|
-
]
|
|
715
|
-
const childBlock: ContentBlock = { type: 'text', content: 'Child content' }
|
|
716
|
-
const { blocks: result, parentFound } = nestBlockUnderParent(
|
|
717
|
-
blocks,
|
|
718
|
-
'parent',
|
|
719
|
-
childBlock,
|
|
720
|
-
)
|
|
721
|
-
expect(parentFound).toBe(true)
|
|
722
|
-
expect((result[0] as AgentContentBlock).blocks).toHaveLength(1)
|
|
723
|
-
expect((result[0] as AgentContentBlock).blocks![0]).toEqual(childBlock)
|
|
724
|
-
})
|
|
725
|
-
|
|
726
|
-
test('returns parentFound false when parent not found', () => {
|
|
727
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
728
|
-
const childBlock: ContentBlock = { type: 'text', content: 'Child' }
|
|
729
|
-
const { blocks: result, parentFound } = nestBlockUnderParent(
|
|
730
|
-
blocks,
|
|
731
|
-
'nonexistent',
|
|
732
|
-
childBlock,
|
|
733
|
-
)
|
|
734
|
-
expect(parentFound).toBe(false)
|
|
735
|
-
expect(result).toBe(blocks)
|
|
736
|
-
})
|
|
737
|
-
|
|
738
|
-
test('appends to existing blocks in parent', () => {
|
|
739
|
-
const blocks: ContentBlock[] = [
|
|
740
|
-
{
|
|
741
|
-
type: 'agent',
|
|
742
|
-
agentId: 'parent',
|
|
743
|
-
agentName: 'Parent',
|
|
744
|
-
agentType: 'parent',
|
|
745
|
-
content: '',
|
|
746
|
-
status: 'running',
|
|
747
|
-
blocks: [{ type: 'text', content: 'Existing' }],
|
|
748
|
-
initialPrompt: '',
|
|
749
|
-
},
|
|
750
|
-
]
|
|
751
|
-
const childBlock: ContentBlock = { type: 'text', content: 'New child' }
|
|
752
|
-
const { blocks: result, parentFound } = nestBlockUnderParent(
|
|
753
|
-
blocks,
|
|
754
|
-
'parent',
|
|
755
|
-
childBlock,
|
|
756
|
-
)
|
|
757
|
-
expect(parentFound).toBe(true)
|
|
758
|
-
expect((result[0] as AgentContentBlock).blocks).toHaveLength(2)
|
|
759
|
-
expect((result[0] as AgentContentBlock).blocks![1]).toEqual(childBlock)
|
|
760
|
-
})
|
|
761
|
-
|
|
762
|
-
test('nests under deeply nested parent', () => {
|
|
763
|
-
const blocks: ContentBlock[] = [
|
|
764
|
-
{
|
|
765
|
-
type: 'agent',
|
|
766
|
-
agentId: 'grandparent',
|
|
767
|
-
agentName: 'GP',
|
|
768
|
-
agentType: 'gp',
|
|
769
|
-
content: '',
|
|
770
|
-
status: 'running',
|
|
771
|
-
blocks: [
|
|
772
|
-
{
|
|
773
|
-
type: 'agent',
|
|
774
|
-
agentId: 'parent',
|
|
775
|
-
agentName: 'Parent',
|
|
776
|
-
agentType: 'parent',
|
|
777
|
-
content: '',
|
|
778
|
-
status: 'running',
|
|
779
|
-
blocks: [],
|
|
780
|
-
initialPrompt: '',
|
|
781
|
-
},
|
|
782
|
-
],
|
|
783
|
-
initialPrompt: '',
|
|
784
|
-
},
|
|
785
|
-
]
|
|
786
|
-
const childBlock: ContentBlock = { type: 'text', content: 'Nested child' }
|
|
787
|
-
const { blocks: result, parentFound } = nestBlockUnderParent(
|
|
788
|
-
blocks,
|
|
789
|
-
'parent',
|
|
790
|
-
childBlock,
|
|
791
|
-
)
|
|
792
|
-
expect(parentFound).toBe(true)
|
|
793
|
-
const grandparent = result[0] as AgentContentBlock
|
|
794
|
-
const parent = grandparent.blocks![0] as AgentContentBlock
|
|
795
|
-
expect(parent.blocks).toHaveLength(1)
|
|
796
|
-
expect(parent.blocks![0]).toEqual(childBlock)
|
|
797
|
-
})
|
|
798
|
-
})
|
|
799
|
-
|
|
800
|
-
describe('moveSpawnAgentBlock', () => {
|
|
801
|
-
test('replaces temp agent id with real id', () => {
|
|
802
|
-
const blocks: ContentBlock[] = [
|
|
803
|
-
{
|
|
804
|
-
type: 'agent',
|
|
805
|
-
agentId: 'temp',
|
|
806
|
-
agentName: 'Temp',
|
|
807
|
-
agentType: 'temp',
|
|
808
|
-
content: '',
|
|
809
|
-
status: 'running',
|
|
810
|
-
blocks: [],
|
|
811
|
-
initialPrompt: '',
|
|
812
|
-
},
|
|
813
|
-
]
|
|
814
|
-
const result = moveSpawnAgentBlock(blocks, 'temp', 'real')
|
|
815
|
-
expect((result[0] as AgentContentBlock).agentId).toBe('real')
|
|
816
|
-
})
|
|
817
|
-
|
|
818
|
-
test('nests extracted block under parent when found', () => {
|
|
819
|
-
const blocks: ContentBlock[] = [
|
|
820
|
-
{
|
|
821
|
-
type: 'agent',
|
|
822
|
-
agentId: 'parent',
|
|
823
|
-
agentName: 'Parent',
|
|
824
|
-
agentType: 'parent',
|
|
825
|
-
content: '',
|
|
826
|
-
status: 'running',
|
|
827
|
-
blocks: [
|
|
828
|
-
{
|
|
829
|
-
type: 'agent',
|
|
830
|
-
agentId: 'temp',
|
|
831
|
-
agentName: 'Temp',
|
|
832
|
-
agentType: 'temp',
|
|
833
|
-
content: '',
|
|
834
|
-
status: 'running',
|
|
835
|
-
blocks: [],
|
|
836
|
-
initialPrompt: '',
|
|
837
|
-
},
|
|
838
|
-
],
|
|
839
|
-
initialPrompt: '',
|
|
840
|
-
},
|
|
841
|
-
]
|
|
842
|
-
const result = moveSpawnAgentBlock(blocks, 'temp', 'real', 'parent')
|
|
843
|
-
const parent = result[0] as AgentContentBlock
|
|
844
|
-
expect(parent.blocks).toHaveLength(1)
|
|
845
|
-
expect((parent.blocks![0] as AgentContentBlock).agentId).toBe('real')
|
|
846
|
-
})
|
|
847
|
-
|
|
848
|
-
test('updates in place when parent missing to preserve order', () => {
|
|
849
|
-
const blocks: ContentBlock[] = [
|
|
850
|
-
{
|
|
851
|
-
type: 'agent',
|
|
852
|
-
agentId: 'temp',
|
|
853
|
-
agentName: 'Temp',
|
|
854
|
-
agentType: 'temp',
|
|
855
|
-
content: '',
|
|
856
|
-
status: 'running',
|
|
857
|
-
blocks: [],
|
|
858
|
-
initialPrompt: '',
|
|
859
|
-
},
|
|
860
|
-
{ type: 'text', content: 'other' },
|
|
861
|
-
]
|
|
862
|
-
const result = moveSpawnAgentBlock(blocks, 'temp', 'real', 'missing')
|
|
863
|
-
// Block should stay in its original position (index 0), not move to end
|
|
864
|
-
expect(result[0]).toMatchObject({ type: 'agent', agentId: 'real' })
|
|
865
|
-
expect(result[1]).toMatchObject({ type: 'text', content: 'other' })
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
test('preserves block order when multiple agents resolve out of order', () => {
|
|
869
|
-
// Simulate spawn_agents creating 3 placeholder blocks in order
|
|
870
|
-
const blocks: ContentBlock[] = [
|
|
871
|
-
{
|
|
872
|
-
type: 'agent',
|
|
873
|
-
agentId: 'toolcall-0',
|
|
874
|
-
agentName: 'Agent A',
|
|
875
|
-
agentType: 'file-picker',
|
|
876
|
-
content: '',
|
|
877
|
-
status: 'running',
|
|
878
|
-
blocks: [],
|
|
879
|
-
initialPrompt: '',
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
type: 'agent',
|
|
883
|
-
agentId: 'toolcall-1',
|
|
884
|
-
agentName: 'Agent B',
|
|
885
|
-
agentType: 'code-searcher',
|
|
886
|
-
content: '',
|
|
887
|
-
status: 'running',
|
|
888
|
-
blocks: [],
|
|
889
|
-
initialPrompt: '',
|
|
890
|
-
},
|
|
891
|
-
{
|
|
892
|
-
type: 'agent',
|
|
893
|
-
agentId: 'toolcall-2',
|
|
894
|
-
agentName: 'Agent C',
|
|
895
|
-
agentType: 'commander',
|
|
896
|
-
content: '',
|
|
897
|
-
status: 'running',
|
|
898
|
-
blocks: [],
|
|
899
|
-
initialPrompt: '',
|
|
900
|
-
},
|
|
901
|
-
]
|
|
902
|
-
|
|
903
|
-
// Agents resolve in different order: C first, then A, then B
|
|
904
|
-
let result = moveSpawnAgentBlock(blocks, 'toolcall-2', 'real-c')
|
|
905
|
-
result = moveSpawnAgentBlock(result, 'toolcall-0', 'real-a')
|
|
906
|
-
result = moveSpawnAgentBlock(result, 'toolcall-1', 'real-b')
|
|
907
|
-
|
|
908
|
-
// Order should be preserved: A, B, C
|
|
909
|
-
expect(result[0]).toMatchObject({ agentId: 'real-a' })
|
|
910
|
-
expect(result[1]).toMatchObject({ agentId: 'real-b' })
|
|
911
|
-
expect(result[2]).toMatchObject({ agentId: 'real-c' })
|
|
912
|
-
})
|
|
913
|
-
})
|
|
914
|
-
|
|
915
|
-
describe('extractBlockById', () => {
|
|
916
|
-
test('extracts block from top level', () => {
|
|
917
|
-
const blocks: ContentBlock[] = [
|
|
918
|
-
{ type: 'text', content: 'Keep me' },
|
|
919
|
-
{
|
|
920
|
-
type: 'agent',
|
|
921
|
-
agentId: 'extract-me',
|
|
922
|
-
agentName: 'Extract',
|
|
923
|
-
agentType: 'extract',
|
|
924
|
-
content: '',
|
|
925
|
-
status: 'running',
|
|
926
|
-
blocks: [],
|
|
927
|
-
initialPrompt: '',
|
|
928
|
-
},
|
|
929
|
-
]
|
|
930
|
-
const { remainingBlocks, extractedBlock } = extractBlockById(
|
|
931
|
-
blocks,
|
|
932
|
-
'extract-me',
|
|
933
|
-
)
|
|
934
|
-
expect(remainingBlocks).toHaveLength(1)
|
|
935
|
-
expect(remainingBlocks[0].type).toBe('text')
|
|
936
|
-
expect(extractedBlock).not.toBeNull()
|
|
937
|
-
expect((extractedBlock as AgentContentBlock).agentId).toBe('extract-me')
|
|
938
|
-
})
|
|
939
|
-
|
|
940
|
-
test('returns null when block not found', () => {
|
|
941
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
942
|
-
const { remainingBlocks, extractedBlock } = extractBlockById(
|
|
943
|
-
blocks,
|
|
944
|
-
'nonexistent',
|
|
945
|
-
)
|
|
946
|
-
expect(remainingBlocks).toHaveLength(1)
|
|
947
|
-
expect(extractedBlock).toBeNull()
|
|
948
|
-
})
|
|
949
|
-
|
|
950
|
-
test('extracts from nested blocks', () => {
|
|
951
|
-
const blocks: ContentBlock[] = [
|
|
952
|
-
{
|
|
953
|
-
type: 'agent',
|
|
954
|
-
agentId: 'parent',
|
|
955
|
-
agentName: 'Parent',
|
|
956
|
-
agentType: 'parent',
|
|
957
|
-
content: '',
|
|
958
|
-
status: 'running',
|
|
959
|
-
blocks: [
|
|
960
|
-
{
|
|
961
|
-
type: 'agent',
|
|
962
|
-
agentId: 'nested-child',
|
|
963
|
-
agentName: 'Child',
|
|
964
|
-
agentType: 'child',
|
|
965
|
-
content: '',
|
|
966
|
-
status: 'running',
|
|
967
|
-
blocks: [],
|
|
968
|
-
initialPrompt: '',
|
|
969
|
-
},
|
|
970
|
-
],
|
|
971
|
-
initialPrompt: '',
|
|
972
|
-
},
|
|
973
|
-
]
|
|
974
|
-
const { remainingBlocks, extractedBlock } = extractBlockById(
|
|
975
|
-
blocks,
|
|
976
|
-
'nested-child',
|
|
977
|
-
)
|
|
978
|
-
expect((remainingBlocks[0] as AgentContentBlock).blocks).toHaveLength(0)
|
|
979
|
-
expect(extractedBlock).not.toBeNull()
|
|
980
|
-
expect((extractedBlock as AgentContentBlock).agentId).toBe('nested-child')
|
|
981
|
-
})
|
|
982
|
-
|
|
983
|
-
test('handles empty blocks array', () => {
|
|
984
|
-
const { remainingBlocks, extractedBlock } = extractBlockById([], 'any-id')
|
|
985
|
-
expect(remainingBlocks).toHaveLength(0)
|
|
986
|
-
expect(extractedBlock).toBeNull()
|
|
987
|
-
})
|
|
988
|
-
|
|
989
|
-
test('preserves non-matching nested structure', () => {
|
|
990
|
-
const blocks: ContentBlock[] = [
|
|
991
|
-
{
|
|
992
|
-
type: 'agent',
|
|
993
|
-
agentId: 'parent',
|
|
994
|
-
agentName: 'Parent',
|
|
995
|
-
agentType: 'parent',
|
|
996
|
-
content: '',
|
|
997
|
-
status: 'running',
|
|
998
|
-
blocks: [
|
|
999
|
-
{ type: 'text', content: 'Keep this' },
|
|
1000
|
-
{
|
|
1001
|
-
type: 'agent',
|
|
1002
|
-
agentId: 'extract-me',
|
|
1003
|
-
agentName: 'Extract',
|
|
1004
|
-
agentType: 'extract',
|
|
1005
|
-
content: '',
|
|
1006
|
-
status: 'running',
|
|
1007
|
-
blocks: [],
|
|
1008
|
-
initialPrompt: '',
|
|
1009
|
-
},
|
|
1010
|
-
{ type: 'text', content: 'Keep this too' },
|
|
1011
|
-
],
|
|
1012
|
-
initialPrompt: '',
|
|
1013
|
-
},
|
|
1014
|
-
]
|
|
1015
|
-
const { remainingBlocks, extractedBlock } = extractBlockById(
|
|
1016
|
-
blocks,
|
|
1017
|
-
'extract-me',
|
|
1018
|
-
)
|
|
1019
|
-
const parentBlock = remainingBlocks[0] as AgentContentBlock
|
|
1020
|
-
expect(parentBlock.blocks).toHaveLength(2)
|
|
1021
|
-
expect((parentBlock.blocks![0] as TextContentBlock).content).toBe(
|
|
1022
|
-
'Keep this',
|
|
1023
|
-
)
|
|
1024
|
-
expect((parentBlock.blocks![1] as TextContentBlock).content).toBe(
|
|
1025
|
-
'Keep this too',
|
|
1026
|
-
)
|
|
1027
|
-
expect(extractedBlock).not.toBeNull()
|
|
1028
|
-
})
|
|
1029
|
-
})
|
|
1030
|
-
|
|
1031
|
-
describe('transformAskUserBlocks', () => {
|
|
1032
|
-
test('transforms ask_user tool block to ask-user block', () => {
|
|
1033
|
-
const blocks: ContentBlock[] = [
|
|
1034
|
-
{
|
|
1035
|
-
type: 'tool',
|
|
1036
|
-
toolCallId: 'tool-123',
|
|
1037
|
-
toolName: 'ask_user',
|
|
1038
|
-
input: {
|
|
1039
|
-
questions: [
|
|
1040
|
-
{ question: 'Pick one', options: [{ label: 'A' }, { label: 'B' }] },
|
|
1041
|
-
],
|
|
1042
|
-
},
|
|
1043
|
-
},
|
|
1044
|
-
]
|
|
1045
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1046
|
-
toolCallId: 'tool-123',
|
|
1047
|
-
resultValue: { answers: [{ questionIndex: 0, selectedOption: 'A' }] },
|
|
1048
|
-
})
|
|
1049
|
-
expect(result[0].type).toBe('ask-user')
|
|
1050
|
-
const askUserBlock = result[0] as AskUserContentBlock
|
|
1051
|
-
expect(askUserBlock.answers).toEqual([
|
|
1052
|
-
{ questionIndex: 0, selectedOption: 'A' },
|
|
1053
|
-
])
|
|
1054
|
-
expect(askUserBlock.questions).toEqual([
|
|
1055
|
-
{ question: 'Pick one', options: [{ label: 'A' }, { label: 'B' }] },
|
|
1056
|
-
])
|
|
1057
|
-
})
|
|
1058
|
-
|
|
1059
|
-
test('transforms skipped ask_user block', () => {
|
|
1060
|
-
const blocks: ContentBlock[] = [
|
|
1061
|
-
{
|
|
1062
|
-
type: 'tool',
|
|
1063
|
-
toolCallId: 'tool-123',
|
|
1064
|
-
toolName: 'ask_user',
|
|
1065
|
-
input: {
|
|
1066
|
-
questions: [
|
|
1067
|
-
{ question: 'Pick one', options: [{ label: 'A' }, { label: 'B' }] },
|
|
1068
|
-
],
|
|
1069
|
-
},
|
|
1070
|
-
},
|
|
1071
|
-
]
|
|
1072
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1073
|
-
toolCallId: 'tool-123',
|
|
1074
|
-
resultValue: { skipped: true },
|
|
1075
|
-
})
|
|
1076
|
-
expect(result[0].type).toBe('ask-user')
|
|
1077
|
-
expect((result[0] as AskUserContentBlock).skipped).toBe(true)
|
|
1078
|
-
})
|
|
1079
|
-
|
|
1080
|
-
test('keeps tool block when no result data', () => {
|
|
1081
|
-
const blocks: ContentBlock[] = [
|
|
1082
|
-
{
|
|
1083
|
-
type: 'tool',
|
|
1084
|
-
toolCallId: 'tool-123',
|
|
1085
|
-
toolName: 'ask_user',
|
|
1086
|
-
input: { questions: [] },
|
|
1087
|
-
},
|
|
1088
|
-
]
|
|
1089
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1090
|
-
toolCallId: 'tool-123',
|
|
1091
|
-
resultValue: {},
|
|
1092
|
-
})
|
|
1093
|
-
expect(result[0].type).toBe('tool')
|
|
1094
|
-
})
|
|
1095
|
-
|
|
1096
|
-
test('does not transform non-matching tool', () => {
|
|
1097
|
-
const blocks: ContentBlock[] = [
|
|
1098
|
-
{
|
|
1099
|
-
type: 'tool',
|
|
1100
|
-
toolCallId: 'tool-123',
|
|
1101
|
-
toolName: 'ask_user',
|
|
1102
|
-
input: { questions: [] },
|
|
1103
|
-
},
|
|
1104
|
-
]
|
|
1105
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1106
|
-
toolCallId: 'different-id',
|
|
1107
|
-
resultValue: { answers: [{ questionIndex: 0, selectedOption: 'A' }] },
|
|
1108
|
-
})
|
|
1109
|
-
expect(result[0].type).toBe('tool')
|
|
1110
|
-
})
|
|
1111
|
-
|
|
1112
|
-
test('transforms nested ask_user in agent blocks', () => {
|
|
1113
|
-
const blocks: ContentBlock[] = [
|
|
1114
|
-
{
|
|
1115
|
-
type: 'agent',
|
|
1116
|
-
agentId: 'agent-1',
|
|
1117
|
-
agentName: 'Test',
|
|
1118
|
-
agentType: 'test',
|
|
1119
|
-
content: '',
|
|
1120
|
-
status: 'running',
|
|
1121
|
-
blocks: [
|
|
1122
|
-
{
|
|
1123
|
-
type: 'tool',
|
|
1124
|
-
toolCallId: 'tool-123',
|
|
1125
|
-
toolName: 'ask_user',
|
|
1126
|
-
input: { questions: [{ question: 'Q?' }] },
|
|
1127
|
-
},
|
|
1128
|
-
],
|
|
1129
|
-
initialPrompt: '',
|
|
1130
|
-
},
|
|
1131
|
-
]
|
|
1132
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1133
|
-
toolCallId: 'tool-123',
|
|
1134
|
-
resultValue: { answers: ['Yes'] },
|
|
1135
|
-
})
|
|
1136
|
-
expect((result[0] as AgentContentBlock).blocks![0].type).toBe('ask-user')
|
|
1137
|
-
})
|
|
1138
|
-
|
|
1139
|
-
test('returns same reference when nothing changes', () => {
|
|
1140
|
-
const blocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
1141
|
-
const result = transformAskUserBlocks(blocks, {
|
|
1142
|
-
toolCallId: 'tool-123',
|
|
1143
|
-
resultValue: { answers: [{ questionIndex: 0, selectedOption: 'A' }] },
|
|
1144
|
-
})
|
|
1145
|
-
expect(result[0]).toBe(blocks[0])
|
|
1146
|
-
})
|
|
1147
|
-
})
|
|
1148
|
-
|
|
1149
|
-
describe('updateToolBlockWithOutput', () => {
|
|
1150
|
-
test('updates tool block with formatted output', () => {
|
|
1151
|
-
const blocks: ContentBlock[] = [
|
|
1152
|
-
{
|
|
1153
|
-
type: 'tool',
|
|
1154
|
-
toolCallId: 'tool-123',
|
|
1155
|
-
toolName: 'read_files',
|
|
1156
|
-
input: { paths: ['file.ts'] },
|
|
1157
|
-
},
|
|
1158
|
-
]
|
|
1159
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1160
|
-
toolCallId: 'tool-123',
|
|
1161
|
-
toolOutput: [{ type: 'text', value: 'file contents' }],
|
|
1162
|
-
})
|
|
1163
|
-
expect((result[0] as ToolContentBlock).output).toBeDefined()
|
|
1164
|
-
})
|
|
1165
|
-
|
|
1166
|
-
test('formats terminal command output specially', () => {
|
|
1167
|
-
const blocks: ContentBlock[] = [
|
|
1168
|
-
{
|
|
1169
|
-
type: 'tool',
|
|
1170
|
-
toolCallId: 'tool-123',
|
|
1171
|
-
toolName: 'run_terminal_command',
|
|
1172
|
-
input: { command: 'echo hi' },
|
|
1173
|
-
},
|
|
1174
|
-
]
|
|
1175
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1176
|
-
toolCallId: 'tool-123',
|
|
1177
|
-
toolOutput: [{ value: { stdout: 'hi\n', stderr: '' } }],
|
|
1178
|
-
})
|
|
1179
|
-
expect((result[0] as ToolContentBlock).output).toBe('hi\n')
|
|
1180
|
-
})
|
|
1181
|
-
|
|
1182
|
-
test('combines stdout and stderr for terminal commands', () => {
|
|
1183
|
-
const blocks: ContentBlock[] = [
|
|
1184
|
-
{
|
|
1185
|
-
type: 'tool',
|
|
1186
|
-
toolCallId: 'tool-123',
|
|
1187
|
-
toolName: 'run_terminal_command',
|
|
1188
|
-
input: { command: 'cmd' },
|
|
1189
|
-
},
|
|
1190
|
-
]
|
|
1191
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1192
|
-
toolCallId: 'tool-123',
|
|
1193
|
-
toolOutput: [{ value: { stdout: 'out', stderr: 'err' } }],
|
|
1194
|
-
})
|
|
1195
|
-
expect((result[0] as ToolContentBlock).output).toBe('outerr')
|
|
1196
|
-
})
|
|
1197
|
-
|
|
1198
|
-
test('does not update non-matching tool block', () => {
|
|
1199
|
-
const blocks: ContentBlock[] = [
|
|
1200
|
-
{
|
|
1201
|
-
type: 'tool',
|
|
1202
|
-
toolCallId: 'tool-123',
|
|
1203
|
-
toolName: 'read_files',
|
|
1204
|
-
input: {},
|
|
1205
|
-
},
|
|
1206
|
-
]
|
|
1207
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1208
|
-
toolCallId: 'different-id',
|
|
1209
|
-
toolOutput: [{ value: 'output' }],
|
|
1210
|
-
})
|
|
1211
|
-
expect((result[0] as ToolContentBlock).output).toBeUndefined()
|
|
1212
|
-
})
|
|
1213
|
-
|
|
1214
|
-
test('updates nested tool blocks in agent', () => {
|
|
1215
|
-
const blocks: ContentBlock[] = [
|
|
1216
|
-
{
|
|
1217
|
-
type: 'agent',
|
|
1218
|
-
agentId: 'agent-1',
|
|
1219
|
-
agentName: 'Test',
|
|
1220
|
-
agentType: 'test',
|
|
1221
|
-
content: '',
|
|
1222
|
-
status: 'running',
|
|
1223
|
-
blocks: [
|
|
1224
|
-
{
|
|
1225
|
-
type: 'tool',
|
|
1226
|
-
toolCallId: 'tool-123',
|
|
1227
|
-
toolName: 'read_files',
|
|
1228
|
-
input: {},
|
|
1229
|
-
},
|
|
1230
|
-
],
|
|
1231
|
-
initialPrompt: '',
|
|
1232
|
-
},
|
|
1233
|
-
]
|
|
1234
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1235
|
-
toolCallId: 'tool-123',
|
|
1236
|
-
toolOutput: [{ type: 'text', value: 'contents' }],
|
|
1237
|
-
})
|
|
1238
|
-
expect(
|
|
1239
|
-
((result[0] as AgentContentBlock).blocks![0] as ToolContentBlock).output,
|
|
1240
|
-
).toBeDefined()
|
|
1241
|
-
})
|
|
1242
|
-
|
|
1243
|
-
test('returns same reference for unchanged nested blocks', () => {
|
|
1244
|
-
const nestedBlocks: ContentBlock[] = [{ type: 'text', content: 'Hello' }]
|
|
1245
|
-
const blocks: ContentBlock[] = [
|
|
1246
|
-
{
|
|
1247
|
-
type: 'agent',
|
|
1248
|
-
agentId: 'agent-1',
|
|
1249
|
-
agentName: 'Test',
|
|
1250
|
-
agentType: 'test',
|
|
1251
|
-
content: '',
|
|
1252
|
-
status: 'running',
|
|
1253
|
-
blocks: nestedBlocks,
|
|
1254
|
-
initialPrompt: '',
|
|
1255
|
-
},
|
|
1256
|
-
]
|
|
1257
|
-
const result = updateToolBlockWithOutput(blocks, {
|
|
1258
|
-
toolCallId: 'non-existent',
|
|
1259
|
-
toolOutput: [],
|
|
1260
|
-
})
|
|
1261
|
-
expect(result[0]).toBe(blocks[0])
|
|
1262
|
-
})
|
|
1263
|
-
})
|