import React, { type ReactNode } from 'react' import { type KeyboardEvent, Box, Byline, KeyboardShortcutHint, Text } from '@anthropic/ink' import { useKeybinding } from '../../../../keybindings/useKeybinding.js' import { isAutoMemoryEnabled } from '../../../../memdir/paths.js' import type { Tools } from '../../../../Tool.js' import { getMemoryScopeDisplay } from '../../../../tools/AgentTool/agentMemory.js' import type { AgentDefinition } from '../../../../tools/AgentTool/loadAgentsDir.js' import { truncateToWidth } from '../../../../utils/format.js' import { getAgentModelDisplay } from '../../../../utils/model/agent.js' import { ConfigurableShortcutHint } from '../../../ConfigurableShortcutHint.js' import { useWizard } from '../../../wizard/index.js' import { WizardDialogLayout } from '../../../wizard/WizardDialogLayout.js' import { getNewRelativeAgentFilePath } from '../../agentFileUtils.js' import { validateAgent } from '../../validateAgent.js' import type { AgentWizardData } from '../types.js' type Props = { tools: Tools existingAgents: AgentDefinition[] onSave: () => void onSaveAndEdit: () => void error?: string | null } export function ConfirmStep({ tools, existingAgents, onSave, onSaveAndEdit, error, }: Props): ReactNode { const { goBack, wizardData } = useWizard() useKeybinding('confirm:no', goBack, { context: 'Confirmation' }) const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 's' || e.key === 'return') { e.preventDefault() onSave() } else if (e.key === 'e') { e.preventDefault() onSaveAndEdit() } } const agent = wizardData.finalAgent! const validation = validateAgent(agent, tools, existingAgents) const systemPromptPreview = truncateToWidth(agent.getSystemPrompt(), 240) const whenToUsePreview = truncateToWidth(agent.whenToUse, 240) const getToolsDisplay = (toolNames: string[] | undefined): string => { // undefined means "all tools" per PR semantic if (toolNames === undefined) return 'All tools' if (toolNames.length === 0) return 'None' if (toolNames.length === 1) return toolNames[0] || 'None' if (toolNames.length === 2) return toolNames.join(' and ') return `${toolNames.slice(0, -1).join(', ')}, and ${toolNames[toolNames.length - 1]}` } // Compute memory display outside JSX const memoryDisplayElement = isAutoMemoryEnabled() ? ( Memory: {getMemoryScopeDisplay(agent.memory)} ) : null return ( } > Name: {agent.agentType} Location:{' '} {getNewRelativeAgentFilePath({ source: wizardData.location!, agentType: agent.agentType, })} Tools: {getToolsDisplay(agent.tools)} Model: {getAgentModelDisplay(agent.model)} {memoryDisplayElement} Description (tells Claude when to use this agent): {whenToUsePreview} System prompt: {systemPromptPreview} {validation.warnings.length > 0 && ( Warnings: {validation.warnings.map((warning, i) => ( {' '} • {warning} ))} )} {validation.errors.length > 0 && ( Errors: {validation.errors.map((err, i) => ( {' '} • {err} ))} )} {error && ( {error} )} Press s or Enter to save,{' '} e to save and edit ) }