@within-7/minto 0.1.4 → 0.1.6
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/dist/commands/agents/AgentsCommand.js +2342 -0
- package/dist/commands/agents/AgentsCommand.js.map +7 -0
- package/dist/commands/agents/constants.js +58 -0
- package/dist/commands/agents/constants.js.map +7 -0
- package/dist/commands/agents/index.js +37 -0
- package/dist/commands/agents/index.js.map +7 -0
- package/dist/commands/agents/types.js +10 -0
- package/dist/commands/agents/types.js.map +7 -0
- package/dist/commands/agents/utils/fileOperations.js +185 -0
- package/dist/commands/agents/utils/fileOperations.js.map +7 -0
- package/dist/commands/agents/utils/index.js +21 -0
- package/dist/commands/agents/utils/index.js.map +7 -0
- package/dist/commands/bug.js +2 -2
- package/dist/commands/bug.js.map +2 -2
- package/dist/commands/compact.js +5 -5
- package/dist/commands/compact.js.map +2 -2
- package/dist/commands/ctx_viz.js +55 -22
- package/dist/commands/ctx_viz.js.map +2 -2
- package/dist/commands/mcp-interactive.js +11 -11
- package/dist/commands/mcp-interactive.js.map +2 -2
- package/dist/commands/model.js +94 -32
- package/dist/commands/model.js.map +3 -3
- package/dist/commands/plugin/AddMarketplaceForm.js +49 -21
- package/dist/commands/plugin/AddMarketplaceForm.js.map +2 -2
- package/dist/commands/plugin/ConfirmDialog.js +38 -26
- package/dist/commands/plugin/ConfirmDialog.js.map +2 -2
- package/dist/commands/plugin/InstalledPluginsByMarketplace.js +24 -8
- package/dist/commands/plugin/InstalledPluginsByMarketplace.js.map +2 -2
- package/dist/commands/plugin/InstalledPluginsManager.js +3 -1
- package/dist/commands/plugin/InstalledPluginsManager.js.map +2 -2
- package/dist/commands/plugin/MainMenu.js +16 -7
- package/dist/commands/plugin/MainMenu.js.map +2 -2
- package/dist/commands/plugin/MarketplaceManager.js +84 -39
- package/dist/commands/plugin/MarketplaceManager.js.map +2 -2
- package/dist/commands/plugin/MarketplaceSelector.js +7 -3
- package/dist/commands/plugin/MarketplaceSelector.js.map +2 -2
- package/dist/commands/plugin/PlaceholderScreen.js +16 -2
- package/dist/commands/plugin/PlaceholderScreen.js.map +2 -2
- package/dist/commands/plugin/PluginBrowser.js +4 -2
- package/dist/commands/plugin/PluginBrowser.js.map +2 -2
- package/dist/commands/plugin/PluginDetailsInstall.js +12 -6
- package/dist/commands/plugin/PluginDetailsInstall.js.map +2 -2
- package/dist/commands/plugin/PluginDetailsManage.js +14 -5
- package/dist/commands/plugin/PluginDetailsManage.js.map +2 -2
- package/dist/commands/plugin/example-usage.js.map +2 -2
- package/dist/commands/plugin/utils.js.map +2 -2
- package/dist/commands/plugin.js +226 -46
- package/dist/commands/plugin.js.map +2 -2
- package/dist/commands/refreshCommands.js +6 -3
- package/dist/commands/refreshCommands.js.map +2 -2
- package/dist/commands/resume.js +2 -1
- package/dist/commands/resume.js.map +2 -2
- package/dist/commands/setup.js +19 -5
- package/dist/commands/setup.js.map +2 -2
- package/dist/commands/terminalSetup.js +2 -2
- package/dist/commands/terminalSetup.js.map +1 -1
- package/dist/commands.js +14 -30
- package/dist/commands.js.map +2 -2
- package/dist/components/AskUserQuestionDialog/AskUserQuestionDialog.js.map +2 -2
- package/dist/components/AskUserQuestionDialog/QuestionView.js +10 -1
- package/dist/components/AskUserQuestionDialog/QuestionView.js.map +2 -2
- package/dist/components/BackgroundTasksPanel.js +5 -1
- package/dist/components/BackgroundTasksPanel.js.map +2 -2
- package/dist/components/Config.js +17 -4
- package/dist/components/Config.js.map +2 -2
- package/dist/components/ConsoleOAuthFlow.js.map +2 -2
- package/dist/components/CustomSelect/select-option.js +4 -1
- package/dist/components/CustomSelect/select-option.js.map +2 -2
- package/dist/components/Help.js +6 -8
- package/dist/components/Help.js.map +2 -2
- package/dist/components/Logo.js +1 -1
- package/dist/components/Logo.js.map +2 -2
- package/dist/components/ModelListManager.js.map +2 -2
- package/dist/components/ModelSelector/ModelSelector.js +2030 -0
- package/dist/components/ModelSelector/ModelSelector.js.map +7 -0
- package/dist/components/ModelSelector/ScreenContainer.js +27 -0
- package/dist/components/ModelSelector/ScreenContainer.js.map +7 -0
- package/dist/components/ModelSelector/constants.js +37 -0
- package/dist/components/ModelSelector/constants.js.map +7 -0
- package/dist/components/ModelSelector/hooks/index.js +5 -0
- package/dist/components/ModelSelector/hooks/index.js.map +7 -0
- package/dist/components/ModelSelector/hooks/useEscapeNavigation.js +21 -0
- package/dist/components/ModelSelector/hooks/useEscapeNavigation.js.map +7 -0
- package/dist/components/ModelSelector/index.js +17 -0
- package/dist/components/ModelSelector/index.js.map +7 -0
- package/dist/components/ModelSelector/types.js +1 -0
- package/dist/components/ModelSelector/types.js.map +7 -0
- package/dist/components/PressEnterToContinue.js +1 -1
- package/dist/components/PressEnterToContinue.js.map +2 -2
- package/dist/components/ProjectOnboarding.js +1 -1
- package/dist/components/ProjectOnboarding.js.map +2 -2
- package/dist/components/PromptInput.js +88 -37
- package/dist/components/PromptInput.js.map +2 -2
- package/dist/components/QuitSummary.js +17 -10
- package/dist/components/QuitSummary.js.map +2 -2
- package/dist/components/SentryErrorBoundary.js.map +2 -2
- package/dist/components/StreamingBashOutput.js.map +2 -2
- package/dist/components/StructuredDiff.js.map +2 -2
- package/dist/components/SubagentProgress.js.map +2 -2
- package/dist/components/TaskCard.js.map +2 -2
- package/dist/components/TextInput.js.map +1 -1
- package/dist/components/TodoItem.js.map +1 -1
- package/dist/components/binary-feedback/BinaryFeedbackOption.js +1 -3
- package/dist/components/binary-feedback/BinaryFeedbackOption.js.map +2 -2
- package/dist/components/messages/AssistantLocalCommandOutputMessage.js.map +1 -1
- package/dist/components/messages/AssistantToolUseMessage.js +3 -1
- package/dist/components/messages/AssistantToolUseMessage.js.map +2 -2
- package/dist/components/messages/TaskProgressMessage.js.map +2 -2
- package/dist/components/messages/TaskToolMessage.js.map +2 -2
- package/dist/components/messages/UserToolResultMessage/utils.js.map +2 -2
- package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +2 -2
- package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +2 -2
- package/dist/components/permissions/hooks.js.map +2 -2
- package/dist/constants/modelCapabilities.js +1 -1
- package/dist/constants/modelCapabilities.js.map +2 -2
- package/dist/constants/prompts.js.map +1 -1
- package/dist/constants/timing.js +34 -0
- package/dist/constants/timing.js.map +7 -0
- package/dist/entrypoints/cli.js +128 -33
- package/dist/entrypoints/cli.js.map +3 -3
- package/dist/entrypoints/mcp.js +13 -18
- package/dist/entrypoints/mcp.js.map +2 -2
- package/dist/hooks/useCanUseTool.js.map +2 -2
- package/dist/hooks/useCancelRequest.js.map +1 -1
- package/dist/hooks/useHistorySearch.js.map +2 -2
- package/dist/hooks/useLogStartupTime.js.map +2 -2
- package/dist/hooks/usePermissionRequestLogging.js.map +2 -2
- package/dist/hooks/useTextInput.js.map +1 -1
- package/dist/hooks/useUnifiedCompletion.js +493 -394
- package/dist/hooks/useUnifiedCompletion.js.map +2 -2
- package/dist/index.js.map +2 -2
- package/dist/permissions.js +4 -7
- package/dist/permissions.js.map +2 -2
- package/dist/query.js +6 -1
- package/dist/query.js.map +2 -2
- package/dist/screens/REPL.js +72 -36
- package/dist/screens/REPL.js.map +2 -2
- package/dist/screens/ResumeConversation.js +2 -1
- package/dist/screens/ResumeConversation.js.map +2 -2
- package/dist/services/adapters/base.js.map +2 -2
- package/dist/services/adapters/chatCompletions.js.map +2 -2
- package/dist/services/adapters/responsesAPI.js +3 -1
- package/dist/services/adapters/responsesAPI.js.map +2 -2
- package/dist/services/claude.js +327 -328
- package/dist/services/claude.js.map +2 -2
- package/dist/services/customCommands.js +6 -1
- package/dist/services/customCommands.js.map +2 -2
- package/dist/services/fileFreshness.js.map +2 -2
- package/dist/services/gpt5ConnectionTest.js +20 -7
- package/dist/services/gpt5ConnectionTest.js.map +2 -2
- package/dist/services/hookExecutor.js +6 -12
- package/dist/services/hookExecutor.js.map +2 -2
- package/dist/services/mcpClient.js +29 -2
- package/dist/services/mcpClient.js.map +2 -2
- package/dist/services/mentionProcessor.js +23 -10
- package/dist/services/mentionProcessor.js.map +2 -2
- package/dist/services/modelAdapterFactory.js.map +2 -2
- package/dist/services/oauth.js.map +2 -2
- package/dist/services/openai.js +109 -72
- package/dist/services/openai.js.map +3 -3
- package/dist/services/responseStateManager.js.map +2 -2
- package/dist/services/systemReminder.js.map +2 -2
- package/dist/tools/ArchitectTool/ArchitectTool.js.map +1 -1
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +14 -8
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +2 -2
- package/dist/tools/BashOutputTool/BashOutputTool.js.map +2 -2
- package/dist/tools/BashTool/BashTool.js.map +2 -2
- package/dist/tools/FileReadTool/FileReadTool.js.map +1 -1
- package/dist/tools/FileWriteTool/FileWriteTool.js.map +2 -2
- package/dist/tools/GrepTool/GrepTool.js +1 -4
- package/dist/tools/GrepTool/GrepTool.js.map +2 -2
- package/dist/tools/MultiEditTool/MultiEditTool.js +4 -1
- package/dist/tools/MultiEditTool/MultiEditTool.js.map +2 -2
- package/dist/tools/NotebookReadTool/NotebookReadTool.js +3 -1
- package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +2 -2
- package/dist/tools/SkillTool/SkillTool.js +12 -6
- package/dist/tools/SkillTool/SkillTool.js.map +2 -2
- package/dist/tools/TaskTool/TaskTool.js +14 -5
- package/dist/tools/TaskTool/TaskTool.js.map +2 -2
- package/dist/tools/TaskTool/prompt.js.map +2 -2
- package/dist/tools/ThinkTool/ThinkTool.js +6 -1
- package/dist/tools/ThinkTool/ThinkTool.js.map +2 -2
- package/dist/tools/TodoWriteTool/TodoWriteTool.js +23 -3
- package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +2 -2
- package/dist/tools/URLFetcherTool/URLFetcherTool.js +2 -2
- package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +2 -2
- package/dist/tools/URLFetcherTool/cache.js +6 -3
- package/dist/tools/URLFetcherTool/cache.js.map +2 -2
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js +3 -1
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js.map +2 -2
- package/dist/tools/WebSearchTool/WebSearchTool.js.map +2 -2
- package/dist/tools/WebSearchTool/prompt.js.map +2 -2
- package/dist/tools/WebSearchTool/searchProviders.js +15 -6
- package/dist/tools/WebSearchTool/searchProviders.js.map +2 -2
- package/dist/tools.js +4 -1
- package/dist/tools.js.map +2 -2
- package/dist/types/core.js +1 -0
- package/dist/types/core.js.map +7 -0
- package/dist/types/hooks.js +1 -4
- package/dist/types/hooks.js.map +2 -2
- package/dist/types/marketplace.js +8 -2
- package/dist/types/marketplace.js.map +2 -2
- package/dist/types/plugin.js +9 -6
- package/dist/types/plugin.js.map +2 -2
- package/dist/utils/BackgroundShellManager.js +76 -10
- package/dist/utils/BackgroundShellManager.js.map +2 -2
- package/dist/utils/PersistentShell.js +7 -2
- package/dist/utils/PersistentShell.js.map +2 -2
- package/dist/utils/advancedFuzzyMatcher.js +4 -1
- package/dist/utils/advancedFuzzyMatcher.js.map +2 -2
- package/dist/utils/agentLoader.js +69 -35
- package/dist/utils/agentLoader.js.map +2 -2
- package/dist/utils/agentStorage.js.map +2 -2
- package/dist/utils/async.js +163 -0
- package/dist/utils/async.js.map +7 -0
- package/dist/utils/autoUpdater.js +8 -2
- package/dist/utils/autoUpdater.js.map +2 -2
- package/dist/utils/commands.js +23 -11
- package/dist/utils/commands.js.map +2 -2
- package/dist/utils/commonUnixCommands.js +3 -1
- package/dist/utils/commonUnixCommands.js.map +2 -2
- package/dist/utils/compressionMode.js.map +2 -2
- package/dist/utils/config.js +30 -14
- package/dist/utils/config.js.map +2 -2
- package/dist/utils/debugLogger.js.map +2 -2
- package/dist/utils/env.js.map +2 -2
- package/dist/utils/envConfig.js +82 -0
- package/dist/utils/envConfig.js.map +7 -0
- package/dist/utils/errorHandling.js +89 -0
- package/dist/utils/errorHandling.js.map +7 -0
- package/dist/utils/expertChatStorage.js.map +2 -2
- package/dist/utils/fuzzyMatcher.js +13 -7
- package/dist/utils/fuzzyMatcher.js.map +2 -2
- package/dist/utils/hookManager.js +14 -4
- package/dist/utils/hookManager.js.map +2 -2
- package/dist/utils/log.js.map +2 -2
- package/dist/utils/marketplaceManager.js +44 -9
- package/dist/utils/marketplaceManager.js.map +2 -2
- package/dist/utils/messageContextManager.js.map +1 -1
- package/dist/utils/messages.js +6 -3
- package/dist/utils/messages.js.map +2 -2
- package/dist/utils/model.js +3 -1
- package/dist/utils/model.js.map +2 -2
- package/dist/utils/pluginInstaller.js +3 -15
- package/dist/utils/pluginInstaller.js.map +2 -2
- package/dist/utils/pluginLoader.js +41 -13
- package/dist/utils/pluginLoader.js.map +2 -2
- package/dist/utils/pluginRegistry.js.map +2 -2
- package/dist/utils/pluginValidator.js +71 -49
- package/dist/utils/pluginValidator.js.map +2 -2
- package/dist/utils/ptyCompat.js.map +2 -2
- package/dist/utils/roundConverter.js.map +2 -2
- package/dist/utils/secureFile.js +43 -14
- package/dist/utils/secureFile.js.map +2 -2
- package/dist/utils/sessionState.js.map +2 -2
- package/dist/utils/skillLoader.js.map +2 -2
- package/dist/utils/teamConfig.js +7 -4
- package/dist/utils/teamConfig.js.map +2 -2
- package/dist/utils/theme.js.map +2 -2
- package/dist/utils/thinking.js.map +2 -2
- package/dist/utils/unaryLogging.js.map +2 -2
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,2342 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useCallback,
|
|
6
|
+
useReducer,
|
|
7
|
+
Fragment
|
|
8
|
+
} from "react";
|
|
9
|
+
import { Box, Text, useInput } from "ink";
|
|
10
|
+
import InkTextInput from "ink-text-input";
|
|
11
|
+
import {
|
|
12
|
+
getActiveAgents,
|
|
13
|
+
clearAgentCache
|
|
14
|
+
} from "../../utils/agentLoader.js";
|
|
15
|
+
import * as path from "path";
|
|
16
|
+
import * as os from "os";
|
|
17
|
+
import { exec } from "child_process";
|
|
18
|
+
import { promisify } from "util";
|
|
19
|
+
import { getTheme } from "../../utils/theme.js";
|
|
20
|
+
const execAsync = promisify(exec);
|
|
21
|
+
import { getMCPTools } from "../../services/mcpClient.js";
|
|
22
|
+
import { getModelManager } from "../../utils/model.js";
|
|
23
|
+
import { randomUUID } from "crypto";
|
|
24
|
+
import {
|
|
25
|
+
UI_ICONS,
|
|
26
|
+
TOOL_CATEGORIES
|
|
27
|
+
} from "./constants.js";
|
|
28
|
+
import {
|
|
29
|
+
getAgentFilePath,
|
|
30
|
+
saveAgent,
|
|
31
|
+
deleteAgent,
|
|
32
|
+
openInEditor,
|
|
33
|
+
updateAgent
|
|
34
|
+
} from "./utils.js";
|
|
35
|
+
function getDisplayModelName(modelId) {
|
|
36
|
+
if (!modelId) return "Inherit";
|
|
37
|
+
try {
|
|
38
|
+
const profiles = getModelManager().getActiveModelProfiles();
|
|
39
|
+
const profile = profiles.find(
|
|
40
|
+
(p) => p.modelName === modelId || p.name === modelId
|
|
41
|
+
);
|
|
42
|
+
return profile ? profile.name : `Custom (${modelId})`;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn("Failed to get model profiles:", error);
|
|
45
|
+
return modelId ? `Custom (${modelId})` : "Inherit";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function generateAgentWithClaude(prompt) {
|
|
49
|
+
const { queryModel } = await import("../../services/claude.js");
|
|
50
|
+
const systemPrompt = `You are an expert at creating AI agent configurations. Based on the user's description, generate a specialized agent configuration.
|
|
51
|
+
|
|
52
|
+
Return your response as a JSON object with exactly these fields:
|
|
53
|
+
- identifier: A short, kebab-case identifier for the agent (e.g., "code-reviewer", "security-auditor")
|
|
54
|
+
- whenToUse: A clear description of when this agent should be used (50-200 words)
|
|
55
|
+
- systemPrompt: A comprehensive system prompt that defines the agent's role, capabilities, and behavior (200-500 words)
|
|
56
|
+
|
|
57
|
+
Make the agent highly specialized and effective for the described use case.`;
|
|
58
|
+
try {
|
|
59
|
+
const messages = [
|
|
60
|
+
{
|
|
61
|
+
type: "user",
|
|
62
|
+
uuid: randomUUID(),
|
|
63
|
+
message: { role: "user", content: prompt }
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
const response = await queryModel("main", messages, [systemPrompt]);
|
|
67
|
+
let responseText = "";
|
|
68
|
+
if (typeof response.message?.content === "string") {
|
|
69
|
+
responseText = response.message.content;
|
|
70
|
+
} else if (Array.isArray(response.message?.content)) {
|
|
71
|
+
const textContent = response.message.content.find(
|
|
72
|
+
(c) => c.type === "text"
|
|
73
|
+
);
|
|
74
|
+
responseText = textContent?.text || "";
|
|
75
|
+
} else if (response.message?.content?.[0]?.text) {
|
|
76
|
+
responseText = response.message.content[0].text;
|
|
77
|
+
}
|
|
78
|
+
if (!responseText) {
|
|
79
|
+
throw new Error("No text content in Claude response");
|
|
80
|
+
}
|
|
81
|
+
const MAX_JSON_SIZE = 1e5;
|
|
82
|
+
const MAX_FIELD_LENGTH = 1e4;
|
|
83
|
+
if (responseText.length > MAX_JSON_SIZE) {
|
|
84
|
+
throw new Error("Response too large");
|
|
85
|
+
}
|
|
86
|
+
let parsed;
|
|
87
|
+
try {
|
|
88
|
+
parsed = JSON.parse(responseText.trim());
|
|
89
|
+
} catch {
|
|
90
|
+
const startIdx = responseText.indexOf("{");
|
|
91
|
+
const endIdx = responseText.lastIndexOf("}");
|
|
92
|
+
if (startIdx === -1 || endIdx === -1 || startIdx >= endIdx) {
|
|
93
|
+
throw new Error("No valid JSON found in Claude response");
|
|
94
|
+
}
|
|
95
|
+
const jsonStr = responseText.substring(startIdx, endIdx + 1);
|
|
96
|
+
if (jsonStr.length > MAX_JSON_SIZE) {
|
|
97
|
+
throw new Error("JSON content too large");
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(jsonStr);
|
|
101
|
+
} catch (parseError) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Invalid JSON format: ${parseError instanceof Error ? parseError.message : "Unknown error"}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const identifier = String(parsed.identifier || "").slice(0, 100).trim();
|
|
108
|
+
const whenToUse = String(parsed.whenToUse || "").slice(0, MAX_FIELD_LENGTH).trim();
|
|
109
|
+
const agentSystemPrompt = String(parsed.systemPrompt || "").slice(0, MAX_FIELD_LENGTH).trim();
|
|
110
|
+
if (!identifier || !whenToUse || !agentSystemPrompt) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
"Invalid response structure: missing required fields (identifier, whenToUse, systemPrompt)"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const sanitize = (str) => str.replace(/[\x00-\x1F\x7F-\x9F]/g, "");
|
|
116
|
+
const cleanIdentifier = sanitize(identifier);
|
|
117
|
+
if (!/^[a-zA-Z0-9-]+$/.test(cleanIdentifier)) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Invalid identifier format: only letters, numbers, and hyphens allowed"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
identifier: cleanIdentifier,
|
|
124
|
+
whenToUse: sanitize(whenToUse),
|
|
125
|
+
systemPrompt: sanitize(agentSystemPrompt)
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("AI generation failed:", error);
|
|
129
|
+
const fallbackId = prompt.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").slice(0, 30);
|
|
130
|
+
return {
|
|
131
|
+
identifier: fallbackId || "custom-agent",
|
|
132
|
+
whenToUse: `Use this agent when you need assistance with: ${prompt}`,
|
|
133
|
+
systemPrompt: `You are a specialized assistant focused on helping with ${prompt}. Provide expert-level assistance in this domain.`
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function validateAgentType(agentType, existingAgents = []) {
|
|
138
|
+
const errors = [];
|
|
139
|
+
const warnings = [];
|
|
140
|
+
if (!agentType) {
|
|
141
|
+
errors.push("Agent type is required");
|
|
142
|
+
return { isValid: false, errors, warnings };
|
|
143
|
+
}
|
|
144
|
+
if (!/^[a-zA-Z]/.test(agentType)) {
|
|
145
|
+
errors.push("Agent type must start with a letter");
|
|
146
|
+
}
|
|
147
|
+
if (!/^[a-zA-Z0-9-]+$/.test(agentType)) {
|
|
148
|
+
errors.push("Agent type can only contain letters, numbers, and hyphens");
|
|
149
|
+
}
|
|
150
|
+
if (agentType.length < 3) {
|
|
151
|
+
errors.push("Agent type must be at least 3 characters long");
|
|
152
|
+
}
|
|
153
|
+
if (agentType.length > 50) {
|
|
154
|
+
errors.push("Agent type must be less than 50 characters");
|
|
155
|
+
}
|
|
156
|
+
const reserved = ["help", "exit", "quit", "agents", "task"];
|
|
157
|
+
if (reserved.includes(agentType.toLowerCase())) {
|
|
158
|
+
errors.push("This name is reserved");
|
|
159
|
+
}
|
|
160
|
+
const duplicate = existingAgents.find((a) => a.agentType === agentType);
|
|
161
|
+
if (duplicate) {
|
|
162
|
+
errors.push(
|
|
163
|
+
`An agent with this name already exists in ${duplicate.location}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (agentType.includes("--")) {
|
|
167
|
+
warnings.push("Consider avoiding consecutive hyphens");
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
isValid: errors.length === 0,
|
|
171
|
+
errors,
|
|
172
|
+
warnings
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function validateAgentConfig(config, existingAgents = []) {
|
|
176
|
+
const errors = [];
|
|
177
|
+
const warnings = [];
|
|
178
|
+
if (config.agentType) {
|
|
179
|
+
const typeValidation = validateAgentType(config.agentType, existingAgents);
|
|
180
|
+
errors.push(...typeValidation.errors);
|
|
181
|
+
warnings.push(...typeValidation.warnings);
|
|
182
|
+
}
|
|
183
|
+
if (!config.whenToUse) {
|
|
184
|
+
errors.push("Description is required");
|
|
185
|
+
} else if (config.whenToUse.length < 10) {
|
|
186
|
+
warnings.push(
|
|
187
|
+
"Description should be more descriptive (at least 10 characters)"
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (!config.systemPrompt) {
|
|
191
|
+
errors.push("System prompt is required");
|
|
192
|
+
} else if (config.systemPrompt.length < 20) {
|
|
193
|
+
warnings.push(
|
|
194
|
+
"System prompt might be too short for effective agent behavior"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (!config.selectedTools || config.selectedTools.length === 0) {
|
|
198
|
+
warnings.push("No tools selected - agent will have limited capabilities");
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
isValid: errors.length === 0,
|
|
202
|
+
errors,
|
|
203
|
+
warnings
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function Header({ title, subtitle, step, totalSteps, children }) {
|
|
207
|
+
const theme = getTheme();
|
|
208
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.primary }, title), subtitle && /* @__PURE__ */ React.createElement(Text, { color: theme.secondary }, step && totalSteps ? `Step ${step}/${totalSteps}: ` : "", subtitle), children);
|
|
209
|
+
}
|
|
210
|
+
function InstructionBar({
|
|
211
|
+
instructions = "Press \u2191\u2193 to navigate \xB7 Enter to select \xB7 Esc to go back"
|
|
212
|
+
}) {
|
|
213
|
+
const theme = getTheme();
|
|
214
|
+
return /* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, /* @__PURE__ */ React.createElement(Box, { borderStyle: "round", borderColor: theme.secondary, paddingX: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.secondary }, instructions)));
|
|
215
|
+
}
|
|
216
|
+
function SelectList({
|
|
217
|
+
options,
|
|
218
|
+
selectedIndex,
|
|
219
|
+
onChange,
|
|
220
|
+
onCancel,
|
|
221
|
+
numbered = true
|
|
222
|
+
}) {
|
|
223
|
+
const theme = getTheme();
|
|
224
|
+
useInput((input, key) => {
|
|
225
|
+
if (key.escape && onCancel) {
|
|
226
|
+
onCancel();
|
|
227
|
+
} else if (key.return) {
|
|
228
|
+
onChange(options[selectedIndex].value);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, options.map((option, idx) => /* @__PURE__ */ React.createElement(Box, { key: option.value }, /* @__PURE__ */ React.createElement(Text, { color: idx === selectedIndex ? theme.primary : void 0 }, idx === selectedIndex ? `${UI_ICONS.pointer} ` : " ", numbered ? `${idx + 1}. ` : "", option.label))));
|
|
232
|
+
}
|
|
233
|
+
function MultilineTextInput({
|
|
234
|
+
value,
|
|
235
|
+
onChange,
|
|
236
|
+
placeholder = "",
|
|
237
|
+
onSubmit,
|
|
238
|
+
focus = true,
|
|
239
|
+
rows = 5,
|
|
240
|
+
error
|
|
241
|
+
}) {
|
|
242
|
+
const theme = getTheme();
|
|
243
|
+
const [internalValue, setInternalValue] = useState(value);
|
|
244
|
+
const [cursorBlink, setCursorBlink] = useState(true);
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
setInternalValue(value);
|
|
247
|
+
}, [value]);
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
if (!focus) return;
|
|
250
|
+
const timer = setInterval(() => {
|
|
251
|
+
setCursorBlink((prev) => !prev);
|
|
252
|
+
}, 500);
|
|
253
|
+
return () => clearInterval(timer);
|
|
254
|
+
}, [focus]);
|
|
255
|
+
const lines = internalValue.split("\n");
|
|
256
|
+
const lineCount = lines.length;
|
|
257
|
+
const charCount = internalValue.length;
|
|
258
|
+
const isEmpty = !internalValue.trim();
|
|
259
|
+
const hasContent = !isEmpty;
|
|
260
|
+
const formatLines = (text) => {
|
|
261
|
+
if (!text && placeholder) {
|
|
262
|
+
return [placeholder];
|
|
263
|
+
}
|
|
264
|
+
const maxWidth = 70;
|
|
265
|
+
const result = [];
|
|
266
|
+
const textLines = text.split("\n");
|
|
267
|
+
textLines.forEach((line) => {
|
|
268
|
+
if (line.length <= maxWidth) {
|
|
269
|
+
result.push(line);
|
|
270
|
+
} else {
|
|
271
|
+
let remaining = line;
|
|
272
|
+
while (remaining.length > 0) {
|
|
273
|
+
result.push(remaining.slice(0, maxWidth));
|
|
274
|
+
remaining = remaining.slice(maxWidth);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
return result.length > 0 ? result : [""];
|
|
279
|
+
};
|
|
280
|
+
const displayLines = formatLines(internalValue);
|
|
281
|
+
const visibleLines = displayLines.slice(
|
|
282
|
+
Math.max(0, displayLines.length - rows)
|
|
283
|
+
);
|
|
284
|
+
const handleSubmit = () => {
|
|
285
|
+
if (internalValue.trim() && onSubmit) {
|
|
286
|
+
onSubmit();
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
290
|
+
Box,
|
|
291
|
+
{
|
|
292
|
+
borderStyle: "round",
|
|
293
|
+
borderColor: focus ? theme.primary : "gray",
|
|
294
|
+
paddingX: 2,
|
|
295
|
+
paddingY: 1,
|
|
296
|
+
minHeight: rows + 2
|
|
297
|
+
},
|
|
298
|
+
/* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
299
|
+
InkTextInput,
|
|
300
|
+
{
|
|
301
|
+
value: internalValue,
|
|
302
|
+
onChange: (val) => {
|
|
303
|
+
setInternalValue(val);
|
|
304
|
+
onChange(val);
|
|
305
|
+
},
|
|
306
|
+
onSubmit: handleSubmit,
|
|
307
|
+
focus,
|
|
308
|
+
placeholder
|
|
309
|
+
}
|
|
310
|
+
), focus && cursorBlink && hasContent && /* @__PURE__ */ React.createElement(Text, { color: theme.primary }, "_"))
|
|
311
|
+
), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "row", justifyContent: "space-between" }, /* @__PURE__ */ React.createElement(Box, null, hasContent ? /* @__PURE__ */ React.createElement(Text, { color: theme.success }, "\u2713 ", charCount, " chars \u2022 ", lineCount, " line", lineCount !== 1 ? "s" : "") : /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "\u25CB Type to begin...")), /* @__PURE__ */ React.createElement(Box, null, error ? /* @__PURE__ */ React.createElement(Text, { color: theme.error }, "\u26A0 ", error) : /* @__PURE__ */ React.createElement(Text, { dimColor: true }, hasContent ? "Ready" : "Waiting")))), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Press Enter to submit \xB7 Shift+Enter for new line")));
|
|
312
|
+
}
|
|
313
|
+
function LoadingSpinner({ text }) {
|
|
314
|
+
const theme = getTheme();
|
|
315
|
+
const [frame, setFrame] = useState(0);
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
const interval = setInterval(() => {
|
|
318
|
+
setFrame((prev) => (prev + 1) % UI_ICONS.loading.length);
|
|
319
|
+
}, 100);
|
|
320
|
+
return () => clearInterval(interval);
|
|
321
|
+
}, []);
|
|
322
|
+
return /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Text, { color: theme.primary }, UI_ICONS.loading[frame]), text && /* @__PURE__ */ React.createElement(Text, { color: theme.secondary }, " ", text));
|
|
323
|
+
}
|
|
324
|
+
function AgentsUI({ onExit }) {
|
|
325
|
+
const theme = getTheme();
|
|
326
|
+
const [modeState, setModeState] = useState({
|
|
327
|
+
mode: "list-agents",
|
|
328
|
+
location: "all"
|
|
329
|
+
});
|
|
330
|
+
const [agents, setAgents] = useState([]);
|
|
331
|
+
const [changes, setChanges] = useState([]);
|
|
332
|
+
const [refreshKey, setRefreshKey] = useState(0);
|
|
333
|
+
const [loading, setLoading] = useState(true);
|
|
334
|
+
const [tools, setTools] = useState([]);
|
|
335
|
+
const [createState, setCreateState] = useReducer(
|
|
336
|
+
(state, action) => {
|
|
337
|
+
switch (action.type) {
|
|
338
|
+
case "RESET":
|
|
339
|
+
return {
|
|
340
|
+
location: null,
|
|
341
|
+
agentType: "",
|
|
342
|
+
method: null,
|
|
343
|
+
generationPrompt: "",
|
|
344
|
+
whenToUse: "",
|
|
345
|
+
selectedTools: [],
|
|
346
|
+
selectedModel: null,
|
|
347
|
+
selectedColor: null,
|
|
348
|
+
systemPrompt: "",
|
|
349
|
+
isGenerating: false,
|
|
350
|
+
wasGenerated: false,
|
|
351
|
+
isAIGenerated: false,
|
|
352
|
+
error: null,
|
|
353
|
+
warnings: [],
|
|
354
|
+
agentTypeCursor: 0,
|
|
355
|
+
whenToUseCursor: 0,
|
|
356
|
+
promptCursor: 0,
|
|
357
|
+
generationPromptCursor: 0
|
|
358
|
+
};
|
|
359
|
+
case "SET_LOCATION":
|
|
360
|
+
return { ...state, location: action.value };
|
|
361
|
+
case "SET_METHOD":
|
|
362
|
+
return { ...state, method: action.value };
|
|
363
|
+
case "SET_AGENT_TYPE":
|
|
364
|
+
return { ...state, agentType: action.value, error: null };
|
|
365
|
+
case "SET_GENERATION_PROMPT":
|
|
366
|
+
return { ...state, generationPrompt: action.value };
|
|
367
|
+
case "SET_WHEN_TO_USE":
|
|
368
|
+
return { ...state, whenToUse: action.value, error: null };
|
|
369
|
+
case "SET_SELECTED_TOOLS":
|
|
370
|
+
return { ...state, selectedTools: action.value };
|
|
371
|
+
case "SET_SELECTED_MODEL":
|
|
372
|
+
return { ...state, selectedModel: action.value };
|
|
373
|
+
case "SET_SELECTED_COLOR":
|
|
374
|
+
return { ...state, selectedColor: action.value };
|
|
375
|
+
case "SET_SYSTEM_PROMPT":
|
|
376
|
+
return { ...state, systemPrompt: action.value };
|
|
377
|
+
case "SET_IS_GENERATING":
|
|
378
|
+
return { ...state, isGenerating: action.value };
|
|
379
|
+
case "SET_WAS_GENERATED":
|
|
380
|
+
return { ...state, wasGenerated: action.value };
|
|
381
|
+
case "SET_IS_AI_GENERATED":
|
|
382
|
+
return { ...state, isAIGenerated: action.value };
|
|
383
|
+
case "SET_ERROR":
|
|
384
|
+
return { ...state, error: action.value };
|
|
385
|
+
case "SET_WARNINGS":
|
|
386
|
+
return { ...state, warnings: action.value };
|
|
387
|
+
case "SET_CURSOR":
|
|
388
|
+
return { ...state, [action.field]: action.value };
|
|
389
|
+
default:
|
|
390
|
+
return state;
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
location: null,
|
|
395
|
+
agentType: "",
|
|
396
|
+
method: null,
|
|
397
|
+
generationPrompt: "",
|
|
398
|
+
whenToUse: "",
|
|
399
|
+
selectedTools: [],
|
|
400
|
+
selectedModel: null,
|
|
401
|
+
selectedColor: null,
|
|
402
|
+
systemPrompt: "",
|
|
403
|
+
isGenerating: false,
|
|
404
|
+
wasGenerated: false,
|
|
405
|
+
isAIGenerated: false,
|
|
406
|
+
error: null,
|
|
407
|
+
warnings: [],
|
|
408
|
+
agentTypeCursor: 0,
|
|
409
|
+
whenToUseCursor: 0,
|
|
410
|
+
promptCursor: 0,
|
|
411
|
+
generationPromptCursor: 0
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
const loadAgents = useCallback(async () => {
|
|
415
|
+
setLoading(true);
|
|
416
|
+
clearAgentCache();
|
|
417
|
+
const abortController = new AbortController();
|
|
418
|
+
const loadingId = Date.now();
|
|
419
|
+
try {
|
|
420
|
+
const result = await getActiveAgents();
|
|
421
|
+
if (abortController.signal.aborted) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
setAgents(result);
|
|
425
|
+
if (modeState.selectedAgent) {
|
|
426
|
+
const freshSelectedAgent = result.find(
|
|
427
|
+
(a) => a.agentType === modeState.selectedAgent.agentType
|
|
428
|
+
);
|
|
429
|
+
if (freshSelectedAgent) {
|
|
430
|
+
setModeState((prev) => ({ ...prev, selectedAgent: freshSelectedAgent }));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const availableTools = [];
|
|
434
|
+
let coreTools = [
|
|
435
|
+
{ name: "Read", description: "Read files from filesystem" },
|
|
436
|
+
{ name: "Write", description: "Write files to filesystem" },
|
|
437
|
+
{ name: "Edit", description: "Edit existing files" },
|
|
438
|
+
{ name: "MultiEdit", description: "Make multiple edits to files" },
|
|
439
|
+
{ name: "NotebookEdit", description: "Edit Jupyter notebooks" },
|
|
440
|
+
{ name: "Bash", description: "Execute bash commands" },
|
|
441
|
+
{ name: "Glob", description: "Find files matching patterns" },
|
|
442
|
+
{ name: "Grep", description: "Search file contents" },
|
|
443
|
+
{ name: "LS", description: "List directory contents" },
|
|
444
|
+
{ name: "WebFetch", description: "Fetch web content" },
|
|
445
|
+
{ name: "WebSearch", description: "Search the web" },
|
|
446
|
+
{ name: "TodoWrite", description: "Manage task lists" }
|
|
447
|
+
];
|
|
448
|
+
coreTools = coreTools.filter(
|
|
449
|
+
(t) => t.name !== "Task" && t.name !== "ExitPlanMode"
|
|
450
|
+
);
|
|
451
|
+
availableTools.push(...coreTools);
|
|
452
|
+
try {
|
|
453
|
+
const mcpTools = await getMCPTools();
|
|
454
|
+
if (Array.isArray(mcpTools) && mcpTools.length > 0) {
|
|
455
|
+
availableTools.push(...mcpTools);
|
|
456
|
+
}
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.warn("Failed to load MCP tools:", error);
|
|
459
|
+
}
|
|
460
|
+
if (!abortController.signal.aborted) {
|
|
461
|
+
setTools(availableTools);
|
|
462
|
+
}
|
|
463
|
+
} catch (error) {
|
|
464
|
+
if (!abortController.signal.aborted) {
|
|
465
|
+
console.error("Failed to load agents:", error);
|
|
466
|
+
}
|
|
467
|
+
} finally {
|
|
468
|
+
if (!abortController.signal.aborted) {
|
|
469
|
+
setLoading(false);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return () => abortController.abort();
|
|
473
|
+
}, []);
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
let cleanup;
|
|
476
|
+
const load = async () => {
|
|
477
|
+
cleanup = await loadAgents();
|
|
478
|
+
};
|
|
479
|
+
load();
|
|
480
|
+
return () => {
|
|
481
|
+
if (cleanup) {
|
|
482
|
+
cleanup();
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
}, [refreshKey, loadAgents]);
|
|
486
|
+
useInput((input, key) => {
|
|
487
|
+
if (!key.escape) return;
|
|
488
|
+
const changesSummary = changes.length > 0 ? `Agent changes:
|
|
489
|
+
${changes.join("\n")}` : void 0;
|
|
490
|
+
const current = modeState.mode;
|
|
491
|
+
if (current === "list-agents") {
|
|
492
|
+
onExit(changesSummary);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
switch (current) {
|
|
496
|
+
case "create-location":
|
|
497
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
498
|
+
break;
|
|
499
|
+
case "create-method":
|
|
500
|
+
setModeState({ mode: "create-location", location: modeState.location });
|
|
501
|
+
break;
|
|
502
|
+
case "create-generate":
|
|
503
|
+
setModeState({ mode: "create-location", location: modeState.location });
|
|
504
|
+
break;
|
|
505
|
+
case "create-type":
|
|
506
|
+
setModeState({ mode: "create-generate", location: modeState.location });
|
|
507
|
+
break;
|
|
508
|
+
case "create-prompt":
|
|
509
|
+
setModeState({ mode: "create-type", location: modeState.location });
|
|
510
|
+
break;
|
|
511
|
+
case "create-description":
|
|
512
|
+
setModeState({ mode: "create-prompt", location: modeState.location });
|
|
513
|
+
break;
|
|
514
|
+
case "create-tools":
|
|
515
|
+
setModeState({
|
|
516
|
+
mode: "create-description",
|
|
517
|
+
location: modeState.location
|
|
518
|
+
});
|
|
519
|
+
break;
|
|
520
|
+
case "create-model":
|
|
521
|
+
setModeState({ mode: "create-tools", location: modeState.location });
|
|
522
|
+
break;
|
|
523
|
+
case "create-color":
|
|
524
|
+
setModeState({ mode: "create-model", location: modeState.location });
|
|
525
|
+
break;
|
|
526
|
+
case "create-confirm":
|
|
527
|
+
setModeState({ mode: "create-color", location: modeState.location });
|
|
528
|
+
break;
|
|
529
|
+
case "agent-menu":
|
|
530
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
531
|
+
break;
|
|
532
|
+
case "view-agent":
|
|
533
|
+
setModeState({
|
|
534
|
+
mode: "agent-menu",
|
|
535
|
+
selectedAgent: modeState.selectedAgent
|
|
536
|
+
});
|
|
537
|
+
break;
|
|
538
|
+
case "edit-agent":
|
|
539
|
+
setModeState({
|
|
540
|
+
mode: "agent-menu",
|
|
541
|
+
selectedAgent: modeState.selectedAgent
|
|
542
|
+
});
|
|
543
|
+
break;
|
|
544
|
+
case "edit-tools":
|
|
545
|
+
case "edit-model":
|
|
546
|
+
case "edit-color":
|
|
547
|
+
setModeState({
|
|
548
|
+
mode: "edit-agent",
|
|
549
|
+
selectedAgent: modeState.selectedAgent
|
|
550
|
+
});
|
|
551
|
+
break;
|
|
552
|
+
case "delete-confirm":
|
|
553
|
+
setModeState({
|
|
554
|
+
mode: "agent-menu",
|
|
555
|
+
selectedAgent: modeState.selectedAgent
|
|
556
|
+
});
|
|
557
|
+
break;
|
|
558
|
+
default:
|
|
559
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
const handleAgentSelect = useCallback(
|
|
564
|
+
(agent) => {
|
|
565
|
+
setModeState({
|
|
566
|
+
mode: "agent-menu",
|
|
567
|
+
location: modeState.location,
|
|
568
|
+
selectedAgent: agent
|
|
569
|
+
});
|
|
570
|
+
},
|
|
571
|
+
[modeState]
|
|
572
|
+
);
|
|
573
|
+
const handleCreateNew = useCallback(() => {
|
|
574
|
+
console.log("=== STARTING AGENT CREATION FLOW ===");
|
|
575
|
+
console.log("Current mode state:", modeState);
|
|
576
|
+
setCreateState({ type: "RESET" });
|
|
577
|
+
console.log("Reset create state");
|
|
578
|
+
setModeState({ mode: "create-location" });
|
|
579
|
+
console.log("Set mode to create-location");
|
|
580
|
+
console.log("=== CREATE NEW HANDLER COMPLETED ===");
|
|
581
|
+
}, [modeState]);
|
|
582
|
+
const handleAgentCreated = useCallback((message) => {
|
|
583
|
+
setChanges((prev) => [...prev, message]);
|
|
584
|
+
setRefreshKey((prev) => prev + 1);
|
|
585
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
586
|
+
}, []);
|
|
587
|
+
const handleAgentDeleted = useCallback((message) => {
|
|
588
|
+
setChanges((prev) => [...prev, message]);
|
|
589
|
+
setRefreshKey((prev) => prev + 1);
|
|
590
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
591
|
+
}, []);
|
|
592
|
+
if (loading) {
|
|
593
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "Agents" }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Loading agents..." }))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
594
|
+
}
|
|
595
|
+
switch (modeState.mode) {
|
|
596
|
+
case "list-agents":
|
|
597
|
+
return /* @__PURE__ */ React.createElement(
|
|
598
|
+
AgentListView,
|
|
599
|
+
{
|
|
600
|
+
location: modeState.location || "all",
|
|
601
|
+
agents,
|
|
602
|
+
allAgents: agents,
|
|
603
|
+
onBack: () => onExit(),
|
|
604
|
+
onSelect: handleAgentSelect,
|
|
605
|
+
onCreateNew: handleCreateNew,
|
|
606
|
+
changes
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
case "create-location":
|
|
610
|
+
return /* @__PURE__ */ React.createElement(
|
|
611
|
+
LocationSelect,
|
|
612
|
+
{
|
|
613
|
+
createState,
|
|
614
|
+
setCreateState,
|
|
615
|
+
setModeState
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
case "create-method":
|
|
619
|
+
return /* @__PURE__ */ React.createElement(
|
|
620
|
+
MethodSelect,
|
|
621
|
+
{
|
|
622
|
+
createState,
|
|
623
|
+
setCreateState,
|
|
624
|
+
setModeState
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
case "create-generate":
|
|
628
|
+
return /* @__PURE__ */ React.createElement(
|
|
629
|
+
GenerateStep,
|
|
630
|
+
{
|
|
631
|
+
createState,
|
|
632
|
+
setCreateState,
|
|
633
|
+
setModeState,
|
|
634
|
+
existingAgents: agents
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
case "create-type":
|
|
638
|
+
return /* @__PURE__ */ React.createElement(
|
|
639
|
+
TypeStep,
|
|
640
|
+
{
|
|
641
|
+
createState,
|
|
642
|
+
setCreateState,
|
|
643
|
+
setModeState,
|
|
644
|
+
existingAgents: agents
|
|
645
|
+
}
|
|
646
|
+
);
|
|
647
|
+
case "create-description":
|
|
648
|
+
return /* @__PURE__ */ React.createElement(
|
|
649
|
+
DescriptionStep,
|
|
650
|
+
{
|
|
651
|
+
createState,
|
|
652
|
+
setCreateState,
|
|
653
|
+
setModeState
|
|
654
|
+
}
|
|
655
|
+
);
|
|
656
|
+
case "create-tools":
|
|
657
|
+
return /* @__PURE__ */ React.createElement(
|
|
658
|
+
ToolsStep,
|
|
659
|
+
{
|
|
660
|
+
createState,
|
|
661
|
+
setCreateState,
|
|
662
|
+
setModeState,
|
|
663
|
+
tools
|
|
664
|
+
}
|
|
665
|
+
);
|
|
666
|
+
case "create-model":
|
|
667
|
+
return /* @__PURE__ */ React.createElement(
|
|
668
|
+
ModelStep,
|
|
669
|
+
{
|
|
670
|
+
createState,
|
|
671
|
+
setCreateState,
|
|
672
|
+
setModeState
|
|
673
|
+
}
|
|
674
|
+
);
|
|
675
|
+
case "create-color":
|
|
676
|
+
return /* @__PURE__ */ React.createElement(
|
|
677
|
+
ColorStep,
|
|
678
|
+
{
|
|
679
|
+
createState,
|
|
680
|
+
setCreateState,
|
|
681
|
+
setModeState
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
case "create-prompt":
|
|
685
|
+
return /* @__PURE__ */ React.createElement(
|
|
686
|
+
PromptStep,
|
|
687
|
+
{
|
|
688
|
+
createState,
|
|
689
|
+
setCreateState,
|
|
690
|
+
setModeState
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
case "create-confirm":
|
|
694
|
+
return /* @__PURE__ */ React.createElement(
|
|
695
|
+
ConfirmStep,
|
|
696
|
+
{
|
|
697
|
+
createState,
|
|
698
|
+
setCreateState,
|
|
699
|
+
setModeState,
|
|
700
|
+
tools,
|
|
701
|
+
onAgentCreated: handleAgentCreated
|
|
702
|
+
}
|
|
703
|
+
);
|
|
704
|
+
case "agent-menu":
|
|
705
|
+
return /* @__PURE__ */ React.createElement(
|
|
706
|
+
AgentMenu,
|
|
707
|
+
{
|
|
708
|
+
agent: modeState.selectedAgent,
|
|
709
|
+
setModeState
|
|
710
|
+
}
|
|
711
|
+
);
|
|
712
|
+
case "view-agent":
|
|
713
|
+
return /* @__PURE__ */ React.createElement(
|
|
714
|
+
ViewAgent,
|
|
715
|
+
{
|
|
716
|
+
agent: modeState.selectedAgent,
|
|
717
|
+
tools,
|
|
718
|
+
setModeState
|
|
719
|
+
}
|
|
720
|
+
);
|
|
721
|
+
case "edit-agent":
|
|
722
|
+
return /* @__PURE__ */ React.createElement(
|
|
723
|
+
EditMenu,
|
|
724
|
+
{
|
|
725
|
+
agent: modeState.selectedAgent,
|
|
726
|
+
setModeState
|
|
727
|
+
}
|
|
728
|
+
);
|
|
729
|
+
case "edit-tools":
|
|
730
|
+
return /* @__PURE__ */ React.createElement(
|
|
731
|
+
EditToolsStep,
|
|
732
|
+
{
|
|
733
|
+
agent: modeState.selectedAgent,
|
|
734
|
+
tools,
|
|
735
|
+
setModeState,
|
|
736
|
+
onAgentUpdated: (message, updated) => {
|
|
737
|
+
setChanges((prev) => [...prev, message]);
|
|
738
|
+
setRefreshKey((prev) => prev + 1);
|
|
739
|
+
setModeState({ mode: "agent-menu", selectedAgent: updated });
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
);
|
|
743
|
+
case "edit-model":
|
|
744
|
+
return /* @__PURE__ */ React.createElement(
|
|
745
|
+
EditModelStep,
|
|
746
|
+
{
|
|
747
|
+
agent: modeState.selectedAgent,
|
|
748
|
+
setModeState,
|
|
749
|
+
onAgentUpdated: (message, updated) => {
|
|
750
|
+
setChanges((prev) => [...prev, message]);
|
|
751
|
+
setRefreshKey((prev) => prev + 1);
|
|
752
|
+
setModeState({ mode: "agent-menu", selectedAgent: updated });
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
);
|
|
756
|
+
case "edit-color":
|
|
757
|
+
return /* @__PURE__ */ React.createElement(
|
|
758
|
+
EditColorStep,
|
|
759
|
+
{
|
|
760
|
+
agent: modeState.selectedAgent,
|
|
761
|
+
setModeState,
|
|
762
|
+
onAgentUpdated: (message, updated) => {
|
|
763
|
+
setChanges((prev) => [...prev, message]);
|
|
764
|
+
setRefreshKey((prev) => prev + 1);
|
|
765
|
+
setModeState({ mode: "agent-menu", selectedAgent: updated });
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
);
|
|
769
|
+
case "delete-confirm":
|
|
770
|
+
return /* @__PURE__ */ React.createElement(
|
|
771
|
+
DeleteConfirm,
|
|
772
|
+
{
|
|
773
|
+
agent: modeState.selectedAgent,
|
|
774
|
+
setModeState,
|
|
775
|
+
onAgentDeleted: handleAgentDeleted
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
default:
|
|
779
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "Agents" }, /* @__PURE__ */ React.createElement(Text, null, "Mode: ", modeState.mode, " (Not implemented yet)"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, "Press Esc to go back"))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "Esc to go back" }));
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function AgentListView({
|
|
783
|
+
location,
|
|
784
|
+
agents,
|
|
785
|
+
allAgents,
|
|
786
|
+
onBack,
|
|
787
|
+
onSelect,
|
|
788
|
+
onCreateNew,
|
|
789
|
+
changes
|
|
790
|
+
}) {
|
|
791
|
+
const theme = getTheme();
|
|
792
|
+
const allAgentsList = allAgents || agents;
|
|
793
|
+
const customAgents = allAgentsList.filter((a) => a.location !== "built-in");
|
|
794
|
+
const builtInAgents = allAgentsList.filter((a) => a.location === "built-in");
|
|
795
|
+
const [selectedAgent, setSelectedAgent] = useState(null);
|
|
796
|
+
const [onCreateOption, setOnCreateOption] = useState(true);
|
|
797
|
+
const [currentLocation, setCurrentLocation] = useState(location);
|
|
798
|
+
const [inLocationTabs, setInLocationTabs] = useState(false);
|
|
799
|
+
const [selectedLocationTab, setSelectedLocationTab] = useState(0);
|
|
800
|
+
const locationTabs = [
|
|
801
|
+
{ label: "All", value: "all" },
|
|
802
|
+
{ label: "Personal", value: "user" },
|
|
803
|
+
{ label: "Project", value: "project" }
|
|
804
|
+
];
|
|
805
|
+
const activeMap = useMemo(() => {
|
|
806
|
+
const map = /* @__PURE__ */ new Map();
|
|
807
|
+
agents.forEach((a) => map.set(a.agentType, a));
|
|
808
|
+
return map;
|
|
809
|
+
}, [agents]);
|
|
810
|
+
const checkOverride = (agent) => {
|
|
811
|
+
const active = activeMap.get(agent.agentType);
|
|
812
|
+
const isOverridden = !!(active && active.location !== agent.location);
|
|
813
|
+
return {
|
|
814
|
+
isOverridden,
|
|
815
|
+
overriddenBy: isOverridden ? active.location : null
|
|
816
|
+
};
|
|
817
|
+
};
|
|
818
|
+
const renderCreateOption = () => /* @__PURE__ */ React.createElement(Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(Text, { color: onCreateOption ? theme.primary : void 0 }, onCreateOption ? `${UI_ICONS.pointer} ` : " "), /* @__PURE__ */ React.createElement(Text, { bold: true, color: onCreateOption ? theme.primary : void 0 }, "\u2728 Create new agent"));
|
|
819
|
+
const renderAgent = (agent, isBuiltIn = false) => {
|
|
820
|
+
const isSelected = !isBuiltIn && !onCreateOption && selectedAgent?.agentType === agent.agentType && selectedAgent?.location === agent.location;
|
|
821
|
+
const { isOverridden, overriddenBy } = checkOverride(agent);
|
|
822
|
+
const dimmed = isBuiltIn || isOverridden;
|
|
823
|
+
const color = !isBuiltIn && isSelected ? theme.primary : void 0;
|
|
824
|
+
const agentModel = agent.model || null;
|
|
825
|
+
const modelDisplay = getDisplayModelName(agentModel);
|
|
826
|
+
return /* @__PURE__ */ React.createElement(
|
|
827
|
+
Box,
|
|
828
|
+
{
|
|
829
|
+
key: `${agent.agentType}-${agent.location}`,
|
|
830
|
+
flexDirection: "row",
|
|
831
|
+
alignItems: "center"
|
|
832
|
+
},
|
|
833
|
+
/* @__PURE__ */ React.createElement(Box, { flexDirection: "row", alignItems: "center", minWidth: 3 }, /* @__PURE__ */ React.createElement(Text, { dimColor: dimmed && !isSelected, color }, isBuiltIn ? "" : isSelected ? `${UI_ICONS.pointer} ` : " ")),
|
|
834
|
+
/* @__PURE__ */ React.createElement(Box, { flexDirection: "row", alignItems: "center", flexGrow: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: dimmed && !isSelected, color }, agent.agentType), /* @__PURE__ */ React.createElement(Text, { dimColor: true, color: dimmed ? void 0 : "gray" }, " \xB7 ", modelDisplay)),
|
|
835
|
+
overriddenBy && /* @__PURE__ */ React.createElement(Box, { marginLeft: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: !isSelected, color: isSelected ? "yellow" : "gray" }, UI_ICONS.warning, " overridden by ", overriddenBy))
|
|
836
|
+
);
|
|
837
|
+
};
|
|
838
|
+
const displayAgents = useMemo(() => {
|
|
839
|
+
if (currentLocation === "all") {
|
|
840
|
+
return [
|
|
841
|
+
...customAgents.filter((a) => a.location === "user"),
|
|
842
|
+
...customAgents.filter((a) => a.location === "project")
|
|
843
|
+
];
|
|
844
|
+
} else if (currentLocation === "user" || currentLocation === "project") {
|
|
845
|
+
return customAgents.filter((a) => a.location === currentLocation);
|
|
846
|
+
}
|
|
847
|
+
return customAgents;
|
|
848
|
+
}, [customAgents, currentLocation]);
|
|
849
|
+
useEffect(() => {
|
|
850
|
+
const tabIndex = locationTabs.findIndex(
|
|
851
|
+
(tab) => tab.value === currentLocation
|
|
852
|
+
);
|
|
853
|
+
if (tabIndex !== -1) {
|
|
854
|
+
setSelectedLocationTab(tabIndex);
|
|
855
|
+
}
|
|
856
|
+
}, [currentLocation, locationTabs]);
|
|
857
|
+
useEffect(() => {
|
|
858
|
+
if (displayAgents.length > 0 && !selectedAgent && !onCreateOption) {
|
|
859
|
+
setOnCreateOption(true);
|
|
860
|
+
}
|
|
861
|
+
}, [displayAgents.length, selectedAgent, onCreateOption]);
|
|
862
|
+
useInput((input, key) => {
|
|
863
|
+
if (key.escape) {
|
|
864
|
+
if (inLocationTabs) {
|
|
865
|
+
setInLocationTabs(false);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
onBack();
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if (key.return) {
|
|
872
|
+
if (inLocationTabs) {
|
|
873
|
+
setCurrentLocation(locationTabs[selectedLocationTab].value);
|
|
874
|
+
setInLocationTabs(false);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (onCreateOption && onCreateNew) {
|
|
878
|
+
onCreateNew();
|
|
879
|
+
} else if (selectedAgent) {
|
|
880
|
+
onSelect(selectedAgent);
|
|
881
|
+
}
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
if (key.tab) {
|
|
885
|
+
setInLocationTabs(!inLocationTabs);
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
if (inLocationTabs) {
|
|
889
|
+
if (key.leftArrow) {
|
|
890
|
+
setSelectedLocationTab(
|
|
891
|
+
(prev) => prev > 0 ? prev - 1 : locationTabs.length - 1
|
|
892
|
+
);
|
|
893
|
+
} else if (key.rightArrow) {
|
|
894
|
+
setSelectedLocationTab(
|
|
895
|
+
(prev) => prev < locationTabs.length - 1 ? prev + 1 : 0
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
if (key.upArrow || key.downArrow) {
|
|
901
|
+
const allNavigableItems = [];
|
|
902
|
+
if (onCreateNew) {
|
|
903
|
+
allNavigableItems.push({ type: "create", agent: null });
|
|
904
|
+
}
|
|
905
|
+
displayAgents.forEach((agent) => {
|
|
906
|
+
const { isOverridden } = checkOverride(agent);
|
|
907
|
+
if (!isOverridden) {
|
|
908
|
+
allNavigableItems.push({ type: "agent", agent });
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
if (allNavigableItems.length === 0) return;
|
|
912
|
+
if (key.upArrow) {
|
|
913
|
+
if (onCreateOption) {
|
|
914
|
+
const lastAgent = allNavigableItems[allNavigableItems.length - 1];
|
|
915
|
+
if (lastAgent.type === "agent") {
|
|
916
|
+
setSelectedAgent(lastAgent.agent);
|
|
917
|
+
setOnCreateOption(false);
|
|
918
|
+
}
|
|
919
|
+
} else if (selectedAgent) {
|
|
920
|
+
const currentIndex = allNavigableItems.findIndex(
|
|
921
|
+
(item) => item.type === "agent" && item.agent?.agentType === selectedAgent.agentType && item.agent?.location === selectedAgent.location
|
|
922
|
+
);
|
|
923
|
+
if (currentIndex > 0) {
|
|
924
|
+
const prevItem = allNavigableItems[currentIndex - 1];
|
|
925
|
+
if (prevItem.type === "create") {
|
|
926
|
+
setOnCreateOption(true);
|
|
927
|
+
setSelectedAgent(null);
|
|
928
|
+
} else {
|
|
929
|
+
setSelectedAgent(prevItem.agent);
|
|
930
|
+
}
|
|
931
|
+
} else {
|
|
932
|
+
if (onCreateNew) {
|
|
933
|
+
setOnCreateOption(true);
|
|
934
|
+
setSelectedAgent(null);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
} else if (key.downArrow) {
|
|
939
|
+
if (onCreateOption) {
|
|
940
|
+
const firstAgent = allNavigableItems.find(
|
|
941
|
+
(item) => item.type === "agent"
|
|
942
|
+
);
|
|
943
|
+
if (firstAgent) {
|
|
944
|
+
setSelectedAgent(firstAgent.agent);
|
|
945
|
+
setOnCreateOption(false);
|
|
946
|
+
}
|
|
947
|
+
} else if (selectedAgent) {
|
|
948
|
+
const currentIndex = allNavigableItems.findIndex(
|
|
949
|
+
(item) => item.type === "agent" && item.agent?.agentType === selectedAgent.agentType && item.agent?.location === selectedAgent.location
|
|
950
|
+
);
|
|
951
|
+
if (currentIndex < allNavigableItems.length - 1) {
|
|
952
|
+
const nextItem = allNavigableItems[currentIndex + 1];
|
|
953
|
+
if (nextItem.type === "agent") {
|
|
954
|
+
setSelectedAgent(nextItem.agent);
|
|
955
|
+
}
|
|
956
|
+
} else {
|
|
957
|
+
if (onCreateNew) {
|
|
958
|
+
setOnCreateOption(true);
|
|
959
|
+
setSelectedAgent(null);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
const EmptyStateInput = () => {
|
|
967
|
+
useInput((input, key) => {
|
|
968
|
+
if (key.escape) {
|
|
969
|
+
onBack();
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (key.return && onCreateNew) {
|
|
973
|
+
onCreateNew();
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
return null;
|
|
978
|
+
};
|
|
979
|
+
if (!agents.length || currentLocation !== "built-in" && !customAgents.length) {
|
|
980
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(EmptyStateInput, null), /* @__PURE__ */ React.createElement(Header, { title: "\u{1F916} Agents", subtitle: "" }, onCreateNew && /* @__PURE__ */ React.createElement(Box, { marginY: 1 }, renderCreateOption()), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.primary }, "\u{1F4AD} What are agents?")), /* @__PURE__ */ React.createElement(Text, null, "Specialized AI assistants that Minto can delegate to for specific tasks, compatible with Claude Code `.claude` agent packs."), /* @__PURE__ */ React.createElement(Text, null, "Each agent has its own context, prompt, and tools."), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.primary }, "\u{1F4A1} Popular agent ideas:")), /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, "\u2022 \u{1F50D} Code Reviewer - Reviews PRs for best practices"), /* @__PURE__ */ React.createElement(Text, null, "\u2022 \u{1F512} Security Auditor - Finds vulnerabilities"), /* @__PURE__ */ React.createElement(Text, null, "\u2022 \u26A1 Performance Optimizer - Improves code speed"), /* @__PURE__ */ React.createElement(Text, null, "\u2022 \u{1F9D1}\u200D\u{1F4BC} Tech Lead - Makes architecture decisions"), /* @__PURE__ */ React.createElement(Text, null, "\u2022 \u{1F3A8} UX Expert - Improves user experience"))), currentLocation !== "built-in" && builtInAgents.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, UI_ICONS.separator.repeat(40))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.secondary }, "Built-in (always available):"), builtInAgents.map((a) => renderAgent(a, true))))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "Press Enter to create new agent \xB7 Esc to go back" }));
|
|
981
|
+
}
|
|
982
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u{1F916} Agents", subtitle: "" }, changes.length > 0 && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, changes[changes.length - 1])), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row", gap: 2 }, locationTabs.map((tab, idx) => {
|
|
983
|
+
const isActive = currentLocation === tab.value;
|
|
984
|
+
const isSelected = inLocationTabs && idx === selectedLocationTab;
|
|
985
|
+
return /* @__PURE__ */ React.createElement(Box, { key: tab.value, flexDirection: "row" }, /* @__PURE__ */ React.createElement(
|
|
986
|
+
Text,
|
|
987
|
+
{
|
|
988
|
+
color: isSelected || isActive ? theme.primary : void 0,
|
|
989
|
+
bold: isActive,
|
|
990
|
+
dimColor: !isActive && !isSelected
|
|
991
|
+
},
|
|
992
|
+
isSelected ? "\u25B6 " : isActive ? "\u25C9 " : "\u25CB ",
|
|
993
|
+
tab.label
|
|
994
|
+
), idx < locationTabs.length - 1 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " | "));
|
|
995
|
+
})), /* @__PURE__ */ React.createElement(Box, { marginTop: 0 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, currentLocation === "all" ? "Showing all agents" : currentLocation === "user" ? "Personal agents (~/.claude/agents)" : "Project agents (.claude/agents)"))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, onCreateNew && /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, renderCreateOption()), currentLocation === "all" ? /* @__PURE__ */ React.createElement(React.Fragment, null, customAgents.filter((a) => a.location === "user").length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.secondary }, "Personal:"), customAgents.filter((a) => a.location === "user").map((a) => renderAgent(a))), customAgents.filter((a) => a.location === "project").length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
996
|
+
Box,
|
|
997
|
+
{
|
|
998
|
+
marginTop: customAgents.filter((a) => a.location === "user").length > 0 ? 1 : 0
|
|
999
|
+
},
|
|
1000
|
+
/* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.secondary }, "Project:")
|
|
1001
|
+
), customAgents.filter((a) => a.location === "project").map((a) => renderAgent(a))), builtInAgents.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { marginTop: customAgents.length > 0 ? 1 : 0 }, /* @__PURE__ */ React.createElement(Text, null, UI_ICONS.separator.repeat(40))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.secondary }, "Built-in:"), builtInAgents.map((a) => renderAgent(a, true))))) : /* @__PURE__ */ React.createElement(React.Fragment, null, displayAgents.map((a) => renderAgent(a)), currentLocation !== "built-in" && builtInAgents.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, UI_ICONS.separator.repeat(40))), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.secondary }, "Built-in:"), builtInAgents.map((a) => renderAgent(a, true))))))), /* @__PURE__ */ React.createElement(
|
|
1002
|
+
InstructionBar,
|
|
1003
|
+
{
|
|
1004
|
+
instructions: inLocationTabs ? "\u2190\u2192 Switch tabs \u2022 Enter Select \u2022 Tab Exit tabs" : "\u2191\u2193 Navigate \u2022 Tab Location \u2022 Enter Select"
|
|
1005
|
+
}
|
|
1006
|
+
));
|
|
1007
|
+
}
|
|
1008
|
+
function GenerateStep({
|
|
1009
|
+
createState,
|
|
1010
|
+
setCreateState,
|
|
1011
|
+
setModeState,
|
|
1012
|
+
existingAgents
|
|
1013
|
+
}) {
|
|
1014
|
+
const handleSubmit = async () => {
|
|
1015
|
+
if (createState.generationPrompt.trim()) {
|
|
1016
|
+
setCreateState({ type: "SET_IS_GENERATING", value: true });
|
|
1017
|
+
setCreateState({ type: "SET_ERROR", value: null });
|
|
1018
|
+
try {
|
|
1019
|
+
const generated = await generateAgentWithClaude(
|
|
1020
|
+
createState.generationPrompt
|
|
1021
|
+
);
|
|
1022
|
+
const validation = validateAgentType(
|
|
1023
|
+
generated.identifier,
|
|
1024
|
+
existingAgents
|
|
1025
|
+
);
|
|
1026
|
+
let finalIdentifier = generated.identifier;
|
|
1027
|
+
if (!validation.isValid) {
|
|
1028
|
+
let counter = 1;
|
|
1029
|
+
while (true) {
|
|
1030
|
+
const testId = `${generated.identifier}-${counter}`;
|
|
1031
|
+
const testValidation = validateAgentType(testId, existingAgents);
|
|
1032
|
+
if (testValidation.isValid) {
|
|
1033
|
+
finalIdentifier = testId;
|
|
1034
|
+
break;
|
|
1035
|
+
}
|
|
1036
|
+
counter++;
|
|
1037
|
+
if (counter > 10) {
|
|
1038
|
+
finalIdentifier = `custom-agent-${Date.now()}`;
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
setCreateState({ type: "SET_AGENT_TYPE", value: finalIdentifier });
|
|
1044
|
+
setCreateState({ type: "SET_WHEN_TO_USE", value: generated.whenToUse });
|
|
1045
|
+
setCreateState({
|
|
1046
|
+
type: "SET_SYSTEM_PROMPT",
|
|
1047
|
+
value: generated.systemPrompt
|
|
1048
|
+
});
|
|
1049
|
+
setCreateState({ type: "SET_WAS_GENERATED", value: true });
|
|
1050
|
+
setCreateState({ type: "SET_IS_GENERATING", value: false });
|
|
1051
|
+
setModeState({ mode: "create-tools", location: createState.location });
|
|
1052
|
+
} catch (error) {
|
|
1053
|
+
console.error("Generation failed:", error);
|
|
1054
|
+
setCreateState({
|
|
1055
|
+
type: "SET_ERROR",
|
|
1056
|
+
value: "Failed to generate agent. Please try again or use manual configuration."
|
|
1057
|
+
});
|
|
1058
|
+
setCreateState({ type: "SET_IS_GENERATING", value: false });
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1063
|
+
Header,
|
|
1064
|
+
{
|
|
1065
|
+
title: "\u2728 New Agent",
|
|
1066
|
+
subtitle: "What should it do?",
|
|
1067
|
+
step: 2,
|
|
1068
|
+
totalSteps: 8
|
|
1069
|
+
},
|
|
1070
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, createState.isGenerating ? /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, createState.generationPrompt), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Generating agent configuration..." }))) : /* @__PURE__ */ React.createElement(
|
|
1071
|
+
MultilineTextInput,
|
|
1072
|
+
{
|
|
1073
|
+
value: createState.generationPrompt,
|
|
1074
|
+
onChange: (value) => setCreateState({ type: "SET_GENERATION_PROMPT", value }),
|
|
1075
|
+
placeholder: "An expert that reviews pull requests for best practices, security issues, and suggests improvements...",
|
|
1076
|
+
onSubmit: handleSubmit,
|
|
1077
|
+
error: createState.error,
|
|
1078
|
+
rows: 3
|
|
1079
|
+
}
|
|
1080
|
+
))
|
|
1081
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1082
|
+
}
|
|
1083
|
+
function TypeStep({
|
|
1084
|
+
createState,
|
|
1085
|
+
setCreateState,
|
|
1086
|
+
setModeState,
|
|
1087
|
+
existingAgents
|
|
1088
|
+
}) {
|
|
1089
|
+
const handleSubmit = () => {
|
|
1090
|
+
const validation = validateAgentType(createState.agentType, existingAgents);
|
|
1091
|
+
if (validation.isValid) {
|
|
1092
|
+
setModeState({ mode: "create-prompt", location: createState.location });
|
|
1093
|
+
} else {
|
|
1094
|
+
setCreateState({ type: "SET_ERROR", value: validation.errors[0] });
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1098
|
+
Header,
|
|
1099
|
+
{
|
|
1100
|
+
title: "Create new agent",
|
|
1101
|
+
subtitle: "Enter agent identifier",
|
|
1102
|
+
step: 3,
|
|
1103
|
+
totalSteps: 8
|
|
1104
|
+
},
|
|
1105
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1106
|
+
InkTextInput,
|
|
1107
|
+
{
|
|
1108
|
+
value: createState.agentType,
|
|
1109
|
+
onChange: (value) => setCreateState({ type: "SET_AGENT_TYPE", value }),
|
|
1110
|
+
placeholder: "e.g. code-reviewer, tech-lead",
|
|
1111
|
+
onSubmit: handleSubmit
|
|
1112
|
+
}
|
|
1113
|
+
), createState.error && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { color: "red" }, "\u26A0 ", createState.error)))
|
|
1114
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1115
|
+
}
|
|
1116
|
+
function DescriptionStep({
|
|
1117
|
+
createState,
|
|
1118
|
+
setCreateState,
|
|
1119
|
+
setModeState
|
|
1120
|
+
}) {
|
|
1121
|
+
const handleSubmit = () => {
|
|
1122
|
+
if (createState.whenToUse.trim()) {
|
|
1123
|
+
setModeState({ mode: "create-tools", location: createState.location });
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1127
|
+
Header,
|
|
1128
|
+
{
|
|
1129
|
+
title: "Create new agent",
|
|
1130
|
+
subtitle: "Describe when to use this agent",
|
|
1131
|
+
step: 5,
|
|
1132
|
+
totalSteps: 8
|
|
1133
|
+
},
|
|
1134
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1135
|
+
MultilineTextInput,
|
|
1136
|
+
{
|
|
1137
|
+
value: createState.whenToUse,
|
|
1138
|
+
onChange: (value) => setCreateState({ type: "SET_WHEN_TO_USE", value }),
|
|
1139
|
+
placeholder: "Use this agent when you need to review code for best practices, security issues...",
|
|
1140
|
+
onSubmit: handleSubmit,
|
|
1141
|
+
error: createState.error,
|
|
1142
|
+
rows: 4
|
|
1143
|
+
}
|
|
1144
|
+
))
|
|
1145
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1146
|
+
}
|
|
1147
|
+
function ToolsStep({
|
|
1148
|
+
createState,
|
|
1149
|
+
setCreateState,
|
|
1150
|
+
setModeState,
|
|
1151
|
+
tools
|
|
1152
|
+
}) {
|
|
1153
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1154
|
+
const initialSelection = createState.selectedTools.length > 0 ? new Set(createState.selectedTools) : new Set(tools.map((t) => t.name));
|
|
1155
|
+
const [selectedTools, setSelectedTools] = useState(initialSelection);
|
|
1156
|
+
const [showAdvanced, setShowAdvanced] = useState(false);
|
|
1157
|
+
const [selectedCategory, setSelectedCategory] = useState("all");
|
|
1158
|
+
const categorizedTools = useMemo(() => {
|
|
1159
|
+
const categories = {
|
|
1160
|
+
read: [],
|
|
1161
|
+
edit: [],
|
|
1162
|
+
execution: [],
|
|
1163
|
+
web: [],
|
|
1164
|
+
mcp: [],
|
|
1165
|
+
other: []
|
|
1166
|
+
};
|
|
1167
|
+
tools.forEach((tool) => {
|
|
1168
|
+
let categorized = false;
|
|
1169
|
+
if (tool.name.startsWith("mcp__")) {
|
|
1170
|
+
categories.mcp.push(tool);
|
|
1171
|
+
categorized = true;
|
|
1172
|
+
} else {
|
|
1173
|
+
for (const [category, toolNames] of Object.entries(TOOL_CATEGORIES)) {
|
|
1174
|
+
if (Array.isArray(toolNames) && toolNames.includes(tool.name)) {
|
|
1175
|
+
categories[category]?.push(tool);
|
|
1176
|
+
categorized = true;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (!categorized) {
|
|
1182
|
+
categories.other.push(tool);
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
return categories;
|
|
1186
|
+
}, [tools]);
|
|
1187
|
+
const displayTools = useMemo(() => {
|
|
1188
|
+
if (selectedCategory === "all") {
|
|
1189
|
+
return tools;
|
|
1190
|
+
}
|
|
1191
|
+
return categorizedTools[selectedCategory] || [];
|
|
1192
|
+
}, [selectedCategory, tools, categorizedTools]);
|
|
1193
|
+
const allSelected = selectedTools.size === tools.length && tools.length > 0;
|
|
1194
|
+
const categoryOptions = [
|
|
1195
|
+
{ id: "all", label: `All (${tools.length})` },
|
|
1196
|
+
{ id: "read", label: `Read (${categorizedTools.read.length})` },
|
|
1197
|
+
{ id: "edit", label: `Edit (${categorizedTools.edit.length})` },
|
|
1198
|
+
{
|
|
1199
|
+
id: "execution",
|
|
1200
|
+
label: `Execution (${categorizedTools.execution.length})`
|
|
1201
|
+
},
|
|
1202
|
+
{ id: "web", label: `Web (${categorizedTools.web.length})` },
|
|
1203
|
+
{ id: "mcp", label: `MCP (${categorizedTools.mcp.length})` },
|
|
1204
|
+
{ id: "other", label: `Other (${categorizedTools.other.length})` }
|
|
1205
|
+
].filter((cat) => cat.id === "all" || categorizedTools[cat.id]?.length > 0);
|
|
1206
|
+
const readSelected = categorizedTools.read.every(
|
|
1207
|
+
(tool) => selectedTools.has(tool.name)
|
|
1208
|
+
);
|
|
1209
|
+
const editSelected = categorizedTools.edit.every(
|
|
1210
|
+
(tool) => selectedTools.has(tool.name)
|
|
1211
|
+
);
|
|
1212
|
+
const execSelected = categorizedTools.execution.every(
|
|
1213
|
+
(tool) => selectedTools.has(tool.name)
|
|
1214
|
+
);
|
|
1215
|
+
const webSelected = categorizedTools.web.every(
|
|
1216
|
+
(tool) => selectedTools.has(tool.name)
|
|
1217
|
+
);
|
|
1218
|
+
const options = [
|
|
1219
|
+
{ id: "continue", label: "Save", isContinue: true },
|
|
1220
|
+
{
|
|
1221
|
+
id: "separator1",
|
|
1222
|
+
label: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
1223
|
+
isSeparator: true
|
|
1224
|
+
},
|
|
1225
|
+
{
|
|
1226
|
+
id: "all",
|
|
1227
|
+
label: `${allSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} All tools`,
|
|
1228
|
+
isAll: true
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
id: "read",
|
|
1232
|
+
label: `${readSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Read-only tools`,
|
|
1233
|
+
isCategory: true
|
|
1234
|
+
},
|
|
1235
|
+
{
|
|
1236
|
+
id: "edit",
|
|
1237
|
+
label: `${editSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Edit tools`,
|
|
1238
|
+
isCategory: true
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
id: "execution",
|
|
1242
|
+
label: `${execSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Execution tools`,
|
|
1243
|
+
isCategory: true
|
|
1244
|
+
},
|
|
1245
|
+
{
|
|
1246
|
+
id: "separator2",
|
|
1247
|
+
label: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
1248
|
+
isSeparator: true
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
id: "advanced",
|
|
1252
|
+
label: `[ ${showAdvanced ? "Hide" : "Show"} advanced options ]`,
|
|
1253
|
+
isAdvancedToggle: true
|
|
1254
|
+
},
|
|
1255
|
+
...showAdvanced ? displayTools.map((tool) => ({
|
|
1256
|
+
id: tool.name,
|
|
1257
|
+
label: `${selectedTools.has(tool.name) ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} ${tool.name}`,
|
|
1258
|
+
isTool: true
|
|
1259
|
+
})) : []
|
|
1260
|
+
];
|
|
1261
|
+
const handleSelect = () => {
|
|
1262
|
+
const option = options[selectedIndex];
|
|
1263
|
+
if (!option) return;
|
|
1264
|
+
if (option.isSeparator) return;
|
|
1265
|
+
if (option.isContinue) {
|
|
1266
|
+
const result = allSelected ? ["*"] : Array.from(selectedTools);
|
|
1267
|
+
setCreateState({ type: "SET_SELECTED_TOOLS", value: result });
|
|
1268
|
+
setModeState({ mode: "create-model", location: createState.location });
|
|
1269
|
+
} else if (option.isAdvancedToggle) {
|
|
1270
|
+
setShowAdvanced(!showAdvanced);
|
|
1271
|
+
} else if (option.isAll) {
|
|
1272
|
+
if (allSelected) {
|
|
1273
|
+
setSelectedTools(/* @__PURE__ */ new Set());
|
|
1274
|
+
} else {
|
|
1275
|
+
setSelectedTools(new Set(tools.map((t) => t.name)));
|
|
1276
|
+
}
|
|
1277
|
+
} else if (option.isCategory) {
|
|
1278
|
+
const categoryName = option.id;
|
|
1279
|
+
const categoryTools = categorizedTools[categoryName] || [];
|
|
1280
|
+
const newSelected = new Set(selectedTools);
|
|
1281
|
+
const categorySelected = categoryTools.every(
|
|
1282
|
+
(tool) => selectedTools.has(tool.name)
|
|
1283
|
+
);
|
|
1284
|
+
if (categorySelected) {
|
|
1285
|
+
categoryTools.forEach((tool) => newSelected.delete(tool.name));
|
|
1286
|
+
} else {
|
|
1287
|
+
categoryTools.forEach((tool) => newSelected.add(tool.name));
|
|
1288
|
+
}
|
|
1289
|
+
setSelectedTools(newSelected);
|
|
1290
|
+
} else if (option.isTool) {
|
|
1291
|
+
const newSelected = new Set(selectedTools);
|
|
1292
|
+
if (newSelected.has(option.id)) {
|
|
1293
|
+
newSelected.delete(option.id);
|
|
1294
|
+
} else {
|
|
1295
|
+
newSelected.add(option.id);
|
|
1296
|
+
}
|
|
1297
|
+
setSelectedTools(newSelected);
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
useInput((input, key) => {
|
|
1301
|
+
if (key.return) {
|
|
1302
|
+
handleSelect();
|
|
1303
|
+
} else if (key.upArrow) {
|
|
1304
|
+
setSelectedIndex((prev) => {
|
|
1305
|
+
let newIndex = prev > 0 ? prev - 1 : options.length - 1;
|
|
1306
|
+
while (options[newIndex] && options[newIndex].isSeparator) {
|
|
1307
|
+
newIndex = newIndex > 0 ? newIndex - 1 : options.length - 1;
|
|
1308
|
+
}
|
|
1309
|
+
return newIndex;
|
|
1310
|
+
});
|
|
1311
|
+
} else if (key.downArrow) {
|
|
1312
|
+
setSelectedIndex((prev) => {
|
|
1313
|
+
let newIndex = prev < options.length - 1 ? prev + 1 : 0;
|
|
1314
|
+
while (options[newIndex] && options[newIndex].isSeparator) {
|
|
1315
|
+
newIndex = newIndex < options.length - 1 ? newIndex + 1 : 0;
|
|
1316
|
+
}
|
|
1317
|
+
return newIndex;
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u{1F527} Tool Permissions", subtitle: "", step: 3, totalSteps: 5 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, options.map((option, idx) => {
|
|
1322
|
+
const isSelected = idx === selectedIndex;
|
|
1323
|
+
const isContinue = option.isContinue;
|
|
1324
|
+
const isAdvancedToggle = option.isAdvancedToggle;
|
|
1325
|
+
const isSeparator = option.isSeparator;
|
|
1326
|
+
return /* @__PURE__ */ React.createElement(Box, { key: option.id }, /* @__PURE__ */ React.createElement(
|
|
1327
|
+
Text,
|
|
1328
|
+
{
|
|
1329
|
+
color: isSelected && !isSeparator ? "cyan" : isSeparator ? "gray" : void 0,
|
|
1330
|
+
bold: isContinue,
|
|
1331
|
+
dimColor: isSeparator
|
|
1332
|
+
},
|
|
1333
|
+
isSeparator ? option.label : `${isSelected ? `${UI_ICONS.pointer} ` : " "}${isContinue || isAdvancedToggle ? `${option.label}` : option.label}`
|
|
1334
|
+
), option.isTool && isSelected && tools.find((t) => t.name === option.id)?.description && /* @__PURE__ */ React.createElement(Box, { marginLeft: 4 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, tools.find((t) => t.name === option.id)?.description)));
|
|
1335
|
+
}), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, allSelected ? "All tools selected" : `${selectedTools.size} of ${tools.length} tools selected`), selectedCategory !== "all" && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Filtering: ", selectedCategory, " tools")))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 Navigate \u2022 Enter Toggle \u2022 Esc Back" }));
|
|
1336
|
+
}
|
|
1337
|
+
function ModelStep({ createState, setCreateState, setModeState }) {
|
|
1338
|
+
const theme = getTheme();
|
|
1339
|
+
const manager = getModelManager();
|
|
1340
|
+
const profiles = manager.getActiveModelProfiles();
|
|
1341
|
+
const groupedModels = profiles.reduce((acc, profile) => {
|
|
1342
|
+
const provider = profile.provider || "Default";
|
|
1343
|
+
if (!acc[provider]) acc[provider] = [];
|
|
1344
|
+
acc[provider].push(profile);
|
|
1345
|
+
return acc;
|
|
1346
|
+
}, {});
|
|
1347
|
+
const modelOptions = [
|
|
1348
|
+
{
|
|
1349
|
+
id: null,
|
|
1350
|
+
name: "\u25C8 Inherit from parent",
|
|
1351
|
+
provider: "System",
|
|
1352
|
+
modelName: "default"
|
|
1353
|
+
},
|
|
1354
|
+
...Object.entries(groupedModels).flatMap(
|
|
1355
|
+
([provider, models]) => models.map((p) => ({
|
|
1356
|
+
id: p.modelName,
|
|
1357
|
+
name: p.name,
|
|
1358
|
+
provider,
|
|
1359
|
+
modelName: p.modelName
|
|
1360
|
+
}))
|
|
1361
|
+
)
|
|
1362
|
+
];
|
|
1363
|
+
const [selectedIndex, setSelectedIndex] = useState(() => {
|
|
1364
|
+
const idx = modelOptions.findIndex((m) => m.id === createState.selectedModel);
|
|
1365
|
+
return idx >= 0 ? idx : 0;
|
|
1366
|
+
});
|
|
1367
|
+
const handleSelect = (modelId) => {
|
|
1368
|
+
setCreateState({ type: "SET_SELECTED_MODEL", value: modelId });
|
|
1369
|
+
setModeState({ mode: "create-color", location: createState.location });
|
|
1370
|
+
};
|
|
1371
|
+
useInput((input, key) => {
|
|
1372
|
+
if (key.return) {
|
|
1373
|
+
handleSelect(modelOptions[selectedIndex].id);
|
|
1374
|
+
} else if (key.upArrow) {
|
|
1375
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : modelOptions.length - 1);
|
|
1376
|
+
} else if (key.downArrow) {
|
|
1377
|
+
setSelectedIndex((prev) => prev < modelOptions.length - 1 ? prev + 1 : 0);
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u{1F916} Select Model", subtitle: "", step: 4, totalSteps: 5 }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, modelOptions.map((model, index) => {
|
|
1381
|
+
const isSelected = index === selectedIndex;
|
|
1382
|
+
const isInherit = model.id === null;
|
|
1383
|
+
return /* @__PURE__ */ React.createElement(Box, { key: model.id || "inherit", marginBottom: 0 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(Text, { color: isSelected ? theme.primary : void 0 }, isSelected ? UI_ICONS.pointer : " "), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", flexGrow: 1 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(
|
|
1384
|
+
Text,
|
|
1385
|
+
{
|
|
1386
|
+
bold: isInherit,
|
|
1387
|
+
color: isSelected ? theme.primary : void 0
|
|
1388
|
+
},
|
|
1389
|
+
model.name
|
|
1390
|
+
), !isInherit && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, model.provider, " \u2022 ", model.modelName)))));
|
|
1391
|
+
}))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 Navigate \u2022 Enter Select" }));
|
|
1392
|
+
}
|
|
1393
|
+
function ColorStep({ createState, setCreateState, setModeState }) {
|
|
1394
|
+
const theme = getTheme();
|
|
1395
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1396
|
+
const colors = [
|
|
1397
|
+
{ label: "Default", value: null, displayColor: null },
|
|
1398
|
+
{ label: "Yellow", value: "yellow", displayColor: "yellow" },
|
|
1399
|
+
{ label: "Blue", value: "blue", displayColor: "blue" },
|
|
1400
|
+
{ label: "Magenta", value: "magenta", displayColor: "magenta" },
|
|
1401
|
+
{ label: "Cyan", value: "cyan", displayColor: "cyan" },
|
|
1402
|
+
{ label: "Gray", value: "gray", displayColor: "gray" },
|
|
1403
|
+
{ label: "White", value: "white", displayColor: "white" }
|
|
1404
|
+
];
|
|
1405
|
+
const handleSelect = (value) => {
|
|
1406
|
+
setCreateState({ type: "SET_SELECTED_COLOR", value });
|
|
1407
|
+
setModeState({ mode: "create-confirm", location: createState.location });
|
|
1408
|
+
};
|
|
1409
|
+
useInput((input, key) => {
|
|
1410
|
+
if (key.return) {
|
|
1411
|
+
handleSelect(colors[selectedIndex].value);
|
|
1412
|
+
} else if (key.upArrow) {
|
|
1413
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : colors.length - 1);
|
|
1414
|
+
} else if (key.downArrow) {
|
|
1415
|
+
setSelectedIndex((prev) => prev < colors.length - 1 ? prev + 1 : 0);
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u{1F3A8} Color Theme", subtitle: "", step: 5, totalSteps: 5 }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Choose how your agent appears in the list:")), colors.map((color, idx) => {
|
|
1419
|
+
const isSelected = idx === selectedIndex;
|
|
1420
|
+
return /* @__PURE__ */ React.createElement(Box, { key: idx, flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, { color: isSelected ? theme.primary : void 0 }, isSelected ? "\u276F " : " "), /* @__PURE__ */ React.createElement(Box, { minWidth: 12 }, /* @__PURE__ */ React.createElement(
|
|
1421
|
+
Text,
|
|
1422
|
+
{
|
|
1423
|
+
bold: isSelected,
|
|
1424
|
+
color: color.displayColor || void 0
|
|
1425
|
+
},
|
|
1426
|
+
color.label
|
|
1427
|
+
)));
|
|
1428
|
+
}), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, null, "Preview: "), /* @__PURE__ */ React.createElement(Text, { bold: true, color: colors[selectedIndex].displayColor || void 0 }, createState.agentType || "your-agent")))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 Navigate \u2022 Enter Select" }));
|
|
1429
|
+
}
|
|
1430
|
+
function PromptStep({ createState, setCreateState, setModeState }) {
|
|
1431
|
+
const handleSubmit = () => {
|
|
1432
|
+
if (createState.systemPrompt.trim()) {
|
|
1433
|
+
setModeState({
|
|
1434
|
+
mode: "create-description",
|
|
1435
|
+
location: createState.location
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1440
|
+
Header,
|
|
1441
|
+
{
|
|
1442
|
+
title: "Create new agent",
|
|
1443
|
+
subtitle: "System prompt",
|
|
1444
|
+
step: 4,
|
|
1445
|
+
totalSteps: 8
|
|
1446
|
+
},
|
|
1447
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1448
|
+
MultilineTextInput,
|
|
1449
|
+
{
|
|
1450
|
+
value: createState.systemPrompt,
|
|
1451
|
+
onChange: (value) => setCreateState({ type: "SET_SYSTEM_PROMPT", value }),
|
|
1452
|
+
placeholder: "You are a helpful assistant that specializes in...",
|
|
1453
|
+
onSubmit: handleSubmit,
|
|
1454
|
+
error: createState.error,
|
|
1455
|
+
rows: 5
|
|
1456
|
+
}
|
|
1457
|
+
))
|
|
1458
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1459
|
+
}
|
|
1460
|
+
function ConfirmStep({
|
|
1461
|
+
createState,
|
|
1462
|
+
setCreateState,
|
|
1463
|
+
setModeState,
|
|
1464
|
+
tools,
|
|
1465
|
+
onAgentCreated
|
|
1466
|
+
}) {
|
|
1467
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
1468
|
+
const theme = getTheme();
|
|
1469
|
+
const handleConfirm = async () => {
|
|
1470
|
+
setIsCreating(true);
|
|
1471
|
+
try {
|
|
1472
|
+
await saveAgent(
|
|
1473
|
+
createState.location,
|
|
1474
|
+
createState.agentType,
|
|
1475
|
+
createState.whenToUse,
|
|
1476
|
+
createState.selectedTools,
|
|
1477
|
+
createState.systemPrompt,
|
|
1478
|
+
createState.selectedModel,
|
|
1479
|
+
createState.selectedColor || void 0
|
|
1480
|
+
);
|
|
1481
|
+
onAgentCreated(`Created agent: ${createState.agentType}`);
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
setCreateState({ type: "SET_ERROR", value: error.message });
|
|
1484
|
+
setIsCreating(false);
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
const validation = validateAgentConfig(createState);
|
|
1488
|
+
const toolNames = createState.selectedTools.includes("*") ? "All tools" : createState.selectedTools.length > 0 ? createState.selectedTools.join(", ") : "No tools";
|
|
1489
|
+
const handleEditInEditor = async () => {
|
|
1490
|
+
const filePath = createState.location === "project" ? path.join(
|
|
1491
|
+
process.cwd(),
|
|
1492
|
+
".claude",
|
|
1493
|
+
"agents",
|
|
1494
|
+
`${createState.agentType}.md`
|
|
1495
|
+
) : path.join(
|
|
1496
|
+
os.homedir(),
|
|
1497
|
+
".claude",
|
|
1498
|
+
"agents",
|
|
1499
|
+
`${createState.agentType}.md`
|
|
1500
|
+
);
|
|
1501
|
+
try {
|
|
1502
|
+
await saveAgent(
|
|
1503
|
+
createState.location,
|
|
1504
|
+
createState.agentType,
|
|
1505
|
+
createState.whenToUse,
|
|
1506
|
+
createState.selectedTools,
|
|
1507
|
+
createState.systemPrompt,
|
|
1508
|
+
createState.selectedModel,
|
|
1509
|
+
createState.selectedColor || void 0
|
|
1510
|
+
);
|
|
1511
|
+
const command = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
1512
|
+
await execAsync(`${command} "${filePath}"`);
|
|
1513
|
+
onAgentCreated(`Created agent: ${createState.agentType}`);
|
|
1514
|
+
} catch (error) {
|
|
1515
|
+
setCreateState({ type: "SET_ERROR", value: error.message });
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
useInput((input, key) => {
|
|
1519
|
+
if (isCreating) return;
|
|
1520
|
+
if ((key.return || input === "s") && !isCreating) {
|
|
1521
|
+
handleConfirm();
|
|
1522
|
+
} else if (input === "e") {
|
|
1523
|
+
handleEditInEditor();
|
|
1524
|
+
} else if (key.escape) {
|
|
1525
|
+
setModeState({ mode: "create-color", location: createState.location });
|
|
1526
|
+
}
|
|
1527
|
+
});
|
|
1528
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u2705 Review & Create", subtitle: "" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.primary }, "\u{1F4CB} Configuration")), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", gap: 0 }, /* @__PURE__ */ React.createElement(Text, null, "\u2022 ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "Agent ID:"), " ", createState.agentType), /* @__PURE__ */ React.createElement(Text, null, "\u2022 ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "Location:"), " ", createState.location === "project" ? "Project" : "Personal"), /* @__PURE__ */ React.createElement(Text, null, "\u2022 ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "Tools:"), " ", toolNames.length > 50 ? toolNames.slice(0, 50) + "..." : toolNames), /* @__PURE__ */ React.createElement(Text, null, "\u2022 ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "Model:"), " ", getDisplayModelName(createState.selectedModel)), createState.selectedColor && /* @__PURE__ */ React.createElement(Text, null, "\u2022 ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "Color:"), " ", /* @__PURE__ */ React.createElement(Text, { color: createState.selectedColor }, createState.selectedColor))), /* @__PURE__ */ React.createElement(Box, { marginTop: 1, marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.primary }, "\u{1F4DD} Purpose")), /* @__PURE__ */ React.createElement(Box, { paddingLeft: 1 }, /* @__PURE__ */ React.createElement(Text, null, createState.whenToUse)), validation.warnings.length > 0 && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Warnings:")), validation.warnings.map((warning, idx) => /* @__PURE__ */ React.createElement(Fragment, { key: idx }, /* @__PURE__ */ React.createElement(Text, { color: theme.warning }, " \u2022 ", warning)))), createState.error && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.error }, "\u2717 ", createState.error)), /* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, isCreating ? /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Creating agent..." }) : null))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "Enter Save \u2022 E Edit \u2022 Esc Back" }));
|
|
1529
|
+
}
|
|
1530
|
+
function LocationSelect({
|
|
1531
|
+
createState,
|
|
1532
|
+
setCreateState,
|
|
1533
|
+
setModeState
|
|
1534
|
+
}) {
|
|
1535
|
+
const theme = getTheme();
|
|
1536
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1537
|
+
const options = [
|
|
1538
|
+
{ label: "\u{1F4C1} Project", value: "project", desc: ".claude/agents/" },
|
|
1539
|
+
{ label: "\u{1F3E0} Personal", value: "user", desc: "~/.claude/agents/" }
|
|
1540
|
+
];
|
|
1541
|
+
const handleChange = (value) => {
|
|
1542
|
+
setCreateState({ type: "SET_LOCATION", value });
|
|
1543
|
+
setCreateState({ type: "SET_METHOD", value: "generate" });
|
|
1544
|
+
setModeState({ mode: "create-generate", location: value });
|
|
1545
|
+
};
|
|
1546
|
+
const handleCancel = () => {
|
|
1547
|
+
setModeState({ mode: "list-agents", location: "all" });
|
|
1548
|
+
};
|
|
1549
|
+
useInput((input, key) => {
|
|
1550
|
+
if (key.escape) {
|
|
1551
|
+
handleCancel();
|
|
1552
|
+
} else if (key.return) {
|
|
1553
|
+
handleChange(options[selectedIndex].value);
|
|
1554
|
+
} else if (key.upArrow) {
|
|
1555
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : options.length - 1);
|
|
1556
|
+
} else if (key.downArrow) {
|
|
1557
|
+
setSelectedIndex((prev) => prev < options.length - 1 ? prev + 1 : 0);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "\u{1F4E6} Save Location", subtitle: "", step: 1, totalSteps: 5 }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1, flexDirection: "column" }, options.map((opt, idx) => /* @__PURE__ */ React.createElement(Box, { key: opt.value, flexDirection: "column", marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { color: idx === selectedIndex ? theme.primary : void 0 }, idx === selectedIndex ? "\u276F " : " ", opt.label), /* @__PURE__ */ React.createElement(Box, { marginLeft: 3 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, opt.desc)))))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 Navigate \u2022 Enter Select" }));
|
|
1561
|
+
}
|
|
1562
|
+
function MethodSelect({
|
|
1563
|
+
createState,
|
|
1564
|
+
setCreateState,
|
|
1565
|
+
setModeState
|
|
1566
|
+
}) {
|
|
1567
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1568
|
+
const options = [
|
|
1569
|
+
{ label: "Generate with Claude (recommended)", value: "generate" },
|
|
1570
|
+
{ label: "Manual configuration", value: "manual" }
|
|
1571
|
+
];
|
|
1572
|
+
const handleChange = (value) => {
|
|
1573
|
+
setCreateState({
|
|
1574
|
+
type: "SET_METHOD",
|
|
1575
|
+
value
|
|
1576
|
+
});
|
|
1577
|
+
if (value === "generate") {
|
|
1578
|
+
setCreateState({ type: "SET_IS_AI_GENERATED", value: true });
|
|
1579
|
+
setModeState({ mode: "create-generate", location: createState.location });
|
|
1580
|
+
} else {
|
|
1581
|
+
setCreateState({ type: "SET_IS_AI_GENERATED", value: false });
|
|
1582
|
+
setModeState({ mode: "create-type", location: createState.location });
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
const handleCancel = () => {
|
|
1586
|
+
setModeState({ mode: "create-location" });
|
|
1587
|
+
};
|
|
1588
|
+
useInput((input, key) => {
|
|
1589
|
+
if (key.escape) {
|
|
1590
|
+
handleCancel();
|
|
1591
|
+
} else if (key.return) {
|
|
1592
|
+
handleChange(options[selectedIndex].value);
|
|
1593
|
+
} else if (key.upArrow) {
|
|
1594
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : options.length - 1);
|
|
1595
|
+
} else if (key.downArrow) {
|
|
1596
|
+
setSelectedIndex((prev) => prev < options.length - 1 ? prev + 1 : 0);
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1600
|
+
Header,
|
|
1601
|
+
{
|
|
1602
|
+
title: "Create new agent",
|
|
1603
|
+
subtitle: "Creation method",
|
|
1604
|
+
step: 2,
|
|
1605
|
+
totalSteps: 9
|
|
1606
|
+
},
|
|
1607
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1608
|
+
SelectList,
|
|
1609
|
+
{
|
|
1610
|
+
options,
|
|
1611
|
+
selectedIndex,
|
|
1612
|
+
onChange: handleChange,
|
|
1613
|
+
onCancel: handleCancel
|
|
1614
|
+
}
|
|
1615
|
+
))
|
|
1616
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1617
|
+
}
|
|
1618
|
+
function AgentMenu({ agent, setModeState }) {
|
|
1619
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1620
|
+
const options = [
|
|
1621
|
+
{ label: "View details", value: "view" },
|
|
1622
|
+
{
|
|
1623
|
+
label: "Edit agent",
|
|
1624
|
+
value: "edit",
|
|
1625
|
+
disabled: agent.location === "built-in"
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
label: "Delete agent",
|
|
1629
|
+
value: "delete",
|
|
1630
|
+
disabled: agent.location === "built-in"
|
|
1631
|
+
}
|
|
1632
|
+
];
|
|
1633
|
+
const availableOptions = options.filter((opt) => !opt.disabled);
|
|
1634
|
+
const handleSelect = (value) => {
|
|
1635
|
+
switch (value) {
|
|
1636
|
+
case "view":
|
|
1637
|
+
setModeState({ mode: "view-agent", selectedAgent: agent });
|
|
1638
|
+
break;
|
|
1639
|
+
case "edit":
|
|
1640
|
+
setModeState({ mode: "edit-agent", selectedAgent: agent });
|
|
1641
|
+
break;
|
|
1642
|
+
case "delete":
|
|
1643
|
+
setModeState({ mode: "delete-confirm", selectedAgent: agent });
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
useInput((input, key) => {
|
|
1648
|
+
if (key.return) {
|
|
1649
|
+
handleSelect(availableOptions[selectedIndex].value);
|
|
1650
|
+
} else if (key.upArrow) {
|
|
1651
|
+
setSelectedIndex(
|
|
1652
|
+
(prev) => prev > 0 ? prev - 1 : availableOptions.length - 1
|
|
1653
|
+
);
|
|
1654
|
+
} else if (key.downArrow) {
|
|
1655
|
+
setSelectedIndex(
|
|
1656
|
+
(prev) => prev < availableOptions.length - 1 ? prev + 1 : 0
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1661
|
+
Header,
|
|
1662
|
+
{
|
|
1663
|
+
title: `Agent: ${agent.agentType}`,
|
|
1664
|
+
subtitle: `${agent.location}`
|
|
1665
|
+
},
|
|
1666
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1667
|
+
SelectList,
|
|
1668
|
+
{
|
|
1669
|
+
options: availableOptions,
|
|
1670
|
+
selectedIndex,
|
|
1671
|
+
onChange: handleSelect,
|
|
1672
|
+
numbered: false
|
|
1673
|
+
}
|
|
1674
|
+
))
|
|
1675
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1676
|
+
}
|
|
1677
|
+
function EditMenu({ agent, setModeState }) {
|
|
1678
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1679
|
+
const [isOpening, setIsOpening] = useState(false);
|
|
1680
|
+
const theme = getTheme();
|
|
1681
|
+
const options = [
|
|
1682
|
+
{ label: "Open in editor", value: "open-editor" },
|
|
1683
|
+
{ label: "Edit tools", value: "edit-tools" },
|
|
1684
|
+
{ label: "Edit model", value: "edit-model" },
|
|
1685
|
+
{ label: "Edit color", value: "edit-color" }
|
|
1686
|
+
];
|
|
1687
|
+
const handleSelect = async (value) => {
|
|
1688
|
+
switch (value) {
|
|
1689
|
+
case "open-editor":
|
|
1690
|
+
setIsOpening(true);
|
|
1691
|
+
try {
|
|
1692
|
+
const filePath = getAgentFilePath(agent);
|
|
1693
|
+
await openInEditor(filePath);
|
|
1694
|
+
setModeState({ mode: "agent-menu", selectedAgent: agent });
|
|
1695
|
+
} catch (error) {
|
|
1696
|
+
console.error("Failed to open editor:", error);
|
|
1697
|
+
} finally {
|
|
1698
|
+
setIsOpening(false);
|
|
1699
|
+
}
|
|
1700
|
+
break;
|
|
1701
|
+
case "edit-tools":
|
|
1702
|
+
setModeState({ mode: "edit-tools", selectedAgent: agent });
|
|
1703
|
+
break;
|
|
1704
|
+
case "edit-model":
|
|
1705
|
+
setModeState({ mode: "edit-model", selectedAgent: agent });
|
|
1706
|
+
break;
|
|
1707
|
+
case "edit-color":
|
|
1708
|
+
setModeState({ mode: "edit-color", selectedAgent: agent });
|
|
1709
|
+
break;
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
const handleBack = () => {
|
|
1713
|
+
setModeState({ mode: "agent-menu", selectedAgent: agent });
|
|
1714
|
+
};
|
|
1715
|
+
useInput((input, key) => {
|
|
1716
|
+
if (key.escape) {
|
|
1717
|
+
handleBack();
|
|
1718
|
+
} else if (key.return && !isOpening) {
|
|
1719
|
+
handleSelect(options[selectedIndex].value);
|
|
1720
|
+
} else if (key.upArrow) {
|
|
1721
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : options.length - 1);
|
|
1722
|
+
} else if (key.downArrow) {
|
|
1723
|
+
setSelectedIndex((prev) => prev < options.length - 1 ? prev + 1 : 0);
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
if (isOpening) {
|
|
1727
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1728
|
+
Header,
|
|
1729
|
+
{
|
|
1730
|
+
title: `Edit agent: ${agent.agentType}`,
|
|
1731
|
+
subtitle: "Opening in editor..."
|
|
1732
|
+
},
|
|
1733
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Opening file in editor..." }))
|
|
1734
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1735
|
+
}
|
|
1736
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
1737
|
+
Header,
|
|
1738
|
+
{
|
|
1739
|
+
title: `Edit agent: ${agent.agentType}`,
|
|
1740
|
+
subtitle: `Location: ${agent.location}`
|
|
1741
|
+
},
|
|
1742
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
1743
|
+
SelectList,
|
|
1744
|
+
{
|
|
1745
|
+
options,
|
|
1746
|
+
selectedIndex,
|
|
1747
|
+
onChange: handleSelect,
|
|
1748
|
+
numbered: false
|
|
1749
|
+
}
|
|
1750
|
+
))
|
|
1751
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 navigate \xB7 Enter select \xB7 Esc back" }));
|
|
1752
|
+
}
|
|
1753
|
+
function EditToolsStep({
|
|
1754
|
+
agent,
|
|
1755
|
+
tools,
|
|
1756
|
+
setModeState,
|
|
1757
|
+
onAgentUpdated
|
|
1758
|
+
}) {
|
|
1759
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
1760
|
+
const initialTools = Array.isArray(agent.tools) ? agent.tools : agent.tools === "*" ? tools.map((t) => t.name) : [];
|
|
1761
|
+
const [selectedTools, setSelectedTools] = useState(
|
|
1762
|
+
new Set(initialTools)
|
|
1763
|
+
);
|
|
1764
|
+
const [showAdvanced, setShowAdvanced] = useState(false);
|
|
1765
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
1766
|
+
const categorizedTools = useMemo(() => {
|
|
1767
|
+
const categories = {
|
|
1768
|
+
read: [],
|
|
1769
|
+
edit: [],
|
|
1770
|
+
execution: [],
|
|
1771
|
+
web: [],
|
|
1772
|
+
other: []
|
|
1773
|
+
};
|
|
1774
|
+
tools.forEach((tool) => {
|
|
1775
|
+
let categorized = false;
|
|
1776
|
+
for (const [category, toolNames] of Object.entries(TOOL_CATEGORIES)) {
|
|
1777
|
+
if (Array.isArray(toolNames) && toolNames.includes(tool.name)) {
|
|
1778
|
+
categories[category]?.push(tool);
|
|
1779
|
+
categorized = true;
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
if (!categorized) {
|
|
1784
|
+
categories.other.push(tool);
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
return categories;
|
|
1788
|
+
}, [tools]);
|
|
1789
|
+
const allSelected = selectedTools.size === tools.length && tools.length > 0;
|
|
1790
|
+
const readSelected = categorizedTools.read.every((tool) => selectedTools.has(tool.name)) && categorizedTools.read.length > 0;
|
|
1791
|
+
const editSelected = categorizedTools.edit.every((tool) => selectedTools.has(tool.name)) && categorizedTools.edit.length > 0;
|
|
1792
|
+
const execSelected = categorizedTools.execution.every((tool) => selectedTools.has(tool.name)) && categorizedTools.execution.length > 0;
|
|
1793
|
+
const options = [
|
|
1794
|
+
{ id: "continue", label: "Save", isContinue: true },
|
|
1795
|
+
{
|
|
1796
|
+
id: "separator1",
|
|
1797
|
+
label: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
1798
|
+
isSeparator: true
|
|
1799
|
+
},
|
|
1800
|
+
{
|
|
1801
|
+
id: "all",
|
|
1802
|
+
label: `${allSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} All tools`,
|
|
1803
|
+
isAll: true
|
|
1804
|
+
},
|
|
1805
|
+
{
|
|
1806
|
+
id: "read",
|
|
1807
|
+
label: `${readSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Read-only tools`,
|
|
1808
|
+
isCategory: true
|
|
1809
|
+
},
|
|
1810
|
+
{
|
|
1811
|
+
id: "edit",
|
|
1812
|
+
label: `${editSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Edit tools`,
|
|
1813
|
+
isCategory: true
|
|
1814
|
+
},
|
|
1815
|
+
{
|
|
1816
|
+
id: "execution",
|
|
1817
|
+
label: `${execSelected ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} Execution tools`,
|
|
1818
|
+
isCategory: true
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
id: "separator2",
|
|
1822
|
+
label: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
1823
|
+
isSeparator: true
|
|
1824
|
+
},
|
|
1825
|
+
{
|
|
1826
|
+
id: "advanced",
|
|
1827
|
+
label: `[ ${showAdvanced ? "Hide" : "Show"} advanced options ]`,
|
|
1828
|
+
isAdvancedToggle: true
|
|
1829
|
+
},
|
|
1830
|
+
...showAdvanced ? tools.map((tool) => ({
|
|
1831
|
+
id: tool.name,
|
|
1832
|
+
label: `${selectedTools.has(tool.name) ? UI_ICONS.checkboxOn : UI_ICONS.checkboxOff} ${tool.name}`,
|
|
1833
|
+
isTool: true
|
|
1834
|
+
})) : []
|
|
1835
|
+
];
|
|
1836
|
+
const handleSave = async () => {
|
|
1837
|
+
setIsUpdating(true);
|
|
1838
|
+
try {
|
|
1839
|
+
const toolsArray = allSelected ? "*" : Array.from(selectedTools);
|
|
1840
|
+
await updateAgent(
|
|
1841
|
+
agent,
|
|
1842
|
+
agent.whenToUse,
|
|
1843
|
+
toolsArray,
|
|
1844
|
+
agent.systemPrompt,
|
|
1845
|
+
agent.color,
|
|
1846
|
+
agent.model
|
|
1847
|
+
);
|
|
1848
|
+
clearAgentCache();
|
|
1849
|
+
const freshAgents = await getActiveAgents();
|
|
1850
|
+
const updatedAgent = freshAgents.find(
|
|
1851
|
+
(a) => a.agentType === agent.agentType
|
|
1852
|
+
);
|
|
1853
|
+
if (updatedAgent) {
|
|
1854
|
+
onAgentUpdated(
|
|
1855
|
+
`Updated tools for agent: ${agent.agentType}`,
|
|
1856
|
+
updatedAgent
|
|
1857
|
+
);
|
|
1858
|
+
setModeState({ mode: "edit-agent", selectedAgent: updatedAgent });
|
|
1859
|
+
} else {
|
|
1860
|
+
console.error("Failed to find updated agent after save");
|
|
1861
|
+
const fallbackAgent = {
|
|
1862
|
+
...agent,
|
|
1863
|
+
tools: toolsArray.length === 1 && toolsArray[0] === "*" ? "*" : toolsArray
|
|
1864
|
+
};
|
|
1865
|
+
onAgentUpdated(
|
|
1866
|
+
`Updated tools for agent: ${agent.agentType}`,
|
|
1867
|
+
fallbackAgent
|
|
1868
|
+
);
|
|
1869
|
+
setModeState({ mode: "edit-agent", selectedAgent: fallbackAgent });
|
|
1870
|
+
}
|
|
1871
|
+
} catch (error) {
|
|
1872
|
+
console.error("Failed to update agent tools:", error);
|
|
1873
|
+
} finally {
|
|
1874
|
+
setIsUpdating(false);
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
const handleSelect = () => {
|
|
1878
|
+
const option = options[selectedIndex];
|
|
1879
|
+
if (!option) return;
|
|
1880
|
+
if (option.isSeparator) return;
|
|
1881
|
+
if (option.isContinue) {
|
|
1882
|
+
handleSave();
|
|
1883
|
+
} else if (option.isAdvancedToggle) {
|
|
1884
|
+
setShowAdvanced(!showAdvanced);
|
|
1885
|
+
} else if (option.isAll) {
|
|
1886
|
+
if (allSelected) {
|
|
1887
|
+
setSelectedTools(/* @__PURE__ */ new Set());
|
|
1888
|
+
} else {
|
|
1889
|
+
setSelectedTools(new Set(tools.map((t) => t.name)));
|
|
1890
|
+
}
|
|
1891
|
+
} else if (option.isCategory) {
|
|
1892
|
+
const categoryName = option.id;
|
|
1893
|
+
const categoryTools = categorizedTools[categoryName] || [];
|
|
1894
|
+
const newSelected = new Set(selectedTools);
|
|
1895
|
+
const categorySelected = categoryTools.every(
|
|
1896
|
+
(tool) => selectedTools.has(tool.name)
|
|
1897
|
+
);
|
|
1898
|
+
if (categorySelected) {
|
|
1899
|
+
categoryTools.forEach((tool) => newSelected.delete(tool.name));
|
|
1900
|
+
} else {
|
|
1901
|
+
categoryTools.forEach((tool) => newSelected.add(tool.name));
|
|
1902
|
+
}
|
|
1903
|
+
setSelectedTools(newSelected);
|
|
1904
|
+
} else if (option.isTool) {
|
|
1905
|
+
const newSelected = new Set(selectedTools);
|
|
1906
|
+
if (newSelected.has(option.id)) {
|
|
1907
|
+
newSelected.delete(option.id);
|
|
1908
|
+
} else {
|
|
1909
|
+
newSelected.add(option.id);
|
|
1910
|
+
}
|
|
1911
|
+
setSelectedTools(newSelected);
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
useInput((input, key) => {
|
|
1915
|
+
if (key.escape) {
|
|
1916
|
+
setModeState({ mode: "edit-agent", selectedAgent: agent });
|
|
1917
|
+
} else if (key.return && !isUpdating) {
|
|
1918
|
+
handleSelect();
|
|
1919
|
+
} else if (key.upArrow) {
|
|
1920
|
+
setSelectedIndex((prev) => {
|
|
1921
|
+
let newIndex = prev > 0 ? prev - 1 : options.length - 1;
|
|
1922
|
+
while (options[newIndex] && options[newIndex].isSeparator) {
|
|
1923
|
+
newIndex = newIndex > 0 ? newIndex - 1 : options.length - 1;
|
|
1924
|
+
}
|
|
1925
|
+
return newIndex;
|
|
1926
|
+
});
|
|
1927
|
+
} else if (key.downArrow) {
|
|
1928
|
+
setSelectedIndex((prev) => {
|
|
1929
|
+
let newIndex = prev < options.length - 1 ? prev + 1 : 0;
|
|
1930
|
+
while (options[newIndex] && options[newIndex].isSeparator) {
|
|
1931
|
+
newIndex = newIndex < options.length - 1 ? newIndex + 1 : 0;
|
|
1932
|
+
}
|
|
1933
|
+
return newIndex;
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
});
|
|
1937
|
+
if (isUpdating) {
|
|
1938
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: `Edit agent: ${agent.agentType}` }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Updating agent tools..." }))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
1939
|
+
}
|
|
1940
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: `Edit agent: ${agent.agentType}` }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, options.map((option, idx) => {
|
|
1941
|
+
const isSelected = idx === selectedIndex;
|
|
1942
|
+
const isContinue = "isContinue" in option && option.isContinue;
|
|
1943
|
+
const isAdvancedToggle = option.isAdvancedToggle;
|
|
1944
|
+
const isSeparator = option.isSeparator;
|
|
1945
|
+
return /* @__PURE__ */ React.createElement(Box, { key: option.id }, /* @__PURE__ */ React.createElement(
|
|
1946
|
+
Text,
|
|
1947
|
+
{
|
|
1948
|
+
color: isSelected && !isSeparator ? "cyan" : isSeparator ? "gray" : void 0,
|
|
1949
|
+
bold: isContinue,
|
|
1950
|
+
dimColor: isSeparator
|
|
1951
|
+
},
|
|
1952
|
+
isSeparator ? option.label : `${isSelected ? `${UI_ICONS.pointer} ` : " "}${isContinue || isAdvancedToggle ? option.label : option.label}`
|
|
1953
|
+
), option.isTool && isSelected && tools.find((t) => t.name === option.id)?.description && /* @__PURE__ */ React.createElement(Box, { marginLeft: 4 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, tools.find((t) => t.name === option.id)?.description)));
|
|
1954
|
+
}), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, allSelected ? "All tools selected" : `${selectedTools.size} of ${tools.length} tools selected`)))), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "Enter toggle selection \xB7 \u2191\u2193 navigate \xB7 Esc back" }));
|
|
1955
|
+
}
|
|
1956
|
+
function EditModelStep({
|
|
1957
|
+
agent,
|
|
1958
|
+
setModeState,
|
|
1959
|
+
onAgentUpdated
|
|
1960
|
+
}) {
|
|
1961
|
+
const manager = getModelManager();
|
|
1962
|
+
const profiles = manager.getActiveModelProfiles();
|
|
1963
|
+
const currentModel = agent.model || null;
|
|
1964
|
+
const modelOptions = [
|
|
1965
|
+
{
|
|
1966
|
+
id: null,
|
|
1967
|
+
name: "Inherit from parent",
|
|
1968
|
+
description: "Use the model from task configuration"
|
|
1969
|
+
},
|
|
1970
|
+
...profiles.map((p) => ({
|
|
1971
|
+
id: p.modelName,
|
|
1972
|
+
name: p.name,
|
|
1973
|
+
description: `${p.provider || "provider"} \xB7 ${p.modelName}`
|
|
1974
|
+
}))
|
|
1975
|
+
];
|
|
1976
|
+
const defaultIndex = modelOptions.findIndex((m) => m.id === currentModel);
|
|
1977
|
+
const [selectedIndex, setSelectedIndex] = useState(
|
|
1978
|
+
defaultIndex >= 0 ? defaultIndex : 0
|
|
1979
|
+
);
|
|
1980
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
1981
|
+
const handleSave = async (modelId) => {
|
|
1982
|
+
setIsUpdating(true);
|
|
1983
|
+
try {
|
|
1984
|
+
const modelValue = modelId === null ? void 0 : modelId;
|
|
1985
|
+
await updateAgent(
|
|
1986
|
+
agent,
|
|
1987
|
+
agent.whenToUse,
|
|
1988
|
+
agent.tools,
|
|
1989
|
+
agent.systemPrompt,
|
|
1990
|
+
agent.color,
|
|
1991
|
+
modelValue
|
|
1992
|
+
);
|
|
1993
|
+
clearAgentCache();
|
|
1994
|
+
const freshAgents = await getActiveAgents();
|
|
1995
|
+
const updatedAgent = freshAgents.find(
|
|
1996
|
+
(a) => a.agentType === agent.agentType
|
|
1997
|
+
);
|
|
1998
|
+
if (updatedAgent) {
|
|
1999
|
+
onAgentUpdated(
|
|
2000
|
+
`Updated model for agent: ${agent.agentType}`,
|
|
2001
|
+
updatedAgent
|
|
2002
|
+
);
|
|
2003
|
+
setModeState({ mode: "edit-agent", selectedAgent: updatedAgent });
|
|
2004
|
+
} else {
|
|
2005
|
+
console.error("Failed to find updated agent after save");
|
|
2006
|
+
const fallbackAgent = { ...agent };
|
|
2007
|
+
if (modelValue) {
|
|
2008
|
+
;
|
|
2009
|
+
fallbackAgent.model = modelValue;
|
|
2010
|
+
} else {
|
|
2011
|
+
delete fallbackAgent.model;
|
|
2012
|
+
}
|
|
2013
|
+
onAgentUpdated(
|
|
2014
|
+
`Updated model for agent: ${agent.agentType}`,
|
|
2015
|
+
fallbackAgent
|
|
2016
|
+
);
|
|
2017
|
+
setModeState({ mode: "edit-agent", selectedAgent: fallbackAgent });
|
|
2018
|
+
}
|
|
2019
|
+
} catch (error) {
|
|
2020
|
+
console.error("Failed to update agent model:", error);
|
|
2021
|
+
} finally {
|
|
2022
|
+
setIsUpdating(false);
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
useInput((input, key) => {
|
|
2026
|
+
if (key.escape) {
|
|
2027
|
+
setModeState({ mode: "edit-agent", selectedAgent: agent });
|
|
2028
|
+
} else if (key.return && !isUpdating) {
|
|
2029
|
+
handleSave(modelOptions[selectedIndex].id);
|
|
2030
|
+
} else if (key.upArrow) {
|
|
2031
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : modelOptions.length - 1);
|
|
2032
|
+
} else if (key.downArrow) {
|
|
2033
|
+
setSelectedIndex((prev) => prev < modelOptions.length - 1 ? prev + 1 : 0);
|
|
2034
|
+
}
|
|
2035
|
+
});
|
|
2036
|
+
if (isUpdating) {
|
|
2037
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: `Edit agent: ${agent.agentType}` }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Updating agent model..." }))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
2038
|
+
}
|
|
2039
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
2040
|
+
Header,
|
|
2041
|
+
{
|
|
2042
|
+
title: `Edit agent: ${agent.agentType}`,
|
|
2043
|
+
subtitle: "Model determines the agent's reasoning capabilities and speed."
|
|
2044
|
+
},
|
|
2045
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, /* @__PURE__ */ React.createElement(
|
|
2046
|
+
SelectList,
|
|
2047
|
+
{
|
|
2048
|
+
options: modelOptions.map((m, i) => ({
|
|
2049
|
+
label: `${i + 1}. ${m.name}${m.description ? `
|
|
2050
|
+
${m.description}` : ""}`,
|
|
2051
|
+
value: m.id
|
|
2052
|
+
})),
|
|
2053
|
+
selectedIndex,
|
|
2054
|
+
onChange: (val) => handleSave(val),
|
|
2055
|
+
numbered: false
|
|
2056
|
+
}
|
|
2057
|
+
))
|
|
2058
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 navigate \xB7 Enter select \xB7 Esc back" }));
|
|
2059
|
+
}
|
|
2060
|
+
function EditColorStep({
|
|
2061
|
+
agent,
|
|
2062
|
+
setModeState,
|
|
2063
|
+
onAgentUpdated
|
|
2064
|
+
}) {
|
|
2065
|
+
const currentColor = agent.color || null;
|
|
2066
|
+
const colors = [
|
|
2067
|
+
{ label: "Automatic color", value: null },
|
|
2068
|
+
{ label: "Yellow", value: "yellow" },
|
|
2069
|
+
{ label: "Blue", value: "blue" },
|
|
2070
|
+
{ label: "Magenta", value: "magenta" },
|
|
2071
|
+
{ label: "Cyan", value: "cyan" },
|
|
2072
|
+
{ label: "Gray", value: "gray" },
|
|
2073
|
+
{ label: "White", value: "white" }
|
|
2074
|
+
];
|
|
2075
|
+
const defaultIndex = colors.findIndex((color) => color.value === currentColor);
|
|
2076
|
+
const [selectedIndex, setSelectedIndex] = useState(
|
|
2077
|
+
defaultIndex >= 0 ? defaultIndex : 0
|
|
2078
|
+
);
|
|
2079
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
2080
|
+
const handleSave = async (color) => {
|
|
2081
|
+
setIsUpdating(true);
|
|
2082
|
+
try {
|
|
2083
|
+
const colorValue = color === null ? void 0 : color;
|
|
2084
|
+
await updateAgent(
|
|
2085
|
+
agent,
|
|
2086
|
+
agent.whenToUse,
|
|
2087
|
+
agent.tools,
|
|
2088
|
+
agent.systemPrompt,
|
|
2089
|
+
colorValue,
|
|
2090
|
+
agent.model
|
|
2091
|
+
);
|
|
2092
|
+
clearAgentCache();
|
|
2093
|
+
const freshAgents = await getActiveAgents();
|
|
2094
|
+
const updatedAgent = freshAgents.find(
|
|
2095
|
+
(a) => a.agentType === agent.agentType
|
|
2096
|
+
);
|
|
2097
|
+
if (updatedAgent) {
|
|
2098
|
+
onAgentUpdated(
|
|
2099
|
+
`Updated color for agent: ${agent.agentType}`,
|
|
2100
|
+
updatedAgent
|
|
2101
|
+
);
|
|
2102
|
+
setModeState({ mode: "edit-agent", selectedAgent: updatedAgent });
|
|
2103
|
+
} else {
|
|
2104
|
+
console.error("Failed to find updated agent after save");
|
|
2105
|
+
const fallbackAgent = {
|
|
2106
|
+
...agent,
|
|
2107
|
+
...colorValue ? { color: colorValue } : { color: void 0 }
|
|
2108
|
+
};
|
|
2109
|
+
onAgentUpdated(
|
|
2110
|
+
`Updated color for agent: ${agent.agentType}`,
|
|
2111
|
+
fallbackAgent
|
|
2112
|
+
);
|
|
2113
|
+
setModeState({ mode: "edit-agent", selectedAgent: fallbackAgent });
|
|
2114
|
+
}
|
|
2115
|
+
} catch (error) {
|
|
2116
|
+
console.error("Failed to update agent color:", error);
|
|
2117
|
+
} finally {
|
|
2118
|
+
setIsUpdating(false);
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
useInput((input, key) => {
|
|
2122
|
+
if (key.escape) {
|
|
2123
|
+
setModeState({ mode: "edit-agent", selectedAgent: agent });
|
|
2124
|
+
} else if (key.return && !isUpdating) {
|
|
2125
|
+
handleSave(colors[selectedIndex].value);
|
|
2126
|
+
} else if (key.upArrow) {
|
|
2127
|
+
setSelectedIndex((prev) => prev > 0 ? prev - 1 : colors.length - 1);
|
|
2128
|
+
} else if (key.downArrow) {
|
|
2129
|
+
setSelectedIndex((prev) => prev < colors.length - 1 ? prev + 1 : 0);
|
|
2130
|
+
}
|
|
2131
|
+
});
|
|
2132
|
+
if (isUpdating) {
|
|
2133
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: `Edit agent: ${agent.agentType}` }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Updating agent color..." }))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
2134
|
+
}
|
|
2135
|
+
const selectedColor = colors[selectedIndex];
|
|
2136
|
+
const previewColor = selectedColor.value || void 0;
|
|
2137
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
2138
|
+
Header,
|
|
2139
|
+
{
|
|
2140
|
+
title: `Edit agent: ${agent.agentType}`,
|
|
2141
|
+
subtitle: "Choose background color"
|
|
2142
|
+
},
|
|
2143
|
+
/* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, colors.map((color, index) => {
|
|
2144
|
+
const isSelected = index === selectedIndex;
|
|
2145
|
+
const isCurrent = color.value === currentColor;
|
|
2146
|
+
return /* @__PURE__ */ React.createElement(Box, { key: color.value || "automatic" }, /* @__PURE__ */ React.createElement(Text, { color: isSelected ? "cyan" : void 0 }, isSelected ? "\u276F " : " "), /* @__PURE__ */ React.createElement(Text, { color: color.value || void 0 }, "\u25CF"), /* @__PURE__ */ React.createElement(Text, null, " ", color.label, isCurrent && /* @__PURE__ */ React.createElement(Text, { color: "green" }, " \u2714")));
|
|
2147
|
+
}), /* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, /* @__PURE__ */ React.createElement(Text, null, "Preview: "), /* @__PURE__ */ React.createElement(Text, { color: previewColor }, agent.agentType)))
|
|
2148
|
+
), /* @__PURE__ */ React.createElement(InstructionBar, { instructions: "\u2191\u2193 navigate \xB7 Enter select \xB7 Esc back" }));
|
|
2149
|
+
}
|
|
2150
|
+
function ViewAgent({ agent, tools, setModeState }) {
|
|
2151
|
+
const theme = getTheme();
|
|
2152
|
+
const agentTools = Array.isArray(agent.tools) ? agent.tools : [];
|
|
2153
|
+
const hasAllTools = agent.tools === "*" || agentTools.includes("*");
|
|
2154
|
+
const locationPath = agent.location === "user" ? `~/.claude/agents/${agent.agentType}.md` : agent.location === "project" ? `.claude/agents/${agent.agentType}.md` : "(built-in)";
|
|
2155
|
+
const displayModel = getDisplayModelName(agent.model || null);
|
|
2156
|
+
const allowedTools = useMemo(() => {
|
|
2157
|
+
if (hasAllTools) return tools;
|
|
2158
|
+
return tools.filter(
|
|
2159
|
+
(tool) => agentTools.some((allowedTool) => {
|
|
2160
|
+
if (allowedTool.includes("*")) {
|
|
2161
|
+
const prefix = allowedTool.replace("*", "");
|
|
2162
|
+
return tool.name.startsWith(prefix);
|
|
2163
|
+
}
|
|
2164
|
+
return tool.name === allowedTool;
|
|
2165
|
+
})
|
|
2166
|
+
);
|
|
2167
|
+
}, [tools, agentTools, hasAllTools]);
|
|
2168
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: `Agent: ${agent.agentType}`, subtitle: "Details" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Type:"), " ", agent.agentType), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Location:"), " ", agent.location, " ", locationPath !== "(built-in)" ? `\xB7 ${locationPath}` : ""), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Description:"), " ", agent.whenToUse), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Model:"), " ", displayModel), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Color:"), " ", agent.color || "auto"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Tools:")), hasAllTools ? /* @__PURE__ */ React.createElement(Text, { color: theme.secondary }, "All tools (", tools.length, " available)") : /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, allowedTools.map((tool) => /* @__PURE__ */ React.createElement(Fragment, { key: tool.name }, /* @__PURE__ */ React.createElement(Text, { color: theme.secondary }, "\u2022 ", tool.name)))), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "System Prompt:")), /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, null, agent.systemPrompt)))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
2169
|
+
}
|
|
2170
|
+
function EditAgent({
|
|
2171
|
+
agent,
|
|
2172
|
+
tools,
|
|
2173
|
+
setModeState,
|
|
2174
|
+
onAgentUpdated
|
|
2175
|
+
}) {
|
|
2176
|
+
const theme = getTheme();
|
|
2177
|
+
const [currentStep, setCurrentStep] = useState("description");
|
|
2178
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
2179
|
+
const [editedDescription, setEditedDescription] = useState(agent.whenToUse);
|
|
2180
|
+
const [editedTools, setEditedTools] = useState(
|
|
2181
|
+
Array.isArray(agent.tools) ? agent.tools : agent.tools === "*" ? ["*"] : []
|
|
2182
|
+
);
|
|
2183
|
+
const [editedPrompt, setEditedPrompt] = useState(agent.systemPrompt);
|
|
2184
|
+
const [error, setError] = useState(null);
|
|
2185
|
+
const handleSave = async () => {
|
|
2186
|
+
setIsUpdating(true);
|
|
2187
|
+
try {
|
|
2188
|
+
await updateAgent(
|
|
2189
|
+
agent,
|
|
2190
|
+
editedDescription,
|
|
2191
|
+
editedTools,
|
|
2192
|
+
editedPrompt,
|
|
2193
|
+
agent.color
|
|
2194
|
+
);
|
|
2195
|
+
clearAgentCache();
|
|
2196
|
+
onAgentUpdated(`Updated agent: ${agent.agentType}`);
|
|
2197
|
+
} catch (error2) {
|
|
2198
|
+
setError(error2.message);
|
|
2199
|
+
setIsUpdating(false);
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
const renderStepContent = () => {
|
|
2203
|
+
switch (currentStep) {
|
|
2204
|
+
case "description":
|
|
2205
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Edit Description:"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
2206
|
+
MultilineTextInput,
|
|
2207
|
+
{
|
|
2208
|
+
value: editedDescription,
|
|
2209
|
+
onChange: setEditedDescription,
|
|
2210
|
+
placeholder: "Describe when to use this agent...",
|
|
2211
|
+
onSubmit: () => setCurrentStep("tools"),
|
|
2212
|
+
error,
|
|
2213
|
+
rows: 4
|
|
2214
|
+
}
|
|
2215
|
+
)));
|
|
2216
|
+
case "tools":
|
|
2217
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Edit Tools:"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
2218
|
+
ToolsStep,
|
|
2219
|
+
{
|
|
2220
|
+
createState: {
|
|
2221
|
+
selectedTools: editedTools
|
|
2222
|
+
},
|
|
2223
|
+
setCreateState: (action) => {
|
|
2224
|
+
if (action.type === "SET_SELECTED_TOOLS") {
|
|
2225
|
+
setEditedTools(action.value);
|
|
2226
|
+
setCurrentStep("prompt");
|
|
2227
|
+
}
|
|
2228
|
+
},
|
|
2229
|
+
setModeState: () => {
|
|
2230
|
+
},
|
|
2231
|
+
tools
|
|
2232
|
+
}
|
|
2233
|
+
)));
|
|
2234
|
+
case "prompt":
|
|
2235
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Edit System Prompt:"), /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
2236
|
+
MultilineTextInput,
|
|
2237
|
+
{
|
|
2238
|
+
value: editedPrompt,
|
|
2239
|
+
onChange: setEditedPrompt,
|
|
2240
|
+
placeholder: "System prompt for the agent...",
|
|
2241
|
+
onSubmit: () => setCurrentStep("confirm"),
|
|
2242
|
+
error,
|
|
2243
|
+
rows: 5
|
|
2244
|
+
}
|
|
2245
|
+
)));
|
|
2246
|
+
case "confirm":
|
|
2247
|
+
const validation = validateAgentConfig({
|
|
2248
|
+
agentType: agent.agentType,
|
|
2249
|
+
whenToUse: editedDescription,
|
|
2250
|
+
systemPrompt: editedPrompt,
|
|
2251
|
+
selectedTools: editedTools
|
|
2252
|
+
});
|
|
2253
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Confirm Changes:"), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Agent:"), " ", agent.agentType), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Description:"), " ", editedDescription), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Tools:"), " ", editedTools.includes("*") ? "All tools" : editedTools.join(", ")), /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, "System Prompt:"), " ", editedPrompt.slice(0, 100), editedPrompt.length > 100 ? "..." : ""), validation.warnings.length > 0 && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, validation.warnings.map((warning, idx) => /* @__PURE__ */ React.createElement(Fragment, { key: idx }, /* @__PURE__ */ React.createElement(Text, { color: theme.warning }, "\u26A0 ", warning)))), error && /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { color: theme.error }, "\u2717 ", error)), /* @__PURE__ */ React.createElement(Box, { marginTop: 2 }, isUpdating ? /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Updating agent..." }) : /* @__PURE__ */ React.createElement(Text, null, "Press Enter to save changes"))));
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
useInput((input, key) => {
|
|
2257
|
+
if (key.escape) {
|
|
2258
|
+
if (currentStep === "description") {
|
|
2259
|
+
setModeState({ mode: "agent-menu", selectedAgent: agent });
|
|
2260
|
+
} else {
|
|
2261
|
+
const steps = [
|
|
2262
|
+
"description",
|
|
2263
|
+
"tools",
|
|
2264
|
+
"prompt",
|
|
2265
|
+
"confirm"
|
|
2266
|
+
];
|
|
2267
|
+
const currentIndex = steps.indexOf(currentStep);
|
|
2268
|
+
if (currentIndex > 0) {
|
|
2269
|
+
setCurrentStep(steps[currentIndex - 1]);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
if (key.return && currentStep === "confirm" && !isUpdating) {
|
|
2275
|
+
handleSave();
|
|
2276
|
+
}
|
|
2277
|
+
});
|
|
2278
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(
|
|
2279
|
+
Header,
|
|
2280
|
+
{
|
|
2281
|
+
title: `Edit Agent: ${agent.agentType}`,
|
|
2282
|
+
subtitle: `Step ${["description", "tools", "prompt", "confirm"].indexOf(currentStep) + 1}/4`
|
|
2283
|
+
},
|
|
2284
|
+
/* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, renderStepContent())
|
|
2285
|
+
), /* @__PURE__ */ React.createElement(
|
|
2286
|
+
InstructionBar,
|
|
2287
|
+
{
|
|
2288
|
+
instructions: currentStep === "confirm" ? "Press Enter to save \xB7 Esc to go back" : "Enter to continue \xB7 Esc to go back"
|
|
2289
|
+
}
|
|
2290
|
+
));
|
|
2291
|
+
}
|
|
2292
|
+
function DeleteConfirm({
|
|
2293
|
+
agent,
|
|
2294
|
+
setModeState,
|
|
2295
|
+
onAgentDeleted
|
|
2296
|
+
}) {
|
|
2297
|
+
const [isDeleting, setIsDeleting] = useState(false);
|
|
2298
|
+
const [selected, setSelected] = useState(false);
|
|
2299
|
+
const handleConfirm = async () => {
|
|
2300
|
+
if (selected) {
|
|
2301
|
+
setIsDeleting(true);
|
|
2302
|
+
try {
|
|
2303
|
+
await deleteAgent(agent);
|
|
2304
|
+
clearAgentCache();
|
|
2305
|
+
onAgentDeleted(`Deleted agent: ${agent.agentType}`);
|
|
2306
|
+
} catch (error) {
|
|
2307
|
+
console.error("Failed to delete agent:", error);
|
|
2308
|
+
setIsDeleting(false);
|
|
2309
|
+
}
|
|
2310
|
+
} else {
|
|
2311
|
+
setModeState({ mode: "agent-menu", selectedAgent: agent });
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
useInput((input, key) => {
|
|
2315
|
+
if (key.return) {
|
|
2316
|
+
handleConfirm();
|
|
2317
|
+
} else if (key.leftArrow || key.rightArrow || key.tab) {
|
|
2318
|
+
setSelected(!selected);
|
|
2319
|
+
}
|
|
2320
|
+
});
|
|
2321
|
+
if (isDeleting) {
|
|
2322
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "Delete agent", subtitle: "Deleting..." }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(LoadingSpinner, { text: "Deleting agent..." }))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
2323
|
+
}
|
|
2324
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { title: "Delete agent", subtitle: `Delete "${agent.agentType}"?` }, /* @__PURE__ */ React.createElement(Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, null, "This action cannot be undone. The agent file will be permanently deleted."), /* @__PURE__ */ React.createElement(Box, { marginTop: 2, gap: 3 }, /* @__PURE__ */ React.createElement(Text, { color: !selected ? "cyan" : void 0 }, !selected ? `${UI_ICONS.pointer} ` : " ", "No"), /* @__PURE__ */ React.createElement(Text, { color: selected ? "red" : void 0 }, selected ? `${UI_ICONS.pointer} ` : " ", "Yes, delete")))), /* @__PURE__ */ React.createElement(InstructionBar, null));
|
|
2325
|
+
}
|
|
2326
|
+
var AgentsCommand_default = {
|
|
2327
|
+
name: "agents",
|
|
2328
|
+
description: "Manage agent configurations",
|
|
2329
|
+
type: "local-jsx",
|
|
2330
|
+
isEnabled: true,
|
|
2331
|
+
isHidden: false,
|
|
2332
|
+
async call(onExit) {
|
|
2333
|
+
return /* @__PURE__ */ React.createElement(AgentsUI, { onExit });
|
|
2334
|
+
},
|
|
2335
|
+
userFacingName() {
|
|
2336
|
+
return "agents";
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
export {
|
|
2340
|
+
AgentsCommand_default as default
|
|
2341
|
+
};
|
|
2342
|
+
//# sourceMappingURL=AgentsCommand.js.map
|