@hyperwindmill/caretaker-cli 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +110 -0
- package/README.md +25 -0
- package/dist/agents/dispatch.d.ts +35 -0
- package/dist/agents/dispatch.d.ts.map +1 -0
- package/dist/agents/dispatch.js +108 -0
- package/dist/agents/sync.d.ts +10 -0
- package/dist/agents/sync.d.ts.map +1 -0
- package/dist/agents/sync.js +95 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +50 -0
- package/dist/cli/run.d.ts +11 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +89 -0
- package/dist/cli/web/fs.d.ts +3 -0
- package/dist/cli/web/fs.d.ts.map +1 -0
- package/dist/cli/web/fs.js +35 -0
- package/dist/cli/web/mcp_bridge.d.ts +7 -0
- package/dist/cli/web/mcp_bridge.d.ts.map +1 -0
- package/dist/cli/web/mcp_bridge.js +86 -0
- package/dist/cli/web/scheduler/heartbeat.d.ts +16 -0
- package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -0
- package/dist/cli/web/scheduler/heartbeat.js +181 -0
- package/dist/cli/web/scheduler/locks.d.ts +8 -0
- package/dist/cli/web/scheduler/locks.d.ts.map +1 -0
- package/dist/cli/web/scheduler/locks.js +7 -0
- package/dist/cli/web/scheduler/logs.d.ts +21 -0
- package/dist/cli/web/scheduler/logs.d.ts.map +1 -0
- package/dist/cli/web/scheduler/logs.js +62 -0
- package/dist/cli/web/scheduler/strategy.d.ts +6 -0
- package/dist/cli/web/scheduler/strategy.d.ts.map +1 -0
- package/dist/cli/web/scheduler/strategy.js +1 -0
- package/dist/cli/web/scheduler/task_review.d.ts +18 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -0
- package/dist/cli/web/scheduler/task_review.js +77 -0
- package/dist/cli/web/scheduler/task_roles.d.ts +22 -0
- package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -0
- package/dist/cli/web/scheduler/task_roles.js +70 -0
- package/dist/cli/web/scheduler/task_strategy.d.ts +2 -0
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -0
- package/dist/cli/web/scheduler/task_strategy.js +437 -0
- package/dist/cli/web/scheduler/telegram.d.ts +7 -0
- package/dist/cli/web/scheduler/telegram.d.ts.map +1 -0
- package/dist/cli/web/scheduler/telegram.js +393 -0
- package/dist/cli/web/scheduler.d.ts +15 -0
- package/dist/cli/web/scheduler.d.ts.map +1 -0
- package/dist/cli/web/scheduler.js +60 -0
- package/dist/cli/web/server.d.ts +38 -0
- package/dist/cli/web/server.d.ts.map +1 -0
- package/dist/cli/web/server.js +970 -0
- package/dist/commands/loader.d.ts +37 -0
- package/dist/commands/loader.d.ts.map +1 -0
- package/dist/commands/loader.js +110 -0
- package/dist/harness/claude_code_runner.d.ts +47 -0
- package/dist/harness/claude_code_runner.d.ts.map +1 -0
- package/dist/harness/claude_code_runner.js +325 -0
- package/dist/harness/claude_code_stream.d.ts +32 -0
- package/dist/harness/claude_code_stream.d.ts.map +1 -0
- package/dist/harness/claude_code_stream.js +121 -0
- package/dist/harness/context_files.d.ts +23 -0
- package/dist/harness/context_files.d.ts.map +1 -0
- package/dist/harness/context_files.js +126 -0
- package/dist/harness/history.d.ts +4 -0
- package/dist/harness/history.d.ts.map +1 -0
- package/dist/harness/history.js +120 -0
- package/dist/harness/index.d.ts +8 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +8 -0
- package/dist/harness/loop.d.ts +73 -0
- package/dist/harness/loop.d.ts.map +1 -0
- package/dist/harness/loop.js +373 -0
- package/dist/harness/model_limits.d.ts +25 -0
- package/dist/harness/model_limits.d.ts.map +1 -0
- package/dist/harness/model_limits.js +67 -0
- package/dist/harness/models.d.ts +9 -0
- package/dist/harness/models.d.ts.map +1 -0
- package/dist/harness/models.js +38 -0
- package/dist/harness/prelude.d.ts +21 -0
- package/dist/harness/prelude.d.ts.map +1 -0
- package/dist/harness/prelude.js +41 -0
- package/dist/harness/provider.d.ts +87 -0
- package/dist/harness/provider.d.ts.map +1 -0
- package/dist/harness/provider.js +140 -0
- package/dist/harness/runtime_info.d.ts +7 -0
- package/dist/harness/runtime_info.d.ts.map +1 -0
- package/dist/harness/runtime_info.js +15 -0
- package/dist/harness/think_tag_splitter.d.ts +33 -0
- package/dist/harness/think_tag_splitter.d.ts.map +1 -0
- package/dist/harness/think_tag_splitter.js +70 -0
- package/dist/harness/title.d.ts +17 -0
- package/dist/harness/title.d.ts.map +1 -0
- package/dist/harness/title.js +75 -0
- package/dist/harness/tools/builtin/bash.d.ts +3 -0
- package/dist/harness/tools/builtin/bash.d.ts.map +1 -0
- package/dist/harness/tools/builtin/bash.js +137 -0
- package/dist/harness/tools/builtin/edit.d.ts +6 -0
- package/dist/harness/tools/builtin/edit.d.ts.map +1 -0
- package/dist/harness/tools/builtin/edit.js +85 -0
- package/dist/harness/tools/builtin/fetch.d.ts +3 -0
- package/dist/harness/tools/builtin/fetch.d.ts.map +1 -0
- package/dist/harness/tools/builtin/fetch.js +75 -0
- package/dist/harness/tools/builtin/get_agent_context.d.ts +3 -0
- package/dist/harness/tools/builtin/get_agent_context.d.ts.map +1 -0
- package/dist/harness/tools/builtin/get_agent_context.js +76 -0
- package/dist/harness/tools/builtin/glob.d.ts +3 -0
- package/dist/harness/tools/builtin/glob.d.ts.map +1 -0
- package/dist/harness/tools/builtin/glob.js +52 -0
- package/dist/harness/tools/builtin/grep.d.ts +3 -0
- package/dist/harness/tools/builtin/grep.d.ts.map +1 -0
- package/dist/harness/tools/builtin/grep.js +126 -0
- package/dist/harness/tools/builtin/index.d.ts +23 -0
- package/dist/harness/tools/builtin/index.d.ts.map +1 -0
- package/dist/harness/tools/builtin/index.js +74 -0
- package/dist/harness/tools/builtin/invoke_agent.d.ts +3 -0
- package/dist/harness/tools/builtin/invoke_agent.d.ts.map +1 -0
- package/dist/harness/tools/builtin/invoke_agent.js +106 -0
- package/dist/harness/tools/builtin/invoke_command.d.ts +3 -0
- package/dist/harness/tools/builtin/invoke_command.d.ts.map +1 -0
- package/dist/harness/tools/builtin/invoke_command.js +42 -0
- package/dist/harness/tools/builtin/list_agents.d.ts +3 -0
- package/dist/harness/tools/builtin/list_agents.d.ts.map +1 -0
- package/dist/harness/tools/builtin/list_agents.js +32 -0
- package/dist/harness/tools/builtin/list_commands.d.ts +3 -0
- package/dist/harness/tools/builtin/list_commands.d.ts.map +1 -0
- package/dist/harness/tools/builtin/list_commands.js +27 -0
- package/dist/harness/tools/builtin/list_skills.d.ts +3 -0
- package/dist/harness/tools/builtin/list_skills.d.ts.map +1 -0
- package/dist/harness/tools/builtin/list_skills.js +24 -0
- package/dist/harness/tools/builtin/multiedit.d.ts +3 -0
- package/dist/harness/tools/builtin/multiedit.d.ts.map +1 -0
- package/dist/harness/tools/builtin/multiedit.js +88 -0
- package/dist/harness/tools/builtin/read_attachment.d.ts +3 -0
- package/dist/harness/tools/builtin/read_attachment.d.ts.map +1 -0
- package/dist/harness/tools/builtin/read_attachment.js +128 -0
- package/dist/harness/tools/builtin/read_document.d.ts +37 -0
- package/dist/harness/tools/builtin/read_document.d.ts.map +1 -0
- package/dist/harness/tools/builtin/read_document.js +238 -0
- package/dist/harness/tools/builtin/read_file.d.ts +3 -0
- package/dist/harness/tools/builtin/read_file.d.ts.map +1 -0
- package/dist/harness/tools/builtin/read_file.js +141 -0
- package/dist/harness/tools/builtin/read_image.d.ts +3 -0
- package/dist/harness/tools/builtin/read_image.d.ts.map +1 -0
- package/dist/harness/tools/builtin/read_image.js +80 -0
- package/dist/harness/tools/builtin/read_skill.d.ts +3 -0
- package/dist/harness/tools/builtin/read_skill.d.ts.map +1 -0
- package/dist/harness/tools/builtin/read_skill.js +30 -0
- package/dist/harness/tools/builtin/shell-env.d.ts +55 -0
- package/dist/harness/tools/builtin/shell-env.d.ts.map +1 -0
- package/dist/harness/tools/builtin/shell-env.js +181 -0
- package/dist/harness/tools/builtin/task_tools.d.ts +21 -0
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -0
- package/dist/harness/tools/builtin/task_tools.js +708 -0
- package/dist/harness/tools/builtin/write.d.ts +3 -0
- package/dist/harness/tools/builtin/write.d.ts.map +1 -0
- package/dist/harness/tools/builtin/write.js +56 -0
- package/dist/harness/tools/index.d.ts +6 -0
- package/dist/harness/tools/index.d.ts.map +1 -0
- package/dist/harness/tools/index.js +7 -0
- package/dist/harness/tools/instance.d.ts +3 -0
- package/dist/harness/tools/instance.d.ts.map +1 -0
- package/dist/harness/tools/instance.js +19 -0
- package/dist/harness/tools/registry.d.ts +21 -0
- package/dist/harness/tools/registry.d.ts.map +1 -0
- package/dist/harness/tools/registry.js +33 -0
- package/dist/harness/tools/resolve.d.ts +5 -0
- package/dist/harness/tools/resolve.d.ts.map +1 -0
- package/dist/harness/tools/resolve.js +60 -0
- package/dist/harness/tools/sandbox.d.ts +6 -0
- package/dist/harness/tools/sandbox.d.ts.map +1 -0
- package/dist/harness/tools/sandbox.js +23 -0
- package/dist/harness/tools/types.d.ts +80 -0
- package/dist/harness/tools/types.d.ts.map +1 -0
- package/dist/harness/tools/types.js +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/lib/encryption.d.ts +24 -0
- package/dist/lib/encryption.d.ts.map +1 -0
- package/dist/lib/encryption.js +163 -0
- package/dist/lib/open_url.d.ts +9 -0
- package/dist/lib/open_url.d.ts.map +1 -0
- package/dist/lib/open_url.js +23 -0
- package/dist/lib/task_git.d.ts +11 -0
- package/dist/lib/task_git.d.ts.map +1 -0
- package/dist/lib/task_git.js +100 -0
- package/dist/mcp/adapter.d.ts +9 -0
- package/dist/mcp/adapter.d.ts.map +1 -0
- package/dist/mcp/adapter.js +74 -0
- package/dist/mcp/client.d.ts +50 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +243 -0
- package/dist/mcp/oauth.d.ts +30 -0
- package/dist/mcp/oauth.d.ts.map +1 -0
- package/dist/mcp/oauth.js +171 -0
- package/dist/mcp/oauth_callback.d.ts +9 -0
- package/dist/mcp/oauth_callback.d.ts.map +1 -0
- package/dist/mcp/oauth_callback.js +51 -0
- package/dist/mcp/oauth_store.d.ts +22 -0
- package/dist/mcp/oauth_store.d.ts.map +1 -0
- package/dist/mcp/oauth_store.js +40 -0
- package/dist/mcp/server_manager.d.ts +49 -0
- package/dist/mcp/server_manager.d.ts.map +1 -0
- package/dist/mcp/server_manager.js +271 -0
- package/dist/plugins/fetchers/git.d.ts +67 -0
- package/dist/plugins/fetchers/git.d.ts.map +1 -0
- package/dist/plugins/fetchers/git.js +130 -0
- package/dist/plugins/fetchers/path.d.ts +4 -0
- package/dist/plugins/fetchers/path.d.ts.map +1 -0
- package/dist/plugins/fetchers/path.js +22 -0
- package/dist/plugins/loader.d.ts +31 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +146 -0
- package/dist/plugins/manifest.d.ts +56 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +389 -0
- package/dist/plugins/refresh_on_start.d.ts +7 -0
- package/dist/plugins/refresh_on_start.d.ts.map +1 -0
- package/dist/plugins/refresh_on_start.js +35 -0
- package/dist/plugins/source_manager.d.ts +27 -0
- package/dist/plugins/source_manager.d.ts.map +1 -0
- package/dist/plugins/source_manager.js +211 -0
- package/dist/plugins/types.d.ts +41 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +11 -0
- package/dist/session/context_usage.d.ts +13 -0
- package/dist/session/context_usage.d.ts.map +1 -0
- package/dist/session/context_usage.js +25 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/store.d.ts +68 -0
- package/dist/session/store.d.ts.map +1 -0
- package/dist/session/store.js +268 -0
- package/dist/session/types.d.ts +60 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +11 -0
- package/dist/store/db.d.ts +64 -0
- package/dist/store/db.d.ts.map +1 -0
- package/dist/store/db.js +91 -0
- package/dist/store/json.d.ts +21 -0
- package/dist/store/json.d.ts.map +1 -0
- package/dist/store/json.js +135 -0
- package/dist/tui/agents.d.ts +4 -0
- package/dist/tui/agents.d.ts.map +1 -0
- package/dist/tui/agents.js +616 -0
- package/dist/tui/app.d.ts +2 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/app.js +32 -0
- package/dist/tui/chat.d.ts +10 -0
- package/dist/tui/chat.d.ts.map +1 -0
- package/dist/tui/chat.js +258 -0
- package/dist/tui/logo.d.ts +2 -0
- package/dist/tui/logo.d.ts.map +1 -0
- package/dist/tui/logo.js +10 -0
- package/dist/tui/mcp_servers.d.ts +4 -0
- package/dist/tui/mcp_servers.d.ts.map +1 -0
- package/dist/tui/mcp_servers.js +287 -0
- package/dist/tui/plugins.d.ts +4 -0
- package/dist/tui/plugins.d.ts.map +1 -0
- package/dist/tui/plugins.js +234 -0
- package/dist/tui/providers.d.ts +4 -0
- package/dist/tui/providers.d.ts.map +1 -0
- package/dist/tui/providers.js +178 -0
- package/dist/tui/tool_picker_state.d.ts +9 -0
- package/dist/tui/tool_picker_state.d.ts.map +1 -0
- package/dist/tui/tool_picker_state.js +37 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/webview/index.html +22 -0
- package/dist/webview/standalone.css +2732 -0
- package/dist/webview/standalone.css.map +7 -0
- package/dist/webview/standalone.js +20641 -0
- package/dist/webview/standalone.js.map +7 -0
- package/package.json +120 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { isAbsolute } from 'node:path';
|
|
5
|
+
import { watch, existsSync } from 'node:fs';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import SelectInput from 'ink-select-input';
|
|
8
|
+
import TextInput from 'ink-text-input';
|
|
9
|
+
import { loadAgents, loadConfig, saveAgents, dataDir } from '../store/json.js';
|
|
10
|
+
import { fetchOpenAiStyleModels } from '../harness/models.js';
|
|
11
|
+
import { tools as toolRegistry } from '../harness/tools/instance.js';
|
|
12
|
+
import { listPlugins as listDiscoveredPlugins } from '../plugins/source_manager.js';
|
|
13
|
+
import { listMcpServers } from '../mcp/server_manager.js';
|
|
14
|
+
import { deleteSession, listForAgent } from '../session/store.js';
|
|
15
|
+
import ChatScreen from './chat.js';
|
|
16
|
+
import { applyToolState, cycleToolState, formatToolsForDetail, getToolState, } from './tool_picker_state.js';
|
|
17
|
+
export default function Agents({ onBack }) {
|
|
18
|
+
const [agents, setAgents] = useState([]);
|
|
19
|
+
const [providers, setProviders] = useState([]);
|
|
20
|
+
const [loaded, setLoaded] = useState(false);
|
|
21
|
+
const [mode, setMode] = useState('list');
|
|
22
|
+
const [selected, setSelected] = useState(null);
|
|
23
|
+
const [pastSessions, setPastSessions] = useState([]);
|
|
24
|
+
const [selectedSession, setSelectedSession] = useState(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
let watcher = null;
|
|
27
|
+
const loadInitial = async () => {
|
|
28
|
+
const [a, c] = await Promise.all([loadAgents(), loadConfig()]);
|
|
29
|
+
setAgents(a);
|
|
30
|
+
setProviders(c.providers);
|
|
31
|
+
setLoaded(true);
|
|
32
|
+
};
|
|
33
|
+
void loadInitial();
|
|
34
|
+
// Set up file watcher to refresh agents when edited from another surface
|
|
35
|
+
const dir = dataDir();
|
|
36
|
+
if (existsSync(dir)) {
|
|
37
|
+
watcher = watch(dir, (eventType, filename) => {
|
|
38
|
+
if (filename === 'agents.json') {
|
|
39
|
+
void (async () => {
|
|
40
|
+
const [a, c] = await Promise.all([loadAgents(), loadConfig()]);
|
|
41
|
+
setAgents((prevAgents) => {
|
|
42
|
+
// If selected agent was modified, update it in-place
|
|
43
|
+
if (selected) {
|
|
44
|
+
const fresh = a.find((x) => x.id === selected.id);
|
|
45
|
+
if (fresh) {
|
|
46
|
+
// Update selected with fresh data if workingDir or other runtime fields changed
|
|
47
|
+
setSelected({ ...fresh });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return a;
|
|
51
|
+
});
|
|
52
|
+
setProviders(c.providers);
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
watcher?.close();
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
// Refresh past-chats list whenever we enter or return to the agent detail.
|
|
62
|
+
const selectedId = selected?.id;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (mode === 'detail' && selectedId) {
|
|
65
|
+
void listForAgent(selectedId).then(setPastSessions);
|
|
66
|
+
}
|
|
67
|
+
}, [mode, selectedId]);
|
|
68
|
+
useInput((_input, key) => {
|
|
69
|
+
if (!key.escape)
|
|
70
|
+
return;
|
|
71
|
+
if (mode === 'list')
|
|
72
|
+
onBack();
|
|
73
|
+
else if (mode === 'detail')
|
|
74
|
+
setMode('list');
|
|
75
|
+
else if (mode === 'delete')
|
|
76
|
+
setMode('detail');
|
|
77
|
+
else if (mode === 'past-chats')
|
|
78
|
+
setMode('detail');
|
|
79
|
+
else if (mode === 'session-detail') {
|
|
80
|
+
setSelectedSession(null);
|
|
81
|
+
setMode('past-chats');
|
|
82
|
+
}
|
|
83
|
+
else if (mode === 'session-delete')
|
|
84
|
+
setMode('session-detail');
|
|
85
|
+
// create/edit: AgentForm; chat: ChatScreen — both have their own ESC.
|
|
86
|
+
});
|
|
87
|
+
if (!loaded)
|
|
88
|
+
return _jsx(Text, { dimColor: true, children: "loading\u2026" });
|
|
89
|
+
if (mode === 'create' || mode === 'edit') {
|
|
90
|
+
if (providers.length === 0) {
|
|
91
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "yellow", children: "No providers configured. Create a provider first." }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [{ label: '← Back', value: 'back' }], onSelect: () => setMode('list') }) })] }));
|
|
92
|
+
}
|
|
93
|
+
const isEdit = mode === 'edit';
|
|
94
|
+
return (_jsx(AgentForm, { providers: providers, existingNames: agents.filter((a) => a.id !== selected?.id).map((a) => a.name), initial: isEdit ? (selected ?? undefined) : undefined, onCancel: () => setMode(isEdit ? 'detail' : 'list'), onSave: async (a) => {
|
|
95
|
+
let next;
|
|
96
|
+
if (isEdit) {
|
|
97
|
+
next = agents.map((x) => (x.id === a.id ? a : x));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
next = [...agents, a];
|
|
101
|
+
}
|
|
102
|
+
await saveAgents(next);
|
|
103
|
+
setAgents(next);
|
|
104
|
+
if (isEdit) {
|
|
105
|
+
setSelected(a);
|
|
106
|
+
setMode('detail');
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
setMode('list');
|
|
110
|
+
}
|
|
111
|
+
} }));
|
|
112
|
+
}
|
|
113
|
+
if (mode === 'chat' && selected) {
|
|
114
|
+
const provider = providers.find((p) => p.name === selected.provider);
|
|
115
|
+
if (!provider) {
|
|
116
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "red", children: ["Provider \"", selected.provider, "\" not found."] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [{ label: '← Back', value: 'back' }], onSelect: () => setMode('detail') }) })] }));
|
|
117
|
+
}
|
|
118
|
+
return (_jsx(ChatScreen, { agent: selected, provider: provider, initialSession: selectedSession, onBack: () => {
|
|
119
|
+
const cameFromPast = !!selectedSession;
|
|
120
|
+
setSelectedSession(null);
|
|
121
|
+
if (cameFromPast) {
|
|
122
|
+
setMode('past-chats');
|
|
123
|
+
void listForAgent(selected.id).then(setPastSessions);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
setMode('detail');
|
|
127
|
+
}
|
|
128
|
+
} }));
|
|
129
|
+
}
|
|
130
|
+
if (mode === 'session-detail' && selected && selectedSession) {
|
|
131
|
+
const entry = pastSessions.find((e) => e.meta.id === selectedSession.id);
|
|
132
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: selectedSession.title }), entry && _jsxs(Text, { dimColor: true, children: ["last updated ", formatRelative(entry.updatedAt)] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [
|
|
133
|
+
{ label: 'Load', value: 'load' },
|
|
134
|
+
{ label: 'Delete', value: 'delete' },
|
|
135
|
+
{ label: '← Back', value: 'back' },
|
|
136
|
+
], onSelect: (item) => {
|
|
137
|
+
if (item.value === 'load')
|
|
138
|
+
return setMode('chat');
|
|
139
|
+
if (item.value === 'delete')
|
|
140
|
+
return setMode('session-delete');
|
|
141
|
+
setSelectedSession(null);
|
|
142
|
+
setMode('past-chats');
|
|
143
|
+
} }) })] }));
|
|
144
|
+
}
|
|
145
|
+
if (mode === 'session-delete' && selected && selectedSession) {
|
|
146
|
+
const targetId = selectedSession.id;
|
|
147
|
+
const targetAgentId = selectedSession.agentId;
|
|
148
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: ["Delete chat \"", selectedSession.title, "\"?"] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [
|
|
149
|
+
{ label: 'No, cancel', value: 'no' },
|
|
150
|
+
{ label: 'Yes, delete', value: 'yes' },
|
|
151
|
+
], onSelect: async (item) => {
|
|
152
|
+
if (item.value === 'no')
|
|
153
|
+
return setMode('session-detail');
|
|
154
|
+
await deleteSession(targetAgentId, targetId);
|
|
155
|
+
const fresh = await listForAgent(selected.id);
|
|
156
|
+
setPastSessions(fresh);
|
|
157
|
+
setSelectedSession(null);
|
|
158
|
+
setMode(fresh.length > 0 ? 'past-chats' : 'detail');
|
|
159
|
+
} }) })] }));
|
|
160
|
+
}
|
|
161
|
+
if (mode === 'past-chats' && selected) {
|
|
162
|
+
if (pastSessions.length === 0) {
|
|
163
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { dimColor: true, children: ["No past chats for \"", selected.name, "\"."] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [{ label: '← Back', value: 'back' }], onSelect: () => setMode('detail') }) })] }));
|
|
164
|
+
}
|
|
165
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Past chats \u2014 ", selected.name, " (", pastSessions.length, ")"] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [
|
|
166
|
+
...pastSessions.map((s) => ({
|
|
167
|
+
label: `${s.meta.title} — ${formatRelative(s.updatedAt)}`,
|
|
168
|
+
value: `s:${s.meta.id}`,
|
|
169
|
+
})),
|
|
170
|
+
{ label: '← Back', value: '__back__' },
|
|
171
|
+
], onSelect: (item) => {
|
|
172
|
+
if (item.value === '__back__')
|
|
173
|
+
return setMode('detail');
|
|
174
|
+
const id = item.value.replace(/^s:/, '');
|
|
175
|
+
const entry = pastSessions.find((x) => x.meta.id === id);
|
|
176
|
+
if (entry) {
|
|
177
|
+
setSelectedSession(entry.meta);
|
|
178
|
+
setMode('session-detail');
|
|
179
|
+
}
|
|
180
|
+
} }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "(esc to go back)" }) })] }));
|
|
181
|
+
}
|
|
182
|
+
if (mode === 'delete' && selected) {
|
|
183
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: ["Delete agent \"", selected.name, "\"?"] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [
|
|
184
|
+
{ label: 'No, cancel', value: 'no' },
|
|
185
|
+
{ label: 'Yes, delete', value: 'yes' },
|
|
186
|
+
], onSelect: async (item) => {
|
|
187
|
+
if (item.value === 'no')
|
|
188
|
+
return setMode('detail');
|
|
189
|
+
const next = agents.filter((x) => x.id !== selected.id);
|
|
190
|
+
await saveAgents(next);
|
|
191
|
+
setAgents(next);
|
|
192
|
+
setSelected(null);
|
|
193
|
+
setMode('list');
|
|
194
|
+
} }) })] }));
|
|
195
|
+
}
|
|
196
|
+
if (mode === 'detail' && selected) {
|
|
197
|
+
const managed = !!selected.pluginId;
|
|
198
|
+
const isClaudeCode = providers.find((p) => p.name === selected.provider)?.type === 'claude-code';
|
|
199
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: selected.name }), managed && (_jsx(Text, { color: "cyan", children: "[managed by plugin \u00B7 name + system prompt come from the manifest]" })), _jsxs(Text, { children: ["provider: ", selected.provider] }), _jsxs(Text, { children: ["model: ", selected.model] }), isClaudeCode ? (_jsxs(Text, { children: ["permissionMode: ", selected.permissionMode || 'Auto (Claude Code default)'] })) : (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["maxTurns: ", selected.maxTurns === 0 ? 'unlimited' : selected.maxTurns] }), _jsxs(Text, { children: ["tools:", ' ', selected.allowedTools.length === 0
|
|
200
|
+
? '(none)'
|
|
201
|
+
: formatToolsForDetail(selected.allowedTools, selected.confirmTools ?? [])] }), _jsxs(Text, { children: ["plugins:", ' ', (selected.plugins ?? []).length === 0 ? '(none)' : selected.plugins.join(', ')] })] })), _jsxs(Text, { children: ["mcp: ", (selected.mcpServers ?? []).length === 0 ? '(none)' : selected.mcpServers.length, ' ', "server(s)"] }), _jsxs(Text, { children: ["workDir: ", selected.workingDir || '(cwd)'] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: "system prompt:" }), _jsx(Text, { children: selected.systemPrompt || '(empty)' })] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: [
|
|
202
|
+
{ label: 'New chat', value: 'new-chat' },
|
|
203
|
+
...(pastSessions.length > 0
|
|
204
|
+
? [{ label: `Past chats (${pastSessions.length})`, value: 'past-chats' }]
|
|
205
|
+
: []),
|
|
206
|
+
{ label: 'Edit', value: 'edit' },
|
|
207
|
+
...(managed ? [] : [{ label: 'Delete', value: 'delete' }]),
|
|
208
|
+
{ label: '← Back', value: 'back' },
|
|
209
|
+
], onSelect: (item) => {
|
|
210
|
+
if (item.value === 'new-chat') {
|
|
211
|
+
setSelectedSession(null);
|
|
212
|
+
return setMode('chat');
|
|
213
|
+
}
|
|
214
|
+
if (item.value === 'past-chats')
|
|
215
|
+
return setMode('past-chats');
|
|
216
|
+
if (item.value === 'edit')
|
|
217
|
+
return setMode('edit');
|
|
218
|
+
if (item.value === 'delete')
|
|
219
|
+
return setMode('delete');
|
|
220
|
+
setMode('list');
|
|
221
|
+
} }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "(esc to go back)" }) })] }));
|
|
222
|
+
}
|
|
223
|
+
const items = [
|
|
224
|
+
...agents.map((a) => {
|
|
225
|
+
const flag = a.pluginId ? ' [managed]' : '';
|
|
226
|
+
return {
|
|
227
|
+
label: `${a.name} — ${a.model} via ${a.provider}${flag}`,
|
|
228
|
+
value: `a:${a.id}`,
|
|
229
|
+
};
|
|
230
|
+
}),
|
|
231
|
+
{ label: '+ Create new', value: '__new__' },
|
|
232
|
+
{ label: '← Back', value: '__back__' },
|
|
233
|
+
];
|
|
234
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: ["Agents (", agents.length, ")"] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: items, onSelect: (item) => {
|
|
235
|
+
if (item.value === '__back__')
|
|
236
|
+
return onBack();
|
|
237
|
+
if (item.value === '__new__')
|
|
238
|
+
return setMode('create');
|
|
239
|
+
const id = item.value.replace(/^a:/, '');
|
|
240
|
+
const a = agents.find((x) => x.id === id);
|
|
241
|
+
if (a) {
|
|
242
|
+
setSelected(a);
|
|
243
|
+
setMode('detail');
|
|
244
|
+
}
|
|
245
|
+
} }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "(esc to go back)" }) })] }));
|
|
246
|
+
}
|
|
247
|
+
const CLAUDE_CODE_PERMISSION_MODES = [
|
|
248
|
+
'acceptEdits',
|
|
249
|
+
'auto',
|
|
250
|
+
'bypassPermissions',
|
|
251
|
+
'manual',
|
|
252
|
+
'dontAsk',
|
|
253
|
+
'plan',
|
|
254
|
+
];
|
|
255
|
+
// Computes the step sequence for a given form flavor, so claude-code's
|
|
256
|
+
// skip-tools/plugins/maxTurns + insert-permissionMode branching lives in one
|
|
257
|
+
// place instead of scattered across every transition.
|
|
258
|
+
function stepSequence(managed, isClaudeCode) {
|
|
259
|
+
const seq = [];
|
|
260
|
+
if (!managed)
|
|
261
|
+
seq.push('name');
|
|
262
|
+
seq.push('provider', 'model');
|
|
263
|
+
if (!managed)
|
|
264
|
+
seq.push('systemPrompt');
|
|
265
|
+
if (isClaudeCode) {
|
|
266
|
+
seq.push('mcpServers', 'workingDir', 'permissionMode');
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
seq.push('tools', 'plugins', 'mcpServers', 'workingDir', 'maxTurns');
|
|
270
|
+
}
|
|
271
|
+
return seq;
|
|
272
|
+
}
|
|
273
|
+
function AgentForm({ providers, existingNames, initial, onSave, onCancel, }) {
|
|
274
|
+
const isEdit = !!initial;
|
|
275
|
+
const managed = !!initial?.pluginId;
|
|
276
|
+
// Managed agents: skip the name step (locked to manifest) and start at
|
|
277
|
+
// provider. systemPrompt is locked too — handled in advance() below.
|
|
278
|
+
const [step, setStep] = useState(managed ? 'provider' : 'name');
|
|
279
|
+
const [name, setName] = useState(initial?.name ?? '');
|
|
280
|
+
const [provider, setProvider] = useState(initial?.provider ?? '');
|
|
281
|
+
const isClaudeCode = providers.find((p) => p.name === provider)?.type === 'claude-code';
|
|
282
|
+
const [model, setModel] = useState(initial?.model ?? '');
|
|
283
|
+
const [systemPrompt, setSystemPrompt] = useState(initial?.systemPrompt ?? '');
|
|
284
|
+
const [permissionMode, setPermissionMode] = useState(initial?.permissionMode ?? '');
|
|
285
|
+
const normalizeTools = (tools) => {
|
|
286
|
+
const hasTaskTools = tools.some((t) => t.startsWith('mcp__task__'));
|
|
287
|
+
if (hasTaskTools) {
|
|
288
|
+
return [...tools.filter((t) => !t.startsWith('mcp__task__')), 'mcp__task__*'];
|
|
289
|
+
}
|
|
290
|
+
return tools;
|
|
291
|
+
};
|
|
292
|
+
const [allowedTools, setAllowedTools] = useState(normalizeTools(initial?.allowedTools ?? []));
|
|
293
|
+
const [confirmTools, setConfirmTools] = useState(normalizeTools(initial?.confirmTools ?? []));
|
|
294
|
+
const [activePlugins, setActivePlugins] = useState(initial?.plugins ?? []);
|
|
295
|
+
const [discoveredPlugins, setDiscoveredPlugins] = useState([]);
|
|
296
|
+
const [activeMcp, setActiveMcp] = useState(initial?.mcpServers ?? []);
|
|
297
|
+
const [mcpServers, setMcpServers] = useState([]);
|
|
298
|
+
const [workingDir, setWorkingDir] = useState(initial?.workingDir ?? '');
|
|
299
|
+
const [maxTurns, setMaxTurns] = useState(String(initial?.maxTurns ?? 30));
|
|
300
|
+
const [error, setError] = useState(null);
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
void listDiscoveredPlugins().then(setDiscoveredPlugins);
|
|
303
|
+
void listMcpServers().then(setMcpServers);
|
|
304
|
+
}, []);
|
|
305
|
+
useInput((_input, key) => {
|
|
306
|
+
if (key.escape)
|
|
307
|
+
onCancel();
|
|
308
|
+
});
|
|
309
|
+
// Step sequence computed as a filtered array (rather than scattering
|
|
310
|
+
// isClaudeCode conditionals across every transition): claude-code skips
|
|
311
|
+
// tools/plugins/maxTurns and gets a permissionMode step instead.
|
|
312
|
+
const steps = stepSequence(managed, isClaudeCode);
|
|
313
|
+
const nextAfter = (s) => {
|
|
314
|
+
const idx = steps.indexOf(s);
|
|
315
|
+
return idx >= 0 && idx + 1 < steps.length ? steps[idx + 1] : s;
|
|
316
|
+
};
|
|
317
|
+
const finalize = (n, permissionModeOverride) => {
|
|
318
|
+
const pm = permissionModeOverride ?? permissionMode;
|
|
319
|
+
const a = {
|
|
320
|
+
id: initial?.id ?? randomUUID(),
|
|
321
|
+
name: name.trim(),
|
|
322
|
+
systemPrompt: systemPrompt.trim(),
|
|
323
|
+
provider,
|
|
324
|
+
model: model.trim(),
|
|
325
|
+
allowedTools,
|
|
326
|
+
maxTurns: n,
|
|
327
|
+
...(confirmTools.length > 0 ? { confirmTools } : {}),
|
|
328
|
+
...(activePlugins.length > 0 ? { plugins: activePlugins } : {}),
|
|
329
|
+
...(activeMcp.length > 0 ? { mcpServers: activeMcp } : {}),
|
|
330
|
+
...(workingDir.trim() ? { workingDir: workingDir.trim() } : {}),
|
|
331
|
+
...(isClaudeCode && pm ? { permissionMode: pm } : {}),
|
|
332
|
+
// Preserve plugin-managed origin tags so the next sync recognizes
|
|
333
|
+
// this row instead of orphaning it.
|
|
334
|
+
...(initial?.pluginId ? { pluginId: initial.pluginId } : {}),
|
|
335
|
+
...(initial?.pluginScopedName ? { pluginScopedName: initial.pluginScopedName } : {}),
|
|
336
|
+
};
|
|
337
|
+
void onSave(a);
|
|
338
|
+
};
|
|
339
|
+
const advance = () => {
|
|
340
|
+
if (step === 'name') {
|
|
341
|
+
const v = name.trim();
|
|
342
|
+
if (!v)
|
|
343
|
+
return setError('name is required');
|
|
344
|
+
if (existingNames.includes(v))
|
|
345
|
+
return setError('name already exists');
|
|
346
|
+
setError(null);
|
|
347
|
+
setStep(nextAfter('name'));
|
|
348
|
+
}
|
|
349
|
+
else if (step === 'systemPrompt') {
|
|
350
|
+
setError(null);
|
|
351
|
+
setStep(nextAfter('systemPrompt'));
|
|
352
|
+
}
|
|
353
|
+
else if (step === 'tools') {
|
|
354
|
+
setError(null);
|
|
355
|
+
setStep(nextAfter('tools'));
|
|
356
|
+
}
|
|
357
|
+
else if (step === 'plugins') {
|
|
358
|
+
setError(null);
|
|
359
|
+
setStep(nextAfter('plugins'));
|
|
360
|
+
}
|
|
361
|
+
else if (step === 'mcpServers') {
|
|
362
|
+
setError(null);
|
|
363
|
+
setStep(nextAfter('mcpServers'));
|
|
364
|
+
}
|
|
365
|
+
else if (step === 'workingDir') {
|
|
366
|
+
const v = workingDir.trim();
|
|
367
|
+
if (v && !isAbsolute(v))
|
|
368
|
+
return setError('workingDir must be an absolute path (or empty for cwd)');
|
|
369
|
+
setError(null);
|
|
370
|
+
setStep(nextAfter('workingDir'));
|
|
371
|
+
}
|
|
372
|
+
else if (step === 'maxTurns') {
|
|
373
|
+
const n = Number.parseInt(maxTurns.trim(), 10);
|
|
374
|
+
if (!Number.isFinite(n) || n < 0)
|
|
375
|
+
return setError('maxTurns must be a non-negative integer (0 = unlimited)');
|
|
376
|
+
finalize(n);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const providerInitialIndex = Math.max(0, providers.findIndex((p) => p.name === provider));
|
|
380
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: isEdit ? `Edit agent "${initial.name}"` : 'New agent' }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { children: "name: " }), managed ? (_jsxs(Text, { children: [_jsx(Text, { children: name }), _jsx(Text, { dimColor: true, children: ' (managed by plugin)' })] })) : step === 'name' ? (_jsx(TextInput, { value: name, onChange: setName, onSubmit: advance })) : (_jsx(Text, { children: name }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "provider: " }), step === 'provider' ? (_jsx(Box, { flexDirection: "column", children: _jsx(SelectInput, { items: providers.map((p) => ({ label: p.name, value: p.name })), initialIndex: providerInitialIndex, onSelect: (item) => {
|
|
381
|
+
setProvider(item.value);
|
|
382
|
+
setStep('model');
|
|
383
|
+
} }) })) : step === 'name' ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: provider }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "model: " }), step === 'model' ? (_jsx(ModelStep, { provider: providers.find((p) => p.name === provider), initialModel: model || undefined, onPick: (id) => {
|
|
384
|
+
setModel(id);
|
|
385
|
+
setError(null);
|
|
386
|
+
setStep(nextAfter('model'));
|
|
387
|
+
} })) : ['name', 'provider'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: model }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "prompt: " }), managed ? (_jsxs(Text, { children: [_jsxs(Text, { children: [(systemPrompt || '(empty)').slice(0, 80), systemPrompt.length > 80 ? '…' : ''] }), _jsx(Text, { dimColor: true, children: ' (managed by plugin)' })] })) : step === 'systemPrompt' ? (_jsx(TextInput, { value: systemPrompt, onChange: setSystemPrompt, onSubmit: advance, placeholder: isEdit ? '(enter to keep current)' : '(optional system prompt)' })) : ['name', 'provider', 'model'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: systemPrompt || '(empty)' }))] }), !isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "tools:" }), step === 'tools' ? (_jsx(ToolPicker, { tools: [
|
|
388
|
+
...toolRegistry.list().filter((t) => !t.name.startsWith('mcp__task__')),
|
|
389
|
+
{
|
|
390
|
+
name: 'mcp__task__*',
|
|
391
|
+
description: 'Manage autonomous tasks & checklists (enables all mcp__task__* tools)',
|
|
392
|
+
parameters: { type: 'object', properties: {} },
|
|
393
|
+
execute: async () => ({ content: '' }),
|
|
394
|
+
},
|
|
395
|
+
], allowed: allowedTools, confirm: confirmTools, onChange: (a, c) => {
|
|
396
|
+
setAllowedTools(a);
|
|
397
|
+
setConfirmTools(c);
|
|
398
|
+
}, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${allowedTools.length === 0 ? '(none)' : formatToolsForDetail(allowedTools, confirmTools)}` }))] })), !isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "plugins:" }), step === 'plugins' ? (_jsx(PluginPicker, { plugins: discoveredPlugins, value: activePlugins, onChange: setActivePlugins, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt', 'tools'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${activePlugins.length === 0 ? '(none)' : activePlugins.join(', ')}` }))] })), _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "mcp:" }), step === 'mcpServers' ? (_jsx(McpPicker, { servers: mcpServers, value: activeMcp, onChange: setActiveMcp, onSubmit: advance })) : ['name', 'provider', 'model', 'systemPrompt', 'tools', 'plugins'].includes(step) ? (_jsx(Text, { dimColor: true, children: " (pending)" })) : (_jsx(Text, { children: ` ${activeMcp.length === 0
|
|
399
|
+
? '(none)'
|
|
400
|
+
: activeMcp.map((id) => mcpServers.find((s) => s.id === id)?.name ?? id).join(', ')}` }))] }), _jsxs(Box, { children: [_jsx(Text, { children: "workDir: " }), step === 'workingDir' ? (_jsx(TextInput, { value: workingDir, onChange: setWorkingDir, onSubmit: advance, placeholder: "(empty = process.cwd() \u2014 absolute path otherwise)" })) : [
|
|
401
|
+
'name',
|
|
402
|
+
'provider',
|
|
403
|
+
'model',
|
|
404
|
+
'systemPrompt',
|
|
405
|
+
'tools',
|
|
406
|
+
'plugins',
|
|
407
|
+
'mcpServers',
|
|
408
|
+
].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: workingDir.trim() || '(cwd)' }))] }), !isClaudeCode && (_jsxs(Box, { children: [_jsx(Text, { children: "maxTurns: " }), step === 'maxTurns' ? (_jsx(TextInput, { value: maxTurns, onChange: setMaxTurns, onSubmit: advance, placeholder: "0 = unlimited" })) : (_jsx(Text, { dimColor: true, children: "(pending)" }))] })), isClaudeCode && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "permissionMode: " }), step === 'permissionMode' ? (_jsx(SelectInput, { items: [
|
|
409
|
+
{ label: 'Auto (Claude Code default)', value: '' },
|
|
410
|
+
...CLAUDE_CODE_PERMISSION_MODES.map((m) => ({ label: m, value: m })),
|
|
411
|
+
], initialIndex: permissionMode
|
|
412
|
+
? Math.max(0, CLAUDE_CODE_PERMISSION_MODES.indexOf(permissionMode) + 1)
|
|
413
|
+
: 0, onSelect: (item) => {
|
|
414
|
+
setPermissionMode(item.value);
|
|
415
|
+
setError(null);
|
|
416
|
+
const n = Number.parseInt(maxTurns.trim(), 10);
|
|
417
|
+
finalize(Number.isFinite(n) && n >= 0 ? n : 30, item.value);
|
|
418
|
+
} })) : ['name', 'provider', 'model', 'systemPrompt', 'mcpServers', 'workingDir'].includes(step) ? (_jsx(Text, { dimColor: true, children: "(pending)" })) : (_jsx(Text, { children: permissionMode || 'Auto (Claude Code default)' })), _jsx(Text, { dimColor: true, children: "Uses your local Claude Code session; Anthropic may bill programmatic use as extra usage." })] })), error && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "red", children: error }) })), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "(esc to cancel)" }) })] }));
|
|
419
|
+
}
|
|
420
|
+
function ModelStep({ provider, initialModel, onPick, }) {
|
|
421
|
+
const isClaudeCode = provider.type === 'claude-code';
|
|
422
|
+
const [state, setState] = useState(isClaudeCode ? { mode: 'manual', reason: null } : { mode: 'loading' });
|
|
423
|
+
const [manualValue, setManualValue] = useState(initialModel ?? '');
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
// claude-code providers never expose an OpenAI-style model-listing
|
|
426
|
+
// endpoint — always go straight to manual entry.
|
|
427
|
+
if (isClaudeCode)
|
|
428
|
+
return;
|
|
429
|
+
let cancelled = false;
|
|
430
|
+
void fetchOpenAiStyleModels(provider.endpoint, provider.apiKey ?? null).then((res) => {
|
|
431
|
+
if (cancelled)
|
|
432
|
+
return;
|
|
433
|
+
if (res.ok && res.ids.length > 0) {
|
|
434
|
+
setState({ mode: 'select', ids: res.ids.sort() });
|
|
435
|
+
}
|
|
436
|
+
else if (res.ok) {
|
|
437
|
+
setState({ mode: 'manual', reason: 'provider returned an empty list' });
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
setState({ mode: 'manual', reason: res.error });
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return () => {
|
|
444
|
+
cancelled = true;
|
|
445
|
+
};
|
|
446
|
+
}, [isClaudeCode, provider.endpoint, provider.apiKey]);
|
|
447
|
+
if (state.mode === 'loading') {
|
|
448
|
+
return _jsxs(Text, { dimColor: true, children: ["fetching models from ", provider.name, "\u2026"] });
|
|
449
|
+
}
|
|
450
|
+
if (state.mode === 'manual') {
|
|
451
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(TextInput, { value: manualValue, onChange: setManualValue, onSubmit: () => {
|
|
452
|
+
const v = manualValue.trim();
|
|
453
|
+
if (v)
|
|
454
|
+
onPick(v);
|
|
455
|
+
}, placeholder: isClaudeCode ? 'sonnet | opus | haiku (or full model id)' : 'e.g. gpt-4o-mini' }), state.reason && (_jsx(Text, { dimColor: true, color: "yellow", children: state.reason.slice(0, 200) }))] }));
|
|
456
|
+
}
|
|
457
|
+
const items = [
|
|
458
|
+
...state.ids.map((id) => ({ label: id, value: `m:${id}` })),
|
|
459
|
+
{ label: '✏ enter manually', value: '__manual__' },
|
|
460
|
+
];
|
|
461
|
+
const initialIndex = initialModel ? Math.max(0, state.ids.indexOf(initialModel)) : 0;
|
|
462
|
+
return (_jsx(SelectInput, { items: items, initialIndex: initialIndex, onSelect: (item) => {
|
|
463
|
+
if (item.value === '__manual__') {
|
|
464
|
+
setState({ mode: 'manual', reason: null });
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
onPick(item.value.replace(/^m:/, ''));
|
|
468
|
+
} }));
|
|
469
|
+
}
|
|
470
|
+
function ToolPicker({ tools, allowed, confirm, onChange, onSubmit, }) {
|
|
471
|
+
const [hl, setHl] = useState(0);
|
|
472
|
+
// Auto-skip when nothing to pick. Intentionally fires only when the list size changes,
|
|
473
|
+
// not on every onSubmit identity change from the parent.
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
if (tools.length === 0)
|
|
476
|
+
onSubmit();
|
|
477
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
478
|
+
}, [tools.length]);
|
|
479
|
+
useInput((input, key) => {
|
|
480
|
+
if (tools.length === 0)
|
|
481
|
+
return;
|
|
482
|
+
if (key.upArrow) {
|
|
483
|
+
setHl((h) => Math.max(0, h - 1));
|
|
484
|
+
}
|
|
485
|
+
else if (key.downArrow) {
|
|
486
|
+
setHl((h) => Math.min(tools.length - 1, h + 1));
|
|
487
|
+
}
|
|
488
|
+
else if (input === ' ') {
|
|
489
|
+
const tool = tools[hl];
|
|
490
|
+
if (!tool)
|
|
491
|
+
return;
|
|
492
|
+
const cur = getToolState(tool.name, allowed, confirm);
|
|
493
|
+
const next = applyToolState(tool.name, cycleToolState(cur), allowed, confirm);
|
|
494
|
+
onChange(next.allowed, next.confirm);
|
|
495
|
+
}
|
|
496
|
+
else if (key.return) {
|
|
497
|
+
onSubmit();
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
if (tools.length === 0) {
|
|
501
|
+
return _jsx(Text, { dimColor: true, children: " (no tools registered, skipping)" });
|
|
502
|
+
}
|
|
503
|
+
return (_jsxs(Box, { flexDirection: "column", children: [tools.map((t, i) => {
|
|
504
|
+
const state = getToolState(t.name, allowed, confirm);
|
|
505
|
+
const cursor = i === hl ? '›' : ' ';
|
|
506
|
+
const checkbox = state === 'inactive' ? '[ ]' : state === 'active' ? '[x]' : '[!]';
|
|
507
|
+
const checkboxColor = state === 'confirm' ? 'yellow' : undefined;
|
|
508
|
+
const dangerSuffix = t.dangerous ? ' (dangerous)' : '';
|
|
509
|
+
const desc = t.description.length > 60 ? `${t.description.slice(0, 57)}…` : t.description;
|
|
510
|
+
return (_jsxs(Text, { children: [` ${cursor} `, _jsx(Text, { color: checkboxColor, children: checkbox }), " ", _jsx(Text, { bold: i === hl, children: t.name }), _jsx(Text, { dimColor: true, children: `${dangerSuffix} — ${desc}` })] }, t.name));
|
|
511
|
+
}), _jsx(Text, { dimColor: true, children: " (\u2191/\u2193 navigate \u00B7 space cycles inactive \u2192 active \u2192 confirm \u00B7 enter)" })] }));
|
|
512
|
+
}
|
|
513
|
+
function PluginPicker({ plugins, value, onChange, onSubmit, }) {
|
|
514
|
+
const [hl, setHl] = useState(0);
|
|
515
|
+
// Auto-skip when nothing to pick — but keep the user in the step long
|
|
516
|
+
// enough to read the hint, by surfacing a Continue line they can press
|
|
517
|
+
// enter on. (Skipping silently would advance instantly when no plugins
|
|
518
|
+
// are configured, hiding the fact that the field exists.)
|
|
519
|
+
useInput((_input, key) => {
|
|
520
|
+
if (plugins.length === 0) {
|
|
521
|
+
if (key.return)
|
|
522
|
+
onSubmit();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (key.upArrow) {
|
|
526
|
+
setHl((h) => Math.max(0, h - 1));
|
|
527
|
+
}
|
|
528
|
+
else if (key.downArrow) {
|
|
529
|
+
setHl((h) => Math.min(plugins.length - 1, h + 1));
|
|
530
|
+
}
|
|
531
|
+
else if (_input === ' ') {
|
|
532
|
+
const p = plugins[hl];
|
|
533
|
+
if (!p)
|
|
534
|
+
return;
|
|
535
|
+
const set = new Set(value);
|
|
536
|
+
if (set.has(p.name))
|
|
537
|
+
set.delete(p.name);
|
|
538
|
+
else
|
|
539
|
+
set.add(p.name);
|
|
540
|
+
onChange([...set]);
|
|
541
|
+
}
|
|
542
|
+
else if (key.return) {
|
|
543
|
+
onSubmit();
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
if (plugins.length === 0) {
|
|
547
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: " (no discovered plugins \u2014 add a source from the Plugins menu)" }), _jsx(Text, { dimColor: true, children: " (enter to continue)" })] }));
|
|
548
|
+
}
|
|
549
|
+
return (_jsxs(Box, { flexDirection: "column", children: [plugins.map((p, i) => {
|
|
550
|
+
const checked = value.includes(p.name);
|
|
551
|
+
const cursor = i === hl ? '›' : ' ';
|
|
552
|
+
const checkbox = checked ? '[x]' : '[ ]';
|
|
553
|
+
const desc = p.description
|
|
554
|
+
? p.description.length > 60
|
|
555
|
+
? `${p.description.slice(0, 57)}…`
|
|
556
|
+
: p.description
|
|
557
|
+
: '';
|
|
558
|
+
return (_jsxs(Text, { children: [` ${cursor} ${checkbox} `, _jsx(Text, { bold: i === hl, children: p.name }), _jsx(Text, { dimColor: true, children: ` [${p.manifestKind}]${desc ? ` — ${desc}` : ''}` })] }, p.id));
|
|
559
|
+
}), _jsx(Text, { dimColor: true, children: " (\u2191/\u2193 navigate \u00B7 space toggle \u00B7 enter confirm)" })] }));
|
|
560
|
+
}
|
|
561
|
+
function McpPicker({ servers, value, onChange, onSubmit, }) {
|
|
562
|
+
const [hl, setHl] = useState(0);
|
|
563
|
+
useInput((_input, key) => {
|
|
564
|
+
if (servers.length === 0) {
|
|
565
|
+
if (key.return)
|
|
566
|
+
onSubmit();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (key.upArrow) {
|
|
570
|
+
setHl((h) => Math.max(0, h - 1));
|
|
571
|
+
}
|
|
572
|
+
else if (key.downArrow) {
|
|
573
|
+
setHl((h) => Math.min(servers.length - 1, h + 1));
|
|
574
|
+
}
|
|
575
|
+
else if (_input === ' ') {
|
|
576
|
+
const s = servers[hl];
|
|
577
|
+
if (!s)
|
|
578
|
+
return;
|
|
579
|
+
const set = new Set(value);
|
|
580
|
+
if (set.has(s.id))
|
|
581
|
+
set.delete(s.id);
|
|
582
|
+
else
|
|
583
|
+
set.add(s.id);
|
|
584
|
+
onChange([...set]);
|
|
585
|
+
}
|
|
586
|
+
else if (key.return) {
|
|
587
|
+
onSubmit();
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
if (servers.length === 0) {
|
|
591
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: " (no MCP servers configured \u2014 add one from the MCP Servers menu)" }), _jsx(Text, { dimColor: true, children: " (enter to continue)" })] }));
|
|
592
|
+
}
|
|
593
|
+
return (_jsxs(Box, { flexDirection: "column", children: [servers.map((s, i) => {
|
|
594
|
+
const checked = value.includes(s.id);
|
|
595
|
+
const cursor = i === hl ? '›' : ' ';
|
|
596
|
+
const checkbox = checked ? '[x]' : '[ ]';
|
|
597
|
+
const tail = `${s.transport} · ${s.enabled ? 'enabled' : 'disabled'}`;
|
|
598
|
+
return (_jsxs(Text, { children: [` ${cursor} ${checkbox} `, _jsx(Text, { bold: true, children: s.name }), _jsx(Text, { dimColor: true, children: ` (${tail})` })] }, s.id));
|
|
599
|
+
}), _jsx(Text, { dimColor: true, children: " (\u2191/\u2193 navigate \u00B7 space toggle \u00B7 enter confirm)" })] }));
|
|
600
|
+
}
|
|
601
|
+
function formatRelative(d) {
|
|
602
|
+
const diff = Date.now() - d.getTime();
|
|
603
|
+
const sec = Math.floor(diff / 1000);
|
|
604
|
+
if (sec < 60)
|
|
605
|
+
return `${sec}s ago`;
|
|
606
|
+
const min = Math.floor(sec / 60);
|
|
607
|
+
if (min < 60)
|
|
608
|
+
return `${min}m ago`;
|
|
609
|
+
const hr = Math.floor(min / 60);
|
|
610
|
+
if (hr < 24)
|
|
611
|
+
return `${hr}h ago`;
|
|
612
|
+
const day = Math.floor(hr / 24);
|
|
613
|
+
if (day < 7)
|
|
614
|
+
return `${day}d ago`;
|
|
615
|
+
return d.toISOString().slice(0, 10);
|
|
616
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/tui/app.tsx"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,UAAU,GAAG,4CAyC1B"}
|
package/dist/tui/app.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Box, Text, useApp, useInput } from 'ink';
|
|
4
|
+
import SelectInput from 'ink-select-input';
|
|
5
|
+
import Providers from './providers.js';
|
|
6
|
+
import Agents from './agents.js';
|
|
7
|
+
import Plugins from './plugins.js';
|
|
8
|
+
import McpServers from './mcp_servers.js';
|
|
9
|
+
import Logo from './logo.js';
|
|
10
|
+
export default function App() {
|
|
11
|
+
const [view, setView] = useState('menu');
|
|
12
|
+
const { exit } = useApp();
|
|
13
|
+
useInput((_input, key) => {
|
|
14
|
+
if (!key.escape)
|
|
15
|
+
return;
|
|
16
|
+
if (view === 'menu')
|
|
17
|
+
exit();
|
|
18
|
+
// Sub-views handle their own ESC via onBack chains.
|
|
19
|
+
});
|
|
20
|
+
return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Logo, {}) }), view === 'menu' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(SelectInput, { items: [
|
|
21
|
+
{ label: 'Agents', value: 'agents' },
|
|
22
|
+
{ label: 'Providers', value: 'providers' },
|
|
23
|
+
{ label: 'Plugins', value: 'plugins' },
|
|
24
|
+
{ label: 'MCP Servers', value: 'mcp' },
|
|
25
|
+
{ label: 'Quit', value: 'quit' },
|
|
26
|
+
], onSelect: (item) => {
|
|
27
|
+
if (item.value === 'quit')
|
|
28
|
+
exit();
|
|
29
|
+
else
|
|
30
|
+
setView(item.value);
|
|
31
|
+
} }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "(esc to quit)" }) })] })), view === 'providers' && _jsx(Providers, { onBack: () => setView('menu') }), view === 'agents' && _jsx(Agents, { onBack: () => setView('menu') }), view === 'plugins' && _jsx(Plugins, { onBack: () => setView('menu') }), view === 'mcp' && _jsx(McpServers, { onBack: () => setView('menu') })] }));
|
|
32
|
+
}
|